From b834c99148d901050e73728aa7bf0546068e1873 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Sun, 1 Sep 2019 18:25:23 +0200 Subject: [PATCH] examples: modify other examples and tests to use esp_netif instead of tcpip_adapter --- components/driver/test/esp32/test_adc2.c | 6 ++++-- components/esp_eth/test/test_emac.c | 9 ++++++--- components/esp_http_client/lib/http_auth.c | 2 +- components/esp_wifi/src/smartconfig_ack.c | 6 +++--- components/esp_wifi/test/esp32/test_wifi.c | 6 +++--- .../ble/blufi/main/blufi_example_main.c | 3 ++- .../components/iperf/cmd_wifi.c | 16 ++++++++++------ .../protocols/esp_local_ctrl/main/app_main.c | 3 ++- .../protocols/icmp_echo/main/echo_example_main.c | 2 +- examples/protocols/mqtt/ssl_psk/main/app_main.c | 4 ++-- .../components/modem/src/esp_modem.c | 2 +- .../pppos_client/main/pppos_client_main.c | 4 ++-- examples/system/console/main/cmd_wifi.c | 6 ++++-- examples/system/select/main/select_example.c | 4 ++-- examples/wifi/espnow/main/espnow_example_main.c | 4 ++-- examples/wifi/fast_scan/main/fast_scan.c | 7 ++++++- examples/wifi/iperf/main/cmd_wifi.c | 16 ++++++++++------ examples/wifi/power_save/main/power_save.c | 3 ++- examples/wifi/scan/main/scan.c | 3 ++- .../main/simple_sniffer_example_main.c | 4 ++-- .../wifi/smart_config/main/smartconfig_main.c | 5 +++-- .../wpa2_enterprise/main/wpa2_enterprise_main.c | 15 ++++++++++----- examples/wifi/wps/main/wps.c | 3 ++- .../components/test_utils/test_utils.c | 6 +++--- 24 files changed, 85 insertions(+), 54 deletions(-) diff --git a/components/driver/test/esp32/test_adc2.c b/components/driver/test/esp32/test_adc2.c index fa45232280..176cc17bfb 100644 --- a/components/driver/test/esp32/test_adc2.c +++ b/components/driver/test/esp32/test_adc2.c @@ -94,8 +94,10 @@ TEST_CASE("adc2 work with wifi","[adc]") r = nvs_flash_init(); } TEST_ESP_OK( r); - tcpip_adapter_init(); + esp_netif_init(); event_init(); + esp_netif_create_default_wifi_sta(); + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); TEST_ESP_OK(esp_wifi_init(&cfg)); wifi_config_t wifi_config = { @@ -144,5 +146,5 @@ TEST_CASE("adc2 work with wifi","[adc]") printf("test passed...\n"); - TEST_IGNORE_MESSAGE("this test case is ignored due to the critical memory leak of tcpip_adapter and event_loop."); + TEST_IGNORE_MESSAGE("this test case is ignored due to the critical memory leak of esp_netif and event_loop."); } diff --git a/components/esp_eth/test/test_emac.c b/components/esp_eth/test/test_emac.c index 368494cbf7..47123db8ab 100644 --- a/components/esp_eth/test/test_emac.c +++ b/components/esp_eth/test/test_emac.c @@ -62,7 +62,7 @@ static void got_ip_event_handler(void *arg, esp_event_base_t event_base, { EventGroupHandle_t eth_event_group = (EventGroupHandle_t)arg; ip_event_got_ip_t *event = (ip_event_got_ip_t *)event_data; - const tcpip_adapter_ip_info_t *ip_info = (tcpip_adapter_ip_info_t *)&event->ip_info; + const esp_netif_ip_info_t *ip_info = &event->ip_info; ESP_LOGI(TAG, "Ethernet Got IP Address"); ESP_LOGI(TAG, "~~~~~~~~~~~"); @@ -309,9 +309,11 @@ TEST_CASE("dm9051 io test", "[ethernet][ignore]") }; TEST_ESP_OK(spi_bus_add_device(HSPI_HOST, &devcfg, &spi_handle)); gpio_install_isr_service(0); - tcpip_adapter_init(); + esp_netif_init(); TEST_ESP_OK(esp_event_loop_create_default()); - TEST_ESP_OK(tcpip_adapter_set_default_eth_handlers()); + esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); + esp_netif_t* eth_netif = esp_netif_new(&cfg); + TEST_ESP_OK(esp_eth_set_default_handlers(eth_netif)); TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, NULL)); TEST_ESP_OK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL)); eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); @@ -322,6 +324,7 @@ TEST_CASE("dm9051 io test", "[ethernet][ignore]") esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy); esp_eth_handle_t eth_handle = NULL; TEST_ESP_OK(esp_eth_driver_install(&config, ð_handle)); + TEST_ESP_OK(esp_netif_attach(eth_netif, eth_handle)); vTaskDelay(pdMS_TO_TICKS(portMAX_DELAY)); TEST_ESP_OK(esp_eth_driver_uninstall(eth_handle)); TEST_ESP_OK(phy->del(phy)); diff --git a/components/esp_http_client/lib/http_auth.c b/components/esp_http_client/lib/http_auth.c index 7463a92f59..1fcc2f1152 100644 --- a/components/esp_http_client/lib/http_auth.c +++ b/components/esp_http_client/lib/http_auth.c @@ -17,7 +17,7 @@ #include #include -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "lwip/sockets.h" #include "esp32/rom/md5_hash.h" #include "mbedtls/base64.h" diff --git a/components/esp_wifi/src/smartconfig_ack.c b/components/esp_wifi/src/smartconfig_ack.c index 3cda1a21c6..db9276d8d4 100644 --- a/components/esp_wifi/src/smartconfig_ack.c +++ b/components/esp_wifi/src/smartconfig_ack.c @@ -21,7 +21,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "lwip/sockets.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "esp_log.h" #include "esp_wifi.h" #include "esp_event.h" @@ -69,7 +69,7 @@ static int sc_ack_send_get_errno(int fd) static void sc_ack_send_task(void *pvParameters) { sc_ack_t *ack = (sc_ack_t *)pvParameters; - tcpip_adapter_ip_info_t local_ip; + esp_netif_ip_info_t local_ip; uint8_t remote_ip[4]; memcpy(remote_ip, ack->ctx.ip, sizeof(remote_ip)); int remote_port = (ack->type == SC_TYPE_ESPTOUCH) ? SC_ACK_TOUCH_SERVER_PORT : SC_ACK_AIRKISS_SERVER_PORT; @@ -94,7 +94,7 @@ static void sc_ack_send_task(void *pvParameters) while (s_sc_ack_send) { /* Get local IP address of station */ - ret = tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &local_ip); + ret = esp_netif_get_ip_info(esp_netif_get_handle_from_ifkey("WIFI_STA_DEF"), &local_ip); if ((ESP_OK == ret) && (local_ip.ip.addr != INADDR_ANY)) { /* If ESP touch, smartconfig ACK contains local IP address. */ if (ack->type == SC_TYPE_ESPTOUCH) { diff --git a/components/esp_wifi/test/esp32/test_wifi.c b/components/esp_wifi/test/esp32/test_wifi.c index 0d1385f6bc..1a467baaee 100644 --- a/components/esp_wifi/test/esp32/test_wifi.c +++ b/components/esp_wifi/test/esp32/test_wifi.c @@ -144,8 +144,8 @@ TEST_CASE("wifi stop and deinit","[wifi]") } TEST_ESP_OK(r); //init tcpip - ESP_LOGI(TAG, EMPH_STR("tcpip_adapter_init")); - tcpip_adapter_init(); + ESP_LOGI(TAG, EMPH_STR("esp_netif_init")); + esp_netif_init(); //init event loop ESP_LOGI(TAG, EMPH_STR("event_init")); @@ -163,7 +163,7 @@ TEST_CASE("wifi stop and deinit","[wifi]") nvs_flash_deinit(); ESP_LOGI(TAG, "test passed..."); - TEST_IGNORE_MESSAGE("this test case is ignored due to the critical memory leak of tcpip_adapter and event_loop."); + TEST_IGNORE_MESSAGE("this test case is ignored due to the critical memory leak of esp_netif and event_loop."); } static void start_wifi_as_softap(void) diff --git a/examples/bluetooth/bluedroid/ble/blufi/main/blufi_example_main.c b/examples/bluetooth/bluedroid/ble/blufi/main/blufi_example_main.c index cf3e153303..3cb5e6a51b 100644 --- a/examples/bluetooth/bluedroid/ble/blufi/main/blufi_example_main.c +++ b/examples/bluetooth/bluedroid/ble/blufi/main/blufi_example_main.c @@ -197,9 +197,10 @@ static void wifi_event_handler(void* arg, esp_event_base_t event_base, static void initialise_wifi(void) { - tcpip_adapter_init(); + esp_netif_init(); wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK(esp_event_loop_create_default()); + assert(esp_netif_create_default_wifi_sta()); ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL)); ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL)); diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/components/iperf/cmd_wifi.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/components/iperf/cmd_wifi.c index 8fd95ce474..a4e060ec8a 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/components/iperf/cmd_wifi.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/components/iperf/cmd_wifi.c @@ -16,7 +16,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/event_groups.h" #include "esp_wifi.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "iperf.h" typedef struct { @@ -51,6 +51,8 @@ static const char *TAG = "iperf"; static EventGroupHandle_t wifi_event_group; const int CONNECTED_BIT = BIT0; const int DISCONNECTED_BIT = BIT1; +static esp_netif_t * sta_netif = NULL; +static esp_netif_t * ap_netif = NULL; static void scan_done_handler(void) { @@ -124,9 +126,11 @@ void initialise_wifi(void) return; } - tcpip_adapter_init(); + esp_netif_init(); wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK(esp_event_loop_create_default()); + assert(sta_netif = esp_netif_create_default_wifi_sta()); + assert(ap_netif = esp_netif_create_default_wifi_ap()); ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &wifi_event_handler, NULL)); ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &ip_event_handler, NULL)); @@ -286,22 +290,22 @@ static int wifi_cmd_query(int argc, char **argv) static uint32_t wifi_get_local_ip(void) { int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0); - tcpip_adapter_if_t ifx = TCPIP_ADAPTER_IF_AP; - tcpip_adapter_ip_info_t ip_info; + esp_netif_t * ifx = ap_netif; + esp_netif_ip_info_t ip_info; wifi_mode_t mode; esp_wifi_get_mode(&mode); if (WIFI_MODE_STA == mode) { bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0); if (bits & CONNECTED_BIT) { - ifx = TCPIP_ADAPTER_IF_STA; + ifx = sta_netif; } else { ESP_LOGE(TAG, "sta has no IP"); return 0; } } - tcpip_adapter_get_ip_info(ifx, &ip_info); + esp_netif_get_ip_info(ifx, &ip_info); return ip_info.ip.addr; } diff --git a/examples/protocols/esp_local_ctrl/main/app_main.c b/examples/protocols/esp_local_ctrl/main/app_main.c index 65651cc667..43ba8bf241 100644 --- a/examples/protocols/esp_local_ctrl/main/app_main.c +++ b/examples/protocols/esp_local_ctrl/main/app_main.c @@ -65,9 +65,10 @@ void wifi_init_sta(void) { s_wifi_event_group = xEventGroupCreate(); - tcpip_adapter_init(); + esp_netif_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); + assert(esp_netif_create_default_wifi_sta()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); diff --git a/examples/protocols/icmp_echo/main/echo_example_main.c b/examples/protocols/icmp_echo/main/echo_example_main.c index 3f222bb157..53acb17422 100644 --- a/examples/protocols/icmp_echo/main/echo_example_main.c +++ b/examples/protocols/icmp_echo/main/echo_example_main.c @@ -80,7 +80,7 @@ void app_main(void) initialize_console(); ESP_ERROR_CHECK(nvs_flash_init()); - tcpip_adapter_init(); + esp_netif_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); /* wait for active network connection */ ESP_ERROR_CHECK(example_connect()); diff --git a/examples/protocols/mqtt/ssl_psk/main/app_main.c b/examples/protocols/mqtt/ssl_psk/main/app_main.c index 7a08d17725..48e73f8c09 100644 --- a/examples/protocols/mqtt/ssl_psk/main/app_main.c +++ b/examples/protocols/mqtt/ssl_psk/main/app_main.c @@ -15,7 +15,7 @@ #include "esp_system.h" #include "nvs_flash.h" #include "esp_event.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "protocol_examples_common.h" #include "freertos/FreeRTOS.h" @@ -128,7 +128,7 @@ void app_main(void) esp_log_level_set("OUTBOX", ESP_LOG_VERBOSE); ESP_ERROR_CHECK(nvs_flash_init()); - tcpip_adapter_init(); + esp_netif_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); /* This helper function configures Wi-Fi or Ethernet, as selected in menuconfig. diff --git a/examples/protocols/pppos_client/components/modem/src/esp_modem.c b/examples/protocols/pppos_client/components/modem/src/esp_modem.c index d59da0b5f2..99e10db2a5 100644 --- a/examples/protocols/pppos_client/components/modem/src/esp_modem.c +++ b/examples/protocols/pppos_client/components/modem/src/esp_modem.c @@ -20,7 +20,7 @@ #include "netif/ppp/pppapi.h" #include "netif/ppp/pppos.h" #include "lwip/dns.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "esp_modem.h" #include "esp_log.h" #include "sdkconfig.h" diff --git a/examples/protocols/pppos_client/main/pppos_client_main.c b/examples/protocols/pppos_client/main/pppos_client_main.c index c3a18a6cb6..7df7c49388 100644 --- a/examples/protocols/pppos_client/main/pppos_client_main.c +++ b/examples/protocols/pppos_client/main/pppos_client_main.c @@ -9,7 +9,7 @@ #include #include "freertos/FreeRTOS.h" #include "freertos/event_groups.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "mqtt_client.h" #include "esp_modem.h" #include "esp_log.h" @@ -181,7 +181,7 @@ static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event) void app_main(void) { - tcpip_adapter_init(); + esp_netif_init(); event_group = xEventGroupCreate(); /* create dte object */ esp_modem_dte_config_t config = ESP_MODEM_DTE_DEFAULT_CONFIG(); diff --git a/examples/system/console/main/cmd_wifi.c b/examples/system/console/main/cmd_wifi.c index b9c24f0cd1..e26a9dcea9 100644 --- a/examples/system/console/main/cmd_wifi.c +++ b/examples/system/console/main/cmd_wifi.c @@ -16,7 +16,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/event_groups.h" #include "esp_wifi.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "esp_event.h" #include "cmd_wifi.h" @@ -44,9 +44,11 @@ static void initialise_wifi(void) if (initialized) { return; } - tcpip_adapter_init(); + esp_netif_init(); wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK(esp_event_loop_create_default()); + assert(esp_netif_create_default_wifi_ap()); + assert(esp_netif_create_default_wifi_sta()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &event_handler, NULL) ); diff --git a/examples/system/select/main/select_example.c b/examples/system/select/main/select_example.c index 5da28c7dde..78d1516274 100644 --- a/examples/system/select/main/select_example.c +++ b/examples/system/select/main/select_example.c @@ -18,7 +18,7 @@ #include "esp_vfs.h" #include "esp_vfs_dev.h" #include "driver/uart.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "lwip/sockets.h" #include "lwip/netdb.h" @@ -43,7 +43,7 @@ static void socket_init(void) int err; struct sockaddr_in saddr = { 0 }; - tcpip_adapter_init(); + esp_netif_init(); err = getaddrinfo("localhost", "80", &hints, &res); diff --git a/examples/wifi/espnow/main/espnow_example_main.c b/examples/wifi/espnow/main/espnow_example_main.c index ad540eb335..981a8477e0 100644 --- a/examples/wifi/espnow/main/espnow_example_main.c +++ b/examples/wifi/espnow/main/espnow_example_main.c @@ -21,7 +21,7 @@ #include "freertos/timers.h" #include "nvs_flash.h" #include "esp_event.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "esp_wifi.h" #include "esp_log.h" #include "esp_system.h" @@ -41,7 +41,7 @@ static void example_espnow_deinit(example_espnow_send_param_t *send_param); /* WiFi should start before using ESPNOW */ static void example_wifi_init(void) { - tcpip_adapter_init(); + esp_netif_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); diff --git a/examples/wifi/fast_scan/main/fast_scan.c b/examples/wifi/fast_scan/main/fast_scan.c index 43df223e1c..185cacc0cb 100644 --- a/examples/wifi/fast_scan/main/fast_scan.c +++ b/examples/wifi/fast_scan/main/fast_scan.c @@ -85,7 +85,7 @@ static void event_handler(void* arg, esp_event_base_t event_base, /* Initialize Wi-Fi as sta and set scan method */ static void fast_scan(void) { - tcpip_adapter_init(); + esp_netif_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); @@ -94,6 +94,11 @@ static void fast_scan(void) ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL)); ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL)); + // Initialize default station as network interface instance (esp-netif) + esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta(); + assert(sta_netif); + + // Initialize and start WiFi wifi_config_t wifi_config = { .sta = { .ssid = DEFAULT_SSID, diff --git a/examples/wifi/iperf/main/cmd_wifi.c b/examples/wifi/iperf/main/cmd_wifi.c index 8bd3819a18..6710dcdee1 100644 --- a/examples/wifi/iperf/main/cmd_wifi.c +++ b/examples/wifi/iperf/main/cmd_wifi.c @@ -16,7 +16,7 @@ #include "freertos/FreeRTOS.h" #include "freertos/event_groups.h" #include "esp_wifi.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "esp_event.h" #include "iperf.h" @@ -48,6 +48,8 @@ static wifi_scan_arg_t scan_args; static wifi_args_t ap_args; static bool reconnect = true; static const char *TAG="cmd_wifi"; +static esp_netif_t *netif_ap = NULL; +static esp_netif_t *netif_sta = NULL; static EventGroupHandle_t wifi_event_group; const int CONNECTED_BIT = BIT0; @@ -106,9 +108,11 @@ void initialise_wifi(void) return; } - tcpip_adapter_init(); + esp_netif_init(); wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK( esp_event_loop_create_default() ); + assert(netif_ap = esp_netif_create_default_wifi_ap()); + assert(netif_sta = esp_netif_create_default_wifi_sta()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_SCAN_DONE, &scan_done_handler, NULL) ); @@ -266,22 +270,22 @@ static int wifi_cmd_query(int argc, char** argv) static uint32_t wifi_get_local_ip(void) { int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0); - tcpip_adapter_if_t ifx = TCPIP_ADAPTER_IF_AP; - tcpip_adapter_ip_info_t ip_info; + esp_netif_t * netif = netif_ap; + esp_netif_ip_info_t ip_info; wifi_mode_t mode; esp_wifi_get_mode(&mode); if (WIFI_MODE_STA == mode) { bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0); if (bits & CONNECTED_BIT) { - ifx = TCPIP_ADAPTER_IF_STA; + netif = netif_sta; } else { ESP_LOGE(TAG, "sta has no IP"); return 0; } } - tcpip_adapter_get_ip_info(ifx, &ip_info); + esp_netif_get_ip_info(netif, &ip_info); return ip_info.ip.addr; } diff --git a/examples/wifi/power_save/main/power_save.c b/examples/wifi/power_save/main/power_save.c index 21b7e7b51b..8e2a5ef6d9 100644 --- a/examples/wifi/power_save/main/power_save.c +++ b/examples/wifi/power_save/main/power_save.c @@ -55,8 +55,9 @@ static void event_handler(void* arg, esp_event_base_t event_base, /*init wifi as sta and set power save mode*/ static void wifi_power_save(void) { - tcpip_adapter_init(); + esp_netif_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); + assert(esp_netif_create_default_wifi_sta()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); diff --git a/examples/wifi/scan/main/scan.c b/examples/wifi/scan/main/scan.c index a3ab6253e1..d3759d3c98 100644 --- a/examples/wifi/scan/main/scan.c +++ b/examples/wifi/scan/main/scan.c @@ -114,8 +114,9 @@ static void print_cipher_type(int pairwise_cipher, int group_cipher) /* Initialize Wi-Fi as sta and set scan method */ static void wifi_scan(void) { - tcpip_adapter_init(); + esp_netif_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); + assert(esp_netif_create_default_wifi_sta()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); diff --git a/examples/wifi/simple_sniffer/main/simple_sniffer_example_main.c b/examples/wifi/simple_sniffer/main/simple_sniffer_example_main.c index e1a78a42ce..3a60fc0ba4 100644 --- a/examples/wifi/simple_sniffer/main/simple_sniffer_example_main.c +++ b/examples/wifi/simple_sniffer/main/simple_sniffer_example_main.c @@ -11,7 +11,7 @@ #include #include "linenoise/linenoise.h" #include "argtable3/argtable3.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "esp_console.h" #include "esp_event.h" #include "esp_vfs_dev.h" @@ -64,7 +64,7 @@ static void initialize_nvs(void) /* Initialize wifi with tcp/ip adapter */ static void initialize_wifi(void) { - tcpip_adapter_init(); + esp_netif_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); diff --git a/examples/wifi/smart_config/main/smartconfig_main.c b/examples/wifi/smart_config/main/smartconfig_main.c index 65e7c50331..62b3ab4a91 100644 --- a/examples/wifi/smart_config/main/smartconfig_main.c +++ b/examples/wifi/smart_config/main/smartconfig_main.c @@ -18,7 +18,7 @@ #include "esp_log.h" #include "esp_system.h" #include "nvs_flash.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "esp_smartconfig.h" /* FreeRTOS event group to signal when we are connected & ready to make a request */ @@ -78,9 +78,10 @@ static void event_handler(void* arg, esp_event_base_t event_base, static void initialise_wifi(void) { - tcpip_adapter_init(); + esp_netif_init(); s_wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK(esp_event_loop_create_default()); + assert(esp_netif_create_default_wifi_sta()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); diff --git a/examples/wifi/wpa2_enterprise/main/wpa2_enterprise_main.c b/examples/wifi/wpa2_enterprise/main/wpa2_enterprise_main.c index 00b6ff74f3..a9386a63d0 100644 --- a/examples/wifi/wpa2_enterprise/main/wpa2_enterprise_main.c +++ b/examples/wifi/wpa2_enterprise/main/wpa2_enterprise_main.c @@ -27,7 +27,7 @@ #include "esp_log.h" #include "esp_system.h" #include "nvs_flash.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" /* The examples use simple WiFi configuration that you can set via project configuration menu. @@ -48,6 +48,9 @@ /* FreeRTOS event group to signal when we are connected & ready to make a request */ static EventGroupHandle_t wifi_event_group; +/* esp netif object representing the WIFI station */ +static esp_netif_t *sta_netif = NULL; + /* The event group allows multiple bits for each event, but we only care about one event - are we connected to the AP with an IP? */ @@ -101,9 +104,11 @@ static void initialise_wifi(void) unsigned int client_key_bytes = client_key_end - client_key_start; #endif /* CONFIG_EXAMPLE_EAP_METHOD_TLS */ - tcpip_adapter_init(); + esp_netif_init(); wifi_event_group = xEventGroupCreate(); ESP_ERROR_CHECK(esp_event_loop_create_default()); + assert(sta_netif = esp_netif_create_default_wifi_sta()); + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL) ); @@ -139,14 +144,14 @@ static void initialise_wifi(void) static void wpa2_enterprise_example_task(void *pvParameters) { - tcpip_adapter_ip_info_t ip; - memset(&ip, 0, sizeof(tcpip_adapter_ip_info_t)); + esp_netif_ip_info_t ip; + memset(&ip, 0, sizeof(esp_netif_ip_info_t)); vTaskDelay(2000 / portTICK_PERIOD_MS); while (1) { vTaskDelay(2000 / portTICK_PERIOD_MS); - if (tcpip_adapter_get_ip_info(ESP_IF_WIFI_STA, &ip) == 0) { + if (esp_netif_get_ip_info(sta_netif, &ip) == 0) { ESP_LOGI(TAG, "~~~~~~~~~~~"); ESP_LOGI(TAG, "IP:"IPSTR, IP2STR(&ip.ip)); ESP_LOGI(TAG, "MASK:"IPSTR, IP2STR(&ip.netmask)); diff --git a/examples/wifi/wps/main/wps.c b/examples/wifi/wps/main/wps.c index 640ad952c6..17095e9316 100644 --- a/examples/wifi/wps/main/wps.c +++ b/examples/wifi/wps/main/wps.c @@ -97,8 +97,9 @@ static void got_ip_event_handler(void* arg, esp_event_base_t event_base, /*init wifi as sta and start wps*/ static void start_wps(void) { - tcpip_adapter_init(); + esp_netif_init(); ESP_ERROR_CHECK(esp_event_loop_create_default()); + assert(esp_netif_create_default_wifi_sta()); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); diff --git a/tools/unit-test-app/components/test_utils/test_utils.c b/tools/unit-test-app/components/test_utils/test_utils.c index ec45b85727..3624f1cfd4 100644 --- a/tools/unit-test-app/components/test_utils/test_utils.c +++ b/tools/unit-test-app/components/test_utils/test_utils.c @@ -17,7 +17,7 @@ #include "test_utils.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "tcpip_adapter.h" +#include "esp_netif.h" #include "lwip/sockets.h" const esp_partition_t *get_test_data_partition(void) @@ -32,7 +32,7 @@ const esp_partition_t *get_test_data_partition(void) void test_case_uses_tcpip(void) { // Can be called more than once, does nothing on subsequent calls - tcpip_adapter_init(); + esp_netif_init(); // Allocate all sockets then free them // (First time each socket is allocated some one-time allocations happen.) @@ -49,7 +49,7 @@ void test_case_uses_tcpip(void) // Allow LWIP tasks to finish initialising themselves vTaskDelay(25 / portTICK_RATE_MS); - printf("Note: tcpip_adapter_init() has been called. Until next reset, TCP/IP task will periodicially allocate memory and consume CPU time.\n"); + printf("Note: esp_netif_init() has been called. Until next reset, TCP/IP task will periodicially allocate memory and consume CPU time.\n"); // Reset the leak checker as LWIP allocates a lot of memory on first run unity_reset_leak_checks();