From 31d9da3f73190bcc1fe515473ef9f057f991e057 Mon Sep 17 00:00:00 2001
From: Laurent THOMAS <laurent.thomas@open-cells.com>
Date: Mon, 27 Dec 2021 17:10:19 +0100
Subject: [PATCH] cleanup nr_band() function

---
 common/utils/nr/nr_common.c                  | 28 ++++++--------------
 common/utils/nr/nr_common.h                  |  3 +--
 openair2/F1AP/f1ap_cu_interface_management.c | 25 +++++++++--------
 openair2/F1AP/f1ap_du_interface_management.c |  1 +
 openair2/GNB_APP/gnb_app.c                   |  1 -
 5 files changed, 24 insertions(+), 34 deletions(-)

diff --git a/common/utils/nr/nr_common.c b/common/utils/nr/nr_common.c
index 0de24bcf6d7..d9f5108b3ec 100644
--- a/common/utils/nr/nr_common.c
+++ b/common/utils/nr/nr_common.c
@@ -42,7 +42,7 @@ const char *duplex_mode[]={"FDD","TDD"};
 // - N_OFFs for bands from 80 to 89 and band 95 is referred to UL
 // - Frequencies are expressed in KHz
 // - col: NR_band ul_min  ul_max  dl_min  dl_max  step  N_OFFs_DL  deltaf_raster
-nr_bandentry_t nr_bandtable[] = {
+const nr_bandentry_t nr_bandtable[] = {
   {1,   1920000, 1980000, 2110000, 2170000, 20, 422000, 100},
   {2,   1850000, 1910000, 1930000, 1990000, 20, 386000, 100},
   {3,   1710000, 1785000, 1805000, 1880000, 20, 361000, 100},
@@ -117,7 +117,7 @@ uint16_t get_band(uint64_t downlink_frequency, int32_t delta_duplex)
   uint64_t center_freq_diff_khz = 999999999999999999; // 2^64
   uint16_t current_band = 0;
 
-  for (int ind = 0; ind < nr_bandtable_size; ind++) {
+  for (int ind = 0; ind < sizeofArray(nr_bandtable); ind++) {
 
     if (dl_freq_khz < nr_bandtable[ind].dl_min || dl_freq_khz > nr_bandtable[ind].dl_max)
       continue;
@@ -143,8 +143,6 @@ uint16_t get_band(uint64_t downlink_frequency, int32_t delta_duplex)
   return current_band;
 }
 
-const size_t nr_bandtable_size = sizeof(nr_bandtable) / sizeof(nr_bandentry_t);
-
 int NRRIV2BW(int locationAndBandwidth,int N_RB) {
   int tmp = locationAndBandwidth/N_RB;
   int tmp2 = locationAndBandwidth%N_RB;
@@ -459,31 +457,21 @@ uint16_t config_bandwidth(int mu, int nb_rb, int nr_band)
 
 // Returns the corresponding row index of the NR table
 int get_nr_table_idx(int nr_bandP, uint8_t scs_index) {
-  int i, j;
   int scs_khz = 15 << scs_index;
   int supplementary_bands[] = {29,75,76,80,81,82,83,84,86,89,95};
-  size_t s = sizeof(supplementary_bands)/sizeof(supplementary_bands[0]);
 
-  for(j = 0; j < s; j++){
+  for(int j = 0; j < sizeofArray(supplementary_bands); j++){
     if (nr_bandP == supplementary_bands[j])
       AssertFatal(0 == 1, "Band %d is a supplementary band (%d). This is not supported yet.\n", nr_bandP, supplementary_bands[j]);
   }
 
-  AssertFatal(nr_bandP <= nr_bandtable[nr_bandtable_size-1].band, "NR band %d exceeds NR bands table maximum limit %d\n", nr_bandP, nr_bandtable[nr_bandtable_size-1].band);
-  for (i = 0; i < nr_bandtable_size && nr_bandtable[i].band != nr_bandP; i++);
-
-  // In frequency bands with two deltaFRaster,
-  // the higher deltaFRaster applies to channels using only the SCS that is equal to or larger than the higher deltaFRaster
-  // and SSB SCS is equal to the higher deltaFRaster.
-  while(((i+1)<nr_bandtable_size) &&
-        (nr_bandtable[i+1].band == nr_bandtable[i].band) &&
-        (nr_bandtable[i].deltaf_raster != scs_khz)) {
-    i++;
+  int i;
+  for (i = 0; i < sizeofArray(nr_bandtable); i++) {
+    if ( nr_bandtable[i].band == nr_bandP && nr_bandtable[i].deltaf_raster == scs_khz )
+      break;
   }
 
-  AssertFatal(nr_bandtable[i].band == nr_bandP, "Found band table %d does not correspond to the input one %d\n",nr_bandtable[i].band,nr_bandP);
-
-
+  AssertFatal(i < sizeofArray(nr_bandtable), "band is not existing: %d\n",nr_bandP);
   LOG_D(PHY, "NR band table index %d (Band %d, dl_min %lu, ul_min %lu)\n", i, nr_bandtable[i].band, nr_bandtable[i].dl_min,nr_bandtable[i].ul_min);
 
   return i;
diff --git a/common/utils/nr/nr_common.h b/common/utils/nr/nr_common.h
index 44a6e055770..e7414c9f83c 100644
--- a/common/utils/nr/nr_common.h
+++ b/common/utils/nr/nr_common.h
@@ -48,8 +48,7 @@ typedef struct nr_bandentry_s {
   uint8_t deltaf_raster;
 } nr_bandentry_t;
 
-extern const size_t nr_bandtable_size;
-extern nr_bandentry_t nr_bandtable[];
+extern const nr_bandentry_t nr_bandtable[];
 static inline int get_num_dmrs(uint16_t dmrs_mask ) {
 
   int num_dmrs=0;
diff --git a/openair2/F1AP/f1ap_cu_interface_management.c b/openair2/F1AP/f1ap_cu_interface_management.c
index 7e9105a9700..73dd55ba7f1 100644
--- a/openair2/F1AP/f1ap_cu_interface_management.c
+++ b/openair2/F1AP/f1ap_cu_interface_management.c
@@ -115,34 +115,32 @@ int CU_handle_F1_SETUP_REQUEST(instance_t instance,
   F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_F1SetupRequestIEs_t, ie, container,
                              F1AP_ProtocolIE_ID_id_gNB_DU_Served_Cells_List, true);
   req->num_cells_available = ie->value.choice.GNB_DU_Served_Cells_List.list.count;
-  LOG_D(F1AP, "req->num_cells_available %d \n",
-        req->num_cells_available);
-  int num_cells_available = req->num_cells_available;
+  LOG_D(F1AP, "req->num_cells_available %d \n", req->num_cells_available);
 
-  for (i=0; i<num_cells_available; i++) {
+  for (i=0; i<req->num_cells_available; i++) {
     F1AP_GNB_DU_Served_Cells_Item_t *served_cells_item_p;
     served_cells_item_p = &(((F1AP_GNB_DU_Served_Cells_ItemIEs_t *)
                              ie->value.choice.GNB_DU_Served_Cells_List.list.array[i])->
                             value.choice.GNB_DU_Served_Cells_Item);
-
+    F1AP_Served_Cell_Information_t *served_cell_information= &gnb_du_served_cells_item->served_Cell_Information;
     /* tac */
-    if (served_cells_item_p->served_Cell_Information.fiveGS_TAC) {
-      OCTET_STRING_TO_INT16(served_cells_item_p->served_Cell_Information.fiveGS_TAC, req->cell[i].tac);
+    if (served_Cell_Information->fiveGS_TAC) {
+      OCTET_STRING_TO_INT16(served_Cell_Information->fiveGS_TAC, req->cell[i].tac);
       LOG_D(F1AP, "req->tac[%d] %d \n", i, req->cell[i].tac);
     }
 
     /* - nRCGI */
-    TBCD_TO_MCC_MNC(&(served_cells_item_p->served_Cell_Information.nRCGI.pLMN_Identity), req->cell[i].mcc,
+    TBCD_TO_MCC_MNC(&(served_Cell_Information->nRCGI.pLMN_Identity), req->cell[i].mcc,
                     req->cell[i].mnc,req->cell[i].mnc_digit_length);
     // NR cellID
-    BIT_STRING_TO_NR_CELL_IDENTITY(&served_cells_item_p->served_Cell_Information.nRCGI.nRCellIdentity,
+    BIT_STRING_TO_NR_CELL_IDENTITY(&served_Cell_Information->nRCGI.nRCellIdentity,
                                    req->cell[i].nr_cellid);
     LOG_D(F1AP, "[SCTP %d] Received nRCGI: MCC %d, MNC %d, CELL_ID %llu\n", assoc_id,
           req->cell[i].mcc,
           req->cell[i].mnc,
           (long long unsigned int)req->cell[i].nr_cellid);
     /* - nRPCI */
-    req->cell[i].nr_pci = served_cells_item_p->served_Cell_Information.nRPCI;
+    req->cell[i].nr_pci = served_Cell_Information->nRPCI;
     LOG_D(F1AP, "req->nr_pci[%d] %d \n", i, req->cell[i].nr_pci);
 
     // LTS: FIXME data model failure: we don't KNOW if we receive a 4G or a 5G cell
@@ -152,6 +150,8 @@ int CU_handle_F1_SETUP_REQUEST(instance_t instance,
     else
       f1ap_req(true, instance)->cell_type=CELL_MACRO_ENB;
 
+    
+
     LOG_I(F1AP, "Received Cell in %d context\n", f1ap_req(true, instance)->cell_type==CELL_MACRO_GNB);
     // System Information
     /* mib */
@@ -208,11 +208,14 @@ int CU_handle_F1_SETUP_REQUEST(instance_t instance,
   //     uint16_t nr_sul_band[32];
   //   } tdd;
   // } nr_mode_info[F1AP_MAX_NB_CELLS];
+
+
+  
   // We copy and store in F1 task data, RRC will free "req" as it frees all itti received messages
   message_p = itti_alloc_new_message(TASK_CU_F1, 0, F1AP_SETUP_REQ);
   memcpy(&F1AP_SETUP_REQ(message_p), req, sizeof(f1ap_setup_req_t) );
 
-  if (num_cells_available > 0) {
+  if (req->num_cells_available > 0) {
     if (f1ap_req(true, instance)->cell_type == CELL_MACRO_GNB) {
       itti_send_msg_to_task(TASK_RRC_GNB, GNB_MODULE_ID_TO_INSTANCE(instance), message_p);
     } else {
diff --git a/openair2/F1AP/f1ap_du_interface_management.c b/openair2/F1AP/f1ap_du_interface_management.c
index 12b05590038..1c6ec12556b 100644
--- a/openair2/F1AP/f1ap_du_interface_management.c
+++ b/openair2/F1AP/f1ap_du_interface_management.c
@@ -585,6 +585,7 @@ int DU_send_gNB_DU_CONFIGURATION_UPDATE(instance_t instance,
     MCC_MNC_TO_PLMNID(cell->mcc, cell->mnc, cell->mnc_digit_length, &servedPLMN_item->pLMN_Identity);
     // // /* - CHOICE NR-MODE-Info */
     F1AP_NR_Mode_Info_t *nR_Mode_Info=&served_cell_information->nR_Mode_Info;
+    LOG_E(F1AP,"Here hardcoded values instead of values from configuration file\n");
 
     if (f1ap_setup_req->fdd_flag) {
       nR_Mode_Info->present = F1AP_NR_Mode_Info_PR_fDD;
diff --git a/openair2/GNB_APP/gnb_app.c b/openair2/GNB_APP/gnb_app.c
index 9090761242b..7d51d958406 100644
--- a/openair2/GNB_APP/gnb_app.c
+++ b/openair2/GNB_APP/gnb_app.c
@@ -198,7 +198,6 @@ void *gNB_app_task(void *args_p)
 
   RC.nrrrc = (gNB_RRC_INST **)malloc(RC.nb_nr_inst*sizeof(gNB_RRC_INST *));
   LOG_I(PHY, "%s() RC.nb_nr_inst:%d RC.nrrrc:%p\n", __FUNCTION__, RC.nb_nr_inst, RC.nrrrc);
-
   for (gnb_id = gnb_id_start; (gnb_id < gnb_id_end) ; gnb_id++) {
     RC.nrrrc[gnb_id] = (gNB_RRC_INST*)calloc(1,sizeof(gNB_RRC_INST));
     LOG_I(PHY, "%s() Creating RRC instance RC.nrrrc[%d]:%p (%d of %d)\n", __FUNCTION__, gnb_id, RC.nrrrc[gnb_id], gnb_id+1, gnb_id_end);
-- 
GitLab