• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 /* ****************************************************************************
20   1 头文件包含
21 **************************************************************************** */
22 #include "wal_cfg80211_apt.h"
23 #include "net_adpater.h"
24 #include "hmac_ext_if.h"
25 #include "wal_event_msg.h"
26 #include "wal_wpa_ioctl.h"
27 
28 #ifdef __cplusplus
29 #if __cplusplus
30 extern "C" {
31 #endif
32 #endif
33 
34 /* ****************************************************************************
35   2 外部函数声明
36 **************************************************************************** */
37 /* ****************************************************************************
38   3 全局变量定义
39 **************************************************************************** */
40 hisi_upload_frame_cb     g_upload_frame_func = HI_NULL;
41 hisi_send_event_cb       g_send_event_func   = HI_NULL;
42 
43 /* ****************************************************************************
44   4 函数实现
45 **************************************************************************** */
46 /* ****************************************************************************
47  功能描述  : 提供给用户的回调函数注册接口,回调函数用于驱动向wpa抛事件
48  输入参数  : [1]func
49  输出参数  : 无
50  返 回 值  : 无
51 **************************************************************************** */
hisi_register_send_event_cb(hisi_send_event_cb func)52 hi_s32 hisi_register_send_event_cb(hisi_send_event_cb func)
53 {
54     if ((g_send_event_func != NULL) && (func != NULL)) {
55         g_send_event_func = func;
56         return HI_ERR_S_FAILURE;
57     }
58     g_send_event_func = func;
59     return HI_SUCCESS;
60 }
61 
62 /* ****************************************************************************
63  功能描述  : 上报new station事件接口
64  输入参数  : oal_net_device_stru *pst_dev, const hi_u8 *mac_addr,
65              oal_station_info_stru *sinfo, oal_gfp_enum_uint8 gfp
66  输出参数  : 无
67  返 回 值  : 无
68 **************************************************************************** */
cfg80211_new_sta(const oal_net_device_stru * netdev,const hi_u8 * mac_addr,hi_u8 addr_len,const oal_station_info_stru * sinfo)69 hi_u32 cfg80211_new_sta(const oal_net_device_stru *netdev, const hi_u8 *mac_addr, hi_u8 addr_len,
70     const oal_station_info_stru *sinfo)
71 {
72     hisi_new_sta_info_stru new_sta_info;
73 
74     if (g_send_event_func == HI_NULL) {
75         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_new_sta::g_send_event_func is null.}\r\n");
76         return HI_FAIL;
77     }
78 
79     /* 安全编程规则6.6例外(1) 固定长度的结构体进行内存初始化 */
80     memset_s(&new_sta_info, sizeof(hisi_new_sta_info_stru), 0, sizeof(hisi_new_sta_info_stru));
81 
82     if (sinfo->assoc_req_ies_len == 0) {
83         oam_error_log2(0, OAM_SF_ANY, "{cfg80211_new_sta::assoc_req_ies or assoc_req_ies_len null error %p,%d.}\r\n",
84             (uintptr_t)sinfo->assoc_req_ies, sinfo->assoc_req_ies_len);
85         return HI_FAIL;
86     }
87 
88     new_sta_info.ielen = sinfo->assoc_req_ies_len;
89     new_sta_info.reassoc = 0;
90     if (memcpy_s(new_sta_info.macaddr, ETH_ADDR_LEN, mac_addr, addr_len) != EOK) {
91         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_new_sta::mem safe function err!}");
92         return HI_FAIL;
93     }
94 
95     new_sta_info.ie = (hi_u8 *)oal_memalloc(sinfo->assoc_req_ies_len);
96     if (new_sta_info.ie == HI_NULL) {
97         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_new_sta::pst_new_sta_info->ie malloc error!}");
98         return HI_FAIL;
99     }
100     if (memcpy_s(new_sta_info.ie, sinfo->assoc_req_ies_len, sinfo->assoc_req_ies, sinfo->assoc_req_ies_len) != EOK) {
101         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_new_sta::mem safe function err!}");
102         oal_free(new_sta_info.ie);
103         return HI_FAIL;
104     }
105 
106     hi_u32 ret = (hi_u32)g_send_event_func(netdev->name, HISI_ELOOP_EVENT_NEW_STA, (hi_u8 *)&new_sta_info,
107         (hi_u32)sizeof(hisi_new_sta_info_stru));
108     if (ret != HI_SUCCESS) {
109         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_new_sta::g_send_event_func fail.}\r\n");
110         oal_free(new_sta_info.ie);
111         return HI_FAIL;
112     }
113 
114     return HI_SUCCESS;
115 }
116 
117 /* ****************************************************************************
118  功能描述  : 上报new station事件接口
119  输入参数  : oal_net_device_stru *pst_dev, const hi_u8 *puc_mac_addr,
120             oal_gfp_enum_uint8 en_gfp
121  输出参数  : 无
122  返 回 值  : 无
123 **************************************************************************** */
cfg80211_del_sta(oal_net_device_stru * netdev,const hi_u8 * mac_addr,hi_u8 addr_len)124 hi_u32 cfg80211_del_sta(oal_net_device_stru *netdev, const hi_u8 *mac_addr, hi_u8 addr_len)
125 {
126     hi_u32 l_ret;
127 
128     /* 入参检查 */
129     if ((netdev == HI_NULL) || (mac_addr == HI_NULL)) {
130         oam_error_log2(0, OAM_SF_ANY, "{cfg80211_del_sta::pst_dev or puc_mac_addr ptr NULL %p,%p.}\r\n",
131             (uintptr_t)netdev, (uintptr_t)mac_addr);
132         return HI_FAIL;
133     }
134 
135     if (g_send_event_func == HI_NULL) {
136         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_del_sta::g_send_event_func is null.}\r\n");
137         return HI_FAIL;
138     }
139 
140     l_ret = (hi_u32)g_send_event_func(netdev->name, HISI_ELOOP_EVENT_DEL_STA, (hi_u8 *)mac_addr, addr_len);
141     return l_ret;
142 }
143 
144 /* ****************************************************************************
145  功能描述  : 上报管理帧数据接口
146  输入参数  : struct wireless_dev *wdev, hi_s32 freq, hi_s32 sig_mbm,
147              const hi_u8 *buf, size_t len, oal_gfp_enum_uint8 gfp
148  输出参数  : 无
149  返 回 值  : bool
150 **************************************************************************** */
cfg80211_rx_mgmt(const oal_net_device_stru * netdev,hi_s32 freq,hi_s32 l_sig_mbm,const hi_u8 * buffer,size_t len)151 hi_u8 cfg80211_rx_mgmt(const oal_net_device_stru *netdev, hi_s32 freq, hi_s32 l_sig_mbm, const hi_u8 *buffer,
152     size_t len)
153 {
154     hisi_rx_mgmt_stru rx_mgmt;
155     oal_wireless_dev *wdev = (oal_wireless_dev *)GET_NET_DEV_CFG80211_WIRELESS(netdev);
156     hi_u32 l_ret;
157 
158     if (g_send_event_func == HI_NULL) {
159         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_rx_mgmt::g_send_event_func is null.}\r\n");
160         return HI_FALSE;
161     }
162 
163     if (memset_s(&rx_mgmt, sizeof(hisi_rx_mgmt_stru), 0, sizeof(hisi_rx_mgmt_stru)) != EOK) {
164         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_rx_mgmt::mem safe function err!}");
165         return HI_FALSE;
166     }
167     /* 入参检查 */
168     if ((wdev == HI_NULL) || (buffer == HI_NULL)) {
169         oam_error_log2(0, OAM_SF_ANY, "{cfg80211_rx_mgmt::pst_wdev or buf ptr NULL %p,%p.}\r\n", (uintptr_t)wdev,
170             (uintptr_t)buffer);
171         return HI_FALSE;
172     }
173 
174     rx_mgmt.buf = HI_NULL;
175     rx_mgmt.len = len;
176     rx_mgmt.freq = (hi_u32)freq;
177     rx_mgmt.sig_mbm = l_sig_mbm;
178 
179     if (len != 0) {
180         rx_mgmt.buf = oal_memalloc(len);
181         if (rx_mgmt.buf == HI_NULL) {
182             oam_error_log1(0, OAM_SF_ANY, "{cfg80211_rx_mgmt::pst_rx_mgmt->buf malloc error %p.}",
183                 (uintptr_t)rx_mgmt.buf);
184             return HI_FALSE;
185         }
186         if (memcpy_s(rx_mgmt.buf, len, buffer, len) != EOK) {
187             oam_error_log0(0, OAM_SF_ANY, "{cfg80211_rx_mgmt::mem safe function err!}");
188             oal_free(rx_mgmt.buf);
189             return HI_FALSE;
190         }
191     }
192 
193     l_ret = (hi_u32)g_send_event_func(netdev->name, HISI_ELOOP_EVENT_RX_MGMT, (hi_u8 *) &rx_mgmt,
194                                       sizeof(hisi_rx_mgmt_stru));
195     if (l_ret != HI_SUCCESS) {
196         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_rx_mgmt::g_send_event_func fail.}\r\n");
197         if (rx_mgmt.buf != HI_NULL) {
198             oal_free(rx_mgmt.buf);
199         }
200         return HI_FALSE;
201     }
202 
203     return HI_TRUE;
204 }
205 
206 /* ****************************************************************************
207  函 数 名  : cfg80211_mgmt_tx_status
208  功能描述  : 上报发送状态接口
209  输入参数  : struct wireless_dev *wdev, hi_u64 cookie,
210              const hi_u8 *buf, size_t len, bool ack, oal_gfp_enum_uint8 gfp
211  输出参数  : 无
212  返 回 值  : bool
213  调用函数  :
214  被调函数  :
215 
216  修改历史      :
217   1.日    期   : 2016年6月13日
218     作    者   : HiSilicon
219     修改内容   : 新生成函数
220 
221 **************************************************************************** */
cfg80211_mgmt_tx_status(struct wireless_dev * wdev,const hi_u8 * buffer,size_t len,hi_u8 ack)222 hi_u8 cfg80211_mgmt_tx_status(struct wireless_dev *wdev, const hi_u8 *buffer, size_t len, hi_u8 ack)
223 {
224     hisi_tx_status_stru tx_status;
225     hi_u32 l_ret;
226 
227     if (g_send_event_func == HI_NULL) {
228         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mgmt_tx_status::g_send_event_func is null.}\r\n");
229         return HI_FALSE;
230     }
231 
232     if (memset_s(&tx_status, sizeof(hisi_tx_status_stru), 0, sizeof(hisi_tx_status_stru)) != EOK) {
233         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mgmt_tx_status::mem safe function err!}");
234         return HI_FALSE;
235     }
236     /* 入参检查 */
237     if ((wdev == HI_NULL) || (buffer == HI_NULL)) {
238         oam_error_log2(0, OAM_SF_ANY, "{cfg80211_mgmt_tx_status::pst_wdev or puc_buf ptr NULL %p,%p.}\r\n",
239             (uintptr_t)wdev, (uintptr_t)buffer);
240         return HI_FALSE;
241     }
242 
243     tx_status.buf = HI_NULL;
244     tx_status.len = len;
245     tx_status.ack = ack;
246 
247     if (len != 0) {
248         tx_status.buf = oal_memalloc(len);
249         if (tx_status.buf == HI_NULL) {
250             oam_error_log1(0, OAM_SF_ANY, "{cfg80211_mgmt_tx_status::pst_tx_status->buf malloc error %p.}",
251                 (uintptr_t)tx_status.buf);
252             return HI_FALSE;
253         }
254         if (memcpy_s(tx_status.buf, len, buffer, len) != EOK) {
255             oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mgmt_tx_status::mem safe function err!}");
256             oal_free(tx_status.buf);
257             return HI_FALSE;
258         }
259     }
260 
261     l_ret = (hi_u32)g_send_event_func(wdev->netdev->name, HISI_ELOOP_EVENT_TX_STATUS, (hi_u8 *)&tx_status,
262         sizeof(hisi_tx_status_stru));
263     if (l_ret != HI_SUCCESS) {
264         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mgmt_tx_status::g_send_event_func fail.}\r\n");
265         if (tx_status.buf != HI_NULL) {
266             oal_free(tx_status.buf);
267         }
268         return HI_FALSE;
269     }
270 
271     return HI_TRUE;
272 }
273 
274 /* ****************************************************************************
275  函 数 名  : cfg80211_inform_bss_frame
276  功能描述  : 扫描结果上报接口
277  输入参数  :
278 
279  输出参数  :
280  返 回 值  :
281  调用函数  :
282  被调函数  :
283 
284  修改历史      :
285   1.日    期   : 2016年6月29日
286     作    者   : HiSilicon
287     修改内容   : 新生成函数
288 
289 **************************************************************************** */
cfg80211_inform_bss_frame(const oal_net_device_stru * netdev,oal_wiphy_stru * wiphy,const oal_ieee80211_channel_stru * ieee80211_channel,const wal_scanned_bss_info_stru * scanned_bss_info)290 hi_void cfg80211_inform_bss_frame(const oal_net_device_stru *netdev, oal_wiphy_stru *wiphy,
291     const oal_ieee80211_channel_stru *ieee80211_channel, const wal_scanned_bss_info_stru *scanned_bss_info)
292 {
293     hisi_scan_result_stru scan_result = { 0 };
294 
295     if (g_send_event_func == HI_NULL) {
296         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_inform_bss_frame::g_send_event_func is null.}\r\n");
297         return;
298     }
299 
300     if ((wiphy == HI_NULL) || (ieee80211_channel == HI_NULL) || (scanned_bss_info->mgmt == HI_NULL)) {
301         oam_error_log3(0, OAM_SF_ANY, "{cfg80211_inform_bss_frame::wiphy or ieee80211_channel or mgmt null %p,%p,%p}",
302             (uintptr_t)wiphy, (uintptr_t)ieee80211_channel, (uintptr_t)(scanned_bss_info->mgmt));
303         return;
304     }
305 
306     hi_u32 ie_len = scanned_bss_info->mgmt_len - (hi_u32)oal_offset_of(oal_ieee80211_mgmt_stru, u.probe_resp.variable);
307     hi_u32 beacon_len = scanned_bss_info->mgmt_len - (hi_u32)oal_offset_of(oal_ieee80211_mgmt_stru, u.beacon.variable);
308 
309     scan_result.variable = oal_memalloc(ie_len + beacon_len);
310     if (scan_result.variable == HI_NULL) {
311         oam_error_log2(0, OAM_SF_ANY, "{cfg80211_inform_bss_frame::mallocErr.ieLen%d,beaconLen%d}", ie_len, beacon_len);
312         return;
313     }
314 
315     /* 安全编程规则6.6例外(3)从堆中分配内存后,赋予初值 */
316     memset_s(scan_result.variable, ie_len + beacon_len, 0, ie_len + beacon_len);
317 
318     scan_result.ie_len        = ie_len;
319     scan_result.beacon_ie_len = beacon_len;
320     scan_result.beacon_int  = (hi_s16)scanned_bss_info->mgmt->u.probe_resp.beacon_int;
321     scan_result.caps        = (hi_s16) scanned_bss_info->mgmt->u.probe_resp.capab_info;
322     scan_result.level       = scanned_bss_info->l_signal;
323     scan_result.freq        = ieee80211_channel->center_freq;
324     scan_result.flags       = (hi_s32)ieee80211_channel->flags;
325 
326     if (memcpy_s(scan_result.bssid, ETH_ADDR_LEN, scanned_bss_info->mgmt->bssid, ETH_ALEN) != EOK) {
327         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_inform_bss_frame::mem safe function err!}");
328         oal_free(scan_result.variable);
329         return;
330     }
331     if (memcpy_s(scan_result.variable, ie_len, scanned_bss_info->mgmt->u.probe_resp.variable, ie_len) != EOK) {
332         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_inform_bss_frame::mem safe function err!}");
333         oal_free(scan_result.variable);
334         return;
335     }
336     if (memcpy_s(scan_result.variable + ie_len, beacon_len,
337         scanned_bss_info->mgmt->u.beacon.variable, beacon_len) != EOK) {
338         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_inform_bss_frame::mem safe function err!}");
339         oal_free(scan_result.variable);
340         return;
341     }
342 
343     if ((hi_u32)g_send_event_func(netdev->name, HISI_ELOOP_EVENT_SCAN_RESULT, (hi_u8 *)&scan_result,
344         sizeof(hisi_scan_result_stru)) != HI_SUCCESS) {
345         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_inform_bss_frame::g_send_event_func fail.}");
346         oal_free(scan_result.variable);
347     }
348 }
349 
cfg80211_connect_result_return(const oal_net_device_stru * netdev,const oal_connet_result_stru * connet_result,hisi_connect_result_stru * connect_result)350 hi_void cfg80211_connect_result_return(const oal_net_device_stru *netdev, const oal_connet_result_stru *connet_result,
351     hisi_connect_result_stru *connect_result)
352 {
353     hi_unref_param(connet_result);
354 
355 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
356     if (connet_result->us_connect_status == 0) {
357         /* 如果上报关联成功则关闭PM */
358         hi_u32 pm_flag = 0;
359         hwal_ioctl_set_pm_on(netdev->name, &pm_flag);
360     }
361 #endif
362     if (g_send_event_func == HI_NULL) {
363         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_connect_result::g_send_event_func is null.}\r\n");
364         return;
365     }
366 
367     if ((hi_u32)g_send_event_func(netdev->name, HISI_ELOOP_EVENT_CONNECT_RESULT, (hi_u8 *)connect_result,
368         sizeof(hisi_connect_result_stru)) != HI_SUCCESS) {
369         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_connect_result::g_send_event_func fail.}\r\n");
370         if (connect_result->req_ie != HI_NULL) {
371             oal_free(connect_result->req_ie);
372             connect_result->req_ie = HI_NULL;
373         }
374         if (connect_result->resp_ie != HI_NULL) {
375             oal_free(connect_result->resp_ie);
376             connect_result->resp_ie = HI_NULL;
377         }
378     }
379 
380     return;
381 }
382 
383 /* ****************************************************************************
384  函 数 名  : cfg80211_connect_result
385  功能描述  : 关联结果上报接口
386  输入参数  :
387 
388  输出参数  :
389  返 回 值  :
390  调用函数  :
391  被调函数  :
392 
393  修改历史      :
394   1.日    期   : 2016年6月29日
395     作    者   : HiSilicon
396     修改内容   : 新生成函数
397 
398 **************************************************************************** */
cfg80211_connect_result(const oal_net_device_stru * netdev,const oal_connet_result_stru * connet_result)399 hi_void cfg80211_connect_result(const oal_net_device_stru *netdev, const oal_connet_result_stru *connet_result)
400 {
401     hisi_connect_result_stru connect_result = { 0 };
402 
403     if (g_send_event_func == HI_NULL || netdev == HI_NULL) {
404         oam_error_log1(0, OAM_SF_ANY, "{cfg80211_connect_result::g_send_event_func or dev null %p}", (uintptr_t)netdev);
405         return;
406     }
407 
408     if (memcpy_s(connect_result.bssid, ETH_ADDR_LEN, connet_result->auc_bssid, ETH_ALEN) != EOK) {
409         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_connect_result::mem safe function err!}");
410         return;
411     }
412 
413     if ((connet_result->puc_req_ie != HI_NULL) && (connet_result->req_ie_len != 0)) {
414         connect_result.req_ie = oal_memalloc(connet_result->req_ie_len);
415         connect_result.req_ie_len = connet_result->req_ie_len;
416         if (connect_result.req_ie == HI_NULL) {
417             oam_error_log0(0, OAM_SF_ANY, "{cfg80211_connect_result::pst_connect_result->req_ie zalloc error}\r\n");
418             return;
419         }
420         if (memcpy_s(connect_result.req_ie, connet_result->req_ie_len, connet_result->puc_req_ie,
421             connet_result->req_ie_len) != EOK) {
422             oam_error_log0(0, OAM_SF_ANY, "{cfg80211_connect_result::mem safe function err!}");
423             oal_free(connect_result.req_ie);
424             return;
425         }
426     }
427 
428     if ((connet_result->puc_rsp_ie != HI_NULL) && (connet_result->rsp_ie_len != 0)) {
429         connect_result.resp_ie = oal_memalloc(connet_result->rsp_ie_len);
430         connect_result.resp_ie_len = connet_result->rsp_ie_len;
431         if (connect_result.resp_ie == HI_NULL) {
432             oam_error_log0(0, OAM_SF_ANY, "{cfg80211_connect_result::pst_connect_result->resp_ie zalloc error}\n");
433             oal_free(connect_result.req_ie);
434             return;
435         }
436         if (memcpy_s(connect_result.resp_ie, connet_result->rsp_ie_len, connet_result->puc_rsp_ie,
437             connet_result->rsp_ie_len) != EOK) {
438             oam_error_log0(0, OAM_SF_ANY, "{cfg80211_connect_result::mem safe function err!}");
439             oal_free(connect_result.req_ie);
440             oal_free(connect_result.resp_ie);
441             return;
442         }
443     }
444 
445     connect_result.status = connet_result->us_connect_status;
446     connect_result.freq = connet_result->us_freq;
447 
448     cfg80211_connect_result_return(netdev, connet_result, &connect_result);
449 
450     return;
451 }
452 
453 /* ****************************************************************************
454  函 数 名  : cfg80211_disconnected
455  功能描述  : 去关联上报接口
456  输入参数  :
457 
458  输出参数  :
459  返 回 值  :
460  调用函数  :
461  被调函数  :
462 
463  修改历史      :
464   1.日    期   : 2016年6月29日
465     作    者   : HiSilicon
466     修改内容   : 新生成函数
467 
468 **************************************************************************** */
cfg80211_disconnected(const oal_net_device_stru * netdev,hi_u16 us_reason,const hi_u8 * ie,hi_u32 ie_len)469 hi_u32 cfg80211_disconnected(const oal_net_device_stru *netdev, hi_u16 us_reason, const hi_u8 *ie, hi_u32 ie_len)
470 {
471     hisi_disconnect_stru disconnect;
472     hi_u32 l_ret;
473 
474     if (g_send_event_func == HI_NULL) {
475         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_disconnected::g_send_event_func is null.}");
476         return HI_FAIL;
477     }
478 
479     /* 安全编程规则6.6例外(1) 固定长度的结构体进行内存初始化 */
480     memset_s(&disconnect, sizeof(hisi_disconnect_stru), 0, sizeof(hisi_disconnect_stru));
481 
482     if ((ie != HI_NULL) && (ie_len != 0)) {
483         disconnect.ie = oal_memalloc(ie_len);
484         disconnect.ie_len = ie_len;
485         if (disconnect.ie == HI_NULL) {
486             oam_error_log0(0, OAM_SF_ANY, "{cfg80211_disconnected::malloc error.}");
487             return HI_FAIL;
488         }
489         if (memcpy_s(disconnect.ie, ie_len, ie, ie_len) != EOK) {
490             oam_error_log0(0, OAM_SF_ANY, "{cfg80211_disconnected::mem safe function err!}");
491             oal_free(disconnect.ie);
492             return HI_FAIL;
493         }
494     }
495     disconnect.reason = us_reason;
496 
497     l_ret = (hi_u32)g_send_event_func(netdev->name, HISI_ELOOP_EVENT_DISCONNECT, (hi_u8 *)&disconnect,
498         sizeof(hisi_disconnect_stru));
499     if (l_ret != HI_SUCCESS) {
500         oam_error_log1(0, OAM_SF_ANY, "{cfg80211_disconnected::g_send_event_func fail, ret:%u.}", l_ret);
501         if (disconnect.ie != HI_NULL) {
502             oal_free(disconnect.ie);
503         }
504         return HI_FAIL;
505     }
506 
507     return HI_SUCCESS;
508 }
509 
510 /* ****************************************************************************
511  功能描述  : 延时上报机制中超时上报去关联给WPA
512 **************************************************************************** */
cfg80211_timeout_disconnected(const oal_net_device_stru * netdev)513 hi_u32 cfg80211_timeout_disconnected(const oal_net_device_stru *netdev)
514 {
515     hi_u32 l_ret;
516 
517     if (g_send_event_func == HI_NULL) {
518         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_timeout_disconnected::g_send_event_func is null.}");
519         return HI_FAIL;
520     }
521 
522     l_ret = (hi_u32)g_send_event_func(netdev->name, HISI_ELOOP_EVENT_TIMEOUT_DISCONN, HI_NULL, 0);
523     if (l_ret != HI_SUCCESS) {
524         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_timeout_disconnected::g_send_event_func fail.}");
525     }
526 
527     return l_ret;
528 }
529 
530 /* ****************************************************************************
531  函 数 名  : cfg80211_scan_done
532  功能描述  : 扫描完成上报接口
533  输入参数  :
534 
535  输出参数  :
536  返 回 值  :
537  调用函数  :
538  被调函数  :
539 
540  修改历史      :
541   1.日    期   : 2016年6月29日
542     作    者   : HiSilicon
543     修改内容   : 新生成函数
544 
545 **************************************************************************** */
cfg80211_scan_done(const oal_net_device_stru * netdev,hisi_scan_status_enum status)546 hi_void cfg80211_scan_done(const oal_net_device_stru *netdev, hisi_scan_status_enum status)
547 {
548     hisi_driver_scan_status_stru scan_ctl_status;
549 
550     scan_ctl_status.scan_status = status;
551     if (g_send_event_func == HI_NULL) {
552         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_scan_done::g_send_event_func is null.}");
553         return;
554     }
555     g_send_event_func(netdev->name, HISI_ELOOP_EVENT_SCAN_DONE, (hi_u8 *)&scan_ctl_status,
556         sizeof(hisi_driver_scan_status_stru));
557 }
558 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
559 /* ****************************************************************************
560  函 数 名  : cfg80211_rx_exception
561  功能描述  : DFX上报接口(私有接口)
562  输入参数  :
563 
564  输出参数  :
565  返 回 值  :
566  调用函数  :
567  被调函数  :
568 
569  修改历史      :
570   1.日    期   : 2017年2月17日
571     作    者   : HiSilicon
572     修改内容   : 新生成函数
573 
574 **************************************************************************** */
cfg80211_rx_exception(const oal_net_device_stru * netdev,hi_u8 * puc_data,hi_u32 data_len)575 hi_void cfg80211_rx_exception(const oal_net_device_stru *netdev, hi_u8 *puc_data, hi_u32 data_len)
576 {
577     if (g_send_event_func == HI_NULL) {
578         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_rx_exception::g_send_event_func is null.}\r\n");
579         return;
580     }
581     if ((puc_data == HI_NULL) || (data_len > 32)) { /* 32:数据长度 */
582         oam_error_log1(0, OAM_SF_ANY, "{cfg80211_rx_exception::puc_data is null or ul_data_len[%d] too long.}\r\n",
583             data_len);
584         return;
585     }
586     g_send_event_func(netdev->name, HISI_ELOOP_EVENT_RX_DFX, puc_data, data_len);
587 }
588 
589 /* ****************************************************************************
590  函 数 名  : cfg80211_mic_failure
591  功能描述  : 上报mic攻击
592  输入参数  :
593  输出参数  :
594  返 回 值  :
595  调用函数  :
596  被调函数  :
597 
598  修改历史      :
599   1.日    期   : 2013年12月28日
600     作    者   : HiSilicon
601     修改内容   : 新生成函数
602   2.日    期   : 2014年5月15日
603     作    者   : HiSilicon
604     修改内容   : 新生成函数
605 
606 **************************************************************************** */
cfg80211_mic_failure(const oal_net_device_stru * netdev,const hmac_mic_event_stru * mic_event,const hi_u8 * puc_tsc,oal_gfp_enum_uint8 gfp)607 hi_u32 cfg80211_mic_failure(const oal_net_device_stru *netdev, const hmac_mic_event_stru *mic_event,
608     const hi_u8 *puc_tsc, oal_gfp_enum_uint8 gfp)
609 {
610     hi_u32 ret;
611     hisi_michael_mic_failure_stru mic_failure;
612 
613     cfg80211_michael_mic_failure(netdev, mic_event->auc_user_mac, mic_event->key_type, mic_event->l_key_id, puc_tsc,
614         gfp);
615 
616     mic_failure.key_type = mic_event->key_type;
617     mic_failure.l_key_id = mic_event->l_key_id;
618     if (memcpy_s(mic_failure.user_mac_addr, WLAN_MAC_ADDR_LEN, mic_event->auc_user_mac, WLAN_MAC_ADDR_LEN) != EOK) {
619         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mic_failure::mem safe function err!}");
620         return HI_FAIL;
621     }
622 
623     if (g_send_event_func == HI_NULL) {
624         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mic_failure::g_send_event_func is null.}\r\n");
625         return HI_FAIL;
626     }
627 
628     ret = (hi_u32)g_send_event_func(netdev->name, HISI_ELOOP_EVENT_MICHAEL_MIC_FAILURE, (hi_u8 *)&mic_failure,
629         sizeof(hisi_michael_mic_failure_stru));
630     return ret;
631 }
632 #endif
633 /* ****************************************************************************
634  功能描述  : STA根据CSA切换信道事件上报
635 **************************************************************************** */
cfg80211_csa_channel_switch(const oal_net_device_stru * netdev,hi_s32 freq)636 hi_u32 cfg80211_csa_channel_switch(const oal_net_device_stru *netdev, hi_s32 freq)
637 {
638     hi_u32 ret;
639     hisi_ch_switch_stru channel_switch;
640 
641     channel_switch.freq = freq;
642 
643     if (g_send_event_func == HI_NULL) {
644         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mesh_report_accept_peer::g_send_event_func is null.}");
645         return HI_FAIL;
646     }
647 
648     ret = (hi_u32)g_send_event_func(netdev->name, HISI_ELOOP_EVENT_CHANNEL_SWITCH, (hi_u8 *)&channel_switch,
649         (hi_u32)sizeof(hisi_ch_switch_stru));
650     return ret;
651 }
652 
653 #ifdef _PRE_WLAN_FEATURE_MESH
654 /* ****************************************************************************
655  功能描述  : Mesh上报需要发送Mesh Peering Close Frame
656  被调函数  :
657   1.日    期   : 2019年1月26日
658     作    者   : HiSilicon
659     修改内容   : 新生成函数
660 
661 **************************************************************************** */
cfg80211_mesh_close(const oal_net_device_stru * netdev,const hi_u8 * mac_addr,hi_u8 addr_len,hi_u16 us_reason)662 hi_u32 cfg80211_mesh_close(const oal_net_device_stru *netdev, const hi_u8 *mac_addr, hi_u8 addr_len, hi_u16 us_reason)
663 {
664     hisi_mesh_close_peer_stru mesh_close_peer;
665 
666     if (memset_s(&mesh_close_peer, sizeof(hisi_mesh_close_peer_stru), 0, sizeof(hisi_mesh_close_peer_stru)) != EOK) {
667         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mesh_close::mem safe function err!}");
668         return HI_FAIL;
669     }
670 
671     if (memcpy_s(mesh_close_peer.macaddr, ETH_ADDR_LEN, mac_addr, addr_len) != EOK) {
672         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mesh_close::mem safe function err!}");
673         return HI_FAIL;
674     }
675 
676     mesh_close_peer.us_reason = us_reason;
677 
678     if (g_send_event_func == HI_NULL) {
679         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mesh_close::g_send_event_func is null.}\r\n");
680         return HI_FAIL;
681     }
682 
683     g_send_event_func(netdev->name, HISI_ELOOP_EVENT_MESH_CLOSE, (hi_u8 *)&mesh_close_peer,
684         sizeof(hisi_mesh_close_peer_stru));
685     return HI_SUCCESS;
686 }
687 
688 /* ****************************************************************************
689 功能描述  : mesh非扫描状态上报mesh beacon帧
690 输入参数  :oal_net_device_stru *pst_net_device, hi_u8 *puc_mac_addr,
691          hi_u8 uc_bcn_prio, hi_u8 en_is_mbr, oal_gfp_enum_uint8 en_gfp
692 返 回 值  :hi_u32
693 修改历史      :
694  1.日    期   : 2019年3月21日
695    作    者   : HiSilicon
696    修改内容   : 新生成函数
697 **************************************************************************** */
cfg80211_mesh_new_peer_candidate(const oal_net_device_stru * netdev,const hmac_report_new_peer_candidate_stru * puc_new_peer)698 hi_u32 cfg80211_mesh_new_peer_candidate(const oal_net_device_stru *netdev,
699     const hmac_report_new_peer_candidate_stru *puc_new_peer)
700 {
701     hisi_mesh_new_peer_candidate_stru new_mesh_peer;
702 
703     if (memset_s(&new_mesh_peer, sizeof(hisi_mesh_new_peer_candidate_stru), 0,
704         sizeof(hisi_mesh_new_peer_candidate_stru)) != EOK) {
705         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mesh_new_peer_candidate::mem safe function err!}");
706         return HI_FAIL;
707     }
708 
709     new_mesh_peer.bcn_prio = puc_new_peer->bcn_prio;
710     new_mesh_peer.is_mbr = puc_new_peer->is_mbr;
711     new_mesh_peer.rssi = (hi_s8)(-(puc_new_peer->rssi));
712     if (memcpy_s(new_mesh_peer.auc_peer_addr, ETH_ADDR_LEN, puc_new_peer->auc_mac_addr, ETH_ADDR_LEN) != EOK) {
713         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mesh_new_peer_candidate::mem safe function err!}");
714         return HI_FAIL;
715     }
716 
717     if (g_send_event_func == HI_NULL) {
718         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mesh_new_peer_candidate::g_send_event_func is null.}\r\n");
719         return HI_FAIL;
720     }
721 
722     g_send_event_func(netdev->name, HISI_ELOOP_EVENT_NEW_PEER_CANDIDATE, (hi_u8 *)&new_mesh_peer,
723         sizeof(hisi_mesh_new_peer_candidate_stru));
724     return HI_SUCCESS;
725 }
726 #endif
727 
728 #ifdef _PRE_WLAN_FEATURE_P2P
729 /* ****************************************************************************
730  功能描述  : 保持在指定信道上报
731  修改历史      :
732   1.日    期   : 2019年4月28日
733     作    者   : HiSilicon
734     修改内容   : 新生成函数
735 **************************************************************************** */
cfg80211_remain_on_channel(const oal_net_device_stru * netdev,hi_u32 freq,hi_u32 duration)736 hi_u32 cfg80211_remain_on_channel(const oal_net_device_stru *netdev, hi_u32 freq, hi_u32 duration)
737 {
738     hisi_on_channel_stru remain_on_channel;
739     if (g_send_event_func == HI_NULL) {
740         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_remain_on_channel::g_send_event_func is null.}\r\n");
741         return HI_FAIL;
742     }
743     remain_on_channel.freq = (hi_s32)freq;
744     remain_on_channel.duration = (hi_s32)duration;
745 
746     g_send_event_func(netdev->name, HISI_ELOOP_EVENT_REMAIN_ON_CHANNEL, (hi_u8 *)&remain_on_channel,
747         sizeof(hisi_on_channel_stru));
748     return HI_SUCCESS;
749 }
750 
751 /* ****************************************************************************
752  功能描述  : 取消保持在指定信道事件上报
753  修改历史      :
754   1.日    期   : 2019年4月28日
755     作    者   : HiSilicon
756     修改内容   : 新生成函数
757 **************************************************************************** */
cfg80211_cancel_remain_on_channel(const oal_net_device_stru * netdev,hi_u32 freq)758 hi_u32 cfg80211_cancel_remain_on_channel(const oal_net_device_stru *netdev, hi_u32 freq)
759 {
760     hisi_on_channel_stru remain_on_channel;
761     if (g_send_event_func == HI_NULL) {
762         oam_error_log0(0, OAM_SF_ANY, "{cfg80211_mesh_report_accept_peer::g_send_event_func is null.}\r\n");
763         return HI_FAIL;
764     }
765     remain_on_channel.freq = (hi_s32)freq;
766 
767     g_send_event_func(netdev->name, HISI_ELOOP_EVENT_CANCEL_REMAIN_ON_CHANNEL, (hi_u8 *)&remain_on_channel,
768         sizeof(hisi_on_channel_stru));
769     return HI_SUCCESS;
770 }
771 #endif
772 
773 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
774 /* ****************************************************************************
775  函 数 名  : cfg80211_rx_mgmt_ext
776  功能描述  : 上报接收到的管理帧
777  输入参数  : [1]dev
778              [2]freq
779              [3]buf
780              [4]len
781  输出参数  : HI_SUCCESS 上报成功,其它错误码 上报失败
782  返 回 值  : hi_u32
783 **************************************************************************** */
cfg80211_rx_mgmt_ext(const oal_net_device_stru * netdev,hi_s32 freq,const hi_u8 * buf,hi_u32 len)784 hi_u32 cfg80211_rx_mgmt_ext(const oal_net_device_stru *netdev, hi_s32 freq, const hi_u8 *buf, hi_u32 len)
785 {
786     hi_u8 ret;
787 
788     ret = cfg80211_rx_mgmt(netdev, freq, 0, buf, len);
789 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
790     ret = HI_TRUE;
791 #endif
792     if (ret == HI_TRUE) {
793         return HI_SUCCESS;
794     } else {
795         return HI_FAIL;
796     }
797 }
798 
cfg80211_kobject_uevent_env_sta_join(oal_net_device_stru * netdev,const hi_u8 * mac_addr,hi_u8 addr_len)799 hi_void cfg80211_kobject_uevent_env_sta_join(oal_net_device_stru *netdev, const hi_u8 *mac_addr, hi_u8 addr_len)
800 {
801     hi_unref_param(addr_len);
802 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
803     if (memset_s(&env, sizeof(env), 0, sizeof(env)) != EOK) {
804         return;
805     }
806     add_uevent_var(&env, "SOFTAP=STA_JOIN wlan0 wlan0 %02x:%02x:%02x:%02x:%02x:%02x",
807                    mac_addr[0], mac_addr[1], mac_addr[2],  /* 0 1 2 数组的位数 */
808                    mac_addr[3], mac_addr[4], mac_addr[5]); /* 3 4 5 数组的位数 */
809 #if (LINUX_VERSION_CODE >= kernel_version(4, 1, 0))
810     kobject_uevent_env(&(netdev->dev.kobj), KOBJ_CHANGE, env.envp);
811 #else
812     kobject_uevent_env(&(netdev->dev.kobj), KOBJ_CHANGE, (hi_s8 **)&env);
813 #endif
814 #else
815     hi_unref_param(netdev);
816     hi_unref_param(mac_addr);
817 #endif /* #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) */
818 }
819 
cfg80211_kobject_uevent_env_sta_leave(oal_net_device_stru * netdev,const hi_u8 * mac_addr,hi_u8 addr_len)820 hi_void cfg80211_kobject_uevent_env_sta_leave(oal_net_device_stru *netdev, const hi_u8 *mac_addr, hi_u8 addr_len)
821 {
822     hi_unref_param(addr_len);
823 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
824     if (memset_s(&env, sizeof(env), 0, sizeof(env)) != EOK) {
825         return;
826     }
827     add_uevent_var(&env, "SOFTAP=STA_LEAVE wlan0 wlan0 %02x:%02x:%02x:%02x:%02x:%02x",
828                    mac_addr[0], mac_addr[1], mac_addr[2],  /* 0 1 2 数组的位数 */
829                    mac_addr[3], mac_addr[4], mac_addr[5]); /* 3 4 5 数组的位数 */
830 #if (LINUX_VERSION_CODE >= kernel_version(4, 1, 0))
831     kobject_uevent_env(&(netdev->dev.kobj), KOBJ_CHANGE, env.envp);
832 #else
833     kobject_uevent_env(&(netdev->dev.kobj), KOBJ_CHANGE, (hi_s8 **)&env);
834 #endif
835 #else
836     hi_unref_param(netdev);
837     hi_unref_param(mac_addr);
838 #endif /* #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) */
839 }
840 #endif
841 
842 #ifdef _PRE_WLAN_FEATURE_PROMIS
843 /* ****************************************************************************
844  函 数 名  : hwal_send_others_bss_data
845  功能描述  : 上报其他BSS网络数据包
846  输入参数  : pst_netbuf 数据包的netbuf指针、数据包的长度
847  输出参数  : 无
848  返 回 值  :
849  调用函数  :
850  被调函数  :
851 
852  修改历史      :
853   1.日    期   : 2016年7月10日
854     作    者   : HiSilicon
855     修改内容   : 新生成函数
856 
857 **************************************************************************** */
hwal_send_others_bss_data(const oal_netbuf_stru * netbuf)858 hi_u32 hwal_send_others_bss_data(const oal_netbuf_stru *netbuf)
859 {
860     hi_u32 *recv_buf = HI_NULL;
861     hi_s32 frame_len;
862     hi_s8 rssi;
863     mac_ieee80211_frame_stru *frame_hdr = HI_NULL;
864     hi_u8 filter;
865 
866     if (netbuf == HI_NULL) {
867         oam_error_log0(0, OAM_SF_ANY, "hwal_send_others_bss_data::pst_netbuf is null");
868         return HI_ERR_CODE_PTR_NULL;
869     }
870     hmac_rx_ctl_stru *rx_ctrl = (hmac_rx_ctl_stru *)oal_netbuf_cb(netbuf);
871     if (rx_ctrl == HI_NULL) {
872         oam_error_log0(0, OAM_SF_ANY, "hwal_send_others_bss_data::rx_ctrl is null");
873         return HI_ERR_CODE_PTR_NULL;
874     }
875     recv_buf = rx_ctrl->pul_mac_hdr_start_addr;
876     frame_len = (hi_s32)rx_ctrl->us_frame_len;
877     rssi = rx_ctrl->rssi_dbm;
878 
879     frame_hdr = (mac_ieee80211_frame_stru *)recv_buf;
880 
881     /* mdata_en/udata_en/mmngt_en/umngt_en */
882     filter = hwal_get_promis_filter();
883     if ((filter == 0x3) || (filter == 0x2) || (filter == 0x1)) { /* 数据帧 0011 0x3 0x2 0x1 */
884         if (frame_hdr->frame_control.type != WLAN_DATA_BASICTYPE) {
885             return HI_SUCCESS;
886         }
887     }
888     if ((filter == 0xC) || (filter == 0x8) || (filter == 0x4)) { /* 管理帧 1100 0xC 0x8 0x4 */
889         if (frame_hdr->frame_control.type != WLAN_MANAGEMENT) {
890             return HI_SUCCESS;
891         }
892     }
893     if ((filter == 0x2) || (filter == 0x8)) { /* 单播 管理帧+数据帧 0x2 0x8 */
894         if (ether_is_multicast(frame_hdr->auc_address1)) {
895             return HI_SUCCESS;
896         }
897     }
898     if ((filter == 0x1) || (filter == 0x4)) { /* 多播+广播 管理帧+数据帧 0x1 0x4 */
899         if (!ether_is_multicast(frame_hdr->auc_address1)) {
900             return HI_SUCCESS;
901         }
902     }
903 
904     if (g_upload_frame_func != HI_NULL) {
905         g_upload_frame_func(recv_buf, frame_len, rssi);
906     }
907 
908     return HI_SUCCESS;
909 }
910 
911 /* ****************************************************************************
912  函 数 名  : hisi_wlan_register_upload_frame_cb
913  功能描述  : 供用户调用,注册处理驱动上报的数据包函数
914  输入参数  : func 函数指针
915  输出参数  : 无
916  返 回 值  :
917  调用函数  :
918  被调函数  :
919 
920  修改历史      :
921   1.日    期   : 2017年1月12日
922     作    者   : HiSilicon
923     修改内容   : 新生成函数
924 
925 **************************************************************************** */
hisi_wlan_register_upload_frame_cb(hisi_upload_frame_cb func)926 hi_u32 hisi_wlan_register_upload_frame_cb(hisi_upload_frame_cb func)
927 {
928     hi_task_lock();
929     g_upload_frame_func = func;
930     hi_task_unlock();
931     return HI_SUCCESS;
932 }
933 #endif // #ifdef _PRE_WLAN_FEATURE_PROMIS
934 
935 #ifdef __cplusplus
936 #if __cplusplus
937 }
938 #endif
939 #endif
940