From 4df3157a7ac681058bc5a6cef39d3c90e1ba08f1 Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@eurecom.fr>
Date: Thu, 19 Mar 2020 09:33:18 +0100
Subject: [PATCH] L2: do not overwrite FAPI message, correct check

---
 openair2/PHY_INTERFACE/phy_stub_UE.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index 4d3b579f845..8a238fa5b5d 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -791,7 +791,11 @@ int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req, module_id_t Mod_id) {
                       tx_request_pdu_list[pdu_index].segments[0].segment_data,
                       tx_request_pdu_list[pdu_index].segments[0].segment_length);
         } else if (rnti == 0x0002) { /* RA-RNTI */
-          LOG_E(MAC, "%s(): Received RAR?\n", __func__);
+          if (UE_mac_inst[Mod_id].UE_mode[0] != RA_RESPONSE) {
+            LOG_D(MAC, "UE %d not awaiting RAR, is in mode %d\n",
+                  Mod_id, UE_mac_inst[Mod_id].UE_mode[0]);
+            continue;
+          }
           // RNTI parameter not actually used. Provided only to comply with
           // existing function definition.  Not sure about parameters to fill
           // the preamble index.
@@ -806,7 +810,7 @@ int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req, module_id_t Mod_id) {
             ue_process_rar(Mod_id, 0, sfn,
                 ra_rnti, //RA-RNTI
                 tx_request_pdu_list[pdu_index].segments[0].segment_data,
-                &dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.rnti, //t-crnti
+                &UE_mac_inst[Mod_id].crnti, //t-crnti
                 UE_mac_inst[Mod_id].RA_prach_resources.ra_PreambleIndex,
                 tx_request_pdu_list[pdu_index].segments[0].segment_data);
             UE_mac_inst[Mod_id].UE_mode[0] = RA_RESPONSE;
-- 
GitLab