lwip: Add missing null-checks, rename to vanilla-lwip

This commit is contained in:
David Cermak
2022-06-01 20:38:40 +02:00
parent 00377cf2e5
commit 7efcb5e625
14 changed files with 46 additions and 39 deletions

View File

@@ -29,12 +29,12 @@ 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_LWIP_ORIG
config ESP_NETIF_TCPIP_VANILLA_LWIP
bool "LwIP-orig"
depends on !LWIP_PPP_SUPPORT && !LWIP_IPV4_NAPT
depends on !LWIP_IPV4_NAPT
help
This choice sets the original, vanilla-lwIP as the TCP/IP stack.
Warning: Current implementation does not support PPP and NAPT features
Warning: Current implementation does not NAPT features
endchoice

View File

@@ -16,7 +16,7 @@
#include "esp_netif_private.h"
#include "esp_random.h"
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG)
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP)
#include "lwip/tcpip.h"
#include "lwip/dhcp.h"
@@ -567,7 +567,7 @@ static void esp_netif_lwip_remove(esp_netif_t *esp_netif)
}
netif_remove(esp_netif->lwip_netif);
#if ESP_GRATUITOUS_ARP
if (esp_netif->flags&ESP_NETIF_FLAG_GARP) {
if (esp_netif->flags & ESP_NETIF_FLAG_GARP) {
netif_unset_garp_flag(esp_netif->lwip_netif);
}
#endif
@@ -2081,4 +2081,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_LWIP_ORIG */
#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP || CONFIG_ESP_NETIF_TCPIP_VANILLA_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_LWIP_ORIG)
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_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_LWIP_ORIG)
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP)
struct esp_netif_netstack_lwip_vanilla_config {
err_t (*init_fn)(struct netif*);

View File

@@ -18,13 +18,15 @@
#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) {
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 */
@@ -34,8 +36,6 @@ static void netif_callback_fn(struct netif* netif, netif_nsc_reason_t reason, co
#endif /* #if LWIP_IPV6 */
}
static netif_ext_callback_t netif_callback = { .callback_fn = NULL, .next = NULL };
void set_lwip_netif_callback(void)
{
if (netif_callback.callback_fn == NULL ) {

View File

@@ -9,7 +9,7 @@
#include "esp_netif_lwip_internal.h"
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
#if defined(CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
#if PPP_SUPPORT
typedef struct ppp_pcb_s ppp_pcb;
@@ -44,7 +44,7 @@ void netif_unset_garp_flag(struct netif *netif);
#endif // ESP_GRATUITOUS_ARP
#else // !CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG and !CONFIG_ESP_NETIF_TCPIP_LWIP
#else // !CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP and !CONFIG_ESP_NETIF_TCPIP_LWIP
static inline void set_lwip_netif_callback(void) { }
@@ -52,4 +52,4 @@ static inline void remove_lwip_netif_callback(void) { }
static inline void netif_unset_garp_flag(struct netif *netif) {}
#endif // CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG or CONFIG_ESP_NETIF_TCPIP_LWIP
#endif // CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP or CONFIG_ESP_NETIF_TCPIP_LWIP

View File

@@ -6,6 +6,7 @@
#include "esp_wifi.h"
#include "esp_netif.h"
#include "esp_netif_net_stack.h"
#include "netif/wlanif.h"
#include "esp_log.h"
#include "esp_private/wifi.h"
#include "esp_wifi_netif.h"
@@ -100,10 +101,6 @@ bool esp_wifi_is_if_ready_when_started(wifi_netif_driver_t ifx)
#endif
}
void 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 esp_wifi_register_if_rxcb(wifi_netif_driver_t ifx, esp_netif_receive_t fn, void * arg)
{
if (ifx->base.netif != arg) {

View File

@@ -13,7 +13,7 @@
extern "C" {
#endif
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
#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); }
@@ -24,7 +24,7 @@ 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_LWIP_ORIG || CONFIG_ESP_NETIF_TCPIP_LWIP
#endif // CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP || CONFIG_ESP_NETIF_TCPIP_LWIP
#ifdef __cplusplus
}

View File

@@ -12,7 +12,7 @@
extern "C" {
#endif
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP_ORIG) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
#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); }
@@ -53,7 +53,7 @@ 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_LWIP_ORIG || CONFIG_ESP_NETIF_TCPIP_LWIP
#endif // CONFIG_ESP_NETIF_TCPIP_VANILLA_LWIP || CONFIG_ESP_NETIF_TCPIP_LWIP
#ifdef __cplusplus
}

View File

@@ -632,7 +632,7 @@ 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_LWIP_ORIG) || defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
#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.

View File

@@ -1,16 +1,8 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _WLAN_LWIP_IF_H_
@@ -19,13 +11,19 @@
#include "esp_wifi.h"
#include "lwip/err.h"
#include "lwip/netif.h"
#ifdef __cplusplus
extern "C" {
#endif
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);
void wlanif_input(void *netif, void *buffer, size_t len, void* eb);
err_t wlanif_init(struct netif *netif);

View File

@@ -26,6 +26,9 @@ bool dhcp_ip_addr_restore(struct netif *netif)
nvs_handle_t nvs;
char if_key[IF_KEY_SIZE];
bool err = false;
if (netif == NULL) {
return false;
}
struct dhcp *dhcp = netif_dhcp_data(netif);
uint32_t *ip_addr = &dhcp->offered_ip_addr.addr;
@@ -42,6 +45,9 @@ void dhcp_ip_addr_store(struct netif *netif)
{
nvs_handle_t nvs;
char if_key[IF_KEY_SIZE];
if (netif == NULL) {
return;
}
struct dhcp *dhcp = netif_dhcp_data(netif);
uint32_t ip_addr = dhcp->offered_ip_addr.addr;
@@ -56,6 +62,9 @@ void dhcp_ip_addr_erase(struct netif *netif)
{
nvs_handle_t nvs;
char if_key[IF_KEY_SIZE];
if (netif == NULL) {
return;
}
if (nvs_open(DHCP_NAMESPACE, NVS_READWRITE, &nvs) == ESP_OK) {
nvs_erase_key(nvs, gen_if_key(netif, if_key));
nvs_commit(nvs);

View File

@@ -77,18 +77,22 @@ low_level_init(struct netif *netif)
}
void set_wifi_netif(int wifi_inx, void* netif)
err_t set_wifi_netif(int wifi_inx, void* netif)
{
if (wifi_inx < 2) {
s_wifi_netifs[wifi_inx] = netif;
return ERR_OK;
}
return ERR_ARG;
}
static void wifi_pbuf_free(struct pbuf *p)
{
wifi_custom_pbuf_t* wifi_pbuf = (wifi_custom_pbuf_t*)p;
esp_wifi_internal_free_rx_buffer(wifi_pbuf->l2_buf);
if (wifi_pbuf) {
esp_wifi_internal_free_rx_buffer(wifi_pbuf->l2_buf);
}
mem_free(wifi_pbuf);
}

View File

@@ -974,7 +974,6 @@ components/lwip/port/esp32/include/debug/lwip_debug.h
components/lwip/port/esp32/include/netdb.h
components/lwip/port/esp32/include/netif/ethernetif.h
components/lwip/port/esp32/include/netif/openthreadif.h
components/lwip/port/esp32/include/netif/wlanif.h
components/lwip/port/esp32/include/netinet/in.h
components/lwip/port/esp32/include/netinet/tcp.h
components/lwip/port/esp32/include/sntp/sntp_get_set_time.h