diff --git a/lib/include/srslte/mac/mac_rar_pdu_nr.h b/lib/include/srslte/mac/mac_rar_pdu_nr.h index ae3084ebb..6ef9857d9 100644 --- a/lib/include/srslte/mac/mac_rar_pdu_nr.h +++ b/lib/include/srslte/mac/mac_rar_pdu_nr.h @@ -15,6 +15,7 @@ #include "srslte/common/common.h" #include "srslte/config.h" +#include "srslte/phy/common/phy_common_nr.h" #include "srslte/srslog/srslog.h" #include #include @@ -34,21 +35,20 @@ public: mac_rar_subpdu_nr(mac_rar_pdu_nr* parent_); // RAR content length in bits (38.321 Sec 6.2.3) - static const uint32_t UL_GRANT_NBITS = 27; + static const uint32_t UL_GRANT_NBITS = SRSLTE_RAR_UL_GRANT_NBITS; static const uint32_t TA_COMMAND_NBITS = 12; // getter bool read_subpdu(const uint8_t* ptr); bool has_more_subpdus(); uint32_t get_total_length(); - bool has_rapid(); - uint8_t get_rapid(); - uint16_t get_temp_crnti(); - uint32_t get_ta(); - void get_ul_grant(std::array& grant); - - bool has_backoff(); - uint8_t get_backoff(); + bool has_rapid() const; + uint8_t get_rapid() const; + uint16_t get_temp_crnti() const; + uint32_t get_ta() const; + std::array get_ul_grant() const; + bool has_backoff() const; + uint8_t get_backoff() const; // setter uint32_t write_subpdu(const uint8_t* start_); @@ -82,7 +82,10 @@ public: bool pack(); bool unpack(const uint8_t* payload, const uint32_t& len); uint32_t get_num_subpdus(); + // Returns reference to a single subPDU const mac_rar_subpdu_nr& get_subpdu(const uint32_t& index); + // Returns reference to all subPDUs + const std::vector& get_subpdus(); uint32_t get_remaining_len(); diff --git a/lib/include/srslte/phy/common/phy_common_nr.h b/lib/include/srslte/phy/common/phy_common_nr.h index 5ebe70161..45e4f300d 100644 --- a/lib/include/srslte/phy/common/phy_common_nr.h +++ b/lib/include/srslte/phy/common/phy_common_nr.h @@ -151,6 +151,11 @@ typedef enum SRSLTE_API { */ #define SRSLTE_SEARCH_SPACE_IS_COMMON(SS_TYPE) ((SS_TYPE) < srslte_search_space_type_ue) +/** + * @brief RAR content length in bits (see TS 38.321 Sec 6.2.3) + */ +#define SRSLTE_RAR_UL_GRANT_NBITS (27) + /** * @brief Indicates the MCS table the UE shall use for PDSCH and/or PUSCH without transform precoding */ diff --git a/lib/src/mac/mac_rar_pdu_nr.cc b/lib/src/mac/mac_rar_pdu_nr.cc index b4cf347cd..558870d83 100644 --- a/lib/src/mac/mac_rar_pdu_nr.cc +++ b/lib/src/mac/mac_rar_pdu_nr.cc @@ -91,27 +91,27 @@ uint32_t mac_rar_subpdu_nr::get_total_length() return (header_length + payload_length); } -bool mac_rar_subpdu_nr::has_rapid() +bool mac_rar_subpdu_nr::has_rapid() const { return (type == rar_subh_type_t::RAPID); } -uint8_t mac_rar_subpdu_nr::get_rapid() +uint8_t mac_rar_subpdu_nr::get_rapid() const { return rapid; } -uint32_t mac_rar_subpdu_nr::get_ta() +uint32_t mac_rar_subpdu_nr::get_ta() const { return ta; } -uint16_t mac_rar_subpdu_nr::get_temp_crnti() +uint16_t mac_rar_subpdu_nr::get_temp_crnti() const { return temp_crnti; } -bool mac_rar_subpdu_nr::has_backoff() +bool mac_rar_subpdu_nr::has_backoff() const { return (type == rar_subh_type_t::BACKOFF); } @@ -121,9 +121,9 @@ void mac_rar_subpdu_nr::set_backoff(const uint8_t backoff_indicator_) backoff_indicator = backoff_indicator_; } -void mac_rar_subpdu_nr::get_ul_grant(std::array& grant_) +std::array mac_rar_subpdu_nr::get_ul_grant() const { - grant_ = ul_grant; + return ul_grant; } std::string mac_rar_subpdu_nr::to_string() @@ -197,6 +197,11 @@ const mac_rar_subpdu_nr& mac_rar_pdu_nr::get_subpdu(const uint32_t& index) return subpdus.at(index); } +const std::vector& mac_rar_pdu_nr::get_subpdus() +{ + return subpdus; +} + uint32_t mac_rar_pdu_nr::get_remaining_len() { return remaining_len; diff --git a/lib/test/mac/mac_pdu_nr_test.cc b/lib/test/mac/mac_pdu_nr_test.cc index b524c3a79..db0f13413 100644 --- a/lib/test/mac/mac_pdu_nr_test.cc +++ b/lib/test/mac/mac_pdu_nr_test.cc @@ -291,8 +291,7 @@ int mac_rar_pdu_unpack_test7() TESTASSERT(subpdu.get_ta() == tv_ta); TESTASSERT(subpdu.get_rapid() == tv_rapid); - std::array msg3_grant; - subpdu.get_ul_grant(msg3_grant); + std::array msg3_grant = subpdu.get_ul_grant(); TESTASSERT(memcmp(msg3_grant.data(), tv_msg3_grant, msg3_grant.size()) == 0); return SRSLTE_SUCCESS;