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 #include "wifi_hal_fn.h"
17
18 const std::string VAILD_IFNAME = "wlan0";
19 const std::string INVAILD_IFNAME = "wlan2";
20 const int NAME_LEN = 5;
21
VendorHalInit(wifiHandle * handle)22 WifiError VendorHalInit(wifiHandle *handle)
23 {
24 return HAL_SUCCESS;
25 }
26
WaitDriverStart(void)27 WifiError WaitDriverStart(void)
28 {
29 return HAL_SUCCESS;
30 }
31
VendorHalExit(wifiHandle handle,VendorHalExitHandler handler)32 void VendorHalExit(wifiHandle handle, VendorHalExitHandler handler)
33 {
34 HDF_LOGI("VendorHalExit enter");
35 }
36
StartHalLoop(wifiHandle handle)37 void StartHalLoop(wifiHandle handle)
38 {
39 HDF_LOGI("StartHalLoop enter");
40 }
41
VendorHalGetIfaces(wifiHandle handle,int * num,wifiInterfaceHandle ** interfaces)42 WifiError VendorHalGetIfaces(wifiHandle handle, int *num, wifiInterfaceHandle **interfaces)
43 {
44 return HAL_SUCCESS;
45 }
46
VendorHalGetIfName(wifiInterfaceHandle handle,char * name,size_t size)47 WifiError VendorHalGetIfName(wifiInterfaceHandle handle, char *name, size_t size)
48 {
49 return HAL_SUCCESS;
50 }
51
VendorHalGetChannelsInBand(wifiInterfaceHandle handle,int band,std::vector<uint32_t> & freqs)52 WifiError VendorHalGetChannelsInBand(wifiInterfaceHandle handle, int band,
53 std::vector<uint32_t>& freqs)
54 {
55 if (band == 0) {
56 return HAL_SUCCESS;
57 }
58 return HAL_UNKNOWN;
59 }
60
VendorHalSetRestartHandler(wifiHandle handle,VendorHalRestartHandler handler)61 WifiError VendorHalSetRestartHandler(wifiHandle handle, VendorHalRestartHandler handler)
62 {
63 return HAL_SUCCESS;
64 }
65
VendorHalCreateIface(wifiHandle handle,const char * ifname,HalIfaceType ifaceType)66 WifiError VendorHalCreateIface(wifiHandle handle, const char* ifname, HalIfaceType ifaceType)
67 {
68 return HAL_SUCCESS;
69 }
70
VendorHalDeleteIface(wifiHandle handle,const char * ifname)71 WifiError VendorHalDeleteIface(wifiHandle handle, const char* ifname)
72 {
73 if (strncmp(ifname, VAILD_IFNAME.c_str(), NAME_LEN) == 0) {
74 return HAL_SUCCESS;
75 }
76 return HAL_NOT_SUPPORTED;
77 }
78
TriggerVendorHalRestart(wifiHandle handle)79 WifiError TriggerVendorHalRestart(wifiHandle handle)
80 {
81 return HAL_SUCCESS;
82 }
83
WifiSetCountryCode(wifiInterfaceHandle handle,const char * countryCode)84 static WifiError WifiSetCountryCode(wifiInterfaceHandle handle, const char *countryCode)
85 {
86 return HAL_SUCCESS;
87 }
88
GetPowerMode(const char * ifName,int * mode)89 WifiError GetPowerMode(const char *ifName, int *mode)
90 {
91 return HAL_SUCCESS;
92 }
93
SetPowerMode(const char * ifName,int mode)94 WifiError SetPowerMode(const char *ifName, int mode)
95 {
96 return HAL_SUCCESS;
97 }
98
EnablePowerMode(const char * ifName,int mode)99 WifiError EnablePowerMode(const char *ifName, int mode)
100 {
101 return HAL_SUCCESS;
102 }
103
WifiGetSignalInfo(wifiInterfaceHandle handle,OHOS::HDI::Wlan::Chip::V1_0::SignalPollResult & signalPollresult)104 static WifiError WifiGetSignalInfo(wifiInterfaceHandle handle,
105 OHOS::HDI::Wlan::Chip::V1_0::SignalPollResult& signalPollresult)
106 {
107 return HAL_SUCCESS;
108 }
109
WifiSetDpiMarkRule(int32_t uid,int32_t protocol,int32_t enable)110 WifiError WifiSetDpiMarkRule(int32_t uid, int32_t protocol, int32_t enable)
111 {
112 if (uid == 0) {
113 return HAL_SUCCESS;
114 }
115 return HAL_INVALID_ARGS;
116 }
117
WifiStartScan(wifiInterfaceHandle handle,const OHOS::HDI::Wlan::Chip::V1_0::ScanParams & scanParam)118 WifiError WifiStartScan(wifiInterfaceHandle handle,
119 const OHOS::HDI::Wlan::Chip::V1_0::ScanParams& scanParam)
120 {
121 if (scanParam.fastConnectFlag == 0) {
122 return HAL_SUCCESS;
123 }
124 return HAL_INVALID_ARGS;
125 }
126
RegisterIfaceCallBack(const char * ifaceName,WifiCallbackHandler onCallbackEvent)127 static WifiError RegisterIfaceCallBack(const char *ifaceName, WifiCallbackHandler onCallbackEvent)
128 {
129 if (ifaceName == nullptr) {
130 HDF_LOGE("ifaceName is null");
131 return HAL_NONE;
132 }
133 return HAL_SUCCESS;
134 }
135
WifiGetScanInfo(wifiInterfaceHandle handle,std::vector<OHOS::HDI::Wlan::Chip::V1_0::ScanResultsInfo> & res)136 WifiError WifiGetScanInfo(wifiInterfaceHandle handle,
137 std::vector<OHOS::HDI::Wlan::Chip::V1_0::ScanResultsInfo>& res)
138 {
139 return HAL_SUCCESS;
140 }
141
WifiStartPnoScan(wifiInterfaceHandle handle,const OHOS::HDI::Wlan::Chip::V1_0::PnoScanParams & pnoScanParam)142 WifiError WifiStartPnoScan(wifiInterfaceHandle handle,
143 const OHOS::HDI::Wlan::Chip::V1_0::PnoScanParams& pnoScanParam)
144 {
145 if (pnoScanParam.min2gRssi == 0) {
146 return HAL_SUCCESS;
147 }
148 return HAL_INVALID_ARGS;
149 }
150
WifiStopPnoScan(wifiInterfaceHandle handle)151 WifiError WifiStopPnoScan(wifiInterfaceHandle handle)
152 {
153 return HAL_SUCCESS;
154 }
155
WifiGetSupportedFeatureSet(const char * ifName)156 uint32_t WifiGetSupportedFeatureSet(const char *ifName)
157 {
158 if (ifName == nullptr) {
159 return 0;
160 }
161 if (strncmp(ifName, VAILD_IFNAME.c_str(), NAME_LEN) == 0) {
162 return 1;
163 }
164 return 0;
165 }
166
GetChipCaps(const char * ifName)167 uint32_t GetChipCaps(const char *ifName)
168 {
169 if (ifName == nullptr) {
170 return 0;
171 }
172 if (strncmp(ifName, VAILD_IFNAME.c_str(), NAME_LEN) == 0) {
173 return 1;
174 }
175 return 0;
176 }
177
SetTxPower(const char * ifName,int mode)178 WifiError SetTxPower(const char *ifName, int mode)
179 {
180 if (mode == 0) {
181 return HAL_SUCCESS;
182 }
183 return HAL_INVALID_ARGS;
184 }
185
IsSupportCoex(bool & isCoex)186 WifiError IsSupportCoex(bool& isCoex)
187 {
188 isCoex = true;
189 return HAL_SUCCESS;
190 }
191
InitWifiHalFuncTable(WifiHalFn * fn)192 WifiError InitWifiHalFuncTable(WifiHalFn *fn)
193 {
194 if (fn == nullptr) {
195 return HAL_UNKNOWN;
196 }
197 fn->vendorHalInit = VendorHalInit;
198 fn->waitDriverStart = WaitDriverStart;
199 fn->vendorHalExit = VendorHalExit;
200 fn->startHalLoop = StartHalLoop;
201 fn->vendorHalGetIfaces = VendorHalGetIfaces;
202 fn->vendorHalGetIfName = VendorHalGetIfName;
203 fn->vendorHalGetChannelsInBand = VendorHalGetChannelsInBand;
204 fn->vendorHalSetRestartHandler = VendorHalSetRestartHandler;
205 fn->vendorHalCreateIface = VendorHalCreateIface;
206 fn->vendorHalDeleteIface = VendorHalDeleteIface;
207 fn->triggerVendorHalRestart = TriggerVendorHalRestart;
208 fn->wifiSetCountryCode = WifiSetCountryCode;
209 fn->getPowerMode = GetPowerMode;
210 fn->setPowerMode = SetPowerMode;
211 fn->enablePowerMode = EnablePowerMode;
212 fn->getSignalPollInfo = WifiGetSignalInfo;
213 fn->setDpiMarkRule = WifiSetDpiMarkRule;
214 fn->wifiStartScan = WifiStartScan;
215 fn->registerIfaceCallBack = RegisterIfaceCallBack;
216 fn->getScanResults = WifiGetScanInfo;
217 fn->wifiStartPnoScan = WifiStartPnoScan;
218 fn->wifiStopPnoScan = WifiStopPnoScan;
219 fn->wifiGetSupportedFeatureSet = WifiGetSupportedFeatureSet;
220 fn->getChipCaps = GetChipCaps;
221 fn->setTxPower = SetTxPower;
222 fn->isSupportCoex = IsSupportCoex;
223 return HAL_SUCCESS;
224 }