Skip to content

Commit c86ec8d

Browse files
Fix issue related to downlink sequence counter rollover in LoRaWAN.
For the test, the downlink sequence counter of the downlink messages has been incremented by 1600 (< MAX_FCNT_GAP) several times. For example, until 64005 and following situation was shown: Downlink sequence counter increased to 64005 (by 1600 steps) The radio module accepts this, as expected. After that, downlink sequence counter increased to 65536 (rollover for 32 bits sequence counter) The radio module rejects this frame With the change everything works fine.
1 parent 964f5ad commit c86ec8d

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,13 @@ bool LoRaMac::message_integrity_check(const uint8_t *const payload,
319319
sequence_counter_prev = (uint16_t) * downlink_counter;
320320
sequence_counter_diff = sequence_counter - sequence_counter_prev;
321321
*downlink_counter += sequence_counter_diff;
322-
if (sequence_counter < sequence_counter_prev) {
323-
*downlink_counter += 0x10000;
322+
323+
if (sequence_counter_diff >= _lora_phy->get_maximum_frame_counter_gap()) {
324+
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOST;
325+
_mcps_indication.dl_frame_counter = *downlink_counter;
326+
return false;
324327
}
325-
328+
326329
// sizeof nws_skey must be the same as _params.keys.nwk_skey,
327330
_lora_crypto.compute_mic(payload, size - LORAMAC_MFR_LEN,
328331
nwk_skey,
@@ -332,13 +335,7 @@ bool LoRaMac::message_integrity_check(const uint8_t *const payload,
332335
if (mic_rx != mic) {
333336
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_MIC_FAIL;
334337
return false;
335-
}
336-
337-
if (sequence_counter_diff >= _lora_phy->get_maximum_frame_counter_gap()) {
338-
_mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOST;
339-
_mcps_indication.dl_frame_counter = *downlink_counter;
340-
return false;
341-
}
338+
}
342339

343340
return true;
344341
}

0 commit comments

Comments
 (0)