From eb610af36b9de20ad23357e56d52a356fb5477c9 Mon Sep 17 00:00:00 2001
From: Xu Bo <xubo1@cn.fujitsu.com>
Date: Thu, 11 Jan 2018 11:19:57 +0000
Subject: [PATCH] fix DLSCH ACK/NAK cce_index issue

---
 openair2/LAYER2/MAC/eNB_scheduler.c           |  2 +-
 .../LAYER2/MAC/eNB_scheduler_primitives.c     | 26 ++++++++++++++-----
 openair2/LAYER2/MAC/proto.h                   |  2 +-
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c
index 7ae6862af3..6122b9a50b 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler.c
@@ -751,7 +751,7 @@ eNB_dlsch_ulsch_scheduler(module_id_t module_idP, frame_t frameP,
     // Allocate CCEs for good after scheduling is done
 
     for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++)
-	allocate_CCEs(module_idP, CC_id, subframeP, 0);
+	allocate_CCEs(module_idP, CC_id, frameP, subframeP, 2);
 
 
     stop_meas(&RC.mac[module_idP]->eNB_scheduler);
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
index f09b7852bd..3aa2ede87a 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
@@ -3063,7 +3063,7 @@ get_nCCE_max(COMMON_channels_t * cc, int num_pdcch_symbols, int subframe)
 
 // Allocate the CCEs
 int
-allocate_CCEs(int module_idP, int CC_idP, int subframeP, int test_onlyP)
+allocate_CCEs(int module_idP, int CC_idP, frame_t frameP, sub_frame_t subframeP, int test_onlyP)
 {
     int *CCE_table = RC.mac[module_idP]->CCE_table[CC_idP];
     nfapi_dl_config_request_body_t *DL_req =
@@ -3081,6 +3081,11 @@ allocate_CCEs(int module_idP, int CC_idP, int subframeP, int test_onlyP)
     int i, j, idci;
     int nCCE = 0;
 
+    eNB_MAC_INST *eNB = RC.mac[module_idP];
+    COMMON_channels_t *cc = &eNB->common_channels[CC_idP];
+    int ackNAK_absSF = get_pucch1_absSF(cc, (frameP*10+subframeP));
+    nfapi_ul_config_request_body_t *ul_req = &eNB->UL_req_tmp[CC_idP][ackNAK_absSF % 10].ul_config_request_body;
+
     LOG_D(MAC,
 	  "Allocate CCEs subframe %d, test %d : (DL PDU %d, DL DCI %d, UL %d)\n",
 	  subframeP, test_onlyP, DL_req->number_pdu, DL_req->number_dci,
@@ -3176,7 +3181,7 @@ allocate_CCEs(int module_idP, int CC_idP, int subframeP, int test_onlyP)
 		dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.
 		aggregation_level;
 	    LOG_D(MAC, "Allocating at nCCE %d\n", fCCE);
-	    if (test_onlyP == 0) {
+	    if ((test_onlyP%2) == 0) {
 		dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = fCCE;
 		LOG_D(MAC,
 		      "Allocate COMMON DCI CCEs subframe %d, test %d => L %d fCCE %d\n",
@@ -3270,7 +3275,7 @@ allocate_CCEs(int module_idP, int CC_idP, int subframeP, int test_onlyP)
 	    // the allocation is feasible, rnti rule passes
 	    nCCE += hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level;
 	    LOG_D(MAC, "Allocating at nCCE %d\n", fCCE);
-	    if (test_onlyP == 0) {
+	    if ((test_onlyP%2) == 0) {
 		hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.cce_index = fCCE;
 		LOG_D(MAC, "Allocate CCEs subframe %d, test %d\n",
 		      subframeP, test_onlyP);
@@ -3365,11 +3370,20 @@ allocate_CCEs(int module_idP, int CC_idP, int subframeP, int test_onlyP)
 		dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.
 		aggregation_level;
 	    LOG_D(MAC, "Allocating at nCCE %d\n", fCCE);
-	    if (test_onlyP == 0) {
+	    if ((test_onlyP%2) == 0) {
 		dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = fCCE;
 		LOG_D(MAC, "Allocate CCEs subframe %d, test %d\n",
 		      subframeP, test_onlyP);
 	    }
+            if ((test_onlyP/2) == 1) {
+              for(int ack_int = 0;ack_int < ul_req->number_of_pdus; ack_int++){
+                if(((ul_req->ul_config_pdu_list[ack_int].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) ||
+                    (ul_req->ul_config_pdu_list[ack_int].pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE)) &&
+                   (ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.ue_information.ue_information_rel8.rnti == dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti)){
+                  ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0 = fCCE;
+                }
+              }
+            }
 	    idci++;
 	}
     }				// for i = 0 ... num_DL_DCIs
@@ -3546,7 +3560,7 @@ CCE_allocation_infeasible(int module_idP,
 		  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.
 		  aggregation_level,
 		  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type);
-	    ret = allocate_CCEs(module_idP, CC_idP, subframe, 0);
+	    ret = allocate_CCEs(module_idP, CC_idP, 0, subframe, 0);
 	    if (ret == -1)
 		res = TRUE;
 	    DL_req->number_pdu--;
@@ -3563,7 +3577,7 @@ CCE_allocation_infeasible(int module_idP,
 	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level =
 		aggregation;
 	    HI_DCI0_req->number_of_dci++;
-	    ret = allocate_CCEs(module_idP, CC_idP, subframe, 0);
+	    ret = allocate_CCEs(module_idP, CC_idP, 0, subframe, 0);
 	    if (ret == -1)
 		res = TRUE;
 	    HI_DCI0_req->number_of_dci--;
diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h
index a2c4890356..2525f134f4 100644
--- a/openair2/LAYER2/MAC/proto.h
+++ b/openair2/LAYER2/MAC/proto.h
@@ -405,7 +405,7 @@ int get_nCCE_offset(int *CCE_table,
 		    const unsigned short rnti,
 		    const unsigned char subframe);
 
-int allocate_CCEs(int module_idP, int CC_idP, int subframe, int test_only);
+int allocate_CCEs(int module_idP, int CC_idP, frame_t frameP, sub_frame_t subframeP, int test_only);
 
 boolean_t CCE_allocation_infeasible(int module_idP,
 				    int CC_idP,
-- 
GitLab