From 0814acb8dcae5f5853fe37069abd3f4c91d1b798 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:20:13 +0100 Subject: [PATCH] Fix Lora ESP32S3 compile warning --- .../tasmota_xdrv_driver/xdrv_73_3_lora_sx126x.ino | 3 ++- .../xdrv_73_4_lorawan_cryptography.ino | 14 ++++++++++++++ .../xdrv_73_8_lorawan_bridge.ino | 3 +-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_73_3_lora_sx126x.ino b/tasmota/tasmota_xdrv_driver/xdrv_73_3_lora_sx126x.ino index b3dfdd9fe..5a2679d7c 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_73_3_lora_sx126x.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_73_3_lora_sx126x.ino @@ -43,7 +43,8 @@ bool LoraSx126xBusy(void) { /*********************************************************************************************/ -void IRAM_ATTR LoraSx126xOnInterrupt(void) { +void IRAM_ATTR LoraSx126xOnInterrupt(void); +void LoraSx126xOnInterrupt(void) { // This is called after EVERY type of enabled interrupt so chk for valid receivedFlag in LoraAvailableSx126x() if (!Lora.sendFlag && !Lora.receivedFlag && !Lora.receive_time) { Lora.receive_time = millis(); diff --git a/tasmota/tasmota_xdrv_driver/xdrv_73_4_lorawan_cryptography.ino b/tasmota/tasmota_xdrv_driver/xdrv_73_4_lorawan_cryptography.ino index 94e6acde9..842b4a4f7 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_73_4_lorawan_cryptography.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_73_4_lorawan_cryptography.ino @@ -26,6 +26,20 @@ uint32_t LoraWanGenerateMIC(uint8_t* msg, size_t len, uint8_t* key) { return(((uint32_t)cmac[0]) | ((uint32_t)cmac[1] << 8) | ((uint32_t)cmac[2] << 16) | ((uint32_t)cmac[3]) << 24); } +/*********************************************************************************************/ + +// EncryptJoinAccept uses AES Decrypt to encrypt a join-accept message +// - The payload contains JoinNonce/AppNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType) | MIC +// - In LoRaWAN 1.0, the AppKey is used +// - In LoRaWAN 1.1, the NwkKey is used in reply to a JoinRequest +// - In LoRaWAN 1.1, the JSEncKey is used in reply to a RejoinRequest (type 0,1,2) +void LoraWanEncryptJoinAccept(uint8_t* key, uint8_t* payload, size_t len, uint8_t* encrypted) { + RadioLibAES128Instance.init(key); + RadioLibAES128Instance.decryptECB(payload, len, encrypted); +} + +/*********************************************************************************************/ + // deriveLegacySKey derives a session key void _LoraWanDeriveLegacySKey(uint8_t* key, uint8_t t, uint32_t jn, uint32_t nid, uint16_t dn, uint8_t* derived) { uint8_t buf[TAS_LORAWAN_AES128_KEY_SIZE] = { 0 }; diff --git a/tasmota/tasmota_xdrv_driver/xdrv_73_8_lorawan_bridge.ino b/tasmota/tasmota_xdrv_driver/xdrv_73_8_lorawan_bridge.ino index cab4d9ad5..467c251e6 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_73_8_lorawan_bridge.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_73_8_lorawan_bridge.ino @@ -297,8 +297,7 @@ bool LoraWanInput(uint8_t* data, uint32_t packet_size) { join_data[16] = NewMIC >> 24; uint8_t EncData[33]; EncData[0] = join_data[0]; - RadioLibAES128Instance.init(LoraSettings.end_node[node].AppKey); - RadioLibAES128Instance.decryptECB(&join_data[1], 16, &EncData[1]); + LoraWanEncryptJoinAccept(LoraSettings.end_node[node].AppKey, &join_data[1], 16, &EncData[1]); // AddLog(LOG_LEVEL_DEBUG, PSTR("DBG: Join %17_H"), join_data);