From a9ef29fa673c4c9a24c757a5baa7346438297d20 Mon Sep 17 00:00:00 2001 From: Olivier Date: Mon, 4 Sep 2017 23:37:11 +0200 Subject: [PATCH] Update hwUniqueID() function (#921) --- hal/architecture/MyHw.h | 6 ++++-- hal/architecture/MyHwAVR.cpp | 16 +++++++++++++--- hal/architecture/MyHwESP8266.cpp | 2 +- hal/architecture/MyHwTeensy3.cpp | 4 ++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/hal/architecture/MyHw.h b/hal/architecture/MyHw.h index 7677500..2afe9ca 100644 --- a/hal/architecture/MyHw.h +++ b/hal/architecture/MyHw.h @@ -1,4 +1,4 @@ -/* +/* * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -26,6 +26,8 @@ #ifndef MyHw_h #define MyHw_h +#define MY_HWID_PADDING_BYTE (0xAAu) + // Implement these as functions or macros /* #define hwInit() MY_SERIALDEVICE.begin(BAUD_RATE) @@ -83,7 +85,7 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo unsigned long ms); /** -* Retrieve unique ID +* Retrieve unique hardware ID * @param uniqueID unique ID * @return True if unique ID successfully retrieved */ diff --git a/hal/architecture/MyHwAVR.cpp b/hal/architecture/MyHwAVR.cpp index f45556a..9b7cbb8 100644 --- a/hal/architecture/MyHwAVR.cpp +++ b/hal/architecture/MyHwAVR.cpp @@ -18,6 +18,7 @@ */ #include "MyHwAVR.h" +#include "avr/boot.h" bool hwInit(void) { @@ -239,9 +240,18 @@ inline void hwRandomNumberInit() bool hwUniqueID(unique_id_t* uniqueID) { - // not implemented yet - (void)uniqueID; - return false; + // padding + (void)memset(uniqueID, MY_HWID_PADDING_BYTE, sizeof(unique_id_t)); + // no unique ID for non-PB AVR, use HW specifics for diversification + *((uint8_t*)uniqueID) = boot_signature_byte_get(0x00); + *((uint8_t*)uniqueID + 1) = boot_signature_byte_get(0x02); + *((uint8_t*)uniqueID + 2) = boot_signature_byte_get(0x04); + *((uint8_t*)uniqueID + 3) = boot_signature_byte_get(0x01); //OSCCAL + // ATMEGA328PB specifics, has unique ID + //for(uint8_t idx = 0; idx < 10; idx++) { + // *((uint8_t*)uniqueID + 4 + idx) = boot_signature_byte_get(0xE + idx); + //} + return false; // false, since no unique ID returned } uint16_t hwCPUVoltage() diff --git a/hal/architecture/MyHwESP8266.cpp b/hal/architecture/MyHwESP8266.cpp index d732716..8a18274 100644 --- a/hal/architecture/MyHwESP8266.cpp +++ b/hal/architecture/MyHwESP8266.cpp @@ -65,7 +65,7 @@ void hwWriteConfig(const int addr, uint8_t value) bool hwUniqueID(unique_id_t *uniqueID) { // padding - memset((uint8_t*)uniqueID, 0x0A, sizeof(unique_id_t)); + (void)memset((uint8_t*)uniqueID, MY_HWID_PADDING_BYTE, sizeof(unique_id_t)); uint32_t val = ESP.getChipId(); (void)memcpy((uint8_t*)uniqueID, &val, 4); val = ESP.getFlashChipId(); diff --git a/hal/architecture/MyHwTeensy3.cpp b/hal/architecture/MyHwTeensy3.cpp index b4f20bd..4bc32a3 100644 --- a/hal/architecture/MyHwTeensy3.cpp +++ b/hal/architecture/MyHwTeensy3.cpp @@ -1,4 +1,4 @@ -/** +/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each @@ -92,7 +92,7 @@ bool hwUniqueID(unique_id_t *uniqueID) { #if defined(__MKL26Z64__) (void)memcpy((uint8_t*)uniqueID, &SIM_UIDMH, 12); - (void)memset((uint8_t*)uniqueID + 12, 0, 4); + (void)memset((uint8_t*)uniqueID + 12, MY_HWID_PADDING_BYTE, 4); #else (void)memcpy((uint8_t*)uniqueID, &SIM_UIDH, 16); #endif