|
|
@@ -31,7 +31,7 @@
|
|
|
#include "esp_event.h"
|
|
|
|
|
|
static struct netif *esp_netif[TCPIP_ADAPTER_IF_MAX];
|
|
|
-static struct ip_info esp_ip[TCPIP_ADAPTER_IF_MAX];
|
|
|
+static tcpip_adapter_ip_info_t esp_ip[TCPIP_ADAPTER_IF_MAX];
|
|
|
|
|
|
static tcpip_adapter_dhcp_status_t dhcps_status = TCPIP_ADAPTER_DHCP_INIT;
|
|
|
static tcpip_adapter_dhcp_status_t dhcpc_status = TCPIP_ADAPTER_DHCP_INIT;
|
|
|
@@ -53,9 +53,9 @@ void tcpip_adapter_init(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, struct ip_info *info)
|
|
|
+esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_adapter_ip_info_t *ip_info)
|
|
|
{
|
|
|
- if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || mac == NULL || info == NULL) {
|
|
|
+ if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || mac == NULL || ip_info == NULL) {
|
|
|
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
|
|
}
|
|
|
|
|
|
@@ -65,17 +65,17 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, struct
|
|
|
return ESP_ERR_NO_MEM;
|
|
|
}
|
|
|
memcpy(esp_netif[tcpip_if]->hwaddr, mac, NETIF_MAX_HWADDR_LEN);
|
|
|
- netif_add(esp_netif[tcpip_if], &info->ip, &info->netmask, &info->gw, NULL, wlanif_init, tcpip_input);
|
|
|
+ netif_add(esp_netif[tcpip_if], &ip_info->ip, &ip_info->netmask, &ip_info->gw, NULL, wlanif_init, tcpip_input);
|
|
|
}
|
|
|
|
|
|
if (tcpip_if == TCPIP_ADAPTER_IF_AP) {
|
|
|
netif_set_up(esp_netif[tcpip_if]);
|
|
|
|
|
|
if (dhcps_status == TCPIP_ADAPTER_DHCP_INIT) {
|
|
|
- dhcps_start(esp_netif[tcpip_if], info);
|
|
|
+ dhcps_start(esp_netif[tcpip_if], ip_info->ip);
|
|
|
|
|
|
printf("dhcp server start:(ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR ")\n",
|
|
|
- IP2STR(&info->ip), IP2STR(&info->netmask), IP2STR(&info->gw));
|
|
|
+ IP2STR(&ip_info->ip), IP2STR(&ip_info->netmask), IP2STR(&ip_info->gw));
|
|
|
|
|
|
dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
|
|
|
}
|
|
|
@@ -164,37 +164,37 @@ esp_err_t tcpip_adapter_down(tcpip_adapter_if_t tcpip_if)
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
-esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info *if_ip)
|
|
|
+esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info)
|
|
|
{
|
|
|
struct netif *p_netif;
|
|
|
|
|
|
- if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || if_ip == NULL) {
|
|
|
+ if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || ip_info == NULL) {
|
|
|
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
|
|
}
|
|
|
|
|
|
p_netif = esp_netif[tcpip_if];
|
|
|
|
|
|
if (p_netif != NULL && netif_is_up(p_netif)) {
|
|
|
- ip4_addr_set(&if_ip->ip, ip_2_ip4(&p_netif->ip_addr));
|
|
|
- ip4_addr_set(&if_ip->netmask, ip_2_ip4(&p_netif->netmask));
|
|
|
- ip4_addr_set(&if_ip->gw, ip_2_ip4(&p_netif->gw));
|
|
|
+ ip4_addr_set(&ip_info->ip, ip_2_ip4(&p_netif->ip_addr));
|
|
|
+ ip4_addr_set(&ip_info->netmask, ip_2_ip4(&p_netif->netmask));
|
|
|
+ ip4_addr_set(&ip_info->gw, ip_2_ip4(&p_netif->gw));
|
|
|
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
- ip4_addr_copy(if_ip->ip, esp_ip[tcpip_if].ip);
|
|
|
- ip4_addr_copy(if_ip->gw, esp_ip[tcpip_if].gw);
|
|
|
- ip4_addr_copy(if_ip->netmask, esp_ip[tcpip_if].netmask);
|
|
|
+ ip4_addr_copy(ip_info->ip, esp_ip[tcpip_if].ip);
|
|
|
+ ip4_addr_copy(ip_info->gw, esp_ip[tcpip_if].gw);
|
|
|
+ ip4_addr_copy(ip_info->netmask, esp_ip[tcpip_if].netmask);
|
|
|
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
-esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info *if_ip)
|
|
|
+esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info)
|
|
|
{
|
|
|
struct netif *p_netif;
|
|
|
tcpip_adapter_dhcp_status_t status;
|
|
|
|
|
|
- if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || if_ip == NULL) {
|
|
|
+ if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || ip_info == NULL) {
|
|
|
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
|
|
}
|
|
|
|
|
|
@@ -212,14 +212,14 @@ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, struct ip_info
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
+ ip4_addr_copy(esp_ip[tcpip_if].ip, ip_info->ip);
|
|
|
+ ip4_addr_copy(esp_ip[tcpip_if].gw, ip_info->gw);
|
|
|
+ ip4_addr_copy(esp_ip[tcpip_if].netmask, ip_info->netmask);
|
|
|
|
|
|
p_netif = esp_netif[tcpip_if];
|
|
|
|
|
|
if (p_netif != NULL && netif_is_up(p_netif)) {
|
|
|
- netif_set_addr(p_netif, &if_ip->ip, &if_ip->netmask, &if_ip->gw);
|
|
|
+ netif_set_addr(p_netif, &ip_info->ip, &ip_info->netmask, &ip_info->gw);
|
|
|
}
|
|
|
|
|
|
return ESP_OK;
|
|
|
@@ -265,7 +265,7 @@ esp_err_t tcpip_adapter_set_mac(tcpip_adapter_if_t tcpip_if, uint8_t mac[6])
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
-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_option(tcpip_adapter_option_mode_t opt_op, tcpip_adapter_option_id_t opt_id, void *opt_val, uint32_t opt_len)
|
|
|
{
|
|
|
void *opt_info = dhcps_option_info(opt_id, opt_len);
|
|
|
|
|
|
@@ -308,18 +308,18 @@ esp_err_t tcpip_adapter_dhcps_option(tcpip_adapter_option_mode opt_op, tcpip_ada
|
|
|
if (*(uint32_t*)opt_val != 0)
|
|
|
*(uint32_t*)opt_info = *(uint32_t*)opt_val;
|
|
|
else
|
|
|
- *(uint32_t*)opt_info = DHCPS_LEASE_TIME_DEF;
|
|
|
+ *(uint32_t*)opt_info = DHCPS_LEASE_TIME_DEF;
|
|
|
break;
|
|
|
}
|
|
|
case REQUESTED_IP_ADDRESS:
|
|
|
{
|
|
|
- struct ip_info info;
|
|
|
+ tcpip_adapter_ip_info_t info;
|
|
|
uint32_t softap_ip = 0;
|
|
|
uint32_t start_ip = 0;
|
|
|
uint32_t end_ip = 0;
|
|
|
- struct dhcps_lease *poll = opt_val;
|
|
|
+ dhcps_lease_t *poll = opt_val;
|
|
|
|
|
|
- memset(&info, 0x00, sizeof(struct ip_info));
|
|
|
+ memset(&info, 0x00, sizeof(tcpip_adapter_ip_info_t));
|
|
|
tcpip_adapter_get_ip_info(WIFI_IF_AP, &info);
|
|
|
softap_ip = htonl(info.ip.addr);
|
|
|
start_ip = htonl(poll->start_ip.addr);
|
|
|
@@ -377,9 +377,9 @@ esp_err_t tcpip_adapter_dhcps_start(tcpip_adapter_if_t tcpip_if)
|
|
|
struct netif *p_netif = esp_netif[tcpip_if];
|
|
|
|
|
|
if (p_netif != NULL && netif_is_up(p_netif)) {
|
|
|
- struct ip_info default_ip;
|
|
|
+ tcpip_adapter_ip_info_t default_ip;
|
|
|
tcpip_adapter_get_ip_info(WIFI_IF_AP, &default_ip);
|
|
|
- dhcps_start(p_netif, &default_ip);
|
|
|
+ dhcps_start(p_netif, default_ip.ip);
|
|
|
dhcps_status = TCPIP_ADAPTER_DHCP_STARTED;
|
|
|
TCPIP_ADAPTER_DEBUG("dhcp server start successfully\n");
|
|
|
return ESP_OK;
|
|
|
@@ -421,7 +421,7 @@ esp_err_t tcpip_adapter_dhcps_stop(tcpip_adapter_if_t tcpip_if)
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
-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_option(tcpip_adapter_option_mode_t opt_op, tcpip_adapter_option_id_t opt_id, void *opt_val, uint32_t opt_len)
|
|
|
{
|
|
|
// TODO: when dhcp request timeout,change the retry count
|
|
|
return ESP_OK;
|
|
|
@@ -430,7 +430,7 @@ esp_err_t tcpip_adapter_dhcpc_option(tcpip_adapter_option_mode opt_op, tcpip_ada
|
|
|
static void tcpip_adapter_dhcpc_cb(void)
|
|
|
{
|
|
|
struct netif *netif = esp_netif[TCPIP_ADAPTER_IF_STA];
|
|
|
- struct ip_info *ip_info = &esp_ip[TCPIP_ADAPTER_IF_STA];
|
|
|
+ tcpip_adapter_ip_info_t *ip_info = &esp_ip[TCPIP_ADAPTER_IF_STA];
|
|
|
system_event_t evt;
|
|
|
|
|
|
if (!netif) {
|
|
|
@@ -450,9 +450,7 @@ static void tcpip_adapter_dhcpc_cb(void)
|
|
|
|
|
|
//notify event
|
|
|
evt.event_id = SYSTEM_EVENT_STA_GOTIP;
|
|
|
- memcpy(&evt.event_info.got_ip.ip, &ip_info->ip, sizeof(evt.event_info.got_ip.ip));
|
|
|
- memcpy(&evt.event_info.got_ip.netmask, &ip_info->netmask, sizeof(evt.event_info.got_ip.netmask));
|
|
|
- memcpy(&evt.event_info.got_ip.gw, &ip_info->gw, sizeof(evt.event_info.got_ip.gw));
|
|
|
+ memcpy(&evt.event_info.got_ip.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t));
|
|
|
|
|
|
esp_event_send(&evt);
|
|
|
} else {
|
|
|
@@ -541,13 +539,13 @@ esp_err_t tcpip_adapter_dhcpc_stop(tcpip_adapter_if_t tcpip_if)
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
-esp_err_t tcpip_adapter_sta_input(void *buffer, uint16_t len, void* eb)
|
|
|
+esp_err_t tcpip_adapter_sta_input(void *buffer, uint16_t len, void *eb)
|
|
|
{
|
|
|
wlanif_input(esp_netif[TCPIP_ADAPTER_IF_STA], buffer, len, eb);
|
|
|
return ESP_OK;
|
|
|
}
|
|
|
|
|
|
-esp_err_t tcpip_adapter_ap_input(void *buffer, uint16_t len, void* eb)
|
|
|
+esp_err_t tcpip_adapter_ap_input(void *buffer, uint16_t len, void *eb)
|
|
|
{
|
|
|
wlanif_input(esp_netif[TCPIP_ADAPTER_IF_AP], buffer, len, eb);
|
|
|
return ESP_OK;
|