mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-18 23:54:39 +00:00
esp_mesh: creation of wifi network interfaces for esp-mesh examples moved to used common esp_wifi_default API
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "esp_log.h"
|
||||
#include "esp_private/wifi.h"
|
||||
#include "esp_wifi_netif.h"
|
||||
#include <string.h>
|
||||
|
||||
//
|
||||
// Purpose of this module is to provide basic wifi initialization setup for
|
||||
@@ -318,4 +319,50 @@ esp_netif_t* esp_netif_create_default_wifi_sta(void)
|
||||
esp_netif_attach_wifi_station(netif);
|
||||
esp_wifi_set_default_wifi_sta_handlers();
|
||||
return netif;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Creates mesh network interfaces based on default STA and AP,
|
||||
* but without DHCP, this is to be enabled separately only on root node
|
||||
*/
|
||||
esp_err_t esp_netif_create_default_wifi_mesh_netifs(esp_netif_t **p_netif_sta, esp_netif_t **p_netif_ap)
|
||||
{
|
||||
// Create "almost" default AP, with un-flagged DHCP server
|
||||
esp_netif_inherent_config_t netif_cfg;
|
||||
memcpy(&netif_cfg, ESP_NETIF_BASE_DEFAULT_WIFI_AP, sizeof(netif_cfg));
|
||||
netif_cfg.flags &= ~ESP_NETIF_DHCPS;
|
||||
esp_netif_config_t cfg_ap = {
|
||||
.base = &netif_cfg,
|
||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP,
|
||||
};
|
||||
esp_netif_t *netif_ap = esp_netif_new(&cfg_ap);
|
||||
assert(netif_ap);
|
||||
ESP_ERROR_CHECK(esp_netif_attach_wifi_ap(netif_ap));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_default_wifi_ap_handlers());
|
||||
|
||||
// ...and stop DHCP server to be compatible with former tcpip_adapter (to keep the ESP_NETIF_DHCP_STOPPED state)
|
||||
ESP_ERROR_CHECK(esp_netif_dhcps_stop(netif_ap));
|
||||
|
||||
// Create "almost" default station, but with un-flagged DHCP client
|
||||
memcpy(&netif_cfg, ESP_NETIF_BASE_DEFAULT_WIFI_STA, sizeof(netif_cfg));
|
||||
netif_cfg.flags &= ~ESP_NETIF_DHCPC;
|
||||
esp_netif_config_t cfg_sta = {
|
||||
.base = &netif_cfg,
|
||||
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA,
|
||||
};
|
||||
esp_netif_t *netif_sta = esp_netif_new(&cfg_sta);
|
||||
assert(netif_sta);
|
||||
ESP_ERROR_CHECK(esp_netif_attach_wifi_station(netif_sta));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_default_wifi_sta_handlers());
|
||||
|
||||
// ...and stop DHCP client (to be started separately if the station were promoted to root)
|
||||
ESP_ERROR_CHECK(esp_netif_dhcpc_stop(netif_sta));
|
||||
|
||||
if (p_netif_sta) {
|
||||
*p_netif_sta = netif_sta;
|
||||
}
|
||||
if (p_netif_ap) {
|
||||
*p_netif_ap = netif_ap;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
Reference in New Issue
Block a user