LoRaWAN: Handling re-joining when already Joined

This is a remedy for the issue #7230.
While the device is joining, LORAWAN_STATUS_CONNECT_IN_PROGRESS is returned.
However, if the device is already joined, we will return LORAWAN_STATUS_ALREADY_CONNECTED.
pull/7445/head
Hasnain Virk 2018-07-06 13:11:52 +03:00
parent 69d8c0bac3
commit 51f92b0efd
3 changed files with 18 additions and 7 deletions

View File

@ -155,6 +155,10 @@ lorawan_status_t LoRaWANStack::connect()
return LORAWAN_STATUS_NOT_INITIALIZED; return LORAWAN_STATUS_NOT_INITIALIZED;
} }
if (_loramac.nwk_joined()) {
return LORAWAN_STATUS_ALREADY_CONNECTED;
}
lorawan_status_t status = _loramac.prepare_join(NULL, MBED_CONF_LORA_OVER_THE_AIR_ACTIVATION); lorawan_status_t status = _loramac.prepare_join(NULL, MBED_CONF_LORA_OVER_THE_AIR_ACTIVATION);
if (LORAWAN_STATUS_OK != status) { if (LORAWAN_STATUS_OK != status) {
@ -170,6 +174,10 @@ lorawan_status_t LoRaWANStack::connect(const lorawan_connect_t &connect)
return LORAWAN_STATUS_NOT_INITIALIZED; return LORAWAN_STATUS_NOT_INITIALIZED;
} }
if (_loramac.nwk_joined()) {
return LORAWAN_STATUS_ALREADY_CONNECTED;
}
if (!(connect.connect_type == LORAWAN_CONNECTION_OTAA) if (!(connect.connect_type == LORAWAN_CONNECTION_OTAA)
&& !(connect.connect_type == LORAWAN_CONNECTION_ABP)) { && !(connect.connect_type == LORAWAN_CONNECTION_ABP)) {
return LORAWAN_STATUS_PARAMETER_INVALID; return LORAWAN_STATUS_PARAMETER_INVALID;
@ -1170,7 +1178,7 @@ void LoRaWANStack::process_connecting_state(lorawan_status_t &op_status)
if (_ctrl_flags & CONNECTED_FLAG) { if (_ctrl_flags & CONNECTED_FLAG) {
tr_debug("Already connected"); tr_debug("Already connected");
op_status = LORAWAN_STATUS_OK; op_status = LORAWAN_STATUS_ALREADY_CONNECTED;
return; return;
} }

View File

@ -814,9 +814,11 @@ lorawan_status_t LoRaMac::send_join_request()
status = prepare_frame(&mac_hdr, &fctrl, 0, NULL, 0); status = prepare_frame(&mac_hdr, &fctrl, 0, NULL, 0);
if (status == LORAWAN_STATUS_OK) { if (status == LORAWAN_STATUS_OK) {
status = schedule_tx(); if (schedule_tx() == LORAWAN_STATUS_OK) {
status = LORAWAN_STATUS_CONNECT_IN_PROGRESS;
}
} else { } else {
tr_error("Retransmission: error %d", status); tr_error("Couldn't send a JoinRequest: error %d", status);
} }
return status; return status;

View File

@ -98,10 +98,11 @@ typedef enum lorawan_status {
#if defined(LORAWAN_COMPLIANCE_TEST) #if defined(LORAWAN_COMPLIANCE_TEST)
LORAWAN_STATUS_COMPLIANCE_TEST_ON = -1019, /**< Compliance test - is on-going */ LORAWAN_STATUS_COMPLIANCE_TEST_ON = -1019, /**< Compliance test - is on-going */
#endif #endif
LORAWAN_STATUS_DUTYCYCLE_RESTRICTED = -1020, LORAWAN_STATUS_DUTYCYCLE_RESTRICTED = -1020, /**< Transmission will continue after duty cycle backoff*/
LORAWAN_STATUS_NO_CHANNEL_FOUND = -1021, LORAWAN_STATUS_NO_CHANNEL_FOUND = -1021, /**< None of the channels is enabled at the moment*/
LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND = -1022, LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND = -1022, /**< None of the enabled channels is ready for another TX (duty cycle limited)*/
LORAWAN_STATUS_METADATA_NOT_AVAILABLE = -1023 LORAWAN_STATUS_METADATA_NOT_AVAILABLE = -1023, /**< Meta-data after an RX or TX is stale*/
LORAWAN_STATUS_ALREADY_CONNECTED = -1024 /**< The device has already joined a network*/
} lorawan_status_t; } lorawan_status_t;
/** The lorawan_connect_otaa structure. /** The lorawan_connect_otaa structure.