From 4b8251838dd8d123e2e7a1e4983629f0a47a9ea9 Mon Sep 17 00:00:00 2001
From: Navid Nikaein <navid.nikaein@eurecom.fr>
Date: Wed, 20 Apr 2016 13:14:16 +0200
Subject: [PATCH] enabling SRB2

---
 openair2/LAYER2/PDCP_v10.1.0/pdcp.c      |  6 ++--
 openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c |  2 +-
 openair2/RRC/LITE/rrc_eNB.c              | 38 ++++++++++++++----------
 3 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
index c71b83ec2..595bdfd31 100755
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
@@ -115,7 +115,7 @@ boolean_t pdcp_data_req(
     AssertError (rb_idP < NB_RB_MBMS_MAX, return FALSE, "RB id is too high (%u/%d) %u %u!\n", rb_idP, NB_RB_MBMS_MAX, ctxt_pP->module_id, ctxt_pP->rnti);
   } else {
     if (srb_flagP) {
-      AssertError (rb_idP < 2, return FALSE, "RB id is too high (%u/%d) %u %u!\n", rb_idP, 2, ctxt_pP->module_id, ctxt_pP->rnti);
+      AssertError (rb_idP < 3, return FALSE, "RB id is too high (%u/%d) %u %u!\n", rb_idP, 3, ctxt_pP->module_id, ctxt_pP->rnti);
     } else {
       AssertError (rb_idP < maxDRB, return FALSE, "RB id is too high (%u/%d) %u %u!\n", rb_idP, maxDRB, ctxt_pP->module_id, ctxt_pP->rnti);
     }
@@ -1475,8 +1475,8 @@ pdcp_config_req_asn1 (
       pdcp_pP->seq_num_size=5;
     }
 
-    LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Action MODIFY LCID %d "
-            "RB id %d configured with SN size %d and RLC %s \n",
+    LOG_I(PDCP,PROTOCOL_PDCP_CTXT_FMT" Action MODIFY LCID %d "
+            "RB id %d reconfigured with SN size %d and RLC %s \n",
           PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP),
           lc_idP,
           rb_idP,
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
index 787d463b3..40ce7c728 100755
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
@@ -482,7 +482,7 @@ int pdcp_fifo_read_input_sdus (const protocol_ctxt_t* const  ctxt_pP)
             ctxt.enb_flag      = ENB_FLAG_NO;
             ctxt.module_id     = pdcp_read_header_g.inst - oai_emulation.info.nb_enb_local + oai_emulation.info.first_ue_local;
             ctxt.rnti          = pdcp_UE_UE_module_id_to_rnti[ctxt.module_id];
-            rab_id    = pdcp_read_header_g.rb_id;
+            rab_id    = pdcp_read_header_g.rb_id % maxDRB;
           }
 
           CHECK_CTXT_ARGS(&ctxt);
diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c
index 0a230ea8e..6a68d6760 100644
--- a/openair2/RRC/LITE/rrc_eNB.c
+++ b/openair2/RRC/LITE/rrc_eNB.c
@@ -1153,6 +1153,8 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
   //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
   *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
   dedicatedInfoNASList = CALLOC(1, sizeof(struct RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList));
+
+  int e_rab_done=0;
   
   for ( i = 0  ;
 	i < ue_context_pP->ue_context.setup_e_rabs ;
@@ -1167,9 +1169,10 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
     DRB_config = CALLOC(1, sizeof(*DRB_config));
 
     DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
-    *(DRB_config->eps_BearerIdentity) = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;  
+    // allowed value 5..15, value : x+4
+    *(DRB_config->eps_BearerIdentity) = ue_context_pP->ue_context.e_rab[i].param.e_rab_id + 4;  
 
-    DRB_config->drb_Identity =  1 + drb_identity_index ;// + i ;// (DRB_Identity_t) ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
+    DRB_config->drb_Identity =  1 + drb_identity_index + e_rab_done;// + i ;// (DRB_Identity_t) ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
     // 1 + drb_identiy_index;  
 
     DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long));
@@ -1273,12 +1276,14 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
       }
       
       /* If list is empty free the list and reset the address */
-      if (dedicatedInfoNASList->list.count == 0) {
-	free(dedicatedInfoNASList);
-	dedicatedInfoNASList = NULL;
-      }					       
+      if (dedicatedInfoNASList != NULL) {
+	if (dedicatedInfoNASList->list.count == 0) {
+	  free(dedicatedInfoNASList);
+	  dedicatedInfoNASList = NULL;
+	}				
+      }
     }
-    
+    e_rab_done++;
     ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE; 
     ue_context_pP->ue_context.e_rab[i].xid =rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id);   //Transaction_id,
     
@@ -1477,7 +1482,9 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* cons
   SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup;
 
   SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB2_ul_SpecificParameters;
+  // this list has the configuration for SRB1 and SRB2
   ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config);
+  // this list has only the configuration for SRB2
   ASN_SEQUENCE_ADD(&SRB_configList2->list, SRB2_config);
 
   // Configure DRB
@@ -1898,7 +1905,7 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* cons
   size = do_RRCConnectionReconfiguration(ctxt_pP,
                                          buffer,
                                          rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id),   //Transaction_id,
-                                         (SRB_ToAddModList_t*)NULL, /// NN: do not reconfig srb1: SRB_configList2,
+                                         (SRB_ToAddModList_t*)SRB_configList, // SRB_configList
                                          (DRB_ToAddModList_t*)*DRB_configList,
                                          (DRB_ToReleaseList_t*)NULL,  // DRB2_list,
                                          (struct SPS_Config*)NULL,    // *sps_Config,
@@ -3306,7 +3313,7 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
 
   rrc_pdcp_config_asn1_req(
     ctxt_pP,
-    NULL,  //LG-RK 14/05/2014 SRB_configList,
+    SRB_configList, //NULL,  //LG-RK 14/05/2014 SRB_configList,
     DRB_configList, 
     (DRB_ToReleaseList_t *) NULL,
     /*eNB_rrc_inst[ctxt_pP->module_id].ciphering_algorithm[ue_mod_idP] |
@@ -3323,7 +3330,7 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
   // Refresh SRBs/DRBs
   rrc_rlc_config_asn1_req(
     ctxt_pP,
-    NULL,  //LG-RK 14/05/2014 SRB_configList,
+    SRB_configList, // NULL,  //LG-RK 14/05/2014 SRB_configList,
     DRB_configList,
     (DRB_ToReleaseList_t *) NULL
 #ifdef Rel10
@@ -4581,9 +4588,9 @@ void rrc_eNB_reconfigure_DRBs (const protocol_ctxt_t* const ctxt_pP,
 			       rrc_eNB_ue_context_t*  ue_context_pP){
 
   int i;
-
+  int e_rab_done=0;
   for (i = 0; 
-       i < NB_RB_MAX - 3;  // S1AP_MAX_E_RAB
+       i < 3;//NB_RB_MAX - 3;  // S1AP_MAX_E_RAB
        i++) {
     
     if ( ue_context_pP->ue_context.e_rab[i].status < E_RAB_STATUS_DONE){ 
@@ -4600,14 +4607,13 @@ void rrc_eNB_reconfigure_DRBs (const protocol_ctxt_t* const ctxt_pP,
       ue_context_pP->ue_context.e_rab[i].param.gtp_teid=0;
       
       ue_context_pP->ue_context.nb_of_e_rabs++;
-      
+      e_rab_done++;
       LOG_I(RRC,"setting up the dedicated DRBs %d (index %d) status %d \n", 
 	    ue_context_pP->ue_context.e_rab[i].param.e_rab_id, i, ue_context_pP->ue_context.e_rab[i].status);
     }
-    
-    ue_context_pP->ue_context.setup_e_rabs+=ue_context_pP->ue_context.nb_of_e_rabs;
   }
-  
+  ue_context_pP->ue_context.setup_e_rabs+=e_rab_done;
+ 
   rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(ctxt_pP, ue_context_pP, 0);
 }
 
-- 
GitLab