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 "oam_ext_if.h"
23 #include "hmac_mgmt_ap.h"
24 #include "hmac_encap_frame.h"
25 #include "hmac_encap_frame_ap.h"
26 #include "hmac_event.h"
27 #include "hmac_mgmt_bss_comm.h"
28 #include "mac_frame.h"
29 #include "hmac_rx_data.h"
30 #include "hmac_uapsd.h"
31 #include "mac_ie.h"
32 #include "mac_user.h"
33 #include "hmac_user.h"
34 #include "hmac_11i.h"
35 #include "hmac_protection.h"
36 #include "hmac_chan_mgmt.h"
37 #include "hmac_fsm.h"
38 #include "hmac_ext_if.h"
39 #include "hmac_config.h"
40 #ifdef _PRE_WLAN_FEATURE_P2P
41 #include "hmac_p2p.h"
42 #endif
43 #include "hmac_blockack.h"
44 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
45 #include "hmac_ext_if.h"
46 #endif
47 #include "oal_ext_if.h"
48
49 #ifdef __cplusplus
50 #if __cplusplus
51 extern "C" {
52 #endif
53 #endif
54
55 /* ****************************************************************************
56 2 全局变量定义
57 **************************************************************************** */
58 static hi_u32 hmac_ap_up_update_sta_sup_rates(hi_u8 *puc_payload, hmac_user_stru *hmac_user,
59 mac_status_code_enum_uint16 *pen_status_code, const hmac_sup_rates_info_stru *sup_rates_info);
60 static hi_u32 hmac_ap_prepare_assoc_req(hmac_user_stru *hmac_user, const hi_u8 *puc_payload, hi_u32 payload_len,
61 hi_u8 mgmt_frm_type);
62 #ifdef _PRE_WLAN_FEATURE_MESH
63 static hi_u32 hmac_mesh_up_rx_confirm_action(const hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
64 hi_u8 *puc_mac_hdr, hi_u8 *puc_payload, hi_u32 payload_len);
65 static hi_u32 hmac_check_open_action_sec_authenticator(const hmac_vap_stru *hmac_vap, hi_u8 *puc_payload,
66 hi_u32 msg_len, const hmac_user_stru *hmac_user, mac_status_code_enum_uint16 *pen_status_code);
67 static hi_u32 hmac_chk_open_action_sec_cap(const mac_vap_stru *mac_vap, const hi_u8 *puc_ie, hi_u8 is_80211i_mode,
68 hi_u8 offset, mac_status_code_enum_uint16 *pen_status_code);
69 #endif
70
71 /* ****************************************************************************
72 3 函数实现
73 **************************************************************************** */
74 #ifdef _PRE_WLAN_FEATURE_PMF
75 /* ****************************************************************************
76 功能描述 : 根据ap sta两端的pmf能力设置这条连接pmf使能状态
77 输入参数 : pst_mac_vap
78 pst_mac_user
79 puc_rsn_ie :存储user rsn能力的指针
80 修改历史 :
81 1.日 期 : 2014年5月20日
82 作 者 : HiSilicon
83 修改内容 : 新生成函数
84 **************************************************************************** */
hmac_set_pmf_cap(mac_user_stru * mac_user,const mac_vap_stru * mac_vap,const hi_u8 * puc_rsn_ie)85 hi_void hmac_set_pmf_cap(mac_user_stru *mac_user, const mac_vap_stru *mac_vap, const hi_u8 *puc_rsn_ie)
86 {
87 hi_u16 us_rsn_capability;
88 hi_u8 ap_mfpc;
89 hi_u8 ap_dot11_rsna_activated;
90 hi_u8 sta_mfpc;
91
92 if (mac_vap->mib_info == HI_NULL) {
93 oam_error_log0(0, 0, "hmac_set_pmf_cap::mib_info null");
94 return;
95 }
96
97 ap_dot11_rsna_activated = mac_vap->mib_info->wlan_mib_privacy.dot11_rsna_activated;
98 us_rsn_capability = mac_get_rsn_capability(puc_rsn_ie);
99 ap_mfpc = mac_vap->mib_info->wlan_mib_privacy.dot11_rsnamfpc;
100 sta_mfpc = (us_rsn_capability & BIT7) ? HI_TRUE : HI_FALSE;
101
102 if ((ap_mfpc == HI_FALSE) || (sta_mfpc == HI_FALSE) || (ap_dot11_rsna_activated == HI_FALSE)) {
103 mac_user_set_pmf_active(mac_user, HI_FALSE);
104 return;
105 } else {
106 mac_user_set_pmf_active(mac_user, HI_TRUE);
107 return;
108 }
109 }
110 #endif
111
112 /* ****************************************************************************
113 功能描述 : AP(驱动)上报去关联某个STA
114 修改历史 :
115 1.日 期 : 2013年9月9日
116 作 者 : HiSilicon
117 修改内容 : 新生成函数
118 **************************************************************************** */
hmac_handle_disconnect_rsp_ap(const hmac_vap_stru * hmac_vap,const hmac_user_stru * hmac_user)119 hi_void hmac_handle_disconnect_rsp_ap(const hmac_vap_stru *hmac_vap, const hmac_user_stru *hmac_user)
120 {
121 hmac_send_event_to_host(hmac_vap->base_vap, (const hi_u8*)(hmac_user->base_user->user_mac_addr),
122 WLAN_MAC_ADDR_LEN, HMAC_HOST_CTX_EVENT_SUB_TYPE_STA_DISCONNECT_AP);
123 return;
124 }
125
126 /* ****************************************************************************
127 功能描述 : AP(驱动)上报新关联上某个STA
128 修改历史 :
129 1.日 期 : 2013年9月9日
130 作 者 : HiSilicon
131 修改内容 : 新生成函数
132 **************************************************************************** */
hmac_handle_connect_rsp_ap(const hmac_vap_stru * hmac_vap,const hmac_user_stru * hmac_user)133 static hi_void hmac_handle_connect_rsp_ap(const hmac_vap_stru *hmac_vap, const hmac_user_stru *hmac_user)
134 {
135 hmac_asoc_user_req_ie_stru asoc_user_req_info;
136
137 /* 上报内核的关联sta发送的关联请求帧ie信息 */
138 asoc_user_req_info.puc_assoc_req_ie_buff = hmac_user->puc_assoc_req_ie_buff;
139 asoc_user_req_info.assoc_req_ie_len = hmac_user->assoc_req_ie_len;
140
141 /* 关联的STA mac地址 */
142 if (memcpy_s((hi_u8 *)asoc_user_req_info.auc_user_mac_addr, WLAN_MAC_ADDR_LEN, hmac_user->base_user->user_mac_addr,
143 WLAN_MAC_ADDR_LEN) != EOK) {
144 oam_error_log0(0, OAM_SF_CFG, "hmac_handle_connect_rsp_ap:: auc_user_mac_addr memcpy_s fail.");
145 return;
146 }
147 hmac_send_event_to_host(hmac_vap->base_vap, (const hi_u8 *)(&asoc_user_req_info),
148 sizeof(hmac_asoc_user_req_ie_stru), HMAC_HOST_CTX_EVENT_SUB_TYPE_STA_CONNECT_AP);
149 }
150
151 #ifdef _PRE_WLAN_FEATURE_MESH
hmac_mesh_sae_auth_proc(const hmac_vap_stru * hmac_vap,oal_netbuf_stru * auth_req)152 hi_void hmac_mesh_sae_auth_proc(const hmac_vap_stru *hmac_vap, oal_netbuf_stru *auth_req)
153 {
154 hi_u8 mac_addr[WLAN_MAC_ADDR_LEN] = {0};
155 hi_u16 auth_seq = mac_get_auth_seq_num(oal_netbuf_header(auth_req)); /* 解析auth transaction number */
156 if (auth_seq > WLAN_AUTH_TRASACTION_NUM_TWO) {
157 oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_AUTH,
158 "{hmac_ap_rx_auth_req::[MESH]auth receive invalid seq, auth seq [%d]}", auth_seq);
159 return;
160 }
161 oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_AUTH,
162 "{hmac_ap_rx_auth_req::[MESH]auth receive valid seq, auth seq [%d]}", auth_seq);
163
164 /* 获取STA的地址 */
165 mac_get_address2(oal_netbuf_header(auth_req), WLAN_MAC_ADDR_LEN, mac_addr, WLAN_MAC_ADDR_LEN);
166 if (mac_addr_is_zero(mac_addr)) {
167 oam_warning_log3(hmac_vap->base_vap->vap_id, OAM_SF_AUTH,
168 "{hmac_ap_rx_auth_req::[MESH]user mac:XX:XX:XX:%02X:%02X:%02X is all 0 and invalid!}", mac_addr[3],
169 mac_addr[4], mac_addr[5]); /* 3 4 5 元素索引 */
170 return;
171 }
172
173 hmac_rx_ctl_stru *rx_ctl = (hmac_rx_ctl_stru *)oal_netbuf_cb(auth_req);
174 hmac_user_stru *hmac_user = mac_vap_get_hmac_user_by_addr(hmac_vap->base_vap, mac_addr, WLAN_MAC_ADDR_LEN);
175
176 if ((hmac_user != HI_NULL) && (hmac_user->base_user->user_asoc_state != MAC_USER_STATE_ASSOC) &&
177 (hmac_user->base_user->is_mesh_user == HI_TRUE)) {
178 /* 更新用户的RSSI统计信息 */
179 hmac_user->base_user->rx_conn_rssi = wlan_rssi_lpf(hmac_user->base_user->rx_conn_rssi, rx_ctl->rssi_dbm);
180 }
181
182 hmac_rx_mgmt_send_to_host(hmac_vap, auth_req);
183
184 oam_warning_log3(hmac_vap->base_vap->vap_id, OAM_SF_AUTH,
185 "{hmac_ap_rx_auth_req::[MESH] report Auth Req to host,user mac:XX:XX:XX:%02X:%02X:%02X.}", mac_addr[3],
186 mac_addr[4], mac_addr[5]); /* 3 4 5 元素索引 */
187 }
188 #endif
189
190 /* ****************************************************************************
191 功能描述 : 处理认证请求帧
192 修改历史 :
193 1.日 期 : 2013年7月1日
194 作 者 : HiSilicon
195 修改内容 : 新生成函数
196 **************************************************************************** */
hmac_ap_rx_auth_req(const hmac_vap_stru * hmac_vap,const oal_netbuf_stru * auth_req)197 static hi_void hmac_ap_rx_auth_req(const hmac_vap_stru *hmac_vap, const oal_netbuf_stru *auth_req)
198 {
199 hi_u8 auc_chtxt[WLAN_CHTXT_SIZE] = {0};
200 hi_u16 auth_alg = mac_get_auth_alg(oal_netbuf_header(auth_req));
201 hi_u8 chtxt_index;
202
203 if (auth_alg == WLAN_WITP_AUTH_SHARED_KEY) {
204 /* 获取challenge text */
205 for (chtxt_index = 0; chtxt_index < WLAN_CHTXT_SIZE; chtxt_index++) {
206 auc_chtxt[chtxt_index] = oal_get_random();
207 }
208 }
209
210 #ifdef _PRE_WLAN_FEATURE_MESH
211 /* MESH VAP时收到认证请求帧且认证类型为SAE 时直接发送给WPA_SUPPLICANT处理,不在此处组Auth Response帧 */
212 if ((hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH) && (auth_alg == WLAN_WITP_AUTH_SAE)) {
213 hmac_mesh_sae_auth_proc(hmac_vap, auth_req);
214 return;
215 }
216 #endif
217
218 /* AP接收到STA发来的认证请求帧组相应的认证响应帧 */
219 oal_netbuf_stru *auth_rsp = (oal_netbuf_stru *)oal_netbuf_alloc(WLAN_MGMT_NETBUF_SIZE, 0, 4); /* align 4 */
220 if (auth_rsp == HI_NULL) {
221 oam_error_log0(hmac_vap->base_vap->vap_id, OAM_SF_AUTH, "{hmac_ap_rx_auth_req::pst_auth_rsp null.}");
222 return;
223 }
224
225 /* 安全编程规则6.6例外(1) 固定长度的结构体进行内存初始化 */
226 memset_s(oal_netbuf_cb(auth_rsp), oal_netbuf_cb_size(), 0, oal_netbuf_cb_size());
227
228 hi_u16 us_auth_rsp_len = hmac_encap_auth_rsp(hmac_vap->base_vap, auth_rsp, auth_req, auc_chtxt, WLAN_CHTXT_SIZE);
229 if (us_auth_rsp_len == 0) {
230 oal_netbuf_free(auth_rsp);
231 oam_error_log0(hmac_vap->base_vap->vap_id, OAM_SF_AUTH, "{hmac_ap_rx_auth_req::auth_rsp_len is 0.}");
232 return;
233 }
234
235 oal_netbuf_put(auth_rsp, us_auth_rsp_len);
236
237 /* 发送认证响应帧之前,将用户的节能状态复位 */
238 hmac_tx_ctl_stru *tx_ctl = (hmac_tx_ctl_stru *)oal_netbuf_cb(auth_rsp);
239 if (hmac_user_get_user_stru(tx_ctl->us_tx_user_idx) != HI_NULL) {
240 hmac_mgmt_reset_psm(hmac_vap->base_vap, tx_ctl->us_tx_user_idx);
241 }
242
243 /* 抛事件给dmac发送认证帧 */
244 hi_u32 ret = hmac_tx_mgmt_send_event(hmac_vap->base_vap, auth_rsp, us_auth_rsp_len);
245 if (ret != HI_SUCCESS) {
246 oal_netbuf_free(auth_rsp);
247 oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_AUTH,
248 "{hmac_ap_rx_auth_req::hmac_tx_mgmt_send_event failed[%d].}", ret);
249 }
250 }
251
252 /* ****************************************************************************
253 功能描述 : 处理接收去认证帧
254 修改历史 :
255 1.日 期 : 2013年7月1日
256 作 者 : HiSilicon
257 修改内容 : 新生成函数
258 **************************************************************************** */
hmac_ap_rx_deauth_req(const hmac_vap_stru * hmac_vap,hi_u8 * puc_mac_hdr,hi_u8 is_protected)259 static hi_u32 hmac_ap_rx_deauth_req(const hmac_vap_stru *hmac_vap, hi_u8 *puc_mac_hdr, hi_u8 is_protected)
260 {
261 hi_u8 *sa_mac_addr = HI_NULL;
262 hi_u8 *da_mac_addr = HI_NULL;
263 hi_u16 us_err_code = *((hi_u16 *)(puc_mac_hdr + MAC_80211_FRAME_LEN));
264
265 mac_rx_get_sa((mac_ieee80211_frame_stru *)puc_mac_hdr, &sa_mac_addr);
266
267 /* 增加接收到去认证帧时的维测信息 */
268 oam_warning_log3(0, OAM_SF_AUTH, "{aput rx deauth frame, reason code = %d, sa[XX:XX:XX:XX:%X:%X]}", us_err_code,
269 sa_mac_addr[4], sa_mac_addr[5]); /* 4 5MAC地址最后2字节 */
270
271 hmac_user_stru *hmac_user = mac_vap_get_hmac_user_by_addr(hmac_vap->base_vap, sa_mac_addr, WLAN_MAC_ADDR_LEN);
272 if (hmac_user == HI_NULL) {
273 oam_warning_log0(hmac_vap->base_vap->vap_id, OAM_SF_AUTH, "{aput rx deauth frame, pst_hmac_user null.}");
274 return HI_FAIL;
275 }
276
277 #ifdef _PRE_WLAN_FEATURE_PMF
278 /* 检查是否需要发送SA query request */
279 if ((hmac_user->base_user->user_asoc_state == MAC_USER_STATE_ASSOC) &&
280 (hmac_pmf_check_err_code(hmac_user->base_user, is_protected, puc_mac_hdr) == HI_SUCCESS)) {
281 /* 在关联状态下收到未加密的ReasonCode 6/7需要开启SA Query流程 */
282 hi_u32 ret = hmac_start_sa_query(hmac_vap->base_vap, hmac_user, hmac_user->base_user->cap_info.pmf_active);
283 if (ret != HI_SUCCESS) {
284 return HI_ERR_CODE_PMF_SA_QUERY_START_FAIL;
285 }
286 return HI_SUCCESS;
287 }
288 #endif
289
290 /* 如果该用户的管理帧加密属性不一致,丢弃该报文 */
291 mac_rx_get_da((mac_ieee80211_frame_stru *)puc_mac_hdr, &da_mac_addr);
292 if ((HI_TRUE != ether_is_multicast(da_mac_addr)) && (is_protected != hmac_user->base_user->cap_info.pmf_active)) {
293 oam_error_log2(hmac_vap->base_vap->vap_id, OAM_SF_AUTH, "{hmac_ap_rx_deauth_req::PMF check failed %d %d.}",
294 is_protected, hmac_user->base_user->cap_info.pmf_active);
295 return HI_FAIL;
296 }
297 #ifdef _PRE_WLAN_FEATURE_MESH
298 /* 当源地址指向一个Mesh类型的User时,有可能收到Deauth帧,同样上报并删除用户即可 */
299 if ((hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH) && (hmac_user->base_user->is_mesh_user == HI_TRUE)) {
300 oam_warning_log4(hmac_vap->base_vap->vap_id, OAM_SF_AUTH,
301 "{meshut rx deauth frame [mesh user], reason code = %d, sa[XX:XX:XX:%X:%X:%X]}", us_err_code,
302 sa_mac_addr[3], sa_mac_addr[4], sa_mac_addr[5]); /* 3 4 5 元素索引 */
303
304 hmac_handle_close_peer_mesh(hmac_vap, sa_mac_addr, WLAN_MAC_ADDR_LEN, HMAC_REPORT_DEAUTH,
305 DMAC_DISASOC_MISC_KICKUSER);
306 } else {
307 #endif
308 /* 抛事件上报内核,已经去关联某个STA */
309 hmac_handle_disconnect_rsp_ap(hmac_vap, hmac_user);
310 hmac_user_del(hmac_vap->base_vap, hmac_user);
311 #ifdef _PRE_WLAN_FEATURE_MESH
312 }
313 #endif
314 return HI_SUCCESS;
315 }
316
317 /* ****************************************************************************
318 功能描述 : 按一定顺序将user中速率重新排序
319 修改历史 :
320 1.日 期 : 2013年7月9日
321 作 者 : HiSilicon
322 修改内容 : 新生成函数
323 **************************************************************************** */
hmac_user_sort_op_rates(hmac_user_stru * hmac_user)324 static hi_void hmac_user_sort_op_rates(hmac_user_stru *hmac_user)
325 {
326 hi_u8 loop;
327 hi_u8 num_rates;
328 hi_u8 min_rate;
329 hi_u8 temp_rate; /* 临时速率,用于数据交换 */
330 hi_u8 index;
331 hi_u8 temp_index; /* 临时索引,用于数据交换 */
332
333 num_rates = hmac_user->op_rates.rs_nrates;
334
335 for (loop = 0; loop < num_rates; loop++) {
336 /* 记录当前速率为最小速率 */
337 min_rate = (hmac_user->op_rates.auc_rs_rates[loop] & 0x7F);
338 temp_index = loop;
339
340 /* 依次查找最小速率 */
341 for (index = loop + 1; index < num_rates; index++) {
342 /* 记录的最小速率大于如果当前速率 */
343 if (min_rate > (hmac_user->op_rates.auc_rs_rates[index] & 0x7F)) {
344 /* 更新最小速率 */
345 min_rate = (hmac_user->op_rates.auc_rs_rates[index] & 0x7F);
346 temp_index = index;
347 }
348 }
349
350 temp_rate = hmac_user->op_rates.auc_rs_rates[loop];
351 hmac_user->op_rates.auc_rs_rates[loop] = hmac_user->op_rates.auc_rs_rates[temp_index];
352 hmac_user->op_rates.auc_rs_rates[temp_index] = temp_rate;
353 }
354 }
355
356 /* ****************************************************************************
357 功能描述 : AP侧设置STA的能力信息
358 修改历史 :
359 1.日 期 : 2013年7月3日
360 作 者 : HiSilicon
361 修改内容 : 新生成函数
362 2.日 期 : 2013年7月8日
363 作 者 : HiSilicon
364 修改内容 : 添加函数检查内容
365 **************************************************************************** */
hmac_ap_up_update_sta_cap_info(const hmac_vap_stru * hmac_vap,hi_u16 us_cap_info,const hmac_user_stru * hmac_user,mac_status_code_enum_uint16 * pen_status_code)366 static hi_u8 hmac_ap_up_update_sta_cap_info(const hmac_vap_stru *hmac_vap, hi_u16 us_cap_info,
367 const hmac_user_stru *hmac_user, mac_status_code_enum_uint16 *pen_status_code)
368 {
369 mac_vap_stru *mac_vap = HI_NULL;
370 hi_u8 ret;
371 mac_cap_info_stru *cap_info = (mac_cap_info_stru *)(&us_cap_info);
372
373 mac_vap = hmac_vap->base_vap;
374 /* check bss capability info MAC,忽略MAC能力不匹配的STA */
375 ret = hmac_check_bss_cap_info(us_cap_info, mac_vap);
376 if (ret != HI_TRUE) {
377 oam_error_log1(hmac_vap->base_vap->vap_id, OAM_SF_ANY,
378 "{hmac_ap_up_update_sta_cap_info::hmac_check_bss_cap_info failed[%d].}", ret);
379 *pen_status_code = MAC_UNSUP_CAP;
380 return HI_FALSE;
381 }
382
383 /* 如果以上各能力信息均满足关联要求,则继续处理其他能力信息 */
384 mac_vap_check_bss_cap_info_phy_ap(us_cap_info, mac_vap);
385
386 if ((0 == cap_info->privacy) &&
387 (hmac_user->base_user->key_info.cipher_type != WLAN_80211_CIPHER_SUITE_NO_ENCRYP)) {
388 oam_warning_log2(hmac_vap->base_vap->vap_id, OAM_SF_ANY,
389 "{hmac_ap_up_update_sta_cap_info::Encrypt not match,cap privacy[%d],user_cipher_type[%d].}",
390 cap_info->privacy, hmac_user->base_user->key_info.cipher_type);
391 *pen_status_code = MAC_UNSPEC_FAIL;
392 return HI_FALSE;
393 }
394
395 return HI_TRUE;
396 }
397
398 #ifdef _PRE_WLAN_FEATURE_MESH
399 /* ****************************************************************************
400 功能描述 : 检查更新关联STA的速率信息(mesh add sta接口适配)
401 返 回 值 : hi_u32
402 修改历史 :
403 1.日 期 : 2019年1月17日
404 作 者 : HiSilicon
405 修改内容 : 新生成函数
406 **************************************************************************** */
hmac_mesh_update_sta_sup_rates(hi_u8 * puc_sup_rates,hi_u8 sup_rates_len,hmac_user_stru * hmac_user,mac_status_code_enum_uint16 * pen_status_code)407 hi_u32 hmac_mesh_update_sta_sup_rates(hi_u8 *puc_sup_rates, hi_u8 sup_rates_len, hmac_user_stru *hmac_user,
408 mac_status_code_enum_uint16 *pen_status_code)
409 {
410 mac_user_stru *mac_user = HI_NULL;
411 mac_vap_stru *mac_vap = HI_NULL;
412 hi_u8 puc_sup_rates_set[MAC_MAX_SUPRATES] = {0};
413 hi_u32 loop;
414
415 mac_user = hmac_user->base_user;
416 mac_vap = mac_vap_get_vap_stru(mac_user->vap_id);
417 if (mac_vap == HI_NULL) {
418 *pen_status_code = MAC_UNSUP_RATE;
419 oam_error_log0(mac_user->vap_id, OAM_SF_ANY, "{hmac_mesh_update_sta_sup_rates::pst_mac_vap null.}");
420 return HI_ERR_CODE_PTR_NULL;
421 }
422
423 if (sup_rates_len == 0) {
424 *pen_status_code = MAC_UNSUP_RATE;
425 oam_error_log0(mac_user->vap_id, OAM_SF_ANY,
426 "{hmac_mesh_update_sta_sup_rates::the sta's rates are not supported.}");
427 return HI_FAIL;
428 }
429
430 if (puc_sup_rates != HI_NULL) {
431 if (memcpy_s(puc_sup_rates_set, sup_rates_len, puc_sup_rates, sup_rates_len) != EOK) {
432 oam_error_log2(mac_user->vap_id, OAM_SF_ANY,
433 "{hmac_mesh_update_sta_sup_rates::memcpy_s fail, puc_sup_rates_set[%p], puc_sup_rates[%p].}",
434 (uintptr_t)puc_sup_rates_set, (uintptr_t)puc_sup_rates);
435 return HI_FAIL;
436 }
437 }
438
439 if (sup_rates_len > MAC_MAX_SUPRATES) {
440 oam_warning_log1(0, OAM_SF_ANY, "hmac_mesh_update_sta_sup_rates: ul_sup_rates_len error: %d", sup_rates_len);
441 sup_rates_len = MAC_MAX_SUPRATES;
442 }
443
444 for (loop = 0; loop < sup_rates_len; loop++) {
445 /* 保存对应的速率到USER中 */
446 hmac_user->op_rates.auc_rs_rates[loop] = puc_sup_rates_set[loop] & 0x7F;
447 }
448 hmac_user->op_rates.rs_nrates = sup_rates_len;
449
450 /* 按一定顺序重新排列速率 */
451 hmac_user_sort_op_rates(hmac_user);
452
453 /* ******************************************************************
454 如果STA不支持所有基本速率返回不支持速率的错误码
455 ****************************************************************** */
456 hmac_check_sta_base_rate((hi_u8 *)hmac_user, pen_status_code);
457 return HI_SUCCESS;
458 }
459
460 /* ****************************************************************************
461 功能描述 :通知WPA发送Mesh Close Peer,与对端断开连接。
462 输入参数 : [1]hmac_vap
463 [2]puc_mac_addr,
464 [3]us_disasoc_reason_code
465 [4]us_dmac_reason_code
466 返 回 值 :hi_u32
467 **************************************************************************** */
hmac_handle_close_peer_mesh(const hmac_vap_stru * hmac_vap,const hi_u8 * mac_addr,hi_u8 mac_addr_len,hi_u16 us_disasoc_reason_code,hi_u16 us_dmac_reason_code)468 hi_u32 hmac_handle_close_peer_mesh(const hmac_vap_stru *hmac_vap, const hi_u8 *mac_addr, hi_u8 mac_addr_len,
469 hi_u16 us_disasoc_reason_code, hi_u16 us_dmac_reason_code)
470 {
471 hi_u8 data[WLAN_MAC_ADDR_LEN + WLAN_MAC_ADDR_LEN] = {0};
472
473 /* 去关联的STA mac地址 */
474 if (mac_addr != HI_NULL) {
475 if (memcpy_s((hi_u8 *)data, WLAN_MAC_ADDR_LEN, mac_addr, mac_addr_len) != EOK) {
476 oam_error_log0(0, OAM_SF_CFG, "hmac_handle_close_peer_mesh:: puc_mac_addr memcpy_s fail.");
477 return HI_FAIL;
478 }
479 }
480 /* 填充断联原因 */
481 /* 事件payload填写的是错误码 */
482 *((hi_u32 *)(data + WLAN_MAC_ADDR_LEN)) =
483 ((us_disasoc_reason_code & 0x0000ffff) | ((us_dmac_reason_code << 16) & 0xffff0000)); /* 16:左移 */
484
485 return hmac_send_event_to_host(hmac_vap->base_vap, (const hi_u8 *)data, WLAN_MAC_ADDR_LEN + sizeof(hi_u32),
486 HMAC_HOST_CTX_EVENT_SUB_TYPE_PEER_CLOSE_MESH);
487 }
488 #endif
489
hmac_resort_rates_info_cyc(hmac_user_stru * hmac_user,const hi_u8 * puc_ext_sup_rates_ie,hi_u8 uc_num_rates,hi_u8 * uc_num_ex_rates,hi_u16 us_msg_idx_ex)490 hi_void hmac_resort_rates_info_cyc(hmac_user_stru *hmac_user, const hi_u8 *puc_ext_sup_rates_ie, hi_u8 uc_num_rates,
491 hi_u8 *uc_num_ex_rates, hi_u16 us_msg_idx_ex)
492 {
493 hi_u32 loop;
494
495 /* 超出支持速率总个数,扩展速率集进行修正 */
496 if (uc_num_rates + *uc_num_ex_rates > WLAN_MAX_SUPP_RATES) {
497 *uc_num_ex_rates = WLAN_MAX_SUPP_RATES - uc_num_rates;
498 }
499
500 if (uc_num_rates < WLAN_MAX_SUPP_RATES) {
501 for (loop = 0; loop < *uc_num_ex_rates; loop++) {
502 hmac_user->op_rates.auc_rs_rates[uc_num_rates + loop] = puc_ext_sup_rates_ie[us_msg_idx_ex + loop] & 0x7F;
503 }
504 }
505 }
506
hmac_resort_rates_info(hmac_user_stru * hmac_user,const hi_u8 * puc_ext_sup_rates_ie,hi_u8 uc_num_rates)507 hi_void hmac_resort_rates_info(hmac_user_stru *hmac_user, const hi_u8 *puc_ext_sup_rates_ie, hi_u8 uc_num_rates)
508 {
509 hi_u16 us_msg_idx_ex = 0;
510 hi_u8 temp_rate;
511 hi_u8 uc_num_ex_rates = 0;
512 mac_vap_stru *mac_vap = HI_NULL;
513
514 mac_vap = mac_vap_get_vap_stru(hmac_user->base_user->vap_id);
515 if (mac_vap == HI_NULL) {
516 return;
517 }
518 if (puc_ext_sup_rates_ie == HI_NULL) {
519 if (mac_vap->channel.band == WLAN_BAND_2G) {
520 oam_warning_log0(0, OAM_SF_ANY, "{hmac_ap_up_update_sta_user::puc_ext_sup_rates_ie null.}");
521 }
522 } else {
523 uc_num_ex_rates = puc_ext_sup_rates_ie[1];
524 us_msg_idx_ex += MAC_IE_HDR_LEN;
525 /* 只有11g混合模式或者更高协议版本才支持ERP */
526 if ((mac_vap->protocol > WLAN_LEGACY_11G_MODE) &&
527 (uc_num_ex_rates <= WLAN_MAX_SUPP_RATES && uc_num_ex_rates >= MAC_MIN_XRATE_LEN)) {
528 hmac_resort_rates_info_cyc(hmac_user, puc_ext_sup_rates_ie, uc_num_rates, &uc_num_ex_rates, us_msg_idx_ex);
529 } else {
530 uc_num_ex_rates = 0;
531 }
532 }
533
534 /* 更新STA支持的速率个数 */
535 hmac_user->op_rates.rs_nrates = uc_num_rates + uc_num_ex_rates;
536
537 /* 按一定顺序重新排列速率 */
538 hmac_user_sort_op_rates(hmac_user);
539
540 /* ******************************************************************
541 重排11g模式的可操作速率,使11b速率都聚集在11a之前
542 802.11a 速率:6、9、12、18、24、36、48、54Mbps
543 802.11b 速率:1、2、5.5、11Mbps
544 由于按由小到大排序后802.11b中的速率11Mbps在802.11a中,下标为5
545 所以从第五位进行检验并排序。
546 ****************************************************************** */
547 if (hmac_user->op_rates.rs_nrates == MAC_DATARATES_PHY_80211G_NUM) { /* 11g_compatibility mode */
548 if ((hmac_user->op_rates.auc_rs_rates[5] & 0x7F) == 0x16) { /* 5 元素索引 11Mbps */
549 temp_rate = hmac_user->op_rates.auc_rs_rates[5];
550 hmac_user->op_rates.auc_rs_rates[5] = hmac_user->op_rates.auc_rs_rates[4]; /* 5 4 元素索引 */
551 hmac_user->op_rates.auc_rs_rates[4] = hmac_user->op_rates.auc_rs_rates[3]; /* 4 3 元素索引 */
552 hmac_user->op_rates.auc_rs_rates[3] = temp_rate; /* 3 元素索引 */
553 }
554 }
555 }
556
557 /* ****************************************************************************
558 功能描述 : 检查更新AP侧关联STA的速率信息
559 输入参数 : hi_u8 *puc_payload -- 关联帧帧体内容指针
560 hi_u32 ul_msg_len -- 关联帧帧体长度
561 hmac_user_stru *pst_hmac_user -- 关联用户的结构体指针
562 hi_u16 *pus_msg_idx -- 关联帧帧体偏移索引
563 输出参数 : wlan_status_code_enum_uint16 *pen_status_code-- 关联状态码
564 hi_u8 *puc_num_rates -- 关联用户的速率个数
565 hi_u16 *pus_msg_idx -- 关联帧帧体偏移索引
566 返 回 值 : hi_u32
567 修改历史 :
568 1.日 期 : 2013年7月10日
569 作 者 : HiSilicon
570 修改内容 : 新生成函数
571 **************************************************************************** */
hmac_ap_up_update_sta_sup_rates(hi_u8 * puc_payload,hmac_user_stru * hmac_user,mac_status_code_enum_uint16 * pen_status_code,const hmac_sup_rates_info_stru * sup_rates_info)572 static hi_u32 hmac_ap_up_update_sta_sup_rates(hi_u8 *puc_payload, hmac_user_stru *hmac_user,
573 mac_status_code_enum_uint16 *pen_status_code, const hmac_sup_rates_info_stru *sup_rates_info)
574 {
575 hi_u8 uc_num_rates = 0;
576 hi_u32 loop;
577 mac_user_stru *mac_user = HI_NULL;
578 mac_vap_stru *mac_vap = HI_NULL;
579 hi_u8 *puc_sup_rates_ie = HI_NULL;
580 hi_u8 *puc_ext_sup_rates_ie = HI_NULL;
581 hi_u16 us_msg_idx = 0;
582
583 mac_user = hmac_user->base_user;
584 mac_vap = mac_vap_get_vap_stru(mac_user->vap_id);
585 if (mac_vap == HI_NULL) {
586 *pen_status_code = MAC_UNSUP_RATE;
587 oam_error_log0(mac_user->vap_id, OAM_SF_ANY, "{hmac_ap_up_update_sta_sup_rates::pst_mac_vap null.}");
588 return HI_ERR_CODE_PTR_NULL;
589 }
590
591 if (sup_rates_info->msg_len > sup_rates_info->us_offset) {
592 puc_sup_rates_ie = mac_find_ie(MAC_EID_RATES, puc_payload + sup_rates_info->us_offset,
593 (sup_rates_info->msg_len - sup_rates_info->us_offset));
594 }
595 if (puc_sup_rates_ie == HI_NULL) {
596 *pen_status_code = MAC_UNSUP_RATE;
597 oam_error_log0(mac_user->vap_id, OAM_SF_ANY, "{hmac_ap_up_update_sta_user::puc_ie null.}");
598 return HI_ERR_CODE_PTR_NULL;
599 } else {
600 uc_num_rates = puc_sup_rates_ie[1];
601
602 /* 如果速率个数为0或超过最大支持速率 ,直接返回失败 */
603 if (uc_num_rates == 0 || uc_num_rates > WLAN_MAX_SUPP_RATES) {
604 *pen_status_code = MAC_UNSUP_RATE;
605 *(sup_rates_info->pus_msg_idx) = us_msg_idx;
606 oam_error_log0(mac_user->vap_id, OAM_SF_ANY,
607 "{hmac_ap_up_update_sta_sup_rates::the sta's rates are not supported.}");
608 return HI_FAIL;
609 }
610
611 us_msg_idx += MAC_IE_HDR_LEN;
612
613 for (loop = 0; loop < uc_num_rates; loop++) {
614 /* 保存对应的速率到USER中 */
615 hmac_user->op_rates.auc_rs_rates[loop] = puc_sup_rates_ie[us_msg_idx + loop] & 0x7F;
616 }
617
618 us_msg_idx += uc_num_rates;
619 hmac_user->op_rates.rs_nrates = uc_num_rates;
620 }
621
622 if (sup_rates_info->msg_len > sup_rates_info->us_offset) {
623 /* 如果存在扩展速率 */
624 puc_ext_sup_rates_ie = mac_find_ie(MAC_EID_XRATES, puc_payload + sup_rates_info->us_offset,
625 (sup_rates_info->msg_len - sup_rates_info->us_offset));
626 }
627
628 hmac_resort_rates_info(hmac_user, puc_ext_sup_rates_ie, uc_num_rates);
629
630 /* ******************************************************************
631 如果STA不支持所有基本速率返回不支持速率的错误码
632 **************************************************************** */
633 hmac_check_sta_base_rate((hi_u8 *)hmac_user, pen_status_code);
634
635 *(sup_rates_info->pus_msg_idx) = us_msg_idx;
636 return HI_SUCCESS;
637 }
638
639 #if defined(_PRE_WLAN_FEATURE_WPA) || defined(_PRE_WLAN_FEATURE_WPA2)
640 /* ****************************************************************************
641 功能描述 : AP 检测STA 关联请求帧中的安全相关公共信息
642 输入参数 : [1]mac_vap
643 [2]puc_ie
644 [3]is_80211i_mode
645 [4]offset
646 [5]pen_status_code
647 返 回 值 : static hi_u32
648 **************************************************************************** */
hmac_check_assoc_req_security_cap_common(const mac_vap_stru * mac_vap,const hi_u8 * ie,hi_u8 is_80211i,hi_u8 offset,mac_status_code_enum_uint16 * pen_status_code)649 static hi_u32 hmac_check_assoc_req_security_cap_common(const mac_vap_stru *mac_vap, const hi_u8 *ie, hi_u8 is_80211i,
650 hi_u8 offset, mac_status_code_enum_uint16 *pen_status_code)
651 {
652 wlan_mib_ieee802dot11_stru *mib_info = mac_vap->mib_info;
653 hi_u8 len = 0;
654 hi_u8 auc_oui[MAC_OUI_LEN];
655
656 if (hmac_get_security_oui(is_80211i, auc_oui) != HI_SUCCESS) {
657 *pen_status_code = MAC_UNSUP_RSN_INFO_VER;
658 return HI_FAIL;
659 }
660 /* 检测版本信息 */
661 if (mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_version != hi_makeu16(ie[offset], ie[offset + 1])) {
662 *pen_status_code = MAC_UNSUP_RSN_INFO_VER;
663 oam_error_log1(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_check_assoc_req_security_cap_common::unsup rsn ver=%d.}",
664 hi_makeu16(ie[offset], ie[offset + 1]));
665 return HI_FAIL;
666 }
667 /* 忽略版本信息 */
668 hi_u8 index = offset + 2; /* 2 忽略版本信息 */
669
670 if (memcmp(auc_oui, ie + index, MAC_OUI_LEN) != 0) {
671 oam_warning_log0(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_check_assoc_req_security_cap_common::invalid OUI.}");
672 }
673 index += MAC_OUI_LEN;
674 hi_u8 grp_policy = ie[index++]; /* 获取组播密钥 */
675
676 /* 获取单播加密套件 */
677 hi_u8 pcip_policy = hmac_get_pcip_policy_auth(ie + index, &len);
678 index += len;
679
680 /* 获取认证套件信息 */
681 hi_u8 auth_policy = hmac_get_auth_policy_auth(ie + index, &len);
682
683 /* 成对密钥套件是否为组播密钥套件 */
684 pcip_policy = (pcip_policy == WLAN_80211_CIPHER_SUITE_GROUP_CIPHER) ? grp_policy : pcip_policy;
685
686 /* 检测组播套件 */
687 if (mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_group_cipher != grp_policy) {
688 *pen_status_code = MAC_INVALID_GRP_CIPHER;
689 oam_error_log1(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_check_assoc_req_security_cap_common::grp %d}", grp_policy);
690 return HI_FAIL;
691 }
692 /* 检测单播密钥套件 */
693 if (hmac_check_pcip_policy(mib_info, pcip_policy, is_80211i) != HI_SUCCESS) {
694 *pen_status_code = MAC_INVALID_PW_CIPHER;
695 oam_error_log1(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_check_assoc_req_security_cap_common:pcip%d}", pcip_policy);
696 return HI_FAIL;
697 }
698 /* 检测认证套件 */
699 if (mac_check_auth_policy(mib_info, auth_policy) == HI_FALSE) {
700 *pen_status_code = MAC_INVALID_AKMP_CIPHER;
701 oam_error_log1(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_check_assoc_req_security_cap_common:auth%d}", auth_policy);
702 return HI_FAIL;
703 }
704 /* 禁止单播套件为TKIP, 组播套件为CCMP */
705 if ((grp_policy == WLAN_80211_CIPHER_SUITE_CCMP) && (pcip_policy == WLAN_80211_CIPHER_SUITE_TKIP)) {
706 *pen_status_code = MAC_CIPHER_REJ;
707 oam_error_log0(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_check_assoc_req_security_cap_common::conflict.}");
708 return HI_FAIL;
709 }
710 /* 更新mib 参数 */
711 mib_info->wlan_mib_rsna_cfg.dot11_rsna_group_cipher_requested = grp_policy;
712 mib_info->wlan_mib_rsna_cfg.dot11_rsna_pairwise_cipher_requested = pcip_policy;
713
714 return HI_SUCCESS;
715 }
716
hmac_chk_assoc_req_sec_cap_auth_encry(const mac_vap_stru * mac_vap,mac_status_code_enum_uint16 * pen_status_code,hi_u8 * puc_rsn_ie,hi_u8 * puc_wpa_ie)717 static hi_u32 hmac_chk_assoc_req_sec_cap_auth_encry(const mac_vap_stru *mac_vap,
718 mac_status_code_enum_uint16 *pen_status_code, hi_u8 *puc_rsn_ie, hi_u8 *puc_wpa_ie)
719 {
720 hi_u8 is_80211i_mode = 0;
721 hi_u8 *puc_ie = HI_NULL;
722 hi_u8 index = 0;
723 hi_u8 rsn_found = HI_FALSE; /* AP 接收到的ASSOC REQ帧IE 是否匹配 */
724
725 /* RSNA 或 WPA加密方式处理 */
726 if (mac_vap->cap_flag.wpa2 == HI_TRUE) {
727 if (puc_rsn_ie != HI_NULL) {
728 rsn_found = HI_TRUE;
729 is_80211i_mode = DMAC_RSNA_802_11I;
730
731 /* 略过 IE + LEN */
732 index += 2; /* 2 略过 IE + LEN */
733
734 puc_ie = puc_rsn_ie;
735 }
736 }
737
738 if ((rsn_found == HI_FALSE) && (mac_vap->cap_flag.wpa == HI_TRUE)) {
739 if (puc_wpa_ie != HI_NULL) {
740 rsn_found = HI_TRUE;
741 is_80211i_mode = DMAC_WPA_802_11I;
742
743 /* 略过 IE(1字节) + LEN(1字节) + WPA OUI(4字节) */
744 index += 6; /* 共6个字节 */
745
746 puc_ie = puc_wpa_ie;
747 } else {
748 *pen_status_code = MAC_CIPHER_REJ;
749 return HI_FAIL;
750 }
751 }
752
753 if (((rsn_found == HI_TRUE) && (puc_ie != HI_NULL)) && (hmac_check_assoc_req_security_cap_common(mac_vap, puc_ie,
754 is_80211i_mode, index, pen_status_code) != HI_SUCCESS)) {
755 return HI_FAIL;
756 }
757
758 oam_info_log1(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_chk_assoc_req_sec_cap_auth_encry::is_80211i_mode = %d}",
759 is_80211i_mode);
760 return HI_SUCCESS;
761 }
762
763 /* ****************************************************************************
764 功能描述 : AP 检查接收到的ASOC REQ消息中的SECURITY参数.如出错,则返回对应的错
765 误码
766 输入参数 : [1]hmac_vap
767 [2]puc_mac_hdr
768 [3]puc_payload
769 [4]msg_len
770 [5]hmac_user
771 [6]pen_status_code
772 返 回 值 : static hi_u8
773 **************************************************************************** */
hmac_chk_assoc_req_sec_cap_auth(const hmac_vap_stru * vap,const hi_u8 * hdr,hi_u8 * payload,hi_u32 len,const hmac_user_stru * user,mac_status_code_enum_uint16 * status)774 static hi_u32 hmac_chk_assoc_req_sec_cap_auth(const hmac_vap_stru *vap, const hi_u8 *hdr, hi_u8 *payload, hi_u32 len,
775 const hmac_user_stru *user, mac_status_code_enum_uint16 *status)
776 {
777 hi_u8 pcip_policy = WLAN_80211_CIPHER_SUITE_NO_ENCRYP;
778 hi_u8 grp_policy = WLAN_80211_CIPHER_SUITE_NO_ENCRYP;
779 hi_u8 *puc_rsn_ie = HI_NULL;
780 hi_u8 *puc_wpa_ie = HI_NULL;
781
782 mac_vap_stru *mac_vap = vap->base_vap;
783 wlan_mib_ieee802dot11_stru *mib_info = mac_vap->mib_info;
784
785 mib_info->wlan_mib_rsna_cfg.dot11_rsna_group_cipher_requested = 0;
786 mib_info->wlan_mib_rsna_cfg.dot11_rsna_pairwise_cipher_requested = 0;
787
788 if (mib_info->wlan_mib_privacy.dot11_rsna_activated != HI_TRUE) {
789 oam_info_log0(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_chk_assoc_req_sec_cap_auth::dot11RSNAActivated = FALSE}");
790 return HI_SUCCESS;
791 }
792
793 hi_u8 offset = MAC_CAP_INFO_LEN + MAC_LIS_INTERVAL_IE_LEN;
794 if (mac_get_frame_sub_type(hdr) == WLAN_FC0_SUBTYPE_REASSOC_REQ) {
795 offset += OAL_MAC_ADDR_LEN;
796 }
797 if (len > offset) {
798 /* 获取RSNA和WPA IE信息 */
799 puc_rsn_ie = mac_find_ie(MAC_EID_RSN, payload + offset, (len - offset));
800 puc_wpa_ie = mac_find_vendor_ie(MAC_WLAN_OUI_MICROSOFT, MAC_OUITYPE_WPA, payload + offset,
801 (hi_s32)(len - offset));
802 }
803
804 if ((puc_rsn_ie == HI_NULL) && (puc_wpa_ie == HI_NULL)) {
805 /* 加密方式不是WPA/WPA2, 则判断是否为WEP */
806 grp_policy = mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_group_cipher;
807 if (is_wep_cipher(grp_policy)) {
808 mib_info->wlan_mib_rsna_cfg.dot11_rsna_pairwise_cipher_requested = grp_policy;
809 } else if (vap->wps_active == HI_TRUE) {
810 mac_user_init_key(user->base_user);
811 return HI_SUCCESS;
812 } else {
813 *status = MAC_UNSPEC_FAIL;
814 oam_error_log0(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_chk_assoc_req_sec_cap_auth:WPA/WPA2}");
815 return HI_FAIL;
816 }
817 } else {
818 if (hmac_chk_assoc_req_sec_cap_auth_encry(mac_vap, status, puc_rsn_ie, puc_wpa_ie) != HI_SUCCESS) {
819 return HI_FAIL;
820 }
821 }
822
823 if (*status == MAC_SUCCESSFUL_STATUSCODE) {
824 /* 检测出来的这个硬件加密方式应该保存到 mac_user -> en_cipher_type 中 */
825 mac_user_stru *mac_user = user->base_user;
826 /* 保存用户的加密方式 */
827 mac_user->key_info.cipher_type = pcip_policy;
828 }
829 oam_info_log2(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_chk_assoc_req_sec_cap_auth::"
830 "group=%d, pairwise=%d, auth=%d}", grp_policy, pcip_policy);
831
832 return HI_SUCCESS;
833 }
834 #endif /* (_PRE_WLAN_FEATURE_WPA) || defined(_PRE_WLAN_FEATURE_WPA2) */
835
836 /* ****************************************************************************
837 功能描述 : 查看sta是否属于erp站点
838 输入参数 : mac_user_stru pst_mac_user
839 返 回 值 : HI_TRUE: sta为erp站点
840 HI_FALSE:sta为非erp站点(11b站点)
841 修改历史 :
842 1.日 期 : 2014年3月26日
843 作 者 : HiSilicon
844 修改内容 : 新生成函数
845 **************************************************************************** */
hmac_is_erp_sta(const hmac_user_stru * hmac_user)846 static hi_u8 hmac_is_erp_sta(const hmac_user_stru *hmac_user)
847 {
848 hi_u32 loop;
849 hi_u8 is_erp_sta;
850
851 /* 确认是否是erp 站点 */
852 if (hmac_user->op_rates.rs_nrates <= MAC_NUM_DR_802_11B) {
853 is_erp_sta = HI_FALSE;
854 for (loop = 0; loop < hmac_user->op_rates.rs_nrates; loop++) {
855 /* 如果支持速率不在11b的1M, 2M, 5.5M, 11M范围内,则说明站点为支持ERP的站点 */
856 if (((hmac_user->op_rates.auc_rs_rates[loop] & 0x7F) != 0x2) &&
857 ((hmac_user->op_rates.auc_rs_rates[loop] & 0x7F) != 0x4) &&
858 ((hmac_user->op_rates.auc_rs_rates[loop] & 0x7F) != 0xb) &&
859 ((hmac_user->op_rates.auc_rs_rates[loop] & 0x7F) != 0x16)) {
860 is_erp_sta = HI_TRUE;
861 break;
862 }
863 }
864 } else {
865 is_erp_sta = HI_TRUE;
866 }
867
868 return is_erp_sta;
869 }
870
871 /* ****************************************************************************
872 功能描述 : AP处理assoc req 中的capability info
873 输入参数 : pst_hmac_vap : hmac vap结构体指针
874 pst_hmac_user : hmac user结构体指针
875 us_cap_info : 帧体中cap info信息
876 返 回 值 : hi_u32
877 修改历史 :
878 1.日 期 : 2013年7月9日
879 作 者 : HiSilicon
880 修改内容 : 新生成函数
881 **************************************************************************** */
hmac_ap_up_update_legacy_capability(const hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,hi_u16 us_cap_info)882 static hi_void hmac_ap_up_update_legacy_capability(const hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
883 hi_u16 us_cap_info)
884 {
885 mac_protection_stru *protection = &(hmac_vap->base_vap->protection);
886 mac_user_stru *mac_user = hmac_user->base_user;
887
888 /* 如果STA不支持short slot */
889 if ((us_cap_info & MAC_CAP_SHORT_SLOT) != MAC_CAP_SHORT_SLOT) {
890 /* 如果STA之前没有关联, 或者之前以支持short slot站点身份关联,需要update处理 */
891 if ((mac_user->user_asoc_state != MAC_USER_STATE_ASSOC) ||
892 (hmac_user->hmac_cap_info.short_slot_time == HI_TRUE)) {
893 protection->sta_no_short_slot_num++;
894 }
895
896 hmac_user->hmac_cap_info.short_slot_time = HI_FALSE;
897 } else {
898 /* 如果STA以不支持short slot站点身份关联,需要update处理 */
899 if ((mac_user->user_asoc_state == MAC_USER_STATE_ASSOC) &&
900 (hmac_user->hmac_cap_info.short_slot_time == HI_FALSE) && (protection->sta_no_short_slot_num != 0)) {
901 protection->sta_no_short_slot_num--;
902 }
903
904 hmac_user->hmac_cap_info.short_slot_time = HI_TRUE;
905 }
906
907 hmac_user->user_stats_flag.no_short_slot_stats_flag = HI_TRUE;
908
909 /* 如果STA不支持short preamble */
910 if ((us_cap_info & MAC_CAP_SHORT_PREAMBLE) != MAC_CAP_SHORT_PREAMBLE) {
911 /* 如果STA之前没有关联, 或者之前以支持short preamble站点身份关联,需要update处理 */
912 if ((mac_user->user_asoc_state != MAC_USER_STATE_ASSOC) ||
913 (hmac_user->hmac_cap_info.short_preamble == HI_TRUE)) {
914 protection->sta_no_short_preamble_num++;
915 }
916
917 hmac_user->hmac_cap_info.short_preamble = HI_FALSE;
918 } else {
919 /* 如果STA之前以不支持short preamble站点身份关联,需要update处理 */
920 if ((mac_user->user_asoc_state == MAC_USER_STATE_ASSOC) &&
921 (hmac_user->hmac_cap_info.short_preamble == HI_FALSE) && (protection->sta_no_short_preamble_num != 0)) {
922 protection->sta_no_short_preamble_num--;
923 }
924
925 hmac_user->hmac_cap_info.short_preamble = HI_TRUE;
926 }
927
928 hmac_user->user_stats_flag.no_short_preamble_stats_flag = HI_TRUE;
929
930 /* 确定user是否是erp站点 */
931 hi_u8 is_erp_sta = hmac_is_erp_sta(hmac_user);
932 if (is_erp_sta == HI_FALSE) {
933 /* 如果STA之前没有关联, 或者之前以支持ERP站点身份关联,需要update处理 */
934 if ((mac_user->user_asoc_state != MAC_USER_STATE_ASSOC) || (hmac_user->hmac_cap_info.erp == HI_TRUE)) {
935 protection->sta_non_erp_num++;
936 }
937
938 hmac_user->hmac_cap_info.erp = HI_FALSE;
939 } else {
940 /* 如果STA之前以不支持ERP身份站点关联,需要update处理 */
941 if ((mac_user->user_asoc_state == MAC_USER_STATE_ASSOC) && (hmac_user->hmac_cap_info.erp == HI_FALSE) &&
942 (protection->sta_non_erp_num != 0)) {
943 protection->sta_non_erp_num--;
944 }
945
946 hmac_user->hmac_cap_info.erp = HI_TRUE;
947 }
948
949 hmac_user->user_stats_flag.no_erp_stats_flag = HI_TRUE;
950
951 hi_u8 spectrum_mgmt = ((us_cap_info & MAC_CAP_SPECTRUM_MGMT) != MAC_CAP_SPECTRUM_MGMT) ? HI_FALSE : HI_TRUE;
952 mac_user_set_spectrum_mgmt(hmac_user->base_user, spectrum_mgmt);
953 }
954
955 #ifdef _PRE_WLAN_FEATURE_UAPSD
956 /* ****************************************************************************
957 功能描述 : 更新ASOC关联实体中的UAPSD信息
958 修改历史 :
959 1.日 期 : 2013年7月9日
960 作 者 : HiSilicon
961 修改内容 : 新生成函数
962 **************************************************************************** */
hmac_ap_up_update_asoc_entry_prot(const hi_u8 * puc_mac_hdr,hi_u8 sub_type,hi_u32 msg_len,const hmac_user_stru * hmac_user)963 static hi_void hmac_ap_up_update_asoc_entry_prot(const hi_u8 *puc_mac_hdr, hi_u8 sub_type, hi_u32 msg_len,
964 const hmac_user_stru *hmac_user)
965 {
966 /* WMM */
967 hmac_uapsd_update_user_para(puc_mac_hdr, sub_type, msg_len, hmac_user);
968 }
969 #endif
970
hmac_sta_ssid_and_sup_rate_proc(const hmac_update_sta_user_info_stru * update_sta_user,hmac_user_stru * hmac_user,mac_status_code_enum_uint16 * status_code,mac_vap_stru * mac_vap,hi_u16 * msg_idx)971 hi_u32 hmac_sta_ssid_and_sup_rate_proc(const hmac_update_sta_user_info_stru *update_sta_user,
972 hmac_user_stru *hmac_user, mac_status_code_enum_uint16 *status_code, mac_vap_stru *mac_vap, hi_u16 *msg_idx)
973 {
974 mac_cfg_ssid_param_stru cfg_ssid;
975 hmac_sup_rates_info_stru sup_rates;
976 hi_u16 us_rate_len = 0;
977
978 #ifdef _PRE_WLAN_FEATURE_MESH
979 /* Mesh关连帧不带SSID */
980 if ((mac_vap->vap_mode != WLAN_VAP_MODE_MESH) ||
981 (mac_get_frame_sub_type(update_sta_user->puc_mac_hdr) != WLAN_FC0_SUBTYPE_ACTION)) {
982 #endif
983 /* 判断SSID,长度或内容不一致时,认为是SSID不一致 */
984 if (update_sta_user->puc_payload[*msg_idx] == MAC_EID_SSID) {
985 hi_u16 us_ssid_len = 0;
986
987 cfg_ssid.ssid_len = 0;
988
989 hmac_config_get_ssid(mac_vap, &us_ssid_len, (hi_u8 *)(&cfg_ssid));
990
991 if (cfg_ssid.ssid_len != update_sta_user->puc_payload[(*msg_idx) + 1]) {
992 *status_code = MAC_UNSPEC_FAIL;
993 oam_warning_log1(mac_vap->vap_id, OAM_SF_ASSOC,
994 "{hmac_ap_up_update_sta_user:AP refuse STA assoc,ssid len Err,status_code=%d}", *status_code);
995 return HI_FAIL;
996 }
997
998 if (memcmp(&(update_sta_user->puc_payload[(*msg_idx) + 2]), cfg_ssid.ac_ssid, /* 2 索引偏置 */
999 cfg_ssid.ssid_len) != 0) {
1000 *status_code = MAC_UNSPEC_FAIL;
1001 oam_warning_log1(mac_vap->vap_id, OAM_SF_ASSOC,
1002 "{hmac_ap_up_update_sta_user::AP refuse STA assoc,ssid mismatch,status_code=%d}", *status_code);
1003 return HI_FAIL;
1004 }
1005 }
1006
1007 (*msg_idx) += update_sta_user->puc_payload[(*msg_idx) + 1] + MAC_IE_HDR_LEN;
1008 #ifdef _PRE_WLAN_FEATURE_MESH
1009 }
1010 #endif
1011
1012 /* 当前用户已关联 */
1013 sup_rates.msg_len = update_sta_user->msg_len;
1014 sup_rates.us_offset = *msg_idx;
1015 sup_rates.pus_msg_idx = &us_rate_len;
1016 hi_u32 rslt = hmac_ap_up_update_sta_sup_rates(update_sta_user->puc_payload, hmac_user, status_code, &sup_rates);
1017 if (rslt != HI_SUCCESS) {
1018 oam_warning_log2(mac_vap->vap_id, OAM_SF_ASSOC,
1019 "{hmac_ap_up_update_sta_user::AP refuse STA assoc,update rates Err=%d,status_code=%d}", rslt, *status_code);
1020 return rslt;
1021 }
1022
1023 (*msg_idx) += us_rate_len;
1024
1025 return HI_SUCCESS;
1026 }
1027
hmac_sta_several_param_proc(const hmac_vap_stru * hmac_vap,const hmac_update_sta_user_info_stru * sta_user,hmac_user_stru * hmac_user,mac_status_code_enum_uint16 * status_code,const hmac_sta_check_info * sta_check)1028 hi_u32 hmac_sta_several_param_proc(const hmac_vap_stru *hmac_vap, const hmac_update_sta_user_info_stru *sta_user,
1029 hmac_user_stru *hmac_user, mac_status_code_enum_uint16 *status_code, const hmac_sta_check_info *sta_check)
1030 {
1031 const hi_u8 *ie = HI_NULL;
1032 hi_u8 sub_type = mac_get_frame_sub_type(sta_user->puc_mac_hdr);
1033 #ifdef _PRE_WLAN_FEATURE_MESH
1034 if ((hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH) && (sub_type == WLAN_FC0_SUBTYPE_ACTION)) {
1035 /* 检查接收到的Mesh Peering Open消息中的SECURITY参数.如出错,则返回对应的错误码 */
1036 hi_u32 sec_rslt = hmac_check_open_action_sec_authenticator(hmac_vap, sta_user->puc_payload, sta_user->msg_len,
1037 hmac_user, status_code);
1038 if (sec_rslt != HI_SUCCESS) {
1039 return HI_FAIL;
1040 }
1041 } else {
1042 #endif
1043 /* 检查接收到的ASOC REQ消息中的SECURITY参数.如出错,则返回对应的错误码 */
1044 hi_u32 ret = hmac_chk_assoc_req_sec_cap_auth(hmac_vap, sta_user->puc_mac_hdr, sta_user->puc_payload,
1045 sta_user->msg_len, hmac_user, status_code);
1046 if (ret != HI_SUCCESS) {
1047 oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC, "{hmac_ap_up_update_sta_user::Err=%d}", ret);
1048 return HI_FAIL;
1049 }
1050 #ifdef _PRE_WLAN_FEATURE_MESH
1051 }
1052 #endif
1053
1054 /* 更新对应STA的legacy协议能力 */
1055 hmac_ap_up_update_legacy_capability(hmac_vap, hmac_user, sta_check->cap);
1056
1057 /* 检查HT capability是否匹配,并进行处理 */
1058 hi_u16 ret_val = hmac_vap_check_ht_capabilities_ap(hmac_vap, sta_user->puc_payload, sta_check->msg_idx,
1059 sta_user->msg_len, hmac_user);
1060 if (ret_val != MAC_SUCCESSFUL_STATUSCODE) {
1061 *status_code = ret_val;
1062 return ret_val;
1063 }
1064
1065 /* 更新AP中保护相关mib量 */
1066 hi_u32 rslt = hmac_user_protection_sync_data(hmac_vap->base_vap);
1067 if (rslt != HI_SUCCESS) {
1068 oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC, "{hmac_ap_up_update_sta_user::Err=%d}", rslt);
1069 }
1070
1071 #ifdef _PRE_WLAN_FEATURE_UAPSD
1072 /* 更新对应STA的协议能力 */
1073 hmac_ap_up_update_asoc_entry_prot(sta_user->puc_payload, sub_type, sta_user->msg_len, hmac_user);
1074 #endif
1075
1076 /* 更新QoS能力 */
1077 hmac_mgmt_update_assoc_user_qos(sta_user->puc_payload, (hi_u16)sta_user->msg_len, sta_check->msg_idx, hmac_user);
1078
1079 if (sta_user->msg_len > sta_check->offset) {
1080 /* 查找RSN信息元素,如果没有RSN信息元素,则按照不支持处理 */
1081 ie = mac_find_ie(MAC_EID_RSN, sta_user->puc_payload + sta_check->offset,
1082 (sta_user->msg_len - sta_check->offset));
1083 /* 根据RSN信息元素, 判断RSN能力是否匹配 */
1084 if (hmac_check_rsn_capability(hmac_vap->base_vap, ie, status_code) != HI_SUCCESS) {
1085 return HI_FAIL;
1086 }
1087 #ifdef _PRE_WLAN_FEATURE_PMF
1088 /* 配置这条连接的pmf能力开关 */
1089 hmac_set_pmf_cap(hmac_user->base_user, hmac_vap->base_vap, ie);
1090 #endif
1091 }
1092 return HI_SUCCESS;
1093 }
1094
hmac_sta_protocol_bandwidth_proc(const hmac_vap_stru * hmac_vap,const hmac_update_sta_user_info_stru * update,hmac_user_stru * hmac_user,mac_status_code_enum_uint16 * status_code,hi_u16 msg_idx)1095 hi_u32 hmac_sta_protocol_bandwidth_proc(const hmac_vap_stru *hmac_vap, const hmac_update_sta_user_info_stru *update,
1096 hmac_user_stru *hmac_user, mac_status_code_enum_uint16 *status_code, hi_u16 msg_idx)
1097 {
1098 mac_vap_stru *mac_vap = hmac_vap->base_vap;
1099 mac_user_stru *mac_user = hmac_user->base_user;
1100 wlan_bw_cap_enum_uint8 bandwidth_cap;
1101 wlan_bw_cap_enum_uint8 bwcap_ap; /* ap自身带宽能力 */
1102
1103 hi_unref_param(update);
1104 hi_unref_param(msg_idx);
1105
1106 /* 获取用户的协议模式 */
1107 hmac_set_user_protocol_mode(mac_vap, hmac_user);
1108 if (hmac_get_auc_avail_protocol_mode(mac_vap->protocol, mac_user->protocol_mode) == WLAN_PROTOCOL_BUTT) {
1109 oam_warning_log3(mac_vap->vap_id, OAM_SF_ASSOC,
1110 "{hmac_ap_up_update_sta_user:user not allowed:no valid protocol:vapMode=%d,userMode=%d,userAvailMode=%d}",
1111 mac_vap->protocol, mac_user->protocol_mode, mac_user->avail_protocol_mode);
1112 *status_code = MAC_UNSUP_CAP;
1113 return HI_FAIL;
1114 }
1115 /* 获取用户与VAP协议模式交集 */
1116 mac_user->avail_protocol_mode = hmac_get_auc_avail_protocol_mode(mac_vap->protocol, mac_user->protocol_mode);
1117 mac_user->cur_protocol_mode = mac_user->avail_protocol_mode;
1118 oam_warning_log3(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_ap_up_update_sta_user:protocol:%d,mode:%d,avail_mode:%d}",
1119 mac_vap->protocol, mac_user->protocol_mode, mac_user->avail_protocol_mode);
1120 /* 获取用户和VAP 可支持的11a/b/g 速率交集 */
1121 hmac_vap_set_user_avail_rates(mac_vap, hmac_user);
1122 /* 获取用户的带宽能力 */
1123 mac_user_get_sta_cap_bandwidth(mac_user, &bandwidth_cap);
1124 /* 获取vap带宽能力与用户带宽能力的交集 */
1125 mac_vap_get_bandwidth_cap(hmac_vap->base_vap, &bwcap_ap);
1126 mac_user_set_bandwidth_info(mac_user, oal_min(bwcap_ap, bandwidth_cap), oal_min(bwcap_ap, bandwidth_cap));
1127
1128 oam_warning_log3(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_ap_up_update_sta_user::bwcap_ap:%d,bw_cap:%d,curbw:%d.}",
1129 bwcap_ap, bandwidth_cap, mac_user->cur_bandwidth);
1130
1131 hi_u32 rslt = hmac_config_user_cap_syn(mac_vap, mac_user);
1132 if (rslt != HI_SUCCESS) {
1133 oam_error_log1(mac_user->vap_id, OAM_SF_ASSOC, "{hmac_ap_up_update_sta_user::config_usr_cap_syn Err=%d}", rslt);
1134 }
1135 /* 根据用户支持带宽能力,协商出当前带宽,dmac offload架构下,同步带宽信息到device */
1136 rslt = hmac_config_user_info_syn(mac_vap, mac_user);
1137 if (rslt != HI_SUCCESS) {
1138 oam_error_log1(mac_user->vap_id, OAM_SF_ASSOC, "{hmac_ap_up_update_sta_user::usr_info_syn failed[%d].}", rslt);
1139 }
1140 /* 获取用户与VAP空间流交集 */
1141 rslt = hmac_user_set_avail_num_space_stream(mac_user, WLAN_SINGLE_NSS);
1142 if (rslt != HI_SUCCESS) {
1143 *status_code = MAC_UNSPEC_FAIL;
1144 oam_warning_log1(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_ap_up_update_sta_user:set_avail_num_spaceErr=%d}", rslt);
1145 }
1146 #ifdef _PRE_WLAN_FEATURE_OPMODE_NOTIFY
1147 /* 处理Operating Mode Notification 信息元素 */
1148 rslt = hmac_check_opmode_notify(hmac_vap, update_sta_user->puc_mac_hdr, update_sta_user->puc_payload, msg_idx,
1149 update_sta_user->msg_len, hmac_user);
1150 if (rslt != HI_SUCCESS) {
1151 oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC, "{hmac_ap_up_update_sta_user:check Err%d}", rslt);
1152 }
1153 #endif
1154 return HI_SUCCESS;
1155 }
1156
1157 /* ****************************************************************************
1158 功能描述 : AP侧更新STA信息
1159 1.日 期 : 2013年7月3日
1160 作 者 : HiSilicon
1161 修改内容 : 新生成函数
1162 2.日 期 : 2013年8月27日
1163 作 者 : HiSilicon
1164 修改内容 : 修改函数,添加安全相关的信息
1165 **************************************************************************** */
hmac_ap_up_update_sta_user(const hmac_vap_stru * hmac_vap,const hmac_update_sta_user_info_stru * update,hmac_user_stru * hmac_user,mac_status_code_enum_uint16 * status_code)1166 static hi_u32 hmac_ap_up_update_sta_user(const hmac_vap_stru *hmac_vap, const hmac_update_sta_user_info_stru *update,
1167 hmac_user_stru *hmac_user, mac_status_code_enum_uint16 *status_code)
1168 {
1169 hi_u16 msg_idx = 0;
1170 hi_u16 offset = MAC_CAP_INFO_LEN + MAC_LISTEN_INT_LEN;
1171 mac_vap_stru *mac_vap = hmac_vap->base_vap;
1172
1173 *status_code = MAC_SUCCESSFUL_STATUSCODE;
1174
1175 #ifdef _PRE_WLAN_FEATURE_MESH
1176 if (mac_get_frame_sub_type(update->puc_mac_hdr) == WLAN_FC0_SUBTYPE_ACTION) {
1177 /* Mesh关联采用Self_protected Action帧,帧结构不同 */
1178 offset = MAC_ACTION_CATEGORY_LEN + MAC_ACTION_CODE_LEN + MAC_CAP_INFO_LEN;
1179 msg_idx += MAC_ACTION_CATEGORY_LEN + MAC_ACTION_CODE_LEN;
1180 }
1181 #endif
1182
1183 /* **************************************************************************
1184 检查AP是否支持当前正在关联的STA的所有能力
1185 |ESS|IBSS|CFPollable|CFPReq|Privacy|Preamble|PBCC|Agility|Reserved|
1186 ************************************************************************** */
1187 hi_u16 cap = update->puc_payload[msg_idx] | (update->puc_payload[(msg_idx + 1)] << 8); /* 8 */
1188
1189 if (hmac_ap_up_update_sta_cap_info(hmac_vap, cap, hmac_user, status_code) != HI_TRUE) {
1190 return HI_FAIL;
1191 }
1192 msg_idx += MAC_CAP_INFO_LEN;
1193
1194 #ifdef _PRE_WLAN_FEATURE_MESH
1195 msg_idx += (mac_get_frame_sub_type(update->puc_mac_hdr) != WLAN_FC0_SUBTYPE_ACTION) ? MAC_LIS_INTERVAL_IE_LEN : 0;
1196 if ((mac_get_frame_sub_type(update->puc_mac_hdr) == WLAN_FC0_SUBTYPE_ACTION) &&
1197 (mac_get_action_category(update->puc_payload) == MAC_ACTION_CATEGORY_SELF_PROTECTED) &&
1198 (mac_get_action_code(update->puc_payload) == MAC_SP_ACTION_MESH_PEERING_CONFIRM)) {
1199 /* Mesh Peering Confirm帧中Cap后为AID */
1200 msg_idx += MAC_AID_LEN;
1201 offset += MAC_AID_LEN;
1202 }
1203 #else
1204 msg_idx += MAC_LIS_INTERVAL_IE_LEN;
1205 #endif
1206
1207 if (mac_get_frame_sub_type(update->puc_mac_hdr) == WLAN_FC0_SUBTYPE_REASSOC_REQ) {
1208 /* 重关联比关联请求帧头多了AP的MAC地址 */
1209 msg_idx += WLAN_MAC_ADDR_LEN;
1210 offset += WLAN_MAC_ADDR_LEN;
1211 }
1212
1213 hi_u32 rslt = hmac_sta_ssid_and_sup_rate_proc(update, hmac_user, status_code, mac_vap, &msg_idx);
1214 if (rslt != HI_SUCCESS) {
1215 return rslt;
1216 }
1217 hmac_sta_check_info sta_check = { cap, msg_idx, offset, { 0, 0 } };
1218 rslt = hmac_sta_several_param_proc(hmac_vap, update, hmac_user, status_code, &sta_check);
1219 if (rslt != HI_SUCCESS) {
1220 return rslt;
1221 }
1222
1223 rslt = hmac_sta_protocol_bandwidth_proc(hmac_vap, update, hmac_user, status_code, msg_idx);
1224 return rslt;
1225 }
1226
1227 /* ****************************************************************************
1228 功能描述 : AP 保存STA 的关联请求帧信息,以备上报内核
1229 输入参数 : [1]hmac_user
1230 [2]puc_payload
1231 [3]payload_len
1232 [4]mgmt_frm_type
1233 返 回 值 : static hi_u32
1234 **************************************************************************** */
hmac_ap_prepare_assoc_req(hmac_user_stru * hmac_user,const hi_u8 * puc_payload,hi_u32 payload_len,hi_u8 mgmt_frm_type)1235 static hi_u32 hmac_ap_prepare_assoc_req(hmac_user_stru *hmac_user, const hi_u8 *puc_payload, hi_u32 payload_len,
1236 hi_u8 mgmt_frm_type)
1237 {
1238 hi_u32 payload_size;
1239
1240 /* AP 保存STA 的关联请求帧信息,以备上报内核 */
1241 if (hmac_user->puc_assoc_req_ie_buff != HI_NULL) {
1242 oal_mem_free(hmac_user->puc_assoc_req_ie_buff);
1243 hmac_user->puc_assoc_req_ie_buff = HI_NULL;
1244 hmac_user->assoc_req_ie_len = 0;
1245 }
1246 payload_size = payload_len;
1247
1248 /* 目前11r没有实现,所以处理重关联帧的流程和关联帧一样,11r实现后此处需要修改 */
1249 if (WLAN_FC0_SUBTYPE_REASSOC_REQ == mgmt_frm_type) {
1250 /* 重关联比关联请求帧头多了AP的MAC地址 */
1251 puc_payload += (WLAN_MAC_ADDR_LEN + MAC_CAP_INFO_LEN + MAC_LIS_INTERVAL_IE_LEN);
1252 if (payload_len < (WLAN_MAC_ADDR_LEN + MAC_CAP_INFO_LEN + MAC_LIS_INTERVAL_IE_LEN)) {
1253 oam_warning_log0(0, OAM_SF_CFG, "hmac_ap_prepare_assoc_req:: reassoc frame err.");
1254 return HI_FAIL;
1255 }
1256 payload_len -= (WLAN_MAC_ADDR_LEN + MAC_CAP_INFO_LEN + MAC_LIS_INTERVAL_IE_LEN);
1257 } else {
1258 if (payload_len < (MAC_CAP_INFO_LEN + MAC_LIS_INTERVAL_IE_LEN)) {
1259 oam_warning_log0(0, OAM_SF_CFG, "hmac_ap_prepare_assoc_req:: resoc frame err.");
1260 return HI_FAIL;
1261 }
1262 puc_payload += (MAC_CAP_INFO_LEN + MAC_LIS_INTERVAL_IE_LEN);
1263 payload_len -= (MAC_CAP_INFO_LEN + MAC_LIS_INTERVAL_IE_LEN);
1264 }
1265
1266 hmac_user->puc_assoc_req_ie_buff = oal_mem_alloc(OAL_MEM_POOL_ID_LOCAL, (hi_u16)payload_size);
1267 if (hmac_user->puc_assoc_req_ie_buff == HI_NULL) {
1268 oam_error_log0(hmac_user->base_user->vap_id, OAM_SF_ASSOC,
1269 "{hmac_ap_prepare_assoc_req::Alloc Assoc Req for kernel failed.}");
1270 hmac_user->assoc_req_ie_len = 0;
1271 return HI_FAIL;
1272 } else {
1273 if (memcpy_s(hmac_user->puc_assoc_req_ie_buff, (hi_u16)payload_size, puc_payload, payload_len) != EOK) {
1274 oal_mem_free(hmac_user->puc_assoc_req_ie_buff);
1275 oam_error_log0(0, OAM_SF_CFG, "hmac_ap_prepare_assoc_req:: puc_payload memcpy_s fail.");
1276 return HI_FAIL;
1277 }
1278 hmac_user->assoc_req_ie_len = payload_len;
1279 return HI_SUCCESS;
1280 }
1281 }
1282
hmac_ap_get_mac_and_user(const hmac_vap_stru * hmac_vap,const hi_u8 * puc_mac_hdr,hi_u8 * sta_mac_addr,hmac_user_stru ** hmac_user,hi_u8 * user_idx)1283 static hi_u32 hmac_ap_get_mac_and_user(const hmac_vap_stru *hmac_vap, const hi_u8 *puc_mac_hdr, hi_u8 *sta_mac_addr,
1284 hmac_user_stru **hmac_user, hi_u8 *user_idx)
1285 {
1286 hi_u32 rslt;
1287
1288 mac_get_address2(puc_mac_hdr, WLAN_MAC_ADDR_LEN, sta_mac_addr, WLAN_MAC_ADDR_LEN);
1289
1290 rslt = mac_vap_find_user_by_macaddr(hmac_vap->base_vap, sta_mac_addr, WLAN_MAC_ADDR_LEN, user_idx);
1291 if (rslt != HI_SUCCESS) {
1292 oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC,
1293 "{hmac_ap_up_rx_asoc_req::mac_vap_find_user_by_macaddr failed[%d].}", rslt);
1294 oam_warning_log3(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC,
1295 "{hmac_ap_up_rx_asoc_req::user mac:%XX:XX:XX:%02X:%02X:%02X.}", sta_mac_addr[3], sta_mac_addr[4],
1296 sta_mac_addr[5]); /* 3 4 5 元素索引 */
1297 hmac_mgmt_send_deauth_frame(hmac_vap->base_vap, sta_mac_addr, WLAN_MAC_ADDR_LEN, MAC_ASOC_NOT_AUTH);
1298
1299 return rslt;
1300 }
1301
1302 oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC, "{hmac_ap_get_mac_and_user::uc_user_idx[%d].}",
1303 *user_idx);
1304
1305 *hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(*user_idx);
1306 if ((*hmac_user == HI_NULL) || ((*hmac_user)->base_user == HI_NULL)) {
1307 oam_error_log0(0, OAM_SF_ASSOC, "{hmac_ap_up_rx_asoc_req::pst_hmac_user null.}");
1308 /* 没有查到对应的USER,发送去认证消息 */
1309 hmac_mgmt_send_deauth_frame(hmac_vap->base_vap, sta_mac_addr, WLAN_MAC_ADDR_LEN, MAC_ASOC_NOT_AUTH);
1310 return HI_ERR_CODE_PTR_NULL;
1311 }
1312 #ifdef _PRE_WLAN_FEATURE_MESH
1313 if ((hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH) && ((*hmac_user)->base_user->is_mesh_user == HI_TRUE)) {
1314 /* 不应该收到Mesh User发来的Assoc Req */
1315 oam_warning_log3(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC,
1316 "{hmac_ap_up_rx_asoc_req::[MESH] receive assoc req from mesh user, user mac:XX:XX:XX:%02X:%02X:%02X.}",
1317 sta_mac_addr[3], sta_mac_addr[4], sta_mac_addr[5]); /* 3 4 5 元素索引 */
1318 return HI_SUCCESS;
1319 }
1320 #endif
1321 return HI_CONTINUE;
1322 }
1323
hmac_ap_asoc_pmf_process(const hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,mac_status_code_enum_uint16 * status_code)1324 static hi_u32 hmac_ap_asoc_pmf_process(const hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
1325 mac_status_code_enum_uint16 *status_code)
1326 {
1327 /* 是否符合触发SA query流程的条件 */
1328 #ifdef _PRE_WLAN_FEATURE_PMF
1329 if ((hmac_user->sa_query_info.sa_query_interval_timer.is_enabled != HI_TRUE) &&
1330 (hmac_user->base_user->user_asoc_state == MAC_USER_STATE_ASSOC) &&
1331 (hmac_user->base_user->cap_info.pmf_active == HI_TRUE)) {
1332 oam_info_log0(hmac_user->base_user->vap_id, OAM_SF_ASSOC,
1333 "{hmac_ap_up_rx_asoc_req::AP rx STA assoc req ,and start sa query process.}");
1334 hi_u32 rslt = hmac_start_sa_query(hmac_vap->base_vap, hmac_user, hmac_user->base_user->cap_info.pmf_active);
1335 if (rslt != HI_SUCCESS) {
1336 oam_error_log1(hmac_user->base_user->vap_id, OAM_SF_ASSOC,
1337 "{hmac_ap_up_rx_asoc_req::hmac_start_sa_query failed[%d].}", rslt);
1338 return rslt;
1339 }
1340 oam_info_log0(hmac_user->base_user->vap_id, OAM_SF_ASSOC,
1341 "{hmac_ap_up_rx_asoc_req::set en_status_code is MAC_REJECT_TEMP.}");
1342 *status_code = MAC_REJECT_TEMP;
1343 }
1344 #endif
1345 return HI_SUCCESS;
1346 }
1347
1348 #ifdef _PRE_WLAN_FEATURE_P2P
hmac_ap_asoc_p2p_process(const hmac_vap_stru * hmac_vap,hi_u8 mgmt_frm_type,hi_u32 payload_len,hi_u8 * puc_payload,const hmac_user_stru * hmac_user)1349 static hi_void hmac_ap_asoc_p2p_process(const hmac_vap_stru *hmac_vap, hi_u8 mgmt_frm_type, hi_u32 payload_len,
1350 hi_u8 *puc_payload, const hmac_user_stru *hmac_user)
1351 {
1352 hi_s32 l_len = ((mgmt_frm_type == WLAN_FC0_SUBTYPE_REASSOC_REQ) ? (MAC_CAP_INFO_LEN + MAC_LISTEN_INT_LEN +
1353 WLAN_MAC_ADDR_LEN) : (MAC_CAP_INFO_LEN + MAC_LISTEN_INT_LEN));
1354 if (is_p2p_go(hmac_vap->base_vap) &&
1355 (HI_NULL == mac_find_vendor_ie(MAC_WLAN_OUI_WFA, MAC_WLAN_OUI_TYPE_WFA_P2P, puc_payload + l_len,
1356 (hi_s32) payload_len - l_len))) {
1357 oam_info_log1(hmac_user->base_user->vap_id, OAM_SF_ASSOC,
1358 "{hmac_ap_up_rx_asoc_req::GO got assoc request from legacy device, length = [%d]}",
1359 payload_len);
1360 hmac_p2p_disable_pm(hmac_vap);
1361 }
1362 }
1363 #endif
1364
hmac_ap_asoc_req_process(hmac_ap_asoc_req_stru asoc_req,hmac_ap_asoc_info_stru asoc_info)1365 static hi_u32 hmac_ap_asoc_req_process(hmac_ap_asoc_req_stru asoc_req, hmac_ap_asoc_info_stru asoc_info)
1366 {
1367 hi_u32 rslt;
1368 hmac_update_sta_user_info_stru update_sta_user_info = {
1369 .puc_mac_hdr = asoc_req.puc_mac_hdr,
1370 .puc_payload = asoc_req.puc_payload,
1371 .msg_len = asoc_req.payload_len
1372 };
1373
1374 rslt = hmac_ap_asoc_pmf_process(asoc_req.hmac_vap, asoc_info.hmac_user, asoc_info.status_code);
1375 if (rslt != HI_SUCCESS) {
1376 oam_error_log0(0, OAM_SF_ASSOC, "hmac_ap_asoc_pmf_process fail");
1377 return rslt;
1378 }
1379
1380 if (*(asoc_info.status_code) != MAC_REJECT_TEMP) {
1381 /* 当可以查找到用户时,说明当前USER的状态为已关联或已认证完成 */
1382 rslt = hmac_ap_up_update_sta_user(asoc_req.hmac_vap, &update_sta_user_info, asoc_info.hmac_user,
1383 asoc_info.status_code);
1384 if ((rslt != HI_SUCCESS) || (*(asoc_info.status_code) != MAC_SUCCESSFUL_STATUSCODE)) {
1385 oam_warning_log1(0, OAM_SF_ASSOC, "{hmac_ap_up_update_sta_user failed[%d].}", *(asoc_info.status_code));
1386 hmac_user_set_asoc_state(asoc_req.hmac_vap->base_vap, asoc_info.hmac_user->base_user,
1387 MAC_USER_STATE_AUTH_COMPLETE);
1388 }
1389 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
1390 /* 同步ap带宽,能力等信息到dmac */
1391 hmac_chan_sync(asoc_req.hmac_vap->base_vap, asoc_req.hmac_vap->base_vap->channel.chan_number,
1392 asoc_req.hmac_vap->base_vap->channel.en_bandwidth, HI_FALSE);
1393 #endif
1394
1395 /* 根据用户支持带宽能力,协商出当前带宽,dmac offload架构下,同步带宽信息到device */
1396 rslt = hmac_config_user_info_syn(asoc_req.hmac_vap->base_vap, asoc_info.hmac_user->base_user);
1397 if (rslt != HI_SUCCESS) {
1398 oam_error_log1(0, OAM_SF_ASSOC, "{hmac_ap_up_rx_asoc_req::usr_info_syn failed[%d].}", rslt);
1399 }
1400
1401 if (*(asoc_info.status_code) == MAC_SUCCESSFUL_STATUSCODE) {
1402 rslt = hmac_init_security(asoc_req.hmac_vap->base_vap, asoc_info.sta_mac_addr, WLAN_MAC_ADDR_LEN);
1403 if (rslt != HI_SUCCESS) {
1404 oam_error_log2(0, 0, "{hmac_init_security failed[%d] status_code[%d].}", rslt, MAC_UNSPEC_FAIL);
1405 *(asoc_info.status_code) = MAC_UNSPEC_FAIL;
1406 }
1407 #if defined(_PRE_WLAN_FEATURE_WPA) || defined(_PRE_WLAN_FEATURE_WPA2)
1408 rslt = hmac_init_user_security_port(asoc_req.hmac_vap->base_vap, asoc_info.hmac_user->base_user);
1409 if (rslt != HI_SUCCESS) {
1410 oam_error_log1(0, OAM_SF_ASSOC, "{hmac_init_user_security_port failed[%d].}", rslt);
1411 }
1412 #endif /* defined(_PRE_WLAN_FEATURE_WPA) || defined(_PRE_WLAN_FEATURE_WPA2) */
1413 }
1414
1415 if ((rslt != HI_SUCCESS) || (*(asoc_info.status_code) != MAC_SUCCESSFUL_STATUSCODE)) {
1416 oam_warning_log2(0, OAM_SF_CFG, "hmac_ap_up_update_sta_user fail rslt[%d] status_code[%d].", rslt,
1417 *(asoc_info.status_code));
1418 hmac_user_set_asoc_state(asoc_req.hmac_vap->base_vap, asoc_info.hmac_user->base_user,
1419 MAC_USER_STATE_AUTH_COMPLETE);
1420 }
1421 #ifdef _PRE_WLAN_FEATURE_P2P
1422 hmac_ap_asoc_p2p_process(asoc_req.hmac_vap, asoc_req.mgmt_frm_type, asoc_req.payload_len,
1423 asoc_req.puc_payload, asoc_info.hmac_user);
1424 #endif
1425 }
1426
1427 return HI_SUCCESS;
1428 }
1429
hmac_ap_prepare_asoc_rsp(hmac_ap_asoc_req_stru asoc_req,hmac_ap_asoc_info_stru asoc_info,oal_netbuf_stru ** asoc_rsp,hi_u32 * asoc_rsp_len)1430 static hi_u32 hmac_ap_prepare_asoc_rsp(hmac_ap_asoc_req_stru asoc_req, hmac_ap_asoc_info_stru asoc_info,
1431 oal_netbuf_stru **asoc_rsp, hi_u32 *asoc_rsp_len)
1432 {
1433 hmac_asoc_rsp_ap_info_stru asoc_rsp_ap_info;
1434 hmac_tx_ctl_stru *tx_ctl = HI_NULL;
1435
1436 *asoc_rsp = (oal_netbuf_stru *)oal_netbuf_alloc(WLAN_MGMT_NETBUF_SIZE, 0, 4); /* align 4 */
1437 if (*asoc_rsp == HI_NULL) {
1438 oam_error_log0(asoc_info.hmac_user->base_user->vap_id, OAM_SF_ASSOC,
1439 "{hmac_ap_up_rx_asoc_req::pst_asoc_rsp null.}");
1440 /* 异常返回之前删除user */
1441 hmac_user_del(asoc_req.hmac_vap->base_vap, asoc_info.hmac_user);
1442 return HI_ERR_CODE_ALLOC_MEM_FAIL;
1443 }
1444 tx_ctl = (hmac_tx_ctl_stru *)oal_netbuf_cb(*asoc_rsp);
1445 if (memset_s(tx_ctl, oal_netbuf_cb_size(), 0, sizeof(hmac_tx_ctl_stru)) != EOK) {
1446 oal_netbuf_free(*asoc_rsp);
1447 return HI_FAIL;
1448 }
1449
1450 asoc_rsp_ap_info.puc_sta_addr = asoc_info.sta_mac_addr;
1451 asoc_rsp_ap_info.assoc_id = asoc_info.hmac_user->base_user->us_assoc_id;
1452 asoc_rsp_ap_info.status_code = *(asoc_info.status_code);
1453 asoc_rsp_ap_info.puc_asoc_rsp = oal_netbuf_header(*asoc_rsp);
1454 asoc_rsp_ap_info.us_type = (asoc_req.mgmt_frm_type == WLAN_FC0_SUBTYPE_ASSOC_REQ) ?
1455 WLAN_FC0_SUBTYPE_ASSOC_RSP : WLAN_FC0_SUBTYPE_REASSOC_RSP;
1456 *asoc_rsp_len = hmac_mgmt_encap_asoc_rsp_ap(asoc_req.hmac_vap->base_vap, &asoc_rsp_ap_info);
1457 if (*asoc_rsp_len == 0) {
1458 oam_warning_log0(asoc_info.hmac_user->base_user->vap_id, OAM_SF_ASSOC,
1459 "{hmac_ap_up_rx_asoc_req::hmac_mgmt_encap_asoc_rsp_ap encap msg fail.}");
1460 oal_netbuf_free(*asoc_rsp);
1461 /* 异常返回之前删除user */
1462 hmac_user_del(asoc_req.hmac_vap->base_vap, asoc_info.hmac_user);
1463 return HI_FAIL;
1464 }
1465
1466 oal_netbuf_put(*asoc_rsp, *asoc_rsp_len);
1467
1468 tx_ctl->us_tx_user_idx = asoc_info.hmac_user->base_user->us_assoc_id;
1469 tx_ctl->us_mpdu_len = (hi_u16)(*asoc_rsp_len);
1470 tx_ctl->frame_header_length = MAC_80211_FRAME_LEN;
1471 tx_ctl->frame_header = (mac_ieee80211_frame_stru *)oal_netbuf_header(*asoc_rsp);
1472 tx_ctl->mac_head_type = 1;
1473
1474 return HI_SUCCESS;
1475 }
1476
hmac_ap_tx_asoc_rsp(const hmac_vap_stru * hmac_vap,hi_u8 mgmt_frm_type,hmac_ap_asoc_info_stru asoc_info)1477 static hi_u32 hmac_ap_tx_asoc_rsp(const hmac_vap_stru *hmac_vap, hi_u8 mgmt_frm_type, hmac_ap_asoc_info_stru asoc_info)
1478 {
1479 hi_u32 rslt;
1480 oal_net_device_stru *netdev = HI_NULL;
1481 oal_netbuf_stru *asoc_rsp = HI_NULL;
1482 hi_u32 asoc_rsp_len;
1483 hmac_tx_ctl_stru *tx_ctl = HI_NULL;
1484 hmac_ap_asoc_req_stru asoc_req = {
1485 .hmac_vap = hmac_vap,
1486 .mgmt_frm_type = mgmt_frm_type
1487 };
1488
1489 rslt = hmac_ap_prepare_asoc_rsp(asoc_req, asoc_info, &asoc_rsp, &asoc_rsp_len);
1490 if (rslt != HI_SUCCESS) {
1491 oam_error_log0(0, OAM_SF_ASSOC, "hmac_ap_prepare_asoc_rsp fail");
1492 return rslt;
1493 }
1494
1495 /* 判断当前状态,如果用户已经关联成功则向上报用户离开信息 */
1496 if (asoc_info.hmac_user->base_user->user_asoc_state == MAC_USER_STATE_ASSOC) {
1497 netdev = hmac_vap_get_net_device(hmac_vap->base_vap->vap_id);
1498 if (netdev != HI_NULL) {
1499 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
1500 oal_kobject_uevent_env_sta_leave(netdev, asoc_info.sta_mac_addr);
1501 #endif
1502 }
1503 }
1504
1505 if (*(asoc_info.status_code) == MAC_SUCCESSFUL_STATUSCODE) {
1506 hmac_user_set_asoc_state(hmac_vap->base_vap, asoc_info.hmac_user->base_user, MAC_USER_STATE_ASSOC);
1507 }
1508
1509 /* 发送关联响应帧之前,将用户的节能状态复位 */
1510 tx_ctl = (hmac_tx_ctl_stru *)oal_netbuf_cb(asoc_rsp);
1511 hmac_mgmt_reset_psm(hmac_vap->base_vap, tx_ctl->us_tx_user_idx);
1512
1513 rslt = hmac_tx_mgmt_send_event(hmac_vap->base_vap, asoc_rsp, (hi_u16)asoc_rsp_len);
1514 if (rslt != HI_SUCCESS) {
1515 oal_netbuf_free(asoc_rsp);
1516 oam_warning_log1(asoc_info.hmac_user->base_user->vap_id, OAM_SF_ASSOC,
1517 "{hmac_ap_up_rx_asoc_req::hmac_tx_mgmt_send_event failed[%d].}", rslt);
1518 /* 异常返回之前删除user */
1519 hmac_user_del(hmac_vap->base_vap, asoc_info.hmac_user);
1520 return rslt;
1521 }
1522
1523 return HI_SUCCESS;
1524 }
1525
1526 /* ****************************************************************************
1527 功能描述 : AP侧接收到对应STA的关联请求消息
1528 修改历史 :
1529 1.日 期 : 2013年7月2日
1530 作 者 : HiSilicon
1531 修改内容 : 新生成函数
1532 **************************************************************************** */
hmac_ap_up_rx_asoc_req(const hmac_vap_stru * hmac_vap,hi_u8 mgmt_frm_type,hi_u8 * puc_mac_hdr,hi_u8 * puc_payload,hi_u32 payload_len)1533 static hi_u32 hmac_ap_up_rx_asoc_req(const hmac_vap_stru *hmac_vap, hi_u8 mgmt_frm_type,
1534 hi_u8 *puc_mac_hdr, hi_u8 *puc_payload, hi_u32 payload_len)
1535 {
1536 hmac_user_stru *hmac_user = HI_NULL;
1537 hi_u8 user_idx = 0;
1538 mac_status_code_enum_uint16 status_code = MAC_SUCCESSFUL_STATUSCODE;
1539 hi_u8 sta_mac_addr[WLAN_MAC_ADDR_LEN] = { 0 };
1540 hi_u8 *sta_mac_addr_ptr = sta_mac_addr;
1541 hmac_ap_asoc_info_stru asoc_info = {.sta_mac_addr = sta_mac_addr, .status_code = &status_code};
1542 hmac_ap_asoc_req_stru asoc_req = { .hmac_vap = hmac_vap, .mgmt_frm_type = mgmt_frm_type,
1543 .puc_mac_hdr = puc_mac_hdr, .puc_payload = puc_payload, .payload_len =payload_len };
1544
1545 hi_u32 rslt = hmac_ap_get_mac_and_user(hmac_vap, puc_mac_hdr, sta_mac_addr_ptr, &hmac_user, &user_idx);
1546 if (rslt != HI_CONTINUE) {
1547 oam_error_log0(0, OAM_SF_ASSOC, "hmac_ap_get_mac_and_user fail");
1548 return rslt;
1549 }
1550 asoc_info.hmac_user = hmac_user;
1551
1552 rslt = hmac_ap_asoc_req_process(asoc_req, asoc_info);
1553 if (rslt != HI_SUCCESS) {
1554 oam_error_log0(0, OAM_SF_ASSOC, "hmac_ap_asoc_req_process fail");
1555 return rslt;
1556 }
1557
1558 rslt = hmac_ap_tx_asoc_rsp(hmac_vap, mgmt_frm_type, asoc_info);
1559 if (rslt != HI_SUCCESS) {
1560 oam_error_log0(0, OAM_SF_ASSOC, "hmac_ap_tx_asoc_rsp fail");
1561 return rslt;
1562 }
1563 hi_u8 vap_id = hmac_user->base_user->vap_id;
1564 hi_unref_param(vap_id);
1565 if (status_code == MAC_SUCCESSFUL_STATUSCODE) {
1566 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
1567 rslt = hmac_config_user_rate_info_syn(hmac_vap->base_vap, hmac_user->base_user);
1568 if (rslt != HI_SUCCESS) {
1569 oam_error_log1(vap_id, OAM_SF_ASSOC, "{hmac_sta_wait_asoc_rx::user_rate_info_syn failed[%d].}", rslt);
1570 }
1571 #endif
1572 /* user已经关联上,抛事件给DMAC,在DMAC层挂用户算法钩子 */
1573 hmac_user_add_notify_alg(hmac_vap->base_vap, user_idx);
1574
1575 /* AP 保存STA 的关联请求帧信息,以备上报内核 */
1576 hmac_ap_prepare_assoc_req(hmac_user, puc_payload, payload_len, mgmt_frm_type);
1577
1578 /* 上报WAL层(WAL上报内核) AP关联上了一个新的STA */
1579 hmac_handle_connect_rsp_ap(hmac_vap, hmac_user);
1580 oam_warning_log1(vap_id, OAM_SF_ASSOC, "{hmac_ap_up_rx_asoc_req::STA assoc success! idx=%d.}", user_idx);
1581 } else {
1582 /* AP检测STA失败,将其删除 */
1583 if (status_code != MAC_REJECT_TEMP) {
1584 hmac_user_del(hmac_vap->base_vap, hmac_user);
1585 }
1586 }
1587 return HI_SUCCESS;
1588 }
1589
1590 /* ****************************************************************************
1591 功能描述 : AP侧接收到对应STA的去关联请求消息
1592 修改历史 :
1593 1.日 期 : 2013年7月2日
1594 作 者 : HiSilicon
1595 修改内容 : 新生成函数
1596 **************************************************************************** */
hmac_ap_up_rx_disasoc(const hmac_vap_stru * hmac_vap,hi_u8 * puc_mac_hdr,hi_u8 is_protected)1597 static hi_u32 hmac_ap_up_rx_disasoc(const hmac_vap_stru *hmac_vap, hi_u8 *puc_mac_hdr, hi_u8 is_protected)
1598 {
1599 hi_u8 *da_mac_addr = HI_NULL;
1600 hi_u8 *sa_mac_addr = HI_NULL;
1601 hi_u8 sta_mac_addr[WLAN_MAC_ADDR_LEN];
1602
1603 mac_get_address2(puc_mac_hdr, WLAN_MAC_ADDR_LEN, sta_mac_addr, WLAN_MAC_ADDR_LEN);
1604
1605 mac_rx_get_sa((mac_ieee80211_frame_stru *)puc_mac_hdr, &sa_mac_addr);
1606
1607 /* 增加接收到去关联帧时的维测信息 */
1608 oam_warning_log4(0, OAM_SF_ASSOC,
1609 "{hmac_ap_up_rx_disasoc::Because of err_code[%d], disassoc frame from source addr xx:xx:xx:%02x:%02x:%02x.}",
1610 *((hi_u16 *)(puc_mac_hdr + MAC_80211_FRAME_LEN)), sa_mac_addr[3], sa_mac_addr[4], sa_mac_addr[5]); /* 3 4 5 */
1611
1612 hmac_user_stru *hmac_user = mac_vap_get_hmac_user_by_addr(hmac_vap->base_vap, sta_mac_addr, WLAN_MAC_ADDR_LEN);
1613 if (hmac_user == HI_NULL) {
1614 oam_warning_log0(0, OAM_SF_ASSOC, "{hmac_ap_up_rx_disasoc::pst_hmac_user null.}");
1615 /* 没有查到对应的USER,发送去认证消息 */
1616 hmac_mgmt_send_deauth_frame(hmac_vap->base_vap, sta_mac_addr, WLAN_MAC_ADDR_LEN, MAC_NOT_ASSOCED);
1617
1618 return HI_ERR_CODE_PTR_NULL;
1619 }
1620 #ifdef _PRE_WLAN_FEATURE_MESH
1621 if ((hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH) && (hmac_user->base_user->is_mesh_user == HI_TRUE)) {
1622 /* 不应该收到Mesh User发来的DisAssoc Req */
1623 oam_warning_log3(0, OAM_SF_ASSOC,
1624 "{hmac_ap_up_rx_disasoc::[MESH] receive disassoc req from mesh user, user mac:XX:XX:XX:%02X:%02X:%02X.}",
1625 sta_mac_addr[3], sta_mac_addr[4], sta_mac_addr[5]); /* 3 4 5 元素索引 */
1626
1627 return HI_SUCCESS;
1628 }
1629 #endif
1630 if (hmac_user->base_user->user_asoc_state == MAC_USER_STATE_ASSOC) {
1631 #ifdef _PRE_WLAN_FEATURE_PMF
1632 /* 检查是否需要发送SA query request */
1633 if (HI_SUCCESS == hmac_pmf_check_err_code(hmac_user->base_user, is_protected, puc_mac_hdr)) {
1634 /* 在关联状态下收到未加密的ReasonCode 6/7需要启动SA Query流程 */
1635 hi_u32 ret = hmac_start_sa_query(hmac_vap->base_vap, hmac_user, hmac_user->base_user->cap_info.pmf_active);
1636 if (ret != HI_SUCCESS) {
1637 oam_error_log1(0, OAM_SF_ASSOC, "{hmac_ap_up_rx_disasoc::hmac_start_sa_query Err=%d}", ret);
1638 return HI_ERR_CODE_PMF_SA_QUERY_START_FAIL;
1639 }
1640 return HI_SUCCESS;
1641 }
1642 #endif
1643
1644 /* 如果该用户的管理帧加密属性不一致,丢弃该报文 */
1645 mac_rx_get_da((mac_ieee80211_frame_stru *)puc_mac_hdr, &da_mac_addr);
1646 if (!ether_is_multicast(da_mac_addr) && (is_protected != hmac_user->base_user->cap_info.pmf_active)) {
1647 oam_error_log1(0, OAM_SF_ASSOC, "{hmac_ap_up_rx_disasoc::PMF check fail,is_protected=%d}", is_protected);
1648 return HI_FAIL;
1649 }
1650
1651 mac_user_set_asoc_state(hmac_user->base_user, MAC_USER_STATE_AUTH_COMPLETE);
1652 /* 抛事件上报内核,已经去关联某个STA */
1653 hmac_handle_disconnect_rsp_ap(hmac_vap, hmac_user);
1654
1655 /* 有些网卡去关联时只发送DISASOC,也将删除其在AP内部的数据结构 */
1656 hi_u32 hmac_user_del_ret = hmac_user_del(hmac_vap->base_vap, hmac_user);
1657 if (hmac_user_del_ret != HI_SUCCESS) {
1658 oam_warning_log1(0, OAM_SF_ASSOC, "{hmac_ap_up_rx_disasoc::hmac_user_del err=%d}", hmac_user_del_ret);
1659 }
1660 }
1661
1662 return HI_SUCCESS;
1663 }
1664
1665 #ifdef _PRE_WLAN_FEATURE_MESH
hmac_ap_up_get_mesh_hmac_user(const hmac_vap_stru * hmac_vap,const hi_u8 * puc_data)1666 static hi_u32 hmac_ap_up_get_mesh_hmac_user(const hmac_vap_stru *hmac_vap, const hi_u8 *puc_data)
1667 {
1668 if ((hmac_vap->base_vap->vap_mode == WLAN_VAP_MODE_MESH) &&
1669 (puc_data[MAC_ACTION_OFFSET_CATEGORY] == MAC_ACTION_CATEGORY_SELF_PROTECTED) &&
1670 (puc_data[MAC_ACTION_OFFSET_ACTION] == MAC_SP_ACTION_MESH_PEERING_OPEN)) {
1671 /* Mesh Peering Open收到时可能无用户,统一由wpa添加用户,该处直接上报 */
1672 oam_warning_log0(hmac_vap->base_vap->vap_id, OAM_SF_RX,
1673 "{hmac_ap_up_get_mesh_hmac_user::rx open frame but no user.}");
1674 return HI_SUCCESS;
1675 } else {
1676 oam_warning_log0(hmac_vap->base_vap->vap_id, OAM_SF_RX, "{hmac_ap_up_get_mesh_hmac_user::find_user failed.}");
1677 return HI_FAIL;
1678 }
1679 }
1680 #endif
1681
hmac_ap_up_rx_action_category_public(const hmac_vap_stru * hmac_vap,oal_netbuf_stru * netbuf,const hi_u8 * puc_data)1682 static hi_void hmac_ap_up_rx_action_category_public(const hmac_vap_stru *hmac_vap, oal_netbuf_stru *netbuf,
1683 const hi_u8 *puc_data)
1684 {
1685 switch (puc_data[MAC_ACTION_OFFSET_ACTION]) {
1686 case MAC_PUB_VENDOR_SPECIFIC: {
1687 #ifdef _PRE_WLAN_FEATURE_P2P
1688 /* 查找OUI-OUI type值为 50 6F 9A - 09 (WFA P2P v1.0) */
1689 /* 并用hmac_rx_mgmt_send_to_host接口上报 */
1690 if (HI_TRUE == mac_ie_check_p2p_action(puc_data + MAC_ACTION_OFFSET_ACTION)) {
1691 hmac_rx_mgmt_send_to_host(hmac_vap, netbuf);
1692 }
1693 #else
1694 hi_unref_param(hmac_vap);
1695 hi_unref_param(netbuf);
1696 #endif
1697 break;
1698 }
1699 default:
1700 break;
1701 }
1702 }
1703
hmac_ap_up_rx_action_category_vht(hmac_vap_stru * hmac_vap,oal_netbuf_stru * netbuf,const hi_u8 * puc_data)1704 static hi_void hmac_ap_up_rx_action_category_vht(hmac_vap_stru *hmac_vap, oal_netbuf_stru *netbuf,
1705 const hi_u8 *puc_data)
1706 {
1707 switch (puc_data[MAC_ACTION_OFFSET_ACTION]) {
1708 case MAC_VHT_ACTION_OPREATE_MODE_NOTIFY:
1709 #ifdef _PRE_WLAN_FEATURE_OPMODE_NOTIFY
1710 hmac_mgmt_rx_opmode_notify_frame(hmac_vap, netbuf);
1711 break;
1712 #else
1713 hi_unref_param(hmac_vap);
1714 hi_unref_param(netbuf);
1715 break;
1716 #endif
1717 case MAC_VHT_ACTION_BUTT:
1718 break;
1719 default:
1720 break;
1721 }
1722 }
1723
1724 #ifdef _PRE_WLAN_FEATURE_PMF
hmac_ap_up_rx_action_category_sa_query(hmac_vap_stru * hmac_vap,oal_netbuf_stru * netbuf,const hi_u8 * puc_data,hi_u8 is_protected)1725 static hi_void hmac_ap_up_rx_action_category_sa_query(hmac_vap_stru *hmac_vap, oal_netbuf_stru *netbuf,
1726 const hi_u8 *puc_data, hi_u8 is_protected)
1727 {
1728 switch (puc_data[MAC_ACTION_OFFSET_ACTION]) {
1729 case MAC_SA_QUERY_ACTION_RESPONSE:
1730 hmac_rx_sa_query_rsp(hmac_vap, netbuf, is_protected);
1731 break;
1732 case MAC_SA_QUERY_ACTION_REQUEST:
1733 hmac_rx_sa_query_req(hmac_vap, netbuf, is_protected);
1734 break;
1735 default:
1736 break;
1737 }
1738 }
1739 #endif
1740
1741 #ifdef _PRE_WLAN_FEATURE_MESH
hmac_ap_up_rx_action_self_protected(const hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,mac_ieee80211_frame_stru * frame_hdr,oal_netbuf_stru * netbuf,hi_u8 * puc_data)1742 static hi_void hmac_ap_up_rx_action_self_protected(const hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
1743 mac_ieee80211_frame_stru *frame_hdr, oal_netbuf_stru *netbuf, hi_u8 *puc_data)
1744 {
1745 hi_u32 ret;
1746 hmac_rx_ctl_stru *rx_ctrl = (hmac_rx_ctl_stru *)oal_netbuf_cb(netbuf);
1747 switch (puc_data[MAC_ACTION_OFFSET_ACTION]) {
1748 case MAC_SP_ACTION_MESH_PEERING_CONFIRM:
1749 if (hmac_user == HI_NULL) {
1750 return;
1751 }
1752 /* 上报wpa_supplicant之前,预先处理与驱动User相关的速率/RSN等信息 */
1753 ret = hmac_mesh_up_rx_confirm_action(hmac_vap, hmac_user, (hi_u8 *)frame_hdr, puc_data,
1754 rx_ctrl->us_frame_len - rx_ctrl->mac_header_len);
1755 if (ret != HI_SUCCESS) {
1756 hmac_handle_close_peer_mesh(hmac_vap, hmac_user->base_user->user_mac_addr, WLAN_MAC_ADDR_LEN,
1757 (hi_u16)ret, MAC_UNSPEC_REASON);
1758 break;
1759 }
1760 /* fall-through */
1761 case MAC_SP_ACTION_MESH_PEERING_OPEN:
1762 /* confirm消息内容与open消息关于user信息的部分一致 */
1763 case MAC_SP_ACTION_MESH_PEERING_CLOSE:
1764 case MAC_SP_ACTION_MESH_GROUP_KEY_INFORM:
1765 case MAC_SP_ACTION_MESH_GROUP_KEY_ACK:
1766 if ((hmac_user != HI_NULL) && (hmac_user->base_user->user_asoc_state != MAC_USER_STATE_ASSOC) &&
1767 (hmac_user->base_user->is_mesh_user == HI_TRUE)) {
1768 /* 更新用户的RSSI统计信息 */
1769 hmac_user->base_user->rx_conn_rssi =
1770 wlan_rssi_lpf(hmac_user->base_user->rx_conn_rssi, rx_ctrl->rssi_dbm);
1771 }
1772 /* 收到SELF_PROTECTED类型ACTION帧发送到WPA_SUPPLICANT处理 */
1773 hmac_rx_mgmt_send_to_host(hmac_vap, netbuf);
1774 break;
1775 default:
1776 oam_warning_log0(hmac_user->base_user->vap_id, OAM_SF_ASSOC,
1777 "{hmac_ap_up_rx_action_self_protected::unsupported self protected action subtype.}");
1778 break;
1779 }
1780 }
1781
hmac_ap_up_rx_action_category_mesh(const hi_u8 * puc_data)1782 static hi_void hmac_ap_up_rx_action_category_mesh(const hi_u8 *puc_data)
1783 {
1784 switch (puc_data[MAC_ACTION_OFFSET_ACTION]) {
1785 case MAC_MESH_ACTION_TBTT_ADJ_REQ:
1786 case MAC_MESH_ACTION_TBTT_ADJ_RSP:
1787 oam_info_log0(0, OAM_SF_ASSOC, "{hmac_ap_up_rx_action_category_mesh::[MESH]rx tbtt adj req/rsp.}");
1788 break;
1789 default:
1790 oam_warning_log0(0, OAM_SF_ASSOC,
1791 "{hmac_ap_up_rx_action_category_mesh::unsupported mesh action subtype.}");
1792 break;
1793 }
1794 }
1795 #endif
1796
1797 /* ****************************************************************************
1798 功能描述 : AP在UP状态下的接收ACTION帧处理
1799 输入参数 : pst_hmac_vap: HMAC VAP指针
1800 pst_netbuf : 管理帧所在的sk_buff
1801 修改历史 :
1802 1.日 期 : 2014年2月21日
1803 作 者 : HiSilicon
1804 修改内容 : 新生成函数
1805 **************************************************************************** */
hmac_ap_up_rx_action(hmac_vap_stru * hmac_vap,oal_netbuf_stru * netbuf,hi_u8 is_protected)1806 static hi_void hmac_ap_up_rx_action(hmac_vap_stru *hmac_vap, oal_netbuf_stru *netbuf, hi_u8 is_protected)
1807 {
1808 hmac_user_stru *hmac_user = HI_NULL;
1809 hmac_rx_ctl_stru *rx_ctrl = (hmac_rx_ctl_stru *)oal_netbuf_cb(netbuf);
1810 /* 获取帧头信息 */
1811 mac_ieee80211_frame_stru *frame_hdr = (mac_ieee80211_frame_stru *)rx_ctrl->pul_mac_hdr_start_addr;
1812 /* 获取帧体指针 */
1813 hi_u8 *puc_data = (hi_u8 *)rx_ctrl->pul_mac_hdr_start_addr + rx_ctrl->mac_header_len;
1814 /* 获取发送端的用户指针 */
1815 hmac_user = mac_vap_get_hmac_user_by_addr(hmac_vap->base_vap, frame_hdr->auc_address2, WLAN_MAC_ADDR_LEN);
1816 if (hmac_user == HI_NULL) {
1817 #ifdef _PRE_WLAN_FEATURE_MESH
1818 if (hmac_ap_up_get_mesh_hmac_user(hmac_vap, puc_data) != HI_SUCCESS) {
1819 return;
1820 }
1821 #else
1822 oam_warning_log0(hmac_vap->base_vap->vap_id, OAM_SF_RX, "{hmac_ap_up_rx_action::find_user_by_macaddr failed.}");
1823 return;
1824 #endif
1825 }
1826
1827 /* Category */
1828 if (puc_data[MAC_ACTION_OFFSET_CATEGORY] == MAC_ACTION_CATEGORY_BA) {
1829 hmac_mgmt_rx_action_ba(hmac_vap, hmac_user, puc_data);
1830 } else if (puc_data[MAC_ACTION_OFFSET_CATEGORY] == MAC_ACTION_CATEGORY_PUBLIC) {
1831 hmac_ap_up_rx_action_category_public(hmac_vap, netbuf, puc_data);
1832 } else if (puc_data[MAC_ACTION_OFFSET_CATEGORY] == MAC_ACTION_CATEGORY_VHT) {
1833 hmac_ap_up_rx_action_category_vht(hmac_vap, netbuf, puc_data);
1834 #ifdef _PRE_WLAN_FEATURE_PMF
1835 } else if (puc_data[MAC_ACTION_OFFSET_CATEGORY] == MAC_ACTION_CATEGORY_SA_QUERY) {
1836 hmac_ap_up_rx_action_category_sa_query(hmac_vap, netbuf, puc_data, is_protected);
1837 #endif
1838 #ifdef _PRE_WLAN_FEATURE_MESH
1839 } else if (puc_data[MAC_ACTION_OFFSET_CATEGORY] == MAC_ACTION_CATEGORY_SELF_PROTECTED) {
1840 hmac_ap_up_rx_action_self_protected(hmac_vap, hmac_user, frame_hdr, netbuf, puc_data);
1841 } else if (puc_data[MAC_ACTION_OFFSET_CATEGORY] == MAC_ACTION_CATEGORY_MESH) {
1842 hmac_ap_up_rx_action_category_mesh(puc_data);
1843 #endif
1844 #ifdef _PRE_WLAN_FEATURE_P2P
1845 } else if (puc_data[MAC_ACTION_OFFSET_CATEGORY] == MAC_ACTION_CATEGORY_VENDOR) {
1846 /* 查找OUI-OUI type值为 50 6F 9A - 09 (WFA P2P v1.0) */
1847 /* 并用hmac_rx_mgmt_send_to_host接口上报 */
1848 if (HI_TRUE == mac_ie_check_p2p_action(puc_data + MAC_ACTION_OFFSET_CATEGORY)) {
1849 hmac_rx_mgmt_send_to_host(hmac_vap, netbuf);
1850 }
1851 #endif
1852 }
1853 }
1854
1855 /* ****************************************************************************
1856 功能描述 : AP在UP状态下的接收WPS probe req帧处理
1857 输入参数 : pst_hmac_vap: HMAC VAP指针
1858 pst_netbuf : 管理帧所在的sk_buff
1859 修改历史 :
1860 1.日 期 : 2014年5月17日
1861 作 者 : HiSilicon
1862 修改内容 : 新生成函数
1863 **************************************************************************** */
hmac_ap_up_rx_probe_req(const hmac_vap_stru * hmac_vap,oal_netbuf_stru * netbuf)1864 static hi_void hmac_ap_up_rx_probe_req(const hmac_vap_stru *hmac_vap, oal_netbuf_stru *netbuf)
1865 {
1866 hmac_rx_ctl_stru *rx_ctrl = HI_NULL;
1867 enum ieee80211_band band;
1868 hi_s32 l_freq;
1869
1870 rx_ctrl = (hmac_rx_ctl_stru *)oal_netbuf_cb(netbuf);
1871 /* 获取AP 当前信道 */
1872 if (WLAN_BAND_2G == hmac_vap->base_vap->channel.band) {
1873 band = IEEE80211_BAND_2GHZ;
1874 } else {
1875 band = IEEE80211_NUM_BANDS;
1876 }
1877 l_freq = oal_ieee80211_channel_to_frequency(hmac_vap->base_vap->channel.chan_number, band);
1878
1879 /* 上报接收到的probe req 管理帧 */
1880 hmac_send_mgmt_to_host(hmac_vap, netbuf, rx_ctrl->us_frame_len, l_freq);
1881 }
1882
1883 /* ****************************************************************************
1884 功能描述 : AP在UP状态下的接收管理帧处理
1885 修改历史 :
1886 1.日 期 : 2013年6月24日
1887 作 者 : HiSilicon
1888 修改内容 : 新生成函数
1889 **************************************************************************** */
hmac_ap_up_rx_mgmt(hmac_vap_stru * hmac_vap,const dmac_wlan_crx_event_stru * mgmt_rx_event)1890 hi_u32 hmac_ap_up_rx_mgmt(hmac_vap_stru *hmac_vap, const dmac_wlan_crx_event_stru *mgmt_rx_event)
1891 {
1892 hmac_rx_ctl_stru *rx_ctrl = (hmac_rx_ctl_stru *)oal_netbuf_cb((oal_netbuf_stru *)mgmt_rx_event->netbuf);
1893 hi_u8 *puc_mac_hdr = (hi_u8 *)(rx_ctrl->pul_mac_hdr_start_addr);
1894 hi_u32 mac_hdr_len = rx_ctrl->mac_header_len; /* MAC头长度 */
1895 hi_u8 *puc_payload = (hi_u8 *)(puc_mac_hdr) + mac_hdr_len;
1896 hi_u32 msg_len = rx_ctrl->us_frame_len; /* 消息总长度,不包括FCS */
1897 hi_u8 is_protected = (hi_u8)mac_get_protectedframe(puc_mac_hdr);
1898 hi_u8 mgmt_type = mac_get_frame_sub_type(puc_mac_hdr);
1899
1900 if (hmac_vap->base_vap->vap_state != MAC_VAP_STATE_UP) {
1901 return HI_SUCCESS;
1902 }
1903
1904 /* Bar frame proc here */
1905 if ((mac_get_frame_type(puc_mac_hdr) == WLAN_FC0_TYPE_CTL) && ((mgmt_type >> 4) == WLAN_BLOCKACK_REQ)) { /* 移4 */
1906 hmac_up_rx_bar(hmac_vap, rx_ctrl);
1907 }
1908
1909 switch (mgmt_type) {
1910 case WLAN_FC0_SUBTYPE_AUTH:
1911 if (msg_len - mac_hdr_len < WLAN_FC0_AUTH_MIN_LEN) {
1912 oam_warning_log0(hmac_vap->base_vap->vap_id, OAM_SF_AUTH, "{hmac_ap_up_rx_mgmt::auth frame err.}");
1913 } else {
1914 hmac_ap_rx_auth_req(hmac_vap, (oal_netbuf_stru *)mgmt_rx_event->netbuf);
1915 }
1916 break;
1917
1918 case WLAN_FC0_SUBTYPE_DEAUTH:
1919 if (msg_len - mac_hdr_len < WLAN_FC0_DEAUTH_MIN_LEN) {
1920 oam_warning_log0(hmac_vap->base_vap->vap_id, OAM_SF_AUTH, "{hmac_ap_up_rx_mgmt::deauth frame err.}");
1921 } else {
1922 hmac_ap_rx_deauth_req(hmac_vap, puc_mac_hdr, is_protected);
1923 }
1924 break;
1925
1926 case WLAN_FC0_SUBTYPE_ASSOC_REQ:
1927 case WLAN_FC0_SUBTYPE_REASSOC_REQ:
1928 hmac_ap_up_rx_asoc_req(hmac_vap, mgmt_type, puc_mac_hdr, puc_payload, (msg_len - mac_hdr_len));
1929 break;
1930
1931 case WLAN_FC0_SUBTYPE_DISASSOC:
1932 if (msg_len - mac_hdr_len < WLAN_FC0_DISASSOC_MIN_LEN) {
1933 oam_warning_log0(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC, "{hmac_ap_up_rx_mgmt::disassoc frame err.}");
1934 } else {
1935 hmac_ap_up_rx_disasoc(hmac_vap, puc_mac_hdr, is_protected);
1936 }
1937 break;
1938
1939 case WLAN_FC0_SUBTYPE_ACTION:
1940 if (msg_len - mac_hdr_len < WLAN_FC0_ACTION_MIN_LEN) {
1941 oam_warning_log0(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC, "{hmac_ap_up_rx_mgmt::action frame err.}");
1942 } else {
1943 hmac_ap_up_rx_action(hmac_vap, (oal_netbuf_stru *)mgmt_rx_event->netbuf, is_protected);
1944 }
1945 break;
1946
1947 case WLAN_FC0_SUBTYPE_PROBE_REQ:
1948 hmac_ap_up_rx_probe_req(hmac_vap, (oal_netbuf_stru *)mgmt_rx_event->netbuf);
1949 break;
1950
1951 default:
1952 break;
1953 }
1954
1955 return HI_SUCCESS;
1956 }
1957
1958 /* ****************************************************************************
1959 功能描述 : 管理帧超时处理函数
1960 修改历史 :
1961 1.日 期 : 2013年7月1日
1962 作 者 : HiSilicon
1963 修改内容 : 新生成函数
1964 **************************************************************************** */
hmac_mgmt_timeout_ap(hi_void * param)1965 hi_u32 hmac_mgmt_timeout_ap(hi_void *param)
1966 {
1967 hmac_vap_stru *hmac_vap = HI_NULL;
1968 hmac_user_stru *hmac_user = HI_NULL;
1969 hi_u32 ret;
1970
1971 hmac_user = (hmac_user_stru *)param;
1972
1973 hmac_vap = hmac_vap_get_vap_stru(hmac_user->base_user->vap_id);
1974 if (hmac_vap == HI_NULL) {
1975 oam_error_log0(hmac_user->base_user->vap_id, OAM_SF_AUTH, "{hmac_mgmt_timeout_ap::pst_hmac_vap null.}");
1976 return HI_ERR_CODE_PTR_NULL;
1977 }
1978
1979 oam_warning_log1(hmac_user->base_user->vap_id, OAM_SF_AUTH,
1980 "{hmac_mgmt_timeout_ap::Wait AUTH timeout!! After %d ms.}", WLAN_AUTH_TIMEOUT);
1981
1982 /* 发送去关联帧消息给STA */
1983 hmac_mgmt_send_deauth_frame(hmac_vap->base_vap, hmac_user->base_user->user_mac_addr, WLAN_MAC_ADDR_LEN,
1984 MAC_AUTH_NOT_VALID);
1985
1986 ret = hmac_user_del(hmac_vap->base_vap, hmac_user);
1987 if (ret != HI_SUCCESS) {
1988 oam_warning_log1(hmac_user->base_user->vap_id, OAM_SF_AUTH,
1989 "{hmac_mgmt_timeout_ap::hmac_user_del failed[%d].}", ret);
1990 }
1991 return HI_SUCCESS;
1992 }
1993
1994 #ifdef _PRE_WLAN_FEATURE_MESH
1995 /* ****************************************************************************
1996 功能描述 : Mesh 侧接收到mesh peering confirm frame的处理入口
1997 输入参数 : [1]hmac_vap
1998 [2]puc_mac_hdr
1999 [3]puc_payload
2000 [4]payload_len
2001 返 回 值 : 处理正常或失败
2002 **************************************************************************** */
hmac_mesh_up_rx_confirm_action(const hmac_vap_stru * hmac_vap,hmac_user_stru * hmac_user,hi_u8 * puc_mac_hdr,hi_u8 * puc_payload,hi_u32 payload_len)2003 static hi_u32 hmac_mesh_up_rx_confirm_action(const hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
2004 hi_u8 *puc_mac_hdr, hi_u8 *puc_payload, hi_u32 payload_len)
2005 {
2006 hmac_update_sta_user_info_stru update_sta_user_info;
2007 hi_u32 rslt;
2008 mac_user_stru *mac_user = hmac_user->base_user;
2009
2010 if (mac_user->is_mesh_user != HI_TRUE) {
2011 oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC,
2012 "{hmac_mesh_up_rx_confirm_action::request user[%d] is not mesh user}", mac_user->us_assoc_id);
2013 return HI_ERR_CODE_MESH_NOT_MESH_USER;
2014 }
2015
2016 /* 关联状态下收到confirm Action帧不刷新驱动用户属性 */
2017 if (mac_user->user_asoc_state == MAC_USER_STATE_ASSOC) {
2018 oam_warning_log1(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC,
2019 "{hmac_mesh_up_rx_confirm_action::user[%d] assoc succ yet,dont' update user info!}",
2020 mac_user->us_assoc_id);
2021 return HI_SUCCESS;
2022 }
2023
2024 /* Mesh 和Mesh 之间无需开启pmf,因此不会触发SA query流程 */
2025 update_sta_user_info.puc_mac_hdr = puc_mac_hdr;
2026 update_sta_user_info.puc_payload = puc_payload;
2027 update_sta_user_info.msg_len = payload_len;
2028
2029 mac_status_code_enum_uint16 status_code = MAC_SUCCESSFUL_STATUSCODE;
2030 rslt = hmac_ap_up_update_sta_user(hmac_vap, &update_sta_user_info, hmac_user, &status_code);
2031 if ((rslt != HI_SUCCESS) || (status_code != MAC_SUCCESSFUL_STATUSCODE)) {
2032 oam_warning_log1(hmac_user->base_user->vap_id, OAM_SF_ASSOC,
2033 "{hmac_mesh_up_rx_confirm_action::hmac_ap_up_update_sta_user failed[%d].}", status_code);
2034 hmac_user_set_asoc_state(hmac_vap->base_vap, hmac_user->base_user, MAC_USER_STATE_AUTH_COMPLETE);
2035 }
2036
2037 /* 根据用户支持带宽能力,协商出当前带宽,dmac offload架构下,同步带宽信息到device */
2038 rslt = hmac_config_user_info_syn(hmac_vap->base_vap, hmac_user->base_user);
2039 if (rslt != HI_SUCCESS) {
2040 oam_error_log1(hmac_vap->base_vap->vap_id, OAM_SF_ASSOC,
2041 "{hmac_mesh_up_rx_confirm_action::usr_info_syn failed[%d].}", rslt);
2042 }
2043
2044 /* Mesh和Mesh之间没有802.1X */
2045 if (status_code == MAC_SUCCESSFUL_STATUSCODE) {
2046 rslt = hmac_init_user_security_port(hmac_vap->base_vap, hmac_user->base_user);
2047 if (rslt != HI_SUCCESS) {
2048 oam_error_log1(0, OAM_SF_ASSOC, "{hmac_mesh_up_rx_confirm_action::hmac_init_user_security_port Err=%d}",
2049 rslt);
2050 status_code = MAC_UNSPEC_FAIL;
2051 }
2052 }
2053
2054 /* 处理失败,上报更新用户失败发送踢用户事件到Wpa_supplicant */
2055 if ((rslt != HI_SUCCESS) || (status_code != MAC_SUCCESSFUL_STATUSCODE)) {
2056 oam_warning_log2(hmac_vap->base_vap->vap_id, OAM_SF_CFG,
2057 "{hmac_mesh_up_rx_confirm_action:: fail rslt=%d,status_code=%d", rslt, status_code);
2058 hmac_user_set_asoc_state(hmac_vap->base_vap, hmac_user->base_user, MAC_USER_STATE_AUTH_COMPLETE);
2059 return HI_FAIL;
2060 }
2061
2062 oam_warning_log1(mac_user->vap_id, OAM_SF_ASSOC, "{hmac_mesh_up_rx_confirm_action::update_sta_user[%d] succ}",
2063 mac_user->us_assoc_id);
2064
2065 return HI_SUCCESS;
2066 }
2067
2068 /* ****************************************************************************
2069 功能描述 : Mesh检查接收到的Mesh Peering Open消息中的SECURITY参数.如出错,则返回对应的错
2070 误码
2071 输入参数 : [1]hmac_vap
2072 [2]puc_payload
2073 [3]msg_len
2074 [4]hmac_user
2075 输出参数 : [1]pen_status_code
2076 返 回 值 : hi_u32
2077 **************************************************************************** */
hmac_check_open_action_sec_authenticator(const hmac_vap_stru * hmac_vap,hi_u8 * puc_payload,hi_u32 msg_len,const hmac_user_stru * hmac_user,mac_status_code_enum_uint16 * pen_status_code)2078 static hi_u32 hmac_check_open_action_sec_authenticator(const hmac_vap_stru *hmac_vap, hi_u8 *puc_payload,
2079 hi_u32 msg_len, const hmac_user_stru *hmac_user, mac_status_code_enum_uint16 *pen_status_code)
2080 {
2081 hi_u8 pcip_policy = WLAN_80211_CIPHER_SUITE_NO_ENCRYP;
2082 mac_user_stru *mac_user = NULL;
2083 hi_u8 *puc_rsn_ie = HI_NULL;
2084 hi_u8 *puc_ie = HI_NULL;
2085 hi_u8 index = 0;
2086 hi_u32 ret;
2087
2088 mac_vap_stru *mac_vap = hmac_vap->base_vap;
2089 wlan_mib_ieee802dot11_stru *mib_info = mac_vap->mib_info;
2090
2091 mib_info->wlan_mib_rsna_cfg.dot11_rsna_group_cipher_requested = 0;
2092 mib_info->wlan_mib_rsna_cfg.dot11_rsna_pairwise_cipher_requested = 0;
2093
2094 if (mib_info->wlan_mib_privacy.dot11_rsna_activated != HI_TRUE) {
2095 oam_info_log0(mac_vap->vap_id, OAM_SF_ASSOC,
2096 "{hmac_check_open_action_sec_authenticator::dot11RSNAActivated = FALSE.}");
2097 return HI_SUCCESS;
2098 }
2099
2100 if (mib_info->wlan_mib_mesh_sta_cfg.dot11_mesh_security_activated != HI_TRUE) {
2101 oam_info_log0(mac_vap->vap_id, OAM_SF_ASSOC,
2102 "{hmac_check_open_action_sec_authenticator::dot11MeshSecurityActivated = FALSE.}");
2103 return HI_SUCCESS;
2104 }
2105
2106 hi_u8 offset = MAC_ACTION_CATEGORY_LEN + MAC_ACTION_CODE_LEN + MAC_CAP_INFO_LEN;
2107
2108 if (msg_len > offset) {
2109 /* 获取RSNA信息 */
2110 puc_rsn_ie = mac_find_ie(MAC_EID_RSN, puc_payload + offset, (msg_len - offset));
2111 }
2112
2113 /* 获取RSNA信息 */
2114 puc_rsn_ie = mac_find_ie(MAC_EID_RSN, puc_payload + offset, (msg_len - offset));
2115 if (puc_rsn_ie == HI_NULL) {
2116 *pen_status_code = MAC_CIPHER_REJ;
2117 oam_info_log0(mac_vap->vap_id, OAM_SF_ASSOC,
2118 "{hmac_check_open_action_sec_authenticator::can not find RSNA ie.}");
2119 return HI_FAIL;
2120 }
2121
2122 /* RSNA加密方式处理 */
2123 /* 略过 IE + LEN */
2124 index += 2; /* 2 略过 IE + LEN */
2125 puc_ie = puc_rsn_ie;
2126
2127 ret = hmac_chk_open_action_sec_cap(mac_vap, puc_ie, DMAC_RSNA_802_11I, index, pen_status_code);
2128 if (ret != HI_SUCCESS) {
2129 return HI_FAIL;
2130 }
2131
2132 if (*pen_status_code == MAC_SUCCESSFUL_STATUSCODE) {
2133 /* 检测出来的这个硬件加密方式应该保存到 mac_user -> en_cipher_type 中 */
2134 mac_user = hmac_user->base_user;
2135 /* 保存用户的加密方式 */
2136 mac_user->key_info.cipher_type = pcip_policy;
2137 }
2138 return HI_SUCCESS;
2139 }
2140
2141 /* ****************************************************************************
2142 功能描述 : Mesh检测Mesh Open Peering 帧中的安全相关公共信息
2143 输入参数 : [1]mac_vap
2144 [2]puc_ie
2145 [3]hi_u8 uc_80211i_mode
2146 [4]offset
2147 输出参数 : [1]pen_status_code
2148 返 回 值 : hi_u32
2149 **************************************************************************** */
hmac_chk_open_action_sec_cap(const mac_vap_stru * mac_vap,const hi_u8 * puc_ie,hi_u8 is_80211i_mode,hi_u8 offset,mac_status_code_enum_uint16 * pen_status_code)2150 static hi_u32 hmac_chk_open_action_sec_cap(const mac_vap_stru *mac_vap, const hi_u8 *puc_ie, hi_u8 is_80211i_mode,
2151 hi_u8 offset, mac_status_code_enum_uint16 *pen_status_code)
2152 {
2153 hi_u8 auc_oui[MAC_OUI_LEN] = {0};
2154 hi_u8 index = offset;
2155 hi_u8 len = 0;
2156 wlan_mib_ieee802dot11_stru *mib_info = mac_vap->mib_info;
2157
2158 if (hmac_get_security_oui(is_80211i_mode, auc_oui) != HI_SUCCESS) {
2159 *pen_status_code = MAC_UNSUP_RSN_INFO_VER;
2160 oam_error_log0(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_chk_open_action_sec_cap:getSecurityOui Er}");
2161 return HI_FAIL;
2162 }
2163
2164 /* 检测版本信息 */
2165 if (mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_version != hi_makeu16(puc_ie[index], puc_ie[index + 1])) {
2166 *pen_status_code = MAC_UNSUP_RSN_INFO_VER;
2167 oam_error_log1(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_chk_open_action_sec_cap:unsup rsn ver=%d}",
2168 hi_makeu16(puc_ie[index], puc_ie[index + 1]));
2169 return HI_FAIL;
2170 }
2171
2172 /* 忽略版本信息 */
2173 index += 2; /* 2 忽略版本信息 */
2174
2175 /* 检测组播OUI 信息 */
2176 if (memcmp(auc_oui, puc_ie + index, MAC_OUI_LEN) != 0) {
2177 oam_warning_log0(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_chk_open_action_sec_cap::invalid OUI.}");
2178 }
2179 index += MAC_OUI_LEN;
2180
2181 hi_u8 grp_policy = puc_ie[index++]; /* 获取组播密钥 */
2182 hi_u8 pcip_policy = hmac_get_pcip_policy_auth(puc_ie + index, &len); /* 获取单播加密套件 */
2183
2184 index += len;
2185
2186 /* 获取认证套件信息 */
2187 hi_u8 auth_policy = hmac_get_auth_policy_auth(puc_ie + index, &len);
2188
2189 /* 成对密钥套件是否为组播密钥套件 */
2190 pcip_policy = (pcip_policy == WLAN_80211_CIPHER_SUITE_GROUP_CIPHER) ? grp_policy : pcip_policy;
2191 /* 检测组播套件 */
2192 if (mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_group_cipher != grp_policy) {
2193 *pen_status_code = MAC_INVALID_GRP_CIPHER;
2194 oam_error_log1(mac_vap->vap_id, OAM_SF_ASSOC,
2195 "{hmac_chk_open_action_sec_cap::invalid group[%d].}", grp_policy);
2196 return HI_FAIL;
2197 }
2198
2199 /* 检测单播密钥套件 (只有CCMP) */
2200 if (hmac_mesh_check_pcip_policy(pcip_policy) != HI_TRUE) {
2201 *pen_status_code = MAC_INVALID_PW_CIPHER;
2202 oam_error_log1(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_chk_open_action_sec_cap::invalid pcip[%d].}", pcip_policy);
2203 return HI_FAIL;
2204 }
2205
2206 /* 检测认证套件 (只有SAE) */
2207 if (hmac_mesh_check_auth_policy(auth_policy) == HI_FALSE) {
2208 *pen_status_code = MAC_INVALID_AKMP_CIPHER;
2209 oam_error_log1(mac_vap->vap_id, OAM_SF_ASSOC, "{hmac_chk_open_action_sec_cap::invalid auth[%d].}", auth_policy);
2210 return HI_FAIL;
2211 }
2212
2213 /* 针对RSN 情况下,做单独处理 RSN capability */
2214 /* RSN Capabilities Information */
2215 /* ----------------------------------------------------- */
2216 /* | B15 - B6 | B5 - B4 | B3 - B2 | */
2217 /* ----------------------------------------------------- */
2218 /* | Reserved | GTSKA Replay Ctr | PTSKA Replay Ctr | */
2219 /* ----------------------------------------------------- */
2220 /* | B1 | B0 | */
2221 /* ----------------------------------------------------- */
2222 /* | No Pairwise | Pre-Authentication | */
2223 /* ----------------------------------------------------- */
2224 /* 检测预认证能力 */
2225 /* 更新mib 参数 */
2226 mib_info->wlan_mib_rsna_cfg.dot11_rsna_group_cipher_requested = grp_policy;
2227 mib_info->wlan_mib_rsna_cfg.dot11_rsna_pairwise_cipher_requested = pcip_policy;
2228
2229 return HI_SUCCESS;
2230 }
2231
2232 /* ****************************************************************************
2233 功能描述 : 检测MESH单播密钥是否匹配
2234 输入参数 :hi_u8 uc_policy
2235 返 回 值 : hi_u8
2236 HI_TRUE:匹配成功
2237 HI_FALSE:匹配失败
2238 修改历史 :
2239 1.日 期 : 2019年2月21日
2240 作 者 : HiSilicon
2241 修改内容 : 新生成函数
2242 **************************************************************************** */
hmac_mesh_check_pcip_policy(hi_u8 policy)2243 hi_u8 hmac_mesh_check_pcip_policy(hi_u8 policy)
2244 {
2245 /* 检测单播密钥是否使能和匹配 */
2246 if (policy != WLAN_80211_CIPHER_SUITE_CCMP) {
2247 return HI_FALSE;
2248 }
2249 return HI_TRUE;
2250 }
2251
2252 /* ****************************************************************************
2253 功能描述 : 检测认证方式是否匹配
2254 输入参数 : hi_u8 uc_policy
2255 返 回 值 : hi_u8 HI_TRUE:匹配成功
2256 HI_FALSE:匹配失败
2257 修改历史 :
2258 1.日 期 : 2019年2月21日
2259 作 者 : HiSilicon
2260 修改内容 : 新生成函数
2261 **************************************************************************** */
hmac_mesh_check_auth_policy(hi_u8 policy)2262 hi_u8 hmac_mesh_check_auth_policy(hi_u8 policy)
2263 {
2264 /* 检测认证方式是否使能和匹配 */
2265 if (policy != WLAN_AUTH_SUITE_SAE_SHA256) {
2266 return HI_FALSE;
2267 }
2268 return HI_TRUE;
2269 }
2270 #endif
2271 #ifdef __cplusplus
2272 #if __cplusplus
2273 }
2274 #endif
2275 #endif
2276