diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index 57c3e3d24..036b928ed 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -632,6 +632,13 @@ public: virtual void wait_ra_completion(uint16_t rnti) = 0; }; +// STACK interface for RRC +class stack_interface_rrc +{ +public: + virtual void start_cell_search() = 0; +}; + // Combined interface for PHY to access stack (MAC and RRC) class stack_interface_phy_lte : public mac_interface_phy_lte, public rrc_interface_phy_lte { diff --git a/srsue/hdr/stack/rrc/rrc.h b/srsue/hdr/stack/rrc/rrc.h index 509aca629..9a414b6f9 100644 --- a/srsue/hdr/stack/rrc/rrc.h +++ b/srsue/hdr/stack/rrc/rrc.h @@ -299,6 +299,7 @@ public: usim_interface_rrc* usim_, gw_interface_rrc* gw_, srslte::timers* timers_, + stack_interface_rrc* stack_, const rrc_args_t& args_); void stop(); @@ -349,8 +350,11 @@ public: void write_pdu_pcch(srslte::unique_byte_buffer_t pdu); void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t pdu); -private: + // STACK interface + void cell_search_completed(const phy_interface_rrc_lte::cell_search_ret_t& cs_ret, + const phy_interface_rrc_lte::phy_cell_t& found_cell); +private: typedef struct { enum { PDU, PCCH, PDU_MCH, RLF, PDU_BCCH_DLSCH, STOP } command; srslte::unique_byte_buffer_t pdu; @@ -371,6 +375,7 @@ private: nas_interface_rrc* nas = nullptr; usim_interface_rrc* usim = nullptr; gw_interface_rrc* gw = nullptr; + stack_interface_rrc* stack = nullptr; srslte::unique_byte_buffer_t dedicated_info_nas; diff --git a/srsue/hdr/stack/rrc/rrc_procedures.h b/srsue/hdr/stack/rrc/rrc_procedures.h index 0e898d375..d73c55f7f 100644 --- a/srsue/hdr/stack/rrc/rrc_procedures.h +++ b/srsue/hdr/stack/rrc/rrc_procedures.h @@ -32,12 +32,17 @@ namespace srsue { class rrc::cell_search_proc : public srslte::proc_impl_t { public: + struct cell_search_event_t { + phy_interface_rrc_lte::cell_search_ret_t cs_ret; + phy_interface_rrc_lte::phy_cell_t found_cell; + }; enum class state_t { phy_cell_search, si_acquire }; srslte::proc_outcome_t init(rrc* parent_); srslte::proc_outcome_t step() final; + srslte::proc_outcome_t trigger_event(const cell_search_event_t& event); - phy_interface_rrc_lte::cell_search_ret_t get_cs_ret() { return cs_ret; } + phy_interface_rrc_lte::cell_search_ret_t get_cs_ret() { return search_result.cs_ret; } static const char* name() { return "Cell Search"; } private: @@ -48,8 +53,8 @@ private: srslte::log* log_h; // state vars - phy_interface_rrc_lte::cell_search_ret_t cs_ret; - state_t state; + cell_search_event_t search_result; + state_t state; }; class rrc::si_acquire_proc : public srslte::proc_impl_t diff --git a/srsue/hdr/stack/ue_stack_lte.h b/srsue/hdr/stack/ue_stack_lte.h index 7a7cc1c44..dbfb8f485 100644 --- a/srsue/hdr/stack/ue_stack_lte.h +++ b/srsue/hdr/stack/ue_stack_lte.h @@ -54,6 +54,7 @@ class ue_stack_lte final : public ue_stack_base, public stack_interface_phy_lte, public stack_interface_gw, public stack_interface_mac, + public stack_interface_rrc, public thread { public: @@ -117,6 +118,9 @@ public: void process_pdus() final; void wait_ra_completion(uint16_t rnti) final; + // Interface for RRC + void start_cell_search() final; + private: void run_thread() final; void run_tti_impl(uint32_t tti); diff --git a/srsue/src/stack/rrc/rrc.cc b/srsue/src/stack/rrc/rrc.cc index fa8009839..85a44ddc1 100644 --- a/srsue/src/stack/rrc/rrc.cc +++ b/srsue/src/stack/rrc/rrc.cc @@ -98,16 +98,18 @@ void rrc::init(phy_interface_rrc_lte* phy_, usim_interface_rrc* usim_, gw_interface_rrc* gw_, srslte::timers* timers_, + stack_interface_rrc* stack_, const rrc_args_t& args_) { - pool = byte_buffer_pool::get_instance(); + pool = byte_buffer_pool::get_instance(); phy = phy_; mac = mac_; rlc = rlc_; pdcp = pdcp_; - nas = nas_; - usim = usim_; - gw = gw_; + nas = nas_; + usim = usim_; + gw = gw_; + stack = stack_; args = args_; @@ -325,9 +327,9 @@ void rrc::plmn_select(srslte::plmn_id_t plmn_id) * it. Sends connectionRequest message and returns if message transmitted successfully. * It does not wait until completition of Connection Establishment procedure */ -bool rrc::connection_request(srslte::establishment_cause_t cause, srslte::unique_byte_buffer_t dedicated_info_nas) +bool rrc::connection_request(srslte::establishment_cause_t cause, srslte::unique_byte_buffer_t dedicated_info_nas_) { - if (not conn_req_proc.launch(this, cause, std::move(dedicated_info_nas))) { + if (not conn_req_proc.launch(this, cause, std::move(dedicated_info_nas_))) { rrc_log->error("Failed to initiate connection request procedure\n"); return false; } @@ -1479,15 +1481,21 @@ void rrc::start_cell_reselection() }); } +void rrc::cell_search_completed(const phy_interface_rrc_lte::cell_search_ret_t& cs_ret, + const phy_interface_rrc_lte::phy_cell_t& found_cell) +{ + cell_searcher.trigger_event(cell_search_proc::cell_search_event_t{cs_ret, found_cell}); +} + /******************************************************************************* -* -* -* -* Reception of Broadcast messages (MIB and SIBs) -* -* -* -*******************************************************************************/ + * + * + * + * Reception of Broadcast messages (MIB and SIBs) + * + * + * + *******************************************************************************/ void rrc::write_pdu_bcch_bch(unique_byte_buffer_t pdu) { asn1::rrc::bcch_bch_msg_s bch_msg; @@ -2847,11 +2855,12 @@ void rrc::set_rrc_default() * ************************************************************************/ -void rrc::rrc_meas::init(rrc *parent) { - this->parent = parent; - this->log_h = parent->rrc_log; - this->phy = parent->phy; - this->timers = parent->timers; +void rrc::rrc_meas::init(rrc* parent_) +{ + this->parent = parent_; + this->log_h = parent_->rrc_log; + this->phy = parent_->phy; + this->timers = parent_->timers; s_measure_enabled = false; reset(); } diff --git a/srsue/src/stack/rrc/rrc_procedures.cc b/srsue/src/stack/rrc/rrc_procedures.cc index facde57eb..4d5ed476e 100644 --- a/srsue/src/stack/rrc/rrc_procedures.cc +++ b/srsue/src/stack/rrc/rrc_procedures.cc @@ -43,6 +43,7 @@ proc_outcome_t rrc::cell_search_proc::init(srsue::rrc* parent_) Info("Starting...\n"); state = state_t::phy_cell_search; + rrc_ptr->stack->start_cell_search(); return proc_outcome_t::repeat; } @@ -50,25 +51,8 @@ proc_outcome_t rrc::cell_search_proc::init(srsue::rrc* parent_) proc_outcome_t rrc::cell_search_proc::step() { if (state == state_t::phy_cell_search) { - // Blocks waiting for result of phy cell search - phy_interface_rrc_lte::phy_cell_t new_cell; - - // BLOCKING CALL - cs_ret = rrc_ptr->phy->cell_search(&new_cell); - - switch (cs_ret.found) { - case phy_interface_rrc_lte::cell_search_ret_t::CELL_FOUND: { - return handle_cell_found(new_cell); - } - case phy_interface_rrc_lte::cell_search_ret_t::CELL_NOT_FOUND: - Info("No cells found.\n"); - // do nothing - return proc_outcome_t::success; - case phy_interface_rrc_lte::cell_search_ret_t::ERROR: - Error("Error while performing cell search\n"); - // TODO: check what errors can happen (currently not handled in our code) - return proc_outcome_t::error; - } + // Waits for cell search to complete + return proc_outcome_t::yield; } else if (state == state_t::si_acquire) { if (not rrc_ptr->si_acquirer.run()) { // SI Acquire has completed @@ -121,6 +105,32 @@ proc_outcome_t rrc::cell_search_proc::handle_cell_found(const phy_interface_rrc_ return proc_outcome_t::repeat; } +proc_outcome_t rrc::cell_search_proc::trigger_event(const cell_search_event_t& event) +{ + if (state != state_t::phy_cell_search) { + Error("Received unexpected cell search result\n"); + return proc_outcome_t::error; + } + search_result = event; + + Info("PHY cell search completed.\n"); + // Transition to SI Acquire or finish + switch (search_result.cs_ret.found) { + case phy_interface_rrc_lte::cell_search_ret_t::CELL_FOUND: { + return handle_cell_found(search_result.found_cell); + } + case phy_interface_rrc_lte::cell_search_ret_t::CELL_NOT_FOUND: + Info("No cells found.\n"); + // do nothing + return proc_outcome_t::success; + case phy_interface_rrc_lte::cell_search_ret_t::ERROR: + Error("Error while performing cell search\n"); + // TODO: check what errors can happen (currently not handled in our code) + return proc_outcome_t::error; + } + return proc_outcome_t::yield; +} + /************************************** * SI Acquire Procedure *************************************/ diff --git a/srsue/src/stack/ue_stack_lte.cc b/srsue/src/stack/ue_stack_lte.cc index 2b6210707..e24524f40 100644 --- a/srsue/src/stack/ue_stack_lte.cc +++ b/srsue/src/stack/ue_stack_lte.cc @@ -127,7 +127,7 @@ int ue_stack_lte::init(const stack_args_t& args_, srslte::logger* logger_) rlc.init(&pdcp, &rrc, &timers, 0 /* RB_ID_SRB0 */); pdcp.init(&rlc, &rrc, gw); nas.init(usim.get(), &rrc, gw, args.nas); - rrc.init(phy, &mac, &rlc, &pdcp, &nas, usim.get(), gw, &timers, args.rrc); + rrc.init(phy, &mac, &rlc, &pdcp, &nas, usim.get(), gw, &timers, this, args.rrc); running = true; start(STACK_MAIN_THREAD_PRIO); @@ -284,11 +284,25 @@ void ue_stack_lte::process_pdus() void ue_stack_lte::wait_ra_completion(uint16_t rnti) { - background_tasks.push_task([this, rnti](uint32_t worker_id){ + background_tasks.push_task([this, rnti](uint32_t worker_id) { phy->set_crnti(rnti); // signal MAC RA proc to go back to idle mac.notify_ra_completed(); }); } +/******************** + * RRC Interface + *******************/ + +void ue_stack_lte::start_cell_search() +{ + background_tasks.push_task([this](uint32_t worker_id) { + phy_interface_rrc_lte::phy_cell_t found_cell; + phy_interface_rrc_lte::cell_search_ret_t ret = phy->cell_search(&found_cell); + // notify back RRC + rrc.cell_search_completed(ret, found_cell); + }); +} + } // namespace srsue