@@ -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 }
0 commit comments