mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/luid: allow to overwrite luid_base()
This allows to overwrite luid_base() with a function that reads an ID from e.g. a EUI64MAC chip if no CPU ID is available.
This commit is contained in:
parent
9fb01b6d1c
commit
f6e7be9a06
@ -26,7 +26,26 @@
|
||||
|
||||
#include "luid.h"
|
||||
|
||||
static uint8_t lastused = 1;
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
void __attribute__((weak)) luid_base(void *buf, size_t len)
|
||||
{
|
||||
memset(buf, LUID_BACKUP_SEED, len);
|
||||
|
||||
#if CPUID_LEN
|
||||
uint8_t *out = (uint8_t *)buf;
|
||||
uint8_t cid[CPUID_LEN];
|
||||
|
||||
cpuid_get(cid);
|
||||
for (size_t i = 0; i < MAX(len, CPUID_LEN); i++) {
|
||||
out[i % len] ^= cid[i % CPUID_LEN];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint8_t lastused;
|
||||
|
||||
void luid_get(void *buf, size_t len)
|
||||
{
|
||||
@ -44,19 +63,3 @@ void luid_custom(void *buf, size_t len, int gen)
|
||||
}
|
||||
}
|
||||
|
||||
void luid_base(void *buf, size_t len)
|
||||
{
|
||||
assert(buf && (len > 0));
|
||||
|
||||
memset(buf, LUID_BACKUP_SEED, len);
|
||||
|
||||
#if CPUID_LEN
|
||||
uint8_t *out = (uint8_t *)buf;
|
||||
uint8_t cid[CPUID_LEN];
|
||||
|
||||
cpuid_get(cid);
|
||||
for (size_t i = 0; i < CPUID_LEN; i++) {
|
||||
out[i % len] ^= cid[i];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user