Skip to content

Commit 9cc32af

Browse files
martinjaegernashif
authored andcommitted
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 <[email protected]>
1 parent f613b54 commit 9cc32af

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

include/lorawan/lorawan.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,20 @@ enum lorawan_message_type {
7878
* case the values stored in the secure element will be used instead.
7979
*/
8080
struct lorawan_join_otaa {
81+
/** Join EUI */
8182
uint8_t *join_eui;
83+
/** Network Key */
8284
uint8_t *nwk_key;
85+
/** Application Key */
8386
uint8_t *app_key;
87+
/**
88+
* Device Nonce
89+
*
90+
* Starting with LoRaWAN 1.0.4 the DevNonce must be monotonically
91+
* increasing for each OTAA join with the same EUI. The DevNonce
92+
* should be stored in non-volatile memory by the application.
93+
*/
94+
uint32_t dev_nonce;
8495
};
8596

8697
struct lorawan_join_abp {

subsys/lorawan/lorawan.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ static LoRaMacStatus_t lorawan_join_otaa(
212212
mlme_req.Req.Join.Datarate = default_datarate;
213213
mlme_req.Req.Join.NetworkActivation = ACTIVATION_TYPE_OTAA;
214214

215+
/* Retrieve the NVM context to store device nonce */
216+
mib_req.Type = MIB_NVM_CTXS;
217+
if (LoRaMacMibGetRequestConfirm(&mib_req) != LORAMAC_STATUS_OK) {
218+
LOG_ERR("Could not get NVM context");
219+
return -EINVAL;
220+
}
221+
mib_req.Param.Contexts->Crypto.DevNonce = join_cfg->otaa.dev_nonce;
222+
215223
mib_req.Type = MIB_DEV_EUI;
216224
mib_req.Param.DevEui = join_cfg->dev_eui;
217225
LoRaMacMibSetRequestConfirm(&mib_req);

0 commit comments

Comments
 (0)