From f5c945dc2fe093c5c6529c550cd5fbade9d084c1 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 1 Feb 2021 21:32:00 +0100 Subject: [PATCH] mac_nr: add interface to set C-RNTI and contention ID from RRC used during contention-based/free RA --- .../srslte/interfaces/ue_nr_interfaces.h | 6 +++++ srsue/hdr/stack/mac_nr/mac_nr.h | 8 +++++-- srsue/src/stack/mac_nr/mac_nr.cc | 23 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/include/srslte/interfaces/ue_nr_interfaces.h b/lib/include/srslte/interfaces/ue_nr_interfaces.h index 1d9009b54..0468a606d 100644 --- a/lib/include/srslte/interfaces/ue_nr_interfaces.h +++ b/lib/include/srslte/interfaces/ue_nr_interfaces.h @@ -60,6 +60,12 @@ public: virtual void setup_lcid(const srslte::logical_channel_config_t& config) = 0; virtual void set_config(const srslte::bsr_cfg_t& bsr_cfg) = 0; virtual void set_config(const srslte::sr_cfg_t& sr_cfg) = 0; + + // RRC informs MAC about the (randomly) selected ID used for contention-based RA + virtual void set_contention_id(const uint64_t ue_identity) = 0; + + // RRC informs MAC about new UE identity for contention-free RA + virtual bool set_crnti(const uint16_t crnti) = 0; }; class phy_interface_mac_nr diff --git a/srsue/hdr/stack/mac_nr/mac_nr.h b/srsue/hdr/stack/mac_nr/mac_nr.h index a4c7ec031..875d63710 100644 --- a/srsue/hdr/stack/mac_nr/mac_nr.h +++ b/srsue/hdr/stack/mac_nr/mac_nr.h @@ -58,10 +58,12 @@ public: void get_metrics(mac_metrics_t* metrics); - /******** Interface for RRC (RRC -> MAC) ****************/ + /// Interface for RRC (RRC -> MAC) void setup_lcid(const srslte::logical_channel_config_t& config); void set_config(const srslte::bsr_cfg_t& bsr_cfg); void set_config(const srslte::sr_cfg_t& sr_cfg); + void set_contention_id(const uint64_t ue_identity); + bool set_crnti(const uint16_t crnti); /// stack interface void process_pdus(); @@ -76,6 +78,7 @@ private: bool has_crnti(); uint16_t get_crnti(); + bool is_valid_crnti(const uint16_t crnti); /// Interaction with rest of the stack phy_interface_mac_nr* phy = nullptr; @@ -89,7 +92,8 @@ private: bool started = false; - uint16_t crnti = 0xdead; + uint16_t crnti = 0xdead; + uint64_t contention_id = 0; static constexpr uint32_t MIN_RLC_PDU_LEN = 5; ///< minimum bytes that need to be available in a MAC PDU for attempting to add another RLC SDU diff --git a/srsue/src/stack/mac_nr/mac_nr.cc b/srsue/src/stack/mac_nr/mac_nr.cc index 61b48d164..596c8289e 100644 --- a/srsue/src/stack/mac_nr/mac_nr.cc +++ b/srsue/src/stack/mac_nr/mac_nr.cc @@ -258,6 +258,29 @@ void mac_nr::set_config(const srslte::sr_cfg_t& sr_cfg) logger.warning("Not Scheduling Request Config yet"); } +void mac_nr::set_contention_id(uint64_t ue_identity) +{ + contention_id = ue_identity; +} + +bool mac_nr::set_crnti(const uint16_t crnti_) +{ + if (is_valid_crnti(crnti_)) { + logger.info("Setting C-RNTI to 0x%X", crnti_); + crnti = crnti_; + return true; + } else { + logger.warning("Failed to set C-RNTI, 0x%X is not valid.", crnti_); + return false; + } +} + +bool mac_nr::is_valid_crnti(const uint16_t crnti) +{ + // TS 38.321 15.3.0 Table 7.1-1 + return (crnti >= 0x0001 && crnti <= 0xFFEF); +} + void mac_nr::get_metrics(mac_metrics_t m[SRSLTE_MAX_CARRIERS]) {} /**