diff --git a/lib/include/srsran/interfaces/mac_interface_types.h b/lib/include/srsran/interfaces/mac_interface_types.h index 7832e5788..16cabf249 100644 --- a/lib/include/srsran/interfaces/mac_interface_types.h +++ b/lib/include/srsran/interfaces/mac_interface_types.h @@ -131,6 +131,7 @@ struct rach_cfg_nr_t { uint32_t powerRampingStep; uint32_t ra_responseWindow; uint32_t ra_ContentionResolutionTimer; + uint32_t nof_preambles; rach_cfg_nr_t() { reset(); } void reset() @@ -140,6 +141,7 @@ struct rach_cfg_nr_t { powerRampingStep = 0; preambleTransMax = 0; ra_responseWindow = 0; + nof_preambles = 0; } }; diff --git a/lib/src/asn1/rrc_nr_utils.cc b/lib/src/asn1/rrc_nr_utils.cc index 830cbb420..a7fe0d11a 100644 --- a/lib/src/asn1/rrc_nr_utils.cc +++ b/lib/src/asn1/rrc_nr_utils.cc @@ -97,6 +97,10 @@ void make_mac_rach_cfg(const rach_cfg_common_s& asn1_type, rach_cfg_nr_t* rach_c rach_cfg_nr->PreambleReceivedTargetPower = asn1_type.rach_cfg_generic.preamb_rx_target_pwr; rach_cfg_nr->preambleTransMax = asn1_type.rach_cfg_generic.preamb_trans_max.to_number(); rach_cfg_nr->ra_ContentionResolutionTimer = asn1_type.ra_contention_resolution_timer.to_number(); + + if (asn1_type.total_nof_ra_preambs_present) { + rach_cfg_nr->nof_preambles = asn1_type.total_nof_ra_preambs; + } }; int make_rlc_config_t(const rlc_cfg_c& asn1_type, uint8_t bearer_id, rlc_config_t* cfg_out) diff --git a/srsue/hdr/stack/mac_nr/proc_ra_nr.h b/srsue/hdr/stack/mac_nr/proc_ra_nr.h index 9807f73af..238c90bbe 100644 --- a/srsue/hdr/stack/mac_nr/proc_ra_nr.h +++ b/srsue/hdr/stack/mac_nr/proc_ra_nr.h @@ -29,7 +29,7 @@ class proc_ra_nr { public: proc_ra_nr(mac_interface_proc_ra_nr& mac_, srslog::basic_logger& logger_); - ~proc_ra_nr(){}; + ~proc_ra_nr() { srsran_random_free(random_gen); }; void init(phy_interface_mac_nr* phy_h_, srsran::ext_task_sched_handle* task_sched_); void set_config(const srsran::rach_cfg_nr_t& rach_cfg_nr); @@ -57,8 +57,10 @@ private: 16 * 10; ///< Limited from frame system number opportunity period in TS 38.211 tables 6.3.3.2-2, 6.3.3.2-3 ///< and 6.3.3.2-4 - mac_interface_proc_ra_nr& mac; - srslog::basic_logger& logger; + mac_interface_proc_ra_nr& mac; + srslog::basic_logger& logger; + srsran_random_t random_gen; + phy_interface_mac_nr* phy = nullptr; srsran::ext_task_sched_handle* task_sched = nullptr; srsran::task_multiqueue::queue_handle task_queue; diff --git a/srsue/hdr/stack/rrc_nr/rrc_nr.h b/srsue/hdr/stack/rrc_nr/rrc_nr.h index edb223cb8..0b859bef7 100644 --- a/srsue/hdr/stack/rrc_nr/rrc_nr.h +++ b/srsue/hdr/stack/rrc_nr/rrc_nr.h @@ -166,6 +166,8 @@ private: bool running = false; srsran::block_queue cmd_q; + srsran_random_t random_gen; + // PHY config srsran::phy_cfg_nr_t phy_cfg = {}; diff --git a/srsue/src/stack/mac_nr/proc_ra_nr.cc b/srsue/src/stack/mac_nr/proc_ra_nr.cc index b08818571..34a7710bb 100644 --- a/srsue/src/stack/mac_nr/proc_ra_nr.cc +++ b/srsue/src/stack/mac_nr/proc_ra_nr.cc @@ -41,6 +41,10 @@ void proc_ra_nr::init(phy_interface_mac_nr* phy_, srsran::ext_task_sched_handle* rar_timeout_timer = task_sched->get_unique_timer(); contention_resolution_timer = task_sched->get_unique_timer(); backoff_timer = task_sched->get_unique_timer(); + + struct timeval tv; + gettimeofday(&tv, NULL); + random_gen = srsran_random_init(tv.tv_usec); } /* Sets a new configuration. The configuration is applied by initialization() function */ @@ -166,7 +170,11 @@ void proc_ra_nr::ra_preamble_transmission() preamble_received_target_power = rach_cfg.PreambleReceivedTargetPower + delta_preamble + (preamble_transmission_counter - 1) * rach_cfg.powerRampingStep + power_offset_2step_ra; - preamble_index = 0; + if (rach_cfg.nof_preambles) { + preamble_index = srsran_random_uniform_int_dist(random_gen, 0, rach_cfg.nof_preambles); + } else { + preamble_index = 0; + } prach_occasion = 0; // instruct the physical layer to transmit the Random Access Preamble using the selected PRACH occasion, corresponding // RA-RNTI (if available), PREAMBLE_INDEX, and PREAMBLE_RECEIVED_TARGET_POWER. diff --git a/srsue/src/stack/rrc_nr/rrc_nr.cc b/srsue/src/stack/rrc_nr/rrc_nr.cc index e977b5377..5d5445f30 100644 --- a/srsue/src/stack/rrc_nr/rrc_nr.cc +++ b/srsue/src/stack/rrc_nr/rrc_nr.cc @@ -36,10 +36,16 @@ rrc_nr::rrc_nr(srsran::task_sched_handle task_sched_) : cell_selector(*this), meas_cells(task_sched_) { + struct timeval tv; + gettimeofday(&tv, NULL); + random_gen = srsran_random_init(tv.tv_usec); set_phy_default_config(); } -rrc_nr::~rrc_nr() = default; +rrc_nr::~rrc_nr() +{ + srsran_random_free(random_gen); +} int rrc_nr::init(phy_interface_rrc_nr* phy_, mac_interface_rrc_nr* mac_, @@ -601,8 +607,7 @@ void rrc_nr::send_setup_request(srsran::nr_establishment_cause_t cause) // TODO: implement ng_minus5_g_s_tmsi_part1 rrc_setup_req->ue_id.set_random_value(); - // TODO use proper RNG - uint64_t random_id = 0; + uint64_t random_id = srsran_random_uniform_int_dist(random_gen, 0, 12345); for (uint i = 0; i < 5; i++) { // fill random ID bytewise, 40 bits = 5 bytes random_id |= ((uint64_t)rand() & 0xFF) << i * 8; }