From 7ce434b2748429dde92efd9373156af02a7303f6 Mon Sep 17 00:00:00 2001 From: Hasnain Virk Date: Wed, 27 Jun 2018 11:36:04 +0300 Subject: [PATCH] LoRaWAN: Fixing transport of fatal TX timeout event This commit fixes the issue reported in #7285. If the radio is unable to transmit, its a fatal error and can happen both while joining or sending a normal packet. In the case of such a catastrophy we ought to tell the application that this happened. A fix for the radio driver will also be patched. --- features/lorawan/LoRaWANStack.cpp | 42 +++++++++++++++------- features/lorawan/lorastack/mac/LoRaMac.cpp | 2 -- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/features/lorawan/LoRaWANStack.cpp b/features/lorawan/LoRaWANStack.cpp index bf2656e109..9e5bb1698a 100644 --- a/features/lorawan/LoRaWANStack.cpp +++ b/features/lorawan/LoRaWANStack.cpp @@ -557,9 +557,14 @@ void LoRaWANStack::process_transmission_timeout() // this is a fatal error and should not happen tr_debug("TX Timeout"); _loramac.on_radio_tx_timeout(); - _ctrl_flags |= TX_ONGOING_FLAG; + _ctrl_flags &= ~TX_ONGOING_FLAG; _ctrl_flags &= ~TX_DONE_FLAG; - state_controller(DEVICE_STATE_STATUS_CHECK); + if (_device_current_state == DEVICE_STATE_JOINING) { + mlme_confirm_handler(); + } else { + state_controller(DEVICE_STATE_STATUS_CHECK); + } + state_machine_run_to_completion(); } @@ -888,21 +893,33 @@ void LoRaWANStack::mlme_confirm_handler() } } } - } else if (_loramac.get_mlme_confirmation()->req_type == MLME_JOIN) { - if (_loramac.get_mlme_confirmation()->status == LORAMAC_EVENT_INFO_STATUS_OK) { - state_controller(DEVICE_STATE_CONNECTED); - } else { - tr_error("Joining error: %d", _loramac.get_mlme_confirmation()->status); - if (_loramac.get_mlme_confirmation()->status == LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL) { + } + + if (_loramac.get_mlme_confirmation()->req_type == MLME_JOIN) { + + switch (_loramac.get_mlme_confirmation()->status) { + case LORAMAC_EVENT_INFO_STATUS_OK: + state_controller(DEVICE_STATE_CONNECTED); + break; + + case LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL: // fatal error _device_current_state = DEVICE_STATE_IDLE; + tr_error("Joining abandoned: CRYPTO_ERROR"); send_event_to_application(CRYPTO_ERROR); - } else { + break; + + case LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT: + // fatal error + _device_current_state = DEVICE_STATE_IDLE; + tr_error("Joining abandoned: Radio failed to transmit"); + send_event_to_application(TX_TIMEOUT); + break; + + default: // non-fatal, retry if possible _device_current_state = DEVICE_STATE_AWAITING_JOIN_ACCEPT; state_controller(DEVICE_STATE_JOINING); - } - } } } @@ -917,9 +934,8 @@ void LoRaWANStack::mcps_confirm_handler() } // failure case - tr_error("mcps_confirmation: Error code = %d", _loramac.get_mcps_confirmation()->status); - if (_loramac.get_mcps_confirmation()->status == LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT) { + tr_error("Fatal Error, Radio failed to transmit"); send_event_to_application(TX_TIMEOUT); return; } diff --git a/features/lorawan/lorastack/mac/LoRaMac.cpp b/features/lorawan/lorastack/mac/LoRaMac.cpp index 4f5f20a7a4..b6f5edf2a8 100644 --- a/features/lorawan/lorastack/mac/LoRaMac.cpp +++ b/features/lorawan/lorastack/mac/LoRaMac.cpp @@ -727,8 +727,6 @@ void LoRaMac::on_radio_tx_timeout(void) _mcps_confirmation.nb_retries = _params.ack_timeout_retry_counter; _mcps_confirmation.ack_received = false; _mcps_confirmation.tx_toa = 0; - - post_process_mcps_req(); } void LoRaMac::on_radio_rx_timeout(bool is_timeout)