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) {
return equals(x->phy_cell.earfcn, x->phy_cell.cell.id);
}
bool equals(uint32_t earfcn, uint32_t pci) {
return earfcn == this->phy_cell.earfcn && pci == phy_cell.cell.id;
}
bool equals(uint32_t earfcn, uint32_t pci) { return earfcn == 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
bool greater(cell_t *x) {
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);
cout << "Attaching UE..." << endl;
while (!ue.switch_on() && running) {
sleep(1);
}
ue.switch_on();
if (running) {
if (args.gui.enable) {
ue.start_plot();
}
if (args.gui.enable) {
ue.start_plot();
}
while (running) {

View File

@ -167,15 +167,9 @@ void ue_stack_lte::stop_impl()
bool ue_stack_lte::switch_on()
{
if (running) {
proc_state_t proc_result = proc_state_t::on_going;
pending_tasks.try_push(ue_queue_id,
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;
pending_tasks.try_push(ue_queue_id, task_t{[this](task_t*) { nas.start_attach_request(nullptr); }});
return true;
}
return false;
}

View File

@ -303,7 +303,9 @@ void nas::start_attach_request(srslte::proc_state_t* result)
if (!plmn_is_selected) {
nas_log->info("No PLMN selected. Starting PLMN Search...\n");
if (not plmn_searcher.launch(this)) {
*result = proc_state_t::error;
if (result != nullptr) {
*result = proc_state_t::error;
}
return;
}
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();
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;
// stay in this state if attach failed
if (result != nullptr) {
*result = p.is_success() ? proc_state_t::success : proc_state_t::error;
}
if (not p.is_success()) {
enter_emm_deregistered();
}
@ -321,18 +324,24 @@ void nas::start_attach_request(srslte::proc_state_t* result)
});
} else {
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;
case EMM_STATE_REGISTERED:
if (rrc->is_connected()) {
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 {
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)) {
nas_log->error("Cannot initiate concurrent rrc connection procedures\n");
*result = proc_state_t::error;
if (result != nullptr) {
*result = proc_state_t::error;
}
return;
}
callbacks.defer_task([this, result]() {
@ -345,14 +354,18 @@ void nas::start_attach_request(srslte::proc_state_t* result)
} else {
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;
});
}
break;
default:
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;
}
}
}