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 "v2_0/ichip_iface_callback.h" 22 #include "v2_0/chip_types.h" 23 24 #ifdef __cplusplus 25 extern "C" 26 { 27 #endif 28 29 #undef LOG_DOMAIN 30 #define LOG_DOMAIN 0xD001566 31 32 #define IFNAMSIZ_WIFI 16 33 #define ETH_ADDR_LEN 6 34 #define BSS_STATUS_ASSOCIATED 1 35 36 typedef unsigned char macAddr[6]; 37 38 struct WifiInfo; 39 struct WifiInterfaceInfo; 40 typedef struct WifiInfo *wifiHandle; 41 typedef struct WifiInterfaceInfo *wifiInterfaceHandle; 42 43 typedef enum { 44 HAL_TYPE_STA = 0, 45 HAL_TYPE_AP = 1, 46 HAL_TYPE_P2P = 2, 47 HAL_TYPE_NAN = 3 48 } HalIfaceType; 49 50 typedef enum { 51 HAL_SUCCESS = 0, 52 HAL_NONE = 0, 53 HAL_UNKNOWN = -1, 54 HAL_UNINITIALIZED = -2, 55 HAL_NOT_SUPPORTED = -3, 56 HAL_NOT_AVAILABLE = -4, 57 HAL_INVALID_ARGS = -5, 58 HAL_INVALID_REQUEST_ID = -6, 59 HAL_TIMED_OUT = -7, 60 HAL_TOO_MANY_REQUESTS = -8, 61 HAL_OUT_OF_MEMORY = -9, 62 HAL_BUSY = -10 63 } WifiError; 64 65 enum Ieee80211Band { 66 IEEE80211_BAND_2GHZ, 67 IEEE80211_BAND_5GHZ, 68 IEEE80211_NUM_BANDS 69 }; 70 71 enum ScanBandType { 72 SCAN_BAND_UNSPECIFIED = 0, /* not specified */ 73 SCAN_BAND_24_GHZ = 1, /* 2.4 GHz band */ 74 SCAN_BAND_5_GHZ = 2, /* 5 GHz band without DFS channels */ 75 SCAN_BAND_BOTH = 3, /* both bands without DFS channels */ 76 SCAN_BAND_5_GHZ_DFS_ONLY = 4, /* 5 GHz band with DFS channels */ 77 SCAN_BAND_5_GHZ_WITH_DFS = 6, /* 5 GHz band with DFS channels */ 78 SCAN_BAND_BOTH_WITH_DFS = 7, /* both bands with DFS channels */ 79 }; 80 81 typedef struct { 82 uint8_t associatedBssid[ETH_ADDR_LEN]; 83 uint32_t associatedFreq; 84 } AssociatedInfo; 85 86 WifiError VendorHalInit(wifiHandle *handle); 87 WifiError WaitDriverStart(void); 88 89 typedef void (*VendorHalExitHandler) (wifiHandle handle); 90 void VendorHalExit(wifiHandle handle, VendorHalExitHandler handler); 91 void StartHalLoop(wifiHandle handle); 92 93 WifiError VendorHalGetIfaces(wifiHandle handle, int *numIfaces, wifiInterfaceHandle **ifaces); 94 WifiError VendorHalGetIfName(wifiInterfaceHandle iface, char *name, size_t size); 95 96 typedef struct { 97 void (*onVendorHalRestart)(const char* error); 98 } VendorHalRestartHandler; 99 100 WifiError VendorHalSetRestartHandler(wifiHandle handle, 101 VendorHalRestartHandler handler); 102 103 typedef struct { 104 void (*onScanEvent) (int event); 105 void (*onRssiReport) (int index, int c0Rssi, int c1Rssi); 106 void (*onWifiNetlinkMessage) (uint32_t type, const std::vector<uint8_t>& recvMsg); 107 } WifiCallbackHandler; 108 109 typedef struct { 110 void (*onWifiNetlinkMessage) (uint32_t type, const std::vector<uint8_t>& recvMsg); 111 } WifiExtCallbackHandler; 112 113 typedef struct { 114 WifiError (*vendorHalInit)(wifiHandle *); 115 WifiError (*waitDriverStart)(void); 116 void (*vendorHalExit)(wifiHandle, VendorHalExitHandler); 117 void (*startHalLoop)(wifiHandle); 118 uint32_t (*wifiGetSupportedFeatureSet)(const char *); 119 WifiError (*wifiGetChipFeatureSet)(wifiHandle handle, uint64_t *set); 120 WifiError (*vendorHalGetIfaces)(wifiHandle, int *, wifiInterfaceHandle **); 121 WifiError (*vendorHalGetIfName)(wifiInterfaceHandle, char *name, size_t size); 122 WifiError (*vendorHalGetChannelsInBand)(wifiInterfaceHandle, int, std::vector<uint32_t>&); 123 WifiError (*vendorHalCreateIface)(wifiHandle handle, const char* ifname, HalIfaceType ifaceType); 124 WifiError (*vendorHalDeleteIface)(wifiHandle handle, const char* ifname); 125 WifiError (*vendorHalSetRestartHandler)(wifiHandle handle, VendorHalRestartHandler handler); 126 uint32_t (*getChipCaps)(const char *); 127 WifiError (*vendorHalPreInit)(void); 128 WifiError (*triggerVendorHalRestart)(wifiHandle handle); 129 WifiError (*wifiSetCountryCode)(wifiInterfaceHandle handle, const char *); 130 WifiError (*getPowerMode)(const char *, int *); 131 WifiError (*setPowerMode)(const char *, int); 132 WifiError (*isSupportCoex)(bool&); 133 WifiError (*wifiStartScan)(wifiInterfaceHandle handle, 134 const OHOS::HDI::Wlan::Chip::V2_0::ScanParams& scanParam); 135 WifiError (*wifiStartPnoScan)(wifiInterfaceHandle handle, 136 const OHOS::HDI::Wlan::Chip::V2_0::PnoScanParams& pnoScanParam); 137 WifiError (*wifiStopPnoScan)(wifiInterfaceHandle handle); 138 WifiError (*getScanResults)(wifiInterfaceHandle handle, 139 std::vector<OHOS::HDI::Wlan::Chip::V2_0::ScanResultsInfo>& mscanResults); 140 WifiError (*enablePowerMode)(const char *, int); 141 WifiError (*getSignalPollInfo)(wifiInterfaceHandle handle, 142 OHOS::HDI::Wlan::Chip::V2_0::SignalPollResult& signalPollResult); 143 WifiError (*setDpiMarkRule)(int32_t, int32_t, int32_t); 144 WifiError (*registerIfaceCallBack)(const char *, WifiCallbackHandler); 145 WifiError (*setTxPower)(const char *, int); 146 WifiError (*registerExtIfaceCallBack)(const char* ifName, WifiExtCallbackHandler handler); 147 WifiError (*sendCmdToDriver)(const char* ifName, int32_t cmdId, 148 const std::vector<int8_t>& paramBuf, std::vector<int8_t>& result); 149 WifiError (*sendActionFrame)(wifiInterfaceHandle handle, uint32_t freq, const std::vector<uint8_t>& frameData); 150 WifiError (*registerActionFrameReceiver)(wifiInterfaceHandle handle, const std::vector<uint8_t>& match); 151 WifiError (*getCoexictenceChannelList)(const char* ifName, std::vector<uint8_t>& paramBuf); 152 WifiError (*setProjectionScreenParam)(wifiInterfaceHandle handle, 153 const OHOS::HDI::Wlan::Chip::V2_0::ProjectionScreenCmdParam& param); 154 } WifiHalFn; 155 156 WifiError InitWifiVendorHalFuncTable(WifiHalFn *fn); 157 typedef WifiError (*InitWifiVendorHalFuncTableT)(WifiHalFn *fn); 158 159 #ifdef __cplusplus 160 } 161 #endif 162 163 #endif 164