You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.8 KiB
C

/**
5 years ago
*
* \section COPYRIGHT
5 years ago
*
* Copyright 2013-2021 Software Radio Systems Limited
5 years ago
*
* 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.
5 years ago
*
*/
#ifndef SRSENB_MAC_NR_H
#define SRSENB_MAC_NR_H
5 years ago
#include "srsran/common/block_queue.h"
#include "srsran/common/mac_pcap.h"
5 years ago
#include "srsenb/hdr/common/rnti_pool.h"
5 years ago
#include "srsenb/hdr/stack/enb_stack_base.h"
#include "srsenb/hdr/stack/mac/nr/ue_nr.h"
#include "srsran/common/task_scheduler.h"
#include "srsran/interfaces/enb_metrics_interface.h"
#include "srsran/interfaces/enb_rlc_interfaces.h"
#include "srsran/interfaces/gnb_interfaces.h"
5 years ago
namespace srsenb {
struct mac_nr_args_t {
srsenb::pcap_args_t pcap;
};
class mac_nr final : public mac_interface_phy_nr, public mac_interface_rrc_nr, public mac_interface_rlc_nr
5 years ago
{
public:
mac_nr(srsran::task_sched_handle task_sched_);
5 years ago
~mac_nr();
int init(const mac_nr_args_t& args_,
phy_interface_stack_nr* phy,
stack_interface_mac* stack_,
rlc_interface_mac* rlc_,
5 years ago
rrc_interface_mac_nr* rrc_);
void stop();
void get_metrics(srsenb::mac_metrics_t& metrics);
5 years ago
// MAC interface for RRC
int cell_cfg(srsenb::sched_interface::cell_cfg_t* cell_cfg) override;
uint16_t reserve_rnti() override;
5 years ago
int read_pdu_bcch_bch(uint8_t* payload);
// MAC interface for RLC
// TODO:
int rlc_buffer_state(uint16_t rnti, uint32_t lc_id, uint32_t tx_queue, uint32_t retx_queue) override { return 0; }
5 years ago
// Interface for PHY
int sf_indication(const uint32_t tti);
int rx_data_indication(stack_interface_phy_nr::rx_data_ind_t& grant);
void process_pdus();
void rach_detected(const srsran_slot_cfg_t& slot_cfg, uint32_t enb_cc_idx, uint32_t preamble_idx, uint32_t time_adv);
int slot_indication(const srsran_slot_cfg_t& slot_cfg) override;
int get_dl_sched(const srsran_slot_cfg_t& slot_cfg, dl_sched_t& dl_sched) override;
int get_ul_sched(const srsran_slot_cfg_t& slot_cfg, ul_sched_t& ul_sched) override;
int pucch_info(const srsran_slot_cfg_t& slot_cfg, const pucch_info_t& pucch_info) override;
int pusch_info(const srsran_slot_cfg_t& slot_cfg, const pusch_info_t& pusch_info) override;
void rach_detected(const rach_info_t& rach_info) override;
5 years ago
private:
uint16_t add_ue(uint32_t enb_cc_idx);
int remove_ue(uint16_t rnti);
// internal misc helpers
bool is_rnti_valid_unsafe(uint16_t rnti);
bool is_rnti_active_unsafe(uint16_t rnti);
// PDU processing
int handle_pdu(srsran::unique_byte_buffer_t pdu);
// Interaction with other components
phy_interface_stack_nr* phy = nullptr;
stack_interface_mac* stack = nullptr;
rlc_interface_mac* rlc = nullptr;
rrc_interface_mac_nr* rrc = nullptr;
5 years ago
// args
srsran::task_sched_handle task_sched;
srsran::task_multiqueue::queue_handle stack_task_queue;
std::unique_ptr<srsran::mac_pcap> pcap = nullptr;
mac_nr_args_t args = {};
srslog::basic_logger& logger;
5 years ago
std::atomic<bool> started = {false};
5 years ago
srsenb::sched_interface::cell_cfg_t cfg = {};
// Map of active UEs
pthread_rwlock_t rwlock = {};
static const uint16_t FIRST_RNTI = 0x4601;
srsran::static_circular_map<uint16_t, std::unique_ptr<ue_nr>, SRSENB_MAX_UES> ue_db;
std::atomic<uint16_t> ue_counter;
5 years ago
// BCH buffers
struct sib_info_t {
uint32_t index;
uint32_t periodicity;
srsran::unique_byte_buffer_t payload;
5 years ago
};
std::vector<sib_info_t> bcch_dlsch_payload;
srsran::unique_byte_buffer_t bcch_bch_payload = nullptr;
5 years ago
// Number of rach preambles detected for a cc.
std::vector<uint32_t> detected_rachs;
5 years ago
};
} // namespace srsenb
#endif // SRSENB_MAC_NR_H