ESP32-IDF
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Data Structures | Macros | Typedefs | Enumerations | Functions
esp_wifi.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "esp_err.h"
#include "rom/queue.h"

Go to the source code of this file.

Data Structures

struct  wifi_init_config_t
 
struct  wifi_scan_config_t
 
struct  wifi_ap_list_t
 
struct  wifi_ap_config_t
 
struct  wifi_sta_config_t
 
union  wifi_config_t
 
struct  station_info
 

Macros

#define WIFI_INIT_CONFIG_DEFAULT(event_queue_)
 
#define WIFI_PROTOCOL_11B   1
 
#define WIFI_PROTOCOL_11G   2
 
#define WIFI_PROTOCOL_11N   4
 

Typedefs

typedef void(* wifi_promiscuous_cb_t )(void *buf, uint16_t len)
 The RX callback function in the promiscuous mode. More...
 
typedef esp_err_t(* wifi_rxcb_t )(void *buffer, uint16_t len, void *eb)
 The WiFi RX callback function. More...
 
typedef void(* esp_vendor_ie_cb_t )(void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const uint8_t *vnd_ie, int rssi)
 Define function pointer for vendor specific element callback. More...
 

Enumerations

enum  wifi_mode_t {
  WIFI_MODE_NULL = 0, WIFI_MODE_STA, WIFI_MODE_AP, WIFI_MODE_APSTA,
  WIFI_MODE_MAX
}
 
enum  wifi_interface_t { WIFI_IF_STA = 0, WIFI_IF_AP, WIFI_IF_MAX }
 
enum  wifi_country_t {
  WIFI_COUNTRY_CN = 0, WIFI_COUNTRY_JP, WIFI_COUNTRY_US, WIFI_COUNTRY_EU,
  WIFI_COUNTRY_MAX
}
 
enum  wifi_auth_mode_t {
  WIFI_AUTH_OPEN = 0, WIFI_AUTH_WEP, WIFI_AUTH_WPA_PSK, WIFI_AUTH_WPA2_PSK,
  WIFI_AUTH_WPA_WPA2_PSK, WIFI_AUTH_MAX
}
 
enum  {
  WIFI_REASON_UNSPECIFIED = 1, WIFI_REASON_AUTH_EXPIRE = 2, WIFI_REASON_AUTH_LEAVE = 3, WIFI_REASON_ASSOC_EXPIRE = 4,
  WIFI_REASON_ASSOC_TOOMANY = 5, WIFI_REASON_NOT_AUTHED = 6, WIFI_REASON_NOT_ASSOCED = 7, WIFI_REASON_ASSOC_LEAVE = 8,
  WIFI_REASON_ASSOC_NOT_AUTHED = 9, WIFI_REASON_DISASSOC_PWRCAP_BAD = 10, WIFI_REASON_DISASSOC_SUPCHAN_BAD = 11, WIFI_REASON_IE_INVALID = 13,
  WIFI_REASON_MIC_FAILURE = 14, WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT = 15, WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT = 16, WIFI_REASON_IE_IN_4WAY_DIFFERS = 17,
  WIFI_REASON_GROUP_CIPHER_INVALID = 18, WIFI_REASON_PAIRWISE_CIPHER_INVALID = 19, WIFI_REASON_AKMP_INVALID = 20, WIFI_REASON_UNSUPP_RSN_IE_VERSION = 21,
  WIFI_REASON_INVALID_RSN_IE_CAP = 22, WIFI_REASON_802_1X_AUTH_FAILED = 23, WIFI_REASON_CIPHER_SUITE_REJECTED = 24, WIFI_REASON_BEACON_TIMEOUT = 200,
  WIFI_REASON_NO_AP_FOUND = 201, WIFI_REASON_AUTH_FAIL = 202, WIFI_REASON_ASSOC_FAIL = 203, WIFI_REASON_HANDSHAKE_TIMEOUT = 204
}
 
enum  wifi_second_chan_t { WIFI_SECOND_CHAN_NONE = 0, WIFI_SECOND_CHAN_ABOVE, WIFI_SECOND_CHAN_BELOW }
 
enum  wifi_ps_type_t { WIFI_PS_NONE, WIFI_PS_MODEM, WIFI_PS_LIGHT, WIFI_PS_MAC }
 
enum  wifi_bandwidth_t { WIFI_BW_HT20 = 0, WIFI_BW_HT40 }
 
enum  wifi_storage_t { WIFI_STORAGE_FLASH, WIFI_STORAGE_RAM }
 
enum  wifi_vendor_ie_type_t {
  WIFI_VND_IE_TYPE_BEACON, WIFI_VND_IE_TYPE_PROBE_REQ, WIFI_VND_IE_TYPE_PROBE_RESP, WIFI_VND_IE_TYPE_ASSOC_REQ,
  WIFI_VND_IE_TYPE_ASSOC_RESP
}
 Vendor IE type. More...
 
enum  wifi_vendor_ie_id_t { WIFI_VND_IE_ID_0, WIFI_VND_IE_ID_1 }
 Vendor IE index. More...
 

Functions

esp_err_t esp_wifi_init (wifi_init_config_t *config)
 Init WiFi Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer, WiFi NVS structure etc, this WiFi also start WiFi task. More...
 
esp_err_t esp_wifi_deinit (void)
 Deinit WiFi Free all resource allocated in esp_wifi_init and stop WiFi task. More...
 
esp_err_t esp_wifi_set_mode (wifi_mode_t mode)
 Set the WiFi operating mode. More...
 
esp_err_t esp_wifi_get_mode (wifi_mode_t *mode)
 Get current operating mode of WiFi. More...
 
esp_err_t esp_wifi_start (void)
 Start WiFi according to current configuration If mode is WIFI_MODE_STA, it create station control block and start station If mode is WIFI_MODE_AP, it create soft-AP control block and start soft-AP If mode is WIFI_MODE_APSTA, it create soft-AP and station control block and start soft-AP and station. More...
 
esp_err_t esp_wifi_stop (void)
 Stop WiFi If mode is WIFI_MODE_STA, it stop station and free station control block If mode is WIFI_MODE_AP, it stop soft-AP and free soft-AP control block If mode is WIFI_MODE_APSTA, it stop station/soft-AP and free station/soft-AP control block. More...
 
esp_err_t esp_wifi_connect (void)
 Connect the ESP32 WiFi station to the AP. More...
 
esp_err_t esp_wifi_disconnect (void)
 Disconnect the ESP32 WiFi station from the AP. More...
 
esp_err_t esp_wifi_clear_fast_connect (void)
 Currently this API is just an stub API. More...
 
esp_err_t esp_wifi_kick_station (uint16_t aid)
 Kick the all station or associated id equals to aid. More...
 
esp_err_t esp_wifi_scan_start (wifi_scan_config_t *conf, bool block)
 Scan all available APs. More...
 
esp_err_t esp_wifi_scan_stop (void)
 Stop the scan in process. More...
 
esp_err_t esp_wifi_get_ap_num (uint16_t *number)
 Get number of APs found in last scan. More...
 
esp_err_t esp_wifi_get_ap_list (uint16_t *number, wifi_ap_list_t *ap_list)
 Get AP list found in last scan. More...
 
esp_err_t esp_wifi_set_ps (wifi_ps_type_t type)
 Set current power save type. More...
 
esp_err_t esp_wifi_get_ps (wifi_ps_type_t *type)
 Get current power save type. More...
 
esp_err_t esp_wifi_set_protocol (wifi_interface_t ifx, uint8_t protocol_bitmap)
 Set protocol type of specified interface The default protocol is (WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N) More...
 
esp_err_t esp_wifi_get_protocol (wifi_interface_t ifx, uint8_t *protocol_bitmap)
 Get the current protocol bitmap of specified ifx. More...
 
esp_err_t esp_wifi_set_bandwidth (wifi_interface_t ifx, wifi_bandwidth_t bw)
 Set the bandwidth of ESP32 specified interface. More...
 
esp_err_t esp_wifi_get_bandwidth (wifi_interface_t ifx, wifi_bandwidth_t *bw)
 Get the bandwidth of ESP32 specified interface. More...
 
esp_err_t esp_wifi_set_channel (uint8_t primary, wifi_second_chan_t second)
 Set primary/second channel of ESP32. More...
 
esp_err_t esp_wifi_get_channel (uint8_t *primary, wifi_second_chan_t *second)
 Get the primary/second channel of ESP32. More...
 
esp_err_t esp_wifi_set_country (wifi_country_t country)
 Set country code The default value is WIFI_COUNTRY_CN. More...
 
esp_err_t esp_wifi_get_country (wifi_country_t *country)
 Get country code. More...
 
esp_err_t esp_wifi_set_mac (wifi_interface_t ifx, uint8_t mac[6])
 Set MAC address of the ESP32 WiFi station or the soft-AP interface. More...
 
esp_err_t esp_wifi_get_mac (wifi_interface_t ifx, uint8_t mac[6])
 Get mac of specified interface. More...
 
esp_err_t esp_wifi_set_promiscuous_rx_cb (wifi_promiscuous_cb_t cb)
 Register the RX callback function in the promiscuous mode. More...
 
esp_err_t esp_wifi_set_promiscuous (uint8_t enable)
 Enable the promiscuous mode. More...
 
esp_err_t esp_wifi_get_promiscuous (uint8_t *enable)
 Get the promiscuous mode. More...
 
esp_err_t esp_wifi_set_config (wifi_interface_t ifx, wifi_config_t *conf)
 Set the configuration of the ESP32 STA or AP. More...
 
esp_err_t esp_wifi_get_config (wifi_interface_t ifx, wifi_config_t *conf)
 Get configuration of specified interface. More...
 
esp_err_t esp_wifi_get_station_list (struct station_info **station)
 Get STAs associated with soft-AP. More...
 
esp_err_t esp_wifi_free_station_list (void)
 
esp_err_t esp_wifi_set_storage (wifi_storage_t storage)
 Set the WiFi API configuration storage type. More...
 
esp_err_t esp_wifi_reg_rxcb (wifi_interface_t ifx, wifi_rxcb_t fn)
 Set the WiFi RX callback. More...
 
esp_err_t esp_wifi_set_auto_connect (bool en)
 Set auto connect The default value is true. More...
 
esp_err_t esp_wifi_get_auto_connect (bool *en)
 Get the auto connect flag. More...
 
esp_err_t esp_wifi_set_vendor_ie (bool enable, wifi_vendor_ie_type_t type, wifi_vendor_ie_id_t idx, uint8_t *vnd_ie)
 Set vendor specific element. More...
 
esp_err_t esp_wifi_set_vendor_ie_cb (esp_vendor_ie_cb_t cb, void *ctx)
 Set vendor specific element callback. More...
 

Macro Definition Documentation

#define WIFI_INIT_CONFIG_DEFAULT (   event_queue_)
Value:
{ \
.event_queue = event_queue_, \
.rx_ba_win = 0, \
.tx_ba_win = 0, \
.rx_buf_cnt = 0, \
.tx_buf_cnt = 0 \
};
#define WIFI_PROTOCOL_11B   1
#define WIFI_PROTOCOL_11G   2
#define WIFI_PROTOCOL_11N   4

Typedef Documentation

typedef void(* esp_vendor_ie_cb_t)(void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const uint8_t *vnd_ie, int rssi)

Define function pointer for vendor specific element callback.

Parameters
void*ctx : reserved
wifi_vendor_ie_type_ttype : 0 - WIFI_VND_IE_TYPE_BEACON 1 - WIFI_VND_IE_TYPE_PROBE_REQ 2 - WIFI_VND_IE_TYPE_PROBE_RESP 3 - WIFI_VND_IE_TYPE_ASSOC_REQ 4 - WIFI_VND_IE_TYPE_ASSOC_RESP
constuint8_t sa[6] : source address
constuint8_t *vnd_ie : pointer to a vendor specific element
intrssi : received signal strength indication
typedef void(* wifi_promiscuous_cb_t)(void *buf, uint16_t len)

The RX callback function in the promiscuous mode.

Each time a packet is received, the callback function will be called.

Parameters
void*buf : the data received
uint16_tlen : data length
Returns
ESP_OK : succeed
others : fail
typedef esp_err_t(* wifi_rxcb_t)(void *buffer, uint16_t len, void *eb)

The WiFi RX callback function.

Each time the WiFi need to forward the packets to high layer, the callback function will be called

Enumeration Type Documentation

anonymous enum
Enumerator
WIFI_REASON_UNSPECIFIED 
WIFI_REASON_AUTH_EXPIRE 
WIFI_REASON_AUTH_LEAVE 
WIFI_REASON_ASSOC_EXPIRE 
WIFI_REASON_ASSOC_TOOMANY 
WIFI_REASON_NOT_AUTHED 
WIFI_REASON_NOT_ASSOCED 
WIFI_REASON_ASSOC_LEAVE 
WIFI_REASON_ASSOC_NOT_AUTHED 
WIFI_REASON_DISASSOC_PWRCAP_BAD 
WIFI_REASON_DISASSOC_SUPCHAN_BAD 
WIFI_REASON_IE_INVALID 
WIFI_REASON_MIC_FAILURE 
WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT 
WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT 
WIFI_REASON_IE_IN_4WAY_DIFFERS 
WIFI_REASON_GROUP_CIPHER_INVALID 
WIFI_REASON_PAIRWISE_CIPHER_INVALID 
WIFI_REASON_AKMP_INVALID 
WIFI_REASON_UNSUPP_RSN_IE_VERSION 
WIFI_REASON_INVALID_RSN_IE_CAP 
WIFI_REASON_802_1X_AUTH_FAILED 
WIFI_REASON_CIPHER_SUITE_REJECTED 
WIFI_REASON_BEACON_TIMEOUT 
WIFI_REASON_NO_AP_FOUND 
WIFI_REASON_AUTH_FAIL 
WIFI_REASON_ASSOC_FAIL 
WIFI_REASON_HANDSHAKE_TIMEOUT 
Enumerator
WIFI_AUTH_OPEN 

authenticate mode : open

WIFI_AUTH_WEP 

authenticate mode : WEP

WIFI_AUTH_WPA_PSK 

authenticate mode : WPA_PSK

WIFI_AUTH_WPA2_PSK 

authenticate mode : WPA2_PSK

WIFI_AUTH_WPA_WPA2_PSK 

authenticate mode : WPA_WPA2_PSK

WIFI_AUTH_MAX 
Enumerator
WIFI_BW_HT20 
WIFI_BW_HT40 
Enumerator
WIFI_COUNTRY_CN 

country China, channel range [1, 14]

WIFI_COUNTRY_JP 

country Japan, channel range [1, 14]

WIFI_COUNTRY_US 

country USA, channel range [1, 11]

WIFI_COUNTRY_EU 

country Europe, channel range [1, 13]

WIFI_COUNTRY_MAX 
Enumerator
WIFI_IF_STA 

ESP32 station interface

WIFI_IF_AP 

ESP32 soft-AP interface

WIFI_IF_MAX 
Enumerator
WIFI_MODE_NULL 

null mode

WIFI_MODE_STA 

WiFi station mode

WIFI_MODE_AP 

WiFi soft-AP mode

WIFI_MODE_APSTA 

WiFi station + soft-AP mode

WIFI_MODE_MAX 
Enumerator
WIFI_PS_NONE 

No power save

WIFI_PS_MODEM 

Modem power save

WIFI_PS_LIGHT 

Light power save

WIFI_PS_MAC 

MAC power save

Enumerator
WIFI_SECOND_CHAN_NONE 

the channel width is HT20

WIFI_SECOND_CHAN_ABOVE 

the channel width is HT40 and the second channel is above the primary channel

WIFI_SECOND_CHAN_BELOW 

the channel width is HT40 and the second channel is below the primary channel

Enumerator
WIFI_STORAGE_FLASH 

all configuration will strore in both memory and flash

WIFI_STORAGE_RAM 

all configuration will only store in the memory

Vendor IE index.

Enumerator
WIFI_VND_IE_ID_0 
WIFI_VND_IE_ID_1 

Vendor IE type.

Enumerator
WIFI_VND_IE_TYPE_BEACON 
WIFI_VND_IE_TYPE_PROBE_REQ 
WIFI_VND_IE_TYPE_PROBE_RESP 
WIFI_VND_IE_TYPE_ASSOC_REQ 
WIFI_VND_IE_TYPE_ASSOC_RESP 

Function Documentation

esp_err_t esp_wifi_clear_fast_connect ( void  )

Currently this API is just an stub API.

Parameters
null
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_connect ( void  )

Connect the ESP32 WiFi station to the AP.

Attention
1. This API only impact WIFI_MODE_STA or WIFI_MODE_APSTA mode
2. If the ESP32 is connected to an AP, call esp_wifi_disconnect to disconnect.
Parameters
null
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_deinit ( void  )

Deinit WiFi Free all resource allocated in esp_wifi_init and stop WiFi task.

Attention
1. This API should be called if you want to remove WiFi driver from the system
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_disconnect ( void  )

Disconnect the ESP32 WiFi station from the AP.

Parameters
null
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_free_station_list ( void  )
esp_err_t esp_wifi_get_ap_list ( uint16_t number,
wifi_ap_list_t ap_list 
)

Get AP list found in last scan.

Parameters
uint16_t*number : as input param, it stores max AP number ap_list can hold, as output param, it store the actual AP number this API returns
wifi_ap_list_t*ap_list : a list to hold the found APs
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_ap_num ( uint16_t number)

Get number of APs found in last scan.

Parameters
uint16_t*number : store number of APIs found in last scan
Attention
This API can only be called when the scan is completed, otherwise it may get wrong value
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_auto_connect ( bool en)

Get the auto connect flag.

Parameters
bool*en : store current auto connect configuration
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_bandwidth ( wifi_interface_t  ifx,
wifi_bandwidth_t bw 
)

Get the bandwidth of ESP32 specified interface.

Attention
1. API return false if try to get a interface that is not enable
Parameters
wifi_interface_tifx : interface to be configured
wifi_bandwidth_t*bw : store bandwidth of interface ifx
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_channel ( uint8_t primary,
wifi_second_chan_t second 
)

Get the primary/second channel of ESP32.

Attention
1. API return false if try to get a interface that is not enable
Parameters
uint8_t*primary : store current primary channel
wifi_second_chan_t*second : store current second channel
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_config ( wifi_interface_t  ifx,
wifi_config_t conf 
)

Get configuration of specified interface.

Parameters
wifi_interface_tifx : interface
wifi_config_t*conf : station or soft-AP configuration
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_country ( wifi_country_t country)

Get country code.

Parameters
wifi_country_tcountry : store current country
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_mac ( wifi_interface_t  ifx,
uint8_t  mac[6] 
)

Get mac of specified interface.

Parameters
uint8_tmac[6] : store mac of this interface ifx
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_mode ( wifi_mode_t mode)

Get current operating mode of WiFi.

Parameters
wifi_mode_t*mode : store current WiFi mode
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_promiscuous ( uint8_t enable)

Get the promiscuous mode.

Parameters
uint8*enable : store the current status of promiscuous mode
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_protocol ( wifi_interface_t  ifx,
uint8_t protocol_bitmap 
)

Get the current protocol bitmap of specified ifx.

Parameters
wifi_interface_tifx : interfaces
uint8_tprotocol : store current WiFi protocol bitmap of interface ifx
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_ps ( wifi_ps_type_t type)

Get current power save type.

Parameters
wifi_ps_type_t*type : store current power save type
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_get_station_list ( struct station_info **  station)

Get STAs associated with soft-AP.

Attention
SSC only API
Parameters
structstation_info **station : station list
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_init ( wifi_init_config_t config)

Init WiFi Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer, WiFi NVS structure etc, this WiFi also start WiFi task.

Attention
1. This API must be called before all other WiFi API can be called
2. Generally we should init event_q in *config, WiFi driver will post the event to this queue when event happens, such as, when station connects to WiFi, WiFi driver will post station connected event to this queue. If the queue is not initialized, WiFi will not post any events
3. For other parameters, currently it's not ready, just ignore it.
Parameters
wifi_init_config_t*config : provide WiFi init configuration
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_kick_station ( uint16_t  aid)

Kick the all station or associated id equals to aid.

Parameters
uint16_taid : when aid is 0, kick all stations, otherwise kick station whose associated id is aid
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_reg_rxcb ( wifi_interface_t  ifx,
wifi_rxcb_t  fn 
)

Set the WiFi RX callback.

Attention
1. Currently we support only one RX callback for each interface
Parameters
wifi_interface_tifx : interface
wifi_rxcb_tfn : WiFi RX callback
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_scan_start ( wifi_scan_config_t conf,
bool  block 
)

Scan all available APs.

Attention
If this API is called, the found APs are stored in WiFi driver dynamic allocated memory and the will be freed in esp_wifi_get_ap_list, so generally, call esp_wifi_get_ap_list to cause the memory to be freed once the scan is done
Parameters
structscan_config *config : configuration of scanning
boolblock : if block is true, this API will block the caller until the scan is done, otherwise it will return immediately
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_scan_stop ( void  )

Stop the scan in process.

Parameters
null
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_auto_connect ( bool  en)

Set auto connect The default value is true.

Attention
1.
Parameters
boolen : true - enable auto connect / false - disable auto connect
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_bandwidth ( wifi_interface_t  ifx,
wifi_bandwidth_t  bw 
)

Set the bandwidth of ESP32 specified interface.

Attention
1. API return false if try to configure a interface that is not enable
2. WIFI_BW_HT40 is supported only when the interface support 11N
Parameters
wifi_interface_tifx : interface to be configured
wifi_bandwidth_tbw : bandwidth
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_channel ( uint8_t  primary,
wifi_second_chan_t  second 
)

Set primary/second channel of ESP32.

Attention
1. This is a special API for sniffer
Parameters
uint8_tprimary : for HT20, primary is the channel number, for HT40, primary is the primary channel
wifi_second_chan_tsecond : for HT20, second is ignored, for HT40, second is the second channel
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_config ( wifi_interface_t  ifx,
wifi_config_t conf 
)

Set the configuration of the ESP32 STA or AP.

Attention
1. This API can be called only when specified interface is enabled, otherwise, API fail
2. For station configuration, bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.
3. ESP32 is limited to only one channel, so when in the soft-AP+station mode, the soft-AP will adjust its channel automatically to be the same as the channel of the ESP32 station.
Parameters
wifi_interface_tifx : interface
wifi_config_t*conf : station or soft-AP configuration
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_country ( wifi_country_t  country)

Set country code The default value is WIFI_COUNTRY_CN.

Parameters
wifi_country_tcountry : country type
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_mac ( wifi_interface_t  ifx,
uint8_t  mac[6] 
)

Set MAC address of the ESP32 WiFi station or the soft-AP interface.

Attention
1. This API can only be called when the interface is disabled
2. ESP32 soft-AP and station have different MAC addresses, do not set them to be the same.
  • The bit0 of the first byte of ESP32 MAC address can not be 1. For example, the MAC address can set to be "1a:XX:XX:XX:XX:XX", but can not be "15:XX:XX:XX:XX:XX".
Parameters
wifi_interface_tifx : interface
uint8mac[6]: the MAC address.
Returns
true : succeed
false : fail
esp_err_t esp_wifi_set_mode ( wifi_mode_t  mode)

Set the WiFi operating mode.

Set the WiFi operating mode as station, soft-AP or station+soft-AP, The default mode is soft-AP mode.

Parameters
wifi_mode_tmode : WiFi operating modes:
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_promiscuous ( uint8_t  enable)

Enable the promiscuous mode.

Parameters
uint8promiscuous : 0 - disable / 1 - enable
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_promiscuous_rx_cb ( wifi_promiscuous_cb_t  cb)

Register the RX callback function in the promiscuous mode.

Each time a packet is received, the registered callback function will be called.

Parameters
wifi_promiscuous_cb_tcb : callback
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_protocol ( wifi_interface_t  ifx,
uint8_t  protocol_bitmap 
)

Set protocol type of specified interface The default protocol is (WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N)

Attention
Currently we only support 802.11b or 802.11bg or 802.11bgn mode
Parameters
wifi_interface_tifx : interfaces
uint8_tprotocol : WiFi protocol bitmap
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_ps ( wifi_ps_type_t  type)

Set current power save type.

Parameters
wifi_ps_type_ttype : power save type
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_storage ( wifi_storage_t  storage)

Set the WiFi API configuration storage type.

Attention
1. The default value is WIFI_STORAGE_FLASH
Parameters
wifi_storage_tstorage : storage type
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_vendor_ie ( bool  enable,
wifi_vendor_ie_type_t  type,
wifi_vendor_ie_id_t  idx,
uint8_t vnd_ie 
)

Set vendor specific element.

Parameters
boolenable : enable or not
wifi_vendor_ie_type_ttype : 0 - WIFI_VND_IE_TYPE_BEACON 1 - WIFI_VND_IE_TYPE_PROBE_REQ 2 - WIFI_VND_IE_TYPE_PROBE_RESP 3 - WIFI_VND_IE_TYPE_ASSOC_REQ 4 - WIFI_VND_IE_TYPE_ASSOC_RESP
wifi_vendor_ie_id_tidx : 0 - WIFI_VND_IE_ID_0 1 - WIFI_VND_IE_ID_1
uint8_t*vnd_ie : pointer to a vendor specific element
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_set_vendor_ie_cb ( esp_vendor_ie_cb_t  cb,
void ctx 
)

Set vendor specific element callback.

Parameters
esp_vendor_ie_cb_tcb : callback function
void*ctx : reserved
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_start ( void  )

Start WiFi according to current configuration If mode is WIFI_MODE_STA, it create station control block and start station If mode is WIFI_MODE_AP, it create soft-AP control block and start soft-AP If mode is WIFI_MODE_APSTA, it create soft-AP and station control block and start soft-AP and station.

Parameters
null
Returns
ESP_OK : succeed
others : fail
esp_err_t esp_wifi_stop ( void  )

Stop WiFi If mode is WIFI_MODE_STA, it stop station and free station control block If mode is WIFI_MODE_AP, it stop soft-AP and free soft-AP control block If mode is WIFI_MODE_APSTA, it stop station/soft-AP and free station/soft-AP control block.

Parameters
null
Returns
ESP_OK : succeed
others : fail