Skip to content

Commit

Permalink
[LoRaWAN] Collection of fixes (also fixes #1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenCellist committed Oct 7, 2024
1 parent dc77e6e commit 9db98f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/protocols/LoRaWAN/LoRaWAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ int16_t LoRaWANNode::sendReceive(uint8_t* dataUp, size_t lenUp, uint8_t fPort, u
eventUp->nbTrans = trans;
}

#if !RADIOLIB_STATIC_ONLY
delete[] uplinkMsg;
#endif

// if a hardware error occurred, return
if(state < RADIOLIB_ERR_NONE) {
#if !RADIOLIB_STATIC_ONLY
delete[] uplinkMsg;
#endif
return(state);
}

Expand Down Expand Up @@ -938,6 +939,9 @@ int16_t LoRaWANNode::activateOTAA(uint8_t joinDr, LoRaWANJoinEvent_t *joinEvent)
this->devNonce += 1;
LoRaWANNode::hton<uint16_t>(&this->bufferNonces[RADIOLIB_LORAWAN_NONCES_DEV_NONCE], this->devNonce);

// set the Time on Air of the JoinRequest
this->lastToA = this->phyLayer->getTimeOnAir(RADIOLIB_LORAWAN_JOIN_REQUEST_LEN) / 1000;

// configure Rx1 and Rx2 delay for JoinAccept message - these are re-configured once a valid JoinAccept is received
this->rxDelays[1] = RADIOLIB_LORAWAN_JOIN_ACCEPT_DELAY_1_MS;
this->rxDelays[2] = RADIOLIB_LORAWAN_JOIN_ACCEPT_DELAY_2_MS;
Expand Down Expand Up @@ -1481,7 +1485,7 @@ int16_t LoRaWANNode::parseDownlink(uint8_t* data, size_t* len, LoRaWANEvent_t* e
// check the address
uint32_t addr = LoRaWANNode::ntoh<uint32_t>(&downlinkMsg[RADIOLIB_LORAWAN_FHDR_DEV_ADDR_POS]);
if(addr != this->devAddr) {
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Device address mismatch, expected 0x%08X, got 0x%08X", this->devAddr, addr);
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("Device address mismatch, expected 0x%08lX, got 0x%08lX", this->devAddr, addr);
#if !RADIOLIB_STATIC_ONLY
delete[] downlinkMsg;
#endif
Expand Down Expand Up @@ -3197,7 +3201,7 @@ bool LoRaWANNode::verifyMIC(uint8_t* msg, size_t len, uint8_t* key) {
// calculate the expected value and compare
uint32_t micCalculated = generateMIC(msg, len - sizeof(uint32_t), key);
if(micCalculated != micReceived) {
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("MIC mismatch, expected %08x, got %08x", micCalculated, micReceived);
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("MIC mismatch, expected %08lx, got %08lx", micCalculated, micReceived);
return(false);
}

Expand Down
2 changes: 1 addition & 1 deletion src/protocols/LoRaWAN/LoRaWAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ class LoRaWANNode {
\param initialDr The datarate at which to send the first uplink and any subsequent uplinks (unless ADR is enabled).
\returns \ref status_codes
*/
int16_t activateABP(uint8_t initialDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED);
virtual int16_t activateABP(uint8_t initialDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED);

/*! \brief Whether there is an ongoing session active */
bool isActivated();
Expand Down

0 comments on commit 9db98f2

Please sign in to comment.