diff --git a/sys/include/luid.h b/sys/include/luid.h index 5ad2857bff..b647958b44 100644 --- a/sys/include/luid.h +++ b/sys/include/luid.h @@ -55,6 +55,9 @@ #include +#include "net/eui48.h" +#include "net/eui64.h" + #ifdef __cplusplus extern "C" { #endif @@ -82,6 +85,43 @@ extern "C" { */ void luid_get(void *buf, size_t len); +/** + * @brief 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. + * + * @param[out] addr memory location to copy the address into. + */ +void luid_get_short(network_uint16_t *addr); + +/** + * @brief 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. + * + * @param[out] addr memory location to copy the address into. + */ +void luid_get_eui48(eui48_t *addr); + +/** + * @brief 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. + * + * @param[out] addr memory location to copy the address into. + */ +void luid_get_eui64(eui64_t *addr); + /** * @brief Get a custom unique ID based on a user given generator value * diff --git a/sys/luid/luid.c b/sys/luid/luid.c index 9810df5df3..544eeb1c3f 100644 --- a/sys/luid/luid.c +++ b/sys/luid/luid.c @@ -63,3 +63,30 @@ void luid_custom(void *buf, size_t len, int gen) } } +void luid_get_short(network_uint16_t *addr) +{ + luid_base(addr, sizeof(*addr)); + addr->u8[1] ^= lastused++; + + /* https://tools.ietf.org/html/rfc4944#section-12 requires the first bit to + * 0 for unicast addresses */ + addr->u8[0] &= 0x7F; +} + +void luid_get_eui48(eui48_t *addr) +{ + luid_base(addr, sizeof(*addr)); + addr->uint8[5] ^= lastused++; + + eui48_set_local(addr); + eui48_clear_group(addr); +} + +void luid_get_eui64(eui64_t *addr) +{ + luid_base(addr, sizeof(*addr)); + addr->uint8[7] ^= lastused++; + + eui64_set_local(addr); + eui64_clear_group(addr); +}