diff --git a/lib/include/srslte/interfaces/ue_interfaces.h b/lib/include/srslte/interfaces/ue_interfaces.h index 52d11416c..923111371 100644 --- a/lib/include/srslte/interfaces/ue_interfaces.h +++ b/lib/include/srslte/interfaces/ue_interfaces.h @@ -580,7 +580,6 @@ public: /* Cell search and selection procedures */ virtual void cell_search_start() = 0; - virtual void cell_search_stop() = 0; virtual void cell_search_next() = 0; virtual void cell_select(uint32_t earfcn, srslte_cell_t cell) = 0; virtual bool cell_handover(srslte_cell_t cell) = 0; diff --git a/lib/src/phy/ue/ue_sync.c b/lib/src/phy/ue/ue_sync.c index d99bff89a..b66cf5b53 100644 --- a/lib/src/phy/ue/ue_sync.c +++ b/lib/src/phy/ue/ue_sync.c @@ -755,7 +755,9 @@ int srslte_ue_sync_zerocopy_multi(srslte_ue_sync_t *q, cf_t *input_buffer[SRSLTE if (q->do_agc) { srslte_agc_process(&q->agc, input_buffer[0], q->sf_len); } - + + INFO("SYNC FIND: sf_idx=%d, ret=%d, next_state=%d\n", q->sf_idx, ret, q->state); + break; case SF_TRACK: @@ -817,6 +819,9 @@ int srslte_ue_sync_zerocopy_multi(srslte_ue_sync_t *q, cf_t *input_buffer[SRSLTE q->frame_total_cnt++; } + + INFO("SYNC TRACK: sf_idx=%d, ret=%d, next_state=%d\n", q->sf_idx, ret, q->state); + break; } } diff --git a/srsue/hdr/phy/phch_recv.h b/srsue/hdr/phy/phch_recv.h index b5848a6b3..861d58229 100644 --- a/srsue/hdr/phy/phch_recv.h +++ b/srsue/hdr/phy/phch_recv.h @@ -61,7 +61,6 @@ public: void reset_sync(); void cell_search_start(); - void cell_search_stop(); void cell_search_next(bool reset = false); void cell_select(uint32_t earfcn, srslte_cell_t cell); bool cell_handover(srslte_cell_t cell); @@ -299,14 +298,16 @@ private: const static uint32_t NOF_IN_SYNC_SF = 100; // State for primary cell - enum { + typedef enum { IDLE = 0, CELL_SEARCH, CELL_SELECT, CELL_RESELECT, CELL_MEASURE, CELL_CAMP, - } phy_state; + } phy_state_t; + + phy_state_t phy_state, prev_state; bool is_in_idle; @@ -330,7 +331,6 @@ private: float ul_dl_factor; uint32_t current_earfcn; int cur_earfcn_index; - bool cell_search_in_progress; float dl_freq; float ul_freq; diff --git a/srsue/hdr/phy/phy.h b/srsue/hdr/phy/phy.h index 9270973c0..0894a98fb 100644 --- a/srsue/hdr/phy/phy.h +++ b/srsue/hdr/phy/phy.h @@ -85,7 +85,6 @@ public: void sync_reset(); void configure_ul_params(bool pregen_disabled = false); void cell_search_start(); - void cell_search_stop(); void cell_search_next(); void cell_select(uint32_t earfcn, srslte_cell_t phy_cell); bool cell_handover(srslte_cell_t cell); diff --git a/srsue/src/phy/phch_recv.cc b/srsue/src/phy/phch_recv.cc index a6f1a5d84..ad76537e0 100644 --- a/srsue/src/phy/phch_recv.cc +++ b/srsue/src/phy/phch_recv.cc @@ -132,7 +132,6 @@ void phch_recv::reset() next_offset = 0; cell_is_set = false; srate_mode = SRATE_NONE; - cell_search_in_progress = false; current_earfcn = 0; sfn_p.reset(); measure_p.reset(); @@ -262,17 +261,17 @@ void phch_recv::reset_sync() { search_p.reset(); measure_p.reset(); srslte_ue_sync_reset(&ue_sync); - + Info("----- PHY RESET----\n"); phy_state = CELL_SELECT; } void phch_recv::cell_search_inc() { + Info("cell_search_inc, cur_idx=%d, size=%d\n", cur_earfcn_index, earfcn.size()); cur_earfcn_index++; if (cur_earfcn_index >= 0) { if (cur_earfcn_index >= (int) earfcn.size()) { cur_earfcn_index = 0; - cell_search_in_progress = false; phy_state = IDLE; rrc->earfcn_end(); } else { @@ -281,20 +280,16 @@ void phch_recv::cell_search_inc() current_earfcn = earfcn[cur_earfcn_index]; set_frequency(); } + phy_state = CELL_SEARCH; } } } void phch_recv::cell_search_next(bool reset) { - if (cell_search_in_progress || reset) { - cell_search_in_progress = false; - if (reset) { - cur_earfcn_index = -1; - } - cell_search_inc(); - phy_state = CELL_SEARCH; - cell_search_in_progress = true; + if (reset) { + cur_earfcn_index = -1; } + cell_search_inc(); } void phch_recv::cell_search_start() { @@ -311,11 +306,6 @@ void phch_recv::cell_search_start() { } } -void phch_recv::cell_search_stop() { - Info("SYNC: Stopping Cell Search procedure...\n"); - cell_search_in_progress = false; -} - bool phch_recv::cell_handover(srslte_cell_t cell) { int cnt = 0; @@ -369,19 +359,18 @@ void phch_recv::cell_reselect() uint32_t earfcn = new_earfcn; srslte_cell_t cell = new_cell; + Info("Reset from cell_reselect\n"); + reset_sync(); + // If we are already in the new cell, just resynchronize if (earfcn == current_earfcn && this->cell.id == cell.id) { - log_h->info("Cell Select: Already in cell EARFCN=%d\n", earfcn); - cell_search_in_progress = false; + log_h->info("Cell Select: Already in cell EARFCN=%d, PCI=%d\n", earfcn, cell.id); if (srate_mode != SRATE_CAMP) { set_sampling_rate(); + log_h->info("Cell Select: Setting Camping sampling rate\n"); } - phy_state = CELL_SELECT; } else { - /* If we are going to a new cell, configure it */ - cell_search_in_progress = false; - if (earfcn != current_earfcn) { if (set_frequency()) { log_h->error("Cell Select: Configuring cell in EARFCN=%d, PCI=%d\n", earfcn, cell.id); @@ -394,7 +383,6 @@ void phch_recv::cell_reselect() if (set_cell()) { log_h->info("Cell Select: Synchronizing on cell...\n"); - phy_state = CELL_SELECT; } } } @@ -533,33 +521,29 @@ void phch_recv::run_thread() sf_idx = tti%10; + prev_state = phy_state; + switch (phy_state) { case CELL_SEARCH: - if (cell_search_in_progress) + switch(search_p.run(&cell)) { - switch(search_p.run(&cell)) - { - case search::CELL_FOUND: - if (!srslte_cell_isvalid(&cell)) { - Error("SYNC: Detected invalid cell\n"); - phy_state = IDLE; - break; - } - if (set_cell()) { - set_sampling_rate(); - phy_state = CELL_SELECT; - } - break; - case search::CELL_NOT_FOUND: - if (cell_search_in_progress) { - cell_search_inc(); - } + case search::CELL_FOUND: + if (!srslte_cell_isvalid(&cell)) { + Error("SYNC: Detected invalid cell\n"); phy_state = IDLE; break; - default: - radio_error(); - break; } + if (set_cell()) { + set_sampling_rate(); + phy_state = CELL_SELECT; + } + break; + case search::CELL_NOT_FOUND: + cell_search_inc(); + break; + default: + radio_error(); + break; } break; case CELL_RESELECT: @@ -569,7 +553,7 @@ void phch_recv::run_thread() switch (sfn_p.run_subframe(&cell, &tti)) { case sfn_sync::SFN_FOUND: - if (!cell_search_in_progress) { + if (prev_state == CELL_SEARCH) { log_h->info("Sync OK. Camping on cell PCI=%d...\n", cell.id); phy_state = CELL_CAMP; rrc->cell_camping(earfcn[cur_earfcn_index], cell); @@ -580,13 +564,8 @@ void phch_recv::run_thread() } break; case sfn_sync::TIMEOUT: - if (cell_search_in_progress) { - log_h->warning("SYNC: Timeout while synchronizing SFN. Going back to cell search\n"); - phy_state = CELL_SEARCH; - } else { - log_h->warning("SYNC: Timeout while synchronizing SFN. Reselecting cell\n"); - phy_state = CELL_SELECT; - } + log_h->warning("SYNC: Timeout while synchronizing SFN. Going back to cell search\n"); + phy_state = CELL_SEARCH; break; case sfn_sync::IDLE: break; @@ -610,7 +589,6 @@ void phch_recv::run_thread() log_h->info("SYNC: Measured OK. Camping on cell PCI=%d...\n", cell.id); phy_state = CELL_CAMP; - cell_search_in_progress = false; rrc->cell_camping(earfcn[cur_earfcn_index], cell, measure_p.rsrp()); break; case measure::IDLE: @@ -833,6 +811,7 @@ phch_recv::search::ret_code phch_recv::search::run(srslte_cell_t *cell) if (p->srate_mode != SRATE_FIND) { p->srate_mode = SRATE_FIND; p->radio_h->set_rx_srate(1.92e6); + Info("SYNC: Setting Cell Search sampling rate\n"); } /* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */ @@ -992,7 +971,7 @@ phch_recv::sfn_sync::ret_code phch_recv::sfn_sync::run_subframe(srslte_cell_t *c } } } else { - Debug("SYNC: PSS/SSS not found...\n"); + Info("SYNC: PSS/SSS not found...\n"); } cnt++; diff --git a/srsue/src/phy/phy.cc b/srsue/src/phy/phy.cc index a2d517a02..e4b618158 100644 --- a/srsue/src/phy/phy.cc +++ b/srsue/src/phy/phy.cc @@ -256,11 +256,6 @@ void phy::cell_search_start() sf_recv.cell_search_start(); } -void phy::cell_search_stop() -{ - sf_recv.cell_search_stop(); -} - void phy::cell_search_next() { sf_recv.cell_search_next(); diff --git a/srsue/src/upper/nas.cc b/srsue/src/upper/nas.cc index 7f5683867..8a05595c7 100644 --- a/srsue/src/upper/nas.cc +++ b/srsue/src/upper/nas.cc @@ -161,14 +161,15 @@ void nas::plmn_found(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id, uint16_t tracking_ // RRC indicates that the UE has gone through all EARFCN and finished PLMN selection void nas::plmn_search_end() { if (known_plmns.size() > 0) { - nas_log->info("Could not find Home PLMN Id=%s, trying to connect to PLMN Id=%s\n", - plmn_id_to_string(home_plmn).c_str(), - plmn_id_to_string(known_plmns[0]).c_str()); - - nas_log->console("Could not find Home PLMN Id=%s, trying to connect to PLMN Id=%s\n", - plmn_id_to_string(home_plmn).c_str(), - plmn_id_to_string(known_plmns[0]).c_str()); - + if (home_plmn.mcc != known_plmns[0].mcc && home_plmn.mnc != known_plmns[0].mnc) { + nas_log->info("Could not find Home PLMN Id=%s, trying to connect to PLMN Id=%s\n", + plmn_id_to_string(home_plmn).c_str(), + plmn_id_to_string(known_plmns[0]).c_str()); + + nas_log->console("Could not find Home PLMN Id=%s, trying to connect to PLMN Id=%s\n", + plmn_id_to_string(home_plmn).c_str(), + plmn_id_to_string(known_plmns[0]).c_str()); + } rrc->plmn_select(known_plmns[0]); } else { nas_log->info("Finished searching PLMN in current EARFCN set but no networks were found.\n"); diff --git a/srsue/src/upper/rrc.cc b/srsue/src/upper/rrc.cc index 1aecb273b..cdd19f22c 100644 --- a/srsue/src/upper/rrc.cc +++ b/srsue/src/upper/rrc.cc @@ -212,10 +212,8 @@ void rrc::run_thread() { plmn_select_timeout++; if (plmn_select_timeout >= RRC_PLMN_SELECT_TIMEOUT) { rrc_log->info("RRC PLMN Search: timeout expired\n"); - phy->cell_search_stop(); - sleep(1); - rrc_log->console("\nRRC PLMN Search: timeout expired. Searching again\n"); - + rrc_log->console("\nRRC PLMN Search: timeout expired.\n"); + state = RRC_STATE_IDLE; } break; case RRC_STATE_CELL_SELECTING: @@ -236,14 +234,13 @@ void rrc::run_thread() { } } // Don't time out during reestablishment (T311 running) - if (!mac_timers->timer_get(t311)->is_running()) { + if (!mac_timers->timer_get(t311)->is_running() || !phy->sync_status()) { select_cell_timeout++; if (select_cell_timeout >= RRC_SELECT_CELL_TIMEOUT) { rrc_log->info("RRC Cell Selecting: timeout expired. Starting Cell Search...\n"); - plmn_select_timeout = 0; select_cell_timeout = 0; + state = RRC_STATE_PLMN_START; serving_cell->in_sync = false; - phy->cell_search_start(); } } break; @@ -457,17 +454,30 @@ void rrc::plmn_select_rrc(LIBLTE_RRC_PLMN_IDENTITY_STRUCT plmn_id) { if (state == RRC_STATE_IDLE || state == RRC_STATE_CONNECTED || state == RRC_STATE_PLMN_SELECTION) { if (phy->sync_status() && selected_plmn_id.mcc == plmn_id.mcc && selected_plmn_id.mnc == plmn_id.mnc) { rrc_log->info("Already camping on selected PLMN, connecting...\n"); - state = RRC_STATE_CELL_SELECTING; - select_cell_timeout = 0; } else { - rrc_log->info("PLMN Id=%s selected\n", plmn_id_to_string(plmn_id).c_str()); - // Sort cells according to RSRP - selected_plmn_id = plmn_id; - select_cell_timeout = 0; - state = RRC_STATE_CELL_SELECTING; + if (serving_cell->plmn_equals(selected_plmn_id)) { + phy->cell_select(serving_cell->get_earfcn(), serving_cell->phy_cell); + } else { + bool found = false; + for (uint32_t i=0;iplmn_equals(selected_plmn_id)) { + rrc_log->info("PLMN Id=%s selected, PCI=%d\n", plmn_id_to_string(plmn_id).c_str(), neighbour_cells[i]->get_pci()); + phy->cell_select(neighbour_cells[i]->get_earfcn(), neighbour_cells[i]->phy_cell); + found = true; + } + } + if (!found) { + rrc_log->warning("Could not find any cell for the selected PLMN\n"); + state = RRC_STATE_IDLE; + return; + } + } } + + state = RRC_STATE_CELL_SELECTING; + select_cell_timeout = 0; } else { rrc_log->warning("Requested PLMN select in incorrect state %s\n", rrc_state_text[state]); } @@ -988,7 +998,6 @@ void rrc::send_con_restablish_request(LIBLTE_RRC_CON_REEST_REQ_CAUSE_ENUM cause, break; default: rrc_log->info("Unsupported integrity algorithm during reestablishment\n"); - return; } // Prepare ConnectionRestalishmentRequest packet