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