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_device_impl.h"
17 #include <new>
18 #ifndef OHOS_ARCH_LITE
19 #include "iremote_broker.h"
20 #include "iremote_object.h"
21 #include "iservice_registry.h"
22 #include "wifi_sa_manager.h"
23 #endif
24 #include "wifi_device_proxy.h"
25 #include "wifi_device_mgr_proxy.h"
26 #include "wifi_logger.h"
27 #include "wifi_common_util.h"
28
29 DEFINE_WIFILOG_LABEL("WifiDeviceImpl");
30
31 namespace OHOS {
32 namespace Wifi {
33 #define RETURN_IF_FAIL(cond) \
34 do { \
35 if (!(cond)) { \
36 WIFI_LOGI("'%{public}s' failed.", #cond); \
37 return WIFI_OPT_FAILED; \
38 } \
39 } while (0)
40
WifiDeviceImpl()41 WifiDeviceImpl::WifiDeviceImpl() : systemAbilityId_(0), instId_(0), client_(nullptr)
42 {}
43
~WifiDeviceImpl()44 WifiDeviceImpl::~WifiDeviceImpl()
45 {
46 #ifdef OHOS_ARCH_LITE
47 WifiDeviceProxy::ReleaseInstance();
48 #endif
49 }
50
Init(int systemAbilityId,int instId)51 bool WifiDeviceImpl::Init(int systemAbilityId, int instId)
52 {
53 #ifdef OHOS_ARCH_LITE
54 WifiDeviceProxy *deviceProxy = WifiDeviceProxy::GetInstance();
55 if (deviceProxy == nullptr) {
56 WIFI_LOGE("get wifi device proxy failed.");
57 return false;
58 }
59 if (deviceProxy->Init() != WIFI_OPT_SUCCESS) {
60 WIFI_LOGE("wifi device proxy init failed.");
61 WifiDeviceProxy::ReleaseInstance();
62 return false;
63 }
64 client_ = deviceProxy;
65 return true;
66 #else
67 systemAbilityId_ = systemAbilityId;
68 instId_ = instId;
69 return true;
70 #endif
71 }
72
GetWifiDeviceProxy()73 bool WifiDeviceImpl::GetWifiDeviceProxy()
74 {
75 #ifdef OHOS_ARCH_LITE
76 return (client_ != nullptr);
77 #else
78 WifiSaLoadManager::GetInstance().LoadWifiSa(systemAbilityId_);
79 if (IsRemoteDied() == false) {
80 return true;
81 }
82
83 sptr<ISystemAbilityManager> sa_mgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
84 if (sa_mgr == nullptr) {
85 WIFI_LOGE("failed to get SystemAbilityManager");
86 return false;
87 }
88
89 sptr<IRemoteObject> object = sa_mgr->GetSystemAbility(systemAbilityId_);
90 if (object == nullptr) {
91 WIFI_LOGE("failed to get DEVICE_SERVICE");
92 return false;
93 }
94
95 sptr<IWifiDeviceMgr> deviceMgr = iface_cast<IWifiDeviceMgr>(object);
96 if (deviceMgr == nullptr) {
97 deviceMgr = new (std::nothrow) WifiDeviceMgrProxy(object);
98 }
99 if (deviceMgr == nullptr) {
100 WIFI_LOGE("wifi device init failed, %{public}d", systemAbilityId_.load());
101 return false;
102 }
103
104 sptr<IRemoteObject> service = deviceMgr->GetWifiRemote(instId_);
105 if (service == nullptr) {
106 WIFI_LOGE("wifi device remote obj is null, %{public}d", instId_);
107 return false;
108 }
109
110 client_ = iface_cast<IWifiDevice>(service);
111 if (client_ == nullptr) {
112 client_ = new (std::nothrow) WifiDeviceProxy(service);
113 }
114 if (client_ == nullptr) {
115 WIFI_LOGE("wifi device instId_ %{public}d init failed. %{public}d", instId_, systemAbilityId_.load());
116 return false;
117 }
118 return true;
119 #endif
120 }
121
EnableWifi()122 ErrCode WifiDeviceImpl::EnableWifi()
123 {
124 std::lock_guard<std::mutex> lock(mutex_);
125 RETURN_IF_FAIL(GetWifiDeviceProxy());
126 return client_->EnableWifi();
127 }
128
DisableWifi()129 ErrCode WifiDeviceImpl::DisableWifi()
130 {
131 std::lock_guard<std::mutex> lock(mutex_);
132 RETURN_IF_FAIL(GetWifiDeviceProxy());
133 return client_->DisableWifi();
134 }
135
InitWifiProtect(const WifiProtectType & protectType,const std::string & protectName)136 ErrCode WifiDeviceImpl::InitWifiProtect(const WifiProtectType &protectType, const std::string &protectName)
137 {
138 std::lock_guard<std::mutex> lock(mutex_);
139 RETURN_IF_FAIL(GetWifiDeviceProxy());
140 return client_->InitWifiProtect(protectType, protectName);
141 }
142
GetWifiProtectRef(const WifiProtectMode & protectMode,const std::string & protectName)143 ErrCode WifiDeviceImpl::GetWifiProtectRef(const WifiProtectMode &protectMode, const std::string &protectName)
144 {
145 std::lock_guard<std::mutex> lock(mutex_);
146 RETURN_IF_FAIL(GetWifiDeviceProxy());
147 return client_->GetWifiProtectRef(protectMode, protectName);
148 }
149
PutWifiProtectRef(const std::string & protectName)150 ErrCode WifiDeviceImpl::PutWifiProtectRef(const std::string &protectName)
151 {
152 std::lock_guard<std::mutex> lock(mutex_);
153 RETURN_IF_FAIL(GetWifiDeviceProxy());
154 return client_->PutWifiProtectRef(protectName);
155 }
156
IsHeldWifiProtectRef(const std::string & protectName,bool & isHeld)157 ErrCode WifiDeviceImpl::IsHeldWifiProtectRef(const std::string &protectName, bool &isHeld)
158 {
159 std::lock_guard<std::mutex> lock(mutex_);
160 RETURN_IF_FAIL(GetWifiDeviceProxy());
161 return client_->IsHeldWifiProtectRef(protectName, isHeld);
162 }
163
164 #ifndef OHOS_ARCH_LITE
IsHeldWifiProtect(bool & isHeld)165 ErrCode WifiDeviceImpl::IsHeldWifiProtect(bool &isHeld)
166 {
167 std::string bundleName = GetBundleName();
168 return IsHeldWifiProtectRef(bundleName, isHeld);
169 }
170
GetWifiProtect(const WifiProtectMode & protectMode)171 ErrCode WifiDeviceImpl::GetWifiProtect(const WifiProtectMode &protectMode)
172 {
173 std::string bundleName = GetBundleName();
174 return GetWifiProtectRef(protectMode, bundleName);
175 }
176
PutWifiProtect()177 ErrCode WifiDeviceImpl::PutWifiProtect()
178 {
179 std::string bundleName = GetBundleName();
180 return PutWifiProtectRef(bundleName);
181 }
182 #endif
RemoveCandidateConfig(int networkId)183 ErrCode WifiDeviceImpl::RemoveCandidateConfig(int networkId)
184 {
185 std::lock_guard<std::mutex> lock(mutex_);
186 RETURN_IF_FAIL(GetWifiDeviceProxy());
187 return client_->RemoveCandidateConfig(networkId);
188 }
189
RemoveCandidateConfig(const WifiDeviceConfig & config)190 ErrCode WifiDeviceImpl::RemoveCandidateConfig(const WifiDeviceConfig &config)
191 {
192 std::lock_guard<std::mutex> lock(mutex_);
193 RETURN_IF_FAIL(GetWifiDeviceProxy());
194 return client_->RemoveCandidateConfig(config);
195 }
196
AddDeviceConfig(const WifiDeviceConfig & config,int & result,bool isCandidate)197 ErrCode WifiDeviceImpl::AddDeviceConfig(const WifiDeviceConfig &config, int &result, bool isCandidate)
198 {
199 std::lock_guard<std::mutex> lock(mutex_);
200 RETURN_IF_FAIL(GetWifiDeviceProxy());
201 return client_->AddDeviceConfig(config, result, isCandidate);
202 }
203
UpdateDeviceConfig(const WifiDeviceConfig & config,int & result)204 ErrCode WifiDeviceImpl::UpdateDeviceConfig(const WifiDeviceConfig &config, int &result)
205 {
206 std::lock_guard<std::mutex> lock(mutex_);
207 RETURN_IF_FAIL(GetWifiDeviceProxy());
208 return client_->UpdateDeviceConfig(config, result);
209 }
210
RemoveDevice(int networkId)211 ErrCode WifiDeviceImpl::RemoveDevice(int networkId)
212 {
213 std::lock_guard<std::mutex> lock(mutex_);
214 RETURN_IF_FAIL(GetWifiDeviceProxy());
215 return client_->RemoveDevice(networkId);
216 }
217
RemoveAllDevice()218 ErrCode WifiDeviceImpl::RemoveAllDevice()
219 {
220 std::lock_guard<std::mutex> lock(mutex_);
221 RETURN_IF_FAIL(GetWifiDeviceProxy());
222 return client_->RemoveAllDevice();
223 }
224
SetWifiTxPower(int power)225 ErrCode WifiDeviceImpl::SetWifiTxPower(int power)
226 {
227 std::lock_guard<std::mutex> lock(mutex_);
228 RETURN_IF_FAIL(GetWifiDeviceProxy());
229 return client_->SetTxPower(power);
230 }
231
GetDeviceConfigs(std::vector<WifiDeviceConfig> & result,bool isCandidate)232 ErrCode WifiDeviceImpl::GetDeviceConfigs(std::vector<WifiDeviceConfig> &result, bool isCandidate)
233 {
234 std::lock_guard<std::mutex> lock(mutex_);
235 RETURN_IF_FAIL(GetWifiDeviceProxy());
236 return client_->GetDeviceConfigs(result, isCandidate);
237 }
238
EnableDeviceConfig(int networkId,bool attemptEnable)239 ErrCode WifiDeviceImpl::EnableDeviceConfig(int networkId, bool attemptEnable)
240 {
241 std::lock_guard<std::mutex> lock(mutex_);
242 RETURN_IF_FAIL(GetWifiDeviceProxy());
243 return client_->EnableDeviceConfig(networkId, attemptEnable);
244 }
245
DisableDeviceConfig(int networkId)246 ErrCode WifiDeviceImpl::DisableDeviceConfig(int networkId)
247 {
248 std::lock_guard<std::mutex> lock(mutex_);
249 RETURN_IF_FAIL(GetWifiDeviceProxy());
250 return client_->DisableDeviceConfig(networkId);
251 }
252
AllowAutoConnect(int32_t networkId,bool isAllowed)253 ErrCode WifiDeviceImpl::AllowAutoConnect(int32_t networkId, bool isAllowed)
254 {
255 std::lock_guard<std::mutex> lock(mutex_);
256 RETURN_IF_FAIL(GetWifiDeviceProxy());
257 return client_->AllowAutoConnect(networkId, isAllowed);
258 }
259
ConnectToNetwork(int networkId,bool isCandidate)260 ErrCode WifiDeviceImpl::ConnectToNetwork(int networkId, bool isCandidate)
261 {
262 std::lock_guard<std::mutex> lock(mutex_);
263 RETURN_IF_FAIL(GetWifiDeviceProxy());
264 return client_->ConnectToNetwork(networkId, isCandidate);
265 }
266
ConnectToDevice(const WifiDeviceConfig & config)267 ErrCode WifiDeviceImpl::ConnectToDevice(const WifiDeviceConfig &config)
268 {
269 std::lock_guard<std::mutex> lock(mutex_);
270 RETURN_IF_FAIL(GetWifiDeviceProxy());
271 return client_->ConnectToDevice(config);
272 }
273
IsConnected(bool & isConnected)274 ErrCode WifiDeviceImpl::IsConnected(bool &isConnected)
275 {
276 std::lock_guard<std::mutex> lock(mutex_);
277 RETURN_IF_FAIL(GetWifiDeviceProxy());
278 return client_->IsConnected(isConnected);
279 }
280
ReConnect()281 ErrCode WifiDeviceImpl::ReConnect()
282 {
283 std::lock_guard<std::mutex> lock(mutex_);
284 RETURN_IF_FAIL(GetWifiDeviceProxy());
285 return client_->ReConnect();
286 }
287
ReAssociate()288 ErrCode WifiDeviceImpl::ReAssociate()
289 {
290 std::lock_guard<std::mutex> lock(mutex_);
291 RETURN_IF_FAIL(GetWifiDeviceProxy());
292 return client_->ReAssociate();
293 }
294
Disconnect()295 ErrCode WifiDeviceImpl::Disconnect()
296 {
297 std::lock_guard<std::mutex> lock(mutex_);
298 RETURN_IF_FAIL(GetWifiDeviceProxy());
299 return client_->Disconnect();
300 }
301
StartWps(const WpsConfig & config)302 ErrCode WifiDeviceImpl::StartWps(const WpsConfig &config)
303 {
304 std::lock_guard<std::mutex> lock(mutex_);
305 RETURN_IF_FAIL(GetWifiDeviceProxy());
306 return client_->StartWps(config);
307 }
308
CancelWps()309 ErrCode WifiDeviceImpl::CancelWps()
310 {
311 std::lock_guard<std::mutex> lock(mutex_);
312 RETURN_IF_FAIL(GetWifiDeviceProxy());
313 return client_->CancelWps();
314 }
315
IsWifiActive(bool & bActive)316 ErrCode WifiDeviceImpl::IsWifiActive(bool &bActive)
317 {
318 std::lock_guard<std::mutex> lock(mutex_);
319 RETURN_IF_FAIL(GetWifiDeviceProxy());
320 return client_->IsWifiActive(bActive);
321 }
322
GetWifiState(int & state)323 ErrCode WifiDeviceImpl::GetWifiState(int &state)
324 {
325 std::lock_guard<std::mutex> lock(mutex_);
326 RETURN_IF_FAIL(GetWifiDeviceProxy());
327 return client_->GetWifiState(state);
328 }
329
GetLinkedInfo(WifiLinkedInfo & info)330 ErrCode WifiDeviceImpl::GetLinkedInfo(WifiLinkedInfo &info)
331 {
332 std::lock_guard<std::mutex> lock(mutex_);
333 RETURN_IF_FAIL(GetWifiDeviceProxy());
334 return client_->GetLinkedInfo(info);
335 }
336
GetSignalPollInfoArray(std::vector<WifiSignalPollInfo> & wifiSignalPollInfos,int length)337 ErrCode WifiDeviceImpl::GetSignalPollInfoArray(std::vector<WifiSignalPollInfo> &wifiSignalPollInfos, int length)
338 {
339 std::lock_guard<std::mutex> lock(mutex_);
340 RETURN_IF_FAIL(GetWifiDeviceProxy());
341 return client_->GetSignalPollInfoArray(wifiSignalPollInfos, length);
342 }
343
GetDisconnectedReason(DisconnectedReason & reason)344 ErrCode WifiDeviceImpl::GetDisconnectedReason(DisconnectedReason &reason)
345 {
346 RETURN_IF_FAIL(GetWifiDeviceProxy());
347 return client_->GetDisconnectedReason(reason);
348 }
349
IsMeteredHotspot(bool & bMeteredHotspot)350 ErrCode WifiDeviceImpl::IsMeteredHotspot(bool &bMeteredHotspot)
351 {
352 std::lock_guard<std::mutex> lock(mutex_);
353 RETURN_IF_FAIL(GetWifiDeviceProxy());
354 return client_->IsMeteredHotspot(bMeteredHotspot);
355 }
356
GetIpInfo(IpInfo & info)357 ErrCode WifiDeviceImpl::GetIpInfo(IpInfo &info)
358 {
359 std::lock_guard<std::mutex> lock(mutex_);
360 RETURN_IF_FAIL(GetWifiDeviceProxy());
361 return client_->GetIpInfo(info);
362 }
363
GetIpv6Info(IpV6Info & info)364 ErrCode WifiDeviceImpl::GetIpv6Info(IpV6Info &info)
365 {
366 std::lock_guard<std::mutex> lock(mutex_);
367 RETURN_IF_FAIL(GetWifiDeviceProxy());
368 return client_->GetIpv6Info(info);
369 }
370
SetCountryCode(const std::string & countryCode)371 ErrCode WifiDeviceImpl::SetCountryCode(const std::string &countryCode)
372 {
373 std::lock_guard<std::mutex> lock(mutex_);
374 RETURN_IF_FAIL(GetWifiDeviceProxy());
375 return client_->SetCountryCode(countryCode);
376 }
377
GetCountryCode(std::string & countryCode)378 ErrCode WifiDeviceImpl::GetCountryCode(std::string &countryCode)
379 {
380 std::lock_guard<std::mutex> lock(mutex_);
381 RETURN_IF_FAIL(GetWifiDeviceProxy());
382 return client_->GetCountryCode(countryCode);
383 }
384
GetSignalLevel(const int & rssi,const int & band,int & level)385 ErrCode WifiDeviceImpl::GetSignalLevel(const int &rssi, const int &band, int &level)
386 {
387 std::lock_guard<std::mutex> lock(mutex_);
388 RETURN_IF_FAIL(GetWifiDeviceProxy());
389 return client_->GetSignalLevel(rssi, band, level);
390 }
391
392 #ifdef OHOS_ARCH_LITE
RegisterCallBack(const std::shared_ptr<IWifiDeviceCallBack> & callback,const std::vector<std::string> & event)393 ErrCode WifiDeviceImpl::RegisterCallBack(const std::shared_ptr<IWifiDeviceCallBack> &callback,
394 const std::vector<std::string> &event)
395 #else
396 ErrCode WifiDeviceImpl::RegisterCallBack(const sptr<IWifiDeviceCallBack> &callback,
397 const std::vector<std::string> &event)
398 #endif
399 {
400 std::lock_guard<std::mutex> lock(mutex_);
401 RETURN_IF_FAIL(GetWifiDeviceProxy());
402 return client_->RegisterCallBack(callback, event);
403 }
404
GetSupportedFeatures(long & features)405 ErrCode WifiDeviceImpl::GetSupportedFeatures(long &features)
406 {
407 std::lock_guard<std::mutex> lock(mutex_);
408 RETURN_IF_FAIL(GetWifiDeviceProxy());
409 return client_->GetSupportedFeatures(features);
410 }
411
IsFeatureSupported(long feature,bool & isSupported)412 ErrCode WifiDeviceImpl::IsFeatureSupported(long feature, bool &isSupported)
413 {
414 std::lock_guard<std::mutex> lock(mutex_);
415 RETURN_IF_FAIL(GetWifiDeviceProxy());
416 ErrCode ret = client_->IsFeatureSupported(feature, isSupported);
417 if (ret != WIFI_OPT_SUCCESS) {
418 return ret;
419 }
420 return WIFI_OPT_SUCCESS;
421 }
422
GetDeviceMacAddress(std::string & result)423 ErrCode WifiDeviceImpl::GetDeviceMacAddress(std::string &result)
424 {
425 std::lock_guard<std::mutex> lock(mutex_);
426 RETURN_IF_FAIL(GetWifiDeviceProxy());
427 return client_->GetDeviceMacAddress(result);
428 }
429
IsBandTypeSupported(int bandType,bool & supported)430 ErrCode WifiDeviceImpl::IsBandTypeSupported(int bandType, bool &supported)
431 {
432 std::lock_guard<std::mutex> lock(mutex_);
433 RETURN_IF_FAIL(GetWifiDeviceProxy());
434 return client_->IsBandTypeSupported(bandType, supported);
435 }
436
Get5GHzChannelList(std::vector<int> & result)437 ErrCode WifiDeviceImpl::Get5GHzChannelList(std::vector<int> &result)
438 {
439 std::lock_guard<std::mutex> lock(mutex_);
440 RETURN_IF_FAIL(GetWifiDeviceProxy());
441 return client_->Get5GHzChannelList(result);
442 }
443
StartPortalCertification()444 ErrCode WifiDeviceImpl::StartPortalCertification()
445 {
446 std::lock_guard<std::mutex> lock(mutex_);
447 RETURN_IF_FAIL(GetWifiDeviceProxy());
448 return client_->StartPortalCertification();
449 }
450
SetLowLatencyMode(bool enabled)451 bool WifiDeviceImpl::SetLowLatencyMode(bool enabled)
452 {
453 std::lock_guard<std::mutex> lock(mutex_);
454 RETURN_IF_FAIL(GetWifiDeviceProxy());
455 return client_->SetLowLatencyMode(enabled);
456 }
457
SetAppFrozen(std::set<int> pidList,bool isFrozen)458 ErrCode WifiDeviceImpl::SetAppFrozen(std::set<int> pidList, bool isFrozen)
459 {
460 std::lock_guard<std::mutex> lock(mutex_);
461 RETURN_IF_FAIL(GetWifiDeviceProxy());
462 return client_->SetAppFrozen(pidList, isFrozen);
463 }
464
ResetAllFrozenApp()465 ErrCode WifiDeviceImpl::ResetAllFrozenApp()
466 {
467 std::lock_guard<std::mutex> lock(mutex_);
468 RETURN_IF_FAIL(GetWifiDeviceProxy());
469 return client_->ResetAllFrozenApp();
470 }
471
DisableAutoJoin(const std::string & conditionName)472 ErrCode WifiDeviceImpl::DisableAutoJoin(const std::string &conditionName)
473 {
474 std::lock_guard<std::mutex> lock(mutex_);
475 RETURN_IF_FAIL(GetWifiDeviceProxy());
476 return client_->DisableAutoJoin(conditionName);
477 }
478
EnableAutoJoin(const std::string & conditionName)479 ErrCode WifiDeviceImpl::EnableAutoJoin(const std::string &conditionName)
480 {
481 std::lock_guard<std::mutex> lock(mutex_);
482 RETURN_IF_FAIL(GetWifiDeviceProxy());
483 return client_->EnableAutoJoin(conditionName);
484 }
485
RegisterAutoJoinCondition(const std::string & conditionName,const std::function<bool ()> & autoJoinCondition)486 ErrCode WifiDeviceImpl::RegisterAutoJoinCondition(const std::string &conditionName,
487 const std::function<bool()> &autoJoinCondition)
488 {
489 if (!autoJoinCondition) {
490 WIFI_LOGE("the target of autoJoinCondition for %{public}s is empty", conditionName.c_str());
491 return WIFI_OPT_FAILED;
492 }
493 std::lock_guard<std::mutex> lock(mutex_);
494 RETURN_IF_FAIL(GetWifiDeviceProxy());
495 return client_->RegisterAutoJoinCondition(conditionName, autoJoinCondition);
496 }
497
DeregisterAutoJoinCondition(const std::string & conditionName)498 ErrCode WifiDeviceImpl::DeregisterAutoJoinCondition(const std::string &conditionName)
499 {
500 std::lock_guard<std::mutex> lock(mutex_);
501 RETURN_IF_FAIL(GetWifiDeviceProxy());
502 return client_->DeregisterAutoJoinCondition(conditionName);
503 }
504
RegisterFilterBuilder(const FilterTag & filterTag,const std::string & filterName,const FilterBuilder & filterBuilder)505 ErrCode WifiDeviceImpl::RegisterFilterBuilder(const FilterTag &filterTag,
506 const std::string &filterName,
507 const FilterBuilder &filterBuilder)
508 {
509 if (!filterBuilder) {
510 WIFI_LOGE("the target of filterBuilder for %{public}s is empty", filterName.c_str());
511 return WIFI_OPT_FAILED;
512 }
513 std::lock_guard<std::mutex> lock(mutex_);
514 RETURN_IF_FAIL(GetWifiDeviceProxy());
515 return client_->RegisterFilterBuilder(filterTag, filterName, filterBuilder);
516 }
517
DeregisterFilterBuilder(const FilterTag & filterTag,const std::string & filterName)518 ErrCode WifiDeviceImpl::DeregisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName)
519 {
520 std::lock_guard<std::mutex> lock(mutex_);
521 RETURN_IF_FAIL(GetWifiDeviceProxy());
522 return client_->DeregisterFilterBuilder(filterTag, filterName);
523 }
524
RegisterCommonBuilder(const TagType & tagType,const std::string & tagName,const CommonBuilder & commonBuilder)525 ErrCode WifiDeviceImpl::RegisterCommonBuilder(const TagType &tagType, const std::string &tagName,
526 const CommonBuilder &commonBuilder)
527 {
528 if (commonBuilder.IsEmpty()) {
529 WIFI_LOGE("the target of commonBuilder for %{public}s is empty", tagName.c_str());
530 return WIFI_OPT_FAILED;
531 }
532 std::lock_guard<std::mutex> lock(mutex_);
533 RETURN_IF_FAIL(GetWifiDeviceProxy());
534 return client_->RegisterCommonBuilder(tagType, tagName, commonBuilder);
535 }
536
DeregisterCommonBuilder(const TagType & tagType,const std::string & tagName)537 ErrCode WifiDeviceImpl::DeregisterCommonBuilder(const TagType &tagType, const std::string &tagName)
538 {
539 std::lock_guard<std::mutex> lock(mutex_);
540 RETURN_IF_FAIL(GetWifiDeviceProxy());
541 return client_->DeregisterCommonBuilder(tagType, tagName);
542 }
543
IsRemoteDied(void)544 bool WifiDeviceImpl::IsRemoteDied(void)
545 {
546 return (client_ == nullptr) ? true : client_->IsRemoteDied();
547 }
548
GetChangeDeviceConfig(ConfigChange & value,WifiDeviceConfig & config)549 ErrCode WifiDeviceImpl::GetChangeDeviceConfig(ConfigChange& value, WifiDeviceConfig &config)
550 {
551 std::lock_guard<std::mutex> lock(mutex_);
552 RETURN_IF_FAIL(GetWifiDeviceProxy());
553 return client_->GetChangeDeviceConfig(value, config);
554 }
555
FactoryReset()556 ErrCode WifiDeviceImpl::FactoryReset()
557 {
558 std::lock_guard<std::mutex> lock(mutex_);
559 RETURN_IF_FAIL(GetWifiDeviceProxy());
560 return client_->FactoryReset();
561 }
562
ReceiveNetworkControlInfo(const WifiNetworkControlInfo & networkControlInfo)563 ErrCode WifiDeviceImpl::ReceiveNetworkControlInfo(const WifiNetworkControlInfo& networkControlInfo)
564 {
565 std::lock_guard<std::mutex> lock(mutex_);
566 RETURN_IF_FAIL(GetWifiDeviceProxy());
567 return client_->ReceiveNetworkControlInfo(networkControlInfo);
568 }
569
LimitSpeed(const int controlId,const int limitMode)570 ErrCode WifiDeviceImpl::LimitSpeed(const int controlId, const int limitMode)
571 {
572 std::lock_guard<std::mutex> lock(mutex_);
573 RETURN_IF_FAIL(GetWifiDeviceProxy());
574 return client_->LimitSpeed(controlId, limitMode);
575 }
576
SetLowTxPower(const WifiLowPowerParam wifiLowPowerParam)577 ErrCode WifiDeviceImpl::SetLowTxPower(const WifiLowPowerParam wifiLowPowerParam)
578 {
579 std::lock_guard<std::mutex> lock(mutex_);
580 RETURN_IF_FAIL(GetWifiDeviceProxy());
581 return client_->SetLowTxPower(wifiLowPowerParam);
582 }
583
EnableHiLinkHandshake(bool uiFlag,std::string & bssid,WifiDeviceConfig & deviceConfig)584 ErrCode WifiDeviceImpl::EnableHiLinkHandshake(bool uiFlag, std::string &bssid, WifiDeviceConfig &deviceConfig)
585 {
586 std::lock_guard<std::mutex> lock(mutex_);
587 RETURN_IF_FAIL(GetWifiDeviceProxy());
588 return client_->EnableHiLinkHandshake(uiFlag, bssid, deviceConfig);
589 }
590
SetSatelliteState(const int state)591 ErrCode WifiDeviceImpl::SetSatelliteState(const int state)
592 {
593 std::lock_guard<std::mutex> lock(mutex_);
594 RETURN_IF_FAIL(GetWifiDeviceProxy());
595 return client_->SetSatelliteState(state);
596 }
597
EnableSemiWifi()598 ErrCode WifiDeviceImpl::EnableSemiWifi()
599 {
600 std::lock_guard<std::mutex> lock(mutex_);
601 RETURN_IF_FAIL(GetWifiDeviceProxy());
602 return client_->EnableSemiWifi();
603 }
604
GetWifiDetailState(WifiDetailState & state)605 ErrCode WifiDeviceImpl::GetWifiDetailState(WifiDetailState &state)
606 {
607 std::lock_guard<std::mutex> lock(mutex_);
608 RETURN_IF_FAIL(GetWifiDeviceProxy());
609 return client_->GetWifiDetailState(state);
610 }
611
StartRoamToNetwork(const int networkId,const std::string bssid,const bool isCandidate)612 ErrCode WifiDeviceImpl::StartRoamToNetwork(const int networkId, const std::string bssid, const bool isCandidate)
613 {
614 std::lock_guard<std::mutex> lock(mutex_);
615 RETURN_IF_FAIL(GetWifiDeviceProxy());
616 return client_->StartRoamToNetwork(networkId, bssid, isCandidate);
617 }
618
StartConnectToUserSelectNetwork(int networkId,std::string bssid,bool isCandidate)619 ErrCode WifiDeviceImpl::StartConnectToUserSelectNetwork(int networkId, std::string bssid, bool isCandidate)
620 {
621 std::lock_guard<std::mutex> lock(mutex_);
622 RETURN_IF_FAIL(GetWifiDeviceProxy());
623 return client_->StartConnectToUserSelectNetwork(networkId, bssid, isCandidate);
624 }
625
GetDeviceConfig(const int & networkId,WifiDeviceConfig & config)626 ErrCode WifiDeviceImpl::GetDeviceConfig(const int &networkId, WifiDeviceConfig &config)
627 {
628 std::lock_guard<std::mutex> lock(mutex_);
629 RETURN_IF_FAIL(GetWifiDeviceProxy());
630 return client_->GetDeviceConfig(networkId, config);
631 }
632
SetDpiMarkRule(const std::string & ifaceName,int uid,int protocol,int enable)633 ErrCode WifiDeviceImpl::SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable)
634 {
635 std::lock_guard<std::mutex> lock(mutex_);
636 RETURN_IF_FAIL(GetWifiDeviceProxy());
637 return client_->SetDpiMarkRule(ifaceName, uid, protocol, enable);
638 }
639
UpdateNetworkLagInfo(const NetworkLagType networkLagType,const NetworkLagInfo & networkLagInfo)640 ErrCode WifiDeviceImpl::UpdateNetworkLagInfo(const NetworkLagType networkLagType, const NetworkLagInfo &networkLagInfo)
641 {
642 std::lock_guard<std::mutex> lock(mutex_);
643 RETURN_IF_FAIL(GetWifiDeviceProxy());
644 return client_->UpdateNetworkLagInfo(networkLagType, networkLagInfo);
645 }
646
FetchWifiSignalInfoForVoWiFi(VoWifiSignalInfo & signalInfo)647 ErrCode WifiDeviceImpl::FetchWifiSignalInfoForVoWiFi(VoWifiSignalInfo &signalInfo)
648 {
649 std::lock_guard<std::mutex> lock(mutex_);
650 RETURN_IF_FAIL(GetWifiDeviceProxy());
651 return client_->FetchWifiSignalInfoForVoWiFi(signalInfo);
652 }
653
IsSupportVoWifiDetect(bool & isSupported)654 ErrCode WifiDeviceImpl::IsSupportVoWifiDetect(bool &isSupported)
655 {
656 std::lock_guard<std::mutex> lock(mutex_);
657 RETURN_IF_FAIL(GetWifiDeviceProxy());
658 return client_->IsSupportVoWifiDetect(isSupported);
659 }
660
SetVoWifiDetectMode(WifiDetectConfInfo info)661 ErrCode WifiDeviceImpl::SetVoWifiDetectMode(WifiDetectConfInfo info)
662 {
663 std::lock_guard<std::mutex> lock(mutex_);
664 RETURN_IF_FAIL(GetWifiDeviceProxy());
665 return client_->SetVoWifiDetectMode(info);
666 }
667
GetVoWifiDetectMode(WifiDetectConfInfo & info)668 ErrCode WifiDeviceImpl::GetVoWifiDetectMode(WifiDetectConfInfo &info)
669 {
670 std::lock_guard<std::mutex> lock(mutex_);
671 RETURN_IF_FAIL(GetWifiDeviceProxy());
672 return client_->GetVoWifiDetectMode(info);
673 }
674
SetVoWifiDetectPeriod(int period)675 ErrCode WifiDeviceImpl::SetVoWifiDetectPeriod(int period)
676 {
677 std::lock_guard<std::mutex> lock(mutex_);
678 RETURN_IF_FAIL(GetWifiDeviceProxy());
679 return client_->SetVoWifiDetectPeriod(period);
680 }
681
GetVoWifiDetectPeriod(int & period)682 ErrCode WifiDeviceImpl::GetVoWifiDetectPeriod(int &period)
683 {
684 std::lock_guard<std::mutex> lock(mutex_);
685 RETURN_IF_FAIL(GetWifiDeviceProxy());
686 return client_->GetVoWifiDetectPeriod(period);
687 }
688
GetMultiLinkedInfo(std::vector<WifiLinkedInfo> & multiLinkedInfo)689 ErrCode WifiDeviceImpl::GetMultiLinkedInfo(std::vector<WifiLinkedInfo> &multiLinkedInfo)
690 {
691 std::lock_guard<std::mutex> lock(mutex_);
692 RETURN_IF_FAIL(GetWifiDeviceProxy());
693 return client_->GetMultiLinkedInfo(multiLinkedInfo);
694 }
695
696 } // namespace Wifi
697 } // namespace OHOS
698