diff --git a/sys/include/luid.h b/sys/include/luid.h index b2aebb9bcd..870865b3a3 100644 --- a/sys/include/luid.h +++ b/sys/include/luid.h @@ -57,6 +57,7 @@ #include "net/eui48.h" #include "net/eui64.h" +#include "net/netdev.h" #ifdef __cplusplus extern "C" { @@ -127,6 +128,19 @@ void luid_get_short(network_uint16_t *addr); */ void luid_get_eui48(eui48_t *addr); +/** + * @brief 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. + * + * @pre the netdev registered itself with @see netdev_register + * + * @param[in] netdev Netdev to generate the EUI48 for. + * @param[out] addr memory location to copy the address into. + */ +void luid_netdev_get_eui48(const netdev_t *netdev, eui48_t *addr); + /** * @brief Get a unique EUI64 address * @@ -139,6 +153,19 @@ void luid_get_eui48(eui48_t *addr); */ void luid_get_eui64(eui64_t *addr); +/** + * @brief 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. + * + * @pre the netdev registered itself with @see netdev_register + * + * @param[in] netdev Netdev to generate the EUI64 for. + * @param[out] addr memory location to copy the address into. + */ +void luid_netdev_get_eui64(const netdev_t *netdev, 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 bdaff93ff4..baa51584fe 100644 --- a/sys/luid/luid.c +++ b/sys/luid/luid.c @@ -89,6 +89,21 @@ void luid_get_eui48(eui48_t *addr) eui48_clear_group(addr); } +void luid_netdev_get_eui48(const netdev_t *netdev, eui48_t *addr) +{ + luid_base(addr, sizeof(*addr)); +#ifdef MODULE_NETDEV_REGISTER + addr->uint8[4] ^= netdev->type; + addr->uint8[5] ^= netdev->index; +#else + /* we should only get here with gnrc_netif_single */ + (void)netdev; +#endif + + eui48_set_local(addr); + eui48_clear_group(addr); +} + void luid_get_eui64(eui64_t *addr) { luid_base(addr, sizeof(*addr)); @@ -97,3 +112,18 @@ void luid_get_eui64(eui64_t *addr) eui64_set_local(addr); eui64_clear_group(addr); } + +void luid_netdev_get_eui64(const netdev_t *netdev, eui64_t *addr) +{ + luid_base(addr, sizeof(*addr)); +#ifdef MODULE_NETDEV_REGISTER + addr->uint8[6] ^= netdev->type; + addr->uint8[7] ^= netdev->index; +#else + /* we should only get here with gnrc_netif_single */ + (void)netdev; +#endif + + eui64_set_local(addr); + eui64_clear_group(addr); +}