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 <mutex>
19 
20 #undef LOG_TAG
21 #define LOG_TAG "WifiP2PHalInterface"
22 
23 namespace OHOS {
24 namespace Wifi {
GetInstance(void)25 WifiP2PHalInterface &WifiP2PHalInterface::GetInstance(void)
26 {
27     static WifiP2PHalInterface inst;
28     static int initFlag = 0;
29     static std::mutex initMutex;
30     if (initFlag == 0) {
31         std::unique_lock<std::mutex> lock(initMutex);
32         if (initFlag == 0) {
33 #ifdef HDI_WPA_INTERFACE_SUPPORT
34             if (inst.InitHdiWpaClient()) {
35                 initFlag = 1;
36             }
37 #else
38             if (inst.InitIdlClient()) {
39                 initFlag = 1;
40             }
41 #endif
42         }
43     }
44     return inst;
45 }
46 
StartP2p(const std::string & ifaceName,const bool hasPersisentGroup) const47 WifiErrorNo WifiP2PHalInterface::StartP2p(const std::string &ifaceName, const bool hasPersisentGroup) const
48 {
49 #ifdef HDI_WPA_INTERFACE_SUPPORT
50     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
51     return mHdiWpaClient->ReqP2pStart(ifaceName, hasPersisentGroup);
52 #else
53     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
54     return mIdlClient->ReqP2pStart();
55 #endif
56 }
57 
StopP2p(void) const58 WifiErrorNo WifiP2PHalInterface::StopP2p(void) const
59 {
60 #ifdef HDI_WPA_INTERFACE_SUPPORT
61     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
62     return mHdiWpaClient->ReqP2pStop();
63 #else
64     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
65     return mIdlClient->ReqP2pStop();
66 #endif
67 }
68 
RegisterP2pCallback(const P2pHalCallback & callbacks)69 WifiErrorNo WifiP2PHalInterface::RegisterP2pCallback(const P2pHalCallback &callbacks)
70 {
71 #ifdef HDI_WPA_INTERFACE_SUPPORT
72     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
73     WifiErrorNo err = mHdiWpaClient->ReqP2pRegisterCallback(callbacks);
74 #else
75     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
76     WifiErrorNo err = mIdlClient->ReqP2pRegisterCallback(callbacks);
77 #endif
78     if (err == WIFI_HAL_OPT_OK || callbacks.onConnectSupplicant == nullptr) {
79         mP2pCallback = callbacks;
80     }
81     return err;
82 }
83 
StartWpsPbc(const std::string & groupInterface,const std::string & bssid) const84 WifiErrorNo WifiP2PHalInterface::StartWpsPbc(const std::string &groupInterface, const std::string &bssid) const
85 {
86 #ifdef HDI_WPA_INTERFACE_SUPPORT
87     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
88     return mHdiWpaClient->ReqP2pSetupWpsPbc(groupInterface, bssid);
89 #else
90     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
91     return mIdlClient->ReqP2pSetupWpsPbc(groupInterface, bssid);
92 #endif
93 }
94 
StartWpsPin(const std::string & groupInterface,const std::string & address,const std::string & pin,std::string & result) const95 WifiErrorNo WifiP2PHalInterface::StartWpsPin(
96     const std::string &groupInterface, const std::string &address, const std::string &pin, std::string &result) const
97 {
98 #ifdef HDI_WPA_INTERFACE_SUPPORT
99     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
100     return mHdiWpaClient->ReqP2pSetupWpsPin(groupInterface, address, pin, result);
101 #else
102     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
103     return mIdlClient->ReqP2pSetupWpsPin(groupInterface, address, pin, result);
104 #endif
105 }
106 
RemoveNetwork(int networkId) const107 WifiErrorNo WifiP2PHalInterface::RemoveNetwork(int networkId) const
108 {
109 #ifdef HDI_WPA_INTERFACE_SUPPORT
110     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
111     return mHdiWpaClient->ReqP2pRemoveNetwork(networkId);
112 #else
113     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
114     return mIdlClient->ReqP2pRemoveNetwork(networkId);
115 #endif
116 }
117 
ListNetworks(std::map<int,WifiP2pGroupInfo> & mapGroups) const118 WifiErrorNo WifiP2PHalInterface::ListNetworks(std::map<int, WifiP2pGroupInfo> &mapGroups) const
119 {
120 #ifdef HDI_WPA_INTERFACE_SUPPORT
121     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
122     return mHdiWpaClient->ReqP2pListNetworks(mapGroups);
123 #else
124     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
125     return mIdlClient->ReqP2pListNetworks(mapGroups);
126 #endif
127 }
128 
SetP2pDeviceName(const std::string & name) const129 WifiErrorNo WifiP2PHalInterface::SetP2pDeviceName(const std::string &name) const
130 {
131 #ifdef HDI_WPA_INTERFACE_SUPPORT
132     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
133     return mHdiWpaClient->ReqP2pSetDeviceName(name);
134 #else
135     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
136     return mIdlClient->ReqP2pSetDeviceName(name);
137 #endif
138 }
139 
SetP2pDeviceType(const std::string & type) const140 WifiErrorNo WifiP2PHalInterface::SetP2pDeviceType(const std::string &type) const
141 {
142 #ifdef HDI_WPA_INTERFACE_SUPPORT
143     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
144     return mHdiWpaClient->ReqP2pSetWpsDeviceType(type);
145 #else
146     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
147     return mIdlClient->ReqP2pSetWpsDeviceType(type);
148 #endif
149 }
150 
SetP2pSecondaryDeviceType(const std::string & type)151 WifiErrorNo WifiP2PHalInterface::SetP2pSecondaryDeviceType(const std::string &type)
152 {
153 #ifdef HDI_WPA_INTERFACE_SUPPORT
154     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
155     return mHdiWpaClient->ReqP2pSetWpsSecondaryDeviceType(type);
156 #else
157     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
158     return mIdlClient->ReqP2pSetWpsSecondaryDeviceType(type);
159 #endif
160 }
161 
SetP2pConfigMethods(const std::string & methods) const162 WifiErrorNo WifiP2PHalInterface::SetP2pConfigMethods(const std::string &methods) const
163 {
164 #ifdef HDI_WPA_INTERFACE_SUPPORT
165     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
166     return mHdiWpaClient->ReqP2pSetWpsConfigMethods(methods);
167 #else
168     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
169     return mIdlClient->ReqP2pSetWpsConfigMethods(methods);
170 #endif
171 }
172 
SetP2pSsidPostfix(const std::string & postfixName) const173 WifiErrorNo WifiP2PHalInterface::SetP2pSsidPostfix(const std::string &postfixName) const
174 {
175 #ifdef HDI_WPA_INTERFACE_SUPPORT
176     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
177     return mHdiWpaClient->ReqP2pSetSsidPostfixName(postfixName);
178 #else
179     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
180     return mIdlClient->ReqP2pSetSsidPostfixName(postfixName);
181 #endif
182 }
183 
SetP2pGroupIdle(const std::string & groupInterface,size_t time) const184 WifiErrorNo WifiP2PHalInterface::SetP2pGroupIdle(const std::string &groupInterface, size_t time) const
185 {
186 #ifdef HDI_WPA_INTERFACE_SUPPORT
187     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
188     return mHdiWpaClient->ReqP2pSetGroupMaxIdle(groupInterface, time);
189 #else
190     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
191     return mIdlClient->ReqP2pSetGroupMaxIdle(groupInterface, time);
192 #endif
193 }
194 
SetP2pPowerSave(const std::string & groupInterface,bool enable) const195 WifiErrorNo WifiP2PHalInterface::SetP2pPowerSave(const std::string &groupInterface, bool enable) const
196 {
197 #ifdef HDI_WPA_INTERFACE_SUPPORT
198     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
199     return mHdiWpaClient->ReqP2pSetPowerSave(groupInterface, enable);
200 #else
201     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
202     return mIdlClient->ReqP2pSetPowerSave(groupInterface, enable);
203 #endif
204 }
205 
SetWfdEnable(bool enable) const206 WifiErrorNo WifiP2PHalInterface::SetWfdEnable(bool enable) const
207 {
208 #ifdef HDI_WPA_INTERFACE_SUPPORT
209     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
210     return mHdiWpaClient->ReqP2pSetWfdEnable(enable);
211 #else
212     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
213     return mIdlClient->ReqP2pSetWfdEnable(enable);
214 #endif
215 }
216 
SetWfdDeviceConfig(const std::string & config) const217 WifiErrorNo WifiP2PHalInterface::SetWfdDeviceConfig(const std::string &config) const
218 {
219 #ifdef HDI_WPA_INTERFACE_SUPPORT
220     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
221     return mHdiWpaClient->ReqP2pSetWfdDeviceConfig(config);
222 #else
223     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
224     return mIdlClient->ReqP2pSetWfdDeviceConfig(config);
225 #endif
226 }
227 
P2pFind(size_t timeout) const228 WifiErrorNo WifiP2PHalInterface::P2pFind(size_t timeout) const
229 {
230 #ifdef HDI_WPA_INTERFACE_SUPPORT
231     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
232     return mHdiWpaClient->ReqP2pStartFind(timeout);
233 #else
234     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
235     return mIdlClient->ReqP2pStartFind(timeout);
236 #endif
237 }
238 
P2pStopFind() const239 WifiErrorNo WifiP2PHalInterface::P2pStopFind() const
240 {
241 #ifdef HDI_WPA_INTERFACE_SUPPORT
242     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
243     return mHdiWpaClient->ReqP2pStopFind();
244 #else
245     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
246     return mIdlClient->ReqP2pStopFind();
247 #endif
248 }
249 
P2pConfigureListen(bool enable,size_t period,size_t interval) const250 WifiErrorNo WifiP2PHalInterface::P2pConfigureListen(bool enable, size_t period, size_t interval) const
251 {
252 #ifdef HDI_WPA_INTERFACE_SUPPORT
253     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
254     return mHdiWpaClient->ReqP2pSetExtListen(enable, period, interval);
255 #else
256     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
257     return mIdlClient->ReqP2pSetExtListen(enable, period, interval);
258 #endif
259 }
260 
SetListenChannel(size_t channel,unsigned char regClass) const261 WifiErrorNo WifiP2PHalInterface::SetListenChannel(size_t channel, unsigned char regClass) const
262 {
263 #ifdef HDI_WPA_INTERFACE_SUPPORT
264     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
265     return mHdiWpaClient->ReqP2pSetListenChannel(channel, regClass);
266 #else
267     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
268     return mIdlClient->ReqP2pSetListenChannel(channel, regClass);
269 #endif
270 }
271 
P2pFlush() const272 WifiErrorNo WifiP2PHalInterface::P2pFlush() const
273 {
274 #ifdef HDI_WPA_INTERFACE_SUPPORT
275     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
276     return mHdiWpaClient->ReqP2pFlush();
277 #else
278     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
279     return mIdlClient->ReqP2pFlush();
280 #endif
281 }
282 
Connect(const WifiP2pConfigInternal & config,bool isJoinExistingGroup,std::string & pin) const283 WifiErrorNo WifiP2PHalInterface::Connect(const WifiP2pConfigInternal &config, bool isJoinExistingGroup,
284     std::string &pin) const
285 {
286 #ifdef HDI_WPA_INTERFACE_SUPPORT
287     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
288     return mHdiWpaClient->ReqP2pConnect(config, isJoinExistingGroup, pin);
289 #else
290     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
291     return mIdlClient->ReqP2pConnect(config, isJoinExistingGroup, pin);
292 #endif
293 }
294 
CancelConnect() const295 WifiErrorNo WifiP2PHalInterface::CancelConnect() const
296 {
297 #ifdef HDI_WPA_INTERFACE_SUPPORT
298     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
299     return mHdiWpaClient->ReqP2pCancelConnect();
300 #else
301     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
302     return mIdlClient->ReqP2pCancelConnect();
303 #endif
304 }
305 
ProvisionDiscovery(const WifiP2pConfigInternal & config) const306 WifiErrorNo WifiP2PHalInterface::ProvisionDiscovery(const WifiP2pConfigInternal &config) const
307 {
308 #ifdef HDI_WPA_INTERFACE_SUPPORT
309     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
310     return mHdiWpaClient->ReqP2pProvisionDiscovery(config);
311 #else
312     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
313     return mIdlClient->ReqP2pProvisionDiscovery(config);
314 #endif
315 }
316 
GroupAdd(bool isPersistent,int networkId,int freq) const317 WifiErrorNo WifiP2PHalInterface::GroupAdd(bool isPersistent, int networkId, int freq) const
318 {
319 #ifdef HDI_WPA_INTERFACE_SUPPORT
320     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
321     return mHdiWpaClient->ReqP2pAddGroup(isPersistent, networkId, freq);
322 #else
323     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
324     return mIdlClient->ReqP2pAddGroup(isPersistent, networkId, freq);
325 #endif
326 }
327 
GroupRemove(const std::string & groupInterface) const328 WifiErrorNo WifiP2PHalInterface::GroupRemove(const std::string &groupInterface) const
329 {
330 #ifdef HDI_WPA_INTERFACE_SUPPORT
331     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
332     return mHdiWpaClient->ReqP2pRemoveGroup(groupInterface);
333 #else
334     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
335     return mIdlClient->ReqP2pRemoveGroup(groupInterface);
336 #endif
337 }
338 
GroupClientRemove(const std::string & deviceMac) const339 WifiErrorNo WifiP2PHalInterface::GroupClientRemove(const std::string &deviceMac) const
340 {
341 #ifdef HDI_WPA_INTERFACE_SUPPORT
342     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
343     return mHdiWpaClient->ReqP2pRemoveGroupClient(deviceMac);
344 #else
345     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
346     return mIdlClient->ReqP2pRemoveGroupClient(deviceMac);
347 #endif
348 }
349 
Invite(const WifiP2pGroupInfo & group,const std::string & deviceAddr) const350 WifiErrorNo WifiP2PHalInterface::Invite(const WifiP2pGroupInfo &group, const std::string &deviceAddr) const
351 {
352 #ifdef HDI_WPA_INTERFACE_SUPPORT
353     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
354     return mHdiWpaClient->ReqP2pInvite(group, deviceAddr);
355 #else
356     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
357     return mIdlClient->ReqP2pInvite(group, deviceAddr);
358 #endif
359 }
360 
Reinvoke(int networkId,const std::string & deviceAddr) const361 WifiErrorNo WifiP2PHalInterface::Reinvoke(int networkId, const std::string &deviceAddr) const
362 {
363 #ifdef HDI_WPA_INTERFACE_SUPPORT
364     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
365     return mHdiWpaClient->ReqP2pReinvoke(networkId, deviceAddr);
366 #else
367     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
368     return mIdlClient->ReqP2pReinvoke(networkId, deviceAddr);
369 #endif
370 }
371 
GetDeviceAddress(std::string & deviceAddress) const372 WifiErrorNo WifiP2PHalInterface::GetDeviceAddress(std::string &deviceAddress) const
373 {
374 #ifdef HDI_WPA_INTERFACE_SUPPORT
375     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
376     return mHdiWpaClient->ReqP2pGetDeviceAddress(deviceAddress);
377 #else
378     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
379     return mIdlClient->ReqP2pGetDeviceAddress(deviceAddress);
380 #endif
381 }
382 
GetGroupCapability(const std::string & deviceAddress,uint32_t & cap) const383 WifiErrorNo WifiP2PHalInterface::GetGroupCapability(const std::string &deviceAddress, uint32_t &cap) const
384 {
385 #ifdef HDI_WPA_INTERFACE_SUPPORT
386     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
387     return mHdiWpaClient->ReqP2pGetGroupCapability(deviceAddress, cap);
388 #else
389     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
390     return mIdlClient->ReqP2pGetGroupCapability(deviceAddress, cap);
391 #endif
392 }
393 
P2pServiceAdd(const WifiP2pServiceInfo & info) const394 WifiErrorNo WifiP2PHalInterface::P2pServiceAdd(const WifiP2pServiceInfo &info) const
395 {
396 #ifdef HDI_WPA_INTERFACE_SUPPORT
397     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
398     return mHdiWpaClient->ReqP2pAddService(info);
399 #else
400     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
401     return mIdlClient->ReqP2pAddService(info);
402 #endif
403 }
404 
P2pServiceRemove(const WifiP2pServiceInfo & info) const405 WifiErrorNo WifiP2PHalInterface::P2pServiceRemove(const WifiP2pServiceInfo &info) const
406 {
407 #ifdef HDI_WPA_INTERFACE_SUPPORT
408     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
409     return mHdiWpaClient->ReqP2pRemoveService(info);
410 #else
411     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
412     return mIdlClient->ReqP2pRemoveService(info);
413 #endif
414 }
415 
FlushService() const416 WifiErrorNo WifiP2PHalInterface::FlushService() const
417 {
418 #ifdef HDI_WPA_INTERFACE_SUPPORT
419     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
420     return mHdiWpaClient->ReqP2pFlushService();
421 #else
422     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
423     return mIdlClient->ReqP2pFlushService();
424 #endif
425 }
426 
SaveConfig() const427 WifiErrorNo WifiP2PHalInterface::SaveConfig() const
428 {
429 #ifdef HDI_WPA_INTERFACE_SUPPORT
430     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
431     return mHdiWpaClient->ReqP2pSaveConfig();
432 #else
433     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
434     return mIdlClient->ReqP2pSaveConfig();
435 #endif
436 }
437 
ReqServiceDiscovery(const std::string & deviceAddress,const std::vector<unsigned char> & tlvs,std::string & reqID) const438 WifiErrorNo WifiP2PHalInterface::ReqServiceDiscovery(
439     const std::string &deviceAddress, const std::vector<unsigned char> &tlvs, std::string &reqID) const
440 {
441 #ifdef HDI_WPA_INTERFACE_SUPPORT
442     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
443     return mHdiWpaClient->ReqP2pReqServiceDiscovery(deviceAddress, tlvs, reqID);
444 #else
445     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
446     return mIdlClient->ReqP2pReqServiceDiscovery(deviceAddress, tlvs, reqID);
447 #endif
448 }
449 
CancelReqServiceDiscovery(const std::string & id) const450 WifiErrorNo WifiP2PHalInterface::CancelReqServiceDiscovery(const std::string &id) const
451 {
452 #ifdef HDI_WPA_INTERFACE_SUPPORT
453     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
454     return mHdiWpaClient->ReqP2pCancelServiceDiscovery(id);
455 #else
456     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
457     return mIdlClient->ReqP2pCancelServiceDiscovery(id);
458 #endif
459 }
460 
SetRandomMacAddr(bool enable) const461 WifiErrorNo WifiP2PHalInterface::SetRandomMacAddr(bool enable) const
462 {
463 #ifdef HDI_WPA_INTERFACE_SUPPORT
464     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
465     return mHdiWpaClient->ReqP2pSetRandomMac(enable);
466 #else
467     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
468     return mIdlClient->ReqP2pSetRandomMac(enable);
469 #endif
470 }
471 
SetMiracastMode(int type) const472 WifiErrorNo WifiP2PHalInterface::SetMiracastMode(int type) const
473 {
474 #ifdef HDI_WPA_INTERFACE_SUPPORT
475     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
476     return mHdiWpaClient->ReqP2pSetMiracastType(type);
477 #else
478     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
479     return mIdlClient->ReqP2pSetMiracastType(type);
480 #endif
481 }
482 
SetPersistentReconnect(int mode) const483 WifiErrorNo WifiP2PHalInterface::SetPersistentReconnect(int mode) const
484 {
485 #ifdef HDI_WPA_INTERFACE_SUPPORT
486     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
487     return mHdiWpaClient->ReqSetPersistentReconnect(mode);
488 #else
489     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
490     return mIdlClient->ReqSetPersistentReconnect(mode);
491 #endif
492 }
493 
RespServiceDiscovery(const WifiP2pDevice & device,int frequency,int dialogToken,const std::vector<unsigned char> & tlvs) const494 WifiErrorNo WifiP2PHalInterface::RespServiceDiscovery(
495     const WifiP2pDevice &device, int frequency, int dialogToken, const std::vector<unsigned char> &tlvs) const
496 {
497 #ifdef HDI_WPA_INTERFACE_SUPPORT
498     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
499     return mHdiWpaClient->ReqRespServiceDiscovery(device, frequency, dialogToken, tlvs);
500 #else
501     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
502     return mIdlClient->ReqRespServiceDiscovery(device, frequency, dialogToken, tlvs);
503 #endif
504 }
505 
SetServiceDiscoveryExternal(bool isExternalProcess) const506 WifiErrorNo WifiP2PHalInterface::SetServiceDiscoveryExternal(bool isExternalProcess) const
507 {
508 #ifdef HDI_WPA_INTERFACE_SUPPORT
509     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
510     return mHdiWpaClient->ReqSetServiceDiscoveryExternal(isExternalProcess);
511 #else
512     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
513     return mIdlClient->ReqSetServiceDiscoveryExternal(isExternalProcess);
514 #endif
515 }
516 
GetP2pPeer(const std::string & deviceAddress,WifiP2pDevice & device) const517 WifiErrorNo WifiP2PHalInterface::GetP2pPeer(const std::string &deviceAddress, WifiP2pDevice &device) const
518 {
519 #ifdef HDI_WPA_INTERFACE_SUPPORT
520     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
521     return mHdiWpaClient->ReqGetP2pPeer(deviceAddress, device);
522 #else
523     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
524     return mIdlClient->ReqGetP2pPeer(deviceAddress, device);
525 #endif
526 }
527 
GetChba0Freq(int & chba0Freq) const528 WifiErrorNo WifiP2PHalInterface::GetChba0Freq(int &chba0Freq) const
529 {
530 #ifdef HDI_WPA_INTERFACE_SUPPORT
531     LOGE("call WifiP2PHalInterface::%{public}s!", __func__);
532     return WIFI_HAL_OPT_FAILED;
533 #else
534     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
535     return mIdlClient->ReqP2pGetChba0Freq(chba0Freq);
536 #endif
537 }
538 
P2pGetSupportFrequenciesByBand(int band,std::vector<int> & frequencies) const539 WifiErrorNo WifiP2PHalInterface::P2pGetSupportFrequenciesByBand(int band, std::vector<int> &frequencies) const
540 {
541 #ifdef HDI_WPA_INTERFACE_SUPPORT
542     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
543     return mHdiWpaClient->ReqP2pGetSupportFrequencies(band, frequencies);
544 #else
545     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
546     return mIdlClient->ReqP2pGetSupportFrequencies(band, frequencies);
547 #endif
548 }
549 
P2pSetGroupConfig(int networkId,const HalP2pGroupConfig & config) const550 WifiErrorNo WifiP2PHalInterface::P2pSetGroupConfig(int networkId, const HalP2pGroupConfig &config) const
551 {
552 #ifdef HDI_WPA_INTERFACE_SUPPORT
553     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
554     return mHdiWpaClient->ReqP2pSetGroupConfig(networkId, config);
555 #else
556     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
557     return mIdlClient->ReqP2pSetGroupConfig(networkId, config);
558 #endif
559 }
560 
P2pGetGroupConfig(int networkId,HalP2pGroupConfig & config) const561 WifiErrorNo WifiP2PHalInterface::P2pGetGroupConfig(int networkId, HalP2pGroupConfig &config) const
562 {
563 #ifdef HDI_WPA_INTERFACE_SUPPORT
564     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
565     return mHdiWpaClient->ReqP2pGetGroupConfig(networkId, config);
566 #else
567     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
568     return mIdlClient->ReqP2pGetGroupConfig(networkId, config);
569 #endif
570 }
571 
P2pAddNetwork(int & networkId) const572 WifiErrorNo WifiP2PHalInterface::P2pAddNetwork(int &networkId) const
573 {
574 #ifdef HDI_WPA_INTERFACE_SUPPORT
575     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
576     return mHdiWpaClient->ReqP2pAddNetwork(networkId);
577 #else
578     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
579     return mIdlClient->ReqP2pAddNetwork(networkId);
580 #endif
581 }
582 
GetP2pCallbackInst(void) const583 const P2pHalCallback &WifiP2PHalInterface::GetP2pCallbackInst(void) const
584 {
585     return mP2pCallback;
586 }
587 
Hid2dConnect(const Hid2dConnectConfig & config) const588 WifiErrorNo WifiP2PHalInterface::Hid2dConnect(const Hid2dConnectConfig &config) const
589 {
590 #ifdef HDI_WPA_INTERFACE_SUPPORT
591     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
592     return mHdiWpaClient->ReqP2pHid2dConnect(config);
593 #else
594     CHECK_NULL_AND_RETURN(mIdlClient, WIFI_HAL_OPT_FAILED);
595     return mIdlClient->ReqP2pHid2dConnect(config);
596 #endif
597 }
598 
DeliverP2pData(int32_t cmdType,int32_t dataType,const std::string & carryData) const599 WifiErrorNo WifiP2PHalInterface::DeliverP2pData(int32_t cmdType, int32_t dataType, const std::string& carryData) const
600 {
601 #ifdef HDI_WPA_INTERFACE_SUPPORT
602     CHECK_NULL_AND_RETURN(mHdiWpaClient, WIFI_HAL_OPT_FAILED);
603     return mHdiWpaClient->DeliverP2pData(cmdType, dataType, carryData.c_str());
604 #else
605     LOGE("DeliverP2pData enter Ipc");
606     return WIFI_HAL_OPT_FAILED;
607 #endif
608 }
609 }  // namespace Wifi
610 }  // namespace OHOS