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