From d1ad31596921a78fdbc20f4f4e26a1e6f92572cf Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Fri, 9 Apr 2021 22:53:24 +0200 Subject: [PATCH] mac_nr: add various safety/length checks --- srsue/src/stack/mac_nr/mac_nr.cc | 17 +++++++++++------ srsue/src/stack/mac_nr/mux_nr.cc | 6 ++++++ srsue/src/stack/mac_nr/proc_bsr_nr.cc | 6 ++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/srsue/src/stack/mac_nr/mac_nr.cc b/srsue/src/stack/mac_nr/mac_nr.cc index bfbd15824..53d2253fa 100644 --- a/srsue/src/stack/mac_nr/mac_nr.cc +++ b/srsue/src/stack/mac_nr/mac_nr.cc @@ -128,7 +128,8 @@ void mac_nr::update_buffer_states() mac_buffer_states.lcid_buffer_size[channel.lcid] += buffer_len; mac_buffer_states.lcg_buffer_size[channel.lcg] += buffer_len; } - logger.info("%s", mac_buffer_states.to_string()); + logger.debug("%s", mac_buffer_states.to_string()); + // Count TTI for metrics for (uint32_t i = 0; i < SRSRAN_MAX_CARRIERS; ++i) { metrics[i].nof_tti++; @@ -286,11 +287,15 @@ void mac_nr::new_grant_ul(const uint32_t cc_idx, const mac_nr_grant_ul_t& grant, ul_harq_buffer = mux.get_pdu(grant.tbs); // fill TB action (goes into UL harq eventually) - action->tb.payload = ul_harq_buffer.get(); // pass handle to PDU to PHY - action->tb.enabled = true; - action->tb.rv = 0; - action->tb.softbuffer = &softbuffer_tx; - srsran_softbuffer_tx_reset(&softbuffer_tx); + if (ul_harq_buffer != nullptr) { + action->tb.payload = ul_harq_buffer.get(); // pass handle to PDU to PHY + action->tb.enabled = true; + action->tb.rv = 0; + action->tb.softbuffer = &softbuffer_tx; + srsran_softbuffer_tx_reset(&softbuffer_tx); + } else { + action->tb.enabled = false; + } // store PCAP if (pcap) { diff --git a/srsue/src/stack/mac_nr/mux_nr.cc b/srsue/src/stack/mac_nr/mux_nr.cc index a33213516..f949d960b 100644 --- a/srsue/src/stack/mac_nr/mux_nr.cc +++ b/srsue/src/stack/mac_nr/mux_nr.cc @@ -49,6 +49,12 @@ srsran::unique_byte_buffer_t mux_nr::get_pdu(uint32_t max_pdu_len) return nullptr; } + // verify buffer is large enough for UL grant + if (phy_tx_pdu->get_tailroom() < max_pdu_len) { + logger.error("Can't provide MAC PDU. Grant too big (%d < %d).", phy_tx_pdu->get_tailroom(), max_pdu_len); + return nullptr; + } + logger.debug("Building new MAC PDU (%d B)", max_pdu_len); tx_pdu.init_tx(phy_tx_pdu.get(), max_pdu_len, true); diff --git a/srsue/src/stack/mac_nr/proc_bsr_nr.cc b/srsue/src/stack/mac_nr/proc_bsr_nr.cc index 5ea11ecc8..afb6aca56 100644 --- a/srsue/src/stack/mac_nr/proc_bsr_nr.cc +++ b/srsue/src/stack/mac_nr/proc_bsr_nr.cc @@ -199,8 +199,10 @@ bool proc_bsr_nr::check_new_data(const mac_buffer_states_t& new_buffer_state) srsran::mac_sch_subpdu_nr::lcg_bsr_t proc_bsr_nr::generate_sbsr() { srsran::mac_sch_subpdu_nr::lcg_bsr_t sbsr = {}; - sbsr.lcg_id = buffer_state.last_non_zero_lcg; - sbsr.buffer_size = buff_size_bytes_to_field(buffer_state.lcg_buffer_size.at(sbsr.lcg_id), SHORT_BSR); + if (buffer_state.nof_lcgs_with_data > 0) { + sbsr.lcg_id = buffer_state.last_non_zero_lcg; + sbsr.buffer_size = buff_size_bytes_to_field(buffer_state.lcg_buffer_size.at(sbsr.lcg_id), SHORT_BSR); + } triggered_bsr_type = NONE; return sbsr; }