net/eui_provider: provide index to the callback function

If the same callback function is used for multiple interfaces
(`NETDEV_INDEX_ANY`), it is necessary to also provide the index of
the interface to hand out and address.
This commit is contained in:
Benjamin Valentin 2020-12-04 13:49:09 +01:00
parent 9a0243e062
commit fe9ae5bc80
7 changed files with 19 additions and 9 deletions

View File

@ -41,8 +41,10 @@ extern "C" {
/** /**
* @brief AT24Mac provides a EUI-64, this is also printed on the board * @brief AT24Mac provides a EUI-64, this is also printed on the board
*/ */
static inline int _at24mac_get_eui64(const void *arg, eui64_t *addr) static inline int _at24mac_get_eui64(const void *arg, eui64_t *addr, uint8_t index)
{ {
(void) index;
return at24mac_get_eui64((uintptr_t)arg, addr); return at24mac_get_eui64((uintptr_t)arg, addr);
} }

View File

@ -37,9 +37,10 @@ extern "C" {
/** /**
* @brief Constant in EEPROM provides a EUI-64, this is also printed on the board * @brief Constant in EEPROM provides a EUI-64, this is also printed on the board
*/ */
static inline int _eeprom_mac_get_eui64(const void *arg, eui64_t *addr) static inline int _eeprom_mac_get_eui64(const void *arg, eui64_t *addr, uint8_t index)
{ {
(void) arg; (void) arg;
(void) index;
if (eeprom_read(EEPROM_MAC_ADDR, addr, sizeof(eui64_t)) != sizeof(eui64_t)) { if (eeprom_read(EEPROM_MAC_ADDR, addr, sizeof(eui64_t)) != sizeof(eui64_t)) {
return -1; return -1;

View File

@ -48,8 +48,10 @@ extern "C" {
/** /**
* @brief AT24Mac provides a EUI-48 * @brief AT24Mac provides a EUI-48
*/ */
static inline int _at24mac_get_eui48(const void *arg, eui48_t *addr) static inline int _at24mac_get_eui48(const void *arg, eui48_t *addr, uint8_t index)
{ {
(void) index;
return at24mac_get_eui48((uintptr_t)arg, addr); return at24mac_get_eui48((uintptr_t)arg, addr);
} }

View File

@ -62,9 +62,10 @@ extern "C" {
/** /**
* @brief EDBG provides a EUI-64, the same that is printed on the board * @brief EDBG provides a EUI-64, the same that is printed on the board
*/ */
static inline int _edbg_get_eui64(const void *arg, eui64_t *addr) static inline int _edbg_get_eui64(const void *arg, eui64_t *addr, uint8_t index)
{ {
(void) arg; (void) arg;
(void) index;
/* EDBG can take a while to respond on cold boot */ /* EDBG can take a while to respond on cold boot */
unsigned tries = 10000; unsigned tries = 10000;

View File

@ -33,12 +33,14 @@ extern "C" {
* *
* @param arg unused * @param arg unused
* @param[out] addr The EUI-64 * @param[out] addr The EUI-64
* @param index unused
* *
* @return 0 * @return 0
*/ */
static inline int cc2538_get_eui64_primary(const void *arg, eui64_t *addr) static inline int cc2538_get_eui64_primary(const void *arg, eui64_t *addr, uint8_t index)
{ {
(void) arg; (void) arg;
(void) index;
/* /*
* The primary EUI-64 seems to be written to memory in a non-sequential * The primary EUI-64 seems to be written to memory in a non-sequential

View File

@ -108,24 +108,26 @@ extern "C" {
* *
* @param[in] arg Optional argument provided by eui48_conf_t * @param[in] arg Optional argument provided by eui48_conf_t
* @param[out] addr Destination pointer for the EUI-48 address * @param[out] addr Destination pointer for the EUI-48 address
* @param[in] index index of the netdev
* *
* @return 0 on success, next provider in eui48_conf_t will be * @return 0 on success, next provider in eui48_conf_t will be
* used otherwise. * used otherwise.
* Will fall back to @see luid_get_eui48 eventually. * Will fall back to @see luid_get_eui48 eventually.
*/ */
typedef int (*netdev_get_eui48_cb_t)(const void *arg, eui48_t *addr); typedef int (*netdev_get_eui48_cb_t)(const void *arg, eui48_t *addr, uint8_t index);
/** /**
* @brief Function for providing a EUI-64 to a device * @brief Function for providing a EUI-64 to a device
* *
* @param[in] arg Optional argument provided by eui64_conf_t * @param[in] arg Optional argument provided by eui64_conf_t
* @param[out] addr Destination pointer for the EUI-64 address * @param[out] addr Destination pointer for the EUI-64 address
* @param[in] index index of the netdev
* *
* @return 0 on success, next provider in eui64_conf_t will be * @return 0 on success, next provider in eui64_conf_t will be
* used otherwise. * used otherwise.
* Will fall back to @see luid_get_eui64 eventually. * Will fall back to @see luid_get_eui64 eventually.
*/ */
typedef int (*netdev_get_eui64_cb_t)(const void *arg, eui64_t *addr); typedef int (*netdev_get_eui64_cb_t)(const void *arg, eui64_t *addr, uint8_t index);
/** /**
* @brief Structure to hold providers for EUI-48 addresses * @brief Structure to hold providers for EUI-48 addresses

View File

@ -35,7 +35,7 @@ void netdev_eui48_get(netdev_t *netdev, eui48_t *addr)
#else #else
(void) netdev; (void) netdev;
#endif #endif
if (eui48_conf[i].provider(eui48_conf[i].arg, addr) == 0) { if (eui48_conf[i].provider(eui48_conf[i].arg, addr, i) == 0) {
return; return;
} }
} }
@ -60,7 +60,7 @@ void netdev_eui64_get(netdev_t *netdev, eui64_t *addr)
#else #else
(void) netdev; (void) netdev;
#endif #endif
if (eui64_conf[i].provider(eui64_conf[i].arg, addr) == 0) { if (eui64_conf[i].provider(eui64_conf[i].arg, addr, i) == 0) {
return; return;
} }
} }