From e5d07a4231cf2e3841c725af04118f95aac3e211 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 1 Feb 2018 12:54:40 +0000 Subject: [PATCH 1/7] Starting to extract AMF value from authentication request (AUTN) in srsUE. --- srsue/src/upper/usim.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/srsue/src/upper/usim.cc b/srsue/src/upper/usim.cc index fe70797e3..f8b45d625 100644 --- a/srsue/src/upper/usim.cc +++ b/srsue/src/upper/usim.cc @@ -356,6 +356,11 @@ void usim::gen_auth_res_milenage( uint8_t *rand, { sqn[i] = autn_enb[i] ^ ak[i]; } + // Extract AMF from autn + for(int i=0;i<2;i++) + { + amf[i]=autn_enb[6+i]; + } // Generate MAC security_milenage_f1( k, @@ -431,6 +436,10 @@ void usim::gen_auth_res_xor(uint8_t *rand, for(i=0;i<6;i++) { sqn[i] = autn_enb[i] ^ ak[i]; } + // Extract AMF from autn + for(int i=0;i<2;i++){ + amf[i]=autn_enb[6+i]; + } // Generate cdout for(i=0; i<6; i++) { From e4b1525982e72736499ba05fda8875abf5eb4b1e Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 1 Feb 2018 14:08:16 +0000 Subject: [PATCH 2/7] Removed AMF from USIM configuration. AMF is exctracted from the authentication request now. --- srsue/hdr/upper/usim.h | 1 - srsue/src/main.cc | 1 - srsue/src/upper/usim.cc | 7 ------- srsue/test/upper/nas_test.cc | 2 -- srsue/test/upper/usim_test.cc | 1 - srsue/ue.conf.example | 1 - 6 files changed, 13 deletions(-) diff --git a/srsue/hdr/upper/usim.h b/srsue/hdr/upper/usim.h index cf5a4c820..e37f58218 100644 --- a/srsue/hdr/upper/usim.h +++ b/srsue/hdr/upper/usim.h @@ -43,7 +43,6 @@ typedef enum{ typedef struct{ std::string algo; std::string op; - std::string amf; std::string imsi; std::string imei; std::string k; diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 98966510c..498aacd54 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -124,7 +124,6 @@ void parse_args(all_args_t *args, int argc, char *argv[]) { ("usim.algo", bpo::value(&args->usim.algo), "USIM authentication algorithm") ("usim.op", bpo::value(&args->usim.op), "USIM operator variant") - ("usim.amf", bpo::value(&args->usim.amf), "USIM authentication management field") ("usim.imsi", bpo::value(&args->usim.imsi), "USIM IMSI") ("usim.imei", bpo::value(&args->usim.imei), "USIM IMEI") ("usim.k", bpo::value(&args->usim.k), "USIM K") diff --git a/srsue/src/upper/usim.cc b/srsue/src/upper/usim.cc index f8b45d625..b9f4fda0e 100644 --- a/srsue/src/upper/usim.cc +++ b/srsue/src/upper/usim.cc @@ -53,13 +53,6 @@ void usim::init(usim_args_t *args, srslte::log *usim_log_) usim_log->console("Invalid length for OP: %d should be %d", args->op.length(), 32); } - if(4 == args->amf.length()) { - str_to_hex(args->amf, amf); - } else { - usim_log->error("Invalid length for AMF: %d should be %d", args->amf.length(), 4); - usim_log->console("Invalid length for AMF: %d should be %d", args->amf.length(), 4); - } - if(15 == args->imsi.length()) { imsi = 0; for(i=0; i<15; i++) diff --git a/srsue/test/upper/nas_test.cc b/srsue/test/upper/nas_test.cc index f328d77df..4f4ffb687 100644 --- a/srsue/test/upper/nas_test.cc +++ b/srsue/test/upper/nas_test.cc @@ -117,7 +117,6 @@ int security_command_test() usim_args_t args; args.algo = "xor"; - args.amf = "9001"; args.imei = "353490069873319"; args.imsi = "001010123456789"; args.k = "00112233445566778899aabbccddeeff"; @@ -179,7 +178,6 @@ int mme_attach_request_test() srsue::usim usim; usim_args_t args; args.algo = "xor"; - args.amf = "9001"; args.imei = "353490069873319"; args.imsi = "001010123456789"; args.k = "00112233445566778899aabbccddeeff"; diff --git a/srsue/test/upper/usim_test.cc b/srsue/test/upper/usim_test.cc index 4ac468673..bf60e124c 100644 --- a/srsue/test/upper/usim_test.cc +++ b/srsue/test/upper/usim_test.cc @@ -74,7 +74,6 @@ int main(int argc, char **argv) usim_args_t args; args.algo = "milenage"; - args.amf = "8000"; args.imei = "35609204079301"; args.imsi = "208930000000001"; args.k = "8BAF473F2F8FD09487CCCBD7097C6862"; diff --git a/srsue/ue.conf.example b/srsue/ue.conf.example index 347822072..140662ac0 100644 --- a/srsue/ue.conf.example +++ b/srsue/ue.conf.example @@ -93,7 +93,6 @@ file_max_size = -1 [usim] algo = xor op = 63BFA50EE6523365FF14C1F45F88737D -amf = 9001 k = 00112233445566778899aabbccddeeff imsi = 001010123456789 imei = 353490069873319 From e2c3a304b7c04d1d06ffa50b2f999712f0018b30 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Thu, 1 Feb 2018 18:17:40 +0100 Subject: [PATCH 3/7] In-sync and out-of-sync after 100 and 200 ms. Use RSRP -124 dBm as per the specs instead of SNR --- srsue/hdr/phy/phch_recv.h | 7 +++++++ srsue/src/phy/phch_recv.cc | 20 ++++++++++++++++++-- srsue/src/phy/phch_worker.cc | 16 +++++++--------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/srsue/hdr/phy/phch_recv.h b/srsue/hdr/phy/phch_recv.h index 0530459df..50ea28f96 100644 --- a/srsue/hdr/phy/phch_recv.h +++ b/srsue/hdr/phy/phch_recv.h @@ -291,6 +291,13 @@ private: // Sync metrics sync_metrics_t metrics; + // in-sync / out-of-sync counters + uint32_t out_of_sync_cnt; + uint32_t in_sync_cnt; + + const static uint32_t NOF_OUT_OF_SYNC_SF = 200; + const static uint32_t NOF_IN_SYNC_SF = 100; + // State for primary cell enum { IDLE = 0, diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index 7d89892c9..de80d53c7 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -124,6 +124,8 @@ void phch_recv::stop() void phch_recv::reset() { + in_sync_cnt = 0; + out_of_sync_cnt = 0; tx_mutex_cnt = 0; phy_state = IDLE; time_adv_sec = 0; @@ -713,6 +715,7 @@ void phch_recv::run_thread() intra_freq_meas.write(tti, buffer[0], SRSLTE_SF_LEN_PRB(cell.nof_prb)); break; case 0: + Warning("SYNC: Out-of-sync detected in PSS/SSS\n"); out_of_sync(); worker->release(); worker_com->reset_ul(); @@ -742,11 +745,24 @@ void phch_recv::run_thread() } void phch_recv::in_sync() { - rrc->in_sync(); + out_of_sync_cnt = 0; + in_sync_cnt++; + // Send RRC in-sync signal after 100 ms consecutive subframes + if (in_sync_cnt == NOF_IN_SYNC_SF) { + rrc->in_sync(); + in_sync_cnt = 0; + } } +// Out of sync called by worker or phch_recv every 1 or 5 ms void phch_recv::out_of_sync() { - rrc->out_of_sync(); + in_sync_cnt = 0; + // Send RRC out-of-sync signal after 200 ms consecutive subframes + out_of_sync_cnt++; + if (out_of_sync_cnt >= NOF_OUT_OF_SYNC_SF) { + rrc->out_of_sync(); + out_of_sync_cnt = 0; + } } diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index ebb8710d5..8644beee6 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -241,15 +241,12 @@ void phch_worker::work_imp() /* Do FFT and extract PDCCH LLR, or quit if no actions are required in this subframe */ bool chest_ok = extract_fft_and_pdcch_llr(); - bool snr_th_err = 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest))<-20.0; - bool snr_th_ok = 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest))>-15.0; - // Call feedback loop for chest if (chest_loop && ((1<<(tti%10)) & phy->args->cfo_ref_mask)) { chest_loop->set_cfo(srslte_chest_dl_get_cfo(&ue_dl.chest)); } - if (chest_ok && !snr_th_err) { + if (chest_ok) { /***** Downlink Processing *******/ @@ -370,12 +367,13 @@ void phch_worker::work_imp() update_measurements(); if (chest_ok) { - if (snr_th_ok) { - log_h->debug("SNR=%.1f dB sync=in-sync from channel estimator\n", 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest))); + if (phy->avg_rsrp_dbm > -124.0) { + log_h->debug("SNR=%.1f dB, RSRP=%.1f dBm sync=in-sync from channel estimator\n", + 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest)), phy->avg_rsrp_dbm); chest_loop->in_sync(); - } else if (snr_th_err) { - log_h->info("SNR=%.1f dB sync=out-of-sync from channel estimator\n", - 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest))); + } else { + log_h->warning("SNR=%.1f dB RSRP=%.1f dBm, sync=out-of-sync from channel estimator\n", + 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest)), phy->avg_rsrp_dbm); chest_loop->out_of_sync(); } } From 36358fa34bc75a262e94cc5fd78a25b09ad215ae Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Thu, 1 Feb 2018 20:16:10 +0100 Subject: [PATCH 4/7] Use SNR as out-of-sync threshold in addition to RSRP --- srsue/src/phy/phch_worker.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srsue/src/phy/phch_worker.cc b/srsue/src/phy/phch_worker.cc index 8644beee6..3d051825d 100644 --- a/srsue/src/phy/phch_worker.cc +++ b/srsue/src/phy/phch_worker.cc @@ -367,7 +367,7 @@ void phch_worker::work_imp() update_measurements(); if (chest_ok) { - if (phy->avg_rsrp_dbm > -124.0) { + if (phy->avg_rsrp_dbm > -124.0 && 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest)) > -30.0) { log_h->debug("SNR=%.1f dB, RSRP=%.1f dBm sync=in-sync from channel estimator\n", 10*log10(srslte_chest_dl_get_snr(&ue_dl.chest)), phy->avg_rsrp_dbm); chest_loop->in_sync(); From 5eeaf529904aebd5e5d87bc9d87ac48dcf5581f9 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Thu, 1 Feb 2018 20:16:35 +0100 Subject: [PATCH 5/7] Check for non-zero payload in log --- lib/src/common/log_filter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/common/log_filter.cc b/lib/src/common/log_filter.cc index 6720c21ad..b498d466c 100644 --- a/lib/src/common/log_filter.cc +++ b/lib/src/common/log_filter.cc @@ -126,7 +126,7 @@ void log_filter::all_log(srslte::LOG_LEVEL_ENUM level, ss << std::endl; } - if (hex_limit > 0) { + if (hex_limit > 0 && hex && size > 0) { ss << hex_string(hex, size); } str_ptr s_ptr(new std::string(ss.str())); From 45ea443377891d24f0782604becc6b6e4e8ef507 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Thu, 1 Feb 2018 20:48:27 +0100 Subject: [PATCH 6/7] Deallocate attach_request pdu --- srsue/src/upper/rrc.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 84e4bbfd1..f34c80979 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -958,6 +958,8 @@ void rrc::send_con_setup_complete(byte_buffer_t *nas_msg) { memcpy(ul_dcch_msg.msg.rrc_con_setup_complete.dedicated_info_nas.msg, nas_msg->msg, nas_msg->N_bytes); ul_dcch_msg.msg.rrc_con_setup_complete.dedicated_info_nas.N_bytes = nas_msg->N_bytes; + pool->deallocate(nas_msg); + send_ul_dcch_msg(); } From 348117df3c298e14b374af437c27a7a4bc5c8a60 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Fri, 2 Feb 2018 10:58:40 +0100 Subject: [PATCH 7/7] Recover on radio overflow --- srsue/hdr/phy/phy.h | 1 + srsue/hdr/ue.h | 3 ++- srsue/hdr/ue_base.h | 2 ++ srsue/src/phy/phch_recv.cc | 6 ++++-- srsue/src/phy/phy.cc | 5 +++++ srsue/src/ue.cc | 7 +++++++ 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index 5a1ac14a7..53d4f6e13 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -78,6 +78,7 @@ public: void set_earfcn(std::vector earfcns); void force_freq(float dl_freq, float ul_freq); + void radio_overflow(); /********** RRC INTERFACE ********************/ void reset(); diff --git a/srsue/hdr/ue.h b/srsue/hdr/ue.h index b008b2fd5..763531261 100644 --- a/srsue/hdr/ue.h +++ b/srsue/hdr/ue.h @@ -73,13 +73,14 @@ public: void start_plot(); static void rf_msg(srslte_rf_error_t error); - void handle_rf_msg(srslte_rf_error_t error); // UE metrics interface bool get_metrics(ue_metrics_t &m); void pregenerate_signals(bool enable); + void radio_overflow(); + private: virtual ~ue(); diff --git a/srsue/hdr/ue_base.h b/srsue/hdr/ue_base.h index 9674a1486..256813d5f 100644 --- a/srsue/hdr/ue_base.h +++ b/srsue/hdr/ue_base.h @@ -156,6 +156,8 @@ public: virtual void stop() = 0; virtual bool is_attached() = 0; virtual void start_plot() = 0; + + virtual void radio_overflow() = 0; void handle_rf_msg(srslte_rf_error_t error); diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index de80d53c7..944a6e955 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -296,15 +296,17 @@ bool phch_recv::stop_sync() { usleep(10000); cnt++; } + if (!is_in_idle) { + Warning("SYNC: Could not go to IDLE\n"); + } return is_in_idle; } } void phch_recv::reset_sync() { - wait_radio_reset(); - Warning("SYNC: Resetting sync, cell_search_in_progress=%s\n", cell_search_in_progress?"yes":"no"); + search_p.reset(); srslte_ue_sync_reset(&ue_sync); resync_sfn(true, true); diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index 0763b09cb..820cf1351 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -352,6 +352,11 @@ int phy::prach_tx_tti() return prach_buffer.tx_tti(); } +// Handle the case of a radio overflow. Resynchronise inmediatly +void phy::radio_overflow() { + sf_recv.reset_sync(); +} + void phy::reset() { Info("Resetting PHY\n"); diff --git a/srsue/src/ue.cc b/srsue/src/ue.cc index 184cbcf56..a9277e62c 100644 --- a/srsue/src/ue.cc +++ b/srsue/src/ue.cc @@ -297,10 +297,17 @@ bool ue::get_metrics(ue_metrics_t &m) return false; } +void ue::radio_overflow() { + phy.radio_overflow(); +} + void ue::rf_msg(srslte_rf_error_t error) { ue_base *ue = ue_base::get_instance(LTE); ue->handle_rf_msg(error); + if(error.type == srslte_rf_error_t::SRSLTE_RF_ERROR_OVERFLOW) { + ue->radio_overflow(); + } } } // namespace srsue