diff --git a/NOTICE.md b/NOTICE.md
index 96b5d4c552ed9752d8a8ba396c9c4df4293dc34b..39dd33795d71fa7b42d86a6ddc4fe9b7a6048c7d 100644
--- a/NOTICE.md
+++ b/NOTICE.md
@@ -21,3 +21,7 @@ The Regents of the University of California: BSD 3-Clause Licence.
 
 Niels Provos <provos@citi.umich.edu>: BSD 2-Clause Licence.
 
+## Credits for source code openair3/GTPV1-U/nw-gtpv1u: ##
+
+Amit Chawre <http://www.amitchawre.net/contact.html>: BSD 2-Clause Licence.
+
diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab
index c3b997a4e89e015722df42a63979073cae3f3351..7e9e3800db52200f5d8196e9b3a187c2f39282a4 100644
--- a/ci-scripts/Jenkinsfile-gitlab
+++ b/ci-scripts/Jenkinsfile-gitlab
@@ -30,7 +30,6 @@ def sendSocialMediaMessage(pipeChannel, pipeColor, pipeMessage) {
     }
 }
 
-def doRedHatBuild = false
 def doFlexranCtrlTest = false
 
 // Location of the executor node
@@ -85,21 +84,6 @@ pipeline {
                         echo "Platform is ${env.TESTPLATFORM_OWNER}"
                     }
 
-                    if (params.RedHatRemoteServer == null) {
-                        allParametersPresent = false
-                    }
-                    if (params.RedHatRemoteCredentials == null) {
-                        allParametersPresent = false
-                    }
-                    if (params.RedHatWorkingPath == null) {
-                        allParametersPresent = false
-                    }
-                    if (allParametersPresent) {
-                        echo "Performing Red Hat Build"
-                        doRedHatBuild = true
-                    } else {
-                        doRedHatBuild = false
-                    }
                     if (params.FlexRanRtcGitLabRepository_Credentials != null) {
                         doFlexranCtrlTest = true
                     }
@@ -279,7 +263,7 @@ pipeline {
                     steps {
                         gitlabCommitStatus(name: "Build eNB-USRP") {
                             timeout (time: 20, unit: 'MINUTES') {
-                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID} --keep-vm-alive"
+                                sh "./ci-scripts/oai-ci-vm-tool wait --workspace $WORKSPACE --variant enb-usrp --job-name ${JOB_NAME} --build-id ${BUILD_ID}"
                             }
                         }
                     }
@@ -311,28 +295,6 @@ pipeline {
                         }
                     }
                 }
-                stage ("Build eNB-USRP on Red Hat") {
-                    when {
-                        expression {doRedHatBuild}
-                    }
-                    steps {
-                        gitlabCommitStatus(name: "Build eNB-USRP-RHE") {
-                            script {
-                                try {
-                                    withCredentials([
-                                        [$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.RedHatRemoteCredentials}", usernameVariable: 'RH_Username', passwordVariable: 'RH_Password']
-                                    ]) {
-                                        timeout (time: 20, unit: 'MINUTES') {
-                                            sh "./ci-scripts/buildOnRH.sh --workspace $WORKSPACE --job-name ${JOB_NAME} --build-id ${BUILD_ID} --remote-host ${params.RedHatRemoteServer} --remote-path ${params.RedHatWorkingPath} --remote-user-name ${RH_Username} --remote-password ${RH_Password}"
-                                        }
-                                    }
-                                } catch (Exception e) {
-                                    echo "Red Hat build failed but we could keep running pipeline if all ubuntu-based build passed"
-                                }
-                            }
-                        }
-                    }
-                }
             }
             post {
                 failure {
diff --git a/ci-scripts/checkCodingFormattingRules.sh b/ci-scripts/checkCodingFormattingRules.sh
index fb159d4da07db4662a48f297c5646c807ee05084..d47b90a9dd297d9711ed33d057e7cd8fa50c8910 100755
--- a/ci-scripts/checkCodingFormattingRules.sh
+++ b/ci-scripts/checkCodingFormattingRules.sh
@@ -77,7 +77,7 @@ then
        IS_NFAPI=`echo $FILE | egrep -c "nfapi/open-nFAPI|nfapi/oai_integration/vendor_ext"`
        IS_OAI_LICENCE_PRESENT=`egrep -c "OAI Public License" $FILE`
        IS_BSD_LICENCE_PRESENT=`egrep -c "the terms of the BSD Licence" $FILE`
-       IS_EXCEPTION=`echo $FILE | egrep -c "common/utils/collection/tree.h|common/utils/collection/queue.h|common/utils/itti_analyzer/common/queue.h|openair3/UTILS/tree.h|openair3/UTILS/queue.h"`
+       IS_EXCEPTION=`echo $FILE | egrep -c "common/utils/collection/tree.h|common/utils/collection/queue.h|common/utils/itti_analyzer/common/queue.h|openair3/UTILS/tree.h|openair3/UTILS/queue.h|openair3/GTPV1-U/nw-gtpv1u|openair2/UTIL/OPT/ws_"`
        if [ $IS_OAI_LICENCE_PRESENT -eq 0 ] && [ $IS_BSD_LICENCE_PRESENT -eq 0 ]
        then
            if [ $IS_NFAPI -eq 0 ] && [ $IS_EXCEPTION -eq 0 ]
@@ -194,12 +194,12 @@ do
             IS_NFAPI=`echo $FULLFILE | egrep -c "nfapi/open-nFAPI|nfapi/oai_integration/vendor_ext"`
             IS_OAI_LICENCE_PRESENT=`egrep -c "OAI Public License" $FULLFILE`
             IS_BSD_LICENCE_PRESENT=`egrep -c "the terms of the BSD Licence" $FULLFILE`
-            IS_EXCEPTION=`echo $FILE | egrep -c "common/utils/collection/tree.h|common/utils/collection/queue.h|common/utils/itti_analyzer/common/queue.h|openair3/UTILS/tree.h|openair3/UTILS/queue.h"`
+            IS_EXCEPTION=`echo $FULLFILE | egrep -c "common/utils/collection/tree.h|common/utils/collection/queue.h|common/utils/itti_analyzer/common/queue.h|openair3/UTILS/tree.h|openair3/UTILS/queue.h|openair3/GTPV1-U/nw-gtpv1u|openair2/UTIL/OPT/ws_"`
             if [ $IS_OAI_LICENCE_PRESENT -eq 0 ] && [ $IS_BSD_LICENCE_PRESENT -eq 0 ]
             then
                 if [ $IS_NFAPI -eq 0 ] && [ $IS_EXCEPTION -eq 0 ]
                 then
-                    echo $FILE >> ./files-w-suspect-banner.txt
+                    echo $FULLFILE >> ./files-w-suspect-banner.txt
                 fi
             fi
         fi
diff --git a/common/utils/T/defs.h b/common/utils/T/defs.h
index 69b379ce0b3c3963475622ec3ed6d66b472ed97b..a194e621db6fa0e336476431a55e23a8f570d752 100644
--- a/common/utils/T/defs.h
+++ b/common/utils/T/defs.h
@@ -1,5 +1,5 @@
-#ifndef _TRACER_DEFS_H_
-#define _TRACER_DEFS_H_
+#ifndef _COMMON_UTILS_T_DEFS_H_
+#define _COMMON_UTILS_T_DEFS_H_
 
 /* types of plots */
 #define PLOT_VS_TIME   0
@@ -27,4 +27,4 @@ void *forwarder(char *ip, int port);
 void forward(void *forwarder, char *buf, int size);
 void forward_start_client(void *forwarder, int socket);
 
-#endif /* _TRACER_DEFS_H_ */
+#endif /* _COMMON_UTILS_T_DEFS_H_ */
diff --git a/common/utils/T/tracer/defs.h b/common/utils/T/tracer/defs.h
index 443fabdde8423ed744d1739f54acc82cef1c5c50..394351eab0f5b658df53817b27d346837c2d65c3 100644
--- a/common/utils/T/tracer/defs.h
+++ b/common/utils/T/tracer/defs.h
@@ -1,5 +1,5 @@
-#ifndef _TRACER_DEFS_H_
-#define _TRACER_DEFS_H_
+#ifndef _COMMON_UTILS_T_TRACER_DEFS_H_
+#define _COMMON_UTILS_T_TRACER_DEFS_H_
 
 /* types of plots */
 #define PLOT_VS_TIME   0
@@ -21,4 +21,4 @@ void t_gui_start(void);
 void t_gui_set_input_signal(int eNB, int frame, int subframe, int antenna,
     int size, void *buf);
 
-#endif /* _TRACER_DEFS_H_ */
+#endif /* _COMMON_UTILS_T_TRACER_DEFS_H_ */
diff --git a/doc/TESTING_GNB_W_COTS_UE.md b/doc/TESTING_GNB_W_COTS_UE.md
index 198f6bb115c1265969f5fb2f7e797fbe2ede3d1b..17f37ad2d7875c980a4ef55bdbe490c474dc0408 100644
--- a/doc/TESTING_GNB_W_COTS_UE.md
+++ b/doc/TESTING_GNB_W_COTS_UE.md
@@ -12,6 +12,7 @@ STATUS 2020/09/10 : updated the status of interop (end to end UL/DL traffic)
 7.   [Log file monitoring](#log-file-monitoring)
 6.   [Required tools for debug](#required-tools-for-debug)
 7.   [Status of interoperability](#status-of-interoperability) 
+8.   [CI integration](#ci-integration)  
 
 ## Configuration Overview
 
@@ -70,7 +71,7 @@ cd cmake_targets/
 - **EPC**
 
 for reference:
-https://github.com/OPENAIRINTERFACE/openair-epc-fed/blob/master-documentation/docs/DEPLOY_HOME.md
+https://github.com/OPENAIRINTERFACE/openair-epc-fed/blob/master/docs/DEPLOY_HOME.md
 
 
 
@@ -204,7 +205,7 @@ The test takes typically a few seconds, max 10-15 seconds. If it takes more than
 - **EPC** (on EPC host):
 
 for reference:
-https://github.com/OPENAIRINTERFACE/openair-epc-fed/blob/master-documentation/docs/DEPLOY_HOME.md
+https://github.com/OPENAIRINTERFACE/openair-epc-fed/blob/master/docs/DEPLOY_HOME.md
 
 
 
@@ -384,3 +385,16 @@ The following parts have been validated with FR1 COTS UE:
     some packet losses might still occur even in ideal channel conditions  
 
 
+## CI integration  
+The automation scripts are available on ILIADE.  
+The end-to-end test is integrated in the CI flow in a semi-automated manner, comprising 3 steps:  
+- update a YAML file comprising the IT resources definition, branch and commit number the test has to run on   
+- run the python script that generates the test from the YAML file  
+```
+python3 obj_build_from_yaml.py py_params_template.yaml fr1.sh
+```
+- run the test (fr1.sh)
+
+At the date of writing, the test comprises the deployment of the components (epc, eNB, gNB, cots ue) and the execution of 2 pings procedures (20 pings in 20sec, then 5 pings in 1sec)  
+
+This automation is run for every integration branch to be merged into develop.
diff --git a/executables/stats.h b/executables/stats.h
index 6c847a2860662e1aec2afebb751a4a122a342b6e..9bd4c6f08099ff3f5c6694356c9424af66cf72d2 100644
--- a/executables/stats.h
+++ b/executables/stats.h
@@ -21,8 +21,8 @@
 
 /* Header file generated by fdesign on Thu Aug 28 12:13:51 2014 */
 
-#ifndef FD_stats_form_h_
-#define FD_stats_form_h_
+#ifndef _EXECUTABLES_STATS_H_
+#define _EXECUTABLES_STATS_H_
 
 #include <forms.h>
 
@@ -43,4 +43,4 @@ typedef struct {
 
 extern FD_stats_form *create_form_stats_form( void );
 
-#endif /* FD_stats_form_h_ */
+#endif /* _EXECUTABLES_STATS_H_ */
diff --git a/executables/threads_t.h b/executables/threads_t.h
index 0671f409883256b4db50e1c9c68778a1840ae5ef..c4b233ccc9d14112a4c4c03ce38932135ec596c9 100644
--- a/executables/threads_t.h
+++ b/executables/threads_t.h
@@ -1,5 +1,5 @@
-#ifndef _THREADS_T_H_
-#define _THREADS_T_H_
+#ifndef _EXECUTABLES_THREADS_T_H_
+#define _EXECUTABLES_THREADS_T_H_
 
 typedef struct threads_s {
   int main;
@@ -18,4 +18,4 @@ typedef struct threads_s {
   //int dlsch_td1_three;
 } threads_t;
 
-#endif /* _THREADS_T_H_ */
+#endif /* _EXECUTABLES_THREADS_T_H_ */
diff --git a/openair1/PHY/NR_TRANSPORT/pucch_rx.c b/openair1/PHY/NR_TRANSPORT/pucch_rx.c
index 71132b64c55a282221ad841d3bab04b3cedeb8ff..bee868b5a59ba090ccbb0223520f915004b6efa3 100644
--- a/openair1/PHY/NR_TRANSPORT/pucch_rx.c
+++ b/openair1/PHY/NR_TRANSPORT/pucch_rx.c
@@ -67,7 +67,7 @@ int nr_find_pucch(uint16_t rnti,
   AssertFatal(gNB!=NULL,"gNB is null\n");
   int index = -1;
 
-  for (int i=0; i<NUMBER_OF_NR_ULSCH_MAX; i++) {
+  for (int i=0; i<NUMBER_OF_NR_PUCCH_MAX; i++) {
     AssertFatal(gNB->pucch[i]!=NULL,"gNB->pucch[%d] is null\n",i);
     if ((gNB->pucch[i]->active >0) &&
         (gNB->pucch[i]->pucch_pdu.rnti==rnti) &&
@@ -414,7 +414,7 @@ void nr_decode_pucch0(PHY_VARS_gNB *gNB,
     uci_pdu->harq->harq_confidence_level = (no_conf) ? 1 : 0;
     uci_pdu->harq->harq_list = (nfapi_nr_harq_t*)malloc(1);
     uci_pdu->harq->harq_list[0].harq_value = index&0x01;
-    LOG_I(PHY, "HARQ value %d with confidence level (0 is good, 1 is bad) %d\n",
+    LOG_D(PHY, "HARQ value %d with confidence level (0 is good, 1 is bad) %d\n",
           uci_pdu->harq->harq_list[0].harq_value,uci_pdu->harq->harq_confidence_level);
     if (pucch_pdu->sr_flag == 1) {
       uci_pdu->sr = calloc(1,sizeof(*uci_pdu->sr));
@@ -429,7 +429,7 @@ void nr_decode_pucch0(PHY_VARS_gNB *gNB,
     uci_pdu->harq->harq_list = (nfapi_nr_harq_t*)malloc(2);
     uci_pdu->harq->harq_list[1].harq_value = index&0x01;
     uci_pdu->harq->harq_list[0].harq_value = (index>>1)&0x01;
-    LOG_I(PHY, "HARQ values %d and %d with confidence level (0 is good, 1 is bad) %d\n",
+    LOG_D(PHY, "HARQ values %d and %d with confidence level (0 is good, 1 is bad) %d\n",
           uci_pdu->harq->harq_list[1].harq_value,uci_pdu->harq->harq_list[0].harq_value,uci_pdu->harq->harq_confidence_level);
     if (pucch_pdu->sr_flag == 1) {
       uci_pdu->sr = calloc(1,sizeof(*uci_pdu->sr));
diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
index 5d67dcd3e45c5ff87452981e8c064b0a27c20e36..d24c88fd1fe4bdccdff04f251e2c802fe1613310 100644
--- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
+++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c
@@ -1669,7 +1669,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
   // looking for pbch only in slot where it is supposed to be
   if ((ue->decode_MIB == 1) && slot_pbch)
     {
-      LOG_I(PHY," ------  PBCH ChannelComp/LLR: frame.slot %d.%d ------  \n", frame_rx%1024, nr_tti_rx);
+      LOG_D(PHY," ------  PBCH ChannelComp/LLR: frame.slot %d.%d ------  \n", frame_rx%1024, nr_tti_rx);
       for (int i=1; i<4; i++) {
 
 	nr_slot_fep(ue,
@@ -1690,7 +1690,7 @@ int phy_procedures_nrUE_RX(PHY_VARS_NR_UE *ue,
       nr_ue_pbch_procedures(gNB_id, ue, proc, 0);
 
       if (ue->no_timing_correction==0) {
-        LOG_I(PHY,"start adjust sync slot = %d no timing %d\n", nr_tti_rx, ue->no_timing_correction);
+        LOG_D(PHY,"start adjust sync slot = %d no timing %d\n", nr_tti_rx, ue->no_timing_correction);
         nr_adjust_synch_ue(fp,
                            ue,
                            gNB_id,
diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c
index 200508cc676d745712719617a0865f7355057630..6e703c2328f42fe53074164462462fb07eb1fb42 100644
--- a/openair1/SIMULATION/NR_PHY/dlsim.c
+++ b/openair1/SIMULATION/NR_PHY/dlsim.c
@@ -697,7 +697,7 @@ int main(int argc, char **argv)
   
 
   nr_ue_phy_config_request(&UE_mac->phy_config);
-  NR_UE_list_t *UE_list = &RC.nrmac[0]->UE_list;
+  NR_UE_info_t *UE_info = &RC.nrmac[0]->UE_info;
   //NR_COMMON_channels_t *cc = RC.nrmac[0]->common_channels;
   snrRun = 0;
 
@@ -758,11 +758,11 @@ int main(int argc, char **argv)
         memset(RC.nrmac[0]->cce_list[1][1],0,MAX_NUM_CCE*sizeof(int));
         clear_nr_nfapi_information(RC.nrmac[0], 0, frame, slot);
 
-        UE_list->UE_sched_ctrl[0].harq_processes[harq_pid].ndi = !(trial&1);
+        UE_info->UE_sched_ctrl[0].harq_processes[harq_pid].ndi = !(trial&1);
 
 
-        UE_list->UE_sched_ctrl[0].harq_processes[harq_pid].round = round;   
-        UE_list->UE_sched_ctrl[0].current_harq_pid = harq_pid;
+        UE_info->UE_sched_ctrl[0].harq_processes[harq_pid].round = round;
+        UE_info->UE_sched_ctrl[0].current_harq_pid = harq_pid;
         gNB->dlsch[0][0]->harq_processes[harq_pid]->round = round;
       
         if (css_flag == 0) nr_schedule_uss_dlsch_phytest(0,frame,slot,&pucch_sched,&dlsch_config);
diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c
index 4e46603dc92c9d9ed8a9e620886c78cfcc63e63b..ad8409de69db0484f684c48ed49236a01adf42ff 100644
--- a/openair2/LAYER2/NR_MAC_gNB/config.c
+++ b/openair2/LAYER2/NR_MAC_gNB/config.c
@@ -46,6 +46,9 @@
 #include "NR_MIB.h"
 #include "LAYER2/NR_MAC_COMMON/nr_mac_common.h"
 
+/* Softmodem params */
+#include "executables/softmodem-common.h"
+
 extern RAN_CONTEXT_t RC;
 //extern int l2_init_gNB(void);
 extern void mac_top_init_gNB(void);
@@ -346,22 +349,34 @@ int rrc_mac_config_req_gNB(module_id_t Mod_idP,
   
   if (secondaryCellGroup) {
 
-    NR_UE_list_t *UE_list = &RC.nrmac[Mod_idP]->UE_list;
-    int UE_id;
-    if (add_ue == 1) {
-      UE_id = add_new_nr_ue(Mod_idP,rnti);
-      UE_list->secondaryCellGroup[UE_id] = secondaryCellGroup;
-      uint8_t num_preamble = secondaryCellGroup->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated->choice.uplink->cfra->resources.choice.ssb->ssb_ResourceList.list.count;
-      UE_list->preambles[UE_id].num_preambles = num_preamble;
-      UE_list->preambles[UE_id].preamble_list = (uint8_t *) malloc(num_preamble*sizeof(uint8_t));
-      for (int i=0; i<num_preamble; i++) {
-        UE_list->preambles[UE_id].preamble_list[i] = secondaryCellGroup->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated->choice.uplink->cfra->resources.choice.ssb->ssb_ResourceList.list.array[i]->ra_PreambleIndex;
-      }
+    NR_UE_info_t *UE_info = &RC.nrmac[Mod_idP]->UE_info;
+    if (add_ue == 1 && get_softmodem_params()->phy_test) {
+      const int UE_id = add_new_nr_ue(Mod_idP,rnti);
+      UE_info->secondaryCellGroup[UE_id] = secondaryCellGroup;
+      struct NR_ServingCellConfig__downlinkBWP_ToAddModList *bwpList =
+          secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList;
+      AssertFatal(bwpList->list.count == 1,
+                  "downlinkBWP_ToAddModList has %d BWP!\n",
+                  bwpList->list.count);
+      const int bwp_id = 1;
+      UE_info->UE_sched_ctrl[UE_id].active_bwp = bwpList->list.array[bwp_id - 1];
       LOG_I(PHY,"Added new UE_id %d/%x with initial secondaryCellGroup\n",UE_id,rnti);
-    }
-    else { // secondaryCellGroup has been updated
-      UE_id = find_nr_UE_id(Mod_idP,rnti);
-      UE_list->secondaryCellGroup[UE_id] = secondaryCellGroup;
+    } else if (add_ue == 1 && !get_softmodem_params()->phy_test) {
+      /* TODO: should check for free RA process */
+      const int CC_id = 0;
+      NR_RA_t *ra = &RC.nrmac[Mod_idP]->common_channels[CC_id].ra[0];
+      ra->state = RA_IDLE;
+      ra->secondaryCellGroup = secondaryCellGroup;
+      ra->crnti = rnti;
+      uint8_t num_preamble = secondaryCellGroup->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated->choice.uplink->cfra->resources.choice.ssb->ssb_ResourceList.list.count;
+      ra->preambles.num_preambles = num_preamble;
+      ra->preambles.preamble_list = (uint8_t *) malloc(num_preamble*sizeof(uint8_t));
+      for (int i = 0; i < num_preamble; i++)
+        ra->preambles.preamble_list[i] = secondaryCellGroup->spCellConfig->reconfigurationWithSync->rach_ConfigDedicated->choice.uplink->cfra->resources.choice.ssb->ssb_ResourceList.list.array[i]->ra_PreambleIndex;
+      LOG_I(PHY,"Added new RA process for UE RNTI %04x with initial secondaryCellGroup\n", rnti);
+    } else { // secondaryCellGroup has been updated
+      const int UE_id = find_nr_UE_id(Mod_idP,rnti);
+      UE_info->secondaryCellGroup[UE_id] = secondaryCellGroup;
       LOG_I(PHY,"Modified UE_id %d/%x with secondaryCellGroup\n",UE_id,rnti);
     }
   }
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
index 548845eae5db766f19fa07cb1b1be6e3e92f524b..5a330daf149ee14fbeff1cb81fcec212c049c5d2 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
@@ -63,19 +63,19 @@ const uint8_t slots_per_frame[5] = {10, 20, 40, 80, 160};
 uint16_t nr_pdcch_order_table[6] = { 31, 31, 511, 2047, 2047, 8191 };
 
 void clear_mac_stats(gNB_MAC_INST *gNB) {
-  memset((void*)gNB->UE_list.mac_stats,0,MAX_MOBILES_PER_GNB*sizeof(NR_mac_stats_t));
+  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) {
 
-  NR_UE_list_t *UE_list = &gNB->UE_list;
+  NR_UE_info_t *UE_info = &gNB->UE_info;
   NR_mac_stats_t *stats;
   int lc_id;
 
   for (int UE_id=0;UE_id<MAX_MOBILES_PER_GNB;UE_id++) {
-    if (UE_list->active[UE_id] == TRUE) {
-      LOG_I(MAC,"UE %x\n",UE_list->rnti[UE_id]);
-      stats = &UE_list->mac_stats[UE_id];
+    if (UE_info->active[UE_id]) {
+      LOG_I(MAC, "UE %x\n", UE_info->rnti[UE_id]);
+      stats = &UE_info->mac_stats[UE_id];
       LOG_I(MAC,"dlsch_rounds %d/%d/%d/%d, dlsch_errors %d\n",stats->dlsch_rounds[0],stats->dlsch_rounds[1],stats->dlsch_rounds[2],stats->dlsch_rounds[3],stats->dlsch_errors);
       LOG_I(MAC,"dlsch_total_bytes %d\n",stats->dlsch_total_bytes);
       LOG_I(MAC,"ulsch_rounds %d/%d/%d/%d, ulsch_errors %d\n",stats->ulsch_rounds[0],stats->ulsch_rounds[1],stats->ulsch_rounds[2],stats->ulsch_rounds[3],stats->ulsch_errors);
@@ -130,18 +130,18 @@ void check_nr_ul_failure(module_id_t module_idP,
                          frame_t frameP,
                          sub_frame_t slotP) {
 
-  UE_list_t                     *UE_list  = &RC.nrmac[module_idP]->UE_list;
+  NR_UE_info_t                 *UE_info  = &RC.nrmac[module_idP]->UE_info;
   nfapi_nr_dl_dci_request_t  *DL_req   = &RC.nrmac[module_idP]->DL_req[0];
   uint16_t                      rnti      = UE_RNTI(module_idP, UE_id);
   NR_COMMON_channels_t          *cc       = RC.nrmac[module_idP]->common_channels;
 
   // check uplink failure
-  if ((UE_list->UE_sched_ctrl[UE_id].ul_failure_timer > 0) &&
-      (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 0)) {
+  if ((UE_info->UE_sched_ctrl[UE_id].ul_failure_timer > 0) &&
+      (UE_info->UE_sched_ctrl[UE_id].ul_out_of_sync == 0)) {
     LOG_I(MAC, "UE %d rnti %x: UL Failure timer %d \n", UE_id, rnti,
-    UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);
-    if (UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent == 0) {
-      UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent = 1;
+    UE_info->UE_sched_ctrl[UE_id].ul_failure_timer);
+    if (UE_info->UE_sched_ctrl[UE_id].ra_pdcch_order_sent == 0) {
+      UE_info->UE_sched_ctrl[UE_id].ra_pdcch_order_sent = 1;
 
       // add a format 1A dci for this UE to request an RA procedure (only one UE per subframe)
       nfapi_nr_dl_dci_request_pdu_t *dl_config_pdu                    = &DL_req[CC_id].dl_tti_request_body.dl_config_pdu_list[DL_req[CC_id].dl_tti_request_body.number_pdu];
@@ -151,7 +151,7 @@ void check_nr_ul_failure(module_id_t module_idP,
       dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag                = NFAPI_DL_DCI_REQUEST_DCI_DL_PDU_REL8_TAG;
       dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format            = NFAPI_DL_DCI_FORMAT_1A;
       dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level     = get_aggregation(get_bw_index(module_idP, CC_id),
-                      UE_list->UE_sched_ctrl[UE_id].
+                      UE_info->UE_sched_ctrl[UE_id].
                       dl_cqi[CC_id], format1A);
       dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                  = rnti;
       dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type             = 1;  // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications
@@ -167,27 +167,27 @@ void check_nr_ul_failure(module_id_t module_idP,
       LOG_I(MAC,
       "UE %d rnti %x: sending PDCCH order for RAPROC (failure timer %d), resource_block_coding %d \n",
       UE_id, rnti,
-      UE_list->UE_sched_ctrl[UE_id].ul_failure_timer,
+      UE_info->UE_sched_ctrl[UE_id].ul_failure_timer,
       dl_config_pdu->dci_dl_pdu.
       dci_dl_pdu_rel8.resource_block_coding);
     } else {    // ra_pdcch_sent==1
       LOG_I(MAC,
       "UE %d rnti %x: sent PDCCH order for RAPROC waiting (failure timer %d) \n",
       UE_id, rnti,
-      UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);
-      if ((UE_list->UE_sched_ctrl[UE_id].ul_failure_timer % 40) == 0) UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent = 0;  // resend every 4 frames
+      UE_info->UE_sched_ctrl[UE_id].ul_failure_timer);
+      if ((UE_info->UE_sched_ctrl[UE_id].ul_failure_timer % 40) == 0) UE_info->UE_sched_ctrl[UE_id].ra_pdcch_order_sent = 0;  // resend every 4 frames
     }
 
-    UE_list->UE_sched_ctrl[UE_id].ul_failure_timer++;
+    UE_info->UE_sched_ctrl[UE_id].ul_failure_timer++;
     // check threshold
-    if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer > 20000) {
+    if (UE_info->UE_sched_ctrl[UE_id].ul_failure_timer > 20000) {
       // inform RRC of failure and clear timer
       LOG_I(MAC,
       "UE %d rnti %x: UL Failure after repeated PDCCH orders: Triggering RRC \n",
       UE_id, rnti);
       mac_eNB_rrc_ul_failure(module_idP, CC_id, frameP, subframeP,rnti);
-      UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
-      UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync   = 1;
+      UE_info->UE_sched_ctrl[UE_id].ul_failure_timer = 0;
+      UE_info->UE_sched_ctrl[UE_id].ul_out_of_sync   = 1;
 
       //Inform the controller about the UE deactivation. Should be moved to RRC agent in the future
       if (rrc_agent_registered[module_idP]) {
@@ -204,7 +204,7 @@ void check_nr_ul_failure(module_id_t module_idP,
 void schedule_nr_SRS(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 {
   gNB_MAC_INST *gNB = RC.nrmac[module_idP];
-  UE_list_t *UE_list = &gNB->UE_list;
+  NR_UE_info_t *UE_info = &gNB->UE_info;
   nfapi_ul_config_request_body_t *ul_req;
   int CC_id, UE_id;
   NR_COMMON_channels_t *cc = RC.nrmac[module_idP]->common_channels;
@@ -238,16 +238,16 @@ void schedule_nr_SRS(module_id_t module_idP, frame_t frameP, sub_frame_t subfram
       if ((1 << tmp) & deltaTSFC) {
   // This is an SRS subframe, loop over UEs
   for (UE_id = 0; UE_id < MAX_MOBILES_PER_GNB; UE_id++) {
-    if (!RC.nrmac[module_idP]->UE_list.active[UE_id]) continue;
+    if (!RC.nrmac[module_idP]->UE_info.active[UE_id]) continue;
     ul_req = &RC.nrmac[module_idP]->UL_req[CC_id].ul_config_request_body;
     // drop the allocation if the UE hasn't send RRCConnectionSetupComplete yet
     if (mac_eNB_get_rrc_status(module_idP,UE_RNTI(module_idP, UE_id)) < RRC_CONNECTED) continue;
 
-    AssertFatal(UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated != NULL,
+    AssertFatal(UE_info->UE_template[CC_id][UE_id].physicalConfigDedicated != NULL,
           "physicalConfigDedicated is null for UE %d\n",
           UE_id);
 
-    if ((soundingRS_UL_ConfigDedicated = UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->soundingRS_UL_ConfigDedicated) != NULL) {
+    if ((soundingRS_UL_ConfigDedicated = UE_info->UE_template[CC_id][UE_id].physicalConfigDedicated->soundingRS_UL_ConfigDedicated) != NULL) {
       if (soundingRS_UL_ConfigDedicated->present == SoundingRS_UL_ConfigDedicated_PR_setup) {
         get_srs_pos(&cc[CC_id],
         soundingRS_UL_ConfigDedicated->choice.
@@ -262,7 +262,7 @@ void schedule_nr_SRS(module_id_t module_idP, frame_t frameP, sub_frame_t subfram
     ul_config_pdu->pdu_size =  2 + (uint8_t) (2 + sizeof(nfapi_ul_config_srs_pdu));
     ul_config_pdu->srs_pdu.srs_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL8_TAG;
     ul_config_pdu->srs_pdu.srs_pdu_rel8.size = (uint8_t)sizeof(nfapi_ul_config_srs_pdu);
-    ul_config_pdu->srs_pdu.srs_pdu_rel8.rnti = UE_list->UE_template[CC_id][UE_id].rnti;
+    ul_config_pdu->srs_pdu.srs_pdu_rel8.rnti = UE_info->UE_template[CC_id][UE_id].rnti;
     ul_config_pdu->srs_pdu.srs_pdu_rel8.srs_bandwidth = soundingRS_UL_ConfigDedicated->choice.setup.srs_Bandwidth;
     ul_config_pdu->srs_pdu.srs_pdu_rel8.frequency_domain_position = soundingRS_UL_ConfigDedicated->choice.setup.freqDomainPosition;
     ul_config_pdu->srs_pdu.srs_pdu_rel8.srs_hopping_bandwidth = soundingRS_UL_ConfigDedicated->choice.setup.srs_HoppingBandwidth;;
@@ -275,7 +275,7 @@ void schedule_nr_SRS(module_id_t module_idP, frame_t frameP, sub_frame_t subfram
     ul_req->number_of_pdus++;
         } // if (((10*frameP+subframeP) % srsPeriodicity) == srsOffset)
       } // if (soundingRS_UL_ConfigDedicated->present == SoundingRS_UL_ConfigDedicated_PR_setup)
-    }   // if ((soundingRS_UL_ConfigDedicated = UE_list->UE_template[CC_id][UE_id].physicalConfigDedicated->soundingRS_UL_ConfigDedicated)!=NULL)
+    }   // if ((soundingRS_UL_ConfigDedicated = UE_info->UE_template[CC_id][UE_id].physicalConfigDedicated->soundingRS_UL_ConfigDedicated)!=NULL)
   }   // for (UE_id ...
       }     // if((1<<tmp) & deltaTSFC)
 
@@ -322,9 +322,9 @@ void nr_schedule_pusch(int Mod_idP,
                        sub_frame_t slotP) {
 
   nfapi_nr_ul_tti_request_t *UL_tti_req = &RC.nrmac[Mod_idP]->UL_tti_req[0];
-  NR_UE_list_t *UE_list = &RC.nrmac[Mod_idP]->UE_list;
+  NR_UE_info_t *UE_info = &RC.nrmac[Mod_idP]->UE_info;
   int k = slotP + ul_slots - num_slots_per_tdd;
-  NR_sched_pusch *pusch = &UE_list->UE_sched_ctrl[UE_id].sched_pusch[k];
+  NR_sched_pusch *pusch = &UE_info->UE_sched_ctrl[UE_id].sched_pusch[k];
   if ((pusch->active == true) && (frameP == pusch->frame) && (slotP == pusch->slot)) {
     UL_tti_req->SFN = pusch->frame;
     UL_tti_req->Slot = pusch->slot;
@@ -332,7 +332,7 @@ void nr_schedule_pusch(int Mod_idP,
     UL_tti_req->pdus_list[UL_tti_req->n_pdus].pdu_size = sizeof(nfapi_nr_pusch_pdu_t);
     UL_tti_req->pdus_list[UL_tti_req->n_pdus].pusch_pdu = pusch->pusch_pdu;
     UL_tti_req->n_pdus+=1;
-    memset((void *) &UE_list->UE_sched_ctrl[UE_id].sched_pusch[k],
+    memset((void *) &UE_info->UE_sched_ctrl[UE_id].sched_pusch[k],
            0, sizeof(NR_sched_pusch));
   }
 }
@@ -348,10 +348,10 @@ void nr_schedule_pucch(int Mod_idP,
   uint16_t O_ack;
   uint8_t SR_flag = 0; // no SR in PUCCH implemented for now
   NR_ServingCellConfigCommon_t *scc = RC.nrmac[Mod_idP]->common_channels->ServingCellConfigCommon;
-  NR_UE_list_t *UE_list = &RC.nrmac[Mod_idP]->UE_list;
-  AssertFatal(UE_list->active[UE_id] >=0,"Cannot find UE_id %d is not active\n",UE_id);
+  NR_UE_info_t *UE_info = &RC.nrmac[Mod_idP]->UE_info;
+  AssertFatal(UE_info->active[UE_id],"Cannot find UE_id %d is not active\n",UE_id);
 
-  NR_CellGroupConfig_t *secondaryCellGroup = UE_list->secondaryCellGroup[UE_id];
+  NR_CellGroupConfig_t *secondaryCellGroup = UE_info->secondaryCellGroup[UE_id];
   int bwp_id=1;
   NR_BWP_Uplink_t *ubwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->uplinkConfig->uplinkBWP_ToAddModList->list.array[bwp_id-1];
   nfapi_nr_ul_tti_request_t *UL_tti_req = &RC.nrmac[Mod_idP]->UL_tti_req[0];
@@ -359,7 +359,7 @@ void nr_schedule_pucch(int Mod_idP,
   NR_sched_pucch *curr_pucch;
 
   for (int k=0; k<nr_ulmix_slots; k++) {
-    curr_pucch = &UE_list->UE_sched_ctrl[UE_id].sched_pucch[k];
+    curr_pucch = &UE_info->UE_sched_ctrl[UE_id].sched_pucch[k];
     if ((curr_pucch->dai_c > 0) && (frameP == curr_pucch->frame) && (slotP == curr_pucch->ul_slot)) {
       UL_tti_req->SFN = curr_pucch->frame;
       UL_tti_req->Slot = curr_pucch->ul_slot;
@@ -381,59 +381,46 @@ void nr_schedule_pucch(int Mod_idP,
                          O_ack,
                          SR_flag);
 
-      memset((void *) &UE_list->UE_sched_ctrl[UE_id].sched_pucch[k],
+      memset((void *) &UE_info->UE_sched_ctrl[UE_id].sched_pucch[k],
              0,
              sizeof(NR_sched_pucch));
     }
   }
 }
 
-
-
-bool is_xlsch_in_slot(uint64_t bitmap, sub_frame_t slot){
-
-  if((bitmap>>slot)&0x01)
-    return true;
-  else
-    return false;
+bool is_xlsch_in_slot(uint64_t bitmap, sub_frame_t slot) {
+  return (bitmap >> slot) & 0x01;
 }
 
 void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
                                frame_t frame,
                                sub_frame_t slot){
-
-			       
   protocol_ctxt_t   ctxt;
   PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frame, slot,module_idP);
  
-  int CC_id;
-  int UE_id;
-  uint64_t *dlsch_in_slot_bitmap=NULL;
-  uint64_t *ulsch_in_slot_bitmap=NULL;
-  int pucch_sched;
-
-  UE_id=0;
-  int bwp_id = 1;
+  const int UE_id = 0;
+  const int bwp_id = 1;
 
   gNB_MAC_INST *gNB = RC.nrmac[module_idP];
-  NR_UE_list_t *UE_list = &gNB->UE_list;
-  NR_UE_sched_ctrl_t *ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
+  NR_UE_info_t *UE_info = &gNB->UE_info;
+  NR_UE_sched_ctrl_t *ue_sched_ctl = &UE_info->UE_sched_ctrl[UE_id];
   NR_COMMON_channels_t *cc = gNB->common_channels;
   NR_ServingCellConfigCommon_t        *scc     = cc->ServingCellConfigCommon;
-  int num_slots_per_tdd = (slots_per_frame[*scc->ssbSubcarrierSpacing])>>(7-scc->tdd_UL_DL_ConfigurationCommon->pattern1.dl_UL_TransmissionPeriodicity);
 
-  int nr_ulmix_slots = scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots;
-  if (scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols!=0)
-    nr_ulmix_slots++;
+  NR_TDD_UL_DL_Pattern_t *tdd_pattern = &scc->tdd_UL_DL_ConfigurationCommon->pattern1;
+  const int num_slots_per_tdd = slots_per_frame[*scc->ssbSubcarrierSpacing] >> (7 - tdd_pattern->dl_UL_TransmissionPeriodicity);
+  const int nr_ulmix_slots = tdd_pattern->nrofUplinkSlots + (tdd_pattern->nrofUplinkSymbols!=0);
 
-  if (slot== 0 && (UE_list->fiveG_connected[UE_id] || get_softmodem_params()->phy_test)) {
+  if (slot == 0 && UE_info->active[UE_id]) {
     for (int k=0; k<nr_ulmix_slots; k++) {
-      memset((void *) &UE_list->UE_sched_ctrl[UE_id].sched_pucch[k],
+      /* Seems to be covered 384? */
+      /*memset((void *) &UE_info->UE_sched_ctrl[UE_id].sched_pucch[k],
              0,
-             sizeof(NR_sched_pucch));
-      memset((void *) &UE_list->UE_sched_ctrl[UE_id].sched_pusch[k],
+             sizeof(NR_sched_pucch));*/
+      /* Seems to be covered in line 335? */
+      /*memset((void *) &UE_info->UE_sched_ctrl[UE_id].sched_pusch[k],
              0,
-             sizeof(NR_sched_pusch));
+             sizeof(NR_sched_pusch));*/
     }
   }
 
@@ -442,48 +429,27 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
 
   pdcp_run(&ctxt);
   //rrc_rx_tx(&ctxt, CC_id);
-
-  dlsch_in_slot_bitmap = &RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[UE_id].dlsch_in_slot_bitmap;  // static bitmap signaling which slot in a tdd period contains dlsch
-  ulsch_in_slot_bitmap = &RC.nrmac[module_idP]->UE_list.UE_sched_ctrl[UE_id].ulsch_in_slot_bitmap;  // static bitmap signaling which slot in a tdd period contains ulsch
-
-  // hardcoding dlsch to be in slot 1
-  if (!(slot%num_slots_per_tdd)) {
-    if(slot==0) {
-      *dlsch_in_slot_bitmap = 0x02;
-      *ulsch_in_slot_bitmap = 0x100;
-    }
-    else {
-      *dlsch_in_slot_bitmap = 0x00;
-      *ulsch_in_slot_bitmap = 0x00;
-    }
+  /* send tick to RLC every ms */
+  if ((slot & ((1 << *scc->ssbSubcarrierSpacing) - 1)) == 0) {
+    void nr_rlc_tick(int frame, int subframe);
+    nr_rlc_tick(frame, slot >> *scc->ssbSubcarrierSpacing);
   }
 
+  const uint64_t dlsch_in_slot_bitmap = (1 << 1);
+  const uint64_t ulsch_in_slot_bitmap = (1 << 8);
+
   memset(RC.nrmac[module_idP]->cce_list[bwp_id][0],0,MAX_NUM_CCE*sizeof(int)); // coreset0
   memset(RC.nrmac[module_idP]->cce_list[bwp_id][1],0,MAX_NUM_CCE*sizeof(int)); // coresetid 1
-  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
+  for (int CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
     //mbsfn_status[CC_id] = 0;
 
     // clear vrb_maps
-    memset(cc[CC_id].vrb_map, 0, 100);
-    memset(cc[CC_id].vrb_map_UL, 0, 100);
+    memset(cc[CC_id].vrb_map, 0, 275);
+    memset(cc[CC_id].vrb_map_UL, 0, 275);
 
     clear_nr_nfapi_information(RC.nrmac[module_idP], CC_id, frame, slot);
   }
 
-  // refresh UE list based on UEs dropped by PHY in previous subframe
-  /*
-  for (i = 0; i < MAX_MOBILES_PER_GNB; i++) {
-    if (UE_list->active[i]) {
-
-      nfapi_nr_config_request_t *cfg = &RC.nrmac[module_idP]->config[CC_id];      
-      
-      rnti = 0;//UE_RNTI(module_idP, i);
-      CC_id = 0;//UE_PCCID(module_idP, i);
-
-    } //END if (UE_list->active[i])
-  } //END for (i = 0; i < MAX_MOBILES_PER_GNB; i++)
-  */
-
   if ((slot == 0) && (frame & 127) == 0) dump_mac_stats(RC.nrmac[module_idP]);
 
   // This schedules MIB
@@ -506,8 +472,7 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
   if (get_softmodem_params()->phy_test == 0) {
     nr_schedule_RA(module_idP, frame, slot);
     nr_schedule_reception_msg3(module_idP, 0, frame, slot);
-  } else
-    UE_list->fiveG_connected[UE_id] = true;
+  }
 
   if (get_softmodem_params()->phy_test) {
 
@@ -527,29 +492,30 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
   }
 
   // This schedules the DCI for Uplink and subsequently PUSCH
-  if (UE_list->fiveG_connected[UE_id]) {
+  // The decision about whether to schedule is done for each UE independently
+  // inside
+  if (UE_info->active[UE_id] && slot < 10) {
     int tda = 1; // time domain assignment hardcoded for now
-    schedule_fapi_ul_pdu(module_idP, frame, slot, num_slots_per_tdd, nr_ulmix_slots, tda);
+    schedule_fapi_ul_pdu(module_idP, frame, slot, num_slots_per_tdd, nr_ulmix_slots, tda, ulsch_in_slot_bitmap);
     nr_schedule_pusch(module_idP, UE_id, num_slots_per_tdd, nr_ulmix_slots, frame, slot);
   }
 
-  if (UE_list->fiveG_connected[UE_id] && (is_xlsch_in_slot(*dlsch_in_slot_bitmap,slot%num_slots_per_tdd))) {
+  if (UE_info->active[UE_id]
+      && (is_xlsch_in_slot(dlsch_in_slot_bitmap, slot % num_slots_per_tdd))
+      && (!get_softmodem_params()->phy_test || slot == 1)
+      && slot < 10) {
     ue_sched_ctl->current_harq_pid = slot % num_slots_per_tdd;
-    nr_update_pucch_scheduling(module_idP, UE_id, frame, slot, num_slots_per_tdd,&pucch_sched);
-    nr_schedule_uss_dlsch_phytest(module_idP, frame, slot, &UE_list->UE_sched_ctrl[UE_id].sched_pucch[pucch_sched], NULL);
+    //int pucch_sched;
+    //nr_update_pucch_scheduling(module_idP, UE_id, frame, slot, num_slots_per_tdd,&pucch_sched);
+    //nr_schedule_uss_dlsch_phytest(module_idP, frame, slot, &UE_info->UE_sched_ctrl[UE_id].sched_pucch[pucch_sched], NULL);
+    nr_schedule_ue_spec(module_idP, frame, slot, num_slots_per_tdd);
     // resetting ta flag
     gNB->ta_len = 0;
   }
 
-  if (UE_list->fiveG_connected[UE_id])
+  if (UE_info->active[UE_id])
     nr_schedule_pucch(module_idP, UE_id, nr_ulmix_slots, frame, slot);
 
-    /*
-    // Allocate CCEs for good after scheduling is done
-    for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++)
-      allocate_CCEs(module_idP, CC_id, subframeP, 0);
-    */
-
   stop_meas(&RC.nrmac[module_idP]->eNB_scheduler);
   
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_OUT);
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
index 4c17ee3a0fb9c73e3b57e08792a5d93efc4aadc9..413727b9cb89c35f2e6c4e971b2c15d9633d7a8c 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
@@ -247,14 +247,11 @@ void nr_initiate_ra_proc(module_id_t module_idP,
 
   uint8_t ul_carrier_id = 0; // 0 for NUL 1 for SUL
   NR_SearchSpace_t *ss;
-  int UE_id = 0;
   // ra_rnti from 5.1.3 in 38.321
   uint16_t ra_rnti=1+symbol+(slotP*14)+(freq_index*14*80)+(ul_carrier_id*14*80*8);
 
   uint16_t msg2_frame, msg2_slot,monitoring_slot_period,monitoring_offset;
   gNB_MAC_INST *nr_mac = RC.nrmac[module_idP];
-  NR_UE_list_t *UE_list = &nr_mac->UE_list;
-  NR_CellGroupConfig_t *secondaryCellGroup = UE_list->secondaryCellGroup[UE_id];
   NR_COMMON_channels_t *cc = &nr_mac->common_channels[CC_id];
   NR_ServingCellConfigCommon_t *scc = cc->ServingCellConfigCommon;
   NR_RA_t *ra = &cc->ra[0];
@@ -262,23 +259,21 @@ void nr_initiate_ra_proc(module_id_t module_idP,
   // if the preamble received correspond to one of the listed
   // the UE sent a RACH either for starting RA procedure or RA procedure failed and UE retries
   int pr_found=0;
-  for (int i=0;i<UE_list->preambles[UE_id].num_preambles;i++) {
-    if (preamble_index == UE_list->preambles[UE_id].preamble_list[i]) {
+  for (int i = 0; i < ra->preambles.num_preambles; i++) {
+    if (preamble_index == ra->preambles.preamble_list[i]) {
       pr_found=1;
       break;
     }
   }
-  if (pr_found)
-    UE_list->fiveG_connected[UE_id] = false;
-  else {
-    LOG_E(MAC, "[gNB %d][RAPROC] FAILURE: preamble %d does not correspond to any of the ones in rach_ConfigDedicated for UE_id %d\n",
-          module_idP, preamble_index, UE_id);
+  if (!pr_found) {
+    LOG_E(MAC, "[gNB %d][RAPROC] FAILURE: preamble %d does not correspond to any of the ones in rach_ConfigDedicated\n",
+          module_idP, preamble_index);
     return; // if the PRACH preamble does not correspond to any of the ones sent through RRC abort RA proc
   }
 
   // This should be handled differently when we use the initialBWP for RA
   ra->bwp_id=1;
-  NR_BWP_Downlink_t *bwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.array[ra->bwp_id-1];
+  NR_BWP_Downlink_t *bwp=ra->secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.array[ra->bwp_id-1];
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_INITIATE_RA_PROC, 1);
 
@@ -325,7 +320,6 @@ void nr_initiate_ra_proc(module_id_t module_idP,
 
     ra->RA_rnti = ra_rnti;
     ra->preamble_index = preamble_index;
-    UE_list->tc_rnti[UE_id] = ra->rnti;
 
     LOG_I(MAC,"[gNB %d][RAPROC] CC_id %d Frame %d Activating Msg2 generation in frame %d, slot %d using RA rnti %x\n",
       module_idP,
@@ -423,7 +417,6 @@ void nr_schedule_reception_msg3(module_id_t module_idP, int CC_id, frame_t frame
       ul_req->pdus_list[ul_req->n_pdus].pdu_size = sizeof(nfapi_nr_pusch_pdu_t);
       ul_req->pdus_list[ul_req->n_pdus].pusch_pdu = ra->pusch_pdu;
       ul_req->n_pdus+=1;
-      ra->state = RA_IDLE;
     }
   }
 }
@@ -434,8 +427,6 @@ void nr_add_msg3(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t
   NR_COMMON_channels_t                            *cc = &mac->common_channels[CC_id];
   NR_ServingCellConfigCommon_t                   *scc = cc->ServingCellConfigCommon;
   NR_RA_t                                         *ra = &cc->ra[0];
-  NR_UE_list_t                               *UE_list = &mac->UE_list;
-  int UE_id = 0;
 
   if (ra->state == RA_IDLE) {
     LOG_W(MAC,"RA is not active for RA %X. skipping msg3 scheduling\n", ra->rnti);
@@ -447,13 +438,12 @@ void nr_add_msg3(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t
   nfapi_nr_pusch_pdu_t  *pusch_pdu = &ra->pusch_pdu;
   memset(pusch_pdu, 0, sizeof(nfapi_nr_pusch_pdu_t));
 
-
-  AssertFatal(UE_list->active[UE_id] >=0,"Cannot find UE_id %d is not active\n", UE_id);
-
-  NR_CellGroupConfig_t *secondaryCellGroup = UE_list->secondaryCellGroup[UE_id];
-  AssertFatal(secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
-    "downlinkBWP_ToAddModList has %d BWP!\n", secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count);
-  NR_BWP_Uplink_t *ubwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->uplinkConfig->uplinkBWP_ToAddModList->list.array[ra->bwp_id-1];
+  AssertFatal(ra->secondaryCellGroup,
+              "no secondaryCellGroup for RNTI %04x\n",
+              ra->crnti);
+  AssertFatal(ra->secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
+    "downlinkBWP_ToAddModList has %d BWP!\n", ra->secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count);
+  NR_BWP_Uplink_t *ubwp = ra->secondaryCellGroup->spCellConfig->spCellConfigDedicated->uplinkConfig->uplinkBWP_ToAddModList->list.array[ra->bwp_id - 1];
   LOG_D(MAC, "Frame %d, Subframe %d Adding Msg3 UL Config Request for (%d,%d) : (%d,%d,%d) for rnti: %d\n",
     frameP,
     slotP,
@@ -542,17 +532,15 @@ void nr_generate_Msg2(module_id_t module_idP,
                       frame_t frameP,
                       sub_frame_t slotP){
 
-  int UE_id = 0, dci_formats[2], rnti_types[2], mcsIndex;
+  int dci_formats[2], rnti_types[2], mcsIndex;
   int startSymbolAndLength = 0, StartSymbolIndex = -1, NrOfSymbols = 14, StartSymbolIndex_tmp, NrOfSymbols_tmp, x_Overhead, time_domain_assignment = 0;
   gNB_MAC_INST                      *nr_mac = RC.nrmac[module_idP];
   NR_COMMON_channels_t                  *cc = &nr_mac->common_channels[0];
   NR_RA_t                               *ra = &cc->ra[0];
-  NR_UE_list_t                     *UE_list = &nr_mac->UE_list;
   NR_SearchSpace_t *ss = ra->ra_ss;
 
   uint16_t RA_rnti = ra->RA_rnti;
   long locationAndBandwidth;
-  // uint8_t *vrb_map = cc[CC_id].vrb_map, CC_id;
 
   // check if UE is doing RA on CORESET0 , InitialBWP or configured BWP from SCD
   // get the BW of the PDCCH for PDCCH size and RAR PDSCH size
@@ -597,11 +585,13 @@ void nr_generate_Msg2(module_id_t module_idP,
     // This code from this point on will not work on initialBWP or CORESET0
     AssertFatal(ra->bwp_id>0,"cannot work on initialBWP for now\n");
 
-    NR_CellGroupConfig_t *secondaryCellGroup = UE_list->secondaryCellGroup[UE_id];
-    AssertFatal(secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
-      "downlinkBWP_ToAddModList has %d BWP!\n", secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count);
-    NR_BWP_Downlink_t *bwp = secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.array[ra->bwp_id - 1];
-    NR_BWP_Uplink_t *ubwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->uplinkConfig->uplinkBWP_ToAddModList->list.array[ra->bwp_id-1];
+    AssertFatal(ra->secondaryCellGroup,
+                "no secondaryCellGroup for RNTI %04x\n",
+                ra->crnti);
+    AssertFatal(ra->secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
+      "downlinkBWP_ToAddModList has %d BWP!\n", ra->secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count);
+    NR_BWP_Downlink_t *bwp = ra->secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.array[ra->bwp_id - 1];
+    NR_BWP_Uplink_t *ubwp=ra->secondaryCellGroup->spCellConfig->spCellConfigDedicated->uplinkConfig->uplinkBWP_ToAddModList->list.array[ra->bwp_id-1];
 
     LOG_D(MAC, "[RAPROC] Scheduling common search space DCI type 1 dlBWP BW %d\n", dci10_bw);
 
@@ -681,7 +671,30 @@ void nr_generate_Msg2(module_id_t module_idP,
 	  dci_pdu_rel15[0].mcs,
 	  dci_pdu_rel15[0].tb_scaling);
 
-    nr_configure_pdcch(nr_mac, pdcch_pdu_rel15, RA_rnti, 0, ss, scc, bwp);
+    uint8_t nr_of_candidates, aggregation_level;
+    find_aggregation_candidates(&aggregation_level, &nr_of_candidates, ss);
+    NR_ControlResourceSet_t *coreset = get_coreset(bwp, ss, 0 /* common */);
+    int CCEIndex = allocate_nr_CCEs(
+        nr_mac,
+        bwp,
+        coreset,
+        aggregation_level,
+        0, /* n_RNTI 0: common search space */
+        0); // m
+
+    if (CCEIndex < 0) {
+      LOG_E(MAC, "%s(): cannot find free CCE for RA RNTI %04x!\n", __func__, ra->rnti);
+      return;
+    }
+    nr_configure_pdcch(nr_mac,
+                       pdcch_pdu_rel15,
+                       RA_rnti,
+                       ss,
+                       coreset,
+                       scc,
+                       bwp,
+                       aggregation_level,
+                       CCEIndex);
 
     LOG_I(MAC, "Frame %d: Subframe %d : Adding common DL DCI for RA_RNTI %x\n", frameP, slotP, RA_rnti);
 
@@ -696,7 +709,7 @@ void nr_generate_Msg2(module_id_t module_idP,
       pdcch_pdu_rel15->StartSymbolIndex,
       pdcch_pdu_rel15->DurationSymbols);
 
-    fill_dci_pdu_rel15(scc,secondaryCellGroup,pdcch_pdu_rel15, &dci_pdu_rel15[0], dci_formats, rnti_types,dci10_bw,ra->bwp_id);
+    fill_dci_pdu_rel15(scc,ra->secondaryCellGroup,pdcch_pdu_rel15, &dci_pdu_rel15[0], dci_formats, rnti_types,dci10_bw,ra->bwp_id);
 
     dl_req->nPDUs+=2;
 
@@ -719,6 +732,11 @@ void nr_generate_Msg2(module_id_t module_idP,
     nr_mac->TX_req[CC_id].Number_of_PDUs++;
     nr_mac->TX_req[CC_id].Slot = slotP;
     memcpy((void*)&tx_req->TLVs[0].value.direct[0], (void*)&cc[CC_id].RAR_pdu.payload[0], tx_req->TLVs[0].length);
+
+    /* mark the corresponding RBs as used */
+    uint8_t *vrb_map = cc[CC_id].vrb_map;
+    for (int rb = 0; rb < pdsch_pdu_rel15->rbSize; rb++)
+      vrb_map[rb + pdsch_pdu_rel15->rbStart] = 1;
   }
 }
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c
index 5fa77c6ca7a409534ef0f88b34e2c34fa013a657..989d6fb9527cba12f1dfefe3a433b2843909f6cf 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c
@@ -82,7 +82,7 @@ void schedule_nr_mib(module_id_t module_idP, frame_t frameP, sub_frame_t slotP){
 
     if (mib_sdu_length > 0) {
 
-      LOG_I(MAC, "Frame %d, slot %d: Adding BCH PDU in position %d (length %d)\n", frameP, slotP, dl_req->nPDUs, mib_sdu_length);
+      LOG_D(MAC, "Frame %d, slot %d: Adding BCH PDU in position %d (length %d)\n", frameP, slotP, dl_req->nPDUs, mib_sdu_length);
 
       if ((frameP & 1023) < 80){
         LOG_I(MAC,"[gNB %d] Frame %d : MIB->BCH  CC_id %d, Received %d bytes\n",module_idP, frameP, CC_id, mib_sdu_length);
@@ -137,6 +137,11 @@ void schedule_nr_mib(module_id_t module_idP, frame_t frameP, sub_frame_t slotP){
       dl_config_pdu->ssb_pdu.ssb_pdu_rel15.bchPayloadFlag      = 1;
       dl_config_pdu->ssb_pdu.ssb_pdu_rel15.bchPayload          = (*(uint32_t*)cc->MIB_pdu.payload) & ((1<<24)-1);
       dl_req->nPDUs++;
+
+      uint8_t *vrb_map = cc[CC_id].vrb_map;
+      const int rbStart = dl_config_pdu->ssb_pdu.ssb_pdu_rel15.ssbOffsetPointA;
+      for (int rb = 0; rb < 20; rb++)
+        vrb_map[rbStart + rb] = 1;
     }
   }
 }
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
index 495095ce9e30035c85b0275cfb42784c82ce3553..93c9e32842be46d33936d09739bf0c1b04616c34 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
@@ -32,6 +32,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"
@@ -45,6 +46,9 @@
 /*TAG*/
 #include "NR_TAG-Id.h"
 
+/*Softmodem params*/
+#include "executables/softmodem-common.h"
+
 ////////////////////////////////////////////////////////
 /////* DLSCH MAC PDU generation (6.1.2 TS 38.321) */////
 ////////////////////////////////////////////////////////
@@ -54,6 +58,7 @@
 //#define SIZE_OF_POINTER sizeof (void *)
 
 int nr_generate_dlsch_pdu(module_id_t module_idP,
+                          NR_UE_sched_ctrl_t *ue_sched_ctl,
                           unsigned char *sdus_payload,
                           unsigned char *mac_pdu,
                           unsigned char num_sdus,
@@ -70,14 +75,6 @@ int nr_generate_dlsch_pdu(module_id_t module_idP,
   // MAC CEs
   uint8_t mac_header_control_elements[16], *ce_ptr;
   ce_ptr = &mac_header_control_elements[0];
-  uint16_t UE_id = 0; //TODO need to get as a function parameter or need to invoke api to UE_id using module Id and RNTI
-  gNB_MAC_INST *gNB_mac = RC.nrmac[module_idP];
-  NR_UE_list_t *UE_list = &gNB_mac->UE_list;
-  NR_UE_sched_ctrl_t *ue_sched_ctl = NULL;
-  //NR_CellGroupConfig_t *config = UE_list->secondaryCellGroup[UE_id];
-  ue_sched_ctl = &(UE_list->UE_sched_ctrl[UE_id]);
-
-  NR_mac_stats_t *mac_stats = &(UE_list->mac_stats[UE_id]);
 
   // 1) Compute MAC CE and related subheaders
 
@@ -329,8 +326,6 @@ int nr_generate_dlsch_pdu(module_id_t module_idP,
     memcpy((void *) mac_pdu_ptr, (void *) dlsch_buffer_ptr, sdu_lengths[i]);
     dlsch_buffer_ptr += sdu_lengths[i];
     mac_pdu_ptr += sdu_lengths[i];
-
-    mac_stats->lc_bytes_tx[sdu_lcids[i]] += sdu_lengths[i];
   }
 
   // 4) Compute final offset for padding
@@ -412,6 +407,405 @@ void handle_nr_uci(NR_UL_IND_t *UL_info, NR_UE_sched_ctrl_t *sched_ctrl, NR_mac_
   UL_info->uci_ind.num_ucis = 0;
 }
 
-/* functionalities of this function have been moved to nr_schedule_uss_dlsch_phytest */
-void nr_schedule_ue_spec(module_id_t module_idP, frame_t frameP, sub_frame_t slotP) {
+int getNrOfSymbols(NR_BWP_Downlink_t *bwp, int tda) {
+  struct NR_PDSCH_TimeDomainResourceAllocationList *tdaList =
+    bwp->bwp_Common->pdsch_ConfigCommon->choice.setup->pdsch_TimeDomainAllocationList;
+  AssertFatal(tda < tdaList->list.count,
+              "time_domain_allocation %d>=%d\n",
+              tda,
+              tdaList->list.count);
+
+  const int startSymbolAndLength = tdaList->list.array[tda]->startSymbolAndLength;
+  int startSymbolIndex, nrOfSymbols;
+  SLIV2SL(startSymbolAndLength, &startSymbolIndex, &nrOfSymbols);
+  return nrOfSymbols;
+}
+
+nfapi_nr_dmrs_type_e getDmrsConfigType(NR_BWP_Downlink_t *bwp) {
+  return bwp->bwp_Dedicated->pdsch_Config->choice.setup->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_Type == NULL ? 0 : 1;
+}
+
+uint8_t getN_PRB_DMRS(NR_BWP_Downlink_t *bwp, int numDmrsCdmGrpsNoData) {
+  const nfapi_nr_dmrs_type_e dmrsConfigType = getDmrsConfigType(bwp);
+  if (dmrsConfigType == NFAPI_NR_DMRS_TYPE1) {
+    // if no data in dmrs cdm group is 1 only even REs have no data
+    // if no data in dmrs cdm group is 2 both odd and even REs have no data
+    return numDmrsCdmGrpsNoData * 6;
+  } else {
+    return numDmrsCdmGrpsNoData * 4;
+  }
+}
+
+void nr_simple_dlsch_preprocessor(module_id_t module_id,
+                                  frame_t frame,
+                                  sub_frame_t slot,
+                                  int num_slots_per_tdd) {
+  NR_UE_info_t *UE_info = &RC.nrmac[module_id]->UE_info;
+
+  AssertFatal(UE_info->num_UEs <= 1,
+              "%s() cannot handle more than one UE, but found %d\n",
+              __func__,
+              UE_info->num_UEs);
+  if (UE_info->num_UEs == 0)
+    return;
+
+  const int UE_id = 0;
+  const int CC_id = 0;
+
+  NR_UE_sched_ctrl_t *sched_ctrl = &UE_info->UE_sched_ctrl[UE_id];
+  sched_ctrl->rbSize = 0;
+
+  /* Retrieve amount of data to send for this UE */
+  sched_ctrl->num_total_bytes = 0;
+  const int lcid = DL_SCH_LCID_DTCH;
+  const uint16_t rnti = UE_info->rnti[UE_id];
+  sched_ctrl->rlc_status[lcid] = mac_rlc_status_ind(module_id,
+                                                    rnti,
+                                                    module_id,
+                                                    frame,
+                                                    slot,
+                                                    ENB_FLAG_YES,
+                                                    MBMS_FLAG_NO,
+                                                    lcid,
+                                                    0,
+                                                    0);
+  sched_ctrl->num_total_bytes += sched_ctrl->rlc_status[lcid].bytes_in_buffer;
+  if (sched_ctrl->num_total_bytes == 0 && !get_softmodem_params()->phy_test)
+    return;
+  LOG_D(MAC,
+        "%d.%d, DTCH%d->DLSCH, RLC status %d bytes\n",
+        frame,
+        slot,
+        lcid,
+        sched_ctrl->rlc_status[lcid].bytes_in_buffer);
+
+  /* Find a free CCE */
+  const int target_ss = NR_SearchSpace__searchSpaceType_PR_ue_Specific;
+  sched_ctrl->search_space = get_searchspace(sched_ctrl->active_bwp, target_ss);
+  uint8_t nr_of_candidates;
+  find_aggregation_candidates(&sched_ctrl->aggregation_level,
+                              &nr_of_candidates,
+                              sched_ctrl->search_space);
+  sched_ctrl->coreset = get_coreset(
+      sched_ctrl->active_bwp, sched_ctrl->search_space, 1 /* dedicated */);
+  sched_ctrl->cce_index = allocate_nr_CCEs(RC.nrmac[module_id],
+                                  sched_ctrl->active_bwp,
+                                  sched_ctrl->coreset,
+                                  sched_ctrl->aggregation_level,
+                                  UE_info->rnti[UE_id],
+                                  0); // m
+  if (sched_ctrl->cce_index < 0) {
+    LOG_E(MAC, "%s(): could not find CCE for UE %d\n", __func__, UE_id);
+    return;
+  }
+
+  /* Find PUCCH occasion */
+  nr_update_pucch_scheduling(
+      module_id, UE_id, frame, slot, num_slots_per_tdd, &sched_ctrl->pucch_sched_idx);
+  AssertFatal(sched_ctrl->pucch_sched_idx >= 0, "no uplink slot for PUCCH found!\n");
+
+  uint8_t *vrb_map = RC.nrmac[module_id]->common_channels[CC_id].vrb_map;
+  const int current_harq_pid = sched_ctrl->current_harq_pid;
+  NR_UE_harq_t *harq = &sched_ctrl->harq_processes[current_harq_pid];
+  NR_UE_ret_info_t *retInfo = &sched_ctrl->retInfo[current_harq_pid];
+  const uint16_t bwpSize = NRRIV2BW(sched_ctrl->active_bwp->bwp_Common->genericParameters.locationAndBandwidth, 275);
+  int rbStart = NRRIV2PRBOFFSET(sched_ctrl->active_bwp->bwp_Common->genericParameters.locationAndBandwidth, 275);
+
+  if (harq->round != 0) { /* retransmission */
+    sched_ctrl->time_domain_allocation = retInfo->time_domain_allocation;
+
+    /* ensure that there is a free place for RB allocation */
+    int rbSize = 0;
+    while (rbSize < retInfo->rbSize) {
+      rbStart += rbSize; /* last iteration rbSize was not enough, skip it */
+      rbSize = 0;
+      while (rbStart < bwpSize && vrb_map[rbStart]) rbStart++;
+      if (rbStart >= bwpSize) {
+        LOG_E(MAC,
+              "cannot allocate retransmission for UE %d/RNTI %04x: no resources\n",
+              UE_id,
+              rnti);
+        return;
+      }
+      while (rbStart + rbSize < bwpSize
+             && !vrb_map[rbStart + rbSize]
+             && rbSize < retInfo->rbSize)
+        rbSize++;
+    }
+    sched_ctrl->rbSize = retInfo->rbSize;
+    sched_ctrl->rbStart = rbStart;
+
+    /* MCS etc: just reuse from previous scheduling opportunity */
+    sched_ctrl->mcsTableIdx = retInfo->mcsTableIdx;
+    sched_ctrl->mcs = retInfo->mcs;
+    sched_ctrl->numDmrsCdmGrpsNoData = retInfo->numDmrsCdmGrpsNoData;
+  } else {
+    // Time-domain allocation
+    sched_ctrl->time_domain_allocation = 2;
+
+    // modulation scheme
+    sched_ctrl->mcsTableIdx = 0;
+    sched_ctrl->mcs = 9;
+    sched_ctrl->numDmrsCdmGrpsNoData = 1;
+
+    // Freq-demain allocation
+    while (rbStart < bwpSize && vrb_map[rbStart]) rbStart++;
+
+    uint8_t N_PRB_DMRS =
+        getN_PRB_DMRS(sched_ctrl->active_bwp, sched_ctrl->numDmrsCdmGrpsNoData);
+    int nrOfSymbols = getNrOfSymbols(sched_ctrl->active_bwp,
+                                     sched_ctrl->time_domain_allocation);
+
+    int rbSize = 0;
+    uint32_t TBS = 0;
+    do {
+      rbSize++;
+      TBS = nr_compute_tbs(nr_get_Qm_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx),
+                           nr_get_code_rate_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx),
+                           rbSize,
+                           nrOfSymbols,
+                           N_PRB_DMRS, // FIXME // This should be multiplied by the
+                                       // number of dmrs symbols
+                           0 /* N_PRB_oh, 0 for initialBWP */,
+                           0 /* tb_scaling */,
+                           1 /* nrOfLayers */)
+            >> 3;
+    } while (rbStart + rbSize < bwpSize && !vrb_map[rbStart + rbSize] && TBS < sched_ctrl->num_total_bytes);
+    sched_ctrl->rbSize = rbSize;
+    sched_ctrl->rbStart = rbStart;
+  }
+
+  /* mark the corresponding RBs as used */
+  for (int rb = 0; rb < sched_ctrl->rbSize; rb++)
+    vrb_map[rb + sched_ctrl->rbStart] = 1;
+}
+
+void nr_schedule_ue_spec(module_id_t module_id,
+                         frame_t frame,
+                         sub_frame_t slot,
+                         int num_slots_per_tdd) {
+  /* PREPROCESSOR */
+  nr_simple_dlsch_preprocessor(module_id, frame, slot, num_slots_per_tdd);
+
+  gNB_MAC_INST *gNB_mac = RC.nrmac[module_id];
+  NR_UE_info_t *UE_info = &gNB_mac->UE_info;
+
+  const int ta_len = gNB_mac->ta_len;
+  const int CC_id = 0;
+
+  NR_UE_list_t *UE_list = &UE_info->list;
+  for (int UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) {
+    NR_UE_sched_ctrl_t *sched_ctrl = &UE_info->UE_sched_ctrl[UE_id];
+    if (sched_ctrl->rbSize <= 0 && !get_softmodem_params()->phy_test)
+      continue;
+
+    const rnti_t rnti = UE_info->rnti[UE_id];
+
+    /* POST processing */
+    struct NR_PDSCH_TimeDomainResourceAllocationList *tdaList =
+      sched_ctrl->active_bwp->bwp_Common->pdsch_ConfigCommon->choice.setup->pdsch_TimeDomainAllocationList;
+    AssertFatal(sched_ctrl->time_domain_allocation < tdaList->list.count,
+                "time_domain_allocation %d>=%d\n",
+                sched_ctrl->time_domain_allocation,
+                tdaList->list.count);
+
+    const int startSymbolAndLength =
+      tdaList->list.array[sched_ctrl->time_domain_allocation]->startSymbolAndLength;
+    int startSymbolIndex, nrOfSymbols;
+    SLIV2SL(startSymbolAndLength, &startSymbolIndex, &nrOfSymbols);
+
+    uint8_t N_PRB_DMRS =
+        getN_PRB_DMRS(sched_ctrl->active_bwp, sched_ctrl->numDmrsCdmGrpsNoData);
+    const uint32_t TBS =
+        nr_compute_tbs(nr_get_Qm_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx),
+                       nr_get_code_rate_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx),
+                       sched_ctrl->rbSize,
+                       nrOfSymbols,
+                       N_PRB_DMRS, // FIXME // This should be multiplied by the
+                                   // number of dmrs symbols
+                       0 /* N_PRB_oh, 0 for initialBWP */,
+                       0 /* tb_scaling */,
+                       1 /* nrOfLayers */)
+        >> 3;
+
+    const int current_harq_pid = sched_ctrl->current_harq_pid;
+    NR_UE_harq_t *harq = &sched_ctrl->harq_processes[current_harq_pid];
+    NR_sched_pucch *pucch = &sched_ctrl->sched_pucch[sched_ctrl->pucch_sched_idx];
+    harq->feedback_slot = pucch->ul_slot;
+    harq->is_waiting = 1;
+    UE_info->mac_stats[UE_id].dlsch_rounds[harq->round]++;
+
+    nfapi_nr_dl_tti_request_body_t *dl_req = &gNB_mac->DL_req[CC_id].dl_tti_request_body;
+    nr_fill_nfapi_dl_pdu(module_id,
+                         UE_id,
+                         sched_ctrl->active_bwp->bwp_Id,
+                         sched_ctrl->search_space,
+                         sched_ctrl->coreset,
+                         dl_req,
+                         pucch,
+                         1 /* nrOfLayers */,
+                         sched_ctrl->mcs,
+                         sched_ctrl->rbSize,
+                         sched_ctrl->rbStart,
+                         sched_ctrl->numDmrsCdmGrpsNoData,
+                         getDmrsConfigType(sched_ctrl->active_bwp),
+                         sched_ctrl->mcsTableIdx,
+                         nr_get_code_rate_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx),
+                         nr_get_Qm_dl(sched_ctrl->mcs, sched_ctrl->mcsTableIdx),
+                         TBS,
+                         sched_ctrl->time_domain_allocation,
+                         startSymbolIndex,
+                         nrOfSymbols,
+                         sched_ctrl->aggregation_level,
+                         sched_ctrl->cce_index,
+                         current_harq_pid,
+                         harq->ndi,
+                         harq->round);
+
+    NR_UE_ret_info_t *retInfo = &sched_ctrl->retInfo[current_harq_pid];
+    if (harq->round != 0) { /* retransmission */
+      if (sched_ctrl->rbSize != retInfo->rbSize)
+        LOG_W(MAC,
+              "retransmission uses different rbSize (%d vs. orig %d)\n",
+              sched_ctrl->rbSize,
+              retInfo->rbSize);
+      if (sched_ctrl->time_domain_allocation != retInfo->time_domain_allocation)
+        LOG_W(MAC,
+              "retransmission uses different time_domain_allocation (%d vs. orig %d)\n",
+              sched_ctrl->time_domain_allocation,
+              retInfo->time_domain_allocation);
+      if (sched_ctrl->mcs != retInfo->mcs
+          || sched_ctrl->mcsTableIdx != retInfo->mcsTableIdx
+          || sched_ctrl->numDmrsCdmGrpsNoData != retInfo->numDmrsCdmGrpsNoData)
+        LOG_W(MAC,
+              "retransmission uses different table/MCS/numDmrsCdmGrpsNoData (%d/%d/%d vs. orig %d/%d/%d)\n",
+              sched_ctrl->mcsTableIdx,
+              sched_ctrl->mcs,
+              sched_ctrl->numDmrsCdmGrpsNoData,
+              retInfo->mcsTableIdx,
+              retInfo->mcs,
+              retInfo->numDmrsCdmGrpsNoData);
+      /* we do not have to do anything, since we do not require to get data
+       * from RLC, encode MAC CEs, or copy data to FAPI structures */
+      LOG_W(MAC, "%d.%2d retransmission UE %d/RNTI %04x\n", frame, slot, UE_id, rnti);
+    } else { /* initial transmission */
+      /* Get RLC data TODO: remove random data retrieval */
+      int header_length_total = 0;
+      int header_length_last = 0;
+      int sdu_length_total = 0;
+      int num_sdus = 0;
+      uint16_t sdu_lengths[NB_RB_MAX] = {0};
+      uint8_t mac_sdus[MAX_NR_DLSCH_PAYLOAD_BYTES];
+      unsigned char sdu_lcids[NB_RB_MAX] = {0};
+      const int lcid = DL_SCH_LCID_DTCH;
+      if (sched_ctrl->num_total_bytes > 0) {
+        LOG_D(MAC,
+              "[gNB %d][USER-PLANE DEFAULT DRB] Frame %d : DTCH->DLSCH, Requesting "
+              "%d bytes from RLC (lcid %d total hdr len %d), TBS: %d \n \n",
+              module_id,
+              frame,
+              TBS - ta_len - header_length_total - sdu_length_total - 3,
+              lcid,
+              header_length_total,
+              TBS);
+
+        sdu_lengths[num_sdus] = mac_rlc_data_req(module_id,
+            rnti,
+            module_id,
+            frame,
+            ENB_FLAG_YES,
+            MBMS_FLAG_NO,
+            lcid,
+            TBS - ta_len - header_length_total - sdu_length_total - 3,
+            (char *)&mac_sdus[sdu_length_total],
+            0,
+            0);
+
+        LOG_D(MAC,
+              "[gNB %d][USER-PLANE DEFAULT DRB] Got %d bytes for DTCH %d \n",
+              module_id,
+              sdu_lengths[num_sdus],
+              lcid);
+
+        sdu_lcids[num_sdus] = lcid;
+        sdu_length_total += sdu_lengths[num_sdus];
+        header_length_last = 1 + 1 + (sdu_lengths[num_sdus] >= 128);
+        header_length_total += header_length_last;
+
+        num_sdus++;
+
+        //ue_sched_ctl->uplane_inactivity_timer = 0;
+      }
+      else if (get_softmodem_params()->phy_test) {
+        LOG_D(MAC, "Configuring DL_TX in %d.%d: random data\n", frame, slot);
+        // fill dlsch_buffer with random data
+        for (int i = 0; i < TBS; i++)
+          mac_sdus[i] = (unsigned char) (lrand48()&0xff);
+        sdu_lcids[0] = 0x3f; // DRB
+        sdu_lengths[0] = TBS - ta_len - 3;
+        header_length_total += 2 + (sdu_lengths[0] >= 128);
+        sdu_length_total += sdu_lengths[0];
+        num_sdus +=1;
+      }
+
+      UE_info->mac_stats[UE_id].dlsch_total_bytes += TBS;
+      UE_info->mac_stats[UE_id].lc_bytes_tx[lcid] += sdu_length_total;
+
+      // Check if there is data from RLC or CE
+      const int post_padding = TBS >= 2 + header_length_total + sdu_length_total + ta_len;
+      // padding param currently not in use
+      //padding = TBS - header_length_total - sdu_length_total - ta_len - 1;
+
+      const int ntx_req = gNB_mac->TX_req[CC_id].Number_of_PDUs;
+      nfapi_nr_pdu_t *tx_req = &gNB_mac->TX_req[CC_id].pdu_list[ntx_req];
+      /* pointer to directly generate the PDU into the nFAPI structure */
+      uint32_t *buf = tx_req->TLVs[0].value.direct;
+
+      const int offset = nr_generate_dlsch_pdu(
+          module_id,
+          sched_ctrl,
+          (unsigned char *)mac_sdus,
+          (unsigned char *)buf,
+          num_sdus, // num_sdus
+          sdu_lengths,
+          sdu_lcids,
+          255, // no drx
+          NULL, // contention res id
+          post_padding);
+
+      // Padding: fill remainder of DLSCH with 0
+      if (post_padding > 0) {
+        for (int j = 0; j < TBS - offset; j++)
+          buf[offset + j] = 0;
+      }
+
+      /* the buffer has been filled by nr_generate_dlsch_pdu(), below we simply
+       * fill the remaining information */
+      tx_req->PDU_length = TBS;
+      tx_req->PDU_index  = gNB_mac->pdu_index[0]++;
+      tx_req->num_TLV = 1;
+      tx_req->TLVs[0].length = TBS + 2;
+      gNB_mac->TX_req[CC_id].Number_of_PDUs++;
+      gNB_mac->TX_req[CC_id].SFN = frame;
+      gNB_mac->TX_req[CC_id].Slot = slot;
+
+      retInfo->rbSize = sched_ctrl->rbSize;
+      retInfo->time_domain_allocation = sched_ctrl->time_domain_allocation;
+      retInfo->mcsTableIdx = sched_ctrl->mcsTableIdx;
+      retInfo->mcs = sched_ctrl->mcs;
+      retInfo->numDmrsCdmGrpsNoData = sched_ctrl->numDmrsCdmGrpsNoData;
+
+#if defined(ENABLE_MAC_PAYLOAD_DEBUG)
+      if (frame%100 == 0) {
+        LOG_I(MAC,
+              "%d.%d, first 10 payload bytes, TBS size: %d \n",
+              frame,
+              slot,
+              TBS);
+        for(int i = 0; i < 10; i++)
+          LOG_I(MAC, "byte %d: %x\n", i, ((uint8_t *) buf)[i]);
+      }
+#endif
+    }
+  }
 }
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
index f786db8ba907aeec4dcaba4e36b91fafcdbbf3fa..450ffa2268f4b156be9d7301ac53b770ee978b98 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
@@ -252,14 +252,12 @@ void nr_schedule_css_dlsch_phytest(module_id_t   module_idP,
   }
 }
 
-
-int configure_fapi_dl_pdu(int Mod_idP,
-                          nfapi_nr_dl_tti_request_body_t *dl_req,
-                          NR_sched_pucch *pucch_sched,
-                          uint8_t *mcsIndex,
-                          uint16_t *rbSize,
-                          uint16_t *rbStart) {
-
+int configure_fapi_dl_pdu_phytest(int Mod_idP,
+                                  nfapi_nr_dl_tti_request_body_t *dl_req,
+                                  NR_sched_pucch *pucch_sched,
+                                  uint8_t *mcsIndex,
+                                  uint16_t *rbSize,
+                                  uint16_t *rbStart) {
   gNB_MAC_INST                        *nr_mac  = RC.nrmac[Mod_idP];
   NR_COMMON_channels_t                *cc      = nr_mac->common_channels;
   NR_ServingCellConfigCommon_t        *scc     = cc->ServingCellConfigCommon;
@@ -271,9 +269,9 @@ int configure_fapi_dl_pdu(int Mod_idP,
   int bwp_id=1;
   int UE_id = 0;
 
-  NR_UE_list_t *UE_list = &RC.nrmac[Mod_idP]->UE_list;
+  NR_UE_info_t *UE_info = &RC.nrmac[Mod_idP]->UE_info;
 
-  NR_CellGroupConfig_t *secondaryCellGroup = UE_list->secondaryCellGroup[UE_id];
+  NR_CellGroupConfig_t *secondaryCellGroup = UE_info->secondaryCellGroup[UE_id];
   AssertFatal(secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
 	      "downlinkBWP_ToAddModList has %d BWP!\n",
 	      secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count);
@@ -298,7 +296,7 @@ int configure_fapi_dl_pdu(int Mod_idP,
 
 
   pdsch_pdu_rel15->pduBitmap = 0;
-  pdsch_pdu_rel15->rnti = UE_list->rnti[UE_id];
+  pdsch_pdu_rel15->rnti = UE_info->rnti[UE_id];
   pdsch_pdu_rel15->pduIndex = 0;
 
   // BWP
@@ -310,17 +308,17 @@ int configure_fapi_dl_pdu(int Mod_idP,
 
   pdsch_pdu_rel15->NrOfCodewords = 1;
   int mcs = (mcsIndex!=NULL) ? *mcsIndex : 9;
-  int current_harq_pid = UE_list->UE_sched_ctrl[UE_id].current_harq_pid;
+  int current_harq_pid = UE_info->UE_sched_ctrl[UE_id].current_harq_pid;
   pdsch_pdu_rel15->targetCodeRate[0] = nr_get_code_rate_dl(mcs,0);
   pdsch_pdu_rel15->qamModOrder[0] = 2;
   pdsch_pdu_rel15->mcsIndex[0] = mcs;
   pdsch_pdu_rel15->mcsTable[0] = 0;
-  pdsch_pdu_rel15->rvIndex[0] = nr_rv_round_map[UE_list->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].round];
+  pdsch_pdu_rel15->rvIndex[0] = nr_rv_round_map[UE_info->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].round];
   pdsch_pdu_rel15->dataScramblingId = *scc->physCellId;
   pdsch_pdu_rel15->nrOfLayers = 1;    
   pdsch_pdu_rel15->transmissionScheme = 0;
   pdsch_pdu_rel15->refPoint = 0; // Point A
-  UE_list->mac_stats[UE_id].dlsch_rounds[UE_list->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].round]++;
+  UE_info->mac_stats[UE_id].dlsch_rounds[UE_info->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].round]++;
   pdsch_pdu_rel15->dmrsConfigType = bwp->bwp_Dedicated->pdsch_Config->choice.setup->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->dmrs_Type == NULL ? 0 : 1;  
   pdsch_pdu_rel15->dlDmrsScramblingId = *scc->physCellId;
   pdsch_pdu_rel15->SCID = 0;
@@ -368,18 +366,18 @@ int configure_fapi_dl_pdu(int Mod_idP,
   dci_pdu_rel15[0].rv = pdsch_pdu_rel15->rvIndex[0];
   // harq pid and ndi
   dci_pdu_rel15[0].harq_pid = current_harq_pid;
-  dci_pdu_rel15[0].ndi = UE_list->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].ndi;
+  dci_pdu_rel15[0].ndi = UE_info->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].ndi;
   // DAI
   dci_pdu_rel15[0].dai[0].val = (pucch_sched->dai_c-1)&3;
 
   // TPC for PUCCH
-  dci_pdu_rel15[0].tpc = UE_list->UE_sched_ctrl[UE_id].tpc1; // table 7.2.1-1 in 38.213
+  dci_pdu_rel15[0].tpc = UE_info->UE_sched_ctrl[UE_id].tpc1; // table 7.2.1-1 in 38.213
   // PUCCH resource indicator
   dci_pdu_rel15[0].pucch_resource_indicator = pucch_sched->resource_indicator;
   // PDSCH to HARQ TI
   dci_pdu_rel15[0].pdsch_to_harq_feedback_timing_indicator.val = pucch_sched->timing_indicator;
-  UE_list->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].feedback_slot = pucch_sched->ul_slot;
-  UE_list->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].is_waiting = 1;
+  UE_info->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].feedback_slot = pucch_sched->ul_slot;
+  UE_info->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].is_waiting = 1;
   // antenna ports
   dci_pdu_rel15[0].antenna_ports.val = 0;  // nb of cdm groups w/o data 1 and dmrs port 0
   // dmrs sequence initialization
@@ -416,18 +414,30 @@ int configure_fapi_dl_pdu(int Mod_idP,
   }
   AssertFatal(found==1,"Couldn't find an adequate searchspace\n");
 
-  int ret = nr_configure_pdcch(nr_mac,
-                               pdcch_pdu_rel15,
-                               UE_list->rnti[UE_id],
-		               1, // ue-specific
-		               ss,
-		               scc,
-		               bwp);
-  if (ret < 0) {
-   LOG_I(MAC,"CCE list not empty, couldn't schedule PDSCH\n");
-   free(dci_pdu_rel15);
-   return (0);
+  uint8_t nr_of_candidates, aggregation_level;
+  find_aggregation_candidates(&aggregation_level, &nr_of_candidates, ss);
+  NR_ControlResourceSet_t *coreset = get_coreset(bwp, ss, 1 /* dedicated */);
+  int CCEIndex = allocate_nr_CCEs(
+      nr_mac,
+      bwp,
+      coreset,
+      aggregation_level,
+      UE_info->rnti[UE_id],
+      0); // m
+  if (CCEIndex < 0) {
+    LOG_E(MAC, "%s(): CCE list not empty, couldn't schedule PDSCH\n", __func__);
+    free(dci_pdu_rel15);
+    return 0;
   }
+  nr_configure_pdcch(nr_mac,
+                     pdcch_pdu_rel15,
+                     UE_info->rnti[UE_id],
+                     ss,
+                     coreset,
+                     scc,
+                     bwp,
+                     aggregation_level,
+                     CCEIndex);
 
   int dci_formats[2];
   int rnti_types[2];
@@ -455,8 +465,8 @@ int configure_fapi_dl_pdu(int Mod_idP,
 
   // Hardcode it for now
   TBS = dl_tti_pdsch_pdu->pdsch_pdu.pdsch_pdu_rel15.TBSize[0];
-  if (UE_list->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].round==0)
-    UE_list->mac_stats[UE_id].dlsch_total_bytes += TBS;
+  if (UE_info->UE_sched_ctrl[UE_id].harq_processes[current_harq_pid].round==0)
+    UE_info->mac_stats[UE_id].dlsch_total_bytes += TBS;
 
   LOG_D(MAC, "DLSCH PDU: start PRB %d n_PRB %d startSymbolAndLength %d start symbol %d nb_symbols %d nb_layers %d nb_codewords %d mcs %d TBS: %d\n",
 	pdsch_pdu_rel15->rbStart,
@@ -581,7 +591,7 @@ void configure_fapi_dl_Tx(module_id_t Mod_idP,
   tx_req->num_TLV = 1;
   tx_req->TLVs[0].length = tbs_bytes +2;
 
-  memcpy((void*)&tx_req->TLVs[0].value.direct[0], (void*)&nr_mac->UE_list.DLSCH_pdu[0][0].payload[0], tbs_bytes);
+  memcpy((void*)&tx_req->TLVs[0].value.direct[0], (void*)&nr_mac->UE_info.DLSCH_pdu[0][0].payload[0], tbs_bytes);
 
   nr_mac->TX_req[CC_id].Number_of_PDUs++;
   nr_mac->TX_req[CC_id].SFN = frameP;
@@ -608,13 +618,13 @@ void nr_schedule_uss_dlsch_phytest(module_id_t   module_idP,
 
   mac_rlc_status_resp_t rlc_status;
 
-  NR_UE_list_t *UE_list = &gNB_mac->UE_list;
+  NR_UE_info_t *UE_info = &gNB_mac->UE_info;
  
-  if (UE_list->num_UEs ==0) return;
+  if (UE_info->num_UEs ==0) return;
  
   unsigned char sdu_lcids[NB_RB_MAX] = {0};
   uint16_t sdu_lengths[NB_RB_MAX] = {0};
-  uint16_t rnti = UE_list->rnti[UE_id];
+  uint16_t rnti = UE_info->rnti[UE_id];
 
   uint8_t mac_sdus[MAX_NR_DLSCH_PAYLOAD_BYTES];
   
@@ -622,12 +632,13 @@ void nr_schedule_uss_dlsch_phytest(module_id_t   module_idP,
 
   ta_len = gNB_mac->ta_len;
 
-  TBS_bytes = configure_fapi_dl_pdu(module_idP,
-                                    dl_req,
-                                    pucch_sched,
-                                    dlsch_config!=NULL ? dlsch_config->mcsIndex : NULL,
-                                    dlsch_config!=NULL ? &dlsch_config->rbSize : NULL,
-                                    dlsch_config!=NULL ? &dlsch_config->rbStart : NULL);
+  TBS_bytes = configure_fapi_dl_pdu_phytest(
+      module_idP,
+      dl_req,
+      pucch_sched,
+      dlsch_config != NULL ? dlsch_config->mcsIndex : NULL,
+      dlsch_config != NULL ? &dlsch_config->rbSize : NULL,
+      dlsch_config != NULL ? &dlsch_config->rbStart : NULL);
 
   if (TBS_bytes == 0)
    return;
@@ -692,7 +703,7 @@ void nr_schedule_uss_dlsch_phytest(module_id_t   module_idP,
     // fill dlsch_buffer with random data
     for (i = 0; i < TBS_bytes; i++){
       mac_sdus[i] = (unsigned char) (lrand48()&0xff);
-      //((uint8_t *)gNB_mac->UE_list.DLSCH_pdu[0][0].payload[0])[i] = (unsigned char) (lrand48()&0xff);
+      //((uint8_t *)gNB_mac->UE_info.DLSCH_pdu[0][0].payload[0])[i] = (unsigned char) (lrand48()&0xff);
     }
     //Sending SDUs with size 1
     //Initialize elements of sdu_lcids and sdu_lengths
@@ -706,13 +717,15 @@ void nr_schedule_uss_dlsch_phytest(module_id_t   module_idP,
     if (frameP%100 == 0){
       LOG_I(MAC, "Printing first 10 payload bytes at the gNB side, Frame: %d, slot: %d, TBS size: %d \n", frameP, slotP, TBS_bytes);
       for(int i = 0; i < 10; i++) {
-        LOG_I(MAC, "%x. ", ((uint8_t *)gNB_mac->UE_list.DLSCH_pdu[CC_id][0][0].payload[0])[i]);
+        LOG_I(MAC, "%x. ", ((uint8_t *)gNB_mac->UE_info.DLSCH_pdu[CC_id][0][0].payload[0])[i]);
       }
     }
     #endif
 
   }
 
+  UE_info->mac_stats[UE_id].lc_bytes_tx[lcid] += sdu_length_total;
+
   // there is at least one SDU or TA command
   // if (num_sdus > 0 ){
   if (ta_len + sdu_length_total + header_length_total > 0) {
@@ -729,8 +742,9 @@ void nr_schedule_uss_dlsch_phytest(module_id_t   module_idP,
     }
 
     offset = nr_generate_dlsch_pdu(module_idP,
+                                   &UE_info->UE_sched_ctrl[UE_id],
                                    (unsigned char *) mac_sdus,
-                                   (unsigned char *) gNB_mac->UE_list.DLSCH_pdu[0][0].payload[0],
+                                   (unsigned char *) gNB_mac->UE_info.DLSCH_pdu[0][0].payload[0],
                                    num_sdus, //num_sdus
                                    sdu_lengths,
                                    sdu_lcids,
@@ -741,7 +755,7 @@ void nr_schedule_uss_dlsch_phytest(module_id_t   module_idP,
     // Padding: fill remainder of DLSCH with 0
     if (post_padding > 0){
       for (int j = 0; j < (TBS_bytes - offset); j++)
-        gNB_mac->UE_list.DLSCH_pdu[0][0].payload[0][offset + j] = 0; // mac_pdu[offset + j] = 0;
+        gNB_mac->UE_info.DLSCH_pdu[0][0].payload[0][offset + j] = 0; // mac_pdu[offset + j] = 0;
     }
 
     configure_fapi_dl_Tx(module_idP, frameP, slotP, dl_req, tx_req, TBS_bytes, gNB_mac->pdu_index[CC_id]);
@@ -758,7 +772,7 @@ void nr_schedule_uss_dlsch_phytest(module_id_t   module_idP,
       if (frameP%100 == 0){
         LOG_I(MAC, "Printing first 10 payload bytes at the gNB side, Frame: %d, slot: %d, TBS size: %d \n", frameP, slotP, TBS_bytes);
         for(int i = 0; i < 10; i++) {
-          LOG_I(MAC, "byte %d : %x\n", i,((uint8_t *)gNB_mac->UE_list.DLSCH_pdu[0][0].payload[0])[i]); //LOG_I(MAC, "%x. ", mac_payload[i]);
+          LOG_I(MAC, "byte %d : %x\n", i,((uint8_t *)gNB_mac->UE_info.DLSCH_pdu[0][0].payload[0])[i]); //LOG_I(MAC, "%x. ", mac_payload[i]);
         }
       }
 #endif
@@ -799,12 +813,26 @@ int8_t select_ul_harq_pid(NR_UE_sched_ctrl_t *sched_ctrl) {
   return -1;
 }
 
+long get_K2(NR_BWP_Uplink_t *ubwp, int time_domain_assignment, int mu) {
+  DevAssert(ubwp);
+  const NR_PUSCH_TimeDomainResourceAllocation_t *tda_list = ubwp->bwp_Common->pusch_ConfigCommon->choice.setup->pusch_TimeDomainAllocationList->list.array[time_domain_assignment];
+  if (tda_list->k2)
+    return *tda_list->k2;
+  else if (mu < 2)
+    return 1;
+  else if (mu == 2)
+    return 2;
+  else
+    return 3;
+}
+
 void schedule_fapi_ul_pdu(int Mod_idP,
                           frame_t frameP,
                           sub_frame_t slotP,
                           int num_slots_per_tdd,
                           int ul_slots,
-                          int time_domain_assignment) {
+                          int time_domain_assignment,
+                          uint64_t ulsch_in_slot_bitmap) {
 
   gNB_MAC_INST                      *nr_mac    = RC.nrmac[Mod_idP];
   NR_COMMON_channels_t                  *cc    = nr_mac->common_channels;
@@ -813,10 +841,10 @@ void schedule_fapi_ul_pdu(int Mod_idP,
   int bwp_id=1;
   int mu = scc->uplinkConfigCommon->initialUplinkBWP->genericParameters.subcarrierSpacing;
   int UE_id = 0;
-  NR_UE_list_t *UE_list = &RC.nrmac[Mod_idP]->UE_list;
-  AssertFatal(UE_list->active[UE_id] >=0,"Cannot find UE_id %d is not active\n",UE_id);
+  NR_UE_info_t *UE_info = &RC.nrmac[Mod_idP]->UE_info;
+  AssertFatal(UE_info->active[UE_id],"Cannot find UE_id %d is not active\n",UE_id);
 
-  NR_CellGroupConfig_t *secondaryCellGroup = UE_list->secondaryCellGroup[UE_id];
+  NR_CellGroupConfig_t *secondaryCellGroup = UE_info->secondaryCellGroup[UE_id];
   AssertFatal(secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
 	      "downlinkBWP_ToAddModList has %d BWP!\n",
 	      secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count);
@@ -828,18 +856,14 @@ void schedule_fapi_ul_pdu(int Mod_idP,
   AssertFatal(time_domain_assignment<ubwp->bwp_Common->pusch_ConfigCommon->choice.setup->pusch_TimeDomainAllocationList->list.count,
               "time_domain_assignment %d>=%d\n",time_domain_assignment,ubwp->bwp_Common->pusch_ConfigCommon->choice.setup->pusch_TimeDomainAllocationList->list.count);
 
-  int K2;
-  if (ubwp->bwp_Common->pusch_ConfigCommon->choice.setup->pusch_TimeDomainAllocationList->list.array[time_domain_assignment]->k2 != NULL)
-   K2 = *ubwp->bwp_Common->pusch_ConfigCommon->choice.setup->pusch_TimeDomainAllocationList->list.array[time_domain_assignment]->k2;
-  else {
-    if (mu<2) K2=1;
-    else if(mu==2) K2=2;
-         else K2=3;
-  }
-
-  if (is_xlsch_in_slot(UE_list->UE_sched_ctrl[UE_id].ulsch_in_slot_bitmap,(slotP+K2)%num_slots_per_tdd)) {
-
-    //nfapi_nr_ul_tti_request_t *UL_tti_req = &RC.nrmac[Mod_idP]->UL_tti_req[0];
+  int K2 = get_K2(ubwp, time_domain_assignment,mu);
+  /* check if slot is UL, and for phy test verify that it is in first TDD
+   * period, slot 8 (for K2=2, this is at slot 6 in the gNB; because of UE
+   * limitations).  Note that if K2 or the TDD configuration is changed, below
+   * conditions might exclude each other and never be true */
+  const int slot_idx = (slotP + K2) % num_slots_per_tdd;
+  if (is_xlsch_in_slot(ulsch_in_slot_bitmap, slot_idx)
+        && (!get_softmodem_params()->phy_test || slotP == 6)) {
     nfapi_nr_ul_dci_request_t *UL_dci_req = &RC.nrmac[Mod_idP]->UL_dci_req[0];
     UL_dci_req->SFN = frameP;
     UL_dci_req->Slot = slotP;
@@ -849,10 +873,10 @@ void schedule_fapi_ul_pdu(int Mod_idP,
     AssertFatal(bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList->list.count>0,
                 "searchPsacesToAddModList is empty\n");
 
-    uint16_t rnti = UE_list->rnti[UE_id];
+    uint16_t rnti = UE_info->rnti[UE_id];
 
     int first_ul_slot = num_slots_per_tdd - ul_slots;
-    NR_sched_pusch *pusch_sched = &UE_list->UE_sched_ctrl[UE_id].sched_pusch[slotP+K2-first_ul_slot];
+    NR_sched_pusch *pusch_sched = &UE_info->UE_sched_ctrl[UE_id].sched_pusch[slotP+K2-first_ul_slot];
     pusch_sched->frame = frameP;
     pusch_sched->slot = slotP + K2;
     pusch_sched->active = true;
@@ -1002,9 +1026,9 @@ void schedule_fapi_ul_pdu(int Mod_idP,
 
     //Pusch Allocation in frequency domain [TS38.214, sec 6.1.2.2]
     //Optional Data only included if indicated in pduBitmap
-    int8_t harq_id = select_ul_harq_pid(&UE_list->UE_sched_ctrl[UE_id]);
+    int8_t harq_id = select_ul_harq_pid(&UE_info->UE_sched_ctrl[UE_id]);
     if (harq_id < 0) return;
-    NR_UE_ul_harq_t *cur_harq = &UE_list->UE_sched_ctrl[UE_id].ul_harq_processes[harq_id];
+    NR_UE_ul_harq_t *cur_harq = &UE_info->UE_sched_ctrl[UE_id].ul_harq_processes[harq_id];
     pusch_pdu->pusch_data.harq_process_id = harq_id;
     pusch_pdu->pusch_data.new_data_indicator = cur_harq->ndi;
     pusch_pdu->pusch_data.rv_index = nr_rv_round_map[cur_harq->round];
@@ -1034,8 +1058,8 @@ void schedule_fapi_ul_pdu(int Mod_idP,
                                                    0,
                                                    pusch_pdu->nrOfLayers)>>3;
 
-    UE_list->mac_stats[UE_id].ulsch_rounds[cur_harq->round]++;      
-    if (cur_harq->round == 0) UE_list->mac_stats[UE_id].ulsch_total_bytes_scheduled+=pusch_pdu->pusch_data.tb_size;      
+    UE_info->mac_stats[UE_id].ulsch_rounds[cur_harq->round]++;
+    if (cur_harq->round == 0) UE_info->mac_stats[UE_id].ulsch_total_bytes_scheduled+=pusch_pdu->pusch_data.tb_size;
 
     pusch_pdu->pusch_data.num_cb = 0; //CBG not supported
     //pusch_pdu->pusch_data.cb_present_and_position;
@@ -1084,22 +1108,34 @@ void schedule_fapi_ul_pdu(int Mod_idP,
     rnti_types[0]   = NR_RNTI_C;
     LOG_D(MAC,"Configuring ULDCI/PDCCH in %d.%d\n", frameP,slotP);
 
-    int ret = nr_configure_pdcch(nr_mac,
-                                 pdcch_pdu_rel15,
-                                 UE_list->rnti[UE_id],
-                                 1, // ue-specific,
-                                 ss,
-		                 scc,
-		                 bwp);
-
-    if (ret < 0) {
-      LOG_I(MAC,"CCE list not empty, couldn't schedule PUSCH\n");
+    uint8_t nr_of_candidates, aggregation_level;
+    find_aggregation_candidates(&aggregation_level, &nr_of_candidates, ss);
+    NR_ControlResourceSet_t *coreset = get_coreset(bwp, ss, 1 /* dedicated */);
+    int CCEIndex = allocate_nr_CCEs(
+        nr_mac,
+        bwp,
+        coreset,
+        aggregation_level,
+        UE_info->rnti[UE_id],
+        0); // m
+    if (CCEIndex < 0) {
+      LOG_E(MAC, "%s(): CCE list not empty, couldn't schedule PUSCH\n", __func__);
       pusch_sched->active = false;
       return;
     }
     else {
+      nr_configure_pdcch(nr_mac,
+                         pdcch_pdu_rel15,
+                         UE_info->rnti[UE_id],
+                         ss,
+                         coreset,
+                         scc,
+                         bwp,
+                         aggregation_level,
+                         CCEIndex);
+
       dci_pdu_rel15_t *dci_pdu_rel15 = calloc(MAX_DCI_CORESET,sizeof(dci_pdu_rel15_t));
-      config_uldci(ubwp,pusch_pdu,pdcch_pdu_rel15,&dci_pdu_rel15[0],dci_formats,rnti_types,time_domain_assignment,UE_list->UE_sched_ctrl[UE_id].tpc0,n_ubwp,bwp_id);
+      config_uldci(ubwp,pusch_pdu,pdcch_pdu_rel15,&dci_pdu_rel15[0],dci_formats,rnti_types,time_domain_assignment,UE_info->UE_sched_ctrl[UE_id].tpc0,n_ubwp,bwp_id);
       fill_dci_pdu_rel15(scc,secondaryCellGroup,pdcch_pdu_rel15,dci_pdu_rel15,dci_formats,rnti_types,pusch_pdu->bwp_size,bwp_id);
       free(dci_pdu_rel15);
     }
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
index f4ec142da191a1608c2681b6ca6076a14fd9bb51..b13cd89a19c3a15c017e23f11524e1fed3c18fb4 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
@@ -63,7 +63,6 @@
 #define ENABLE_MAC_PAYLOAD_DEBUG
 #define DEBUG_gNB_SCHEDULER 1
 
-
 #include "common/ran_context.h"
 
 extern RAN_CONTEXT_t RC;
@@ -127,37 +126,60 @@ static inline uint8_t get_max_cces(uint8_t scs) {
   return (nr_max_number_of_cces_per_slot[scs]);
 } 
 
+NR_ControlResourceSet_t *get_coreset(NR_BWP_Downlink_t *bwp,
+                                     NR_SearchSpace_t *ss,
+                                     int ss_type) {
+  NR_ControlResourceSetId_t coreset_id = *ss->controlResourceSetId;
+  if (ss_type == 0) { // common search space
+    AssertFatal(coreset_id != 0, "coreset0 currently not supported\n");
+    NR_ControlResourceSet_t *coreset = bwp->bwp_Common->pdcch_ConfigCommon->choice.setup->commonControlResourceSet;
+    AssertFatal(coreset_id == coreset->controlResourceSetId,
+                "ID of common ss coreset does not correspond to id set in the "
+                "search space\n");
+    return coreset;
+  } else {
+    const int n = bwp->bwp_Dedicated->pdcch_Config->choice.setup->controlResourceSetToAddModList->list.count;
+    for (int i = 0; i < n; i++) {
+      NR_ControlResourceSet_t *coreset =
+          bwp->bwp_Dedicated->pdcch_Config->choice.setup->controlResourceSetToAddModList->list.array[i];
+      if (coreset_id == coreset->controlResourceSetId) {
+        return coreset;
+      }
+    }
+    AssertFatal(0, "Couldn't find coreset with id %ld\n", coreset_id);
+  }
+}
+
+NR_SearchSpace_t *get_searchspace(
+    NR_BWP_Downlink_t *bwp,
+    NR_SearchSpace__searchSpaceType_PR target_ss) {
+  DevAssert(bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList);
+  DevAssert(bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList->list.count > 0);
+
+  const int n = bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList->list.count;
+  for (int i=0;i<n;i++) {
+    NR_SearchSpace_t *ss = bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList->list.array[i];
+    AssertFatal(ss->controlResourceSetId != NULL, "ss->controlResourceSetId is null\n");
+    AssertFatal(ss->searchSpaceType != NULL, "ss->searchSpaceType is null\n");
+    if (ss->searchSpaceType->present == target_ss) {
+      return ss;
+    }
+  }
+  AssertFatal(0, "Couldn't find an adequate searchspace\n");
+}
+
 int allocate_nr_CCEs(gNB_MAC_INST *nr_mac,
-		     int bwp_id,
-		     int list_id,
-		     int aggregation,
-		     int search_space, // 0 common, 1 ue-specific
-		     int UE_id,
-		     int m) {
+                     NR_BWP_Downlink_t *bwp,
+                     NR_ControlResourceSet_t *coreset,
+                     int aggregation,
+                     uint16_t n_RNTI,
+                     int m) {
   // uncomment these when we allocate for common search space
   //  NR_COMMON_channels_t                *cc      = nr_mac->common_channels;
   //  NR_ServingCellConfigCommon_t        *scc     = cc->ServingCellConfigCommon;
 
-  NR_UE_list_t *UE_list = &nr_mac->UE_list;
-
-  NR_BWP_Downlink_t *bwp;
-  NR_CellGroupConfig_t *secondaryCellGroup;
-
-  NR_ControlResourceSet_t *coreset;
-
-  AssertFatal(UE_list->active[UE_id] >=0,"UE_id %d is not active\n",UE_id);
-  secondaryCellGroup = UE_list->secondaryCellGroup[UE_id];
-  bwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.array[bwp_id-1];
-
-  if (search_space == 1) {
-    coreset = bwp->bwp_Dedicated->pdcch_Config->choice.setup->controlResourceSetToAddModList->list.array[list_id];
-  }
-  else {
-    coreset = bwp->bwp_Common->pdcch_ConfigCommon->choice.setup->commonControlResourceSet;
-  }
-
   int coreset_id = coreset->controlResourceSetId;
-  int *cce_list = nr_mac->cce_list[bwp_id][coreset_id];
+  int *cce_list = nr_mac->cce_list[bwp->bwp_Id][coreset_id];
 
   int n_rb=0;
   for (int i=0;i<6;i++)
@@ -167,17 +189,14 @@ int allocate_nr_CCEs(gNB_MAC_INST *nr_mac,
   n_rb*=6;
 
   uint16_t N_reg = n_rb * coreset->duration;
-  uint16_t Y=0, N_cce, M_s_max, n_CI=0;
-  uint16_t n_RNTI = search_space == 1 ? UE_list->rnti[UE_id]:0;
-  uint32_t A[3]={39827,39829,39839};
-
-  N_cce = N_reg / NR_NB_REG_PER_CCE;
+  uint16_t n_CI=0;
+  const uint32_t A[3]={39827,39829,39839};
+  /* if n_RNTI is zero, this results in zero, too! */
+  uint16_t Y = (A[0]*n_RNTI)%65537; // Candidate 0, antenna port 0
 
-  M_s_max = (aggregation==4)?4:(aggregation==8)?2:1;
+  uint16_t N_cce = N_reg / NR_NB_REG_PER_CCE;
 
-  if (search_space == 1) {
-    Y = (A[0]*n_RNTI)%65537; // Candidate 0, antenna port 0
-  }
+  uint16_t M_s_max = (aggregation==4)?4:(aggregation==8)?2:1;
   int first_cce = aggregation * (( Y + (m*N_cce)/(aggregation*M_s_max) + n_CI ) % CEILIDIV(N_cce,aggregation));
 
   for (int i=0;i<aggregation;i++)
@@ -407,44 +426,229 @@ void nr_configure_css_dci_initial(nfapi_nr_dl_tti_pdcch_pdu_rel15_t* pdcch_pdu,
 
 }
 
-int nr_configure_pdcch(gNB_MAC_INST *nr_mac,
-                       nfapi_nr_dl_tti_pdcch_pdu_rel15_t* pdcch_pdu,
-                       uint16_t rnti,
-                       int ss_type,
-                       NR_SearchSpace_t *ss,
-                       NR_ServingCellConfigCommon_t *scc,
-                       NR_BWP_Downlink_t *bwp){
+void nr_fill_nfapi_dl_pdu(int Mod_idP,
+                          int UE_id,
+                          int bwp_id,
+                          NR_SearchSpace_t *ss,
+                          NR_ControlResourceSet_t *coreset,
+                          nfapi_nr_dl_tti_request_body_t *dl_req,
+                          NR_sched_pucch *pucch_sched,
+                          int nrOfLayers,
+                          uint8_t mcs,
+                          uint16_t rbSize,
+                          uint16_t rbStart,
+                          uint8_t numDmrsCdmGrpsNoData,
+                          nfapi_nr_dmrs_type_e dmrsConfigType,
+                          uint8_t table_idx,
+                          uint16_t R,
+                          uint8_t Qm,
+                          uint32_t TBS,
+                          int time_domain_assignment,
+                          int StartSymbolIndex,
+                          int NrOfSymbols,
+                          uint8_t aggregation_level,
+                          int CCEIndex,
+                          int harq_pid,
+                          int ndi,
+                          int round) {
+  gNB_MAC_INST                        *nr_mac  = RC.nrmac[Mod_idP];
+  NR_COMMON_channels_t                *cc      = nr_mac->common_channels;
+  NR_ServingCellConfigCommon_t        *scc     = cc->ServingCellConfigCommon;
+
+  NR_UE_info_t *UE_info = &RC.nrmac[Mod_idP]->UE_info;
+
+  NR_CellGroupConfig_t *secondaryCellGroup = UE_info->secondaryCellGroup[UE_id];
+  AssertFatal(secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
+	      "downlinkBWP_ToAddModList has %d BWP!\n",
+	      secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count);
+  NR_BWP_Downlink_t *bwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.array[bwp_id-1];
 
-  int CCEIndex = -1;
-  int cid = 0;
-  NR_ControlResourceSet_t *coreset = NULL;
+  AssertFatal(bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList!=NULL,"searchPsacesToAddModList is null\n");
+  AssertFatal(bwp->bwp_Dedicated->pdcch_Config->choice.setup->searchSpacesToAddModList->list.count>0,
+              "searchPsacesToAddModList is empty\n");
+
+  nfapi_nr_dl_tti_request_pdu_t *dl_tti_pdcch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs];
+  memset((void*)dl_tti_pdcch_pdu,0,sizeof(nfapi_nr_dl_tti_request_pdu_t));
+  dl_tti_pdcch_pdu->PDUType = NFAPI_NR_DL_TTI_PDCCH_PDU_TYPE;
+  dl_tti_pdcch_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdcch_pdu));
+
+  nfapi_nr_dl_tti_request_pdu_t *dl_tti_pdsch_pdu = &dl_req->dl_tti_pdu_list[dl_req->nPDUs+1];
+  memset((void*)dl_tti_pdsch_pdu,0,sizeof(nfapi_nr_dl_tti_request_pdu_t));
+  dl_tti_pdsch_pdu->PDUType = NFAPI_NR_DL_TTI_PDSCH_PDU_TYPE;
+  dl_tti_pdsch_pdu->PDUSize = (uint8_t)(2+sizeof(nfapi_nr_dl_tti_pdsch_pdu));
+
+  nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu_rel15 = &dl_tti_pdcch_pdu->pdcch_pdu.pdcch_pdu_rel15;
+  nfapi_nr_dl_tti_pdsch_pdu_rel15_t *pdsch_pdu_rel15 = &dl_tti_pdsch_pdu->pdsch_pdu.pdsch_pdu_rel15;
+
+
+  pdsch_pdu_rel15->pduBitmap = 0;
+  pdsch_pdu_rel15->rnti = UE_info->rnti[UE_id];
+  pdsch_pdu_rel15->pduIndex = nr_mac->pdu_index[0]++;
+
+  // BWP
+  pdsch_pdu_rel15->BWPSize  = NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth,275);
+  pdsch_pdu_rel15->BWPStart = NRRIV2PRBOFFSET(bwp->bwp_Common->genericParameters.locationAndBandwidth,275);
+  pdsch_pdu_rel15->SubcarrierSpacing = bwp->bwp_Common->genericParameters.subcarrierSpacing;
+  if (bwp->bwp_Common->genericParameters.cyclicPrefix)
+    pdsch_pdu_rel15->CyclicPrefix = *bwp->bwp_Common->genericParameters.cyclicPrefix;
+  else
+    pdsch_pdu_rel15->CyclicPrefix = 0;
+
+  pdsch_pdu_rel15->NrOfCodewords = 1;
+  pdsch_pdu_rel15->targetCodeRate[0] = nr_get_code_rate_dl(mcs,0);
+  pdsch_pdu_rel15->qamModOrder[0] = 2;
+  pdsch_pdu_rel15->mcsIndex[0] = mcs;
+  pdsch_pdu_rel15->mcsTable[0] = 0;
+  pdsch_pdu_rel15->rvIndex[0] = nr_rv_round_map[round];
+  pdsch_pdu_rel15->dataScramblingId = *scc->physCellId;
+  pdsch_pdu_rel15->nrOfLayers = nrOfLayers;
+  pdsch_pdu_rel15->transmissionScheme = 0;
+  pdsch_pdu_rel15->refPoint = 0; // Point A
+  pdsch_pdu_rel15->dmrsConfigType = dmrsConfigType;
+  pdsch_pdu_rel15->dlDmrsScramblingId = *scc->physCellId;
+  pdsch_pdu_rel15->SCID = 0;
+  pdsch_pdu_rel15->numDmrsCdmGrpsNoData = numDmrsCdmGrpsNoData;
+  pdsch_pdu_rel15->dmrsPorts = 1;
+  pdsch_pdu_rel15->resourceAlloc = 1;
+  pdsch_pdu_rel15->rbStart = rbStart;
+  pdsch_pdu_rel15->rbSize = rbSize;
+  pdsch_pdu_rel15->VRBtoPRBMapping = 1; // non-interleaved, check if this is ok for initialBWP
+  pdsch_pdu_rel15->targetCodeRate[0] = R;
+  pdsch_pdu_rel15->qamModOrder[0] = Qm;
+  pdsch_pdu_rel15->TBSize[0] = TBS;
+  pdsch_pdu_rel15->mcsTable[0] = table_idx;
+  pdsch_pdu_rel15->StartSymbolIndex = StartSymbolIndex;
+  pdsch_pdu_rel15->NrOfSymbols      = NrOfSymbols;
+
+  //  k0 = *bwp->bwp_Common->pdsch_ConfigCommon->choice.setup->pdsch_TimeDomainAllocationList->list.array[i]->k0;
+  pdsch_pdu_rel15->dlDmrsSymbPos =
+      fill_dmrs_mask(bwp->bwp_Dedicated->pdsch_Config->choice.setup,
+                     scc->dmrs_TypeA_Position,
+                     pdsch_pdu_rel15->NrOfSymbols);
+
+  dci_pdu_rel15_t dci_pdu_rel15[MAX_DCI_CORESET];
+  memset(dci_pdu_rel15, 0, sizeof(dci_pdu_rel15_t) * MAX_DCI_CORESET);
+
+  // bwp indicator
+  int n_dl_bwp = secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count;
+  if (n_dl_bwp < 4)
+    dci_pdu_rel15[0].bwp_indicator.val = bwp_id;
+  else
+    dci_pdu_rel15[0].bwp_indicator.val = bwp_id - 1; // as per table 7.3.1.1.2-1 in 38.212
+  // frequency domain assignment
+  if (bwp->bwp_Dedicated->pdsch_Config->choice.setup->resourceAllocation==NR_PDSCH_Config__resourceAllocation_resourceAllocationType1)
+    dci_pdu_rel15[0].frequency_domain_assignment.val =
+        PRBalloc_to_locationandbandwidth0(
+            pdsch_pdu_rel15->rbSize,
+            pdsch_pdu_rel15->rbStart,
+            NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth,
+                     275));
+  else
+    AssertFatal(1==0,"Only frequency resource allocation type 1 is currently supported\n");
+  // time domain assignment
+  dci_pdu_rel15[0].time_domain_assignment.val = time_domain_assignment; // row index used here instead of SLIV;
+  // mcs and rv
+  dci_pdu_rel15[0].mcs = mcs;
+  dci_pdu_rel15[0].rv = pdsch_pdu_rel15->rvIndex[0];
+  // harq pid and ndi
+  dci_pdu_rel15[0].harq_pid = harq_pid;
+  dci_pdu_rel15[0].ndi = ndi;
+  // DAI
+  dci_pdu_rel15[0].dai[0].val = (pucch_sched->dai_c-1)&3;
+
+  // TPC for PUCCH
+  dci_pdu_rel15[0].tpc = UE_info->UE_sched_ctrl[UE_id].tpc1; // table 7.2.1-1 in 38.213
+  // PUCCH resource indicator
+  dci_pdu_rel15[0].pucch_resource_indicator = pucch_sched->resource_indicator;
+  // PDSCH to HARQ TI
+  dci_pdu_rel15[0].pdsch_to_harq_feedback_timing_indicator.val = pucch_sched->timing_indicator;
+  // antenna ports
+  dci_pdu_rel15[0].antenna_ports.val = 0;  // nb of cdm groups w/o data 1 and dmrs port 0
+  // dmrs sequence initialization
+  dci_pdu_rel15[0].dmrs_sequence_initialization.val = pdsch_pdu_rel15->SCID;
+  LOG_D(MAC,
+        "[gNB scheduler phytest] DCI type 1 payload: freq_alloc %d (%d,%d,%d), "
+        "time_alloc %d, vrb to prb %d, mcs %d tb_scaling %d ndi %d rv %d\n",
+        dci_pdu_rel15[0].frequency_domain_assignment.val,
+        pdsch_pdu_rel15->rbStart,
+        pdsch_pdu_rel15->rbSize,
+        NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth, 275),
+        dci_pdu_rel15[0].time_domain_assignment.val,
+        dci_pdu_rel15[0].vrb_to_prb_mapping.val,
+        dci_pdu_rel15[0].mcs,
+        dci_pdu_rel15[0].tb_scaling,
+        dci_pdu_rel15[0].ndi,
+        dci_pdu_rel15[0].rv);
+
+  nr_configure_pdcch(nr_mac,
+                     pdcch_pdu_rel15,
+                     UE_info->rnti[UE_id],
+                     ss,
+                     coreset,
+                     scc,
+                     bwp,
+                     aggregation_level,
+                     CCEIndex);
+
+  int dci_formats[2];
+  int rnti_types[2];
+
+  if (ss->searchSpaceType->choice.ue_Specific->dci_Formats)
+    dci_formats[0]  = NR_DL_DCI_FORMAT_1_1;
+  else
+    dci_formats[0]  = NR_DL_DCI_FORMAT_1_0;
+
+  rnti_types[0]   = NR_RNTI_C;
+
+  fill_dci_pdu_rel15(scc,secondaryCellGroup,pdcch_pdu_rel15,dci_pdu_rel15,dci_formats,rnti_types,pdsch_pdu_rel15->BWPSize,bwp_id);
+
+  LOG_D(MAC,
+        "DCI params: rnti %x, rnti_type %d, dci_format %d\n",
+        pdcch_pdu_rel15->dci_pdu.RNTI[0],
+        rnti_types[0],
+        dci_formats[0]);
+  LOG_D(MAC,
+        "coreset params: FreqDomainResource %llx, start_symbol %d  n_symb %d\n",
+        (unsigned long long)pdcch_pdu_rel15->FreqDomainResource,
+        pdcch_pdu_rel15->StartSymbolIndex,
+        pdcch_pdu_rel15->DurationSymbols);
+
+  // I don't know why the following is not needed, but in this case we don't
+  // need additional calculations:
+  //const uint16_t N_RE_prime = NR_NB_SC_PER_RB * N_sh_symb - N_PRB_DMRS - N_PRB_oh;
+  //LOG_D(MAC,
+  //      "N_RE_prime %d for %d symbols %d DMRS per PRB and %d overhead\n",
+  //      N_RE_prime,
+  //      N_sh_symb,
+  //      N_PRB_DMRS,
+  //      N_PRB_oh);
+  //pdsch_pdu_rel15->nb_mod_symbols = N_RE_prime*pdsch_pdu_rel15->n_prb*pdsch_pdu_rel15->nb_codewords;
+
+  LOG_D(MAC,
+        "DLSCH PDU: start PRB %d n_PRB %d start symbol %d nb_symbols %d "
+        "nb_layers %d nb_codewords %d mcs %d TBS: %d\n",
+        pdsch_pdu_rel15->rbStart,
+        pdsch_pdu_rel15->rbSize,
+        pdsch_pdu_rel15->StartSymbolIndex,
+        pdsch_pdu_rel15->NrOfSymbols,
+        pdsch_pdu_rel15->nrOfLayers,
+        pdsch_pdu_rel15->NrOfCodewords,
+        pdsch_pdu_rel15->mcsIndex[0],
+        TBS);
+
+  dl_req->nPDUs += 2;
+}
 
+void nr_configure_pdcch(gNB_MAC_INST *nr_mac,
+                        nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu,
+                        uint16_t rnti,
+                        NR_SearchSpace_t *ss,
+                        NR_ControlResourceSet_t *coreset,
+                        NR_ServingCellConfigCommon_t *scc,
+                        NR_BWP_Downlink_t *bwp,
+                        uint8_t aggregation_level,
+                        int CCEIndex) {
   if (bwp) { // This is not the InitialBWP
-    NR_ControlResourceSet_t *temp_coreset;
-    NR_ControlResourceSetId_t coresetid = *ss->controlResourceSetId;
-    if (ss_type == 0) { // common search space
-      if (coresetid == 0){
-        AssertFatal(1==0,"coreset0 currently not supported\n");
-      }
-      else {
-        coreset = bwp->bwp_Common->pdcch_ConfigCommon->choice.setup->commonControlResourceSet;
-        AssertFatal(coresetid==coreset->controlResourceSetId,"ID of common ss coreset does not correspond to id set in the search space\n");
-      }
-    }
-    else {
-      int n_list = bwp->bwp_Dedicated->pdcch_Config->choice.setup->controlResourceSetToAddModList->list.count;
-      for (int i=0; i<n_list; i++) {
-        temp_coreset = bwp->bwp_Dedicated->pdcch_Config->choice.setup->controlResourceSetToAddModList->list.array[i];
-        if (coresetid==temp_coreset->controlResourceSetId) {
-          coreset = temp_coreset;
-          cid = i;
-          break;
-        }
-      }
-      if(coreset==NULL)
-        AssertFatal(1==0,"Couldn't find coreset with id %ld\n",coresetid);
-    }
-    
     pdcch_pdu->BWPSize  = NRRIV2BW(bwp->bwp_Common->genericParameters.locationAndBandwidth,275);
     pdcch_pdu->BWPStart = NRRIV2PRBOFFSET(bwp->bwp_Common->genericParameters.locationAndBandwidth,275);
     pdcch_pdu->SubcarrierSpacing = bwp->bwp_Common->genericParameters.subcarrierSpacing;
@@ -507,22 +711,6 @@ int nr_configure_pdcch(gNB_MAC_INST *nr_mac,
       pdcch_pdu->dci_pdu.ScramblingRNTI[pdcch_pdu->numDlDci]=0;
     }
 
-    uint8_t nr_of_candidates,aggregation_level;
-    find_aggregation_candidates(&aggregation_level,
-                               &nr_of_candidates,
-                               ss);
-
-    CCEIndex = allocate_nr_CCEs(nr_mac,
-                                1, // bwp_id
-                                cid,
-                                aggregation_level,
-                                ss->searchSpaceType->present-1, // search_space, 0 common, 1 ue-specific
-                                0, // UE-id
-                                0); // m
-
-    if (CCEIndex<0)
-     return (CCEIndex);
-
     pdcch_pdu->dci_pdu.AggregationLevel[pdcch_pdu->numDlDci] = aggregation_level;
     pdcch_pdu->dci_pdu.CceIndex[pdcch_pdu->numDlDci] = CCEIndex;
 
@@ -531,7 +719,6 @@ int nr_configure_pdcch(gNB_MAC_INST *nr_mac,
 
     pdcch_pdu->dci_pdu.powerControlOffsetSS[pdcch_pdu->numDlDci]=1;
     pdcch_pdu->numDlDci++;
-    return (0);
   }
   else { // this is for InitialBWP
     AssertFatal(1==0,"Fill in InitialBWP PDCCH configuration\n");
@@ -1396,39 +1583,34 @@ int extract_length(int startSymbolAndLength) {
 }
 
 /*
- * Dump the UL or DL UE_list into LOG_T(MAC)
+ * Dump the UL or DL UE_info into LOG_T(MAC)
  */
-void
-dump_nr_ue_list(NR_UE_list_t *listP,
-             int ul_flag)
-//------------------------------------------------------------------------------
-{
-  if (ul_flag == 0) {
-    for (int j = listP->head; j >= 0; j = listP->next[j]) {
-      LOG_T(MAC, "DL list node %d => %d\n",
-            j,
-            listP->next[j]);
-    }
-  } else {
-    for (int j = listP->head_ul; j >= 0; j = listP->next_ul[j]) {
-      LOG_T(MAC, "UL list node %d => %d\n",
-            j,
-            listP->next_ul[j]);
-    }
-  }
+void dump_nr_ue_list(NR_UE_list_t *listP) {
+  for (int j = listP->head; j >= 0; j = listP->next[j])
+    LOG_T(MAC, "DL list node %d => %d\n", j, listP->next[j]);
+}
 
-  return;
+/*
+ * Add a UE to NR_UE_list listP
+ */
+inline void add_nr_ue_list(NR_UE_list_t *listP, int UE_id) {
+  int *cur = &listP->head;
+  while (*cur >= 0) {
+    AssertFatal(*cur != UE_id, "UE_id %d already in NR_UE_list!\n", UE_id);
+    cur = &listP->next[*cur];
+  }
+  *cur = UE_id;
 }
 
 int find_nr_UE_id(module_id_t mod_idP, rnti_t rntiP)
 //------------------------------------------------------------------------------
 {
   int UE_id;
-  NR_UE_list_t *UE_list = &RC.nrmac[mod_idP]->UE_list;
+  NR_UE_info_t *UE_info = &RC.nrmac[mod_idP]->UE_info;
 
   for (UE_id = 0; UE_id < MAX_MOBILES_PER_GNB; UE_id++) {
-    if (UE_list->active[UE_id] == TRUE) {
-      if (UE_list->rnti[UE_id] == rntiP) {
+    if (UE_info->active[UE_id]) {
+      if (UE_info->rnti[UE_id] == rntiP) {
         return UE_id;
       }
     }
@@ -1439,40 +1621,38 @@ int find_nr_UE_id(module_id_t mod_idP, rnti_t rntiP)
 
 int add_new_nr_ue(module_id_t mod_idP, rnti_t rntiP){
 
-  int UE_id;
-  int i;
-  NR_UE_list_t *UE_list = &RC.nrmac[mod_idP]->UE_list;
+  NR_UE_info_t *UE_info = &RC.nrmac[mod_idP]->UE_info;
   NR_COMMON_channels_t *cc = RC.nrmac[mod_idP]->common_channels;
   NR_ServingCellConfigCommon_t *scc = cc->ServingCellConfigCommon;
   int num_slots_ul = scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots;
   if (scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols>0)
     num_slots_ul++;
-  LOG_I(MAC, "[gNB %d] Adding UE with rnti %x (next avail %d, num_UEs %d)\n",
+  LOG_W(MAC, "[gNB %d] Adding UE with rnti %x (num_UEs %d)\n",
         mod_idP,
         rntiP,
-        UE_list->avail,
-        UE_list->num_UEs);
-  dump_nr_ue_list(UE_list, 0);
+        UE_info->num_UEs);
+  dump_nr_ue_list(&UE_info->list);
 
-  for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
-    if (UE_list->active[i] == TRUE)
+  for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
+    if (UE_info->active[i])
       continue;
 
-    UE_id = i;
-    UE_list->num_UEs++;
-    UE_list->active[UE_id] = TRUE;
-    UE_list->rnti[UE_id] = rntiP;
-    memset((void *) &UE_list->UE_sched_ctrl[UE_id],
+    int UE_id = i;
+    UE_info->num_UEs++;
+    UE_info->active[UE_id] = true;
+    UE_info->rnti[UE_id] = rntiP;
+    add_nr_ue_list(&UE_info->list, UE_id);
+    memset((void *) &UE_info->UE_sched_ctrl[UE_id],
            0,
            sizeof(NR_UE_sched_ctrl_t));
-    UE_list->UE_sched_ctrl[UE_id].ul_rssi = 0;
-    UE_list->UE_sched_ctrl[UE_id].sched_pucch = (NR_sched_pucch *)malloc(num_slots_ul*sizeof(NR_sched_pucch));
-    UE_list->UE_sched_ctrl[UE_id].sched_pusch = (NR_sched_pusch *)malloc(num_slots_ul*sizeof(NR_sched_pusch));
+    UE_info->UE_sched_ctrl[UE_id].ul_rssi = 0;
+    UE_info->UE_sched_ctrl[UE_id].sched_pucch = (NR_sched_pucch *)malloc(num_slots_ul*sizeof(NR_sched_pucch));
+    UE_info->UE_sched_ctrl[UE_id].sched_pusch = (NR_sched_pusch *)malloc(num_slots_ul*sizeof(NR_sched_pusch));
     for (int k=0; k<num_slots_ul; k++) {
-      memset((void *) &UE_list->UE_sched_ctrl[UE_id].sched_pucch[k],
+      memset((void *) &UE_info->UE_sched_ctrl[UE_id].sched_pucch[k],
              0,
              sizeof(NR_sched_pucch));
-      memset((void *) &UE_list->UE_sched_ctrl[UE_id].sched_pusch[k],
+      memset((void *) &UE_info->UE_sched_ctrl[UE_id].sched_pusch[k],
              0,
              sizeof(NR_sched_pusch));
     }
@@ -1480,15 +1660,13 @@ int add_new_nr_ue(module_id_t mod_idP, rnti_t rntiP){
           mod_idP,
           UE_id,
           rntiP);
-    dump_nr_ue_list(UE_list,
-		    0);
+    dump_nr_ue_list(&UE_info->list);
     return (UE_id);
   }
 
   // printf("MAC: cannot add new UE for rnti %x\n", rntiP);
-  LOG_E(MAC, "error in add_new_ue(), could not find space in UE_list, Dumping UE list\n");
-  dump_nr_ue_list(UE_list,
-		  0);
+  LOG_E(MAC, "error in add_new_ue(), could not find space in UE_info, Dumping UE list\n");
+  dump_nr_ue_list(&UE_info->list);
   return -1;
 }
 
@@ -1510,8 +1688,8 @@ void get_pdsch_to_harq_feedback(int Mod_idP,
                                 uint8_t *pdsch_to_harq_feedback) {
 
   int bwp_id=1;
-  NR_UE_list_t *UE_list = &RC.nrmac[Mod_idP]->UE_list;
-  NR_CellGroupConfig_t *secondaryCellGroup = UE_list->secondaryCellGroup[UE_id];
+  NR_UE_info_t *UE_info = &RC.nrmac[Mod_idP]->UE_info;
+  NR_CellGroupConfig_t *secondaryCellGroup = UE_info->secondaryCellGroup[UE_id];
   NR_BWP_Downlink_t *bwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.array[bwp_id-1];
   NR_BWP_Uplink_t *ubwp=secondaryCellGroup->spCellConfig->spCellConfigDedicated->uplinkConfig->uplinkBWP_ToAddModList->list.array[bwp_id-1];
 
@@ -1563,7 +1741,7 @@ void nr_update_pucch_scheduling(int Mod_idP,
                                 int *pucch_id) {
 
   NR_ServingCellConfigCommon_t *scc = RC.nrmac[Mod_idP]->common_channels->ServingCellConfigCommon;
-  NR_UE_list_t *UE_list = &RC.nrmac[Mod_idP]->UE_list;
+  NR_UE_info_t *UE_info = &RC.nrmac[Mod_idP]->UE_info;
   NR_sched_pucch *curr_pucch;
   int first_ul_slot_tdd,k,i;
   uint8_t pdsch_to_harq_feedback[8];
@@ -1578,7 +1756,7 @@ void nr_update_pucch_scheduling(int Mod_idP,
 
   // for each possible ul or mixed slot
   for (k=0; k<nr_ulmix_slots; k++) {
-    curr_pucch = &UE_list->UE_sched_ctrl[UE_id].sched_pucch[k];
+    curr_pucch = &UE_info->UE_sched_ctrl[UE_id].sched_pucch[k];
     // if there is free room in current pucch structure
     if (curr_pucch->dai_c<MAX_ACK_BITS) {
       curr_pucch->frame = frameP;
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
index bb0dad7064d5a13b229c99785648b3f751d84910..b87d8787bfb7ebaf9baeb4b0784f1fb8f8632e2b 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
@@ -212,7 +212,7 @@ void nr_process_mac_pdu(
 
                 LOG_D(MAC, "[UE %d] Frame %d : ULSCH -> UL-DTCH %d (gNB %d, %d bytes)\n", module_idP, frameP, rx_lcid, module_idP, mac_sdu_len);
 		int UE_id = find_nr_UE_id(module_idP, rnti);
-		RC.nrmac[module_idP]->UE_list.mac_stats[UE_id].lc_bytes_rx[rx_lcid] += mac_sdu_len;
+		RC.nrmac[module_idP]->UE_info.mac_stats[UE_id].lc_bytes_rx[rx_lcid] += mac_sdu_len;
                 #if defined(ENABLE_MAC_PAYLOAD_DEBUG)
                     LOG_T(MAC, "[UE %d] First 32 bytes of DLSCH : \n", module_idP);
 
@@ -313,19 +313,19 @@ void nr_rx_sdu(const module_id_t gnb_mod_idP,
                const uint16_t rssi){
   int current_rnti = 0, UE_id = -1, harq_pid = 0;
   gNB_MAC_INST *gNB_mac = NULL;
-  NR_UE_list_t *UE_list = NULL;
+  NR_UE_info_t *UE_info = NULL;
   NR_UE_sched_ctrl_t *UE_scheduling_control = NULL;
 
   current_rnti = rntiP;
   UE_id = find_nr_UE_id(gnb_mod_idP, current_rnti);
   gNB_mac = RC.nrmac[gnb_mod_idP];
-  UE_list = &gNB_mac->UE_list;
+  UE_info = &gNB_mac->UE_info;
   int target_snrx10 = gNB_mac->pusch_target_snrx10;
 
   if (UE_id != -1) {
-    UE_scheduling_control = &(UE_list->UE_sched_ctrl[UE_id]);
+    UE_scheduling_control = &(UE_info->UE_sched_ctrl[UE_id]);
 
-    UE_list->mac_stats[UE_id].ulsch_total_bytes_rx += sdu_lenP;
+    UE_info->mac_stats[UE_id].ulsch_total_bytes_rx += sdu_lenP;
     LOG_D(MAC, "[gNB %d][PUSCH %d] CC_id %d %d.%d Received ULSCH sdu from PHY (rnti %x, UE_id %d) ul_cqi %d\n",
           gnb_mod_idP,
           harq_pid,
@@ -365,20 +365,44 @@ void nr_rx_sdu(const module_id_t gnb_mod_idP,
 
     }
   }
-  else {
+  else if (sduP != NULL) { // if the CRC passed
     // random access pusch with TC-RNTI
-    if (sduP != NULL) { // if the CRC passed
-      for (int i = 0; i < MAX_MOBILES_PER_GNB; i++) {
-        if (UE_list->active[i] == TRUE) {
-          if (UE_list->tc_rnti[i] == current_rnti) {
-            // for now the only thing we are doing is set the UE as 5G connected
-            UE_list->fiveG_connected[i] = true;
-            LOG_I(MAC, "[gNB %d][RAPROC] PUSCH with TC_RNTI %x received correctly and UE_id %d is now 5G connected\n",
-                  gnb_mod_idP, current_rnti, i);
-          }
-        }
-      }
+    NR_RA_t *ra = &gNB_mac->common_channels[CC_idP].ra[0];
+    if (ra->state != WAIT_Msg3) {
+      LOG_E(MAC,
+            "expected RA state WAIT_Msg3/%d (but is %d) for RA-RNTI %04x\n",
+            WAIT_Msg3,
+            ra->state,
+            ra->rnti);
+      return;
+    }
+    if (ra->rnti != current_rnti) {
+      LOG_E(MAC,
+            "expected RA-RNTI %04x (C-RNTI %04x) to match current RNTI %04x\n",
+            ra->rnti,
+            ra->crnti,
+            current_rnti);
+      return;
     }
+    free(ra->preambles.preamble_list);
+    ra->state = RA_IDLE;
+    LOG_I(MAC, "reset RA state information for RA-RNTI %04x\n", ra->rnti);
+    const int UE_id = add_new_nr_ue(gnb_mod_idP, ra->crnti);
+    UE_info->secondaryCellGroup[UE_id] = ra->secondaryCellGroup;
+    struct NR_ServingCellConfig__downlinkBWP_ToAddModList *bwpList =
+        ra->secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList;
+    AssertFatal(bwpList->list.count == 1,
+                "downlinkBWP_ToAddModList has %d BWP!\n",
+                bwpList->list.count);
+    const int bwp_id = 1;
+    UE_info->UE_sched_ctrl[UE_id].active_bwp = bwpList->list.array[bwp_id - 1];
+    LOG_W(MAC,
+          "[gNB %d][RAPROC] PUSCH with TC_RNTI %x received correctly, "
+          "adding UE MAC Context UE_id %d/RNTI %04x\n",
+          gnb_mod_idP,
+          current_rnti,
+          UE_id,
+          ra->crnti);
   }
 }
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
index 7caf1baed57bcf22d32ce286afe90d7ee174c79a..f636a27300d583188aedf52c031ae29b65594a28 100644
--- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
+++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
@@ -67,6 +67,7 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
 			       frame_t frame_rxP, sub_frame_t slot_rxP);
 
 int nr_generate_dlsch_pdu(module_id_t Mod_idP,
+                          NR_UE_sched_ctrl_t *ue_sched_ctl,
                           unsigned char *sdus_payload,
                           unsigned char *mac_pdu,
                           unsigned char num_sdus,
@@ -76,7 +77,10 @@ int nr_generate_dlsch_pdu(module_id_t Mod_idP,
                           unsigned char *ue_cont_res_id,
                           unsigned short post_padding);
 
-void nr_schedule_ue_spec(module_id_t module_idP, frame_t frameP, sub_frame_t slotP);
+void nr_schedule_ue_spec(module_id_t module_id,
+                         frame_t frame,
+                         sub_frame_t slot,
+                         int num_slots_per_tdd);
 
 void schedule_nr_mib(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP);
 
@@ -126,12 +130,38 @@ void nr_schedule_css_dlsch_phytest(module_id_t   module_idP,
                                    frame_t       frameP,
                                    sub_frame_t   subframeP);
 
-int configure_fapi_dl_pdu(int Mod_id,
-                         nfapi_nr_dl_tti_request_body_t *dl_req,
-                         NR_sched_pucch *pucch_sched,
-                         uint8_t *mcsIndex,
-                         uint16_t *rbSize,
-                         uint16_t *rbStart);
+void nr_fill_nfapi_dl_pdu(int Mod_id,
+                          int UE_id,
+                          int bwp_id,
+                          NR_SearchSpace_t *ss,
+                          NR_ControlResourceSet_t *coreset,
+                          nfapi_nr_dl_tti_request_body_t *dl_req,
+                          NR_sched_pucch *pucch_sched,
+                          int nrOfLayers,
+                          uint8_t mcs,
+                          uint16_t rbSize,
+                          uint16_t rbStart,
+                          uint8_t numDmrsCdmGrpsNoData,
+                          nfapi_nr_dmrs_type_e dmrsConfigType,
+                          uint8_t table_idx,
+                          uint16_t R,
+                          uint8_t Qm,
+                          uint32_t tbs,
+                          int time_domain_assignment,
+                          int StartSymbolIndex,
+                          int NrOfSymbols,
+                          uint8_t aggregation_level,
+                          int CCEIndex,
+                          int harq_pid,
+                          int ndi,
+                          int round);
+
+int configure_fapi_dl_pdu_phytest(int Mod_id,
+                                  nfapi_nr_dl_tti_request_body_t *dl_req,
+                                  NR_sched_pucch *pucch_sched,
+                                  uint8_t *mcsIndex,
+                                  uint16_t *rbSize,
+                                  uint16_t *rbStart);
 
 void config_uldci(NR_BWP_Uplink_t *ubwp,
                   nfapi_nr_pusch_pdu_t *pusch_pdu,
@@ -211,13 +241,15 @@ void find_search_space(int ss_type,
                        NR_BWP_Downlink_t *bwp,
                        NR_SearchSpace_t *ss);
 
-int nr_configure_pdcch(gNB_MAC_INST *nr_mac,
-                       nfapi_nr_dl_tti_pdcch_pdu_rel15_t* pdcch_pdu,
-                       uint16_t rnti,
-                       int ss_type,
-                       NR_SearchSpace_t *ss,
-                       NR_ServingCellConfigCommon_t *scc,
-                       NR_BWP_Downlink_t *bwp);
+void nr_configure_pdcch(gNB_MAC_INST *nr_mac,
+                        nfapi_nr_dl_tti_pdcch_pdu_rel15_t *pdcch_pdu,
+                        uint16_t rnti,
+                        NR_SearchSpace_t *ss,
+                        NR_ControlResourceSet_t *coreset,
+                        NR_ServingCellConfigCommon_t *scc,
+                        NR_BWP_Downlink_t *bwp,
+                        uint8_t aggregation_level,
+                        int CCEIndex);
 
 void fill_dci_pdu_rel15(NR_ServingCellConfigCommon_t *scc,
                         NR_CellGroupConfig_t *secondaryCellGroup,
@@ -233,6 +265,16 @@ void prepare_dci(NR_CellGroupConfig_t *secondaryCellGroup,
                  nr_dci_format_t format,
                  int bwp_id);
 
+/* find coreset within the search space */
+NR_ControlResourceSet_t *get_coreset(NR_BWP_Downlink_t *bwp,
+                                     NR_SearchSpace_t *ss,
+                                     int ss_type);
+
+/* find a search space within a BWP */
+NR_SearchSpace_t *get_searchspace(
+    NR_BWP_Downlink_t *bwp,
+    NR_SearchSpace__searchSpaceType_PR target_ss);
+
 void find_aggregation_candidates(uint8_t *aggregation_level,
                                  uint8_t *nr_of_candidates,
                                  NR_SearchSpace_t *ss);
@@ -259,20 +301,19 @@ int NRRIV2BW(int locationAndBandwidth,int N_RB);
 
 int NRRIV2PRBOFFSET(int locationAndBandwidth,int N_RB);
 
-void dump_nr_ue_list(NR_UE_list_t *listP, int ul_flag);
+void dump_nr_ue_list(NR_UE_list_t *listP);
+void add_nr_ue_list(NR_UE_list_t *listP, int UE_id);
 
 int find_nr_UE_id(module_id_t mod_idP, rnti_t rntiP);
 
 int add_new_nr_ue(module_id_t mod_idP, rnti_t rntiP);
 
 int allocate_nr_CCEs(gNB_MAC_INST *nr_mac,
-                     int bwp_id,
-                     int coreset_id,
+                     NR_BWP_Downlink_t *bwp,
+                     NR_ControlResourceSet_t *coreset,
                      int aggregation,
-                     int search_space, // 0 common, 1 ue-specific
-                     int UE_id,
-                     int m
-                     );
+                     uint16_t n_RNTI,
+                     int m);
 
 int get_dlscs(nfapi_nr_config_request_t *cfg);
 
@@ -305,7 +346,8 @@ void schedule_fapi_ul_pdu(int Mod_idP,
                           sub_frame_t slotP,
                           int num_slots_per_tdd,
                           int ul_slots,
-                          int time_domain_assignment);
+                          int time_domain_assignment,
+                          uint64_t ulsch_in_slot_bitmap);
 
 void nr_process_mac_pdu(
     module_id_t module_idP,
diff --git a/openair2/LAYER2/NR_MAC_gNB/main.c b/openair2/LAYER2/NR_MAC_gNB/main.c
index bd0be8c4092f070bf6a2c47b8f11c7c89ec4e30f..7df00f15f1cc3967219f90b9a67fcd3ce956b0f7 100644
--- a/openair2/LAYER2/NR_MAC_gNB/main.c
+++ b/openair2/LAYER2/NR_MAC_gNB/main.c
@@ -50,7 +50,7 @@ void mac_top_init_gNB(void)
 {
   module_id_t     i;
   int             list_el;
-  NR_UE_list_t    *UE_list;
+  NR_UE_info_t    *UE_info;
   gNB_MAC_INST    *nrmac;
 
   LOG_I(MAC, "[MAIN] Init function start:nb_nr_macrlc_inst=%d\n",RC.nb_nr_macrlc_inst);
@@ -104,29 +104,21 @@ void mac_top_init_gNB(void)
     nrmac = RC.nrmac[i];
     nrmac->if_inst = NR_IF_Module_init(i);
     
-    UE_list = &nrmac->UE_list;
-    UE_list->num_UEs = 0;
-    UE_list->head = -1;
-    UE_list->head_ul = -1;
-    UE_list->avail = 0;
-
-    for (list_el = 0; list_el < MAX_MOBILES_PER_GNB - 1; list_el++) {
-       UE_list->next[list_el] = list_el + 1;
-      UE_list->next_ul[list_el] = list_el + 1;
-      UE_list->active[list_el] = FALSE;
+    UE_info = &nrmac->UE_info;
+    UE_info->num_UEs = 0;
+    UE_info->list.head = -1;
+    for (list_el = 0; list_el < MAX_MOBILES_PER_GNB; list_el++) {
+      UE_info->list.next[list_el] = -1;
+      UE_info->active[list_el] = false;
       for (int list_harq = 0; list_harq < NR_MAX_NB_HARQ_PROCESSES; list_harq++) {
-        UE_list->UE_sched_ctrl[list_el].harq_processes[list_harq].round = 0;
-        UE_list->UE_sched_ctrl[list_el].harq_processes[list_harq].ndi = 0;
-        UE_list->UE_sched_ctrl[list_el].harq_processes[list_harq].is_waiting = 0;
-        UE_list->UE_sched_ctrl[list_el].ul_harq_processes[list_harq].round = 0;
-        UE_list->UE_sched_ctrl[list_el].ul_harq_processes[list_harq].ndi = 0;
-        UE_list->UE_sched_ctrl[list_el].ul_harq_processes[list_harq].state = 0;
+        UE_info->UE_sched_ctrl[list_el].harq_processes[list_harq].round = 0;
+        UE_info->UE_sched_ctrl[list_el].harq_processes[list_harq].ndi = 0;
+        UE_info->UE_sched_ctrl[list_el].harq_processes[list_harq].is_waiting = 0;
+        UE_info->UE_sched_ctrl[list_el].ul_harq_processes[list_harq].round = 0;
+        UE_info->UE_sched_ctrl[list_el].ul_harq_processes[list_harq].ndi = 0;
+        UE_info->UE_sched_ctrl[list_el].ul_harq_processes[list_harq].state = 0;
       }
     }
-
-    UE_list->next[list_el] = -1;
-    UE_list->next_ul[list_el] = -1;
-    UE_list->active[list_el] = FALSE;
   }
 
   srand48(0);
diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
index bd8f0208c6561f1c3c93f04d6715909aa3613df8..e0a484abdbc30aac92671e5911081601ab83c054 100644
--- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
+++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
@@ -83,6 +83,11 @@ typedef enum {
   WAIT_Msg4_ACK = 4
 } RA_gNB_state_t;
 
+typedef struct NR_preamble_ue {
+  uint8_t num_preambles;
+  uint8_t *preamble_list;
+} NR_preamble_ue_t;
+
 /*! \brief gNB template for the Random access information */
 typedef struct {
   /// Flag to indicate this process is active
@@ -141,6 +146,12 @@ typedef struct {
   int msg4_mcs;
   /// RA search space
   NR_SearchSpace_t *ra_ss;
+  /// secondaryCellGroup for UE in NSA that is to come
+  NR_CellGroupConfig_t *secondaryCellGroup;
+  /// Preambles for contention-free access
+  NR_preamble_ue_t preambles;
+  /// NSA: the UEs C-RNTI to use
+  rnti_t crnti;
 } NR_RA_t;
 
 /*! \brief gNB common channels */
@@ -172,9 +183,9 @@ typedef struct {
   /// Template for RA computations
   NR_RA_t ra[NR_NB_RA_PROC_MAX];
   /// VRB map for common channels
-  uint8_t vrb_map[100];
+  uint8_t vrb_map[275];
   /// VRB map for common channels and retransmissions by PHICH
-  uint8_t vrb_map_UL[100];
+  uint8_t vrb_map_UL[275];
   /// number of subframe allocation pattern available for MBSFN sync area
   uint8_t num_sf_allocation_pattern;
 } NR_COMMON_channels_t;
@@ -268,6 +279,14 @@ typedef struct NR_UE_harq {
   uint16_t feedback_slot;
 } NR_UE_harq_t;
 
+typedef struct NR_UE_old_sched {
+  uint16_t rbSize;
+  int time_domain_allocation;
+  uint8_t mcsTableIdx;
+  uint8_t mcs;
+  uint8_t numDmrsCdmGrpsNoData;
+} NR_UE_ret_info_t;
+
 typedef enum {
   INACTIVE = 0,
   ACTIVE_NOT_SCHED,
@@ -283,10 +302,39 @@ typedef struct NR_UE_ul_harq {
 
 /*! \brief scheduling control information set through an API */
 typedef struct {
-  uint64_t dlsch_in_slot_bitmap;  // static bitmap signaling which slot in a tdd period contains dlsch
-  uint64_t ulsch_in_slot_bitmap;  // static bitmap signaling which slot in a tdd period contains ulsch
+  /// total amount of data awaiting for this UE
+  uint32_t num_total_bytes;
+  /// per-LC status data
+  mac_rlc_status_resp_t rlc_status[MAX_NUM_LCID];
+
+  /// the currently active BWP in DL
+  NR_BWP_Downlink_t *active_bwp;
   NR_sched_pucch *sched_pucch;
+  /// selected PUCCH index, if scheduled
+  int pucch_sched_idx;
   NR_sched_pusch *sched_pusch;
+
+  /// CCE index and aggregation, should be coherent with cce_list
+  NR_SearchSpace_t *search_space;
+  NR_ControlResourceSet_t *coreset;
+  int cce_index;
+  uint8_t aggregation_level;
+
+  /// RB allocation within active BWP
+  uint16_t rbSize;
+  uint16_t rbStart;
+
+  // time-domain allocation for scheduled RBs
+  int time_domain_allocation;
+
+  /// MCS-related infos
+  uint8_t mcsTableIdx;
+  uint8_t mcs;
+  uint8_t numDmrsCdmGrpsNoData;
+
+  /// Retransmission-related information
+  NR_UE_ret_info_t retInfo[NR_MAX_NB_HARQ_PROCESSES];
+
   uint16_t ta_timer;
   int16_t ta_update;
   uint8_t tpc0;
@@ -299,11 +347,6 @@ typedef struct {
   NR_UE_mac_ce_ctrl_t UE_mac_ce_ctrl;// MAC CE related information
 } NR_UE_sched_ctrl_t;
 
-typedef struct NR_preamble_ue {
-  uint8_t num_preambles;
-  uint8_t *preamble_list;
-} NR_preamble_ue;
-
 typedef struct {
 
   int lc_bytes_tx[64];
@@ -317,25 +360,26 @@ typedef struct {
   int ulsch_total_bytes_rx;
 } NR_mac_stats_t;
 
+
+/*! \brief UNR_E_list_t is a "list" of users within UE_info_t. Especial useful in
+ * the scheduler and to keep "classes" of users. */
+typedef struct {
+  int head;
+  int next[MAX_MOBILES_PER_GNB];
+} NR_UE_list_t;
+
 /*! \brief UE list used by gNB to order UEs/CC for scheduling*/
 typedef struct {
   DLSCH_PDU DLSCH_pdu[4][MAX_MOBILES_PER_GNB];
   /// scheduling control info
   NR_UE_sched_ctrl_t UE_sched_ctrl[MAX_MOBILES_PER_GNB];
   NR_mac_stats_t mac_stats[MAX_MOBILES_PER_GNB];
-  int next[MAX_MOBILES_PER_GNB];
-  int head;
-  int next_ul[MAX_MOBILES_PER_GNB];
-  int head_ul;
-  int avail;
+  NR_UE_list_t list;
   int num_UEs;
-  boolean_t active[MAX_MOBILES_PER_GNB];
-  boolean_t fiveG_connected[MAX_MOBILES_PER_GNB];
+  bool active[MAX_MOBILES_PER_GNB];
   rnti_t rnti[MAX_MOBILES_PER_GNB];
-  rnti_t tc_rnti[MAX_MOBILES_PER_GNB];
-  NR_preamble_ue preambles[MAX_MOBILES_PER_GNB];
   NR_CellGroupConfig_t *secondaryCellGroup[MAX_MOBILES_PER_GNB];
-} NR_UE_list_t;
+} NR_UE_info_t;
 
 /*! \brief top level eNB MAC structure */
 typedef struct gNB_MAC_INST_s {
@@ -373,7 +417,7 @@ typedef struct gNB_MAC_INST_s {
   /// NFAPI DL PDU structure
   nfapi_nr_tx_data_request_t        TX_req[NFAPI_CC_MAX];
 
-  NR_UE_list_t UE_list;
+  NR_UE_info_t UE_info;
 
   /// UL handle
   uint32_t ul_handle;
diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c
index c8b385bbfcdcf5ea755287d69ea68e1b33b3013e..44c85f5f6a64e16519d77ae593e01a3e97bec745 100644
--- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c
+++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c
@@ -431,9 +431,9 @@ static void deliver_sdu_drb(void *_ue, nr_pdcp_entity_t *entity,
       GTPV1U_ENB_TUNNEL_DATA_REQ(message_p).offset       = GTPU_HEADER_OVERHEAD_MAX;
       GTPV1U_ENB_TUNNEL_DATA_REQ(message_p).rnti         = ue->rnti;
       GTPV1U_ENB_TUNNEL_DATA_REQ(message_p).rab_id       = rb_id + 4;
-    printf("!!!!!!! deliver_sdu_drb (drb %d) sending message to gtp size %d: ", rb_id, size);
-    //for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)buf[i]);
-    printf("\n");
+      LOG_D(PDCP, "%s() (drb %d) sending message to gtp size %d\n", __func__, rb_id, size);
+      //for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)buf[i]);
+      //printf("\n");
       itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p);
 
   }
@@ -474,9 +474,9 @@ rb_found:
   memblock = get_free_mem_block(size, __FUNCTION__);
   memcpy(memblock->data, buf, size);
 
-printf("!!!!!!! deliver_pdu_drb (srb %d) calling rlc_data_req size %d: ", rb_id, size);
-//for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]);
-printf("\n");
+  LOG_D(PDCP, "%s(): (srb %d) calling rlc_data_req size %d\n", __func__, rb_id, size);
+  //for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]);
+  //printf("\n");
   enqueue_rlc_data_req(&ctxt, 0, MBMS_FLAG_NO, rb_id, sdu_id, 0, size, memblock, NULL, NULL);
 }
 
@@ -872,7 +872,7 @@ static boolean_t pdcp_data_req_drb(
   const sdu_size_t sdu_buffer_size,
   unsigned char *const sdu_buffer)
 {
-printf("pdcp_data_req called size %d\n", sdu_buffer_size);
+  LOG_D(PDCP, "%s() called, size %d\n", __func__, sdu_buffer_size);
   nr_pdcp_ue_t *ue;
   nr_pdcp_entity_t *rb;
   int rnti = ctxt_pP->rnti;
diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c
index 919cf1a46a01a758cb2f8bc147402904e1437cf1..5048dd245ef01daf12d5256257576139c7682d44 100644
--- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c
+++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c
@@ -158,14 +158,6 @@ mac_rlc_status_resp_t mac_rlc_status_ind(
   mac_rlc_status_resp_t ret;
   nr_rlc_entity_t *rb;
 
-  /* TODO: handle time a bit more properly */
-  if (nr_rlc_current_time_last_frame != frameP ||
-      nr_rlc_current_time_last_subframe != subframeP) {
-    nr_rlc_current_time++;
-    nr_rlc_current_time_last_frame = frameP;
-    nr_rlc_current_time_last_subframe = subframeP;
-  }
-
   nr_rlc_manager_lock(nr_rlc_ue_manager);
   ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP);
 
@@ -921,3 +913,10 @@ rlc_op_status_t rrc_rlc_remove_ue (const protocol_ctxt_t* const x)
 
   return RLC_OP_STATUS_OK;
 }
+
+void nr_rlc_tick(int frame, int subframe)
+{
+  if (frame != nr_rlc_current_time_last_frame ||
+      subframe != nr_rlc_current_time_last_subframe)
+    nr_rlc_current_time++;
+}
diff --git a/openair2/LAYER2/nr_rlc/tests/LOG/log.h b/openair2/LAYER2/nr_rlc/tests/LOG/log.h
index 5c9fcd643cfca036cc81eca221f4a5e818aee685..8ebc7e1909634fc37334f499671353d1169e9131 100644
--- a/openair2/LAYER2/nr_rlc/tests/LOG/log.h
+++ b/openair2/LAYER2/nr_rlc/tests/LOG/log.h
@@ -1,5 +1,5 @@
-#ifndef _LOG_H_
-#define _LOG_H_
+#ifndef _NR_RLC_TESTS_LOG_H_
+#define _NR_RLC_TESTS_LOG_H_
 
 #include <stdio.h>
 
@@ -7,4 +7,4 @@
 #define LOG_D(x, ...) printf(__VA_ARGS__)
 #define LOG_W(x, ...) printf(__VA_ARGS__)
 
-#endif /* _LOG_H_ */
+#endif /* _NR_RLC_TESTS_LOG_H_ */
diff --git a/openair2/LAYER2/rlc_v2/tests/LOG/log.h b/openair2/LAYER2/rlc_v2/tests/LOG/log.h
index 5c9fcd643cfca036cc81eca221f4a5e818aee685..89d85090b178f66a396853f86f6052a3e9b1099c 100644
--- a/openair2/LAYER2/rlc_v2/tests/LOG/log.h
+++ b/openair2/LAYER2/rlc_v2/tests/LOG/log.h
@@ -1,5 +1,5 @@
-#ifndef _LOG_H_
-#define _LOG_H_
+#ifndef _RLC_V2_TESTS_LOG_H_
+#define _RLC_V2_TESTS_LOG_H_
 
 #include <stdio.h>
 
@@ -7,4 +7,4 @@
 #define LOG_D(x, ...) printf(__VA_ARGS__)
 #define LOG_W(x, ...) printf(__VA_ARGS__)
 
-#endif /* _LOG_H_ */
+#endif /* _RLC_V2_TESTS_LOG_H_ */
diff --git a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c
index c5b90cf028047d4d48cf6280ca9e4fcab0ca130c..22c48d11eb2fd0c515f0ece9762109ed13f91d69 100644
--- a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c
+++ b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c
@@ -181,10 +181,10 @@ void NR_UL_indication(NR_UL_IND_t *UL_info) {
   clear_nr_nfapi_information(mac,CC_id,UL_info->frame,UL_info->slot);
   handle_nr_rach(UL_info);
   
-  handle_nr_uci(UL_info,&mac->UE_list.UE_sched_ctrl[0],&mac->UE_list.mac_stats[0],mac->pucch_target_snrx10);
+  handle_nr_uci(UL_info,&mac->UE_info.UE_sched_ctrl[0],&mac->UE_info.mac_stats[0],mac->pucch_target_snrx10);
   // clear HI prior to handling ULSCH
   mac->UL_dci_req[CC_id].numPdus = 0;
-  handle_nr_ulsch(UL_info, &mac->UE_list.UE_sched_ctrl[0],&mac->UE_list.mac_stats[0]);
+  handle_nr_ulsch(UL_info, &mac->UE_info.UE_sched_ctrl[0],&mac->UE_info.mac_stats[0]);
 
   if (nfapi_mode != 1) {
     if (ifi->CC_mask == ((1<<MAX_NUM_CCs)-1)) {
diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c
index 31a26d322d4d280ed8ad762f2128405c2e7a586b..a6775bbf8a4b0f0d197da8620460a251d4993d83 100644
--- a/openair2/RRC/LTE/rrc_eNB.c
+++ b/openair2/RRC/LTE/rrc_eNB.c
@@ -155,7 +155,6 @@ init_SI(
   LOG_D(RRC,"%s()\n\n\n\n",__FUNCTION__);
 
   if(configuration->radioresourceconfig[CC_id].mbms_dedicated_serving_cell == TRUE) {
-
     LOG_I(RRC, "Configuring MIB FeMBMS (N_RB_DL %d)\n",
           (int)configuration->N_RB_DL[CC_id]);
     RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MIB_FeMBMS = (uint8_t *) malloc16(4);
@@ -500,13 +499,17 @@ init_SI(
                            RC.rrc[ctxt_pP->module_id]->carrier[CC_id].FeMBMS_flag,
                            (carrier->sib1_MBMS==NULL?(LTE_BCCH_DL_SCH_Message_MBMS_t *) NULL:(LTE_BCCH_DL_SCH_Message_MBMS_t *)carrier->sib1_MBMS),//(LTE_BCCH_DL_SCH_Message_MBMS_t *) NULL,
                            (LTE_SchedulingInfo_MBMS_r14_t *) NULL,
-                        (carrier->sib1_MBMS==NULL?(struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL:(struct LTE_NonMBSFN_SubframeConfig_r14 *)carrier->sib1_MBMS->nonMBSFN_SubframeConfig_r14),//(struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
-                        (carrier->sib1_MBMS==NULL?(LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL:(LTE_SystemInformationBlockType1_MBMS_r14_t *)carrier->sib1_MBMS->systemInformationBlockType13_r14),//(LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
-                        (carrier->sib1_MBMS==NULL?(LTE_MBSFN_AreaInfoList_r9_t *) NULL:(LTE_MBSFN_AreaInfoList_r9_t *)&carrier->sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9)//(LTE_MBSFN_AreaInfoList_r9_t *) NULL
-
-			,(LTE_MBSFNAreaConfiguration_r9_t*) NULL
-
-                         );
+                           (carrier->sib1_MBMS==NULL
+                            ? (struct LTE_NonMBSFN_SubframeConfig_r14 *)NULL
+                            : (struct LTE_NonMBSFN_SubframeConfig_r14 *)carrier->sib1_MBMS->nonMBSFN_SubframeConfig_r14),//(struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
+                           (carrier->sib1_MBMS==NULL
+                            ? (LTE_SystemInformationBlockType1_MBMS_r14_t *)NULL
+                            : (LTE_SystemInformationBlockType1_MBMS_r14_t *)carrier->sib1_MBMS->systemInformationBlockType13_r14),//(LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
+                           (carrier->sib1_MBMS==NULL
+                            ? (LTE_MBSFN_AreaInfoList_r9_t *)NULL
+                            : (LTE_MBSFN_AreaInfoList_r9_t *)&carrier->sib1_MBMS->systemInformationBlockType13_r14->mbsfn_AreaInfoList_r9),//(LTE_MBSFN_AreaInfoList_r9_t *) NULL,
+                           (LTE_MBSFNAreaConfiguration_r9_t *)NULL
+                          );
   }
 
   /* set flag to indicate that cell information is configured. This is required
@@ -590,7 +593,7 @@ init_MCCH(
                            (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
                            (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
                            (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
-			   (LTE_MBSFNAreaConfiguration_r9_t*) NULL
+                           (LTE_MBSFNAreaConfiguration_r9_t *) NULL
                           );
   }
 
@@ -1040,59 +1043,59 @@ void release_UE_in_freeList(module_id_t mod_id) {
 
       for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
         eNB_PHY = RC.eNB[mod_id][CC_id];
+        int id;
+        // clean ULSCH entries for rnti
+        id = find_ulsch(rnti,eNB_PHY,SEARCH_EXIST);
 
-	int id;
-
-	// clean ULSCH entries for rnti
-	id = find_ulsch(rnti,eNB_PHY,SEARCH_EXIST);
         if (id>=0) clean_eNb_ulsch(eNB_PHY->ulsch[id]);
 
-	// clean DLSCH entries for rnti
-	id = find_dlsch(rnti,eNB_PHY,SEARCH_EXIST);
+        // clean DLSCH entries for rnti
+        id = find_dlsch(rnti,eNB_PHY,SEARCH_EXIST);
+
         if (id>=0) clean_eNb_dlsch(eNB_PHY->dlsch[id][0]);
 
-	// clean UCI entries for rnti
+        // clean UCI entries for rnti
         for (i=0; i<NUMBER_OF_UCI_VARS_MAX; i++) {
           if(eNB_PHY->uci_vars[i].rnti == rnti) {
             LOG_I(MAC, "clean eNb uci_vars[%d] UE %x \n",i, rnti);
             memset(&eNB_PHY->uci_vars[i],0,sizeof(LTE_eNB_UCI));
           }
         }
-		
-	/*
-        for (i=0; i<MAX_MOBILES_PER_ENB; i++) {
-          ulsch = eNB_PHY->ulsch[i];
-
-          if((ulsch != NULL) && (ulsch->rnti == rnti)) {
-            void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
-            LOG_I(RRC, "clean_eNb_ulsch ulsch[%d] UE %x\n", i, rnti);
-            clean_eNb_ulsch(ulsch);
-          }
 
-          dlsch = eNB_PHY->dlsch[i][0];
+        /*
+              for (i=0; i<MAX_MOBILES_PER_ENB; i++) {
+                ulsch = eNB_PHY->ulsch[i];
 
-          if((dlsch != NULL) && (dlsch->rnti == rnti)) {
-            void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch);
-            LOG_I(RRC, "clean_eNb_dlsch dlsch[%d] UE %x \n", i, rnti);
-            clean_eNb_dlsch(dlsch);
-          }
-        }
+                if((ulsch != NULL) && (ulsch->rnti == rnti)) {
+                  void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
+                  LOG_I(RRC, "clean_eNb_ulsch ulsch[%d] UE %x\n", i, rnti);
+                  clean_eNb_ulsch(ulsch);
+                }
 
-        ulsch = eNB_PHY->ulsch[i];
+                dlsch = eNB_PHY->dlsch[i][0];
 
-        if((ulsch != NULL) && (ulsch->rnti == rnti)) {
-          void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
-          LOG_I(RRC, "clean_eNb_ulsch ulsch[%d] UE %x\n", i, rnti);
-          clean_eNb_ulsch(ulsch);
-        }
+                if((dlsch != NULL) && (dlsch->rnti == rnti)) {
+                  void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch);
+                  LOG_I(RRC, "clean_eNb_dlsch dlsch[%d] UE %x \n", i, rnti);
+                  clean_eNb_dlsch(dlsch);
+                }
+              }
 
-        for (i=0; i<NUMBER_OF_UCI_VARS_MAX; i++) {
-          if(eNB_PHY->uci_vars[i].rnti == rnti) {
-            LOG_I(MAC, "clean eNb uci_vars[%d] UE %x \n",i, rnti);
-            memset(&eNB_PHY->uci_vars[i],0,sizeof(LTE_eNB_UCI));
-          }
-        }
-	*/
+              ulsch = eNB_PHY->ulsch[i];
+
+              if((ulsch != NULL) && (ulsch->rnti == rnti)) {
+                void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch);
+                LOG_I(RRC, "clean_eNb_ulsch ulsch[%d] UE %x\n", i, rnti);
+                clean_eNb_ulsch(ulsch);
+              }
+
+              for (i=0; i<NUMBER_OF_UCI_VARS_MAX; i++) {
+                if(eNB_PHY->uci_vars[i].rnti == rnti) {
+                  LOG_I(MAC, "clean eNb uci_vars[%d] UE %x \n",i, rnti);
+                  memset(&eNB_PHY->uci_vars[i],0,sizeof(LTE_eNB_UCI));
+                }
+              }
+        */
 
         if (flexran_agent_get_rrc_xface(mod_id)) {
           flexran_agent_get_rrc_xface(mod_id)->flexran_agent_notify_ue_state_change(
@@ -1488,7 +1491,7 @@ rrc_eNB_generate_RRCConnectionReestablishment(
                                  (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
                                  (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
                                  (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
-			         (LTE_MBSFNAreaConfiguration_r9_t*) NULL
+                                 (LTE_MBSFNAreaConfiguration_r9_t *) NULL
                                 );
           break;
         }
@@ -2190,7 +2193,6 @@ rrc_eNB_generate_RRCConnectionRelease(
   uint8_t buffer[RRC_BUF_SIZE];
   uint16_t size = 0;
   int release_num;
-
   memset(buffer, 0, RRC_BUF_SIZE);
   T(T_ENB_RRC_CONNECTION_RELEASE, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
@@ -3281,7 +3283,8 @@ void rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t
 
     MeasObj2->measObjectId = 2;
     MeasObj2->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectNR_r15;
-    MeasObj2->measObject.choice.measObjectNR_r15.carrierFreq_r15 =641272; //634000; //(634000 = 3.51GHz) (640000 = 3.6GHz) (641272 = 3619.08MHz = 3600 + 30/1000*106*12/2) (642256 is for 3.6GHz and absoluteFrequencySSB = 642016)
+    MeasObj2->measObject.choice.measObjectNR_r15.carrierFreq_r15 = 641272;
+    //634000; //(634000 = 3.51GHz) (640000 = 3.6GHz) (641272 = 3619.08MHz = 3600 + 30/1000*106*12/2) (642256 is for 3.6GHz and absoluteFrequencySSB = 642016)
     MeasObj2->measObject.choice.measObjectNR_r15.rs_ConfigSSB_r15.measTimingConfig_r15.periodicityAndOffset_r15.present = LTE_MTC_SSB_NR_r15__periodicityAndOffset_r15_PR_sf20_r15;
     MeasObj2->measObject.choice.measObjectNR_r15.rs_ConfigSSB_r15.measTimingConfig_r15.periodicityAndOffset_r15.choice.sf20_r15 = 0;
     MeasObj2->measObject.choice.measObjectNR_r15.rs_ConfigSSB_r15.measTimingConfig_r15.ssb_Duration_r15 = LTE_MTC_SSB_NR_r15__ssb_Duration_r15_sf4;
@@ -3593,20 +3596,19 @@ void rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t
                size,
                buffer,
                PDCP_TRANSMISSION_MODE_CONTROL);
-
   /* Refresh SRBs/DRBs */
   rrc_pdcp_config_asn1_req(ctxt_pP,
-                          *SRB_configList2, // NULL,
-                          *DRB_configList,
-                          NULL,
-                          0xff, // already configured during the securitymodecommand
-                          NULL,
-                          NULL,
-                          NULL
+                           *SRB_configList2, // NULL,
+                           *DRB_configList,
+                           NULL,
+                           0xff, // already configured during the securitymodecommand
+                           NULL,
+                           NULL,
+                           NULL
 #if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                          , (LTE_PMCH_InfoList_r9_t *) NULL
+                           , (LTE_PMCH_InfoList_r9_t *) NULL
 #endif
-                          , NULL);
+                           , NULL);
 
   /* Refresh SRBs/DRBs */
   if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
@@ -3619,7 +3621,7 @@ void rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t
                             0,
                             0
 #endif
-                            );
+                           );
   }
 
   free(Sparams);
@@ -4666,7 +4668,7 @@ rrc_eNB_process_MeasurementReport(
         for (int e_rab=0; e_rab < X2AP_ENDC_SGNB_ADDITION_REQ(msg).nb_e_rabs_tobeadded; e_rab++) {
           X2AP_ENDC_SGNB_ADDITION_REQ(msg).e_rabs_tobeadded[e_rab].e_rab_id = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
           X2AP_ENDC_SGNB_ADDITION_REQ(msg).e_rabs_tobeadded[e_rab].gtp_teid = ue_context_pP->ue_context.e_rab[e_rab].param.gtp_teid;
-          X2AP_ENDC_SGNB_ADDITION_REQ(msg).e_rabs_tobeadded[e_rab].drb_ID = ue_context_pP->ue_context.DRB_configList->list.array[e_rab]->drb_Identity; 
+          X2AP_ENDC_SGNB_ADDITION_REQ(msg).e_rabs_tobeadded[e_rab].drb_ID = ue_context_pP->ue_context.DRB_configList->list.array[e_rab]->drb_Identity;
           memcpy(&X2AP_ENDC_SGNB_ADDITION_REQ(msg).e_rabs_tobeadded[e_rab].sgw_addr,
                  &ue_context_pP->ue_context.e_rab[e_rab].param.sgw_addr,
                  sizeof(transport_layer_addr_t));
@@ -5789,7 +5791,7 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct
     (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
     (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
     (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
-    (LTE_MBSFNAreaConfiguration_r9_t*) NULL
+    (LTE_MBSFNAreaConfiguration_r9_t *) NULL
   );
   // Configure target eNB SRB2
   /// SRB2
@@ -6341,20 +6343,19 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct
     ue_context_pP->ue_context.rnti,
     rrc_eNB_mui,
     size);
-
   /* Refresh SRBs/DRBs */
   rrc_pdcp_config_asn1_req(ctxt_pP,
-                          *SRB_configList2, // NULL,
-                          *DRB_configList,
-                          NULL,
-                          0xff, // already configured during the securitymodecommand
-                          NULL,
-                          NULL,
-                          NULL
+                           *SRB_configList2, // NULL,
+                           *DRB_configList,
+                           NULL,
+                           0xff, // already configured during the securitymodecommand
+                           NULL,
+                           NULL,
+                           NULL
 #if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0))
-                          , (LTE_PMCH_InfoList_r9_t *) NULL
+                           , (LTE_PMCH_InfoList_r9_t *) NULL
 #endif
-                          , NULL);
+                           , NULL);
 
   /* Refresh SRBs/DRBs */
   if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
@@ -6367,7 +6368,7 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct
                             0,
                             0
 #endif
-                            );
+                           );
   }
 
   free(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ);
@@ -6413,6 +6414,7 @@ rrc_eNB_configure_rbs_handover(struct rrc_eNB_ue_context_s *ue_context_p, protoc
                            NULL,
                            NULL,
                            (LTE_PMCH_InfoList_r9_t *) NULL, NULL);
+
   if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
     rrc_rlc_config_asn1_req(ctxt_pP,
                             ue_context_p->ue_context.SRB_configList,
@@ -6470,7 +6472,7 @@ rrc_eNB_configure_rbs_handover(struct rrc_eNB_ue_context_s *ue_context_p, protoc
     (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
     (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
     (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
-    (LTE_MBSFNAreaConfiguration_r9_t*) NULL
+    (LTE_MBSFNAreaConfiguration_r9_t *) NULL
   );
 }
 
@@ -6553,6 +6555,7 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
                            kUPenc,
                            (LTE_PMCH_InfoList_r9_t *) NULL,
                            NULL);
+
   /* Refresh SRBs/DRBs */
   if (!NODE_IS_CU(RC.rrc[ctxt_pP->module_id]->node_type)) {
     rrc_rlc_config_asn1_req(ctxt_pP,
@@ -6562,7 +6565,7 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
                             (LTE_PMCH_InfoList_r9_t *) NULL,
                             0,
                             0
-                            );
+                           );
   }
 
   /* Set the SRB active in UE context */
@@ -6687,7 +6690,7 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
                                    (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
                                    (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
                                    (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
-   				   (LTE_MBSFNAreaConfiguration_r9_t*) NULL
+                                   (LTE_MBSFNAreaConfiguration_r9_t *) NULL
                                   );
           }
         } else {        // remove LCHAN from MAC/PHY
@@ -6747,7 +6750,7 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
                                    (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
                                    (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
                                    (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
-   				   (LTE_MBSFNAreaConfiguration_r9_t*) NULL
+                                   (LTE_MBSFNAreaConfiguration_r9_t *) NULL
                                   );
           }
         } // end else of if (ue_context_pP->ue_context.DRB_active[drb_id] == 0)
@@ -6910,7 +6913,7 @@ rrc_eNB_generate_RRCConnectionSetup(
                                      (struct LTE_NonMBSFN_SubframeConfig_r14 *) NULL,
                                      (LTE_SystemInformationBlockType1_MBMS_r14_t *) NULL,
                                      (LTE_MBSFN_AreaInfoList_r9_t *) NULL,
-   				     (LTE_MBSFNAreaConfiguration_r9_t*) NULL
+                                     (LTE_MBSFNAreaConfiguration_r9_t *) NULL
                                     );
               break;
             }
@@ -7044,6 +7047,16 @@ char openair_rrc_eNB_configuration(
   return 0;
 }
 
+static
+void rrc_eNB_generate_RRCConnectionReestablishmentReject_unknown_UE(protocol_ctxt_t *const ctxt_pP,
+    const int CC_id) {
+  struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_next_free_ue_context(ctxt_pP, ctxt_pP->rnti);
+  rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP,
+      ue_context_p,
+      CC_id);
+  ue_context_p->ue_context.ul_failure_timer = 500;  // 500 milliseconds to send the message and remove temporary entry
+}
+
 /*------------------------------------------------------------------------------*/
 int
 rrc_eNB_decode_ccch(
@@ -7122,12 +7135,14 @@ rrc_eNB_decode_ccch(
           uint16_t                          c_rnti = 0;
 
           if (rrcConnectionReestablishmentRequest->ue_Identity.physCellId != RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId) {
+            /* UE was moving from previous cell so quickly that RRCConnectionReestablishment for previous cell was recieved in this cell */
             LOG_E(RRC,
                   PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest ue_Identity.physCellId(%ld) is not equal to current physCellId(%d), let's reject the UE\n",
                   PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
                   rrcConnectionReestablishmentRequest->ue_Identity.physCellId,
                   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId);
-            rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
+            rrc_eNB_generate_RRCConnectionReestablishmentReject_unknown_UE(ctxt_pP,
+                CC_id);
             break;
           }
 
@@ -7140,10 +7155,12 @@ rrc_eNB_decode_ccch(
 
           if (rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI.size == 0 ||
               rrcConnectionReestablishmentRequest->ue_Identity.c_RNTI.size > 2) {
+            /* c_RNTI range error should not happen */
             LOG_E(RRC,
                   PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest c_RNTI range error, let's reject the UE\n",
                   PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-            rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
+            rrc_eNB_generate_RRCConnectionReestablishmentReject_unknown_UE(ctxt_pP,
+                CC_id);
             break;
           }
 
@@ -7155,7 +7172,8 @@ rrc_eNB_decode_ccch(
             LOG_E(RRC,
                   PROTOCOL_RRC_CTXT_UE_FMT" LTE_RRCConnectionReestablishmentRequest without UE context, let's reject the UE\n",
                   PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
-            rrc_eNB_generate_RRCConnectionReestablishmentReject(ctxt_pP, ue_context_p, CC_id);
+            rrc_eNB_generate_RRCConnectionReestablishmentReject_unknown_UE(ctxt_pP,
+                CC_id);
             break;
           }
 
@@ -7222,8 +7240,10 @@ rrc_eNB_decode_ccch(
 
           if(ue_context_p->ue_context.ue_reestablishment_timer > 0) {
             LOG_E(RRC,
-                  PROTOCOL_RRC_CTXT_UE_FMT" RRRCConnectionReconfigurationComplete(Previous) don't receive, delete the Previous UE\n",
-                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
+                  PROTOCOL_RRC_CTXT_UE_FMT" RRRCConnectionReconfigurationComplete(Previous) don't receive, delete the Previous UE,\nprevious Status %d, new Status RRC_RECONFIGURED\n",
+                  PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                  ue_context_p->ue_context.Status
+                 );
             ue_context_p->ue_context.Status = RRC_RECONFIGURED;
             protocol_ctxt_t  ctxt_old_p;
             PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt_old_p,
@@ -7808,8 +7828,7 @@ rrc_eNB_decode_dcch(
               LOG_I(RRC,
                     PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_HO_EXECUTION (xid %ld)\n",
                     PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier);
-            }
-            else if(ue_context_p->ue_context.Status == RRC_NR_NSA){
+            } else if(ue_context_p->ue_context.Status == RRC_NR_NSA) {
               //Looking for a condition to trigger S1AP E-RAB-Modification-indication, based on the reception of RRCConnectionReconfigurationComplete
               //including NR specific elements.
               if(ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.criticalExtensions.choice.rrcConnectionReconfigurationComplete_r8.
@@ -7837,8 +7856,7 @@ rrc_eNB_decode_dcch(
                   }
                 }
               }
-            }
-            else {
+            } else {
               dedicated_DRB = 0;
               ue_context_p->ue_context.Status = RRC_RECONFIGURED;
               LOG_I(RRC,
@@ -7847,7 +7865,6 @@ rrc_eNB_decode_dcch(
             }
 
             ue_context_p->ue_context.reestablishment_xid = -1;
-
           } else {
             dedicated_DRB = 1;
             ue_context_p->ue_context.Status = RRC_RECONFIGURED;
@@ -8383,8 +8400,7 @@ rrc_eNB_decode_dcch(
       case LTE_UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10:
         T(T_ENB_RRC_MBMS_COUNTING_RESPONSE_R10, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
           T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
-    	LOG_E(RRC, "THINH [LTE_UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10]\n");
-
+        LOG_E(RRC, "THINH [LTE_UL_DCCH_MessageType__c1_PR_mbmsCountingResponse_r10]\n");
         break;
 
       case LTE_UL_DCCH_MessageType__c1_PR_interFreqRSTDMeasurementIndication_r10:
@@ -8412,46 +8428,46 @@ rrc_eNB_decode_dcch(
 
       case LTE_UL_DCCH_MessageType__messageClassExtension_PR_c2: //SidelinkUEInformation
         if(ul_dcch_msg->message.choice.messageClassExtension.choice.c2.present ==
-          LTE_UL_DCCH_MessageType__messageClassExtension__c2_PR_scgFailureInformationNR_r15){
+            LTE_UL_DCCH_MessageType__messageClassExtension__c2_PR_scgFailureInformationNR_r15) {
           if (ul_dcch_msg->message.choice.messageClassExtension.choice.c2.choice.scgFailureInformationNR_r15.
-            criticalExtensions.present == LTE_SCGFailureInformationNR_r15__criticalExtensions_PR_c1){
+              criticalExtensions.present == LTE_SCGFailureInformationNR_r15__criticalExtensions_PR_c1) {
             if (ul_dcch_msg->message.choice.messageClassExtension.choice.c2.choice.scgFailureInformationNR_r15.criticalExtensions.
-              choice.c1.present == LTE_SCGFailureInformationNR_r15__criticalExtensions__c1_PR_scgFailureInformationNR_r15){
+                choice.c1.present == LTE_SCGFailureInformationNR_r15__criticalExtensions__c1_PR_scgFailureInformationNR_r15) {
               if (ul_dcch_msg->message.choice.messageClassExtension.choice.c2.choice.scgFailureInformationNR_r15.criticalExtensions.
-                choice.c1.choice.scgFailureInformationNR_r15.failureReportSCG_NR_r15!=NULL) {
+                  choice.c1.choice.scgFailureInformationNR_r15.failureReportSCG_NR_r15!=NULL) {
                 LOG_E(RRC, "Received NR scgFailureInformation from UE, failure type: %ld \n",
-                  ul_dcch_msg->message.choice.messageClassExtension.choice.c2.choice.scgFailureInformationNR_r15.criticalExtensions.
-                  choice.c1.choice.scgFailureInformationNR_r15.failureReportSCG_NR_r15->failureType_r15);
+                      ul_dcch_msg->message.choice.messageClassExtension.choice.c2.choice.scgFailureInformationNR_r15.criticalExtensions.
+                      choice.c1.choice.scgFailureInformationNR_r15.failureReportSCG_NR_r15->failureType_r15);
                 xer_fprint(stdout, &asn_DEF_LTE_UL_DCCH_Message, (void *)ul_dcch_msg);
               }
             }
           }
-        }
-        else if(ul_dcch_msg->message.choice.messageClassExtension.choice.c2.present == LTE_UL_DCCH_MessageType__messageClassExtension__c2_PR_sidelinkUEInformation_r12){
+        } else if(ul_dcch_msg->message.choice.messageClassExtension.choice.c2.present == LTE_UL_DCCH_MessageType__messageClassExtension__c2_PR_sidelinkUEInformation_r12) {
           //case UL_DCCH_MessageType__messageClassExtension__c2_PR_sidelinkUEInformation_r12: //SidelinkUEInformation
           LOG_I(RRC,"THINH [LTE_UL_DCCH_MessageType__messageClassExtension_PR_c2]\n");
           LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)Rx_sdu,sdu_sizeP,
-                    "[MSG] RRC SidelinkUEInformation \n");
+                      "[MSG] RRC SidelinkUEInformation \n");
           MSC_LOG_RX_MESSAGE(
-              MSC_RRC_ENB,
-              MSC_RRC_UE,
-              Rx_sdu,
-              sdu_sizeP,
-              MSC_AS_TIME_FMT" SidelinkUEInformation UE %x size %u",
-              MSC_AS_TIME_ARGS(ctxt_pP),
-              ue_context_p->ue_context.rnti,
-              sdu_sizeP);
-          LOG_I(RRC,
-            PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
-            "(SidelinkUEInformation) ---> RRC_eNB\n",
-            PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-            DCCH,
+            MSC_RRC_ENB,
+            MSC_RRC_UE,
+            Rx_sdu,
+            sdu_sizeP,
+            MSC_AS_TIME_FMT" SidelinkUEInformation UE %x size %u",
+            MSC_AS_TIME_ARGS(ctxt_pP),
+            ue_context_p->ue_context.rnti,
             sdu_sizeP);
+          LOG_I(RRC,
+                PROTOCOL_RRC_CTXT_UE_FMT" RLC RB %02d --- RLC_DATA_IND %d bytes "
+                "(SidelinkUEInformation) ---> RRC_eNB\n",
+                PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
+                DCCH,
+                sdu_sizeP);
           rrc_eNB_process_SidelinkUEInformation(
             ctxt_pP,
             ue_context_p,
             &ul_dcch_msg->message.choice.messageClassExtension.choice.c2.choice.sidelinkUEInformation_r12);
-          }
+        }
+
         break;
 
       default:
@@ -8618,17 +8634,14 @@ void rrc_enb_init(void) {
 
 //-----------------------------------------------------------------------------
 void process_successful_rlc_sdu_indication(int instance,
-                                           int rnti,
-                                           int message_id)
-{
+    int rnti,
+    int message_id) {
   int release_num;
   int release_total;
   RRC_release_ctrl_t *release_ctrl;
-
   /* Check if the message sent was RRC Connection Release.
    * If yes then continue the release process.
    */
-
   pthread_mutex_lock(&rrc_release_freelist);
 
   if (rrc_release_info.num_UEs > 0) {
@@ -8670,14 +8683,11 @@ void process_successful_rlc_sdu_indication(int instance,
 }
 
 //-----------------------------------------------------------------------------
-void process_unsuccessful_rlc_sdu_indication(int instance, int rnti)
-{
+void process_unsuccessful_rlc_sdu_indication(int instance, int rnti) {
   int release_num;
   int release_total;
   RRC_release_ctrl_t *release_ctrl;
-
   /* radio link failure detected by RLC layer, remove UE properly */
-
   pthread_mutex_lock(&rrc_release_freelist);
 
   /* first, check if the rnti is in the list rrc_release_info.RRC_release_ctrl */
@@ -8745,8 +8755,7 @@ void process_rlc_sdu_indication(int instance,
                                 int rnti,
                                 int is_successful,
                                 int srb_id,
-                                int message_id)
-{
+                                int message_id) {
   if (is_successful)
     process_successful_rlc_sdu_indication(instance, rnti, message_id);
   else
@@ -9089,51 +9098,49 @@ void rrc_eNB_process_AdditionResponseInformation(const module_id_t enb_mod_idP,
     return;
   }
 
-    protocol_ctxt_t ctxt;
-    rrc_eNB_ue_context_t *ue_context;
-    unsigned char buffer[8192];
-    int size;
-
-    ue_context = rrc_eNB_get_ue_context(RC.rrc[enb_mod_idP], m->rnti);
-    if (ue_context) {
-      ue_context->ue_context.nb_of_modify_endc_e_rabs = m->nb_e_rabs_admitted_tobeadded;
-
-      int j=0;
-      while(j < m->nb_e_rabs_admitted_tobeadded){
-	for (int e_rab_idx=0; e_rab_idx<ue_context->ue_context.setup_e_rabs; e_rab_idx++){
-	  //Update ue_context information with gNB's address and new GTP tunnel ID
-	  if( ue_context->ue_context.e_rab[e_rab_idx].param.e_rab_id == m->e_rabs_admitted_tobeadded[j].e_rab_id){
-	    memcpy(ue_context->ue_context.gnb_gtp_endc_addrs[e_rab_idx].buffer,
-		   m->e_rabs_admitted_tobeadded[j].gnb_addr.buffer,
-		   m->e_rabs_admitted_tobeadded[j].gnb_addr.length);
-	    ue_context->ue_context.gnb_gtp_endc_addrs[e_rab_idx].length = m->e_rabs_admitted_tobeadded[j].gnb_addr.length;
-	    ue_context->ue_context.gnb_gtp_endc_teid[e_rab_idx] = m->e_rabs_admitted_tobeadded[j].gtp_teid;
-	    ue_context->ue_context.e_rab[e_rab_idx].status = E_RAB_STATUS_TOMODIFY;
-	    break;
-	  }
-	}
-	j++;
+  protocol_ctxt_t ctxt;
+  rrc_eNB_ue_context_t *ue_context;
+  unsigned char buffer[8192];
+  int size;
+  ue_context = rrc_eNB_get_ue_context(RC.rrc[enb_mod_idP], m->rnti);
+
+  if (ue_context) {
+    ue_context->ue_context.nb_of_modify_endc_e_rabs = m->nb_e_rabs_admitted_tobeadded;
+    int j=0;
+
+    while(j < m->nb_e_rabs_admitted_tobeadded) {
+      for (int e_rab_idx=0; e_rab_idx<ue_context->ue_context.setup_e_rabs; e_rab_idx++) {
+        //Update ue_context information with gNB's address and new GTP tunnel ID
+        if( ue_context->ue_context.e_rab[e_rab_idx].param.e_rab_id == m->e_rabs_admitted_tobeadded[j].e_rab_id) {
+          memcpy(ue_context->ue_context.gnb_gtp_endc_addrs[e_rab_idx].buffer,
+                 m->e_rabs_admitted_tobeadded[j].gnb_addr.buffer,
+                 m->e_rabs_admitted_tobeadded[j].gnb_addr.length);
+          ue_context->ue_context.gnb_gtp_endc_addrs[e_rab_idx].length = m->e_rabs_admitted_tobeadded[j].gnb_addr.length;
+          ue_context->ue_context.gnb_gtp_endc_teid[e_rab_idx] = m->e_rabs_admitted_tobeadded[j].gtp_teid;
+          ue_context->ue_context.e_rab[e_rab_idx].status = E_RAB_STATUS_TOMODIFY;
+          break;
+        }
       }
 
-      PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
-                                    0,
-                                    ENB_FLAG_YES,
-                                    m->rnti,
-                                    0, 0);
-
-      size = rrc_eNB_generate_RRCConnectionReconfiguration_endc(&ctxt, ue_context, buffer, 8192, scg_CellGroupConfig, nr1_conf);
-
-      rrc_data_req(&ctxt,
-                   DCCH,
-                   rrc_eNB_mui++,
-                   SDU_CONFIRM_NO,
-                   size,
-                   buffer,
-                   PDCP_TRANSMISSION_MODE_CONTROL);
-    } else {
-      LOG_E(F1AP, "no ue_context for RNTI %x, acknowledging release\n", m->rnti);
+      j++;
     }
 
+    PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
+                                  0,
+                                  ENB_FLAG_YES,
+                                  m->rnti,
+                                  0, 0);
+    size = rrc_eNB_generate_RRCConnectionReconfiguration_endc(&ctxt, ue_context, buffer, 8192, scg_CellGroupConfig, nr1_conf);
+    rrc_data_req(&ctxt,
+                 DCCH,
+                 rrc_eNB_mui++,
+                 SDU_CONFIRM_NO,
+                 size,
+                 buffer,
+                 PDCP_TRANSMISSION_MODE_CONTROL);
+  } else {
+    LOG_E(F1AP, "no ue_context for RNTI %x, acknowledging release\n", m->rnti);
+  }
 }
 
 //-----------------------------------------------------------------------------
@@ -9470,8 +9477,8 @@ void *rrc_enb_process_itti_msg(void *notUsed) {
       break;
 
     case M2AP_MCE_CONFIGURATION_UPDATE:
-       rrc_eNB_process_M2AP_MCE_CONFIGURATION_UPDATE(&ctxt,&M2AP_MCE_CONFIGURATION_UPDATE(msg_p));
-       break;
+      rrc_eNB_process_M2AP_MCE_CONFIGURATION_UPDATE(&ctxt,&M2AP_MCE_CONFIGURATION_UPDATE(msg_p));
+      break;
 
     case RLC_SDU_INDICATION:
       process_rlc_sdu_indication(instance,
@@ -9515,7 +9522,7 @@ rrc_enb_task(
       //if (go_nr) rrc_go_nr();
     }
   }
-  }
+}
 
 /*------------------------------------------------------------------------------*/
 void
diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c
index 44215df2185ea3e42dcc62d030d434fc3257a043..1e182eff8bd5922947d84f116d427df42ff46636 100755
--- a/openair2/RRC/NR_UE/rrc_UE.c
+++ b/openair2/RRC/NR_UE/rrc_UE.c
@@ -399,9 +399,9 @@ int8_t nr_rrc_ue_decode_NR_BCCH_BCH_Message(
     }
 
 
-    for(i=0; i<buffer_len; ++i){
-        printf("[RRC] MIB PDU : %d\n", bufferP[i]);
-    }
+    //for(i=0; i<buffer_len; ++i){
+    //    printf("[RRC] MIB PDU : %d\n", bufferP[i]);
+    //}
 
     asn_dec_rval_t dec_rval = uper_decode_complete( NULL,
                                                     &asn_DEF_NR_BCCH_BCH_Message,
diff --git a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h
index 8f2908e52aa182f11d8067d4c005addf4f01f778..18b60aa611721c54e5652f2602503e6c184f2964 100644
--- a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h
+++ b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h
@@ -16,13 +16,13 @@
 #include "NwEvt.h"
 #include "NwLog.h"
 
+#ifndef __NW_MINI_LOG_MGR_H__
+#define __NW_MINI_LOG_MGR_H__
+
 #ifndef NW_ASSERT
 #define NW_ASSERT assert
 #endif
 
-#ifndef __NW_MINI_LOG_MGR_H__
-#define __NW_MINI_LOG_MGR_H__
-
 extern uint32_t g_log_level;
 
 
diff --git a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.h b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.h
index b17228c9cf725e313bea2af3a279bbc1d8ed9528..a1f16ff89b9010ddd59fa38d563599c76427989a 100644
--- a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.h
+++ b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.h
@@ -17,13 +17,13 @@
 #include "NwEvt.h"
 #include "NwLog.h"
 
+#ifndef __NW_MINI_TMR_MGR_H__
+#define __NW_MINI_TMR_MGR_H__
+
 #ifndef NW_ASSERT
 #define NW_ASSERT assert
 #endif
 
-#ifndef __NW_MINI_TMR_MGR_H__
-#define __NW_MINI_TMR_MGR_H__
-
 typedef struct {
   NwEventT      ev;
   void*         timeoutArg;
diff --git a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniUdpEntity.h b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniUdpEntity.h
index 2e19ebbb8eec047ddc9ddea0d4722f2102e33256..568c5b07969d596460ead54753b4386201bcbd10 100644
--- a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniUdpEntity.h
+++ b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniUdpEntity.h
@@ -17,13 +17,13 @@
 #include "NwEvt.h"
 #include "NwLog.h"
 
+#ifndef __NW_MINI_UDP_ENTITY_H__
+#define __NW_MINI_UDP_ENTITY_H__
+
 #ifndef NW_ASSERT
 #define NW_ASSERT assert
 #endif
 
-#ifndef __NW_MINI_UDP_ENTITY_H__
-#define __NW_MINI_UDP_ENTITY_H__
-
 typedef struct {
   uint32_t        hSocket;
   NwEventT      ev;
diff --git a/targets/COMMON/threads_t.h b/targets/COMMON/threads_t.h
index 0671f409883256b4db50e1c9c68778a1840ae5ef..5fb1645444bce8fa6e998e9ee6bb777679ad65cc 100644
--- a/targets/COMMON/threads_t.h
+++ b/targets/COMMON/threads_t.h
@@ -1,5 +1,5 @@
-#ifndef _THREADS_T_H_
-#define _THREADS_T_H_
+#ifndef _TARGETS_COMMON_THREADS_T_H_
+#define _TARGETS_COMMON_THREADS_T_H_
 
 typedef struct threads_s {
   int main;
@@ -18,4 +18,4 @@ typedef struct threads_s {
   //int dlsch_td1_three;
 } threads_t;
 
-#endif /* _THREADS_T_H_ */
+#endif /* _TARGETS_COMMON_THREADS_T_H_ */
diff --git a/targets/RT/USER/stats.h b/targets/RT/USER/stats.h
index 264c8f7af028556a4aa5f3bbf293e45082e68db6..15ee4a808765c73b1c3cb2b77c6bf0671d5f842c 100644
--- a/targets/RT/USER/stats.h
+++ b/targets/RT/USER/stats.h
@@ -21,8 +21,8 @@
 
 /* Header file generated by fdesign on Thu Aug 28 12:13:51 2014 */
 
-#ifndef FD_stats_form_h_
-#define FD_stats_form_h_
+#ifndef _TARGETS_RT_USER_STATS_H_
+#define _TARGETS_RT_USER_STATS_H_
 
 #include <forms.h>
 
@@ -43,4 +43,4 @@ typedef struct {
 
 extern FD_stats_form * create_form_stats_form( void );
 
-#endif /* FD_stats_form_h_ */
+#endif /* _TARGETS_RT_USER_STATS_H_ */