• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "wifi_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 int g_bigDataRecvLen = 0;
31 constexpr int SIGNALARR_LENGTH = 6;
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.WriteString(config.bssid);
311     data.WriteInt32(config.bssidType);
312     data.WriteString(config.ssid);
313     data.WriteInt32(config.band);
314     data.WriteInt32(config.channel);
315     data.WriteInt32(config.frequency);
316     data.WriteInt32(config.level);
317     data.WriteBool(config.isPasspoint);
318     data.WriteBool(config.isEphemeral);
319     data.WriteString(config.preSharedKey);
320     data.WriteString(config.keyMgmt);
321     for (int i = 0; i < WEPKEYS_SIZE; i++) {
322         data.WriteString(config.wepKeys[i]);
323     }
324     data.WriteInt32(config.wepTxKeyIndex);
325     data.WriteInt32(config.priority);
326     data.WriteBool(config.hiddenSSID);
327     data.WriteInt32((int)config.wifiIpConfig.assignMethod);
328     WriteIpAddress(data, config.wifiIpConfig.staticIpAddress.ipAddress.address);
329     data.WriteInt32(config.wifiIpConfig.staticIpAddress.ipAddress.prefixLength);
330     data.WriteInt32(config.wifiIpConfig.staticIpAddress.ipAddress.flags);
331     data.WriteInt32(config.wifiIpConfig.staticIpAddress.ipAddress.scope);
332     WriteIpAddress(data, config.wifiIpConfig.staticIpAddress.gateway);
333     WriteIpAddress(data, config.wifiIpConfig.staticIpAddress.dnsServer1);
334     WriteIpAddress(data, config.wifiIpConfig.staticIpAddress.dnsServer2);
335     data.WriteString(config.wifiIpConfig.staticIpAddress.domains);
336     WriteEapConfig(data, config.wifiEapConfig);
337     data.WriteInt32((int)config.wifiProxyconfig.configureMethod);
338     data.WriteString(config.wifiProxyconfig.autoProxyConfig.pacWebAddress);
339     data.WriteString(config.wifiProxyconfig.manualProxyConfig.serverHostName);
340     data.WriteInt32(config.wifiProxyconfig.manualProxyConfig.serverPort);
341     data.WriteString(config.wifiProxyconfig.manualProxyConfig.exclusionObjectList);
342     data.WriteInt32((int)config.wifiPrivacySetting);
343     data.WriteString(config.callProcessName);
344     data.WriteString(config.ancoCallProcessName);
345     data.WriteInt32(config.uid);
346     data.WriteInt32(config.wifiWapiConfig.wapiPskType);
347     data.WriteString(config.wifiWapiConfig.wapiAsCertData);
348     data.WriteString(config.wifiWapiConfig.wapiUserCertData);
349 }
350 
RemoveCandidateConfig(const WifiDeviceConfig & config)351 ErrCode WifiDeviceProxy::RemoveCandidateConfig(const WifiDeviceConfig &config)
352 {
353     if (mRemoteDied) {
354         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
355         return WIFI_OPT_FAILED;
356     }
357     MessageOption option;
358     MessageParcel data, reply;
359     if (!data.WriteInterfaceToken(GetDescriptor())) {
360         WIFI_LOGE("Write interface token error: %{public}s", __func__);
361         return WIFI_OPT_FAILED;
362     }
363     data.WriteInt32(0);
364     /* Write a flag: 1-remove config by networkId, 2-remove config by WifiDeviceConfig */
365     data.WriteInt32(2);
366     WriteDeviceConfig(config, data);
367     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_CANDIDATE_CONFIG),
368         data, reply, option);
369     if (error != ERR_NONE) {
370         WIFI_LOGE("Set Attr(%{public}d) failed,error=%{public}d",
371             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_CANDIDATE_CONFIG), error);
372         return WIFI_OPT_FAILED;
373     }
374     int exception = reply.ReadInt32();
375     if (exception) {
376         return WIFI_OPT_FAILED;
377     }
378     int ret = reply.ReadInt32();
379     if (ret != WIFI_OPT_SUCCESS) {
380         return ErrCode(ret);
381     }
382 
383     return WIFI_OPT_SUCCESS;
384 }
385 
RemoveCandidateConfig(int networkId)386 ErrCode WifiDeviceProxy::RemoveCandidateConfig(int networkId)
387 {
388     if (mRemoteDied) {
389         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
390         return WIFI_OPT_FAILED;
391     }
392     MessageOption option;
393     MessageParcel data, reply;
394     if (!data.WriteInterfaceToken(GetDescriptor())) {
395         WIFI_LOGE("Write interface token error: %{public}s", __func__);
396         return WIFI_OPT_FAILED;
397     }
398     data.WriteInt32(0);
399     /* Write a flag: 1-remove config by networkId, 2-remove config by WifiDeviceConfig */
400     data.WriteInt32(1);
401     data.WriteInt32(networkId);
402     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_CANDIDATE_CONFIG),
403         data, reply, option);
404     if (error != ERR_NONE) {
405         WIFI_LOGE("Set Attr(%{public}d) failed,error=%{public}d",
406             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_CANDIDATE_CONFIG), error);
407         return WIFI_OPT_FAILED;
408     }
409     int exception = reply.ReadInt32();
410     if (exception) {
411         return WIFI_OPT_FAILED;
412     }
413     return ErrCode(reply.ReadInt32());
414 }
415 
AddDeviceConfig(const WifiDeviceConfig & config,int & result,bool isCandidate)416 ErrCode WifiDeviceProxy::AddDeviceConfig(const WifiDeviceConfig &config, int &result, bool isCandidate)
417 {
418     if (mRemoteDied) {
419         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
420         return WIFI_OPT_FAILED;
421     }
422     MessageOption option;
423     MessageParcel data, reply;
424     if (!data.WriteInterfaceToken(GetDescriptor())) {
425         WIFI_LOGE("Write interface token error: %{public}s", __func__);
426         return WIFI_OPT_FAILED;
427     }
428     data.WriteInt32(0);
429     /* true-candidate config, false-normal config */
430     data.WriteBool(isCandidate);
431     WriteDeviceConfig(config, data);
432     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ADD_DEVICE_CONFIG),
433         data, reply, option);
434     if (error != ERR_NONE) {
435         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
436             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ADD_DEVICE_CONFIG), error);
437         return WIFI_OPT_FAILED;
438     }
439     int exception = reply.ReadInt32();
440     if (exception) {
441         return WIFI_OPT_FAILED;
442     }
443     int ret = reply.ReadInt32();
444     if (ret != WIFI_OPT_SUCCESS) {
445         return ErrCode(ret);
446     }
447     result = reply.ReadInt32();
448 
449     return WIFI_OPT_SUCCESS;
450 }
451 
UpdateDeviceConfig(const WifiDeviceConfig & config,int & result)452 ErrCode WifiDeviceProxy::UpdateDeviceConfig(const WifiDeviceConfig &config, int &result)
453 {
454     if (mRemoteDied) {
455         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
456         return WIFI_OPT_FAILED;
457     }
458 
459     MessageOption option;
460     MessageParcel data, reply;
461     if (!data.WriteInterfaceToken(GetDescriptor())) {
462         WIFI_LOGE("Write interface token error: %{public}s", __func__);
463         return WIFI_OPT_FAILED;
464     }
465     data.WriteInt32(0);
466     WriteDeviceConfig(config, data);
467     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_UPDATE_DEVICE_CONFIG), data,
468         reply, option);
469     if (error != ERR_NONE) {
470         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
471             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_UPDATE_DEVICE_CONFIG), error);
472         return WIFI_OPT_FAILED;
473     }
474     int exception = reply.ReadInt32();
475     if (exception) {
476         return WIFI_OPT_FAILED;
477     }
478     int ret = reply.ReadInt32();
479     if (ret != WIFI_OPT_SUCCESS) {
480         return ErrCode(ret);
481     }
482     result = reply.ReadInt32();
483     return WIFI_OPT_SUCCESS;
484 }
485 
RemoveDevice(int networkId)486 ErrCode WifiDeviceProxy::RemoveDevice(int networkId)
487 {
488     if (mRemoteDied) {
489         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
490         return WIFI_OPT_FAILED;
491     }
492     MessageOption option;
493     MessageParcel data, reply;
494     if (!data.WriteInterfaceToken(GetDescriptor())) {
495         WIFI_LOGE("Write interface token error: %{public}s", __func__);
496         return WIFI_OPT_FAILED;
497     }
498     data.WriteInt32(0);
499     data.WriteInt32(networkId);
500     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_DEVICE_CONFIG),
501         data, reply, option);
502     if (error != ERR_NONE) {
503         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
504             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_DEVICE_CONFIG), error);
505         return WIFI_OPT_FAILED;
506     }
507     int exception = reply.ReadInt32();
508     if (exception) {
509         return WIFI_OPT_FAILED;
510     }
511     return ErrCode(reply.ReadInt32());
512 }
513 
RemoveAllDevice()514 ErrCode WifiDeviceProxy::RemoveAllDevice()
515 {
516     if (mRemoteDied) {
517         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
518         return WIFI_OPT_FAILED;
519     }
520     MessageOption option;
521     MessageParcel data;
522     MessageParcel reply;
523     if (!data.WriteInterfaceToken(GetDescriptor())) {
524         WIFI_LOGE("Write interface token error: %{public}s", __func__);
525         return WIFI_OPT_FAILED;
526     }
527     data.WriteInt32(0);
528     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_ALL_DEVICE_CONFIG),
529         data, reply, option);
530     if (error != ERR_NONE) {
531         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
532             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_ALL_DEVICE_CONFIG), error);
533         return WIFI_OPT_FAILED;
534     }
535 
536     int exception = reply.ReadInt32();
537     if (exception) {
538         return WIFI_OPT_FAILED;
539     }
540     return ErrCode(reply.ReadInt32());
541 }
542 
ReadIpAddress(MessageParcel & reply,WifiIpAddress & address)543 void WifiDeviceProxy::ReadIpAddress(MessageParcel &reply, WifiIpAddress &address)
544 {
545     address.family = reply.ReadInt32();
546     address.addressIpv4 = static_cast<uint32_t>(reply.ReadInt32());
547     int size = reply.ReadInt32();
548     if (size > MAX_SIZE) {
549         WIFI_LOGE("Read IP address size error: %{public}d", size);
550         return;
551     }
552     for (int i = 0; i < size; i++) {
553         address.addressIpv6.push_back(reply.ReadInt8());
554     }
555     return;
556 }
557 
BigDataReadIpAddress(WifiIpAddress & address,std::vector<std::string> & tokens)558 void WifiDeviceProxy::BigDataReadIpAddress(WifiIpAddress &address, std::vector<std::string> &tokens)
559 {
560     address.family = CheckDataLegal(tokens[g_bigDataRecvLen++]);
561     address.addressIpv4 = static_cast<size_t>(CheckDataLegal(tokens[g_bigDataRecvLen++]));
562     int size = CheckDataLegal(tokens[g_bigDataRecvLen++]);
563     if (size > MAX_SIZE) {
564         WIFI_LOGE("Read IP address size error: %{public}d", size);
565         return;
566     }
567     for (int i = 0; i < size; i++) {
568         address.addressIpv6.push_back(CheckDataLegal(tokens[g_bigDataRecvLen++]));
569     }
570     return;
571 }
572 
ReadEapConfig(MessageParcel & reply,WifiEapConfig & wifiEapConfig)573 void WifiDeviceProxy::ReadEapConfig(MessageParcel &reply, WifiEapConfig &wifiEapConfig)
574 {
575     wifiEapConfig.eap = reply.ReadString();
576     wifiEapConfig.phase2Method = Phase2Method(reply.ReadInt32());
577     wifiEapConfig.identity = reply.ReadString();
578     wifiEapConfig.anonymousIdentity = reply.ReadString();
579     wifiEapConfig.password = reply.ReadString();
580     wifiEapConfig.caCertPath = reply.ReadString();
581     wifiEapConfig.caCertAlias = reply.ReadString();
582     reply.ReadUInt8Vector(&wifiEapConfig.certEntry);
583     wifiEapConfig.clientCert = reply.ReadString();
584     if (strcpy_s(wifiEapConfig.certPassword, sizeof(wifiEapConfig.certPassword),
585         reply.ReadString().c_str()) != EOK) {
586         WIFI_LOGE("%{public}s: failed to copy", __func__);
587     }
588     wifiEapConfig.privateKey = reply.ReadString();
589     wifiEapConfig.altSubjectMatch = reply.ReadString();
590     wifiEapConfig.domainSuffixMatch = reply.ReadString();
591     wifiEapConfig.realm = reply.ReadString();
592     wifiEapConfig.plmn = reply.ReadString();
593     wifiEapConfig.eapSubId = reply.ReadInt32();
594 }
595 
BigDataReadEapConfig(WifiEapConfig & wifiEapConfig,std::vector<std::string> & tokens)596 void WifiDeviceProxy::BigDataReadEapConfig(WifiEapConfig &wifiEapConfig, std::vector<std::string> &tokens)
597 {
598     wifiEapConfig.eap = HexToString(tokens[g_bigDataRecvLen++]);
599     wifiEapConfig.phase2Method = Phase2Method(CheckDataLegal(tokens[g_bigDataRecvLen++]));
600     wifiEapConfig.identity = HexToString(tokens[g_bigDataRecvLen++]);
601     wifiEapConfig.anonymousIdentity = HexToString(tokens[g_bigDataRecvLen++]);
602     wifiEapConfig.password = HexToString(tokens[g_bigDataRecvLen++]);
603     wifiEapConfig.caCertPath = HexToString(tokens[g_bigDataRecvLen++]);
604     wifiEapConfig.caCertAlias = HexToString(tokens[g_bigDataRecvLen++]);
605     wifiEapConfig.clientCert = HexToString(tokens[g_bigDataRecvLen++]);
606     wifiEapConfig.privateKey = HexToString(tokens[g_bigDataRecvLen++]);
607     wifiEapConfig.altSubjectMatch = HexToString(tokens[g_bigDataRecvLen++]);
608     wifiEapConfig.domainSuffixMatch = HexToString(tokens[g_bigDataRecvLen++]);
609     wifiEapConfig.realm = HexToString(tokens[g_bigDataRecvLen++]);
610     wifiEapConfig.plmn = HexToString(tokens[g_bigDataRecvLen++]);
611     wifiEapConfig.eapSubId = CheckDataLegal(tokens[g_bigDataRecvLen++]);
612 }
613 
splitString(std::string str,char delimiter)614 std::vector<std::string> splitString(std::string str, char delimiter)
615 {
616     std::vector<std::string> tokens;
617     std::string token;
618     size_t pos = 0;
619     while ((pos = str.find(delimiter)) != std::string::npos) {
620         token = str.substr(0, pos);
621         tokens.push_back(token);
622         str.erase(0, pos + 1);
623     }
624     tokens.push_back(str);
625     return tokens;
626 }
627 
ParseDeviceConfigs(MessageParcel & reply,std::vector<WifiDeviceConfig> & result)628 void WifiDeviceProxy::ParseDeviceConfigs(MessageParcel &reply, std::vector<WifiDeviceConfig> &result)
629 {
630     WIFI_LOGI("ParseDeviceConfigs");
631     constexpr int MAX_DEVICE_CONFIG_SIZE = 1024;
632     std::vector<uint32_t> allSize;
633     reply.ReadUInt32Vector(&allSize);
634     uint32_t retSize = allSize.size();
635     if (retSize > MAX_DEVICE_CONFIG_SIZE || retSize == 0) {
636         WIFI_LOGE("Parse device config size error: %{public}d", retSize);
637         return;
638     }
639     sptr<Ashmem> ashmem = reply.ReadAshmem();
640     if (ashmem == nullptr || !ashmem->MapReadAndWriteAshmem()) {
641         WIFI_LOGE("ParseDeviceConfigs ReadAshmem error");
642         return;
643     }
644     int offset = 0;
645     for (uint32_t i = 0; i < retSize; i++) {
646         auto origin = ashmem->ReadFromAshmem(allSize[i], offset);
647         if (origin == nullptr) {
648             offset += static_cast<int>(allSize[i]);
649             continue;
650         }
651         MessageParcel inParcel;
652         inParcel.WriteBuffer(reinterpret_cast<const char*>(origin), allSize[i]);
653         WifiDeviceConfig config;
654         ReadDeviceConfig(inParcel, config);
655         offset += static_cast<int>(allSize[i]);
656         result.emplace_back(config);
657     }
658     ashmem->UnmapAshmem();
659     ashmem->CloseAshmem();
660     return;
661 }
662 
ParseMultiLinkedInfo(MessageParcel & reply,std::vector<WifiLinkedInfo> & result)663 void WifiDeviceProxy::WifiDeviceProxy::ParseMultiLinkedInfo(MessageParcel &reply, std::vector<WifiLinkedInfo> &result)
664 {
665     std::vector<uint32_t> allSize;
666     reply.ReadUInt32Vector(&allSize);
667     uint32_t retSize = static_cast<uint32_t>(allSize.size());
668     if (retSize > WIFI_MAX_MLO_LINK_NUM || retSize == 0) {
669         WIFI_LOGE("Parse multi linked info size error: %{public}d", retSize);
670         return;
671     }
672     sptr<Ashmem> ashmem = reply.ReadAshmem();
673     if (ashmem == nullptr || !ashmem->MapReadAndWriteAshmem()) {
674         WIFI_LOGE("ParseMultiLinkedInfo ReadAshmem error");
675         return;
676     }
677     int offset = 0;
678     for (uint32_t i = 0; i < retSize; i++) {
679         auto origin = ashmem->ReadFromAshmem(allSize[i], offset);
680         if (origin == nullptr) {
681             offset += static_cast<int>(allSize[i]);
682             continue;
683         }
684         MessageParcel inParcel;
685         inParcel.WriteBuffer(reinterpret_cast<const char*>(origin), allSize[i]);
686         WifiLinkedInfo info;
687         ReadLinkedInfo(inParcel, info);
688         offset += static_cast<int>(allSize[i]);
689         result.emplace_back(info);
690     }
691     ashmem->UnmapAshmem();
692     ashmem->CloseAshmem();
693 }
694 
GetDeviceConfigs(std::vector<WifiDeviceConfig> & result,bool isCandidate)695 ErrCode WifiDeviceProxy::GetDeviceConfigs(std::vector<WifiDeviceConfig> &result, bool isCandidate)
696 {
697     if (mRemoteDied) {
698         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
699         return WIFI_OPT_FAILED;
700     }
701     MessageOption option;
702     MessageParcel data;
703     MessageParcel reply;
704     if (!data.WriteInterfaceToken(GetDescriptor())) {
705         WIFI_LOGE("Write interface token error: %{public}s", __func__);
706         return WIFI_OPT_FAILED;
707     }
708     data.WriteInt32(0);
709     /* true-candidate config, false-normal config */
710     data.WriteBool(isCandidate);
711     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIGS),
712         data, reply, option);
713     if (error != ERR_NONE) {
714         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
715             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIGS), error);
716         return WIFI_OPT_FAILED;
717     }
718     int exception = reply.ReadInt32();
719     if (exception) {
720         return WIFI_OPT_FAILED;
721     }
722     int ret = reply.ReadInt32();
723     if (ret != WIFI_OPT_SUCCESS) {
724         return ErrCode(ret);
725     }
726 
727     ParseDeviceConfigs(reply, result);
728     return WIFI_OPT_SUCCESS;
729 }
730 
SetTxPower(int power)731 ErrCode WifiDeviceProxy::SetTxPower(int power)
732 {
733     if (mRemoteDied) {
734         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
735         return WIFI_OPT_FAILED;
736     }
737     MessageOption option;
738     MessageParcel data;
739     MessageParcel reply;
740     if (!data.WriteInterfaceToken(GetDescriptor())) {
741         WIFI_LOGE("Write interface token error: %{public}s", __func__);
742         return WIFI_OPT_FAILED;
743     }
744     data.WriteInt32(0);
745     data.WriteInt32(power);
746     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_TX_POWER), data, reply,
747         option);
748     if (error != ERR_NONE) {
749         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
750             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_TX_POWER), error);
751         return WIFI_OPT_FAILED;
752     }
753     int exception = reply.ReadInt32();
754     if (exception) {
755         return WIFI_OPT_FAILED;
756     }
757     return ErrCode(reply.ReadInt32());
758 }
759 
EnableDeviceConfig(int networkId,bool attemptEnable)760 ErrCode WifiDeviceProxy::EnableDeviceConfig(int networkId, bool attemptEnable)
761 {
762     if (mRemoteDied) {
763         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
764         return WIFI_OPT_FAILED;
765     }
766     MessageOption option;
767     MessageParcel data, reply;
768     if (!data.WriteInterfaceToken(GetDescriptor())) {
769         WIFI_LOGE("Write interface token error: %{public}s", __func__);
770         return WIFI_OPT_FAILED;
771     }
772     data.WriteInt32(0);
773     data.WriteInt32(networkId);
774     data.WriteInt32(attemptEnable);
775     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_DEVICE), data, reply,
776         option);
777     if (error != ERR_NONE) {
778         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
779             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_DEVICE), error);
780         return WIFI_OPT_FAILED;
781     }
782     int exception = reply.ReadInt32();
783     if (exception) {
784         return WIFI_OPT_FAILED;
785     }
786     return ErrCode(reply.ReadInt32());
787 }
788 
DisableDeviceConfig(int networkId)789 ErrCode WifiDeviceProxy::DisableDeviceConfig(int networkId)
790 {
791     if (mRemoteDied) {
792         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
793         return WIFI_OPT_FAILED;
794     }
795     MessageOption option;
796     MessageParcel data, reply;
797     if (!data.WriteInterfaceToken(GetDescriptor())) {
798         WIFI_LOGE("Write interface token error: %{public}s", __func__);
799         return WIFI_OPT_FAILED;
800     }
801     data.WriteInt32(0);
802     data.WriteInt32(networkId);
803     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_DEVICE), data, reply,
804         option);
805     if (error != ERR_NONE) {
806         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
807             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_DEVICE), error);
808         return WIFI_OPT_FAILED;
809     }
810     int exception = reply.ReadInt32();
811     if (exception) {
812         return WIFI_OPT_FAILED;
813     }
814     return ErrCode(reply.ReadInt32());
815 }
816 
AllowAutoConnect(int32_t networkId,bool isAllowed)817 ErrCode WifiDeviceProxy::AllowAutoConnect(int32_t networkId, bool isAllowed)
818 {
819     if (mRemoteDied) {
820         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
821         return WIFI_OPT_FAILED;
822     }
823     MessageOption option;
824     MessageParcel data, reply;
825     if (!data.WriteInterfaceToken(GetDescriptor())) {
826         WIFI_LOGE("Write interface token error: %{public}s", __func__);
827         return WIFI_OPT_FAILED;
828     }
829     data.WriteInt32(0);
830     data.WriteInt32(networkId);
831     data.WriteBool(isAllowed);
832     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ALLOW_AUTO_CONNECT), data,
833         reply, option);
834     if (error != ERR_NONE) {
835         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
836             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ALLOW_AUTO_CONNECT), error);
837         return WIFI_OPT_FAILED;
838     }
839     int exception = reply.ReadInt32();
840     if (exception) {
841         return WIFI_OPT_FAILED;
842     }
843     return ErrCode(reply.ReadInt32());
844 }
845 
ConnectToNetwork(int networkId,bool isCandidate)846 ErrCode WifiDeviceProxy::ConnectToNetwork(int networkId, bool isCandidate)
847 {
848     if (mRemoteDied) {
849         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
850         return WIFI_OPT_FAILED;
851     }
852     MessageOption option;
853     MessageParcel data, reply;
854     if (!data.WriteInterfaceToken(GetDescriptor())) {
855         WIFI_LOGE("Write interface token error: %{public}s", __func__);
856         return WIFI_OPT_FAILED;
857     }
858     data.WriteInt32(0);
859     /* true-candidate config, false-normal config */
860     data.WriteBool(isCandidate);
861     data.WriteInt32(networkId);
862     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT_TO), data, reply,
863         option);
864     if (error != ERR_NONE) {
865         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
866             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT_TO), error);
867         return WIFI_OPT_FAILED;
868     }
869     int exception = reply.ReadInt32();
870     if (exception) {
871         return WIFI_OPT_FAILED;
872     }
873     return ErrCode(reply.ReadInt32());
874 }
875 
ConnectToDevice(const WifiDeviceConfig & config)876 ErrCode WifiDeviceProxy::ConnectToDevice(const WifiDeviceConfig &config)
877 {
878     if (mRemoteDied) {
879         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
880         return WIFI_OPT_FAILED;
881     }
882     MessageOption option;
883     MessageParcel data, reply;
884     if (!data.WriteInterfaceToken(GetDescriptor())) {
885         WIFI_LOGE("Write interface token error: %{public}s", __func__);
886         return WIFI_OPT_FAILED;
887     }
888     data.WriteInt32(0);
889     WriteDeviceConfig(config, data);
890     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT2_TO), data, reply,
891         option);
892     if (error != ERR_NONE) {
893         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
894             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT2_TO), error);
895         return WIFI_OPT_FAILED;
896     }
897     int exception = reply.ReadInt32();
898     if (exception) {
899         return WIFI_OPT_FAILED;
900     }
901     return ErrCode(reply.ReadInt32());
902 }
903 
StartRoamToNetwork(const int networkId,const std::string bssid,const bool isCandidate)904 ErrCode WifiDeviceProxy::StartRoamToNetwork(const int networkId, const std::string bssid, const bool isCandidate)
905 {
906     if (mRemoteDied) {
907         WIFI_LOGE("failed to %{public}s,remote service is died!", __func__);
908         return WIFI_OPT_FAILED;
909     }
910     MessageOption option;
911     MessageParcel data;
912     MessageParcel reply;
913     if (!data.WriteInterfaceToken(GetDescriptor())) {
914         WIFI_LOGE("%{public}s write interface token error.", __func__);
915         return WIFI_OPT_FAILED;
916     }
917     data.WriteInt32(0);
918     data.WriteInt32(networkId);
919     data.WriteString(bssid);
920     data.WriteInt32(isCandidate);
921     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_ROAM_TO_NETWORK), data,
922         reply, option);
923     if (error != ERR_NONE) {
924         WIFI_LOGE("StartRoamToNetwork %{public}d failed, error code is %{public}d",
925             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_ROAM_TO_NETWORK), error);
926         return WIFI_OPT_FAILED;
927     }
928     int exception = reply.ReadInt32();
929     if (exception) {
930         WIFI_LOGE("StartRoamToNetwork Reply Read failed, exception:%{public}d", exception);
931         return WIFI_OPT_FAILED;
932     }
933     int ret = reply.ReadInt32();
934     if (ret != WIFI_OPT_SUCCESS) {
935         WIFI_LOGE("StartRoamToNetwork Reply Read failed, ret:%{public}d", ret);
936         return ErrCode(ret);
937     }
938     return WIFI_OPT_SUCCESS;
939 }
940 
StartConnectToUserSelectNetwork(const int networkId,const std::string bssid,const bool isCandidate)941 ErrCode WifiDeviceProxy::StartConnectToUserSelectNetwork(const int networkId,
942     const std::string bssid, const bool isCandidate)
943 {
944     if (mRemoteDied) {
945         WIFI_LOGE("failed to StartConnectToUserSelectNetwork, remote service is died!");
946         return WIFI_OPT_FAILED;
947     }
948     MessageOption option;
949     MessageParcel data;
950     MessageParcel reply;
951     if (!data.WriteInterfaceToken(GetDescriptor())) {
952         WIFI_LOGE("Write interface token has error: %{public}s", __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>(
960         DevInterfaceCode::WIFI_SVR_CMD_START_CONNECT_TO_USER_SELECT_NETWORK), data, reply, option);
961     if (error != ERR_NONE) {
962         WIFI_LOGE("StartConnectToUserSelectNetwork %{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("StartConnectToUserSelectNetwork 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("StartConnectToUserSelectNetwork Reply Read failed, ret:%{public}d", ret);
974         return ErrCode(ret);
975     }
976     return WIFI_OPT_SUCCESS;
977 }
978 
IsConnected(bool & isConnected)979 ErrCode WifiDeviceProxy::IsConnected(bool &isConnected)
980 {
981     if (mRemoteDied) {
982         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
983         return WIFI_OPT_FAILED;
984     }
985     MessageOption option;
986     MessageParcel data, reply;
987     if (!data.WriteInterfaceToken(GetDescriptor())) {
988         WIFI_LOGE("Write interface token error: %{public}s", __func__);
989         return WIFI_OPT_FAILED;
990     }
991     data.WriteInt32(0);
992     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_CONNECTED), data,
993         reply, option);
994     if (error != ERR_NONE) {
995         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
996             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_CONNECTED), error);
997         return WIFI_OPT_FAILED;
998     }
999     int exception = reply.ReadInt32();
1000     if (exception) {
1001         return WIFI_OPT_FAILED;
1002     }
1003     int ret = reply.ReadInt32();
1004     if (ret != WIFI_OPT_SUCCESS) {
1005         return ErrCode(ret);
1006     }
1007     isConnected = reply.ReadBool();
1008     return WIFI_OPT_SUCCESS;
1009 }
1010 
ReConnect()1011 ErrCode WifiDeviceProxy::ReConnect()
1012 {
1013     if (mRemoteDied) {
1014         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1015         return WIFI_OPT_FAILED;
1016     }
1017     MessageOption option;
1018     MessageParcel data, reply;
1019     if (!data.WriteInterfaceToken(GetDescriptor())) {
1020         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1021         return WIFI_OPT_FAILED;
1022     }
1023     data.WriteInt32(0);
1024     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_RECONNECT), data, reply,
1025         option);
1026     if (error != ERR_NONE) {
1027         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1028             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_RECONNECT), error);
1029         return WIFI_OPT_FAILED;
1030     }
1031     int exception = reply.ReadInt32();
1032     if (exception) {
1033         return WIFI_OPT_FAILED;
1034     }
1035     return ErrCode(reply.ReadInt32());
1036 }
1037 
ReAssociate(void)1038 ErrCode WifiDeviceProxy::ReAssociate(void)
1039 {
1040     if (mRemoteDied) {
1041         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1042         return WIFI_OPT_FAILED;
1043     }
1044     MessageOption option;
1045     MessageParcel data, reply;
1046     if (!data.WriteInterfaceToken(GetDescriptor())) {
1047         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1048         return WIFI_OPT_FAILED;
1049     }
1050     data.WriteInt32(0);
1051     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REASSOCIATE), data, reply,
1052         option);
1053     if (error != ERR_NONE) {
1054         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1055             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REASSOCIATE), error);
1056         return WIFI_OPT_FAILED;
1057     }
1058     int exception = reply.ReadInt32();
1059     if (exception) {
1060         return WIFI_OPT_FAILED;
1061     }
1062     return ErrCode(reply.ReadInt32());
1063 }
1064 
Disconnect(void)1065 ErrCode WifiDeviceProxy::Disconnect(void)
1066 {
1067     if (mRemoteDied) {
1068         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1069         return WIFI_OPT_FAILED;
1070     }
1071     MessageOption option;
1072     MessageParcel data, reply;
1073     if (!data.WriteInterfaceToken(GetDescriptor())) {
1074         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1075         return WIFI_OPT_FAILED;
1076     }
1077     data.WriteInt32(0);
1078     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISCONNECT), data, reply,
1079         option);
1080     if (error != ERR_NONE) {
1081         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1082             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISCONNECT), error);
1083         return WIFI_OPT_FAILED;
1084     }
1085     int exception = reply.ReadInt32();
1086     if (exception) {
1087         return WIFI_OPT_FAILED;
1088     }
1089     return ErrCode(reply.ReadInt32());
1090 }
1091 
StartWps(const WpsConfig & config)1092 ErrCode WifiDeviceProxy::StartWps(const WpsConfig &config)
1093 {
1094     if (mRemoteDied) {
1095         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1096         return WIFI_OPT_FAILED;
1097     }
1098     MessageOption option;
1099     MessageParcel data, reply;
1100     if (!data.WriteInterfaceToken(GetDescriptor())) {
1101         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1102         return WIFI_OPT_FAILED;
1103     }
1104     data.WriteInt32(0);
1105     data.WriteInt32(static_cast<int>(config.setup));
1106     data.WriteCString(config.pin.c_str());
1107     data.WriteCString(config.bssid.c_str());
1108     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_WPS), data, reply,
1109         option);
1110     if (error != ERR_NONE) {
1111         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1112             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_WPS), error);
1113         return WIFI_OPT_FAILED;
1114     }
1115     int exception = reply.ReadInt32();
1116     if (exception) {
1117         return WIFI_OPT_FAILED;
1118     }
1119     return ErrCode(reply.ReadInt32());
1120 }
1121 
CancelWps(void)1122 ErrCode WifiDeviceProxy::CancelWps(void)
1123 {
1124     if (mRemoteDied) {
1125         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1126         return WIFI_OPT_FAILED;
1127     }
1128     MessageOption option;
1129     MessageParcel data, reply;
1130     if (!data.WriteInterfaceToken(GetDescriptor())) {
1131         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1132         return WIFI_OPT_FAILED;
1133     }
1134     data.WriteInt32(0);
1135     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_CANCEL_WPS), data, reply,
1136         option);
1137     if (error != ERR_NONE) {
1138         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1139             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CANCEL_WPS), error);
1140         return WIFI_OPT_FAILED;
1141     }
1142     int exception = reply.ReadInt32();
1143     if (exception) {
1144         return WIFI_OPT_FAILED;
1145     }
1146     return ErrCode(reply.ReadInt32());
1147 }
1148 
IsWifiActive(bool & bActive)1149 ErrCode WifiDeviceProxy::IsWifiActive(bool &bActive)
1150 {
1151     if (mRemoteDied) {
1152         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1153         return WIFI_OPT_FAILED;
1154     }
1155     MessageOption option;
1156     MessageParcel data, reply;
1157     if (!data.WriteInterfaceToken(GetDescriptor())) {
1158         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1159         return WIFI_OPT_FAILED;
1160     }
1161     data.WriteInt32(0);
1162     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_ACTIVE), data, reply,
1163         option);
1164     if (error != ERR_NONE) {
1165         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1166             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_ACTIVE), error);
1167         return WIFI_OPT_FAILED;
1168     }
1169     int exception = reply.ReadInt32();
1170     if (exception) {
1171         return WIFI_OPT_FAILED;
1172     }
1173     int ret = reply.ReadInt32();
1174     if (ret != WIFI_OPT_SUCCESS) {
1175         return ErrCode(ret);
1176     }
1177 
1178     bActive = reply.ReadBool();
1179     return WIFI_OPT_SUCCESS;
1180 }
1181 
GetWifiState(int & state)1182 ErrCode WifiDeviceProxy::GetWifiState(int &state)
1183 {
1184     if (mRemoteDied) {
1185         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1186         return WIFI_OPT_FAILED;
1187     }
1188     MessageOption option;
1189     MessageParcel data, reply;
1190     if (!data.WriteInterfaceToken(GetDescriptor())) {
1191         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1192         return WIFI_OPT_FAILED;
1193     }
1194     data.WriteInt32(0);
1195     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_STATE), data, reply,
1196         option);
1197     if (error != ERR_NONE) {
1198         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1199             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_STATE), error);
1200         return WIFI_OPT_FAILED;
1201     }
1202     int exception = reply.ReadInt32();
1203     if (exception) {
1204         return WIFI_OPT_FAILED;
1205     }
1206     int ret = reply.ReadInt32();
1207     if (ret != WIFI_OPT_SUCCESS) {
1208         return ErrCode(ret);
1209     }
1210 
1211     state = reply.ReadInt32();
1212     return WIFI_OPT_SUCCESS;
1213 }
1214 
ReadLinkedInfo(MessageParcel & reply,WifiLinkedInfo & info)1215 void WifiDeviceProxy::ReadLinkedInfo(MessageParcel &reply, WifiLinkedInfo &info)
1216 {
1217     info.networkId = reply.ReadInt32();
1218     info.ssid = reply.ReadString();
1219     info.bssid = reply.ReadString();
1220     info.rssi = reply.ReadInt32();
1221     info.band = reply.ReadInt32();
1222     info.frequency = reply.ReadInt32();
1223     info.linkSpeed = reply.ReadInt32();
1224     info.macAddress = reply.ReadString();
1225     info.macType = reply.ReadInt32();
1226     info.ipAddress = static_cast<uint32_t>(reply.ReadInt32());
1227     int tmpConnState = reply.ReadInt32();
1228     if ((tmpConnState >= 0) && (tmpConnState <= (int)ConnState::UNKNOWN)) {
1229         info.connState = ConnState(tmpConnState);
1230     } else {
1231         info.connState = ConnState::UNKNOWN;
1232     }
1233     info.ifHiddenSSID = reply.ReadBool();
1234     info.rxLinkSpeed = reply.ReadInt32();
1235     info.txLinkSpeed = reply.ReadInt32();
1236     info.chload = reply.ReadInt32();
1237     info.snr = reply.ReadInt32();
1238     info.isDataRestricted = reply.ReadInt32();
1239     info.portalUrl = reply.ReadString();
1240 
1241     int tmpState = reply.ReadInt32();
1242     if ((tmpState >= 0) && (tmpState <= (int)SupplicantState::INVALID)) {
1243         info.supplicantState = (SupplicantState)tmpState;
1244     } else {
1245         info.supplicantState = SupplicantState::INVALID;
1246     }
1247 
1248     int tmpDetailState = reply.ReadInt32();
1249     if ((tmpDetailState >= 0) && (tmpDetailState <= (int)DetailedState::INVALID)) {
1250         info.detailedState = (DetailedState)tmpDetailState;
1251     } else {
1252         info.detailedState = DetailedState::INVALID;
1253     }
1254     info.wifiStandard = reply.ReadInt32();
1255     info.maxSupportedRxLinkSpeed = reply.ReadInt32();
1256     info.maxSupportedTxLinkSpeed = reply.ReadInt32();
1257     int tmpChanWidth = reply.ReadInt32();
1258     if ((tmpChanWidth >= 0) && (tmpChanWidth <= (int)WifiChannelWidth::WIDTH_INVALID)) {
1259         info.channelWidth = (WifiChannelWidth)tmpChanWidth;
1260     } else {
1261         info.channelWidth = WifiChannelWidth::WIDTH_INVALID;
1262     }
1263     info.isAncoConnected = reply.ReadBool();
1264     info.supportedWifiCategory = static_cast<WifiCategory>(reply.ReadInt32());
1265     info.isHiLinkNetwork = reply.ReadBool();
1266     info.lastRxPackets = reply.ReadInt32();
1267     info.lastTxPackets = reply.ReadInt32();
1268     info.wifiLinkType = static_cast<WifiLinkType>(reply.ReadInt32());
1269     info.linkId = reply.ReadInt32();
1270 }
1271 
ReadWifiSignalPollInfo(MessageParcel & reply,std::vector<WifiSignalPollInfo> & wifiSignalPollInfos)1272 void WifiDeviceProxy::ReadWifiSignalPollInfo(MessageParcel &reply, std::vector<WifiSignalPollInfo> &wifiSignalPollInfos)
1273 {
1274     int arrayLength = reply.ReadInt32();
1275     if (arrayLength > SIGNALARR_LENGTH) {
1276         arrayLength = SIGNALARR_LENGTH;
1277     }
1278     for (int index = 0; index < arrayLength; index++) {
1279         WifiSignalPollInfo signInfo;
1280         signInfo.signal = reply.ReadInt32();
1281         signInfo.txrate = reply.ReadInt32();
1282         signInfo.rxrate = reply.ReadInt32();
1283         signInfo.noise = reply.ReadInt32();
1284         signInfo.txPackets = reply.ReadInt32();
1285         signInfo.rxPackets = reply.ReadInt32();
1286         signInfo.snr = reply.ReadInt32();
1287         signInfo.chload = reply.ReadInt32();
1288         signInfo.ulDelay = reply.ReadInt32();
1289         signInfo.txBytes = reply.ReadInt32();
1290         signInfo.rxBytes = reply.ReadInt32();
1291         signInfo.txFailed = reply.ReadInt32();
1292         signInfo.chloadSelf = reply.ReadInt32();
1293         signInfo.timeStamp = reply.ReadInt64();
1294         wifiSignalPollInfos.push_back(signInfo);
1295     }
1296 }
1297 
GetDisconnectedReason(DisconnectedReason & reason)1298 ErrCode WifiDeviceProxy::GetDisconnectedReason(DisconnectedReason &reason)
1299 {
1300     if (mRemoteDied) {
1301         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1302         return WIFI_OPT_FAILED;
1303     }
1304     MessageOption option;
1305     MessageParcel data, reply;
1306     if (!data.WriteInterfaceToken(GetDescriptor())) {
1307         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1308         return WIFI_OPT_FAILED;
1309     }
1310     data.WriteInt32(0);
1311     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DISCONNECTED_REASON),
1312         data, reply, option);
1313     if (error != ERR_NONE) {
1314         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1315             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DISCONNECTED_REASON), error);
1316         return WIFI_OPT_FAILED;
1317     }
1318 
1319     int exception = reply.ReadInt32();
1320     if (exception) {
1321         return WIFI_OPT_FAILED;
1322     }
1323     int ret = reply.ReadInt32();
1324     if (ret != WIFI_OPT_SUCCESS) {
1325         return ErrCode(ret);
1326     }
1327     int tempReason = reply.ReadInt32();
1328     if (tempReason >= 0 && tempReason <= (int)DisconnectedReason::DISC_REASON_CONNECTION_REJECTED) {
1329         reason = (DisconnectedReason)tempReason;
1330     } else {
1331         reason = DisconnectedReason::DISC_REASON_DEFAULT;
1332     }
1333     return WIFI_OPT_SUCCESS;
1334 }
1335 
IsMeteredHotspot(bool & bMeteredHotspot)1336 ErrCode WifiDeviceProxy::IsMeteredHotspot(bool &bMeteredHotspot)
1337 {
1338     if (mRemoteDied) {
1339         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1340         return WIFI_OPT_FAILED;
1341     }
1342     MessageOption option;
1343     MessageParcel data, reply;
1344     if (!data.WriteInterfaceToken(GetDescriptor())) {
1345         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1346         return WIFI_OPT_FAILED;
1347     }
1348     data.WriteInt32(0);
1349     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_METERED_HOTSPOT),
1350         data, reply, option);
1351     if (error != ERR_NONE) {
1352         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1353             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_METERED_HOTSPOT), error);
1354         return WIFI_OPT_FAILED;
1355     }
1356     int exception = reply.ReadInt32();
1357     if (exception) {
1358         return WIFI_OPT_FAILED;
1359     }
1360     int ret = reply.ReadInt32();
1361     if (ret != WIFI_OPT_SUCCESS) {
1362         return ErrCode(ret);
1363     }
1364 
1365     bMeteredHotspot = reply.ReadBool();
1366     return WIFI_OPT_SUCCESS;
1367 }
1368 
GetLinkedInfo(WifiLinkedInfo & info)1369 ErrCode WifiDeviceProxy::GetLinkedInfo(WifiLinkedInfo &info)
1370 {
1371     if (mRemoteDied) {
1372         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1373         return WIFI_OPT_FAILED;
1374     }
1375     MessageOption option;
1376     MessageParcel data, reply;
1377     if (!data.WriteInterfaceToken(GetDescriptor())) {
1378         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1379         return WIFI_OPT_FAILED;
1380     }
1381     data.WriteInt32(0);
1382     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_LINKED_INFO), data,
1383         reply, option);
1384     if (error != ERR_NONE) {
1385         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1386             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_LINKED_INFO), error);
1387         return WIFI_OPT_FAILED;
1388     }
1389 
1390     int exception = reply.ReadInt32();
1391     if (exception) {
1392         return WIFI_OPT_FAILED;
1393     }
1394     int ret = reply.ReadInt32();
1395     if (ret != WIFI_OPT_SUCCESS) {
1396         return ErrCode(ret);
1397     }
1398 
1399     ReadLinkedInfo(reply, info);
1400     return WIFI_OPT_SUCCESS;
1401 }
1402 
GetSignalPollInfoArray(std::vector<WifiSignalPollInfo> & wifiSignalPollInfos,int length)1403 ErrCode WifiDeviceProxy::GetSignalPollInfoArray(std::vector<WifiSignalPollInfo> &wifiSignalPollInfos, int length)
1404 {
1405     if (mRemoteDied) {
1406         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1407         return WIFI_OPT_FAILED;
1408     }
1409     MessageOption option;
1410     MessageParcel data;
1411     MessageParcel reply;
1412     if (!data.WriteInterfaceToken(GetDescriptor())) {
1413         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1414         return WIFI_OPT_FAILED;
1415     }
1416     data.WriteInt32(0);
1417     data.WriteInt32(length);
1418 
1419     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SIGNALPOLL_INFO_ARRAY),
1420         data, reply, option);
1421     if (error != ERR_NONE) {
1422         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1423             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SIGNALPOLL_INFO_ARRAY), error);
1424         return WIFI_OPT_FAILED;
1425     }
1426 
1427     int exception = reply.ReadInt32();
1428     if (exception) {
1429         return WIFI_OPT_FAILED;
1430     }
1431     int ret = reply.ReadInt32();
1432     if (ret != WIFI_OPT_SUCCESS) {
1433         return ErrCode(ret);
1434     }
1435     ReadWifiSignalPollInfo(reply, wifiSignalPollInfos);
1436     return WIFI_OPT_SUCCESS;
1437 }
1438 
GetIpInfo(IpInfo & info)1439 ErrCode WifiDeviceProxy::GetIpInfo(IpInfo &info)
1440 {
1441     if (mRemoteDied) {
1442         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1443         return WIFI_OPT_FAILED;
1444     }
1445     MessageOption option;
1446     MessageParcel data, reply;
1447     if (!data.WriteInterfaceToken(GetDescriptor())) {
1448         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1449         return WIFI_OPT_FAILED;
1450     }
1451     data.WriteInt32(0);
1452     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_INFO), data, reply,
1453         option);
1454     if (error != ERR_NONE) {
1455         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1456             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_INFO), error);
1457         return WIFI_OPT_FAILED;
1458     }
1459     int exception = reply.ReadInt32();
1460     if (exception) {
1461         return WIFI_OPT_FAILED;
1462     }
1463     int ret = reply.ReadInt32();
1464     if (ret != WIFI_OPT_SUCCESS) {
1465         return ErrCode(ret);
1466     }
1467 
1468     info.ipAddress = static_cast<uint32_t>(reply.ReadInt32());
1469     info.gateway = static_cast<uint32_t>(reply.ReadInt32());
1470     info.netmask = static_cast<uint32_t>(reply.ReadInt32());
1471     info.primaryDns = static_cast<uint32_t>(reply.ReadInt32());
1472     info.secondDns = static_cast<uint32_t>(reply.ReadInt32());
1473     info.serverIp = static_cast<uint32_t>(reply.ReadInt32());
1474     info.leaseDuration = static_cast<uint32_t>(reply.ReadInt32());
1475     return WIFI_OPT_SUCCESS;
1476 }
1477 
GetIpv6Info(IpV6Info & info)1478 ErrCode WifiDeviceProxy::GetIpv6Info(IpV6Info &info)
1479 {
1480     if (mRemoteDied) {
1481         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1482         return WIFI_OPT_FAILED;
1483     }
1484     MessageOption option;
1485     MessageParcel data, reply;
1486     if (!data.WriteInterfaceToken(GetDescriptor())) {
1487         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1488         return WIFI_OPT_FAILED;
1489     }
1490     data.WriteInt32(0);
1491     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_IPV6INFO),
1492         data, reply, option);
1493     if (error != ERR_NONE) {
1494         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1495             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_IPV6INFO), error);
1496         return WIFI_OPT_FAILED;
1497     }
1498     int exception = reply.ReadInt32();
1499     if (exception) {
1500         return WIFI_OPT_FAILED;
1501     }
1502     int ret = reply.ReadInt32();
1503     if (ret != WIFI_OPT_SUCCESS) {
1504         return ErrCode(ret);
1505     }
1506     info.linkIpV6Address = reply.ReadString();
1507     info.globalIpV6Address = reply.ReadString();
1508     info.randGlobalIpV6Address = reply.ReadString();
1509     info.uniqueLocalAddress1 = reply.ReadString();
1510     info.uniqueLocalAddress2 = reply.ReadString();
1511     info.gateway = reply.ReadString();
1512     info.netmask = reply.ReadString();
1513     info.primaryDns = reply.ReadString();
1514     info.secondDns = reply.ReadString();
1515     return WIFI_OPT_SUCCESS;
1516 }
1517 
SetCountryCode(const std::string & countryCode)1518 ErrCode WifiDeviceProxy::SetCountryCode(const 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     data.WriteString(countryCode);
1532     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_COUNTRY_CODE), data,
1533         reply, option);
1534     if (error != ERR_NONE) {
1535         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1536             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_COUNTRY_CODE), error);
1537         return WIFI_OPT_FAILED;
1538     }
1539     int exception = reply.ReadInt32();
1540     if (exception) {
1541         return WIFI_OPT_FAILED;
1542     }
1543     return ErrCode(reply.ReadInt32());
1544 }
1545 
GetCountryCode(std::string & countryCode)1546 ErrCode WifiDeviceProxy::GetCountryCode(std::string &countryCode)
1547 {
1548     if (mRemoteDied) {
1549         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1550         return WIFI_OPT_FAILED;
1551     }
1552     MessageOption option;
1553     MessageParcel data, reply;
1554     if (!data.WriteInterfaceToken(GetDescriptor())) {
1555         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1556         return WIFI_OPT_FAILED;
1557     }
1558     data.WriteInt32(0);
1559     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_COUNTRY_CODE), data,
1560         reply, option);
1561     if (error != ERR_NONE) {
1562         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1563             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_COUNTRY_CODE), error);
1564         return WIFI_OPT_FAILED;
1565     }
1566     int exception = reply.ReadInt32();
1567     if (exception) {
1568         return WIFI_OPT_FAILED;
1569     }
1570     int ret = reply.ReadInt32();
1571     if (ret != WIFI_OPT_SUCCESS) {
1572         return ErrCode(ret);
1573     }
1574     countryCode = reply.ReadString();
1575     return WIFI_OPT_SUCCESS;
1576 }
1577 
RegisterCallBack(const sptr<IWifiDeviceCallBack> & callback,const std::vector<std::string> & event)1578 ErrCode WifiDeviceProxy::RegisterCallBack(const sptr<IWifiDeviceCallBack> &callback,
1579     const std::vector<std::string> &event)
1580 {
1581     if (mRemoteDied) {
1582         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1583         return WIFI_OPT_FAILED;
1584     }
1585     MessageParcel data, reply;
1586     MessageOption option(MessageOption::TF_ASYNC);
1587 
1588     if (!data.WriteInterfaceToken(GetDescriptor())) {
1589         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1590         return WIFI_OPT_FAILED;
1591     }
1592     data.WriteInt32(0);
1593 
1594     if (g_deviceCallBackStub == nullptr) {
1595         WIFI_LOGE("g_deviceCallBackStub is nullptr");
1596         return WIFI_OPT_FAILED;
1597     }
1598     g_deviceCallBackStub->RegisterUserCallBack(callback);
1599 
1600     if (!data.WriteRemoteObject(g_deviceCallBackStub->AsObject())) {
1601         WIFI_LOGE("WifiDeviceProxy::RegisterCallBack WriteRemoteObject failed!");
1602         return WIFI_OPT_FAILED;
1603     }
1604 
1605     int pid = GetCallingPid();
1606     data.WriteInt32(pid);
1607     int tokenId = GetCallingTokenId();
1608     data.WriteInt32(tokenId);
1609     int eventNum = static_cast<int>(event.size());
1610     data.WriteInt32(eventNum);
1611     if (eventNum > 0) {
1612         for (auto &eventName : event) {
1613             data.WriteString(eventName);
1614         }
1615     }
1616     WIFI_LOGD("%{public}s, calling uid: %{public}d, pid: %{public}d, tokenId: %{private}d",
1617         __func__, GetCallingUid(), pid, tokenId);
1618     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_REGISTER_CALLBACK_CLIENT),
1619         data, reply, option);
1620     if (error != ERR_NONE) {
1621         WIFI_LOGE("Set Attr(%{public}d) failed, code is %{public}d",
1622             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REGISTER_CALLBACK_CLIENT), error);
1623         return WIFI_OPT_FAILED;
1624     }
1625     int exception = reply.ReadInt32();
1626     if (exception) {
1627         return WIFI_OPT_FAILED;
1628     }
1629     return ErrCode(reply.ReadInt32());
1630 }
1631 
GetSignalLevel(const int & rssi,const int & band,int & level)1632 ErrCode WifiDeviceProxy::GetSignalLevel(const int &rssi, const int &band, int &level)
1633 {
1634     if (mRemoteDied) {
1635         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1636         return WIFI_OPT_FAILED;
1637     }
1638     MessageOption option;
1639     MessageParcel data, reply;
1640     if (!data.WriteInterfaceToken(GetDescriptor())) {
1641         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1642         return WIFI_OPT_FAILED;
1643     }
1644     data.WriteInt32(0);
1645     data.WriteInt32(rssi);
1646     data.WriteInt32(band);
1647     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SIGNAL_LEVEL), data,
1648         reply, option);
1649     if (error != ERR_NONE) {
1650         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1651             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SIGNAL_LEVEL), error);
1652         return WIFI_OPT_FAILED;
1653     }
1654     int exception = reply.ReadInt32();
1655     if (exception) {
1656         return WIFI_OPT_FAILED;
1657     }
1658     int ret = reply.ReadInt32();
1659     if (ret != WIFI_OPT_SUCCESS) {
1660         return ErrCode(ret);
1661     }
1662 
1663     level = reply.ReadInt32();
1664     return WIFI_OPT_SUCCESS;
1665 }
1666 
GetSupportedFeatures(long & features)1667 ErrCode WifiDeviceProxy::GetSupportedFeatures(long &features)
1668 {
1669     if (mRemoteDied) {
1670         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1671         return WIFI_OPT_FAILED;
1672     }
1673     MessageOption option;
1674     MessageParcel data, reply;
1675     if (!data.WriteInterfaceToken(GetDescriptor())) {
1676         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1677         return WIFI_OPT_FAILED;
1678     }
1679     data.WriteInt32(0);
1680     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES),
1681         data, reply, option);
1682     if (error != ERR_NONE) {
1683         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1684             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES), error);
1685         return WIFI_OPT_FAILED;
1686     }
1687     int exception = reply.ReadInt32();
1688     if (exception) {
1689         return WIFI_OPT_FAILED;
1690     }
1691     int ret = reply.ReadInt32();
1692     if (ret != WIFI_OPT_SUCCESS) {
1693         return ErrCode(ret);
1694     }
1695 
1696     features = reply.ReadInt64();
1697     return WIFI_OPT_SUCCESS;
1698 }
1699 
IsFeatureSupported(long feature,bool & isSupported)1700 ErrCode WifiDeviceProxy::IsFeatureSupported(long feature, bool &isSupported)
1701 {
1702     if (mRemoteDied) {
1703         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1704         return WIFI_OPT_FAILED;
1705     }
1706     MessageOption option;
1707     MessageParcel data;
1708     MessageParcel reply;
1709     if (!data.WriteInterfaceToken(GetDescriptor())) {
1710         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1711         return WIFI_OPT_FAILED;
1712     }
1713     data.WriteInt32(0);
1714     data.WriteInt64(feature);
1715     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_FEATURE_SUPPORTED),
1716         data, reply, option);
1717     if (error != ERR_NONE) {
1718         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1719             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_FEATURE_SUPPORTED), error);
1720         return WIFI_OPT_FAILED;
1721     }
1722     int exception = reply.ReadInt32();
1723     if (exception) {
1724         return WIFI_OPT_FAILED;
1725     }
1726     int ret = reply.ReadInt32();
1727     if (ret != WIFI_OPT_SUCCESS) {
1728         return ErrCode(ret);
1729     }
1730 
1731     isSupported = reply.ReadInt32();
1732     return WIFI_OPT_SUCCESS;
1733 }
1734 
GetDeviceMacAddress(std::string & result)1735 ErrCode WifiDeviceProxy::GetDeviceMacAddress(std::string &result)
1736 {
1737     if (mRemoteDied) {
1738         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1739         return WIFI_OPT_FAILED;
1740     }
1741     const char *readStr = nullptr;
1742     MessageOption option;
1743     MessageParcel data;
1744     MessageParcel reply;
1745     if (!data.WriteInterfaceToken(GetDescriptor())) {
1746         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1747         return WIFI_OPT_FAILED;
1748     }
1749     data.WriteInt32(0);
1750     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DERVICE_MAC_ADD),
1751         data, reply, option);
1752     if (error != ERR_NONE) {
1753         WIFI_LOGE("Set Attr(%{public}d) failed",
1754             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DERVICE_MAC_ADD));
1755         return WIFI_OPT_FAILED;
1756     }
1757 
1758     int exception = reply.ReadInt32();
1759     if (exception) {
1760         return WIFI_OPT_FAILED;
1761     }
1762     int ret = reply.ReadInt32();
1763     if (ErrCode(ret) != WIFI_OPT_SUCCESS) {
1764         return ErrCode(ret);
1765     }
1766     readStr = reply.ReadCString();
1767     result = (readStr != nullptr) ? readStr : "";
1768     return WIFI_OPT_SUCCESS;
1769 }
1770 
SetLowLatencyMode(bool enabled)1771 bool WifiDeviceProxy::SetLowLatencyMode(bool enabled)
1772 {
1773     if (mRemoteDied) {
1774         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1775         return WIFI_OPT_FAILED;
1776     }
1777     MessageOption option;
1778     MessageParcel data;
1779     MessageParcel reply;
1780     if (!data.WriteInterfaceToken(GetDescriptor())) {
1781         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1782         return WIFI_OPT_FAILED;
1783     }
1784     data.WriteInt32(0);
1785     data.WriteBool(enabled);
1786     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_LATENCY_MODE), data,
1787         reply, option);
1788     if (error != ERR_NONE) {
1789         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1790             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_LATENCY_MODE), error);
1791         return WIFI_OPT_FAILED;
1792     }
1793     int exception = reply.ReadInt32();
1794     if (exception) {
1795         return WIFI_OPT_FAILED;
1796     }
1797     return reply.ReadBool();
1798 }
1799 
OnRemoteDied(const wptr<IRemoteObject> & remoteObject)1800 void WifiDeviceProxy::OnRemoteDied(const wptr<IRemoteObject> &remoteObject)
1801 {
1802     WIFI_LOGW("Remote service is died! remoteObject: %{private}p", &remoteObject);
1803     mRemoteDied = true;
1804     RemoveDeathRecipient();
1805     if (g_deviceCallBackStub == nullptr) {
1806         WIFI_LOGE("g_deviceCallBackStub is nullptr");
1807         return;
1808     }
1809     if (g_deviceCallBackStub != nullptr) {
1810         g_deviceCallBackStub->SetRemoteDied(true);
1811     }
1812 }
1813 
IsRemoteDied(void)1814 bool WifiDeviceProxy::IsRemoteDied(void)
1815 {
1816     if (mRemoteDied) {
1817         WIFI_LOGW("IsRemoteDied! remote is died now!");
1818     }
1819     return mRemoteDied;
1820 }
1821 
IsBandTypeSupported(int bandType,bool & supported)1822 ErrCode WifiDeviceProxy::IsBandTypeSupported(int bandType, bool &supported)
1823 {
1824     if (mRemoteDied) {
1825         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1826         return WIFI_OPT_FAILED;
1827     }
1828     MessageOption option;
1829     MessageParcel data, reply;
1830     if (!data.WriteInterfaceToken(GetDescriptor())) {
1831         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1832         return WIFI_OPT_FAILED;
1833     }
1834     data.WriteInt32(0);
1835     data.WriteInt32(bandType);
1836     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_BANDTYPE_SUPPORTED),
1837         data, reply, option);
1838     if (error != ERR_NONE) {
1839         WIFI_LOGE("IsBandTypeSupported (%{public}d) failed,error code is %{public}d",
1840             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_BANDTYPE_SUPPORTED), error);
1841         return WIFI_OPT_FAILED;
1842     }
1843 
1844     int exception = reply.ReadInt32();
1845     if (exception) {
1846         return WIFI_OPT_FAILED;
1847     }
1848     int ret = reply.ReadInt32();
1849     if (ret != WIFI_OPT_SUCCESS) {
1850         return ErrCode(ret);
1851     }
1852     supported = reply.ReadInt32();
1853     return WIFI_OPT_SUCCESS;
1854 }
1855 
Get5GHzChannelList(std::vector<int> & result)1856 ErrCode WifiDeviceProxy::Get5GHzChannelList(std::vector<int> &result)
1857 {
1858     if (mRemoteDied) {
1859         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1860         return WIFI_OPT_FAILED;
1861     }
1862     constexpr int MAX_CHANNEL_SIZE = 36;
1863     MessageOption option;
1864     MessageParcel data, reply;
1865     if (!data.WriteInterfaceToken(GetDescriptor())) {
1866         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1867         return WIFI_OPT_FAILED;
1868     }
1869     data.WriteInt32(0);
1870     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_5G_CHANNELLIST), data,
1871         reply, option);
1872     if (error != ERR_NONE) {
1873         WIFI_LOGE("Get5GHzChannelList(%{public}d) failed,error code is %{public}d",
1874             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_5G_CHANNELLIST), error);
1875         return WIFI_OPT_FAILED;
1876     }
1877 
1878     int exception = reply.ReadInt32();
1879     if (exception) {
1880         return WIFI_OPT_FAILED;
1881     }
1882     int ret = reply.ReadInt32();
1883     if (ret != WIFI_OPT_SUCCESS) {
1884         return ErrCode(ret);
1885     }
1886     int retSize = reply.ReadInt32();
1887     if (retSize > MAX_CHANNEL_SIZE) {
1888         WIFI_LOGE("Get5GHzChannelList fail, size error: %{public}d", retSize);
1889         return WIFI_OPT_FAILED;
1890     }
1891     for (int i = 0; i < retSize; ++i) {
1892         result.emplace_back(reply.ReadInt32());
1893     }
1894     return WIFI_OPT_SUCCESS;
1895 }
1896 
SetAppFrozen(std::set<int> pidList,bool isFrozen)1897 ErrCode WifiDeviceProxy::SetAppFrozen(std::set<int> pidList, bool isFrozen)
1898 {
1899     if (mRemoteDied) {
1900         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1901         return WIFI_OPT_FAILED;
1902     }
1903     MessageOption option;
1904     MessageParcel data, reply;
1905     if (!data.WriteInterfaceToken(GetDescriptor())) {
1906         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1907         return WIFI_OPT_FAILED;
1908     }
1909     data.WriteInt32(0);
1910     int size = static_cast<int>(pidList.size() < MAX_PID_LIST_SIZE ? pidList.size() : MAX_PID_LIST_SIZE);
1911     int count = 0;
1912     data.WriteInt32(size);
1913     for (std::set<int>::iterator it = pidList.begin(); it != pidList.end() && count < size; it++, count++) {
1914         data.WriteInt32(*it);
1915     }
1916     data.WriteBool(isFrozen);
1917     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_FROZEN_APP), data,
1918         reply, option);
1919     if (error != ERR_NONE) {
1920         WIFI_LOGE("SetAppFrozen(%{public}d) failed,error code is %{public}d",
1921             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_FROZEN_APP), error);
1922         return WIFI_OPT_FAILED;
1923     }
1924     int exception = reply.ReadInt32();
1925     if (exception) {
1926         return WIFI_OPT_FAILED;
1927     }
1928     return WIFI_OPT_SUCCESS;
1929 }
1930 
ResetAllFrozenApp()1931 ErrCode WifiDeviceProxy::ResetAllFrozenApp()
1932 {
1933     if (mRemoteDied) {
1934         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1935         return WIFI_OPT_FAILED;
1936     }
1937     MessageOption option;
1938     MessageParcel data, reply;
1939     if (!data.WriteInterfaceToken(GetDescriptor())) {
1940         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1941         return WIFI_OPT_FAILED;
1942     }
1943     data.WriteInt32(0);
1944     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_RESET_ALL_FROZEN_APP), data,
1945         reply, option);
1946     if (error != ERR_NONE) {
1947         WIFI_LOGE("Get5GHzChannelList(%{public}d) failed,error code is %{public}d",
1948             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_RESET_ALL_FROZEN_APP), error);
1949         return WIFI_OPT_FAILED;
1950     }
1951     int exception = reply.ReadInt32();
1952     if (exception) {
1953         return WIFI_OPT_FAILED;
1954     }
1955     return WIFI_OPT_SUCCESS;
1956 }
1957 
DisableAutoJoin(const std::string & conditionName)1958 ErrCode WifiDeviceProxy::DisableAutoJoin(const std::string &conditionName)
1959 {
1960     if (mRemoteDied) {
1961         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1962         return WIFI_OPT_FAILED;
1963     }
1964     MessageOption option;
1965     MessageParcel data, reply;
1966     if (!data.WriteInterfaceToken(GetDescriptor())) {
1967         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1968         return WIFI_OPT_FAILED;
1969     }
1970     data.WriteInt32(0);
1971     data.WriteString(conditionName);
1972     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_AUTO_JOIN), data,
1973                                       reply, option);
1974     if (error != ERR_NONE) {
1975         WIFI_LOGE("DisableAutoJoin (%{public}d) failed,error code is %{public}d",
1976                   static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_AUTO_JOIN), error);
1977         return WIFI_OPT_FAILED;
1978     }
1979     int exception = reply.ReadInt32();
1980     if (exception) {
1981         return WIFI_OPT_FAILED;
1982     }
1983     return WIFI_OPT_SUCCESS;
1984 }
1985 
EnableAutoJoin(const std::string & conditionName)1986 ErrCode WifiDeviceProxy::EnableAutoJoin(const std::string &conditionName)
1987 {
1988     if (mRemoteDied) {
1989         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
1990         return WIFI_OPT_FAILED;
1991     }
1992     MessageOption option;
1993     MessageParcel data, reply;
1994     if (!data.WriteInterfaceToken(GetDescriptor())) {
1995         WIFI_LOGE("Write interface token error: %{public}s", __func__);
1996         return WIFI_OPT_FAILED;
1997     }
1998     data.WriteInt32(0);
1999     data.WriteString(conditionName);
2000     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_AUTO_JOIN), data,
2001                                       reply, option);
2002     if (error != ERR_NONE) {
2003         WIFI_LOGE("EnableAutoJoin(%{public}d) failed,error code is %{public}d",
2004                   static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_AUTO_JOIN), error);
2005         return WIFI_OPT_FAILED;
2006     }
2007     int exception = reply.ReadInt32();
2008     if (exception) {
2009         return WIFI_OPT_FAILED;
2010     }
2011     return WIFI_OPT_SUCCESS;
2012 }
2013 
RegisterAutoJoinCondition(const std::string & conditionName,const std::function<bool ()> & autoJoinCondition)2014 ErrCode WifiDeviceProxy::RegisterAutoJoinCondition(const std::string &conditionName,
2015                                                    const std::function<bool()> &autoJoinCondition)
2016 {
2017     return WIFI_OPT_FAILED;
2018 }
2019 
DeregisterAutoJoinCondition(const std::string & conditionName)2020 ErrCode WifiDeviceProxy::DeregisterAutoJoinCondition(const std::string &conditionName)
2021 {
2022     return WIFI_OPT_FAILED;
2023 }
2024 
RegisterFilterBuilder(const FilterTag & filterTag,const std::string & filterName,const FilterBuilder & filterBuilder)2025 ErrCode WifiDeviceProxy::RegisterFilterBuilder(const FilterTag &filterTag,
2026                                                const std::string &filterName,
2027                                                const FilterBuilder &filterBuilder)
2028 {
2029     return WIFI_OPT_FAILED;
2030 }
2031 
DeregisterFilterBuilder(const FilterTag & filterTag,const std::string & filterName)2032 ErrCode WifiDeviceProxy::DeregisterFilterBuilder(const FilterTag &filterTag, const std::string &filterName)
2033 {
2034     return WIFI_OPT_FAILED;
2035 }
2036 
RegisterCommonBuilder(const TagType & tagType,const std::string & tagName,const CommonBuilder & commonBuilder)2037 ErrCode WifiDeviceProxy::RegisterCommonBuilder(const TagType &tagType, const std::string &tagName,
2038                                                const CommonBuilder &commonBuilder)
2039 {
2040     return WIFI_OPT_FAILED;
2041 }
2042 
DeregisterCommonBuilder(const TagType & tagType,const std::string & tagName)2043 ErrCode WifiDeviceProxy::DeregisterCommonBuilder(const TagType &tagType, const std::string &tagName)
2044 {
2045     return WIFI_OPT_FAILED;
2046 }
2047 
StartPortalCertification()2048 ErrCode WifiDeviceProxy::StartPortalCertification()
2049 {
2050     if (mRemoteDied) {
2051         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2052         return WIFI_OPT_FAILED;
2053     }
2054     MessageOption option;
2055     MessageParcel data, reply;
2056     if (!data.WriteInterfaceToken(GetDescriptor())) {
2057         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2058         return WIFI_OPT_FAILED;
2059     }
2060     data.WriteInt32(0);
2061     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_PORTAL_CERTIF), data,
2062         reply, option);
2063     if (error != ERR_NONE) {
2064         WIFI_LOGE("StartPortalCertification(%{public}d) failed,error code is %{public}d",
2065             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_PORTAL_CERTIF), error);
2066         return WIFI_OPT_FAILED;
2067     }
2068 
2069     int exception = reply.ReadInt32();
2070     if (exception) {
2071         return WIFI_OPT_FAILED;
2072     }
2073     int ret = reply.ReadInt32();
2074     if (ret != WIFI_OPT_SUCCESS) {
2075         return ErrCode(ret);
2076     }
2077 
2078     return WIFI_OPT_SUCCESS;
2079 }
2080 
GetChangeDeviceConfig(ConfigChange & value,WifiDeviceConfig & config)2081 ErrCode WifiDeviceProxy::GetChangeDeviceConfig(ConfigChange &value, WifiDeviceConfig &config)
2082 {
2083     if (mRemoteDied) {
2084         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2085         return WIFI_OPT_FAILED;
2086     }
2087     MessageOption option;
2088     MessageParcel data, reply;
2089     if (!data.WriteInterfaceToken(GetDescriptor())) {
2090         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2091         return WIFI_OPT_FAILED;
2092     }
2093     data.WriteInt32(0);
2094     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIG_CHANGE),
2095         data, reply, option);
2096     if (error != ERR_NONE) {
2097         WIFI_LOGE("GetChangeDeviceConfig (%{public}d) failed,error code is %{public}d",
2098             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIG_CHANGE), error);
2099         return WIFI_OPT_FAILED;
2100     }
2101 
2102     int exception = reply.ReadInt32();
2103     if (exception) {
2104         return WIFI_OPT_FAILED;
2105     }
2106     value = (ConfigChange)reply.ReadInt32();
2107     config.networkId = reply.ReadInt32();
2108     config.ssid = reply.ReadString();
2109     config.bssid = reply.ReadString();
2110     config.callProcessName = reply.ReadString();
2111     config.ancoCallProcessName = reply.ReadString();
2112     config.keyMgmt = reply.ReadString();
2113     int ret = reply.ReadInt32();
2114     if (ret != WIFI_OPT_SUCCESS) {
2115         return ErrCode(ret);
2116     }
2117     return WIFI_OPT_SUCCESS;
2118 }
2119 
FactoryReset()2120 ErrCode WifiDeviceProxy::FactoryReset()
2121 {
2122     if (mRemoteDied) {
2123         WIFI_LOGE("failed to `%{public}s`, remote service is died.", __func__);
2124         return WIFI_OPT_FAILED;
2125     }
2126     MessageParcel data, reply;
2127     MessageOption option;
2128     if (!data.WriteInterfaceToken(GetDescriptor())) {
2129         WIFI_LOGE("Write interface token error, func:%{public}s", __func__);
2130         return WIFI_OPT_FAILED;
2131     }
2132 
2133     data.WriteInt32(0);
2134     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_SET_FACTORY_RESET), data,
2135         reply, option);
2136     if (error != ERR_NONE) {
2137         WIFI_LOGE("FactoryReset(%{public}d) failed, error code is %{public}d",
2138             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_SET_FACTORY_RESET), error);
2139         return WIFI_OPT_FAILED;
2140     }
2141 
2142     int exception = reply.ReadInt32();
2143     if (exception) {
2144         WIFI_LOGE("Reply Read failed, exception:%{public}d", exception);
2145         return WIFI_OPT_FAILED;
2146     }
2147     int ret = reply.ReadInt32();
2148     if (ret != WIFI_OPT_SUCCESS) {
2149         WIFI_LOGE("Reply Read failed, ret:%{public}d", ret);
2150         return ErrCode(ret);
2151     }
2152     return WIFI_OPT_SUCCESS;
2153 }
2154 
ReceiveNetworkControlInfo(const WifiNetworkControlInfo & networkControlInfo)2155 ErrCode WifiDeviceProxy::ReceiveNetworkControlInfo(const WifiNetworkControlInfo& networkControlInfo)
2156 {
2157     if (mRemoteDied) {
2158         WIFI_LOGE("failed to %{public}s,remote service is died!", __func__);
2159         return WIFI_OPT_FAILED;
2160     }
2161     MessageOption option;
2162     MessageParcel data;
2163     MessageParcel reply;
2164     if (!data.WriteInterfaceToken(GetDescriptor())) {
2165         WIFI_LOGE("Write interface token has error: %{public}s", __func__);
2166         return WIFI_OPT_FAILED;
2167     }
2168 
2169     data.WriteInt32(0);
2170     data.WriteInt32(networkControlInfo.uid);
2171     data.WriteInt32(networkControlInfo.pid);
2172     data.WriteString(networkControlInfo.bundleName);
2173     data.WriteInt32(networkControlInfo.state);
2174     data.WriteInt32(networkControlInfo.sceneId);
2175     data.WriteInt32(networkControlInfo.rtt);
2176     int error = Remote()->SendRequest(
2177         static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_NET_CONTROL_INFO), data, reply, option);
2178     if (error != ERR_NONE) {
2179         WIFI_LOGE("ReceiveNetworkControlInfo(%{public}d) failed, error code is %{public}d",
2180             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_NET_CONTROL_INFO), error);
2181         return WIFI_OPT_FAILED;
2182     }
2183 
2184     int exception = reply.ReadInt32();
2185     if (exception) {
2186         WIFI_LOGE("ReceiveNetworkControlInfo Reply Read failed, exception:%{public}d", exception);
2187         return WIFI_OPT_FAILED;
2188     }
2189     int ret = reply.ReadInt32();
2190     if (ret != WIFI_OPT_SUCCESS) {
2191         WIFI_LOGE("ReceiveNetworkControlInfo Reply Read failed, ret:%{public}d", ret);
2192         return ErrCode(ret);
2193     }
2194     return WIFI_OPT_SUCCESS;
2195 }
2196 
LimitSpeed(const int controlId,const int limitMode)2197 ErrCode WifiDeviceProxy::LimitSpeed(const int controlId, const int limitMode)
2198 {
2199     if (mRemoteDied) {
2200         WIFI_LOGE("failed to %{public}s,remote service is died!", __func__);
2201         return WIFI_OPT_FAILED;
2202     }
2203     MessageOption option;
2204     MessageParcel data;
2205     MessageParcel reply;
2206     if (!data.WriteInterfaceToken(GetDescriptor())) {
2207         WIFI_LOGE("Write interface token has error: %{public}s", __func__);
2208         return WIFI_OPT_FAILED;
2209     }
2210     data.WriteInt32(0);
2211     data.WriteInt32(controlId);
2212     data.WriteInt32(limitMode);
2213     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_LIMIT_SPEED), data,
2214         reply, option);
2215     if (error != ERR_NONE) {
2216         WIFI_LOGE("LimitSpeed(%{public}d) failed, error code is %{public}d",
2217             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_LIMIT_SPEED), error);
2218         return WIFI_OPT_FAILED;
2219     }
2220     int exception = reply.ReadInt32();
2221     if (exception) {
2222         WIFI_LOGE("LimitSpeed Reply Read failed, exception:%{public}d", exception);
2223         return WIFI_OPT_FAILED;
2224     }
2225     int ret = reply.ReadInt32();
2226     if (ret != WIFI_OPT_SUCCESS) {
2227         WIFI_LOGE("LimitSpeed Reply Read failed, ret:%{public}d", ret);
2228         return ErrCode(ret);
2229     }
2230     return WIFI_OPT_SUCCESS;
2231 }
2232 
SetLowTxPower(const WifiLowPowerParam wifiLowPowerParam)2233 ErrCode WifiDeviceProxy::SetLowTxPower(const WifiLowPowerParam wifiLowPowerParam)
2234 {
2235     if (mRemoteDied) {
2236         WIFI_LOGE("failed to %{public}s,remote service is died!", __func__);
2237         return WIFI_OPT_FAILED;
2238     }
2239     MessageOption option;
2240     MessageParcel data;
2241     MessageParcel reply;
2242     if (!data.WriteInterfaceToken(GetDescriptor())) {
2243         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2244         return WIFI_OPT_FAILED;
2245     }
2246     data.WriteInt32(0);
2247     data.WriteString(wifiLowPowerParam.ifName);
2248     data.WriteInt32(wifiLowPowerParam.scene);
2249     data.WriteInt32(wifiLowPowerParam.rssiThreshold);
2250     data.WriteString(wifiLowPowerParam.peerMacaddr);
2251     data.WriteString(wifiLowPowerParam.powerParam);
2252     data.WriteInt32(wifiLowPowerParam.powerParamLen);
2253     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_TX_POWER), data,
2254         reply, option);
2255     if (error != ERR_NONE) {
2256         WIFI_LOGE("SetLowTxPower(%{public}d) failed, error code is %{public}d",
2257             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_TX_POWER), error);
2258         return WIFI_OPT_FAILED;
2259     }
2260     int exception = reply.ReadInt32();
2261     if (exception) {
2262         WIFI_LOGE("SetLowTxPower Reply Read failed, exception:%{public}d", exception);
2263         return WIFI_OPT_FAILED;
2264     }
2265     int ret = reply.ReadInt32();
2266     if (ret != WIFI_OPT_SUCCESS) {
2267         WIFI_LOGE("SetLowTxPower Reply Read failed, ret:%{public}d", ret);
2268         return ErrCode(ret);
2269     }
2270     return WIFI_OPT_SUCCESS;
2271 }
2272 
EnableHiLinkHandshake(bool uiFlag,std::string & bssid,WifiDeviceConfig & deviceConfig)2273 ErrCode WifiDeviceProxy::EnableHiLinkHandshake(bool uiFlag, std::string &bssid, WifiDeviceConfig &deviceConfig)
2274 {
2275     if (mRemoteDied) {
2276         WIFI_LOGE("failed to `%{public}s`, remote service is died.", __func__);
2277         return WIFI_OPT_FAILED;
2278     }
2279     MessageParcel data, reply;
2280     MessageOption option;
2281     if (!data.WriteInterfaceToken(GetDescriptor())) {
2282         WIFI_LOGE("Write interface token error, func:%{public}s", __func__);
2283         return WIFI_OPT_FAILED;
2284     }
2285 
2286     data.WriteInt32(0);
2287     data.WriteBool(uiFlag);
2288     data.WriteString(bssid);
2289     WriteDeviceConfig(deviceConfig, data);
2290 
2291     //Wirte device config
2292     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_HILINK_CONNECT), data,
2293         reply, option);
2294     if (error != ERR_NONE) {
2295         WIFI_LOGE("EnableHiLinkHandshake(%{public}d) failed, error code is %{public}d",
2296             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_HILINK_CONNECT), error);
2297         return WIFI_OPT_FAILED;
2298     }
2299 
2300     int exception = reply.ReadInt32();
2301     if (exception) {
2302         WIFI_LOGE("Reply Read failed, exception:%{public}d", exception);
2303         return WIFI_OPT_FAILED;
2304     }
2305     int ret = reply.ReadInt32();
2306     if (ret != WIFI_OPT_SUCCESS) {
2307         WIFI_LOGE("Reply Read failed, ret:%{public}d", ret);
2308         return ErrCode(ret);
2309     }
2310     return WIFI_OPT_SUCCESS;
2311 }
2312 
SetSatelliteState(const int state)2313 ErrCode WifiDeviceProxy::SetSatelliteState(const int state)
2314 {
2315     if (mRemoteDied) {
2316         WIFI_LOGE("failed to %{public}s,remote service is died!", __func__);
2317         return WIFI_OPT_FAILED;
2318     }
2319     MessageOption option;
2320     MessageParcel data;
2321     MessageParcel reply;
2322     if (!data.WriteInterfaceToken(GetDescriptor())) {
2323         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2324         return WIFI_OPT_FAILED;
2325     }
2326     data.WriteInt32(0);
2327     data.WriteInt32(state);
2328     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_SATELLITE_STATE), data,
2329         reply, option);
2330     if (error != ERR_NONE) {
2331         WIFI_LOGE("SetSatelliteState(%{public}d) failed, error code is %{public}d",
2332             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_SATELLITE_STATE), error);
2333         return WIFI_OPT_FAILED;
2334     }
2335     int exception = reply.ReadInt32();
2336     if (exception) {
2337         WIFI_LOGE("SetSatelliteState Reply Read failed, exception:%{public}d", exception);
2338         return WIFI_OPT_FAILED;
2339     }
2340     int ret = reply.ReadInt32();
2341     if (ret != WIFI_OPT_SUCCESS) {
2342         WIFI_LOGE("SetSatelliteState Reply Read failed, ret:%{public}d", ret);
2343         return ErrCode(ret);
2344     }
2345     return WIFI_OPT_SUCCESS;
2346 }
2347 
EnableSemiWifi()2348 ErrCode WifiDeviceProxy::EnableSemiWifi()
2349 {
2350     if (mRemoteDied) {
2351         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2352         return WIFI_OPT_FAILED;
2353     }
2354     MessageOption option;
2355     MessageParcel data;
2356     MessageParcel reply;
2357     if (!data.WriteInterfaceToken(GetDescriptor())) {
2358         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2359         return WIFI_OPT_FAILED;
2360     }
2361     data.WriteInt32(0);
2362     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_SEMI_WIFI), data,
2363         reply, option);
2364     if (error != ERR_NONE) {
2365         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2366             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_SEMI_WIFI), error);
2367         return WIFI_OPT_FAILED;
2368     }
2369     int exception = reply.ReadInt32();
2370     if (exception) {
2371         return WIFI_OPT_FAILED;
2372     }
2373     return ErrCode(reply.ReadInt32());
2374 }
2375 
GetWifiDetailState(WifiDetailState & state)2376 ErrCode WifiDeviceProxy::GetWifiDetailState(WifiDetailState &state)
2377 {
2378     if (mRemoteDied) {
2379         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2380         return WIFI_OPT_FAILED;
2381     }
2382     MessageOption option;
2383     MessageParcel data;
2384     MessageParcel reply;
2385     if (!data.WriteInterfaceToken(GetDescriptor())) {
2386         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2387         return WIFI_OPT_FAILED;
2388     }
2389     data.WriteInt32(0);
2390     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_DETAIL_STATE), data,
2391         reply, option);
2392     if (error != ERR_NONE) {
2393         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2394             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_DETAIL_STATE), error);
2395         return WIFI_OPT_FAILED;
2396     }
2397     int exception = reply.ReadInt32();
2398     if (exception) {
2399         return WIFI_OPT_FAILED;
2400     }
2401     int ret = reply.ReadInt32();
2402     if (ret != WIFI_OPT_SUCCESS) {
2403         return ErrCode(ret);
2404     }
2405 
2406     int tempState = reply.ReadInt32();
2407     if (tempState >= 0 && tempState <= static_cast<int>(WifiDetailState::STATE_SEMI_ACTIVE)) {
2408         state = static_cast<WifiDetailState>(tempState);
2409     } else {
2410         state = WifiDetailState::STATE_UNKNOWN;
2411     }
2412     return WIFI_OPT_SUCCESS;
2413 }
2414 
ReadDeviceConfig(MessageParcel & reply,WifiDeviceConfig & config)2415 void WifiDeviceProxy::ReadDeviceConfig(MessageParcel &reply, WifiDeviceConfig &config)
2416 {
2417     config.networkId = reply.ReadInt32();
2418     config.bssid = reply.ReadString();
2419     config.bssidType = reply.ReadInt32();
2420     config.ssid = reply.ReadString();
2421     config.band = reply.ReadInt32();
2422     config.channel = reply.ReadInt32();
2423     config.frequency = reply.ReadInt32();
2424     config.level = reply.ReadInt32();
2425     config.isPasspoint = reply.ReadBool();
2426     config.isEphemeral = reply.ReadBool();
2427     config.preSharedKey = reply.ReadString();
2428     config.keyMgmt = reply.ReadString();
2429     for (int j = 0; j < WEPKEYS_SIZE; j++) {
2430         config.wepKeys[j] = reply.ReadString();
2431     }
2432     config.wepTxKeyIndex = reply.ReadInt32();
2433     config.priority = reply.ReadInt32();
2434     config.hiddenSSID = reply.ReadBool();
2435     config.wifiIpConfig.assignMethod = AssignIpMethod(reply.ReadInt32());
2436     ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.ipAddress.address);
2437     config.wifiIpConfig.staticIpAddress.ipAddress.prefixLength = reply.ReadInt32();
2438     config.wifiIpConfig.staticIpAddress.ipAddress.flags = reply.ReadInt32();
2439     config.wifiIpConfig.staticIpAddress.ipAddress.scope = reply.ReadInt32();
2440     ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.gateway);
2441     ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.dnsServer1);
2442     ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.dnsServer2);
2443     config.wifiIpConfig.staticIpAddress.domains = reply.ReadString();
2444     ReadEapConfig(reply, config.wifiEapConfig);
2445     config.wifiProxyconfig.configureMethod = ConfigureProxyMethod(reply.ReadInt32());
2446     config.wifiProxyconfig.autoProxyConfig.pacWebAddress = reply.ReadString();
2447     config.wifiProxyconfig.manualProxyConfig.serverHostName = reply.ReadString();
2448     config.wifiProxyconfig.manualProxyConfig.serverPort = reply.ReadInt32();
2449     config.wifiProxyconfig.manualProxyConfig.exclusionObjectList = reply.ReadString();
2450     config.wifiPrivacySetting = WifiPrivacyConfig(reply.ReadInt32());
2451     config.uid = reply.ReadInt32();
2452     config.callProcessName = reply.ReadString();
2453     config.ancoCallProcessName = reply.ReadString();
2454     config.wifiWapiConfig.wapiPskType = reply.ReadInt32();
2455     config.networkSelectionStatus.status = WifiDeviceConfigStatus(reply.ReadInt32());
2456     config.networkSelectionStatus.networkSelectionDisableReason = DisabledReason(reply.ReadInt32());
2457     config.networkSelectionStatus.seenInLastQualifiedNetworkSelection = reply.ReadBool();
2458     config.isPortal = reply.ReadBool();
2459     config.noInternetAccess = reply.ReadBool();
2460     config.isAllowAutoConnect = reply.ReadBool();
2461 }
2462 
GetDeviceConfig(const int & networkId,WifiDeviceConfig & config)2463 ErrCode WifiDeviceProxy::GetDeviceConfig(const int &networkId, WifiDeviceConfig &config)
2464 {
2465     if (mRemoteDied) {
2466         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2467         return WIFI_OPT_FAILED;
2468     }
2469     MessageOption option;
2470     MessageParcel data;
2471     MessageParcel reply;
2472     if (!data.WriteInterfaceToken(GetDescriptor())) {
2473         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2474         return WIFI_OPT_FAILED;
2475     }
2476     data.WriteInt32(0);
2477     data.WriteInt32(networkId);
2478     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIG),
2479         data, reply, option);
2480     if (error != ERR_NONE) {
2481         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2482             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIG), error);
2483         return WIFI_OPT_FAILED;
2484     }
2485     int exception = reply.ReadInt32();
2486     if (exception) {
2487         return WIFI_OPT_FAILED;
2488     }
2489     int ret = reply.ReadInt32();
2490     if (ret != WIFI_OPT_SUCCESS) {
2491         return ErrCode(ret);
2492     }
2493 
2494     ReadDeviceConfig(reply, config);
2495     return WIFI_OPT_SUCCESS;
2496 }
2497 
SetDpiMarkRule(const std::string & ifaceName,int uid,int protocol,int enable)2498 ErrCode WifiDeviceProxy::SetDpiMarkRule(const std::string &ifaceName, int uid, int protocol, int enable)
2499 {
2500     if (mRemoteDied) {
2501         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2502         return WIFI_OPT_FAILED;
2503     }
2504     MessageOption option;
2505     MessageParcel data, reply;
2506     if (!data.WriteInterfaceToken(GetDescriptor())) {
2507         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2508         return WIFI_OPT_FAILED;
2509     }
2510     data.WriteInt32(0);
2511     data.WriteCString(ifaceName.c_str());
2512     data.WriteInt32(uid);
2513     data.WriteInt32(protocol);
2514     data.WriteInt32(enable);
2515     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_DPI_MARK_RULE), data,
2516         reply, option);
2517     if (error != ERR_NONE) {
2518         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2519             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_DPI_MARK_RULE), error);
2520         return ErrCode(error);
2521     }
2522     int exception = reply.ReadInt32();
2523     if (exception) {
2524         return WIFI_OPT_FAILED;
2525     }
2526     int ret = reply.ReadInt32();
2527     if (ret != WIFI_OPT_SUCCESS) {
2528         return ErrCode(ret);
2529     }
2530     return WIFI_OPT_SUCCESS;
2531 }
2532 
UpdateNetworkLagInfo(const NetworkLagType networkLagType,const NetworkLagInfo & networkLagInfo)2533 ErrCode WifiDeviceProxy::UpdateNetworkLagInfo(const NetworkLagType networkLagType, const NetworkLagInfo &networkLagInfo)
2534 {
2535     if (mRemoteDied) {
2536         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2537         return WIFI_OPT_FAILED;
2538     }
2539     MessageOption option;
2540     MessageParcel data;
2541     MessageParcel reply;
2542     if (!data.WriteInterfaceToken(GetDescriptor())) {
2543         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2544         return WIFI_OPT_FAILED;
2545     }
2546     data.WriteInt32(0);
2547     data.WriteInt32(static_cast<int32_t>(networkLagType));
2548     data.WriteInt32(static_cast<int32_t>(networkLagInfo.uid));
2549     int error = Remote()->SendRequest(
2550         static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_NETWORK_LAG_INFO), data, reply, option);
2551     if (error != ERR_NONE) {
2552         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2553             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_NETWORK_LAG_INFO),
2554             error);
2555         return WIFI_OPT_FAILED;
2556     }
2557     int exception = reply.ReadInt32();
2558     if (exception) {
2559         return WIFI_OPT_FAILED;
2560     }
2561     return ErrCode(reply.ReadInt32());
2562 }
2563 
ReadSignalInfoForVoWiFi(MessageParcel & reply,VoWifiSignalInfo & signalInfo)2564 void WifiDeviceProxy::ReadSignalInfoForVoWiFi(MessageParcel &reply, VoWifiSignalInfo &signalInfo)
2565 {
2566     signalInfo.rssi = reply.ReadInt32();
2567     signalInfo.noise = reply.ReadInt32();
2568     signalInfo.bler = reply.ReadInt32();
2569     signalInfo.deltaTxPacketCounter = reply.ReadInt32();
2570     signalInfo.accessType = reply.ReadInt32();
2571     signalInfo.reverse = reply.ReadInt32();
2572     signalInfo.txGood = reply.ReadInt64();
2573     signalInfo.txBad = reply.ReadInt64();
2574     signalInfo.macAddress = reply.ReadString();
2575 }
2576 
FetchWifiSignalInfoForVoWiFi(VoWifiSignalInfo & signalInfo)2577 ErrCode WifiDeviceProxy::FetchWifiSignalInfoForVoWiFi(VoWifiSignalInfo &signalInfo)
2578 {
2579     if (mRemoteDied) {
2580         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2581         return WIFI_OPT_FAILED;
2582     }
2583     MessageOption option;
2584     MessageParcel data, reply;
2585     if (!data.WriteInterfaceToken(GetDescriptor())) {
2586         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2587         return WIFI_OPT_FAILED;
2588     }
2589     data.WriteInt32(0);
2590     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_FETCH_SIGNALINFO_VOWIFI),
2591         data, reply, option);
2592     if (error != ERR_NONE) {
2593         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2594             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_FETCH_SIGNALINFO_VOWIFI), error);
2595         return ErrCode(error);
2596     }
2597     int exception = reply.ReadInt32();
2598     if (exception) {
2599         return WIFI_OPT_FAILED;
2600     }
2601     int ret = reply.ReadInt32();
2602     if (ret != WIFI_OPT_SUCCESS) {
2603         return ErrCode(ret);
2604     }
2605 
2606     ReadSignalInfoForVoWiFi(reply, signalInfo);
2607     return WIFI_OPT_SUCCESS;
2608 }
2609 
IsSupportVoWifiDetect(bool & isSupported)2610 ErrCode WifiDeviceProxy::IsSupportVoWifiDetect(bool &isSupported)
2611 {
2612     if (mRemoteDied) {
2613         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2614         return WIFI_OPT_FAILED;
2615     }
2616     MessageOption option;
2617     MessageParcel data, reply;
2618     if (!data.WriteInterfaceToken(GetDescriptor())) {
2619         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2620         return WIFI_OPT_FAILED;
2621     }
2622     data.WriteInt32(0);
2623     data.WriteInt32(isSupported);
2624     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_SUPPORT_VOWIFI_DETECT),
2625         data, reply, option);
2626     if (error != ERR_NONE) {
2627         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2628             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_SUPPORT_VOWIFI_DETECT), error);
2629         return ErrCode(error);
2630     }
2631     int exception = reply.ReadInt32();
2632     if (exception) {
2633         return WIFI_OPT_FAILED;
2634     }
2635     int ret = reply.ReadInt32();
2636     if (ret != WIFI_OPT_SUCCESS) {
2637         return ErrCode(ret);
2638     }
2639     isSupported = reply.ReadInt32();
2640     return WIFI_OPT_SUCCESS;
2641 }
2642 
SetVoWifiDetectMode(WifiDetectConfInfo info)2643 ErrCode WifiDeviceProxy::SetVoWifiDetectMode(WifiDetectConfInfo info)
2644 {
2645     if (mRemoteDied) {
2646         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2647         return WIFI_OPT_FAILED;
2648     }
2649     MessageOption option;
2650     MessageParcel data, reply;
2651     if (!data.WriteInterfaceToken(GetDescriptor())) {
2652         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2653         return WIFI_OPT_FAILED;
2654     }
2655     data.WriteInt32(0);
2656     data.WriteInt32(info.wifiDetectMode);
2657     data.WriteInt32(info.threshold);
2658     data.WriteInt32(info.envalueCount);
2659     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_VOWIFI_DETECT_MODE),
2660         data, reply, option);
2661     if (error != ERR_NONE) {
2662         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2663             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_VOWIFI_DETECT_MODE), error);
2664         return ErrCode(error);
2665     }
2666     int exception = reply.ReadInt32();
2667     if (exception) {
2668         return WIFI_OPT_FAILED;
2669     }
2670     int ret = reply.ReadInt32();
2671     if (ret != WIFI_OPT_SUCCESS) {
2672         return ErrCode(ret);
2673     }
2674     return WIFI_OPT_SUCCESS;
2675 }
2676 
GetVoWifiDetectMode(WifiDetectConfInfo & info)2677 ErrCode WifiDeviceProxy::GetVoWifiDetectMode(WifiDetectConfInfo &info)
2678 {
2679     if (mRemoteDied) {
2680         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2681         return WIFI_OPT_FAILED;
2682     }
2683     MessageOption option;
2684     MessageParcel data, reply;
2685     if (!data.WriteInterfaceToken(GetDescriptor())) {
2686         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2687         return WIFI_OPT_FAILED;
2688     }
2689     data.WriteInt32(0);
2690     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_VOWIFI_DETECT_MODE),
2691         data, reply, option);
2692     if (error != ERR_NONE) {
2693         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2694             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_VOWIFI_DETECT_MODE), error);
2695         return ErrCode(error);
2696     }
2697     int exception = reply.ReadInt32();
2698     if (exception) {
2699         return WIFI_OPT_FAILED;
2700     }
2701     int ret = reply.ReadInt32();
2702     if (ret != WIFI_OPT_SUCCESS) {
2703         return ErrCode(ret);
2704     }
2705     info.wifiDetectMode = reply.ReadInt32();
2706     info.threshold = reply.ReadInt32();
2707     info.envalueCount = reply.ReadInt32();
2708     return WIFI_OPT_SUCCESS;
2709 }
2710 
SetVoWifiDetectPeriod(int period)2711 ErrCode WifiDeviceProxy::SetVoWifiDetectPeriod(int period)
2712 {
2713     if (mRemoteDied) {
2714         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2715         return WIFI_OPT_FAILED;
2716     }
2717     MessageOption option;
2718     MessageParcel data, reply;
2719     if (!data.WriteInterfaceToken(GetDescriptor())) {
2720         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2721         return WIFI_OPT_FAILED;
2722     }
2723     data.WriteInt32(0);
2724     data.WriteInt32(period);
2725     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_VOWIFI_DETECT_PERIOD),
2726         data, reply, option);
2727     if (error != ERR_NONE) {
2728         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2729             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_VOWIFI_DETECT_PERIOD), error);
2730         return ErrCode(error);
2731     }
2732     int exception = reply.ReadInt32();
2733     if (exception) {
2734         return WIFI_OPT_FAILED;
2735     }
2736     int ret = reply.ReadInt32();
2737     if (ret != WIFI_OPT_SUCCESS) {
2738         return ErrCode(ret);
2739     }
2740     return WIFI_OPT_SUCCESS;
2741 }
2742 
GetVoWifiDetectPeriod(int & period)2743 ErrCode WifiDeviceProxy::GetVoWifiDetectPeriod(int &period)
2744 {
2745     if (mRemoteDied) {
2746         WIFI_LOGE("failed to `%{public}s`,remote service is died!", __func__);
2747         return WIFI_OPT_FAILED;
2748     }
2749     MessageOption option;
2750     MessageParcel data, reply;
2751     if (!data.WriteInterfaceToken(GetDescriptor())) {
2752         WIFI_LOGE("Write interface token error: %{public}s", __func__);
2753         return WIFI_OPT_FAILED;
2754     }
2755     data.WriteInt32(0);
2756     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_VOWIFI_DETECT_PERIOD),
2757         data, reply, option);
2758     if (error != ERR_NONE) {
2759         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2760             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_VOWIFI_DETECT_PERIOD), error);
2761         return ErrCode(error);
2762     }
2763     int exception = reply.ReadInt32();
2764     if (exception) {
2765         return WIFI_OPT_FAILED;
2766     }
2767     int ret = reply.ReadInt32();
2768     if (ret != WIFI_OPT_SUCCESS) {
2769         return ErrCode(ret);
2770     }
2771     period = reply.ReadInt32();
2772     return WIFI_OPT_SUCCESS;
2773 }
2774 
GetMultiLinkedInfo(std::vector<WifiLinkedInfo> & multiLinkedInfo)2775 ErrCode WifiDeviceProxy::GetMultiLinkedInfo(std::vector<WifiLinkedInfo> &multiLinkedInfo)
2776 {
2777     if (mRemoteDied) {
2778         WIFI_LOGE("failed to GetMultiLinkedInfo, remote service is died!");
2779         return WIFI_OPT_FAILED;
2780     }
2781     MessageOption option;
2782     MessageParcel data;
2783     MessageParcel reply;
2784     if (!data.WriteInterfaceToken(GetDescriptor())) {
2785         WIFI_LOGE("GetMultiLinkedInfo Write interface token error");
2786         return WIFI_OPT_FAILED;
2787     }
2788     data.WriteInt32(0);
2789     int error = Remote()->SendRequest(static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_MULTI_LINKED_INFO), data,
2790         reply, option);
2791     if (error != ERR_NONE) {
2792         WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
2793             static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_LINKED_INFO), error);
2794         return WIFI_OPT_FAILED;
2795     }
2796 
2797     int exception = reply.ReadInt32();
2798     if (exception) {
2799         WIFI_LOGE("GetMultiLinkedInfo has exception");
2800         return WIFI_OPT_FAILED;
2801     }
2802     int ret = reply.ReadInt32();
2803     if (ret != WIFI_OPT_SUCCESS) {
2804         return ErrCode(ret);
2805     }
2806 
2807     ParseMultiLinkedInfo(reply, multiLinkedInfo);
2808     return WIFI_OPT_SUCCESS;
2809 }
2810 
2811 }  // namespace Wifi
2812 }  // namespace OHOS
2813