From 83270fdde7f13f6b6f54b2e02ec63ce2ee13dcd1 Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@openairinterface.org>
Date: Tue, 3 May 2022 12:22:01 +0200
Subject: [PATCH] Transfer Initial UL RRC Message through internal F1

---
 common/utils/ocp_itti/intertask_interface.h   |   1 +
 openair2/COMMON/f1ap_messages_types.h         |   3 +-
 openair2/F1AP/f1ap_cu_rrc_message_transfer.c  |  80 ++++----
 openair2/F1AP/f1ap_du_rrc_message_transfer.c  |   4 +-
 openair2/F1AP/f1ap_du_rrc_message_transfer.h  |   2 +-
 .../NR_MAC_gNB/gNB_scheduler_primitives.c     |  60 +++++-
 .../LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c   |  16 +-
 openair2/LAYER2/NR_MAC_gNB/mac_proto.h        |   7 +-
 .../LAYER2/NR_MAC_gNB/mac_rrc_ul_direct.c     |  18 +-
 openair2/LAYER2/NR_MAC_gNB/mac_rrc_ul_f1ap.c  |  17 +-
 openair2/LAYER2/NR_MAC_gNB/main.c             |   1 +
 openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h       |   3 +
 openair2/RRC/NR/L2_nr_interface.c             |  68 -------
 openair2/RRC/NR/MESSAGES/asn1_msg.c           |  82 +++------
 openair2/RRC/NR/MESSAGES/asn1_msg.h           |  25 +--
 openair2/RRC/NR/nr_rrc_config.c               |  16 +-
 openair2/RRC/NR/nr_rrc_config.h               |  10 +-
 openair2/RRC/NR/nr_rrc_proto.h                |  21 +--
 openair2/RRC/NR/rrc_gNB.c                     | 172 ++++++++----------
 openair2/RRC/NR/rrc_gNB_reconfig.c            |   6 +-
 20 files changed, 293 insertions(+), 319 deletions(-)

diff --git a/common/utils/ocp_itti/intertask_interface.h b/common/utils/ocp_itti/intertask_interface.h
index 636d305c135..a3f447baa3f 100644
--- a/common/utils/ocp_itti/intertask_interface.h
+++ b/common/utils/ocp_itti/intertask_interface.h
@@ -304,6 +304,7 @@ void *rrc_enb_process_msg(void *);
   TASK_DEF(TASK_BM,       TASK_PRIORITY_MED, 200, NULL, NULL)   \
   TASK_DEF(TASK_PHY_ENB,  TASK_PRIORITY_MED, 200, NULL, NULL)   \
   TASK_DEF(TASK_MAC_ENB,  TASK_PRIORITY_MED, 200, NULL, NULL)   \
+  TASK_DEF(TASK_MAC_GNB,  TASK_PRIORITY_MED, 200, NULL, NULL)   \
   TASK_DEF(TASK_RLC_ENB,  TASK_PRIORITY_MED, 200, NULL, NULL)   \
   TASK_DEF(TASK_RRC_ENB_NB_IoT,  TASK_PRIORITY_MED, 200, NULL, NULL) \
   TASK_DEF(TASK_PDCP_ENB, TASK_PRIORITY_MED, 200, NULL, NULL)   \
diff --git a/openair2/COMMON/f1ap_messages_types.h b/openair2/COMMON/f1ap_messages_types.h
index c19bdff9a22..cbc4d1c6f2d 100644
--- a/openair2/COMMON/f1ap_messages_types.h
+++ b/openair2/COMMON/f1ap_messages_types.h
@@ -62,7 +62,6 @@
 
 #define F1AP_MAX_NO_OF_TNL_ASSOCIATIONS 32
 #define F1AP_MAX_NO_UE_ID 1024
-#define F1AP_MAX_DU2CU_RRC_LENGTH 1024
 
 typedef struct f1ap_net_ip_address_s {
   unsigned ipv4:1;
@@ -310,7 +309,7 @@ typedef struct f1ap_initial_ul_rrc_message_s {
   uint16_t crnti;
   uint8_t *rrc_container;
   int      rrc_container_length;
-  char     du2cu_rrc_container[F1AP_MAX_DU2CU_RRC_LENGTH];
+  uint8_t *du2cu_rrc_container;
   int      du2cu_rrc_container_length;
 } f1ap_initial_ul_rrc_message_t;
 
diff --git a/openair2/F1AP/f1ap_cu_rrc_message_transfer.c b/openair2/F1AP/f1ap_cu_rrc_message_transfer.c
index 62a62095b16..3ae30cafb9f 100644
--- a/openair2/F1AP/f1ap_cu_rrc_message_transfer.c
+++ b/openair2/F1AP/f1ap_cu_rrc_message_transfer.c
@@ -79,56 +79,60 @@ int CU_handle_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t             instance,
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_C_RNTI, true);
   rnti = ie->value.choice.C_RNTI;
-  /* RRC Container */
-  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
+  F1AP_InitialULRRCMessageTransferIEs_t *rrccont;
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, rrccont, container,
                              F1AP_ProtocolIE_ID_id_RRCContainer, true);
-  AssertFatal(ie!=NULL,"RRCContainer is missing\n");
-
-  // create an ITTI message and copy SDU
-  if (f1ap_req(true, instance)->cell_type==CELL_MACRO_GNB) {
-    message_p = itti_alloc_new_message (TASK_CU_F1, 0, NR_RRC_MAC_CCCH_DATA_IND);
-    memset (NR_RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, CCCH_SDU_SIZE);
-    ccch_sdu_len = ie->value.choice.RRCContainer.size;
-    memcpy(NR_RRC_MAC_CCCH_DATA_IND (message_p).sdu, ie->value.choice.RRCContainer.buf,
-           ccch_sdu_len);
-  } else {
-    message_p = itti_alloc_new_message (TASK_CU_F1, 0, RRC_MAC_CCCH_DATA_IND);
-    memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, CCCH_SDU_SIZE);
-    ccch_sdu_len = ie->value.choice.RRCContainer.size;
-    memcpy(RRC_MAC_CCCH_DATA_IND (message_p).sdu, ie->value.choice.RRCContainer.buf,
-           ccch_sdu_len);
-  }
+  AssertFatal(rrccont!=NULL,"RRCContainer is missing\n");
 
-  LOG_I(F1AP, "%s() RRCContainer (CCCH) size %ld: ", __func__, ie->value.choice.RRCContainer.size);
-  /* DUtoCURRCContainer */
-  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
+  F1AP_InitialULRRCMessageTransferIEs_t *du2cu;
+  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, du2cu, container,
                              F1AP_ProtocolIE_ID_id_DUtoCURRCContainer, false);
 
-  if (ie) {
-    NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container = malloc(sizeof(OCTET_STRING_t));
-    NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->size = ie->value.choice.DUtoCURRCContainer.size;
-    NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->buf = malloc(ie->value.choice.DUtoCURRCContainer.size);
-    memcpy(NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->buf,
-           ie->value.choice.DUtoCURRCContainer.buf,
-           ie->value.choice.DUtoCURRCContainer.size);
-  }
-
   int f1ap_uid = f1ap_add_ue(CUtype, instance, rnti);
 
   if (f1ap_uid  < 0 ) {
     LOG_E(F1AP, "Failed to add UE \n");
-    itti_free(ITTI_MSG_ORIGIN_ID(message_p), message_p);
     return -1;
   }
 
+  // create an ITTI message and copy SDU
+  if (f1ap_req(true, instance)->cell_type==CELL_MACRO_GNB) {
+    message_p = itti_alloc_new_message (TASK_CU_F1, 0, F1AP_INITIAL_UL_RRC_MESSAGE);
+    f1ap_initial_ul_rrc_message_t *ul_rrc = &F1AP_INITIAL_UL_RRC_MESSAGE(message_p);
+    ul_rrc->nr_cellid = nr_cellid; // CU instance
+    ul_rrc->crnti      = rnti;
+    ul_rrc->rrc_container_length = rrccont->value.choice.RRCContainer.size;
+    ul_rrc->rrc_container = malloc(ul_rrc->rrc_container_length);
+    memcpy(ul_rrc->rrc_container, rrccont->value.choice.RRCContainer.buf, ul_rrc->rrc_container_length);
+    AssertFatal(du2cu != NULL, "no masterCellGroup in initial UL RRC message\n");
+    ul_rrc->du2cu_rrc_container_length = du2cu->value.choice.DUtoCURRCContainer.size;
+    ul_rrc->du2cu_rrc_container = malloc(ul_rrc->du2cu_rrc_container_length);
+    memcpy(ul_rrc->du2cu_rrc_container, du2cu->value.choice.DUtoCURRCContainer.buf, ul_rrc->du2cu_rrc_container_length);
+    itti_send_msg_to_task(TASK_RRC_GNB, instance, message_p);
+  } else {
+    message_p = itti_alloc_new_message (TASK_CU_F1, 0, RRC_MAC_CCCH_DATA_IND);
+    memset (RRC_MAC_CCCH_DATA_IND (message_p).sdu, 0, CCCH_SDU_SIZE);
+    ccch_sdu_len = rrccont->value.choice.RRCContainer.size;
+    memcpy(RRC_MAC_CCCH_DATA_IND (message_p).sdu, rrccont->value.choice.RRCContainer.buf,
+           ccch_sdu_len);
+    NR_RRC_MAC_CCCH_DATA_IND (message_p).frame     = 0;
+    NR_RRC_MAC_CCCH_DATA_IND (message_p).sub_frame = 0;
+    NR_RRC_MAC_CCCH_DATA_IND (message_p).sdu_size  = ccch_sdu_len;
+    NR_RRC_MAC_CCCH_DATA_IND (message_p).nr_cellid = nr_cellid; // CU instance
+    NR_RRC_MAC_CCCH_DATA_IND (message_p).rnti      = rnti;
+    NR_RRC_MAC_CCCH_DATA_IND (message_p).CC_id     = CC_id;
+    if (du2cu) {
+      NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container = malloc(sizeof(OCTET_STRING_t));
+      NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->size = du2cu->value.choice.DUtoCURRCContainer.size;
+      NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->buf = malloc(du2cu->value.choice.DUtoCURRCContainer.size);
+      memcpy(NR_RRC_MAC_CCCH_DATA_IND (message_p).du_to_cu_rrc_container->buf,
+             du2cu->value.choice.DUtoCURRCContainer.buf,
+             du2cu->value.choice.DUtoCURRCContainer.size);
+    }
+    itti_send_msg_to_task (TASK_RRC_ENB, instance, message_p);
+  }
+
   //getCxt(true,ITTI_MSG_DESTINATION_ID(message_p))->f1ap_ue[f1ap_uid].du_ue_f1ap_id = du_ue_f1ap_id;
-  NR_RRC_MAC_CCCH_DATA_IND (message_p).frame     = 0;
-  NR_RRC_MAC_CCCH_DATA_IND (message_p).sub_frame = 0;
-  NR_RRC_MAC_CCCH_DATA_IND (message_p).sdu_size  = ccch_sdu_len;
-  NR_RRC_MAC_CCCH_DATA_IND (message_p).nr_cellid = nr_cellid; // CU instance
-  NR_RRC_MAC_CCCH_DATA_IND (message_p).rnti      = rnti;
-  NR_RRC_MAC_CCCH_DATA_IND (message_p).CC_id     = CC_id;
-  itti_send_msg_to_task (f1ap_req(true,ITTI_MSG_DESTINATION_ID(message_p))->cell_type==CELL_MACRO_GNB?TASK_RRC_GNB:TASK_RRC_ENB, instance, message_p);
   return 0;
 }
 
diff --git a/openair2/F1AP/f1ap_du_rrc_message_transfer.c b/openair2/F1AP/f1ap_du_rrc_message_transfer.c
index d896a2640b4..c0f8b798397 100644
--- a/openair2/F1AP/f1ap_du_rrc_message_transfer.c
+++ b/openair2/F1AP/f1ap_du_rrc_message_transfer.c
@@ -749,7 +749,7 @@ int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t     instanceP,
     rnti_t          rntiP,
     const uint8_t   *sduP,
     sdu_size_t      sdu_lenP,
-    const char      *sdu2P,
+    const uint8_t   *sdu2P,
     sdu_size_t      sdu2_lenP) {
   F1AP_F1AP_PDU_t                       pdu= {0};
   F1AP_InitialULRRCMessageTransfer_t    *out;
@@ -808,7 +808,7 @@ int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t     instanceP,
     ie5->criticality                    = F1AP_Criticality_reject;
     ie5->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
     OCTET_STRING_fromBuf(&ie5->value.choice.DUtoCURRCContainer,
-                         sdu2P,
+                         (const char *)sdu2P,
                          sdu2_lenP);
   }
   /* mandatory */
diff --git a/openair2/F1AP/f1ap_du_rrc_message_transfer.h b/openair2/F1AP/f1ap_du_rrc_message_transfer.h
index d6f196e3843..b42d731ac70 100644
--- a/openair2/F1AP/f1ap_du_rrc_message_transfer.h
+++ b/openair2/F1AP/f1ap_du_rrc_message_transfer.h
@@ -50,7 +50,7 @@ int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t     instanceP,
     rnti_t          rntiP,
     const uint8_t   *sduP,
     sdu_size_t      sdu_lenP,
-    const char   *sdu2P,
+    const uint8_t   *sdu2P,
     sdu_size_t      sdu2_lenP);
 
 #endif /* F1AP_DU_RRC_MESSAGE_TRANSFER_H_ */
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
index 9941437e130..acbfc3a25b6 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
@@ -44,9 +44,12 @@
 #include "OCG.h"
 #include "OCG_extern.h"
 
+/* TODO REMOVE_DU_RRC: the RRC in the DU is a hack and should be taken out in the future */
 #include "RRC/LTE/rrc_extern.h"
 #include "RRC/NR/nr_rrc_extern.h"
+#include "RRC/NR/rrc_gNB_UE_context.h"
 #include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
+#include "RRC/NR/MESSAGES/asn1_msg.h"
 
 #include "intertask_interface.h"
 
@@ -2318,7 +2321,7 @@ int rnti_to_remove[10];
 volatile int rnti_to_remove_count;
 pthread_mutex_t rnti_to_remove_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-void delete_nr_ue_data(NR_UE_info_t *UE, NR_COMMON_channels_t *ccPtr)
+void delete_nr_ue_data(NR_UE_info_t *UE, NR_COMMON_channels_t *ccPtr, uid_allocator_t *uia)
 {
   NR_UE_sched_ctrl_t *sched_ctrl = &UE->UE_sched_ctrl;
   destroy_nr_list(&sched_ctrl->available_dl_harq);
@@ -2327,6 +2330,7 @@ void delete_nr_ue_data(NR_UE_info_t *UE, NR_COMMON_channels_t *ccPtr)
   destroy_nr_list(&sched_ctrl->available_ul_harq);
   destroy_nr_list(&sched_ctrl->feedback_ul_harq);
   destroy_nr_list(&sched_ctrl->retrans_ul_harq);
+  uid_linear_allocator_free(uia, UE->uid);
   LOG_I(NR_MAC, "Remove NR rnti 0x%04x\n", UE->rnti);
   const rnti_t rnti = UE->rnti;
   free(UE);
@@ -2374,6 +2378,7 @@ NR_UE_info_t *add_new_nr_ue(gNB_MAC_INST *nr_mac, rnti_t rntiP, NR_CellGroupConf
   }
 
   UE->rnti = rntiP;
+  UE->uid = uid_linear_allocator_new(&UE_info->uid_allocator);
   UE->CellGroup = CellGroup;
 
   if (CellGroup)
@@ -2469,7 +2474,7 @@ NR_UE_info_t *add_new_nr_ue(gNB_MAC_INST *nr_mac, rnti_t rntiP, NR_CellGroupConf
     }
   if (i == MAX_MOBILES_PER_GNB) {
     LOG_E(NR_MAC,"Try to add UE %04x but the list is full\n", rntiP);
-    delete_nr_ue_data(UE, nr_mac->common_channels);
+    delete_nr_ue_data(UE, nr_mac->common_channels, &UE_info->uid_allocator);
     pthread_mutex_unlock(&UE_info->mutex);
     return NULL;
   }
@@ -2573,7 +2578,7 @@ void mac_remove_nr_ue(gNB_MAC_INST *nr_mac, rnti_t rnti)
  memcpy(UE_info->list, newUEs, sizeof(UE_info->list));
  pthread_mutex_unlock(&UE_info->mutex);
 
- delete_nr_ue_data(UE, nr_mac->common_channels);
+ delete_nr_ue_data(UE, nr_mac->common_channels, &UE_info->uid_allocator);
 }
 
 void nr_mac_remove_ra_rnti(module_id_t mod_id, rnti_t rnti) {
@@ -3091,3 +3096,52 @@ void UL_tti_req_ahead_initialization(gNB_MAC_INST * gNB, NR_ServingCellConfigCom
     req->Slot = i;
   }
 }
+
+void send_initial_ul_rrc_message(module_id_t        module_id,
+                                 int                CC_id,
+                                 const NR_UE_info_t *UE,
+                                 rb_id_t            srb_id,
+                                 const uint8_t      *sdu,
+                                 sdu_size_t         sdu_len) {
+  const gNB_MAC_INST *mac = RC.nrmac[module_id];
+  const rnti_t rnti = UE->rnti;
+  LOG_W(MAC,
+        "[RAPROC] Received SDU for CCCH on SRB %ld length %d for UE %04x\n",
+        srb_id, sdu_len, rnti);
+
+  /* TODO REMOVE_DU_RRC: the RRC in the DU is a hack and should be taken out in the future */
+  if (NODE_IS_DU(RC.nrrrc[module_id]->node_type)) {
+    struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_allocate_new_UE_context(RC.nrrrc[module_id]);
+    ue_context_p->ue_id_rnti                    = rnti;
+    ue_context_p->ue_context.rnti               = rnti;
+    ue_context_p->ue_context.random_ue_identity = rnti;
+    ue_context_p->ue_context.Srb0.Active        = 1;
+    RB_INSERT(rrc_nr_ue_tree_s, &RC.nrrrc[module_id]->rrc_ue_head, ue_context_p);
+  }
+
+  const NR_ServingCellConfigCommon_t *scc = RC.nrrrc[module_id]->carrier.servingcellconfigcommon;
+  const NR_ServingCellConfig_t *sccd = RC.nrrrc[module_id]->configuration.scd;
+  NR_CellGroupConfig_t cellGroupConfig = {0};
+  fill_initial_cellGroupConfig(UE->uid, &cellGroupConfig, scc, sccd, &RC.nrrrc[module_id]->configuration);
+
+  uint8_t du2cu_rrc_container[1024];
+  asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CellGroupConfig,
+                                                  NULL,
+                                                  &cellGroupConfig,
+                                                  du2cu_rrc_container,
+                                                  sizeof(du2cu_rrc_container));
+  AssertFatal(enc_rval.encoded > 0,
+              "Could not encode cellGroupConfig for UE %04x, failed element %s\n",
+              rnti,
+              enc_rval.failed_type->name);
+
+  const f1ap_initial_ul_rrc_message_t ul_rrc_msg = {
+    /* TODO: add mcc, mnc, cell_id, ..., is not available at MAC yet */
+    .crnti = rnti,
+    .rrc_container = (uint8_t *) sdu,
+    .rrc_container_length = sdu_len,
+    .du2cu_rrc_container = (uint8_t *) du2cu_rrc_container,
+    .du2cu_rrc_container_length = (enc_rval.encoded + 7) / 8
+  };
+  mac->mac_rrc.initial_ul_rrc_message_transfer(module_id, &ul_rrc_msg);
+}
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
index ce276b079c3..08ef33b582e 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
@@ -320,16 +320,12 @@ int nr_process_mac_pdu( instance_t module_idP,
             mac_len = 6;
           }
 
-          nr_mac_rrc_data_ind(module_idP,
-                              CC_id,
-                              frameP,
-                              0,
-                              0,
-                              UE->rnti,
-                              CCCH,
-                              pduP + mac_subheader_len,
-                              mac_len,
-                              0);
+          send_initial_ul_rrc_message(module_idP,
+                                      CC_id,
+                                      UE,
+                                      CCCH,
+                                      pduP + mac_subheader_len,
+                                      mac_len);
           break;
 
         case UL_SCH_LCID_DTCH ... (UL_SCH_LCID_DTCH + 28):
diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
index 950119510de..41c094a9117 100644
--- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
+++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h
@@ -520,7 +520,12 @@ void nr_sr_reporting(gNB_MAC_INST *nrmac, frame_t frameP, sub_frame_t slotP);
 
 size_t dump_mac_stats(gNB_MAC_INST *gNB, char *output, size_t strlen, bool reset_rsrp);
 
-void process_CellGroup(NR_CellGroupConfig_t *CellGroup, NR_UE_sched_ctrl_t *sched_ctrl);
+void send_initial_ul_rrc_message(module_id_t        module_id,
+                                 int                CC_id,
+                                 const NR_UE_info_t *UE,
+                                 rb_id_t            srb_id,
+                                 const uint8_t      *sdu,
+                                 sdu_size_t         sdu_len);
 
 void abort_nr_dl_harq(NR_UE_info_t* UE, int8_t harq_pid);
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_rrc_ul_direct.c b/openair2/LAYER2/NR_MAC_gNB/mac_rrc_ul_direct.c
index f290e0d2680..25ee7feb14a 100644
--- a/openair2/LAYER2/NR_MAC_gNB/mac_rrc_ul_direct.c
+++ b/openair2/LAYER2/NR_MAC_gNB/mac_rrc_ul_direct.c
@@ -25,8 +25,22 @@
 
 static void initial_ul_rrc_message_transfer_direct(module_id_t module_id, const f1ap_initial_ul_rrc_message_t *ul_rrc)
 {
-  /* TODO ITTI message for NR_RRC_MAC_IND? */
-  AssertFatal(0 == 1, "not implemented\n");
+  MessageDef *msg = itti_alloc_new_message(TASK_MAC_GNB, 0, F1AP_INITIAL_UL_RRC_MESSAGE);
+  /* copy all fields, but reallocate rrc_containers! */
+  f1ap_initial_ul_rrc_message_t *f1ap_msg = &F1AP_INITIAL_UL_RRC_MESSAGE(msg);
+  *f1ap_msg = *ul_rrc;
+
+  f1ap_msg->rrc_container = malloc(ul_rrc->rrc_container_length);
+  DevAssert(f1ap_msg->rrc_container);
+  memcpy(f1ap_msg->rrc_container, ul_rrc->rrc_container, ul_rrc->rrc_container_length);
+  f1ap_msg->rrc_container_length = ul_rrc->rrc_container_length;
+
+  f1ap_msg->du2cu_rrc_container = malloc(ul_rrc->du2cu_rrc_container_length);
+  DevAssert(f1ap_msg->du2cu_rrc_container);
+  memcpy(f1ap_msg->du2cu_rrc_container, ul_rrc->du2cu_rrc_container, ul_rrc->du2cu_rrc_container_length);
+  f1ap_msg->du2cu_rrc_container_length = ul_rrc->du2cu_rrc_container_length;
+
+  itti_send_msg_to_task(TASK_RRC_GNB, module_id, msg);
 }
 
 void mac_rrc_ul_direct_init(struct nr_mac_rrc_ul_if_s *mac_rrc)
diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_rrc_ul_f1ap.c b/openair2/LAYER2/NR_MAC_gNB/mac_rrc_ul_f1ap.c
index ed67fb91193..65e7f10405e 100644
--- a/openair2/LAYER2/NR_MAC_gNB/mac_rrc_ul_f1ap.c
+++ b/openair2/LAYER2/NR_MAC_gNB/mac_rrc_ul_f1ap.c
@@ -25,7 +25,22 @@
 
 static void initial_ul_rrc_message_transfer_f1ap(module_id_t module_id, const f1ap_initial_ul_rrc_message_t *ul_rrc)
 {
-  AssertFatal(0 == 1, "not implemented\n");
+  MessageDef *msg = itti_alloc_new_message(TASK_MAC_GNB, 0, F1AP_INITIAL_UL_RRC_MESSAGE);
+  /* copy all fields, but reallocate rrc_containers! */
+  f1ap_initial_ul_rrc_message_t *f1ap_msg = &F1AP_INITIAL_UL_RRC_MESSAGE(msg);
+  *f1ap_msg = *ul_rrc;
+
+  f1ap_msg->rrc_container = malloc(ul_rrc->rrc_container_length);
+  DevAssert(f1ap_msg->rrc_container);
+  memcpy(f1ap_msg->rrc_container, ul_rrc->rrc_container, ul_rrc->rrc_container_length);
+  f1ap_msg->rrc_container_length = ul_rrc->rrc_container_length;
+
+  f1ap_msg->du2cu_rrc_container = malloc(ul_rrc->du2cu_rrc_container_length);
+  DevAssert(f1ap_msg->du2cu_rrc_container);
+  memcpy(f1ap_msg->du2cu_rrc_container, ul_rrc->du2cu_rrc_container, ul_rrc->du2cu_rrc_container_length);
+  f1ap_msg->du2cu_rrc_container_length = ul_rrc->du2cu_rrc_container_length;
+
+  itti_send_msg_to_task(TASK_DU_F1, module_id, msg);
 }
 
 void mac_rrc_ul_f1ap_init(struct nr_mac_rrc_ul_if_s *mac_rrc)
diff --git a/openair2/LAYER2/NR_MAC_gNB/main.c b/openair2/LAYER2/NR_MAC_gNB/main.c
index 3a58393c6b8..fd7168dea2d 100644
--- a/openair2/LAYER2/NR_MAC_gNB/main.c
+++ b/openair2/LAYER2/NR_MAC_gNB/main.c
@@ -220,6 +220,7 @@ void mac_top_init_gNB(ngran_node_t node_type)
       RC.nrmac[i]->first_MIB = true;
 
       pthread_mutex_init(&RC.nrmac[i]->UE_info.mutex, NULL);
+      uid_linear_allocator_init(&RC.nrmac[i]->UE_info.uid_allocator);
 
       if (get_softmodem_params()->phy_test) {
         RC.nrmac[i]->pre_processor_dl = nr_preprocessor_phytest;
diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
index 3d94bcfa435..2d618029c6e 100644
--- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
+++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
@@ -46,6 +46,7 @@
 #include "targets/ARCH/COMMON/common_lib.h"
 #include "COMMON/platform_constants.h"
 #include "common/ran_context.h"
+#include "collection/linear_alloc.h"
 
 /* RRC */
 #include "NR_BCCH-BCH-Message.h"
@@ -711,6 +712,7 @@ typedef struct nr_mac_rrc_ul_if_s {
 #define MAX_CSI_REPORTCONFIG 48
 typedef struct {
   rnti_t rnti;
+  uid_t uid; // unique ID of this UE
   /// scheduling control info
   nr_csi_report_t csi_report_template[MAX_CSI_REPORTCONFIG];
   NR_UE_sched_ctrl_t UE_sched_ctrl;
@@ -737,6 +739,7 @@ typedef struct {
   pthread_mutex_t mutex;
   NR_UE_info_t *list[MAX_MOBILES_PER_GNB+1];
   bool sched_csirs;
+  uid_allocator_t uid_allocator;
 } NR_UEs_t;
 
 #define UE_iterator(BaSe, VaR) NR_UE_info_t ** VaR##pptr=BaSe, *VaR; while ((VaR=*(VaR##pptr++)))
diff --git a/openair2/RRC/NR/L2_nr_interface.c b/openair2/RRC/NR/L2_nr_interface.c
index 6fc0566cbd5..9ed279e5007 100644
--- a/openair2/RRC/NR/L2_nr_interface.c
+++ b/openair2/RRC/NR/L2_nr_interface.c
@@ -306,74 +306,6 @@ int8_t nr_mac_rrc_bwp_switch_req(const module_id_t     module_idP,
   return 0;
 }
 
-int8_t nr_mac_rrc_data_ind(const module_id_t     module_idP,
-                           const int             CC_id,
-                           const frame_t         frameP,
-                           const sub_frame_t     sub_frameP,
-                           const int             UE_id,
-                           const rnti_t          rntiP,
-                           const rb_id_t         srb_idP,
-                           const uint8_t        *sduP,
-                           const sdu_size_t      sdu_lenP,
-                           const bool            brOption) {
-
-  if (NODE_IS_DU(RC.nrrrc[module_idP]->node_type)) {
-    LOG_W(RRC,"[DU %d][RAPROC] Received SDU for CCCH on SRB %ld length %d for UE id %d RNTI %x \n",
-          module_idP, srb_idP, sdu_lenP, UE_id, rntiP);
-
-    // Generate DUtoCURRCContainer
-    // call do_RRCSetup like full procedure and extract masterCellGroup
-    NR_CellGroupConfig_t cellGroupConfig;
-    NR_ServingCellConfigCommon_t *scc=RC.nrrrc[module_idP]->carrier.servingcellconfigcommon;
-    NR_ServingCellConfig_t *servingcellconfigdedicated = RC.nrrrc[module_idP]->configuration.scd;
-    memset(&cellGroupConfig,0,sizeof(cellGroupConfig));
-
-    struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_allocate_new_UE_context(RC.nrrrc[module_idP]);
-    ue_context_p->ue_id_rnti                    = rntiP;
-    ue_context_p->ue_context.rnti               = rntiP;
-    ue_context_p->ue_context.random_ue_identity = rntiP;
-    ue_context_p->ue_context.Srb0.Active        = 1;
-    RB_INSERT(rrc_nr_ue_tree_s, &RC.nrrrc[module_idP]->rrc_ue_head, ue_context_p);
-
-    fill_initial_cellGroupConfig(ue_context_p->local_uid,&cellGroupConfig,scc,servingcellconfigdedicated,&RC.nrrrc[module_idP]->configuration);
-
-    MessageDef* tmp=itti_alloc_new_message_sized(TASK_RRC_GNB, 0, F1AP_INITIAL_UL_RRC_MESSAGE, sizeof(f1ap_initial_ul_rrc_message_t) + sdu_lenP);
-    f1ap_initial_ul_rrc_message_t *msg = &F1AP_INITIAL_UL_RRC_MESSAGE(tmp);
-
-    asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CellGroupConfig,
-                                                    NULL,
-                                                    (void *)&cellGroupConfig,
-                                                    msg->du2cu_rrc_container,
-                                                    F1AP_MAX_DU2CU_RRC_LENGTH);
-
-    if (enc_rval.encoded == -1) {
-      LOG_E(F1AP,"Could not encoded cellGroupConfig, failed element %s\n",enc_rval.failed_type->name);
-      exit(-1);
-    }
-    /* do ITTI message */
-    msg->du2cu_rrc_container_length = (enc_rval.encoded+7)/8;
-    msg->crnti=rntiP;
-    msg->rrc_container=(uint8_t*) (msg+1); // Made extra room after the struct with itti_alloc_msg_sized()
-    memcpy(msg->rrc_container, sduP, sdu_lenP);
-    msg->rrc_container_length=sdu_lenP;
-    itti_send_msg_to_task(TASK_DU_F1, 0, tmp);
-
-    return 0;
-  }
-
-  protocol_ctxt_t ctxt;
-  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, GNB_FLAG_YES, rntiP, frameP, sub_frameP,0);
-
-  if((srb_idP & RAB_OFFSET) == CCCH) {
-    LOG_D(NR_RRC, "[gNB %d] Received SDU for CCCH on SRB %ld\n", module_idP, srb_idP);
-    ctxt.brOption = brOption;
-    if (sdu_lenP > 0) {
-      nr_rrc_gNB_decode_ccch(&ctxt, sduP, sdu_lenP, NULL, CC_id);
-    }
-  }
-  return 0;
-}
-
 void nr_mac_gNB_rrc_ul_failure(const module_id_t Mod_instP,
                                const int CC_idP,
                                const frame_t frameP,
diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c
index ea4e038ca04..4bbcdb2cc97 100755
--- a/openair2/RRC/NR/MESSAGES/asn1_msg.c
+++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c
@@ -1020,8 +1020,8 @@ long rrc_get_max_nr_csrs(uint8_t max_rbs, long b_SRS) {
 
 void fill_default_downlinkBWP(NR_BWP_Downlink_t *bwp,
                               int bwp_loop,
-                              NR_ServingCellConfig_t *servingcellconfigdedicated,
-                              NR_ServingCellConfigCommon_t *scc,
+                              const NR_ServingCellConfig_t *servingcellconfigdedicated,
+                              const NR_ServingCellConfigCommon_t *scc,
                               const gNB_RrcConfigurationReq *configuration) {
 
   /// BWP common configuration
@@ -1167,8 +1167,8 @@ void fill_default_downlinkBWP(NR_BWP_Downlink_t *bwp,
 
 void fill_default_uplinkBWP(NR_BWP_Uplink_t *ubwp,
                             int bwp_loop,
-                            NR_ServingCellConfig_t *servingcellconfigdedicated,
-                            NR_ServingCellConfigCommon_t *scc,
+                            const NR_ServingCellConfig_t *servingcellconfigdedicated,
+                            const NR_ServingCellConfigCommon_t *scc,
                             const gNB_RrcConfigurationReq *configuration,
                             int uid) {
 
@@ -1364,13 +1364,11 @@ void fill_default_uplinkBWP(NR_BWP_Uplink_t *ubwp,
 }
 
 void fill_initial_SpCellConfig(int uid,
-                               NR_CellGroupConfig_t *cellGroupConfig,
-                               NR_ServingCellConfigCommon_t *scc,
-                               NR_ServingCellConfig_t *servingcellconfigdedicated,
-                               const gNB_RrcConfigurationReq *configuration) {
-
-  NR_SpCellConfig_t *SpCellConfig = cellGroupConfig->spCellConfig;
-
+                               NR_SpCellConfig_t *SpCellConfig,
+                               const NR_ServingCellConfigCommon_t *scc,
+                               const NR_ServingCellConfig_t *servingcellconfigdedicated,
+                               const gNB_RrcConfigurationReq *configuration)
+{
   // This assert will never happen in the current implementation because NUMBER_OF_UE_MAX = 4.
   // However, if in the future NUMBER_OF_UE_MAX is increased, it will be necessary to improve the allocation of SRS resources,
   // where the startPosition = 2 or 3 and sl160 = 17, 17, 27 ... 157 only give us 30 different allocations.
@@ -2002,8 +2000,8 @@ void update_cellGroupConfig(NR_CellGroupConfig_t *cellGroupConfig,
 
 void fill_initial_cellGroupConfig(int uid,
                                   NR_CellGroupConfig_t *cellGroupConfig,
-                                  NR_ServingCellConfigCommon_t *scc,
-                                  NR_ServingCellConfig_t *servingcellconfigdedicated,
+                                  const NR_ServingCellConfigCommon_t *scc,
+                                  const NR_ServingCellConfig_t *servingcellconfigdedicated,
                                   const gNB_RrcConfigurationReq *configuration)
 {
   NR_MAC_CellGroupConfig_t                         *mac_CellGroupConfig  = NULL;
@@ -2057,20 +2055,21 @@ void fill_initial_cellGroupConfig(int uid,
   
   cellGroupConfig->spCellConfig                                             = calloc(1,sizeof(*cellGroupConfig->spCellConfig));
 
-  fill_initial_SpCellConfig(uid,cellGroupConfig,scc,servingcellconfigdedicated,configuration);
+  fill_initial_SpCellConfig(uid,cellGroupConfig->spCellConfig,scc,servingcellconfigdedicated,configuration);
   
   cellGroupConfig->sCellToAddModList                                        = NULL;
   cellGroupConfig->sCellToReleaseList                                       = NULL;
 }
 
 //------------------------------------------------------------------------------
-int16_t do_RRCSetup(rrc_gNB_ue_context_t          *const ue_context_pP,
-                    uint8_t                       *const buffer,
-                    const uint8_t                 transaction_id,
-                    OCTET_STRING_t                *masterCellGroup_from_DU,
-                    NR_ServingCellConfigCommon_t  *scc,
-                    NR_ServingCellConfig_t        *servingcellconfigdedicated,
-                    const gNB_RrcConfigurationReq *configuration)
+int do_RRCSetup(rrc_gNB_ue_context_t         *const ue_context_pP,
+                uint8_t                      *const buffer,
+                const uint8_t                transaction_id,
+                const uint8_t                *masterCellGroup,
+                int                          masterCellGroup_len,
+                const NR_ServingCellConfigCommon_t *scc,
+                const NR_ServingCellConfig_t        *servingcellconfigdedicated,
+                const gNB_RrcConfigurationReq *configuration)
 //------------------------------------------------------------------------------
 {
     asn_enc_rval_t                                   enc_rval;
@@ -2080,7 +2079,6 @@ int16_t do_RRCSetup(rrc_gNB_ue_context_t          *const ue_context_pP,
     NR_SRB_ToAddMod_t                                *SRB1_config          = NULL;
     NR_PDCP_Config_t                                 *pdcp_Config          = NULL;
     NR_CellGroupConfig_t                             *cellGroupConfig      = NULL;
-    char masterCellGroup_buf[3000];
 
     AssertFatal(ue_context_pP != NULL,"ue_context_p is null\n");
     gNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context;
@@ -2123,38 +2121,14 @@ int16_t do_RRCSetup(rrc_gNB_ue_context_t          *const ue_context_pP,
     ie->radioBearerConfig.securityConfig    = NULL;
     
     /****************************** masterCellGroup ******************************/
-    /* TODO */
-    if (masterCellGroup_from_DU) {
-      memcpy(&ie->masterCellGroup,masterCellGroup_from_DU,sizeof(*masterCellGroup_from_DU));
-      // decode masterCellGroup OCTET_STRING received from DU and place in ue context
-      uper_decode(NULL,
-		  &asn_DEF_NR_CellGroupConfig,   //might be added prefix later
-		  (void **)&cellGroupConfig,
-		  (uint8_t *)masterCellGroup_from_DU->buf,
-		  masterCellGroup_from_DU->size, 0, 0);
-    }
-    else {
-      cellGroupConfig = calloc(1, sizeof(NR_CellGroupConfig_t));
-      fill_initial_cellGroupConfig(ue_context_pP->local_uid,cellGroupConfig,scc,servingcellconfigdedicated,configuration);
-
-      enc_rval = uper_encode_to_buffer(&asn_DEF_NR_CellGroupConfig,
-				       NULL,
-				       (void *)cellGroupConfig,
-				       masterCellGroup_buf,
-				       3000);
-      
-      if(enc_rval.encoded == -1) {
-        LOG_E(NR_RRC, "ASN1 message CellGroupConfig encoding failed (%s, %lu)!\n",
-	      enc_rval.failed_type->name, enc_rval.encoded);
-        return -1;
-      }
-      
-      if (OCTET_STRING_fromBuf(&ie->masterCellGroup, masterCellGroup_buf, (enc_rval.encoded+7)/8) == -1) {
-        LOG_E(NR_RRC, "fatal: OCTET_STRING_fromBuf failed\n");
-        return -1;
-      }
-    }
-
+    DevAssert(masterCellGroup && masterCellGroup_len > 0);
+    ie->masterCellGroup.buf = malloc(masterCellGroup_len);
+    AssertFatal(ie->masterCellGroup.buf != NULL, "could not allocate memory for masterCellGroup\n");
+    memcpy(ie->masterCellGroup.buf, masterCellGroup, masterCellGroup_len);
+    ie->masterCellGroup.size = masterCellGroup_len;
+
+    // decode masterCellGroup OCTET_STRING received from DU and place in ue context
+    uper_decode(NULL, &asn_DEF_NR_CellGroupConfig, (void **)&cellGroupConfig, masterCellGroup, masterCellGroup_len, 0, 0);
     ue_p->masterCellGroup = cellGroupConfig;
 
     if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) {
diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.h b/openair2/RRC/NR/MESSAGES/asn1_msg.h
index 61a81fb2d5c..d480fd39a1a 100644
--- a/openair2/RRC/NR/MESSAGES/asn1_msg.h
+++ b/openair2/RRC/NR/MESSAGES/asn1_msg.h
@@ -102,15 +102,15 @@ uint8_t do_RRCReject(uint8_t Mod_id,
                      uint8_t *const buffer);
 
 void fill_initial_SpCellConfig(int uid,
-                               NR_CellGroupConfig_t *cellGroupConfig,
-                               NR_ServingCellConfigCommon_t *scc,
-                               NR_ServingCellConfig_t *servingcellconfigdedicated,
+                               NR_SpCellConfig_t *SpCellConfig,
+                               const NR_ServingCellConfigCommon_t *scc,
+                               const NR_ServingCellConfig_t *servingcellconfigdedicated,
                                const gNB_RrcConfigurationReq *configuration);
 
 void fill_initial_cellGroupConfig(int uid,
                                   NR_CellGroupConfig_t *cellGroupConfig,
-                                  NR_ServingCellConfigCommon_t *scc,
-                                  NR_ServingCellConfig_t *servingcellconfigdedicated,
+                                  const NR_ServingCellConfigCommon_t *scc,
+                                  const NR_ServingCellConfig_t *servingcellconfigdedicated,
                                   const gNB_RrcConfigurationReq *configuration);
 
 void update_cellGroupConfig(NR_CellGroupConfig_t *cellGroupConfig,
@@ -125,13 +125,14 @@ void fill_mastercellGroupConfig(NR_CellGroupConfig_t *cellGroupConfig,
                                 uint8_t nb_bearers_to_setup,
                                 long *priority);
 
-int16_t do_RRCSetup(rrc_gNB_ue_context_t         *const ue_context_pP,
-                    uint8_t                      *const buffer,
-                    const uint8_t                transaction_id,
-                    OCTET_STRING_t               *masterCellGroup_from_DU,
-                    NR_ServingCellConfigCommon_t *scc,
-                    NR_ServingCellConfig_t       *servingcellconfigdedicated,
-                    const gNB_RrcConfigurationReq *configuration);
+int do_RRCSetup(rrc_gNB_ue_context_t         *const ue_context_pP,
+                uint8_t                      *const buffer,
+                const uint8_t                transaction_id,
+                const uint8_t                *masterCellGroup,
+                int                          masterCellGroup_len,
+                const NR_ServingCellConfigCommon_t *scc,
+                const NR_ServingCellConfig_t       *servingcellconfigdedicated,
+                const gNB_RrcConfigurationReq *configuration);
 
 uint8_t do_NR_SecurityModeCommand(
                     const protocol_ctxt_t *const ctxt_pP,
diff --git a/openair2/RRC/NR/nr_rrc_config.c b/openair2/RRC/NR/nr_rrc_config.c
index 11460f86af0..211a1542980 100644
--- a/openair2/RRC/NR/nr_rrc_config.c
+++ b/openair2/RRC/NR/nr_rrc_config.c
@@ -71,7 +71,7 @@ void rrc_coreset_config(NR_ControlResourceSet_t *coreset,
   coreset->pdcch_DMRS_ScramblingID = NULL;
 }
 
-uint64_t get_ssb_bitmap(NR_ServingCellConfigCommon_t *scc) {
+uint64_t get_ssb_bitmap(const NR_ServingCellConfigCommon_t *scc) {
   uint64_t bitmap=0;
   switch (scc->ssb_PositionsInBurst->present) {
     case 1 :
@@ -139,7 +139,7 @@ void set_csirs_periodicity(NR_NZP_CSI_RS_Resource_t *nzpcsi0, int uid, int nb_sl
 }
 
 
-void config_csirs(NR_ServingCellConfigCommon_t *servingcellconfigcommon,
+void config_csirs(const NR_ServingCellConfigCommon_t *servingcellconfigcommon,
                   NR_CSI_MeasConfig_t *csi_MeasConfig,
                   int uid,
                   int num_dl_antenna_ports,
@@ -372,7 +372,7 @@ void prepare_sim_uecap(NR_UE_NR_Capability_t *cap,
   phy_Parameters->phy_ParametersFRX_Diff->pucch_F0_2WithoutFH = NULL;
 }
 
-void nr_rrc_config_dl_tda(NR_ServingCellConfigCommon_t *scc,
+void nr_rrc_config_dl_tda(const NR_ServingCellConfigCommon_t *scc,
                           NR_PDSCH_TimeDomainResourceAllocationList_t	*pdsch_TimeDomainAllocationList,
                           int curr_bwp) {
 
@@ -593,9 +593,9 @@ void set_pucch_power_config(NR_PUCCH_Config_t *pucch_Config, int do_csirs) {
   ASN_SEQUENCE_ADD(&pucch_Config->spatialRelationInfoToAddModList->list,pucchspatial);
 }
 
-void set_SR_periodandoffset(NR_SchedulingRequestResourceConfig_t *schedulingRequestResourceConfig,
-                            NR_ServingCellConfigCommon_t *scc) {
-
+static void set_SR_periodandoffset(NR_SchedulingRequestResourceConfig_t *schedulingRequestResourceConfig,
+                            const NR_ServingCellConfigCommon_t *scc)
+{
   const NR_TDD_UL_DL_Pattern_t *tdd = scc->tdd_UL_DL_ConfigurationCommon ? &scc->tdd_UL_DL_ConfigurationCommon->pattern1 : NULL;
   int sr_slot = 1; // in FDD SR in slot 1
   if(tdd)
@@ -637,7 +637,7 @@ void set_SR_periodandoffset(NR_SchedulingRequestResourceConfig_t *schedulingRequ
   schedulingRequestResourceConfig->periodicityAndOffset->choice.sl640 = sr_slot;
 }
 
-void scheduling_request_config(NR_ServingCellConfigCommon_t *scc,
+void scheduling_request_config(const NR_ServingCellConfigCommon_t *scc,
                                NR_PUCCH_Config_t *pucch_Config) {
 
   // format with <=2 bits in pucch resource set 0
@@ -660,7 +660,7 @@ void scheduling_request_config(NR_ServingCellConfigCommon_t *scc,
 void set_dl_mcs_table(int scs, NR_UE_NR_Capability_t *cap,
                       NR_SpCellConfig_t *SpCellConfig,
                       NR_BWP_DownlinkDedicated_t *bwp_Dedicated,
-                      NR_ServingCellConfigCommon_t *scc) {
+                      const NR_ServingCellConfigCommon_t *scc) {
 
   if (cap == NULL){
     bwp_Dedicated->pdsch_Config->choice.setup->mcs_Table = NULL;
diff --git a/openair2/RRC/NR/nr_rrc_config.h b/openair2/RRC/NR/nr_rrc_config.h
index 1d6db7b64dd..e062bbdfac9 100644
--- a/openair2/RRC/NR/nr_rrc_config.h
+++ b/openair2/RRC/NR/nr_rrc_config.h
@@ -111,12 +111,12 @@ typedef struct physicalcellgroup_s{
   long        RNTI_Value[MAX_NUM_CCs];
 }physicalcellgroup_t;
 
-uint64_t get_ssb_bitmap(NR_ServingCellConfigCommon_t *scc);
+uint64_t get_ssb_bitmap(const NR_ServingCellConfigCommon_t *scc);
 void rrc_coreset_config(NR_ControlResourceSet_t *coreset,
                         int bwp_id,
                         int curr_bwp,
                         uint64_t ssb_bitmap);
-void nr_rrc_config_dl_tda(NR_ServingCellConfigCommon_t *scc,
+void nr_rrc_config_dl_tda(const NR_ServingCellConfigCommon_t *scc,
                           NR_PDSCH_TimeDomainResourceAllocationList_t	*pdsch_TimeDomainAllocationList,
                           int curr_bwp);
 void nr_rrc_config_ul_tda(NR_ServingCellConfigCommon_t *scc, int min_fb_delay);
@@ -124,9 +124,9 @@ void config_pucch_resset0(NR_PUCCH_Config_t *pucch_Config, int uid, int curr_bwp
 void config_pucch_resset1(NR_PUCCH_Config_t *pucch_Config, NR_UE_NR_Capability_t *uecap);
 void set_dl_DataToUL_ACK(NR_PUCCH_Config_t *pucch_Config, int min_feedback_time);
 void set_pucch_power_config(NR_PUCCH_Config_t *pucch_Config, int do_csirs);
-void scheduling_request_config(NR_ServingCellConfigCommon_t *scc,
+void scheduling_request_config(const NR_ServingCellConfigCommon_t *scc,
                                NR_PUCCH_Config_t *pucch_Config);
-void config_csirs(NR_ServingCellConfigCommon_t *servingcellconfigcommon,
+void config_csirs(const NR_ServingCellConfigCommon_t *servingcellconfigcommon,
                   NR_CSI_MeasConfig_t *csi_MeasConfig,
                   int uid,
                   int num_dl_antenna_ports,
@@ -137,7 +137,7 @@ void config_csiim(int do_csirs, int dl_antenna_ports, int curr_bwp,
 void set_dl_mcs_table(int scs, NR_UE_NR_Capability_t *cap,
                       NR_SpCellConfig_t *SpCellConfig,
                       NR_BWP_DownlinkDedicated_t *bwp_Dedicated,
-                      NR_ServingCellConfigCommon_t *scc);
+                      const NR_ServingCellConfigCommon_t *scc);
 void prepare_sim_uecap(NR_UE_NR_Capability_t *cap,
                        NR_ServingCellConfigCommon_t *scc,
                        int numerology,
diff --git a/openair2/RRC/NR/nr_rrc_proto.h b/openair2/RRC/NR/nr_rrc_proto.h
index dc6e14215ff..b90cf4dfa4c 100644
--- a/openair2/RRC/NR/nr_rrc_proto.h
+++ b/openair2/RRC/NR/nr_rrc_proto.h
@@ -108,9 +108,9 @@ void
 rrc_gNB_generate_RRCSetup(
     const protocol_ctxt_t        *const ctxt_pP,
     rrc_gNB_ue_context_t         *const ue_context_pP,
-    OCTET_STRING_t               *masterCellGroup_from_DU,
-    NR_ServingCellConfigCommon_t *scc,
-    const int                    CC_id);
+    const uint8_t                *masterCellGroup,
+    int                           masterCellGroup_len,
+    NR_ServingCellConfigCommon_t *scc);
 
 int parse_CG_ConfigInfo(gNB_RRC_INST *rrc, NR_CG_ConfigInfo_t *CG_ConfigInfo, x2ap_ENDC_sgnb_addition_req_t *m);
 
@@ -174,17 +174,6 @@ int8_t nr_mac_rrc_bwp_switch_req(const module_id_t     module_idP,
                                  const int             dl_bwp_id,
                                  const int             ul_bwp_id);
 
-int8_t nr_mac_rrc_data_ind(const module_id_t     module_idP,
-                           const int             CC_id,
-                           const frame_t         frameP,
-                           const sub_frame_t     sub_frameP,
-                           const int             UE_id,
-                           const rnti_t          rntiP,
-                           const rb_id_t         srb_idP,
-                           const uint8_t        *sduP,
-                           const sdu_size_t      sdu_lenP,
-                           const bool            brOption);
-
 int nr_rrc_reconfiguration_req(rrc_gNB_ue_context_t         *const ue_context_pP,
                                protocol_ctxt_t              *const ctxt_pP,
                                const int                    dl_bwp_id,
@@ -193,8 +182,8 @@ int nr_rrc_reconfiguration_req(rrc_gNB_ue_context_t         *const ue_context_pP
 int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
                            const uint8_t      *buffer,
                            int                buffer_length,
-                           OCTET_STRING_t     *du_to_cu_rrc_container,
-                           const int          CC_id);
+                           const uint8_t      *du_to_cu_rrc_container,
+                           int                du_to_cu_rrc_container_length);
 
 void
 rrc_gNB_generate_dedicatedRRCReconfiguration_release(
diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c
index 1904f294327..450084ab03c 100755
--- a/openair2/RRC/NR/rrc_gNB.c
+++ b/openair2/RRC/NR/rrc_gNB.c
@@ -339,10 +339,9 @@ void
 rrc_gNB_generate_RRCSetup(
     const protocol_ctxt_t        *const ctxt_pP,
     rrc_gNB_ue_context_t         *const ue_context_pP,
-    OCTET_STRING_t               *masterCellGroup_from_DU,
-    NR_ServingCellConfigCommon_t *scc,
-    const int                    CC_id
-)
+    const uint8_t                *masterCellGroup,
+    int                           masterCellGroup_len,
+    NR_ServingCellConfigCommon_t *scc)
 //-----------------------------------------------------------------------------
 {
   LOG_I(NR_RRC, "rrc_gNB_generate_RRCSetup for RNTI %04x\n", ctxt_pP->rnti);
@@ -355,16 +354,15 @@ rrc_gNB_generate_RRCSetup(
 
   gNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context;
   gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id];
-  NR_ServingCellConfig_t *servingcellconfigdedicated = rrc->configuration.scd;
-  int16_t ret = do_RRCSetup(ue_context_pP,
-                            (uint8_t *) ue_p->Srb0.Tx_buffer.Payload,
-                            rrc_gNB_get_next_transaction_identifier(ctxt_pP->module_id),
-                            masterCellGroup_from_DU,
-                            scc,servingcellconfigdedicated,&rrc->configuration);
-
-  AssertFatal(ret>0,"Error generating RRCSetup for RRCSetupRequest\n");
-
-  ue_p->Srb0.Tx_buffer.payload_size = ret;
+  const NR_ServingCellConfig_t *sccd = rrc->configuration.scd;
+  ue_p->Srb0.Tx_buffer.payload_size = do_RRCSetup(ue_context_pP,
+                                                  (uint8_t *) ue_p->Srb0.Tx_buffer.Payload,
+                                                  rrc_gNB_get_next_transaction_identifier(ctxt_pP->module_id),
+                                                  masterCellGroup,
+                                                  masterCellGroup_len,
+                                                  scc,
+                                                  sccd,
+                                                  &rrc->configuration);
 
   LOG_DUMPMSG(NR_RRC, DEBUG_RRC,
               (char *)(ue_p->Srb0.Tx_buffer.Payload),
@@ -400,8 +398,8 @@ rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(
   LOG_I(NR_RRC, "generate RRCSetup for RRCReestablishmentRequest \n");
   rrc_gNB_ue_context_t         *ue_context_pP   = NULL;
   gNB_RRC_INST                 *rrc_instance_p = RC.nrrrc[ctxt_pP->module_id];
-  NR_ServingCellConfigCommon_t *scc=rrc_instance_p->carrier.servingcellconfigcommon;
-  NR_ServingCellConfig_t       *servingcellconfigdedicated = rrc_instance_p->configuration.scd;
+  const NR_ServingCellConfigCommon_t *scc=rrc_instance_p->carrier.servingcellconfigcommon;
+  const NR_ServingCellConfig_t       *sccd = rrc_instance_p->configuration.scd;
 
   ue_context_pP = rrc_gNB_get_next_free_ue_context(ctxt_pP, rrc_instance_p, 0);
 
@@ -410,7 +408,10 @@ rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(
                             (uint8_t *) ue_p->Srb0.Tx_buffer.Payload,
                             rrc_gNB_get_next_transaction_identifier(ctxt_pP->module_id),
                             NULL,
-                            scc,servingcellconfigdedicated,&rrc_instance_p->configuration);
+                            0,
+                            scc,
+                            sccd,
+                            &rrc_instance_p->configuration);
 
   AssertFatal(ret>0,"Error generating RRCSetup for RRCReestablishmentRequest\n");
 
@@ -452,9 +453,7 @@ rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(
 void
 rrc_gNB_generate_RRCReject(
     const protocol_ctxt_t    *const ctxt_pP,
-    rrc_gNB_ue_context_t     *const ue_context_pP,
-    const int                CC_id
-)
+    rrc_gNB_ue_context_t     *const ue_context_pP)
 //-----------------------------------------------------------------------------
 {
   LOG_I(NR_RRC, "rrc_gNB_generate_RRCReject \n");
@@ -1858,8 +1857,8 @@ int nr_rrc_reconfiguration_req(rrc_gNB_ue_context_t         *const ue_context_pP
 int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
                            const uint8_t      *buffer,
                            int                buffer_length,
-                           OCTET_STRING_t     *du_to_cu_rrc_container,
-                           const int          CC_id)
+                           const uint8_t      *du_to_cu_rrc_container,
+                           int                du_to_cu_rrc_container_len)
 {
   module_id_t                                       Idx;
   asn_dec_rval_t                                    dec_rval;
@@ -1869,22 +1868,16 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
   NR_RRCSetupRequest_IEs_t                         *rrcSetupRequest = NULL;
   NR_RRCReestablishmentRequest_IEs_t                rrcReestablishmentRequest;
   uint64_t                                          random_value = 0;
-  int i;
 
-    dec_rval = uper_decode( NULL,
-                            &asn_DEF_NR_UL_CCCH_Message,
-                            (void **)&ul_ccch_msg,
-                            (uint8_t *) buffer,
-                            100,
-                            0,
-                            0);
+  LOG_I(NR_RRC, "Decoding CCCH: RNTI %04x, inst %ld, payload_size %d\n", ctxt_pP->rnti, ctxt_pP->instance, buffer_length);
+  dec_rval = uper_decode(NULL, &asn_DEF_NR_UL_CCCH_Message, (void **) &ul_ccch_msg, buffer, buffer_length, 0, 0);
 
-    if (dec_rval.consumed == 0) {
-        /* TODO */
-        LOG_E(NR_RRC, PROTOCOL_NR_RRC_CTXT_UE_FMT" FATAL Error in receiving CCCH\n",
-                   PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP));
-        return -1;
-    }
+  if (dec_rval.code != RC_OK || dec_rval.consumed == 0) {
+    LOG_E(NR_RRC,
+          PROTOCOL_NR_RRC_CTXT_UE_FMT" FATAL Error in receiving CCCH\n",
+          PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP));
+    return -1;
+  }
 
     if (ul_ccch_msg->message.present == NR_UL_CCCH_MessageType_PR_c1) {
      switch (ul_ccch_msg->message.choice.c1->present) {
@@ -1990,8 +1983,7 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
                     PROTOCOL_NR_RRC_CTXT_UE_FMT" RRCSetupRequest without random UE identity or S-TMSI not supported, let's reject the UE\n",
                     PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP));
             rrc_gNB_generate_RRCReject(ctxt_pP,
-                                       rrc_gNB_get_ue_context(gnb_rrc_inst, ctxt_pP->rnti),
-                                       CC_id);
+                                       rrc_gNB_get_ue_context(gnb_rrc_inst, ctxt_pP->rnti));
             break;
           }
 
@@ -2000,8 +1992,8 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
           rrc_gNB_generate_RRCSetup(ctxt_pP,
                                     rrc_gNB_get_ue_context(gnb_rrc_inst, ctxt_pP->rnti),
                                     du_to_cu_rrc_container,
-                                    gnb_rrc_inst->carrier.servingcellconfigcommon,
-                                    CC_id);
+                                    du_to_cu_rrc_container_len,
+                                    gnb_rrc_inst->carrier.servingcellconfigcommon);
         }
         break;
 
@@ -2033,13 +2025,13 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
                   PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),
                   rrcReestablishmentRequest.ue_Identity.physCellId,
                   RC.nrrrc[ctxt_pP->module_id]->carrier.physCellId);
-            rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(ctxt_pP, CC_id);
+            rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(ctxt_pP, 0);
             break;
           }
 
           LOG_D(NR_RRC, "physCellId is %ld\n", rrcReestablishmentRequest.ue_Identity.physCellId);
 
-          for (i = 0; i < rrcReestablishmentRequest.ue_Identity.shortMAC_I.size; i++) {
+          for (int i = 0; i < rrcReestablishmentRequest.ue_Identity.shortMAC_I.size; i++) {
             LOG_D(NR_RRC, "rrcReestablishmentRequest.ue_Identity.shortMAC_I.buf[%d] = %x\n",
                   i, rrcReestablishmentRequest.ue_Identity.shortMAC_I.buf[i]);
           }
@@ -2050,7 +2042,7 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
             LOG_E(NR_RRC,
                   PROTOCOL_NR_RRC_CTXT_UE_FMT" NR_RRCReestablishmentRequest c_RNTI range error, fallback to RRC establishment\n",
                   PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP));
-            rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(ctxt_pP, CC_id);
+            rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(ctxt_pP, 0);
             break;
           }
 
@@ -2062,7 +2054,7 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
             LOG_E(NR_RRC,
                   PROTOCOL_NR_RRC_CTXT_UE_FMT" NR_RRCReestablishmentRequest without UE context, fallback to RRC establishment\n",
                   PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP));
-            rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(ctxt_pP, CC_id);
+            rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(ctxt_pP, 0);
             break;
           }
 #if(0)
@@ -2073,14 +2065,14 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
             LOG_E(NR_RRC,
                   PROTOCOL_NR_RRC_CTXT_UE_FMT" NR_RRCReestablishmentRequest without UE_id(MAC) rnti %x, fallback to RRC establishment\n",
                   PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),c_rnti);
-            rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(ctxt_pP, CC_id);
+            rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(ctxt_pP, 0);
             break;
           }
 
           //previous rnti
           rnti_t previous_rnti = 0;
 
-          for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
+          for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
             if (reestablish_rnti_map[i][1] == c_rnti) {
               previous_rnti = reestablish_rnti_map[i][0];
               break;
@@ -2094,7 +2086,7 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
               LOG_E(NR_RRC,
                     PROTOCOL_NR_RRC_CTXT_UE_FMT" RRCReestablishmentRequest without UE_id(MAC) previous rnti %x, fallback to RRC establishment\n",
                     PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),previous_rnti);
-              rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(ctxt_pP, CC_id);
+              rrc_gNB_generate_RRCSetup_for_RRCReestablishmentRequest(ctxt_pP, 0);
               break;
             }
           }
@@ -2148,7 +2140,7 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
           ue_context_p->ue_context.reestablishment_xid = -1;
 
           // insert C-RNTI to map
-          for (i = 0; i < MAX_MOBILES_PER_ENB; i++) {
+          for (int i = 0; i < MAX_MOBILES_PER_ENB; i++) {
             if (reestablish_rnti_map[i][0] == 0) {
               reestablish_rnti_map[i][0] = ctxt_pP->rnti;
               reestablish_rnti_map[i][1] = c_rnti;
@@ -2164,7 +2156,7 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
                 rrcReestablishmentRequest.ue_Identity.physCellId,
                 ue_context_p->ue_context.reestablishment_cause);
 
-          ue_context_p->ue_context.primaryCC_id = CC_id;
+          ue_context_p->ue_context.primaryCC_id = 0;
           //LG COMMENT Idx = (ue_mod_idP * NB_RB_MAX) + DCCH;
           Idx = DCCH;
           // SRB1
@@ -2186,7 +2178,7 @@ int nr_rrc_gNB_decode_ccch(protocol_ctxt_t    *const ctxt_pP,
                 &DCCH_LCHAN_DESC,
                 LCHAN_DESC_SIZE);
 
-          rrc_gNB_generate_RRCReestablishment(ctxt_pP, ue_context_p, CC_id);
+          rrc_gNB_generate_RRCReestablishment(ctxt_pP, ue_context_p, 0);
 
           LOG_I(NR_RRC, PROTOCOL_NR_RRC_CTXT_UE_FMT"CALLING RLC CONFIG SRB1 (rbid %d)\n",
                 PROTOCOL_NR_RRC_CTXT_UE_ARGS(ctxt_pP),
@@ -2878,6 +2870,38 @@ void rrc_gNB_process_f1_setup_req(f1ap_setup_req_t *f1_setup_req) {
   }//for (int i=0;i<f1_setup_req->num_cells_available;i++)
 }
 
+void rrc_gNB_process_initial_ul_rrc_message(const f1ap_initial_ul_rrc_message_t *ul_rrc)
+{
+  // first get RRC instance (note, no the ITTI instance)
+  module_id_t i = 0;
+  for (i=0; i < RC.nb_nr_inst; i++) {
+    gNB_RRC_INST *rrc = RC.nrrrc[i];
+    if (rrc->nr_cellid == ul_rrc->nr_cellid)
+      break;
+  }
+  //AssertFatal(i != RC.nb_nr_inst, "Cell_id not found\n");
+  // TODO REMOVE_DU_RRC in monolithic mode, the MAC does not have the
+  // nr_cellid. Thus, the above check would fail. For the time being, just put
+  // a warning, as we handle one DU only anyway
+  if (i == RC.nb_nr_inst) {
+    i = 0;
+    LOG_W(RRC, "initial UL RRC message nr_cellid %ld does not match RRC's %ld\n", ul_rrc->nr_cellid, RC.nrrrc[0]->nr_cellid);
+  }
+  protocol_ctxt_t ctxt = { 0 };
+  PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, i, GNB_FLAG_YES, ul_rrc->crnti, 0, 0);
+
+  nr_rrc_gNB_decode_ccch(&ctxt,
+                         ul_rrc->rrc_container,
+                         ul_rrc->rrc_container_length,
+                         ul_rrc->du2cu_rrc_container,
+                         ul_rrc->du2cu_rrc_container_length);
+
+  if (ul_rrc->rrc_container)
+    free(ul_rrc->rrc_container);
+  if (ul_rrc->du2cu_rrc_container)
+    free(ul_rrc->du2cu_rrc_container);
+}
+
 void rrc_gNB_process_release_request(const module_id_t gnb_mod_idP, x2ap_ENDC_sgnb_release_request_t *m)
 {
   gNB_RRC_INST *rrc = RC.nrrrc[gnb_mod_idP];
@@ -3885,49 +3909,11 @@ void *rrc_gnb_task(void *args_p) {
         nr_rrc_subframe_process(&RRC_SUBFRAME_PROCESS(msg_p).ctxt, RRC_SUBFRAME_PROCESS(msg_p).CC_id);
         break;
 
-      /* Messages from MAC */
-      case NR_RRC_MAC_CCCH_DATA_IND:
-	{
-	  instance_t i;
-	  for (i=0; i<RC.nb_nr_inst; i++) {
-	    // first get RRC instance (note, no the ITTI instance)
-	    gNB_RRC_INST *rrc = RC.nrrrc[i];
-	    
-	    if (rrc->nr_cellid == NR_RRC_MAC_CCCH_DATA_IND(msg_p).nr_cellid)
-	      break;
-	  }
-	  AssertFatal(i!=RC.nb_nr_inst, "Cell_id not found\n");
-	  PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
-					i,
-					GNB_FLAG_YES,
-					NR_RRC_MAC_CCCH_DATA_IND(msg_p).rnti,
-					msg_p->ittiMsgHeader.lte_time.frame,
-					msg_p->ittiMsgHeader.lte_time.slot);
-	  LOG_I(NR_RRC,"Decoding CCCH : ue %d, inst %ld, CC_id %d, ctxt %p, sib_info_p->Rx_buffer.payload_size %d\n",
-		ctxt.rnti,
-		i,
-		NR_RRC_MAC_CCCH_DATA_IND(msg_p).CC_id,
-		&ctxt,
-		NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
-	  
-	  if (NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size >= CCCH_SDU_SIZE) {
-	    LOG_I(NR_RRC, "CCCH message has size %d > %d\n",
-		  NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,CCCH_SDU_SIZE);
-	    break;
-	  }
-
-	  nr_rrc_gNB_decode_ccch(&ctxt,
-				 (uint8_t *)NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu,
-				 NR_RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size,
-				 NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container,
-				 NR_RRC_MAC_CCCH_DATA_IND(msg_p).CC_id);
-	  
-	  if (NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container) {
-	    free(NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container->buf);
-	    free(NR_RRC_MAC_CCCH_DATA_IND(msg_p).du_to_cu_rrc_container);
-	  }
-	}
-      break;
+      case F1AP_INITIAL_UL_RRC_MESSAGE:
+        AssertFatal(NODE_IS_CU(RC.nrrrc[instance]->node_type) || NODE_IS_MONOLITHIC(RC.nrrrc[instance]->node_type),
+                    "should not receive F1AP_INITIAL_UL_RRC_MESSAGE, need call by CU!\n");
+        rrc_gNB_process_initial_ul_rrc_message(&F1AP_INITIAL_UL_RRC_MESSAGE(msg_p));
+        break;
 
       /* Messages from PDCP */
       case NR_RRC_DCCH_DATA_IND:
diff --git a/openair2/RRC/NR/rrc_gNB_reconfig.c b/openair2/RRC/NR/rrc_gNB_reconfig.c
index 2ee3a26c4b0..08baeb3d454 100644
--- a/openair2/RRC/NR/rrc_gNB_reconfig.c
+++ b/openair2/RRC/NR/rrc_gNB_reconfig.c
@@ -82,9 +82,9 @@ void fix_servingcellconfigdedicated(NR_ServingCellConfig_t *scd) {
 
 void fill_default_nsa_downlinkBWP(NR_BWP_Downlink_t *bwp,
                                   long bwp_loop,
-                                  NR_CellGroupConfig_t *secondaryCellGroup,
-                                  NR_ServingCellConfig_t *servingcellconfigdedicated,
-                                  NR_ServingCellConfigCommon_t *servingcellconfigcommon,
+                                  const NR_CellGroupConfig_t *secondaryCellGroup,
+                                  const NR_ServingCellConfig_t *servingcellconfigdedicated,
+                                  const NR_ServingCellConfigCommon_t *servingcellconfigcommon,
                                   const gNB_RrcConfigurationReq *configuration,
                                   NR_UE_NR_Capability_t *uecap,
                                   int dl_antenna_ports,
-- 
GitLab