1 /*
2 * Copyright (c) 2021-2023 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 <stdlib.h>
17
18 #include "hdf_log.h"
19 #include "sbuf_common_adapter.h"
20 #include "securec.h"
21
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27
28 #define DRIVER_SERVICE_NAME "hdfwifi"
29 static struct HdfDevEventlistener g_wifiDevEventListener;
30 static bool g_isHasRegisterListener = false;
31 #define PNO_SCAN_INFO_MAXSIZE 1500
32
ParserNetworkInfo(struct HdfSBuf * reply,struct NetworkInfoResult * result)33 static int32_t ParserNetworkInfo(struct HdfSBuf *reply, struct NetworkInfoResult *result)
34 {
35 uint32_t i;
36 const char *ifName = NULL;
37 uint8_t *mode = NULL;
38 uint32_t replayDataSize;
39
40 if (!HdfSbufReadUint32(reply, &result->nums)) {
41 HDF_LOGE("%s: get networkNum failed", __FUNCTION__);
42 return RET_CODE_FAILURE;
43 }
44 if (result->nums > MAX_IFACE_NUM) {
45 result->nums = MAX_IFACE_NUM;
46 }
47 for (i = 0; i < result->nums; i++) {
48 ifName = HdfSbufReadString(reply);
49 if (ifName == NULL) {
50 HDF_LOGE("%s: get ifName failed", __FUNCTION__);
51 return RET_CODE_FAILURE;
52 }
53 if (!HdfSbufReadBuffer(reply, (const void **)&mode, &replayDataSize) || mode == NULL ||
54 replayDataSize != WIFI_IFTYPE_MAX) {
55 HDF_LOGE("%s: get mode failed", __FUNCTION__);
56 return RET_CODE_FAILURE;
57 }
58 if (strncpy_s(result->infos[i].name, IFNAMSIZ, ifName, strlen(ifName)) != EOK) {
59 HDF_LOGE("%s: memcpy_s name failed", __FUNCTION__);
60 return RET_CODE_FAILURE;
61 }
62 if (memcpy_s(result->infos[i].supportMode, WIFI_IFTYPE_MAX, mode, replayDataSize) != EOK) {
63 HDF_LOGE("%s: memcpy_s supportMode failed", __FUNCTION__);
64 return RET_CODE_FAILURE;
65 }
66 }
67 return RET_CODE_SUCCESS;
68 }
69
ParserDeviceMacAddr(struct HdfSBuf * reply,uint8_t * mac,uint8_t len)70 static int32_t ParserDeviceMacAddr(struct HdfSBuf *reply, uint8_t *mac, uint8_t len)
71 {
72 uint8_t isEfuseSavedMac;
73 uint32_t replayDataSize = 0;
74 const uint8_t *replayData = 0;
75
76 if (!HdfSbufReadUint8(reply, &isEfuseSavedMac)) {
77 HDF_LOGE("%s: HdfSbufReadUint8 failed", __FUNCTION__);
78 return RET_CODE_FAILURE;
79 }
80 if (!isEfuseSavedMac) {
81 HDF_LOGE("%s: not support to get device mac addr", __FUNCTION__);
82 return RET_CODE_NOT_SUPPORT;
83 }
84 if (!HdfSbufReadBuffer(reply, (const void **)(&replayData), &replayDataSize) || replayDataSize != len) {
85 HDF_LOGE("%s: HdfSbufReadBuffer failed", __FUNCTION__);
86 return RET_CODE_FAILURE;
87 }
88 if (memcpy_s(mac, len, replayData, replayDataSize) != EOK) {
89 HDF_LOGE("%s: memcpy failed", __FUNCTION__);
90 return RET_CODE_FAILURE;
91 }
92 return RET_CODE_SUCCESS;
93 }
94
ParserFreqInfo(struct HdfSBuf * reply,struct FreqInfoResult * result,uint32_t size)95 static int32_t ParserFreqInfo(struct HdfSBuf *reply, struct FreqInfoResult *result, uint32_t size)
96 {
97 uint32_t replayDataSize = 0;
98 const uint8_t *replayData = 0;
99
100 if (result == NULL || result->freqs == NULL || result->txPower == NULL) {
101 HDF_LOGE("%s: Invalid input parameter", __FUNCTION__);
102 return RET_CODE_INVALID_PARAM;
103 }
104
105 if (!HdfSbufReadUint32(reply, &result->nums)) {
106 HDF_LOGE("%s: read num failed", __FUNCTION__);
107 return RET_CODE_FAILURE;
108 }
109 if (result->nums > size) {
110 HDF_LOGE("%s: num valid", __FUNCTION__);
111 return RET_CODE_FAILURE;
112 }
113 if (!HdfSbufReadBuffer(reply, (const void **)(&replayData), &replayDataSize)) {
114 HDF_LOGE("%s: read freqs failed", __FUNCTION__);
115 return RET_CODE_FAILURE;
116 }
117 if (memcpy_s(result->freqs, size * sizeof(uint32_t), replayData, replayDataSize) != EOK) {
118 HDF_LOGE("%s: memcpy failed", __FUNCTION__);
119 return RET_CODE_FAILURE;
120 }
121 return RET_CODE_SUCCESS;
122 }
123
ParserAssociatedStas(struct HdfSBuf * reply,struct AssocStaInfoResult * result)124 static int32_t ParserAssociatedStas(struct HdfSBuf *reply, struct AssocStaInfoResult *result)
125 {
126 uint32_t replayDataSize = 0;
127 const uint8_t *replayData = 0;
128
129 if (!HdfSbufReadUint32(reply, &result->num)) {
130 HDF_LOGE("%s: read num failed", __FUNCTION__);
131 return RET_CODE_FAILURE;
132 }
133 if (result->num > MAX_ASSOC_STA_NUM) {
134 HDF_LOGE("%s: num invalid", __FUNCTION__);
135 return RET_CODE_FAILURE;
136 }
137 if (result->num != 0) {
138 if (!HdfSbufReadBuffer(reply, (const void **)(&replayData), &replayDataSize) ||
139 replayDataSize > sizeof(result->infos)) {
140 HDF_LOGE("%s: read AssocStaInfo failed", __FUNCTION__);
141 return RET_CODE_FAILURE;
142 }
143 if (memcpy_s(result->infos, sizeof(result->infos), replayData, replayDataSize) != EOK) {
144 HDF_LOGE("%s: memcpy failed", __FUNCTION__);
145 return RET_CODE_FAILURE;
146 }
147 }
148 return RET_CODE_SUCCESS;
149 }
150
HdfSbufObtainDefault(struct HdfSBuf ** data,struct HdfSBuf ** reply)151 static int32_t HdfSbufObtainDefault(struct HdfSBuf **data, struct HdfSBuf **reply)
152 {
153 *data = HdfSbufObtainDefaultSize();
154 if (*data == NULL) {
155 return RET_CODE_FAILURE;
156 }
157 *reply = HdfSbufObtainDefaultSize();
158 if (*reply == NULL) {
159 HdfSbufRecycle(*data);
160 return RET_CODE_FAILURE;
161 }
162 return RET_CODE_SUCCESS;
163 }
164
WifiMsgRegisterEventListener(struct HdfDevEventlistener * listener)165 static int32_t WifiMsgRegisterEventListener(struct HdfDevEventlistener *listener)
166 {
167 struct HdfIoService *wifiService = GetWifiService();
168 if (wifiService == NULL || listener == NULL) {
169 HDF_LOGE("%s: At least one param is null", __FUNCTION__);
170 return RET_CODE_FAILURE;
171 }
172 if (HdfDeviceRegisterEventListener(wifiService, listener) != RET_CODE_SUCCESS) {
173 HDF_LOGE("%s: fail to register event listener, line: %d", __FUNCTION__, __LINE__);
174 return RET_CODE_FAILURE;
175 }
176 g_isHasRegisterListener = true;
177 return RET_CODE_SUCCESS;
178 }
179
WifiMsgUnregisterEventListener(struct HdfDevEventlistener * listener)180 static void WifiMsgUnregisterEventListener(struct HdfDevEventlistener *listener)
181 {
182 struct HdfIoService *wifiService = GetWifiService();
183 if (listener == NULL) {
184 return;
185 }
186 if (HdfDeviceUnregisterEventListener(wifiService, listener) != HDF_SUCCESS) {
187 HDF_LOGE("%s: fail to unregister event listener, line: %d", __FUNCTION__, __LINE__);
188 }
189 g_isHasRegisterListener = false;
190 }
191
WifiDriverClientInit(void)192 int32_t WifiDriverClientInit(void)
193 {
194 int32_t ret;
195 struct HdfIoService *wifiService = InitWifiService(DRIVER_SERVICE_NAME);
196 if (wifiService == NULL) {
197 HDF_LOGE("%s: fail to get remote service!", __FUNCTION__);
198 return RET_CODE_FAILURE;
199 }
200 g_wifiDevEventListener.onReceive = OnWiFiEvents;
201 if (g_isHasRegisterListener) {
202 HDF_LOGI("%s:has register listener!", __FUNCTION__);
203 return RET_CODE_SUCCESS;
204 }
205 ret = WifiMsgRegisterEventListener(&g_wifiDevEventListener);
206 if (ret != RET_CODE_SUCCESS) {
207 HDF_LOGE("%s: register event listener failed, line: %d", __FUNCTION__, __LINE__);
208 }
209 return ret;
210 }
211
WifiDriverClientDeinit(void)212 void WifiDriverClientDeinit(void)
213 {
214 struct HdfIoService *wifiService = GetWifiService();
215 if (wifiService == NULL) {
216 return;
217 }
218 WifiMsgUnregisterEventListener(&g_wifiDevEventListener);
219 if (HdfIoserviceGetListenerCount(wifiService) != 0) {
220 HDF_LOGE("%s: the current EventListener is not empty. cancel the listener registration first.",
221 __FUNCTION__);
222 return;
223 }
224 ReleaseWifiService();
225 }
226
GetUsableNetworkInfo(struct NetworkInfoResult * result)227 int32_t GetUsableNetworkInfo(struct NetworkInfoResult *result)
228 {
229 int32_t ret;
230 struct HdfSBuf *data = NULL;
231 struct HdfSBuf *reply = NULL;
232
233 if (result == NULL) {
234 HDF_LOGE("%s params is NULL", __FUNCTION__);
235 return RET_CODE_INVALID_PARAM;
236 }
237 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
238 return RET_CODE_FAILURE;
239 }
240 ret = SendCmdSync(WIFI_HAL_CMD_GET_NETWORK_INFO, data, reply);
241 if (ret == RET_CODE_SUCCESS) {
242 ret = ParserNetworkInfo(reply, result);
243 } else {
244 ret = RET_CODE_FAILURE;
245 }
246 HdfSbufRecycle(data);
247 HdfSbufRecycle(reply);
248 return ret;
249 }
250
IsSupportCombo(uint8_t * isSupportCombo)251 int32_t IsSupportCombo(uint8_t *isSupportCombo)
252 {
253 int32_t ret;
254 struct HdfSBuf *data = NULL;
255 struct HdfSBuf *reply = NULL;
256
257 if (isSupportCombo == NULL) {
258 HDF_LOGE("%s params is NULL", __FUNCTION__);
259 return RET_CODE_INVALID_PARAM;
260 }
261 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
262 return RET_CODE_FAILURE;
263 }
264 ret = SendCmdSync(WIFI_HAL_CMD_IS_SUPPORT_COMBO, data, reply);
265 do {
266 if (ret != RET_CODE_SUCCESS) {
267 break;
268 }
269 if (!HdfSbufReadUint8(reply, isSupportCombo)) {
270 HDF_LOGE("%s: HdfSbufReadUint8 failed", __FUNCTION__);
271 ret = RET_CODE_FAILURE;
272 } else {
273 ret = RET_CODE_SUCCESS;
274 }
275 } while (0);
276 HdfSbufRecycle(data);
277 HdfSbufRecycle(reply);
278 return ret;
279 }
280
GetComboInfo(uint64_t * comboInfo,uint32_t size)281 int32_t GetComboInfo(uint64_t *comboInfo, uint32_t size)
282 {
283 int32_t ret;
284 uint8_t isComboValid;
285 uint32_t replayDataSize = 0;
286 const uint8_t *replayData = 0;
287 struct HdfSBuf *data = NULL;
288 struct HdfSBuf *reply = NULL;
289
290 if (comboInfo == NULL) {
291 HDF_LOGE("%s params is NULL", __FUNCTION__);
292 return RET_CODE_INVALID_PARAM;
293 }
294 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
295 return RET_CODE_FAILURE;
296 }
297 ret = SendCmdSync(WIFI_HAL_CMD_GET_SUPPORT_COMBO, data, reply);
298 do {
299 if (ret != RET_CODE_SUCCESS) {
300 ret = RET_CODE_FAILURE;
301 break;
302 }
303 if (!HdfSbufReadUint8(reply, &isComboValid)) {
304 HDF_LOGE("%s: read combo valid flag failed", __FUNCTION__);
305 ret = RET_CODE_FAILURE;
306 break;
307 }
308 if (!isComboValid) {
309 HDF_LOGE("%s: not support combo mode", __FUNCTION__);
310 ret = RET_CODE_NOT_SUPPORT;
311 break;
312 }
313 if (!HdfSbufReadBuffer(reply, (const void **)(&replayData), &replayDataSize)) {
314 HDF_LOGE("%s: HdfSbufReadBuffer failed", __FUNCTION__);
315 ret = RET_CODE_FAILURE;
316 break;
317 }
318 if (memcpy_s(comboInfo, size, replayData, replayDataSize) != EOK) {
319 HDF_LOGE("%s: memcpy failed", __FUNCTION__);
320 ret = RET_CODE_FAILURE;
321 break;
322 }
323 } while (0);
324 HdfSbufRecycle(data);
325 HdfSbufRecycle(reply);
326 return ret;
327 }
328
SetMacAddr(const char * ifName,unsigned char * mac,uint8_t len)329 int32_t SetMacAddr(const char *ifName, unsigned char *mac, uint8_t len)
330 {
331 int32_t ret;
332 struct HdfSBuf *data = NULL;
333 struct HdfSBuf *reply = NULL;
334
335 if (ifName == NULL || mac == NULL) {
336 HDF_LOGE("%s params is NULL", __FUNCTION__);
337 return RET_CODE_INVALID_PARAM;
338 }
339 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
340 return RET_CODE_FAILURE;
341 }
342 do {
343 if (!HdfSbufWriteString(data, ifName)) {
344 HDF_LOGE("%s: write ifName failed", __FUNCTION__);
345 ret = RET_CODE_FAILURE;
346 break;
347 }
348 if (!HdfSbufWriteBuffer(data, mac, len)) {
349 HDF_LOGE("%s: write mac failed", __FUNCTION__);
350 ret = RET_CODE_FAILURE;
351 break;
352 }
353 ret = SendCmdSync(WIFI_HAL_CMD_SET_MAC_ADDR, data, reply);
354 } while (0);
355 HdfSbufRecycle(data);
356 HdfSbufRecycle(reply);
357 return ret;
358 }
359
GetDevMacAddr(const char * ifName,int32_t type,uint8_t * mac,uint8_t len)360 int32_t GetDevMacAddr(const char *ifName, int32_t type, uint8_t *mac, uint8_t len)
361 {
362 int32_t ret;
363 struct HdfSBuf *data = NULL;
364 struct HdfSBuf *reply = NULL;
365
366 if (ifName == NULL || mac == NULL) {
367 HDF_LOGE("%s params is NULL", __FUNCTION__);
368 return RET_CODE_INVALID_PARAM;
369 }
370 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
371 return RET_CODE_FAILURE;
372 }
373 do {
374 if (!HdfSbufWriteString(data, ifName)) {
375 HDF_LOGE("%s: write ifName failed", __FUNCTION__);
376 ret = RET_CODE_FAILURE;
377 break;
378 }
379 if (!HdfSbufWriteInt32(data, type)) {
380 HDF_LOGE("%s: write type failed", __FUNCTION__);
381 ret = RET_CODE_FAILURE;
382 break;
383 }
384 ret = SendCmdSync(WIFI_HAL_CMD_GET_DEV_MAC_ADDR, data, reply);
385 if (ret != RET_CODE_SUCCESS) {
386 ret = RET_CODE_FAILURE;
387 break;
388 }
389 ret = ParserDeviceMacAddr(reply, mac, len);
390 } while (0);
391 HdfSbufRecycle(data);
392 HdfSbufRecycle(reply);
393 return ret;
394 }
395
GetValidFreqByBand(const char * ifName,int32_t band,struct FreqInfoResult * result,uint32_t size)396 int32_t GetValidFreqByBand(const char *ifName, int32_t band, struct FreqInfoResult *result, uint32_t size)
397 {
398 int32_t ret;
399 struct HdfSBuf *data = NULL;
400 struct HdfSBuf *reply = NULL;
401
402 if (ifName == NULL || result == NULL || band >= IEEE80211_NUM_BANDS) {
403 HDF_LOGE("%s params is NULL", __FUNCTION__);
404 return RET_CODE_INVALID_PARAM;
405 }
406 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
407 return RET_CODE_FAILURE;
408 }
409 do {
410 if (!HdfSbufWriteString(data, ifName)) {
411 HDF_LOGE("%s: write ifName failed", __FUNCTION__);
412 ret = RET_CODE_FAILURE;
413 break;
414 }
415 if (!HdfSbufWriteInt32(data, band)) {
416 HDF_LOGE("%s: write band failed", __FUNCTION__);
417 ret = RET_CODE_FAILURE;
418 break;
419 }
420 ret = SendCmdSync(WIFI_HAL_CMD_GET_VALID_FREQ, data, reply);
421 if (ret != RET_CODE_SUCCESS) {
422 ret = RET_CODE_FAILURE;
423 break;
424 }
425 ret = ParserFreqInfo(reply, result, size);
426 } while (0);
427 HdfSbufRecycle(data);
428 HdfSbufRecycle(reply);
429 return ret;
430 }
431
SetTxPower(const char * ifName,int32_t power)432 int32_t SetTxPower(const char *ifName, int32_t power)
433 {
434 int32_t ret;
435 struct HdfSBuf *data = NULL;
436 struct HdfSBuf *reply = NULL;
437
438 if (ifName == NULL) {
439 HDF_LOGE("%s params is NULL", __FUNCTION__);
440 return RET_CODE_INVALID_PARAM;
441 }
442 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
443 return RET_CODE_FAILURE;
444 }
445 do {
446 if (!HdfSbufWriteString(data, ifName)) {
447 HDF_LOGE("%s: write ifName failed", __FUNCTION__);
448 ret = RET_CODE_FAILURE;
449 break;
450 }
451 if (!HdfSbufWriteInt32(data, power)) {
452 HDF_LOGE("%s: HdfSbufWriteInt32 failed", __FUNCTION__);
453 ret = RET_CODE_FAILURE;
454 break;
455 }
456 ret = SendCmdSync(WIFI_HAL_CMD_SET_TX_POWER, data, reply);
457 } while (0);
458 HdfSbufRecycle(data);
459 HdfSbufRecycle(reply);
460 return ret;
461 }
462
GetAssociatedStas(const char * ifName,struct AssocStaInfoResult * result)463 int32_t GetAssociatedStas(const char *ifName, struct AssocStaInfoResult *result)
464 {
465 int32_t ret;
466 struct HdfSBuf *data = NULL;
467 struct HdfSBuf *reply = NULL;
468
469 if (ifName == NULL || result == NULL) {
470 HDF_LOGE("%s params is NULL", __FUNCTION__);
471 return RET_CODE_INVALID_PARAM;
472 }
473 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
474 return RET_CODE_FAILURE;
475 }
476 do {
477 if (!HdfSbufWriteString(data, ifName)) {
478 HDF_LOGE("%s: write ifName failed", __FUNCTION__);
479 ret = RET_CODE_FAILURE;
480 break;
481 }
482 ret = SendCmdSync(WIFI_HAL_CMD_GET_ASSOC_STA, data, reply);
483 if (ret != RET_CODE_SUCCESS) {
484 ret = RET_CODE_FAILURE;
485 break;
486 }
487 ret = ParserAssociatedStas(reply, result);
488 } while (0);
489 HdfSbufRecycle(data);
490 HdfSbufRecycle(reply);
491 return ret;
492 }
493
WifiSetCountryCode(const char * ifName,const char * code,uint32_t len)494 int32_t WifiSetCountryCode(const char *ifName, const char *code, uint32_t len)
495 {
496 int32_t ret;
497 struct HdfSBuf *data = NULL;
498 struct HdfSBuf *reply = NULL;
499
500 if (ifName == NULL || code == NULL) {
501 HDF_LOGE("%s params is NULL", __FUNCTION__);
502 return RET_CODE_INVALID_PARAM;
503 }
504 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
505 return RET_CODE_FAILURE;
506 }
507 do {
508 if (!HdfSbufWriteString(data, ifName)) {
509 HDF_LOGE("%s: write ifName failed", __FUNCTION__);
510 ret = RET_CODE_FAILURE;
511 break;
512 }
513 if (!HdfSbufWriteBuffer(data, code, len)) {
514 HDF_LOGE("%s: write code failed", __FUNCTION__);
515 ret = RET_CODE_FAILURE;
516 break;
517 }
518 ret = SendCmdSync(WIFI_HAL_CMD_SET_COUNTRY_CODE, data, reply);
519 } while (0);
520 HdfSbufRecycle(data);
521 HdfSbufRecycle(reply);
522 return ret;
523 }
524
SetScanMacAddr(const char * ifName,uint8_t * scanMac,uint8_t len)525 int32_t SetScanMacAddr(const char *ifName, uint8_t *scanMac, uint8_t len)
526 {
527 int32_t ret;
528 uint8_t isFuncValid;
529 struct HdfSBuf *data = NULL;
530 struct HdfSBuf *reply = NULL;
531
532 if (ifName == NULL || scanMac == NULL) {
533 HDF_LOGE("%s params is NULL", __FUNCTION__);
534 return RET_CODE_INVALID_PARAM;
535 }
536 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
537 return RET_CODE_FAILURE;
538 }
539 do {
540 if (!HdfSbufWriteString(data, ifName)) {
541 HDF_LOGE("%s: write ifName failed", __FUNCTION__);
542 ret = RET_CODE_FAILURE;
543 break;
544 }
545 if (!HdfSbufWriteBuffer(data, scanMac, len)) {
546 HDF_LOGE("%s: write scan mac failed", __FUNCTION__);
547 ret = RET_CODE_FAILURE;
548 break;
549 }
550 ret = SendCmdSync(WIFI_HAL_CMD_SET_SCAN_MAC_ADDR, data, reply);
551 if (ret != RET_CODE_SUCCESS) {
552 break;
553 }
554 if (!HdfSbufReadUint8(reply, &isFuncValid)) {
555 HDF_LOGE("%s: read valid flag failed", __FUNCTION__);
556 ret = RET_CODE_FAILURE;
557 break;
558 }
559 if (!isFuncValid) {
560 HDF_LOGE("%s: not support to set scan mac addr", __FUNCTION__);
561 ret = RET_CODE_NOT_SUPPORT;
562 break;
563 }
564 } while (0);
565 HdfSbufRecycle(data);
566 HdfSbufRecycle(reply);
567 return ret;
568 }
569
AcquireChipId(const char * ifName,uint8_t * chipId)570 int32_t AcquireChipId(const char *ifName, uint8_t *chipId)
571 {
572 int32_t ret;
573 struct HdfSBuf *data = NULL;
574 struct HdfSBuf *reply = NULL;
575
576 if (ifName == NULL || chipId == NULL) {
577 HDF_LOGE("%s params is NULL", __FUNCTION__);
578 return RET_CODE_INVALID_PARAM;
579 }
580 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
581 return RET_CODE_FAILURE;
582 }
583 do {
584 if (!HdfSbufWriteString(data, ifName)) {
585 HDF_LOGE("%s: HdfSbufWriteString failed", __FUNCTION__);
586 ret = RET_CODE_FAILURE;
587 break;
588 }
589 ret = SendCmdSync(WIFI_HAL_CMD_GET_CHIPID, data, reply);
590 if (ret != RET_CODE_SUCCESS) {
591 break;
592 }
593 if (!HdfSbufReadUint8(reply, chipId)) {
594 HDF_LOGE("%s: HdfSbufReadUint8 failed", __FUNCTION__);
595 ret = RET_CODE_FAILURE;
596 break;
597 }
598 } while (0);
599 HdfSbufRecycle(data);
600 HdfSbufRecycle(reply);
601 return ret;
602 }
603
GetIfNames(struct HdfSBuf * reply,char ** ifNames,uint32_t * num)604 static int32_t GetIfNames(struct HdfSBuf *reply, char **ifNames, uint32_t *num)
605 {
606 uint32_t i;
607 uint32_t replayDataSize = 0;
608 const char *replayData = NULL;
609
610 if (!HdfSbufReadUint32(reply, num)) {
611 HDF_LOGE("%s: HdfSbufReadUint32 failed", __FUNCTION__);
612 return RET_CODE_FAILURE;
613 }
614 *ifNames = (char *)calloc(*num, IFNAMSIZ);
615 if (*ifNames == NULL) {
616 HDF_LOGE("%s: calloc failed", __FUNCTION__);
617 return RET_CODE_FAILURE;
618 }
619
620 if (!HdfSbufReadBuffer(reply, (const void **)(&replayData), &replayDataSize) ||
621 replayDataSize < (*num * IFNAMSIZ)) {
622 HDF_LOGE("%s: HdfSbufReadBuffer failed", __FUNCTION__);
623 free(*ifNames);
624 *ifNames = NULL;
625 return RET_CODE_FAILURE;
626 }
627
628 for (i = 0; i < *num; i++) {
629 if (memcpy_s(*ifNames + i * IFNAMSIZ, IFNAMSIZ, replayData + i * IFNAMSIZ, replayDataSize) != EOK) {
630 HDF_LOGE("%s: memcpy failed", __FUNCTION__);
631 free(*ifNames);
632 *ifNames = NULL;
633 return RET_CODE_FAILURE;
634 }
635 }
636 return RET_CODE_SUCCESS;
637 }
638
GetIfNamesByChipId(const uint8_t chipId,char ** ifNames,uint32_t * num)639 int32_t GetIfNamesByChipId(const uint8_t chipId, char **ifNames, uint32_t *num)
640 {
641 int32_t ret;
642 struct HdfSBuf *data = NULL;
643 struct HdfSBuf *reply = NULL;
644
645 if (ifNames == NULL || num == NULL) {
646 HDF_LOGE("%s params is NULL", __FUNCTION__);
647 return RET_CODE_INVALID_PARAM;
648 }
649 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
650 return RET_CODE_FAILURE;
651 }
652 do {
653 if (!HdfSbufWriteUint8(data, chipId)) {
654 HDF_LOGE("%s: HdfSbufWriteUint8 failed", __FUNCTION__);
655 ret = RET_CODE_FAILURE;
656 break;
657 }
658 ret = SendCmdSync(WIFI_HAL_CMD_GET_IFNAMES, data, reply);
659 if (ret != RET_CODE_SUCCESS) {
660 break;
661 }
662 ret = GetIfNames(reply, ifNames, num);
663 } while (0);
664 HdfSbufRecycle(data);
665 HdfSbufRecycle(reply);
666 return ret;
667 }
668
SetResetDriver(const uint8_t chipId,const char * ifName)669 int32_t SetResetDriver(const uint8_t chipId, const char *ifName)
670 {
671 int32_t ret;
672 struct HdfSBuf *data = NULL;
673 struct HdfSBuf *reply = NULL;
674
675 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
676 return RET_CODE_FAILURE;
677 }
678 do {
679 if (!HdfSbufWriteUint8(data, chipId)) {
680 HDF_LOGE("%s: HdfSbufWriteUint8 failed", __FUNCTION__);
681 ret = RET_CODE_FAILURE;
682 break;
683 }
684 if (!HdfSbufWriteString(data, ifName)) {
685 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
686 ret = RET_CODE_FAILURE;
687 break;
688 }
689 ret = SendCmdSync(WIFI_HAL_CMD_RESET_DRIVER, data, reply);
690 } while (0);
691 HdfSbufRecycle(data);
692 HdfSbufRecycle(reply);
693 return ret;
694 }
695
GetNetDeviceInfo(struct NetDeviceInfoResult * netDeviceInfoResult)696 int32_t GetNetDeviceInfo(struct NetDeviceInfoResult *netDeviceInfoResult)
697 {
698 int32_t ret;
699 struct HdfSBuf *data = NULL;
700 struct HdfSBuf *reply = NULL;
701 uint32_t netdevNum = 0;
702 uint32_t ifNameSize;
703 uint32_t macSize;
704 uint32_t i;
705 const uint8_t *replayData = NULL;
706 const char *ifName = NULL;
707
708 if (netDeviceInfoResult == NULL) {
709 HDF_LOGE("%s: params is NULL", __FUNCTION__);
710 return RET_CODE_INVALID_PARAM;
711 }
712 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
713 return RET_CODE_FAILURE;
714 }
715 do {
716 ret = SendCmdSync(WIFI_HAL_CMD_GET_NETDEV_INFO, data, reply);
717 if (ret != RET_CODE_SUCCESS) {
718 break;
719 }
720 if (!HdfSbufReadUint32(reply, &netdevNum)) {
721 HDF_LOGE("%s: HdfSbufReadUint32 failed", __FUNCTION__);
722 ret = RET_CODE_FAILURE;
723 break;
724 }
725 for (i = 0; i < netdevNum; i++) {
726 if (!HdfSbufReadUint32(reply, &(netDeviceInfoResult->deviceInfos[i].index)) ||
727 !HdfSbufReadBuffer(reply, (const void **)(&ifName), &ifNameSize) ||
728 !HdfSbufReadUint8(reply, &(netDeviceInfoResult->deviceInfos[i].iftype)) ||
729 !HdfSbufReadBuffer(reply, (const void **)(&replayData), &macSize)) {
730 HDF_LOGE("%s: read fail!", __FUNCTION__);
731 ret = RET_CODE_FAILURE;
732 break;
733 }
734 if (memcpy_s(netDeviceInfoResult->deviceInfos[i].ifName, ifNameSize, ifName, ifNameSize) != EOK) {
735 HDF_LOGE("%s: memcpy failed", __FUNCTION__);
736 ret = RET_CODE_FAILURE;
737 break;
738 }
739 if (memcpy_s(netDeviceInfoResult->deviceInfos[i].mac, macSize, replayData, macSize) != EOK) {
740 HDF_LOGE("%s: memcpy failed", __FUNCTION__);
741 ret = RET_CODE_FAILURE;
742 break;
743 }
744 }
745 } while (0);
746 HdfSbufRecycle(data);
747 HdfSbufRecycle(reply);
748 return ret;
749 }
750
GetCurrentPowerMode(const char * ifName,uint8_t * mode)751 int32_t GetCurrentPowerMode(const char *ifName, uint8_t *mode)
752 {
753 int32_t ret;
754 struct HdfSBuf *data = NULL;
755 struct HdfSBuf *reply = NULL;
756
757 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
758 HDF_LOGE("%s: HdfSbufObtainDefault fail", __FUNCTION__);
759 return RET_CODE_FAILURE;
760 }
761
762 do {
763 if (!HdfSbufWriteString(data, ifName)) {
764 HDF_LOGE("%s: write ifName fail!", __FUNCTION__);
765 ret = RET_CODE_FAILURE;
766 break;
767 }
768 ret = SendCmdSync(WIFI_HAL_CMD_GET_POWER_MODE, data, reply);
769 if (ret != RET_CODE_SUCCESS) {
770 HDF_LOGE("%s: SendCmdSync fail!", __FUNCTION__);
771 break;
772 }
773 if (!HdfSbufReadUint8(reply, mode)) {
774 HDF_LOGE("%s: HdfSbufReadUint8 failed", __FUNCTION__);
775 ret = RET_CODE_FAILURE;
776 break;
777 }
778 } while (0);
779
780 HdfSbufRecycle(data);
781 HdfSbufRecycle(reply);
782 return ret;
783 }
784
SetPowerMode(const char * ifName,uint8_t mode)785 int32_t SetPowerMode(const char *ifName, uint8_t mode)
786 {
787 int32_t ret = RET_CODE_FAILURE;
788 struct HdfSBuf *data = NULL;
789
790 data = HdfSbufObtainDefaultSize();
791 if (data == NULL) {
792 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail!", __FUNCTION__);
793 return ret;
794 }
795
796 do {
797 if (!HdfSbufWriteString(data, ifName)) {
798 HDF_LOGE("%s: write ifName fail!", __FUNCTION__);
799 break;
800 }
801 if (!HdfSbufWriteUint8(data, mode)) {
802 HDF_LOGE("%s: write ifName fail!", __FUNCTION__);
803 break;
804 }
805 ret = SendCmdSync(WIFI_HAL_CMD_SET_POWER_MODE, data, NULL);
806 } while (0);
807
808 HdfSbufRecycle(data);
809 return ret;
810 }
811
WifiCmdScan(const char * ifName,WifiScan * scan)812 int32_t WifiCmdScan(const char *ifName, WifiScan *scan)
813 {
814 int32_t ret;
815 struct HdfSBuf *data = NULL;
816
817 if (ifName == NULL || scan == NULL) {
818 HDF_LOGE("%s: Input param is null", __FUNCTION__);
819 return RET_CODE_INVALID_PARAM;
820 }
821 data = HdfSbufObtainDefaultSize();
822 if (data == NULL) {
823 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail", __FUNCTION__);
824 return RET_CODE_FAILURE;
825 }
826 bool isSerializeFailed = false;
827 isSerializeFailed = isSerializeFailed || !HdfSbufWriteString(data, ifName);
828 if (scan->bssid == NULL) {
829 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, scan->bssid, 0);
830 } else {
831 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, scan->bssid, ETH_ADDR_LEN);
832 }
833 isSerializeFailed =
834 isSerializeFailed || !HdfSbufWriteBuffer(data, scan->ssids, sizeof(scan->ssids[0]) * scan->numSsids);
835 isSerializeFailed = isSerializeFailed || !HdfSbufWriteBuffer(data, scan->extraIes, scan->extraIesLen);
836 isSerializeFailed =
837 isSerializeFailed || !HdfSbufWriteBuffer(data, scan->freqs, sizeof(scan->freqs[0]) * scan->numFreqs);
838 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, scan->prefixSsidScanFlag);
839 isSerializeFailed = isSerializeFailed || !HdfSbufWriteUint8(data, scan->fastConnectFlag);
840 if (isSerializeFailed) {
841 HDF_LOGE("%s: Serialize failed!", __FUNCTION__);
842 ret = RET_CODE_FAILURE;
843 } else {
844 ret = SendCmdSync(WIFI_WPA_CMD_SCAN, data, NULL);
845 }
846 HdfSbufRecycle(data);
847 return ret;
848 }
849
StartChannelMeas(const char * ifName,const struct MeasParam * measParam)850 int32_t StartChannelMeas(const char *ifName, const struct MeasParam *measParam)
851 {
852 int32_t ret = RET_CODE_FAILURE;
853 struct HdfSBuf *data = NULL;
854
855 data = HdfSbufObtainDefaultSize();
856 if (data == NULL) {
857 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail!", __FUNCTION__);
858 return ret;
859 }
860
861 do {
862 if (!HdfSbufWriteString(data, ifName)) {
863 HDF_LOGE("%s: write ifName fail!", __FUNCTION__);
864 break;
865 }
866 if (!HdfSbufWriteBuffer(data, measParam, sizeof(struct MeasParam))) {
867 HDF_LOGE("%s: write paramBuf fail!", __FUNCTION__);
868 break;
869 }
870 ret = SendCmdSync(WIFI_HAL_CMD_START_CHANNEL_MEAS, data, NULL);
871 } while (0);
872
873 HdfSbufRecycle(data);
874 return ret;
875 }
876
SetProjectionScreenParam(const char * ifName,const ProjectionScreenParam * param)877 int32_t SetProjectionScreenParam(const char *ifName, const ProjectionScreenParam *param)
878 {
879 int32_t ret = RET_CODE_FAILURE;
880 struct HdfSBuf *req = NULL;
881
882 req = HdfSbufObtainDefaultSize();
883 if (req == NULL) {
884 HDF_LOGE("%{public}s: HdfSbufObtainDefaultSize fail!", __FUNCTION__);
885 return ret;
886 }
887
888 do {
889 if (!HdfSbufWriteString(req, ifName)) {
890 HDF_LOGE("%{public}s: write ifName fail!", __FUNCTION__);
891 break;
892 }
893 if (!HdfSbufWriteInt32(req, param->cmdId)) {
894 HDF_LOGE("%{public}s: write cmd fail!", __FUNCTION__);
895 break;
896 }
897 if (!HdfSbufWriteBuffer(req, param->buf, param->bufLen)) {
898 HDF_LOGE("%{public}s: write buffer data fail!", __FUNCTION__);
899 break;
900 }
901 ret = SendCmdSync(WIFI_HAL_CMD_CONFIG_PROJECTION_SCREEN, req, NULL);
902 if (ret != RET_CODE_SUCCESS) {
903 HDF_LOGE("%{public}s: SendCmdSync fail, ret = %{public}d!", __FUNCTION__, ret);
904 }
905 } while (0);
906
907 HdfSbufRecycle(req);
908 return ret;
909 }
910
SendCmdIoctl(const char * ifName,int32_t cmdId,const int8_t * paramBuf,uint32_t paramBufLen)911 int32_t SendCmdIoctl(const char *ifName, int32_t cmdId, const int8_t *paramBuf, uint32_t paramBufLen)
912 {
913 int ret = RET_CODE_FAILURE;
914 struct HdfSBuf *req = NULL;
915
916 req = HdfSbufObtainDefaultSize();
917 if (req == NULL) {
918 HDF_LOGE("%{public}s: HdfSbufObtainDefaultSize fail!", __FUNCTION__);
919 return ret;
920 }
921
922 do {
923 if (!HdfSbufWriteString(req, ifName)) {
924 HDF_LOGE("%{public}s: write ifName fail!", __FUNCTION__);
925 break;
926 }
927 if (!HdfSbufWriteInt32(req, cmdId)) {
928 HDF_LOGE("%{public}s: write cmd fail!", __FUNCTION__);
929 break;
930 }
931 if (!HdfSbufWriteBuffer(req, paramBuf, paramBufLen)) {
932 HDF_LOGE("%{public}s: write buffer data fail!", __FUNCTION__);
933 break;
934 }
935 ret = SendCmdSync(WIFI_HAL_CMD_SET_CMD_IOCTL, req, NULL);
936 if (ret != RET_CODE_SUCCESS) {
937 HDF_LOGE("%{public}s: SendCmdSync fail, ret = %{public}d!", __FUNCTION__, ret);
938 }
939 } while (0);
940
941 HdfSbufRecycle(req);
942 return ret;
943 }
944
GetStationInfo(const char * ifName,StationInfo * info,const uint8_t * mac,uint32_t macLen)945 int32_t GetStationInfo(const char *ifName, StationInfo *info, const uint8_t *mac, uint32_t macLen)
946 {
947 int32_t ret = RET_CODE_FAILURE;
948
949 struct HdfSBuf *data = NULL;
950 struct HdfSBuf *reply = NULL;
951 const uint8_t *replayData = NULL;
952 uint32_t size;
953
954 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
955 return RET_CODE_FAILURE;
956 }
957
958 do {
959 if (!HdfSbufWriteString(data, ifName)) {
960 HDF_LOGE("%{public}s: write ifName fail!", __FUNCTION__);
961 break;
962 }
963 if (!HdfSbufWriteBuffer(data, mac, macLen)) {
964 HDF_LOGE("%{public}s: write mac address fail!", __FUNCTION__);
965 break;
966 }
967 ret = SendCmdSync(WIFI_HAL_CMD_GET_STATION_INFO, data, reply);
968 if (ret != RET_CODE_SUCCESS) {
969 HDF_LOGE("%{public}s: SendCmdSync fail, ret = %{public}d!", __FUNCTION__, ret);
970 break;
971 }
972 if (!HdfSbufReadBuffer(reply, (const void **)(&replayData), &size)) {
973 HDF_LOGE("%{public}s: read station information fail!", __FUNCTION__);
974 ret = RET_CODE_FAILURE;
975 break;
976 }
977 if (memcpy_s(info, sizeof(StationInfo), replayData, size) != EOK) {
978 HDF_LOGE("%{public}s: memcpy_s fail", __FUNCTION__);
979 ret = RET_CODE_FAILURE;
980 }
981 } while (0);
982 HdfSbufRecycle(data);
983 HdfSbufRecycle(reply);
984 return ret;
985 }
986
SerializeSettingsToSbuf(struct HdfSBuf * req,const WifiPnoSettings * pnoSettings)987 static int32_t SerializeSettingsToSbuf(struct HdfSBuf *req, const WifiPnoSettings *pnoSettings)
988 {
989 if (!HdfSbufWriteInt32(req, pnoSettings->min2gRssi)) {
990 HDF_LOGE("%{public}s: write min2gRssi fail!", __FUNCTION__);
991 return RET_CODE_FAILURE;
992 }
993 if (!HdfSbufWriteInt32(req, pnoSettings->min5gRssi)) {
994 HDF_LOGE("%{public}s: write min5gRssi fail!", __FUNCTION__);
995 return RET_CODE_FAILURE;
996 }
997 if (!HdfSbufWriteInt32(req, pnoSettings->scanIntervalMs)) {
998 HDF_LOGE("%{public}s: write scanIntervalMs fail!", __FUNCTION__);
999 return RET_CODE_FAILURE;
1000 }
1001 if (!HdfSbufWriteInt32(req, pnoSettings->scanIterations)) {
1002 HDF_LOGE("%{public}s: write scanIterations fail!", __FUNCTION__);
1003 return RET_CODE_FAILURE;
1004 }
1005 if (!HdfSbufWriteUint32(req, pnoSettings->pnoNetworksLen)) {
1006 HDF_LOGE("%{public}s: write pnoNetworksLen fail!", __FUNCTION__);
1007 return RET_CODE_FAILURE;
1008 }
1009 for (uint32_t i = 0; i < pnoSettings->pnoNetworksLen; i++) {
1010 if (!HdfSbufWriteUint8(req, pnoSettings->pnoNetworks[i].isHidden)) {
1011 HDF_LOGE("%{public}s: write isHidden fail!", __FUNCTION__);
1012 return RET_CODE_FAILURE;
1013 }
1014 if (!HdfSbufWriteBuffer(req, pnoSettings->pnoNetworks[i].freqs,
1015 sizeof(int32_t) * (pnoSettings->pnoNetworks[i].freqsLen))) {
1016 HDF_LOGE("%{public}s: write freqs fail!", __FUNCTION__);
1017 return RET_CODE_FAILURE;
1018 }
1019 if (!HdfSbufWriteBuffer(req, pnoSettings->pnoNetworks[i].ssid.ssid,
1020 pnoSettings->pnoNetworks[i].ssid.ssidLen)) {
1021 HDF_LOGE("%{public}s: write ssid fail!", __FUNCTION__);
1022 return RET_CODE_FAILURE;
1023 }
1024 }
1025 return RET_CODE_SUCCESS;
1026 }
1027
WifiStartPnoScan(const char * ifName,const WifiPnoSettings * pnoSettings)1028 int32_t WifiStartPnoScan(const char *ifName, const WifiPnoSettings *pnoSettings)
1029 {
1030 int32_t ret = RET_CODE_FAILURE;
1031 struct HdfSBuf *req = NULL;
1032
1033 if (ifName == NULL || pnoSettings == NULL) {
1034 HDF_LOGE("%s: Input param is null", __FUNCTION__);
1035 return RET_CODE_INVALID_PARAM;
1036 }
1037 req = HdfSbufObtain(PNO_SCAN_INFO_MAXSIZE);
1038 if (req == NULL) {
1039 HDF_LOGE("%s: HdfSbufObtainDefaultSize fail", __FUNCTION__);
1040 return RET_CODE_FAILURE;
1041 }
1042 do {
1043 if (!HdfSbufWriteString(req, ifName)) {
1044 HDF_LOGE("%{public}s: write ifName fail!", __FUNCTION__);
1045 break;
1046 }
1047 if (SerializeSettingsToSbuf(req, pnoSettings) != RET_CODE_SUCCESS) {
1048 HDF_LOGE("%{public}s:SerilizeSettingsToSbuf fail!", __FUNCTION__);
1049 break;
1050 }
1051 ret = SendCmdSync(WIFI_HAL_CMD_START_PNO_SCAN, req, NULL);
1052 if (ret != RET_CODE_SUCCESS) {
1053 HDF_LOGE("%{public}s: SendCmdSync fail, ret = %{public}d!", __FUNCTION__, ret);
1054 }
1055 } while (0);
1056 HdfSbufRecycle(req);
1057 return ret;
1058 }
1059
WifiStopPnoScan(const char * ifName)1060 int32_t WifiStopPnoScan(const char *ifName)
1061 {
1062 int32_t ret = RET_CODE_FAILURE;
1063 struct HdfSBuf *req = NULL;
1064
1065 req = HdfSbufObtainDefaultSize();
1066 if (req == NULL) {
1067 HDF_LOGE("%{public}s: HdfSbufObtainDefaultSize fail!", __FUNCTION__);
1068 return ret;
1069 }
1070
1071 do {
1072 if (!HdfSbufWriteString(req, ifName)) {
1073 HDF_LOGE("%{public}s: write ifName fail!", __FUNCTION__);
1074 break;
1075 }
1076 ret = SendCmdSync(WIFI_HAL_CMD_STOP_PNO_SCAN, req, NULL);
1077 if (ret != RET_CODE_SUCCESS) {
1078 HDF_LOGE("%{public}s: SendCmdSync fail, ret = %{public}d!", __FUNCTION__, ret);
1079 }
1080 } while (0);
1081
1082 HdfSbufRecycle(req);
1083 return ret;
1084 }
1085
ClientGetApBandwidth(const char * ifName,uint8_t * bandwidth)1086 int32_t ClientGetApBandwidth(const char *ifName, uint8_t *bandwidth)
1087 {
1088 int32_t ret;
1089 struct HdfSBuf *data = NULL;
1090 struct HdfSBuf *reply = NULL;
1091
1092 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
1093 HDF_LOGE("%s: HdfSbufObtainDefault fail", __FUNCTION__);
1094 return RET_CODE_FAILURE;
1095 }
1096
1097 do {
1098 if (!HdfSbufWriteString(data, ifName)) {
1099 HDF_LOGE("%s: write ifName fail!", __FUNCTION__);
1100 ret = RET_CODE_FAILURE;
1101 break;
1102 }
1103 ret = SendCmdSync(WIFI_HAL_CMD_GET_AP_BANDWIDTH, data, reply);
1104 if (ret != RET_CODE_SUCCESS) {
1105 HDF_LOGE("%s: SendCmdSync fail, code=%d", __FUNCTION__, ret);
1106 break;
1107 }
1108 if (!HdfSbufReadUint8(reply, bandwidth)) {
1109 HDF_LOGE("%s: HdfSbufReadUint8 failed", __FUNCTION__);
1110 ret = RET_CODE_FAILURE;
1111 break;
1112 }
1113 } while (0);
1114
1115 HdfSbufRecycle(data);
1116 HdfSbufRecycle(reply);
1117 return ret;
1118 }
1119
WifiGetSignalPollInfo(const char * ifName,struct SignalResult * signalResult)1120 int32_t WifiGetSignalPollInfo(const char *ifName, struct SignalResult *signalResult)
1121 {
1122 int32_t ret = RET_CODE_FAILURE;
1123 struct HdfSBuf *data = NULL;
1124 struct HdfSBuf *reply = NULL;
1125 const uint8_t *replayData = NULL;
1126 uint32_t size;
1127
1128 if (HdfSbufObtainDefault(&data, &reply) != RET_CODE_SUCCESS) {
1129 return RET_CODE_FAILURE;
1130 }
1131 do {
1132 if (!HdfSbufWriteString(data, ifName)) {
1133 HDF_LOGE("%{public}s: write ifName fail!", __FUNCTION__);
1134 break;
1135 }
1136 ret = SendCmdSync(WIFI_HAL_CMD_GET_SIGNAL_INFO, data, reply);
1137 if (ret != RET_CODE_SUCCESS) {
1138 HDF_LOGE("%{public}s: SendCmdSync fail, ret = %{public}d!", __FUNCTION__, ret);
1139 break;
1140 }
1141 if (!HdfSbufReadBuffer(reply, (const void **)(&replayData), &size)) {
1142 HDF_LOGE("%{public}s: read signal information fail!", __FUNCTION__);
1143 ret = RET_CODE_FAILURE;
1144 break;
1145 }
1146 if (memcpy_s(signalResult, sizeof(struct SignalResult), replayData, size) != EOK) {
1147 HDF_LOGE("%{public}s: memcpy_s fail", __FUNCTION__);
1148 ret = RET_CODE_FAILURE;
1149 }
1150 } while (0);
1151 HdfSbufRecycle(data);
1152 HdfSbufRecycle(reply);
1153 return ret;
1154 }
1155
WifiSendActionFrame(const char * ifName,uint32_t freq,const uint8_t * frameData,uint32_t frameDataLen)1156 int32_t WifiSendActionFrame(const char *ifName, uint32_t freq, const uint8_t *frameData, uint32_t frameDataLen)
1157 {
1158 (void)ifName;
1159 (void)freq;
1160 (void)frameData;
1161 (void)frameDataLen;
1162 return RET_CODE_NOT_SUPPORT;
1163 }
1164
WifiRegisterActionFrameReceiver(const char * ifName,const uint8_t * match,uint32_t matchLen)1165 int32_t WifiRegisterActionFrameReceiver(const char *ifName, const uint8_t *match, uint32_t matchLen)
1166 {
1167 (void)ifName;
1168 (void)match;
1169 (void)matchLen;
1170 return RET_CODE_NOT_SUPPORT;
1171 }
1172
WifiSetPowerSaveMode(const char * ifName,int32_t frequency,int32_t mode)1173 int32_t WifiSetPowerSaveMode(const char *ifName, int32_t frequency, int32_t mode)
1174 {
1175 (void)ifName;
1176 (void)frequency;
1177 (void)mode;
1178
1179 return RET_CODE_NOT_SUPPORT;
1180 }
1181
WifiSetDpiMarkRule(int32_t uid,int32_t protocol,int32_t enable)1182 int32_t WifiSetDpiMarkRule(int32_t uid, int32_t protocol, int32_t enable)
1183 {
1184 (void)uid;
1185 (void)protocol;
1186 (void)enable;
1187
1188 return RET_CODE_NOT_SUPPORT;
1189 }
1190
WifiInstallWlanExtParam(const char * ifName,const InstallWlanParam * param)1191 int32_t WifiInstallWlanExtParam(const char *ifName, const InstallWlanParam *param)
1192 {
1193 (void)ifName;
1194 (void)param;
1195
1196 return RET_CODE_NOT_SUPPORT;
1197 }
1198
1199 #ifdef __cplusplus
1200 #if __cplusplus
1201 }
1202 #endif
1203 #endif
1204