• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_cmd.h"
17 #include "hdf_log.h"
18 #include "securec.h"
19 #include "wifi_hal_sta_feature.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif
26 
27 static struct DListHead g_networkHead = {0};
28 
GetNetworkHead(void)29 struct DListHead *GetNetworkHead(void)
30 {
31     return &g_networkHead;
32 }
33 
HalCmdGetAvailableNetwork(void)34 int32_t HalCmdGetAvailableNetwork(void)
35 {
36     int32_t ret;
37     struct NetworkInfoResult networkInfo;
38     uint32_t i;
39 
40     ret = GetUsableNetworkInfo(&networkInfo);
41     if (ret != HDF_SUCCESS) {
42         HDF_LOGE("%s: get network info failed", __FUNCTION__);
43         return ret;
44     }
45     if (!DListIsEmpty(&g_networkHead)) {
46         ClearIWiFiList();
47     }
48     for (i = 0; i < networkInfo.nums; i++) {
49         struct IWiFiList *networkList = (struct IWiFiList *)malloc(sizeof(struct IWiFiList));
50         if (networkList == NULL) {
51             HDF_LOGE("%s: malloc failed, line: %d", __FUNCTION__, __LINE__);
52             ClearIWiFiList();
53             return HDF_FAILURE;
54         }
55         (void)memset_s(networkList, sizeof(struct IWiFiList), 0, sizeof(struct IWiFiList));
56         DListInsertTail(&networkList->entry, &g_networkHead);
57         if (memcpy_s(networkList->ifName, IFNAME_MAX_LEN, networkInfo.infos[i].name,
58             strlen(networkInfo.infos[i].name)) != EOK) {
59             HDF_LOGE("%s: memcpy_s failed, line: %d", __FUNCTION__, __LINE__);
60             ClearIWiFiList();
61             return HDF_FAILURE;
62         }
63         if (memcpy_s(networkList->supportMode, PROTOCOL_80211_IFTYPE_NUM,
64             networkInfo.infos[i].supportMode, PROTOCOL_80211_IFTYPE_NUM) != EOK) {
65             HDF_LOGE("%s: memcpy_s failed, line: %d", __FUNCTION__, __LINE__);
66             ClearIWiFiList();
67             return HDF_FAILURE;
68         }
69         networkList->ifeature = NULL;
70     }
71     return ret;
72 }
73 
GetSupportTypeByList(uint8_t * supType)74 static void GetSupportTypeByList(uint8_t *supType)
75 {
76     int32_t i;
77     struct IWiFiList *networkList = NULL;
78 
79     DLIST_FOR_EACH_ENTRY(networkList, &g_networkHead, struct IWiFiList, entry) {
80         for (i = 0; i < PROTOCOL_80211_IFTYPE_NUM; i++) {
81             if (networkList->supportMode[i] == 1) {
82                 supType[i] = 1;
83             }
84         }
85     }
86 }
87 
HalCmdGetSupportType(uint8_t * supType)88 int32_t HalCmdGetSupportType(uint8_t *supType)
89 {
90     int32_t ret;
91     uint8_t isComboValid;
92 
93     GetSupportTypeByList(supType);
94     ret = IsSupportCombo(&isComboValid);
95     if (ret != HDF_SUCCESS) {
96         HDF_LOGE("%s:IsSupportCombo failed, line: %d", __FUNCTION__, __LINE__);
97         return ret;
98     }
99     supType[PROTOCOL_80211_IFTYPE_NUM] = isComboValid;
100 
101     return ret;
102 }
103 
HalCmdGetSupportCombo(uint64_t * supCombo,uint32_t size)104 int32_t HalCmdGetSupportCombo(uint64_t *supCombo, uint32_t size)
105 {
106     int32_t ret;
107 
108     ret = GetComboInfo(supCombo, size);
109     if (ret != HDF_SUCCESS) {
110         HDF_LOGE("%s: GetComboInfo failed, line: %d", __FUNCTION__, __LINE__);
111     }
112     return ret;
113 }
114 
HalCmdGetDevMacAddr(const char * ifName,int32_t type,unsigned char * mac,uint8_t len)115 int32_t HalCmdGetDevMacAddr(const char *ifName, int32_t type, unsigned char *mac, uint8_t len)
116 {
117     int32_t ret;
118 
119     ret = GetDevMacAddr(ifName, type, (uint8_t *)mac, len);
120     if (ret != HDF_SUCCESS) {
121         HDF_LOGE("%s:GetDevMacAddr failed, line: %d", __FUNCTION__, __LINE__);
122     }
123     return ret;
124 }
125 
HalCmdSetMacAddr(const char * ifName,unsigned char * mac,uint8_t len)126 int32_t HalCmdSetMacAddr(const char *ifName, unsigned char *mac, uint8_t len)
127 {
128     int32_t ret;
129 
130     ret = SetMacAddr(ifName, mac, len);
131     if (ret != HDF_SUCCESS) {
132         HDF_LOGE("%s: SetMacAddr failed", __FUNCTION__);
133     }
134     return ret;
135 }
136 
HalCmdGetValidFreqWithBand(const char * ifName,int32_t band,int32_t * freqs,uint32_t * num)137 int32_t HalCmdGetValidFreqWithBand(const char *ifName, int32_t band, int32_t *freqs, uint32_t *num)
138 {
139     int32_t ret;
140     struct FreqInfoResult result;
141     ret = GetValidFreqByBand(ifName, band, &result);
142     if (ret != HDF_SUCCESS) {
143         HDF_LOGE("%s: GetValidFreqByBand failed", __FUNCTION__);
144         return ret;
145     }
146     if (memcpy_s(freqs, MAX_CHANNEL_NUM * sizeof(int32_t), result.freqs,
147         result.nums * sizeof(int32_t)) != EOK) {
148         HDF_LOGE("%s: memcpy failed, line: %d", __FUNCTION__, __LINE__);
149         return HDF_FAILURE;
150     }
151     *num = result.nums;
152     return ret;
153 }
154 
HalCmdSetTxPower(const char * ifName,int32_t power)155 int32_t HalCmdSetTxPower(const char *ifName, int32_t power)
156 {
157     int32_t ret;
158     ret = SetTxPower(ifName, power);
159     if (ret != HDF_SUCCESS) {
160         HDF_LOGE("%s: SetTxPower failed", __FUNCTION__);
161     }
162     return ret;
163 }
164 
HalCmdGetAsscociatedStas(const char * ifName,struct StaInfo * staInfo,uint32_t count,uint32_t * num)165 int32_t HalCmdGetAsscociatedStas(const char *ifName, struct StaInfo *staInfo, uint32_t count, uint32_t *num)
166 {
167     int32_t ret;
168     struct AssocStaInfoResult result;
169 
170     ret = GetAssociatedStas(ifName, &result);
171     if (ret != HDF_SUCCESS) {
172         HDF_LOGE("%s: GetAssociatedStas failed", __FUNCTION__);
173         return ret;
174     }
175     if (memcpy_s(staInfo, count * sizeof(*staInfo), result.infos,
176         result.num * sizeof(struct AssocStaInfo)) != EOK) {
177         HDF_LOGE("%s: memcpy staInfo failed", __FUNCTION__);
178         return HDF_FAILURE;
179     }
180     *num = result.num;
181     return ret;
182 }
183 
HalCmdSetCountryCode(const char * ifName,const char * code,uint32_t len)184 int32_t HalCmdSetCountryCode(const char *ifName, const char *code, uint32_t len)
185 {
186     int32_t ret;
187     ret = WifiSetCountryCode(ifName, code, len);
188     if (ret != HDF_SUCCESS) {
189         HDF_LOGE("%s: WifiSetCountryCode failed", __FUNCTION__);
190     }
191     return ret;
192 }
193 
HalCmdSetScanningMacAddress(const char * ifName,unsigned char * scanMac,uint8_t len)194 int32_t HalCmdSetScanningMacAddress(const char *ifName, unsigned char *scanMac, uint8_t len)
195 {
196     int32_t ret;
197     ret = SetScanMacAddr(ifName, scanMac, len);
198     if (ret != HDF_SUCCESS) {
199         HDF_LOGE("%s: SetScanMacAddr failed", __FUNCTION__);
200     }
201     return ret;
202 }
203 
HalCmdStartScanInner(const char * ifName,WifiScan * scan)204 int32_t HalCmdStartScanInner(const char *ifName, WifiScan *scan)
205 {
206     int32_t ret;
207     ret = WifiCmdScan(ifName, (WifiScan *)scan);
208     if (ret != HDF_SUCCESS) {
209         HDF_LOGE("%s: SetScanMacAddr failed", __FUNCTION__);
210     }
211     return ret;
212 }
213 
HalCmdGetChipId(const char * ifName,uint8_t * chipId)214 int32_t HalCmdGetChipId(const char *ifName, uint8_t *chipId)
215 {
216     int32_t ret;
217     ret = AcquireChipId(ifName, chipId);
218     if (ret != HDF_SUCCESS) {
219         HDF_LOGE("%s: AcquireChipId failed", __FUNCTION__);
220     }
221     return ret;
222 }
223 
HalCmdGetIfNamesByChipId(const uint8_t chipId,char ** ifNames,uint32_t * num)224 int32_t HalCmdGetIfNamesByChipId(const uint8_t chipId, char **ifNames, uint32_t *num)
225 {
226     int32_t ret;
227     ret = GetIfNamesByChipId(chipId, ifNames, num);
228     if (ret != HDF_SUCCESS) {
229         HDF_LOGE("%s: GetIfNamesByChipId failed", __FUNCTION__);
230     }
231     return ret;
232 }
233 
HalCmdSetResetDriver(const uint8_t chipId,const char * ifName)234 int32_t HalCmdSetResetDriver(const uint8_t chipId, const char *ifName)
235 {
236     int32_t ret;
237     ret = SetResetDriver(chipId, ifName);
238     if (ret != HDF_SUCCESS) {
239         HDF_LOGE("%s: SetResetDriver failed", __FUNCTION__);
240     }
241     return ret;
242 }
243 
ClearIWiFiList(void)244 void ClearIWiFiList(void)
245 {
246     struct IWiFiList *networkList = NULL;
247     struct IWiFiList *tmp = NULL;
248 
249     DLIST_FOR_EACH_ENTRY_SAFE(networkList, tmp, &g_networkHead, struct IWiFiList, entry) {
250         DListRemove(&networkList->entry);
251         free(networkList);
252         networkList = NULL;
253     }
254     InitIWiFiList();
255 }
256 
InitIWiFiList(void)257 void InitIWiFiList(void)
258 {
259     DListHeadInit(&g_networkHead);
260 }
261 
262 #ifdef __cplusplus
263 #if __cplusplus
264 }
265 #endif
266 #endif