upgraded to new code restruct

master
Ismael Gomez 7 years ago
parent c47c4b8b03
commit 4b5cbafdb5

@ -101,6 +101,16 @@ public:
virtual void write_pdu(uint32_t lcid, srslte::byte_buffer_t *pdu) = 0;
virtual uint32_t get_ul_count() = 0;
virtual bool get_s_tmsi(LIBLTE_RRC_S_TMSI_STRUCT *s_tmsi) = 0;
virtual void plmn_found(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id, uint16_t tracking_area_code) = 0;
virtual void cell_selected() = 0;
};
// NAS interface for UE
class nas_interface_ue
{
public:
virtual void attach_request() = 0;
virtual void deattach_request() = 0;
};
// RRC interface for MAC
@ -117,6 +127,7 @@ class rrc_interface_phy
public:
virtual void in_sync() = 0;
virtual void out_of_sync() = 0;
virtual void cell_found(uint32_t earfcn, srslte_cell_t phy_cell, float rsrp) = 0;
};
// RRC interface for NAS
@ -127,14 +138,18 @@ public:
virtual uint16_t get_mcc() = 0;
virtual uint16_t get_mnc() = 0;
virtual void enable_capabilities() = 0;
virtual void plmn_search() = 0;
virtual void plmn_select(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id) = 0;
virtual void connect() = 0;
};
// RRC interface for GW
class rrc_interface_gw
{
public:
virtual bool rrc_connected() = 0;
virtual void rrc_connect() = 0;
virtual bool is_connected() = 0;
virtual void connect() = 0;
virtual bool have_drb() = 0;
};
@ -400,8 +415,7 @@ public:
virtual void configure_prach_params() = 0;
/* Start synchronization with strongest cell in the current carrier frequency */
virtual void sync_start() = 0;
virtual void sync_stop() = 0;
virtual bool sync_status() = 0;
/* Sets a C-RNTI allowing the PHY to pregenerate signals if necessary */
virtual void set_crnti(uint16_t rnti) = 0;
@ -462,9 +476,14 @@ public:
virtual void set_config_common(phy_cfg_common_t *common) = 0;
virtual void set_config_tdd(LIBLTE_RRC_TDD_CONFIG_STRUCT *tdd) = 0;
virtual void set_config_64qam_en(bool enable) = 0;
/* Cell search and selection procedures */
virtual void cell_search_start() = 0;
virtual void cell_search_next() = 0;
virtual bool cell_select(uint32_t earfcn, srslte_cell_t cell) = 0;
/* Is the PHY downlink synchronized? */
virtual bool status_is_sync() = 0;
virtual bool sync_status() = 0;
/* Configure UL using parameters written with set_param() */
virtual void configure_ul_params(bool pregen_disabled = false) = 0;

@ -249,8 +249,8 @@ void gw::run_thread()
{
gw_log->info_hex(pdu->msg, pdu->N_bytes, "TX PDU");
while(run_enable && (!rrc->rrc_connected() || !rrc->have_drb())) {
rrc->rrc_connect();
while(run_enable && (!rrc->is_connected() || !rrc->have_drb())) {
rrc->connect();
usleep(1000);
}

@ -51,12 +51,16 @@ public:
void stop();
void set_agc_enable(bool enable);
void resync_sfn();
void resync_sfn();
void set_earfcn(std::vector<uint32_t> earfcn);
void cell_search_start();
void cell_search_next();
bool cell_select(uint32_t earfcn, srslte_cell_t cell);
uint32_t get_current_tti();
void sync_start();
void sync_stop();
bool status_is_sync();
void set_time_adv_sec(float time_adv_sec);
@ -65,7 +69,9 @@ public:
const static int MUTEX_X_WORKER = 4;
private:
std::vector<uint32_t> earfcn;
void set_ue_sync_opts(srslte_ue_sync_t *q);
void run_thread();
int sync_sfn();
@ -91,7 +97,7 @@ private:
sync_metrics_t metrics;
enum {
IDLE, CELL_SEARCH, SYNCING, SYNC_DONE
IDLE, CELL_SEARCH, CELL_SELECT, CAMPING
} phy_state;
srslte_cell_t cell;
@ -111,6 +117,7 @@ private:
uint32_t sync_sfn_cnt;
const static uint32_t SYNC_SFN_TIMEOUT = 5000;
float ul_dl_factor;
int cur_earfcn_index;
bool cell_search(int force_N_id_2 = -1);
bool init_cell();

@ -69,18 +69,21 @@ public:
void enable_pregen_signals(bool enable);
void start_trace();
void write_trace(std::string filename);
void write_trace(std::string filename);
void set_earfcn(std::vector<uint32_t> earfcns);
/********** RRC INTERFACE ********************/
void reset();
bool status_is_sync();
void configure_ul_params(bool pregen_disabled = false);
void resync_sfn();
void resync_sfn();
void cell_search_start();
void cell_search_next();
bool cell_select(uint32_t earfcn, srslte_cell_t phy_cell);
/********** MAC INTERFACE ********************/
/* Functions to synchronize with a cell */
void sync_start();
void sync_stop();
bool sync_status(); // this is also RRC interface
/* Sets a C-RNTI allowing the PHY to pregenerate signals if necessary */
void set_crnti(uint16_t rnti);

@ -39,7 +39,7 @@ using srslte::byte_buffer_t;
namespace srsue {
// EMM states (3GPP 24.302 v10.0.0)
typedef enum{
typedef enum {
EMM_STATE_NULL = 0,
EMM_STATE_DEREGISTERED,
EMM_STATE_REGISTERED_INITIATED,
@ -48,97 +48,133 @@ typedef enum{
EMM_STATE_DEREGISTERED_INITIATED,
EMM_STATE_TAU_INITIATED,
EMM_STATE_N_ITEMS,
}emm_state_t;
static const char emm_state_text[EMM_STATE_N_ITEMS][100] = {"NULL",
"DEREGISTERED",
"REGISTERED INITIATED",
"REGISTERED",
"SERVICE REQUEST INITIATED",
"DEREGISTERED INITIATED",
"TRACKING AREA UPDATE INITIATED"};
class nas
:public nas_interface_rrc
{
public:
nas();
void init(usim_interface_nas *usim_,
rrc_interface_nas *rrc_,
gw_interface_nas *gw_,
srslte::log *nas_log_);
void stop();
emm_state_t get_state();
// RRC interface
void notify_connection_setup();
void write_pdu(uint32_t lcid, byte_buffer_t *pdu);
uint32_t get_ul_count();
bool is_attached();
bool get_s_tmsi(LIBLTE_RRC_S_TMSI_STRUCT *s_tmsi);
private:
srslte::byte_buffer_pool *pool;
srslte::log *nas_log;
rrc_interface_nas *rrc;
usim_interface_nas *usim;
gw_interface_nas *gw;
emm_state_t state;
// Save short MAC
// Identifiers
LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti;
bool is_guti_set;
uint32_t ip_addr;
uint8_t eps_bearer_id;
uint8_t transaction_id;
// NAS counters - incremented for each security-protected message recvd/sent
uint32_t count_ul;
uint32_t count_dl;
// Security
uint8_t ksi;
uint8_t k_nas_enc[32];
uint8_t k_nas_int[32];
srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo;
srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo;
void integrity_generate(uint8_t *key_128,
uint32_t count,
uint8_t rb_id,
uint8_t direction,
uint8_t *msg,
uint32_t msg_len,
uint8_t *mac);
void integrity_check();
void cipher_encrypt();
void cipher_decrypt();
// Parsers
void parse_attach_accept(uint32_t lcid, byte_buffer_t *pdu);
void parse_attach_reject(uint32_t lcid, byte_buffer_t *pdu);
void parse_authentication_request(uint32_t lcid, byte_buffer_t *pdu);
void parse_authentication_reject(uint32_t lcid, byte_buffer_t *pdu);
void parse_identity_request(uint32_t lcid, byte_buffer_t *pdu);
void parse_security_mode_command(uint32_t lcid, byte_buffer_t *pdu);
void parse_service_reject(uint32_t lcid, byte_buffer_t *pdu);
void parse_esm_information_request(uint32_t lcid, byte_buffer_t *pdu);
void parse_emm_information(uint32_t lcid, byte_buffer_t *pdu);
// Senders
void send_attach_request();
void send_identity_response();
void send_service_request();
void send_esm_information_response();
void gen_pdn_connectivity_request(LIBLTE_BYTE_MSG_STRUCT *msg);
};
} emm_state_t;
static const char emm_state_text[EMM_STATE_N_ITEMS][100] = {"NULL",
"DEREGISTERED",
"REGISTERED INITIATED",
"REGISTERED",
"SERVICE REQUEST INITIATED",
"DEREGISTERED INITIATED",
"TRACKING AREA UPDATE INITIATED"};
typedef enum {
PLMN_NOT_SELECTED = 0,
PLMN_SELECTED
} plmn_selection_state_t;
class nas
: public nas_interface_rrc, public nas_interface_ue {
public:
nas();
void init(usim_interface_nas *usim_,
rrc_interface_nas *rrc_,
gw_interface_nas *gw_,
srslte::log *nas_log_);
void stop();
emm_state_t get_state();
// RRC interface
void notify_connection_setup();
void write_pdu(uint32_t lcid, byte_buffer_t *pdu);
uint32_t get_ul_count();
bool is_attached();
bool get_s_tmsi(LIBLTE_RRC_S_TMSI_STRUCT *s_tmsi);
void plmn_found(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id, uint16_t tracking_area_code);
void cell_selected();
// UE interface
void attach_request();
void deattach_request();
private:
srslte::byte_buffer_pool *pool;
srslte::log *nas_log;
rrc_interface_nas *rrc;
usim_interface_nas *usim;
gw_interface_nas *gw;
emm_state_t state;
plmn_selection_state_t plmn_selection;
LIBLTE_RRC_PLMN_IDENTITY_STRUCT current_plmn;
// Save short MAC
// Identifiers
LIBLTE_MME_EPS_MOBILE_ID_GUTI_STRUCT guti;
bool is_guti_set;
uint32_t ip_addr;
uint8_t eps_bearer_id;
uint8_t transaction_id;
// NAS counters - incremented for each security-protected message recvd/sent
uint32_t count_ul;
uint32_t count_dl;
// Security
uint8_t ksi;
uint8_t k_nas_enc[32];
uint8_t k_nas_int[32];
srslte::CIPHERING_ALGORITHM_ID_ENUM cipher_algo;
srslte::INTEGRITY_ALGORITHM_ID_ENUM integ_algo;
void integrity_generate(uint8_t *key_128,
uint32_t count,
uint8_t rb_id,
uint8_t direction,
uint8_t *msg,
uint32_t msg_len,
uint8_t *mac);
void integrity_check();
void cipher_encrypt();
void cipher_decrypt();
// Parsers
void parse_attach_accept(uint32_t lcid, byte_buffer_t *pdu);
void parse_attach_reject(uint32_t lcid, byte_buffer_t *pdu);
void parse_authentication_request(uint32_t lcid, byte_buffer_t *pdu);
void parse_authentication_reject(uint32_t lcid, byte_buffer_t *pdu);
void parse_identity_request(uint32_t lcid, byte_buffer_t *pdu);
void parse_security_mode_command(uint32_t lcid, byte_buffer_t *pdu);
void parse_service_reject(uint32_t lcid, byte_buffer_t *pdu);
void parse_esm_information_request(uint32_t lcid, byte_buffer_t *pdu);
void parse_emm_information(uint32_t lcid, byte_buffer_t *pdu);
// Senders
void send_attach_request();
void send_identity_response();
void send_service_request();
void send_esm_information_response();
void gen_pdn_connectivity_request(LIBLTE_BYTE_MSG_STRUCT *msg);
};
} // namespace srsue

@ -34,6 +34,7 @@
#include "srslte/common/common.h"
#include "srslte/interfaces/ue_interfaces.h"
#include "srslte/common/security.h"
#include "srslte/common/threads.h"
#include <map>
@ -42,168 +43,231 @@ using srslte::byte_buffer_t;
namespace srsue {
// RRC states (3GPP 36.331 v10.0.0)
typedef enum{
typedef enum {
RRC_STATE_IDLE = 0,
RRC_STATE_SIB1_SEARCH,
RRC_STATE_SIB2_SEARCH,
RRC_STATE_WAIT_FOR_CON_SETUP,
RRC_STATE_COMPLETING_SETUP,
RRC_STATE_RRC_CONNECTED,
RRC_STATE_PLMN_SELECTION,
RRC_STATE_CELL_SELECTING,
RRC_STATE_CELL_SELECTED,
RRC_STATE_CONNECTING,
RRC_STATE_CONNECTED,
RRC_STATE_N_ITEMS,
}rrc_state_t;
static const char rrc_state_text[RRC_STATE_N_ITEMS][100] = {"IDLE",
"SIB1_SEARCH",
"SIB2_SEARCH",
"WAIT FOR CON SETUP",
"COMPLETING SETUP",
"RRC CONNECTED"};
class rrc
:public rrc_interface_nas
,public rrc_interface_phy
,public rrc_interface_mac
,public rrc_interface_gw
,public rrc_interface_pdcp
,public rrc_interface_rlc
,public srslte::timer_callback
{
public:
rrc();
void init(phy_interface_rrc *phy_,
mac_interface_rrc *mac_,
rlc_interface_rrc *rlc_,
pdcp_interface_rrc *pdcp_,
nas_interface_rrc *nas_,
usim_interface_rrc *usim_,
srslte::mac_interface_timers *mac_timers_,
srslte::log *rrc_log_);
void stop();
rrc_state_t get_state();
void set_ue_category(int category);
// Timeout callback interface
void timer_expired(uint32_t timeout_id);
void test_con_restablishment();
void liblte_rrc_log(char* str);
private:
srslte::byte_buffer_pool *pool;
srslte::log *rrc_log;
phy_interface_rrc *phy;
mac_interface_rrc *mac;
rlc_interface_rrc *rlc;
pdcp_interface_rrc *pdcp;
nas_interface_rrc *nas;
usim_interface_rrc *usim;
srslte::bit_buffer_t bit_buf;
pthread_mutex_t mutex;
rrc_state_t state;
uint8_t transaction_id;
bool drb_up;
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_RRC_MIB_STRUCT mib;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1_STRUCT sib1;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT sib2;
std::map<uint32_t, LIBLTE_RRC_SRB_TO_ADD_MOD_STRUCT> srbs;
std::map<uint32_t, LIBLTE_RRC_DRB_TO_ADD_MOD_STRUCT> drbs;
LIBLTE_RRC_DL_CCCH_MSG_STRUCT dl_ccch_msg;
LIBLTE_RRC_DL_DCCH_MSG_STRUCT dl_dcch_msg;
pthread_t sib_search_thread;
// RRC constants and timers
srslte::mac_interface_timers *mac_timers;
uint32_t n310_cnt, N310;
uint32_t n311_cnt, N311;
uint32_t t301, t310, t311;
uint32_t safe_reset_timer;
int ue_category;
// NAS interface
void write_sdu(uint32_t lcid, byte_buffer_t *sdu);
uint16_t get_mcc();
uint16_t get_mnc();
void enable_capabilities();
// PHY interface
void in_sync();
void out_of_sync();
// MAC interface
void release_pucch_srs();
void ra_problem();
// GW interface
bool rrc_connected();
void rrc_connect();
bool have_drb();
// PDCP interface
void write_pdu(uint32_t lcid, byte_buffer_t *pdu);
void write_pdu_bcch_bch(byte_buffer_t *pdu);
void write_pdu_bcch_dlsch(byte_buffer_t *pdu);
void write_pdu_pcch(byte_buffer_t *pdu);
// RLC interface
void max_retx_attempted();
// Senders
void send_con_request();
void send_con_restablish_request();
void send_con_restablish_complete();
void send_con_setup_complete(byte_buffer_t *nas_msg);
void send_ul_info_transfer(uint32_t lcid, byte_buffer_t *sdu);
void send_security_mode_complete(uint32_t lcid, byte_buffer_t *pdu);
void send_rrc_con_reconfig_complete(uint32_t lcid, byte_buffer_t *pdu);
void send_rrc_ue_cap_info(uint32_t lcid, byte_buffer_t *pdu);
// Parsers
void parse_dl_ccch(byte_buffer_t *pdu);
void parse_dl_dcch(uint32_t lcid, byte_buffer_t *pdu);
void parse_dl_info_transfer(uint32_t lcid, byte_buffer_t *pdu);
// Helpers
void reset_ue();
void rrc_connection_release();
void radio_link_failure();
static void* start_sib_thread(void *rrc_);
void sib_search();
uint32_t sib_start_tti(uint32_t tti, uint32_t period, uint32_t x);
void apply_sib2_configs();
void handle_con_setup(LIBLTE_RRC_CONNECTION_SETUP_STRUCT *setup);
void handle_con_reest(LIBLTE_RRC_CONNECTION_REESTABLISHMENT_STRUCT *setup);
void handle_rrc_con_reconfig(uint32_t lcid, LIBLTE_RRC_CONNECTION_RECONFIGURATION_STRUCT *reconfig, byte_buffer_t *pdu);
void add_srb(LIBLTE_RRC_SRB_TO_ADD_MOD_STRUCT *srb_cnfg);
void add_drb(LIBLTE_RRC_DRB_TO_ADD_MOD_STRUCT *drb_cnfg);
void release_drb(uint8_t lcid);
void apply_rr_config_dedicated(LIBLTE_RRC_RR_CONFIG_DEDICATED_STRUCT *cnfg);
void apply_phy_config_dedicated(LIBLTE_RRC_PHYSICAL_CONFIG_DEDICATED_STRUCT *phy_cnfg, bool apply_defaults);
void apply_mac_config_dedicated(LIBLTE_RRC_MAC_MAIN_CONFIG_STRUCT *mac_cfg, bool apply_defaults);
// Helpers for setting default values
void set_phy_default_pucch_srs();
void set_phy_default();
void set_mac_default();
void set_rrc_default();
};
} rrc_state_t;
static const char rrc_state_text[RRC_STATE_N_ITEMS][100] = {"IDLE",
"PLMN SELECTION",
"CELL SELECTION",
"CONNECTING",
"CONNECTED",
"RRC CONNECTED"};
typedef enum {
SI_ACQUIRE_IDLE = 0,
SI_ACQUIRE_SIB1,
SI_ACQUIRE_SIB2,
SI_ACQUIRE_DONE
} si_acquire_state_t;
class rrc
: public rrc_interface_nas,
public rrc_interface_phy,
public rrc_interface_mac,
public rrc_interface_gw,
public rrc_interface_pdcp,
public rrc_interface_rlc,
public srslte::timer_callback,
public thread
{
public:
rrc();
void init(phy_interface_rrc *phy_,
mac_interface_rrc *mac_,
rlc_interface_rrc *rlc_,
pdcp_interface_rrc *pdcp_,
nas_interface_rrc *nas_,
usim_interface_rrc *usim_,
srslte::mac_interface_timers *mac_timers_,
srslte::log *rrc_log_);
void stop();
rrc_state_t get_state();
void set_ue_category(int category);
// Timeout callback interface
void timer_expired(uint32_t timeout_id);
void test_con_restablishment();
void liblte_rrc_log(char *str);
private:
srslte::byte_buffer_pool *pool;
srslte::log *rrc_log;
phy_interface_rrc *phy;
mac_interface_rrc *mac;
rlc_interface_rrc *rlc;
pdcp_interface_rrc *pdcp;
nas_interface_rrc *nas;
usim_interface_rrc *usim;
srslte::bit_buffer_t bit_buf;
pthread_mutex_t mutex;
rrc_state_t state;
uint8_t transaction_id;
bool drb_up;
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;
std::map<uint32_t, LIBLTE_RRC_SRB_TO_ADD_MOD_STRUCT> srbs;
std::map<uint32_t, LIBLTE_RRC_DRB_TO_ADD_MOD_STRUCT> drbs;
LIBLTE_RRC_DL_CCCH_MSG_STRUCT dl_ccch_msg;
LIBLTE_RRC_DL_DCCH_MSG_STRUCT dl_dcch_msg;
// RRC constants and timers
srslte::mac_interface_timers *mac_timers;
uint32_t n310_cnt, N310;
uint32_t n311_cnt, N311;
uint32_t t301, t310, t311;
uint32_t safe_reset_timer;
int ue_category;
typedef struct {
uint32_t earfcn;
srslte_cell_t phy_cell;
float rsrp;
bool has_valid_sib1;
bool has_valid_sib2;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1_STRUCT sib1;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT sib2;
} cell_t;
std::vector<cell_t> known_cells;
cell_t *current_cell;
si_acquire_state_t si_acquire_state;
void select_next_cell_in_plmn();
LIBLTE_RRC_PLMN_IDENTITY_STRUCT selected_plmn_id;
int last_selected_cell;
bool thread_running;
void run_thread();
// NAS interface
void write_sdu(uint32_t lcid, byte_buffer_t *sdu);
uint16_t get_mcc();
uint16_t get_mnc();
void enable_capabilities();
void plmn_search();
void plmn_select(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id);
void connect();
// PHY interface
void in_sync();
void out_of_sync();
void cell_found(uint32_t earfcn, srslte_cell_t phy_cell, float rsrp);
// MAC interface
void release_pucch_srs();
void ra_problem();
// GW interface
bool is_connected();
bool have_drb();
// PDCP interface
void write_pdu(uint32_t lcid, byte_buffer_t *pdu);
void write_pdu_bcch_bch(byte_buffer_t *pdu);
void write_pdu_bcch_dlsch(byte_buffer_t *pdu);
void write_pdu_pcch(byte_buffer_t *pdu);
// RLC interface
void max_retx_attempted();
// Senders
void send_con_request();
void send_con_restablish_request();
void send_con_restablish_complete();
void send_con_setup_complete(byte_buffer_t *nas_msg);
void send_ul_info_transfer(uint32_t lcid, byte_buffer_t *sdu);
void send_security_mode_complete(uint32_t lcid, byte_buffer_t *pdu);
void send_rrc_con_reconfig_complete(uint32_t lcid, byte_buffer_t *pdu);
void send_rrc_ue_cap_info(uint32_t lcid, byte_buffer_t *pdu);
// Parsers
void parse_dl_ccch(byte_buffer_t *pdu);
void parse_dl_dcch(uint32_t lcid, byte_buffer_t *pdu);
void parse_dl_info_transfer(uint32_t lcid, byte_buffer_t *pdu);
// Helpers
void reset_ue();
void rrc_connection_release();
void radio_link_failure();
uint32_t sib_start_tti(uint32_t tti, uint32_t period, uint32_t x);
void apply_sib2_configs(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT *sib2);
void handle_con_setup(LIBLTE_RRC_CONNECTION_SETUP_STRUCT *setup);
void handle_con_reest(LIBLTE_RRC_CONNECTION_REESTABLISHMENT_STRUCT *setup);
void
handle_rrc_con_reconfig(uint32_t lcid, LIBLTE_RRC_CONNECTION_RECONFIGURATION_STRUCT *reconfig, byte_buffer_t *pdu);
void add_srb(LIBLTE_RRC_SRB_TO_ADD_MOD_STRUCT *srb_cnfg);
void add_drb(LIBLTE_RRC_DRB_TO_ADD_MOD_STRUCT *drb_cnfg);
void release_drb(uint8_t lcid);
void apply_rr_config_dedicated(LIBLTE_RRC_RR_CONFIG_DEDICATED_STRUCT *cnfg);
void apply_phy_config_dedicated(LIBLTE_RRC_PHYSICAL_CONFIG_DEDICATED_STRUCT *phy_cnfg, bool apply_defaults);
void apply_mac_config_dedicated(LIBLTE_RRC_MAC_MAIN_CONFIG_STRUCT *mac_cfg, bool apply_defaults);
// Helpers for setting default values
void set_phy_default_pucch_srs();
void set_phy_default();
void set_mac_default();
void set_rrc_default();
};
} // namespace srsue

@ -138,24 +138,23 @@ void mac::reset()
void mac::run_thread() {
int cnt=0;
Info("Waiting PHY to synchronize with cell\n");
phy_h->sync_start();
while(!phy_h->get_current_tti() && started) {
usleep(50000);
}
Debug("Setting ttysync to %d\n", phy_h->get_current_tti());
ttisync.set_producer_cntr(phy_h->get_current_tti());
while(started) {
/* Warning: Here order of invocation of procedures is important!! */
ttisync.wait();
tti = phy_h->get_current_tti();
if (started) {
log_h->step(tti);
while (!phy_h->sync_status()) {
usleep(5000);
if (phy_h->sync_status()) {
Debug("Setting ttysync to %d\n", phy_h->get_current_tti());
ttisync.set_producer_cntr(phy_h->get_current_tti());
}
}
if (started && phy_h->sync_status()) {
/* Warning: Here order of invocation of procedures is important!! */
ttisync.wait();
tti = phy_h->get_current_tti();
log_h->step(tti);
timers_db.step_all();
// Step all procedures
@ -488,7 +487,7 @@ void mac::upper_timers::reset()
/********************************************************
*
* Class that runs a thread to process DL MAC PDUs from
* DEMU unit
* DEMUX unit
*
*******************************************************/
mac::pdu_process::pdu_process(demux *demux_unit_)

@ -37,466 +37,510 @@
#define Debug(fmt, ...) if (SRSLTE_DEBUG_ENABLED) log_h->debug_line(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
namespace srsue {
phch_recv::phch_recv() {
running = false;
}
void phch_recv::init(srslte::radio_multi* _radio_handler, mac_interface_phy *_mac, rrc_interface_phy *_rrc,
prach* _prach_buffer, srslte::thread_pool* _workers_pool,
phch_common* _worker_com, srslte::log* _log_h, uint32_t nof_rx_antennas_, uint32_t prio, int sync_cpu_affinity)
{
radio_h = _radio_handler;
log_h = _log_h;
mac = _mac;
rrc = _rrc;
workers_pool = _workers_pool;
worker_com = _worker_com;
prach_buffer = _prach_buffer;
nof_rx_antennas = nof_rx_antennas_;
tx_mutex_cnt = 0;
running = true;
phy_state = IDLE;
time_adv_sec = 0;
cell_is_set = false;
sync_sfn_cnt = 0;
for (uint32_t i=0;i<nof_rx_antennas;i++) {
sf_buffer_sfn[i] = (cf_t*) srslte_vec_malloc(sizeof(cf_t)*3*SRSLTE_SF_LEN_PRB(100));
}
nof_tx_mutex = MUTEX_X_WORKER*workers_pool->get_nof_workers();
worker_com->set_nof_mutex(nof_tx_mutex);
if(sync_cpu_affinity < 0){
start(prio);
} else {
start_cpu(prio, sync_cpu_affinity);
phch_recv::phch_recv() {
running = false;
}
}
void phch_recv::stop() {
running = false;
wait_thread_finish();
for (uint32_t i=0;i<nof_rx_antennas;i++) {
if (sf_buffer_sfn[i]) {
free(sf_buffer_sfn[i]);
void phch_recv::init(srslte::radio_multi *_radio_handler, mac_interface_phy *_mac, rrc_interface_phy *_rrc,
prach *_prach_buffer, srslte::thread_pool *_workers_pool,
phch_common *_worker_com, srslte::log *_log_h, uint32_t nof_rx_antennas_, uint32_t prio,
int sync_cpu_affinity) {
radio_h = _radio_handler;
log_h = _log_h;
mac = _mac;
rrc = _rrc;
workers_pool = _workers_pool;
worker_com = _worker_com;
prach_buffer = _prach_buffer;
nof_rx_antennas = nof_rx_antennas_;
tx_mutex_cnt = 0;
running = true;
phy_state = IDLE;
time_adv_sec = 0;
cell_is_set = false;
sync_sfn_cnt = 0;
for (uint32_t i = 0; i < nof_rx_antennas; i++) {
sf_buffer_sfn[i] = (cf_t *) srslte_vec_malloc(sizeof(cf_t) * 3 * SRSLTE_SF_LEN_PRB(100));
}
}
}
void phch_recv::set_agc_enable(bool enable)
{
do_agc = enable;
}
nof_tx_mutex = MUTEX_X_WORKER * workers_pool->get_nof_workers();
worker_com->set_nof_mutex(nof_tx_mutex);
if (sync_cpu_affinity < 0) {
start(prio);
} else {
start_cpu(prio, sync_cpu_affinity);
}
int radio_recv_wrapper_cs(void *h, cf_t *data[SRSLTE_MAX_PORTS], uint32_t nsamples, srslte_timestamp_t *rx_time)
{
srslte::radio_multi *radio_h = (srslte::radio_multi*) h;
if (radio_h->rx_now(data, nsamples, rx_time)) {
int offset = nsamples-radio_h->get_tti_len();
if (abs(offset)<10 && offset != 0) {
radio_h->tx_offset(offset);
} else if (nsamples<10) {
radio_h->tx_offset(nsamples);
}
void phch_recv::stop() {
running = false;
wait_thread_finish();
for (uint32_t i = 0; i < nof_rx_antennas; i++) {
if (sf_buffer_sfn[i]) {
free(sf_buffer_sfn[i]);
}
}
return nsamples;
} else {
return -1;
}
}
double callback_set_rx_gain(void *h, double gain) {
srslte::radio_multi *radio_handler = (srslte::radio_multi*) h;
return radio_handler->set_rx_gain_th(gain);
}
void phch_recv::set_agc_enable(bool enable) {
do_agc = enable;
}
void phch_recv::set_time_adv_sec(float _time_adv_sec) {
time_adv_sec = _time_adv_sec;
}
int radio_recv_wrapper_cs(void *h, cf_t *data[SRSLTE_MAX_PORTS], uint32_t nsamples, srslte_timestamp_t *rx_time) {
srslte::radio_multi *radio_h = (srslte::radio_multi *) h;
if (radio_h->rx_now(data, nsamples, rx_time)) {
int offset = nsamples - radio_h->get_tti_len();
if (abs(offset) < 10 && offset != 0) {
radio_h->tx_offset(offset);
} else if (nsamples < 10) {
radio_h->tx_offset(nsamples);
}
return nsamples;
} else {
return -1;
}
}
void phch_recv::set_ue_sync_opts(srslte_ue_sync_t *q) {
if (worker_com->args->cfo_integer_enabled) {
srslte_ue_sync_cfo_i_detec_en(q, true);
double callback_set_rx_gain(void *h, double gain) {
srslte::radio_multi *radio_handler = (srslte::radio_multi *) h;
return radio_handler->set_rx_gain_th(gain);
}
float cfo_tol = worker_com->args->cfo_correct_tol_hz;
srslte_cfo_set_tol(&q->strack.cfocorr, cfo_tol/(15000*q->fft_size));
srslte_cfo_set_tol(&q->sfind.cfocorr, cfo_tol/(15000*q->fft_size));
int time_correct_period = worker_com->args->time_correct_period;
if (time_correct_period > 0) {
srslte_ue_sync_set_sample_offset_correct_period(q, time_correct_period);
void phch_recv::set_time_adv_sec(float _time_adv_sec) {
time_adv_sec = _time_adv_sec;
}
sss_alg_t sss_alg = SSS_FULL;
if (!worker_com->args->sss_algorithm.compare("diff")) {
sss_alg = SSS_DIFF;
} else if (!worker_com->args->sss_algorithm.compare("partial")) {
sss_alg = SSS_PARTIAL_3;
} else if (!worker_com->args->sss_algorithm.compare("full")){
sss_alg = SSS_FULL;
} else {
Warning("Invalid SSS algorithm %s. Using 'full'\n", worker_com->args->sss_algorithm.c_str());
void phch_recv::set_ue_sync_opts(srslte_ue_sync_t *q) {
if (worker_com->args->cfo_integer_enabled) {
srslte_ue_sync_cfo_i_detec_en(q, true);
}
float cfo_tol = worker_com->args->cfo_correct_tol_hz;
srslte_cfo_set_tol(&q->strack.cfocorr, cfo_tol / (15000 * q->fft_size));
srslte_cfo_set_tol(&q->sfind.cfocorr, cfo_tol / (15000 * q->fft_size));
int time_correct_period = worker_com->args->time_correct_period;
if (time_correct_period > 0) {
srslte_ue_sync_set_sample_offset_correct_period(q, time_correct_period);
}
sss_alg_t sss_alg = SSS_FULL;
if (!worker_com->args->sss_algorithm.compare("diff")) {
sss_alg = SSS_DIFF;
} else if (!worker_com->args->sss_algorithm.compare("partial")) {
sss_alg = SSS_PARTIAL_3;
} else if (!worker_com->args->sss_algorithm.compare("full")) {
sss_alg = SSS_FULL;
} else {
Warning("Invalid SSS algorithm %s. Using 'full'\n", worker_com->args->sss_algorithm.c_str());
}
srslte_sync_set_sss_algorithm(&q->strack, (sss_alg_t) sss_alg);
srslte_sync_set_sss_algorithm(&q->sfind, (sss_alg_t) sss_alg);
}
srslte_sync_set_sss_algorithm(&q->strack, (sss_alg_t) sss_alg);
srslte_sync_set_sss_algorithm(&q->sfind, (sss_alg_t) sss_alg);
}
bool phch_recv::init_cell() {
cell_is_set = false;
if (!srslte_ue_mib_init(&ue_mib, cell))
{
if (!srslte_ue_sync_init_multi(&ue_sync, cell, radio_recv_wrapper_cs, nof_rx_antennas, radio_h))
{
// Set options defined in expert section
set_ue_sync_opts(&ue_sync);
for (uint32_t i=0;i<workers_pool->get_nof_workers();i++) {
if (!((phch_worker*) workers_pool->get_worker(i))->init_cell(cell)) {
Error("Error setting cell: initiating PHCH worker\n");
return false;
bool phch_recv::init_cell() {
cell_is_set = false;
if (!srslte_ue_mib_init(&ue_mib, cell)) {
if (!srslte_ue_sync_init_multi(&ue_sync, cell, radio_recv_wrapper_cs, nof_rx_antennas, radio_h)) {
// Set options defined in expert section
set_ue_sync_opts(&ue_sync);
for (uint32_t i = 0; i < workers_pool->get_nof_workers(); i++) {
if (!((phch_worker *) workers_pool->get_worker(i))->init_cell(cell)) {
Error("Error setting cell: initiating PHCH worker\n");
return false;
}
}
radio_h->set_tti_len(SRSLTE_SF_LEN_PRB(cell.nof_prb));
if (do_agc) {
srslte_ue_sync_start_agc(&ue_sync, callback_set_rx_gain, last_gain);
}
srslte_ue_sync_set_cfo(&ue_sync, cellsearch_cfo);
cell_is_set = true;
} else {
Error("Error setting cell: initiating ue_sync");
}
radio_h->set_tti_len(SRSLTE_SF_LEN_PRB(cell.nof_prb));
if (do_agc) {
srslte_ue_sync_start_agc(&ue_sync, callback_set_rx_gain, last_gain);
}
srslte_ue_sync_set_cfo(&ue_sync, cellsearch_cfo);
cell_is_set = true;
} else {
Error("Error setting cell: initiating ue_sync");
Error("Error setting cell: initiating ue_mib\n");
}
} else {
Error("Error setting cell: initiating ue_mib\n");
}
return cell_is_set;
}
return cell_is_set;
}
void phch_recv::free_cell()
{
if (cell_is_set) {
for (uint32_t i=0;i<workers_pool->get_nof_workers();i++) {
((phch_worker*) workers_pool->get_worker(i))->free_cell();
void phch_recv::free_cell() {
if (phy_state != IDLE) {
phy_state = IDLE;
usleep(2000);
}
if (cell_is_set) {
for (uint32_t i = 0; i < workers_pool->get_nof_workers(); i++) {
((phch_worker *) workers_pool->get_worker(i))->free_cell();
}
prach_buffer->free_cell();
cell_is_set = false;
}
prach_buffer->free_cell();
}
}
bool phch_recv::cell_search(int force_N_id_2)
{
uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
uint8_t bch_payload_bits[SRSLTE_BCH_PAYLOAD_LEN/8];
srslte_ue_cellsearch_result_t found_cells[3];
srslte_ue_cellsearch_t cs;
bool phch_recv::cell_search(int force_N_id_2) {
uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
uint8_t bch_payload_bits[SRSLTE_BCH_PAYLOAD_LEN / 8];
bzero(found_cells, 3*sizeof(srslte_ue_cellsearch_result_t));
srslte_ue_cellsearch_result_t found_cells[3];
srslte_ue_cellsearch_t cs;
log_h->console("Searching for cell...\n");
if (srslte_ue_cellsearch_init_multi(&cs, SRSLTE_DEFAULT_MAX_FRAMES_PSS, radio_recv_wrapper_cs, nof_rx_antennas, radio_h)) {
Error("Initiating UE cell search\n");
return false;
}
srslte_ue_cellsearch_set_nof_valid_frames(&cs, SRSLTE_DEFAULT_NOF_VALID_PSS_FRAMES);
// Set options defined in expert section
set_ue_sync_opts(&cs.ue_sync);
if (do_agc) {
srslte_ue_sync_start_agc(&cs.ue_sync, callback_set_rx_gain, last_gain);
}
radio_h->set_rx_srate(1.92e6);
radio_h->start_rx();
/* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */
uint32_t max_peak_cell = 0;
int ret = SRSLTE_ERROR;
if (force_N_id_2 >= 0 && force_N_id_2 < 3) {
ret = srslte_ue_cellsearch_scan_N_id_2(&cs, force_N_id_2, &found_cells[force_N_id_2]);
max_peak_cell = force_N_id_2;
} else {
ret = srslte_ue_cellsearch_scan(&cs, found_cells, &max_peak_cell);
}
bzero(found_cells, 3 * sizeof(srslte_ue_cellsearch_result_t));
log_h->console("Searching for cell...\n");
if (srslte_ue_cellsearch_init_multi(&cs, SRSLTE_DEFAULT_MAX_FRAMES_PSS, radio_recv_wrapper_cs, nof_rx_antennas,
radio_h)) {
Error("Initiating UE cell search\n");
return false;
}
last_gain = srslte_agc_get_gain(&cs.ue_sync.agc);
srslte_ue_cellsearch_set_nof_valid_frames(&cs, SRSLTE_DEFAULT_NOF_VALID_PSS_FRAMES);
radio_h->stop_rx();
srslte_ue_cellsearch_free(&cs);
if (ret < 0) {
Error("Error decoding MIB: Error searching PSS\n");
return false;
} else if (ret == 0) {
Error("Error decoding MIB: Could not find any PSS in this frequency\n");
return false;
}
// Save result
cell.id = found_cells[max_peak_cell].cell_id;
cell.cp = found_cells[max_peak_cell].cp;
cellsearch_cfo = found_cells[max_peak_cell].cfo;
log_h->console("Found CELL ID: %d CP: %s, CFO: %.1f KHz.\nTrying to decode MIB...\n",
cell.id, srslte_cp_string(cell.cp), cellsearch_cfo/1000);
srslte_ue_mib_sync_t ue_mib_sync;
if (srslte_ue_mib_sync_init_multi(&ue_mib_sync, cell.id, cell.cp, radio_recv_wrapper_cs, nof_rx_antennas, radio_h)) {
Error("Initiating UE MIB synchronization\n");
return false;
// Set options defined in expert section
set_ue_sync_opts(&cs.ue_sync);
if (do_agc) {
srslte_ue_sync_start_agc(&cs.ue_sync, callback_set_rx_gain, last_gain);
}
radio_h->set_rx_srate(1.92e6);
radio_h->start_rx();
/* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */
uint32_t max_peak_cell = 0;
int ret = SRSLTE_ERROR;
if (force_N_id_2 >= 0 && force_N_id_2 < 3) {
ret = srslte_ue_cellsearch_scan_N_id_2(&cs, force_N_id_2, &found_cells[force_N_id_2]);
max_peak_cell = force_N_id_2;
} else {
ret = srslte_ue_cellsearch_scan(&cs, found_cells, &max_peak_cell);
}
last_gain = srslte_agc_get_gain(&cs.ue_sync.agc);
radio_h->stop_rx();
srslte_ue_cellsearch_free(&cs);
if (ret < 0) {
Error("Error decoding MIB: Error searching PSS\n");
return false;
} else if (ret == 0) {
Error("Error decoding MIB: Could not find any PSS in this frequency\n");
return false;
}
// Save result
cell.id = found_cells[max_peak_cell].cell_id;
cell.cp = found_cells[max_peak_cell].cp;
cellsearch_cfo = found_cells[max_peak_cell].cfo;
log_h->console("Found CELL ID: %d CP: %s, CFO: %.1f KHz.\nTrying to decode MIB...\n",
cell.id, srslte_cp_string(cell.cp), cellsearch_cfo / 1000);
srslte_ue_mib_sync_t ue_mib_sync;
if (srslte_ue_mib_sync_init_multi(&ue_mib_sync, cell.id, cell.cp, radio_recv_wrapper_cs, nof_rx_antennas,
radio_h)) {
Error("Initiating UE MIB synchronization\n");
return false;
}
// Set options defined in expert section
set_ue_sync_opts(&ue_mib_sync.ue_sync);
if (do_agc) {
srslte_ue_sync_start_agc(&ue_mib_sync.ue_sync, callback_set_rx_gain, last_gain);
}
srslte_ue_sync_set_cfo(&ue_mib_sync.ue_sync, cellsearch_cfo);
/* Find and decode MIB */
uint32_t sfn;
int sfn_offset;
radio_h->start_rx();
ret = srslte_ue_mib_sync_decode(&ue_mib_sync,
SRSLTE_DEFAULT_MAX_FRAMES_PBCH,
bch_payload, &cell.nof_ports, &sfn_offset);
radio_h->stop_rx();
last_gain = srslte_agc_get_gain(&ue_mib_sync.ue_sync.agc);
cellsearch_cfo = srslte_ue_sync_get_cfo(&ue_mib_sync.ue_sync);
srslte_ue_mib_sync_free(&ue_mib_sync);
if (ret == 1) {
srslte_pbch_mib_unpack(bch_payload, &cell, NULL);
worker_com->set_cell(cell);
srslte_cell_fprint(stdout, &cell, 0);
srslte_bit_pack_vector(bch_payload, bch_payload_bits, SRSLTE_BCH_PAYLOAD_LEN);
mac->bch_decoded_ok(bch_payload_bits, SRSLTE_BCH_PAYLOAD_LEN / 8);
return true;
} else {
Warning("Error decoding MIB: Error decoding PBCH\n");
return false;
}
}
// Set options defined in expert section
set_ue_sync_opts(&ue_mib_sync.ue_sync);
if (do_agc) {
srslte_ue_sync_start_agc(&ue_mib_sync.ue_sync, callback_set_rx_gain, last_gain);
int phch_recv::sync_sfn(void) {
int ret = SRSLTE_ERROR;
uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
srslte_ue_sync_decode_sss_on_track(&ue_sync, true);
ret = srslte_ue_sync_zerocopy_multi(&ue_sync, sf_buffer_sfn);
if (ret < 0) {
Error("Error calling ue_sync_get_buffer");
return -1;
}
if (ret == 1) {
if (srslte_ue_sync_get_sfidx(&ue_sync) == 0) {
int sfn_offset = 0;
Info("SYNC: Decoding MIB...\n");
int n = srslte_ue_mib_decode(&ue_mib, sf_buffer_sfn[0], bch_payload, NULL, &sfn_offset);
if (n < 0) {
Error("Error decoding MIB while synchronising SFN");
return -1;
} else if (n == SRSLTE_UE_MIB_FOUND) {
uint32_t sfn;
srslte_pbch_mib_unpack(bch_payload, &cell, &sfn);
sfn = (sfn+sfn_offset)%1024;
tti = sfn * 10;
srslte_ue_sync_decode_sss_on_track(&ue_sync, true);
Info("SYNC: DONE, TTI=%d, sfn_offset=%d\n", tti, sfn_offset);
srslte_ue_mib_reset(&ue_mib);
return 1;
}
}
} else {
Debug("SYNC: PSS/SSS not found...\n");
}
return 0;
}
srslte_ue_sync_set_cfo(&ue_mib_sync.ue_sync, cellsearch_cfo);
/* Find and decode MIB */
uint32_t sfn;
int sfn_offset;
radio_h->start_rx();
ret = srslte_ue_mib_sync_decode(&ue_mib_sync,
SRSLTE_DEFAULT_MAX_FRAMES_PBCH,
bch_payload, &cell.nof_ports, &sfn_offset);
radio_h->stop_rx();
last_gain = srslte_agc_get_gain(&ue_mib_sync.ue_sync.agc);
cellsearch_cfo = srslte_ue_sync_get_cfo(&ue_mib_sync.ue_sync);
srslte_ue_mib_sync_free(&ue_mib_sync);
if (ret == 1) {
srslte_pbch_mib_unpack(bch_payload, &cell, NULL);
worker_com->set_cell(cell);
srslte_cell_fprint(stdout, &cell, 0);
srslte_bit_pack_vector(bch_payload, bch_payload_bits, SRSLTE_BCH_PAYLOAD_LEN);
mac->bch_decoded_ok(bch_payload_bits, SRSLTE_BCH_PAYLOAD_LEN/8);
return true;
} else {
Warning("Error decoding MIB: Error decoding PBCH\n");
return false;
void phch_recv::resync_sfn() {
sync_sfn_cnt = 0;
phy_state = CELL_SELECT;
}
}
void phch_recv::set_earfcn(std::vector<uint32_t> earfcn) {
this->earfcn = earfcn;
}
int phch_recv::sync_sfn(void) {
int ret = SRSLTE_ERROR;
uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
void phch_recv::cell_search_next() {
cur_earfcn_index++;
if (cur_earfcn_index >= 0) {
if ((uint32_t) cur_earfcn_index >= earfcn.size() - 1) {
cur_earfcn_index = 0;
}
// If PHY is running, stop and free resources
free_cell();
float dl_freq = srslte_band_fd(earfcn[cur_earfcn_index]);
if (dl_freq >= 0) {
log_h->console("Cell Search: Set DL EARFCN=%d, frequency=%.1f MHz\n", earfcn[cur_earfcn_index], dl_freq / 1e6);
log_h->info("Cell Search: Set DL EARFCN=%d, frequency=%.1f MHz, channel_index=%d\n", earfcn[cur_earfcn_index],
dl_freq / 1e6, cur_earfcn_index);
radio_h->set_rx_freq(dl_freq);
// Start PHY cell search (finds maximum cell in frequency)
phy_state = CELL_SEARCH;
} else {
log_h->error("Cell Search: Invalid EARFCN=%d, channel_index=%d\n", earfcn[cur_earfcn_index], cur_earfcn_index);
}
}
}
srslte_ue_sync_decode_sss_on_track(&ue_sync, true);
ret = srslte_ue_sync_zerocopy_multi(&ue_sync, sf_buffer_sfn);
if (ret < 0) {
Error("Error calling ue_sync_get_buffer");
return -1;
void phch_recv::cell_search_start() {
cur_earfcn_index = -1;
log_h->console("Cell Search: Starting procedure...\n");
log_h->info("Cell Search: Starting procedure...\n");
cell_search_next();
}
if (ret == 1) {
if (srslte_ue_sync_get_sfidx(&ue_sync) == 0) {
int sfn_offset=0;
Info("SYNC: Decoding MIB...\n");
int n = srslte_ue_mib_decode(&ue_mib, sf_buffer_sfn[0], bch_payload, NULL, &sfn_offset);
if (n < 0) {
Error("Error decoding MIB while synchronising SFN");
return -1;
} else if (n == SRSLTE_UE_MIB_FOUND) {
uint32_t sfn;
srslte_pbch_mib_unpack(bch_payload, &cell, &sfn);
sfn = (sfn + sfn_offset)%1024;
tti = sfn*10;
srslte_ue_sync_decode_sss_on_track(&ue_sync, true);
Info("SYNC: DONE, TTI=%d, sfn_offset=%d\n", tti, sfn_offset);
srslte_ue_mib_reset(&ue_mib);
return 1;
bool phch_recv::cell_select(uint32_t earfcn, srslte_cell_t cell) {
free_cell();
float dl_freq = srslte_band_fd(earfcn);
float ul_freq = srslte_band_ul_earfcn(earfcn);
if (dl_freq >= 0 || ul_freq <= 0) {
log_h->console("Cell Select: Set EARFCN=%d, DL frequency=%.1f MHz, UL frequency=%.1f MHz\n", earfcn,
dl_freq / 1e6, ul_freq / 1e6);
log_h->info("Cell Select: Set EARFCN=%d, frequency=%.1f MHz, UL frequency=%.1f MHz\n", earfcn, dl_freq / 1e6,
ul_freq / 1e6);
radio_h->set_rx_freq(dl_freq);
radio_h->set_tx_freq(ul_freq);
this->cell = cell;
if (init_cell()) {
phy_state = CELL_SELECT;
return true;
} else {
log_h->error("Cell Select: Initializing cell in EARFCN=%d, PCI=%d\n", earfcn, cell.id);
}
}
} else {
Debug("SYNC: PSS/SSS not found...\n");
} else {
log_h->error("Cell Select: Invalid EARFCN=%d\n", earfcn);
}
return false;
}
return 0;
}
void phch_recv::resync_sfn() {
sync_sfn_cnt = 0;
phy_state = SYNCING;
}
void phch_recv::run_thread() {
int sync_res;
phch_worker *worker = NULL;
cf_t *buffer[SRSLTE_MAX_PORTS];
while (running) {
switch (phy_state) {
case CELL_SEARCH:
if (cell_search()) {
log_h->console("Initializating cell configuration...\n");
init_cell();
float srate = (float) srslte_sampling_freq_hz(cell.nof_prb);
if (30720 % ((int) srate / 1000) == 0) {
radio_h->set_master_clock_rate(30.72e6);
} else {
radio_h->set_master_clock_rate(23.04e6);
}
void phch_recv::run_thread()
{
int sync_res;
phch_worker *worker = NULL;
cf_t *buffer[SRSLTE_MAX_PORTS];
while(running) {
switch(phy_state) {
case CELL_SEARCH:
if (cell_search()) {
log_h->console("Initializating cell configuration...\n");
init_cell();
float srate = (float) srslte_sampling_freq_hz(cell.nof_prb);
if (30720%((int) srate/1000) == 0) {
radio_h->set_master_clock_rate(30.72e6);
} else {
radio_h->set_master_clock_rate(23.04e6);
log_h->console("Setting Sampling frequency %.2f MHz\n", (float) srate / 1000000);
radio_h->set_rx_srate(srate);
radio_h->set_tx_srate(srate);
ul_dl_factor = radio_h->get_tx_freq() / radio_h->get_rx_freq();
Info("SYNC: Cell found. Synchronizing...\n");
phy_state = CELL_SELECT;
sync_sfn_cnt = 0;
srslte_ue_mib_reset(&ue_mib);
}
log_h->console("Setting Sampling frequency %.2f MHz\n", (float) srate/1000000);
radio_h->set_rx_srate(srate);
radio_h->set_tx_srate(srate);
break;
case CELL_SELECT:
ul_dl_factor = radio_h->get_tx_freq()/radio_h->get_rx_freq();
srslte_ue_sync_decode_sss_on_track(&ue_sync, true);
Info("SYNC: Cell found. Synchronizing...\n");
phy_state = SYNCING;
sync_sfn_cnt = 0;
srslte_ue_mib_reset(&ue_mib);
}
break;
case SYNCING:
srslte_ue_sync_decode_sss_on_track(&ue_sync, true);
if (!radio_is_streaming) {
// Start streaming
radio_h->start_rx();
radio_is_streaming = true;
}
switch(sync_sfn()) {
default:
log_h->console("Going IDLE\n");
phy_state = IDLE;
break;
case 1:
srslte_ue_sync_set_agc_period(&ue_sync, 20);
phy_state = SYNC_DONE;
break;
case 0:
break;
}
sync_sfn_cnt++;
if (sync_sfn_cnt >= SYNC_SFN_TIMEOUT) {
sync_sfn_cnt = 0;
radio_h->stop_rx();
radio_is_streaming = false;
log_h->console("Timeout while synchronizing SFN\n");
log_h->warning("Timeout while synchronizing SFN\n");
}
break;
case SYNC_DONE:
tti = (tti+1)%10240;
worker = (phch_worker*) workers_pool->wait_worker(tti);
sync_res = 0;
if (worker) {
for (uint32_t i=0;i<nof_rx_antennas;i++) {
buffer[i] = worker->get_buffer(i);
if (!radio_is_streaming) {
// Start streaming
radio_h->start_rx();
radio_is_streaming = true;
}
switch (sync_sfn()) {
default:
log_h->console("Going IDLE\n");
phy_state = IDLE;
break;
case 1:
srslte_ue_sync_set_agc_period(&ue_sync, 20);
phy_state = CAMPING;
break;
case 0:
break;
}
sync_sfn_cnt++;
if (sync_sfn_cnt >= SYNC_SFN_TIMEOUT) {
sync_sfn_cnt = 0;
radio_h->stop_rx();
radio_is_streaming = false;
log_h->console("Timeout while synchronizing SFN\n");
log_h->warning("Timeout while synchronizing SFN\n");
}
break;
case CAMPING:
tti = (tti+1) % 10240;
worker = (phch_worker *) workers_pool->wait_worker(tti);
sync_res = 0;
if (worker) {
for (uint32_t i = 0; i < nof_rx_antennas; i++) {
buffer[i] = worker->get_buffer(i);
}
sync_res = srslte_ue_sync_zerocopy_multi(&ue_sync, buffer);
if (sync_res == 1) {
log_h->step(tti);
Debug("Worker %d synchronized\n", worker->get_id());
metrics.sfo = srslte_ue_sync_get_sfo(&ue_sync);
metrics.cfo = srslte_ue_sync_get_cfo(&ue_sync);
worker->set_cfo(ul_dl_factor*metrics.cfo/15000);
worker_com->set_sync_metrics(metrics);
float sample_offset = (float) srslte_ue_sync_get_sfo(&ue_sync)/1000;
worker->set_sample_offset(sample_offset);
/* Compute TX time: Any transmission happens in TTI+4 thus advance 4 ms the reception time */
srslte_timestamp_t rx_time, tx_time, tx_time_prach;
srslte_ue_sync_get_last_timestamp(&ue_sync, &rx_time);
srslte_timestamp_copy(&tx_time, &rx_time);
srslte_timestamp_add(&tx_time, 0, 4e-3 - time_adv_sec);
worker->set_tx_time(tx_time);
Debug("Settting TTI=%d, tx_mutex=%d to worker %d\n", tti, tx_mutex_cnt, worker->get_id());
worker->set_tti(tti, tx_mutex_cnt);
tx_mutex_cnt = (tx_mutex_cnt+1)%nof_tx_mutex;
// Check if we need to TX a PRACH
if (prach_buffer->is_ready_to_send(tti)) {
srslte_timestamp_copy(&tx_time_prach, &rx_time);
srslte_timestamp_add(&tx_time_prach, 0, prach::tx_advance_sf*1e-3);
prach_buffer->send(radio_h, ul_dl_factor*metrics.cfo/15000, worker_com->pathloss, tx_time_prach);
radio_h->tx_end();
worker_com->p0_preamble = prach_buffer->get_p0_preamble();
worker_com->cur_radio_power = SRSLTE_MIN(SRSLTE_PC_MAX, worker_com->pathloss + worker_com->p0_preamble);
}
workers_pool->start_worker(worker);
// Notify RRC in-sync every 1 frame
if ((tti%10) == 0) {
rrc->in_sync();
log_h->debug("Sending in-sync to RRC\n");
sync_res = srslte_ue_sync_zerocopy_multi(&ue_sync, buffer);
if (sync_res == 1) {
log_h->step(tti);
Debug("Worker %d synchronized\n", worker->get_id());
metrics.sfo = srslte_ue_sync_get_sfo(&ue_sync);
metrics.cfo = srslte_ue_sync_get_cfo(&ue_sync);
worker->set_cfo(ul_dl_factor * metrics.cfo / 15000);
worker_com->set_sync_metrics(metrics);
float sample_offset = (float) srslte_ue_sync_get_sfo(&ue_sync) / 1000;
worker->set_sample_offset(sample_offset);
/* Compute TX time: Any transmission happens in TTI4 thus advance 4 ms the reception time */
srslte_timestamp_t rx_time, tx_time, tx_time_prach;
srslte_ue_sync_get_last_timestamp(&ue_sync, &rx_time);
srslte_timestamp_copy(&tx_time, &rx_time);
srslte_timestamp_add(&tx_time, 0, 4e-3 - time_adv_sec);
worker->set_tx_time(tx_time);
Debug("Settting TTI=%d, tx_mutex=%d to worker %d\n", tti, tx_mutex_cnt, worker->get_id());
worker->set_tti(tti, tx_mutex_cnt);
tx_mutex_cnt = (tx_mutex_cnt+1) % nof_tx_mutex;
// Check if we need to TX a PRACH
if (prach_buffer->is_ready_to_send(tti)) {
srslte_timestamp_copy(&tx_time_prach, &rx_time);
srslte_timestamp_add(&tx_time_prach, 0, prach::tx_advance_sf * 1e-3);
prach_buffer->send(radio_h, ul_dl_factor * metrics.cfo / 15000, worker_com->pathloss, tx_time_prach);
radio_h->tx_end();
worker_com->p0_preamble = prach_buffer->get_p0_preamble();
worker_com->cur_radio_power = SRSLTE_MIN(SRSLTE_PC_MAX, worker_com->pathloss+worker_com->p0_preamble);
}
workers_pool->start_worker(worker);
// Notify RRC in-sync every 1 frame
if ((tti % 10) == 0) {
rrc->in_sync();
log_h->debug("Sending in-sync to RRC\n");
}
} else {
log_h->console("Sync error.\n");
log_h->error("Sync error. Sending out-of-sync to RRC\n");
// Notify RRC of out-of-sync frame
rrc->out_of_sync();
worker->release();
worker_com->reset_ul();
phy_state = CELL_SELECT;
}
} else {
log_h->console("Sync error.\n");
log_h->error("Sync error. Sending out-of-sync to RRC\n");
// Notify RRC of out-of-sync frame
rrc->out_of_sync();
worker->release();
worker_com->reset_ul();
phy_state = SYNCING;
// wait_worker() only returns NULL if it's being closed. Quit now to avoid unnecessary loops here
running = false;
}
} else {
// wait_worker() only returns NULL if it's being closed. Quit now to avoid unnecessary loops here
running = false;
}
break;
case IDLE:
usleep(1000);
break;
break;
case IDLE:
usleep(1000);
break;
}
}
}
}
uint32_t phch_recv::get_current_tti()
{
return tti;
}
bool phch_recv::status_is_sync()
{
return phy_state == SYNC_DONE;
}
void phch_recv::get_current_cell(srslte_cell_t* cell_)
{
if (cell_) {
memcpy(cell_, &cell, sizeof(srslte_cell_t));
uint32_t phch_recv::get_current_tti() {
return tti;
}
}
void phch_recv::sync_start()
{
radio_h->set_master_clock_rate(30.72e6);
phy_state = CELL_SEARCH;
}
void phch_recv::sync_stop()
{
free_cell();
radio_h->stop_rx();
radio_is_streaming = false;
phy_state = IDLE;
}
bool phch_recv::status_is_sync() {
return phy_state == CAMPING;
}
void phch_recv::get_current_cell(srslte_cell_t *cell_) {
if (cell_) {
memcpy(cell_, &cell, sizeof(srslte_cell_t));
}
}
}

@ -205,6 +205,21 @@ void phy::configure_ul_params(bool pregen_disabled)
}
}
void phy::cell_search_start()
{
sf_recv.cell_search_start();
}
void phy::cell_search_next()
{
sf_recv.cell_search_next();
}
bool phy::cell_select(uint32_t earfcn, srslte_cell_t phy_cell)
{
return sf_recv.cell_select(earfcn, phy_cell);
}
float phy::get_phr()
{
float phr = radio_handler->get_max_tx_power() - workers_common.cur_pusch_power;
@ -280,23 +295,18 @@ int phy::sr_last_tx_tti()
return workers_common.sr_last_tx_tti;
}
bool phy::status_is_sync()
{
return sf_recv.status_is_sync();
}
void phy::resync_sfn() {
sf_recv.resync_sfn();
}
void phy::sync_start()
void phy::set_earfcn(vector< uint32_t > earfcns)
{
sf_recv.sync_start();
sf_recv.set_earfcn(earfcns);
}
void phy::sync_stop()
bool phy::sync_status()
{
sf_recv.sync_stop();
return sf_recv.status_is_sync();
}
void phy::set_rar_grant(uint32_t tti, uint8_t grant_payload[SRSLTE_RAR_GRANT_LEN])

@ -178,11 +178,6 @@ bool ue::init(all_args_t *args_)
radio.register_error_handler(rf_msg);
radio.set_rx_freq(args->rf.dl_freq);
radio.set_tx_freq(args->rf.ul_freq);
phy_log.console("Setting frequency: DL=%.1f Mhz, UL=%.1f MHz\n", args->rf.dl_freq/1e6, args->rf.ul_freq/1e6);
mac.init(&phy, &rlc, &rrc, &mac_log);
rlc.init(&pdcp, &rrc, this, &rlc_log, &mac);
pdcp.init(&rlc, &rrc, &gw, &pdcp_log, SECURITY_DIRECTION_UPLINK);
@ -258,7 +253,7 @@ bool ue::get_metrics(ue_metrics_t &m)
rf_metrics.rf_error = false; // Reset error flag
if(EMM_STATE_REGISTERED == nas.get_state()) {
if(RRC_STATE_RRC_CONNECTED == rrc.get_state()) {
if(RRC_STATE_CONNECTED == rrc.get_state()) {
phy.get_metrics(m.phy);
mac.get_metrics(m.mac);
rlc.get_metrics(m.rlc);

@ -29,42 +29,72 @@
using namespace srslte;
namespace srsue{
nas::nas()
:state(EMM_STATE_DEREGISTERED)
,is_guti_set(false)
,ip_addr(0)
,eps_bearer_id(0)
,count_ul(0)
,count_dl(0)
{}
void nas::init(usim_interface_nas *usim_,
rrc_interface_nas *rrc_,
gw_interface_nas *gw_,
srslte::log *nas_log_)
{
pool = byte_buffer_pool::get_instance();
usim = usim_;
rrc = rrc_;
gw = gw_;
nas_log = nas_log_;
}
namespace srsue {
nas::nas()
: state(EMM_STATE_DEREGISTERED), plmn_selection(PLMN_SELECTED), is_guti_set(false), ip_addr(0), eps_bearer_id(0),
count_ul(0), count_dl(0) {}
void nas::init(usim_interface_nas *usim_,
rrc_interface_nas *rrc_,
gw_interface_nas *gw_,
srslte::log *nas_log_) {
pool = byte_buffer_pool::get_instance();
usim = usim_;
rrc = rrc_;
gw = gw_;
nas_log = nas_log_;
state = EMM_STATE_DEREGISTERED;
void nas::stop()
{}
// Manual PLMN selection procedure
current_plmn.mcc = 1;
current_plmn.mnc = 1;
plmn_selection = PLMN_SELECTED;
}
emm_state_t nas::get_state()
{
return state;
}
void nas::stop() {}
emm_state_t nas::get_state() {
return state;
}
/*******************************************************************************
UE interface
*******************************************************************************/
void nas::attach_request() {
if (state == EMM_STATE_DEREGISTERED) {
state = EMM_STATE_REGISTERED_INITIATED;
if (plmn_selection == PLMN_NOT_SELECTED) {
rrc->plmn_search();
} else if (plmn_selection == PLMN_SELECTED) {
rrc->plmn_select(current_plmn);
}
} else {
nas_log->info("Attach request ignored. State = %s\n", emm_state_text[state]);
}
}
void nas::deattach_request() {
state = EMM_STATE_DEREGISTERED_INITIATED;
nas_log->info("Dettach request not supported\n");
}
/*******************************************************************************
RRC interface
*******************************************************************************/
void nas::plmn_found(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id, uint16_t tracking_area_code) {
// if it's the plmn we want rrc->plmn_select() and plmn_selection = PLMN_SELECTED
}
void nas::cell_selected() {
if (state == EMM_STATE_REGISTERED_INITIATED) {
rrc->connect();
} else {
nas_log->info("Cell selcted in invalid state = %s\n", emm_state_text[state]);
}
}
bool nas::is_attached()
{
return state == EMM_STATE_REGISTERED;
@ -73,7 +103,7 @@ bool nas::is_attached()
void nas::notify_connection_setup()
{
nas_log->debug("State = %s\n", emm_state_text[state]);
if(EMM_STATE_DEREGISTERED == state) {
if(EMM_STATE_REGISTERED_INITIATED == state) {
send_attach_request();
} else {
send_service_request();

@ -29,7 +29,6 @@
#include <sstream>
#include "upper/rrc.h"
#include "srslte/phy/utils/bit.h"
#include "srslte/common/security.h"
#include "srslte/common/bcd_helpers.h"
@ -39,6 +38,11 @@ using namespace srslte;
namespace srsue{
/*******************************************************************************
Base functions
*******************************************************************************/
rrc::rrc()
:state(RRC_STATE_IDLE)
,drb_up(false)
@ -76,6 +80,11 @@ void rrc::init(phy_interface_rrc *phy_,
usim = usim_;
rrc_log = rrc_log_;
mac_timers = mac_timers_;
state = RRC_STATE_IDLE;
si_acquire_state = SI_ACQUIRE_IDLE;
thread_running = true;
start();
pthread_mutex_init(&mutex, NULL);
@ -93,7 +102,10 @@ void rrc::init(phy_interface_rrc *phy_,
}
void rrc::stop()
{}
{
thread_running = false;
wait_thread_finish();
}
rrc_state_t rrc::get_state()
{
@ -110,66 +122,127 @@ void rrc::set_ue_category(int category)
}
/*******************************************************************************
*
*
*
* PLMN selection, cell selection/reselection and acquisition of SI procedures
*
*
*
*******************************************************************************/
/*******************************************************************************
NAS interface
*******************************************************************************/
void rrc::write_sdu(uint32_t lcid, byte_buffer_t *sdu)
uint16_t rrc::get_mcc()
{
rrc_log->info_hex(sdu->msg, sdu->N_bytes, "RX %s SDU", rb_id_text[lcid]);
switch(state)
{
case RRC_STATE_COMPLETING_SETUP:
send_con_setup_complete(sdu);
break;
case RRC_STATE_RRC_CONNECTED:
send_ul_info_transfer(lcid, sdu);
break;
default:
rrc_log->error("SDU received from NAS while RRC state = %s", rrc_state_text[state]);
break;
if (current_cell) {
if(current_cell->sib1.N_plmn_ids > 0) {
return current_cell->sib1.plmn_id[0].id.mcc;
}
}
return 0;
}
uint16_t rrc::get_mcc()
uint16_t rrc::get_mnc()
{
if(sib1.N_plmn_ids > 0)
return sib1.plmn_id[0].id.mcc;
else
return 0;
if (current_cell) {
if(current_cell->sib1.N_plmn_ids > 0) {
return current_cell->sib1.plmn_id[0].id.mnc;
}
}
return 0;
}
uint16_t rrc::get_mnc()
void rrc::plmn_search()
{
if(sib1.N_plmn_ids > 0)
return sib1.plmn_id[0].id.mnc;
else
return 0;
state = RRC_STATE_PLMN_SELECTION;
phy->cell_search_start();
}
/*******************************************************************************
MAC interface
*******************************************************************************/
/* Reception of PUCCH/SRS release procedure (Section 5.3.13) */
void rrc::release_pucch_srs()
void rrc::plmn_select(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id)
{
// Apply default configuration for PUCCH (CQI and SR) and SRS (release)
set_phy_default_pucch_srs();
bool sync_ok = false;
// Configure RX signals without pregeneration because default option is release
phy->configure_ul_params(true);
state = RRC_STATE_CELL_SELECTING;
// Sort cells according to RSRP
selected_plmn_id = plmn_id;
last_selected_cell = -1;
select_next_cell_in_plmn();
}
void rrc::ra_problem() {
radio_link_failure();
void rrc::connect()
{
pthread_mutex_lock(&mutex);
if(RRC_STATE_CELL_SELECTED == state) {
if (si_acquire_state == SI_ACQUIRE_IDLE) {
rrc_log->info("RRC in IDLE state - sending connection request.\n");
state = RRC_STATE_CONNECTING;
send_con_request();
} else {
rrc_log->warning("Received connect() but SI not acquired\n");
}
} else {
rrc_log->warning("Received connect() but cell is not selected\n");
}
pthread_mutex_unlock(&mutex);
}
void rrc::select_next_cell_in_plmn() {
for (uint32_t i=last_selected_cell+1;i<known_cells.size();i++) {
for (uint32_t j=0;j<known_cells[i].sib1.N_plmn_ids;j++) {
if (known_cells[i].sib1.plmn_id[j].id.mcc == selected_plmn_id.mcc ||
known_cells[i].sib1.plmn_id[j].id.mnc == selected_plmn_id.mnc)
{
// Check that cell satisfies S criteria
if (phy->cell_select(known_cells[i].earfcn, known_cells[i].phy_cell)) {
si_acquire_state = SI_ACQUIRE_SIB1;
last_selected_cell = i;
return;
}
}
}
}
}
/*******************************************************************************
PHY interface
*******************************************************************************/
void rrc::cell_found(uint32_t earfcn, srslte_cell_t phy_cell, float rsrp) {
// find if cell_id-earfcn combination already exists
for (uint32_t i=0;i<known_cells.size();i++) {
if (earfcn == known_cells[i].earfcn && phy_cell.id == known_cells[i].phy_cell.id) {
known_cells[i].rsrp = rsrp;
current_cell = &known_cells[i];
rrc_log->info("Updating cell EARFCN=%d, PCI=%d, RSRP=%d dBm\n", known_cells[i].earfcn, known_cells[i].phy_cell.id, known_cells[i].rsrp);
return;
}
}
// add to list of known cells
cell_t cell;
cell.phy_cell = phy_cell;
cell.rsrp = rsrp;
cell.earfcn = earfcn;
cell.has_valid_sib1 = false;
cell.has_valid_sib2 = false;
known_cells.push_back(cell);
// save current cell
current_cell = &known_cells.back();
rrc_log->info("Found new cell EARFCN=%d, PCI=%d, RSRP=%d dBm\n", cell.earfcn, cell.phy_cell.id, cell.rsrp);
}
// Detection of physical layer problems (5.3.11.1)
void rrc::out_of_sync()
{
@ -198,22 +271,236 @@ void rrc::in_sync()
}
/*******************************************************************************
GW interface
PDCP interface
*******************************************************************************/
void rrc::write_pdu_bcch_bch(byte_buffer_t *pdu)
{
pool->deallocate(pdu);
if (state == RRC_STATE_PLMN_SELECTION) {
// Do we need to do something with BCH?
rrc_log->info_hex(pdu->msg, pdu->N_bytes, "BCCH BCH message received.");
si_acquire_state = SI_ACQUIRE_SIB1;
} else {
rrc_log->warning("Received BCCH BCH in incorrect state\n");
}
}
bool rrc::rrc_connected()
void rrc::write_pdu_bcch_dlsch(byte_buffer_t *pdu)
{
return (RRC_STATE_RRC_CONNECTED == state);
rrc_log->info_hex(pdu->msg, pdu->N_bytes, "BCCH DLSCH message received.");
rrc_log->info("BCCH DLSCH message Stack latency: %ld us\n", pdu->get_latency_us());
LIBLTE_RRC_BCCH_DLSCH_MSG_STRUCT dlsch_msg;
srslte_bit_unpack_vector(pdu->msg, bit_buf.msg, pdu->N_bytes*8);
bit_buf.N_bits = pdu->N_bytes*8;
pool->deallocate(pdu);
liblte_rrc_unpack_bcch_dlsch_msg((LIBLTE_BIT_MSG_STRUCT*)&bit_buf, &dlsch_msg);
if (dlsch_msg.N_sibs > 0) {
if (LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1 == dlsch_msg.sibs[0].sib_type && SI_ACQUIRE_SIB1 == si_acquire_state)
{
mac->bcch_stop_rx();
// Handle SIB1
memcpy(&current_cell->sib1, &dlsch_msg.sibs[0].sib.sib1, sizeof(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1_STRUCT));
rrc_log->info("SIB1 received, CellID=%d, si_window=%d, sib2_period=%d\n",
current_cell->sib1.cell_id&0xfff,
liblte_rrc_si_window_length_num[current_cell->sib1.si_window_length],
liblte_rrc_si_periodicity_num[current_cell->sib1.sched_info[0].si_periodicity]);
// Send PLMN and TAC to NAS
std::stringstream ss;
for(uint32_t i=0;i<current_cell->sib1.N_plmn_ids;i++){
std::string mcc;
std::string mnc;
mcc_to_string(current_cell->sib1.plmn_id[i].id.mcc, &mcc);
mnc_to_string(current_cell->sib1.plmn_id[i].id.mnc, &mnc);
ss << " PLMN Id: MCC " << mcc << " MNC " << mnc;
nas->plmn_found(current_cell->sib1.plmn_id[i].id, current_cell->sib1.tracking_area_code);
}
// Set TDD Config
if (current_cell->sib1.tdd) {
phy->set_config_tdd(&current_cell->sib1.tdd_cnfg);
}
rrc_log->console("SIB1 received, CellID=%d, %s\n",
current_cell->sib1.cell_id&0xfff,
ss.str().c_str());
current_cell->has_valid_sib1 = true;
si_acquire_state = SI_ACQUIRE_SIB2;
} else if (LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2 == dlsch_msg.sibs[0].sib_type && SI_ACQUIRE_SIB2 == si_acquire_state)
{
mac->bcch_stop_rx();
// Handle SIB2
memcpy(&current_cell->sib2, &dlsch_msg.sibs[0].sib.sib2, sizeof(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT));
rrc_log->console("SIB2 received\n");
rrc_log->info("SIB2 received\n");
apply_sib2_configs(&current_cell->sib2);
current_cell->has_valid_sib2 = true;
si_acquire_state = SI_ACQUIRE_IDLE;
}
}
}
void rrc::rrc_connect() {
pthread_mutex_lock(&mutex);
if(RRC_STATE_IDLE == state) {
rrc_log->info("RRC in IDLE state - sending connection request.\n");
state = RRC_STATE_WAIT_FOR_CON_SETUP;
send_con_request();
// Right now, this thread only controls System Information acquisition procedure
void rrc::run_thread()
{
uint32_t tti ;
uint32_t si_win_start, si_win_len;
uint16_t period;
uint32_t nof_sib1_trials = 0;
const int SIB1_SEARCH_TIMEOUT = 30;
while(thread_running)
{
switch(si_acquire_state)
{
case SI_ACQUIRE_SIB1:
// Instruct MAC to look for SIB1
if (!current_cell->has_valid_sib1) {
tti = mac->get_current_tti();
si_win_start = sib_start_tti(tti, 2, 5);
mac->bcch_start_rx(si_win_start, 1);
rrc_log->debug("Instructed MAC to search for SIB1, win_start=%d, win_len=%d\n",
si_win_start, 1);
nof_sib1_trials++;
if (nof_sib1_trials >= SIB1_SEARCH_TIMEOUT) {
if (state == RRC_STATE_CELL_SELECTING) {
select_next_cell_in_plmn();
si_acquire_state = SI_ACQUIRE_IDLE;
} else if (state == RRC_STATE_PLMN_SELECTION) {
phy->cell_search_next();
}
nof_sib1_trials = 0;
}
} else {
si_acquire_state = SI_ACQUIRE_SIB2;
}
break;
case SI_ACQUIRE_SIB2:
// Instruct MAC to look for SIB2 only when selecting a cell
if (state == RRC_STATE_CELL_SELECTING && !current_cell->has_valid_sib2) {
tti = mac->get_current_tti();
period = liblte_rrc_si_periodicity_num[current_cell->sib1.sched_info[0].si_periodicity];
si_win_start = sib_start_tti(tti, period, 0);
si_win_len = liblte_rrc_si_window_length_num[current_cell->sib1.si_window_length];
mac->bcch_start_rx(si_win_start, si_win_len);
rrc_log->debug("Instructed MAC to search for SIB2, win_start=%d, win_len=%d\n",
si_win_start, si_win_len);
} else {
si_acquire_state = SI_ACQUIRE_DONE;
}
break;
case SI_ACQUIRE_DONE:
// After acquiring SI, tell NAS that the cell is selected or go to next cell in case of PLMN selection
if (state == RRC_STATE_CELL_SELECTING) {
nas->cell_selected();
state = RRC_STATE_CELL_SELECTED;
} else if (state == RRC_STATE_PLMN_SELECTION) {
phy->cell_search_next();
}
si_acquire_state = SI_ACQUIRE_IDLE;
break;
default:
break;
}
usleep(10000);
}
pthread_mutex_unlock(&mutex);
}
/*******************************************************************************
*
*
*
* Connection control and establishment/reestablishment procedures
*
*
*
*******************************************************************************/
/*******************************************************************************
NAS interface
*******************************************************************************/
void rrc::write_sdu(uint32_t lcid, byte_buffer_t *sdu)
{
rrc_log->info_hex(sdu->msg, sdu->N_bytes, "RX %s SDU", rb_id_text[lcid]);
switch(state)
{
case RRC_STATE_CONNECTING:
send_con_setup_complete(sdu);
break;
case RRC_STATE_CONNECTED:
send_ul_info_transfer(lcid, sdu);
break;
default:
rrc_log->error("SDU received from NAS while RRC state = %s", rrc_state_text[state]);
break;
}
}
/*******************************************************************************
MAC interface
*******************************************************************************/
/* Reception of PUCCH/SRS release procedure (Section 5.3.13) */
void rrc::release_pucch_srs()
{
// Apply default configuration for PUCCH (CQI and SR) and SRS (release)
set_phy_default_pucch_srs();
// Configure RX signals without pregeneration because default option is release
phy->configure_ul_params(true);
}
void rrc::ra_problem() {
radio_link_failure();
}
/*******************************************************************************
GW interface
*******************************************************************************/
bool rrc::is_connected()
{
return (RRC_STATE_CONNECTED == state);
}
bool rrc::have_drb()
@ -246,75 +533,6 @@ void rrc::write_pdu(uint32_t lcid, byte_buffer_t *pdu)
}
void rrc::write_pdu_bcch_bch(byte_buffer_t *pdu)
{
// Unpack the MIB
rrc_log->info_hex(pdu->msg, pdu->N_bytes, "BCCH BCH message received.");
rrc_log->info("BCCH BCH message Stack latency: %ld us\n", pdu->get_latency_us());
srslte_bit_unpack_vector(pdu->msg, bit_buf.msg, pdu->N_bytes*8);
bit_buf.N_bits = pdu->N_bytes*8;
pool->deallocate(pdu);
liblte_rrc_unpack_bcch_bch_msg((LIBLTE_BIT_MSG_STRUCT*)&bit_buf, &mib);
rrc_log->info("MIB received BW=%s MHz\n", liblte_rrc_dl_bandwidth_text[mib.dl_bw]);
rrc_log->console("MIB received BW=%s MHz\n", liblte_rrc_dl_bandwidth_text[mib.dl_bw]);
// Start the SIB search state machine
state = RRC_STATE_SIB1_SEARCH;
pthread_create(&sib_search_thread, NULL, &rrc::start_sib_thread, this);
}
void rrc::write_pdu_bcch_dlsch(byte_buffer_t *pdu)
{
rrc_log->info_hex(pdu->msg, pdu->N_bytes, "BCCH DLSCH message received.");
rrc_log->info("BCCH DLSCH message Stack latency: %ld us\n", pdu->get_latency_us());
LIBLTE_RRC_BCCH_DLSCH_MSG_STRUCT dlsch_msg;
srslte_bit_unpack_vector(pdu->msg, bit_buf.msg, pdu->N_bytes*8);
bit_buf.N_bits = pdu->N_bytes*8;
pool->deallocate(pdu);
liblte_rrc_unpack_bcch_dlsch_msg((LIBLTE_BIT_MSG_STRUCT*)&bit_buf, &dlsch_msg);
if (dlsch_msg.N_sibs > 0) {
if (LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1 == dlsch_msg.sibs[0].sib_type && RRC_STATE_SIB1_SEARCH == state) {
// Handle SIB1
memcpy(&sib1, &dlsch_msg.sibs[0].sib.sib1, sizeof(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1_STRUCT));
rrc_log->info("SIB1 received, CellID=%d, si_window=%d, sib2_period=%d\n",
sib1.cell_id&0xfff,
liblte_rrc_si_window_length_num[sib1.si_window_length],
liblte_rrc_si_periodicity_num[sib1.sched_info[0].si_periodicity]);
std::stringstream ss;
for(uint32_t i=0;i<sib1.N_plmn_ids;i++){
std::string mcc;
std::string mnc;
mcc_to_string(sib1.plmn_id[i].id.mcc, &mcc);
mnc_to_string(sib1.plmn_id[i].id.mnc, &mnc);
ss << " PLMN Id: MCC " << mcc << " MNC " << mnc;
}
// Set TDD Config
if (dlsch_msg.sibs[0].sib.sib1.tdd) {
phy->set_config_tdd(&dlsch_msg.sibs[0].sib.sib1.tdd_cnfg);
}
rrc_log->console("SIB1 received, CellID=%d, %s\n",
sib1.cell_id&0xfff,
ss.str().c_str());
state = RRC_STATE_SIB2_SEARCH;
mac->bcch_stop_rx();
//TODO: Use all SIB1 info
} else if (LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2 == dlsch_msg.sibs[0].sib_type && RRC_STATE_SIB2_SEARCH == state) {
// Handle SIB2
memcpy(&sib2, &dlsch_msg.sibs[0].sib.sib2, sizeof(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT));
rrc_log->console("SIB2 received\n");
rrc_log->info("SIB2 received\n");
state = RRC_STATE_WAIT_FOR_CON_SETUP;
mac->bcch_stop_rx();
apply_sib2_configs();
send_con_request();
}
}
}
void rrc::write_pdu_pcch(byte_buffer_t *pdu)
{
@ -352,7 +570,7 @@ void rrc::write_pdu_pcch(byte_buffer_t *pdu)
mac->pcch_stop_rx();
if(RRC_STATE_IDLE == state) {
rrc_log->info("RRC in IDLE state - sending connection request.\n");
state = RRC_STATE_WAIT_FOR_CON_SETUP;
state = RRC_STATE_CONNECTING;
send_con_request();
}
}
@ -400,7 +618,7 @@ void rrc::send_con_request()
bit_buf.msg[bit_buf.N_bits + i] = 0;
bit_buf.N_bits += 8 - (bit_buf.N_bits % 8);
}
byte_buffer_t *pdcp_buf = pool_allocate;
byte_buffer_t *pdcp_buf = pool_allocate;;
srslte_bit_pack_vector(bit_buf.msg, pdcp_buf->msg, bit_buf.N_bits);
pdcp_buf->N_bytes = bit_buf.N_bits/8;
pdcp_buf->set_timestamp();
@ -417,7 +635,6 @@ void rrc::send_con_request()
mac->set_contention_id(uecri);
rrc_log->info("Sending RRC Connection Request on SRB0\n");
state = RRC_STATE_WAIT_FOR_CON_SETUP;
pdcp->write_sdu(RB_ID_SRB0, pdcp_buf);
}
@ -478,7 +695,7 @@ void rrc::send_con_restablish_request()
// Wait for cell re-synchronization
uint32_t timeout_cnt = 0;
while(!phy->status_is_sync() && timeout_cnt < TIMEOUT_RESYNC_REESTABLISH){
while(!phy->sync_status() && timeout_cnt < TIMEOUT_RESYNC_REESTABLISH){
usleep(10000);
timeout_cnt++;
}
@ -494,7 +711,7 @@ void rrc::send_con_restablish_request()
bit_buf.msg[bit_buf.N_bits + i] = 0;
bit_buf.N_bits += 8 - (bit_buf.N_bits % 8);
}
byte_buffer_t *pdcp_buf = pool_allocate;
byte_buffer_t *pdcp_buf = pool_allocate;;
srslte_bit_pack_vector(bit_buf.msg, pdcp_buf->msg, bit_buf.N_bits);
pdcp_buf->N_bytes = bit_buf.N_bits/8;
@ -509,7 +726,6 @@ void rrc::send_con_restablish_request()
mac->set_contention_id(uecri);
rrc_log->info("Sending RRC Connection Resetablishment Request on SRB0\n");
state = RRC_STATE_WAIT_FOR_CON_SETUP;
pdcp->write_sdu(RB_ID_SRB0, pdcp_buf);
}
@ -531,11 +747,11 @@ void rrc::send_con_restablish_complete()
bit_buf.msg[bit_buf.N_bits + i] = 0;
bit_buf.N_bits += 8 - (bit_buf.N_bits % 8);
}
byte_buffer_t *pdcp_buf = pool_allocate;
byte_buffer_t *pdcp_buf = pool_allocate;;
srslte_bit_pack_vector(bit_buf.msg, pdcp_buf->msg, bit_buf.N_bits);
pdcp_buf->N_bytes = bit_buf.N_bits/8;
state = RRC_STATE_RRC_CONNECTED;
state = RRC_STATE_CONNECTED;
rrc_log->console("RRC Connected\n");
rrc_log->info("Sending RRC Connection Reestablishment Complete\n");
pdcp->write_sdu(RB_ID_SRB1, pdcp_buf);
@ -562,12 +778,12 @@ void rrc::send_con_setup_complete(byte_buffer_t *nas_msg)
bit_buf.msg[bit_buf.N_bits + i] = 0;
bit_buf.N_bits += 8 - (bit_buf.N_bits % 8);
}
byte_buffer_t *pdcp_buf = pool_allocate;
byte_buffer_t *pdcp_buf = pool_allocate;;
srslte_bit_pack_vector(bit_buf.msg, pdcp_buf->msg, bit_buf.N_bits);
pdcp_buf->N_bytes = bit_buf.N_bits/8;
pdcp_buf->set_timestamp();
state = RRC_STATE_RRC_CONNECTED;
state = RRC_STATE_CONNECTED;
rrc_log->console("RRC Connected\n");
rrc_log->info("Sending RRC Connection Setup Complete\n");
pdcp->write_sdu(RB_ID_SRB1, pdcp_buf);
@ -654,7 +870,7 @@ void rrc::send_rrc_con_reconfig_complete(uint32_t lcid, byte_buffer_t *pdu)
void rrc::enable_capabilities()
{
bool enable_ul_64 = ue_category>=5 && sib2.rr_config_common_sib.pusch_cnfg.enable_64_qam;
bool enable_ul_64 = ue_category>=5 && current_cell->sib2.rr_config_common_sib.pusch_cnfg.enable_64_qam;
rrc_log->info("%s 64QAM PUSCH\n", enable_ul_64?"Enabling":"Disabling");
phy->set_config_64qam_en(enable_ul_64);
}
@ -766,7 +982,6 @@ void rrc::parse_dl_ccch(byte_buffer_t *pdu)
transaction_id = dl_ccch_msg.msg.rrc_con_setup.rrc_transaction_id;
handle_con_setup(&dl_ccch_msg.msg.rrc_con_setup);
rrc_log->info("Notifying NAS of connection setup\n");
state = RRC_STATE_COMPLETING_SETUP;
nas->notify_connection_setup();
break;
case LIBLTE_RRC_DL_CCCH_MSG_TYPE_RRC_CON_REEST:
@ -904,108 +1119,44 @@ void rrc::radio_link_failure() {
rrc_log->warning("Detected Radio-Link Failure\n");
rrc_log->console("Warning: Detected Radio-Link Failure\n");
if (state != RRC_STATE_RRC_CONNECTED) {
if (state != RRC_STATE_CONNECTED) {
rrc_connection_release();
} else {
send_con_restablish_request();
}
}
void* rrc::start_sib_thread(void *rrc_)
{
rrc *r = (rrc*)rrc_;
r->sib_search();
return NULL;
}
void rrc::sib_search()
{
bool searching = true;
uint32_t tti ;
uint32_t si_win_start, si_win_len;
uint16_t period;
uint32_t nof_sib1_trials = 0;
const int SIB1_SEARCH_TIMEOUT = 30;
while(searching)
{
switch(state)
{
case RRC_STATE_SIB1_SEARCH:
// Instruct MAC to look for SIB1
while(!phy->status_is_sync()){
usleep(50000);
}
usleep(10000);
tti = mac->get_current_tti();
si_win_start = sib_start_tti(tti, 2, 5);
mac->bcch_start_rx(si_win_start, 1);
rrc_log->debug("Instructed MAC to search for SIB1, win_start=%d, win_len=%d\n",
si_win_start, 1);
nof_sib1_trials++;
if (nof_sib1_trials >= SIB1_SEARCH_TIMEOUT) {
rrc_log->info("Timeout while searching for SIB1. Resynchronizing SFN...\n");
rrc_log->console("Timeout while searching for SIB1. Resynchronizing SFN...\n");
phy->resync_sfn();
nof_sib1_trials = 0;
}
break;
case RRC_STATE_SIB2_SEARCH:
// Instruct MAC to look for SIB2
usleep(10000);
tti = mac->get_current_tti();
period = liblte_rrc_si_periodicity_num[sib1.sched_info[0].si_periodicity];
si_win_start = sib_start_tti(tti, period, 0);
si_win_len = liblte_rrc_si_window_length_num[sib1.si_window_length];
mac->bcch_start_rx(si_win_start, si_win_len);
rrc_log->debug("Instructed MAC to search for SIB2, win_start=%d, win_len=%d\n",
si_win_start, si_win_len);
break;
default:
searching = false;
break;
}
usleep(100000);
}
}
// Determine SI messages scheduling as in 36.331 5.2.3 Acquisition of an SI message
uint32_t rrc::sib_start_tti(uint32_t tti, uint32_t period, uint32_t x) {
return (period*10*(1+tti/(period*10))+x)%10240; // the 1 means next opportunity
}
void rrc::apply_sib2_configs()
void rrc::apply_sib2_configs(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT *sib2)
{
if(RRC_STATE_WAIT_FOR_CON_SETUP != state){
rrc_log->error("State must be RRC_STATE_WAIT_FOR_CON_SETUP to handle SIB2. Actual state: %s\n",
rrc_state_text[state]);
return;
}
// Apply RACH timeAlginmentTimer configuration
mac_interface_rrc::mac_cfg_t cfg;
mac->get_config(&cfg);
cfg.main.time_alignment_timer = sib2.time_alignment_timer;
memcpy(&cfg.rach, &sib2.rr_config_common_sib.rach_cnfg, sizeof(LIBLTE_RRC_RACH_CONFIG_COMMON_STRUCT));
cfg.prach_config_index = sib2.rr_config_common_sib.prach_cnfg.root_sequence_index;
cfg.main.time_alignment_timer = sib2->time_alignment_timer;
memcpy(&cfg.rach, &sib2->rr_config_common_sib.rach_cnfg, sizeof(LIBLTE_RRC_RACH_CONFIG_COMMON_STRUCT));
cfg.prach_config_index = sib2->rr_config_common_sib.prach_cnfg.root_sequence_index;
mac->set_config(&cfg);
rrc_log->info("Set RACH ConfigCommon: NofPreambles=%d, ResponseWindow=%d, ContentionResolutionTimer=%d ms\n",
liblte_rrc_number_of_ra_preambles_num[sib2.rr_config_common_sib.rach_cnfg.num_ra_preambles],
liblte_rrc_ra_response_window_size_num[sib2.rr_config_common_sib.rach_cnfg.ra_resp_win_size],
liblte_rrc_mac_contention_resolution_timer_num[sib2.rr_config_common_sib.rach_cnfg.mac_con_res_timer]);
liblte_rrc_number_of_ra_preambles_num[sib2->rr_config_common_sib.rach_cnfg.num_ra_preambles],
liblte_rrc_ra_response_window_size_num[sib2->rr_config_common_sib.rach_cnfg.ra_resp_win_size],
liblte_rrc_mac_contention_resolution_timer_num[sib2->rr_config_common_sib.rach_cnfg.mac_con_res_timer]);
// Apply PHY RR Config Common
phy_interface_rrc::phy_cfg_common_t common;
memcpy(&common.pdsch_cnfg, &sib2.rr_config_common_sib.pdsch_cnfg, sizeof(LIBLTE_RRC_PDSCH_CONFIG_COMMON_STRUCT));
memcpy(&common.pusch_cnfg, &sib2.rr_config_common_sib.pusch_cnfg, sizeof(LIBLTE_RRC_PUSCH_CONFIG_COMMON_STRUCT));
memcpy(&common.pucch_cnfg, &sib2.rr_config_common_sib.pucch_cnfg, sizeof(LIBLTE_RRC_PUCCH_CONFIG_COMMON_STRUCT));
memcpy(&common.ul_pwr_ctrl, &sib2.rr_config_common_sib.ul_pwr_ctrl, sizeof(LIBLTE_RRC_UL_POWER_CONTROL_COMMON_STRUCT));
memcpy(&common.prach_cnfg, &sib2.rr_config_common_sib.prach_cnfg, sizeof(LIBLTE_RRC_PRACH_CONFIG_SIB_STRUCT));
if (sib2.rr_config_common_sib.srs_ul_cnfg.present) {
memcpy(&common.srs_ul_cnfg, &sib2.rr_config_common_sib.srs_ul_cnfg, sizeof(LIBLTE_RRC_SRS_UL_CONFIG_COMMON_STRUCT));
memcpy(&common.pdsch_cnfg, &sib2->rr_config_common_sib.pdsch_cnfg, sizeof(LIBLTE_RRC_PDSCH_CONFIG_COMMON_STRUCT));
memcpy(&common.pusch_cnfg, &sib2->rr_config_common_sib.pusch_cnfg, sizeof(LIBLTE_RRC_PUSCH_CONFIG_COMMON_STRUCT));
memcpy(&common.pucch_cnfg, &sib2->rr_config_common_sib.pucch_cnfg, sizeof(LIBLTE_RRC_PUCCH_CONFIG_COMMON_STRUCT));
memcpy(&common.ul_pwr_ctrl, &sib2->rr_config_common_sib.ul_pwr_ctrl, sizeof(LIBLTE_RRC_UL_POWER_CONTROL_COMMON_STRUCT));
memcpy(&common.prach_cnfg, &sib2->rr_config_common_sib.prach_cnfg, sizeof(LIBLTE_RRC_PRACH_CONFIG_SIB_STRUCT));
if (sib2->rr_config_common_sib.srs_ul_cnfg.present) {
memcpy(&common.srs_ul_cnfg, &sib2->rr_config_common_sib.srs_ul_cnfg, sizeof(LIBLTE_RRC_SRS_UL_CONFIG_COMMON_STRUCT));
} else {
// default is release
common.srs_ul_cnfg.present = false;
@ -1015,34 +1166,34 @@ void rrc::apply_sib2_configs()
phy->configure_ul_params();
rrc_log->info("Set PUSCH ConfigCommon: HopOffset=%d, RSGroup=%d, RSNcs=%d, N_sb=%d\n",
sib2.rr_config_common_sib.pusch_cnfg.pusch_hopping_offset,
sib2.rr_config_common_sib.pusch_cnfg.ul_rs.group_assignment_pusch,
sib2.rr_config_common_sib.pusch_cnfg.ul_rs.cyclic_shift,
sib2.rr_config_common_sib.pusch_cnfg.n_sb);
sib2->rr_config_common_sib.pusch_cnfg.pusch_hopping_offset,
sib2->rr_config_common_sib.pusch_cnfg.ul_rs.group_assignment_pusch,
sib2->rr_config_common_sib.pusch_cnfg.ul_rs.cyclic_shift,
sib2->rr_config_common_sib.pusch_cnfg.n_sb);
rrc_log->info("Set PUCCH ConfigCommon: DeltaShift=%d, CyclicShift=%d, N1=%d, NRB=%d\n",
liblte_rrc_delta_pucch_shift_num[sib2.rr_config_common_sib.pucch_cnfg.delta_pucch_shift],
sib2.rr_config_common_sib.pucch_cnfg.n_cs_an,
sib2.rr_config_common_sib.pucch_cnfg.n1_pucch_an,
sib2.rr_config_common_sib.pucch_cnfg.n_rb_cqi);
liblte_rrc_delta_pucch_shift_num[sib2->rr_config_common_sib.pucch_cnfg.delta_pucch_shift],
sib2->rr_config_common_sib.pucch_cnfg.n_cs_an,
sib2->rr_config_common_sib.pucch_cnfg.n1_pucch_an,
sib2->rr_config_common_sib.pucch_cnfg.n_rb_cqi);
rrc_log->info("Set PRACH ConfigCommon: SeqIdx=%d, HS=%s, FreqOffset=%d, ZC=%d, ConfigIndex=%d\n",
sib2.rr_config_common_sib.prach_cnfg.root_sequence_index,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.high_speed_flag?"yes":"no",
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.prach_freq_offset,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.zero_correlation_zone_config,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.prach_config_index);
sib2->rr_config_common_sib.prach_cnfg.root_sequence_index,
sib2->rr_config_common_sib.prach_cnfg.prach_cnfg_info.high_speed_flag?"yes":"no",
sib2->rr_config_common_sib.prach_cnfg.prach_cnfg_info.prach_freq_offset,
sib2->rr_config_common_sib.prach_cnfg.prach_cnfg_info.zero_correlation_zone_config,
sib2->rr_config_common_sib.prach_cnfg.prach_cnfg_info.prach_config_index);
rrc_log->info("Set SRS ConfigCommon: BW-Configuration=%d, SF-Configuration=%d, ACKNACK=%s\n",
liblte_rrc_srs_bw_config_num[sib2.rr_config_common_sib.srs_ul_cnfg.bw_cnfg],
liblte_rrc_srs_subfr_config_num[sib2.rr_config_common_sib.srs_ul_cnfg.subfr_cnfg],
sib2.rr_config_common_sib.srs_ul_cnfg.ack_nack_simul_tx?"yes":"no");
mac_timers->get(t301)->set(this, liblte_rrc_t301_num[sib2.ue_timers_and_constants.t301]);
mac_timers->get(t310)->set(this, liblte_rrc_t310_num[sib2.ue_timers_and_constants.t310]);
mac_timers->get(t311)->set(this, liblte_rrc_t311_num[sib2.ue_timers_and_constants.t311]);
N310 = liblte_rrc_n310_num[sib2.ue_timers_and_constants.n310];
N311 = liblte_rrc_n311_num[sib2.ue_timers_and_constants.n311];
liblte_rrc_srs_bw_config_num[sib2->rr_config_common_sib.srs_ul_cnfg.bw_cnfg],
liblte_rrc_srs_subfr_config_num[sib2->rr_config_common_sib.srs_ul_cnfg.subfr_cnfg],
sib2->rr_config_common_sib.srs_ul_cnfg.ack_nack_simul_tx?"yes":"no");
mac_timers->get(t301)->set(this, liblte_rrc_t301_num[sib2->ue_timers_and_constants.t301]);
mac_timers->get(t310)->set(this, liblte_rrc_t310_num[sib2->ue_timers_and_constants.t310]);
mac_timers->get(t311)->set(this, liblte_rrc_t311_num[sib2->ue_timers_and_constants.t311]);
N310 = liblte_rrc_n310_num[sib2->ue_timers_and_constants.n310];
N311 = liblte_rrc_n311_num[sib2->ue_timers_and_constants.n311];
rrc_log->info("Set Constants and Timers: N310=%d, N311=%d, t301=%d, t310=%d, t311=%d\n",
N310, N311, mac_timers->get(t301)->get_timeout(),
@ -1309,7 +1460,7 @@ void rrc::handle_rrc_con_reconfig(uint32_t lcid, LIBLTE_RRC_CONNECTION_RECONFIGU
byte_buffer_t *nas_sdu;
for(i=0;i<reconfig->N_ded_info_nas;i++)
{
nas_sdu = pool_allocate;
nas_sdu = pool_allocate;;
memcpy(nas_sdu->msg, &reconfig->ded_info_nas_list[i].msg, reconfig->ded_info_nas_list[i].N_bytes);
nas_sdu->N_bytes = reconfig->ded_info_nas_list[i].N_bytes;
nas->write_pdu(lcid, nas_sdu);

@ -363,9 +363,7 @@ int main(int argc, char *argv[])
radio.set_tx_freq(prog_args.rf_tx_freq);
// Instruct the PHY to configure PRACH parameters and sync to current cell
my_phy.sync_start();
while(!my_phy.status_is_sync()) {
while(!my_phy.sync_status()) {
usleep(20000);
}

@ -182,11 +182,9 @@ int main(int argc, char *argv[])
// Set RX freq and gain
radio.set_rx_freq(prog_args.rf_freq);
my_phy.sync_start();
bool running = true;
bool running = true;
while(running) {
if (bch_decoded && my_phy.status_is_sync()) {
if (bch_decoded && my_phy.sync_status()) {
uint32_t tti = my_phy.get_current_tti();
// SIB1 is scheduled in subframe #5 of even frames, try to decode next frame SIB1
@ -196,7 +194,7 @@ int main(int argc, char *argv[])
total_pkts++;
}
usleep(30000);
if (bch_decoded && my_phy.status_is_sync() && total_pkts > 0) {
if (bch_decoded && my_phy.sync_status() && total_pkts > 0) {
if (srslte_verbose == SRSLTE_VERBOSE_NONE && srsapps_verbose == 0) {
float gain = prog_args.rf_gain;
if (gain < 0) {

@ -18,17 +18,6 @@
# and at http://www.gnu.org/licenses/.
#
# IP traffic over RLC test
add_executable(ip_test ip_test.cc)
target_link_libraries(ip_test srsue_mac
srsue_phy
srslte_common
srslte_phy
srslte_radio
srslte_upper
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES})
add_executable(usim_test usim_test.cc)
target_link_libraries(usim_test srsue_upper srslte_upper srslte_phy)
add_test(usim_test usim_test)

@ -1,645 +0,0 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include <linux/ip.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <assert.h>
#include "srslte/phy/utils/debug.h"
#include "mac/mac.h"
#include "phy/phy.h"
#include "srslte/common/threads.h"
#include "srslte/common/common.h"
#include "srslte/common/buffer_pool.h"
#include "srslte/common/logger.h"
#include "srslte/common/log_filter.h"
#include "srslte/upper/rlc.h"
#include "upper/rrc.h"
#include "srslte/radio/radio_multi.h"
#define START_TUNTAP
#define USE_RADIO
#define PRINT_GW 0
/**********************************************************************
* Program arguments processing
***********************************************************************/
#define LCID 3
typedef struct {
float rx_freq;
float tx_freq;
float rx_gain;
float tx_gain;
int time_adv;
std::string ip_address;
}prog_args_t;
uint32_t srsapps_verbose = 1;
prog_args_t prog_args;
void args_default(prog_args_t *args) {
args->tx_freq = 2.505e9;
args->rx_freq = 2.625e9;
args->rx_gain = 50.0;
args->tx_gain = 70.0;
args->time_adv = -1; // calibrated for b210
args->ip_address = "192.168.3.2";
}
void usage(prog_args_t *args, char *prog) {
printf("Usage: %s [gGIrfFtv]\n", prog);
printf("\t-f RX frequency [Default %.1f MHz]\n", args->rx_freq/1e6);
printf("\t-F TX frequency [Default %.1f MHz]\n", args->tx_freq/1e6);
printf("\t-g RX gain [Default %.1f]\n", args->rx_gain);
printf("\t-G TX gain [Default %.1f]\n", args->tx_gain);
printf("\t-I IP address [Default %s]\n", args->ip_address.c_str());
printf("\t-t time advance (in samples) [Default %d]\n", args->time_adv);
printf("\t-v [increase verbosity, default none]\n");
}
void parse_args(prog_args_t *args, int argc, char **argv) {
int opt;
args_default(args);
while ((opt = getopt(argc, argv, "gGfFItv")) != -1) {
switch (opt) {
case 'g':
args->rx_gain = atof(argv[optind]);
break;
case 'G':
args->tx_gain = atof(argv[optind]);
break;
case 'f':
args->rx_freq = atof(argv[optind]);
break;
case 'F':
args->tx_freq = atof(argv[optind]);
break;
case 'I':
args->ip_address = argv[optind];
break;
case 't':
args->time_adv = atoi(argv[optind]);
break;
case 'v':
srsapps_verbose++;
break;
default:
usage(args, argv[0]);
exit(-1);
}
}
if (args->rx_freq < 0 || args->tx_freq < 0) {
usage(args, argv[0]);
exit(-1);
}
}
int setup_if_addr(char *ip_addr);
// Define dummy RLC always transmitts
class tester : public srsue::pdcp_interface_rlc,
public srsue::rrc_interface_rlc,
public srsue::rrc_interface_phy,
public srsue::rrc_interface_mac,
public srsue::ue_interface,
public thread
{
public:
tester() {
state = srsue::RRC_STATE_SIB1_SEARCH;
read_enable = true;
}
void init(srsue::phy *phy_, srsue::mac *mac_, srslte::rlc *rlc_, srslte::log *log_h_, std::string ip_address) {
log_h = log_h_;
rlc = rlc_;
mac = mac_;
phy = phy_;
#ifdef START_TUNTAP
if (init_tuntap((char*) ip_address.c_str())) {
log_h->error("Initiating IP address\n");
}
#endif
pool = srslte::byte_buffer_pool::get_instance();
// Start reader thread
running=true;
start();
}
void sib_search()
{
bool searching = true;
uint32_t tti ;
uint32_t si_win_start, si_win_len;
uint16_t period;
uint32_t nof_sib1_trials = 0;
const int SIB1_SEARCH_TIMEOUT = 30;
while(searching)
{
switch(state)
{
case srsue::RRC_STATE_SIB1_SEARCH:
// Instruct MAC to look for SIB1
while(!phy->status_is_sync()){
usleep(50000);
}
usleep(10000);
tti = mac->get_current_tti();
si_win_start = sib_start_tti(tti, 2, 5);
mac->bcch_start_rx(si_win_start, 1);
log_h->info("Instructed MAC to search for SIB1, win_start=%d, win_len=%d\n",
si_win_start, 1);
nof_sib1_trials++;
if (nof_sib1_trials >= SIB1_SEARCH_TIMEOUT) {
log_h->info("Timeout while searching for SIB1. Resynchronizing SFN...\n");
log_h->console("Timeout while searching for SIB1. Resynchronizing SFN...\n");
phy->resync_sfn();
nof_sib1_trials = 0;
}
break;
case srsue::RRC_STATE_SIB2_SEARCH:
// Instruct MAC to look for SIB2
usleep(10000);
tti = mac->get_current_tti();
period = liblte_rrc_si_periodicity_num[sib1.sched_info[0].si_periodicity];
si_win_start = sib_start_tti(tti, period, 0);
si_win_len = liblte_rrc_si_window_length_num[sib1.si_window_length];
mac->bcch_start_rx(si_win_start, si_win_len);
log_h->info("Instructed MAC to search for SIB2, win_start=%d, win_len=%d\n",
si_win_start, si_win_len);
break;
default:
searching = false;
break;
}
usleep(100000);
}
}
bool is_sib_received() {
return state == srsue::RRC_STATE_WAIT_FOR_CON_SETUP;
}
void release_pucch_srs() {}
void ra_problem() {}
void write_pdu_bcch_bch(srslte::byte_buffer_t *pdu) {}
void write_pdu_bcch_dlsch(srslte::byte_buffer_t *pdu)
{
log_h->info_hex(pdu->msg, pdu->N_bytes, "BCCH DLSCH message received.");
log_h->info("BCCH DLSCH message Stack latency: %ld us\n", pdu->get_latency_us());
LIBLTE_RRC_BCCH_DLSCH_MSG_STRUCT dlsch_msg;
srslte_bit_unpack_vector(pdu->msg, bit_buf.msg, pdu->N_bytes*8);
bit_buf.N_bits = pdu->N_bytes*8;
pool->deallocate(pdu);
liblte_rrc_unpack_bcch_dlsch_msg((LIBLTE_BIT_MSG_STRUCT*)&bit_buf, &dlsch_msg);
if (dlsch_msg.N_sibs > 0) {
if (LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1 == dlsch_msg.sibs[0].sib_type && srsue::RRC_STATE_SIB1_SEARCH == state) {
// Handle SIB1
memcpy(&sib1, &dlsch_msg.sibs[0].sib.sib1, sizeof(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1_STRUCT));
log_h->info("SIB1 received, CellID=%d, si_window=%d, sib2_period=%d\n",
sib1.cell_id&0xfff,
liblte_rrc_si_window_length_num[sib1.si_window_length],
liblte_rrc_si_periodicity_num[sib1.sched_info[0].si_periodicity]);
std::stringstream ss;
for(uint32_t i=0;i<sib1.N_plmn_ids;i++){
ss << " PLMN Id: MCC " << sib1.plmn_id[i].id.mcc << " MNC " << sib1.plmn_id[i].id.mnc;
}
log_h->console("SIB1 received, CellID=%d, %s\n",
sib1.cell_id&0xfff,
ss.str().c_str());
state = srsue::RRC_STATE_SIB2_SEARCH;
mac->bcch_stop_rx();
//TODO: Use all SIB1 info
} else if (LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2 == dlsch_msg.sibs[0].sib_type && srsue::RRC_STATE_SIB2_SEARCH == state) {
// Handle SIB2
memcpy(&sib2, &dlsch_msg.sibs[0].sib.sib2, sizeof(LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT));
log_h->console("SIB2 received\n");
log_h->info("SIB2 received\n");
state = srsue::RRC_STATE_WAIT_FOR_CON_SETUP;
mac->bcch_stop_rx();
apply_sib2_configs();
srslte::byte_buffer_t *sdu = pool_allocate;
assert(sdu);
// Send Msg3
sdu->N_bytes = 10;
for (uint32_t i=0;i<sdu->N_bytes;i++) {
sdu->msg[i] = i+1;
}
uint64_t uecri = 0;
uint8_t *ue_cri_ptr = (uint8_t*) &uecri;
uint32_t nbytes = 6;
for (uint32_t i=0;i<nbytes;i++) {
ue_cri_ptr[nbytes-i-1] = sdu->msg[i];
}
log_h->info("Setting UE contention resolution ID: %d\n", uecri);
mac->set_contention_id(uecri);
rlc->write_sdu(0, sdu);
}
}
}
void write_pdu_pcch(srslte::byte_buffer_t *sdu) {}
void max_retx_attempted(){}
void in_sync() {};
void out_of_sync() {};
void write_pdu(uint32_t lcid, srslte::byte_buffer_t *sdu)
{
uint32_t n=0;
switch(lcid) {
case LCID:
n = write(tun_fd, sdu->msg, sdu->N_bytes);
if (n != sdu->N_bytes) {
log_h->error("TUN/TAP write failure n=%d, nof_bytes=%d\n", n, sdu->N_bytes);
return;
}
log_h->debug_hex(sdu->msg, sdu->N_bytes,
"Wrote %d bytes to TUN/TAP\n",
sdu->N_bytes);
pool->deallocate(sdu);
break;
case 0:
log_h->info("Received ConnectionSetupComplete\n");
// Setup a single UM bearer
LIBLTE_RRC_RLC_CONFIG_STRUCT cfg;
bzero(&cfg, sizeof(LIBLTE_RRC_RLC_CONFIG_STRUCT));
cfg.rlc_mode = LIBLTE_RRC_RLC_MODE_UM_BI;
cfg.dl_um_bi_rlc.t_reordering = LIBLTE_RRC_T_REORDERING_MS100;
cfg.dl_um_bi_rlc.sn_field_len = LIBLTE_RRC_SN_FIELD_LENGTH_SIZE10;
cfg.ul_um_bi_rlc.sn_field_len = LIBLTE_RRC_SN_FIELD_LENGTH_SIZE10;
rlc->add_bearer(LCID, &cfg);
mac->setup_lcid(LCID, 0, 1, -1, 100000);
LIBLTE_RRC_PHYSICAL_CONFIG_DEDICATED_STRUCT dedicated;
bzero(&dedicated, sizeof(LIBLTE_RRC_PHYSICAL_CONFIG_DEDICATED_STRUCT));
dedicated.pusch_cnfg_ded.beta_offset_ack_idx = 5;
dedicated.pusch_cnfg_ded.beta_offset_ri_idx = 12;
dedicated.pusch_cnfg_ded.beta_offset_cqi_idx = 15;
dedicated.pusch_cnfg_ded_present = true;
dedicated.sched_request_cnfg.dsr_trans_max = LIBLTE_RRC_DSR_TRANS_MAX_N4;
dedicated.sched_request_cnfg.sr_pucch_resource_idx = 0;
dedicated.sched_request_cnfg.sr_cnfg_idx = 35;
dedicated.sched_request_cnfg.setup_present = true;
dedicated.sched_request_cnfg_present = true;
phy->set_config_dedicated(&dedicated);
phy->configure_ul_params();
srsue::mac_interface_rrc::mac_cfg_t mac_cfg;
mac->get_config(&mac_cfg);
memcpy(&mac_cfg.sr, &dedicated.sched_request_cnfg, sizeof(LIBLTE_RRC_SCHEDULING_REQUEST_CONFIG_STRUCT));
mac_cfg.main.ulsch_cnfg.periodic_bsr_timer = LIBLTE_RRC_PERIODIC_BSR_TIMER_SF40;
mac->set_config(&mac_cfg);
break;
default:
log_h->error("Received message for lcid=%d\n", lcid);
break;
}
}
private:
int tun_fd;
bool running;
srslte::log *log_h;
srslte::byte_buffer_pool *pool;
srslte::rlc *rlc;
srsue::mac *mac;
srsue::phy *phy;
srslte::bit_buffer_t bit_buf;
srsue::rrc_state_t state;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_1_STRUCT sib1;
LIBLTE_RRC_SYS_INFO_BLOCK_TYPE_2_STRUCT sib2;
bool read_enable;
// Determine SI messages scheduling as in 36.331 5.2.3 Acquisition of an SI message
uint32_t sib_start_tti(uint32_t tti, uint32_t period, uint32_t x) {
return (period*10*(1+tti/(period*10))+x)%10240; // the 1 means next opportunity
}
int init_tuntap(char *ip_address) {
read_enable = true;
tun_fd = setup_if_addr(ip_address);
if (tun_fd<0) {
fprintf(stderr, "Error setting up IP %s\n", ip_address);
return -1;
}
printf("Created tun/tap interface at IP %s\n", ip_address);
return 0;
}
void run_thread() {
struct iphdr *ip_pkt;
uint32_t idx = 0;
int32_t N_bytes;
srslte::byte_buffer_t *pdu = pool_allocate;
log_h->info("TUN/TAP reader thread running\n");
while(running) {
N_bytes = read(tun_fd, &pdu->msg[idx], SRSLTE_MAX_BUFFER_SIZE_BYTES-SRSLTE_BUFFER_HEADER_OFFSET - idx);
if(N_bytes > 0 && read_enable)
{
pdu->N_bytes = idx + N_bytes;
ip_pkt = (struct iphdr*)pdu->msg;
log_h->debug_hex(pdu->msg, pdu->N_bytes,
"Read %d bytes from TUN/TAP\n",
N_bytes);
// Check if entire packet was received
if(ntohs(ip_pkt->tot_len) == pdu->N_bytes)
{
log_h->info_hex(pdu->msg, pdu->N_bytes, "UL PDU");
// Send PDU directly to PDCP
pdu->set_timestamp();
rlc->write_sdu(LCID, pdu);
pdu = pool_allocate;
idx = 0;
} else{
idx += N_bytes;
}
}else{
log_h->error("Failed to read from TUN interface - gw receive thread exiting.\n");
break;
}
}
}
void apply_sib2_configs()
{
// Apply RACH timeAlginmentTimer configuration
srsue::mac_interface_rrc::mac_cfg_t cfg;
mac->get_config(&cfg);
cfg.main.time_alignment_timer = sib2.time_alignment_timer;
memcpy(&cfg.rach, &sib2.rr_config_common_sib.rach_cnfg, sizeof(LIBLTE_RRC_RACH_CONFIG_COMMON_STRUCT));
cfg.prach_config_index = sib2.rr_config_common_sib.prach_cnfg.root_sequence_index;
mac->set_config(&cfg);
log_h->info("Set RACH ConfigCommon: NofPreambles=%d, ResponseWindow=%d, ContentionResolutionTimer=%d ms\n",
liblte_rrc_number_of_ra_preambles_num[sib2.rr_config_common_sib.rach_cnfg.num_ra_preambles],
liblte_rrc_ra_response_window_size_num[sib2.rr_config_common_sib.rach_cnfg.ra_resp_win_size],
liblte_rrc_mac_contention_resolution_timer_num[sib2.rr_config_common_sib.rach_cnfg.mac_con_res_timer]);
// Apply PHY RR Config Common
srsue::phy_interface_rrc::phy_cfg_common_t common;
memcpy(&common.pdsch_cnfg, &sib2.rr_config_common_sib.pdsch_cnfg, sizeof(LIBLTE_RRC_PDSCH_CONFIG_COMMON_STRUCT));
memcpy(&common.pusch_cnfg, &sib2.rr_config_common_sib.pusch_cnfg, sizeof(LIBLTE_RRC_PUSCH_CONFIG_COMMON_STRUCT));
memcpy(&common.pucch_cnfg, &sib2.rr_config_common_sib.pucch_cnfg, sizeof(LIBLTE_RRC_PUCCH_CONFIG_COMMON_STRUCT));
memcpy(&common.ul_pwr_ctrl, &sib2.rr_config_common_sib.ul_pwr_ctrl, sizeof(LIBLTE_RRC_UL_POWER_CONTROL_COMMON_STRUCT));
memcpy(&common.prach_cnfg, &sib2.rr_config_common_sib.prach_cnfg, sizeof(LIBLTE_RRC_PRACH_CONFIG_SIB_STRUCT));
if (sib2.rr_config_common_sib.srs_ul_cnfg.present) {
memcpy(&common.srs_ul_cnfg, &sib2.rr_config_common_sib.srs_ul_cnfg, sizeof(LIBLTE_RRC_SRS_UL_CONFIG_COMMON_STRUCT));
} else {
// default is release
common.srs_ul_cnfg.present = false;
}
phy->set_config_common(&common);
phy->configure_ul_params();
log_h->info("Set PUSCH ConfigCommon: HopOffset=%d, RSGroup=%d, RSNcs=%d, N_sb=%d\n",
sib2.rr_config_common_sib.pusch_cnfg.pusch_hopping_offset,
sib2.rr_config_common_sib.pusch_cnfg.ul_rs.group_assignment_pusch,
sib2.rr_config_common_sib.pusch_cnfg.ul_rs.cyclic_shift,
sib2.rr_config_common_sib.pusch_cnfg.n_sb);
log_h->info("Set PUCCH ConfigCommon: DeltaShift=%d, CyclicShift=%d, N1=%d, NRB=%d\n",
liblte_rrc_delta_pucch_shift_num[sib2.rr_config_common_sib.pucch_cnfg.delta_pucch_shift],
sib2.rr_config_common_sib.pucch_cnfg.n_cs_an,
sib2.rr_config_common_sib.pucch_cnfg.n1_pucch_an,
sib2.rr_config_common_sib.pucch_cnfg.n_rb_cqi);
log_h->info("Set PRACH ConfigCommon: SeqIdx=%d, HS=%d, FreqOffset=%d, ZC=%d, ConfigIndex=%d\n",
sib2.rr_config_common_sib.prach_cnfg.root_sequence_index,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.high_speed_flag?1:0,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.prach_freq_offset,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.zero_correlation_zone_config,
sib2.rr_config_common_sib.prach_cnfg.prach_cnfg_info.prach_config_index);
log_h->info("Set SRS ConfigCommon: BW-Configuration=%d, SF-Configuration=%d, ACKNACK=%d\n",
sib2.rr_config_common_sib.srs_ul_cnfg.bw_cnfg,
sib2.rr_config_common_sib.srs_ul_cnfg.subfr_cnfg,
sib2.rr_config_common_sib.srs_ul_cnfg.ack_nack_simul_tx);
}
};
// Create classes
srslte::logger logger;
srslte::log_filter log_phy;
srslte::log_filter log_mac;
srslte::log_filter log_rlc;
srslte::log_filter log_tester;
srslte::mac_pcap mac_pcap;
srsue::phy my_phy;
srsue::mac my_mac;
srslte::rlc rlc;
srslte::radio_multi my_radio;
// Local classes for testing
tester my_tester;
bool running = true;
void sig_int_handler(int signo)
{
running = false;
}
int main(int argc, char *argv[])
{
parse_args(&prog_args, argc, argv);
// set to null to disable pcap
const char *pcap_filename = "/tmp/ip_test.pcap";
logger.init("/tmp/ip_test_ue.log");
log_phy.init("PHY ", &logger, true);
log_mac.init("MAC ", &logger, true);
log_rlc.init("RLC ", &logger);
log_tester.init("TEST", &logger);
logger.log("\n\n");
if (srsapps_verbose == 1) {
log_phy.set_level(srslte::LOG_LEVEL_INFO);
log_phy.set_hex_limit(100);
log_mac.set_level(srslte::LOG_LEVEL_DEBUG);
log_mac.set_hex_limit(100);
log_rlc.set_level(srslte::LOG_LEVEL_DEBUG);
log_rlc.set_hex_limit(1000);
log_tester.set_level(srslte::LOG_LEVEL_DEBUG);
log_tester.set_hex_limit(100);
printf("Log level info\n");
}
if (srsapps_verbose == 2) {
log_phy.set_level(srslte::LOG_LEVEL_DEBUG);
log_phy.set_hex_limit(100);
log_mac.set_level(srslte::LOG_LEVEL_DEBUG);
log_mac.set_hex_limit(100);
log_rlc.set_level(srslte::LOG_LEVEL_DEBUG);
log_rlc.set_hex_limit(100);
log_tester.set_level(srslte::LOG_LEVEL_DEBUG);
log_tester.set_hex_limit(100);
srslte_verbose = SRSLTE_VERBOSE_DEBUG;
printf("Log level debug\n");
}
// Init Radio and PHY
#ifdef USE_RADIO
my_radio.init();
#else
my_radio.init(NULL, "dummy");
#endif
my_radio.set_tx_freq(prog_args.tx_freq);
my_radio.set_tx_gain(prog_args.tx_gain);
my_radio.set_rx_freq(prog_args.rx_freq);
my_radio.set_rx_gain(prog_args.rx_gain);
if (prog_args.time_adv >= 0) {
printf("Setting TA=%d samples\n",prog_args.time_adv);
my_radio.set_tx_adv(prog_args.time_adv);
}
my_phy.init(&my_radio, &my_mac, &my_tester, &log_phy, NULL);
my_mac.init(&my_phy, &rlc, &my_tester, &log_mac);
rlc.init(&my_tester, &my_tester, &my_tester, &log_rlc, &my_mac);
my_tester.init(&my_phy, &my_mac, &rlc, &log_tester, prog_args.ip_address);
if (pcap_filename) {
mac_pcap.open(pcap_filename);
my_mac.start_pcap(&mac_pcap);
signal(SIGINT, sig_int_handler);
}
// Set MAC defaults
LIBLTE_RRC_MAC_MAIN_CONFIG_STRUCT default_cfg;
bzero(&default_cfg, sizeof(LIBLTE_RRC_MAC_MAIN_CONFIG_STRUCT));
default_cfg.ulsch_cnfg.max_harq_tx = LIBLTE_RRC_MAX_HARQ_TX_N5;
default_cfg.ulsch_cnfg.periodic_bsr_timer = LIBLTE_RRC_PERIODIC_BSR_TIMER_INFINITY;
default_cfg.ulsch_cnfg.retx_bsr_timer = LIBLTE_RRC_RETRANSMISSION_BSR_TIMER_SF2560;
default_cfg.ulsch_cnfg.tti_bundling = false;
default_cfg.drx_cnfg.setup_present = false;
default_cfg.phr_cnfg.setup_present = false;
default_cfg.time_alignment_timer = LIBLTE_RRC_TIME_ALIGNMENT_TIMER_INFINITY;
my_mac.set_config_main(&default_cfg);
while(running) {
if (my_tester.is_sib_received()) {
printf("Main running\n");
sleep(1);
} else {
my_tester.sib_search();
}
}
if (pcap_filename) {
mac_pcap.close();
}
my_phy.stop();
my_mac.stop();
}
/******************* This is copied from srsue gw **********************/
int setup_if_addr(char *ip_addr)
{
char *dev = (char*) "tun_srsue";
// Construct the TUN device
int tun_fd = open("/dev/net/tun", O_RDWR);
if(0 > tun_fd)
{
perror("open");
return(-1);
}
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
strncpy(ifr.ifr_ifrn.ifrn_name, dev, IFNAMSIZ);
if(0 > ioctl(tun_fd, TUNSETIFF, &ifr))
{
perror("ioctl");
return -1;
}
// Bring up the interface
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if(0 > ioctl(sock, SIOCGIFFLAGS, &ifr))
{
perror("socket");
return -1;
}
ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if(0 > ioctl(sock, SIOCSIFFLAGS, &ifr))
{
perror("ioctl");
return -1;
}
// Setup the IP address
sock = socket(AF_INET, SOCK_DGRAM, 0);
ifr.ifr_addr.sa_family = AF_INET;
((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr = inet_addr(ip_addr);
if(0 > ioctl(sock, SIOCSIFADDR, &ifr))
{
perror("ioctl");
return -1;
}
ifr.ifr_netmask.sa_family = AF_INET;
((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr.s_addr = inet_addr("255.255.255.0");
if(0 > ioctl(sock, SIOCSIFNETMASK, &ifr))
{
perror("ioctl");
return -1;
}
return(tun_fd);
}
Loading…
Cancel
Save