diff --git a/boards/avr-rss2/include/board.h b/boards/avr-rss2/include/board.h index a4dbe6b920..4f625eaeec 100644 --- a/boards/avr-rss2/include/board.h +++ b/boards/avr-rss2/include/board.h @@ -23,9 +23,6 @@ #include "cpu.h" #include "periph/gpio.h" -#include "at24mac.h" -#include "net/eui_provider.h" - #ifdef __cplusplus extern "C" { #endif @@ -38,24 +35,6 @@ extern "C" { #define AT24MAC_PARAM_TYPE AT24MAC6XX /** @} */ -/** - * @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) -{ - return at24mac_get_eui64((uintptr_t)arg, addr); -} - -/** - * @name EUI-64 sources on the board - * AT24Mac is present on the board - * @{ - */ -#define EUI64_PROVIDER_FUNC _at24mac_get_eui64 -#define EUI64_PROVIDER_TYPE NETDEV_AT86RF2XX -#define EUI64_PROVIDER_INDEX 0 -/** @} */ - /** * @name LED pin definitions and handlers * @{ diff --git a/boards/avr-rss2/include/eui_provider_params.h b/boards/avr-rss2/include/eui_provider_params.h new file mode 100644 index 0000000000..fad4dbb736 --- /dev/null +++ b/boards/avr-rss2/include/eui_provider_params.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2020 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_avr-rss2 + * @{ + * + * @file + * @brief EUI providers found on the board + * + * @author Benjamin Valentin + */ +#ifndef EUI_PROVIDER_PARAMS_H +#define EUI_PROVIDER_PARAMS_H + +#include "at24mac.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief AT24Mac provides a EUI-64, this is also printed on the board + */ +static inline int _at24mac_get_eui64(uint8_t index, eui64_t *addr) +{ + return at24mac_get_eui64(index, addr); +} + +/** + * @name EUI-64 sources on the board + * AT24Mac is present on the board + * @{ + */ +#define EUI64_PROVIDER_FUNC _at24mac_get_eui64 +#define EUI64_PROVIDER_TYPE NETDEV_AT86RF2XX +#define EUI64_PROVIDER_INDEX 0 +/** @} */ + + +#ifdef __cplusplus +} +#endif + +#endif /* EUI_PROVIDER_PARAMS_H */ +/** @} */ diff --git a/boards/derfmega256/include/board.h b/boards/derfmega256/include/board.h index cf850d7cb6..a28921631f 100644 --- a/boards/derfmega256/include/board.h +++ b/boards/derfmega256/include/board.h @@ -21,44 +21,10 @@ #include "cpu.h" -#include "periph/eeprom.h" -#include "net/eui_provider.h" - #ifdef __cplusplus extern "C" { #endif -/** - * @name MAC configuration - * Offset of the MAC address in the EEPROM - */ -#define EEPROM_MAC_ADDR (0x1fe4) - -/** - * @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) -{ - (void) arg; - - if (eeprom_read(EEPROM_MAC_ADDR, addr, sizeof(eui64_t)) != sizeof(eui64_t)) { - return -1; - } - - addr->uint64.u64 = byteorder_htonll(addr->uint64.u64).u64; - - return 0; -} - -/** - * @name EUI-64 sources on the board - * @{ - */ -#define EUI64_PROVIDER_FUNC _eeprom_mac_get_eui64 -#define EUI64_PROVIDER_TYPE NETDEV_AT86RF2XX -#define EUI64_PROVIDER_INDEX 0 -/** @} */ - /** * @name xtimer configuration values * @{ diff --git a/boards/derfmega256/include/eui_provider_params.h b/boards/derfmega256/include/eui_provider_params.h new file mode 100644 index 0000000000..3d1ce9d29d --- /dev/null +++ b/boards/derfmega256/include/eui_provider_params.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2020 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_deRFmega256 + * @{ + * + * @file + * @brief EUI providers found on the board + * + * @author Alexander Chudov + */ +#ifndef EUI_PROVIDER_PARAMS_H +#define EUI_PROVIDER_PARAMS_H + +#include "net/eui64.h" +#include "periph/eeprom.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name MAC configuration + * Offset of the MAC address in the EEPROM + */ +#define EEPROM_MAC_ADDR (0x1fe4) + +/** + * @brief Constant in EEPROM provides a EUI-64, this is also printed on the board + */ +static inline int _eeprom_mac_get_eui64(uint8_t index, eui64_t *addr) +{ + (void)index; + + if (eeprom_read(EEPROM_MAC_ADDR, addr, sizeof(eui64_t)) != sizeof(eui64_t)) { + return -1; + } + + addr->uint64.u64 = byteorder_htonll(addr->uint64.u64).u64; + + return 0; +} + +/** + * @name EUI-64 sources on the board + * @{ + */ +#define EUI64_PROVIDER_FUNC _eeprom_mac_get_eui64 +#define EUI64_PROVIDER_TYPE NETDEV_AT86RF2XX +#define EUI64_PROVIDER_INDEX 0 +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* EUI_PROVIDER_PARAMS_H */ +/** @} */ diff --git a/boards/same54-xpro/include/board.h b/boards/same54-xpro/include/board.h index 5618f18e63..6d0e6a03c4 100644 --- a/boards/same54-xpro/include/board.h +++ b/boards/same54-xpro/include/board.h @@ -21,7 +21,6 @@ #define BOARD_H #include "cpu.h" -#include "at24mac.h" #include "mtd.h" #ifdef __cplusplus @@ -45,22 +44,6 @@ extern "C" { #define ATCA_PARAM_I2C I2C_DEV(1) /** @} */ -/** - * @brief AT24Mac provides a EUI-48 - */ -static inline int _at24mac_get_eui48(const void *arg, eui48_t *addr) -{ - return at24mac_get_eui48((uintptr_t)arg, addr); -} - -/** - * @name EUI-48 sources on the board - * AT24Mac is present on the board - * @{ - */ -#define EUI48_PROVIDER_FUNC _at24mac_get_eui48 -/** @} */ - /** * @name LED pin definitions and handlers * @{ diff --git a/boards/same54-xpro/include/eui_provider_params.h b/boards/same54-xpro/include/eui_provider_params.h new file mode 100644 index 0000000000..fbb7471c26 --- /dev/null +++ b/boards/same54-xpro/include/eui_provider_params.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2020 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_same54-xpro + * @{ + * + * @file + * @brief EUI providers found on the board + * + * @author Benjamin Valentin + */ +#ifndef EUI_PROVIDER_PARAMS_H +#define EUI_PROVIDER_PARAMS_H + +#include "at24mac.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief AT24Mac provides a EUI-48 + */ +static inline int _at24mac_get_eui48(uint8_t index, eui48_t *addr) +{ + return at24mac_get_eui48(index, addr); +} + +/** + * @name EUI-48 sources on the board + * AT24Mac is present on the board + * @{ + */ +#define EUI48_PROVIDER_FUNC _at24mac_get_eui48 +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* EUI_PROVIDER_PARAMS_H */ +/** @} */ diff --git a/boards/samr21-xpro/include/board.h b/boards/samr21-xpro/include/board.h index daba7670a4..44cc80cf7e 100644 --- a/boards/samr21-xpro/include/board.h +++ b/boards/samr21-xpro/include/board.h @@ -25,8 +25,6 @@ #include "periph_conf.h" #include "periph_cpu.h" -#include "edbg_eui.h" - #ifdef __cplusplus extern "C" { #endif @@ -59,30 +57,6 @@ extern "C" { #define AT86RF2XX_PARAM_SLEEP GPIO_PIN(PA, 20) #define AT86RF2XX_PARAM_RESET GPIO_PIN(PB, 15) -/** - * @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) -{ - (void) arg; - - /* EDBG can take a while to respond on cold boot */ - unsigned tries = 10000; - while (--tries && edbg_get_eui64(addr)) {} - return tries ? 0 : -1; -} - -/** - * @name EUI sources on the board - * EUI-64 inside EDBG for the internal radio - * @{ - */ -#define EUI64_PROVIDER_FUNC _edbg_get_eui64 -#define EUI64_PROVIDER_TYPE NETDEV_AT86RF2XX -#define EUI64_PROVIDER_INDEX 0 -/** @} */ - - /** * @name LED pin definitions and handlers * @{ diff --git a/boards/samr21-xpro/include/eui_provider_params.h b/boards/samr21-xpro/include/eui_provider_params.h new file mode 100644 index 0000000000..3ffdc9fdd6 --- /dev/null +++ b/boards/samr21-xpro/include/eui_provider_params.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2020 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_samr21-xpro + * @{ + * + * @file + * @brief EUI providers found on the board + * + * @author Benjamin Valentin + */ +#ifndef EUI_PROVIDER_PARAMS_H +#define EUI_PROVIDER_PARAMS_H + +#include "edbg_eui.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief EDBG provides a EUI-64, the same that is printed on the board + */ +static inline int _edbg_get_eui64(uint8_t index, eui64_t *addr) +{ + (void)index; + + /* EDBG can take a while to respond on cold boot */ + unsigned tries = 10000; + while (--tries && edbg_get_eui64(addr)) {} + return tries ? 0 : -1; +} + +/** + * @name EUI sources on the board + * EUI-64 inside EDBG for the internal radio + * @{ + */ +#define EUI64_PROVIDER_FUNC _edbg_get_eui64 +#define EUI64_PROVIDER_TYPE NETDEV_AT86RF2XX +#define EUI64_PROVIDER_INDEX 0 +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* EUI_PROVIDER_PARAMS_H */ +/** @} */ diff --git a/cpu/cc2538/include/cc2538_eui_primary.h b/cpu/cc2538/include/cc2538_eui_primary.h index a8d242071b..9d1050b3b0 100644 --- a/cpu/cc2538/include/cc2538_eui_primary.h +++ b/cpu/cc2538/include/cc2538_eui_primary.h @@ -33,12 +33,14 @@ extern "C" { * * @param arg unused * @param[out] addr The EUI-64 + * @param index unused * * @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 diff --git a/sys/include/net/eui_provider.h b/sys/include/net/eui_provider.h index 87282ae007..44f46a2d9d 100644 --- a/sys/include/net/eui_provider.h +++ b/sys/include/net/eui_provider.h @@ -106,33 +106,32 @@ extern "C" { /** * @brief Function for providing a EUI-48 to a device * - * @param[in] arg Optional argument provided by eui48_conf_t + * @param[in] index index of the netdev * @param[out] addr Destination pointer for the EUI-48 address * * @return 0 on success, next provider in eui48_conf_t will be * used otherwise. * 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)(uint8_t index, eui48_t *addr); /** * @brief Function for providing a EUI-64 to a device * - * @param[in] arg Optional argument provided by eui64_conf_t + * @param[in] index index of the netdev * @param[out] addr Destination pointer for the EUI-64 address * * @return 0 on success, next provider in eui64_conf_t will be * used otherwise. * 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)(uint8_t index, eui64_t *addr); /** * @brief Structure to hold providers for EUI-48 addresses */ typedef struct { netdev_get_eui48_cb_t provider; /**< function to provide an EUI-48 */ - const void *arg; /**< argument to the provider function */ netdev_type_t type; /**< device type to match or `NETDEV_ANY` */ uint8_t index; /**< device index to match or `NETDEV_INDEX_ANY` */ } eui48_conf_t; @@ -142,7 +141,6 @@ typedef struct { */ typedef struct { netdev_get_eui64_cb_t provider; /**< function to provide an EUI-64 */ - const void *arg; /**< argument to the provider function */ netdev_type_t type; /**< device type to match or `NETDEV_ANY` */ uint8_t index; /**< device index to match or `NETDEV_INDEX_ANY` */ } eui64_conf_t; diff --git a/sys/net/link_layer/eui_provider/eui_provider.c b/sys/net/link_layer/eui_provider/eui_provider.c index 558b5b4e35..54e348ff11 100644 --- a/sys/net/link_layer/eui_provider/eui_provider.c +++ b/sys/net/link_layer/eui_provider/eui_provider.c @@ -35,7 +35,7 @@ void netdev_eui48_get(netdev_t *netdev, eui48_t *addr) #else (void) netdev; #endif - if (eui48_conf[i].provider(eui48_conf[i].arg, addr) == 0) { + if (eui48_conf[i].provider(i, addr) == 0) { return; } } @@ -60,7 +60,7 @@ void netdev_eui64_get(netdev_t *netdev, eui64_t *addr) #else (void) netdev; #endif - if (eui64_conf[i].provider(eui64_conf[i].arg, addr) == 0) { + if (eui64_conf[i].provider(i, addr) == 0) { return; } } diff --git a/sys/net/link_layer/eui_provider/include/eui48_provider_params.h b/sys/net/link_layer/eui_provider/include/eui48_provider_params.h index 26cda3fbd0..fc1bc946c2 100644 --- a/sys/net/link_layer/eui_provider/include/eui48_provider_params.h +++ b/sys/net/link_layer/eui_provider/include/eui48_provider_params.h @@ -17,7 +17,9 @@ #ifndef EUI48_PROVIDER_PARAMS_H #define EUI48_PROVIDER_PARAMS_H -#include "board.h" +#if __has_include("eui_provider_params.h") +#include "eui_provider_params.h" +#endif #include "net/eui_provider.h" #ifdef __cplusplus @@ -38,13 +40,6 @@ extern "C" { #endif #endif -/** - * @brief Optional function argument to `netdev_get_eui48_cb_t` - */ -#ifndef EUI48_PROVIDER_ARG -#define EUI48_PROVIDER_ARG NULL -#endif - /** * @brief Driver type to match with EUI-48 provider */ @@ -66,7 +61,6 @@ extern "C" { #ifndef EUI48_PROVIDER_PARAMS #define EUI48_PROVIDER_PARAMS { \ .provider = EUI48_PROVIDER_FUNC, \ - .arg = EUI48_PROVIDER_ARG, \ .type = EUI48_PROVIDER_TYPE, \ .index = EUI48_PROVIDER_INDEX, \ }, diff --git a/sys/net/link_layer/eui_provider/include/eui64_provider_params.h b/sys/net/link_layer/eui_provider/include/eui64_provider_params.h index 802cfaec23..d685694758 100644 --- a/sys/net/link_layer/eui_provider/include/eui64_provider_params.h +++ b/sys/net/link_layer/eui_provider/include/eui64_provider_params.h @@ -17,7 +17,9 @@ #ifndef EUI64_PROVIDER_PARAMS_H #define EUI64_PROVIDER_PARAMS_H -#include "board.h" +#if __has_include("eui_provider_params.h") +#include "eui_provider_params.h" +#endif #include "net/eui_provider.h" #ifdef __cplusplus @@ -38,13 +40,6 @@ extern "C" { #endif #endif -/** - * @brief Optional function argument to `netdev_get_eui64_cb_t` - */ -#ifndef EUI64_PROVIDER_ARG -#define EUI64_PROVIDER_ARG NULL -#endif - /** * @brief Driver type to match with EUI-64 provider */ @@ -66,7 +61,6 @@ extern "C" { #ifndef EUI64_PROVIDER_PARAMS #define EUI64_PROVIDER_PARAMS { \ .provider = EUI64_PROVIDER_FUNC, \ - .arg = EUI64_PROVIDER_ARG, \ .type = EUI64_PROVIDER_TYPE, \ .index = EUI64_PROVIDER_INDEX, \ },