Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LoRaWAN] Implement full session persistence & more v1.1 specification #835

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,9 @@ setModem KEYWORD2

# LoRaWAN
wipe KEYWORD2
restoreOTAA KEYWORD2
beginOTAA KEYWORD2
beginAPB KEYWORD2
beginABP KEYWORD2
uplink KEYWORD2
downlink KEYWORD2
configureChannel KEYWORD2
Expand Down Expand Up @@ -399,5 +400,10 @@ RADIOLIB_ERR_INVALID_PORT LITERAL1
RADIOLIB_ERR_NO_RX_WINDOW LITERAL1
RADIOLIB_ERR_INVALID_CHANNEL LITERAL1
RADIOLIB_ERR_INVALID_CID LITERAL1
RADIOLIB_ERR_UPLINK_UNAVAILABLE LITERAL1
RADIOLIB_ERR_COMMAND_QUEUE_FULL LITERAL1
RADIOLIB_ERR_COMMAND_QUEUE_EMPTY LITERAL1
RADIOLIB_ERR_COMMAND_QUEUE_ITEM_NOT_FOUND LITERAL1
RADIOLIB_ERR_JOIN_NONCE_INVALID LITERAL1
RADIOLIB_ERR_N_FCNT_DOWN_INVALID LITERAL1
RADIOLIB_ERR_A_FCNT_DOWN_INVALID LITERAL1
2 changes: 1 addition & 1 deletion src/BuildOpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@

// the amount of space allocated to the persistent storage
#if !defined(RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE)
#define RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE (0x60)
#define RADIOLIB_HAL_PERSISTENT_STORAGE_SIZE (0xD0)
#endif

// This only compiles on STM32 boards with SUBGHZ module, but also
Expand Down
48 changes: 35 additions & 13 deletions src/Hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,47 @@
#include "BuildOpt.h"

// list of persistent parameters
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_NONCE_ID (0)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID (1)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_UP_ID (2)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_MAGIC_ID (3)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_APP_S_KEY_ID (4)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_FNWK_SINT_KEY_ID (5)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_SNWK_SINT_KEY_ID (6)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_NWK_SENC_KEY_ID (7)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_VERSION_ID (0) // this is NOT the LoRaWAN version, but version of this table
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_MAGIC_ID (1)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID (2)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_APP_S_KEY_ID (3)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_FNWK_SINT_KEY_ID (4)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_SNWK_SINT_KEY_ID (5)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_NWK_SENC_KEY_ID (6)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_NONCE_ID (7)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_JOIN_NONCE_ID (8)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_HOME_NET_ID (9)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_DL_SETTINGS_ID (10)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_CF_LIST_ID (11)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_RX_DELAY_ID (12)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_UP_ID (13)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_A_FCNT_DOWN_ID (14)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_N_FCNT_DOWN_ID (15)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_CONF_FCNT_ID (16)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_ADR_ID (17)
#define RADIOLIB_PERSISTENT_PARAM_LORAWAN_FOPTS_ID (18)

static const uint32_t RadioLibPersistentParamTable[] = {
0x00, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_NONCE_ID
0x04, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID
0x08, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_UP_ID
0x0C, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_MAGIC_ID
0x00, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_VERSION
0x08, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_MAGIC_ID
0x0C, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_ADDR_ID
0x10, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_APP_S_KEY_ID
0x20, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FNWK_SINT_KEY_ID
0x30, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_SNWK_SINT_KEY_ID
0x40, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_NWK_SENC_KEY_ID
0x50, // end
0x50, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DEV_NONCE_ID
0x54, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_JOIN_NONCE_ID
0x58, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_HOME_NET_ID
0x5C, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_DL_SETTINGS_ID
0x60, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_CF_LIST
0x70, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_RX_DELAY_ID
0x74, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FCNT_UP_ID
0x78, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_AFCNT_DOWN_ID
0x7C, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_NFCNT_DOWN_ID
0x80, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_CONF_FCNT_ID
0x84, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_ADR_ID
0x88, // RADIOLIB_PERSISTENT_PARAM_LORAWAN_FOPTS_ID
0xD0, // end
};

/*!
Expand Down
20 changes: 20 additions & 0 deletions src/TypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,26 @@
*/
#define RADIOLIB_ERR_COMMAND_QUEUE_EMPTY (-1110)

/*!
\brief Unable to delete MAC command because it was not found in the queue.
*/
#define RADIOLIB_ERR_COMMAND_QUEUE_ITEM_NOT_FOUND (-1111)

/*!
\brief Unable to join network because JoinNonce is not higher than saved value.
*/
#define RADIOLIB_ERR_JOIN_NONCE_INVALID (-1112)

/*!
\brief Received downlink Network frame counter is invalid (lower than last heard value).
*/
#define RADIOLIB_ERR_N_FCNT_DOWN_INVALID (-1113)

/*!
\brief Received downlink Application frame counter is invalid (lower than last heard value).
*/
#define RADIOLIB_ERR_A_FCNT_DOWN_INVALID (-1114)

/*!
\}
*/
Expand Down
Loading