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_proxy.h"
17 #include "define.h"
18 #include "wifi_manager_service_ipc_interface_code.h"
19 #include "wifi_common_util.h"
20 #include "wifi_device_callback_stub.h"
21 #include "wifi_hisysevent.h"
22 #include "wifi_logger.h"
23
24 DEFINE_WIFILOG_LABEL("WifiDeviceProxy");
25
26 namespace OHOS {
27 namespace Wifi {
28
29 constexpr int MAX_SIZE = 256;
30 constexpr int MAX_ASHMEM_SIZE = 300;
31 int g_bigDataRecvLen = 0;
32
33 static sptr<WifiDeviceCallBackStub> g_deviceCallBackStub =
34 sptr<WifiDeviceCallBackStub>(new (std::nothrow) WifiDeviceCallBackStub());
35
WifiDeviceProxy(const sptr<IRemoteObject> & impl)36 WifiDeviceProxy::WifiDeviceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IWifiDevice>(impl),
37 remote_(nullptr), mRemoteDied(false), deathRecipient_(nullptr)
38 {
39 std::lock_guard<std::mutex> lock(mutex_);
40 if (impl) {
41 if (!impl->IsProxyObject()) {
42 WIFI_LOGW("not proxy object!");
43 return;
44 }
45 deathRecipient_ = new (std::nothrow) WifiDeathRecipient(*this);
46 if (deathRecipient_ == nullptr) {
47 WIFI_LOGW("deathRecipient_ is nullptr!");
48 }
49 if (!impl->AddDeathRecipient(deathRecipient_)) {
50 WIFI_LOGW("AddDeathRecipient failed!");
51 return;
52 }
53 remote_ = impl;
54 WIFI_LOGD("AddDeathRecipient success! ");
55 }
56 }
57
~WifiDeviceProxy()58 WifiDeviceProxy::~WifiDeviceProxy()
59 {
60 WIFI_LOGD("enter ~WifiDeviceProxy!");
61 RemoveDeathRecipient();
62 }
63
RemoveDeathRecipient(void)64 void WifiDeviceProxy::RemoveDeathRecipient(void)
65 {
66 std::lock_guard<std::mutex> lock(mutex_);
67 if (remote_ == nullptr) {
68 WIFI_LOGI("remote_ is nullptr!");
69 return;
70 }
71 if (deathRecipient_ == nullptr) {
72 WIFI_LOGI("deathRecipient_ is nullptr!");
73 return;
74 }
75 remote_->RemoveDeathRecipient(deathRecipient_);
76 remote_ = nullptr;
77 }
78
EnableWifi()79 ErrCode WifiDeviceProxy::EnableWifi()
80 {
81 if (mRemoteDied) {
82 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
83 return WIFI_OPT_FAILED;
84 }
85 MessageOption option;
86 MessageParcel data;
87 MessageParcel reply;
88 if (!data.WriteInterfaceToken(GetDescriptor())) {
89 WIFI_LOGE("Write interface token error: %{public}s", __func__);
90 return WIFI_OPT_FAILED;
91 }
92 data.WriteInt32(0);
93 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_WIFI), data, reply,
94 option);
95 if (error != ERR_NONE) {
96 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
97 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_WIFI), error);
98 return WIFI_OPT_FAILED;
99 }
100
101 int exception = reply.ReadInt32();
102 if (exception) {
103 return WIFI_OPT_FAILED;
104 }
105 return ErrCode(reply.ReadInt32());
106 }
107
DisableWifi()108 ErrCode WifiDeviceProxy::DisableWifi()
109 {
110 if (mRemoteDied) {
111 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
112 return WIFI_OPT_FAILED;
113 }
114 MessageOption option;
115 MessageParcel data, reply;
116 if (!data.WriteInterfaceToken(GetDescriptor())) {
117 WIFI_LOGE("Write interface token error: %{public}s", __func__);
118 return WIFI_OPT_FAILED;
119 }
120 data.WriteInt32(0);
121 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_WIFI), data, reply,
122 option);
123 if (error != ERR_NONE) {
124 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
125 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_WIFI), error);
126 return WIFI_OPT_FAILED;
127 }
128 int exception = reply.ReadInt32();
129 if (exception) {
130 return WIFI_OPT_FAILED;
131 }
132 return ErrCode(reply.ReadInt32());
133 }
134
InitWifiProtect(const WifiProtectType & protectType,const std::string & protectName)135 ErrCode WifiDeviceProxy::InitWifiProtect(const WifiProtectType &protectType, const std::string &protectName)
136 {
137 if (mRemoteDied) {
138 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
139 return WIFI_OPT_FAILED;
140 }
141 MessageOption option;
142 MessageParcel data, reply;
143 if (!data.WriteInterfaceToken(GetDescriptor())) {
144 WIFI_LOGE("Write interface token error: %{public}s", __func__);
145 return WIFI_OPT_FAILED;
146 }
147 data.WriteInt32(0);
148 data.WriteInt32((int)protectType);
149 data.WriteCString(protectName.c_str());
150 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_INIT_WIFI_PROTECT), data,
151 reply, option);
152 if (error != ERR_NONE) {
153 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
154 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_INIT_WIFI_PROTECT), error);
155 return ErrCode(error);
156 }
157 int exception = reply.ReadInt32();
158 if (exception) {
159 return WIFI_OPT_FAILED;
160 }
161 int ret = reply.ReadInt32();
162 if (ret != WIFI_OPT_SUCCESS) {
163 return ErrCode(ret);
164 }
165
166 return WIFI_OPT_SUCCESS;
167 }
168
GetWifiProtectRef(const WifiProtectMode & protectMode,const std::string & protectName)169 ErrCode WifiDeviceProxy::GetWifiProtectRef(const WifiProtectMode &protectMode, const std::string &protectName)
170 {
171 if (mRemoteDied) {
172 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
173 return WIFI_OPT_FAILED;
174 }
175 MessageOption option;
176 MessageParcel data, reply;
177 if (!data.WriteInterfaceToken(GetDescriptor())) {
178 WIFI_LOGE("Write interface token error: %{public}s", __func__);
179 return WIFI_OPT_FAILED;
180 }
181 data.WriteInt32(0);
182 data.WriteInt32((int)protectMode);
183 data.WriteCString(protectName.c_str());
184 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_PROTECT), data,
185 reply, option);
186 if (error != ERR_NONE) {
187 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
188 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_PROTECT), error);
189 return ErrCode(error);
190 }
191 int exception = reply.ReadInt32();
192 if (exception) {
193 return WIFI_OPT_FAILED;
194 }
195 int ret = reply.ReadInt32();
196 if (ret != WIFI_OPT_SUCCESS) {
197 return ErrCode(ret);
198 }
199
200 return WIFI_OPT_SUCCESS;
201 }
202
PutWifiProtectRef(const std::string & protectName)203 ErrCode WifiDeviceProxy::PutWifiProtectRef(const std::string &protectName)
204 {
205 if (mRemoteDied) {
206 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
207 return WIFI_OPT_FAILED;
208 }
209 MessageOption option;
210 MessageParcel data, reply;
211 if (!data.WriteInterfaceToken(GetDescriptor())) {
212 WIFI_LOGE("Write interface token error: %{public}s", __func__);
213 return WIFI_OPT_FAILED;
214 }
215 data.WriteInt32(0);
216 data.WriteCString(protectName.c_str());
217 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_PUT_WIFI_PROTECT), data,
218 reply, option);
219 if (error != ERR_NONE) {
220 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
221 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_PUT_WIFI_PROTECT), error);
222 return ErrCode(error);
223 }
224 int exception = reply.ReadInt32();
225 if (exception) {
226 return WIFI_OPT_FAILED;
227 }
228 int ret = reply.ReadInt32();
229 if (ret != WIFI_OPT_SUCCESS) {
230 return ErrCode(ret);
231 }
232
233 return WIFI_OPT_SUCCESS;
234 }
235
IsHeldWifiProtectRef(const std::string & protectName,bool & isHoldProtect)236 ErrCode WifiDeviceProxy::IsHeldWifiProtectRef(
237 const std::string &protectName, bool &isHoldProtect)
238 {
239 if (mRemoteDied) {
240 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
241 return WIFI_OPT_FAILED;
242 }
243 MessageOption option;
244 MessageParcel data, reply;
245 if (!data.WriteInterfaceToken(GetDescriptor())) {
246 WIFI_LOGE("Write interface token error: %{public}s", __func__);
247 return WIFI_OPT_FAILED;
248 }
249 data.WriteInt32(0);
250 data.WriteCString(protectName.c_str());
251 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_HELD_WIFI_PROTECT), data,
252 reply, option);
253 if (error != ERR_NONE) {
254 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
255 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_HELD_WIFI_PROTECT), error);
256 return ErrCode(error);
257 }
258 int exception = reply.ReadInt32();
259 if (exception) {
260 return WIFI_OPT_FAILED;
261 }
262 int ret = reply.ReadInt32();
263 if (ret != WIFI_OPT_SUCCESS) {
264 return ErrCode(ret);
265 }
266
267 isHoldProtect = reply.ReadBool();
268 WIFI_LOGD("%{public}s result %{public}d", __func__, isHoldProtect);
269 return WIFI_OPT_SUCCESS;
270 }
271
WriteIpAddress(MessageParcel & data,const WifiIpAddress & address)272 void WifiDeviceProxy::WriteIpAddress(MessageParcel &data, const WifiIpAddress &address)
273 {
274 data.WriteInt32(address.family);
275 data.WriteInt32(address.addressIpv4);
276 int size = static_cast<int>(address.addressIpv6.size());
277 data.WriteInt32(size);
278 for (int i = 0; i < size; i++) {
279 data.WriteInt8(address.addressIpv6[i]);
280 }
281 return;
282 }
283
WriteEapConfig(MessageParcel & data,const WifiEapConfig & wifiEapConfig)284 void WifiDeviceProxy::WriteEapConfig(MessageParcel &data, const WifiEapConfig &wifiEapConfig)
285 {
286 data.WriteString(wifiEapConfig.eap);
287 data.WriteInt32(static_cast<int>(wifiEapConfig.phase2Method));
288 data.WriteString(wifiEapConfig.identity);
289 data.WriteString(wifiEapConfig.anonymousIdentity);
290 data.WriteString(wifiEapConfig.password);
291
292 data.WriteString(wifiEapConfig.caCertPath);
293 data.WriteString(wifiEapConfig.caCertAlias);
294 data.WriteUInt8Vector(wifiEapConfig.certEntry);
295
296 data.WriteString(wifiEapConfig.clientCert);
297 data.WriteString(std::string(wifiEapConfig.certPassword));
298 data.WriteString(wifiEapConfig.privateKey);
299
300 data.WriteString(wifiEapConfig.altSubjectMatch);
301 data.WriteString(wifiEapConfig.domainSuffixMatch);
302 data.WriteString(wifiEapConfig.realm);
303 data.WriteString(wifiEapConfig.plmn);
304 data.WriteInt32(wifiEapConfig.eapSubId);
305 }
306
WriteDeviceConfig(const WifiDeviceConfig & config,MessageParcel & data)307 void WifiDeviceProxy::WriteDeviceConfig(const WifiDeviceConfig &config, MessageParcel &data)
308 {
309 data.WriteInt32(config.networkId);
310 data.WriteInt32(config.status);
311 data.WriteString(config.bssid);
312 data.WriteInt32(config.bssidType);
313 data.WriteString(config.ssid);
314 data.WriteInt32(config.band);
315 data.WriteInt32(config.channel);
316 data.WriteInt32(config.frequency);
317 data.WriteInt32(config.level);
318 data.WriteBool(config.isPasspoint);
319 data.WriteBool(config.isEphemeral);
320 data.WriteString(config.preSharedKey);
321 data.WriteString(config.keyMgmt);
322 for (int i = 0; i < WEPKEYS_SIZE; i++) {
323 data.WriteString(config.wepKeys[i]);
324 }
325 data.WriteInt32(config.wepTxKeyIndex);
326 data.WriteInt32(config.priority);
327 data.WriteBool(config.hiddenSSID);
328 data.WriteInt32((int)config.wifiIpConfig.assignMethod);
329 WriteIpAddress(data, config.wifiIpConfig.staticIpAddress.ipAddress.address);
330 data.WriteInt32(config.wifiIpConfig.staticIpAddress.ipAddress.prefixLength);
331 data.WriteInt32(config.wifiIpConfig.staticIpAddress.ipAddress.flags);
332 data.WriteInt32(config.wifiIpConfig.staticIpAddress.ipAddress.scope);
333 WriteIpAddress(data, config.wifiIpConfig.staticIpAddress.gateway);
334 WriteIpAddress(data, config.wifiIpConfig.staticIpAddress.dnsServer1);
335 WriteIpAddress(data, config.wifiIpConfig.staticIpAddress.dnsServer2);
336 data.WriteString(config.wifiIpConfig.staticIpAddress.domains);
337 WriteEapConfig(data, config.wifiEapConfig);
338 data.WriteInt32((int)config.wifiProxyconfig.configureMethod);
339 data.WriteString(config.wifiProxyconfig.autoProxyConfig.pacWebAddress);
340 data.WriteString(config.wifiProxyconfig.manualProxyConfig.serverHostName);
341 data.WriteInt32(config.wifiProxyconfig.manualProxyConfig.serverPort);
342 data.WriteString(config.wifiProxyconfig.manualProxyConfig.exclusionObjectList);
343 data.WriteInt32((int)config.wifiPrivacySetting);
344 data.WriteString(config.callProcessName);
345 data.WriteString(config.ancoCallProcessName);
346 data.WriteInt32(config.uid);
347 data.WriteInt32(config.wifiWapiConfig.wapiPskType);
348 data.WriteString(config.wifiWapiConfig.wapiAsCertData);
349 data.WriteString(config.wifiWapiConfig.wapiUserCertData);
350 }
351
RemoveCandidateConfig(const WifiDeviceConfig & config)352 ErrCode WifiDeviceProxy::RemoveCandidateConfig(const WifiDeviceConfig &config)
353 {
354 if (mRemoteDied) {
355 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
356 return WIFI_OPT_FAILED;
357 }
358 MessageOption option;
359 MessageParcel data, reply;
360 if (!data.WriteInterfaceToken(GetDescriptor())) {
361 WIFI_LOGE("Write interface token error: %{public}s", __func__);
362 return WIFI_OPT_FAILED;
363 }
364 data.WriteInt32(0);
365 /* Write a flag: 1-remove config by networkId, 2-remove config by WifiDeviceConfig */
366 data.WriteInt32(2);
367 WriteDeviceConfig(config, data);
368 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_CANDIDATE_CONFIG),
369 data, reply, option);
370 if (error != ERR_NONE) {
371 WIFI_LOGE("Set Attr(%{public}d) failed,error=%{public}d",
372 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_CANDIDATE_CONFIG), error);
373 return WIFI_OPT_FAILED;
374 }
375 int exception = reply.ReadInt32();
376 if (exception) {
377 return WIFI_OPT_FAILED;
378 }
379 int ret = reply.ReadInt32();
380 if (ret != WIFI_OPT_SUCCESS) {
381 return ErrCode(ret);
382 }
383
384 return WIFI_OPT_SUCCESS;
385 }
386
RemoveCandidateConfig(int networkId)387 ErrCode WifiDeviceProxy::RemoveCandidateConfig(int networkId)
388 {
389 if (mRemoteDied) {
390 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
391 return WIFI_OPT_FAILED;
392 }
393 MessageOption option;
394 MessageParcel data, reply;
395 if (!data.WriteInterfaceToken(GetDescriptor())) {
396 WIFI_LOGE("Write interface token error: %{public}s", __func__);
397 return WIFI_OPT_FAILED;
398 }
399 data.WriteInt32(0);
400 /* Write a flag: 1-remove config by networkId, 2-remove config by WifiDeviceConfig */
401 data.WriteInt32(1);
402 data.WriteInt32(networkId);
403 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_CANDIDATE_CONFIG),
404 data, reply, option);
405 if (error != ERR_NONE) {
406 WIFI_LOGE("Set Attr(%{public}d) failed,error=%{public}d",
407 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_CANDIDATE_CONFIG), error);
408 return WIFI_OPT_FAILED;
409 }
410 int exception = reply.ReadInt32();
411 if (exception) {
412 return WIFI_OPT_FAILED;
413 }
414 return ErrCode(reply.ReadInt32());
415 }
416
AddDeviceConfig(const WifiDeviceConfig & config,int & result,bool isCandidate)417 ErrCode WifiDeviceProxy::AddDeviceConfig(const WifiDeviceConfig &config, int &result, bool isCandidate)
418 {
419 if (mRemoteDied) {
420 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
421 return WIFI_OPT_FAILED;
422 }
423 MessageOption option;
424 MessageParcel data, reply;
425 if (!data.WriteInterfaceToken(GetDescriptor())) {
426 WIFI_LOGE("Write interface token error: %{public}s", __func__);
427 return WIFI_OPT_FAILED;
428 }
429 data.WriteInt32(0);
430 /* true-candidate config, false-normal config */
431 data.WriteBool(isCandidate);
432 WriteDeviceConfig(config, data);
433 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ADD_DEVICE_CONFIG),
434 data, reply, option);
435 if (error != ERR_NONE) {
436 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
437 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ADD_DEVICE_CONFIG), error);
438 return WIFI_OPT_FAILED;
439 }
440 int exception = reply.ReadInt32();
441 if (exception) {
442 return WIFI_OPT_FAILED;
443 }
444 int ret = reply.ReadInt32();
445 if (ret != WIFI_OPT_SUCCESS) {
446 return ErrCode(ret);
447 }
448 result = reply.ReadInt32();
449
450 return WIFI_OPT_SUCCESS;
451 }
452
UpdateDeviceConfig(const WifiDeviceConfig & config,int & result)453 ErrCode WifiDeviceProxy::UpdateDeviceConfig(const WifiDeviceConfig &config, int &result)
454 {
455 if (mRemoteDied) {
456 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
457 return WIFI_OPT_FAILED;
458 }
459
460 MessageOption option;
461 MessageParcel data, reply;
462 if (!data.WriteInterfaceToken(GetDescriptor())) {
463 WIFI_LOGE("Write interface token error: %{public}s", __func__);
464 return WIFI_OPT_FAILED;
465 }
466 data.WriteInt32(0);
467 WriteDeviceConfig(config, data);
468 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_UPDATE_DEVICE_CONFIG), data,
469 reply, option);
470 if (error != ERR_NONE) {
471 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
472 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_UPDATE_DEVICE_CONFIG), error);
473 return WIFI_OPT_FAILED;
474 }
475 int exception = reply.ReadInt32();
476 if (exception) {
477 return WIFI_OPT_FAILED;
478 }
479 int ret = reply.ReadInt32();
480 if (ret != WIFI_OPT_SUCCESS) {
481 return ErrCode(ret);
482 }
483 result = reply.ReadInt32();
484 return WIFI_OPT_SUCCESS;
485 }
486
RemoveDevice(int networkId)487 ErrCode WifiDeviceProxy::RemoveDevice(int networkId)
488 {
489 if (mRemoteDied) {
490 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
491 return WIFI_OPT_FAILED;
492 }
493 MessageOption option;
494 MessageParcel data, reply;
495 if (!data.WriteInterfaceToken(GetDescriptor())) {
496 WIFI_LOGE("Write interface token error: %{public}s", __func__);
497 return WIFI_OPT_FAILED;
498 }
499 data.WriteInt32(0);
500 data.WriteInt32(networkId);
501 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_DEVICE_CONFIG),
502 data, reply, option);
503 if (error != ERR_NONE) {
504 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
505 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_DEVICE_CONFIG), error);
506 return WIFI_OPT_FAILED;
507 }
508 int exception = reply.ReadInt32();
509 if (exception) {
510 return WIFI_OPT_FAILED;
511 }
512 return ErrCode(reply.ReadInt32());
513 }
514
RemoveAllDevice()515 ErrCode WifiDeviceProxy::RemoveAllDevice()
516 {
517 if (mRemoteDied) {
518 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
519 return WIFI_OPT_FAILED;
520 }
521 MessageOption option;
522 MessageParcel data;
523 MessageParcel reply;
524 if (!data.WriteInterfaceToken(GetDescriptor())) {
525 WIFI_LOGE("Write interface token error: %{public}s", __func__);
526 return WIFI_OPT_FAILED;
527 }
528 data.WriteInt32(0);
529 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_ALL_DEVICE_CONFIG),
530 data, reply, option);
531 if (error != ERR_NONE) {
532 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
533 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_ALL_DEVICE_CONFIG), error);
534 return WIFI_OPT_FAILED;
535 }
536
537 int exception = reply.ReadInt32();
538 if (exception) {
539 return WIFI_OPT_FAILED;
540 }
541 return ErrCode(reply.ReadInt32());
542 }
543
ReadIpAddress(MessageParcel & reply,WifiIpAddress & address)544 void WifiDeviceProxy::ReadIpAddress(MessageParcel &reply, WifiIpAddress &address)
545 {
546 address.family = reply.ReadInt32();
547 address.addressIpv4 = static_cast<uint32_t>(reply.ReadInt32());
548 int size = reply.ReadInt32();
549 if (size > MAX_SIZE) {
550 WIFI_LOGE("Read IP address size error: %{public}d", size);
551 return;
552 }
553 for (int i = 0; i < size; i++) {
554 address.addressIpv6.push_back(reply.ReadInt8());
555 }
556 return;
557 }
558
BigDataReadIpAddress(WifiIpAddress & address,std::vector<std::string> & tokens)559 void WifiDeviceProxy::BigDataReadIpAddress(WifiIpAddress &address, std::vector<std::string> &tokens)
560 {
561 address.family = CheckDataLegal(tokens[g_bigDataRecvLen++]);
562 address.addressIpv4 = static_cast<size_t>(CheckDataLegal(tokens[g_bigDataRecvLen++]));
563 int size = CheckDataLegal(tokens[g_bigDataRecvLen++]);
564 if (size > MAX_SIZE) {
565 WIFI_LOGE("Read IP address size error: %{public}d", size);
566 return;
567 }
568 for (int i = 0; i < size; i++) {
569 address.addressIpv6.push_back(CheckDataLegal(tokens[g_bigDataRecvLen++]));
570 }
571 return;
572 }
573
ReadEapConfig(MessageParcel & reply,WifiEapConfig & wifiEapConfig)574 void WifiDeviceProxy::ReadEapConfig(MessageParcel &reply, WifiEapConfig &wifiEapConfig)
575 {
576 wifiEapConfig.eap = reply.ReadString();
577 wifiEapConfig.phase2Method = Phase2Method(reply.ReadInt32());
578 wifiEapConfig.identity = reply.ReadString();
579 wifiEapConfig.anonymousIdentity = reply.ReadString();
580 wifiEapConfig.password = reply.ReadString();
581 wifiEapConfig.caCertPath = reply.ReadString();
582 wifiEapConfig.caCertAlias = reply.ReadString();
583 reply.ReadUInt8Vector(&wifiEapConfig.certEntry);
584 wifiEapConfig.clientCert = reply.ReadString();
585 if (strcpy_s(wifiEapConfig.certPassword, sizeof(wifiEapConfig.certPassword),
586 reply.ReadString().c_str()) != EOK) {
587 WIFI_LOGE("%{public}s: failed to copy", __func__);
588 }
589 wifiEapConfig.privateKey = reply.ReadString();
590 wifiEapConfig.altSubjectMatch = reply.ReadString();
591 wifiEapConfig.domainSuffixMatch = reply.ReadString();
592 wifiEapConfig.realm = reply.ReadString();
593 wifiEapConfig.plmn = reply.ReadString();
594 wifiEapConfig.eapSubId = reply.ReadInt32();
595 }
596
BigDataReadEapConfig(WifiEapConfig & wifiEapConfig,std::vector<std::string> & tokens)597 void WifiDeviceProxy::BigDataReadEapConfig(WifiEapConfig &wifiEapConfig, std::vector<std::string> &tokens)
598 {
599 wifiEapConfig.eap = HexToString(tokens[g_bigDataRecvLen++]);
600 wifiEapConfig.phase2Method = Phase2Method(CheckDataLegal(tokens[g_bigDataRecvLen++]));
601 wifiEapConfig.identity = HexToString(tokens[g_bigDataRecvLen++]);
602 wifiEapConfig.anonymousIdentity = HexToString(tokens[g_bigDataRecvLen++]);
603 wifiEapConfig.password = HexToString(tokens[g_bigDataRecvLen++]);
604 wifiEapConfig.caCertPath = HexToString(tokens[g_bigDataRecvLen++]);
605 wifiEapConfig.caCertAlias = HexToString(tokens[g_bigDataRecvLen++]);
606 wifiEapConfig.clientCert = HexToString(tokens[g_bigDataRecvLen++]);
607 wifiEapConfig.privateKey = HexToString(tokens[g_bigDataRecvLen++]);
608 wifiEapConfig.altSubjectMatch = HexToString(tokens[g_bigDataRecvLen++]);
609 wifiEapConfig.domainSuffixMatch = HexToString(tokens[g_bigDataRecvLen++]);
610 wifiEapConfig.realm = HexToString(tokens[g_bigDataRecvLen++]);
611 wifiEapConfig.plmn = HexToString(tokens[g_bigDataRecvLen++]);
612 wifiEapConfig.eapSubId = CheckDataLegal(tokens[g_bigDataRecvLen++]);
613 }
614
splitString(std::string str,char delimiter)615 std::vector<std::string> splitString(std::string str, char delimiter)
616 {
617 std::vector<std::string> tokens;
618 std::string token;
619 size_t pos = 0;
620 while ((pos = str.find(delimiter)) != std::string::npos) {
621 token = str.substr(0, pos);
622 tokens.push_back(token);
623 str.erase(0, pos + 1);
624 }
625 tokens.push_back(str);
626 return tokens;
627 }
628
ParseBigConfig(MessageParcel & reply,std::vector<WifiDeviceConfig> & result,int retSize,long len)629 void WifiDeviceProxy::ParseBigConfig(MessageParcel &reply, std::vector<WifiDeviceConfig> &result, int retSize,
630 long len)
631 {
632 WIFI_LOGI("WifiDeviceProxy ParseBigConfig");
633 sptr<Ashmem> ashmem = reply.ReadAshmem();
634 if (ashmem == nullptr || !ashmem->MapReadAndWriteAshmem()) {
635 WIFI_LOGE("ParseDeviceConfigs ReadAshmem error");
636 return;
637 }
638
639 std::string net = (char *)ashmem->ReadFromAshmem(len, 0);
640 std::vector<std::string> tokens = splitString(net, ';');
641 for (int m = 0; m < retSize; ++m) {
642 WifiDeviceConfig config;
643 config.networkId = CheckDataLegal(tokens[g_bigDataRecvLen++]);
644 config.status = CheckDataLegal(tokens[g_bigDataRecvLen++]);
645 config.bssid = HexToString(tokens[g_bigDataRecvLen++]);
646 config.bssidType = CheckDataLegal(tokens[g_bigDataRecvLen++]);
647 config.ssid = HexToString(tokens[g_bigDataRecvLen++]);
648 config.band = CheckDataLegal(tokens[g_bigDataRecvLen++]);
649 config.channel = CheckDataLegal(tokens[g_bigDataRecvLen++]);
650 config.frequency = CheckDataLegal(tokens[g_bigDataRecvLen++]);
651 config.level = CheckDataLegal(tokens[g_bigDataRecvLen++]);
652 config.isPasspoint = CheckDataLegal(tokens[g_bigDataRecvLen++]);
653 config.isEphemeral = CheckDataLegal(tokens[g_bigDataRecvLen++]);
654 config.preSharedKey = HexToString(tokens[g_bigDataRecvLen++]);
655 config.keyMgmt = HexToString(tokens[g_bigDataRecvLen++]);
656 for (int j = 0; j < WEPKEYS_SIZE; j++) {
657 config.wepKeys[j] = HexToString(tokens[g_bigDataRecvLen++]);
658 }
659 config.wepTxKeyIndex = CheckDataLegal(tokens[g_bigDataRecvLen++]);
660 config.priority = CheckDataLegal(tokens[g_bigDataRecvLen++]);
661 config.hiddenSSID = CheckDataLegal(tokens[g_bigDataRecvLen++]);
662 config.wifiIpConfig.assignMethod = AssignIpMethod(CheckDataLegal(tokens[g_bigDataRecvLen++]));
663 BigDataReadIpAddress(config.wifiIpConfig.staticIpAddress.ipAddress.address, tokens);
664 config.wifiIpConfig.staticIpAddress.ipAddress.prefixLength = CheckDataLegal(tokens[g_bigDataRecvLen++]);
665 config.wifiIpConfig.staticIpAddress.ipAddress.flags = CheckDataLegal(tokens[g_bigDataRecvLen++]);
666 config.wifiIpConfig.staticIpAddress.ipAddress.scope = CheckDataLegal(tokens[g_bigDataRecvLen++]);
667 BigDataReadIpAddress(config.wifiIpConfig.staticIpAddress.gateway, tokens);
668 BigDataReadIpAddress(config.wifiIpConfig.staticIpAddress.dnsServer1, tokens);
669 BigDataReadIpAddress(config.wifiIpConfig.staticIpAddress.dnsServer2, tokens);
670 config.wifiIpConfig.staticIpAddress.domains = HexToString(tokens[g_bigDataRecvLen++]);
671 BigDataReadEapConfig(config.wifiEapConfig, tokens);
672 config.wifiProxyconfig.configureMethod = ConfigureProxyMethod(CheckDataLegal(tokens[g_bigDataRecvLen++]));
673 config.wifiProxyconfig.autoProxyConfig.pacWebAddress = HexToString(tokens[g_bigDataRecvLen++]);
674 config.wifiProxyconfig.manualProxyConfig.serverHostName = HexToString(tokens[g_bigDataRecvLen++]);
675 config.wifiProxyconfig.manualProxyConfig.serverPort = CheckDataLegal(tokens[g_bigDataRecvLen++]);
676 config.wifiProxyconfig.manualProxyConfig.exclusionObjectList = HexToString(tokens[g_bigDataRecvLen++]);
677 config.wifiPrivacySetting = WifiPrivacyConfig(CheckDataLegal(tokens[g_bigDataRecvLen++]));
678 config.uid = CheckDataLegal(tokens[g_bigDataRecvLen++]);
679 config.callProcessName = HexToString(tokens[g_bigDataRecvLen++]);
680 config.ancoCallProcessName = HexToString(tokens[g_bigDataRecvLen++]);
681 config.networkSelectionStatus.status = WifiDeviceConfigStatus(CheckDataLegal(tokens[g_bigDataRecvLen++]));
682 config.networkSelectionStatus.networkSelectionDisableReason =
683 DisabledReason(CheckDataLegal(tokens[g_bigDataRecvLen++]));
684 result.emplace_back(config);
685 }
686 g_bigDataRecvLen = 0;
687 ashmem->UnmapAshmem();
688 ashmem->CloseAshmem();
689
690 return;
691 }
692
ParseSmallConfig(MessageParcel & reply,std::vector<WifiDeviceConfig> & result,int retSize)693 void WifiDeviceProxy::ParseSmallConfig(MessageParcel &reply, std::vector<WifiDeviceConfig> &result, int retSize)
694 {
695 for (int i = 0; i < retSize; ++i) {
696 WifiDeviceConfig config;
697 config.networkId = reply.ReadInt32();
698 config.status = reply.ReadInt32();
699 config.bssid = reply.ReadString();
700 config.bssidType = reply.ReadInt32();
701 config.ssid = reply.ReadString();
702 config.band = reply.ReadInt32();
703 config.channel = reply.ReadInt32();
704 config.frequency = reply.ReadInt32();
705 config.level = reply.ReadInt32();
706 config.isPasspoint = reply.ReadBool();
707 config.isEphemeral = reply.ReadBool();
708 config.preSharedKey = reply.ReadString();
709 config.keyMgmt = reply.ReadString();
710 for (int j = 0; j < WEPKEYS_SIZE; j++) {
711 config.wepKeys[j] = reply.ReadString();
712 }
713 config.wepTxKeyIndex = reply.ReadInt32();
714 config.priority = reply.ReadInt32();
715 config.hiddenSSID = reply.ReadBool();
716 config.wifiIpConfig.assignMethod = AssignIpMethod(reply.ReadInt32());
717 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.ipAddress.address);
718 config.wifiIpConfig.staticIpAddress.ipAddress.prefixLength = reply.ReadInt32();
719 config.wifiIpConfig.staticIpAddress.ipAddress.flags = reply.ReadInt32();
720 config.wifiIpConfig.staticIpAddress.ipAddress.scope = reply.ReadInt32();
721 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.gateway);
722 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.dnsServer1);
723 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.dnsServer2);
724 config.wifiIpConfig.staticIpAddress.domains = reply.ReadString();
725 ReadEapConfig(reply, config.wifiEapConfig);
726 config.wifiProxyconfig.configureMethod = ConfigureProxyMethod(reply.ReadInt32());
727 config.wifiProxyconfig.autoProxyConfig.pacWebAddress = reply.ReadString();
728 config.wifiProxyconfig.manualProxyConfig.serverHostName = reply.ReadString();
729 config.wifiProxyconfig.manualProxyConfig.serverPort = reply.ReadInt32();
730 config.wifiProxyconfig.manualProxyConfig.exclusionObjectList = reply.ReadString();
731 config.wifiPrivacySetting = WifiPrivacyConfig(reply.ReadInt32());
732 config.uid = reply.ReadInt32();
733 config.callProcessName = reply.ReadString();
734 config.ancoCallProcessName = reply.ReadString();
735 config.wifiWapiConfig.wapiPskType = reply.ReadInt32();
736 config.networkSelectionStatus.status = WifiDeviceConfigStatus(reply.ReadInt32());
737 config.networkSelectionStatus.networkSelectionDisableReason = DisabledReason(reply.ReadInt32());
738 result.emplace_back(config);
739 }
740 }
741
ParseDeviceConfigs(MessageParcel & reply,std::vector<WifiDeviceConfig> & result)742 void WifiDeviceProxy::ParseDeviceConfigs(MessageParcel &reply, std::vector<WifiDeviceConfig> &result)
743 {
744 WIFI_LOGI("ParseDeviceConfigs");
745 constexpr int MAX_DEVICE_CONFIG_SIZE = 1024;
746 int retSize = reply.ReadInt32();
747 if (retSize > MAX_DEVICE_CONFIG_SIZE || retSize == 0) {
748 WIFI_LOGE("Parse device config size error: %{public}d", retSize);
749 return;
750 }
751 if (retSize > MAX_ASHMEM_SIZE) {
752 long len = reply.ReadInt64();
753 ParseBigConfig(reply, result, retSize, len);
754 return;
755 }
756
757 ParseSmallConfig(reply, result, retSize);
758
759 return;
760 }
761
GetDeviceConfigs(std::vector<WifiDeviceConfig> & result,bool isCandidate)762 ErrCode WifiDeviceProxy::GetDeviceConfigs(std::vector<WifiDeviceConfig> &result, bool isCandidate)
763 {
764 if (mRemoteDied) {
765 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
766 return WIFI_OPT_FAILED;
767 }
768 MessageOption option;
769 MessageParcel data;
770 MessageParcel reply;
771 if (!data.WriteInterfaceToken(GetDescriptor())) {
772 WIFI_LOGE("Write interface token error: %{public}s", __func__);
773 return WIFI_OPT_FAILED;
774 }
775 data.WriteInt32(0);
776 /* true-candidate config, false-normal config */
777 data.WriteBool(isCandidate);
778 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIGS),
779 data, reply, option);
780 if (error != ERR_NONE) {
781 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
782 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIGS), error);
783 return WIFI_OPT_FAILED;
784 }
785 int exception = reply.ReadInt32();
786 if (exception) {
787 return WIFI_OPT_FAILED;
788 }
789 int ret = reply.ReadInt32();
790 if (ret != WIFI_OPT_SUCCESS) {
791 return ErrCode(ret);
792 }
793
794 ParseDeviceConfigs(reply, result);
795 return WIFI_OPT_SUCCESS;
796 }
797
SetTxPower(int power)798 ErrCode WifiDeviceProxy::SetTxPower(int power)
799 {
800 if (mRemoteDied) {
801 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
802 return WIFI_OPT_FAILED;
803 }
804 MessageOption option;
805 MessageParcel data;
806 MessageParcel reply;
807 if (!data.WriteInterfaceToken(GetDescriptor())) {
808 WIFI_LOGE("Write interface token error: %{public}s", __func__);
809 return WIFI_OPT_FAILED;
810 }
811 data.WriteInt32(0);
812 data.WriteInt32(power);
813 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_TX_POWER), data, reply,
814 option);
815 if (error != ERR_NONE) {
816 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
817 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_TX_POWER), error);
818 return WIFI_OPT_FAILED;
819 }
820 int exception = reply.ReadInt32();
821 if (exception) {
822 return WIFI_OPT_FAILED;
823 }
824 return ErrCode(reply.ReadInt32());
825 }
826
EnableDeviceConfig(int networkId,bool attemptEnable)827 ErrCode WifiDeviceProxy::EnableDeviceConfig(int networkId, bool attemptEnable)
828 {
829 if (mRemoteDied) {
830 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
831 return WIFI_OPT_FAILED;
832 }
833 MessageOption option;
834 MessageParcel data, reply;
835 if (!data.WriteInterfaceToken(GetDescriptor())) {
836 WIFI_LOGE("Write interface token error: %{public}s", __func__);
837 return WIFI_OPT_FAILED;
838 }
839 data.WriteInt32(0);
840 data.WriteInt32(networkId);
841 data.WriteInt32(attemptEnable);
842 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_DEVICE), data, reply,
843 option);
844 if (error != ERR_NONE) {
845 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
846 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_DEVICE), error);
847 return WIFI_OPT_FAILED;
848 }
849 int exception = reply.ReadInt32();
850 if (exception) {
851 return WIFI_OPT_FAILED;
852 }
853 return ErrCode(reply.ReadInt32());
854 }
855
DisableDeviceConfig(int networkId)856 ErrCode WifiDeviceProxy::DisableDeviceConfig(int networkId)
857 {
858 if (mRemoteDied) {
859 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
860 return WIFI_OPT_FAILED;
861 }
862 MessageOption option;
863 MessageParcel data, reply;
864 if (!data.WriteInterfaceToken(GetDescriptor())) {
865 WIFI_LOGE("Write interface token error: %{public}s", __func__);
866 return WIFI_OPT_FAILED;
867 }
868 data.WriteInt32(0);
869 data.WriteInt32(networkId);
870 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_DEVICE), data, reply,
871 option);
872 if (error != ERR_NONE) {
873 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
874 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_DEVICE), error);
875 return WIFI_OPT_FAILED;
876 }
877 int exception = reply.ReadInt32();
878 if (exception) {
879 return WIFI_OPT_FAILED;
880 }
881 return ErrCode(reply.ReadInt32());
882 }
883
ConnectToNetwork(int networkId,bool isCandidate)884 ErrCode WifiDeviceProxy::ConnectToNetwork(int networkId, bool isCandidate)
885 {
886 if (mRemoteDied) {
887 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
888 return WIFI_OPT_FAILED;
889 }
890 MessageOption option;
891 MessageParcel data, reply;
892 if (!data.WriteInterfaceToken(GetDescriptor())) {
893 WIFI_LOGE("Write interface token error: %{public}s", __func__);
894 return WIFI_OPT_FAILED;
895 }
896 data.WriteInt32(0);
897 /* true-candidate config, false-normal config */
898 data.WriteBool(isCandidate);
899 data.WriteInt32(networkId);
900 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT_TO), data, reply,
901 option);
902 if (error != ERR_NONE) {
903 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
904 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT_TO), error);
905 return WIFI_OPT_FAILED;
906 }
907 int exception = reply.ReadInt32();
908 if (exception) {
909 return WIFI_OPT_FAILED;
910 }
911 return ErrCode(reply.ReadInt32());
912 }
913
ConnectToDevice(const WifiDeviceConfig & config)914 ErrCode WifiDeviceProxy::ConnectToDevice(const WifiDeviceConfig &config)
915 {
916 if (mRemoteDied) {
917 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
918 return WIFI_OPT_FAILED;
919 }
920 MessageOption option;
921 MessageParcel data, reply;
922 if (!data.WriteInterfaceToken(GetDescriptor())) {
923 WIFI_LOGE("Write interface token error: %{public}s", __func__);
924 return WIFI_OPT_FAILED;
925 }
926 data.WriteInt32(0);
927 WriteDeviceConfig(config, data);
928 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT2_TO), data, reply,
929 option);
930 if (error != ERR_NONE) {
931 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
932 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT2_TO), error);
933 return WIFI_OPT_FAILED;
934 }
935 int exception = reply.ReadInt32();
936 if (exception) {
937 return WIFI_OPT_FAILED;
938 }
939 return ErrCode(reply.ReadInt32());
940 }
941
StartRoamToNetwork(const int networkId,const std::string bssid,const bool isCandidate)942 ErrCode WifiDeviceProxy::StartRoamToNetwork(const int networkId, const std::string bssid, const bool isCandidate)
943 {
944 if (mRemoteDied) {
945 WIFI_LOGE("failed to %{public}s,remote service is died!", __func__);
946 return WIFI_OPT_FAILED;
947 }
948 MessageOption option;
949 MessageParcel data;
950 MessageParcel reply;
951 if (!data.WriteInterfaceToken(GetDescriptor())) {
952 WIFI_LOGE("%{public}s write interface token error.", __func__);
953 return WIFI_OPT_FAILED;
954 }
955 data.WriteInt32(0);
956 data.WriteInt32(networkId);
957 data.WriteString(bssid);
958 data.WriteInt32(isCandidate);
959 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_ROAM_TO_NETWORK), data,
960 reply, option);
961 if (error != ERR_NONE) {
962 WIFI_LOGE("StartRoamToNetwork %{public}d failed, error code is %{public}d",
963 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_ROAM_TO_NETWORK), error);
964 return WIFI_OPT_FAILED;
965 }
966 int exception = reply.ReadInt32();
967 if (exception) {
968 WIFI_LOGE("StartRoamToNetwork Reply Read failed, exception:%{public}d", exception);
969 return WIFI_OPT_FAILED;
970 }
971 int ret = reply.ReadInt32();
972 if (ret != WIFI_OPT_SUCCESS) {
973 WIFI_LOGE("StartRoamToNetwork Reply Read failed, ret:%{public}d", ret);
974 return ErrCode(ret);
975 }
976 return WIFI_OPT_SUCCESS;
977 }
978
StartConnectToUserSelectNetwork(const int networkId,const std::string bssid,const bool isCandidate)979 ErrCode WifiDeviceProxy::StartConnectToUserSelectNetwork(const int networkId,
980 const std::string bssid, const bool isCandidate)
981 {
982 if (mRemoteDied) {
983 WIFI_LOGE("failed to StartConnectToUserSelectNetwork, remote service is died!");
984 return WIFI_OPT_FAILED;
985 }
986 MessageOption option;
987 MessageParcel data;
988 MessageParcel reply;
989 if (!data.WriteInterfaceToken(GetDescriptor())) {
990 WIFI_LOGE("Write interface token has error: %{public}s", __func__);
991 return WIFI_OPT_FAILED;
992 }
993 data.WriteInt32(0);
994 data.WriteInt32(networkId);
995 data.WriteString(bssid);
996 data.WriteInt32(isCandidate);
997 int error = Remote()->SendRequest(static_cast<uint32_t>(
998 DevInterfaceCode::WIFI_SVR_CMD_START_CONNECT_TO_USER_SELECT_NETWORK), data, reply, option);
999 if (error != ERR_NONE) {
1000 WIFI_LOGE("StartConnectToUserSelectNetwork %{public}d failed, error code is %{public}d",
1001 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_ROAM_TO_NETWORK), error);
1002 return WIFI_OPT_FAILED;
1003 }
1004 int exception = reply.ReadInt32();
1005 if (exception) {
1006 WIFI_LOGE("StartConnectToUserSelectNetwork Reply Read failed, exception:%{public}d", exception);
1007 return WIFI_OPT_FAILED;
1008 }
1009 int ret = reply.ReadInt32();
1010 if (ret != WIFI_OPT_SUCCESS) {
1011 WIFI_LOGE("StartConnectToUserSelectNetwork Reply Read failed, ret:%{public}d", ret);
1012 return ErrCode(ret);
1013 }
1014 return WIFI_OPT_SUCCESS;
1015 }
1016
IsConnected(bool & isConnected)1017 ErrCode WifiDeviceProxy::IsConnected(bool &isConnected)
1018 {
1019 if (mRemoteDied) {
1020 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1021 return WIFI_OPT_FAILED;
1022 }
1023 MessageOption option;
1024 MessageParcel data, reply;
1025 if (!data.WriteInterfaceToken(GetDescriptor())) {
1026 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1027 return WIFI_OPT_FAILED;
1028 }
1029 data.WriteInt32(0);
1030 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_CONNECTED), data,
1031 reply, option);
1032 if (error != ERR_NONE) {
1033 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1034 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_CONNECTED), error);
1035 return WIFI_OPT_FAILED;
1036 }
1037 int exception = reply.ReadInt32();
1038 if (exception) {
1039 return WIFI_OPT_FAILED;
1040 }
1041 int ret = reply.ReadInt32();
1042 if (ret != WIFI_OPT_SUCCESS) {
1043 return ErrCode(ret);
1044 }
1045 isConnected = reply.ReadBool();
1046 return WIFI_OPT_SUCCESS;
1047 }
1048
ReConnect()1049 ErrCode WifiDeviceProxy::ReConnect()
1050 {
1051 if (mRemoteDied) {
1052 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1053 return WIFI_OPT_FAILED;
1054 }
1055 MessageOption option;
1056 MessageParcel data, reply;
1057 if (!data.WriteInterfaceToken(GetDescriptor())) {
1058 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1059 return WIFI_OPT_FAILED;
1060 }
1061 data.WriteInt32(0);
1062 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_RECONNECT), data, reply,
1063 option);
1064 if (error != ERR_NONE) {
1065 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1066 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_RECONNECT), error);
1067 return WIFI_OPT_FAILED;
1068 }
1069 int exception = reply.ReadInt32();
1070 if (exception) {
1071 return WIFI_OPT_FAILED;
1072 }
1073 return ErrCode(reply.ReadInt32());
1074 }
1075
ReAssociate(void)1076 ErrCode WifiDeviceProxy::ReAssociate(void)
1077 {
1078 if (mRemoteDied) {
1079 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1080 return WIFI_OPT_FAILED;
1081 }
1082 MessageOption option;
1083 MessageParcel data, reply;
1084 if (!data.WriteInterfaceToken(GetDescriptor())) {
1085 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1086 return WIFI_OPT_FAILED;
1087 }
1088 data.WriteInt32(0);
1089 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REASSOCIATE), data, reply,
1090 option);
1091 if (error != ERR_NONE) {
1092 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1093 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REASSOCIATE), error);
1094 return WIFI_OPT_FAILED;
1095 }
1096 int exception = reply.ReadInt32();
1097 if (exception) {
1098 return WIFI_OPT_FAILED;
1099 }
1100 return ErrCode(reply.ReadInt32());
1101 }
1102
Disconnect(void)1103 ErrCode WifiDeviceProxy::Disconnect(void)
1104 {
1105 if (mRemoteDied) {
1106 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1107 return WIFI_OPT_FAILED;
1108 }
1109 MessageOption option;
1110 MessageParcel data, reply;
1111 if (!data.WriteInterfaceToken(GetDescriptor())) {
1112 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1113 return WIFI_OPT_FAILED;
1114 }
1115 data.WriteInt32(0);
1116 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISCONNECT), data, reply,
1117 option);
1118 if (error != ERR_NONE) {
1119 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1120 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISCONNECT), error);
1121 return WIFI_OPT_FAILED;
1122 }
1123 int exception = reply.ReadInt32();
1124 if (exception) {
1125 return WIFI_OPT_FAILED;
1126 }
1127 return ErrCode(reply.ReadInt32());
1128 }
1129
StartWps(const WpsConfig & config)1130 ErrCode WifiDeviceProxy::StartWps(const WpsConfig &config)
1131 {
1132 if (mRemoteDied) {
1133 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1134 return WIFI_OPT_FAILED;
1135 }
1136 MessageOption option;
1137 MessageParcel data, reply;
1138 if (!data.WriteInterfaceToken(GetDescriptor())) {
1139 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1140 return WIFI_OPT_FAILED;
1141 }
1142 data.WriteInt32(0);
1143 data.WriteInt32(static_cast<int>(config.setup));
1144 data.WriteCString(config.pin.c_str());
1145 data.WriteCString(config.bssid.c_str());
1146 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_WPS), data, reply,
1147 option);
1148 if (error != ERR_NONE) {
1149 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1150 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_WPS), error);
1151 return WIFI_OPT_FAILED;
1152 }
1153 int exception = reply.ReadInt32();
1154 if (exception) {
1155 return WIFI_OPT_FAILED;
1156 }
1157 return ErrCode(reply.ReadInt32());
1158 }
1159
CancelWps(void)1160 ErrCode WifiDeviceProxy::CancelWps(void)
1161 {
1162 if (mRemoteDied) {
1163 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1164 return WIFI_OPT_FAILED;
1165 }
1166 MessageOption option;
1167 MessageParcel data, reply;
1168 if (!data.WriteInterfaceToken(GetDescriptor())) {
1169 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1170 return WIFI_OPT_FAILED;
1171 }
1172 data.WriteInt32(0);
1173 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_CANCEL_WPS), data, reply,
1174 option);
1175 if (error != ERR_NONE) {
1176 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1177 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CANCEL_WPS), error);
1178 return WIFI_OPT_FAILED;
1179 }
1180 int exception = reply.ReadInt32();
1181 if (exception) {
1182 return WIFI_OPT_FAILED;
1183 }
1184 return ErrCode(reply.ReadInt32());
1185 }
1186
IsWifiActive(bool & bActive)1187 ErrCode WifiDeviceProxy::IsWifiActive(bool &bActive)
1188 {
1189 if (mRemoteDied) {
1190 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1191 return WIFI_OPT_FAILED;
1192 }
1193 MessageOption option;
1194 MessageParcel data, reply;
1195 if (!data.WriteInterfaceToken(GetDescriptor())) {
1196 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1197 return WIFI_OPT_FAILED;
1198 }
1199 data.WriteInt32(0);
1200 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_ACTIVE), data, reply,
1201 option);
1202 if (error != ERR_NONE) {
1203 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1204 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_ACTIVE), error);
1205 return WIFI_OPT_FAILED;
1206 }
1207 int exception = reply.ReadInt32();
1208 if (exception) {
1209 return WIFI_OPT_FAILED;
1210 }
1211 int ret = reply.ReadInt32();
1212 if (ret != WIFI_OPT_SUCCESS) {
1213 return ErrCode(ret);
1214 }
1215
1216 bActive = reply.ReadBool();
1217 return WIFI_OPT_SUCCESS;
1218 }
1219
GetWifiState(int & state)1220 ErrCode WifiDeviceProxy::GetWifiState(int &state)
1221 {
1222 if (mRemoteDied) {
1223 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1224 return WIFI_OPT_FAILED;
1225 }
1226 MessageOption option;
1227 MessageParcel data, reply;
1228 if (!data.WriteInterfaceToken(GetDescriptor())) {
1229 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1230 return WIFI_OPT_FAILED;
1231 }
1232 data.WriteInt32(0);
1233 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_STATE), data, reply,
1234 option);
1235 if (error != ERR_NONE) {
1236 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1237 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_STATE), error);
1238 return WIFI_OPT_FAILED;
1239 }
1240 int exception = reply.ReadInt32();
1241 if (exception) {
1242 return WIFI_OPT_FAILED;
1243 }
1244 int ret = reply.ReadInt32();
1245 if (ret != WIFI_OPT_SUCCESS) {
1246 return ErrCode(ret);
1247 }
1248
1249 state = reply.ReadInt32();
1250 return WIFI_OPT_SUCCESS;
1251 }
1252
ReadLinkedInfo(MessageParcel & reply,WifiLinkedInfo & info)1253 void WifiDeviceProxy::ReadLinkedInfo(MessageParcel &reply, WifiLinkedInfo &info)
1254 {
1255 info.networkId = reply.ReadInt32();
1256 info.ssid = reply.ReadString();
1257 info.bssid = reply.ReadString();
1258 info.rssi = reply.ReadInt32();
1259 info.band = reply.ReadInt32();
1260 info.frequency = reply.ReadInt32();
1261 info.linkSpeed = reply.ReadInt32();
1262 info.macAddress = reply.ReadString();
1263 info.macType = reply.ReadInt32();
1264 info.ipAddress = static_cast<uint32_t>(reply.ReadInt32());
1265 int tmpConnState = reply.ReadInt32();
1266 if ((tmpConnState >= 0) && (tmpConnState <= (int)ConnState::UNKNOWN)) {
1267 info.connState = ConnState(tmpConnState);
1268 } else {
1269 info.connState = ConnState::UNKNOWN;
1270 }
1271 info.ifHiddenSSID = reply.ReadBool();
1272 info.rxLinkSpeed = reply.ReadInt32();
1273 info.txLinkSpeed = reply.ReadInt32();
1274 info.chload = reply.ReadInt32();
1275 info.snr = reply.ReadInt32();
1276 info.isDataRestricted = reply.ReadInt32();
1277 info.portalUrl = reply.ReadString();
1278
1279 int tmpState = reply.ReadInt32();
1280 if ((tmpState >= 0) && (tmpState <= (int)SupplicantState::INVALID)) {
1281 info.supplicantState = (SupplicantState)tmpState;
1282 } else {
1283 info.supplicantState = SupplicantState::INVALID;
1284 }
1285
1286 int tmpDetailState = reply.ReadInt32();
1287 if ((tmpDetailState >= 0) && (tmpDetailState <= (int)DetailedState::INVALID)) {
1288 info.detailedState = (DetailedState)tmpDetailState;
1289 } else {
1290 info.detailedState = DetailedState::INVALID;
1291 }
1292 info.wifiStandard = reply.ReadInt32();
1293 info.maxSupportedRxLinkSpeed = reply.ReadInt32();
1294 info.maxSupportedTxLinkSpeed = reply.ReadInt32();
1295 int tmpChanWidth = reply.ReadInt32();
1296 if ((tmpChanWidth >= 0) && (tmpChanWidth <= (int)WifiChannelWidth::WIDTH_INVALID)) {
1297 info.channelWidth = (WifiChannelWidth)tmpChanWidth;
1298 } else {
1299 info.channelWidth = WifiChannelWidth::WIDTH_INVALID;
1300 }
1301 info.isAncoConnected = reply.ReadBool();
1302 info.supportedWifiCategory = static_cast<WifiCategory>(reply.ReadInt32());
1303 info.isHiLinkNetwork = reply.ReadBool();
1304 }
1305
GetDisconnectedReason(DisconnectedReason & reason)1306 ErrCode WifiDeviceProxy::GetDisconnectedReason(DisconnectedReason &reason)
1307 {
1308 if (mRemoteDied) {
1309 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1310 return WIFI_OPT_FAILED;
1311 }
1312 MessageOption option;
1313 MessageParcel data, reply;
1314 if (!data.WriteInterfaceToken(GetDescriptor())) {
1315 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1316 return WIFI_OPT_FAILED;
1317 }
1318 data.WriteInt32(0);
1319 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DISCONNECTED_REASON),
1320 data, reply, option);
1321 if (error != ERR_NONE) {
1322 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1323 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DISCONNECTED_REASON), error);
1324 return WIFI_OPT_FAILED;
1325 }
1326
1327 int exception = reply.ReadInt32();
1328 if (exception) {
1329 return WIFI_OPT_FAILED;
1330 }
1331 int ret = reply.ReadInt32();
1332 if (ret != WIFI_OPT_SUCCESS) {
1333 return ErrCode(ret);
1334 }
1335 int tempReason = reply.ReadInt32();
1336 if (tempReason >= 0 && tempReason <= (int)DisconnectedReason::DISC_REASON_CONNECTION_REJECTED) {
1337 reason = (DisconnectedReason)tempReason;
1338 } else {
1339 reason = DisconnectedReason::DISC_REASON_DEFAULT;
1340 }
1341 return WIFI_OPT_SUCCESS;
1342 }
1343
IsMeteredHotspot(bool & bMeteredHotspot)1344 ErrCode WifiDeviceProxy::IsMeteredHotspot(bool &bMeteredHotspot)
1345 {
1346 if (mRemoteDied) {
1347 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1348 return WIFI_OPT_FAILED;
1349 }
1350 MessageOption option;
1351 MessageParcel data, reply;
1352 if (!data.WriteInterfaceToken(GetDescriptor())) {
1353 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1354 return WIFI_OPT_FAILED;
1355 }
1356 data.WriteInt32(0);
1357 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_METERED_HOTSPOT),
1358 data, reply, option);
1359 if (error != ERR_NONE) {
1360 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1361 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_METERED_HOTSPOT), error);
1362 return WIFI_OPT_FAILED;
1363 }
1364 int exception = reply.ReadInt32();
1365 if (exception) {
1366 return WIFI_OPT_FAILED;
1367 }
1368 int ret = reply.ReadInt32();
1369 if (ret != WIFI_OPT_SUCCESS) {
1370 return ErrCode(ret);
1371 }
1372
1373 bMeteredHotspot = reply.ReadBool();
1374 return WIFI_OPT_SUCCESS;
1375 }
1376
GetLinkedInfo(WifiLinkedInfo & info)1377 ErrCode WifiDeviceProxy::GetLinkedInfo(WifiLinkedInfo &info)
1378 {
1379 if (mRemoteDied) {
1380 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1381 return WIFI_OPT_FAILED;
1382 }
1383 MessageOption option;
1384 MessageParcel data, reply;
1385 if (!data.WriteInterfaceToken(GetDescriptor())) {
1386 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1387 return WIFI_OPT_FAILED;
1388 }
1389 data.WriteInt32(0);
1390 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_LINKED_INFO), data,
1391 reply, option);
1392 if (error != ERR_NONE) {
1393 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1394 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_LINKED_INFO), error);
1395 return WIFI_OPT_FAILED;
1396 }
1397
1398 int exception = reply.ReadInt32();
1399 if (exception) {
1400 return WIFI_OPT_FAILED;
1401 }
1402 int ret = reply.ReadInt32();
1403 if (ret != WIFI_OPT_SUCCESS) {
1404 return ErrCode(ret);
1405 }
1406
1407 ReadLinkedInfo(reply, info);
1408 return WIFI_OPT_SUCCESS;
1409 }
1410
GetIpInfo(IpInfo & info)1411 ErrCode WifiDeviceProxy::GetIpInfo(IpInfo &info)
1412 {
1413 if (mRemoteDied) {
1414 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1415 return WIFI_OPT_FAILED;
1416 }
1417 MessageOption option;
1418 MessageParcel data, reply;
1419 if (!data.WriteInterfaceToken(GetDescriptor())) {
1420 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1421 return WIFI_OPT_FAILED;
1422 }
1423 data.WriteInt32(0);
1424 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_INFO), data, reply,
1425 option);
1426 if (error != ERR_NONE) {
1427 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1428 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_INFO), error);
1429 return WIFI_OPT_FAILED;
1430 }
1431 int exception = reply.ReadInt32();
1432 if (exception) {
1433 return WIFI_OPT_FAILED;
1434 }
1435 int ret = reply.ReadInt32();
1436 if (ret != WIFI_OPT_SUCCESS) {
1437 return ErrCode(ret);
1438 }
1439
1440 info.ipAddress = static_cast<uint32_t>(reply.ReadInt32());
1441 info.gateway = static_cast<uint32_t>(reply.ReadInt32());
1442 info.netmask = static_cast<uint32_t>(reply.ReadInt32());
1443 info.primaryDns = static_cast<uint32_t>(reply.ReadInt32());
1444 info.secondDns = static_cast<uint32_t>(reply.ReadInt32());
1445 info.serverIp = static_cast<uint32_t>(reply.ReadInt32());
1446 info.leaseDuration = static_cast<uint32_t>(reply.ReadInt32());
1447 return WIFI_OPT_SUCCESS;
1448 }
1449
GetIpv6Info(IpV6Info & info)1450 ErrCode WifiDeviceProxy::GetIpv6Info(IpV6Info &info)
1451 {
1452 if (mRemoteDied) {
1453 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1454 return WIFI_OPT_FAILED;
1455 }
1456 MessageOption option;
1457 MessageParcel data, reply;
1458 if (!data.WriteInterfaceToken(GetDescriptor())) {
1459 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1460 return WIFI_OPT_FAILED;
1461 }
1462 data.WriteInt32(0);
1463 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_IPV6INFO),
1464 data, reply, option);
1465 if (error != ERR_NONE) {
1466 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1467 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_IPV6INFO), error);
1468 return WIFI_OPT_FAILED;
1469 }
1470 int exception = reply.ReadInt32();
1471 if (exception) {
1472 return WIFI_OPT_FAILED;
1473 }
1474 int ret = reply.ReadInt32();
1475 if (ret != WIFI_OPT_SUCCESS) {
1476 return ErrCode(ret);
1477 }
1478 info.linkIpV6Address = reply.ReadString();
1479 info.globalIpV6Address = reply.ReadString();
1480 info.randGlobalIpV6Address = reply.ReadString();
1481 info.uniqueLocalAddress1 = reply.ReadString();
1482 info.uniqueLocalAddress2 = reply.ReadString();
1483 info.gateway = reply.ReadString();
1484 info.netmask = reply.ReadString();
1485 info.primaryDns = reply.ReadString();
1486 info.secondDns = reply.ReadString();
1487 return WIFI_OPT_SUCCESS;
1488 }
1489
SetCountryCode(const std::string & countryCode)1490 ErrCode WifiDeviceProxy::SetCountryCode(const std::string &countryCode)
1491 {
1492 if (mRemoteDied) {
1493 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1494 return WIFI_OPT_FAILED;
1495 }
1496 MessageOption option;
1497 MessageParcel data, reply;
1498 if (!data.WriteInterfaceToken(GetDescriptor())) {
1499 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1500 return WIFI_OPT_FAILED;
1501 }
1502 data.WriteInt32(0);
1503 data.WriteString(countryCode);
1504 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_COUNTRY_CODE), data,
1505 reply, option);
1506 if (error != ERR_NONE) {
1507 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1508 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_COUNTRY_CODE), error);
1509 return WIFI_OPT_FAILED;
1510 }
1511 int exception = reply.ReadInt32();
1512 if (exception) {
1513 return WIFI_OPT_FAILED;
1514 }
1515 return ErrCode(reply.ReadInt32());
1516 }
1517
GetCountryCode(std::string & countryCode)1518 ErrCode WifiDeviceProxy::GetCountryCode(std::string &countryCode)
1519 {
1520 if (mRemoteDied) {
1521 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1522 return WIFI_OPT_FAILED;
1523 }
1524 MessageOption option;
1525 MessageParcel data, reply;
1526 if (!data.WriteInterfaceToken(GetDescriptor())) {
1527 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1528 return WIFI_OPT_FAILED;
1529 }
1530 data.WriteInt32(0);
1531 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_COUNTRY_CODE), data,
1532 reply, option);
1533 if (error != ERR_NONE) {
1534 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1535 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_COUNTRY_CODE), error);
1536 return WIFI_OPT_FAILED;
1537 }
1538 int exception = reply.ReadInt32();
1539 if (exception) {
1540 return WIFI_OPT_FAILED;
1541 }
1542 int ret = reply.ReadInt32();
1543 if (ret != WIFI_OPT_SUCCESS) {
1544 return ErrCode(ret);
1545 }
1546 countryCode = reply.ReadString();
1547 return WIFI_OPT_SUCCESS;
1548 }
1549
RegisterCallBack(const sptr<IWifiDeviceCallBack> & callback,const std::vector<std::string> & event)1550 ErrCode WifiDeviceProxy::RegisterCallBack(const sptr<IWifiDeviceCallBack> &callback,
1551 const std::vector<std::string> &event)
1552 {
1553 if (mRemoteDied) {
1554 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1555 return WIFI_OPT_FAILED;
1556 }
1557 MessageParcel data, reply;
1558 MessageOption option(MessageOption::TF_ASYNC);
1559
1560 if (!data.WriteInterfaceToken(GetDescriptor())) {
1561 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1562 return WIFI_OPT_FAILED;
1563 }
1564 data.WriteInt32(0);
1565
1566 if (g_deviceCallBackStub == nullptr) {
1567 WIFI_LOGE("g_deviceCallBackStub is nullptr");
1568 return WIFI_OPT_FAILED;
1569 }
1570 g_deviceCallBackStub->RegisterUserCallBack(callback);
1571
1572 if (!data.WriteRemoteObject(g_deviceCallBackStub->AsObject())) {
1573 WIFI_LOGE("WifiDeviceProxy::RegisterCallBack WriteRemoteObject failed!");
1574 return WIFI_OPT_FAILED;
1575 }
1576
1577 int pid = GetCallingPid();
1578 data.WriteInt32(pid);
1579 int tokenId = GetCallingTokenId();
1580 data.WriteInt32(tokenId);
1581 int eventNum = static_cast<int>(event.size());
1582 data.WriteInt32(eventNum);
1583 if (eventNum > 0) {
1584 for (auto &eventName : event) {
1585 data.WriteString(eventName);
1586 }
1587 }
1588 WIFI_LOGD("%{public}s, calling uid: %{public}d, pid: %{public}d, tokenId: %{private}d",
1589 __func__, GetCallingUid(), pid, tokenId);
1590 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REGISTER_CALLBACK_CLIENT),
1591 data, reply, option);
1592 if (error != ERR_NONE) {
1593 WIFI_LOGE("Set Attr(%{public}d) failed, code is %{public}d",
1594 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REGISTER_CALLBACK_CLIENT), error);
1595 return WIFI_OPT_FAILED;
1596 }
1597 int exception = reply.ReadInt32();
1598 if (exception) {
1599 return WIFI_OPT_FAILED;
1600 }
1601 return ErrCode(reply.ReadInt32());
1602 }
1603
GetSignalLevel(const int & rssi,const int & band,int & level)1604 ErrCode WifiDeviceProxy::GetSignalLevel(const int &rssi, const int &band, int &level)
1605 {
1606 if (mRemoteDied) {
1607 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1608 return WIFI_OPT_FAILED;
1609 }
1610 MessageOption option;
1611 MessageParcel data, reply;
1612 if (!data.WriteInterfaceToken(GetDescriptor())) {
1613 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1614 return WIFI_OPT_FAILED;
1615 }
1616 data.WriteInt32(0);
1617 data.WriteInt32(rssi);
1618 data.WriteInt32(band);
1619 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SIGNAL_LEVEL), data,
1620 reply, option);
1621 if (error != ERR_NONE) {
1622 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1623 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SIGNAL_LEVEL), error);
1624 return WIFI_OPT_FAILED;
1625 }
1626 int exception = reply.ReadInt32();
1627 if (exception) {
1628 return WIFI_OPT_FAILED;
1629 }
1630 int ret = reply.ReadInt32();
1631 if (ret != WIFI_OPT_SUCCESS) {
1632 return ErrCode(ret);
1633 }
1634
1635 level = reply.ReadInt32();
1636 return WIFI_OPT_SUCCESS;
1637 }
1638
GetSupportedFeatures(long & features)1639 ErrCode WifiDeviceProxy::GetSupportedFeatures(long &features)
1640 {
1641 if (mRemoteDied) {
1642 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1643 return WIFI_OPT_FAILED;
1644 }
1645 MessageOption option;
1646 MessageParcel data, reply;
1647 if (!data.WriteInterfaceToken(GetDescriptor())) {
1648 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1649 return WIFI_OPT_FAILED;
1650 }
1651 data.WriteInt32(0);
1652 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES),
1653 data, reply, option);
1654 if (error != ERR_NONE) {
1655 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1656 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES), error);
1657 return WIFI_OPT_FAILED;
1658 }
1659 int exception = reply.ReadInt32();
1660 if (exception) {
1661 return WIFI_OPT_FAILED;
1662 }
1663 int ret = reply.ReadInt32();
1664 if (ret != WIFI_OPT_SUCCESS) {
1665 return ErrCode(ret);
1666 }
1667
1668 features = reply.ReadInt64();
1669 return WIFI_OPT_SUCCESS;
1670 }
1671
GetDeviceMacAddress(std::string & result)1672 ErrCode WifiDeviceProxy::GetDeviceMacAddress(std::string &result)
1673 {
1674 if (mRemoteDied) {
1675 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1676 return WIFI_OPT_FAILED;
1677 }
1678 const char *readStr = nullptr;
1679 MessageOption option;
1680 MessageParcel data;
1681 MessageParcel reply;
1682 if (!data.WriteInterfaceToken(GetDescriptor())) {
1683 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1684 return WIFI_OPT_FAILED;
1685 }
1686 data.WriteInt32(0);
1687 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DERVICE_MAC_ADD),
1688 data, reply, option);
1689 if (error != ERR_NONE) {
1690 WIFI_LOGE("Set Attr(%{public}d) failed",
1691 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DERVICE_MAC_ADD));
1692 return WIFI_OPT_FAILED;
1693 }
1694
1695 int exception = reply.ReadInt32();
1696 if (exception) {
1697 return WIFI_OPT_FAILED;
1698 }
1699 int ret = reply.ReadInt32();
1700 if (ErrCode(ret) != WIFI_OPT_SUCCESS) {
1701 return ErrCode(ret);
1702 }
1703 readStr = reply.ReadCString();
1704 result = (readStr != nullptr) ? readStr : "";
1705 return WIFI_OPT_SUCCESS;
1706 }
1707
SetLowLatencyMode(bool enabled)1708 bool WifiDeviceProxy::SetLowLatencyMode(bool enabled)
1709 {
1710 if (mRemoteDied) {
1711 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1712 return WIFI_OPT_FAILED;
1713 }
1714 MessageOption option;
1715 MessageParcel data;
1716 MessageParcel reply;
1717 if (!data.WriteInterfaceToken(GetDescriptor())) {
1718 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1719 return WIFI_OPT_FAILED;
1720 }
1721 data.WriteInt32(0);
1722 data.WriteBool(enabled);
1723 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_LATENCY_MODE), data,
1724 reply, option);
1725 if (error != ERR_NONE) {
1726 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1727 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_LATENCY_MODE), error);
1728 return WIFI_OPT_FAILED;
1729 }
1730 int exception = reply.ReadInt32();
1731 if (exception) {
1732 return WIFI_OPT_FAILED;
1733 }
1734 return reply.ReadBool();
1735 }
1736
OnRemoteDied(const wptr<IRemoteObject> & remoteObject)1737 void WifiDeviceProxy::OnRemoteDied(const wptr<IRemoteObject> &remoteObject)
1738 {
1739 WIFI_LOGW("Remote service is died! remoteObject: %{private}p", &remoteObject);
1740 mRemoteDied = true;
1741 RemoveDeathRecipient();
1742 if (g_deviceCallBackStub == nullptr) {
1743 WIFI_LOGE("g_deviceCallBackStub is nullptr");
1744 return;
1745 }
1746 if (g_deviceCallBackStub != nullptr) {
1747 g_deviceCallBackStub->SetRemoteDied(true);
1748 }
1749 }
1750
IsRemoteDied(void)1751 bool WifiDeviceProxy::IsRemoteDied(void)
1752 {
1753 if (mRemoteDied) {
1754 WIFI_LOGW("IsRemoteDied! remote is died now!");
1755 }
1756 return mRemoteDied;
1757 }
1758
IsBandTypeSupported(int bandType,bool & supported)1759 ErrCode WifiDeviceProxy::IsBandTypeSupported(int bandType, bool &supported)
1760 {
1761 if (mRemoteDied) {
1762 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1763 return WIFI_OPT_FAILED;
1764 }
1765 MessageOption option;
1766 MessageParcel data, reply;
1767 if (!data.WriteInterfaceToken(GetDescriptor())) {
1768 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1769 return WIFI_OPT_FAILED;
1770 }
1771 data.WriteInt32(0);
1772 data.WriteInt32(bandType);
1773 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_BANDTYPE_SUPPORTED),
1774 data, reply, option);
1775 if (error != ERR_NONE) {
1776 WIFI_LOGE("IsBandTypeSupported (%{public}d) failed,error code is %{public}d",
1777 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_BANDTYPE_SUPPORTED), error);
1778 return WIFI_OPT_FAILED;
1779 }
1780
1781 int exception = reply.ReadInt32();
1782 if (exception) {
1783 return WIFI_OPT_FAILED;
1784 }
1785 int ret = reply.ReadInt32();
1786 if (ret != WIFI_OPT_SUCCESS) {
1787 return ErrCode(ret);
1788 }
1789 supported = reply.ReadInt32();
1790 return WIFI_OPT_SUCCESS;
1791 }
1792
Get5GHzChannelList(std::vector<int> & result)1793 ErrCode WifiDeviceProxy::Get5GHzChannelList(std::vector<int> &result)
1794 {
1795 if (mRemoteDied) {
1796 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1797 return WIFI_OPT_FAILED;
1798 }
1799 constexpr int MAX_CHANNEL_SIZE = 36;
1800 MessageOption option;
1801 MessageParcel data, reply;
1802 if (!data.WriteInterfaceToken(GetDescriptor())) {
1803 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1804 return WIFI_OPT_FAILED;
1805 }
1806 data.WriteInt32(0);
1807 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_5G_CHANNELLIST), data,
1808 reply, option);
1809 if (error != ERR_NONE) {
1810 WIFI_LOGE("Get5GHzChannelList(%{public}d) failed,error code is %{public}d",
1811 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_5G_CHANNELLIST), error);
1812 return WIFI_OPT_FAILED;
1813 }
1814
1815 int exception = reply.ReadInt32();
1816 if (exception) {
1817 return WIFI_OPT_FAILED;
1818 }
1819 int ret = reply.ReadInt32();
1820 if (ret != WIFI_OPT_SUCCESS) {
1821 return ErrCode(ret);
1822 }
1823 int retSize = reply.ReadInt32();
1824 if (retSize > MAX_CHANNEL_SIZE) {
1825 WIFI_LOGE("Get5GHzChannelList fail, size error: %{public}d", retSize);
1826 return WIFI_OPT_FAILED;
1827 }
1828 for (int i = 0; i < retSize; ++i) {
1829 result.emplace_back(reply.ReadInt32());
1830 }
1831 return WIFI_OPT_SUCCESS;
1832 }
1833
SetAppFrozen(std::set<int> pidList,bool isFrozen)1834 ErrCode WifiDeviceProxy::SetAppFrozen(std::set<int> pidList, bool isFrozen)
1835 {
1836 if (mRemoteDied) {
1837 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1838 return WIFI_OPT_FAILED;
1839 }
1840 MessageOption option;
1841 MessageParcel data, reply;
1842 if (!data.WriteInterfaceToken(GetDescriptor())) {
1843 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1844 return WIFI_OPT_FAILED;
1845 }
1846 data.WriteInt32(0);
1847 int size = static_cast<int>(pidList.size() < MAX_PID_LIST_SIZE ? pidList.size() : MAX_PID_LIST_SIZE);
1848 int count = 0;
1849 data.WriteInt32(size);
1850 for (std::set<int>::iterator it = pidList.begin(); it != pidList.end() && count < size; it++, count++) {
1851 data.WriteInt32(*it);
1852 }
1853 data.WriteBool(isFrozen);
1854 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_FROZEN_APP), data,
1855 reply, option);
1856 if (error != ERR_NONE) {
1857 WIFI_LOGE("SetAppFrozen(%{public}d) failed,error code is %{public}d",
1858 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_FROZEN_APP), error);
1859 return WIFI_OPT_FAILED;
1860 }
1861 int exception = reply.ReadInt32();
1862 if (exception) {
1863 return WIFI_OPT_FAILED;
1864 }
1865 return WIFI_OPT_SUCCESS;
1866 }
1867
ResetAllFrozenApp()1868 ErrCode WifiDeviceProxy::ResetAllFrozenApp()
1869 {
1870 if (mRemoteDied) {
1871 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1872 return WIFI_OPT_FAILED;
1873 }
1874 MessageOption option;
1875 MessageParcel data, reply;
1876 if (!data.WriteInterfaceToken(GetDescriptor())) {
1877 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1878 return WIFI_OPT_FAILED;
1879 }
1880 data.WriteInt32(0);
1881 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_RESET_ALL_FROZEN_APP), data,
1882 reply, option);
1883 if (error != ERR_NONE) {
1884 WIFI_LOGE("Get5GHzChannelList(%{public}d) failed,error code is %{public}d",
1885 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_RESET_ALL_FROZEN_APP), error);
1886 return WIFI_OPT_FAILED;
1887 }
1888 int exception = reply.ReadInt32();
1889 if (exception) {
1890 return WIFI_OPT_FAILED;
1891 }
1892 return WIFI_OPT_SUCCESS;
1893 }
1894
DisableAutoJoin(const std::string & conditionName)1895 ErrCode WifiDeviceProxy::DisableAutoJoin(const std::string &conditionName)
1896 {
1897 if (mRemoteDied) {
1898 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1899 return WIFI_OPT_FAILED;
1900 }
1901 MessageOption option;
1902 MessageParcel data, reply;
1903 if (!data.WriteInterfaceToken(GetDescriptor())) {
1904 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1905 return WIFI_OPT_FAILED;
1906 }
1907 data.WriteInt32(0);
1908 data.WriteString(conditionName);
1909 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_AUTO_JOIN), data,
1910 reply, option);
1911 if (error != ERR_NONE) {
1912 WIFI_LOGE("DisableAutoJoin (%{public}d) failed,error code is %{public}d",
1913 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_AUTO_JOIN), error);
1914 return WIFI_OPT_FAILED;
1915 }
1916 int exception = reply.ReadInt32();
1917 if (exception) {
1918 return WIFI_OPT_FAILED;
1919 }
1920 return WIFI_OPT_SUCCESS;
1921 }
1922
EnableAutoJoin(const std::string & conditionName)1923 ErrCode WifiDeviceProxy::EnableAutoJoin(const std::string &conditionName)
1924 {
1925 if (mRemoteDied) {
1926 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1927 return WIFI_OPT_FAILED;
1928 }
1929 MessageOption option;
1930 MessageParcel data, reply;
1931 if (!data.WriteInterfaceToken(GetDescriptor())) {
1932 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1933 return WIFI_OPT_FAILED;
1934 }
1935 data.WriteInt32(0);
1936 data.WriteString(conditionName);
1937 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_AUTO_JOIN), data,
1938 reply, option);
1939 if (error != ERR_NONE) {
1940 WIFI_LOGE("EnableAutoJoin(%{public}d) failed,error code is %{public}d",
1941 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_AUTO_JOIN), error);
1942 return WIFI_OPT_FAILED;
1943 }
1944 int exception = reply.ReadInt32();
1945 if (exception) {
1946 return WIFI_OPT_FAILED;
1947 }
1948 return WIFI_OPT_SUCCESS;
1949 }
1950
RegisterAutoJoinCondition(const std::string & conditionName,const std::function<bool ()> & autoJoinCondition)1951 ErrCode WifiDeviceProxy::RegisterAutoJoinCondition(const std::string &conditionName,
1952 const std::function<bool()> &autoJoinCondition)
1953 {
1954 return WIFI_OPT_FAILED;
1955 }
1956
DeregisterAutoJoinCondition(const std::string & conditionName)1957 ErrCode WifiDeviceProxy::DeregisterAutoJoinCondition(const std::string &conditionName)
1958 {
1959 return WIFI_OPT_FAILED;
1960 }
1961
RegisterFilterBuilder(const FilterTag & filterTag,const std::string & filterName,const FilterBuilder & filterBuilder)1962 ErrCode WifiDeviceProxy::RegisterFilterBuilder(const FilterTag &filterTag,
1963 const std::string &filterName,
1964 const FilterBuilder &filterBuilder)
1965 {
1966 return WIFI_OPT_FAILED;
1967 }
1968
DeregisterFilterBuilder(const FilterTag & filterTag,const std::string & filterName)1969 ErrCode WifiDeviceProxy::DeregisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName)
1970 {
1971 return WIFI_OPT_FAILED;
1972 }
1973
RegisterCommonBuilder(const TagType & tagType,const std::string & tagName,const CommonBuilder & commonBuilder)1974 ErrCode WifiDeviceProxy::RegisterCommonBuilder(const TagType &tagType, const std::string &tagName,
1975 const CommonBuilder &commonBuilder)
1976 {
1977 return WIFI_OPT_FAILED;
1978 }
1979
DeregisterCommonBuilder(const TagType & tagType,const std::string & tagName)1980 ErrCode WifiDeviceProxy::DeregisterCommonBuilder(const TagType &tagType, const std::string &tagName)
1981 {
1982 return WIFI_OPT_FAILED;
1983 }
1984
StartPortalCertification()1985 ErrCode WifiDeviceProxy::StartPortalCertification()
1986 {
1987 if (mRemoteDied) {
1988 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1989 return WIFI_OPT_FAILED;
1990 }
1991 MessageOption option;
1992 MessageParcel data, reply;
1993 if (!data.WriteInterfaceToken(GetDescriptor())) {
1994 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1995 return WIFI_OPT_FAILED;
1996 }
1997 data.WriteInt32(0);
1998 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_PORTAL_CERTIF), data,
1999 reply, option);
2000 if (error != ERR_NONE) {
2001 WIFI_LOGE("StartPortalCertification(%{public}d) failed,error code is %{public}d",
2002 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_PORTAL_CERTIF), error);
2003 return WIFI_OPT_FAILED;
2004 }
2005
2006 int exception = reply.ReadInt32();
2007 if (exception) {
2008 return WIFI_OPT_FAILED;
2009 }
2010 int ret = reply.ReadInt32();
2011 if (ret != WIFI_OPT_SUCCESS) {
2012 return ErrCode(ret);
2013 }
2014
2015 return WIFI_OPT_SUCCESS;
2016 }
2017
GetChangeDeviceConfig(ConfigChange & value,WifiDeviceConfig & config)2018 ErrCode WifiDeviceProxy::GetChangeDeviceConfig(ConfigChange &value, WifiDeviceConfig &config)
2019 {
2020 if (mRemoteDied) {
2021 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2022 return WIFI_OPT_FAILED;
2023 }
2024 MessageOption option;
2025 MessageParcel data, reply;
2026 if (!data.WriteInterfaceToken(GetDescriptor())) {
2027 WIFI_LOGE("Write interface token error: %{public}s", __func__);
2028 return WIFI_OPT_FAILED;
2029 }
2030 data.WriteInt32(0);
2031 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIG_CHANGE),
2032 data, reply, option);
2033 if (error != ERR_NONE) {
2034 WIFI_LOGE("GetChangeDeviceConfig (%{public}d) failed,error code is %{public}d",
2035 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIG_CHANGE), error);
2036 return WIFI_OPT_FAILED;
2037 }
2038
2039 int exception = reply.ReadInt32();
2040 if (exception) {
2041 return WIFI_OPT_FAILED;
2042 }
2043 value = (ConfigChange)reply.ReadInt32();
2044 config.networkId = reply.ReadInt32();
2045 config.ssid = reply.ReadString();
2046 config.bssid = reply.ReadString();
2047 config.callProcessName = reply.ReadString();
2048 config.ancoCallProcessName = reply.ReadString();
2049 config.keyMgmt = reply.ReadString();
2050 int ret = reply.ReadInt32();
2051 if (ret != WIFI_OPT_SUCCESS) {
2052 return ErrCode(ret);
2053 }
2054 return WIFI_OPT_SUCCESS;
2055 }
2056
FactoryReset()2057 ErrCode WifiDeviceProxy::FactoryReset()
2058 {
2059 if (mRemoteDied) {
2060 WIFI_LOGE("failed to `%{public}s`, remote service is died.", __func__);
2061 return WIFI_OPT_FAILED;
2062 }
2063 MessageParcel data, reply;
2064 MessageOption option;
2065 if (!data.WriteInterfaceToken(GetDescriptor())) {
2066 WIFI_LOGE("Write interface token error, func:%{public}s", __func__);
2067 return WIFI_OPT_FAILED;
2068 }
2069
2070 data.WriteInt32(0);
2071 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_SET_FACTORY_RESET), data,
2072 reply, option);
2073 if (error != ERR_NONE) {
2074 WIFI_LOGE("FactoryReset(%{public}d) failed, error code is %{public}d",
2075 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_SET_FACTORY_RESET), error);
2076 return WIFI_OPT_FAILED;
2077 }
2078
2079 int exception = reply.ReadInt32();
2080 if (exception) {
2081 WIFI_LOGE("Reply Read failed, exception:%{public}d", exception);
2082 return WIFI_OPT_FAILED;
2083 }
2084 int ret = reply.ReadInt32();
2085 if (ret != WIFI_OPT_SUCCESS) {
2086 WIFI_LOGE("Reply Read failed, ret:%{public}d", ret);
2087 return ErrCode(ret);
2088 }
2089 return WIFI_OPT_SUCCESS;
2090 }
2091
LimitSpeed(const int controlId,const int limitMode)2092 ErrCode WifiDeviceProxy::LimitSpeed(const int controlId, const int limitMode)
2093 {
2094 if (mRemoteDied) {
2095 WIFI_LOGE("failed to %{public}s,remote service is died!", __func__);
2096 return WIFI_OPT_FAILED;
2097 }
2098 MessageOption option;
2099 MessageParcel data;
2100 MessageParcel reply;
2101 if (!data.WriteInterfaceToken(GetDescriptor())) {
2102 WIFI_LOGE("Write interface token has error: %{public}s", __func__);
2103 return WIFI_OPT_FAILED;
2104 }
2105 data.WriteInt32(0);
2106 data.WriteInt32(controlId);
2107 data.WriteInt32(limitMode);
2108 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_LIMIT_SPEED), data,
2109 reply, option);
2110 if (error != ERR_NONE) {
2111 WIFI_LOGE("LimitSpeed(%{public}d) failed, error code is %{public}d",
2112 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_LIMIT_SPEED), error);
2113 return WIFI_OPT_FAILED;
2114 }
2115 int exception = reply.ReadInt32();
2116 if (exception) {
2117 WIFI_LOGE("LimitSpeed Reply Read failed, exception:%{public}d", exception);
2118 return WIFI_OPT_FAILED;
2119 }
2120 int ret = reply.ReadInt32();
2121 if (ret != WIFI_OPT_SUCCESS) {
2122 WIFI_LOGE("LimitSpeed Reply Read failed, ret:%{public}d", ret);
2123 return ErrCode(ret);
2124 }
2125 return WIFI_OPT_SUCCESS;
2126 }
2127
SetLowTxPower(const WifiLowPowerParam wifiLowPowerParam)2128 ErrCode WifiDeviceProxy::SetLowTxPower(const WifiLowPowerParam wifiLowPowerParam)
2129 {
2130 if (mRemoteDied) {
2131 WIFI_LOGE("failed to %{public}s,remote service is died!", __func__);
2132 return WIFI_OPT_FAILED;
2133 }
2134 MessageOption option;
2135 MessageParcel data;
2136 MessageParcel reply;
2137 if (!data.WriteInterfaceToken(GetDescriptor())) {
2138 WIFI_LOGE("Write interface token error: %{public}s", __func__);
2139 return WIFI_OPT_FAILED;
2140 }
2141 data.WriteInt32(0);
2142 data.WriteString(wifiLowPowerParam.ifName);
2143 data.WriteInt32(wifiLowPowerParam.scene);
2144 data.WriteInt32(wifiLowPowerParam.rssiThreshold);
2145 data.WriteString(wifiLowPowerParam.peerMacaddr);
2146 data.WriteString(wifiLowPowerParam.powerParam);
2147 data.WriteInt32(wifiLowPowerParam.powerParamLen);
2148 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_TX_POWER), data,
2149 reply, option);
2150 if (error != ERR_NONE) {
2151 WIFI_LOGE("SetLowTxPower(%{public}d) failed, error code is %{public}d",
2152 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_TX_POWER), error);
2153 return WIFI_OPT_FAILED;
2154 }
2155 int exception = reply.ReadInt32();
2156 if (exception) {
2157 WIFI_LOGE("SetLowTxPower Reply Read failed, exception:%{public}d", exception);
2158 return WIFI_OPT_FAILED;
2159 }
2160 int ret = reply.ReadInt32();
2161 if (ret != WIFI_OPT_SUCCESS) {
2162 WIFI_LOGE("SetLowTxPower Reply Read failed, ret:%{public}d", ret);
2163 return ErrCode(ret);
2164 }
2165 return WIFI_OPT_SUCCESS;
2166 }
2167
EnableHiLinkHandshake(bool uiFlag,std::string & bssid,WifiDeviceConfig & deviceConfig)2168 ErrCode WifiDeviceProxy::EnableHiLinkHandshake(bool uiFlag, std::string &bssid, WifiDeviceConfig &deviceConfig)
2169 {
2170 if (mRemoteDied) {
2171 WIFI_LOGE("failed to `%{public}s`, remote service is died.", __func__);
2172 return WIFI_OPT_FAILED;
2173 }
2174 MessageParcel data, reply;
2175 MessageOption option;
2176 if (!data.WriteInterfaceToken(GetDescriptor())) {
2177 WIFI_LOGE("Write interface token error, func:%{public}s", __func__);
2178 return WIFI_OPT_FAILED;
2179 }
2180 data.WriteInt32(0);
2181 data.WriteBool(uiFlag);
2182 data.WriteString(bssid);
2183 WriteDeviceConfig(deviceConfig, data);
2184 //Wirte device config
2185 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_HILINK_CONNECT), data,
2186 reply, option);
2187 if (error != ERR_NONE) {
2188 WIFI_LOGE("EnableHiLinkHandshake(%{public}d) failed, error code is %{public}d",
2189 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_HILINK_CONNECT), error);
2190 return WIFI_OPT_FAILED;
2191 }
2192 int exception = reply.ReadInt32();
2193 if (exception) {
2194 WIFI_LOGE("Reply Read failed, exception:%{public}d", exception);
2195 return WIFI_OPT_FAILED;
2196 }
2197 int ret = reply.ReadInt32();
2198 if (ret != WIFI_OPT_SUCCESS) {
2199 WIFI_LOGE("Reply Read failed, ret:%{public}d", ret);
2200 return ErrCode(ret);
2201 }
2202 return WIFI_OPT_SUCCESS;
2203 }
2204
SetSatelliteState(const int state)2205 ErrCode WifiDeviceProxy::SetSatelliteState(const int state)
2206 {
2207 if (mRemoteDied) {
2208 WIFI_LOGE("failed to %{public}s,remote service is died!", __func__);
2209 return WIFI_OPT_FAILED;
2210 }
2211 MessageOption option;
2212 MessageParcel data;
2213 MessageParcel reply;
2214 if (!data.WriteInterfaceToken(GetDescriptor())) {
2215 WIFI_LOGE("Write interface token error: %{public}s", __func__);
2216 return WIFI_OPT_FAILED;
2217 }
2218 data.WriteInt32(0);
2219 data.WriteInt32(state);
2220 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_SATELLITE_STATE), data,
2221 reply, option);
2222 if (error != ERR_NONE) {
2223 WIFI_LOGE("SetSatelliteState(%{public}d) failed, error code is %{public}d",
2224 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_SATELLITE_STATE), error);
2225 return WIFI_OPT_FAILED;
2226 }
2227 int exception = reply.ReadInt32();
2228 if (exception) {
2229 WIFI_LOGE("SetSatelliteState Reply Read failed, exception:%{public}d", exception);
2230 return WIFI_OPT_FAILED;
2231 }
2232 int ret = reply.ReadInt32();
2233 if (ret != WIFI_OPT_SUCCESS) {
2234 WIFI_LOGE("SetSatelliteState Reply Read failed, ret:%{public}d", ret);
2235 return ErrCode(ret);
2236 }
2237 return WIFI_OPT_SUCCESS;
2238 }
2239
EnableSemiWifi()2240 ErrCode WifiDeviceProxy::EnableSemiWifi()
2241 {
2242 if (mRemoteDied) {
2243 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2244 return WIFI_OPT_FAILED;
2245 }
2246 MessageOption option;
2247 MessageParcel data;
2248 MessageParcel reply;
2249 if (!data.WriteInterfaceToken(GetDescriptor())) {
2250 WIFI_LOGE("Write interface token error: %{public}s", __func__);
2251 return WIFI_OPT_FAILED;
2252 }
2253 data.WriteInt32(0);
2254 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_SEMI_WIFI), data,
2255 reply, option);
2256 if (error != ERR_NONE) {
2257 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2258 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_SEMI_WIFI), error);
2259 return WIFI_OPT_FAILED;
2260 }
2261 int exception = reply.ReadInt32();
2262 if (exception) {
2263 return WIFI_OPT_FAILED;
2264 }
2265 return ErrCode(reply.ReadInt32());
2266 }
2267
GetWifiDetailState(WifiDetailState & state)2268 ErrCode WifiDeviceProxy::GetWifiDetailState(WifiDetailState &state)
2269 {
2270 if (mRemoteDied) {
2271 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2272 return WIFI_OPT_FAILED;
2273 }
2274 MessageOption option;
2275 MessageParcel data;
2276 MessageParcel reply;
2277 if (!data.WriteInterfaceToken(GetDescriptor())) {
2278 WIFI_LOGE("Write interface token error: %{public}s", __func__);
2279 return WIFI_OPT_FAILED;
2280 }
2281 data.WriteInt32(0);
2282 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_DETAIL_STATE), data,
2283 reply, option);
2284 if (error != ERR_NONE) {
2285 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2286 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_DETAIL_STATE), error);
2287 return WIFI_OPT_FAILED;
2288 }
2289 int exception = reply.ReadInt32();
2290 if (exception) {
2291 return WIFI_OPT_FAILED;
2292 }
2293 int ret = reply.ReadInt32();
2294 if (ret != WIFI_OPT_SUCCESS) {
2295 return ErrCode(ret);
2296 }
2297
2298 int tempState = reply.ReadInt32();
2299 if (tempState >= 0 && tempState <= static_cast<int>(WifiDetailState::STATE_SEMI_ACTIVE)) {
2300 state = static_cast<WifiDetailState>(tempState);
2301 } else {
2302 state = WifiDetailState::STATE_UNKNOWN;
2303 }
2304 return WIFI_OPT_SUCCESS;
2305 }
2306
ReadDeviceConfig(MessageParcel & reply,WifiDeviceConfig & config)2307 void WifiDeviceProxy::ReadDeviceConfig(MessageParcel &reply, WifiDeviceConfig &config)
2308 {
2309 config.networkId = reply.ReadInt32();
2310 config.status = reply.ReadInt32();
2311 config.bssid = reply.ReadString();
2312 config.bssidType = reply.ReadInt32();
2313 config.ssid = reply.ReadString();
2314 config.band = reply.ReadInt32();
2315 config.channel = reply.ReadInt32();
2316 config.frequency = reply.ReadInt32();
2317 config.level = reply.ReadInt32();
2318 config.isPasspoint = reply.ReadBool();
2319 config.isEphemeral = reply.ReadBool();
2320 config.preSharedKey = reply.ReadString();
2321 config.keyMgmt = reply.ReadString();
2322 for (int j = 0; j < WEPKEYS_SIZE; j++) {
2323 config.wepKeys[j] = reply.ReadString();
2324 }
2325 config.wepTxKeyIndex = reply.ReadInt32();
2326 config.priority = reply.ReadInt32();
2327 config.hiddenSSID = reply.ReadBool();
2328 config.wifiIpConfig.assignMethod = AssignIpMethod(reply.ReadInt32());
2329 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.ipAddress.address);
2330 config.wifiIpConfig.staticIpAddress.ipAddress.prefixLength = reply.ReadInt32();
2331 config.wifiIpConfig.staticIpAddress.ipAddress.flags = reply.ReadInt32();
2332 config.wifiIpConfig.staticIpAddress.ipAddress.scope = reply.ReadInt32();
2333 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.gateway);
2334 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.dnsServer1);
2335 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.dnsServer2);
2336 config.wifiIpConfig.staticIpAddress.domains = reply.ReadString();
2337 ReadEapConfig(reply, config.wifiEapConfig);
2338 config.wifiProxyconfig.configureMethod = ConfigureProxyMethod(reply.ReadInt32());
2339 config.wifiProxyconfig.autoProxyConfig.pacWebAddress = reply.ReadString();
2340 config.wifiProxyconfig.manualProxyConfig.serverHostName = reply.ReadString();
2341 config.wifiProxyconfig.manualProxyConfig.serverPort = reply.ReadInt32();
2342 config.wifiProxyconfig.manualProxyConfig.exclusionObjectList = reply.ReadString();
2343 config.wifiPrivacySetting = WifiPrivacyConfig(reply.ReadInt32());
2344 config.uid = reply.ReadInt32();
2345 config.callProcessName = reply.ReadString();
2346 config.ancoCallProcessName = reply.ReadString();
2347 config.wifiWapiConfig.wapiPskType = reply.ReadInt32();
2348 config.networkSelectionStatus.status = WifiDeviceConfigStatus(reply.ReadInt32());
2349 config.networkSelectionStatus.networkSelectionDisableReason = DisabledReason(reply.ReadInt32());
2350 }
2351
GetDeviceConfig(const int & networkId,WifiDeviceConfig & config)2352 ErrCode WifiDeviceProxy::GetDeviceConfig(const int &networkId, WifiDeviceConfig &config)
2353 {
2354 if (mRemoteDied) {
2355 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2356 return WIFI_OPT_FAILED;
2357 }
2358 MessageOption option;
2359 MessageParcel data;
2360 MessageParcel reply;
2361 if (!data.WriteInterfaceToken(GetDescriptor())) {
2362 WIFI_LOGE("Write interface token error: %{public}s", __func__);
2363 return WIFI_OPT_FAILED;
2364 }
2365 data.WriteInt32(0);
2366 data.WriteInt32(networkId);
2367 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIG),
2368 data, reply, option);
2369 if (error != ERR_NONE) {
2370 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2371 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIG), error);
2372 return WIFI_OPT_FAILED;
2373 }
2374 int exception = reply.ReadInt32();
2375 if (exception) {
2376 return WIFI_OPT_FAILED;
2377 }
2378 int ret = reply.ReadInt32();
2379 if (ret != WIFI_OPT_SUCCESS) {
2380 return ErrCode(ret);
2381 }
2382
2383 ReadDeviceConfig(reply, config);
2384 return WIFI_OPT_SUCCESS;
2385 }
2386
SetDpiMarkRule(const std::string & ifaceName,int uid,int protocol,int enable)2387 ErrCode WifiDeviceProxy::SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable)
2388 {
2389 if (mRemoteDied) {
2390 WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2391 return WIFI_OPT_FAILED;
2392 }
2393 MessageOption option;
2394 MessageParcel data, reply;
2395 if (!data.WriteInterfaceToken(GetDescriptor())) {
2396 WIFI_LOGE("Write interface token error: %{public}s", __func__);
2397 return WIFI_OPT_FAILED;
2398 }
2399 data.WriteInt32(0);
2400 data.WriteCString(ifaceName.c_str());
2401 data.WriteInt32(uid);
2402 data.WriteInt32(protocol);
2403 data.WriteInt32(enable);
2404 int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_DPI_MARK_RULE),
2405 data, reply, option);
2406 if (error != ERR_NONE) {
2407 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2408 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_DPI_MARK_RULE), error);
2409 return WIFI_OPT_FAILED;
2410 }
2411 int exception = reply.ReadInt32();
2412 if (exception) {
2413 return WIFI_OPT_FAILED;
2414 }
2415 int ret = reply.ReadInt32();
2416 if (ret != WIFI_OPT_SUCCESS) {
2417 return ErrCode(ret);
2418 }
2419
2420 return WIFI_OPT_SUCCESS;
2421 }
2422
2423 } // namespace Wifi
2424 } // namespace OHOS
2425