From f1455f15a3e184139ac3bbb92f43e65ac8f5e390 Mon Sep 17 00:00:00 2001
From: matzakos <matzakos@eurecom.fr>
Date: Wed, 10 Nov 2021 18:33:48 +0100
Subject: [PATCH] Check whether RRC Setup is available before sending CBRA Msg4

-Required for the CU/DU split case if the RRC Setup arrives later than the first opportunity to transmit Msg4
-Next extension is to decouple RRCSetup from Msg4
---
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c | 5 +++++
 openair2/RRC/NR/L2_nr_interface.c             | 8 ++++++++
 openair2/RRC/NR/nr_rrc_proto.h                | 6 ++++++
 3 files changed, 19 insertions(+)

diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
index dc4d187842e..26ef47f1525 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
@@ -1388,6 +1388,11 @@ void nr_generate_Msg4(module_id_t module_idP, int CC_id, frame_t frameP, sub_fra
 
   if (ra->Msg4_frame == frameP && ra->Msg4_slot == slotP ) {
 
+    if (nr_mac_rrc_check_RRCSetup(module_idP, ra->rnti) <= 0){
+      ra->Msg4_frame++;
+      return;
+    }
+
     uint8_t time_domain_assignment = 0;
     uint8_t mcsIndex = 0;
 
diff --git a/openair2/RRC/NR/L2_nr_interface.c b/openair2/RRC/NR/L2_nr_interface.c
index 445aa832cbc..dd9a5bb188d 100644
--- a/openair2/RRC/NR/L2_nr_interface.c
+++ b/openair2/RRC/NR/L2_nr_interface.c
@@ -304,6 +304,14 @@ int8_t mac_rrc_nr_data_req(const module_id_t Mod_idP,
 
 }
 
+int8_t nr_mac_rrc_check_RRCSetup(const module_id_t Mod_idP,
+                               const rnti_t      rnti) {
+  struct rrc_gNB_ue_context_s *ue_context_p = rrc_gNB_get_ue_context(RC.nrrrc[Mod_idP], rnti);
+  char payload_size = ue_context_p->ue_context.Srb0.Tx_buffer.payload_size;
+  return payload_size;
+
+}
+
 int8_t nr_mac_rrc_data_ind(const module_id_t     module_idP,
                            const int             CC_id,
                            const frame_t         frameP,
diff --git a/openair2/RRC/NR/nr_rrc_proto.h b/openair2/RRC/NR/nr_rrc_proto.h
index 2ac8d14a235..771845d5d00 100644
--- a/openair2/RRC/NR/nr_rrc_proto.h
+++ b/openair2/RRC/NR/nr_rrc_proto.h
@@ -170,6 +170,12 @@ nr_rrc_data_req(
   const pdcp_transmission_mode_t modeP
 );
 
+int8_t nr_mac_rrc_check_RRCSetup(
+  const module_id_t Mod_idP,
+  const rnti_t      rnti
+
+);
+
 int
 nr_rrc_mac_remove_ue(module_id_t mod_idP,
                   rnti_t rntiP);
-- 
GitLab