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