From a8a431b9555b7abda9a8f1a0bf52939689b55215 Mon Sep 17 00:00:00 2001
From: francescomani <francesco.mani@eurecom.fr>
Date: Thu, 9 Dec 2021 10:37:22 +0100
Subject: [PATCH] fix for fr2 msg3

---
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c | 2 +-
 openair2/RRC/NR/nr_rrc_config.c               | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
index 4851aa4ef0..2705b85b8c 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
@@ -885,7 +885,7 @@ void nr_get_Msg3alloc(module_id_t module_id,
     for (int i=0; i<pusch_TimeDomainAllocationList->list.count; i++) {
       k2 = *pusch_TimeDomainAllocationList->list.array[i]->k2;
       // we want to transmit in the uplink symbols of mixed slot
-      if (k2 + DELTA[mu] == nb_slots_per_period) {
+      if ((k2 + DELTA[mu])%nb_slots_per_period == 0) {
         temp_slot = current_slot + k2 + DELTA[mu]; // msg3 slot according to 8.3 in 38.213
         ra->Msg3_slot = temp_slot%nr_slots_per_frame[mu];
         if (is_xlsch_in_slot(RC.nrmac[module_id]->ulsch_slot_bitmap[ra->Msg3_slot / 64], ra->Msg3_slot)) {
diff --git a/openair2/RRC/NR/nr_rrc_config.c b/openair2/RRC/NR/nr_rrc_config.c
index 08ce820283..b4cbe7b8bc 100644
--- a/openair2/RRC/NR/nr_rrc_config.c
+++ b/openair2/RRC/NR/nr_rrc_config.c
@@ -89,8 +89,10 @@ void nr_rrc_config_ul_tda(NR_ServingCellConfigCommon_t *scc, int min_fb_delay){
       struct NR_PUSCH_TimeDomainResourceAllocation *pusch_timedomainresourceallocation_msg3 = CALLOC(1,sizeof(struct NR_PUSCH_TimeDomainResourceAllocation));
       pusch_timedomainresourceallocation_msg3->k2  = CALLOC(1,sizeof(long));
       *pusch_timedomainresourceallocation_msg3->k2 = nb_slots_per_period - DELTA[mu];
-      AssertFatal(*pusch_timedomainresourceallocation_msg3->k2>=min_fb_delay,"Computed k2 for msg3 %ld is smaller than min feedback delay set in config file %d\n",
-                  *pusch_timedomainresourceallocation_msg3->k2, min_fb_delay);
+      if(*pusch_timedomainresourceallocation_msg3->k2 < min_fb_delay)
+        *pusch_timedomainresourceallocation_msg3->k2 += nb_slots_per_period;
+      AssertFatal(*pusch_timedomainresourceallocation_msg3->k2<33,"Computed k2 for msg3 %ld is larger than the range allowed by RRC (0..32)\n",
+                  *pusch_timedomainresourceallocation_msg3->k2);
       pusch_timedomainresourceallocation_msg3->mappingType = NR_PUSCH_TimeDomainResourceAllocation__mappingType_typeB;
       pusch_timedomainresourceallocation_msg3->startSymbolAndLength = get_SLIV(14-ul_symb,ul_symb-1); // starting in fist ul symbol til the last but one
       ASN_SEQUENCE_ADD(&scc->uplinkConfigCommon->initialUplinkBWP->pusch_ConfigCommon->choice.setup->pusch_TimeDomainAllocationList->list,pusch_timedomainresourceallocation_msg3);
-- 
2.26.2