From eedc4226f06bb1d1427faa49cdeed8ccb13467ca Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Sat, 15 Sep 2018 22:42:10 +0200
Subject: [PATCH] modifications for SRB0 to allow multiple UE contexts in case
 of delayed CCCH reception in CU/DU split (moved SRB0 from carrier to UE
 context)

---
 openair2/LAYER2/MAC/eNB_scheduler_RA.c        |  34 ++---
 openair2/LAYER2/MAC/eNB_scheduler_bch.c       |   8 +-
 openair2/LAYER2/MAC/eNB_scheduler_dlsch.c     |  10 +-
 openair2/LAYER2/MAC/eNB_scheduler_mch.c       |   2 +-
 .../L2_INTERFACE/openair_rrc_L2_interface.h   |   1 +
 openair2/RRC/LTE/L2_interface.c               |  33 +++--
 openair2/RRC/LTE/rrc_defs.h                   |   1 -
 openair2/RRC/LTE/rrc_eNB.c                    | 121 ++++++++++--------
 openair2/RRC/LTE/rrc_proto.h                  |  17 ++-
 9 files changed, 122 insertions(+), 105 deletions(-)

diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index 3dbce03d04..3309ba7b9f 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -831,21 +831,22 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
 	        // Get RRCConnectionSetup for Piggyback
 	        /*rrc_sdu_length = mac_rrc_data_req(module_idP, CC_idP, frameP, CCCH, 1,	// 1 transport block
 	    				      &cc[CC_idP].CCCH_pdu.payload[0], ENB_FLAG_YES, module_idP, 0);	// not used in this case*/
-
-	    	rrc_sdu_length = mac_rrc_data_req(module_idP, CC_idP, frameP, CCCH, 1,	// 1 transport block
-	    					      &cc[CC_idP].CCCH_pdu.payload[0], 0);	// not used in this case
-
-	        LOG_D(MAC,
-	        	  "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: UE_id %d, rrc_sdu_length %d\n",
-	        	  module_idP, CC_idP, frameP, subframeP, UE_id, rrc_sdu_length);
-
-	        AssertFatal(rrc_sdu_length > 0,
-	    		"[MAC][eNB Scheduler] CCCH not allocated\n");
-
-		LOG_D(MAC,
-		      "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating Msg4 BR with RRC Piggyback (ce_level %d RNTI %x)\n",
-		      module_idP, CC_idP, frameP, subframeP,
-		      ra->rach_resource_type - 1, ra->rnti);
+	      
+	      rrc_sdu_length = mac_rrc_data_req(module_idP, CC_idP, frameP, CCCH, 
+						UE_RNTI(module_idP,UE_id),1,	// 1 transport block
+						&cc[CC_idP].CCCH_pdu.payload[0], 0);	// not used in this case
+	      
+	      LOG_D(MAC,
+		    "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: UE_id %d, rrc_sdu_length %d\n",
+		    module_idP, CC_idP, frameP, subframeP, UE_id, rrc_sdu_length);
+	      
+	      AssertFatal(rrc_sdu_length > 0,
+			  "[MAC][eNB Scheduler] CCCH not allocated\n");
+	      
+	      LOG_D(MAC,
+		    "[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating Msg4 BR with RRC Piggyback (ce_level %d RNTI %x)\n",
+		    module_idP, CC_idP, frameP, subframeP,
+		    ra->rach_resource_type - 1, ra->rnti);
 
 		AssertFatal(1 == 0,
 			    "Msg4 generation not finished for BL/CE UE\n");
@@ -1017,7 +1018,8 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
     					      &cc[CC_idP].CCCH_pdu.payload[0], ENB_FLAG_YES, module_idP, 0);	// not used in this case*/
 
 	  // check if there's data on the CCCH to send with Msg4
-	  rrc_sdu_length = mac_rrc_data_req(module_idP, CC_idP, frameP, CCCH, 1,	// 1 transport block
+	  rrc_sdu_length = mac_rrc_data_req(module_idP, CC_idP, frameP, CCCH, 
+					    UE_RNTI(module_idP,UE_id),1,	// 1 transport block
 					    &cc[CC_idP].CCCH_pdu.payload[0], 0);	// not used in this case
 	  
 	  LOG_D(MAC,
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_bch.c b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
index b2b59691f8..b88a58ec7c 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_bch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
@@ -193,7 +193,7 @@ schedule_SIB1_BR(module_id_t module_idP,
 	n_NB = Sj[((cc->physCellId % N_S_NB) + (i * N_S_NB / m)) % N_S_NB];
 
 
-	bcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, BCCH_SIB1_BR, 1, &cc->BCCH_BR_pdu[0].payload[0], 0);	// not used in this case
+	bcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, BCCH_SIB1_BR, 0xFFFF, 1, &cc->BCCH_BR_pdu[0].payload[0], 0);	// not used in this case
 
 	AssertFatal(cc->mib->message.schedulingInfoSIB1_BR_r13 < 19,
 		    "schedulingInfoSIB1_BR_r13 %d > 18\n",
@@ -382,7 +382,7 @@ schedule_SI_BR(module_id_t module_idP, frame_t frameP,
 		if ((sf_mod_period < si_WindowLength_BR_r13)
 		    && ((frameP & (((1 << si_RepetitionPattern_r13) - 1))) == 0)) {	// this SIB is to be scheduled
 
-		    bcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, BCCH_SI_BR + i, 1, &cc->BCCH_BR_pdu[i + 1].payload[0], 0);	// not used in this case
+		  bcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, BCCH_SI_BR + i, 0xFFFF, 1, &cc->BCCH_BR_pdu[i + 1].payload[0], 0);	// not used in this case
 
 		    AssertFatal(bcch_sdu_length > 0,
 				"RRC returned 0 bytes for SI-BR %d\n", i);
@@ -524,7 +524,7 @@ schedule_mib(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 	dl_req = &dl_config_request->dl_config_request_body;
 	cc = &eNB->common_channels[CC_id];
 
-	mib_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, MIBCH, 1, &cc->MIB_pdu.payload[0], 0);	// not used in this case
+	mib_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, MIBCH, 0xFFFF, 1, &cc->MIB_pdu.payload[0], 0);	// not used in this case
 
 	LOG_D(MAC, "Frame %d, subframe %d: BCH PDU length %d\n", frameP, subframeP, mib_sdu_length);
 
@@ -611,7 +611,7 @@ schedule_SI(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 	    dl_req = &eNB->DL_req[CC_id].dl_config_request_body;
 
 
-	    bcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, BCCH, 1, &cc->BCCH_pdu.payload[0], 0);	// not used in this case
+	    bcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, BCCH, 0xFFFF,1, &cc->BCCH_pdu.payload[0], 0);	// not used in this case
 
 	    if (bcch_sdu_length > 0) {
 		LOG_D(MAC, "[eNB %d] Frame %d : BCCH->DLSCH CC_id %d, Received %d bytes \n", module_idP, frameP, CC_id, bcch_sdu_length);
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
index da52a8fedc..938e6b304b 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
@@ -731,10 +731,14 @@ schedule_ue_spec(module_id_t module_idP,slice_id_t slice_idP,
 	  aggregation = 2;
 	}
       }
+      int ccecond = CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP,
+					      aggregation, rnti);
+      if (!ccecond) {
+	// check for CCCH
+      }
       /* if (continue_flag != 1 */
       if ((ue_sched_ctl->pre_nb_available_rbs[CC_id] == 0) ||	// no RBs allocated
-	  CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP,
-				    aggregation, rnti)) {
+	  ccecond) {
 	LOG_D(MAC,
 	      "[eNB %d] Frame %d : no RB allocated for UE %d on CC_id %d: continue \n",
 	      module_idP, frameP, UE_id, CC_id);
@@ -1836,7 +1840,7 @@ void schedule_PCH(module_id_t module_idP,frame_t frameP,sub_frame_t subframeP)
 	pcch_sdu_length = mac_rrc_data_req(module_idP,
                                            CC_id,
                                            frameP,
-                                           PCCH,1,
+                                           PCCH,0xFFFE,1,
                                            &cc->PCCH_pdu.payload[0],
                                            i); // used for ue index
 	if (pcch_sdu_length == 0) {
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_mch.c b/openair2/LAYER2/MAC/eNB_scheduler_mch.c
index 16953e958a..da2b19dee6 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_mch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_mch.c
@@ -542,7 +542,7 @@ schedule_MBMS(module_id_t module_idP, uint8_t CC_id, frame_t frameP,
 	      "[eNB %d] CC_id %d Frame %d Subframe %d: Schedule MCCH MESSAGE (area %d, sfAlloc %d)\n",
 	      module_idP, CC_id, frameP, subframeP, i, j);
 
-	mcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, MCCH, 1, &cc->MCCH_pdu.payload[0], 
+	mcch_sdu_length = mac_rrc_data_req(module_idP, CC_id, frameP, MCCH, 0xFFFC, 1, &cc->MCCH_pdu.payload[0], 
 					   i);	// this is the mbsfn sync area index
 
 	if (mcch_sdu_length > 0) {
diff --git a/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.h b/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.h
index f01721e182..6b7502d50d 100644
--- a/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.h
+++ b/openair2/RRC/L2_INTERFACE/openair_rrc_L2_interface.h
@@ -39,6 +39,7 @@ mac_rrc_data_req(
   const int             CC_idP,
   const frame_t         frameP,
   const rb_id_t         srb_idP,
+  const rnti_t          rntiP,
   const uint8_t         nb_tbP,
   uint8_t* const        buffer_pP,
   const uint8_t         mbsfn_sync_areaP
diff --git a/openair2/RRC/LTE/L2_interface.c b/openair2/RRC/LTE/L2_interface.c
index 9ce6a5d52f..ed7e0c4d01 100644
--- a/openair2/RRC/LTE/L2_interface.c
+++ b/openair2/RRC/LTE/L2_interface.c
@@ -53,6 +53,7 @@ mac_rrc_data_req(
   const int         CC_id,
   const frame_t     frameP,
   const rb_id_t     Srb_id,
+  const rnti_t      rnti,
   const uint8_t     Nb_tb,
   uint8_t*    const buffer_pP,
   const uint8_t     mbsfn_sync_area
@@ -105,9 +106,6 @@ mac_rrc_data_req(
         return (RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1);
       } // All RFN mod 8 transmit SIB2-3 in SF 5
       else if ((frameP%8) == 1) {
-	LOG_I(RRC,"Copying SIB23 @ %p to mac %d bytes\n",
-	      RC.rrc[Mod_idP]->carrier[CC_id].SIB23,
-	      RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23);
         memcpy(&buffer_pP[0],
                RC.rrc[Mod_idP]->carrier[CC_id].SIB23,
                RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB23);
@@ -144,14 +142,19 @@ mac_rrc_data_req(
     }
 
     if( (Srb_id & RAB_OFFSET ) == CCCH) {
-      LOG_T(RRC,"[eNB %d] Frame %d CCCH request (Srb_id %d)\n",Mod_idP,frameP, Srb_id);
 
-      if(RC.rrc[Mod_idP]->carrier[CC_id].Srb0.Active==0) {
+      struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(RC.rrc[Mod_idP],rnti);
+      
+      if (ue_context_p == NULL) return(0);
+      eNB_RRC_UE_t *ue_p = &ue_context_p->ue_context; 
+      LOG_T(RRC,"[eNB %d] Frame %d CCCH request (Srb_id %d, rnti %x)\n",Mod_idP,frameP, Srb_id,rnti);
+
+      if(ue_p->Srb0.Active==0) {
         LOG_E(RRC,"[eNB %d] CCCH Not active\n",Mod_idP);
-        return -1;
+        return(0);
       }
 
-      Srb_info=&RC.rrc[Mod_idP]->carrier[CC_id].Srb0;
+      Srb_info=&ue_p->Srb0;
 
       // check if data is there for MAC
       if(Srb_info->Tx_buffer.payload_size>0) { //Fill buffer
@@ -300,18 +303,14 @@ mac_rrc_data_ind(
    */
   PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, rntiP, frameP, sub_frameP,0);
 
-    if((srb_idP & RAB_OFFSET) == CCCH) {
-    Srb_info = &RC.rrc[module_idP]->carrier[CC_id].Srb0;
-    LOG_D(RRC,"[eNB %d] Received SDU for CCCH on SRB %d\n",module_idP,Srb_info->Srb_id);
+  if((srb_idP & RAB_OFFSET) == CCCH) {
+    LOG_D(RRC,"[eNB %d] Received SDU for CCCH on SRB 0\n",module_idP);
     
     //    msg("\n******INST %d Srb_info %p, Srb_id=%d****\n\n",Mod_id,Srb_info,Srb_info->Srb_id);
-    if (sdu_lenP > 0) {
-      memcpy(Srb_info->Rx_buffer.Payload,sduP,sdu_lenP);
-      Srb_info->Rx_buffer.payload_size = sdu_lenP;
-      rrc_eNB_decode_ccch(&ctxt, Srb_info, CC_id);
-    }
-    }
-    if((srb_idP & RAB_OFFSET) == DCCH) {
+    if (sdu_lenP > 0)  rrc_eNB_decode_ccch(&ctxt, sduP, sdu_lenP, CC_id);
+    
+  }
+  if((srb_idP & RAB_OFFSET) == DCCH) {
       struct rrc_eNB_ue_context_s*    ue_context_p = NULL;
       ue_context_p = rrc_eNB_get_ue_context(RC.rrc[ctxt.module_id],rntiP);
       if(ue_context_p){
diff --git a/openair2/RRC/LTE/rrc_defs.h b/openair2/RRC/LTE/rrc_defs.h
index 8464e11913..ad7d2f31f6 100644
--- a/openair2/RRC/LTE/rrc_defs.h
+++ b/openair2/RRC/LTE/rrc_defs.h
@@ -671,7 +671,6 @@ typedef struct {
   SystemInformationBlockType21_r14_t *sib21;
   // End - TTN
   SRB_INFO                          SI;
-  SRB_INFO                          Srb0;
   uint8_t                           *paging[MAX_MOBILES_PER_ENB];
   uint32_t                           sizeof_paging[MAX_MOBILES_PER_ENB];
 } rrc_eNB_carrier_data_t;
diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c
index f8775acb75..1f5cd605ba 100644
--- a/openair2/RRC/LTE/rrc_eNB.c
+++ b/openair2/RRC/LTE/rrc_eNB.c
@@ -131,8 +131,8 @@ openair_rrc_on(
     for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
       rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI, BCCH, 1);
       RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SI.Active = 1;
-      rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0, CCCH, 1);
-      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Active = 1;
+      //      rrc_config_buffer (&RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0, CCCH, 1);
+      //      RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Active = 1;
     }
 }
 
@@ -1224,29 +1224,30 @@ rrc_eNB_generate_RRCConnectionReject(
   T(T_ENB_RRC_CONNECTION_REJECT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
-  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size =
+  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 
+  ue_p->Srb0.Tx_buffer.payload_size =
     do_RRCConnectionReject(ctxt_pP->module_id,
-                          (uint8_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload);
+                          (uint8_t*) ue_p->Srb0.Tx_buffer.Payload);
 
   LOG_DUMPMSG(RRC,DEBUG_RRC,
-              (char *)(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload),
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
+              (char *)(ue_p->Srb0.Tx_buffer.Payload),
+	      ue_p->Srb0.Tx_buffer.payload_size,
               "[MSG] RRCConnectionReject\n");
 
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Header,
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
+    ue_p->Srb0.Tx_buffer.Header,
+    ue_p->Srb0.Tx_buffer.payload_size,
     MSC_AS_TIME_FMT" RRCConnectionReject UE %x size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP == NULL ? -1 : ue_context_pP->ue_context.rnti,
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
+    ue_p->Srb0.Tx_buffer.payload_size);
 
   LOG_I(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReject (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
+        ue_p->Srb0.Tx_buffer.payload_size);
 }
 
 //-----------------------------------------------------------------------------
@@ -1266,19 +1267,22 @@ rrc_eNB_generate_RRCConnectionReestablishment(
   T(T_ENB_RRC_CONNECTION_REESTABLISHMENT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
-  SRB_configList = &ue_context_pP->ue_context.SRB_configList;
-  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size =
+  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 
+
+  SRB_configList = &ue_p->SRB_configList;
+
+  ue_p->Srb0.Tx_buffer.payload_size =
     do_RRCConnectionReestablishment(ctxt_pP,
                                     ue_context_pP,
                                     CC_id,
-                                    (uint8_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload,
+                                    (uint8_t*) ue_p->Srb0.Tx_buffer.Payload,
                                     (uint8_t) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB, //at this point we do not have the UE capability information, so it can only be TM1 or TM2
                                     rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
                                     SRB_configList,
                                     &ue_context_pP->ue_context.physicalConfigDedicated);
   LOG_DUMPMSG(RRC,DEBUG_RRC,
-              (char *)(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload),
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
+              (char *)(ue_p->Srb0.Tx_buffer.Payload),
+              ue_p->Srb0.Tx_buffer.payload_size,
               "[MSG] RRCConnectionReestablishment\n"
               );
   // configure SRB1 for UE
@@ -1342,17 +1346,17 @@ rrc_eNB_generate_RRCConnectionReestablishment(
 
   MSC_LOG_TX_MESSAGE(MSC_RRC_ENB,
                      MSC_RRC_UE,
-                     RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Header,
-                     RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
+                     ue_p->Srb0.Tx_buffer.Header,
+                     ue_p->Srb0.Tx_buffer.payload_size,
                      MSC_AS_TIME_FMT" RRCConnectionReestablishment UE %x size %u",
                      MSC_AS_TIME_ARGS(ctxt_pP),
                      ue_context_pP->ue_context.rnti,
-                     RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
+                     ue_p->Srb0.Tx_buffer.payload_size);
 
   LOG_I(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReestablishment (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
+        ue_p->Srb0.Tx_buffer.payload_size);
 
   int UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti);
   if(UE_id != -1){
@@ -2022,30 +2026,32 @@ rrc_eNB_generate_RRCConnectionReestablishmentReject(
   T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_REJECT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
-  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size =
+  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 
+
+  ue_p->Srb0.Tx_buffer.payload_size =
     do_RRCConnectionReestablishmentReject(ctxt_pP->module_id,
-                          (uint8_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload);
+                          (uint8_t*) ue_p->Srb0.Tx_buffer.Payload);
 
   LOG_DUMPMSG(RRC,DEBUG_RRC,
-              (char *)(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload),
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
+              (char *)(ue_p->Srb0.Tx_buffer.Payload),
+              ue_p->Srb0.Tx_buffer.payload_size,
               "[MSG] RRCConnectionReestablishmentReject\n");
 
 
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Header,
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
+    ue_p->Srb0.Tx_buffer.Header,
+    ue_p->Srb0.Tx_buffer.payload_size,
     MSC_AS_TIME_FMT" RRCConnectionReestablishmentReject UE %x size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP == NULL ? -1 : ue_context_pP->ue_context.rnti,
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
+    ue_p->Srb0.Tx_buffer.payload_size);
 
   LOG_I(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionReestablishmentReject (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
+        ue_p->Srb0.Tx_buffer.payload_size);
 }
 
 //-----------------------------------------------------------------------------
@@ -5732,20 +5738,22 @@ rrc_eNB_generate_RRCConnectionSetup(
   T(T_ENB_RRC_CONNECTION_SETUP, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
     T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
-  SRB_configList = &ue_context_pP->ue_context.SRB_configList;
-  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size =
+  eNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; 
+
+  SRB_configList = &ue_p->SRB_configList;
+  ue_p->Srb0.Tx_buffer.payload_size =
     do_RRCConnectionSetup(ctxt_pP,
                           ue_context_pP,
                           CC_id,
-                          (uint8_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload,
+                          (uint8_t*) ue_p->Srb0.Tx_buffer.Payload,
 			  (uint8_t) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB, //at this point we do not have the UE capability information, so it can only be TM1 or TM2
                           rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),
                           SRB_configList,
                           &ue_context_pP->ue_context.physicalConfigDedicated);
 
   LOG_DUMPMSG(RRC,DEBUG_RRC,
-              (char *)(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Payload),
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
+              (char *)(ue_p->Srb0.Tx_buffer.Payload),
+              ue_p->Srb0.Tx_buffer.payload_size,
               "[MSG] RRC Connection Setup\n");
 
   // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE
@@ -5812,18 +5820,18 @@ rrc_eNB_generate_RRCConnectionSetup(
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_RRC_UE,
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.Header, // LG WARNING
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size,
+    ue_p->Srb0.Tx_buffer.Header, // LG WARNING
+    ue_p->Srb0.Tx_buffer.payload_size,
     MSC_AS_TIME_FMT" RRCConnectionSetup UE %x size %u",
     MSC_AS_TIME_ARGS(ctxt_pP),
     ue_context_pP->ue_context.rnti,
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
+    ue_p->Srb0.Tx_buffer.payload_size);
 
 
   LOG_I(RRC,
         PROTOCOL_RRC_CTXT_UE_FMT" [RAPROC] Logical Channel DL-CCCH, Generating RRCConnectionSetup (bytes %d)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-        RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Srb0.Tx_buffer.payload_size);
+        ue_p->Srb0.Tx_buffer.payload_size);
 
   //ue_context_pP->ue_context.ue_release_timer_thres=100;
      // activate release timer, if RRCSetupComplete not received after 100 frames, remove UE
@@ -5887,10 +5895,6 @@ openair_rrc_eNB_init(
   pthread_mutex_init(&RC.rrc[ctxt.module_id]->cell_info_mutex,NULL);
   RC.rrc[ctxt.module_id]->cell_info_configured = 0;
 
-  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) {
-    RC.rrc[ctxt.module_id]->carrier[CC_id].Srb0.Active = 0;
-  }
-
   uid_linear_allocator_init(&RC.rrc[ctxt.module_id]->uid_allocator);
   RB_INIT(&RC.rrc[ctxt.module_id]->rrc_ue_head);
   //    for (j = 0; j < (MAX_MOBILES_PER_ENB + 1); j++) {
@@ -6016,7 +6020,8 @@ openair_rrc_eNB_init(
 int
 rrc_eNB_decode_ccch(
   protocol_ctxt_t* const ctxt_pP,
-  const SRB_INFO*        const Srb_info,
+  uint8_t                *buffer,
+  int                    buffer_length,
   const int              CC_id
 )
 //-----------------------------------------------------------------------------
@@ -6038,17 +6043,17 @@ rrc_eNB_decode_ccch(
 
   LOG_I(RRC, PROTOCOL_RRC_CTXT_UE_FMT" Decoding UL CCCH %x.%x.%x.%x.%x.%x (%p)\n",
         PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),
-        ((uint8_t*) Srb_info->Rx_buffer.Payload)[0],
-        ((uint8_t *) Srb_info->Rx_buffer.Payload)[1],
-        ((uint8_t *) Srb_info->Rx_buffer.Payload)[2],
-        ((uint8_t *) Srb_info->Rx_buffer.Payload)[3],
-        ((uint8_t *) Srb_info->Rx_buffer.Payload)[4],
-        ((uint8_t *) Srb_info->Rx_buffer.Payload)[5], (uint8_t *) Srb_info->Rx_buffer.Payload);
+        ((uint8_t*) buffer)[0],
+        ((uint8_t *) buffer)[1],
+        ((uint8_t *) buffer)[2],
+        ((uint8_t *) buffer)[3],
+        ((uint8_t *) buffer)[4],
+        ((uint8_t *) buffer)[5], (uint8_t *) buffer);
   dec_rval = uper_decode(
                NULL,
                &asn_DEF_UL_CCCH_Message,
                (void**)&ul_ccch_msg,
-               (uint8_t*) Srb_info->Rx_buffer.Payload,
+               (uint8_t*) buffer,
                100,
                0,
                0);
@@ -6109,8 +6114,8 @@ rrc_eNB_decode_ccch(
       T(T_ENB_RRC_CONNECTION_REESTABLISHMENT_REQUEST, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
         T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
-      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(Srb_info->Rx_buffer.Payload),
-                  Srb_info->Rx_buffer.payload_size,
+      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(buffer),
+                  buffer_length,
                   "[MSG] RRC Connection Reestablishment Request\n");
 
       LOG_D(RRC,
@@ -6329,8 +6334,8 @@ rrc_eNB_decode_ccch(
       T(T_ENB_RRC_CONNECTION_REQUEST, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame),
         T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti));
 
-      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)(Srb_info->Rx_buffer.Payload),
-                  Srb_info->Rx_buffer.payload_size,
+      LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,
+                  buffer_length,
                   "[MSG] RRC Connection Request\n");
 
       LOG_D(RRC,
@@ -6347,7 +6352,7 @@ rrc_eNB_decode_ccch(
         MSC_LOG_RX_DISCARDED_MESSAGE(
           MSC_RRC_ENB,
           MSC_RRC_UE,
-          Srb_info->Rx_buffer.Payload,
+          buffer,
           dec_rval.consumed,
           MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (UE already in context)",
           MSC_AS_TIME_ARGS(ctxt_pP),
@@ -6418,7 +6423,7 @@ rrc_eNB_decode_ccch(
             MSC_LOG_RX_MESSAGE(
               MSC_RRC_ENB,
               MSC_RRC_UE,
-              Srb_info->Rx_buffer.Payload,
+              buffer,
               dec_rval.consumed,
               MSC_AS_TIME_FMT" RRCConnectionRequest UE %x size %u (s-TMSI mmec %u m_TMSI %u random UE id (0x%" PRIx64 ")",
               MSC_AS_TIME_ARGS(ctxt_pP),
@@ -7445,8 +7450,12 @@ rrc_enb_task(
             PROTOCOL_RRC_CTXT_UE_ARGS(&ctxt),
             msg_name_p);
 
+      struct rrc_eNB_ue_context_s *ue_context_p = rrc_eNB_get_ue_context(RC.rrc[instance],
+									 RRC_MAC_CCCH_DATA_IND(msg_p).rnti);
+
       CC_id = RRC_MAC_CCCH_DATA_IND(msg_p).CC_id;
-      srb_info_p = &RC.rrc[instance]->carrier[CC_id].Srb0;
+      eNB_RRC_UE_t *ue_p = &ue_context_p->ue_context; 
+      srb_info_p = &ue_p->Srb0;
 
       LOG_I(RRC,"Decoding CCCH : inst %d, CC_id %d, ctxt %p, sib_info_p->Rx_buffer.payload_size %d\n",
 	    instance,CC_id,&ctxt, RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
@@ -7459,7 +7468,7 @@ rrc_enb_task(
              RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size);
       srb_info_p->Rx_buffer.payload_size = RRC_MAC_CCCH_DATA_IND(msg_p).sdu_size;
 
-      rrc_eNB_decode_ccch(&ctxt, srb_info_p, CC_id);
+      rrc_eNB_decode_ccch(&ctxt, srb_info_p->Rx_buffer.Payload,srb_info_p->Rx_buffer.payload_size, CC_id);
       break;
 	    
       /* Messages from PDCP */
diff --git a/openair2/RRC/LTE/rrc_proto.h b/openair2/RRC/LTE/rrc_proto.h
index 68c8655714..408270edbc 100644
--- a/openair2/RRC/LTE/rrc_proto.h
+++ b/openair2/RRC/LTE/rrc_proto.h
@@ -219,13 +219,15 @@ uint8_t rrc_eNB_get_next_transaction_identifier(module_id_t module_idP);
 
 /**\brief Entry routine to decode a UL-CCCH-Message.  Invokes PER decoder and parses message.
    \param ctxt_pP Running context
-   \param Srb_info Pointer to SRB0 information structure (buffer, etc.)*/
-int
-rrc_eNB_decode_ccch(
-  protocol_ctxt_t* const ctxt_pP,
-  const SRB_INFO*        const Srb_info,
-  const int              CC_id
-);
+   \param buffer Pointer to SDU
+   \param buffer_length length of SDU in bytes
+   \param CC_id component carrier index*/
+
+int rrc_eNB_decode_ccch(protocol_ctxt_t* const ctxt_pP,
+			uint8_t                *buffer,
+			int                    buffer_length,
+			const int              CC_id
+			);
 
 /**\brief Entry routine to decode a UL-DCCH-Message.  Invokes PER decoder and parses message.
    \param ctxt_pP Context
@@ -411,6 +413,7 @@ mac_rrc_data_req(
   const int         CC_id,
   const frame_t     frameP,
   const rb_id_t     Srb_id,
+  const rnti_t      rnti,
   const uint8_t     Nb_tb,
   uint8_t*    const buffer_pP,
   const uint8_t     mbsfn_sync_area
-- 
GitLab