From 290f39d80580eea4feacb84beb31d995c868ab46 Mon Sep 17 00:00:00 2001 From: Francisco Date: Tue, 2 Mar 2021 13:48:19 +0000 Subject: [PATCH] fix crnti mac ce handling in the rrc in normal (no handover) case --- lib/include/srslte/common/byte_buffer.h | 5 ++- srsenb/hdr/stack/rrc/mac_controller.h | 1 + srsenb/hdr/stack/rrc/rrc.h | 1 + srsenb/hdr/stack/rrc/rrc_ue.h | 1 + srsenb/src/stack/rrc/rrc.cc | 44 +++++++++++++++++++++---- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/lib/include/srslte/common/byte_buffer.h b/lib/include/srslte/common/byte_buffer.h index 3719c4747..bf6dc1450 100644 --- a/lib/include/srslte/common/byte_buffer.h +++ b/lib/include/srslte/common/byte_buffer.h @@ -132,7 +132,7 @@ public: } uint32_t get_headroom() { return msg - buffer; } // Returns the remaining space from what is reported to be the length of msg - uint32_t get_tailroom() { return (sizeof(buffer) - (msg - buffer) - N_bytes); } + uint32_t get_tailroom() const { return (sizeof(buffer) - (msg - buffer) - N_bytes); } std::chrono::microseconds get_latency_us() const { return md.tp.get_latency_us(); } std::chrono::high_resolution_clock::time_point get_timestamp() const { return md.tp.get_timestamp(); } @@ -147,6 +147,9 @@ public: N_bytes += size; } + // vector-like interface + void resize(size_t size) { N_bytes = size; } + size_t capacity() const { return get_tailroom(); } uint8_t* data() { return msg; } const uint8_t* data() const { return msg; } uint32_t size() const { return N_bytes; } diff --git a/srsenb/hdr/stack/rrc/mac_controller.h b/srsenb/hdr/stack/rrc/mac_controller.h index 83037baa2..3a97de60a 100644 --- a/srsenb/hdr/stack/rrc/mac_controller.h +++ b/srsenb/hdr/stack/rrc/mac_controller.h @@ -56,6 +56,7 @@ public: void handle_ho_prep(const asn1::rrc::ho_prep_info_r8_ies_s& ho_prep); const ue_cfg_t& get_ue_sched_cfg() const { return current_sched_ue_cfg; } + bool is_crnti_set() const { return crnti_set; } void set_scell_activation(const std::bitset& scell_mask); void set_drb_activation(bool active); diff --git a/srsenb/hdr/stack/rrc/rrc.h b/srsenb/hdr/stack/rrc/rrc.h index 1f8547d0f..75328750b 100644 --- a/srsenb/hdr/stack/rrc/rrc.h +++ b/srsenb/hdr/stack/rrc/rrc.h @@ -171,6 +171,7 @@ private: void config_mac(); void parse_ul_dcch(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t pdu); void parse_ul_ccch(uint16_t rnti, srslte::unique_byte_buffer_t pdu); + void send_rrc_connection_reject(uint16_t rnti); uint32_t paging_tti = INVALID_TTI; srslte::byte_buffer_t byte_buf_paging; diff --git a/srsenb/hdr/stack/rrc/rrc_ue.h b/srsenb/hdr/stack/rrc/rrc_ue.h index 90eb43610..725abaeb5 100644 --- a/srsenb/hdr/stack/rrc/rrc_ue.h +++ b/srsenb/hdr/stack/rrc/rrc_ue.h @@ -98,6 +98,7 @@ public: int get_cqi(uint16_t* pmi_idx, uint16_t* n_pucch, uint32_t ue_cc_idx); int get_ri(uint32_t m_ri, uint16_t* ri_idx); bool is_allocated() const; + bool is_crnti_set() const { return mac_ctrl.is_crnti_set(); } void send_dl_ccch(asn1::rrc::dl_ccch_msg_s* dl_ccch_msg); bool send_dl_dcch(const asn1::rrc::dl_dcch_msg_s* dl_dcch_msg, diff --git a/srsenb/src/stack/rrc/rrc.cc b/srsenb/src/stack/rrc/rrc.cc index 78a5fd28f..8a209c2ab 100644 --- a/srsenb/src/stack/rrc/rrc.cc +++ b/srsenb/src/stack/rrc/rrc.cc @@ -193,18 +193,48 @@ void rrc::upd_user(uint16_t new_rnti, uint16_t old_rnti) // Send Reconfiguration to old_rnti if is RRC_CONNECT or RRC Release if already released here auto old_it = users.find(old_rnti); - if (old_it != users.end()) { - auto ue_ptr = old_it->second.get(); - if (ue_ptr->mobility_handler->is_ho_running()) { - ue_ptr->mobility_handler->trigger(ue::rrc_mobility::user_crnti_upd_ev{old_rnti, new_rnti}); - } else if (ue_ptr->is_connected()) { + if (old_it == users.end()) { + send_rrc_connection_reject(old_rnti); + return; + } + ue* ue_ptr = old_it->second.get(); + + if (ue_ptr->mobility_handler->is_ho_running()) { + ue_ptr->mobility_handler->trigger(ue::rrc_mobility::user_crnti_upd_ev{old_rnti, new_rnti}); + } else { + logger.info("Resuming rnti=0x%x RRC connection due to received C-RNTI CE from rnti=0x%x.", old_rnti, new_rnti); + if (ue_ptr->is_connected()) { + // Send a new RRC Reconfiguration to overlay previous old_it->second->send_connection_reconf(); - } else { - old_it->second->send_connection_reject(); } } } +// Note: this method is not part of UE methods, because the UE context may not exist anymore when reject is sent +void rrc::send_rrc_connection_reject(uint16_t rnti) +{ + dl_ccch_msg_s dl_ccch_msg; + dl_ccch_msg.msg.set_c1().set_rrc_conn_reject().crit_exts.set_c1().set_rrc_conn_reject_r8().wait_time = 10; + + // Allocate a new PDU buffer, pack the message and send to PDCP + srslte::unique_byte_buffer_t pdu = srslte::make_byte_buffer(); + if (pdu == nullptr) { + logger.error("Allocating pdu"); + return; + } + asn1::bit_ref bref(pdu->msg, pdu->get_tailroom()); + if (dl_ccch_msg.pack(bref) != asn1::SRSASN_SUCCESS) { + logger.error(pdu->msg, bref.distance_bytes(), "Failed to pack DL-CCCH-Msg:"); + return; + } + pdu->N_bytes = bref.distance_bytes(); + + char buf[32] = {}; + sprintf(buf, "SRB0 - rnti=0x%x", rnti); + log_rrc_message(buf, Tx, pdu.get(), dl_ccch_msg, dl_ccch_msg.msg.c1().type().to_string()); + rlc->write_sdu(rnti, RB_ID_SRB0, std::move(pdu)); +} + /******************************************************************************* PDCP interface *******************************************************************************/