From 427b223136ce00cd933f86628729acf81c231c83 Mon Sep 17 00:00:00 2001
From: Laurent <laurent.thomas@open-cells.com>
Date: Mon, 27 Jul 2020 16:08:31 +0200
Subject: [PATCH] small fiwes

---
 cmake_targets/build_oai                            |  1 +
 common/utils/ocp_itti/intertask_interface.cpp      |  2 +-
 common/utils/threadPool/thread-pool.c              |  5 +++--
 executables/nr-uesoftmodem.c                       |  7 ++-----
 openair1/PHY/LTE_UE_TRANSPORT/prach_ue.c           |  2 +-
 openair1/PHY/NR_TRANSPORT/nr_prach.c               |  2 +-
 openair1/PHY/TOOLS/readme.md                       | 12 ++++++++++++
 openair1/PHY/phy_vars.h                            |  8 ++++----
 openair1/PHY/phy_vars_nr_ue.h                      |  2 +-
 openair1/SCHED_NR/phy_procedures_nr_gNB.c          |  2 +-
 openair2/ENB_APP/flexran_agent_extern.h            |  2 --
 openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c       |  2 +-
 targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c |  4 ++--
 targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp       |  1 -
 targets/ARCH/rfsimulator/simulator.c               | 12 ++++++++++--
 15 files changed, 40 insertions(+), 24 deletions(-)
 create mode 100644 openair1/PHY/TOOLS/readme.md

diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai
index 88b8811575b..e0093c909c2 100755
--- a/cmake_targets/build_oai
+++ b/cmake_targets/build_oai
@@ -580,6 +580,7 @@ function main() {
 
     cmake_file=$DIR/$build_dir/CMakeLists.txt
     echo "cmake_minimum_required(VERSION 2.8)"                             >  $cmake_file
+    echo "project (OpenAirInterface)"                                    >> $cmake_file
     echo "set ( CMAKE_BUILD_TYPE $CMAKE_BUILD_TYPE )"                     >> $cmake_file
     echo "set ( CFLAGS_PROCESSOR_USER \"$CFLAGS_PROCESSOR_USER\" )"       >> $cmake_file
     echo "set ( UE_EXPANSION $UE_EXPANSION )"                             >> $cmake_file
diff --git a/common/utils/ocp_itti/intertask_interface.cpp b/common/utils/ocp_itti/intertask_interface.cpp
index 22933fdd5be..1680410ebb5 100644
--- a/common/utils/ocp_itti/intertask_interface.cpp
+++ b/common/utils/ocp_itti/intertask_interface.cpp
@@ -80,7 +80,7 @@ task_list_t tasks[TASK_MAX];
 
   void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize_t size) {
     void *ptr = NULL;
-    AssertFatal ((ptr=malloc (size)) != NULL, "Memory allocation of %zu bytes failed (%d -> %d)!\n",
+    AssertFatal ((ptr=calloc (size, 1)) != NULL, "Memory allocation of %zu bytes failed (%d -> %d)!\n",
                  size, origin_task_id, destination_task_id);
     return ptr;
   }
diff --git a/common/utils/threadPool/thread-pool.c b/common/utils/threadPool/thread-pool.c
index cbb2dbe3d91..e1446f15d71 100644
--- a/common/utils/threadPool/thread-pool.c
+++ b/common/utils/threadPool/thread-pool.c
@@ -111,9 +111,10 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) {
   pool->activated=true;
   initNotifiedFIFO(&pool->incomingFifo);
   char *saveptr, * curptr;
+  char *parms_cpy=strdup(params);
   pool->nbThreads=0;
   pool->restrictRNTI=false;
-  curptr=strtok_r(params,",",&saveptr);
+  curptr=strtok_r(parms_cpy,",",&saveptr);
   struct one_thread * ptr;
   while ( curptr!=NULL ) {
     int c=toupper(curptr[0]);
@@ -145,7 +146,7 @@ void initTpool(char *params,tpool_t *pool, bool performanceMeas) {
 
     curptr=strtok_r(NULL,",",&saveptr);
   }
-
+  free(parms_cpy);
   if (pool->activated && pool->nbThreads==0) {
     printf("No servers created in the thread pool, exit\n");
     exit(1);
diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c
index 6d3bbc90385..e4c6d7b4395 100644
--- a/executables/nr-uesoftmodem.c
+++ b/executables/nr-uesoftmodem.c
@@ -76,12 +76,9 @@ unsigned short config_frames[4] = {2,9,11,13};
 #include <openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.h>
 #include <openair1/SCHED_NR_UE/fapi_nr_ue_l1.h>
 
-//#include "stats.h"
-// current status is that every UE has a DL scope for a SINGLE eNB (eNB_id=0)
-#include "PHY/TOOLS/nr_phy_scope.h"
-// at eNB 0, an UL scope for every UE
-//FD_lte_phy_scope_enb *form_enb[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
+/* Callbacks, globals and object handlers */
 
+#include "PHY/TOOLS/nr_phy_scope.h"
 #include <executables/nr-uesoftmodem.h>
 #include "executables/softmodem-common.h"
 #include "executables/thread-common.h"
diff --git a/openair1/PHY/LTE_UE_TRANSPORT/prach_ue.c b/openair1/PHY/LTE_UE_TRANSPORT/prach_ue.c
index e4083863f0d..ab7c2b90910 100644
--- a/openair1/PHY/LTE_UE_TRANSPORT/prach_ue.c
+++ b/openair1/PHY/LTE_UE_TRANSPORT/prach_ue.c
@@ -55,7 +55,7 @@ int32_t generate_prach( PHY_VARS_UE *ue, uint8_t eNB_id, uint8_t subframe, uint1
   uint8_t preamble_index     = ue->prach_resources[eNB_id]->ra_PreambleIndex;
   uint8_t tdd_mapindex       = ue->prach_resources[eNB_id]->ra_TDD_map_index;
   int16_t *prachF           = ue->prach_vars[eNB_id]->prachF;
-  static int16_t prach_tmp[45600*2] __attribute__((aligned(32)));
+  static int16_t prach_tmp[45600*4] __attribute__((aligned(32)));
   int16_t *prach            = prach_tmp;
   int16_t *prach2;
   int16_t amp               = ue->prach_vars[eNB_id]->amp;
diff --git a/openair1/PHY/NR_TRANSPORT/nr_prach.c b/openair1/PHY/NR_TRANSPORT/nr_prach.c
index 2640a86240b..d36dd6772bf 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_prach.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_prach.c
@@ -540,7 +540,7 @@ void rx_nr_prach(PHY_VARS_gNB *gNB,
   uint16_t           rootSequenceIndex;  
   int                numrootSequenceIndex;
   uint8_t            restricted_set;      
-  uint8_t            n_ra_prb;
+  uint8_t            n_ra_prb=0xFF;
   int16_t            *prachF=NULL;
   int                nb_rx;
 
diff --git a/openair1/PHY/TOOLS/readme.md b/openair1/PHY/TOOLS/readme.md
new file mode 100644
index 00000000000..f6671acc6df
--- /dev/null
+++ b/openair1/PHY/TOOLS/readme.md
@@ -0,0 +1,12 @@
+
+To use the scope, run the xNB or the UE with option "-d"  
+
+Usage in gdb
+In gdb, when you break, you can refresh immediatly the scope view by calling the display function.
+The first paramter is the graph context, nevertheless we keep the last value for a dirty call in gdb (so you can use '0')  
+
+Example with no variable known
+phy_scope_nrUE(0, PHY_vars_UE_g[0][0], 0, 0, 0)
+
+or
+phy_scope_gNB(0, phy_vars_gnb, phy_vars_ru, UE_id)
diff --git a/openair1/PHY/phy_vars.h b/openair1/PHY/phy_vars.h
index a74d148479d..5e2be8bd8f7 100644
--- a/openair1/PHY/phy_vars.h
+++ b/openair1/PHY/phy_vars.h
@@ -59,10 +59,10 @@ const short conjugate2[8]__attribute__((aligned(16))) = {1,-1,1,-1,1,-1,1,-1};
 unsigned char NB_RU=0;
 
 #ifndef OPENAIR2
-unsigned char NB_eNB_INST=0;
-uint16_t NB_UE_INST=0;
-unsigned char NB_RN_INST=0;
-unsigned char NB_INST=0;
+//unsigned char NB_eNB_INST=0;
+//uint16_t NB_UE_INST=0;
+//unsigned char NB_RN_INST=0;
+//unsigned char NB_INST=0;
 #endif
 
 int number_of_cards;
diff --git a/openair1/PHY/phy_vars_nr_ue.h b/openair1/PHY/phy_vars_nr_ue.h
index 1843d8d5bcd..baa64561f0e 100644
--- a/openair1/PHY/phy_vars_nr_ue.h
+++ b/openair1/PHY/phy_vars_nr_ue.h
@@ -138,4 +138,4 @@ uint8_t scrambling_lut[65536*16] __attribute__((aligned(32)));
 uint8_t max_ldpc_iterations=4;
 uint8_t max_turbo_iterations=4;
 
-#endif /*__PHY_VARS_H__ */
+#endif
diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index 992c908c5d2..94e356951aa 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -424,7 +424,7 @@ void phy_procedures_gNB_uespec_RX(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx)
   for (int ULSCH_id=0;ULSCH_id<NUMBER_OF_NR_ULSCH_MAX;ULSCH_id++) {
     NR_gNB_ULSCH_t *ulsch = gNB->ulsch[ULSCH_id][0];
     int harq_pid;
-    int no_sig;
+    //int no_sig;
     NR_UL_gNB_HARQ_t *ulsch_harq;
 
     if ((ulsch) &&
diff --git a/openair2/ENB_APP/flexran_agent_extern.h b/openair2/ENB_APP/flexran_agent_extern.h
index 5f17cf4841e..2a5930e1a8b 100644
--- a/openair2/ENB_APP/flexran_agent_extern.h
+++ b/openair2/ENB_APP/flexran_agent_extern.h
@@ -44,8 +44,6 @@ AGENT_PHY_xface *flexran_agent_get_phy_xface(mid_t mod_id);
 
 extern AGENT_MAC_xface *agent_mac_xface[NUM_MAX_ENB];
 #define flexran_agent_get_mac_xface(mod_id) (agent_mac_xface[mod_id])
-/* Control module interface for the communication of the RRC Control Module with the agent */
-
 /* Control module interface for the communication of the RRC Control Module with the agent */
 // AGENT_RRC_xface *flexran_agent_get_rrc_xface(mid_t mod_id);
 extern AGENT_RRC_xface *agent_rrc_xface[NUM_MAX_ENB];
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
index 56ae14f98b8..840aafa9430 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
@@ -360,7 +360,7 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources,
 
   uint8_t sdu_lcids[NB_RB_MAX] = {0};
   uint16_t sdu_lengths[NB_RB_MAX] = {0};
-  int TBS_bytes = 848, header_length_total, num_sdus, offset, preambleTransMax, mac_ce_len;
+  int TBS_bytes = 848, header_length_total=0, num_sdus, offset, preambleTransMax, mac_ce_len;
 
   AssertFatal(CC_id == 0,"Transmission on secondary CCs is not supported yet\n");
 
diff --git a/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c b/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c
index c72e7d41300..1d3c280f0e5 100644
--- a/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c
+++ b/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c
@@ -288,7 +288,7 @@ int ethernet_tune(openair0_device *device,
     /******************* interface level options  *************************/
     case MTU_SIZE: /* change  MTU of the eth interface */
         ifr.ifr_addr.sa_family = AF_INET;
-        strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name));
+        strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name)-1);
         ifr.ifr_mtu =value;
         if (ioctl(eth->sockfdd,SIOCSIFMTU,(caddr_t)&ifr) < 0 )
             perror ("[ETHERNET] Can't set the MTU");
@@ -298,7 +298,7 @@ int ethernet_tune(openair0_device *device,
 
     case TX_Q_LEN:  /* change TX queue length of eth interface */
         ifr.ifr_addr.sa_family = AF_INET;
-        strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name));
+        strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name)-1);
         ifr.ifr_qlen =value;
         if (ioctl(eth->sockfdd,SIOCSIFTXQLEN,(caddr_t)&ifr) < 0 )
             perror ("[ETHERNET] Can't set the txqueuelen");
diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
index 1377086e8f4..6e94717a6fb 100644
--- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
+++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp
@@ -976,7 +976,6 @@ extern "C" {
     double usrp_master_clock;
   
     if (device_adds[0].get("type") == "b200") {
-      printf("Found USRP b200\n");
       device->type = USRP_B200_DEV;
       usrp_master_clock = 30.72e6;
       args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock);
diff --git a/targets/ARCH/rfsimulator/simulator.c b/targets/ARCH/rfsimulator/simulator.c
index b7b435f2d92..9f9e316da8b 100644
--- a/targets/ARCH/rfsimulator/simulator.c
+++ b/targets/ARCH/rfsimulator/simulator.c
@@ -148,15 +148,18 @@ void allocCirBuf(rfsimulator_state_t *bridge, int sock) {
     // Legacy changes directlty the variable channel_model->path_loss_dB place to place
     // while calling new_channel_desc_scm() with path losses = 0
     static bool init_done=false;
+
     if (!init_done) {
 	    uint64_t rand;
 	    FILE *h=fopen("/dev/random","r");
-            fread(&rand,sizeof(rand),1,h);
+            if ( 1 != fread(&rand,sizeof(rand),1,h) )
+              LOG_W(HW, "Simulator can't read /dev/random\n");
 	    fclose(h);
       randominit(rand);
       tableNor(rand);
       init_done=true;
     }
+
     ptr->channel_model=new_channel_desc_scm(bridge->tx_num_channels,bridge->rx_num_channels,
                                             bridge->channelmod,
                                             bridge->sample_rate,
@@ -379,6 +382,7 @@ static int rfsimulator_write_internal(rfsimulator_state_t *t, openair0_timestamp
   if (t->lastWroteTS > timestamp+nsamps)
     LOG_E(HW,"Not supported to send Tx out of order (same in USRP) %lu, %lu\n",
               t->lastWroteTS, timestamp);
+
   t->lastWroteTS=timestamp+nsamps;
 
   if (!alreadyLocked)
@@ -480,6 +484,7 @@ static bool flushInput(rfsimulator_state_t *t, int timeout, int nsamps_for_initi
 	  b->trashingPacket=true;
 	} else if ( b->lastReceivedTS < b->th.timestamp) {
           int nbAnt= b->th.nbAnt;
+
           if ( b->th.timestamp-b->lastReceivedTS < CirSize ) {
           for (uint64_t index=b->lastReceivedTS; index < b->th.timestamp; index++ ) {
             for (int a=0; a < nbAnt; a++) {
@@ -490,8 +495,10 @@ static bool flushInput(rfsimulator_state_t *t, int timeout, int nsamps_for_initi
           } else {
 	    memset(b->circularBuf, 0, sampleToByte(CirSize,1));
 	  }
+
           if (b->lastReceivedTS != 0 && b->th.timestamp-b->lastReceivedTS > 50 )
             LOG_W(HW,"UEsock: %d gap of: %ld in reception\n", fd, b->th.timestamp-b->lastReceivedTS );
+
           b->lastReceivedTS=b->th.timestamp;
 	  
         } else if ( b->lastReceivedTS > b->th.timestamp && b->th.size == 1 ) {
@@ -510,7 +517,7 @@ static bool flushInput(rfsimulator_state_t *t, int timeout, int nsamps_for_initi
           LOG_E(HW,"UEsock: %d Tx/Rx shift too large Tx:%lu, Rx:%lu\n", fd, t->lastWroteTS, b->lastReceivedTS);
 
         pthread_mutex_unlock(&Sockmutex);
-        b->transferPtr=(char *)&b->circularBuf[b->lastReceivedTS%CirSize];
+        b->transferPtr=(char *)&b->circularBuf[(b->lastReceivedTS*b->th.nbAnt)%CirSize];
         b->remainToTransfer=sampleToByte(b->th.size, b->th.nbAnt);
       }
 
@@ -653,6 +660,7 @@ int rfsimulator_read(openair0_device *device, openair0_timestamp *ptimestamp, vo
         else { // no channel modeling
           sample_t *out=(sample_t *)samplesVoid[a];
           const int64_t base=t->nextTimestamp*nbAnt+a;
+
           for ( int i=0; i < nsamps; i++ ) {
 	    const int idx=(i*nbAnt+base)%CirSize;
             out[i].r+=ptr->circularBuf[idx].r;
-- 
GitLab