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