1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #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_0/iwlan_callback.h"
23 #include "v1_0/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 const uint32_t RESET_TIME = 20;
30 #define DEFAULT_COMBO_SIZE 10
31 #define WLAN_FREQ_MAX_NUM 14
32 #define WLAN_MAX_NUM_STA_WITH_AP 4
33 #define ETH_ADDR_LEN 6
34
HdfStubDriver(void)35 struct HdfWlanStubData *HdfStubDriver(void)
36 {
37 static struct HdfWlanStubData registerManager;
38 return ®isterManager;
39 }
40
WlanInterfaceStart(struct IWlanInterface * self)41 int32_t WlanInterfaceStart(struct IWlanInterface *self)
42 {
43 int32_t ret;
44
45 (void)self;
46 if (g_wifi == NULL) {
47 HDF_LOGE("%{public}s: g_wifi is NULL", __func__);
48 return HDF_FAILURE;
49 }
50 ret = g_wifi->start(g_wifi);
51 if (ret != HDF_SUCCESS) {
52 HDF_LOGE("%{public}s start WiFi failed! error code: %{public}d", __func__, ret);
53 }
54 return ret;
55 }
56
WlanInterfaceStop(struct IWlanInterface * self)57 int32_t WlanInterfaceStop(struct IWlanInterface *self)
58 {
59 int32_t ret;
60
61 (void)self;
62 if (g_wifi == NULL) {
63 HDF_LOGE("%{public}s: g_wifi is NULL", __func__);
64 return HDF_FAILURE;
65 }
66 ret = g_wifi->stop(g_wifi);
67 if (ret != HDF_SUCCESS) {
68 HDF_LOGE("%{public}s stop WiFi failed! error code: %{public}d", __func__, ret);
69 }
70 return ret;
71 }
72
WlanInterfaceCreateFeature(struct IWlanInterface * self,int32_t type,struct HdfFeatureInfo * ifeature)73 int32_t WlanInterfaceCreateFeature(struct IWlanInterface *self, int32_t type, struct HdfFeatureInfo *ifeature)
74 {
75 int32_t ret = HDF_FAILURE;
76
77 (void)self;
78 if (ifeature == NULL) {
79 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
80 return HDF_ERR_INVALID_PARAM;
81 }
82 if (g_wifi == NULL) {
83 HDF_LOGE("%{public}s: g_wifi is NULL", __func__);
84 return HDF_FAILURE;
85 }
86 if (type == PROTOCOL_80211_IFTYPE_AP) {
87 ret = g_wifi->createFeature(type, (struct IWiFiBaseFeature **)&g_apFeature);
88 if (ret != HDF_SUCCESS) {
89 HDF_LOGE("%{public}s: createAPFeature failed, error code: %{public}d", __func__, ret);
90 return HDF_FAILURE;
91 }
92 if (g_apFeature != NULL) {
93 ifeature->type = g_apFeature->baseFeature.type;
94 ifeature->ifName = strdup((g_apFeature->baseFeature).ifName);
95 }
96 } else if (type == PROTOCOL_80211_IFTYPE_STATION) {
97 ret = g_wifi->createFeature(type, (struct IWiFiBaseFeature **)&g_staFeature);
98 if (ret != HDF_SUCCESS) {
99 HDF_LOGE("%{public}s: createSTAFeature failed, error code: %{public}d", __func__, ret);
100 return HDF_FAILURE;
101 }
102 if (g_staFeature != NULL) {
103 ifeature->type = g_staFeature->baseFeature.type;
104 ifeature->ifName = strdup((g_staFeature->baseFeature).ifName);
105 }
106 } else {
107 HDF_LOGE("%{public}s: wlan type is Invalid", __func__);
108 }
109 return ret;
110 }
111
WlanInterfaceDestroyFeature(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature)112 int32_t WlanInterfaceDestroyFeature(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature)
113 {
114 int32_t ret = HDF_FAILURE;
115
116 (void)self;
117 if (ifeature == NULL || ifeature->ifName == NULL) {
118 HDF_LOGE("%{public}s input parameter invalid!", __func__);
119 return HDF_ERR_INVALID_PARAM;
120 }
121 if (g_wifi == NULL) {
122 HDF_LOGE("%{public}s: g_wifi is NULL", __func__);
123 return HDF_FAILURE;
124 }
125 if (ifeature->type == PROTOCOL_80211_IFTYPE_AP) {
126 if (g_apFeature == NULL) {
127 HDF_LOGE("%{public}s g_apFeature is NULL!", __func__);
128 return HDF_FAILURE;
129 }
130 ret = strcpy_s((g_apFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName);
131 if (ret != HDF_SUCCESS) {
132 HDF_LOGE("%{public}s: strcpy_s apFeature ifName is failed!", __func__);
133 return HDF_FAILURE;
134 }
135 ret = g_wifi->destroyFeature(&(g_apFeature->baseFeature));
136 } else if (ifeature->type == PROTOCOL_80211_IFTYPE_STATION) {
137 if (g_staFeature == NULL) {
138 HDF_LOGE("%{public}s g_staFeature is NULL!", __func__);
139 return HDF_FAILURE;
140 }
141 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName);
142 if (ret != HDF_SUCCESS) {
143 HDF_LOGE("%{public}s: strcpy_s staFeature ifName is failed!", __func__);
144 return HDF_FAILURE;
145 }
146 ret = g_wifi->destroyFeature(&(g_staFeature->baseFeature));
147 } else {
148 HDF_LOGE("%{public}s: wlan type is invalid", __func__);
149 }
150 return ret;
151 }
152
WlanInterfaceGetAssociatedStas(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,struct HdfStaInfo * staInfo,uint32_t * staInfoLen,uint32_t * num)153 int32_t WlanInterfaceGetAssociatedStas(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
154 struct HdfStaInfo *staInfo, uint32_t *staInfoLen, uint32_t *num)
155 {
156 int32_t ret;
157
158 (void)self;
159 if (ifeature == NULL || ifeature->ifName == NULL || staInfo == NULL || staInfoLen == NULL || num == NULL) {
160 HDF_LOGE("%{public}s:input parameter invalid!", __func__);
161 return HDF_ERR_INVALID_PARAM;
162 }
163 if (g_apFeature == NULL) {
164 HDF_LOGE("%{public}s g_apFeature is NULL!", __func__);
165 return HDF_FAILURE;
166 }
167 ret = strcpy_s((g_apFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName);
168 if (ret != HDF_SUCCESS) {
169 HDF_LOGE("%{public}s: strcpy_s apFeature ifName is failed!", __func__);
170 return HDF_FAILURE;
171 }
172
173 struct StaInfo *wifiStaInfo = (struct StaInfo *)OsalMemCalloc(sizeof(struct StaInfo) * (*staInfoLen));
174 if (wifiStaInfo == NULL) {
175 HDF_LOGE("%{public}s:OsalMemCalloc failed!", __func__);
176 return HDF_FAILURE;
177 }
178 ret = g_apFeature->getAssociatedStas(g_apFeature, wifiStaInfo, *staInfoLen, num);
179 if (ret != HDF_SUCCESS) {
180 HDF_LOGE("%{public}s get associated sta failed!, error code: %{public}d", __func__, ret);
181 OsalMemFree(wifiStaInfo);
182 return ret;
183 }
184 for (uint32_t i = 0; i < (*num); i++) {
185 staInfo[i].mac = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * ETH_ADDR_LEN);
186 if (staInfo[i].mac != NULL) {
187 if (memcpy_s(staInfo[i].mac, WIFI_MAC_ADDR_LENGTH, wifiStaInfo[i].mac, WIFI_MAC_ADDR_LENGTH) != EOK) {
188 HDF_LOGE("%{public}s fail : memcpy_s mac fail!", __func__);
189 ret = HDF_FAILURE;
190 break;
191 }
192 staInfo[i].macLen = WIFI_MAC_ADDR_LENGTH;
193 }
194 }
195 OsalMemFree(wifiStaInfo);
196 return ret;
197 }
198
GetBasefeature(const struct HdfFeatureInfo * ifeature,struct IWiFiBaseFeature ** baseFeature)199 static int32_t GetBasefeature(const struct HdfFeatureInfo *ifeature, struct IWiFiBaseFeature **baseFeature)
200 {
201 if (ifeature == NULL || baseFeature == NULL) {
202 HDF_LOGE("%{public}s ifeature or baseFeature is NULL!", __func__);
203 return HDF_ERR_INVALID_PARAM;
204 }
205 if (ifeature->type == PROTOCOL_80211_IFTYPE_AP) {
206 if (g_apFeature == NULL) {
207 HDF_LOGE("%{public}s g_apFeature is NULL!", __func__);
208 return HDF_FAILURE;
209 }
210 *baseFeature = &(g_apFeature->baseFeature);
211 } else if (ifeature->type == PROTOCOL_80211_IFTYPE_STATION) {
212 if (g_staFeature == NULL) {
213 HDF_LOGE("%{public}s g_staFeature is NULL!", __func__);
214 return HDF_FAILURE;
215 }
216 *baseFeature = &(g_staFeature->baseFeature);
217 } else {
218 HDF_LOGE("%{public}s: wlan type is Invalid, featureType is %{public}d", __func__, ifeature->type);
219 return HDF_FAILURE;
220 }
221 return HDF_SUCCESS;
222 }
223
WlanInterfaceGetChipId(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,uint8_t * chipId)224 int32_t WlanInterfaceGetChipId(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, uint8_t *chipId)
225 {
226 int32_t ret = HDF_FAILURE;
227 struct IWiFiBaseFeature *baseFeature = NULL;
228
229 (void)self;
230 if (ifeature == NULL || ifeature->ifName == NULL || chipId == NULL) {
231 HDF_LOGE("%{public}s ifeature or ifName is NULL!", __func__);
232 return HDF_ERR_INVALID_PARAM;
233 }
234 ret = GetBasefeature(ifeature, &baseFeature);
235 if (ret != HDF_SUCCESS) {
236 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
237 return HDF_FAILURE;
238 }
239 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
240 if (ret != HDF_SUCCESS) {
241 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
242 return HDF_FAILURE;
243 }
244
245 return baseFeature->getChipId(baseFeature, chipId);
246 }
247
WlanInterfaceGetDeviceMacAddress(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,uint8_t * mac,uint32_t * macLen,uint8_t len)248 int32_t WlanInterfaceGetDeviceMacAddress(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
249 uint8_t *mac, uint32_t *macLen, uint8_t len)
250 {
251 int32_t ret = HDF_FAILURE;
252 struct IWiFiBaseFeature *baseFeature = NULL;
253
254 (void)self;
255 if (ifeature == NULL || ifeature->ifName == NULL || mac == NULL || macLen == NULL) {
256 HDF_LOGE("%{public}s input parameter invalid!", __func__);
257 return HDF_ERR_INVALID_PARAM;
258 }
259 ret = GetBasefeature(ifeature, &baseFeature);
260 if (ret != HDF_SUCCESS) {
261 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
262 return HDF_FAILURE;
263 }
264 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
265 if (ret != HDF_SUCCESS) {
266 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
267 return HDF_FAILURE;
268 }
269 ret = baseFeature->getDeviceMacAddress(baseFeature, mac, len);
270 *macLen = ETH_ADDR_LEN;
271 return ret;
272 }
273
WlanInterfaceGetFeatureByIfName(struct IWlanInterface * self,const char * ifName,struct HdfFeatureInfo * ifeature)274 int32_t WlanInterfaceGetFeatureByIfName(struct IWlanInterface *self, const char *ifName,
275 struct HdfFeatureInfo *ifeature)
276 {
277 int32_t ret;
278 struct IWiFiBaseFeature *baseFeature = NULL;
279
280 (void)self;
281 if (ifName == NULL || ifeature == NULL) {
282 HDF_LOGE("%{public}s input parameter invalid!", __func__);
283 return HDF_ERR_INVALID_PARAM;
284 }
285 if (g_wifi == NULL) {
286 HDF_LOGE("%{public}s gwifi is NULL!", __func__);
287 return HDF_FAILURE;
288 }
289 ret = g_wifi->getFeatureByIfName(ifName, (struct IWiFiBaseFeature **)&baseFeature);
290 if (ret != HDF_SUCCESS) {
291 HDF_LOGE("%{public}s get FeatureByIfName failed!, error code: %{public}d", __func__, ret);
292 return ret;
293 }
294 if (baseFeature == NULL) {
295 HDF_LOGE("%{public}s baseFeature is NULL!", __func__);
296 return HDF_FAILURE;
297 }
298 ifeature->type = baseFeature->type;
299 ifeature->ifName = strdup(baseFeature->ifName);
300 return ret;
301 }
302
WlanInterfaceGetFeatureType(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,int32_t * featureType)303 int32_t WlanInterfaceGetFeatureType(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
304 int32_t *featureType)
305 {
306 (void)self;
307 int32_t ret;
308 int32_t type;
309 struct IWiFiBaseFeature *baseFeature = NULL;
310
311 if (ifeature == NULL || featureType == NULL) {
312 HDF_LOGE("%{public}s input parameter invalid!", __func__);
313 return HDF_ERR_INVALID_PARAM;
314 }
315 ret = GetBasefeature(ifeature, &baseFeature);
316 if (ret != HDF_SUCCESS) {
317 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
318 return HDF_FAILURE;
319 }
320 baseFeature->type = ifeature->type;
321 type = baseFeature->getFeatureType(baseFeature);
322 *featureType = type;
323 return HDF_SUCCESS;
324 }
325
WlanInterfaceGetFreqsWithBand(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,const struct HdfWifiInfo * wifiInfo,int32_t * freq,uint32_t * freqLen)326 int32_t WlanInterfaceGetFreqsWithBand(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
327 const struct HdfWifiInfo *wifiInfo, int32_t *freq, uint32_t *freqLen)
328 {
329 int32_t ret;
330 struct IWiFiBaseFeature *baseFeature = NULL;
331
332 (void)self;
333 if (ifeature == NULL || ifeature->ifName == NULL || freq == NULL || freqLen == NULL || wifiInfo == NULL) {
334 HDF_LOGE("%{public}s input parameter invalid!", __func__);
335 return HDF_ERR_INVALID_PARAM;
336 }
337 ret = GetBasefeature(ifeature, &baseFeature);
338 if (ret != HDF_SUCCESS) {
339 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
340 return HDF_FAILURE;
341 }
342 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
343 if (ret != HDF_SUCCESS) {
344 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
345 return HDF_FAILURE;
346 }
347
348 return baseFeature->getValidFreqsWithBand(baseFeature, wifiInfo->band, freq, wifiInfo->size, freqLen);
349 }
350
WlanInterfaceGetIfNamesByChipId(struct IWlanInterface * self,uint8_t chipId,char * ifName,uint32_t ifNameLen,uint32_t * num)351 int32_t WlanInterfaceGetIfNamesByChipId(struct IWlanInterface *self, uint8_t chipId, char *ifName,
352 uint32_t ifNameLen, uint32_t *num)
353 {
354 int32_t ret;
355
356 (void)self;
357 if (ifName == NULL || num == NULL) {
358 HDF_LOGE("%{public}s input parameter invalid!", __func__);
359 return HDF_ERR_INVALID_PARAM;
360 }
361 char *name = NULL;
362
363 if (g_staFeature != NULL) {
364 HDF_LOGD("%{public}s g_staFeature is not NULL!", __func__);
365 ret = g_staFeature->baseFeature.getIfNamesByChipId(chipId, &name, num);
366 } else if (g_apFeature != NULL) {
367 HDF_LOGD("%{public}s g_apFeature is not NULL!", __func__);
368 ret = g_apFeature->baseFeature.getIfNamesByChipId(chipId, &name, num);
369 } else {
370 HDF_LOGE("%{public}s: ap and sta feature is Invalid.", __func__);
371 ret = HDF_FAILURE;
372 }
373
374 if (ret != HDF_SUCCESS) {
375 HDF_LOGE("%{public}s get name failed!, error code: %{public}d", __func__, ret);
376 return ret;
377 }
378
379 if (name != NULL) {
380 if (strcpy_s(ifName, ifNameLen, name) != EOK) {
381 HDF_LOGE("%{public}s: copy ifName failed!", __func__);
382 return HDF_FAILURE;
383 }
384 }
385 return ret;
386 }
387
WlanInterfaceGetNetworkIfaceName(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,char * ifName,uint32_t ifNameLen)388 int32_t WlanInterfaceGetNetworkIfaceName(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
389 char *ifName, uint32_t ifNameLen)
390 {
391 int32_t ret;
392 const char *name = NULL;
393 struct IWiFiBaseFeature *baseFeature = NULL;
394
395 (void)self;
396 if (ifeature == NULL || ifeature->ifName == NULL || ifName == NULL) {
397 HDF_LOGE("%{public}s input parameter invalid!", __func__);
398 return HDF_ERR_INVALID_PARAM;
399 }
400 ret = GetBasefeature(ifeature, &baseFeature);
401 if (ret != HDF_SUCCESS) {
402 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
403 return HDF_FAILURE;
404 }
405 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
406 if (ret != HDF_SUCCESS) {
407 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
408 return HDF_FAILURE;
409 }
410 name = baseFeature->getNetworkIfaceName(baseFeature);
411 if (name == NULL) {
412 HDF_LOGE("%{public}s get network iface name failed!", __func__);
413 return HDF_FAILURE;
414 }
415 if (strcpy_s(ifName, ifNameLen, name) != EOK) {
416 HDF_LOGE("%{public}s: copy ifName failed!", __func__);
417 return HDF_FAILURE;
418 }
419 return HDF_SUCCESS;
420 }
421
WlanInterfaceGetSupportCombo(struct IWlanInterface * self,uint64_t * combo)422 int32_t WlanInterfaceGetSupportCombo(struct IWlanInterface *self, uint64_t *combo)
423 {
424 int32_t ret;
425
426 (void)self;
427 if (combo == NULL) {
428 HDF_LOGE("%{public}s input parameter invalid!", __func__);
429 return HDF_ERR_INVALID_PARAM;
430 }
431 if (g_wifi == NULL) {
432 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
433 return HDF_FAILURE;
434 }
435 ret = g_wifi->getSupportCombo(combo, DEFAULT_COMBO_SIZE);
436 if (ret == HDF_ERR_NOT_SUPPORT) {
437 HDF_LOGW("%{public}s: not support to getting combo!, error code: %{public}d", __func__, ret);
438 }
439 return ret;
440 }
441
WlanInterfaceGetSupportFeature(struct IWlanInterface * self,uint8_t * supType,uint32_t * supTypeLen)442 int32_t WlanInterfaceGetSupportFeature(struct IWlanInterface *self, uint8_t *supType, uint32_t *supTypeLen)
443 {
444 int32_t ret;
445
446 (void)self;
447 if (supType == NULL || supTypeLen == NULL) {
448 HDF_LOGE("%{public}s input parameter invalid!", __func__);
449 return HDF_ERR_INVALID_PARAM;
450 }
451 if (g_wifi == NULL) {
452 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
453 return HDF_FAILURE;
454 }
455 ret = g_wifi->getSupportFeature(supType, *supTypeLen);
456 if (ret != HDF_SUCCESS) {
457 HDF_LOGE("%{public}s get support feature failed! error code: %{public}d", __func__, ret);
458 }
459 return ret;
460 }
461
HdfWlanAddRemoteObj(struct IWlanCallback * self)462 static int32_t HdfWlanAddRemoteObj(struct IWlanCallback *self)
463 {
464 struct HdfWlanRemoteNode *pos = NULL;
465 struct DListHead *head = &HdfStubDriver()->remoteListHead;
466
467 if (self == NULL) {
468 HDF_LOGE("%{public}s:self == NULL", __func__);
469 return HDF_ERR_INVALID_PARAM;
470 }
471 if (!DListIsEmpty(head)) {
472 DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWlanRemoteNode, node) {
473 if (pos->service == self->AsObject(self)) {
474 HDF_LOGE("%{public}s: pos->service == self", __func__);
475 return HDF_FAILURE;
476 }
477 }
478 }
479
480 struct HdfWlanRemoteNode *newRemoteNode =
481 (struct HdfWlanRemoteNode *)OsalMemCalloc(sizeof(struct HdfWlanRemoteNode));
482 if (newRemoteNode == NULL) {
483 HDF_LOGE("%{public}s:newRemoteNode is NULL", __func__);
484 return HDF_FAILURE;
485 }
486
487 newRemoteNode->callbackObj = self;
488 newRemoteNode->service = self->AsObject(self);
489 DListInsertTail(&newRemoteNode->node, head);
490 return HDF_SUCCESS;
491 }
492
WlanFillScanResultInfo(WifiScanResult * wifiScanResult,struct HdfWifiScanResult * scanResult)493 static int32_t WlanFillScanResultInfo(WifiScanResult *wifiScanResult, struct HdfWifiScanResult *scanResult)
494 {
495 if (wifiScanResult == NULL || scanResult == NULL) {
496 HDF_LOGE("%{public}s: wifiScanResult or scanResult is NULL!", __func__);
497 return HDF_ERR_INVALID_PARAM;
498 }
499 scanResult->flags = wifiScanResult->flags;
500 scanResult->caps = wifiScanResult->caps;
501 scanResult->freq = wifiScanResult->freq;
502 scanResult->beaconInt = wifiScanResult->beaconInt;
503 scanResult->qual = wifiScanResult->qual;
504 scanResult->level = wifiScanResult->level;
505 scanResult->age = wifiScanResult->age;
506 if (wifiScanResult->bssid != NULL) {
507 scanResult->bssid = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * ETH_ADDR_LEN);
508 if (scanResult->bssid != NULL) {
509 if (memcpy_s(scanResult->bssid, ETH_ADDR_LEN, wifiScanResult->bssid, ETH_ADDR_LEN) != EOK) {
510 HDF_LOGE("%{public}s: memcpy_s bssid fail!", __func__);
511 OsalMemFree(scanResult->bssid);
512 return HDF_FAILURE;
513 }
514 scanResult->bssidLen = ETH_ADDR_LEN;
515 }
516 }
517 if ((wifiScanResult->ie != NULL) && (wifiScanResult->ieLen != 0)) {
518 scanResult->ie = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) *wifiScanResult->ieLen);
519 if (scanResult->ie != NULL) {
520 if (memcpy_s(scanResult->ie, wifiScanResult->ieLen, wifiScanResult->ie,
521 wifiScanResult->ieLen) != EOK) {
522 HDF_LOGE("%{public}s: memcpy_s ie fail!", __func__);
523 OsalMemFree(scanResult->ie);
524 return HDF_FAILURE;
525 }
526 scanResult->ieLen = wifiScanResult->ieLen;
527 }
528 }
529 if ((wifiScanResult->ie != NULL) && (wifiScanResult->ieLen != 0)) {
530 scanResult->beaconIe = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * wifiScanResult->beaconIeLen);
531 if (scanResult->beaconIe != NULL) {
532 if (memcpy_s(scanResult->beaconIe, wifiScanResult->beaconIeLen, wifiScanResult->beaconIe,
533 wifiScanResult->beaconIeLen) != EOK) {
534 HDF_LOGE("%{public}s: memcpy_s beaconIe fail!", __func__);
535 OsalMemFree(scanResult->beaconIe);
536 return HDF_FAILURE;
537 }
538 scanResult->beaconIeLen = wifiScanResult->beaconIeLen;
539 }
540 }
541 return HDF_SUCCESS;
542 }
543
HdfWLanCallbackFun(uint32_t event,void * data,const char * ifName)544 static int32_t HdfWLanCallbackFun(uint32_t event, void *data, const char *ifName)
545 {
546 struct HdfWlanRemoteNode *pos = NULL;
547 struct DListHead *head = &HdfStubDriver()->remoteListHead;
548 WifiScanResult *wifiScanResult = NULL;
549 int32_t *code = NULL;
550 int32_t ret = HDF_FAILURE;
551
552 if (data == NULL || ifName == NULL) {
553 HDF_LOGE("%{public}s: data or ifName is NULL!", __func__);
554 return HDF_ERR_INVALID_PARAM;
555 }
556 DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWlanRemoteNode, node) {
557 if (pos->service == NULL || pos->callbackObj == NULL) {
558 HDF_LOGW("%{public}s: pos->service or pos->callbackObj NULL", __func__);
559 continue;
560 }
561 switch (event) {
562 case WIFI_EVENT_RESET_DRIVER:
563 if (data != NULL) {
564 code = (int32_t *)data;
565 ret = pos->callbackObj->ResetDriverResult(pos->callbackObj, event, *code, ifName);
566 }
567 break;
568 case WIFI_EVENT_SCAN_RESULT:
569 wifiScanResult = (WifiScanResult *)data;
570 struct HdfWifiScanResult *scanResult =
571 (struct HdfWifiScanResult *)OsalMemCalloc(sizeof(struct HdfWifiScanResult));
572 if ((scanResult == NULL) || (WlanFillScanResultInfo(wifiScanResult, scanResult) != HDF_SUCCESS)) {
573 HDF_LOGE("%{public}s: scanResult is NULL or WlanFillScanResultInfo fialed!", __func__);
574 HdfWifiScanResultFree(scanResult, true);
575 break;
576 }
577 ret = pos->callbackObj->ScanResult(pos->callbackObj, event, scanResult, ifName);
578 HdfWifiScanResultFree(scanResult, true);
579 break;
580 default:
581 HDF_LOGE("%{public}s: unknown eventId:%{public}d", __func__, event);
582 break;
583 }
584 if (ret != HDF_SUCCESS) {
585 HDF_LOGE("%{public}s: dispatch code fialed, error code: %{public}d", __func__, ret);
586 }
587 }
588 return ret;
589 }
590
HdfWlanNetlinkCallbackFun(const uint8_t * recvMsg,uint32_t recvMsgLen)591 static int32_t HdfWlanNetlinkCallbackFun(const uint8_t *recvMsg, uint32_t recvMsgLen)
592 {
593 struct HdfWlanRemoteNode *pos = NULL;
594 struct DListHead *head = &HdfStubDriver()->remoteListHead;
595 int32_t ret = HDF_FAILURE;
596
597 if (recvMsg == NULL) {
598 HDF_LOGE("%{public}s: recvMsg or ifName is NULL!", __func__);
599 return HDF_ERR_INVALID_PARAM;
600 }
601 DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWlanRemoteNode, node) {
602 if (pos->service == NULL || pos->callbackObj == NULL) {
603 HDF_LOGW("%{public}s: pos->service or pos->callbackObj NULL", __func__);
604 continue;
605 }
606 ret = pos->callbackObj->WifiNetlinkMessage(pos->callbackObj, recvMsg, recvMsgLen);
607 if (ret != HDF_SUCCESS) {
608 HDF_LOGE("%{public}s: dispatch code fialed, error code: %{public}d", __func__, ret);
609 }
610 }
611 return ret;
612 }
613
HdfWlanDelRemoteObj(struct IWlanCallback * self)614 static void HdfWlanDelRemoteObj(struct IWlanCallback *self)
615 {
616 struct HdfWlanRemoteNode *pos = NULL;
617 struct HdfWlanRemoteNode *tmp = NULL;
618 struct DListHead *head = &HdfStubDriver()->remoteListHead;
619
620 DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, head, struct HdfWlanRemoteNode, node) {
621 if (pos->service->index == self->AsObject(self)->index) {
622 DListRemove(&(pos->node));
623 IWlanCallbackRelease(pos->callbackObj);
624 OsalMemFree(pos);
625 break;
626 }
627 }
628 IWlanCallbackRelease(self);
629 }
630
WlanInterfaceRegisterEventCallback(struct IWlanInterface * self,struct IWlanCallback * cbFunc,const char * ifName)631 int32_t WlanInterfaceRegisterEventCallback(struct IWlanInterface *self, struct IWlanCallback *cbFunc,
632 const char *ifName)
633 {
634 int32_t ret;
635
636 (void)self;
637 if (cbFunc == NULL || ifName == NULL) {
638 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
639 return HDF_ERR_INVALID_PARAM;
640 }
641 if (g_wifi == NULL) {
642 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
643 return HDF_FAILURE;
644 }
645 (void)OsalMutexLock(&HdfStubDriver()->mutex);
646
647 do {
648 ret = HdfWlanAddRemoteObj(cbFunc);
649 if (ret != HDF_SUCCESS) {
650 HDF_LOGE("%{public}s: HdfSensorAddRemoteObj false", __func__);
651 break;
652 }
653 ret = g_wifi->registerEventCallback(HdfWLanCallbackFun, ifName);
654 if (ret != HDF_SUCCESS) {
655 HDF_LOGE("%{public}s: Register failed!, error code: %{public}d", __func__, ret);
656 HdfWlanDelRemoteObj(cbFunc);
657 break;
658 }
659 ret = WlanInterfaceRegisterHid2dCallback(HdfWlanNetlinkCallbackFun, ifName);
660 if (ret != HDF_SUCCESS) {
661 HDF_LOGE("%{public}s: Register failed!, error code: %{public}d", __func__, ret);
662 g_wifi->unregisterEventCallback(HdfWLanCallbackFun, ifName);
663 HdfWlanDelRemoteObj(cbFunc);
664 }
665 } while (0);
666
667 (void)OsalMutexUnlock(&HdfStubDriver()->mutex);
668 return ret;
669 }
670
WlanInterfaceUnregisterEventCallback(struct IWlanInterface * self,struct IWlanCallback * cbFunc,const char * ifName)671 int32_t WlanInterfaceUnregisterEventCallback(struct IWlanInterface *self, struct IWlanCallback *cbFunc,
672 const char *ifName)
673 {
674 int32_t ret;
675
676 (void)self;
677 if (cbFunc == NULL || ifName == NULL) {
678 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
679 return HDF_ERR_INVALID_PARAM;
680 }
681 if (g_wifi == NULL) {
682 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
683 return HDF_FAILURE;
684 }
685 (void)OsalMutexLock(&HdfStubDriver()->mutex);
686 HdfWlanDelRemoteObj(cbFunc);
687 if (DListIsEmpty(&HdfStubDriver()->remoteListHead)) {
688 ret = g_wifi->unregisterEventCallback(HdfWLanCallbackFun, ifName);
689 if (ret != HDF_SUCCESS) {
690 HDF_LOGE("%{public}s: Unregister failed!, error code: %{public}d", __func__, ret);
691 (void)OsalMutexUnlock(&HdfStubDriver()->mutex);
692 return ret;
693 }
694 }
695 (void)OsalMutexUnlock(&HdfStubDriver()->mutex);
696 return HDF_SUCCESS;
697 }
698
WlanInterfaceResetDriver(struct IWlanInterface * self,uint8_t chipId,const char * ifName)699 int32_t WlanInterfaceResetDriver(struct IWlanInterface *self, uint8_t chipId, const char *ifName)
700 {
701 int32_t ret;
702
703 (void)self;
704 if (ifName == NULL) {
705 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
706 return HDF_ERR_INVALID_PARAM;
707 }
708 if (g_wifi == NULL) {
709 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
710 return HDF_FAILURE;
711 }
712 ret = g_wifi->resetDriver(chipId, ifName);
713 if (ret != HDF_SUCCESS) {
714 HDF_LOGE("%{public}s reset driver failed! error code: %{public}d", __func__, ret);
715 return ret;
716 }
717 OsalMSleep(RESET_TIME);
718 return ret;
719 }
720
WlanInterfaceSetCountryCode(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,const char * code,uint32_t len)721 int32_t WlanInterfaceSetCountryCode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
722 const char *code, uint32_t len)
723 {
724 int32_t ret;
725
726 (void)self;
727 if (ifeature == NULL || ifeature->ifName == NULL || code == NULL) {
728 HDF_LOGE("%{public}s input parameter invalid!", __func__);
729 return HDF_ERR_INVALID_PARAM;
730 }
731 if (g_apFeature == NULL) {
732 HDF_LOGE("%{public}s g_apFeature is NULL!", __func__);
733 return HDF_FAILURE;
734 }
735 ret = strcpy_s((g_apFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName);
736 if (ret != HDF_SUCCESS) {
737 HDF_LOGE("%{public}s: strcpy_s apFeature ifName is failed!", __func__);
738 return HDF_FAILURE;
739 }
740 ret = g_apFeature->setCountryCode(g_apFeature, code, strlen(code));
741 if (ret != HDF_SUCCESS) {
742 HDF_LOGE("%{public}s set country code failed!, error code: %{public}d", __func__, ret);
743 }
744 return ret;
745 }
746
WlanInterfaceSetMacAddress(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,const uint8_t * mac,uint32_t macLen)747 int32_t WlanInterfaceSetMacAddress(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
748 const uint8_t *mac, uint32_t macLen)
749 {
750 int32_t ret = HDF_FAILURE;
751 struct IWiFiBaseFeature *baseFeature = NULL;
752
753 (void)self;
754 if (ifeature == NULL || mac == NULL || ifeature->ifName == NULL) {
755 HDF_LOGE("%{public}s input parameter invalid!", __func__);
756 return HDF_ERR_INVALID_PARAM;
757 }
758 ret = GetBasefeature(ifeature, &baseFeature);
759 if (ret != HDF_SUCCESS) {
760 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
761 return HDF_FAILURE;
762 }
763 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
764 if (ret != HDF_SUCCESS) {
765 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
766 return HDF_FAILURE;
767 }
768 return baseFeature->setMacAddress(baseFeature, (uint8_t *)mac, ETH_ADDR_LEN);
769 }
770
WlanInterfaceSetScanningMacAddress(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,const uint8_t * scanMac,uint32_t scanMacLen)771 int32_t WlanInterfaceSetScanningMacAddress(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
772 const uint8_t *scanMac, uint32_t scanMacLen)
773 {
774 int32_t ret;
775
776 (void)self;
777 if (ifeature == NULL || ifeature->ifName == NULL || scanMac == NULL) {
778 HDF_LOGE("%{public}s input parameter invalid!", __func__);
779 return HDF_ERR_INVALID_PARAM;
780 }
781 if (g_staFeature == NULL) {
782 HDF_LOGE("%{public}s g_staFeature is NULL!", __func__);
783 return HDF_FAILURE;
784 }
785 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName);
786 if (ret != HDF_SUCCESS) {
787 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
788 return HDF_FAILURE;
789 }
790 ret = g_staFeature->setScanningMacAddress(g_staFeature, (uint8_t *)scanMac, (uint8_t)scanMacLen);
791
792 return ret;
793 }
794
WlanInterfaceSetTxPower(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,int32_t power)795 int32_t WlanInterfaceSetTxPower(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, int32_t power)
796 {
797 int32_t ret;
798 struct IWiFiBaseFeature *baseFeature = NULL;
799
800 (void)self;
801 if (ifeature == NULL || ifeature->ifName == NULL) {
802 HDF_LOGE("%{public}s input parameter invalid!", __func__);
803 return HDF_ERR_INVALID_PARAM;
804 }
805 ret = GetBasefeature(ifeature, &baseFeature);
806 if (ret != HDF_SUCCESS) {
807 HDF_LOGE("%{public}s GetBasefeature failed!", __func__);
808 return HDF_FAILURE;
809 }
810 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName);
811 if (ret != HDF_SUCCESS) {
812 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret);
813 return HDF_FAILURE;
814 }
815
816 return baseFeature->setTxPower(baseFeature, power);
817 }
818
WlanInterfaceGetNetDevInfo(struct IWlanInterface * self,struct HdfNetDeviceInfoResult * netDeviceInfoResult)819 int32_t WlanInterfaceGetNetDevInfo(struct IWlanInterface *self, struct HdfNetDeviceInfoResult *netDeviceInfoResult)
820 {
821 int32_t ret = HDF_FAILURE;
822
823 (void)self;
824 if (g_wifi == NULL || netDeviceInfoResult == NULL) {
825 HDF_LOGE("%{public}s: input parameter invalid!", __func__);
826 return HDF_ERR_INVALID_PARAM;
827 }
828 struct NetDeviceInfoResult *netDeviceInfo =
829 (struct NetDeviceInfoResult *)OsalMemCalloc(sizeof(struct NetDeviceInfoResult));
830 if (netDeviceInfo == NULL) {
831 HDF_LOGE("%{public}s:OsalMemCalloc failed!", __func__);
832 return HDF_FAILURE;
833 }
834 ret = g_wifi->getNetDevInfo(netDeviceInfo);
835 if (ret != HDF_SUCCESS) {
836 HDF_LOGE("%{public}s: get netdev info failed!, error code: %{public}d", __func__, ret);
837 OsalMemFree(netDeviceInfo);
838 return HDF_FAILURE;
839 }
840
841 netDeviceInfoResult->deviceInfos =
842 (struct HdfNetDeviceInfo *)OsalMemCalloc(sizeof(struct HdfNetDeviceInfo) * MAX_NETDEVICE_COUNT);
843 if (netDeviceInfoResult->deviceInfos == NULL) {
844 HDF_LOGE("%{public}s:netDeviceInfoResult->deviceInfos OsalMemCalloc failed", __func__);
845 OsalMemFree(netDeviceInfo);
846 return HDF_FAILURE;
847 }
848 netDeviceInfoResult->deviceInfosLen = MAX_NETDEVICE_COUNT;
849 for (uint32_t i = 0; i < netDeviceInfoResult->deviceInfosLen; i++) {
850 netDeviceInfoResult->deviceInfos[i].index = netDeviceInfo->deviceInfos[i].index;
851 netDeviceInfoResult->deviceInfos[i].iftype = netDeviceInfo->deviceInfos[i].iftype;
852 netDeviceInfoResult->deviceInfos[i].ifName = (char *)OsalMemCalloc(sizeof(char) * IFNAMSIZ);
853 if (netDeviceInfoResult->deviceInfos != NULL) {
854 if (memcpy_s(netDeviceInfoResult->deviceInfos[i].ifName, IFNAMSIZ, netDeviceInfo->deviceInfos[i].ifName,
855 IFNAMSIZ) != EOK) {
856 OsalMemFree(netDeviceInfoResult->deviceInfos[i].ifName);
857 break;
858 }
859 netDeviceInfoResult->deviceInfos[i].ifNameLen = IFNAMSIZ;
860 }
861 netDeviceInfoResult->deviceInfos[i].mac = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * ETH_ADDR_LEN);
862 if (netDeviceInfoResult->deviceInfos[i].mac != NULL) {
863 if (memcpy_s(netDeviceInfoResult->deviceInfos[i].mac, ETH_ADDR_LEN, netDeviceInfo->deviceInfos[i].mac,
864 ETH_ADDR_LEN) != EOK) {
865 OsalMemFree(netDeviceInfoResult->deviceInfos[i].mac);
866 break;
867 }
868 netDeviceInfoResult->deviceInfos[i].macLen = ETH_ADDR_LEN;
869 }
870 }
871 OsalMemFree(netDeviceInfo);
872 return ret;
873 }
874
WLanFillScanData(WifiScan * wifiScan,const struct HdfWifiScan * scan)875 static int32_t WLanFillScanData(WifiScan *wifiScan, const struct HdfWifiScan *scan)
876 {
877 if (wifiScan == NULL || scan == NULL) {
878 HDF_LOGE("%{public}s wifiScan or scan is NULL", __func__);
879 return HDF_ERR_INVALID_PARAM;
880 }
881 if ((scan->ssids != NULL) && (scan->ssidsLen != 0)) {
882 wifiScan->ssids = (WifiDriverScanSsid *)OsalMemCalloc(sizeof(WifiDriverScanSsid) * scan->ssidsLen);
883 if (wifiScan->ssids != NULL) {
884 if (memcpy_s(wifiScan->ssids, scan->ssidsLen, scan->ssids, scan->ssidsLen) != EOK) {
885 HDF_LOGE("%{public}s fail : memcpy_s ssids fail!", __func__);
886 OsalMemFree(wifiScan->ssids);
887 return HDF_FAILURE;
888 }
889 wifiScan->numSsids = scan->ssidsLen;
890 }
891 }
892
893 if ((scan->freqs != NULL) && (scan->freqsLen != 0)) {
894 wifiScan->freqs = (int32_t *)OsalMemCalloc(sizeof(int32_t) * scan->freqsLen);
895 if (wifiScan->freqs != NULL) {
896 if (memcpy_s(wifiScan->freqs, scan->freqsLen, scan->freqs, scan->freqsLen) != EOK) {
897 HDF_LOGE("%{public}s fail : memcpy_s freqs fail!", __func__);
898 OsalMemFree(wifiScan->freqs);
899 return HDF_FAILURE;
900 }
901 wifiScan->numFreqs = scan->freqsLen;
902 }
903 }
904
905 if ((scan->bssid != NULL) && (scan->bssidLen != 0)) {
906 wifiScan->bssid = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * scan->bssidLen);
907 if (wifiScan->bssid != NULL) {
908 if (memcpy_s(wifiScan->bssid, scan->bssidLen, scan->bssid, scan->bssidLen) != EOK) {
909 HDF_LOGE("%{public}s fail : memcpy_s bssid fail!", __func__);
910 OsalMemFree(wifiScan->bssid);
911 return HDF_FAILURE;
912 }
913 }
914 }
915 if ((scan->extraIes != NULL) && (scan->extraIesLen != 0)) {
916 wifiScan->extraIes = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * scan->extraIesLen);
917 if (wifiScan->extraIes != NULL) {
918 if (memcpy_s(wifiScan->extraIes, scan->extraIesLen, scan->extraIes, scan->extraIesLen) != EOK) {
919 HDF_LOGE("%{public}s fail : memcpy_s extraIes fail!", __func__);
920 OsalMemFree(wifiScan->extraIes);
921 return HDF_FAILURE;
922 }
923 wifiScan->extraIesLen = scan->extraIesLen;
924 }
925 }
926
927 wifiScan->prefixSsidScanFlag = scan->prefixSsidScanFlag;
928 wifiScan->fastConnectFlag = scan->fastConnectFlag;
929 return HDF_SUCCESS;
930 }
931
WifiScanFree(WifiScan * dataBlock)932 static void WifiScanFree(WifiScan *dataBlock)
933 {
934 if (dataBlock == NULL) {
935 return;
936 }
937
938 if (dataBlock->ssids != NULL) {
939 OsalMemFree(dataBlock->ssids);
940 dataBlock->ssids = NULL;
941 }
942 if (dataBlock->freqs != NULL) {
943 OsalMemFree(dataBlock->freqs);
944 dataBlock->freqs = NULL;
945 }
946 if (dataBlock->bssid != NULL) {
947 OsalMemFree(dataBlock->bssid);
948 dataBlock->bssid = NULL;
949 }
950 if (dataBlock->extraIes != NULL) {
951 OsalMemFree(dataBlock->extraIes);
952 dataBlock->extraIes = NULL;
953 }
954 OsalMemFree(dataBlock);
955 }
956
WlanInterfaceStartScan(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,const struct HdfWifiScan * scan)957 int32_t WlanInterfaceStartScan(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature,
958 const struct HdfWifiScan *scan)
959 {
960 int32_t ret = HDF_FAILURE;
961
962 (void)self;
963 if (ifeature == NULL || ifeature->ifName == NULL || scan == NULL) {
964 HDF_LOGE("%{public}s input parameter invalid!", __func__);
965 return HDF_ERR_INVALID_PARAM;
966 }
967 WifiScan *wifiScan = (WifiScan *)OsalMemCalloc(sizeof(WifiScan));
968 if (wifiScan == NULL) {
969 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__);
970 return HDF_FAILURE;
971 }
972 if (WLanFillScanData(wifiScan, scan) != HDF_SUCCESS) {
973 HDF_LOGE("%{public}s fail : memcpy_s ssids fail!", __func__);
974 WifiScanFree(wifiScan);
975 return HDF_FAILURE;
976 }
977 if (g_staFeature == NULL) {
978 HDF_LOGE("%{public}s g_staFeature is NULL!", __func__);
979 WifiScanFree(wifiScan);
980 return HDF_FAILURE;
981 }
982 ret = g_staFeature->startScan(ifeature->ifName, wifiScan);
983 if (ret != HDF_SUCCESS) {
984 HDF_LOGE("%{public}s get netdev info failed!, error code: %{public}d", __func__, ret);
985 }
986 WifiScanFree(wifiScan);
987 return ret;
988 }
989
WlanInterfaceGetPowerMode(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,uint8_t * mode)990 int32_t WlanInterfaceGetPowerMode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, uint8_t *mode)
991 {
992 int32_t ret;
993
994 (void)self;
995 if (ifeature == NULL || ifeature->ifName == NULL || mode == NULL) {
996 HDF_LOGE("%{public}s input parameter invalid!", __func__);
997 return HDF_ERR_INVALID_PARAM;
998 }
999 if (g_wifi == NULL) {
1000 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
1001 return HDF_FAILURE;
1002 }
1003 ret = g_wifi->getPowerMode(ifeature->ifName, mode);
1004 if (ret != HDF_SUCCESS) {
1005 HDF_LOGE("%{public}s: get power mode failed!, error code: %{public}d", __func__, ret);
1006 }
1007 return ret;
1008 }
1009
WlanInterfaceSetPowerMode(struct IWlanInterface * self,const struct HdfFeatureInfo * ifeature,uint8_t mode)1010 int32_t WlanInterfaceSetPowerMode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, uint8_t mode)
1011 {
1012 int32_t ret;
1013
1014 (void)self;
1015 if (ifeature == NULL || ifeature->ifName == NULL) {
1016 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1017 return HDF_ERR_INVALID_PARAM;
1018 }
1019 if (g_wifi == NULL) {
1020 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
1021 return HDF_FAILURE;
1022 }
1023 ret = g_wifi->setPowerMode(ifeature->ifName, mode);
1024 if (ret != HDF_SUCCESS) {
1025 HDF_LOGE("%{public}s: get power mode failed!, error code: %{public}d", __func__, ret);
1026 }
1027 return ret;
1028 }
1029
WlanInterfaceSetProjectionScreenParam(struct IWlanInterface * self,const char * ifName,const struct ProjectionScreenCmdParam * param)1030 int32_t WlanInterfaceSetProjectionScreenParam(struct IWlanInterface *self, const char *ifName,
1031 const struct ProjectionScreenCmdParam *param)
1032 {
1033 int32_t ret;
1034 ProjScrnCmdParam *projScrnCmdParam = NULL;
1035
1036 (void)self;
1037 if (ifName == NULL || param == NULL) {
1038 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1039 return HDF_ERR_INVALID_PARAM;
1040 }
1041 if (g_wifi == NULL) {
1042 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
1043 return HDF_FAILURE;
1044 }
1045
1046 projScrnCmdParam = OsalMemCalloc(sizeof(ProjScrnCmdParam) + param->bufLen);
1047 if (projScrnCmdParam == NULL) {
1048 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__);
1049 return HDF_FAILURE;
1050 }
1051 projScrnCmdParam->cmdId = param->cmdId;
1052 projScrnCmdParam->bufLen = param->bufLen;
1053 do {
1054 if (memcpy_s(projScrnCmdParam->buf, projScrnCmdParam->bufLen, param->buf, param->bufLen) != EOK) {
1055 HDF_LOGE("%{public}s: memcpy_s failed", __func__);
1056 ret = HDF_FAILURE;
1057 break;
1058 }
1059 ret = g_wifi->setProjectionScreenParam(ifName, projScrnCmdParam);
1060 if (ret != HDF_SUCCESS) {
1061 HDF_LOGE("%{public}s: get channel meas result failed!, error code: %{public}d", __func__, ret);
1062 }
1063 } while (0);
1064
1065 OsalMemFree(projScrnCmdParam);
1066 return ret;
1067 }
1068
WlanInterfaceGetStaInfo(struct IWlanInterface * self,const char * ifName,struct WifiStationInfo * info,const uint8_t * mac,uint32_t macLen)1069 int32_t WlanInterfaceGetStaInfo(struct IWlanInterface *self, const char *ifName, struct WifiStationInfo *info,
1070 const uint8_t *mac, uint32_t macLen)
1071 {
1072 int32_t ret;
1073
1074 (void)self;
1075 if (ifName == NULL || info == NULL || mac == NULL) {
1076 HDF_LOGE("%{public}s input parameter invalid!", __func__);
1077 return HDF_ERR_INVALID_PARAM;
1078 }
1079 if (g_wifi == NULL) {
1080 HDF_LOGE("%{public}s g_wifi is NULL!", __func__);
1081 return HDF_FAILURE;
1082 }
1083 ret = g_wifi->getStationInfo(ifName, (StationInfo *)info, mac, macLen);
1084 if (ret != HDF_SUCCESS) {
1085 HDF_LOGE("%{public}s: get station information failed!, error code: %{public}d", __func__, ret);
1086 }
1087 return ret;
1088 }
1089
WlanInterfaceWifiConstruct(void)1090 int32_t WlanInterfaceWifiConstruct(void)
1091 {
1092 int32_t ret;
1093
1094 ret = WifiConstruct(&g_wifi);
1095 if (ret != HDF_SUCCESS) {
1096 HDF_LOGE("%{public}s construct WiFi failed! error code: %{public}d", __func__, ret);
1097 }
1098 return ret;
1099 }
1100
WlanInterfaceWifiDestruct(void)1101 int32_t WlanInterfaceWifiDestruct(void)
1102 {
1103 int32_t ret;
1104
1105 ret = WifiDestruct(&g_wifi);
1106 if (ret != HDF_SUCCESS) {
1107 HDF_LOGE("%{public}s destruct WiFi failed! error code: %{public}d", __func__, ret);
1108 }
1109 return ret;
1110 }
1111