From 738d61a173d215b73f3b5f17e059d301be012237 Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@eurecom.fr>
Date: Mon, 21 Sep 2020 16:08:24 +0200
Subject: [PATCH] Remove fiveG_connected and use active

---
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c    | 21 ++++++++++---------
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c |  6 ++----
 .../NR_MAC_gNB/gNB_scheduler_primitives.c     |  4 ++--
 .../LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c   | 12 +++++------
 openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h       |  1 -
 5 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
index 0f39fb9302..eacc8d14b8 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
@@ -411,14 +411,16 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
   const int num_slots_per_tdd = slots_per_frame[*scc->ssbSubcarrierSpacing] >> (7 - tdd_pattern->dl_UL_TransmissionPeriodicity);
   const int nr_ulmix_slots = tdd_pattern->nrofUplinkSlots + (tdd_pattern->nrofUplinkSymbols!=0);
 
-  if (slot== 0 && (UE_info->fiveG_connected[UE_id] || get_softmodem_params()->phy_test)) {
+  if (slot == 0 && UE_info->active[UE_id]) {
     for (int k=0; k<nr_ulmix_slots; k++) {
-      memset((void *) &UE_info->UE_sched_ctrl[UE_id].sched_pucch[k],
+      /* Seems to be covered 384? */
+      /*memset((void *) &UE_info->UE_sched_ctrl[UE_id].sched_pucch[k],
              0,
-             sizeof(NR_sched_pucch));
-      memset((void *) &UE_info->UE_sched_ctrl[UE_id].sched_pusch[k],
+             sizeof(NR_sched_pucch));*/
+      /* Seems to be covered in line 335? */
+      /*memset((void *) &UE_info->UE_sched_ctrl[UE_id].sched_pusch[k],
              0,
-             sizeof(NR_sched_pusch));
+             sizeof(NR_sched_pusch));*/
     }
   }
 
@@ -470,8 +472,7 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
   if (get_softmodem_params()->phy_test == 0) {
     nr_schedule_RA(module_idP, frame, slot);
     nr_schedule_reception_msg3(module_idP, 0, frame, slot);
-  } else
-    UE_info->fiveG_connected[UE_id] = true;
+  }
 
   if (get_softmodem_params()->phy_test) {
 
@@ -493,13 +494,13 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
   // This schedules the DCI for Uplink and subsequently PUSCH
   // The decision about whether to schedule is done for each UE independently
   // inside
-  if (UE_info->fiveG_connected[UE_id]) {
+  if (UE_info->active[UE_id]) {
     int tda = 1; // time domain assignment hardcoded for now
     schedule_fapi_ul_pdu(module_idP, frame, slot, num_slots_per_tdd, nr_ulmix_slots, tda, ulsch_in_slot_bitmap);
     nr_schedule_pusch(module_idP, UE_id, num_slots_per_tdd, nr_ulmix_slots, frame, slot);
   }
 
-  if (UE_info->fiveG_connected[UE_id]
+  if (UE_info->active[UE_id]
       && (is_xlsch_in_slot(dlsch_in_slot_bitmap, slot % num_slots_per_tdd))
       && (!get_softmodem_params()->phy_test || slot == 1)) {
     ue_sched_ctl->current_harq_pid = slot % num_slots_per_tdd;
@@ -511,7 +512,7 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
     gNB->ta_len = 0;
   }
 
-  if (UE_info->fiveG_connected[UE_id])
+  if (UE_info->active[UE_id])
     nr_schedule_pucch(module_idP, UE_id, nr_ulmix_slots, frame, slot);
 
   stop_meas(&RC.nrmac[module_idP]->eNB_scheduler);
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
index 46a30ad0b6..5f7ae0c7dd 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
@@ -268,9 +268,7 @@ void nr_initiate_ra_proc(module_id_t module_idP,
       break;
     }
   }
-  if (pr_found)
-    UE_info->fiveG_connected[UE_id] = false;
-  else {
+  if (!pr_found) {
     LOG_E(MAC, "[gNB %d][RAPROC] FAILURE: preamble %d does not correspond to any of the ones in rach_ConfigDedicated for UE_id %d\n",
           module_idP, preamble_index, UE_id);
     return; // if the PRACH preamble does not correspond to any of the ones sent through RRC abort RA proc
@@ -448,7 +446,7 @@ void nr_add_msg3(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t
   memset(pusch_pdu, 0, sizeof(nfapi_nr_pusch_pdu_t));
 
 
-  AssertFatal(UE_info->active[UE_id],"Cannot find UE_id %d is not active\n", UE_id);
+  AssertFatal(!UE_info->active[UE_id], "UE_id %d is already active\n", UE_id);
 
   NR_CellGroupConfig_t *secondaryCellGroup = UE_info->secondaryCellGroup[UE_id];
   AssertFatal(secondaryCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList->list.count == 1,
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
index bdaa402dad..d325bf0c07 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
@@ -1626,7 +1626,7 @@ int add_new_nr_ue(module_id_t mod_idP, rnti_t rntiP){
   int num_slots_ul = scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSlots;
   if (scc->tdd_UL_DL_ConfigurationCommon->pattern1.nrofUplinkSymbols>0)
     num_slots_ul++;
-  LOG_I(MAC, "[gNB %d] Adding UE with rnti %x (num_UEs %d)\n",
+  LOG_W(MAC, "[gNB %d] Adding UE with rnti %x (num_UEs %d)\n",
         mod_idP,
         rntiP,
         UE_info->num_UEs);
@@ -1638,7 +1638,7 @@ int add_new_nr_ue(module_id_t mod_idP, rnti_t rntiP){
 
     int UE_id = i;
     UE_info->num_UEs++;
-    UE_info->active[UE_id] = true;
+    UE_info->active[UE_id] = false; /* not yet active, we wait for RA! */
     UE_info->rnti[UE_id] = rntiP;
     add_nr_ue_list(&UE_info->list, UE_id);
     memset((void *) &UE_info->UE_sched_ctrl[UE_id],
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
index b68c452f16..0e977c5352 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
@@ -369,13 +369,11 @@ void nr_rx_sdu(const module_id_t gnb_mod_idP,
     // random access pusch with TC-RNTI
     if (sduP != NULL) { // if the CRC passed
       for (int i = 0; i < MAX_MOBILES_PER_GNB; i++) {
-        if (UE_info->active[i]) {
-          if (UE_info->tc_rnti[i] == current_rnti) {
-            // for now the only thing we are doing is set the UE as 5G connected
-            UE_info->fiveG_connected[i] = true;
-            LOG_I(MAC, "[gNB %d][RAPROC] PUSCH with TC_RNTI %x received correctly and UE_id %d is now 5G connected\n",
-                  gnb_mod_idP, current_rnti, i);
-          }
+        if (UE_info->tc_rnti[i] == current_rnti) {
+          // for now the only thing we are doing is set the UE as active
+          UE_info->active[i] = true;
+          LOG_W(MAC, "[gNB %d][RAPROC] PUSCH with TC_RNTI %x received correctly and UE_id %d is now 5G connected\n",
+                gnb_mod_idP, current_rnti, i);
         }
       }
     }
diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
index 64117b4d9a..4c1c440617 100644
--- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
+++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h
@@ -360,7 +360,6 @@ typedef struct {
   NR_UE_list_t list;
   int num_UEs;
   bool active[MAX_MOBILES_PER_GNB];
-  boolean_t fiveG_connected[MAX_MOBILES_PER_GNB];
   rnti_t rnti[MAX_MOBILES_PER_GNB];
   rnti_t tc_rnti[MAX_MOBILES_PER_GNB];
   NR_preamble_ue preambles[MAX_MOBILES_PER_GNB];
-- 
2.26.2