make UE switch_on non-blocking

this allows a simpler main that just signals NAS to switch on the UE
but doesn't block until the action is completed.

For making sure the UE also attached if the first attempt failed
the NAS needs to be extended to support the correct timers.
This commit is contained in:
Andre Puschmann 2019-10-11 13:28:57 +02:00
parent 626259eede
commit 35307a047a
4 changed files with 27 additions and 26 deletions

View File

@ -77,9 +77,7 @@ class cell_t
bool equals(cell_t *x) { bool equals(cell_t *x) {
return equals(x->phy_cell.earfcn, x->phy_cell.cell.id); return equals(x->phy_cell.earfcn, x->phy_cell.cell.id);
} }
bool equals(uint32_t earfcn, uint32_t pci) { bool equals(uint32_t earfcn, uint32_t pci) { return earfcn == phy_cell.earfcn && pci == phy_cell.cell.id; }
return earfcn == this->phy_cell.earfcn && pci == phy_cell.cell.id;
}
// NaN means an RSRP value has not yet been obtained. Keep then in the list and clean them if never updated // NaN means an RSRP value has not yet been obtained. Keep then in the list and clean them if never updated
bool greater(cell_t *x) { bool greater(cell_t *x) {
return rsrp > x->rsrp || std::isnan(rsrp); return rsrp > x->rsrp || std::isnan(rsrp);

View File

@ -583,14 +583,10 @@ int main(int argc, char* argv[])
pthread_create(&input, nullptr, &input_loop, &args); pthread_create(&input, nullptr, &input_loop, &args);
cout << "Attaching UE..." << endl; cout << "Attaching UE..." << endl;
while (!ue.switch_on() && running) { ue.switch_on();
sleep(1);
}
if (running) { if (args.gui.enable) {
if (args.gui.enable) { ue.start_plot();
ue.start_plot();
}
} }
while (running) { while (running) {

View File

@ -167,15 +167,9 @@ void ue_stack_lte::stop_impl()
bool ue_stack_lte::switch_on() bool ue_stack_lte::switch_on()
{ {
if (running) { if (running) {
proc_state_t proc_result = proc_state_t::on_going; pending_tasks.try_push(ue_queue_id, task_t{[this](task_t*) { nas.start_attach_request(nullptr); }});
pending_tasks.try_push(ue_queue_id, return true;
task_t{[this, &proc_result](task_t*) { nas.start_attach_request(&proc_result); }});
while (proc_result == proc_state_t::on_going) {
usleep(1000);
}
return proc_result == proc_state_t::success;
} }
return false; return false;
} }

View File

@ -303,7 +303,9 @@ void nas::start_attach_request(srslte::proc_state_t* result)
if (!plmn_is_selected) { if (!plmn_is_selected) {
nas_log->info("No PLMN selected. Starting PLMN Search...\n"); nas_log->info("No PLMN selected. Starting PLMN Search...\n");
if (not plmn_searcher.launch(this)) { if (not plmn_searcher.launch(this)) {
*result = proc_state_t::error; if (result != nullptr) {
*result = proc_state_t::error;
}
return; return;
} }
callbacks.defer_task([this, result]() { callbacks.defer_task([this, result]() {
@ -312,8 +314,9 @@ void nas::start_attach_request(srslte::proc_state_t* result)
} }
plmn_search_proc p = plmn_searcher.pop(); plmn_search_proc p = plmn_searcher.pop();
nas_log->info("Attach Request from PLMN Search %s\n", p.is_success() ? "finished successfully" : "failed"); nas_log->info("Attach Request from PLMN Search %s\n", p.is_success() ? "finished successfully" : "failed");
*result = p.is_success() ? proc_state_t::success : proc_state_t::error; if (result != nullptr) {
// stay in this state if attach failed *result = p.is_success() ? proc_state_t::success : proc_state_t::error;
}
if (not p.is_success()) { if (not p.is_success()) {
enter_emm_deregistered(); enter_emm_deregistered();
} }
@ -321,18 +324,24 @@ void nas::start_attach_request(srslte::proc_state_t* result)
}); });
} else { } else {
nas_log->error("PLMN selected in state %s\n", emm_state_text[state]); nas_log->error("PLMN selected in state %s\n", emm_state_text[state]);
*result = proc_state_t::error; if (result != nullptr) {
*result = proc_state_t::error;
}
} }
break; break;
case EMM_STATE_REGISTERED: case EMM_STATE_REGISTERED:
if (rrc->is_connected()) { if (rrc->is_connected()) {
nas_log->info("NAS is already registered and RRC connected\n"); nas_log->info("NAS is already registered and RRC connected\n");
*result = proc_state_t::success; if (result != nullptr) {
*result = proc_state_t::success;
}
} else { } else {
nas_log->info("NAS is already registered but RRC disconnected. Connecting now...\n"); nas_log->info("NAS is already registered but RRC disconnected. Connecting now...\n");
if (not rrc_connector.launch(this, srslte::establishment_cause_t ::mo_data, nullptr)) { if (not rrc_connector.launch(this, srslte::establishment_cause_t ::mo_data, nullptr)) {
nas_log->error("Cannot initiate concurrent rrc connection procedures\n"); nas_log->error("Cannot initiate concurrent rrc connection procedures\n");
*result = proc_state_t::error; if (result != nullptr) {
*result = proc_state_t::error;
}
return; return;
} }
callbacks.defer_task([this, result]() { callbacks.defer_task([this, result]() {
@ -345,14 +354,18 @@ void nas::start_attach_request(srslte::proc_state_t* result)
} else { } else {
nas_log->error("Could not attach from attach_request\n"); nas_log->error("Could not attach from attach_request\n");
} }
*result = proc.is_success() ? proc_state_t::success : proc_state_t::error; if (result != nullptr) {
*result = proc.is_success() ? proc_state_t::success : proc_state_t::error;
}
return proc_outcome_t::success; return proc_outcome_t::success;
}); });
} }
break; break;
default: default:
nas_log->info("Attach request ignored. State = %s\n", emm_state_text[state]); nas_log->info("Attach request ignored. State = %s\n", emm_state_text[state]);
*result = proc_state_t::error; if (result != nullptr) {
*result = proc_state_t::error;
}
} }
} }