From 586207207f7f204fb4d0e7c1a6489afa52315bdc Mon Sep 17 00:00:00 2001 From: Yogesh Mantri Date: Tue, 23 Jan 2024 15:09:45 +0100 Subject: [PATCH] change(esp_netif): Add Non-Fatal errtype to indicate lower layer medium failure UDP application sends packet using esp_netif, underlying transport such as Wi-Fi may drop the packet due to higher load. New error code represent transient, non-fatal packet drop error. udp application may use such errtype, for example to rate limit. --- components/esp_common/src/esp_err_to_name.c | 5 ++- .../esp_common/src/esp_err_to_name.c.in | 2 +- .../esp_http_server/include/esp_http_server.h | 6 +-- .../esp_netif/include/esp_netif_types.h | 2 + components/esp_netif/lwip/netif/wlanif.c | 41 +++++++++++++------ .../esp_supplicant/include/esp_dpp.h | 4 +- 6 files changed, 41 insertions(+), 19 deletions(-) diff --git a/components/esp_common/src/esp_err_to_name.c b/components/esp_common/src/esp_err_to_name.c index aba5fae342..c344dd519a 100644 --- a/components/esp_common/src/esp_err_to_name.c +++ b/components/esp_common/src/esp_err_to_name.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -595,6 +595,9 @@ static const esp_err_msg_t esp_err_msg_table[] = { # endif # ifdef ESP_ERR_ESP_NETIF_DHCPS_START_FAILED ERR_TBL_IT(ESP_ERR_ESP_NETIF_DHCPS_START_FAILED), /* 20493 0x500d */ +# endif +# ifdef ESP_ERR_ESP_NETIF_TX_FAILED + ERR_TBL_IT(ESP_ERR_ESP_NETIF_TX_FAILED), /* 20494 0x500e */ # endif // components/esp_common/include/esp_err.h # ifdef ESP_ERR_FLASH_BASE diff --git a/components/esp_common/src/esp_err_to_name.c.in b/components/esp_common/src/esp_err_to_name.c.in index 36b40071e4..309881219f 100644 --- a/components/esp_common/src/esp_err_to_name.c.in +++ b/components/esp_common/src/esp_err_to_name.c.in @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/components/esp_http_server/include/esp_http_server.h b/components/esp_http_server/include/esp_http_server.h index 6b319af214..759eadf85f 100644 --- a/components/esp_http_server/include/esp_http_server.h +++ b/components/esp_http_server/include/esp_http_server.h @@ -1045,8 +1045,8 @@ esp_err_t httpd_req_get_cookie_val(httpd_req_t *req, const char *cookie_name, ch /** * @brief Test if a URI matches the given wildcard template. * - * Template may end with "?" to make the previous character optional (typically a slash), - * "*" for a wildcard match, and "?*" to make the previous character optional, and if present, + * Template may end with '?' to make the previous character optional (typically a slash), + * '*' for a wildcard match, and '?*' to make the previous character optional, and if present, * allow anything to follow. * * Example: @@ -1055,7 +1055,7 @@ esp_err_t httpd_req_get_cookie_val(httpd_req_t *req, const char *cookie_name, ch * - /api/\* (sans the backslash) matches /api/ and /api/status, but not /api or /ap * - /api/?* or /api/\*? (sans the backslash) matches /api/, /api/status, and also /api, but not /apix or /ap * - * The special characters "?" and "*" anywhere else in the template will be taken literally. + * The special characters '?' and '*' anywhere else in the template will be taken literally. * * @param[in] uri_template URI template (pattern) * @param[in] uri_to_match URI to be matched diff --git a/components/esp_netif/include/esp_netif_types.h b/components/esp_netif/include/esp_netif_types.h index 836fbd7974..c9874c5673 100644 --- a/components/esp_netif/include/esp_netif_types.h +++ b/components/esp_netif/include/esp_netif_types.h @@ -34,6 +34,8 @@ extern "C" { #define ESP_ERR_ESP_NETIF_MLD6_FAILED ESP_ERR_ESP_NETIF_BASE + 0x0B #define ESP_ERR_ESP_NETIF_IP6_ADDR_FAILED ESP_ERR_ESP_NETIF_BASE + 0x0C #define ESP_ERR_ESP_NETIF_DHCPS_START_FAILED ESP_ERR_ESP_NETIF_BASE + 0x0D +#define ESP_ERR_ESP_NETIF_TX_FAILED ESP_ERR_ESP_NETIF_BASE + 0x0E + /** diff --git a/components/esp_netif/lwip/netif/wlanif.c b/components/esp_netif/lwip/netif/wlanif.c index f6bdfae4fa..a7d26ed86c 100644 --- a/components/esp_netif/lwip/netif/wlanif.c +++ b/components/esp_netif/lwip/netif/wlanif.c @@ -24,6 +24,7 @@ #include "lwip/esp_netif_net_stack.h" #include "esp_compiler.h" #include "lwip/esp_pbuf_ref.h" +#include "esp_netif_types.h" /** * In this function, the hardware should be initialized. @@ -84,10 +85,11 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) } struct pbuf *q = p; - esp_err_t ret; + esp_err_t netif_ret = ESP_FAIL; + err_t ret = ERR_IF; if(q->next == NULL) { - ret = esp_netif_transmit_wrap(esp_netif, q->payload, q->len, q); + netif_ret = esp_netif_transmit_wrap(esp_netif, q->payload, q->len, q); } else { LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug")); @@ -97,21 +99,36 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) } else { return ERR_MEM; } - ret = esp_netif_transmit_wrap(esp_netif, q->payload, q->len, q); + netif_ret = esp_netif_transmit_wrap(esp_netif, q->payload, q->len, q); pbuf_free(q); } - if (ret == ESP_OK) { - return ERR_OK; + /* translate netif_ret to lwip supported return value */ + switch (netif_ret) { + + case ESP_OK: + ret = ERR_OK; + break; + + case ESP_ERR_NO_MEM: + ret = ERR_MEM; + break; + + case ESP_ERR_ESP_NETIF_TX_FAILED: + ret = ERR_BUF; + break; + + case ESP_ERR_INVALID_ARG: + ret = ERR_ARG; + break; + + default: + ret = ERR_IF; + break; } - if (ret == ESP_ERR_NO_MEM) { - return ERR_MEM; - } - if (ret == ESP_ERR_INVALID_ARG) { - return ERR_ARG; - } - return ERR_IF; + + return ret; } /** diff --git a/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h b/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h index 4545bd33e0..2b07a54281 100644 --- a/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h +++ b/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -79,7 +79,7 @@ esp_err_t esp_supp_dpp_deinit(void); * @param chan_list List of channels device will be available on for listening * @param type Bootstrap method type, only QR Code method is supported for now. * @param key (Optional) 32 byte Raw Private Key for generating a Bootstrapping Public Key - * @param info (Optional) Ancilliary Device Information like Serial Number + * @param info (Optional) Ancillary Device Information like Serial Number * * @return * - ESP_OK: Success