From a3782b432c10598d8850277bf5c8c7d1e90f42e5 Mon Sep 17 00:00:00 2001 From: StevenCellist Date: Sat, 4 Jan 2025 16:20:42 +0100 Subject: [PATCH] [LoRaWAN] Accept MAC channel mask if ADR is disabled --- src/protocols/LoRaWAN/LoRaWAN.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/protocols/LoRaWAN/LoRaWAN.cpp b/src/protocols/LoRaWAN/LoRaWAN.cpp index 53fd2a57..0705d6ad 100644 --- a/src/protocols/LoRaWAN/LoRaWAN.cpp +++ b/src/protocols/LoRaWAN/LoRaWAN.cpp @@ -1930,7 +1930,6 @@ bool LoRaWANNode::execMacCommand(uint8_t cid, uint8_t* optIn, uint8_t lenIn, uin // only acknowledge if the radio is able to operate at or below the requested power level if(state == RADIOLIB_ERR_NONE || (state == RADIOLIB_ERR_INVALID_OUTPUT_POWER && powerActual < power)) { pwrAck = 1; - this->txPowerSteps = macTxSteps; } else { RADIOLIB_DEBUG_PROTOCOL_PRINTLN("ADR failed to configure Tx power %d, code %d!", power, state); } @@ -1942,10 +1941,17 @@ bool LoRaWANNode::execMacCommand(uint8_t cid, uint8_t* optIn, uint8_t lenIn, uin // if ACK not completely successful, revert and stop if(optOut[0] != 0x07) { - this->applyChannelMask(chMaskGrp0123, chMaskGrp45); - this->setAvailableChannels(chMaskActive); + // according to paragraph 4.3.1.1, if ADR is disabled, + // the ADR channel mask must be accepted even if drAck/pwrAck fails. + // therefore, only revert the channel mask if ADR is enabled. + if(this->adrEnabled) { + this->applyChannelMask(chMaskGrp0123, chMaskGrp45); + this->setAvailableChannels(chMaskActive); + } + // revert datarate this->channels[RADIOLIB_LORAWAN_UPLINK].dr = currentDr; - // Tx power was not modified + // Tx power was not actually modified + return(true); }