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 #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 typedef struct { 72 uint8_t associatedBssid[ETH_ADDR_LEN]; 73 uint32_t associatedFreq; 74 } AssociatedInfo; 75 76 WifiError VendorHalInit(wifiHandle *handle); 77 WifiError WaitDriverStart(void); 78 79 typedef void (*VendorHalExitHandler) (wifiHandle handle); 80 void VendorHalExit(wifiHandle handle, VendorHalExitHandler handler); 81 void StartHalLoop(wifiHandle handle); 82 83 WifiError VendorHalGetIfaces(wifiHandle handle, int *numIfaces, wifiInterfaceHandle **ifaces); 84 WifiError VendorHalGetIfName(wifiInterfaceHandle iface, char *name, size_t size); 85 86 typedef struct { 87 void (*onVendorHalRestart)(const char* error); 88 } VendorHalRestartHandler; 89 90 WifiError VendorHalSetRestartHandler(wifiHandle handle, 91 VendorHalRestartHandler handler); 92 93 typedef struct { 94 void (*onScanEvent) (int event); 95 void (*onRssiReport) (int index, int c0Rssi, int c1Rssi); 96 void (*onWifiNetlinkMessage) (uint32_t type, const std::vector<uint8_t>& recvMsg); 97 } WifiCallbackHandler; 98 99 typedef struct { 100 void (*onWifiNetlinkMessage) (uint32_t type, const std::vector<uint8_t>& recvMsg); 101 } WifiExtCallbackHandler; 102 103 typedef struct { 104 WifiError (*vendorHalInit)(wifiHandle *); 105 WifiError (*waitDriverStart)(void); 106 void (*vendorHalExit)(wifiHandle, VendorHalExitHandler); 107 void (*startHalLoop)(wifiHandle); 108 uint32_t (*wifiGetSupportedFeatureSet)(const char *); 109 WifiError (*wifiGetChipFeatureSet)(wifiHandle handle, uint64_t *set); 110 WifiError (*vendorHalGetIfaces)(wifiHandle, int *, wifiInterfaceHandle **); 111 WifiError (*vendorHalGetIfName)(wifiInterfaceHandle, char *name, size_t size); 112 WifiError (*vendorHalGetChannelsInBand)(wifiInterfaceHandle, int, std::vector<uint32_t>&); 113 WifiError (*vendorHalCreateIface)(wifiHandle handle, const char* ifname, HalIfaceType ifaceType); 114 WifiError (*vendorHalDeleteIface)(wifiHandle handle, const char* ifname); 115 WifiError (*vendorHalSetRestartHandler)(wifiHandle handle, VendorHalRestartHandler handler); 116 uint32_t (*getChipCaps)(const char *); 117 WifiError (*vendorHalPreInit)(void); 118 WifiError (*triggerVendorHalRestart)(wifiHandle handle); 119 WifiError (*wifiSetCountryCode)(wifiInterfaceHandle handle, const char *); 120 WifiError (*getPowerMode)(const char *, int *); 121 WifiError (*setPowerMode)(const char *, int); 122 WifiError (*isSupportCoex)(bool&); 123 WifiError (*wifiStartScan)(wifiInterfaceHandle handle, 124 const OHOS::HDI::Wlan::Chip::V1_0::ScanParams& scanParam); 125 WifiError (*wifiStartPnoScan)(wifiInterfaceHandle handle, 126 const OHOS::HDI::Wlan::Chip::V1_0::PnoScanParams& pnoScanParam); 127 WifiError (*wifiStopPnoScan)(wifiInterfaceHandle handle); 128 WifiError (*getScanResults)(wifiInterfaceHandle handle, 129 std::vector<OHOS::HDI::Wlan::Chip::V1_0::ScanResultsInfo>& mscanResults); 130 WifiError (*enablePowerMode)(const char *, int); 131 WifiError (*getSignalPollInfo)(wifiInterfaceHandle handle, 132 OHOS::HDI::Wlan::Chip::V1_0::SignalPollResult& signalPollResult); 133 WifiError (*setDpiMarkRule)(int32_t, int32_t, int32_t); 134 WifiError (*registerIfaceCallBack)(const char *, WifiCallbackHandler); 135 WifiError (*setTxPower)(const char *, int); 136 WifiError (*registerExtIfaceCallBack)(const char* ifName, WifiExtCallbackHandler handler); 137 WifiError (*sendCmdToDriver)(const char* ifName, int32_t cmdId, const std::vector<int8_t>& paramBuf); 138 WifiError (*sendActionFrame)(wifiInterfaceHandle handle, uint32_t freq, const std::vector<uint8_t>& frameData); 139 WifiError (*registerActionFrameReceiver)(wifiInterfaceHandle handle, const std::vector<uint8_t>& match); 140 WifiError (*getCoexictenceChannelList)(const char* ifName, std::vector<uint8_t>& paramBuf); 141 WifiError (*setProjectionScreenParam)(wifiInterfaceHandle handle, 142 const OHOS::HDI::Wlan::Chip::V1_0::ProjectionScreenCmdParam& param); 143 } WifiHalFn; 144 145 WifiError InitWifiVendorHalFuncTable(WifiHalFn *fn); 146 typedef WifiError (*InitWifiVendorHalFuncTableT)(WifiHalFn *fn); 147 148 #ifdef __cplusplus 149 } 150 #endif 151 152 #endif