]> granicus.if.org Git - esp-idf/commitdiff
bugfix: add netif info in event message when got ipv6 address
authorTian Zhong Xing <tianzhongxing@espressif.com>
Wed, 5 Jul 2017 08:29:02 +0000 (16:29 +0800)
committerTian Zhong Xing <tianzhongxing@espressif.com>
Mon, 23 Oct 2017 05:50:43 +0000 (13:50 +0800)
components/esp32/event_default_handlers.c
components/esp32/include/esp_event.h
components/tcpip_adapter/tcpip_adapter_lwip.c

index e4941362ccdda6f7426cfb4045ff394bc0494d2f..76d49f83ebb272b2b1642fcae0bf4d6b3a235703 100644 (file)
@@ -341,7 +341,7 @@ static esp_err_t esp_system_event_debug(system_event_t *event)
                    MAC2STR(ap_probereqrecved->mac));
         break;
     }
-    case SYSTEM_EVENT_AP_STA_GOT_IP6: {
+    case SYSTEM_EVENT_GOT_IP6: {
         ip6_addr_t *addr = &event->event_info.got_ip6.ip6_info.ip;
         ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STA_GOT_IP6 address %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
                  IP6_ADDR_BLOCK1(addr),
index ccffdb8186e3cb2a02889dc1c33fa34edc7bf251..53c416c29fb20998cde6c107737ba2267463af71 100644 (file)
@@ -45,7 +45,7 @@ typedef enum {
     SYSTEM_EVENT_AP_STACONNECTED,          /**< a station connected to ESP32 soft-AP */
     SYSTEM_EVENT_AP_STADISCONNECTED,       /**< a station disconnected from ESP32 soft-AP */
     SYSTEM_EVENT_AP_PROBEREQRECVED,        /**< Receive probe request packet in soft-AP interface */
-    SYSTEM_EVENT_AP_STA_GOT_IP6,           /**< ESP32 station or ap interface v6IP addr is preferred */
+    SYSTEM_EVENT_GOT_IP6,                  /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */
     SYSTEM_EVENT_ETH_START,                /**< ESP32 ethernet start */
     SYSTEM_EVENT_ETH_STOP,                 /**< ESP32 ethernet stop */
     SYSTEM_EVENT_ETH_CONNECTED,            /**< ESP32 ethernet phy link up */
@@ -54,6 +54,11 @@ typedef enum {
     SYSTEM_EVENT_MAX
 } system_event_id_t;
 
+/* add this macro define for compatible with old IDF version */
+#ifndef SYSTEM_EVENT_AP_STA_GOT_IP6
+#define SYSTEM_EVENT_AP_STA_GOT_IP6 SYSTEM_EVENT_GOT_IP6
+#endif
+
 typedef enum {
     WPS_FAIL_REASON_NORMAL = 0,                   /**< ESP32 WPS normal fail reason */
     WPS_FAIL_REASON_RECV_M2D,                       /**< ESP32 WPS receive M2D frame */
@@ -95,8 +100,9 @@ typedef struct {
 } system_event_sta_wps_er_pin_t;
 
 typedef struct {
+    tcpip_adapter_if_t if_index;
     tcpip_adapter_ip6_info_t ip6_info;
-} system_event_ap_sta_got_ip6_t;
+} system_event_got_ip6_t;
 
 typedef struct {
     uint8_t mac[6];           /**< MAC address of the station connected to ESP32 soft-AP */
@@ -124,7 +130,7 @@ typedef union {
     system_event_ap_staconnected_t             sta_connected;      /**< a station connected to ESP32 soft-AP */
     system_event_ap_stadisconnected_t          sta_disconnected;   /**< a station disconnected to ESP32 soft-AP */
     system_event_ap_probe_req_rx_t             ap_probereqrecved;  /**< ESP32 soft-AP receive probe request packet */
-    system_event_ap_sta_got_ip6_t              got_ip6;            /**< ESP32 station or ap ipv6 addr state change to preferred */
+    system_event_got_ip6_t                     got_ip6;            /**< ESP32 station or ap or ethernet ipv6 addr state change to preferred */
 } system_event_info_t;
 
 typedef struct {
index 267ae681b31cf73b33be398a1f5caaee69ae90b5..b5fe5dce572d2328b6af677e351f27cdb25f4709 100644 (file)
@@ -436,6 +436,11 @@ static void tcpip_adapter_nd6_cb(struct netif *p_netif, uint8_t ip_idex)
 {
     tcpip_adapter_ip6_info_t *ip6_info;
 
+    system_event_t evt;
+    //notify event
+
+    evt.event_id = SYSTEM_EVENT_GOT_IP6;
+
     if (!p_netif) {
         ESP_LOGD(TAG, "null p_netif=%p", p_netif);
         return;
@@ -443,18 +448,19 @@ static void tcpip_adapter_nd6_cb(struct netif *p_netif, uint8_t ip_idex)
 
     if (p_netif == esp_netif[TCPIP_ADAPTER_IF_STA]) {
         ip6_info = &esp_ip6[TCPIP_ADAPTER_IF_STA];
+        evt.event_info.got_ip6.if_index = TCPIP_ADAPTER_IF_STA;
     } else if (p_netif == esp_netif[TCPIP_ADAPTER_IF_AP]) {
         ip6_info = &esp_ip6[TCPIP_ADAPTER_IF_AP];
+        evt.event_info.got_ip6.if_index = TCPIP_ADAPTER_IF_AP;
+    } else if (p_netif == esp_netif[TCPIP_ADAPTER_IF_ETH]) {
+        ip6_info = &esp_ip6[TCPIP_ADAPTER_IF_ETH];
+        evt.event_info.got_ip6.if_index = TCPIP_ADAPTER_IF_ETH;
     } else {
         return;
     }
 
-    system_event_t evt;
-
     ip6_addr_set(&ip6_info->ip, ip_2_ip6(&p_netif->ip6_addr[ip_idex]));
 
-    //notify event
-    evt.event_id = SYSTEM_EVENT_AP_STA_GOT_IP6;
     memcpy(&evt.event_info.got_ip6.ip6_info, ip6_info, sizeof(tcpip_adapter_ip6_info_t));
     esp_event_send(&evt);
 }