• 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 "oal_net.h"
23 #include "oal_cfg80211.h"
24 #include "hdf_wifi_event.h"
25 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
26 #include "wal_cfg80211_apt.h"
27 #endif
28 
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif
33 #endif
34 
35 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
36 /* ****************************************************************************
37   2 全局变量定义
38 **************************************************************************** */
39 static oal_kobj_uevent_env_stru g_env;
40 #endif
41 
42 /* ****************************************************************************
43  功能描述  : 上报调度扫描结果
44 **************************************************************************** */
oal_cfg80211_sched_scan_result(oal_wiphy_stru * pst_wiphy)45 hi_void oal_cfg80211_sched_scan_result(oal_wiphy_stru *pst_wiphy)
46 {
47 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
48     return cfg80211_sched_scan_results(pst_wiphy);
49 #else
50     hi_unref_param(pst_wiphy);
51 #endif
52 }
53 
54 /* ****************************************************************************
55  功能描述  : 上报linux 内核已经处于指定信道
56 **************************************************************************** */
oal_cfg80211_ready_on_channel(oal_wireless_dev * wdev,hi_u64 cookie,oal_ieee80211_channel_stru * chan,hi_u32 duration,oal_gfp_enum_uint8 en_gfp)57 hi_void oal_cfg80211_ready_on_channel(
58 #if (LINUX_VERSION_CODE >= kernel_version(3, 10, 44)) || (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
59     oal_wireless_dev *wdev,
60 #else
61     oal_net_device_stru *net_dev,
62 #endif
63     hi_u64 cookie, oal_ieee80211_channel_stru *chan, hi_u32 duration, oal_gfp_enum_uint8 en_gfp)
64 {
65 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
66 #if (LINUX_VERSION_CODE >= kernel_version(3, 10, 44))
67     cfg80211_ready_on_channel(wdev, cookie, chan, duration, en_gfp);
68 #else
69     enum nl80211_channel_type en_channel_type;
70     en_channel_type = NL80211_CHAN_HT20;
71     cfg80211_ready_on_channel(pst_net_dev, cookie, chan, en_channel_type, duration, en_gfp);
72 #endif
73 #else
74     hi_unref_param(wdev);
75     hi_unref_param(cookie);
76     hi_unref_param(chan);
77     hi_unref_param(duration);
78     hi_unref_param(en_gfp);
79 #endif
80 }
81 
oal_kobject_uevent_env_sta_join(oal_net_device_stru * net_device,const hi_u8 * mac_addr)82 hi_void oal_kobject_uevent_env_sta_join(oal_net_device_stru *net_device, const hi_u8 *mac_addr)
83 {
84 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
85     memset_s(&g_env, sizeof(g_env), 0, sizeof(g_env));
86     add_uevent_var(&g_env, "SOFTAP=STA_JOIN wlan0 wlan0 %02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1],
87         mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); /* mac addr 0:1:2:3:4:5 */
88 #if (LINUX_VERSION_CODE >= kernel_version(4, 1, 0))
89     kobject_uevent_env(&(net_device->dev.kobj), KOBJ_CHANGE, g_env.envp);
90 #else
91     kobject_uevent_env(&(net_device->dev.kobj), KOBJ_CHANGE, (char **)&g_env);
92 #endif
93 #else
94     hi_unref_param(net_device);
95     hi_unref_param(mac_addr);
96 #endif /* #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) */
97 }
98 
oal_kobject_uevent_env_sta_leave(oal_net_device_stru * net_device,const hi_u8 * mac_addr)99 hi_void oal_kobject_uevent_env_sta_leave(oal_net_device_stru *net_device, const hi_u8 *mac_addr)
100 {
101 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
102     memset_s(&g_env, sizeof(g_env), 0, sizeof(g_env));
103     add_uevent_var(&g_env, "SOFTAP=STA_LEAVE wlan0 wlan0 %02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1],
104         mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); /* mac addr 0:1:2:3:4:5 */
105     kobject_uevent_env(&(net_device->dev.kobj), KOBJ_CHANGE, g_env.envp);
106 #else
107     hi_unref_param(net_device);
108     hi_unref_param(mac_addr);
109 #endif /* #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) */
110 }
111 
oal_cfg80211_mgmt_tx_status(oal_wireless_dev * wdev,hi_u64 cookie,const hi_u8 * buf,size_t len,hi_u8 ack,oal_gfp_enum_uint8 gfp)112 hi_void oal_cfg80211_mgmt_tx_status(
113 #if (LINUX_VERSION_CODE >= kernel_version(3, 10, 44)) || (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
114     oal_wireless_dev *wdev,
115 #else
116     oal_net_device_stru *pst_net_dev,
117 #endif
118     hi_u64 cookie, const hi_u8 *buf, size_t len, hi_u8 ack, oal_gfp_enum_uint8 gfp)
119 {
120 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) || defined(_PRE_HDF_LINUX)
121     hi_unref_param(cookie);
122     hi_unref_param(gfp);
123     HdfWifiEventMgmtTxStatus(wdev->netdev, buf, len, ack);
124 #elif (LINUX_VERSION_CODE >= kernel_version(3, 10, 44))
125     cfg80211_mgmt_tx_status(wdev, cookie, buf, len, ack, gfp);
126 #else /* linux vs 3.4.5 */
127     cfg80211_mgmt_tx_status(pst_net_dev, cookie, buf, len, ack, gfp);
128 #endif
129 }
130 
131 /* ****************************************************************************
132  功能描述  : 上报扫描完成结果
133 **************************************************************************** */
oal_cfg80211_scan_done(oal_cfg80211_scan_request_stru * pst_cfg80211_scan_request,hi_s8 c_aborted)134 hi_void oal_cfg80211_scan_done(oal_cfg80211_scan_request_stru *pst_cfg80211_scan_request, hi_s8 c_aborted)
135 {
136     (void)pst_cfg80211_scan_request;
137 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
138 #if (LINUX_VERSION_CODE >= kernel_version(4, 8, 0))
139     oal_cfg80211_scan_info_stru scan_info = {
140         .aborted = c_aborted
141     };
142     cfg80211_scan_done(pst_cfg80211_scan_request, &scan_info);
143 #endif
144 #else /* (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) || defined(_PRE_HDF_LINUX) */
145     (void)c_aborted;
146 #endif
147 }
148 
149 /* ****************************************************************************
150  功能描述  : STA上报给关联结果结构体
151 **************************************************************************** */
oal_cfg80211_connect_result(oal_net_device_stru * net_device,const oal_connet_result_stru * connect_result)152 hi_u32 oal_cfg80211_connect_result(oal_net_device_stru *net_device, const oal_connet_result_stru *connect_result)
153 {
154 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
155     cfg80211_connect_result(net_device, connect_result->auc_bssid, connect_result->puc_req_ie,
156                             connect_result->req_ie_len, connect_result->puc_rsp_ie, connect_result->rsp_ie_len,
157                             connect_result->us_status_code, GFP_ATOMIC);
158 #else
159     HdfWifiEventConnectResult(net_device, (struct ConnetResult *)connect_result);
160 #endif
161 
162     return HI_SUCCESS;
163 }
164 
165 /* ****************************************************************************
166  功能描述  : STA上报给内核去关联结果
167 **************************************************************************** */
oal_cfg80211_disconnected(oal_net_device_stru * pst_net_device,hi_u16 us_reason,const hi_u8 * puc_ie,hi_u32 ul_ie_len,hi_bool locally_generated)168 hi_u32 oal_cfg80211_disconnected(oal_net_device_stru *pst_net_device, hi_u16 us_reason, const hi_u8 *puc_ie,
169     hi_u32 ul_ie_len, hi_bool locally_generated)
170 {
171 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
172     cfg80211_disconnected(pst_net_device, us_reason, puc_ie, ul_ie_len, locally_generated, GFP_ATOMIC);
173 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) || defined(_PRE_HDF_LINUX)
174     HdfWifiEventDisconnected(pst_net_device, us_reason, puc_ie, ul_ie_len);
175     hi_unref_param(locally_generated);
176 #endif
177     return HI_SUCCESS;
178 }
179 
180 /* ****************************************************************************
181  功能描述  : AP上报去关联某个STA情况
182 **************************************************************************** */
oal_cfg80211_del_sta(oal_net_device_stru * net_device,const hi_u8 * mac_addr,hi_u8 addr_len,oal_gfp_enum_uint8 en_gfp)183 hi_u32 oal_cfg80211_del_sta(oal_net_device_stru *net_device, const hi_u8 *mac_addr, hi_u8 addr_len,
184     oal_gfp_enum_uint8 en_gfp)
185 {
186     hi_unref_param(addr_len);
187 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
188     cfg80211_del_sta(net_device, mac_addr, en_gfp);
189 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) || defined(_PRE_HDF_LINUX)
190     HdfWifiEventDelSta(net_device, mac_addr, WLAN_MAC_ADDR_LEN);
191     hi_unref_param(en_gfp);
192 #endif
193 
194     return HI_SUCCESS;
195 }
196 
197 /* ****************************************************************************
198  功能描述  : AP上报新关联某个STA情况
199 **************************************************************************** */
oal_cfg80211_new_sta(oal_net_device_stru * net_device,const hi_u8 * mac_addr,hi_u8 addr_len,oal_station_info_stru * station_info,oal_gfp_enum_uint8 en_gfp)200 hi_u32 oal_cfg80211_new_sta(oal_net_device_stru *net_device, const hi_u8 *mac_addr, hi_u8 addr_len,
201     oal_station_info_stru *station_info, oal_gfp_enum_uint8 en_gfp)
202 {
203 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
204     cfg80211_new_sta(net_device, mac_addr, station_info, en_gfp);
205     hi_unref_param(addr_len);
206 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) || defined(_PRE_HDF_LINUX)
207     struct StationInfo info = { 0 };
208     info.assocReqIes = station_info->assoc_req_ies;
209     info.assocReqIesLen = station_info->assoc_req_ies_len;
210     HdfWifiEventNewSta(net_device, mac_addr, WLAN_MAC_ADDR_LEN, &info);
211     hi_unref_param(en_gfp);
212     hi_unref_param(addr_len);
213 #endif
214 
215     return HI_SUCCESS;
216 }
217 
218 /* ****************************************************************************
219  功能描述  : 上报mic攻击
220 **************************************************************************** */
oal_cfg80211_mic_failure(oal_net_device_stru * net_device,const hi_u8 * mac_addr,enum nl80211_key_type key_type,hi_s32 key_id,const hi_u8 * tsc,oal_gfp_enum_uint8 en_gfp)221 hi_void oal_cfg80211_mic_failure(oal_net_device_stru *net_device, const hi_u8 *mac_addr,
222     enum nl80211_key_type key_type, hi_s32 key_id, const hi_u8 *tsc, oal_gfp_enum_uint8 en_gfp)
223 {
224 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
225     cfg80211_michael_mic_failure(net_device, mac_addr, key_type, key_id, tsc, en_gfp);
226 #else
227     hi_unref_param(net_device);
228     hi_unref_param(mac_addr);
229     hi_unref_param(key_type);
230     hi_unref_param(key_id);
231     hi_unref_param(tsc);
232     hi_unref_param(en_gfp);
233 #endif
234 }
235 
236 /* ****************************************************************************
237  功能描述  : 上报接收到的管理帧
238 **************************************************************************** */
oal_cfg80211_rx_mgmt(oal_net_device_stru * pst_dev,hi_s32 l_freq,const hi_u8 * puc_buf,hi_u32 ul_len,oal_gfp_enum_uint8 en_gfp)239 hi_u32 oal_cfg80211_rx_mgmt(oal_net_device_stru *pst_dev, hi_s32 l_freq, const hi_u8 *puc_buf, hi_u32 ul_len,
240     oal_gfp_enum_uint8 en_gfp)
241 {
242 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
243     oal_wireless_dev *pst_wdev = HI_NULL;
244     pst_wdev = pst_dev->ieee80211Ptr;
245 
246     cfg80211_rx_mgmt(pst_wdev, l_freq, 0, puc_buf, ul_len, en_gfp);
247 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) || defined(_PRE_HDF_LINUX)
248     HdfWifiEventRxMgmt(pst_dev, l_freq, 0, puc_buf, (size_t)ul_len);
249     hi_unref_param(en_gfp);
250 #endif
251 
252     return HI_SUCCESS;
253 }
254 
255 /* ****************************************************************************
256 上报内核bss信息
257 **************************************************************************** */
oal_cfg80211_inform_bss_frame(oal_wiphy_stru * pst_wiphy,oal_ieee80211_channel_stru * pst_ieee80211_channel,oal_ieee80211_mgmt_stru * pst_mgmt,hi_u32 ul_len,hi_s32 l_signal,oal_gfp_enum_uint8 en_ftp)258 oal_cfg80211_bss_stru *oal_cfg80211_inform_bss_frame(oal_wiphy_stru *pst_wiphy,
259     oal_ieee80211_channel_stru *pst_ieee80211_channel, oal_ieee80211_mgmt_stru *pst_mgmt, hi_u32 ul_len,
260     hi_s32 l_signal, oal_gfp_enum_uint8 en_ftp)
261 {
262 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
263     return cfg80211_inform_bss_frame(pst_wiphy, pst_ieee80211_channel, pst_mgmt, ul_len, l_signal, en_ftp);
264 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION) || defined(_PRE_HDF_LINUX)
265     hi_unref_param(pst_wiphy);
266     hi_unref_param(pst_ieee80211_channel);
267     hi_unref_param(pst_mgmt);
268     hi_unref_param(ul_len);
269     hi_unref_param(l_signal);
270     hi_unref_param(en_ftp);
271     return NULL;
272 #endif
273 }
274 
275 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION) && !defined(_PRE_HDF_LINUX)
oal_cfg80211_put_bss(oal_wiphy_stru * pst_wiphy,oal_cfg80211_bss_stru * pst_cfg80211_bss)276 hi_void oal_cfg80211_put_bss(oal_wiphy_stru *pst_wiphy, oal_cfg80211_bss_stru *pst_cfg80211_bss)
277 {
278     cfg80211_put_bss(pst_wiphy, pst_cfg80211_bss);
279 }
280 #endif
281 
282 #ifdef __cplusplus
283 #if __cplusplus
284 }
285 #endif
286 #endif
287