From ace5656236caeb156e5bc3c17a3986f793cd09cc Mon Sep 17 00:00:00 2001 From: "wangtao@espressif.com" Date: Thu, 7 May 2026 16:38:07 +0800 Subject: [PATCH] fix(lwip): improve lost ip event process --- components/esp_netif/lwip/esp_netif_lwip.c | 19 ++++--- .../injected/esp_wifi_ap_get_sta_list.h | 56 ------------------- 2 files changed, 12 insertions(+), 63 deletions(-) delete mode 100644 components/esp_wifi/remote/include/injected/esp_wifi_ap_get_sta_list.h diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index aeb4893caa4..06dd102ea5c 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -1338,7 +1338,7 @@ esp_err_t esp_netif_receive(esp_netif_t *esp_netif, void *buffer, size_t len, vo } #if CONFIG_LWIP_IPV4 -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, bool renew); // // DHCP: @@ -1401,7 +1401,7 @@ static void esp_netif_internal_dhcpc_cb(struct netif *netif) } } else { if (!ip4_addr_cmp(&ip_info->ip, IP4_ADDR_ANY4)) { - esp_netif_start_ip_lost_timer(esp_netif); + esp_netif_start_ip_lost_timer(esp_netif, false); } } } @@ -1441,7 +1441,7 @@ static void esp_netif_ip_lost_timer(void *arg) } } -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, bool renew) { esp_netif_ip_info_t *ip_info_old = esp_netif->ip_info; struct netif *netif = esp_netif->lwip_netif; @@ -1450,7 +1450,12 @@ static esp_err_t esp_netif_start_ip_lost_timer(esp_netif_t *esp_netif) if ( netif && (CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL > 0)) { if (esp_netif->timer_running) { - sys_untimeout(esp_netif_ip_lost_timer, (void *)esp_netif); + if (renew) { + sys_untimeout(esp_netif_ip_lost_timer, (void *)esp_netif); + } else{ + ESP_LOGD(TAG, "if%p start ip lost tmr: already started", esp_netif); + return ESP_OK; + } } esp_netif->timer_running = true; sys_timeout(CONFIG_ESP_NETIF_IP_LOST_TIMER_INTERVAL * 1000, esp_netif_ip_lost_timer, (void *)esp_netif); @@ -1481,7 +1486,7 @@ static esp_err_t esp_netif_dhcpc_stop_api(esp_netif_api_msg_t *msg) if (p_netif != NULL) { dhcp_stop(p_netif); esp_netif_reset_ip_info(esp_netif); - esp_netif_start_ip_lost_timer(esp_netif); + esp_netif_start_ip_lost_timer(esp_netif, false); } else { ESP_LOGD(TAG, "dhcp client if not ready"); return ESP_ERR_ESP_NETIF_IF_NOT_READY; @@ -1544,7 +1549,7 @@ static esp_err_t esp_netif_dhcpc_start_api(esp_netif_api_msg_t *msg) ip_addr_set_zero(&p_netif->ip_addr); ip_addr_set_zero(&p_netif->netmask); ip_addr_set_zero(&p_netif->gw); - esp_netif_start_ip_lost_timer(esp_netif); + esp_netif_start_ip_lost_timer(esp_netif, true); } else { ESP_LOGD(TAG, "dhcp client re init"); esp_netif->dhcpc_status = ESP_NETIF_DHCP_INIT; @@ -1795,7 +1800,7 @@ static esp_err_t esp_netif_down_api(esp_netif_api_msg_t *msg) if (esp_netif->flags & ESP_NETIF_DHCP_CLIENT) { #if CONFIG_LWIP_IPV4 - esp_netif_start_ip_lost_timer(esp_netif); + esp_netif_start_ip_lost_timer(esp_netif, false); #endif } diff --git a/components/esp_wifi/remote/include/injected/esp_wifi_ap_get_sta_list.h b/components/esp_wifi/remote/include/injected/esp_wifi_ap_get_sta_list.h deleted file mode 100644 index b1cb3b10e38..00000000000 --- a/components/esp_wifi/remote/include/injected/esp_wifi_ap_get_sta_list.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include "esp_netif_types.h" -#include "esp_wifi_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef ESP_WIFI_MAX_CONN_NUM -// Number of maximum wifi connection may be undefined if we have no native wifi support on this target -// and at the same time there's no native interface injected by the wifi_remote component. -// In this case, we just let the header compilable, since no wifi API could be used (let's make a sanity check) -#if !CONFIG_SOC_WIFI_SUPPORTED && !CONFIG_ESP_WIFI_REMOTE_ENABLED && !CONFIG_ESP_HOST_WIFI_ENABLED -#define ESP_WIFI_MAX_CONN_NUM (15) -typedef struct wifi_sta_list_t wifi_sta_list_t; -#else -#error WiFi header mismatch! Please make sure you use the correct version of WiFi API -#endif -#endif // ESP_WIFI_MAX_CONN_NUM - -/** - * @brief station list structure - */ -typedef struct { - int num; /**< Number of connected stations */ - esp_netif_pair_mac_ip_t sta[ESP_WIFI_MAX_CONN_NUM]; /**< Connected stations */ -} wifi_sta_mac_ip_list_t; - -/** - * @brief Get IP information for stations connected to the Wi-Fi AP interface - * - * @note If `CONFIG_LWIP_DHCPS` is disabled then DHCP lookup is skipped; IPv4 may still be filled from the lwIP ARP cache when available. - * After DHCP (when enabled), any station still without an IP is resolved via ARP table on the same interface. - * - * @warning This API works only for the default Wi-Fi AP interface, i.e. esp-netif with key="WIFI_AP_DEF" - * - * @param[in] wifi_sta_list Wi-Fi station info list, returned from esp_wifi_ap_get_sta_list() - * @param[out] wifi_sta_ip_mac_list IP layer station info list, corresponding to MAC addresses provided in wifi_sta_list - * - * @return - * - ESP_OK - * - ESP_ERR_ESP_NETIF_NO_MEM - * - ESP_ERR_ESP_NETIF_INVALID_PARAMS - */ -esp_err_t esp_wifi_ap_get_sta_list_with_ip(const wifi_sta_list_t *wifi_sta_list, wifi_sta_mac_ip_list_t *wifi_sta_ip_mac_list); - -#ifdef __cplusplus -} -#endif