lorawan: allow setting of DevNonce for OTAA re-join

Starting with LoRaWAN 1.0.4 the DevNonce sent with the OTAA join must be
monotonically increasing for each new join with the same EUI. The DevNonce
should be stored in non-volatile memory by the application.

This commit uses a simple extension of the lorawan_join_otaa struct to
allow specifying the DevNonce.

Signed-off-by: Martin Jäger <martin@libre.solar>
This commit is contained in:
Martin Jäger 2022-02-26 13:52:18 +01:00 committed by Anas Nashif
parent f613b546e0
commit 9cc32af99e
2 changed files with 19 additions and 0 deletions

View File

@ -78,9 +78,20 @@ enum lorawan_message_type {
* case the values stored in the secure element will be used instead.
*/
struct lorawan_join_otaa {
/** Join EUI */
uint8_t *join_eui;
/** Network Key */
uint8_t *nwk_key;
/** Application Key */
uint8_t *app_key;
/**
* Device Nonce
*
* Starting with LoRaWAN 1.0.4 the DevNonce must be monotonically
* increasing for each OTAA join with the same EUI. The DevNonce
* should be stored in non-volatile memory by the application.
*/
uint32_t dev_nonce;
};
struct lorawan_join_abp {

View File

@ -212,6 +212,14 @@ static LoRaMacStatus_t lorawan_join_otaa(
mlme_req.Req.Join.Datarate = default_datarate;
mlme_req.Req.Join.NetworkActivation = ACTIVATION_TYPE_OTAA;
/* Retrieve the NVM context to store device nonce */
mib_req.Type = MIB_NVM_CTXS;
if (LoRaMacMibGetRequestConfirm(&mib_req) != LORAMAC_STATUS_OK) {
LOG_ERR("Could not get NVM context");
return -EINVAL;
}
mib_req.Param.Contexts->Crypto.DevNonce = join_cfg->otaa.dev_nonce;
mib_req.Type = MIB_DEV_EUI;
mib_req.Param.DevEui = join_cfg->dev_eui;
LoRaMacMibSetRequestConfirm(&mib_req);