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