tcpip_adapter: code clean up
This commit is contained in:
parent
62c891735b
commit
7d0c139fdc
|
@ -110,12 +110,12 @@ esp_err_t tcpip_adapter_set_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac);
|
|||
#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_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_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_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_stop(tcpip_adapter_if_t tcpip_if);
|
||||
|
||||
|
|
|
@ -297,43 +297,58 @@ esp_err_t tcpip_adapter_dhcps_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adap
|
|||
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);
|
||||
if (opt_info == NULL || opt_val == NULL)
|
||||
|
||||
if (opt_info == NULL || opt_val == NULL) {
|
||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
switch (opt_id) {
|
||||
case IP_ADDRESS_LEASE_TIME:
|
||||
{
|
||||
*(uint32_t*)opt_val = *(uint32_t*)opt_info;
|
||||
break;
|
||||
}
|
||||
case REQUESTED_IP_ADDRESS:
|
||||
{
|
||||
memcpy(opt_val, opt_info, opt_len);
|
||||
break;
|
||||
}
|
||||
case ROUTER_SOLICITATION_ADDRESS:
|
||||
{
|
||||
*(uint8_t *)opt_val = (*(uint8_t *)opt_info) & OFFER_ROUTER;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else{
|
||||
if (dhcps_status == TCPIP_ADAPTER_DHCP_STARTED)
|
||||
} else if (opt_op == TCPIP_ADAPTER_OP_SET) {
|
||||
if (dhcps_status == TCPIP_ADAPTER_DHCP_STARTED) {
|
||||
return ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
switch (opt_id) {
|
||||
case IP_ADDRESS_LEASE_TIME:
|
||||
{
|
||||
if (*(uint32_t*)opt_val != 0)
|
||||
*(uint32_t*)opt_info = *(uint32_t*)opt_val;
|
||||
else
|
||||
*(uint32_t*)opt_info = DHCPS_LEASE_TIME_DEF;
|
||||
break;
|
||||
case REQUESTED_IP_ADDRESS:{
|
||||
}
|
||||
case REQUESTED_IP_ADDRESS:
|
||||
{
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (end_ip - start_ip > DHCPS_MAX_LEASE)
|
||||
if (end_ip - start_ip > DHCPS_MAX_LEASE) {
|
||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
memcpy(opt_info, opt_val, opt_len);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ROUTER_SOLICITATION_ADDRESS:
|
||||
{
|
||||
*(uint8_t *)opt_info = (*(uint8_t *)opt_val) & OFFER_ROUTER;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
return ESP_OK;
|
||||
|
|
Loading…
Reference in a new issue