Wi-Fi

[中文]

Introduction

The WiFi libraries provide support for configuring and monitoring the ESP32 WiFi networking functionality. This includes configuration for:

  • Station mode (aka STA mode or WiFi client mode). ESP32 connects to an access point.

  • AP mode (aka Soft-AP mode or Access Point mode). Stations connect to the ESP32.

  • Combined AP-STA mode (ESP32 is concurrently an access point and a station connected to another access point).

  • Various security modes for the above (WPA, WPA2, WEP, etc.)

  • Scanning for access points (active & passive scanning).

  • Promiscuous mode for monitoring of IEEE802.11 WiFi packets.

Application Examples

The wifi directory of ESP-IDF examples contains the following applications:

Code examples for Wi-Fi are provided in the wifi directory of ESP-IDF examples.

In addition, there is a simple esp-idf-template application to demonstrate a minimal IDF project structure.

API Reference

Functions

esp_err_t esp_wifi_init(const wifi_init_config_t *config)

Initialize WiFi Allocate resource for WiFi driver, such as WiFi control structure, RX/TX buffer, WiFi NVS structure etc. This WiFi also starts WiFi task.

Attention

1. This API must be called before all other WiFi API can be called

Attention

2. Always use WIFI_INIT_CONFIG_DEFAULT macro to initialize the configuration to default values, this can guarantee all the fields get correct value when more fields are added into wifi_init_config_t in future release. If you want to set your own initial values, overwrite the default values which are set by WIFI_INIT_CONFIG_DEFAULT. Please be notified that the field ‘magic’ of wifi_init_config_t should always be WIFI_INIT_CONFIG_MAGIC!

Return

  • ESP_OK: succeed

  • ESP_ERR_NO_MEM: out of memory

  • others: refer to error code esp_err.h

Parameters
  • config: pointer to WiFi initialized configuration structure; can point to a temporary variable.

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

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

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.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

  • others: refer to error code in esp_err.h

Parameters
  • mode: WiFi operating mode

esp_err_t esp_wifi_get_mode(wifi_mode_t *mode)

Get current operating mode of WiFi.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • [out] mode: store current WiFi mode

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.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

  • ESP_ERR_NO_MEM: out of memory

  • ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong

  • ESP_FAIL: other WiFi internal errors

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.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

esp_err_t esp_wifi_restore(void)

Restore WiFi stack persistent settings to default values.

This function will reset settings made using the following APIs:

  • esp_wifi_set_bandwidth,

  • esp_wifi_set_protocol,

  • esp_wifi_set_config related

  • esp_wifi_set_mode

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

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

Attention

2. If the ESP32 is connected to an AP, call esp_wifi_disconnect to disconnect.

Attention

3. The scanning triggered by esp_wifi_start_scan() will not be effective until connection between ESP32 and the AP is established. If ESP32 is scanning and connecting at the same time, ESP32 will abort scanning and return a warning message and error number ESP_ERR_WIFI_STATE. If you want to do reconnection after ESP32 received disconnect event, remember to add the maximum retry time, otherwise the called scan will not work. This is especially true when the AP doesn’t exist, and you still try reconnection after ESP32 received disconnect event with the reason code WIFI_REASON_NO_AP_FOUND.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start

  • ESP_ERR_WIFI_CONN: WiFi internal error, station or soft-AP control block wrong

  • ESP_ERR_WIFI_SSID: SSID of AP which station connects is invalid

esp_err_t esp_wifi_disconnect(void)

Disconnect the ESP32 WiFi station from the AP.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi was not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start

  • ESP_FAIL: other WiFi internal errors

esp_err_t esp_wifi_clear_fast_connect(void)

Currently this API is just an stub API.

Return

  • ESP_OK: succeed

  • others: fail

esp_err_t esp_wifi_deauth_sta(uint16_t aid)

deauthenticate all stations or associated id equals to aid

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start

  • ESP_ERR_INVALID_ARG: invalid argument

  • ESP_ERR_WIFI_MODE: WiFi mode is wrong

Parameters
  • aid: when aid is 0, deauthenticate all stations, otherwise deauthenticate station whose associated id is aid

esp_err_t esp_wifi_scan_start(const wifi_scan_config_t *config, 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_scan_get_ap_records, so generally, call esp_wifi_scan_get_ap_records to cause the memory to be freed once the scan is done

Attention

The values of maximum active scan time and passive scan time per channel are limited to 1500 milliseconds. Values above 1500ms may cause station to disconnect from AP and are not recommended.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_STARTED: WiFi was not started by esp_wifi_start

  • ESP_ERR_WIFI_TIMEOUT: blocking scan is timeout

  • ESP_ERR_WIFI_STATE: wifi still connecting when invoke esp_wifi_scan_start

  • others: refer to error code in esp_err.h

Parameters
  • config: configuration of scanning

  • block: if block is true, this API will block the caller until the scan is done, otherwise it will return immediately

esp_err_t esp_wifi_scan_stop(void)

Stop the scan in process.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start

esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number)

Get number of APs found in last scan.

Attention

This API can only be called when the scan is completed, otherwise it may get wrong value.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • [out] number: store number of APIs found in last scan

esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records)

Get AP list found in last scan.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start

  • ESP_ERR_INVALID_ARG: invalid argument

  • ESP_ERR_NO_MEM: out of memory

Parameters
  • [inout] number: As input param, it stores max AP number ap_records can hold. As output param, it receives the actual AP number this API returns.

  • ap_records: wifi_ap_record_t array to hold the found APs

esp_err_t esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info)

Get information of AP which the ESP32 station is associated with.

Attention

When the obtained country information is empty, it means that the AP does not carry country information

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_CONN: The station interface don’t initialized

  • ESP_ERR_WIFI_NOT_CONNECT: The station is in disconnect status

Parameters
  • ap_info: the wifi_ap_record_t to hold AP information sta can get the connected ap’s phy mode info through the struct member phy_11b,phy_11g,phy_11n,phy_lr in the wifi_ap_record_t struct. For example, phy_11b = 1 imply that ap support 802.11b mode

esp_err_t esp_wifi_set_ps(wifi_ps_type_t type)

Set current WiFi power save type.

Attention

Default power save type is WIFI_PS_MIN_MODEM.

Return

ESP_OK: succeed

Parameters
  • type: power save type

esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type)

Get current WiFi power save type.

Attention

Default power save type is WIFI_PS_MIN_MODEM.

Return

ESP_OK: succeed

Parameters
  • [out] type: store current power save type

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

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_IF: invalid interface

  • others: refer to error codes in esp_err.h

Parameters
  • ifx: interfaces

  • protocol_bitmap: WiFi protocol bitmap

esp_err_t esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap)

Get the current protocol bitmap of the specified interface.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_IF: invalid interface

  • ESP_ERR_INVALID_ARG: invalid argument

  • others: refer to error codes in esp_err.h

Parameters
  • ifx: interface

  • [out] protocol_bitmap: store current WiFi protocol bitmap of interface ifx

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 an interface that is not enabled

Attention

2. WIFI_BW_HT40 is supported only when the interface support 11N

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_IF: invalid interface

  • ESP_ERR_INVALID_ARG: invalid argument

  • others: refer to error codes in esp_err.h

Parameters
  • ifx: interface to be configured

  • bw: bandwidth

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

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_IF: invalid interface

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • ifx: interface to be configured

  • [out] bw: store bandwidth of interface ifx

esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second)

Set primary/secondary channel of ESP32.

Attention

1. This API should be called after esp_wifi_start()

Attention

2. When ESP32 is in STA mode, this API should not be called when STA is scanning or connecting to an external AP

Attention

3. When ESP32 is in softAP mode, this API should not be called when softAP has connected to external STAs

Attention

4. When ESP32 is in STA+softAP mode, this API should not be called when in the scenarios described above

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_IF: invalid interface

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • primary: for HT20, primary is the channel number, for HT40, primary is the primary channel

  • second: for HT20, second is ignored, for HT40, second is the second channel

esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second)

Get the primary/secondary channel of ESP32.

Attention

1. API return false if try to get a interface that is not enable

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • primary: store current primary channel

  • [out] second: store current second channel

esp_err_t esp_wifi_set_country(const wifi_country_t *country)

configure country info

Attention

1. The default country is {.cc=”CN”, .schan=1, .nchan=13, policy=WIFI_COUNTRY_POLICY_AUTO}

Attention

2. When the country policy is WIFI_COUNTRY_POLICY_AUTO, the country info of the AP to which the station is connected is used. E.g. if the configured country info is {.cc=”USA”, .schan=1, .nchan=11} and the country info of the AP to which the station is connected is {.cc=”JP”, .schan=1, .nchan=14} then the country info that will be used is {.cc=”JP”, .schan=1, .nchan=14}. If the station disconnected from the AP the country info is set back back to the country info of the station automatically, {.cc=”US”, .schan=1, .nchan=11} in the example.

Attention

3. When the country policy is WIFI_COUNTRY_POLICY_MANUAL, always use the configured country info.

Attention

4. When the country info is changed because of configuration or because the station connects to a different external AP, the country IE in probe response/beacon of the soft-AP is changed also.

Attention

5. The country configuration is not stored into flash

Attention

6. This API doesn’t validate the per-country rules, it’s up to the user to fill in all fields according to local regulations.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • country: the configured country info

esp_err_t esp_wifi_get_country(wifi_country_t *country)

get the current country info

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • country: country info

esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, const 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

Attention

2. ESP32 soft-AP and station have different MAC addresses, do not set them to be the same.

Attention

3. The bit 0 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”.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

  • ESP_ERR_WIFI_IF: invalid interface

  • ESP_ERR_WIFI_MAC: invalid mac address

  • ESP_ERR_WIFI_MODE: WiFi mode is wrong

  • others: refer to error codes in esp_err.h

Parameters
  • ifx: interface

  • mac: the MAC address

esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6])

Get mac of specified interface.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

  • ESP_ERR_WIFI_IF: invalid interface

Parameters
  • ifx: interface

  • [out] mac: store mac of the interface ifx

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.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

Parameters
  • cb: callback

esp_err_t esp_wifi_set_promiscuous(bool en)

Enable the promiscuous mode.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

Parameters
  • en: false - disable, true - enable

esp_err_t esp_wifi_get_promiscuous(bool *en)

Get the promiscuous mode.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • [out] en: store the current status of promiscuous mode

esp_err_t esp_wifi_set_promiscuous_filter(const wifi_promiscuous_filter_t *filter)

Enable the promiscuous mode packet type filter.

Note

The default filter is to filter all packets except WIFI_PKT_MISC

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

Parameters
  • filter: the packet type filtered in promiscuous mode.

esp_err_t esp_wifi_get_promiscuous_filter(wifi_promiscuous_filter_t *filter)

Get the promiscuous filter.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • [out] filter: store the current status of promiscuous filter

esp_err_t esp_wifi_set_promiscuous_ctrl_filter(const wifi_promiscuous_filter_t *filter)

Enable subtype filter of the control packet in promiscuous mode.

Note

The default filter is to filter none control packet.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

Parameters
  • filter: the subtype of the control packet filtered in promiscuous mode.

esp_err_t esp_wifi_get_promiscuous_ctrl_filter(wifi_promiscuous_filter_t *filter)

Get the subtype filter of the control packet in promiscuous mode.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_ARG: invalid argument

Parameters
  • [out] filter: store the current status of subtype filter of the control packet in promiscuous mode

esp_err_t esp_wifi_set_config(wifi_interface_t interface, 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

Attention

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.

Attention

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.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

  • ESP_ERR_WIFI_IF: invalid interface

  • ESP_ERR_WIFI_MODE: invalid mode

  • ESP_ERR_WIFI_PASSWORD: invalid password

  • ESP_ERR_WIFI_NVS: WiFi internal NVS error

  • others: refer to the erro code in esp_err.h

Parameters
  • interface: interface

  • conf: station or soft-AP configuration

esp_err_t esp_wifi_get_config(wifi_interface_t interface, wifi_config_t *conf)

Get configuration of specified interface.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

  • ESP_ERR_WIFI_IF: invalid interface

Parameters
  • interface: interface

  • [out] conf: station or soft-AP configuration

esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta)

Get STAs associated with soft-AP.

Attention

SSC only API

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

  • ESP_ERR_WIFI_MODE: WiFi mode is wrong

  • ESP_ERR_WIFI_CONN: WiFi internal error, the station/soft-AP control block is invalid

Parameters
  • [out] sta: station list ap can get the connected sta’s phy mode info through the struct member phy_11b,phy_11g,phy_11n,phy_lr in the wifi_sta_info_t struct. For example, phy_11b = 1 imply that sta support 802.11b mode

esp_err_t esp_wifi_ap_get_sta_aid(const uint8_t mac[6], uint16_t *aid)

Get AID of STA connected with soft-AP.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

  • ESP_ERR_NOT_FOUND: Requested resource not found

  • ESP_ERR_WIFI_MODE: WiFi mode is wrong

  • ESP_ERR_WIFI_CONN: WiFi internal error, the station/soft-AP control block is invalid

Parameters
  • mac: STA’s mac address

  • [out] aid: Store the AID corresponding to STA mac

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

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • storage: : storage type

esp_err_t esp_wifi_set_vendor_ie(bool enable, wifi_vendor_ie_type_t type, wifi_vendor_ie_id_t idx, const void *vnd_ie)

Set 802.11 Vendor-Specific Information Element.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init()

  • ESP_ERR_INVALID_ARG: Invalid argument, including if first byte of vnd_ie is not WIFI_VENDOR_IE_ELEMENT_ID (0xDD) or second byte is an invalid length.

  • ESP_ERR_NO_MEM: Out of memory

Parameters
  • enable: If true, specified IE is enabled. If false, specified IE is removed.

  • type: Information Element type. Determines the frame type to associate with the IE.

  • idx: Index to set or clear. Each IE type can be associated with up to two elements (indices 0 & 1).

  • vnd_ie: Pointer to vendor specific element data. First 6 bytes should be a header with fields matching vendor_ie_data_t. If enable is false, this argument is ignored and can be NULL. Data does not need to remain valid after the function returns.

esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx)

Register Vendor-Specific Information Element monitoring callback.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

Parameters
  • cb: Callback function

  • ctx: Context argument, passed to callback function.

esp_err_t esp_wifi_set_max_tx_power(int8_t power)

Set maximum transmitting power after WiFi start.

Attention

1. Maximum power before wifi startup is limited by PHY init data bin.

Attention

2. The value set by this API will be mapped to the max_tx_power of the structure wifi_country_t variable.

Attention

3. Mapping Table {Power, max_tx_power} = {{8, 2}, {20, 5}, {28, 7}, {34, 8}, {44, 11}, {52, 13}, {56, 14}, {60, 15}, {66, 16}, {72, 18}, {80, 20}}.

Attention

4. Param power unit is 0.25dBm, range is [8, 84] corresponding to 2dBm - 20dBm.

Attention

5. Relationship between set value and actual value. As follows: {set value range, actual value} = {{[8, 19],8}, {[20, 27],20}, {[28, 33],28}, {[34, 43],34}, {[44, 51],44}, {[52, 55],52}, {[56, 59],56}, {[60, 65],60}, {[66, 71],66}, {[72, 79],72}, {[80, 84],80}}.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start

  • ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is out of range

Parameters
  • power: Maximum WiFi transmitting power.

esp_err_t esp_wifi_get_max_tx_power(int8_t *power)

Get maximum transmiting power after WiFi start.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start

  • ESP_ERR_WIFI_ARG: invalid argument

Parameters
  • power: Maximum WiFi transmitting power, unit is 0.25dBm.

esp_err_t esp_wifi_set_event_mask(uint32_t mask)

Set mask to enable or disable some WiFi events.

Attention

1. Mask can be created by logical OR of various WIFI_EVENT_MASK_ constants. Events which have corresponding bit set in the mask will not be delivered to the system event handler.

Attention

2. Default WiFi event mask is WIFI_EVENT_MASK_AP_PROBEREQRECVED.

Attention

3. There may be lots of stations sending probe request data around. Don’t unmask this event unless you need to receive probe request data.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

Parameters
  • mask: WiFi event mask.

esp_err_t esp_wifi_get_event_mask(uint32_t *mask)

Get mask of WiFi events.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_ARG: invalid argument

Parameters
  • mask: WiFi event mask.

esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq)

Send raw ieee80211 data.

Attention

Currently only support for sending beacon/probe request/probe response/action and non-QoS data frame

Return

  • ESP_OK: success

  • ESP_ERR_WIFI_IF: Invalid interface

  • ESP_ERR_INVALID_ARG: Invalid parameter

  • ESP_ERR_WIFI_NO_MEM: out of memory

Parameters
  • ifx: interface if the Wi-Fi mode is Station, the ifx should be WIFI_IF_STA. If the Wi-Fi mode is SoftAP, the ifx should be WIFI_IF_AP. If the Wi-Fi mode is Station+SoftAP, the ifx should be WIFI_IF_STA or WIFI_IF_AP. If the ifx is wrong, the API returns ESP_ERR_WIFI_IF.

  • buffer: raw ieee80211 buffer

  • len: the length of raw buffer, the len must be <= 1500 Bytes and >= 24 Bytes

  • en_sys_seq: indicate whether use the internal sequence number. If en_sys_seq is false, the sequence in raw buffer is unchanged, otherwise it will be overwritten by WiFi driver with the system sequence number. Generally, if esp_wifi_80211_tx is called before the Wi-Fi connection has been set up, both en_sys_seq==true and en_sys_seq==false are fine. However, if the API is called after the Wi-Fi connection has been set up, en_sys_seq must be true, otherwise ESP_ERR_WIFI_ARG is returned.

esp_err_t esp_wifi_set_csi_rx_cb(wifi_csi_cb_t cb, void *ctx)

Register the RX callback function of CSI data.

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

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

Parameters
  • cb: callback

  • ctx: context argument, passed to callback function

esp_err_t esp_wifi_set_csi_config(const wifi_csi_config_t *config)

Set CSI data configuration.

return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • config: configuration

esp_err_t esp_wifi_set_csi(bool en)

Enable or disable CSI.

return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled

  • ESP_ERR_INVALID_ARG: invalid argument

Parameters
  • en: true - enable, false - disable

esp_err_t esp_wifi_set_ant_gpio(const wifi_ant_gpio_config_t *config)

Set antenna GPIO configuration.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_ARG: Invalid argument, e.g. parameter is NULL, invalid GPIO number etc

Parameters
  • config: Antenna GPIO configuration.

esp_err_t esp_wifi_get_ant_gpio(wifi_ant_gpio_config_t *config)

Get current antenna GPIO configuration.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is NULL

Parameters
  • config: Antenna GPIO configuration.

esp_err_t esp_wifi_set_ant(const wifi_ant_config_t *config)

Set antenna configuration.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_ARG: Invalid argument, e.g. parameter is NULL, invalid antenna mode or invalid GPIO number

Parameters
  • config: Antenna configuration.

esp_err_t esp_wifi_get_ant(wifi_ant_config_t *config)

Get current antenna configuration.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is NULL

Parameters
  • config: Antenna configuration.

esp_err_t esp_wifi_set_inactive_time(wifi_interface_t ifx, uint16_t sec)

Set the inactive time of the ESP32 STA or AP.

Attention

1. For Station, If the station does not receive a beacon frame from the connected SoftAP during the inactive time, disconnect from SoftAP. Default 6s.

Attention

2. For SoftAP, If the softAP doesn’t receive any data from the connected STA during inactive time, the softAP will force deauth the STA. Default is 300s.

Attention

3. The inactive time configuration is not stored into flash

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start

  • ESP_ERR_WIFI_ARG: invalid argument, For Station, if sec is less than 3. For SoftAP, if sec is less than 10.

Parameters
  • ifx: interface to be configured.

  • sec: Inactive time. Unit seconds.

esp_err_t esp_wifi_get_inactive_time(wifi_interface_t ifx, uint16_t *sec)

Get inactive time of specified interface.

Return

  • ESP_OK: succeed

  • ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init

  • ESP_ERR_WIFI_ARG: invalid argument

Parameters
  • ifx: Interface to be configured.

  • sec: Inactive time. Unit seconds.

esp_err_t esp_wifi_statis_dump(uint32_t modules)

Dump WiFi statistics.

Return

  • ESP_OK: succeed

  • others: failed

Parameters
  • modules: statistic modules to be dumped

Structures

struct wifi_init_config_t

WiFi stack configuration parameters passed to esp_wifi_init call.

Public Members

system_event_handler_t event_handler

WiFi event handler

wifi_osi_funcs_t *osi_funcs

WiFi OS functions

wpa_crypto_funcs_t wpa_crypto_funcs

WiFi station crypto functions when connect

int static_rx_buf_num

WiFi static RX buffer number

int dynamic_rx_buf_num

WiFi dynamic RX buffer number

int tx_buf_type

WiFi TX buffer type

int static_tx_buf_num

WiFi static TX buffer number

int dynamic_tx_buf_num

WiFi dynamic TX buffer number

int csi_enable

WiFi channel state information enable flag

int ampdu_rx_enable

WiFi AMPDU RX feature enable flag

int ampdu_tx_enable

WiFi AMPDU TX feature enable flag

int nvs_enable

WiFi NVS flash enable flag

int nano_enable

Nano option for printf/scan family enable flag

int tx_ba_win

WiFi Block Ack TX window size

int rx_ba_win

WiFi Block Ack RX window size

int wifi_task_core_id

WiFi Task Core ID

int beacon_max_len

WiFi softAP maximum length of the beacon

int mgmt_sbuf_num

WiFi management short buffer number, the minimum value is 6, the maximum value is 32

uint64_t feature_caps

Enables additional WiFi features and capabilities

int magic

WiFi init magic number, it should be the last field

Macros

ESP_ERR_WIFI_NOT_INIT

WiFi driver was not installed by esp_wifi_init

ESP_ERR_WIFI_NOT_STARTED

WiFi driver was not started by esp_wifi_start

ESP_ERR_WIFI_NOT_STOPPED

WiFi driver was not stopped by esp_wifi_stop

ESP_ERR_WIFI_IF

WiFi interface error

ESP_ERR_WIFI_MODE

WiFi mode error

ESP_ERR_WIFI_STATE

WiFi internal state error

ESP_ERR_WIFI_CONN

WiFi internal control block of station or soft-AP error

ESP_ERR_WIFI_NVS

WiFi internal NVS module error

ESP_ERR_WIFI_MAC

MAC address is invalid

ESP_ERR_WIFI_SSID

SSID is invalid

ESP_ERR_WIFI_PASSWORD

Password is invalid

ESP_ERR_WIFI_TIMEOUT

Timeout error

ESP_ERR_WIFI_WAKE_FAIL

WiFi is in sleep state(RF closed) and wakeup fail

ESP_ERR_WIFI_WOULD_BLOCK

The caller would block

ESP_ERR_WIFI_NOT_CONNECT

Station still in disconnect status

ESP_ERR_WIFI_POST

Failed to post the event to WiFi task

ESP_ERR_WIFI_INIT_STATE

Invalid WiFi state when init/deinit is called

ESP_ERR_WIFI_STOP_STATE

Returned when WiFi is stopping

WIFI_STATIC_TX_BUFFER_NUM
WIFI_DYNAMIC_TX_BUFFER_NUM
WIFI_CSI_ENABLED
WIFI_AMPDU_RX_ENABLED
WIFI_AMPDU_TX_ENABLED
WIFI_NVS_ENABLED
WIFI_NANO_FORMAT_ENABLED
WIFI_INIT_CONFIG_MAGIC
WIFI_DEFAULT_TX_BA_WIN
WIFI_DEFAULT_RX_BA_WIN
WIFI_TASK_CORE_ID
WIFI_SOFTAP_BEACON_MAX_LEN
WIFI_MGMT_SBUF_NUM
CONFIG_FEATURE_WPA3_SAE_BIT
WIFI_INIT_CONFIG_DEFAULT()

Type Definitions

typedef void (*wifi_promiscuous_cb_t)(void *buf, wifi_promiscuous_pkt_type_t type)

The RX callback function in the promiscuous mode. Each time a packet is received, the callback function will be called.

Parameters

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

Function signature for received Vendor-Specific Information Element callback.

Parameters
  • ctx: Context argument, as passed to esp_wifi_set_vendor_ie_cb() when registering callback.

  • type: Information element type, based on frame type received.

  • sa: Source 802.11 address.

  • vnd_ie: Pointer to the vendor specific element data received.

  • rssi: Received signal strength indication.

typedef void (*wifi_csi_cb_t)(void *ctx, wifi_csi_info_t *data)

The RX callback function of Channel State Information(CSI) data.

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

Parameters
  • ctx: context argument, passed to esp_wifi_set_csi_rx_cb() when registering callback function.

  • data: CSI data received. The memory that it points to will be deallocated after callback function returns.

Unions

union wifi_config_t
#include <esp_wifi_types.h>

Configuration data for ESP32 AP or STA.

The usage of this union (for ap or sta configuration) is determined by the accompanying interface argument passed to esp_wifi_set_config() or esp_wifi_get_config()

Public Members

wifi_ap_config_t ap

configuration of AP

wifi_sta_config_t sta

configuration of STA

Structures

struct wifi_country_t

Structure describing WiFi country-based regional restrictions.

Public Members

char cc[3]

country code string

uint8_t schan

start channel

uint8_t nchan

total channel number

int8_t max_tx_power

This field is used for getting WiFi maximum transmitting power, call esp_wifi_set_max_tx_power to set the maximum transmitting power.

wifi_country_policy_t policy

country policy

struct wifi_active_scan_time_t

Range of active scan times per channel.

Public Members

uint32_t min

minimum active scan time per channel, units: millisecond

uint32_t max

maximum active scan time per channel, units: millisecond, values above 1500ms may cause station to disconnect from AP and are not recommended.

struct wifi_scan_time_t

Aggregate of active & passive scan time per channel.

Public Members

wifi_active_scan_time_t active

active scan time per channel, units: millisecond.

uint32_t passive

passive scan time per channel, units: millisecond, values above 1500ms may cause station to disconnect from AP and are not recommended.

struct wifi_scan_config_t

Parameters for an SSID scan.

Public Members

uint8_t *ssid

SSID of AP

uint8_t *bssid

MAC address of AP

uint8_t channel

channel, scan the specific channel

bool show_hidden

enable to scan AP whose SSID is hidden

wifi_scan_type_t scan_type

scan type, active or passive

wifi_scan_time_t scan_time

scan time per channel

struct wifi_ap_record_t

Description of a WiFi AP.

Public Members

uint8_t bssid[6]

MAC address of AP

uint8_t ssid[33]

SSID of AP

uint8_t primary

channel of AP

wifi_second_chan_t second

secondary channel of AP

int8_t rssi

signal strength of AP

wifi_auth_mode_t authmode

authmode of AP

wifi_cipher_type_t pairwise_cipher

pairwise cipher of AP

wifi_cipher_type_t group_cipher

group cipher of AP

wifi_ant_t ant

antenna used to receive beacon from AP

uint32_t phy_11b : 1

bit: 0 flag to identify if 11b mode is enabled or not

uint32_t phy_11g : 1

bit: 1 flag to identify if 11g mode is enabled or not

uint32_t phy_11n : 1

bit: 2 flag to identify if 11n mode is enabled or not

uint32_t phy_lr : 1

bit: 3 flag to identify if low rate is enabled or not

uint32_t wps : 1

bit: 4 flag to identify if WPS is supported or not

uint32_t reserved : 27

bit: 5..31 reserved

wifi_country_t country

country information of AP

struct wifi_scan_threshold_t

Structure describing parameters for a WiFi fast scan.

Public Members

int8_t rssi

The minimum rssi to accept in the fast scan mode

wifi_auth_mode_t authmode

The weakest authmode to accept in the fast scan mode

struct wifi_pmf_config_t

Configuration structure for Protected Management Frame

Public Members

bool capable

Advertizes support for Protected Management Frame. Device will prefer to connect in PMF mode if other device also advertizes PMF capability.

bool required

Advertizes that Protected Management Frame is required. Device will not associate to non-PMF capable devices.

struct wifi_ap_config_t

Soft-AP configuration settings for the ESP32.

Public Members

uint8_t ssid[32]

SSID of ESP32 soft-AP. If ssid_len field is 0, this must be a Null terminated string. Otherwise, length is set according to ssid_len.

uint8_t password[64]

Password of ESP32 soft-AP.

uint8_t ssid_len

Optional length of SSID field.

uint8_t channel

Channel of ESP32 soft-AP

wifi_auth_mode_t authmode

Auth mode of ESP32 soft-AP. Do not support AUTH_WEP in soft-AP mode

uint8_t ssid_hidden

Broadcast SSID or not, default 0, broadcast the SSID

uint8_t max_connection

Max number of stations allowed to connect in, default 4, max 10

uint16_t beacon_interval

Beacon interval which should be multiples of 100. Unit: TU(time unit, 1 TU = 1024 us). Range: 100 ~ 60000. Default value: 100

struct wifi_sta_config_t

STA configuration settings for the ESP32.

Public Members

uint8_t ssid[32]

SSID of target AP.

uint8_t password[64]

Password of target AP.

wifi_scan_method_t scan_method

do all channel scan or fast scan

bool bssid_set

whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.

uint8_t bssid[6]

MAC address of target AP

uint8_t channel

channel of target AP. Set to 1~13 to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.

uint16_t listen_interval

Listen interval for ESP32 station to receive beacon when WIFI_PS_MAX_MODEM is set. Units: AP beacon intervals. Defaults to 3 if set to 0.

wifi_sort_method_t sort_method

sort the connect AP in the list by rssi or security mode

wifi_scan_threshold_t threshold

When sort_method is set, only APs which have an auth mode that is more secure than the selected auth mode and a signal stronger than the minimum RSSI will be used.

wifi_pmf_config_t pmf_cfg

Configuration for Protected Management Frame. Will be advertized in RSN Capabilities in RSN IE.

struct wifi_sta_info_t

Description of STA associated with AP.

Public Members

uint8_t mac[6]

mac address

int8_t rssi

current average rssi of sta connected

uint32_t phy_11b : 1

bit: 0 flag to identify if 11b mode is enabled or not

uint32_t phy_11g : 1

bit: 1 flag to identify if 11g mode is enabled or not

uint32_t phy_11n : 1

bit: 2 flag to identify if 11n mode is enabled or not

uint32_t phy_lr : 1

bit: 3 flag to identify if low rate is enabled or not

uint32_t reserved : 28

bit: 4..31 reserved

struct wifi_sta_list_t

List of stations associated with the ESP32 Soft-AP.

Public Members

wifi_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM]

station list

int num

number of stations in the list (other entries are invalid)

struct vendor_ie_data_t

Vendor Information Element header.

The first bytes of the Information Element will match this header. Payload follows.

Public Members

uint8_t element_id

Should be set to WIFI_VENDOR_IE_ELEMENT_ID (0xDD)

uint8_t length

Length of all bytes in the element data following this field. Minimum 4.

uint8_t vendor_oui[3]

Vendor identifier (OUI).

uint8_t vendor_oui_type

Vendor-specific OUI type.

uint8_t payload[0]

Payload. Length is equal to value in ‘length’ field, minus 4.

struct wifi_pkt_rx_ctrl_t

Received packet radio metadata header, this is the common header at the beginning of all promiscuous mode RX callback buffers.

Public Members

signed rssi : 8

Received Signal Strength Indicator(RSSI) of packet. unit: dBm

unsigned rate : 5

PHY rate encoding of the packet. Only valid for non HT(11bg) packet

unsigned __pad0__ : 1

reserve

unsigned sig_mode : 2

0: non HT(11bg) packet; 1: HT(11n) packet; 3: VHT(11ac) packet

unsigned __pad1__ : 16

reserve

unsigned mcs : 7

Modulation Coding Scheme. If is HT(11n) packet, shows the modulation, range from 0 to 76(MSC0 ~ MCS76)

unsigned cwb : 1

Channel Bandwidth of the packet. 0: 20MHz; 1: 40MHz

unsigned __pad2__ : 16

reserve

unsigned smoothing : 1

reserve

unsigned not_sounding : 1

reserve

unsigned __pad3__ : 1

reserve

unsigned aggregation : 1

Aggregation. 0: MPDU packet; 1: AMPDU packet

unsigned stbc : 2

Space Time Block Code(STBC). 0: non STBC packet; 1: STBC packet

unsigned fec_coding : 1

Flag is set for 11n packets which are LDPC

unsigned sgi : 1

Short Guide Interval(SGI). 0: Long GI; 1: Short GI

signed noise_floor : 8

noise floor of Radio Frequency Module(RF). unit: 0.25dBm

unsigned ampdu_cnt : 8

ampdu cnt

unsigned channel : 4

primary channel on which this packet is received

unsigned secondary_channel : 4

secondary channel on which this packet is received. 0: none; 1: above; 2: below

unsigned __pad4__ : 8

reserve

unsigned timestamp : 32

timestamp. The local time when this packet is received. It is precise only if modem sleep or light sleep is not enabled. unit: microsecond

unsigned __pad5__ : 32

reserve

unsigned __pad6__ : 31

reserve

unsigned ant : 1

antenna number from which this packet is received. 0: WiFi antenna 0; 1: WiFi antenna 1

unsigned sig_len : 12

length of packet including Frame Check Sequence(FCS)

unsigned __pad7__ : 12

reserve

unsigned rx_state : 8

state of the packet. 0: no error; others: error numbers which are not public

struct wifi_promiscuous_pkt_t

Payload passed to ‘buf’ parameter of promiscuous mode RX callback.

Public Members

wifi_pkt_rx_ctrl_t rx_ctrl

metadata header

uint8_t payload[0]

Data or management payload. Length of payload is described by rx_ctrl.sig_len. Type of content determined by packet type argument of callback.

struct wifi_promiscuous_filter_t

Mask for filtering different packet types in promiscuous mode.

Public Members

uint32_t filter_mask

OR of one or more filter values WIFI_PROMIS_FILTER_*

struct wifi_csi_config_t

Channel state information(CSI) configuration type.

Public Members

bool lltf_en

enable to receive legacy long training field(lltf) data. Default enabled

bool htltf_en

enable to receive HT long training field(htltf) data. Default enabled

bool stbc_htltf2_en

enable to receive space time block code HT long training field(stbc-htltf2) data. Default enabled

bool ltf_merge_en

enable to generate htlft data by averaging lltf and ht_ltf data when receiving HT packet. Otherwise, use ht_ltf data directly. Default enabled

bool channel_filter_en

enable to turn on channel filter to smooth adjacent sub-carrier. Disable it to keep independence of adjacent sub-carrier. Default enabled

bool manu_scale

manually scale the CSI data by left shifting or automatically scale the CSI data. If set true, please set the shift bits. false: automatically. true: manually. Default false

uint8_t shift

manually left shift bits of the scale of the CSI data. The range of the left shift bits is 0~15

struct wifi_csi_info_t

CSI data type.

Public Members

wifi_pkt_rx_ctrl_t rx_ctrl

received packet radio metadata header of the CSI data

uint8_t mac[6]

source MAC address of the CSI data

bool first_word_invalid

first four bytes of the CSI data is invalid or not

int8_t *buf

buffer of CSI data

uint16_t len

length of CSI data

struct wifi_ant_gpio_t

WiFi GPIO configuration for antenna selection.

Public Members

uint8_t gpio_select : 1

Whether this GPIO is connected to external antenna switch

uint8_t gpio_num : 7

The GPIO number that connects to external antenna switch

struct wifi_ant_gpio_config_t

WiFi GPIOs configuration for antenna selection.

Public Members

wifi_ant_gpio_t gpio_cfg[4]

The configurations of GPIOs that connect to external antenna switch

struct wifi_ant_config_t

WiFi antenna configuration.

Public Members

wifi_ant_mode_t rx_ant_mode

WiFi antenna mode for receiving

wifi_ant_t rx_ant_default

Default antenna mode for receiving, it’s ignored if rx_ant_mode is not WIFI_ANT_MODE_AUTO

wifi_ant_mode_t tx_ant_mode

WiFi antenna mode for transmission, it can be set to WIFI_ANT_MODE_AUTO only if rx_ant_mode is set to WIFI_ANT_MODE_AUTO

uint8_t enabled_ant0 : 4

Index (in antenna GPIO configuration) of enabled WIFI_ANT_MODE_ANT0

uint8_t enabled_ant1 : 4

Index (in antenna GPIO configuration) of enabled WIFI_ANT_MODE_ANT1

struct wifi_event_sta_scan_done_t

Argument structure for WIFI_EVENT_SCAN_DONE event

Public Members

uint32_t status

status of scanning APs: 0 — success, 1 - failure

uint8_t number

number of scan results

uint8_t scan_id

scan sequence number, used for block scan

struct wifi_event_sta_connected_t

Argument structure for WIFI_EVENT_STA_CONNECTED event

Public Members

uint8_t ssid[32]

SSID of connected AP

uint8_t ssid_len

SSID length of connected AP

uint8_t bssid[6]

BSSID of connected AP

uint8_t channel

channel of connected AP

wifi_auth_mode_t authmode

authentication mode used by AP

struct wifi_event_sta_disconnected_t

Argument structure for WIFI_EVENT_STA_DISCONNECTED event

Public Members

uint8_t ssid[32]

SSID of disconnected AP

uint8_t ssid_len

SSID length of disconnected AP

uint8_t bssid[6]

BSSID of disconnected AP

uint8_t reason

reason of disconnection

struct wifi_event_sta_authmode_change_t

Argument structure for WIFI_EVENT_STA_AUTHMODE_CHANGE event

Public Members

wifi_auth_mode_t old_mode

the old auth mode of AP

wifi_auth_mode_t new_mode

the new auth mode of AP

struct wifi_event_sta_wps_er_pin_t

Argument structure for WIFI_EVENT_STA_WPS_ER_PIN event

Public Members

uint8_t pin_code[8]

PIN code of station in enrollee mode

struct wifi_event_sta_wps_er_success_t

Argument structure for WIFI_EVENT_STA_WPS_ER_SUCCESS event

Public Members

uint8_t ap_cred_cnt

Number of AP credentials received

uint8_t ssid[MAX_SSID_LEN]

SSID of AP

uint8_t passphrase[MAX_PASSPHRASE_LEN]

Passphrase for the AP

struct wifi_event_sta_wps_er_success_t::[anonymous] ap_cred[MAX_WPS_AP_CRED]

All AP credentials received from WPS handshake

struct wifi_event_ap_staconnected_t

Argument structure for WIFI_EVENT_AP_STACONNECTED event

Public Members

uint8_t mac[6]

MAC address of the station connected to ESP32 soft-AP

uint8_t aid

the aid that ESP32 soft-AP gives to the station connected to

struct wifi_event_ap_stadisconnected_t

Argument structure for WIFI_EVENT_AP_STADISCONNECTED event

Public Members

uint8_t mac[6]

MAC address of the station disconnects to ESP32 soft-AP

uint8_t aid

the aid that ESP32 soft-AP gave to the station disconnects to

struct wifi_event_ap_probe_req_rx_t

Argument structure for WIFI_EVENT_AP_PROBEREQRECVED event

Public Members

int rssi

Received probe request signal strength

uint8_t mac[6]

MAC address of the station which send probe request

Macros

WIFI_IF_STA
WIFI_IF_AP
WIFI_PROTOCOL_11B
WIFI_PROTOCOL_11G
WIFI_PROTOCOL_11N
WIFI_PROTOCOL_LR
ESP_WIFI_MAX_CONN_NUM

max number of stations which can connect to ESP32 soft-AP

WIFI_VENDOR_IE_ELEMENT_ID
WIFI_PROMIS_FILTER_MASK_ALL

filter all packets

WIFI_PROMIS_FILTER_MASK_MGMT

filter the packets with type of WIFI_PKT_MGMT

WIFI_PROMIS_FILTER_MASK_CTRL

filter the packets with type of WIFI_PKT_CTRL

WIFI_PROMIS_FILTER_MASK_DATA

filter the packets with type of WIFI_PKT_DATA

WIFI_PROMIS_FILTER_MASK_MISC

filter the packets with type of WIFI_PKT_MISC

WIFI_PROMIS_FILTER_MASK_DATA_MPDU

filter the MPDU which is a kind of WIFI_PKT_DATA

WIFI_PROMIS_FILTER_MASK_DATA_AMPDU

filter the AMPDU which is a kind of WIFI_PKT_DATA

WIFI_PROMIS_FILTER_MASK_FCSFAIL

filter the FCS failed packets, do not open it in general

WIFI_PROMIS_CTRL_FILTER_MASK_ALL

filter all control packets

WIFI_PROMIS_CTRL_FILTER_MASK_WRAPPER

filter the control packets with subtype of Control Wrapper

WIFI_PROMIS_CTRL_FILTER_MASK_BAR

filter the control packets with subtype of Block Ack Request

WIFI_PROMIS_CTRL_FILTER_MASK_BA

filter the control packets with subtype of Block Ack

WIFI_PROMIS_CTRL_FILTER_MASK_PSPOLL

filter the control packets with subtype of PS-Poll

WIFI_PROMIS_CTRL_FILTER_MASK_RTS

filter the control packets with subtype of RTS

WIFI_PROMIS_CTRL_FILTER_MASK_CTS

filter the control packets with subtype of CTS

WIFI_PROMIS_CTRL_FILTER_MASK_ACK

filter the control packets with subtype of ACK

WIFI_PROMIS_CTRL_FILTER_MASK_CFEND

filter the control packets with subtype of CF-END

WIFI_PROMIS_CTRL_FILTER_MASK_CFENDACK

filter the control packets with subtype of CF-END+CF-ACK

WIFI_EVENT_MASK_ALL

mask all WiFi events

WIFI_EVENT_MASK_NONE

mask none of the WiFi events

WIFI_EVENT_MASK_AP_PROBEREQRECVED

mask SYSTEM_EVENT_AP_PROBEREQRECVED event

MAX_SSID_LEN
MAX_PASSPHRASE_LEN
MAX_WPS_AP_CRED
WIFI_STATIS_BUFFER
WIFI_STATIS_RXTX
WIFI_STATIS_HW
WIFI_STATIS_DIAG
WIFI_STATIS_ALL

Type Definitions

typedef esp_interface_t wifi_interface_t

Enumerations

enum wifi_mode_t

Values:

WIFI_MODE_NULL = 0

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
enum wifi_country_policy_t

Values:

WIFI_COUNTRY_POLICY_AUTO

Country policy is auto, use the country info of AP to which the station is connected

WIFI_COUNTRY_POLICY_MANUAL

Country policy is manual, always use the configured country info

enum wifi_auth_mode_t

Values:

WIFI_AUTH_OPEN = 0

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_WPA2_ENTERPRISE

authenticate mode : WPA2_ENTERPRISE

WIFI_AUTH_WPA3_PSK

authenticate mode : WPA3_PSK

WIFI_AUTH_WPA2_WPA3_PSK

authenticate mode : WPA2_WPA3_PSK

WIFI_AUTH_MAX
enum wifi_err_reason_t

Values:

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_INVALID_PMKID = 53
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
WIFI_REASON_CONNECTION_FAIL = 205
WIFI_REASON_AP_TSF_RESET = 206
enum wifi_second_chan_t

Values:

WIFI_SECOND_CHAN_NONE = 0

the channel width is HT20

WIFI_SECOND_CHAN_ABOVE

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

WIFI_SECOND_CHAN_BELOW

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

enum wifi_scan_type_t

Values:

WIFI_SCAN_TYPE_ACTIVE = 0

active scan

WIFI_SCAN_TYPE_PASSIVE

passive scan

enum wifi_cipher_type_t

Values:

WIFI_CIPHER_TYPE_NONE = 0

the cipher type is none

WIFI_CIPHER_TYPE_WEP40

the cipher type is WEP40

WIFI_CIPHER_TYPE_WEP104

the cipher type is WEP104

WIFI_CIPHER_TYPE_TKIP

the cipher type is TKIP

WIFI_CIPHER_TYPE_CCMP

the cipher type is CCMP

WIFI_CIPHER_TYPE_TKIP_CCMP

the cipher type is TKIP and CCMP

WIFI_CIPHER_TYPE_AES_CMAC128

the cipher type is AES-CMAC-128

WIFI_CIPHER_TYPE_UNKNOWN

the cipher type is unknown

enum wifi_ant_t

WiFi antenna.

Values:

WIFI_ANT_ANT0

WiFi antenna 0

WIFI_ANT_ANT1

WiFi antenna 1

WIFI_ANT_MAX

Invalid WiFi antenna

enum wifi_scan_method_t

Values:

WIFI_FAST_SCAN = 0

Do fast scan, scan will end after find SSID match AP

WIFI_ALL_CHANNEL_SCAN

All channel scan, scan will end after scan all the channel

enum wifi_sort_method_t

Values:

WIFI_CONNECT_AP_BY_SIGNAL = 0

Sort match AP in scan list by RSSI

WIFI_CONNECT_AP_BY_SECURITY

Sort match AP in scan list by security mode

enum wifi_ps_type_t

Values:

WIFI_PS_NONE

No power save

WIFI_PS_MIN_MODEM

Minimum modem power saving. In this mode, station wakes up to receive beacon every DTIM period

WIFI_PS_MAX_MODEM

Maximum modem power saving. In this mode, interval to receive beacons is determined by the listen_interval parameter in wifi_sta_config_t

enum wifi_bandwidth_t

Values:

WIFI_BW_HT20 = 1
WIFI_BW_HT40
enum wifi_storage_t

Values:

WIFI_STORAGE_FLASH

all configuration will store in both memory and flash

WIFI_STORAGE_RAM

all configuration will only store in the memory

enum wifi_vendor_ie_type_t

Vendor Information Element type.

Determines the frame type that the IE will be associated with.

Values:

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
enum wifi_vendor_ie_id_t

Vendor Information Element index.

Each IE type can have up to two associated vendor ID elements.

Values:

WIFI_VND_IE_ID_0
WIFI_VND_IE_ID_1
enum wifi_promiscuous_pkt_type_t

Promiscuous frame type.

Passed to promiscuous mode RX callback to indicate the type of parameter in the buffer.

Values:

WIFI_PKT_MGMT

Management frame, indicates ‘buf’ argument is wifi_promiscuous_pkt_t

WIFI_PKT_CTRL

Control frame, indicates ‘buf’ argument is wifi_promiscuous_pkt_t

WIFI_PKT_DATA

Data frame, indiciates ‘buf’ argument is wifi_promiscuous_pkt_t

WIFI_PKT_MISC

Other type, such as MIMO etc. ‘buf’ argument is wifi_promiscuous_pkt_t but the payload is zero length.

enum wifi_ant_mode_t

WiFi antenna mode.

Values:

WIFI_ANT_MODE_ANT0

Enable WiFi antenna 0 only

WIFI_ANT_MODE_ANT1

Enable WiFi antenna 1 only

WIFI_ANT_MODE_AUTO

Enable WiFi antenna 0 and 1, automatically select an antenna

WIFI_ANT_MODE_MAX

Invalid WiFi enabled antenna

enum wifi_phy_rate_t

WiFi PHY rate encodings.

Values:

WIFI_PHY_RATE_1M_L = 0x00

1 Mbps with long preamble

WIFI_PHY_RATE_2M_L = 0x01

2 Mbps with long preamble

WIFI_PHY_RATE_5M_L = 0x02

5.5 Mbps with long preamble

WIFI_PHY_RATE_11M_L = 0x03

11 Mbps with long preamble

WIFI_PHY_RATE_2M_S = 0x05

2 Mbps with short preamble

WIFI_PHY_RATE_5M_S = 0x06

5.5 Mbps with short preamble

WIFI_PHY_RATE_11M_S = 0x07

11 Mbps with short preamble

WIFI_PHY_RATE_48M = 0x08

48 Mbps

WIFI_PHY_RATE_24M = 0x09

24 Mbps

WIFI_PHY_RATE_12M = 0x0A

12 Mbps

WIFI_PHY_RATE_6M = 0x0B

6 Mbps

WIFI_PHY_RATE_54M = 0x0C

54 Mbps

WIFI_PHY_RATE_36M = 0x0D

36 Mbps

WIFI_PHY_RATE_18M = 0x0E

18 Mbps

WIFI_PHY_RATE_9M = 0x0F

9 Mbps

WIFI_PHY_RATE_MCS0_LGI = 0x10

MCS0 with long GI, 6.5 Mbps for 20MHz, 13.5 Mbps for 40MHz

WIFI_PHY_RATE_MCS1_LGI = 0x11

MCS1 with long GI, 13 Mbps for 20MHz, 27 Mbps for 40MHz

WIFI_PHY_RATE_MCS2_LGI = 0x12

MCS2 with long GI, 19.5 Mbps for 20MHz, 40.5 Mbps for 40MHz

WIFI_PHY_RATE_MCS3_LGI = 0x13

MCS3 with long GI, 26 Mbps for 20MHz, 54 Mbps for 40MHz

WIFI_PHY_RATE_MCS4_LGI = 0x14

MCS4 with long GI, 39 Mbps for 20MHz, 81 Mbps for 40MHz

WIFI_PHY_RATE_MCS5_LGI = 0x15

MCS5 with long GI, 52 Mbps for 20MHz, 108 Mbps for 40MHz

WIFI_PHY_RATE_MCS6_LGI = 0x16

MCS6 with long GI, 58.5 Mbps for 20MHz, 121.5 Mbps for 40MHz

WIFI_PHY_RATE_MCS7_LGI = 0x17

MCS7 with long GI, 65 Mbps for 20MHz, 135 Mbps for 40MHz

WIFI_PHY_RATE_MCS0_SGI = 0x18

MCS0 with short GI, 7.2 Mbps for 20MHz, 15 Mbps for 40MHz

WIFI_PHY_RATE_MCS1_SGI = 0x19

MCS1 with short GI, 14.4 Mbps for 20MHz, 30 Mbps for 40MHz

WIFI_PHY_RATE_MCS2_SGI = 0x1A

MCS2 with short GI, 21.7 Mbps for 20MHz, 45 Mbps for 40MHz

WIFI_PHY_RATE_MCS3_SGI = 0x1B

MCS3 with short GI, 28.9 Mbps for 20MHz, 60 Mbps for 40MHz

WIFI_PHY_RATE_MCS4_SGI = 0x1C

MCS4 with short GI, 43.3 Mbps for 20MHz, 90 Mbps for 40MHz

WIFI_PHY_RATE_MCS5_SGI = 0x1D

MCS5 with short GI, 57.8 Mbps for 20MHz, 120 Mbps for 40MHz

WIFI_PHY_RATE_MCS6_SGI = 0x1E

MCS6 with short GI, 65 Mbps for 20MHz, 135 Mbps for 40MHz

WIFI_PHY_RATE_MCS7_SGI = 0x1F

MCS7 with short GI, 72.2 Mbps for 20MHz, 150 Mbps for 40MHz

WIFI_PHY_RATE_LORA_250K = 0x29

250 Kbps

WIFI_PHY_RATE_LORA_500K = 0x2A

500 Kbps

WIFI_PHY_RATE_MAX
enum wifi_event_t

WiFi event declarations

Values:

WIFI_EVENT_WIFI_READY = 0

ESP32 WiFi ready

WIFI_EVENT_SCAN_DONE

ESP32 finish scanning AP

WIFI_EVENT_STA_START

ESP32 station start

WIFI_EVENT_STA_STOP

ESP32 station stop

WIFI_EVENT_STA_CONNECTED

ESP32 station connected to AP

WIFI_EVENT_STA_DISCONNECTED

ESP32 station disconnected from AP

WIFI_EVENT_STA_AUTHMODE_CHANGE

the auth mode of AP connected by ESP32 station changed

WIFI_EVENT_STA_BEACON_TIMEOUT

ESP32 station beacon timeout

WIFI_EVENT_STA_WPS_ER_SUCCESS

ESP32 station wps succeeds in enrollee mode

WIFI_EVENT_STA_WPS_ER_FAILED

ESP32 station wps fails in enrollee mode

WIFI_EVENT_STA_WPS_ER_TIMEOUT

ESP32 station wps timeout in enrollee mode

WIFI_EVENT_STA_WPS_ER_PIN

ESP32 station wps pin code in enrollee mode

WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP

ESP32 station wps overlap in enrollee mode

WIFI_EVENT_AP_START

ESP32 soft-AP start

WIFI_EVENT_AP_STOP

ESP32 soft-AP stop

WIFI_EVENT_AP_STACONNECTED

a station connected to ESP32 soft-AP

WIFI_EVENT_AP_STADISCONNECTED

a station disconnected from ESP32 soft-AP

WIFI_EVENT_AP_PROBEREQRECVED

Receive probe request packet in soft-AP interface

WIFI_EVENT_MAX

Invalid WiFi event ID

enum wifi_event_sta_wps_fail_reason_t

Argument structure for WIFI_EVENT_STA_WPS_ER_FAILED event

Values:

WPS_FAIL_REASON_NORMAL = 0

ESP32 WPS normal fail reason

WPS_FAIL_REASON_RECV_M2D

ESP32 WPS receive M2D frame

WPS_FAIL_REASON_MAX