WisBlock LoRaWan DevNonce

The LoRaWan specification indicates that a device can only use a dev-nonce once. If the device powers down and needs to re-establish a connection to a LoRa Gateway it either needs to start at 1 and step through each value until one that has not been used is found, or it needs to store the last dev-nonce value that was used and increment that value. It is this latter more efficient approach that is implemented here.

The LoRaWan 1.04 specification chapter 6.2.5 “Join-Request Frame” says “A DevNonce value shall never be reused for a given JoinEUI value. If the end-device can be power-cycled, then DevNonce shall be persisted (e.g. stored in non-volatile memory). Resetting DevNonce without changing JoinEUI will cause the Join Server to discard Join-Requests of the end-device. For each end-device the Join Server keeps track of the last DevNonce value used by the end-device and ignores Join-Requests if DevNonce is not incremented“.

The structure of the lora-mac code allows for board specific customizations by implementing hardware device files including eeprom-board.c and rtc-board.c. I have implemented this in the rtc-board file and I extended the rtc-board.h template to include interfaces for RtcEEPROMWrite and RtcEEPROMRead.

The DevNonce value is generated in the LoRaMacCrypto.c file in the LoRaMacCryptoPrepareJoinRequest function. Here I retrieve the two bytes having the last DevNonce value used, increment it and store the two bytes back into RTC EEPROM. Full source code is on my GitHub repository here.


Posted

in

by

Tags:

Comments

Leave a Reply