From 7d45bfda21d59a15675da459a34d065ffc911b2f Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 31 Jan 2020 15:18:19 +0100 Subject: [PATCH] esp_netif_lwip_ppp: fix posting ip-event data Closes https://github.com/espressif/esp-idf/issues/4634 --- components/esp_netif/lwip/esp_netif_lwip_ppp.c | 16 +++++++++------- .../pppos_client/main/pppos_client_main.c | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.c b/components/esp_netif/lwip/esp_netif_lwip_ppp.c index 3ebddd5ea7..f36538c548 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_ppp.c +++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.c @@ -45,20 +45,23 @@ static void on_ppp_status_changed(ppp_pcb *pcb, int err_code, void *ctx) { struct netif *pppif = ppp_netif(pcb); const ip_addr_t *dest_ip = NULL; - ip_event_ap_staipassigned_t evt = { 0 }; - esp_err_t err; esp_netif_t *netif = ctx; + ip_event_got_ip_t evt = { + .esp_netif = netif, + .if_index = -1, + }; + esp_err_t err; struct lwip_ppp_ctx *obj = netif->lwip_ppp_ctx; - esp_netif_ip_info_t ipinfo = { {0}, {0}, {0} }; esp_ip4_addr_t ns1; esp_ip4_addr_t ns2; switch (err_code) { case PPPERR_NONE: /* Connected */ ESP_LOGI(TAG, "Connected"); - ipinfo.ip.addr = pppif->ip_addr.u_addr.ip4.addr; - ipinfo.gw.addr = pppif->gw.u_addr.ip4.addr; - ipinfo.netmask.addr = pppif->netmask.u_addr.ip4.addr; + evt.ip_info.ip.addr = pppif->ip_addr.u_addr.ip4.addr; + evt.ip_info.gw.addr = pppif->gw.u_addr.ip4.addr; + evt.ip_info.netmask.addr = pppif->netmask.u_addr.ip4.addr; + dest_ip = dns_getserver(0); if(dest_ip != NULL){ ns1.addr = (*dest_ip).u_addr.ip4.addr; @@ -70,7 +73,6 @@ static void on_ppp_status_changed(ppp_pcb *pcb, int err_code, void *ctx) ESP_LOGI(TAG, "Name Server1: " IPSTR, IP2STR(&ns1)); ESP_LOGI(TAG, "Name Server2: " IPSTR, IP2STR(&ns2)); - evt.ip.addr = ipinfo.ip.addr; err = esp_event_post(IP_EVENT, netif->get_ip_event, &evt, sizeof(evt), 0); if (ESP_OK != err) { diff --git a/examples/protocols/pppos_client/main/pppos_client_main.c b/examples/protocols/pppos_client/main/pppos_client_main.c index a6eea822d4..7637ba3ce7 100644 --- a/examples/protocols/pppos_client/main/pppos_client_main.c +++ b/examples/protocols/pppos_client/main/pppos_client_main.c @@ -181,7 +181,7 @@ static void on_ppp_changed(void *arg, esp_event_base_t event_base, static void on_ip_event(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { - ESP_LOGI(TAG, "IP event! %d", event_id); + ESP_LOGD(TAG, "IP event! %d", event_id); if (event_id == IP_EVENT_PPP_GOT_IP) { esp_netif_dns_info_t dns_info; @@ -192,7 +192,7 @@ static void on_ip_event(void *arg, esp_event_base_t event_base, ESP_LOGI(TAG, "~~~~~~~~~~~~~~"); ESP_LOGI(TAG, "IP : " IPSTR, IP2STR(&event->ip_info.ip)); ESP_LOGI(TAG, "Netmask : " IPSTR, IP2STR(&event->ip_info.netmask)); - ESP_LOGI(TAG, "Gateway : " IPSTR, IP2STR(&event->ip_info.ip)); + ESP_LOGI(TAG, "Gateway : " IPSTR, IP2STR(&event->ip_info.gw)); esp_netif_get_dns_info(netif, 0, &dns_info); ESP_LOGI(TAG, "Name Server1: " IPSTR, IP2STR(&dns_info.ip.u_addr.ip4)); esp_netif_get_dns_info(netif, 1, &dns_info);