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