From 8ef25c89538cce49a4d8af1f99cc2f962417cbd5 Mon Sep 17 00:00:00 2001
From: Navid Nikaein <navid.nikaein@eurecom.fr>
Date: Wed, 25 Nov 2015 11:22:45 +0100
Subject: [PATCH] * improve the management of two simultaneous E_RAB_SETUP_REQ.

---
 openair2/LAYER2/PDCP_v10.1.0/pdcp.c |  2 +-
 openair2/RRC/LITE/defs.h            |  1 +
 openair2/RRC/LITE/rrc_eNB.c         | 61 +++++++++++++++-------------
 openair2/RRC/LITE/rrc_eNB_S1AP.c    | 63 ++++++++++++++---------------
 openair3/S1AP/s1ap_eNB.c            |  1 -
 openair3/S1AP/s1ap_eNB_decoder.c    |  4 +-
 6 files changed, 69 insertions(+), 63 deletions(-)

diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
index 3eb1ed83fc7..c71b83ec2e3 100755
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
@@ -130,7 +130,7 @@ boolean_t pdcp_data_req(
             PROTOCOL_CTXT_ARGS(ctxt_pP),
             rb_idP);
     return FALSE;
-  }
+    }
   }
 
   if (sdu_buffer_sizeP == 0) {
diff --git a/openair2/RRC/LITE/defs.h b/openair2/RRC/LITE/defs.h
index 1a4d6e0fe1a..85d8e9cabe7 100644
--- a/openair2/RRC/LITE/defs.h
+++ b/openair2/RRC/LITE/defs.h
@@ -303,6 +303,7 @@ typedef struct eNB_RRC_UE_s {
 #endif
   SRB_ToAddModList_t*                SRB_configList;
   DRB_ToAddModList_t*                DRB_configList;
+  DRB_ToAddModList_t*                DRB_configList2[8];
   uint8_t                            DRB_active[8];
   struct PhysicalConfigDedicated*    physicalConfigDedicated;
   struct SPS_Config*                 sps_Config;
diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c
index bff756a25b1..9a9b39ed0d7 100644
--- a/openair2/RRC/LITE/rrc_eNB.c
+++ b/openair2/RRC/LITE/rrc_eNB.c
@@ -1077,7 +1077,7 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
   struct PDCP_Config__rlc_UM         *PDCP_rlc_UM                      = NULL;
   struct LogicalChannelConfig        *DRB_lchan_config                 = NULL;
   struct LogicalChannelConfig__ul_SpecificParameters
-      *DRB_ul_SpecificParameters        = NULL;
+    *DRB_ul_SpecificParameters        = NULL;
   DRB_ToAddModList_t**                DRB_configList=&ue_context_pP->ue_context.DRB_configList; 
   //DRB_ToAddModList_t**                RRC_DRB_configList=&ue_context_pP->ue_context.DRB_configList;
 
@@ -1085,8 +1085,8 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
   DedicatedInfoNAS_t                 *dedicatedInfoNas                 = NULL;
 
   long                               *logicalchannelgroup, *logicalchannelgroup_drb;
-  int drb_identity_index=0;
-
+  int drb_identity_index=0, nas_sequence_flag = 0;
+  
 // Configure DRB
   //*DRB_configList = CALLOC(1, sizeof(*DRB_configList));
   *DRB_configList = CALLOC(1, sizeof(**DRB_configList));
@@ -1097,7 +1097,7 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
 	i++){
     
     // bypass the already configured erabs
-    if (ue_context_pP->ue_context.e_rab[i].status == E_RAB_STATUS_ESTABLISHED) {
+    if (ue_context_pP->ue_context.e_rab[i].status >= E_RAB_STATUS_DONE) {
       drb_identity_index++;
       continue;
     }
@@ -1107,7 +1107,7 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
     DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long));
     *(DRB_config->eps_BearerIdentity) = ue_context_pP->ue_context.e_rab[i].param.e_rab_id;  
 
-    DRB_config->drb_Identity = 1 + drb_identity_index;// (DRB_Identity_t) ue_context_pP->ue_context.e_rab[i].param.e_rab_id;
+    DRB_config->drb_Identity =  1 + drb_identity_index ;// + 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));
@@ -1181,35 +1181,40 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t* co
     DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
 
     ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config);
-
+    //ue_context_pP->ue_context.DRB_configList2[drb_identity_index] = &(*DRB_configList);
+    
     LOG_I(RRC,"EPS ID %d, DRB ID %d (index %d), QCI %d, priority %d, LCID %d LCGID %d \n",
 	  *DRB_config->eps_BearerIdentity,
 	  DRB_config->drb_Identity, i,
 	  ue_context_pP->ue_context.e_rab[i].param.qos.qci,
 	  DRB_ul_SpecificParameters->priority,
 	  *(DRB_config->logicalChannelIdentity),
-	  DRB_ul_SpecificParameters->logicalChannelGroup	  
+	  *DRB_ul_SpecificParameters->logicalChannelGroup	  
 	  );
- 
-    if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
-      dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
-      memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
-      OCTET_STRING_fromBuf(dedicatedInfoNas, 
-			   (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
-                           ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
-      ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
-    } 
-    /* TODO parameters yet to process ... */
-    {
-      //      ue_context_pP->ue_context.e_rab[i].param.qos;
-      //      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
-      //      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
-    }
 
-    /* If list is empty free the list and reset the address */
-    if (dedicatedInfoNASList->list.count == 0) {
-      free(dedicatedInfoNASList);
-      dedicatedInfoNASList = NULL;
+    //if (nas_sequence_flag == 0)
+    {
+      if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) {
+	dedicatedInfoNas = CALLOC(1, sizeof(DedicatedInfoNAS_t));
+	memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t));
+	OCTET_STRING_fromBuf(dedicatedInfoNas, 
+			     (char*)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer,
+			     ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length);
+	ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas);
+	//	nas_sequence_flag = 1;
+      } 
+      /* TODO parameters yet to process ... */
+      {
+	//      ue_context_pP->ue_context.e_rab[i].param.qos;
+	//      ue_context_pP->ue_context.e_rab[i].param.sgw_addr;
+	//      ue_context_pP->ue_context.e_rab[i].param.gtp_teid;
+      }
+      
+      /* If list is empty free the list and reset the address */
+      if (dedicatedInfoNASList->list.count == 0) {
+	free(dedicatedInfoNASList);
+	dedicatedInfoNASList = NULL;
+      }					       
     }
     
     ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE; 
@@ -1482,6 +1487,7 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t* cons
   DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb;
 
   ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config);
+  //ue_context_pP->ue_context.DRB_configList2[0] = &(*DRB_configList);
 
   mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig));
   ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig;
@@ -3238,7 +3244,8 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
   rrc_pdcp_config_asn1_req(
     ctxt_pP,
     NULL,  //LG-RK 14/05/2014 SRB_configList,
-    DRB_configList, (DRB_ToReleaseList_t *) NULL,
+    DRB_configList, 
+    (DRB_ToReleaseList_t *) NULL,
     /*eNB_rrc_inst[ctxt_pP->module_id].ciphering_algorithm[ue_mod_idP] |
              (eNB_rrc_inst[ctxt_pP->module_id].integrity_algorithm[ue_mod_idP] << 4),
      */
diff --git a/openair2/RRC/LITE/rrc_eNB_S1AP.c b/openair2/RRC/LITE/rrc_eNB_S1AP.c
index 23ec2d2b749..76a10d948f9 100644
--- a/openair2/RRC/LITE/rrc_eNB_S1AP.c
+++ b/openair2/RRC/LITE/rrc_eNB_S1AP.c
@@ -1322,48 +1322,46 @@ rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(const protocol_ctxt_t* const ctxt_pP,
   int e_rab;
   int e_rabs_done = 0;
   int e_rabs_failed = 0;
-  int established_e_rab_index=0;
-  
+    
   msg_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_E_RAB_SETUP_RESP);
   S1AP_E_RAB_SETUP_RESP (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id;
-
-  established_e_rab_index=ue_context_pP->ue_context.setup_e_rabs - ue_context_pP->ue_context.nb_of_e_rabs;
-
-  for (e_rab = 0; e_rab <  ue_context_pP->ue_context.nb_of_e_rabs ; e_rab++) {
+ 
+  for (e_rab = 0; e_rab <  ue_context_pP->ue_context.setup_e_rabs ; e_rab++) {
    
-    
-    /* if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_ESTABLISHED) 
-      continue;
-     else 
-    */
-    if (ue_context_pP->ue_context.e_rab[e_rab+established_e_rab_index].status == E_RAB_STATUS_DONE) {
-      e_rabs_done++;
-      S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].e_rab_id = ue_context_pP->ue_context.e_rab[e_rab+established_e_rab_index].param.e_rab_id;
+       
+    if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) {
+     
+      S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].e_rab_id = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
       // TODO add other information from S1-U when it will be integrated
-      S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].gtp_teid = ue_context_pP->ue_context.enb_gtp_teid[e_rab+established_e_rab_index];
-      S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr = ue_context_pP->ue_context.enb_gtp_addrs[e_rab+established_e_rab_index];
+      S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].gtp_teid = ue_context_pP->ue_context.enb_gtp_teid[e_rab];
+      S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr = ue_context_pP->ue_context.enb_gtp_addrs[e_rab];
       //S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr.length += 4;
-      ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED;
+      ue_context_pP->ue_context.e_rab[e_rabs_done].status = E_RAB_STATUS_ESTABLISHED;
       
-      LOG_I (RRC,"enb_gtp_addr (msg index %d, local index %d, status %d): nb_of_e_rabs %d,  e_rab_id %d, teid: %u, addr: %d.%d.%d.%d \n ",
-	     e_rab,established_e_rab_index, ue_context_pP->ue_context.e_rab[e_rab+established_e_rab_index].status,
+      LOG_I (RRC,"enb_gtp_addr (msg index %d, context index %d, status %d): nb_of_e_rabs %d,  e_rab_id %d, teid: %u, addr: %d.%d.%d.%d \n ",
+	     e_rabs_done,  e_rab, ue_context_pP->ue_context.e_rab[e_rab].status,
 	     ue_context_pP->ue_context.nb_of_e_rabs,
-	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].e_rab_id,
-	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].gtp_teid,
-	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr.buffer[0],
-	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr.buffer[1],
-	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr.buffer[2],
-	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rab].eNB_addr.buffer[3]);
-    } else {
+	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].e_rab_id,
+	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].gtp_teid,
+	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[0],
+	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[1],
+	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[2],
+	     S1AP_E_RAB_SETUP_RESP (msg_p).e_rabs[e_rabs_done].eNB_addr.buffer[3]);
+
+      e_rabs_done++;
+    } else if ((ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_NEW)  || 
+	       (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_ESTABLISHED)){
+      LOG_D (RRC,"E-RAB is NEW or already ESTABLISHED\n");
+    }else {
+      ue_context_pP->ue_context.e_rab[e_rabs_failed].status = E_RAB_STATUS_FAILED;
+      S1AP_E_RAB_SETUP_RESP  (msg_p).e_rabs_failed[e_rabs_failed].e_rab_id = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id;
       e_rabs_failed++;
-      ue_context_pP->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED;
-      S1AP_E_RAB_SETUP_RESP  (msg_p).e_rabs_failed[e_rab].e_rab_id = ue_context_pP->ue_context.e_rab[e_rab+established_e_rab_index].param.e_rab_id;
       // TODO add cause when it will be integrated
     }
   }
   
-  LOG_I(RRC,"S1AP_E_RAB_SETUP_RESP: nb_of_erabs %d, total e_rabs %d, index %d, \n",
-	ue_context_pP->ue_context.nb_of_e_rabs, ue_context_pP->ue_context.setup_e_rabs, established_e_rab_index);
+  LOG_I(RRC,"S1AP_E_RAB_SETUP_RESP: nb_of_erabs %d, total e_rabs %d, index %d \n",
+	ue_context_pP->ue_context.nb_of_e_rabs, ue_context_pP->ue_context.setup_e_rabs, e_rab);
   MSC_LOG_TX_MESSAGE(
     MSC_RRC_ENB,
     MSC_S1AP_ENB,
@@ -1378,8 +1376,9 @@ rrc_eNB_send_S1AP_E_RAB_SETUP_RESP(const protocol_ctxt_t* const ctxt_pP,
 
   S1AP_E_RAB_SETUP_RESP (msg_p).nb_of_e_rabs = e_rabs_done;
   S1AP_E_RAB_SETUP_RESP (msg_p).nb_of_e_rabs_failed = e_rabs_failed;
-
-  itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
+  if ((e_rabs_done > 0) )
+    itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p);
+      
 }
 
 # endif /* defined(ENABLE_ITTI) */
diff --git a/openair3/S1AP/s1ap_eNB.c b/openair3/S1AP/s1ap_eNB.c
index 8af891a2b64..9dd34b35c49 100644
--- a/openair3/S1AP/s1ap_eNB.c
+++ b/openair3/S1AP/s1ap_eNB.c
@@ -33,7 +33,6 @@
  * \email: navid.nikaein@eurecom.fr
  * \version 1.0
  * @ingroup _s1ap
-
  */
 
 #include <pthread.h>
diff --git a/openair3/S1AP/s1ap_eNB_decoder.c b/openair3/S1AP/s1ap_eNB_decoder.c
index f212b084780..4a3689cec0f 100644
--- a/openair3/S1AP/s1ap_eNB_decoder.c
+++ b/openair3/S1AP/s1ap_eNB_decoder.c
@@ -124,7 +124,7 @@ static int s1ap_eNB_decode_initiating_message(s1ap_message *message,
   case S1ap_ProcedureCode_id_E_RABSetup:
     ret = s1ap_decode_s1ap_e_rabsetuprequesties(
 						&message->msg.s1ap_E_RABSetupRequestIEs, &initiating_p->value);
-    s1ap_xer_print_s1ap_e_rabsetuprequest(s1ap_xer__print2sp, message_string, message);
+    //s1ap_xer_print_s1ap_e_rabsetuprequest(s1ap_xer__print2sp, message_string, message);
     message_id = S1AP_E_RAB_SETUP_REQUEST_LOG;
     message_string_size = strlen(message_string);
     message_p           = itti_alloc_new_message_sized(TASK_S1AP,
@@ -139,7 +139,7 @@ static int s1ap_eNB_decode_initiating_message(s1ap_message *message,
   case S1ap_ProcedureCode_id_E_RABRelease:
     ret = s1ap_decode_s1ap_e_rabreleasecommandies(&message->msg.s1ap_E_RABReleaseCommandIEs, 
 						 &initiating_p->value);
-    s1ap_xer_print_s1ap_e_rabsetuprequest(s1ap_xer__print2sp, message_string, message);
+    //s1ap_xer_print_s1ap_e_rabsetuprequest(s1ap_xer__print2sp, message_string, message);
     S1AP_ERROR("TODO  E_RABReleas initiating message\n");
     free(message_string);
     
-- 
GitLab