From b215b431f018bf1d95f4e52fce901c47209665bf Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Mon, 25 Dec 2017 04:25:37 -0800
Subject: [PATCH] changes to allow configuring multicast interface on command
 line

---
 common/config/config_cmdline.c       |  6 +++++-
 targets/RT/USER/lte-softmodem-stub.c | 12 +++++++++---
 targets/RT/USER/lte-softmodem.c      |  3 +++
 targets/RT/USER/lte-softmodem.h      |  4 +++-
 targets/RT/USER/lte-ue.c             |  7 ++++---
 5 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/common/config/config_cmdline.c b/common/config/config_cmdline.c
index 42ea7259c31..fd30ff9d007 100644
--- a/common/config/config_cmdline.c
+++ b/common/config/config_cmdline.c
@@ -35,6 +35,8 @@
 #include <errno.h>
 #include "config_userapi.h"
 
+extern char *emul_iface;
+
 int processoption(paramdef_t *cfgoptions, char *value)
 {
 char *tmpval = value;
@@ -54,8 +56,9 @@ char defbool[2]="1";
        	case TYPE_STRING:
            config_check_valptr(cfgoptions, (char **)(cfgoptions->strptr), sizeof(char *));
            config_check_valptr(cfgoptions, cfgoptions->strptr, strlen(tmpval+1));
+	   printf("cfgoptions->strptr %p (&emul_iface %p, emul_iface %p)\n",cfgoptions->strptr,&emul_iface,emul_iface);
            sprintf(*(cfgoptions->strptr), "%s",tmpval);
-           printf_cmdl("[CONFIG] %s set to  %s from command line\n", cfgoptions->optname, tmpval);
+           printf("[CONFIG] %s set to  %s from command line\n", cfgoptions->optname, tmpval);
 	   optisset=1;
         break;
 	
@@ -112,6 +115,7 @@ int j;
 char *pp;
 char *cfgpath; 
  
+
   j = (prefix ==NULL) ? 0 : strlen(prefix); 
   cfgpath = malloc( j + MAX_OPTNAME_SIZE +1);
   if (cfgpath == NULL) {
diff --git a/targets/RT/USER/lte-softmodem-stub.c b/targets/RT/USER/lte-softmodem-stub.c
index 3e62bc68f95..958bb03f7bd 100644
--- a/targets/RT/USER/lte-softmodem-stub.c
+++ b/targets/RT/USER/lte-softmodem-stub.c
@@ -130,6 +130,8 @@ uint8_t nfapi_mode = 3;
 
 uint16_t sf_ahead=4;
 
+char *emul_iface;
+
 pthread_cond_t sync_cond;
 pthread_mutex_t sync_mutex;
 int sync_var=-1; //!< protected by mutex \ref sync_mutex.
@@ -228,7 +230,7 @@ extern PHY_VARS_UE* init_ue_vars(LTE_DL_FRAME_PARMS *frame_parms,
 			  uint8_t abstraction_flag);
 
 extern void init_eNB_afterRU(void);
-extern void init_UE_stub(int nb_inst,int,int);
+extern void init_UE_stub(int nb_inst,int,int,char*);
 extern int init_timer_thread(void);
 
 int transmission_mode=1;
@@ -672,13 +674,16 @@ static void get_options(void) {
      uint8_t n_rb_dl;
 
      paramdef_t cmdline_uemodeparams[] =CMDLINE_UEMODEPARAMS_DESC;
-     paramdef_t cmdline_ueparams[] =CMDLINE_UEPARAMS_DESC;
+     paramdef_t cmdline_ueparams[] =CMDLINE_UEPARAMS_DESC; 
 
      set_default_frame_parms(frame_parms);
 
+     emul_iface=malloc(100);
+
      config_process_cmdline( cmdline_uemodeparams,sizeof(cmdline_uemodeparams)/sizeof(paramdef_t),NULL);
      config_process_cmdline( cmdline_ueparams,sizeof(cmdline_ueparams)/sizeof(paramdef_t),NULL);
 
+
       if (loopfile != NULL) {
   	  printf("Input file for hardware emulation: %s",loopfile);
   	  mode=loop_through_memory;
@@ -739,6 +744,7 @@ static void get_options(void) {
 	    rx_gain[0][CC_id] = rx_gain[0][0];
 	    tx_gain[0][CC_id] = tx_gain[0][0];
       }
+      printf("Emulation interface : %s (%p,%p)\n",emul_iface,emul_iface,&emul_iface);
   } /* UE_flag > 0 */
 #if T_TRACER
   paramdef_t cmdline_ttraceparams[] =CMDLINE_TTRACEPARAMS_DESC ;
@@ -1359,7 +1365,7 @@ int main( int argc, char **argv )
 
 
     init_timer_thread();
-    init_UE_stub(1,eMBMS_active,uecap_xer_in);
+    init_UE_stub(1,eMBMS_active,uecap_xer_in,emul_iface);
 
     /*for(CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
       PHY_vars_UE_g[0][CC_id]->rf_map.card=0;
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index 6cb872e21b0..b76f8734361 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -120,6 +120,8 @@ uint8_t nfapi_mode = 2;
 
 uint16_t sf_ahead=4;
 
+char emul_iface[100];
+
 pthread_cond_t sync_cond;
 pthread_mutex_t sync_mutex;
 int sync_var=-1; //!< protected by mutex \ref sync_mutex.
@@ -609,6 +611,7 @@ static void get_options(void) {
   if (UE_flag > 0) {
      uint8_t n_rb_dl;
      nfapi_mode=0;
+
      paramdef_t cmdline_uemodeparams[] =CMDLINE_UEMODEPARAMS_DESC;
      paramdef_t cmdline_ueparams[] =CMDLINE_UEPARAMS_DESC;
 
diff --git a/targets/RT/USER/lte-softmodem.h b/targets/RT/USER/lte-softmodem.h
index c12e275f92b..a1efac88606 100644
--- a/targets/RT/USER/lte-softmodem.h
+++ b/targets/RT/USER/lte-softmodem.h
@@ -72,6 +72,7 @@
 #define CONFIG_HLP_DLMCS         "Set the maximum downlink MCS\n"
 #define CONFIG_HLP_STMON         "Enable processing timing measurement of lte softmodem on per subframe basis \n"
 #define CONFIG_HLP_PRB           "Set the PRB, valid values: 6, 25, 50, 100  \n"    
+#define CONFIG_HLP_EMULIFACE     "Set the interface name for the multicast transport for emulation mode (e.g. eth0, lo, etc.)  \n"    
 #define CONFIG_HLP_MSLOTS        "Skip the missed slots/subframes \n"    
 #define CONFIG_HLP_ULMCS         "Set the maximum uplink MCS\n"
 #define CONFIG_HLP_TDD           "Set hardware to TDD mode (default: FDD). Used only with -U (otherwise set in config file).\n"
@@ -128,7 +129,8 @@
 {"ue-scan-carrier",  	       CONFIG_HLP_UESCAN,     PARAMFLAG_BOOL,	iptr:&UE_scan_carrier,  	    defintval:0,    TYPE_INT,	   0},     \
 {"ue-max-power",     	       NULL,		      0,		iptr:&(tx_max_power[0]),	    defintval:90,   TYPE_INT,	   0},     \
 {"r"  ,                        CONFIG_HLP_PRB,        0,                u8ptr:&n_rb_dl,                     defintval:0,    TYPE_UINT8,    0},     \
-}
+{"emul-iface",                 CONFIG_HLP_EMULIFACE,  0,                strptr:&emul_iface,                  defstrval:"lo", TYPE_STRING,   100} \
+ }
 
 
 extern int16_t dlsch_demod_shift;
diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index 0c14d93e76b..b7e80add5de 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -77,7 +77,7 @@ void init_UE_threads(int);
 void init_UE_threads_stub(int);
 void *UE_thread(void *arg);
 void init_UE(int nb_inst,int,int);
-void init_UE_stub(int nb_inst,int,int);
+void init_UE_stub(int nb_inst,int,int,char*);
 extern void oai_subframe_ind(uint16_t sfn, uint16_t sf);
 //extern int tx_req_UE_MAC1();
 
@@ -270,7 +270,7 @@ void init_UE(int nb_inst,int eMBMS_active, int uecap_xer_in) {
 }
 
 
-void init_UE_stub(int nb_inst,int eMBMS_active, int uecap_xer_in) {
+void init_UE_stub(int nb_inst,int eMBMS_active, int uecap_xer_in, char *emul_iface) {
 
   int         inst;
 
@@ -291,7 +291,8 @@ void init_UE_stub(int nb_inst,int eMBMS_active, int uecap_xer_in) {
 
   printf("UE threads created \n");
 
-  multicast_link_start(ue_stub_rx_handler,0,"lo");
+  LOG_I(PHY,"Starting multicast link on %s\n",emul_iface);
+  multicast_link_start(ue_stub_rx_handler,0,emul_iface);
 
 
 }
-- 
GitLab