diff --git a/features/lorawan/lorastack/mac/LoRaMac.cpp b/features/lorawan/lorastack/mac/LoRaMac.cpp index a971fb9cd4..032094d9df 100644 --- a/features/lorawan/lorastack/mac/LoRaMac.cpp +++ b/features/lorawan/lorastack/mac/LoRaMac.cpp @@ -319,10 +319,13 @@ bool LoRaMac::message_integrity_check(const uint8_t *const payload, sequence_counter_prev = (uint16_t) * downlink_counter; sequence_counter_diff = sequence_counter - sequence_counter_prev; *downlink_counter += sequence_counter_diff; - if (sequence_counter < sequence_counter_prev) { - *downlink_counter += 0x10000; + + if (sequence_counter_diff >= _lora_phy->get_maximum_frame_counter_gap()) { + _mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOST; + _mcps_indication.dl_frame_counter = *downlink_counter; + return false; } - + // sizeof nws_skey must be the same as _params.keys.nwk_skey, _lora_crypto.compute_mic(payload, size - LORAMAC_MFR_LEN, nwk_skey, @@ -332,13 +335,7 @@ bool LoRaMac::message_integrity_check(const uint8_t *const payload, if (mic_rx != mic) { _mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_MIC_FAIL; return false; - } - - if (sequence_counter_diff >= _lora_phy->get_maximum_frame_counter_gap()) { - _mcps_indication.status = LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOST; - _mcps_indication.dl_frame_counter = *downlink_counter; - return false; - } + } return true; }