1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pkg/lwip: Start rework of netif initialisation

Use separate files with auto_init
Proof of concept with only moving netdev_tap
This commit is contained in:
Erik Ekman 2021-03-06 13:43:14 +01:00
parent 8ae782b98d
commit 2816ade5f8
8 changed files with 148 additions and 24 deletions

View File

@ -63,6 +63,7 @@ ifneq (,$(filter lwip_%,$(USEMODULE)))
USEMODULE += lwip_contrib
USEMODULE += lwip_core
USEMODULE += lwip_netif
USEMODULE += lwip_netif_init_devs
USEMODULE += netdev
ifeq (,$(filter lwip_ipv4 lwip_ipv6,$(USEMODULE)))
USEMODULE += lwip_ipv4

View File

@ -29,6 +29,9 @@ endif
ifneq (,$(filter lwip_netdev,$(USEMODULE)))
DIRS += $(RIOTBASE)/pkg/lwip/contrib/netdev
endif
ifneq (,$(filter lwip_netif_init_devs,$(USEMODULE)))
DIRS += $(RIOTBASE)/pkg/lwip/init_devs
endif
ifneq (,$(filter lwip_sock,$(USEMODULE)))
ifneq (,$(filter lwip_ipv6,$(USEMODULE)))
CFLAGS += -DSOCK_HAS_IPV6

View File

@ -11,6 +11,7 @@
*
* @file
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @author Erik Ekman <eekman@google.com>
*/
#include "kernel_defines.h"
@ -21,11 +22,6 @@
#include "lwip/netifapi.h"
#include "netif/lowpan6.h"
#ifdef MODULE_NETDEV_TAP
#include "netdev_tap.h"
#include "netdev_tap_params.h"
#endif
#ifdef MODULE_AT86RF2XX
#include "at86rf2xx.h"
#include "at86rf2xx_params.h"
@ -76,15 +72,12 @@
#endif
#include "lwip.h"
#include "lwip_init_devs.h"
#define ENABLE_DEBUG 0
#include "debug.h"
#ifdef MODULE_NETDEV_TAP
#define LWIP_NETIF_NUMOF (NETDEV_TAP_MAX)
#endif
#ifdef MODULE_AT86RF2XX /* is mutual exclusive with above ifdef */
#ifdef MODULE_AT86RF2XX
#define LWIP_NETIF_NUMOF ARRAY_SIZE(at86rf2xx_params)
#endif
@ -129,10 +122,6 @@
static struct netif netif[LWIP_NETIF_NUMOF];
#endif
#ifdef MODULE_NETDEV_TAP
static netdev_tap_t netdev_taps[LWIP_NETIF_NUMOF];
#endif
#ifdef MODULE_AT86RF2XX
static at86rf2xx_t at86rf2xx_devs[LWIP_NETIF_NUMOF];
#endif
@ -179,18 +168,10 @@ static netdev_ieee802154_submac_t nrf802154_netdev;
void lwip_bootstrap(void)
{
lwip_netif_init_devs();
/* TODO: do for every eligible netdev */
#ifdef LWIP_NETIF_NUMOF
#ifdef MODULE_NETDEV_TAP
for (unsigned i = 0; i < LWIP_NETIF_NUMOF; i++) {
netdev_tap_setup(&netdev_taps[i], &netdev_tap_params[i]);
if (netif_add_noaddr(&netif[i], &netdev_taps[i].netdev, lwip_netdev_init,
tcpip_input) == NULL) {
DEBUG("Could not add netdev_tap device\n");
return;
}
}
#elif defined(MODULE_MRF24J40)
#ifdef MODULE_MRF24J40
for (unsigned i = 0; i < LWIP_NETIF_NUMOF; i++) {
mrf24j40_setup(&mrf24j40_devs[i], &mrf24j40_params[i], i);
if (netif_add_noaddr(&netif[i], &mrf24j40_devs[i].netdev.netdev, lwip_netdev_init,

View File

@ -0,0 +1,47 @@
/*
* Copyright (C) Google LLC
*
* 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 sys_auto_init_lwip_netif
*
* @{
*
* @file
* @brief Helpers for simplified network setup
*
* @author Erik Ekman <eekman@google.com>
*/
#ifndef LWIP_INIT_DEVS_H
#define LWIP_INIT_DEVS_H
#ifdef __cplusplus
extern "C" {
#endif
#include "lwip/netif.h"
#include "net/netdev.h"
void lwip_netif_init_devs(void);
/**
* @brief Adds an Ethernet netif using the supplied netdev.
*
* @param netif pointer to the interface to be added
* @param state pointer to the netdev for the interface
*
* The netif will be set up using the `lwip_netdev_init` helper.
*/
struct netif *lwip_add_ethernet(struct netif *netif, netdev_t *state);
#ifdef __cplusplus
}
#endif
#endif /* LWIP_INIT_DEVS_H */
/** @} */

View File

@ -0,0 +1,3 @@
MODULE = lwip_netif_init_devs
include $(RIOTMAKE)/auto_init.inc.mk

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 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 sys_auto_init_lwip_netif
* @{
*
* @file
* @brief Auto initialization for TAP network interfaces
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
* @author Erik Ekman <eekman@google.com>
*/
#include "netdev_tap.h"
#include "netdev_tap_params.h"
#include "lwip_init_devs.h"
#define ENABLE_DEBUG 0
#include "debug.h"
#define NETIF_TAP_NUMOF (NETDEV_TAP_MAX)
static struct netif netif[NETIF_TAP_NUMOF];
static netdev_tap_t netdev_taps[NETIF_TAP_NUMOF];
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]);
if (lwip_add_ethernet(&netif[i], &netdev_taps[i].netdev) == NULL) {
DEBUG("Could not add netdev_tap device\n");
return;
}
}
}
/** @} */

38
pkg/lwip/init_devs/init.c Normal file
View File

@ -0,0 +1,38 @@
/*
* Copyright (C) Google LLC
*
* 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 sys_auto_init_lwip_netif
* @{
*
* @file
* @brief Initializes the supported network interfaces for lwIP
* @author Erik Ekman <eekman@google.com>
*/
#include "kernel_defines.h"
#include "lwip_init_devs.h"
#include "lwip/netif/netdev.h"
/**
* @brief Initializes network interfaces
*/
void lwip_netif_init_devs(void)
{
if (IS_USED(MODULE_NETDEV_TAP)) {
extern void auto_init_netdev_tap(void);
auto_init_netdev_tap();
}
}
struct netif *lwip_add_ethernet(struct netif *netif, netdev_t *state)
{
return netif_add_noaddr(netif, state, lwip_netdev_init, tcpip_input);
}
/**@}*/

View File

@ -78,6 +78,14 @@
* @see @ref net_gnrc_netif, @ref sys_auto_init
*/
/**
* @defgroup sys_auto_init_lwip_netif lwIP netif drivers auto-initialization
* @ingroup sys_auto_init
* @brief Provides auto-initialization of network device drivers for lwIP
*
* @see @ref pkg_lwip, @ref sys_auto_init
*/
/**
* @defgroup sys_auto_init_multimedia Multimedia driver auto-initialization
* @ingroup sys_auto_init