diff --git a/include/lorawan/lorawan.h b/include/lorawan/lorawan.h index 0ba3211670f..58ace723d32 100644 --- a/include/lorawan/lorawan.h +++ b/include/lorawan/lorawan.h @@ -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 { diff --git a/subsys/lorawan/lorawan.c b/subsys/lorawan/lorawan.c index 84559b99c7b..c10b3f57ac9 100644 --- a/subsys/lorawan/lorawan.c +++ b/subsys/lorawan/lorawan.c @@ -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);