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
This commit is contained in:
David Cermak 2022-09-23 08:59:37 +02:00 committed by David Čermák
parent fab39d2c4b
commit 678d7aadd9
10 changed files with 30 additions and 33 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}

View File

@ -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 */

View File

@ -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*/

View File

@ -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 */

View File

@ -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 */

View File

@ -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}"

View File

@ -16,10 +16,8 @@
#include "esp_wifi.h"
#include "esp_event.h"
#if CONFIG_ESP_NETIF_TCPIP_LWIP
#include <string.h>
#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

View File

@ -11,8 +11,6 @@
#include <mbedtls/build_info.h>
#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 */