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_c_proxy.h"
17 #include "wlan_hdi_service_stub.h"
18 #include <string.h>
19 #include <hdf_base.h>
20 #include <hdf_log.h>
21 #include <hdf_sbuf.h>
22 #include <servmgr_hdi.h>
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif /* __cplusplus */
27
28 #define ETH_ADDR_LEN 6
29
WlanProxyCall(struct IWifiInterface * self,int32_t id,struct HdfSBuf * data,struct HdfSBuf * reply)30 static int32_t WlanProxyCall(struct IWifiInterface *self, int32_t id, struct HdfSBuf *data, struct HdfSBuf *reply)
31 {
32 if (self->remote == NULL || self->remote->dispatcher == NULL ||
33 self->remote->dispatcher->Dispatch == NULL) {
34 HDF_LOGE("%{public}s: obj is null", __func__);
35 return HDF_ERR_INVALID_OBJECT;
36 }
37 return self->remote->dispatcher->Dispatch(self->remote, id, data, reply);
38 }
39
WlanConstruct(struct IWifiInterface * self)40 static int32_t WlanConstruct(struct IWifiInterface *self)
41 {
42 int32_t ec = HDF_FAILURE;
43
44 if (self == NULL) {
45 return HDF_ERR_INVALID_PARAM;
46 }
47 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
48 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
49 if (data == NULL || reply == NULL) {
50 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
51 ec = HDF_ERR_MALLOC_FAIL;
52 goto finished;
53 }
54 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data)) {
55 ec = HDF_ERR_MALLOC_FAIL;
56 goto finished;
57 }
58 ec = WlanProxyCall(self, WLAN_SERVICE_CONSTRUCT, data, reply);
59 if (ec != HDF_SUCCESS) {
60 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
61 }
62
63 finished:
64 if (data != NULL) {
65 HdfSbufRecycle(data);
66 }
67 if (reply != NULL) {
68 HdfSbufRecycle(reply);
69 }
70 return ec;
71 }
72
WlanDestruct(struct IWifiInterface * self)73 static int32_t WlanDestruct(struct IWifiInterface *self)
74 {
75 int32_t ec = HDF_FAILURE;
76
77 if (self == NULL) {
78 return HDF_ERR_INVALID_PARAM;
79 }
80 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
81 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
82 if (data == NULL || reply == NULL) {
83 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
84 ec = HDF_ERR_MALLOC_FAIL;
85 goto finished;
86 }
87 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data)) {
88 ec = HDF_ERR_MALLOC_FAIL;
89 goto finished;
90 }
91 ec = WlanProxyCall(self, WLAN_SERVICE_DECONSTRUCT, data, reply);
92 if (ec != HDF_SUCCESS) {
93 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
94 }
95
96 finished:
97 if (data != NULL) {
98 HdfSbufRecycle(data);
99 }
100 if (reply != NULL) {
101 HdfSbufRecycle(reply);
102 }
103 return ec;
104 }
105
WlanStart(struct IWifiInterface * self)106 static int32_t WlanStart(struct IWifiInterface *self)
107 {
108 int32_t ec = HDF_FAILURE;
109
110 if (self == NULL) {
111 return HDF_ERR_INVALID_PARAM;
112 }
113 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
114 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
115 if (data == NULL || reply == NULL) {
116 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
117 ec = HDF_ERR_MALLOC_FAIL;
118 goto finished;
119 }
120 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data)) {
121 ec = HDF_ERR_MALLOC_FAIL;
122 goto finished;
123 }
124 ec = WlanProxyCall(self, WLAN_SERVICE_START, data, reply);
125 if (ec != HDF_SUCCESS) {
126 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
127 }
128
129 finished:
130 if (data != NULL) {
131 HdfSbufRecycle(data);
132 }
133 if (reply != NULL) {
134 HdfSbufRecycle(reply);
135 }
136 return ec;
137 }
138
WlanStop(struct IWifiInterface * self)139 static int32_t WlanStop(struct IWifiInterface *self)
140 {
141 int32_t ec = HDF_FAILURE;
142
143 if (self == NULL) {
144 return HDF_ERR_INVALID_PARAM;
145 }
146 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
147 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
148 if (data == NULL || reply == NULL) {
149 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
150 ec = HDF_ERR_MALLOC_FAIL;
151 goto finished;
152 }
153 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data)) {
154 ec = HDF_ERR_MALLOC_FAIL;
155 goto finished;
156 }
157 ec = WlanProxyCall(self, WLAN_SERVICE_STOP, data, reply);
158 if (ec != HDF_SUCCESS) {
159 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
160 }
161
162 finished:
163 if (data != NULL) {
164 HdfSbufRecycle(data);
165 }
166 if (reply != NULL) {
167 HdfSbufRecycle(reply);
168 }
169 return ec;
170 }
171
WlanCreateFeature(struct IWifiInterface * self,const int32_t type,struct WlanFeatureInfo ** ifeature)172 static int32_t WlanCreateFeature(struct IWifiInterface *self, const int32_t type, struct WlanFeatureInfo **ifeature)
173 {
174 bool ec = 0;
175 int32_t wlanType = 0;
176
177 if (self == NULL) {
178 return HDF_ERR_INVALID_PARAM;
179 }
180 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
181 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
182 if (data == NULL || reply == NULL) {
183 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
184 ec = HDF_ERR_MALLOC_FAIL;
185 goto finished;
186 }
187 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
188 !HdfSbufWriteInt32(data, type)) {
189 HDF_LOGE("%{public}s: write type failed!", __func__);
190 ec = HDF_ERR_MALLOC_FAIL;
191 goto finished;
192 }
193 ec = WlanProxyCall(self, WLAN_SERVICE_CREATE_FEATURE, data, reply);
194 if (ec != HDF_SUCCESS) {
195 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
196 goto finished;
197 }
198 *ifeature = (struct WlanFeatureInfo*)OsalMemAlloc(sizeof(struct WlanFeatureInfo));
199 const char *ifname = HdfSbufReadString(reply);
200 (*ifeature)->ifName = strdup(ifname);
201 HdfSbufReadInt32(reply, &wlanType);
202 (*ifeature)->wlanType = wlanType;
203
204 finished:
205 if (data != NULL) {
206 HdfSbufRecycle(data);
207 }
208 if (reply != NULL) {
209 HdfSbufRecycle(reply);
210 }
211 return ec;
212 }
213
WlanDestroyFeature(struct IWifiInterface * self,struct WlanFeatureInfo * ifeature)214 static int32_t WlanDestroyFeature(struct IWifiInterface *self, struct WlanFeatureInfo *ifeature)
215 {
216 int32_t ec = HDF_FAILURE;
217
218 if (self == NULL) {
219 return HDF_ERR_INVALID_PARAM;
220 }
221 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
222 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
223 if (data == NULL || reply == NULL) {
224 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
225 ec = HDF_ERR_MALLOC_FAIL;
226 goto finished;
227 }
228 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
229 !HdfSbufWriteString(data, ifeature->ifName)) {
230 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
231 ec = HDF_ERR_MALLOC_FAIL;
232 goto finished;
233 }
234 if (!HdfSbufWriteInt32(data, ifeature->wlanType)) {
235 HDF_LOGE("%{public}s: write wlanType failed!", __func__);
236 ec = HDF_ERR_MALLOC_FAIL;
237 goto finished;
238 }
239 ec = WlanProxyCall(self, WLAN_SERVICE_DESTROY_FEATURE, data, reply);
240 if (ec != HDF_SUCCESS) {
241 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
242 }
243
244 finished:
245 OsalMemFree(ifeature->ifName);
246 OsalMemFree(ifeature);
247 if (data != NULL) {
248 HdfSbufRecycle(data);
249 }
250 if (reply != NULL) {
251 HdfSbufRecycle(reply);
252 }
253 return ec;
254 }
255
WlanGetAsscociatedStas(struct IWifiInterface * self,const struct WlanFeatureInfo * ifeature,struct StaInfo * staInfo,uint32_t count,uint32_t * num)256 static int32_t WlanGetAsscociatedStas(struct IWifiInterface *self, const struct WlanFeatureInfo *ifeature,
257 struct StaInfo *staInfo, uint32_t count, uint32_t *num)
258 {
259 int32_t ec = HDF_FAILURE;
260
261 if (self == NULL) {
262 return HDF_ERR_INVALID_PARAM;
263 }
264 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
265 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
266 if (data == NULL || reply == NULL) {
267 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
268 ec = HDF_ERR_MALLOC_FAIL;
269 goto finished;
270 }
271 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
272 !HdfSbufWriteString(data, ifeature->ifName)) {
273 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
274 ec = HDF_ERR_MALLOC_FAIL;
275 goto finished;
276 }
277 ec = WlanProxyCall(self, WLAN_SERVICE_GET_ASSCOCIATE_STA, data, reply);
278 if (ec != HDF_SUCCESS) {
279 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
280 goto finished;
281 }
282 if (!HdfSbufReadUint32(reply, num)) {
283 HDF_LOGE("%{public}s: read num failed! error code is %{public}d", __func__, ec);
284 ec = HDF_ERR_MALLOC_FAIL;
285 goto finished;
286 }
287 if (!HdfSbufReadBuffer(reply, (const void **)&staInfo, &count)) {
288 HDF_LOGE("%{public}s: read num failed! error code is %{public}d", __func__, ec);
289 ec = HDF_ERR_MALLOC_FAIL;
290 }
291
292 finished:
293 if (data != NULL) {
294 HdfSbufRecycle(data);
295 }
296 if (reply != NULL) {
297 HdfSbufRecycle(reply);
298 }
299 return ec;
300 }
301
WlanGetChipId(struct IWifiInterface * self,const struct WlanFeatureInfo * ifeature,uint8_t * chipId)302 static int32_t WlanGetChipId(struct IWifiInterface *self, const struct WlanFeatureInfo *ifeature, uint8_t *chipId)
303 {
304 int32_t ec = HDF_FAILURE;
305
306 if (self == NULL) {
307 return HDF_ERR_INVALID_PARAM;
308 }
309 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
310 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
311 if (data == NULL || reply == NULL) {
312 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
313 ec = HDF_ERR_MALLOC_FAIL;
314 goto finished;
315 }
316 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
317 !HdfSbufWriteString(data, ifeature->ifName)) {
318 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
319 ec = HDF_ERR_MALLOC_FAIL;
320 goto finished;
321 }
322 if (!HdfSbufWriteInt32(data, ifeature->wlanType)) {
323 HDF_LOGE("%{public}s: write wlanType failed!", __func__);
324 ec = HDF_ERR_MALLOC_FAIL;
325 goto finished;
326 }
327 ec = WlanProxyCall(self, WLAN_SERVICE_GET_CHIPID, data, reply);
328 if (ec != HDF_SUCCESS) {
329 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
330 goto finished;
331 }
332 if (!HdfSbufReadUint8(reply, chipId)) {
333 HDF_LOGE("%{public}s: get chipId failed!", __func__);
334 ec = HDF_ERR_MALLOC_FAIL;
335 }
336
337 finished:
338 if (data != NULL) {
339 HdfSbufRecycle(data);
340 }
341 if (reply != NULL) {
342 HdfSbufRecycle(reply);
343 }
344 return ec;
345 }
346
WlanGetDeviceMacAddress(struct IWifiInterface * self,const struct WlanFeatureInfo * ifeature,unsigned char * mac,uint8_t len)347 static int32_t WlanGetDeviceMacAddress(struct IWifiInterface *self, const struct WlanFeatureInfo *ifeature,
348 unsigned char *mac, uint8_t len)
349 {
350 int32_t ec = HDF_FAILURE;
351 unsigned char *macaddr = NULL;
352
353 if (self == NULL) {
354 return HDF_ERR_INVALID_PARAM;
355 }
356 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
357 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
358 if (data == NULL || reply == NULL) {
359 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
360 ec = HDF_ERR_MALLOC_FAIL;
361 goto finished;
362 }
363 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
364 !HdfSbufWriteString(data, ifeature->ifName)) {
365 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
366 ec = HDF_ERR_MALLOC_FAIL;
367 goto finished;
368 }
369 if (!HdfSbufWriteInt32(data, ifeature->wlanType)) {
370 HDF_LOGE("%{public}s: write wlanType failed!", __func__);
371 ec = HDF_ERR_MALLOC_FAIL;
372 goto finished;
373 }
374 ec = WlanProxyCall(self, WLAN_SERVICE_GET_MAC_ADDR, data, reply);
375 if (ec != HDF_SUCCESS) {
376 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
377 goto finished;
378 }
379 macaddr = (unsigned char *)HdfSbufReadUnpadBuffer(reply, len);
380 for (uint8_t i = 0; i < len; i++) {
381 *(mac + i) = *(macaddr + i);
382 }
383
384 finished:
385 if (data != NULL) {
386 HdfSbufRecycle(data);
387 }
388 if (reply != NULL) {
389 HdfSbufRecycle(reply);
390 }
391 return ec;
392 }
393
WlanGetFeatureByIfName(struct IWifiInterface * self,const char * ifName,struct WlanFeatureInfo ** ifeature)394 static int32_t WlanGetFeatureByIfName(struct IWifiInterface *self, const char *ifName,
395 struct WlanFeatureInfo **ifeature)
396 {
397 int32_t ec = HDF_FAILURE;
398 int32_t wlanType = 0;
399
400 if (self == NULL) {
401 return HDF_ERR_INVALID_PARAM;
402 }
403 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
404 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
405 if (data == NULL || reply == NULL) {
406 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
407 ec = HDF_ERR_MALLOC_FAIL;
408 goto finished;
409 }
410 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
411 !HdfSbufWriteString(data, ifName)) {
412 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
413 ec = HDF_ERR_MALLOC_FAIL;
414 goto finished;
415 }
416 ec = WlanProxyCall(self, WLAN_SERVICE_GET_FEATURE_NAME, data, reply);
417 if (ec != HDF_SUCCESS) {
418 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
419 goto finished;
420 }
421 if (!HdfSbufReadInt32(reply, &wlanType)) {
422 HDF_LOGE("%{public}s: read wlantype failed! error code is %{public}d", __func__, ec);
423 ec = HDF_ERR_MALLOC_FAIL;
424 goto finished;
425 }
426 (*ifeature)->wlanType = wlanType;
427
428 finished:
429 if (data != NULL) {
430 HdfSbufRecycle(data);
431 }
432 if (reply != NULL) {
433 HdfSbufRecycle(reply);
434 }
435 return ec;
436 }
437
WlanGetFeatureType(struct IWifiInterface * self,struct WlanFeatureInfo * ifeature)438 static int32_t WlanGetFeatureType(struct IWifiInterface *self, struct WlanFeatureInfo *ifeature)
439 {
440 int32_t ec = HDF_FAILURE;
441 int32_t wlanType = 0;
442
443 if (self == NULL) {
444 return HDF_ERR_INVALID_PARAM;
445 }
446 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
447 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
448 if (data == NULL || reply == NULL) {
449 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
450 ec = HDF_ERR_MALLOC_FAIL;
451 goto finished;
452 }
453 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
454 !HdfSbufWriteInt32(data, ifeature->wlanType)) {
455 HDF_LOGE("%{public}s: write wlanType failed!", __func__);
456 ec = HDF_ERR_MALLOC_FAIL;
457 goto finished;
458 }
459 ec = WlanProxyCall(self, WLAN_SERVICE_GET_FEATURE_TYPE, data, reply);
460 if (ec != HDF_SUCCESS) {
461 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
462 goto finished;
463 }
464 if (!HdfSbufReadInt32(reply, &wlanType)) {
465 HDF_LOGE("%{public}s: read wlantype failed! error code is %{public}d", __func__, ec);
466 ec = HDF_ERR_MALLOC_FAIL;
467 goto finished;
468 }
469 ifeature->wlanType = wlanType;
470
471 finished:
472 if (data != NULL) {
473 HdfSbufRecycle(data);
474 }
475 if (reply != NULL) {
476 HdfSbufRecycle(reply);
477 }
478 return ec;
479 }
480
WlanGetFreqsWithBand(struct IWifiInterface * self,const struct WlanFeatureInfo * ifeature,int32_t band,int32_t * freqs,uint32_t count,uint32_t * num)481 static int32_t WlanGetFreqsWithBand(struct IWifiInterface *self, const struct WlanFeatureInfo *ifeature,
482 int32_t band, int32_t *freqs, uint32_t count, uint32_t *num)
483 {
484 int32_t ec = HDF_FAILURE;
485
486 if (self == NULL) {
487 return HDF_ERR_INVALID_PARAM;
488 }
489 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
490 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
491
492 if (data == NULL || reply == NULL) {
493 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
494 ec = HDF_ERR_MALLOC_FAIL;
495 goto finished;
496 }
497 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
498 !HdfSbufWriteString(data, ifeature->ifName)) {
499 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
500 ec = HDF_ERR_MALLOC_FAIL;
501 goto finished;
502 }
503 if (!HdfSbufWriteInt32(data, band) || !HdfSbufWriteInt32(data, count)) {
504 HDF_LOGE("%{public}s: write sbuf failed!", __func__);
505 ec = HDF_ERR_MALLOC_FAIL;
506 goto finished;
507 }
508 ec = WlanProxyCall(self, WLAN_SERVICE_GET_FREQ_WITHBAND, data, reply);
509 if (ec != HDF_SUCCESS) {
510 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
511 goto finished;
512 }
513 if (!HdfSbufReadUint32(reply, num)) {
514 HDF_LOGE("%{public}s: read num failed! error code is %{public}d", __func__, ec);
515 ec = HDF_FAILURE;
516 goto finished;
517 }
518 for (uint32_t i = 0; i < (*num); i++) {
519 if (!HdfSbufReadInt32(reply, &freqs[i])) {
520 HDF_LOGE("%s: write freq failed", __func__);
521 ec = HDF_FAILURE;
522 goto finished;
523 }
524 }
525
526 finished:
527 if (data != NULL) {
528 HdfSbufRecycle(data);
529 }
530 if (reply != NULL) {
531 HdfSbufRecycle(reply);
532 }
533 return ec;
534 }
535
WlanGetIfNamesByChipId(struct IWifiInterface * self,const uint8_t chipId,char ** ifNames,uint32_t * num)536 static int32_t WlanGetIfNamesByChipId(struct IWifiInterface *self, const uint8_t chipId, char **ifNames, uint32_t *num)
537 {
538 int32_t ec = HDF_FAILURE;
539
540 if (self == NULL) {
541 return HDF_ERR_INVALID_PARAM;
542 }
543 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
544 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
545 if (data == NULL || reply == NULL) {
546 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
547 ec = HDF_ERR_MALLOC_FAIL;
548 goto finished;
549 }
550 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
551 !HdfSbufWriteUint8(data, chipId)) {
552 HDF_LOGE("%{public}s: write wlanType failed!", __func__);
553 ec = HDF_ERR_MALLOC_FAIL;
554 goto finished;
555 }
556 ec = WlanProxyCall(self, WLAN_SERVICE_GET_NAME_BYCHIPID, data, reply);
557 if (ec != HDF_SUCCESS) {
558 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
559 goto finished;
560 }
561 if (!HdfSbufReadUint32(reply, num)) {
562 HDF_LOGE("%s: write num failed", __func__);
563 ec = HDF_ERR_INVALID_PARAM;
564 goto finished;
565 }
566 *ifNames = (char *)HdfSbufReadString(reply);
567
568 finished:
569 if (data != NULL) {
570 HdfSbufRecycle(data);
571 }
572 if (reply != NULL) {
573 HdfSbufRecycle(reply);
574 }
575 return ec;
576 }
577
WlanGetNetworkIfaceName(struct IWifiInterface * self,struct WlanFeatureInfo * ifeature)578 static int32_t WlanGetNetworkIfaceName(struct IWifiInterface *self, struct WlanFeatureInfo *ifeature)
579 {
580 int32_t ec = HDF_FAILURE;
581
582 if (self == NULL) {
583 return HDF_ERR_INVALID_PARAM;
584 }
585 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
586 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
587 if (data == NULL || reply == NULL) {
588 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
589 ec = HDF_ERR_MALLOC_FAIL;
590 goto finished;
591 }
592 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
593 !HdfSbufWriteString(data, ifeature->ifName)) {
594 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
595 ec = HDF_ERR_MALLOC_FAIL;
596 goto finished;
597 }
598 ec = WlanProxyCall(self, WLAN_SERVICE_GET_NETWORK_NAME, data, reply);
599 if (ec != HDF_SUCCESS) {
600 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
601 goto finished;
602 }
603 const char *ifName = HdfSbufReadString(reply);
604 HDF_LOGI("%{public}s: ifName is %{public}s!", __func__, ifName);
605 ifeature->ifName = strdup(ifName);
606
607 finished:
608 if (data != NULL) {
609 HdfSbufRecycle(data);
610 }
611 if (reply != NULL) {
612 HdfSbufRecycle(reply);
613 }
614 return ec;
615 }
616
WlanGetSupportCombo(struct IWifiInterface * self,uint64_t * combo)617 static int32_t WlanGetSupportCombo(struct IWifiInterface *self, uint64_t *combo)
618 {
619 int32_t ec = HDF_FAILURE;
620
621 if (self == NULL) {
622 return HDF_ERR_INVALID_PARAM;
623 }
624 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
625 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
626 if (data == NULL || reply == NULL) {
627 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
628 ec = HDF_ERR_MALLOC_FAIL;
629 goto finished;
630 }
631 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data)) {
632 ec = HDF_ERR_MALLOC_FAIL;
633 goto finished;
634 }
635 ec = WlanProxyCall(self, WLAN_SERVICE_GET_SUPPORT_COMBO, data, reply);
636 if ((ec != HDF_SUCCESS) && (ec != HDF_ERR_NOT_SUPPORT)) {
637 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
638 goto finished;
639 }
640 if (ec == HDF_SUCCESS) {
641 for (int i = 0; i < ETH_ADDR_LEN; i++) {
642 int ret = HdfSbufReadUint64(reply, &combo[i]);
643 if (ret != HDF_SUCCESS) {
644 HDF_LOGE("%s: write combo failed!, error code: %d", __func__, ret);
645 }
646 }
647 }
648
649 finished:
650 if (data != NULL) {
651 HdfSbufRecycle(data);
652 }
653 if (reply != NULL) {
654 HdfSbufRecycle(reply);
655 }
656 return ec;
657 }
658
WlanGetSupportFeature(struct IWifiInterface * self,uint8_t * supType)659 static int32_t WlanGetSupportFeature(struct IWifiInterface *self, uint8_t *supType)
660 {
661 int32_t ec = HDF_FAILURE;
662 uint32_t size = 0;
663 uint8_t *isSupType = NULL;
664
665 if (self == NULL) {
666 return HDF_ERR_INVALID_PARAM;
667 }
668 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
669 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
670 if (data == NULL || reply == NULL) {
671 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
672 ec = HDF_ERR_MALLOC_FAIL;
673 goto finished;
674 }
675 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data)) {
676 ec = HDF_ERR_MALLOC_FAIL;
677 goto finished;
678 }
679 ec = WlanProxyCall(self, WLAN_SERVICE_GET_SUPPORT_FEATURE, data, reply);
680 if (ec != HDF_SUCCESS) {
681 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
682 goto finished;
683 }
684 HdfSbufReadUint32(reply, &size);
685 isSupType = (uint8_t *)HdfSbufReadUnpadBuffer(reply, size);
686 for (uint32_t i = 0; i < size; i++) {
687 *(supType + i) = *(isSupType + i);
688 }
689
690 finished:
691 if (data != NULL) {
692 HdfSbufRecycle(data);
693 }
694 if (reply != NULL) {
695 HdfSbufRecycle(reply);
696 }
697 return ec;
698 }
699
700 int32_t (*callback_)(uint32_t event, void *data, const char *ifName);
701
ServiceManagerTestCallbackDispatch(struct HdfRemoteService * service,int eventId,struct HdfSBuf * data,struct HdfSBuf * reply)702 static int ServiceManagerTestCallbackDispatch(struct HdfRemoteService *service, int eventId,
703 struct HdfSBuf *data, struct HdfSBuf *reply)
704 {
705 const char *ifName = HdfSbufReadString(data);
706 return callback_(eventId, data, ifName);
707 }
708
709 static struct HdfRemoteDispatcher g_callbackDispatcher = {
710 .Dispatch = ServiceManagerTestCallbackDispatch,
711 };
712
WlanRegisterEventCallback(struct IWifiInterface * self,CallbackFunc cbFunc)713 static int32_t WlanRegisterEventCallback(struct IWifiInterface *self, CallbackFunc cbFunc)
714 {
715 int32_t ec = HDF_FAILURE;
716
717 if (self == NULL) {
718 return HDF_ERR_INVALID_PARAM;
719 }
720 struct HdfRemoteService *callback = HdfRemoteServiceObtain(NULL, &g_callbackDispatcher);
721 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
722 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
723 if (data == NULL || reply == NULL) {
724 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
725 ec = HDF_ERR_MALLOC_FAIL;
726 goto finished;
727 }
728 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data)) {
729 ec = HDF_ERR_MALLOC_FAIL;
730 goto finished;
731 }
732 HdfSbufWriteRemoteService(data, callback);
733 ec = WlanProxyCall(self, WLAN_SERVICE_REGISTER_CALLBACK, data, reply);
734 if (ec != HDF_SUCCESS) {
735 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
736 goto finished;
737 }
738 callback_ = cbFunc;
739
740 finished:
741 if (data != NULL) {
742 HdfSbufRecycle(data);
743 }
744 if (reply != NULL) {
745 HdfSbufRecycle(reply);
746 }
747 return ec;
748 }
749
WlanUnregisterEventCallback(struct IWifiInterface * self)750 static int32_t WlanUnregisterEventCallback(struct IWifiInterface *self)
751 {
752 int32_t ec = HDF_FAILURE;
753
754 if (self == NULL) {
755 return HDF_ERR_INVALID_PARAM;
756 }
757 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
758 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
759 if (data == NULL || reply == NULL) {
760 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
761 ec = HDF_ERR_MALLOC_FAIL;
762 goto finished;
763 }
764 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data)) {
765 ec = HDF_ERR_MALLOC_FAIL;
766 goto finished;
767 }
768 ec = WlanProxyCall(self, WLAN_SERVICE_UNREGISTER_CALLBACK, data, reply);
769 if (ec != HDF_SUCCESS) {
770 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
771 }
772
773 finished:
774 if (data != NULL) {
775 HdfSbufRecycle(data);
776 }
777 if (reply != NULL) {
778 HdfSbufRecycle(reply);
779 }
780 return ec;
781 }
782
WlanResetDriver(struct IWifiInterface * self,const uint8_t chipId)783 static int32_t WlanResetDriver(struct IWifiInterface *self, const uint8_t chipId)
784 {
785 int32_t ec = HDF_FAILURE;
786
787 if (self == NULL) {
788 return HDF_ERR_INVALID_PARAM;
789 }
790 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
791 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
792 if (data == NULL || reply == NULL) {
793 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
794 ec = HDF_ERR_MALLOC_FAIL;
795 goto finished;
796 }
797 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
798 !HdfSbufWriteUint8(data, chipId)) {
799 HDF_LOGE("%{public}s: write wlanType failed!", __func__);
800 ec = HDF_ERR_MALLOC_FAIL;
801 goto finished;
802 }
803 ec = WlanProxyCall(self, WLAN_SERVICE_RESET_DRIVER, data, reply);
804 if (ec != HDF_SUCCESS) {
805 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
806 }
807
808 finished:
809 if (data != NULL) {
810 HdfSbufRecycle(data);
811 }
812 if (reply != NULL) {
813 HdfSbufRecycle(reply);
814 }
815 return ec;
816 }
817
WlanSetCountryCode(struct IWifiInterface * self,const struct WlanFeatureInfo * ifeature,const char * code,uint32_t len)818 static int32_t WlanSetCountryCode(struct IWifiInterface *self, const struct WlanFeatureInfo *ifeature,
819 const char *code, uint32_t len)
820 {
821 int32_t ec = HDF_FAILURE;
822
823 if (self == NULL) {
824 return HDF_ERR_INVALID_PARAM;
825 }
826 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
827 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
828 if (data == NULL || reply == NULL) {
829 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
830 ec = HDF_ERR_MALLOC_FAIL;
831 goto finished;
832 }
833 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
834 !HdfSbufWriteString(data, ifeature->ifName)) {
835 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
836 ec = HDF_ERR_MALLOC_FAIL;
837 goto finished;
838 }
839 if (!HdfSbufWriteString(data, code)) {
840 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
841 ec = HDF_ERR_MALLOC_FAIL;
842 goto finished;
843 }
844 ec = WlanProxyCall(self, WLAN_SERVICE_SET_COUNTRY_CODE, data, reply);
845 if (ec != HDF_SUCCESS) {
846 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
847 }
848
849 finished:
850 if (data != NULL) {
851 HdfSbufRecycle(data);
852 }
853 if (reply != NULL) {
854 HdfSbufRecycle(reply);
855 }
856 return ec;
857 }
858
WlanSetMacAddress(struct IWifiInterface * self,const struct WlanFeatureInfo * ifeature,unsigned char * mac,uint8_t len)859 static int32_t WlanSetMacAddress(struct IWifiInterface *self, const struct WlanFeatureInfo *ifeature,
860 unsigned char *mac, uint8_t len)
861 {
862 int32_t ec = HDF_FAILURE;
863
864 if (self == NULL) {
865 return HDF_ERR_INVALID_PARAM;
866 }
867 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
868 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
869 if (data == NULL || reply == NULL) {
870 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
871 ec = HDF_ERR_MALLOC_FAIL;
872 goto finished;
873 }
874 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
875 !HdfSbufWriteString(data, ifeature->ifName)) {
876 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
877 ec = HDF_ERR_MALLOC_FAIL;
878 goto finished;
879 }
880 for (int i = 0; i < ETH_ADDR_LEN; i++) {
881 if (!HdfSbufWriteUint8(data, mac[i])) {
882 HDF_LOGE(" %s: read mac failed", __func__);
883 ec = HDF_ERR_INVALID_PARAM;
884 goto finished;
885 }
886 }
887 ec = WlanProxyCall(self, WLAN_SERVICE_SET_MAC_ADDR, data, reply);
888 if (ec != HDF_SUCCESS) {
889 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
890 }
891
892 finished:
893 if (data != NULL) {
894 HdfSbufRecycle(data);
895 }
896 if (reply != NULL) {
897 HdfSbufRecycle(reply);
898 }
899 return ec;
900 }
901
WlanSetScanningMacAddress(struct IWifiInterface * self,const struct WlanFeatureInfo * ifeature,unsigned char * scanMac,uint8_t len)902 static int32_t WlanSetScanningMacAddress(struct IWifiInterface *self, const struct WlanFeatureInfo *ifeature,
903 unsigned char *scanMac, uint8_t len)
904 {
905 int32_t ec = HDF_FAILURE;
906
907 if (self == NULL) {
908 return HDF_ERR_INVALID_PARAM;
909 }
910 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
911 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
912 if (data == NULL || reply == NULL) {
913 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
914 ec = HDF_ERR_MALLOC_FAIL;
915 goto finished;
916 }
917 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
918 !HdfSbufWriteString(data, ifeature->ifName)) {
919 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
920 ec = HDF_ERR_MALLOC_FAIL;
921 goto finished;
922 }
923 if (!HdfSbufWriteUint8(data, len)) {
924 HDF_LOGE("%{public}s: write wlanType failed!", __func__);
925 ec = HDF_ERR_MALLOC_FAIL;
926 goto finished;
927 }
928 for (int i = 0; i < ETH_ADDR_LEN; i++) {
929 if (!HdfSbufWriteUint8(data, scanMac[i])) {
930 HDF_LOGE(" %s: read scanMac failed", __func__);
931 ec = HDF_ERR_INVALID_PARAM;
932 goto finished;
933 }
934 }
935 ec = WlanProxyCall(self, WLAN_SERVICE_SET_SACN_MACADDR, data, reply);
936 if (ec != HDF_SUCCESS) {
937 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
938 }
939
940 finished:
941 if (data != NULL) {
942 HdfSbufRecycle(data);
943 }
944 if (reply != NULL) {
945 HdfSbufRecycle(reply);
946 }
947 return ec;
948 }
949
WlanSetTxPower(struct IWifiInterface * self,const struct WlanFeatureInfo * ifeature,int32_t power)950 static int32_t WlanSetTxPower(struct IWifiInterface *self, const struct WlanFeatureInfo *ifeature, int32_t power)
951 {
952 int32_t ec = HDF_FAILURE;
953
954 if (self == NULL) {
955 return HDF_ERR_INVALID_PARAM;
956 }
957 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
958 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
959 if (data == NULL || reply == NULL) {
960 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
961 ec = HDF_ERR_MALLOC_FAIL;
962 goto finished;
963 }
964 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
965 !HdfSbufWriteString(data, ifeature->ifName)) {
966 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
967 ec = HDF_ERR_MALLOC_FAIL;
968 goto finished;
969 }
970 if (!HdfSbufWriteInt32(data, power)) {
971 HDF_LOGE("%{public}s: write wlanType failed!", __func__);
972 ec = HDF_ERR_MALLOC_FAIL;
973 goto finished;
974 }
975 ec = WlanProxyCall(self, WLAN_SERVICE_SET_TX_POWR, data, reply);
976 if (ec != HDF_SUCCESS) {
977 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
978 }
979
980 finished:
981 if (data != NULL) {
982 HdfSbufRecycle(data);
983 }
984 if (reply != NULL) {
985 HdfSbufRecycle(reply);
986 }
987 return ec;
988 }
989
WlanGetNetDevInfo(struct IWifiInterface * self,struct NetDeviceInfoResult * netDeviceInfoResult)990 static int32_t WlanGetNetDevInfo(struct IWifiInterface *self, struct NetDeviceInfoResult *netDeviceInfoResult)
991 {
992 int32_t ec = HDF_FAILURE;
993 uint32_t dataSize = 0;
994 struct NetDeviceInfoResult *respNetdevInfo = NULL;
995
996 if (self == NULL) {
997 return HDF_ERR_INVALID_PARAM;
998 }
999 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
1000 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
1001 if (data == NULL || reply == NULL) {
1002 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
1003 ec = HDF_ERR_MALLOC_FAIL;
1004 goto finished;
1005 }
1006 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data)) {
1007 ec = HDF_ERR_MALLOC_FAIL;
1008 goto finished;
1009 }
1010 ec = WlanProxyCall(self, WLAN_SERVICE_GET_NETDEV_INFO, data, reply);
1011 if (ec != HDF_SUCCESS) {
1012 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
1013 goto finished;
1014 }
1015 if (!HdfSbufReadBuffer(reply, (const void **)(&respNetdevInfo), &dataSize) ||
1016 dataSize != sizeof(struct NetDeviceInfoResult)) {
1017 ec = HDF_FAILURE;
1018 goto finished;
1019 }
1020 if (memcpy_s(netDeviceInfoResult, sizeof(struct NetDeviceInfoResult), respNetdevInfo, dataSize) != EOK) {
1021 HDF_LOGE("%{public}s: memcpy_s failed!", __func__);
1022 ec = HDF_FAILURE;
1023 }
1024
1025 finished:
1026 if (data != NULL) {
1027 HdfSbufRecycle(data);
1028 }
1029 if (reply != NULL) {
1030 HdfSbufRecycle(reply);
1031 }
1032 return ec;
1033 }
1034
WlanStartScan(struct IWifiInterface * self,const struct WlanFeatureInfo * ifeature,WifiScan * scan)1035 static int32_t WlanStartScan(struct IWifiInterface *self, const struct WlanFeatureInfo *ifeature, WifiScan *scan)
1036 {
1037 int32_t ec = HDF_FAILURE;
1038
1039 if (self == NULL) {
1040 return HDF_ERR_INVALID_PARAM;
1041 }
1042 struct HdfSBuf *data = HdfSbufTypedObtain(SBUF_IPC);
1043 struct HdfSBuf *reply = HdfSbufTypedObtain(SBUF_IPC);
1044 if (data == NULL || reply == NULL) {
1045 HDF_LOGE("%{public}s: HdfSubf malloc failed!", __func__);
1046 ec = HDF_ERR_MALLOC_FAIL;
1047 goto finished;
1048 }
1049 if (!HdfRemoteServiceWriteInterfaceToken(self->remote, data) ||
1050 !HdfSbufWriteString(data, ifeature->ifName)) {
1051 HDF_LOGE("%{public}s: write ifeature->ifName failed!", __func__);
1052 ec = HDF_ERR_MALLOC_FAIL;
1053 goto finished;
1054 }
1055 if (!HdfSbufWriteBuffer(data, scan, sizeof(WifiScan))) {
1056 HDF_LOGE("%s: write buffer fail!", __func__);
1057 ec = HDF_ERR_MALLOC_FAIL;
1058 goto finished;
1059 }
1060 ec = WlanProxyCall(self, WLAN_SERVICE_START_SCAN, data, reply);
1061 if (ec != HDF_SUCCESS) {
1062 HDF_LOGE("%{public}s: call failed! error code is %{public}d", __func__, ec);
1063 }
1064
1065 finished:
1066 if (data != NULL) {
1067 HdfSbufRecycle(data);
1068 }
1069 if (reply != NULL) {
1070 HdfSbufRecycle(reply);
1071 }
1072 return ec;
1073 }
1074
IwifiConstruct(struct IWifiInterface * inst)1075 static void IwifiConstruct(struct IWifiInterface *inst)
1076 {
1077 inst->construct = WlanConstruct;
1078 inst->destruct = WlanDestruct;
1079 inst->start = WlanStart;
1080 inst->stop = WlanStop;
1081 inst->createFeature = WlanCreateFeature;
1082 inst->destroyFeature = WlanDestroyFeature;
1083 inst->getAsscociatedStas = WlanGetAsscociatedStas;
1084 inst->getChipId = WlanGetChipId;
1085 inst->getDeviceMacAddress = WlanGetDeviceMacAddress;
1086 inst->getFeatureByIfName = WlanGetFeatureByIfName;
1087 inst->getFeatureType = WlanGetFeatureType;
1088 inst->getFreqsWithBand = WlanGetFreqsWithBand;
1089 inst->getIfNamesByChipId = WlanGetIfNamesByChipId;
1090 inst->getNetworkIfaceName = WlanGetNetworkIfaceName;
1091 inst->getSupportCombo = WlanGetSupportCombo;
1092 inst->getSupportFeature = WlanGetSupportFeature;
1093 inst->registerEventCallback = WlanRegisterEventCallback;
1094 inst->unregisterEventCallback = WlanUnregisterEventCallback;
1095 inst->resetDriver = WlanResetDriver;
1096 inst->setCountryCode = WlanSetCountryCode;
1097 inst->setMacAddress = WlanSetMacAddress;
1098 inst->setScanningMacAddress = WlanSetScanningMacAddress;
1099 inst->setTxPower = WlanSetTxPower;
1100 inst->getNetDevInfo = WlanGetNetDevInfo;
1101 inst->startScan = WlanStartScan;
1102 }
1103
HdIWifiInterfaceGet(const char * serviceName)1104 struct IWifiInterface *HdIWifiInterfaceGet(const char *serviceName)
1105 {
1106 struct HDIServiceManager *serviceMgr = HDIServiceManagerGet();
1107 HDF_LOGI("%{public}s: HDIServiceManager start! serviceName = %{public}s", __func__, serviceName);
1108 if (serviceMgr == NULL) {
1109 HDF_LOGE("%{public}s: HDIServiceManager not found!", __func__);
1110 return NULL;
1111 }
1112 struct HdfRemoteService *remote = serviceMgr->GetService(serviceMgr, serviceName);
1113 if (remote == NULL) {
1114 HDF_LOGE("%{public}s: HdfRemoteService not found!", __func__);
1115 return NULL;
1116 }
1117 struct IWifiInterface *wlanClient = (struct IWifiInterface *)OsalMemAlloc(sizeof(struct IWifiInterface));
1118 if (wlanClient == NULL) {
1119 HDF_LOGE("%{public}s: malloc sample instance failed!", __func__);
1120 HdfRemoteServiceRecycle(remote);
1121 return NULL;
1122 }
1123 if (!HdfRemoteServiceSetInterfaceDesc(remote, "HDI.WLAN.V1_0")) {
1124 HDF_LOGE("%{public}s: failed to init interface desc", __func__);
1125 HdfRemoteServiceRecycle(remote);
1126 return NULL;
1127 }
1128 wlanClient->remote = remote;
1129
1130 IwifiConstruct(wlanClient);
1131 return wlanClient;
1132 }
1133
HdIWifiInterfaceRelease(struct IWifiInterface * instance)1134 void HdIWifiInterfaceRelease(struct IWifiInterface *instance)
1135 {
1136 if (instance == NULL) {
1137 return;
1138 }
1139 HdfRemoteServiceRecycle(instance->remote);
1140 OsalMemFree(instance);
1141 }
1142
1143 #ifdef __cplusplus
1144 }
1145 #endif /* __cplusplus */