From e47fc8354e239fcb54e1d7870779e6fa0bebb8d6 Mon Sep 17 00:00:00 2001
From: Lionel Gauthier <lionel.gauthier@eurecom.fr>
Date: Fri, 16 May 2014 15:09:38 +0000
Subject: [PATCH] Warning disabled SRB config list in RRC reconfiguration
 complete() when calling pdcp and rlc config asn1 req

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5326 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 .../EURECOM-NAS/src/api/network/nas_message.c |  17 +--
 .../EURECOM-NAS/src/emm/SecurityModeControl.c |   4 +-
 openair-cn/SCTP/sctp_eNB_task.c               |   2 +-
 openair1/SCHED/phy_procedures_lte_eNb.c       |   4 +-
 openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_entity.h |   2 +-
 openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_init.c   | 101 ++++++++++++++++--
 openair2/LAYER2/RLC/rlc_rrc.c                 |   8 ++
 openair2/RRC/LITE/rrc_eNB.c                   |  10 +-
 8 files changed, 124 insertions(+), 24 deletions(-)

diff --git a/openair-cn/NAS/EURECOM-NAS/src/api/network/nas_message.c b/openair-cn/NAS/EURECOM-NAS/src/api/network/nas_message.c
index 2153eafe0d..696f1a0b75 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/api/network/nas_message.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/api/network/nas_message.c
@@ -401,20 +401,25 @@ int nas_message_encode(
 
             if (emm_security_context) {
 #ifdef NAS_MME
+                /* TS 124.301, section 4.4.3.1
+                 * The NAS sequence number part of the NAS COUNT shall be
+                 * exchanged between the UE and the MME as part of the
+                 * NAS signalling. After each new or retransmitted outbound
+                 * security protected NAS message, the sender shall increase
+                 * the NAS COUNT number by one. Specifically, on the sender
+                 * side, the NAS sequence number shall be increased by one,
+                 * and if the result is zero (due to wrap around), the NAS
+                 * overflow counter shall also be incremented by one (see
+                 * subclause 4.4.3.5).
+                 */
                 emm_security_context->dl_count.seq_num += 1;
                 if ( ! emm_security_context->dl_count.seq_num) {
                     emm_security_context->dl_count.overflow += 1;
-                    if ( ! emm_security_context->dl_count.overflow) {
-                        // TODO
-                    }
                 }
 #else
                 emm_security_context->ul_count.seq_num += 1;
                 if ( ! emm_security_context->ul_count.seq_num) {
                     emm_security_context->ul_count.overflow += 1;
-                    if ( ! emm_security_context->ul_count.overflow) {
-                        // TODO
-                    }
                 }
 #endif
             }
diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c b/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c
index 1492f27afa..2910faa169 100644
--- a/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c
+++ b/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c
@@ -114,8 +114,8 @@ typedef struct {
     int ksi;                /* NAS key set identifier               */
     int eea;                /* Replayed EPS encryption algorithms   */
     int eia;                /* Replayed EPS integrity algorithms    */
-    int selected_eea;       /* Replayed EPS encryption algorithms   */
-    int selected_eia;       /* Replayed EPS integrity algorithms    */
+    int selected_eea;       /* Selected EPS encryption algorithms   */
+    int selected_eia;       /* Selected EPS integrity algorithms    */
     int notify_failure;     /* Indicates whether the security mode control
                              * procedure failure shall be notified to the
                              * ongoing EMM procedure        */
diff --git a/openair-cn/SCTP/sctp_eNB_task.c b/openair-cn/SCTP/sctp_eNB_task.c
index 7cfaefeb46..f039109f4a 100644
--- a/openair-cn/SCTP/sctp_eNB_task.c
+++ b/openair-cn/SCTP/sctp_eNB_task.c
@@ -549,7 +549,7 @@ inline void sctp_eNB_read_from_socket(struct sctp_cnx_list_elm_s *sctp_cnx)
     } else {
         sctp_cnx->nb_messages++;
 
-        if (sinfo.sinfo_ppid != sctp_cnx->ppid) {
+        if (ntohl(sinfo.sinfo_ppid) != sctp_cnx->ppid) {
             /* Mismatch in Payload Protocol Identifier,
              * may be we received unsollicited traffic from stack other than S1AP.
              */
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index dcf7c3e0ef..d10e8af094 100755
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -2909,7 +2909,7 @@ void phy_procedures_eNB_RX(unsigned char last_slot,PHY_VARS_eNB *phy_vars_eNB,ui
 #endif
       stop_meas(&phy_vars_eNB->ulsch_decoding_stats);
 
-#ifdef DEBUG_PHY_PROC
+//#ifdef DEBUG_PHY_PROC
       LOG_I(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d RNTI %x RX power (%d,%d) N0 (%d,%d) dB ACK (%d,%d), decoding iter %d\n",
 	  phy_vars_eNB->Mod_id,harq_pid,
 	  frame,last_slot>>1,
@@ -2921,7 +2921,7 @@ void phy_procedures_eNB_RX(unsigned char last_slot,PHY_VARS_eNB *phy_vars_eNB,ui
 	  phy_vars_eNB->ulsch_eNB[i]->o_ACK[0],
 	  phy_vars_eNB->ulsch_eNB[i]->o_ACK[1],
 	  ret);
-#endif //DEBUG_PHY_PROC
+//#endif //DEBUG_PHY_PROC
       /*
 	if ((two_ues_connected==1) && (phy_vars_eNB->cooperation_flag==2)) {
 	for (j=0;j<phy_vars_eNB->lte_frame_parms.nb_antennas_rx;j++) {
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_entity.h b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_entity.h
index f54d15414c..ed5b3dc746 100755
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_entity.h
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_entity.h
@@ -187,8 +187,8 @@ typedef struct rlc_am_entity_s {
   // note occupancy of other buffers is deducted from nb elements in lists
   rlc_buffer_occupancy_t  buffer_occupancy_retransmission_buffer;   /*!< \brief Number of PDUs. */
 
-  //boolean_t               allocation;                              /*!< \brief Boolean for rlc_am_entity_t struct allocation. */
   boolean_t               initialized;                               /*!< \brief Boolean for rlc_am_entity_t struct initialization. */
+  boolean_t               configured;                               /*!< \brief Boolean for rlc_am_entity_t struct  configuration. */
 } rlc_am_entity_t;
 /** @} */
 #    endif
diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_init.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_init.c
index 2c3ba4f79a..abc975c5cb 100755
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_init.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_init.c
@@ -43,9 +43,9 @@ void rlc_am_init(rlc_am_entity_t *rlc_pP, frame_t frameP)
 //-----------------------------------------------------------------------------
 {
     if (rlc_pP->initialized == TRUE) {
-        LOG_D(RLC, "[FRAME %5u][RLC_AM][MOD XX][RB XX][INIT] ALREADY DONE, DOING NOTHING\n", frameP);
+        LOG_D(RLC, "[FRAME %5u][RLC_AM][MOD XX][RB XX][INIT] INITIALIZATION ALREADY DONE, DOING NOTHING\n", frameP);
     } else {
-        LOG_D(RLC, "[FRAME %5u][RLC_AM][MOD XX][RB XX][INIT] STATE VARIABLES, BUFFERS, LISTS\n", frameP);
+        LOG_D(RLC, "[FRAME %5u][RLC_AM][MOD XX][RB XX][INIT] INITIALIZATION: STATE VARIABLES, BUFFERS, LISTS\n", frameP);
         memset(rlc_pP, 0, sizeof(rlc_am_entity_t));
 
         list2_init(&rlc_pP->receiver_buffer,      "RX BUFFER");
@@ -76,9 +76,62 @@ void rlc_am_init(rlc_am_entity_t *rlc_pP, frame_t frameP)
 
         rlc_pP->last_frame_status_indication = 123456; // any value > 1
         rlc_pP->first_retrans_pdu_sn         = -1;
+
         rlc_pP->initialized                  = TRUE;
     }
 }
+//-----------------------------------------------------------------------------
+void rlc_am_reestablish(rlc_am_entity_t *rlc_pP, frame_t frameP)
+//-----------------------------------------------------------------------------
+{
+    /*
+     * RLC re-establishment is performed upon request by RRC, and the function
+     * is applicable for AM, UM and TM RLC entities.
+     * When RRC indicates that an RLC entity should be re-established, the RLC entity shall:
+     * - if it is an AM RLC entity:
+     *    - when possible, reassemble RLC SDUs from any byte segments of AMD PDUs with SN < VR(MR) in the
+     *       receiving side, remove RLC headers when doing so and deliver all reassembled RLC SDUs to upper layer in
+     *        ascending order of the RLC SN, if not delivered before;
+     *    - discard the remaining AMD PDUs and byte segments of AMD PDUs in the receiving side;
+     *    - discard all RLC SDUs and AMD PDUs in the transmitting side;
+     *    - discard all RLC control PDUs.
+     *    - stop and reset all timers;
+     *    - reset all state variables to their initial values.
+     */
+    LOG_D(RLC, "[FRAME %5u][RLC_AM][MOD XX][RB XX][REESTABLISH] RE-INIT STATE VARIABLES, BUFFERS, LISTS\n", frameP);
+
+#warning TODO when possible reassemble RLC SDUs from any byte segments of AMD PDUs with SN inf VR(MR)
+    list2_free(&rlc_pP->receiver_buffer);
+
+    list_free(&rlc_pP->pdus_to_mac_layer);
+    list_free(&rlc_pP->control_pdu_list);
+    list_free(&rlc_pP->segmentation_pdu_list);
+
+
+    // TX state variables
+    rlc_pP->vt_a    = 0;
+    rlc_pP->vt_ms   = rlc_pP->vt_a + RLC_AM_WINDOW_SIZE;
+    rlc_pP->vt_s    = 0;
+    rlc_pP->poll_sn = 0;
+
+    // TX counters
+    rlc_pP->c_pdu_without_poll  = 0;
+    rlc_pP->c_byte_without_poll = 0;
+
+    // RX state variables
+    rlc_pP->vr_r    = 0;
+    rlc_pP->vr_mr   = rlc_pP->vr_r + RLC_AM_WINDOW_SIZE;
+    rlc_pP->vr_x    = 0;
+    rlc_pP->vr_ms   = 0;
+    rlc_pP->vr_h    = 0;
+
+    rlc_pP->last_frame_status_indication = 123456; // any value > 1
+    rlc_pP->first_retrans_pdu_sn         = -1;
+
+    rlc_pP->initialized                  = TRUE;
+
+}
+
 //-----------------------------------------------------------------------------
 void rlc_am_cleanup(rlc_am_entity_t *rlc_pP)
 //-----------------------------------------------------------------------------
@@ -133,7 +186,8 @@ void rlc_am_configure(rlc_am_entity_t *rlc_pP,
                       uint32_t            t_status_prohibitP)
 //-----------------------------------------------------------------------------
 {
-    LOG_I(RLC, "[FRAME %5u][%s][RLC_AM][MOD %u/%u][RB %u][CONFIGURE] max_retx_threshold %d poll_pdu %d poll_byte %d t_poll_retransmit %d t_reordering %d t_status_prohibit %d\n",
+  if (rlc_pP->configured == TRUE) {
+      LOG_I(RLC, "[FRAME %5u][%s][RLC_AM][MOD %u/%u][RB %u][RECONFIGURE] max_retx_threshold %d poll_pdu %d poll_byte %d t_poll_retransmit %d t_reordering %d t_status_prohibit %d\n",
           frameP,
           (rlc_pP->is_enb) ? "eNB" : "UE",
           rlc_pP->enb_module_id,
@@ -146,14 +200,41 @@ void rlc_am_configure(rlc_am_entity_t *rlc_pP,
           t_reorderingP,
           t_status_prohibitP);
 
-    rlc_pP->max_retx_threshold = max_retx_thresholdP;
-    rlc_pP->poll_pdu           = poll_pduP;
-    rlc_pP->poll_byte          = poll_byteP;
-    rlc_pP->protocol_state     = RLC_DATA_TRANSFER_READY_STATE;
+      rlc_pP->max_retx_threshold = max_retx_thresholdP;
+      rlc_pP->poll_pdu           = poll_pduP;
+      rlc_pP->poll_byte          = poll_byteP;
+      rlc_pP->protocol_state     = RLC_DATA_TRANSFER_READY_STATE;
+
+      rlc_pP->t_poll_retransmit.time_out   = t_poll_retransmitP;
+      rlc_pP->t_reordering.time_out        = t_reorderingP;
+      rlc_pP->t_status_prohibit.time_out   = t_status_prohibitP;
+  } else {
+      LOG_I(RLC, "[FRAME %5u][%s][RLC_AM][MOD %u/%u][RB %u][CONFIGURE] max_retx_threshold %d poll_pdu %d poll_byte %d t_poll_retransmit %d t_reordering %d t_status_prohibit %d\n",
+          frameP,
+          (rlc_pP->is_enb) ? "eNB" : "UE",
+          rlc_pP->enb_module_id,
+          rlc_pP->ue_module_id,
+          rlc_pP->rb_id,
+          max_retx_thresholdP,
+          poll_pduP,
+          poll_byteP,
+          t_poll_retransmitP,
+          t_reorderingP,
+          t_status_prohibitP);
+
+      rlc_pP->max_retx_threshold = max_retx_thresholdP;
+      rlc_pP->poll_pdu           = poll_pduP;
+      rlc_pP->poll_byte          = poll_byteP;
+      rlc_pP->protocol_state     = RLC_DATA_TRANSFER_READY_STATE;
+
+
+      rlc_am_init_timer_poll_retransmit(rlc_pP, t_poll_retransmitP);
+      rlc_am_init_timer_reordering     (rlc_pP, t_reorderingP);
+      rlc_am_init_timer_status_prohibit(rlc_pP, t_status_prohibitP);
+
+      rlc_pP->configured = TRUE;
+  }
 
-    rlc_am_init_timer_poll_retransmit(rlc_pP, t_poll_retransmitP);
-    rlc_am_init_timer_reordering     (rlc_pP, t_reorderingP);
-    rlc_am_init_timer_status_prohibit(rlc_pP, t_status_prohibitP);
 }
 //-----------------------------------------------------------------------------
 void rlc_am_set_debug_infos(rlc_am_entity_t *rlc_pP,
diff --git a/openair2/LAYER2/RLC/rlc_rrc.c b/openair2/LAYER2/RLC/rlc_rrc.c
index 26f42d14ed..1424d3f160 100644
--- a/openair2/LAYER2/RLC/rlc_rrc.c
+++ b/openair2/LAYER2/RLC/rlc_rrc.c
@@ -458,8 +458,16 @@ rb_free_rlc_union (void *rlcu_pP)
               rlc_tm_cleanup(&rlcu_p->rlc.tm);
               break;
           default:
+            LOG_W(RLC,
+                "%s %p unknown RLC type\n",
+                __FUNCTION__,
+                rlcu_pP);
             break;
         }
+        LOG_D(RLC,
+            "%s %p \n",
+            __FUNCTION__,
+            rlcu_pP);
         free(rlcu_p);
     }
 }
diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c
index b451e9c7fd..3f4a9529ed 100644
--- a/openair2/RRC/LITE/rrc_eNB.c
+++ b/openair2/RRC/LITE/rrc_eNB.c
@@ -2280,7 +2280,7 @@ void rrc_eNB_process_RRCConnectionReconfigurationComplete(
 #endif
     // Refresh SRBs/DRBs
     rrc_pdcp_config_asn1_req(enb_mod_idP, ue_mod_idP, frameP, ENB_FLAG_YES,
-                             SRB_configList,
+                            NULL,  //LG-RK 14/05/2014 SRB_configList,
                              DRB_configList, (DRB_ToReleaseList_t *) NULL,
                              /*eNB_rrc_inst[enb_mod_idP].ciphering_algorithm[ue_mod_idP] |
                              (eNB_rrc_inst[enb_mod_idP].integrity_algorithm[ue_mod_idP] << 4), 
@@ -2294,7 +2294,13 @@ void rrc_eNB_process_RRCConnectionReconfigurationComplete(
 #endif
         );
     // Refresh SRBs/DRBs
-    rrc_rlc_config_asn1_req(enb_mod_idP, ue_mod_idP, frameP, 1, SRB_configList, DRB_configList, (DRB_ToReleaseList_t *) NULL
+    rrc_rlc_config_asn1_req(enb_mod_idP,
+        ue_mod_idP,
+        frameP,
+        1,
+        NULL,  //LG-RK 14/05/2014 SRB_configList,
+        DRB_configList,
+        (DRB_ToReleaseList_t *) NULL
 #ifdef Rel10
                             , (PMCH_InfoList_r9_t *) NULL
 #endif
-- 
GitLab