From 66395ff7b795dc3953d52ea05000e0f2b1e7e70a Mon Sep 17 00:00:00 2001
From: cig <guido.casati@iis.fraunhofer.de>
Date: Fri, 8 May 2020 11:56:52 +0200
Subject: [PATCH] Set RA offset at UE to compensate for 2 frames offset
 introduced by gNB

---
 openair2/LAYER2/NR_MAC_UE/mac_defs.h         | 2 ++
 openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 2 ++
 openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c  | 2 +-
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h
index 368eae96824..a7115617479 100755
--- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h
+++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h
@@ -188,6 +188,8 @@ typedef struct {
   /* Random Access parameters */
   /// state of RA procedure
   RA_state_t ra_state;
+  /// RA rx frame offset: compensate RA rx offset introduced by OAI gNB.
+  uint8_t RA_offset;
   /// RA-rnti
   uint16_t ra_rnti;
   /// Temporary CRNTI
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
index 0ec27e401cc..57a69e836ca 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
@@ -887,6 +887,8 @@ void nr_ue_prach_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t s
   NR_RACH_ConfigGeneric_t *rach_ConfigGeneric = &setup->rach_ConfigGeneric;
   config_index = rach_ConfigGeneric->prach_ConfigurationIndex;
 
+  mac->RA_offset = 2; // to compensate the rx frame offset at the gNB
+
   if (is_nr_UL_slot(scc, slotP)) {
 
     if (setup->msg1_SubcarrierSpacing)
diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
index 27903d8a3bb..75ae4cd12ec 100644
--- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
+++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c
@@ -120,7 +120,7 @@ int nr_ue_ul_indication(nr_uplink_indication_t *ul_info){
     if (mac->generate_nr_prach){
       uint16_t monitoring_slot_period, monitoring_offset;
       uint16_t rach_frame = mac->scheduled_response.ul_config->sfn;
-      uint16_t rx_rach_frame = (rach_frame + 2) % MAX_FRAME_NUMBER; // compensate 2 frames offset delay at gNB side
+      uint16_t rx_rach_frame = (rach_frame + mac->RA_offset) % MAX_FRAME_NUMBER; // compensate 2 frames offset delay at gNB side
       uint16_t rach_slot  = mac->scheduled_response.ul_config->slot;
       nr_ue_msg2_scheduler(module_id, rx_rach_frame, rach_slot, &mac->msg2_rx_frame, &mac->msg2_rx_slot);
     }
-- 
GitLab