1 /*
2 * Copyright (c) 2021 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 "wlan_hal_proxy.h"
17 #include "Iwifi_hal.h"
18 #include "wlan_hdi_service_stub.h"
19 #include "iservmgr_hdi.h"
20 #include "securec.h"
21 #include "hdf_log.h"
22 #include <osal_mem.h>
23 #include <message_parcel.h>
24 #include <cstring>
25
26 using namespace OHOS;
27 using namespace OHOS::HDI::WLAN::V1_0;
28 using namespace std;
29 #define ETH_ADDR_LEN 6
30
31 std::function<int32_t(int32_t event, struct HdfSBuf *sbuf)> WlanInterfaceProxy::callback_ = nullptr;
32
Get(const std::string & serviceName)33 sptr<IWlan> IWlan::Get(const std::string& serviceName)
34 {
35 do {
36 using namespace OHOS::HDI::ServiceManager::V1_0;
37 auto servMgr = IServiceManager::Get();
38 if (servMgr == nullptr) {
39 break;
40 }
41 sptr<IRemoteObject> remote = servMgr->GetService(serviceName.c_str());
42 if (remote != nullptr) {
43 return iface_cast<IWlan>(remote);
44 }
45 } while (false);
46 HDF_LOGE("%s: get DataWlanService failed!", __func__);
47 return nullptr;
48 }
49
wifiConstruct()50 int32_t WlanInterfaceProxy::wifiConstruct()
51 {
52 MessageParcel data;
53 MessageParcel reply;
54 MessageOption option;
55
56 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor())) {
57 return HDF_ERR_INVALID_PARAM;
58 }
59 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_CONSTRUCT, data, reply, option);
60 if (ret != HDF_SUCCESS) {
61 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
62 }
63 return ret;
64 }
65
wifiDestruct()66 int32_t WlanInterfaceProxy::wifiDestruct()
67 {
68 MessageParcel data;
69 MessageParcel reply;
70 MessageOption option;
71
72 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor())) {
73 return HDF_ERR_INVALID_PARAM;
74 }
75 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_DECONSTRUCT, data, reply, option);
76 if (ret != HDF_SUCCESS) {
77 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
78 }
79 return ret;
80 }
81
start()82 int32_t WlanInterfaceProxy::start()
83 {
84 MessageParcel data;
85 MessageParcel reply;
86 MessageOption option;
87
88 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor())) {
89 return HDF_ERR_INVALID_PARAM;
90 }
91 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_START, data, reply, option);
92 if (ret != HDF_SUCCESS) {
93 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
94 }
95 return ret;
96 }
97
stop()98 int32_t WlanInterfaceProxy::stop()
99 {
100 MessageParcel data;
101 MessageParcel reply;
102 MessageOption option;
103
104 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor())) {
105 return HDF_ERR_INVALID_PARAM;
106 }
107 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_STOP, data, reply, option);
108 if (ret != HDF_SUCCESS) {
109 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
110 }
111 return ret;
112 }
113
createFeature(int32_t type,std::shared_ptr<WifiFeatureInfo> & ifeature)114 int32_t WlanInterfaceProxy::createFeature(int32_t type, std::shared_ptr<WifiFeatureInfo>& ifeature)
115 {
116 MessageParcel data;
117 MessageParcel reply;
118 MessageOption option;
119
120 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
121 !data.WriteInt32(type)) {
122 HDF_LOGE("%s: write type failed!", __func__);
123 return HDF_ERR_INVALID_PARAM;
124 }
125 ifeature = std::make_shared<WifiFeatureInfo>();
126 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_CREATE_FEATURE, data, reply, option);
127 if (ret != HDF_SUCCESS) {
128 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
129 }
130 char *name = (char *)reply.ReadCString();
131 ifeature->ifName = strdup(name);
132 int32_t wlan_type = reply.ReadInt32();
133 ifeature->type = wlan_type;
134 return ret;
135 }
136
getSupportFeature(std::vector<uint8_t> & supType)137 int32_t WlanInterfaceProxy::getSupportFeature(std::vector<uint8_t>& supType)
138 {
139 MessageParcel data;
140 MessageParcel reply;
141 MessageOption option;
142
143 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor())) {
144 return HDF_ERR_INVALID_PARAM;
145 }
146 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_GET_SUPPORT_FEATURE, data, reply, option);
147 if (ret != HDF_SUCCESS) {
148 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
149 }
150 uint32_t size = reply.ReadUint32();
151 uint8_t *supTypeCp = (uint8_t *)reply.ReadUnpadBuffer(size);
152 supType.assign(supTypeCp, supTypeCp + size);
153 return ret;
154 }
155
getSupportCombo(std::vector<uint64_t> & combo)156 int32_t WlanInterfaceProxy::getSupportCombo(std::vector<uint64_t>& combo)
157 {
158 MessageParcel data;
159 MessageParcel reply;
160 MessageOption option;
161
162 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor())) {
163 return HDF_ERR_INVALID_PARAM;
164 }
165 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_GET_SUPPORT_COMBO, data, reply, option);
166 if (ret == HDF_ERR_NOT_SUPPORT) {
167 HDF_LOGW("%s: not support to getting combo!", __func__);
168 return HDF_ERR_NOT_SUPPORT;
169 } else if (ret == HDF_SUCCESS) {
170 for (int i = 0; i < ETH_ADDR_LEN; i++) {
171 combo.push_back(reply.ReadUint64());
172 }
173 }
174 return ret;
175 }
176
getFeatureByIfName(std::string & ifName,std::shared_ptr<WifiFeatureInfo> & ifeature)177 int32_t WlanInterfaceProxy::getFeatureByIfName(std::string& ifName, std::shared_ptr<WifiFeatureInfo>& ifeature)
178 {
179 MessageParcel data;
180 MessageParcel reply;
181 MessageOption option;
182
183 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
184 !data.WriteCString(ifName.c_str())) {
185 HDF_LOGE("%s: write ifname failed!", __func__);
186 return HDF_ERR_INVALID_PARAM;
187 }
188 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_GET_FEATURE_NAME, data, reply, option);
189 if (ret != HDF_SUCCESS) {
190 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
191 }
192 int32_t wlan_type = reply.ReadInt32();
193 ifeature->type = wlan_type;
194 return ret;
195 }
196
CallbackWlanProxy(int32_t event,struct HdfSBuf * reqData)197 int32_t WlanInterfaceProxy::CallbackWlanProxy(int32_t event, struct HdfSBuf *reqData)
198 {
199 HDF_LOGI("%s: enter", __func__);
200 if (reqData == NULL) {
201 HDF_LOGE("%s: ptr NULL", __func__);
202 return HDF_ERR_INVALID_PARAM;
203 }
204 callback_(event, reqData);
205 return HDF_SUCCESS;
206 }
207
OnRemoteRequest(uint32_t code,OHOS::MessageParcel & data,OHOS::MessageParcel & reply,OHOS::MessageOption & option)208 int IPCObjectStubWlan::OnRemoteRequest(uint32_t code, OHOS::MessageParcel &data,
209 OHOS::MessageParcel &reply, OHOS::MessageOption &option)
210 {
211 int32_t ret = 0;
212 int32_t status = -1;
213
214 HDF_LOGI("IPCObjectStubWlan::OnRemoteRequest called, code = %d", code);
215 struct HdfSBuf *dataSbuf = HdfSbufTypedObtain(SBUF_IPC);
216 if (dataSbuf == NULL) {
217 HDF_LOGE("%s: dataSbuf malloc failed!", __func__);
218 HdfSbufRecycle(dataSbuf);
219 }
220 switch (code) {
221 case WIFI_EVENT_RESET_DRIVER: {
222 const char *name = data.ReadCString();
223 HDF_LOGI("IPCObjectStubWlan::OnRemoteRequest called, ifName = %{public}s", name);
224 status = data.ReadInt32();
225 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
226 !data.WriteInt32(status)) {
227 HDF_LOGE("%s: write status failed!", __func__);
228 }
229 ret = WlanInterfaceProxy::CallbackWlanProxy((int32_t)code, dataSbuf);
230 if (ret != 0) {
231 HDF_LOGE("%s: failed, error code is %d", __func__, ret);
232 }
233 break;
234 }
235 default:
236 HDF_LOGE("%s: unknown code:%d", __func__, code);
237 ret = HDF_FAILURE;
238 break;
239 }
240 HdfSbufRecycle(dataSbuf);
241 return ret;
242 }
243
registerEventCallback(std::function<int32_t (int32_t event,struct HdfSBuf * sbuf)> cb)244 int32_t WlanInterfaceProxy::registerEventCallback(std::function<int32_t(int32_t event, struct HdfSBuf *sbuf)> cb)
245 {
246 sptr<IPCObjectStub> callback = new IPCObjectStubWlan();
247 OHOS::MessageParcel data;
248 OHOS::MessageParcel reply;
249 OHOS::MessageOption option;
250
251 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor())) {
252 return HDF_ERR_INVALID_PARAM;
253 }
254 int32_t ret = data.WriteRemoteObject(callback);
255 if (!ret) {
256 HDF_LOGE("%s: set callback write remote obj failed!", __func__);
257 return HDF_FAILURE;
258 }
259 ret = Remote()->SendRequest(WLAN_SERVICE_REGISTER_CALLBACK, data, reply, option);
260 if (ret != HDF_SUCCESS) {
261 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
262 }
263 callback_ = cb;
264 return ret;
265 }
266
unregisterEventCallback()267 int32_t WlanInterfaceProxy::unregisterEventCallback()
268 {
269 MessageParcel data;
270 MessageParcel reply;
271 MessageOption option;
272
273 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor())) {
274 return HDF_ERR_INVALID_PARAM;
275 }
276 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_UNREGISTER_CALLBACK, data, reply, option);
277 if (ret != HDF_SUCCESS) {
278 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
279 }
280 return ret;
281 }
282
destroyFeature(std::shared_ptr<WifiFeatureInfo> ifeature)283 int32_t WlanInterfaceProxy::destroyFeature(std::shared_ptr<WifiFeatureInfo> ifeature)
284 {
285 MessageParcel data;
286 MessageParcel reply;
287 MessageOption option;
288
289 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
290 !data.WriteCString(ifeature->ifName)) {
291 HDF_LOGE("%s: write ifname failed!", __func__);
292 return HDF_ERR_INVALID_PARAM;
293 }
294 if (!data.WriteInt32(ifeature->type)) {
295 HDF_LOGE("%s: write type failed!", __func__);
296 return HDF_ERR_INVALID_PARAM;
297 }
298 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_DESTROY_FEATURE, data, reply, option);
299 if (ret != HDF_SUCCESS) {
300 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
301 }
302 if (ifeature->ifName != NULL) {
303 free(ifeature->ifName);
304 }
305 return ret;
306 }
307
resetDriver(const uint8_t chipId)308 int32_t WlanInterfaceProxy::resetDriver(const uint8_t chipId)
309 {
310 MessageParcel data;
311 MessageParcel reply;
312 MessageOption option;
313
314 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
315 !data.WriteUint8(chipId)) {
316 HDF_LOGE("%s: write chipid failed!", __func__);
317 return HDF_ERR_INVALID_PARAM;
318 }
319 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_RESET_DRIVER, data, reply, option);
320 if (ret != HDF_SUCCESS) {
321 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
322 }
323 return ret;
324 }
325
getAsscociatedStas(std::shared_ptr<WifiFeatureInfo> ifeature,std::shared_ptr<StaInfo> staInfo,uint32_t count,std::vector<uint32_t> & num)326 int32_t WlanInterfaceProxy::getAsscociatedStas(std::shared_ptr<WifiFeatureInfo> ifeature,
327 std::shared_ptr<StaInfo> staInfo, uint32_t count, std::vector<uint32_t>& num)
328 {
329 MessageParcel data;
330 MessageParcel reply;
331 MessageOption option;
332
333 HDF_LOGI("%s: enter GetAsscociatedStas", __func__);
334 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
335 !data.WriteCString(ifeature->ifName)) {
336 HDF_LOGE("%s: write ifname failed!", __func__);
337 return HDF_ERR_INVALID_PARAM;
338 }
339 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_GET_ASSCOCIATE_STA, data, reply, option);
340 if (ret != HDF_SUCCESS) {
341 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
342 }
343 count = reply.ReadUint32();
344 return ret;
345 }
346
setCountryCode(std::shared_ptr<WifiFeatureInfo> ifeature,std::string & code,uint32_t len)347 int32_t WlanInterfaceProxy::setCountryCode(std::shared_ptr<WifiFeatureInfo> ifeature, std::string& code, uint32_t len)
348 {
349 MessageParcel data;
350 MessageParcel reply;
351 MessageOption option;
352
353 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
354 !data.WriteCString(ifeature->ifName)) {
355 HDF_LOGE("%s: write ifname failed!", __func__);
356 return HDF_ERR_INVALID_PARAM;
357 }
358 if (!data.WriteCString(code.c_str())) {
359 HDF_LOGE("%s: write code failed!", __func__);
360 return HDF_ERR_INVALID_PARAM;
361 }
362 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_SET_COUNTRY_CODE, data, reply, option);
363 if (ret != HDF_SUCCESS) {
364 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
365 }
366 return ret;
367 }
368
getNetworkIfaceName(std::shared_ptr<WifiFeatureInfo> ifeature)369 int32_t WlanInterfaceProxy::getNetworkIfaceName(std::shared_ptr<WifiFeatureInfo> ifeature)
370 {
371 MessageParcel data;
372 MessageParcel reply;
373 MessageOption option;
374
375 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
376 !data.WriteCString(ifeature->ifName)) {
377 HDF_LOGE("%s: write ifname failed!", __func__);
378 return HDF_ERR_INVALID_PARAM;
379 }
380 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_GET_NETWORK_NAME, data, reply, option);
381 if (ret != HDF_SUCCESS) {
382 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
383 }
384 char *name = (char *)reply.ReadCString();
385 ifeature->ifName = name;
386 return ret;
387 }
388
getFeatureType(std::shared_ptr<WifiFeatureInfo> ifeature)389 int32_t WlanInterfaceProxy::getFeatureType(std::shared_ptr<WifiFeatureInfo> ifeature)
390 {
391 MessageParcel data;
392 MessageParcel reply;
393 MessageOption option;
394
395 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
396 !data.WriteInt32(ifeature->type)) {
397 HDF_LOGE("%s: write type failed!", __func__);
398 return HDF_ERR_INVALID_PARAM;
399 }
400 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_GET_FEATURE_TYPE, data, reply, option);
401 if (ret != HDF_SUCCESS) {
402 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
403 }
404 int32_t wifi_type = reply.ReadInt32();
405 ifeature->type = wifi_type;
406 return ret;
407 }
408
setMacAddress(std::shared_ptr<WifiFeatureInfo> ifeature,std::vector<uint8_t> & mac)409 int32_t WlanInterfaceProxy::setMacAddress(std::shared_ptr<WifiFeatureInfo> ifeature, std::vector<uint8_t>& mac)
410 {
411 MessageParcel data;
412 MessageParcel reply;
413 MessageOption option;
414
415 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
416 !data.WriteCString(ifeature->ifName)) {
417 HDF_LOGE("%s: write ifname failed!", __func__);
418 return HDF_ERR_INVALID_PARAM;
419 }
420 for (uint8_t i = 0; i < mac.size(); i++) {
421 if (!data.WriteUint8(mac[i])) {
422 HDF_LOGE("%s: write mac failed!", __func__);
423 }
424 }
425 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_SET_MAC_ADDR, data, reply, option);
426 if (ret != HDF_SUCCESS) {
427 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
428 }
429 return ret;
430 }
431
getDeviceMacAddress(std::shared_ptr<WifiFeatureInfo> ifeature,std::vector<uint8_t> & mac,uint8_t len)432 int32_t WlanInterfaceProxy::getDeviceMacAddress(std::shared_ptr<WifiFeatureInfo> ifeature, std::vector<uint8_t>& mac,
433 uint8_t len)
434 {
435 MessageParcel data;
436 MessageParcel reply;
437 MessageOption option;
438
439 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
440 !data.WriteCString(ifeature->ifName)) {
441 HDF_LOGE("%s: write ifname failed!", __func__);
442 return HDF_ERR_INVALID_PARAM;
443 }
444 if (!data.WriteInt32(ifeature->type)) {
445 HDF_LOGE("%s: write type failed!", __func__);
446 return HDF_ERR_INVALID_PARAM;
447 }
448 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_GET_MAC_ADDR, data, reply, option);
449 if (ret != HDF_SUCCESS) {
450 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
451 }
452 uint8_t *macBuff = (uint8_t *)reply.ReadUnpadBuffer(len);
453 mac.assign(macBuff, macBuff + len);
454 return ret;
455 }
456
getFreqsWithBand(std::shared_ptr<WifiFeatureInfo> ifeature,int32_t band,std::vector<int32_t> freq,uint32_t count,uint32_t & num)457 int32_t WlanInterfaceProxy::getFreqsWithBand(std::shared_ptr<WifiFeatureInfo> ifeature, int32_t band,
458 std::vector<int32_t> freq, uint32_t count, uint32_t& num)
459 {
460 MessageParcel data;
461 MessageParcel reply;
462 MessageOption option;
463
464 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
465 !data.WriteCString(ifeature->ifName)) {
466 HDF_LOGE("%s: write ifname failed!", __func__);
467 return HDF_ERR_INVALID_PARAM;
468 }
469 if (!data.WriteInt32(band)) {
470 HDF_LOGE("%s: write ifname failed!", __func__);
471 return HDF_ERR_INVALID_PARAM;
472 }
473 if (!data.WriteInt32(count)) {
474 HDF_LOGE("%s: write ifname failed!", __func__);
475 return HDF_ERR_INVALID_PARAM;
476 }
477 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_GET_FREQ_WITHBAND, data, reply, option);
478 if (ret != HDF_SUCCESS) {
479 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
480 }
481 num = reply.ReadUint32();
482 for (uint32_t i = 0; i < num; i++) {
483 freq.push_back(reply.ReadInt32());
484 HDF_LOGI("%s: freqs[%d] is %d", __func__, i, freq[i]);
485 }
486 return ret;
487 }
488
setTxPower(std::shared_ptr<WifiFeatureInfo> ifeature,int32_t power)489 int32_t WlanInterfaceProxy::setTxPower(std::shared_ptr<WifiFeatureInfo> ifeature, int32_t power)
490 {
491 MessageParcel data;
492 MessageParcel reply;
493 MessageOption option;
494
495 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
496 !data.WriteCString(ifeature->ifName)) {
497 HDF_LOGE("%s: write ifname failed!", __func__);
498 return HDF_ERR_INVALID_PARAM;
499 }
500 if (!data.WriteInt32(power)) {
501 HDF_LOGE("%s: write power failed!", __func__);
502 return HDF_ERR_INVALID_PARAM;
503 }
504 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_SET_TX_POWR, data, reply, option);
505 if (ret != HDF_SUCCESS) {
506 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
507 }
508 return ret;
509 }
510
getChipId(std::shared_ptr<WifiFeatureInfo> ifeature,uint8_t & chipId)511 int32_t WlanInterfaceProxy::getChipId(std::shared_ptr<WifiFeatureInfo> ifeature, uint8_t& chipId)
512 {
513 MessageParcel data;
514 MessageParcel reply;
515 MessageOption option;
516
517 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
518 !data.WriteCString(ifeature->ifName)) {
519 HDF_LOGE("%s: write ifname failed!", __func__);
520 return HDF_ERR_INVALID_PARAM;
521 }
522 if (!data.WriteInt32(ifeature->type)) {
523 HDF_LOGE("%s: write type failed!", __func__);
524 return HDF_ERR_INVALID_PARAM;
525 }
526 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_GET_CHIPID, data, reply, option);
527 if (ret != HDF_SUCCESS) {
528 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
529 }
530 chipId = reply.ReadUint8();
531 return ret;
532 }
533
getIfNamesByChipId(const uint8_t chipId,std::string & ifNames,uint32_t & num)534 int32_t WlanInterfaceProxy::getIfNamesByChipId(const uint8_t chipId, std::string& ifNames, uint32_t& num)
535 {
536 MessageParcel data;
537 MessageParcel reply;
538 MessageOption option;
539 char *name = NULL;
540
541 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
542 !data.WriteUint8(chipId)) {
543 HDF_LOGE("%s: write chipid failed!", __func__);
544 return HDF_ERR_INVALID_PARAM;
545 }
546 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_GET_NAME_BYCHIPID, data, reply, option);
547 if (ret != HDF_SUCCESS) {
548 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
549 }
550 name = (char *)reply.ReadCString();
551 num = reply.ReadUint32();
552 ifNames = name;
553 return ret;
554 }
555
setScanningMacAddress(std::shared_ptr<WifiFeatureInfo> ifeature,std::vector<uint8_t> & scanMac,uint8_t len)556 int32_t WlanInterfaceProxy::setScanningMacAddress(std::shared_ptr<WifiFeatureInfo> ifeature,
557 std::vector<uint8_t>& scanMac, uint8_t len)
558 {
559 MessageParcel data;
560 MessageParcel reply;
561 MessageOption option;
562
563 if (!data.WriteInterfaceToken(WlanInterfaceProxy::GetDescriptor()) ||
564 !data.WriteCString(ifeature->ifName)) {
565 HDF_LOGE("%s: write ifname failed!", __func__);
566 return HDF_ERR_INVALID_PARAM;
567 }
568 if (!data.WriteUint8(len)) {
569 HDF_LOGE("%s: write len failed!", __func__);
570 return HDF_ERR_INVALID_PARAM;
571 }
572 for (int i = 0; i < ETH_ADDR_LEN; i++) {
573 if (!data.WriteUint8(scanMac[i])) {
574 HDF_LOGE("%s: write scanMac failed!", __func__);
575 }
576 HDF_LOGE("%s: mac addr is %x!", __func__, scanMac[i]);
577 }
578 int32_t ret = Remote()->SendRequest(WLAN_SERVICE_SET_SACN_MACADDR, data, reply, option);
579 if (ret != HDF_ERR_NOT_SUPPORT) {
580 HDF_LOGE("%s: SendRequest failed, error code is %d", __func__, ret);
581 }
582 return ret;
583 }