From 0802f49d7c883525236147eeceb7372014180388 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Fri, 22 Nov 2013 09:56:10 +0000
Subject: [PATCH] - Updated s1ap configuration to handle modes where
 oai_emulation is not compiled

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4492 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair-cn/S1AP/s1ap_eNB.c           |  4 ++++
 openair-cn/S1AP/s1ap_eNB.h           | 16 ++++++++++++++++
 openair2/RRC/LITE/rrc_eNB.c          | 18 ++++++++++--------
 targets/RTAI/USER/lte-softmodem.c    | 21 ++++++++++++++++++++-
 targets/SIMU/USER/oaisim.c           |  4 ++--
 targets/SIMU/USER/oaisim_functions.c | 11 ++++++++---
 6 files changed, 60 insertions(+), 14 deletions(-)

diff --git a/openair-cn/S1AP/s1ap_eNB.c b/openair-cn/S1AP/s1ap_eNB.c
index 9ad3267ef0..50b58cdcdc 100644
--- a/openair-cn/S1AP/s1ap_eNB.c
+++ b/openair-cn/S1AP/s1ap_eNB.c
@@ -58,6 +58,10 @@
 #include "assertions.h"
 #include "conversions.h"
 
+#if !defined(OAI_EMU)
+s1ap_eNB_config_t s1ap_config;
+#endif
+
 static int s1ap_eNB_generate_s1_setup_request(
     s1ap_eNB_instance_t *instance_p, s1ap_eNB_mme_data_t *s1ap_mme_data_p);
 
diff --git a/openair-cn/S1AP/s1ap_eNB.h b/openair-cn/S1AP/s1ap_eNB.h
index 7b56db91b8..db0d53f8e9 100644
--- a/openair-cn/S1AP/s1ap_eNB.h
+++ b/openair-cn/S1AP/s1ap_eNB.h
@@ -39,6 +39,22 @@
 #ifndef S1AP_ENB_H_
 #define S1AP_ENB_H_
 
+typedef struct s1ap_eNB_config_s {
+    // MME related params
+    unsigned char mme_enabled;          ///< MME enabled ?
+    char          mme_ip_address[16];   ///< MME IP v4 address
+} s1ap_eNB_config_t;
+
+#if defined(OAI_EMU)
+# define EPC_MODE_ENABLED       oai_emulation.info.s1ap_config.mme_enabled
+# define EPC_MODE_MME_ADDRESS   oai_emulation.info.s1ap_config.mme_ip_address
+#else
+extern s1ap_eNB_config_t s1ap_config;
+
+# define EPC_MODE_ENABLED       s1ap_config.mme_enabled
+# define EPC_MODE_MME_ADDRESS   s1ap_config.mme_ip_address
+#endif
+
 void *s1ap_eNB_task(void *arg);
 
 uint32_t s1ap_generate_eNB_id(void);
diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c
index 5bed07bb33..f671b70f62 100644
--- a/openair2/RRC/LITE/rrc_eNB.c
+++ b/openair2/RRC/LITE/rrc_eNB.c
@@ -72,7 +72,9 @@
 #endif
 
 #if defined(ENABLE_USE_MME)
-# if !defined(ENABLE_ITTI)
+# if defined(ENABLE_ITTI)
+#   include "s1ap_eNB.h"
+# else
 #   include "../../S1AP/s1ap_eNB.h"
 # endif
 #endif
@@ -617,10 +619,10 @@ char openair_rrc_lite_eNB_init (u8 Mod_id)
 
 #if defined(ENABLE_USE_MME)
   /* Connect eNB to MME */
-  if (oai_emulation.info.mme_enabled > 0)
+  if (EPC_MODE_ENABLED > 0)
     {
 # if !defined(ENABLE_ITTI)
-      if (s1ap_eNB_init (oai_emulation.info.mme_ip_address, Mod_id) < 0)
+      if (s1ap_eNB_init (EPC_MODE_MME_ADDRESS, Mod_id) < 0)
         {
           mac_xface->macphy_exit ("");
           return -1;
@@ -807,7 +809,7 @@ int rrc_eNB_decode_dcch (u8 Mod_id, u32 frame, u8 Srb_id, u8 UE_index,
                      Mod_id, UE_index);
 
 #if defined(ENABLE_USE_MME)
-            if (oai_emulation.info.mme_enabled == 1)
+            if (EPC_MODE_ENABLED == 1)
             {
 # if defined(ENABLE_ITTI)
               eNB_rrc_inst[Mod_id].Info.UE[UE_index].e_rab[eNB_rrc_inst[Mod_id].Info.UE[UE_index].index_of_e_rabs - 1].status = E_RAB_STATUS_DONE;
@@ -817,7 +819,7 @@ int rrc_eNB_decode_dcch (u8 Mod_id, u32 frame, u8 Srb_id, u8 UE_index,
           }
 
 #if defined(ENABLE_USE_MME)
-          if (oai_emulation.info.mme_enabled == 1)
+          if (EPC_MODE_ENABLED == 1)
           {
               eNB_RRC_UE_INFO *UE_info = &eNB_rrc_inst[Mod_id].Info.UE[UE_index];
 
@@ -979,7 +981,7 @@ int rrc_eNB_decode_dcch (u8 Mod_id, u32 frame, u8 Srb_id, u8 UE_index,
 #endif
 
 #if defined(ENABLE_USE_MME)
-          if (oai_emulation.info.mme_enabled == 1)
+          if (EPC_MODE_ENABLED == 1)
           {
               eNB_RRC_UE_INFO *UE_info = &eNB_rrc_inst[Mod_id].Info.UE[UE_index];
 
@@ -1019,7 +1021,7 @@ int rrc_eNB_decode_dcch (u8 Mod_id, u32 frame, u8 Srb_id, u8 UE_index,
         case UL_DCCH_MessageType__c1_PR_ulInformationTransfer:
 #if defined(ENABLE_USE_MME)
           {
-            if (oai_emulation.info.mme_enabled == 1)
+            if (EPC_MODE_ENABLED == 1)
 # if defined(ENABLE_ITTI)
             {
               ULInformationTransfer_t *ulInformationTransfer = &ul_dcch_msg->message.choice.c1.choice.ulInformationTransfer;
@@ -1332,7 +1334,7 @@ void rrc_eNB_process_RRCConnectionSetupComplete (u8 Mod_id,
 
   // Forward message to S1AP layer
 #if defined(ENABLE_USE_MME)
-  if (oai_emulation.info.mme_enabled == 1)
+  if (EPC_MODE_ENABLED == 1)
 # if defined(ENABLE_ITTI)
   {
     MessageDef *message_p;
diff --git a/targets/RTAI/USER/lte-softmodem.c b/targets/RTAI/USER/lte-softmodem.c
index ccd0528736..50a271cce0 100644
--- a/targets/RTAI/USER/lte-softmodem.c
+++ b/targets/RTAI/USER/lte-softmodem.c
@@ -92,6 +92,10 @@ unsigned short config_frames[4] = {2,9,11,13};
 #include "UTIL/MATH/oml.h"
 #include "UTIL/LOG/vcd_signal_dumper.h"
 
+#if defined(ENABLE_USE_MME)
+# include "s1ap_eNB.h"
+#endif
+
 #ifdef XFORMS
 #include "PHY/TOOLS/lte_phy_scope.h"
 #include "stats.h"
@@ -972,7 +976,7 @@ int main(int argc, char **argv) {
   mode = normal_txrx;
 
 
-  while ((c = getopt_long (argc, argv, "C:ST:UdF:V",long_options,NULL)) != -1)
+  while ((c = getopt_long (argc, argv, "C:O:ST:UdF:V",long_options,NULL)) != -1)
     {
       switch (c)
         {
@@ -997,6 +1001,21 @@ int main(int argc, char **argv) {
         case 'T':
           tcxo=atoi(optarg);
           break;
+        case 'O':
+#if defined(ENABLE_USE_MME)
+          EPC_MODE_ENABLED = 1;
+          if (optarg == NULL) /* No IP address provided: use localhost */
+          {
+            memcpy(&EPC_MODE_MME_ADDRESS[0], "127.0.0.1", 10);
+          } else {
+            u8 ip_length = strlen(optarg) + 1;
+            memcpy(&EPC_MODE_MME_ADDRESS[0], optarg,
+            ip_length > 16 ? 16 : ip_length);
+          }
+#else
+          printf("You enabled mme mode without s1ap compiled...\n");
+#endif
+          break;
 	case 'F':
 	  sprintf(rxg_fname,"%srxg.lime",optarg);
 	  rxg_fd = fopen(rxg_fname,"r");
diff --git a/targets/SIMU/USER/oaisim.c b/targets/SIMU/USER/oaisim.c
index 2856247826..6d74459ce5 100644
--- a/targets/SIMU/USER/oaisim.c
+++ b/targets/SIMU/USER/oaisim.c
@@ -393,9 +393,9 @@ void *l2l1_task(void *args_p) {
     {
         char *mme_address_v4;
 
-        if (oai_emulation.info.mme_enabled)
+        if (EPC_MODE_ENABLED)
         {
-            mme_address_v4 = oai_emulation.info.mme_ip_address;
+            mme_address_v4 = EPC_MODE_MME_ADDRESS;
         }
         else
         {
diff --git a/targets/SIMU/USER/oaisim_functions.c b/targets/SIMU/USER/oaisim_functions.c
index e40010110b..2b78f94968 100644
--- a/targets/SIMU/USER/oaisim_functions.c
+++ b/targets/SIMU/USER/oaisim_functions.c
@@ -32,6 +32,10 @@
 # include "intertask_interface.h"
 #endif
 
+#if defined(ENABLE_USE_MME)
+# include "s1ap_eNB.h"
+#endif
+
 #ifdef SMBV
 extern u8 config_smbv;
 extern char smbv_ip[16];
@@ -361,13 +365,14 @@ void get_simulation_options(int argc, char *argv[]) {
       break;
     case 'O':
 #if defined(ENABLE_USE_MME)
-      oai_emulation.info.mme_enabled = 1;
+      EPC_MODE_ENABLED = 1;
       if (optarg == NULL) /* No IP address provided: use localhost */
       {
-        memcpy(&oai_emulation.info.mme_ip_address[0], "127.0.0.1", 10);
+          memcpy(&EPC_MODE_MME_ADDRESS[0], "127.0.0.1", 10);
       } else {
         u8 ip_length = strlen(optarg) + 1;
-        memcpy(&oai_emulation.info.mme_ip_address[0], optarg, ip_length > 16 ? 16 : ip_length);
+        memcpy(&EPC_MODE_MME_ADDRESS[0], optarg,
+               ip_length > 16 ? 16 : ip_length);
       }
 #else
       printf("You enabled MME mode without MME support...\n");
-- 
GitLab