From ca5f71f774ab92da3c8ab31515ef7adbb9864642 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 23 Oct 2024 21:18:37 -0500 Subject: [PATCH 1/4] Add device unique id (#5092) * Add device unique id * Trunk * WIP * Esp32 implementation * Trunk * Check for ESP_EFUSE_OPTIONAL_UNIQUE_ID * Comment print * Trunk --- src/mesh/NodeDB.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 78ccdd85a..87a7ad091 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -34,7 +34,11 @@ #endif #include "modules/StoreForwardModule.h" #include +#include +#include #include +#include +#include #endif #ifdef ARCH_PORTDUINO @@ -109,6 +113,43 @@ NodeDB::NodeDB() uint32_t channelFileCRC = crc32Buffer(&channelFile, sizeof(channelFile)); int saveWhat = 0; + bool hasUniqueId = false; + // Get device unique id +#if defined(ARCH_ESP32) && defined(ESP_EFUSE_OPTIONAL_UNIQUE_ID) + uint32_t unique_id[4]; + // ESP32 factory burns a unique id in efuse for S2+ series and evidently C3+ series + // This is used for HMACs in the esp-rainmaker AIOT platform and seems to be a good choice for us + esp_err_t err = esp_efuse_read_field_blob(ESP_EFUSE_OPTIONAL_UNIQUE_ID, unique_id, sizeof(unique_id) * 8); + if (err == ESP_OK) { + memcpy(myNodeInfo.device_id.bytes, unique_id, sizeof(unique_id)); + myNodeInfo.device_id.size = 16; + hasUniqueId = true; + } else { + LOG_WARN("Failed to read unique id from efuse"); + } +#elif defined(ARCH_NRF52) + // Nordic applies a FIPS compliant Random ID to each chip at the factory + // We concatenate the device address to the Random ID to create a unique ID for now + // This will likely utilize a crypto module in the future + uint64_t device_id_start = ((uint64_t)NRF_FICR->DEVICEID[1] << 32) | NRF_FICR->DEVICEID[0]; + uint64_t device_id_end = ((uint64_t)NRF_FICR->DEVICEADDR[1] << 32) | NRF_FICR->DEVICEADDR[0]; + memcpy(myNodeInfo.device_id.bytes, &device_id_start, sizeof(device_id_start)); + memcpy(myNodeInfo.device_id.bytes + sizeof(device_id_start), &device_id_end, sizeof(device_id_end)); + myNodeInfo.device_id.size = 16; + hasUniqueId = true; +#else + // FIXME - implement for other platforms +#endif + // Uncomment below to print the device id + // if (hasUniqueId) { + // std::string deviceIdHex; + // for (size_t i = 0; i < myNodeInfo.device_id.size; ++i) { + // char buf[3]; + // snprintf(buf, sizeof(buf), "%02X", myNodeInfo.device_id.bytes[i]); + // deviceIdHex += buf; + // } + // LOG_DEBUG("Device ID (HEX): %s", deviceIdHex.c_str()); + // } // likewise - we always want the app requirements to come from the running appload myNodeInfo.min_app_version = 30200; // format is Mmmss (where M is 1+the numeric major number. i.e. 30200 means 2.2.00 From 6485f037ec6126a1a92880abfe44272587b68bdc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 23 Oct 2024 21:21:49 -0500 Subject: [PATCH 2/4] [create-pull-request] automated change (#5133) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> --- protobufs | 2 +- src/mesh/generated/meshtastic/rtttl.pb.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/protobufs b/protobufs index 8686d049c..7960241cc 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 8686d049c22c232f57121e66dfb29e7be65010f0 +Subproject commit 7960241ccdd6b262a11b79523857037f755ab847 diff --git a/src/mesh/generated/meshtastic/rtttl.pb.h b/src/mesh/generated/meshtastic/rtttl.pb.h index 2b7e35f11..0572265f7 100644 --- a/src/mesh/generated/meshtastic/rtttl.pb.h +++ b/src/mesh/generated/meshtastic/rtttl.pb.h @@ -13,7 +13,7 @@ /* Canned message module configuration. */ typedef struct _meshtastic_RTTTLConfig { /* Ringtone for PWM Buzzer in RTTTL Format. */ - char ringtone[230]; + char ringtone[231]; } meshtastic_RTTTLConfig; @@ -41,7 +41,7 @@ extern const pb_msgdesc_t meshtastic_RTTTLConfig_msg; /* Maximum encoded size of messages (where known) */ #define MESHTASTIC_MESHTASTIC_RTTTL_PB_H_MAX_SIZE meshtastic_RTTTLConfig_size -#define meshtastic_RTTTLConfig_size 232 +#define meshtastic_RTTTLConfig_size 233 #ifdef __cplusplus } /* extern "C" */ From 701293c2d3e69b57baccacb001b412a9527183a2 Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Thu, 24 Oct 2024 21:58:24 +0200 Subject: [PATCH 3/4] fix missing includes (#5138) --- src/detect/ScanI2CTwoWire.cpp | 3 ++- src/motion/LIS3DHSensor.cpp | 1 + src/motion/LSM6DS3Sensor.cpp | 1 + src/motion/MotionSensor.h | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 71e475904..6cb6ba09a 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -7,7 +7,8 @@ #include "linux/LinuxHardwareI2C.h" #endif #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) -#include "main.h" // atecc +#include "main.h" // atecc +#include "meshUtils.h" // vformat #endif // AXP192 and AXP2101 have the same device address, we just need to identify it in Power.cpp diff --git a/src/motion/LIS3DHSensor.cpp b/src/motion/LIS3DHSensor.cpp index 0d608670c..d06b46b50 100755 --- a/src/motion/LIS3DHSensor.cpp +++ b/src/motion/LIS3DHSensor.cpp @@ -1,4 +1,5 @@ #include "LIS3DHSensor.h" +#include "NodeDB.h" #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C diff --git a/src/motion/LSM6DS3Sensor.cpp b/src/motion/LSM6DS3Sensor.cpp index b3b1a13ec..3b25c3872 100755 --- a/src/motion/LSM6DS3Sensor.cpp +++ b/src/motion/LSM6DS3Sensor.cpp @@ -1,4 +1,5 @@ #include "LSM6DS3Sensor.h" +#include "NodeDB.h" #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C diff --git a/src/motion/MotionSensor.h b/src/motion/MotionSensor.h index 4da23cc70..78eec54ce 100755 --- a/src/motion/MotionSensor.h +++ b/src/motion/MotionSensor.h @@ -14,6 +14,7 @@ #include "../graphics/Screen.h" #include "../graphics/ScreenFonts.h" #include "../power.h" +#include "Wire.h" // Base class for motion processing class MotionSensor From 0c0da3909ff5b124542daf1614d036fad9b68cc2 Mon Sep 17 00:00:00 2001 From: Mark Trevor Birss Date: Fri, 25 Oct 2024 00:07:01 +0200 Subject: [PATCH 4/4] Update variant.h (#5140) --- variants/betafpv_2400_tx_micro/variant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/betafpv_2400_tx_micro/variant.h b/variants/betafpv_2400_tx_micro/variant.h index fd06183ee..67699e7c8 100644 --- a/variants/betafpv_2400_tx_micro/variant.h +++ b/variants/betafpv_2400_tx_micro/variant.h @@ -34,4 +34,4 @@ #define SX128X_TXEN 26 #define SX128X_RXEN 27 #define SX128X_RESET LORA_RESET -#define SX128X_MAX_POWER 13 \ No newline at end of file +#define SX128X_MAX_POWER 3