mirror of https://github.com/pvnis/srsRAN_4G.git
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.
392 lines
13 KiB
C
392 lines
13 KiB
C
6 years ago
|
/*
|
||
|
* Copyright 2013-2019 Software Radio Systems Limited
|
||
8 years ago
|
*
|
||
|
* This file is part of srsLTE.
|
||
|
*
|
||
6 years ago
|
* srsLTE is free software: you can redistribute it and/or modify
|
||
8 years ago
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
6 years ago
|
* srsLTE is distributed in the hope that it will be useful,
|
||
8 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* A copy of the GNU Affero General Public License can be found in
|
||
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
7 years ago
|
#ifndef SRSENB_RRC_H
|
||
|
#define SRSENB_RRC_H
|
||
8 years ago
|
|
||
6 years ago
|
#include "rrc_metrics.h"
|
||
6 years ago
|
#include "srsenb/hdr/stack/upper/common_enb.h"
|
||
6 years ago
|
#include "srslte/asn1/rrc_asn1.h"
|
||
|
#include "srslte/common/block_queue.h"
|
||
8 years ago
|
#include "srslte/common/buffer_pool.h"
|
||
|
#include "srslte/common/common.h"
|
||
6 years ago
|
#include "srslte/common/log.h"
|
||
8 years ago
|
#include "srslte/common/threads.h"
|
||
|
#include "srslte/common/timeout.h"
|
||
|
#include "srslte/interfaces/enb_interfaces.h"
|
||
6 years ago
|
#include <map>
|
||
|
#include <queue>
|
||
8 years ago
|
|
||
|
namespace srsenb {
|
||
|
|
||
6 years ago
|
struct rrc_cfg_sr_t {
|
||
|
uint32_t period;
|
||
|
asn1::rrc::sched_request_cfg_c::setup_s_::dsr_trans_max_e_ dsr_max;
|
||
|
uint32_t nof_prb;
|
||
|
uint32_t sf_mapping[80];
|
||
|
uint32_t nof_subframes;
|
||
|
};
|
||
|
|
||
8 years ago
|
typedef enum {
|
||
|
RRC_CFG_CQI_MODE_PERIODIC = 0,
|
||
|
RRC_CFG_CQI_MODE_APERIODIC,
|
||
|
RRC_CFG_CQI_MODE_N_ITEMS
|
||
|
} rrc_cfg_cqi_mode_t;
|
||
|
|
||
|
static const char rrc_cfg_cqi_mode_text[RRC_CFG_CQI_MODE_N_ITEMS][20] = {"periodic", "aperiodic"};
|
||
|
|
||
|
typedef struct {
|
||
|
uint32_t sf_mapping[80];
|
||
|
uint32_t nof_subframes;
|
||
|
uint32_t nof_prb;
|
||
|
uint32_t period;
|
||
|
bool simultaneousAckCQI;
|
||
|
rrc_cfg_cqi_mode_t mode;
|
||
|
} rrc_cfg_cqi_t;
|
||
|
|
||
|
typedef struct {
|
||
6 years ago
|
bool configured;
|
||
|
asn1::rrc::lc_ch_cfg_s::ul_specific_params_s_ lc_cfg;
|
||
|
asn1::rrc::pdcp_cfg_s pdcp_cfg;
|
||
|
asn1::rrc::rlc_cfg_c rlc_cfg;
|
||
8 years ago
|
} rrc_cfg_qci_t;
|
||
|
|
||
|
#define MAX_NOF_QCI 10
|
||
|
|
||
|
typedef struct {
|
||
6 years ago
|
asn1::rrc::sib_type1_s sib1;
|
||
|
asn1::rrc::sib_info_item_c sibs[ASN1_RRC_MAX_SIB];
|
||
|
asn1::rrc::mac_main_cfg_s mac_cnfg;
|
||
|
|
||
|
asn1::rrc::pusch_cfg_ded_s pusch_cfg;
|
||
|
asn1::rrc::ant_info_ded_s antenna_info;
|
||
|
asn1::rrc::pdsch_cfg_ded_s::p_a_e_ pdsch_cfg;
|
||
|
rrc_cfg_sr_t sr_cfg;
|
||
|
rrc_cfg_cqi_t cqi_cfg;
|
||
|
rrc_cfg_qci_t qci_cfg[MAX_NOF_QCI];
|
||
|
srslte_cell_t cell;
|
||
|
bool enable_mbsfn;
|
||
|
uint32_t inactivity_timeout_ms;
|
||
6 years ago
|
srslte::CIPHERING_ALGORITHM_ID_ENUM
|
||
|
eea_preference_list[srslte::CIPHERING_ALGORITHM_ID_N_ITEMS];
|
||
|
srslte::INTEGRITY_ALGORITHM_ID_ENUM
|
||
|
eia_preference_list[srslte::INTEGRITY_ALGORITHM_ID_N_ITEMS];
|
||
|
} rrc_cfg_t;
|
||
8 years ago
|
|
||
|
static const char rrc_state_text[RRC_STATE_N_ITEMS][100] = {"IDLE",
|
||
|
"WAIT FOR CON SETUP COMPLETE",
|
||
|
"WAIT FOR SECURITY MODE COMPLETE",
|
||
|
"WAIT FOR UE CAPABILITIY INFORMATION",
|
||
|
"WAIT FOR CON RECONF COMPLETE",
|
||
|
"RRC CONNECTED"
|
||
|
"RELEASE REQUEST"};
|
||
|
|
||
|
class rrc : public rrc_interface_pdcp,
|
||
|
public rrc_interface_mac,
|
||
|
public rrc_interface_rlc,
|
||
|
public rrc_interface_s1ap,
|
||
|
public thread
|
||
|
{
|
||
|
public:
|
||
6 years ago
|
rrc() : act_monitor(this), cnotifier(NULL), running(false), nof_si_messages(0), thread("RRC")
|
||
|
{
|
||
7 years ago
|
users.clear();
|
||
|
pending_paging.clear();
|
||
|
|
||
|
pool = NULL;
|
||
|
phy = NULL;
|
||
|
mac = NULL;
|
||
|
rlc = NULL;
|
||
|
pdcp = NULL;
|
||
|
gtpu = NULL;
|
||
|
s1ap = NULL;
|
||
|
rrc_log = NULL;
|
||
|
|
||
|
bzero(&sr_sched, sizeof(sr_sched));
|
||
|
bzero(&cqi_sched, sizeof(cqi_sched));
|
||
6 years ago
|
bzero(&cfg.sr_cfg, sizeof(cfg.sr_cfg));
|
||
|
bzero(&cfg.cqi_cfg, sizeof(cfg.cqi_cfg));
|
||
|
bzero(&cfg.qci_cfg, sizeof(cfg.qci_cfg));
|
||
|
bzero(&cfg.cell, sizeof(cfg.cell));
|
||
7 years ago
|
}
|
||
6 years ago
|
|
||
|
void init(rrc_cfg_t* cfg,
|
||
|
phy_interface_stack_lte* phy,
|
||
|
mac_interface_rrc* mac,
|
||
|
rlc_interface_rrc* rlc,
|
||
|
pdcp_interface_rrc* pdcp,
|
||
|
s1ap_interface_rrc* s1ap,
|
||
|
gtpu_interface_rrc* gtpu,
|
||
|
srslte::log* log_rrc);
|
||
|
|
||
8 years ago
|
void stop();
|
||
|
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);
|
||
|
|
||
|
// 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);
|
||
|
|
||
|
// rrc_interface_s1ap
|
||
6 years ago
|
void write_dl_info(uint16_t rnti, srslte::unique_byte_buffer_t sdu);
|
||
8 years ago
|
void release_complete(uint16_t rnti);
|
||
|
bool setup_ue_ctxt(uint16_t rnti, LIBLTE_S1AP_MESSAGE_INITIALCONTEXTSETUPREQUEST_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);
|
||
|
|
||
|
// rrc_interface_pdcp
|
||
6 years ago
|
void write_pdu(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t pdu);
|
||
6 years ago
|
|
||
|
void parse_sibs();
|
||
8 years ago
|
uint32_t get_nof_users();
|
||
|
|
||
6 years ago
|
// logging
|
||
|
typedef enum { Rx = 0, Tx } direction_t;
|
||
|
template <class T>
|
||
|
void log_rrc_message(const std::string& source, direction_t dir, const srslte::byte_buffer_t* pdu, const T& msg);
|
||
|
|
||
8 years ago
|
// Notifier for user connect
|
||
|
class connect_notifier {
|
||
|
public:
|
||
|
virtual void user_connected(uint16_t rnti) = 0;
|
||
|
};
|
||
|
void set_connect_notifer(connect_notifier *cnotifier);
|
||
|
|
||
|
class activity_monitor : public thread
|
||
|
{
|
||
|
public:
|
||
|
activity_monitor(rrc* parent_);
|
||
|
void stop();
|
||
|
private:
|
||
|
rrc* parent;
|
||
|
bool running;
|
||
|
void run_thread();
|
||
|
};
|
||
6 years ago
|
|
||
8 years ago
|
class ue
|
||
|
{
|
||
6 years ago
|
public:
|
||
|
ue();
|
||
8 years ago
|
bool is_connected();
|
||
6 years ago
|
bool is_idle();
|
||
8 years ago
|
bool is_timeout();
|
||
|
void set_activity();
|
||
7 years ago
|
|
||
|
uint32_t rl_failure();
|
||
|
|
||
8 years ago
|
rrc_state_t get_state();
|
||
6 years ago
|
|
||
8 years ago
|
void send_connection_setup(bool is_setup = true);
|
||
6 years ago
|
void send_connection_reest();
|
||
6 years ago
|
void send_connection_reject();
|
||
8 years ago
|
void send_connection_release();
|
||
6 years ago
|
void send_connection_reest_rej();
|
||
6 years ago
|
void send_connection_reconf(srslte::unique_byte_buffer_t sdu);
|
||
8 years ago
|
void send_connection_reconf_new_bearer(LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT *e);
|
||
6 years ago
|
void send_connection_reconf_upd(srslte::unique_byte_buffer_t pdu);
|
||
8 years ago
|
void send_security_mode_command();
|
||
|
void send_ue_cap_enquiry();
|
||
6 years ago
|
void parse_ul_dcch(uint32_t lcid, srslte::unique_byte_buffer_t pdu);
|
||
8 years ago
|
|
||
6 years ago
|
void handle_rrc_con_req(asn1::rrc::rrc_conn_request_s* msg);
|
||
|
void handle_rrc_con_reest_req(asn1::rrc::rrc_conn_reest_request_r8_ies_s* msg);
|
||
6 years ago
|
void handle_rrc_con_setup_complete(asn1::rrc::rrc_conn_setup_complete_s* msg, srslte::unique_byte_buffer_t pdu);
|
||
|
void handle_rrc_reconf_complete(asn1::rrc::rrc_conn_recfg_complete_s* msg, srslte::unique_byte_buffer_t pdu);
|
||
6 years ago
|
void handle_security_mode_complete(asn1::rrc::security_mode_complete_s* msg);
|
||
|
void handle_security_mode_failure(asn1::rrc::security_mode_fail_s* msg);
|
||
6 years ago
|
bool handle_ue_cap_info(asn1::rrc::ue_cap_info_s* msg);
|
||
6 years ago
|
|
||
8 years ago
|
void set_bitrates(LIBLTE_S1AP_UEAGGREGATEMAXIMUMBITRATE_STRUCT *rates);
|
||
|
void set_security_capabilities(LIBLTE_S1AP_UESECURITYCAPABILITIES_STRUCT *caps);
|
||
|
void set_security_key(uint8_t* key, uint32_t length);
|
||
|
|
||
|
bool setup_erabs(LIBLTE_S1AP_E_RABTOBESETUPLISTCTXTSUREQ_STRUCT *e);
|
||
|
bool setup_erabs(LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT *e);
|
||
7 years ago
|
void 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);
|
||
8 years ago
|
bool release_erabs();
|
||
|
|
||
|
void notify_s1ap_ue_ctxt_setup_complete();
|
||
|
void notify_s1ap_ue_erab_setup_response(LIBLTE_S1AP_E_RABTOBESETUPLISTBEARERSUREQ_STRUCT *e);
|
||
|
|
||
6 years ago
|
int sr_allocate(uint32_t period, uint8_t* I_sr, uint16_t* N_pucch_sr);
|
||
|
void sr_get(uint8_t* I_sr, uint16_t* N_pucch_sr);
|
||
8 years ago
|
int sr_free();
|
||
|
|
||
6 years ago
|
int cqi_allocate(uint32_t period, uint16_t* pmi_idx, uint16_t* n_pucch);
|
||
|
void cqi_get(uint16_t* pmi_idx, uint16_t* n_pucch);
|
||
|
int cqi_free();
|
||
6 years ago
|
|
||
6 years ago
|
bool select_security_algorithms();
|
||
6 years ago
|
void send_dl_ccch(asn1::rrc::dl_ccch_msg_s* dl_ccch_msg);
|
||
6 years ago
|
void send_dl_dcch(asn1::rrc::dl_dcch_msg_s* dl_dcch_msg,
|
||
|
srslte::unique_byte_buffer_t pdu = srslte::unique_byte_buffer_t());
|
||
6 years ago
|
|
||
|
uint16_t rnti;
|
||
6 years ago
|
rrc* parent;
|
||
6 years ago
|
|
||
|
bool connect_notified;
|
||
|
|
||
8 years ago
|
private:
|
||
7 years ago
|
srslte::byte_buffer_pool *pool;
|
||
|
|
||
6 years ago
|
struct timeval t_last_activity;
|
||
8 years ago
|
|
||
6 years ago
|
asn1::rrc::establishment_cause_e establishment_cause;
|
||
7 years ago
|
|
||
8 years ago
|
// S-TMSI for this UE
|
||
|
bool has_tmsi;
|
||
|
uint32_t m_tmsi;
|
||
|
uint8_t mmec;
|
||
|
|
||
7 years ago
|
uint32_t rlf_cnt;
|
||
8 years ago
|
uint8_t transaction_id;
|
||
|
rrc_state_t state;
|
||
6 years ago
|
|
||
6 years ago
|
std::map<uint32_t, asn1::rrc::srb_to_add_mod_s> srbs;
|
||
|
std::map<uint32_t, asn1::rrc::drb_to_add_mod_s> drbs;
|
||
6 years ago
|
|
||
8 years ago
|
uint8_t k_enb[32]; // Provided by MME
|
||
|
uint8_t k_rrc_enc[32];
|
||
|
uint8_t k_rrc_int[32];
|
||
|
uint8_t k_up_enc[32];
|
||
|
uint8_t k_up_int[32]; // Not used: only for relay nodes (3GPP 33.401 Annex A.7)
|
||
|
|
||
|
srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo;
|
||
|
srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo;
|
||
|
|
||
|
LIBLTE_S1AP_UEAGGREGATEMAXIMUMBITRATE_STRUCT bitrates;
|
||
|
LIBLTE_S1AP_UESECURITYCAPABILITIES_STRUCT security_capabilities;
|
||
6 years ago
|
asn1::rrc::ue_eutra_cap_s eutra_capabilities;
|
||
8 years ago
|
|
||
|
typedef struct {
|
||
|
uint8_t id;
|
||
|
LIBLTE_S1AP_E_RABLEVELQOSPARAMETERS_STRUCT qos_params;
|
||
|
LIBLTE_S1AP_TRANSPORTLAYERADDRESS_STRUCT address;
|
||
|
uint32_t teid_out;
|
||
|
uint32_t teid_in;
|
||
|
}erab_t;
|
||
|
std::map<uint8_t, erab_t> erabs;
|
||
|
int sr_sched_sf_idx;
|
||
|
int sr_sched_prb_idx;
|
||
|
bool sr_allocated;
|
||
|
uint32_t sr_N_pucch;
|
||
|
uint32_t sr_I;
|
||
6 years ago
|
uint32_t cqi_pucch;
|
||
|
uint32_t cqi_idx;
|
||
|
bool cqi_allocated;
|
||
|
int cqi_sched_sf_idx;
|
||
7 years ago
|
int cqi_sched_prb_idx;
|
||
6 years ago
|
int get_drbid_config(asn1::rrc::drb_to_add_mod_s* drb, int drbid);
|
||
6 years ago
|
bool nas_pending;
|
||
6 years ago
|
srslte::byte_buffer_t erab_info;
|
||
6 years ago
|
};
|
||
|
|
||
|
private:
|
||
8 years ago
|
std::map<uint16_t,ue> users;
|
||
6 years ago
|
|
||
6 years ago
|
std::map<uint32_t, LIBLTE_S1AP_UEPAGINGID_STRUCT > pending_paging;
|
||
8 years ago
|
|
||
6 years ago
|
activity_monitor act_monitor;
|
||
|
|
||
6 years ago
|
std::vector<srslte::unique_byte_buffer_t> sib_buffer;
|
||
8 years ago
|
|
||
|
// user connect notifier
|
||
|
connect_notifier *cnotifier;
|
||
|
|
||
7 years ago
|
void process_release_complete(uint16_t rnti);
|
||
|
void process_rl_failure(uint16_t rnti);
|
||
8 years ago
|
void rem_user(uint16_t rnti);
|
||
|
uint32_t generate_sibs();
|
||
6 years ago
|
void configure_mbsfn_sibs(asn1::rrc::sib_type2_s* sib2, asn1::rrc::sib_type13_r9_s* sib13);
|
||
7 years ago
|
|
||
|
void config_mac();
|
||
6 years ago
|
void parse_ul_dcch(uint16_t rnti, uint32_t lcid, srslte::unique_byte_buffer_t pdu);
|
||
|
void parse_ul_ccch(uint16_t rnti, srslte::unique_byte_buffer_t pdu);
|
||
8 years ago
|
void 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);
|
||
6 years ago
|
void enable_integrity(uint16_t rnti, uint32_t lcid);
|
||
|
void enable_encryption(uint16_t rnti, uint32_t lcid);
|
||
6 years ago
|
srslte::byte_buffer_pool* pool;
|
||
|
srslte::byte_buffer_t byte_buf_paging;
|
||
6 years ago
|
|
||
6 years ago
|
phy_interface_stack_lte* phy;
|
||
6 years ago
|
mac_interface_rrc* mac;
|
||
|
rlc_interface_rrc* rlc;
|
||
|
pdcp_interface_rrc* pdcp;
|
||
|
gtpu_interface_rrc* gtpu;
|
||
|
s1ap_interface_rrc* s1ap;
|
||
|
srslte::log* rrc_log;
|
||
8 years ago
|
|
||
|
typedef struct{
|
||
6 years ago
|
uint16_t rnti;
|
||
|
uint32_t lcid;
|
||
6 years ago
|
srslte::unique_byte_buffer_t pdu;
|
||
8 years ago
|
}rrc_pdu;
|
||
|
|
||
7 years ago
|
const static uint32_t LCID_EXIT = 0xffff0000;
|
||
7 years ago
|
const static uint32_t LCID_REM_USER = 0xffff0001;
|
||
|
const static uint32_t LCID_REL_USER = 0xffff0002;
|
||
|
const static uint32_t LCID_RLF_USER = 0xffff0003;
|
||
|
const static uint32_t LCID_ACT_USER = 0xffff0004;
|
||
8 years ago
|
|
||
|
bool running;
|
||
7 years ago
|
static const int RRC_THREAD_PRIO = 65;
|
||
8 years ago
|
srslte::block_queue<rrc_pdu> rx_pdu_queue;
|
||
|
|
||
6 years ago
|
struct sr_sched_t {
|
||
|
uint32_t nof_users[100][80];
|
||
|
};
|
||
6 years ago
|
|
||
6 years ago
|
sr_sched_t sr_sched;
|
||
|
sr_sched_t cqi_sched;
|
||
|
asn1::rrc::mcch_msg_s mcch;
|
||
|
bool enable_mbms;
|
||
|
rrc_cfg_t cfg;
|
||
|
uint32_t nof_si_messages;
|
||
|
asn1::rrc::sib_type2_s sib2;
|
||
8 years ago
|
|
||
|
void run_thread();
|
||
|
void rem_user_thread(uint16_t rnti);
|
||
|
pthread_mutex_t user_mutex;
|
||
|
|
||
|
pthread_mutex_t paging_mutex;
|
||
|
};
|
||
|
|
||
|
} // namespace srsenb
|
||
|
|
||
7 years ago
|
#endif // SRSENB_RRC_H
|