From 678d7aadd97c4a93cb6564067ac0f47e3e90cbfa Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 23 Sep 2022 08:59:37 +0200 Subject: [PATCH] esp-netif/lwip: Introduce TCP/IP stack has BSD API * This variable is automatically selected when lwip stack is chosen * This commit also fixes lwip loopback configuration --- components/esp_netif/Kconfig | 4 ++++ .../esp_netif/include/lwip/esp_netif_net_stack.h | 8 ++++++-- components/esp_netif/loopback/esp_netif_loopback.c | 13 +++++++++---- components/esp_netif/lwip/esp_netif_lwip.c | 4 ---- components/esp_netif/lwip/esp_netif_lwip_defaults.c | 10 +++++----- components/esp_netif/lwip/esp_netif_lwip_internal.h | 4 ---- components/esp_netif/lwip/esp_netif_lwip_ppp.c | 4 ---- components/esp_wifi/CMakeLists.txt | 6 +++++- components/esp_wifi/src/smartconfig_ack.c | 6 +----- components/mbedtls/port/net_sockets.c | 4 ---- 10 files changed, 30 insertions(+), 33 deletions(-) diff --git a/components/esp_netif/Kconfig b/components/esp_netif/Kconfig index 005ea75687..e79907b2fc 100644 --- a/components/esp_netif/Kconfig +++ b/components/esp_netif/Kconfig @@ -20,6 +20,7 @@ menu "ESP NETIF Adapter" Choose the TCP/IP Stack to work, for example, LwIP, uIP, etc. config ESP_NETIF_TCPIP_LWIP bool "LwIP" + select ESP_NETIF_USES_TCPIP_WITH_BSD_API help lwIP is a small independent implementation of the TCP/IP protocol suite. @@ -31,6 +32,9 @@ menu "ESP NETIF Adapter" endchoice + config ESP_NETIF_USES_TCPIP_WITH_BSD_API + bool # Set to true if the chosen TCP/IP stack provides BSD socket API + config ESP_NETIF_L2_TAP bool "Enable netif L2 TAP support" select ETH_TRANSMIT_MUTEX diff --git a/components/esp_netif/include/lwip/esp_netif_net_stack.h b/components/esp_netif/include/lwip/esp_netif_net_stack.h index 52790d72ac..0550b82e87 100644 --- a/components/esp_netif/include/lwip/esp_netif_net_stack.h +++ b/components/esp_netif/include/lwip/esp_netif_net_stack.h @@ -10,7 +10,9 @@ #include "lwip/netif.h" #include "esp_netif_ppp.h" -#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) +#ifdef __cplusplus +extern "C" { +#endif typedef err_t (*init_fn_t)(struct netif*); typedef void (*input_fn_t)(void *netif, void *buffer, size_t len, void *eb); @@ -72,4 +74,6 @@ err_t wlanif_init_sta(struct netif *netif); */ void wlanif_input(void *h, void *buffer, size_t len, void* l2_buff); -#endif // CONFIG_ESP_NETIF_TCPIP_LWIP +#ifdef __cplusplus +} +#endif diff --git a/components/esp_netif/loopback/esp_netif_loopback.c b/components/esp_netif/loopback/esp_netif_loopback.c index c328a37e5e..e3fbb71921 100644 --- a/components/esp_netif/loopback/esp_netif_loopback.c +++ b/components/esp_netif/loopback/esp_netif_loopback.c @@ -32,6 +32,11 @@ static bool s_netif_up = false; * * */ + +#ifndef NETIF_MAX_HWADDR_LEN +#define NETIF_MAX_HWADDR_LEN 6U +#endif + struct esp_netif_obj { // default interface addresses uint8_t mac[NETIF_MAX_HWADDR_LEN]; @@ -112,9 +117,9 @@ static esp_err_t esp_netif_init_configuration(esp_netif_t *esp_netif, const esp_ // Configure general esp-netif properties memcpy(esp_netif->mac, cfg->base->mac, NETIF_MAX_HWADDR_LEN); if (cfg->base->ip_info == NULL) { - ip4_addr_set_zero(&esp_netif->ip_info->ip); - ip4_addr_set_zero(&esp_netif->ip_info->gw); - ip4_addr_set_zero(&esp_netif->ip_info->netmask); + esp_netif->ip_info->ip.addr = 0; + esp_netif->ip_info->gw.addr = 0; + esp_netif->ip_info->netmask.addr = 0; } else { memcpy(esp_netif->ip_info, cfg->base->ip_info, sizeof(esp_netif_ip_info_t)); } @@ -450,7 +455,7 @@ esp_err_t esp_netif_leave_ip6_multicast_group(esp_netif_t *esp_netif, const esp_ return ESP_ERR_NOT_SUPPORTED; } -esp_err_t esp_netif_add_ip6_address(esp_netif_t *esp_netif, const esp_ip6_addr_t *addr, uint8_t preference) +esp_err_t esp_netif_add_ip6_address(esp_netif_t *esp_netif, const ip_event_add_ip6_t *addr) { return ESP_ERR_NOT_SUPPORTED; } diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 53dff2ba69..49070a498d 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -17,8 +17,6 @@ #include "esp_netif_private.h" #include "esp_random.h" -#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) - #include "lwip/tcpip.h" #include "lwip/dhcp.h" #include "lwip/ip_addr.h" @@ -2275,5 +2273,3 @@ esp_err_t esp_netif_remove_ip6_address(esp_netif_t *esp_netif, const esp_ip6_add _RUN_IN_LWIP_TASK(esp_netif_remove_ip6_address_api, esp_netif, addr) #endif // CONFIG_LWIP_IPV6 - -#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP */ diff --git a/components/esp_netif/lwip/esp_netif_lwip_defaults.c b/components/esp_netif/lwip/esp_netif_lwip_defaults.c index 14c527f788..97009d3d57 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_defaults.c +++ b/components/esp_netif/lwip/esp_netif_lwip_defaults.c @@ -7,9 +7,9 @@ #include "esp_netif.h" #include "esp_netif_lwip_internal.h" #include "lwip/esp_netif_net_stack.h" +#if defined(CONFIG_PPP_SUPPORT) #include "esp_netif_lwip_ppp.h" - -#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) +#endif #if CONFIG_ESP_NETIF_BRIDGE_EN #include "netif/bridgeif.h" @@ -48,6 +48,7 @@ static const struct esp_netif_netstack_config s_wifi_netif_config_sta = { } }; +#if defined(CONFIG_PPP_SUPPORT) static const struct esp_netif_netstack_config s_netif_config_ppp = { .lwip_ppp = { .input_fn = esp_netif_lwip_ppp_input, @@ -57,10 +58,9 @@ static const struct esp_netif_netstack_config s_netif_config_ppp = { } } }; +const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_ppp = &s_netif_config_ppp; +#endif // CONFIG_PPP_SUPPORT const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_eth = &s_eth_netif_config; const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_sta = &s_wifi_netif_config_sta; const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_ap = &s_wifi_netif_config_ap; -const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_ppp = &s_netif_config_ppp; - -#endif /*CONFIG_ESP_NETIF_TCPIP_LWIP*/ diff --git a/components/esp_netif/lwip/esp_netif_lwip_internal.h b/components/esp_netif/lwip/esp_netif_lwip_internal.h index 332a4f822d..3316bf19f3 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_internal.h +++ b/components/esp_netif/lwip/esp_netif_lwip_internal.h @@ -11,8 +11,6 @@ #include "lwip/netif.h" #include "dhcpserver/dhcpserver.h" -#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP) - struct esp_netif_api_msg_s; typedef int (*esp_netif_api_fn)(struct esp_netif_api_msg_s *msg); @@ -108,5 +106,3 @@ struct esp_netif_obj { uint8_t max_ports; #endif // CONFIG_ESP_NETIF_BRIDGE_EN }; - -#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP */ diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.c b/components/esp_netif/lwip/esp_netif_lwip_ppp.c index 67175df4d9..fc27232eff 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_ppp.c +++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.c @@ -7,8 +7,6 @@ #include "esp_netif.h" -#ifdef CONFIG_ESP_NETIF_TCPIP_LWIP - #include "lwip/dns.h" #include "netif/ppp/pppapi.h" #include "netif/ppp/pppos.h" @@ -325,5 +323,3 @@ esp_err_t esp_netif_ppp_get_params(esp_netif_t *netif, esp_netif_ppp_config_t *c config->ppp_error_event_enabled = obj->ppp_error_event_enabled; return ESP_OK; } - -#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP */ diff --git a/components/esp_wifi/CMakeLists.txt b/components/esp_wifi/CMakeLists.txt index 5722e0a00c..b85208d5d8 100644 --- a/components/esp_wifi/CMakeLists.txt +++ b/components/esp_wifi/CMakeLists.txt @@ -20,12 +20,16 @@ if(CONFIG_ESP32_WIFI_ENABLED) "src/coexist.c" "src/mesh_event.c" "src/smartconfig.c" - "src/smartconfig_ack.c" "src/wifi_init.c" "src/wifi_default.c" "src/wifi_netif.c" "src/wifi_default_ap.c" "${idf_target}/esp_adapter.c") + + if(CONFIG_ESP_NETIF_USES_TCPIP_WITH_BSD_API) + list(APPEND srcs + "src/smartconfig_ack.c") + endif() endif() idf_component_register(SRCS "${srcs}" diff --git a/components/esp_wifi/src/smartconfig_ack.c b/components/esp_wifi/src/smartconfig_ack.c index 48949267cf..0247faa229 100644 --- a/components/esp_wifi/src/smartconfig_ack.c +++ b/components/esp_wifi/src/smartconfig_ack.c @@ -16,10 +16,8 @@ #include "esp_wifi.h" #include "esp_event.h" -#if CONFIG_ESP_NETIF_TCPIP_LWIP - #include -#include "lwip/sockets.h" +#include "sys/socket.h" #include "esp_smartconfig.h" #include "smartconfig_ack.h" @@ -231,5 +229,3 @@ void sc_send_ack_stop(void) { s_sc_ack_send = false; } - -#endif diff --git a/components/mbedtls/port/net_sockets.c b/components/mbedtls/port/net_sockets.c index 102b9c8025..aa6455497b 100644 --- a/components/mbedtls/port/net_sockets.c +++ b/components/mbedtls/port/net_sockets.c @@ -11,8 +11,6 @@ #include -#ifdef CONFIG_ESP_NETIF_TCPIP_LWIP - #if !defined(MBEDTLS_NET_C) #if defined(MBEDTLS_PLATFORM_C) @@ -427,5 +425,3 @@ void mbedtls_net_free( mbedtls_net_context *ctx ) } #endif /* MBEDTLS_NET_C */ - -#endif /* CONFIG_ESP_NETIF_TCPIP_LWIP */