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 reserved:28;    /**< bit: 4..31 reserved */
276 } wifi_sta_info_t;
277 
278 #define ESP_WIFI_MAX_CONN_NUM  (10)       /**< max number of stations which can connect to ESP32 soft-AP */
279 
280 /** @brief List of stations associated with the ESP32 Soft-AP */
281 typedef struct {
282     wifi_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM]; /**< station list */
283     int       num; /**< number of stations in the list (other entries are invalid) */
284 } wifi_sta_list_t;
285 
286 typedef enum {
287     WIFI_STORAGE_FLASH,  /**< all configuration will store in both memory and flash */
288     WIFI_STORAGE_RAM,    /**< all configuration will only store in the memory */
289 } wifi_storage_t;
290 
291 /**
292   * @brief     Vendor Information Element type
293   *
294   * Determines the frame type that the IE will be associated with.
295   */
296 typedef enum {
297     WIFI_VND_IE_TYPE_BEACON,
298     WIFI_VND_IE_TYPE_PROBE_REQ,
299     WIFI_VND_IE_TYPE_PROBE_RESP,
300     WIFI_VND_IE_TYPE_ASSOC_REQ,
301     WIFI_VND_IE_TYPE_ASSOC_RESP,
302 } wifi_vendor_ie_type_t;
303 
304 /**
305   * @brief     Vendor Information Element index
306   *
307   * Each IE type can have up to two associated vendor ID elements.
308   */
309 typedef enum {
310     WIFI_VND_IE_ID_0,
311     WIFI_VND_IE_ID_1,
312 } wifi_vendor_ie_id_t;
313 
314 #define WIFI_VENDOR_IE_ELEMENT_ID 0xDD
315 
316 /**
317  * @brief Vendor Information Element header
318  *
319  * The first bytes of the Information Element will match this header. Payload follows.
320  */
321 typedef struct {
322     uint8_t element_id;      /**< Should be set to WIFI_VENDOR_IE_ELEMENT_ID (0xDD) */
323     uint8_t length;          /**< Length of all bytes in the element data following this field. Minimum 4. */
324     uint8_t vendor_oui[3];   /**< Vendor identifier (OUI). */
325     uint8_t vendor_oui_type; /**< Vendor-specific OUI type. */
326     uint8_t payload[0];      /**< Payload. Length is equal to value in 'length' field, minus 4. */
327 } vendor_ie_data_t;
328 
329 /** @brief Received packet radio metadata header, this is the common header at the beginning of all promiscuous mode RX callback buffers */
330 typedef struct {
331     signed rssi:8;                /**< Received Signal Strength Indicator(RSSI) of packet. unit: dBm */
332     unsigned rate:5;              /**< PHY rate encoding of the packet. Only valid for non HT(11bg) packet */
333     unsigned :1;                  /**< reserved */
334     unsigned sig_mode:2;          /**< 0: non HT(11bg) packet; 1: HT(11n) packet; 3: VHT(11ac) packet */
335     unsigned :16;                 /**< reserved */
336     unsigned mcs:7;               /**< Modulation Coding Scheme. If is HT(11n) packet, shows the modulation, range from 0 to 76(MSC0 ~ MCS76) */
337     unsigned cwb:1;               /**< Channel Bandwidth of the packet. 0: 20MHz; 1: 40MHz */
338     unsigned :16;                 /**< reserved */
339     unsigned smoothing:1;         /**< reserved */
340     unsigned not_sounding:1;      /**< reserved */
341     unsigned :1;                  /**< reserved */
342     unsigned aggregation:1;       /**< Aggregation. 0: MPDU packet; 1: AMPDU packet */
343     unsigned stbc:2;              /**< Space Time Block Code(STBC). 0: non STBC packet; 1: STBC packet */
344     unsigned fec_coding:1;        /**< Flag is set for 11n packets which are LDPC */
345     unsigned sgi:1;               /**< Short Guide Interval(SGI). 0: Long GI; 1: Short GI */
346 #if CONFIG_IDF_TARGET_ESP32
347     signed noise_floor:8;         /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/
348 #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
349     unsigned :8;                  /**< reserved */
350 #endif
351     unsigned ampdu_cnt:8;         /**< ampdu cnt */
352     unsigned channel:4;           /**< primary channel on which this packet is received */
353     unsigned secondary_channel:4; /**< secondary channel on which this packet is received. 0: none; 1: above; 2: below */
354     unsigned :8;                  /**< reserved */
355     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 */
356     unsigned :32;                 /**< reserved */
357 #if CONFIG_IDF_TARGET_ESP32S2
358     unsigned :32;                 /**< reserved */
359 #elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
360     signed noise_floor:8;         /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/
361     unsigned :24;                 /**< reserved */
362     unsigned :32;                 /**< reserved */
363 #endif
364     unsigned :31;                 /**< reserved */
365     unsigned ant:1;               /**< antenna number from which this packet is received. 0: WiFi antenna 0; 1: WiFi antenna 1 */
366 #if CONFIG_IDF_TARGET_ESP32S2
367     signed noise_floor:8;         /**< noise floor of Radio Frequency Module(RF). unit: 0.25dBm*/
368     unsigned :24;                 /**< reserved */
369 #elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
370     unsigned :32;                 /**< reserved */
371     unsigned :32;                 /**< reserved */
372     unsigned :32;                 /**< reserved */
373 #endif
374     unsigned sig_len:12;          /**< length of packet including Frame Check Sequence(FCS) */
375     unsigned :12;                 /**< reserved */
376     unsigned rx_state:8;          /**< state of the packet. 0: no error; others: error numbers which are not public */
377 } wifi_pkt_rx_ctrl_t;
378 
379 /** @brief Payload passed to 'buf' parameter of promiscuous mode RX callback.
380  */
381 typedef struct {
382     wifi_pkt_rx_ctrl_t rx_ctrl; /**< metadata header */
383     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. */
384 } wifi_promiscuous_pkt_t;
385 
386 /**
387   * @brief Promiscuous frame type
388   *
389   * Passed to promiscuous mode RX callback to indicate the type of parameter in the buffer.
390   *
391   */
392 typedef enum {
393     WIFI_PKT_MGMT,  /**< Management frame, indicates 'buf' argument is wifi_promiscuous_pkt_t */
394     WIFI_PKT_CTRL,  /**< Control frame, indicates 'buf' argument is wifi_promiscuous_pkt_t */
395     WIFI_PKT_DATA,  /**< Data frame, indiciates 'buf' argument is wifi_promiscuous_pkt_t */
396     WIFI_PKT_MISC,  /**< Other type, such as MIMO etc. 'buf' argument is wifi_promiscuous_pkt_t but the payload is zero length. */
397 } wifi_promiscuous_pkt_type_t;
398 
399 
400 #define WIFI_PROMIS_FILTER_MASK_ALL         (0xFFFFFFFF)  /**< filter all packets */
401 #define WIFI_PROMIS_FILTER_MASK_MGMT        (1)           /**< filter the packets with type of WIFI_PKT_MGMT */
402 #define WIFI_PROMIS_FILTER_MASK_CTRL        (1<<1)        /**< filter the packets with type of WIFI_PKT_CTRL */
403 #define WIFI_PROMIS_FILTER_MASK_DATA        (1<<2)        /**< filter the packets with type of WIFI_PKT_DATA */
404 #define WIFI_PROMIS_FILTER_MASK_MISC        (1<<3)        /**< filter the packets with type of WIFI_PKT_MISC */
405 #define WIFI_PROMIS_FILTER_MASK_DATA_MPDU   (1<<4)        /**< filter the MPDU which is a kind of WIFI_PKT_DATA */
406 #define WIFI_PROMIS_FILTER_MASK_DATA_AMPDU  (1<<5)        /**< filter the AMPDU which is a kind of WIFI_PKT_DATA */
407 #define WIFI_PROMIS_FILTER_MASK_FCSFAIL     (1<<6)        /**< filter the FCS failed packets, do not open it in general */
408 
409 #define WIFI_PROMIS_CTRL_FILTER_MASK_ALL         (0xFF800000)  /**< filter all control packets */
410 #define WIFI_PROMIS_CTRL_FILTER_MASK_WRAPPER     (1<<23)       /**< filter the control packets with subtype of Control Wrapper */
411 #define WIFI_PROMIS_CTRL_FILTER_MASK_BAR         (1<<24)       /**< filter the control packets with subtype of Block Ack Request */
412 #define WIFI_PROMIS_CTRL_FILTER_MASK_BA          (1<<25)       /**< filter the control packets with subtype of Block Ack */
413 #define WIFI_PROMIS_CTRL_FILTER_MASK_PSPOLL      (1<<26)       /**< filter the control packets with subtype of PS-Poll */
414 #define WIFI_PROMIS_CTRL_FILTER_MASK_RTS         (1<<27)       /**< filter the control packets with subtype of RTS */
415 #define WIFI_PROMIS_CTRL_FILTER_MASK_CTS         (1<<28)       /**< filter the control packets with subtype of CTS */
416 #define WIFI_PROMIS_CTRL_FILTER_MASK_ACK         (1<<29)       /**< filter the control packets with subtype of ACK */
417 #define WIFI_PROMIS_CTRL_FILTER_MASK_CFEND       (1<<30)       /**< filter the control packets with subtype of CF-END */
418 #define WIFI_PROMIS_CTRL_FILTER_MASK_CFENDACK    (1<<31)       /**< filter the control packets with subtype of CF-END+CF-ACK */
419 
420 /** @brief Mask for filtering different packet types in promiscuous mode. */
421 typedef struct {
422     uint32_t filter_mask; /**< OR of one or more filter values WIFI_PROMIS_FILTER_* */
423 } wifi_promiscuous_filter_t;
424 
425 #define WIFI_EVENT_MASK_ALL                 (0xFFFFFFFF)  /**< mask all WiFi events */
426 #define WIFI_EVENT_MASK_NONE                (0)           /**< mask none of the WiFi events */
427 #define WIFI_EVENT_MASK_AP_PROBEREQRECVED   (BIT(0))      /**< mask SYSTEM_EVENT_AP_PROBEREQRECVED event */
428 
429 /**
430   * @brief Channel state information(CSI) configuration type
431   *
432   */
433 typedef struct {
434     bool lltf_en;           /**< enable to receive legacy long training field(lltf) data. Default enabled */
435     bool htltf_en;          /**< enable to receive HT long training field(htltf) data. Default enabled */
436     bool stbc_htltf2_en;    /**< enable to receive space time block code HT long training field(stbc-htltf2) data. Default enabled */
437     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 */
438     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 */
439     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 */
440     uint8_t shift;          /**< manually left shift bits of the scale of the CSI data. The range of the left shift bits is 0~15 */
441 } wifi_csi_config_t;
442 
443 /**
444   * @brief CSI data type
445   *
446   */
447 typedef struct {
448     wifi_pkt_rx_ctrl_t rx_ctrl;/**< received packet radio metadata header of the CSI data */
449     uint8_t mac[6];            /**< source MAC address of the CSI data */
450     bool first_word_invalid;   /**< first four bytes of the CSI data is invalid or not */
451     int8_t *buf;               /**< buffer of CSI data */
452     uint16_t len;              /**< length of CSI data */
453 } wifi_csi_info_t;
454 
455 /**
456   * @brief WiFi GPIO configuration for antenna selection
457   *
458   */
459 typedef struct {
460     uint8_t gpio_select: 1,           /**< Whether this GPIO is connected to external antenna switch */
461             gpio_num: 7;              /**< The GPIO number that connects to external antenna switch */
462 } wifi_ant_gpio_t;
463 
464 /**
465   * @brief WiFi GPIOs configuration for antenna selection
466   *
467   */
468 typedef struct {
469     wifi_ant_gpio_t  gpio_cfg[4];  /**< The configurations of GPIOs that connect to external antenna switch */
470 } wifi_ant_gpio_config_t;
471 
472 /**
473   * @brief WiFi antenna mode
474   *
475   */
476 typedef enum {
477     WIFI_ANT_MODE_ANT0,          /**< Enable WiFi antenna 0 only */
478     WIFI_ANT_MODE_ANT1,          /**< Enable WiFi antenna 1 only */
479     WIFI_ANT_MODE_AUTO,          /**< Enable WiFi antenna 0 and 1, automatically select an antenna */
480     WIFI_ANT_MODE_MAX,           /**< Invalid WiFi enabled antenna */
481 } wifi_ant_mode_t;
482 
483 /**
484   * @brief WiFi antenna configuration
485   *
486   */
487 typedef struct {
488     wifi_ant_mode_t rx_ant_mode;          /**< WiFi antenna mode for receiving */
489     wifi_ant_t      rx_ant_default;       /**< Default antenna mode for receiving, it's ignored if rx_ant_mode is not WIFI_ANT_MODE_AUTO */
490     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 */
491     uint8_t         enabled_ant0: 4,      /**< Index (in antenna GPIO configuration) of enabled WIFI_ANT_MODE_ANT0 */
492                     enabled_ant1: 4;      /**< Index (in antenna GPIO configuration) of enabled WIFI_ANT_MODE_ANT1 */
493 } wifi_ant_config_t;
494 
495 /**
496   * @brief     The Rx callback function of Action Tx operations
497   *
498   * @param     hdr pointer to the IEEE 802.11 Header structure
499   * @param     payload pointer to the Payload following 802.11 Header
500   * @param     len length of the Payload
501   * @param     channel channel number the frame is received on
502   *
503   */
504 typedef int (* wifi_action_rx_cb_t)(uint8_t *hdr, uint8_t *payload,
505                                     size_t len, uint8_t channel);
506 
507 /**
508  * @brief Action Frame Tx Request
509  *
510  *
511  */
512 typedef struct {
513     wifi_interface_t ifx;       /**< WiFi interface to send request to */
514     uint8_t dest_mac[6];        /**< Destination MAC address */
515     bool no_ack;                /**< Indicates no ack required */
516     wifi_action_rx_cb_t rx_cb;  /**< Rx Callback to receive any response */
517     uint32_t data_len;          /**< Length of the appended Data */
518     uint8_t data[0];            /**< Appended Data payload */
519 } wifi_action_tx_req_t;
520 
521 /**
522   * @brief FTM Initiator configuration
523   *
524   */
525 typedef struct {
526     uint8_t resp_mac[6];        /**< MAC address of the FTM Responder */
527     uint8_t channel;            /**< Primary channel of the FTM Responder */
528     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) */
529     uint16_t burst_period;      /**< Requested time period between consecutive FTM bursts in 100's of milliseconds (0 - No pref) */
530 } wifi_ftm_initiator_cfg_t;
531 
532 /**
533   * @brief WiFi PHY rate encodings
534   *
535   */
536 typedef enum {
537     WIFI_PHY_RATE_1M_L      = 0x00, /**< 1 Mbps with long preamble */
538     WIFI_PHY_RATE_2M_L      = 0x01, /**< 2 Mbps with long preamble */
539     WIFI_PHY_RATE_5M_L      = 0x02, /**< 5.5 Mbps with long preamble */
540     WIFI_PHY_RATE_11M_L     = 0x03, /**< 11 Mbps with long preamble */
541     WIFI_PHY_RATE_2M_S      = 0x05, /**< 2 Mbps with short preamble */
542     WIFI_PHY_RATE_5M_S      = 0x06, /**< 5.5 Mbps with short preamble */
543     WIFI_PHY_RATE_11M_S     = 0x07, /**< 11 Mbps with short preamble */
544     WIFI_PHY_RATE_48M       = 0x08, /**< 48 Mbps */
545     WIFI_PHY_RATE_24M       = 0x09, /**< 24 Mbps */
546     WIFI_PHY_RATE_12M       = 0x0A, /**< 12 Mbps */
547     WIFI_PHY_RATE_6M        = 0x0B, /**< 6 Mbps */
548     WIFI_PHY_RATE_54M       = 0x0C, /**< 54 Mbps */
549     WIFI_PHY_RATE_36M       = 0x0D, /**< 36 Mbps */
550     WIFI_PHY_RATE_18M       = 0x0E, /**< 18 Mbps */
551     WIFI_PHY_RATE_9M        = 0x0F, /**< 9 Mbps */
552     WIFI_PHY_RATE_MCS0_LGI  = 0x10, /**< MCS0 with long GI, 6.5 Mbps for 20MHz, 13.5 Mbps for 40MHz */
553     WIFI_PHY_RATE_MCS1_LGI  = 0x11, /**< MCS1 with long GI, 13 Mbps for 20MHz, 27 Mbps for 40MHz */
554     WIFI_PHY_RATE_MCS2_LGI  = 0x12, /**< MCS2 with long GI, 19.5 Mbps for 20MHz, 40.5 Mbps for 40MHz */
555     WIFI_PHY_RATE_MCS3_LGI  = 0x13, /**< MCS3 with long GI, 26 Mbps for 20MHz, 54 Mbps for 40MHz */
556     WIFI_PHY_RATE_MCS4_LGI  = 0x14, /**< MCS4 with long GI, 39 Mbps for 20MHz, 81 Mbps for 40MHz */
557     WIFI_PHY_RATE_MCS5_LGI  = 0x15, /**< MCS5 with long GI, 52 Mbps for 20MHz, 108 Mbps for 40MHz */
558     WIFI_PHY_RATE_MCS6_LGI  = 0x16, /**< MCS6 with long GI, 58.5 Mbps for 20MHz, 121.5 Mbps for 40MHz */
559     WIFI_PHY_RATE_MCS7_LGI  = 0x17, /**< MCS7 with long GI, 65 Mbps for 20MHz, 135 Mbps for 40MHz */
560     WIFI_PHY_RATE_MCS0_SGI  = 0x18, /**< MCS0 with short GI, 7.2 Mbps for 20MHz, 15 Mbps for 40MHz */
561     WIFI_PHY_RATE_MCS1_SGI  = 0x19, /**< MCS1 with short GI, 14.4 Mbps for 20MHz, 30 Mbps for 40MHz */
562     WIFI_PHY_RATE_MCS2_SGI  = 0x1A, /**< MCS2 with short GI, 21.7 Mbps for 20MHz, 45 Mbps for 40MHz */
563     WIFI_PHY_RATE_MCS3_SGI  = 0x1B, /**< MCS3 with short GI, 28.9 Mbps for 20MHz, 60 Mbps for 40MHz */
564     WIFI_PHY_RATE_MCS4_SGI  = 0x1C, /**< MCS4 with short GI, 43.3 Mbps for 20MHz, 90 Mbps for 40MHz */
565     WIFI_PHY_RATE_MCS5_SGI  = 0x1D, /**< MCS5 with short GI, 57.8 Mbps for 20MHz, 120 Mbps for 40MHz */
566     WIFI_PHY_RATE_MCS6_SGI  = 0x1E, /**< MCS6 with short GI, 65 Mbps for 20MHz, 135 Mbps for 40MHz */
567     WIFI_PHY_RATE_MCS7_SGI  = 0x1F, /**< MCS7 with short GI, 72.2 Mbps for 20MHz, 150 Mbps for 40MHz */
568     WIFI_PHY_RATE_LORA_250K = 0x29, /**< 250 Kbps */
569     WIFI_PHY_RATE_LORA_500K = 0x2A, /**< 500 Kbps */
570     WIFI_PHY_RATE_MAX,
571 } wifi_phy_rate_t;
572 
573 
574 /** WiFi event declarations */
575 typedef enum {
576     WIFI_EVENT_WIFI_READY = 0,           /**< ESP32 WiFi ready */
577     WIFI_EVENT_SCAN_DONE,                /**< ESP32 finish scanning AP */
578     WIFI_EVENT_STA_START,                /**< ESP32 station start */
579     WIFI_EVENT_STA_STOP,                 /**< ESP32 station stop */
580     WIFI_EVENT_STA_CONNECTED,            /**< ESP32 station connected to AP */
581     WIFI_EVENT_STA_DISCONNECTED,         /**< ESP32 station disconnected from AP */
582     WIFI_EVENT_STA_AUTHMODE_CHANGE,      /**< the auth mode of AP connected by ESP32 station changed */
583 
584     WIFI_EVENT_STA_WPS_ER_SUCCESS,       /**< ESP32 station wps succeeds in enrollee mode */
585     WIFI_EVENT_STA_WPS_ER_FAILED,        /**< ESP32 station wps fails in enrollee mode */
586     WIFI_EVENT_STA_WPS_ER_TIMEOUT,       /**< ESP32 station wps timeout in enrollee mode */
587     WIFI_EVENT_STA_WPS_ER_PIN,           /**< ESP32 station wps pin code in enrollee mode */
588     WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP,   /**< ESP32 station wps overlap in enrollee mode */
589 
590     WIFI_EVENT_AP_START,                 /**< ESP32 soft-AP start */
591     WIFI_EVENT_AP_STOP,                  /**< ESP32 soft-AP stop */
592     WIFI_EVENT_AP_STACONNECTED,          /**< a station connected to ESP32 soft-AP */
593     WIFI_EVENT_AP_STADISCONNECTED,       /**< a station disconnected from ESP32 soft-AP */
594     WIFI_EVENT_AP_PROBEREQRECVED,        /**< Receive probe request packet in soft-AP interface */
595 
596     WIFI_EVENT_FTM_REPORT,               /**< Receive report of FTM procedure */
597 
598     /* Add next events after this only */
599     WIFI_EVENT_STA_BSS_RSSI_LOW,         /**< AP's RSSI crossed configured threshold */
600     WIFI_EVENT_ACTION_TX_STATUS,         /**< Status indication of Action Tx operation */
601     WIFI_EVENT_ROC_DONE,                 /**< Remain-on-Channel operation complete */
602 
603     WIFI_EVENT_STA_BEACON_TIMEOUT,       /**< ESP32 station beacon timeout */
604 
605     WIFI_EVENT_MAX,                      /**< Invalid WiFi event ID */
606 } wifi_event_t;
607 
608 /** @cond **/
609 /** @brief WiFi event base declaration */
610 ESP_EVENT_DECLARE_BASE(WIFI_EVENT);
611 /** @endcond **/
612 
613 /** Argument structure for WIFI_EVENT_SCAN_DONE event */
614 typedef struct {
615     uint32_t status;          /**< status of scanning APs: 0 — success, 1 - failure */
616     uint8_t  number;          /**< number of scan results */
617     uint8_t  scan_id;         /**< scan sequence number, used for block scan */
618 } wifi_event_sta_scan_done_t;
619 
620 /** Argument structure for WIFI_EVENT_STA_CONNECTED event */
621 typedef struct {
622     uint8_t ssid[32];         /**< SSID of connected AP */
623     uint8_t ssid_len;         /**< SSID length of connected AP */
624     uint8_t bssid[6];         /**< BSSID of connected AP*/
625     uint8_t channel;          /**< channel of connected AP*/
626     wifi_auth_mode_t authmode;/**< authentication mode used by AP*/
627 } wifi_event_sta_connected_t;
628 
629 /** Argument structure for WIFI_EVENT_STA_DISCONNECTED event */
630 typedef struct {
631     uint8_t ssid[32];         /**< SSID of disconnected AP */
632     uint8_t ssid_len;         /**< SSID length of disconnected AP */
633     uint8_t bssid[6];         /**< BSSID of disconnected AP */
634     uint8_t reason;           /**< reason of disconnection */
635 } wifi_event_sta_disconnected_t;
636 
637 /** Argument structure for WIFI_EVENT_STA_AUTHMODE_CHANGE event */
638 typedef struct {
639     wifi_auth_mode_t old_mode;         /**< the old auth mode of AP */
640     wifi_auth_mode_t new_mode;         /**< the new auth mode of AP */
641 } wifi_event_sta_authmode_change_t;
642 
643 /** Argument structure for WIFI_EVENT_STA_WPS_ER_PIN event */
644 typedef struct {
645     uint8_t pin_code[8];         /**< PIN code of station in enrollee mode */
646 } wifi_event_sta_wps_er_pin_t;
647 
648 /** Argument structure for WIFI_EVENT_STA_WPS_ER_FAILED event */
649 typedef enum {
650     WPS_FAIL_REASON_NORMAL = 0,     /**< ESP32 WPS normal fail reason */
651     WPS_FAIL_REASON_RECV_M2D,       /**< ESP32 WPS receive M2D frame */
652     WPS_FAIL_REASON_MAX
653 } wifi_event_sta_wps_fail_reason_t;
654 
655 #define MAX_SSID_LEN        32
656 #define MAX_PASSPHRASE_LEN  64
657 #define MAX_WPS_AP_CRED     3
658 
659 /** Argument structure for WIFI_EVENT_STA_WPS_ER_SUCCESS event */
660 typedef struct {
661     uint8_t ap_cred_cnt;                        /**< Number of AP credentials received */
662     struct {
663         uint8_t ssid[MAX_SSID_LEN];             /**< SSID of AP */
664         uint8_t passphrase[MAX_PASSPHRASE_LEN]; /**< Passphrase for the AP */
665     } ap_cred[MAX_WPS_AP_CRED];                 /**< All AP credentials received from WPS handshake */
666 } wifi_event_sta_wps_er_success_t;
667 
668 /** Argument structure for WIFI_EVENT_AP_STACONNECTED event */
669 typedef struct {
670     uint8_t mac[6];           /**< MAC address of the station connected to ESP32 soft-AP */
671     uint8_t aid;              /**< the aid that ESP32 soft-AP gives to the station connected to  */
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 } wifi_event_ap_stadisconnected_t;
679 
680 /** Argument structure for WIFI_EVENT_AP_PROBEREQRECVED event */
681 typedef struct {
682     int rssi;                 /**< Received probe request signal strength */
683     uint8_t mac[6];           /**< MAC address of the station which send probe request */
684 } wifi_event_ap_probe_req_rx_t;
685 
686 /** Argument structure for WIFI_EVENT_STA_BSS_RSSI_LOW event */
687 typedef struct {
688     int32_t rssi;                 /**< RSSI value of bss */
689 } wifi_event_bss_rssi_low_t;
690 
691 /**
692   * @brief FTM operation status types
693   *
694   */
695 typedef enum {
696     FTM_STATUS_SUCCESS = 0,     /**< FTM exchange is successful */
697     FTM_STATUS_UNSUPPORTED,     /**< Peer does not support FTM */
698     FTM_STATUS_CONF_REJECTED,   /**< Peer rejected FTM configuration in FTM Request */
699     FTM_STATUS_NO_RESPONSE,     /**< Peer did not respond to FTM Requests */
700     FTM_STATUS_FAIL,            /**< Unknown error during FTM exchange */
701 } wifi_ftm_status_t;
702 
703 /** Argument structure for */
704 typedef struct {
705     uint8_t dlog_token;     /**< Dialog Token of the FTM frame */
706     int8_t rssi;            /**< RSSI of the FTM frame received */
707     uint32_t rtt;           /**< Round Trip Time in pSec with a peer */
708     uint64_t t1;            /**< Time of departure of FTM frame from FTM Responder in pSec */
709     uint64_t t2;            /**< Time of arrival of FTM frame at FTM Initiator in pSec */
710     uint64_t t3;            /**< Time of departure of ACK from FTM Initiator in pSec */
711     uint64_t t4;            /**< Time of arrival of ACK at FTM Responder in pSec */
712 } wifi_ftm_report_entry_t;
713 
714 /** Argument structure for WIFI_EVENT_FTM_REPORT event */
715 typedef struct {
716     uint8_t peer_mac[6];                        /**< MAC address of the FTM Peer */
717     wifi_ftm_status_t status;                   /**< Status of the FTM operation */
718     uint32_t rtt_raw;                           /**< Raw average Round-Trip-Time with peer in Nano-Seconds */
719     uint32_t rtt_est;                           /**< Estimated Round-Trip-Time with peer in Nano-Seconds */
720     uint32_t dist_est;                          /**< Estimated one-way distance in Centi-Meters */
721     wifi_ftm_report_entry_t *ftm_report_data;   /**< Pointer to FTM Report with multiple entries, should be freed after use */
722     uint8_t ftm_report_num_entries;             /**< Number of entries in the FTM Report data */
723 } wifi_event_ftm_report_t;
724 
725 #define WIFI_STATIS_BUFFER    (1<<0)
726 #define WIFI_STATIS_RXTX      (1<<1)
727 #define WIFI_STATIS_HW        (1<<2)
728 #define WIFI_STATIS_DIAG      (1<<3)
729 #define WIFI_STATIS_PS        (1<<4)
730 #define WIFI_STATIS_ALL       (-1)
731 
732 /** Argument structure for WIFI_EVENT_ACTION_TX_STATUS event */
733 typedef struct {
734     wifi_interface_t ifx;     /**< WiFi interface to send request to */
735     uint32_t context;         /**< Context to identify the request */
736     uint8_t da[6];            /**< Destination MAC address */
737     uint8_t status;           /**< Status of the operation */
738 } wifi_event_action_tx_status_t;
739 
740 /** Argument structure for WIFI_EVENT_ROC_DONE event */
741 typedef struct {
742     uint32_t context;         /**< Context to identify the request */
743 } wifi_event_roc_done_t;
744 
745 #ifdef __cplusplus
746 }
747 #endif
748 
749 #endif /* __ESP_WIFI_TYPES_H__ */
750