diff --git a/ci-scripts/conf_files/channelmod_rfsimu.conf b/ci-scripts/conf_files/channelmod_rfsimu.conf
index 9a6ded24f11dbc8b5131872284c43b5e96a3846b..cd4490d9ba4887eff8f1484473466023c3062236 100644
--- a/ci-scripts/conf_files/channelmod_rfsimu.conf
+++ b/ci-scripts/conf_files/channelmod_rfsimu.conf
@@ -15,7 +15,7 @@ channelmod = {
         ds_tdl                           = 0;      
     },
     {
-        model_name                       = "rfsimu_channel_ue1"
+        model_name                       = "rfsimu_channel_ue0"
       	type                             = "AWGN";			  
       	ploss_dB                         = 0;
         noise_power_dB                   = 0; 
diff --git a/ci-scripts/conf_files/enb.band38.lte_2x2.100PRB.usrpn310.conf b/ci-scripts/conf_files/enb.band38.lte_2x2.100PRB.usrpn310.conf
new file mode 100644
index 0000000000000000000000000000000000000000..d2e91fb872b39707671ad39e130aa33a092eef51
--- /dev/null
+++ b/ci-scripts/conf_files/enb.band38.lte_2x2.100PRB.usrpn310.conf
@@ -0,0 +1,281 @@
+Active_eNBs = ( "eNB-Eurecom-B38");
+# Asn1_verbosity, choice in: none, info, annoying
+Asn1_verbosity = "none";
+
+eNBs =
+(
+ {
+    ////////// Identification parameters:
+    eNB_ID    =  0xe02;
+
+    cell_type =  "CELL_MACRO_ENB";
+
+    eNB_name  =  "eNB-Eurecom-B38";
+
+    // Tracking area code, 0x0000 and 0xfffe are reserved values
+    tracking_area_code = 1;
+    plmn_list = ( { mcc = 208; mnc = 97; mnc_length = 2; } );
+
+    tr_s_preference     = "local_mac"
+
+    ////////// Physical parameters:
+
+    component_carriers = (
+      {
+      node_function             = "3GPP_eNODEB";
+      node_timing               = "synch_to_ext_device";
+      node_synch_ref            = 0;
+      frame_type					      = "TDD";
+      tdd_config 					      = 1;
+      tdd_config_s            			      = 0;
+      prefix_type             			      = "NORMAL";
+      eutra_band              			      = 38;
+      downlink_frequency      			      = 2605000000L;
+      nr_scg_ssb_freq                                 = 624608;
+      uplink_frequency_offset 			      = 0;
+      Nid_cell					      = 0;
+      N_RB_DL                 			      = 100;
+      Nid_cell_mbsfn          			      = 0;
+      nb_antenna_ports                                = 1;
+      nb_antennas_tx          			      = 2;
+      nb_antennas_rx          			      = 2;
+      tx_gain                                            = 90;
+      rx_gain                                            = 125;
+      pbch_repetition                                 = "FALSE";
+      prach_root              			      = 0;
+      prach_config_index      			      = 0;
+      prach_high_speed        			      = "DISABLE";
+      prach_zero_correlation  			      = 1;
+      prach_freq_offset       			      = 2;
+      pucch_delta_shift       			      = 1;
+      pucch_nRB_CQI           			      = 0;
+      pucch_nCS_AN            			      = 0;
+      pucch_n1_AN             			      = 0;
+      pdsch_referenceSignalPower 			      = -29;
+      pdsch_p_b                  			      = 0;
+      pusch_n_SB                 			      = 1;
+      pusch_enable64QAM          			      = "DISABLE";
+      pusch_hoppingMode                                  = "interSubFrame";
+      pusch_hoppingOffset                                = 0;
+      pusch_groupHoppingEnabled  			      = "ENABLE";
+      pusch_groupAssignment      			      = 0;
+      pusch_sequenceHoppingEnabled		   	      = "DISABLE";
+      pusch_nDMRS1                                       = 1;
+      phich_duration                                     = "NORMAL";
+      phich_resource                                     = "ONESIXTH";
+      srs_enable                                         = "DISABLE";
+      /*  srs_BandwidthConfig                                =;
+      srs_SubframeConfig                                 =;
+      srs_ackNackST                                      =;
+      srs_MaxUpPts                                       =;*/
+
+      pusch_p0_Nominal                                   = -96;
+      pusch_alpha                                        = "AL1";
+      pucch_p0_Nominal                                   = -104;
+      msg3_delta_Preamble                                = 6;
+      pucch_deltaF_Format1                               = "deltaF2";
+      pucch_deltaF_Format1b                              = "deltaF3";
+      pucch_deltaF_Format2                               = "deltaF0";
+      pucch_deltaF_Format2a                              = "deltaF0";
+      pucch_deltaF_Format2b		    	      = "deltaF0";
+
+      rach_numberOfRA_Preambles                          = 64;
+      rach_preamblesGroupAConfig                         = "DISABLE";
+      /*
+      rach_sizeOfRA_PreamblesGroupA                      = ;
+      rach_messageSizeGroupA                             = ;
+      rach_messagePowerOffsetGroupB                      = ;
+      */
+      rach_powerRampingStep                              = 4;
+      rach_preambleInitialReceivedTargetPower            = -108;
+      rach_preambleTransMax                              = 10;
+      rach_raResponseWindowSize                          = 10;
+      rach_macContentionResolutionTimer                  = 48;
+      rach_maxHARQ_Msg3Tx                                = 4;
+
+      pcch_default_PagingCycle                           = 128;
+      pcch_nB                                            = "oneT";
+      bcch_modificationPeriodCoeff			      = 2;
+      ue_TimersAndConstants_t300			      = 1000;
+      ue_TimersAndConstants_t301			      = 1000;
+      ue_TimersAndConstants_t310			      = 1000;
+      ue_TimersAndConstants_t311			      = 10000;
+      ue_TimersAndConstants_n310			      = 20;
+      ue_TimersAndConstants_n311			      = 1;
+      ue_TransmissionMode                                    = 1;
+
+      //Parameters for SIB18
+      rxPool_sc_CP_Len                                       = "normal";
+      rxPool_sc_Period                                       = "sf40";
+      rxPool_data_CP_Len                                     = "normal";
+      rxPool_ResourceConfig_prb_Num                          = 20;
+      rxPool_ResourceConfig_prb_Start                        = 5;
+      rxPool_ResourceConfig_prb_End                          = 44;
+      rxPool_ResourceConfig_offsetIndicator_present          = "prSmall";
+      rxPool_ResourceConfig_offsetIndicator_choice           = 0;
+      rxPool_ResourceConfig_subframeBitmap_present           = "prBs40";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_buf              = "00000000000000000000";
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_size             = 5;
+      rxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused      = 0;
+/*    rxPool_dataHoppingConfig_hoppingParameter                       = 0;
+      rxPool_dataHoppingConfig_numSubbands                            = "ns1";
+      rxPool_dataHoppingConfig_rbOffset                               = 0;
+      rxPool_commTxResourceUC-ReqAllowed                              = "TRUE";
+*/
+      // Parameters for SIB19
+      discRxPool_cp_Len                                               = "normal"
+      discRxPool_discPeriod                                           = "rf32"
+      discRxPool_numRetx                                              = 1;
+      discRxPool_numRepetition                                        = 2;
+      discRxPool_ResourceConfig_prb_Num                               = 5;
+      discRxPool_ResourceConfig_prb_Start                             = 3;
+      discRxPool_ResourceConfig_prb_End                               = 21;
+      discRxPool_ResourceConfig_offsetIndicator_present               = "prSmall";
+      discRxPool_ResourceConfig_offsetIndicator_choice                = 0;
+      discRxPool_ResourceConfig_subframeBitmap_present                = "prBs40";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_buf          = "f0ffffffff";
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_size         = 5;
+      discRxPool_ResourceConfig_subframeBitmap_choice_bs_bits_unused  = 0;
+
+      }
+    );
+
+
+    srb1_parameters :
+    {
+        # timer_poll_retransmit = (ms) [5, 10, 15, 20,... 250, 300, 350, ... 500]
+        timer_poll_retransmit    = 80;
+
+        # timer_reordering = (ms) [0,5, ... 100, 110, 120, ... ,200]
+        timer_reordering         = 35;
+
+        # timer_reordering = (ms) [0,5, ... 250, 300, 350, ... ,500]
+        timer_status_prohibit    = 0;
+
+        # poll_pdu = [4, 8, 16, 32 , 64, 128, 256, infinity(>10000)]
+        poll_pdu                 =  4;
+
+        # poll_byte = (kB) [25,50,75,100,125,250,375,500,750,1000,1250,1500,2000,3000,infinity(>10000)]
+        poll_byte                =  99999;
+
+        # max_retx_threshold = [1, 2, 3, 4 , 6, 8, 16, 32]
+        max_retx_threshold       =  4;
+    }
+
+    # ------- SCTP definitions
+    SCTP :
+    {
+        # Number of streams to use in input/output
+        SCTP_INSTREAMS  = 2;
+        SCTP_OUTSTREAMS = 2;
+    };
+
+
+    ////////// MME parameters:
+    mme_ip_address      = ( { ipv4       = "CI_MME_IP_ADDR";
+                              ipv6       = "192:168:30::17";
+                              active     = "yes";
+                              preference = "ipv4";
+                            }
+                          );
+
+    enable_measurement_reports = "no";
+
+    ///X2
+    enable_x2 = "yes";
+    t_reloc_prep      = 1000;      /* unit: millisecond */
+    tx2_reloc_overall = 2000;      /* unit: millisecond */
+    t_dc_prep         = 1000;      /* unit: millisecond */
+    t_dc_overall      = 2000;      /* unit: millisecond */
+
+    NETWORK_INTERFACES :
+    {
+        ENB_INTERFACE_NAME_FOR_S1_MME            = "eno1";
+        ENB_IPV4_ADDRESS_FOR_S1_MME              = "CI_ENB_IP_ADDR";
+        ENB_INTERFACE_NAME_FOR_S1U               = "eno1";
+        ENB_IPV4_ADDRESS_FOR_S1U                 = "CI_ENB_IP_ADDR";
+        ENB_PORT_FOR_S1U                         = 2152; # Spec 2152
+        ENB_IPV4_ADDRESS_FOR_X2C                 = "CI_ENB_IP_ADDR";
+        ENB_PORT_FOR_X2C                         = 36422; # Spec 36422
+    };
+  }
+);
+
+MACRLCs = (
+	{
+	num_cc = 1;
+	tr_s_preference = "local_L1";
+	tr_n_preference = "local_RRC";
+	phy_test_mode = 0;
+        scheduler_mode = "fairRR";
+        bler_target_upper = 20.0;
+        bler_target_lower = 10.0;
+        max_ul_rb_index   = 27;
+        puSch10xSnr     =  200;
+        puCch10xSnr     =  150;
+        }  
+);
+
+L1s = (
+    	{
+	num_cc = 1;
+	tr_n_preference = "local_mac";
+        prach_dtx_threshold = 200;
+        pucch1_dtx_threshold = 5
+        pucch1ab_dtx_threshold =0;
+        }  
+);
+
+RUs = (
+    {		  
+       local_rf       = "yes"
+         nb_tx          = 2
+         nb_rx          = 2
+         att_tx         = 0
+         att_rx         = 0;
+         bands          = [38];
+         max_pdschReferenceSignalPower = -27;
+         max_rxgain                    = 75;
+         eNB_instances  = [0];
+         sdr_addrs      = "mgmt_addr=192.168.18.241,addr=192.168.20.2,second_addr=192.168.10.2";
+
+    }
+);  
+
+THREAD_STRUCT = (
+  {
+    #three config for level of parallelism "PARALLEL_SINGLE_THREAD", "PARALLEL_RU_L1_SPLIT", or "PARALLEL_RU_L1_TRX_SPLIT"
+    parallel_config    = "PARALLEL_SINGLE_THREAD";
+    #two option for worker "WORKER_DISABLE" or "WORKER_ENABLE"
+    worker_config      = "WORKER_ENABLE";
+  }
+);
+
+NETWORK_CONTROLLER :
+{
+    FLEXRAN_ENABLED        = "no";
+    FLEXRAN_INTERFACE_NAME = "lo";
+    FLEXRAN_IPV4_ADDRESS   = "127.0.0.1";
+    FLEXRAN_PORT           = 2210;
+    FLEXRAN_CACHE          = "/mnt/oai_agent_cache";
+    FLEXRAN_AWAIT_RECONF   = "no";
+};
+
+     log_config :
+     {
+       global_log_level                      ="info";
+       global_log_verbosity                  ="medium";
+       hw_log_level                          ="info";
+       hw_log_verbosity                      ="medium";
+       phy_log_level                         ="info";
+       phy_log_verbosity                     ="medium";
+       mac_log_level                         ="info";
+       mac_log_verbosity                     ="high";
+       rlc_log_level                         ="info";
+       rlc_log_verbosity                     ="medium";
+       pdcp_log_level                        ="info";
+       pdcp_log_verbosity                    ="medium";
+       rrc_log_level                         ="info";
+       rrc_log_verbosity                     ="medium";
+    };
+
diff --git a/ci-scripts/conf_files/enb.band38.nsa_2x2.100PRB.usrpn310.conf b/ci-scripts/conf_files/enb.band38.nsa_2x2.100PRB.usrpn310.conf
index 3460b82ac5ce501b4075d3325e4d9e48652f092d..7a9df0499647da1b3ddaccc3aae0f1b3279fc4ad 100644
--- a/ci-scripts/conf_files/enb.band38.nsa_2x2.100PRB.usrpn310.conf
+++ b/ci-scripts/conf_files/enb.band38.nsa_2x2.100PRB.usrpn310.conf
@@ -6,7 +6,7 @@ eNBs =
 (
  {
     ////////// Identification parameters:
-    eNB_ID    =  0xe00;
+    eNB_ID    =  0xe05;
 
     cell_type =  "CELL_MACRO_ENB";
 
diff --git a/ci-scripts/conf_files/gnb.band78.nsa_2x2.106PRB.usrpn310.conf b/ci-scripts/conf_files/gnb.band78.nsa_2x2.106PRB.usrpn310.conf
index e6fafd1ef2967b06563c918021532bb976cde896..a4452b202d76a6973cf77637ec5fb9d3f2cf0aaa 100644
--- a/ci-scripts/conf_files/gnb.band78.nsa_2x2.106PRB.usrpn310.conf
+++ b/ci-scripts/conf_files/gnb.band78.nsa_2x2.106PRB.usrpn310.conf
@@ -251,6 +251,7 @@ RUs = (
          eNB_instances  = [0];
          bf_weights = [0x00007fff, 0x00007fff];
          #clock_src = "external";
+         sf_extension = 0 
          sdr_addrs = "mgmt_addr=192.168.18.240,addr=192.168.10.2,second_addr=192.168.20.2,clock_source=internal,time_source=internal"
     }
 );  
diff --git a/ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.2x2.usrpn310.conf b/ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.2x2.usrpn310.conf
index 819f48b7bd7d8d0d0fbbabffc0644bb2eb2c6b60..c889ba2b89d904f9d62726a82f43361b7429c855 100644
--- a/ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.2x2.usrpn310.conf
+++ b/ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.2x2.usrpn310.conf
@@ -253,8 +253,8 @@ MACRLCs = (
     num_cc           = 1;
     tr_s_preference  = "local_L1";
     tr_n_preference  = "local_RRC";
-    pusch_TargetSNRx10 = 200;
-    pucch_TargetSNRx10 = 150;
+#    pusch_TargetSNRx10 = 200;
+#    pucch_TargetSNRx10 = 150;
     ulsch_max_slots_inactivity=20;
   }
 );
@@ -265,7 +265,7 @@ L1s = (
       tr_n_preference = "local_mac";
       pusch_proc_threads = 2;
       prach_dtx_threshold = 120;
-      pucch0_dtx_threshold = 150;
+#      pucch0_dtx_threshold = 150;
       }
 );
 
@@ -288,7 +288,7 @@ RUs = (
          # bf_weights = [0x00007fff, 0x00000000, 0x00000000, 0x00007fff];
          ## beamforming 4x4 matrix:
          #bf_weights = [0x00007fff, 0x0000, 0x0000, 0x0000, 0x00000000, 0x00007fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x00007fff, 0x0000, 0x0000, 0x0000, 0x0000, 0x00007fff];
-
+         sf_extension = 0
          sdr_addrs = "mgmt_addr=192.168.18.240,addr=192.168.10.2,second_addr=192.168.20.2,clock_source=internal,time_source=internal"
     }
 );
diff --git a/ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf b/ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf
index 145f58cb9353f19bb26abc4042ededa7a483faab..1cca2c92684120991d0e378bfec61b2cda1d25f5 100644
--- a/ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf
+++ b/ci-scripts/conf_files/gnb.band78.sa.fr1.106PRB.usrpn310.conf
@@ -219,7 +219,7 @@ gNBs =
         GNB_IPV4_ADDRESS_FOR_NG_AMF              = "CI_GNB_IP_ADDR";
         GNB_INTERFACE_NAME_FOR_NGU               = "eth0";
         GNB_IPV4_ADDRESS_FOR_NGU                 = "CI_GNB_IP_ADDR";
-        GNB_PORT_FOR_S1U                         = 2152; # Spec 2152
+        GNB_PORT_FOR_NGU                         = 2152; # Spec 2152
     };
 
   }
diff --git a/ci-scripts/xml_files/fr1_lte_2x2_quectel.xml b/ci-scripts/xml_files/fr1_lte_2x2_quectel.xml
index 86d9e5d5f0dbe2b86c9a91a2bbf6b2fc7ba3fc8c..03d474aef04b79a763e58d76e7044740b4d20125 100644
--- a/ci-scripts/xml_files/fr1_lte_2x2_quectel.xml
+++ b/ci-scripts/xml_files/fr1_lte_2x2_quectel.xml
@@ -59,7 +59,7 @@
 	<testCase id="030000">
 		<class>Initialize_eNB</class>
 		<desc>Initialize eNB</desc>
-		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band38.nsa_2x2.100PRB.usrpn310.conf --usrp-tx-thread-config 1 --thread-pool 0,2,4,6</Initialize_eNB_args>
+		<Initialize_eNB_args>-O ci-scripts/conf_files/enb.band38.lte_2x2.100PRB.usrpn310.conf --usrp-tx-thread-config 1 --thread-pool 0,2,4,6</Initialize_eNB_args>
 		<eNB_instance>0</eNB_instance>
 		<eNB_serverId>0</eNB_serverId>
 		<air_interface>lte</air_interface>
diff --git a/common/utils/nr/nr_common.c b/common/utils/nr/nr_common.c
index 8ba4633604a5933d7245d3656b0c754b849f47bf..c26eb63b6ac77c62994f138ab6d29080ed1335bd 100644
--- a/common/utils/nr/nr_common.c
+++ b/common/utils/nr/nr_common.c
@@ -34,6 +34,8 @@
 #include "assertions.h"
 #include "nr_common.h"
 
+const char *duplex_mode[]={"FDD","TDD"};
+
 // Table 5.2-1 NR operating bands in FR1 & FR2 (3GPP TS 38.101)
 // Table 5.4.2.3-1 Applicable NR-ARFCN per operating band in FR1 & FR2 (3GPP TS 38.101)
 // Notes:
@@ -249,6 +251,176 @@ int get_dmrs_port(int nl, uint16_t dmrs_ports) {
   return p;
 }
 
+int get_num_dmrs(uint16_t dmrs_mask ) {
+
+  int num_dmrs=0;
+
+  for (int i=0;i<16;i++) num_dmrs+=((dmrs_mask>>i)&1);
+  return(num_dmrs);
+}
+
+lte_frame_type_t get_frame_type(uint16_t current_band, uint8_t scs_index)
+{
+  lte_frame_type_t current_type;
+  int32_t delta_duplex = get_delta_duplex(current_band, scs_index);
+
+  if (delta_duplex == 0)
+    current_type = TDD;
+  else
+    current_type = FDD;
+
+  LOG_I(NR_MAC, "NR band %d, duplex mode %s, duplex spacing = %d KHz\n", current_band, duplex_mode[current_type], delta_duplex);
+
+  return current_type;
+}
+
+// Computes the duplex spacing (either positive or negative) in KHz
+int32_t get_delta_duplex(int nr_bandP, uint8_t scs_index)
+{
+  int nr_table_idx = get_nr_table_idx(nr_bandP, scs_index);
+
+  int32_t delta_duplex = (nr_bandtable[nr_table_idx].ul_min - nr_bandtable[nr_table_idx].dl_min);
+
+  LOG_I(NR_MAC, "NR band duplex spacing is %d KHz (nr_bandtable[%d].band = %d)\n", delta_duplex, nr_table_idx, nr_bandtable[nr_table_idx].band);
+
+  return delta_duplex;
+}
+
+uint16_t config_bandwidth(int mu, int nb_rb, int nr_band)
+{
+
+  if (nr_band < 100)  { //FR1
+   switch(mu) {
+    case 0 :
+      if (nb_rb<=25)
+        return 5;
+      if (nb_rb<=52)
+        return 10;
+      if (nb_rb<=79)
+        return 15;
+      if (nb_rb<=106)
+        return 20;
+      if (nb_rb<=133)
+        return 25;
+      if (nb_rb<=160)
+        return 30;
+      if (nb_rb<=216)
+        return 40;
+      if (nb_rb<=270)
+        return 50;
+      AssertFatal(1==0,"Number of DL resource blocks %d undefined for mu %d and band %d\n", nb_rb, mu, nr_band);
+      break;
+    case 1 :
+      if (nb_rb<=11)
+        return 5;
+      if (nb_rb<=24)
+        return 10;
+      if (nb_rb<=38)
+        return 15;
+      if (nb_rb<=51)
+        return 20;
+      if (nb_rb<=65)
+        return 25;
+      if (nb_rb<=78)
+        return 30;
+      if (nb_rb<=106)
+        return 40;
+      if (nb_rb<=133)
+        return 50;
+      if (nb_rb<=162)
+        return 60;
+      if (nb_rb<=189)
+        return 70;
+      if (nb_rb<=217)
+        return 80;
+      if (nb_rb<=245)
+        return 90;
+      if (nb_rb<=273)
+        return 100;
+      AssertFatal(1==0,"Number of DL resource blocks %d undefined for mu %d and band %d\n", nb_rb, mu, nr_band);
+      break;
+    case 2 :
+      if (nb_rb<=11)
+        return 10;
+      if (nb_rb<=18)
+        return 15;
+      if (nb_rb<=24)
+        return 20;
+      if (nb_rb<=31)
+        return 25;
+      if (nb_rb<=38)
+        return 30;
+      if (nb_rb<=51)
+        return 40;
+      if (nb_rb<=65)
+        return 50;
+      if (nb_rb<=79)
+        return 60;
+      if (nb_rb<=93)
+        return 70;
+      if (nb_rb<=107)
+        return 80;
+      if (nb_rb<=121)
+        return 90;
+      if (nb_rb<=135)
+        return 100;
+      AssertFatal(1==0,"Number of DL resource blocks %d undefined for mu %d and band %d\n", nb_rb, mu, nr_band);
+      break;
+    default:
+      AssertFatal(1==0,"Numerology %d undefined for band %d in FR1\n", mu,nr_band);
+   }
+  }
+  else {
+   switch(mu) {
+    case 2 :
+      if (nb_rb<=66)
+        return 50;
+      if (nb_rb<=132)
+        return 100;
+      if (nb_rb<=264)
+        return 200;
+      AssertFatal(1==0,"Number of DL resource blocks %d undefined for mu %d and band %d\n", nb_rb, mu, nr_band);
+      break;
+    case 3 :
+      if (nb_rb<=32)
+        return 50;
+      if (nb_rb<=66)
+        return 100;
+      if (nb_rb<=132)
+        return 200;
+      if (nb_rb<=264)
+        return 400;
+      AssertFatal(1==0,"Number of DL resource blocks %d undefined for mu %d and band %d\n", nb_rb, mu, nr_band);
+      break;
+    default:
+      AssertFatal(1==0,"Numerology %d undefined for band %d in FR1\n", mu,nr_band);
+   }
+  }
+}
+
+// Returns the corresponding row index of the NR table
+int get_nr_table_idx(int nr_bandP, uint8_t scs_index) {
+  int i, j;
+  int scs_khz = 15 << scs_index;
+  int supplementary_bands[] = {29,75,76,80,81,82,83,84,86,89,95};
+  size_t s = sizeof(supplementary_bands)/sizeof(supplementary_bands[0]);
+
+  for(j = 0; j < s; j++){
+    if (nr_bandP == supplementary_bands[j])
+      AssertFatal(0 == 1, "Band %d is a supplementary band (%d). This is not supported yet.\n", nr_bandP, supplementary_bands[j]);
+  }
+
+  AssertFatal(nr_bandP <= nr_bandtable[nr_bandtable_size-1].band, "NR band %d exceeds NR bands table maximum limit %d\n", nr_bandP, nr_bandtable[nr_bandtable_size-1].band);
+  for (i = 0; i < nr_bandtable_size && nr_bandtable[i].band != nr_bandP; i++);
+
+  // selection of correct Deltaf raster according to SCS
+  if ((nr_bandtable[i].deltaf_raster != 100) && (nr_bandtable[i].deltaf_raster != scs_khz))
+    i++;
+
+  LOG_D(PHY, "NR band table index %d (Band %d, dl_min %lu, ul_min %lu)\n", i, nr_bandtable[i].band, nr_bandtable[i].dl_min,nr_bandtable[i].ul_min);
+
+  return i;
+}
 
 int get_subband_size(int NPRB,int size) {
   // implements table  5.2.1.4-2 from 36.214
diff --git a/common/utils/nr/nr_common.h b/common/utils/nr/nr_common.h
index b3d2469a12d41751bc5c06f3de797bfe818cf8fc..32ce0bb975053649a559b5a99a18f664e4a2e9e7 100644
--- a/common/utils/nr/nr_common.h
+++ b/common/utils/nr/nr_common.h
@@ -35,6 +35,7 @@
 
 #include <stdint.h>
 #include "assertions.h"
+#include "PHY/defs_common.h"
 
 typedef struct nr_bandentry_s {
   int16_t band;
@@ -50,6 +51,11 @@ typedef struct nr_bandentry_s {
 extern const size_t nr_bandtable_size;
 extern nr_bandentry_t nr_bandtable[];
 
+int get_num_dmrs(uint16_t dmrs_mask);
+uint16_t config_bandwidth(int mu, int nb_rb, int nr_band);
+int get_nr_table_idx(int nr_bandP, uint8_t scs_index);
+int32_t get_delta_duplex(int nr_bandP, uint8_t scs_index);
+lte_frame_type_t get_frame_type(uint16_t nr_bandP, uint8_t scs_index);
 uint16_t get_band(uint64_t downlink_frequency, int32_t delta_duplex);
 int NRRIV2BW(int locationAndBandwidth,int N_RB);
 int NRRIV2PRBOFFSET(int locationAndBandwidth,int N_RB);
diff --git a/common/utils/telnetsrv/telnetsrv.c b/common/utils/telnetsrv/telnetsrv.c
index 734126721ad03a9141e87eb5eff10b79db202f4c..9e4eeca205c1a57da35a517b53095916b981cb6b 100644
--- a/common/utils/telnetsrv/telnetsrv.c
+++ b/common/utils/telnetsrv/telnetsrv.c
@@ -51,6 +51,7 @@
 #include <dlfcn.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <form.h>
 #include "common/utils/load_module_shlib.h"
 #include "common/config/config_userapi.h"
 #include "common/utils/threadPool/thread-pool.h"
@@ -62,34 +63,27 @@
 #include "telnetsrv_proccmd.h"
 static char *telnet_defstatmod[] = {"softmodem","phy","loader","measur"};
 static telnetsrv_params_t telnetparams;
-#define TELNETSRV_LISTENADDR 0
-#define TELNETSRV_LISTENPORT 1
-#define TELNETSRV_PRIORITY   2
-#define TELNETSRV_DEBUG      3
-#define TELNETSRV_LOOPC      4
-#define TELNETSRV_LOOPD      5
-#define TELNETSRV_HISFILE    6
-#define TELNETSRV_HISSIZE    7
-#define TELNETSRV_PHYBSIZE   8
-#define TELNETSRV_STATICMOD  9
-#define TELNETSRV_SHRMOD     10
+
+#define TELNETSRV_OPTNAME_STATICMOD   "staticmod"
+#define TELNETSRV_OPTNAME_SHRMOD      "shrmod"
 
 paramdef_t telnetoptions[] = {
-  /*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-  /*                                            configuration parameters for telnet utility                                                                             */
-  /*   optname                     helpstr                paramflags           XXXptr                               defXXXval               type                 numelt */
-  /*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-  {"listenaddr",    "<listen ip address>\n",         0,                 uptr:&telnetparams.listenaddr,        defstrval:"0.0.0.0",            TYPE_IPV4ADDR,  0 },
-  {"listenport",    "<local port>\n",                0,                 uptr:&(telnetparams.listenport),      defuintval:9090,                TYPE_UINT,      0 },
-  {"priority",      "<scheduling policy (0-99)\n",   0,                 iptr:&telnetparams.priority,          defuintval:0,                   TYPE_INT,       0 },
-  {"debug",         "<debug level>\n",               0,                 uptr:NULL,                            defuintval:0,                   TYPE_UINT,      0 },
-  {"loopcount",     "<loop command iterations>\n",   0,                 uptr:&(telnetparams.loopcount),       defuintval:10,                  TYPE_UINT,      0 },
-  {"loopdelay",     "<loop command delay (ms)>\n",   0,                 uptr:&(telnetparams.loopdelay),       defuintval:5000,                TYPE_UINT,      0 },
-  {"histfile",      "<history file name>\n",         PARAMFLAG_NOFREE,  strptr:&(telnetparams.histfile),      defstrval:"oaitelnet.history",  TYPE_STRING,    0 },
-  {"histsize",      "<history sizes>\n",             0,                 iptr:&(telnetparams.histsize),        defuintval:50,                  TYPE_INT,       0 },
-  {"phypbsize",     "<phy dump buff size (bytes)>\n",0,                 uptr:&(telnetparams.phyprntbuff_size),defuintval:65000,               TYPE_UINT,      0 },
-  {"staticmod",     "<static modules selection>\n",  0,                 strlistptr:NULL,                      defstrlistval:telnet_defstatmod,TYPE_STRINGLIST,(sizeof(telnet_defstatmod)/sizeof(char *))},
-  {"shrmod",        "<dynamic modules selection>\n", 0,                 strlistptr:NULL,                      defstrlistval:NULL,TYPE_STRINGLIST,0 }
+  /*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+  /*                                            configuration parameters for telnet utility                                                                                      */
+  /*   optname                              helpstr                paramflags           XXXptr                               defXXXval               type                 numelt */
+  /*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+  {"listenaddr",                   "<listen ip address>\n",         0,                 uptr:&telnetparams.listenaddr,        defstrval:"0.0.0.0",            TYPE_IPV4ADDR,  0 },
+  {"listenport",                   "<local port>\n",                0,                 uptr:&(telnetparams.listenport),      defuintval:9090,                TYPE_UINT,      0 },
+  {"listenstdin",                  "enable input from stdin\n",     PARAMFLAG_BOOL,    uptr:&(telnetparams.listenstdin),     defuintval:0,                   TYPE_UINT,      0 },
+  {"priority",                     "<scheduling policy (0-99)\n",   0,                 iptr:&telnetparams.priority,          defuintval:0,                   TYPE_INT,       0 },
+  {"debug",                        "<debug level>\n",               0,                 uptr:NULL,                            defuintval:0,                   TYPE_UINT,      0 },
+  {"loopcount",                    "<loop command iterations>\n",   0,                 uptr:&(telnetparams.loopcount),       defuintval:10,                  TYPE_UINT,      0 },
+  {"loopdelay",                    "<loop command delay (ms)>\n",   0,                 uptr:&(telnetparams.loopdelay),       defuintval:5000,                TYPE_UINT,      0 },
+  {"histfile",                     "<history file name>\n",         PARAMFLAG_NOFREE,  strptr:&(telnetparams.histfile),      defstrval:"oaitelnet.history",  TYPE_STRING,    0 },
+  {"histsize",                     "<history sizes>\n",             0,                 iptr:&(telnetparams.histsize),        defuintval:50,                  TYPE_INT,       0 },
+  {"phypbsize",                    "<phy dump buff size (bytes)>\n",0,                 uptr:&(telnetparams.phyprntbuff_size),defuintval:65000,               TYPE_UINT,      0 },
+  {TELNETSRV_OPTNAME_STATICMOD,    "<static modules selection>\n",  0,                 strlistptr:NULL,                      defstrlistval:telnet_defstatmod,TYPE_STRINGLIST,(sizeof(telnet_defstatmod)/sizeof(char *))},
+  {TELNETSRV_OPTNAME_SHRMOD,       "<dynamic modules selection>\n", 0,                 strlistptr:NULL,                      defstrlistval:NULL,TYPE_STRINGLIST,0 }
 };
 
 int get_phybsize(void) {
@@ -682,6 +676,77 @@ void run_telnetsrv(void) {
   return;
 }
 
+void run_telnetclt(void) {
+  int sock;
+  struct sockaddr_in name;
+  pthread_setname_np(pthread_self(), "telnetclt");
+  set_sched(pthread_self(),0,telnetparams.priority);
+  char prompt[sizeof(TELNET_PROMPT_PREFIX)+10];
+  sprintf(prompt,"%s_%s> ",TELNET_PROMPT_PREFIX,get_softmodem_function(NULL));
+  name.sin_family = AF_INET;
+  struct in_addr addr;
+  inet_aton("127.0.0.1", &addr) ;
+  name.sin_addr.s_addr = addr.s_addr;   
+  name.sin_port = htons((unsigned short)(telnetparams.listenport));
+  while (1) {
+    sock = socket(AF_INET, SOCK_STREAM, 0);
+    if (sock < 0)
+      fprintf(stderr,"[TELNETSRV] Error %s on socket call\n",strerror(errno));
+
+    if(connect(sock, (void *) &name, sizeof(name)))
+      fprintf(stderr,"[TELNETSRV] Error %s on connect call\n",strerror(errno));
+ 
+    struct timeval ts;
+    ts.tv_sec = 1; // 1 second
+    ts.tv_usec = 0;
+    while (1) {
+      fd_set fds;   
+      FD_ZERO(&fds);
+      FD_SET(sock, &fds);
+      FD_SET(STDIN_FILENO , &fds);     
+      // wait for data
+      int nready = select(sock + 1, &fds, (fd_set *) 0, (fd_set *) 0, &ts);
+      if (nready < 0) {
+          perror("select. Error");
+          break;                                                                                                                                   
+      }
+      else if (nready == 0) {
+          ts.tv_sec = 1; // 1 second
+          ts.tv_usec = 0;
+      }
+      else if ( FD_ISSET(sock, &fds)) {
+          int rv; 
+          char inbuf[TELNET_MAX_MSGLENGTH*2];
+          memset(inbuf,0,sizeof(inbuf)); 
+          rv = recv(sock , inbuf , sizeof(inbuf)-1 , 0);
+          if (rv  > 0) {
+				 printf("%s",inbuf);
+			  }
+          else if (rv == 0) {
+              printf("Connection closed by the remote end\n\r");
+              break;
+          }
+          else {
+              perror("recv error");
+              break;            
+          }
+      }       
+      else if (FD_ISSET(STDIN_FILENO , &fds)) {
+		char *inbuf=NULL;  
+      	size_t inlen=0; 
+        inlen = getline( &inbuf,&inlen, stdin);
+        if ( inlen > 0 ) {
+      	  if ( send(sock, inbuf,inlen, 0) < 0) 
+              break;
+          }
+        free(inbuf); 
+      }
+    }
+    close(sock);
+    }
+  return;
+} /* run_telnetclt */
+
 void poll_telnetcmdq(void *qid, void *arg) {
 	notifiedFIFO_elt_t *msg = pollNotifiedFIFO((notifiedFIFO_t *)qid);
 	
@@ -720,10 +785,10 @@ void exec_moduleinit(char *modname) {
 
 int add_embeddedmodules(void) {
   int ret=0;
-
-  for(int i=0; i<telnetoptions[TELNETSRV_STATICMOD].numelt; i++) {
+  int pindex = config_paramidx_fromname(telnetoptions,sizeof(telnetoptions)/sizeof(paramdef_t), TELNETSRV_OPTNAME_STATICMOD); 
+  for(int i=0; i<telnetoptions[pindex].numelt; i++) {
     ret++;
-    exec_moduleinit(telnetoptions[TELNETSRV_STATICMOD].strlistptr[i]);
+    exec_moduleinit(telnetoptions[pindex].strlistptr[i]);
   }
 
   return ret;
@@ -733,16 +798,16 @@ int add_sharedmodules(void) {
   char initfunc[TELNET_CMD_MAXSIZE+9];
   void (*fptr)(void);
   int ret=0;
-
-  for(int i=0; i<telnetoptions[TELNETSRV_SHRMOD].numelt; i++) {
-    sprintf(initfunc,"add_%s_cmds",telnetoptions[TELNETSRV_SHRMOD].strlistptr[i]);
+  int pindex = config_paramidx_fromname(telnetoptions,sizeof(telnetoptions)/sizeof(paramdef_t), TELNETSRV_OPTNAME_SHRMOD); 
+  for(int i=0; i<telnetoptions[pindex].numelt; i++) {
+    sprintf(initfunc,"add_%s_cmds",telnetoptions[pindex].strlistptr[i]);
     fptr = dlsym(RTLD_DEFAULT,initfunc);
 
     if ( fptr != NULL) {
       fptr();
       ret++;
     } else {
-      fprintf(stderr,"[TELNETSRV] couldn't find %s for module %s \n",initfunc,telnetoptions[TELNETSRV_STATICMOD].strlistptr[i]);
+      fprintf(stderr,"[TELNETSRV] couldn't find %s for module %s \n",initfunc,telnetoptions[pindex].strlistptr[i]);
     }
   }
 
@@ -767,6 +832,12 @@ int telnetsrv_autoinit(void) {
 
   add_telnetcmd("telnet", telnet_vardef, telnet_cmdarray);
   add_embeddedmodules();
+  if ( telnetparams.listenstdin ) {
+    if(pthread_create(&telnetparams.telnetclt_pthread,NULL, (void *(*)(void *))run_telnetclt, NULL) != 0) {
+      fprintf(stderr,"[TELNETSRV] Error %s on pthread_create f() run_telnetclt \n",strerror(errno));
+    return -1;
+    }
+  }  
   return 0;
 }
 
@@ -807,7 +878,7 @@ int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmdde
 
 
 /* function which will be called by the shared lib loader, to check shared lib version
-   against main exec version. version mismatch no considered as fatal (interfaces not supposed to change)
+   against main exec version. version mismatch not considered as fatal (interfaces not supposed to change)
 */
 int  telnetsrv_checkbuildver(char *mainexec_buildversion, char **shlib_buildversion) {
 #ifndef PACKAGE_VERSION
diff --git a/common/utils/telnetsrv/telnetsrv.h b/common/utils/telnetsrv/telnetsrv.h
index 59655501d3ed15f26037f18a649303e92141df1b..9c7b18fe6d37824d40646286a761d704ea5c21c7 100644
--- a/common/utils/telnetsrv/telnetsrv.h
+++ b/common/utils/telnetsrv/telnetsrv.h
@@ -108,6 +108,7 @@ typedef struct cmdparser {
 /* global variables used by the telnet server                                        */
 typedef struct {
      pthread_t telnet_pthread;       // thread id of the telnet server
+     pthread_t telnetclt_pthread;    // thread id of the telnet client (used when listenstdin set to true)
      int telnetdbg;                  // debug level of the server
      int priority;                   // server running priority
      char *histfile;                 // command history
@@ -119,6 +120,7 @@ typedef struct {
      char msgbuff[TELNET_MAX_MSGLENGTH];      // internal buffer of the client_printf function which is used to print to the client terminal */
      unsigned int   listenport;           // ip port the telnet server is listening on
      unsigned int   listenaddr;           // ip address the telnet server is listening on
+     unsigned int   listenstdin;          // enable command input from stdin    
      unsigned int   loopcount;            // loop command param: number of loop iteration
      unsigned int   loopdelay;            // loop command param: delay in ms between 2 iterations
      unsigned int   phyprntbuff_size;     // for phy module,  dump_eNB_stats function buffer size
diff --git a/common/utils/telnetsrv/telnetsrv_5Gue_measurements.c b/common/utils/telnetsrv/telnetsrv_5Gue_measurements.c
new file mode 100644
index 0000000000000000000000000000000000000000..a8925a2df9e894c45dd88ec3411b84742a50baf5
--- /dev/null
+++ b/common/utils/telnetsrv/telnetsrv_5Gue_measurements.c
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file common/utils/telnetsrv/telnetsrv_nrue_measurements.c
+ * \brief: implementation of telnet commands related to nrUE measurments
+ * \author Francois TABURET
+ * \date 2021
+ * \version 0.1
+ * \company NOKIA BellLabs France
+ * \email: francois.taburet@nokia-bell-labs.com
+ * \note
+ * \warning
+ */
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+
+
+
+#define TELNETSERVERCODE
+#include "telnetsrv.h"
+
+#include "common/utils/LOG/log.h"
+#include "common/config/config_userapi.h"
+#include "telnetsrv_measurements.h"
+#include "telnetsrv_ltemeasur_def.h"
+#include "telnetsrv_cpumeasur_def.h"
+#include "openair2/LAYER2/NR_MAC_UE/mac_defs.h"
+#include "openair1/PHY/phy_extern_nr_ue.h"
+
+void measurcmd_display_macstats(telnet_printfunc_t prnt);
+void measurcmd_display_macstats_ue(telnet_printfunc_t prnt);
+void measurcmd_display_rlcstats(telnet_printfunc_t prnt);
+void measurcmd_display_phycpu(telnet_printfunc_t prnt);
+void measurcmd_display_maccpu(telnet_printfunc_t prnt);
+void measurcmd_display_pdcpcpu(telnet_printfunc_t prnt);
+
+
+static telnet_measurgroupdef_t nrUEmeasurgroups[] = {
+//  {"ue",   GROUP_LTESTATS,0, measurcmd_display_macstats,   {NULL}},
+//  {"rlc",   GROUP_LTESTATS,0, measurcmd_display_rlcstats,   {NULL}},
+  {"phycpu",GROUP_CPUSTATS,0, measurcmd_display_phycpu,     {NULL}},
+//  {"maccpu",GROUP_CPUSTATS,0, measurcmd_display_maccpu,      {NULL}},
+//  {"pdcpcpu",GROUP_CPUSTATS,0, measurcmd_display_pdcpcpu,      {NULL}},
+};
+#define TELNET_NUM_NRUEMEASURGROUPS (sizeof(nrUEmeasurgroups)/sizeof(telnet_measurgroupdef_t))
+
+
+static double                  cpufreq;
+
+
+#define HDR "---------------------------------"
+
+
+int get_measurgroups(telnet_measurgroupdef_t **measurgroups) {
+  *measurgroups = nrUEmeasurgroups;
+  return TELNET_NUM_NRUEMEASURGROUPS;
+}
+
+
+void measurcmd_display_phycpu(telnet_printfunc_t prnt) {
+  PHY_VARS_NR_UE *UE = PHY_vars_UE_g[0][0];
+  telnet_cpumeasurdef_t  cpumeasur[]=CPU_PHYNRUE_MEASURE;
+  prnt("%s cpu (%1.1g GHz) measurements: PHY (cpustats %s) %s\n",HDR,cpufreq,
+       PRINT_CPUMEAS_STATE,HDR);
+  measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t));
+}
+/*
+void measurcmd_display_maccpu(telnet_printfunc_t prnt) {
+  eNB_MAC_INST *macvars = RC.mac[eNB_id];
+  telnet_cpumeasurdef_t  cpumeasur[]=CPU_MACENB_MEASURE;
+  prnt("%s cpu (%1.1g GHz) measurements: MAC (cpustats %s) %s\n",HDR,cpufreq,
+       PRINT_CPUMEAS_STATE,HDR);
+  measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t));
+}
+
+void measurcmd_display_pdcpcpu(telnet_printfunc_t prnt) {
+  pdcp_stats_t *pdcpvars = &(eNB_pdcp_stats[eNB_id]);
+  telnet_cpumeasurdef_t  cpumeasur[]=CPU_PDCPENB_MEASURE;
+  prnt("%s cpu (%1.1g GHz) measurements: PDCP (cpustats %s) %s \n",HDR,cpufreq,
+       PRINT_CPUMEAS_STATE,HDR);
+  measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t));
+}
+//----------------------------------------------------------------------------------------------------
+
+
+void measurcmd_display_macstats_ue(telnet_printfunc_t prnt) {
+  UE_info_t *UE_info = &(RC.mac[eNB_id]->UE_info);
+
+  for (int UE_id=UE_info->list.head; UE_id>=0; UE_id=UE_info->list.next[UE_id]) {
+    for (int i=0; i<UE_info->numactiveCCs[UE_id]; i++) {
+      int CC_id = UE_info->ordered_CCids[i][UE_id];
+      prnt("%s UE %i Id %i CCid %i %s\n",HDR,i,UE_id,CC_id,HDR);
+      eNB_UE_STATS *macuestatptr = &(UE_info->eNB_UE_stats[CC_id][UE_id]);
+      telnet_ltemeasurdef_t  statsptr[]=LTEMAC_UEMEASURE;
+      measurcmd_display_measures(prnt, statsptr, sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t));
+    }
+  }
+} // measurcmd_display_macstats_ue 
+
+void measurcmd_display_macstats(telnet_printfunc_t prnt) {
+  for (int CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) {
+    eNB_STATS *macstatptr=&(RC.mac[eNB_id]->eNB_stats[CC_id]);
+    telnet_ltemeasurdef_t  statsptr[]=LTEMAC_MEASURE;
+    prnt("%s eNB %i mac stats CC %i frame %u %s\n",
+         HDR, eNB_id, CC_id, RC.mac[eNB_id]->frame,HDR);
+    measurcmd_display_measures(prnt,statsptr,sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t));
+  }
+} // measurcmd_display_macstats 
+
+
+void measurcmd_display_one_rlcstat(telnet_printfunc_t prnt, int UE_id, telnet_ltemeasurdef_t *statsptr, int num_rlcmeasure, unsigned int *rlcstats,
+                                   char *rbid_str, protocol_ctxt_t *ctxt, const srb_flag_t srb_flagP, const rb_id_t rb_idP)
+
+{
+  int rlc_status = rlc_stat_req(ctxt,srb_flagP,rb_idP,
+                                rlcstats,   rlcstats+1, rlcstats+2, rlcstats+3, rlcstats+4, rlcstats+5,
+                                rlcstats+6, rlcstats+7, rlcstats+8, rlcstats+9, rlcstats+10, rlcstats+11,
+                                rlcstats+12, rlcstats+13, rlcstats+14, rlcstats+15, rlcstats+16, rlcstats+17,
+                                rlcstats+18, rlcstats+19, rlcstats+20, rlcstats+21, rlcstats+22, rlcstats+23,
+                                rlcstats+24, rlcstats+25, rlcstats+26, rlcstats+27);
+
+  if (rlc_status == RLC_OP_STATUS_OK) {
+    prnt("%s UE %i RLC %s mode %s %s\n",HDR,UE_id, rbid_str,
+         (rlcstats[0]==RLC_MODE_AM)? "AM": (rlcstats[0]==RLC_MODE_UM)?"UM":"NONE",HDR);
+    measurcmd_display_measures(prnt, statsptr, num_rlcmeasure);
+  }
+} // status measurcmd_rlc_stat_req 
+
+
+void measurcmd_display_rlcstats(telnet_printfunc_t prnt) {
+  protocol_ctxt_t      ctxt;
+  UE_info_t *UE_info = &(RC.mac[eNB_id]->UE_info);
+  telnet_ltemeasurdef_t  statsptr[]=LTE_RLCMEASURE;
+  int num_rlcmeasure = sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t );
+  unsigned int *rlcstats = malloc(num_rlcmeasure*sizeof(unsigned int));
+  eNB_MAC_INST *eNB = RC.mac[eNB_id];
+
+  for(int i=0; i <num_rlcmeasure ; i++) {
+    statsptr[i].vptr = rlcstats + i;
+  }
+
+  for (int UE_id=UE_info->list.head; UE_id>=0; UE_id=UE_info->list.next[UE_id]) {
+#define NB_eNB_INST 1
+    PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt,eNB_id, ENB_FLAG_YES,UE_info->eNB_UE_stats[0][UE_id].crnti,
+                                   eNB->frame,eNB->subframe,eNB_id);
+    measurcmd_display_one_rlcstat(prnt, UE_id, statsptr, num_rlcmeasure, rlcstats, "DCCH", &ctxt, SRB_FLAG_YES, DCCH);
+    measurcmd_display_one_rlcstat(prnt, UE_id, statsptr, num_rlcmeasure, rlcstats, "DTCH", &ctxt, SRB_FLAG_NO,  DTCH-2);
+  }
+} // measurcmd_display_macstats_ue 
+
+*/
+
+
diff --git a/common/utils/telnetsrv/telnetsrv_CMakeLists.txt b/common/utils/telnetsrv/telnetsrv_CMakeLists.txt
index 519a1a72ffc02c22af9f4c58ae1e78a975d4931a..2713c71cc074e7761e195a6106707beb52b96069 100644
--- a/common/utils/telnetsrv/telnetsrv_CMakeLists.txt
+++ b/common/utils/telnetsrv/telnetsrv_CMakeLists.txt
@@ -8,9 +8,9 @@ set(TELNETSRV_SOURCE
     )
     
 add_library(telnetsrv MODULE ${TELNETSRV_SOURCE} )
-target_link_libraries(telnetsrv PRIVATE history)
+target_link_libraries(telnetsrv PRIVATE history ncurses form )
 
-foreach(TELNETLIB enb gnb 4gUE 5gUE)
+foreach(TELNETLIB enb gnb 4Gue 5Gue)
     set(TELNETLIB_SRCS "")
     foreach(TELNETLIB_ASRC measurements phycmd)
        set(TELNETLIB_SRC ${OPENAIR_DIR}/common/utils/telnetsrv/telnetsrv_${TELNETLIB}_${TELNETLIB_ASRC}.c)
@@ -32,4 +32,4 @@ install(TARGETS telnetsrv DESTINATION bin)
 
 if (EXISTS "${OPENAIR_BUILD_DIR}/ran_build/build" AND IS_DIRECTORY "${OPENAIR_BUILD_DIR}/ran_build/build")
      install(TARGETS telnetsrv DESTINATION ${OPENAIR_BUILD_DIR}/ran_build/build)
-endif (EXISTS "${OPENAIR_BUILD_DIR}/ran_build/build" AND IS_DIRECTORY "${OPENAIR_BUILD_DIR}/ran_build/build")
\ No newline at end of file
+endif (EXISTS "${OPENAIR_BUILD_DIR}/ran_build/build" AND IS_DIRECTORY "${OPENAIR_BUILD_DIR}/ran_build/build")
diff --git a/common/utils/telnetsrv/telnetsrv_cpumeasur_def.h b/common/utils/telnetsrv/telnetsrv_cpumeasur_def.h
index 7a45b351f3231b24591cf15ac9e6a70df6441e54..a275272e809ebd26eabfb98d9caf6a24a78dcde2 100644
--- a/common/utils/telnetsrv/telnetsrv_cpumeasur_def.h
+++ b/common/utils/telnetsrv/telnetsrv_cpumeasur_def.h
@@ -24,8 +24,8 @@
  * \        strucures arrays which are then used by the display functions
  * \        in telnetsrv_measurements.c.
  * \author Francois TABURET
- * \date 2019
- * \version 0.1
+ * \date 2021
+ * \version 0.2
  * \company NOKIA BellLabs France
  * \email: francois.taburet@nokia-bell-labs.com
  * \note
@@ -37,67 +37,119 @@
 
 #define CPU_PHYENB_MEASURE \
 { \
-  {"phy_proc_tx",            	  	 &(phyvars->phy_proc_tx),0},\
-  {"phy_proc_rx",            	  	 &(phyvars->phy_proc_rx),0},\
-  {"rx_prach",               	  	 &(phyvars->rx_prach),0},\
-  {"ofdm_mod",         	  	         &(phyvars->ofdm_mod_stats),0},\
-  {"dlsch_common_and_dci",   	  	 &(phyvars->dlsch_common_and_dci),0},\
-  {"dlsch_ue_specific",      	  	 &(phyvars->dlsch_ue_specific),0},\
-  {"dlsch_encoding",   	  	         &(phyvars->dlsch_encoding_stats),0},\
-  {"dlsch_modulation", 	  	         &(phyvars->dlsch_modulation_stats),0},\
-  {"dlsch_scrambling",                   &(phyvars->dlsch_scrambling_stats),0},\
-  {"dlsch_rate_matching",                &(phyvars->dlsch_rate_matching_stats),0},\
-  {"dlsch_turbo_encod_prep",             &(phyvars->dlsch_turbo_encoding_preperation_stats),0},\
-  {"dlsch_turbo_encod_segm",             &(phyvars->dlsch_turbo_encoding_segmentation_stats),0},\
-  {"dlsch_turbo_encod", 	         &(phyvars->dlsch_turbo_encoding_stats),0},\
-  {"dlsch_turbo_encod_waiting",          &(phyvars->dlsch_turbo_encoding_waiting_stats),0},\
-  {"dlsch_turbo_encod_signal",           &(phyvars->dlsch_turbo_encoding_signal_stats),0},\
-  {"dlsch_turbo_encod_main",	         &(phyvars->dlsch_turbo_encoding_main_stats),0},\
-  {"dlsch_turbo_encod_wakeup0",          &(phyvars->dlsch_turbo_encoding_wakeup_stats0),0},\
-  {"dlsch_turbo_encod_wakeup1",          &(phyvars->dlsch_turbo_encoding_wakeup_stats1),0},\
-  {"dlsch_interleaving",                 &(phyvars->dlsch_interleaving_stats),0},\
-  {"rx_dft",                             &(phyvars->rx_dft_stats),0},\
-  {"ulsch_channel_estimation",           &(phyvars->ulsch_channel_estimation_stats),0},\
-  {"ulsch_freq_offset_estimation",       &(phyvars->ulsch_freq_offset_estimation_stats),0},\
-  {"ulsch_decoding",                     &(phyvars->ulsch_decoding_stats),0},\
-  {"ulsch_demodulation",                 &(phyvars->ulsch_demodulation_stats),0},\
-  {"ulsch_rate_unmatching",              &(phyvars->ulsch_rate_unmatching_stats),0},\
-  {"ulsch_turbo_decoding",               &(phyvars->ulsch_turbo_decoding_stats),0},\
-  {"ulsch_deinterleaving",               &(phyvars->ulsch_deinterleaving_stats),0},\
-  {"ulsch_demultiplexing",               &(phyvars->ulsch_demultiplexing_stats),0},\
-  {"ulsch_llr",                          &(phyvars->ulsch_llr_stats),0},\
-  {"ulsch_tc_init",                      &(phyvars->ulsch_tc_init_stats),0},\
-  {"ulsch_tc_alpha",                     &(phyvars->ulsch_tc_alpha_stats),0},\
-  {"ulsch_tc_beta",                      &(phyvars->ulsch_tc_beta_stats),0},\
-  {"ulsch_tc_gamma",                     &(phyvars->ulsch_tc_gamma_stats),0},\
-  {"ulsch_tc_ext",                       &(phyvars->ulsch_tc_ext_stats),0},\
-  {"ulsch_tc_intl1",                     &(phyvars->ulsch_tc_intl1_stats),0},\
-  {"ulsch_tc_intl2",                     &(phyvars->ulsch_tc_intl2_stats),0},\
+  {"phy_proc_tx",            	  	 &(phyvars->phy_proc_tx),0,1},\
+  {"phy_proc_rx",            	  	 &(phyvars->phy_proc_rx),0,1},\
+  {"rx_prach",               	  	 &(phyvars->rx_prach),0,1},\
+  {"ofdm_mod",         	  	         &(phyvars->ofdm_mod_stats),0,1},\
+  {"dlsch_common_and_dci",   	  	 &(phyvars->dlsch_common_and_dci),0,1},\
+  {"dlsch_ue_specific",      	  	 &(phyvars->dlsch_ue_specific),0,1},\
+  {"dlsch_encoding",   	  	         &(phyvars->dlsch_encoding_stats),0,1},\
+  {"dlsch_modulation", 	  	         &(phyvars->dlsch_modulation_stats),0,1},\
+  {"dlsch_scrambling",                   &(phyvars->dlsch_scrambling_stats),0,1},\
+  {"dlsch_rate_matching",                &(phyvars->dlsch_rate_matching_stats),0,1},\
+  {"dlsch_turbo_encod_prep",             &(phyvars->dlsch_turbo_encoding_preperation_stats),0,1},\
+  {"dlsch_turbo_encod_segm",             &(phyvars->dlsch_turbo_encoding_segmentation_stats),0,1},\
+  {"dlsch_turbo_encod", 	         &(phyvars->dlsch_turbo_encoding_stats),0,1},\
+  {"dlsch_turbo_encod_waiting",          &(phyvars->dlsch_turbo_encoding_waiting_stats),0,1},\
+  {"dlsch_turbo_encod_signal",           &(phyvars->dlsch_turbo_encoding_signal_stats),0,1},\
+  {"dlsch_turbo_encod_main",	         &(phyvars->dlsch_turbo_encoding_main_stats),0,1},\
+  {"dlsch_turbo_encod_wakeup0",          &(phyvars->dlsch_turbo_encoding_wakeup_stats0),0,1},\
+  {"dlsch_turbo_encod_wakeup1",          &(phyvars->dlsch_turbo_encoding_wakeup_stats1),0,1},\
+  {"dlsch_interleaving",                 &(phyvars->dlsch_interleaving_stats),0,1},\
+  {"rx_dft",                             &(phyvars->rx_dft_stats),0,1},\
+  {"ulsch_channel_estimation",           &(phyvars->ulsch_channel_estimation_stats),0,1},\
+  {"ulsch_freq_offset_estimation",       &(phyvars->ulsch_freq_offset_estimation_stats),0,1},\
+  {"ulsch_decoding",                     &(phyvars->ulsch_decoding_stats),0,1},\
+  {"ulsch_demodulation",                 &(phyvars->ulsch_demodulation_stats),0,1},\
+  {"ulsch_rate_unmatching",              &(phyvars->ulsch_rate_unmatching_stats),0,1},\
+  {"ulsch_turbo_decoding",               &(phyvars->ulsch_turbo_decoding_stats),0,1},\
+  {"ulsch_deinterleaving",               &(phyvars->ulsch_deinterleaving_stats),0,1},\
+  {"ulsch_demultiplexing",               &(phyvars->ulsch_demultiplexing_stats),0,1},\
+  {"ulsch_llr",                          &(phyvars->ulsch_llr_stats),0,1},\
+  {"ulsch_tc_init",                      &(phyvars->ulsch_tc_init_stats),0,1},\
+  {"ulsch_tc_alpha",                     &(phyvars->ulsch_tc_alpha_stats),0,1},\
+  {"ulsch_tc_beta",                      &(phyvars->ulsch_tc_beta_stats),0,1},\
+  {"ulsch_tc_gamma",                     &(phyvars->ulsch_tc_gamma_stats),0,1},\
+  {"ulsch_tc_ext",                       &(phyvars->ulsch_tc_ext_stats),0,1},\
+  {"ulsch_tc_intl1",                     &(phyvars->ulsch_tc_intl1_stats),0,1},\
+  {"ulsch_tc_intl2",                     &(phyvars->ulsch_tc_intl2_stats),0,1},\
 }
 
 #define CPU_MACENB_MEASURE \
 { \
-  {"eNB_scheduler",	    &(macvars->eNB_scheduler),0},\
-  {"schedule_si",	    &(macvars->schedule_si),0},\
-  {"schedule_ra",	    &(macvars->schedule_ra),0},\
-  {"schedule_ulsch",	    &(macvars->schedule_ulsch),0},\
-  {"fill_DLSCH_dci",	    &(macvars->fill_DLSCH_dci),0},\
-  {"schedule_dlsch_pre",    &(macvars->schedule_dlsch_preprocessor),0},\
-  {"schedule_dlsch",	    &(macvars->schedule_dlsch),0},\
-  {"schedule_mch",	    &(macvars->schedule_mch),0},\
-  {"rx_ulsch_sdu",	    &(macvars->rx_ulsch_sdu),0},\
-  {"schedule_pch",	    &(macvars->schedule_pch),0},\
+  {"eNB_scheduler",	    &(macvars->eNB_scheduler),0,1},\
+  {"schedule_si",	    &(macvars->schedule_si),0,1},\
+  {"schedule_ra",	    &(macvars->schedule_ra),0,1},\
+  {"schedule_ulsch",	    &(macvars->schedule_ulsch),0,1},\
+  {"fill_DLSCH_dci",	    &(macvars->fill_DLSCH_dci),0,1},\
+  {"schedule_dlsch_pre",    &(macvars->schedule_dlsch_preprocessor),0,1},\
+  {"schedule_dlsch",	    &(macvars->schedule_dlsch),0,1},\
+  {"schedule_mch",	    &(macvars->schedule_mch),0,1},\
+  {"rx_ulsch_sdu",	    &(macvars->rx_ulsch_sdu),0,1},\
+  {"schedule_pch",	    &(macvars->schedule_pch),0,1},\
 }
 
 #define CPU_PDCPENB_MEASURE \
 { \
-  {"pdcp_run",               &(pdcpvars->pdcp_run),0},\
-  {"data_req",               &(pdcpvars->data_req),0},\
-  {"data_ind",               &(pdcpvars->data_ind),0},\
-  {"apply_security",         &(pdcpvars->apply_security),0},\
-  {"validate_security",      &(pdcpvars->validate_security),0},\
-  {"pdcp_ip",                &(pdcpvars->pdcp_ip),0},\
-  {"ip_pdcp",                &(pdcpvars->ip_pdcp),0},\
+  {"pdcp_run",               &(pdcpvars->pdcp_run),0,1},\
+  {"data_req",               &(pdcpvars->data_req),0,1},\
+  {"data_ind",               &(pdcpvars->data_ind),0,1},\
+  {"apply_security",         &(pdcpvars->apply_security),0,1},\
+  {"validate_security",      &(pdcpvars->validate_security),0,1},\
+  {"pdcp_ip",                &(pdcpvars->pdcp_ip),0,1},\
+  {"ip_pdcp",                &(pdcpvars->ip_pdcp),0,1},\
 }
 
+/* from openair1/PHY/defs_nr_UE.h */
+#define CPU_PHYNRUE_MEASURE \
+{ \
+    {"phy_proc",          &(UE->phy_proc[0]),0,RX_NB_TH},\
+    {"phy_proc_rx",       &(UE-> phy_proc_rx[0]),0,RX_NB_TH},\
+    {"phy_proc_tx",       &(UE->phy_proc_tx),0,1},\
+    {"ofdm_mod_stats",       &(UE->ofdm_mod_stats),0,1},\
+    {"ulsch_encoding_stats",       &(UE->ulsch_encoding_stats),0,1},\
+    {"ulsch_modulation_stats",       &(UE->ulsch_modulation_stats),0,1},\
+    {"ulsch_segmentation_stats",       &(UE->ulsch_segmentation_stats),0,1},\
+    {"ulsch_rate_matching_stats",       &(UE->ulsch_rate_matching_stats),0,1},\
+    {"ulsch_turbo_encoding_stats",       &(UE->ulsch_turbo_encoding_stats),0,1},\
+    {"ulsch_interleaving_stats",       &(UE->ulsch_interleaving_stats),0,1},\
+    {"ulsch_multiplexing_stats",       &(UE->ulsch_multiplexing_stats),0,1},\
+    {"generic_stat",       &(UE->generic_stat),0,1},\
+    {"generic_stat_bis",       &(UE->generic_stat_bis[0][0]),0,RX_NB_TH,LTE_SLOTS_PER_SUBFRAME},\
+    {"ofdm_demod_stats",       &(UE->ofdm_demod_stats),0,1},\
+    {"dlsch_rx_pdcch_stats",       &(UE->dlsch_rx_pdcch_stats),0,1},\
+    {"rx_dft_stats",       &(UE->rx_dft_stats),0,1},\
+    {"dlsch_c...timation_stats",       &(UE->dlsch_channel_estimation_stats),0,1},\
+    {"dlsch_f...timation_stats",       &(UE->dlsch_freq_offset_estimation_stats),0,1},\
+    {"dlsch_demodulation_stats",       &(UE->dlsch_demodulation_stats),0,1},\
+    {"dlsch_rate_unmatching_stats",       &(UE->dlsch_rate_unmatching_stats),0,1},\
+    {"dlsch_turbo_decoding_stats",       &(UE->dlsch_turbo_decoding_stats),0,1},\
+    {"dlsch_deinterleaving_stats",       &(UE->dlsch_deinterleaving_stats),0,1},\
+    {"dlsch_llr_stats",       &(UE->dlsch_llr_stats),0,1},\
+    {"dlsch_unscrambling_stats",       &(UE->dlsch_unscrambling_stats),0,1},\
+    {"dlsch_rate_matching_stats",       &(UE->dlsch_rate_matching_stats),0,1},\
+    {"dlsch_turbo_encoding_stats",       &(UE->dlsch_turbo_encoding_stats),0,1},\
+    {"dlsch_interleaving_stats",       &(UE->dlsch_interleaving_stats),0,1},\
+    {"dlsch_tc_init_stats",       &(UE->dlsch_tc_init_stats),0,1},\
+    {"dlsch_tc_alpha_stats",       &(UE->dlsch_tc_alpha_stats),0,1},\
+    {"dlsch_tc_beta_stats",       &(UE->dlsch_tc_beta_stats),0,1},\
+    {"dlsch_tc_gamma_stats",       &(UE->dlsch_tc_gamma_stats),0,1},\
+    {"dlsch_tc_ext_stats",       &(UE->dlsch_tc_ext_stats),0,1},\
+    {"dlsch_tc_intl1_stats",       &(UE->dlsch_tc_intl1_stats),0,1},\
+    {"dlsch_tc_intl2_stats",       &(UE->dlsch_tc_intl2_stats),0,1},\
+    {"tx_prach",       &(UE->tx_prach),0,1},\
+    {"dlsch_encoding_SIC_stats",       &(UE->dlsch_encoding_SIC_stats),0,1},\
+    {"dlsch_scrambling_SIC_stats",       &(UE->dlsch_scrambling_SIC_stats),0,1},\
+    {"dlsch_modulation_SIC_stats",       &(UE->dlsch_modulation_SIC_stats),0,1},\
+    {"dlsch...ping_unit_SIC_stats",       &(UE->dlsch_llr_stripping_unit_SIC_stats),0,1},\
+    {"dlsch_unscrambling_SIC_stats",       &(UE->dlsch_unscrambling_SIC_stats),0,1},\
+    {"ue_front_end_stat",       &(UE->ue_front_end_stat[0]),0,RX_NB_TH},\
+    {"ue_front_end_per_slot_stat",      &(UE->ue_front_end_per_slot_stat[0][0]),0,RX_NB_TH,LTE_SLOTS_PER_SUBFRAME},\
+    {"pdcch_procedures_stat",       &(UE->pdcch_procedures_stat[0]),0,RX_NB_TH},\
+    {"pdsch_procedures_stat",       &(UE->pdsch_procedures_stat[0]),0,RX_NB_TH},\
+    {"pdsch_procedures_per_slot_stat",  &(UE->pdsch_procedures_per_slot_stat[0][0]),0,RX_NB_TH,LTE_SLOTS_PER_SUBFRAME},\
+    {"dlsch_procedures_stat",       &(UE->dlsch_procedures_stat[0]),0,RX_NB_TH},\
+    {"dlsch_decoding_stats",       &(UE->dlsch_decoding_stats[0]),0,RX_NB_TH},\
+    {"dlsch_llr_stats_para", &(UE->dlsch_llr_stats_parallelization[0][0]),0,RX_NB_TH,LTE_SLOTS_PER_SUBFRAME},\
+}
 #endif
diff --git a/common/utils/telnetsrv/telnetsrv_measurements.c b/common/utils/telnetsrv/telnetsrv_measurements.c
index 4a11e7c2dd59f4d073d4e6a8712ab78679277642..786cbd094cc432619906b38fde0b7a70ff3917ef 100644
--- a/common/utils/telnetsrv/telnetsrv_measurements.c
+++ b/common/utils/telnetsrv/telnetsrv_measurements.c
@@ -64,13 +64,30 @@ void measurcmd_display_groups(telnet_printfunc_t prnt,telnet_measurgroupdef_t *m
 } /* measurcmd_display_groups */
 /*----------------------------------------------------------------------------------------------------*/
 /* cpu measurements functions                         */
-void measurcmd_display_cpumeasures(telnet_printfunc_t prnt, telnet_cpumeasurdef_t  *cpumeasure, int cpumeasure_size) {
-  for (int i=0; i<cpumeasure_size; i++) {
-    prnt("%02d %*s:  %15.3f us; %15d %s",i,TELNET_MAXMEASURNAME_LEN-1,(cpumeasure+i)->statname,
-         ((cpumeasure+i)->astatptr->trials!=0)?(((cpumeasure+i)->astatptr->diff)/((cpumeasure+i)->astatptr->trials))/cpufreq/1000:0,
-         (cpumeasure+i)->astatptr->trials, ((i%2)==1)?"|\n":"  | " );
-  }
 
+
+static char *stridx(int max,int i, char *buff) {
+    if (max>1)
+        sprintf(buff,"[%d]",i);
+    else
+        sprintf(buff,"   ");
+    return buff;
+
+}
+void measurcmd_display_cpumeasures(telnet_printfunc_t prnt, telnet_cpumeasurdef_t  *cpumeasure, int cpumeasure_size) {
+  int p=0;
+  char stridx1[16];
+  char stridx2[16];
+  for (int i=0; i<cpumeasure_size; i++)
+    for (int o1=0;o1<cpumeasure[i].num_occur1;o1++)
+      for (int o2=0;o2<=cpumeasure[i].num_occur2;o2++)
+      {
+      prnt("%02d %*s%s%s:  %15.3f us; %15d %s",p,TELNET_MAXMEASURNAME_LEN+7,(cpumeasure+i)->statname,
+            stridx(cpumeasure[i].num_occur1,o1,stridx1),stridx(cpumeasure[i].num_occur2,o2,stridx2),
+           ((cpumeasure+i+o1+o2)->astatptr->trials!=0)?(((cpumeasure+i+o1+o2)->astatptr->diff)/((cpumeasure+i+o1+o2)->astatptr->trials))/cpufreq/1000:0,
+           (cpumeasure+i+o1+o2)->astatptr->trials, ((p%2)==1)?"|\n":"  | " );
+      p++;
+      }
   prnt("\n\n");
 } /* measurcmd_display_measures */
 
@@ -137,11 +154,17 @@ int measurcmd_show(char *buf, int debug, telnet_printfunc_t prnt) {
   }
   telnet_measurgroupdef_t *measurgroups;
   int num_measurgroups = fptr( &measurgroups);
- 
+
   int s = sscanf(buf,"%ms %i-%i\n",&subcmd, &idx1,&idx2);
 
   if (s>0) {
-    if ( strcmp(subcmd,"groups") == 0) {
+    if ( strcmp(subcmd,"inq") == 0) {
+                notifiedFIFO_elt_t *msg =newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
+                time_stats_msg_t *msgdata=NotifiedFifoData(msg);
+                msgdata->msgid = TIMESTAT_MSGID_DISPLAY;
+                msgdata->displayFunc = prnt;
+                pushNotifiedFIFO(&measur_fifo, msg);
+    } else if ( strcmp(subcmd,"groups") == 0){
       measurcmd_display_groups(prnt,measurgroups,num_measurgroups);
       badcmd=0;
     } else {
@@ -182,13 +205,13 @@ int measurcmd_cpustats(char *buf, int debug, telnet_printfunc_t prnt) {
   int badcmd=1;
 
   if (debug > 0)
-    prnt(" measurcmd_show received %s\n",buf);
+    prnt(" measurcmd_cpustats received %s\n",buf);
 
   int s = sscanf(buf,"%ms %i-%i\n",&subcmd, &idx1,&idx2);
 
   if (s>0) {
     if ( strcmp(subcmd,"enable") == 0) {
-      cpumeas(CPUMEAS_ENABLE);
+      
       badcmd=0;
     } else if ( strcmp(subcmd,"disable") == 0) {
       cpumeas(CPUMEAS_DISABLE);
@@ -203,6 +226,64 @@ int measurcmd_cpustats(char *buf, int debug, telnet_printfunc_t prnt) {
   free(subcmd);
   return CMDSTATUS_FOUND;
 }
+
+void measurcmd_async_help(telnet_printfunc_t prnt) {
+}
+
+int measurcmd_async(char *buf, int debug, telnet_printfunc_t prnt) {
+  char *subcmd=NULL;
+  int idx1, idx2;
+  int okcmd=0;
+
+  if (buf == NULL) {
+	  measurcmd_async_help(prnt);
+	  return CMDSTATUS_FOUND;
+  }
+  if (debug > 0)
+    prnt(" measurcmd_async received %s\n",buf);
+  
+
+  int s = sscanf(buf,"%ms %i-%i\n",&subcmd, &idx1,&idx2);
+
+  if (s==1) {
+    if ( strcmp(subcmd,"enable") == 0) {
+      init_meas();
+      okcmd=1;
+    } else if ( strcmp(subcmd,"disable") == 0) {
+      end_meas();
+      okcmd=1;
+    }
+  } else if ( s == 3 ) {
+	int msgid;
+    if ( strcmp(subcmd,"enable") == 0) {
+      msgid = TIMESTAT_MSGID_ENABLE;
+      okcmd=1;
+    } else if ( strcmp(subcmd,"disable") == 0) {
+      msgid = TIMESTAT_MSGID_DISABLE;
+      okcmd=1;
+    } else if ( strcmp(subcmd,"display") == 0) {
+      msgid = TIMESTAT_MSGID_DISPLAY;
+      okcmd=1;
+    }
+    if (okcmd) {
+      notifiedFIFO_elt_t *nfe = newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
+	  time_stats_msg_t *msg = (time_stats_msg_t *)NotifiedFifoData(nfe);
+      msg->msgid = msgid ;
+      msg->displayFunc = prnt;
+	  for(int i=idx1; i<idx2; i++) {
+		msg->timestat_id =i;
+        pushNotifiedFIFO(&measur_fifo, nfe);
+	  }
+    }	  
+  }
+
+  if (!(okcmd)) {
+    prnt("Unknown command: %s\n",buf);
+  }
+
+  free(subcmd);
+  return CMDSTATUS_FOUND;
+}
 /*-------------------------------------------------------------------------------------*/
 
 /* function called at telnet server init to add the measur command */
diff --git a/common/utils/telnetsrv/telnetsrv_measurements.h b/common/utils/telnetsrv/telnetsrv_measurements.h
index 08136df0fda6d3325b8afd59f7f628c6086670cf..99ae695f41da3f0b1ff0adeecd26091ac11ab4cf 100644
--- a/common/utils/telnetsrv/telnetsrv_measurements.h
+++ b/common/utils/telnetsrv/telnetsrv_measurements.h
@@ -49,6 +49,9 @@ typedef struct cpumeasurdef {
   char statname[TELNET_MAXMEASURNAME_LEN];
   time_stats_t *astatptr;
   unsigned int statemask;
+  uint8_t  num_occur1;
+  uint8_t  num_occur2;
+  uint8_t  num_occur3;
 } telnet_cpumeasurdef_t;
 
 typedef struct ltemeasurdef {
@@ -60,6 +63,7 @@ typedef struct ltemeasurdef {
 
 #define GROUP_LTESTATS    0
 #define GROUP_CPUSTATS    1
+
 typedef void(*measur_dislayfunc_t)(telnet_printfunc_t prnt);
 typedef struct mesurgroupdef {
   char groupname[TELNET_MAXMEASURNAME_LEN];
@@ -79,9 +83,11 @@ typedef struct mesurgroupdef {
 #ifdef TELNETSRV_MEASURMENTS_MAIN
 int measurcmd_show(char *buf, int debug, telnet_printfunc_t prnt);
 int measurcmd_cpustats(char *buf, int debug, telnet_printfunc_t prnt);
+int measurcmd_async(char *buf, int debug, telnet_printfunc_t prnt);
 telnetshell_cmddef_t measur_cmdarray[] = {
-  {"show", "groups | <group name>" , measurcmd_show},
+  {"show", "groups | <group name> | inq" , measurcmd_show},
   {"cpustats","[enable | disable]",measurcmd_cpustats},
+  {"async","[enable | disable]",measurcmd_async},
   {"","",NULL}
 };
 
diff --git a/executables/nr-ru.c b/executables/nr-ru.c
index e3c6a3d9648d0f5760ec836f2c8ade9903b65217..336b7bec120634bb716149e5289b785f27106c11 100644
--- a/executables/nr-ru.c
+++ b/executables/nr-ru.c
@@ -33,6 +33,7 @@
 
 #include "common/utils/assertions.h"
 #include "common/utils/system.h"
+#include "common/ran_context.h"
 
 #include "../../ARCH/COMMON/common_lib.h"
 #include "../../ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.h"
@@ -47,8 +48,6 @@
 #include "PHY/INIT/phy_init.h"
 #include "SCHED_NR/sched_nr.h"
 
-#include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h"
-
 #include "common/utils/LOG/log.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 
diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index c0236f521feb5f99a0bbe5c5de085ba11b0dd37e..cf0cd238175b2192a9fa82af68248584adafc107 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -21,6 +21,7 @@
 
 #include "executables/nr-softmodem-common.h"
 #include "common/utils/nr/nr_common.h"
+#include "common/ran_context.h"
 #include "PHY/defs_gNB.h"
 #include "PHY/phy_extern.h"
 #include "PHY/NR_REFSIG/nr_refsig.h"
@@ -35,7 +36,6 @@
 #include "MBSFN-SubframeConfigList.h"*/
 #include "openair1/PHY/defs_RU.h"
 #include "openair1/PHY/CODING/nrLDPC_extern.h"
-#include "LAYER2/NR_MAC_gNB/mac_proto.h"
 #include "assertions.h"
 #include <math.h>
 
diff --git a/openair1/PHY/INIT/nr_parms.c b/openair1/PHY/INIT/nr_parms.c
index f8c63c9deb284446015f07b68853c48d57767cb6..0920da667d3d99d67949c58490e2bed19724e8e1 100644
--- a/openair1/PHY/INIT/nr_parms.c
+++ b/openair1/PHY/INIT/nr_parms.c
@@ -22,7 +22,6 @@
 #include "phy_init.h"
 #include "common/utils/nr/nr_common.h"
 #include "common/utils/LOG/log.h"
-#include "LAYER2/NR_MAC_gNB/mac_proto.h"
 
 /// Subcarrier spacings in Hz indexed by numerology index
 uint32_t nr_subcarrier_spacing[MAX_NUM_SUBCARRIER_SPACING] = {15e3, 30e3, 60e3, 120e3, 240e3};
diff --git a/openair1/PHY/MODULATION/slot_fep_nr.c b/openair1/PHY/MODULATION/slot_fep_nr.c
index 577a06ce5a40e608ff913b356f1f2761b8e72f90..eb26dfc02bfb6e3b6a222521ec70d3f64ec6e487 100644
--- a/openair1/PHY/MODULATION/slot_fep_nr.c
+++ b/openair1/PHY/MODULATION/slot_fep_nr.c
@@ -129,18 +129,14 @@ int nr_slot_fep(PHY_VARS_NR_UE *ue,
       rxdata_ptr = (int16_t *)tmp_dft_in;
     }
 
-#if UE_TIMING_TRACE
     start_meas(&ue->rx_dft_stats);
-#endif
 
     dft(dftsize,
         rxdata_ptr,
         (int16_t *)&common_vars->common_vars_rx_data_per_thread[proc->thread_id].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],
         1);
 
-#if UE_TIMING_TRACE
     stop_meas(&ue->rx_dft_stats);
-#endif
 
     int symb_offset = (Ns%frame_parms->slots_per_subframe)*frame_parms->symbols_per_slot;
     int32_t rot2 = ((uint32_t*)frame_parms->symbol_rotation[0])[symbol+symb_offset];
@@ -249,18 +245,14 @@ int nr_slot_fep_init_sync(PHY_VARS_NR_UE *ue,
 
     }
 
-#if UE_TIMING_TRACE
     start_meas(&ue->rx_dft_stats);
-#endif
 
     dft(dftsize,
         rxdata_ptr,
         (int16_t *)&common_vars->common_vars_rx_data_per_thread[proc->thread_id].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],
         1);
 
-#if UE_TIMING_TRACE
     stop_meas(&ue->rx_dft_stats);
-#endif
 
     int symb_offset = (Ns%frame_parms->slots_per_subframe)*frame_parms->symbols_per_slot;
     int32_t rot2 = ((uint32_t*)frame_parms->symbol_rotation[0])[symbol + symb_offset];
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c
index ecc2cded11c530c980d693ce80be7e003cf0a696..d75f97aa537dadc7736ed3387aea211f1d259dca 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch.c
@@ -37,7 +37,7 @@
 #include "PHY/NR_REFSIG/dmrs_nr.h"
 #include "PHY/NR_REFSIG/ptrs_nr.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
-#include "LAYER2/NR_MAC_gNB/mac_proto.h"
+#include "common/utils/nr/nr_common.h"
 
 //#define DEBUG_DLSCH
 //#define DEBUG_DLSCH_MAPPING
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
index 9956e147016559bb79e53bd9b354a3d241065e97..acb59b0e4027fdae7c64b530392ad1334dfb064a 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
@@ -39,10 +39,10 @@
 #include "PHY/NR_TRANSPORT/nr_transport_proto.h"
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 #include "PHY/NR_TRANSPORT/nr_dlsch.h"
-#include "openair2/LAYER2/NR_MAC_gNB/mac_proto.h"
 #include "SCHED_NR/sched_nr.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "common/utils/LOG/log.h"
+#include "common/utils/nr/nr_common.h"
 #include <syscall.h>
 #include <openair2/UTIL/OPT/opt.h>
 
diff --git a/openair1/PHY/NR_TRANSPORT/nr_prach_common.c b/openair1/PHY/NR_TRANSPORT/nr_prach_common.c
index a95c519d439290449bd82792465632cbf63c0df8..84118e82675bc3dedbff992f07384aec685bb5da 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_prach_common.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_prach_common.c
@@ -37,7 +37,6 @@
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 #include "common/utils/LOG/log.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
-#include "openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h"
 #include "T.h"
 
 
diff --git a/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h b/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
index 1aef49918989e2533851d1cce7f9dd8f6ff6b3e4..4fed3a468febf4ce41809d33765d3c17f8abb8a3 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
+++ b/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
@@ -35,7 +35,6 @@
 
 #include "PHY/defs_nr_common.h"
 #include "PHY/defs_gNB.h"
-#include "LAYER2/NR_MAC_gNB/mac_proto.h"
 
 #define NR_PBCH_PDU_BITS 24
 
@@ -315,6 +314,7 @@ int nr_find_pucch(uint16_t rnti,
 void init_prach_list(PHY_VARS_gNB *gNB);
 void init_prach_ru_list(RU_t *ru);
 void free_nr_ru_prach_entry(RU_t *ru, int prach_id);
+uint8_t get_nr_prach_duration(uint8_t prach_format);
 
 void nr_generate_csi_rs(PHY_VARS_gNB *gNB,
                         int16_t amp,
diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c b/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c
index 44f1844ae96dd180262410994dd973df2f295414..7f6f0e8ef9bcc190a28eede7e4193653829f97f9 100644
--- a/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c
+++ b/openair1/PHY/NR_UE_ESTIMATION/nr_ue_measurements.c
@@ -36,7 +36,6 @@
 #include "PHY/phy_extern_nr_ue.h"
 #include "common/utils/LOG/log.h"
 #include "PHY/sse_intrin.h"
-#include "openair2/LAYER2/NR_MAC_UE/mac_proto.h"
 
 //#define k1 1000
 #define k1 ((long long int) 1000)
diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
index a6dce88801e0d26a2f92712214f23229c9a71208..b6009776a16e2b4aba121623fe6dd7dd7e66b386 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
@@ -36,10 +36,8 @@
   #include <string.h>
 #endif
 
-#include <LAYER2/NR_MAC_UE/mac_defs.h>
-#include <LAYER2/NR_MAC_UE/mac_proto.h>
-#include "executables/softmodem-common.h"
 
+#include "executables/softmodem-common.h"
 #include "nr_transport_proto_ue.h"
 #include "PHY/CODING/nrPolar_tools/nr_polar_dci_defs.h"
 #include "PHY/phy_extern_nr_ue.h"
diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c
index fa090933061678770e53c8f3aec0f010a6a693b7..8a4cafc6d774cf54a66656c42a002cc8c49e0e28 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/dci_tools_nr.c
@@ -45,11 +45,6 @@
 
 //#define DEBUG_HARQ
 
-//#include "LAYER2/MAC/extern.h"
-//#include "LAYER2/MAC/defs.h"
-//#include "../openair2/LAYER2/MAC/extern.h"
-//#include "../openair2/LAYER2/MAC/defs.h"
-
 //#define DEBUG_DCI
 #define NR_PDCCH_DCI_TOOLS
 //#define NR_PDCCH_DCI_TOOLS_DEBUG
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index 8ee5e13235fabfcf57d9270fd905bd172ce47f33..509e42d663be9ee61815b16bb88b02fe5a0c04ca 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -43,7 +43,7 @@
 #include "SIMULATION/TOOLS/sim.h"
 #include "executables/nr-uesoftmodem.h"
 #include "PHY/CODING/nrLDPC_extern.h"
-#include "LAYER2/NR_MAC_gNB/mac_proto.h"
+#include "common/utils/nr/nr_common.h"
 
 //#define ENABLE_PHY_PAYLOAD_DEBUG 1
 
@@ -236,11 +236,10 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
                            uint8_t harq_pid,
                            uint8_t is_crnti,
                            uint8_t llr8_flag) {
-#if UE_TIMING_TRACE
   time_stats_t *dlsch_rate_unmatching_stats=&phy_vars_ue->dlsch_rate_unmatching_stats;
   time_stats_t *dlsch_turbo_decoding_stats=&phy_vars_ue->dlsch_turbo_decoding_stats;
   time_stats_t *dlsch_deinterleaving_stats=&phy_vars_ue->dlsch_deinterleaving_stats;
-#endif
+
   uint32_t A,E;
   uint32_t G;
   uint32_t ret,offset;
@@ -411,21 +410,15 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
   for (r=0; r<harq_process->C; r++) {
     //printf("start rx segment %d\n",r);
     E = nr_get_E(G, harq_process->C, harq_process->Qm, harq_process->Nl, r);
-#if UE_TIMING_TRACE
     start_meas(dlsch_deinterleaving_stats);
-#endif
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_DEINTERLEAVING, VCD_FUNCTION_IN);
     nr_deinterleaving_ldpc(E,
                            harq_process->Qm,
                            harq_process->w[r], // [hna] w is e
                            dlsch_llr+r_offset);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_DEINTERLEAVING, VCD_FUNCTION_OUT);
-#if UE_TIMING_TRACE
     stop_meas(dlsch_deinterleaving_stats);
-#endif
-#if UE_TIMING_TRACE
     start_meas(dlsch_rate_unmatching_stats);
-#endif
     LOG_D(PHY,"HARQ_PID %d Rate Matching Segment %d (coded bits %d,E %d, F %d,unpunctured/repeated bits %d, TBS %d, mod_order %d, nb_rb %d, Nl %d, rv %d, round %d)...\n",
           harq_pid,r, G,E,harq_process->F,
           Kr*3,
@@ -454,16 +447,12 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
                                  E,
                                  harq_process->F,
                                  Kr-harq_process->F-2*(p_decParams->Z))==-1) {
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_RATE_MATCHING, VCD_FUNCTION_OUT);
-#if UE_TIMING_TRACE
-      stop_meas(dlsch_rate_unmatching_stats);
-#endif
-      LOG_E(PHY,"dlsch_decoding.c: Problem in rate_matching\n");
-      return(dlsch->max_ldpc_iterations + 1);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_RATE_MATCHING, VCD_FUNCTION_OUT);
+    stop_meas(dlsch_rate_unmatching_stats);
+    LOG_E(PHY,"dlsch_decoding.c: Problem in rate_matching\n");
+    return(dlsch->max_ldpc_iterations + 1);
     } else {
-#if UE_TIMING_TRACE
-      stop_meas(dlsch_rate_unmatching_stats);
-#endif
+    stop_meas(dlsch_rate_unmatching_stats);
     }
 
     r_offset += E;
@@ -492,9 +481,7 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
     }
 
     if (err_flag == 0) {
-#if UE_TIMING_TRACE
       start_meas(dlsch_turbo_decoding_stats);
-#endif
       //set first 2*Z_c bits to zeros
       memset(&z[0],0,2*harq_process->Z*sizeof(int16_t));
       //set Filler bits
@@ -545,13 +532,10 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
       if (LOG_DEBUGFLAG(DEBUG_DLSCH_DECOD)) {
         for (int k=0; k<A>>3; k++)
           LOG_D(PHY,"output decoder [%d] =  0x%02x \n", k, harq_process->c[r][k]);
-
         LOG_D(PHY,"no_iterations_ldpc %d (ret %u)\n",no_iteration_ldpc,ret);
       }
 
-#if UE_TIMING_TRACE
       stop_meas(dlsch_turbo_decoding_stats);
-#endif
     }
 
     if ((err_flag == 0) && (ret>=(1+dlsch->max_ldpc_iterations))) {// a Code segment is in error so break;
@@ -645,11 +629,10 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
                                     uint8_t harq_pid,
                                     uint8_t is_crnti,
                                     uint8_t llr8_flag) {
-#if UE_TIMING_TRACE
+
   time_stats_t *dlsch_rate_unmatching_stats=&phy_vars_ue->dlsch_rate_unmatching_stats;
   time_stats_t *dlsch_turbo_decoding_stats=&phy_vars_ue->dlsch_turbo_decoding_stats;
   time_stats_t *dlsch_deinterleaving_stats=&phy_vars_ue->dlsch_deinterleaving_stats;
-#endif
   uint32_t A,E;
   uint32_t G;
   uint32_t ret,offset;
@@ -812,7 +795,6 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
 
   notifiedFIFO_elt_t *res_dl;
   opp_enabled=1;
-
   if (harq_process->C>1) {
     for (int nb_seg =1 ; nb_seg<harq_process->C; nb_seg++) {
       if ( (res_dl=tryPullTpool(&nf, &pool_dl)) != NULL ) {
@@ -867,9 +849,7 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
    dlsch_llr+r_offset,
    &harq_process->w[r]);
   */
-#if UE_TIMING_TRACE
   start_meas(dlsch_deinterleaving_stats);
-#endif
   nr_deinterleaving_ldpc(E,
                          harq_process->Qm,
                          harq_process->w[r],
@@ -879,12 +859,8 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
     for (int i =0; i<16; i++)
       LOG_D(PHY,"rx output deinterleaving w[%d]= %d r_offset %u\n", i,harq_process->w[r][i], r_offset);
 
-#if UE_TIMING_TRACE
   stop_meas(dlsch_deinterleaving_stats);
-#endif
-#if UE_TIMING_TRACE
   start_meas(dlsch_rate_unmatching_stats);
-#endif
 
   if (LOG_DEBUGFLAG(DEBUG_DLSCH_DECOD))
     LOG_I(PHY,"HARQ_PID %d Rate Matching Segment %d (coded bits %d,unpunctured/repeated bits %d, TBS %d, mod_order %d, nb_rb %d, Nl %d, rv %d, round %d)...\n",
@@ -915,15 +891,11 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
                                E,
                                harq_process->F,
                                Kr-harq_process->F-2*(p_decParams->Z))==-1) {
-#if UE_TIMING_TRACE
     stop_meas(dlsch_rate_unmatching_stats);
-#endif
     LOG_E(PHY,"dlsch_decoding.c: Problem in rate_matching\n");
     return(dlsch->max_ldpc_iterations);
   } else {
-#if UE_TIMING_TRACE
     stop_meas(dlsch_rate_unmatching_stats);
-#endif
   }
 
   if (LOG_DEBUGFLAG(DEBUG_DLSCH_DECOD))
@@ -966,9 +938,7 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
                                 Kr,r,harq_process->C,harq_process->nb_rb,crc_type,A,harq_process->TBS,
                                 harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round,dlsch->max_ldpc_iterations);
     */
-#if UE_TIMING_TRACE
     start_meas(dlsch_turbo_decoding_stats);
-#endif
     LOG_D(PHY,"mthread AbsSubframe %d.%d Start LDPC segment %d/%d \n",frame%1024,nr_slot_rx,r,harq_process->C-1);
     /*for (int cnt =0; cnt < (kc-2)*p_decParams->Z; cnt++){
       inv_d[cnt] = (1)*harq_process->d[r][cnt];
@@ -1037,11 +1007,10 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
       for (int k=0; k<32; k++)
         LOG_D(PHY,"output decoder [%d] =  0x%02x \n", k, harq_process->c[r][k]);
 
-#if UE_TIMING_TRACE
     stop_meas(dlsch_turbo_decoding_stats);
-#endif
   }
 
+
   if ((err_flag == 0) && (ret>=(1+dlsch->max_ldpc_iterations))) {// a Code segment is in error so break;
     LOG_D(PHY,"AbsSubframe %d.%d CRC failed, segment %d/%d \n",frame%1024,nr_slot_rx,r,harq_process->C-1);
     err_flag = 1;
@@ -1135,7 +1104,6 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
 }
 
 
-
 void nr_dlsch_decoding_process(void *arg) {
   nr_rxtx_thread_data_t *rxtxD= (nr_rxtx_thread_data_t *)arg;
   UE_nr_rxtx_proc_t *proc = &rxtxD->proc;
@@ -1167,11 +1135,10 @@ void nr_dlsch_decoding_process(void *arg) {
   proc->instance_cnt_dlsch_td=-1;
   //proc->nr_slot_rx = proc->sub_frame_start * frame_parms->slots_per_subframe;
   proc->decoder_thread_available = 1;
-#if UE_TIMING_TRACE
   time_stats_t *dlsch_rate_unmatching_stats=&phy_vars_ue->dlsch_rate_unmatching_stats;
   time_stats_t *dlsch_turbo_decoding_stats=&phy_vars_ue->dlsch_turbo_decoding_stats;
   time_stats_t *dlsch_deinterleaving_stats=&phy_vars_ue->dlsch_deinterleaving_stats;
-#endif
+
   uint32_t A,E;
   uint32_t G;
   uint32_t ret;
@@ -1272,9 +1239,7 @@ void nr_dlsch_decoding_process(void *arg) {
   Kr_bytes = Kr>>3;
   K_bits_F = Kr-harq_process->F;
   E = nr_get_E(G, harq_process->C, harq_process->Qm, harq_process->Nl, r);
-#if UE_TIMING_TRACE
   start_meas(dlsch_deinterleaving_stats);
-#endif
   nr_deinterleaving_ldpc(E,
                          harq_process->Qm,
                          harq_process->w[r],
@@ -1284,13 +1249,8 @@ void nr_dlsch_decoding_process(void *arg) {
     for (int i =0; i<16; i++)
       LOG_D(PHY,"rx output thread 0 deinterleaving w[%d]= %d r_offset %u\n", i,harq_process->w[r][i], r_offset);
 
-#if UE_TIMING_TRACE
   stop_meas(dlsch_deinterleaving_stats);
-#endif
-#if UE_TIMING_TRACE
   start_meas(dlsch_rate_unmatching_stats);
-#endif
-
   if (LOG_DEBUGFLAG(DEBUG_DLSCH_DECOD))
     LOG_I(PHY,"HARQ_PID %d Rate Matching Segment %d (coded bits %d,unpunctured/repeated bits %d, TBS %d, mod_order %d, nb_rb %d, Nl %d, rv %d, round %d)...\n",
           harq_pid,r, G,
@@ -1319,15 +1279,11 @@ void nr_dlsch_decoding_process(void *arg) {
                                E,
                                harq_process->F,
                                Kr-harq_process->F-2*(p_decParams->Z))==-1) {
-#if UE_TIMING_TRACE
     stop_meas(dlsch_rate_unmatching_stats);
-#endif
     LOG_E(PHY,"dlsch_decoding.c: Problem in rate_matching\n");
     //return(dlsch->max_ldpc_iterations);
   } else {
-#if UE_TIMING_TRACE
     stop_meas(dlsch_rate_unmatching_stats);
-#endif
   }
 
   if (LOG_DEBUGFLAG(DEBUG_DLSCH_DECOD)) {
@@ -1364,9 +1320,7 @@ void nr_dlsch_decoding_process(void *arg) {
                    Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round);
     }
 
-#if UE_TIMING_TRACE
     start_meas(dlsch_turbo_decoding_stats);
-#endif
     //      LOG_D(PHY,"AbsSubframe %d.%d Start LDPC segment %d/%d \n",frame%1024,subframe,r,harq_process->C-1);
     /*
             for (int cnt =0; cnt < (kc-2)*p_decParams->Z; cnt++){
@@ -1412,10 +1366,7 @@ void nr_dlsch_decoding_process(void *arg) {
     if ( LOG_DEBUGFLAG(DEBUG_DLSCH_DECOD))
       for (int k=0; k<2; k++)
         LOG_D(PHY,"segment 1 output decoder [%d] =  0x%02x \n", k, harq_process->c[r][k]);
-
-#if UE_TIMING_TRACE
     stop_meas(dlsch_turbo_decoding_stats);
-#endif
   }
 
   if ((err_flag == 0) && (ret>=(1+dlsch->max_ldpc_iterations))) {// a Code segment is in error so break;
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c
index fb6e7bf6b5da04d2c47c890f7a07e51298cb2c16..031c08a72dfd52c329bdce03eec8d4eee67175b8 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_demodulation.c
@@ -41,6 +41,7 @@
 #include "openair1/PHY/NR_TRANSPORT/nr_dlsch.h"
 #include "PHY/NR_REFSIG/nr_refsig.h"
 #include "PHY/NR_REFSIG/dmrs_nr.h"
+#include "common/utils/nr/nr_common.h"
 
 #ifndef USER_MODE
 #define NOCYGWIN_STATIC static
@@ -163,9 +164,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
 //  int avg_0[2];
 //  int avg_1[2];
 
-#if UE_TIMING_TRACE
   uint8_t slot = 0;
-#endif
 
   unsigned char aatx=0,aarx=0;
 
@@ -331,12 +330,10 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
     DevAssert(dlsch1_harq);
   }
 
-#if UE_TIMING_TRACE
   if(symbol > ue->frame_parms.symbols_per_slot>>1)
   {
       slot = 1;
   }
-#endif
 
 #ifdef DEBUG_HARQ
   printf("Demod  dlsch0_harq->pmi_alloc %d\n",  dlsch0_harq->pmi_alloc);
@@ -346,9 +343,7 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
   uint8_t config_type = dlsch0_harq->dmrsConfigType;
 
   if (beamforming_mode==0) {//No beamforming
-#if UE_TIMING_TRACE
     start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#endif
     if (dlsch0_harq->Nl > 1)//More than or equal 2 layers
       nb_rb = nr_dlsch_extract_rbs_multiple(common_vars->common_vars_rx_data_per_thread[proc->thread_id].rxdataF,
                                             pdsch_vars[gNB_id]->dl_ch_estimates,
@@ -389,7 +384,6 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
 
   len = (pilots==1)? ((config_type==NFAPI_NR_DMRS_TYPE1)?nb_rb*(12-6*dlsch0_harq->n_dmrs_cdm_groups): nb_rb*(12-4*dlsch0_harq->n_dmrs_cdm_groups)):(nb_rb*12);
 
-#if UE_TIMING_TRACE
   stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
 #if DISABLE_LOG_X
   printf("[AbsSFN %u.%d] Slot%d Symbol %d type %d: Pilot/Data extraction %5.2f \n",
@@ -398,11 +392,8 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
   LOG_I(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d type %d: Pilot/Data extraction %5.2f \n",
 	frame,nr_slot_rx,slot,symbol,type,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #endif
-#endif
   
-#if UE_TIMING_TRACE
   start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#endif
   n_tx = dlsch0_harq->Nl;
   n_rx = frame_parms->nb_antennas_rx;
   
@@ -416,18 +407,13 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
                          len,
                          nb_rb_pdsch);
 
-#if UE_TIMING_TRACE
     stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
 #if DISABLE_LOG_X
     printf("[AbsSFN %u.%d] Slot%d Symbol %d: Channel Scale %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #else
     LOG_I(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d: Channel Scale  %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #endif
-#endif
-
-#if UE_TIMING_TRACE
     start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#endif
   if (first_symbol_flag==1) {
     if (beamforming_mode==0){
       nr_dlsch_channel_level(pdsch_vars[gNB_id]->dl_ch_estimates_ext,
@@ -482,19 +468,14 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
     }
 #endif
 
-#if UE_TIMING_TRACE
     stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
 #if DISABLE_LOG_X
     printf("[AbsSFN %u.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level %5.2f \n",frame,nr_slot_rx,slot,symbol,first_symbol_flag,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #else
     LOG_I(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level  %5.2f \n",frame,nr_slot_rx,slot,symbol,first_symbol_flag,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #endif
-#endif
 
-
-#if UE_TIMING_TRACE
     start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#endif
 // Now channel compensation
   if (dlsch0_harq->mimo_mode<NR_DUALSTREAM) {
     nr_dlsch_channel_compensation(pdsch_vars[gNB_id]->rxdataF_ext,
@@ -539,18 +520,13 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
                                           0);
   }
 
-#if UE_TIMING_TRACE
     stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
 #if DISABLE_LOG_X
     printf("[AbsSFN %u.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp %5.2f \n", frame, nr_slot_rx, slot, symbol, pdsch_vars[gNB_id]->log2_maxh, proc->channel_level, ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #else
     LOG_I(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp  %5.2f \n", frame, nr_slot_rx, slot, symbol, pdsch_vars[gNB_id]->log2_maxh, proc->channel_level, ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #endif
-#endif
-// MRC
-#if UE_TIMING_TRACE
     start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#endif
 
   if (frame_parms->nb_antennas_rx > 1) {
     if (dlsch0_harq->mimo_mode<NR_DUALSTREAM) {
@@ -603,19 +579,13 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
     //i_mod should have been passed as a parameter
   }
   
-#if UE_TIMING_TRACE
     stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
 #if DISABLE_LOG_X
     printf("[AbsSFN %u.%d] Slot%d Symbol %d: Channel Combine %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #else
     LOG_I(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d: Channel Combine  %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #endif
-#endif
-
-#if UE_TIMING_TRACE
-
     start_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
-#endif
   /* Store the valid DL RE's */
     pdsch_vars[gNB_id]->dl_valid_re[symbol-1] = len;
 
@@ -692,14 +662,12 @@ int nr_rx_pdsch(PHY_VARS_NR_UE *ue,
 
     }
 
-#if UE_TIMING_TRACE
     stop_meas(&ue->generic_stat_bis[proc->thread_id][slot]);
 #if DISABLE_LOG_X
     printf("[AbsSFN %u.%d] Slot%d Symbol %d: LLR Computation %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #else
     LOG_I(PHY, "[AbsSFN %u.%d] Slot%d Symbol %d: LLR Computation  %5.2f \n",frame,nr_slot_rx,slot,symbol,ue->generic_stat_bis[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #endif
-#endif
 
 // Please keep it: useful for debugging
 #ifdef DEBUG_PDSCH_RX
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c
index 7dfd765b76e8050710b92f423600518232c101e1..6b8014b5ce219c7214cbeabc80f47ccc66c11e50 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_initial_sync.c
@@ -126,15 +126,11 @@ int nr_pbch_detection(UE_nr_rxtx_proc_t * proc, PHY_VARS_NR_UE *ue, int pbch_ini
       // initialization of structure
       current_ssb = create_ssb_node(l,hf);
 
-#if UE_TIMING_TRACE
       start_meas(&ue->dlsch_channel_estimation_stats);
-#endif
       // computing correlation between received DMRS symbols and transmitted sequence for current i_ssb and n_hf
       for(int i=pbch_initial_symbol; i<pbch_initial_symbol+3;i++)
           nr_pbch_dmrs_correlation(ue,proc,0,0,i,i-pbch_initial_symbol,current_ssb);
-#if UE_TIMING_TRACE
       stop_meas(&ue->dlsch_channel_estimation_stats);
-#endif
       
       current_ssb->metric = current_ssb->c_re*current_ssb->c_re + current_ssb->c_im*current_ssb->c_im;
       
@@ -150,15 +146,11 @@ int nr_pbch_detection(UE_nr_rxtx_proc_t * proc, PHY_VARS_NR_UE *ue, int pbch_ini
   NR_UE_SSB *temp_ptr=best_ssb;
   while (ret!=0 && temp_ptr != NULL) {
 
-#if UE_TIMING_TRACE
     start_meas(&ue->dlsch_channel_estimation_stats);
-#endif
   // computing channel estimation for selected best ssb
     for(int i=pbch_initial_symbol; i<pbch_initial_symbol+3;i++)
       nr_pbch_channel_estimation(ue,proc,0,0,i,i-pbch_initial_symbol,temp_ptr->i_ssb,temp_ptr->n_hf);
-#if UE_TIMING_TRACE
     stop_meas(&ue->dlsch_channel_estimation_stats);
-#endif
 
     ret = nr_rx_pbch(ue,
                      proc,
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
index ba5c65ceb71086c01f6505bc4134ad9acfaaeb49..f8e7ce317f31aec5e68e34838d23cf83b7bacda1 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
@@ -39,7 +39,6 @@
 #include "PHY/CODING/nrLDPC_extern.h"
 #include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
-#include "LAYER2/NR_MAC_gNB/mac_proto.h"
 #include <openair2/UTIL/OPT/opt.h>
 
 //#define DEBUG_ULSCH_CODING
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index b1addf740a2ee6c668eb03831b1841d1e1877c5e..1c98c8c119257bc7de0e7097215bccd7ae8e1cee 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -44,8 +44,6 @@
 #include "PHY/TOOLS/tools_defs.h"
 #include "executables/nr-softmodem.h"
 #include "executables/softmodem-common.h"
-#include "LAYER2/NR_MAC_UE/mac_proto.h"
-
 #include "PHY/NR_REFSIG/ul_ref_seq_nr.h"
 
 //#define DEBUG_PUSCH_MAPPING
@@ -143,7 +141,12 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
 
     ulsch_ue->Nid_cell    = Nid_cell;
 
-    get_num_re_dmrs(pusch_pdu, &nb_dmrs_re_per_rb, &number_dmrs_symbols);
+    for (int i = start_symbol; i < start_symbol + number_of_symbols; i++) {
+      if((ul_dmrs_symb_pos >> i) & 0x01)
+        number_dmrs_symbols += 1;
+    }
+
+    nb_dmrs_re_per_rb = ((dmrs_type == pusch_dmrs_type1) ? 6:4)*cdm_grps_no_data;
 
     LOG_D(PHY,"ulsch %x : start_rb %d bwp_start %d start_sc %d start_symbol %d num_symbols %d cdmgrpsnodata %d num_dmrs %d dmrs_re_per_rb %d\n",
           rnti,start_rb,pusch_pdu->bwp_start,start_sc,start_symbol,number_of_symbols,cdm_grps_no_data,number_dmrs_symbols,nb_dmrs_re_per_rb);
diff --git a/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c b/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c
index 20a159565507db4f83146fb785f88769516905ec..68d873541156233250def5db490d0f844a56f3d7 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.c
@@ -34,7 +34,6 @@
 #include "PHY/defs_nr_common.h"
 #include "PHY/defs_nr_UE.h"
 //#include "PHY/extern.h"
-//#include "LAYER2/MAC/extern.h"
 #include "PHY/NR_UE_TRANSPORT/pucch_nr.h"
 #include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h"
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
diff --git a/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.h b/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.h
index dcf7fb4a37eab55559ed4fbf6219242511ce30bd..078a95605f59f36bb561e9fbf564122a0b1d0e5b 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.h
+++ b/openair1/PHY/NR_UE_TRANSPORT/pucch_nr.h
@@ -37,7 +37,6 @@
 #include "PHY/defs_nr_common.h"
 #include "PHY/defs_nr_UE.h"
 //#include "PHY/extern.h"
-//#include "LAYER2/MAC/extern.h"
 
 #include "common/utils/LOG/log.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
diff --git a/openair1/PHY/TOOLS/time_meas.c b/openair1/PHY/TOOLS/time_meas.c
index 8a15edc8f61b17350f8a72cf6b1ea48d577bbaa8..c62fbed10630ef627417a1318ea02c2ec5375e3b 100644
--- a/openair1/PHY/TOOLS/time_meas.c
+++ b/openair1/PHY/TOOLS/time_meas.c
@@ -18,17 +18,27 @@
  * For more information about the OpenAirInterface (OAI) Software Alliance:
  *      contact@openairinterface.org
  */
-
+#define _GNU_SOURCE
 #include <stdio.h>
 #include "time_meas.h"
 #include <math.h>
 #include <unistd.h>
-
+#include <string.h>
+#include "assertions.h"
+#ifndef PHYSIM
+  #include <pthread.h>
+  #include "common/config/config_userapi.h"
+#endif
 // global var for openair performance profiler
 int opp_enabled = 0;
 double cpu_freq_GHz  __attribute__ ((aligned(32)));
 
 double cpu_freq_GHz  __attribute__ ((aligned(32)))=0.0;
+#ifndef PHYSIM
+static uint32_t    max_cpumeasur;
+static time_stats_t  **measur_table;
+notifiedFIFO_t measur_fifo;
+#endif
 double get_cpu_freq_GHz(void)
 {
   if (cpu_freq_GHz <1 ) {
@@ -133,3 +143,112 @@ double get_time_meas_us(time_stats_t *ts)
 
   return 0;
 }
+
+#ifndef PHYSIM
+/* function for the asynchronous measurment module: cpu stat are sent to a dedicated thread
+ * which is in charge of computing the cpu time spent in a given function/algorithm...
+ */
+
+time_stats_t *register_meas(char *name)
+{
+  for (int i=0; i<max_cpumeasur; i++) {
+    if (measur_table[i] == NULL) {
+      measur_table[i] = (time_stats_t *)malloc(sizeof(time_stats_t));
+      memset(measur_table[i] ,0,sizeof(time_stats_t));
+      measur_table[i]->meas_name = strdup(name);
+      measur_table[i]->meas_index = i;
+      measur_table[i]->tpoolmsg =newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
+      measur_table[i]->tstatptr = (time_stats_msg_t *)NotifiedFifoData(measur_table[i]->tpoolmsg);
+      return measur_table[i];
+    }
+  }
+  return NULL;
+}
+
+void free_measurtbl(void) {
+  for (int i=0; i<max_cpumeasur; i++) {
+    if (measur_table[i] != NULL) {
+	  free(measur_table[i]->meas_name);
+	  delNotifiedFIFO_elt(measur_table[i]->tpoolmsg);
+	  free(measur_table[i]);
+    }
+  }
+  //free the fifo...
+}
+
+void run_cpumeasur(void) {
+    struct sched_param schedp;
+    pthread_setname_np(pthread_self(), "measur");
+    schedp.sched_priority=0;
+    int rt=pthread_setschedparam(pthread_self(), SCHED_IDLE, &schedp);
+    AssertFatal(rt==0, "couldn't set measur thread priority: %s\n",strerror(errno));
+    initNotifiedFIFO(&measur_fifo);
+    while(1) {
+      notifiedFIFO_elt_t *msg = pullNotifiedFIFO(&measur_fifo);
+      time_stats_msg_t *tsm = (time_stats_msg_t *)NotifiedFifoData(msg);
+        switch(tsm->msgid) {
+          case TIMESTAT_MSGID_START:
+             measur_table[tsm->timestat_id]->in=tsm->ts;
+             (measur_table[tsm->timestat_id]->trials)++;
+          break;
+          case TIMESTAT_MSGID_STOP:
+    /// process duration is the difference between two clock points
+             measur_table[tsm->timestat_id]->p_time = (tsm->ts - measur_table[tsm->timestat_id]->in);
+             measur_table[tsm->timestat_id]->diff += measur_table[tsm->timestat_id]->p_time;
+             if ( measur_table[tsm->timestat_id]->p_time > measur_table[tsm->timestat_id]->max )
+               measur_table[tsm->timestat_id]->max = measur_table[tsm->timestat_id]->p_time;
+          break;
+          case TIMESTAT_MSGID_DISPLAY:
+            {
+            char aline[256];
+            int start, stop;
+             if (tsm->displayFunc != NULL) {
+               if(tsm->timestat_id >= 0) {
+                 start=tsm->timestat_id ;
+                 stop=start+1;
+               }
+               else {
+                  start=0;
+                  stop=max_cpumeasur ;
+               }
+               for (int i=start ; i<stop ; i++) {
+                 if (measur_table[i] != NULL) {
+                   sprintf(aline,"%s: %15.3f us ",measur_table[i]->meas_name, measur_table[i]->trials==0?0:(  (measur_table[i]->trials/measur_table[i]->diff )/ cpu_freq_GHz /1000 ));
+                   tsm->displayFunc(aline);
+                   }
+                }
+             }
+            }
+          break;
+          case TIMESTAT_MSGID_END:
+            free_measurtbl();
+            delNotifiedFIFO_elt(msg);
+            pthread_exit(NULL);
+          break;
+          default:
+          break;
+      }
+    delNotifiedFIFO_elt(msg);
+    }
+}
+
+
+void init_meas(void) {
+  pthread_t thid;
+  paramdef_t cpumeasur_params[] = CPUMEASUR_PARAMS_DESC;
+  int numparams=sizeof(cpumeasur_params)/sizeof(paramdef_t);
+  int rt = config_get( cpumeasur_params,numparams,CPUMEASUR_SECTION);
+  AssertFatal(rt >= 0, "cpumeasur configuration couldn't be performed");
+  measur_table=calloc(max_cpumeasur,sizeof( time_stats_t *));
+  AssertFatal(measur_table!=NULL, "couldn't allocate %u cpu measurements entries\n",max_cpumeasur);
+  rt=pthread_create(&thid,NULL, (void *(*)(void *))run_cpumeasur, NULL);
+  AssertFatal(rt==0, "couldn't create cpu measurment thread: %s\n",strerror(errno));
+}
+
+void end_meas(void) {
+    notifiedFIFO_elt_t *nfe = newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
+	time_stats_msg_t *msg = (time_stats_msg_t *)NotifiedFifoData(nfe);
+    msg->msgid = TIMESTAT_MSGID_END ;
+    pushNotifiedFIFO(&measur_fifo, nfe);
+}
+#endif
diff --git a/openair1/PHY/TOOLS/time_meas.h b/openair1/PHY/TOOLS/time_meas.h
index e2ceef84050de9f7ddf3e8664948724aa2f50eb0..f78ea55530a294fc87ebcddc0948d2f53b6e7adb 100644
--- a/openair1/PHY/TOOLS/time_meas.h
+++ b/openair1/PHY/TOOLS/time_meas.h
@@ -31,30 +31,56 @@
 #include <pthread.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
+#ifndef PHYSIM
+  #include "common/utils/threadPool/thread-pool.h"
+#endif
 // global var to enable openair performance profiler
 extern int opp_enabled;
 extern double cpu_freq_GHz  __attribute__ ((aligned(32)));;
-
+// structure to store data to compute cpu measurment
 #if defined(__x86_64__) || defined(__i386__)
-typedef struct {
-  long long in;
-  long long diff;
-  long long p_time; /*!< \brief absolute process duration */
-  long long diff_square; /*!< \brief process duration square */
-  long long max;
-  int trials;
-  int meas_flag;
-} time_stats_t;
+  #define OAI_CPUTIME_TYPE long long
 #elif defined(__arm__)
+  #define OAI_CPUTIME_TYPE uint32_t
+#else
+  #error "building on unsupported CPU architecture"
+#endif
+
+#define TIMESTAT_MSGID_START       0     /*!< \brief send time at measure starting point */
+#define TIMESTAT_MSGID_STOP        1     /*!< \brief send time at measure end  point */
+#define TIMESTAT_MSGID_ENABLE      2     /*!< \brief enable measure point */
+#define TIMESTAT_MSGID_DISABLE     3     /*!< \brief disable measure point */
+#define TIMESTAT_MSGID_DISPLAY     10    /*!< \brief display measure */
+#define TIMESTAT_MSGID_END         11    /*!< \brief stops the measure threads and free assocated resources */
+typedef void(*meas_printfunc_t)(const char* format, ...);
 typedef struct {
-  uint32_t in;
-  uint32_t diff;
-  uint32_t p_time; /*!< \brief absolute process duration */
-  uint32_t diff_square; /*!< \brief process duration square */
-  uint32_t max;
-  int trials;
-} time_stats_t;
+  int               msgid;                  /*!< \brief message id, as defined by TIMESTAT_MSGID_X macros */
+  int               timestat_id;            /*!< \brief points to the time_stats_t entry in cpumeas table */
+  OAI_CPUTIME_TYPE  ts;                     /*!< \brief time stamp */
+  meas_printfunc_t  displayFunc;            /*!< \brief function to call when DISPLAY message is received*/
+} time_stats_msg_t;
+
+
+typedef struct {
+  OAI_CPUTIME_TYPE in;      /*!< \brief time at measure starting point */
+  OAI_CPUTIME_TYPE diff;     /*!< \brief average difference between time at starting point and time at endpoint*/
+  OAI_CPUTIME_TYPE p_time; /*!< \brief absolute process duration */
+  OAI_CPUTIME_TYPE diff_square; /*!< \brief process duration square */
+  OAI_CPUTIME_TYPE max;      /*!< \brief maximum difference between time at starting point and time at endpoint*/
+  int trials;                /*!< \brief number of start point - end point iterations */
+  int meas_flag;             /*!< \brief 1: stop_meas not called (consecutive calls of start_meas) */
+  char *meas_name;           /*!< \brief name to use when printing the measure (not used for PHY simulators)*/
+  int meas_index;            /*!< \brief index of this measure in the measure array (not used for PHY simulators)*/
+  int meas_enabled;         /*!< \brief per measure enablement flag. send_meas tests this flag, unused today in start_meas and stop_meas*/
+#ifndef PHYSIM
+  notifiedFIFO_elt_t *tpoolmsg; /*!< \brief message pushed to the cpu measurment queue to report a measure START or STOP */
+  time_stats_msg_t *tstatptr;   /*!< \brief pointer to the time_stats_msg_t data in the tpoolmsg, stored here for perf considerations*/
 #endif
+} time_stats_t;
+#define MEASURE_ENABLED(X)       (X->meas_enabled)
+
+
+
 
 static inline void start_meas(time_stats_t *ts) __attribute__((always_inline));
 static inline void stop_meas(time_stats_t *ts) __attribute__((always_inline));
@@ -137,4 +163,28 @@ static inline void copy_meas(time_stats_t *dst_ts,time_stats_t *src_ts) {
     dst_ts->max=src_ts->max;
   }
 }
+
+#ifndef PHYSIM
+extern notifiedFIFO_t measur_fifo;
+#define CPUMEASUR_SECTION "cpumeasur"
+
+#define CPUMEASUR_PARAMS_DESC { \
+    {"max_cpumeasur",     "Max number of cpu measur entries",      0,       uptr:&max_cpumeasur,           defintval:100,         TYPE_UINT,   0},\
+  }
+
+  void init_meas(void);
+  time_stats_t *register_meas(char *name);
+  #define START_MEAS(X) send_meas(X, TIMESTAT_MSGID_START)
+  #define STOP_MEAS(X)  send_meas(X, TIMESTAT_MSGID_STOP)
+  static inline void send_meas(time_stats_t *ts, int msgid) {
+    if (MEASURE_ENABLED(ts) ) {
+      ts->tstatptr->timestat_id=ts->meas_index;
+      ts->tstatptr->msgid = msgid ;
+      ts->tstatptr->ts = rdtsc_oai();
+      pushNotifiedFIFO(&measur_fifo, ts->tpoolmsg);
+    }
+  }
+  void end_meas(void);
+
+#endif  //ifndef PHYSIM
 #endif
diff --git a/openair1/SCHED_NR/fapi_nr_l1.c b/openair1/SCHED_NR/fapi_nr_l1.c
index 3a7b630d0965a237b3c3fbed47357d3193bc3a29..8f315ba214d2fea4b283685b526308fac516f848 100644
--- a/openair1/SCHED_NR/fapi_nr_l1.c
+++ b/openair1/SCHED_NR/fapi_nr_l1.c
@@ -30,6 +30,7 @@
  * \warning
  */
 #include "fapi_nr_l1.h"
+#include "common/ran_context.h"
 #include "PHY/NR_TRANSPORT/nr_transport_proto.h"
 #include "PHY/NR_TRANSPORT/nr_dlsch.h"
 #include "PHY/NR_TRANSPORT/nr_dci.h"
@@ -146,7 +147,7 @@ void nr_schedule_response(NR_Sched_Rsp_t *Sched_INFO){
   AssertFatal(RC.gNB!=NULL,"RC.gNB is null\n");
   AssertFatal(RC.gNB[Mod_id]!=NULL,"RC.gNB[%d] is null\n",Mod_id);
 
-  gNB         = RC.gNB[Mod_id];
+  gNB = RC.gNB[Mod_id];
 
   notifiedFIFO_elt_t *res;
   res = pullTpool(gNB->resp_L1_tx, gNB->threadPool);
diff --git a/openair1/SCHED_NR/nr_prach_procedures.c b/openair1/SCHED_NR/nr_prach_procedures.c
index caa5f8ea78263e15f746726fdaefb9844f5b0038..1ea8dbdf3c4878dd40c4004880eda98523e3a1f3 100644
--- a/openair1/SCHED_NR/nr_prach_procedures.c
+++ b/openair1/SCHED_NR/nr_prach_procedures.c
@@ -49,6 +49,59 @@
 
 extern uint8_t nfapi_mode;
 
+uint8_t get_nr_prach_duration(uint8_t prach_format){
+
+  switch(prach_format){
+
+      case 0:  // format 0
+         return 0;
+
+      case 1:  // format 1
+         return 0;
+
+      case 2:  // format 2
+         return 0;
+
+      case 3:  // format 3
+         return 0;
+
+      case 4:  // format A1
+         return 2;
+
+      case 5:  // format A2
+         return 4;
+
+      case 6:  // format A3
+         return 6;
+
+      case 7:  // format B1
+         return 2;
+
+      case 8:  // format B4
+         return 12;
+
+      case 9:  // format C0
+         return 2;
+
+      case 10:  // format C2
+         return 6;
+
+      case 11:  // format A1/B1
+         return 2;
+
+      case 12:  // format A2/B2
+         return 4;
+
+      case 13:  // format A3/B3
+         return 6;
+
+      default :
+         AssertFatal(1==0,"Invalid Prach format\n");
+         break;
+
+  }
+}
+
 void L1_nr_prach_procedures(PHY_VARS_gNB *gNB,int frame,int slot) {
 
   uint16_t max_preamble[4]={0},max_preamble_energy[4]={0},max_preamble_delay[4]={0};
diff --git a/openair1/SCHED_NR_UE/defs.h b/openair1/SCHED_NR_UE/defs.h
index 7b4511e7f4236f7a4e67c90a288db37551827296..c98574ec42f35addc4758ff8290303605a7d96e1 100644
--- a/openair1/SCHED_NR_UE/defs.h
+++ b/openair1/SCHED_NR_UE/defs.h
@@ -340,8 +340,6 @@ uint16_t nr_get_n1_pucch(PHY_VARS_NR_UE *phy_vars_ue,
 */
 UE_MODE_t get_nrUE_mode(uint8_t Mod_id,uint8_t CC_id,uint8_t gNB_index);
 
-uint8_t get_ra_PreambleIndex(uint8_t Mod_id, uint8_t CC_id, uint8_t gNB_id);
-
 /*! \brief This function implements the power control mechanism for PUCCH from 36.213.
     @param phy_vars_ue PHY variables
     @param proc Pointer to proc descriptor
diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
index b09da1b5bd9eed36118e14d0424bc2fe7890552d..5faa84193cbdac850230ec00737942d3d7a9e2ff 100644
--- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
+++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
@@ -52,7 +52,8 @@
 #endif
 #include "executables/softmodem-common.h"
 #include "executables/nr-uesoftmodem.h"
-#include "openair2/LAYER2/NR_MAC_UE/mac_proto.h"
+#include "LAYER2/NR_MAC_UE/mac_proto.h"
+#include "LAYER2/NR_MAC_UE/nr_l1_helpers.h"
 
 //#define DEBUG_PHY_PROC
 #define NR_PDCCH_SCHED
@@ -64,8 +65,6 @@
 #define PUCCH
 #endif
 
-#include "LAYER2/NR_MAC_UE/mac_defs.h"
-#include "LAYER2/NR_MAC_UE/mac_proto.h"
 #include "common/utils/LOG/log.h"
 
 #ifdef EMOS
@@ -215,12 +214,6 @@ UE_MODE_t get_nrUE_mode(uint8_t Mod_id,uint8_t CC_id,uint8_t gNB_id){
   return(PHY_vars_UE_g[Mod_id][CC_id]->UE_mode[gNB_id]);
 }
 
-uint8_t get_ra_PreambleIndex(uint8_t Mod_id, uint8_t CC_id, uint8_t gNB_id){
-
-  return PHY_vars_UE_g[Mod_id][CC_id]->prach_resources[gNB_id]->ra_PreambleIndex;
-
-}
-
 // convert time factor "16 * 64 * T_c / (2^mu)" in N_TA calculation in TS38.213 section 4.2 to samples by multiplying with samples per second
 //   16 * 64 * T_c            / (2^mu) * samples_per_second
 // = 16 * T_s                 / (2^mu) * samples_per_second
@@ -282,9 +275,8 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,
 
   LOG_D(PHY,"****** start TX-Chain for AbsSubframe %d.%d ******\n", frame_tx, slot_tx);
 
-#if UE_TIMING_TRACE
+
   start_meas(&ue->phy_proc_tx);
-#endif
 
   if (ue->UE_mode[gNB_id] <= PUSCH){
 
@@ -296,9 +288,8 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue,
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX, VCD_FUNCTION_OUT);
-#if UE_TIMING_TRACE
   stop_meas(&ue->phy_proc_tx);
-#endif
+
 
 }
 
@@ -647,9 +638,7 @@ int nr_ue_pdcch_procedures(uint8_t gNB_id,
 
 
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PDCCH_PROCEDURES, VCD_FUNCTION_IN);
-#if UE_TIMING_TRACE
-      start_meas(&ue->dlsch_rx_pdcch_stats);
-#endif
+    start_meas(&ue->dlsch_rx_pdcch_stats);
 
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PDCCH, VCD_FUNCTION_IN);
 #ifdef NR_PDCCH_SCHED_DEBUG
@@ -749,9 +738,7 @@ int nr_ue_pdcch_procedures(uint8_t gNB_id,
     //  send to mac
     ue->if_inst->dl_indication(&dl_indication, NULL);
 
-#if UE_TIMING_TRACE
   stop_meas(&ue->dlsch_rx_pdcch_stats);
-#endif
     
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PDCCH_PROCEDURES, VCD_FUNCTION_OUT);
   return(dci_cnt);
@@ -833,12 +820,10 @@ int nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int gNB_
       else
         first_symbol_flag = 0;
 
-#if UE_TIMING_TRACE
       uint8_t slot = 0;
       if(m >= ue->frame_parms.symbols_per_slot>>1)
         slot = 1;
       start_meas(&ue->dlsch_llr_stats_parallelization[proc->thread_id][slot]);
-#endif
       // process DLSCH received symbols in the slot
       // symbol by symbol processing (if data/DMRS are multiplexed is checked inside the function)
       if (pdsch == PDSCH || pdsch == SI_PDSCH || pdsch == RA_PDSCH) {
@@ -857,13 +842,11 @@ int nr_ue_pdsch_procedures(PHY_VARS_NR_UE *ue, UE_nr_rxtx_proc_t *proc, int gNB_
           return -1;
       } else AssertFatal(1==0,"Not RA_PDSCH, SI_PDSCH or PDSCH\n");
 
-#if UE_TIMING_TRACE
       stop_meas(&ue->dlsch_llr_stats_parallelization[proc->thread_id][slot]);
-#if DISABLE_LOG_X
+#if PHYSIM
       printf("[AbsSFN %d.%d] LLR Computation Symbol %d %5.2f \n",frame_rx,nr_slot_rx,m,ue->dlsch_llr_stats_parallelization[proc->thread_id][slot].p_time/(cpuf*1000.0));
 #else
       LOG_D(PHY, "[AbsSFN %d.%d] LLR Computation Symbol %d %5.2f \n",frame_rx,nr_slot_rx,m,ue->dlsch_llr_stats_parallelization[proc->thread_id][slot].p_time/(cpuf*1000.0));
-#endif
 #endif
 
       if(first_symbol_flag) {
@@ -971,19 +954,17 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
                                                    dmrs_len,
                                                    dlsch0->harq_processes[harq_pid]->Qm,
                                                    dlsch0->harq_processes[harq_pid]->Nl);
-#if UE_TIMING_TRACE
-    start_meas(&ue->dlsch_unscrambling_stats);
-#endif
-    nr_dlsch_unscrambling(pdsch_vars->llr[0],
-                          dlsch0->harq_processes[harq_pid]->G,
-                          0,
-                          ue->frame_parms.Nid_cell,
-                          dlsch0->rnti);
+
+      start_meas(&ue->dlsch_unscrambling_stats);
+      nr_dlsch_unscrambling(pdsch_vars->llr[0],
+                            dlsch0->harq_processes[harq_pid]->G,
+                            0,
+                            ue->frame_parms.Nid_cell,
+                            dlsch0->rnti);
       
 
-#if UE_TIMING_TRACE
-    stop_meas(&ue->dlsch_unscrambling_stats);
-#endif
+      stop_meas(&ue->dlsch_unscrambling_stats);
+
 
 #if 0
       LOG_I(PHY," ------ start ldpc decoder for AbsSubframe %d.%d / %d  ------  \n", frame_rx, nr_slot_rx, harq_pid);
@@ -996,9 +977,8 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
       LOG_I(PHY,"start ldpc decode for CW 0 for AbsSubframe %d.%d / %d  --> Pdcch Sym  %d \n", frame_rx, nr_slot_rx, harq_pid, ue->pdcch_vars[proc->thread_id][gNB_id]->num_pdcch_symbols);
 #endif
 
-#if UE_TIMING_TRACE
-    start_meas(&ue->dlsch_decoding_stats[proc->thread_id]);
-#endif
+
+   start_meas(&ue->dlsch_decoding_stats[proc->thread_id]);
 
     if( dlsch_parallel) {
       ret = nr_dlsch_decoding_mthread(ue,
@@ -1059,9 +1039,9 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
 
 
 
-#if UE_TIMING_TRACE
-    stop_meas(&ue->dlsch_decoding_stats[proc->thread_id]);
-#if DISABLE_LOG_X
+
+      stop_meas(&ue->dlsch_decoding_stats[proc->thread_id]);
+#if PHYSIM
     printf(" --> Unscrambling for CW0 %5.3f\n",
            (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
     printf("AbsSubframe %d.%d --> LDPC Decoding for CW0 %5.3f\n",
@@ -1073,7 +1053,6 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
           frame_rx%1024, nr_slot_rx,(ue->dlsch_decoding_stats[proc->thread_id].p_time)/(cpuf*1000.0));
 #endif
 
-#endif
     if(is_cw1_active) {
       // start ldpc decode for CW 1
       dlsch1->harq_processes[harq_pid]->G = nr_get_G(dlsch1->harq_processes[harq_pid]->nb_rb,
@@ -1082,17 +1061,13 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
                                                      dmrs_len,
                                                      dlsch1->harq_processes[harq_pid]->Qm,
                                                      dlsch1->harq_processes[harq_pid]->Nl);
-#if UE_TIMING_TRACE
       start_meas(&ue->dlsch_unscrambling_stats);
-#endif
       nr_dlsch_unscrambling(pdsch_vars->llr[1],
                             dlsch1->harq_processes[harq_pid]->G,
                             0,
                             ue->frame_parms.Nid_cell,
                             dlsch1->rnti);
-#if UE_TIMING_TRACE
       stop_meas(&ue->dlsch_unscrambling_stats);
-#endif
 
 #if 0
           LOG_I(PHY,"start ldpc decode for CW 1 for AbsSubframe %d.%d / %d --> nb_rb %d \n", frame_rx, nr_slot_rx, harq_pid, dlsch1->harq_processes[harq_pid]->nb_rb);
@@ -1104,9 +1079,8 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
           LOG_I(PHY,"start ldpc decode for CW 1 for AbsSubframe %d.%d / %d  --> Pdcch Sym  %d \n", frame_rx, nr_slot_rx, harq_pid, ue->pdcch_vars[proc->thread_id][gNB_id]->num_pdcch_symbols);
 #endif
 
-#if UE_TIMING_TRACE
       start_meas(&ue->dlsch_decoding_stats[proc->thread_id]);
-#endif
+
 
       if(dlsch_parallel) {
         ret1 = nr_dlsch_decoding_mthread(ue,
@@ -1141,9 +1115,9 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
         LOG_T(PHY,"CWW sequential dlsch decoding, ret1 = %d\n", ret1);
       }
 
-#if UE_TIMING_TRACE
-      stop_meas(&ue->dlsch_decoding_stats[proc->thread_id]);
-#if DISABLE_LOG_X
+
+    stop_meas(&ue->dlsch_decoding_stats[proc->thread_id]);
+#if PHYSIM
       printf(" --> Unscrambling for CW1 %5.3f\n",
              (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
       printf("AbsSubframe %d.%d --> ldpc Decoding for CW1 %5.3f\n",
@@ -1155,7 +1129,7 @@ bool nr_ue_dlsch_procedures(PHY_VARS_NR_UE *ue,
             frame_rx%1024, nr_slot_rx,(ue->dlsch_decoding_stats[proc->thread_id].p_time)/(cpuf*1000.0));
 #endif
 
-#endif
+
       LOG_D(PHY,"AbsSubframe %d.%d --> ldpc Decoding for CW1 %5.3f\n",
             frame_rx%1024, nr_slot_rx,(ue->dlsch_decoding_stats[proc->thread_id].p_time)/(cpuf*1000.0));
 
@@ -1378,9 +1352,9 @@ void *UE_thread_slot1_dl_processing(void *arg) {
     }
 
     /**** Slot1 FE Processing ****/
-#if UE_TIMING_TRACE
+
     start_meas(&ue->ue_front_end_per_slot_stat[proc->thread_id][1]);
-#endif
+
     // I- start dl slot1 processing
     // do first symbol of next downlink nr_slot_rx for channel estimation
     /*
@@ -1405,9 +1379,8 @@ void *UE_thread_slot1_dl_processing(void *arg) {
       {
 	//if( (l != pilot0) && (l != pilot1))
 	{
-#if UE_TIMING_TRACE
+
 	  start_meas(&ue->ofdm_demod_stats);
-#endif
 	  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
 	  //printf("AbsSubframe %d.%d FFT slot %d, symbol %d\n", frame_rx,nr_slot_rx,slot1,l);
 	  front_end_fft(ue,
@@ -1416,9 +1389,7 @@ void *UE_thread_slot1_dl_processing(void *arg) {
                         0,
                         0);
 	  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
-#if UE_TIMING_TRACE
 	  stop_meas(&ue->ofdm_demod_stats);
-#endif
 	}
       } // for l=1..l2
 
@@ -1471,14 +1442,13 @@ void *UE_thread_slot1_dl_processing(void *arg) {
     //printf(" [slot1 dl processing] ==> Start LLR Comuptation slot1 for AbsSubframe %d.%d \n", proc->frame_rx, proc->nr_slot_rx);
 
 
-#if UE_TIMING_TRACE
+
     stop_meas(&ue->ue_front_end_per_slot_stat[proc->thread_id][1]);
-#if DISABLE_LOG_X
+#if PHYSIM
     printf("[AbsSFN %d.%d] Slot1: FFT + Channel Estimate + Pdsch Proc Slot0 %5.2f \n",frame_rx,nr_slot_rx,ue->ue_front_end_per_slot_stat[proc->thread_id][1].p_time/(cpuf*1000.0));
 #else
     LOG_D(PHY, "[AbsSFN %d.%d] Slot1: FFT + Channel Estimate + Pdsch Proc Slot0 %5.2f \n",frame_rx,nr_slot_rx,ue->ue_front_end_per_slot_stat[proc->thread_id][1].p_time/(cpuf*1000.0));
 #endif
-#endif
 
 
     //wait until pdcch is decoded
@@ -1496,9 +1466,8 @@ void *UE_thread_slot1_dl_processing(void *arg) {
     //printf("AbsSubframe %d.%d Pdsch Procedure (slot1)\n",frame_rx,nr_slot_rx);
 
 
-#if UE_TIMING_TRACE
     start_meas(&ue->pdsch_procedures_per_slot_stat[proc->thread_id][1]);
-#endif
+
     // start slave thread for Pdsch Procedure (slot1)
     // do procedures for C-RNTI
     uint8_t gNB_id = 0;
@@ -1568,13 +1537,11 @@ void *UE_thread_slot1_dl_processing(void *arg) {
     proc->llr_slot1_available=1;
     //printf("Set available LLR slot1 to 1 AbsSubframe %d.%d \n",frame_rx,nr_slot_rx);
 
-#if UE_TIMING_TRACE
     stop_meas(&ue->pdsch_procedures_per_slot_stat[proc->thread_id][1]);
-#if DISABLE_LOG_X
+#if PHYSIM
     printf("[AbsSFN %d.%d] Slot1: LLR Computation %5.2f \n",frame_rx,nr_slot_rx,ue->pdsch_procedures_per_slot_stat[proc->thread_id][1].p_time/(cpuf*1000.0));
 #else
     LOG_D(PHY, "[AbsSFN %d.%d] Slot1: LLR Computation %5.2f \n",frame_rx,nr_slot_rx,ue->pdsch_procedures_per_slot_stat[proc->thread_id][1].p_time/(cpuf*1000.0));
-#endif
 #endif
 
     if (pthread_mutex_lock(&proc->mutex_slot1_dl_processing) != 0) {
@@ -1717,13 +1684,10 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
                   (ue->symbol_offset+i)%(fp->symbols_per_slot),
                   nr_slot_rx);
 
-#if UE_TIMING_TRACE
+
       start_meas(&ue->dlsch_channel_estimation_stats);
-#endif
       nr_pbch_channel_estimation(ue,proc,gNB_id,nr_slot_rx,(ue->symbol_offset+i)%(fp->symbols_per_slot),i-1,(fp->ssb_index)&7,fp->half_frame_bit);
-#if UE_TIMING_TRACE
       stop_meas(&ue->dlsch_channel_estimation_stats);
-#endif
     }
 
     nr_ue_rsrp_measurements(ue, gNB_id, proc, nr_slot_rx, 0);
@@ -1763,9 +1727,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
 
   for (uint16_t l=0; l<nb_symb_pdcch; l++) {
 
-#if UE_TIMING_TRACE
     start_meas(&ue->ofdm_demod_stats);
-#endif
     nr_slot_fep(ue,
                 proc,
                 l,
@@ -1789,9 +1751,8 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
                                     fp->first_carrier_offset+(pdcch_vars->pdcch_config[n_ss].BWPStart + coreset_start_rb)*12,
                                     coreset_nb_rb);
 
-#if UE_TIMING_TRACE
       stop_meas(&ue->ofdm_demod_stats);
-#endif
+
     }
     dci_cnt = dci_cnt + nr_ue_pdcch_procedures(gNB_id, ue, proc, n_ss);
   }
@@ -1841,10 +1802,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
   curMsg->UE = ue;
   curMsg->ue_sched_mode = ONLY_PUSCH;
   pushTpool(&(get_nrUE_params()->Tpool), newElt);
-
-#if UE_TIMING_TRACE
   start_meas(&ue->generic_stat);
-#endif
   // do procedures for C-RNTI
   int ret_pdsch = 0;
   if (ue->dlsch[proc->thread_id][gNB_id][0]->active == 1) {
@@ -1941,9 +1899,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
     LOG_D(PHY, "DLSCH data reception at nr_slot_rx: %d \n \n", nr_slot_rx);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDSCH_PROC, VCD_FUNCTION_IN);
 
-#if UE_TIMING_TRACE
     start_meas(&ue->dlsch_procedures_stat[proc->thread_id]);
-#endif
 
     if (ret_pdsch >= 0)
       nr_ue_dlsch_procedures(ue,
@@ -1955,10 +1911,8 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
 			   &ue->dlsch_errors[gNB_id],
 			   dlsch_parallel);
 
-
-#if UE_TIMING_TRACE
   stop_meas(&ue->dlsch_procedures_stat[proc->thread_id]);
-#if DISABLE_LOG_X
+#if PHYSIM
   printf("[SFN %d] Slot1:       Pdsch Proc %5.2f\n",nr_slot_rx,ue->pdsch_procedures_stat[proc->thread_id].p_time/(cpuf*1000.0));
   printf("[SFN %d] Slot0 Slot1: Dlsch Proc %5.2f\n",nr_slot_rx,ue->dlsch_procedures_stat[proc->thread_id].p_time/(cpuf*1000.0));
 #else
@@ -1966,7 +1920,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
   LOG_D(PHY, "[SFN %d] Slot0 Slot1: Dlsch Proc %5.2f\n",nr_slot_rx,ue->dlsch_procedures_stat[proc->thread_id].p_time/(cpuf*1000.0));
 #endif
 
-#endif
+
 
   // deactivate dlsch once dlsch proc is done
   ue->dlsch[proc->thread_id][gNB_id][0]->active = 0;
@@ -1975,9 +1929,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
 
  }
 
-#if UE_TIMING_TRACE
 start_meas(&ue->generic_stat);
-#endif
 
 #if 0
 
@@ -2042,8 +1994,8 @@ if (nr_slot_rx==9) {
 
  }
 
-#if UE_TIMING_TRACE
 stop_meas(&ue->generic_stat);
+#if PHYSIM
 printf("after tubo until end of Rx %5.2f \n",ue->generic_stat.p_time/(cpuf*1000.0));
 #endif
 
@@ -2054,14 +2006,12 @@ phy_procedures_emos_UE_RX(ue,slot,gNB_id);
 
 VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_RX, VCD_FUNCTION_OUT);
 
-#if UE_TIMING_TRACE
 stop_meas(&ue->phy_proc_rx[proc->thread_id]);
-#if DISABLE_LOG_X
+#if PHYSIM
 printf("------FULL RX PROC [SFN %d]: %5.2f ------\n",nr_slot_rx,ue->phy_proc_rx[proc->thread_id].p_time/(cpuf*1000.0));
 #else
 LOG_D(PHY, "------FULL RX PROC [SFN %d]: %5.2f ------\n",nr_slot_rx,ue->phy_proc_rx[proc->thread_id].p_time/(cpuf*1000.0));
 #endif
-#endif
 
 //#endif //pdsch
 
diff --git a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c
index 8ad45c97adc1a99f4a79bd4c8a0e53deaf274544..77ac105e140f3776b26e6ecf290c235c20370862 100644
--- a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c
+++ b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.c
@@ -38,7 +38,6 @@
 #include "PHY/defs_nr_UE.h"
 #include <openair1/SCHED/sched_common.h>
 #include <openair1/PHY/NR_UE_TRANSPORT/pucch_nr.h>
-#include "openair2/LAYER2/NR_MAC_UE/mac_proto.h"
 #include "openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h"
 #include <openair1/PHY/impl_defs_nr.h>
 #include <common/utils/nr/nr_common.h>
@@ -58,115 +57,6 @@
 uint8_t nr_is_cqi_TXOp(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t gNB_id);
 uint8_t nr_is_ri_TXOp(PHY_VARS_NR_UE *ue,UE_nr_rxtx_proc_t *proc,uint8_t gNB_id);
 
-/* TS 36.213 Table 9.2.5.2-1: Code rate  corresponding to higher layer parameter PUCCH-F2-maximum-coderate, */
-/* or PUCCH-F3-maximum-coderate, or PUCCH-F4-maximum-coderate */
-/* add one additional element set to 0 for parsing the array until this end */
-/* stored values are code rates * 100 */
-//static const int code_rate_r_time_100[8] = { (0.08 * 100), (0.15 * 100), (0.25*100), (0.35*100), (0.45*100), (0.60*100), (0.80*100), 0 } ;
-
-static float RSRP_meas_mapping_nr[98]
-= {
-  -140,
-    -139,
-    -138,
-    -137,
-    -136,
-    -135,
-    -134,
-    -133,
-    -132,
-    -131,
-    -130,
-    -129,
-    -128,
-    -127,
-    -126,
-    -125,
-    -124,
-    -123,
-    -122,
-    -121,
-    -120,
-    -119,
-    -118,
-    -117,
-    -116,
-    -115,
-    -114,
-    -113,
-    -112,
-    -111,
-    -110,
-    -109,
-    -108,
-    -107,
-    -106,
-    -105,
-    -104,
-    -103,
-    -102,
-    -101,
-    -100,
-    -99,
-    -98,
-    -97,
-    -96,
-    -95,
-    -94,
-    -93,
-    -92,
-    -91,
-    -90,
-    -89,
-    -88,
-    -87,
-    -86,
-    -85,
-    -84,
-    -83,
-    -82,
-    -81,
-    -80,
-    -79,
-    -78,
-    -77,
-    -76,
-    -75,
-    -74,
-    -73,
-    -72,
-    -71,
-    -70,
-    -69,
-    -68,
-    -67,
-    -66,
-    -65,
-    -64,
-    -63,
-    -62,
-    -61,
-    -60,
-    -59,
-    -58,
-    -57,
-    -56,
-    -55,
-    -54,
-    -53,
-    -52,
-    -51,
-    -50,
-    -49,
-    -48,
-    -47,
-    -46,
-    -45,
-    -44,
-    -43
-  }
-  ;
-  
 long
 binary_search_float_nr(
   float elements[],
@@ -394,187 +284,10 @@ void pucch_procedures_ue_nr(PHY_VARS_NR_UE *ue,
 }
 
 
-/*******************************************************************
-*
-* NAME :         check_pucch_format
-*
-* PARAMETERS :   ue context
-*                processing slots of reception/transmission
-*                gNB_id identifier
-*
-* RETURN :       harq process identifier
-*
-* DESCRIPTION :  return tx harq process identifier for given transmission slot
-*                YS 38.213 9.2.2  PUCCH Formats for UCI transmission
-*
-*********************************************************************/
-
-boolean_t check_pucch_format(NR_UE_MAC_INST_t *mac, uint8_t gNB_id, pucch_format_nr_t format_pucch, int nb_symbols_for_tx, int uci_size)
-{
-  pucch_format_nr_t selected_pucch_format;
-  pucch_format_nr_t selected_pucch_format_second;
-  /*NR_SetupRelease_PUCCH_FormatConfig_t *identified_format = NULL;
-
-  switch (format_pucch) {
-    case pucch_format1_nr:
-    if (mac->ULbwp[bwp_id-1]->bwp_Dedicated->pucch_Config->choice.setup->format1 != NULL)
-      identified_format = mac->ULbwp[bwp_id-1]->bwp_Dedicated->pucch_Config->choice.setup->format1;
-    break;
-
-    case pucch_format2_nr:
-    if (mac->ULbwp[bwp_id-1]->bwp_Dedicated->pucch_Config->choice.setup->format2 != NULL)
-      identified_format = mac->ULbwp[bwp_id-1]->bwp_Dedicated->pucch_Config->choice.setup->format2;
-    break;
-
-    case pucch_format3_nr:
-    if (mac->ULbwp[bwp_id-1]->bwp_Dedicated->pucch_Config->choice.setup->format3 != NULL)
-      identified_format = mac->ULbwp[bwp_id-1]->bwp_Dedicated->pucch_Config->choice.setup->format3;
-    break;
-
-    case pucch_format4_nr:
-    if (mac->ULbwp[bwp_id-1]->bwp_Dedicated->pucch_Config->choice.setup->format4 != NULL)
-      identified_format = mac->ULbwp[bwp_id-1]->bwp_Dedicated->pucch_Config->choice.setup->format4;
-    break;
-
-    default:
-    break;
-  }*/
-
- /* if ((identified_format != NULL) && (identified_format->choice.setup->nrofSlots[0] != 1)) {
-    LOG_E(PHY,"PUCCH not implemented multislots transmission : at line %d in function %s of file %s \n", LINE_FILE , __func__, FILE_NAME);
-    return (FALSE);
-  }*/
-
-  if (nb_symbols_for_tx <= 2) {
-    if (uci_size <= 2) {
-      selected_pucch_format = pucch_format0_nr;
-      selected_pucch_format_second = selected_pucch_format;
-    }
-    else {
-      selected_pucch_format = pucch_format2_nr;
-      selected_pucch_format_second = selected_pucch_format;
-    }
-  }
-  else {
-    if (nb_symbols_for_tx >= 4) {
-      if (uci_size <= 2) {
-        selected_pucch_format = pucch_format1_nr;
-        selected_pucch_format_second = selected_pucch_format;
-      }
-      else {
-        selected_pucch_format = pucch_format3_nr;  /* in this case choice can be done between two formats */
-        selected_pucch_format_second = pucch_format4_nr;
-      }
-    }
-    else {
-      LOG_D(PHY,"PUCCH Undefined PUCCH format : set PUCCH to format 4 : at line %d in function %s of file %s \n", LINE_FILE , __func__, FILE_NAME);
-      return (FALSE);
-    }
-  }
-
-  NR_TST_PHY_PRINTF("PUCCH format %d nb symbols total %d uci size %d selected format %d \n", format_pucch, nb_symbols_for_tx, uci_size, selected_pucch_format);
-
-  if (format_pucch != selected_pucch_format) {
-    if (format_pucch != selected_pucch_format_second) {
-      NR_TST_PHY_PRINTF("PUCCH mismatched of selected format: at line %d in function %s of file %s \n", LINE_FILE , __func__, FILE_NAME);
-      LOG_D(PHY,"PUCCH format mismatched of selected format: at line %d in function %s of file %s \n", LINE_FILE , __func__, FILE_NAME);
-      return (FALSE);
-    }
-    else {
-      return (TRUE);
-    }
-  }
-  else {
-    return (TRUE);
-  }
-}
-
-
-
-/*******************************************************************
-*
-* NAME :         get_csi_nr
-* PARAMETERS :   ue context
-*                processing slots of reception/transmission
-*                gNB_id identifier
-*
-* RETURN :       size of csi payload
-*
-* DESCRIPTION :  CSI management is not already implemented
-*                so it has been simulated thank to two functions:
-*                - set_csi_nr
-*                - get_csi_nr
-*
-*********************************************************************/
 
 int      dummy_csi_status = 0;
 uint32_t dummy_csi_payload = 0;
 
-/* FFS TODO_NR code that should be developed */
-
-uint16_t get_nr_csi_bitlen(NR_UE_MAC_INST_t *mac) {
-
-  uint16_t csi_bitlen =0;
-  uint16_t rsrp_bitlen = 0;
-  uint16_t diff_rsrp_bitlen = 0;
-  uint16_t nb_ssbri_cri = 0; 
-  uint16_t cri_ssbri_bitlen = 0;
-  
-  NR_CSI_MeasConfig_t *csi_MeasConfig = mac->cg->spCellConfig->spCellConfigDedicated->csi_MeasConfig->choice.setup;
-  struct NR_CSI_ResourceConfig__csi_RS_ResourceSetList__nzp_CSI_RS_SSB * nzp_CSI_RS_SSB = csi_MeasConfig->csi_ResourceConfigToAddModList->list.array[0]->csi_RS_ResourceSetList.choice.nzp_CSI_RS_SSB;
-
-  uint16_t nb_csi_ssb_report = nzp_CSI_RS_SSB->csi_SSB_ResourceSetList!=NULL ? nzp_CSI_RS_SSB->csi_SSB_ResourceSetList->list.count:0;
-  
-  if (0 != nb_csi_ssb_report){
-	  uint8_t nb_ssb_resources =0;
-	  
-  if (NULL != csi_MeasConfig->csi_ReportConfigToAddModList->list.array[0]->groupBasedBeamReporting.choice.disabled->nrofReportedRS)
-      nb_ssbri_cri = *(csi_MeasConfig->csi_ReportConfigToAddModList->list.array[0]->groupBasedBeamReporting.choice.disabled->nrofReportedRS)+1;
-  else
-      nb_ssbri_cri = 1;
-  
-  nb_ssb_resources = csi_MeasConfig->csi_SSB_ResourceSetToAddModList->list.array[0]->csi_SSB_ResourceList.list.count;
-  
-  if (nb_ssb_resources){
-	cri_ssbri_bitlen =ceil(log2 (nb_ssb_resources));
-	rsrp_bitlen = 7;
-	diff_rsrp_bitlen = 4;
-	}
-  else{
-	cri_ssbri_bitlen =0;
-	rsrp_bitlen = 0;
-	diff_rsrp_bitlen = 0;
-	}
-  
-  csi_bitlen = ((cri_ssbri_bitlen * nb_ssbri_cri) + rsrp_bitlen +(diff_rsrp_bitlen *(nb_ssbri_cri -1 ))) *nb_csi_ssb_report;
-               
-  //printf("get csi bitlen %d nb_ssbri_cri %d nb_csi_report %d nb_resources %d\n", csi_bitlen,nb_ssbri_cri ,nb_csi_ssb_report, nb_ssb_resources);
-  }
-  return csi_bitlen;
-}
-
-int get_csi_nr(NR_UE_MAC_INST_t *mac, PHY_VARS_NR_UE *ue, uint8_t gNB_id, uint32_t *csi_payload)
-{
-  VOID_PARAMETER ue;
-  VOID_PARAMETER gNB_id;
-  float rsrp_db[7];
-  int nElem = 98;
-  int rsrp_offset = 17;
-  int csi_status = 0;
-  
-  csi_status = get_nr_csi_bitlen(mac);
-  rsrp_db[0] = get_nr_RSRP(0,0,0);
-
-
-  if (csi_status == 0) {
-    *csi_payload = 0;
-  }
-  else {
-    *csi_payload = binary_search_float_nr(RSRP_meas_mapping_nr,nElem, rsrp_db[0]) + rsrp_offset;
-  }
-
-  return (csi_status);
-}
 
 /* FFS TODO_NR code that should be removed */
 
diff --git a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.h b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.h
index 101b80fb8d2d25274df9730dabb8d28a74c7b113..37e24f43bcfa60bef4fcd794ee1771788606800e 100644
--- a/openair1/SCHED_NR_UE/pucch_uci_ue_nr.h
+++ b/openair1/SCHED_NR_UE/pucch_uci_ue_nr.h
@@ -41,8 +41,6 @@
 /************** INCLUDE *******************************************/
 
 #include "PHY/defs_nr_UE.h"
-#include "openair2/LAYER2/NR_MAC_UE/mac_proto.h"
-#include "openair2/LAYER2/NR_MAC_UE/mac_defs.h"
 #include "RRC/NR_UE/rrc_proto.h"
 
 #ifdef DEFINE_VARIABLES_PUCCH_UE_NR_H
@@ -65,31 +63,6 @@ void pucch_procedures_ue_nr(PHY_VARS_NR_UE *ue,
                             uint8_t gNB_id,
                             UE_nr_rxtx_proc_t *proc);
 
-/** \brief This function check pucch format
-    @param ue context
-    @param gNB_id identity
-    @param format_pucch pucch format
-    @param nb_symbols_for_tx number of symbols for pucch transmission
-    @param uci size number of uci bits
-    @returns TRUE pucch format matched uci size and constraints, FALSE invalid pucch format */
-
-boolean_t check_pucch_format(NR_UE_MAC_INST_t *mac, uint8_t gNB_id, pucch_format_nr_t format_pucch, int nb_symbols_for_tx, 
-                             int uci_size);
-
-/** \brief This function reads current CSI
-    @param ue context
-    @param gNB_id identity
-    @param csi_payload is updated with CSI
-    @returns number of bits of CSI */
-
-int get_csi_nr(NR_UE_MAC_INST_t *mac, PHY_VARS_NR_UE *ue, uint8_t gNB_id, uint32_t *csi_payload);
-
-/** \brief This dummy function sets current CSI for simulation
-    @param csi_status
-    @param csi_payload is updated with CSI
-    @returns none */
-    
-uint16_t get_nr_csi_bitlen(NR_UE_MAC_INST_t *mac);
 
 void set_csi_nr(int csi_status, uint32_t csi_payload);
 
diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c
index c879eadddd7cc74738aabdf96d290527e9fa29ba..c9d17aaf843f60b67512c285d0d2c44a5c8df280 100644
--- a/openair1/SIMULATION/NR_PHY/dlsim.c
+++ b/openair1/SIMULATION/NR_PHY/dlsim.c
@@ -27,6 +27,7 @@
 #include <unistd.h>
 #include "common/ran_context.h"
 #include "common/config/config_userapi.h"
+#include "common/utils/nr/nr_common.h"
 #include "common/utils/LOG/log.h"
 #include "LAYER2/NR_MAC_gNB/nr_mac_gNB.h"
 #include "LAYER2/NR_MAC_UE/mac_defs.h"
@@ -429,7 +430,9 @@ int main(int argc, char **argv)
 
   FILE *scg_fd=NULL;
   
-  while ((c = getopt (argc, argv, "f:hA:pf:g:in:s:S:t:x:y:z:M:N:F:GR:dPIL:Ea:b:d:e:m:w:T:U:q")) != -1) {
+
+  while ((c = getopt (argc, argv, "f:hA:pf:g:in:s:S:t:x:y:z:M:N:F:GR:dPIL:Ea:b:D:e:m:w:T:U:q")) != -1) {
+
     switch (c) {
     case 'f':
       scg_fd = fopen(optarg,"r");
@@ -595,7 +598,7 @@ int main(int argc, char **argv)
     case 'b':
       g_rbSize = atoi(optarg);
       break;
-    case 'd':
+    case 'D':
       dlsch_threads = atoi(optarg);
       break;    
     case 'e':
@@ -668,7 +671,7 @@ int main(int argc, char **argv)
       printf("-U Change DMRS Config, arguments list DMRS TYPE{0=A,1=B} DMRS AddPos{0:2} DMRS ConfType{1:2}, e.g. -U 3 0 2 1 \n");
       printf("-P Print DLSCH performances\n");
       printf("-w Write txdata to binary file (one frame)\n");
-      printf("-d number of dlsch threads, 0: no dlsch parallelization\n");
+      printf("-D number of dlsch threads, 0: no dlsch parallelization\n");
       exit (-1);
       break;
     }
@@ -685,7 +688,7 @@ int main(int argc, char **argv)
 
   if (snr1set==0)
     snr1 = snr0+10;
-  init_dlsch_tpool(dlsch_threads);
+
 
 
   RC.gNB = (PHY_VARS_gNB**) malloc(sizeof(PHY_VARS_gNB *));
@@ -981,7 +984,11 @@ int main(int argc, char **argv)
   reset_meas(&msgDataTx->phy_proc_tx);
   gNB->phy_proc_tx_0 = &msgDataTx->phy_proc_tx;
   pushTpool(gNB->threadPool,msgL1Tx);
-
+  if (dlsch_threads ) { 
+    init_dlsch_tpool(dlsch_threads);
+    pthread_t dlsch0_threads;
+    threadCreate(&dlsch0_threads, dlsch_thread, (void *)UE, "DLthread", -1, OAI_PRIORITY_RT_MAX-1);
+  }
   for (SNR = snr0; SNR < snr1; SNR += .2) {
 
     varArray_t *table_tx=initVarArray(1000,sizeof(double));
diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c
index 8f4f227f6ca95ef3ce94747d0e501947b4428fd7..1169b8ecd8e5e18b67a1157717c7f1bb1f4ebb7f 100644
--- a/openair1/SIMULATION/NR_PHY/pbchsim.c
+++ b/openair1/SIMULATION/NR_PHY/pbchsim.c
@@ -28,6 +28,7 @@
 #include "common/config/config_userapi.h"
 #include "common/utils/LOG/log.h"
 #include "common/ran_context.h" 
+#include "common/utils/nr/nr_common.h"
 #include "PHY/types.h"
 #include "PHY/defs_nr_common.h"
 #include "PHY/defs_nr_UE.h"
diff --git a/openair1/SIMULATION/NR_PHY/prachsim.c b/openair1/SIMULATION/NR_PHY/prachsim.c
index 6167c809ff3daeac997367e018de35ba27942a92..a33713234c174ecdbd1f75bdb927c2bdde766f87 100644
--- a/openair1/SIMULATION/NR_PHY/prachsim.c
+++ b/openair1/SIMULATION/NR_PHY/prachsim.c
@@ -47,6 +47,7 @@
 #include "nr_unitary_defs.h"
 #include "OCG_vars.h"
 #include <openair2/LAYER2/MAC/mac_vars.h>
+#include <openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h>
 #include <openair2/RRC/LTE/rrc_vars.h>
 #include <executables/softmodem-common.h>
 #include <openair2/RRC/NR_UE/rrc_defs.h>
diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c
index 90ec3be3def20f2c3e4f8cac1cf2d3ab4b2a3c48..ef4367b752006fb6417b25f6daf3677ec520f73b 100644
--- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c
+++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c
@@ -359,7 +359,6 @@ void get_info_from_tda_tables(int default_abc,
 }
 
 const char *prachfmt[]={"0","1","2","3", "A1","A2","A3","B1","B4","C0","C2","A1/B1","A2/B2","A3/B3"};
-const char *duplex_mode[]={"FDD","TDD"};
 
 uint16_t get_NCS(uint8_t index, uint16_t format0, uint8_t restricted_set_config) {
 
@@ -1573,60 +1572,6 @@ int get_nr_prach_occasion_info_from_index(uint8_t index,
 }
 
 
-uint8_t get_nr_prach_duration(uint8_t prach_format){
-
-  switch(prach_format){
-
-      case 0:  // format 0
-         return 0;
-
-      case 1:  // format 1
-         return 0;
-
-      case 2:  // format 2
-         return 0;
-
-      case 3:  // format 3
-         return 0;
-
-      case 4:  // format A1
-         return 2;
-
-      case 5:  // format A2
-         return 4;
-
-      case 6:  // format A3
-         return 6;
-
-      case 7:  // format B1
-         return 2;
-
-      case 8:  // format B4
-         return 12;
-
-      case 9:  // format C0
-         return 2;
-
-      case 10:  // format C2
-         return 6;
-
-      case 11:  // format A1/B1
-         return 2;
-
-      case 12:  // format A2/B2
-         return 4;
-
-      case 13:  // format A3/B3
-         return 6;
-
-      default :
-         AssertFatal(1==0,"Invalid Prach format\n");
-         break;
-
-  }
-
-}
-
 int get_nr_prach_info_from_index(uint8_t index,
                                  int frame,
                                  int slot,
@@ -1981,170 +1926,6 @@ int32_t table_6_4_1_1_3_4_pusch_dmrs_positions_l [12][8] = {
 {0,         3072,          -1,         -1,          3,       1539,        -1,         -1},       //14              // (DMRS l' position)
 };
 
-// Returns the corresponding row index of the NR table
-int get_nr_table_idx(int nr_bandP, uint8_t scs_index)
-{
-  int i, j;
-  int scs_khz = 15 << scs_index;
-  int supplementary_bands[] = {29,75,76,80,81,82,83,84,86,89,95};
-  size_t s = sizeof(supplementary_bands)/sizeof(supplementary_bands[0]);
-
-  for(j = 0; j < s; j++){
-    if (nr_bandP == supplementary_bands[j])
-      AssertFatal(0 == 1, "Band %d is a supplementary band (%d). This is not supported yet.\n", nr_bandP, supplementary_bands[j]);
-  }
-
-  AssertFatal(nr_bandP <= nr_bandtable[nr_bandtable_size-1].band, "NR band %d exceeds NR bands table maximum limit %d\n", nr_bandP, nr_bandtable[nr_bandtable_size-1].band);
-  for (i = 0; i < nr_bandtable_size && nr_bandtable[i].band != nr_bandP; i++);
-
-  // selection of correct Deltaf raster according to SCS
-  if ((nr_bandtable[i].deltaf_raster != 100) && (nr_bandtable[i].deltaf_raster != scs_khz))
-    i++;
-
-  LOG_D(PHY, "NR band table index %d (Band %d, dl_min %lu, ul_min %lu)\n", i, nr_bandtable[i].band, nr_bandtable[i].dl_min,nr_bandtable[i].ul_min);
-
-  return i;
-}
-
-// Computes the duplex spacing (either positive or negative) in KHz
-int32_t get_delta_duplex(int nr_bandP, uint8_t scs_index)
-{
-  int nr_table_idx = get_nr_table_idx(nr_bandP, scs_index);
-
-  int32_t delta_duplex = (nr_bandtable[nr_table_idx].ul_min - nr_bandtable[nr_table_idx].dl_min);
-
-  LOG_I(NR_MAC, "NR band duplex spacing is %d KHz (nr_bandtable[%d].band = %d)\n", delta_duplex, nr_table_idx, nr_bandtable[nr_table_idx].band);
-
-  return delta_duplex;
-}
-
-lte_frame_type_t get_frame_type(uint16_t current_band, uint8_t scs_index)
-{
-  lte_frame_type_t current_type;
-  int32_t delta_duplex = get_delta_duplex(current_band, scs_index);
-
-  if (delta_duplex == 0)
-    current_type = TDD;
-  else
-    current_type = FDD;
-
-  LOG_I(NR_MAC, "NR band %d, duplex mode %s, duplex spacing = %d KHz\n", current_band, duplex_mode[current_type], delta_duplex);
-
-  return current_type;
-}
-
-uint16_t config_bandwidth(int mu, int nb_rb, int nr_band)
-{
-
-  if (nr_band < 100)  { //FR1
-   switch(mu) {
-    case 0 :
-      if (nb_rb<=25)
-        return 5; 
-      if (nb_rb<=52)
-        return 10;
-      if (nb_rb<=79)
-        return 15;
-      if (nb_rb<=106)
-        return 20;
-      if (nb_rb<=133)
-        return 25;
-      if (nb_rb<=160)
-        return 30;
-      if (nb_rb<=216)
-        return 40;
-      if (nb_rb<=270)
-        return 50;
-      AssertFatal(1==0,"Number of DL resource blocks %d undefined for mu %d and band %d\n", nb_rb, mu, nr_band);
-      break;
-    case 1 :
-      if (nb_rb<=11)
-        return 5; 
-      if (nb_rb<=24)
-        return 10;
-      if (nb_rb<=38)
-        return 15;
-      if (nb_rb<=51)
-        return 20;
-      if (nb_rb<=65)
-        return 25;
-      if (nb_rb<=78)
-        return 30;
-      if (nb_rb<=106)
-        return 40;
-      if (nb_rb<=133)
-        return 50;
-      if (nb_rb<=162)
-        return 60;
-      if (nb_rb<=189)
-        return 70;
-      if (nb_rb<=217)
-        return 80;
-      if (nb_rb<=245)
-        return 90;
-      if (nb_rb<=273)
-        return 100;
-      AssertFatal(1==0,"Number of DL resource blocks %d undefined for mu %d and band %d\n", nb_rb, mu, nr_band);
-      break;
-    case 2 :
-      if (nb_rb<=11)
-        return 10; 
-      if (nb_rb<=18)
-        return 15;
-      if (nb_rb<=24)
-        return 20;
-      if (nb_rb<=31)
-        return 25;
-      if (nb_rb<=38)
-        return 30;
-      if (nb_rb<=51)
-        return 40;
-      if (nb_rb<=65)
-        return 50;
-      if (nb_rb<=79)
-        return 60;
-      if (nb_rb<=93)
-        return 70;
-      if (nb_rb<=107)
-        return 80;
-      if (nb_rb<=121)
-        return 90;
-      if (nb_rb<=135)
-        return 100;
-      AssertFatal(1==0,"Number of DL resource blocks %d undefined for mu %d and band %d\n", nb_rb, mu, nr_band);
-      break;
-    default:
-      AssertFatal(1==0,"Numerology %d undefined for band %d in FR1\n", mu,nr_band);
-   }
-  }
-  else {
-   switch(mu) {
-    case 2 :
-      if (nb_rb<=66)
-        return 50;
-      if (nb_rb<=132)
-        return 100;
-      if (nb_rb<=264)
-        return 200;
-      AssertFatal(1==0,"Number of DL resource blocks %d undefined for mu %d and band %d\n", nb_rb, mu, nr_band);
-      break;
-    case 3 :
-      if (nb_rb<=32)
-        return 50;
-      if (nb_rb<=66)
-        return 100;
-      if (nb_rb<=132)
-        return 200;
-      if (nb_rb<=264)
-        return 400;
-      AssertFatal(1==0,"Number of DL resource blocks %d undefined for mu %d and band %d\n", nb_rb, mu, nr_band);
-      break;
-    default:
-      AssertFatal(1==0,"Numerology %d undefined for band %d in FR1\n", mu,nr_band);
-   }
-  }
-
-}
 
 void get_delta_arfcn(int i, uint32_t nrarfcn, uint64_t N_OFFs){
 
@@ -2516,13 +2297,7 @@ static inline uint8_t get_table_idx(uint8_t mcs_table, uint8_t dci_format, uint8
     return 1;
 }
 
-int get_num_dmrs(uint16_t dmrs_mask ) {
-
-  int num_dmrs=0;
 
-  for (int i=0;i<16;i++) num_dmrs+=((dmrs_mask>>i)&1);
-  return(num_dmrs);
-}
 /* returns the total DMRS symbols in a slot*/
 uint8_t get_num_dmrs_symbols(NR_PDSCH_Config_t *pdsch_Config,int dmrs_TypeA_Position,int NrOfSymbols, int startSymbol, int mappingtype){
   return get_num_dmrs(fill_dmrs_mask(pdsch_Config,dmrs_TypeA_Position,NrOfSymbols, startSymbol, mappingtype));
@@ -3607,13 +3382,23 @@ void get_type0_PDCCH_CSS_config_parameters(NR_Type0_PDCCH_CSS_config_t *type0_PD
                                            uint16_t ssb_start_symbol,
                                            NR_SubcarrierSpacing_t scs_ssb,
                                            frequency_range_t frequency_range,
+                                           int nr_band,
                                            uint32_t ssb_index,
                                            uint32_t ssb_period,
                                            uint32_t ssb_offset_point_a) {
 
   NR_SubcarrierSpacing_t scs_pdcch;
 
-  channel_bandwidth_t min_channel_bw = bw_10MHz; // TODO remove hardcoding and implement Table 5.3.5-1 in 38.104
+  channel_bandwidth_t min_channel_bw;
+
+  // according to Table 5.3.5-1 in 38.104
+  // band 79 is the only one which minimum is 40
+  // for all the other channels it is either 10 or 5
+  // and there is no difference between the two for this implementation so it is set it to 10
+  if (nr_band == 79)
+    min_channel_bw = bw_40MHz;
+  else
+    min_channel_bw = bw_10MHz;
 
   if (frequency_range == FR2) {
     if(mib->subCarrierSpacingCommon == NR_MIB__subCarrierSpacingCommon_scs15or60)
diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h
index e107553117d5dbe60e3b09f6f34be93b70912a93..ced29f066f14a93123597b8633114476daa6fba6 100644
--- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h
+++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h
@@ -37,12 +37,6 @@
 #include "nr_mac.h"
 #include "openair1/PHY/impl_defs_nr.h"
 
-uint16_t config_bandwidth(int mu, int nb_rb, int nr_band);
-
-lte_frame_type_t get_frame_type(uint16_t nr_bandP, uint8_t scs_index);
-
-int32_t get_delta_duplex(int nr_bandP, uint8_t scs_index);
-
 uint64_t from_nrarfcn(int nr_bandP, uint8_t scs_index, uint32_t dl_nrarfcn);
 
 uint32_t to_nrarfcn(int nr_bandP, uint64_t dl_CarrierFreq, uint8_t scs_index, uint32_t bw);
@@ -97,8 +91,6 @@ int get_nr_prach_occasion_info_from_index(uint8_t index,
                                  uint16_t *N_RA_sfn,
                                  uint8_t *max_association_period);
 
-uint8_t get_nr_prach_duration(uint8_t prach_format);
-
 uint8_t get_pusch_mcs_table(long *mcs_Table,
                             int is_tp,
                             int dci_format,
@@ -121,7 +113,6 @@ int64_t *get_prach_config_info(frequency_range_t freq_range,
 
 uint16_t get_NCS(uint8_t index, uint16_t format, uint8_t restricted_set_config);
 
-int get_num_dmrs(uint16_t dmrs_mask );
 uint8_t get_l0_ul(uint8_t mapping_type, uint8_t dmrs_typeA_position);
 int32_t get_l_prime(uint8_t duration_in_symbols, uint8_t mapping_type, pusch_dmrs_AdditionalPosition_t additional_pos, pusch_maxLength_t pusch_maxLength, uint8_t start_symbolt, uint8_t dmrs_typeA_position);
 
@@ -136,6 +127,7 @@ void get_type0_PDCCH_CSS_config_parameters(NR_Type0_PDCCH_CSS_config_t *type0_PD
                                            uint16_t ssb_start_symbol,
                                            NR_SubcarrierSpacing_t scs_ssb,
                                            frequency_range_t frequency_range,
+                                           int nr_band,
                                            uint32_t ssb_index,
                                            uint32_t ssb_period,
                                            uint32_t ssb_offset_point_a);
diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h
index 30b87a056e7bc808017540ec87ab597a55988acb..a078e385dcb662c7d803025a556c4d80a108392b 100755
--- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h
+++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h
@@ -270,23 +270,6 @@ void nr_ue_configure_pucch(NR_UE_MAC_INST_t *mac,
                            fapi_nr_ul_config_pucch_pdu *pucch_pdu,
                            int O_SR, int O_ACK, int O_CSI);
 
-/** \brief Function for UE/PHY to compute PUSCH transmit power in power-control procedure.
-    @param Mod_id Module id of UE
-    @returns Po_NOMINAL_PUSCH (PREAMBLE_RECEIVED_TARGET_POWER+DELTA_PREAMBLE
-*/
-int nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_t module_idP, uint8_t CC_id);
-
-/** \brief Function to compute DELTA_PREAMBLE from 38.321 subclause 7.3
-   (for RA power ramping procedure and Msg3 PUSCH power control policy)
-    @param Mod_id Module id of UE
-    @returns DELTA_PREAMBLE
-*/
-int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id, uint16_t prach_format);
-
-/** \brief Function to compute configured maximum output power according to clause 6.2.4 of 3GPP TS 38.101-1 version 16.5.0 Release 16
-    @param Mod_id Module id of UE
-*/
-long nr_get_Pcmax(module_id_t mod_id);
 
 /* Random Access */
 
@@ -390,10 +373,6 @@ int8_t nr_ue_process_dci_freq_dom_resource_assignment(nfapi_nr_ue_pusch_pdu_t *p
 void config_dci_pdu(NR_UE_MAC_INST_t *mac, fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15, fapi_nr_dl_config_request_t *dl_config, int rnti_type, int ss_id);
 void fill_dci_search_candidates(NR_SearchSpace_t *ss,fapi_nr_dl_config_dci_dl_pdu_rel15_t *rel15);
 
-void get_num_re_dmrs(nfapi_nr_ue_pusch_pdu_t *pusch_pdu,
-                     uint8_t *nb_dmrs_re_per_rb,
-                     uint16_t *number_dmrs_symbols);
-
 void build_ssb_to_ro_map(NR_UE_MAC_INST_t *mac);
 
 void config_bwp_ue(NR_UE_MAC_INST_t *mac, uint16_t *bwp_ind, uint8_t *dci_format);
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c
index 7f1011fb28feaed58da6519eb692ae8fab985728..eaaa5f5f7222777acbdcf35cee5a18897f7fac6c 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.c
@@ -35,150 +35,9 @@
 #include "mac_defs.h"
 #include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h"
 #include "LAYER2/NR_MAC_UE/mac_proto.h"
+#include "LAYER2/NR_MAC_UE/nr_l1_helpers.h"
 #include "NR_P-Max.h"
 
-/* TS 38.321 subclause 7.3 - return DELTA_PREAMBLE values in dB */
-int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id, uint16_t prach_format){
-
-  NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
-  NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = (mac->scc!=NULL) ? 
-    mac->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup:
-    mac->scc_SIB->uplinkConfigCommon->initialUplinkBWP.rach_ConfigCommon->choice.setup;
-  NR_SubcarrierSpacing_t scs = *nr_rach_ConfigCommon->msg1_SubcarrierSpacing;
-  int prach_sequence_length = (mac->scc!=NULL)?(mac->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup->prach_RootSequenceIndex.present - 1) : (mac->scc_SIB->uplinkConfigCommon->initialUplinkBWP.rach_ConfigCommon->choice.setup->prach_RootSequenceIndex.present-1);
-  uint8_t prachConfigIndex, mu;
-
-  AssertFatal(CC_id == 0, "Transmission on secondary CCs is not supported yet\n");
-
-  // SCS configuration from msg1_SubcarrierSpacing and table 4.2-1 in TS 38.211
-
-  switch (scs){
-    case NR_SubcarrierSpacing_kHz15:
-    mu = 0;
-    break;
-
-    case NR_SubcarrierSpacing_kHz30:
-    mu = 1;
-    break;
-
-    case NR_SubcarrierSpacing_kHz60:
-    mu = 2;
-    break;
-
-    case NR_SubcarrierSpacing_kHz120:
-    mu = 3;
-    break;
-
-    case NR_SubcarrierSpacing_kHz240:
-    mu = 4;
-    break;
-
-    case NR_SubcarrierSpacing_spare3:
-    mu = 5;
-    break;
-
-    case NR_SubcarrierSpacing_spare2:
-    mu = 6;
-    break;
-
-    case NR_SubcarrierSpacing_spare1:
-    mu = 7;
-    break;
-
-    default:
-    AssertFatal(1 == 0,"Unknown msg1_SubcarrierSpacing %lu\n", scs);
-  }
-
-  // Preamble formats given by prach_ConfigurationIndex and tables 6.3.3.2-2 and 6.3.3.2-2 in TS 38.211
-
-  prachConfigIndex = nr_rach_ConfigCommon->rach_ConfigGeneric.prach_ConfigurationIndex;
-
-  if (prach_sequence_length == 0) {
-    AssertFatal(prach_format < 4, "Illegal PRACH format %d for sequence length 839\n", prach_format);
-    switch (prach_format) {
-
-      // long preamble formats
-      case 0:
-      case 3:
-      return  0;
-
-      case 1:           
-      return -3;
-
-      case 2:
-      return -6;
-    }
-  } else {
-    switch (prach_format) { // short preamble formats
-      case 0:
-      case 3:
-      return 8 + 3*mu;
-
-      case 1:
-      case 4:
-      case 8:
-      return 5 + 3*mu;
-
-      case 2:
-      case 5:
-      return 3 + 3*mu;
-
-      case 6:
-      return 3*mu;
-
-      case 7:
-      return 5 + 3*mu;
-
-      default:
-      AssertFatal(1 == 0, "[UE %d] ue_procedures.c: FATAL, Illegal preambleFormat %d, prachConfigIndex %d\n", mod_id, prach_format, prachConfigIndex);
-    }
-  }
-  return 0;
-}
-
-// TS 38.321 subclause 5.1.3 - RA preamble transmission - ra_PREAMBLE_RECEIVED_TARGET_POWER configuration
-// Measurement units:
-// - preambleReceivedTargetPower      dBm (-202..-60, 2 dBm granularity)
-// - delta_preamble                   dB
-// - RA_PREAMBLE_POWER_RAMPING_STEP   dB
-// - POWER_OFFSET_2STEP_RA            dB
-// returns receivedTargerPower in dBm
-int nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_t mod_id, uint8_t CC_id){
-  
-  NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
-  int8_t receivedTargerPower;
-  int8_t delta_preamble;
-
-  NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = (mac->scc != NULL) ? mac->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup: mac->scc_SIB->uplinkConfigCommon->initialUplinkBWP.rach_ConfigCommon->choice.setup;
-  long preambleReceivedTargetPower = nr_rach_ConfigCommon->rach_ConfigGeneric.preambleReceivedTargetPower;
-  delta_preamble = nr_get_DELTA_PREAMBLE(mod_id, CC_id, prach_resources->prach_format);
-
-  receivedTargerPower = preambleReceivedTargetPower + delta_preamble + (prach_resources->RA_PREAMBLE_POWER_RAMPING_COUNTER - 1) * prach_resources->RA_PREAMBLE_POWER_RAMPING_STEP + prach_resources->POWER_OFFSET_2STEP_RA;
-
-  LOG_D(MAC, "In %s: receivedTargerPower is %d dBm \n", __FUNCTION__, receivedTargerPower);
-
-  return receivedTargerPower;
-}
-
-void get_num_re_dmrs(nfapi_nr_ue_pusch_pdu_t *pusch_pdu,
-                     uint8_t *nb_dmrs_re_per_rb,
-                     uint16_t *number_dmrs_symbols){
-
-  int start_symbol          = pusch_pdu->start_symbol_index;
-  uint8_t number_of_symbols = pusch_pdu->nr_of_symbols;
-  uint16_t ul_dmrs_symb_pos = pusch_pdu->ul_dmrs_symb_pos;
-  uint8_t dmrs_type         = pusch_pdu->dmrs_config_type;
-  uint8_t cdm_grps_no_data  = pusch_pdu->num_dmrs_cdm_grps_no_data;
-
-  *number_dmrs_symbols = 0;
-  for (int i = start_symbol; i < start_symbol + number_of_symbols; i++) {
-    if((ul_dmrs_symb_pos >> i) & 0x01)
-      *number_dmrs_symbols += 1;
-  }
-
-  *nb_dmrs_re_per_rb = ((dmrs_type == pusch_dmrs_type1) ? 6:4)*cdm_grps_no_data;
-
-}
 
 // Implementation of 6.2.4 Configured ransmitted power
 // 3GPP TS 38.101-1 version 16.5.0 Release 16
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.h b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.h
new file mode 100755
index 0000000000000000000000000000000000000000..8b3f00af43d2db6988d5e717177f49438f1f15ef
--- /dev/null
+++ b/openair2/LAYER2/NR_MAC_UE/nr_l1_helpers.h
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/** \brief Function to compute configured maximum output power according to clause 6.2.4 of 3GPP TS 38.101-1 version 16.5.0 Release 16
+    @param Mod_id Module id of UE
+*/
+long nr_get_Pcmax(module_id_t mod_id);
+/** @}*/
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
index 83784634fcf74b4c7aee68f76ad7c3ce722c9746..c3c195a64ab4e32000f44f10b1576a1f10155564 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c
@@ -30,23 +30,18 @@
  * \warning
  */
 
-/* Tools */
-#include "SIMULATION/TOOLS/sim.h"	// for taus
-
 /* RRC */
 #include "NR_RACH-ConfigCommon.h"
 #include "RRC/NR_UE/rrc_proto.h"
 
 /* PHY */
-#include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
-#include "PHY/defs_common.h"
-#include "PHY/defs_nr_common.h"
 #include "PHY/NR_UE_ESTIMATION/nr_estimation.h"
 
 /* MAC */
 #include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h"
 #include "NR_MAC_COMMON/nr_mac.h"
 #include "LAYER2/NR_MAC_UE/mac_proto.h"
+#include "LAYER2/NR_MAC_UE/nr_l1_helpers.h"
 
 #include <executables/softmodem-common.h>
 
@@ -198,6 +193,130 @@ void init_RA(module_id_t mod_id,
   }
 }
 
+
+/* TS 38.321 subclause 7.3 - return DELTA_PREAMBLE values in dB */
+int8_t nr_get_DELTA_PREAMBLE(module_id_t mod_id, int CC_id, uint16_t prach_format){
+
+  NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
+  NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = (mac->scc!=NULL) ?
+    mac->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup:
+    mac->scc_SIB->uplinkConfigCommon->initialUplinkBWP.rach_ConfigCommon->choice.setup;
+  NR_SubcarrierSpacing_t scs = *nr_rach_ConfigCommon->msg1_SubcarrierSpacing;
+  int prach_sequence_length = (mac->scc!=NULL)?(mac->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup->prach_RootSequenceIndex.present - 1) : (mac->scc_SIB->uplinkConfigCommon->initialUplinkBWP.rach_ConfigCommon->choice.setup->prach_RootSequenceIndex.present-1);
+  uint8_t prachConfigIndex, mu;
+
+  AssertFatal(CC_id == 0, "Transmission on secondary CCs is not supported yet\n");
+
+  // SCS configuration from msg1_SubcarrierSpacing and table 4.2-1 in TS 38.211
+
+  switch (scs){
+    case NR_SubcarrierSpacing_kHz15:
+    mu = 0;
+    break;
+
+    case NR_SubcarrierSpacing_kHz30:
+    mu = 1;
+    break;
+
+    case NR_SubcarrierSpacing_kHz60:
+    mu = 2;
+    break;
+
+    case NR_SubcarrierSpacing_kHz120:
+    mu = 3;
+    break;
+
+    case NR_SubcarrierSpacing_kHz240:
+    mu = 4;
+    break;
+
+    case NR_SubcarrierSpacing_spare3:
+    mu = 5;
+    break;
+
+    case NR_SubcarrierSpacing_spare2:
+    mu = 6;
+    break;
+
+    case NR_SubcarrierSpacing_spare1:
+    mu = 7;
+    break;
+
+    default:
+    AssertFatal(1 == 0,"Unknown msg1_SubcarrierSpacing %lu\n", scs);
+  }
+
+  // Preamble formats given by prach_ConfigurationIndex and tables 6.3.3.2-2 and 6.3.3.2-2 in TS 38.211
+
+  prachConfigIndex = nr_rach_ConfigCommon->rach_ConfigGeneric.prach_ConfigurationIndex;
+
+  if (prach_sequence_length == 0) {
+    AssertFatal(prach_format < 4, "Illegal PRACH format %d for sequence length 839\n", prach_format);
+    switch (prach_format) {
+
+      // long preamble formats
+      case 0:
+      case 3:
+      return  0;
+
+      case 1:
+      return -3;
+
+      case 2:
+      return -6;
+    }
+  } else {
+    switch (prach_format) { // short preamble formats
+      case 0:
+      case 3:
+      return 8 + 3*mu;
+
+      case 1:
+      case 4:
+      case 8:
+      return 5 + 3*mu;
+
+      case 2:
+      case 5:
+      return 3 + 3*mu;
+
+      case 6:
+      return 3*mu;
+
+      case 7:
+      return 5 + 3*mu;
+
+      default:
+      AssertFatal(1 == 0, "[UE %d] ue_procedures.c: FATAL, Illegal preambleFormat %d, prachConfigIndex %d\n", mod_id, prach_format, prachConfigIndex);
+    }
+  }
+  return 0;
+}
+
+// TS 38.321 subclause 5.1.3 - RA preamble transmission - ra_PREAMBLE_RECEIVED_TARGET_POWER configuration
+// Measurement units:
+// - preambleReceivedTargetPower      dBm (-202..-60, 2 dBm granularity)
+// - delta_preamble                   dB
+// - RA_PREAMBLE_POWER_RAMPING_STEP   dB
+// - POWER_OFFSET_2STEP_RA            dB
+// returns receivedTargerPower in dBm
+int nr_get_Po_NOMINAL_PUSCH(NR_PRACH_RESOURCES_t *prach_resources, module_id_t mod_id, uint8_t CC_id){
+
+  NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
+  int8_t receivedTargerPower;
+  int8_t delta_preamble;
+
+  NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon = (mac->scc != NULL) ? mac->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup: mac->scc_SIB->uplinkConfigCommon->initialUplinkBWP.rach_ConfigCommon->choice.setup;
+  long preambleReceivedTargetPower = nr_rach_ConfigCommon->rach_ConfigGeneric.preambleReceivedTargetPower;
+  delta_preamble = nr_get_DELTA_PREAMBLE(mod_id, CC_id, prach_resources->prach_format);
+
+  receivedTargerPower = preambleReceivedTargetPower + delta_preamble + (prach_resources->RA_PREAMBLE_POWER_RAMPING_COUNTER - 1) * prach_resources->RA_PREAMBLE_POWER_RAMPING_STEP + prach_resources->POWER_OFFSET_2STEP_RA;
+
+  LOG_D(MAC, "In %s: receivedTargerPower is %d dBm \n", __FUNCTION__, receivedTargerPower);
+
+  return receivedTargerPower;
+}
+
 void ssb_rach_config(RA_config_t *ra, NR_PRACH_RESOURCES_t *prach_resources, NR_RACH_ConfigCommon_t *nr_rach_ConfigCommon, fapi_nr_ul_config_prach_pdu *prach_pdu){
 
   // Determine the SSB to RACH mapping ratio
@@ -280,6 +399,10 @@ void ra_preambles_config(NR_PRACH_RESOURCES_t *prach_resources, NR_UE_MAC_INST_t
   int PLThreshold = 0;
   long deltaPreamble_Msg3 = 0;
   uint8_t noGroupB = 0;
+  // Random seed generation
+  long long tmp = rdtsc_oai();
+  unsigned short int *seed = (unsigned short int*)&tmp;
+
   RA_config_t *ra = &mac->ra;
   NR_RACH_ConfigCommon_t *setup;
   if (mac->scc) setup = mac->scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup;
@@ -378,28 +501,28 @@ void ra_preambles_config(NR_PRACH_RESOURCES_t *prach_resources, NR_UE_MAC_INST_t
     if(ra->ra_PreambleIndex < 0 || ra->ra_PreambleIndex > 63) {
       if (noGroupB) {
         // use Group A preamble
-        ra->ra_PreambleIndex = ra->starting_preamble_nb + ((taus()) % ra->cb_preambles_per_ssb);
+        ra->ra_PreambleIndex = ra->starting_preamble_nb + (nrand48(seed) % ra->cb_preambles_per_ssb);
         ra->RA_usedGroupA = 1;
       } else if ((ra->Msg3_size < messageSizeGroupA) && (dl_pathloss > PLThreshold)) {
         // Group B is configured and RA preamble Group A is used
         // - todo add condition on CCCH_sdu_size for initiation by CCCH
-        ra->ra_PreambleIndex = ra->starting_preamble_nb + ((taus()) % sizeOfRA_PreamblesGroupA);
+        ra->ra_PreambleIndex = ra->starting_preamble_nb + (nrand48(seed) % sizeOfRA_PreamblesGroupA);
         ra->RA_usedGroupA = 1;
       } else {
         // Group B preamble is configured and used
         // the first sizeOfRA_PreamblesGroupA RA preambles belong to RA Preambles Group A
         // the remaining belong to RA Preambles Group B
-        ra->ra_PreambleIndex = ra->starting_preamble_nb + sizeOfRA_PreamblesGroupA + ((taus()) % (ra->cb_preambles_per_ssb - sizeOfRA_PreamblesGroupA));
+        ra->ra_PreambleIndex = ra->starting_preamble_nb + sizeOfRA_PreamblesGroupA + (nrand48(seed) % (ra->cb_preambles_per_ssb - sizeOfRA_PreamblesGroupA));
         ra->RA_usedGroupA = 0;
       }
     }
   } else { // Msg3 is being retransmitted
     if (ra->RA_usedGroupA && noGroupB) {
-      ra->ra_PreambleIndex = ra->starting_preamble_nb + ((taus()) % ra->cb_preambles_per_ssb);
+      ra->ra_PreambleIndex = ra->starting_preamble_nb + (nrand48(seed) % ra->cb_preambles_per_ssb);
     } else if (ra->RA_usedGroupA && !noGroupB){
-      ra->ra_PreambleIndex = ra->starting_preamble_nb + ((taus()) % sizeOfRA_PreamblesGroupA);
+      ra->ra_PreambleIndex = ra->starting_preamble_nb + (nrand48(seed) % sizeOfRA_PreamblesGroupA);
     } else {
-      ra->ra_PreambleIndex = ra->starting_preamble_nb + sizeOfRA_PreamblesGroupA + ((taus()) % (ra->cb_preambles_per_ssb - sizeOfRA_PreamblesGroupA));
+      ra->ra_PreambleIndex = ra->starting_preamble_nb + sizeOfRA_PreamblesGroupA + (nrand48(seed) % (ra->cb_preambles_per_ssb - sizeOfRA_PreamblesGroupA));
     }
   }
   prach_resources->ra_PreambleIndex = ra->ra_PreambleIndex;
@@ -467,7 +590,8 @@ void nr_get_prach_resources(module_id_t mod_id,
   if (rach_ConfigDedicated) {
     if (rach_ConfigDedicated->cfra){
       uint8_t cfra_ssb_resource_idx = 0;
-      prach_resources->ra_PreambleIndex = rach_ConfigDedicated->cfra->resources.choice.ssb->ssb_ResourceList.list.array[cfra_ssb_resource_idx]->ra_PreambleIndex;
+      ra->ra_PreambleIndex = rach_ConfigDedicated->cfra->resources.choice.ssb->ssb_ResourceList.list.array[cfra_ssb_resource_idx]->ra_PreambleIndex;
+      prach_resources->ra_PreambleIndex = ra->ra_PreambleIndex;
       LOG_D(MAC, "In %s: selected RA preamble index %d for contention-free random access procedure for SSB with Id %d\n", __FUNCTION__, prach_resources->ra_PreambleIndex, cfra_ssb_resource_idx);
     }
   } else {
@@ -837,6 +961,9 @@ void nr_ra_failed(uint8_t mod_id, uint8_t CC_id, NR_PRACH_RESOURCES_t *prach_res
 
   NR_UE_MAC_INST_t *mac = get_mac_inst(mod_id);
   RA_config_t *ra = &mac->ra;
+  // Random seed generation
+  long long tmp = rdtsc_oai();
+  unsigned short int *seed = (unsigned short int*)&tmp;
 
   ra->first_Msg3 = 1;
   ra->ra_PreambleIndex = -1;
@@ -850,7 +977,7 @@ void nr_ra_failed(uint8_t mod_id, uint8_t CC_id, NR_PRACH_RESOURCES_t *prach_res
     LOG_D(MAC, "In %s: [UE %d][%d.%d] Maximum number of RACH attempts (%d) reached, selecting backoff time...\n",
           __FUNCTION__, mod_id, frame, slot, ra->preambleTransMax);
 
-    ra->RA_backoff_cnt = rand() % (prach_resources->RA_PREAMBLE_BACKOFF + 1);
+    ra->RA_backoff_cnt = nrand48(seed) % (prach_resources->RA_PREAMBLE_BACKOFF + 1);
     prach_resources->RA_PREAMBLE_TRANSMISSION_COUNTER = 1;
     prach_resources->RA_PREAMBLE_POWER_RAMPING_STEP += 2; // 2 dB increment
     prach_resources->ra_PREAMBLE_RECEIVED_TARGET_POWER = nr_get_Po_NOMINAL_PUSCH(prach_resources, mod_id, CC_id);
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
index bf1c368999d8ced328832813a860f02e366dc8e5..86d859f01a347f2dfca6b203e555bcda5a46a83b 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
@@ -54,7 +54,6 @@
 /* PHY */
 #include "PHY/NR_TRANSPORT/nr_dci.h"
 #include "executables/softmodem-common.h"
-#include "SCHED_NR_UE/defs.h"
 
 /* utils */
 #include "assertions.h"
@@ -1413,7 +1412,7 @@ void nr_ue_configure_pucch(NR_UE_MAC_INST_t *mac,
         mac->cg->physicalCellGroupConfig &&
         (mac->cg->physicalCellGroupConfig->harq_ACK_SpatialBundlingPUCCH != NULL ||
         mac->cg->physicalCellGroupConfig->pdsch_HARQ_ACK_Codebook != 1)) {
-      LOG_E(PHY,"PUCCH Unsupported cell group configuration : at line %d in function %s of file %s \n", LINE_FILE , __func__, FILE_NAME);
+      LOG_E(MAC,"PUCCH Unsupported cell group configuration : at line %d in function %s of file %s \n", LINE_FILE , __func__, FILE_NAME);
       return;
     }
     else if (mac->cg &&
@@ -3637,8 +3636,6 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t
     return 0;
   }
 
-  int cc_id                = dl_info->cc_id;
-  uint8_t gNB_id           = dl_info->gNB_index;
   NR_UE_MAC_INST_t *mac    = get_mac_inst(mod_id);
   RA_config_t *ra          = &mac->ra;
   uint8_t n_subPDUs        = 0;  // number of RAR payloads
@@ -3650,7 +3647,7 @@ int nr_ue_process_rar(nr_downlink_indication_t *dl_info, NR_UL_TIME_ALIGNMENT_t
   int ret                  = 0;
   NR_RA_HEADER_RAPID *rarh = (NR_RA_HEADER_RAPID *) dlsch_buffer; // RAR subheader pointer
   NR_MAC_RAR *rar          = (NR_MAC_RAR *) (dlsch_buffer + 1);   // RAR subPDU pointer
-  uint8_t preamble_index   = get_ra_PreambleIndex(mod_id, cc_id, gNB_id); //prach_resources->ra_PreambleIndex;
+  uint8_t preamble_index   = ra->ra_PreambleIndex;
 
   LOG_D(NR_MAC, "In %s:[%d.%d]: [UE %d][RAPROC] invoking MAC for received RAR (current preamble %d)\n", __FUNCTION__, frame, slot, mod_id, preamble_index);
 
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
index 0ec4872b28115371a91c7207bf23481aa8f5e684..1bc8b16fe5117dd66e53a9063cfce12fc3205c87 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
@@ -850,7 +850,14 @@ int nr_config_pusch_pdu(NR_UE_MAC_INST_t *mac,
     return -1;
   }
 
-  get_num_re_dmrs(pusch_config_pdu, &nb_dmrs_re_per_rb, &number_dmrs_symbols);
+  int start_symbol = pusch_config_pdu->start_symbol_index;
+  int number_of_symbols = pusch_config_pdu->nr_of_symbols;
+  for (int i = start_symbol; i < start_symbol + number_of_symbols; i++) {
+    if((pusch_config_pdu->ul_dmrs_symb_pos >> i) & 0x01)
+      number_dmrs_symbols += 1;
+  }
+
+  nb_dmrs_re_per_rb = ((pusch_config_pdu->dmrs_config_type == pusch_dmrs_type1) ? 6:4)*pusch_config_pdu->num_dmrs_cdm_grps_no_data;
 
   // Compute TBS
   pusch_config_pdu->pusch_data.tb_size = nr_compute_tbs(pusch_config_pdu->qam_mod_order,
@@ -2005,6 +2012,7 @@ void nr_ue_sib1_scheduler(module_id_t module_idP,
                                         ssb_start_symbol,
                                         scs_ssb,
                                         frequency_range,
+                                        mac->nr_band,
                                         ssb_index,
                                         1, // If the UE is not configured with a periodicity, the UE assumes a periodicity of a half frame
                                         ssb_offset_point_a);
diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c
index a2c130078eb448b05a8872d696b5de393bdbd6d3..cedd0957941e4905cf576e52c4ab356cc5970ba4 100644
--- a/openair2/LAYER2/NR_MAC_gNB/config.c
+++ b/openair2/LAYER2/NR_MAC_gNB/config.c
@@ -33,7 +33,7 @@
 #include "COMMON/platform_types.h"
 #include "COMMON/platform_constants.h"
 #include "common/ran_context.h"
-
+#include "common/utils/nr/nr_common.h"
 #include "common/utils/LOG/log.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
index 972343ddd167475c8ab5c91df5d95599ff3d6e53..7d2e6e4465dadfa80f3af6c2fffe67495a3eea97 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
@@ -46,9 +46,6 @@
 //#include "LAYER2/MAC/pre_processor.c"
 #include "pdcp.h"
 
-#include "openair1/PHY/defs_gNB.h"
-#include "openair1/PHY/NR_TRANSPORT/nr_dlsch.h"
-
 #include "intertask_interface.h"
 
 #include "executables/softmodem-common.h"
@@ -62,85 +59,6 @@ uint16_t nr_pdcch_order_table[6] = { 31, 31, 511, 2047, 2047, 8191 };
 
 uint8_t vnf_first_sched_entry = 1;
 
-void clear_mac_stats(gNB_MAC_INST *gNB) {
-  memset((void*)gNB->UE_info.mac_stats,0,MAX_MOBILES_PER_GNB*sizeof(NR_mac_stats_t));
-}
-#define MACSTATSSTRLEN 16384
-void dump_mac_stats(gNB_MAC_INST *gNB)
-{
-  NR_UE_info_t *UE_info = &gNB->UE_info;
-  int num = 1;
-  FILE *fd=fopen("nrMAC_stats.log","w");
-  AssertFatal(fd!=NULL,"Cannot open nrMAC_stats.log, error %s\n",strerror(errno));
-  char output[MACSTATSSTRLEN];
-  memset(output,0,MACSTATSSTRLEN);
-  int stroff=0;
-  for (int UE_id = UE_info->list.head; UE_id >= 0; UE_id = UE_info->list.next[UE_id]) {
-
-    stroff+=sprintf(output+stroff,"UE ID %d RNTI %04x (%d/%d) PH %d dB PCMAX %d dBm\n",
-      UE_id,
-      UE_info->rnti[UE_id],
-      num++,
-      UE_info->num_UEs,
-      UE_info->UE_sched_ctrl[UE_id].ph,
-      UE_info->UE_sched_ctrl[UE_id].pcmax);
-
-    LOG_I(NR_MAC, "UE ID %d RNTI %04x (%d/%d) PH %d dB PCMAX %d dBm\n",
-          UE_id,
-          UE_info->rnti[UE_id],
-          num++,
-          UE_info->num_UEs,
-          UE_info->UE_sched_ctrl[UE_id].ph,
-          UE_info->UE_sched_ctrl[UE_id].pcmax);
-
-    NR_mac_stats_t *stats = &UE_info->mac_stats[UE_id];
-    const int avg_rsrp = stats->num_rsrp_meas > 0 ? stats->cumul_rsrp / stats->num_rsrp_meas : 0;
-    stroff+=sprintf(output+stroff,"UE %d: dlsch_rounds %d/%d/%d/%d, dlsch_errors %d, pucch0_DTX %d average RSRP %d (%d meas)\n",
-          UE_id,
-          stats->dlsch_rounds[0], stats->dlsch_rounds[1],
-          stats->dlsch_rounds[2], stats->dlsch_rounds[3], stats->dlsch_errors,
-          stats->pucch0_DTX,
-          avg_rsrp, stats->num_rsrp_meas);
-    LOG_I(NR_MAC, "UE %d: dlsch_rounds %d/%d/%d/%d, dlsch_errors %d, pucch0_DTX %d\n",
-          UE_id, stats->dlsch_rounds[0], stats->dlsch_rounds[1], stats->dlsch_rounds[2], stats->dlsch_rounds[3],
-          stats->dlsch_errors, stats->pucch0_DTX);
-    stats->num_rsrp_meas = 0;
-    stats->cumul_rsrp = 0 ;
-    stroff+=sprintf(output+stroff,"UE %d: dlsch_total_bytes %d\n", UE_id, stats->dlsch_total_bytes);
-    stroff+=sprintf(output+stroff,"UE %d: ulsch_rounds %d/%d/%d/%d, ulsch_DTX %d, ulsch_errors %d\n",
-                    UE_id,
-                    stats->ulsch_rounds[0], stats->ulsch_rounds[1],
-                    stats->ulsch_rounds[2], stats->ulsch_rounds[3],
-                    stats->ulsch_DTX,
-                    stats->ulsch_errors);
-    stroff+=sprintf(output+stroff,
-                    "UE %d: ulsch_total_bytes_scheduled %d, ulsch_total_bytes_received %d\n",
-                    UE_id,
-                    stats->ulsch_total_bytes_scheduled, stats->ulsch_total_bytes_rx);
-    LOG_I(NR_MAC, "UE %d: dlsch_total_bytes %d\n", UE_id, stats->dlsch_total_bytes);
-    LOG_I(NR_MAC, "UE %d: ulsch_rounds %d/%d/%d/%d, ulsch_errors %d, ulsch_DTX %d\n",
-          UE_id, stats->ulsch_rounds[0], stats->ulsch_rounds[1], stats->ulsch_rounds[2], stats->ulsch_rounds[3],
-          stats->ulsch_errors, stats->ulsch_DTX);
-    LOG_I(NR_MAC,
-          "UE %d: ulsch_total_bytes (scheduled/received): %d / %d\n",
-          UE_id,
-          stats->ulsch_total_bytes_scheduled, stats->ulsch_total_bytes_rx);
-    for (int lc_id = 0; lc_id < 63; lc_id++) {
-      if (stats->lc_bytes_tx[lc_id] > 0) {
-        stroff+=sprintf(output+stroff, "UE %d: LCID %d: %d bytes TX\n", UE_id, lc_id, stats->lc_bytes_tx[lc_id]);
-	LOG_D(NR_MAC, "UE %d: LCID %d: %d bytes TX\n", UE_id, lc_id, stats->lc_bytes_tx[lc_id]);
-      }
-      if (stats->lc_bytes_rx[lc_id] > 0) {
-        stroff+=sprintf(output+stroff, "UE %d: LCID %d: %d bytes RX\n", UE_id, lc_id, stats->lc_bytes_rx[lc_id]);
-	LOG_D(NR_MAC, "UE %d: LCID %d: %d bytes RX\n", UE_id, lc_id, stats->lc_bytes_rx[lc_id]);
-      }
-    }
-  }
-  print_meas(&gNB->eNB_scheduler, "DL & UL scheduling timing stats", NULL, NULL);
-  if (stroff>0) fprintf(fd,"%s",output);
-  fclose(fd);
-}
-
 void clear_nr_nfapi_information(gNB_MAC_INST * gNB,
                                 int CC_idP,
                                 frame_t frameP,
@@ -358,6 +276,8 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
   protocol_ctxt_t   ctxt={0};
   PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frame, slot,module_idP);
 
+  char stats_output[16384];
+
   gNB_MAC_INST *gNB = RC.nrmac[module_idP];
   NR_COMMON_channels_t *cc = gNB->common_channels;
   NR_ServingCellConfigCommon_t        *scc     = cc->ServingCellConfigCommon;
@@ -426,8 +346,11 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
   }
 
 
-  if ((slot == 0) && (frame & 127) == 0) dump_mac_stats(RC.nrmac[module_idP]);
-
+  if ((slot == 0) && (frame & 127) == 0) {
+     stats_output[0]='\0';
+     dump_mac_stats(RC.nrmac[module_idP],stats_output,16384);
+     LOG_I(NR_MAC,"Frame.Slot %d.%d\n%s\n",frame,slot,stats_output);
+  }
 
   // This schedules MIB
   schedule_nr_mib(module_idP, frame, slot);
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c
index 28b7ea3c21f7ed95dafb705f48fa22d75c08fc09..79f6dbee1b96bdacdb0ab6fdb124639341cbfefa 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c
@@ -219,6 +219,7 @@ void schedule_nr_mib(module_id_t module_idP, frame_t frameP, sub_frame_t slotP)
                                                         ssb_start_symbol,
                                                         scs,
                                                         FR1,
+                                                        band,
                                                         i_ssb,
                                                         ssb_frame_periodicity,
                                                         offset_pointa);
@@ -246,6 +247,7 @@ void schedule_nr_mib(module_id_t module_idP, frame_t frameP, sub_frame_t slotP)
                                                         ssb_start_symbol,
                                                         scs,
                                                         FR1,
+                                                        band,
                                                         i_ssb,
                                                         ssb_frame_periodicity,
                                                         offset_pointa);
@@ -281,6 +283,7 @@ void schedule_nr_mib(module_id_t module_idP, frame_t frameP, sub_frame_t slotP)
                                                         ssb_start_symbol,
                                                         scs,
                                                         FR2,
+                                                        band,
                                                         i_ssb,
                                                         ssb_frame_periodicity,
                                                         offset_pointa);
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
index 737914dbde442dc176543acd8dbe29e52ab5449c..4795df889fa7bbdf9c940f9bfb2832bf74176570 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
@@ -29,11 +29,7 @@
 
  */
 
-/*PHY*/
-#include "PHY/CODING/coding_defs.h"
-#include "PHY/defs_nr_common.h"
 #include "common/utils/nr/nr_common.h"
-#include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 /*MAC*/
 #include "NR_MAC_COMMON/nr_mac.h"
 #include "NR_MAC_gNB/nr_mac_gNB.h"
@@ -569,12 +565,12 @@ bool allocate_dl_retransmission(module_id_t module_id,
     return false;
   }
 
-  sched_ctrl->sched_pdsch.pucch_allocation = alloc;
-
   /* just reuse from previous scheduling opportunity, set new start RB */
   sched_ctrl->sched_pdsch = *retInfo;
   sched_ctrl->sched_pdsch.rbStart = rbStart;
 
+  sched_ctrl->sched_pdsch.pucch_allocation = alloc;
+
   /* retransmissions: directly allocate */
   *n_rb_sched -= sched_ctrl->sched_pdsch.rbSize;
   for (int rb = 0; rb < sched_ctrl->sched_pdsch.rbSize; rb++)
@@ -894,7 +890,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
     UE_info->mac_stats[UE_id].dlsch_rounds[harq->round]++;
 
     LOG_D(NR_MAC,
-          "%4d.%2d [DLSCH/PDSCH/PUCCH] UE %d RNTI %04x DCI L %d start %3d RBs %3d startSymbol %2d nb_symbol %2d dmrspos %x MCS %2d TBS %4d HARQ PID %2d round %d RV %d NDI %d dl_data_to_ULACK %d (%d.%d) TPC %d\n",
+          "%4d.%2d [DLSCH/PDSCH/PUCCH] UE %d RNTI %04x DCI L %d start %3d RBs %3d startSymbol %2d nb_symbol %2d dmrspos %x MCS %2d TBS %4d HARQ PID %2d round %d RV %d NDI %d dl_data_to_ULACK %d (%d.%d) PUCCH allocation %d TPC %d\n",
           frame,
           slot,
           UE_id,
@@ -914,6 +910,7 @@ void nr_schedule_ue_spec(module_id_t module_id,
           pucch->timing_indicator,
           pucch->frame,
           pucch->ul_slot,
+          sched_pdsch->pucch_allocation,
           sched_ctrl->tpc1);
 
     NR_BWP_Downlink_t *bwp = sched_ctrl->active_bwp;
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
index c44cb6d4f1685dadb831c19c78678418e4a88e13..78d0041084341f50bc58532ff50d085a9ab399ea 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
@@ -29,11 +29,8 @@
  */
 
 #include "nr_mac_gNB.h"
-#include "SCHED_NR/sched_nr.h"
 #include "NR_MAC_gNB/mac_proto.h"
 #include "LAYER2/NR_MAC_COMMON/nr_mac_common.h"
-#include "PHY/NR_TRANSPORT/nr_dlsch.h"
-#include "PHY/NR_TRANSPORT/nr_dci.h"
 #include "executables/nr-softmodem.h"
 #include "LAYER2/NR_MAC_COMMON/nr_mac.h"
 #include "executables/softmodem-common.h"
@@ -378,14 +375,12 @@ void nr_preprocessor_phytest(module_id_t module_id,
   sched_pdsch->rbStart = rbStart;
   sched_pdsch->rbSize = rbSize;
   const int tda = sched_ctrl->active_bwp ? RC.nrmac[module_id]->preferred_dl_tda[sched_ctrl->active_bwp->bwp_Id][slot] : 1;
-  const uint8_t num_dmrs_cdm_grps_no_data = 1;
-  const long f = 1;
+  const long f = sched_ctrl->active_bwp ? sched_ctrl->search_space->searchSpaceType->choice.ue_Specific->dci_Formats : 0;
   ps->nrOfLayers = target_dl_Nl;
-  if (ps->time_domain_allocation != tda || ps->numDmrsCdmGrpsNoData != num_dmrs_cdm_grps_no_data)
+  if (ps->time_domain_allocation != tda)
     nr_set_pdsch_semi_static(
         scc, UE_info->CellGroup[UE_id], sched_ctrl->active_bwp, NULL, tda, f, ps);
 
-
   sched_pdsch->mcs = target_dl_mcs;
   sched_pdsch->Qm = nr_get_Qm_dl(sched_pdsch->mcs, ps->mcsTableIdx);
   sched_pdsch->R = nr_get_code_rate_dl(sched_pdsch->mcs, ps->mcsTableIdx);
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
index b948027291dd8db4359c4f7fd36e2345911627ac..40295fda87f4d689b6817577fdd4b1fc9055c500 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
@@ -1335,28 +1335,28 @@ void fill_dci_pdu_rel15(const NR_ServingCellConfigCommon_t *scc,
       pos = 1;
       // Freq domain assignment 0-16 bit
       fsize = (int)ceil(log2((N_RB * (N_RB + 1)) >> 1));
-      LOG_D(PHY, "fsize = %i\n", fsize);
+      LOG_D(NR_MAC, "fsize = %i\n", fsize);
       for (int i = 0; i < fsize; i++)
         *dci_pdu |= (((uint64_t)dci_pdu_rel15->frequency_domain_assignment.val >> (fsize - i - 1)) & 1) << (dci_size - pos++);
-      LOG_D(PHY, "dci_pdu_rel15->frequency_domain_assignment.val = %i\n", dci_pdu_rel15->frequency_domain_assignment.val);
+      LOG_D(NR_MAC, "dci_pdu_rel15->frequency_domain_assignment.val = %i\n", dci_pdu_rel15->frequency_domain_assignment.val);
       // Time domain assignment 4 bit
       for (int i = 0; i < 4; i++)
         *dci_pdu |= (((uint64_t)dci_pdu_rel15->time_domain_assignment.val >> (3 - i)) & 1) << (dci_size - pos++);
-      LOG_D(PHY, "dci_pdu_rel15->time_domain_assignment.val = %i\n", dci_pdu_rel15->time_domain_assignment.val);
+      LOG_D(NR_MAC, "dci_pdu_rel15->time_domain_assignment.val = %i\n", dci_pdu_rel15->time_domain_assignment.val);
       // VRB to PRB mapping 1 bit
       *dci_pdu |= ((uint64_t)dci_pdu_rel15->vrb_to_prb_mapping.val & 1) << (dci_size - pos++);
-      LOG_D(PHY, "dci_pdu_rel15->vrb_to_prb_mapping.val = %i\n", dci_pdu_rel15->vrb_to_prb_mapping.val);
+      LOG_D(NR_MAC, "dci_pdu_rel15->vrb_to_prb_mapping.val = %i\n", dci_pdu_rel15->vrb_to_prb_mapping.val);
       // MCS 5bit  //bit over 32, so dci_pdu ++
       for (int i = 0; i < 5; i++)
         *dci_pdu |= (((uint64_t)dci_pdu_rel15->mcs >> (4 - i)) & 1) << (dci_size - pos++);
-      LOG_D(PHY, "dci_pdu_rel15->mcs = %i\n", dci_pdu_rel15->mcs);
+      LOG_D(NR_MAC, "dci_pdu_rel15->mcs = %i\n", dci_pdu_rel15->mcs);
       // Redundancy version  2bit
       for (int i = 0; i < 2; i++)
         *dci_pdu |= (((uint64_t)dci_pdu_rel15->rv >> (1 - i)) & 1) << (dci_size - pos++);
-      LOG_D(PHY, "dci_pdu_rel15->rv = %i\n", dci_pdu_rel15->rv);
+      LOG_D(NR_MAC, "dci_pdu_rel15->rv = %i\n", dci_pdu_rel15->rv);
       // System information indicator 1bit
       *dci_pdu |= ((uint64_t)dci_pdu_rel15->system_info_indicator&1)<<(dci_size-pos++);
-      LOG_D(PHY, "dci_pdu_rel15->system_info_indicator = %i\n", dci_pdu_rel15->system_info_indicator);
+      LOG_D(NR_MAC, "dci_pdu_rel15->system_info_indicator = %i\n", dci_pdu_rel15->system_info_indicator);
       break;
 
     case NR_RNTI_TC:
diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
index d17448437de18aad3ba568ee297ac6d08d5dff55..5136a4a57cdca6afe82a830a8f00fde7640c8ccd 100644
--- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
+++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
@@ -31,8 +31,6 @@
 #ifndef __LAYER2_NR_MAC_PROTO_H__
 #define __LAYER2_NR_MAC_PROTO_H__
 
-#include "PHY/defs_gNB.h"
-
 #include "LAYER2/NR_MAC_gNB/nr_mac_gNB.h"
 #include "NR_TAG-Id.h"
 
@@ -443,4 +441,5 @@ bool nr_find_nb_rb(uint16_t Qm,
 
 void nr_sr_reporting(int Mod_idP, frame_t frameP, sub_frame_t slotP);
 
+void dump_mac_stats(gNB_MAC_INST *gNB, char *output, int strlen);
 #endif /*__LAYER2_NR_MAC_PROTO_H__*/
diff --git a/openair2/LAYER2/NR_MAC_gNB/main.c b/openair2/LAYER2/NR_MAC_gNB/main.c
index 117c18ae8da3784749948cc18daed5f6a5ca028f..6e13e4bcc6225cf523037588450bb305a3e41ec2 100644
--- a/openair2/LAYER2/NR_MAC_gNB/main.c
+++ b/openair2/LAYER2/NR_MAC_gNB/main.c
@@ -45,6 +45,86 @@
 extern RAN_CONTEXT_t RC;
 
 
+#define MACSTATSSTRLEN 16384
+
+void *nrmac_stats_thread(void *arg) {
+
+  gNB_MAC_INST *gNB = (gNB_MAC_INST *)arg;
+
+  char output[MACSTATSSTRLEN];
+  memset(output,0,MACSTATSSTRLEN);
+  FILE *fd=fopen("nrMAC_stats.log","w");
+  AssertFatal(fd!=NULL,"Cannot open nrMAC_stats.log, error %s\n",strerror(errno));
+
+  while (oai_exit == 0) {
+     dump_mac_stats(gNB,output,MACSTATSSTRLEN);
+     fprintf(fd,"%s\n",output);
+     fflush(fd);
+     usleep(200000);
+     fseek(fd,0,SEEK_SET);
+  }
+  fclose(fd);
+  return (void *)0;
+}
+
+void clear_mac_stats(gNB_MAC_INST *gNB) {
+  memset((void*)gNB->UE_info.mac_stats,0,MAX_MOBILES_PER_GNB*sizeof(NR_mac_stats_t));
+}
+
+void dump_mac_stats(gNB_MAC_INST *gNB, char *output, int strlen)
+{
+  NR_UE_info_t *UE_info = &gNB->UE_info;
+  int num = 1;
+ 
+  int stroff=0;
+  if (UE_info->num_UEs == 0) return;
+
+  for (int UE_id = UE_info->list.head; UE_id >= 0; UE_id = UE_info->list.next[UE_id]) {
+
+    stroff+=sprintf(output+stroff,"UE ID %d RNTI %04x (%d/%d) PH %d dB PCMAX %d dBm\n",
+      UE_id,
+      UE_info->rnti[UE_id],
+      num++,
+      UE_info->num_UEs,
+      UE_info->UE_sched_ctrl[UE_id].ph,
+      UE_info->UE_sched_ctrl[UE_id].pcmax);
+
+    NR_mac_stats_t *stats = &UE_info->mac_stats[UE_id];
+    const int avg_rsrp = stats->num_rsrp_meas > 0 ? stats->cumul_rsrp / stats->num_rsrp_meas : 0;
+    stroff+=sprintf(output+stroff,"UE %d: dlsch_rounds %d/%d/%d/%d, dlsch_errors %d, pucch0_DTX %d average RSRP %d (%d meas)\n",
+          UE_id,
+          stats->dlsch_rounds[0], stats->dlsch_rounds[1],
+          stats->dlsch_rounds[2], stats->dlsch_rounds[3], stats->dlsch_errors,
+          stats->pucch0_DTX,
+          avg_rsrp, stats->num_rsrp_meas);
+    stats->num_rsrp_meas = 0;
+    stats->cumul_rsrp = 0 ;
+    stroff+=sprintf(output+stroff,"UE %d: dlsch_total_bytes %d\n", UE_id, stats->dlsch_total_bytes);
+    stroff+=sprintf(output+stroff,"UE %d: ulsch_rounds %d/%d/%d/%d, ulsch_DTX %d, ulsch_errors %d\n",
+                    UE_id,
+                    stats->ulsch_rounds[0], stats->ulsch_rounds[1],
+                    stats->ulsch_rounds[2], stats->ulsch_rounds[3],
+                    stats->ulsch_DTX,
+                    stats->ulsch_errors);
+    stroff+=sprintf(output+stroff,
+                    "UE %d: ulsch_total_bytes_scheduled %d, ulsch_total_bytes_received %d\n",
+                    UE_id,
+                    stats->ulsch_total_bytes_scheduled, stats->ulsch_total_bytes_rx);
+    for (int lc_id = 0; lc_id < 63; lc_id++) {
+      if (stats->lc_bytes_tx[lc_id] > 0) {
+        stroff+=sprintf(output+stroff, "UE %d: LCID %d: %d bytes TX\n", UE_id, lc_id, stats->lc_bytes_tx[lc_id]);
+	LOG_D(NR_MAC, "UE %d: LCID %d: %d bytes TX\n", UE_id, lc_id, stats->lc_bytes_tx[lc_id]);
+      }
+      if (stats->lc_bytes_rx[lc_id] > 0) {
+        stroff+=sprintf(output+stroff, "UE %d: LCID %d: %d bytes RX\n", UE_id, lc_id, stats->lc_bytes_rx[lc_id]);
+	LOG_D(NR_MAC, "UE %d: LCID %d: %d bytes RX\n", UE_id, lc_id, stats->lc_bytes_rx[lc_id]);
+      }
+    }
+  }
+  print_meas(&gNB->eNB_scheduler, "DL & UL scheduling timing stats", NULL, NULL);
+}
+
+
 void mac_top_init_gNB(void)
 {
   module_id_t     i;
@@ -90,6 +170,7 @@ void mac_top_init_gNB(void)
         RC.nrmac[i]->pre_processor_dl = nr_init_fr1_dlsch_preprocessor(i, 0);
         RC.nrmac[i]->pre_processor_ul = nr_init_fr1_ulsch_preprocessor(i, 0);
       }
+      pthread_create(&RC.nrmac[i]->stats_thread,NULL,nrmac_stats_thread,(void*)RC.nrmac[i]);
 
     }//END for (i = 0; i < RC.nb_nr_macrlc_inst; i++)
 
@@ -103,6 +184,7 @@ void mac_top_init_gNB(void)
 
     rrc_init_nr_global_param();
 
+
   } else {
     RC.nrmac = NULL;
   }
diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
index 8d5f93b48c7bfdfa23a3e53925e97ae3f469d809..68acd150a192ef74cf68d6c5001073a5e167f4b7 100644
--- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
+++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
@@ -665,6 +665,7 @@ typedef struct gNB_MAC_INST_s {
   NR_TAG_t                        *tag;
   /// Pointer to IF module instance for PHY
   NR_IF_Module_t                  *if_inst;
+  pthread_t                       stats_thread;
   /// Pusch target SNR
   int                             pusch_target_snrx10;
   /// Pucch target SNR
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
index cc44572abddc2b5a5802822b4dbd987f4384ee95..05e77a935de7b17b3dc1db423228991d0dbd390d 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
@@ -603,7 +603,7 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const  ctxt_pP)
   //int optval;
   int bytes_received;
   sidelink_pc5s_element *sl_pc5s_msg_send = NULL;
-  pc5s_header_t *pc5s_header = NULL;
+  pc5s_header_t *pc5s_header  = NULL;
   rb_id_t          rab_id  = 0;
   //TTN for D2D (PC5S)
   // receive a message from ProSe App
@@ -704,6 +704,12 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const  ctxt_pP)
                 pc5s_header->rb_id,
                 rab_id,
                 pc5s_header->data_size);
+            /* pointers to pc5s_header fields possibly not aligned because pc5s_header points to a packed structure
+             * Using these possibly unaligned pointers in a function call may trigger alignment errors at run time and
+             * gcc, from v9,  now warns about it. fix these warnings by using  local variables
+             */
+              uint32_t sourceL2Id = pc5s_header->sourceL2Id;
+              uint32_t destinationL2Id = pc5s_header->destinationL2Id;
               pdcp_data_req(
                 &ctxt,
                 SRB_FLAG_NO,
@@ -713,9 +719,11 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const  ctxt_pP)
                 pc5s_header->data_size,
                 (unsigned char *)receive_buf,
                 PDCP_TRANSMISSION_MODE_DATA,
-                &pc5s_header->sourceL2Id,
-                &pc5s_header->destinationL2Id
+                &sourceL2Id,
+                &destinationL2Id
               );
+              pc5s_header->sourceL2Id = sourceL2Id;
+              pc5s_header->destinationL2Id=destinationL2Id;             
             } else { /* else of h_rc == HASH_TABLE_OK */
               MSC_LOG_RX_DISCARDED_MESSAGE(
                 (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
@@ -759,6 +767,12 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const  ctxt_pP)
               pc5s_header->rb_id,
               DEFAULT_RAB_ID,
               pc5s_header->data_size);
+            /* pointers to pc5s_header fields possibly not aligned because pc5s_header points to a packed structure
+             * Using these possibly unaligned pointers in a function call may trigger alignment errors at run time and
+             * gcc, from v9,  now warns about it. fix these warnings by using  local variables
+             */
+            uint32_t sourceL2Id = pc5s_header->sourceL2Id;
+            uint32_t destinationL2Id = pc5s_header->destinationL2Id;
             pdcp_data_req (
               &ctxt,
               SRB_FLAG_NO,
@@ -768,9 +782,11 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const  ctxt_pP)
               pc5s_header->data_size,
               (unsigned char *)receive_buf,
               PDCP_TRANSMISSION_MODE_DATA,
-              &pc5s_header->sourceL2Id,
-              &pc5s_header->destinationL2Id
+              &sourceL2Id,
+              &destinationL2Id
             );
+            pc5s_header->sourceL2Id = sourceL2Id;
+            pc5s_header->destinationL2Id=destinationL2Id; 
           }
         } /* end of !ctxt.enb_flag */
 
diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c
index b2230df623cfe1440044c8339d0f797467ae00ba..30fb20b72797667fcc4ba3c2860874547ef3c85e 100644
--- a/openair2/RRC/LTE/rrc_UE.c
+++ b/openair2/RRC/LTE/rrc_UE.c
@@ -2969,6 +2969,12 @@ int decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index,
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize = siWindowLength_int[sib1->si_WindowLength];
   LOG_I( RRC, "[FRAME unknown][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB1 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
          ctxt_pP->module_id, eNB_index, ctxt_pP->module_id );
+  /* pointers to  SIperiod inthe Info struct points to a packed structure
+ * Using these possibly unaligned pointers in a function call may trigger alignment errors at run time and
+ * gcc, from v9,  now warns about it. fix these warnings by removing the indirection on data
+ * Not sure if SiPeriod can be modified, reassign after function call for security
+ */
+  uint16_t Aligned_SIperiod = UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod;
   rrc_mac_config_req_ue(ctxt_pP->module_id, 0, eNB_index,
                         (LTE_RadioResourceConfigCommonSIB_t *)NULL,
                         (struct LTE_PhysicalConfigDedicated *)NULL,
@@ -2981,7 +2987,7 @@ int decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index,
                         UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->tdd_Config,
                         (LTE_MobilityControlInfo_t *) NULL,
                         &UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize,
-                        &UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod,
+                        &Aligned_SIperiod,
                         NULL,
                         NULL,
                         NULL,
@@ -2995,6 +3001,7 @@ int decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index,
                         (struct LTE_NonMBSFN_SubframeConfig_r14 *)NULL,
                         (LTE_MBSFN_AreaInfoList_r9_t *)NULL
                        );
+  UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod=Aligned_SIperiod;
   LOG_I(RRC,"Setting SIStatus bit 0 to 1\n");
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus = 1;
   UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIB1systemInfoValueTag = sib1->systemInfoValueTag;
diff --git a/openair2/RRC/LTE/rrc_defs.h b/openair2/RRC/LTE/rrc_defs.h
index 1c02c3de46c0a2ed3e559a0e5b99e7aa6ca490f4..f5b1db8b8cdbb5366eb03c12187488d4afc47559 100644
--- a/openair2/RRC/LTE/rrc_defs.h
+++ b/openair2/RRC/LTE/rrc_defs.h
@@ -364,7 +364,7 @@ typedef struct UE_RRC_INFO_s {
   uint8_t SIwindowsize_MBMS; //!< Corresponds to the SIB1 si-WindowLength parameter. The unit is ms. Possible values are (final): 1,2,5,10,15,20,40
   uint8_t handoverTarget;
   HO_STATE_t ho_state;
-  uint16_t SIperiod; //!< Corresponds to the SIB1 si-Periodicity parameter (multiplied by 10). Possible values are (final): 80,160,320,640,1280,2560,5120
+  uint16_t SIperiod ; //!< Corresponds to the SIB1 si-Periodicity parameter (multiplied by 10). Possible values are (final): 80,160,320,640,1280,2560,5120
   uint16_t SIperiod_MBMS; //!< Corresponds to the SIB1-MBMS si-Periodicity parameter (multiplied by 10). Possible values are (final): 80,160,320,640,1280,2560,5120 TODO
   unsigned short UE_index;
   uint32_t T300_active;
diff --git a/openair3/NAS/COMMON/API/NETWORK/as_message.c b/openair3/NAS/COMMON/API/NETWORK/as_message.c
index fd3f15cb4ca840dd44a38359779d662a55cba9ea..4a2da215948632a58f9d3787ae8d68c8440736f6 100644
--- a/openair3/NAS/COMMON/API/NETWORK/as_message.c
+++ b/openair3/NAS/COMMON/API/NETWORK/as_message.c
@@ -81,7 +81,12 @@ int as_message_decode(const char* buffer, as_message_t* msg, int length)
   LOG_FUNC_IN;
 
   int bytes;
-  Byte_t** data = NULL;
+  /* pointers to msg fields possibly not aligned because msg  points to a packed structure
+ * Using these possibly unaligned pointers in a function call may trigger alignment errors at run time and
+ * gcc, from v9,  now warns about it. fix these warnings by removing the indirection on data
+ * (in fact i don't understand this code data seems to be useless...)
+ */
+  Byte_t *data = NULL;
 
   /* Get the message type */
   msg->msgID = *(uint16_t*)(buffer);
@@ -91,49 +96,49 @@ int as_message_decode(const char* buffer, as_message_t* msg, int length)
   case AS_NAS_ESTABLISH_REQ:
     /* NAS signalling connection establish request */
     bytes += sizeof(nas_establish_req_t) - sizeof(Byte_t*);
-    data = &msg->msg.nas_establish_req.initialNasMsg.data;
+    data = msg->msg.nas_establish_req.initialNasMsg.data;
     break;
 
   case AS_NAS_ESTABLISH_IND:
     /* NAS signalling connection establishment indication */
     bytes += sizeof(nas_establish_ind_t) - sizeof(Byte_t*);
-    data = &msg->msg.nas_establish_ind.initialNasMsg.data;
+    data = msg->msg.nas_establish_ind.initialNasMsg.data;
     break;
 
   case AS_NAS_ESTABLISH_RSP:
     /* NAS signalling connection establishment response */
     bytes += sizeof(nas_establish_rsp_t) - sizeof(Byte_t*);
-    data = &msg->msg.nas_establish_rsp.nasMsg.data;
+    data = msg->msg.nas_establish_rsp.nasMsg.data;
     break;
 
   case AS_NAS_ESTABLISH_CNF:
     /* NAS signalling connection establishment confirm */
     bytes += sizeof(nas_establish_cnf_t) - sizeof(Byte_t*);
-    data = &msg->msg.nas_establish_cnf.nasMsg.data;
+    data = msg->msg.nas_establish_cnf.nasMsg.data;
     break;
 
   case AS_UL_INFO_TRANSFER_REQ:
     /* Uplink L3 data transfer request */
     bytes += sizeof(ul_info_transfer_req_t) - sizeof(Byte_t*);
-    data = &msg->msg.ul_info_transfer_req.nasMsg.data;
+    data = msg->msg.ul_info_transfer_req.nasMsg.data;
     break;
 
   case AS_UL_INFO_TRANSFER_IND:
     /* Uplink L3 data transfer indication */
     bytes += sizeof(ul_info_transfer_ind_t) - sizeof(Byte_t*);
-    data = &msg->msg.ul_info_transfer_ind.nasMsg.data;
+    data = msg->msg.ul_info_transfer_ind.nasMsg.data;
     break;
 
   case AS_DL_INFO_TRANSFER_REQ:
     /* Downlink L3 data transfer request */
     bytes += sizeof(dl_info_transfer_req_t) - sizeof(Byte_t*);
-    data = &msg->msg.dl_info_transfer_req.nasMsg.data;
+    data = msg->msg.dl_info_transfer_req.nasMsg.data;
     break;
 
   case AS_DL_INFO_TRANSFER_IND:
     /* Downlink L3 data transfer indication */
     bytes += sizeof(dl_info_transfer_ind_t) - sizeof(Byte_t*);
-    data = &msg->msg.dl_info_transfer_ind.nasMsg.data;
+    data = msg->msg.dl_info_transfer_ind.nasMsg.data;
     break;
 
   case AS_BROADCAST_INFO_IND:
@@ -166,7 +171,8 @@ int as_message_decode(const char* buffer, as_message_t* msg, int length)
   if (bytes > 0) {
     if (data) {
       /* Set the pointer to dedicated NAS information */
-      *data = (Byte_t*)(buffer + bytes);
+      /* wasn't data already computed above for specific cases here we override ?? */
+      data = (Byte_t *)buffer + bytes;
     }
 
     /* Decode the message */
@@ -201,8 +207,10 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
   LOG_FUNC_IN;
 
   int bytes = sizeof(msg->msgID);
-  as_nas_info_t* nas_msg = NULL;
-
+  as_nas_info_t nas_msg;
+  Byte_t *dataptr=NULL;
+  uint32_t len=0;
+  
   switch (msg->msgID) {
   case AS_BROADCAST_INFO_IND:
     /* Broadcast information */
@@ -237,25 +245,30 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
   case AS_NAS_ESTABLISH_REQ:
     /* NAS signalling connection establish request */
     bytes += sizeof(nas_establish_req_t) - sizeof(Byte_t*);
-    nas_msg = &msg->msg.nas_establish_req.initialNasMsg;
+    nas_msg = msg->msg.nas_establish_req.initialNasMsg;
     break;
 
   case AS_NAS_ESTABLISH_IND:
     /* NAS signalling connection establish indication */
     bytes += sizeof(nas_establish_ind_t) - sizeof(Byte_t*);
-    nas_msg = &msg->msg.nas_establish_ind.initialNasMsg;
+    nas_msg = msg->msg.nas_establish_ind.initialNasMsg;
+    dataptr=(Byte_t *)&(msg->msg.nas_establish_ind.initialNasMsg.data);
+    len=msg->msg.nas_establish_ind.initialNasMsg.length;
     break;
 
   case AS_NAS_ESTABLISH_RSP:
     /* NAS signalling connection establish response */
     bytes += sizeof(nas_establish_rsp_t) - sizeof(Byte_t*);
-    nas_msg = &msg->msg.nas_establish_rsp.nasMsg;
+    nas_msg = msg->msg.nas_establish_rsp.nasMsg;
+
     break;
 
   case AS_NAS_ESTABLISH_CNF:
     /* NAS signalling connection establish confirm */
     bytes += sizeof(nas_establish_cnf_t) - sizeof(Byte_t*);
-    nas_msg = &msg->msg.nas_establish_cnf.nasMsg;
+    nas_msg = msg->msg.nas_establish_cnf.nasMsg;
+    dataptr=(Byte_t *)&(msg->msg.nas_establish_cnf.nasMsg.data);
+    len=msg->msg.nas_establish_ind.initialNasMsg.length;
     break;
 
   case AS_NAS_RELEASE_REQ:
@@ -271,7 +284,7 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
   case AS_UL_INFO_TRANSFER_REQ:
     /* Uplink L3 data transfer request */
     bytes += sizeof(ul_info_transfer_req_t) - sizeof(Byte_t*);
-    nas_msg = &msg->msg.ul_info_transfer_req.nasMsg;
+    nas_msg = msg->msg.ul_info_transfer_req.nasMsg;
     break;
 
   case AS_UL_INFO_TRANSFER_CNF:
@@ -282,13 +295,13 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
   case AS_UL_INFO_TRANSFER_IND:
     /* Uplink L3 data transfer indication */
     bytes += sizeof(ul_info_transfer_ind_t) - sizeof(Byte_t*);
-    nas_msg = &msg->msg.ul_info_transfer_ind.nasMsg;
+    nas_msg = msg->msg.ul_info_transfer_ind.nasMsg;
     break;
 
   case AS_DL_INFO_TRANSFER_REQ:
     /* Downlink L3 data transfer */
     bytes += sizeof(dl_info_transfer_req_t) - sizeof(Byte_t*);
-    nas_msg = &msg->msg.dl_info_transfer_req.nasMsg;
+    nas_msg = msg->msg.dl_info_transfer_req.nasMsg;
     break;
 
   case AS_DL_INFO_TRANSFER_CNF:
@@ -299,7 +312,8 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
   case AS_DL_INFO_TRANSFER_IND:
     /* Downlink L3 data transfer indication */
     bytes += sizeof(dl_info_transfer_ind_t) - sizeof(Byte_t*);
-    nas_msg = &msg->msg.dl_info_transfer_ind.nasMsg;
+    nas_msg = msg->msg.dl_info_transfer_ind.nasMsg;
+ 
     break;
 
   case AS_RAB_ESTABLISH_REQ:
@@ -343,14 +357,14 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
     /* Encode the AS message */
     memcpy(buffer, (unsigned char*)msg, bytes);
 
-    if ( nas_msg && (nas_msg->length > 0) ) {
+    if ( (dataptr!=NULL) && (len > 0) ) {
       /* Copy the NAS message */
-      memcpy(buffer + bytes, nas_msg->data, nas_msg->length);
-      bytes += nas_msg->length;
+      memcpy(buffer + bytes, nas_msg.data, nas_msg.length);
+      bytes += len;
       /* Release NAS message memory */
-      free(nas_msg->data);
-      nas_msg->length = 0;
-      nas_msg->data = NULL;
+      free(nas_msg.data);
+      len=0;
+      dataptr = NULL;
     }
 
     LOG_FUNC_RETURN (bytes);
diff --git a/openair3/NAS/UE/EMM/SAP/emm_as.c b/openair3/NAS/UE/EMM/SAP/emm_as.c
index 10b118eac0315e338e282ef192ed7397dcb6e538..6b226be38061696a5ff4434c91ebcbc50b958497 100644
--- a/openair3/NAS/UE/EMM/SAP/emm_as.c
+++ b/openair3/NAS/UE/EMM/SAP/emm_as.c
@@ -136,17 +136,25 @@ static int _emm_as_encrypt(
 
 static int _emm_as_send(const nas_user_t *user, const emm_as_t *msg);
 
-static int _emm_as_security_res(const emm_data_t *emm_data, const emm_as_security_t *,
-                                ul_info_transfer_req_t *);
-static int _emm_as_establish_req(const emm_data_t *emm_data, const emm_as_establish_t *,
-                                 nas_establish_req_t *);
 
 
-static int _emm_as_cell_info_req(const emm_as_cell_info_t *, cell_info_req_t *);
 
-static int _emm_as_data_req(const emm_data_t *emm_data, const emm_as_data_t *msg, ul_info_transfer_req_t *);
-static int _emm_as_status_ind(const emm_data_t *emm_data, const emm_as_status_t *, ul_info_transfer_req_t *);
-static int _emm_as_release_req(const emm_as_release_t *, nas_release_req_t *);
+
+static int _emm_as_cell_info_req(const emm_as_cell_info_t *, cell_info_req_t *);
+/* prototyping of the following function modified: the last parameter turned to a void pointer
+ * instead of a ponter to the union field of the as_msg packed structure. This is to avoid new warnings introduced
+ * from gcc V9 which warns when accessing fields in a packed structure which may result in an alignment problem
+ * at run time. Modifications allow gcc to know at compile time that it cannot assume any alignment for those pointers.
+ * On X86 this is not fatal, as at run time the problem can be fixed (but it's better for perf to avoid). On other 
+ * processor as Arm i think it can end in seg fault
+ */
+static int _emm_as_security_res(const emm_data_t *emm_data, const emm_as_security_t *,
+                                void *ul_info_transfer_req_unaligned);
+static int _emm_as_establish_req(const emm_data_t *emm_data, const emm_as_establish_t *,
+                                 void *nas_establish_req_unaligned);                             
+static int _emm_as_data_req(const emm_data_t *emm_data, const emm_as_data_t *msg, void *ul_info_transfer_req_unaligned);
+static int _emm_as_status_ind(const emm_data_t *emm_data, const emm_as_status_t *, void *ul_info_transfer_req_unaligned);
+static int _emm_as_release_req(const emm_as_release_t *, void *nas_release_req_unaligned);
 
 /****************************************************************************/
 /******************  E X P O R T E D    F U N C T I O N S  ******************/
@@ -938,32 +946,32 @@ static int _emm_as_send(const nas_user_t *user, const emm_as_t *msg)
   case _EMMAS_DATA_REQ:
     as_msg.msgID = _emm_as_data_req(user->emm_data,
                      &msg->u.data,
-                     &as_msg.msg.ul_info_transfer_req);
+                     (void *)(&as_msg.msg.ul_info_transfer_req));
     break;
 
   case _EMMAS_STATUS_IND:
     as_msg.msgID = _emm_as_status_ind(user->emm_data,
                      &msg->u.status,
-                     &as_msg.msg.ul_info_transfer_req);
+                     (void *)(&as_msg.msg.ul_info_transfer_req));
     break;
 
   case _EMMAS_RELEASE_REQ:
     as_msg.msgID = _emm_as_release_req(
                      &msg->u.release,
-                     &as_msg.msg.nas_release_req);
+                     (void *)(&as_msg.msg.nas_release_req));
     break;
 
 
   case _EMMAS_SECURITY_RES:
     as_msg.msgID = _emm_as_security_res(user->emm_data,
                      &msg->u.security,
-                     &as_msg.msg.ul_info_transfer_req);
+                     (void *)(&as_msg.msg.ul_info_transfer_req));
     break;
 
   case _EMMAS_ESTABLISH_REQ:
     as_msg.msgID = _emm_as_establish_req(user->emm_data,
                      &msg->u.establish,
-                     &as_msg.msg.nas_establish_req);
+                     (void *)(&as_msg.msg.nas_establish_req));
     break;
 
 
@@ -1069,10 +1077,10 @@ static int _emm_as_send(const nas_user_t *user, const emm_as_t *msg)
  **                                                                        **
  ***************************************************************************/
 static int _emm_as_data_req(const emm_data_t *emm_data, const emm_as_data_t *msg,
-                            ul_info_transfer_req_t *as_msg)
+                            void *ul_info_transfer_req_unaligned)
 {
   LOG_FUNC_IN;
-
+  ul_info_transfer_req_t *as_msg = (ul_info_transfer_req_t *)ul_info_transfer_req_unaligned;
   int size = 0;
   int is_encoded = FALSE;
 
@@ -1165,12 +1173,12 @@ static int _emm_as_data_req(const emm_data_t *emm_data, const emm_as_data_t *msg
  **                                                                        **
  ***************************************************************************/
 static int _emm_as_status_ind(const emm_data_t *emm_data, const emm_as_status_t *msg,
-                              ul_info_transfer_req_t *as_msg)
+                              void *ul_info_transfer_req_unaligned)
 {
   LOG_FUNC_IN;
 
   int size = 0;
-
+  ul_info_transfer_req_t *as_msg = (ul_info_transfer_req_t *)ul_info_transfer_req_unaligned;
   LOG_TRACE(INFO, "EMMAS-SAP - Send AS status indication (cause=%d)",
             msg->emm_cause);
 
@@ -1239,12 +1247,12 @@ static int _emm_as_status_ind(const emm_data_t *emm_data, const emm_as_status_t
  **                                                                        **
  ***************************************************************************/
 static int _emm_as_release_req(const emm_as_release_t *msg,
-                               nas_release_req_t *as_msg)
+                               void *nas_release_req_unaligned)
 {
   LOG_FUNC_IN;
 
   LOG_TRACE(INFO, "EMMAS-SAP - Send AS release request");
-
+  nas_release_req_t *as_msg = (nas_release_req_t *)nas_release_req_unaligned;
   /* Setup the AS message */
   if (msg->guti) {
     as_msg->s_tmsi.MMEcode = msg->guti->gummei.MMEcode;
@@ -1279,10 +1287,10 @@ static int _emm_as_release_req(const emm_as_release_t *msg,
  **                                                                        **
  ***************************************************************************/
 static int _emm_as_security_res(const emm_data_t *emm_data, const emm_as_security_t *msg,
-                                ul_info_transfer_req_t *as_msg)
+                                void *ul_info_transfer_req_unaligned)
 {
   LOG_FUNC_IN;
-
+  ul_info_transfer_req_t *as_msg=(ul_info_transfer_req_t *)ul_info_transfer_req_unaligned;
   int size = 0;
 
   LOG_TRACE(INFO, "EMMAS-SAP - Send AS security response");
@@ -1373,12 +1381,12 @@ static int _emm_as_security_res(const emm_data_t *emm_data, const emm_as_securit
  **                                                                        **
  ***************************************************************************/
 static int _emm_as_establish_req(const emm_data_t *emm_data, const emm_as_establish_t *msg,
-                                 nas_establish_req_t *as_msg)
+                                 void *nas_establish_req_unaligned)
 {
   LOG_FUNC_IN;
 
   int size = 0;
-
+  nas_establish_req_t *as_msg = (nas_establish_req_t *)nas_establish_req_unaligned;
   LOG_TRACE(INFO, "EMMAS-SAP - Send AS connection establish request");
 
   nas_message_t nas_msg;
diff --git a/openair3/NAS/UE/nas_network.c b/openair3/NAS/UE/nas_network.c
index f8abba4900e8a5936e71ea266c7061c5fa10417c..f6b291bb7bc0687981457303fea6a0d94cadecd8 100644
--- a/openair3/NAS/UE/nas_network.c
+++ b/openair3/NAS/UE/nas_network.c
@@ -141,11 +141,11 @@ int nas_network_process_data(nas_user_t *user, int msg_id, const void *data)
 
   case AS_CELL_INFO_CNF: {
     /* Received cell information confirm */
-    const cell_info_cnf_t *info = &msg->msg.cell_info_cnf;
-    int cell_found = (info->errCode == AS_SUCCESS);
-    rc = nas_proc_cell_info(user, cell_found, info->tac,
-                            info->cellID, info->rat,
-                            info->rsrp, info->rsrq);
+    /* remove using pointers to fiels of the packed structure msg as it
+     * triggers warnings with gcc version 9 */
+    const cell_info_cnf_t info = msg->msg.cell_info_cnf;
+    int cell_found = (info.errCode == AS_SUCCESS);
+    rc = nas_proc_cell_info(user, cell_found, info.tac, info.cellID, info.rat, info.rsrp, info.rsrq);
     break;
   }
 
@@ -157,12 +157,12 @@ int nas_network_process_data(nas_user_t *user, int msg_id, const void *data)
 
   case AS_NAS_ESTABLISH_CNF: {
     /* Received NAS signalling connection establishment confirm */
-    const nas_establish_cnf_t *confirm = &msg->msg.nas_establish_cnf;
+    const nas_establish_cnf_t confirm = msg->msg.nas_establish_cnf;
 
-    if ( (confirm->errCode == AS_SUCCESS) ||
-         (confirm->errCode == AS_TERMINATED_NAS) ) {
-      rc = nas_proc_establish_cnf(user, confirm->nasMsg.data,
-                                  confirm->nasMsg.length);
+    if ( (confirm.errCode == AS_SUCCESS) ||
+         (confirm.errCode == AS_TERMINATED_NAS) ) {
+      rc = nas_proc_establish_cnf(user, confirm.nasMsg.data,
+                                  confirm.nasMsg.length);
     } else {
       LOG_TRACE(WARNING, "NET-MAIN  - "
                 "Initial NAS message not delivered");
@@ -191,10 +191,10 @@ int nas_network_process_data(nas_user_t *user, int msg_id, const void *data)
     break;
 
   case AS_DL_INFO_TRANSFER_IND: {
-    const dl_info_transfer_ind_t *info = &msg->msg.dl_info_transfer_ind;
+    const dl_info_transfer_ind_t info = msg->msg.dl_info_transfer_ind;
     /* Received downlink data transfer indication */
-    rc = nas_proc_dl_transfer_ind(user, info->nasMsg.data,
-                                  info->nasMsg.length);
+    rc = nas_proc_dl_transfer_ind(user, info.nasMsg.data,
+                                  info.nasMsg.length);
     break;
   }
 
diff --git a/openair3/ocp-gtpu/gtp_itf.cpp b/openair3/ocp-gtpu/gtp_itf.cpp
index c367374436fd9b3c78c518f7c198046b3510eb49..ca199c1308dc90e40fa366991d8bf754e195fc08 100644
--- a/openair3/ocp-gtpu/gtp_itf.cpp
+++ b/openair3/ocp-gtpu/gtp_itf.cpp
@@ -74,6 +74,12 @@ class gtpEndPoint {
   int ipVersion;
   map<int,teidData_t> ue2te_mapping;
   map<int,rntiData_t> te2ue_mapping;
+  // we use the same port number for source and destination address
+  // this allow using non standard gtp port number (different from 2152)
+  // and so, for example tu run 4G and 5G cores on one system
+  tcp_udp_port_t get_dstport() {
+	  return (tcp_udp_port_t)atol(addr.destinationService);
+  }
 };
 
 class gtpEndPoints {
@@ -99,6 +105,8 @@ int legacyInstanceMapping=0;
 #define compatInst(a) ((a)==0 || (a)==INSTANCE_DEFAULT?legacyInstanceMapping:a)
 
 #define GTPV1U_HEADER_SIZE                                  (8)
+
+
 static  int gtpv1uCreateAndSendMsg(int h, uint32_t peerIp, uint16_t peerPort, teid_t teid, uint8_t *Msg,int msgLen,
                                    bool seqNumFlag, bool  npduNumFlag, bool extHdrFlag, int seqNum, int npduNum, int extHdrType) {
   AssertFatal(extHdrFlag==false,"Not developped");
@@ -299,7 +307,6 @@ static  int udpServerSocket(openAddr_s addr) {
     LOG_E(GTPU,"getaddrinfo error: %s\n", gai_strerror(status));
     return -1;
   }
-
   int sockfd=-1;
 
   // loop through all the results and bind to the first we can
@@ -459,17 +466,18 @@ int ocp_gtpv1u_create_s1u_tunnel(instance_t instance,
         create_tunnel_req->rnti,
         create_tunnel_req->num_tunnels,
         create_tunnel_req->sgw_S1u_teid[0]);
-
+  tcp_udp_port_t dstport=globGtp.instances[compatInst(instance)].get_dstport();
   for (int i = 0; i < create_tunnel_req->num_tunnels; i++) {
     AssertFatal(create_tunnel_req->eps_bearer_id[i] > 4,
                 "From legacy code not clear, seems impossible (bearer=%d)\n",
                 create_tunnel_req->eps_bearer_id[i]);
     int incoming_rb_id=create_tunnel_req->eps_bearer_id[i]-4;
+
     teid_t teid=newGtpuCreateTunnel(compatInst(instance), create_tunnel_req->rnti,
                                     incoming_rb_id,
                                     create_tunnel_req->eps_bearer_id[i],
                                     create_tunnel_req->sgw_S1u_teid[i],
-                                    create_tunnel_req->sgw_addr[i], 2152,
+                                    create_tunnel_req->sgw_addr[i],  dstport,
                                     pdcp_data_req);
     create_tunnel_resp->status=0;
     create_tunnel_resp->rnti=create_tunnel_req->rnti;
@@ -525,13 +533,13 @@ int gtpv1u_create_ngu_tunnel(  const instance_t instance,
         create_tunnel_req->rnti,
         create_tunnel_req->num_tunnels,
         create_tunnel_req->upf_NGu_teid[0]);
-
+  tcp_udp_port_t dstport=globGtp.instances[compatInst(instance)].get_dstport();
   for (int i = 0; i < create_tunnel_req->num_tunnels; i++) {
     teid_t teid=newGtpuCreateTunnel(compatInst(instance), create_tunnel_req->rnti,
                                     create_tunnel_req->incoming_rb_id[i],
                                     create_tunnel_req->pdusession_id[i],
                                     create_tunnel_req->upf_NGu_teid[i],
-                                    create_tunnel_req->upf_addr[i], 2152,
+                                    create_tunnel_req->upf_addr[i],  dstport,
                                     pdcp_data_req);
     create_tunnel_resp->status=0;
     create_tunnel_resp->rnti=create_tunnel_req->rnti;
@@ -869,6 +877,7 @@ void *ocp_gtpv1uTask(void *args)  {
           // to be dev: should be removed, to use API
           strcpy(addr.originHost, GTPV1U_ENB_S1_REQ(message_p).addrStr);
           strcpy(addr.originService, GTPV1U_ENB_S1_REQ(message_p).portStr);
+          strcpy(addr.destinationService,addr.originService);
           AssertFatal((legacyInstanceMapping=ocp_gtpv1Init(addr))!=0,"Instance 0 reserved for legacy\n");
           break;
 
@@ -876,6 +885,7 @@ void *ocp_gtpv1uTask(void *args)  {
           // to be dev: should be removed, to use API
           strcpy(addr.originHost, GTPV1U_ENB_S1_REQ(message_p).addrStr);
           strcpy(addr.originService, GTPV1U_ENB_S1_REQ(message_p).portStr);
+          strcpy(addr.destinationService,addr.originService);
           AssertFatal((legacyInstanceMapping=ocp_gtpv1Init(addr))!=0,"Instance 0 reserved for legacy\n");
           break;