From 943d4ef24d3de75d6ba45507c6593c23ec7b01c4 Mon Sep 17 00:00:00 2001 From: Bernd Giesecke Date: Thu, 17 Oct 2024 12:09:05 +0800 Subject: [PATCH] Add functions to get network session key and app session key after join --- CHANGELOG.md | 3 +++ README.md | 2 ++ library.json | 2 +- library.properties | 2 +- src/boards/mcu/rak11300/SimpleTimer.h | 4 ++-- src/mac/LoRaMac.cpp | 6 +++--- src/mac/LoRaMac.h | 4 ++++ src/mac/LoRaMacHelper.cpp | 16 ++++++++++++++++ src/mac/LoRaMacHelper.h | 3 +++ 9 files changed, 35 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3382d0..6d21cb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Arduino library for LoRa communication with Semtech SX126x chips. It is based on # Release Notes +# V2.0.27 Access to NWsKey and AppsKey + - Add functions to get network session key and app session key after join + # V2.0.26 Add missing header file - Fix compilation error diff --git a/README.md b/README.md index 1515443..359e2ee 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---- ## Changelog [Code releases](CHANGELOG.md) +- 2024-10-17 Access to NWsKey and AppsKey + - Add functions to get network session key and app session key after join - 2024-07-02 Add missing header file - Fix compilation error - 2024-06-26 diff --git a/library.json b/library.json index e946f0d..65dd6da 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "SX126x-Arduino", - "version": "2.0.26", + "version": "2.0.27", "keywords": [ "lora", "Semtech", diff --git a/library.properties b/library.properties index da44098..0f4e173 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SX126x-Arduino -version=2.0.26 +version=2.0.27 author=Bernd Giesecke maintainer=Bernd Giesecke sentence=Arduino library to use Semtech SX126x LoRa chips and modules to communicate diff --git a/src/boards/mcu/rak11300/SimpleTimer.h b/src/boards/mcu/rak11300/SimpleTimer.h index 65cb6bc..e5def9a 100644 --- a/src/boards/mcu/rak11300/SimpleTimer.h +++ b/src/boards/mcu/rak11300/SimpleTimer.h @@ -111,7 +111,7 @@ class SimpleTimer volatile timer_callback callbacks[MAX_TIMERS]; // delay values - volatile unsigned long delays[MAX_TIMERS]; + volatile long delays[MAX_TIMERS]; // number of runs to be executed for each timer volatile int maxNumRuns[MAX_TIMERS]; @@ -129,4 +129,4 @@ class SimpleTimer int numTimers; }; -#endif +#endif \ No newline at end of file diff --git a/src/mac/LoRaMac.cpp b/src/mac/LoRaMac.cpp index a2f1872..c023edc 100644 --- a/src/mac/LoRaMac.cpp +++ b/src/mac/LoRaMac.cpp @@ -84,7 +84,7 @@ static uint8_t *LoRaMacAppKey; /*! * AES encryption/decryption cipher network session key */ -static uint8_t LoRaMacNwkSKey[] = +uint8_t LoRaMacNwkSKey[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -92,7 +92,7 @@ static uint8_t LoRaMacNwkSKey[] = /*! * AES encryption/decryption cipher application session key */ -static uint8_t LoRaMacAppSKey[] = +uint8_t LoRaMacAppSKey[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -111,7 +111,7 @@ static uint32_t LoRaMacNetID; /*! * Mote Address */ -static uint32_t LoRaMacDevAddr; +uint32_t LoRaMacDevAddr; /*! * Multicast channels linked list diff --git a/src/mac/LoRaMac.h b/src/mac/LoRaMac.h index 4d2db03..7fb8c7a 100644 --- a/src/mac/LoRaMac.h +++ b/src/mac/LoRaMac.h @@ -1960,4 +1960,8 @@ LoRaMacStatus_t LoRaMacMcpsRequest(McpsReq_t *mcpsRequest); void ResetMacCounters(void); +extern uint8_t LoRaMacNwkSKey[]; +extern uint8_t LoRaMacAppSKey[]; +extern uint32_t LoRaMacDevAddr; + #endif // __LORAMAC_H__ diff --git a/src/mac/LoRaMacHelper.cpp b/src/mac/LoRaMacHelper.cpp index 8466b95..39969d9 100644 --- a/src/mac/LoRaMacHelper.cpp +++ b/src/mac/LoRaMacHelper.cpp @@ -1153,6 +1153,22 @@ uint32_t lmh_getDevAddr(void) return LoRaMacGetOTAADevId(); } +void lmh_getNwSkey(uint8_t * key) +{ + for (int idx=0; idx<16; idx++) + { + key[idx] = LoRaMacNwkSKey[idx]; + } +} + +void lmh_getAppSkey(uint8_t *key) +{ + for (int idx = 0; idx < 16; idx++) + { + key[idx] = LoRaMacAppSKey[idx]; + } +} + /** * @brief Set the AS923 frequency variant * diff --git a/src/mac/LoRaMacHelper.h b/src/mac/LoRaMacHelper.h index 20b51d6..377194d 100644 --- a/src/mac/LoRaMacHelper.h +++ b/src/mac/LoRaMacHelper.h @@ -314,4 +314,7 @@ uint8_t lmh_getConfRetries(void); */ void lmh_reset_mac(void); +void lmh_getNwSkey(uint8_t *key); +void lmh_getAppSkey(uint8_t *key); + #endif