Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/l2util: add eui_short/48/64_get() #12641

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions sys/include/net/eui48.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,35 @@ static inline void eui48_clear_group(eui48_t *addr)
addr->uint8[0] &= ~EUI48_GROUP_FLAG;
}

/**
* @brief Generates an EUI-48 address for the netdev interface.
*
* @note It is possible to supply a board-specific, constant addres
* by implementing @ref board_get_eui48.
* If no such function is availiable, this will fall back to
* @ref luid_get_eui48.
*
* @param[in] netdev The network device for which the address is
* generated.
* Will be passed on to @ref board_get_eui48.
* @param[out] addr The generated EUI-48 address
*
*/
void eui48_get(netdev_t *netdev, eui48_t *addr);

/**
* @brief Board-specific function to supply an EUI-48 to a netdev
*
* Implement this function in your board code if the board
benpicco marked this conversation as resolved.
Show resolved Hide resolved
* provides the means to supply a unique address to a netdev.
*
* @see eui48_get
*
* @param[in] netdev The network device that requested the address
* @param[out] addr The dedicated address for the netdev
*
*/
size_t board_get_eui48(netdev_t *netdev, eui48_t *addr);

#ifdef __cplusplus
}
Expand Down
60 changes: 60 additions & 0 deletions sys/include/net/eui64.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,66 @@ static inline void eui64_clear_group(eui64_t *addr)
addr->uint8[0] &= ~EUI64_GROUP_FLAG;
}

/**
* @brief Generates an short address for the netdev interface.
*
* @note It is possible to supply a board-specific, constant addres
* by implementing @ref board_get_eui_short.
* If no such function is availiable, this will fall back to
* @ref luid_get_short.
*
* @param[in] netdev The network device for which the address is
* generated.
* Will be passed on to @ref board_get_eui48.
* @param[out] addr The generated short address
*
*/
void eui_short_get(netdev_t *netdev, uint16_t *addr);

/**
* @brief Generates an EUI-64 address for the netdev interface.
*
* @note It is possible to supply a board-specific, constant addres
* by implementing @ref board_get_eui64.
* If no such function is availiable, this will fall back to
* @ref luid_get_eui64.
*
* @param[in] netdev The network device for which the address is
* generated.
* Will be passed on to @ref board_get_eui64.
* @param[out] addr The generated EUI-64 address
*
*/
void eui64_get(netdev_t *netdev, eui64_t *addr);

/**
* @brief Board-specific function to supply a short address to a netdev
*
* Implement this function in your board code if the board
benpicco marked this conversation as resolved.
Show resolved Hide resolved
* provides the means to supply a unique address to a netdev.
*
* @see eui_short_get
*
* @param[in] netdev The network device that requested the address
* @param[out] addr The dedicated address for the netdev
*
*/
size_t board_get_eui_short(netdev_t *netdev, uint16_t *addr);

/**
* @brief Board-specific function to supply an EUI-64 to a netdev
*
* Implement this function in your board code if the board
* provides the means to supply a unique address to a netdev.
*
* @see eui64_get
*
* @param[in] netdev The network device that requested the address
* @param[out] addr The dedicated address for the netdev
*
*/
size_t board_get_eui64(netdev_t *netdev, eui64_t *addr);

#ifdef __cplusplus
}
#endif
Expand Down
48 changes: 48 additions & 0 deletions sys/net/link_layer/l2util/l2util.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <assert.h>

#include "log.h"
#include "luid.h"
#include "net/eui48.h"
#include "net/ieee802154.h"
#include "net/ipv6.h"
Expand Down Expand Up @@ -238,5 +239,52 @@ int l2util_ndp_addr_len_from_l2ao(int dev_type,
return -ENOTSUP;
}

size_t __attribute__((weak)) board_get_eui_short(netdev_t *netdev, uint16_t *addr)
benpicco marked this conversation as resolved.
Show resolved Hide resolved
{
(void) netdev;
(void) addr;
return 0;
}

size_t __attribute__((weak)) board_get_eui48(netdev_t *netdev, eui48_t *addr)
{
(void) netdev;
(void) addr;
return 0;
}

size_t __attribute__((weak)) board_get_eui64(netdev_t *netdev, eui64_t *addr)
{
(void) netdev;
(void) addr;
return 0;
}

void eui_short_get(netdev_t *netdev, uint16_t *addr)
{
if (board_get_eui_short(netdev, addr) == sizeof(*addr)) {
return;
}

luid_get_short(addr);
}

void eui48_get(netdev_t *netdev, eui48_t *addr)
{
if (board_get_eui48(netdev, addr) == sizeof(*addr)) {
return;
}

luid_get_eui48(addr);
}

void eui64_get(netdev_t *netdev, eui64_t *addr)
{
if (board_get_eui64(netdev, addr) == sizeof(*addr)) {
return;
}

luid_get_eui64(addr);
}

/** @} */