1 /*
2  * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #pragma once
8 
9 #include <stdint.h>
10 #include <stdbool.h>
11 #include "esp_err.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 #define FLOW_ID_ALL                  (8)
18 #define BSS_MAX_COLOR                (63)
19 
20 /**
21   * @brief Access category
22   */
23 typedef enum {
24     ESP_WIFI_ACI_VO,    /**< voice traffic */
25     ESP_WIFI_ACI_VI,    /**< video traffic */
26     ESP_WIFI_ACI_BE,    /**< best effort traffic */
27     ESP_WIFI_ACI_BK,    /**< background traffic */
28     ESP_WIFI_ACI_MAX,   /**< the max value */
29 } esp_wifi_aci_t;
30 
31 /**
32   * @brief Channel state information(CSI) HE STBC CSI selection
33   */
34 enum {
35     ESP_CSI_ACQUIRE_STBC_HELTF1,            /**< HE STBC: select the first HE-LTF */
36     ESP_CSI_ACQUIRE_STBC_HELTF2,            /**< HE STBC: select the second HE-LTF */
37     ESP_CSI_ACQUIRE_STBC_SAMPLE_HELTFS,     /**< HE STBC: sample alternating scarier of HE-LTF1 and HE-LTF2 */
38 };
39 
40 /**
41   * @brief Channel state information(CSI) configuration type
42   */
43 typedef struct {
44     uint32_t enable : 1;                    /**< enable to acquire CSI */
45     uint32_t acquire_csi_legacy : 1;        /**< enable to acquire L-LTF when receiving a 11g PPDU */
46     uint32_t acquire_csi_ht20 : 1;          /**< enable to acquire HT-LTF when receiving an HT20 PPDU */
47     uint32_t acquire_csi_ht40 : 1;          /**< enable to acquire HT-LTF when receiving an HT40 PPDU */
48     uint32_t acquire_csi_su : 1;            /**< enable to acquire HE-LTF when receiving an HE20 SU PPDU */
49     uint32_t acquire_csi_mu : 1;            /**< enable to acquire HE-LTF when receiving an HE20 MU PPDU */
50     uint32_t acquire_csi_dcm : 1;           /**< enable to acquire HE-LTF when receiving an HE20 DCM applied PPDU */
51     uint32_t acquire_csi_beamformed : 1;    /**< enable to acquire HE-LTF when receiving an HE20 Beamformed applied PPDU */
52     uint32_t acquire_csi_he_stbc : 2;       /**< when receiving an STBC applied HE PPDU,
53                                                  0- acquire the complete HE-LTF1,
54                                                  1- acquire the complete HE-LTF2
55                                                  2- sample evenly among the HE-LTF1 and HE-LTF2 */
56     uint32_t val_scale_cfg : 2;             /**< value 0-3 */
57     uint32_t dump_ack_en : 1;               /**< enable to dump 802.11 ACK frame, default disabled */
58     uint32_t reserved : 19;                 /**< reserved */
59 } wifi_csi_acquire_config_t;
60 
61 /**
62   * @brief HE variant HT Control field including UPH(UL power headroom) and OM(Operation mode)
63   */
64 typedef struct {
65     uint32_t id : 2;                                   /**< HE Variant ID = 3 */
66     uint32_t uph_id : 4;                               /**< UPH control ID: 4 */
67     uint32_t ul_pw_headroom : 5;                       /**< the available UL power headroom for the current HE-MCS, unit: dB, value[0, 31] */
68     uint32_t min_tx_pw_flag : 1;                       /**< indicate that the min. transmit power for current HE-MCS is reached, set to 0 otherwise */
69     uint32_t rsvd : 2;                                 /**< reserved */
70     uint32_t ctrl_id : 4;                              /**< OM control ID: 1 */
71     uint32_t rx_nss : 3;                               /**< the max. number of spatial streams for the reception, only accept 0. */
72     uint32_t bw : 2;                                   /**< the operating channel width for both reception and transmission, only accept 0. */
73     uint32_t ul_mu_disable : 1;                        /**< disable UL MU operations */
74     uint32_t tx_nsts : 3;                              /**< the max. number of spatial streams for the transmission, only accept 0. */
75     uint32_t er_su_disable : 1;                        /**< disable the reception of 242-tone HE ER SU PPDU */
76     uint32_t dl_mu_mimo_resounding_recommendation : 1; /**< indicate the STA suggests the AP either resounding the channel or increase the channel sounding frequency with the STA */
77     uint32_t ul_mu_data_disable : 1;                   /**< disable UL MU data operations */
78     uint32_t padding : 2;                              /**< padding bits */
79 } esp_wifi_htc_omc_t;
80 
81 /**
82   * @brief TWT setup commands
83   */
84 typedef enum {
85     TWT_REQUEST,                   /**< request to join a TWT without providing a set of TWT parameters */
86     TWT_SUGGEST,                   /**< request to join a TWT and offer a set of preferred TWT parameters but might accept alternative TWT parameters */
87     TWT_DEMAND,                    /**< request to join a TWT and currently accept only the indicated TWT parameters */
88     TWT_GROUPING,                  /**< for S1G STA */
89     TWT_ACCEPT,                    /**< accept the TWT request with the TWT parameters, also used in unsolicited TWT response */
90     TWT_ALTERNATE,                 /**< indicate a counter-offer of TWT parameters without creation of a TWT agreement */
91     TWT_DICTATE,                   /**< indicate no TWT agreement is created, but one is likely to be accepted only if the requesting STA transmits a new TWT setup request with the indicated TWT parameters */
92     TWT_REJECT,                    /**< indicate that the negotiation has ended in failure to crate a new TWT agreement */
93 } wifi_twt_setup_cmds_t;
94 
95 /**
96   * @brief TWT setup config
97   */
98 typedef struct
99 {
100     wifi_twt_setup_cmds_t setup_cmd;    /**< Indicates the type of TWT command */
101     uint16_t trigger :1;                /**< 1: a trigger-enabled TWT, 0: a non-trigger-enabled TWT */
102     uint16_t flow_type :1;              /**< 0: an announced TWT, 1: an unannounced TWT */
103     uint16_t flow_id :3;                /**< When set up an individual TWT agreement, the flow id will be assigned by AP after a successful agreement setup.
104                                              flow_id could be specified to a value in the range of [0, 7], but it might be changed by AP in the response.
105                                              When change TWT parameters of the existing TWT agreement, flow_id should be an existing one. The value range is [0, 7]. */
106     uint16_t wake_invl_expn :5;         /**< TWT Wake Interval Exponent. The value range is [0, 31]. */
107     uint16_t wake_duration_unit :1;     /**< TWT Wake duration unit, 0: 256us 1: TU (TU = 1024us)*/
108     uint16_t reserved :5;               /**< bit: 11.15 reserved */
109     uint8_t min_wake_dura;              /**< Nominal Minimum Wake Duration, indicates the minimum amount of time, in unit of 256 us, that the TWT requesting STA expects that it needs to be awake. The value range is [1, 255]. */
110     uint16_t wake_invl_mant;            /**< TWT Wake Interval Mantissa. The value range is [1, 65535]. */
111     uint16_t twt_id;                    /**< TWT connection id, the value range is [0, 32767]. */
112     uint16_t timeout_time_ms;           /**< Timeout times of receiving setup action frame response, default 5s*/
113 } wifi_twt_setup_config_t;
114 
115 /**
116   * @brief HE SU GI and LTF types
117   */
118 typedef enum {
119     HE_SU_ERSU_1_LTF_0_8_US_GI,    /**< 1 LTF and 0.8 us GI */
120     HE_SU_ERSU_2_LTF_0_8_US_GI,    /**< 2 LTF and 0.8 us GI */
121     HE_SU_ERSU_2_LTF_1_6_US_GI,    /**< 2 LTF and 1.6 us GI */
122     HE_SU_ERSU_4_LTF_3_2_US_GI,    /**< 4 LTF and 3.2 us GI */
123 } he_su_gi_and_ltf_type_t;
124 
125 /**
126   * @brief Reception format
127   */
128 typedef enum {
129     RX_BB_FORMAT_11B      = 0,    /**< the reception frame is a 11b MPDU */
130     RX_BB_FORMAT_11G      = 1,    /**< the reception frame is a 11g MPDU */
131     RX_BB_FORMAT_HT       = 2,    /**< the reception frame is a HT MPDU */
132     RX_BB_FORMAT_VHT      = 3,    /**< the reception frame is a VHT MPDU */
133     RX_BB_FORMAT_HE_SU    = 4,    /**< the reception frame is a HE SU MPDU */
134     RX_BB_FORMAT_HE_MU    = 5,    /**< the reception frame is a HE MU MPDU */
135     RX_BB_FORMAT_HE_ERSU  = 6,    /**< the reception frame is a HE ER SU MPDU */
136     RX_BB_FORMAT_HE_TB    = 7,    /**< the reception frame is a HE TB MPDU */
137 } wifi_rx_bb_format_t;
138 
139 /**
140   * @brief RxControl Info
141   */
142 typedef struct {
143     signed rssi : 8;                              /**< the RSSI of the reception frame */
144     unsigned rate : 5;                            /**< if cur_bb_format is RX_BB_FORMAT_11B, it's the transmission rate. otherwise it's Rate field of L-SIG */
145     unsigned : 1;                                 /**< reserved */
146     unsigned : 2;                                 /**< reserved */
147     unsigned : 12;                                /**< reserved */
148     unsigned rxmatch0 : 1;                        /**< indicate whether the reception frame is from interface 0 */
149     unsigned rxmatch1 : 1;                        /**< indicate whether the reception frame is from interface 1 */
150     unsigned rxmatch2 : 1;                        /**< indicate whether the reception frame is from interface 2 */
151     unsigned rxmatch3 : 1;                        /**< indicate whether the reception frame is from interface 3 */
152     uint32_t he_siga1;                            /**< HE-SIGA1 or HT-SIG */
153     unsigned rxend_state : 8;                     /**< reception state, 0: successful, others: failure */
154     uint16_t he_siga2;                            /**< HE-SIGA2 */
155     unsigned : 7;                                 /**< reserved */
156     unsigned is_group : 1;                        /**< indicate whether the reception is a group addressed frame */
157     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 */
158     unsigned : 15;                                /**< reserved */
159     unsigned : 15;                                /**< reserved */
160     unsigned : 2;                                 /**< reserved */
161     signed noise_floor : 8;                       /**< the noise floor of the reception frame */
162     unsigned channel : 4;                         /**< the primary channel */
163     unsigned second : 4;                          /**< the second channel if in HT40 */
164     unsigned : 8;                                 /**< reserved */
165     unsigned : 8;                                 /**< reserved */
166     unsigned : 32;                                /**< reserved */
167     unsigned : 32;                                /**< reserved */
168     unsigned : 2;                                 /**< reserved */
169     unsigned : 4;                                 /**< reserved */
170     unsigned : 2;                                 /**< reserved */
171     unsigned rx_channel_estimate_len : 10;        /**< the length of the channel information */
172     unsigned rx_channel_estimate_info_vld : 1;    /**< indicate the channel information is valid */
173     unsigned : 1;                                 /**< reserved */
174     unsigned : 11;                                /**< reserved */
175     unsigned : 1;                                 /**< reserved */
176     unsigned : 24;                                /**< reserved */
177     unsigned cur_bb_format : 4;                   /**< the format of the reception frame */
178     unsigned cur_single_mpdu : 1;                 /**< indicate whether the reception MPDU is a S-MPDU */
179     unsigned : 3;                                 /**< reserved */
180     unsigned : 32;                                /**< reserved */
181     unsigned : 32;                                /**< reserved */
182     unsigned : 32;                                /**< reserved */
183     unsigned : 32;                                /**< reserved */
184     unsigned : 32;                                /**< reserved */
185     unsigned : 32;                                /**< reserved */
186     unsigned : 32;                                /**< reserved */
187     unsigned : 32;                                /**< reserved */
188     unsigned : 8;                                 /**< reserved */
189     unsigned he_sigb_len : 6;                     /**< the length of HE-SIGB */
190     unsigned : 2;                                 /**< reserved */
191     unsigned : 8;                                 /**< reserved */
192     unsigned : 8;                                 /**< reserved */
193     unsigned : 32;                                /**< reserved */
194     unsigned : 7;                                 /**< reserved */
195     unsigned : 1;                                 /**< reserved */
196     unsigned : 8;                                 /**< reserved */
197     unsigned : 16;                                /**< reserved */
198     unsigned sig_len : 14;                        /**< the length of the reception MPDU */
199     unsigned : 2;                                 /**< reserved */
200     unsigned dump_len : 14;                       /**< the length of the reception MPDU excluding the FCS */
201     unsigned : 2;                                 /**< reserved */
202     unsigned rx_state : 8;                        /**< reception state, 0: successful, others: failure */
203     unsigned : 24;                                /**< reserved */
204 } __attribute__((packed)) esp_wifi_rxctrl_t;
205 
206 /** Argument structure for WIFI_EVENT_TWT_SET_UP event */
207 typedef struct {
208     wifi_twt_setup_config_t config;       /**< itwt setup config, this value is determined by the AP */
209     esp_err_t status;                     /**< itwt setup status, 1: indicate setup success, others : indicate setup fail */
210     uint8_t reason;                       /**< itwt setup frame tx fail reason */
211     uint64_t target_wake_time;            /**< TWT SP start time */
212 } wifi_event_sta_itwt_setup_t;
213 
214 /** Argument structure for WIFI_EVENT_TWT_TEARDOWN event */
215 typedef struct {
216     uint8_t flow_id;                     /**< flow id */
217 } wifi_event_sta_itwt_teardown_t;
218 
219 /**
220   * @brief iTWT probe status
221   */
222 typedef enum {
223     ITWT_PROBE_FAIL,               /**< station sends probe request fail */
224     ITWT_PROBE_SUCCESS,            /**< 1) station receives beacon from AP; 2) station receives probe response from AP */
225     ITWT_PROBE_TIMEOUT,            /**< 1) timeout of receiving ACK in response of previously probe request sending by station
226                                         2) timeout of receiving probe response in response of previously probe request sending by station */
227     ITWT_PROBE_STA_DISCONNECTED,   /**< station is not connected */
228 } wifi_itwt_probe_status_t;
229 
230 /** Argument structure for WIFI_EVENT_ITWT_SEND_PROBE event */
231 typedef struct {
232     wifi_itwt_probe_status_t status;     /**< probe status */
233     uint8_t reason;                      /**< failure reason */
234 } wifi_event_sta_itwt_probe_t;
235 
236 /** Argument structure for WIFI_EVENT_ITWT_SUSPEND event */
237 typedef struct {
238     esp_err_t status;                    /**< suspend status */
239     uint8_t flow_id_bitmap;              /**< bitmap of the suspended flow id */
240     uint32_t actual_suspend_time_ms[8];  /**< the actual suspend time for each flow id, unit: ms */
241 } wifi_event_sta_itwt_suspend_t;
242 
243 /**
244   * @brief TWT types
245   */
246 typedef enum {
247     TWT_TYPE_INDIVIDUAL,                 /**< individual twt */
248     TWT_TYPE_BROADCAST,                  /**< broadcast twt */
249     TWT_TYPE_MAX,                        /**< the max value */
250 } wifi_twt_type_t;
251 
252 /** Argument structure for twt configuration */
253 typedef struct {
254     bool post_wakeup_event;              /**< post twt wakeup event */
255     bool twt_enable_keep_alive;          /**< twt enable send qos null to keep alive */
256 } wifi_twt_config_t;
257 
258 /** Argument structure for WIFI_EVENT_TWT_WAKEUP event */
259 typedef struct {
260     wifi_twt_type_t twt_type;           /**< twt type */
261     uint8_t flow_id;                    /**< flow id */
262 } wifi_event_sta_twt_wakeup_t;
263 
264 #ifdef __cplusplus
265 }
266 #endif
267