diff --git a/lib/include/srslte/interfaces/nr_common_interface_types.h b/lib/include/srslte/interfaces/nr_common_interface_types.h new file mode 100644 index 000000000..3b15a6332 --- /dev/null +++ b/lib/include/srslte/interfaces/nr_common_interface_types.h @@ -0,0 +1,50 @@ +/* + * Copyright 2013-2020 Software Radio Systems Limited + * + * This file is part of srsLTE. + * + * srsLTE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsLTE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ + +#ifndef SRSLTE_COMMON_NR_H +#define SRSLTE_COMMON_NR_H + +namespace srslte { + +// NR Radio Bearer Id + +enum rb_id_nr_t { NR_SRB0, NR_SRB1, NR_SRB2, NR_SRB3, NR_DRB1, RB_ID_NR_N_ITEMS }; +inline const char* to_string(rb_id_nr_t rb_id) +{ + const static char* names[] = {"SRB0", "SRB1", "SRB2", "SRB3", "DRB1"}; + return (rb_id < rb_id_nr_t::RB_ID_NR_N_ITEMS) ? names[rb_id] : "invalid bearer id"; +} +inline bool is_srb(rb_id_nr_t lcid) +{ + return lcid <= rb_id_nr_t::NR_SRB3; +} +inline bool is_drb(rb_id_nr_t lcid) +{ + return not is_srb(lcid) and lcid <= rb_id_nr_t::RB_ID_NR_N_ITEMS; +} +inline int get_drb_id(rb_id_nr_t rb_id) +{ + return is_drb(rb_id) ? (rb_id - 3) : -1; +} + +} // namespace srslte + +#endif // SRSLTE_NR_COMMON_INTERFACE_TYPES_H diff --git a/srsenb/hdr/stack/upper/common_enb.h b/srsenb/hdr/stack/upper/common_enb.h index 6a13563ec..36828a9ba 100644 --- a/srsenb/hdr/stack/upper/common_enb.h +++ b/srsenb/hdr/stack/upper/common_enb.h @@ -51,8 +51,11 @@ enum rb_id_t { RB_ID_DRB8, RB_ID_N_ITEMS, }; -static const char* rb_id_text[] = - {"SRB0", "SRB1", "SRB2", "DRB1", "DRB2", "DRB3", "DRB4", "DRB5", "DRB6", "DRB7", "DRB8"}; +inline const char* to_string(rb_id_t rb_id) +{ + const static char* names[] = {"SRB0", "SRB1", "SRB2", "DRB1", "DRB2", "DRB3", "DRB4", "DRB5", "DRB6", "DRB7", "DRB8"}; + return (rb_id < RB_ID_N_ITEMS) ? names[rb_id] : "invalid bearer id"; +} // Cat 3 UE - Max number of DL-SCH transport block bits received within a TTI // 3GPP 36.306 Table 4.1.1 diff --git a/srsenb/src/stack/rrc/rrc.cc b/srsenb/src/stack/rrc/rrc.cc index 587549132..387415dba 100644 --- a/srsenb/src/stack/rrc/rrc.cc +++ b/srsenb/src/stack/rrc/rrc.cc @@ -531,7 +531,7 @@ void rrc::parse_ul_dcch(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer if (user_it != users.end()) { user_it->second->parse_ul_dcch(lcid, std::move(pdu)); } else { - rrc_log->error("Processing %s: Unknown rnti=0x%x\n", rb_id_text[lcid], rnti); + rrc_log->error("Processing %s: Unknown rnti=0x%x\n", srsenb::to_string((rb_id_t)lcid), rnti); } } } @@ -797,7 +797,7 @@ void rrc::tti_clock() while (rx_pdu_queue.try_pop(&p)) { // print Rx PDU if (p.pdu != nullptr) { - rrc_log->info_hex(p.pdu->msg, p.pdu->N_bytes, "Rx %s PDU", rb_id_text[p.lcid]); + rrc_log->info_hex(p.pdu->msg, p.pdu->N_bytes, "Rx %s PDU", to_string((rb_id_t)p.lcid)); } // check if user exists diff --git a/srsenb/src/stack/rrc/rrc_ue.cc b/srsenb/src/stack/rrc/rrc_ue.cc index c84493975..e94e8cb87 100644 --- a/srsenb/src/stack/rrc/rrc_ue.cc +++ b/srsenb/src/stack/rrc/rrc_ue.cc @@ -161,7 +161,8 @@ void rrc::ue::parse_ul_dcch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) return; } - parent->log_rrc_message(rb_id_text[lcid], Rx, pdu.get(), ul_dcch_msg, ul_dcch_msg.msg.c1().type().to_string()); + parent->log_rrc_message( + srsenb::to_string((rb_id_t)lcid), Rx, pdu.get(), ul_dcch_msg, ul_dcch_msg.msg.c1().type().to_string()); // reuse PDU pdu->clear(); // TODO: name collision with byte_buffer reset diff --git a/srsenb/src/stack/upper/pdcp.cc b/srsenb/src/stack/upper/pdcp.cc index 56f69cf95..989aa9721 100644 --- a/srsenb/src/stack/upper/pdcp.cc +++ b/srsenb/src/stack/upper/pdcp.cc @@ -193,7 +193,7 @@ void pdcp::user_interface_rrc::write_pdu_pcch(srslte::unique_byte_buffer_t pdu) std::string pdcp::user_interface_rrc::get_rb_name(uint32_t lcid) { - return std::string(rb_id_text[lcid]); + return to_string((rb_id_t)lcid); } } // namespace srsenb diff --git a/srsenb/src/stack/upper/rlc.cc b/srsenb/src/stack/upper/rlc.cc index f6d623d5d..95b3817a3 100644 --- a/srsenb/src/stack/upper/rlc.cc +++ b/srsenb/src/stack/upper/rlc.cc @@ -184,7 +184,7 @@ void rlc::read_pdu_pcch(uint8_t* payload, uint32_t buffer_size) int rlc::read_pdu(uint16_t rnti, uint32_t lcid, uint8_t* payload, uint32_t nof_bytes) { - int ret; + int ret; pthread_rwlock_rdlock(&rwlock); if (users.count(rnti)) { @@ -273,7 +273,7 @@ void rlc::user_interface::write_pdu_pcch(srslte::unique_byte_buffer_t sdu) std::string rlc::user_interface::get_rb_name(uint32_t lcid) { - return std::string(rb_id_text[lcid]); + return to_string((rb_id_t)lcid); } } // namespace srsenb diff --git a/srsue/hdr/stack/rrc/rrc_nr.h b/srsue/hdr/stack/rrc/rrc_nr.h index 5887c7858..8f2b16e87 100644 --- a/srsue/hdr/stack/rrc/rrc_nr.h +++ b/srsue/hdr/stack/rrc/rrc_nr.h @@ -25,6 +25,7 @@ #include "srslte/asn1/rrc_nr_asn1.h" #include "srslte/common/block_queue.h" #include "srslte/common/buffer_pool.h" +#include "srslte/interfaces/nr_common_interface_types.h" #include "srslte/interfaces/ue_interfaces.h" #include "srslte/interfaces/ue_nr_interfaces.h" #include "srsue/hdr/stack/upper/gw.h" @@ -134,17 +135,7 @@ private: // RRC constants and timers srslte::timer_handler* timers = nullptr; - // Radio bearers - std::map rb_id_t = {{0, "SRB0"}, {1, "SRB1"}, {2, "SRB2"}, {3, "SRB3"}, {4, "DRB1"}}; - - std::string get_rb_name(uint32_t lcid) final - { - if (lcid < rb_id_t.size()) { - return rb_id_t.at(lcid); - } else { - return "INVALID_RB"; - } - } + std::string get_rb_name(uint32_t lcid) final { return srslte::to_string((srslte::rb_id_nr_t)lcid); } bool initiated = false; };