From 4b02d818392a88a479628fc164c6f4c32bd8f685 Mon Sep 17 00:00:00 2001
From: naoi <naoi.haruki@jp.fujitsu.com>
Date: Thu, 1 Mar 2018 16:21:32 +0900
Subject: [PATCH] Fix: Random access information may not release if msg3_round
 initial value is not zero.

---
 openair2/LAYER2/MAC/eNB_scheduler_RA.c        | 25 +++++++++++++++++++
 .../LAYER2/MAC/eNB_scheduler_primitives.c     | 12 ++-------
 openair2/LAYER2/MAC/eNB_scheduler_ulsch.c     |  2 +-
 openair2/LAYER2/MAC/proto.h                   |  3 +++
 openair2/LAYER2/MAC/rar_tools.c               |  1 +
 5 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index bcd3984df9..5dee9b7a2c 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -1565,6 +1565,8 @@ initiate_ra_proc(module_id_t module_idP,
 
     struct PRACH_ConfigSIB_v1310 *ext4_prach = NULL;
     PRACH_ParametersListCE_r13_t *prach_ParametersListCE_r13 = NULL;
+  
+    static uint8_t failure_cnt = 0;
 
     if (cc->radioResourceConfigCommon_BR
 	&& cc->radioResourceConfigCommon_BR->ext4) {
@@ -1649,6 +1651,7 @@ initiate_ra_proc(module_id_t module_idP,
 	    }
 	    ra[i].RA_rnti = ra_rnti;
 	    ra[i].preamble_index = preamble_index;
+	    failure_cnt = 0;
 	    LOG_D(MAC,
 		  "[eNB %d][RAPROC] CC_id %d Frame %d Activating RAR generation in Frame %d, subframe %d for process %d, rnti %x, state %d\n",
 		  module_idP, CC_id, frameP, ra[i].Msg2_frame,
@@ -1661,6 +1664,13 @@ initiate_ra_proc(module_id_t module_idP,
     LOG_E(MAC,
 	  "[eNB %d][RAPROC] FAILURE: CC_id %d Frame %d Initiating RA procedure for preamble index %d\n",
 	  module_idP, CC_id, frameP, preamble_index);
+  
+    failure_cnt++;
+    if(failure_cnt > 20) {
+      LOG_E(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Clear Random access information\n");
+      clear_ra_proc(module_idP, CC_id, frameP);
+    }
+  
 }
 
 void
@@ -1687,3 +1697,18 @@ cancel_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP,
 	}
     }
 }
+
+void clear_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP)
+{
+  unsigned char i;
+  RA_t *ra = (RA_t *) & RC.mac[module_idP]->common_channels[CC_id].ra[0];
+
+  for (i = 0; i < NB_RA_PROC_MAX; i++) {
+    LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Clear Random access information rnti %x\n", module_idP, CC_id, frameP, ra[i].rnti);
+    ra[i].state = IDLE;
+    ra[i].timing_offset = 0;
+    ra[i].RRC_timer = 20;
+    ra[i].rnti = 0;
+    ra[i].msg3_round = 0;
+  }
+}
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
index fa462561af..ef41f4e850 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
@@ -2170,16 +2170,8 @@ int rrc_mac_remove_ue(module_id_t mod_idP, rnti_t rntiP)
     eNB_dlsch_info[mod_idP][pCC_id][UE_id].serving_num = 0;
 
     // check if this has an RA process active
-    RA_t *ra;
-    for (i = 0; i < NB_RA_PROC_MAX; i++) {
-	ra = (RA_t *) & RC.mac[mod_idP]->common_channels[pCC_id].ra[i];
-	if (ra->rnti == rntiP) {
-	    ra->state = IDLE;
-	    ra->timing_offset = 0;
-	    ra->RRC_timer = 20;
-	    ra->rnti = 0;
-	    //break;
-	}
+    if(find_RA_id(mod_idP, pCC_id, rntiP) != -1) {
+      cancel_ra_proc(mod_idP, pCC_id, 0, rntiP);
     }
 
     return 0;
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
index f4ad9a6e9d..6b5bf9a3d0 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
@@ -194,7 +194,7 @@ rx_sdu(const module_id_t enb_mod_idP,
 		  (int) mac->common_channels[CC_idP].
 		  radioResourceConfigCommon->rach_ConfigCommon.
 		  maxHARQ_Msg3Tx);
-	    if (ra[RA_id].msg3_round ==
+	    if (ra[RA_id].msg3_round >=
 		mac->common_channels[CC_idP].radioResourceConfigCommon->
 		rach_ConfigCommon.maxHARQ_Msg3Tx - 1) {
 		cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti);
diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h
index d42c8f38dc..d2cf3e047b 100644
--- a/openair2/LAYER2/MAC/proto.h
+++ b/openair2/LAYER2/MAC/proto.h
@@ -299,6 +299,9 @@ void cancel_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP,
 @param Msg3_frame    frame where scheduling takes place
 @param Msg3_subframe subframe where scheduling takes place
 */
+
+void clear_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP);
+
 void set_msg3_subframe(module_id_t Mod_id,
 		       int CC_id,
 		       int frame,
diff --git a/openair2/LAYER2/MAC/rar_tools.c b/openair2/LAYER2/MAC/rar_tools.c
index f48a53636f..6a9b4fa987 100644
--- a/openair2/LAYER2/MAC/rar_tools.c
+++ b/openair2/LAYER2/MAC/rar_tools.c
@@ -84,6 +84,7 @@ fill_rar(const module_id_t module_idP,
     ra->msg3_TPC = 3;
     ra->msg3_ULdelay = 0;
     ra->msg3_cqireq = 0;
+    ra->msg3_round = 0;
     rar[2] |= ((ra->msg3_mcs & 0x8) >> 3);	// mcs 10
     rar[3] =
 	(((ra->msg3_mcs & 0x7) << 5)) | ((ra->msg3_TPC & 7) << 2) |
-- 
GitLab