From a7b114c4ecbfeb98cf2866fe531514c0180f1a1b Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@eurecom.fr>
Date: Thu, 25 Oct 2018 10:23:43 +0200
Subject: [PATCH] RAN API: Check for MAC presence

---
 openair2/ENB_APP/flexran_agent_ran_api.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/openair2/ENB_APP/flexran_agent_ran_api.c b/openair2/ENB_APP/flexran_agent_ran_api.c
index 09088aa79d..7fb0d767e1 100644
--- a/openair2/ENB_APP/flexran_agent_ran_api.c
+++ b/openair2/ENB_APP/flexran_agent_ran_api.c
@@ -73,6 +73,7 @@ sub_frame_t flexran_get_current_subframe(mid_t mod_id)
 /* Why uint16_t, frame_t and sub_frame_t are defined as uint32_t? */
 uint16_t flexran_get_sfn_sf(mid_t mod_id)
 {
+  if (!mac_is_present(mod_id)) return 0;
   frame_t frame = flexran_get_current_system_frame_num(mod_id);
   sub_frame_t subframe = flexran_get_current_subframe(mod_id);
   uint16_t sfn_sf, frame_mask, sf_mask;
@@ -86,6 +87,7 @@ uint16_t flexran_get_sfn_sf(mid_t mod_id)
 
 uint16_t flexran_get_future_sfn_sf(mid_t mod_id, int ahead_of_time)
 {
+  if (!mac_is_present(mod_id)) return 0;
   frame_t frame = flexran_get_current_system_frame_num(mod_id);
   sub_frame_t subframe = flexran_get_current_subframe(mod_id);
   uint16_t sfn_sf, frame_mask, sf_mask;
@@ -114,6 +116,7 @@ int flexran_get_num_ues(mid_t mod_id)
 
 rnti_t flexran_get_ue_crnti(mid_t mod_id, mid_t ue_id)
 {
+  if (!mac_is_present(mod_id)) return 0;
   return UE_RNTI(mod_id, ue_id);
 }
 
@@ -137,6 +140,7 @@ uint8_t flexran_get_ue_wcqi(mid_t mod_id, mid_t ue_id)
 
 rlc_buffer_occupancy_t flexran_get_tx_queue_size(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id)
 {
+  if (!mac_is_present(mod_id)) return 0;
   rnti_t rnti = flexran_get_ue_crnti(mod_id, ue_id);
   frame_t frame = flexran_get_current_frame(mod_id);
   sub_frame_t subframe = flexran_get_current_subframe(mod_id);
@@ -150,6 +154,7 @@ rlc_buffer_occupancy_t flexran_get_tx_queue_size(mid_t mod_id, mid_t ue_id, logi
 
 rlc_buffer_occupancy_t flexran_get_num_pdus_buffer(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id)
 {
+  if (!mac_is_present(mod_id)) return 0;
   rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
   frame_t frame = flexran_get_current_frame(mod_id);
   sub_frame_t subframe = flexran_get_current_subframe(mod_id);
@@ -163,6 +168,7 @@ rlc_buffer_occupancy_t flexran_get_num_pdus_buffer(mid_t mod_id, mid_t ue_id, lo
 
 frame_t flexran_get_hol_delay(mid_t mod_id, mid_t ue_id, logical_chan_id_t channel_id)
 {
+  if (!mac_is_present(mod_id)) return 0;
   rnti_t rnti = flexran_get_ue_crnti(mod_id,ue_id);
   frame_t frame = flexran_get_current_frame(mod_id);
   sub_frame_t subframe = flexran_get_current_subframe(mod_id);
-- 
GitLab