diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
index dc4d187842e02a8e686aac7b3cc9341ab650169c..26ef47f1525bc1b20d8757bd175d7968e8eb2959 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 445aa832cbceae4af9ef04c9d4b63e1125697fbf..dd9a5bb188d8220df57a2b5a8109ec9a181e87f0 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 2ac8d14a2359c5f42056a4321ec830cddb204dd8..771845d5d0084f5dca87f923b4e64a6ad67ccd34 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);