Locally Unique ID Generator

Generate system wide (locally) unique IDs. More...

Detailed Description

Generate system wide (locally) unique IDs.

This module generates system wide, variable length unique IDs based on on the cpuid module. If the cpuid module is not present, the module falls back to a pre-defined, constant seed for creating unique IDs.

The main purpose of this module is to have a unified way for e.g. creating hardware addresses and similar.

The IDs generated by this module are base created from a constant base part and a dynamic portion, which is XORed into the base ID. If the cpuid module is present, the base ID is created from the CPU's unique ID. If not, the base ID is created by simple 'memsetting' the base ID with the defined backup seed value.

Once the base ID is generated, a LUID is generated by (i) XORing a counter value with the LSB of the base ID, or (ii) by XORing the least significant byes with a value given by the user.

Example: Calling luid_base(&buf, 8) will always yield an identical value, independent how often the function is called. But calling luid_base(&buf, 2) afterwards will results in a different value, if the cpuid module is present, and in the same (but shorter) value if not.

Example: Calling luid_get(&buf, 8) four times in a row, will yield four different IDs, differing in their LSB.

Example: Calling luid_custom(&buf, 8, 123) will always yield the same value, but calling luid_custom(&buf, 8, 124) will differ.

Note
This module generates locally unique IDs without any guarantees on their structure. These LUIDs are not compatible nor conform to UUIDs as defined in RFC4122.

Files

file  luid.h
 Header of the unique ID generation module.
 

Macros

#define LUID_BACKUP_SEED   0x23
 Value used as based for the LUIDs in case the cpuid module is not present.
 

Functions

void luid_get (void *buf, size_t len)
 Get a unique ID. More...
 
void luid_get_lb (void *buf, size_t len)
 Get a unique ID with change in the last byte. More...
 
void luid_get_short (network_uint16_t *addr)
 Get a unique short unicast address. More...
 
void luid_get_eui48 (eui48_t *addr)
 Get a unique EUI48 address. More...
 
void luid_netdev_get_eui48 (const netdev_t *netdev, eui48_t *addr)
 Get a unique EUI48 address. More...
 
void luid_get_eui64 (eui64_t *addr)
 Get a unique EUI64 address. More...
 
void luid_netdev_get_eui64 (const netdev_t *netdev, eui64_t *addr)
 Get a unique EUI64 address. More...
 
void luid_custom (void *buf, size_t len, int gen)
 Get a custom unique ID based on a user given generator value. More...
 
void luid_base (void *buf, size_t len)
 Get a LUID base value. More...
 

Function Documentation

◆ luid_base()

void luid_base ( void *  buf,
size_t  len 
)

Get a LUID base value.

The luid module creates the value dependent on the given len value using the cpuid module if present or a static seed value (LUID_BACKUP_SEED) if not.

Parameters
[out]bufmemory location to copy the LUID into. MUST be able to hold at least len bytes
[in]lenlength of the LUID in bytes

◆ luid_custom()

void luid_custom ( void *  buf,
size_t  len,
int  gen 
)

Get a custom unique ID based on a user given generator value.

The resulting ID is built from the base ID XORed with gen in the base ID's most significant bytes.

Note
Calling this function with identical values for gen and len will always result in identical LUIDs.
Parameters
[out]bufmemory location to copy the LUID into. MUST be able to hold at least len bytes
[in]lenlength of the LUID in bytes
[in]gencustom LUID generator value

◆ luid_get()

void luid_get ( void *  buf,
size_t  len 
)

Get a unique ID.

The resulting ID is built from the base ID generated with luid_base(), which isXORed with an 8-bit incrementing counter value into the first (lowest index) byte.

Note
The resulting LUID will repeat after 255 calls.
Postcondition
The generated LUID must be used unchanged, as it could collide with other LUIDs if altered.
Parameters
[out]bufmemory location to copy the LUID into. MUST be able to hold at least len bytes
[in]lenlength of the LUID in bytes

◆ luid_get_eui48()

void luid_get_eui48 ( eui48_t addr)

Get a unique EUI48 address.

The resulting address is built from the base ID generated with luid_base(), which isXORed with an 8-bit incrementing counter value into the least significant byte.

Note
The resulting address will repeat after 255 calls.
Parameters
[out]addrmemory location to copy the address into.

◆ luid_get_eui64()

void luid_get_eui64 ( eui64_t addr)

Get a unique EUI64 address.

The resulting address is built from the base ID generated with luid_base(), which isXORed with an 8-bit incrementing counter value into the least significant byte.

Note
The resulting address will repeat after 255 calls.
Parameters
[out]addrmemory location to copy the address into.

◆ luid_get_lb()

void luid_get_lb ( void *  buf,
size_t  len 
)

Get a unique ID with change in the last byte.

The resulting ID is built from the base ID generated with luid_base(), which isXORed with an 8-bit incrementing counter value into the last (highest index) byte.

Note
The resulting LUID will repeat after 255 calls.
Parameters
[out]bufmemory location to copy the LUID into. MUST be able to hold at least len bytes
[in]lenlength of the LUID in bytes

◆ luid_get_short()

void luid_get_short ( network_uint16_t addr)

Get a unique short unicast address.

The resulting address is built from the base ID generated with luid_base(), which isXORed with an 8-bit incrementing counter value into the least significant byte.

Note
The resulting address will repeat after 255 calls.
Parameters
[out]addrmemory location to copy the address into.

◆ luid_netdev_get_eui48()

void luid_netdev_get_eui48 ( const netdev_t netdev,
eui48_t addr 
)

Get a unique EUI48 address.

The resulting address is built from the base ID generated with luid_base(), which isXORed with the netdev type and netdev index in the least significant bytes.

Precondition
the netdev registered itself with
See also
netdev_register
Parameters
[in]netdevNetdev to generate the EUI48 for.
[out]addrmemory location to copy the address into.

◆ luid_netdev_get_eui64()

void luid_netdev_get_eui64 ( const netdev_t netdev,
eui64_t addr 
)

Get a unique EUI64 address.

The resulting address is built from the base ID generated with luid_base(), which isXORed with the netdev type and netdev index in the least significant bytes.

Precondition
the netdev registered itself with
See also
netdev_register
Parameters
[in]netdevNetdev to generate the EUI64 for.
[out]addrmemory location to copy the address into.