tcpip_adapter: not allow to set ip if dhcpc/s not stoped

TW6804
This commit is contained in:
Wu Jian Gang 2016-08-30 23:58:55 +08:00
parent b56ca86571
commit 7bea025b56
2 changed files with 18 additions and 2 deletions

View File

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

View File

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