1/* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "wifi_hal_sta_feature.h" 17#include "hdf_base.h" 18#include "hdf_log.h" 19#include "securec.h" 20#include "wifi_hal_cmd.h" 21#include "wifi_hal_util.h" 22 23#ifdef __cplusplus 24#if __cplusplus 25extern "C" { 26#endif 27#endif 28 29static int32_t SetScanningMacAddressInner(const struct IWiFiSta *staFeature, unsigned char *scanMac, uint8_t len) 30{ 31 if (staFeature == NULL || scanMac == NULL || len != WIFI_MAC_ADDR_LENGTH) { 32 HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__); 33 return HDF_ERR_INVALID_PARAM; 34 } 35 return HalCmdSetScanningMacAddress(staFeature->baseFeature.ifName, scanMac, len); 36} 37 38static int32_t SetScanningMacAddress(const struct IWiFiSta *staFeature, unsigned char *scanMac, uint8_t len) 39{ 40 HalMutexLock(); 41 int32_t ret = SetScanningMacAddressInner(staFeature, scanMac, len); 42 HalMutexUnlock(); 43 return ret; 44} 45 46static int32_t StartScanInner(const char *ifName, WifiScan *scan) 47{ 48 if (ifName == NULL || scan == NULL) { 49 HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__); 50 return HDF_ERR_INVALID_PARAM; 51 } 52 return HalCmdStartScanInner(ifName, scan); 53} 54 55static int32_t StartScan(const char *ifName, WifiScan *scan) 56{ 57 HalMutexLock(); 58 int32_t ret = StartScanInner(ifName, scan); 59 HalMutexUnlock(); 60 return ret; 61} 62 63static int32_t StartPnoScanInner(const char *ifName, const WifiPnoSettings *pnoSettings) 64{ 65 if (ifName == NULL || pnoSettings == NULL) { 66 HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__); 67 return HDF_ERR_INVALID_PARAM; 68 } 69 return HalCmdStartPnoScan(ifName, pnoSettings); 70} 71 72static int32_t StartPnoScan(const char *ifName, const WifiPnoSettings *pnoSettings) 73{ 74 HalMutexLock(); 75 int32_t ret = StartPnoScanInner(ifName, pnoSettings); 76 HalMutexUnlock(); 77 return ret; 78} 79 80static int32_t StopPnoScanInner(const char *ifName) 81{ 82 if (ifName == NULL) { 83 HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__); 84 return HDF_ERR_INVALID_PARAM; 85 } 86 return HalCmdStopPnoScan(ifName); 87} 88 89static int32_t StopPnoScan(const char *ifName) 90{ 91 HalMutexLock(); 92 int32_t ret = StopPnoScanInner(ifName); 93 HalMutexUnlock(); 94 return ret; 95} 96 97static int32_t GetSignalPollInfoInner(const char *ifName, struct SignalResult *signalResult) 98{ 99 if (ifName == NULL || signalResult == NULL) { 100 HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__); 101 return HDF_ERR_INVALID_PARAM; 102 } 103 return HalCmdGetSignalPollInfo(ifName, signalResult); 104} 105 106static int32_t GetSignalPollInfo(const char *ifName, struct SignalResult *signalResult) 107{ 108 HalMutexLock(); 109 int32_t ret = GetSignalPollInfoInner(ifName, signalResult); 110 HalMutexUnlock(); 111 return ret; 112} 113 114int32_t InitStaFeature(struct IWiFiSta **fe) 115{ 116 if (fe == NULL || *fe == NULL) { 117 HDF_LOGE("%s: input parameter invalid, line: %d", __FUNCTION__, __LINE__); 118 return HDF_ERR_INVALID_PARAM; 119 } 120 if (InitBaseFeature((struct IWiFiBaseFeature **)fe) != HDF_SUCCESS) { 121 HDF_LOGE("%s: init base feature, line: %d", __FUNCTION__, __LINE__); 122 return HDF_FAILURE; 123 } 124 (*fe)->setScanningMacAddress = SetScanningMacAddress; 125 (*fe)->startScan = StartScan; 126 (*fe)->startPnoScan = StartPnoScan; 127 (*fe)->stopPnoScan = StopPnoScan; 128 (*fe)->getSignalPollInfo = GetSignalPollInfo; 129 return HDF_SUCCESS; 130} 131 132#ifdef __cplusplus 133#if __cplusplus 134} 135#endif 136#endif