lwip: Remove vanilla-lwip config until it's fully deployable

This commit is contained in:
David Cermak 2022-06-02 16:25:20 +02:00
parent 7efcb5e625
commit c67f4c2b4c
14 changed files with 116 additions and 199 deletions

View File

@ -13,7 +13,6 @@ set(srcs
"vfs_l2tap/esp_vfs_l2tap.c"
"lwip/esp_netif_lwip.c"
"lwip/esp_netif_lwip_defaults.c"
"lwip/esp_netif_lwip_orig.c"
"lwip/esp_netif_sta_list.c")
set(include_dirs "include")

View File

@ -29,13 +29,6 @@ menu "ESP NETIF Adapter"
Dummy implementation of esp-netif functionality which connects driver transmit
to receive function. This option is for testing purpose only
config ESP_NETIF_TCPIP_VANILLA_LWIP
bool "LwIP-orig"
depends on !LWIP_IPV4_NAPT
help
This choice sets the original, vanilla-lwIP as the TCP/IP stack.
Warning: Current implementation does not NAPT features
endchoice
config ESP_NETIF_L2_TAP

View File

@ -10,13 +10,12 @@
#include "esp_check.h"
#include "esp_netif_lwip_internal.h"
#include "esp_netif_lwip_orig.h"
#include "esp_netif.h"
#include "esp_netif_private.h"
#include "esp_random.h"
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP)
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
#include "lwip/tcpip.h"
#include "lwip/dhcp.h"
@ -26,6 +25,7 @@
#include "lwip/nd6.h"
#include "lwip/priv/tcpip_priv.h"
#include "lwip/netif.h"
#include "lwip/etharp.h"
#if LWIP_DNS /* don't build if not configured for use in lwipopts.h */
#include "lwip/dns.h"
#endif
@ -48,6 +48,8 @@
#define ESP_NETIF_HOSTNAME_MAX_SIZE 32
#define DHCP_CB_CHANGE (LWIP_NSC_IPV4_SETTINGS_CHANGED | LWIP_NSC_IPV4_ADDRESS_CHANGED | LWIP_NSC_IPV4_GATEWAY_CHANGED | LWIP_NSC_IPV4_NETMASK_CHANGED)
/**
* @brief lwip thread safe tcpip function utility macros
*/
@ -99,7 +101,75 @@ static const char *TAG = "esp_netif_lwip";
static bool tcpip_initialized = false;
static esp_netif_t *s_last_default_esp_netif = NULL;
static bool s_is_last_default_esp_netif_overridden = false;
static netif_ext_callback_t netif_callback = { .callback_fn = NULL, .next = NULL };
static void esp_netif_internal_dhcpc_cb(struct netif *netif);
#if LWIP_IPV6
static void esp_netif_internal_nd6_cb(struct netif *p_netif, uint8_t ip_index);
#endif /* LWIP_IPV6 */
static void netif_callback_fn(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args)
{
if (reason & DHCP_CB_CHANGE) {
esp_netif_internal_dhcpc_cb(netif);
}
#if LWIP_IPV6
if ((reason & LWIP_NSC_IPV6_ADDR_STATE_CHANGED) && (args != NULL)) {
s8_t addr_idx = args->ipv6_addr_state_changed.addr_index;
if (netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) {
/* address is valid -> call the callback function */
esp_netif_internal_nd6_cb(netif, addr_idx);
}
}
#endif /* #if LWIP_IPV6 */
}
static void set_lwip_netif_callback(void)
{
if (netif_callback.callback_fn == NULL ) {
netif_add_ext_callback(&netif_callback, netif_callback_fn);
}
}
static void remove_lwip_netif_callback(void)
{
netif_remove_ext_callback(&netif_callback);
memset(&netif_callback, 0, sizeof(netif_callback));
}
static void dns_clear_servers(bool keep_fallback)
{
u8_t numdns = 0;
for (numdns = 0; numdns < DNS_MAX_SERVERS; numdns ++) {
if (keep_fallback && numdns == DNS_FALLBACK_SERVER_INDEX) {
continue;
}
dns_setserver(numdns, NULL);
}
}
#ifdef CONFIG_LWIP_GARP_TMR_INTERVAL
static void netif_send_garp(void *arg)
{
struct netif *netif = arg;
etharp_gratuitous(netif);
sys_timeout(CONFIG_LWIP_GARP_TMR_INTERVAL*1000, netif_send_garp, netif);
}
static void netif_set_garp_flag(struct netif *netif)
{
sys_timeout(CONFIG_LWIP_GARP_TMR_INTERVAL*1000, netif_send_garp, netif);
}
static void netif_unset_garp_flag(struct netif *netif)
{
sys_untimeout(netif_send_garp, netif);
}
#endif // CONFIG_LWIP_GARP_TMR_INTERVAL
#if !LWIP_TCPIP_CORE_LOCKING
static sys_sem_t api_sync_sem = NULL;
@ -947,7 +1017,7 @@ static esp_err_t esp_netif_start_ip_lost_timer(esp_netif_t *esp_netif);
//
// DHCP:
//
void esp_netif_internal_dhcpc_cb(struct netif *netif)
static void esp_netif_internal_dhcpc_cb(struct netif *netif)
{
if (!netif) {
ESP_LOGD(TAG, "null netif=%p", netif);
@ -1145,8 +1215,6 @@ static esp_err_t esp_netif_dhcpc_start_api(esp_netif_api_msg_t *msg)
return ESP_ERR_ESP_NETIF_DHCPC_START_FAILED;
}
dhcp_set_cb(p_netif, esp_netif_internal_dhcpc_cb);
esp_netif->dhcpc_status = ESP_NETIF_DHCP_STARTED;
return ESP_OK;
} else {
@ -1647,7 +1715,7 @@ esp_ip6_addr_type_t esp_netif_ip6_get_addr_type(esp_ip6_addr_t* ip6_addr)
}
void esp_netif_internal_nd6_cb(struct netif *p_netif, uint8_t ip_index)
static void esp_netif_internal_nd6_cb(struct netif *p_netif, uint8_t ip_index)
{
ESP_LOGD(TAG, "%s lwip-netif:%p", __func__, p_netif);
if (!p_netif) {
@ -1684,7 +1752,6 @@ static esp_err_t esp_netif_create_ip6_linklocal_api(esp_netif_api_msg_t *msg)
struct netif *p_netif = esp_netif->lwip_netif;
if (p_netif != NULL && netif_is_up(p_netif)) {
netif_create_ip6_linklocal_address(p_netif, 1);
nd6_set_cb(p_netif, esp_netif_internal_nd6_cb);
return ESP_OK;
} else {
return ESP_FAIL;
@ -2081,4 +2148,4 @@ esp_err_t esp_netif_remove_ip6_address(esp_netif_t *esp_netif, const esp_ip6_add
#endif // CONFIG_LWIP_IPV6
#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP || CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP */
#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP */

View File

@ -8,7 +8,7 @@
#include "esp_netif_lwip_internal.h"
#include "esp_netif_lwip_ppp.h"
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP)
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
#include "netif/wlanif.h"
#include "netif/ethernetif.h"

View File

@ -12,7 +12,7 @@
#include "lwip/netif.h"
#include "dhcpserver/dhcpserver.h"
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP)
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
struct esp_netif_netstack_lwip_vanilla_config {
err_t (*init_fn)(struct netif*);

View File

@ -1,105 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <lwip/dns.h>
#include <lwip/timeouts.h>
#include <lwip/etharp.h>
#include "esp_check.h"
#include "esp_netif_lwip_internal.h"
#include "esp_netif_lwip_orig.h"
#include "esp_netif.h"
#include "esp_netif_private.h"
#define DHCP_CB_CHANGE (LWIP_NSC_IPV4_SETTINGS_CHANGED | LWIP_NSC_IPV4_ADDRESS_CHANGED | LWIP_NSC_IPV4_GATEWAY_CHANGED | LWIP_NSC_IPV4_NETMASK_CHANGED)
static netif_ext_callback_t netif_callback = { .callback_fn = NULL, .next = NULL };
static void netif_callback_fn(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args)
{
if (reason & DHCP_CB_CHANGE) {
esp_netif_internal_dhcpc_cb(netif);
}
#if LWIP_IPV6
if ((reason & LWIP_NSC_IPV6_ADDR_STATE_CHANGED) && (args != NULL)) {
s8_t addr_idx = args->ipv6_addr_state_changed.addr_index;
if (netif_ip6_addr_state(netif, addr_idx) & IP6_ADDR_VALID) {
/* address is valid -> call the callback function */
esp_netif_internal_nd6_cb(netif, addr_idx);
}
}
#endif /* #if LWIP_IPV6 */
}
void set_lwip_netif_callback(void)
{
if (netif_callback.callback_fn == NULL ) {
netif_add_ext_callback(&netif_callback, netif_callback_fn);
}
}
void remove_lwip_netif_callback(void)
{
netif_remove_ext_callback(&netif_callback);
memset(&netif_callback, 0, sizeof(netif_callback));
}
void dns_clear_servers(bool keep_fallback)
{
u8_t numdns = 0;
for (numdns = 0; numdns < DNS_MAX_SERVERS; numdns ++) {
if (keep_fallback && numdns == DNS_FALLBACK_SERVER_INDEX) {
continue;
}
dns_setserver(numdns, NULL);
}
}
#if PPP_SUPPORT && PPP_AUTH_SUPPORT
typedef struct {
struct tcpip_api_call_data call;
ppp_pcb *ppp;
u8_t authtype;
const char *user;
const char *passwd;
} set_auth_msg_t;
static err_t pppapi_do_ppp_set_auth(struct tcpip_api_call_data *m)
{
set_auth_msg_t *msg = (set_auth_msg_t *)m;
ppp_set_auth(msg->ppp, msg->authtype, msg->user, msg->passwd);
return ERR_OK;
}
void pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd)
{
set_auth_msg_t msg = { .ppp = pcb, .authtype = authtype, .user = user, .passwd = passwd};
tcpip_api_call(pppapi_do_ppp_set_auth, &msg.call);
}
#endif // PPP_SUPPORT && PPP_AUTH_SUPPORT
#ifdef CONFIG_LWIP_GARP_TMR_INTERVAL
void netif_send_garp(void *arg)
{
struct netif *netif = arg;
etharp_gratuitous(netif);
sys_timeout(CONFIG_LWIP_GARP_TMR_INTERVAL*1000, netif_send_garp, netif);
}
void netif_set_garp_flag(struct netif *netif)
{
sys_timeout(CONFIG_LWIP_GARP_TMR_INTERVAL*1000, netif_send_garp, netif);
}
void netif_unset_garp_flag(struct netif *netif)
{
sys_untimeout(netif_send_garp, netif);
}
#endif // CONFIG_LWIP_GARP_TMR_INTERVAL

View File

@ -1,55 +0,0 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_netif_lwip_internal.h"
#if defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
#if PPP_SUPPORT
typedef struct ppp_pcb_s ppp_pcb;
#endif
/**
* @brief Sets one extended lwip netif callbacks for all esp-netif
*/
void set_lwip_netif_callback(void);
void remove_lwip_netif_callback(void);
void esp_netif_internal_dhcpc_cb(struct netif *netif);
void esp_netif_internal_nd6_cb(struct netif *netif, uint8_t index);
static inline void dhcp_set_cb(struct netif *netif, void (*cb)(struct netif*)) { }
static inline void nd6_set_cb(struct netif *netif, void (*cb)(struct netif *netif, u8_t ip_index)) { }
void dns_clear_servers(bool keep_fallback);
#if PPP_SUPPORT && PPP_AUTH_SUPPORT
void pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd);
#endif
#if ESP_GRATUITOUS_ARP
void netif_set_garp_flag(struct netif *netif);
void netif_unset_garp_flag(struct netif *netif);
#endif // ESP_GRATUITOUS_ARP
#else // !CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP and !CONFIG_ESP_NETIF_TCPIP_LWIP
static inline void set_lwip_netif_callback(void) { }
static inline void remove_lwip_netif_callback(void) { }
static inline void netif_unset_garp_flag(struct netif *netif) {}
#endif // CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP or CONFIG_ESP_NETIF_TCPIP_LWIP

View File

@ -17,7 +17,6 @@
#include "esp_event.h"
#include "esp_netif_ppp.h"
#include "esp_netif_lwip_internal.h"
#include "esp_netif_lwip_orig.h"
#include <string.h>
#include "lwip/ip6_addr.h"
@ -37,6 +36,29 @@ typedef struct lwip_peer2peer_ctx {
ppp_pcb *ppp;
} lwip_peer2peer_ctx_t;
#if PPP_SUPPORT && PPP_AUTH_SUPPORT
typedef struct {
struct tcpip_api_call_data call;
ppp_pcb *ppp;
u8_t authtype;
const char *user;
const char *passwd;
} set_auth_msg_t;
static err_t pppapi_do_ppp_set_auth(struct tcpip_api_call_data *m)
{
set_auth_msg_t *msg = (set_auth_msg_t *)m;
ppp_set_auth(msg->ppp, msg->authtype, msg->user, msg->passwd);
return ERR_OK;
}
static void pppapi_set_auth(ppp_pcb *pcb, u8_t authtype, const char *user, const char *passwd)
{
set_auth_msg_t msg = { .ppp = pcb, .authtype = authtype, .user = user, .passwd = passwd};
tcpip_api_call(pppapi_do_ppp_set_auth, &msg.call);
}
#endif // PPP_SUPPORT && PPP_AUTH_SUPPORT
/**
* @brief lwip callback from PPP client used here to produce PPP error related events,
* as well as some IP events

View File

@ -13,8 +13,6 @@
extern "C" {
#endif
#if defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
static inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop)
{ return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); }
static inline struct hostent *gethostbyname(const char *name)
@ -24,8 +22,6 @@ static inline void freeaddrinfo(struct addrinfo *ai)
static inline int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res)
{ return lwip_getaddrinfo(nodename, servname, hints, res); }
#endif // CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP || CONFIG_ESP_NETIF_TCPIP_LWIP
#ifdef __cplusplus
}
#endif

View File

@ -12,8 +12,6 @@
extern "C" {
#endif
#if defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
static inline int accept(int s,struct sockaddr *addr,socklen_t *addrlen)
{ return lwip_accept(s,addr,addrlen); }
static inline int bind(int s,const struct sockaddr *name, socklen_t namelen)
@ -53,8 +51,6 @@ static inline const char *inet_ntop(int af, const void *src, char *dst, socklen_
static inline int inet_pton(int af, const char *src, void *dst)
{ return lwip_inet_pton(af, src, dst); }
#endif // CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP || CONFIG_ESP_NETIF_TCPIP_LWIP
#ifdef __cplusplus
}
#endif

View File

@ -632,7 +632,6 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
#define LWIP_NETIF_STATUS_CALLBACK 0
#endif
#if defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
/**
* LWIP_NETIF_EXT_STATUS_CALLBACK==1: Support an extended callback function
* for several netif related event that supports multiple subscribers.
@ -641,8 +640,6 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
* to provide netif related events on IP4/IP6 address/status changes
*/
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
#endif
/**
* LWIP_NETIF_TX_SINGLE_PBUF: if this is set to 1, lwIP *tries* to put all data
@ -1440,13 +1437,13 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min)
* allocate memory for lwip in SPIRAM firstly. If failed, try to allocate
* internal memory then.
*/
#if CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST
#if CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP
#define mem_clib_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
#define mem_clib_calloc(n, size) heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
#else /* !CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST */
#else /* !CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP */
#define mem_clib_malloc malloc
#define mem_clib_calloc calloc
#endif /* CONFIG_WIFI_LWIP_ALLOCATION_FROM_SPIRAM_FIRST */
#endif /* CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP */
#ifdef __cplusplus
}

View File

@ -21,8 +21,8 @@ extern "C" {
err_t wlanif_init_ap(struct netif *netif);
err_t wlanif_init_sta(struct netif *netif);
err_t set_wifi_netif(int wifi_inx, void* netif);
esp_err_t wifi_rxcb_sta(void *buffer, uint16_t len, void *eb);
esp_err_t wifi_rxcb_ap(void *buffer, uint16_t len, void *eb);
esp_err_t wifi_rxcb_sta(void *buffer, uint16_t len, void *l2_buff);
esp_err_t wifi_rxcb_ap(void *buffer, uint16_t len, void *l2_buff);
void wlanif_input(void *netif, void *buffer, size_t len, void* eb);

View File

@ -244,9 +244,9 @@ sta_output(struct netif *netif, struct pbuf *p)
LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
if (q != NULL) {
pbuf_copy(q, p);
pbuf_copy(q, p);
} else {
return ERR_MEM;
return ERR_MEM;
}
ret = esp_wifi_internal_tx(WIFI_IF_STA, q->payload, q->len);
pbuf_free(q);
@ -276,9 +276,9 @@ ap_output(struct netif *netif, struct pbuf *p)
LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
if (q != NULL) {
pbuf_copy(q, p);
pbuf_copy(q, p);
} else {
return ERR_MEM;
return ERR_MEM;
}
ret = esp_wifi_internal_tx(WIFI_IF_AP, q->payload, q->len);
pbuf_free(q);

View File

@ -24,6 +24,13 @@ _Static_assert(MAX_FDS >= CONFIG_LWIP_MAX_SOCKETS, "MAX_FDS < CONFIG_LWIP_MAX_SO
#ifdef CONFIG_VFS_SUPPORT_SELECT
/**
* @brief This function is implemented only in FreeRTOS port (ingroup sys_sem)
* and has no official API counterpart in lwip's sys.h declarations
* Signals a semaphore from ISR
* @param sem the semaphore to signal
* @return 1 if the signal has caused a high-prio task to unblock (pxHigherPriorityTaskWoken)
*/
int sys_sem_signal_isr(sys_sem_t *sem);
static void lwip_stop_socket_select(void *sem)