From 4d521a00ed3092b2dc027626e96d6682d2ec23d0 Mon Sep 17 00:00:00 2001
From: Wu Jing <wu.jing@cn.fujitsu.com>
Date: Fri, 15 Feb 2019 08:40:52 +0000
Subject: [PATCH] fix issue when uci array is full(rm1954)

---
 .../nfapi/public_inc/nfapi_interface.h        |  1 +
 openair1/PHY/LTE_TRANSPORT/transport_eNB.h    |  2 ++
 openair1/PHY/LTE_TRANSPORT/uci_tools.c        | 10 ++++++---
 openair1/PHY/defs_eNB.h                       |  2 +-
 openair1/SCHED/fapi_l1.c                      |  3 +++
 openair1/SCHED/phy_procedures_lte_eNb.c       | 22 +++++++++----------
 openair2/LAYER2/MAC/eNB_scheduler.c           |  1 +
 openair2/LAYER2/MAC/eNB_scheduler_RA.c        |  1 +
 openair2/RRC/LTE/rrc_eNB.c                    |  8 ++++---
 targets/COMMON/openairinterface5g_limits.h    |  6 +++++
 10 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h
index dce784f40e..a39a0422a6 100644
--- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h
+++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h
@@ -1867,6 +1867,7 @@ typedef struct {
 	nfapi_tl_t tl;
 	uint32_t handle;
 	uint16_t rnti;
+	uint16_t ue_id;
 } nfapi_ul_config_ue_information_rel8_t;
 #define NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG 0x2013
 
diff --git a/openair1/PHY/LTE_TRANSPORT/transport_eNB.h b/openair1/PHY/LTE_TRANSPORT/transport_eNB.h
index 7df39e038c..ae9c78509f 100644
--- a/openair1/PHY/LTE_TRANSPORT/transport_eNB.h
+++ b/openair1/PHY/LTE_TRANSPORT/transport_eNB.h
@@ -326,6 +326,8 @@ typedef struct {
   uint8_t     subframe;
   /// corresponding UE RNTI
   uint16_t    rnti;
+  /// UE ID from Layer2
+  uint16_t    ue_id;
   /// Type (SR,HARQ,CQI,HARQ_SR,HARQ_CQI,SR_CQI,HARQ_SR_CQI)
   UCI_type_t  type;
   /// SRS active flag
diff --git a/openair1/PHY/LTE_TRANSPORT/uci_tools.c b/openair1/PHY/LTE_TRANSPORT/uci_tools.c
index 88c652133b..b9f1558f3e 100644
--- a/openair1/PHY/LTE_TRANSPORT/uci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/uci_tools.c
@@ -41,15 +41,19 @@ int16_t find_uci(uint16_t rnti, int frame, int subframe, PHY_VARS_eNB *eNB,find_
   uint16_t i;
   int16_t first_free_index=-1;
   AssertFatal(eNB!=NULL,"eNB is null\n");
-  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
+  for (i=0; i<NUMBER_OF_UCI_VARS_MAX; i++) {
     if ((eNB->uci_vars[i].active >0) &&
 	(eNB->uci_vars[i].rnti==rnti) &&
 	(eNB->uci_vars[i].frame==frame) &&
 	(eNB->uci_vars[i].subframe==subframe)) return(i); 
     else if ((eNB->uci_vars[i].active == 0) && (first_free_index==-1)) first_free_index=i;
   }
-  if (type == SEARCH_EXIST) return(-1);
-  else return(first_free_index);
+  if (type == SEARCH_EXIST){
+       return(-1);
+  }
+  else{
+       return(first_free_index);
+  }
 }
 
 
diff --git a/openair1/PHY/defs_eNB.h b/openair1/PHY/defs_eNB.h
index 4de8305075..9bf7ba7987 100644
--- a/openair1/PHY/defs_eNB.h
+++ b/openair1/PHY/defs_eNB.h
@@ -942,7 +942,7 @@ typedef struct PHY_VARS_eNB_s {
   LTE_eNB_PRACH        prach_vars_br;
 #endif
   LTE_eNB_COMMON       common_vars;
-  LTE_eNB_UCI          uci_vars[NUMBER_OF_UE_MAX];
+  LTE_eNB_UCI          uci_vars[NUMBER_OF_UCI_VARS_MAX];
   LTE_eNB_SRS          srs_vars[NUMBER_OF_UE_MAX];
   LTE_eNB_PBCH         pbch;
   LTE_eNB_PUSCH       *pusch_vars[NUMBER_OF_UE_MAX];
diff --git a/openair1/SCHED/fapi_l1.c b/openair1/SCHED/fapi_l1.c
index 931e18d2ca..baf78d943d 100644
--- a/openair1/SCHED/fapi_l1.c
+++ b/openair1/SCHED/fapi_l1.c
@@ -501,6 +501,7 @@ void handle_uci_sr_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_pdu_t
   uci->frame               = frame;
   uci->subframe            = subframe;
   uci->rnti                = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti;
+  uci->ue_id               = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.ue_id;
   uci->type                = SR;
   uci->pucch_fmt           = pucch_format1;
   uci->num_antenna_ports   = 1;
@@ -520,6 +521,7 @@ void handle_uci_sr_harq_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_
   uci->frame               = frame;
   uci->subframe            = subframe;
   uci->rnti                = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti;
+  uci->ue_id               = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.ue_id;
   uci->type                = HARQ_SR;
   uci->num_antenna_ports   = 1;
   uci->num_pucch_resources = 1;
@@ -538,6 +540,7 @@ void handle_uci_harq_pdu(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_request_pdu
   uci->frame             = frame;
   uci->subframe          = subframe;
   uci->rnti              = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti;
+  uci->ue_id             = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.ue_id;
   uci->type              = HARQ;
   uci->srs_active        = srs_active;
   uci->num_antenna_ports = ul_config_pdu->uci_harq_pdu.harq_information.harq_information_rel11.num_ant_ports;
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index 5685b8d130..7a44a9bd24 100644
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -731,7 +731,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
   LTE_eNB_UCI *uci;
   uint16_t tdd_multiplexing_mask=0;
 
-  for (i=0;i<NUMBER_OF_UE_MAX;i++) {
+  for (i=0;i<NUMBER_OF_UCI_VARS_MAX;i++) {
 
     uci = &eNB->uci_vars[i];
     if ((uci->active == 1) &&
@@ -775,7 +775,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 		
 	metric_SR = rx_pucch(eNB,
 			     uci->pucch_fmt,
-			     i,
+			     uci->ue_id,
 			     uci->n_pucch_1_0_sr[0],
 			     0, // n2_pucch
 			     uci->srs_active, // shortened format
@@ -810,7 +810,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 	  
 	  metric[0] = rx_pucch(eNB,
 			       uci->pucch_fmt,
-			       i,
+			       uci->ue_id,
 			       uci->n_pucch_1[0][0],
 			       0, //n2_pucch
 			       uci->srs_active, // shortened format
@@ -830,7 +830,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 	    
 	    metric[0]=rx_pucch(eNB,
 			       uci->pucch_fmt,
-			       i,
+			       uci->ue_id,
 			       uci->n_pucch_1_0_sr[0],
 			       0, //n2_pucch
 			       uci->srs_active, // shortened format
@@ -860,7 +860,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 #if 1
 	      metric[0] = rx_pucch(eNB,
 				   uci->pucch_fmt,
-				   i,
+				   uci->ue_id,
 				   uci->n_pucch_1[0][0],
 				   0, //n2_pucch
 				   uci->srs_active, // shortened format
@@ -875,7 +875,7 @@ void uci_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 	          SR_payload = 1;
 	          metric[0] = rx_pucch(eNB,
 				       pucch_format1b,
-				       i,
+				       uci->ue_id,
 				       uci->n_pucch_1_0_sr[0],
 				       0, //n2_pucch
 				       uci->srs_active, // shortened format
@@ -1241,13 +1241,13 @@ void uci_procedures(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc)
 	LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Got SR for PUSCH, transmitting to MAC\n",eNB->Mod_id,
 	      uci->rnti,frame,subframe);
 	
-	if (eNB->first_sr[i] == 1) { // this is the first request for uplink after Connection Setup, so clear HARQ process 0 use for Msg4
-	  eNB->first_sr[i] = 0;
-	  eNB->dlsch[i][0]->harq_processes[0]->round=0;
-	  eNB->dlsch[i][0]->harq_processes[0]->status=SCH_IDLE;
+        if (eNB->first_sr[uci->ue_id] == 1) { // this is the first request for uplink after Connection Setup, so clear HARQ process 0 use for Msg4
+          eNB->first_sr[uci->ue_id] = 0;
+          eNB->dlsch[uci->ue_id][0]->harq_processes[0]->round=0;
+          eNB->dlsch[uci->ue_id][0]->harq_processes[0]->status=SCH_IDLE;
 	  LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d First SR\n",
 		eNB->Mod_id,
-		eNB->ulsch[i]->rnti,frame,subframe);
+		eNB->ulsch[uci->ue_id]->rnti,frame,subframe);
 	}
       }
     }
diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c
index 8648fa5771..6478ef997b 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler.c
@@ -338,6 +338,7 @@ schedule_SR(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)
 	ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus].pdu_type                                              = NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE;
 	ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus].uci_sr_pdu.ue_information.ue_information_rel8.tl.tag  = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG;
 	ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus].uci_sr_pdu.ue_information.ue_information_rel8.rnti    = UE_list->UE_template[CC_id][UE_id].rnti;
+	ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus].uci_sr_pdu.ue_information.ue_information_rel8.ue_id   = UE_id;
 	ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus].uci_sr_pdu.ue_information.ue_information_rel11.tl.tag = 0;
 	ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus].uci_sr_pdu.ue_information.ue_information_rel13.tl.tag = 0;
 	ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus].uci_sr_pdu.sr_information                             = sr;
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index 3815ecbebd..228ae66f22 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -972,6 +972,7 @@ generate_Msg4(module_id_t module_idP, int CC_idP, frame_t frameP,
                 ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG;
 		ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.handle = 0;	// don't know how to use this
 		ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti = ra->rnti;
+                ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.ue_id = UE_id;
                 ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL13_TAG;
 		ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.ue_type = (ra->rach_resource_type < 3) ? 1 : 2;
 		ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel13.empty_symbols = 0;
diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c
index 148f11075f..0e4bc188d0 100644
--- a/openair2/RRC/LTE/rrc_eNB.c
+++ b/openair2/RRC/LTE/rrc_eNB.c
@@ -930,9 +930,11 @@ void release_UE_in_freeList(module_id_t mod_id) {
             clean_eNb_ulsch(ulsch);
           }
 
-          if(eNB_PHY->uci_vars[i].rnti == rnti) {
-            LOG_I(MAC, "clean eNb uci_vars[%d] UE %x \n",i, rnti);
-            memset(&eNB_PHY->uci_vars[i],0,sizeof(LTE_eNB_UCI));
+          for(j = 0;j < NUMBER_OF_UCI_VARS_MAX;j++){
+            if(eNB_PHY->uci_vars[j].rnti == rnti){
+              LOG_I(MAC, "clean eNb uci_vars[%d] UE %x \n",j, rnti);
+              memset(&eNB_PHY->uci_vars[j],0,sizeof(LTE_eNB_UCI));
+            }
           }
         }
 
diff --git a/targets/COMMON/openairinterface5g_limits.h b/targets/COMMON/openairinterface5g_limits.h
index 644952ca79..3d9e1cbcca 100644
--- a/targets/COMMON/openairinterface5g_limits.h
+++ b/targets/COMMON/openairinterface5g_limits.h
@@ -12,13 +12,16 @@
 // This problem will be fixed in the future.
 #            ifndef UESIM_EXPANSION
 #                define NUMBER_OF_UE_MAX 16
+#                define NUMBER_OF_UCI_VARS_MAX 24
 #                define NUMBER_OF_CONNECTED_eNB_MAX 3
 #            else
 #                define NUMBER_OF_UE_MAX 256
+#                define NUMBER_OF_UCI_VARS_MAX 256
 #                define NUMBER_OF_CONNECTED_eNB_MAX 1
 #            endif
 #        else
 #                define NUMBER_OF_UE_MAX 256
+#                define NUMBER_OF_UCI_VARS_MAX 256
 #                define NUMBER_OF_CONNECTED_eNB_MAX 1
 #        endif
 #else
@@ -32,13 +35,16 @@ and the other are using MAX_MOBILES_PER_ENB in for-loop.
 */
 #            ifndef UESIM_EXPANSION
 #                define NUMBER_OF_UE_MAX 16
+#                define NUMBER_OF_UCI_VARS_MAX 24
 #                define NUMBER_OF_CONNECTED_eNB_MAX 3
 #            else
 #                define NUMBER_OF_UE_MAX 256
+#                define NUMBER_OF_UCI_VARS_MAX 256
 #                define NUMBER_OF_CONNECTED_eNB_MAX 1
 #            endif
 #        else
 #                define NUMBER_OF_UE_MAX 256
+#                define NUMBER_OF_UCI_VARS_MAX 256
 #                define NUMBER_OF_CONNECTED_eNB_MAX 1
 #        endif
 #        if defined(STANDALONE) && STANDALONE==1
-- 
2.26.2