esp_netif: Make esp_netif_receive() return value configurable

pull/11275/head
David Cermak 2023-03-27 12:54:25 +02:00
rodzic 8855ddf044
commit 7d6241e761
9 zmienionych plików z 44 dodań i 20 usunięć

Wyświetl plik

@ -35,6 +35,14 @@ menu "ESP NETIF Adapter"
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_RECEIVE_REPORT_ERRORS
bool "Use esp_err_t to report errors from esp_netif_receive"
default n
help
Enable if esp_netif_receive() should return error code. This is useful to inform upper layers
that packet input to TCP/IP stack failed, so the upper layers could implement flow control.
This option is disabled by default due to backward compatibility and will be enabled in v6.0 (IDF-7194)
config ESP_NETIF_L2_TAP
bool "Enable netif L2 TAP support"
select ETH_TRANSMIT_MUTEX

Wyświetl plik

@ -14,8 +14,16 @@
extern "C" {
#endif
#ifdef CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS
typedef esp_err_t esp_netif_recv_ret_t;
#define ESP_NETIF_OPTIONAL_RETURN_CODE(expr) expr
#else
typedef void esp_netif_recv_ret_t;
#define ESP_NETIF_OPTIONAL_RETURN_CODE(expr)
#endif // CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS
typedef err_t (*init_fn_t)(struct netif*);
typedef esp_err_t (*input_fn_t)(void *netif, void *buffer, size_t len, void *eb);
typedef esp_netif_recv_ret_t (*input_fn_t)(void *netif, void *buffer, size_t len, void *eb);
struct esp_netif_netstack_lwip_vanilla_config {
init_fn_t init_fn;
@ -49,7 +57,7 @@ err_t ethernetif_init(struct netif *netif);
* @param len Input buffer size
* @param l2_buff External buffer pointer (to be passed to custom input-buffer free)
*/
esp_err_t ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff);
esp_netif_recv_ret_t ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff);
/**
* @brief LWIP's network stack init function for WiFi (AP)
@ -79,7 +87,7 @@ err_t wlanif_init_nan(struct netif *netif);
* @param len Input buffer size
* @param l2_buff External buffer pointer (to be passed to custom input-buffer free)
*/
esp_err_t wlanif_input(void *h, void *buffer, size_t len, void* l2_buff);
esp_netif_recv_ret_t wlanif_input(void *h, void *buffer, size_t len, void* l2_buff);
#ifdef __cplusplus
}

Wyświetl plik

@ -1218,7 +1218,12 @@ esp_err_t esp_netif_transmit_wrap(esp_netif_t *esp_netif, void *data, size_t len
esp_err_t esp_netif_receive(esp_netif_t *esp_netif, void *buffer, size_t len, void *eb)
{
#ifdef CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS
return esp_netif->lwip_input_fn(esp_netif->netif_handle, buffer, len, eb);
#else
esp_netif->lwip_input_fn(esp_netif->netif_handle, buffer, len, eb);
return ESP_OK;
#endif
}
#if CONFIG_LWIP_IPV4

Wyświetl plik

@ -9,6 +9,7 @@
#include "esp_netif.h"
#include "esp_netif_ppp.h"
#include "lwip/netif.h"
#include "lwip/esp_netif_net_stack.h"
#ifdef CONFIG_LWIP_DHCPS
#include "dhcpserver/dhcpserver.h"
#endif
@ -76,7 +77,7 @@ struct esp_netif_obj {
// lwip netif related
struct netif *lwip_netif;
err_t (*lwip_init_fn)(struct netif*);
esp_err_t (*lwip_input_fn)(void *input_netif_handle, void *buffer, size_t len, void *eb);
esp_netif_recv_ret_t (*lwip_input_fn)(void *input_netif_handle, void *buffer, size_t len, void *eb);
void * netif_handle; // netif impl context (either vanilla lwip-netif or ppp_pcb)
netif_related_data_t *related_data; // holds additional data for specific netifs
#if ESP_DHCPS

Wyświetl plik

@ -269,15 +269,15 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif)
return ESP_OK;
}
esp_err_t esp_netif_lwip_ppp_input(void *ppp_ctx, void *buffer, size_t len, void *eb)
esp_netif_recv_ret_t esp_netif_lwip_ppp_input(void *ppp_ctx, void *buffer, size_t len, void *eb)
{
struct lwip_peer2peer_ctx * obj = ppp_ctx;
err_t ret = pppos_input_tcpip(obj->ppp, buffer, len);
if (ret != ERR_OK) {
ESP_LOGE(TAG, "pppos_input_tcpip failed with %d", ret);
return ESP_FAIL;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_FAIL);
}
return ESP_OK;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_OK);
}
esp_err_t esp_netif_stop_ppp(netif_related_data_t *netif_related)

Wyświetl plik

@ -40,7 +40,7 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif);
* @return
* - ESP_OK on success
*/
esp_err_t esp_netif_lwip_ppp_input(void *ppp, void *buffer, size_t len, void *eb);
esp_netif_recv_ret_t esp_netif_lwip_ppp_input(void *ppp, void *buffer, size_t len, void *eb);
/**
* @brief Destroys the ppp netif object

Wyświetl plik

@ -18,9 +18,10 @@
#include "lwip/ethip6.h"
#include "netif/etharp.h"
#include "esp_compiler.h"
#include "esp_netif.h"
#include "esp_netif_net_stack.h"
#include "esp_compiler.h"
#include "lwip/esp_netif_net_stack.h"
#include "lwip/esp_pbuf_ref.h"
/* Define those to better describe your network interface. */
@ -115,7 +116,7 @@ static err_t ethernet_low_level_output(struct netif *netif, struct pbuf *p)
* @param len length of buffer
* @param l2_buff Placeholder for a separate L2 buffer. Unused for ethernet interface
*/
esp_err_t ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff)
esp_netif_recv_ret_t ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff)
{
struct netif *netif = h;
esp_netif_t *esp_netif = esp_netif_get_handle_from_netif_impl(netif);
@ -125,23 +126,23 @@ esp_err_t ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff)
if (buffer) {
esp_netif_free_rx_buffer(esp_netif, buffer);
}
return ESP_FAIL;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_FAIL);
}
/* allocate custom pbuf to hold */
p = esp_pbuf_allocate(esp_netif, buffer, len, buffer);
if (p == NULL) {
esp_netif_free_rx_buffer(esp_netif, buffer);
return ESP_ERR_NO_MEM;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_ERR_NO_MEM);
}
/* full packet send to tcpip_thread to process */
if (unlikely(netif->input(p, netif) != ERR_OK)) {
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
pbuf_free(p);
return ESP_FAIL;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_FAIL);
}
/* the pbuf will be free in upper layer, eg: ethernet_input */
return ESP_OK;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_OK);
}
/**

Wyświetl plik

@ -126,7 +126,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
* @param len length of buffer
* @param l2_buff wlan's L2 buffer pointer
*/
esp_err_t wlanif_input(void *h, void *buffer, size_t len, void* l2_buff)
esp_netif_recv_ret_t wlanif_input(void *h, void *buffer, size_t len, void* l2_buff)
{
struct netif * netif = h;
esp_netif_t *esp_netif = netif->state;
@ -136,14 +136,14 @@ esp_err_t wlanif_input(void *h, void *buffer, size_t len, void* l2_buff)
if (l2_buff) {
esp_netif_free_rx_buffer(esp_netif, l2_buff);
}
return ESP_FAIL;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_FAIL);
}
#ifdef CONFIG_LWIP_L2_TO_L3_COPY
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
if (p == NULL) {
esp_netif_free_rx_buffer(esp_netif, l2_buff);
return ESP_ERR_NO_MEM;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_ERR_NO_MEM);
}
memcpy(p->payload, buffer, len);
esp_netif_free_rx_buffer(esp_netif, l2_buff);
@ -151,7 +151,7 @@ esp_err_t wlanif_input(void *h, void *buffer, size_t len, void* l2_buff)
p = esp_pbuf_allocate(esp_netif, buffer, len, l2_buff);
if (p == NULL) {
esp_netif_free_rx_buffer(esp_netif, l2_buff);
return ESP_ERR_NO_MEM;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_ERR_NO_MEM);
}
#endif
@ -160,9 +160,9 @@ esp_err_t wlanif_input(void *h, void *buffer, size_t len, void* l2_buff)
if (unlikely(netif->input(p, netif) != ERR_OK)) {
LWIP_DEBUGF(NETIF_DEBUG, ("wlanif_input: IP input error\n"));
pbuf_free(p);
return ESP_FAIL;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_FAIL);
}
return ESP_OK;
return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_OK);
}
/**

Wyświetl plik

@ -10,6 +10,7 @@ CONFIG_ESP_TLS_INSECURE=y
CONFIG_ESP_TLS_SKIP_SERVER_CERT_VERIFY=y
CONFIG_EXAMPLE_CONNECT_ETHERNET=y
CONFIG_EXAMPLE_CONNECT_WIFI=n
CONFIG_ESP_NETIF_RECEIVE_REPORT_ERRORS=y
CONFIG_EXAMPLE_USE_INTERNAL_ETHERNET=y
CONFIG_EXAMPLE_ETH_PHY_IP101=y
CONFIG_EXAMPLE_ETH_MDC_GPIO=23