• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #include "oal_ext_if.h"
20 #include "oam_ext_if.h"
21 #include "hi_list.h"
22 #include "hmac_ext_if.h"
23 #include "wal_11d.h"
24 #include "wal_main.h"
25 #include "wal_ioctl.h"
26 #include "wal_regdb.h"
27 #include "wifi_mac80211_ops.h"
28 #include "wal_cfg80211.h"
29 #include "wal_wpa_ioctl.h"
30 #include "net_adpater.h"
31 #include "hdf_wlan_utils.h"
32 #include "wifi_module.h"
33 #include "osal_mem.h"
34 
35 #define HDF_LOG_TAG Hi3881Driver
36 
37 static struct MacStorage g_macStorage = { 0 };
38 
39 #define WIFI_SCAN_EXTRA_IE_LEN_MAX 512
40 
WalDisconnect(NetDevice * netDev,uint16_t reasonCode)41 int32_t WalDisconnect(NetDevice *netDev, uint16_t reasonCode)
42 {
43     return wal_cfg80211_disconnect(NULL, netDev, reasonCode);
44 }
45 
46 hi_u32 wal_send_scan_abort_msg(oal_net_device_stru *netdev);
47 
WifiScanSetSsid(const struct WlanScanRequest * params,oal_cfg80211_scan_request_stru * request)48 static int32_t WifiScanSetSsid(const struct WlanScanRequest *params, oal_cfg80211_scan_request_stru *request)
49 {
50     int32_t count = 0;
51     int32_t loop;
52 
53     if (params->ssidCount > WPAS_MAX_SCAN_SSIDS) {
54         oam_error_log(0, OAM_SF_ANY, "%s:unexpected numSsids!numSsids=%u", __func__, params->ssidCount);
55         return HDF_FAILURE;
56     }
57 
58     if (params->ssidCount == 0) {
59         oam_debug_log(0, OAM_SF_ANY, "%s:ssid number is 0!", __func__);
60         return HDF_SUCCESS;
61     }
62 
63     request->ssids = (oal_cfg80211_ssid_stru *)OsalMemCalloc(params->ssidCount * sizeof(oal_cfg80211_ssid_stru));
64     if (request->ssids == NULL) {
65         oam_error_log(0, OAM_SF_ANY, "%s:oom", __func__);
66         return HDF_FAILURE;
67     }
68 
69     for (loop = 0; loop < params->ssidCount; loop++) {
70         if (count >= DRIVER_MAX_SCAN_SSIDS) {
71             break;
72         }
73 
74         if (params->ssids[loop].ssidLen > IEEE80211_MAX_SSID_LEN) {
75             continue;
76         }
77 
78         request->ssids[count].ssid_len = params->ssids[loop].ssidLen;
79         if (memcpy_s(request->ssids[count].ssid, OAL_IEEE80211_MAX_SSID_LEN, params->ssids[loop].ssid,
80             params->ssids[loop].ssidLen) != EOK) {
81             continue;
82         }
83         count++;
84     }
85     request->n_ssids = count;
86 
87     return HDF_SUCCESS;
88 }
89 
WifiScanSetUserIe(const struct WlanScanRequest * params,oal_cfg80211_scan_request_stru * request)90 static int32_t WifiScanSetUserIe(const struct WlanScanRequest *params, oal_cfg80211_scan_request_stru *request)
91 {
92     if (params->extraIEsLen > WIFI_SCAN_EXTRA_IE_LEN_MAX) {
93         oam_error_log(0, OAM_SF_ANY, "%s:unexpected extra len!extraIesLen=%d", __func__, params->extraIEsLen);
94         return HDF_FAILURE;
95     }
96     if ((params->extraIEs != NULL) && (params->extraIEsLen != 0)) {
97         request->ie = (uint8_t *)OsalMemCalloc(params->extraIEsLen);
98         if (request->ie == NULL) {
99             oam_error_log(0, OAM_SF_ANY, "%s:oom", __func__);
100             goto fail;
101         }
102         (void)memcpy_s(request->ie, params->extraIEsLen, params->extraIEs, params->extraIEsLen);
103         request->ie_len = params->extraIEsLen;
104     }
105 
106     return HDF_SUCCESS;
107 
108 fail:
109     if (request->ie != NULL) {
110         OsalMemFree(request->ie);
111         request->ie = NULL;
112     }
113 
114     return HDF_FAILURE;
115 }
116 
GetChannelByFreq(const oal_wiphy_stru * wiphy,uint16_t center_freq)117 static oal_ieee80211_channel *GetChannelByFreq(const oal_wiphy_stru *wiphy, uint16_t center_freq)
118 {
119     enum Ieee80211Band band;
120     oal_ieee80211_supported_band *currentBand = NULL;
121     int32_t loop;
122     for (band = (enum Ieee80211Band)0; band < IEEE80211_NUM_BANDS; band++) {
123         currentBand = wiphy->bands[band];
124         if (currentBand == NULL) {
125             continue;
126         }
127         for (loop = 0; loop < currentBand->n_channels; loop++) {
128             if (currentBand->channels[loop].center_freq == center_freq) {
129                 return &currentBand->channels[loop];
130             }
131         }
132     }
133     return NULL;
134 }
135 
WifiScanSetChannel(const oal_wiphy_stru * wiphy,const struct WlanScanRequest * params,oal_cfg80211_scan_request_stru * request)136 static int32_t WifiScanSetChannel(const oal_wiphy_stru *wiphy, const struct WlanScanRequest *params,
137     oal_cfg80211_scan_request_stru *request)
138 {
139     int32_t loop;
140     int32_t count = 0;
141     enum Ieee80211Band band = IEEE80211_BAND_2GHZ;
142     oal_ieee80211_channel *chan = NULL;
143 
144     if ((params->freqs == NULL) || (params->freqsCount == 0)) {
145         if (wiphy->bands[band] == NULL) {
146             oam_error_log(0, OAM_SF_ANY, "%s:invalid band info", __func__);
147             return HDF_FAILURE;
148         }
149 
150         for (loop = 0; loop < (int32_t)wiphy->bands[band]->n_channels; loop++) {
151             chan = &wiphy->bands[band]->channels[loop];
152             if ((chan->flags & WIFI_CHAN_DISABLED) != 0) {
153                 continue;
154             }
155             request->channels[count++] = chan;
156         }
157     } else {
158         for (loop = 0; loop < params->freqsCount; loop++) {
159             chan = GetChannelByFreq(wiphy, (uint16_t)(params->freqs[loop]));
160             if (chan == NULL) {
161                 oam_error_log(0, OAM_SF_ANY, "%s:freq not found!freq=%d", __func__, params->freqs[loop]);
162                 continue;
163             }
164 
165             request->channels[count++] = chan;
166         }
167     }
168 
169     if (count == 0) {
170         oam_error_log(0, OAM_SF_ANY, "%s:invalid freq info", __func__);
171         return HDF_FAILURE;
172     }
173     request->n_channels = count;
174 
175     return HDF_SUCCESS;
176 }
177 
WifiScanSetRequest(struct NetDevice * netdev,const struct WlanScanRequest * params,oal_cfg80211_scan_request_stru * request)178 static int32_t WifiScanSetRequest(struct NetDevice *netdev, const struct WlanScanRequest *params,
179     oal_cfg80211_scan_request_stru *request)
180 {
181     if (netdev == NULL || netdev->ieee80211Ptr == NULL) {
182         return HDF_FAILURE;
183     }
184     request->wiphy = GET_NET_DEV_CFG80211_WIRELESS(netdev)->wiphy;
185     request->dev = netdev;
186     request->wdev = GET_NET_DEV_CFG80211_WIRELESS(netdev);
187     request->n_ssids = params->ssidCount;
188     request->prefix_ssid_scan_flag = 0;
189     if (WifiScanSetChannel(GET_NET_DEV_CFG80211_WIRELESS(netdev)->wiphy, params, request)) {
190         oam_error_log(0, OAM_SF_ANY, "%s:set channel failed!", __func__);
191         return HDF_FAILURE;
192     }
193     if (WifiScanSetSsid(params, request)) {
194         oam_error_log(0, OAM_SF_ANY, "%s:set ssid failed!", __func__);
195         return HDF_FAILURE;
196     }
197     if (WifiScanSetUserIe(params, request)) {
198         oam_error_log(0, OAM_SF_ANY, "%s:set user ie failed!", __func__);
199         return HDF_FAILURE;
200     }
201     return HDF_SUCCESS;
202 }
203 
WifiScanFree(oal_cfg80211_scan_request_stru ** request)204 static void WifiScanFree(oal_cfg80211_scan_request_stru **request)
205 {
206     if (*request != NULL) {
207         if ((*request)->ie != NULL) {
208             OsalMemFree((*request)->ie);
209             (*request)->ie = NULL;
210         }
211         if ((*request)->ssids != NULL) {
212             OsalMemFree((*request)->ssids);
213             (*request)->ssids = NULL;
214         }
215         OsalMemFree(*request);
216         *request = NULL;
217     }
218 }
219 
WalStartScan(NetDevice * netdev,struct WlanScanRequest * scanParam)220 static int32_t WalStartScan(NetDevice *netdev, struct WlanScanRequest *scanParam)
221 {
222     oal_wiphy_stru *wiphy = oal_wiphy_get();
223 
224     oal_cfg80211_scan_request_stru *request =
225         (oal_cfg80211_scan_request_stru *)OsalMemCalloc(sizeof(oal_cfg80211_scan_request_stru));
226     if (request == NULL) {
227         oam_error_log0(0, OAM_SF_ANY, "{WalStartScan::oom!}");
228         return HDF_FAILURE;
229     }
230     if (WifiScanSetRequest(netdev, scanParam, request) != HDF_SUCCESS) {
231         WifiScanFree(&request);
232         return HDF_FAILURE;
233     }
234     // scan request will be released after scan finish
235     hi_u32 ret = wal_cfg80211_scan(wiphy, request);
236     if (ret != HI_SUCCESS) {
237         WifiScanFree(&request);
238     }
239     return ret;
240 }
241 
WalGetChannel(oal_wiphy_stru * wiphy,int32_t freq)242 static oal_ieee80211_channel_stru *WalGetChannel(oal_wiphy_stru *wiphy, int32_t freq)
243 {
244     if (wiphy == NULL) {
245         HDF_LOGE("%s: capality is NULL!", __func__);
246         return NULL;
247     }
248 
249     enum Ieee80211Band band;
250     oal_ieee80211_supported_band *currentBand = NULL;
251     int32_t loop;
252 
253     for (band = (enum Ieee80211Band)0; band < IEEE80211_NUM_BANDS; band++) {
254         currentBand = wiphy->bands[band];
255         if (currentBand == NULL) {
256             continue;
257         }
258 
259         for (loop = 0; loop < currentBand->n_channels; loop++) {
260             if (currentBand->channels[loop].center_freq == freq) {
261                 return &currentBand->channels[loop];
262             }
263         }
264     }
265 
266     return NULL;
267 }
268 
WalConnect(NetDevice * netDev,WlanConnectParams * param)269 static int32_t WalConnect(NetDevice *netDev, WlanConnectParams *param)
270 {
271     if (netDev == NULL || param == NULL) {
272         HDF_LOGE("%s:NULL ptr!", __func__);
273         return HDF_FAILURE;
274     }
275     oal_wiphy_stru *wiphy = oal_wiphy_get();
276     oal_cfg80211_connect_params_stru cfg80211_params = { 0 };
277     if (param->centerFreq != WLAN_FREQ_NOT_SPECFIED) {
278         cfg80211_params.channel = WalGetChannel(wiphy, param->centerFreq);
279         if ((cfg80211_params.channel == NULL) || (cfg80211_params.channel->flags & WIFI_CHAN_DISABLED)) {
280             HDF_LOGE("%s:illegal channel.flags=%u", __func__,
281                 (cfg80211_params.channel == NULL) ? 0 : cfg80211_params.channel->flags);
282             return HDF_FAILURE;
283         }
284     }
285     cfg80211_params.bssid = param->bssid;
286     cfg80211_params.ssid = param->ssid;
287     cfg80211_params.ie = param->ie;
288     cfg80211_params.ssid_len = param->ssidLen;
289     cfg80211_params.ie_len = param->ieLen;
290     int ret = memcpy_s(&cfg80211_params.crypto, sizeof(cfg80211_params.crypto), &param->crypto, sizeof(param->crypto));
291     if (ret != EOK) {
292         HDF_LOGE("%s:Copy crypto info failed!ret=%d", __func__, ret);
293         return HDF_FAILURE;
294     }
295     cfg80211_params.key = param->key;
296     cfg80211_params.auth_type = (oal_nl80211_auth_type_enum_uint8)param->authType;
297     cfg80211_params.privacy = param->privacy;
298     cfg80211_params.key_len = param->keyLen;
299     cfg80211_params.key_idx = param->keyIdx;
300     cfg80211_params.mfp = (oal_nl80211_mfp_enum_uint8)param->mfp;
301 
302     return wal_cfg80211_connect(wiphy, netDev, &cfg80211_params);
303 }
304 
SetupWireLessDev(struct NetDevice * netDev,struct WlanAPConf * apSettings)305 static int32_t SetupWireLessDev(struct NetDevice *netDev, struct WlanAPConf *apSettings)
306 {
307     if (netDev->ieee80211Ptr == NULL) {
308         netDev->ieee80211Ptr = (struct wireless_dev *)OsalMemCalloc(sizeof(struct wireless_dev));
309         if (netDev->ieee80211Ptr == NULL) {
310             return HDF_ERR_INVALID_PARAM;
311         }
312     }
313 
314     if (GET_NET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.chan == NULL) {
315         GET_NET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.chan =
316             (oal_ieee80211_channel *)OsalMemCalloc(sizeof(oal_ieee80211_channel));
317         if (GET_NET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.chan == NULL) {
318             OsalMemFree(netDev->ieee80211Ptr);
319             netDev->ieee80211Ptr = NULL;
320             return HI_ERR_CODE_PTR_NULL;
321         }
322     }
323 
324     GET_NET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.width = (oal_nl80211_channel_type)apSettings->width;
325     GET_NET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.center_freq1 = apSettings->centerFreq1;
326     GET_NET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.chan->hw_value = apSettings->channel;
327     GET_NET_DEV_CFG80211_WIRELESS(netDev)->preset_chandef.chan->band = IEEE80211_BAND_2GHZ;
328     return HI_SUCCESS;
329 }
330 
331 
WalSetSsid(NetDevice * netDev,const uint8_t * ssid,uint32_t ssidLen)332 int32_t WalSetSsid(NetDevice *netDev, const uint8_t *ssid, uint32_t ssidLen)
333 {
334     mac_cfg_ssid_param_stru ssid_param = { 0 };
335     hi_u32 ret;
336 
337     ssid_param.ssid_len = ssidLen;
338     if (memcpy_s(ssid_param.ac_ssid, WLAN_SSID_MAX_LEN, (hi_s8 *)ssid, ssidLen) != EOK) {
339         oam_error_log0(0, 0, "{wal_cfg80211_set_ssid::mem safe function err!}");
340         return HI_FAIL;
341     }
342 
343     ret = wal_cfg80211_start_req(netDev, &ssid_param, sizeof(mac_cfg_ssid_param_stru), WLAN_CFGID_SSID, HI_FALSE);
344     if (ret != HI_SUCCESS) {
345         oam_error_log1(0, OAM_SF_ANY, "{wal_cfg80211_set_ssid::return err code [%u]!}", ret);
346         return ret;
347     }
348 
349     return HI_SUCCESS;
350 }
351 
352 hi_u32 wal_cfg80211_set_channel_info(oal_net_device_stru *netdev);
WalSetChannel(NetDevice * netDev)353 int32_t WalSetChannel(NetDevice *netDev)
354 {
355     return wal_cfg80211_set_channel_info(netDev);
356 }
357 
358 hi_u32 wal_cfg80211_fill_beacon_param(mac_vap_stru *mac_vap, oal_beacon_data_stru *beacon_info,
359     mac_beacon_param_stru *beacon_param);
360 
WalChangeBeacon(NetDevice * netDev,struct WlanBeaconConf * param)361 int32_t WalChangeBeacon(NetDevice *netDev, struct WlanBeaconConf *param)
362 {
363     mac_beacon_param_stru beacon_param = { 0 };
364     beacon_param.l_interval = param->interval;
365     beacon_param.l_dtim_period = param->DTIMPeriod;
366     beacon_param.hidden_ssid = param->hiddenSSID;
367     mac_vap_stru *mac_vap = oal_net_dev_priv(netDev);
368 
369     oam_info_log(0, OAM_SF_ANY, "%s: beacon info, head=%p, headLen=%d, tail=%p, tailLen=%d", __func__, param->headIEs,
370         param->headIEsLength, param->tailIEs, param->tailIEsLength);
371 
372     oal_beacon_data_stru beacon_data = { 0 };
373     beacon_data.head = param->headIEs;
374     beacon_data.head_len = param->headIEsLength;
375     beacon_data.tail = param->tailIEs;
376     beacon_data.tail_len = param->tailIEsLength;
377 
378     hi_u32 ret = wal_cfg80211_fill_beacon_param(mac_vap, &beacon_data, &beacon_param);
379     if (ret != HI_SUCCESS) {
380         oam_warning_log1(0, OAM_SF_ANY, "{wal_cfg80211_fill_beacon_param failed!ret=%d}\r\n", ret);
381         return ret;
382     }
383 
384     beacon_param.operation_type = MAC_ADD_BEACON;
385     return wal_cfg80211_start_req((oal_net_device_stru *)netDev, &beacon_param, sizeof(mac_beacon_param_stru),
386         WLAN_CFGID_CFG80211_CONFIG_BEACON, HI_FALSE);
387 }
388 
WalSetMeshId(NetDevice * netDev,const char * meshId,uint32_t meshIdLen)389 int32_t WalSetMeshId(NetDevice *netDev, const char *meshId, uint32_t meshIdLen)
390 {
391 #ifdef _PRE_WLAN_FEATURE_MESH
392     return wal_cfg80211_set_meshid((oal_net_device_stru *)netDev, meshId, meshIdLen);
393 #else
394     (void)netDev;
395     (void)meshId;
396     (void)meshIdLen;
397     return 0;
398 #endif
399 }
400 
401 hi_u32 wal_start_vap(oal_net_device_stru *netdev);
402 
WalStartAp(NetDevice * netDev)403 int32_t WalStartAp(NetDevice *netDev)
404 {
405     return wal_start_vap(netDev);
406 }
407 
WalStopAp(NetDevice * netDev)408 int32_t WalStopAp(NetDevice *netDev)
409 {
410     wal_msg_write_stru write_msg;
411     if (netDev == HI_NULL) {
412         oam_error_log0(0, OAM_SF_ANY, "{wal_cfg80211_stop_ap::pst_netdev is null!}");
413         goto fail;
414     }
415     mac_vap_stru *mac_vap = oal_net_dev_priv(netDev);
416     if (mac_vap == HI_NULL) {
417         oam_error_log0(0, OAM_SF_ANY, "{wal_cfg80211_stop_ap::can't get mac vap from netdevice priv data!}");
418         goto fail;
419     }
420 
421     if ((mac_vap->vap_mode != WLAN_VAP_MODE_BSS_AP)
422 #ifdef _PRE_WLAN_FEATURE_MESH
423         && (mac_vap->vap_mode != WLAN_VAP_MODE_MESH)
424 #endif
425     ) {
426         oam_error_log0(mac_vap->vap_id, OAM_SF_ANY, "{wal_cfg80211_stop_ap::vap is not in ap mode!}");
427         goto fail;
428     }
429 
430     if ((oal_netdevice_flags(netDev) & OAL_IFF_RUNNING) == 0) {
431         oam_warning_log0(0, OAM_SF_ANY, "{wal_cfg80211_stop_ap::vap is already down!}\r\n");
432         return HI_SUCCESS;
433     }
434 
435     wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_DOWN_VAP, sizeof(mac_cfg_start_vap_param_stru));
436 
437 #ifdef _PRE_WLAN_FEATURE_P2P
438     oal_wireless_dev *wdev = netDev->ieee80211Ptr;
439     wlan_p2p_mode_enum_uint8 p2p_mode = wal_wireless_iftype_to_mac_p2p_mode(wdev->iftype);
440     if (WLAN_P2P_BUTT == p2p_mode) {
441         oam_error_log0(0, OAM_SF_ANY, "{wal_cfg80211_stop_ap::wal_wireless_iftype_to_mac_p2p_mode return BUFF}\r\n");
442         goto fail;
443     }
444     oam_warning_log1(0, OAM_SF_ANY, "{wal_cfg80211_stop_ap::en_p2p_mode=%u}\r\n", p2p_mode);
445 
446     ((mac_cfg_start_vap_param_stru *)write_msg.auc_value)->p2p_mode = p2p_mode;
447 #endif
448 
449     ((mac_cfg_start_vap_param_stru *)write_msg.auc_value)->net_dev = netDev;
450 
451     hi_u32 ret = wal_send_cfg_event(netDev, WAL_MSG_TYPE_WRITE,
452         WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(mac_cfg_start_vap_param_stru), (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
453     if (oal_unlikely(ret != HI_SUCCESS)) {
454         oam_warning_log1(mac_vap->vap_id, OAM_SF_ANY, "{wal_cfg80211_stop_ap::failed to stop ap, error[%u]}", ret);
455         goto fail;
456     }
457 
458     return HI_SUCCESS;
459 
460 fail:
461 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
462     return HI_FAIL;
463 #elif (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
464     return -HI_FAIL;
465 #endif
466 }
467 
WalDelStation(NetDevice * netDev,const uint8_t * macAddr)468 int32_t WalDelStation(NetDevice *netDev, const uint8_t *macAddr)
469 {
470     oal_station_del_parameters_stru params = { 0 };
471     params.mac = macAddr;
472     return wal_cfg80211_del_station(NULL, netDev, &params);
473 }
474 
WalAddKey(struct NetDevice * netdev,uint8_t keyIndex,bool pairwise,const uint8_t * macAddr,struct KeyParams * params)475 int32_t WalAddKey(struct NetDevice *netdev, uint8_t keyIndex, bool pairwise, const uint8_t *macAddr,
476     struct KeyParams *params)
477 {
478     oal_key_params_stru keyParm = { 0 };
479     keyParm.key = params->key;
480     keyParm.key_len = params->keyLen;
481     keyParm.seq_len = params->seqLen;
482     keyParm.seq = params->seq;
483     keyParm.cipher = params->cipher;
484     return wal_cfg80211_add_key(NULL, netdev, keyIndex, pairwise, macAddr, &keyParm);
485 }
486 
WalDelKey(struct NetDevice * netdev,uint8_t keyIndex,bool pairwise,const uint8_t * macAddr)487 int32_t WalDelKey(struct NetDevice *netdev, uint8_t keyIndex, bool pairwise, const uint8_t *macAddr)
488 {
489     return wal_cfg80211_remove_key(NULL, netdev, keyIndex, pairwise, macAddr);
490 }
491 
WalSetDefaultKey(struct NetDevice * netDev,uint8_t keyIndex,bool unicast,bool multicas)492 int32_t WalSetDefaultKey(struct NetDevice *netDev, uint8_t keyIndex, bool unicast, bool multicas)
493 {
494     return wal_cfg80211_set_default_key(NULL, netDev, keyIndex, unicast, multicas);
495 }
496 
WalSetMacAddr(NetDevice * netDev,uint8_t * mac,uint8_t len)497 int32_t WalSetMacAddr(NetDevice *netDev, uint8_t *mac, uint8_t len)
498 {
499     (void)netDev;
500     uint32_t ret;
501 
502     ret = wal_macaddr_check(mac);
503     if (ret != HI_SUCCESS) {
504         oam_error_log0(0, OAM_SF_ANY, "mac addr is unavailable!");
505         return ret;
506     }
507     ret = memcpy_s(g_macStorage.mac, ETHER_ADDR_LEN, mac, len);
508     if (ret != HI_SUCCESS) {
509         oam_error_log0(0, OAM_SF_ANY, "memcpy_s failed!");
510         return ret;
511     }
512     g_macStorage.isStorage = true;
513     return HI_SUCCESS;
514 }
515 
PreSetMac(NetDevice * netDev,hi_u8 * mac,hi_u8 len)516 static int32_t PreSetMac(NetDevice *netDev, hi_u8 *mac, hi_u8 len)
517 {
518     uint32_t ret;
519     Mac80211SetMacParam param;
520     wal_msg_write_stru write_msg;
521     mac_cfg_staion_id_param_stru *mac_param = HI_NULL;
522 
523     ret = NetIfSetMacAddr(netDev, mac, len);
524     if (ret != HDF_SUCCESS) {
525         oam_error_log0(0, OAM_SF_ANY, "NetIfSetMacAddr failed!");
526         return ret;
527     }
528     if (memcpy_s(param.mac, ETHER_ADDR_LEN, mac, ETHER_ADDR_LEN) != EOK) {
529         oam_error_log0(0, OAM_SF_ANY, "WalSetMacAddr:: memcpy_s FAILED");
530         return HI_FAIL;
531     }
532     param.p2pMode = false;
533     param.resv = 0;
534     wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_STATION_ID, sizeof(mac_cfg_staion_id_param_stru));
535     mac_param = (mac_cfg_staion_id_param_stru *)write_msg.auc_value;
536     if (memcpy_s(mac_param, sizeof(mac_cfg_staion_id_param_stru), &param, sizeof(mac_cfg_staion_id_param_stru)) !=
537         EOK) {
538         oam_error_log0(0, OAM_SF_ANY, "WalSetMacParam:: memcpy_s FAILED");
539         return HI_FAIL;
540     }
541     ret = wal_send_cfg_event(netDev, WAL_MSG_TYPE_WRITE,
542         WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(mac_cfg_staion_id_param_stru), (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
543     if (ret != HI_SUCCESS) {
544         oam_error_log1(0, OAM_SF_ANY, "{wal_set_mac_to_mib::return err code [%u]!}\r\n", ret);
545         return ret;
546     }
547 
548     ret = memset_s(g_macStorage.mac, ETHER_ADDR_LEN, 0, len);
549     if (ret != HDF_SUCCESS) {
550         oam_error_log0(0, OAM_SF_ANY, "memset_s failed!");
551         return ret;
552     }
553     g_macStorage.isStorage = false;
554     return HI_SUCCESS;
555 }
556 
WalSetMode(NetDevice * netDev,enum WlanWorkMode iftype)557 int32_t WalSetMode(NetDevice *netDev, enum WlanWorkMode iftype)
558 {
559     int32_t ret;
560     uint32_t flags = 0;
561     oal_vif_params_stru params = {
562         .use_4addr = 0,
563         .macaddr = NULL
564     };
565     oam_info_log1(0, OAM_SF_ANY, "{WalSetMode enter iftype:%d!}", iftype);
566     if (iftype == WLAN_WORKMODE_STA || iftype == WLAN_WORKMODE_AP) {
567         wal_deinit_drv_wlan_netdev(netDev);
568         ret = RenewNetDevice(&netDev);
569         if (ret != HDF_SUCCESS) {
570             oam_error_log(0, OAM_SF_ANY, "%s:RenewNetDevice failed!ret=%d", __func__, ret);
571             return ret;
572         }
573         ret = wal_init_drv_wlan_netdev(iftype, WAL_PHY_MODE_11N, netDev);
574         if (ret != HISI_OK) {
575             oam_error_log0(0, OAM_SF_ANY, "wal_init_drv_wlan_netdev failed!");
576             return ret;
577         }
578     }
579     if (g_macStorage.isStorage) {
580         ret = PreSetMac(netDev, g_macStorage.mac, ETHER_ADDR_LEN);
581         if (ret != HI_SUCCESS) {
582             oam_error_log0(0, OAM_SF_ANY, "PreSetMac failed!}");
583             return HI_FAIL;
584         }
585         params.macaddr = (hi_u8 *)netDev->macAddr;
586     }
587 
588     if (iftype == WLAN_WORKMODE_STA)
589         return HI_SUCCESS;
590     return wal_cfg80211_change_virtual_intf(NULL, netDev, iftype, &flags, &params);
591 }
592 
593 
WalAbortScan(NetDevice * netDev)594 int32_t WalAbortScan(NetDevice *netDev)
595 {
596     return wal_force_scan_complete(netDev);
597 }
598 
599 
600 extern hi_u8 g_efuseMacExist;
WalGetDeviceMacAddr(NetDevice * netDev,int32_t type,uint8_t * mac,uint8_t len)601 int32_t WalGetDeviceMacAddr(NetDevice *netDev, int32_t type, uint8_t *mac, uint8_t len)
602 {
603     (void)netDev;
604     if (mac == NULL || len != ETHER_ADDR_LEN) {
605         oam_error_log0(0, OAM_SF_ANY, "{WalGetDeviceMacAddr::input param error!}");
606         return HI_FAIL;
607     }
608     if (!g_efuseMacExist) {
609         /* if there is no data in efuse */
610         oam_warning_log0(0, OAM_SF_ANY, "wal_get_efuse_mac_addr:: no data in efuse!");
611         return HDF_ERR_NOT_SUPPORT;
612     }
613     if (wal_get_dev_addr(mac, len, type) != HI_SUCCESS) {
614         oam_error_log0(0, OAM_SF_ANY, "{set_mac_addr_by_type::GetDeviceMacAddr failed!}");
615         return HI_FAIL;
616     }
617     return HI_SUCCESS;
618 }
619 
WalGetValidFreqsWithBand(NetDevice * netDev,int32_t band,int32_t * freqs,uint32_t * num)620 int32_t WalGetValidFreqsWithBand(NetDevice *netDev, int32_t band, int32_t *freqs, uint32_t *num)
621 {
622     (void)netDev;
623     uint32_t freqIndex = 0;
624     uint32_t channelNumber;
625     uint32_t freqTmp;
626     uint32_t minFreq;
627     uint32_t maxFreq;
628     const struct ieee80211_regdomain *regdom = NULL;
629 
630     regdom = wal_get_cfg_regdb();
631     if (regdom == NULL) {
632         oam_error_log0(0, OAM_SF_ANY, "wal_get_cfg_regdb failed!");
633         return HI_FAIL;
634     }
635     minFreq = regdom->reg_rules[0].freq_range.start_freq_khz / MHZ_TO_KHZ;
636     maxFreq = regdom->reg_rules[0].freq_range.end_freq_khz / MHZ_TO_KHZ;
637     switch (band) {
638         case WLAN_BAND_2G:
639             for (channelNumber = 1; channelNumber <= WIFI_24G_CHANNEL_NUMS; channelNumber++) {
640                 if (channelNumber < WAL_MAX_CHANNEL_2G) {
641                     freqTmp = WAL_MIN_FREQ_2G + (channelNumber - 1) * WAL_FREQ_2G_INTERVAL;
642                 } else if (channelNumber == WAL_MAX_CHANNEL_2G) {
643                     freqTmp = WAL_MAX_FREQ_2G;
644                 }
645                 if (freqTmp < minFreq || freqTmp > maxFreq) {
646                     continue;
647                 }
648                 freqs[freqIndex] = freqTmp;
649                 freqIndex++;
650             }
651             *num = freqIndex;
652             break;
653         default:
654             oam_error_log0(0, OAM_SF_ANY, "not support this band!");
655             return HDF_ERR_NOT_SUPPORT;
656     }
657     return HI_SUCCESS;
658 }
659 
WalSetTxPower(NetDevice * netDev,int32_t power)660 int32_t WalSetTxPower(NetDevice *netDev, int32_t power)
661 {
662     int32_t ret;
663     wal_msg_write_stru write_msg;
664     wal_write_msg_hdr_init(&write_msg, WLAN_CFGID_TX_POWER, sizeof(hi_s32));
665     *((hi_s32 *)(write_msg.auc_value)) = power;
666 
667     ret = wal_send_cfg_event(netDev, WAL_MSG_TYPE_WRITE, WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(hi_s32),
668         (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
669     if (ret != HI_SUCCESS) {
670         oam_error_log1(0, 0, "{WalSetTxPower::return err code %u!}", ret);
671         return ret;
672     }
673     return HI_SUCCESS;
674 }
675 
WalGetAssociatedStasCount(NetDevice * netDev,uint32_t * num)676 int32_t WalGetAssociatedStasCount(NetDevice *netDev, uint32_t *num)
677 {
678     mac_vap_stru *mac_vap = HI_NULL;
679     mac_vap = (mac_vap_stru *)oal_net_dev_priv(netDev);
680     if (mac_vap == NULL) {
681         oam_error_log0(0, OAM_SF_ANY, "WalGetUserNum:: mac_vap is null");
682         return HI_FAIL;
683     }
684     *num = mac_vap->user_nums;
685     return HI_SUCCESS;
686 }
687 
WalGetAssociatedStasInfo(NetDevice * netDev,WifiStaInfo * staInfo,uint32_t num)688 int32_t WalGetAssociatedStasInfo(NetDevice *netDev, WifiStaInfo *staInfo, uint32_t num)
689 {
690     uint32_t number = 0;
691     mac_vap_stru *mac_vap = HI_NULL;
692     hi_list *entry = HI_NULL;
693     hi_list *user_list_head = HI_NULL;
694     mac_user_stru *user_tmp = HI_NULL;
695 
696     mac_vap = (mac_vap_stru *)oal_net_dev_priv(netDev);
697     if (mac_vap == NULL) {
698         oam_error_log0(0, OAM_SF_ANY, "WalGetAssociatedStas:: mac_vap is null");
699         return HI_FAIL;
700     }
701     user_list_head = &(mac_vap->mac_user_list_head);
702     for (entry = user_list_head->next; entry != user_list_head && number < num; number++) {
703         user_tmp = hi_list_entry(entry, mac_user_stru, user_dlist);
704         if (user_tmp == HI_NULL) {
705             oam_error_log0(0, OAM_SF_ANY, "WalGetAssociatedStas:: mac_user is null");
706             return HI_FAIL;
707         }
708         if (memcpy_s(staInfo + number, ETHER_ADDR_LEN, user_tmp->user_mac_addr, ETHER_ADDR_LEN)) {
709             oam_error_log0(0, OAM_SF_ANY, "WalGetAssociatedStas:: memcpy_s failed!");
710             return HI_FAIL;
711         }
712         entry = entry->next;
713     }
714     return HI_SUCCESS;
715 }
716 
WalSetCountryCode(NetDevice * netDev,const char * code,uint32_t len)717 int32_t WalSetCountryCode(NetDevice *netDev, const char *code, uint32_t len)
718 {
719     int32_t ret;
720     if (code == NULL || strlen(code) != len) {
721         oam_error_log0(0, OAM_SF_ANY, "{WalSetCountryCode::input param error!}");
722         return HI_FAIL;
723     }
724     if (len > (MAC_CONTRY_CODE_LEN - 1)) {
725         oam_error_log0(0, OAM_SF_ANY, "{WalSetCountryCode::country code len error!}\r\n");
726         return HI_FAIL;
727     }
728     ret = wal_regdomain_update(netDev, code, MAC_CONTRY_CODE_LEN);
729     if (ret != HI_SUCCESS) {
730         oam_error_log1(0, OAM_SF_ANY, "{WalSetCountryCode::regdomain_update return err code %u!}\r\n", ret);
731         return ret;
732     }
733     return HI_SUCCESS;
734 }
735 
WalSetScanningMacAddress(NetDevice * netDev,unsigned char * mac,uint32_t len)736 int32_t WalSetScanningMacAddress(NetDevice *netDev, unsigned char *mac, uint32_t len)
737 {
738     (void)netDev;
739     (void)mac;
740     (void)len;
741     return HDF_ERR_NOT_SUPPORT;
742 }
743 
WalConfigAp(NetDevice * netDev,struct WlanAPConf * apConf)744 int32_t WalConfigAp(NetDevice *netDev, struct WlanAPConf *apConf)
745 {
746     int32_t ret = SetupWireLessDev(netDev, apConf);
747     if (ret != HI_SUCCESS) {
748         oam_error_log2(0, OAM_SF_ANY, "{%s::SetupWireLessDev failed!ret=%d!}\r\n", __func__, ret);
749         return ret;
750     }
751     ret = WalSetChannel(netDev);
752     if (ret != HI_SUCCESS) {
753         oam_error_log2(0, OAM_SF_ANY, "{%s::WalSetChannel failed!ret=%d!}\r\n", __func__, ret);
754         return ret;
755     }
756     ret = WalSetSsid(netDev, apConf->ssidConf.ssid, apConf->ssidConf.ssidLen);
757     if (ret != HI_SUCCESS) {
758         oam_error_log2(0, OAM_SF_ANY, "{%s::WalSetSsid failed!ret=%d!}\r\n", __func__, ret);
759         return ret;
760     }
761     return HI_SUCCESS;
762 }
763 
WalReleaseHwCapability(struct WlanHwCapability * self)764 void WalReleaseHwCapability(struct WlanHwCapability *self)
765 {
766     uint8_t i;
767     if (self == NULL) {
768         return;
769     }
770     for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
771         if (self->bands[i] != NULL) {
772             OsalMemFree(self->bands[i]);
773             self->bands[i] = NULL;
774         }
775     }
776     if (self->supportedRates != NULL) {
777         OsalMemFree(self->supportedRates);
778         self->supportedRates = NULL;
779     }
780     OsalMemFree(self);
781 }
782 
783 
WalGetHwCapability(struct NetDevice * netDev,struct WlanHwCapability ** capability)784 int32_t WalGetHwCapability(struct NetDevice *netDev, struct WlanHwCapability **capability)
785 {
786     uint8_t loop;
787     if (netDev == NULL || GET_NET_DEV_CFG80211_WIRELESS(netDev) == NULL ||
788         GET_NET_DEV_CFG80211_WIRELESS(netDev)->wiphy == NULL) {
789         return HI_FAIL;
790     }
791     if (capability == NULL) {
792         return HI_FAIL;
793     }
794     oal_ieee80211_supported_band *band = GET_NET_DEV_CFG80211_WIRELESS(netDev)->wiphy->bands[IEEE80211_BAND_2GHZ];
795     struct WlanHwCapability *hwCapability = (struct WlanHwCapability *)OsalMemCalloc(sizeof(struct WlanHwCapability));
796     if (hwCapability == NULL) {
797         oam_error_log1(0, OAM_SF_ANY, "{%s::oom!}\r\n", __func__);
798         return HI_FAIL;
799     }
800     hwCapability->Release = WalReleaseHwCapability;
801     if (hwCapability->bands[IEEE80211_BAND_2GHZ] == NULL) {
802         hwCapability->bands[IEEE80211_BAND_2GHZ] =
803             OsalMemCalloc(sizeof(struct WlanBand) + (sizeof(struct WlanChannel) * band->n_channels));
804         if (hwCapability->bands[IEEE80211_BAND_2GHZ] == NULL) {
805             oam_error_log1(0, OAM_SF_ANY, "{%s::oom!}\r\n", __func__);
806             WalReleaseHwCapability(hwCapability);
807             return HI_FAIL;
808         }
809     }
810     hwCapability->htCapability = band->ht_cap.cap;
811     hwCapability->bands[IEEE80211_BAND_2GHZ]->channelCount = band->n_channels;
812     for (loop = 0; loop < band->n_channels; loop++) {
813         hwCapability->bands[IEEE80211_BAND_2GHZ]->channels[loop].centerFreq = band->channels[loop].center_freq;
814         hwCapability->bands[IEEE80211_BAND_2GHZ]->channels[loop].flags = band->channels[loop].flags;
815         hwCapability->bands[IEEE80211_BAND_2GHZ]->channels[loop].channelId = band->channels[loop].hw_value;
816     }
817     hwCapability->supportedRateCount = band->n_bitrates;
818     hwCapability->supportedRates = OsalMemCalloc(sizeof(uint16_t) * band->n_bitrates);
819     if (hwCapability->supportedRates == NULL) {
820         oam_error_log1(0, OAM_SF_ANY, "{%s::oom!}\r\n", __func__);
821         WalReleaseHwCapability(hwCapability);
822         return HI_FAIL;
823     }
824     for (loop = 0; loop < band->n_bitrates; loop++) {
825         hwCapability->supportedRates[loop] = band->bitrates[loop].bitrate;
826     }
827     *capability = hwCapability;
828     return HI_SUCCESS;
829 }
830 
831 #ifdef _PRE_WLAN_FEATURE_P2P
WalRemainOnChannel(struct NetDevice * netDev,WifiOnChannel * onChannel)832 int32_t WalRemainOnChannel(struct NetDevice *netDev, WifiOnChannel *onChannel)
833 {
834     if (netDev == NULL || onChannel == NULL) {
835         HDF_LOGE("%s:NULL ptr!", __func__);
836         return HI_FAIL;
837     }
838     oal_wiphy_stru *wiphy = oal_wiphy_get();
839     oal_wireless_dev *wdev = GET_NET_DEV_CFG80211_WIRELESS(netDev);
840     hi_u64 pullCookie = 0;
841     hi_u8 channelIdx;
842     oal_ieee80211_channel* wifi2ghzChannels = wal_get_g_wifi_2ghz_channels();
843 
844     channelIdx = (hi_u8)oal_ieee80211_frequency_to_channel(onChannel->freq);
845 
846     return (hi_s32)wal_cfg80211_remain_on_channel(wiphy, wdev, &(wifi2ghzChannels[channelIdx - 1]),
847                                                  (hi_u32)onChannel->duration, &pullCookie);
848 }
849 
WalCancelRemainOnChannel(struct NetDevice * netDev)850 int32_t WalCancelRemainOnChannel(struct NetDevice *netDev)
851 {
852     if (netDev == NULL) {
853         HDF_LOGE("%s:NULL ptr!", __func__);
854         return HI_FAIL;
855     }
856 
857     oal_wireless_dev *wdev = GET_NET_DEV_CFG80211_WIRELESS(netDev);
858     return (hi_s32)wal_cfg80211_cancel_remain_on_channel(HI_NULL, wdev, (hi_u64)0);
859 }
860 
WalProbeReqReport(struct NetDevice * netDev,int32_t report)861 int32_t WalProbeReqReport(struct NetDevice *netDev, int32_t report)
862 {
863     (void)report;
864     if (netDev == NULL) {
865         HDF_LOGE("%s:NULL ptr!", __func__);
866         return HI_FAIL;
867     }
868     return HI_SUCCESS;
869 }
870 
WalAddIf(struct NetDevice * netDev,WifiIfAdd * ifAdd)871 int32_t WalAddIf(struct NetDevice *netDev, WifiIfAdd *ifAdd)
872 {
873     if (netDev == NULL || ifAdd == NULL) {
874         HDF_LOGE("%s:NULL ptr!", __func__);
875         return HI_FAIL;
876     }
877     if (SetIfName(ifAdd) != HI_SUCCESS) {
878         HDF_LOGE("%s:set ifName fail!", __func__);
879         return HI_FAIL;
880     }
881     int32_t ret = InitNetdev(netDev, (nl80211_iftype_uint8)ifAdd->type);
882     if (ret != HI_SUCCESS) {
883         oam_error_log0(0, 0, "hwal_ioctl_add_if: wal_init_drv_wlan_netdev failed!");
884         return -HI_FAIL;
885     }
886     return HI_SUCCESS;
887 }
888 
WalRemoveIf(struct NetDevice * netDev,WifiIfRemove * ifRemove)889 int32_t WalRemoveIf(struct NetDevice *netDev, WifiIfRemove *ifRemove)
890 {
891     if (netDev == NULL || ifRemove == NULL) {
892         HDF_LOGE("%s:NULL ptr!", __func__);
893         return HI_FAIL;
894     }
895 
896     struct NetDevice *removeNetdev = NULL;
897     removeNetdev = NetDeviceGetInstByName((const char*)(ifRemove->ifName));
898     if (removeNetdev == NULL) {
899         return -HI_FAIL;
900     }
901     int32_t ret = wal_deinit_drv_wlan_netdev(removeNetdev);
902     if (ret != HI_SUCCESS) {
903         oam_error_log0(0, 0, "hwal_ioctl_remove_if: wal_deinit_drv_wlan_netdev failed!");
904         return -HI_FAIL;
905     }
906     NetDeviceDeInit(removeNetdev);
907     return HI_SUCCESS;
908 }
909 
WalSetApWpsP2pIe(struct NetDevice * netDev,WifiAppIe * appIe)910 int32_t WalSetApWpsP2pIe(struct NetDevice *netDev, WifiAppIe *appIe)
911 {
912     if (netDev == NULL || appIe == NULL) {
913         HDF_LOGE("%s:NULL ptr!", __func__);
914         return HI_FAIL;
915     }
916 
917     if (appIe->ieLen > WLAN_WPS_IE_MAX_SIZE) {
918         oam_error_log0(0, 0, "app ie length is too large!");
919         return -HI_FAIL;
920     }
921 
922     return (hi_s32)wal_ioctl_set_wps_p2p_ie(netDev, appIe->ie, appIe->ieLen,
923                                             appIe->appIeType);
924 }
925 
WalGetDriverFlag(struct NetDevice * netDev,WifiGetDrvFlags ** params)926 int32_t WalGetDriverFlag(struct NetDevice *netDev, WifiGetDrvFlags **params)
927 {
928     if (netDev == NULL || params == NULL) {
929         HDF_LOGE("%s:NULL ptr!", __func__);
930         return HI_FAIL;
931     }
932     oal_wireless_dev *wdev = GET_NET_DEV_CFG80211_WIRELESS(netDev);
933     WifiGetDrvFlags *getDrvFlag = (WifiGetDrvFlags *)OsalMemCalloc(sizeof(WifiGetDrvFlags));
934     switch (wdev->iftype) {
935         case NL80211_IFTYPE_P2P_CLIENT:
936              /* fall-through */
937         case NL80211_IFTYPE_P2P_GO:
938             getDrvFlag->drvFlags = (hi_u64)(HISI_DRIVER_FLAGS_AP);
939             break;
940         case NL80211_IFTYPE_P2P_DEVICE:
941             getDrvFlag->drvFlags = (hi_u64)(HISI_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE |
942                                             HISI_DRIVER_FLAGS_P2P_CONCURRENT |
943                                             HISI_DRIVER_FLAGS_P2P_CAPABLE);
944             break;
945         default:
946             getDrvFlag->drvFlags = 0;
947     }
948     *params = getDrvFlag;
949     return HI_SUCCESS;
950 }
951 #endif
952 
InitMsgHdr(wal_msg_write_stru * writeMsg,WifiActionData * actionData)953 int32_t InitMsgHdr (wal_msg_write_stru *writeMsg, WifiActionData *actionData)
954 {
955     hi_unref_param(writeMsg);
956 
957     if(actionData->data[0] == MAC_ACTION_CATEGORY_SELF_PROTECTED) {
958 #ifdef _PRE_WLAN_FEATURE_MESH
959         wal_write_msg_hdr_init(writeMsg, WLAN_CFGID_SEND_MESH_ACTION, sizeof(WifiActionData));
960 #else
961         return HI_FAIL;
962 #endif
963     } else if (actionData->data[0] == MAC_ACTION_CATEGORY_PUBLIC) {
964 #ifdef _PRE_WLAN_FEATURE_P2P
965         wal_write_msg_hdr_init(writeMsg, WLAN_CFGID_SEND_P2P_ACTION, sizeof(WifiActionData));
966 #endif
967     } else {
968         return HI_FAIL;
969     }
970 
971     return HI_SUCCESS;
972 }
973 
WalSendAction(struct NetDevice * netDev,WifiActionData * actionData)974 int32_t WalSendAction(struct NetDevice *netDev, WifiActionData *actionData)
975 {
976     wal_msg_write_stru write_msg;
977 
978     if (netDev == NULL || actionData == NULL) {
979         HDF_LOGE("%s:NULL ptr!", __func__);
980         return HI_FAIL;
981     }
982     if (InitMsgHdr(&write_msg, actionData) == HI_FAIL) {
983         return HI_FAIL;
984     }
985 
986     mac_action_data_stru *actionParam = (mac_action_data_stru *)(write_msg.auc_value);
987 
988     if (memcpy_s(actionParam->dst, WLAN_MAC_ADDR_LEN, actionData->dst, WLAN_MAC_ADDR_LEN) ||
989         memcpy_s(actionParam->src, WLAN_MAC_ADDR_LEN, actionData->src, WLAN_MAC_ADDR_LEN) ||
990         memcpy_s(actionParam->bssid, WLAN_MAC_ADDR_LEN, actionData->bssid, WLAN_MAC_ADDR_LEN)) {
991         oam_error_log0(0, 0, "hwal_ioctol_send_action :oal_copy_from_user_new dst,src or bssid ailed ");
992         return HI_FAIL;
993     }
994 
995     actionParam->data = HI_NULL;
996     if (actionData->dataLen > 0 && actionData->dataLen <= MAX_ACTION_DATA_LEN) {
997         actionParam->data = (hi_u8 *)OsalMemCalloc(actionData->dataLen * sizeof(hi_u8));
998         if (oal_unlikely(actionParam->data == HI_NULL)) {
999             oam_error_log0(0, OAM_SF_CFG, "{hwal_ioctol_send_action ::puc_data alloc mem return null ptr!}");
1000             return HI_FAIL;
1001         }
1002         if (memcpy_s(actionParam->data, actionData->dataLen, actionData->data, actionData->dataLen)) {
1003             oam_error_log0(0, 0, "hwal_ioctl_send_action :oal_copy_from_user_new action_data failed. ");
1004             return HI_FAIL;
1005         }
1006     }
1007     actionParam->data_len = actionData->dataLen;
1008     actionParam->freq = actionData->freq;
1009     actionParam->wait = actionData->freq;
1010     actionParam->no_cck = actionData->noCck;
1011 
1012     oam_warning_log4(0, 0, "hwal_ioctl_send_action send action frame(mac addr = %02X:XX:%02X:XX:%02X:%02X)",
1013         actionParam->dst[0], actionParam->dst[2],   /* 0 2 */
1014         actionParam->dst[4], actionParam->dst[5]);  /* 4 5 */
1015 
1016     hi_s32 ret = wal_send_cfg_event(netDev, WAL_MSG_TYPE_WRITE,
1017         WAL_MSG_WRITE_MSG_HDR_LENGTH + sizeof(mac_action_data_stru), (hi_u8 *)&write_msg, HI_FALSE, HI_NULL);
1018     if (ret != HI_SUCCESS) {
1019         oam_warning_log1(0,0, "{hwal_ioctl_send_action ::send action frame to driver failed[%d].}", ret);
1020         OsalMemFree(actionParam->data);
1021         return HI_FAIL;
1022     }
1023 
1024     return HI_SUCCESS;
1025 }
1026 
WalGetIftype(struct NetDevice * netDev,uint8_t * iftype)1027 int32_t WalGetIftype(struct NetDevice *netDev, uint8_t *iftype)
1028 {
1029     iftype = (uint8_t *)(&(GET_NET_DEV_CFG80211_WIRELESS(netDev)->iftype));
1030     if (iftype == NULL) {
1031         HDF_LOGE("%s: iftype is NULL!", __func__);
1032         return HI_FAIL;
1033     }
1034     return HI_SUCCESS;
1035 }
1036 
1037 static struct HdfMac80211BaseOps g_baseOps = {
1038     .SetMode = WalSetMode,
1039     .AddKey = WalAddKey,
1040     .DelKey = WalDelKey,
1041     .SetDefaultKey = WalSetDefaultKey,
1042     .GetDeviceMacAddr = WalGetDeviceMacAddr,
1043     .SetMacAddr = WalSetMacAddr,
1044     .SetTxPower = WalSetTxPower,
1045     .GetValidFreqsWithBand = WalGetValidFreqsWithBand,
1046     .GetHwCapability = WalGetHwCapability,
1047     .SendAction = WalSendAction,
1048     .GetIftype = WalGetIftype,
1049 };
1050 
1051 static struct HdfMac80211STAOps g_staOps = {
1052     .Connect = WalConnect,
1053     .Disconnect = WalDisconnect,
1054     .StartScan = WalStartScan,
1055     .AbortScan = WalAbortScan,
1056     .SetScanningMacAddress = WalSetScanningMacAddress,
1057 };
1058 
1059 static struct HdfMac80211APOps g_apOps = {
1060     .ConfigAp = WalConfigAp,
1061     .StartAp = WalStartAp,
1062     .StopAp = WalStopAp,
1063     .ConfigBeacon = WalChangeBeacon,
1064     .DelStation = WalDelStation,
1065     .SetCountryCode = WalSetCountryCode,
1066     .GetAssociatedStasCount = WalGetAssociatedStasCount,
1067     .GetAssociatedStasInfo = WalGetAssociatedStasInfo
1068 };
1069 
1070 #ifdef _PRE_WLAN_FEATURE_P2P
1071 static struct HdfMac80211P2POps g_p2pOps = {
1072     .RemainOnChannel = WalRemainOnChannel,
1073     .CancelRemainOnChannel = WalCancelRemainOnChannel,
1074     .ProbeReqReport = WalProbeReqReport,
1075     .AddIf = WalAddIf,
1076     .RemoveIf = WalRemoveIf,
1077     .SetApWpsP2pIe = WalSetApWpsP2pIe,
1078     .GetDriverFlag = WalGetDriverFlag,
1079 };
1080 #endif
1081 
HiMac80211Init(struct HdfChipDriver * chipDriver)1082 hi_void HiMac80211Init(struct HdfChipDriver *chipDriver)
1083 {
1084     if (chipDriver == NULL) {
1085         oam_error_log(0, OAM_SF_ANY, "%s:input is NULL!", __func__);
1086         return;
1087     }
1088     chipDriver->ops = &g_baseOps;
1089     chipDriver->staOps = &g_staOps;
1090     chipDriver->apOps = &g_apOps;
1091 #ifdef _PRE_WLAN_FEATURE_P2P
1092     chipDriver->p2pOps = &g_p2pOps;
1093 #endif
1094 }
1095