diff --git a/srsue/hdr/stack/rrc_nr/rrc_nr.h b/srsue/hdr/stack/rrc_nr/rrc_nr.h index 48e1c37e9..86a911eca 100644 --- a/srsue/hdr/stack/rrc_nr/rrc_nr.h +++ b/srsue/hdr/stack/rrc_nr/rrc_nr.h @@ -87,7 +87,6 @@ public: // PHY interface void in_sync() final; void out_of_sync() final; - void cell_search_found_cell(const cell_search_result_t& result) final{}; // RLC interface void max_retx_attempted() final; @@ -122,8 +121,9 @@ public: void rrc_release(); bool configure_sk_counter(uint16_t sk_counter); bool is_config_pending(); + // STACK interface - void cell_search_completed(const rrc_interface_phy_lte::cell_search_ret_t& cs_ret, const phy_cell_t& found_cell); + void cell_search_found_cell(const rrc_interface_phy_nr::cell_search_result_t& result) final; void cell_select_completed(const cell_select_result_t& result) final; void set_phy_config_complete(bool status) final; diff --git a/srsue/hdr/stack/rrc_nr/rrc_nr_procedures.h b/srsue/hdr/stack/rrc_nr/rrc_nr_procedures.h index 8de42297e..fc75e4f0a 100644 --- a/srsue/hdr/stack/rrc_nr/rrc_nr_procedures.h +++ b/srsue/hdr/stack/rrc_nr/rrc_nr_procedures.h @@ -32,7 +32,8 @@ public: srsran::proc_outcome_t step(); cell_search_result_t get_result() const { return cell_search_ret; } static const char* name() { return "Cell Selection"; } - srsran::proc_outcome_t react(const bool& event); + srsran::proc_outcome_t react(const rrc_interface_phy_nr::cell_search_result_t& result); + srsran::proc_outcome_t react(const rrc_interface_phy_nr::cell_select_result_t& result); void then(const srsran::proc_result_t& proc_result) const; private: diff --git a/srsue/hdr/stack/ue_stack_lte.h b/srsue/hdr/stack/ue_stack_lte.h index 102082926..e48e94ead 100644 --- a/srsue/hdr/stack/ue_stack_lte.h +++ b/srsue/hdr/stack/ue_stack_lte.h @@ -125,7 +125,8 @@ public: void run_tti(uint32_t tti, uint32_t tti_jump) final; // RRC interface for NR PHY - void cell_search_found_cell(const cell_search_result_t& result) final {} + void cell_search_found_cell(const cell_search_result_t& result) final; + void cell_select_completed(const cell_select_result_t& result) final; // MAC Interface for NR PHY void tb_decoded(const uint32_t cc_idx, @@ -168,7 +169,6 @@ public: void reset_eps_bearers() final; srsran::ext_task_sched_handle get_task_sched() { return {&task_sched}; } - void cell_select_completed(const cell_select_result_t& result) override; private: void run_thread() final; diff --git a/srsue/src/stack/rrc_nr/rrc_nr.cc b/srsue/src/stack/rrc_nr/rrc_nr.cc index 558a2e715..c49efdc5b 100644 --- a/srsue/src/stack/rrc_nr/rrc_nr.cc +++ b/srsue/src/stack/rrc_nr/rrc_nr.cc @@ -396,12 +396,8 @@ void rrc_nr::handle_sib1(const sib1_s& sib1) // Apply SSB Config fill_phy_ssb_cfg(sib1.serving_cell_cfg_common, &phy_cfg.ssb); - // Init cell selection - phy_interface_rrc_nr::cell_select_args_t cell_cfg = {}; - cell_cfg.carrier = phy_cfg.carrier; - cell_cfg.ssb_cfg = phy_cfg.get_ssb_cfg(); - if (not phy->start_cell_select(cell_cfg)) { - logger.warning("Could not set start cell select."); + if (not phy->set_config(phy_cfg)) { + logger.warning("Could not set phy config."); return; } } @@ -1998,8 +1994,10 @@ void rrc_nr::ra_problem() void rrc_nr::release_pucch_srs() {} // STACK interface -void rrc_nr::cell_search_completed(const rrc_interface_phy_lte::cell_search_ret_t& cs_ret, const phy_cell_t& found_cell) -{} +void rrc_nr::cell_search_found_cell(const rrc_interface_phy_nr::cell_search_result_t& result) +{ + cell_selector.trigger(result); +} void rrc_nr::set_phy_config_complete(bool status) { @@ -2021,10 +2019,7 @@ void rrc_nr::set_phy_config_complete(bool status) void rrc_nr::cell_select_completed(const rrc_interface_phy_nr::cell_select_result_t& result) { - if (not phy->set_config(phy_cfg)) { - logger.warning("Could not set phy config."); - return; - } + cell_selector.trigger(result); } } // namespace srsue diff --git a/srsue/src/stack/rrc_nr/rrc_nr_procedures.cc b/srsue/src/stack/rrc_nr/rrc_nr_procedures.cc index 5f93e6fbf..4780d2508 100644 --- a/srsue/src/stack/rrc_nr/rrc_nr_procedures.cc +++ b/srsue/src/stack/rrc_nr/rrc_nr_procedures.cc @@ -367,18 +367,21 @@ proc_outcome_t rrc_nr::cell_selection_proc::init() init_serv_cell = meas_cells.serving_cell().phy_cell; // TODO: add full cell selection - phy_interface_rrc_nr::cell_select_args_t cell_cfg = {}; - cell_cfg.carrier = rrc_handle.phy_cfg.carrier; - cell_cfg.ssb_cfg = rrc_handle.phy_cfg.get_ssb_cfg(); - rrc_handle.phy->start_cell_select(cell_cfg); - - // Skip cell selection if serving cell is suitable and there are no stronger neighbours in same earfcn - if (is_serv_cell_suitable()) { - Debug("Skipping cell selection procedure as there are no stronger neighbours in same EARFCN."); - return set_proc_complete(); + // Start cell search + phy_interface_rrc_nr::cell_search_args_t cs_args = {}; + cs_args.center_freq_hz = rrc_handle.phy_cfg.carrier.dl_center_frequency_hz; + cs_args.ssb_freq_hz = rrc_handle.phy_cfg.carrier.ssb_center_freq_hz; + cs_args.ssb_scs = rrc_handle.phy_cfg.ssb.scs; + cs_args.ssb_pattern = rrc_handle.phy_cfg.ssb.pattern; + cs_args.duplex_mode = rrc_handle.phy_cfg.duplex.mode; + if (not rrc_handle.phy->start_cell_search(cs_args)) { + Error("Could not set start cell search."); + return proc_outcome_t::error; } - return set_proc_complete(); + state = search_state_t::cell_search; + + return proc_outcome_t::yield; } proc_outcome_t rrc_nr::cell_selection_proc::step() @@ -400,6 +403,61 @@ proc_outcome_t rrc_nr::cell_selection_proc::step() return proc_outcome_t::error; } +proc_outcome_t rrc_nr::cell_selection_proc::react(const rrc_interface_phy_nr::cell_search_result_t& result) +{ + if (state != search_state_t::cell_search) { + Error("Cell search result received in wrong state"); + return proc_outcome_t::error; + } + + // Print result only if the cell is found + if (result.cell_found) { + // Convert Cell measurement in Text + std::array csi_info_str = {}; + srsran_csi_meas_info_short(&result.measurements, csi_info_str.data(), (uint32_t)csi_info_str.size()); + + // Unpack MIB and convert to text + srsran_mib_nr_t mib = {}; + std::array mib_info_str = {}; + if (srsran_pbch_msg_nr_mib_unpack(&result.pbch_msg, &mib) == SRSASN_SUCCESS) { + // Convert to text + srsran_pbch_msg_nr_mib_info(&mib, mib_info_str.data(), (uint32_t)mib_info_str.size()); + } else { + // It could be the PBCH does not carry MIB + strcpy(mib_info_str.data(), "No MIB found"); + } + + // Logs the PCI, cell measurements and decoded MIB + Info("Cell search found PCI=%d %s %s", result.pci, csi_info_str.data(), mib_info_str.data()); + } else { + Info("Cell search did not find any cell"); + } + + // Transition to cell selection ignoring the cell search result + state = search_state_t::cell_selection; + + phy_interface_rrc_nr::cell_select_args_t cs_args = {}; + cs_args.carrier = rrc_handle.phy_cfg.carrier; + cs_args.ssb_cfg = rrc_handle.phy_cfg.get_ssb_cfg(); + + if (not rrc_handle.phy->start_cell_select(cs_args)) { + Error("Could not set start cell search."); + return proc_outcome_t::error; + } + + return proc_outcome_t::yield; +} + +proc_outcome_t rrc_nr::cell_selection_proc::react(const rrc_interface_phy_nr::cell_select_result_t& result) +{ + if (state != search_state_t::cell_selection) { + Error("Cell selection result received in wrong state"); + return proc_outcome_t::error; + } + + return set_proc_complete(); +} + void rrc_nr::cell_selection_proc::then(const srsran::proc_result_t& proc_result) const { Info("Completed with %s.", proc_result.is_success() ? "success" : "failure"); diff --git a/srsue/src/stack/ue_stack_lte.cc b/srsue/src/stack/ue_stack_lte.cc index d7880b5ad..3914bdc53 100644 --- a/srsue/src/stack/ue_stack_lte.cc +++ b/srsue/src/stack/ue_stack_lte.cc @@ -510,9 +510,13 @@ void ue_stack_lte::set_phy_config_complete(bool status) cfg_task_queue.push([this, status]() { rrc_nr.set_phy_config_complete(status); }); } +void ue_stack_lte::cell_search_found_cell(const cell_search_result_t& result) +{ + cfg_task_queue.push([this, result]() { rrc_nr.cell_search_found_cell(result); }); +} void ue_stack_lte::cell_select_completed(const rrc_interface_phy_nr::cell_select_result_t& result) { - rrc_nr.cell_select_completed(result); + cfg_task_queue.push([this, result]() { rrc_nr.cell_select_completed(result); }); } } // namespace srsue diff --git a/srsue/src/stack/ue_stack_nr.cc b/srsue/src/stack/ue_stack_nr.cc index 695060cce..33695810b 100644 --- a/srsue/src/stack/ue_stack_nr.cc +++ b/srsue/src/stack/ue_stack_nr.cc @@ -202,6 +202,11 @@ void ue_stack_nr::set_phy_config_complete(bool status) sync_task_queue.push([this, status]() { rrc->set_phy_config_complete(status); }); } +void ue_stack_nr::cell_search_found_cell(const cell_search_result_t& result) +{ + sync_task_queue.push([this, result]() { rrc->cell_search_found_cell(result); }); +} + void ue_stack_nr::cell_select_completed(const rrc_interface_phy_nr::cell_select_result_t& result) { sync_task_queue.push([this, result]() { rrc->cell_select_completed(result); });