Skip to content

Commit 62b0864

Browse files
committed
Changed improved the way JoinNonce is checked
1 parent 68b4fe9 commit 62b0864

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/mac/LoRaMacCrypto.c

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,24 @@ static void ResetFCnts( void )
806806
}
807807
}
808808

809+
static bool IsJoinNonce10xOk( uint32_t joinNonce )
810+
{
811+
#if( USE_10X_JOIN_NONCE_COUNTER_CHECK == 1 )
812+
// Check if the JoinNonce is greater as the previous one
813+
return ( joinNonce > CryptoNvm->JoinNonce ) ? true : false;
814+
#else
815+
// Check if the JoinNonce is different from the previous one
816+
return( joinNonce != CryptoNvm->JoinNonce ) ? true : false;
817+
#endif
818+
}
819+
820+
#if( USE_LRWAN_1_1_X_CRYPTO == 1 )
821+
static bool IsJoinNonce11xOk( uint32_t joinNonce )
822+
{
823+
return ( joinNonce > CryptoNvm->JoinNonce ) ? true : false;
824+
}
825+
#endif
826+
809827
/*
810828
* API functions
811829
*/
@@ -1136,18 +1154,24 @@ LoRaMacCryptoStatus_t LoRaMacCryptoHandleJoinAccept( JoinReqIdentifier_t joinReq
11361154
}
11371155

11381156
uint32_t currentJoinNonce;
1157+
bool isJoinNonceOk = false;
11391158

11401159
currentJoinNonce = ( uint32_t )macMsg->JoinNonce[0];
11411160
currentJoinNonce |= ( ( uint32_t )macMsg->JoinNonce[1] << 8 );
11421161
currentJoinNonce |= ( ( uint32_t )macMsg->JoinNonce[2] << 16 );
11431162

1144-
#if( USE_JOIN_NONCE_COUNTER_CHECK == 1 )
1145-
// Check if the JoinNonce is greater as the previous one
1146-
if( currentJoinNonce > CryptoNvm->JoinNonce )
1147-
#else
1148-
// Check if the JoinNonce is different from the previous one
1149-
if( currentJoinNonce != CryptoNvm->JoinNonce )
1163+
#if( USE_LRWAN_1_1_X_CRYPTO == 1 )
1164+
if( versionMinor == 1 )
1165+
{
1166+
isJoinNonceOk = IsJoinNonce11xOk( currentJoinNonce );
1167+
}
1168+
else
11501169
#endif
1170+
{
1171+
isJoinNonceOk = IsJoinNonce10xOk( currentJoinNonce );
1172+
}
1173+
1174+
if( isJoinNonceOk == true )
11511175
{
11521176
CryptoNvm->JoinNonce = currentJoinNonce;
11531177
}

src/mac/LoRaMacCrypto.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,21 @@ extern "C"
6161
#define USE_RANDOM_DEV_NONCE 0
6262

6363
/*!
64-
* Indicates if JoinNonce is counter based and requires to be checked
64+
* Indicates if JoinNonce is counter based and requires to be checked on 1.0.x devices
65+
* \remark Only applies to LoRaWAN 1.0.x when following recomendations provided
66+
* by "Technical Recommendations for Preventing State Synchronization
67+
* Issues around LoRaWAN® 1.0.x Join Procedure"
68+
* https://lora-alliance.org/wp-content/uploads/2020/11/lorawan-1.0.x-join-synch-issues-remedies-v1.0.0.pdf
6569
*/
66-
#define USE_JOIN_NONCE_COUNTER_CHECK 1
70+
#define USE_10X_JOIN_NONCE_COUNTER_CHECK 0
6771

6872
/*!
6973
* Initial value of the frame counters
7074
*/
7175
#define FCNT_DOWN_INITAL_VALUE 0xFFFFFFFF
7276

7377
/*!
74-
* LoRaMac Cryto Status
78+
* LoRaMac Crypto Status
7579
*/
7680
typedef enum eLoRaMacCryptoStatus
7781
{

0 commit comments

Comments
 (0)