1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/luid: provide luid_get_eui48() and luid_get_eui64()

The most common use case for luid is to generate those
addresses, so provide helper functions for it.
This commit is contained in:
Benjamin Valentin 2019-11-04 21:08:23 +01:00
parent f6e7be9a06
commit 38e94d09db
2 changed files with 67 additions and 0 deletions

View File

@ -55,6 +55,9 @@
#include <stddef.h>
#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
*

View File

@ -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);
}