diff --git a/lib/include/srslte/common/interfaces_common.h b/lib/include/srslte/common/interfaces_common.h index b4e45f96b..5a88563de 100644 --- a/lib/include/srslte/common/interfaces_common.h +++ b/lib/include/srslte/common/interfaces_common.h @@ -60,7 +60,7 @@ typedef struct { class srslte_gw_config_t { public: - srslte_gw_config_t(uint32_t lcid_ = 0) : lcid(lcid_) {} + explicit srslte_gw_config_t(uint32_t lcid_ = 0) : lcid(lcid_) {} uint32_t lcid; }; diff --git a/lib/include/srslte/common/log.h b/lib/include/srslte/common/log.h index 0230a350a..9cdb4e130 100644 --- a/lib/include/srslte/common/log.h +++ b/lib/include/srslte/common/log.h @@ -44,62 +44,53 @@ typedef enum { LOG_LEVEL_DEBUG, LOG_LEVEL_N_ITEMS } LOG_LEVEL_ENUM; -static const char log_level_text[LOG_LEVEL_N_ITEMS][16] = {"None ", - "Error ", - "Warning", - "Info ", - "Debug "}; - -static const char log_level_text_short[LOG_LEVEL_N_ITEMS][16] = {"[-]", - "[E]", - "[W]", - "[I]", - "[D]"}; +static const char log_level_text[LOG_LEVEL_N_ITEMS][16] = {"None ", "Error ", "Warning", "Info ", "Debug "}; + +static const char log_level_text_short[LOG_LEVEL_N_ITEMS][16] = {"[-]", "[E]", "[W]", "[I]", "[D]"}; class log { public: - - log() { - service_name = ""; - tti = 0; - level = LOG_LEVEL_NONE; - hex_limit = 0; + log() + { + service_name = ""; + tti = 0; + level = LOG_LEVEL_NONE; + hex_limit = 0; add_string_en = false; } - log(std::string service_name_) { - service_name = service_name_; - tti = 0; - level = LOG_LEVEL_NONE; - hex_limit = 0; + explicit log(std::string service_name_) + { + service_name = std::move(service_name_); + tti = 0; + level = LOG_LEVEL_NONE; + hex_limit = 0; add_string_en = false; } - virtual ~log() {}; + virtual ~log() = default; // This function shall be called at the start of every tti for printing tti - void step(uint32_t tti_) { - tti = tti_; - add_string_en = false; + void step(uint32_t tti_) + { + tti = tti_; + add_string_en = false; } - void prepend_string(std::string s) { + void prepend_string(std::string s) + { add_string_en = true; - add_string_val = s; + add_string_val = std::move(s); } - uint32_t get_tti() { - return tti; - } + uint32_t get_tti() { return tti; } - void set_level(LOG_LEVEL_ENUM l) { - level = l; - } + void set_level(LOG_LEVEL_ENUM l) { level = l; } - void set_level(std::string l) { set_level(get_level_from_string(l)); } + void set_level(std::string l) { set_level(get_level_from_string(std::move(l))); } - srslte::LOG_LEVEL_ENUM get_level_from_string(std::string l) + static srslte::LOG_LEVEL_ENUM get_level_from_string(std::string l) { std::transform(l.begin(), l.end(), l.begin(), ::toupper); if ("NONE" == l) { @@ -117,42 +108,44 @@ public: } } - LOG_LEVEL_ENUM get_level() { - return level; - } + LOG_LEVEL_ENUM get_level() { return level; } - void set_hex_limit(int limit) { - hex_limit = limit; - } - int get_hex_limit() { - return hex_limit; - } + void set_hex_limit(int limit) { hex_limit = limit; } + int get_hex_limit() { return hex_limit; } // Pure virtual methods for logging - virtual void console(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; - virtual void error(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; - virtual void warning(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; - virtual void info(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; + virtual void console(const char* message, ...) __attribute__((format(printf, 2, 3))) = 0; + virtual void error(const char* message, ...) __attribute__((format(printf, 2, 3))) = 0; + virtual void warning(const char* message, ...) __attribute__((format(printf, 2, 3))) = 0; + virtual void info(const char* message, ...) __attribute__((format(printf, 2, 3))) = 0; virtual void info_long(const char* message, ...) __attribute__((format(printf, 2, 3))) = 0; - virtual void debug(const char * message, ...) __attribute__ ((format (printf, 2, 3))) = 0; + virtual void debug(const char* message, ...) __attribute__((format(printf, 2, 3))) = 0; virtual void debug_long(const char* message, ...) __attribute__((format(printf, 2, 3))) = 0; // Same with hex dump - virtual void error_hex(const uint8_t *, int, const char *, ...) __attribute__((format (printf, 4, 5))) - {error("error_hex not implemented.\n");} - virtual void warning_hex(const uint8_t *, int, const char *, ...) __attribute__((format (printf, 4, 5))) - {error("warning_hex not implemented.\n");} - virtual void info_hex(const uint8_t *, int, const char *, ...) __attribute__((format (printf, 4, 5))) - {error("info_hex not implemented.\n");} - virtual void debug_hex(const uint8_t *, int, const char *, ...) __attribute__((format (printf, 4, 5))) - {error("debug_hex not implemented.\n");} + virtual void error_hex(const uint8_t*, int, const char*, ...) __attribute__((format(printf, 4, 5))) + { + error("error_hex not implemented.\n"); + } + virtual void warning_hex(const uint8_t*, int, const char*, ...) __attribute__((format(printf, 4, 5))) + { + error("warning_hex not implemented.\n"); + } + virtual void info_hex(const uint8_t*, int, const char*, ...) __attribute__((format(printf, 4, 5))) + { + error("info_hex not implemented.\n"); + } + virtual void debug_hex(const uint8_t*, int, const char*, ...) __attribute__((format(printf, 4, 5))) + { + error("debug_hex not implemented.\n"); + } protected: - std::string get_service_name() { return service_name; } - uint32_t tti; - LOG_LEVEL_ENUM level; - int hex_limit; - std::string service_name; + std::string get_service_name() { return service_name; } + uint32_t tti; + LOG_LEVEL_ENUM level; + int hex_limit; + std::string service_name; bool add_string_en; std::string add_string_val; @@ -161,4 +154,3 @@ protected: } // namespace srslte #endif // SRSLTE_LOG_H - diff --git a/lib/include/srslte/interfaces/sched_interface.h b/lib/include/srslte/interfaces/sched_interface.h index 5db6711c8..21d4ab92e 100644 --- a/lib/include/srslte/interfaces/sched_interface.h +++ b/lib/include/srslte/interfaces/sched_interface.h @@ -34,75 +34,72 @@ public: const static uint32_t max_prb = 100; const static uint32_t max_rbg = 25; - const static int MAX_SIB_PAYLOAD_LEN = 2048; + const static int MAX_SIB_PAYLOAD_LEN = 2048; const static int MAX_SIBS = 16; - const static int MAX_LC = 6; + const static int MAX_LC = 6; const static int MAX_DATA_LIST = 32; const static int MAX_RAR_LIST = 8; const static int MAX_BC_LIST = 8; const static int MAX_RLC_PDU_LIST = 8; - const static int MAX_PHICH_LIST = 8; - + const static int MAX_PHICH_LIST = 8; + typedef struct { - uint32_t len; - uint32_t period_rf; + uint32_t len; + uint32_t period_rf; } cell_cfg_sib_t; - - + typedef struct { - int pdsch_mcs; - int pdsch_max_mcs; - int pusch_mcs; - int pusch_max_mcs; + int pdsch_mcs; + int pdsch_max_mcs; + int pusch_mcs; + int pusch_max_mcs; int nof_ctrl_symbols; int max_aggr_level; - } sched_args_t; + } sched_args_t; - typedef struct { - + // Main cell configuration (used to calculate DCI locations in scheduler) srslte_cell_t cell; - + /* SIB configuration */ - cell_cfg_sib_t sibs[MAX_SIBS]; - uint32_t si_window_ms; - + cell_cfg_sib_t sibs[MAX_SIBS]; + uint32_t si_window_ms; + /* pusch configuration */ - srslte_pusch_hopping_cfg_t pusch_hopping_cfg; - + srslte_pusch_hopping_cfg_t pusch_hopping_cfg; + /* prach configuration */ uint32_t prach_config; uint32_t prach_nof_preambles; - uint32_t prach_freq_offset; + uint32_t prach_freq_offset; uint32_t prach_rar_window; - uint32_t prach_contention_resolution_timer; - + uint32_t prach_contention_resolution_timer; + uint32_t maxharq_msg3tx; uint32_t n1pucch_an; - uint32_t delta_pucch_shift; + uint32_t delta_pucch_shift; // If non-negative, statically allocate N prbs at the edges of the uplink for PUCCH - int nrb_pucch; + int nrb_pucch; - uint32_t nrb_cqi; + uint32_t nrb_cqi; uint32_t ncs_an; - + uint32_t srs_subframe_config; - uint32_t srs_subframe_offset; - uint32_t srs_bw_config; - - } cell_cfg_t; - - + uint32_t srs_subframe_offset; + uint32_t srs_bw_config; + + } cell_cfg_t; + typedef struct { - int priority; - int bsd; + int priority; + int bsd; int pbr; int group; - enum {IDLE = 0, UL, DL, BOTH} direction; - } ue_bearer_cfg_t; - + enum { IDLE = 0, UL, DL, BOTH } direction; + } ue_bearer_cfg_t; + typedef struct { /* ue capabilities, etc */ @@ -113,43 +110,42 @@ public: srslte_uci_offset_cfg_t uci_offset; srslte_pucch_cfg_t pucch_cfg; - uint32_t aperiodic_cqi_period; // if 0 is periodic CQI + uint32_t aperiodic_cqi_period; // if 0 is periodic CQI srslte_dl_cfg_t dl_cfg; - ue_bearer_cfg_t ue_bearers[MAX_LC]; - - } ue_cfg_t; - + ue_bearer_cfg_t ue_bearers[MAX_LC]; + + } ue_cfg_t; + typedef struct { - uint32_t lcid; + uint32_t lcid; uint32_t nbytes; - } dl_sched_pdu_t; - - + } dl_sched_pdu_t; + typedef struct { uint32_t lcid; uint32_t lcid_buffer_size; uint32_t stop; uint8_t* mtch_payload; } dl_mtch_sched_t; - + typedef struct { - dl_sched_pdu_t pdu[20]; + dl_sched_pdu_t pdu[20]; dl_mtch_sched_t mtch_sched[8]; - uint32_t num_mtch_sched; - uint8_t *mcch_payload; - uint32_t current_sf_allocation_num; - } dl_pdu_mch_t; - + uint32_t num_mtch_sched; + uint8_t* mcch_payload; + uint32_t current_sf_allocation_num; + } dl_pdu_mch_t; + typedef struct { - srslte_dci_dl_t dci; - uint32_t tbs[SRSLTE_MAX_TB]; - bool mac_ce_ta; - bool mac_ce_rnti; - uint32_t nof_pdu_elems[SRSLTE_MAX_TB]; - dl_sched_pdu_t pdu[SRSLTE_MAX_TB][MAX_RLC_PDU_LIST]; + srslte_dci_dl_t dci; + uint32_t tbs[SRSLTE_MAX_TB]; + bool mac_ce_ta; + bool mac_ce_rnti; + uint32_t nof_pdu_elems[SRSLTE_MAX_TB]; + dl_sched_pdu_t pdu[SRSLTE_MAX_TB][MAX_RLC_PDU_LIST]; } dl_sched_data_t; - + typedef struct { bool needs_pdcch; uint32_t current_tx_nb; @@ -167,99 +163,95 @@ public: typedef struct { dl_sched_rar_info_t data; - srslte_dci_rar_grant_t grant; + srslte_dci_rar_grant_t grant; } dl_sched_rar_grant_t; - + typedef struct { uint32_t tbs; srslte_dci_dl_t dci; uint32_t nof_grants; dl_sched_rar_grant_t msg3_grant[MAX_RAR_LIST]; - } dl_sched_rar_t; + } dl_sched_rar_t; typedef struct { srslte_dci_dl_t dci; - enum bc_type { - BCCH, PCCH - } type; - + enum bc_type { BCCH, PCCH } type; + uint32_t index; - - uint32_t tbs; - - } dl_sched_bc_t; - + + uint32_t tbs; + + } dl_sched_bc_t; + typedef struct { - uint32_t cfi; - uint32_t nof_data_elems; - uint32_t nof_rar_elems; - uint32_t nof_bc_elems; + uint32_t cfi; + uint32_t nof_data_elems; + uint32_t nof_rar_elems; + uint32_t nof_bc_elems; dl_sched_data_t data[MAX_DATA_LIST]; dl_sched_rar_t rar[MAX_RAR_LIST]; dl_sched_bc_t bc[MAX_BC_LIST]; - } dl_sched_res_t; - + } dl_sched_res_t; + typedef struct { - uint16_t rnti; - enum phich_elem { - ACK, NACK - } phich; + uint16_t rnti; + enum phich_elem { ACK, NACK } phich; } ul_sched_phich_t; typedef struct { - uint32_t nof_dci_elems; - uint32_t nof_phich_elems; + uint32_t nof_dci_elems; + uint32_t nof_phich_elems; ul_sched_data_t pusch[MAX_DATA_LIST]; ul_sched_phich_t phich[MAX_PHICH_LIST]; - } ul_sched_res_t; - + } ul_sched_res_t; + /******************* Scheduler Control ****************************/ /* Provides cell configuration including SIB periodicity, etc. */ - virtual int cell_cfg(cell_cfg_t *cell_cfg) = 0; - virtual int reset() = 0; + virtual int cell_cfg(cell_cfg_t* cell_cfg) = 0; + virtual int reset() = 0; /* Manages UE scheduling context */ - virtual int ue_cfg(uint16_t rnti, ue_cfg_t *cfg) = 0; - virtual int ue_rem(uint16_t rnti) = 0; - virtual bool ue_exists(uint16_t rnti) = 0; + virtual int ue_cfg(uint16_t rnti, ue_cfg_t* cfg) = 0; + virtual int ue_rem(uint16_t rnti) = 0; + virtual bool ue_exists(uint16_t rnti) = 0; /* Manages UE bearers and associated configuration */ - virtual int bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, ue_bearer_cfg_t *cfg) = 0; - virtual int bearer_ue_rem(uint16_t rnti, uint32_t lc_id) = 0; - - virtual uint32_t get_ul_buffer(uint16_t rnti) = 0; - virtual uint32_t get_dl_buffer(uint16_t rnti) = 0; + virtual int bearer_ue_cfg(uint16_t rnti, uint32_t lc_id, ue_bearer_cfg_t* cfg) = 0; + virtual int bearer_ue_rem(uint16_t rnti, uint32_t lc_id) = 0; + + virtual uint32_t get_ul_buffer(uint16_t rnti) = 0; + virtual uint32_t get_dl_buffer(uint16_t rnti) = 0; /******************* Scheduling Interface ***********************/ /* DL buffer status report */ - virtual int dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue) = 0; - virtual int dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code) = 0; - + virtual int dl_rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue) = 0; + virtual int dl_mac_buffer_state(uint16_t rnti, uint32_t ce_code) = 0; + /* DL information */ virtual int dl_ack_info(uint32_t tti, uint16_t rnti, uint32_t tb_idx, bool ack) = 0; - virtual int dl_rach_info(dl_sched_rar_info_t rar_info) = 0; - virtual int dl_ri_info(uint32_t tti, uint16_t rnti, uint32_t ri_value) = 0; - virtual int dl_pmi_info(uint32_t tti, uint16_t rnti, uint32_t pmi_value) = 0; - virtual int dl_cqi_info(uint32_t tti, uint16_t rnti, uint32_t cqi_value) = 0; - + virtual int dl_rach_info(dl_sched_rar_info_t rar_info) = 0; + virtual int dl_ri_info(uint32_t tti, uint16_t rnti, uint32_t ri_value) = 0; + virtual int dl_pmi_info(uint32_t tti, uint16_t rnti, uint32_t pmi_value) = 0; + virtual int dl_cqi_info(uint32_t tti, uint16_t rnti, uint32_t cqi_value) = 0; + /* UL information */ - virtual int ul_crc_info(uint32_t tti, uint16_t rnti, bool crc) = 0; - virtual int ul_sr_info(uint32_t tti, uint16_t rnti) = 0; - virtual int ul_bsr(uint16_t rnti, uint32_t lcid, uint32_t bsr, bool set_value = true) = 0; - virtual int ul_recv_len(uint16_t rnti, uint32_t lcid, uint32_t len) = 0; - virtual int ul_phr(uint16_t rnti, int phr) = 0; - virtual int ul_cqi_info(uint32_t tti, uint16_t rnti, uint32_t cqi, uint32_t ul_ch_code) = 0; - + virtual int ul_crc_info(uint32_t tti, uint16_t rnti, bool crc) = 0; + virtual int ul_sr_info(uint32_t tti, uint16_t rnti) = 0; + virtual int ul_bsr(uint16_t rnti, uint32_t lcid, uint32_t bsr, bool set_value = true) = 0; + virtual int ul_recv_len(uint16_t rnti, uint32_t lcid, uint32_t len) = 0; + virtual int ul_phr(uint16_t rnti, int phr) = 0; + virtual int ul_cqi_info(uint32_t tti, uint16_t rnti, uint32_t cqi, uint32_t ul_ch_code) = 0; + /* Run Scheduler for this tti */ - virtual int dl_sched(uint32_t tti, dl_sched_res_t *sched_result) = 0; - virtual int ul_sched(uint32_t tti, ul_sched_res_t *sched_result) = 0; + virtual int dl_sched(uint32_t tti, dl_sched_res_t* sched_result) = 0; + virtual int ul_sched(uint32_t tti, ul_sched_res_t* sched_result) = 0; /* Custom */ virtual void set_dl_tti_mask(uint8_t* tti_mask, uint32_t nof_sfs) = 0; }; -} +} // namespace srsenb #endif // SRSLTE_SCHED_INTERFACE_H diff --git a/srsenb/hdr/stack/mac/scheduler.h b/srsenb/hdr/stack/mac/scheduler.h index c25edd1de..f1f9a5bd2 100644 --- a/srsenb/hdr/stack/mac/scheduler.h +++ b/srsenb/hdr/stack/mac/scheduler.h @@ -30,8 +30,8 @@ #include "srslte/interfaces/sched_interface.h" #include #include -#include #include +#include namespace srsenb { @@ -142,8 +142,11 @@ public: const static int rv_idx[4] = {0, 2, 3, 1}; return rv_idx[retx_idx % 4]; } - static void generate_cce_location( - srslte_regs_t* regs, sched_ue::sched_dci_cce_t* location, uint32_t cfi, uint32_t sf_idx = 0, uint16_t rnti = 0); + static void generate_cce_location(srslte_regs_t* regs, + sched_ue::sched_dci_cce_t* location, + uint32_t cfi, + uint32_t sf_idx = 0, + uint16_t rnti = 0); static uint32_t aggr_level(uint32_t aggr_idx) { return 1u << aggr_idx; } class carrier_sched; diff --git a/srsenb/hdr/stack/mac/scheduler_carrier.h b/srsenb/hdr/stack/mac/scheduler_carrier.h index 651c2064e..a8404c1e5 100644 --- a/srsenb/hdr/stack/mac/scheduler_carrier.h +++ b/srsenb/hdr/stack/mac/scheduler_carrier.h @@ -115,12 +115,16 @@ public: ul_harq_proc::ul_alloc_t alloc, tti_sched_result_t::ul_alloc_t::type_t alloc_type, uint32_t msg3 = 0); - int generate_format1a( - uint32_t rb_start, uint32_t l_crb, uint32_t tbs, uint32_t rv, uint16_t rnti, srslte_dci_dl_t* dci); - void set_bc_sched_result(const pdcch_grid_t::alloc_result_t& dci_result); - void set_rar_sched_result(const pdcch_grid_t::alloc_result_t& dci_result); - void set_dl_data_sched_result(const pdcch_grid_t::alloc_result_t& dci_result); - void set_ul_sched_result(const pdcch_grid_t::alloc_result_t& dci_result); + int generate_format1a(uint32_t rb_start, + uint32_t l_crb, + uint32_t tbs, + uint32_t rv, + uint16_t rnti, + srslte_dci_dl_t* dci); + void set_bc_sched_result(const pdcch_grid_t::alloc_result_t& dci_result); + void set_rar_sched_result(const pdcch_grid_t::alloc_result_t& dci_result); + void set_dl_data_sched_result(const pdcch_grid_t::alloc_result_t& dci_result); + void set_ul_sched_result(const pdcch_grid_t::alloc_result_t& dci_result); // consts carrier_sched* parent_carrier = nullptr; @@ -210,8 +214,8 @@ private: class ra_sched { public: - using dl_sched_rar_info_t = sched_interface::dl_sched_rar_info_t; - using dl_sched_rar_t = sched_interface::dl_sched_rar_t; + using dl_sched_rar_info_t = sched_interface::dl_sched_rar_info_t; + using dl_sched_rar_t = sched_interface::dl_sched_rar_t; using dl_sched_rar_grant_t = sched_interface::dl_sched_rar_grant_t; struct pending_msg3_t { bool enabled = false; @@ -230,22 +234,15 @@ public: const pending_msg3_t& find_pending_msg3(uint32_t tti); private: - struct sched_rar_t { - int buf_rar = 0; - uint16_t rnti = 0; - uint32_t ra_id = 0; - uint32_t rar_tti = 0; - }; - // args srslte::log* log_h = nullptr; sched::cell_cfg_t* cfg; std::map* ue_db = nullptr; - std::queue pending_rars; - std::array pending_msg3; - uint32_t tti_tx_dl = 0; - uint32_t rar_aggr_level = 2; + std::queue pending_rars; + std::array pending_msg3; + uint32_t tti_tx_dl = 0; + uint32_t rar_aggr_level = 2; }; } // namespace srsenb diff --git a/srsenb/hdr/stack/mac/scheduler_harq.h b/srsenb/hdr/stack/mac/scheduler_harq.h index c142f4681..9732314ec 100644 --- a/srsenb/hdr/stack/mac/scheduler_harq.h +++ b/srsenb/hdr/stack/mac/scheduler_harq.h @@ -43,7 +43,9 @@ struct rbg_range_t { }; // Range of PRBs -struct prb_range_t { +class prb_range_t +{ +public: uint32_t prb_start = 0, prb_end = 0; prb_range_t() = default; prb_range_t(uint32_t s, uint32_t e) : prb_start(s), prb_end(e) {} diff --git a/srsenb/hdr/stack/mac/scheduler_ue.h b/srsenb/hdr/stack/mac/scheduler_ue.h index 047a7cabd..86cb5339a 100644 --- a/srsenb/hdr/stack/mac/scheduler_ue.h +++ b/srsenb/hdr/stack/mac/scheduler_ue.h @@ -42,7 +42,7 @@ class sched_ue public: // used by sched_metric to store the pdsch/pusch allocations - bool has_pucch; + bool has_pucch = false; typedef struct { uint32_t cce_start[4][6]; @@ -119,14 +119,23 @@ public: void set_sr(); void unset_sr(); - void set_needs_ta_cmd(uint32_t nof_ta_cmd); + void set_needs_ta_cmd(uint32_t nof_ta_cmd); - int generate_format1( - dl_harq_proc* h, sched_interface::dl_sched_data_t* data, uint32_t tti, uint32_t cfi, const rbgmask_t& user_mask); - int generate_format2a( - dl_harq_proc* h, sched_interface::dl_sched_data_t* data, uint32_t tti, uint32_t cfi, const rbgmask_t& user_mask); - int generate_format2( - dl_harq_proc* h, sched_interface::dl_sched_data_t* data, uint32_t tti, uint32_t cfi, const rbgmask_t& user_mask); + int generate_format1(dl_harq_proc* h, + sched_interface::dl_sched_data_t* data, + uint32_t tti, + uint32_t cfi, + const rbgmask_t& user_mask); + int generate_format2a(dl_harq_proc* h, + sched_interface::dl_sched_data_t* data, + uint32_t tti, + uint32_t cfi, + const rbgmask_t& user_mask); + int generate_format2(dl_harq_proc* h, + sched_interface::dl_sched_data_t* data, + uint32_t tti, + uint32_t cfi, + const rbgmask_t& user_mask); int generate_format0(sched_interface::ul_sched_data_t* data, uint32_t tti, ul_harq_proc::ul_alloc_t alloc, @@ -156,11 +165,16 @@ private: int alloc_pdu(int tbs, sched_interface::dl_sched_pdu_t* pdu); static uint32_t format1_count_prb(uint32_t bitmask, uint32_t cell_nof_prb); - static int cqi_to_tbs( - uint32_t cqi, uint32_t nof_prb, uint32_t nof_re, uint32_t max_mcs, uint32_t max_Qm, bool is_ul, uint32_t* mcs); - int alloc_tbs_dl(uint32_t nof_prb, uint32_t nof_re, uint32_t req_bytes, int* mcs); - int alloc_tbs_ul(uint32_t nof_prb, uint32_t nof_re, uint32_t req_bytes, int* mcs); - int alloc_tbs(uint32_t nof_prb, uint32_t nof_re, uint32_t req_bytes, bool is_ul, int* mcs); + static int cqi_to_tbs(uint32_t cqi, + uint32_t nof_prb, + uint32_t nof_re, + uint32_t max_mcs, + uint32_t max_Qm, + bool is_ul, + uint32_t* mcs); + int alloc_tbs_dl(uint32_t nof_prb, uint32_t nof_re, uint32_t req_bytes, int* mcs); + int alloc_tbs_ul(uint32_t nof_prb, uint32_t nof_re, uint32_t req_bytes, int* mcs); + int alloc_tbs(uint32_t nof_prb, uint32_t nof_re, uint32_t req_bytes, bool is_ul, int* mcs); static bool bearer_is_ul(ue_bearer_t* lch); static bool bearer_is_dl(ue_bearer_t* lch); @@ -172,55 +186,58 @@ private: bool needs_cqi_unlocked(uint32_t tti, bool will_send = false); - int generate_format2a_unlocked( - dl_harq_proc* h, sched_interface::dl_sched_data_t* data, uint32_t tti, uint32_t cfi, const rbgmask_t& user_mask); + int generate_format2a_unlocked(dl_harq_proc* h, + sched_interface::dl_sched_data_t* data, + uint32_t tti, + uint32_t cfi, + const rbgmask_t& user_mask); bool is_first_dl_tx(); - sched_interface::ue_cfg_t cfg; - srslte_cell_t cell; - srslte::log* log_h; + sched_interface::ue_cfg_t cfg = {}; + srslte_cell_t cell = {}; + srslte::log* log_h = nullptr; std::mutex mutex; /* Buffer states */ - bool sr; - int buf_mac; - int buf_ul; - ue_bearer_t lch[sched_interface::MAX_LC]; - - int power_headroom; - uint32_t dl_ri; - uint32_t dl_ri_tti; - uint32_t dl_pmi; - uint32_t dl_pmi_tti; - uint32_t dl_cqi; - uint32_t dl_cqi_tti; - uint32_t cqi_request_tti; - uint32_t ul_cqi; - uint32_t ul_cqi_tti; - uint16_t rnti; - uint32_t max_mcs_dl; - uint32_t max_aggr_level; - uint32_t max_mcs_ul; - uint32_t max_msg3retx; - int fixed_mcs_ul; - int fixed_mcs_dl; - uint32_t P; - - uint32_t nof_ta_cmd; - - int next_tpc_pusch; - int next_tpc_pucch; + bool sr = false; + int buf_mac = 0; + int buf_ul = 0; + std::array lch = {}; + + int power_headroom = 0; + uint32_t dl_ri = 0; + uint32_t dl_ri_tti = 0; + uint32_t dl_pmi = 0; + uint32_t dl_pmi_tti = 0; + uint32_t dl_cqi = 0; + uint32_t dl_cqi_tti = 0; + uint32_t cqi_request_tti = 0; + uint32_t ul_cqi = 0; + uint32_t ul_cqi_tti = 0; + uint16_t rnti = 0; + uint32_t max_mcs_dl = 0; + uint32_t max_aggr_level = 0; + uint32_t max_mcs_ul = 0; + uint32_t max_msg3retx = 0; + int fixed_mcs_ul = 0; + int fixed_mcs_dl = 0; + uint32_t P = 0; + + uint32_t nof_ta_cmd = 0; + + int next_tpc_pusch = 0; + int next_tpc_pucch = 0; // Allowed DCI locations per CFI and per subframe - sched_dci_cce_t dci_locations[3][10]; + std::array, 3> dci_locations = {}; - const static int SCHED_MAX_HARQ_PROC = SRSLTE_FDD_NOF_HARQ; - dl_harq_proc dl_harq[SCHED_MAX_HARQ_PROC]; - ul_harq_proc ul_harq[SCHED_MAX_HARQ_PROC]; + const static int SCHED_MAX_HARQ_PROC = SRSLTE_FDD_NOF_HARQ; + std::array dl_harq = {}; + std::array ul_harq = {}; - bool phy_config_dedicated_enabled; + bool phy_config_dedicated_enabled = false; asn1::rrc::phys_cfg_ded_s::ant_info_c_ dl_ant_info; }; } // namespace srsenb diff --git a/srsenb/hdr/stack/rrc/rrc.h b/srsenb/hdr/stack/rrc/rrc.h index e5e53cfe0..bd9a579fc 100644 --- a/srsenb/hdr/stack/rrc/rrc.h +++ b/srsenb/hdr/stack/rrc/rrc.h @@ -46,7 +46,7 @@ struct rrc_cfg_sr_t { uint32_t nof_subframes; }; -typedef enum { RRC_CFG_CQI_MODE_PERIODIC = 0, RRC_CFG_CQI_MODE_APERIODIC, RRC_CFG_CQI_MODE_N_ITEMS } rrc_cfg_cqi_mode_t; +enum rrc_cfg_cqi_mode_t { RRC_CFG_CQI_MODE_PERIODIC = 0, RRC_CFG_CQI_MODE_APERIODIC, RRC_CFG_CQI_MODE_N_ITEMS }; static const char rrc_cfg_cqi_mode_text[RRC_CFG_CQI_MODE_N_ITEMS][20] = {"periodic", "aperiodic"}; @@ -141,30 +141,29 @@ public: void get_metrics(rrc_metrics_t& m); // rrc_interface_mac - void rl_failure(uint16_t rnti); - void add_user(uint16_t rnti); - void upd_user(uint16_t new_rnti, uint16_t old_rnti); - void set_activity_user(uint16_t rnti); - bool is_paging_opportunity(uint32_t tti, uint32_t* payload_len); + void rl_failure(uint16_t rnti) override; + void add_user(uint16_t rnti) override; + void upd_user(uint16_t new_rnti, uint16_t old_rnti) override; + void set_activity_user(uint16_t rnti) override; + bool is_paging_opportunity(uint32_t tti, uint32_t* payload_len) override; // rrc_interface_rlc - void read_pdu_bcch_dlsch(uint32_t sib_idx, uint8_t* payload); - void read_pdu_pcch(uint8_t* payload, uint32_t buffer_size); - void max_retx_attempted(uint16_t rnti); + void read_pdu_bcch_dlsch(uint32_t sib_idx, uint8_t* payload) override; + void read_pdu_pcch(uint8_t* payload, uint32_t buffer_size) override; + void max_retx_attempted(uint16_t rnti) override; // rrc_interface_s1ap - void write_dl_info(uint16_t rnti, srslte::unique_byte_buffer_t sdu); - void release_complete(uint16_t rnti); - bool setup_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPREQUEST_STRUCT* msg); - bool modify_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_UECONTEXTMODIFICATIONREQUEST_STRUCT* msg); - bool setup_ue_erabs(uint16_t rnti, LIBLTE_S1AP_MESSAGE_E_RABSETUPREQUEST_STRUCT* msg); - bool release_erabs(uint32_t rnti); - void add_paging_id(uint32_t ueid, LIBLTE_S1AP_UEPAGINGID_STRUCT UEPagingID); + void write_dl_info(uint16_t rnti, srslte::unique_byte_buffer_t sdu) override; + void release_complete(uint16_t rnti) override; + bool setup_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPREQUEST_STRUCT* msg) override; + bool modify_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_UECONTEXTMODIFICATIONREQUEST_STRUCT* msg) override; + bool setup_ue_erabs(uint16_t rnti, LIBLTE_S1AP_MESSAGE_E_RABSETUPREQUEST_STRUCT* msg) override; + bool release_erabs(uint32_t rnti) override; + void add_paging_id(uint32_t ueid, LIBLTE_S1AP_UEPAGINGID_STRUCT UEPagingID) override; // rrc_interface_pdcp - void write_pdu(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t pdu); + void write_pdu(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t pdu) override; - void parse_sibs(); uint32_t get_nof_users(); // logging @@ -180,16 +179,16 @@ public: }; void set_connect_notifer(connect_notifier* cnotifier); - class activity_monitor : public thread + class activity_monitor final : public thread { public: - activity_monitor(rrc* parent_); + explicit activity_monitor(rrc* parent_); void stop(); private: rrc* parent; bool running; - void run_thread(); + void run_thread() override; }; class ue @@ -261,12 +260,12 @@ public: uint16_t rnti; rrc* parent; - bool connect_notified; + bool connect_notified = false; - bool is_csfb; + bool is_csfb = false; private: - srslte::byte_buffer_pool* pool; + srslte::byte_buffer_pool* pool = nullptr; struct timeval t_last_activity; struct timeval t_ue_init; @@ -274,13 +273,13 @@ public: std::unique_ptr mobility_handler; // S-TMSI for this UE - bool has_tmsi; - uint32_t m_tmsi; - uint8_t mmec; + bool has_tmsi = false; + uint32_t m_tmsi = 0; + uint8_t mmec = 0; - uint32_t rlf_cnt; - uint8_t transaction_id; - rrc_state_t state; + uint32_t rlf_cnt = 0; + uint8_t transaction_id = 0; + rrc_state_t state = RRC_STATE_IDLE; std::map srbs; std::map drbs; @@ -306,18 +305,18 @@ public: uint32_t teid_in; } erab_t; std::map erabs; - int sr_sched_sf_idx; - int sr_sched_prb_idx; - bool sr_allocated; - uint32_t sr_N_pucch; - uint32_t sr_I; - uint32_t cqi_pucch; - uint32_t cqi_idx; - bool cqi_allocated; - int cqi_sched_sf_idx; - int cqi_sched_prb_idx; + int sr_sched_sf_idx = 0; + int sr_sched_prb_idx = 0; + bool sr_allocated = false; + uint32_t sr_N_pucch = 0; + uint32_t sr_I = 0; + uint32_t cqi_pucch = 0; + uint32_t cqi_idx = 0; + bool cqi_allocated = false; + int cqi_sched_sf_idx = 0; + int cqi_sched_prb_idx = 0; int get_drbid_config(asn1::rrc::drb_to_add_mod_s* drb, int drbid); - bool nas_pending; + bool nas_pending = false; srslte::byte_buffer_t erab_info; }; @@ -375,7 +374,7 @@ private: const static uint32_t LCID_RLF_USER = 0xffff0003; const static uint32_t LCID_ACT_USER = 0xffff0004; - bool running; + bool running = false; static const int RRC_THREAD_PRIO = 65; srslte::block_queue rx_pdu_queue; @@ -386,7 +385,7 @@ private: sr_sched_t sr_sched; sr_sched_t cqi_sched; asn1::rrc::mcch_msg_s mcch; - bool enable_mbms; + bool enable_mbms = false; rrc_cfg_t cfg; uint32_t nof_si_messages; asn1::rrc::sib_type2_s sib2; diff --git a/srsenb/src/enb_cfg_parser.h b/srsenb/src/enb_cfg_parser.h index fbc1e01a5..5f45cdaea 100644 --- a/srsenb/src/enb_cfg_parser.h +++ b/srsenb/src/enb_cfg_parser.h @@ -22,13 +22,13 @@ #ifndef ENB_CFG_PARSER_SIB1_H #define ENB_CFG_PARSER_SIB1_H -#include -#include -#include +#include "srsenb/hdr/parser.h" +#include #include +#include +#include #include -#include -#include "srsenb/hdr/parser.h" +#include #include "srsenb/hdr/stack/rrc/rrc.h" #include "srslte/asn1/asn1_utils.h" @@ -37,57 +37,45 @@ namespace srsenb { using namespace libconfig; -class field_sched_info : public parser::field_itf +class field_sched_info final : public parser::field_itf { public: - field_sched_info(asn1::rrc::sib_type1_s* data_) { data = data_; } - ~field_sched_info() {} - int parse(Setting &root); - const char* get_name() { - return "sched_info"; - } + explicit field_sched_info(asn1::rrc::sib_type1_s* data_) { data = data_; } + int parse(Setting& root) override; + const char* get_name() override { return "sched_info"; } private: asn1::rrc::sib_type1_s* data; }; -class field_intra_neigh_cell_list : public parser::field_itf +class field_intra_neigh_cell_list final : public parser::field_itf { public: - field_intra_neigh_cell_list(asn1::rrc::sib_type4_s* data_) { data = data_; } - ~field_intra_neigh_cell_list(){} - int parse(Setting& root); - const char* get_name() { - return "intra_neigh_cell_list"; - } + explicit field_intra_neigh_cell_list(asn1::rrc::sib_type4_s* data_) { data = data_; } + int parse(Setting& root) override; + const char* get_name() override { return "intra_neigh_cell_list"; } private: asn1::rrc::sib_type4_s* data; }; -class field_intra_black_cell_list : public parser::field_itf +class field_intra_black_cell_list final : public parser::field_itf { public: - field_intra_black_cell_list(asn1::rrc::sib_type4_s* data_) { data = data_; } - ~field_intra_black_cell_list(){} - int parse(Setting &root); - const char* get_name() { - return "intra_black_cell_list"; - } + explicit field_intra_black_cell_list(asn1::rrc::sib_type4_s* data_) { data = data_; } + int parse(Setting& root) override; + const char* get_name() override { return "intra_black_cell_list"; } private: asn1::rrc::sib_type4_s* data; }; -class field_carrier_freqs_info_list : public parser::field_itf +class field_carrier_freqs_info_list final : public parser::field_itf { public: - field_carrier_freqs_info_list(asn1::rrc::sib_type7_s* data_) { data = data_; } - ~field_carrier_freqs_info_list(){} - int parse(Setting &root); - const char* get_name() { - return "carrier_freqs_info_list"; - } + explicit field_carrier_freqs_info_list(asn1::rrc::sib_type7_s* data_) { data = data_; } + int parse(Setting& root) override; + const char* get_name() override { return "carrier_freqs_info_list"; } private: asn1::rrc::sib_type7_s* data; @@ -96,26 +84,26 @@ private: class field_sf_mapping : public parser::field_itf { public: - field_sf_mapping(uint32_t *sf_mapping_, uint32_t *nof_subframes_) { sf_mapping = sf_mapping_; nof_subframes = nof_subframes_; } - ~field_sf_mapping(){} - int parse(Setting &root); - const char* get_name() { - return "sf_mapping"; + field_sf_mapping(uint32_t* sf_mapping_, uint32_t* nof_subframes_) + { + sf_mapping = sf_mapping_; + nof_subframes = nof_subframes_; } + int parse(Setting& root) override; + const char* get_name() override { return "sf_mapping"; } -private: - uint32_t *sf_mapping; - uint32_t *nof_subframes; +private: + uint32_t* sf_mapping; + uint32_t* nof_subframes; }; class field_qci : public parser::field_itf { public: - field_qci(rrc_cfg_qci_t *cfg_) { cfg = cfg_; } - ~field_qci(){} - const char* get_name() { return "field_cqi"; } + explicit field_qci(rrc_cfg_qci_t* cfg_) { cfg = cfg_; } + const char* get_name() override { return "field_cqi"; } - int parse(Setting& root); + int parse(Setting& root) override; private: rrc_cfg_qci_t* cfg; @@ -138,32 +126,6 @@ private: rrc_meas_cfg_t* meas_cfg; }; -class field_meas_cell_list final : public parser::field_itf -{ -public: - explicit field_meas_cell_list(rrc_meas_cfg_t* meas_cfg_) : meas_cfg(meas_cfg_) {} - - int parse(Setting& root) override; - - const char* get_name() override { return "meas_cell_list"; } - -private: - rrc_meas_cfg_t* meas_cfg; -}; - -class field_meas_report_desc final : public parser::field_itf -{ -public: - explicit field_meas_report_desc(rrc_meas_cfg_t* meas_cfg_) : meas_cfg(meas_cfg_) {} - - int parse(Setting& root) override; - - const char* get_name() override { return "meas_report_desc"; } - -private: - rrc_meas_cfg_t* meas_cfg; -}; - } // namespace rr_sections // ASN1 parsers @@ -171,15 +133,15 @@ private: class field_asn1 : public parser::field_itf { public: - field_asn1(const char* name_, bool* enabled_value_ = NULL) + explicit field_asn1(const char* name_, bool* enabled_value_ = nullptr) { name = name_; enabled_value = enabled_value_; } - const char* get_name() { return name; } + const char* get_name() override { return name; } - int parse(Setting& root) + int parse(Setting& root) override { if (root.exists(name)) { @@ -210,13 +172,13 @@ class field_asn1_seqof_size : public field_asn1 ListType* store_ptr; public: - field_asn1_seqof_size(const char* name_, ListType* store_ptr_, bool* enabled_value_ = NULL) : + field_asn1_seqof_size(const char* name_, ListType* store_ptr_, bool* enabled_value_ = nullptr) : field_asn1(name_, enabled_value_), store_ptr(store_ptr_) { } - int parse_value(Setting& root) + int parse_value(Setting& root) override { uint32_t size_val; if (root.lookupValue(name, size_val)) { @@ -228,8 +190,8 @@ public: }; template -field_asn1_seqof_size* make_asn1_seqof_size_parser(const char* name, ListType* store_ptr, - bool* enabled = NULL) +field_asn1_seqof_size* +make_asn1_seqof_size_parser(const char* name, ListType* store_ptr, bool* enabled = nullptr) { return new field_asn1_seqof_size(name, store_ptr, enabled); } @@ -240,13 +202,13 @@ class field_asn1_choice_type_number : public field_asn1 ChoiceType* store_ptr; public: - field_asn1_choice_type_number(const char* name_, ChoiceType* store_ptr_, bool* enabled_value_ = NULL) : + field_asn1_choice_type_number(const char* name_, ChoiceType* store_ptr_, bool* enabled_value_ = nullptr) : field_asn1(name_, enabled_value_), store_ptr(store_ptr_) { } - int parse_value(Setting& root) + int parse_value(Setting& root) override { NumberType val; if (root.lookupValue(name, val)) { @@ -345,13 +307,13 @@ class field_asn1_enum_number : public field_asn1 EnumType* store_ptr; public: - field_asn1_enum_number(const char* name_, EnumType* store_ptr_, bool* enabled_value_ = NULL) : + field_asn1_enum_number(const char* name_, EnumType* store_ptr_, bool* enabled_value_ = nullptr) : field_asn1(name_, enabled_value_), store_ptr(store_ptr_) { } - int parse_value(Setting& root) + int parse_value(Setting& root) override { bool found = parse_enum_by_number(*store_ptr, name, root); return found ? 0 : -1; @@ -359,8 +321,8 @@ public: }; template -field_asn1_enum_number* make_asn1_enum_number_parser(const char* name, EnumType* store_ptr, - bool* enabled = NULL) +field_asn1_enum_number* +make_asn1_enum_number_parser(const char* name, EnumType* store_ptr, bool* enabled = nullptr) { return new field_asn1_enum_number(name, store_ptr, enabled); } @@ -371,13 +333,13 @@ class field_asn1_enum_str : public field_asn1 EnumType* store_ptr; public: - field_asn1_enum_str(const char* name_, EnumType* store_ptr_, bool* enabled_value_ = NULL) : + field_asn1_enum_str(const char* name_, EnumType* store_ptr_, bool* enabled_value_ = nullptr) : field_asn1(name_, enabled_value_), store_ptr(store_ptr_) { } - int parse_value(Setting& root) + int parse_value(Setting& root) override { bool found = parse_enum_by_str(*store_ptr, name, root); return found ? 0 : -1; @@ -385,7 +347,7 @@ public: }; template -field_asn1_enum_str* make_asn1_enum_str_parser(const char* name, EnumType* store_ptr, bool* enabled = NULL) +field_asn1_enum_str* make_asn1_enum_str_parser(const char* name, EnumType* store_ptr, bool* enabled = nullptr) { return new field_asn1_enum_str(name, store_ptr, enabled); } @@ -396,13 +358,13 @@ class field_asn1_enum_number_str : public field_asn1 EnumType* store_ptr; public: - field_asn1_enum_number_str(const char* name_, EnumType* store_ptr_, bool* enabled_value_ = NULL) : + field_asn1_enum_number_str(const char* name_, EnumType* store_ptr_, bool* enabled_value_ = nullptr) : field_asn1(name_, enabled_value_), store_ptr(store_ptr_) { } - int parse_value(Setting& root) + int parse_value(Setting& root) override { bool found = parse_enum_by_number_str(*store_ptr, name, root); return found ? 0 : -1; @@ -410,8 +372,8 @@ public: }; template -field_asn1_enum_number_str* make_asn1_enum_number_str_parser(const char* name, EnumType* store_ptr, - bool* enabled = NULL) +field_asn1_enum_number_str* +make_asn1_enum_number_str_parser(const char* name, EnumType* store_ptr, bool* enabled = nullptr) { return new field_asn1_enum_number_str(name, store_ptr, enabled); } @@ -421,8 +383,11 @@ class field_asn1_choice_str : public field_asn1 { public: typedef bool (*func_ptr)(ChoiceType*, const char*, Setting&); - field_asn1_choice_str(const char* name_, const char* choicetypename_, func_ptr f_, ChoiceType* store_ptr_, - bool* enabled_value_ = NULL) : + field_asn1_choice_str(const char* name_, + const char* choicetypename_, + func_ptr f_, + ChoiceType* store_ptr_, + bool* enabled_value_ = nullptr) : field_asn1(name_, enabled_value_), store_ptr(store_ptr_), choicetypename(choicetypename_), @@ -430,7 +395,7 @@ public: { } - int parse_value(Setting& root) + int parse_value(Setting& root) override { typename ChoiceType::types type; bool found = parse_enum_by_str(type, choicetypename, root); @@ -451,8 +416,11 @@ private: }; template -field_asn1_choice_str* make_asn1_choice_str_parser(const char* name, const char* choicetypename, - ChoiceType* store_ptr, FuncOper f, bool* enabled = NULL) +field_asn1_choice_str* make_asn1_choice_str_parser(const char* name, + const char* choicetypename, + ChoiceType* store_ptr, + FuncOper f, + bool* enabled = nullptr) { return new field_asn1_choice_str(name, choicetypename, f, store_ptr, enabled); } @@ -462,8 +430,11 @@ class field_asn1_choice_number : public field_asn1 { public: typedef bool (*func_ptr)(ChoiceType*, const char*, Setting&); - field_asn1_choice_number(const char* name_, const char* choicetypename_, func_ptr f_, ChoiceType* store_ptr_, - bool* enabled_value_ = NULL) : + field_asn1_choice_number(const char* name_, + const char* choicetypename_, + func_ptr f_, + ChoiceType* store_ptr_, + bool* enabled_value_ = nullptr) : field_asn1(name_, enabled_value_), store_ptr(store_ptr_), choicetypename(choicetypename_), @@ -471,7 +442,7 @@ public: { } - int parse_value(Setting& root) + int parse_value(Setting& root) override { typename ChoiceType::types type; bool found = parse_enum_by_number(type, choicetypename, root); @@ -497,13 +468,13 @@ class field_asn1_bitstring_number : public field_asn1 BitString* store_ptr; public: - field_asn1_bitstring_number(const char* name_, BitString* store_ptr_, bool* enabled_value_ = NULL) : + field_asn1_bitstring_number(const char* name_, BitString* store_ptr_, bool* enabled_value_ = nullptr) : field_asn1(name_, enabled_value_), store_ptr(store_ptr_) { } - int parse_value(Setting& root) + int parse_value(Setting& root) override { NumType val; if (parser::lookupValue(root, name, &val)) { @@ -512,8 +483,8 @@ public: } else { std::string str_val; if (parser::lookupValue(root, name, &str_val)) { - fprintf(stderr, "PARSER ERROR: Expected number for field %s but got the string \"%s\"\n", name, - str_val.c_str()); + fprintf( + stderr, "PARSER ERROR: Expected number for field %s but got the string \"%s\"\n", name, str_val.c_str()); } } return -1; @@ -530,10 +501,10 @@ field_asn1_bitstring_number* make_asn1_bitstring_number_par class phr_cnfg_parser : public parser::field_itf { public: - phr_cnfg_parser(asn1::rrc::mac_main_cfg_s::phr_cfg_c_* phr_cfg_) { phr_cfg = phr_cfg_; } - ~phr_cnfg_parser() {} - int parse(Setting& root); - const char* get_name() { return "phr_cnfg"; } + explicit phr_cnfg_parser(asn1::rrc::mac_main_cfg_s::phr_cfg_c_* phr_cfg_) { phr_cfg = phr_cfg_; } + ~phr_cnfg_parser() override = default; + int parse(Setting& root) override; + const char* get_name() override { return "phr_cnfg"; } private: asn1::rrc::mac_main_cfg_s::phr_cfg_c_* phr_cfg; @@ -547,16 +518,16 @@ public: enabled(enabled_) { } - ~mbsfn_sf_cfg_list_parser() {} - int parse(Setting& root); - const char* get_name() { return "mbsfnSubframeConfigList"; } + ~mbsfn_sf_cfg_list_parser() override = default; + int parse(Setting& root) override; + const char* get_name() override { return "mbsfnSubframeConfigList"; } private: asn1::rrc::mbsfn_sf_cfg_list_l* mbsfn_list; bool* enabled; }; -class mbsfn_area_info_list_parser : public parser::field_itf +class mbsfn_area_info_list_parser final : public parser::field_itf { public: mbsfn_area_info_list_parser(asn1::rrc::mbsfn_area_info_list_r9_l* mbsfn_list_, bool* enabled_) : @@ -564,15 +535,14 @@ public: enabled(enabled_) { } - ~mbsfn_area_info_list_parser() {} - int parse(Setting& root); - const char* get_name() { return "mbsfn_area_info_list"; } + ~mbsfn_area_info_list_parser() override = default; + int parse(Setting& root) override; + const char* get_name() override { return "mbsfn_area_info_list"; } private: asn1::rrc::mbsfn_area_info_list_r9_l* mbsfn_list; bool* enabled; }; -} +} // namespace srsenb #endif - diff --git a/srsenb/src/stack/mac/scheduler.cc b/srsenb/src/stack/mac/scheduler.cc index 0d917e658..01e8419fc 100644 --- a/srsenb/src/stack/mac/scheduler.cc +++ b/srsenb/src/stack/mac/scheduler.cc @@ -217,7 +217,8 @@ bool sched::ue_exists(uint16_t rnti) return ue_db_access(rnti, [](sched_ue& ue) {}) >= 0; } -void sched::ue_needs_ta_cmd(uint16_t rnti, uint32_t nof_ta_cmd) { +void sched::ue_needs_ta_cmd(uint16_t rnti, uint32_t nof_ta_cmd) +{ pthread_rwlock_rdlock(&rwlock); if (ue_db.count(rnti)) { ue_db[rnti].set_needs_ta_cmd(nof_ta_cmd); @@ -395,8 +396,11 @@ int sched::ul_sched(uint32_t tti, srsenb::sched_interface::ul_sched_res_t* sched * *******************************************************/ -void sched::generate_cce_location( - srslte_regs_t* regs_, sched_ue::sched_dci_cce_t* location, uint32_t cfi, uint32_t sf_idx, uint16_t rnti) +void sched::generate_cce_location(srslte_regs_t* regs_, + sched_ue::sched_dci_cce_t* location, + uint32_t cfi, + uint32_t sf_idx, + uint16_t rnti) { bzero(location, sizeof(sched_ue::sched_dci_cce_t)); diff --git a/srsenb/src/stack/mac/scheduler_carrier.cc b/srsenb/src/stack/mac/scheduler_carrier.cc index 307be39f9..b3cb357ef 100644 --- a/srsenb/src/stack/mac/scheduler_carrier.cc +++ b/srsenb/src/stack/mac/scheduler_carrier.cc @@ -86,7 +86,8 @@ bool sched::carrier_sched::tti_sched_result_t::is_ul_alloc(sched_ue* user) const } sched::carrier_sched::tti_sched_result_t::ctrl_code_t -sched::carrier_sched::tti_sched_result_t::alloc_dl_ctrl(uint32_t aggr_lvl, uint32_t tbs_bytes, uint16_t rnti) { +sched::carrier_sched::tti_sched_result_t::alloc_dl_ctrl(uint32_t aggr_lvl, uint32_t tbs_bytes, uint16_t rnti) +{ ctrl_alloc_t ctrl_alloc{}; // based on rnti, check which type of alloc @@ -104,10 +105,10 @@ sched::carrier_sched::tti_sched_result_t::alloc_dl_ctrl(uint32_t aggr_lvl, uint3 } // Allocation Successful - ctrl_alloc.dci_idx = tti_alloc.get_pdcch_grid().nof_allocs() - 1; - ctrl_alloc.rbg_range = ret.rbg_range; - ctrl_alloc.rnti = rnti; - ctrl_alloc.req_bytes = tbs_bytes; + ctrl_alloc.dci_idx = tti_alloc.get_pdcch_grid().nof_allocs() - 1; + ctrl_alloc.rbg_range = ret.rbg_range; + ctrl_alloc.rnti = rnti; + ctrl_alloc.req_bytes = tbs_bytes; ctrl_alloc.alloc_type = alloc_type; return {ret.outcome, ctrl_alloc}; @@ -153,8 +154,11 @@ alloc_outcome_t sched::carrier_sched::tti_sched_result_t::alloc_paging(uint32_t return ret.first; } -sched::carrier_sched::tti_sched_result_t::rar_code_t sched::carrier_sched::tti_sched_result_t::alloc_rar( - uint32_t aggr_lvl, const dl_sched_rar_t& rar_grant, uint32_t prach_tti, uint32_t buf_rar) +sched::carrier_sched::tti_sched_result_t::rar_code_t +sched::carrier_sched::tti_sched_result_t::alloc_rar(uint32_t aggr_lvl, + const dl_sched_rar_t& rar_grant, + uint32_t prach_tti, + uint32_t buf_rar) { // RA-RNTI = 1 + t_id + f_id // t_id = index of first subframe specified by PRACH (0<=t_id<10) @@ -518,8 +522,12 @@ uint32_t sched::carrier_sched::tti_sched_result_t::get_nof_ctrl_symbols() const return tti_alloc.get_cfi() + ((parent_carrier->cfg->cell.nof_prb <= 10) ? 1 : 0); } -int sched::carrier_sched::tti_sched_result_t::generate_format1a( - uint32_t rb_start, uint32_t l_crb, uint32_t tbs_bytes, uint32_t rv, uint16_t rnti, srslte_dci_dl_t* dci) +int sched::carrier_sched::tti_sched_result_t::generate_format1a(uint32_t rb_start, + uint32_t l_crb, + uint32_t tbs_bytes, + uint32_t rv, + uint16_t rnti, + srslte_dci_dl_t* dci) { /* Calculate I_tbs for this TBS */ int tbs = tbs_bytes * 8; @@ -683,7 +691,8 @@ void ra_sched::init(srslte::log* log_, std::map& ue_db_) } // Schedules RAR -// On every call to this function, we schedule the oldest RAR which is still within the window. If outside the window we discard it. +// On every call to this function, we schedule the oldest RAR which is still within the window. If outside the window we +// discard it. void ra_sched::dl_sched(srsenb::sched::carrier_sched::tti_sched_result_t* tti_sched) { tti_tx_dl = tti_sched->get_tti_tx_dl(); @@ -692,10 +701,7 @@ void ra_sched::dl_sched(srsenb::sched::carrier_sched::tti_sched_result_t* tti_sc // Discard all RARs out of the window. The first one inside the window is scheduled, if we can't we exit while (!pending_rars.empty()) { dl_sched_rar_info_t rar = pending_rars.front(); - if (not sched_utils::is_in_tti_interval(tti_tx_dl, - rar.prach_tti + 3, - rar.prach_tti + 3 + cfg->prach_rar_window)) - { + if (not sched_utils::is_in_tti_interval(tti_tx_dl, rar.prach_tti + 3, rar.prach_tti + 3 + cfg->prach_rar_window)) { if (tti_tx_dl >= rar.prach_tti + 3 + cfg->prach_rar_window) { log_h->console("SCHED: Could not transmit RAR within the window (RA TTI=%d, Window=%d, Now=%d)\n", rar.prach_tti, @@ -718,23 +724,24 @@ void ra_sched::dl_sched(srsenb::sched::carrier_sched::tti_sched_result_t* tti_sc * Msg3 transmission */ dl_sched_rar_t rar_grant; - uint32_t L_prb = 3; - uint32_t n_prb = cfg->nrb_pucch>0?cfg->nrb_pucch:2; + uint32_t L_prb = 3; + uint32_t n_prb = cfg->nrb_pucch > 0 ? cfg->nrb_pucch : 2; bzero(&rar_grant, sizeof(rar_grant)); uint32_t rba = srslte_ra_type2_to_riv(L_prb, n_prb, cfg->cell.nof_prb); - dl_sched_rar_grant_t *grant = &rar_grant.msg3_grant[0]; - grant->grant.tpc_pusch = 3; - grant->grant.trunc_mcs = 0; - grant->grant.rba = rba; - grant->data = rar; + dl_sched_rar_grant_t* grant = &rar_grant.msg3_grant[0]; + grant->grant.tpc_pusch = 3; + grant->grant.trunc_mcs = 0; + grant->grant.rba = rba; + grant->data = rar; rar_grant.nof_grants++; // Try to schedule DCI + RBGs for RAR Grant - sched::carrier_sched::tti_sched_result_t::rar_code_t ret = tti_sched->alloc_rar(rar_aggr_level, - rar_grant, - rar.prach_tti, - 7 * rar_grant.nof_grants); //fixme: check RAR size + sched::carrier_sched::tti_sched_result_t::rar_code_t ret = + tti_sched->alloc_rar(rar_aggr_level, + rar_grant, + rar.prach_tti, + 7 * rar_grant.nof_grants); // fixme: check RAR size // If we can allocate, schedule Msg3 and remove from pending if (!ret.first) { @@ -742,14 +749,16 @@ void ra_sched::dl_sched(srsenb::sched::carrier_sched::tti_sched_result_t* tti_sc } // Schedule Msg3 only if there is a requirement for Msg3 data - uint32_t pending_tti = (tti_sched->get_tti_tx_dl() + MSG3_DELAY_MS + TX_DELAY) % TTIMOD_SZ; + uint32_t pending_tti = (tti_sched->get_tti_tx_dl() + MSG3_DELAY_MS + TX_DELAY) % TTIMOD_SZ; pending_msg3[pending_tti].enabled = true; - pending_msg3[pending_tti].rnti = rar.temp_crnti; // FIXME - pending_msg3[pending_tti].L = L_prb; - pending_msg3[pending_tti].n_prb = n_prb; - dl_sched_rar_grant_t *last_msg3 = &rar_grant.msg3_grant[rar_grant.nof_grants - 1]; - pending_msg3[pending_tti].mcs = last_msg3->grant.trunc_mcs; - log_h->info("SCHED: Allocating Msg3 for rnti=%d at tti=%d\n", rar.temp_crnti, tti_sched->get_tti_tx_dl() + MSG3_DELAY_MS + TX_DELAY); + pending_msg3[pending_tti].rnti = rar.temp_crnti; // FIXME + pending_msg3[pending_tti].L = L_prb; + pending_msg3[pending_tti].n_prb = n_prb; + dl_sched_rar_grant_t* last_msg3 = &rar_grant.msg3_grant[rar_grant.nof_grants - 1]; + pending_msg3[pending_tti].mcs = last_msg3->grant.trunc_mcs; + log_h->info("SCHED: Allocating Msg3 for rnti=%d at tti=%d\n", + rar.temp_crnti, + tti_sched->get_tti_tx_dl() + MSG3_DELAY_MS + TX_DELAY); // Remove pending RAR and exit pending_rars.pop(); @@ -786,7 +795,11 @@ void ra_sched::ul_sched(sched::carrier_sched::tti_sched_result_t* tti_sched) int ra_sched::dl_rach_info(dl_sched_rar_info_t rar_info) { log_h->info("SCHED: New RAR tti=%d, preamble=%d, temp_crnti=0x%x, ta_cmd=%d, msg3_size=%d\n", - rar_info.prach_tti, rar_info.preamble_idx, rar_info.temp_crnti, rar_info.ta_cmd, rar_info.msg3_size); + rar_info.prach_tti, + rar_info.preamble_idx, + rar_info.temp_crnti, + rar_info.ta_cmd, + rar_info.msg3_size); pending_rars.push(rar_info); return 0; } diff --git a/srsenb/src/stack/mac/scheduler_harq.cc b/srsenb/src/stack/mac/scheduler_harq.cc index 2203d96c1..ec2f32b11 100644 --- a/srsenb/src/stack/mac/scheduler_harq.cc +++ b/srsenb/src/stack/mac/scheduler_harq.cc @@ -192,8 +192,12 @@ void dl_harq_proc::new_tx(const rbgmask_t& new_mask, uint32_t tb_idx, uint32_t t new_tx_common(tb_idx, tti, mcs, tbs); } -void dl_harq_proc::new_retx( - const rbgmask_t& new_mask, uint32_t tb_idx, uint32_t tti_, int* mcs, int* tbs, uint32_t n_cce_) +void dl_harq_proc::new_retx(const rbgmask_t& new_mask, + uint32_t tb_idx, + uint32_t tti_, + int* mcs, + int* tbs, + uint32_t n_cce_) { n_cce = n_cce_; rbgmask = new_mask; diff --git a/srsenb/src/stack/mac/scheduler_ue.cc b/srsenb/src/stack/mac/scheduler_ue.cc index 8f7b9ecac..e7870d39d 100644 --- a/srsenb/src/stack/mac/scheduler_ue.cc +++ b/srsenb/src/stack/mac/scheduler_ue.cc @@ -26,10 +26,10 @@ #include "srslte/common/pdu.h" #include "srslte/srslte.h" -#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) +#define Error(fmt, ...) log_h->error(fmt, ##__VA_ARGS__) #define Warning(fmt, ...) log_h->warning(fmt, ##__VA_ARGS__) -#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) -#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) +#define Info(fmt, ...) log_h->info(fmt, ##__VA_ARGS__) +#define Debug(fmt, ...) log_h->debug(fmt, ##__VA_ARGS__) #define MCS_FIRST_DL 4 #define MIN_DATA_TBS 4 @@ -46,18 +46,9 @@ namespace srsenb { * *******************************************************/ -sched_ue::sched_ue() : - has_pucch(false), - power_headroom(0), - rnti(0), - max_mcs_dl(0), - max_mcs_ul(0), - fixed_mcs_ul(0), - fixed_mcs_dl(0), - phy_config_dedicated_enabled(false), - nof_ta_cmd(0) +sched_ue::sched_ue() { - log_h = NULL; + log_h = nullptr; bzero(&cell, sizeof(cell)); bzero(&lch, sizeof(lch)); @@ -84,10 +75,10 @@ void sched_ue::set_cfg(uint16_t rnti_, memcpy(&cell, &cell_cfg->cell, sizeof(srslte_cell_t)); P = srslte_ra_type0_P(cell.nof_prb); - max_mcs_dl = 28; - max_mcs_ul = 28; + max_mcs_dl = 28; + max_mcs_ul = 28; max_aggr_level = 3; - max_msg3retx = cell_cfg->maxharq_msg3tx; + max_msg3retx = cell_cfg->maxharq_msg3tx; cfg = *cfg_; @@ -154,7 +145,8 @@ void sched_ue::set_fixed_mcs(int mcs_ul, int mcs_dl) fixed_mcs_dl = mcs_dl; } -void sched_ue::set_max_mcs(int mcs_ul, int mcs_dl, int max_aggr_level_) { +void sched_ue::set_max_mcs(int mcs_ul, int mcs_dl, int max_aggr_level_) +{ std::lock_guard lock(mutex); if (mcs_ul < 0) { max_mcs_ul = 28; @@ -179,11 +171,11 @@ void sched_ue::set_max_mcs(int mcs_ul, int mcs_dl, int max_aggr_level_) { * *******************************************************/ -void sched_ue::set_bearer_cfg(uint32_t lc_id, sched_interface::ue_bearer_cfg_t* cfg) +void sched_ue::set_bearer_cfg(uint32_t lc_id, sched_interface::ue_bearer_cfg_t* cfg_) { std::lock_guard lock(mutex); if (lc_id < sched_interface::MAX_LC) { - memcpy(&lch[lc_id].cfg, cfg, sizeof(sched_interface::ue_bearer_cfg_t)); + memcpy(&lch[lc_id].cfg, cfg_, sizeof(sched_interface::ue_bearer_cfg_t)); lch[lc_id].buf_tx = 0; lch[lc_id].buf_retx = 0; if (lch[lc_id].cfg.direction != sched_interface::ue_bearer_cfg_t::IDLE) { @@ -250,7 +242,8 @@ void sched_ue::unset_sr() sr = false; } -void sched_ue::set_needs_ta_cmd(uint32_t nof_ta_cmd_) { +void sched_ue::set_needs_ta_cmd(uint32_t nof_ta_cmd_) +{ nof_ta_cmd = nof_ta_cmd_; Info("SCHED: rnti=0x%x needs %d TA CMD\n", rnti, nof_ta_cmd); } @@ -319,7 +312,7 @@ bool sched_ue::get_pucch_sched(uint32_t current_tti, uint32_t prb_idx[2]) int sched_ue::set_ack_info(uint32_t tti, uint32_t tb_idx, bool ack) { std::lock_guard lock(mutex); - int ret = -1; + int ret; for (int i = 0; i < SCHED_MAX_HARQ_PROC; i++) { if (TTI_TX(dl_harq[i].get_tti()) == tti) { Debug("SCHED: Set ACK=%d for rnti=0x%x, pid=%d, tb=%d, tti=%d\n", ack, rnti, i, tb_idx, tti); @@ -422,8 +415,11 @@ void sched_ue::tpc_dec() // Generates a Format1 dci // > return 0 if TBS lock(mutex); @@ -484,7 +480,7 @@ int sched_ue::generate_format1( } else { // Add TA CE. TODO: Common interface to add MAC CE // FIXME: Can't put it in Msg4 because current srsUE doesn't read it - while(nof_ta_cmd > 0 && rem_tbs > 2) { + while (nof_ta_cmd > 0 && rem_tbs > 2) { data->pdu[0][data->nof_pdu_elems[0]].lcid = srslte::sch_subh::TA_CMD; data->nof_pdu_elems[0]++; Info("SCHED: Added MAC TA CMD CE for rnti=0x%x\n", rnti); @@ -525,8 +521,11 @@ int sched_ue::generate_format1( } // Generates a Format2a dci -int sched_ue::generate_format2a( - dl_harq_proc* h, sched_interface::dl_sched_data_t* data, uint32_t tti, uint32_t cfi, const rbgmask_t& user_mask) +int sched_ue::generate_format2a(dl_harq_proc* h, + sched_interface::dl_sched_data_t* data, + uint32_t tti, + uint32_t cfi, + const rbgmask_t& user_mask) { std::lock_guard lock(mutex); int ret = generate_format2a_unlocked(h, data, tti, cfi, user_mask); @@ -534,8 +533,11 @@ int sched_ue::generate_format2a( } // Generates a Format2a dci -int sched_ue::generate_format2a_unlocked( - dl_harq_proc* h, sched_interface::dl_sched_data_t* data, uint32_t tti, uint32_t cfi, const rbgmask_t& user_mask) +int sched_ue::generate_format2a_unlocked(dl_harq_proc* h, + sched_interface::dl_sched_data_t* data, + uint32_t tti, + uint32_t cfi, + const rbgmask_t& user_mask) { bool tb_en[SRSLTE_MAX_TB] = {false}; @@ -637,8 +639,11 @@ int sched_ue::generate_format2a_unlocked( } // Generates a Format2 dci -int sched_ue::generate_format2( - dl_harq_proc* h, sched_interface::dl_sched_data_t* data, uint32_t tti, uint32_t cfi, const rbgmask_t& user_mask) +int sched_ue::generate_format2(dl_harq_proc* h, + sched_interface::dl_sched_data_t* data, + uint32_t tti, + uint32_t cfi, + const rbgmask_t& user_mask) { std::lock_guard lock(mutex); @@ -651,7 +656,7 @@ int sched_ue::generate_format2( if ((SRSLTE_DCI_IS_TB_EN(data->dci.tb[0]) + SRSLTE_DCI_IS_TB_EN(data->dci.tb[1])) == 1) { data->dci.pinfo = (uint8_t)(dl_pmi + 1) % (uint8_t)5; } else { - data->dci.pinfo = (uint8_t)(dl_pmi & 1); + data->dci.pinfo = (uint8_t)(dl_pmi & 1u); } return ret; @@ -698,7 +703,7 @@ int sched_ue::generate_format0(sched_interface::ul_sched_data_t* data, } else { // retx - h->new_retx(0, tti, &mcs, NULL, alloc); + h->new_retx(0, tti, &mcs, nullptr, alloc); tbs = srslte_ra_tbs_from_idx(srslte_ra_tbs_idx_from_mcs(mcs, true), alloc.L) / 8; } @@ -825,7 +830,7 @@ uint32_t sched_ue::get_pending_dl_new_data_unlocked(uint32_t tti) } } if (!is_first_dl_tx() && nof_ta_cmd) { - pending_data += nof_ta_cmd*2; + pending_data += nof_ta_cmd * 2; } return pending_data; } @@ -1002,7 +1007,7 @@ dl_harq_proc* sched_ue::get_pending_dl_harq(uint32_t tti) } } } - dl_harq_proc* h = NULL; + dl_harq_proc* h = nullptr; if (oldest_idx >= 0) { h = &dl_harq[oldest_idx]; } @@ -1018,7 +1023,7 @@ dl_harq_proc* sched_ue::get_empty_dl_harq() { std::lock_guard lock(mutex); - dl_harq_proc* h = NULL; + dl_harq_proc* h = nullptr; for (int i = 0; i < SCHED_MAX_HARQ_PROC && !h; i++) { if (dl_harq[i].is_empty(0) && dl_harq[i].is_empty(1)) { h = &dl_harq[i]; @@ -1145,7 +1150,7 @@ uint32_t sched_ue::format1_count_prb(uint32_t bitmask, uint32_t cell_nof_prb) uint32_t nof_prb = 0; for (uint32_t i = 0; i < nb; i++) { - if (bitmask & (1 << (nb - i - 1))) { + if (bitmask & (1u << (nb - i - 1))) { for (uint32_t j = 0; j < P; j++) { if (i * P + j < cell_nof_prb) { nof_prb++; @@ -1156,8 +1161,13 @@ uint32_t sched_ue::format1_count_prb(uint32_t bitmask, uint32_t cell_nof_prb) return nof_prb; } -int sched_ue::cqi_to_tbs( - uint32_t cqi, uint32_t nof_prb, uint32_t nof_re, uint32_t max_mcs, uint32_t max_Qm, bool is_ul, uint32_t* mcs) +int sched_ue::cqi_to_tbs(uint32_t cqi, + uint32_t nof_prb, + uint32_t nof_re, + uint32_t max_mcs, + uint32_t max_Qm, + bool is_ul, + uint32_t* mcs) { float max_coderate = srslte_cqi_to_coderate(cqi); int sel_mcs = max_mcs + 1; diff --git a/srsenb/src/stack/rrc/rrc.cc b/srsenb/src/stack/rrc/rrc.cc index b0047885c..db1a7c8f4 100644 --- a/srsenb/src/stack/rrc/rrc.cc +++ b/srsenb/src/stack/rrc/rrc.cc @@ -29,8 +29,8 @@ #include "srslte/interfaces/sched_interface.h" #include "srslte/srslte.h" -using srslte::byte_buffer_t; using srslte::bit_buffer_t; +using srslte::byte_buffer_t; using srslte::uint32_to_uint8; using srslte::uint8_to_uint32; @@ -38,19 +38,19 @@ using namespace asn1::rrc; namespace srsenb { -rrc::rrc() : act_monitor(this), cnotifier(NULL), running(false), nof_si_messages(0), thread("RRC") +rrc::rrc() : act_monitor(this), cnotifier(nullptr), nof_si_messages(0), thread("RRC") { users.clear(); pending_paging.clear(); - pool = NULL; - phy = NULL; - mac = NULL; - rlc = NULL; - pdcp = NULL; - gtpu = NULL; - s1ap = NULL; - rrc_log = NULL; + pool = nullptr; + phy = nullptr; + mac = nullptr; + rlc = nullptr; + pdcp = nullptr; + gtpu = nullptr; + s1ap = nullptr; + rrc_log = nullptr; bzero(&sr_sched, sizeof(sr_sched)); bzero(&cqi_sched, sizeof(cqi_sched)); @@ -71,14 +71,14 @@ void rrc::init(rrc_cfg_t* cfg_, gtpu_interface_rrc* gtpu_, srslte::log* log_rrc) { - phy = phy_; - mac = mac_; - rlc = rlc_; - pdcp = pdcp_; - gtpu = gtpu_; - s1ap = s1ap_; - rrc_log = log_rrc; - cnotifier = NULL; + phy = phy_; + mac = mac_; + rlc = rlc_; + pdcp = pdcp_; + gtpu = gtpu_; + s1ap = s1ap_; + rrc_log = log_rrc; + cnotifier = nullptr; running = false; pool = srslte::byte_buffer_pool::get_instance(); @@ -94,8 +94,8 @@ void rrc::init(rrc_cfg_t* cfg_, config_mac(); enb_mobility_cfg.reset(new mobility_cfg(&cfg, log_rrc)); - pthread_mutex_init(&user_mutex, NULL); - pthread_mutex_init(&paging_mutex, NULL); + pthread_mutex_init(&user_mutex, nullptr); + pthread_mutex_init(&paging_mutex, nullptr); act_monitor.start(RRC_THREAD_PRIO); bzero(&sr_sched, sizeof(sr_sched_t)); @@ -110,9 +110,9 @@ void rrc::set_connect_notifer(connect_notifier* cnotifier_) void rrc::stop() { - if(running) { - running = false; - rrc_pdu p = {0, LCID_EXIT, NULL}; + if (running) { + running = false; + rrc_pdu p = {0, LCID_EXIT, nullptr}; rx_pdu_queue.push(std::move(p)); wait_thread_finish(); } @@ -124,21 +124,20 @@ void rrc::stop() pthread_mutex_destroy(&paging_mutex); } - /******************************************************************************* Public functions - All public functions must be mutexed. + All public functions must be mutexed. *******************************************************************************/ -void rrc::get_metrics(rrc_metrics_t &m) +void rrc::get_metrics(rrc_metrics_t& m) { if (running) { pthread_mutex_lock(&user_mutex); m.n_ues = 0; - for(std::map::iterator iter=users.begin(); m.n_ues < ENB_METRICS_MAX_USERS &&iter!=users.end(); ++iter) { - ue *u = (ue*) &iter->second; - if(iter->first != SRSLTE_MRNTI){ + for (auto iter = users.begin(); m.n_ues < ENB_METRICS_MAX_USERS && iter != users.end(); ++iter) { + ue* u = (ue*)&iter->second; + if (iter->first != SRSLTE_MRNTI) { m.ues[m.n_ues++].state = u->get_state(); } } @@ -157,51 +156,59 @@ void rrc::read_pdu_bcch_dlsch(uint32_t sib_index, uint8_t* payload) { if (sib_index < ASN1_RRC_MAX_SIB) { memcpy(payload, sib_buffer[sib_index]->msg, sib_buffer[sib_index]->N_bytes); - } + } } void rrc::rl_failure(uint16_t rnti) { - rrc_pdu p = {rnti, LCID_RLF_USER, NULL}; + rrc_pdu p = {rnti, LCID_RLF_USER, nullptr}; rx_pdu_queue.push(std::move(p)); } void rrc::set_activity_user(uint16_t rnti) { - rrc_pdu p = {rnti, LCID_ACT_USER, NULL}; + rrc_pdu p = {rnti, LCID_ACT_USER, nullptr}; rx_pdu_queue.push(std::move(p)); } void rrc::rem_user_thread(uint16_t rnti) { - rrc_pdu p = {rnti, LCID_REM_USER, NULL}; + rrc_pdu p = {rnti, LCID_REM_USER, nullptr}; rx_pdu_queue.push(std::move(p)); } -uint32_t rrc::get_nof_users() { +uint32_t rrc::get_nof_users() +{ return users.size(); } template -void rrc::log_rrc_message(const std::string& source, const direction_t dir, const srslte::byte_buffer_t* pdu, - const T& msg) +void rrc::log_rrc_message(const std::string& source, + const direction_t dir, + const srslte::byte_buffer_t* pdu, + const T& msg) { if (rrc_log->get_level() == srslte::LOG_LEVEL_INFO) { - rrc_log->info("%s - %s %s (%d B)\n", source.c_str(), dir == Tx ? "Tx" : "Rx", - msg.msg.c1().type().to_string().c_str(), pdu->N_bytes); + rrc_log->info("%s - %s %s (%d B)\n", + source.c_str(), + dir == Tx ? "Tx" : "Rx", + msg.msg.c1().type().to_string().c_str(), + pdu->N_bytes); } else if (rrc_log->get_level() >= srslte::LOG_LEVEL_DEBUG) { asn1::json_writer json_writer; msg.to_json(json_writer); - rrc_log->debug_hex(pdu->msg, pdu->N_bytes, "%s - %s %s (%d B)\n", source.c_str(), dir == Tx ? "Tx" : "Rx", - msg.msg.c1().type().to_string().c_str(), pdu->N_bytes); + rrc_log->debug_hex(pdu->msg, + pdu->N_bytes, + "%s - %s %s (%d B)\n", + source.c_str(), + dir == Tx ? "Tx" : "Rx", + msg.msg.c1().type().to_string().c_str(), + pdu->N_bytes); rrc_log->debug("Content:\n%s\n", json_writer.to_string().c_str()); } } -void rrc::max_retx_attempted(uint16_t rnti) -{ - -} +void rrc::max_retx_attempted(uint16_t rnti) {} // This function is called from PRACH worker (can wait) void rrc::add_user(uint16_t rnti) @@ -218,18 +225,16 @@ void rrc::add_user(uint16_t rnti) } if (rnti == SRSLTE_MRNTI) { - srslte::pdcp_config_t pdcp_cfg = {.bearer_id = 1, - .rb_type = srslte::PDCP_RB_IS_DRB, - .tx_direction = srslte::SECURITY_DIRECTION_DOWNLINK, - .rx_direction = srslte::SECURITY_DIRECTION_UPLINK, - .sn_len = srslte::PDCP_SN_LEN_12, - .t_reorderding = srslte::pdcp_t_reordering_t::ms500}; - - uint32_t teid_in = 1; - - for (uint32_t i = 0; i < mcch.msg.c1().mbsfn_area_cfg_r9().pmch_info_list_r9[0].mbms_session_info_list_r9.size(); - i++) { - uint32_t lcid = mcch.msg.c1().mbsfn_area_cfg_r9().pmch_info_list_r9[0].mbms_session_info_list_r9[i].lc_ch_id_r9; + srslte::pdcp_config_t pdcp_cfg{1, + srslte::PDCP_RB_IS_DRB, + srslte::SECURITY_DIRECTION_DOWNLINK, + srslte::SECURITY_DIRECTION_UPLINK, + srslte::PDCP_SN_LEN_12, + srslte::pdcp_t_reordering_t::ms500}; + uint32_t teid_in = 1; + + for (auto& mbms_item : mcch.msg.c1().mbsfn_area_cfg_r9().pmch_info_list_r9[0].mbms_session_info_list_r9) { + uint32_t lcid = mbms_item.lc_ch_id_r9; rlc->add_bearer_mrb(SRSLTE_MRNTI, lcid); pdcp->add_bearer(SRSLTE_MRNTI, lcid, pdcp_cfg); gtpu->add_bearer(SRSLTE_MRNTI, lcid, 1, 1, &teid_in); @@ -261,8 +266,6 @@ void rrc::upd_user(uint16_t new_rnti, uint16_t old_rnti) pthread_mutex_unlock(&user_mutex); } - - /******************************************************************************* PDCP interface *******************************************************************************/ @@ -288,11 +291,12 @@ void rrc::write_dl_info(uint16_t rnti, srslte::unique_byte_buffer_t sdu) dl_info_transfer_r8_ies_s* dl_info_r8 = &msg_c1->set_dl_info_transfer().crit_exts.set_c1().set_dl_info_transfer_r8(); // msg_c1->dl_info_transfer().rrc_transaction_id = ; - dl_info_r8->non_crit_ext_present = false; + dl_info_r8->non_crit_ext_present = false; dl_info_r8->ded_info_type.set_ded_info_nas(); dl_info_r8->ded_info_type.ded_info_nas().resize(sdu->N_bytes); memcpy(msg_c1->dl_info_transfer().crit_exts.c1().dl_info_transfer_r8().ded_info_type.ded_info_nas().data(), - sdu->msg, sdu->N_bytes); + sdu->msg, + sdu->N_bytes); sdu->clear(); @@ -304,12 +308,13 @@ void rrc::write_dl_info(uint16_t rnti, srslte::unique_byte_buffer_t sdu) pthread_mutex_unlock(&user_mutex); } -void rrc::release_complete(uint16_t rnti) { - rrc_pdu p = {rnti, LCID_REL_USER, NULL}; +void rrc::release_complete(uint16_t rnti) +{ + rrc_pdu p = {rnti, LCID_REL_USER, nullptr}; rx_pdu_queue.push(std::move(p)); } -bool rrc::setup_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPREQUEST_STRUCT *msg) +bool rrc::setup_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPREQUEST_STRUCT* msg) { pthread_mutex_lock(&user_mutex); @@ -322,40 +327,40 @@ bool rrc::setup_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRE return false; } - if(msg->AdditionalCSFallbackIndicator_present) { + if (msg->AdditionalCSFallbackIndicator_present) { rrc_log->warning("Not handling AdditionalCSFallbackIndicator\n"); } - if(msg->CSGMembershipStatus_present) { + if (msg->CSGMembershipStatus_present) { rrc_log->warning("Not handling CSGMembershipStatus\n"); } - if(msg->GUMMEI_ID_present) { + if (msg->GUMMEI_ID_present) { rrc_log->warning("Not handling GUMMEI_ID\n"); } - if(msg->HandoverRestrictionList_present) { + if (msg->HandoverRestrictionList_present) { rrc_log->warning("Not handling HandoverRestrictionList\n"); } - if(msg->ManagementBasedMDTAllowed_present) { + if (msg->ManagementBasedMDTAllowed_present) { rrc_log->warning("Not handling ManagementBasedMDTAllowed\n"); } - if(msg->ManagementBasedMDTPLMNList_present) { + if (msg->ManagementBasedMDTPLMNList_present) { rrc_log->warning("Not handling ManagementBasedMDTPLMNList\n"); } - if(msg->MME_UE_S1AP_ID_2_present) { + if (msg->MME_UE_S1AP_ID_2_present) { rrc_log->warning("Not handling MME_UE_S1AP_ID_2\n"); } - if(msg->RegisteredLAI_present) { + if (msg->RegisteredLAI_present) { rrc_log->warning("Not handling RegisteredLAI\n"); } - if(msg->SRVCCOperationPossible_present) { + if (msg->SRVCCOperationPossible_present) { rrc_log->warning("Not handling SRVCCOperationPossible\n"); } - if(msg->SubscriberProfileIDforRFP_present) { + if (msg->SubscriberProfileIDforRFP_present) { rrc_log->warning("Not handling SubscriberProfileIDforRFP\n"); } - if(msg->TraceActivation_present) { + if (msg->TraceActivation_present) { rrc_log->warning("Not handling TraceActivation\n"); } - if(msg->UERadioCapability_present) { + if (msg->UERadioCapability_present) { rrc_log->warning("Not handling UERadioCapability\n"); } @@ -389,7 +394,7 @@ bool rrc::setup_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRE return true; } -bool rrc::modify_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_UECONTEXTMODIFICATIONREQUEST_STRUCT *msg) +bool rrc::modify_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_UECONTEXTMODIFICATIONREQUEST_STRUCT* msg) { bool err = false; pthread_mutex_lock(&user_mutex); @@ -459,8 +464,7 @@ bool rrc::modify_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_UECONTEXTMODIFICATIO return true; } - -bool rrc::setup_ue_erabs(uint16_t rnti, LIBLTE_S1AP_MESSAGE_E_RABSETUPREQUEST_STRUCT *msg) +bool rrc::setup_ue_erabs(uint16_t rnti, LIBLTE_S1AP_MESSAGE_E_RABSETUPREQUEST_STRUCT* msg) { pthread_mutex_lock(&user_mutex); @@ -509,7 +513,7 @@ bool rrc::release_erabs(uint32_t rnti) than user map *******************************************************************************/ -void rrc::add_paging_id(uint32_t ueid, LIBLTE_S1AP_UEPAGINGID_STRUCT UEPagingID) +void rrc::add_paging_id(uint32_t ueid, LIBLTE_S1AP_UEPAGINGID_STRUCT UEPagingID) { pthread_mutex_lock(&paging_mutex); if (pending_paging.count(ueid) == 0) { @@ -521,12 +525,12 @@ void rrc::add_paging_id(uint32_t ueid, LIBLTE_S1AP_UEPAGINGID_STRUCT UEPagingID) } // Described in Section 7 of 36.304 -bool rrc::is_paging_opportunity(uint32_t tti, uint32_t *payload_len) +bool rrc::is_paging_opportunity(uint32_t tti, uint32_t* payload_len) { int sf_pattern[4][4] = {{9, 4, -1, 0}, {-1, 9, -1, 4}, {-1, -1, -1, 5}, {-1, -1, -1, 9}}; - + if (pending_paging.empty()) { - return false; + return false; } pthread_mutex_lock(&paging_mutex); @@ -539,15 +543,14 @@ bool rrc::is_paging_opportunity(uint32_t tti, uint32_t *payload_len) uint32_t T = cfg.sibs[1].sib2().rr_cfg_common.pcch_cfg.default_paging_cycle.to_number(); uint32_t Nb = T * cfg.sibs[1].sib2().rr_cfg_common.pcch_cfg.nb; - uint32_t N = T1?Nb/T:1; - uint32_t sfn = tti/10; - + uint32_t N = T < Nb ? T : Nb; + uint32_t Ns = Nb / T > 1 ? Nb / T : 1; + uint32_t sfn = tti / 10; + std::vector ue_to_remove; int n = 0; - for (std::map::iterator iter = pending_paging.begin(); - n < ASN1_RRC_MAX_PAGE_REC && iter != pending_paging.end(); ++iter) { + for (auto iter = pending_paging.begin(); n < ASN1_RRC_MAX_PAGE_REC && iter != pending_paging.end(); ++iter) { LIBLTE_S1AP_UEPAGINGID_STRUCT u = (LIBLTE_S1AP_UEPAGINGID_STRUCT)iter->second; uint32_t ueid = ((uint32_t)iter->first) % 1024; uint32_t i_s = (ueid / N) % Ns; @@ -571,7 +574,7 @@ bool rrc::is_paging_opportunity(uint32_t tti, uint32_t *payload_len) paging_elem.ue_id.s_tmsi().mmec.from_number(u.choice.s_TMSI.mMEC.buffer[0]); uint32_t m_tmsi = 0; for (int i = 0; i < LIBLTE_S1AP_M_TMSI_OCTET_STRING_LEN; i++) { - m_tmsi |= u.choice.s_TMSI.m_TMSI.buffer[i] << (8 * (LIBLTE_S1AP_M_TMSI_OCTET_STRING_LEN - i - 1)); + m_tmsi |= u.choice.s_TMSI.m_TMSI.buffer[i] << (8u * (LIBLTE_S1AP_M_TMSI_OCTET_STRING_LEN - i - 1)); } paging_elem.ue_id.s_tmsi().m_tmsi.from_number(m_tmsi); } @@ -601,7 +604,9 @@ bool rrc::is_paging_opportunity(uint32_t tti, uint32_t *payload_len) *payload_len = byte_buf_paging.N_bytes; } rrc_log->info("Assembling PCCH payload with %d UE identities, payload_len=%d bytes, nbits=%d\n", - paging_rec->paging_record_list.size(), byte_buf_paging.N_bytes, N_bits); + paging_rec->paging_record_list.size(), + byte_buf_paging.N_bytes, + N_bits); log_rrc_message("PCCH-Message", Tx, &byte_buf_paging, pcch_msg); return true; @@ -627,7 +632,7 @@ void rrc::read_pdu_pcch(uint8_t* payload, uint32_t buffer_size) void rrc::parse_ul_ccch(uint16_t rnti, srslte::unique_byte_buffer_t pdu) { - uint16_t old_rnti = 0; + uint16_t old_rnti = 0; if (pdu) { ul_ccch_msg_s ul_ccch_msg; @@ -757,7 +762,7 @@ void rrc::rem_user(uint16_t rnti) /* First remove MAC and GTPU to stop processing DL/UL traffic for this user */ - mac->ue_rem(rnti); // MAC handles PHY + mac->ue_rem(rnti); // MAC handles PHY gtpu->rem_user(rnti); // Now remove RLC and PDCP @@ -781,7 +786,7 @@ void rrc::config_mac() // Fill MAC scheduler configuration for SIBs sched_interface::cell_cfg_t sched_cfg; bzero(&sched_cfg, sizeof(sched_interface::cell_cfg_t)); - for (uint32_t i=0;iN_bytes; if (i == 0) { sched_cfg.sibs[i].period_rf = 8; // SIB1 is always 8 rf @@ -789,13 +794,14 @@ void rrc::config_mac() sched_cfg.sibs[i].period_rf = cfg.sib1.sched_info_list[i - 1].si_periodicity.to_number(); } } - sched_cfg.prach_config = cfg.sibs[1].sib2().rr_cfg_common.prach_cfg.prach_cfg_info.prach_cfg_idx; - sched_cfg.prach_nof_preambles = cfg.sibs[1].sib2().rr_cfg_common.rach_cfg_common.preamb_info.nof_ra_preambs.to_number(); - sched_cfg.si_window_ms = cfg.sib1.si_win_len.to_number(); - sched_cfg.prach_rar_window = + sched_cfg.prach_config = cfg.sibs[1].sib2().rr_cfg_common.prach_cfg.prach_cfg_info.prach_cfg_idx; + sched_cfg.prach_nof_preambles = + cfg.sibs[1].sib2().rr_cfg_common.rach_cfg_common.preamb_info.nof_ra_preambs.to_number(); + sched_cfg.si_window_ms = cfg.sib1.si_win_len.to_number(); + sched_cfg.prach_rar_window = cfg.sibs[1].sib2().rr_cfg_common.rach_cfg_common.ra_supervision_info.ra_resp_win_size.to_number(); - sched_cfg.prach_freq_offset = cfg.sibs[1].sib2().rr_cfg_common.prach_cfg.prach_cfg_info.prach_freq_offset; - sched_cfg.maxharq_msg3tx = cfg.sibs[1].sib2().rr_cfg_common.rach_cfg_common.max_harq_msg3_tx; + sched_cfg.prach_freq_offset = cfg.sibs[1].sib2().rr_cfg_common.prach_cfg.prach_cfg_info.prach_freq_offset; + sched_cfg.maxharq_msg3tx = cfg.sibs[1].sib2().rr_cfg_common.rach_cfg_common.max_harq_msg3_tx; sched_cfg.nrb_pucch = SRSLTE_MAX(cfg.sr_cfg.nof_prb, cfg.cqi_cfg.nof_prb); rrc_log->info("Allocating %d PRBs for PUCCH\n", sched_cfg.nrb_pucch); @@ -836,16 +842,16 @@ uint32_t rrc::generate_sibs() } // Add other SIBs to this message, if any - for (uint32_t mapping = 0; mapping < sched_info[sched_info_elem].sib_map_info.size(); mapping++) { - sib_list.push_back(cfg.sibs[(int)sched_info[sched_info_elem].sib_map_info[mapping] + 2]); + for (auto& mapping_enum : sched_info[sched_info_elem].sib_map_info) { + sib_list.push_back(cfg.sibs[(int)mapping_enum + 2]); } } // Pack payload for all messages for (uint32_t msg_index = 0; msg_index < nof_messages; msg_index++) { srslte::unique_byte_buffer_t sib = srslte::allocate_unique_buffer(*pool); - asn1::bit_ref bref(sib->msg, sib->get_tailroom()); - asn1::bit_ref bref0 = bref; + asn1::bit_ref bref(sib->msg, sib->get_tailroom()); + asn1::bit_ref bref0 = bref; msg[msg_index].pack(bref); sib->N_bytes = static_cast((bref.distance(bref0) - 1) / 8 + 1); sib_buffer.push_back(std::move(sib)); @@ -861,7 +867,7 @@ uint32_t rrc::generate_sibs() return nof_messages; } -void rrc::configure_mbsfn_sibs(sib_type2_s* sib2, sib_type13_r9_s* sib13) +void rrc::configure_mbsfn_sibs(sib_type2_s* sib2_, sib_type13_r9_s* sib13_) { // Temp assignment of MCCH, this will eventually come from a cfg file mcch.msg.set_c1(); @@ -894,23 +900,24 @@ void rrc::configure_mbsfn_sibs(sib_type2_s* sib2, sib_type13_r9_s* sib13) pmch_item->mbms_session_info_list_r9[1].tmgi_r9.plmn_id_r9.set_explicit_value_r9() = pmch_item->mbms_session_info_list_r9[0].tmgi_r9.plmn_id_r9.explicit_value_r9(); byte[2] = 1; - memcpy(&pmch_item->mbms_session_info_list_r9[1].tmgi_r9.service_id_r9[0], &byte[0], + memcpy(&pmch_item->mbms_session_info_list_r9[1].tmgi_r9.service_id_r9[0], + &byte[0], 3); // FIXME: Check if service is set to 1 } pmch_item->pmch_cfg_r9.data_mcs_r9 = 20; pmch_item->pmch_cfg_r9.mch_sched_period_r9 = pmch_cfg_r9_s::mch_sched_period_r9_e_::rf64; pmch_item->pmch_cfg_r9.sf_alloc_end_r9 = 64 * 6; - phy->configure_mbsfn(sib2, sib13, mcch); - mac->write_mcch(sib2, sib13, &mcch); + phy->configure_mbsfn(sib2_, sib13_, mcch); + mac->write_mcch(sib2_, sib13_, &mcch); } -void rrc::configure_security(uint16_t rnti, - uint32_t lcid, - uint8_t *k_rrc_enc, - uint8_t *k_rrc_int, - uint8_t *k_up_enc, - uint8_t *k_up_int, +void rrc::configure_security(uint16_t rnti, + uint32_t lcid, + uint8_t* k_rrc_enc, + uint8_t* k_rrc_int, + uint8_t* k_up_enc, + uint8_t* k_up_int, srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo, srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo) { @@ -937,7 +944,7 @@ void rrc::run_thread() rrc_pdu p; running = true; - while(running) { + while (running) { p = rx_pdu_queue.wait_pop(); if (p.pdu) { rrc_log->info_hex(p.pdu->msg, p.pdu->N_bytes, "Rx %s PDU", rb_id_text[p.lcid]); @@ -979,8 +986,6 @@ void rrc::run_thread() } } - - /******************************************************************************* Activity monitor class *******************************************************************************/ @@ -988,7 +993,7 @@ void rrc::run_thread() rrc::activity_monitor::activity_monitor(rrc* parent_) : thread("RRC_ACTIVITY_MONITOR") { running = true; - parent = parent_; + parent = parent_; } void rrc::activity_monitor::stop() @@ -1002,15 +1007,14 @@ void rrc::activity_monitor::stop() void rrc::activity_monitor::run_thread() { - while(running) - { + while (running) { usleep(10000); pthread_mutex_lock(&parent->user_mutex); uint16_t rem_rnti = 0; - for(std::map::iterator iter=parent->users.begin(); rem_rnti == 0 && iter!=parent->users.end(); ++iter) { - if(iter->first != SRSLTE_MRNTI){ - ue *u = (ue*) &iter->second; - uint16_t rnti = (uint16_t) iter->first; + for (auto iter = parent->users.begin(); rem_rnti == 0 && iter != parent->users.end(); ++iter) { + if (iter->first != SRSLTE_MRNTI) { + ue* u = (ue*)&iter->second; + uint16_t rnti = (uint16_t)iter->first; if (parent->cnotifier && u->is_connected() && !u->connect_notified) { parent->cnotifier->user_connected(rnti); @@ -1018,7 +1022,8 @@ void rrc::activity_monitor::run_thread() } if (u->is_timeout()) { - parent->rrc_log->info("User rnti=0x%x timed out. Exists in s1ap=%s\n", rnti, parent->s1ap->user_exists(rnti)?"yes":"no"); + parent->rrc_log->info( + "User rnti=0x%x timed out. Exists in s1ap=%s\n", rnti, parent->s1ap->user_exists(rnti) ? "yes" : "no"); rem_rnti = rnti; } } @@ -1027,7 +1032,7 @@ void rrc::activity_monitor::run_thread() if (parent->s1ap->user_exists(rem_rnti)) { parent->s1ap->user_release(rem_rnti, LIBLTE_S1AP_CAUSERADIONETWORK_USER_INACTIVITY); } else { - if(rem_rnti != SRSLTE_MRNTI) + if (rem_rnti != SRSLTE_MRNTI) parent->rem_user_thread(rem_rnti); } } @@ -1048,26 +1053,9 @@ rrc::ue::ue(rrc* outer_rrc, uint16_t rnti_) : pool(srslte::byte_buffer_pool::get_instance()) { set_activity(); - has_tmsi = false; - connect_notified = false; - transaction_id = 0; - sr_allocated = false; - sr_sched_sf_idx = 0; - sr_sched_prb_idx = 0; - sr_N_pucch = 0; - sr_I = 0; - cqi_allocated = false; - cqi_pucch = 0; - cqi_idx = 0; - cqi_sched_sf_idx = 0; - cqi_sched_prb_idx = 0; - rlf_cnt = 0; - integ_algo = srslte::INTEGRITY_ALGORITHM_ID_EIA0; - cipher_algo = srslte::CIPHERING_ALGORITHM_ID_EEA0; - nas_pending = false; - is_csfb = false; - state = RRC_STATE_IDLE; - gettimeofday(&t_ue_init, NULL); + integ_algo = srslte::INTEGRITY_ALGORITHM_ID_EIA0; + cipher_algo = srslte::CIPHERING_ALGORITHM_ID_EEA0; + gettimeofday(&t_ue_init, nullptr); mobility_handler.reset(new rrc_mobility(this)); } @@ -1076,14 +1064,15 @@ rrc_state_t rrc::ue::get_state() return state; } -uint32_t rrc::ue::rl_failure() { +uint32_t rrc::ue::rl_failure() +{ rlf_cnt++; return rlf_cnt; } -void rrc::ue::set_activity() +void rrc::ue::set_activity() { - gettimeofday(&t_last_activity, NULL); + gettimeofday(&t_last_activity, nullptr); if (parent) { if (parent->rrc_log) { parent->rrc_log->debug("Activity registered rnti=0x%x\n", rnti); @@ -1091,31 +1080,33 @@ void rrc::ue::set_activity() } } -bool rrc::ue::is_connected() { +bool rrc::ue::is_connected() +{ return state == RRC_STATE_REGISTERED; } -bool rrc::ue::is_idle() { +bool rrc::ue::is_idle() +{ return state == RRC_STATE_IDLE; } -bool rrc::ue::is_timeout() +bool rrc::ue::is_timeout() { if (!parent) { - return false; + return false; } - - struct timeval t[3]; - uint32_t deadline_s = 0; - uint32_t deadline_us = 0; - const char *deadline_str = NULL; + + struct timeval t[3]; + uint32_t deadline_s = 0; + uint32_t deadline_us = 0; + const char* deadline_str = nullptr; memcpy(&t[1], &t_last_activity, sizeof(struct timeval)); - gettimeofday(&t[2], NULL); + gettimeofday(&t[2], nullptr); get_time_interval(t); - switch(state) { - case RRC_STATE_IDLE: - deadline_s = 0; + switch (state) { + case RRC_STATE_IDLE: + deadline_s = 0; deadline_us = static_cast((parent->sib2.rr_cfg_common.rach_cfg_common.max_harq_msg3_tx + 1) * 16 * 1000); deadline_str = "RRCConnectionSetup"; @@ -1131,26 +1122,29 @@ bool rrc::ue::is_timeout() deadline_str = "RRCReleaseRequest"; break; default: - deadline_s = parent->cfg.inactivity_timeout_ms/1000; - deadline_us = (parent->cfg.inactivity_timeout_ms%1000)*1000; + deadline_s = parent->cfg.inactivity_timeout_ms / 1000; + deadline_us = (parent->cfg.inactivity_timeout_ms % 1000) * 1000; deadline_str = "Activity"; - break; + break; } - + if (deadline_str) { - int64_t deadline = deadline_s*1e6 + deadline_us; - int64_t elapsed = t[0].tv_sec*1e6 + t[0].tv_usec; + int64_t deadline = deadline_s * 1e6 + deadline_us; + int64_t elapsed = t[0].tv_sec * 1e6 + t[0].tv_usec; if (elapsed > deadline && elapsed > 0) { - parent->rrc_log->warning("User rnti=0x%x expired %s deadline: %ld:%ld>%d:%d us\n", - rnti, deadline_str, - t[0].tv_sec, t[0].tv_usec, - deadline_s, deadline_us); + parent->rrc_log->warning("User rnti=0x%x expired %s deadline: %ld:%ld>%d:%d us\n", + rnti, + deadline_str, + t[0].tv_sec, + t[0].tv_usec, + deadline_s, + deadline_us); memcpy(&t_last_activity, &t[2], sizeof(struct timeval)); state = RRC_STATE_RELEASE_REQUEST; - return true; + return true; } } - return false; + return false; } void rrc::ue::parse_ul_dcch(uint32_t lcid, srslte::unique_byte_buffer_t pdu) @@ -1246,9 +1240,8 @@ void rrc::ue::handle_rrc_con_req(rrc_conn_request_s* msg) void rrc::ue::handle_rrc_con_reest_req(rrc_conn_reest_request_r8_ies_s* msg) { - //TODO: Check Short-MAC-I value + // TODO: Check Short-MAC-I value parent->rrc_log->error("Not Supported: ConnectionReestablishment. \n"); - } void rrc::ue::handle_rrc_con_setup_complete(rrc_conn_setup_complete_s* msg, srslte::unique_byte_buffer_t pdu) @@ -1265,7 +1258,7 @@ void rrc::ue::handle_rrc_con_setup_complete(rrc_conn_setup_complete_s* msg, srsl // Acknowledge Dedicated Configuration parent->mac->phy_config_enabled(rnti, true); - if(has_tmsi) { + if (has_tmsi) { parent->s1ap->initial_ue( rnti, (LIBLTE_S1AP_RRC_ESTABLISHMENT_CAUSE_ENUM)establishment_cause.value, std::move(pdu), m_tmsi, mmec); } else { @@ -1321,12 +1314,12 @@ bool rrc::ue::handle_ue_cap_info(ue_cap_info_s* msg) // parent->s1ap->ue_capabilities(rnti, &eutra_capabilities); } -void rrc::ue::set_bitrates(LIBLTE_S1AP_UEAGGREGATEMAXIMUMBITRATE_STRUCT *rates) +void rrc::ue::set_bitrates(LIBLTE_S1AP_UEAGGREGATEMAXIMUMBITRATE_STRUCT* rates) { memcpy(&bitrates, rates, sizeof(LIBLTE_S1AP_UEAGGREGATEMAXIMUMBITRATE_STRUCT)); } -void rrc::ue::set_security_capabilities(LIBLTE_S1AP_UESECURITYCAPABILITIES_STRUCT *caps) +void rrc::ue::set_security_capabilities(LIBLTE_S1AP_UESECURITYCAPABILITIES_STRUCT* caps) { memcpy(&security_capabilities, caps, sizeof(LIBLTE_S1AP_UESECURITYCAPABILITIES_STRUCT)); } @@ -1335,25 +1328,18 @@ void rrc::ue::set_security_key(uint8_t* key, uint32_t length) { memcpy(k_enb, key, length); parent->rrc_log->info_hex(k_enb, 32, "Key eNodeB (k_enb)"); - // Selects security algorithms (cipher_algo and integ_algo) based on capabilities and config preferences + // Selects security algorithms (cipher_algo and integ_algo) based on capabilities and config preferences select_security_algorithms(); parent->rrc_log->info("Selected security algorithms EEA: EEA%d EIA: EIA%d\n", cipher_algo, integ_algo); - + // Generate K_rrc_enc and K_rrc_int srslte::security_generate_k_rrc(k_enb, cipher_algo, integ_algo, k_rrc_enc, k_rrc_int); // Generate K_up_enc and K_up_int - security_generate_k_up( k_enb, - cipher_algo, - integ_algo, - k_up_enc, - k_up_int); + security_generate_k_up(k_enb, cipher_algo, integ_algo, k_up_enc, k_up_int); - parent->configure_security(rnti, RB_ID_SRB1, - k_rrc_enc, k_rrc_int, - k_up_enc, k_up_int, - cipher_algo, integ_algo); + parent->configure_security(rnti, RB_ID_SRB1, k_rrc_enc, k_rrc_int, k_up_enc, k_up_int, cipher_algo, integ_algo); parent->enable_integrity(rnti, RB_ID_SRB1); @@ -1362,49 +1348,52 @@ void rrc::ue::set_security_key(uint8_t* key, uint32_t length) parent->rrc_log->info_hex(k_up_enc, 32, "UP Encryption Key (k_up_enc)"); } -bool rrc::ue::setup_erabs(LIBLTE_S1AP_E_RABTOBESETUPLISTCTXTSUREQ_STRUCT *e) +bool rrc::ue::setup_erabs(LIBLTE_S1AP_E_RABTOBESETUPLISTCTXTSUREQ_STRUCT* e) { - for(uint32_t i=0; ilen; i++) { - LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT *erab = &e->buffer[i]; - if(erab->ext) { + for (uint32_t i = 0; i < e->len; i++) { + LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT* erab = &e->buffer[i]; + if (erab->ext) { parent->rrc_log->warning("Not handling LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT extensions\n"); } - if(erab->iE_Extensions_present) { + if (erab->iE_Extensions_present) { parent->rrc_log->warning("Not handling LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT extensions\n"); } - if(erab->transportLayerAddress.n_bits > 32) { + if (erab->transportLayerAddress.n_bits > 32) { parent->rrc_log->error("IPv6 addresses not currently supported\n"); return false; } uint32_t teid_out; uint8_to_uint32(erab->gTP_TEID.buffer, &teid_out); - LIBLTE_S1AP_NAS_PDU_STRUCT *nas_pdu = erab->nAS_PDU_present ? &erab->nAS_PDU : NULL; - setup_erab(erab->e_RAB_ID.E_RAB_ID, &erab->e_RABlevelQoSParameters, - &erab->transportLayerAddress, teid_out, nas_pdu); + LIBLTE_S1AP_NAS_PDU_STRUCT* nas_pdu = erab->nAS_PDU_present ? &erab->nAS_PDU : nullptr; + setup_erab( + erab->e_RAB_ID.E_RAB_ID, &erab->e_RABlevelQoSParameters, &erab->transportLayerAddress, teid_out, nas_pdu); } return true; } -bool rrc::ue::setup_erabs(LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT *e) +bool rrc::ue::setup_erabs(LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT* e) { - for(uint32_t i=0; ilen; i++) { - LIBLTE_S1AP_E_RABTOBESETUPITEMBEARERSUREQ_STRUCT *erab = &e->buffer[i]; - if(erab->ext) { + for (uint32_t i = 0; i < e->len; i++) { + LIBLTE_S1AP_E_RABTOBESETUPITEMBEARERSUREQ_STRUCT* erab = &e->buffer[i]; + if (erab->ext) { parent->rrc_log->warning("Not handling LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT extensions\n"); } - if(erab->iE_Extensions_present) { + if (erab->iE_Extensions_present) { parent->rrc_log->warning("Not handling LIBLTE_S1AP_E_RABTOBESETUPITEMCTXTSUREQ_STRUCT extensions\n"); } - if(erab->transportLayerAddress.n_bits > 32) { + if (erab->transportLayerAddress.n_bits > 32) { parent->rrc_log->error("IPv6 addresses not currently supported\n"); return false; } uint32_t teid_out; uint8_to_uint32(erab->gTP_TEID.buffer, &teid_out); - setup_erab(erab->e_RAB_ID.E_RAB_ID, &erab->e_RABlevelQoSParameters, - &erab->transportLayerAddress, teid_out, &erab->nAS_PDU); + setup_erab(erab->e_RAB_ID.E_RAB_ID, + &erab->e_RABlevelQoSParameters, + &erab->transportLayerAddress, + teid_out, + &erab->nAS_PDU); } // Work in progress @@ -1413,9 +1402,11 @@ bool rrc::ue::setup_erabs(LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT *e) return true; } -void rrc::ue::setup_erab(uint8_t id, LIBLTE_S1AP_E_RABLEVELQOSPARAMETERS_STRUCT *qos, - LIBLTE_S1AP_TRANSPORTLAYERADDRESS_STRUCT *addr, uint32_t teid_out, - LIBLTE_S1AP_NAS_PDU_STRUCT *nas_pdu) +void rrc::ue::setup_erab(uint8_t id, + LIBLTE_S1AP_E_RABLEVELQOSPARAMETERS_STRUCT* qos, + LIBLTE_S1AP_TRANSPORTLAYERADDRESS_STRUCT* addr, + uint32_t teid_out, + LIBLTE_S1AP_NAS_PDU_STRUCT* nas_pdu) { erabs[id].id = id; memcpy(&erabs[id].qos_params, qos, sizeof(LIBLTE_S1AP_E_RABLEVELQOSPARAMETERS_STRUCT)); @@ -1423,11 +1414,11 @@ void rrc::ue::setup_erab(uint8_t id, LIBLTE_S1AP_E_RABLEVELQOSPARAMETERS_STRUCT erabs[id].teid_out = teid_out; uint8_t* bit_ptr = addr->buffer; - uint32_t addr_ = liblte_bits_2_value(&bit_ptr, addr->n_bits); - uint8_t lcid = id - 2; // Map e.g. E-RAB 5 to LCID 3 (==DRB1) + uint32_t addr_ = liblte_bits_2_value(&bit_ptr, addr->n_bits); + uint8_t lcid = id - 2; // Map e.g. E-RAB 5 to LCID 3 (==DRB1) parent->gtpu->add_bearer(rnti, lcid, addr_, erabs[id].teid_out, &(erabs[id].teid_in)); - if(nas_pdu) { + if (nas_pdu) { nas_pending = true; memcpy(erab_info.buffer, nas_pdu->buffer, nas_pdu->n_octets); erab_info.N_bytes = nas_pdu->n_octets; @@ -1439,56 +1430,52 @@ void rrc::ue::setup_erab(uint8_t id, LIBLTE_S1AP_E_RABLEVELQOSPARAMETERS_STRUCT bool rrc::ue::release_erabs() { - typedef std::map::iterator it_t; - for(it_t it=erabs.begin(); it!=erabs.end(); ++it) { - // TODO: notify GTPU layer - } + // TODO: notify GTPU layer for each ERAB erabs.clear(); - return true; + return true; } void rrc::ue::notify_s1ap_ue_ctxt_setup_complete() { LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPRESPONSE_STRUCT res; - res.ext = false; + res.ext = false; res.E_RABFailedToSetupListCtxtSURes_present = false; - res.CriticalityDiagnostics_present = false; + res.CriticalityDiagnostics_present = false; - res.E_RABSetupListCtxtSURes.len = 0; + res.E_RABSetupListCtxtSURes.len = 0; res.E_RABFailedToSetupListCtxtSURes.len = 0; - typedef std::map::iterator it_t; - for(it_t it=erabs.begin(); it!=erabs.end(); ++it) { - uint32_t j = res.E_RABSetupListCtxtSURes.len++; - res.E_RABSetupListCtxtSURes.buffer[j].ext = false; + for (auto& erab : erabs) { + uint32_t j = res.E_RABSetupListCtxtSURes.len++; + res.E_RABSetupListCtxtSURes.buffer[j].ext = false; res.E_RABSetupListCtxtSURes.buffer[j].iE_Extensions_present = false; - res.E_RABSetupListCtxtSURes.buffer[j].e_RAB_ID.ext = false; - res.E_RABSetupListCtxtSURes.buffer[j].e_RAB_ID.E_RAB_ID = it->second.id; - uint32_to_uint8(it->second.teid_in, res.E_RABSetupListCtxtSURes.buffer[j].gTP_TEID.buffer); + res.E_RABSetupListCtxtSURes.buffer[j].e_RAB_ID.ext = false; + res.E_RABSetupListCtxtSURes.buffer[j].e_RAB_ID.E_RAB_ID = erab.second.id; + uint32_to_uint8(erab.second.teid_in, res.E_RABSetupListCtxtSURes.buffer[j].gTP_TEID.buffer); } parent->s1ap->ue_ctxt_setup_complete(rnti, &res); } -void rrc::ue::notify_s1ap_ue_erab_setup_response(LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT *e) +void rrc::ue::notify_s1ap_ue_erab_setup_response(LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT* e) { LIBLTE_S1AP_MESSAGE_E_RABSETUPRESPONSE_STRUCT res; - res.ext=false; - res.E_RABSetupListBearerSURes.len = 0; + res.ext = false; + res.E_RABSetupListBearerSURes.len = 0; res.E_RABFailedToSetupListBearerSURes.len = 0; - res.CriticalityDiagnostics_present = false; + res.CriticalityDiagnostics_present = false; res.E_RABFailedToSetupListBearerSURes_present = false; - for(uint32_t i=0; ilen; i++) { - res.E_RABSetupListBearerSURes_present = true; - LIBLTE_S1AP_E_RABTOBESETUPITEMBEARERSUREQ_STRUCT *erab = &e->buffer[i]; - uint8_t id = erab->e_RAB_ID.E_RAB_ID; - uint32_t j = res.E_RABSetupListBearerSURes.len++; - res.E_RABSetupListBearerSURes.buffer[j].ext = false; + for (uint32_t i = 0; i < e->len; i++) { + res.E_RABSetupListBearerSURes_present = true; + LIBLTE_S1AP_E_RABTOBESETUPITEMBEARERSUREQ_STRUCT* erab = &e->buffer[i]; + uint8_t id = erab->e_RAB_ID.E_RAB_ID; + uint32_t j = res.E_RABSetupListBearerSURes.len++; + res.E_RABSetupListBearerSURes.buffer[j].ext = false; res.E_RABSetupListBearerSURes.buffer[j].iE_Extensions_present = false; - res.E_RABSetupListBearerSURes.buffer[j].e_RAB_ID.ext = false; - res.E_RABSetupListBearerSURes.buffer[j].e_RAB_ID.E_RAB_ID = id; + res.E_RABSetupListBearerSURes.buffer[j].e_RAB_ID.ext = false; + res.E_RABSetupListBearerSURes.buffer[j].e_RAB_ID.E_RAB_ID = id; uint32_to_uint8(erabs[id].teid_in, res.E_RABSetupListBearerSURes.buffer[j].gTP_TEID.buffer); } @@ -1518,7 +1505,7 @@ void rrc::ue::send_connection_setup(bool is_setup) dl_ccch_msg_s dl_ccch_msg; dl_ccch_msg.msg.set_c1(); - rr_cfg_ded_s* rr_cfg = NULL; + rr_cfg_ded_s* rr_cfg = nullptr; if (is_setup) { dl_ccch_msg.msg.c1().set_rrc_conn_setup(); dl_ccch_msg.msg.c1().rrc_conn_setup().rrc_transaction_id = (uint8_t)((transaction_id++) % 4); @@ -1541,7 +1528,7 @@ void rrc::ue::send_connection_setup(bool is_setup) rr_cfg->srb_to_add_mod_list[0].rlc_cfg.set(srb_to_add_mod_s::rlc_cfg_c_::types::default_value); // mac-MainConfig - rr_cfg->mac_main_cfg_present = true; + rr_cfg->mac_main_cfg_present = true; mac_main_cfg_s* mac_cfg = &rr_cfg->mac_main_cfg.set_explicit_value(); mac_cfg->ul_sch_cfg_present = true; mac_cfg->ul_sch_cfg = parent->cfg.mac_cnfg.ul_sch_cfg; @@ -1569,18 +1556,19 @@ void rrc::ue::send_connection_setup(bool is_setup) phy_cfg->ant_info.explicit_value().ue_tx_ant_sel.set(setup_e::release); if (is_setup) { - if (sr_allocate(parent->cfg.sr_cfg.period, &phy_cfg->sched_request_cfg.setup().sr_cfg_idx, + if (sr_allocate(parent->cfg.sr_cfg.period, + &phy_cfg->sched_request_cfg.setup().sr_cfg_idx, &phy_cfg->sched_request_cfg.setup().sr_pucch_res_idx)) { parent->rrc_log->error("Allocating SR resources for rnti=%d\n", rnti); - return; + return; } } else { phy_cfg->sched_request_cfg.setup().sr_cfg_idx = (uint8_t)sr_I; phy_cfg->sched_request_cfg.setup().sr_pucch_res_idx = (uint16_t)sr_N_pucch; } - // Power control - phy_cfg->ul_pwr_ctrl_ded_present = true; - phy_cfg->ul_pwr_ctrl_ded.p0_ue_pusch = 0; + // Power control + phy_cfg->ul_pwr_ctrl_ded_present = true; + phy_cfg->ul_pwr_ctrl_ded.p0_ue_pusch = 0; phy_cfg->ul_pwr_ctrl_ded.delta_mcs_enabled = ul_pwr_ctrl_ded_s::delta_mcs_enabled_e_::en0; phy_cfg->ul_pwr_ctrl_ded.accumulation_enabled = true; phy_cfg->ul_pwr_ctrl_ded.p0_ue_pucch = 0, phy_cfg->ul_pwr_ctrl_ded.p_srs_offset = 3; @@ -1594,7 +1582,7 @@ void rrc::ue::send_connection_setup(bool is_setup) phy_cfg->pucch_cfg_ded.ack_nack_repeat.set(pucch_cfg_ded_s::ack_nack_repeat_c_::types::release); phy_cfg->cqi_report_cfg_present = true; - if(parent->cfg.cqi_cfg.mode == RRC_CFG_CQI_MODE_APERIODIC) { + if (parent->cfg.cqi_cfg.mode == RRC_CFG_CQI_MODE_APERIODIC) { phy_cfg->cqi_report_cfg.cqi_report_mode_aperiodic_present = true; phy_cfg->cqi_report_cfg.cqi_report_mode_aperiodic = cqi_report_mode_aperiodic_e::rm30; } else { @@ -1604,10 +1592,11 @@ void rrc::ue::send_connection_setup(bool is_setup) cqi_report_periodic_c::setup_s_::cqi_format_ind_periodic_c_::types::wideband_cqi); phy_cfg->cqi_report_cfg.cqi_report_periodic.setup().simul_ack_nack_and_cqi = false; if (is_setup) { - if (cqi_allocate(parent->cfg.cqi_cfg.period, &phy_cfg->cqi_report_cfg.cqi_report_periodic.setup().cqi_pmi_cfg_idx, + if (cqi_allocate(parent->cfg.cqi_cfg.period, + &phy_cfg->cqi_report_cfg.cqi_report_periodic.setup().cqi_pmi_cfg_idx, &phy_cfg->cqi_report_cfg.cqi_report_periodic.setup().cqi_pucch_res_idx)) { parent->rrc_log->error("Allocating CQI resources for rnti=%d\n", rnti); - return; + return; } } else { phy_cfg->cqi_report_cfg.cqi_report_periodic.setup().cqi_pucch_res_idx = (uint16_t)cqi_pucch; @@ -1616,12 +1605,13 @@ void rrc::ue::send_connection_setup(bool is_setup) } phy_cfg->cqi_report_cfg.nom_pdsch_rs_epre_offset = 0; - // Add SRB1 to Scheduler - srsenb::sched_interface::ue_cfg_t sched_cfg; + // Add SRB1 to Scheduler + srsenb::sched_interface::ue_cfg_t sched_cfg; bzero(&sched_cfg, sizeof(srsenb::sched_interface::ue_cfg_t)); - sched_cfg.maxharq_tx = parent->cfg.mac_cnfg.ul_sch_cfg.max_harq_tx.to_number(); - sched_cfg.continuous_pusch = false; - sched_cfg.aperiodic_cqi_period = parent->cfg.cqi_cfg.mode == RRC_CFG_CQI_MODE_APERIODIC?parent->cfg.cqi_cfg.period:0; + sched_cfg.maxharq_tx = parent->cfg.mac_cnfg.ul_sch_cfg.max_harq_tx.to_number(); + sched_cfg.continuous_pusch = false; + sched_cfg.aperiodic_cqi_period = + parent->cfg.cqi_cfg.mode == RRC_CFG_CQI_MODE_APERIODIC ? parent->cfg.cqi_cfg.period : 0; sched_cfg.ue_bearers[0].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; sched_cfg.ue_bearers[1].direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; if (parent->cfg.cqi_cfg.mode == RRC_CFG_CQI_MODE_APERIODIC) { @@ -1640,19 +1630,19 @@ void rrc::ue::send_connection_setup(bool is_setup) sched_cfg.pucch_cfg.n_rb_2 = parent->sib2.rr_cfg_common.pucch_cfg_common.n_rb_cqi; sched_cfg.pucch_cfg.N_pucch_1 = parent->sib2.rr_cfg_common.pucch_cfg_common.n1_pucch_an; - // Configure MAC + // Configure MAC parent->mac->ue_cfg(rnti, &sched_cfg); - + // Configure SRB1 in RLC parent->rlc->add_bearer(rnti, 1, srslte::rlc_config_t::srb_config(1)); // Configure SRB1 in PDCP - srslte::pdcp_config_t pdcp_cnfg{.bearer_id = 1, - .rb_type = srslte::PDCP_RB_IS_SRB, - .tx_direction = srslte::SECURITY_DIRECTION_DOWNLINK, - .rx_direction = srslte::SECURITY_DIRECTION_UPLINK, - .sn_len = srslte::PDCP_SN_LEN_5, - .t_reorderding = srslte::pdcp_t_reordering_t::ms500}; + srslte::pdcp_config_t pdcp_cnfg{1, + srslte::PDCP_RB_IS_SRB, + srslte::SECURITY_DIRECTION_DOWNLINK, + srslte::SECURITY_DIRECTION_UPLINK, + srslte::PDCP_SN_LEN_5, + srslte::pdcp_t_reordering_t::ms500}; parent->pdcp->add_bearer(rnti, 1, pdcp_cnfg); @@ -1661,10 +1651,10 @@ void rrc::ue::send_connection_setup(bool is_setup) parent->mac->set_dl_ant_info(rnti, &phy_cfg->ant_info); parent->mac->phy_config_enabled(rnti, false); - rr_cfg->drb_to_add_mod_list_present = false; - rr_cfg->drb_to_release_list_present = false; + rr_cfg->drb_to_add_mod_list_present = false; + rr_cfg->drb_to_release_list_present = false; rr_cfg->rlf_timers_and_consts_r9.set_present(false); - rr_cfg->sps_cfg_present = false; + rr_cfg->sps_cfg_present = false; // rr_cfg->rlf_timers_and_constants_present = false; send_dl_ccch(&dl_ccch_msg); @@ -1700,12 +1690,12 @@ int rrc::ue::get_drbid_config(drb_to_add_mod_s* drb, int drb_id) if (qci >= MAX_NOF_QCI) { parent->rrc_log->error("Invalid QCI=%d for ERAB_id=%d, DRB_id=%d\n", qci, erab_id, drb_id); - return -1; + return -1; } - + if (!parent->cfg.qci_cfg[qci].configured) { parent->rrc_log->error("QCI=%d not configured\n", qci); - return -1; + return -1; } // Add DRB1 to the message @@ -1726,12 +1716,12 @@ int rrc::ue::get_drbid_config(drb_to_add_mod_s* drb, int drb_id) drb->rlc_cfg_present = true; drb->rlc_cfg = parent->cfg.qci_cfg[qci].rlc_cfg; - return 0; + return 0; } void rrc::ue::send_connection_reconf_upd(srslte::unique_byte_buffer_t pdu) { - dl_dcch_msg_s dl_dcch_msg; + dl_dcch_msg_s dl_dcch_msg; rrc_conn_recfg_s* rrc_conn_recfg = &dl_dcch_msg.msg.set_c1().set_rrc_conn_recfg(); rrc_conn_recfg->rrc_transaction_id = (uint8_t)((transaction_id++) % 4); rrc_conn_recfg->crit_exts.set_c1().set_rrc_conn_recfg_r8(); @@ -1777,7 +1767,6 @@ void rrc::ue::send_connection_reconf_upd(srslte::unique_byte_buffer_t pdu) send_dl_dcch(&dl_dcch_msg, std::move(pdu)); state = RRC_STATE_WAIT_FOR_CON_RECONF_COMPLETE; - } void rrc::ue::send_connection_reconf(srslte::unique_byte_buffer_t pdu) @@ -1859,7 +1848,7 @@ void rrc::ue::send_connection_reconf(srslte::unique_byte_buffer_t pdu) // Add SRB2 and DRB1 to the scheduler srsenb::sched_interface::ue_bearer_cfg_t bearer_cfg; bearer_cfg.direction = srsenb::sched_interface::ue_bearer_cfg_t::BOTH; - bearer_cfg.group = 0; + bearer_cfg.group = 0; parent->mac->bearer_ue_cfg(rnti, 2, &bearer_cfg); bearer_cfg.group = conn_reconf->rr_cfg_ded.drb_to_add_mod_list[0].lc_ch_cfg.ul_specific_params.lc_ch_group; parent->mac->bearer_ue_cfg(rnti, 3, &bearer_cfg); @@ -1868,12 +1857,12 @@ void rrc::ue::send_connection_reconf(srslte::unique_byte_buffer_t pdu) parent->rlc->add_bearer(rnti, 2, srslte::rlc_config_t::srb_config(2)); // Configure SRB2 in PDCP - srslte::pdcp_config_t pdcp_cnfg_srb = {.bearer_id = 2, - .rb_type = srslte::PDCP_RB_IS_SRB, - .tx_direction = srslte::SECURITY_DIRECTION_DOWNLINK, - .rx_direction = srslte::SECURITY_DIRECTION_UPLINK, - .sn_len = srslte::PDCP_SN_LEN_5, - .t_reorderding = srslte::pdcp_t_reordering_t::ms500}; + srslte::pdcp_config_t pdcp_cnfg_srb = {2, + srslte::PDCP_RB_IS_SRB, + srslte::SECURITY_DIRECTION_DOWNLINK, + srslte::SECURITY_DIRECTION_UPLINK, + srslte::PDCP_SN_LEN_5, + srslte::pdcp_t_reordering_t::ms500}; parent->pdcp->add_bearer(rnti, 2, pdcp_cnfg_srb); parent->pdcp->config_security(rnti, 2, k_rrc_enc, k_rrc_int, k_up_enc, cipher_algo, integ_algo); @@ -1884,12 +1873,12 @@ void rrc::ue::send_connection_reconf(srslte::unique_byte_buffer_t pdu) parent->rlc->add_bearer(rnti, 3, srslte::make_rlc_config_t(conn_reconf->rr_cfg_ded.drb_to_add_mod_list[0].rlc_cfg)); // Configure DRB1 in PDCP - srslte::pdcp_config_t pdcp_cnfg_drb = {.bearer_id = 1, - .rb_type = srslte::PDCP_RB_IS_DRB, - .tx_direction = srslte::SECURITY_DIRECTION_DOWNLINK, - .rx_direction = srslte::SECURITY_DIRECTION_UPLINK, - .sn_len = srslte::PDCP_SN_LEN_12, - .t_reorderding = srslte::pdcp_t_reordering_t::ms500}; + srslte::pdcp_config_t pdcp_cnfg_drb = {1, + srslte::PDCP_RB_IS_DRB, + srslte::SECURITY_DIRECTION_DOWNLINK, + srslte::SECURITY_DIRECTION_UPLINK, + srslte::PDCP_SN_LEN_12, + srslte::pdcp_t_reordering_t::ms500}; if (conn_reconf->rr_cfg_ded.drb_to_add_mod_list[0].pdcp_cfg.rlc_um_present) { if (conn_reconf->rr_cfg_ded.drb_to_add_mod_list[0].pdcp_cfg.rlc_um.pdcp_sn_size.value == @@ -1904,8 +1893,9 @@ void rrc::ue::send_connection_reconf(srslte::unique_byte_buffer_t pdu) // DRB1 has already been configured in GTPU through bearer setup // Add NAS Attach accept - if(nas_pending){ - parent->rrc_log->info_hex(erab_info.buffer, erab_info.N_bytes, "connection_reconf erab_info -> nas_info rnti 0x%x\n", rnti); + if (nas_pending) { + parent->rrc_log->info_hex( + erab_info.buffer, erab_info.N_bytes, "connection_reconf erab_info -> nas_info rnti 0x%x\n", rnti); conn_reconf->ded_info_nas_list_present = true; conn_reconf->ded_info_nas_list.resize(1); conn_reconf->ded_info_nas_list[0].resize(erab_info.N_bytes); @@ -1927,7 +1917,7 @@ void rrc::ue::send_connection_reconf(srslte::unique_byte_buffer_t pdu) state = RRC_STATE_WAIT_FOR_CON_RECONF_COMPLETE; } -void rrc::ue::send_connection_reconf_new_bearer(LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT *e) +void rrc::ue::send_connection_reconf_new_bearer(LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT* e) { srslte::unique_byte_buffer_t pdu = srslte::allocate_unique_buffer(*pool); @@ -1936,10 +1926,10 @@ void rrc::ue::send_connection_reconf_new_bearer(LIBLTE_S1AP_E_RABTOBESETUPLISTBE dl_dcch_msg.msg.c1().rrc_conn_recfg().rrc_transaction_id = (uint8_t)((transaction_id++) % 4); rrc_conn_recfg_r8_ies_s* conn_reconf = &dl_dcch_msg.msg.c1().rrc_conn_recfg().crit_exts.c1().rrc_conn_recfg_r8(); - for(uint32_t i=0; ilen; i++) { - LIBLTE_S1AP_E_RABTOBESETUPITEMBEARERSUREQ_STRUCT *erab = &e->buffer[i]; - uint8_t id = erab->e_RAB_ID.E_RAB_ID; - uint8_t lcid = id - 2; // Map e.g. E-RAB 5 to LCID 3 (==DRB1) + for (uint32_t i = 0; i < e->len; i++) { + LIBLTE_S1AP_E_RABTOBESETUPITEMBEARERSUREQ_STRUCT* erab = &e->buffer[i]; + uint8_t id = erab->e_RAB_ID.E_RAB_ID; + uint8_t lcid = id - 2; // Map e.g. E-RAB 5 to LCID 3 (==DRB1) // Get DRB configuration drb_to_add_mod_s drb_item; @@ -1959,12 +1949,12 @@ void rrc::ue::send_connection_reconf_new_bearer(LIBLTE_S1AP_E_RABTOBESETUPLISTBE // Configure DRB in PDCP srslte::pdcp_config_t pdcp_config = { - .bearer_id = (uint8_t)(drb_item.drb_id - 1), // TODO: Review all ID mapping LCID DRB ERAB EPSBID Mapping - .rb_type = srslte::PDCP_RB_IS_DRB, - .tx_direction = srslte::SECURITY_DIRECTION_DOWNLINK, - .rx_direction = srslte::SECURITY_DIRECTION_UPLINK, - .sn_len = srslte::PDCP_SN_LEN_12, - .t_reorderding = srslte::pdcp_t_reordering_t::ms500}; + (uint8_t)(drb_item.drb_id - 1), // TODO: Review all ID mapping LCID DRB ERAB EPSBID Mapping + srslte::PDCP_RB_IS_DRB, + srslte::SECURITY_DIRECTION_DOWNLINK, + srslte::SECURITY_DIRECTION_UPLINK, + srslte::PDCP_SN_LEN_12, + srslte::pdcp_t_reordering_t::ms500}; parent->pdcp->add_bearer(rnti, lcid, pdcp_config); @@ -1973,7 +1963,8 @@ void rrc::ue::send_connection_reconf_new_bearer(LIBLTE_S1AP_E_RABTOBESETUPLISTBE conn_reconf->rr_cfg_ded.drb_to_add_mod_list.push_back(drb_item); // Add NAS message - parent->rrc_log->info_hex(erab_info.buffer, erab_info.N_bytes, "reconf_new_bearer erab_info -> nas_info rnti 0x%x\n", rnti); + parent->rrc_log->info_hex( + erab_info.buffer, erab_info.N_bytes, "reconf_new_bearer erab_info -> nas_info rnti 0x%x\n", rnti); asn1::dyn_octstring octstr(erab_info.N_bytes); memcpy(octstr.data(), erab_info.msg, erab_info.N_bytes); conn_reconf->ded_info_nas_list.push_back(octstr); @@ -1986,7 +1977,7 @@ void rrc::ue::send_connection_reconf_new_bearer(LIBLTE_S1AP_E_RABTOBESETUPLISTBE void rrc::ue::send_security_mode_command() { - dl_dcch_msg_s dl_dcch_msg; + dl_dcch_msg_s dl_dcch_msg; security_mode_cmd_s* comm = &dl_dcch_msg.msg.set_c1().set_security_mode_cmd(); comm->rrc_transaction_id = (uint8_t)((transaction_id++) % 4); @@ -2028,102 +2019,100 @@ bool rrc::ue::select_security_algorithms() // Algorithms are defined in TS 33.401 [15]. // Note: information missing - bool enc_algo_found = false; + bool enc_algo_found = false; bool integ_algo_found = false; - for (int i = 0; i < srslte::CIPHERING_ALGORITHM_ID_N_ITEMS; i++) { - switch (parent->cfg.eea_preference_list[i]) { - case srslte::CIPHERING_ALGORITHM_ID_EEA0: - // “all bits equal to 0” – UE supports no other algorithm than EEA0, - // specification does not cover the case in which EEA0 is supported with other algorithms - // just assume that EEA0 is always supported even this can not be explicity signaled by S1AP - cipher_algo = srslte::CIPHERING_ALGORITHM_ID_EEA0; - enc_algo_found = true; - parent->rrc_log->info("Selected EEA0 as RRC encryption algorithm\n"); - break; - case srslte::CIPHERING_ALGORITHM_ID_128_EEA1: - // “first bit” – 128-EEA1, - if (security_capabilities.encryptionAlgorithms - .buffer[srslte::CIPHERING_ALGORITHM_ID_128_EEA1 - 1]) { - cipher_algo = srslte::CIPHERING_ALGORITHM_ID_128_EEA1; + for (auto& cipher_item : parent->cfg.eea_preference_list) { + switch (cipher_item) { + case srslte::CIPHERING_ALGORITHM_ID_EEA0: + // “all bits equal to 0” – UE supports no other algorithm than EEA0, + // specification does not cover the case in which EEA0 is supported with other algorithms + // just assume that EEA0 is always supported even this can not be explicity signaled by S1AP + cipher_algo = srslte::CIPHERING_ALGORITHM_ID_EEA0; enc_algo_found = true; - parent->rrc_log->info("Selected EEA1 as RRC encryption algorithm\n"); + parent->rrc_log->info("Selected EEA0 as RRC encryption algorithm\n"); break; - } else { - parent->rrc_log->info("Failed to selected EEA1 as RRC encryption algorithm, due to unsupported algorithm\n"); - } - break; - case srslte::CIPHERING_ALGORITHM_ID_128_EEA2: - // “second bit” – 128-EEA2, - if (security_capabilities.encryptionAlgorithms - .buffer[srslte::CIPHERING_ALGORITHM_ID_128_EEA2 - 1]) { - cipher_algo = srslte::CIPHERING_ALGORITHM_ID_128_EEA2; - enc_algo_found = true; - parent->rrc_log->info("Selected EEA2 as RRC encryption algorithm\n"); + case srslte::CIPHERING_ALGORITHM_ID_128_EEA1: + // “first bit” – 128-EEA1, + if (security_capabilities.encryptionAlgorithms.buffer[srslte::CIPHERING_ALGORITHM_ID_128_EEA1 - 1]) { + cipher_algo = srslte::CIPHERING_ALGORITHM_ID_128_EEA1; + enc_algo_found = true; + parent->rrc_log->info("Selected EEA1 as RRC encryption algorithm\n"); + break; + } else { + parent->rrc_log->info("Failed to selected EEA1 as RRC encryption algorithm, due to unsupported algorithm\n"); + } break; - } else { - parent->rrc_log->info("Failed to selected EEA2 as RRC encryption algorithm, due to unsupported algorithm\n"); - } - break; - case srslte::CIPHERING_ALGORITHM_ID_128_EEA3: - // “third bit” – 128-EEA3, - if (security_capabilities.encryptionAlgorithms.buffer[srslte::CIPHERING_ALGORITHM_ID_128_EEA3 - 1]) { - cipher_algo = srslte::CIPHERING_ALGORITHM_ID_128_EEA3; - enc_algo_found = true; - parent->rrc_log->info("Selected EEA3 as RRC encryption algorithm\n"); + case srslte::CIPHERING_ALGORITHM_ID_128_EEA2: + // “second bit” – 128-EEA2, + if (security_capabilities.encryptionAlgorithms.buffer[srslte::CIPHERING_ALGORITHM_ID_128_EEA2 - 1]) { + cipher_algo = srslte::CIPHERING_ALGORITHM_ID_128_EEA2; + enc_algo_found = true; + parent->rrc_log->info("Selected EEA2 as RRC encryption algorithm\n"); + break; + } else { + parent->rrc_log->info("Failed to selected EEA2 as RRC encryption algorithm, due to unsupported algorithm\n"); + } + break; + case srslte::CIPHERING_ALGORITHM_ID_128_EEA3: + // “third bit” – 128-EEA3, + if (security_capabilities.encryptionAlgorithms.buffer[srslte::CIPHERING_ALGORITHM_ID_128_EEA3 - 1]) { + cipher_algo = srslte::CIPHERING_ALGORITHM_ID_128_EEA3; + enc_algo_found = true; + parent->rrc_log->info("Selected EEA3 as RRC encryption algorithm\n"); + break; + } else { + parent->rrc_log->info("Failed to selected EEA2 as RRC encryption algorithm, due to unsupported algorithm\n"); + } + break; + default: + enc_algo_found = false; break; - } else { - parent->rrc_log->info("Failed to selected EEA2 as RRC encryption algorithm, due to unsupported algorithm\n"); - } - break; - default: - enc_algo_found = false; - break; } if (enc_algo_found) { break; } } - for (int i = 0; i < srslte::INTEGRITY_ALGORITHM_ID_N_ITEMS; i++) { - switch (parent->cfg.eia_preference_list[i]) { - case srslte::INTEGRITY_ALGORITHM_ID_EIA0: - // Null integrity is not supported - parent->rrc_log->info("Skipping EIA0 as RRC integrity algorithm. Null integrity is not supported.\n"); - break; - case srslte::INTEGRITY_ALGORITHM_ID_128_EIA1: - // “first bit” – 128-EIA1, - if (security_capabilities.integrityProtectionAlgorithms.buffer[srslte::INTEGRITY_ALGORITHM_ID_128_EIA1 - 1]) { - integ_algo = srslte::INTEGRITY_ALGORITHM_ID_128_EIA1; - integ_algo_found = true; - parent->rrc_log->info("Selected EIA1 as RRC integrity algorithm.\n"); - } else { - parent->rrc_log->info("Failed to selected EIA1 as RRC encryption algorithm, due to unsupported algorithm\n"); - } - break; - case srslte::INTEGRITY_ALGORITHM_ID_128_EIA2: - // “second bit” – 128-EIA2, - if (security_capabilities.integrityProtectionAlgorithms.buffer[srslte::INTEGRITY_ALGORITHM_ID_128_EIA2 - 1]) { - integ_algo = srslte::INTEGRITY_ALGORITHM_ID_128_EIA2; - integ_algo_found = true; - parent->rrc_log->info("Selected EIA2 as RRC integrity algorithm.\n"); - } else { - parent->rrc_log->info("Failed to selected EIA2 as RRC encryption algorithm, due to unsupported algorithm\n"); - } - break; - case srslte::INTEGRITY_ALGORITHM_ID_128_EIA3: - // “third bit” – 128-EIA3, - if (security_capabilities.integrityProtectionAlgorithms.buffer[srslte::INTEGRITY_ALGORITHM_ID_128_EIA3 - 1]) { - integ_algo = srslte::INTEGRITY_ALGORITHM_ID_128_EIA3; - integ_algo_found = true; - parent->rrc_log->info("Selected EIA3 as RRC integrity algorithm.\n"); - } else { - parent->rrc_log->info("Failed to selected EIA3 as RRC encryption algorithm, due to unsupported algorithm\n"); - } - break; - default: - integ_algo_found = false; - break; + for (auto& eia_enum : parent->cfg.eia_preference_list) { + switch (eia_enum) { + case srslte::INTEGRITY_ALGORITHM_ID_EIA0: + // Null integrity is not supported + parent->rrc_log->info("Skipping EIA0 as RRC integrity algorithm. Null integrity is not supported.\n"); + break; + case srslte::INTEGRITY_ALGORITHM_ID_128_EIA1: + // “first bit” – 128-EIA1, + if (security_capabilities.integrityProtectionAlgorithms.buffer[srslte::INTEGRITY_ALGORITHM_ID_128_EIA1 - 1]) { + integ_algo = srslte::INTEGRITY_ALGORITHM_ID_128_EIA1; + integ_algo_found = true; + parent->rrc_log->info("Selected EIA1 as RRC integrity algorithm.\n"); + } else { + parent->rrc_log->info("Failed to selected EIA1 as RRC encryption algorithm, due to unsupported algorithm\n"); + } + break; + case srslte::INTEGRITY_ALGORITHM_ID_128_EIA2: + // “second bit” – 128-EIA2, + if (security_capabilities.integrityProtectionAlgorithms.buffer[srslte::INTEGRITY_ALGORITHM_ID_128_EIA2 - 1]) { + integ_algo = srslte::INTEGRITY_ALGORITHM_ID_128_EIA2; + integ_algo_found = true; + parent->rrc_log->info("Selected EIA2 as RRC integrity algorithm.\n"); + } else { + parent->rrc_log->info("Failed to selected EIA2 as RRC encryption algorithm, due to unsupported algorithm\n"); + } + break; + case srslte::INTEGRITY_ALGORITHM_ID_128_EIA3: + // “third bit” – 128-EIA3, + if (security_capabilities.integrityProtectionAlgorithms.buffer[srslte::INTEGRITY_ALGORITHM_ID_128_EIA3 - 1]) { + integ_algo = srslte::INTEGRITY_ALGORITHM_ID_128_EIA3; + integ_algo_found = true; + parent->rrc_log->info("Selected EIA3 as RRC integrity algorithm.\n"); + } else { + parent->rrc_log->info("Failed to selected EIA3 as RRC encryption algorithm, due to unsupported algorithm\n"); + } + break; + default: + integ_algo_found = false; + break; } if (integ_algo_found) { @@ -2158,7 +2147,7 @@ void rrc::ue::send_dl_ccch(dl_ccch_msg_s* dl_ccch_msg) } void rrc::ue::send_dl_dcch(dl_dcch_msg_s* dl_dcch_msg, srslte::unique_byte_buffer_t pdu) -{ +{ if (!pdu) { pdu = srslte::allocate_unique_buffer(*pool); } @@ -2190,74 +2179,80 @@ int rrc::ue::sr_free() if (parent->sr_sched.nof_users[sr_sched_prb_idx][sr_sched_sf_idx] > 0) { parent->sr_sched.nof_users[sr_sched_prb_idx][sr_sched_sf_idx]--; } else { - parent->rrc_log->warning("Removing SR resources: no users in time-frequency slot (%d, %d)\n", sr_sched_prb_idx, sr_sched_sf_idx); + parent->rrc_log->warning( + "Removing SR resources: no users in time-frequency slot (%d, %d)\n", sr_sched_prb_idx, sr_sched_sf_idx); } - parent->rrc_log->info("Deallocated SR resources for time-frequency slot (%d, %d)\n", sr_sched_prb_idx, sr_sched_sf_idx); + parent->rrc_log->info( + "Deallocated SR resources for time-frequency slot (%d, %d)\n", sr_sched_prb_idx, sr_sched_sf_idx); } - return 0; + return 0; } void rrc::ue::sr_get(uint8_t* I_sr, uint16_t* N_pucch_sr) { - *I_sr = sr_I; - *N_pucch_sr = sr_N_pucch; + *I_sr = sr_I; + *N_pucch_sr = sr_N_pucch; } int rrc::ue::sr_allocate(uint32_t period, uint8_t* I_sr, uint16_t* N_pucch_sr) { - uint32_t c = SRSLTE_CP_ISNORM(parent->cfg.cell.cp)?3:2; + uint32_t c = SRSLTE_CP_ISNORM(parent->cfg.cell.cp) ? 3 : 2; uint32_t delta_pucch_shift = parent->sib2.rr_cfg_common.pucch_cfg_common.delta_pucch_shift.to_number(); - uint32_t max_users = 12*c/delta_pucch_shift; + uint32_t max_users = 12 * c / delta_pucch_shift; - // Find freq-time resources with least number of users - int i_min=0, j_min=0; + // Find freq-time resources with least number of users + int i_min = 0, j_min = 0; uint32_t min_users = 1e6; - for (uint32_t i=0;icfg.sr_cfg.nof_prb;i++) { - for (uint32_t j=0;jcfg.sr_cfg.nof_subframes;j++) { + for (uint32_t i = 0; i < parent->cfg.sr_cfg.nof_prb; i++) { + for (uint32_t j = 0; j < parent->cfg.sr_cfg.nof_subframes; j++) { if (parent->sr_sched.nof_users[i][j] < min_users) { - i_min = i; - j_min = j; + i_min = i; + j_min = j; min_users = parent->sr_sched.nof_users[i][j]; } } } - + if (parent->sr_sched.nof_users[i_min][j_min] > max_users) { parent->rrc_log->error("Not enough PUCCH resources to allocate Scheduling Request\n"); - return -1; + return -1; } - - // Compute I_sr + + // Compute I_sr if (period != 5 && period != 10 && period != 20 && period != 40 && period != 80) { parent->rrc_log->error("Invalid SchedulingRequest period %d ms\n", period); - return -1; - } + return -1; + } if (parent->cfg.sr_cfg.sf_mapping[j_min] < period) { *I_sr = period - 5 + parent->cfg.sr_cfg.sf_mapping[j_min]; } else { - parent->rrc_log->error("Allocating SR: invalid sf_idx=%d for period=%d\n", parent->cfg.sr_cfg.sf_mapping[j_min], period); - return -1; + parent->rrc_log->error( + "Allocating SR: invalid sf_idx=%d for period=%d\n", parent->cfg.sr_cfg.sf_mapping[j_min], period); + return -1; } - // Compute N_pucch_sr - *N_pucch_sr = i_min*max_users + parent->sr_sched.nof_users[i_min][j_min]; + // Compute N_pucch_sr + *N_pucch_sr = i_min * max_users + parent->sr_sched.nof_users[i_min][j_min]; if (parent->sib2.rr_cfg_common.pucch_cfg_common.n_cs_an) { *N_pucch_sr += parent->sib2.rr_cfg_common.pucch_cfg_common.n_cs_an; } - - // Allocate user - parent->sr_sched.nof_users[i_min][j_min]++; - sr_sched_prb_idx = i_min; - sr_sched_sf_idx = j_min; - sr_allocated = true; - sr_I = *I_sr; - sr_N_pucch = *N_pucch_sr; - - parent->rrc_log->info("Allocated SR resources for time-frequency slot (%d, %d), N_pucch_sr=%d, I_sr=%d\n", - sr_sched_prb_idx, sr_sched_sf_idx, *N_pucch_sr, *I_sr); - return 0; + // Allocate user + parent->sr_sched.nof_users[i_min][j_min]++; + sr_sched_prb_idx = i_min; + sr_sched_sf_idx = j_min; + sr_allocated = true; + sr_I = *I_sr; + sr_N_pucch = *N_pucch_sr; + + parent->rrc_log->info("Allocated SR resources for time-frequency slot (%d, %d), N_pucch_sr=%d, I_sr=%d\n", + sr_sched_prb_idx, + sr_sched_sf_idx, + *N_pucch_sr, + *I_sr); + + return 0; } int rrc::ue::cqi_free() @@ -2266,81 +2261,84 @@ int rrc::ue::cqi_free() if (parent->cqi_sched.nof_users[cqi_sched_prb_idx][cqi_sched_sf_idx] > 0) { parent->cqi_sched.nof_users[cqi_sched_prb_idx][cqi_sched_sf_idx]--; } else { - parent->rrc_log->warning("Removing CQI resources: no users in time-frequency slot (%d, %d)\n", cqi_sched_prb_idx, cqi_sched_sf_idx); + parent->rrc_log->warning( + "Removing CQI resources: no users in time-frequency slot (%d, %d)\n", cqi_sched_prb_idx, cqi_sched_sf_idx); } - parent->rrc_log->info("Deallocated CQI resources for time-frequency slot (%d, %d)\n", cqi_sched_prb_idx, cqi_sched_sf_idx); + parent->rrc_log->info( + "Deallocated CQI resources for time-frequency slot (%d, %d)\n", cqi_sched_prb_idx, cqi_sched_sf_idx); } - return 0; + return 0; } void rrc::ue::cqi_get(uint16_t* pmi_idx, uint16_t* n_pucch) { - *pmi_idx = cqi_idx; - *n_pucch = cqi_pucch; + *pmi_idx = cqi_idx; + *n_pucch = cqi_pucch; } int rrc::ue::cqi_allocate(uint32_t period, uint16_t* pmi_idx, uint16_t* n_pucch) { - uint32_t c = SRSLTE_CP_ISNORM(parent->cfg.cell.cp)?3:2; + uint32_t c = SRSLTE_CP_ISNORM(parent->cfg.cell.cp) ? 3 : 2; uint32_t delta_pucch_shift = parent->sib2.rr_cfg_common.pucch_cfg_common.delta_pucch_shift.to_number(); - uint32_t max_users = 12*c/delta_pucch_shift; + uint32_t max_users = 12 * c / delta_pucch_shift; - // Find freq-time resources with least number of users - int i_min=0, j_min=0; + // Find freq-time resources with least number of users + int i_min = 0, j_min = 0; uint32_t min_users = 1e6; - for (uint32_t i=0;icfg.cqi_cfg.nof_prb;i++) { - for (uint32_t j=0;jcfg.cqi_cfg.nof_subframes;j++) { + for (uint32_t i = 0; i < parent->cfg.cqi_cfg.nof_prb; i++) { + for (uint32_t j = 0; j < parent->cfg.cqi_cfg.nof_subframes; j++) { if (parent->cqi_sched.nof_users[i][j] < min_users) { - i_min = i; - j_min = j; + i_min = i; + j_min = j; min_users = parent->cqi_sched.nof_users[i][j]; } } } - + if (parent->cqi_sched.nof_users[i_min][j_min] > max_users) { parent->rrc_log->error("Not enough PUCCH resources to allocate Scheduling Request\n"); - return -1; + return -1; } - - // Compute I_sr - if (period != 2 && period != 5 && period != 10 && period != 20 && period != 40 && period != 80 && - period != 160 && period != 32 && period != 64 && period != 128) { + + // Compute I_sr + if (period != 2 && period != 5 && period != 10 && period != 20 && period != 40 && period != 80 && period != 160 && + period != 32 && period != 64 && period != 128) { parent->rrc_log->error("Invalid CQI Report period %d ms\n", period); - return -1; - } + return -1; + } if (parent->cfg.cqi_cfg.sf_mapping[j_min] < period) { if (period != 32 && period != 64 && period != 128) { if (period > 2) { - *pmi_idx = period - 3 + parent->cfg.cqi_cfg.sf_mapping[j_min]; + *pmi_idx = period - 3 + parent->cfg.cqi_cfg.sf_mapping[j_min]; } else { - *pmi_idx = parent->cfg.cqi_cfg.sf_mapping[j_min]; - } + *pmi_idx = parent->cfg.cqi_cfg.sf_mapping[j_min]; + } } else { if (period == 32) { - *pmi_idx = 318 + parent->cfg.cqi_cfg.sf_mapping[j_min]; + *pmi_idx = 318 + parent->cfg.cqi_cfg.sf_mapping[j_min]; } else if (period == 64) { - *pmi_idx = 350 + parent->cfg.cqi_cfg.sf_mapping[j_min]; + *pmi_idx = 350 + parent->cfg.cqi_cfg.sf_mapping[j_min]; } else if (period == 128) { - *pmi_idx = 414 + parent->cfg.cqi_cfg.sf_mapping[j_min]; + *pmi_idx = 414 + parent->cfg.cqi_cfg.sf_mapping[j_min]; } } } else { - parent->rrc_log->error("Allocating SR: invalid sf_idx=%d for period=%d\n", parent->cfg.cqi_cfg.sf_mapping[j_min], period); - return -1; + parent->rrc_log->error( + "Allocating SR: invalid sf_idx=%d for period=%d\n", parent->cfg.cqi_cfg.sf_mapping[j_min], period); + return -1; } // Compute n_pucch_2 - *n_pucch = i_min*max_users + parent->cqi_sched.nof_users[i_min][j_min]; + *n_pucch = i_min * max_users + parent->cqi_sched.nof_users[i_min][j_min]; if (parent->sib2.rr_cfg_common.pucch_cfg_common.n_cs_an) { *n_pucch += parent->sib2.rr_cfg_common.pucch_cfg_common.n_cs_an; } - - // Allocate user - parent->cqi_sched.nof_users[i_min][j_min]++; - cqi_sched_prb_idx = i_min; - cqi_sched_sf_idx = j_min; + + // Allocate user + parent->cqi_sched.nof_users[i_min][j_min]++; + cqi_sched_prb_idx = i_min; + cqi_sched_sf_idx = j_min; cqi_allocated = true; cqi_idx = *pmi_idx; cqi_pucch = *n_pucch; @@ -2351,7 +2349,7 @@ int rrc::ue::cqi_allocate(uint32_t period, uint16_t* pmi_idx, uint16_t* n_pucch) *n_pucch, *pmi_idx); - return 0; + return 0; } int rrc::ue::ri_get(uint32_t m_ri, uint16_t* ri_idx) @@ -2393,4 +2391,4 @@ int rrc::ue::ri_get(uint32_t m_ri, uint16_t* ri_idx) return ret; } -} +} // namespace srsenb