1 /*
2 * Copyright (C) 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 "ipc_skeleton.h"
20 #include "rpc_errno.h"
21 #include "serializer.h"
22 #include "samgr_lite.h"
23 #include "wifi_ipc_lite_adapter.h"
24 #include "wifi_device_callback_stub_lite.h"
25 #include "wifi_logger.h"
26
27 DEFINE_WIFILOG_LABEL("WifiDeviceProxyLite");
28
29 namespace OHOS {
30 namespace Wifi {
31 static SvcIdentity g_sid;
32 static IpcObjectStub g_objStub;
33 static WifiDeviceCallBackStub g_deviceCallBackStub;
ReadIpAddress(IpcIo * reply,WifiIpAddress & address)34 static void ReadIpAddress(IpcIo *reply, WifiIpAddress &address)
35 {
36 constexpr int MAX_SIZE = 256;
37 (void)ReadInt32(reply, &address.family);
38 (void)ReadUint32(reply, &address.addressIpv4);
39 int size = 0;
40 (void)ReadInt32(reply, &size);
41 if (size > MAX_SIZE) {
42 WIFI_LOGE("Read IP address size error: %{public}d", size);
43 return;
44 }
45 int tmpAddress = 0;
46 for (int i = 0; i < size; i++) {
47 (void)ReadInt8(reply, (int8_t *)&tmpAddress);
48 address.addressIpv6.push_back(tmpAddress);
49 }
50 return;
51 }
52
Parse5GChannels(IpcIo * reply,std::vector<int> & result)53 static void Parse5GChannels(IpcIo *reply, std::vector<int> &result)
54 {
55 int retSize = 0;
56 constexpr int MAX_5G_CHANNELS = 36;
57 (void)ReadInt32(reply, &retSize);
58 if (retSize > MAX_5G_CHANNELS) {
59 WIFI_LOGE("Parse5GChannels fail, size error: %{public}d", retSize);
60 return;
61 }
62 for (int i = 0; i < retSize; ++i) {
63 int channel = 0;
64 (void)ReadInt32(reply, &channel);
65 result.emplace_back(channel);
66 }
67 }
68
ReadEapConfig(IpcIo * reply,WifiEapConfig & wifiEapConfig)69 static void ReadEapConfig(IpcIo *reply, WifiEapConfig &wifiEapConfig)
70 {
71 size_t readLen;
72 wifiEapConfig.eap = (char *)ReadString(reply, &readLen);
73 int phase2Method = 0;
74 (void)ReadInt32(reply, &phase2Method);
75 wifiEapConfig.phase2Method = Phase2Method(phase2Method);
76 wifiEapConfig.identity = (char *)ReadString(reply, &readLen);
77 wifiEapConfig.anonymousIdentity = (char *)ReadString(reply, &readLen);
78 wifiEapConfig.password = (char *)ReadString(reply, &readLen);
79 wifiEapConfig.caCertPath = (char *)ReadString(reply, &readLen);
80 wifiEapConfig.caCertAlias = (char *)ReadString(reply, &readLen);
81 wifiEapConfig.clientCert = (char *)ReadString(reply, &readLen);
82 if (strcpy_s(wifiEapConfig.certPassword, sizeof(wifiEapConfig.certPassword),
83 (char *)ReadString(reply, &readLen)) != EOK) {
84 WIFI_LOGE("%{public}s: failed to copy", __func__);
85 }
86 wifiEapConfig.privateKey = (char *)ReadString(reply, &readLen);
87 wifiEapConfig.altSubjectMatch = (char *)ReadString(reply, &readLen);
88 wifiEapConfig.domainSuffixMatch = (char *)ReadString(reply, &readLen);
89 wifiEapConfig.realm = (char *)ReadString(reply, &readLen);
90 wifiEapConfig.plmn = (char *)ReadString(reply, &readLen);
91 (void)ReadInt32(reply, &wifiEapConfig.eapSubId);
92 }
93
ParseDeviceConfigs(IpcIo * reply,std::vector<WifiDeviceConfig> & result)94 static void ParseDeviceConfigs(IpcIo *reply, std::vector<WifiDeviceConfig> &result)
95 {
96 size_t readLen;
97 constexpr int MAX_DEVICE_CONFIG_SIZE = 1024;
98 int retSize = 0;
99 (void)ReadInt32(reply, &retSize);
100 if (retSize > MAX_DEVICE_CONFIG_SIZE) {
101 WIFI_LOGE("Parse device config size error: %{public}d", retSize);
102 return;
103 }
104 for (int i = 0; i < retSize; ++i) {
105 WifiDeviceConfig config;
106 (void)ReadInt32(reply, &config.networkId);
107 (void)ReadInt32(reply, &config.status);
108 config.bssid = (char *)ReadString(reply, &readLen);
109 config.ssid = (char *)ReadString(reply, &readLen);
110 (void)ReadInt32(reply, &config.band);
111 (void)ReadInt32(reply, &config.channel);
112 (void)ReadInt32(reply, &config.frequency);
113 (void)ReadInt32(reply, &config.level);
114 (void)ReadBool(reply, &config.isPasspoint);
115 (void)ReadBool(reply, &config.isEphemeral);
116 config.preSharedKey = (char *)ReadString(reply, &readLen);
117 config.keyMgmt = (char *)ReadString(reply, &readLen);
118 for (int j = 0; j < WEPKEYS_SIZE; j++) {
119 config.wepKeys[j] = (char *)ReadString(reply, &readLen);
120 }
121 (void)ReadInt32(reply, &config.wepTxKeyIndex);
122 (void)ReadInt32(reply, &config.priority);
123 (void)ReadBool(reply, &config.hiddenSSID);
124 int ipMethod = 0;
125 (void)ReadInt32(reply, &ipMethod);
126 config.wifiIpConfig.assignMethod = AssignIpMethod(ipMethod);
127 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.ipAddress.address);
128 (void)ReadInt32(reply, &config.wifiIpConfig.staticIpAddress.ipAddress.prefixLength);
129 (void)ReadInt32(reply, &config.wifiIpConfig.staticIpAddress.ipAddress.flags);
130 (void)ReadInt32(reply, &config.wifiIpConfig.staticIpAddress.ipAddress.scope);
131 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.gateway);
132 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.dnsServer1);
133 ReadIpAddress(reply, config.wifiIpConfig.staticIpAddress.dnsServer2);
134 config.wifiIpConfig.staticIpAddress.domains = (char *)ReadString(reply, &readLen);
135 ReadEapConfig(reply, config.wifiEapConfig);
136 int proxyMethod = 0;
137 (void)ReadInt32(reply, &proxyMethod);
138 config.wifiProxyconfig.configureMethod = ConfigureProxyMethod(proxyMethod);
139 config.wifiProxyconfig.autoProxyConfig.pacWebAddress = (char *)ReadString(reply, &readLen);
140 config.wifiProxyconfig.manualProxyConfig.serverHostName = (char *)ReadString(reply, &readLen);
141 (void)ReadInt32(reply, &config.wifiProxyconfig.manualProxyConfig.serverPort);
142 config.wifiProxyconfig.manualProxyConfig.exclusionObjectList = (char *)ReadString(reply, &readLen);
143 int privacyConfig = 0;
144 (void)ReadInt32(reply, &privacyConfig);
145 config.wifiPrivacySetting = WifiPrivacyConfig(privacyConfig);
146 (void)ReadInt32(reply, &config.uid);
147 (void)ReadInt32(reply, &config.wifiWapiConfig.wapiPskType);
148 result.emplace_back(config);
149 std::string().swap(config.preSharedKey);
150 }
151 }
152
ReadLinkedInfo(IpcIo * reply,WifiLinkedInfo & info)153 static void ReadLinkedInfo(IpcIo *reply, WifiLinkedInfo &info)
154 {
155 size_t readLen;
156 (void)ReadInt32(reply, &info.networkId);
157 info.ssid = (char *)ReadString(reply, &readLen);
158 info.bssid = (char *)ReadString(reply, &readLen);
159 (void)ReadInt32(reply, &info.rssi);
160 (void)ReadInt32(reply, &info.band);
161 (void)ReadInt32(reply, &info.frequency);
162 (void)ReadInt32(reply, &info.linkSpeed);
163 info.macAddress = (char *)ReadString(reply, &readLen);
164 (void)ReadUint32(reply, &info.ipAddress);
165 int tmpConnState = 0;
166 (void)ReadInt32(reply, &tmpConnState);
167 if ((tmpConnState >= 0) && (tmpConnState <= (int)ConnState::UNKNOWN)) {
168 info.connState = ConnState(tmpConnState);
169 } else {
170 info.connState = ConnState::UNKNOWN;
171 }
172 (void)ReadBool(reply, &info.ifHiddenSSID);
173 (void)ReadInt32(reply, &info.rxLinkSpeed);
174 (void)ReadInt32(reply, &info.txLinkSpeed);
175 (void)ReadInt32(reply, &info.chload);
176 (void)ReadInt32(reply, &info.snr);
177 (void)ReadInt32(reply, &info.isDataRestricted);
178 info.portalUrl = (char *)ReadString(reply, &readLen);
179
180 int tmpState = 0;
181 (void)ReadInt32(reply, &tmpState);
182 if ((tmpState >= 0) && (tmpState <= (int)SupplicantState::INVALID)) {
183 info.supplicantState = (SupplicantState)tmpState;
184 } else {
185 info.supplicantState = SupplicantState::INVALID;
186 }
187
188 int tmpDetailState = 0;
189 (void)ReadInt32(reply, &tmpDetailState);
190 if ((tmpDetailState >= 0) && (tmpDetailState <= (int)DetailedState::INVALID)) {
191 info.detailedState = (DetailedState)tmpDetailState;
192 } else {
193 info.detailedState = DetailedState::INVALID;
194 }
195 (void)ReadInt32(reply, &info.wifiStandard);
196 (void)ReadInt32(reply, &info.maxSupportedRxLinkSpeed);
197 (void)ReadInt32(reply, &info.maxSupportedTxLinkSpeed);
198
199 int tmpChanWidth = (int)WifiChannelWidth::WIDTH_INVALID;
200 (void)ReadInt32(reply, &tmpChanWidth);
201 if ((tmpChanWidth >= 0) && (tmpChanWidth <= (int)WifiChannelWidth::WIDTH_INVALID)) {
202 info.channelWidth = (WifiChannelWidth)tmpChanWidth;
203 } else {
204 info.channelWidth = WifiChannelWidth::WIDTH_INVALID;
205 }
206 }
207
ReadDhcpInfo(IpcIo * reply,IpInfo & info)208 static void ReadDhcpInfo(IpcIo *reply, IpInfo &info)
209 {
210 (void)ReadUint32(reply, &info.ipAddress);
211 (void)ReadUint32(reply, &info.gateway);
212 (void)ReadUint32(reply, &info.netmask);
213 (void)ReadUint32(reply, &info.primaryDns);
214 (void)ReadUint32(reply, &info.secondDns);
215 (void)ReadUint32(reply, &info.serverIp);
216 (void)ReadUint32(reply, &info.leaseDuration);
217 }
218
IpcCallback(void * owner,int code,IpcIo * reply)219 static int IpcCallback(void *owner, int code, IpcIo *reply)
220 {
221 if (code != 0 || owner == nullptr || reply == nullptr) {
222 WIFI_LOGE("Callback error, code:%{public}d, owner:%{public}d, reply:%{public}d",
223 code, owner == nullptr, reply == nullptr);
224 return ERR_FAILED;
225 }
226
227 struct IpcOwner *data = (struct IpcOwner *)owner;
228 (void)ReadInt32(reply, &data->exception);
229 (void)ReadInt32(reply, &data->retCode);
230 if (data->exception != 0 || data->retCode != WIFI_OPT_SUCCESS || data->variable == nullptr) {
231 return ERR_NONE;
232 }
233
234 switch (data->funcId) {
235 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_ADD_DEVICE_CONFIG):
236 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_UPDATE_DEVICE_CONFIG):
237 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_STATE):
238 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SIGNAL_LEVEL): {
239 (void)ReadInt32(reply, (int32_t *)data->variable);
240 break;
241 }
242 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_CONNECTED):
243 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_ACTIVE):
244 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_LATENCY_MODE): {
245 (void)ReadBool(reply, (bool *)data->variable);
246 break;
247 }
248 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_COUNTRY_CODE):
249 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DERVICE_MAC_ADD): {
250 size_t readLen = 0;
251 *((std::string *)data->variable) = (char *)ReadString(reply, &readLen);
252 break;
253 }
254 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES): {
255 int64_t features = 0;
256 ReadInt64(reply, &features);
257 *((long *)data->variable) = features;
258 break;
259 }
260 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIGS): {
261 ParseDeviceConfigs(reply, *((std::vector<WifiDeviceConfig> *)data->variable));
262 break;
263 }
264 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_LINKED_INFO): {
265 ReadLinkedInfo(reply, *((WifiLinkedInfo *)data->variable));
266 break;
267 }
268 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_INFO): {
269 ReadDhcpInfo(reply, *((IpInfo *)data->variable));
270 break;
271 }
272 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_BANDTYPE_SUPPORTED): {
273 (void)ReadBool(reply, (bool *)data->variable);
274 break;
275 }
276 case static_cast<uint32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_5G_CHANNELLIST): {
277 Parse5GChannels(reply, *((std::vector<int> *)data->variable));
278 break;
279 }
280 default:
281 break;
282 }
283
284 return ERR_NONE;
285 }
286
AsyncCallback(uint32_t code,IpcIo * data,IpcIo * reply,MessageOption option)287 static int AsyncCallback(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option)
288 {
289 if (data == nullptr) {
290 WIFI_LOGE("AsyncCallback error, data is null");
291 return ERR_FAILED;
292 }
293 return g_deviceCallBackStub.OnRemoteRequest(code, data);
294 }
295
OnRemoteSrvDied(void * arg)296 static void OnRemoteSrvDied(void *arg)
297 {
298 WIFI_LOGE("%{public}s called.", __func__);
299 WifiDeviceProxy *client = WifiDeviceProxy::GetInstance();
300 if (client != nullptr) {
301 client->OnRemoteDied();
302 }
303 return;
304 }
305
306 WifiDeviceProxy *WifiDeviceProxy::g_instance = nullptr;
WifiDeviceProxy()307 WifiDeviceProxy::WifiDeviceProxy() : remoteDied_(false)
308 {}
309
~WifiDeviceProxy()310 WifiDeviceProxy::~WifiDeviceProxy()
311 {}
312
GetInstance(void)313 WifiDeviceProxy *WifiDeviceProxy::GetInstance(void)
314 {
315 if (g_instance != nullptr) {
316 return g_instance;
317 }
318
319 WifiDeviceProxy *tempInstance = new(std::nothrow) WifiDeviceProxy();
320 g_instance = tempInstance;
321 return g_instance;
322 }
323
ReleaseInstance(void)324 void WifiDeviceProxy::ReleaseInstance(void)
325 {
326 if (g_instance != nullptr) {
327 delete g_instance;
328 g_instance = nullptr;
329 }
330 }
331
Init()332 ErrCode WifiDeviceProxy::Init()
333 {
334 IUnknown *iUnknown = SAMGR_GetInstance()->GetFeatureApi(WIFI_SERVICE_LITE, WIFI_FEATURE_DEVICE);
335 if (iUnknown == nullptr) {
336 WIFI_LOGE("GetFeatureApi failed.");
337 return WIFI_OPT_FAILED;
338 }
339 IClientProxy *proxy = nullptr;
340 int result = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, reinterpret_cast<void **>(&proxy));
341 if (result != 0) {
342 WIFI_LOGE("QueryInterface failed.");
343 return WIFI_OPT_FAILED;
344 }
345 remote_ = proxy;
346
347 // Register SA Death Callback
348 uint32_t deadId = 0;
349 svcIdentity_ = SAMGR_GetRemoteIdentity(WIFI_SERVICE_LITE, WIFI_FEATURE_DEVICE);
350 result = AddDeathRecipient(svcIdentity_, OnRemoteSrvDied, nullptr, &deadId);
351 if (result != 0) {
352 WIFI_LOGE("Register SA Death Callback failed, errorCode[%d]", result);
353 }
354 return WIFI_OPT_SUCCESS;
355 }
356
EnableWifi()357 ErrCode WifiDeviceProxy::EnableWifi()
358 {
359 if (remoteDied_ || remote_ == nullptr) {
360 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
361 __func__, remoteDied_, remote_ == nullptr);
362 return WIFI_OPT_FAILED;
363 }
364
365 IpcIo req;
366 char data[IPC_DATA_SIZE_SMALL];
367 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
368
369 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
370 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
371 WIFI_LOGE("Write interface token error: %{public}s", __func__);
372 return WIFI_OPT_FAILED;
373 }
374 (void)WriteInt32(&req, 0);
375 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_WIFI);
376 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_WIFI), &req, &owner,
377 IpcCallback);
378 if (error != EC_SUCCESS) {
379 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
380 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_WIFI), error);
381 return WIFI_OPT_FAILED;
382 }
383
384 if (owner.exception) {
385 return WIFI_OPT_FAILED;
386 }
387 return ErrCode(owner.retCode);
388 }
389
DisableWifi()390 ErrCode WifiDeviceProxy::DisableWifi()
391 {
392 if (remoteDied_ || remote_ == nullptr) {
393 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
394 __func__, remoteDied_, remote_ == nullptr);
395 return WIFI_OPT_FAILED;
396 }
397
398 IpcIo req;
399 char data[IPC_DATA_SIZE_SMALL];
400 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
401
402 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
403 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
404 WIFI_LOGE("Write interface token error: %{public}s", __func__);
405 return WIFI_OPT_FAILED;
406 }
407 (void)WriteInt32(&req, 0);
408 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_WIFI);
409 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_WIFI), &req,
410 &owner, IpcCallback);
411 if (error != EC_SUCCESS) {
412 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
413 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_WIFI), error);
414 return WIFI_OPT_FAILED;
415 }
416
417 if (owner.exception) {
418 return WIFI_OPT_FAILED;
419 }
420 return ErrCode(owner.retCode);
421 }
422
InitWifiProtect(const WifiProtectType & protectType,const std::string & protectName)423 ErrCode WifiDeviceProxy::InitWifiProtect(const WifiProtectType &protectType, const std::string &protectName)
424 {
425 if (remoteDied_ || remote_ == nullptr) {
426 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
427 __func__, remoteDied_, remote_ == nullptr);
428 return WIFI_OPT_FAILED;
429 }
430
431 IpcIo req;
432 char data[IPC_DATA_SIZE_SMALL];
433 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
434
435 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
436 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
437 WIFI_LOGE("Write interface token error: %{public}s", __func__);
438 return WIFI_OPT_FAILED;
439 }
440 (void)WriteInt32(&req, 0);
441 (void)WriteInt32(&req, (int)protectType);
442 (void)WriteString(&req, protectName.c_str());
443 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_INIT_WIFI_PROTECT);
444 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_INIT_WIFI_PROTECT), &req,
445 &owner, IpcCallback);
446 if (error != EC_SUCCESS) {
447 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
448 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_INIT_WIFI_PROTECT), error);
449 return ErrCode(error);
450 }
451
452 if (owner.exception) {
453 return WIFI_OPT_FAILED;
454 }
455 return ErrCode(owner.retCode);
456 }
457
GetWifiProtectRef(const WifiProtectMode & protectMode,const std::string & protectName)458 ErrCode WifiDeviceProxy::GetWifiProtectRef(const WifiProtectMode &protectMode, const std::string &protectName)
459 {
460 if (remoteDied_ || remote_ == nullptr) {
461 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
462 __func__, remoteDied_, remote_ == nullptr);
463 return WIFI_OPT_FAILED;
464 }
465
466 IpcIo req;
467 char data[IPC_DATA_SIZE_SMALL];
468 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
469
470 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
471 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
472 WIFI_LOGE("Write interface token error: %{public}s", __func__);
473 return WIFI_OPT_FAILED;
474 }
475 (void)WriteInt32(&req, 0);
476 (void)WriteInt32(&req, (int)protectMode);
477 (void)WriteString(&req, protectName.c_str());
478 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_PROTECT);
479 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_PROTECT), &req,
480 &owner, IpcCallback);
481 if (error != EC_SUCCESS) {
482 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
483 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_PROTECT), error);
484 return ErrCode(error);
485 }
486
487 if (owner.exception) {
488 return WIFI_OPT_FAILED;
489 }
490 return ErrCode(owner.retCode);
491 }
492
PutWifiProtectRef(const std::string & protectName)493 ErrCode WifiDeviceProxy::PutWifiProtectRef(const std::string &protectName)
494 {
495 if (remoteDied_ || remote_ == nullptr) {
496 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
497 __func__, remoteDied_, remote_ == nullptr);
498 return WIFI_OPT_FAILED;
499 }
500
501 IpcIo req;
502 char data[IPC_DATA_SIZE_SMALL];
503 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
504
505 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
506 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
507 WIFI_LOGE("Write interface token error: %{public}s", __func__);
508 return WIFI_OPT_FAILED;
509 }
510 (void)WriteInt32(&req, 0);
511 (void)WriteString(&req, protectName.c_str());
512 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_PUT_WIFI_PROTECT);
513 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_PUT_WIFI_PROTECT), &req,
514 &owner, IpcCallback);
515 if (error != EC_SUCCESS) {
516 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
517 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_PUT_WIFI_PROTECT), error);
518 return ErrCode(error);
519 }
520
521 if (owner.exception) {
522 return WIFI_OPT_FAILED;
523 }
524 return ErrCode(owner.retCode);
525 }
526
RemoveCandidateConfig(int networkId)527 ErrCode WifiDeviceProxy::RemoveCandidateConfig(int networkId)
528 {
529 (void)networkId;
530 return WIFI_OPT_NOT_SUPPORTED;
531 }
532
RemoveCandidateConfig(const WifiDeviceConfig & config)533 ErrCode WifiDeviceProxy::RemoveCandidateConfig(const WifiDeviceConfig &config)
534 {
535 (void)config;
536 return WIFI_OPT_NOT_SUPPORTED;
537 }
538
WriteIpAddress(IpcIo & req,const WifiIpAddress & address)539 void WifiDeviceProxy::WriteIpAddress(IpcIo &req, const WifiIpAddress &address)
540 {
541 (void)WriteInt32(&req, address.family);
542 (void)WriteUint32(&req, address.addressIpv4);
543 int size = address.addressIpv6.size();
544 (void)WriteInt32(&req, size);
545 for (int i = 0; i < size; i++) {
546 (void)WriteInt8(&req, address.addressIpv6[i]);
547 }
548 return;
549 }
550
WriteEapConfig(IpcIo & req,const WifiEapConfig & wifiEapConfig)551 void WifiDeviceProxy::WriteEapConfig(IpcIo &req, const WifiEapConfig &wifiEapConfig)
552 {
553 (void)WriteString(&req, wifiEapConfig.eap.c_str());
554 (void)WriteInt32(&req, static_cast<int>(wifiEapConfig.phase2Method));
555 (void)WriteString(&req, wifiEapConfig.identity.c_str());
556 (void)WriteString(&req, wifiEapConfig.anonymousIdentity.c_str());
557 (void)WriteString(&req, wifiEapConfig.password.c_str());
558
559 (void)WriteString(&req, wifiEapConfig.caCertPath.c_str());
560 (void)WriteString(&req, wifiEapConfig.caCertAlias.c_str());
561
562 (void)WriteString(&req, wifiEapConfig.clientCert.c_str());
563 (void)WriteString(&req, std::string(wifiEapConfig.certPassword).c_str());
564 (void)WriteString(&req, wifiEapConfig.privateKey.c_str());
565
566 (void)WriteString(&req, wifiEapConfig.altSubjectMatch.c_str());
567 (void)WriteString(&req, wifiEapConfig.domainSuffixMatch.c_str());
568 (void)WriteString(&req, wifiEapConfig.realm.c_str());
569 (void)WriteString(&req, wifiEapConfig.plmn.c_str());
570 (void)WriteInt32(&req, wifiEapConfig.eapSubId);
571 }
572
WriteDeviceConfig(const WifiDeviceConfig & config,IpcIo & req)573 void WifiDeviceProxy::WriteDeviceConfig(const WifiDeviceConfig &config, IpcIo &req)
574 {
575 (void)WriteInt32(&req, config.networkId);
576 (void)WriteInt32(&req, config.status);
577 (void)WriteString(&req, config.bssid.c_str());
578 (void)WriteString(&req, config.ssid.c_str());
579 (void)WriteInt32(&req, config.band);
580 (void)WriteInt32(&req, config.channel);
581 (void)WriteInt32(&req, config.frequency);
582 (void)WriteInt32(&req, config.level);
583 (void)WriteBool(&req, config.isPasspoint);
584 (void)WriteBool(&req, config.isEphemeral);
585 (void)WriteString(&req, config.preSharedKey.c_str());
586 (void)WriteString(&req, config.keyMgmt.c_str());
587 for (int i = 0; i < WEPKEYS_SIZE; i++) {
588 (void)WriteString(&req, config.wepKeys[i].c_str());
589 }
590 (void)WriteInt32(&req, config.wepTxKeyIndex);
591 (void)WriteInt32(&req, config.priority);
592 (void)WriteBool(&req, config.hiddenSSID);
593 (void)WriteInt32(&req, (int)config.wifiIpConfig.assignMethod);
594 WriteIpAddress(req, config.wifiIpConfig.staticIpAddress.ipAddress.address);
595 (void)WriteInt32(&req, config.wifiIpConfig.staticIpAddress.ipAddress.prefixLength);
596 (void)WriteInt32(&req, config.wifiIpConfig.staticIpAddress.ipAddress.flags);
597 (void)WriteInt32(&req, config.wifiIpConfig.staticIpAddress.ipAddress.scope);
598 WriteIpAddress(req, config.wifiIpConfig.staticIpAddress.gateway);
599 WriteIpAddress(req, config.wifiIpConfig.staticIpAddress.dnsServer1);
600 WriteIpAddress(req, config.wifiIpConfig.staticIpAddress.dnsServer2);
601 (void)WriteString(&req, config.wifiIpConfig.staticIpAddress.domains.c_str());
602 WriteEapConfig(req, config.wifiEapConfig);
603 (void)WriteInt32(&req, (int)config.wifiProxyconfig.configureMethod);
604 (void)WriteString(&req, config.wifiProxyconfig.autoProxyConfig.pacWebAddress.c_str());
605 (void)WriteString(&req, config.wifiProxyconfig.manualProxyConfig.serverHostName.c_str());
606 (void)WriteInt32(&req, config.wifiProxyconfig.manualProxyConfig.serverPort);
607 (void)WriteString(&req, config.wifiProxyconfig.manualProxyConfig.exclusionObjectList.c_str());
608 (void)WriteInt32(&req, (int)config.wifiPrivacySetting);
609 (void)WriteInt32(&req, (int)config.wifiWapiConfig.wapiPskType);
610 (void)WriteString(&req, config.wifiWapiConfig.wapiAsCertData.c_str());
611 (void)WriteString(&req, config.wifiWapiConfig.wapiUserCertData.c_str());
612 }
613
AddDeviceConfig(const WifiDeviceConfig & config,int & result,bool isCandidate)614 ErrCode WifiDeviceProxy::AddDeviceConfig(const WifiDeviceConfig &config, int &result, bool isCandidate)
615 {
616 if (remoteDied_ || remote_ == nullptr) {
617 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
618 __func__, remoteDied_, remote_ == nullptr);
619 return WIFI_OPT_FAILED;
620 }
621
622 IpcIo req;
623 char data[IPC_DATA_SIZE_BIG];
624 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
625
626 IpcIoInit(&req, data, IPC_DATA_SIZE_BIG, MAX_IPC_OBJ_COUNT);
627 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
628 WIFI_LOGE("Write interface token error: %{public}s", __func__);
629 return WIFI_OPT_FAILED;
630 }
631 (void)WriteInt32(&req, 0);
632 (void)WriteBool(&req, isCandidate);
633 WriteDeviceConfig(config, req);
634 owner.variable = &result;
635 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ADD_DEVICE_CONFIG);
636 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ADD_DEVICE_CONFIG), &req,
637 &owner, IpcCallback);
638 if (error != EC_SUCCESS) {
639 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
640 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ADD_DEVICE_CONFIG), error);
641 return WIFI_OPT_FAILED;
642 }
643
644 if (owner.exception) {
645 return WIFI_OPT_FAILED;
646 }
647 return ErrCode(owner.retCode);
648 }
649
UpdateDeviceConfig(const WifiDeviceConfig & config,int & result)650 ErrCode WifiDeviceProxy::UpdateDeviceConfig(const WifiDeviceConfig &config, int &result)
651 {
652 if (remoteDied_ || remote_ == nullptr) {
653 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
654 __func__, remoteDied_, remote_ == nullptr);
655 return WIFI_OPT_FAILED;
656 }
657
658 IpcIo req;
659 char data[IPC_DATA_SIZE_BIG];
660 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
661
662 IpcIoInit(&req, data, IPC_DATA_SIZE_BIG, MAX_IPC_OBJ_COUNT);
663 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
664 WIFI_LOGE("Write interface token error: %{public}s", __func__);
665 return WIFI_OPT_FAILED;
666 }
667 (void)WriteInt32(&req, 0);
668 WriteDeviceConfig(config, req);
669 owner.variable = &result;
670 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_UPDATE_DEVICE_CONFIG);
671 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_UPDATE_DEVICE_CONFIG),
672 &req, &owner, IpcCallback);
673 if (error != EC_SUCCESS) {
674 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
675 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_UPDATE_DEVICE_CONFIG), error);
676 return WIFI_OPT_FAILED;
677 }
678
679 if (owner.exception) {
680 return WIFI_OPT_FAILED;
681 }
682 return ErrCode(owner.retCode);
683 }
684
RemoveDevice(int networkId)685 ErrCode WifiDeviceProxy::RemoveDevice(int networkId)
686 {
687 if (remoteDied_ || remote_ == nullptr) {
688 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
689 __func__, remoteDied_, remote_ == nullptr);
690 return WIFI_OPT_FAILED;
691 }
692
693 IpcIo req;
694 char data[IPC_DATA_SIZE_SMALL];
695 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
696
697 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
698 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
699 WIFI_LOGE("Write interface token error: %{public}s", __func__);
700 return WIFI_OPT_FAILED;
701 }
702 (void)WriteInt32(&req, 0);
703 (void)WriteInt32(&req, networkId);
704 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_DEVICE_CONFIG);
705 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_DEVICE_CONFIG),
706 &req, &owner, IpcCallback);
707 if (error != EC_SUCCESS) {
708 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
709 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_DEVICE_CONFIG), error);
710 return WIFI_OPT_FAILED;
711 }
712
713 if (owner.exception) {
714 return WIFI_OPT_FAILED;
715 }
716 return ErrCode(owner.retCode);
717 }
718
RemoveAllDevice()719 ErrCode WifiDeviceProxy::RemoveAllDevice()
720 {
721 if (remoteDied_ || remote_ == nullptr) {
722 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
723 __func__, remoteDied_, remote_ == nullptr);
724 return WIFI_OPT_FAILED;
725 }
726
727 IpcIo req;
728 char data[IPC_DATA_SIZE_SMALL];
729 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
730
731 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
732 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
733 WIFI_LOGE("Write interface token error: %{public}s", __func__);
734 return WIFI_OPT_FAILED;
735 }
736 (void)WriteInt32(&req, 0);
737 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_ALL_DEVICE_CONFIG);
738 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_ALL_DEVICE_CONFIG),
739 &req, &owner, IpcCallback);
740 if (error != EC_SUCCESS) {
741 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
742 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REMOVE_ALL_DEVICE_CONFIG), error);
743 return WIFI_OPT_FAILED;
744 }
745
746 if (owner.exception) {
747 return WIFI_OPT_FAILED;
748 }
749 return ErrCode(owner.retCode);
750 }
751
GetDeviceConfigs(std::vector<WifiDeviceConfig> & result,bool isCandidate)752 ErrCode WifiDeviceProxy::GetDeviceConfigs(std::vector<WifiDeviceConfig> &result, bool isCandidate)
753 {
754 if (remoteDied_ || remote_ == nullptr) {
755 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
756 __func__, remoteDied_, remote_ == nullptr);
757 return WIFI_OPT_FAILED;
758 }
759
760 IpcIo req;
761 char data[IPC_DATA_SIZE_SMALL];
762 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
763
764 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
765 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
766 WIFI_LOGE("Write interface token error: %{public}s", __func__);
767 return WIFI_OPT_FAILED;
768 }
769 (void)WriteInt32(&req, 0);
770 (void)WriteBool(&req, isCandidate);
771 owner.variable = &result;
772 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIGS);
773 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIGS), &req,
774 &owner, IpcCallback);
775 if (error != EC_SUCCESS) {
776 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
777 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DEVICE_CONFIGS), error);
778 return WIFI_OPT_FAILED;
779 }
780
781 if (owner.exception) {
782 return WIFI_OPT_FAILED;
783 }
784
785 return ErrCode(owner.retCode);
786 }
787
EnableDeviceConfig(int networkId,bool attemptEnable)788 ErrCode WifiDeviceProxy::EnableDeviceConfig(int networkId, bool attemptEnable)
789 {
790 if (remoteDied_ || remote_ == nullptr) {
791 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
792 __func__, remoteDied_, remote_ == nullptr);
793 return WIFI_OPT_FAILED;
794 }
795
796 IpcIo req;
797 char data[IPC_DATA_SIZE_SMALL];
798 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
799
800 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
801 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
802 WIFI_LOGE("Write interface token error: %{public}s", __func__);
803 return WIFI_OPT_FAILED;
804 }
805 (void)WriteInt32(&req, 0);
806 (void)WriteInt32(&req, networkId);
807 (void)WriteInt32(&req, attemptEnable);
808 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_DEVICE);
809 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_DEVICE), &req,
810 &owner, IpcCallback);
811 if (error != EC_SUCCESS) {
812 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
813 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_DEVICE), error);
814 return WIFI_OPT_FAILED;
815 }
816
817 if (owner.exception) {
818 return WIFI_OPT_FAILED;
819 }
820 return ErrCode(owner.retCode);
821 }
822
DisableDeviceConfig(int networkId)823 ErrCode WifiDeviceProxy::DisableDeviceConfig(int networkId)
824 {
825 if (remoteDied_ || remote_ == nullptr) {
826 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
827 __func__, remoteDied_, remote_ == nullptr);
828 return WIFI_OPT_FAILED;
829 }
830
831 IpcIo req;
832 char data[IPC_DATA_SIZE_SMALL];
833 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
834
835 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
836 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
837 WIFI_LOGE("Write interface token error: %{public}s", __func__);
838 return WIFI_OPT_FAILED;
839 }
840 (void)WriteInt32(&req, 0);
841 (void)WriteInt32(&req, networkId);
842 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_DEVICE);
843 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_DEVICE), &req,
844 &owner, IpcCallback);
845 if (error != EC_SUCCESS) {
846 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
847 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISABLE_DEVICE), error);
848 return WIFI_OPT_FAILED;
849 }
850
851 if (owner.exception) {
852 return WIFI_OPT_FAILED;
853 }
854 return ErrCode(owner.retCode);
855 }
856
ConnectToNetwork(int networkId,bool isCandidate)857 ErrCode WifiDeviceProxy::ConnectToNetwork(int networkId, bool isCandidate)
858 {
859 if (remoteDied_ || remote_ == nullptr) {
860 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
861 __func__, remoteDied_, remote_ == nullptr);
862 return WIFI_OPT_FAILED;
863 }
864
865 IpcIo req;
866 char data[IPC_DATA_SIZE_SMALL];
867 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
868
869 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
870 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
871 WIFI_LOGE("Write interface token error: %{public}s", __func__);
872 return WIFI_OPT_FAILED;
873 }
874 (void)WriteInt32(&req, 0);
875 (void)WriteBool(&req, isCandidate);
876 (void)WriteInt32(&req, networkId);
877 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT_TO);
878 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT_TO), &req, &owner,
879 IpcCallback);
880 if (error != EC_SUCCESS) {
881 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
882 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT_TO), error);
883 return WIFI_OPT_FAILED;
884 }
885
886 if (owner.exception) {
887 return WIFI_OPT_FAILED;
888 }
889 return ErrCode(owner.retCode);
890 }
891
ConnectToDevice(const WifiDeviceConfig & config)892 ErrCode WifiDeviceProxy::ConnectToDevice(const WifiDeviceConfig &config)
893 {
894 if (remoteDied_ || remote_ == nullptr) {
895 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
896 __func__, remoteDied_, remote_ == nullptr);
897 return WIFI_OPT_FAILED;
898 }
899
900 IpcIo req;
901 char data[IPC_DATA_SIZE_BIG];
902 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
903
904 IpcIoInit(&req, data, IPC_DATA_SIZE_BIG, MAX_IPC_OBJ_COUNT);
905 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
906 WIFI_LOGE("Write interface token error: %{public}s", __func__);
907 return WIFI_OPT_FAILED;
908 }
909 (void)WriteInt32(&req, 0);
910 WriteDeviceConfig(config, req);
911 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT2_TO);
912 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT2_TO), &req, &owner,
913 IpcCallback);
914 if (error != EC_SUCCESS) {
915 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
916 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CONNECT2_TO), error);
917 return WIFI_OPT_FAILED;
918 }
919
920 if (owner.exception) {
921 return WIFI_OPT_FAILED;
922 }
923 return ErrCode(owner.retCode);
924 }
925
IsConnected(bool & isConnected)926 ErrCode WifiDeviceProxy::IsConnected(bool &isConnected)
927 {
928 if (remoteDied_ || remote_ == nullptr) {
929 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
930 __func__, remoteDied_, remote_ == nullptr);
931 return WIFI_OPT_FAILED;
932 }
933
934 IpcIo req;
935 char data[IPC_DATA_SIZE_SMALL];
936 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
937 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
938 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
939 WIFI_LOGE("Write interface token error: %{public}s", __func__);
940 return WIFI_OPT_FAILED;
941 }
942 (void)WriteInt32(&req, 0);
943 owner.variable = &isConnected;
944 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_CONNECTED);
945 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_CONNECTED), &req,
946 &owner, IpcCallback);
947 if (error != EC_SUCCESS) {
948 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
949 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_CONNECTED), error);
950 return WIFI_OPT_FAILED;
951 }
952
953 if (owner.exception) {
954 return WIFI_OPT_FAILED;
955 }
956 return ErrCode(owner.retCode);
957 }
958
ReConnect()959 ErrCode WifiDeviceProxy::ReConnect()
960 {
961 if (remoteDied_ || remote_ == nullptr) {
962 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
963 __func__, remoteDied_, remote_ == nullptr);
964 return WIFI_OPT_FAILED;
965 }
966
967 IpcIo req;
968 char data[IPC_DATA_SIZE_SMALL];
969 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
970
971 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
972 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
973 WIFI_LOGE("Write interface token error: %{public}s", __func__);
974 return WIFI_OPT_FAILED;
975 }
976 (void)WriteInt32(&req, 0);
977 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_RECONNECT);
978 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_RECONNECT), &req, &owner,
979 IpcCallback);
980 if (error != EC_SUCCESS) {
981 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
982 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_RECONNECT), error);
983 return WIFI_OPT_FAILED;
984 }
985
986 if (owner.exception) {
987 return WIFI_OPT_FAILED;
988 }
989 return ErrCode(owner.retCode);
990 }
991
ReAssociate(void)992 ErrCode WifiDeviceProxy::ReAssociate(void)
993 {
994 if (remoteDied_ || remote_ == nullptr) {
995 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
996 __func__, remoteDied_, remote_ == nullptr);
997 return WIFI_OPT_FAILED;
998 }
999
1000 IpcIo req;
1001 char data[IPC_DATA_SIZE_SMALL];
1002 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1003
1004 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1005 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1006 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1007 return WIFI_OPT_FAILED;
1008 }
1009 (void)WriteInt32(&req, 0);
1010 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REASSOCIATE);
1011 int error = remote_->Invoke(remote_,
1012 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REASSOCIATE), &req, &owner, IpcCallback);
1013 if (error != EC_SUCCESS) {
1014 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1015 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REASSOCIATE), error);
1016 return WIFI_OPT_FAILED;
1017 }
1018
1019 if (owner.exception) {
1020 return WIFI_OPT_FAILED;
1021 }
1022 return ErrCode(owner.retCode);
1023 }
1024
Disconnect(void)1025 ErrCode WifiDeviceProxy::Disconnect(void)
1026 {
1027 if (remoteDied_ || remote_ == nullptr) {
1028 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1029 __func__, remoteDied_, remote_ == nullptr);
1030 return WIFI_OPT_FAILED;
1031 }
1032
1033 IpcIo req;
1034 char data[IPC_DATA_SIZE_SMALL];
1035 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1036
1037 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1038 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1039 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1040 return WIFI_OPT_FAILED;
1041 }
1042 (void)WriteInt32(&req, 0);
1043 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISCONNECT);
1044 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISCONNECT), &req, &owner,
1045 IpcCallback);
1046 if (error != EC_SUCCESS) {
1047 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1048 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_DISCONNECT), error);
1049 return WIFI_OPT_FAILED;
1050 }
1051
1052 if (owner.exception) {
1053 return WIFI_OPT_FAILED;
1054 }
1055 return ErrCode(owner.retCode);
1056 }
1057
StartWps(const WpsConfig & config)1058 ErrCode WifiDeviceProxy::StartWps(const WpsConfig &config)
1059 {
1060 if (remoteDied_ || remote_ == nullptr) {
1061 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1062 __func__, remoteDied_, remote_ == nullptr);
1063 return WIFI_OPT_FAILED;
1064 }
1065
1066 IpcIo req;
1067 char data[IPC_DATA_SIZE_SMALL];
1068 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1069
1070 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1071 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1072 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1073 return WIFI_OPT_FAILED;
1074 }
1075 (void)WriteInt32(&req, 0);
1076 (void)WriteInt32(&req, static_cast<int>(config.setup));
1077 (void)WriteString(&req, config.pin.c_str());
1078 (void)WriteString(&req, config.bssid.c_str());
1079 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_WPS);
1080 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_WPS), &req, &owner,
1081 IpcCallback);
1082 if (error != EC_SUCCESS) {
1083 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1084 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_START_WPS), error);
1085 return WIFI_OPT_FAILED;
1086 }
1087
1088 if (owner.exception) {
1089 return WIFI_OPT_FAILED;
1090 }
1091 return ErrCode(owner.retCode);
1092 }
1093
CancelWps(void)1094 ErrCode WifiDeviceProxy::CancelWps(void)
1095 {
1096 if (remoteDied_ || remote_ == nullptr) {
1097 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1098 __func__, remoteDied_, remote_ == nullptr);
1099 return WIFI_OPT_FAILED;
1100 }
1101
1102 IpcIo req;
1103 char data[IPC_DATA_SIZE_SMALL];
1104 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1105
1106 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1107 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1108 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1109 return WIFI_OPT_FAILED;
1110 }
1111 (void)WriteInt32(&req, 0);
1112 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CANCEL_WPS);
1113 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CANCEL_WPS), &req, &owner,
1114 IpcCallback);
1115 if (error != EC_SUCCESS) {
1116 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1117 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_CANCEL_WPS), error);
1118 return WIFI_OPT_FAILED;
1119 }
1120
1121 if (owner.exception) {
1122 return WIFI_OPT_FAILED;
1123 }
1124 return ErrCode(owner.retCode);
1125 }
1126
IsWifiActive(bool & bActive)1127 ErrCode WifiDeviceProxy::IsWifiActive(bool &bActive)
1128 {
1129 if (remoteDied_ || remote_ == nullptr) {
1130 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1131 __func__, remoteDied_, remote_ == nullptr);
1132 return WIFI_OPT_FAILED;
1133 }
1134
1135 IpcIo req;
1136 char data[IPC_DATA_SIZE_SMALL];
1137 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1138
1139 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1140 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1141 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1142 return WIFI_OPT_FAILED;
1143 }
1144 (void)WriteInt32(&req, 0);
1145 owner.variable = &bActive;
1146 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_ACTIVE);
1147 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_ACTIVE), &req,
1148 &owner, IpcCallback);
1149 if (error != EC_SUCCESS) {
1150 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1151 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_WIFI_ACTIVE), error);
1152 return WIFI_OPT_FAILED;
1153 }
1154
1155 if (owner.exception) {
1156 return WIFI_OPT_FAILED;
1157 }
1158 return ErrCode(owner.retCode);
1159 }
1160
IsMeteredHotspot(bool & bMeteredHotspot)1161 ErrCode WifiDeviceProxy::IsMeteredHotspot(bool &bMeteredHotspot)
1162 {
1163 if (remoteDied_ || remote_ == nullptr) {
1164 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1165 __func__, remoteDied_, remote_ == nullptr);
1166 return WIFI_OPT_FAILED;
1167 }
1168
1169 IpcIo req;
1170 char data[IPC_DATA_SIZE_SMALL];
1171 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1172
1173 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1174 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1175 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1176 return WIFI_OPT_FAILED;
1177 }
1178 (void)WriteInt32(&req, 0);
1179 owner.variable = &bMeteredHotspot;
1180 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_METERED_HOTSPOT);
1181 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_METERED_HOTSPOT), &req,
1182 &owner, IpcCallback);
1183 if (error != EC_SUCCESS) {
1184 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1185 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_IS_METERED_HOTSPOT), error);
1186 return WIFI_OPT_FAILED;
1187 }
1188
1189 if (owner.exception) {
1190 return WIFI_OPT_FAILED;
1191 }
1192 return ErrCode(owner.retCode);
1193 }
1194
GetWifiState(int & state)1195 ErrCode WifiDeviceProxy::GetWifiState(int &state)
1196 {
1197 if (remoteDied_ || remote_ == nullptr) {
1198 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1199 __func__, remoteDied_, remote_ == nullptr);
1200 return WIFI_OPT_FAILED;
1201 }
1202
1203 IpcIo req;
1204 char data[IPC_DATA_SIZE_SMALL];
1205 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1206
1207 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1208 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1209 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1210 return WIFI_OPT_FAILED;
1211 }
1212 (void)WriteInt32(&req, 0);
1213 owner.variable = &state;
1214 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_STATE);
1215 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_STATE), &req,
1216 &owner, IpcCallback);
1217 if (error != EC_SUCCESS) {
1218 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1219 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_STATE), error);
1220 return WIFI_OPT_FAILED;
1221 }
1222
1223 if (owner.exception) {
1224 return WIFI_OPT_FAILED;
1225 }
1226 return ErrCode(owner.retCode);
1227 }
1228
GetLinkedInfo(WifiLinkedInfo & info)1229 ErrCode WifiDeviceProxy::GetLinkedInfo(WifiLinkedInfo &info)
1230 {
1231 if (remoteDied_ || remote_ == nullptr) {
1232 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1233 __func__, remoteDied_, remote_ == nullptr);
1234 return WIFI_OPT_FAILED;
1235 }
1236
1237 IpcIo req;
1238 char data[IPC_DATA_SIZE_SMALL];
1239 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1240
1241 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1242 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1243 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1244 return WIFI_OPT_FAILED;
1245 }
1246 (void)WriteInt32(&req, 0);
1247 owner.variable = &info;
1248 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_LINKED_INFO);
1249 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_LINKED_INFO), &req,
1250 &owner, IpcCallback);
1251 if (error != EC_SUCCESS) {
1252 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1253 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_LINKED_INFO), error);
1254 return WIFI_OPT_FAILED;
1255 }
1256
1257 if (owner.exception) {
1258 return WIFI_OPT_FAILED;
1259 }
1260 return ErrCode(owner.retCode);
1261 }
1262
GetIpInfo(IpInfo & info)1263 ErrCode WifiDeviceProxy::GetIpInfo(IpInfo &info)
1264 {
1265 if (remoteDied_ || remote_ == nullptr) {
1266 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1267 __func__, remoteDied_, remote_ == nullptr);
1268 return WIFI_OPT_FAILED;
1269 }
1270
1271 IpcIo req;
1272 char data[IPC_DATA_SIZE_SMALL];
1273 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1274
1275 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1276 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1277 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1278 return WIFI_OPT_FAILED;
1279 }
1280 (void)WriteInt32(&req, 0);
1281 owner.variable = &info;
1282 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_INFO);
1283 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_INFO), &req,
1284 &owner, IpcCallback);
1285 if (error != EC_SUCCESS) {
1286 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1287 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_INFO), error);
1288 return WIFI_OPT_FAILED;
1289 }
1290
1291 if (owner.exception) {
1292 return WIFI_OPT_FAILED;
1293 }
1294 return ErrCode(owner.retCode);
1295 }
1296
GetIpv6Info(IpV6Info & info)1297 ErrCode WifiDeviceProxy::GetIpv6Info(IpV6Info &info)
1298 {
1299 if (remoteDied_ || remote_ == nullptr) {
1300 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1301 __func__, remoteDied_, remote_ == nullptr);
1302 return WIFI_OPT_FAILED;
1303 }
1304
1305 IpcIo req;
1306 char data[IPC_DATA_SIZE_SMALL];
1307 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1308
1309 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1310 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1311 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1312 return WIFI_OPT_FAILED;
1313 }
1314 (void)WriteInt32(&req, 0);
1315 owner.variable = &info;
1316 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_IPV6INFO);
1317 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_IPV6INFO), &req,
1318 &owner, IpcCallback);
1319 if (error != EC_SUCCESS) {
1320 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1321 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DHCP_IPV6INFO), error);
1322 return WIFI_OPT_FAILED;
1323 }
1324
1325 if (owner.exception) {
1326 return WIFI_OPT_FAILED;
1327 }
1328 return ErrCode(owner.retCode);
1329 }
1330
SetCountryCode(const std::string & countryCode)1331 ErrCode WifiDeviceProxy::SetCountryCode(const std::string &countryCode)
1332 {
1333 if (remoteDied_ || remote_ == nullptr) {
1334 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1335 __func__, remoteDied_, remote_ == nullptr);
1336 return WIFI_OPT_FAILED;
1337 }
1338
1339 IpcIo req;
1340 char data[IPC_DATA_SIZE_SMALL];
1341 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1342
1343 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1344 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1345 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1346 return WIFI_OPT_FAILED;
1347 }
1348 (void)WriteInt32(&req, 0);
1349 (void)WriteString(&req, countryCode.c_str());
1350 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_COUNTRY_CODE);
1351 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_COUNTRY_CODE), &req,
1352 &owner, IpcCallback);
1353 if (error != EC_SUCCESS) {
1354 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1355 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_COUNTRY_CODE), error);
1356 return WIFI_OPT_FAILED;
1357 }
1358
1359 if (owner.exception) {
1360 return WIFI_OPT_FAILED;
1361 }
1362 return ErrCode(owner.retCode);
1363 }
1364
GetCountryCode(std::string & countryCode)1365 ErrCode WifiDeviceProxy::GetCountryCode(std::string &countryCode)
1366 {
1367 if (remoteDied_ || remote_ == nullptr) {
1368 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1369 __func__, remoteDied_, remote_ == nullptr);
1370 return WIFI_OPT_FAILED;
1371 }
1372
1373 IpcIo req;
1374 char data[IPC_DATA_SIZE_SMALL];
1375 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1376
1377 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1378 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1379 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1380 return WIFI_OPT_FAILED;
1381 }
1382 (void)WriteInt32(&req, 0);
1383 owner.variable = &countryCode;
1384 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_COUNTRY_CODE);
1385 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_COUNTRY_CODE), &req,
1386 &owner, IpcCallback);
1387 if (error != EC_SUCCESS) {
1388 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1389 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_COUNTRY_CODE), error);
1390 return WIFI_OPT_FAILED;
1391 }
1392
1393 if (owner.exception) {
1394 return WIFI_OPT_FAILED;
1395 }
1396 return ErrCode(owner.retCode);
1397 }
1398
RegisterCallBack(const std::shared_ptr<IWifiDeviceCallBack> & callback,const std::vector<std::string> & event)1399 ErrCode WifiDeviceProxy::RegisterCallBack(const std::shared_ptr<IWifiDeviceCallBack> &callback,
1400 const std::vector<std::string> &event)
1401 {
1402 if (remoteDied_ || remote_ == nullptr) {
1403 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1404 __func__, remoteDied_, remote_ == nullptr);
1405 return WIFI_OPT_FAILED;
1406 }
1407 WIFI_LOGD("RegisterCallBack start!");
1408 g_objStub.func = AsyncCallback;
1409 g_objStub.args = nullptr;
1410 g_objStub.isRemote = false;
1411
1412 g_sid.handle = IPC_INVALID_HANDLE;
1413 g_sid.token = SERVICE_TYPE_ANONYMOUS;
1414 g_sid.cookie = (uintptr_t)&g_objStub;
1415
1416 IpcIo req;
1417 char data[IPC_DATA_SIZE_SMALL];
1418 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1419
1420 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1421 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1422 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1423 return WIFI_OPT_FAILED;
1424 }
1425 (void)WriteInt32(&req, 0);
1426 bool writeRemote = WriteRemoteObject(&req, &g_sid);
1427 if (!writeRemote) {
1428 WIFI_LOGE("WriteRemoteObject failed.");
1429 return WIFI_OPT_FAILED;
1430 }
1431 int eventNum = event.size();
1432 (void)WriteInt32(&req, eventNum);
1433 if (eventNum > 0) {
1434 for (auto &eventName : event) {
1435 (void)WriteString(&req, eventName.c_str());
1436 }
1437 }
1438 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REGISTER_CALLBACK_CLIENT);
1439 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REGISTER_CALLBACK_CLIENT),
1440 &req, &owner, IpcCallback);
1441 if (error != EC_SUCCESS) {
1442 WIFI_LOGE("Set Attr(%{public}d) failed, code is %{public}d",
1443 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_REGISTER_CALLBACK_CLIENT), error);
1444 return WIFI_OPT_FAILED;
1445 }
1446
1447 if (owner.exception) {
1448 return WIFI_OPT_FAILED;
1449 }
1450 g_deviceCallBackStub.RegisterUserCallBack(callback);
1451 return ErrCode(owner.retCode);
1452 }
1453
GetSignalLevel(const int & rssi,const int & band,int & level)1454 ErrCode WifiDeviceProxy::GetSignalLevel(const int &rssi, const int &band, int &level)
1455 {
1456 if (remoteDied_ || remote_ == nullptr) {
1457 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1458 __func__, remoteDied_, remote_ == nullptr);
1459 return WIFI_OPT_FAILED;
1460 }
1461
1462 IpcIo req;
1463 char data[IPC_DATA_SIZE_SMALL];
1464 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1465
1466 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1467 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1468 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1469 return WIFI_OPT_FAILED;
1470 }
1471 (void)WriteInt32(&req, 0);
1472 (void)WriteInt32(&req, rssi);
1473 (void)WriteInt32(&req, band);
1474 owner.variable = &level;
1475 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SIGNAL_LEVEL);
1476 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SIGNAL_LEVEL), &req,
1477 &owner, IpcCallback);
1478 if (error != EC_SUCCESS) {
1479 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1480 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SIGNAL_LEVEL), error);
1481 return WIFI_OPT_FAILED;
1482 }
1483
1484 if (owner.exception) {
1485 return WIFI_OPT_FAILED;
1486 }
1487 return ErrCode(owner.retCode);
1488 }
1489
GetSupportedFeatures(long & features)1490 ErrCode WifiDeviceProxy::GetSupportedFeatures(long &features)
1491 {
1492 if (remoteDied_ || remote_ == nullptr) {
1493 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1494 __func__, remoteDied_, remote_ == nullptr);
1495 return WIFI_OPT_FAILED;
1496 }
1497
1498 IpcIo req;
1499 char data[IPC_DATA_SIZE_SMALL];
1500 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1501
1502 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1503 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1504 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1505 return WIFI_OPT_FAILED;
1506 }
1507 (void)WriteInt32(&req, 0);
1508 owner.variable = &features;
1509 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES);
1510 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES),
1511 &req, &owner, IpcCallback);
1512 if (error != EC_SUCCESS) {
1513 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1514 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_SUPPORTED_FEATURES), error);
1515 return WIFI_OPT_FAILED;
1516 }
1517
1518 if (owner.exception) {
1519 return WIFI_OPT_FAILED;
1520 }
1521 return ErrCode(owner.retCode);
1522 }
1523
GetDeviceMacAddress(std::string & result)1524 ErrCode WifiDeviceProxy::GetDeviceMacAddress(std::string &result)
1525 {
1526 if (remoteDied_ || remote_ == nullptr) {
1527 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1528 __func__, remoteDied_, remote_ == nullptr);
1529 return WIFI_OPT_FAILED;
1530 }
1531
1532 IpcIo req;
1533 char data[IPC_DATA_SIZE_SMALL];
1534 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1535
1536 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1537 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1538 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1539 return WIFI_OPT_FAILED;
1540 }
1541 (void)WriteInt32(&req, 0);
1542 owner.variable = &result;
1543 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DERVICE_MAC_ADD);
1544 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DERVICE_MAC_ADD), &req,
1545 &owner, IpcCallback);
1546 if (error != EC_SUCCESS) {
1547 WIFI_LOGE("Set Attr(%{public}d) failed",
1548 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_DERVICE_MAC_ADD));
1549 return WIFI_OPT_FAILED;
1550 }
1551
1552 if (owner.exception) {
1553 return WIFI_OPT_FAILED;
1554 }
1555 return ErrCode(owner.retCode);
1556 }
1557
SetLowLatencyMode(bool enabled)1558 bool WifiDeviceProxy::SetLowLatencyMode(bool enabled)
1559 {
1560 if (remoteDied_ || remote_ == nullptr) {
1561 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1562 __func__, remoteDied_, remote_ == nullptr);
1563 return WIFI_OPT_FAILED;
1564 }
1565
1566 bool result = false;
1567 IpcIo req;
1568 char data[IPC_DATA_SIZE_SMALL];
1569 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1570
1571 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1572 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1573 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1574 return WIFI_OPT_FAILED;
1575 }
1576 (void)WriteInt32(&req, 0);
1577 (void)WriteBool(&req, enabled);
1578 owner.variable = &result;
1579 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_LATENCY_MODE);
1580 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_LATENCY_MODE),
1581 &req, &owner, IpcCallback);
1582 if (error != EC_SUCCESS) {
1583 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1584 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_SET_LOW_LATENCY_MODE), error);
1585 return WIFI_OPT_FAILED;
1586 }
1587
1588 if (owner.exception) {
1589 return WIFI_OPT_FAILED;
1590 }
1591 return result;
1592 }
1593
OnRemoteDied(void)1594 void WifiDeviceProxy::OnRemoteDied(void)
1595 {
1596 WIFI_LOGW("Remote service is died!");
1597 remoteDied_ = true;
1598 g_deviceCallBackStub.SetRemoteDied(true);
1599 }
IsBandTypeSupported(int bandType,bool & supported)1600 ErrCode WifiDeviceProxy::IsBandTypeSupported(int bandType, bool &supported)
1601 {
1602 if (remoteDied_ || remote_ == nullptr) {
1603 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1604 __func__, remoteDied_, remote_ == nullptr);
1605 return WIFI_OPT_FAILED;
1606 }
1607
1608 IpcIo req;
1609 char data[IPC_DATA_SIZE_SMALL];
1610 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1611
1612 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1613 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1614 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1615 return WIFI_OPT_FAILED;
1616 }
1617 (void)WriteInt32(&req, 0);
1618 (void)WriteInt32(&req, bandType);
1619 owner.variable = &supported;
1620 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_BANDTYPE_SUPPORTED);
1621 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_BANDTYPE_SUPPORTED),
1622 &req, &owner, IpcCallback);
1623 if (error != EC_SUCCESS) {
1624 WIFI_LOGE("IsBandTypeSupported (%{public}d) failed,error code is %{public}d",
1625 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_BANDTYPE_SUPPORTED), error);
1626 return WIFI_OPT_FAILED;
1627 }
1628
1629 if (owner.exception) {
1630 return WIFI_OPT_FAILED;
1631 }
1632
1633 return ErrCode(owner.retCode);
1634 }
1635
Get5GHzChannelList(std::vector<int> & result)1636 ErrCode WifiDeviceProxy::Get5GHzChannelList(std::vector<int> &result)
1637 {
1638 if (remoteDied_ || remote_ == nullptr) {
1639 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1640 __func__, remoteDied_, remote_ == nullptr);
1641 return WIFI_OPT_FAILED;
1642 }
1643
1644 IpcIo req;
1645 char data[IPC_DATA_SIZE_SMALL];
1646 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1647
1648 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1649 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1650 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1651 return WIFI_OPT_FAILED;
1652 }
1653 (void)WriteInt32(&req, 0);
1654 owner.variable = &result;
1655 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_5G_CHANNELLIST);
1656 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_5G_CHANNELLIST), &req,
1657 &owner, IpcCallback);
1658 if (error != EC_SUCCESS) {
1659 WIFI_LOGE("Get5GHzChannelList(%{public}d) failed,error code is %{public}d",
1660 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_5G_CHANNELLIST), error);
1661 return WIFI_OPT_FAILED;
1662 }
1663
1664 if (owner.exception) {
1665 return WIFI_OPT_FAILED;
1666 }
1667
1668 return ErrCode(owner.retCode);
1669 }
1670
EnableSemiWifi()1671 ErrCode WifiDeviceProxy::EnableSemiWifi()
1672 {
1673 if (remoteDied_ || remote_ == nullptr) {
1674 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1675 __func__, remoteDied_, remote_ == nullptr);
1676 return WIFI_OPT_FAILED;
1677 }
1678
1679 IpcIo req;
1680 char data[IPC_DATA_SIZE_SMALL];
1681 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1682
1683 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1684 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1685 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1686 return WIFI_OPT_FAILED;
1687 }
1688 (void)WriteInt32(&req, 0);
1689 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_SEMI_WIFI);
1690 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_SEMI_WIFI), &req,
1691 &owner, IpcCallback);
1692 if (error != EC_SUCCESS) {
1693 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1694 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_ENABLE_SEMI_WIFI), error);
1695 return WIFI_OPT_FAILED;
1696 }
1697
1698 if (owner.exception) {
1699 return WIFI_OPT_FAILED;
1700 }
1701 return ErrCode(owner.retCode);
1702 }
1703
GetWifiDetailState(WifiDetailState & state)1704 ErrCode WifiDeviceProxy::GetWifiDetailState(WifiDetailState &state)
1705 {
1706 if (remoteDied_ || remote_ == nullptr) {
1707 WIFI_LOGE("failed to %{public}s, remoteDied_: %{public}d, remote_: %{public}d",
1708 __func__, remoteDied_, remote_ == nullptr);
1709 return WIFI_OPT_FAILED;
1710 }
1711
1712 IpcIo req;
1713 char data[IPC_DATA_SIZE_SMALL];
1714 struct IpcOwner owner = {.exception = -1, .retCode = 0, .variable = nullptr};
1715
1716 IpcIoInit(&req, data, IPC_DATA_SIZE_SMALL, MAX_IPC_OBJ_COUNT);
1717 if (!WriteInterfaceToken(&req, DECLARE_INTERFACE_DESCRIPTOR_L1, DECLARE_INTERFACE_DESCRIPTOR_L1_LENGTH)) {
1718 WIFI_LOGE("Write interface token error: %{public}s", __func__);
1719 return WIFI_OPT_FAILED;
1720 }
1721 (void)WriteInt32(&req, 0);
1722 owner.variable = &state;
1723 owner.funcId = static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_DETAIL_STATE);
1724 int error = remote_->Invoke(remote_, static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_DETAIL_STATE),
1725 &req, &owner, IpcCallback);
1726 if (error != EC_SUCCESS) {
1727 WIFI_LOGE("Set Attr(%{public}d) failed,error code is %{public}d",
1728 static_cast<int32_t>(DevInterfaceCode::WIFI_SVR_CMD_GET_WIFI_DETAIL_STATE), error);
1729 return WIFI_OPT_FAILED;
1730 }
1731
1732 if (owner.exception) {
1733 return WIFI_OPT_FAILED;
1734 }
1735 return ErrCode(owner.retCode);
1736 }
1737
1738 } // namespace Wifi
1739 } // namespace OHOS
1740