From 4dfeafcabda292d9ac5cdf0d2ba12eccb192c0c6 Mon Sep 17 00:00:00 2001 From: Jens Wetterich Date: Thu, 10 Feb 2022 18:16:43 +0100 Subject: [PATCH] cpu/native/netdev_tap: Add to netdev_register --- cpu/native/include/netdev_tap.h | 4 +++- cpu/native/netdev_tap/netdev_tap.c | 3 ++- drivers/include/net/netdev.h | 1 + pkg/lwip/init_devs/auto_init_netdev_tap.c | 2 +- sys/net/gnrc/netif/init_devs/auto_init_netdev_tap.c | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cpu/native/include/netdev_tap.h b/cpu/native/include/netdev_tap.h index 29b3e4d254..e94cd6f861 100644 --- a/cpu/native/include/netdev_tap.h +++ b/cpu/native/include/netdev_tap.h @@ -59,8 +59,10 @@ typedef struct { * * @param dev the preallocated netdev_tap device handle to setup * @param params initialization parameters + * @param index Index of @p params in a global parameter struct array. + * If initialized manually, pass a unique identifier instead. */ -void netdev_tap_setup(netdev_tap_t *dev, const netdev_tap_params_t *params); +void netdev_tap_setup(netdev_tap_t *dev, const netdev_tap_params_t *params, int index); #ifdef __cplusplus } diff --git a/cpu/native/netdev_tap/netdev_tap.c b/cpu/native/netdev_tap/netdev_tap.c index 5bf67e8eff..70755e9176 100644 --- a/cpu/native/netdev_tap/netdev_tap.c +++ b/cpu/native/netdev_tap/netdev_tap.c @@ -290,10 +290,11 @@ static int _send(netdev_t *netdev, const iolist_t *iolist) return res; } -void netdev_tap_setup(netdev_tap_t *dev, const netdev_tap_params_t *params) { +void netdev_tap_setup(netdev_tap_t *dev, const netdev_tap_params_t *params, int index) { dev->netdev.driver = &netdev_driver_tap; strncpy(dev->tap_name, *(params->tap_name), IFNAMSIZ - 1); dev->tap_name[IFNAMSIZ - 1] = '\0'; + netdev_register(&dev->netdev, NETDEV_TAP, index); } static void _tap_isr(int fd, void *arg) { diff --git a/drivers/include/net/netdev.h b/drivers/include/net/netdev.h index 45f64751a6..2595082d03 100644 --- a/drivers/include/net/netdev.h +++ b/drivers/include/net/netdev.h @@ -323,6 +323,7 @@ typedef enum { NETDEV_CC2420, NETDEV_ETHOS, NETDEV_SLIPDEV, + NETDEV_TAP, /* add more if needed */ } netdev_type_t; /** @} */ diff --git a/pkg/lwip/init_devs/auto_init_netdev_tap.c b/pkg/lwip/init_devs/auto_init_netdev_tap.c index 2939498854..effebbf637 100644 --- a/pkg/lwip/init_devs/auto_init_netdev_tap.c +++ b/pkg/lwip/init_devs/auto_init_netdev_tap.c @@ -33,7 +33,7 @@ static netdev_tap_t netdev_taps[NETIF_TAP_NUMOF]; static void auto_init_netdev_tap(void) { for (unsigned i = 0; i < NETIF_TAP_NUMOF; i++) { - netdev_tap_setup(&netdev_taps[i], &netdev_tap_params[i]); + netdev_tap_setup(&netdev_taps[i], &netdev_tap_params[i], i); if (lwip_add_ethernet(&netif[i], &netdev_taps[i].netdev) == NULL) { DEBUG("Could not add netdev_tap device\n"); return; diff --git a/sys/net/gnrc/netif/init_devs/auto_init_netdev_tap.c b/sys/net/gnrc/netif/init_devs/auto_init_netdev_tap.c index 1fd10e41b1..93a4195590 100644 --- a/sys/net/gnrc/netif/init_devs/auto_init_netdev_tap.c +++ b/sys/net/gnrc/netif/init_devs/auto_init_netdev_tap.c @@ -38,7 +38,7 @@ void auto_init_netdev_tap(void) LOG_DEBUG("[auto_init_netif] initializing netdev_tap #%u on TAP %s\n", i, *(p->tap_name)); - netdev_tap_setup(&netdev_tap[i], p); + netdev_tap_setup(&netdev_tap[i], p, i); gnrc_netif_ethernet_create(&_netif[i], _netdev_eth_stack[i], TAP_MAC_STACKSIZE, TAP_MAC_PRIO, "gnrc_netdev_tap", &netdev_tap[i].netdev);