Skip to content

Commit eff1580

Browse files
author
Cruz Monrreal
authored
Merge pull request #10154 from itziardelatorre/itziar
Fix for LoRaWAN downlink sequence counter rollover
2 parents c2e5a8b + 4c1fedd commit eff1580

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

features/lorawan/lorastack/mac/LoRaMac.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,11 @@ 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
}
325328

326329
// sizeof nws_skey must be the same as _params.keys.nwk_skey,
@@ -334,12 +337,6 @@ bool LoRaMac::message_integrity_check(const uint8_t *const payload,
334337
return false;
335338
}
336339

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-
}
342-
343340
return true;
344341
}
345342

0 commit comments

Comments
 (0)