tcpip_adapter: code clean up

This commit is contained in:
Wu Jian Gang 2016-08-26 18:16:29 +08:00
parent 62c891735b
commit 7d0c139fdc
2 changed files with 99 additions and 78 deletions

View file

@ -110,12 +110,12 @@ esp_err_t tcpip_adapter_set_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac);
#endif #endif
esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status); esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);
esp_err_t tcpip_adapter_dhcps_option(uint8_t opt_op, uint8_t opt_id, void* opt_val, uint32_t opt_len); esp_err_t tcpip_adapter_dhcps_option(tcpip_adapter_option_mode opt_op, tcpip_adapter_option_id opt_id, void *opt_val, uint32_t opt_len);
esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if); esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if);
esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if); esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if);
esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status); esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status);
esp_err_t tcpip_adapter_dhcpc_option(uint8_t opt_op, uint8_t opt_id, void* opt_val, uint32_t opt_len); esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_option_mode opt_op, tcpip_adapter_option_id opt_id, void *opt_val, uint32_t opt_len);
esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if); esp_err_t tcpip_adapter_dhcpc_start(tcpip_adapter_if_t tcpip_if);
esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if); esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if);

View file

@ -297,43 +297,58 @@ esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adap
return ESP_OK; return ESP_OK;
} }
esp_err_t tcpip_adapter_dhcps_option(uint8_t opt_op, uint8_t opt_id, void* opt_val, uint32_t opt_len) esp_err_t tcpip_adapter_dhcps_option(tcpip_adapter_option_mode opt_op, tcpip_adapter_option_id opt_id, void *opt_val, uint32_t opt_len)
{ {
void *opt_info = dhcps_option_info(opt_id, opt_len); void *opt_info = dhcps_option_info(opt_id, opt_len);
if (opt_info == NULL || opt_val == NULL)
if (opt_info == NULL || opt_val == NULL) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS; return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}
if (opt_op == TCPIP_ADAPTER_OP_GET) { if (opt_op == TCPIP_ADAPTER_OP_GET) {
if (dhcps_status == TCPIP_ADAPTER_DHCP_STOPED) if (dhcps_status == TCPIP_ADAPTER_DHCP_STOPED) {
return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPED; return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPED;
}
switch (opt_id) { switch (opt_id) {
case IP_ADDRESS_LEASE_TIME: case IP_ADDRESS_LEASE_TIME:
{
*(uint32_t*)opt_val = *(uint32_t*)opt_info; *(uint32_t*)opt_val = *(uint32_t*)opt_info;
break; break;
}
case REQUESTED_IP_ADDRESS: case REQUESTED_IP_ADDRESS:
{
memcpy(opt_val, opt_info, opt_len); memcpy(opt_val, opt_info, opt_len);
break; break;
}
case ROUTER_SOLICITATION_ADDRESS: case ROUTER_SOLICITATION_ADDRESS:
{
*(uint8_t *)opt_val = (*(uint8_t *)opt_info) & OFFER_ROUTER; *(uint8_t *)opt_val = (*(uint8_t *)opt_info) & OFFER_ROUTER;
break; break;
}
default: default:
break; break;
} }
} else{ } else if (opt_op == TCPIP_ADAPTER_OP_SET) {
if (dhcps_status == TCPIP_ADAPTER_DHCP_STARTED) if (dhcps_status == TCPIP_ADAPTER_DHCP_STARTED) {
return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED; return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED;
}
switch (opt_id) { switch (opt_id) {
case IP_ADDRESS_LEASE_TIME: case IP_ADDRESS_LEASE_TIME:
{
if (*(uint32_t*)opt_val != 0) if (*(uint32_t*)opt_val != 0)
*(uint32_t*)opt_info = *(uint32_t*)opt_val; *(uint32_t*)opt_info = *(uint32_t*)opt_val;
else else
*(uint32_t*)opt_info = DHCPS_LEASE_TIME_DEF; *(uint32_t*)opt_info = DHCPS_LEASE_TIME_DEF;
break; break;
case REQUESTED_IP_ADDRESS:{ }
case REQUESTED_IP_ADDRESS:
{
struct ip_info info; struct ip_info info;
uint32_t softap_ip = 0;uint32_t start_ip = 0;uint32_t end_ip = 0; uint32_t softap_ip = 0;
uint32_t start_ip = 0;
uint32_t end_ip = 0;
struct dhcps_lease *poll = opt_val; struct dhcps_lease *poll = opt_val;
memset(&info, 0x00, sizeof(struct ip_info)); memset(&info, 0x00, sizeof(struct ip_info));
@ -353,19 +368,25 @@ esp_err_t tcpip_adapter_dhcps_option(uint8_t opt_op, uint8_t opt_id, void* opt_v
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS; return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
} }
if (end_ip - start_ip > DHCPS_MAX_LEASE) if (end_ip - start_ip > DHCPS_MAX_LEASE) {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS; return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
}
memcpy(opt_info, opt_val, opt_len); memcpy(opt_info, opt_val, opt_len);
}
break; break;
}
case ROUTER_SOLICITATION_ADDRESS: case ROUTER_SOLICITATION_ADDRESS:
{
*(uint8_t *)opt_info = (*(uint8_t *)opt_val) & OFFER_ROUTER; *(uint8_t *)opt_info = (*(uint8_t *)opt_val) & OFFER_ROUTER;
break; break;
}
default: default:
break; break;
} }
} else {
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
} }
return ESP_OK; return ESP_OK;
} }
@ -432,7 +453,7 @@ esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adap
return ESP_OK; return ESP_OK;
} }
esp_err_t tcpip_adapter_dhcpc_option(uint8_t opt_op, uint8_t opt_id, void* opt_val, uint32_t opt_len) esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_option_mode opt_op, tcpip_adapter_option_id opt_id, void *opt_val, uint32_t opt_len)
{ {
// TODO: when dhcp request timeout,change the retry count // TODO: when dhcp request timeout,change the retry count
return ESP_OK; return ESP_OK;