mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 17:19:09 -04:00
esp_netif and examples: using wifi driver handle, update examples and tests to pass the CI
This commit is contained in:
parent
4366347fd4
commit
3a19bf055d
@ -4,7 +4,6 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#include "unity.h"
|
||||
#include "test_utils.h"
|
||||
#include "esp_event.h"
|
||||
@ -15,6 +14,9 @@
|
||||
#include "lwip/sockets.h"
|
||||
#include "ping/ping_sock.h"
|
||||
|
||||
#define GOT_IP_BIT BIT(0)
|
||||
#define ETHERNET_GET_IP_TIMEOUT_MS (20000)
|
||||
|
||||
static const char *TAG = "esp_eth_test";
|
||||
|
||||
#define ETH_START_BIT BIT(0)
|
||||
@ -63,7 +65,6 @@ 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 esp_netif_ip_info_t *ip_info = &event->ip_info;
|
||||
|
||||
ESP_LOGI(TAG, "Ethernet Got IP Address");
|
||||
ESP_LOGI(TAG, "~~~~~~~~~~~");
|
||||
ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip));
|
||||
@ -148,6 +149,8 @@ TEST_CASE("esp32 ethernet event test", "[ethernet][test_env=UT_T2_Ethernet]")
|
||||
EventGroupHandle_t eth_event_group = xEventGroupCreate();
|
||||
TEST_ASSERT(eth_event_group != NULL);
|
||||
TEST_ESP_OK(esp_event_loop_create_default());
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
|
||||
esp_netif_t* eth_netif = esp_netif_new(&cfg);
|
||||
TEST_ESP_OK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, eth_event_group));
|
||||
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
|
||||
@ -156,6 +159,7 @@ TEST_CASE("esp32 ethernet event test", "[ethernet][test_env=UT_T2_Ethernet]")
|
||||
esp_eth_config_t eth_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));
|
||||
/* wait for connection start */
|
||||
bits = xEventGroupWaitBits(eth_event_group, ETH_START_BIT, true, true, pdMS_TO_TICKS(ETH_START_TIMEOUT_MS));
|
||||
TEST_ASSERT((bits & ETH_START_BIT) == ETH_START_BIT);
|
||||
@ -173,6 +177,7 @@ TEST_CASE("esp32 ethernet event test", "[ethernet][test_env=UT_T2_Ethernet]")
|
||||
TEST_ESP_OK(esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler));
|
||||
TEST_ESP_OK(esp_event_loop_delete_default());
|
||||
vEventGroupDelete(eth_event_group);
|
||||
esp_netif_destroy(eth_netif);
|
||||
}
|
||||
|
||||
TEST_CASE("esp32 ethernet dhcp test", "[ethernet][test_env=UT_T2_Ethernet]")
|
||||
@ -182,7 +187,10 @@ TEST_CASE("esp32 ethernet dhcp test", "[ethernet][test_env=UT_T2_Ethernet]")
|
||||
TEST_ASSERT(eth_event_group != NULL);
|
||||
test_case_uses_tcpip();
|
||||
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, eth_event_group));
|
||||
TEST_ESP_OK(esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, eth_event_group));
|
||||
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
||||
@ -192,6 +200,8 @@ TEST_CASE("esp32 ethernet dhcp test", "[ethernet][test_env=UT_T2_Ethernet]")
|
||||
esp_eth_config_t eth_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));
|
||||
|
||||
/* wait for IP lease */
|
||||
bits = xEventGroupWaitBits(eth_event_group, ETH_GOT_IP_BIT, true, true, pdMS_TO_TICKS(ETH_GET_IP_TIMEOUT_MS));
|
||||
TEST_ASSERT((bits & ETH_GOT_IP_BIT) == ETH_GOT_IP_BIT);
|
||||
@ -205,9 +215,10 @@ TEST_CASE("esp32 ethernet dhcp test", "[ethernet][test_env=UT_T2_Ethernet]")
|
||||
TEST_ESP_OK(mac->del(mac));
|
||||
TEST_ESP_OK(esp_event_handler_unregister(IP_EVENT, IP_EVENT_ETH_GOT_IP, got_ip_event_handler));
|
||||
TEST_ESP_OK(esp_event_handler_unregister(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler));
|
||||
TEST_ESP_OK(tcpip_adapter_clear_default_eth_handlers());
|
||||
TEST_ESP_OK(esp_eth_clear_default_handlers(eth_netif));
|
||||
TEST_ESP_OK(esp_event_loop_delete_default());
|
||||
vEventGroupDelete(eth_event_group);
|
||||
esp_netif_destroy(eth_netif);
|
||||
}
|
||||
|
||||
TEST_CASE("esp32 ethernet icmp test", "[ethernet][test_env=UT_T2_Ethernet]")
|
||||
|
@ -71,7 +71,7 @@ esp_netif_t* esp_netif_create_default_wifi_ap(void)
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_AP();
|
||||
esp_netif_t *netif = esp_netif_new(&cfg);
|
||||
assert(netif);
|
||||
esp_wifi_set_default_wifi_ap_handlers(netif);
|
||||
esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_AP, netif);
|
||||
return netif;
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ esp_netif_t* esp_netif_create_default_wifi_sta(void)
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_STA();
|
||||
esp_netif_t *netif = esp_netif_new(&cfg);
|
||||
assert(netif);
|
||||
esp_wifi_set_default_wifi_sta_handlers(netif);
|
||||
esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_STA, netif);
|
||||
return netif;
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ void esp_netif_action_connected(void *esp_netif, esp_event_base_t base, int32_t
|
||||
|
||||
void esp_netif_action_disconnected(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
ESP_LOGD(TAG, "esp_netif action connected with netif%p from event_id=%d", esp_netif, event_id);
|
||||
ESP_LOGD(TAG, "esp_netif action disconnected with netif%p from event_id=%d", esp_netif, event_id);
|
||||
esp_netif_down(esp_netif);
|
||||
|
||||
}
|
||||
|
@ -531,6 +531,15 @@ void esp_netif_set_ip4_addr(esp_ip4_addr_t *addr, uint8_t a, uint8_t b, uint8_t
|
||||
*/
|
||||
char * esp_ip4addr_ntoa(const esp_ip4_addr_t *addr, char *buf, int buflen);
|
||||
|
||||
/**
|
||||
* @brief Ascii internet address interpretation routine
|
||||
* The value returned is in network order.
|
||||
*
|
||||
* @param addr IP address in ascii representation (e.g. "127.0.0.1")
|
||||
* @return ip address in network order
|
||||
*/
|
||||
uint32_t esp_ip4addr_aton(const char *addr);
|
||||
|
||||
//
|
||||
// 6) Driver conversion utilities to related keys, flags, implementation handle, list of netifs
|
||||
//
|
||||
|
@ -36,7 +36,7 @@
|
||||
{ \
|
||||
.base = ESP_NETIF_BASE_DEFAULT_WIFI_AP, \
|
||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP, \
|
||||
.driver = ESP_NETIF_DRIVER_DEFAULT_WIFI_AP, \
|
||||
.driver = NULL, \
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,7 +46,7 @@
|
||||
{ \
|
||||
.base = ESP_NETIF_BASE_DEFAULT_WIFI_STA, \
|
||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA, \
|
||||
.driver = ESP_NETIF_DRIVER_DEFAULT_WIFI_STA, \
|
||||
.driver = NULL, \
|
||||
}
|
||||
/**
|
||||
* @brief Default base config (esp-netif inherent) of WIFI STA
|
||||
|
@ -201,6 +201,12 @@ char * esp_ip4addr_ntoa(const esp_ip4_addr_t *addr, char *buf, int buflen)
|
||||
return ip4addr_ntoa_r((ip4_addr_t *)addr, buf, buflen);
|
||||
}
|
||||
|
||||
uint32_t esp_ip4addr_aton(const char *addr)
|
||||
{
|
||||
return ipaddr_addr(addr);
|
||||
}
|
||||
|
||||
|
||||
esp_netif_iodriver_handle esp_netif_get_io_driver(esp_netif_t *esp_netif)
|
||||
{
|
||||
return esp_netif->driver_handle;
|
||||
@ -380,13 +386,25 @@ esp_netif_t *esp_netif_new(const esp_netif_config_t *esp_netif_config)
|
||||
return esp_netif;
|
||||
}
|
||||
|
||||
static void esp_netif_lwip_remove(esp_netif_t *esp_netif)
|
||||
{
|
||||
if (esp_netif->lwip_netif) {
|
||||
if (netif_is_up(esp_netif->lwip_netif)) {
|
||||
netif_set_down(esp_netif->lwip_netif);
|
||||
}
|
||||
netif_remove(esp_netif->lwip_netif);
|
||||
free(esp_netif->lwip_netif);
|
||||
esp_netif->lwip_netif = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void esp_netif_destroy(esp_netif_t *esp_netif)
|
||||
{
|
||||
if (esp_netif) {
|
||||
esp_netif_remove_from_list(esp_netif);
|
||||
free(esp_netif->ip_info);
|
||||
free(esp_netif->ip_info_old);
|
||||
free(esp_netif->lwip_netif);
|
||||
esp_netif_lwip_remove(esp_netif);
|
||||
free(esp_netif->if_key);
|
||||
free(esp_netif);
|
||||
}
|
||||
@ -536,7 +554,7 @@ static esp_err_t esp_netif_stop_api(esp_netif_api_msg_t *msg)
|
||||
}
|
||||
|
||||
if (!netif_is_up(lwip_netif)) {
|
||||
netif_remove(lwip_netif);
|
||||
esp_netif_lwip_remove(esp_netif);
|
||||
return ESP_ERR_ESP_NETIF_IF_NOT_READY;
|
||||
}
|
||||
|
||||
@ -556,7 +574,7 @@ static esp_err_t esp_netif_stop_api(esp_netif_api_msg_t *msg)
|
||||
}
|
||||
|
||||
netif_set_down(lwip_netif);
|
||||
netif_remove(lwip_netif);
|
||||
esp_netif_lwip_remove(esp_netif);
|
||||
esp_netif_update_default_netif(esp_netif, ESP_NETIF_STOPPED);;
|
||||
|
||||
return ESP_OK;
|
||||
@ -645,7 +663,19 @@ static void esp_netif_dhcpc_cb(struct netif *netif)
|
||||
|
||||
static void esp_netif_ip_lost_timer(void *arg)
|
||||
{
|
||||
esp_netif_t *esp_netif = (esp_netif_t*)arg;
|
||||
esp_netif_t *esp_netif = NULL;
|
||||
esp_netif_t *nif = esp_netif_next(NULL);
|
||||
do {
|
||||
if (nif && nif == arg) {
|
||||
esp_netif = nif;
|
||||
break;
|
||||
}
|
||||
} while (NULL != (nif = esp_netif_next(nif)));
|
||||
|
||||
if (esp_netif == NULL) {
|
||||
ESP_LOGD(TAG, "%s esp_netif not found in the list", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "%s esp_netif:%p", __func__, esp_netif);
|
||||
|
||||
|
@ -63,7 +63,6 @@
|
||||
#include "esp_wifi_types.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_private/esp_wifi_private.h"
|
||||
#include "esp_wifi_default.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -15,9 +15,6 @@
|
||||
#ifndef _ESP_WIFI_DEFAULT_H
|
||||
#define _ESP_WIFI_DEFAULT_H
|
||||
|
||||
#define ESP_NETIF_DRIVER_DEFAULT_WIFI_STA &_g_wifi_driver_sta_ifconfig
|
||||
#define ESP_NETIF_DRIVER_DEFAULT_WIFI_AP &_g_wifi_driver_ap_ifconfig
|
||||
|
||||
/**
|
||||
* @brief Sets default wifi event handlers for STA interface
|
||||
*
|
||||
@ -36,11 +33,19 @@ esp_err_t esp_wifi_set_default_wifi_sta_handlers(void *esp_netif);
|
||||
* @return
|
||||
* - ESP_OK on success, error returned from esp_event_handler_register if failed
|
||||
*/
|
||||
esp_err_t esp_wifi_set_default_wifi_driver_and_handlers(wifi_interface_t wifi_if, void *esp_netif);
|
||||
|
||||
esp_err_t esp_wifi_set_default_wifi_ap_handlers(void *esp_netif);
|
||||
|
||||
|
||||
extern const esp_netif_driver_ifconfig_t _g_wifi_driver_sta_ifconfig;
|
||||
extern const esp_netif_driver_ifconfig_t _g_wifi_driver_ap_ifconfig;
|
||||
/**
|
||||
* @brief Clears default wifi event handlers for supplied network interface
|
||||
*
|
||||
* @param esp_netif instance of corresponding if object
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success, error returned from esp_event_handler_register if failed
|
||||
*/
|
||||
esp_err_t esp_wifi_clear_default_wifi_driver_and_handlers(void *esp_netif);
|
||||
|
||||
|
||||
#endif //_ESP_WIFI_DEFAULT_H
|
||||
|
@ -22,33 +22,37 @@
|
||||
// Also this module holds esp-netif handles for AP and STA
|
||||
//
|
||||
|
||||
typedef struct wifi_netif_driver {
|
||||
esp_netif_driver_base_t base;
|
||||
wifi_interface_t wifi_if;
|
||||
}* wifi_netif_driver_t;
|
||||
|
||||
static const char* TAG = "wifi_init_default";
|
||||
|
||||
static esp_netif_t *sta_netif = NULL;
|
||||
static esp_netif_t *ap_netif = NULL;
|
||||
static bool wifi_default_handlers_set = false;
|
||||
#define MAX_WIFI_IFS (2)
|
||||
|
||||
static esp_netif_t *s_wifi_netifs[MAX_WIFI_IFS] = { NULL };
|
||||
static bool wifi_default_handlers_set = false;
|
||||
|
||||
static esp_err_t wifi_sta_receive(void *buffer, uint16_t len, void *eb)
|
||||
{
|
||||
return esp_netif_receive(sta_netif, buffer, len, eb);
|
||||
return esp_netif_receive(s_wifi_netifs[WIFI_IF_STA], buffer, len, eb);
|
||||
}
|
||||
|
||||
static esp_err_t wifi_ap_receive(void *buffer, uint16_t len, void *eb)
|
||||
{
|
||||
return esp_netif_receive(ap_netif, buffer, len, eb);
|
||||
return esp_netif_receive(s_wifi_netifs[WIFI_IF_AP], buffer, len, eb);
|
||||
}
|
||||
|
||||
|
||||
void wifi_free(void *h, void* buffer)
|
||||
{
|
||||
esp_wifi_internal_free_rx_buffer(buffer);
|
||||
}
|
||||
|
||||
|
||||
esp_err_t wifi_transmit(void *h, void *buffer, size_t len)
|
||||
{
|
||||
return esp_wifi_internal_tx((wifi_interface_t)h, buffer, len);
|
||||
wifi_netif_driver_t driver = h;
|
||||
return esp_wifi_internal_tx(driver->wifi_if, buffer, len);
|
||||
}
|
||||
|
||||
void wifi_start(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data)
|
||||
@ -58,7 +62,8 @@ void wifi_start(void *esp_netif, esp_event_base_t base, int32_t event_id, void *
|
||||
uint8_t mac[6];
|
||||
esp_err_t ret;
|
||||
|
||||
wifi_interface_t wifi_interface = (wifi_interface_t) esp_netif_get_io_driver(esp_netif);
|
||||
wifi_netif_driver_t driver = esp_netif_get_io_driver(esp_netif);
|
||||
wifi_interface_t wifi_interface = driver->wifi_if;
|
||||
|
||||
if ((ret = esp_wifi_get_mac(wifi_interface, mac)) != ESP_OK) {
|
||||
ESP_LOGE(TAG, "esp_wifi_get_mac failed with %d", ret);
|
||||
@ -81,21 +86,21 @@ void wifi_start(void *esp_netif, esp_event_base_t base, int32_t event_id, void *
|
||||
|
||||
static void wifi_default_action_sta_start(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
if (sta_netif != NULL) {
|
||||
wifi_start(sta_netif, base, event_id, data);
|
||||
if (s_wifi_netifs[WIFI_IF_STA] != NULL) {
|
||||
wifi_start(s_wifi_netifs[WIFI_IF_STA], base, event_id, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void wifi_default_action_sta_stop(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
if (sta_netif != NULL) {
|
||||
esp_netif_action_stop(sta_netif, base, event_id, data);
|
||||
if (s_wifi_netifs[WIFI_IF_STA] != NULL) {
|
||||
esp_netif_action_stop(s_wifi_netifs[WIFI_IF_STA], base, event_id, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void wifi_default_action_sta_connected(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
if (sta_netif != NULL) {
|
||||
if (s_wifi_netifs[WIFI_IF_STA] != NULL) {
|
||||
esp_err_t ret;
|
||||
// By default register wifi rxcb once the STA gets connected
|
||||
if ((ret = esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, wifi_sta_receive)) != ESP_OK) {
|
||||
@ -103,40 +108,40 @@ static void wifi_default_action_sta_connected(void *arg, esp_event_base_t base,
|
||||
return;
|
||||
}
|
||||
|
||||
esp_netif_action_connected(sta_netif, base, event_id, data);
|
||||
esp_netif_action_connected(s_wifi_netifs[WIFI_IF_STA], base, event_id, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void wifi_default_action_sta_disconnected(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
if (sta_netif != NULL) {
|
||||
esp_netif_action_disconnected(sta_netif, base, event_id, data);
|
||||
if (s_wifi_netifs[WIFI_IF_STA] != NULL) {
|
||||
esp_netif_action_disconnected(s_wifi_netifs[WIFI_IF_STA], base, event_id, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void wifi_default_action_ap_start(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
if (ap_netif != NULL) {
|
||||
wifi_start(ap_netif, base, event_id, data);
|
||||
if (s_wifi_netifs[WIFI_IF_AP] != NULL) {
|
||||
wifi_start(s_wifi_netifs[WIFI_IF_AP], base, event_id, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void wifi_default_action_ap_stop(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
if (ap_netif != NULL) {
|
||||
esp_netif_action_stop(ap_netif, base, event_id, data);
|
||||
if (s_wifi_netifs[WIFI_IF_AP] != NULL) {
|
||||
esp_netif_action_stop(s_wifi_netifs[WIFI_IF_AP], base, event_id, data);
|
||||
}
|
||||
}
|
||||
|
||||
static void wifi_default_action_sta_got_ip(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
if (sta_netif != NULL) {
|
||||
if (s_wifi_netifs[WIFI_IF_STA] != NULL) {
|
||||
ESP_LOGD(TAG, "Got IP wifi default handler entered");
|
||||
int ret = esp_wifi_internal_set_sta_ip();
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGI(TAG, "esp_wifi_internal_set_sta_ip failed with %d", ret);
|
||||
}
|
||||
esp_netif_action_got_ip(sta_netif, base, event_id, data);
|
||||
esp_netif_action_got_ip(s_wifi_netifs[WIFI_IF_STA], base, event_id, data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,16 +159,40 @@ esp_err_t esp_wifi_clear_default_wifi_handlers(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void _esp_wifi_set_default_ap_netif(esp_netif_t* esp_netif)
|
||||
static esp_err_t wifi_driver_start(esp_netif_t * esp_netif, void * args)
|
||||
{
|
||||
assert(esp_netif);
|
||||
ap_netif = esp_netif;
|
||||
wifi_netif_driver_t driver = args;
|
||||
driver->base.netif = esp_netif;
|
||||
esp_netif_driver_ifconfig_t driver_ifconfig = {
|
||||
.handle = driver,
|
||||
.transmit = wifi_transmit,
|
||||
.driver_free_rx_buffer = wifi_free
|
||||
};
|
||||
|
||||
return esp_netif_set_driver_config(esp_netif, &driver_ifconfig);
|
||||
}
|
||||
|
||||
void _esp_wifi_set_default_sta_netif(esp_netif_t* esp_netif)
|
||||
static esp_err_t disconnect_and_destroy(esp_netif_t* esp_netif)
|
||||
{
|
||||
assert(esp_netif);
|
||||
sta_netif = esp_netif;
|
||||
wifi_netif_driver_t driver = esp_netif_get_io_driver(esp_netif);
|
||||
driver->base.netif = NULL;
|
||||
esp_netif_driver_ifconfig_t driver_ifconfig = { };
|
||||
esp_err_t ret = esp_netif_set_driver_config(esp_netif, &driver_ifconfig);
|
||||
free(driver);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static esp_err_t create_and_attach(wifi_interface_t wifi_if, esp_netif_t* esp_netif)
|
||||
{
|
||||
wifi_netif_driver_t driver = calloc(1, sizeof(struct wifi_netif_driver));
|
||||
if (driver == NULL) {
|
||||
ESP_LOGE(TAG, "No memory to create a wifi driver");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
driver->wifi_if = wifi_if;
|
||||
driver->base.post_attach = wifi_driver_start;
|
||||
esp_netif_attach(esp_netif, driver);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t _esp_wifi_set_default_wifi_handlers(void)
|
||||
@ -219,26 +248,32 @@ fail:
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t esp_wifi_set_default_wifi_sta_handlers(void *esp_netif)
|
||||
esp_err_t esp_wifi_set_default_wifi_driver_and_handlers(wifi_interface_t wifi_if, void *esp_netif)
|
||||
{
|
||||
_esp_wifi_set_default_sta_netif(esp_netif);
|
||||
assert(esp_netif);
|
||||
assert(wifi_if < MAX_WIFI_IFS);
|
||||
s_wifi_netifs[wifi_if] = esp_netif;
|
||||
ESP_ERROR_CHECK(create_and_attach(wifi_if, esp_netif));
|
||||
return _esp_wifi_set_default_wifi_handlers();
|
||||
}
|
||||
|
||||
esp_err_t esp_wifi_set_default_wifi_ap_handlers(void *esp_netif)
|
||||
esp_err_t esp_wifi_clear_default_wifi_driver_and_handlers(void *esp_netif)
|
||||
{
|
||||
_esp_wifi_set_default_ap_netif(esp_netif);
|
||||
return _esp_wifi_set_default_wifi_handlers();
|
||||
int i;
|
||||
for (i = 0; i< MAX_WIFI_IFS; ++i) {
|
||||
// clear internal static pointers to netifs
|
||||
if (s_wifi_netifs[i] == esp_netif) {
|
||||
s_wifi_netifs[i] = NULL;
|
||||
}
|
||||
// check if all netifs are cleared to delete default handlers
|
||||
if (s_wifi_netifs[i] != NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == MAX_WIFI_IFS) { // if all wifi default netifs are null
|
||||
ESP_LOGD(TAG, "Clearing wifi default handlers");
|
||||
esp_wifi_clear_default_wifi_handlers();
|
||||
}
|
||||
return disconnect_and_destroy(esp_netif);
|
||||
}
|
||||
|
||||
const esp_netif_driver_ifconfig_t _g_wifi_driver_sta_ifconfig = {
|
||||
.handle = (void*)WIFI_IF_STA,
|
||||
.transmit = wifi_transmit,
|
||||
.driver_free_rx_buffer = wifi_free,
|
||||
};
|
||||
|
||||
const esp_netif_driver_ifconfig_t _g_wifi_driver_ap_ifconfig = {
|
||||
.handle = (void*)WIFI_IF_AP,
|
||||
.transmit = wifi_transmit,
|
||||
.driver_free_rx_buffer = wifi_free,
|
||||
};
|
||||
|
@ -80,6 +80,9 @@ static esp_err_t event_init(void)
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
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, ESP_EVENT_ANY_ID, &ip_event_handler, NULL));
|
||||
esp_netif_create_default_wifi_sta();
|
||||
esp_netif_create_default_wifi_ap();
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ static void ip_event_handler(void* arg, esp_event_base_t event_base, int32_t eve
|
||||
case IP_EVENT_STA_GOT_IP:
|
||||
event = (ip_event_got_ip_t*)event_data;
|
||||
ESP_LOGI(TAG, "IP_EVENT_STA_GOT_IP");
|
||||
ESP_LOGI(TAG, "got ip:%s\n", ip4addr_ntoa(&event->ip_info.ip));
|
||||
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
|
||||
if (wifi_events) {
|
||||
xEventGroupSetBits(wifi_events, GOT_IP_EVENT);
|
||||
}
|
||||
@ -123,9 +123,9 @@ static void wifi_start_stop_task(void* arg)
|
||||
r = nvs_flash_init();
|
||||
}
|
||||
TEST_ESP_OK(r);
|
||||
//init tcpip
|
||||
ESP_LOGI(TAG, EMPH_STR("tcpip_adapter_init"));
|
||||
tcpip_adapter_init();
|
||||
//init tcpip stack
|
||||
ESP_LOGI(TAG, EMPH_STR("esp_netif_init"));
|
||||
esp_netif_init();
|
||||
//init event loop
|
||||
ESP_LOGI(TAG, EMPH_STR("event_init"));
|
||||
event_init();
|
||||
|
@ -106,6 +106,12 @@ esp_err_t tcpip_adapter_eth_input(void *buffer, uint16_t len, void *eb);
|
||||
*/
|
||||
esp_err_t tcpip_adapter_clear_default_wifi_handlers(void);
|
||||
|
||||
/**
|
||||
* @brief Compatible version of former tcpip_adapter API to clear default ethernet handlers
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t tcpip_adapter_clear_default_eth_handlers(void);
|
||||
|
||||
/**
|
||||
* @brief Compatible version of former tcpip_adapter API of esp_netif_dhcps_stop
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "esp_eth.h"
|
||||
#include "tcpip_adapter_types.h"
|
||||
#include "esp_wifi_default.h"
|
||||
|
||||
extern void _esp_wifi_set_default_ap_netif(esp_netif_t* esp_netif);
|
||||
extern void _esp_wifi_set_default_sta_netif(esp_netif_t* esp_netif);
|
||||
@ -52,7 +53,7 @@ static void wifi_create_and_start_ap(void *esp_netif, esp_event_base_t base, int
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_AP();
|
||||
esp_netif_t *ap_netif = esp_netif_new(&cfg);
|
||||
|
||||
_esp_wifi_set_default_ap_netif(ap_netif);
|
||||
esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_AP, ap_netif);
|
||||
s_esp_netifs[TCPIP_ADAPTER_IF_AP] = ap_netif;
|
||||
}
|
||||
}
|
||||
@ -63,7 +64,7 @@ static void wifi_create_and_start_sta(void *esp_netif, esp_event_base_t base, in
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_STA();
|
||||
esp_netif_t *sta_netif = esp_netif_new(&cfg);
|
||||
|
||||
_esp_wifi_set_default_sta_netif(sta_netif);
|
||||
esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_STA, sta_netif);
|
||||
s_esp_netifs[TCPIP_ADAPTER_IF_STA] = sta_netif;
|
||||
}
|
||||
}
|
||||
@ -104,6 +105,11 @@ static void tcpip_adapter_eth_start(void *esp_netif, esp_event_base_t base, int3
|
||||
esp_netif_attach(esp_netif, eth_handle);
|
||||
}
|
||||
|
||||
esp_err_t tcpip_adapter_clear_default_eth_handlers(void)
|
||||
{
|
||||
return esp_eth_clear_default_handlers(netif_from_if(TCPIP_ADAPTER_IF_ETH));
|
||||
}
|
||||
|
||||
esp_err_t tcpip_adapter_set_default_eth_handlers(void)
|
||||
{
|
||||
if (s_tcpip_adapter_compat) {
|
||||
|
@ -335,7 +335,7 @@ static int wifi_cmd_iperf(int argc, char **argv)
|
||||
if (iperf_args.ip->count == 0) {
|
||||
cfg.flag |= IPERF_FLAG_SERVER;
|
||||
} else {
|
||||
cfg.dip = ipaddr_addr(iperf_args.ip->sval[0]);
|
||||
cfg.dip = esp_ip4addr_aton(iperf_args.ip->sval[0]);
|
||||
cfg.flag |= IPERF_FLAG_CLIENT;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_wifi_default.h"
|
||||
#if CONFIG_EXAMPLE_CONNECT_ETHERNET
|
||||
#include "esp_eth.h"
|
||||
#endif
|
||||
@ -136,7 +137,7 @@ static void start(void)
|
||||
|
||||
assert(netif);
|
||||
|
||||
esp_wifi_set_default_wifi_sta_handlers(netif);
|
||||
esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_STA, netif);
|
||||
|
||||
s_example_esp_netif = netif;
|
||||
|
||||
@ -176,7 +177,7 @@ static void stop(void)
|
||||
}
|
||||
ESP_ERROR_CHECK(err);
|
||||
ESP_ERROR_CHECK(esp_wifi_deinit());
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_clear_default_wifi_driver_and_handlers(s_example_esp_netif));
|
||||
esp_netif_destroy(s_example_esp_netif);
|
||||
s_example_esp_netif = NULL;
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ static int eth_cmd_iperf(int argc, char **argv)
|
||||
}
|
||||
/* iperf -c SERVER_ADDRESS */
|
||||
else {
|
||||
cfg.dip = ipaddr_addr(iperf_args.ip->sval[0]);
|
||||
cfg.dip = esp_ip4addr_aton(iperf_args.ip->sval[0]);
|
||||
cfg.flag |= IPERF_FLAG_CLIENT;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_wifi_default.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
@ -384,11 +385,10 @@ static esp_err_t create_wifi_netifs(void)
|
||||
esp_netif_config_t cfg_ap = {
|
||||
.base = &netif_cfg,
|
||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP,
|
||||
.driver = ESP_NETIF_DRIVER_DEFAULT_WIFI_AP,
|
||||
};
|
||||
esp_netif_t *netif_ap = esp_netif_new(&cfg_ap);
|
||||
assert(netif_ap);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_default_wifi_ap_handlers(netif_ap));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_AP, netif_ap));
|
||||
|
||||
|
||||
memcpy(&netif_cfg, ESP_NETIF_BASE_DEFAULT_WIFI_STA, sizeof(netif_cfg));
|
||||
@ -396,12 +396,11 @@ static esp_err_t create_wifi_netifs(void)
|
||||
esp_netif_config_t cfg_sta = {
|
||||
.base = &netif_cfg,
|
||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA,
|
||||
.driver = ESP_NETIF_DRIVER_DEFAULT_WIFI_STA,
|
||||
};
|
||||
|
||||
netif_sta = esp_netif_new(&cfg_sta);
|
||||
assert(netif_sta);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_default_wifi_sta_handlers(netif_sta));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_STA, netif_sta));
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_wifi_default.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
@ -308,11 +309,10 @@ static esp_err_t create_wifi_netifs(void)
|
||||
esp_netif_config_t cfg_ap = {
|
||||
.base = &netif_cfg,
|
||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP,
|
||||
.driver = ESP_NETIF_DRIVER_DEFAULT_WIFI_AP,
|
||||
};
|
||||
esp_netif_t *netif_ap = esp_netif_new(&cfg_ap);
|
||||
assert(netif_ap);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_default_wifi_ap_handlers(netif_ap));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_AP, netif_ap));
|
||||
|
||||
|
||||
memcpy(&netif_cfg, ESP_NETIF_BASE_DEFAULT_WIFI_STA, sizeof(netif_cfg));
|
||||
@ -320,12 +320,11 @@ static esp_err_t create_wifi_netifs(void)
|
||||
esp_netif_config_t cfg_sta = {
|
||||
.base = &netif_cfg,
|
||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA,
|
||||
.driver = ESP_NETIF_DRIVER_DEFAULT_WIFI_STA,
|
||||
};
|
||||
|
||||
netif_sta = esp_netif_new(&cfg_sta);
|
||||
assert(netif_sta);
|
||||
ESP_ERROR_CHECK(esp_wifi_set_default_wifi_sta_handlers(netif_sta));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_default_wifi_driver_and_handlers(ESP_IF_WIFI_STA, netif_sta));
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "chat_message.hpp"
|
||||
#include "protocol_examples_common.h"
|
||||
#include "esp_event.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
using asio::ip::tcp;
|
||||
@ -137,7 +136,7 @@ void read_line(char * line, int max_chars);
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
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.
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include "chat_message.hpp"
|
||||
#include "protocol_examples_common.h"
|
||||
#include "esp_event.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
|
||||
@ -205,7 +204,7 @@ private:
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
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.
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <iostream>
|
||||
#include "protocol_examples_common.h"
|
||||
#include "esp_event.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
using asio::ip::tcp;
|
||||
@ -87,7 +86,7 @@ private:
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
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.
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include "protocol_examples_common.h"
|
||||
#include "esp_event.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
|
||||
@ -69,7 +68,7 @@ private:
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
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.
|
||||
|
@ -21,6 +21,7 @@ extern "C" {
|
||||
#include "esp_modem_dte.h"
|
||||
#include "esp_event.h"
|
||||
#include "driver/uart.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
|
||||
/**
|
||||
* @brief Declare Event Base for ESP Modem
|
||||
|
@ -315,7 +315,7 @@ static int wifi_cmd_iperf(int argc, char** argv)
|
||||
if (iperf_args.ip->count == 0) {
|
||||
cfg.flag |= IPERF_FLAG_SERVER;
|
||||
} else {
|
||||
cfg.dip = ipaddr_addr(iperf_args.ip->sval[0]);
|
||||
cfg.dip = esp_ip4addr_aton(iperf_args.ip->sval[0]);
|
||||
cfg.flag |= IPERF_FLAG_CLIENT;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user