• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
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 WIFI_DRIVER_CLIENT_H
17 #define WIFI_DRIVER_CLIENT_H
18 
19 #include <stdint.h>
20 #include <stdbool.h>
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 
28 #undef LOG_TAG
29 #define LOG_TAG "HDF_WIFI_CORE"
30 #undef LOG_DOMAIN
31 #define LOG_DOMAIN 0xD002500
32 
33 #ifndef IFNAMSIZ
34 #define IFNAMSIZ 16
35 #endif
36 #define ETH_ADDR_LEN 6
37 #define WIFI_24G_CHANNEL_NUM 14
38 #define WIFI_MAX_CHANNEL_NUM 24
39 #define IEEE80211G_RATES_NUM 12
40 #define IEEE80211B_RATES_NUM 4
41 #define IEEE80211A_RATES_NUM 8
42 #define SIGNAL_LEVEL_CONFFICIENT 100
43 
44 #define WIFI_POWER_MODE_SLEEPING 0
45 #define WIFI_POWER_MODE_GENERAL 1
46 #define WIFI_POWER_MODE_THROUGH_WALL 2
47 #define WIFI_POWER_MODE_NUM 3
48 
49 #define MAX_SCAN_RES_NUM 200
50 #define MAX_SSID_LEN 32
51 
52 typedef enum {
53     CMD_CLOSE_GO_CAC,
54     CMD_SET_GO_CSA_CHANNEL,
55     CMD_SET_GO_RADAR_DETECT,
56     CMD_ID_MCC_STA_P2P_QUOTA_TIME,
57     CMD_ID_CTRL_ROAM_CHANNEL
58 } ProjectionScreenCmd;
59 
60 /* common related interface */
61 enum WifiDriverClientResultCode {
62     RET_CODE_SUCCESS = 0,
63     RET_CODE_FAILURE = -1,
64     RET_CODE_NOT_SUPPORT = -2,
65     RET_CODE_INVALID_PARAM = -3,
66     RET_CODE_MISUSE = -4, /* incorrectly API used */
67     RET_CODE_NOT_AVAILABLE = -5,
68     RET_CODE_NOMEM = -6,
69     RET_CODE_DEVICE_BUSY = -16,
70     RET_CODE_NETDOWN = -211,
71 };
72 
73 enum WifiIfType {
74     WIFI_IFTYPE_UNSPECIFIED,
75     WIFI_IFTYPE_ADHOC,
76     WIFI_IFTYPE_STATION,
77     WIFI_IFTYPE_AP,
78     WIFI_IFTYPE_AP_VLAN,
79     WIFI_IFTYPE_WDS,
80     WIFI_IFTYPE_MONITOR,
81     WIFI_IFTYPE_MESH_POINT,
82     WIFI_IFTYPE_P2P_CLIENT,
83     WIFI_IFTYPE_P2P_GO,
84     WIFI_IFTYPE_P2P_DEVICE,
85     WIFI_IFTYPE_MAX,
86 };
87 
88 typedef enum {
89     WIFI_EVENT_NEW_STA = 0,
90     WIFI_EVENT_DEL_STA,
91     WIFI_EVENT_RX_MGMT,
92     WIFI_EVENT_TX_STATUS,
93     WIFI_EVENT_SCAN_DONE,
94     WIFI_EVENT_SCAN_RESULT = 5,
95     WIFI_EVENT_CONNECT_RESULT,
96     WIFI_EVENT_DISCONNECT,
97     WIFI_EVENT_MESH_CLOSE,
98     WIFI_EVENT_NEW_PEER_CANDIDATE,
99     WIFI_EVENT_REMAIN_ON_CHANNEL = 10,
100     WIFI_EVENT_CANCEL_REMAIN_ON_CHANNEL,
101     WIFI_EVENT_CHANNEL_SWITCH,
102     WIFI_EVENT_EAPOL_RECV,
103     WIFI_EVENT_TIMEOUT_DISCONN,
104     WIFI_EVENT_RESET_DRIVER = 15,
105     WIFI_EVENT_SCAN_RESULTS,
106     WIFI_EVENT_SCAN_ABORTED,
107     WIFI_EVENT_BUTT
108 } WifiEventType;
109 
110 typedef enum {
111     CMD_HID2D_MODULE_INIT,
112     CMD_SET_BATTERY_LEVEL,
113     CMD_SET_SUPP_COEX_CHAN_LIST,
114     CMD_SET_CHAN_ADJUST
115 } Hid2dCmdType;
116 
117 typedef struct {
118     int32_t reassoc;
119     uint32_t ieLen;
120     uint8_t *ie;
121     uint8_t *macAddr;
122     uint8_t resv[2];
123 } WifiNewStaInfo;
124 
125 typedef struct {
126     uint8_t *buf;
127     uint32_t len;
128     int32_t sigMbm;
129     int32_t freq;
130 } WifiRxMgmt;
131 
132 typedef struct {
133     uint8_t *buf;
134     uint32_t len;
135     uint8_t ack;
136     uint8_t resv[3];
137 } WifiTxStatus;
138 
139 typedef struct {
140     uint32_t flags;
141     uint8_t *bssid;
142     uint16_t caps;
143     uint32_t freq;
144     uint16_t beaconInt;
145     int32_t qual;
146     int32_t level;
147     uint32_t age;
148     uint64_t tsf;
149     uint32_t ieLen;
150     uint32_t beaconIeLen;
151     uint8_t *variable;
152     uint8_t *ie;
153     uint8_t *beaconIe;
154 } WifiScanResult;
155 
156 typedef struct {
157     WifiScanResult scanResult[MAX_SCAN_RES_NUM];
158     uint32_t num;
159 } WifiScanResults;
160 
161 typedef struct {
162     uint8_t *reqIe;
163     uint32_t reqIeLen;
164     uint8_t *respIe;
165     uint32_t respIeLen;
166     uint8_t *bssid;
167     uint8_t rsv[2];
168     uint16_t status;
169     uint16_t freq;
170 } WifiConnectResult;
171 
172 typedef struct {
173     uint8_t *ie;
174     uint16_t reason;
175     uint8_t rsv[2];
176     uint32_t ieLen;
177 } WifiDisconnect;
178 
179 enum WifiClientType {
180     /* 1<<0 | 1<<1 | 1<<2 | 1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7 | 1<<10 | 1<<11 | 1<<13 */
181     WIFI_KERNEL_TO_WPA_CLIENT = 11519,
182     /* 1<<17 | 1<<16 | 1<<15 | 1<<5 | 1<<4 */
183     WIFI_KERNEL_TO_HAL_CLIENT = 229424,
184     WIFI_CLIENT_BUTT
185 };
186 
187 typedef int32_t (*OnReceiveFunc)(uint32_t event, void *data, const char *ifName);
188 typedef int32_t (*Hid2dCallback)(const uint8_t *recvMsg, uint32_t recvMsgLen);
189 
190 int32_t WifiRegisterEventCallback(OnReceiveFunc onRecFunc, uint32_t eventType, const char *ifName);
191 void WifiUnregisterEventCallback(OnReceiveFunc onRecFunc, uint32_t eventType, const char *ifName);
192 int32_t WifiRegisterHid2dCallback(Hid2dCallback func, const char *ifName);
193 void WifiUnregisterHid2dCallback(Hid2dCallback func, const char *ifName);
194 
195 /* hal related interface */
196 #define MAX_WLAN_DEVICE 3
197 #define MAX_CHANNEL_NUM 14
198 
199 enum Ieee80211Band {
200     IEEE80211_BAND_2GHZ,  /**< 2.4 GHz */
201     IEEE80211_BAND_5GHZ,  /**< 5 GHz */
202     IEEE80211_NUM_BANDS   /**< Reserved */
203 };
204 
205 struct NetworkInfo {
206     char name[IFNAMSIZ];
207     uint8_t supportMode[WIFI_IFTYPE_MAX];
208 };
209 
210 #define MAX_IFACE_NUM 20
211 
212 struct NetworkInfoResult {
213     uint32_t nums;
214     struct NetworkInfo infos[MAX_IFACE_NUM];
215 };
216 
217 struct FreqInfoResult {
218     int32_t band;
219     uint32_t nums;
220     uint32_t *freqs;
221     uint32_t *txPower;
222 };
223 
224 #define MAX_ASSOC_STA_NUM 8
225 
226 struct AssocStaInfo {
227     uint8_t mac[ETH_ADDR_LEN];  /**< MAC address of the STA */
228 };
229 
230 struct AssocStaInfoResult {
231     uint32_t num;
232     struct AssocStaInfo infos[MAX_ASSOC_STA_NUM];
233 };
234 
235 struct NetDeviceInfo {
236     uint32_t index;
237     char ifName[IFNAMSIZ];
238     uint8_t iftype;
239     uint8_t mac[ETH_ADDR_LEN];
240 };
241 
242 #define MAX_NETDEVICE_COUNT 20
243 
244 struct NetDeviceInfoResult {
245     struct NetDeviceInfo deviceInfos[MAX_NETDEVICE_COUNT];
246 };
247 
248 struct MeasParam {
249     int32_t channelId;
250     int32_t measTime;
251 };
252 
253 struct MeasResult {
254     int32_t channelId;
255     int32_t chload;
256     int32_t noise;
257 };
258 
259 typedef struct {
260     int32_t cmdId;
261     uint32_t bufLen;
262     int8_t buf[0];
263 } ProjectionScreenParam;
264 
265 typedef struct {
266     uint32_t rxRate;
267     uint32_t txRate;
268     uint32_t flags; /* bitfield of STA_DRV_DATA_* */
269     uint8_t rxVhtmcs;
270     uint8_t txVhtmcs;
271     uint8_t rxMcs;
272     uint8_t txMcs;
273     uint8_t rxVhtNss;
274     uint8_t txVhtNss;
275 } __attribute__ ((aligned(8))) StationInfo;
276 
277 #define BSS_STATUS_ASSOCIATED 1
278 typedef struct {
279     uint8_t associatedBssid[ETH_ADDR_LEN];
280     uint32_t associatedFreq;
281 } AssociatedInfo;
282 
283 struct SignalResult {
284     int32_t currentRssi;
285     int32_t associatedFreq;
286     int32_t txBitrate;
287     int32_t rxBitrate;
288     int32_t currentNoise;
289     int32_t currentSnr;
290     int32_t currentChload;
291     int32_t currentUlDelay;
292     int32_t currentTxBytes;
293     int32_t currentRxBytes;
294     int32_t currentTxFailed;
295     int32_t currentTxPackets;
296     int32_t currentRxPackets;
297 };
298 
299 typedef struct {
300     uint8_t ssid[MAX_SSID_LEN];
301     uint32_t ssidLen;
302 } WifiDriverScanSsid;
303 
304 typedef struct {
305     bool isHidden;
306     int32_t *freqs;
307     uint32_t freqsLen;
308     WifiDriverScanSsid ssid;
309 } WifiPnoNetwork;
310 
311 typedef struct {
312     int32_t min2gRssi;
313     int32_t min5gRssi;
314     int32_t scanIntervalMs;
315     int32_t scanIterations;
316     WifiPnoNetwork *pnoNetworks;
317     uint32_t pnoNetworksLen;
318 } WifiPnoSettings;
319 
320 int32_t WifiDriverClientInit(void);
321 void WifiDriverClientDeinit(void);
322 
323 int32_t GetUsableNetworkInfo(struct NetworkInfoResult *result);
324 int32_t IsSupportCombo(uint8_t *isSupportCombo);
325 int32_t GetComboInfo(uint64_t *comboInfo, uint32_t size);
326 int32_t SetMacAddr(const char *ifName, unsigned char *mac, uint8_t len);
327 int32_t GetDevMacAddr(const char *ifName, int32_t type, uint8_t *mac, uint8_t len);
328 int32_t GetValidFreqByBand(const char *ifName, int32_t band,
329     struct FreqInfoResult *result, uint32_t size);
330 int32_t SetTxPower(const char *ifName, int32_t power);
331 int32_t GetAssociatedStas(const char *ifName, struct AssocStaInfoResult *result);
332 int32_t WifiSetCountryCode(const char *ifName, const char *code, uint32_t len);
333 int32_t SetScanMacAddr(const char *ifName, uint8_t *scanMac, uint8_t len);
334 int32_t AcquireChipId(const char *ifName, uint8_t *chipId);
335 int32_t GetIfNamesByChipId(const uint8_t chipId, char **ifNames, uint32_t *num);
336 int32_t SetResetDriver(const uint8_t chipId, const char *ifName);
337 int32_t GetNetDeviceInfo(struct NetDeviceInfoResult *netDeviceInfoResult);
338 int32_t GetCurrentPowerMode(const char *ifName, uint8_t *mode);
339 int32_t SetPowerMode(const char *ifName, uint8_t mode);
340 int32_t StartChannelMeas(const char *ifName, const struct MeasParam *measParam);
341 int32_t GetChannelMeasResult(const char *ifName, struct MeasResult *measResult);
342 int32_t SetProjectionScreenParam(const char *ifName, const ProjectionScreenParam *param);
343 int32_t SendCmdIoctl(const char *ifName, int32_t cmdId, const int8_t *paramBuf, uint32_t paramBufLen);
344 int32_t GetStationInfo(const char *ifName, StationInfo *info, const uint8_t *mac, uint32_t macLen);
345 int32_t WifiStartPnoScan(const char *ifName, const WifiPnoSettings *pnoSettings);
346 int32_t WifiStopPnoScan(const char *ifName);
347 int32_t WifiGetSignalPollInfo(const char *ifName, struct SignalResult *signalResult);
348 
349 /* wpa related interface */
350 #define MAX_NR_CIPHER_SUITES 5
351 #define MAX_NR_AKM_SUITES 2
352 
353 typedef struct {
354     int32_t mode;
355     int32_t freq;
356     int32_t channel;
357 
358     /* for HT */
359     int32_t htEnabled;
360 
361     /*
362      * 0 = HT40 disabled, -1 = HT40 enabled,
363      * secondary channel below primary, 1 = HT40
364      * enabled, secondary channel above primary
365      */
366     int32_t secChannelOffset;
367 
368     /* for VHT */
369     int32_t vhtEnabled;
370 
371     /*
372      * valid for both HT and VHT, center_freq2 is non-zero
373      * only for bandwidth 80 and an 80+80 channel
374      */
375     int32_t centerFreq1;
376     int32_t centerFreq2;
377     int32_t bandwidth;
378     uint8_t band;
379 } WifiFreqParams;
380 
381 typedef struct {
382     uint32_t headLen;
383     uint32_t tailLen;
384     uint8_t *head;
385     uint8_t *tail;
386 } WifiBeaconData;
387 
388 typedef struct {
389     WifiFreqParams freqParams;
390     WifiBeaconData beaconData;
391     uint32_t ssidLen;
392     int32_t beaconInterval;
393     int32_t dtimPeriod;
394     uint8_t *ssid;
395     uint8_t hiddenSsid;
396     uint8_t authType;
397     uint32_t meshSsidLen;
398     uint8_t *meshSsid;
399 } WifiApSetting;
400 
401 typedef struct {
402     uint8_t *buf;
403     uint32_t len;
404 } WifiRxEapol;
405 
406 typedef struct {
407     uint32_t freq;
408     uint32_t dataLen;
409     uint8_t *data;
410     uint64_t *cookie;
411 } WifiMlmeData;
412 
413 typedef struct {
414     int32_t type;
415     uint32_t keyIdx;
416     uint32_t keyLen;
417     uint32_t seqLen;
418     uint32_t cipher;
419     uint8_t *addr;
420     uint8_t *key;
421     uint8_t *seq;
422     uint8_t def;
423     uint8_t defMgmt;
424     uint8_t defaultTypes;
425     uint8_t resv;
426 } WifiKeyExt;
427 
428 typedef struct {
429     uint8_t bssid[ETH_ADDR_LEN];
430     uint8_t iftype;
431     uint8_t resv;
432 } WifiSetMode;
433 
434 typedef struct {
435     uint16_t channel;
436     uint32_t freq;
437     uint32_t flags;
438 } WifiIeee80211Channel;
439 
440 typedef struct {
441     int32_t channelNum;          /**< Number of channels */
442     WifiIeee80211Channel iee80211Channel[WIFI_MAX_CHANNEL_NUM]; /**< WLAN channel structures */
443 }WlanBands;
444 
445 typedef struct {
446     int32_t channelNum;
447     uint16_t bitrate[12];
448     uint16_t htCapab;
449     uint8_t resv[2];
450     WlanBands bands[IEEE80211_NUM_BANDS];
451 } WifiHwFeatureData;
452 
453 typedef struct {
454     WifiDriverScanSsid *ssids;
455     int32_t *freqs;
456     uint8_t *extraIes;
457     uint8_t *bssid;
458     uint8_t numSsids;
459     uint8_t numFreqs;
460     uint8_t prefixSsidScanFlag;
461     uint8_t fastConnectFlag;
462     int32_t extraIesLen;
463 } WifiScan;
464 
465 typedef struct {
466     uint32_t wpaVersions;
467     uint32_t cipherGroup;
468     int32_t nCiphersPairwise;
469     uint32_t ciphersPairwise[MAX_NR_CIPHER_SUITES];
470     int32_t nAkmSuites;
471     uint32_t akmSuites[MAX_NR_AKM_SUITES];
472 } WifiCryptoSetting;
473 
474 typedef struct {
475     uint8_t *bssid;
476     uint8_t *ssid;
477     uint8_t *ie;
478     uint8_t *key;
479     uint8_t authType;
480     uint8_t privacy;
481     uint8_t keyLen;
482     uint8_t keyIdx;
483     uint8_t mfp;
484     uint8_t rsv[3];
485     uint32_t freq;
486     uint32_t ssidLen;
487     uint32_t ieLen;
488     WifiCryptoSetting *crypto;
489 } WifiAssociateParams;
490 
491 typedef enum {
492     WIFI_PHY_MODE_11N = 0,
493     WIFI_PHY_MODE_11G = 1,
494     WIFI_PHY_MODE_11B = 2,
495     WIFI_PHY_MODE_BUTT
496 } WifiPhyMode;
497 
498 typedef struct {
499     uint8_t status;
500     enum WifiIfType ifType;
501     WifiPhyMode mode;
502 } WifiSetNewDev;
503 
504 typedef struct {
505     uint8_t dst[ETH_ADDR_LEN];
506     uint8_t src[ETH_ADDR_LEN];
507     uint8_t bssid[ETH_ADDR_LEN];
508     uint8_t *data;
509     uint32_t dataLen;
510     uint32_t freq;
511     uint32_t wait;
512     int32_t noCck;
513 } WifiActionData;
514 
515 typedef struct {
516     uint32_t freq;
517     uint32_t duration;
518 } WifiOnChannel;
519 
520 
521 typedef struct {
522     uint8_t ifName[IFNAMSIZ];
523     uint8_t type;
524 } WifiIfAdd;
525 
526 typedef struct {
527     uint8_t ifName[IFNAMSIZ];
528 } WifiIfRemove;
529 
530 typedef struct {
531     uint32_t ieLen;
532     uint8_t appIeType;
533     uint8_t rsv[3];
534     uint8_t *ie;
535 } WifiAppIe;
536 
537 typedef struct {
538     uint64_t drvFlags;
539 } WifiGetDrvFlags;
540 
541 int32_t WifiEapolPacketSend(const char *ifName, const uint8_t *srcAddr, const uint8_t *dstAddr, uint8_t *buf,
542     uint32_t length);
543 int32_t WifiEapolPacketReceive(const char *ifName, WifiRxEapol *rxEapol);
544 int32_t WifiEapolEnable(const char *ifName);
545 int32_t WifiEapolDisable(const char *ifName);
546 int32_t WifiCmdSetAp(const char *ifName, WifiApSetting *apsettings);
547 int32_t WifiCmdChangeBeacon(const char *ifName, WifiApSetting *apsettings);
548 int32_t WifiCmdSendMlme(const char *ifName, WifiMlmeData *mlme);
549 int32_t WifiCmdDelKey(const char *ifName, WifiKeyExt *keyExt);
550 int32_t WifiCmdNewKey(const char *ifName, WifiKeyExt *keyExt);
551 int32_t WifiCmdSetKey(const char *ifName, WifiKeyExt *keyExt);
552 int32_t WifiCmdSetMode(const char *ifName, WifiSetMode *setMode);
553 int32_t WifiCmdGetOwnMac(const char *ifName, char *buf, uint32_t len);
554 int32_t WifiCmdGetHwFeature(const char *ifName, WifiHwFeatureData *hwFeatureData);
555 int32_t WifiCmdScan(const char *ifName, WifiScan *scan);
556 int32_t WifiCmdDisconnet(const char *ifName, int32_t reasonCode);
557 int32_t WifiCmdAssoc(const char *ifName, WifiAssociateParams *assocParams);
558 int32_t WifiCmdSetNetdev(const char *ifName, WifiSetNewDev *info);
559 int32_t WifiCmdStaRemove(const char *ifName, const uint8_t *addr, uint32_t addrLen);
560 int32_t WifiCmdSendAction(const char *ifName, WifiActionData *actionData);
561 int32_t WifiCmdSetClient(uint32_t clientNum);
562 int32_t WifiCmdProbeReqReport(const char *ifName, const int32_t *report);
563 int32_t WifiCmdRemainOnChannel(const char *ifName, const WifiOnChannel *onChannel);
564 int32_t WifiCmdCancelRemainOnChannel(const char *ifName);
565 int32_t WifiCmdAddIf(const char *ifName, const WifiIfAdd *ifAdd);
566 int32_t WifiCmdRemoveIf(const char *ifName, const WifiIfRemove *ifRemove);
567 int32_t WifiCmdSetApWpsP2pIe(const char *ifName, const WifiAppIe *appIe);
568 int32_t WifiCmdGetDrvFlags(const char *ifName, WifiGetDrvFlags *params);
569 #ifdef __cplusplus
570 #if __cplusplus
571 }
572 #endif
573 #endif
574 
575 #endif /* end of wifi_driver_client.h */
576