diff --git a/lib/include/srsran/mac/mac_sch_pdu_nr.h b/lib/include/srsran/mac/mac_sch_pdu_nr.h index 08da38bca..197612d39 100644 --- a/lib/include/srsran/mac/mac_sch_pdu_nr.h +++ b/lib/include/srsran/mac/mac_sch_pdu_nr.h @@ -128,7 +128,7 @@ public: const mac_sch_subpdu_nr& get_subpdu(const uint32_t& index); bool is_ulsch(); - void init_tx(byte_buffer_t* buffer_, uint32_t pdu_len_, bool is_ulsch_ = false); + int init_tx(byte_buffer_t* buffer_, uint32_t pdu_len_, bool is_ulsch_ = false); void init_rx(bool ulsch_ = false); // Add SDU or CEs to PDU diff --git a/lib/src/mac/mac_sch_pdu_nr.cc b/lib/src/mac/mac_sch_pdu_nr.cc index e06b50831..17c5f93a1 100644 --- a/lib/src/mac/mac_sch_pdu_nr.cc +++ b/lib/src/mac/mac_sch_pdu_nr.cc @@ -334,13 +334,18 @@ bool mac_sch_pdu_nr::is_ulsch() return ulsch; } -void mac_sch_pdu_nr::init_tx(byte_buffer_t* buffer_, uint32_t pdu_len_, bool ulsch_) +int mac_sch_pdu_nr::init_tx(byte_buffer_t* buffer_, uint32_t pdu_len_, bool ulsch_) { + if (buffer_ == nullptr || buffer_->msg == nullptr) { + logger.error("Invalid buffer"); + return SRSRAN_ERROR; + } buffer = buffer_; subpdus.clear(); pdu_len = pdu_len_; remaining_len = pdu_len_; ulsch = ulsch_; + return SRSRAN_SUCCESS; } void mac_sch_pdu_nr::init_rx(bool ulsch_) diff --git a/srsenb/src/stack/mac/nr/ue_nr.cc b/srsenb/src/stack/mac/nr/ue_nr.cc index 26a48d126..c124e41e8 100644 --- a/srsenb/src/stack/mac/nr/ue_nr.cc +++ b/srsenb/src/stack/mac/nr/ue_nr.cc @@ -111,7 +111,10 @@ int ue_nr::generate_pdu(srsran::byte_buffer_t* pdu, uint32_t grant_size) { std::lock_guard lock(mutex); - mac_pdu_dl.init_tx(pdu, grant_size); + if (mac_pdu_dl.init_tx(pdu, grant_size) != SRSRAN_SUCCESS) { + logger.error("Couldn't initialize MAC PDU buffer"); + return SRSRAN_ERROR; + } // read RLC PDU ue_rlc_buffer->clear();