diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 5de7a2c..8acb193 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -21,10 +21,16 @@ jobs: UNIVERSAL_LIBRARIES: | - source-path: ./ - name: Arduino_DebugUtils + - name: Arduino_SecureElement + - name: ArduinoECCX08 + - name: WiFiNINA # sketch paths to compile (recursive) for all boards UNIVERSAL_SKETCH_PATHS: | - examples/lzssDecoder - examples/crc32 + - examples/crc16 + - examples/sha256 + - examples/boardID SKETCHES_REPORTS_PATH: sketches-reports strategy: diff --git a/src/bpid/bpid.cpp b/src/bpid/bpid.cpp index 74c5705..60fb003 100644 --- a/src/bpid/bpid.cpp +++ b/src/bpid/bpid.cpp @@ -22,11 +22,11 @@ namespace arduino { namespace bpid { if (!arduino::ucid::get(&in[offset], size)) { return false; } - offset += arduino::ucid::UC_UID_SIZE; + offset += UC_UID_SIZE; if (!arduino::mac::get(&in[offset], size - offset)) { return false; } - offset += arduino::mac::IFACE_MAC_SIZE; + offset += IFACE_MAC_ADDR_LENGTH; if (!arduino::csn::get(&in[offset], size - offset)) { return false; } @@ -41,6 +41,7 @@ namespace arduino { namespace bpid { uint8_t out[SHA256::HASH_SIZE]; arduino::sha256::oneshot(data, sizeof(data), out); return arduino::hex::encode(out, sizeof(out)); + return String(""); } }} // arduino::bpid diff --git a/src/bpid/bpid.h b/src/bpid/bpid.h index 2f6c085..780bf8a 100644 --- a/src/bpid/bpid.h +++ b/src/bpid/bpid.h @@ -20,9 +20,9 @@ namespace arduino { namespace bpid { * This library contains the methods to get board provisioning id */ - constexpr int BOARD_PROVISIONING_ID_SIZE = arduino::ucid::UC_UID_SIZE + - arduino::mac::IFACE_MAC_SIZE + - arduino::csn::CRYPTO_SN_SIZE; + constexpr int BOARD_PROVISIONING_ID_SIZE = UC_UID_SIZE + + IFACE_MAC_ADDR_LENGTH + + CRYPTO_SN_SIZE; bool get(uint8_t* in, uint32_t size); String get(); diff --git a/src/bpid/csn.cpp b/src/bpid/csn.cpp index ea967e2..f0e312a 100644 --- a/src/bpid/csn.cpp +++ b/src/bpid/csn.cpp @@ -13,8 +13,10 @@ namespace arduino { namespace csn { bool get(uint8_t *in, uint32_t size) { -#if defined ARDUINO_UNOR4_WIFI - return false; +#if CRYPTO_SN_SIZE == 0 + (void)in; + (void)size; + return false; #else if (size < CRYPTO_SN_SIZE) { return false; diff --git a/src/bpid/csn.h b/src/bpid/csn.h index 87d61a0..47ef85d 100644 --- a/src/bpid/csn.h +++ b/src/bpid/csn.h @@ -11,29 +11,36 @@ #pragma once #include -#include - -namespace arduino { namespace csn { - /* - * This library contains the methods to get board microcontroller id - */ #if defined(ARDUINO_NANO_RP2040_CONNECT) || \ - defined(ARDUINO_SAMD_MKRWIFI1010) || \ defined(ARDUINO_SAMD_NANO_33_IOT) || \ + defined(ARDUINO_SAMD_MKRWIFI1010) || \ + defined(ARDUINO_SAMD_MKRGSM1400) || \ + defined(ARDUINO_SAMD_MKRWAN1300) || \ + defined(ARDUINO_SAMD_MKRWAN1310) || \ + defined(ARDUINO_SAMD_MKRNB1500) || \ + defined(ARDUINO_SAMD_MKR1000) || \ defined(ARDUINO_PORTENTA_H7_M7) || \ defined(ARDUINO_OPTA) || \ defined(ARDUINO_GIGA) - constexpr int CRYPTO_SN_SIZE = 9; + #include + #define CRYPTO_SN_SIZE 0 #elif defined(ARDUINO_PORTENTA_C33) || \ defined(ARDUINO_NICLA_VISION) - constexpr int CRYPTO_SN_SIZE = SE05X_SN_LENGTH; + #include + #define CRYPTO_SN_SIZE 0 #elif defined(ARDUINO_UNOR4_WIFI) - constexpr int CRYPTO_SN_SIZE = 6; + #include + #define CRYPTO_SN_SIZE 0 #else - #error "Unknown board" + #define CRYPTO_SN_SIZE 0 #endif +namespace arduino { namespace csn { + /* + * This library contains the methods to get board microcontroller id + */ + bool get(uint8_t *in, uint32_t size); }} // arduino::csn diff --git a/src/bpid/mac.cpp b/src/bpid/mac.cpp index 348326c..8938534 100644 --- a/src/bpid/mac.cpp +++ b/src/bpid/mac.cpp @@ -13,25 +13,31 @@ namespace arduino { namespace mac { bool get(uint8_t *in, uint32_t size) { - if (size < IFACE_MAC_SIZE) { +#if IFACE_MAC_ADDR_LENGTH == 0 + (void)in; + (void)size; + return false; +#else + if (size < IFACE_MAC_ADDR_LENGTH) { return false; } -#if defined(ARDUINO_SAMD_MKRWIFI1010) || \ - defined(ARDUINO_SAMD_NANO_33_IOT) + #if defined(ARDUINO_SAMD_MKRWIFI1010) || \ + defined(ARDUINO_SAMD_NANO_33_IOT) WiFi.macAddress(in); -#elif defined(ARDUINO_PORTENTA_H7_M7) || \ - defined(ARDUINO_NICLA_VISION) || \ - defined(ARDUINO_GIGA) + #elif defined(ARDUINO_PORTENTA_H7_M7) || \ + defined(ARDUINO_NICLA_VISION) || \ + defined(ARDUINO_GIGA) WiFi.macAddress(in); -#elif defined(ARDUINO_PORTENTA_C33) || \ - defined(ARDUINO_UNOR4_WIFI) + #elif defined(ARDUINO_PORTENTA_C33) || \ + defined(ARDUINO_UNOR4_WIFI) WiFi.macAddress(in); -#elif defined(ARDUINO_NANO_RP2040_CONNECT) + #elif defined(ARDUINO_NANO_RP2040_CONNECT) WiFi.macAddress(in); -#elif defined(ARDUINO_OPTA) + #elif defined(ARDUINO_OPTA) Ethernet.MACAddress(in); -#endif + #endif return true; +#endif } }} // arduino::mac diff --git a/src/bpid/mac.h b/src/bpid/mac.h index ecf3c2c..be83415 100644 --- a/src/bpid/mac.h +++ b/src/bpid/mac.h @@ -10,6 +10,8 @@ #pragma once +#include + #if defined(ARDUINO_NANO_RP2040_CONNECT) || \ defined(ARDUINO_SAMD_MKRWIFI1010) || \ defined(ARDUINO_SAMD_NANO_33_IOT) || \ @@ -28,7 +30,7 @@ #include #define IFACE_MAC_ADDR_LENGTH 6 #else - #error "Unknown board" + #define IFACE_MAC_ADDR_LENGTH 0 #endif namespace arduino { namespace mac { @@ -45,8 +47,6 @@ namespace arduino { namespace mac { * ARDUINO_OPTA: Ethernet.begin(NULL,0,0); reversed */ - constexpr int IFACE_MAC_SIZE = IFACE_MAC_ADDR_LENGTH; - bool get(uint8_t *in, uint32_t size); }} // arduino::mac diff --git a/src/bpid/ucid.cpp b/src/bpid/ucid.cpp index a39e5d1..38a2b0a 100644 --- a/src/bpid/ucid.cpp +++ b/src/bpid/ucid.cpp @@ -13,36 +13,42 @@ namespace arduino { namespace ucid { bool get(uint8_t *in, uint32_t size) { +#if UC_UID_SIZE == 0 + (void)in; + (void)size; + return false; +#else if (size < UC_UID_SIZE) { return false; } -#if defined(ARDUINO_SAMD_MKRWIFI1010) || \ - defined(ARDUINO_SAMD_NANO_33_IOT) + #if defined(ARDUINO_SAMD_MKRWIFI1010) || \ + defined(ARDUINO_SAMD_NANO_33_IOT) (*(uint32_t*)(&in[0x0])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A00C)); (*(uint32_t*)(&in[0x4])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A040)); (*(uint32_t*)(&in[0x8])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A044)); (*(uint32_t*)(&in[0xC])) = __builtin_bswap32(*(volatile uint32_t*)(0x0080A048)); -#elif defined(ARDUINO_PORTENTA_H7_M7) || \ - defined(ARDUINO_NICLA_VISION) || \ - defined(ARDUINO_OPTA) || \ - defined(ARDUINO_GIGA) + #elif defined(ARDUINO_PORTENTA_H7_M7) || \ + defined(ARDUINO_NICLA_VISION) || \ + defined(ARDUINO_OPTA) || \ + defined(ARDUINO_GIGA) (*(uint32_t*)(&in[0x0])) = __builtin_bswap32(HAL_GetUIDw0()); (*(uint32_t*)(&in[0x4])) = __builtin_bswap32(HAL_GetUIDw1()); (*(uint32_t*)(&in[0x8])) = __builtin_bswap32(HAL_GetUIDw2()); -#elif defined(ARDUINO_PORTENTA_C33) || \ - defined(ARDUINO_UNOR4_WIFI) + #elif defined(ARDUINO_PORTENTA_C33) || \ + defined(ARDUINO_UNOR4_WIFI) const bsp_unique_id_t* t = R_BSP_UniqueIdGet(); (*(uint32_t*)(&in[0x0])) = __builtin_bswap32(t->unique_id_words[0x0]); (*(uint32_t*)(&in[0x4])) = __builtin_bswap32(t->unique_id_words[0x1]); (*(uint32_t*)(&in[0x8])) = __builtin_bswap32(t->unique_id_words[0x2]); (*(uint32_t*)(&in[0xC])) = __builtin_bswap32(t->unique_id_words[0x3]); -#elif defined(ARDUINO_NANO_RP2040_CONNECT) + #elif defined(ARDUINO_NANO_RP2040_CONNECT) uint8_t id[UC_UID_SIZE]; flash_get_unique_id(id); (*(uint32_t*)(&in[0x0])) = __builtin_bswap32(*(uint32_t*)&id[0x0]); (*(uint32_t*)(&in[0x4])) = __builtin_bswap32(*(uint32_t*)&id[0x4]); -#endif + #endif return true; +#endif } }} // arduino::ucid diff --git a/src/bpid/ucid.h b/src/bpid/ucid.h index 14a204f..4fca022 100644 --- a/src/bpid/ucid.h +++ b/src/bpid/ucid.h @@ -12,31 +12,36 @@ #include -namespace arduino { namespace ucid { - /* - * This library contains the methods to get board microcontroller id - */ - -#if defined(ARDUINO_SAMD_MKRWIFI1010) || \ - defined(ARDUINO_SAMD_NANO_33_IOT) - constexpr int UC_UID_SIZE = 16; +#if defined(ARDUINO_SAMD_NANO_33_IOT) || \ + defined(ARDUINO_SAMD_MKRWIFI1010) || \ + defined(ARDUINO_SAMD_MKRGSM1400) || \ + defined(ARDUINO_SAMD_MKRWAN1300) || \ + defined(ARDUINO_SAMD_MKRWAN1310) || \ + defined(ARDUINO_SAMD_MKRNB1500) || \ + defined(ARDUINO_SAMD_MKR1000) + #define UC_UID_SIZE 16 #elif defined(ARDUINO_PORTENTA_H7_M7) || \ defined(ARDUINO_NICLA_VISION) || \ defined(ARDUINO_OPTA) || \ defined(ARDUINO_GIGA) - constexpr int UC_UID_SIZE = 12; + #define UC_UID_SIZE 12 #elif defined(ARDUINO_PORTENTA_C33) || \ defined(ARDUINO_UNOR4_WIFI) - constexpr int UC_UID_SIZE = 16; + #define UC_UID_SIZE 16 #elif defined(ARDUINO_NANO_RP2040_CONNECT) extern "C" { #include "hardware/flash.h" } - constexpr int UC_UID_SIZE = FLASH_UNIQUE_ID_SIZE_BYTES; + #define UC_UID_SIZE FLASH_UNIQUE_ID_SIZE_BYTES #else - #error "Unknown board" + #define UC_UID_SIZE 0 #endif +namespace arduino { namespace ucid { + /* + * This library contains the methods to get board microcontroller id + */ + bool get(uint8_t *in, uint32_t size); }} // arduino::ucid