diff --git a/lib/src/phy/enb/enb_ul.c b/lib/src/phy/enb/enb_ul.c index f756c021f..db05d44ea 100644 --- a/lib/src/phy/enb/enb_ul.c +++ b/lib/src/phy/enb/enb_ul.c @@ -50,7 +50,7 @@ int srslte_enb_ul_init(srslte_enb_ul_t *q, bzero(q, sizeof(srslte_enb_ul_t)); - q->users = calloc(sizeof(srslte_enb_ul_user_t*), SRSLTE_SIRNTI); + q->users = calloc(sizeof(srslte_enb_ul_user_t*), (1+SRSLTE_SIRNTI)); if (!q->users) { perror("malloc"); goto clean_exit; @@ -110,7 +110,7 @@ void srslte_enb_ul_free(srslte_enb_ul_t *q) if (q) { if (q->users) { - for (int i=0;iusers[i]) { free(q->users[i]); } @@ -198,8 +198,8 @@ int srslte_enb_ul_set_cell(srslte_enb_ul_t *q, srslte_cell_t cell, int srslte_enb_ul_add_rnti(srslte_enb_ul_t *q, uint16_t rnti) { if (!q->users[rnti]) { - q->users[rnti] = malloc(sizeof(srslte_enb_ul_user_t)); - + q->users[rnti] = calloc(1, sizeof(srslte_enb_ul_user_t)); + if (srslte_pucch_set_crnti(&q->pucch, rnti)) { fprintf(stderr, "Error setting PUCCH rnti\n"); return -1; diff --git a/lib/src/phy/phch/pdsch.c b/lib/src/phy/phch/pdsch.c index c29d048da..6bacf99cf 100644 --- a/lib/src/phy/phch/pdsch.c +++ b/lib/src/phy/phch/pdsch.c @@ -320,7 +320,7 @@ void srslte_pdsch_free(srslte_pdsch_t *q) { if (q->is_ue) { srslte_pdsch_free_rnti(q, 0); } else { - for (uint16_t u=0;uusers[u]) { srslte_pdsch_free_rnti(q, u); } diff --git a/lib/src/phy/phch/pucch.c b/lib/src/phy/phch/pucch.c index 6b271d02e..498d34f3a 100644 --- a/lib/src/phy/phch/pucch.c +++ b/lib/src/phy/phch/pucch.c @@ -451,7 +451,7 @@ clean_exit: void srslte_pucch_free(srslte_pucch_t *q) { if (q->users) { - for (int rnti=0;rntiusers); diff --git a/lib/src/phy/phch/pusch.c b/lib/src/phy/phch/pusch.c index 24e86e9a3..ee01484d8 100644 --- a/lib/src/phy/phch/pusch.c +++ b/lib/src/phy/phch/pusch.c @@ -295,7 +295,7 @@ void srslte_pusch_free(srslte_pusch_t *q) { if (q->is_ue) { srslte_pusch_free_rnti(q, 0); } else { - for (int rnti=0;rntirx_md_first); uhd_rx_metadata_free(&handler->rx_md); uhd_meta_range_free(&handler->rx_gain_range); - uhd_tx_streamer_free(&handler->tx_stream); - uhd_rx_streamer_free(&handler->rx_stream); if (handler->has_rssi) { uhd_sensor_value_free(&handler->rssi_value); } handler->async_thread_running = false; - pthread_join(handler->async_thread, NULL); + pthread_join(handler->async_thread, NULL); + + uhd_tx_streamer_free(&handler->tx_stream); + uhd_rx_streamer_free(&handler->rx_stream); uhd_usrp_free(&handler->usrp); + + free(handler); /** Something else to close the USRP?? */ return 0; diff --git a/lib/src/phy/utils/cexptab.c b/lib/src/phy/utils/cexptab.c index 47ff8ef96..0f9232e85 100644 --- a/lib/src/phy/utils/cexptab.c +++ b/lib/src/phy/utils/cexptab.c @@ -36,7 +36,7 @@ int srslte_cexptab_init(srslte_cexptab_t *h, uint32_t size) { uint32_t i; h->size = size; - h->tab = malloc(sizeof(cf_t) * size); + h->tab = malloc(sizeof(cf_t) * (1+size)); if (h->tab) { for (i = 0; i < size; i++) { h->tab[i] = cexpf(_Complex_I * 2 * M_PI * (float) i / size); diff --git a/srsenb/hdr/enb.h b/srsenb/hdr/enb.h index b28d12ab4..3ab1dddb9 100644 --- a/srsenb/hdr/enb.h +++ b/srsenb/hdr/enb.h @@ -138,42 +138,53 @@ typedef struct { Main UE class *******************************************************************************/ +#define LOG_STDOUT + class enb - :public enb_metrics_interface -{ + :public enb_metrics_interface { public: - static enb* get_instance(void); + static enb *get_instance(void); + static void cleanup(void); bool init(all_args_t *args_); + void stop(); + void start_plot(); - + static void rf_msg(srslte_rf_error_t error); + void handle_rf_msg(srslte_rf_error_t error); // eNodeB metrics interface bool get_metrics(enb_metrics_t &m); void pregenerate_signals(bool enable); - + private: static enb *instance; + enb(); + virtual ~enb(); - srslte::radio radio; - srsenb::phy phy; - srsenb::mac mac; - srslte::mac_pcap mac_pcap; - srsenb::rlc rlc; - srsenb::pdcp pdcp; - srsenb::rrc rrc; - srsenb::gtpu gtpu; - srsenb::s1ap s1ap; - - srslte::logger_file logger; + srslte::radio radio; + srsenb::phy phy; + srsenb::mac mac; + srslte::mac_pcap mac_pcap; + srsenb::rlc rlc; + srsenb::pdcp pdcp; + srsenb::rrc rrc; + srsenb::gtpu gtpu; + srsenb::s1ap s1ap; + +#ifdef LOG_STDOUT + srslte::logger_stdout logger; +#else + srslte::logger_file logger; +#endif srslte::log_filter rf_log; std::vector phy_log; srslte::log_filter mac_log; diff --git a/srsenb/hdr/mac/scheduler.h b/srsenb/hdr/mac/scheduler.h index 66f8998c1..c70ee4247 100644 --- a/srsenb/hdr/mac/scheduler.h +++ b/srsenb/hdr/mac/scheduler.h @@ -80,7 +80,8 @@ public: ************************************************************/ sched(); - + ~sched(); + void init(rrc_interface_mac *rrc, srslte::log *log); void set_metric(metric_dl *dl_metric, metric_ul *ul_metric); int cell_cfg(cell_cfg_t *cell_cfg); diff --git a/srsenb/hdr/mac/ue.h b/srsenb/hdr/mac/ue.h index 5805e5472..b879d040b 100644 --- a/srsenb/hdr/mac/ue.h +++ b/srsenb/hdr/mac/ue.h @@ -38,7 +38,7 @@ namespace srsenb { -class ue : public srslte::read_pdu_interface, +class ue : public srslte::read_pdu_interface, public srslte::pdu_queue::process_callback { public: diff --git a/srsenb/hdr/phy/phch_common.h b/srsenb/hdr/phy/phch_common.h index ae396ae0e..00a59d969 100644 --- a/srsenb/hdr/phy/phch_common.h +++ b/srsenb/hdr/phy/phch_common.h @@ -54,6 +54,7 @@ public: phch_common(uint32_t max_mutex_) : tx_mutex(max_mutex_) { + nof_mutex = 0; max_mutex = max_mutex_; params.max_prach_offset_us = 20; } diff --git a/srsenb/hdr/phy/phch_worker.h b/srsenb/hdr/phy/phch_worker.h index 2f0f80f41..906e8b9d0 100644 --- a/srsenb/hdr/phy/phch_worker.h +++ b/srsenb/hdr/phy/phch_worker.h @@ -42,7 +42,8 @@ public: phch_worker(); void init(phch_common *phy, srslte::log *log_h); - void reset(); + void stop(); + void reset(); cf_t *get_buffer_rx(); void set_time(uint32_t tti, uint32_t tx_mutex_cnt, srslte_timestamp_t tx_time); @@ -83,7 +84,9 @@ private: /* Common objects */ srslte::log *log_h; phch_common *phy; - bool initiated; + bool initiated; + bool running; + cf_t *signal_buffer_rx; cf_t *signal_buffer_tx; uint32_t tti_rx, tti_tx, tti_sched_ul, sf_rx, sf_tx, sf_sched_ul, tx_mutex_cnt; diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index 1bd7240a2..e2c1c9a29 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -45,6 +45,7 @@ enb* enb::get_instance(void) void enb::cleanup(void) { srslte_dft_exit(); + srslte::byte_buffer_pool::cleanup(); boost::mutex::scoped_lock lock(enb_instance_mutex); if(NULL != instance) { delete instance; @@ -61,14 +62,15 @@ enb::enb() enb::~enb() { - srslte::byte_buffer_pool::cleanup(); } bool enb::init(all_args_t *args_) { args = args_; - logger.init(args->log.filename); +#ifndef LOG_STDOUT + logger.init(args->log.filename); +#endif rf_log.init("RF ", &logger); // Create array of pointers to phy_logs @@ -87,7 +89,9 @@ bool enb::init(all_args_t *args_) s1ap_log.init("S1AP", &logger); // Init logs - logger.log("\n\n"); +#ifndef LOG_STDOUT + logger.log("\n\n"); +#endif rf_log.set_level(srslte::LOG_LEVEL_INFO); for (int i=0;iexpert.phy.nof_phy_threads;i++) { ((srslte::log_filter*) phy_log[i])->set_level(level(args->log.phy_level)); diff --git a/srsenb/src/mac/mac.cc b/srsenb/src/mac/mac.cc index 63d189c20..284cef3e7 100644 --- a/srsenb/src/mac/mac.cc +++ b/srsenb/src/mac/mac.cc @@ -83,12 +83,16 @@ bool mac::init(mac_args_t *args_, srslte_cell_t *cell_, phy_interface_mac *phy, reset(); started = true; - } + } + return started; } void mac::stop() { + for (uint32_t i=0;iadd_rnti(SRSLTE_SIRNTI); - - /* Setup P-RNTI in PHY */ - phy_h->add_rnti(SRSLTE_PRNTI); - - /* Setup RA-RNTI in PHY */ - for (int i=0;i<10;i++) { - phy_h->add_rnti(1+i); - } } uint32_t mac::get_unique_id() diff --git a/srsenb/src/mac/scheduler.cc b/srsenb/src/mac/scheduler.cc index 73dbc2d41..79cf3f476 100644 --- a/srsenb/src/mac/scheduler.cc +++ b/srsenb/src/mac/scheduler.cc @@ -20,11 +20,18 @@ namespace srsenb { *******************************************************/ sched::sched() { + current_tti = 0; log_h = NULL; pthread_mutex_init(&mutex, NULL); reset(); } +sched::~sched() +{ + srslte_regs_free(®s); + pthread_mutex_destroy(&mutex); +} + void sched::init(rrc_interface_mac *rrc_, srslte::log* log) { sched_cfg.pdsch_max_mcs = 28; @@ -39,6 +46,7 @@ void sched::init(rrc_interface_mac *rrc_, srslte::log* log) int sched::reset() { + bzero(pending_msg3, sizeof(pending_msg3_t)*10); bzero(pending_rar, sizeof(sched_rar_t)*SCHED_MAX_PENDING_RAR); bzero(pending_sibs, sizeof(sched_sib_t)*MAX_SIBS); ue_db.clear(); diff --git a/srsenb/src/phy/phch_common.cc b/srsenb/src/phy/phch_common.cc index bfb0d1b0d..e4d91581e 100644 --- a/srsenb/src/phy/phch_common.cc +++ b/srsenb/src/phy/phch_common.cc @@ -60,7 +60,7 @@ bool phch_common::init(srslte_cell_t *cell_, srslte::radio* radio_h_, mac_interf is_first_of_burst = true; is_first_tx = true; - for (uint32_t i=0;iparams.pusch_max_its); srslte_enb_dl_set_amp(&enb_dl, phy->params.tx_amplitude); @@ -125,12 +136,29 @@ void phch_worker::init(phch_common* phy_, srslte::log *log_h_) Info("Worker %d configured cell %d PRB\n", get_id(), phy->cell.nof_prb); initiated = true; - + running = true; + #ifdef DEBUG_WRITE_FILE f = fopen("test.dat", "w"); #endif } +void phch_worker::stop() +{ + running = false; + pthread_mutex_lock(&mutex); + + srslte_enb_dl_free(&enb_dl); + srslte_enb_ul_free(&enb_ul); + if (signal_buffer_rx) { + free(signal_buffer_rx); + } + if (signal_buffer_tx) { + free(signal_buffer_tx); + } + pthread_mutex_unlock(&mutex); + pthread_mutex_destroy(&mutex); +} void phch_worker::reset() { initiated = false; @@ -234,7 +262,11 @@ void phch_worker::rem_rnti(uint16_t rnti) void phch_worker::work_imp() { - uint32_t sf_ack; + uint32_t sf_ack; + + if (!running) { + return; + } pthread_mutex_lock(&mutex); diff --git a/srsenb/src/phy/phy.cc b/srsenb/src/phy/phy.cc index bc4f3173e..c0d0a73c9 100644 --- a/srsenb/src/phy/phy.cc +++ b/srsenb/src/phy/phy.cc @@ -134,6 +134,9 @@ void phy::stop() { tx_rx.stop(); workers_common.stop(); + for (uint32_t i=0;i #include +#include #include "srslte/asn1/liblte_mme.h" #include "upper/rrc.h" @@ -61,7 +62,8 @@ void rrc::init(rrc_cfg_t *cfg_, pthread_mutex_init(&user_mutex, NULL); pthread_mutex_init(&paging_mutex, NULL); - + + act_monitor.start(RRC_THREAD_PRIO); bzero(&sr_sched, sizeof(sr_sched_t)); start(RRC_THREAD_PRIO); @@ -69,9 +71,8 @@ void rrc::init(rrc_cfg_t *cfg_, rrc::activity_monitor::activity_monitor(rrc* parent_) { - running = true; - parent = parent_; - start(RRC_THREAD_PRIO); + running = true; + parent = parent_; } void rrc::activity_monitor::stop() @@ -149,6 +150,7 @@ uint32_t rrc::generate_sibs() srslte_bit_pack_vector(bitbuffer.msg, sib_buffer[i].msg, bitbuffer.N_bits); sib_buffer[i].N_bytes = (bitbuffer.N_bits-1)/8+1; } + free(msg); return nof_messages; } @@ -604,23 +606,32 @@ void rrc::run_thread() if (p.pdu) { rrc_log->info_hex(p.pdu->msg, p.pdu->N_bytes, "Rx %s PDU", rb_id_text[p.lcid]); } - switch(p.lcid) - { - case RB_ID_SRB0: - parse_ul_ccch(p.rnti, p.pdu); - break; - case RB_ID_SRB1: - case RB_ID_SRB2: - parse_ul_dcch(p.rnti, p.lcid, p.pdu); - break; - case LCID_REM_USER: - usleep(10000); - rem_user(p.rnti); - break; - default: - rrc_log->error("Rx PDU with invalid bearer id: %s", p.lcid); - break; + pthread_mutex_lock(&user_mutex); + if (users.count(p.rnti) == 1) { + switch(p.lcid) + { + case RB_ID_SRB0: + parse_ul_ccch(p.rnti, p.pdu); + break; + case RB_ID_SRB1: + case RB_ID_SRB2: + parse_ul_dcch(p.rnti, p.lcid, p.pdu); + break; + case LCID_REM_USER: + pthread_mutex_unlock(&user_mutex); + usleep(10000); + rem_user(p.rnti); + pthread_mutex_lock(&user_mutex); + break; + default: + rrc_log->error("Rx PDU with invalid bearer id: %s", p.lcid); + break; + } + } else { + printf("Discarting rnti=0x%xn", p.rnti); + rrc_log->warning("Discarting PDU for removed rnti=0x%x\n", p.rnti); } + pthread_mutex_unlock(&user_mutex); } } void rrc::activity_monitor::run_thread() diff --git a/srsenb/src/upper/s1ap.cc b/srsenb/src/upper/s1ap.cc index eba9186e7..44a564d09 100644 --- a/srsenb/src/upper/s1ap.cc +++ b/srsenb/src/upper/s1ap.cc @@ -347,6 +347,7 @@ bool s1ap::setup_s1() uint16_t tmp16; srslte::byte_buffer_t msg; LIBLTE_S1AP_S1AP_PDU_STRUCT pdu; + bzero(&pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT)); pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_INITIATINGMESSAGE; diff --git a/srsue/hdr/mac/dl_harq.h b/srsue/hdr/mac/dl_harq.h index 963551150..ba5888a30 100644 --- a/srsue/hdr/mac/dl_harq.h +++ b/srsue/hdr/mac/dl_harq.h @@ -188,6 +188,12 @@ private: bzero(&cur_grant, sizeof(Tgrant)); } + ~dl_tb_process() { + if (is_initiated) { + srslte_softbuffer_rx_free(&softbuffer); + } + } + bool init(uint32_t pid_, dl_harq_entity *parent, uint32_t tb_idx) { tid = tb_idx; if (srslte_softbuffer_rx_init(&softbuffer, 110)) { diff --git a/srsue/hdr/mac/proc_ra.h b/srsue/hdr/mac/proc_ra.h index 6863371c0..c1bdf3644 100644 --- a/srsue/hdr/mac/proc_ra.h +++ b/srsue/hdr/mac/proc_ra.h @@ -71,6 +71,9 @@ class ra_proc : public srslte::timer_callback rar_grant_tti = 0; msg3_flushed = false; }; + + ~ra_proc(); + void init(phy_interface_mac *phy_h, rrc_interface_mac *rrc_, srslte::log *log_h, diff --git a/srsue/hdr/mac/ul_harq.h b/srsue/hdr/mac/ul_harq.h index 952b9f002..9ce3b37ca 100644 --- a/srsue/hdr/mac/ul_harq.h +++ b/srsue/hdr/mac/ul_harq.h @@ -163,9 +163,20 @@ private: is_initiated = false; is_grant_configured = false; tti_last_tx = 0; + payload_buffer = NULL; bzero(&cur_grant, sizeof(Tgrant)); } + ~ul_harq_process() + { + if (is_initiated) { + if (payload_buffer) { + free(payload_buffer); + } + srslte_softbuffer_tx_free(&softbuffer); + } + } + bool init(uint32_t pid_, ul_harq_entity *parent) { if (srslte_softbuffer_tx_init(&softbuffer, 110)) { diff --git a/srsue/src/mac/mac.cc b/srsue/src/mac/mac.cc index 12054567f..f28e43553 100644 --- a/srsue/src/mac/mac.cc +++ b/srsue/src/mac/mac.cc @@ -86,6 +86,8 @@ bool mac::init(phy_interface_mac *phy, rlc_interface_mac *rlc, rrc_interface_mac void mac::stop() { + srslte_softbuffer_rx_free(&pch_softbuffer); + started = false; ttisync.increase(); upper_timers_thread.thread_cancel(); diff --git a/srsue/src/mac/proc_ra.cc b/srsue/src/mac/proc_ra.cc index f9903e2eb..28a2b47e3 100644 --- a/srsue/src/mac/proc_ra.cc +++ b/srsue/src/mac/proc_ra.cc @@ -73,6 +73,10 @@ void ra_proc::init(phy_interface_mac* phy_h_, reset(); } +ra_proc::~ra_proc() { + srslte_softbuffer_rx_free(&softbuffer_rar); +} + void ra_proc::reset() { state = IDLE; msg3_transmitted = false; diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 7ff787a38..7607164d3 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -145,6 +145,7 @@ phch_recv::~phch_recv() { } srslte_ue_sync_free(&ue_sync); srslte_ue_dl_free(&ue_dl_measure); + srslte_ue_mib_free(&ue_mib); srslte_ue_mib_sync_free(&ue_mib_sync); srslte_ue_cellsearch_free(&cs); }