mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_netif: Report error if esp_netif_receive() fails
Closes https://github.com/espressif/esp-idf/issues/10770
This commit is contained in:
parent
a7ab77663a
commit
8ce037e99f
@ -13,7 +13,7 @@
|
|||||||
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
|
#if defined(CONFIG_ESP_NETIF_TCPIP_LWIP)
|
||||||
|
|
||||||
typedef err_t (*init_fn_t)(struct netif*);
|
typedef err_t (*init_fn_t)(struct netif*);
|
||||||
typedef void (*input_fn_t)(void *netif, void *buffer, size_t len, void *eb);
|
typedef esp_err_t (*input_fn_t)(void *netif, void *buffer, size_t len, void *eb);
|
||||||
|
|
||||||
struct esp_netif_netstack_lwip_vanilla_config {
|
struct esp_netif_netstack_lwip_vanilla_config {
|
||||||
init_fn_t init_fn;
|
init_fn_t init_fn;
|
||||||
@ -47,7 +47,7 @@ err_t ethernetif_init(struct netif *netif);
|
|||||||
* @param len Input buffer size
|
* @param len Input buffer size
|
||||||
* @param l2_buff External buffer pointer (to be passed to custom input-buffer free)
|
* @param l2_buff External buffer pointer (to be passed to custom input-buffer free)
|
||||||
*/
|
*/
|
||||||
void ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff);
|
esp_err_t ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief LWIP's network stack init function for WiFi (AP)
|
* @brief LWIP's network stack init function for WiFi (AP)
|
||||||
@ -70,6 +70,6 @@ err_t wlanif_init_sta(struct netif *netif);
|
|||||||
* @param len Input buffer size
|
* @param len Input buffer size
|
||||||
* @param l2_buff External buffer pointer (to be passed to custom input-buffer free)
|
* @param l2_buff External buffer pointer (to be passed to custom input-buffer free)
|
||||||
*/
|
*/
|
||||||
void wlanif_input(void *h, void *buffer, size_t len, void* l2_buff);
|
esp_err_t wlanif_input(void *h, void *buffer, size_t len, void* l2_buff);
|
||||||
|
|
||||||
#endif // CONFIG_ESP_NETIF_TCPIP_LWIP
|
#endif // CONFIG_ESP_NETIF_TCPIP_LWIP
|
||||||
|
@ -1170,8 +1170,7 @@ 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)
|
esp_err_t esp_netif_receive(esp_netif_t *esp_netif, void *buffer, size_t len, void *eb)
|
||||||
{
|
{
|
||||||
esp_netif->lwip_input_fn(esp_netif->netif_handle, buffer, len, eb);
|
return esp_netif->lwip_input_fn(esp_netif->netif_handle, buffer, len, eb);
|
||||||
return ESP_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static esp_err_t esp_netif_start_ip_lost_timer(esp_netif_t *esp_netif);
|
static esp_err_t esp_netif_start_ip_lost_timer(esp_netif_t *esp_netif);
|
||||||
|
@ -76,7 +76,7 @@ struct esp_netif_obj {
|
|||||||
// lwip netif related
|
// lwip netif related
|
||||||
struct netif *lwip_netif;
|
struct netif *lwip_netif;
|
||||||
err_t (*lwip_init_fn)(struct netif*);
|
err_t (*lwip_init_fn)(struct netif*);
|
||||||
void (*lwip_input_fn)(void *input_netif_handle, void *buffer, size_t len, void *eb);
|
esp_err_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)
|
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
|
netif_related_data_t *related_data; // holds additional data for specific netifs
|
||||||
#if ESP_DHCPS
|
#if ESP_DHCPS
|
||||||
|
@ -271,13 +271,15 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif)
|
|||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void esp_netif_lwip_ppp_input(void *ppp_ctx, void *buffer, size_t len, void *eb)
|
esp_err_t esp_netif_lwip_ppp_input(void *ppp_ctx, void *buffer, size_t len, void *eb)
|
||||||
{
|
{
|
||||||
struct lwip_peer2peer_ctx * obj = ppp_ctx;
|
struct lwip_peer2peer_ctx * obj = ppp_ctx;
|
||||||
err_t ret = pppos_input_tcpip(obj->ppp, buffer, len);
|
err_t ret = pppos_input_tcpip(obj->ppp, buffer, len);
|
||||||
if (ret != ERR_OK) {
|
if (ret != ERR_OK) {
|
||||||
ESP_LOGE(TAG, "pppos_input_tcpip failed with %d", ret);
|
ESP_LOGE(TAG, "pppos_input_tcpip failed with %d", ret);
|
||||||
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t esp_netif_stop_ppp(netif_related_data_t *netif_related)
|
esp_err_t esp_netif_stop_ppp(netif_related_data_t *netif_related)
|
||||||
|
@ -40,7 +40,7 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif);
|
|||||||
* @return
|
* @return
|
||||||
* - ESP_OK on success
|
* - ESP_OK on success
|
||||||
*/
|
*/
|
||||||
void esp_netif_lwip_ppp_input(void *ppp, void *buffer, size_t len, void *eb);
|
esp_err_t esp_netif_lwip_ppp_input(void *ppp, void *buffer, size_t len, void *eb);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroys the ppp netif object
|
* @brief Destroys the ppp netif object
|
||||||
|
@ -115,7 +115,7 @@ static err_t ethernet_low_level_output(struct netif *netif, struct pbuf *p)
|
|||||||
* @param len length of buffer
|
* @param len length of buffer
|
||||||
* @param l2_buff Placeholder for a separate L2 buffer. Unused for ethernet interface
|
* @param l2_buff Placeholder for a separate L2 buffer. Unused for ethernet interface
|
||||||
*/
|
*/
|
||||||
void ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff)
|
esp_err_t ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff)
|
||||||
{
|
{
|
||||||
struct netif *netif = h;
|
struct netif *netif = h;
|
||||||
esp_netif_t *esp_netif = esp_netif_get_handle_from_netif_impl(netif);
|
esp_netif_t *esp_netif = esp_netif_get_handle_from_netif_impl(netif);
|
||||||
@ -125,21 +125,23 @@ void ethernetif_input(void *h, void *buffer, size_t len, void *l2_buff)
|
|||||||
if (buffer) {
|
if (buffer) {
|
||||||
esp_netif_free_rx_buffer(esp_netif, buffer);
|
esp_netif_free_rx_buffer(esp_netif, buffer);
|
||||||
}
|
}
|
||||||
return;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate custom pbuf to hold */
|
/* allocate custom pbuf to hold */
|
||||||
p = esp_pbuf_allocate(esp_netif, buffer, len, buffer);
|
p = esp_pbuf_allocate(esp_netif, buffer, len, buffer);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
esp_netif_free_rx_buffer(esp_netif, buffer);
|
esp_netif_free_rx_buffer(esp_netif, buffer);
|
||||||
return;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
/* full packet send to tcpip_thread to process */
|
/* full packet send to tcpip_thread to process */
|
||||||
if (unlikely(netif->input(p, netif) != ERR_OK)) {
|
if (unlikely(netif->input(p, netif) != ERR_OK)) {
|
||||||
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
|
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
/* the pbuf will be free in upper layer, eg: ethernet_input */
|
/* the pbuf will be free in upper layer, eg: ethernet_input */
|
||||||
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,7 +126,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
|
|||||||
* @param len length of buffer
|
* @param len length of buffer
|
||||||
* @param l2_buff wlan's L2 buffer pointer
|
* @param l2_buff wlan's L2 buffer pointer
|
||||||
*/
|
*/
|
||||||
void wlanif_input(void *h, void *buffer, size_t len, void* l2_buff)
|
esp_err_t wlanif_input(void *h, void *buffer, size_t len, void* l2_buff)
|
||||||
{
|
{
|
||||||
struct netif * netif = h;
|
struct netif * netif = h;
|
||||||
esp_netif_t *esp_netif = netif->state;
|
esp_netif_t *esp_netif = netif->state;
|
||||||
@ -136,14 +136,14 @@ void wlanif_input(void *h, void *buffer, size_t len, void* l2_buff)
|
|||||||
if (l2_buff) {
|
if (l2_buff) {
|
||||||
esp_netif_free_rx_buffer(esp_netif, l2_buff);
|
esp_netif_free_rx_buffer(esp_netif, l2_buff);
|
||||||
}
|
}
|
||||||
return;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_LWIP_L2_TO_L3_COPY
|
#ifdef CONFIG_LWIP_L2_TO_L3_COPY
|
||||||
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
|
p = pbuf_alloc(PBUF_RAW, len, PBUF_RAM);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
esp_netif_free_rx_buffer(esp_netif, l2_buff);
|
esp_netif_free_rx_buffer(esp_netif, l2_buff);
|
||||||
return;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
memcpy(p->payload, buffer, len);
|
memcpy(p->payload, buffer, len);
|
||||||
esp_netif_free_rx_buffer(esp_netif, l2_buff);
|
esp_netif_free_rx_buffer(esp_netif, l2_buff);
|
||||||
@ -151,7 +151,7 @@ void wlanif_input(void *h, void *buffer, size_t len, void* l2_buff)
|
|||||||
p = esp_pbuf_allocate(esp_netif, buffer, len, l2_buff);
|
p = esp_pbuf_allocate(esp_netif, buffer, len, l2_buff);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
esp_netif_free_rx_buffer(esp_netif, l2_buff);
|
esp_netif_free_rx_buffer(esp_netif, l2_buff);
|
||||||
return;
|
return ESP_ERR_NO_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@ -160,8 +160,9 @@ void wlanif_input(void *h, void *buffer, size_t len, void* l2_buff)
|
|||||||
if (unlikely(netif->input(p, netif) != ERR_OK)) {
|
if (unlikely(netif->input(p, netif) != ERR_OK)) {
|
||||||
LWIP_DEBUGF(NETIF_DEBUG, ("wlanif_input: IP input error\n"));
|
LWIP_DEBUGF(NETIF_DEBUG, ("wlanif_input: IP input error\n"));
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user