From 295ed069fa9a4b1b89669d53e50d635ec2375a88 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Tue, 17 Dec 2013 17:52:21 +0000
Subject: [PATCH] - Add re-synchronisation of SQN on S6A interface - Corrected
 some bugs in NAS layer

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4755 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair-cn/COMMON/nas_messages_types.h        |  3 ++
 openair-cn/COMMON/s6a_messages_types.h        | 17 ++++--
 openair-cn/MME_APP/mme_app_authentication.c   | 35 +++++++++---
 openair-cn/MME_APP/mme_app_ue_context.h       |  2 +-
 openair-cn/NAS/EURECOM-NAS/src/emm/Attach.c   |  8 +--
 .../NAS/EURECOM-NAS/src/emm/Authentication.c  | 53 ++++++++++++++-----
 .../NAS/EURECOM-NAS/src/emm/Identification.c  |  6 ++-
 .../EURECOM-NAS/src/emm/SecurityModeControl.c |  8 +++
 .../NAS/EURECOM-NAS/src/emm/sap/emm_as.c      |  2 +-
 .../NAS/EURECOM-NAS/src/emm/sap/emm_fsm.c     |  6 ++-
 .../NAS/EURECOM-NAS/src/emm/sap/emm_fsm.h     |  1 +
 openair-cn/NAS/nas_itti_messaging.h           | 17 ++++--
 openair-cn/S1AP/s1ap_mme_nas_procedures.c     |  4 +-
 openair-cn/S6A/s6a_auth_info.c                | 12 ++++-
 openair-cn/S6A/s6a_defs.h                     |  1 +
 openair-cn/S6A/s6a_dict.c                     |  3 ++
 openair-cn/SCTP/sctp_eNB_task.c               |  5 +-
 openair-cn/UTILS/CONF/epc_caviar.conf         |  2 +-
 openair1/PHY/LTE_TRANSPORT/dci_tools.c        |  1 -
 openair1/PHY/LTE_TRANSPORT/rar_tools.c        |  4 +-
 openair2/ENB_APP/enb_app.c                    |  8 +--
 targets/RTAI/USER/Makefile                    |  4 +-
 22 files changed, 151 insertions(+), 51 deletions(-)

diff --git a/openair-cn/COMMON/nas_messages_types.h b/openair-cn/COMMON/nas_messages_types.h
index c1fade8987..bebe11d76c 100644
--- a/openair-cn/COMMON/nas_messages_types.h
+++ b/openair-cn/COMMON/nas_messages_types.h
@@ -120,6 +120,9 @@ typedef struct nas_auth_param_req_s {
 
     /* Indicates whether the procedure corresponds to a new connection or not */
     uint8_t  initial_req:1;
+
+    uint8_t re_synchronization:1;
+    uint8_t auts[14];
 } nas_auth_param_req_t;
 
 typedef struct nas_auth_param_rsp_s {
diff --git a/openair-cn/COMMON/s6a_messages_types.h b/openair-cn/COMMON/s6a_messages_types.h
index b505f6374b..e8ba720c5b 100644
--- a/openair-cn/COMMON/s6a_messages_types.h
+++ b/openair-cn/COMMON/s6a_messages_types.h
@@ -1,7 +1,9 @@
 #ifndef S6A_MESSAGES_TYPES_H_
 #define S6A_MESSAGES_TYPES_H_
 
-typedef struct {
+#define AUTS_LENGTH 14
+
+typedef struct s6a_update_location_req_s {
 #define SKIP_SUBSCRIBER_DATA (0x1)
     unsigned skip_subsriber_data:1;
 #define INITIAL_ATTACH       (0x1)
@@ -13,7 +15,7 @@ typedef struct {
     rat_type_t rat_type;
 } s6a_update_location_req_t;
 
-typedef struct {
+typedef struct s6a_update_location_ans_s {
     char    imsi[IMSI_DIGITS_MAX + 1];
     uint8_t imsi_length;
 
@@ -22,15 +24,22 @@ typedef struct {
     subscription_data_t subscription_data;
 } s6a_update_location_ans_t;
 
-typedef struct {
+typedef struct s6a_auth_info_req_s {
     char    imsi[IMSI_DIGITS_MAX + 1];
     uint8_t imsi_length;
     plmn_t  visited_plmn;
     /* Number of vectors to retrieve from HSS, should be equal to one */
     uint8_t nb_of_vectors;
+
+    /* Bit to indicate that USIM has requested a re-synchronization of SQN */
+    unsigned re_synchronization:1;
+    /* AUTS to provide to AUC.
+     * Only present and interpreted if re_synchronization == 1.
+     */
+    uint8_t auts[AUTS_LENGTH];
 } s6a_auth_info_req_t;
 
-typedef struct {
+typedef struct s6a_auth_info_ans_s {
     char       imsi[IMSI_DIGITS_MAX + 1];
     uint8_t    imsi_length;
 
diff --git a/openair-cn/MME_APP/mme_app_authentication.c b/openair-cn/MME_APP/mme_app_authentication.c
index d9717ec258..b9efaf9db3 100644
--- a/openair-cn/MME_APP/mme_app_authentication.c
+++ b/openair-cn/MME_APP/mme_app_authentication.c
@@ -43,13 +43,17 @@
 
 #include "assertions.h"
 
+static
 int mme_app_request_authentication_info(const mme_app_imsi_t imsi,
                                         const uint8_t nb_of_vectors,
-                                        const plmn_t *plmn);
+                                        const plmn_t *plmn,
+                                        const uint8_t *auts);
 
+static
 int mme_app_request_authentication_info(const mme_app_imsi_t imsi,
                                         const uint8_t nb_of_vectors,
-                                        const plmn_t *plmn)
+                                        const plmn_t *plmn,
+                                        const uint8_t *auts)
 {
     s6a_auth_info_req_t *auth_info_req;
     MessageDef          *message_p;
@@ -62,6 +66,13 @@ int mme_app_request_authentication_info(const mme_app_imsi_t imsi,
     MME_APP_IMSI_TO_STRING(imsi, auth_info_req->imsi);
     memcpy(&auth_info_req->visited_plmn, plmn, sizeof(plmn_t));
     auth_info_req->nb_of_vectors = nb_of_vectors;
+    if (auts != NULL) {
+        auth_info_req->re_synchronization = 1;
+        memcpy(auth_info_req->auts, auts, sizeof(auth_info_req->auts));
+    } else {
+        auth_info_req->re_synchronization = 0;
+        memset(auth_info_req->auts, 0, sizeof(auth_info_req->auts));
+    }
 
     return itti_send_msg_to_task(TASK_S6A, INSTANCE_DEFAULT, message_p);
 }
@@ -286,6 +297,14 @@ void mme_app_handle_nas_auth_param_req(nas_auth_param_req_t
 {
     struct ue_context_s *ue_context;
     uint64_t imsi = 0;
+    plmn_t visited_plmn_dongle = {
+        .MCCdigit3 = 2,
+        .MCCdigit2 = 0,
+        .MCCdigit1 = 8,
+        .MNCdigit3 = 2,
+        .MNCdigit2 = 9,
+        .MNCdigit1 = 0xF,
+    };
 
     DevAssert(nas_auth_param_req_p != NULL);
 
@@ -316,10 +335,10 @@ void mme_app_handle_nas_auth_param_req(nas_auth_param_req_t
         /* We have no vector for this UE, send an authentication request
          * to the HSS.
          */
-        plmn_t plmn = {
+        plmn_t visited_plmn_eur = {
+            .MCCdigit3 = 2,
             .MCCdigit2 = 0,
             .MCCdigit1 = 8,
-            .MCCdigit3 = 2,
             .MNCdigit1 = 0,
             .MNCdigit2 = 4,
             .MNCdigit3 = 3,
@@ -328,12 +347,14 @@ void mme_app_handle_nas_auth_param_req(nas_auth_param_req_t
         /* Acquire the current time */
         time(&ue_context->cell_age);
 
-        memcpy(&ue_context->guti.gummei.plmn, &plmn, sizeof(plmn_t));
+        memcpy(&ue_context->guti.gummei.plmn, &visited_plmn_dongle, sizeof(plmn_t));
         MME_APP_DEBUG("and we have no auth. vector for it, request"
                       " authentication information\n");
-        mme_app_request_authentication_info(imsi, 1, &plmn);
+        mme_app_request_authentication_info(imsi, 1, &visited_plmn_dongle, NULL);
     } else {
-        DevMessage("not handled\n");
+        memcpy(&ue_context->guti.gummei.plmn, &visited_plmn_dongle, sizeof(plmn_t));
+
+        mme_app_request_authentication_info(imsi, 1, &visited_plmn_dongle, nas_auth_param_req_p->auts);
     }
 }
 #endif
diff --git a/openair-cn/MME_APP/mme_app_ue_context.h b/openair-cn/MME_APP/mme_app_ue_context.h
index cf7a2c1dd0..bdca1bea06 100644
--- a/openair-cn/MME_APP/mme_app_ue_context.h
+++ b/openair-cn/MME_APP/mme_app_ue_context.h
@@ -51,7 +51,7 @@
 typedef enum {
     ECM_IDLE,
     ECM_CONNECTED,
-    EMM_DEREGISTERED,
+    ECM_DEREGISTERED,
 } mm_state_t;
 
 typedef uint64_t mme_app_imsi_t;
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/Attach.c b/openair-cn/NAS/EURECOM-NAS/src/emm/Attach.c
index 8f7cc4c20e..200e07551c 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/Attach.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/Attach.c
@@ -1099,7 +1099,7 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type,
         }
     } else {
         /* Create UE's EMM context */
-        *emm_ctx = (emm_data_context_t *)malloc(sizeof(emm_data_context_t));
+        *emm_ctx = (emm_data_context_t *)calloc(1, sizeof(emm_data_context_t));
         if (emm_ctx == NULL) {
             LOG_TRACE(WARNING, "EMM-PROC  - Failed to create EMM context");
             ue_ctx.emm_cause = EMM_CAUSE_ILLEGAL_UE;
@@ -1116,9 +1116,9 @@ int emm_proc_attach_request(unsigned int ueid, emm_proc_attach_type_t type,
         (*emm_ctx)->esm_msg.length = 0;
         (*emm_ctx)->esm_msg.value = NULL;
         (*emm_ctx)->emm_cause = EMM_CAUSE_SUCCESS;
+        (*emm_ctx)->_emm_fsm_status = EMM_INVALID;
 
-        (*emm_ctx)->_emm_fsm_status = EMM_DEREGISTERED;
-
+        emm_fsm_set_status(ueid, *emm_ctx, EMM_DEREGISTERED);
 #if defined(EPC_BUILD)
         emm_data_context_add(&_emm_data, *(emm_ctx));
 #endif
@@ -1849,7 +1849,7 @@ static int _emm_attach_identify(void *args)
 #if defined(EPC_BUILD)
         if (!emm_ctx->security) {
             /* Ask upper layer to fetch new security context */
-            nas_itti_auth_info_req(emm_ctx->ueid, emm_ctx->imsi, 1);
+            nas_itti_auth_info_req(emm_ctx->ueid, emm_ctx->imsi, 1, NULL);
 
             rc = RETURNok;
         } else
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/Authentication.c b/openair-cn/NAS/EURECOM-NAS/src/emm/Authentication.c
index c85e92f43c..bf12329b0d 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/Authentication.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/Authentication.c
@@ -32,6 +32,9 @@ Description Defines the authentication EMM procedure executed by the
 
 *****************************************************************************/
 
+#include <stdlib.h> // malloc, free
+#include <string.h> // memcpy, memcmp, memset
+
 #include "emm_proc.h"
 #include "nas_log.h"
 #include "nas_timer.h"
@@ -45,8 +48,11 @@ Description Defines the authentication EMM procedure executed by the
 #include "usim_api.h"
 #endif
 
-#include <stdlib.h> // malloc, free
-#include <string.h> // memcpy, memcmp, memset
+#ifdef NAS_MME
+# if defined(EPC_BUILD)
+#   include "nas_itti_messaging.h"
+# endif
+#endif
 
 /****************************************************************************/
 /****************  E X T E R N A L    D E F I N I T I O N S  ****************/
@@ -534,7 +540,7 @@ int emm_proc_authentication(void *ctx, unsigned int ueid, int ksi,
 
     LOG_FUNC_IN;
 
-    LOG_TRACE(INFO, "EMM-PROC  - Initiate authentication KSI = %d", ksi);
+    LOG_TRACE(INFO, "EMM-PROC  - Initiate authentication KSI = %d, ctx = %p", ksi, ctx);
 
     /* Allocate parameters of the retransmission timer callback */
     data = (authentication_data_t *)malloc(sizeof(authentication_data_t));
@@ -616,11 +622,11 @@ int emm_proc_authentication(void *ctx, unsigned int ueid, int ksi,
 int emm_proc_authentication_complete(unsigned int ueid, int emm_cause,
                                      const OctetString *res)
 {
-    LOG_FUNC_IN;
-
     int rc;
     emm_sap_t emm_sap;
 
+    LOG_FUNC_IN;
+
     LOG_TRACE(INFO, "EMM-PROC  - Authentication complete (ueid=%u, cause=%d)",
               ueid, emm_cause);
 
@@ -665,21 +671,40 @@ int emm_proc_authentication_complete(unsigned int ueid, int emm_cause,
     }
 
     if (emm_cause != EMM_CAUSE_SUCCESS) {
-        /* The MME received an authentication failure message or the RES
-         * contained in the Authentication Response message received from
-         * the UE does not match the XRES parameter computed by the network */
-        (void) _authentication_reject(ueid);
-        /*
-         * Notify EMM that the authentication procedure failed
-         */
-        emm_sap.primitive = EMMREG_COMMON_PROC_REJ;
-        emm_sap.u.emm_reg.ueid = ueid;
+        switch (emm_cause) {
+
+#if defined(EPC_BUILD)
+            case EMM_CAUSE_SYNCH_FAILURE:
+                /* USIM has detected a mismatch in SQN.
+                 * Ask for a new vector.
+                 */
+                nas_itti_auth_info_req(ueid, emm_ctx->imsi, 0, res->value);
+
+                rc = RETURNok;
+                LOG_FUNC_RETURN (rc);
+                break;
+#endif
+
+            default:
+                /* The MME received an authentication failure message or the RES
+                 * contained in the Authentication Response message received from
+                 * the UE does not match the XRES parameter computed by the network */
+                (void) _authentication_reject(ueid);
+                /*
+                 * Notify EMM that the authentication procedure failed
+                 */
+                emm_sap.primitive = EMMREG_COMMON_PROC_REJ;
+                emm_sap.u.emm_reg.ueid = ueid;
+                emm_sap.u.emm_reg.ctx  = emm_ctx;
+                break;
+        }
     } else {
         /*
          * Notify EMM that the authentication procedure successfully completed
          */
         emm_sap.primitive = EMMREG_COMMON_PROC_CNF;
         emm_sap.u.emm_reg.ueid = ueid;
+        emm_sap.u.emm_reg.ctx  = emm_ctx;
         emm_sap.u.emm_reg.u.common.is_attached = emm_ctx->is_attached;
     }
 
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/Identification.c b/openair-cn/NAS/EURECOM-NAS/src/emm/Identification.c
index 64715d7108..b6a246870c 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/Identification.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/Identification.c
@@ -233,8 +233,8 @@ int emm_proc_identification(unsigned int                   ueid,
 
     int rc = RETURNerror;
 
-    LOG_TRACE(INFO, "EMM-PROC  - Initiate identification type = %s (%d)",
-              _emm_identity_type_str[type], type);
+    LOG_TRACE(INFO, "EMM-PROC  - Initiate identification type = %s (%d), ctx = %p",
+              _emm_identity_type_str[type], type, emm_ctx);
 
     /* Allocate parameters of the retransmission timer callback */
     identification_data_t *data =
@@ -363,6 +363,7 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t *imsi,
          */
         emm_sap.primitive = EMMREG_COMMON_PROC_CNF;
         emm_sap.u.emm_reg.ueid = ueid;
+        emm_sap.u.emm_reg.ctx  = emm_ctx;
         emm_sap.u.emm_reg.u.common.is_attached = emm_ctx->is_attached;
     } else {
         LOG_TRACE(ERROR, "EMM-PROC  - No EMM context exists");
@@ -371,6 +372,7 @@ int emm_proc_identification_complete(unsigned int ueid, const imsi_t *imsi,
          */
         emm_sap.primitive = EMMREG_COMMON_PROC_REJ;
         emm_sap.u.emm_reg.ueid = ueid;
+        emm_sap.u.emm_reg.ctx  = emm_ctx;
     }
 
     rc = emm_sap_send(&emm_sap);
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c b/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c
index 66f355b25b..cebf14c0c0 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c
@@ -39,6 +39,11 @@ Description Defines the security mode control EMM procedure executed by the
 
 #include <stdlib.h> // malloc, free
 #include <string.h> // memcpy
+#include <inttypes.h>
+
+#if defined(ENABLE_ITTI)
+# include "assertions.h"
+#endif
 
 /****************************************************************************/
 /****************  E X T E R N A L    D E F I N I T I O N S  ****************/
@@ -438,6 +443,7 @@ int emm_proc_security_mode_control(unsigned int ueid, int ksi, int eea, int eia,
             emm_sap_t emm_sap;
             emm_sap.primitive = EMMREG_COMMON_PROC_REQ;
             emm_sap.u.emm_reg.ueid = ueid;
+            emm_sap.u.emm_reg.ctx  = emm_ctx;
             rc = emm_sap_send(&emm_sap);
         }
     }
@@ -568,6 +574,7 @@ int emm_proc_security_mode_reject(unsigned int ueid)
 #if defined(EPC_BUILD)
     if (ueid > 0) {
         emm_ctx = emm_data_context_get(&_emm_data, ueid);
+        DevAssert(emm_ctx != NULL);
     }
 #else
     if (ueid < EMM_DATA_NB_UE_MAX) {
@@ -591,6 +598,7 @@ int emm_proc_security_mode_reject(unsigned int ueid)
     emm_sap_t emm_sap;
     emm_sap.primitive = EMMREG_COMMON_PROC_REJ;
     emm_sap.u.emm_reg.ueid = ueid;
+    emm_sap.u.emm_reg.ctx  = emm_ctx;
     rc = emm_sap_send(&emm_sap);
 
     LOG_FUNC_RETURN (rc);
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_as.c b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_as.c
index 6adccff52d..33519a2398 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_as.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_as.c
@@ -449,7 +449,7 @@ static int _emm_as_data_ind(const emm_as_data_t *msg, int *emm_cause)
     int rc = RETURNerror;
 
     LOG_TRACE(INFO, "EMMAS-SAP - Received AS data transfer indication "
-              "(ueid=%d, delivered=%s, length=%d)", msg->ueid,
+              "(ueid=%u, delivered=%s, length=%d)", msg->ueid,
               (msg->delivered)? "TRUE" : "FALSE", msg->NASmsg.length);
 
     if (msg->delivered) {
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_fsm.c b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_fsm.c
index 104e17e7e2..4a7f3ab47a 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_fsm.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_fsm.c
@@ -92,6 +92,7 @@ static const char *_emm_fsm_event_str[] = {
 
 /* String representation of EMM status */
 static const char *_emm_fsm_status_str[EMM_STATE_MAX] = {
+     "INVALID",
 #ifdef NAS_UE
     "NULL",
 #endif
@@ -164,6 +165,7 @@ int EmmCommonProcedureInitiated(const emm_reg_t *);
 
 /* EMM state machine handlers */
 static const emm_fsm_handler_t _emm_fsm_handlers[EMM_STATE_MAX] = {
+    NULL,
 #ifdef NAS_UE
     EmmNull,
 #endif
@@ -371,7 +373,7 @@ int emm_fsm_process(const emm_reg_t *evt)
 
     DevAssert(emm_ctx != NULL);
 
-    status = emm_ctx->_emm_fsm_status;
+    status = emm_fsm_get_status(0, emm_ctx);
 # else
     if (evt->ueid >= EMM_FSM_NB_UE_MAX) {
         LOG_FUNC_RETURN (RETURNerror);
@@ -384,6 +386,8 @@ int emm_fsm_process(const emm_reg_t *evt)
               _emm_fsm_event_str[primitive - _EMMREG_START - 1], primitive,
               _emm_fsm_status_str[status]);
 
+    DevAssert(status != EMM_INVALID);
+
     /* Execute the EMM state machine */
     rc = (_emm_fsm_handlers[status])(evt);
 
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_fsm.h b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_fsm.h
index 00b893dca7..7e70675671 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_fsm.h
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_fsm.h
@@ -38,6 +38,7 @@ Description Defines the EPS Mobility Management procedures executed at
  * different state machines.
  */
 typedef enum {
+    EMM_INVALID,
 #ifdef NAS_UE
     EMM_NULL,
 #endif
diff --git a/openair-cn/NAS/nas_itti_messaging.h b/openair-cn/NAS/nas_itti_messaging.h
index a0e82fad17..0027621139 100644
--- a/openair-cn/NAS/nas_itti_messaging.h
+++ b/openair-cn/NAS/nas_itti_messaging.h
@@ -27,14 +27,16 @@
                  06410 Biot FRANCE
 
 *******************************************************************************/
-#ifndef NAS_ITTI_MESSAGING_H_
-#define NAS_ITTI_MESSAGING_H_
 
+#include <string.h>
 #include <stdint.h>
 #include <ctype.h>
 
 #include "intertask_interface.h"
 
+#ifndef NAS_ITTI_MESSAGING_H_
+#define NAS_ITTI_MESSAGING_H_
+
 # if defined(EPC_BUILD) && defined(NAS_MME)
 #include "conversions.h"
 
@@ -45,7 +47,7 @@ void nas_itti_establish_cnf(const nas_error_code_t error_code, void *const data,
                             const uint32_t length);
 
 static inline void nas_itti_auth_info_req(const uint32_t ue_id,
-        const imsi_t *const imsi, uint8_t initial_req)
+        const imsi_t *const imsi, uint8_t initial_req, const uint8_t *auts)
 {
     MessageDef *message_p;
 
@@ -65,6 +67,15 @@ static inline void nas_itti_auth_info_req(const uint32_t ue_id,
     NAS_AUTHENTICATION_PARAM_REQ(message_p).initial_req = initial_req;
     NAS_AUTHENTICATION_PARAM_REQ(message_p).ue_id = ue_id;
 
+    /* Re-synchronisation */
+    if (auts != NULL) {
+        NAS_AUTHENTICATION_PARAM_REQ(message_p).re_synchronization = 1;
+        memcpy(NAS_AUTHENTICATION_PARAM_REQ(message_p).auts, auts, AUTS_LENGTH);
+    } else {
+        NAS_AUTHENTICATION_PARAM_REQ(message_p).re_synchronization = 0;
+        memset(NAS_AUTHENTICATION_PARAM_REQ(message_p).auts, 0, AUTS_LENGTH);
+    }
+
     itti_send_msg_to_task(TASK_MME_APP, INSTANCE_DEFAULT, message_p);
 }
 
diff --git a/openair-cn/S1AP/s1ap_mme_nas_procedures.c b/openair-cn/S1AP/s1ap_mme_nas_procedures.c
index 037a0571c2..00186f3763 100644
--- a/openair-cn/S1AP/s1ap_mme_nas_procedures.c
+++ b/openair-cn/S1AP/s1ap_mme_nas_procedures.c
@@ -207,6 +207,8 @@ int s1ap_generate_downlink_nas_transport(const uint32_t ue_id, void * const data
         message.procedureCode = S1ap_ProcedureCode_id_downlinkNASTransport;
         message.direction     = S1AP_PDU_PR_initiatingMessage;
 
+        ue_ref->s1_ue_state = S1AP_UE_CONNECTED;
+
         downlinkNasTransport = &message.msg.s1ap_DownlinkNASTransportIEs;
 
         /* Setting UE informations with the ones fount in ue_ref */
@@ -224,7 +226,7 @@ int s1ap_generate_downlink_nas_transport(const uint32_t ue_id, void * const data
         s1ap_mme_itti_send_sctp_request(buffer_p, length,
                                         ue_ref->eNB->sctp_assoc_id,
                                         ue_ref->sctp_stream_send);
-        s1ap_mme_itti_nas_downlink_cnf(ue_ref->mme_ue_s1ap_id, AS_SUCCESS);
+        //s1ap_mme_itti_nas_downlink_cnf(ue_ref->mme_ue_s1ap_id, AS_SUCCESS);
     }
     return 0;
 }
diff --git a/openair-cn/S6A/s6a_auth_info.c b/openair-cn/S6A/s6a_auth_info.c
index e7b900198d..e826e37dd3 100644
--- a/openair-cn/S6A/s6a_auth_info.c
+++ b/openair-cn/S6A/s6a_auth_info.c
@@ -340,11 +340,10 @@ int s6a_generate_authentication_info_req(s6a_auth_info_req_t *air_p)
 
     /* Adding the visited plmn id */
     {
-        uint8_t plmn[3] = { 0, 0, 0 };
+        uint8_t plmn[3] = { 0x02, 0xF8, 0x29 };
 
         CHECK_FCT(fd_msg_avp_new(s6a_fd_cnf.dataobj_s6a_visited_plmn_id, 0, &avp));
 
-        PLMN_T_TO_TBCD(air_p->visited_plmn, plmn);
 
         value.os.data = plmn;
         value.os.len  = 3;
@@ -372,6 +371,15 @@ int s6a_generate_authentication_info_req(s6a_auth_info_req_t *air_p)
         CHECK_FCT(fd_msg_avp_setvalue(child_avp, &value));
         CHECK_FCT(fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, child_avp));
 
+        /* Re-synchronization information containing the AUTS computed at USIM */
+        if (air_p->re_synchronization) {
+            CHECK_FCT(fd_msg_avp_new(s6a_fd_cnf.dataobj_s6a_re_synchronization_info, 0, &child_avp));
+            value.os.len = AUTS_LENGTH;
+            value.os.data = air_p->auts;
+            CHECK_FCT(fd_msg_avp_setvalue(child_avp, &value));
+            CHECK_FCT(fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, child_avp));
+        }
+
         CHECK_FCT(fd_msg_avp_add(msg, MSG_BRW_LAST_CHILD, avp));
     }
     CHECK_FCT(fd_msg_send(&msg, NULL, NULL));
diff --git a/openair-cn/S6A/s6a_defs.h b/openair-cn/S6A/s6a_defs.h
index db4c0da782..90ec8e96bf 100644
--- a/openair-cn/S6A/s6a_defs.h
+++ b/openair-cn/S6A/s6a_defs.h
@@ -117,6 +117,7 @@ typedef struct {
     struct dict_object *dataobj_s6a_number_of_requested_vectors;
     struct dict_object *dataobj_s6a_immediate_response_pref;
     struct dict_object *dataobj_s6a_authentication_info;
+    struct dict_object *dataobj_s6a_re_synchronization_info;
     struct dict_object *dataobj_s6a_ue_srvcc_cap;
 
     /* Handlers */
diff --git a/openair-cn/S6A/s6a_dict.c b/openair-cn/S6A/s6a_dict.c
index 3f7c286c01..934bff910d 100644
--- a/openair-cn/S6A/s6a_dict.c
+++ b/openair-cn/S6A/s6a_dict.c
@@ -146,6 +146,9 @@ int s6a_fd_init_dict_objs(void)
     CHECK_FD_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP,
                                 AVP_BY_NAME_ALL_VENDORS, "Authentication-Info",
                                 &s6a_fd_cnf.dataobj_s6a_authentication_info, ENOENT));
+    CHECK_FD_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP,
+                                AVP_BY_NAME_ALL_VENDORS, "Re-Synchronization-Info",
+                                &s6a_fd_cnf.dataobj_s6a_re_synchronization_info, ENOENT));
     CHECK_FD_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP,
                                 AVP_BY_NAME_ALL_VENDORS, "UE-SRVCC-Capability",
                                 &s6a_fd_cnf.dataobj_s6a_ue_srvcc_cap, ENOENT));
diff --git a/openair-cn/SCTP/sctp_eNB_task.c b/openair-cn/SCTP/sctp_eNB_task.c
index cc1d8dd950..612a3dc687 100644
--- a/openair-cn/SCTP/sctp_eNB_task.c
+++ b/openair-cn/SCTP/sctp_eNB_task.c
@@ -560,9 +560,10 @@ void *sctp_eNB_task(void *arg)
                                ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg));
                     break;
             }
+
+            itti_free(TASK_SCTP, received_msg);
+            received_msg = NULL;
         }
-        free(received_msg);
-        received_msg = NULL;
 
         nb_events = itti_get_events(TASK_SCTP, &events);
         /* Now handle notifications for other sockets */
diff --git a/openair-cn/UTILS/CONF/epc_caviar.conf b/openair-cn/UTILS/CONF/epc_caviar.conf
index a3aa2df051..d229618d30 100644
--- a/openair-cn/UTILS/CONF/epc_caviar.conf
+++ b/openair-cn/UTILS/CONF/epc_caviar.conf
@@ -41,7 +41,7 @@ MME_GID = 3,4,5,30,8,9,50021;
 # TA (mcc.mnc:tracking area code) DEFAULT = 208.34:0
 # max values = 999.999:65535
 # maximum of 32 values, comma separated
-PLMN = 208.38:0,209.130:4,208.35:8;
+PLMN = 208.38:0,209.130:4,208.92:0;
 
 # ------- Interfaces definitions
 SGW_INTERFACE_NAME_FOR_S11            = "eth0";
diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
index 53042fda14..1777466501 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
@@ -1600,7 +1600,6 @@ int dump_dci(LTE_DL_FRAME_PARMS *frame_parms, DCI_ALLOC_t *dci) {
   default:
     LOG_E(PHY,"dci_tools.c: dump_dci, unknown format %d\n",dci->format);
     return(-1);
-    break;
   }
   return(0);
 }
diff --git a/openair1/PHY/LTE_TRANSPORT/rar_tools.c b/openair1/PHY/LTE_TRANSPORT/rar_tools.c
index 60776cbfe8..78649a26f8 100644
--- a/openair1/PHY/LTE_TRANSPORT/rar_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/rar_tools.c
@@ -152,7 +152,7 @@ int generate_eNB_ulsch_params_from_rar(unsigned char *rar_pdu,
     ulsch->harq_processes[harq_pid]->rvidx = 0;
     ulsch->harq_processes[harq_pid]->round++;
   }
-  //#ifdef DEBUG_RAR
+#ifdef DEBUG_RAR
   msg("ulsch ra (eNB): harq_pid %d\n",harq_pid);
   msg("ulsch ra (eNB): NBRB     %d\n",ulsch->harq_processes[harq_pid]->nb_rb);
   msg("ulsch ra (eNB): rballoc  %x\n",ulsch->harq_processes[harq_pid]->first_rb);
@@ -162,7 +162,7 @@ int generate_eNB_ulsch_params_from_rar(unsigned char *rar_pdu,
   msg("ulsch ra (eNB): mcs      %d\n",ulsch->harq_processes[harq_pid]->mcs);
   msg("ulsch ra (eNB): Or1      %d\n",ulsch->Or1);
   msg("ulsch ra (eNB): ORI      %d\n",ulsch->O_RI);
-  //#endif
+#endif
   return(0);
 }
 
diff --git a/openair2/ENB_APP/enb_app.c b/openair2/ENB_APP/enb_app.c
index 524827efae..47e9ce7dc5 100644
--- a/openair2/ENB_APP/enb_app.c
+++ b/openair2/ENB_APP/enb_app.c
@@ -111,7 +111,7 @@ static Enb_properties_t enb_0_properties =
     "eNB_Eurecom_0",
     0,
     208,
-    34,
+    92,
     PAGING_DRX_256,
     1, /* There are 2 addresses defined, but use only one by default */
     {
@@ -138,7 +138,7 @@ static Enb_properties_t enb_1_properties =
     "eNB_Eurecom_1",
     0,
     208,
-    34,
+    92,
     PAGING_DRX_256,
     1, /* There are 2 addresses defined, but use only one by default */
     {
@@ -165,7 +165,7 @@ static Enb_properties_t enb_2_properties =
     "eNB_Eurecom_2",
     0,
     208,
-    34,
+    92,
     PAGING_DRX_256,
     1,
     {
@@ -186,7 +186,7 @@ static Enb_properties_t enb_3_properties =
     "eNB_Eurecom_3",
     0,
     208,
-    34,
+    92,
     PAGING_DRX_256,
     1,
     {
diff --git a/targets/RTAI/USER/Makefile b/targets/RTAI/USER/Makefile
index ef88f86a5b..3a1e372e25 100644
--- a/targets/RTAI/USER/Makefile
+++ b/targets/RTAI/USER/Makefile
@@ -113,6 +113,7 @@ endif
 
 ifdef ENABLE_ITTI
 RTAI_OBJ += $(UTILS_OBJS)
+CFLAGS += -DEXMIMO_IOT
 endif
 
 CFLAGS += $(L2_incl) $(ENB_APP_incl) $(UTIL_incl) $(UTILS_incl)
@@ -335,7 +336,8 @@ run_eNB2:
 clean: common-clean
 	@$(RM_F_V) $(OBJ) $(RTAI_OBJ)
 	@$(RM_F_V) $(OBJ:.o=.d) $(RTAI_OBJ:.o=.d)
-	@$(RM_F_V) $(ASN1_MSG_INC)/asn1_msg.o $(ASN1_MSG_INC)/asn1_msg.d
+	@$(RM_F_V) $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1_msg.o $(OPENAIR2_DIR)/RRC/LITE/MESSAGES/asn1_msg.d
+	@$(RM_F_V) lte-enb.o lte-enb.d lte-softmodem.o lte-softmodem.d
 
 cleanasn1:
 	rm -f $(ASN1_MSG_OBJS1)
-- 
2.26.2