• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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_p2p_hal_interface.h"
17 #include "wifi_log.h"
18 #include "hal_device_manage.h"
19 #include <mutex>
20 #include "wifi_config_center.h"
21 
22 #undef LOG_TAG
23 #define LOG_TAG "WifiP2PHalInterface"
24 
25 namespace OHOS {
26 namespace Wifi {
GetInstance(void)27 WifiP2PHalInterface &WifiP2PHalInterface::GetInstance(void)
28 {
29     static WifiP2PHalInterface inst;
30     static int initFlag = 0;
31     static std::mutex initMutex;
32     if (initFlag == 0) {
33         std::unique_lock<std::mutex> lock(initMutex);
34         if (initFlag == 0) {
35 #ifdef HDI_WPA_INTERFACE_SUPPORT
36             if (inst.InitHdiWpaClient()) {
37                 initFlag = 1;
38             }
39 #endif
40         }
41     }
42     return inst;
43 }
44 
StartP2p(const std::string & ifaceName,const bool hasPersisentGroup) const45 WifiErrorNo WifiP2PHalInterface::StartP2p(const std::string &ifaceName, const bool hasPersisentGroup) const
46 {
47 #ifdef HDI_WPA_INTERFACE_SUPPORT
48     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
49     return mHdiWpaClient->ReqP2pStart(ifaceName, hasPersisentGroup);
50 #endif
51     return WIFI_HAL_OPT_FAILED;
52 }
53 
StopP2p(void) const54 WifiErrorNo WifiP2PHalInterface::StopP2p(void) const
55 {
56 #ifdef HDI_WPA_INTERFACE_SUPPORT
57     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
58     return mHdiWpaClient->ReqP2pStop();
59 #endif
60     return WIFI_HAL_OPT_FAILED;
61 }
62 
RegisterP2pCallback(const P2pHalCallback & callbacks)63 WifiErrorNo WifiP2PHalInterface::RegisterP2pCallback(const P2pHalCallback &callbacks)
64 {
65     WifiErrorNo err = WIFI_HAL_OPT_FAILED;
66 #ifdef HDI_WPA_INTERFACE_SUPPORT
67     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
68     err = mHdiWpaClient->ReqP2pRegisterCallback(callbacks);
69 #endif
70     if (err == WIFI_HAL_OPT_OK || callbacks.onConnectSupplicant == nullptr) {
71         mP2pCallback = callbacks;
72     }
73     return err;
74 }
75 
StartWpsPbc(const std::string & groupInterface,const std::string & bssid) const76 WifiErrorNo WifiP2PHalInterface::StartWpsPbc(const std::string &groupInterface, const std::string &bssid) const
77 {
78 #ifdef HDI_WPA_INTERFACE_SUPPORT
79     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
80     return mHdiWpaClient->ReqP2pSetupWpsPbc(groupInterface, bssid);
81 #endif
82     return WIFI_HAL_OPT_FAILED;
83 }
84 
StartWpsPin(const std::string & groupInterface,const std::string & address,const std::string & pin,std::string & result) const85 WifiErrorNo WifiP2PHalInterface::StartWpsPin(
86     const std::string &groupInterface, const std::string &address, const std::string &pin, std::string &result) const
87 {
88 #ifdef HDI_WPA_INTERFACE_SUPPORT
89     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
90     return mHdiWpaClient->ReqP2pSetupWpsPin(groupInterface, address, pin, result);
91 #endif
92     return WIFI_HAL_OPT_FAILED;
93 }
94 
RemoveNetwork(int networkId) const95 WifiErrorNo WifiP2PHalInterface::RemoveNetwork(int networkId) const
96 {
97 #ifdef HDI_WPA_INTERFACE_SUPPORT
98     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
99     return mHdiWpaClient->ReqP2pRemoveNetwork(networkId);
100 #endif
101     return WIFI_HAL_OPT_FAILED;
102 }
103 
ListNetworks(std::map<int,WifiP2pGroupInfo> & mapGroups) const104 WifiErrorNo WifiP2PHalInterface::ListNetworks(std::map<int, WifiP2pGroupInfo> &mapGroups) const
105 {
106 #ifdef HDI_WPA_INTERFACE_SUPPORT
107     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
108     return mHdiWpaClient->ReqP2pListNetworks(mapGroups);
109 #endif
110     return WIFI_HAL_OPT_FAILED;
111 }
112 
SetP2pDeviceName(const std::string & name) const113 WifiErrorNo WifiP2PHalInterface::SetP2pDeviceName(const std::string &name) const
114 {
115 #ifdef HDI_WPA_INTERFACE_SUPPORT
116     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
117     return mHdiWpaClient->ReqP2pSetDeviceName(name);
118 #endif
119     return WIFI_HAL_OPT_FAILED;
120 }
121 
SetP2pDeviceType(const std::string & type) const122 WifiErrorNo WifiP2PHalInterface::SetP2pDeviceType(const std::string &type) const
123 {
124 #ifdef HDI_WPA_INTERFACE_SUPPORT
125     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
126     return mHdiWpaClient->ReqP2pSetWpsDeviceType(type);
127 #endif
128     return WIFI_HAL_OPT_FAILED;
129 }
130 
SetP2pSecondaryDeviceType(const std::string & type)131 WifiErrorNo WifiP2PHalInterface::SetP2pSecondaryDeviceType(const std::string &type)
132 {
133 #ifdef HDI_WPA_INTERFACE_SUPPORT
134     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
135     return mHdiWpaClient->ReqP2pSetWpsSecondaryDeviceType(type);
136 #endif
137     return WIFI_HAL_OPT_FAILED;
138 }
139 
SetP2pConfigMethods(const std::string & methods) const140 WifiErrorNo WifiP2PHalInterface::SetP2pConfigMethods(const std::string &methods) const
141 {
142 #ifdef HDI_WPA_INTERFACE_SUPPORT
143     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
144     return mHdiWpaClient->ReqP2pSetWpsConfigMethods(methods);
145 #endif
146     return WIFI_HAL_OPT_FAILED;
147 }
148 
SetP2pSsidPostfix(const std::string & postfixName) const149 WifiErrorNo WifiP2PHalInterface::SetP2pSsidPostfix(const std::string &postfixName) const
150 {
151 #ifdef HDI_WPA_INTERFACE_SUPPORT
152     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
153     return mHdiWpaClient->ReqP2pSetSsidPostfixName(postfixName);
154 #endif
155     return WIFI_HAL_OPT_FAILED;
156 }
157 
SetP2pGroupIdle(const std::string & groupInterface,size_t time) const158 WifiErrorNo WifiP2PHalInterface::SetP2pGroupIdle(const std::string &groupInterface, size_t time) const
159 {
160 #ifdef HDI_WPA_INTERFACE_SUPPORT
161     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
162     return mHdiWpaClient->ReqP2pSetGroupMaxIdle(groupInterface, time);
163 #endif
164     return WIFI_HAL_OPT_FAILED;
165 }
166 
SetP2pPowerSave(const std::string & groupInterface,bool enable) const167 WifiErrorNo WifiP2PHalInterface::SetP2pPowerSave(const std::string &groupInterface, bool enable) const
168 {
169 #ifdef HDI_WPA_INTERFACE_SUPPORT
170     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
171     return mHdiWpaClient->ReqP2pSetPowerSave(groupInterface, enable);
172 #endif
173     return WIFI_HAL_OPT_FAILED;
174 }
175 
SetWfdEnable(bool enable) const176 WifiErrorNo WifiP2PHalInterface::SetWfdEnable(bool enable) const
177 {
178 #ifdef HDI_WPA_INTERFACE_SUPPORT
179     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
180     return mHdiWpaClient->ReqP2pSetWfdEnable(enable);
181 #endif
182     return WIFI_HAL_OPT_FAILED;
183 }
184 
SetWfdDeviceConfig(const std::string & config) const185 WifiErrorNo WifiP2PHalInterface::SetWfdDeviceConfig(const std::string &config) const
186 {
187 #ifdef HDI_WPA_INTERFACE_SUPPORT
188     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
189     return mHdiWpaClient->ReqP2pSetWfdDeviceConfig(config);
190 #endif
191     return WIFI_HAL_OPT_FAILED;
192 }
193 
P2pFind(size_t timeout) const194 WifiErrorNo WifiP2PHalInterface::P2pFind(size_t timeout) const
195 {
196 #ifdef HDI_WPA_INTERFACE_SUPPORT
197     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
198     return mHdiWpaClient->ReqP2pStartFind(timeout);
199 #endif
200     return WIFI_HAL_OPT_FAILED;
201 }
202 
P2pStopFind() const203 WifiErrorNo WifiP2PHalInterface::P2pStopFind() const
204 {
205 #ifdef HDI_WPA_INTERFACE_SUPPORT
206     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
207     return mHdiWpaClient->ReqP2pStopFind();
208 #endif
209     return WIFI_HAL_OPT_FAILED;
210 }
211 
P2pConfigureListen(bool enable,size_t period,size_t interval) const212 WifiErrorNo WifiP2PHalInterface::P2pConfigureListen(bool enable, size_t period, size_t interval) const
213 {
214 #ifdef HDI_WPA_INTERFACE_SUPPORT
215     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
216     return mHdiWpaClient->ReqP2pSetExtListen(enable, period, interval);
217 #endif
218     return WIFI_HAL_OPT_FAILED;
219 }
220 
SetListenChannel(size_t channel,unsigned char regClass) const221 WifiErrorNo WifiP2PHalInterface::SetListenChannel(size_t channel, unsigned char regClass) const
222 {
223 #ifdef HDI_WPA_INTERFACE_SUPPORT
224     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
225     return mHdiWpaClient->ReqP2pSetListenChannel(channel, regClass);
226 #endif
227     return WIFI_HAL_OPT_FAILED;
228 }
229 
P2pFlush() const230 WifiErrorNo WifiP2PHalInterface::P2pFlush() const
231 {
232 #ifdef HDI_WPA_INTERFACE_SUPPORT
233     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
234     return mHdiWpaClient->ReqP2pFlush();
235 #endif
236     return WIFI_HAL_OPT_FAILED;
237 }
238 
Connect(const WifiP2pConfigInternal & config,bool isJoinExistingGroup,std::string & pin) const239 WifiErrorNo WifiP2PHalInterface::Connect(const WifiP2pConfigInternal &config, bool isJoinExistingGroup,
240     std::string &pin) const
241 {
242 #ifdef HDI_WPA_INTERFACE_SUPPORT
243     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
244     return mHdiWpaClient->ReqP2pConnect(config, isJoinExistingGroup, pin);
245 #endif
246     return WIFI_HAL_OPT_FAILED;
247 }
248 
CancelConnect() const249 WifiErrorNo WifiP2PHalInterface::CancelConnect() const
250 {
251 #ifdef HDI_WPA_INTERFACE_SUPPORT
252     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
253     return mHdiWpaClient->ReqP2pCancelConnect();
254 #endif
255     return WIFI_HAL_OPT_FAILED;
256 }
257 
ProvisionDiscovery(const WifiP2pConfigInternal & config) const258 WifiErrorNo WifiP2PHalInterface::ProvisionDiscovery(const WifiP2pConfigInternal &config) const
259 {
260 #ifdef HDI_WPA_INTERFACE_SUPPORT
261     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
262     return mHdiWpaClient->ReqP2pProvisionDiscovery(config);
263 #endif
264     return WIFI_HAL_OPT_FAILED;
265 }
266 
GroupAdd(bool isPersistent,int networkId,int freq) const267 WifiErrorNo WifiP2PHalInterface::GroupAdd(bool isPersistent, int networkId, int freq) const
268 {
269 #ifdef HDI_WPA_INTERFACE_SUPPORT
270     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
271     return mHdiWpaClient->ReqP2pAddGroup(isPersistent, networkId, freq);
272 #endif
273     return WIFI_HAL_OPT_FAILED;
274 }
275 
GroupRemove(const std::string & groupInterface) const276 WifiErrorNo WifiP2PHalInterface::GroupRemove(const std::string &groupInterface) const
277 {
278 #ifdef HDI_WPA_INTERFACE_SUPPORT
279     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
280     return mHdiWpaClient->ReqP2pRemoveGroup(groupInterface);
281 #endif
282     return WIFI_HAL_OPT_FAILED;
283 }
284 
GroupClientRemove(const std::string & deviceMac) const285 WifiErrorNo WifiP2PHalInterface::GroupClientRemove(const std::string &deviceMac) const
286 {
287 #ifdef HDI_WPA_INTERFACE_SUPPORT
288     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
289     std::string ifName = WifiConfigCenter::GetInstance().GetP2pIfaceName();
290     return mHdiWpaClient->ReqP2pRemoveGroupClient(deviceMac, ifName);
291 #endif
292     return WIFI_HAL_OPT_FAILED;
293 }
294 
Invite(const WifiP2pGroupInfo & group,const std::string & deviceAddr) const295 WifiErrorNo WifiP2PHalInterface::Invite(const WifiP2pGroupInfo &group, const std::string &deviceAddr) const
296 {
297 #ifdef HDI_WPA_INTERFACE_SUPPORT
298     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
299     return mHdiWpaClient->ReqP2pInvite(group, deviceAddr);
300 #endif
301     return WIFI_HAL_OPT_FAILED;
302 }
303 
Reinvoke(int networkId,const std::string & deviceAddr) const304 WifiErrorNo WifiP2PHalInterface::Reinvoke(int networkId, const std::string &deviceAddr) const
305 {
306 #ifdef HDI_WPA_INTERFACE_SUPPORT
307     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
308     return mHdiWpaClient->ReqP2pReinvoke(networkId, deviceAddr);
309 #endif
310     return WIFI_HAL_OPT_FAILED;
311 }
312 
GetDeviceAddress(std::string & deviceAddress) const313 WifiErrorNo WifiP2PHalInterface::GetDeviceAddress(std::string &deviceAddress) const
314 {
315 #ifdef HDI_WPA_INTERFACE_SUPPORT
316     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
317     return mHdiWpaClient->ReqP2pGetDeviceAddress(deviceAddress);
318 #endif
319     return WIFI_HAL_OPT_FAILED;
320 }
321 
GetGroupCapability(const std::string & deviceAddress,uint32_t & cap) const322 WifiErrorNo WifiP2PHalInterface::GetGroupCapability(const std::string &deviceAddress, uint32_t &cap) const
323 {
324 #ifdef HDI_WPA_INTERFACE_SUPPORT
325     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
326     return mHdiWpaClient->ReqP2pGetGroupCapability(deviceAddress, cap);
327 #endif
328     return WIFI_HAL_OPT_FAILED;
329 }
330 
P2pServiceAdd(const WifiP2pServiceInfo & info) const331 WifiErrorNo WifiP2PHalInterface::P2pServiceAdd(const WifiP2pServiceInfo &info) const
332 {
333 #ifdef HDI_WPA_INTERFACE_SUPPORT
334     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
335     return mHdiWpaClient->ReqP2pAddService(info);
336 #endif
337     return WIFI_HAL_OPT_FAILED;
338 }
339 
P2pServiceRemove(const WifiP2pServiceInfo & info) const340 WifiErrorNo WifiP2PHalInterface::P2pServiceRemove(const WifiP2pServiceInfo &info) const
341 {
342 #ifdef HDI_WPA_INTERFACE_SUPPORT
343     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
344     return mHdiWpaClient->ReqP2pRemoveService(info);
345 #endif
346     return WIFI_HAL_OPT_FAILED;
347 }
348 
FlushService() const349 WifiErrorNo WifiP2PHalInterface::FlushService() const
350 {
351 #ifdef HDI_WPA_INTERFACE_SUPPORT
352     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
353     return mHdiWpaClient->ReqP2pFlushService();
354 #endif
355     return WIFI_HAL_OPT_FAILED;
356 }
357 
SaveConfig() const358 WifiErrorNo WifiP2PHalInterface::SaveConfig() const
359 {
360 #ifdef HDI_WPA_INTERFACE_SUPPORT
361     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
362     return mHdiWpaClient->ReqP2pSaveConfig();
363 #endif
364     return WIFI_HAL_OPT_FAILED;
365 }
366 
ReqServiceDiscovery(const std::string & deviceAddress,const std::vector<unsigned char> & tlvs,std::string & reqID) const367 WifiErrorNo WifiP2PHalInterface::ReqServiceDiscovery(
368     const std::string &deviceAddress, const std::vector<unsigned char> &tlvs, std::string &reqID) const
369 {
370 #ifdef HDI_WPA_INTERFACE_SUPPORT
371     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
372     return mHdiWpaClient->ReqP2pReqServiceDiscovery(deviceAddress, tlvs, reqID);
373 #endif
374     return WIFI_HAL_OPT_FAILED;
375 }
376 
CancelReqServiceDiscovery(const std::string & id) const377 WifiErrorNo WifiP2PHalInterface::CancelReqServiceDiscovery(const std::string &id) const
378 {
379 #ifdef HDI_WPA_INTERFACE_SUPPORT
380     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
381     return mHdiWpaClient->ReqP2pCancelServiceDiscovery(id);
382 #endif
383     return WIFI_HAL_OPT_FAILED;
384 }
385 
SetRandomMacAddr(bool enable) const386 WifiErrorNo WifiP2PHalInterface::SetRandomMacAddr(bool enable) const
387 {
388 #ifdef HDI_WPA_INTERFACE_SUPPORT
389     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
390     return mHdiWpaClient->ReqP2pSetRandomMac(enable);
391 #endif
392     return WIFI_HAL_OPT_FAILED;
393 }
394 
SetMiracastMode(int type) const395 WifiErrorNo WifiP2PHalInterface::SetMiracastMode(int type) const
396 {
397 #ifdef HDI_WPA_INTERFACE_SUPPORT
398     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
399     return mHdiWpaClient->ReqP2pSetMiracastType(type);
400 #endif
401     return WIFI_HAL_OPT_FAILED;
402 }
403 
SetPersistentReconnect(int mode) const404 WifiErrorNo WifiP2PHalInterface::SetPersistentReconnect(int mode) const
405 {
406 #ifdef HDI_WPA_INTERFACE_SUPPORT
407     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
408     return mHdiWpaClient->ReqSetPersistentReconnect(mode);
409 #endif
410     return WIFI_HAL_OPT_FAILED;
411 }
412 
RespServiceDiscovery(const WifiP2pDevice & device,int frequency,int dialogToken,const std::vector<unsigned char> & tlvs) const413 WifiErrorNo WifiP2PHalInterface::RespServiceDiscovery(
414     const WifiP2pDevice &device, int frequency, int dialogToken, const std::vector<unsigned char> &tlvs) const
415 {
416 #ifdef HDI_WPA_INTERFACE_SUPPORT
417     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
418     return mHdiWpaClient->ReqRespServiceDiscovery(device, frequency, dialogToken, tlvs);
419 #endif
420     return WIFI_HAL_OPT_FAILED;
421 }
422 
SetServiceDiscoveryExternal(bool isExternalProcess) const423 WifiErrorNo WifiP2PHalInterface::SetServiceDiscoveryExternal(bool isExternalProcess) const
424 {
425 #ifdef HDI_WPA_INTERFACE_SUPPORT
426     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
427     return mHdiWpaClient->ReqSetServiceDiscoveryExternal(isExternalProcess);
428 #endif
429     return WIFI_HAL_OPT_FAILED;
430 }
431 
GetP2pPeer(const std::string & deviceAddress,WifiP2pDevice & device) const432 WifiErrorNo WifiP2PHalInterface::GetP2pPeer(const std::string &deviceAddress, WifiP2pDevice &device) const
433 {
434 #ifdef HDI_WPA_INTERFACE_SUPPORT
435     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
436     return mHdiWpaClient->ReqGetP2pPeer(deviceAddress, device);
437 #endif
438     return WIFI_HAL_OPT_FAILED;
439 }
440 
GetChba0Freq(int & chba0Freq) const441 WifiErrorNo WifiP2PHalInterface::GetChba0Freq(int &chba0Freq) const
442 {
443     return WIFI_HAL_OPT_FAILED;
444 }
445 
P2pGetSupportFrequenciesByBand(const std::string & ifaceName,int band,std::vector<int> & frequencies) const446 WifiErrorNo WifiP2PHalInterface::P2pGetSupportFrequenciesByBand(const std::string &ifaceName, int band,
447     std::vector<int> &frequencies) const
448 {
449 #ifdef HDI_CHIP_INTERFACE_SUPPORT
450     if (!HalDeviceManager::GetInstance().GetFrequenciesByBand(ifaceName, band, frequencies)) {
451         return WIFI_HAL_OPT_FAILED;
452     }
453     return WIFI_HAL_OPT_OK;
454 #endif
455     return WIFI_HAL_OPT_FAILED;
456 }
457 
P2pSetSingleConfig(int networkId,const std::string & key,const std::string & value) const458 WifiErrorNo WifiP2PHalInterface::P2pSetSingleConfig(int networkId,
459     const std::string &key, const std::string &value) const
460 {
461 #ifdef HDI_WPA_INTERFACE_SUPPORT
462     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
463     return mHdiWpaClient->ReqP2pSetSingleConfig(networkId, key, value);
464 #endif
465     return WIFI_HAL_OPT_FAILED;
466 }
467 
P2pSetGroupConfig(int networkId,const HalP2pGroupConfig & config) const468 WifiErrorNo WifiP2PHalInterface::P2pSetGroupConfig(int networkId, const HalP2pGroupConfig &config) const
469 {
470 #ifdef HDI_WPA_INTERFACE_SUPPORT
471     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
472     return mHdiWpaClient->ReqP2pSetGroupConfig(networkId, config);
473 #endif
474     return WIFI_HAL_OPT_FAILED;
475 }
476 
P2pGetGroupConfig(int networkId,HalP2pGroupConfig & config) const477 WifiErrorNo WifiP2PHalInterface::P2pGetGroupConfig(int networkId, HalP2pGroupConfig &config) const
478 {
479 #ifdef HDI_WPA_INTERFACE_SUPPORT
480     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
481     return mHdiWpaClient->ReqP2pGetGroupConfig(networkId, config);
482 #endif
483     return WIFI_HAL_OPT_FAILED;
484 }
485 
P2pAddNetwork(int & networkId) const486 WifiErrorNo WifiP2PHalInterface::P2pAddNetwork(int &networkId) const
487 {
488 #ifdef HDI_WPA_INTERFACE_SUPPORT
489     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
490     return mHdiWpaClient->ReqP2pAddNetwork(networkId);
491 #endif
492     return WIFI_HAL_OPT_FAILED;
493 }
494 
GetP2pCallbackInst(void) const495 const P2pHalCallback &WifiP2PHalInterface::GetP2pCallbackInst(void) const
496 {
497     return mP2pCallback;
498 }
499 
Hid2dConnect(const Hid2dConnectConfig & config) const500 WifiErrorNo WifiP2PHalInterface::Hid2dConnect(const Hid2dConnectConfig &config) const
501 {
502 #ifdef HDI_WPA_INTERFACE_SUPPORT
503     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
504     return mHdiWpaClient->ReqP2pHid2dConnect(config);
505 #endif
506     return WIFI_HAL_OPT_FAILED;
507 }
508 
DeliverP2pData(int32_t cmdType,int32_t dataType,const std::string & carryData) const509 WifiErrorNo WifiP2PHalInterface::DeliverP2pData(int32_t cmdType, int32_t dataType, const std::string& carryData) const
510 {
511 #ifdef HDI_WPA_INTERFACE_SUPPORT
512     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
513     return mHdiWpaClient->DeliverP2pData(cmdType, dataType, carryData.c_str());
514 #endif
515     return WIFI_HAL_OPT_FAILED;
516 }
517 
SetRptBlockList(const std::string & ifaceName,const std::string & interfaceName,const std::vector<std::string> & blockList)518 WifiErrorNo WifiP2PHalInterface::SetRptBlockList(const std::string &ifaceName, const std::string &interfaceName,
519     const std::vector<std::string> &blockList)
520 {
521 #ifdef HDI_CHIP_INTERFACE_SUPPORT
522     if (!HalDeviceManager::GetInstance().SetBlockList(ifaceName, interfaceName, blockList)) {
523         return WIFI_HAL_OPT_FAILED;
524     }
525     return WIFI_HAL_OPT_OK;
526 #endif
527     return WIFI_HAL_OPT_FAILED;
528 }
529 
DisAssociateSta(const std::string & ifaceName,const std::string & interfaceName,const std::string & mac)530 WifiErrorNo WifiP2PHalInterface::DisAssociateSta(const std::string &ifaceName, const std::string &interfaceName,
531     const std::string &mac)
532 {
533 #ifdef HDI_CHIP_INTERFACE_SUPPORT
534     if (!HalDeviceManager::GetInstance().DisAssociateSta(ifaceName, interfaceName, mac)) {
535         return WIFI_HAL_OPT_FAILED;
536     }
537     return WIFI_HAL_OPT_OK;
538 #endif
539     return WIFI_HAL_OPT_FAILED;
540 }
541 
P2pReject(const std::string & mac)542 WifiErrorNo WifiP2PHalInterface::P2pReject(const std::string &mac)
543 {
544 #ifdef HDI_WPA_INTERFACE_SUPPORT
545     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
546     return mHdiWpaClient->P2pReject(mac);
547 #endif
548     return WIFI_HAL_OPT_FAILED;
549 }
550 
SetMiracastSinkConfig(const std::string & config)551 WifiErrorNo WifiP2PHalInterface::SetMiracastSinkConfig(const std::string& config)
552 {
553 #ifdef HDI_WPA_INTERFACE_SUPPORT
554     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
555     return mHdiWpaClient->SetMiracastSinkConfig(config);
556 #endif
557     return WIFI_HAL_OPT_FAILED;
558 }
559 
P2pSetTempConfig(int networkId,const HalP2pGroupConfig & config) const560 WifiErrorNo WifiP2PHalInterface::P2pSetTempConfig(int networkId, const HalP2pGroupConfig &config) const
561 {
562 #ifdef HDI_WPA_INTERFACE_SUPPORT
563     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
564     return mHdiWpaClient->P2pSetTempConfig(networkId, config);
565 #endif
566     return WIFI_HAL_OPT_FAILED;
567 }
568 
TempGroupAdd(int freq)569 WifiErrorNo WifiP2PHalInterface::TempGroupAdd(int freq)
570 {
571 #ifdef HDI_WPA_INTERFACE_SUPPORT
572     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
573     return mHdiWpaClient->P2pTempGroupAdd(freq);
574 #endif
575     return WIFI_HAL_OPT_FAILED;
576 }
577 
SetP2pHighPerf(bool isEnable)578 WifiErrorNo WifiP2PHalInterface::SetP2pHighPerf(bool isEnable)
579 {
580 #ifdef HDI_WPA_INTERFACE_SUPPORT
581     std::string ifName = WifiConfigCenter::GetInstance().GetP2pIfaceName();
582     if (!HalDeviceManager::GetInstance().SetP2pHighPerf(ifName, isEnable)) {
583         return WIFI_HAL_OPT_FAILED;
584     }
585     return WIFI_HAL_OPT_OK;
586 #endif
587     return WIFI_HAL_OPT_FAILED;
588 }
589 }  // namespace Wifi
590 }  // namespace OHOS