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 25struct IWiFi *g_wifi = NULL; 26struct IWiFiAp *g_apFeature = NULL; 27struct IWiFiSta *g_staFeature = NULL; 28struct IWiFiP2p *g_p2pFeature = NULL; 29struct IWiFiBaseFeature *g_baseFeature = NULL; 30static uint32_t g_wifiCount = 0; 31static uint32_t g_apFeatureCount = 0; 32static uint32_t g_staFeatureCount = 0; 33static uint32_t g_p2pFeatureCount = 0; 34const 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 40struct HdfWlanStubData *HdfStubDriver(void) 41{ 42 static struct HdfWlanStubData registerManager; 43 return ®isterManager; 44} 45 46int32_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 65int32_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 87int32_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 141int32_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 214int32_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 260static 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 287int32_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 311int32_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 337int32_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 371int32_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 394int32_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 419int32_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 HDF_LOGE("%{public}s: copy ifName failed!", __func__); 453 return HDF_FAILURE; 454 } 455 } 456 return ret; 457} 458 459int32_t WlanInterfaceGetNetworkIfaceName(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, 460 char *ifName, uint32_t ifNameLen) 461{ 462 int32_t ret; 463 const char *name = NULL; 464 struct IWiFiBaseFeature *baseFeature = NULL; 465 466 (void)self; 467 if (ifeature == NULL || ifeature->ifName == NULL || ifName == NULL) { 468 HDF_LOGE("%{public}s input parameter invalid!", __func__); 469 return HDF_ERR_INVALID_PARAM; 470 } 471 ret = GetBasefeature(ifeature, &baseFeature); 472 if (ret != HDF_SUCCESS) { 473 HDF_LOGE("%{public}s GetBasefeature failed!", __func__); 474 return HDF_FAILURE; 475 } 476 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName); 477 if (ret != HDF_SUCCESS) { 478 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret); 479 return HDF_FAILURE; 480 } 481 name = baseFeature->getNetworkIfaceName(baseFeature); 482 if (name == NULL) { 483 HDF_LOGE("%{public}s get network iface name failed!", __func__); 484 return HDF_FAILURE; 485 } 486 if (strcpy_s(ifName, ifNameLen, name) != EOK) { 487 HDF_LOGE("%{public}s: copy ifName failed!", __func__); 488 return HDF_FAILURE; 489 } 490 return HDF_SUCCESS; 491} 492 493int32_t WlanInterfaceGetSupportCombo(struct IWlanInterface *self, uint64_t *combo) 494{ 495 int32_t ret; 496 497 (void)self; 498 if (combo == NULL) { 499 HDF_LOGE("%{public}s input parameter invalid!", __func__); 500 return HDF_ERR_INVALID_PARAM; 501 } 502 if (g_wifi == NULL || g_wifi->getSupportCombo == NULL) { 503 HDF_LOGE("%{public}s g_wifi or g_wifi->getSupportCombo is NULL!", __func__); 504 return HDF_FAILURE; 505 } 506 ret = g_wifi->getSupportCombo(combo, DEFAULT_COMBO_SIZE); 507 if (ret == HDF_ERR_NOT_SUPPORT) { 508 HDF_LOGW("%{public}s: not support to getting combo!, error code: %{public}d", __func__, ret); 509 } 510 return ret; 511} 512 513int32_t WlanInterfaceGetSupportFeature(struct IWlanInterface *self, uint8_t *supType, uint32_t *supTypeLen) 514{ 515 int32_t ret; 516 517 (void)self; 518 if (supType == NULL || supTypeLen == NULL) { 519 HDF_LOGE("%{public}s input parameter invalid!", __func__); 520 return HDF_ERR_INVALID_PARAM; 521 } 522 if (g_wifi == NULL || g_wifi->getSupportFeature == NULL) { 523 HDF_LOGE("%{public}s g_wifi or g_wifi->getSupportFeature is NULL!", __func__); 524 return HDF_FAILURE; 525 } 526 ret = g_wifi->getSupportFeature(supType, *supTypeLen); 527 if (ret != HDF_SUCCESS) { 528 HDF_LOGE("%{public}s get support feature failed! error code: %{public}d", __func__, ret); 529 } 530 return ret; 531} 532 533static int32_t HdfWlanAddRemoteObj(struct IWlanCallback *self) 534{ 535 struct HdfWlanRemoteNode *pos = NULL; 536 struct DListHead *head = &HdfStubDriver()->remoteListHead; 537 538 if (self == NULL) { 539 HDF_LOGE("%{public}s:self == NULL", __func__); 540 return HDF_ERR_INVALID_PARAM; 541 } 542 if (!DListIsEmpty(head)) { 543 DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWlanRemoteNode, node) { 544 if (pos->service == self->AsObject(self)) { 545 HDF_LOGE("%{public}s: pos->service == self", __func__); 546 return HDF_FAILURE; 547 } 548 } 549 } 550 551 struct HdfWlanRemoteNode *newRemoteNode = 552 (struct HdfWlanRemoteNode *)OsalMemCalloc(sizeof(struct HdfWlanRemoteNode)); 553 if (newRemoteNode == NULL) { 554 HDF_LOGE("%{public}s:newRemoteNode is NULL", __func__); 555 return HDF_FAILURE; 556 } 557 558 newRemoteNode->callbackObj = self; 559 newRemoteNode->service = self->AsObject(self); 560 DListInsertTail(&newRemoteNode->node, head); 561 return HDF_SUCCESS; 562} 563 564static int32_t FillData(uint8_t **dst, uint32_t *dstLen, uint8_t *src, uint32_t srcLen) 565{ 566 if (src == NULL || dst == NULL || dstLen == NULL) { 567 HDF_LOGE("%{public}s: Invalid parameter!", __func__); 568 return HDF_ERR_INVALID_PARAM; 569 } 570 *dst = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * srcLen); 571 if (*dst == NULL) { 572 HDF_LOGE("%{public}s: OsalMemCalloc fail!", __func__); 573 return HDF_FAILURE; 574 } 575 if (memcpy_s(*dst, srcLen, src, srcLen) != EOK) { 576 HDF_LOGE("%{public}s: memcpy_s fail!", __func__); 577 OsalMemFree(*dst); 578 *dst = NULL; 579 return HDF_FAILURE; 580 } 581 *dstLen = srcLen; 582 return HDF_SUCCESS; 583} 584 585static int32_t WlanFillScanResultInfo(WifiScanResult *wifiScanResult, struct HdfWifiScanResult *scanResult) 586{ 587 int32_t ret = HDF_SUCCESS; 588 if (wifiScanResult == NULL || scanResult == NULL) { 589 HDF_LOGE("%{public}s: wifiScanResult or scanResult is NULL!", __func__); 590 return HDF_ERR_INVALID_PARAM; 591 } 592 scanResult->flags = wifiScanResult->flags; 593 scanResult->caps = wifiScanResult->caps; 594 scanResult->freq = wifiScanResult->freq; 595 scanResult->beaconInt = wifiScanResult->beaconInt; 596 scanResult->qual = wifiScanResult->qual; 597 scanResult->level = wifiScanResult->level; 598 scanResult->age = wifiScanResult->age; 599 do { 600 if (wifiScanResult->bssid != NULL && 601 FillData(&scanResult->bssid, &scanResult->bssidLen, wifiScanResult->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) { 602 HDF_LOGE("%{public}s: fill bssid fail!", __func__); 603 ret = HDF_FAILURE; 604 break; 605 } 606 if ((wifiScanResult->ie != NULL) && (wifiScanResult->ieLen != 0) && 607 FillData(&scanResult->ie, &scanResult->ieLen, wifiScanResult->ie, wifiScanResult->ieLen) != HDF_SUCCESS) { 608 HDF_LOGE("%{public}s: fill ie fail!", __func__); 609 ret = HDF_FAILURE; 610 break; 611 } 612 if ((wifiScanResult->beaconIe != NULL) && (wifiScanResult->beaconIeLen != 0) && 613 FillData(&scanResult->beaconIe, &scanResult->beaconIeLen, wifiScanResult->beaconIe, 614 wifiScanResult->beaconIeLen) != HDF_SUCCESS) { 615 HDF_LOGE("%{public}s: fill beaconIe fail!", __func__); 616 ret = HDF_FAILURE; 617 } 618 } while (0); 619 if (ret != HDF_SUCCESS) { 620 if (scanResult->bssid != NULL) { 621 OsalMemFree(scanResult->bssid); 622 } 623 if (scanResult->ie != NULL) { 624 OsalMemFree(scanResult->ie); 625 } 626 if (scanResult->beaconIe != NULL) { 627 OsalMemFree(scanResult->beaconIe); 628 } 629 } 630 return ret; 631} 632 633static int32_t WlanFillScanResultInfoExt(WifiScanResult *wifiScanResult, struct HdfWifiScanResultExt *scanResult) 634{ 635 int32_t ret = HDF_SUCCESS; 636 if (wifiScanResult == NULL || scanResult == NULL) { 637 HDF_LOGE("%{public}s: wifiScanResult or scanResult is NULL!", __func__); 638 return HDF_ERR_INVALID_PARAM; 639 } 640 scanResult->flags = wifiScanResult->flags; 641 scanResult->caps = wifiScanResult->caps; 642 scanResult->freq = wifiScanResult->freq; 643 scanResult->beaconInt = wifiScanResult->beaconInt; 644 scanResult->qual = wifiScanResult->qual; 645 scanResult->level = wifiScanResult->level; 646 scanResult->age = wifiScanResult->age; 647 scanResult->tsf = wifiScanResult->tsf; 648 do { 649 if (wifiScanResult->bssid != NULL && 650 FillData(&scanResult->bssid, &scanResult->bssidLen, wifiScanResult->bssid, ETH_ADDR_LEN) != HDF_SUCCESS) { 651 HDF_LOGE("%{public}s: fill bssid fail!", __func__); 652 ret = HDF_FAILURE; 653 break; 654 } 655 if ((wifiScanResult->ie != NULL) && (wifiScanResult->ieLen != 0) && 656 FillData(&scanResult->ie, &scanResult->ieLen, wifiScanResult->ie, wifiScanResult->ieLen) != HDF_SUCCESS) { 657 HDF_LOGE("%{public}s: fill ie fail!", __func__); 658 ret = HDF_FAILURE; 659 break; 660 } 661 if ((wifiScanResult->beaconIe != NULL) && (wifiScanResult->beaconIeLen != 0) && 662 FillData(&scanResult->beaconIe, &scanResult->beaconIeLen, wifiScanResult->beaconIe, 663 wifiScanResult->beaconIeLen) != HDF_SUCCESS) { 664 HDF_LOGE("%{public}s: fill beaconIe fail!", __func__); 665 ret = HDF_FAILURE; 666 } 667 } while (0); 668 if (ret != HDF_SUCCESS) { 669 if (scanResult->bssid != NULL) { 670 OsalMemFree(scanResult->bssid); 671 } 672 if (scanResult->ie != NULL) { 673 OsalMemFree(scanResult->ie); 674 } 675 if (scanResult->beaconIe != NULL) { 676 OsalMemFree(scanResult->beaconIe); 677 } 678 } 679 return ret; 680} 681 682static int32_t WlanFillScanResultsInfo(WifiScanResults *wifiScanResults, struct HdfWifiScanResults *scanResults) 683{ 684 uint32_t i; 685 if (wifiScanResults == NULL || scanResults == NULL) { 686 HDF_LOGE("%{public}s: wifiScanResults or scanResults is NULL!", __func__); 687 return HDF_ERR_INVALID_PARAM; 688 } 689 for (i = 0; i < wifiScanResults->num; i++) { 690 if (WlanFillScanResultInfoExt(&wifiScanResults->scanResult[i], &scanResults->res[i]) != HDF_SUCCESS) { 691 return HDF_FAILURE; 692 } 693 } 694 scanResults->resLen = wifiScanResults->num; 695 return HDF_SUCCESS; 696} 697 698static int32_t ProcessEventScanResult(struct HdfWlanRemoteNode *node, uint32_t event, WifiScanResult *wifiScanResult, 699 const char *ifName) 700{ 701 HDF_LOGI("hal enter %{public}s, event:%{public}u ifName:%{public}s", __FUNCTION__, event, ifName); 702 struct HdfWifiScanResult *scanResult = NULL; 703 int32_t ret = HDF_FAILURE; 704 705 if (node == NULL || node->callbackObj == NULL || node->callbackObj->ScanResult == NULL) { 706 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__); 707 return HDF_ERR_INVALID_PARAM; 708 } 709 scanResult = (struct HdfWifiScanResult *)OsalMemCalloc(sizeof(struct HdfWifiScanResult)); 710 if ((scanResult == NULL) || (WlanFillScanResultInfo(wifiScanResult, scanResult) != HDF_SUCCESS)) { 711 HDF_LOGE("%{public}s: scanResult is NULL or WlanFillScanResultInfo fialed!", __func__); 712 } else { 713 ret = node->callbackObj->ScanResult(node->callbackObj, event, scanResult, ifName); 714 } 715 HdfWifiScanResultFree(scanResult, true); 716 HDF_LOGI("hal exit %{public}s", __FUNCTION__); 717 return ret; 718} 719 720static int32_t ProcessEventScanResults(struct HdfWlanRemoteNode *node, uint32_t event, 721 WifiScanResults *wifiScanResults, const char *ifName) 722{ 723 HDF_LOGD("hal enter %{public}s, event:%{public}u ifName:%{public}s", __FUNCTION__, event, ifName); 724 struct HdfWifiScanResults *scanResults = NULL; 725 uint32_t size; 726 int32_t ret = HDF_FAILURE; 727 728 if (node == NULL || node->callbackObj == NULL || node->callbackObj->ScanResults == NULL) { 729 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__); 730 return HDF_ERR_INVALID_PARAM; 731 } 732 scanResults = (struct HdfWifiScanResults *)OsalMemCalloc(sizeof(struct HdfWifiScanResults)); 733 if (scanResults == NULL) { 734 HDF_LOGE("%{public}s: scanResults is NULL!", __func__); 735 return HDF_ERR_MALLOC_FAIL; 736 } 737 if (wifiScanResults->num == 0) { 738 scanResults->res = NULL; 739 scanResults->resLen = 0; 740 ret = node->callbackObj->ScanResults(node->callbackObj, event, scanResults, ifName); 741 HdfWifiScanResultsFree(scanResults, true); 742 HDF_LOGD("%{public}s: scanResults num is 0!", __func__); 743 return ret; 744 } 745 scanResults->resLen = wifiScanResults->num; 746 size = sizeof(struct HdfWifiScanResultExt); 747 scanResults->res = (struct HdfWifiScanResultExt *)OsalMemCalloc(size * scanResults->resLen); 748 if ((scanResults->res == NULL) || (WlanFillScanResultsInfo(wifiScanResults, scanResults) != HDF_SUCCESS)) { 749 HDF_LOGE("%{public}s: scanResults->res is NULL or WlanFillScanResultsInfo fialed!", __func__); 750 } else { 751 ret = node->callbackObj->ScanResults(node->callbackObj, event, scanResults, ifName); 752 } 753 HdfWifiScanResultsFree(scanResults, true); 754 HDF_LOGD("hal exit %{public}s, wifiScanResults num:%{public}u", __FUNCTION__, wifiScanResults->num); 755 return ret; 756} 757 758static int32_t ProcessEventScanAborted(struct HdfWlanRemoteNode *node, uint32_t event, const char *ifName) 759{ 760 HDF_LOGI("hal enter %{public}s, event:%{public}u ifName:%{public}s", __FUNCTION__, event, ifName); 761 int32_t ret = HDF_FAILURE; 762 struct HdfWifiScanResults scanResults = {0}; 763 764 if (node == NULL || node->callbackObj == NULL || node->callbackObj->ScanResults == NULL) { 765 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__); 766 return HDF_ERR_INVALID_PARAM; 767 } 768 ret = node->callbackObj->ScanResults(node->callbackObj, event, &scanResults, ifName); 769 HDF_LOGI("hal exit %{public}s, ScanResults ret:%{public}d", __FUNCTION__, ret); 770 return ret; 771} 772 773static int32_t ProcessEventActionReceived(struct HdfWlanRemoteNode *node, uint32_t event, 774 WifiActionData *wifiActionData, const char *ifName) 775{ 776 HDF_LOGI("hal enter %{public}s, event:%{public}u ifName:%{public}s", __FUNCTION__, event, ifName); 777 int32_t ret = HDF_FAILURE; 778 779 if (node == NULL || wifiActionData == NULL || ifName == NULL || node->callbackObj == NULL || 780 node->callbackObj->WifiNetlinkMessage == NULL) { 781 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__); 782 return HDF_ERR_INVALID_PARAM; 783 } 784 ret = node->callbackObj->WifiNetlinkMessage(node->callbackObj, wifiActionData->data, wifiActionData->dataLen); 785 HDF_LOGI("hal exit %{public}s, WifiNetlinkMessage ret:%{public}d", __FUNCTION__, ret); 786 return ret; 787} 788 789static int32_t ProcessEventDataFrameReceived(struct HdfWlanRemoteNode *node, uint32_t event, 790 WifiDataFrame *dataFrame, const char *ifName) 791{ 792 HDF_LOGI("hal enter %{public}s, event:%{public}u ifName:%{public}s", __FUNCTION__, event, ifName); 793 int32_t ret = HDF_FAILURE; 794 795 if ((node == NULL) || (dataFrame == NULL) || (ifName == NULL) || (node->callbackObj == NULL) || 796 (node->callbackObj->WifiNetlinkMessage == NULL)) { 797 HDF_LOGE("%{public}s: hdf wlan remote node or callbackObj is NULL!", __func__); 798 return HDF_ERR_INVALID_PARAM; 799 } 800 ret = node->callbackObj->WifiNetlinkMessage(node->callbackObj, dataFrame->data, dataFrame->dataLen); 801 HDF_LOGI("hal exit %{public}s, WifiNetlinkMessage ret:%{public}d", __FUNCTION__, ret); 802 return ret; 803} 804 805static int32_t HandleWifiEvent(uint32_t event, void *data, const char *ifName, struct HdfWlanRemoteNode *pos) 806{ 807 int ret = HDF_FAILURE; 808 int32_t *code = NULL; 809 if (data == NULL || ifName == NULL || pos == NULL) { 810 HDF_LOGE("%{public}s: invalid input", __func__); 811 return ret; 812 } 813 switch (event) { 814 case WIFI_EVENT_RESET_DRIVER: 815 code = (int32_t *)data; 816 ret = pos->callbackObj->ResetDriverResult(pos->callbackObj, event, *code, ifName); 817 break; 818 case WIFI_EVENT_SCAN_RESULT: 819 ret = ProcessEventScanResult(pos, event, (WifiScanResult *)data, ifName); 820 break; 821 case WIFI_EVENT_SCAN_RESULTS: 822 ret = ProcessEventScanResults(pos, event, (WifiScanResults *)data, ifName); 823 break; 824 case WIFI_EVENT_SCAN_ABORTED: 825 ret = ProcessEventScanAborted(pos, event, ifName); 826 break; 827 case WIFI_EVENT_ACTION_RECEIVED: 828 ret = ProcessEventActionReceived(pos, event, (WifiActionData *)data, ifName); 829 break; 830 case WIFI_EVENT_DATA_FRAME_RECEIVED: 831 ret = ProcessEventDataFrameReceived(pos, event, (WifiDataFrame *)data, ifName); 832 break; 833 default: 834 HDF_LOGE("%{public}s: unknown eventId:%{public}d", __func__, event); 835 break; 836 } 837 return ret; 838} 839 840static int32_t HdfWLanCallbackFun(uint32_t event, void *data, const char *ifName) 841{ 842 HDF_LOGD("%{public}s, event:%{public}u ifName:%{public}s", __FUNCTION__, event, ifName); 843 struct HdfWlanRemoteNode *pos = NULL; 844 struct DListHead *head = NULL; 845 int32_t ret = HDF_FAILURE; 846 (void)OsalMutexLock(&HdfStubDriver()->mutex); 847 head = &HdfStubDriver()->remoteListHead; 848 849 if (data == NULL || ifName == NULL) { 850 HDF_LOGE("%{public}s: data or ifName is NULL!", __func__); 851 (void)OsalMutexUnlock(&HdfStubDriver()->mutex); 852 return HDF_ERR_INVALID_PARAM; 853 } 854 DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWlanRemoteNode, node) { 855 if (pos == NULL) { 856 HDF_LOGE("%{public}s: pos is NULL", __func__); 857 break; 858 } 859 if (pos->service == NULL || pos->callbackObj == NULL) { 860 HDF_LOGW("%{public}s: pos->service or pos->callbackObj NULL", __func__); 861 continue; 862 } 863 ret = HandleWifiEvent(event, data, ifName, pos); 864 if (ret != HDF_SUCCESS) { 865 HDF_LOGE("%{public}s: dispatch code fialed, error code: %{public}d", __func__, ret); 866 } 867 } 868 (void)OsalMutexUnlock(&HdfStubDriver()->mutex); 869 return ret; 870} 871 872static int32_t HdfWlanNetlinkCallbackFun(const uint8_t *recvMsg, uint32_t recvMsgLen) 873{ 874 struct HdfWlanRemoteNode *pos = NULL; 875 struct DListHead *head = NULL; 876 int32_t ret = HDF_FAILURE; 877 (void)OsalMutexLock(&HdfStubDriver()->mutex); 878 head = &HdfStubDriver()->remoteListHead; 879 880 if (recvMsg == NULL) { 881 HDF_LOGE("%{public}s: recvMsg or ifName is NULL!", __func__); 882 (void)OsalMutexUnlock(&HdfStubDriver()->mutex); 883 return HDF_ERR_INVALID_PARAM; 884 } 885 DLIST_FOR_EACH_ENTRY(pos, head, struct HdfWlanRemoteNode, node) { 886 if (pos->service == NULL || pos->callbackObj == NULL) { 887 HDF_LOGW("%{public}s: pos->service or pos->callbackObj NULL", __func__); 888 continue; 889 } 890 ret = pos->callbackObj->WifiNetlinkMessage(pos->callbackObj, recvMsg, recvMsgLen); 891 if (ret != HDF_SUCCESS) { 892 HDF_LOGD("%{public}s: dispatch code fialed, error code: %{public}d", __func__, ret); 893 } 894 } 895 (void)OsalMutexUnlock(&HdfStubDriver()->mutex); 896 return ret; 897} 898 899static void HdfWlanDelRemoteObj(struct IWlanCallback *self) 900{ 901 struct HdfWlanRemoteNode *pos = NULL; 902 struct HdfWlanRemoteNode *tmp = NULL; 903 struct DListHead *head = &HdfStubDriver()->remoteListHead; 904 905 DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, head, struct HdfWlanRemoteNode, node) { 906 if (pos->service->index == self->AsObject(self)->index) { 907 DListRemove(&(pos->node)); 908 IWlanCallbackRelease(pos->callbackObj); 909 OsalMemFree(pos); 910 break; 911 } 912 } 913 IWlanCallbackRelease(self); 914} 915 916int32_t WlanInterfaceRegisterEventCallback(struct IWlanInterface *self, struct IWlanCallback *cbFunc, 917 const char *ifName) 918{ 919 int32_t ret; 920 HDF_LOGI("hal enter %{public}s, ifName:%{public}s", __FUNCTION__, ifName); 921 (void)self; 922 if (cbFunc == NULL || ifName == NULL) { 923 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 924 return HDF_ERR_INVALID_PARAM; 925 } 926 if (g_wifi == NULL || g_wifi->registerEventCallback == NULL) { 927 HDF_LOGE("%{public}s g_wifi or g_wifi->registerEventCallback is NULL!", __func__); 928 return HDF_FAILURE; 929 } 930 (void)OsalMutexLock(&HdfStubDriver()->mutex); 931 932 do { 933 ret = HdfWlanAddRemoteObj(cbFunc); 934 if (ret != HDF_SUCCESS) { 935 HDF_LOGE("%{public}s: HdfSensorAddRemoteObj false", __func__); 936 break; 937 } 938 ret = g_wifi->registerEventCallback(HdfWLanCallbackFun, ifName); 939 if (ret != HDF_SUCCESS) { 940 HDF_LOGE("%{public}s: Register failed!, error code: %{public}d", __func__, ret); 941 HdfWlanDelRemoteObj(cbFunc); 942 break; 943 } 944 ret = WlanInterfaceRegisterHid2dCallback(HdfWlanNetlinkCallbackFun, ifName); 945 if (ret != HDF_SUCCESS) { 946 HDF_LOGE("%{public}s: Register failed!, error code: %{public}d", __func__, ret); 947 g_wifi->unregisterEventCallback(HdfWLanCallbackFun, ifName); 948 HdfWlanDelRemoteObj(cbFunc); 949 } 950 } while (0); 951 952 (void)OsalMutexUnlock(&HdfStubDriver()->mutex); 953 HDF_LOGI("hal exit %{public}s, ret:%{public}d", __FUNCTION__, ret); 954 return ret; 955} 956 957int32_t WlanInterfaceUnregisterEventCallback(struct IWlanInterface *self, struct IWlanCallback *cbFunc, 958 const char *ifName) 959{ 960 HDF_LOGI("hal enter %{public}s, ifName:%{public}s", __FUNCTION__, ifName); 961 int32_t ret; 962 963 (void)self; 964 if (cbFunc == NULL || ifName == NULL) { 965 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 966 return HDF_ERR_INVALID_PARAM; 967 } 968 if (g_wifi == NULL || g_wifi->unregisterEventCallback == NULL) { 969 HDF_LOGE("%{public}s g_wifi or g_wifi->unregisterEventCallback is NULL!", __func__); 970 return HDF_FAILURE; 971 } 972 (void)OsalMutexLock(&HdfStubDriver()->mutex); 973 HdfWlanDelRemoteObj(cbFunc); 974 if (DListIsEmpty(&HdfStubDriver()->remoteListHead)) { 975 ret = g_wifi->unregisterEventCallback(HdfWLanCallbackFun, ifName); 976 if (ret != HDF_SUCCESS) { 977 HDF_LOGE("%{public}s: Unregister failed!, error code: %{public}d", __func__, ret); 978 } 979 ret = WlanInterfaceUnregisterHid2dCallback(HdfWlanNetlinkCallbackFun, ifName); 980 if (ret != HDF_SUCCESS) { 981 HDF_LOGE("%{public}s: Unregister Hid2dCallback failed!, error code: %{public}d", __func__, ret); 982 } 983 } 984 (void)OsalMutexUnlock(&HdfStubDriver()->mutex); 985 HDF_LOGI("hal exit %{public}s", __FUNCTION__); 986 return HDF_SUCCESS; 987} 988 989int32_t WlanInterfaceResetDriver(struct IWlanInterface *self, uint8_t chipId, const char *ifName) 990{ 991 int32_t ret; 992 993 (void)self; 994 if (ifName == NULL) { 995 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 996 return HDF_ERR_INVALID_PARAM; 997 } 998 if (g_wifi == NULL || g_wifi->resetDriver == NULL) { 999 HDF_LOGE("%{public}s g_wifi or g_wifi->resetDriver is NULL!", __func__); 1000 return HDF_FAILURE; 1001 } 1002 ret = g_wifi->resetDriver(chipId, ifName); 1003 if (ret != HDF_SUCCESS) { 1004 HDF_LOGE("%{public}s reset driver failed! error code: %{public}d", __func__, ret); 1005 return ret; 1006 } 1007 OsalMSleep(RESET_TIME); 1008 return ret; 1009} 1010 1011int32_t WlanInterfaceSetCountryCode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, 1012 const char *code, uint32_t len) 1013{ 1014 int32_t ret; 1015 1016 (void)self; 1017 if (ifeature == NULL || ifeature->ifName == NULL || code == NULL) { 1018 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1019 return HDF_ERR_INVALID_PARAM; 1020 } 1021 if (g_apFeature == NULL || g_apFeature->setCountryCode == NULL) { 1022 HDF_LOGE("%{public}s g_apFeature or g_apFeature->setCountryCode is NULL!", __func__); 1023 return HDF_FAILURE; 1024 } 1025 ret = strcpy_s((g_apFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName); 1026 if (ret != HDF_SUCCESS) { 1027 HDF_LOGE("%{public}s: strcpy_s apFeature ifName is failed!", __func__); 1028 return HDF_FAILURE; 1029 } 1030 ret = g_apFeature->setCountryCode(g_apFeature, code, strlen(code)); 1031 if (ret != HDF_SUCCESS) { 1032 HDF_LOGE("%{public}s set country code failed!, error code: %{public}d", __func__, ret); 1033 } 1034 return ret; 1035} 1036 1037int32_t WlanInterfaceSetMacAddress(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, 1038 const uint8_t *mac, uint32_t macLen) 1039{ 1040 int32_t ret = HDF_FAILURE; 1041 struct IWiFiBaseFeature *baseFeature = NULL; 1042 1043 (void)self; 1044 if (ifeature == NULL || mac == NULL || ifeature->ifName == NULL) { 1045 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1046 return HDF_ERR_INVALID_PARAM; 1047 } 1048 ret = GetBasefeature(ifeature, &baseFeature); 1049 if (ret != HDF_SUCCESS) { 1050 HDF_LOGE("%{public}s GetBasefeature failed!", __func__); 1051 return HDF_FAILURE; 1052 } 1053 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName); 1054 if (ret != HDF_SUCCESS) { 1055 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret); 1056 return HDF_FAILURE; 1057 } 1058 return baseFeature->setMacAddress(baseFeature, (uint8_t *)mac, ETH_ADDR_LEN); 1059} 1060 1061int32_t WlanInterfaceSetScanningMacAddress(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, 1062 const uint8_t *scanMac, uint32_t scanMacLen) 1063{ 1064 int32_t ret; 1065 1066 (void)self; 1067 if (ifeature == NULL || ifeature->ifName == NULL || scanMac == NULL) { 1068 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1069 return HDF_ERR_INVALID_PARAM; 1070 } 1071 if (g_staFeature == NULL || g_staFeature->setScanningMacAddress == NULL) { 1072 HDF_LOGE("%{public}s g_staFeature or g_staFeature->setScanningMacAddress is NULL!", __func__); 1073 return HDF_FAILURE; 1074 } 1075 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifeature->ifName); 1076 if (ret != HDF_SUCCESS) { 1077 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret); 1078 return HDF_FAILURE; 1079 } 1080 ret = g_staFeature->setScanningMacAddress(g_staFeature, (uint8_t *)scanMac, (uint8_t)scanMacLen); 1081 1082 return ret; 1083} 1084 1085int32_t WlanInterfaceSetTxPower(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, int32_t power) 1086{ 1087 int32_t ret; 1088 struct IWiFiBaseFeature *baseFeature = NULL; 1089 1090 (void)self; 1091 if (ifeature == NULL || ifeature->ifName == NULL) { 1092 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1093 return HDF_ERR_INVALID_PARAM; 1094 } 1095 ret = GetBasefeature(ifeature, &baseFeature); 1096 if (ret != HDF_SUCCESS) { 1097 HDF_LOGE("%{public}s GetBasefeature failed!", __func__); 1098 return HDF_FAILURE; 1099 } 1100 ret = strcpy_s(baseFeature->ifName, IFNAMSIZ, ifeature->ifName); 1101 if (ret != HDF_SUCCESS) { 1102 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret); 1103 return HDF_FAILURE; 1104 } 1105 1106 return baseFeature->setTxPower(baseFeature, power); 1107} 1108 1109int32_t WlanInterfaceGetNetDevInfo(struct IWlanInterface *self, struct HdfNetDeviceInfoResult *netDeviceInfoResult) 1110{ 1111 int32_t ret = HDF_FAILURE; 1112 1113 (void)self; 1114 if (g_wifi == NULL || g_wifi->getNetDevInfo == NULL ||netDeviceInfoResult == NULL) { 1115 HDF_LOGE("%{public}s: input parameter invalid!", __func__); 1116 return HDF_ERR_INVALID_PARAM; 1117 } 1118 struct NetDeviceInfoResult *netDeviceInfo = 1119 (struct NetDeviceInfoResult *)OsalMemCalloc(sizeof(struct NetDeviceInfoResult)); 1120 if (netDeviceInfo == NULL) { 1121 HDF_LOGE("%{public}s:OsalMemCalloc failed!", __func__); 1122 return HDF_FAILURE; 1123 } 1124 ret = g_wifi->getNetDevInfo(netDeviceInfo); 1125 if (ret != HDF_SUCCESS) { 1126 HDF_LOGE("%{public}s: get netdev info failed!, error code: %{public}d", __func__, ret); 1127 OsalMemFree(netDeviceInfo); 1128 return HDF_FAILURE; 1129 } 1130 1131 netDeviceInfoResult->deviceInfos = 1132 (struct HdfNetDeviceInfo *)OsalMemCalloc(sizeof(struct HdfNetDeviceInfo) * MAX_NETDEVICE_COUNT); 1133 if (netDeviceInfoResult->deviceInfos == NULL) { 1134 HDF_LOGE("%{public}s:netDeviceInfoResult->deviceInfos OsalMemCalloc failed", __func__); 1135 OsalMemFree(netDeviceInfo); 1136 return HDF_FAILURE; 1137 } 1138 netDeviceInfoResult->deviceInfosLen = MAX_NETDEVICE_COUNT; 1139 for (uint32_t i = 0; i < netDeviceInfoResult->deviceInfosLen; i++) { 1140 netDeviceInfoResult->deviceInfos[i].index = netDeviceInfo->deviceInfos[i].index; 1141 netDeviceInfoResult->deviceInfos[i].iftype = netDeviceInfo->deviceInfos[i].iftype; 1142 netDeviceInfoResult->deviceInfos[i].ifName = (char *)OsalMemCalloc(sizeof(char) * IFNAMSIZ); 1143 if (netDeviceInfoResult->deviceInfos != NULL) { 1144 if (memcpy_s(netDeviceInfoResult->deviceInfos[i].ifName, IFNAMSIZ, netDeviceInfo->deviceInfos[i].ifName, 1145 IFNAMSIZ) != EOK) { 1146 OsalMemFree(netDeviceInfoResult->deviceInfos[i].ifName); 1147 break; 1148 } 1149 netDeviceInfoResult->deviceInfos[i].ifNameLen = IFNAMSIZ; 1150 } 1151 netDeviceInfoResult->deviceInfos[i].mac = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * ETH_ADDR_LEN); 1152 if (netDeviceInfoResult->deviceInfos[i].mac != NULL) { 1153 if (memcpy_s(netDeviceInfoResult->deviceInfos[i].mac, ETH_ADDR_LEN, netDeviceInfo->deviceInfos[i].mac, 1154 ETH_ADDR_LEN) != EOK) { 1155 OsalMemFree(netDeviceInfoResult->deviceInfos[i].mac); 1156 break; 1157 } 1158 netDeviceInfoResult->deviceInfos[i].macLen = ETH_ADDR_LEN; 1159 } 1160 } 1161 OsalMemFree(netDeviceInfo); 1162 return ret; 1163} 1164 1165static int32_t WLanFillSsid(WifiScan *wifiScan, const struct HdfWifiScan *scan) 1166{ 1167 uint32_t loop; 1168 1169 for (loop = 0; loop < scan->ssidsLen; loop++) { 1170 if (scan->ssids[loop].ssidLen > MAX_SSID_LEN) { 1171 HDF_LOGW("%{public}s fail : ssidLen is invalid!", __func__); 1172 scan->ssids[loop].ssidLen = MAX_SSID_LEN - 1; 1173 } 1174 if (memcpy_s(wifiScan->ssids[loop].ssid, scan->ssids[loop].ssidLen, scan->ssids[loop].ssid, 1175 scan->ssids[loop].ssidLen) != EOK) { 1176 HDF_LOGE("%{public}s fail : memcpy_s ssids fail!", __func__); 1177 return HDF_FAILURE; 1178 } 1179 wifiScan->ssids[loop].ssidLen = (uint32_t)(scan->ssids[loop].ssidLen); 1180 } 1181 return HDF_SUCCESS; 1182} 1183 1184static int32_t WLanFillScanData(WifiScan *wifiScan, const struct HdfWifiScan *scan) 1185{ 1186 if ((scan->ssids != NULL) && (scan->ssidsLen != 0)) { 1187 wifiScan->ssids = (WifiDriverScanSsid *)OsalMemCalloc(sizeof(WifiDriverScanSsid) * scan->ssidsLen); 1188 if (wifiScan->ssids != NULL) { 1189 if (WLanFillSsid(wifiScan, scan) != HDF_SUCCESS) { 1190 HDF_LOGE("%{public}s fail : fill ssids fail!", __func__); 1191 OsalMemFree(wifiScan->ssids); 1192 return HDF_FAILURE; 1193 } 1194 wifiScan->numSsids = scan->ssidsLen; 1195 } 1196 } 1197 1198 if ((scan->freqs != NULL) && (scan->freqsLen != 0)) { 1199 wifiScan->freqs = (int32_t *)OsalMemCalloc(sizeof(int32_t) * scan->freqsLen); 1200 if (wifiScan->freqs != NULL) { 1201 if (memcpy_s(wifiScan->freqs, sizeof(int32_t) * (scan->freqsLen), scan->freqs, 1202 sizeof(int32_t) * (scan->freqsLen)) != EOK) { 1203 HDF_LOGE("%{public}s fail : memcpy_s freqs fail!", __func__); 1204 OsalMemFree(wifiScan->freqs); 1205 return HDF_FAILURE; 1206 } 1207 wifiScan->numFreqs = scan->freqsLen; 1208 } 1209 } 1210 1211 if ((scan->bssid != NULL) && (scan->bssidLen != 0)) { 1212 wifiScan->bssid = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * scan->bssidLen); 1213 if (wifiScan->bssid != NULL) { 1214 if (memcpy_s(wifiScan->bssid, sizeof(uint8_t) * (scan->bssidLen), scan->bssid, 1215 sizeof(uint8_t) * (scan->bssidLen)) != EOK) { 1216 HDF_LOGE("%{public}s fail : memcpy_s bssid fail!", __func__); 1217 OsalMemFree(wifiScan->bssid); 1218 return HDF_FAILURE; 1219 } 1220 } 1221 } 1222 if ((scan->extraIes != NULL) && (scan->extraIesLen != 0)) { 1223 wifiScan->extraIes = (uint8_t *)OsalMemCalloc(sizeof(uint8_t) * scan->extraIesLen); 1224 if (wifiScan->extraIes != NULL) { 1225 if (memcpy_s(wifiScan->extraIes, sizeof(uint8_t) * (scan->extraIesLen), scan->extraIes, 1226 sizeof(uint8_t) * (scan->extraIesLen)) != EOK) { 1227 HDF_LOGE("%{public}s fail : memcpy_s extraIes fail!", __func__); 1228 OsalMemFree(wifiScan->extraIes); 1229 return HDF_FAILURE; 1230 } 1231 wifiScan->extraIesLen = scan->extraIesLen; 1232 } 1233 } 1234 1235 wifiScan->prefixSsidScanFlag = scan->prefixSsidScanFlag; 1236 wifiScan->fastConnectFlag = scan->fastConnectFlag; 1237 return HDF_SUCCESS; 1238} 1239 1240static void WifiScanFree(WifiScan *dataBlock) 1241{ 1242 if (dataBlock == NULL) { 1243 return; 1244 } 1245 1246 if (dataBlock->ssids != NULL) { 1247 OsalMemFree(dataBlock->ssids); 1248 dataBlock->ssids = NULL; 1249 } 1250 if (dataBlock->freqs != NULL) { 1251 OsalMemFree(dataBlock->freqs); 1252 dataBlock->freqs = NULL; 1253 } 1254 if (dataBlock->bssid != NULL) { 1255 OsalMemFree(dataBlock->bssid); 1256 dataBlock->bssid = NULL; 1257 } 1258 if (dataBlock->extraIes != NULL) { 1259 OsalMemFree(dataBlock->extraIes); 1260 dataBlock->extraIes = NULL; 1261 } 1262 OsalMemFree(dataBlock); 1263} 1264 1265int32_t WlanInterfaceStartScan(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, 1266 const struct HdfWifiScan *scan) 1267{ 1268 HDF_LOGI("hal enter %{public}s", __FUNCTION__); 1269 int32_t ret = HDF_FAILURE; 1270 1271 (void)self; 1272 if (ifeature == NULL || ifeature->ifName == NULL || scan == NULL) { 1273 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1274 return HDF_ERR_INVALID_PARAM; 1275 } 1276 WifiScan *wifiScan = (WifiScan *)OsalMemCalloc(sizeof(WifiScan)); 1277 if (wifiScan == NULL) { 1278 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__); 1279 return HDF_FAILURE; 1280 } 1281 if (WLanFillScanData(wifiScan, scan) != HDF_SUCCESS) { 1282 HDF_LOGE("%{public}s fail : fill scan data fail!", __func__); 1283 WifiScanFree(wifiScan); 1284 return HDF_FAILURE; 1285 } 1286 if (g_staFeature == NULL || g_staFeature->startScan == NULL) { 1287 HDF_LOGE("%{public}s g_staFeature or g_staFeature->startScan is NULL!", __func__); 1288 WifiScanFree(wifiScan); 1289 return HDF_FAILURE; 1290 } 1291 ret = g_staFeature->startScan(ifeature->ifName, wifiScan); 1292 if (ret != HDF_SUCCESS) { 1293 HDF_LOGE("%{public}s start scan failed!, error code: %{public}d", __func__, ret); 1294 } 1295 WifiScanFree(wifiScan); 1296 HDF_LOGI("hal exit %{public}s, ret:%{public}d", __FUNCTION__, ret); 1297 return ret; 1298} 1299 1300int32_t WlanInterfaceGetPowerMode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, uint8_t *mode) 1301{ 1302 int32_t ret; 1303 1304 (void)self; 1305 if (ifeature == NULL || ifeature->ifName == NULL || mode == NULL) { 1306 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1307 return HDF_ERR_INVALID_PARAM; 1308 } 1309 if (g_wifi == NULL || g_wifi->getPowerMode == NULL) { 1310 HDF_LOGE("%{public}s g_wifi or g_wifi->getPowerMode is NULL!", __func__); 1311 return HDF_FAILURE; 1312 } 1313 ret = g_wifi->getPowerMode(ifeature->ifName, mode); 1314 if (ret != HDF_SUCCESS) { 1315 HDF_LOGE("%{public}s: get power mode failed!, error code: %{public}d", __func__, ret); 1316 } 1317 return ret; 1318} 1319 1320int32_t WlanInterfaceSetPowerMode(struct IWlanInterface *self, const struct HdfFeatureInfo *ifeature, uint8_t mode) 1321{ 1322 int32_t ret; 1323 1324 (void)self; 1325 if (ifeature == NULL || ifeature->ifName == NULL) { 1326 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1327 return HDF_ERR_INVALID_PARAM; 1328 } 1329 if (g_wifi == NULL || g_wifi->setPowerMode == NULL) { 1330 HDF_LOGE("%{public}s g_wifi or g_wifi->setPowerMode is NULL!", __func__); 1331 return HDF_FAILURE; 1332 } 1333 ret = g_wifi->setPowerMode(ifeature->ifName, mode); 1334 if (ret != HDF_SUCCESS) { 1335 HDF_LOGE("%{public}s: get power mode failed!, error code: %{public}d", __func__, ret); 1336 } 1337 return ret; 1338} 1339 1340int32_t WlanInterfaceSetProjectionScreenParam(struct IWlanInterface *self, const char *ifName, 1341 const struct ProjectionScreenCmdParam *param) 1342{ 1343 int32_t ret; 1344 ProjectionScreenParam *projectionScreenParam = NULL; 1345 1346 (void)self; 1347 if (ifName == NULL || param == NULL) { 1348 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1349 return HDF_ERR_INVALID_PARAM; 1350 } 1351 if (g_wifi == NULL || g_wifi->setProjectionScreenParam == NULL) { 1352 HDF_LOGE("%{public}s g_wifi or g_wifi->setProjectionScreenParam is NULL!", __func__); 1353 return HDF_FAILURE; 1354 } 1355 1356 projectionScreenParam = OsalMemCalloc(sizeof(ProjectionScreenParam) + param->bufLen); 1357 if (projectionScreenParam == NULL) { 1358 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__); 1359 return HDF_FAILURE; 1360 } 1361 projectionScreenParam->cmdId = param->cmdId; 1362 projectionScreenParam->bufLen = param->bufLen; 1363 do { 1364 if (memcpy_s(projectionScreenParam->buf, projectionScreenParam->bufLen, param->buf, param->bufLen) != EOK) { 1365 HDF_LOGE("%{public}s: memcpy_s failed", __func__); 1366 ret = HDF_FAILURE; 1367 break; 1368 } 1369 ret = g_wifi->setProjectionScreenParam(ifName, projectionScreenParam); 1370 if (ret != HDF_SUCCESS) { 1371 HDF_LOGE("%{public}s: get channel meas result failed!, error code: %{public}d", __func__, ret); 1372 } 1373 } while (0); 1374 1375 OsalMemFree(projectionScreenParam); 1376 return ret; 1377} 1378 1379int32_t WlanInterfaceGetStaInfo(struct IWlanInterface *self, const char *ifName, struct WifiStationInfo *info, 1380 const uint8_t *mac, uint32_t macLen) 1381{ 1382 int32_t ret; 1383 1384 (void)self; 1385 if (ifName == NULL || info == NULL || mac == NULL) { 1386 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1387 return HDF_ERR_INVALID_PARAM; 1388 } 1389 if (g_wifi == NULL || g_wifi->getStationInfo == NULL) { 1390 HDF_LOGE("%{public}s g_wifi or g_wifi->getStationInfo is NULL!", __func__); 1391 return HDF_FAILURE; 1392 } 1393 ret = g_wifi->getStationInfo(ifName, (StationInfo *)info, mac, macLen); 1394 if (ret != HDF_SUCCESS) { 1395 HDF_LOGE("%{public}s: get station information failed!, error code: %{public}d", __func__, ret); 1396 } 1397 return ret; 1398} 1399 1400static int32_t FillPnoSettings(WifiPnoSettings *wifiPnoSettings, const struct PnoSettings *pnoSettings) 1401{ 1402 wifiPnoSettings->min2gRssi = pnoSettings->min2gRssi; 1403 wifiPnoSettings->min5gRssi = pnoSettings->min5gRssi; 1404 wifiPnoSettings->scanIntervalMs = pnoSettings->scanIntervalMs; 1405 wifiPnoSettings->scanIterations = pnoSettings->scanIterations; 1406 1407 if ((pnoSettings->pnoNetworks == NULL) || (pnoSettings->pnoNetworksLen == 0)) { 1408 HDF_LOGE("%{public}s: scan networks is NULL.", __func__); 1409 return HDF_FAILURE; 1410 } 1411 1412 wifiPnoSettings->pnoNetworksLen = pnoSettings->pnoNetworksLen; 1413 wifiPnoSettings->pnoNetworks = 1414 (WifiPnoNetwork *)OsalMemCalloc(sizeof(WifiPnoNetwork) * (pnoSettings->pnoNetworksLen)); 1415 if (wifiPnoSettings->pnoNetworks == NULL) { 1416 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__); 1417 return HDF_FAILURE; 1418 } 1419 for (uint32_t i = 0; i < pnoSettings->pnoNetworksLen; i++) { 1420 wifiPnoSettings->pnoNetworks[i].isHidden = pnoSettings->pnoNetworks[i].isHidden; 1421 wifiPnoSettings->pnoNetworks[i].ssid.ssidLen = (uint32_t)(pnoSettings->pnoNetworks[i].ssid.ssidLen); 1422 if (memcpy_s(wifiPnoSettings->pnoNetworks[i].ssid.ssid, MAX_SSID_LEN, pnoSettings->pnoNetworks[i].ssid.ssid, 1423 pnoSettings->pnoNetworks[i].ssid.ssidLen) != EOK) { 1424 HDF_LOGE("%{public}s fail : memcpy_s ssids fail!", __func__); 1425 return HDF_FAILURE; 1426 } 1427 if (pnoSettings->pnoNetworks[i].freqsLen != 0) { 1428 wifiPnoSettings->pnoNetworks[i].freqs = 1429 (int32_t *)OsalMemCalloc(sizeof(int32_t) * (pnoSettings->pnoNetworks[i].freqsLen)); 1430 if (wifiPnoSettings->pnoNetworks[i].freqs == NULL) { 1431 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__); 1432 return HDF_FAILURE; 1433 } 1434 wifiPnoSettings->pnoNetworks[i].freqsLen = pnoSettings->pnoNetworks[i].freqsLen; 1435 if (memcpy_s(wifiPnoSettings->pnoNetworks[i].freqs, 1436 sizeof(int32_t) * (pnoSettings->pnoNetworks[i].freqsLen), pnoSettings->pnoNetworks[i].freqs, 1437 sizeof(int32_t) * (pnoSettings->pnoNetworks[i].freqsLen)) != EOK) { 1438 HDF_LOGE("%{public}s fail : memcpy_s freqs fail!", __func__); 1439 return HDF_FAILURE; 1440 } 1441 } 1442 } 1443 return HDF_SUCCESS; 1444} 1445 1446static void WifiPnoSettingsFree(WifiPnoSettings *wifiPnoSettings) 1447{ 1448 if (wifiPnoSettings == NULL) { 1449 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1450 return; 1451 } 1452 for (uint32_t i = 0; i < wifiPnoSettings->pnoNetworksLen; i++) { 1453 if (wifiPnoSettings->pnoNetworks[i].freqs != NULL) { 1454 OsalMemFree(wifiPnoSettings->pnoNetworks[i].freqs); 1455 wifiPnoSettings->pnoNetworks[i].freqs = NULL; 1456 } 1457 } 1458 OsalMemFree(wifiPnoSettings->pnoNetworks); 1459 wifiPnoSettings->pnoNetworks = NULL; 1460 OsalMemFree(wifiPnoSettings); 1461} 1462 1463int32_t WlanInterfaceStartPnoScan(struct IWlanInterface *self, const char *ifName, 1464 const struct PnoSettings *pnoSettings) 1465{ 1466 HDF_LOGI("hal enter %{public}s ifName:%{public}s", __FUNCTION__, ifName); 1467 int32_t ret; 1468 (void)self; 1469 1470 if (ifName == NULL || pnoSettings == NULL) { 1471 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1472 return HDF_ERR_INVALID_PARAM; 1473 } 1474 if (g_staFeature == NULL || g_staFeature->startPnoScan == NULL) { 1475 HDF_LOGE("%{public}s g_staFeature or g_staFeature->startPnoScan is NULL!", __func__); 1476 return HDF_FAILURE; 1477 } 1478 WifiPnoSettings *wifiPnoSettings = (WifiPnoSettings *)OsalMemCalloc(sizeof(WifiPnoSettings)); 1479 if (wifiPnoSettings == NULL) { 1480 HDF_LOGE("%{public}s: OsalMemCalloc failed", __func__); 1481 return HDF_FAILURE; 1482 } 1483 if (FillPnoSettings(wifiPnoSettings, pnoSettings) != HDF_SUCCESS) { 1484 HDF_LOGE("%{public}s fail : memcpy_s ssids fail!", __func__); 1485 WifiPnoSettingsFree(wifiPnoSettings); 1486 return HDF_FAILURE; 1487 } 1488 1489 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifName); 1490 if (ret != HDF_SUCCESS) { 1491 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret); 1492 WifiPnoSettingsFree(wifiPnoSettings); 1493 return HDF_FAILURE; 1494 } 1495 ret = g_staFeature->startPnoScan(ifName, wifiPnoSettings); 1496 if (ret != HDF_SUCCESS) { 1497 HDF_LOGE("%{public}s: startPnoScan failed!, error code: %{public}d", __func__, ret); 1498 } 1499 WifiPnoSettingsFree(wifiPnoSettings); 1500 HDF_LOGI("hal exit %{public}s", __FUNCTION__); 1501 return ret; 1502} 1503 1504int32_t WlanInterfaceStopPnoScan(struct IWlanInterface *self, const char *ifName) 1505{ 1506 HDF_LOGI("hal enter %{public}s ifName:%{public}s", __FUNCTION__, ifName); 1507 int32_t ret; 1508 (void)self; 1509 1510 if (ifName == NULL) { 1511 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1512 return HDF_ERR_INVALID_PARAM; 1513 } 1514 if (g_staFeature == NULL || g_staFeature->stopPnoScan == NULL) { 1515 HDF_LOGE("%{public}s g_staFeature or g_staFeature->stopPnoScan is NULL!", __func__); 1516 return HDF_FAILURE; 1517 } 1518 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifName); 1519 if (ret != HDF_SUCCESS) { 1520 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret); 1521 return HDF_FAILURE; 1522 } 1523 ret = g_staFeature->stopPnoScan(ifName); 1524 if (ret != HDF_SUCCESS) { 1525 HDF_LOGE("%{public}s: stopPnoScan failed!, error code: %{public}d", __func__, ret); 1526 } 1527 HDF_LOGI("hal exit %{public}s", __FUNCTION__); 1528 return ret; 1529} 1530 1531int32_t WlanInterfaceGetSignalPollInfo(struct IWlanInterface *self, const char *ifName, 1532 struct SignalPollResult *signalResult) 1533{ 1534 int32_t ret; 1535 (void)self; 1536 1537 if (ifName == NULL || signalResult == NULL) { 1538 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1539 return HDF_ERR_INVALID_PARAM; 1540 } 1541 if (g_staFeature == NULL || g_staFeature->getSignalPollInfo == NULL) { 1542 HDF_LOGE("%{public}s g_staFeature or g_staFeature->getSignalPollInfo is NULL!", __func__); 1543 return HDF_FAILURE; 1544 } 1545 ret = strcpy_s((g_staFeature->baseFeature).ifName, IFNAMSIZ, ifName); 1546 if (ret != HDF_SUCCESS) { 1547 HDF_LOGE("%{public}s: strcpy_s is failed!, error code: %{public}d", __func__, ret); 1548 return HDF_FAILURE; 1549 } 1550 ret = g_staFeature->getSignalPollInfo(ifName, (struct SignalResult *)signalResult); 1551 if (ret != HDF_SUCCESS) { 1552 HDF_LOGE("%{public}s: get signal information failed!, error code: %{public}d", __func__, ret); 1553 } 1554 return ret; 1555} 1556 1557int32_t WlanInterfaceGetApBandwidth(struct IWlanInterface *self, const char *ifName, 1558 uint8_t *bandwidth) 1559{ 1560 int32_t ret; 1561 (void)self; 1562 1563 if (ifName == NULL || bandwidth == NULL) { 1564 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1565 return HDF_ERR_INVALID_PARAM; 1566 } 1567 if (g_apFeature == NULL || g_apFeature->getApBandwidth == NULL) { 1568 HDF_LOGE("%{public}s g_apFeature or g_staFeature->getApBandwidth is NULL!", __func__); 1569 return HDF_FAILURE; 1570 } 1571 ret = g_apFeature->getApBandwidth(ifName, bandwidth); 1572 if (ret != HDF_SUCCESS) { 1573 HDF_LOGE("%{public}s: get signal information failed!, error code: %d", __func__, ret); 1574 } 1575 return ret; 1576} 1577 1578int32_t WlanInterfaceResetToFactoryMacAddress(struct IWlanInterface *self, const char *ifName) 1579{ 1580 int32_t ret; 1581 1582 (void)self; 1583 if (ifName == NULL) { 1584 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1585 return HDF_ERR_INVALID_PARAM; 1586 } 1587 1588 if (g_staFeature != NULL) { 1589 HDF_LOGD("%{public}s g_staFeature is not NULL!", __func__); 1590 ret = g_staFeature->baseFeature.resetToFactoryMacAddress(ifName); 1591 } else if (g_apFeature != NULL) { 1592 HDF_LOGD("%{public}s g_apFeature is not NULL!", __func__); 1593 ret = g_apFeature->baseFeature.resetToFactoryMacAddress(ifName); 1594 } else { 1595 HDF_LOGE("%{public}s: ap and sta feature is Invalid.", __func__); 1596 ret = HDF_FAILURE; 1597 } 1598 1599 if (ret != HDF_SUCCESS) { 1600 HDF_LOGE("%{public}s get name failed!, error code: %{public}d", __func__, ret); 1601 } 1602 return ret; 1603} 1604 1605int32_t WlanInterfaceSendActionFrame(struct IWlanInterface *self, const char *ifName, uint32_t freq, 1606 const uint8_t *frameData, uint32_t frameDataLen) 1607{ 1608 int32_t ret; 1609 (void)self; 1610 if (ifName == NULL || freq == 0 || frameData == NULL || frameDataLen == 0) { 1611 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1612 return HDF_ERR_INVALID_PARAM; 1613 } 1614 if (g_wifi == NULL || g_wifi->sendActionFrame == NULL) { 1615 HDF_LOGE("%{public}s g_wifi or g_wifi->sendActionFrame is NULL!", __func__); 1616 return HDF_FAILURE; 1617 } 1618 ret = g_wifi->sendActionFrame(ifName, freq, frameData, frameDataLen); 1619 if (ret != HDF_SUCCESS) { 1620 HDF_LOGE("%{public}s failed!, error code: %{public}d", __func__, ret); 1621 } 1622 return ret; 1623} 1624 1625int32_t WlanInterfaceRegisterActionFrameReceiver(struct IWlanInterface *self, const char *ifName, 1626 const uint8_t *match, uint32_t matchLen) 1627{ 1628 int32_t ret; 1629 (void)self; 1630 if (ifName == NULL || match == NULL || matchLen == 0) { 1631 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1632 return HDF_ERR_INVALID_PARAM; 1633 } 1634 if (g_wifi == NULL || g_wifi->registerActionFrameReceiver == NULL) { 1635 HDF_LOGE("%{public}s g_wifi or g_wifi->registerActionFrameReceiver is NULL!", __func__); 1636 return HDF_FAILURE; 1637 } 1638 ret = g_wifi->registerActionFrameReceiver(ifName, match, matchLen); 1639 if (ret != HDF_SUCCESS) { 1640 HDF_LOGE("%{public}s failed!, error code: %{public}d", __func__, ret); 1641 } 1642 return ret; 1643} 1644 1645int32_t WlanInterfaceSetPowerSaveMode(struct IWlanInterface *self, const char * ifName, int32_t frequency, int32_t mode) 1646{ 1647 int32_t ret; 1648 (void)self; 1649 1650 HDF_LOGI("Enter %{public}s.", __FUNCTION__); 1651 if (ifName == NULL) { 1652 HDF_LOGE("%{public}s input parameter invalid!", __func__); 1653 return HDF_ERR_INVALID_PARAM; 1654 } 1655 1656 if (g_wifi == NULL || g_wifi->setPowerSaveMode == NULL) { 1657 HDF_LOGE("%{public}s g_wifi or g_wifi->setPowerSaveMode is NULL!", __func__); 1658 return HDF_FAILURE; 1659 } 1660 1661 ret = g_wifi->setPowerSaveMode(ifName, frequency, mode); 1662 if (ret != HDF_SUCCESS) { 1663 HDF_LOGE("%{public}s failed!, error code: %{public}d", __func__, ret); 1664 } 1665 return ret; 1666} 1667 1668int32_t WlanInterfaceSetDpiMarkRule(struct IWlanInterface *self, int32_t uid, int32_t protocol, int32_t enable) 1669{ 1670 int32_t ret; 1671 (void)self; 1672 1673 HDF_LOGI("Enter %{public}s.", __FUNCTION__); 1674 if (g_wifi == NULL || g_wifi->setDpiMarkRule == NULL) { 1675 HDF_LOGE("%{public}s g_wifi or g_wifi->setDpiMarkRule is NULL!", __func__); 1676 return HDF_FAILURE; 1677 } 1678 1679 ret = g_wifi->setDpiMarkRule(uid, protocol, enable); 1680 if (ret != HDF_SUCCESS) { 1681 HDF_LOGE("%{public}s failed!, error code: %{public}d", __func__, ret); 1682 } 1683 return ret; 1684} 1685 1686int32_t WlanInterfaceWifiConstruct(void) 1687{ 1688 int32_t ret; 1689 1690 ret = WifiConstruct(&g_wifi); 1691 if (ret != HDF_SUCCESS) { 1692 HDF_LOGE("%{public}s construct WiFi failed! error code: %{public}d", __func__, ret); 1693 } 1694 return ret; 1695} 1696 1697int32_t WlanInterfaceWifiDestruct(void) 1698{ 1699 int32_t ret; 1700 1701 ret = WifiDestruct(&g_wifi); 1702 if (ret != HDF_SUCCESS) { 1703 HDF_LOGE("%{public}s destruct WiFi failed! error code: %{public}d", __func__, ret); 1704 } 1705 return ret; 1706} 1707