Skip to content

Commit aa3c77e

Browse files
committed
Merge branch 'bugfix/wifi_lwip_set_ip_post_wrong_event' into 'master'
Fix the bug that incorrect event is posted when setting static ip of softap and ethernet See merge request idf/esp-idf!2095
2 parents 5bc724d + 0470f28 commit aa3c77e

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

components/tcpip_adapter/tcpip_adapter_lwip.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,25 @@ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_i
408408

409409
if (p_netif != NULL && netif_is_up(p_netif)) {
410410
netif_set_addr(p_netif, &ip_info->ip, &ip_info->netmask, &ip_info->gw);
411-
if (!(ip4_addr_isany_val(ip_info->ip) || ip4_addr_isany_val(ip_info->netmask) || ip4_addr_isany_val(ip_info->gw))) {
412-
system_event_t evt;
413-
evt.event_id = SYSTEM_EVENT_STA_GOT_IP;
414-
evt.event_info.got_ip.ip_changed = false;
411+
if (tcpip_if == TCPIP_ADAPTER_IF_STA || tcpip_if == TCPIP_ADAPTER_IF_ETH) {
412+
if (!(ip4_addr_isany_val(ip_info->ip) || ip4_addr_isany_val(ip_info->netmask) || ip4_addr_isany_val(ip_info->gw))) {
413+
system_event_t evt;
414+
if (tcpip_if == TCPIP_ADAPTER_IF_STA) {
415+
evt.event_id = SYSTEM_EVENT_STA_GOT_IP;
416+
} else if (tcpip_if == TCPIP_ADAPTER_IF_ETH) {
417+
evt.event_id = SYSTEM_EVENT_ETH_GOT_IP;
418+
}
419+
evt.event_info.got_ip.ip_changed = false;
415420

416-
if (memcmp(ip_info, &esp_ip_old[tcpip_if], sizeof(tcpip_adapter_ip_info_t))) {
417-
evt.event_info.got_ip.ip_changed = true;
418-
}
421+
if (memcmp(ip_info, &esp_ip_old[tcpip_if], sizeof(tcpip_adapter_ip_info_t))) {
422+
evt.event_info.got_ip.ip_changed = true;
423+
}
419424

420-
memcpy(&evt.event_info.got_ip.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t));
421-
memcpy(&esp_ip_old[tcpip_if], ip_info, sizeof(tcpip_adapter_ip_info_t));
422-
esp_event_send(&evt);
423-
ESP_LOGD(TAG, "if%d tcpip adapter set static ip: ip changed=%d", tcpip_if, evt.event_info.got_ip.ip_changed);
425+
memcpy(&evt.event_info.got_ip.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t));
426+
memcpy(&esp_ip_old[tcpip_if], ip_info, sizeof(tcpip_adapter_ip_info_t));
427+
esp_event_send(&evt);
428+
ESP_LOGD(TAG, "if%d tcpip adapter set static ip: ip changed=%d", tcpip_if, evt.event_info.got_ip.ip_changed);
429+
}
424430
}
425431
}
426432

0 commit comments

Comments
 (0)