Merge pull request #15611 from benpicco/boards/eui_provider.h
net/eui_provider: API cleanup
This commit is contained in:
commit
6646682873
@ -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
|
||||
* @{
|
||||
|
||||
51
boards/avr-rss2/include/eui_provider_params.h
Normal file
51
boards/avr-rss2/include/eui_provider_params.h
Normal file
@ -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 <benjamin.valentin@ml-pa.com>
|
||||
*/
|
||||
#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 */
|
||||
/** @} */
|
||||
@ -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
|
||||
* @{
|
||||
|
||||
64
boards/derfmega256/include/eui_provider_params.h
Normal file
64
boards/derfmega256/include/eui_provider_params.h
Normal file
@ -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 <chudov@gmail.com>
|
||||
*/
|
||||
#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 */
|
||||
/** @} */
|
||||
@ -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
|
||||
* @{
|
||||
|
||||
48
boards/same54-xpro/include/eui_provider_params.h
Normal file
48
boards/same54-xpro/include/eui_provider_params.h
Normal file
@ -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 <benjamin.valentin@ml-pa.com>
|
||||
*/
|
||||
#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 */
|
||||
/** @} */
|
||||
@ -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
|
||||
* @{
|
||||
|
||||
55
boards/samr21-xpro/include/eui_provider_params.h
Normal file
55
boards/samr21-xpro/include/eui_provider_params.h
Normal file
@ -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 <benjamin.valentin@ml-pa.com>
|
||||
*/
|
||||
#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 */
|
||||
/** @} */
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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, \
|
||||
},
|
||||
|
||||
@ -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, \
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user