all: check return value of make_byte_buffer() and handle them safely

master
Andre Puschmann 4 years ago
parent 46d46e70ff
commit 1a0891df51

@ -363,6 +363,9 @@ private:
uint32_t len = sizeof(*msg) - sizeof(msg->pdus->data) + msg->pdus->length; uint32_t len = sizeof(*msg) - sizeof(msg->pdus->data) + msg->pdus->length;
srsran::unique_byte_buffer_t tx = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t tx = srsran::make_byte_buffer();
if (tx == nullptr) {
return -1;
}
memcpy(tx->msg, msg, len); memcpy(tx->msg, msg, len);
rf_out_queue->push(std::move(tx)); rf_out_queue->push(std::move(tx));
} }

@ -183,14 +183,15 @@ int srsran_basic_vnf::handle_dl_ind(basic_vnf_api::dl_ind_msg_t* msg)
for (uint32_t i = 0; i < msg->nof_pdus; ++i) { for (uint32_t i = 0; i < msg->nof_pdus; ++i) {
dl_grant.tb[i] = srsran::make_byte_buffer(); dl_grant.tb[i] = srsran::make_byte_buffer();
if (dl_grant.tb[i]->get_tailroom() >= msg->pdus[i].length) { if (dl_grant.tb[i] && dl_grant.tb[i]->get_tailroom() >= msg->pdus[i].length) {
memcpy(dl_grant.tb[i]->msg, msg->pdus[i].data, msg->pdus[i].length); memcpy(dl_grant.tb[i]->msg, msg->pdus[i].data, msg->pdus[i].length);
dl_grant.tb[i]->N_bytes = msg->pdus[i].length; dl_grant.tb[i]->N_bytes = msg->pdus[i].length;
if (msg->pdus[i].type == basic_vnf_api::PDSCH) { if (msg->pdus[i].type == basic_vnf_api::PDSCH) {
m_ue_stack->tb_decoded(cc_idx, dl_grant); m_ue_stack->tb_decoded(cc_idx, dl_grant);
} }
} else { } else {
logger.error("TB too big to fit into buffer (%d > %d)", msg->pdus[i].length, dl_grant.tb[i]->get_tailroom()); logger.error("TB too big to fit into buffer (%d)", msg->pdus[i].length);
return SRSRAN_ERROR;
} }
} }

@ -958,8 +958,12 @@ std::map<uint32_t, srsran::unique_byte_buffer_t> undelivered_sdus_queue::get_buf
if (sdu.sdu != nullptr) { if (sdu.sdu != nullptr) {
// TODO: Find ways to avoid deep copy // TODO: Find ways to avoid deep copy
srsran::unique_byte_buffer_t fwd_sdu = make_byte_buffer(); srsran::unique_byte_buffer_t fwd_sdu = make_byte_buffer();
*fwd_sdu = *sdu.sdu; if (fwd_sdu != nullptr) {
fwd_sdus.emplace(sdu.sdu->md.pdcp_sn, std::move(fwd_sdu)); *fwd_sdu = *sdu.sdu;
fwd_sdus.emplace(sdu.sdu->md.pdcp_sn, std::move(fwd_sdu));
} else {
srslog::fetch_basic_logger("PDCP").warning("Can't allocate buffer to forward buffered SDUs.");
}
} }
} }
return fwd_sdus; return fwd_sdus;

@ -32,7 +32,9 @@ int nas_dedicated_eps_bearer_context_setup_request_test()
srsran::unique_byte_buffer_t tst_msg, out_msg; srsran::unique_byte_buffer_t tst_msg, out_msg;
tst_msg = srsran::make_byte_buffer(); tst_msg = srsran::make_byte_buffer();
TESTASSERT(tst_msg != nullptr);
out_msg = srsran::make_byte_buffer(); out_msg = srsran::make_byte_buffer();
TESTASSERT(out_msg != nullptr);
LIBLTE_MME_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT ded_bearer_req; LIBLTE_MME_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST_MSG_STRUCT ded_bearer_req;

@ -27,6 +27,9 @@ void* write_thread(void* a)
args_t* args = (args_t*)a; args_t* args = (args_t*)a;
for (uint32_t i = 0; i < NMSGS; i++) { for (uint32_t i = 0; i < NMSGS; i++) {
unique_byte_buffer_t b = srsran::make_byte_buffer(); unique_byte_buffer_t b = srsran::make_byte_buffer();
if (b == nullptr) {
return nullptr;
}
memcpy(b->msg, &i, 4); memcpy(b->msg, &i, 4);
b->N_bytes = 4; b->N_bytes = 4;
args->q->write(std::move(b)); args->q->write(std::move(b));

@ -200,6 +200,7 @@ int test_visit()
// TEST: visitor hits type E and steals pdu // TEST: visitor hits type E and steals pdu
E e; E e;
e.pdu = srsran::make_byte_buffer(); e.pdu = srsran::make_byte_buffer();
TESTASSERT(e.pdu != nullptr);
c = std::move(e); c = std::move(e);
TESTASSERT(c.is<E>() and srsran::get<E>(c).pdu != nullptr); TESTASSERT(c.is<E>() and srsran::get<E>(c).pdu != nullptr);
srsran::visit(v, c); srsran::visit(v, c);
@ -209,6 +210,7 @@ int test_visit()
// TEST: visitor hits type E and steals pdu. Second type called there is no pdu to steal. // TEST: visitor hits type E and steals pdu. Second type called there is no pdu to steal.
v.pdu = nullptr; v.pdu = nullptr;
e.pdu = srsran::make_byte_buffer(); e.pdu = srsran::make_byte_buffer();
TESTASSERT(e.pdu != nullptr);
c = std::move(e); c = std::move(e);
srsran::visit(v, c); srsran::visit(v, c);
TESTASSERT(v.pdu != nullptr); TESTASSERT(v.pdu != nullptr);

@ -37,10 +37,12 @@ int test_tx_sdu_notify(const srsran::pdcp_lte_state_t& init_state,
// Write test SDU // Write test SDU
srsran::unique_byte_buffer_t sdu = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t sdu = srsran::make_byte_buffer();
TESTASSERT(sdu != nullptr);
sdu->append_bytes(sdu1, sizeof(sdu1)); sdu->append_bytes(sdu1, sizeof(sdu1));
pdcp->write_sdu(std::move(sdu)); pdcp->write_sdu(std::move(sdu));
srsran::unique_byte_buffer_t out_pdu = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t out_pdu = srsran::make_byte_buffer();
TESTASSERT(out_pdu != nullptr);
rlc->get_last_sdu(out_pdu); rlc->get_last_sdu(out_pdu);
TESTASSERT(out_pdu->N_bytes == 4); TESTASSERT(out_pdu->N_bytes == 4);
@ -84,10 +86,12 @@ int test_tx_sdu_discard(const srsran::pdcp_lte_state_t& init_state,
// Write test SDU // Write test SDU
srsran::unique_byte_buffer_t sdu = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t sdu = srsran::make_byte_buffer();
TESTASSERT(sdu != nullptr);
sdu->append_bytes(sdu1, sizeof(sdu1)); sdu->append_bytes(sdu1, sizeof(sdu1));
pdcp->write_sdu(std::move(sdu)); pdcp->write_sdu(std::move(sdu));
srsran::unique_byte_buffer_t out_pdu = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t out_pdu = srsran::make_byte_buffer();
TESTASSERT(out_pdu != nullptr);
rlc->get_last_sdu(out_pdu); rlc->get_last_sdu(out_pdu);
TESTASSERT(out_pdu->N_bytes == 4); TESTASSERT(out_pdu->N_bytes == 4);

@ -52,13 +52,13 @@ public:
explicit rrc(srsran::task_sched_handle task_sched_); explicit rrc(srsran::task_sched_handle task_sched_);
~rrc(); ~rrc();
void init(const rrc_cfg_t& cfg_, int32_t init(const rrc_cfg_t& cfg_,
phy_interface_rrc_lte* phy, phy_interface_rrc_lte* phy,
mac_interface_rrc* mac, mac_interface_rrc* mac,
rlc_interface_rrc* rlc, rlc_interface_rrc* rlc,
pdcp_interface_rrc* pdcp, pdcp_interface_rrc* pdcp,
s1ap_interface_rrc* s1ap, s1ap_interface_rrc* s1ap,
gtpu_interface_rrc* gtpu); gtpu_interface_rrc* gtpu);
void stop(); void stop();
void get_metrics(rrc_metrics_t& m); void get_metrics(rrc_metrics_t& m);

@ -63,13 +63,13 @@ class rrc_nr final : public rrc_interface_pdcp_nr,
public: public:
explicit rrc_nr(srsran::timer_handler* timers_); explicit rrc_nr(srsran::timer_handler* timers_);
void init(const rrc_nr_cfg_t& cfg, int32_t init(const rrc_nr_cfg_t& cfg,
phy_interface_stack_nr* phy, phy_interface_stack_nr* phy,
mac_interface_rrc_nr* mac, mac_interface_rrc_nr* mac,
rlc_interface_rrc_nr* rlc, rlc_interface_rrc_nr* rlc,
pdcp_interface_rrc_nr* pdcp, pdcp_interface_rrc_nr* pdcp,
ngap_interface_rrc_nr* ngap_, ngap_interface_rrc_nr* ngap_,
gtpu_interface_rrc_nr* gtpu); gtpu_interface_rrc_nr* gtpu);
void stop(); void stop();
@ -78,7 +78,7 @@ public:
rrc_nr_cfg_t update_default_cfg(const rrc_nr_cfg_t& rrc_cfg); rrc_nr_cfg_t update_default_cfg(const rrc_nr_cfg_t& rrc_cfg);
void add_user(uint16_t rnti); void add_user(uint16_t rnti);
void config_mac(); void config_mac();
uint32_t generate_sibs(); int32_t generate_sibs();
int read_pdu_bcch_bch(const uint32_t tti, srsran::unique_byte_buffer_t& buffer) final; int read_pdu_bcch_bch(const uint32_t tti, srsran::unique_byte_buffer_t& buffer) final;
int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::unique_byte_buffer_t& buffer) final; int read_pdu_bcch_dlsch(uint32_t sib_index, srsran::unique_byte_buffer_t& buffer) final;

@ -122,7 +122,10 @@ int enb_stack_lte::init(const stack_args_t& args_, const rrc_cfg_t& rrc_cfg_)
} }
rlc.init(&pdcp, &rrc, &mac, task_sched.get_timer_handler()); rlc.init(&pdcp, &rrc, &mac, task_sched.get_timer_handler());
pdcp.init(&rlc, &rrc, &gtpu); pdcp.init(&rlc, &rrc, &gtpu);
rrc.init(rrc_cfg, phy, &mac, &rlc, &pdcp, &s1ap, &gtpu); if (rrc.init(rrc_cfg, phy, &mac, &rlc, &pdcp, &s1ap, &gtpu) != SRSRAN_SUCCESS) {
stack_logger.error("Couldn't initialize RRC");
return SRSRAN_ERROR;
}
if (s1ap.init(args.s1ap, &rrc, this) != SRSRAN_SUCCESS) { if (s1ap.init(args.s1ap, &rrc, this) != SRSRAN_SUCCESS) {
stack_logger.error("Couldn't initialize S1AP"); stack_logger.error("Couldn't initialize S1AP");
return SRSRAN_ERROR; return SRSRAN_ERROR;

@ -22,14 +22,6 @@ namespace srsenb {
mac_nr::mac_nr() : logger(srslog::fetch_basic_logger("MAC")) mac_nr::mac_nr() : logger(srslog::fetch_basic_logger("MAC"))
{ {
bcch_bch_payload = srsran::make_byte_buffer();
// allocate 8 tx buffers for UE (TODO: as we don't handle softbuffers why do we need so many buffers)
for (int i = 0; i < SRSRAN_FDD_NOF_HARQ; i++) {
ue_tx_buffer.emplace_back(srsran::make_byte_buffer());
}
ue_rlc_buffer = srsran::make_byte_buffer();
} }
mac_nr::~mac_nr() mac_nr::~mac_nr()
@ -58,6 +50,25 @@ int mac_nr::init(const mac_nr_args_t& args_,
pcap->open(args.pcap.filename); pcap->open(args.pcap.filename);
} }
bcch_bch_payload = srsran::make_byte_buffer();
if (bcch_bch_payload == nullptr) {
return SRSRAN_ERROR;
}
// allocate 8 tx buffers for UE (TODO: as we don't handle softbuffers why do we need so many buffers)
for (int i = 0; i < SRSRAN_FDD_NOF_HARQ; i++) {
srsran::unique_byte_buffer_t buffer = srsran::make_byte_buffer();
if (buffer == nullptr) {
return SRSRAN_ERROR;
}
ue_tx_buffer.emplace_back(std::move(buffer));
}
ue_rlc_buffer = srsran::make_byte_buffer();
if (ue_rlc_buffer == nullptr) {
return SRSRAN_ERROR;
}
logger.info("Started"); logger.info("Started");
started = true; started = true;

@ -40,13 +40,13 @@ rrc::rrc(srsran::task_sched_handle task_sched_) :
rrc::~rrc() {} rrc::~rrc() {}
void rrc::init(const rrc_cfg_t& cfg_, int32_t rrc::init(const rrc_cfg_t& cfg_,
phy_interface_rrc_lte* phy_, phy_interface_rrc_lte* phy_,
mac_interface_rrc* mac_, mac_interface_rrc* mac_,
rlc_interface_rrc* rlc_, rlc_interface_rrc* rlc_,
pdcp_interface_rrc* pdcp_, pdcp_interface_rrc* pdcp_,
s1ap_interface_rrc* s1ap_, s1ap_interface_rrc* s1ap_,
gtpu_interface_rrc* gtpu_) gtpu_interface_rrc* gtpu_)
{ {
phy = phy_; phy = phy_;
mac = mac_; mac = mac_;
@ -67,7 +67,10 @@ void rrc::init(const rrc_cfg_t& cfg_,
// Loads the PRACH root sequence // Loads the PRACH root sequence
cfg.sibs[1].sib2().rr_cfg_common.prach_cfg.root_seq_idx = cfg.cell_list[0].root_seq_idx; cfg.sibs[1].sib2().rr_cfg_common.prach_cfg.root_seq_idx = cfg.cell_list[0].root_seq_idx;
nof_si_messages = generate_sibs(); if (generate_sibs() != SRSRAN_SUCCESS) {
logger.error("Couldn't generate SIBs.");
return false;
}
config_mac(); config_mac();
// Check valid inactivity timeout config // Check valid inactivity timeout config
@ -84,6 +87,8 @@ void rrc::init(const rrc_cfg_t& cfg_,
logger.info("Inactivity timeout: %d ms", cfg.inactivity_timeout_ms); logger.info("Inactivity timeout: %d ms", cfg.inactivity_timeout_ms);
running = true; running = true;
return SRSRAN_SUCCESS;
} }
void rrc::stop() void rrc::stop()
@ -764,7 +769,9 @@ void rrc::config_mac()
* Before packing the message, it patches the cell specific params of * Before packing the message, it patches the cell specific params of
* the SIB, including the cellId and the PRACH config index. * the SIB, including the cellId and the PRACH config index.
* *
* @return The number of SIBs messages per CC * The number of generates SIB messages is stored in the class member nof_si_messages
*
* @return SRSRAN_SUCCESS on success, SRSRAN_ERROR on failure
*/ */
uint32_t rrc::generate_sibs() uint32_t rrc::generate_sibs()
{ {
@ -809,9 +816,14 @@ uint32_t rrc::generate_sibs()
// Pack payload for all messages // Pack payload for all messages
for (uint32_t msg_index = 0; msg_index < nof_messages; msg_index++) { for (uint32_t msg_index = 0; msg_index < nof_messages; msg_index++) {
srsran::unique_byte_buffer_t sib_buffer = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t sib_buffer = srsran::make_byte_buffer();
if (sib_buffer == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return SRSRAN_ERROR;
}
asn1::bit_ref bref(sib_buffer->msg, sib_buffer->get_tailroom()); asn1::bit_ref bref(sib_buffer->msg, sib_buffer->get_tailroom());
if (msg[msg_index].pack(bref) == asn1::SRSASN_ERROR_ENCODE_FAIL) { if (msg[msg_index].pack(bref) == asn1::SRSASN_ERROR_ENCODE_FAIL) {
logger.error("Failed to pack SIB message %d", msg_index); logger.error("Failed to pack SIB message %d", msg_index);
return SRSRAN_ERROR;
} }
sib_buffer->N_bytes = bref.distance_bytes(); sib_buffer->N_bytes = bref.distance_bytes();
cell_ctxt->sib_buffer.push_back(std::move(sib_buffer)); cell_ctxt->sib_buffer.push_back(std::move(sib_buffer));
@ -827,7 +839,9 @@ uint32_t rrc::generate_sibs()
} }
} }
return nof_messages; nof_si_messages = nof_messages;
return SRSRAN_SUCCESS;
} }
void rrc::configure_mbsfn_sibs() void rrc::configure_mbsfn_sibs()

@ -329,6 +329,10 @@ bool rrc::ue::rrc_mobility::start_ho_preparation(uint32_t target_eci,
hoprep_r8.ue_radio_access_cap_info[0].rat_type = asn1::rrc::rat_type_e::eutra; hoprep_r8.ue_radio_access_cap_info[0].rat_type = asn1::rrc::rat_type_e::eutra;
srsran::unique_byte_buffer_t buffer = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t buffer = srsran::make_byte_buffer();
if (buffer == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return false;
}
asn1::bit_ref bref(buffer->msg, buffer->get_tailroom()); asn1::bit_ref bref(buffer->msg, buffer->get_tailroom());
if (rrc_ue->eutra_capabilities.pack(bref) == asn1::SRSASN_ERROR_ENCODE_FAIL) { if (rrc_ue->eutra_capabilities.pack(bref) == asn1::SRSASN_ERROR_ENCODE_FAIL) {
logger.error("Failed to pack UE EUTRA Capability"); logger.error("Failed to pack UE EUTRA Capability");
@ -368,6 +372,10 @@ bool rrc::ue::rrc_mobility::start_ho_preparation(uint32_t target_eci,
/*** pack HO Preparation Info into an RRC container buffer ***/ /*** pack HO Preparation Info into an RRC container buffer ***/
srsran::unique_byte_buffer_t buffer = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t buffer = srsran::make_byte_buffer();
if (buffer == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return false;
}
asn1::bit_ref bref(buffer->msg, buffer->get_tailroom()); asn1::bit_ref bref(buffer->msg, buffer->get_tailroom());
if (hoprep.pack(bref) == asn1::SRSASN_ERROR_ENCODE_FAIL) { if (hoprep.pack(bref) == asn1::SRSASN_ERROR_ENCODE_FAIL) {
Error("Failed to pack HO preparation msg"); Error("Failed to pack HO preparation msg");
@ -711,7 +719,12 @@ void rrc::ue::rrc_mobility::handle_ho_requested(idle_st& s, const ho_req_rx_ev&
/* Prepare Handover Command to be sent via S1AP */ /* Prepare Handover Command to be sent via S1AP */
srsran::unique_byte_buffer_t ho_cmd_pdu = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t ho_cmd_pdu = srsran::make_byte_buffer();
asn1::bit_ref bref2{ho_cmd_pdu->msg, ho_cmd_pdu->get_tailroom()}; if (ho_cmd_pdu == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
trigger(srsran::failure_ev{});
return;
}
asn1::bit_ref bref2{ho_cmd_pdu->msg, ho_cmd_pdu->get_tailroom()};
if (dl_dcch_msg.pack(bref2) != asn1::SRSASN_SUCCESS) { if (dl_dcch_msg.pack(bref2) != asn1::SRSASN_SUCCESS) {
logger.error("Failed to pack HandoverCommand"); logger.error("Failed to pack HandoverCommand");
trigger(srsran::failure_ev{}); trigger(srsran::failure_ev{});

@ -21,13 +21,13 @@ namespace srsenb {
rrc_nr::rrc_nr(srsran::timer_handler* timers_) : logger(srslog::fetch_basic_logger("RRC")), timers(timers_) {} rrc_nr::rrc_nr(srsran::timer_handler* timers_) : logger(srslog::fetch_basic_logger("RRC")), timers(timers_) {}
void rrc_nr::init(const rrc_nr_cfg_t& cfg_, int rrc_nr::init(const rrc_nr_cfg_t& cfg_,
phy_interface_stack_nr* phy_, phy_interface_stack_nr* phy_,
mac_interface_rrc_nr* mac_, mac_interface_rrc_nr* mac_,
rlc_interface_rrc_nr* rlc_, rlc_interface_rrc_nr* rlc_,
pdcp_interface_rrc_nr* pdcp_, pdcp_interface_rrc_nr* pdcp_,
ngap_interface_rrc_nr* ngap_, ngap_interface_rrc_nr* ngap_,
gtpu_interface_rrc_nr* gtpu_) gtpu_interface_rrc_nr* gtpu_)
{ {
phy = phy_; phy = phy_;
mac = mac_; mac = mac_;
@ -46,7 +46,11 @@ void rrc_nr::init(const rrc_nr_cfg_t& cfg_,
// derived // derived
slot_dur_ms = 1; slot_dur_ms = 1;
nof_si_messages = generate_sibs(); if (generate_sibs() != SRSRAN_SUCCESS) {
logger.error("Couldn't generate SIB messages.");
return SRSRAN_ERROR;
}
config_mac(); config_mac();
// add dummy user // add dummy user
@ -67,6 +71,8 @@ void rrc_nr::init(const rrc_nr_cfg_t& cfg_,
logger.info("Started"); logger.info("Started");
running = true; running = true;
return SRSRAN_SUCCESS;
} }
void rrc_nr::stop() void rrc_nr::stop()
@ -198,7 +204,7 @@ void rrc_nr::config_mac()
mac->cell_cfg(&sched_cfg); mac->cell_cfg(&sched_cfg);
} }
uint32_t rrc_nr::generate_sibs() int32_t rrc_nr::generate_sibs()
{ {
// MIB packing // MIB packing
bcch_bch_msg_s mib_msg; bcch_bch_msg_s mib_msg;
@ -206,6 +212,10 @@ uint32_t rrc_nr::generate_sibs()
mib = cfg.mib; mib = cfg.mib;
{ {
srsran::unique_byte_buffer_t mib_buf = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t mib_buf = srsran::make_byte_buffer();
if (mib_buf == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return SRSRAN_ERROR;
}
asn1::bit_ref bref(mib_buf->msg, mib_buf->get_tailroom()); asn1::bit_ref bref(mib_buf->msg, mib_buf->get_tailroom());
mib_msg.pack(bref); mib_msg.pack(bref);
mib_buf->N_bytes = bref.distance_bytes(); mib_buf->N_bytes = bref.distance_bytes();
@ -240,6 +250,10 @@ uint32_t rrc_nr::generate_sibs()
// Pack payload for all messages // Pack payload for all messages
for (uint32_t msg_index = 0; msg_index < nof_messages + 1; msg_index++) { for (uint32_t msg_index = 0; msg_index < nof_messages + 1; msg_index++) {
srsran::unique_byte_buffer_t sib = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t sib = srsran::make_byte_buffer();
if (sib == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return SRSRAN_ERROR;
}
asn1::bit_ref bref(sib->msg, sib->get_tailroom()); asn1::bit_ref bref(sib->msg, sib->get_tailroom());
msg[msg_index].pack(bref); msg[msg_index].pack(bref);
sib->N_bytes = bref.distance_bytes(); sib->N_bytes = bref.distance_bytes();
@ -249,7 +263,9 @@ uint32_t rrc_nr::generate_sibs()
log_rrc_message("SIB payload", Tx, sib_buffer.back().get(), msg[msg_index]); log_rrc_message("SIB payload", Tx, sib_buffer.back().get(), msg[msg_index]);
} }
return sib_buffer.size() - 1; nof_si_messages = sib_buffer.size() - 1;
return SRSRAN_SUCCESS;
} }
/******************************************************************************* /*******************************************************************************

@ -201,6 +201,10 @@ void rrc::ue::parse_ul_dcch(uint32_t lcid, srsran::unique_byte_buffer_t pdu)
srsran::unique_byte_buffer_t original_pdu = std::move(pdu); srsran::unique_byte_buffer_t original_pdu = std::move(pdu);
pdu = srsran::make_byte_buffer(); pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
parent->logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return;
}
transaction_id = 0; transaction_id = 0;
@ -748,6 +752,10 @@ bool rrc::ue::handle_ue_cap_info(ue_cap_info_s* msg)
if (eutra_capabilities_unpacked) { if (eutra_capabilities_unpacked) {
srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
parent->logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return false;
}
asn1::bit_ref bref2{pdu->msg, pdu->get_tailroom()}; asn1::bit_ref bref2{pdu->msg, pdu->get_tailroom()};
msg->pack(bref2); msg->pack(bref2);
asn1::rrc::ue_radio_access_cap_info_s ue_rat_caps; asn1::rrc::ue_radio_access_cap_info_s ue_rat_caps;

@ -47,7 +47,7 @@ int test_sib_generation()
rrc_nr_cfg_t rrc_cfg = rrc_obj.update_default_cfg(default_cfg); rrc_nr_cfg_t rrc_cfg = rrc_obj.update_default_cfg(default_cfg);
auto& sched_elem = rrc_cfg.sib1.si_sched_info.sched_info_list[0]; auto& sched_elem = rrc_cfg.sib1.si_sched_info.sched_info_list[0];
rrc_obj.init(rrc_cfg, nullptr, &mac_obj, &rlc_obj, &pdcp_obj, nullptr, nullptr); TESTASSERT(rrc_obj.init(rrc_cfg, nullptr, &mac_obj, &rlc_obj, &pdcp_obj, nullptr, nullptr) == SRSRAN_SUCCESS);
TESTASSERT(test_cell_cfg(mac_obj.cellcfgobj) == SRSRAN_SUCCESS); TESTASSERT(test_cell_cfg(mac_obj.cellcfgobj) == SRSRAN_SUCCESS);
// TEMP tests // TEMP tests
@ -73,7 +73,7 @@ int test_rrc_setup()
// set cfg // set cfg
rrc_nr_cfg_t default_cfg = {}; rrc_nr_cfg_t default_cfg = {};
rrc_nr_cfg_t rrc_cfg = rrc_obj.update_default_cfg(default_cfg); rrc_nr_cfg_t rrc_cfg = rrc_obj.update_default_cfg(default_cfg);
rrc_obj.init(rrc_cfg, nullptr, &mac_obj, &rlc_obj, &pdcp_obj, nullptr, nullptr); TESTASSERT(rrc_obj.init(rrc_cfg, nullptr, &mac_obj, &rlc_obj, &pdcp_obj, nullptr, nullptr) == SRSRAN_SUCCESS);
for (uint32_t n = 0; n < 2; ++n) { for (uint32_t n = 0; n < 2; ++n) {
uint32_t timeout = 5500; uint32_t timeout = 5500;
@ -92,5 +92,5 @@ int main()
TESTASSERT(srsenb::test_sib_generation() == SRSRAN_SUCCESS); TESTASSERT(srsenb::test_sib_generation() == SRSRAN_SUCCESS);
TESTASSERT(srsenb::test_rrc_setup() == SRSRAN_SUCCESS); TESTASSERT(srsenb::test_rrc_setup() == SRSRAN_SUCCESS);
return 0; return SRSRAN_SUCCESS;
} }

@ -229,6 +229,10 @@ void mbms_gw::run_thread()
// Mark the thread as running // Mark the thread as running
m_running = true; m_running = true;
srsran::unique_byte_buffer_t msg = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t msg = srsran::make_byte_buffer();
if (msg == nullptr) {
m_logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return;
}
uint8_t seq = 0; uint8_t seq = 0;
while (m_running) { while (m_running) {

@ -89,6 +89,10 @@ void mme::stop()
void mme::run_thread() void mme::run_thread()
{ {
srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer("mme::run_thread"); srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer("mme::run_thread");
if (pdu == nullptr) {
m_s1ap_logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return;
}
uint32_t sz = SRSRAN_MAX_BUFFER_SIZE_BYTES - SRSRAN_BUFFER_HEADER_OFFSET; uint32_t sz = SRSRAN_MAX_BUFFER_SIZE_BYTES - SRSRAN_BUFFER_HEADER_OFFSET;
struct sockaddr_in enb_addr; struct sockaddr_in enb_addr;

@ -25,7 +25,7 @@ public:
explicit mux_nr(srslog::basic_logger& logger); explicit mux_nr(srslog::basic_logger& logger);
~mux_nr(){}; ~mux_nr(){};
void reset(); void reset();
void init(); int32_t init();
void step(); void step();

@ -217,6 +217,10 @@ bool cc_worker::work_dl()
if (phy->get_dl_pending_grant(dl_slot_cfg.idx, pdsch_cfg, ack_resource, pid)) { if (phy->get_dl_pending_grant(dl_slot_cfg.idx, pdsch_cfg, ack_resource, pid)) {
// Get data buffer // Get data buffer
srsran::unique_byte_buffer_t data = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t data = srsran::make_byte_buffer();
if (data == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return false;
}
data->N_bytes = pdsch_cfg.grant.tb[0].tbs / 8U; data->N_bytes = pdsch_cfg.grant.tb[0].tbs / 8U;
// Get soft-buffer from MAC // Get soft-buffer from MAC

@ -19,8 +19,6 @@ namespace srsue {
mac_nr::mac_nr(srsran::ext_task_sched_handle task_sched_) : mac_nr::mac_nr(srsran::ext_task_sched_handle task_sched_) :
task_sched(task_sched_), logger(srslog::fetch_basic_logger("MAC")), proc_ra(logger), mux(logger), pcap(nullptr) task_sched(task_sched_), logger(srslog::fetch_basic_logger("MAC")), proc_ra(logger), mux(logger), pcap(nullptr)
{ {
tx_buffer = srsran::make_byte_buffer();
rlc_buffer = srsran::make_byte_buffer();
} }
mac_nr::~mac_nr() mac_nr::~mac_nr()
@ -39,7 +37,10 @@ int mac_nr::init(const mac_nr_args_t& args_, phy_interface_mac_nr* phy_, rlc_int
proc_ra.init(phy, this, &task_sched); proc_ra.init(phy, this, &task_sched);
mux.init(); if (mux.init() != SRSRAN_SUCCESS) {
logger.error("Couldn't initialize mux unit.");
return SRSRAN_ERROR;
}
if (srsran_softbuffer_tx_init_guru(&softbuffer_tx, SRSRAN_SCH_NR_MAX_NOF_CB_LDPC, SRSRAN_LDPC_MAX_LEN_ENCODED_CB) < if (srsran_softbuffer_tx_init_guru(&softbuffer_tx, SRSRAN_SCH_NR_MAX_NOF_CB_LDPC, SRSRAN_LDPC_MAX_LEN_ENCODED_CB) <
SRSRAN_SUCCESS) { SRSRAN_SUCCESS) {
@ -47,6 +48,15 @@ int mac_nr::init(const mac_nr_args_t& args_, phy_interface_mac_nr* phy_, rlc_int
return SRSRAN_ERROR; return SRSRAN_ERROR;
} }
tx_buffer = srsran::make_byte_buffer();
if (tx_buffer == nullptr) {
return SRSRAN_ERROR;
}
rlc_buffer = srsran::make_byte_buffer();
if (rlc_buffer == nullptr) {
return SRSRAN_ERROR;
}
started = true; started = true;
return SRSRAN_SUCCESS; return SRSRAN_SUCCESS;

@ -15,12 +15,17 @@
namespace srsue { namespace srsue {
mux_nr::mux_nr(srslog::basic_logger& logger_) : logger(logger_) mux_nr::mux_nr(srslog::basic_logger& logger_) : logger(logger_){};
int32_t mux_nr::init()
{ {
msg3_buff = srsran::make_byte_buffer(); msg3_buff = srsran::make_byte_buffer();
}; if (msg3_buff == nullptr) {
return SRSRAN_ERROR;
}
void mux_nr::init() {} return SRSRAN_SUCCESS;
}
void mux_nr::msg3_flush() void mux_nr::msg3_flush()
{ {

@ -1533,8 +1533,8 @@ void rrc::send_ul_ccch_msg(const ul_ccch_msg_s& msg)
{ {
// Reset and reuse sdu buffer if provided // Reset and reuse sdu buffer if provided
unique_byte_buffer_t pdcp_buf = srsran::make_byte_buffer(); unique_byte_buffer_t pdcp_buf = srsran::make_byte_buffer();
if (not pdcp_buf.get()) { if (pdcp_buf == nullptr) {
logger.error("Fatal Error: Couldn't allocate PDU in byte_align_and_pack()."); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -1565,8 +1565,8 @@ void rrc::send_ul_dcch_msg(uint32_t lcid, const ul_dcch_msg_s& msg)
{ {
// Reset and reuse sdu buffer if provided // Reset and reuse sdu buffer if provided
unique_byte_buffer_t pdcp_buf = srsran::make_byte_buffer(); unique_byte_buffer_t pdcp_buf = srsran::make_byte_buffer();
if (not pdcp_buf.get()) { if (pdcp_buf == nullptr) {
logger.error("Fatal Error: Couldn't allocate PDU in byte_align_and_pack()."); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -1681,8 +1681,8 @@ void rrc::parse_dl_dcch(uint32_t lcid, unique_byte_buffer_t pdu)
switch (dl_dcch_msg.msg.c1().type().value) { switch (dl_dcch_msg.msg.c1().type().value) {
case dl_dcch_msg_type_c::c1_c_::types::dl_info_transfer: case dl_dcch_msg_type_c::c1_c_::types::dl_info_transfer:
pdu = srsran::make_byte_buffer(); pdu = srsran::make_byte_buffer();
if (!pdu.get()) { if (pdu == nullptr) {
logger.error("Fatal error: out of buffers in pool"); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
pdu->N_bytes = c1->dl_info_transfer().crit_exts.c1().dl_info_transfer_r8().ded_info_type.ded_info_nas().size(); pdu->N_bytes = c1->dl_info_transfer().crit_exts.c1().dl_info_transfer_r8().ded_info_type.ded_info_nas().size();

@ -1033,12 +1033,12 @@ srsran::proc_outcome_t rrc::connection_reconf_no_ho_proc::react(const bool& conf
srsran::unique_byte_buffer_t nas_pdu; srsran::unique_byte_buffer_t nas_pdu;
for (auto& pdu : rx_recfg.ded_info_nas_list) { for (auto& pdu : rx_recfg.ded_info_nas_list) {
nas_pdu = srsran::make_byte_buffer(); nas_pdu = srsran::make_byte_buffer();
if (nas_pdu.get()) { if (nas_pdu != nullptr) {
memcpy(nas_pdu->msg, pdu.data(), pdu.size()); memcpy(nas_pdu->msg, pdu.data(), pdu.size());
nas_pdu->N_bytes = pdu.size(); nas_pdu->N_bytes = pdu.size();
rrc_ptr->nas->write_pdu(RB_ID_SRB1, std::move(nas_pdu)); rrc_ptr->nas->write_pdu(RB_ID_SRB1, std::move(nas_pdu));
} else { } else {
rrc_ptr->logger.error("Fatal Error: Couldn't allocate PDU in %s.", __FUNCTION__); rrc_ptr->logger.error("Couldn't allocate PDU in %s.", __FUNCTION__);
return proc_outcome_t::error; return proc_outcome_t::error;
} }
} }

@ -247,7 +247,7 @@ void gw::run_thread()
srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (!pdu) { if (!pdu) {
logger.error("Fatal Error: Couldn't allocate PDU in run_thread()."); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }

@ -317,7 +317,7 @@ void nas::start_attach_request(srsran::establishment_cause_t cause_)
// Start attach request // Start attach request
unique_byte_buffer_t msg = srsran::make_byte_buffer(); unique_byte_buffer_t msg = srsran::make_byte_buffer();
if (msg == nullptr) { if (msg == nullptr) {
logger.warning("Couldn't allocate buffer for Attach request.\n"); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -359,6 +359,10 @@ void nas::start_service_request(srsran::establishment_cause_t cause_)
// Start service request // Start service request
unique_byte_buffer_t msg = srsran::make_byte_buffer(); unique_byte_buffer_t msg = srsran::make_byte_buffer();
if (msg == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return;
}
gen_service_request(msg); gen_service_request(msg);
if (not rrc->connection_request(cause_, std::move(msg))) { if (not rrc->connection_request(cause_, std::move(msg))) {
logger.error("Error starting RRC connection"); logger.error("Error starting RRC connection");
@ -1857,7 +1861,7 @@ void nas::send_security_mode_reject(uint8_t cause)
{ {
unique_byte_buffer_t msg = srsran::make_byte_buffer(); unique_byte_buffer_t msg = srsran::make_byte_buffer();
if (!msg) { if (!msg) {
logger.error("Fatal Error: Couldn't allocate PDU in send_security_mode_reject()."); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -1878,7 +1882,7 @@ void nas::send_attach_request()
{ {
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (!pdu) { if (!pdu) {
logger.error("Fatal Error: Couldn't allocate PDU in %s().", __FUNCTION__); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
gen_attach_request(pdu); gen_attach_request(pdu);
@ -1889,7 +1893,7 @@ void nas::send_detach_request(bool switch_off)
{ {
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (!pdu) { if (!pdu) {
logger.error("Fatal Error: Couldn't allocate PDU in %s().", __FUNCTION__); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -1969,6 +1973,10 @@ void nas::send_attach_complete(const uint8_t& transaction_id_, const uint8_t& ep
// Pack entire message // Pack entire message
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return;
}
liblte_mme_pack_attach_complete_msg( liblte_mme_pack_attach_complete_msg(
&attach_complete, current_sec_hdr, ctxt.tx_count, (LIBLTE_BYTE_MSG_STRUCT*)pdu.get()); &attach_complete, current_sec_hdr, ctxt.tx_count, (LIBLTE_BYTE_MSG_STRUCT*)pdu.get());
// Write NAS pcap // Write NAS pcap
@ -1993,7 +2001,7 @@ void nas::send_detach_accept()
{ {
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (!pdu) { if (!pdu) {
logger.error("Fatal Error: Couldn't allocate PDU in %s().", __FUNCTION__); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -2018,7 +2026,7 @@ void nas::send_authentication_response(const uint8_t* res, const size_t res_len)
{ {
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (!pdu) { if (!pdu) {
logger.error("Fatal Error: Couldn't allocate PDU in send_authentication_response()."); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -2049,7 +2057,7 @@ void nas::send_authentication_failure(const uint8_t cause, const uint8_t* auth_f
{ {
unique_byte_buffer_t msg = srsran::make_byte_buffer(); unique_byte_buffer_t msg = srsran::make_byte_buffer();
if (!msg) { if (!msg) {
logger.error("Fatal Error: Couldn't allocate PDU in send_authentication_failure()."); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -2097,7 +2105,7 @@ void nas::send_identity_response(const uint8 id_type)
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (!pdu) { if (!pdu) {
logger.error("Fatal Error: Couldn't allocate PDU in send_identity_response()."); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -2121,7 +2129,7 @@ void nas::send_service_request()
{ {
unique_byte_buffer_t msg = srsran::make_byte_buffer(); unique_byte_buffer_t msg = srsran::make_byte_buffer();
if (!msg) { if (!msg) {
logger.error("Fatal Error: Couldn't allocate PDU in send_service_request()."); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -2240,8 +2248,8 @@ void nas::send_esm_information_response(const uint8 proc_transaction_id)
} }
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (!pdu) { if (pdu == nullptr) {
logger.error("Fatal Error: Couldn't allocate PDU in %s.", __FUNCTION__); logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return; return;
} }
@ -2271,6 +2279,10 @@ void nas::send_activate_dedicated_eps_bearer_context_accept(const uint8_t& proc_
const uint8_t& eps_bearer_id) const uint8_t& eps_bearer_id)
{ {
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return;
}
LIBLTE_MME_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT_MSG_STRUCT accept = {}; LIBLTE_MME_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT_MSG_STRUCT accept = {};
@ -2305,6 +2317,10 @@ void nas::send_activate_dedicated_eps_bearer_context_accept(const uint8_t& proc_
void nas::send_deactivate_eps_bearer_context_accept(const uint8_t& proc_transaction_id, const uint8_t& eps_bearer_id) void nas::send_deactivate_eps_bearer_context_accept(const uint8_t& proc_transaction_id, const uint8_t& eps_bearer_id)
{ {
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return;
}
LIBLTE_MME_DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT_MSG_STRUCT accept = {}; LIBLTE_MME_DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT_MSG_STRUCT accept = {};
@ -2339,6 +2355,10 @@ void nas::send_deactivate_eps_bearer_context_accept(const uint8_t& proc_transact
void nas::send_modify_eps_bearer_context_accept(const uint8_t& proc_transaction_id, const uint8_t& eps_bearer_id) void nas::send_modify_eps_bearer_context_accept(const uint8_t& proc_transaction_id, const uint8_t& eps_bearer_id)
{ {
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return;
}
LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_ACCEPT_MSG_STRUCT accept = {}; LIBLTE_MME_MODIFY_EPS_BEARER_CONTEXT_ACCEPT_MSG_STRUCT accept = {};
@ -2373,6 +2393,10 @@ void nas::send_modify_eps_bearer_context_accept(const uint8_t& proc_transaction_
void nas::send_activate_test_mode_complete() void nas::send_activate_test_mode_complete()
{ {
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return;
}
if (liblte_mme_pack_activate_test_mode_complete_msg( if (liblte_mme_pack_activate_test_mode_complete_msg(
(LIBLTE_BYTE_MSG_STRUCT*)pdu.get(), current_sec_hdr, ctxt.tx_count)) { (LIBLTE_BYTE_MSG_STRUCT*)pdu.get(), current_sec_hdr, ctxt.tx_count)) {
@ -2398,6 +2422,10 @@ void nas::send_activate_test_mode_complete()
void nas::send_close_ue_test_loop_complete() void nas::send_close_ue_test_loop_complete()
{ {
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
logger.error("Couldn't allocate PDU in %s().", __FUNCTION__);
return;
}
if (liblte_mme_pack_close_ue_test_loop_complete_msg( if (liblte_mme_pack_close_ue_test_loop_complete_msg(
(LIBLTE_BYTE_MSG_STRUCT*)pdu.get(), current_sec_hdr, ctxt.tx_count)) { (LIBLTE_BYTE_MSG_STRUCT*)pdu.get(), current_sec_hdr, ctxt.tx_count)) {

@ -123,6 +123,7 @@ int main()
grant.pid = 0x0123; grant.pid = 0x0123;
uint8_t mac_dl_rar_pdu[] = {0x40, 0x06, 0x68, 0x03, 0x21, 0x46, 0x46, 0x02, 0x00, 0x00, 0x00}; uint8_t mac_dl_rar_pdu[] = {0x40, 0x06, 0x68, 0x03, 0x21, 0x46, 0x46, 0x02, 0x00, 0x00, 0x00};
grant.tb[0] = srsran::make_byte_buffer(); grant.tb[0] = srsran::make_byte_buffer();
TESTASSERT(grant.tb[0] != nullptr);
grant.tb[0].get()->append_bytes(mac_dl_rar_pdu, sizeof(mac_dl_rar_pdu)); grant.tb[0].get()->append_bytes(mac_dl_rar_pdu, sizeof(mac_dl_rar_pdu));
proc_ra_nr.handle_rar_pdu(grant); proc_ra_nr.handle_rar_pdu(grant);

@ -120,6 +120,10 @@ private:
// pack into byte buffer // pack into byte buffer
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
logger.error("Couldn't allocate buffer in %s().", __FUNCTION__);
return;
}
pdu->N_bytes = len; pdu->N_bytes = len;
memcpy(pdu->msg, payload, pdu->N_bytes); memcpy(pdu->msg, payload, pdu->N_bytes);

@ -109,6 +109,10 @@ private:
// pack into byte buffer // pack into byte buffer
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
logger.error("Couldn't allocate buffer in %s().", __FUNCTION__);
return;
}
pdu->N_bytes = len; pdu->N_bytes = len;
memcpy(pdu->msg, payload, pdu->N_bytes); memcpy(pdu->msg, payload, pdu->N_bytes);
@ -129,6 +133,10 @@ private:
// pack into byte buffer // pack into byte buffer
unique_byte_buffer_t pdu = srsran::make_byte_buffer(); unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
logger.error("Couldn't allocate buffer in %s().", __FUNCTION__);
return;
}
pdu->N_bytes = len; pdu->N_bytes = len;
memcpy(pdu->msg, payload, pdu->N_bytes); memcpy(pdu->msg, payload, pdu->N_bytes);
@ -154,9 +162,6 @@ private:
ss_srb_interface* syssim = nullptr; ss_srb_interface* syssim = nullptr;
byte_buffer_pool* pool = nullptr; byte_buffer_pool* pool = nullptr;
// struct sctp_sndrcvinfo sri = {};
// struct sockaddr_in client_addr;
}; };
#endif // SRSUE_TTCN3_SRB_INTERFACE_H #endif // SRSUE_TTCN3_SRB_INTERFACE_H

@ -194,6 +194,10 @@ private:
payload_ptr += 2; payload_ptr += 2;
unique_byte_buffer_t sib = srsran::make_byte_buffer(); unique_byte_buffer_t sib = srsran::make_byte_buffer();
if (sib == nullptr) {
logger.error("Couldn't allocate buffer in %s().", __FUNCTION__);
return;
}
memcpy(sib->msg, payload_ptr, tb_len); memcpy(sib->msg, payload_ptr, tb_len);
payload_ptr += tb_len; payload_ptr += tb_len;
sib->N_bytes = tb_len; sib->N_bytes = tb_len;
@ -695,6 +699,10 @@ private:
payload_ptr += 2; payload_ptr += 2;
unique_byte_buffer_t pch = srsran::make_byte_buffer(); unique_byte_buffer_t pch = srsran::make_byte_buffer();
if (pch == nullptr) {
logger.error("Couldn't allocate buffer in %s().", __FUNCTION__);
return;
}
memcpy(pch->msg, payload_ptr, tb_len); memcpy(pch->msg, payload_ptr, tb_len);
payload_ptr += tb_len; payload_ptr += tb_len;
pch->N_bytes = tb_len; pch->N_bytes = tb_len;

@ -226,6 +226,7 @@ int security_command_test()
// push auth request PDU to NAS to generate security context // push auth request PDU to NAS to generate security context
byte_buffer_pool* pool = byte_buffer_pool::get_instance(); byte_buffer_pool* pool = byte_buffer_pool::get_instance();
unique_byte_buffer_t tmp = srsran::make_byte_buffer(); unique_byte_buffer_t tmp = srsran::make_byte_buffer();
TESTASSERT(tmp != nullptr);
memcpy(tmp->msg, auth_request_pdu, sizeof(auth_request_pdu)); memcpy(tmp->msg, auth_request_pdu, sizeof(auth_request_pdu));
tmp->N_bytes = sizeof(auth_request_pdu); tmp->N_bytes = sizeof(auth_request_pdu);
nas.write_pdu(LCID, std::move(tmp)); nas.write_pdu(LCID, std::move(tmp));
@ -235,6 +236,7 @@ int security_command_test()
// reuse buffer for security mode command // reuse buffer for security mode command
tmp = srsran::make_byte_buffer(); tmp = srsran::make_byte_buffer();
TESTASSERT(tmp != nullptr);
memcpy(tmp->msg, sec_mode_command_pdu, sizeof(sec_mode_command_pdu)); memcpy(tmp->msg, sec_mode_command_pdu, sizeof(sec_mode_command_pdu));
tmp->N_bytes = sizeof(sec_mode_command_pdu); tmp->N_bytes = sizeof(sec_mode_command_pdu);
nas.write_pdu(LCID, std::move(tmp)); nas.write_pdu(LCID, std::move(tmp));
@ -296,6 +298,7 @@ int mme_attach_request_test()
// finally push attach accept // finally push attach accept
byte_buffer_pool* pool = byte_buffer_pool::get_instance(); byte_buffer_pool* pool = byte_buffer_pool::get_instance();
unique_byte_buffer_t tmp = srsran::make_byte_buffer(); unique_byte_buffer_t tmp = srsran::make_byte_buffer();
TESTASSERT(tmp != nullptr);
memcpy(tmp->msg, attach_accept_pdu, sizeof(attach_accept_pdu)); memcpy(tmp->msg, attach_accept_pdu, sizeof(attach_accept_pdu));
tmp->N_bytes = sizeof(attach_accept_pdu); tmp->N_bytes = sizeof(attach_accept_pdu);
nas.write_pdu(LCID, std::move(tmp)); nas.write_pdu(LCID, std::move(tmp));
@ -345,6 +348,7 @@ int esm_info_request_test()
// push ESM info request PDU to NAS to generate response // push ESM info request PDU to NAS to generate response
unique_byte_buffer_t tmp = srsran::make_byte_buffer(); unique_byte_buffer_t tmp = srsran::make_byte_buffer();
TESTASSERT(tmp != nullptr);
memcpy(tmp->msg, esm_info_req_pdu, sizeof(esm_info_req_pdu)); memcpy(tmp->msg, esm_info_req_pdu, sizeof(esm_info_req_pdu));
tmp->N_bytes = sizeof(esm_info_req_pdu); tmp->N_bytes = sizeof(esm_info_req_pdu);
nas.write_pdu(LCID, std::move(tmp)); nas.write_pdu(LCID, std::move(tmp));
@ -383,6 +387,7 @@ int dedicated_eps_bearer_test()
// push dedicated EPS bearer PDU to NAS // push dedicated EPS bearer PDU to NAS
unique_byte_buffer_t tmp = srsran::make_byte_buffer(); unique_byte_buffer_t tmp = srsran::make_byte_buffer();
TESTASSERT(tmp != nullptr);
memcpy(tmp->msg, activate_dedicated_eps_bearer_pdu, sizeof(activate_dedicated_eps_bearer_pdu)); memcpy(tmp->msg, activate_dedicated_eps_bearer_pdu, sizeof(activate_dedicated_eps_bearer_pdu));
tmp->N_bytes = sizeof(activate_dedicated_eps_bearer_pdu); tmp->N_bytes = sizeof(activate_dedicated_eps_bearer_pdu);
nas.write_pdu(LCID, std::move(tmp)); nas.write_pdu(LCID, std::move(tmp));
@ -394,6 +399,7 @@ int dedicated_eps_bearer_test()
// add default EPS beaerer // add default EPS beaerer
unique_byte_buffer_t attach_with_default_bearer = srsran::make_byte_buffer(); unique_byte_buffer_t attach_with_default_bearer = srsran::make_byte_buffer();
TESTASSERT(attach_with_default_bearer != nullptr);
memcpy(attach_with_default_bearer->msg, attach_accept_pdu, sizeof(attach_accept_pdu)); memcpy(attach_with_default_bearer->msg, attach_accept_pdu, sizeof(attach_accept_pdu));
attach_with_default_bearer->N_bytes = sizeof(attach_accept_pdu); attach_with_default_bearer->N_bytes = sizeof(attach_accept_pdu);
nas.write_pdu(LCID, std::move(attach_with_default_bearer)); nas.write_pdu(LCID, std::move(attach_with_default_bearer));
@ -404,6 +410,7 @@ int dedicated_eps_bearer_test()
// push dedicated bearer activation and check that it was added // push dedicated bearer activation and check that it was added
tmp = srsran::make_byte_buffer(); tmp = srsran::make_byte_buffer();
TESTASSERT(tmp != nullptr);
memcpy(tmp->msg, activate_dedicated_eps_bearer_pdu, sizeof(activate_dedicated_eps_bearer_pdu)); memcpy(tmp->msg, activate_dedicated_eps_bearer_pdu, sizeof(activate_dedicated_eps_bearer_pdu));
tmp->N_bytes = sizeof(activate_dedicated_eps_bearer_pdu); tmp->N_bytes = sizeof(activate_dedicated_eps_bearer_pdu);
nas.write_pdu(LCID, std::move(tmp)); nas.write_pdu(LCID, std::move(tmp));
@ -412,6 +419,7 @@ int dedicated_eps_bearer_test()
// tear-down dedicated bearer // tear-down dedicated bearer
tmp = srsran::make_byte_buffer(); tmp = srsran::make_byte_buffer();
TESTASSERT(tmp != nullptr);
memcpy(tmp->msg, deactivate_eps_bearer_pdu, sizeof(deactivate_eps_bearer_pdu)); memcpy(tmp->msg, deactivate_eps_bearer_pdu, sizeof(deactivate_eps_bearer_pdu));
tmp->N_bytes = sizeof(deactivate_eps_bearer_pdu); tmp->N_bytes = sizeof(deactivate_eps_bearer_pdu);
nas.write_pdu(LCID, std::move(tmp)); nas.write_pdu(LCID, std::move(tmp));
@ -420,6 +428,7 @@ int dedicated_eps_bearer_test()
// try to tear-down dedicated bearer again // try to tear-down dedicated bearer again
tmp = srsran::make_byte_buffer(); tmp = srsran::make_byte_buffer();
TESTASSERT(tmp != nullptr);
memcpy(tmp->msg, deactivate_eps_bearer_pdu, sizeof(deactivate_eps_bearer_pdu)); memcpy(tmp->msg, deactivate_eps_bearer_pdu, sizeof(deactivate_eps_bearer_pdu));
tmp->N_bytes = sizeof(deactivate_eps_bearer_pdu); tmp->N_bytes = sizeof(deactivate_eps_bearer_pdu);
nas.write_pdu(LCID, std::move(tmp)); nas.write_pdu(LCID, std::move(tmp));

@ -135,6 +135,9 @@ public:
} }
pdu = srsran::make_byte_buffer(); pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
return;
}
asn1::bit_ref bref(pdu->msg, pdu->get_tailroom()); asn1::bit_ref bref(pdu->msg, pdu->get_tailroom());
dlsch_msg.pack(bref); dlsch_msg.pack(bref);
pdu->N_bytes = bref.distance_bytes(); pdu->N_bytes = bref.distance_bytes();
@ -299,6 +302,9 @@ public:
void send_ccch_msg(dl_ccch_msg_s& dl_ccch_msg) void send_ccch_msg(dl_ccch_msg_s& dl_ccch_msg)
{ {
srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer();
if (pdu == nullptr) {
return;
}
asn1::bit_ref bref(pdu->msg, pdu->get_tailroom()); asn1::bit_ref bref(pdu->msg, pdu->get_tailroom());
dl_ccch_msg.pack(bref); dl_ccch_msg.pack(bref);
@ -311,7 +317,9 @@ public:
void send_dcch_msg(dl_dcch_msg_s& dl_dcch_msg) void send_dcch_msg(dl_dcch_msg_s& dl_dcch_msg)
{ {
srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer(); srsran::unique_byte_buffer_t pdu = srsran::make_byte_buffer();
; if (pdu == nullptr) {
return;
}
asn1::bit_ref bref(pdu->msg, pdu->get_tailroom()); asn1::bit_ref bref(pdu->msg, pdu->get_tailroom());
dl_dcch_msg.pack(bref); dl_dcch_msg.pack(bref);
bref.align_bytes_zero(); bref.align_bytes_zero();

@ -106,10 +106,15 @@ int tft_filter_test_ipv6_combined()
srslog::basic_logger& logger = srslog::fetch_basic_logger("TFT"); srslog::basic_logger& logger = srslog::fetch_basic_logger("TFT");
srsran::unique_byte_buffer_t ip_msg1, ip_msg2, ip_msg3, ip_msg4, ip_msg5; srsran::unique_byte_buffer_t ip_msg1, ip_msg2, ip_msg3, ip_msg4, ip_msg5;
ip_msg1 = make_byte_buffer(); ip_msg1 = make_byte_buffer();
TESTASSERT(ip_msg1 != nullptr);
ip_msg2 = make_byte_buffer(); ip_msg2 = make_byte_buffer();
TESTASSERT(ip_msg2 != nullptr);
ip_msg3 = make_byte_buffer(); ip_msg3 = make_byte_buffer();
TESTASSERT(ip_msg3 != nullptr);
ip_msg4 = make_byte_buffer(); ip_msg4 = make_byte_buffer();
TESTASSERT(ip_msg4 != nullptr);
ip_msg5 = make_byte_buffer(); ip_msg5 = make_byte_buffer();
TESTASSERT(ip_msg5 != nullptr);
// Set IP test message // Set IP test message
ip_msg1->N_bytes = sizeof(ipv6_matched_packet); ip_msg1->N_bytes = sizeof(ipv6_matched_packet);
@ -164,7 +169,9 @@ int tft_filter_test_single_local_port()
srsran::unique_byte_buffer_t ip_msg1, ip_msg2; srsran::unique_byte_buffer_t ip_msg1, ip_msg2;
ip_msg1 = make_byte_buffer(); ip_msg1 = make_byte_buffer();
TESTASSERT(ip_msg1 != nullptr);
ip_msg2 = make_byte_buffer(); ip_msg2 = make_byte_buffer();
TESTASSERT(ip_msg2 != nullptr);
// Filter length: 3 bytes // Filter length: 3 bytes
// Filter type: Single local port // Filter type: Single local port
@ -208,7 +215,9 @@ int tft_filter_test_single_remote_port()
srsran::unique_byte_buffer_t ip_msg1, ip_msg2; srsran::unique_byte_buffer_t ip_msg1, ip_msg2;
ip_msg1 = make_byte_buffer(); ip_msg1 = make_byte_buffer();
TESTASSERT(ip_msg1 != nullptr);
ip_msg2 = make_byte_buffer(); ip_msg2 = make_byte_buffer();
TESTASSERT(ip_msg2 != nullptr);
// Filter length: 3 bytes // Filter length: 3 bytes
// Filter type: Single remote port // Filter type: Single remote port
@ -252,7 +261,9 @@ int tft_filter_test_ipv4_local_addr()
srsran::unique_byte_buffer_t ip_msg1, ip_msg2; srsran::unique_byte_buffer_t ip_msg1, ip_msg2;
ip_msg1 = make_byte_buffer(); ip_msg1 = make_byte_buffer();
TESTASSERT(ip_msg1 != nullptr);
ip_msg2 = make_byte_buffer(); ip_msg2 = make_byte_buffer();
TESTASSERT(ip_msg2 != nullptr);
// Filter length: 9 bytes // Filter length: 9 bytes
// Filter type: IPv4 local address // Filter type: IPv4 local address
@ -299,7 +310,9 @@ int tft_filter_test_ipv4_remote_addr()
srsran::unique_byte_buffer_t ip_msg1, ip_msg2; srsran::unique_byte_buffer_t ip_msg1, ip_msg2;
ip_msg1 = make_byte_buffer(); ip_msg1 = make_byte_buffer();
TESTASSERT(ip_msg1 != nullptr);
ip_msg2 = make_byte_buffer(); ip_msg2 = make_byte_buffer();
TESTASSERT(ip_msg2 != nullptr);
// Filter length: 5 bytes // Filter length: 5 bytes
// Filter type: IPv4 local address // Filter type: IPv4 local address
@ -345,7 +358,9 @@ int tft_filter_test_ipv4_tos()
srsran::unique_byte_buffer_t ip_msg1, ip_msg2; srsran::unique_byte_buffer_t ip_msg1, ip_msg2;
ip_msg1 = make_byte_buffer(); ip_msg1 = make_byte_buffer();
TESTASSERT(ip_msg1 != nullptr);
ip_msg2 = make_byte_buffer(); ip_msg2 = make_byte_buffer();
TESTASSERT(ip_msg2 != nullptr);
// Filter length: 3 bytes // Filter length: 3 bytes
// Filter type: Type of service // Filter type: Type of service

Loading…
Cancel
Save