1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#ifndef WIFI_HAL_H 17094332d3Sopenharmony_ci#define WIFI_HAL_H 18094332d3Sopenharmony_ci 19094332d3Sopenharmony_ci#include <cstdint> 20094332d3Sopenharmony_ci#include <cstddef> 21094332d3Sopenharmony_ci#include "v1_0/ichip_iface_callback.h" 22094332d3Sopenharmony_ci#include "v1_0/chip_types.h" 23094332d3Sopenharmony_ci 24094332d3Sopenharmony_ci#ifdef __cplusplus 25094332d3Sopenharmony_ciextern "C" 26094332d3Sopenharmony_ci{ 27094332d3Sopenharmony_ci#endif 28094332d3Sopenharmony_ci 29094332d3Sopenharmony_ci#define IFNAMSIZ_WIFI 16 30094332d3Sopenharmony_ci#define ETH_ADDR_LEN 6 31094332d3Sopenharmony_ci#define BSS_STATUS_ASSOCIATED 1 32094332d3Sopenharmony_ci 33094332d3Sopenharmony_citypedef unsigned char macAddr[6]; 34094332d3Sopenharmony_ci 35094332d3Sopenharmony_cistruct WifiInfo; 36094332d3Sopenharmony_cistruct WifiInterfaceInfo; 37094332d3Sopenharmony_citypedef struct WifiInfo *wifiHandle; 38094332d3Sopenharmony_citypedef struct WifiInterfaceInfo *wifiInterfaceHandle; 39094332d3Sopenharmony_ci 40094332d3Sopenharmony_citypedef enum { 41094332d3Sopenharmony_ci HAL_TYPE_STA = 0, 42094332d3Sopenharmony_ci HAL_TYPE_AP = 1, 43094332d3Sopenharmony_ci HAL_TYPE_P2P = 2, 44094332d3Sopenharmony_ci HAL_TYPE_NAN = 3 45094332d3Sopenharmony_ci} HalIfaceType; 46094332d3Sopenharmony_ci 47094332d3Sopenharmony_citypedef enum { 48094332d3Sopenharmony_ci HAL_SUCCESS = 0, 49094332d3Sopenharmony_ci HAL_NONE = 0, 50094332d3Sopenharmony_ci HAL_UNKNOWN = -1, 51094332d3Sopenharmony_ci HAL_UNINITIALIZED = -2, 52094332d3Sopenharmony_ci HAL_NOT_SUPPORTED = -3, 53094332d3Sopenharmony_ci HAL_NOT_AVAILABLE = -4, 54094332d3Sopenharmony_ci HAL_INVALID_ARGS = -5, 55094332d3Sopenharmony_ci HAL_INVALID_REQUEST_ID = -6, 56094332d3Sopenharmony_ci HAL_TIMED_OUT = -7, 57094332d3Sopenharmony_ci HAL_TOO_MANY_REQUESTS = -8, 58094332d3Sopenharmony_ci HAL_OUT_OF_MEMORY = -9, 59094332d3Sopenharmony_ci HAL_BUSY = -10 60094332d3Sopenharmony_ci} WifiError; 61094332d3Sopenharmony_ci 62094332d3Sopenharmony_cienum Ieee80211Band { 63094332d3Sopenharmony_ci IEEE80211_BAND_2GHZ, 64094332d3Sopenharmony_ci IEEE80211_BAND_5GHZ, 65094332d3Sopenharmony_ci IEEE80211_NUM_BANDS 66094332d3Sopenharmony_ci}; 67094332d3Sopenharmony_ci 68094332d3Sopenharmony_citypedef struct { 69094332d3Sopenharmony_ci uint8_t associatedBssid[ETH_ADDR_LEN]; 70094332d3Sopenharmony_ci uint32_t associatedFreq; 71094332d3Sopenharmony_ci} AssociatedInfo; 72094332d3Sopenharmony_ci 73094332d3Sopenharmony_ciWifiError VendorHalInit(wifiHandle *handle); 74094332d3Sopenharmony_ciWifiError WaitDriverStart(void); 75094332d3Sopenharmony_ci 76094332d3Sopenharmony_citypedef void (*VendorHalExitHandler) (wifiHandle handle); 77094332d3Sopenharmony_civoid VendorHalExit(wifiHandle handle, VendorHalExitHandler handler); 78094332d3Sopenharmony_civoid StartHalLoop(wifiHandle handle); 79094332d3Sopenharmony_ci 80094332d3Sopenharmony_ciWifiError VendorHalGetIfaces(wifiHandle handle, int *numIfaces, wifiInterfaceHandle **ifaces); 81094332d3Sopenharmony_ciWifiError VendorHalGetIfName(wifiInterfaceHandle iface, char *name, size_t size); 82094332d3Sopenharmony_ci 83094332d3Sopenharmony_citypedef struct { 84094332d3Sopenharmony_ci void (*onVendorHalRestart)(const char* error); 85094332d3Sopenharmony_ci} VendorHalRestartHandler; 86094332d3Sopenharmony_ci 87094332d3Sopenharmony_ciWifiError VendorHalSetRestartHandler(wifiHandle handle, 88094332d3Sopenharmony_ci VendorHalRestartHandler handler); 89094332d3Sopenharmony_ci 90094332d3Sopenharmony_citypedef struct { 91094332d3Sopenharmony_ci void (*onScanEvent) (int event); 92094332d3Sopenharmony_ci void (*onRssiReport) (int index, int c0Rssi, int c1Rssi); 93094332d3Sopenharmony_ci} WifiCallbackHandler; 94094332d3Sopenharmony_ci 95094332d3Sopenharmony_citypedef struct { 96094332d3Sopenharmony_ci void (*onWifiNetlinkMessage) (uint32_t type, const std::vector<uint8_t>& recvMsg); 97094332d3Sopenharmony_ci} WifiExtCallbackHandler; 98094332d3Sopenharmony_ci 99094332d3Sopenharmony_citypedef struct { 100094332d3Sopenharmony_ci WifiError (*vendorHalInit)(wifiHandle *); 101094332d3Sopenharmony_ci WifiError (*waitDriverStart)(void); 102094332d3Sopenharmony_ci void (*vendorHalExit)(wifiHandle, VendorHalExitHandler); 103094332d3Sopenharmony_ci void (*startHalLoop)(wifiHandle); 104094332d3Sopenharmony_ci uint32_t (*wifiGetSupportedFeatureSet)(const char *); 105094332d3Sopenharmony_ci WifiError (*wifiGetChipFeatureSet)(wifiHandle handle, uint64_t *set); 106094332d3Sopenharmony_ci WifiError (*vendorHalGetIfaces)(wifiHandle, int *, wifiInterfaceHandle **); 107094332d3Sopenharmony_ci WifiError (*vendorHalGetIfName)(wifiInterfaceHandle, char *name, size_t size); 108094332d3Sopenharmony_ci WifiError (*vendorHalGetChannelsInBand)(wifiInterfaceHandle, int, std::vector<uint32_t>&); 109094332d3Sopenharmony_ci WifiError (*vendorHalCreateIface)(wifiHandle handle, const char* ifname, HalIfaceType ifaceType); 110094332d3Sopenharmony_ci WifiError (*vendorHalDeleteIface)(wifiHandle handle, const char* ifname); 111094332d3Sopenharmony_ci WifiError (*vendorHalSetRestartHandler)(wifiHandle handle, VendorHalRestartHandler handler); 112094332d3Sopenharmony_ci uint32_t (*getChipCaps)(const char *); 113094332d3Sopenharmony_ci WifiError (*vendorHalPreInit)(void); 114094332d3Sopenharmony_ci WifiError (*triggerVendorHalRestart)(wifiHandle handle); 115094332d3Sopenharmony_ci WifiError (*wifiSetCountryCode)(wifiInterfaceHandle handle, const char *); 116094332d3Sopenharmony_ci WifiError (*getPowerMode)(const char *, int *); 117094332d3Sopenharmony_ci WifiError (*setPowerMode)(const char *, int); 118094332d3Sopenharmony_ci WifiError (*isSupportCoex)(bool&); 119094332d3Sopenharmony_ci WifiError (*wifiStartScan)(wifiInterfaceHandle handle, 120094332d3Sopenharmony_ci const OHOS::HDI::Wlan::Chip::V1_0::ScanParams& scanParam); 121094332d3Sopenharmony_ci WifiError (*wifiStartPnoScan)(wifiInterfaceHandle handle, 122094332d3Sopenharmony_ci const OHOS::HDI::Wlan::Chip::V1_0::PnoScanParams& pnoScanParam); 123094332d3Sopenharmony_ci WifiError (*wifiStopPnoScan)(wifiInterfaceHandle handle); 124094332d3Sopenharmony_ci WifiError (*getScanResults)(wifiInterfaceHandle handle, 125094332d3Sopenharmony_ci std::vector<OHOS::HDI::Wlan::Chip::V1_0::ScanResultsInfo>& mscanResults); 126094332d3Sopenharmony_ci WifiError (*enablePowerMode)(const char *, int); 127094332d3Sopenharmony_ci WifiError (*getSignalPollInfo)(wifiInterfaceHandle handle, 128094332d3Sopenharmony_ci OHOS::HDI::Wlan::Chip::V1_0::SignalPollResult& signalPollResult); 129094332d3Sopenharmony_ci WifiError (*setDpiMarkRule)(int32_t, int32_t, int32_t); 130094332d3Sopenharmony_ci WifiError (*registerIfaceCallBack)(const char *, WifiCallbackHandler); 131094332d3Sopenharmony_ci WifiError (*setTxPower)(const char *, int); 132094332d3Sopenharmony_ci WifiError (*registerExtIfaceCallBack)(const char* ifName, WifiExtCallbackHandler handler); 133094332d3Sopenharmony_ci WifiError (*sendCmdToDriver)(const char* ifName, int32_t cmdId, const std::vector<int8_t>& paramBuf); 134094332d3Sopenharmony_ci WifiError (*sendActionFrame)(wifiInterfaceHandle handle, uint32_t freq, const std::vector<uint8_t>& frameData); 135094332d3Sopenharmony_ci WifiError (*registerActionFrameReceiver)(wifiInterfaceHandle handle, const std::vector<uint8_t>& match); 136094332d3Sopenharmony_ci WifiError (*getCoexictenceChannelList)(const std::string& ifName, std::vector<uint8_t>& paramBuf); 137094332d3Sopenharmony_ci} WifiHalFn; 138094332d3Sopenharmony_ci 139094332d3Sopenharmony_ciWifiError InitWifiVendorHalFuncTable(WifiHalFn *fn); 140094332d3Sopenharmony_citypedef WifiError (*InitWifiVendorHalFuncTableT)(WifiHalFn *fn); 141094332d3Sopenharmony_ci 142094332d3Sopenharmony_ci#ifdef __cplusplus 143094332d3Sopenharmony_ci} 144094332d3Sopenharmony_ci#endif 145094332d3Sopenharmony_ci 146094332d3Sopenharmony_ci#endif