From 5001ba28c4904f3e866ee72fe0e5c534700ba008 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Thu, 7 Jul 2016 21:38:08 +0200 Subject: [PATCH] cpu/native: adapt start-up and auto-init for multiple netdev2_tap --- cpu/native/include/netdev2_tap_params.h | 50 +++++++++++++++++++++ cpu/native/startup.c | 23 ++++++---- sys/auto_init/netif/auto_init_netdev2_tap.c | 35 +++++++-------- 3 files changed, 79 insertions(+), 29 deletions(-) create mode 100644 cpu/native/include/netdev2_tap_params.h diff --git a/cpu/native/include/netdev2_tap_params.h b/cpu/native/include/netdev2_tap_params.h new file mode 100644 index 000000000000..bde2ec52d987 --- /dev/null +++ b/cpu/native/include/netdev2_tap_params.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2017 Freie Universität Berlin + * + * 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 netdev2 + * @brief + * @{ + * + * @file + * @brief Default configuration for the netdev2_tap driver + * + * @author Martine Lenders + */ +#ifndef NETDEV2_TAP_PARAMS_H_ +#define NETDEV2_TAP_PARAMS_H_ + +#include "netdev2_tap.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Number of allocated parameters at @ref netdev2_tap_params + * + * @note This was decided to only be configurable on compile-time to be + * more similar to actual boards + */ +#ifndef NETDEV2_TAP_MAX +#define NETDEV2_TAP_MAX (1) +#endif + +/** + * @brief Configuration parameters for @ref netdev2_tap_t + * + * @note This variable is set on native start-up based on arguments provided + */ +extern netdev2_tap_params_t netdev2_tap_params[NETDEV2_TAP_MAX]; + +#ifdef __cplusplus +} +#endif + +#endif /* NETDEV2_TAP_PARAMS_H_ */ +/** @} */ diff --git a/cpu/native/startup.c b/cpu/native/startup.c index a706b323fb14..281f2db4aeed 100644 --- a/cpu/native/startup.c +++ b/cpu/native/startup.c @@ -60,8 +60,9 @@ int _native_rng_mode = 0; const char *_native_unix_socket_path = NULL; #ifdef MODULE_NETDEV2_TAP -#include "netdev2_tap.h" -extern netdev2_tap_t netdev2_tap; +#include "netdev2_tap_params.h" + +netdev2_tap_params_t netdev2_tap_params[NETDEV2_TAP_MAX]; #endif static const char short_opts[] = ":hi:s:deEoc:"; @@ -199,7 +200,9 @@ void usage_exit(int status) real_printf("usage: %s", _progname); #if defined(MODULE_NETDEV2_TAP) - real_printf(" "); + for (int i = 0; i < NETDEV2_TAP_MAX; i++) { + real_printf(" ", i + 1); + } #endif real_printf(" [-i ] [-d] [-e|-E] [-o] [-c ]\n"); @@ -287,9 +290,11 @@ __attribute__((constructor)) static void startup(int argc, char **argv) } } #ifdef MODULE_NETDEV2_TAP - if (argv[optind] == NULL) { - /* no tap parameter left */ - usage_exit(EXIT_FAILURE); + for (int i = 0; i < NETDEV2_TAP_MAX; i++) { + if (argv[optind + i] == NULL) { + /* no tap parameter left */ + usage_exit(EXIT_FAILURE); + } } #endif @@ -317,9 +322,9 @@ __attribute__((constructor)) static void startup(int argc, char **argv) native_cpu_init(); native_interrupt_init(); #ifdef MODULE_NETDEV2_TAP - netdev2_tap_params_t p; - p.tap_name = &(argv[optind]); - netdev2_tap_setup(&netdev2_tap, &p); + for (int i = 0; i < NETDEV2_TAP_MAX; i++) { + netdev2_tap_params[i].tap_name = &argv[optind + i]; + } #endif board_init(); diff --git a/sys/auto_init/netif/auto_init_netdev2_tap.c b/sys/auto_init/netif/auto_init_netdev2_tap.c index 9058ac04f505..1cf1b6cf6954 100644 --- a/sys/auto_init/netif/auto_init_netdev2_tap.c +++ b/sys/auto_init/netif/auto_init_netdev2_tap.c @@ -22,33 +22,28 @@ #define ENABLE_DEBUG (0) #include "debug.h" -#include "netdev2_tap.h" -#include "net/gnrc/netdev2.h" +#include "netdev2_tap_params.h" #include "net/gnrc/netdev2/eth.h" -extern netdev2_tap_t netdev2_tap; - -/** - * @brief Define stack parameters for the MAC layer thread - * @{ - */ #define TAP_MAC_STACKSIZE (THREAD_STACKSIZE_DEFAULT + DEBUG_EXTRA_STACKSIZE) -#ifndef TAP_MAC_PRIO -#define TAP_MAC_PRIO (GNRC_NETDEV2_MAC_PRIO) -#endif +#define TAP_MAC_PRIO (THREAD_PRIORITY_MAIN - 3) -/** - * @brief Stacks for the MAC layer threads - */ -static char _netdev2_eth_stack[TAP_MAC_STACKSIZE + DEBUG_EXTRA_STACKSIZE]; -static gnrc_netdev2_t _gnrc_netdev2_tap; +static netdev2_tap_t netdev2_tap[NETDEV2_TAP_MAX]; +static char _netdev2_eth_stack[NETDEV2_TAP_MAX][TAP_MAC_STACKSIZE + DEBUG_EXTRA_STACKSIZE]; +static gnrc_netdev2_t _gnrc_netdev2_tap[NETDEV2_TAP_MAX]; void auto_init_netdev2_tap(void) { - gnrc_netdev2_eth_init(&_gnrc_netdev2_tap, (netdev2_t*)&netdev2_tap); - - gnrc_netdev2_init(_netdev2_eth_stack, TAP_MAC_STACKSIZE, - TAP_MAC_PRIO, "gnrc_netdev2_tap", &_gnrc_netdev2_tap); + for (int i = 0; i < NETDEV2_TAP_MAX; i++) { + const netdev2_tap_params_t *p = &netdev2_tap_params[i]; + DEBUG("Initializing netdev2_tap on TAP %s\n", *(p->tap_name)); + netdev2_tap_setup(&netdev2_tap[i], p); + gnrc_netdev2_eth_init(&_gnrc_netdev2_tap[i], (netdev2_t*)&netdev2_tap[i]); + + gnrc_netdev2_init(_netdev2_eth_stack[i], TAP_MAC_STACKSIZE, + TAP_MAC_PRIO, "gnrc_netdev2_tap", + &_gnrc_netdev2_tap[i]); + } } #else