12#if DETWS_ENABLE_DEVICE_ID
23const uint8_t NS_DNS[16] = {0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1,
24 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8};
27void detws_uuid_from_mac(
const uint8_t mac[6],
char out[DETWS_UUID_STR_LEN])
30 uint8_t input[16 + 12];
31 for (
int i = 0; i < 16; i++)
33 for (
int i = 0; i < 6; i++)
35 input[16 + i * 2] = (uint8_t)
det_hex_digit((uint8_t)(mac[i] >> 4));
36 input[16 + i * 2 + 1] = (uint8_t)
det_hex_digit((uint8_t)(mac[i] & 0x0F));
40 sha1(input,
sizeof(input), h);
41 h[6] = (uint8_t)((h[6] & 0x0F) | 0x50);
42 h[8] = (uint8_t)((h[8] & 0x3F) | 0x80);
45 static const int groups[5] = {4, 2, 2, 2, 6};
48 for (
int g = 0; g < 5; g++)
52 for (
int b = 0; b < groups[g]; b++)
63void detws_device_uuid(
char out[DETWS_UUID_STR_LEN])
66 esp_read_mac(mac, ESP_MAC_WIFI_STA);
67 detws_uuid_from_mac(mac, out);
Stable device UUID derived from the chip MAC (DETWS_ENABLE_DEVICE_ID).
Tiny no-stdlib hex encode / decode / nibble helpers (one shared copy).
char det_hex_digit(int nibble, bool upper=false)
Nibble 0..15 -> hex char (lowercase, or uppercase when upper).
void sha1(const uint8_t *data, size_t len, uint8_t digest[SHA1_DIGEST_LEN])
Compute a SHA-1 digest over an arbitrary byte buffer.
Software SHA-1 implementation - no platform dependencies.
#define SHA1_DIGEST_LEN
SHA-1 digest length in bytes.