]> granicus.if.org Git - esp-idf/commitdiff
tcpip_adapter: clean up dhcpc status
authorWu Jian Gang <wujiangang@espressif.com>
Fri, 26 Aug 2016 03:52:46 +0000 (11:52 +0800)
committerWu Jian Gang <wujiangang@espressif.com>
Fri, 26 Aug 2016 11:06:38 +0000 (19:06 +0800)
only auto start dhcpc in init status

components/esp32/event.c
components/tcpip_adapter/tcpip_adapter_lwip.c

index d10972e295af5a5a8339a6c0da214be1cefef4ae..6839493246dac1f5988a85280823f80a6f79110d 100644 (file)
@@ -116,10 +116,17 @@ esp_err_t system_event_sta_stop_handle_default(system_event_t *event)
 
 esp_err_t system_event_sta_connected_handle_default(system_event_t *event)
 {
+    tcpip_adapter_dhcp_status_t status;
+       
     WIFI_API_CALL_CHECK("esp_wifi_reg_rxcb", esp_wifi_reg_rxcb(WIFI_IF_STA, (wifi_rxcb_t)tcpip_adapter_sta_input), ESP_OK);
 
     tcpip_adapter_up(TCPIP_ADAPTER_IF_STA);
-    tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
+
+    tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_STA, &status);
+
+    if (status == TCPIP_ADAPTER_DHCP_INIT) {
+        tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
+    }
 
     return ESP_OK;
 }
index e8464790550a33dc9e5d4fa389a05108c685dfbf..d6ad20ad83792a91ba7c590dffe870fcf0777161 100644 (file)
@@ -147,7 +147,10 @@ esp_err_t tcpip_adapter_down(tcpip_adapter_if_t tcpip_if)
             dhcp_release(esp_netif[tcpip_if]);
             dhcp_stop(esp_netif[tcpip_if]);
             dhcp_cleanup(esp_netif[tcpip_if]);
-            dhcpc_status = TCPIP_ADAPTER_DHCP_STOPED;
+
+            if (dhcpc_status != TCPIP_ADAPTER_DHCP_STOPED) {
+                dhcpc_status = TCPIP_ADAPTER_DHCP_INIT;
+            }
         } else {
             netif_set_down(esp_netif[tcpip_if]);
             netif_set_addr(esp_netif[tcpip_if], IP4_ADDR_ANY, IP4_ADDR_ANY, IP4_ADDR_ANY);