1 /* 2 * Copyright (c) 2024 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_HAL_H 17 #define WIFI_HAL_H 18 19 #include <cstdint> 20 #include <cstddef> 21 #include "v1_0/ichip_iface_callback.h" 22 #include "v1_0/chip_types.h" 23 24 #ifdef __cplusplus 25 extern "C" 26 { 27 #endif 28 29 #define IFNAMSIZ_WIFI 16 30 #define ETH_ADDR_LEN 6 31 #define BSS_STATUS_ASSOCIATED 1 32 33 typedef unsigned char macAddr[6]; 34 35 struct WifiInfo; 36 struct WifiInterfaceInfo; 37 typedef struct WifiInfo *wifiHandle; 38 typedef struct WifiInterfaceInfo *wifiInterfaceHandle; 39 40 typedef enum { 41 HAL_TYPE_STA = 0, 42 HAL_TYPE_AP = 1, 43 HAL_TYPE_P2P = 2, 44 HAL_TYPE_NAN = 3 45 } HalIfaceType; 46 47 typedef enum { 48 HAL_SUCCESS = 0, 49 HAL_NONE = 0, 50 HAL_UNKNOWN = -1, 51 HAL_UNINITIALIZED = -2, 52 HAL_NOT_SUPPORTED = -3, 53 HAL_NOT_AVAILABLE = -4, 54 HAL_INVALID_ARGS = -5, 55 HAL_INVALID_REQUEST_ID = -6, 56 HAL_TIMED_OUT = -7, 57 HAL_TOO_MANY_REQUESTS = -8, 58 HAL_OUT_OF_MEMORY = -9, 59 HAL_BUSY = -10 60 } WifiError; 61 62 enum Ieee80211Band { 63 IEEE80211_BAND_2GHZ, 64 IEEE80211_BAND_5GHZ, 65 IEEE80211_NUM_BANDS 66 }; 67 68 typedef struct { 69 uint8_t associatedBssid[ETH_ADDR_LEN]; 70 uint32_t associatedFreq; 71 } AssociatedInfo; 72 73 WifiError VendorHalInit(wifiHandle *handle); 74 WifiError WaitDriverStart(void); 75 76 typedef void (*VendorHalExitHandler) (wifiHandle handle); 77 void VendorHalExit(wifiHandle handle, VendorHalExitHandler handler); 78 void StartHalLoop(wifiHandle handle); 79 80 WifiError VendorHalGetIfaces(wifiHandle handle, int *numIfaces, wifiInterfaceHandle **ifaces); 81 WifiError VendorHalGetIfName(wifiInterfaceHandle iface, char *name, size_t size); 82 83 typedef struct { 84 void (*onVendorHalRestart)(const char* error); 85 } VendorHalRestartHandler; 86 87 WifiError VendorHalSetRestartHandler(wifiHandle handle, 88 VendorHalRestartHandler handler); 89 90 typedef struct { 91 void (*onScanEvent) (int event); 92 void (*onRssiReport) (int index, int c0Rssi, int c1Rssi); 93 } WifiCallbackHandler; 94 95 typedef struct { 96 WifiError (*vendorHalInit)(wifiHandle *); 97 WifiError (*waitDriverStart)(void); 98 void (*vendorHalExit)(wifiHandle, VendorHalExitHandler); 99 void (*startHalLoop)(wifiHandle); 100 uint32_t (*wifiGetSupportedFeatureSet)(const char *); 101 WifiError (*wifiGetChipFeatureSet)(wifiHandle handle, uint64_t *set); 102 WifiError (*vendorHalGetIfaces)(wifiHandle, int *, wifiInterfaceHandle **); 103 WifiError (*vendorHalGetIfName)(wifiInterfaceHandle, char *name, size_t size); 104 WifiError (*vendorHalGetChannelsInBand)(wifiInterfaceHandle, int, std::vector<uint32_t>&); 105 WifiError (*vendorHalCreateIface)(wifiHandle handle, const char* ifname, HalIfaceType ifaceType); 106 WifiError (*vendorHalDeleteIface)(wifiHandle handle, const char* ifname); 107 WifiError (*vendorHalSetRestartHandler)(wifiHandle handle, VendorHalRestartHandler handler); 108 uint32_t (*getChipCaps)(const char *); 109 WifiError (*vendorHalPreInit)(void); 110 WifiError (*triggerVendorHalRestart)(wifiHandle handle); 111 WifiError (*wifiSetCountryCode)(wifiInterfaceHandle handle, const char *); 112 WifiError (*getPowerMode)(const char *, int *); 113 WifiError (*setPowerMode)(const char *, int); 114 WifiError (*isSupportCoex)(bool&); 115 WifiError (*wifiStartScan)(wifiInterfaceHandle handle, 116 const OHOS::HDI::Wlan::Chip::V1_0::ScanParams& scanParam); 117 WifiError (*wifiStartPnoScan)(wifiInterfaceHandle handle, 118 const OHOS::HDI::Wlan::Chip::V1_0::PnoScanParams& pnoScanParam); 119 WifiError (*wifiStopPnoScan)(wifiInterfaceHandle handle); 120 WifiError (*getScanResults)(wifiInterfaceHandle handle, 121 std::vector<OHOS::HDI::Wlan::Chip::V1_0::ScanResultsInfo>& mscanResults); 122 WifiError (*enablePowerMode)(const char *, int); 123 WifiError (*getSignalPollInfo)(wifiInterfaceHandle handle, 124 OHOS::HDI::Wlan::Chip::V1_0::SignalPollResult& signalPollResult); 125 WifiError (*setDpiMarkRule)(int32_t, int32_t, int32_t); 126 WifiError (*registerIfaceCallBack)(const char *, WifiCallbackHandler); 127 WifiError (*setTxPower)(const char *, int); 128 } WifiHalFn; 129 130 WifiError InitWifiVendorHalFuncTable(WifiHalFn *fn); 131 typedef WifiError (*InitWifiVendorHalFuncTableT)(WifiHalFn *fn); 132 133 #ifdef __cplusplus 134 } 135 #endif 136 137 #endif