[LoRaWAN] Fixed MIC calculation for downlink packets

This commit is contained in:
jgromes 2023-08-14 21:38:31 +02:00
parent 1ed22717d7
commit 0a72d98750

View file

@ -625,6 +625,12 @@ int16_t LoRaWANNode::downlink(uint8_t* data, size_t* len) {
state = RADIOLIB_ERR_NONE; state = RADIOLIB_ERR_NONE;
} }
// get the frame counter and set it to the MIC calculation block
// TODO this will not handle overflow into 32-bits!
// TODO cache the ADR bit?
uint16_t fcnt = LoRaWANNode::ntoh<uint16_t>(&downlinkMsg[RADIOLIB_LORAWAN_FHDR_FCNT_POS]);
LoRaWANNode::hton<uint16_t>(&downlinkMsg[RADIOLIB_LORAWAN_BLOCK_FCNT_POS], fcnt);
//Module::hexdump(downlinkMsg, RADIOLIB_AES128_BLOCK_SIZE + downlinkMsgLen); //Module::hexdump(downlinkMsg, RADIOLIB_AES128_BLOCK_SIZE + downlinkMsgLen);
if(state != RADIOLIB_ERR_NONE) { if(state != RADIOLIB_ERR_NONE) {
@ -646,10 +652,6 @@ int16_t LoRaWANNode::downlink(uint8_t* data, size_t* len) {
return(RADIOLIB_ERR_DOWNLINK_MALFORMED); return(RADIOLIB_ERR_DOWNLINK_MALFORMED);
} }
// TODO cache the ADR bit?
// TODO cache and check fcnt?
uint16_t fcnt = LoRaWANNode::ntoh<uint16_t>(&downlinkMsg[RADIOLIB_LORAWAN_FHDR_FCNT_POS]);
// check fopts len // check fopts len
uint8_t foptsLen = downlinkMsg[RADIOLIB_LORAWAN_FHDR_FCTRL_POS] & RADIOLIB_LORAWAN_FHDR_FOPTS_LEN_MASK; uint8_t foptsLen = downlinkMsg[RADIOLIB_LORAWAN_FHDR_FCTRL_POS] & RADIOLIB_LORAWAN_FHDR_FOPTS_LEN_MASK;
if(foptsLen > 0) { if(foptsLen > 0) {