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 8 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
6 changes: 6 additions & 0 deletions sys/include/luid.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ void luid_get(void *buf, size_t len);
*
* @note The resulting address will repeat after 255 calls.
*
* @warning Don't call this function directly, use @ref l2util_generate_short_addr() instead.
*
* @param[out] addr memory location to copy the address into.
*/
void luid_get_short(network_uint16_t *addr);
Expand All @@ -106,6 +108,8 @@ void luid_get_short(network_uint16_t *addr);
*
* @note The resulting address will repeat after 255 calls.
*
* @warning Don't call this function directly, use @ref l2util_generate_eui48() instead.
*
* @param[out] addr memory location to copy the address into.
*/
void luid_get_eui48(eui48_t *addr);
Expand All @@ -118,6 +122,8 @@ void luid_get_eui48(eui48_t *addr);
*
* @note The resulting address will repeat after 255 calls.
*
* @warning Don't call this function directly, use @ref l2util_generate_eui64() instead.
*
* @param[out] addr memory location to copy the address into.
*/
void luid_get_eui64(eui64_t *addr);
Expand Down
1 change: 0 additions & 1 deletion sys/include/net/eui48.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ static inline void eui48_clear_group(eui48_t *addr)
addr->uint8[0] &= ~EUI48_GROUP_FLAG;
}


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

#include <stdint.h>

#include "luid.h"
#include "net/eui64.h"
#include "net/ndp.h"

Expand Down Expand Up @@ -133,6 +134,125 @@ int l2util_ipv6_iid_to_addr(int dev_type, const eui64_t *iid, uint8_t *addr);
int l2util_ndp_addr_len_from_l2ao(int dev_type,
const ndp_opt_t *opt);

/**
* @brief Board-specific function to supply a short address to a netdev.
*
* @note Implement this function in your board code if the board
* provides the means to supply a unique address to a netdev.
*
* @warning Don't call this function directly, use @ref l2util_generate_short_addr() instead.
*
* @param[in] driver The driver name of the netdev
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please relight my memory: What is the driver name of the netdev?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was that a EUI would be assigned to a certain device/driver.
E.g. both samr21-xpro and same54-xpro contain a EUI-64 resp. EUI-48.
On samr21-xpro that should only be used for the first device of the at86rf2xx driver…

It's not pretty but so far we haven't come up with a better solution to assign IDs to netdevs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not pretty but so far we haven't come up with a better solution to assign IDs to netdevs.

Mhhhh its not just not pretty, it can be very costly. Both the string will cost memory, and string operations aren't the most efficient either. :-/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use NETDEV_TYPE_ here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the netdev allocations would be in an xfa this would be simpler :-/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this we would have the migration benefit, that this could be done driver by driver.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not provide a board-unique ID with params btw?

  • we have to touch every board
  • we waste RAM and ROM for information that is already implicitly available

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* we waste RAM and ROM for information that is already implicitly available

I thought it is not. If it is why use the (more RAM heavy) name?

* we have to touch every board

If we don't use the current approach, I believe we don't have. Also: only every board that provides a netdev params.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it is not. If it is why use the (more RAM heavy) name?

Well we just have to touch every netdev driver (to do the index -> params mapping inside the driver instead of auto_init). I just want to be sure that's the right way to go before I shave that Yak 😉

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to be sure that's the right way to go before I shave that Yak wink

See #12641 (comment). As far as I understand board.c might not exist anymore in the near future :-/.

* @param[in] idx The index in the <driver>_params_t struct
* @param[out] addr The dedicated address for the netdev
*
* @return The number of bytes copied. 0 if no address is available.
*/
size_t board_get_short_addr(const char *driver, unsigned idx, network_uint16_t *addr);

/**
* @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_short_addr.
* If no such function is availiable, this will fall back to
* @ref luid_get_short.
*
* @param[in] driver The driver name of the netdev
* Will be passed on to @ref board_get_eui48.
* @param[in] idx The index in the <driver>_params_t struct
* Will be passed on to @ref board_get_eui48.
* @param[out] addr The generated short address
*
*/
static inline void l2util_generate_short_addr(const char *driver, unsigned idx, network_uint16_t *addr)
{
if (board_get_short_addr(driver, idx, addr) == sizeof(*addr)) {
return;
}

luid_get_short(addr);
}

/**
* @brief Board-specific function to supply an EUI-48 to a netdev
*
* @note Implement this function in your board code if the board
* provides the means to supply a unique address to a netdev.
*
* @warning Don't call this function directly, use @ref l2util_generate_eui48() instead.
*
* @param[in] driver The driver name of the netdev
* @param[in] idx The index in the <driver>_params_t struct
* @param[out] addr The dedicated address for the netdev
*
* @return The number of bytes copied. 0 if no address is available.
*/
size_t board_get_eui48(const char *driver, unsigned idx, eui48_t *addr);

/**
* @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] driver The driver name of the netdev
* Will be passed on to @ref board_get_eui48.
* @param[in] idx The index in the <driver>_params_t struct
* Will be passed on to @ref board_get_eui48.
* @param[out] addr The generated EUI-48 address
*
*/
static inline void l2util_generate_eui48(const char *driver, unsigned idx, eui48_t *addr)
{
if (board_get_eui48(driver, idx, addr) == sizeof(*addr)) {
return;
}

luid_get_eui48(addr);
}

/**
* @brief Board-specific function to supply an EUI-64 to a netdev
*
* @note Implement this function in your board code if the board
* provides the means to supply a unique address to a netdev.
*
* @warning Don't call this function directly, use @ref l2util_generate_eui64() instead.
*
* @param[in] driver The driver name of the netdev
* @param[in] idx The index in the <driver>_params_t struct
* @param[out] addr The dedicated address for the netdev
*
* @return The number of bytes copied. 0 if no address is available.
*/
size_t board_get_eui64(const char *driver, unsigned idx, eui64_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] driver The driver name of the netdev
* Will be passed on to @ref board_get_eui64.
* @param[in] idx The index in the <driver>_params_t struct
* Will be passed on to @ref board_get_eui64.
* @param[out] addr The generated EUI-64 address
*
*/
static inline void l2util_generate_eui64(const char *driver, unsigned idx, eui64_t *addr)
{
if (board_get_eui64(driver, idx, addr) == sizeof(*addr)) {
return;
}

luid_get_eui64(addr);
}

#ifdef __cplusplus
}
Expand Down
24 changes: 24 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,28 @@ int l2util_ndp_addr_len_from_l2ao(int dev_type,
return -ENOTSUP;
}

size_t __attribute__((weak)) board_get_short_addr(const char *driver, unsigned idx, network_uint16_t *addr)
{
(void) driver;
(void) idx;
(void) addr;
return 0;
}

size_t __attribute__((weak)) board_get_eui48(const char *driver, unsigned idx, eui48_t *addr)
{
(void) driver;
(void) idx;
(void) addr;
return 0;
}

size_t __attribute__((weak)) board_get_eui64(const char *driver, unsigned idx, eui64_t *addr)
{
(void) driver;
(void) idx;
(void) addr;
return 0;
}

/** @} */