Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions drivers/at86rf215/at86rf215.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* @}
*/

#include "luid.h"
#include "board.h"
#include "byteorder.h"
#include "net/ieee802154.h"
Expand Down Expand Up @@ -65,8 +64,7 @@ void at86rf215_reset_and_cfg(at86rf215_t *dev)
netdev_ieee802154_reset(&dev->netdev);

/* set device address */
luid_get_short((network_uint16_t *)&dev->netdev.short_addr);
luid_get_eui64((eui64_t *)&dev->netdev.long_addr);
netdev_ieee802154_setup(&dev->netdev);

if (is_subGHz(dev)) {
dev->netdev.chan = CONFIG_AT86RF215_DEFAULT_SUBGHZ_CHANNEL;
Expand Down
18 changes: 18 additions & 0 deletions drivers/include/net/netdev/ieee802154.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "net/gnrc/nettype.h"
#include "net/netopt.h"
#include "net/netdev.h"
#include "luid.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -194,6 +195,23 @@ int netdev_ieee802154_set(netdev_ieee802154_t *dev, netopt_t opt, const void *va
*/
int netdev_ieee802154_dst_filter(netdev_ieee802154_t *dev, const uint8_t *mhr);

/**
* @brief Configure the hardware address of a IEEE 802.15.4 devices
*
* This will obtain a long and short address based on the netdev ID.
* The addresses is stored in the netdev's `long_addr` & `short_addr`.
* The caller must take care of writing them to the hardware.
*
* @pre the netdev registered itself with @see netdev_register
*
* @param[out] dev Netdev to configure
*/
static inline void netdev_ieee802154_setup(netdev_ieee802154_t *dev)
{
luid_netdev_get_eui64(&dev->netdev, (eui64_t *)&dev->long_addr);
luid_get_short((network_uint16_t *)&dev->short_addr);
}

#ifdef __cplusplus
}
#endif
Expand Down
27 changes: 27 additions & 0 deletions sys/include/luid.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

#include "net/eui48.h"
#include "net/eui64.h"
#include "net/netdev.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down
30 changes: 30 additions & 0 deletions sys/luid/luid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}