diff --git a/components/esp_netif/Kconfig b/components/esp_netif/Kconfig index bfa3d54bca..1c17ff2e94 100644 --- a/components/esp_netif/Kconfig +++ b/components/esp_netif/Kconfig @@ -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 diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index a3fef0a31a..5354cbcc28 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -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 */ diff --git a/components/esp_netif/lwip/esp_netif_lwip_defaults.c b/components/esp_netif/lwip/esp_netif_lwip_defaults.c index c57445da56..6239a5b41b 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_defaults.c +++ b/components/esp_netif/lwip/esp_netif_lwip_defaults.c @@ -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" diff --git a/components/esp_netif/lwip/esp_netif_lwip_internal.h b/components/esp_netif/lwip/esp_netif_lwip_internal.h index e19163c75a..c6996c7700 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_internal.h +++ b/components/esp_netif/lwip/esp_netif_lwip_internal.h @@ -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*); diff --git a/components/esp_netif/lwip/esp_netif_lwip_orig.c b/components/esp_netif/lwip/esp_netif_lwip_orig.c index 5610df4e00..4cce66a614 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_orig.c +++ b/components/esp_netif/lwip/esp_netif_lwip_orig.c @@ -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 ) { diff --git a/components/esp_netif/lwip/esp_netif_lwip_orig.h b/components/esp_netif/lwip/esp_netif_lwip_orig.h index d39e6a17e0..f5560e055e 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_orig.h +++ b/components/esp_netif/lwip/esp_netif_lwip_orig.h @@ -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 diff --git a/components/esp_wifi/src/wifi_netif.c b/components/esp_wifi/src/wifi_netif.c index 7683dfa62f..9b69dc35e3 100644 --- a/components/esp_wifi/src/wifi_netif.c +++ b/components/esp_wifi/src/wifi_netif.c @@ -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) { diff --git a/components/lwip/include/lwip/netdb.h b/components/lwip/include/lwip/netdb.h index cc395bac61..c058e5354b 100644 --- a/components/lwip/include/lwip/netdb.h +++ b/components/lwip/include/lwip/netdb.h @@ -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 } diff --git a/components/lwip/include/lwip/sockets.h b/components/lwip/include/lwip/sockets.h index 1b475e3719..cbb1f66bc2 100644 --- a/components/lwip/include/lwip/sockets.h +++ b/components/lwip/include/lwip/sockets.h @@ -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 } diff --git a/components/lwip/port/esp32/include/lwipopts.h b/components/lwip/port/esp32/include/lwipopts.h index c539cbe0c7..f66c4db1b6 100644 --- a/components/lwip/port/esp32/include/lwipopts.h +++ b/components/lwip/port/esp32/include/lwipopts.h @@ -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. diff --git a/components/lwip/port/esp32/include/netif/wlanif.h b/components/lwip/port/esp32/include/netif/wlanif.h index 4535b6cb51..b8e9c8b32e 100644 --- a/components/lwip/port/esp32/include/netif/wlanif.h +++ b/components/lwip/port/esp32/include/netif/wlanif.h @@ -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); diff --git a/components/lwip/port/esp32/netif/dhcp_state.c b/components/lwip/port/esp32/netif/dhcp_state.c index 10b0981219..b441c6df1f 100644 --- a/components/lwip/port/esp32/netif/dhcp_state.c +++ b/components/lwip/port/esp32/netif/dhcp_state.c @@ -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); diff --git a/components/lwip/port/esp32/netif/wlanif.c b/components/lwip/port/esp32/netif/wlanif.c index ae0c888b1e..4824f13751 100644 --- a/components/lwip/port/esp32/netif/wlanif.c +++ b/components/lwip/port/esp32/netif/wlanif.c @@ -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); } diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 5993d748d3..da481e711f 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -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