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_scan_proxy.h"
17 #include <cstddef>
18 #include <cstdint>
19 #include <new>
20 #include <string>
21 #include "define.h"
22 #include "wifi_manager_service_ipc_interface_code.h"
23 #include "ipc_types.h"
24 #include "iremote_proxy.h"
25 #include "message_option.h"
26 #include "message_parcel.h"
27 #include "wifi_common_util.h"
28 #include "wifi_hisysevent.h"
29 #include "wifi_logger.h"
30 #include "wifi_scan_callback_stub.h"
31
32 namespace OHOS {
33 DEFINE_WIFILOG_SCAN_LABEL("WifiScanProxy");
34 namespace Wifi {
35 static sptr<WifiScanCallbackStub> g_wifiScanCallbackStub =
36 sptr<WifiScanCallbackStub>(new (std::nothrow) WifiScanCallbackStub());
37
WifiScanProxy(const sptr<IRemoteObject> & remote)38 WifiScanProxy::WifiScanProxy(const sptr<IRemoteObject> &remote)
39 : IRemoteProxy<IWifiScan>(remote), mRemoteDied(false), remote_(nullptr), deathRecipient_(nullptr)
40 {
41 std::lock_guard<std::mutex> lock(mutex_);
42 if (remote) {
43 if (!remote->IsProxyObject()) {
44 WIFI_LOGW("not proxy object!");
45 return;
46 }
47 deathRecipient_ = new (std::nothrow) WifiDeathRecipient(*this);
48 if (deathRecipient_ == nullptr) {
49 WIFI_LOGW("deathRecipient_ is nullptr!");
50 }
51 if (!remote->AddDeathRecipient(deathRecipient_)) {
52 WIFI_LOGW("AddDeathRecipient failed!");
53 return;
54 }
55 remote_ = remote;
56 WIFI_LOGI("AddDeathRecipient success! deathRecipient_");
57 }
58 }
59
~WifiScanProxy()60 WifiScanProxy::~WifiScanProxy()
61 {
62 WIFI_LOGI("enter ~WifiScanProxy!");
63 RemoveDeathRecipient();
64 }
65
RemoveDeathRecipient(void)66 void WifiScanProxy::RemoveDeathRecipient(void)
67 {
68 WIFI_LOGI("enter RemoveDeathRecipient, deathRecipient_!");
69 std::lock_guard<std::mutex> lock(mutex_);
70 if (remote_ == nullptr) {
71 WIFI_LOGI("remote_ is nullptr!");
72 return;
73 }
74 if (deathRecipient_ == nullptr) {
75 WIFI_LOGI("deathRecipient_ is nullptr!");
76 return;
77 }
78 remote_->RemoveDeathRecipient(deathRecipient_);
79 remote_ = nullptr;
80 }
81
SetScanControlInfo(const ScanControlInfo & info)82 ErrCode WifiScanProxy::SetScanControlInfo(const ScanControlInfo &info)
83 {
84 if (mRemoteDied) {
85 WIFI_LOGW("failed to SetScanControlInfo, remote service is died!");
86 return WIFI_OPT_FAILED;
87 }
88 MessageOption option;
89 MessageParcel data;
90 MessageParcel reply;
91 if (!data.WriteInterfaceToken(GetDescriptor())) {
92 WIFI_LOGE("SetScanControlInfo Write interface token error!");
93 return WIFI_OPT_FAILED;
94 }
95 data.WriteInt32(0);
96 data.WriteInt32(info.scanForbidList.size());
97 for (auto iter = info.scanForbidList.begin(); iter != info.scanForbidList.end(); iter++) {
98 data.WriteInt32(iter->scanScene);
99 data.WriteInt32(static_cast<int>(iter->scanMode));
100 data.WriteInt32(iter->forbidTime);
101 data.WriteInt32(iter->forbidCount);
102 }
103
104 data.WriteInt32(info.scanIntervalList.size());
105 for (auto iter2 = info.scanIntervalList.begin(); iter2 != info.scanIntervalList.end(); iter2++) {
106 data.WriteInt32(iter2->scanScene);
107 data.WriteInt32(static_cast<int>(iter2->scanMode));
108 data.WriteBool(iter2->isSingle);
109 data.WriteInt32(static_cast<int>(iter2->intervalMode));
110 data.WriteInt32(iter2->interval);
111 data.WriteInt32(iter2->count);
112 }
113
114 int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_SET_SCAN_CONTROL_INFO),
115 data, reply, option);
116 if (error != ERR_NONE) {
117 WIFI_LOGW("Set Attr(%{public}d) failed",
118 static_cast<int32_t>(ScanInterfaceCode::WIFI_SVR_CMD_SET_SCAN_CONTROL_INFO));
119 return WIFI_OPT_FAILED;
120 }
121 int exception = reply.ReadInt32();
122 if (exception) {
123 WIFI_LOGE("SetScanControlInfo Reply exception failed!");
124 return WIFI_OPT_FAILED;
125 }
126 int ret = reply.ReadInt32();
127 if (ErrCode(ret) != WIFI_OPT_SUCCESS) {
128 WIFI_LOGE("SetScanControlInfo Reply ReadInt32 failed, ret:%{public}d", ret);
129 return ErrCode(ret);
130 }
131 return WIFI_OPT_SUCCESS;
132 }
133
Scan(bool compatible)134 ErrCode WifiScanProxy::Scan(bool compatible)
135 {
136 if (mRemoteDied) {
137 WIFI_LOGW("failed to Scan, remote service is died!");
138 return WIFI_OPT_FAILED;
139 }
140 MessageOption option;
141 MessageParcel data;
142 MessageParcel reply;
143 if (!data.WriteInterfaceToken(GetDescriptor())) {
144 WIFI_LOGE("Scan Write interface token error!");
145 return WIFI_OPT_FAILED;
146 }
147 data.WriteInt32(0);
148 data.WriteBool(compatible);
149 data.WriteString(GetBundleName());
150 int error =
151 Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_FULL_SCAN), data, reply, option);
152 if (error != ERR_NONE) {
153 WIFI_LOGW("Set Attr(%{public}d) failed", static_cast<int32_t>(ScanInterfaceCode::WIFI_SVR_CMD_FULL_SCAN));
154 return WIFI_OPT_FAILED;
155 }
156 int exception = reply.ReadInt32();
157 if (exception) {
158 return WIFI_OPT_FAILED;
159 }
160 int ret = reply.ReadInt32();
161 /* Record sysevent for scan */
162 WriteWifiScanHiSysEvent(static_cast<int>(ret), GetBundleName());
163 if (ErrCode(ret) != WIFI_OPT_SUCCESS) {
164 return ErrCode(ret);
165 }
166 return WIFI_OPT_SUCCESS;
167 }
168
AdvanceScan(const WifiScanParams & params)169 ErrCode WifiScanProxy::AdvanceScan(const WifiScanParams ¶ms)
170 {
171 if (mRemoteDied) {
172 WIFI_LOGW("failed to AdvanceScan, remote service is died!");
173 return WIFI_OPT_FAILED;
174 }
175 MessageOption option;
176 MessageParcel data;
177 MessageParcel reply;
178 if (!data.WriteInterfaceToken(GetDescriptor())) {
179 WIFI_LOGE("AdvanceScan Write interface token error!");
180 return WIFI_OPT_FAILED;
181 }
182 data.WriteInt32(0);
183 data.WriteCString(params.ssid.c_str());
184 data.WriteCString(params.bssid.c_str());
185 data.WriteInt32(params.freqs.size());
186 for (std::size_t i = 0; i < params.freqs.size(); i++) {
187 data.WriteInt32(params.freqs[i]);
188 }
189 data.WriteInt32(params.band);
190 data.WriteString(GetBundleName());
191
192 int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_SPECIFIED_PARAMS_SCAN),
193 data, reply, option);
194 if (error != ERR_NONE) {
195 WIFI_LOGW("Set Attr(%{public}d) failed",
196 static_cast<int32_t>(ScanInterfaceCode::WIFI_SVR_CMD_SPECIFIED_PARAMS_SCAN));
197 return WIFI_OPT_FAILED;
198 }
199 int exception = reply.ReadInt32();
200 if (exception) {
201 return WIFI_OPT_FAILED;
202 }
203 int ret = reply.ReadInt32();
204 /* Record sysevent for scan */
205 WriteWifiScanHiSysEvent(static_cast<int>(ret), GetBundleName());
206 if (ErrCode(ret) != WIFI_OPT_SUCCESS) {
207 return ErrCode(ret);
208 }
209 return WIFI_OPT_SUCCESS;
210 }
211
IsWifiClosedScan(bool & bOpen)212 ErrCode WifiScanProxy::IsWifiClosedScan(bool &bOpen)
213 {
214 if (mRemoteDied) {
215 WIFI_LOGW("failed to IsWifiClosedScan, remote service is died!");
216 return WIFI_OPT_FAILED;
217 }
218 MessageOption option;
219 MessageParcel data;
220 MessageParcel reply;
221 if (!data.WriteInterfaceToken(GetDescriptor())) {
222 WIFI_LOGE("IsWifiClosedScan Write interface token error!");
223 return WIFI_OPT_FAILED;
224 }
225 data.WriteInt32(0);
226 int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_IS_SCAN_ALWAYS_ACTIVE),
227 data, reply, option);
228 if (error != ERR_NONE) {
229 WIFI_LOGW("Set Attr(%{public}d) failed",
230 static_cast<int32_t>(ScanInterfaceCode::WIFI_SVR_CMD_IS_SCAN_ALWAYS_ACTIVE));
231 return WIFI_OPT_FAILED;
232 }
233 int exception = reply.ReadInt32();
234 if (exception) {
235 WIFI_LOGE("IsWifiClosedScan Reply exception failed!");
236 return WIFI_OPT_FAILED;
237 }
238 int ret = reply.ReadInt32();
239 if (ErrCode(ret) != WIFI_OPT_SUCCESS) {
240 WIFI_LOGE("IsWifiClosedScan Reply ReadInt32 failed, ret:%{public}d", ret);
241 return ErrCode(ret);
242 }
243 bOpen = reply.ReadBool();
244 return WIFI_OPT_SUCCESS;
245 }
246
GetScanInfo(WifiScanInfo & info,std::vector<std::string> & tokens,int32_t & dataRecvLen)247 static void GetScanInfo(WifiScanInfo &info, std::vector<std::string> &tokens, int32_t &dataRecvLen)
248 {
249 info.bssid = HexToString(tokens[dataRecvLen++]);
250 info.ssid = HexToString(tokens[dataRecvLen++]);
251 info.bssidType = CheckDataLegal(tokens[dataRecvLen++]);
252 info.capabilities = HexToString(tokens[dataRecvLen++]);
253 info.frequency = CheckDataLegal(tokens[dataRecvLen++]);
254 info.band = CheckDataLegal(tokens[dataRecvLen++]);
255 info.channelWidth = static_cast<WifiChannelWidth>(CheckDataLegal(tokens[dataRecvLen++]));
256 info.centerFrequency0 = CheckDataLegal(tokens[dataRecvLen++]);
257 info.centerFrequency1 = CheckDataLegal(tokens[dataRecvLen++]);
258 info.rssi = CheckDataLegal(tokens[dataRecvLen++]);
259 info.securityType = static_cast<WifiSecurity>(CheckDataLegal(tokens[dataRecvLen++]));
260 size_t numInfoElems = static_cast<uint32_t>(CheckDataLegal(tokens[dataRecvLen++]));
261 for (size_t i = 0; i < numInfoElems; i++) {
262 WifiInfoElem elem;
263 elem.id = static_cast<uint32_t>(CheckDataLegal(tokens[dataRecvLen++]));
264 size_t ieLen = static_cast<uint32_t>(CheckDataLegal(tokens[dataRecvLen++]));
265 for (size_t j = 0; j < ieLen; j++) {
266 elem.content.push_back(static_cast<char>(CheckDataLegal(tokens[dataRecvLen++])));
267 }
268 info.infoElems.push_back(elem);
269 }
270 info.features = CheckDataTolonglong(tokens[dataRecvLen++]);
271 info.timestamp = CheckDataTolonglong(tokens[dataRecvLen++]);
272 info.wifiStandard = CheckDataLegal(tokens[dataRecvLen++]);
273 info.maxSupportedRxLinkSpeed = CheckDataLegal(tokens[dataRecvLen++]);
274 info.maxSupportedTxLinkSpeed = CheckDataLegal(tokens[dataRecvLen++]);
275 info.disappearCount = CheckDataLegal(tokens[dataRecvLen++]);
276 info.isHiLinkNetwork = CheckDataLegal(tokens[dataRecvLen++]);
277 info.supportedWifiCategory = static_cast<WifiCategory>(CheckDataLegal(tokens[dataRecvLen++]));
278 }
279
ParseScanInfos(MessageParcel & reply,std::vector<WifiScanInfo> & result,int contentSize)280 ErrCode WifiScanProxy::ParseScanInfos(MessageParcel &reply, std::vector<WifiScanInfo> &result, int contentSize)
281 {
282 WIFI_LOGI("WifiScanProxy ParseScanInfos");
283 int32_t allSize = reply.ReadInt32(allSize);
284 sptr<Ashmem> ashmem = reply.ReadAshmem();
285 if (ashmem == nullptr || !ashmem->MapReadAndWriteAshmem()) {
286 WIFI_LOGE("ParseDeviceConfigs ReadAshmem error");
287 return WIFI_OPT_FAILED;
288 }
289 std::string net = (char *)ashmem->ReadFromAshmem(allSize, 0);
290 std::vector<std::string> tokens;
291 SplitStr(net, ";", tokens, true, true);
292 int dataRecvLen = 0;
293 for (int i = 0; i < contentSize && dataRecvLen < static_cast<int>(tokens.size()); ++i) {
294 WifiScanInfo info;
295 GetScanInfo(info, tokens, dataRecvLen);
296 result.emplace_back(info);
297 }
298 ashmem->UnmapAshmem();
299 ashmem->CloseAshmem();
300 return WIFI_OPT_SUCCESS;
301 }
302
ParseScanInfosSmall(MessageParcel & reply,std::vector<WifiScanInfo> & result,int contentSize)303 ErrCode WifiScanProxy::ParseScanInfosSmall(MessageParcel &reply, std::vector<WifiScanInfo> &result, int contentSize)
304 {
305 for (int i = 0; i < contentSize; i++) {
306 WifiScanInfo info;
307 info.bssid = reply.ReadString();
308 info.ssid = reply.ReadString();
309 info.bssidType = reply.ReadInt32();
310 info.capabilities = reply.ReadString();
311 info.frequency = reply.ReadInt32();
312 info.band = reply.ReadInt32();
313 info.channelWidth = static_cast<WifiChannelWidth>(reply.ReadInt32());
314 info.centerFrequency0 = reply.ReadInt32();
315 info.centerFrequency1 = reply.ReadInt32();
316 info.rssi = reply.ReadInt32();
317 info.securityType = static_cast<WifiSecurity>(reply.ReadInt32());
318 // Parse infoElems vector
319 size_t numInfoElems = reply.ReadUint32();
320 for (size_t m = 0; m < numInfoElems; m++) {
321 WifiInfoElem elem;
322 elem.id = reply.ReadInt32();
323 size_t ieLen = reply.ReadUint32();
324 elem.content.resize(ieLen);
325 for (size_t n = 0; n < ieLen; n++) {
326 elem.content[n] = static_cast<char>(reply.ReadInt32());
327 }
328 info.infoElems.push_back(elem);
329 }
330 info.features = reply.ReadInt64();
331 info.timestamp = reply.ReadInt64();
332 info.wifiStandard = reply.ReadInt32();
333 info.maxSupportedRxLinkSpeed = reply.ReadInt32();
334 info.maxSupportedTxLinkSpeed = reply.ReadInt32();
335 info.disappearCount = reply.ReadInt32();
336 info.isHiLinkNetwork = reply.ReadBool();
337 info.supportedWifiCategory = static_cast<WifiCategory>(reply.ReadInt32());
338 result.emplace_back(info);
339 }
340 return WIFI_OPT_SUCCESS;
341 }
342
GetScanInfoList(std::vector<WifiScanInfo> & result,bool compatible)343 ErrCode WifiScanProxy::GetScanInfoList(std::vector<WifiScanInfo> &result, bool compatible)
344 {
345 if (mRemoteDied) {
346 WIFI_LOGW("failed to GetScanInfoList, remote service is died!");
347 return WIFI_OPT_FAILED;
348 }
349 MessageOption option;
350 MessageParcel data;
351 MessageParcel reply;
352 if (!data.WriteInterfaceToken(GetDescriptor())) {
353 WIFI_LOGE("GetScanInfoList Write interface token error!");
354 return WIFI_OPT_FAILED;
355 }
356 data.WriteInt32(0);
357 data.WriteBool(compatible);
358 int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_GET_SCAN_INFO_LIST), data,
359 reply, option);
360 if (error != ERR_NONE) {
361 WIFI_LOGW("Set Attr(%{public}d) failed",
362 static_cast<int32_t>(ScanInterfaceCode::WIFI_SVR_CMD_GET_SCAN_INFO_LIST));
363 return WIFI_OPT_FAILED;
364 }
365 int exception = reply.ReadInt32();
366 if (exception) {
367 WIFI_LOGE("GetScanInfoList Reply exception failed!");
368 return WIFI_OPT_FAILED;
369 }
370 int ret = reply.ReadInt32();
371 if (ErrCode(ret) != WIFI_OPT_SUCCESS) {
372 WIFI_LOGE("GetScanInfoList Reply ReadInt32 failed, ret:%{public}d", ret);
373 return ErrCode(ret);
374 }
375
376 constexpr int maxSize = 200;
377 constexpr int bigSize = 150;
378 int retSize = reply.ReadInt32();
379 if (retSize > maxSize || retSize < 0) {
380 WIFI_LOGE("Scan info size exceeds maximum allowed size: %{public}d", retSize);
381 return WIFI_OPT_FAILED;
382 }
383 if (retSize > bigSize) {
384 return ParseScanInfos(reply, result, retSize);
385 }
386 return ParseScanInfosSmall(reply, result, retSize);
387 }
388
RegisterCallBack(const sptr<IWifiScanCallback> & callback,const std::vector<std::string> & event)389 ErrCode WifiScanProxy::RegisterCallBack(const sptr<IWifiScanCallback> &callback, const std::vector<std::string> &event)
390 {
391 if (mRemoteDied) {
392 WIFI_LOGW("failed to `%{public}s`,remote service is died!", __func__);
393 return WIFI_OPT_FAILED;
394 }
395 WIFI_LOGD("RegisterCallBack start!");
396 MessageParcel data;
397 MessageParcel reply;
398 MessageOption option(MessageOption::TF_ASYNC);
399
400 if (g_wifiScanCallbackStub == nullptr) {
401 WIFI_LOGE("g_wifiScanCallbackStub is nullptr!");
402 return WIFI_OPT_FAILED;
403 }
404 g_wifiScanCallbackStub->RegisterCallBack(callback);
405 if (!data.WriteInterfaceToken(GetDescriptor())) {
406 WIFI_LOGE("Write interface token error: %{public}s", __func__);
407 return WIFI_OPT_FAILED;
408 }
409 data.WriteInt32(0);
410 if (!data.WriteRemoteObject(g_wifiScanCallbackStub->AsObject())) {
411 WIFI_LOGE("RegisterCallBack WriteRemoteObject failed!");
412 return WIFI_OPT_FAILED;
413 }
414
415 int pid = GetCallingPid();
416 data.WriteInt32(pid);
417 int tokenId = GetCallingTokenId();
418 data.WriteInt32(tokenId);
419 int eventNum = static_cast<int>(event.size());
420 data.WriteInt32(eventNum);
421 if (eventNum > 0) {
422 for (auto &eventName : event) {
423 data.WriteString(eventName);
424 }
425 }
426 WIFI_LOGD("%{public}s, calling uid: %{public}d, pid: %{public}d, tokenId: %{private}d", __func__, GetCallingUid(),
427 pid, tokenId);
428 int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_REGISTER_SCAN_CALLBACK),
429 data, reply, option);
430 if (error != ERR_NONE) {
431 WIFI_LOGE("RegisterCallBack failed, error code is %{public}d", error);
432 return WIFI_OPT_FAILED;
433 }
434 int32_t ret = reply.ReadInt32();
435 WIFI_LOGD("RegisterCallBack is finished: result=%{public}d", ret);
436 return WIFI_OPT_SUCCESS;
437 }
438
GetSupportedFeatures(long & features)439 ErrCode WifiScanProxy::GetSupportedFeatures(long &features)
440 {
441 if (mRemoteDied) {
442 WIFI_LOGW("failed to `%{public}s`,remote service is died!", __func__);
443 return WIFI_OPT_FAILED;
444 }
445 MessageOption option;
446 MessageParcel data;
447 MessageParcel reply;
448 if (!data.WriteInterfaceToken(GetDescriptor())) {
449 WIFI_LOGE("Write interface token error: %{public}s", __func__);
450 return WIFI_OPT_FAILED;
451 }
452 data.WriteInt32(0);
453 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES),
454 data, reply, option);
455 if (error != ERR_NONE) {
456 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
457 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES), error);
458 return ErrCode(error);
459 }
460 int exception = reply.ReadInt32();
461 if (exception) {
462 return WIFI_OPT_FAILED;
463 }
464 int ret = reply.ReadInt32();
465 if (ret != WIFI_OPT_SUCCESS) {
466 return ErrCode(ret);
467 }
468
469 features = reply.ReadInt64();
470 return WIFI_OPT_SUCCESS;
471 }
472
OnRemoteDied(const wptr<IRemoteObject> & remoteObject)473 void WifiScanProxy::OnRemoteDied(const wptr<IRemoteObject> &remoteObject)
474 {
475 WIFI_LOGW("Remote service is died!");
476 mRemoteDied = true;
477 if (g_wifiScanCallbackStub == nullptr) {
478 WIFI_LOGE("g_wifiScanCallbackStub is nullptr!");
479 return;
480 }
481 g_wifiScanCallbackStub->SetRemoteDied(true);
482 }
483
IsRemoteDied(void)484 bool WifiScanProxy::IsRemoteDied(void)
485 {
486 if (mRemoteDied) {
487 WIFI_LOGW("IsRemoteDied! remote is died now!");
488 }
489 return mRemoteDied;
490 }
SetScanOnlyAvailable(bool bScanOnlyAvailable)491 ErrCode WifiScanProxy::SetScanOnlyAvailable(bool bScanOnlyAvailable)
492 {
493 if (mRemoteDied) {
494 WIFI_LOGE("failed to SetScanOnlyAvailable, remote service is died!");
495 return WIFI_OPT_FAILED;
496 }
497 MessageOption option;
498 MessageParcel data;
499 MessageParcel reply;
500 if (!data.WriteInterfaceToken(GetDescriptor())) {
501 WIFI_LOGE("SetScanOnlyAvailable Write interface token error!");
502 return WIFI_OPT_FAILED;
503 }
504 data.WriteInt32(0);
505 data.WriteBool(bScanOnlyAvailable);
506 int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_SET_WIFI_SCAN_ONLY), data,
507 reply, option);
508 if (error != ERR_NONE) {
509 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
510 static_cast<int32_t>(ScanInterfaceCode::WIFI_SVR_CMD_SET_WIFI_SCAN_ONLY), error);
511 return WIFI_OPT_FAILED;
512 }
513
514 int exception = reply.ReadInt32();
515 if (exception) {
516 return WIFI_OPT_FAILED;
517 }
518 return ErrCode(reply.ReadInt32());
519 }
520
GetScanOnlyAvailable(bool & bScanOnlyAvailable)521 ErrCode WifiScanProxy::GetScanOnlyAvailable(bool &bScanOnlyAvailable)
522 {
523 if (mRemoteDied) {
524 WIFI_LOGE("failed to GetScanOnlyAvailable,remote service is died!");
525 return WIFI_OPT_FAILED;
526 }
527 MessageOption option;
528 MessageParcel data;
529 MessageParcel reply;
530 if (!data.WriteInterfaceToken(GetDescriptor())) {
531 WIFI_LOGE("GetScanOnlyAvailable Write interface token error!");
532 return WIFI_OPT_FAILED;
533 }
534 data.WriteInt32(0);
535 int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_GET_WIFI_SCAN_ONLY), data,
536 reply, option);
537 if (error != ERR_NONE) {
538 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
539 static_cast<int32_t>(ScanInterfaceCode::WIFI_SVR_CMD_GET_WIFI_SCAN_ONLY), error);
540 return WIFI_OPT_FAILED;
541 }
542 int exception = reply.ReadInt32();
543 if (exception) {
544 WIFI_LOGE("GetScanOnlyAvailable Reply exception failed!");
545 return WIFI_OPT_FAILED;
546 }
547 int ret = reply.ReadInt32();
548 if (ret != WIFI_OPT_SUCCESS) {
549 WIFI_LOGE("GetScanOnlyAvailable Reply ReadInt32 failed, ret:%{public}d", ret);
550 return ErrCode(ret);
551 }
552 bScanOnlyAvailable = reply.ReadBool();
553 return WIFI_OPT_SUCCESS;
554 }
555
StartWifiPnoScan(bool isStartAction,int periodMs,int suspendReason)556 ErrCode WifiScanProxy::StartWifiPnoScan(bool isStartAction, int periodMs, int suspendReason)
557 {
558 if (mRemoteDied) {
559 WIFI_LOGE("failed to StartWifiPnoScan, remote service is died!");
560 return WIFI_OPT_FAILED;
561 }
562 MessageOption option;
563 MessageParcel data;
564 MessageParcel reply;
565 if (!data.WriteInterfaceToken(GetDescriptor())) {
566 WIFI_LOGE("StartWifiPnoScan Write interface token error!");
567 return WIFI_OPT_FAILED;
568 }
569 data.WriteInt32(0);
570 data.WriteBool(isStartAction);
571 data.WriteInt32(periodMs);
572 data.WriteInt32(suspendReason);
573 int error = Remote()->SendRequest(static_cast<uint32_t>(ScanInterfaceCode::WIFI_SVR_CMD_START_PNO_SCAN), data,
574 reply, option);
575 if (error != ERR_NONE) {
576 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
577 static_cast<int32_t>(ScanInterfaceCode::WIFI_SVR_CMD_START_PNO_SCAN), error);
578 return WIFI_OPT_FAILED;
579 }
580 int exception = reply.ReadInt32();
581 if (exception) {
582 WIFI_LOGE("StartWifiPnoScan Reply exception failed!");
583 return WIFI_OPT_FAILED;
584 }
585 int ret = reply.ReadInt32();
586 if (ret != WIFI_OPT_SUCCESS) {
587 WIFI_LOGE("StartWifiPnoScan Reply ReadInt32 failed, ret:%{public}d", ret);
588 return ErrCode(ret);
589 }
590 return WIFI_OPT_SUCCESS;
591 }
592 } // namespace Wifi
593 } // namespace OHOS
594