From 7bea025b5665ca4289b108d1295c25afdcd0e54b Mon Sep 17 00:00:00 2001 From: Wu Jian Gang Date: Tue, 30 Aug 2016 23:58:55 +0800 Subject: [PATCH] tcpip_adapter: not allow to set ip if dhcpc/s not stoped TW6804 --- .../tcpip_adapter/include/tcpip_adapter.h | 1 + components/tcpip_adapter/tcpip_adapter_lwip.c | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/components/tcpip_adapter/include/tcpip_adapter.h b/components/tcpip_adapter/include/tcpip_adapter.h index 55a2f3843b..de81c9400c 100644 --- a/components/tcpip_adapter/include/tcpip_adapter.h +++ b/components/tcpip_adapter/include/tcpip_adapter.h @@ -59,6 +59,7 @@ struct station_list { #define ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED ESP_ERR_TCPIP_ADAPTER_BASE + 0x03 #define ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPED ESP_ERR_TCPIP_ADAPTER_BASE + 0x04 #define ESP_ERR_TCPIP_ADAPTER_NO_MEM ESP_ERR_TCPIP_ADAPTER_BASE + 0x05 +#define ESP_ERR_TCPIP_ADAPTER_DHCP_NOT_STOPED ESP_ERR_TCPIP_ADAPTER_BASE + 0x06 /* will add ethernet interface */ typedef enum { diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c index 1ea72b4b80..7ff6cffc9c 100644 --- a/components/tcpip_adapter/tcpip_adapter_lwip.c +++ b/components/tcpip_adapter/tcpip_adapter_lwip.c @@ -38,7 +38,7 @@ static tcpip_adapter_dhcp_status_t dhcpc_status = TCPIP_ADAPTER_DHCP_INIT; static esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif); -#define TCPIP_ADAPTER_DEBUG(...) +#define TCPIP_ADAPTER_DEBUG(...) void tcpip_adapter_init(void) { @@ -236,11 +236,26 @@ esp_err_t tcpip_adapter_addr_change_cb(struct netif *netif) esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info *if_ip) { struct netif *p_netif; + tcpip_adapter_dhcp_status_t status; if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || if_ip == NULL) { return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS; } + if (tcpip_if == TCPIP_ADAPTER_IF_AP) { + tcpip_adapter_dhcps_get_status(tcpip_if, &status); + + if (status != TCPIP_ADAPTER_DHCP_STOPED) { + return ESP_ERR_TCPIP_ADAPTER_DHCP_NOT_STOPED; + } + } else if (tcpip_if == TCPIP_ADAPTER_IF_STA) { + tcpip_adapter_dhcpc_get_status(tcpip_if, &status); + + if (status != TCPIP_ADAPTER_DHCP_STOPED) { + return ESP_ERR_TCPIP_ADAPTER_DHCP_NOT_STOPED; + } + } + ip4_addr_copy(esp_ip[tcpip_if].ip, if_ip->ip); ip4_addr_copy(esp_ip[tcpip_if].gw, if_ip->gw); ip4_addr_copy(esp_ip[tcpip_if].netmask, if_ip->netmask); @@ -477,7 +492,7 @@ esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if) if (p_netif != NULL) { if (netif_is_up(p_netif)) { TCPIP_ADAPTER_DEBUG("dhcp client init ip/mask/gw to all-0\n"); - ip_addr_set_zero(&p_netif->ip_addr);; + ip_addr_set_zero(&p_netif->ip_addr); ip_addr_set_zero(&p_netif->netmask); ip_addr_set_zero(&p_netif->gw); } -- 2.40.0