From 63acb01dc1f02d001ed57d4c9b91b8f8adadf9b8 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 26 May 2025 14:53:43 +0200 Subject: [PATCH] fix(esp_netif): Rename IP_EVENT_AP_STAIPASSIGNED to generic name Since it's the DHCP server that assigned and IP to a client, (the DHPCS doesn't have to be an AP, and DHCPC doesn't have to be a station or an Eth netif) Closes https://github.com/espressif/esp-idf/issues/15663 --- components/esp_netif/include/esp_netif_types.h | 17 +++++++++++++---- components/esp_netif/lwip/esp_netif_lwip.c | 6 +++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/components/esp_netif/include/esp_netif_types.h b/components/esp_netif/include/esp_netif_types.h index ddc549d78a..80ef593825 100644 --- a/components/esp_netif/include/esp_netif_types.h +++ b/components/esp_netif/include/esp_netif_types.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -98,7 +98,11 @@ typedef enum{ typedef enum { IP_EVENT_STA_GOT_IP, /*!< station got IP from connected AP */ IP_EVENT_STA_LOST_IP, /*!< station lost IP and the IP is reset to 0 */ - IP_EVENT_AP_STAIPASSIGNED, /*!< soft-AP assign an IP to a connected station */ + IP_EVENT_ASSIGNED_IP_TO_CLIENT, /*!< DHCP server assigned an IP to a connected client */ + IP_EVENT_AP_STAIPASSIGNED __attribute__((deprecated("Use IP_EVENT_ASSIGNED_IP_TO_CLIENT instead"))) + = IP_EVENT_ASSIGNED_IP_TO_CLIENT, /*!< compatibility enum, + soft-AP assign an IP to a connected station + @deprecated Use IP_EVENT_ASSIGNED_IP_TO_CLIENT instead */ IP_EVENT_GOT_IP6, /*!< station or ap or ethernet interface v6IP addr is preferred */ IP_EVENT_ETH_GOT_IP, /*!< ethernet got IP from connected AP */ IP_EVENT_ETH_LOST_IP, /*!< ethernet lost IP and the IP is reset to 0 */ @@ -148,12 +152,17 @@ typedef struct { bool preferred; /*!< The default preference of the address */ } ip_event_add_ip6_t; -/** Event structure for IP_EVENT_AP_STAIPASSIGNED event */ +/** Event structure for IP_EVENT_ASSIGNED_IP_TO_CLIENT event */ typedef struct { esp_netif_t *esp_netif; /*!< Pointer to the associated netif handle */ esp_ip4_addr_t ip; /*!< IP address which was assigned to the station */ uint8_t mac[6]; /*!< MAC address of the connected client */ -} ip_event_ap_staipassigned_t; +} ip_event_assigned_ip_to_client_t; + +/** Compatibility event structure for ip_event_ap_staipassigned_t event + * @deprecated Use ip_event_assigned_ip_to_client_t instead */ +__attribute__((deprecated("Use ip_event_assigned_ip_to_client_t instead of ip_event_ap_staipassigned_t"))) +typedef ip_event_assigned_ip_to_client_t ip_event_ap_staipassigned_t; typedef enum { ESP_NETIF_TX = 0, // Data is being transmitted. diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 6f93bd8aeb..6811d8ab9e 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -1123,15 +1123,15 @@ static void esp_netif_dhcps_cb(void* arg, uint8_t ip[4], uint8_t mac[6]) { esp_netif_t *esp_netif = arg; ESP_LOGD(TAG, "%s esp_netif:%p", __func__, esp_netif); - ip_event_ap_staipassigned_t evt = { .esp_netif = esp_netif }; + ip_event_assigned_ip_to_client_t evt = { .esp_netif = esp_netif }; memcpy((char *)&evt.ip.addr, (char *)ip, sizeof(evt.ip.addr)); memcpy((char *)&evt.mac, mac, sizeof(evt.mac)); ESP_LOGI(TAG, "DHCP server assigned IP to a client, IP is: " IPSTR, IP2STR(&evt.ip)); ESP_LOGD(TAG, "Client's MAC: %x:%x:%x:%x:%x:%x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - int ret = esp_event_post(IP_EVENT, IP_EVENT_AP_STAIPASSIGNED, &evt, sizeof(evt), 0); + int ret = esp_event_post(IP_EVENT, IP_EVENT_ASSIGNED_IP_TO_CLIENT, &evt, sizeof(evt), 0); if (ESP_OK != ret) { - ESP_LOGE(TAG, "dhcps cb: failed to post IP_EVENT_AP_STAIPASSIGNED (%x)", ret); + ESP_LOGE(TAG, "dhcps cb: failed to post IP_EVENT_ASSIGNED_IP_TO_CLIENT (%x)", ret); } } #endif