srsLTE/srsue/hdr/stack/mac/proc_ra.h

162 lines
4.9 KiB
C
Raw Normal View History

/**
2017-05-30 06:38:04 -07:00
*
* \section COPYRIGHT
2017-05-30 06:38:04 -07:00
*
* Copyright 2013-2020 Software Radio Systems Limited
2017-05-30 06:38:04 -07:00
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
2017-05-30 06:38:04 -07:00
*
*/
2018-03-31 10:04:04 -07:00
#ifndef SRSUE_PROC_RA_H
#define SRSUE_PROC_RA_H
2017-05-30 06:38:04 -07:00
#include <atomic>
2019-06-10 15:57:10 -07:00
#include <mutex>
2017-05-30 06:38:04 -07:00
#include <stdint.h>
#include "demux.h"
#include "mux.h"
#include "srslte/common/log.h"
#include "srslte/common/mac_pcap.h"
#include "srslte/common/timers.h"
2020-04-21 12:53:37 -07:00
#include "srslte/mac/pdu.h"
2017-05-30 06:38:04 -07:00
/* Random access procedure as specified in Section 5.1 of 36.321 */
namespace srsue {
class ra_proc : public srslte::timer_callback
{
2017-11-23 10:46:34 -08:00
public:
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
explicit ra_proc(srslog::basic_logger& logger) : rar_pdu_msg(20), logger(logger) {}
2017-11-23 10:46:34 -08:00
~ra_proc();
void init(phy_interface_mac_lte* phy_h,
rrc_interface_mac* rrc_,
mac_interface_rrc::ue_rnti_t* rntis,
srslte::timer_handler::unique_timer* time_alignment_timer_,
mux* mux_unit,
srslte::ext_task_sched_handle* task_sched_);
2019-04-23 01:53:11 -07:00
2017-11-23 10:46:34 -08:00
void reset();
2019-04-23 01:53:11 -07:00
void set_config(srslte::rach_cfg_t& rach_cfg);
void set_config_ded(uint32_t preamble_index, uint32_t prach_mask);
2019-04-23 01:53:11 -07:00
2017-11-23 10:46:34 -08:00
void start_pdcch_order();
void start_mac_order(uint32_t msg_len_bits = 56);
2017-11-23 10:46:34 -08:00
void step(uint32_t tti);
2019-04-23 01:53:11 -07:00
void update_rar_window(int& rar_window_start, int& rar_window_length);
2017-11-23 10:46:34 -08:00
bool is_contention_resolution();
void harq_retx();
2019-04-23 01:53:11 -07:00
void harq_max_retx();
void pdcch_to_crnti(bool is_new_uplink_transmission);
2017-11-23 10:46:34 -08:00
void timer_expired(uint32_t timer_id);
void new_grant_dl(mac_interface_phy_lte::mac_grant_dl_t grant, mac_interface_phy_lte::tb_action_dl_t* action);
2020-03-04 01:49:51 -08:00
void tb_decoded_ok(const uint8_t cc_idx, const uint32_t tti);
bool contention_resolution_id_received(uint64_t rx_contention_id);
2017-11-23 10:46:34 -08:00
void start_pcap(srslte::mac_pcap* pcap);
void notify_ra_completed(uint32_t task_id);
bool is_idle() const { return state == IDLE; }
2019-04-23 01:53:11 -07:00
private:
void state_pdcch_setup();
void state_response_reception(uint32_t tti);
void state_backoff_wait(uint32_t tti);
void state_contention_resolution();
void state_completition();
2017-11-23 10:46:34 -08:00
void process_timeadv_cmd(uint32_t ta_cmd);
void initialization();
void resource_selection();
void preamble_transmission();
void response_error();
void complete();
2017-11-23 10:46:34 -08:00
bool contention_resolution_id_received_unsafe(uint64_t rx_contention_id);
2017-11-23 10:46:34 -08:00
// Buffer to receive RAR PDU
static const uint32_t MAX_RAR_PDU_LEN = 2048;
uint8_t rar_pdu_buffer[MAX_RAR_PDU_LEN] = {};
2019-04-23 01:53:11 -07:00
srslte::rar_pdu rar_pdu_msg;
2017-11-23 10:46:34 -08:00
// Random Access parameters provided by higher layers defined in 5.1.1
srslte::rach_cfg_t rach_cfg = {};
2019-04-23 01:53:11 -07:00
int delta_preamble_db = 0;
uint32_t maskIndex = 0;
int preambleIndex = 0;
uint32_t new_ra_msg_len = 0;
2017-11-23 10:46:34 -08:00
bool noncontention_enabled = false;
uint32_t next_preamble_idx = 0;
uint32_t next_prach_mask = 0;
2017-11-23 10:46:34 -08:00
// Internal variables
uint32_t preambleTransmissionCounter = 0;
uint32_t backoff_param_ms = 0;
uint32_t sel_maskIndex = 0;
std::atomic<uint32_t> sel_preamble = {0};
int backoff_interval_start = 0;
uint32_t backoff_interval = 0;
int received_target_power_dbm = 0;
uint32_t ra_rnti = SRSLTE_INVALID_RNTI;
uint32_t ra_tti = 0;
uint32_t current_ta = 0;
// The task_id is a unique number associated with each RA procedure used to track background tasks
uint32_t current_task_id = 0;
2017-11-23 10:46:34 -08:00
srslte_softbuffer_rx_t softbuffer_rar = {};
2017-11-23 10:46:34 -08:00
enum ra_state_t {
IDLE = 0,
PDCCH_SETUP,
RESPONSE_RECEPTION,
BACKOFF_WAIT,
CONTENTION_RESOLUTION,
START_WAIT_COMPLETION,
WAITING_COMPLETION
};
std::atomic<ra_state_t> state = {IDLE};
2017-11-23 10:46:34 -08:00
2019-04-23 01:53:11 -07:00
typedef enum { RA_GROUP_A, RA_GROUP_B } ra_group_t;
ra_group_t last_msg3_group = RA_GROUP_A;
2017-11-23 10:46:34 -08:00
uint32_t rar_window_st = 0;
2017-11-23 10:46:34 -08:00
2019-04-23 01:53:11 -07:00
void read_params();
phy_interface_mac_lte* phy_h = nullptr;
Upgrade loggers in srsue (#2163) * Replaced UE logger in the ue class. * Replaced loggers in the main phy class and prach. * Replaced loggers in phy common and ta_control. * Replace loggers in cc and sf workers. * Replaced loggers in intra_measure, scell_recv, search, sfn_sync, sync. * Remove last uses of the old loggers in the main phy class. * Remove stray newline in logs. * Replaced loggers in ue gw. * - Started to replace loggers in the ue stack. - Replaced loggers in usim and pcsc. - Adapted nas and usim tests. * Replace loggers in nas. * Added missing log init calls in two previously modified tests. * Replaced logger in nas idle procs. * Replaced loggers in nas emm state. * Replaced loggers in tft packet filter and adapted tft test. * Replaced loggers in main RRC class. * Replaced loggers in RRC cell. * Replaced loggers in RRC meas. * Replaced loggers in rrc procedures. * Started logger replacement in MAC layer, more precisely in demux and dl_harq classes. Been unable to inject loggers in construction for dl_tb_process due to very weird static assertions in the std::vector code being the type not constructible which is not true, so instead use the main MAC logger directly. * Replaced loggers in mac mux class. * Replaced loggers in mac pro_bsr. * Replaced loggers in mac proc phr. * Replaced loggers in mac proc SR and RA. * Replace loggers in mac UL HARQ. * Replaced loggers in main ue stack class. * Fixed nas test crashing due to a null string. * Ported mac_test to use the new loggers. * Removed TTI reporting for the PHY log as the old logger did. * Replaced loggers in UE phy tests. * Configure loggers in nas_test. * Replaced loggers in rrc_meas_test. * Replaced loggers in rrc_reconfig_test. * Added missing newline in tft_test. * Fix compilation errors in TTCN3 tests. * Fix linker error detected in CI and warning. * Replaced loggers in TTCN3 tests. * Fix a text replace error in some log messages. * Remove trailing newlines from log entries. * Remove old logger from rrc. * Flush backend before printing the test status. * - Fix compilation error from previous rebase. - Remove trailing newlines from some missing log entries.
2021-01-28 08:17:43 -08:00
srslog::basic_logger& logger;
mux* mux_unit = nullptr;
srslte::mac_pcap* pcap = nullptr;
rrc_interface_mac* rrc = nullptr;
srslte::ext_task_sched_handle* task_sched = nullptr;
srslte::task_multiqueue::queue_handle task_queue;
2017-11-23 10:46:34 -08:00
srslte::timer_handler::unique_timer* time_alignment_timer = nullptr;
srslte::timer_handler::unique_timer contention_resolution_timer;
2017-11-23 10:46:34 -08:00
mac_interface_rrc::ue_rnti_t* rntis = nullptr;
2017-11-23 10:46:34 -08:00
std::atomic<uint64_t> transmitted_contention_id = {0};
std::atomic<uint16_t> transmitted_crnti = {0};
2019-04-23 01:53:11 -07:00
bool started_by_pdcch = false;
uint32_t rar_grant_nbytes = 0;
bool rar_received = false;
2017-05-30 06:38:04 -07:00
};
} // namespace srsue
2018-03-31 10:04:04 -07:00
#endif // SRSUE_PROC_RA_H