Merge branch 'bugfix/optmize_ipv6_event' into 'master'

bugfix: add netif info in event message when got ipv6 address

See merge request !959
This commit is contained in:
Angus Gratton 2017-10-23 17:00:10 +08:00
commit 2c2e7f6303
3 changed files with 20 additions and 8 deletions

View 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),

View 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 {

View 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);
}