1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 /**
10  * @addtogroup WLAN
11  * @{
12  *
13  * @brief Provides cross-OS migration, component adaptation, and modular assembly and compilation.
14  *
15  * Based on the unified APIs provided by the WLAN module, developers of the Hardware Driver Interface
16  * (HDI) are capable of creating, disabling, scanning for, and connecting to WLAN hotspots, managing WLAN chips,
17  * network devices, and power, and applying for, releasing, and moving network data buffers.
18  *
19  * @since 1.0
20  * @version 1.0
21  */
22 
23 /**
24  * @file hdf_wifi_event.h
25  *
26  * @brief Declares WLAN driver events.
27  *
28  * The functions in this file are used to report events such as scanning results, scanning completion, and station
29  * disconnection to the WPA interface.
30  *
31  * @since 1.0
32  * @version 1.0
33  */
34 
35 #ifndef HDF_WIFI_EVENT_H
36 #define HDF_WIFI_EVENT_H
37 
38 #include "hdf_wifi_cmd.h"
39 #include "wifi_mac80211_ops.h"
40 #include "net_device.h"
41 
42 #ifdef __cplusplus
43 #if __cplusplus
44 extern "C" {
45 #endif
46 #endif
47 
48 /**
49  * @brief Defines the rate information received or sent over WLAN.
50  *
51  * @since 1.0
52  * @version 1.0
53  */
54 struct RateInfo {
55     uint8_t    flags;   /**< Flag, used to indicate a specific rate transmission type of 802.11n */
56     uint8_t    mcs;     /**< Modulation and Coding Scheme (MCS) index of the HT/VHT/HE rate */
57     uint16_t   legacy;  /**< 100 kbit/s bit rate defined in 802.11a/b/g */
58     uint8_t    nss;     /**< Number of streams (for VHT and HE only) */
59     uint8_t    resv;    /**< Reserved */
60 };
61 
62 /**
63  * @brief Defines parameters related to the WLAN module that works in station mode.
64  *
65  * @since 1.0
66  * @version 1.0
67  */
68 struct StaBssParameters {
69     uint8_t  flags;           /**< Flag, used to indicate a specific rate transmission type of 802.11n */
70     uint8_t  dtimPeriod;      /**< Delivery Traffic Indication Message (DTIM) period of BSS */
71     uint16_t beaconInterval;  /**< Beacon interval */
72 };
73 
74 /**
75  * @brief Defines the update of the <b>Sta</b> flag.
76  *
77  * @since 1.0
78  * @version 1.0
79  */
80 struct StaFlagUpdate {
81     uint32_t mask;  /**< Flag mask */
82     uint32_t set;   /**< Flag value */
83 };
84 
85 /**
86  * @brief Defines station information.
87  *
88  * @since 1.0
89  * @version 1.0
90  */
91 struct StationInfo {
92     uint32_t                          filled;           /**< Flag values of relevant structures */
93     uint32_t                          connectedTime;    /**< Duration (in seconds) since the last station connection */
94     uint32_t                          inactiveTime;     /**< Duration (in milliseconds) since the last station
95                                                          * activity
96                                                          */
97     uint16_t                          llid;             /**< Local mesh ID */
98     uint16_t                          plid;             /**< Peer mesh ID */
99 
100     uint64_t                          rxBytes;          /**< Received bytes */
101     uint64_t                          txBytes;          /**< Transmitted bytes */
102     struct RateInfo                   txRate;           /**< Transmission rate */
103     struct RateInfo                   rxRate;           /**< Receive rate */
104 
105     uint32_t                          rxPackets;        /**< Received data packets */
106     uint32_t                          txPackets;        /**< Transmitted data packets */
107     uint32_t                          txPetries;        /**< Number of retransmissions */
108     uint32_t                          txFailed;         /**< Number of failed transmissions */
109 
110     uint32_t                          rxDroppedMisc;    /**< Number of receive failures */
111     int32_t                           generation;       /**< Generation number */
112     struct StaBssParameters           bssParam;         /**< Current BSS parameters */
113     struct StaFlagUpdate              staFlags;         /**< Station flag masks and values */
114 
115     int64_t                           offset;           /**< Time offset of station */
116     const uint8_t                    *assocReqIes;      /**< Information Elements (IEs) in Association Request */
117     uint32_t                          assocReqIesLen;   /**< IE length in Association Request */
118     uint32_t                          beaconLossCount;  /**< Number of beacon loss events triggered */
119 
120     uint8_t                           plinkState;       /**< Mesh peer state */
121     int8_t                            signal;           /**< Signal strength */
122     int8_t                            signalAvg;        /**< Average signal strength */
123     uint8_t                           resv1;            /**< Reserved */
124 };
125 
126 /**
127  * @brief Defines authentication information.
128  *
129  * @since 1.0
130  * @version 1.0
131  */
132 struct Auth {
133     uint16_t authAlg;          /**< Authentication algorithm */
134     uint16_t authTransaction;  /**< Authentication transaction */
135     uint16_t statusCode;       /**< Authentication status code */
136     uint8_t variable[0];       /**< Algorithm challenge information stored in a flexible array */
137 };
138 
139 /**
140  * @brief Defines deauthentication information.
141  *
142  * @since 1.0
143  * @version 1.0
144  */
145 struct Deauth {
146     uint16_t reasonCode;  /**< Deauthentication cause code */
147 };
148 
149 /**
150  * @brief Defines station association request.
151  *
152  * @since 1.0
153  * @version 1.0
154  */
155 struct AssocReq {
156     uint16_t capabInfo;       /**< WLAN capability information */
157     uint16_t listenInterval;  /**< Scan interval */
158     uint8_t variable[0];      /**< SSID and rate information stored in a flexible array */
159 };
160 
161 /**
162  * @brief Defines station association response.
163  *
164  * @since 1.0
165  * @version 1.0
166  */
167 struct AssocResp {
168     uint16_t capabInfo;   /**< WLAN capability information */
169     uint16_t statusCode;  /**< Status code */
170     uint16_t aid;         /**< Authentication ID */
171     uint8_t variable[0];  /**< Rate information stored in a flexible array */
172 };
173 
174 /**
175  * @brief Defines station reassociation request.
176  *
177  * @since 1.0
178  * @version 1.0
179  */
180 struct ReassocReq {
181     uint16_t capabInfo;       /**< WLAN capability information */
182     uint16_t listenInterval;  /**< Scan interval */
183     uint8_t currentAp[6];     /**< Current AP */
184     uint8_t variable[0];      /**< SSID and rate information stored in a flexible array */
185 };
186 
187 /**
188  * @brief Defines station reassociation response.
189  *
190  * @since 1.0
191  * @version 1.0
192  */
193 struct ReassocResp {
194     uint16_t capabInfo;   /**< WLAN capability information */
195     uint16_t statusCode;  /**< Status code */
196     uint16_t aid;         /**< Authentication ID */
197     uint8_t variable[0];  /**< Rate information stored in a flexible array */
198 };
199 
200 /**
201  * @brief Defines station disconnection.
202  *
203  * @since 1.0
204  * @version 1.0
205  */
206 struct Disassoc {
207     uint16_t reasonCode;  /**< Cause code */
208 };
209 
210 /**
211  * @brief Defines the update of the <b>Sta</b> flag.
212  *
213  * @since 1.0
214  * @version 1.0
215  */
216 struct Beacon {
217     uint64_t timestamp;   /**< Timestamp */
218     uint16_t beaconInt;   /**< Beacon interval */
219     uint16_t capabInfo;   /**< WLAN capability information */
220     uint8_t variable[0];  /**< SSID and rate information */
221 };
222 
223 /**
224  * @brief Defines scanning response.
225  *
226  * @since 1.0
227  * @version 1.0
228  */
229 struct ProbeResp {
230     uint64_t timestamp;   /**< Timestamp */
231     uint16_t beaconInt;   /**< Beacon interval */
232     uint16_t capabInfo;   /**< WLAN capability information */
233     uint8_t variable[0];  /**< SSID and rate information */
234 };
235 
236 /**
237  * @brief Defines management frame information.
238  *
239  * @since 1.0
240  * @version 1.0
241  */
242 struct Ieee80211Mgmt {
243     uint16_t frameControl;               /**< Frame control field */
244     uint16_t duration;                   /**< Duration */
245     uint8_t dstAddr[6];                  /**< Destination MAC address */
246     uint8_t srcAddr[6];                  /**< Source MAC address */
247     uint8_t bssid[6];                    /**< BSS ID */
248     uint16_t seqCtrl;                    /**< Sequence control */
249     union {
250         struct Auth auth;                /**< Authentication Information */
251         struct Deauth deauth;            /**< Deauthentication Information */
252         struct AssocReq assocReq;        /**< Association request */
253         struct AssocResp assocResp;      /**< Association response */
254         struct ReassocReq reassocReq;    /**< Re-authentication */
255         struct ReassocResp reassocResp;  /**< Re-authentication response */
256         struct Disassoc disassoc;        /**< Disconnected */
257         struct Beacon beacon;            /**< Beacon frame */
258         struct ProbeResp probeResp;      /**< Probe response frame */
259     } u;
260 };
261 
262 /**
263  * @brief Represents the scanned BSS information.
264  *
265  * @since 1.0
266  * @version 1.0
267  */
268 struct ScannedBssInfo {
269     int32_t                  signal;   /**< Signal strength */
270     int16_t                  freq;     /**< Center frequency of the channel where the BSS is located */
271     uint8_t                  array[2];  /**< Reserved */
272     uint32_t                 mgmtLen;  /**< Management frame length */
273     struct Ieee80211Mgmt    *mgmt;     /**< Start address of the management frame */
274 };
275 
276 /**
277  * @brief Defines association results.
278  *
279  * @since 1.0
280  * @version 1.0
281  */
282 struct ConnetResult {
283     uint8_t   bssid[ETH_ADDR_LEN];  /**< MAC address of the AP associated with the station */
284     uint16_t  statusCode;           /**< 16-bit status code defined in the IEEE protocol */
285     uint8_t  *rspIe;                /**< Association response IE */
286     uint8_t  *reqIe;                /**< Association request IE */
287     uint32_t  reqIeLen;             /**< Length of the association request IE */
288     uint32_t  rspIeLen;             /**< Length of the association response IE */
289     uint16_t  connectStatus;        /**< Connection status */
290     uint16_t  freq;                 /**< Frequency of the AP */
291 };
292 
293 /**
294  * @brief Enumerates MLME management statuses, indicating whether a device is successfully associated or
295  * fails to be associated.
296  *
297  * @since 1.0
298  * @version 1.0
299  */
300 enum WifiHmacMgmtStatus {
301     WIFI_HMAC_MGMT_SUCCESS = 0,     /**< Association succeeds */
302     WIFI_HMAC_MGMT_INVALID = 1,     /**< Association fails */
303     WIFI_HMAC_MGMT_TIMEOUT = 2,     /**< Association timeout */
304     WIFI_HMAC_MGMT_REFUSED = 3,     /**< Association refused */
305     WIFI_HMAC_MGMT_TOMANY_REQ = 4,  /**< Repeated association request */
306     WIFI_HMAC_MGMT_ALREADY_BSS = 5  /**< Associated with the BSS */
307 };
308 
309 /**
310  * @brief Reports a new STA event.
311  *
312  * @param netDev Indicates the pointer to the network device. This parameter cannot be null.
313  * @param macAddr Indicates the pointer to the MAC address of the station. This parameter cannot be null.
314  * @param addrLen Indicates the length of the MAC address of the station. The length is fixed to six bytes.
315  * @param info Indicates the pointer to the station information.
316  *
317  * @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
318  *
319  * @since 1.0
320  * @version 1.0
321  */
322 int32_t HdfWifiEventNewSta(const struct NetDevice *netDev, const uint8_t *macAddr, uint8_t addrLen,
323     const struct StationInfo *info);
324 
325 /**
326  * @brief Reports a station deletion event.
327  *
328  * @param netDev Indicates the pointer to the network device. This parameter cannot be null.
329  * @param macAddr Indicates the pointer to the MAC address of the station. This parameter cannot be null.
330  * @param addrLen Indicates the length of the MAC address of the station. The length is fixed to six bytes.
331  *
332  * @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
333  *
334  * @since 1.0
335  * @version 1.0
336  */
337 int32_t HdfWifiEventDelSta(struct NetDevice *netDev, const uint8_t *macAddr, uint8_t addrLen);
338 
339 /**
340  * @brief Reports a scanned BSS event.
341  *
342  * @param netDev Indicates the pointer to the network device. This parameter cannot be null.
343  * @param channel Indicates the pointer to the channel information. This parameter cannot be null.
344  * @param bssInfo Indicates the pointer to the BSS information. This parameter cannot be null.
345  *
346  * @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
347  *
348  * @since 1.0
349  * @version 1.0
350  */
351 int32_t HdfWifiEventInformBssFrame(const struct NetDevice *netDev, const struct WlanChannel *channel,
352     const struct ScannedBssInfo *bssInfo);
353 
354 /**
355  * @brief Reports a scanning completion event.
356  *
357  * @param netDev Indicates the pointer to the network device. This parameter cannot be null.
358  * @param status Indicates the scanning completion status. Value <b>0</b> indicates that the scanning is successful,
359  * and other values indicate that the scanning fails.
360  *
361  * @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
362  *
363  * @since 1.0
364  * @version 1.0
365  */
366 int32_t HdfWifiEventScanDone(const struct NetDevice *netDev, WifiScanStatus status);
367 
368 /**
369  * @brief Reports a connection result event.
370  *
371  * @param netDev Indicates the pointer to the network device. This parameter cannot be null.
372  * @param result Indicates the pointer to the connection result. This parameter cannot be null.
373  *
374  * @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
375  *
376  * @since 1.0
377  * @version 1.0
378  */
379 int32_t HdfWifiEventConnectResult(const struct NetDevice *netDev, const struct ConnetResult *result);
380 
381 /**
382  * @brief Reports a disconnection event.
383  *
384  * @param netDev Indicates the pointer to the network device. This parameter cannot be null.
385  * @param reason Indicates the reason for disconnection.
386  * @param ie Indicates the pointer to the deauth/disassoc frame IE.
387  * @param len Indicates the length of the deauth/disassoc IE.
388  *
389  * @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
390  *
391  * @since 1.0
392  * @version 1.0
393  */
394 int32_t HdfWifiEventDisconnected(const struct NetDevice *netDev, uint16_t reason, const uint8_t *ie, uint32_t len);
395 
396 /**
397  * @brief Reports a transmission management status event.
398  *
399  * @param netDev Indicates the pointer to the network device. This parameter cannot be null.
400  * @param buf Indicates the pointer to the transmission management frame. This parameter cannot be null.
401  * @param len Indicates the length of the transmission management frame.
402  * @param ack Indicates whether the transmission management frame is acknowledged.
403  *
404  * @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
405  *
406  * @since 1.0
407  * @version 1.0
408  */
409 int32_t HdfWifiEventMgmtTxStatus(const struct NetDevice *netDev, const uint8_t *buf, size_t len, uint8_t ack);
410 
411 /**
412  * @brief Reports a receive management status event.
413  *
414  * @param netDev Indicates the pointer to the network device. This parameter cannot be null.
415  * @param freq Indicates the frequency of receiving management frame.
416  * @param sigMbm Indicates the signal strength (in dBm).
417  * @param buf Indicates the pointer to the receive management frame. This parameter cannot be null.
418  * @param len Indicates the length of the receive management frame.
419  *
420  * @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
421  *
422  * @since 1.0
423  * @version 1.0
424  */
425 int32_t HdfWifiEventRxMgmt(const struct NetDevice *netDev, int32_t freq, int32_t sigMbm,
426     const uint8_t *buf, size_t len);
427 
428 /**
429  * @brief Reports a CSA channel switching event.
430  *
431  * @param netDev Indicates the pointer to the network device. This parameter cannot be null.
432  * @param freq Indicates the frequency of the channel.
433  *
434  * @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
435  *
436  * @since 1.0
437  * @version 1.0
438  */
439 int32_t HdfWifiEventCsaChannelSwitch(const struct NetDevice *netDev, int32_t freq);
440 
441 /**
442  * @brief Reports a timeout disconnection event.
443  *
444  * @param netDev Indicates the pointer to the network device. This parameter cannot be null.
445  *
446  * @return Returns <b>0</b> if the event is reported successfully; returns <b>-1</b> otherwise.
447  *
448  * @since 1.0
449  * @version 1.0
450  */
451 int32_t HdfWifiEventTimeoutDisconnected(const struct NetDevice *netDev);
452 
453 /**
454  * @brief Reports the event of receiving the EAPOL frame and notifies WPA to read the EAPOL frame.
455  *
456  * @param name Indicates the pointer to the network port name, for example, <b>wlan0</b>.
457  * @param context Indicates the pointer to the context. This parameter is reserved.
458  *
459  * @return Returns <b>0</b> if the operation is successful; returns <b>-1</b> otherwise.
460  *
461  * @since 1.0
462  * @version 1.0
463  */
464 void HdfWifiEventEapolRecv(const char *name, void *context);
465 
466 /**
467  * @brief Reports the WLAN driver reset result.
468  *
469  * @param chipId Indicates the chip ID. This parameter cannot be null.
470  * @param resetStatus Indicates the WLAN driver reset result.
471  *
472  * @since 1.0
473  * @version 1.0
474  */
475 int32_t HdfWifiEventResetResult(const uint8_t chipId, int32_t resetStatus, const char *ifName);
476 
477 int32_t HdfWifiEventRemainOnChannel(const struct NetDevice *netDev, uint32_t freq, uint32_t duration);
478 
479 int32_t HdfWifiEventCancelRemainOnChannel(const struct NetDevice *netDev, uint32_t freq);
480 
481 #ifdef __cplusplus
482 #if __cplusplus
483 }
484 #endif
485 #endif
486 
487 #endif /* HDF_WIFI_EVENT_H */
488 /** @} */
489