srsLTE/srsue/hdr/stack/rrc/rrc_procedures.h

351 lines
11 KiB
C
Raw Normal View History

/**
*
* \section COPYRIGHT
*
* Copyright 2013-2020 Software Radio Systems Limited
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
*
*/
#include "phy_controller.h"
#include "srslte/common/log.h"
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
#include "srslte/srslog/srslog.h"
#include "srsue/hdr/stack/rrc/rrc.h"
#include <map>
#include <string>
#ifndef SRSLTE_RRC_PROCEDURES_H
#define SRSLTE_RRC_PROCEDURES_H
namespace srsue {
/********************************
* Procedures
*******************************/
class rrc::cell_search_proc
{
public:
enum class state_t { phy_cell_search, si_acquire, wait_measurement, phy_cell_select };
explicit cell_search_proc(rrc* parent_);
srslte::proc_outcome_t init();
srslte::proc_outcome_t step();
srslte::proc_outcome_t step_si_acquire();
srslte::proc_outcome_t react(const phy_controller::cell_srch_res& event);
2020-07-08 04:36:55 -07:00
srslte::proc_outcome_t react(const bool& event);
srslte::proc_outcome_t step_wait_measurement();
rrc_interface_phy_lte::cell_search_ret_t get_result() const { return search_result.cs_ret; }
static const char* name() { return "Cell Search"; }
private:
srslte::proc_outcome_t handle_cell_found(const phy_cell_t& new_cell);
// conts
rrc* rrc_ptr;
// state vars
phy_controller::cell_srch_res search_result;
srslte::proc_future_t<void> si_acquire_fut;
state_t state;
};
/****************************************************************
* TS 36.331 Sec 5.2.3 - Acquisition of an SI message procedure
***************************************************************/
class rrc::si_acquire_proc
{
public:
const static int SIB_SEARCH_TIMEOUT_MS = 1000;
struct si_acq_timer_expired {
uint32_t timer_id;
};
struct sib_received_ev {};
explicit si_acquire_proc(rrc* parent_);
srslte::proc_outcome_t init(uint32_t sib_index_);
srslte::proc_outcome_t step() { return srslte::proc_outcome_t::yield; }
static const char* name() { return "SI Acquire"; }
srslte::proc_outcome_t react(si_acq_timer_expired ev);
srslte::proc_outcome_t react(sib_received_ev ev);
void then(const srslte::proc_state_t& result);
private:
void start_si_acquire();
// conts
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
rrc* rrc_ptr;
srslog::basic_logger& logger;
// state
srslte::timer_handler::unique_timer si_acq_timeout, si_acq_retry_timer;
uint32_t period = 0, sched_index = 0;
uint32_t sib_index = 0;
};
class rrc::serving_cell_config_proc
{
public:
explicit serving_cell_config_proc(rrc* parent_);
srslte::proc_outcome_t init(const std::vector<uint32_t>& required_sibs_);
srslte::proc_outcome_t step();
static const char* name() { return "Serving Cell Configuration"; }
private:
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
rrc* rrc_ptr;
srslog::basic_logger& logger;
srslte::proc_outcome_t launch_sib_acquire();
// proc args
std::vector<uint32_t> required_sibs;
// state variables
uint32_t req_idx = 0;
srslte::proc_future_t<void> si_acquire_fut;
};
class rrc::cell_selection_proc
{
public:
using cell_selection_complete_ev = srslte::proc_result_t<cs_result_t>;
explicit cell_selection_proc(rrc* parent_);
srslte::proc_outcome_t init(std::vector<uint32_t> required_sibs_ = {});
srslte::proc_outcome_t step();
cs_result_t get_result() const { return cs_result; }
static const char* name() { return "Cell Selection"; }
2020-07-08 04:36:55 -07:00
srslte::proc_outcome_t react(const bool& event);
void then(const srslte::proc_result_t<cs_result_t>& proc_result) const;
private:
srslte::proc_outcome_t start_next_cell_selection();
srslte::proc_outcome_t step_cell_search();
srslte::proc_outcome_t step_cell_config();
bool is_serv_cell_suitable() const;
bool is_sib_acq_required() const;
srslte::proc_outcome_t set_proc_complete();
srslte::proc_outcome_t start_phy_cell_selection(const meas_cell_eutra& cell);
srslte::proc_outcome_t start_sib_acquisition();
// consts
rrc* rrc_ptr;
meas_cell_list<meas_cell_eutra>* meas_cells;
// state variables
enum class search_state_t { cell_selection, serv_cell_camp, cell_config, cell_search };
cs_result_t cs_result;
search_state_t state;
uint32_t neigh_index;
bool serv_cell_select_attempted = false;
srslte::proc_future_t<rrc_interface_phy_lte::cell_search_ret_t> cell_search_fut;
srslte::proc_future_t<void> serv_cell_cfg_fut;
bool discard_serving = false, cell_search_called = false;
std::vector<uint32_t> required_sibs = {};
phy_cell_t init_serv_cell;
};
class rrc::plmn_search_proc
{
public:
explicit plmn_search_proc(rrc* parent_);
srslte::proc_outcome_t init();
srslte::proc_outcome_t step();
void then(const srslte::proc_state_t& result) const;
static const char* name() { return "PLMN Search"; }
private:
// consts
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
rrc* rrc_ptr;
srslog::basic_logger& logger;
// state variables
found_plmn_t found_plmns[MAX_FOUND_PLMNS];
int nof_plmns = 0;
srslte::proc_future_t<rrc_interface_phy_lte::cell_search_ret_t> cell_search_fut;
};
class rrc::connection_request_proc
{
public:
explicit connection_request_proc(rrc* parent_);
srslte::proc_outcome_t init(srslte::establishment_cause_t cause_, srslte::unique_byte_buffer_t dedicated_info_nas_);
srslte::proc_outcome_t step();
void then(const srslte::proc_state_t& result);
srslte::proc_outcome_t react(const cell_selection_proc::cell_selection_complete_ev& e);
static const char* name() { return "Connection Request"; }
private:
// const
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
rrc* rrc_ptr;
srslog::basic_logger& logger;
// args
srslte::establishment_cause_t cause;
srslte::unique_byte_buffer_t dedicated_info_nas;
// state variables
enum class state_t { cell_selection, config_serving_cell, wait_t300 } state;
cs_result_t cs_ret;
srslte::proc_future_t<void> serv_cfg_fut;
};
class rrc::connection_reconf_no_ho_proc
{
public:
explicit connection_reconf_no_ho_proc(rrc* parent_);
srslte::proc_outcome_t init(const asn1::rrc::rrc_conn_recfg_s& recfg_);
srslte::proc_outcome_t step() { return srslte::proc_outcome_t::yield; }
static const char* name() { return "Connection Reconfiguration"; }
srslte::proc_outcome_t react(const bool& config_complete);
void then(const srslte::proc_state_t& result);
private:
// const
rrc* rrc_ptr;
// args
bool has_5g_nr_reconfig = false;
asn1::rrc::rrc_conn_recfg_r8_ies_s rx_recfg;
};
class rrc::process_pcch_proc
{
public:
struct paging_complete {
bool outcome;
};
explicit process_pcch_proc(rrc* parent_);
srslte::proc_outcome_t init(const asn1::rrc::paging_s& paging_);
srslte::proc_outcome_t step();
srslte::proc_outcome_t react(paging_complete e);
static const char* name() { return "Process PCCH"; }
private:
// args
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
rrc* rrc_ptr;
srslog::basic_logger& logger;
asn1::rrc::paging_s paging;
// vars
uint32_t paging_idx = 0;
enum class state_t { next_record, nas_paging, serv_cell_cfg } state;
srslte::proc_future_t<void> serv_cfg_fut;
};
class rrc::go_idle_proc
{
public:
explicit go_idle_proc(rrc* rrc_);
srslte::proc_outcome_t init();
srslte::proc_outcome_t step();
srslte::proc_outcome_t react(bool timeout);
static const char* name() { return "Go Idle"; }
void then(const srslte::proc_state_t& result);
private:
static const uint32_t rlc_flush_timeout_ms = 60; // TS 36.331 Sec 5.3.8.3
rrc* rrc_ptr;
srslte::timer_handler::unique_timer rlc_flush_timer;
};
class rrc::cell_reselection_proc
{
public:
/// Timer duration to restart Cell Reselection Procedure
const static uint32_t cell_reselection_periodicity_ms = 20, cell_reselection_periodicity_long_ms = 1000;
cell_reselection_proc(rrc* rrc_);
srslte::proc_outcome_t init();
srslte::proc_outcome_t step();
static const char* name() { return "Cell Reselection"; }
void then(const srslte::proc_state_t& result);
private:
rrc* rrc_ptr;
srslte::timer_handler::unique_timer reselection_timer;
srslte::proc_future_t<cs_result_t> cell_selection_fut;
cs_result_t cell_sel_result = cs_result_t::no_cell;
};
class rrc::connection_reest_proc
{
public:
struct t311_expiry {};
struct serv_cell_cfg_completed {};
struct t301_expiry {};
explicit connection_reest_proc(rrc* rrc_);
// 5.3.7.2 - Initiation
srslte::proc_outcome_t init(asn1::rrc::reest_cause_e cause);
// 5.3.7.3 Actions following cell selection while T311 is running
// && 5.3.7.4 - Actions related to transmission of RRCConnectionReestablishmentRequest message
srslte::proc_outcome_t react(const cell_selection_proc::cell_selection_complete_ev& e);
// 5.3.7.5 - Reception of the RRCConnectionReestablishment by the UE
srslte::proc_outcome_t react(const asn1::rrc::rrc_conn_reest_s& reest_msg);
// 5.3.7.6 - T311 expiry
srslte::proc_outcome_t react(const t311_expiry& ev);
// 5.3.7.7 - T301 expiry or selected cell no longer suitable
srslte::proc_outcome_t react(const t301_expiry& ev);
// detects if cell is no longer suitable (part of 5.3.7.7)
srslte::proc_outcome_t step();
// 5.3.7.8 - Reception of RRCConnectionReestablishmentReject by the UE
srslte::proc_outcome_t react(const asn1::rrc::rrc_conn_reest_reject_s& reest_msg);
static const char* name() { return "Connection re-establishment"; }
uint32_t get_source_earfcn() const { return reest_source_freq; }
private:
enum class state_t { wait_cell_selection, wait_reest_msg } state;
rrc* rrc_ptr = nullptr;
asn1::rrc::reest_cause_e reest_cause = asn1::rrc::reest_cause_e::nulltype;
uint16_t reest_rnti = 0, reest_source_pci = 0;
uint32_t reest_source_freq = 0, reest_cellid = 0;
bool passes_cell_criteria() const;
2019-11-22 08:15:02 -08:00
srslte::proc_outcome_t cell_criteria();
srslte::proc_outcome_t start_cell_selection();
};
class rrc::ho_proc
{
public:
struct t304_expiry {};
struct ra_completed_ev {
bool success;
};
explicit ho_proc(rrc* rrc_);
srslte::proc_outcome_t init(const asn1::rrc::rrc_conn_recfg_s& rrc_reconf);
2020-07-08 04:36:55 -07:00
srslte::proc_outcome_t react(const bool& ev);
srslte::proc_outcome_t react(t304_expiry ev);
srslte::proc_outcome_t react(ra_completed_ev ev);
srslte::proc_outcome_t step() { return srslte::proc_outcome_t::yield; }
void then(const srslte::proc_state_t& result);
static const char* name() { return "Handover"; }
phy_cell_t ho_src_cell;
uint16_t ho_src_rnti = 0;
private:
rrc* rrc_ptr = nullptr;
// args
asn1::rrc::rrc_conn_recfg_r8_ies_s recfg_r8;
// state
phy_cell_t target_cell;
// helper to revert security config of source cell
void reset_security_config();
};
} // namespace srsue
#endif // SRSLTE_RRC_PROCEDURES_H