1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 8 #ifndef __ESP_WIFI_TYPES_H__ 9 #define __ESP_WIFI_TYPES_H__ 10 11 #include "esp_private/esp_wifi_types_private.h" 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 typedef enum { 18 ESP32_WIFI_MODE_NULL = 0, /**< null mode */ 19 ESP32_WIFI_MODE_STA, /**< WiFi station mode */ 20 ESP32_WIFI_MODE_AP, /**< WiFi soft-AP mode */ 21 ESP32_WIFI_MODE_APSTA, /**< WiFi station + soft-AP mode */ 22 ESP32_WIFI_MODE_MAX 23 } wifi_mode_t; 24 25 typedef enum { 26 WIFI_IF_STA = ESP_IF_WIFI_STA, 27 WIFI_IF_AP = ESP_IF_WIFI_AP, 28 } wifi_interface_t; 29 30 #define WIFI_OFFCHAN_TX_REQ 1 31 #define WIFI_OFFCHAN_TX_CANCEL 0 32 33 #define WIFI_ROC_REQ 1 34 #define WIFI_ROC_CANCEL 0 35 36 typedef enum { 37 WIFI_COUNTRY_POLICY_AUTO, /**< Country policy is auto, use the country info of AP to which the station is connected */ 38 WIFI_COUNTRY_POLICY_MANUAL, /**< Country policy is manual, always use the configured country info */ 39 } wifi_country_policy_t; 40 41 /** @brief Structure describing WiFi country-based regional restrictions. */ 42 typedef struct { 43 char cc[3]; /**< country code string */ 44 uint8_t schan; /**< start channel */ 45 uint8_t nchan; /**< total channel number */ 46 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. */ 47 wifi_country_policy_t policy; /**< country policy */ 48 } wifi_country_t; 49 50 typedef enum { 51 WIFI_AUTH_OPEN = 0, /**< authenticate mode : open */ 52 WIFI_AUTH_WEP, /**< authenticate mode : WEP */ 53 WIFI_AUTH_WPA_PSK, /**< authenticate mode : WPA_PSK */ 54 WIFI_AUTH_WPA2_PSK, /**< authenticate mode : WPA2_PSK */ 55 WIFI_AUTH_WPA_WPA2_PSK, /**< authenticate mode : WPA_WPA2_PSK */ 56 WIFI_AUTH_WPA2_ENTERPRISE, /**< authenticate mode : WPA2_ENTERPRISE */ 57 WIFI_AUTH_WPA3_PSK, /**< authenticate mode : WPA3_PSK */ 58 WIFI_AUTH_WPA2_WPA3_PSK, /**< authenticate mode : WPA2_WPA3_PSK */ 59 WIFI_AUTH_WAPI_PSK, /**< authenticate mode : WAPI_PSK */ 60 WIFI_AUTH_MAX 61 } wifi_auth_mode_t; 62 63 typedef enum { 64 WIFI_REASON_UNSPECIFIED = 1, 65 WIFI_REASON_AUTH_EXPIRE = 2, 66 WIFI_REASON_AUTH_LEAVE = 3, 67 WIFI_REASON_ASSOC_EXPIRE = 4, 68 WIFI_REASON_ASSOC_TOOMANY = 5, 69 WIFI_REASON_NOT_AUTHED = 6, 70 WIFI_REASON_NOT_ASSOCED = 7, 71 WIFI_REASON_ASSOC_LEAVE = 8, 72 WIFI_REASON_ASSOC_NOT_AUTHED = 9, 73 WIFI_REASON_DISASSOC_PWRCAP_BAD = 10, 74 WIFI_REASON_DISASSOC_SUPCHAN_BAD = 11, 75 WIFI_REASON_BSS_TRANSITION_DISASSOC = 12, 76 WIFI_REASON_IE_INVALID = 13, 77 WIFI_REASON_MIC_FAILURE = 14, 78 WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT = 15, 79 WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT = 16, 80 WIFI_REASON_IE_IN_4WAY_DIFFERS = 17, 81 WIFI_REASON_GROUP_CIPHER_INVALID = 18, 82 WIFI_REASON_PAIRWISE_CIPHER_INVALID = 19, 83 WIFI_REASON_AKMP_INVALID = 20, 84 WIFI_REASON_UNSUPP_RSN_IE_VERSION = 21, 85 WIFI_REASON_INVALID_RSN_IE_CAP = 22, 86 WIFI_REASON_802_1X_AUTH_FAILED = 23, 87 WIFI_REASON_CIPHER_SUITE_REJECTED = 24, 88 89 WIFI_REASON_INVALID_PMKID = 53, 90 91 WIFI_REASON_BEACON_TIMEOUT = 200, 92 WIFI_REASON_NO_AP_FOUND = 201, 93 WIFI_REASON_AUTH_FAIL = 202, 94 WIFI_REASON_ASSOC_FAIL = 203, 95 WIFI_REASON_HANDSHAKE_TIMEOUT = 204, 96 WIFI_REASON_CONNECTION_FAIL = 205, 97 WIFI_REASON_AP_TSF_RESET = 206, 98 WIFI_REASON_ROAMING = 207, 99 } wifi_err_reason_t; 100 101 typedef enum { 102 WIFI_SECOND_CHAN_NONE = 0, /**< the channel width is HT20 */ 103 WIFI_SECOND_CHAN_ABOVE, /**< the channel width is HT40 and the secondary channel is above the primary channel */ 104 WIFI_SECOND_CHAN_BELOW, /**< the channel width is HT40 and the secondary channel is below the primary channel */ 105 } wifi_second_chan_t; 106 107 typedef enum { 108 WIFI_SCAN_TYPE_ACTIVE = 0, /**< active scan */ 109 WIFI_SCAN_TYPE_PASSIVE, /**< passive scan */ 110 } wifi_scan_type_t; 111 112 /** @brief Range of active scan times per channel */ 113 typedef struct { 114 uint32_t min; /**< minimum active scan time per channel, units: millisecond */ 115 uint32_t max; /**< maximum active scan time per channel, units: millisecond, values above 1500ms may 116 cause station to disconnect from AP and are not recommended. */ 117 } wifi_active_scan_time_t; 118 119 /** @brief Aggregate of active & passive scan time per channel */ 120 typedef struct { 121 wifi_active_scan_time_t active; /**< active scan time per channel, units: millisecond. */ 122 uint32_t passive; /**< passive scan time per channel, units: millisecond, values above 1500ms may 123 cause station to disconnect from AP and are not recommended. */ 124 } wifi_scan_time_t; 125 126 /** @brief Parameters for an SSID scan. */ 127 typedef struct { 128 uint8_t *ssid; /**< SSID of AP */ 129 uint8_t *bssid; /**< MAC address of AP */ 130 uint8_t channel; /**< channel, scan the specific channel */ 131 bool show_hidden; /**< enable to scan AP whose SSID is hidden */ 132 wifi_scan_type_t scan_type; /**< scan type, active or passive */ 133 wifi_scan_time_t scan_time; /**< scan time per channel */ 134 } wifi_scan_config_t; 135 136 typedef enum { 137 WIFI_CIPHER_TYPE_NONE = 0, /**< the cipher type is none */ 138 WIFI_CIPHER_TYPE_WEP40, /**< the cipher type is WEP40 */ 139 WIFI_CIPHER_TYPE_WEP104, /**< the cipher type is WEP104 */ 140 WIFI_CIPHER_TYPE_TKIP, /**< the cipher type is TKIP */ 141 WIFI_CIPHER_TYPE_CCMP, /**< the cipher type is CCMP */ 142 WIFI_CIPHER_TYPE_TKIP_CCMP, /**< the cipher type is TKIP and CCMP */ 143 WIFI_CIPHER_TYPE_AES_CMAC128,/**< the cipher type is AES-CMAC-128 */ 144 WIFI_CIPHER_TYPE_SMS4, /**< the cipher type is SMS4 */ 145 WIFI_CIPHER_TYPE_GCMP, /**< the cipher type is GCMP */ 146 WIFI_CIPHER_TYPE_GCMP256, /**< the cipher type is GCMP-256 */ 147 WIFI_CIPHER_TYPE_AES_GMAC128,/**< the cipher type is AES-GMAC-128 */ 148 WIFI_CIPHER_TYPE_AES_GMAC256,/**< the cipher type is AES-GMAC-256 */ 149 WIFI_CIPHER_TYPE_UNKNOWN, /**< the cipher type is unknown */ 150 } wifi_cipher_type_t; 151 152 /** 153 * @brief WiFi antenna 154 * 155 */ 156 typedef enum { 157 WIFI_ANT_ANT0, /**< WiFi antenna 0 */ 158 WIFI_ANT_ANT1, /**< WiFi antenna 1 */ 159 WIFI_ANT_MAX, /**< Invalid WiFi antenna */ 160 } wifi_ant_t; 161 162 /** @brief Description of a WiFi AP */ 163 typedef struct { 164 uint8_t bssid[6]; /**< MAC address of AP */ 165 uint8_t ssid[33]; /**< SSID of AP */ 166 uint8_t primary; /**< channel of AP */ 167 wifi_second_chan_t second; /**< secondary channel of AP */ 168 int8_t rssi; /**< signal strength of AP */ 169 wifi_auth_mode_t authmode; /**< authmode of AP */ 170 wifi_cipher_type_t pairwise_cipher; /**< pairwise cipher of AP */ 171 wifi_cipher_type_t group_cipher; /**< group cipher of AP */ 172 wifi_ant_t ant; /**< antenna used to receive beacon from AP */ 173 uint32_t phy_11b:1; /**< bit: 0 flag to identify if 11b mode is enabled or not */ 174 uint32_t phy_11g:1; /**< bit: 1 flag to identify if 11g mode is enabled or not */ 175 uint32_t phy_11n:1; /**< bit: 2 flag to identify if 11n mode is enabled or not */ 176 uint32_t phy_lr:1; /**< bit: 3 flag to identify if low rate is enabled or not */ 177 uint32_t wps:1; /**< bit: 4 flag to identify if WPS is supported or not */ 178 uint32_t ftm_responder:1; /**< bit: 5 flag to identify if FTM is supported in responder mode */ 179 uint32_t ftm_initiator:1; /**< bit: 6 flag to identify if FTM is supported in initiator mode */ 180 uint32_t reserved:25; /**< bit: 7..31 reserved */ 181 wifi_country_t country; /**< country information of AP */ 182 } wifi_ap_record_t; 183 184 typedef enum { 185 WIFI_FAST_SCAN = 0, /**< Do fast scan, scan will end after find SSID match AP */ 186 WIFI_ALL_CHANNEL_SCAN, /**< All channel scan, scan will end after scan all the channel */ 187 }wifi_scan_method_t; 188 189 typedef enum { 190 WIFI_CONNECT_AP_BY_SIGNAL = 0, /**< Sort match AP in scan list by RSSI */ 191 WIFI_CONNECT_AP_BY_SECURITY, /**< Sort match AP in scan list by security mode */ 192 }wifi_sort_method_t; 193 194 /** @brief Structure describing parameters for a WiFi fast scan */ 195 typedef struct { 196 int8_t rssi; /**< The minimum rssi to accept in the fast scan mode */ 197 wifi_auth_mode_t authmode; /**< The weakest authmode to accept in the fast scan mode */ 198 }wifi_scan_threshold_t; 199 200 typedef enum { 201 WIFI_PS_NONE, /**< No power save */ 202 WIFI_PS_MIN_MODEM, /**< Minimum modem power saving. In this mode, station wakes up to receive beacon every DTIM period */ 203 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 */ 204 } wifi_ps_type_t; 205 206 #define WIFI_PROTOCOL_11B 1 207 #define WIFI_PROTOCOL_11G 2 208 #define WIFI_PROTOCOL_11N 4 209 #define WIFI_PROTOCOL_LR 8 210 211 typedef enum { 212 WIFI_BW_HT20 = 1, /* Bandwidth is HT20 */ 213 WIFI_BW_HT40, /* Bandwidth is HT40 */ 214 } wifi_bandwidth_t; 215 216 /** Configuration structure for Protected Management Frame */ 217 typedef struct { 218 bool capable; /**< Deprecated variable. Device will always connect in PMF mode if other device also advertizes PMF capability. */ 219 bool required; /**< Advertizes that Protected Management Frame is required. Device will not associate to non-PMF capable devices. */ 220 } wifi_pmf_config_t; 221 222 /** @brief Soft-AP configuration settings for the ESP32 */ 223 typedef struct { 224 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. */ 225 uint8_t password[64]; /**< Password of ESP32 soft-AP. */ 226 uint8_t ssid_len; /**< Optional length of SSID field. */ 227 uint8_t channel; /**< Channel of ESP32 soft-AP */ 228 wifi_auth_mode_t authmode; /**< Auth mode of ESP32 soft-AP. Do not support AUTH_WEP in soft-AP mode */ 229 uint8_t ssid_hidden; /**< Broadcast SSID or not, default 0, broadcast the SSID */ 230 uint8_t max_connection; /**< Max number of stations allowed to connect in, default 4, max 10 */ 231 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 */ 232 wifi_cipher_type_t pairwise_cipher; /**< pairwise cipher of SoftAP, group cipher will be derived using this. cipher values are valid starting from WIFI_CIPHER_TYPE_TKIP, enum values before that will be considered as invalid and default cipher suites(TKIP+CCMP) will be used. Valid cipher suites in softAP mode are WIFI_CIPHER_TYPE_TKIP, WIFI_CIPHER_TYPE_CCMP and WIFI_CIPHER_TYPE_TKIP_CCMP. */ 233 bool ftm_responder; /**< Enable FTM Responder mode */ 234 } wifi_ap_config_t; 235 236 /** @brief STA configuration settings for the ESP32 */ 237 typedef struct { 238 uint8_t ssid[32]; /**< SSID of target AP. */ 239 uint8_t password[64]; /**< Password of target AP. */ 240 wifi_scan_method_t scan_method; /**< do all channel scan or fast scan */ 241 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.*/ 242 uint8_t bssid[6]; /**< MAC address of target AP*/ 243 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.*/ 244 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. */ 245 wifi_sort_method_t sort_method; /**< sort the connect AP in the list by rssi or security mode */ 246 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. */ 247 wifi_pmf_config_t pmf_cfg; /**< Configuration for Protected Management Frame. Will be advertized in RSN Capabilities in RSN IE. */ 248 uint32_t rm_enabled:1; /**< Whether Radio Measurements are enabled for the connection */ 249 uint32_t btm_enabled:1; /**< Whether BSS Transition Management is enabled for the connection */ 250 uint32_t mbo_enabled:1; /**< Whether MBO is enabled for the connection */ 251 uint32_t reserved:29; /**< Reserved for future feature set */ 252 } wifi_sta_config_t; 253 254 /** @brief Configuration data for ESP32 AP or STA. 255 * 256 * The usage of this union (for ap or sta configuration) is determined by the accompanying 257 * interface argument passed to esp_wifi_set_config() or esp_wifi_get_config() 258 * 259 */ 260 typedef union { 261 wifi_ap_config_t ap; /**< configuration of AP */ 262 wifi_sta_config_t sta; /**< configuration of STA */ 263 } wifi_config_t; 264 265 /** @brief Description of STA associated with AP */ 266 typedef struct { 267 uint8_t mac[6]; /**< mac address */ 268 int8_t rssi; /**< current average rssi of sta connected */ 269 uint32_t phy_11b:1; /**< bit: 0 flag to identify if 11b mode is enabled or not */ 270 uint32_t phy_11g:1; /**< bit: 1 flag to identify if 11g mode is enabled or not */ 271 uint32_t phy_11n:1; /**< bit: 2 flag to identify if 11n mode is enabled or not */ 272 uint32_t phy_lr:1; /**< bit: 3 flag to identify if low rate is enabled or not */ 273 uint32_t is_mesh_child:1;/**< bit: 4 flag to identify mesh child */ 274 uint32_t reserved:27; /**< bit: 5..31 reserved */ 275 } wifi_sta_info_t; 276 277 #define ESP_WIFI_MAX_CONN_NUM (10) /**< max number of stations which can connect to ESP32 soft-AP */ 278 279 /** @brief List of stations associated with the ESP32 Soft-AP */ 280 typedef struct { 281 wifi_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM]; /**< station list */ 282 int num; /**< number of stations in the list (other entries are invalid) */ 283 } wifi_sta_list_t; 284 285 typedef enum { 286 WIFI_STORAGE_FLASH, /**< all configuration will store in both memory and flash */ 287 WIFI_STORAGE_RAM, /**< all configuration will only store in the memory */ 288 } wifi_storage_t; 289 290 /** 291 * @brief Vendor Information Element type 292 * 293 * Determines the frame type that the IE will be associated with. 294 */ 295 typedef enum { 296 WIFI_VND_IE_TYPE_BEACON, 297 WIFI_VND_IE_TYPE_PROBE_REQ, 298 WIFI_VND_IE_TYPE_PROBE_RESP, 299 WIFI_VND_IE_TYPE_ASSOC_REQ, 300 WIFI_VND_IE_TYPE_ASSOC_RESP, 301 } wifi_vendor_ie_type_t; 302 303 /** 304 * @brief Vendor Information Element index 305 * 306 * Each IE type can have up to two associated vendor ID elements. 307 */ 308 typedef enum { 309 WIFI_VND_IE_ID_0, 310 WIFI_VND_IE_ID_1, 311 } wifi_vendor_ie_id_t; 312 313 #define WIFI_VENDOR_IE_ELEMENT_ID 0xDD 314 315 /** 316 * @brief Vendor Information Element header 317 * 318 * The first bytes of the Information Element will match this header. Payload follows. 319 */ 320 typedef struct { 321 uint8_t element_id; /**< Should be set to WIFI_VENDOR_IE_ELEMENT_ID (0xDD) */ 322 uint8_t length; /**< Length of all bytes in the element data following this field. Minimum 4. */ 323 uint8_t vendor_oui[3]; /**< Vendor identifier (OUI). */ 324 uint8_t vendor_oui_type; /**< Vendor-specific OUI type. */ 325 uint8_t payload[0]; /**< Payload. Length is equal to value in 'length' field, minus 4. */ 326 } vendor_ie_data_t; 327 328 /** @brief Received packet radio metadata header, this is the common header at the beginning of all promiscuous mode RX callback buffers */ 329 typedef struct { 330 signed rssi:8; /**< Received Signal Strength Indicator(RSSI) of packet. unit: dBm */ 331 unsigned rate:5; /**< PHY rate encoding of the packet. Only valid for non HT(11bg) packet */ 332 unsigned :1; /**< reserved */ 333 unsigned sig_mode:2; /**< 0: non HT(11bg) packet; 1: HT(11n) packet; 3: VHT(11ac) packet */ 334 unsigned :16; /**< reserved */ 335 unsigned mcs:7; /**< Modulation Coding Scheme. If is HT(11n) packet, shows the modulation, range from 0 to 76(MSC0 ~ MCS76) */ 336 unsigned cwb:1; /**< Channel Bandwidth of the packet. 0: 20MHz; 1: 40MHz */ 337 unsigned :16; /**< reserved */ 338 unsigned smoothing:1; /**< reserved */ 339 unsigned not_sounding:1; /**< reserved */ 340 unsigned :1; /**< reserved */ 341 unsigned aggregation:1; /**< Aggregation. 0: MPDU packet; 1: AMPDU packet */ 342 unsigned stbc:2; /**< Space Time Block Code(STBC). 0: non STBC packet; 1: STBC packet */ 343 unsigned fec_coding:1; /**< Flag is set for 11n packets which are LDPC */ 344 unsigned sgi:1; /**< Short Guide Interval(SGI). 0: Long GI; 1: Short GI */ 345 #if CONFIG_IDF_TARGET_ESP32 346 signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/ 347 #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 348 unsigned :8; /**< reserved */ 349 #endif 350 unsigned ampdu_cnt:8; /**< ampdu cnt */ 351 unsigned channel:4; /**< primary channel on which this packet is received */ 352 unsigned secondary_channel:4; /**< secondary channel on which this packet is received. 0: none; 1: above; 2: below */ 353 unsigned :8; /**< reserved */ 354 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 */ 355 unsigned :32; /**< reserved */ 356 #if CONFIG_IDF_TARGET_ESP32S2 357 unsigned :32; /**< reserved */ 358 #elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 359 signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/ 360 unsigned :24; /**< reserved */ 361 unsigned :32; /**< reserved */ 362 #endif 363 unsigned :31; /**< reserved */ 364 unsigned ant:1; /**< antenna number from which this packet is received. 0: WiFi antenna 0; 1: WiFi antenna 1 */ 365 #if CONFIG_IDF_TARGET_ESP32S2 366 signed noise_floor:8; /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/ 367 unsigned :24; /**< reserved */ 368 #elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3 369 unsigned :32; /**< reserved */ 370 unsigned :32; /**< reserved */ 371 unsigned :32; /**< reserved */ 372 #endif 373 unsigned sig_len:12; /**< length of packet including Frame Check Sequence(FCS) */ 374 unsigned :12; /**< reserved */ 375 unsigned rx_state:8; /**< state of the packet. 0: no error; others: error numbers which are not public */ 376 } wifi_pkt_rx_ctrl_t; 377 378 /** @brief Payload passed to 'buf' parameter of promiscuous mode RX callback. 379 */ 380 typedef struct { 381 wifi_pkt_rx_ctrl_t rx_ctrl; /**< metadata header */ 382 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. */ 383 } wifi_promiscuous_pkt_t; 384 385 /** 386 * @brief Promiscuous frame type 387 * 388 * Passed to promiscuous mode RX callback to indicate the type of parameter in the buffer. 389 * 390 */ 391 typedef enum { 392 WIFI_PKT_MGMT, /**< Management frame, indicates 'buf' argument is wifi_promiscuous_pkt_t */ 393 WIFI_PKT_CTRL, /**< Control frame, indicates 'buf' argument is wifi_promiscuous_pkt_t */ 394 WIFI_PKT_DATA, /**< Data frame, indiciates 'buf' argument is wifi_promiscuous_pkt_t */ 395 WIFI_PKT_MISC, /**< Other type, such as MIMO etc. 'buf' argument is wifi_promiscuous_pkt_t but the payload is zero length. */ 396 } wifi_promiscuous_pkt_type_t; 397 398 399 #define WIFI_PROMIS_FILTER_MASK_ALL (0xFFFFFFFF) /**< filter all packets */ 400 #define WIFI_PROMIS_FILTER_MASK_MGMT (1) /**< filter the packets with type of WIFI_PKT_MGMT */ 401 #define WIFI_PROMIS_FILTER_MASK_CTRL (1<<1) /**< filter the packets with type of WIFI_PKT_CTRL */ 402 #define WIFI_PROMIS_FILTER_MASK_DATA (1<<2) /**< filter the packets with type of WIFI_PKT_DATA */ 403 #define WIFI_PROMIS_FILTER_MASK_MISC (1<<3) /**< filter the packets with type of WIFI_PKT_MISC */ 404 #define WIFI_PROMIS_FILTER_MASK_DATA_MPDU (1<<4) /**< filter the MPDU which is a kind of WIFI_PKT_DATA */ 405 #define WIFI_PROMIS_FILTER_MASK_DATA_AMPDU (1<<5) /**< filter the AMPDU which is a kind of WIFI_PKT_DATA */ 406 #define WIFI_PROMIS_FILTER_MASK_FCSFAIL (1<<6) /**< filter the FCS failed packets, do not open it in general */ 407 408 #define WIFI_PROMIS_CTRL_FILTER_MASK_ALL (0xFF800000) /**< filter all control packets */ 409 #define WIFI_PROMIS_CTRL_FILTER_MASK_WRAPPER (1<<23) /**< filter the control packets with subtype of Control Wrapper */ 410 #define WIFI_PROMIS_CTRL_FILTER_MASK_BAR (1<<24) /**< filter the control packets with subtype of Block Ack Request */ 411 #define WIFI_PROMIS_CTRL_FILTER_MASK_BA (1<<25) /**< filter the control packets with subtype of Block Ack */ 412 #define WIFI_PROMIS_CTRL_FILTER_MASK_PSPOLL (1<<26) /**< filter the control packets with subtype of PS-Poll */ 413 #define WIFI_PROMIS_CTRL_FILTER_MASK_RTS (1<<27) /**< filter the control packets with subtype of RTS */ 414 #define WIFI_PROMIS_CTRL_FILTER_MASK_CTS (1<<28) /**< filter the control packets with subtype of CTS */ 415 #define WIFI_PROMIS_CTRL_FILTER_MASK_ACK (1<<29) /**< filter the control packets with subtype of ACK */ 416 #define WIFI_PROMIS_CTRL_FILTER_MASK_CFEND (1<<30) /**< filter the control packets with subtype of CF-END */ 417 #define WIFI_PROMIS_CTRL_FILTER_MASK_CFENDACK (1<<31) /**< filter the control packets with subtype of CF-END+CF-ACK */ 418 419 /** @brief Mask for filtering different packet types in promiscuous mode. */ 420 typedef struct { 421 uint32_t filter_mask; /**< OR of one or more filter values WIFI_PROMIS_FILTER_* */ 422 } wifi_promiscuous_filter_t; 423 424 #define WIFI_EVENT_MASK_ALL (0xFFFFFFFF) /**< mask all WiFi events */ 425 #define WIFI_EVENT_MASK_NONE (0) /**< mask none of the WiFi events */ 426 #define WIFI_EVENT_MASK_AP_PROBEREQRECVED (BIT(0)) /**< mask SYSTEM_EVENT_AP_PROBEREQRECVED event */ 427 428 /** 429 * @brief Channel state information(CSI) configuration type 430 * 431 */ 432 typedef struct { 433 bool lltf_en; /**< enable to receive legacy long training field(lltf) data. Default enabled */ 434 bool htltf_en; /**< enable to receive HT long training field(htltf) data. Default enabled */ 435 bool stbc_htltf2_en; /**< enable to receive space time block code HT long training field(stbc-htltf2) data. Default enabled */ 436 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 */ 437 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 */ 438 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 */ 439 uint8_t shift; /**< manually left shift bits of the scale of the CSI data. The range of the left shift bits is 0~15 */ 440 } wifi_csi_config_t; 441 442 /** 443 * @brief CSI data type 444 * 445 */ 446 typedef struct { 447 wifi_pkt_rx_ctrl_t rx_ctrl;/**< received packet radio metadata header of the CSI data */ 448 uint8_t mac[6]; /**< source MAC address of the CSI data */ 449 bool first_word_invalid; /**< first four bytes of the CSI data is invalid or not */ 450 int8_t *buf; /**< buffer of CSI data */ 451 uint16_t len; /**< length of CSI data */ 452 } wifi_csi_info_t; 453 454 /** 455 * @brief WiFi GPIO configuration for antenna selection 456 * 457 */ 458 typedef struct { 459 uint8_t gpio_select: 1, /**< Whether this GPIO is connected to external antenna switch */ 460 gpio_num: 7; /**< The GPIO number that connects to external antenna switch */ 461 } wifi_ant_gpio_t; 462 463 /** 464 * @brief WiFi GPIOs configuration for antenna selection 465 * 466 */ 467 typedef struct { 468 wifi_ant_gpio_t gpio_cfg[4]; /**< The configurations of GPIOs that connect to external antenna switch */ 469 } wifi_ant_gpio_config_t; 470 471 /** 472 * @brief WiFi antenna mode 473 * 474 */ 475 typedef enum { 476 WIFI_ANT_MODE_ANT0, /**< Enable WiFi antenna 0 only */ 477 WIFI_ANT_MODE_ANT1, /**< Enable WiFi antenna 1 only */ 478 WIFI_ANT_MODE_AUTO, /**< Enable WiFi antenna 0 and 1, automatically select an antenna */ 479 WIFI_ANT_MODE_MAX, /**< Invalid WiFi enabled antenna */ 480 } wifi_ant_mode_t; 481 482 /** 483 * @brief WiFi antenna configuration 484 * 485 */ 486 typedef struct { 487 wifi_ant_mode_t rx_ant_mode; /**< WiFi antenna mode for receiving */ 488 wifi_ant_t rx_ant_default; /**< Default antenna mode for receiving, it's ignored if rx_ant_mode is not WIFI_ANT_MODE_AUTO */ 489 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 */ 490 uint8_t enabled_ant0: 4, /**< Index (in antenna GPIO configuration) of enabled WIFI_ANT_MODE_ANT0 */ 491 enabled_ant1: 4; /**< Index (in antenna GPIO configuration) of enabled WIFI_ANT_MODE_ANT1 */ 492 } wifi_ant_config_t; 493 494 /** 495 * @brief The Rx callback function of Action Tx operations 496 * 497 * @param hdr pointer to the IEEE 802.11 Header structure 498 * @param payload pointer to the Payload following 802.11 Header 499 * @param len length of the Payload 500 * @param channel channel number the frame is received on 501 * 502 */ 503 typedef int (* wifi_action_rx_cb_t)(uint8_t *hdr, uint8_t *payload, 504 size_t len, uint8_t channel); 505 506 /** 507 * @brief Action Frame Tx Request 508 * 509 * 510 */ 511 typedef struct { 512 wifi_interface_t ifx; /**< WiFi interface to send request to */ 513 uint8_t dest_mac[6]; /**< Destination MAC address */ 514 bool no_ack; /**< Indicates no ack required */ 515 wifi_action_rx_cb_t rx_cb; /**< Rx Callback to receive any response */ 516 uint32_t data_len; /**< Length of the appended Data */ 517 uint8_t data[0]; /**< Appended Data payload */ 518 } wifi_action_tx_req_t; 519 520 /** 521 * @brief FTM Initiator configuration 522 * 523 */ 524 typedef struct { 525 uint8_t resp_mac[6]; /**< MAC address of the FTM Responder */ 526 uint8_t channel; /**< Primary channel of the FTM Responder */ 527 uint8_t frm_count; /**< No. of FTM frames requested in terms of 4 or 8 bursts (allowed values - 0(No pref), 16, 24, 32, 64) */ 528 uint16_t burst_period; /**< Requested time period between consecutive FTM bursts in 100's of milliseconds (0 - No pref) */ 529 } wifi_ftm_initiator_cfg_t; 530 531 /** 532 * @brief WiFi PHY rate encodings 533 * 534 */ 535 typedef enum { 536 WIFI_PHY_RATE_1M_L = 0x00, /**< 1 Mbps with long preamble */ 537 WIFI_PHY_RATE_2M_L = 0x01, /**< 2 Mbps with long preamble */ 538 WIFI_PHY_RATE_5M_L = 0x02, /**< 5.5 Mbps with long preamble */ 539 WIFI_PHY_RATE_11M_L = 0x03, /**< 11 Mbps with long preamble */ 540 WIFI_PHY_RATE_2M_S = 0x05, /**< 2 Mbps with short preamble */ 541 WIFI_PHY_RATE_5M_S = 0x06, /**< 5.5 Mbps with short preamble */ 542 WIFI_PHY_RATE_11M_S = 0x07, /**< 11 Mbps with short preamble */ 543 WIFI_PHY_RATE_48M = 0x08, /**< 48 Mbps */ 544 WIFI_PHY_RATE_24M = 0x09, /**< 24 Mbps */ 545 WIFI_PHY_RATE_12M = 0x0A, /**< 12 Mbps */ 546 WIFI_PHY_RATE_6M = 0x0B, /**< 6 Mbps */ 547 WIFI_PHY_RATE_54M = 0x0C, /**< 54 Mbps */ 548 WIFI_PHY_RATE_36M = 0x0D, /**< 36 Mbps */ 549 WIFI_PHY_RATE_18M = 0x0E, /**< 18 Mbps */ 550 WIFI_PHY_RATE_9M = 0x0F, /**< 9 Mbps */ 551 WIFI_PHY_RATE_MCS0_LGI = 0x10, /**< MCS0 with long GI, 6.5 Mbps for 20MHz, 13.5 Mbps for 40MHz */ 552 WIFI_PHY_RATE_MCS1_LGI = 0x11, /**< MCS1 with long GI, 13 Mbps for 20MHz, 27 Mbps for 40MHz */ 553 WIFI_PHY_RATE_MCS2_LGI = 0x12, /**< MCS2 with long GI, 19.5 Mbps for 20MHz, 40.5 Mbps for 40MHz */ 554 WIFI_PHY_RATE_MCS3_LGI = 0x13, /**< MCS3 with long GI, 26 Mbps for 20MHz, 54 Mbps for 40MHz */ 555 WIFI_PHY_RATE_MCS4_LGI = 0x14, /**< MCS4 with long GI, 39 Mbps for 20MHz, 81 Mbps for 40MHz */ 556 WIFI_PHY_RATE_MCS5_LGI = 0x15, /**< MCS5 with long GI, 52 Mbps for 20MHz, 108 Mbps for 40MHz */ 557 WIFI_PHY_RATE_MCS6_LGI = 0x16, /**< MCS6 with long GI, 58.5 Mbps for 20MHz, 121.5 Mbps for 40MHz */ 558 WIFI_PHY_RATE_MCS7_LGI = 0x17, /**< MCS7 with long GI, 65 Mbps for 20MHz, 135 Mbps for 40MHz */ 559 WIFI_PHY_RATE_MCS0_SGI = 0x18, /**< MCS0 with short GI, 7.2 Mbps for 20MHz, 15 Mbps for 40MHz */ 560 WIFI_PHY_RATE_MCS1_SGI = 0x19, /**< MCS1 with short GI, 14.4 Mbps for 20MHz, 30 Mbps for 40MHz */ 561 WIFI_PHY_RATE_MCS2_SGI = 0x1A, /**< MCS2 with short GI, 21.7 Mbps for 20MHz, 45 Mbps for 40MHz */ 562 WIFI_PHY_RATE_MCS3_SGI = 0x1B, /**< MCS3 with short GI, 28.9 Mbps for 20MHz, 60 Mbps for 40MHz */ 563 WIFI_PHY_RATE_MCS4_SGI = 0x1C, /**< MCS4 with short GI, 43.3 Mbps for 20MHz, 90 Mbps for 40MHz */ 564 WIFI_PHY_RATE_MCS5_SGI = 0x1D, /**< MCS5 with short GI, 57.8 Mbps for 20MHz, 120 Mbps for 40MHz */ 565 WIFI_PHY_RATE_MCS6_SGI = 0x1E, /**< MCS6 with short GI, 65 Mbps for 20MHz, 135 Mbps for 40MHz */ 566 WIFI_PHY_RATE_MCS7_SGI = 0x1F, /**< MCS7 with short GI, 72.2 Mbps for 20MHz, 150 Mbps for 40MHz */ 567 WIFI_PHY_RATE_LORA_250K = 0x29, /**< 250 Kbps */ 568 WIFI_PHY_RATE_LORA_500K = 0x2A, /**< 500 Kbps */ 569 WIFI_PHY_RATE_MAX, 570 } wifi_phy_rate_t; 571 572 573 /** WiFi event declarations */ 574 typedef enum { 575 WIFI_EVENT_WIFI_READY = 0, /**< ESP32 WiFi ready */ 576 WIFI_EVENT_SCAN_DONE, /**< ESP32 finish scanning AP */ 577 WIFI_EVENT_STA_START, /**< ESP32 station start */ 578 WIFI_EVENT_STA_STOP, /**< ESP32 station stop */ 579 WIFI_EVENT_STA_CONNECTED, /**< ESP32 station connected to AP */ 580 WIFI_EVENT_STA_DISCONNECTED, /**< ESP32 station disconnected from AP */ 581 WIFI_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP32 station changed */ 582 583 WIFI_EVENT_STA_WPS_ER_SUCCESS, /**< ESP32 station wps succeeds in enrollee mode */ 584 WIFI_EVENT_STA_WPS_ER_FAILED, /**< ESP32 station wps fails in enrollee mode */ 585 WIFI_EVENT_STA_WPS_ER_TIMEOUT, /**< ESP32 station wps timeout in enrollee mode */ 586 WIFI_EVENT_STA_WPS_ER_PIN, /**< ESP32 station wps pin code in enrollee mode */ 587 WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP, /**< ESP32 station wps overlap in enrollee mode */ 588 589 WIFI_EVENT_AP_START, /**< ESP32 soft-AP start */ 590 WIFI_EVENT_AP_STOP, /**< ESP32 soft-AP stop */ 591 WIFI_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */ 592 WIFI_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */ 593 WIFI_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */ 594 595 WIFI_EVENT_FTM_REPORT, /**< Receive report of FTM procedure */ 596 597 /* Add next events after this only */ 598 WIFI_EVENT_STA_BSS_RSSI_LOW, /**< AP's RSSI crossed configured threshold */ 599 WIFI_EVENT_ACTION_TX_STATUS, /**< Status indication of Action Tx operation */ 600 WIFI_EVENT_ROC_DONE, /**< Remain-on-Channel operation complete */ 601 602 WIFI_EVENT_STA_BEACON_TIMEOUT, /**< ESP32 station beacon timeout */ 603 604 WIFI_EVENT_MAX, /**< Invalid WiFi event ID */ 605 } wifi_event_t; 606 607 /** @cond **/ 608 /** @brief WiFi event base declaration */ 609 ESP_EVENT_DECLARE_BASE(WIFI_EVENT); 610 /** @endcond **/ 611 612 /** Argument structure for WIFI_EVENT_SCAN_DONE event */ 613 typedef struct { 614 uint32_t status; /**< status of scanning APs: 0 — success, 1 - failure */ 615 uint8_t number; /**< number of scan results */ 616 uint8_t scan_id; /**< scan sequence number, used for block scan */ 617 } wifi_event_sta_scan_done_t; 618 619 /** Argument structure for WIFI_EVENT_STA_CONNECTED event */ 620 typedef struct { 621 uint8_t ssid[32]; /**< SSID of connected AP */ 622 uint8_t ssid_len; /**< SSID length of connected AP */ 623 uint8_t bssid[6]; /**< BSSID of connected AP*/ 624 uint8_t channel; /**< channel of connected AP*/ 625 wifi_auth_mode_t authmode;/**< authentication mode used by AP*/ 626 } wifi_event_sta_connected_t; 627 628 /** Argument structure for WIFI_EVENT_STA_DISCONNECTED event */ 629 typedef struct { 630 uint8_t ssid[32]; /**< SSID of disconnected AP */ 631 uint8_t ssid_len; /**< SSID length of disconnected AP */ 632 uint8_t bssid[6]; /**< BSSID of disconnected AP */ 633 uint8_t reason; /**< reason of disconnection */ 634 } wifi_event_sta_disconnected_t; 635 636 /** Argument structure for WIFI_EVENT_STA_AUTHMODE_CHANGE event */ 637 typedef struct { 638 wifi_auth_mode_t old_mode; /**< the old auth mode of AP */ 639 wifi_auth_mode_t new_mode; /**< the new auth mode of AP */ 640 } wifi_event_sta_authmode_change_t; 641 642 /** Argument structure for WIFI_EVENT_STA_WPS_ER_PIN event */ 643 typedef struct { 644 uint8_t pin_code[8]; /**< PIN code of station in enrollee mode */ 645 } wifi_event_sta_wps_er_pin_t; 646 647 /** Argument structure for WIFI_EVENT_STA_WPS_ER_FAILED event */ 648 typedef enum { 649 WPS_FAIL_REASON_NORMAL = 0, /**< ESP32 WPS normal fail reason */ 650 WPS_FAIL_REASON_RECV_M2D, /**< ESP32 WPS receive M2D frame */ 651 WPS_FAIL_REASON_MAX 652 } wifi_event_sta_wps_fail_reason_t; 653 654 #define MAX_SSID_LEN 32 655 #define MAX_PASSPHRASE_LEN 64 656 #define MAX_WPS_AP_CRED 3 657 658 /** Argument structure for WIFI_EVENT_STA_WPS_ER_SUCCESS event */ 659 typedef struct { 660 uint8_t ap_cred_cnt; /**< Number of AP credentials received */ 661 struct { 662 uint8_t ssid[MAX_SSID_LEN]; /**< SSID of AP */ 663 uint8_t passphrase[MAX_PASSPHRASE_LEN]; /**< Passphrase for the AP */ 664 } ap_cred[MAX_WPS_AP_CRED]; /**< All AP credentials received from WPS handshake */ 665 } wifi_event_sta_wps_er_success_t; 666 667 /** Argument structure for WIFI_EVENT_AP_STACONNECTED event */ 668 typedef struct { 669 uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */ 670 uint8_t aid; /**< the aid that ESP32 soft-AP gives to the station connected to */ 671 bool is_mesh_child; /**< flag to identify mesh child */ 672 } wifi_event_ap_staconnected_t; 673 674 /** Argument structure for WIFI_EVENT_AP_STADISCONNECTED event */ 675 typedef struct { 676 uint8_t mac[6]; /**< MAC address of the station disconnects to ESP32 soft-AP */ 677 uint8_t aid; /**< the aid that ESP32 soft-AP gave to the station disconnects to */ 678 bool is_mesh_child; /**< flag to identify mesh child */ 679 } wifi_event_ap_stadisconnected_t; 680 681 /** Argument structure for WIFI_EVENT_AP_PROBEREQRECVED event */ 682 typedef struct { 683 int rssi; /**< Received probe request signal strength */ 684 uint8_t mac[6]; /**< MAC address of the station which send probe request */ 685 } wifi_event_ap_probe_req_rx_t; 686 687 /** Argument structure for WIFI_EVENT_STA_BSS_RSSI_LOW event */ 688 typedef struct { 689 int32_t rssi; /**< RSSI value of bss */ 690 } wifi_event_bss_rssi_low_t; 691 692 /** 693 * @brief FTM operation status types 694 * 695 */ 696 typedef enum { 697 FTM_STATUS_SUCCESS = 0, /**< FTM exchange is successful */ 698 FTM_STATUS_UNSUPPORTED, /**< Peer does not support FTM */ 699 FTM_STATUS_CONF_REJECTED, /**< Peer rejected FTM configuration in FTM Request */ 700 FTM_STATUS_NO_RESPONSE, /**< Peer did not respond to FTM Requests */ 701 FTM_STATUS_FAIL, /**< Unknown error during FTM exchange */ 702 } wifi_ftm_status_t; 703 704 /** Argument structure for */ 705 typedef struct { 706 uint8_t dlog_token; /**< Dialog Token of the FTM frame */ 707 int8_t rssi; /**< RSSI of the FTM frame received */ 708 uint32_t rtt; /**< Round Trip Time in pSec with a peer */ 709 uint64_t t1; /**< Time of departure of FTM frame from FTM Responder in pSec */ 710 uint64_t t2; /**< Time of arrival of FTM frame at FTM Initiator in pSec */ 711 uint64_t t3; /**< Time of departure of ACK from FTM Initiator in pSec */ 712 uint64_t t4; /**< Time of arrival of ACK at FTM Responder in pSec */ 713 } wifi_ftm_report_entry_t; 714 715 /** Argument structure for WIFI_EVENT_FTM_REPORT event */ 716 typedef struct { 717 uint8_t peer_mac[6]; /**< MAC address of the FTM Peer */ 718 wifi_ftm_status_t status; /**< Status of the FTM operation */ 719 uint32_t rtt_raw; /**< Raw average Round-Trip-Time with peer in Nano-Seconds */ 720 uint32_t rtt_est; /**< Estimated Round-Trip-Time with peer in Nano-Seconds */ 721 uint32_t dist_est; /**< Estimated one-way distance in Centi-Meters */ 722 wifi_ftm_report_entry_t *ftm_report_data; /**< Pointer to FTM Report with multiple entries, should be freed after use */ 723 uint8_t ftm_report_num_entries; /**< Number of entries in the FTM Report data */ 724 } wifi_event_ftm_report_t; 725 726 #define WIFI_STATIS_BUFFER (1<<0) 727 #define WIFI_STATIS_RXTX (1<<1) 728 #define WIFI_STATIS_HW (1<<2) 729 #define WIFI_STATIS_DIAG (1<<3) 730 #define WIFI_STATIS_PS (1<<4) 731 #define WIFI_STATIS_ALL (-1) 732 733 /** Argument structure for WIFI_EVENT_ACTION_TX_STATUS event */ 734 typedef struct { 735 wifi_interface_t ifx; /**< WiFi interface to send request to */ 736 uint32_t context; /**< Context to identify the request */ 737 uint8_t da[6]; /**< Destination MAC address */ 738 uint8_t status; /**< Status of the operation */ 739 } wifi_event_action_tx_status_t; 740 741 /** Argument structure for WIFI_EVENT_ROC_DONE event */ 742 typedef struct { 743 uint32_t context; /**< Context to identify the request */ 744 } wifi_event_roc_done_t; 745 746 #ifdef __cplusplus 747 } 748 #endif 749 750 #endif /* __ESP_WIFI_TYPES_H__ */ 751