From f4ab618ae03b18d85645f08d0af97a910dd9f15a Mon Sep 17 00:00:00 2001
From: Lionel Gauthier <lionel.gauthier@eurecom.fr>
Date: Tue, 13 May 2014 11:39:38 +0000
Subject: [PATCH] compilation OK for UE+eNB virtualized

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5318 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair-cn/COMMON/security_types.h            |  2 +
 .../NAS/EURECOM-NAS/src/emm/LowerLayer.c      |  2 +-
 openair-cn/NAS/EURECOM-NAS/src/emm/emmData.h  | 40 ++++++-------
 ...ModeCommand.h => NASSecurityModeCommand.h} |  6 +-
 ...deComplete.h => NASSecurityModeComplete.h} |  0
 .../src/emm/msg/SecurityModeCommand.c         |  2 +-
 .../src/emm/msg/SecurityModeComplete.c        |  2 +-
 .../NAS/EURECOM-NAS/src/emm/msg/emm_msg.h     |  4 +-
 .../NAS/EURECOM-NAS/src/emm/sap/emm_as.c      | 58 +++++++++++++++---
 .../NAS/EURECOM-NAS/src/emm/sap/emm_recv.h    |  2 +-
 .../NAS/EURECOM-NAS/src/emm/sap/emm_send.h    |  4 +-
 openair-cn/NAS/Makefile.UE                    |  9 ++-
 openair-cn/NAS/Makefile.inc                   |  4 +-
 openair-cn/SECU/Makefile.eNB                  | 59 +++++++++++--------
 openair-cn/SECU/secu_defs.h                   |  3 +-
 openair2/RRC/LITE/rrc_eNB.c                   | 22 +++----
 openair2/RRC/LITE/rrc_eNB_S1AP.c              |  2 +-
 targets/Makefile.common                       | 45 +++++++++-----
 .../start_enb_and_ue_virt.bash                |  2 +-
 19 files changed, 168 insertions(+), 100 deletions(-)
 rename openair-cn/NAS/EURECOM-NAS/src/emm/msg/{SecurityModeCommand.h => NASSecurityModeCommand.h} (95%)
 rename openair-cn/NAS/EURECOM-NAS/src/emm/msg/{SecurityModeComplete.h => NASSecurityModeComplete.h} (100%)

diff --git a/openair-cn/COMMON/security_types.h b/openair-cn/COMMON/security_types.h
index 1806a39efd..c083b9ebff 100644
--- a/openair-cn/COMMON/security_types.h
+++ b/openair-cn/COMMON/security_types.h
@@ -10,7 +10,9 @@
 #include <stdint.h>
 #include <inttypes.h>
 
+#if 0
 #include "queue.h"
+#endif
 
 #ifndef SECURITY_TYPES_H_
 #define SECURITY_TYPES_H_
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/LowerLayer.c b/openair-cn/NAS/EURECOM-NAS/src/emm/LowerLayer.c
index 50a7a99458..0b737427b4 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/LowerLayer.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/LowerLayer.c
@@ -206,7 +206,7 @@ int lowerlayer_data_ind(unsigned int ueid, const OctetString *data)
     esm_sap_t esm_sap;
     int rc;
 #if defined(NAS_MME)
-    emm_data_context_t *emm_ctx;
+    emm_data_context_t *emm_ctx = NULL;
 #endif
 
     LOG_FUNC_IN;
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/emmData.h b/openair-cn/NAS/EURECOM-NAS/src/emm/emmData.h
index afc061fb4e..c73ccd417b 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/emmData.h
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/emmData.h
@@ -188,17 +188,17 @@ typedef struct {
  * -------------------------
  */
 typedef struct {
-    int usim_is_valid;  /* Indication of USIM data validity     */
+    int                 usim_is_valid;  /* Indication of USIM data validity   */
 
-    imei_t *imei;   /* IMEI read from the UE's non-volatile memory  */
-    const imsi_t *imsi; /* The valid IMSI read from the USIM        */
-    GUTI_t *guti;   /* The valid GUTI read from the USIM        */
-    tai_t  *tai;    /* Last visited registered Tracking Area Id */
+    imei_t             *imei;   /* IMEI read from the UE's non-volatile memory*/
+    const imsi_t       *imsi; /* The valid IMSI read from the USIM            */
+    GUTI_t             *guti;   /* The valid GUTI read from the USIM          */
+    tai_t              *tai;    /* Last visited registered Tracking Area Id   */
 
-    emm_eps_update_t status;    /* The current EPS update status    */
-    emm_ecm_state_t ecm_status; /* The EPS Connection Management status */
-    int is_attached;    /* Network attachment indicator         */
-    int is_emergency;   /* Emergency bearer services indicator      */
+    emm_eps_update_t    status;    /* The current EPS update status           */
+    emm_ecm_state_t     ecm_status; /* The EPS Connection Management status   */
+    int                 is_attached;    /* Network attachment indicator       */
+    int                 is_emergency;   /* Emergency bearer services indicator*/
 
     /* Tracking Areas list the UE is registered to
      * Contains the list of TAIs that identify the tracking areas that
@@ -209,17 +209,17 @@ typedef struct {
 #define EMM_DATA_TAI_MAX        16
     TAI_LIST_T(EMM_DATA_TAI_MAX) ltai;
 
-    int plmn_mode;  /* Network selection operating mode       */
-    int plmn_index; /* Manually selected PLMN             */
-    int plmn_rat;   /* Manually selected Radio Access Technology      */
-
-    plmn_t splmn;   /* The currently selected PLMN            */
-    int is_rplmn;   /* splmn is the registered PLMN           */
-    int is_eplmn;   /* splmn is in the list of equivalent PLMNs   */
-    Stat_t stat;    /* Current network registration status        */
-    tac_t tac;      /* Tracking area code                 */
-    ci_t ci;        /* GERAN/UTRAN/E-UTRAN serving cell identifier    */
-    AcT_t rat;      /* Radio Access Technology of the serving cell    */
+    int                 plmn_mode;  /* Network selection operating mode       */
+    int                 plmn_index; /* Manually selected PLMN                 */
+    int                 plmn_rat; /* Manually selected Radio Access Technology*/
+
+    plmn_t              splmn;      /* The currently selected PLMN            */
+    int                 is_rplmn;   /* splmn is the registered PLMN           */
+    int                 is_eplmn; /* splmn is in the list of equivalent PLMNs */
+    Stat_t              stat;    /* Current network registration status       */
+    tac_t               tac;   /* Tracking area code                          */
+    ci_t                ci;    /* GERAN/UTRAN/E-UTRAN serving cell identifier */
+    AcT_t               rat; /* Radio Access Technology of the serving cell   */
 
     /* An octet string representation of operators present in the network */
     struct {
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeCommand.h b/openair-cn/NAS/EURECOM-NAS/src/emm/msg/NASSecurityModeCommand.h
similarity index 95%
rename from openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeCommand.h
rename to openair-cn/NAS/EURECOM-NAS/src/emm/msg/NASSecurityModeCommand.h
index 1b322fce05..ab99b5dca0 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeCommand.h
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/msg/NASSecurityModeCommand.h
@@ -11,8 +11,8 @@
 #include "ImeisvRequest.h"
 #include "Nonce.h"
 
-#ifndef SECURITY_MODE_COMMAND_H_
-#define SECURITY_MODE_COMMAND_H_
+#ifndef NAS_SECURITY_MODE_COMMAND_H_
+#define NAS_SECURITY_MODE_COMMAND_H_
 
 /* Minimum length macro. Formed by minimum length of each mandatory field */
 #define SECURITY_MODE_COMMAND_MINIMUM_LENGTH ( \
@@ -68,5 +68,5 @@ int decode_security_mode_command(security_mode_command_msg *securitymodecommand,
 
 int encode_security_mode_command(security_mode_command_msg *securitymodecommand, uint8_t *buffer, uint32_t len);
 
-#endif /* ! defined(SECURITY_MODE_COMMAND_H_) */
+#endif /* ! defined(NAS_SECURITY_MODE_COMMAND_H_) */
 
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeComplete.h b/openair-cn/NAS/EURECOM-NAS/src/emm/msg/NASSecurityModeComplete.h
similarity index 100%
rename from openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeComplete.h
rename to openair-cn/NAS/EURECOM-NAS/src/emm/msg/NASSecurityModeComplete.h
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeCommand.c b/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeCommand.c
index c32dec1550..d86d0e0d2d 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeCommand.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeCommand.c
@@ -6,7 +6,7 @@
 
 #include "TLVEncoder.h"
 #include "TLVDecoder.h"
-#include "SecurityModeCommand.h"
+#include "NASSecurityModeCommand.h"
 
 int decode_security_mode_command(security_mode_command_msg *security_mode_command, uint8_t *buffer, uint32_t len)
 {
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeComplete.c b/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeComplete.c
index d58216407f..b334d352d8 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeComplete.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/msg/SecurityModeComplete.c
@@ -6,7 +6,7 @@
 
 #include "TLVEncoder.h"
 #include "TLVDecoder.h"
-#include "SecurityModeComplete.h"
+#include "NASSecurityModeComplete.h"
 
 int decode_security_mode_complete(security_mode_complete_msg *security_mode_complete, uint8_t *buffer, uint32_t len)
 {
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/msg/emm_msg.h b/openair-cn/NAS/EURECOM-NAS/src/emm/msg/emm_msg.h
index e72e35a193..a2e68d0b2a 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/msg/emm_msg.h
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/msg/emm_msg.h
@@ -44,8 +44,8 @@ Description	Defines EPS Mobility Management messages and functions used
 #include "AuthenticationFailure.h"
 #include "IdentityRequest.h"
 #include "IdentityResponse.h"
-#include "SecurityModeCommand.h"
-#include "SecurityModeComplete.h"
+#include "NASSecurityModeCommand.h"
+#include "NASSecurityModeComplete.h"
 #include "SecurityModeReject.h"
 #include "EmmStatus.h"
 #include "EmmInformation.h"
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 9315bc4abd..1de8ef1255 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
@@ -23,6 +23,7 @@ Description Defines the EMMAS Service Access Point that provides
 #include "emm_as.h"
 #include "emm_recv.h"
 #include "emm_send.h"
+#include "emmData.h"
 #include "commonDef.h"
 #include "nas_log.h"
 
@@ -321,8 +322,11 @@ static int _emm_as_recv(unsigned int ueid, const char *msg, int len,
     nas_message_t nas_msg;
     memset(&nas_msg, 0 , sizeof(nas_message_t));
 
-    emm_data_context_t           *emm_ctx  = NULL;
     emm_security_context_t       *security = NULL;    /* Current EPS NAS security context     */
+#if defined(NAS_MME)
+#if defined(EPC_BUILD)
+    emm_data_context_t           *emm_ctx  = NULL;
+#endif
 
 #if defined(EPC_BUILD)
     emm_ctx = emm_data_context_get(&_emm_data, ueid);
@@ -332,8 +336,14 @@ static int _emm_as_recv(unsigned int ueid, const char *msg, int len,
 #else
     if (ueid < EMM_DATA_NB_UE_MAX) {
         emm_ctx = _emm_data.ctx[ueid];
+        if (emm_ctx) {
+            security = emm_ctx->security;
+        }
     }
 #endif
+#else /* NAS_MME */
+    security = _emm_data.security;
+#endif
 
     /* Decode the received message */
     decoder_rc = nas_message_decode(msg, &nas_msg, len, security);
@@ -494,11 +504,12 @@ static int _emm_as_data_ind(const emm_as_data_t *msg, int *emm_cause)
             char *plain_msg = (char *)malloc(msg->NASmsg.length);
             if (plain_msg) {
                 nas_message_security_header_t header;
-                emm_data_context_t           *emm_ctx  = NULL;
                 emm_security_context_t       *security = NULL;    /* Current EPS NAS security context     */
 
                 memset(&header, 0, sizeof(header));
                 /* Decrypt the received security protected message */
+#if defined(NAS_MME)
+                emm_data_context_t           *emm_ctx  = NULL;
 #if defined(EPC_BUILD)
                 if (msg->ueid > 0) {
                     emm_ctx = emm_data_context_get(&_emm_data, msg->ueid);
@@ -513,6 +524,9 @@ static int _emm_as_data_ind(const emm_as_data_t *msg, int *emm_cause)
                         security = emm_ctx->security;
                     }
                 }
+#endif
+#else
+                security = _emm_data.security;
 #endif
                 int bytes = nas_message_decrypt((char *)(msg->NASmsg.value),
                                                 plain_msg,
@@ -590,8 +604,11 @@ static int _emm_as_establish_cnf(const emm_as_establish_t *msg,
     memset(&nas_msg, 0 , sizeof(nas_message_t));
 
     /* Decode initial NAS message */
-    decoder_rc = nas_message_decode((char *)(msg->NASmsg.value), &nas_msg,
-                                    msg->NASmsg.length);
+    decoder_rc = nas_message_decode((char *)(msg->NASmsg.value),
+        &nas_msg,
+        msg->NASmsg.length,
+        _emm_data.security);
+
     if (decoder_rc < 0) {
         LOG_TRACE(WARNING, "EMMAS-SAP - Failed to decode initial NAS message"
                   "(err=%d)", decoder_rc);
@@ -756,6 +773,7 @@ static int _emm_as_establish_req(const emm_as_establish_t *msg, int *emm_cause)
     nas_message_t nas_msg;
     memset(&nas_msg, 0 , sizeof(nas_message_t));
 
+#if defined(NAS_MME)
 #if defined(EPC_BUILD)
     emm_ctx = emm_data_context_get(&_emm_data, msg->ueid);
 #else
@@ -766,6 +784,10 @@ static int _emm_as_establish_req(const emm_as_establish_t *msg, int *emm_cause)
     if (emm_ctx) {
         emm_security_context = emm_ctx->security;
     }
+#else /* NAS_MME */
+    security = _emm_data.security;
+#endif
+
 
     /* Decode initial NAS message */
     decoder_rc = nas_message_decode(
@@ -1353,8 +1375,9 @@ static int _emm_as_data_req(const emm_as_data_t *msg,
 
     if (size > 0) {
         int bytes;
-        struct emm_data_context_s *emm_ctx                = NULL;
         emm_security_context_t    *emm_security_context   = NULL;
+#if defined(NAS_MME)
+        struct emm_data_context_s *emm_ctx                = NULL;
 #if defined(EPC_BUILD)
         emm_ctx = emm_data_context_get(&_emm_data, msg->ueid);
 #else
@@ -1365,6 +1388,9 @@ static int _emm_as_data_req(const emm_as_data_t *msg,
         if (emm_ctx) {
             emm_security_context = emm_ctx->security;
         }
+#else
+        emm_security_context = _emm_data.security;
+#endif
 
         if (!is_encoded) {
             /* Encode the NAS information message */
@@ -1438,8 +1464,9 @@ static int _emm_as_status_ind(const emm_as_status_t *msg,
     }
 
     if (size > 0) {
-        struct emm_data_context_s *emm_ctx                = NULL;
         emm_security_context_t    *emm_security_context   = NULL;
+#if defined(NAS_MME)
+        struct emm_data_context_s *emm_ctx                = NULL;
 #if defined(EPC_BUILD)
         emm_ctx = emm_data_context_get(&_emm_data, msg->ueid);
 #else
@@ -1450,6 +1477,9 @@ static int _emm_as_status_ind(const emm_as_status_t *msg,
         if (emm_ctx) {
             emm_security_context = emm_ctx->security;
         }
+#else
+        emm_security_context = _emm_data.security;
+#endif
         /* Encode the NAS information message */
         int bytes = _emm_as_encode(
             &as_msg->nasMsg,
@@ -1587,7 +1617,11 @@ static int _emm_as_security_res(const emm_as_security_t *msg,
 
     if (size > 0) {
         /* Encode the NAS security message */
-        int bytes = _emm_as_encode(&as_msg->nasMsg, &nas_msg, size);
+        int bytes = _emm_as_encode(&as_msg->nasMsg,
+            &nas_msg,
+            size,
+            _emm_data.security);
+
         if (bytes > 0) {
             LOG_FUNC_RETURN (AS_UL_INFO_TRANSFER_REQ);
         }
@@ -1673,7 +1707,12 @@ static int _emm_as_establish_req(const emm_as_establish_t *msg,
 
     if (size > 0) {
         /* Encode the initial NAS information message */
-        int bytes = _emm_as_encode(&as_msg->initialNasMsg, &nas_msg, size);
+        int bytes = _emm_as_encode(
+            &as_msg->initialNasMsg,
+            &nas_msg,
+            size,
+            _emm_data.security);
+
         if (bytes > 0) {
             LOG_FUNC_RETURN (AS_NAS_ESTABLISH_REQ);
         }
@@ -1757,6 +1796,7 @@ static int _emm_as_security_req(const emm_as_security_t *msg,
         if (emm_ctx) {
             emm_security_context = emm_ctx->security;
         }
+
         /* Encode the NAS security message */
         int bytes = _emm_as_encode(
             &as_msg->nasMsg,
@@ -1835,6 +1875,7 @@ static int _emm_as_security_rej(const emm_as_security_t *msg,
         if (emm_ctx) {
             emm_security_context = emm_ctx->security;
         }
+
         /* Encode the NAS security message */
         int bytes = _emm_as_encode(
             &as_msg->nasMsg,
@@ -1926,6 +1967,7 @@ static int _emm_as_establish_cnf(const emm_as_establish_t *msg,
                     as_msg->nas_ul_count);
             }
         }
+
         /* Encode the initial NAS information message */
         int bytes = _emm_as_encode(
             &as_msg->nasMsg,
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_recv.h b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_recv.h
index e9e29f4ec2..8f524eaea5 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_recv.h
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_recv.h
@@ -37,7 +37,7 @@ Description Defines functions executed at the EMMAS Service Access
 #include "AuthenticationRequest.h"
 #include "AuthenticationReject.h"
 #include "IdentityRequest.h"
-#include "SecurityModeCommand.h"
+#include "NASSecurityModeCommand.h"
 #include "EmmInformation.h"
 #include "DownlinkNasTransport.h"
 #include "CsServiceNotification.h"
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_send.h b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_send.h
index 25040dbf66..bcc1c72c82 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_send.h
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/sap/emm_send.h
@@ -38,7 +38,7 @@ Description Defines functions executed at the EMMAS Service Access
 #include "AuthenticationResponse.h"
 #include "AuthenticationFailure.h"
 #include "IdentityResponse.h"
-#include "SecurityModeComplete.h"
+#include "NASSecurityModeComplete.h"
 #include "SecurityModeReject.h"
 #include "UplinkNasTransport.h"
 #endif
@@ -53,7 +53,7 @@ Description Defines functions executed at the EMMAS Service Access
 #include "AuthenticationRequest.h"
 #include "AuthenticationReject.h"
 #include "IdentityRequest.h"
-#include "SecurityModeCommand.h"
+#include "NASSecurityModeCommand.h"
 #include "EmmInformation.h"
 #include "DownlinkNasTransport.h"
 #include "CsServiceNotification.h"
diff --git a/openair-cn/NAS/Makefile.UE b/openair-cn/NAS/Makefile.UE
index cb0d3c01f7..3bf0a327f2 100644
--- a/openair-cn/NAS/Makefile.UE
+++ b/openair-cn/NAS/Makefile.UE
@@ -18,7 +18,10 @@ libnas_INCLUDES =								\
 	-I$(ESMSAPDIR)								\
 	-I$(MMEAPIDIR)								\
 	-I$(USIMAPIDIR)								\
-	-I$(IESDIR)
+	-I$(IESDIR)                                 \
+    -I$(SECU_DIR)                               \
+    -I$(OPENAIRCN_DIR)/COMMON                   \
+    -I$(OPENAIRCN_DIR)/UTILS
 
 OUTDIR = $(UE_NAS_DIR)/ue_objs
 
@@ -277,8 +280,8 @@ CFLAGS =										\
 	-DUE_BUILD									\
 	-Wuninitialized								\
 	-Werror=implicit-function-declaration		\
-	$(libnas_INCLUDES)							\
-	$(UENAS_CFLAGS)
+	$(UENAS_CFLAGS)							\
+	$(libnas_INCLUDES)
 
 .SECONDEXPANSION:
 $(NAS_UE_COMPILED_OBJS): %.o : $$(subst $(OUTDIR), $(UE_NAS_DIR), $$*.c)
diff --git a/openair-cn/NAS/Makefile.inc b/openair-cn/NAS/Makefile.inc
index 3222655e1b..4f5db7f173 100644
--- a/openair-cn/NAS/Makefile.inc
+++ b/openair-cn/NAS/Makefile.inc
@@ -62,7 +62,7 @@ libnas_emm_msg_SRCS =										\
     EURECOM-NAS/src/emm/msg/DetachRequest.c					\
     EURECOM-NAS/src/emm/msg/emm_msgDef.h					\
     EURECOM-NAS/src/emm/msg/GutiReallocationComplete.c		\
-    EURECOM-NAS/src/emm/msg/SecurityModeCommand.h			\
+    EURECOM-NAS/src/emm/msg/NASSecurityModeCommand.h		\
     EURECOM-NAS/src/emm/msg/ServiceRequest.h				\
     EURECOM-NAS/src/emm/msg/TrackingAreaUpdateRequest.h		\
     EURECOM-NAS/src/emm/msg/AttachReject.h					\
@@ -78,7 +78,7 @@ libnas_emm_msg_SRCS =										\
     EURECOM-NAS/src/emm/msg/DownlinkNasTransport.c			\
     EURECOM-NAS/src/emm/msg/EmmStatus.c						\
     EURECOM-NAS/src/emm/msg/IdentityRequest.c				\
-    EURECOM-NAS/src/emm/msg/SecurityModeComplete.h			\
+    EURECOM-NAS/src/emm/msg/NASSecurityModeComplete.h			\
     EURECOM-NAS/src/emm/msg/TrackingAreaUpdateAccept.h		\
     EURECOM-NAS/src/emm/msg/UplinkNasTransport.h			\
     EURECOM-NAS/src/emm/msg/AttachRequest.h					\
diff --git a/openair-cn/SECU/Makefile.eNB b/openair-cn/SECU/Makefile.eNB
index 902f741909..aceed7f8c1 100644
--- a/openair-cn/SECU/Makefile.eNB
+++ b/openair-cn/SECU/Makefile.eNB
@@ -1,38 +1,45 @@
+# include $(OPENAIR_TARGETS)/SIMU/USER/Makerules
+
+OUTDIR = .
+
+
 libsecu_OBJECTS = \
-	kdf.o	\
+	kdf.o				\
 	key_nas_deriver.o	\
 	nas_stream_eea2.o	\
 	nas_stream_eia2.o
 
--include .deps/*.d
-
-.PHONY = depdir
+# pull in dependency info for *existing* .o files
+-include $(OUTDIR)/*.d
 
 CFLAGS = \
-	-I../COMMON	\
-	-I../UTILS	\
-	-DENB_MODE		\
-	-DENABLE_USE_MME	\
-	-DUSER_MODE		\
-	-O2			\
-	-g			\
-	-Wall			\
+	-Wall           \
+	$(SECU_CFLAGS)  \
+	-DENB_MODE      \
+	-Werror=uninitialized   \
 	-Werror=implicit-function-declaration
 
-$(libsecu_OBJECTS): %.o : %.c
-	$(CC) -c $(CFLAGS) -o $@ $<
-	@if ! test -d ".deps/" ; then mkdir -p .deps; fi
-	@$(CC) -MM $(CFLAGS) $*.c > .deps/$*.d
-	@mv -f .deps/$*.d .deps/$*.d.tmp
-	@sed -e 's|.*:|$*.o:|' < .deps/$*.d.tmp > .deps/$*.d
-	@sed -e 's/.*://' -e 's/\\$$//' < .deps/$*.d.tmp | fmt -1 | \
-	sed -e 's/^ *//' -e 's/$$/:/' >> .deps/$*.d
-	@rm -f .deps/$*.d.tmp
+$(OUTDIR)/%.o : %.c
+	@echo "Compiling $<"
+	@if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi;
+	@$(CC) -c $(CFLAGS) -o $@ $<
+	@$(CC) -MM $(CFLAGS) $< > $(basename $@).d
+	@mv -f $(basename $@).d $(basename $@).d.tmp
+	@sed -e 's|.*:|$@:|' < $(basename $@).d.tmp > $(basename $@).d
+	@sed -e 's/.*://' -e 's/\\$$//' < $(basename $@).d.tmp | fmt -1 | \
+	sed -e 's/^ *//' -e 's/$$/:/' >> $(basename $@).d
+	@rm -f $(basename $@).d.tmp
+
+objsdir:
+	@if [ ! -d $(OUTDIR) ]; then mkdir -p $(OUTDIR); fi;
 
-libsecu.a: $(libsecu_OBJECTS)
-	$(AR) rcvs $@ $(libsecu_OBJECTS)
+$(OUTDIR)/libsecu.a: $(addprefix $(OUTDIR)/,$(libsecu_OBJECTS))
+	@echo Creating SECU archive
+	@$(AR) rcs $@ $(addprefix $(OUTDIR)/,$(libsecu_OBJECTS))
 
 clean:
-	rm -f $(libsecu_OBJECTS)
-	rm -rf .deps/
-	rm -f libsecu.a
\ No newline at end of file
+	@$(RM_F_V) $(OUTDIR)/*.o
+	@$(RM_F_V) $(OUTDIR)/*.d
+	@$(RM_F_V) $(OUTDIR)/libsecu.a
+
+cleanall: clean
diff --git a/openair-cn/SECU/secu_defs.h b/openair-cn/SECU/secu_defs.h
index 6be6db2c8c..111a1d2d0d 100644
--- a/openair-cn/SECU/secu_defs.h
+++ b/openair-cn/SECU/secu_defs.h
@@ -1,8 +1,9 @@
-#include "security_types.h"
 
 #ifndef SECU_DEFS_H_
 #define SECU_DEFS_H_
 
+#include "security_types.h"
+
 #define EIA0_ALG_ID     0x00
 #define EIA1_128_ALG_ID 0x01
 #define EIA2_128_ALG_ID 0x02
diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c
index 8b2621df8b..8ae6f746e2 100644
--- a/openair2/RRC/LITE/rrc_eNB.c
+++ b/openair2/RRC/LITE/rrc_eNB.c
@@ -2551,9 +2551,9 @@ char openair_rrc_lite_eNB_init(
     {
         /* Init security parameters */
         for (j = 0; j < NUMBER_OF_UE_MAX; j++) {
-	  eNB_rrc_inst[enb_mod_idP].ciphering_algorithm[j] = SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
-	  eNB_rrc_inst[enb_mod_idP].integrity_algorithm[j] = SecurityAlgorithmConfig__integrityProtAlgorithm_eia2;
-	  rrc_lite_eNB_init_security(enb_mod_idP, j);
+            eNB_rrc_inst[enb_mod_idP].ciphering_algorithm[j] = SecurityAlgorithmConfig__cipheringAlgorithm_eea0;
+            eNB_rrc_inst[enb_mod_idP].integrity_algorithm[j] = SecurityAlgorithmConfig__integrityProtAlgorithm_eia2;
+            rrc_lite_eNB_init_security(enb_mod_idP, j);
         }
     }
 
@@ -2743,7 +2743,7 @@ int rrc_eNB_decode_ccch(
 		LOG_F(RRC,"%02x ", ((uint8_t*)Srb_info->Rx_buffer.Payload)[i]);
 	      LOG_F(RRC,"\n");
 #endif
-              LOG_D(RRC,
+                LOG_D(RRC,
                       "[FRAME %05d][MAC_eNB][MOD %02d][][--- MAC_DATA_IND  (rrcConnectionRequest on SRB0) -->][RRC_eNB][MOD %02d][]\n",
                       frameP, enb_mod_idP, enb_mod_idP);
 
@@ -2990,10 +2990,10 @@ int rrc_eNB_decode_dcch(
 	      LOG_F(RRC,"\n");
 #endif
 	      LOG_I(RRC,
-		    "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
-		    "(rrcConnectionReestablishmentComplete) --->][RRC_eNB][MOD %02d][]\n",
-		    frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);
-	      break;
+                      "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
+                      "(rrcConnectionReestablishmentComplete) --->][RRC_eNB][MOD %02d][]\n",
+                      frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);
+                break;
 
             case UL_DCCH_MessageType__c1_PR_rrcConnectionSetupComplete:
 #ifdef RRC_MSG_PRINT
@@ -3002,7 +3002,7 @@ int rrc_eNB_decode_dcch(
 		LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
 	      LOG_F(RRC,"\n");
 #endif
-	  LOG_D(RRC,
+                LOG_D(RRC,
                       "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                       "(RRCConnectionSetupComplete) --->][RRC_eNB][MOD %02d][]\n",
                       frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);
@@ -3032,7 +3032,7 @@ int rrc_eNB_decode_dcch(
 		LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
 	      LOG_F(RRC,"\n");
 #endif
-               LOG_I(RRC,
+                LOG_I(RRC,
                       "[eNB %d] Frame %d received securityModeComplete on UL-DCCH %d from UE %d\n",
                       enb_mod_idP, frameP, DCCH, ue_mod_idP);
                 LOG_D(RRC,
@@ -3054,7 +3054,7 @@ int rrc_eNB_decode_dcch(
 		LOG_F(RRC,"%02x ", ((uint8_t*)Rx_sdu)[i]);
 	      LOG_F(RRC,"\n");
 #endif
-               LOG_D(RRC,
+                LOG_D(RRC,
                       "[FRAME %05d][RLC][MOD %02d][RB %02d][--- RLC_DATA_IND %d bytes "
                       "(securityModeFailure) --->][RRC_eNB][MOD %02d][]\n", frameP, enb_mod_idP, DCCH, sdu_sizeP, enb_mod_idP);
 #ifdef XER_PRINT
diff --git a/openair2/RRC/LITE/rrc_eNB_S1AP.c b/openair2/RRC/LITE/rrc_eNB_S1AP.c
index af46936af8..c95d505865 100644
--- a/openair2/RRC/LITE/rrc_eNB_S1AP.c
+++ b/openair2/RRC/LITE/rrc_eNB_S1AP.c
@@ -339,7 +339,7 @@ static void rrc_pdcp_config_security(uint8_t enb_mod_idP, uint8_t ue_mod_idP, ui
 			     kRRCenc, 
 			     kRRCint, 
 			     kUPenc);
-#endif 			     
+#endif
 }
 
 /*------------------------------------------------------------------------------*/
diff --git a/targets/Makefile.common b/targets/Makefile.common
index c505fd02a3..3a00d0a9cc 100644
--- a/targets/Makefile.common
+++ b/targets/Makefile.common
@@ -6,9 +6,10 @@ X2AP_DIR            = $(OPENAIR_HOME)/openair2/X2AP
 SCTP_DIR            = $(OPENAIR_HOME)/openair-cn/SCTP
 UDP_DIR             = $(OPENAIR_HOME)/openair-cn/UDP
 GTPV1U_DIR          = $(OPENAIR_HOME)/openair-cn/GTPV1-U
-CN_SECU_DIR         = $(OPENAIR_HOME)/openair-cn/SECU
+SECU_DIR            = $(OPENAIR_HOME)/openair-cn/SECU
 
 UE_NAS_OBJ_DIR      = $(subst $(OPENAIR_HOME),$(OBJS_DIR),$(UE_NAS_DIR))
+SECU_OBJ_DIR        = $(subst $(OPENAIR_HOME),$(OBJS_DIR),$(SECU_DIR))
 S1AP_OBJ_DIR        = $(subst $(OPENAIR_HOME),$(OBJS_DIR),$(S1AP_DIR))
 X2AP_OBJ_DIR        = $(subst $(OPENAIR_HOME),$(OBJS_DIR),$(X2AP_DIR))
 SCTP_OBJ_DIR        = $(subst $(OPENAIR_HOME),$(OBJS_DIR),$(SCTP_DIR))
@@ -22,15 +23,15 @@ export X2AP_DIR
 export SCTP_DIR
 export UDP_DIR
 export GTPV1U_DIR
-export CN_SECU_DIR
+export SECU_DIR
 
 #Export common cflags (between softmodem and oaisim)
 COMMON_CFLAGS		= \
-    -D'FIRMWARE_VERSION="$(SVN_REV) - $(DATE_REV)"' \
-    -Wall                       \
-    -fno-strict-aliasing        \
-    -O2                         \
-    -Werror=implicit-function-declaration
+	-D'FIRMWARE_VERSION="$(SVN_REV) - $(DATE_REV)"' \
+	-Wall                       \
+	-fno-strict-aliasing        \
+	-O2                         \
+	-Werror=implicit-function-declaration
 
 ITTI_MESSAGES_H		= messages_xml.h
 ITTI_MESSAGES_XML	= messages.xml
@@ -62,12 +63,12 @@ SHARED_DEPENDENCIES += $(ITTI_MESSAGES_H)
 endif
 
 ifdef USE_MME
-#LGLIBS				+= $(UE_NAS_OBJ_DIR)/libuenas.a  $(X2AP_OBJ_DIR)/libx2ap.a
-LIBS				+= $(UE_NAS_OBJ_DIR)/libuenas.a 
+#LGLIBS				+= $(X2AP_OBJ_DIR)/libx2ap.a
+LIBS				+= $(UE_NAS_OBJ_DIR)/libuenas.a $(SECU_OBJ_DIR)/libsecu.a 
 LIBS				+= $(S1AP_OBJ_DIR)/libs1ap.a $(SCTP_OBJ_DIR)/libsctp.a -lsctp -lcrypt
 LIBS				+= $(UDP_OBJ_DIR)/libudp.a $(GTPV1U_OBJ_DIR)/libgtpv1u.a 
-#LG SHARED_DEPENDENCIES	+= $(UE_NAS_OBJ_DIR)/libuenas.a $(X2AP_OBJ_DIR)/libx2ap.a $(S1AP_OBJ_DIR)/libs1ap.a $(SCTP_OBJ_DIR)/libsctp.a  $(UDP_OBJ_DIR)/libudp.a $(GTPV1U_OBJ_DIR)/libgtpv1u.a
-SHARED_DEPENDENCIES	+= $(UE_NAS_OBJ_DIR)/libuenas.a $(S1AP_OBJ_DIR)/libs1ap.a $(SCTP_OBJ_DIR)/libsctp.a  $(UDP_OBJ_DIR)/libudp.a $(GTPV1U_OBJ_DIR)/libgtpv1u.a
+#LG SHARED_DEPENDENCIES	+= $(UE_NAS_OBJ_DIR)/libuenas.a $(SECU_OBJ_DIR)/libsecu.a $(X2AP_OBJ_DIR)/libx2ap.a $(S1AP_OBJ_DIR)/libs1ap.a $(SCTP_OBJ_DIR)/libsctp.a  $(UDP_OBJ_DIR)/libudp.a $(GTPV1U_OBJ_DIR)/libgtpv1u.a
+SHARED_DEPENDENCIES	+= $(UE_NAS_OBJ_DIR)/libuenas.a $(SECU_OBJ_DIR)/libsecu.a $(S1AP_OBJ_DIR)/libs1ap.a $(SCTP_OBJ_DIR)/libsctp.a  $(UDP_OBJ_DIR)/libudp.a $(GTPV1U_OBJ_DIR)/libgtpv1u.a
 
 COMMON_CFLAGS		+= -DLOG_NO_THREAD 
 #-DEMIT_ASN_DEBUG
@@ -83,13 +84,18 @@ COMMON_CFLAGS		+= -I$(OPENAIR_HOME)/openair-cn/NAS/EURECOM-NAS/src/esm/msg
 COMMON_CFLAGS		+= -I$(OPENAIR_HOME)/openair-cn/NAS/EURECOM-NAS/src/util
 endif
 
-UENAS_CFLAGS		 = $(COMMON_CFLAGS)
+UENAS_CFLAGS		= $(COMMON_CFLAGS)
+UENAS_CFLAGS		+= -I$(SECU_DIR)
 export UENAS_CFLAGS
 
-$(UE_NAS_OBJ_DIR)/libuenas.a: force_look
-	@$(MAKE) -C $(UE_NAS_DIR) -f Makefile.UE $(UE_NAS_OBJ_DIR)/libuenas.a OUTDIR=$(UE_NAS_OBJ_DIR)
+SECU_CFLAGS			= $(COMMON_CFLAGS)
+SECU_CFLAGS			+= -I$(OPENAIR_HOME)/openair-cn/COMMON
+SECU_CFLAGS			+= -I$(OPENAIR_HOME)/openair-cn/UTILS
+SECU_CFLAGS			+= -I$(SECU_DIR)
+export SECU_CFLAGS
 
-COMMON_MME_CFLAGS    = -I$(SCTP_DIR)
+COMMON_MME_CFLAGS	= -I$(SECU_DIR)
+COMMON_MME_CFLAGS   += -I$(SCTP_DIR)
 COMMON_MME_CFLAGS	+= -I$(X2AP_DIR)
 COMMON_MME_CFLAGS	+= -I$(S1AP_DIR)
 COMMON_MME_CFLAGS	+= -I$(UDP_DIR)
@@ -137,6 +143,11 @@ GTPV1U_ENB_CFLAGS           += -I$(OPENAIR_HOME)/openair2/ENB_APP
 GTPV1U_ENB_CFLAGS           += $(UTIL_incl) -I$(OPENAIRCN_DIR)/UTILS
 export GTPV1U_ENB_CFLAGS
 
+
+$(UE_NAS_OBJ_DIR)/libuenas.a: force_look
+	@$(MAKE) -C $(UE_NAS_DIR) -f Makefile.UE $(UE_NAS_OBJ_DIR)/libuenas.a OUTDIR=$(UE_NAS_OBJ_DIR)
+$(SECU_OBJ_DIR)/libsecu.a: force_look
+	@$(MAKE) -C $(SECU_DIR) -f Makefile.eNB $(SECU_OBJ_DIR)/libsecu.a OUTDIR=$(SECU_OBJ_DIR)
 $(X2AP_OBJ_DIR)/libx2ap.a: force_look
 	@$(MAKE) -C $(X2AP_DIR) -f Makefile.inc $(X2AP_OBJ_DIR)/libx2ap.a OUTDIR=$(X2AP_OBJ_DIR)
 $(S1AP_OBJ_DIR)/libs1ap.a: force_look
@@ -148,7 +159,7 @@ $(UDP_OBJ_DIR)/libudp.a: force_look
 $(GTPV1U_OBJ_DIR)/libgtpv1u.a: force_look
 	@$(MAKE) -C $(GTPV1U_DIR) -f Makefile.eNB $(GTPV1U_OBJ_DIR)/libgtpv1u.a OUTDIR=$(GTPV1U_OBJ_DIR)
 
-OBJ = $(NAS_UE_OBJS)
+OBJ = $(NAS_UE_OBJS) $(SECU_OBJS)
 endif
 
 export COMMON_CFLAGS
@@ -188,6 +199,7 @@ common-clean:
 	@$(RM_F_V) $(ITTI_MESSAGES_H) $(ITTI_MESSAGES_XML) $(ITTI_MESSAGES_XML:.xml=.d)
 	@$(MAKE) -C $(LFDS_DIR) -f makefile.linux clean OUTDIR=$(LFDS_OBJ_DIR)
 	@if [ -d $(UE_NAS_OBJ_DIR) ]; then $(MAKE) -C $(UE_NAS_DIR) -f Makefile.UE clean OUTDIR=$(UE_NAS_OBJ_DIR); fi
+	@if [ -d $(SECU_OBJ_DIR) ]; then $(MAKE) -C $(SECU_DIR) -f Makefile.eNB clean OUTDIR=$(SECU_OBJ_DIR); fi
 	@if [ -d $(X2AP_OBJ_DIR) ]; then $(MAKE) -C $(X2AP_DIR) -f Makefile.inc clean OUTDIR=$(X2AP_OBJ_DIR); fi
 	@if [ -d $(S1AP_OBJ_DIR) ]; then $(MAKE) -C $(S1AP_DIR) -f Makefile.eNB clean OUTDIR=$(S1AP_OBJ_DIR); fi
 	@if [ -d $(SCTP_OBJ_DIR) ]; then $(MAKE) -C $(SCTP_DIR) -f Makefile.eNB clean OUTDIR=$(SCTP_OBJ_DIR); fi
@@ -196,6 +208,7 @@ common-clean:
 
 common-cleanall:
 	@if [ -d $(UE_NAS_OBJ_DIR) ]; then $(MAKE) -C $(UE_NAS_DIR) -f Makefile.UE cleanall OUTDIR=$(UE_NAS_OBJ_DIR); fi
+	@if [ -d $(SECU_OBJ_DIR) ]; then $(MAKE) -C $(SECU_DIR) -f Makefile.eNB cleanall OUTDIR=$(SECU_OBJ_DIR); fi
 	@if [ -d $(X2AP_OBJ_DIR) ]; then $(MAKE) -C $(X2AP_DIR) -f Makefile.inc cleanall OUTDIR=$(X2AP_OBJ_DIR); fi
 	@if [ -d $(S1AP_OBJ_DIR) ]; then $(MAKE) -C $(S1AP_DIR) -f Makefile.eNB cleanall OUTDIR=$(S1AP_OBJ_DIR); fi
 	@if [ -d $(SCTP_OBJ_DIR) ]; then $(MAKE) -C $(SCTP_DIR) -f Makefile.eNB cleanall OUTDIR=$(SCTP_OBJ_DIR); fi
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/start_enb_and_ue_virt.bash b/targets/PROJECTS/GENERIC-LTE-EPC/start_enb_and_ue_virt.bash
index 44a4ef7f9f..951975088f 100755
--- a/targets/PROJECTS/GENERIC-LTE-EPC/start_enb_and_ue_virt.bash
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/start_enb_and_ue_virt.bash
@@ -93,7 +93,7 @@
 ###########################################################
 # Parameters
 ###########################################################
-declare MAKE_LTE_ACCESS_STRATUM_TARGET="oaisim DEBUG=1 ENABLE_ITTI=1 USE_MME=R10 LINK_PDCP_TO_GTPV1U=1 NAS=1 Rel10=1"
+declare MAKE_LTE_ACCESS_STRATUM_TARGET="oaisim DEBUG=1 ENABLE_ITTI=1 USE_MME=R10 LINK_PDCP_TO_GTPV1U=1 NAS=1 SECU=1 Rel10=1"
 declare MAKE_IP_DRIVER_TARGET="ue_ip.ko"
 declare IP_DRIVER_NAME="ue_ip"
 declare LTEIF="oip1"
-- 
GitLab