mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
netdev: add netdev_register() to keep track if netdev IDs
It is desireable to have a way to identify network devices. This should be independent from the type of netdev, so a common identifier is needed. Base this on the driver ID and the index in the configuration struct. This way we achive unique IDs that stay consistent for any firmware flashed on a board.
This commit is contained in:
parent
22d3bf7c51
commit
7ceb3f0a68
@ -69,6 +69,11 @@ ifneq (,$(filter gnrc_mac,$(USEMODULE)))
|
||||
endif
|
||||
endif
|
||||
|
||||
# Don't register netdevs if there is only a single one of them
|
||||
ifeq (,$(filter gnrc_netif_single,$(USEMODULE)))
|
||||
USEMODULE += netdev_register
|
||||
endif
|
||||
|
||||
ifneq (,$(filter gnrc_gomach,$(USEMODULE)))
|
||||
USEMODULE += gnrc_netif
|
||||
USEMODULE += gnrc_nettype_gomach
|
||||
|
@ -199,6 +199,7 @@ extern "C" {
|
||||
|
||||
#include "iolist.h"
|
||||
#include "net/netopt.h"
|
||||
#include "kernel_defines.h"
|
||||
|
||||
#ifdef MODULE_L2FILTER
|
||||
#include "net/l2filter.h"
|
||||
@ -271,6 +272,18 @@ typedef struct netdev netdev_t;
|
||||
*/
|
||||
typedef void (*netdev_event_cb_t)(netdev_t *dev, netdev_event_t event);
|
||||
|
||||
/**
|
||||
* @brief Driver types for netdev.
|
||||
* @{
|
||||
*/
|
||||
typedef enum {
|
||||
NETDEV_ANY = 0, /**< Will match any device type */
|
||||
NETDEV_AT86RF215,
|
||||
NETDEV_AT86RF2XX,
|
||||
/* add more if needed */
|
||||
} netdev_type_t;
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief Structure to hold driver state
|
||||
*
|
||||
@ -290,8 +303,32 @@ struct netdev {
|
||||
#ifdef MODULE_L2FILTER
|
||||
l2filter_t filter[CONFIG_L2FILTER_LISTSIZE]; /**< link layer address filters */
|
||||
#endif
|
||||
#ifdef MODULE_NETDEV_REGISTER
|
||||
netdev_type_t type; /**< driver type used for netdev */
|
||||
uint8_t index; /**< instance number of the device */
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Register a device with netdev.
|
||||
* Must by called by the driver's setup function.
|
||||
*
|
||||
* @param[out] dev the new netdev
|
||||
* @param[in] type the driver used for the netdev
|
||||
* @param[in] index the index in the config struct
|
||||
*/
|
||||
static inline void netdev_register(struct netdev *dev, netdev_type_t type, uint8_t index)
|
||||
{
|
||||
#ifdef MODULE_NETDEV_REGISTER
|
||||
dev->type = type;
|
||||
dev->index = index;
|
||||
#else
|
||||
(void) dev;
|
||||
(void) type;
|
||||
(void) index;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Structure to hold driver interface -> function mapping
|
||||
*
|
||||
|
@ -73,6 +73,7 @@ PSEUDOMODULES += mpu_noexec_ram
|
||||
PSEUDOMODULES += nanocoap_%
|
||||
PSEUDOMODULES += netdev_default
|
||||
PSEUDOMODULES += netdev_ieee802154_%
|
||||
PSEUDOMODULES += netdev_register
|
||||
PSEUDOMODULES += netstats
|
||||
PSEUDOMODULES += netstats_l2
|
||||
PSEUDOMODULES += netstats_ipv6
|
||||
|
Loading…
Reference in New Issue
Block a user