From 922992b51928f985e426cc49432b41f78aada797 Mon Sep 17 00:00:00 2001 From: yuanjm Date: Fri, 7 May 2021 11:36:13 +0800 Subject: [PATCH] event: Add IP_EVENT_ETH_LOST_IP event Closes https://github.com/espressif/esp-idf/issues/6971 --- components/esp_event/event_send.c | 3 +++ components/esp_event/include/esp_event_legacy.h | 1 + components/esp_netif/include/esp_netif_defaults.h | 2 +- components/esp_netif/include/esp_netif_types.h | 1 + docs/en/api-guides/event-handling.rst | 3 +++ 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/components/esp_event/event_send.c b/components/esp_event/event_send.c index 20098bc142..bc5aef9d37 100644 --- a/components/esp_event/event_send.c +++ b/components/esp_event/event_send.c @@ -121,6 +121,9 @@ static system_event_id_t esp_event_legacy_ip_event_id(int32_t event_id) case IP_EVENT_ETH_GOT_IP: return SYSTEM_EVENT_ETH_GOT_IP; + case IP_EVENT_ETH_LOST_IP: + return SYSTEM_EVENT_ETH_LOST_IP; + default: ESP_LOGE(TAG, "invalid ip event id %d", event_id); return SYSTEM_EVENT_MAX; diff --git a/components/esp_event/include/esp_event_legacy.h b/components/esp_event/include/esp_event_legacy.h index 021ac4075b..dbeeced674 100644 --- a/components/esp_event/include/esp_event_legacy.h +++ b/components/esp_event/include/esp_event_legacy.h @@ -58,6 +58,7 @@ typedef enum { SYSTEM_EVENT_ETH_CONNECTED, /*!< ESP32 ethernet phy link up */ SYSTEM_EVENT_ETH_DISCONNECTED, /*!< ESP32 ethernet phy link down */ SYSTEM_EVENT_ETH_GOT_IP, /*!< ESP32 ethernet got IP from connected AP */ + SYSTEM_EVENT_ETH_LOST_IP, /*!< ESP32 ethernet lost IP and the IP is reset to 0 */ SYSTEM_EVENT_MAX /*!< Number of members in this enum */ } system_event_id_t; diff --git a/components/esp_netif/include/esp_netif_defaults.h b/components/esp_netif/include/esp_netif_defaults.h index 7ef65260d4..903a678e00 100644 --- a/components/esp_netif/include/esp_netif_defaults.h +++ b/components/esp_netif/include/esp_netif_defaults.h @@ -55,7 +55,7 @@ extern "C" { ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \ ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \ .get_ip_event = IP_EVENT_ETH_GOT_IP, \ - .lost_ip_event = 0, \ + .lost_ip_event = IP_EVENT_ETH_LOST_IP, \ .if_key = "ETH_DEF", \ .if_desc = "eth", \ .route_prio = 50 \ diff --git a/components/esp_netif/include/esp_netif_types.h b/components/esp_netif/include/esp_netif_types.h index 044ca0d111..7c68c7172a 100644 --- a/components/esp_netif/include/esp_netif_types.h +++ b/components/esp_netif/include/esp_netif_types.h @@ -88,6 +88,7 @@ typedef enum { IP_EVENT_AP_STAIPASSIGNED, /*!< soft-AP assign an IP to a connected station */ 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 */ IP_EVENT_PPP_GOT_IP, /*!< PPP interface got IP */ IP_EVENT_PPP_LOST_IP, /*!< PPP interface lost IP */ } ip_event_t; diff --git a/docs/en/api-guides/event-handling.rst b/docs/en/api-guides/event-handling.rst index e0a163b471..65de97f1ad 100644 --- a/docs/en/api-guides/event-handling.rst +++ b/docs/en/api-guides/event-handling.rst @@ -123,6 +123,9 @@ Event IDs and Corresponding Data Structures | IP_EVENT_ETH_GOT_IP | :cpp:class:`ip_event_got_ip_t` | | (SYSTEM_EVENT_ETH_GOT_IP) | | +------------------------------------+-----------------------------------------------+ +| IP_EVENT_ETH_LOST_IP | n/a | +| (SYSTEM_EVENT_ETH_LOST_IP) | | ++------------------------------------+-----------------------------------------------+ Mesh Events -----------