94
94
*/
95
95
#define ADR_ACK_COUNTER_MAX 0xFFFFFFFF
96
96
97
+ /*!
98
+ * Delay required to simulate an ABP join like an OTAA join
99
+ */
100
+ #define ABP_JOIN_PENDING_DELAY_MS 10
101
+
97
102
#if defined(__ICCARM__ )
98
103
#ifndef __NO_INIT
99
104
#define __NO_INIT __no_init
@@ -119,14 +124,15 @@ static const uint8_t LoRaMacMaxEirpTable[] = { 8, 10, 12, 13, 14, 16, 18, 20, 21
119
124
*/
120
125
enum eLoRaMacState
121
126
{
122
- LORAMAC_IDLE = 0x00000000 ,
123
- LORAMAC_STOPPED = 0x00000001 ,
124
- LORAMAC_TX_RUNNING = 0x00000002 ,
125
- LORAMAC_RX = 0x00000004 ,
126
- LORAMAC_ACK_RETRY = 0x00000010 ,
127
- LORAMAC_TX_DELAYED = 0x00000020 ,
128
- LORAMAC_TX_CONFIG = 0x00000040 ,
129
- LORAMAC_RX_ABORT = 0x00000080 ,
127
+ LORAMAC_IDLE = 0x00000000 ,
128
+ LORAMAC_STOPPED = 0x00000001 ,
129
+ LORAMAC_TX_RUNNING = 0x00000002 ,
130
+ LORAMAC_RX = 0x00000004 ,
131
+ LORAMAC_ACK_RETRY = 0x00000010 ,
132
+ LORAMAC_TX_DELAYED = 0x00000020 ,
133
+ LORAMAC_TX_CONFIG = 0x00000040 ,
134
+ LORAMAC_RX_ABORT = 0x00000080 ,
135
+ LORAMAC_ABP_JOIN_PENDING = 0x00000100 ,
130
136
};
131
137
132
138
/*
@@ -314,6 +320,10 @@ typedef struct sLoRaMacCtx
314
320
* Start time of the response timeout
315
321
*/
316
322
TimerTime_t ResponseTimeoutStartTime ;
323
+ /*
324
+ * Timer required to simulate an ABP join like an OTAA join
325
+ */
326
+ TimerEvent_t AbpJoinPendingTimer ;
317
327
#endif /* LORAMAC_VERSION */
318
328
/*!
319
329
* Buffer containing the MAC layer commands
@@ -1262,7 +1272,26 @@ static void ProcessRadioRxDone( void )
1262
1272
joinType = MLME_REJOIN_2 ;
1263
1273
}
1264
1274
#endif /* LORAMAC_VERSION */
1275
+ #if (defined( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 )))
1276
+ if ( LORAMAC_CRYPTO_SUCCESS == macCryptoStatus )
1277
+ {
1278
+ VerifyParams_t verifyRxDr ;
1265
1279
1280
+ if ( macMsgJoinAccept .DLSettings .Bits .RX2DataRate != 0x0F )
1281
+ {
1282
+ verifyRxDr .DatarateParams .Datarate = macMsgJoinAccept .DLSettings .Bits .RX2DataRate ;
1283
+ verifyRxDr .DatarateParams .DownlinkDwellTime = Nvm .MacGroup2 .MacParams .DownlinkDwellTime ;
1284
+ if ( RegionVerify ( Nvm .MacGroup2 .Region , & verifyRxDr , PHY_RX_DR ) == false )
1285
+ {
1286
+ // MLME handling
1287
+ if ( LoRaMacConfirmQueueIsCmdActive ( MLME_JOIN ) == true )
1288
+ {
1289
+ LoRaMacConfirmQueueSetStatus ( LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL , MLME_JOIN );
1290
+ }
1291
+ break ;
1292
+ }
1293
+ }
1294
+ #else
1266
1295
VerifyParams_t verifyRxDr ;
1267
1296
bool rxDrValid = false;
1268
1297
verifyRxDr .DatarateParams .Datarate = macMsgJoinAccept .DLSettings .Bits .RX2DataRate ;
@@ -1271,6 +1300,8 @@ static void ProcessRadioRxDone( void )
1271
1300
1272
1301
if ( ( LORAMAC_CRYPTO_SUCCESS == macCryptoStatus ) && ( rxDrValid == true ) )
1273
1302
{
1303
+ #endif
1304
+
1274
1305
// Network ID
1275
1306
Nvm .MacGroup2 .NetID = ( uint32_t ) macMsgJoinAccept .NetID [0 ];
1276
1307
Nvm .MacGroup2 .NetID |= ( ( uint32_t ) macMsgJoinAccept .NetID [1 ] << 8 );
@@ -1283,8 +1314,18 @@ static void ProcessRadioRxDone( void )
1283
1314
1284
1315
// DLSettings
1285
1316
Nvm .MacGroup2 .MacParams .Rx1DrOffset = macMsgJoinAccept .DLSettings .Bits .RX1DRoffset ;
1317
+
1318
+ #if (defined( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 )))
1319
+ // Verify if we shall assign the new datarate
1320
+ if ( macMsgJoinAccept .DLSettings .Bits .RX2DataRate != 0x0F )
1321
+ {
1322
+ #endif
1323
+
1286
1324
Nvm .MacGroup2 .MacParams .Rx2Channel .Datarate = macMsgJoinAccept .DLSettings .Bits .RX2DataRate ;
1287
1325
Nvm .MacGroup2 .MacParams .RxCChannel .Datarate = macMsgJoinAccept .DLSettings .Bits .RX2DataRate ;
1326
+ #if (defined( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 )))
1327
+ }
1328
+ #endif
1288
1329
1289
1330
// RxDelay
1290
1331
Nvm .MacGroup2 .MacParams .ReceiveDelay1 = macMsgJoinAccept .RxDelay ;
@@ -1612,9 +1653,13 @@ static void ProcessRadioRxDone( void )
1612
1653
}
1613
1654
1614
1655
// Set the pending status
1615
- /* if( ( ( ( Nvm.MacGroup1.SrvAckRequested == true ) || ( macMsgData.FHDR.FCtrl.Bits.FPending > 0 ) ) && ( Nvm.MacGroup2.DeviceClass == CLASS_A ) ) ||
1616
- ( MacCtx.McpsIndication.ResponseTimeout > 0 ) ) */
1617
- if ( ( ( Nvm .MacGroup1 .SrvAckRequested == true ) || ( macMsgData .FHDR .FCtrl .Bits .FPending > 0 ) ) && ( Nvm .MacGroup2 .DeviceClass == CLASS_A ) )
1656
+ // Fix for Class C Certification test. Re-enabled part of if condition previously removed.
1657
+ if ( ( ( ( Nvm .MacGroup1 .SrvAckRequested == true ) || ( macMsgData .FHDR .FCtrl .Bits .FPending > 0 ) ) && ( Nvm .MacGroup2 .DeviceClass == CLASS_A ) )
1658
+ #if (defined ( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 )))
1659
+ || ( MacCtx .McpsIndication .ResponseTimeout > 0 )
1660
+ #endif /* LORAMAC_VERSION */
1661
+ )
1662
+ //if( ( ( Nvm.MacGroup1.SrvAckRequested == true ) || ( macMsgData.FHDR.FCtrl.Bits.FPending > 0 ) ) && ( Nvm.MacGroup2.DeviceClass == CLASS_A ) )
1618
1663
{
1619
1664
MacCtx .McpsIndication .IsUplinkTxPending = 1 ;
1620
1665
}
@@ -2877,6 +2922,14 @@ static void ProcessMacCommands( uint8_t *payload, uint8_t macIndex, uint8_t comm
2877
2922
rxParamSetupReq .Datarate = payload [macIndex ] & 0x0F ;
2878
2923
macIndex ++ ;
2879
2924
2925
+ #if (defined( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 )))
2926
+ if ( rxParamSetupReq .Datarate == 0x0F )
2927
+ {
2928
+ // Keep the current datarate
2929
+ rxParamSetupReq .Datarate = Nvm .MacGroup2 .MacParams .Rx2Channel .Datarate ;
2930
+ }
2931
+ #endif
2932
+
2880
2933
rxParamSetupReq .Frequency = ( uint32_t ) payload [macIndex ++ ];
2881
2934
rxParamSetupReq .Frequency |= ( uint32_t ) payload [macIndex ++ ] << 8 ;
2882
2935
rxParamSetupReq .Frequency |= ( uint32_t ) payload [macIndex ++ ] << 16 ;
@@ -5734,7 +5787,18 @@ LoRaMacStatus_t LoRaMacMibSetRequestConfirm( MibRequestConfirm_t* mibSet )
5734
5787
}
5735
5788
case MIB_SYSTEM_MAX_RX_ERROR :
5736
5789
{
5790
+ #if (defined( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 )))
5791
+ if ( mibSet -> Param .SystemMaxRxError <= 500 )
5792
+ { // Only apply the new value if in range 0..500 ms else keep current value.
5793
+ Nvm .MacGroup2 .MacParams .SystemMaxRxError = Nvm .MacGroup2 .MacParamsDefaults .SystemMaxRxError = mibSet -> Param .SystemMaxRxError ;
5794
+ }
5795
+ else
5796
+ {
5797
+ status = LORAMAC_STATUS_PARAMETER_INVALID ;
5798
+ }
5799
+ #else
5737
5800
Nvm .MacGroup2 .MacParams .SystemMaxRxError = Nvm .MacGroup2 .MacParamsDefaults .SystemMaxRxError = mibSet -> Param .SystemMaxRxError ;
5801
+ #endif
5738
5802
break ;
5739
5803
}
5740
5804
case MIB_MIN_RX_SYMBOLS :
@@ -6082,6 +6146,38 @@ LoRaMacStatus_t LoRaMacMcChannelSetupRxParams( AddressIdentifier_t groupID, McRx
6082
6146
return LORAMAC_STATUS_OK ;
6083
6147
}
6084
6148
6149
+ #if (defined( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 )))
6150
+ /*!
6151
+ * \brief Function executed on AbpJoinPendingTimer timer event
6152
+ */
6153
+ static void OnAbpJoinPendingTimerEvent ( void * context )
6154
+ {
6155
+ MacCtx .MacState &= ~LORAMAC_ABP_JOIN_PENDING ;
6156
+ MacCtx .MacFlags .Bits .MacDone = 1 ;
6157
+ OnMacProcessNotify ( );
6158
+ }
6159
+
6160
+ /*!
6161
+ * \brief Start ABP join simulation
6162
+ */
6163
+ static void AbpJoinPendingStart ( void )
6164
+ {
6165
+ static bool initialized = false;
6166
+
6167
+ if ( initialized == false )
6168
+ {
6169
+ initialized = true;
6170
+ TimerInit ( & MacCtx .AbpJoinPendingTimer , OnAbpJoinPendingTimerEvent );
6171
+ }
6172
+
6173
+ MacCtx .MacState |= LORAMAC_ABP_JOIN_PENDING ;
6174
+
6175
+ TimerStop ( & MacCtx .AbpJoinPendingTimer );
6176
+ TimerSetValue ( & MacCtx .AbpJoinPendingTimer , ABP_JOIN_PENDING_DELAY_MS );
6177
+ TimerStart ( & MacCtx .AbpJoinPendingTimer );
6178
+ }
6179
+ #endif /* LORAMAC_VERSION */
6180
+
6085
6181
LoRaMacStatus_t LoRaMacProcessMicForDatablock ( uint8_t * buffer , uint32_t size , uint16_t sessionCnt , uint8_t fragIndex , uint32_t descriptor , uint32_t * mic )
6086
6182
{
6087
6183
LoRaMacCryptoStatus_t macCryptoStatus = LORAMAC_CRYPTO_ERROR ;
@@ -6099,6 +6195,9 @@ LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t* mlmeRequest )
6099
6195
{
6100
6196
LoRaMacStatus_t status = LORAMAC_STATUS_SERVICE_UNKNOWN ;
6101
6197
MlmeConfirmQueue_t queueElement ;
6198
+ #if (defined( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 )))
6199
+ bool isAbpJoinPending = false;
6200
+ #endif /* LORAMAC_VERSION */
6102
6201
uint8_t macCmdPayload [2 ] = { 0x00 , 0x00 };
6103
6202
6104
6203
if ( mlmeRequest == NULL )
@@ -6191,6 +6290,9 @@ LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t* mlmeRequest )
6191
6290
queueElement .ReadyToHandle = true;
6192
6291
OnMacProcessNotify ( );
6193
6292
MacCtx .MacFlags .Bits .MacDone = 1 ;
6293
+ #if (defined( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 )))
6294
+ isAbpJoinPending = true;
6295
+ #endif
6194
6296
status = LORAMAC_STATUS_OK ;
6195
6297
}
6196
6298
#endif /* LORAMAC_VERSION */
@@ -6335,6 +6437,12 @@ LoRaMacStatus_t LoRaMacMlmeRequest( MlmeReq_t* mlmeRequest )
6335
6437
else
6336
6438
{
6337
6439
LoRaMacConfirmQueueAdd ( & queueElement );
6440
+ #if (defined( LORAMAC_VERSION ) && (( LORAMAC_VERSION == 0x01000400 ) || ( LORAMAC_VERSION == 0x01010100 )))
6441
+ if ( isAbpJoinPending == true )
6442
+ {
6443
+ AbpJoinPendingStart ( );
6444
+ }
6445
+ #endif /* LORAMAC_VERSION */
6338
6446
}
6339
6447
return status ;
6340
6448
}
@@ -6681,4 +6789,22 @@ LoRaMacStatus_t LoRaMacDeInitialization( void )
6681
6789
}
6682
6790
}
6683
6791
6792
+ void LoRaMacReset ( void )
6793
+ {
6794
+ // Reset state machine
6795
+ MacCtx .MacState &= ~LORAMAC_TX_RUNNING ;
6796
+ MacCtx .MacFlags .Bits .MacDone = 1 ;
6797
+
6798
+ // Stop Timers
6799
+ TimerStop ( & MacCtx .TxDelayedTimer );
6800
+ TimerStop ( & MacCtx .RxWindowTimer1 );
6801
+ TimerStop ( & MacCtx .RxWindowTimer2 );
6802
+
6803
+ // Stop retransmissions
6804
+ MacCtx .ChannelsNbTransCounter = Nvm .MacGroup2 .MacParams .ChannelsNbTrans ;
6805
+
6806
+ // Inform application layer
6807
+ OnMacProcessNotify ( );
6808
+ }
6809
+
6684
6810
#pragma GCC diagnostic pop
0 commit comments