mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/luid: add luid_netdev_get_eui48() & luid_netdev_get_eui64()
Add functions to generate an EUI based on the netdev ID. This will always return the same EUI for the same netdev, so it is stable across netdev resets.
This commit is contained in:
parent
f4a2148642
commit
3b7351753b
@ -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
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user