From 48f1154444405b9f457f67c703144a40bb32d210 Mon Sep 17 00:00:00 2001
From: Aikaterini <aikaterini.trilyraki@eurecom.fr>
Date: Sun, 7 Feb 2016 20:07:05 +0100
Subject: [PATCH] make changes to use the fronthaul configuration parameters -
 updates to rrh_gw.c and eNB_transport.c wrt to changes in openair0_device
 struct

---
 cmake_targets/build_oai                       |   2 +-
 .../ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c  |   7 +-
 targets/ARCH/COMMON/common_lib.c              |  43 +++----
 targets/ARCH/COMMON/common_lib.h              | 119 ++++++++++--------
 targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp  |  10 +-
 .../CONF/enb.band7.tm1.rrh.usrpb210.conf      |  26 ++--
 targets/RT/USER/eNB_transport_IQ.c            |  33 +++--
 targets/RT/USER/lte-softmodem.c               | 115 +++++++++--------
 targets/RT/USER/rrh_gw.c                      |  10 +-
 9 files changed, 197 insertions(+), 168 deletions(-)

diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai
index c7259813c6..6496ef1794 100755
--- a/cmake_targets/build_oai
+++ b/cmake_targets/build_oai
@@ -97,7 +97,7 @@ Options
    ETHERNET , None
    Adds this trasport protocol support in compilation
 --oaisim
-   Makes the oaisim simulator. Hardware will be defaulted to "NO_VALUE".
+   Makes the oaisim simulator. Hardware will be defaulted to "None".
 --phy_simulators
    Makes the unitary tests Layer 1 simulators
 --core_simulators
diff --git a/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c b/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c
index 2d17dd3e58..0c471da0f9 100644
--- a/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c
+++ b/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c
@@ -828,8 +828,13 @@ int openair0_dev_init_bladerf(openair0_device *device, openair0_config_t *openai
   
   brf_state_t *brf = (brf_state_t*)malloc(sizeof(brf_state_t));
   memset(brf, 0, sizeof(brf_state_t));
+  /* device specific */
+  openair0_cfg->txlaunch_wait = 1;
+  openair0_cfg->txlaunch_wait_slotcount = 1; /* device specific */
+  openair0_cfg->iq_txshift = 5;
+  openair0_cfg->iq_rxrescale = 15;
+  
   // init required params
-
   switch ((int)openair0_cfg->sample_rate) {
   case 30720000:
     openair0_cfg->samples_per_packet    = 2048;
diff --git a/targets/ARCH/COMMON/common_lib.c b/targets/ARCH/COMMON/common_lib.c
index c5a542fbc7..bc886e807b 100644
--- a/targets/ARCH/COMMON/common_lib.c
+++ b/targets/ARCH/COMMON/common_lib.c
@@ -90,23 +90,24 @@ int set_transport(openair0_device *device) {
   
 }
 
-/* FT: looking for the rh interface library and load it */
-int load_lib(openair0_device *device, openair0_config_t *openair0_cfg, char *cfgfile, uint8_t flag) {
+/* look for the interface library and load it */
+int load_lib(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * cfg, uint8_t flag) {
   
   void *lib_handle;
-  oai_device_initfunc_t fp ;
+  oai_device_initfunc_t dp ;
+  oai_transport_initfunc_t tp ;
 
-  if (flag == RF_DEVICE) {
+  if (flag == BBU_LOCAL_RADIO_HEAD) {
       lib_handle = dlopen(OAI_RF_LIBNAME, RTLD_LAZY);
       if (!lib_handle) {
 	printf( "Unable to locate %s: HW device set to NONE_DEV.\n", OAI_RF_LIBNAME);
 	return 0;
       } 
       
-      fp = dlsym(lib_handle,"device_init");
+      dp = dlsym(lib_handle,"device_init");
       
-      if (fp != NULL ) {
-	fp(device,openair0_cfg,cfgfile);
+      if (dp != NULL ) {
+	dp(device,openair0_cfg);
       } else {
 	fprintf(stderr, "%s %d:oai device intializing function not found %s\n", __FILE__, __LINE__, dlerror());
 	return -1;
@@ -118,10 +119,10 @@ int load_lib(openair0_device *device, openair0_config_t *openair0_cfg, char *cfg
 	return 0;
       } 
       
-      fp = dlsym(lib_handle,"transport_init");
+      tp = dlsym(lib_handle,"transport_init");
       
-      if (fp != NULL ) {
-	fp(device,openair0_cfg,cfgfile);
+      if (tp != NULL ) {
+	tp(device,openair0_cfg,cfg);
       } else {
 	fprintf(stderr, "%s %d:oai device intializing function not found %s\n", __FILE__, __LINE__, dlerror());
 	return -1;
@@ -136,10 +137,7 @@ int load_lib(openair0_device *device, openair0_config_t *openair0_cfg, char *cfg
 int openair0_device_load(openair0_device *device, openair0_config_t *openair0_cfg) {
   
   int rc;
-  static char   *cfgfile;
-  uint8_t       flag=RF_DEVICE;
-  /* FT: rewritten for shared library, common, radio head interface implementation */
-  rc=load_lib(device, openair0_cfg, NULL,flag);
+  rc=load_lib(device, openair0_cfg, NULL,BBU_LOCAL_RADIO_HEAD );
   if ( rc >= 0) {       
     if ( set_device(device) < 0) {
       fprintf(stderr, "%s %d:Unsupported radio head\n",__FILE__, __LINE__);
@@ -150,20 +148,23 @@ int openair0_device_load(openair0_device *device, openair0_config_t *openair0_cf
   return 0;
 }
 
-int openair0_transport_load(openair0_device *device, openair0_config_t *openair0_cfg) {
+int openair0_transport_load(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params) {
   
   int rc;
-  static char   *cfgfile;
-  uint8_t       flag=TRANSPORT_PROTOCOL;
-
-  /* FT: rewritten for shared library, common, radio head interface implementation */
-  rc=load_lib(device, openair0_cfg, NULL,flag);
+  rc=load_lib(device, openair0_cfg, eth_params, BBU_REMOTE_RADIO_HEAD);
   if ( rc >= 0) {       
     if ( set_transport(device) < 0) {
-      fprintf(stderr, "%s %d:Unsupported radio head\n",__FILE__, __LINE__);
+      fprintf(stderr, "%s %d:Unsupported transport protocol\n",__FILE__, __LINE__);
       return -1;		   
     }   
   }
   
   return 0;
 }
+
+
+
+
+
+
+
diff --git a/targets/ARCH/COMMON/common_lib.h b/targets/ARCH/COMMON/common_lib.h
index 500a7cb2c3..7f0f95d41b 100644
--- a/targets/ARCH/COMMON/common_lib.h
+++ b/targets/ARCH/COMMON/common_lib.h
@@ -47,16 +47,9 @@
 /* name of shared library implementing the transport */
 #define OAI_TP_LIBNAME        "liboai_transpro.so"
 
-/* flags for BBU to determine whether RF front end is local or remote 
-Note: currently lte-softmodem supports either a local RF device or a remote. */
-#define BBU_LOCAL_RF_ENABLED 1
-#define BBU_REMOTE_RF_ENABLED 2
-#define BBU_LOCAL_REMOTE_RF_ENABLED 3
-/*flags for load_lib() used to specify whether a RF device or a transport protocol library is loaded */
-#define TRANSPORT_PROTOCOL 1
-#define RF_DEVICE 2
-
-
+/* flags for BBU to determine whether the attached radio head is local or remote */
+#define BBU_LOCAL_RADIO_HEAD  0
+#define BBU_REMOTE_RADIO_HEAD 1
 
 typedef int64_t openair0_timestamp;
 typedef volatile int64_t openair0_vtimestamp;
@@ -81,6 +74,49 @@ typedef enum {
 } duplex_mode_t;
 
 
+/*!\brief RF device types
+ */
+typedef enum {
+  MIN_RF_DEV_TYPE = 0,
+  /*!\brief device is ExpressMIMO */
+  EXMIMO_DEV,
+  /*!\brief device is USRP B200/B210*/
+  USRP_B200_DEV,
+  /*!\brief device is USRP X300/X310*/
+  USRP_X300_DEV,
+  /*!\brief device is BLADE RF*/
+  BLADERF_DEV,
+  /*!\brief device is NONE*/
+  NONE_DEV,
+  MAX_RF_DEV_TYPE
+
+} dev_type_t;
+
+/*!\brief transport protocol types
+ */
+typedef enum {
+  MIN_TRANSP_TYPE = 0,
+  /*!\brief transport protocol ETHERNET */
+  ETHERNET_TP,
+  /*!\brief no transport protocol*/
+  NONE_TP,
+  MAX_TRANSP_TYPE
+
+} transport_type_t;
+
+
+/*!\brief  openair0 device host type */
+typedef enum {
+  MIN_HOST_TYPE = 0,
+ /*!\brief device functions within a BBU */
+  BBU_HOST,
+ /*!\brief device functions within a RRH */
+  RRH_HOST,
+  MAX_HOST_TYPE
+
+}host_type_t;
+
+
 /** @addtogroup _PHY_RF_INTERFACE_
  * @{
  */
@@ -167,50 +203,21 @@ typedef struct {
   int chain;
 } openair0_rf_map;
 
+typedef struct {
+  char *remote_addr;
+  //! remote port number for Ethernet interface
+  unsigned int remote_port;
+  //! local IP/MAC addr for Ethernet interface (eNB/BBU, UE)
+  char *my_addr;
+  //! local port number for Ethernet interface (eNB/BBU, UE)
+  unsigned int my_port;
+  //! local port number for Ethernet interface (eNB/BBU, UE)
+  char *local_if_name;
+ //! local port number for Ethernet interface (eNB/BBU, UE)
+  uint8_t transp_preference;
+} eth_params_t;
 
 
-/*!\brief RF device types
- */
-typedef enum {
-  MIN_RF_DEV_TYPE = 0,
-  /*!\brief device is ExpressMIMO */
-  EXMIMO_DEV,
-  /*!\brief device is USRP B200/B210*/
-  USRP_B200_DEV,
-  /*!\brief device is USRP X300/X310*/
-  USRP_X300_DEV,
-  /*!\brief device is BLADE RF*/
-  BLADERF_DEV,
-  /*!\brief device is NONE*/
-  NONE_DEV,
-  MAX_RF_DEV_TYPE
-
-} dev_type_t;
-
-/*!\brief transport protocol types
- */
-typedef enum {
-  MIN_TRANSP_TYPE = 0,
-  /*!\brief transport protocol ETHERNET */
-  ETHERNET_TP,
-  /*!\brief no transport protocol*/
-  NONE_TP,
-  MAX_TRANSP_TYPE
-
-} transport_type_t;
-
-
-/*!\brief  openair0 device host type */
-typedef enum {
-  MIN_HOST_TYPE = 0,
- /*!\brief device functions within a BBU */
-  BBU_HOST,
- /*!\brief device functions within a RRH */
-  RRH_HOST,
-  MAX_HOST_TYPE
-
-}host_type_t;
-
 struct openair0_device_t {
   /*!brief Module ID of this device */
   int Mod_id;
@@ -309,17 +316,19 @@ struct openair0_device_t {
 };
 
 /* type of device init function, implemented in shared lib */
-typedef int(*oai_device_initfunc_t)(openair0_device *device, openair0_config_t *openair0_cfg, char *cfgfile);
+typedef int(*oai_device_initfunc_t)(openair0_device *device, openair0_config_t *openair0_cfg);
+/* type of transport init function, implemented in shared lib */
+typedef int(*oai_transport_initfunc_t)(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params);
 
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
-  /*! \brief Initialize openair RF target. It returns 0 if OK */
+/*! \brief Initialize openair RF target. It returns 0 if OK */
   int openair0_device_load(openair0_device *device, openair0_config_t *openair0_cfg);  
   /*! \brief Initialize transport protocol . It returns 0 if OK */
-  int openair0_transport_load(openair0_device *device, openair0_config_t *openair0_cfg);
+  int openair0_transport_load(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params);
   
   //USRP
 /*! \brief Get the current timestamp of USRP */
diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
index 95df41562c..dc9191a613 100644
--- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
+++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
@@ -387,7 +387,7 @@ int trx_usrp_reset_stats(openair0_device* device) {
 
 
 extern "C" {
-  int device_init(openair0_device* device, openair0_config_t *openair0_cfg, char *cfgfile) {
+  int device_init(openair0_device* device, openair0_config_t *openair0_cfg) {
     
     uhd::set_thread_priority_safe(1.0);
     usrp_state_t *s = (usrp_state_t*)malloc(sizeof(usrp_state_t));
@@ -444,7 +444,7 @@ extern "C" {
     //s->usrp->set_master_clock_rate(usrp_master_clock);
 
     openair0_cfg[0].rx_gain_calib_table = calib_table_x310;
-
+    
     switch ((int)openair0_cfg[0].sample_rate) {
     case 30720000:
             // from usrp_time_offset
@@ -554,6 +554,12 @@ extern "C" {
     }
   }
 
+  /* device specific */
+  openair0_cfg[0].iq_txshift = 5;
+  openair0_cfg[0].iq_rxrescale = 15;
+  openair0_cfg[0].txlaunch_wait = 1;
+  openair0_cfg[0].txlaunch_wait_slotcount = 1;
+  
   for(i=0;i<s->usrp->get_rx_num_channels();i++) {
     if (i<openair0_cfg[0].rx_num_channels) {
       s->usrp->set_rx_rate(openair0_cfg[0].sample_rate,i);
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.rrh.usrpb210.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.rrh.usrpb210.conf
index 95bad9da5b..7c41297238 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.rrh.usrpb210.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/enb.band7.tm1.rrh.usrpb210.conf
@@ -28,7 +28,7 @@ eNBs =
       tdd_config_s            			      = 0;
       prefix_type             			      = "NORMAL";
       eutra_band              			      = 7;
-      downlink_frequency      			      = 2680000000L;
+      downlink_frequency      			      = 2660000000L;
       uplink_frequency_offset 			      = -120000000;
       Nid_cell					      = 0;
       N_RB_DL                 			      = 25;
@@ -36,7 +36,7 @@ eNBs =
       nb_antennas_tx          			      = 1;
       nb_antennas_rx          			      = 1;
       tx_gain                                            = 90;
-      rx_gain                                            = 120;
+      rx_gain                                            = 125;
       prach_root              			      = 0;
       prach_config_index      			      = 0;
       prach_high_speed        			      = "DISABLE";
@@ -143,17 +143,17 @@ eNBs =
 rrh_gw_config = (
  {			  
     local_if_name = "eth0";			  
-    #remote_addr = "169.254.8.28";					  
-    #remote_addr = "127.0.0.1";						  
-    #remote_addr = "74:d4:35:cc:88:45";	 
-    #local_addr = "169.254.7.91";
-    #local_addr = "127.0.0.1";
-    #local_addr = "d4:be:d9:22:0a:ac";
-    local_address = "192.168.12.242" ;
-    remote_address = "192.168.12.31" ;
-    local_port = 50000;		       
-    remote_port = 50001; 
-    active = "no"; 
+    remote_address = "169.254.8.28";					  
+    #remote_address = "127.0.0.1";						  
+    #remote_address = "74:d4:35:cc:88:45";	 
+    local_address = "169.254.7.91";
+    #local_address = "127.0.0.1";
+    #local_address = "d4:be:d9:22:0a:ac";
+    #local_address = "192.168.12.242" ;
+    #remote_address = "192.168.12.31" ;
+    local_port = 50001;		       
+    remote_port = 50000; 
+    active = "no";
     preference = "udp";	                
                              
 }
diff --git a/targets/RT/USER/eNB_transport_IQ.c b/targets/RT/USER/eNB_transport_IQ.c
index 3580e876f6..594b075941 100644
--- a/targets/RT/USER/eNB_transport_IQ.c
+++ b/targets/RT/USER/eNB_transport_IQ.c
@@ -143,10 +143,9 @@ void config_BBU_mod( rrh_module_t *mod_enb, uint8_t RT_flag, uint8_t NRT_flag) {
   
   /* init socket and have handshake-like msg with client to exchange parameters */
   mod_enb->eth_dev.trx_start_func(&mod_enb->eth_dev);//change port  make it plus_id
-    printf("sdfs\n");
 
-  memcpy((void*)mod_enb->devs->openair0_cfg,(void *)mod_enb->eth_dev.openair0_cfg,sizeof(openair0_config_t));
-  printf("sdfs\n");
+  mod_enb->devs->openair0_cfg = mod_enb->eth_dev.openair0_cfg;
+
   /* check sanity of configuration parameters and print */
   check_dev_config(mod_enb);    
   
@@ -387,7 +386,7 @@ void *rrh_eNB_rx_thread(void *arg) {
 
   while (rrh_exit == 0) {    
     while (rx_pos <(1 + subframe)*samples_per_subframe) {
-      LOG_D(RRH,"starting a new send:%d  %d\n",sync_trx,frame);
+      //LOG_D(RRH,"starting a new send:%d  %d\n",sync_trx,frame);
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_RX, 1 );
       VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_HW_FRAME_RX, frame);
       VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_HW_SUBFRAME_RX, subframe );  
@@ -508,7 +507,7 @@ void *rrh_eNB_rx_thread(void *arg) {
        next_rx_pos=(rx_pos+spp_eth);
        
        VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_RX, 0 );
-       /**/
+       /*
        if (frame>50) {
 	 pthread_mutex_lock(&sync_trx_mutex);
 	 while (sync_trx) {
@@ -518,7 +517,7 @@ void *rrh_eNB_rx_thread(void *arg) {
 	 LOG_D(RRH,"out of while send:%d  %d\n",sync_trx,frame);
 	 pthread_cond_signal(&sync_trx_cond);
 	 pthread_mutex_unlock(&sync_trx_mutex);
-       }
+	 }*/
     } // while 
     
     subframe++;
@@ -591,14 +590,14 @@ void *rrh_eNB_tx_thread(void *arg) {
   while (rrh_exit == 0) {     
     while (tx_pos < (1 + subframe)*samples_per_subframe) {
       
-      LOG_D(RRH,"bef lock read:%d  %d\n",sync_trx,frame);
-      pthread_mutex_lock(&sync_trx_mutex);
+      //LOG_D(RRH,"bef lock read:%d  %d\n",sync_trx,frame);
+      //pthread_mutex_lock(&sync_trx_mutex);
       
-      while (!sync_trx) {
-	LOG_D(RRH,"in sync read:%d  %d\n",sync_trx,frame);
-	pthread_cond_wait(&sync_trx_cond,&sync_trx_mutex);
-      }
-      LOG_D(RRH,"out of while read:%d  %d\n",sync_trx,frame);
+      //while (!sync_trx) {
+      //LOG_D(RRH,"in sync read:%d  %d\n",sync_trx,frame);
+      //pthread_cond_wait(&sync_trx_cond,&sync_trx_mutex);
+      //}
+      //LOG_D(RRH,"out of while read:%d  %d\n",sync_trx,frame);
       
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_TX, 1 );
       VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_HW_FRAME, frame);
@@ -660,10 +659,10 @@ void *rrh_eNB_tx_thread(void *arg) {
       tx_pos += spp_eth;
       pck_tx++;   
       
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_TX, 0 );
-      sync_trx=0;
-      pthread_cond_signal(&sync_trx_cond);
-      pthread_mutex_unlock(&sync_trx_mutex);
+      //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_eNB_TX, 0 );
+      //sync_trx=0;
+      //pthread_cond_signal(&sync_trx_cond);
+      //pthread_mutex_unlock(&sync_trx_mutex);
     }
 
     /* wrap around tx buffer index */
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index 00ede275b2..698882b38a 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -372,9 +372,12 @@ int16_t           osa_log_verbosity  = LOG_MED;
 char *rrh_UE_ip = "127.0.0.1";
 int rrh_UE_port = 51000;
 #endif
-/* flag given in runtime to specify if the RF head is local or remote (default option is local RF)*/
-uint8_t local_remote_RF = BBU_LOCAL_RF_ENABLED;
- 
+
+/* flag set by eNB conf file to specify if the radio head is local or remote (default option is local) */
+uint8_t local_remote_radio = BBU_LOCAL_RADIO_HEAD;
+/* struct for ethernet specific parameters given in eNB conf file */
+eth_params_t *eth_params;
+
 char uecap_xer[1024],uecap_xer_in=0;
 extern void *UE_thread(void *arg);
 extern void init_UE_threads(void);
@@ -997,12 +1000,12 @@ void do_OFDM_mod_rt(int subframe,PHY_VARS_eNB *phy_vars_eNB)
         if (tx_offset>=(LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*phy_vars_eNB->lte_frame_parms.samples_per_tti))
           tx_offset -= LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*phy_vars_eNB->lte_frame_parms.samples_per_tti;
 
-    ((short*)&phy_vars_eNB->lte_eNB_common_vars.txdata[0][aa][tx_offset])[0] = ((short*)dummy_tx_b)[2*i]<<openair0_cfg[0].iq_txshift ;
+	// ((short*)&phy_vars_eNB->lte_eNB_common_vars.txdata[0][aa][tx_offset])[0] = ((short*)dummy_tx_b)[2*i]<<openair0_cfg[0].iq_txshift ;
+
+	//	((short*)&phy_vars_eNB->lte_eNB_common_vars.txdata[0][aa][tx_offset])[1] = ((short*)dummy_tx_b)[2*i+1]<<openair0_cfg[0].iq_txshift;
 
-	((short*)&phy_vars_eNB->lte_eNB_common_vars.txdata[0][aa][tx_offset])[1] = ((short*)dummy_tx_b)[2*i+1]<<openair0_cfg[0].iq_txshift;
 
 
-/*
         ((short*)&phy_vars_eNB->lte_eNB_common_vars.txdata[0][aa][tx_offset])[0]=
 #ifdef EXMIMO
           ((short*)dummy_tx_b)[2*i]<<4;
@@ -1019,7 +1022,7 @@ void do_OFDM_mod_rt(int subframe,PHY_VARS_eNB *phy_vars_eNB)
 #else
 	  ((short*)dummy_tx_b)[2*i+1]<<4;
 #endif
-*/
+
      }
      // if S-subframe switch to RX in second subframe
      if (subframe_select(&phy_vars_eNB->lte_frame_parms,subframe) == SF_S) {
@@ -1918,12 +1921,15 @@ static void* eNB_thread( void* arg )
       // USRP_DEBUG is active
       rt_sleep_ns(1000000);
 #endif
-
-/* FT configurable tx lauch delay (in slots )*/
+      /* FT configurable tx lauch delay (in slots )*/
       if ( (frame>50) && (tx_launched == 0) &&
 	   ((openair0_cfg[card].txlaunch_wait == 0) ||
 	    ((openair0_cfg[card].txlaunch_wait == 1) &&
-	     (rx_pos >= (((2*hw_subframe)+openair0_cfg[card].txlaunch_wait_slotcount)*PHY_vars_eNB_g[0][0]->lte_frame_parms.samples_per_tti>>1))))) { 
+	    (rx_pos >= (((2*hw_subframe)+openair0_cfg[card].txlaunch_wait_slotcount)*PHY_vars_eNB_g[0][0]->lte_frame_parms.samples_per_tti>>1))))) { 
+      /* if ((frame>50) &&
+	  (tx_launched == 0) &&
+          (rx_pos >= (((2*hw_subframe)+1)*PHY_vars_eNB_g[0][0]->lte_frame_parms.samples_per_tti>>1))) {*/
+	
         tx_launched = 1;
 
         for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
@@ -2086,7 +2092,7 @@ eNB_thread_cleanup:
 
   eNB_thread_status = 0;
 
-  print_difftimes();
+  // print_difftimes();
 
   return &eNB_thread_status;
 }
@@ -2219,7 +2225,7 @@ static void get_options (int argc, char **argv)
      break;
 
     case 'M':
-      local_remote_RF=atoi(optarg);
+      local_remote_radio=atoi(optarg);
       break;
 
     case 'A':
@@ -2466,8 +2472,11 @@ static void get_options (int argc, char **argv)
 
       for (j=0; j<enb_properties->properties[i]->nb_rrh_gw; j++) {
 	
-	if (enb_properties->properties[i]->rrh_gw_config[j].active == 1 ){
-	  // replace printf by setting
+	if (enb_properties->properties[i]->rrh_gw_config[j].active == 1 ) {
+	  local_remote_radio = BBU_REMOTE_RADIO_HEAD;
+	  eth_params = (eth_params_t*)malloc(sizeof(eth_params_t));
+	  memset(eth_params, 0, sizeof(eth_params_t));
+	 
 	  printf( "\n\tRRH GW %d config for eNB %u:\n\n", j, i);
 	  printf( "\tinterface name :       \t%s:\n",enb_properties->properties[i]->rrh_gw_if_name);
 	  printf( "\tlocal address  :       \t%s:\n",enb_properties->properties[i]->rrh_gw_config[j].local_address);
@@ -2475,6 +2484,16 @@ static void get_options (int argc, char **argv)
 	  printf( "\tremote address :       \t%s:\n",enb_properties->properties[i]->rrh_gw_config[j].remote_address);
 	  printf( "\tremote port    :       \t%d:\n",enb_properties->properties[i]->rrh_gw_config[j].remote_port);
 	  printf( "\ttransport      :       \t%s Ethernet:\n\n",(enb_properties->properties[i]->rrh_gw_config[j].raw == 1)? "RAW" : "UDP");
+	  
+	  eth_params->local_if_name             = enb_properties->properties[i]->rrh_gw_if_name;
+	  eth_params->my_addr                   = enb_properties->properties[i]->rrh_gw_config[j].local_address;
+	  eth_params->my_port                   = enb_properties->properties[i]->rrh_gw_config[j].local_port;
+	  eth_params->remote_addr               = enb_properties->properties[i]->rrh_gw_config[j].remote_address;
+	  eth_params->remote_port               = enb_properties->properties[i]->rrh_gw_config[j].remote_port;
+	  eth_params->transp_preference         = enb_properties->properties[i]->rrh_gw_config[j].raw;
+ 
+	} else {
+	  local_remote_radio = BBU_LOCAL_RADIO_HEAD; 
 	}
 	
       }
@@ -3022,30 +3041,13 @@ int main( int argc, char **argv )
     else //FDD
       openair0_cfg[card].duplex_mode = duplex_mode_FDD;
 
-#ifdef ETHERNET
-
-    //openair0_cfg[card].remote_addr = "192.168.12.242";
-    //openair0_cfg[card].remote_addr = "127.0.0.1";
-    openair0_cfg[card].remote_addr = "74:d4:35:cc:88:45";
-    openair0_cfg[card].remote_port = 50000;
-    //openair0_cfg[card].my_addr = "192.168.12.31";
-    //openair0_cfg[card].my_addr = "127.0.0.1";
-    openair0_cfg[card].my_addr = "d4:be:d9:22:0a:ac";
-    openair0_cfg[card].my_port = 50000; 
-    //openair0_cfg[card].my_port = 50001;
-    openair0_cfg[card].tx_scheduling_advance = 10;
-    openair0_cfg[card].tx_sample_advance = 0;
-    openair0_cfg[card].txlaunch_wait = 0;
-    openair0_cfg[card].txlaunch_wait_slotcount = 0;
-
-    if (frame_parms[0]->N_RB_DL == 6) 
-      openair0_cfg[card].samples_per_packet = 256;
-    else 
-      openair0_cfg[card].samples_per_packet = 1024;
-
-    printf("HW: samples_per_packet %d\n",openair0_cfg[card].samples_per_packet);
-#endif
 
+    if (local_remote_radio == BBU_REMOTE_RADIO_HEAD) {      
+      openair0_cfg[card].remote_addr    = eth_params->remote_addr;
+      openair0_cfg[card].remote_port    = eth_params->remote_port;
+      openair0_cfg[card].my_addr        = eth_params->my_addr;
+      openair0_cfg[card].my_port        = eth_params->my_port;    
+    }
 
     printf("HW: Configuring card %d, nb_antennas_tx/rx %d/%d\n",card,
            ((UE_flag==0) ? PHY_vars_eNB_g[0][0]->lte_frame_parms.nb_antennas_tx : PHY_vars_UE_g[0][0]->lte_frame_parms.nb_antennas_tx),
@@ -3123,29 +3125,32 @@ int main( int argc, char **argv )
   openair0.transp_type = NONE_TP;
   openair0_cfg[0].log_level = glog_level;
 
-  
-  /* BBU can either have local or remote radio heads - local radio head option is set by default so the corresponding device is initiated */
-  if (mode!=loop_through_memory){
-    int ret;
-    ret= openair0_device_load(&openair0, &openair0_cfg[0]);
-    printf("openair0_device_load returns %d\n",ret);
-    if (ret<0) {
-      printf("Exiting, cannot initialize device\n");
-      exit(-1);
+  int returns=-1;
+  /* BBU can have either a local or a remote radio head */  
+  if (local_remote_radio == BBU_LOCAL_RADIO_HEAD) { //local radio head active  - load library of radio head and initiate it
+    if (mode!=loop_through_memory) {
+      returns=openair0_device_load(&openair0, &openair0_cfg[0]);
+      printf("openair0_device_init returns %d\n",returns);
+      if (returns<0) {
+	printf("Exiting, cannot initialize device\n");
+	exit(-1);
+      }
     }
-  }
-  else if (mode==loop_through_memory) {    
-  }
-  /* radio heads are remote so the trasnsport protocol is initiated */
-  if (local_remote_RF == BBU_REMOTE_RF_ENABLED) {
-    if ((mode!=loop_through_memory) && 
-	(openair0_transport_load(&openair0, &openair0_cfg[0]) <0)) {
-      printf("Exiting, cannot initialize transport protocol\n");
-      exit(-1);
+    else if (mode==loop_through_memory) {    
+    }
+  }  else { //remote radio head active - load library of transport protocol and initiate it 
+    if (mode!=loop_through_memory) {
+      returns=openair0_transport_load(&openair0, &openair0_cfg[0], eth_params);
+      printf("openair0_transport_init returns %d\n",returns);
+      if (returns<0) { 
+	printf("Exiting, cannot initialize transport protocol\n");
+	exit(-1);
+      }
     }
     else if (mode==loop_through_memory) {    
     }
   }   
+  
   //for EXMIMO
   //openair0_cfg[0].iq_rxrescale=15;  /* default value if build with EXMIMO */
   //rxrescale=openair0_cfg[0].iq_rxrescale; /* see comments near RX_IQRESCALELEN definition */
diff --git a/targets/RT/USER/rrh_gw.c b/targets/RT/USER/rrh_gw.c
index bfdb01948e..70ca744321 100644
--- a/targets/RT/USER/rrh_gw.c
+++ b/targets/RT/USER/rrh_gw.c
@@ -200,7 +200,7 @@ static rrh_module_t new_module (unsigned int id) {
   memset(rrh_mod.eth_dev.openair0_cfg,0,sizeof(openair0_config_t));
   /* get IP and MAC address */
   get_address(if_name,eth_mode);
-
+  
   if(eth_mode==ETH_UDP_MODE) {
     openair0_cfg.my_addr = &rrh_ip[0];
     openair0_cfg.my_port = rrh_port;
@@ -211,10 +211,14 @@ static rrh_module_t new_module (unsigned int id) {
     LOG_I(RRH,"RAW mode selected for ethernet.\n");
   } 
 
-  /* if use setrunnig parameters we should keep in device->priv keep if_name and raw/udp flag*/
+  /* */
+  eth_params_t *eth_params = (eth_params_t*)malloc(sizeof(eth_params_t));
+  memset(eth_params, 0, sizeof(eth_params_t));
+  eth_params->local_if_name     = if_name;
+  eth_params->transp_preference = eth_mode;
 
   /* ethernet device initialization */
-  if (openair0_transport_load(&rrh_mod.eth_dev, &openair0_cfg)<0,NULL) {
+  if (openair0_transport_load(&rrh_mod.eth_dev, &openair0_cfg,eth_params)<0) {
     LOG_E(RRH,"Exiting, cannot initialize ethernet interface.\n");
     exit(-1);
   }
-- 
GitLab