1 /*
2 * Copyright (c) 2022-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 #include "wlan_common_cmd.h"
16 #include <securec.h>
17 #include <hdf_base.h>
18 #include <hdf_log.h>
19 #include <osal_time.h>
20 #include <osal_mem.h>
21 #include "wlan_extend_cmd.h"
22 #include "v1_1/iwlan_callback.h"
23 #include "v1_1/iwlan_interface.h"
24
25 struct IWiFi *g_wifi = NULL;
26 struct IWiFiAp *g_apFeature = NULL;
27 struct IWiFiSta *g_staFeature = NULL;
28 struct IWiFiBaseFeature *g_baseFeature = NULL;
29 static uint32_t g_wifiCount = 0;
30 static uint32_t g_apFeatureCount = 0;
31 static uint32_t g_staFeatureCount = 0;
32 const uint32_t RESET_TIME = 3;
33 #define DEFAULT_COMBO_SIZE 10
34 #define WLAN_FREQ_MAX_NUM 14
35 #define WLAN_MAX_NUM_STA_WITH_AP 4
36 #define ETH_ADDR_LEN 6
37
HdfStubDriver(void)38 struct HdfWlanStubData *HdfStubDriver(void)
39 {
40 static struct HdfWlanStubData registerManager;
41 return ®isterManager;
42 }
43
WlanInterfaceStart(struct IWlanInterface * self)44 int32_t WlanInterfaceStart(struct IWlanInterface *self)
45 {
46 int32_t ret;
47
48 (void)self;
49 if (g_wifi == NULL || g_wifi->start == NULL) {
50 HDF_LOGE("%{public}s: g_wifi or g_wifi->start is NULL", __func__);
51 return HDF_FAILURE;
52 }
53 ret = g_wifi->start(g_wifi);
54 if (ret != HDF_SUCCESS) {
55 HDF_LOGE("%{public}s start WiFi failed! error code: %{public}d", __func__, ret);
56 } else {
57 g_wifiCount++;
58 }
59 return ret;
60 }
61
WlanInterfaceStop(struct IWlanInterface * self)62 int32_t WlanInterfaceStop(struct IWlanInterface *self)
63 {
64 int32_t ret;
65
66 (void)self;
67 if (g_wifi == NULL || g_wifi->stop == NULL) {
68 HDF_LOGE("%{public}s: g_wifi or g_wifi->stop is NULL", __func__);
69 return HDF_FAILURE;
70 }
71 g_wifiCount--;
72 if (g_wifiCount > 0) {
73 HDF_LOGE("%{public}s: g_wifi is used!", __func__);
74 return HDF_SUCCESS;
75 }
76 ret = g_wifi->stop(g_wifi);
77 if (ret != HDF_SUCCESS) {
78 HDF_LOGE("%{public}s stop WiFi failed! error code: %{public}d", __func__, ret);
79 }
80 return ret;
81 }
82
WlanInterfaceCreateFeature(struct IWlanInterface * self,int32_t type,struct HdfFeatureInfo * ifeature)83 int32_t WlanInterfaceCreateFeature(struct IWlanInterface *self, int32_t type, struct HdfFeatureInfo *ifeature)
84 {
85 int32_t ret = HDF_FAILURE;
86
87 (void)self;
88 if (ifeature == NULL) {
89 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
90 return HDF_ERR_INVALID_PARAM;
91 }
92 if (g_wifi == NULL || g_wifi->createFeature == NULL) {
93 HDF_LOGE("%{public}s: g_wifi or g_wifi->createFeature is NULL", __func__);
94 return HDF_FAILURE;
95 }
96 if (type == PROTOCOL_80211_IFTYPE_AP) {
97 ret = g_wifi->createFeature(type, (struct IWiFiBaseFeature **)&g_apFeature);
98 if (ret != HDF_SUCCESS) {
99 HDF_LOGE("%{public}s: createAPFeature failed, error code: %{public}d", __func__, ret);
100 return HDF_FAILURE;
101 }
102 if (g_apFeature != NULL) {
103 g_apFeatureCount++;
104 ifeature->type = g_apFeature->baseFeature.type;
105 ifeature->ifName = strdup((g_apFeature->baseFeature).ifName);
106 }
107 } else if (type == PROTOCOL_80211_IFTYPE_STATION) {
108 ret = g_wifi->createFeature(type, (struct IWiFiBaseFeature **)&g_staFeature);
109 if (ret != HDF_SUCCESS) {
110 HDF_LOGE("%{public}s: createSTAFeature failed, error code: %{public}d", __func__, ret);
111 return HDF_FAILURE;
112 }
113 if (g_staFeature != NULL) {
114 g_staFeatureCount++;
115 ifeature->type = g_staFeature->baseFeature.type;
116 ifeature->ifName = strdup((g_staFeature->baseFeature).ifName);
117 }
118 } else {
119 HDF_LOGE("%{public}s: wlan type is Invalid", __func__);
120 }
121 return ret;
122 }
123
WlanInterfaceDestroyFeature(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature)124 int32_t WlanInterfaceDestroyFeature(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature)
125 {
126 int32_t ret = HDF_FAILURE;
127
128 (void)self;
129 if (ifeature == NULL || ifeature->ifName == NULL) {
130 HDF_LOGE("%{public}s input parameter invalid!", __func__);
131 return HDF_ERR_INVALID_PARAM;
132 }
133 if (g_wifi == NULL || g_wifi->destroyFeature == NULL) {
134 HDF_LOGE("%{public}s: g_wifi or g_wifi->destroyFeature is NULL", __func__);
135 return HDF_FAILURE;
136 }
137 if (ifeature->type == PROTOCOL_80211_IFTYPE_AP) {
138 if (g_apFeature == NULL) {
139 HDF_LOGE("%{public}s g_apFeature is NULL!", __func__);
140 return HDF_FAILURE;
141 }
142 g_apFeatureCount--;
143 if (g_apFeatureCount > 0) {
144 HDF_LOGI("%{public}s: apFeature is used!", __func__);
145 return HDF_SUCCESS;
146 }
147 ret = strcpy_s((g_apFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName);
148 if (ret != HDF_SUCCESS) {
149 HDF_LOGE("%{public}s: strcpy_s apFeature ifName is failed!", __func__);
150 return HDF_FAILURE;
151 }
152 ret = g_wifi->destroyFeature(&(g_apFeature->baseFeature));
153 g_apFeature = NULL;
154 } else if (ifeature->type == PROTOCOL_80211_IFTYPE_STATION) {
155 if (g_staFeature == NULL) {
156 HDF_LOGE("%{public}s g_staFeature is NULL!", __func__);
157 return HDF_FAILURE;
158 }
159 g_staFeatureCount--;
160 if (g_staFeatureCount > 0) {
161 HDF_LOGI("%{public}s: staFeature is used!", __func__);
162 return HDF_SUCCESS;
163 }
164 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName);
165 if (ret != HDF_SUCCESS) {
166 HDF_LOGE("%{public}s: strcpy_s staFeature ifName is failed!", __func__);
167 return HDF_FAILURE;
168 }
169 ret = g_wifi->destroyFeature(&(g_staFeature->baseFeature));
170 g_staFeature = NULL;
171 } else {
172 HDF_LOGE("%{public}s: wlan type is invalid", __func__);
173 }
174 return ret;
175 }
176
WlanInterfaceGetAssociatedStas(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,struct HdfStaInfo * staInfo,uint32_t * staInfoLen,uint32_t * num)177 int32_t WlanInterfaceGetAssociatedStas(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
178 struct HdfStaInfo *staInfo, uint32_t *staInfoLen, uint32_t *num)
179 {
180 int32_t ret;
181
182 (void)self;
183 if (ifeature == NULL || ifeature->ifName == NULL || staInfo == NULL || staInfoLen == NULL || num == NULL) {
184 HDF_LOGE("%{public}s:input parameter invalid!", __func__);
185 return HDF_ERR_INVALID_PARAM;
186 }
187 if (g_apFeature == NULL || g_apFeature->getAssociatedStas == NULL) {
188 HDF_LOGE("%{public}s g_apFeature or g_apFeature->getAssociatedStas is NULL!", __func__);
189 return HDF_FAILURE;
190 }
191 ret = strcpy_s((g_apFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName);
192 if (ret != HDF_SUCCESS) {
193 HDF_LOGE("%{public}s: strcpy_s apFeature ifName is failed!", __func__);
194 return HDF_FAILURE;
195 }
196
197 struct StaInfo *wifiStaInfo = (struct StaInfo *)OsalMemCalloc(sizeof(struct StaInfo) * (*staInfoLen));
198 if (wifiStaInfo == NULL) {
199 HDF_LOGE("%{public}s:OsalMemCalloc failed!", __func__);
200 return HDF_FAILURE;
201 }
202 ret = g_apFeature->getAssociatedStas(g_apFeature, wifiStaInfo, *staInfoLen, num);
203 if (ret != HDF_SUCCESS) {
204 HDF_LOGE("%{public}s get associated sta failed!, error code: %{public}d", __func__, ret);
205 OsalMemFree(wifiStaInfo);
206 return ret;
207 }
208 for (uint32_t i = 0; i < (*num); i++) {
209 staInfo[i].mac = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * ETH_ADDR_LEN);
210 if (staInfo[i].mac != NULL) {
211 if (memcpy_s(staInfo[i].mac, WIFI_MAC_ADDR_LENGTH, wifiStaInfo[i].mac, WIFI_MAC_ADDR_LENGTH) != EOK) {
212 HDF_LOGE("%{public}s fail : memcpy_s mac fail!", __func__);
213 ret = HDF_FAILURE;
214 break;
215 }
216 staInfo[i].macLen = WIFI_MAC_ADDR_LENGTH;
217 }
218 }
219 OsalMemFree(wifiStaInfo);
220 return ret;
221 }
222
GetBasefeature(const struct HdfFeatureInfo * ifeature,struct IWiFiBaseFeature ** baseFeature)223 static int32_t GetBasefeature(const struct HdfFeatureInfo *ifeature, struct IWiFiBaseFeature **baseFeature)
224 {
225 if (ifeature->type == PROTOCOL_80211_IFTYPE_AP) {
226 if (g_apFeature == NULL) {
227 HDF_LOGE("%{public}s g_apFeature is NULL!", __func__);
228 return HDF_FAILURE;
229 }
230 *baseFeature = &(g_apFeature->baseFeature);
231 } else if (ifeature->type == PROTOCOL_80211_IFTYPE_STATION) {
232 if (g_staFeature == NULL) {
233 HDF_LOGE("%{public}s g_staFeature is NULL!", __func__);
234 return HDF_FAILURE;
235 }
236 *baseFeature = &(g_staFeature->baseFeature);
237 } else {
238 HDF_LOGE("%{public}s: wlan type is Invalid, featureType is %{public}d", __func__, ifeature->type);
239 return HDF_FAILURE;
240 }
241 return HDF_SUCCESS;
242 }
243
WlanInterfaceGetChipId(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,uint8_t * chipId)244 int32_t WlanInterfaceGetChipId(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, uint8_t *chipId)
245 {
246 int32_t ret = HDF_FAILURE;
247 struct IWiFiBaseFeature *baseFeature = NULL;
248
249 (void)self;
250 if (ifeature == NULL || ifeature->ifName == NULL || chipId == NULL) {
251 HDF_LOGE("%{public}s ifeature or ifName is NULL!", __func__);
252 return HDF_ERR_INVALID_PARAM;
253 }
254 ret = GetBasefeature(ifeature, &baseFeature);
255 if (ret != HDF_SUCCESS) {
256 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
257 return HDF_FAILURE;
258 }
259 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
260 if (ret != HDF_SUCCESS) {
261 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
262 return HDF_FAILURE;
263 }
264
265 return baseFeature->getChipId(baseFeature, chipId);
266 }
267
WlanInterfaceGetDeviceMacAddress(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,uint8_t * mac,uint32_t * macLen,uint8_t len)268 int32_t WlanInterfaceGetDeviceMacAddress(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
269 uint8_t *mac, uint32_t *macLen, uint8_t len)
270 {
271 int32_t ret = HDF_FAILURE;
272 struct IWiFiBaseFeature *baseFeature = NULL;
273
274 (void)self;
275 if (ifeature == NULL || ifeature->ifName == NULL || mac == NULL || macLen == NULL) {
276 HDF_LOGE("%{public}s input parameter invalid!", __func__);
277 return HDF_ERR_INVALID_PARAM;
278 }
279 ret = GetBasefeature(ifeature, &baseFeature);
280 if (ret != HDF_SUCCESS) {
281 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
282 return HDF_FAILURE;
283 }
284 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
285 if (ret != HDF_SUCCESS) {
286 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
287 return HDF_FAILURE;
288 }
289 ret = baseFeature->getDeviceMacAddress(baseFeature, mac, len);
290 *macLen = ETH_ADDR_LEN;
291 return ret;
292 }
293
WlanInterfaceGetFeatureByIfName(struct IWlanInterface * self,const char * ifName,struct HdfFeatureInfo * ifeature)294 int32_t WlanInterfaceGetFeatureByIfName(struct IWlanInterface *self, const char *ifName,
295 struct HdfFeatureInfo *ifeature)
296 {
297 int32_t ret;
298 struct IWiFiBaseFeature *baseFeature = NULL;
299
300 (void)self;
301 if (ifName == NULL || ifeature == NULL) {
302 HDF_LOGE("%{public}s input parameter invalid!", __func__);
303 return HDF_ERR_INVALID_PARAM;
304 }
305 if (g_wifi == NULL || g_wifi->getFeatureByIfName == NULL) {
306 HDF_LOGE("%{public}s gwifi or g_wifi->getFeatureByIfName is NULL!", __func__);
307 return HDF_FAILURE;
308 }
309 ret = g_wifi->getFeatureByIfName(ifName, (struct IWiFiBaseFeature **)&baseFeature);
310 if (ret != HDF_SUCCESS) {
311 HDF_LOGE("%{public}s get FeatureByIfName failed!, error code: %{public}d", __func__, ret);
312 return ret;
313 }
314 if (baseFeature == NULL) {
315 HDF_LOGE("%{public}s baseFeature is NULL!", __func__);
316 return HDF_FAILURE;
317 }
318 ifeature->type = baseFeature->type;
319 ifeature->ifName = strdup(baseFeature->ifName);
320 return ret;
321 }
322
WlanInterfaceGetFeatureType(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,int32_t * featureType)323 int32_t WlanInterfaceGetFeatureType(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
324 int32_t *featureType)
325 {
326 (void)self;
327 int32_t ret;
328 int32_t type;
329 struct IWiFiBaseFeature *baseFeature = NULL;
330
331 if (ifeature == NULL || featureType == NULL) {
332 HDF_LOGE("%{public}s input parameter invalid!", __func__);
333 return HDF_ERR_INVALID_PARAM;
334 }
335 ret = GetBasefeature(ifeature, &baseFeature);
336 if (ret != HDF_SUCCESS) {
337 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
338 return HDF_FAILURE;
339 }
340 baseFeature->type = ifeature->type;
341 type = baseFeature->getFeatureType(baseFeature);
342 *featureType = type;
343 return HDF_SUCCESS;
344 }
345
WlanInterfaceGetFreqsWithBand(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,const struct HdfWifiInfo * wifiInfo,int32_t * freq,uint32_t * freqLen)346 int32_t WlanInterfaceGetFreqsWithBand(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
347 const struct HdfWifiInfo *wifiInfo, int32_t *freq, uint32_t *freqLen)
348 {
349 int32_t ret;
350 struct IWiFiBaseFeature *baseFeature = NULL;
351
352 (void)self;
353 if (ifeature == NULL || ifeature->ifName == NULL || freq == NULL || freqLen == NULL || wifiInfo == NULL) {
354 HDF_LOGE("%{public}s input parameter invalid!", __func__);
355 return HDF_ERR_INVALID_PARAM;
356 }
357 ret = GetBasefeature(ifeature, &baseFeature);
358 if (ret != HDF_SUCCESS) {
359 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
360 return HDF_FAILURE;
361 }
362 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
363 if (ret != HDF_SUCCESS) {
364 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
365 return HDF_FAILURE;
366 }
367
368 return baseFeature->getValidFreqsWithBand(baseFeature, wifiInfo->band, freq, wifiInfo->size, freqLen);
369 }
370
WlanInterfaceGetIfNamesByChipId(struct IWlanInterface * self,uint8_t chipId,char * ifName,uint32_t ifNameLen,uint32_t * num)371 int32_t WlanInterfaceGetIfNamesByChipId(struct IWlanInterface *self, uint8_t chipId, char *ifName,
372 uint32_t ifNameLen, uint32_t *num)
373 {
374 int32_t ret;
375
376 (void)self;
377 if (ifName == NULL || num == NULL) {
378 HDF_LOGE("%{public}s input parameter invalid!", __func__);
379 return HDF_ERR_INVALID_PARAM;
380 }
381 char *name = NULL;
382
383 if (g_staFeature != NULL) {
384 HDF_LOGD("%{public}s g_staFeature is not NULL!", __func__);
385 ret = g_staFeature->baseFeature.getIfNamesByChipId(chipId, &name, num);
386 } else if (g_apFeature != NULL) {
387 HDF_LOGD("%{public}s g_apFeature is not NULL!", __func__);
388 ret = g_apFeature->baseFeature.getIfNamesByChipId(chipId, &name, num);
389 } else {
390 HDF_LOGE("%{public}s: ap and sta feature is Invalid.", __func__);
391 ret = HDF_FAILURE;
392 }
393
394 if (ret != HDF_SUCCESS) {
395 HDF_LOGE("%{public}s get name failed!, error code: %{public}d", __func__, ret);
396 return ret;
397 }
398
399 if (name != NULL) {
400 if (strcpy_s(ifName, ifNameLen, name) != EOK) {
401 HDF_LOGE("%{public}s: copy ifName failed!", __func__);
402 return HDF_FAILURE;
403 }
404 }
405 return ret;
406 }
407
WlanInterfaceGetNetworkIfaceName(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,char * ifName,uint32_t ifNameLen)408 int32_t WlanInterfaceGetNetworkIfaceName(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
409 char *ifName, uint32_t ifNameLen)
410 {
411 int32_t ret;
412 const char *name = NULL;
413 struct IWiFiBaseFeature *baseFeature = NULL;
414
415 (void)self;
416 if (ifeature == NULL || ifeature->ifName == NULL || ifName == NULL) {
417 HDF_LOGE("%{public}s input parameter invalid!", __func__);
418 return HDF_ERR_INVALID_PARAM;
419 }
420 ret = GetBasefeature(ifeature, &baseFeature);
421 if (ret != HDF_SUCCESS) {
422 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
423 return HDF_FAILURE;
424 }
425 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
426 if (ret != HDF_SUCCESS) {
427 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
428 return HDF_FAILURE;
429 }
430 name = baseFeature->getNetworkIfaceName(baseFeature);
431 if (name == NULL) {
432 HDF_LOGE("%{public}s get network iface name failed!", __func__);
433 return HDF_FAILURE;
434 }
435 if (strcpy_s(ifName, ifNameLen, name) != EOK) {
436 HDF_LOGE("%{public}s: copy ifName failed!", __func__);
437 return HDF_FAILURE;
438 }
439 return HDF_SUCCESS;
440 }
441
WlanInterfaceGetSupportCombo(struct IWlanInterface * self,uint64_t * combo)442 int32_t WlanInterfaceGetSupportCombo(struct IWlanInterface *self, uint64_t *combo)
443 {
444 int32_t ret;
445
446 (void)self;
447 if (combo == NULL) {
448 HDF_LOGE("%{public}s input parameter invalid!", __func__);
449 return HDF_ERR_INVALID_PARAM;
450 }
451 if (g_wifi == NULL || g_wifi->getSupportCombo == NULL) {
452 HDF_LOGE("%{public}s g_wifi or g_wifi->getSupportCombo is NULL!", __func__);
453 return HDF_FAILURE;
454 }
455 ret = g_wifi->getSupportCombo(combo, DEFAULT_COMBO_SIZE);
456 if (ret == HDF_ERR_NOT_SUPPORT) {
457 HDF_LOGW("%{public}s: not support to getting combo!, error code: %{public}d", __func__, ret);
458 }
459 return ret;
460 }
461
WlanInterfaceGetSupportFeature(struct IWlanInterface * self,uint8_t * supType,uint32_t * supTypeLen)462 int32_t WlanInterfaceGetSupportFeature(struct IWlanInterface *self, uint8_t *supType, uint32_t *supTypeLen)
463 {
464 int32_t ret;
465
466 (void)self;
467 if (supType == NULL || supTypeLen == NULL) {
468 HDF_LOGE("%{public}s input parameter invalid!", __func__);
469 return HDF_ERR_INVALID_PARAM;
470 }
471 if (g_wifi == NULL || g_wifi->getSupportFeature == NULL) {
472 HDF_LOGE("%{public}s g_wifi or g_wifi->getSupportFeature is NULL!", __func__);
473 return HDF_FAILURE;
474 }
475 ret = g_wifi->getSupportFeature(supType, *supTypeLen);
476 if (ret != HDF_SUCCESS) {
477 HDF_LOGE("%{public}s get support feature failed! error code: %{public}d", __func__, ret);
478 }
479 return ret;
480 }
481
HdfWlanAddRemoteObj(struct IWlanCallback * self)482 static int32_t HdfWlanAddRemoteObj(struct IWlanCallback *self)
483 {
484 struct HdfWlanRemoteNode *pos = NULL;
485 struct DListHead *head = &HdfStubDriver()->remoteListHead;
486
487 if (self == NULL) {
488 HDF_LOGE("%{public}s:self == NULL", __func__);
489 return HDF_ERR_INVALID_PARAM;
490 }
491 if (!DListIsEmpty(head)) {
492 DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWlanRemoteNode, node) {
493 if (pos->service == self->AsObject(self)) {
494 HDF_LOGE("%{public}s: pos->service == self", __func__);
495 return HDF_FAILURE;
496 }
497 }
498 }
499
500 struct HdfWlanRemoteNode *newRemoteNode =
501 (struct HdfWlanRemoteNode *)OsalMemCalloc(sizeof(struct HdfWlanRemoteNode));
502 if (newRemoteNode == NULL) {
503 HDF_LOGE("%{public}s:newRemoteNode is NULL", __func__);
504 return HDF_FAILURE;
505 }
506
507 newRemoteNode->callbackObj = self;
508 newRemoteNode->service = self->AsObject(self);
509 DListInsertTail(&newRemoteNode->node, head);
510 return HDF_SUCCESS;
511 }
512
FillData(uint8_t ** dst,uint32_t * dstLen,uint8_t * src,uint32_t srcLen)513 static int32_t FillData(uint8_t **dst, uint32_t *dstLen, uint8_t *src, uint32_t srcLen)
514 {
515 if (src == NULL || dst == NULL || dstLen == NULL) {
516 HDF_LOGE("%{public}s: Invalid parameter!", __func__);
517 return HDF_ERR_INVALID_PARAM;
518 }
519 *dst = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * srcLen);
520 if (*dst == NULL) {
521 HDF_LOGE("%{public}s: OsalMemCalloc fail!", __func__);
522 return HDF_FAILURE;
523 }
524 if (memcpy_s(*dst, srcLen, src, srcLen) != EOK) {
525 HDF_LOGE("%{public}s: memcpy_s fail!", __func__);
526 return HDF_FAILURE;
527 }
528 *dstLen = srcLen;
529 return HDF_SUCCESS;
530 }
531
WlanFillScanResultInfo(WifiScanResult * wifiScanResult,struct HdfWifiScanResult * scanResult)532 static int32_t WlanFillScanResultInfo(WifiScanResult *wifiScanResult, struct HdfWifiScanResult *scanResult)
533 {
534 int32_t ret = HDF_SUCCESS;
535 if (wifiScanResult == NULL || scanResult == NULL) {
536 HDF_LOGE("%{public}s: wifiScanResult or scanResult is NULL!", __func__);
537 return HDF_ERR_INVALID_PARAM;
538 }
539 scanResult->flags = wifiScanResult->flags;
540 scanResult->caps = wifiScanResult->caps;
541 scanResult->freq = wifiScanResult->freq;
542 scanResult->beaconInt = wifiScanResult->beaconInt;
543 scanResult->qual = wifiScanResult->qual;
544 scanResult->level = wifiScanResult->level;
545 scanResult->age = wifiScanResult->age;
546 do {
547 if (wifiScanResult->bssid != NULL &&
548 FillData(&scanResult->bssid, &scanResult->bssidLen, wifiScanResult->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
549 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
550 ret = HDF_FAILURE;
551 break;
552 }
553 if ((wifiScanResult->ie != NULL) && (wifiScanResult->ieLen != 0) &&
554 FillData(&scanResult->ie, &scanResult->ieLen, wifiScanResult->ie, wifiScanResult->ieLen) != HDF_SUCCESS) {
555 HDF_LOGE("%{public}s: fill ie fail!", __func__);
556 ret = HDF_FAILURE;
557 break;
558 }
559 if ((wifiScanResult->beaconIe != NULL) && (wifiScanResult->beaconIeLen != 0) &&
560 FillData(&scanResult->beaconIe, &scanResult->beaconIeLen, wifiScanResult->beaconIe,
561 wifiScanResult->beaconIeLen) != HDF_SUCCESS) {
562 HDF_LOGE("%{public}s: fill beaconIe fail!", __func__);
563 ret = HDF_FAILURE;
564 }
565 } while (0);
566 if (ret != HDF_SUCCESS) {
567 if (scanResult->bssid != NULL) {
568 OsalMemFree(scanResult->bssid);
569 }
570 if (scanResult->ie != NULL) {
571 OsalMemFree(scanResult->ie);
572 }
573 if (scanResult->beaconIe != NULL) {
574 OsalMemFree(scanResult->beaconIe);
575 }
576 }
577 return ret;
578 }
579
WlanFillScanResultInfoExt(WifiScanResult * wifiScanResult,struct HdfWifiScanResultExt * scanResult)580 static int32_t WlanFillScanResultInfoExt(WifiScanResult *wifiScanResult, struct HdfWifiScanResultExt *scanResult)
581 {
582 int32_t ret = HDF_SUCCESS;
583 if (wifiScanResult == NULL || scanResult == NULL) {
584 HDF_LOGE("%{public}s: wifiScanResult or scanResult is NULL!", __func__);
585 return HDF_ERR_INVALID_PARAM;
586 }
587 scanResult->flags = wifiScanResult->flags;
588 scanResult->caps = wifiScanResult->caps;
589 scanResult->freq = wifiScanResult->freq;
590 scanResult->beaconInt = wifiScanResult->beaconInt;
591 scanResult->qual = wifiScanResult->qual;
592 scanResult->level = wifiScanResult->level;
593 scanResult->age = wifiScanResult->age;
594 scanResult->tsf = wifiScanResult->tsf;
595 do {
596 if (wifiScanResult->bssid != NULL &&
597 FillData(&scanResult->bssid, &scanResult->bssidLen, wifiScanResult->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) {
598 HDF_LOGE("%{public}s: fill bssid fail!", __func__);
599 ret = HDF_FAILURE;
600 break;
601 }
602 if ((wifiScanResult->ie != NULL) && (wifiScanResult->ieLen != 0) &&
603 FillData(&scanResult->ie, &scanResult->ieLen, wifiScanResult->ie, wifiScanResult->ieLen) != HDF_SUCCESS) {
604 HDF_LOGE("%{public}s: fill ie fail!", __func__);
605 ret = HDF_FAILURE;
606 break;
607 }
608 if ((wifiScanResult->beaconIe != NULL) && (wifiScanResult->beaconIeLen != 0) &&
609 FillData(&scanResult->beaconIe, &scanResult->beaconIeLen, wifiScanResult->beaconIe,
610 wifiScanResult->beaconIeLen) != HDF_SUCCESS) {
611 HDF_LOGE("%{public}s: fill beaconIe fail!", __func__);
612 ret = HDF_FAILURE;
613 }
614 } while (0);
615 if (ret != HDF_SUCCESS) {
616 if (scanResult->bssid != NULL) {
617 OsalMemFree(scanResult->bssid);
618 }
619 if (scanResult->ie != NULL) {
620 OsalMemFree(scanResult->ie);
621 }
622 if (scanResult->beaconIe != NULL) {
623 OsalMemFree(scanResult->beaconIe);
624 }
625 }
626 return ret;
627 }
628
WlanFillScanResultsInfo(WifiScanResults * wifiScanResults,struct HdfWifiScanResults * scanResults)629 static int32_t WlanFillScanResultsInfo(WifiScanResults *wifiScanResults, struct HdfWifiScanResults *scanResults)
630 {
631 uint32_t i;
632 if (wifiScanResults == NULL || scanResults == NULL) {
633 HDF_LOGE("%{public}s: wifiScanResults or scanResults is NULL!", __func__);
634 return HDF_ERR_INVALID_PARAM;
635 }
636 for (i = 0; i < wifiScanResults->num; i++) {
637 if (WlanFillScanResultInfoExt(&wifiScanResults->scanResult[i], &scanResults->res[i]) != HDF_SUCCESS) {
638 return HDF_FAILURE;
639 }
640 }
641 scanResults->resLen = wifiScanResults->num;
642 return HDF_SUCCESS;
643 }
644
ProcessEventScanResult(struct HdfWlanRemoteNode * node,uint32_t event,WifiScanResult * wifiScanResult,const char * ifName)645 static int32_t ProcessEventScanResult(struct HdfWlanRemoteNode *node, uint32_t event, WifiScanResult *wifiScanResult,
646 const char *ifName)
647 {
648 struct HdfWifiScanResult *scanResult = NULL;
649 int32_t ret = HDF_FAILURE;
650
651 if (node == NULL || node->callbackObj == NULL || node->callbackObj->ScanResult == NULL) {
652 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
653 return HDF_ERR_INVALID_PARAM;
654 }
655 scanResult = (struct HdfWifiScanResult *)OsalMemCalloc(sizeof(struct HdfWifiScanResult));
656 if ((scanResult == NULL) || (WlanFillScanResultInfo(wifiScanResult, scanResult) != HDF_SUCCESS)) {
657 HDF_LOGE("%{public}s: scanResult is NULL or WlanFillScanResultInfo fialed!", __func__);
658 } else {
659 ret = node->callbackObj->ScanResult(node->callbackObj, event, scanResult, ifName);
660 }
661 HdfWifiScanResultFree(scanResult, true);
662 return ret;
663 }
664
ProcessEventScanResults(struct HdfWlanRemoteNode * node,uint32_t event,WifiScanResults * wifiScanResults,const char * ifName)665 static int32_t ProcessEventScanResults(struct HdfWlanRemoteNode *node, uint32_t event,
666 WifiScanResults *wifiScanResults, const char *ifName)
667 {
668 struct HdfWifiScanResults *scanResults = NULL;
669 uint32_t size;
670 int32_t ret = HDF_FAILURE;
671
672 if (node == NULL || node->callbackObj == NULL || node->callbackObj->ScanResults == NULL) {
673 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
674 return HDF_ERR_INVALID_PARAM;
675 }
676 scanResults = (struct HdfWifiScanResults *)OsalMemCalloc(sizeof(struct HdfWifiScanResults));
677 if (scanResults == NULL) {
678 HDF_LOGE("%{public}s: scanResults is NULL!", __func__);
679 return HDF_ERR_MALLOC_FAIL;
680 }
681 scanResults->resLen = wifiScanResults->num;
682 size = sizeof(struct HdfWifiScanResultExt);
683 scanResults->res = (struct HdfWifiScanResultExt *)OsalMemCalloc(size * scanResults->resLen);
684 if ((scanResults->res == NULL) || (WlanFillScanResultsInfo(wifiScanResults, scanResults) != HDF_SUCCESS)) {
685 HDF_LOGE("%{public}s: scanResults->res is NULL or WlanFillScanResultsInfo fialed!", __func__);
686 } else {
687 ret = node->callbackObj->ScanResults(node->callbackObj, event, scanResults, ifName);
688 }
689 HdfWifiScanResultsFree(scanResults, true);
690 return ret;
691 }
692
ProcessEventScanAborted(struct HdfWlanRemoteNode * node,uint32_t event,const char * ifName)693 static int32_t ProcessEventScanAborted(struct HdfWlanRemoteNode *node, uint32_t event, const char *ifName)
694 {
695 int32_t ret = HDF_FAILURE;
696 struct HdfWifiScanResults scanResults = {0};
697
698 if (node == NULL || node->callbackObj == NULL || node->callbackObj->ScanResults == NULL) {
699 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__);
700 return HDF_ERR_INVALID_PARAM;
701 }
702 ret = node->callbackObj->ScanResults(node->callbackObj, event, &scanResults, ifName);
703 return ret;
704 }
705
HdfWLanCallbackFun(uint32_t event,void * data,const char * ifName)706 static int32_t HdfWLanCallbackFun(uint32_t event, void *data, const char *ifName)
707 {
708 struct HdfWlanRemoteNode *pos = NULL;
709 struct DListHead *head = NULL;
710 int32_t *code = NULL;
711 int32_t ret = HDF_FAILURE;
712 (void)OsalMutexLock(&HdfStubDriver()->mutex);
713 head = &HdfStubDriver()->remoteListHead;
714
715 if (data == NULL || ifName == NULL) {
716 HDF_LOGE("%{public}s: data or ifName is NULL!", __func__);
717 (void)OsalMutexUnlock(&HdfStubDriver()->mutex);
718 return HDF_ERR_INVALID_PARAM;
719 }
720 DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWlanRemoteNode, node) {
721 if (pos == NULL) {
722 HDF_LOGE("%{public}s: pos is NULL", __func__);
723 break;
724 }
725 if (pos->service == NULL || pos->callbackObj == NULL) {
726 HDF_LOGW("%{public}s: pos->service or pos->callbackObj NULL", __func__);
727 continue;
728 }
729 switch (event) {
730 case WIFI_EVENT_RESET_DRIVER:
731 code = (int32_t *)data;
732 ret = pos->callbackObj->ResetDriverResult(pos->callbackObj, event, *code, ifName);
733 break;
734 case WIFI_EVENT_SCAN_RESULT:
735 ret = ProcessEventScanResult(pos, event, (WifiScanResult *)data, ifName);
736 break;
737 case WIFI_EVENT_SCAN_RESULTS:
738 ret = ProcessEventScanResults(pos, event, (WifiScanResults *)data, ifName);
739 break;
740 case WIFI_EVENT_SCAN_ABORTED:
741 ret = ProcessEventScanAborted(pos, event, ifName);
742 break;
743 default:
744 HDF_LOGE("%{public}s: unknown eventId:%{public}d", __func__, event);
745 break;
746 }
747 if (ret != HDF_SUCCESS) {
748 HDF_LOGE("%{public}s: dispatch code fialed, error code: %{public}d", __func__, ret);
749 }
750 }
751 (void)OsalMutexUnlock(&HdfStubDriver()->mutex);
752 return ret;
753 }
754
HdfWlanNetlinkCallbackFun(const uint8_t * recvMsg,uint32_t recvMsgLen)755 static int32_t HdfWlanNetlinkCallbackFun(const uint8_t *recvMsg, uint32_t recvMsgLen)
756 {
757 struct HdfWlanRemoteNode *pos = NULL;
758 struct DListHead *head = NULL;
759 int32_t ret = HDF_FAILURE;
760 (void)OsalMutexLock(&HdfStubDriver()->mutex);
761 head = &HdfStubDriver()->remoteListHead;
762
763 if (recvMsg == NULL) {
764 HDF_LOGE("%{public}s: recvMsg or ifName is NULL!", __func__);
765 (void)OsalMutexUnlock(&HdfStubDriver()->mutex);
766 return HDF_ERR_INVALID_PARAM;
767 }
768 DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWlanRemoteNode, node) {
769 if (pos->service == NULL || pos->callbackObj == NULL) {
770 HDF_LOGW("%{public}s: pos->service or pos->callbackObj NULL", __func__);
771 continue;
772 }
773 ret = pos->callbackObj->WifiNetlinkMessage(pos->callbackObj, recvMsg, recvMsgLen);
774 if (ret != HDF_SUCCESS) {
775 HDF_LOGE("%{public}s: dispatch code fialed, error code: %{public}d", __func__, ret);
776 }
777 }
778 (void)OsalMutexUnlock(&HdfStubDriver()->mutex);
779 return ret;
780 }
781
HdfWlanDelRemoteObj(struct IWlanCallback * self)782 static void HdfWlanDelRemoteObj(struct IWlanCallback *self)
783 {
784 struct HdfWlanRemoteNode *pos = NULL;
785 struct HdfWlanRemoteNode *tmp = NULL;
786 struct DListHead *head = &HdfStubDriver()->remoteListHead;
787
788 DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, head, struct HdfWlanRemoteNode, node) {
789 if (pos->service->index == self->AsObject(self)->index) {
790 DListRemove(&(pos->node));
791 IWlanCallbackRelease(pos->callbackObj);
792 OsalMemFree(pos);
793 break;
794 }
795 }
796 IWlanCallbackRelease(self);
797 }
798
WlanInterfaceRegisterEventCallback(struct IWlanInterface * self,struct IWlanCallback * cbFunc,const char * ifName)799 int32_t WlanInterfaceRegisterEventCallback(struct IWlanInterface *self, struct IWlanCallback *cbFunc,
800 const char *ifName)
801 {
802 int32_t ret;
803
804 (void)self;
805 if (cbFunc == NULL || ifName == NULL) {
806 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
807 return HDF_ERR_INVALID_PARAM;
808 }
809 if (g_wifi == NULL || g_wifi->registerEventCallback == NULL) {
810 HDF_LOGE("%{public}s g_wifi or g_wifi->registerEventCallback is NULL!", __func__);
811 return HDF_FAILURE;
812 }
813 (void)OsalMutexLock(&HdfStubDriver()->mutex);
814
815 do {
816 ret = HdfWlanAddRemoteObj(cbFunc);
817 if (ret != HDF_SUCCESS) {
818 HDF_LOGE("%{public}s: HdfSensorAddRemoteObj false", __func__);
819 break;
820 }
821 ret = g_wifi->registerEventCallback(HdfWLanCallbackFun, ifName);
822 if (ret != HDF_SUCCESS) {
823 HDF_LOGE("%{public}s: Register failed!, error code: %{public}d", __func__, ret);
824 HdfWlanDelRemoteObj(cbFunc);
825 break;
826 }
827 ret = WlanInterfaceRegisterHid2dCallback(HdfWlanNetlinkCallbackFun, ifName);
828 if (ret != HDF_SUCCESS) {
829 HDF_LOGE("%{public}s: Register failed!, error code: %{public}d", __func__, ret);
830 g_wifi->unregisterEventCallback(HdfWLanCallbackFun, ifName);
831 HdfWlanDelRemoteObj(cbFunc);
832 }
833 } while (0);
834
835 (void)OsalMutexUnlock(&HdfStubDriver()->mutex);
836 return ret;
837 }
838
WlanInterfaceUnregisterEventCallback(struct IWlanInterface * self,struct IWlanCallback * cbFunc,const char * ifName)839 int32_t WlanInterfaceUnregisterEventCallback(struct IWlanInterface *self, struct IWlanCallback *cbFunc,
840 const char *ifName)
841 {
842 int32_t ret;
843
844 (void)self;
845 if (cbFunc == NULL || ifName == NULL) {
846 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
847 return HDF_ERR_INVALID_PARAM;
848 }
849 if (g_wifi == NULL || g_wifi->unregisterEventCallback == NULL) {
850 HDF_LOGE("%{public}s g_wifi or g_wifi->unregisterEventCallback is NULL!", __func__);
851 return HDF_FAILURE;
852 }
853 (void)OsalMutexLock(&HdfStubDriver()->mutex);
854 HdfWlanDelRemoteObj(cbFunc);
855 if (DListIsEmpty(&HdfStubDriver()->remoteListHead)) {
856 ret = g_wifi->unregisterEventCallback(HdfWLanCallbackFun, ifName);
857 if (ret != HDF_SUCCESS) {
858 HDF_LOGE("%{public}s: Unregister failed!, error code: %{public}d", __func__, ret);
859 }
860 ret = WlanInterfaceUnregisterHid2dCallback(HdfWlanNetlinkCallbackFun, ifName);
861 if (ret != HDF_SUCCESS) {
862 HDF_LOGE("%{public}s: Unregister Hid2dCallback failed!, error code: %{public}d", __func__, ret);
863 }
864 }
865 (void)OsalMutexUnlock(&HdfStubDriver()->mutex);
866 return HDF_SUCCESS;
867 }
868
WlanInterfaceResetDriver(struct IWlanInterface * self,uint8_t chipId,const char * ifName)869 int32_t WlanInterfaceResetDriver(struct IWlanInterface *self, uint8_t chipId, const char *ifName)
870 {
871 int32_t ret;
872
873 (void)self;
874 if (ifName == NULL) {
875 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
876 return HDF_ERR_INVALID_PARAM;
877 }
878 if (g_wifi == NULL || g_wifi->resetDriver == NULL) {
879 HDF_LOGE("%{public}s g_wifi or g_wifi->resetDriver is NULL!", __func__);
880 return HDF_FAILURE;
881 }
882 ret = g_wifi->resetDriver(chipId, ifName);
883 if (ret != HDF_SUCCESS) {
884 HDF_LOGE("%{public}s reset driver failed! error code: %{public}d", __func__, ret);
885 return ret;
886 }
887 OsalMSleep(RESET_TIME);
888 return ret;
889 }
890
WlanInterfaceSetCountryCode(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,const char * code,uint32_t len)891 int32_t WlanInterfaceSetCountryCode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
892 const char *code, uint32_t len)
893 {
894 int32_t ret;
895
896 (void)self;
897 if (ifeature == NULL || ifeature->ifName == NULL || code == NULL) {
898 HDF_LOGE("%{public}s input parameter invalid!", __func__);
899 return HDF_ERR_INVALID_PARAM;
900 }
901 if (g_apFeature == NULL || g_apFeature->setCountryCode == NULL) {
902 HDF_LOGE("%{public}s g_apFeature or g_apFeature->setCountryCode is NULL!", __func__);
903 return HDF_FAILURE;
904 }
905 ret = strcpy_s((g_apFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName);
906 if (ret != HDF_SUCCESS) {
907 HDF_LOGE("%{public}s: strcpy_s apFeature ifName is failed!", __func__);
908 return HDF_FAILURE;
909 }
910 ret = g_apFeature->setCountryCode(g_apFeature, code, strlen(code));
911 if (ret != HDF_SUCCESS) {
912 HDF_LOGE("%{public}s set country code failed!, error code: %{public}d", __func__, ret);
913 }
914 return ret;
915 }
916
WlanInterfaceSetMacAddress(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,const uint8_t * mac,uint32_t macLen)917 int32_t WlanInterfaceSetMacAddress(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
918 const uint8_t *mac, uint32_t macLen)
919 {
920 int32_t ret = HDF_FAILURE;
921 struct IWiFiBaseFeature *baseFeature = NULL;
922
923 (void)self;
924 if (ifeature == NULL || mac == NULL || ifeature->ifName == NULL) {
925 HDF_LOGE("%{public}s input parameter invalid!", __func__);
926 return HDF_ERR_INVALID_PARAM;
927 }
928 ret = GetBasefeature(ifeature, &baseFeature);
929 if (ret != HDF_SUCCESS) {
930 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
931 return HDF_FAILURE;
932 }
933 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
934 if (ret != HDF_SUCCESS) {
935 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
936 return HDF_FAILURE;
937 }
938 return baseFeature->setMacAddress(baseFeature, (uint8_t *)mac, ETH_ADDR_LEN);
939 }
940
WlanInterfaceSetScanningMacAddress(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,const uint8_t * scanMac,uint32_t scanMacLen)941 int32_t WlanInterfaceSetScanningMacAddress(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
942 const uint8_t *scanMac, uint32_t scanMacLen)
943 {
944 int32_t ret;
945
946 (void)self;
947 if (ifeature == NULL || ifeature->ifName == NULL || scanMac == NULL) {
948 HDF_LOGE("%{public}s input parameter invalid!", __func__);
949 return HDF_ERR_INVALID_PARAM;
950 }
951 if (g_staFeature == NULL || g_staFeature->setScanningMacAddress == NULL) {
952 HDF_LOGE("%{public}s g_staFeature or g_staFeature->setScanningMacAddress is NULL!", __func__);
953 return HDF_FAILURE;
954 }
955 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName);
956 if (ret != HDF_SUCCESS) {
957 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
958 return HDF_FAILURE;
959 }
960 ret = g_staFeature->setScanningMacAddress(g_staFeature, (uint8_t *)scanMac, (uint8_t)scanMacLen);
961
962 return ret;
963 }
964
WlanInterfaceSetTxPower(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,int32_t power)965 int32_t WlanInterfaceSetTxPower(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, int32_t power)
966 {
967 int32_t ret;
968 struct IWiFiBaseFeature *baseFeature = NULL;
969
970 (void)self;
971 if (ifeature == NULL || ifeature->ifName == NULL) {
972 HDF_LOGE("%{public}s input parameter invalid!", __func__);
973 return HDF_ERR_INVALID_PARAM;
974 }
975 ret = GetBasefeature(ifeature, &baseFeature);
976 if (ret != HDF_SUCCESS) {
977 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
978 return HDF_FAILURE;
979 }
980 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
981 if (ret != HDF_SUCCESS) {
982 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
983 return HDF_FAILURE;
984 }
985
986 return baseFeature->setTxPower(baseFeature, power);
987 }
988
WlanInterfaceGetNetDevInfo(struct IWlanInterface * self,struct HdfNetDeviceInfoResult * netDeviceInfoResult)989 int32_t WlanInterfaceGetNetDevInfo(struct IWlanInterface *self, struct HdfNetDeviceInfoResult *netDeviceInfoResult)
990 {
991 int32_t ret = HDF_FAILURE;
992
993 (void)self;
994 if (g_wifi == NULL || g_wifi->getNetDevInfo == NULL ||netDeviceInfoResult == NULL) {
995 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
996 return HDF_ERR_INVALID_PARAM;
997 }
998 struct NetDeviceInfoResult *netDeviceInfo =
999 (struct NetDeviceInfoResult *)OsalMemCalloc(sizeof(struct NetDeviceInfoResult));
1000 if (netDeviceInfo == NULL) {
1001 HDF_LOGE("%{public}s:OsalMemCalloc failed!", __func__);
1002 return HDF_FAILURE;
1003 }
1004 ret = g_wifi->getNetDevInfo(netDeviceInfo);
1005 if (ret != HDF_SUCCESS) {
1006 HDF_LOGE("%{public}s: get netdev info failed!, error code: %{public}d", __func__, ret);
1007 OsalMemFree(netDeviceInfo);
1008 return HDF_FAILURE;
1009 }
1010
1011 netDeviceInfoResult->deviceInfos =
1012 (struct HdfNetDeviceInfo *)OsalMemCalloc(sizeof(struct HdfNetDeviceInfo) * MAX_NETDEVICE_COUNT);
1013 if (netDeviceInfoResult->deviceInfos == NULL) {
1014 HDF_LOGE("%{public}s:netDeviceInfoResult->deviceInfos OsalMemCalloc failed", __func__);
1015 OsalMemFree(netDeviceInfo);
1016 return HDF_FAILURE;
1017 }
1018 netDeviceInfoResult->deviceInfosLen = MAX_NETDEVICE_COUNT;
1019 for (uint32_t i = 0; i < netDeviceInfoResult->deviceInfosLen; i++) {
1020 netDeviceInfoResult->deviceInfos[i].index = netDeviceInfo->deviceInfos[i].index;
1021 netDeviceInfoResult->deviceInfos[i].iftype = netDeviceInfo->deviceInfos[i].iftype;
1022 netDeviceInfoResult->deviceInfos[i].ifName = (char *)OsalMemCalloc(sizeof(char) * IFNAMSIZ);
1023 if (netDeviceInfoResult->deviceInfos != NULL) {
1024 if (memcpy_s(netDeviceInfoResult->deviceInfos[i].ifName, IFNAMSIZ, netDeviceInfo->deviceInfos[i].ifName,
1025 IFNAMSIZ) != EOK) {
1026 OsalMemFree(netDeviceInfoResult->deviceInfos[i].ifName);
1027 break;
1028 }
1029 netDeviceInfoResult->deviceInfos[i].ifNameLen = IFNAMSIZ;
1030 }
1031 netDeviceInfoResult->deviceInfos[i].mac = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * ETH_ADDR_LEN);
1032 if (netDeviceInfoResult->deviceInfos[i].mac != NULL) {
1033 if (memcpy_s(netDeviceInfoResult->deviceInfos[i].mac, ETH_ADDR_LEN, netDeviceInfo->deviceInfos[i].mac,
1034 ETH_ADDR_LEN) != EOK) {
1035 OsalMemFree(netDeviceInfoResult->deviceInfos[i].mac);
1036 break;
1037 }
1038 netDeviceInfoResult->deviceInfos[i].macLen = ETH_ADDR_LEN;
1039 }
1040 }
1041 OsalMemFree(netDeviceInfo);
1042 return ret;
1043 }
1044
WLanFillSsid(WifiScan * wifiScan,const struct HdfWifiScan * scan)1045 static int32_t WLanFillSsid(WifiScan *wifiScan, const struct HdfWifiScan *scan)
1046 {
1047 uint32_t loop;
1048
1049 for (loop = 0; loop < scan->ssidsLen; loop++) {
1050 if (scan->ssids[loop].ssidLen > MAX_SSID_LEN) {
1051 HDF_LOGW("%{public}s fail : ssidLen is invalid!", __func__);
1052 scan->ssids[loop].ssidLen = MAX_SSID_LEN - 1;
1053 }
1054 if (memcpy_s(wifiScan->ssids[loop].ssid, scan->ssids[loop].ssidLen, scan->ssids[loop].ssid,
1055 scan->ssids[loop].ssidLen) != EOK) {
1056 HDF_LOGE("%{public}s fail : memcpy_s ssids fail!", __func__);
1057 return HDF_FAILURE;
1058 }
1059 wifiScan->ssids[loop].ssidLen = scan->ssids[loop].ssidLen;
1060 }
1061 return HDF_SUCCESS;
1062 }
1063
WLanFillScanData(WifiScan * wifiScan,const struct HdfWifiScan * scan)1064 static int32_t WLanFillScanData(WifiScan *wifiScan, const struct HdfWifiScan *scan)
1065 {
1066 if ((scan->ssids != NULL) && (scan->ssidsLen != 0)) {
1067 wifiScan->ssids = (WifiDriverScanSsid *)OsalMemCalloc(sizeof(WifiDriverScanSsid) * scan->ssidsLen);
1068 if (wifiScan->ssids != NULL) {
1069 if (WLanFillSsid(wifiScan, scan) != HDF_SUCCESS) {
1070 HDF_LOGE("%{public}s fail : fill ssids fail!", __func__);
1071 OsalMemFree(wifiScan->ssids);
1072 return HDF_FAILURE;
1073 }
1074 wifiScan->numSsids = scan->ssidsLen;
1075 }
1076 }
1077
1078 if ((scan->freqs != NULL) && (scan->freqsLen != 0)) {
1079 wifiScan->freqs = (int32_t *)OsalMemCalloc(sizeof(int32_t) * scan->freqsLen);
1080 if (wifiScan->freqs != NULL) {
1081 if (memcpy_s(wifiScan->freqs, sizeof(int32_t) * (scan->freqsLen), scan->freqs,
1082 sizeof(int32_t) * (scan->freqsLen)) != EOK) {
1083 HDF_LOGE("%{public}s fail : memcpy_s freqs fail!", __func__);
1084 OsalMemFree(wifiScan->freqs);
1085 return HDF_FAILURE;
1086 }
1087 wifiScan->numFreqs = scan->freqsLen;
1088 }
1089 }
1090
1091 if ((scan->bssid != NULL) && (scan->bssidLen != 0)) {
1092 wifiScan->bssid = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * scan->bssidLen);
1093 if (wifiScan->bssid != NULL) {
1094 if (memcpy_s(wifiScan->bssid, sizeof(uint8_t) * (scan->bssidLen), scan->bssid,
1095 sizeof(uint8_t) * (scan->bssidLen)) != EOK) {
1096 HDF_LOGE("%{public}s fail : memcpy_s bssid fail!", __func__);
1097 OsalMemFree(wifiScan->bssid);
1098 return HDF_FAILURE;
1099 }
1100 }
1101 }
1102 if ((scan->extraIes != NULL) && (scan->extraIesLen != 0)) {
1103 wifiScan->extraIes = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * scan->extraIesLen);
1104 if (wifiScan->extraIes != NULL) {
1105 if (memcpy_s(wifiScan->extraIes, sizeof(uint8_t) * (scan->extraIesLen), scan->extraIes,
1106 sizeof(uint8_t) * (scan->extraIesLen)) != EOK) {
1107 HDF_LOGE("%{public}s fail : memcpy_s extraIes fail!", __func__);
1108 OsalMemFree(wifiScan->extraIes);
1109 return HDF_FAILURE;
1110 }
1111 wifiScan->extraIesLen = scan->extraIesLen;
1112 }
1113 }
1114
1115 wifiScan->prefixSsidScanFlag = scan->prefixSsidScanFlag;
1116 wifiScan->fastConnectFlag = scan->fastConnectFlag;
1117 return HDF_SUCCESS;
1118 }
1119
WifiScanFree(WifiScan * dataBlock)1120 static void WifiScanFree(WifiScan *dataBlock)
1121 {
1122 if (dataBlock == NULL) {
1123 return;
1124 }
1125
1126 if (dataBlock->ssids != NULL) {
1127 OsalMemFree(dataBlock->ssids);
1128 dataBlock->ssids = NULL;
1129 }
1130 if (dataBlock->freqs != NULL) {
1131 OsalMemFree(dataBlock->freqs);
1132 dataBlock->freqs = NULL;
1133 }
1134 if (dataBlock->bssid != NULL) {
1135 OsalMemFree(dataBlock->bssid);
1136 dataBlock->bssid = NULL;
1137 }
1138 if (dataBlock->extraIes != NULL) {
1139 OsalMemFree(dataBlock->extraIes);
1140 dataBlock->extraIes = NULL;
1141 }
1142 OsalMemFree(dataBlock);
1143 }
1144
WlanInterfaceStartScan(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,const struct HdfWifiScan * scan)1145 int32_t WlanInterfaceStartScan(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
1146 const struct HdfWifiScan *scan)
1147 {
1148 int32_t ret = HDF_FAILURE;
1149
1150 (void)self;
1151 if (ifeature == NULL || ifeature->ifName == NULL || scan == NULL) {
1152 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1153 return HDF_ERR_INVALID_PARAM;
1154 }
1155 WifiScan *wifiScan = (WifiScan *)OsalMemCalloc(sizeof(WifiScan));
1156 if (wifiScan == NULL) {
1157 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__);
1158 return HDF_FAILURE;
1159 }
1160 if (WLanFillScanData(wifiScan, scan) != HDF_SUCCESS) {
1161 HDF_LOGE("%{public}s fail : fill scan data fail!", __func__);
1162 WifiScanFree(wifiScan);
1163 return HDF_FAILURE;
1164 }
1165 if (g_staFeature == NULL || g_staFeature->startScan == NULL) {
1166 HDF_LOGE("%{public}s g_staFeature or g_staFeature->startScan is NULL!", __func__);
1167 WifiScanFree(wifiScan);
1168 return HDF_FAILURE;
1169 }
1170 ret = g_staFeature->startScan(ifeature->ifName, wifiScan);
1171 if (ret != HDF_SUCCESS) {
1172 HDF_LOGE("%{public}s start scan failed!, error code: %{public}d", __func__, ret);
1173 }
1174 WifiScanFree(wifiScan);
1175 return ret;
1176 }
1177
WlanInterfaceGetPowerMode(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,uint8_t * mode)1178 int32_t WlanInterfaceGetPowerMode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, uint8_t *mode)
1179 {
1180 int32_t ret;
1181
1182 (void)self;
1183 if (ifeature == NULL || ifeature->ifName == NULL || mode == NULL) {
1184 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1185 return HDF_ERR_INVALID_PARAM;
1186 }
1187 if (g_wifi == NULL || g_wifi->getPowerMode == NULL) {
1188 HDF_LOGE("%{public}s g_wifi or g_wifi->getPowerMode is NULL!", __func__);
1189 return HDF_FAILURE;
1190 }
1191 ret = g_wifi->getPowerMode(ifeature->ifName, mode);
1192 if (ret != HDF_SUCCESS) {
1193 HDF_LOGE("%{public}s: get power mode failed!, error code: %{public}d", __func__, ret);
1194 }
1195 return ret;
1196 }
1197
WlanInterfaceSetPowerMode(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,uint8_t mode)1198 int32_t WlanInterfaceSetPowerMode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, uint8_t mode)
1199 {
1200 int32_t ret;
1201
1202 (void)self;
1203 if (ifeature == NULL || ifeature->ifName == NULL) {
1204 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1205 return HDF_ERR_INVALID_PARAM;
1206 }
1207 if (g_wifi == NULL || g_wifi->setPowerMode == NULL) {
1208 HDF_LOGE("%{public}s g_wifi or g_wifi->setPowerMode is NULL!", __func__);
1209 return HDF_FAILURE;
1210 }
1211 ret = g_wifi->setPowerMode(ifeature->ifName, mode);
1212 if (ret != HDF_SUCCESS) {
1213 HDF_LOGE("%{public}s: get power mode failed!, error code: %{public}d", __func__, ret);
1214 }
1215 return ret;
1216 }
1217
WlanInterfaceSetProjectionScreenParam(struct IWlanInterface * self,const char * ifName,const struct ProjectionScreenCmdParam * param)1218 int32_t WlanInterfaceSetProjectionScreenParam(struct IWlanInterface *self, const char *ifName,
1219 const struct ProjectionScreenCmdParam *param)
1220 {
1221 int32_t ret;
1222 ProjectionScreenParam *projectionScreenParam = NULL;
1223
1224 (void)self;
1225 if (ifName == NULL || param == NULL) {
1226 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1227 return HDF_ERR_INVALID_PARAM;
1228 }
1229 if (g_wifi == NULL || g_wifi->setProjectionScreenParam == NULL) {
1230 HDF_LOGE("%{public}s g_wifi or g_wifi->setProjectionScreenParam is NULL!", __func__);
1231 return HDF_FAILURE;
1232 }
1233
1234 projectionScreenParam = OsalMemCalloc(sizeof(ProjectionScreenParam) + param->bufLen);
1235 if (projectionScreenParam == NULL) {
1236 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__);
1237 return HDF_FAILURE;
1238 }
1239 projectionScreenParam->cmdId = param->cmdId;
1240 projectionScreenParam->bufLen = param->bufLen;
1241 do {
1242 if (memcpy_s(projectionScreenParam->buf, projectionScreenParam->bufLen, param->buf, param->bufLen) != EOK) {
1243 HDF_LOGE("%{public}s: memcpy_s failed", __func__);
1244 ret = HDF_FAILURE;
1245 break;
1246 }
1247 ret = g_wifi->setProjectionScreenParam(ifName, projectionScreenParam);
1248 if (ret != HDF_SUCCESS) {
1249 HDF_LOGE("%{public}s: get channel meas result failed!, error code: %{public}d", __func__, ret);
1250 }
1251 } while (0);
1252
1253 OsalMemFree(projectionScreenParam);
1254 return ret;
1255 }
1256
WlanInterfaceGetStaInfo(struct IWlanInterface * self,const char * ifName,struct WifiStationInfo * info,const uint8_t * mac,uint32_t macLen)1257 int32_t WlanInterfaceGetStaInfo(struct IWlanInterface *self, const char *ifName, struct WifiStationInfo *info,
1258 const uint8_t *mac, uint32_t macLen)
1259 {
1260 int32_t ret;
1261
1262 (void)self;
1263 if (ifName == NULL || info == NULL || mac == NULL) {
1264 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1265 return HDF_ERR_INVALID_PARAM;
1266 }
1267 if (g_wifi == NULL || g_wifi->getStationInfo == NULL) {
1268 HDF_LOGE("%{public}s g_wifi or g_wifi->getStationInfo is NULL!", __func__);
1269 return HDF_FAILURE;
1270 }
1271 ret = g_wifi->getStationInfo(ifName, (StationInfo *)info, mac, macLen);
1272 if (ret != HDF_SUCCESS) {
1273 HDF_LOGE("%{public}s: get station information failed!, error code: %{public}d", __func__, ret);
1274 }
1275 return ret;
1276 }
1277
FillPnoSettings(WifiPnoSettings * wifiPnoSettings,const struct PnoSettings * pnoSettings)1278 static int32_t FillPnoSettings(WifiPnoSettings *wifiPnoSettings, const struct PnoSettings *pnoSettings)
1279 {
1280 wifiPnoSettings->min2gRssi = pnoSettings->min2gRssi;
1281 wifiPnoSettings->min5gRssi = pnoSettings->min5gRssi;
1282 wifiPnoSettings->scanIntervalMs = pnoSettings->scanIntervalMs;
1283 wifiPnoSettings->scanIterations = pnoSettings->scanIterations;
1284
1285 if ((pnoSettings->pnoNetworks == NULL) || (pnoSettings->pnoNetworksLen == 0)) {
1286 HDF_LOGE("%{public}s: scan networks is NULL.", __func__);
1287 return HDF_FAILURE;
1288 }
1289
1290 wifiPnoSettings->pnoNetworksLen = pnoSettings->pnoNetworksLen;
1291 wifiPnoSettings->pnoNetworks =
1292 (WifiPnoNetwork *)OsalMemCalloc(sizeof(WifiPnoNetwork) * (pnoSettings->pnoNetworksLen));
1293 if (wifiPnoSettings->pnoNetworks == NULL) {
1294 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__);
1295 return HDF_FAILURE;
1296 }
1297 for (uint32_t i = 0; i < pnoSettings->pnoNetworksLen; i++) {
1298 wifiPnoSettings->pnoNetworks[i].isHidden = pnoSettings->pnoNetworks[i].isHidden;
1299 wifiPnoSettings->pnoNetworks[i].ssid.ssidLen = pnoSettings->pnoNetworks[i].ssid.ssidLen;
1300 if (memcpy_s(wifiPnoSettings->pnoNetworks[i].ssid.ssid, MAX_SSID_LEN, pnoSettings->pnoNetworks[i].ssid.ssid,
1301 pnoSettings->pnoNetworks[i].ssid.ssidLen) != EOK) {
1302 HDF_LOGE("%{public}s fail : memcpy_s ssids fail!", __func__);
1303 return HDF_FAILURE;
1304 }
1305 if (pnoSettings->pnoNetworks[i].freqsLen != 0) {
1306 wifiPnoSettings->pnoNetworks[i].freqs =
1307 (int32_t *)OsalMemCalloc(sizeof(int32_t) * (pnoSettings->pnoNetworks[i].freqsLen));
1308 if (wifiPnoSettings->pnoNetworks[i].freqs == NULL) {
1309 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__);
1310 return HDF_FAILURE;
1311 }
1312 wifiPnoSettings->pnoNetworks[i].freqsLen = pnoSettings->pnoNetworks[i].freqsLen;
1313 if (memcpy_s(wifiPnoSettings->pnoNetworks[i].freqs,
1314 sizeof(int32_t) * (pnoSettings->pnoNetworks[i].freqsLen), pnoSettings->pnoNetworks[i].freqs,
1315 sizeof(int32_t) * (pnoSettings->pnoNetworks[i].freqsLen)) != EOK) {
1316 HDF_LOGE("%{public}s fail : memcpy_s freqs fail!", __func__);
1317 return HDF_FAILURE;
1318 }
1319 }
1320 }
1321 return HDF_SUCCESS;
1322 }
1323
WifiPnoSettingsFree(WifiPnoSettings * wifiPnoSettings)1324 static void WifiPnoSettingsFree(WifiPnoSettings *wifiPnoSettings)
1325 {
1326 if (wifiPnoSettings == NULL) {
1327 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1328 return;
1329 }
1330 for (uint32_t i = 0; i < wifiPnoSettings->pnoNetworksLen; i++) {
1331 if (wifiPnoSettings->pnoNetworks[i].freqs != NULL) {
1332 OsalMemFree(wifiPnoSettings->pnoNetworks[i].freqs);
1333 wifiPnoSettings->pnoNetworks[i].freqs = NULL;
1334 }
1335 }
1336 OsalMemFree(wifiPnoSettings->pnoNetworks);
1337 wifiPnoSettings->pnoNetworks = NULL;
1338 OsalMemFree(wifiPnoSettings);
1339 }
1340
WlanInterfaceStartPnoScan(struct IWlanInterface * self,const char * ifName,const struct PnoSettings * pnoSettings)1341 int32_t WlanInterfaceStartPnoScan(struct IWlanInterface *self, const char *ifName,
1342 const struct PnoSettings *pnoSettings)
1343 {
1344 int32_t ret;
1345 (void)self;
1346
1347 if (ifName == NULL || pnoSettings == NULL) {
1348 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1349 return HDF_ERR_INVALID_PARAM;
1350 }
1351 if (g_staFeature == NULL || g_staFeature->startPnoScan == NULL) {
1352 HDF_LOGE("%{public}s g_staFeature or g_staFeature->startPnoScan is NULL!", __func__);
1353 return HDF_FAILURE;
1354 }
1355 WifiPnoSettings *wifiPnoSettings = (WifiPnoSettings *)OsalMemCalloc(sizeof(WifiPnoSettings));
1356 if (wifiPnoSettings == NULL) {
1357 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__);
1358 return HDF_FAILURE;
1359 }
1360 if (FillPnoSettings(wifiPnoSettings, pnoSettings) != HDF_SUCCESS) {
1361 HDF_LOGE("%{public}s fail : memcpy_s ssids fail!", __func__);
1362 WifiPnoSettingsFree(wifiPnoSettings);
1363 return HDF_FAILURE;
1364 }
1365
1366 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifName);
1367 if (ret != HDF_SUCCESS) {
1368 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
1369 WifiPnoSettingsFree(wifiPnoSettings);
1370 return HDF_FAILURE;
1371 }
1372 ret = g_staFeature->startPnoScan(ifName, wifiPnoSettings);
1373 if (ret != HDF_SUCCESS) {
1374 HDF_LOGE("%{public}s: startPnoScan failed!, error code: %{public}d", __func__, ret);
1375 }
1376 WifiPnoSettingsFree(wifiPnoSettings);
1377 return ret;
1378 }
1379
WlanInterfaceStopPnoScan(struct IWlanInterface * self,const char * ifName)1380 int32_t WlanInterfaceStopPnoScan(struct IWlanInterface *self, const char *ifName)
1381 {
1382 int32_t ret;
1383 (void)self;
1384
1385 if (ifName == NULL) {
1386 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1387 return HDF_ERR_INVALID_PARAM;
1388 }
1389 if (g_staFeature == NULL || g_staFeature->stopPnoScan == NULL) {
1390 HDF_LOGE("%{public}s g_staFeature or g_staFeature->stopPnoScan is NULL!", __func__);
1391 return HDF_FAILURE;
1392 }
1393 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifName);
1394 if (ret != HDF_SUCCESS) {
1395 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
1396 return HDF_FAILURE;
1397 }
1398 ret = g_staFeature->stopPnoScan(ifName);
1399 if (ret != HDF_SUCCESS) {
1400 HDF_LOGE("%{public}s: stopPnoScan failed!, error code: %{public}d", __func__, ret);
1401 }
1402 return ret;
1403 }
1404
WlanInterfaceGetSignalPollInfo(struct IWlanInterface * self,const char * ifName,struct SignalPollResult * signalResult)1405 int32_t WlanInterfaceGetSignalPollInfo(struct IWlanInterface *self, const char *ifName,
1406 struct SignalPollResult *signalResult)
1407 {
1408 int32_t ret;
1409 (void)self;
1410
1411 if (ifName == NULL || signalResult == NULL) {
1412 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1413 return HDF_ERR_INVALID_PARAM;
1414 }
1415 if (g_staFeature == NULL || g_staFeature->getSignalPollInfo == NULL) {
1416 HDF_LOGE("%{public}s g_staFeature or g_staFeature->getSignalPollInfo is NULL!", __func__);
1417 return HDF_FAILURE;
1418 }
1419 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifName);
1420 if (ret != HDF_SUCCESS) {
1421 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
1422 return HDF_FAILURE;
1423 }
1424 ret = g_staFeature->getSignalPollInfo(ifName, (struct SignalResult *)signalResult);
1425 if (ret != HDF_SUCCESS) {
1426 HDF_LOGE("%{public}s: get signal information failed!, error code: %{public}d", __func__, ret);
1427 }
1428 return ret;
1429 }
1430
WlanInterfaceWifiConstruct(void)1431 int32_t WlanInterfaceWifiConstruct(void)
1432 {
1433 int32_t ret;
1434
1435 ret = WifiConstruct(&g_wifi);
1436 if (ret != HDF_SUCCESS) {
1437 HDF_LOGE("%{public}s construct WiFi failed! error code: %{public}d", __func__, ret);
1438 }
1439 return ret;
1440 }
1441
WlanInterfaceWifiDestruct(void)1442 int32_t WlanInterfaceWifiDestruct(void)
1443 {
1444 int32_t ret;
1445
1446 ret = WifiDestruct(&g_wifi);
1447 if (ret != HDF_SUCCESS) {
1448 HDF_LOGE("%{public}s destruct WiFi failed! error code: %{public}d", __func__, ret);
1449 }
1450 return ret;
1451 }
1452