mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-08-06 15:15:15 +08:00
feat(tcpip_adapter): Modify tcpip_adapter according to new wifi APIs
This commit is contained in:
@ -35,6 +35,16 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ip4_addr_t ip;
|
||||||
|
ip4_addr_t netmask;
|
||||||
|
ip4_addr_t gw;
|
||||||
|
} tcpip_adapter_ip_info_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
ip6_addr_t ip;
|
||||||
|
} tcpip_adapter_ip6_info_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TCPIP_ADAPTER_IF_STA = 0, /**< ESP8266 station interface */
|
TCPIP_ADAPTER_IF_STA = 0, /**< ESP8266 station interface */
|
||||||
TCPIP_ADAPTER_IF_AP, /**< ESP8266 soft-AP interface */
|
TCPIP_ADAPTER_IF_AP, /**< ESP8266 soft-AP interface */
|
||||||
@ -58,5 +68,11 @@ bool default_hostname;
|
|||||||
#define TCPIP_ATAPTER_LOG(str, ...)
|
#define TCPIP_ATAPTER_LOG(str, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize tcpip adapter
|
||||||
|
*
|
||||||
|
* This will initialize TCPIP stack inside.
|
||||||
|
*/
|
||||||
|
void tcpip_adapter_init(void);
|
||||||
|
|
||||||
#endif /* _TCPIP_ADAPTER_H_ */
|
#endif /* _TCPIP_ADAPTER_H_ */
|
@ -47,7 +47,12 @@ static os_timer_t* get_ip_timer;
|
|||||||
static uint8_t dhcp_fail_time;
|
static uint8_t dhcp_fail_time;
|
||||||
static bool dhcps_flag = true;
|
static bool dhcps_flag = true;
|
||||||
static bool dhcpc_flag = true;
|
static bool dhcpc_flag = true;
|
||||||
static struct ip_info esp_ip[TCPIP_ADAPTER_IF_MAX];
|
static tcpip_adapter_ip_info_t esp_ip[TCPIP_ADAPTER_IF_MAX];
|
||||||
|
|
||||||
|
void tcpip_adapter_init(void)
|
||||||
|
{
|
||||||
|
//TODO:add tcpip init function.
|
||||||
|
}
|
||||||
|
|
||||||
void esp_wifi_station_dhcpc_event(uint8_t netif_index)
|
void esp_wifi_station_dhcpc_event(uint8_t netif_index)
|
||||||
{
|
{
|
||||||
@ -78,8 +83,6 @@ static void tcpip_adapter_dhcpc_done()
|
|||||||
os_timer_setfn(get_ip_timer, tcpip_adapter_dhcpc_done, NULL);
|
os_timer_setfn(get_ip_timer, tcpip_adapter_dhcpc_done, NULL);
|
||||||
os_timer_arm(get_ip_timer, 200, 1);
|
os_timer_arm(get_ip_timer, 200, 1);
|
||||||
} else {
|
} else {
|
||||||
extern void wifi_station_dhcpc_event();
|
|
||||||
wifi_station_dhcpc_event();
|
|
||||||
TCPIP_ATAPTER_LOG("ERROR dhcp get ip error\n");
|
TCPIP_ATAPTER_LOG("ERROR dhcp get ip error\n");
|
||||||
free(get_ip_timer);
|
free(get_ip_timer);
|
||||||
}
|
}
|
||||||
@ -268,9 +271,10 @@ void tcpip_adapter_start(uint8_t netif_index, bool authed)
|
|||||||
netif_set_default(esp_netif[netif_index]);
|
netif_set_default(esp_netif[netif_index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t opmode = wifi_get_opmode();
|
wifi_mode_t opmode;
|
||||||
|
esp_wifi_get_mode(&opmode);
|
||||||
|
|
||||||
if (opmode == STATION_MODE) {
|
if (opmode == WIFI_MODE_STA) {
|
||||||
netif_set_default(esp_netif[netif_index]);
|
netif_set_default(esp_netif[netif_index]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -303,7 +307,7 @@ void tcpip_adapter_stop(uint8_t netif_index)
|
|||||||
esp_netif[netif_index] = NULL;
|
esp_netif[netif_index] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wifi_set_ip_info(WIFI_INTERFACE netif_index, struct ip_info* if_ip)
|
bool wifi_set_ip_info(wifi_interface_t netif_index, tcpip_adapter_ip_info_t* if_ip)
|
||||||
{
|
{
|
||||||
if (!TCPIP_ADAPTER_IF_VALID((uint8_t)netif_index)) {
|
if (!TCPIP_ADAPTER_IF_VALID((uint8_t)netif_index)) {
|
||||||
TCPIP_ATAPTER_LOG("ERROR bad netif index:%d\n", netif_index);
|
TCPIP_ATAPTER_LOG("ERROR bad netif index:%d\n", netif_index);
|
||||||
@ -315,7 +319,7 @@ bool wifi_set_ip_info(WIFI_INTERFACE netif_index, struct ip_info* if_ip)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wifi_get_ip_info(WIFI_INTERFACE netif_index, struct ip_info* if_ip)
|
bool wifi_get_ip_info(wifi_interface_t netif_index, tcpip_adapter_ip_info_t* if_ip)
|
||||||
{
|
{
|
||||||
if (!TCPIP_ADAPTER_IF_VALID((uint8_t)netif_index)) {
|
if (!TCPIP_ADAPTER_IF_VALID((uint8_t)netif_index)) {
|
||||||
TCPIP_ATAPTER_LOG("ERROR bad netif index:%d\n", netif_index);
|
TCPIP_ATAPTER_LOG("ERROR bad netif index:%d\n", netif_index);
|
||||||
@ -374,20 +378,20 @@ bool wifi_get_ipinfo_v6(uint8_t netif_index, uint8_t ip_index, ip6_addr_t* ipv6)
|
|||||||
|
|
||||||
bool wifi_softap_dhcps_start(void)
|
bool wifi_softap_dhcps_start(void)
|
||||||
{
|
{
|
||||||
uint8_t opmode = NULL_MODE;
|
wifi_mode_t opmode = WIFI_MODE_NULL;
|
||||||
TCPIP_ATAPTER_LOG("start softap dhcps\n");
|
TCPIP_ATAPTER_LOG("start softap dhcps\n");
|
||||||
taskENTER_CRITICAL();
|
taskENTER_CRITICAL();
|
||||||
opmode = wifi_get_opmode();
|
esp_wifi_get_mode(&opmode);
|
||||||
|
|
||||||
if ((opmode == STATION_MODE) || (opmode == NULL_MODE)) {
|
if ((opmode == WIFI_MODE_STA) || (opmode == WIFI_MODE_NULL)) {
|
||||||
taskEXIT_CRITICAL();
|
taskEXIT_CRITICAL();
|
||||||
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi softap before start dhcp server\n");
|
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi softap before start dhcp server\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dhcps_flag == false) {
|
if (dhcps_flag == false) {
|
||||||
struct ip_info ipinfo;
|
tcpip_adapter_ip_info_t ipinfo;
|
||||||
wifi_get_ip_info(SOFTAP_IF, &ipinfo);
|
wifi_get_ip_info(ESP_IF_WIFI_AP, &ipinfo);
|
||||||
TCPIP_ATAPTER_LOG("start softap dhcpserver\n");
|
TCPIP_ATAPTER_LOG("start softap dhcpserver\n");
|
||||||
dhcps_start(&ipinfo);
|
dhcps_start(&ipinfo);
|
||||||
}
|
}
|
||||||
@ -425,11 +429,11 @@ void tcpip_adapter_sta_leave()
|
|||||||
|
|
||||||
bool wifi_softap_dhcps_stop()
|
bool wifi_softap_dhcps_stop()
|
||||||
{
|
{
|
||||||
uint8_t opmode = NULL_MODE;
|
wifi_mode_t opmode = WIFI_MODE_NULL;
|
||||||
taskENTER_CRITICAL();
|
taskENTER_CRITICAL();
|
||||||
opmode = wifi_get_opmode();
|
esp_wifi_get_mode(&opmode);
|
||||||
|
|
||||||
if ((opmode == STATION_MODE) || (opmode == NULL_MODE)) {
|
if ((opmode == WIFI_MODE_STA) || (opmode == WIFI_MODE_NULL)) {
|
||||||
taskEXIT_CRITICAL();
|
taskEXIT_CRITICAL();
|
||||||
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi softap before start dhcp server\n");
|
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi softap before start dhcp server\n");
|
||||||
return false;
|
return false;
|
||||||
@ -448,12 +452,12 @@ bool wifi_softap_dhcps_stop()
|
|||||||
|
|
||||||
bool wifi_station_dhcpc_start(void)
|
bool wifi_station_dhcpc_start(void)
|
||||||
{
|
{
|
||||||
uint8_t opmode = NULL_MODE;
|
wifi_mode_t opmode = WIFI_MODE_NULL;
|
||||||
err_t ret;
|
err_t ret;
|
||||||
taskENTER_CRITICAL();
|
taskENTER_CRITICAL();
|
||||||
opmode = wifi_get_opmode();
|
esp_wifi_get_mode(&opmode);
|
||||||
|
|
||||||
if ((opmode == SOFTAP_MODE) || (opmode == NULL_MODE)) {
|
if ((opmode == WIFI_MODE_AP) || (opmode == WIFI_MODE_NULL)) {
|
||||||
taskEXIT_CRITICAL();
|
taskEXIT_CRITICAL();
|
||||||
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi station mode before start dhcp client\n");
|
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi station mode before start dhcp client\n");
|
||||||
return false;
|
return false;
|
||||||
@ -487,11 +491,11 @@ bool wifi_station_dhcpc_start(void)
|
|||||||
|
|
||||||
bool wifi_station_dhcpc_stop()
|
bool wifi_station_dhcpc_stop()
|
||||||
{
|
{
|
||||||
uint8_t opmode = NULL_MODE;
|
wifi_mode_t opmode = WIFI_MODE_NULL;
|
||||||
taskENTER_CRITICAL();
|
taskENTER_CRITICAL();
|
||||||
opmode = wifi_get_opmode();
|
esp_wifi_get_mode(&opmode);
|
||||||
|
|
||||||
if ((opmode == SOFTAP_MODE) || (opmode == NULL_MODE)) {
|
if ((opmode == WIFI_MODE_AP) || (opmode == WIFI_MODE_NULL)) {
|
||||||
taskEXIT_CRITICAL();
|
taskEXIT_CRITICAL();
|
||||||
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi station mode before stop dhcp client\n");
|
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi station mode before stop dhcp client\n");
|
||||||
return false;
|
return false;
|
||||||
@ -559,9 +563,10 @@ bool wifi_station_set_hostname(char* name)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t opmode = wifi_get_opmode();
|
wifi_mode_t opmode;
|
||||||
|
esp_wifi_get_mode(&opmode);
|
||||||
|
|
||||||
if (opmode == STATION_MODE || opmode == STATIONAP_MODE) {
|
if (opmode == WIFI_MODE_STA || opmode == WIFI_MODE_AP) {
|
||||||
default_hostname = 0;
|
default_hostname = 0;
|
||||||
|
|
||||||
if (hostname != NULL) {
|
if (hostname != NULL) {
|
||||||
|
Reference in New Issue
Block a user