1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 /* ****************************************************************************
20 1 头文件包含
21 **************************************************************************** */
22 #include "oal_ext_if.h"
23 #include "mac_resource.h"
24 #include "mac_frame.h"
25 #include "mac_device.h"
26 #include "mac_resource.h"
27 #include "mac_vap.h"
28 #include "hmac_11i.h"
29 #include "hmac_main.h"
30 #include "hmac_ext_if.h"
31 #include "hmac_crypto_tkip.h"
32 #include "hmac_config.h"
33
34 #ifdef __cplusplus
35 #if __cplusplus
36 extern "C" {
37 #endif
38 #endif
39 #define cipher_suite_no_encrpy(i) (((i) & WLAN_ENCRYPT_BIT) ? 0 : 1)
40 #define cipher_suite_is_wep104(i) ((((i) & WLAN_WEP104_BIT) == WLAN_WEP104_BIT) ? 1 : 0)
41 #define cipher_suite_is_wep40(i) ((((i) & WLAN_WEP104_BIT) == WLAN_WEP_BIT) ? 1 : 0)
42 #define cipher_suite_is_wpa(i) ((((i) & WLAN_WPA_BIT) == WLAN_WPA_BIT) ? 1 : 0)
43 #define cipher_suite_is_wpa2(i) ((((i) & WLAN_WPA2_BIT) == WLAN_WPA2_BIT) ? 1 : 0)
44 #define cipher_suite_is_tkip(i) ((((i) & WLAN_TKIP_BIT) == WLAN_TKIP_BIT) ? 1 : 0)
45 #define cipher_suite_is_ccmp(i) ((((i) & WLAN_CCMP_BIT) == WLAN_CCMP_BIT) ? 1 : 0)
46
47 /* ****************************************************************************
48 功能描述 : 获取key
49 修改历史 :
50 1.日 期 : 2013年11月22日
51 作 者 : HiSilicon
52 修改内容 : 新生成函数
53 **************************************************************************** */
hmac_get_key_info(mac_vap_stru * mac_vap,hi_u8 * mac_addr,hi_u8 pairwise,hi_u8 key_index,hi_u8 * pus_user_idx)54 static wlan_priv_key_param_stru *hmac_get_key_info(mac_vap_stru *mac_vap, hi_u8 *mac_addr, hi_u8 pairwise,
55 hi_u8 key_index, hi_u8 *pus_user_idx)
56 {
57 hi_u32 ret;
58 mac_user_stru *mac_user = HI_NULL;
59 hi_u8 macaddr_is_zero;
60
61 if (mac_vap == HI_NULL) {
62 oam_error_log0(0, OAM_SF_WPA, "{hmac_get_key_info::mac_vap is null}");
63 return HI_NULL;
64 }
65
66 /* 1.1 根据mac addr 找到对应sta索引号 */
67 macaddr_is_zero = mac_addr_is_zero(mac_addr);
68 if (!mac_11i_is_ptk(macaddr_is_zero, pairwise)) {
69 /* 如果是组播用户,不能使用mac地址来查找,根据索引找到组播user内存区域 */
70 *pus_user_idx = mac_vap->multi_user_idx;
71 } else { /* 单播用户 */
72 ret = mac_vap_find_user_by_macaddr(mac_vap, mac_addr, OAL_MAC_ADDR_LEN, pus_user_idx);
73 if (ret != HI_SUCCESS) {
74 return HI_NULL;
75 }
76 }
77
78 mac_user = mac_user_get_user_stru(*pus_user_idx);
79 if (mac_user == HI_NULL) {
80 oam_error_log0(mac_vap->vap_id, OAM_SF_WPA, "{hmac_get_key_info::mac_res_get_mutil_mac_user null.}");
81 return HI_NULL;
82 }
83
84 oam_info_log2(mac_vap->vap_id, OAM_SF_WPA, "{hmac_get_key_info::key_index=%d,pairwise=%d.}", key_index, pairwise);
85
86 if (mac_addr != HI_NULL) {
87 oam_info_log4(mac_vap->vap_id, OAM_SF_WPA, "{hmac_get_key_info::mac_addr[%d] = XX:XX:XX:%02X:%02X:%02X.}",
88 *pus_user_idx, mac_addr[3], mac_addr[4], mac_addr[5]); /* 3 4 5 元素索引 */
89 }
90
91 return mac_user_get_key(mac_user, key_index);
92 }
93
94 #ifdef _PRE_WLAN_FEATURE_WAPI
95 /* ****************************************************************************
96 功能描述 : 配置wapi key
97 修改历史 :
98 1.日 期 : 2015年2月26日
99 作 者 : HiSilicon
100 修改内容 : 新生成函数
101 **************************************************************************** */
hmac_config_wapi_add_key(mac_vap_stru * mac_vap,mac_addkey_param_stru * payload_addkey_params)102 hi_u32 hmac_config_wapi_add_key(mac_vap_stru *mac_vap, mac_addkey_param_stru *payload_addkey_params)
103 {
104 hi_u8 key_index;
105 hi_u8 pairwise;
106 hi_u8 *mac_addr = HI_NULL;
107 mac_key_params_stru *key_param = HI_NULL;
108 hmac_wapi_stru *wapi = HI_NULL;
109 hi_u32 ret;
110 hi_u8 user_index = 0;
111 mac_device_stru *mac_dev = HI_NULL;
112
113 key_index = payload_addkey_params->key_index;
114 if (key_index >= HMAC_WAPI_MAX_KEYID) {
115 oam_error_log1(0, OAM_SF_WPA, "{hmac_config_wapi_add_key::keyid==%u Err!.}", key_index);
116 return HI_FAIL;
117 }
118
119 pairwise = payload_addkey_params->pairwise;
120 mac_addr = (hi_u8 *)payload_addkey_params->auc_mac_addr;
121 key_param = &payload_addkey_params->key;
122
123 if (key_param->key_len != (WAPI_KEY_LEN * 2)) /* 扩大2倍 */
124 if (key_param->key_len != (WAPI_KEY_LEN * 2)) { /* 扩大2倍 */
125 oam_error_log1(0, OAM_SF_WPA, "{hmac_config_wapi_add_key:: key_len %d Err!.}", key_param->key_len);
126 return HI_FAIL;
127 }
128
129 if (pairwise == HI_TRUE) {
130 ret = mac_vap_find_user_by_macaddr(mac_vap, mac_addr, OAL_MAC_ADDR_LEN, &user_index);
131 if (ret != HI_SUCCESS) {
132 oam_error_log1(mac_vap->vap_id, OAM_SF_ANY,
133 "{hmac_config_wapi_add_key::mac_vap_find_user_by_macaddr failed. %u}", ret);
134 return HI_FAIL;
135 }
136 }
137
138 wapi = hmac_user_get_wapi_ptr(mac_vap, pairwise, user_index);
139 if (wapi == HI_NULL) {
140 oam_error_log0(0, OAM_SF_WPA, "{hmac_config_wapi_add_key:: get pst_wapi Err!.}");
141 return HI_FAIL;
142 }
143
144 hmac_wapi_add_key(wapi, key_index, key_param->auc_key);
145 mac_dev = mac_res_get_dev();
146 mac_dev->wapi = HI_TRUE;
147
148 return HI_SUCCESS;
149 }
150
151 /* ****************************************************************************
152 功能描述 : 保存wapi key并且同步
153 修改历史 :
154 1.日 期 : 2015年2月26日
155 作 者 : HiSilicon
156 修改内容 : 新生成函数
157 **************************************************************************** */
158 /* 用同一个事件回调表来定义的,改动一个就要改动所有的。有些需要const 有些不需要。现在没有办法改,lint_t告警屏蔽 */
hmac_config_wapi_add_key_and_sync(const mac_vap_stru * mac_vap,mac_addkey_param_stru * payload_addkey_params)159 hi_u32 hmac_config_wapi_add_key_and_sync(const mac_vap_stru *mac_vap, mac_addkey_param_stru *payload_addkey_params)
160 {
161 hmac_vap_stru *hmac_vap = HI_NULL;
162 hi_u32 ret;
163
164 oam_warning_log2(0, OAM_SF_WPA, "{hmac_config_wapi_add_key_and_sync:: key idx==%u, pairwise==%u}",
165 payload_addkey_params->key_index, payload_addkey_params->pairwise);
166
167 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
168 if (hmac_vap == HI_NULL) {
169 oam_error_log0(mac_vap->vap_id, OAM_SF_ANY, "{hmac_config_wapi_add_key_and_sync::pst_hmac_vap null.}");
170 return HI_ERR_CODE_PTR_NULL;
171 }
172
173 ret = hmac_config_wapi_add_key(hmac_vap->base_vap, payload_addkey_params);
174 if (ret != HI_SUCCESS) {
175 oam_error_log1(mac_vap->vap_id, OAM_SF_WPA,
176 "{hmac_config_wapi_add_key_and_sync::hmac_config_wapi_add_key fail[%d].}", ret);
177 return ret;
178 }
179
180 ret = hmac_config_send_event(mac_vap, WLAN_CFGID_ADD_WAPI_KEY, 0, HI_NULL);
181 if (ret != HI_SUCCESS) {
182 oam_error_log1(mac_vap->vap_id, OAM_SF_WPA,
183 "{hmac_config_wapi_add_key_and_sync::WLAN_CFGID_ADD_WAPI_KEY send fail[%d].}", ret);
184 return ret;
185 }
186
187 return ret;
188 }
189 #endif /* #ifdef _PRE_WLAN_FEATURE_WAPI */
190
191 /* ****************************************************************************
192 函 数 名 : hmac_config_11i_add_key
193 功能描述 : add key 逻辑,抛事件到DMAC
194 输入参数 : frw_event_mem_stru *event_mem
195 返 回 值 : 0:成功,其他:失败
196 修改历史 :
197 1.日 期 : 2013年12月26日
198 作 者 : HiSilicon
199 修改内容 : 新生成函数
200 **************************************************************************** */
hmac_config_11i_add_key(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)201 hi_u32 hmac_config_11i_add_key(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
202 {
203 hi_u8 user_idx = 0;
204
205 /* 2.1 获取参数 */
206 mac_addkey_param_stru *payload_addkey_params = (mac_addkey_param_stru *)puc_param;
207 hi_u8 key_index = payload_addkey_params->key_index;
208 hi_u8 pairwise = payload_addkey_params->pairwise;
209 hi_u8 *mac_addr = (hi_u8 *)payload_addkey_params->auc_mac_addr;
210 mac_key_params_stru *key = &(payload_addkey_params->key);
211
212 #ifdef _PRE_WLAN_FEATURE_WAPI
213 if (oal_unlikely(key->cipher == WLAN_CIPHER_SUITE_SMS4)) {
214 return hmac_config_wapi_add_key_and_sync(mac_vap, payload_addkey_params);
215 }
216 #endif
217
218 /* 2.2 索引值最大值检查 */
219 if (key_index >= WLAN_NUM_TK + WLAN_NUM_IGTK) {
220 oam_error_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_add_key::invalid uc_key_index[%d].}", key_index);
221 return HI_ERR_CODE_SECURITY_KEY_ID;
222 }
223
224 oam_info_log3(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_add_key::mac addr=XX:XX:XX:%02X:%02X:%02X}",
225 mac_addr[3], mac_addr[4], mac_addr[5]); /* 3 4 5 元素索引 */
226
227 if (pairwise == HI_TRUE) {
228 /* 单播密钥存放在单播用户中 */
229 if (mac_vap_find_user_by_macaddr(mac_vap, mac_addr, OAL_MAC_ADDR_LEN, &user_idx) != HI_SUCCESS) {
230 oam_error_log0(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_add_key::find_user_by_macaddr fail.}");
231 return HI_FAIL;
232 }
233 } else {
234 /* 组播密钥存放在组播用户中 */
235 user_idx = mac_vap->multi_user_idx;
236 }
237
238 hmac_user_stru *hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(user_idx);
239 if ((hmac_user == HI_NULL) || (hmac_user->base_user == HI_NULL)) {
240 oam_error_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_add_key::get_mac_user null.idx:%u}", user_idx);
241 return HI_ERR_CODE_SECURITY_USER_INVAILD;
242 }
243 #ifdef _PRE_WLAN_FEATURE_WAPI
244 /* 11i的情况下,关掉wapi端口 */
245 hmac_wapi_reset_port(&hmac_user->wapi);
246 mac_device_stru *mac_dev = mac_res_get_dev();
247 mac_dev->wapi = HI_FALSE;
248 #endif
249
250 /* 3.1 将加密属性更新到用户中 */
251 hi_u32 ret = mac_vap_add_key(mac_vap, hmac_user->base_user, key_index, key);
252 if (ret != HI_SUCCESS) {
253 oam_error_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_add_key::mac_11i_add_key fail[%d].}", ret);
254 return ret;
255 }
256 /* 设置用户8021x端口合法性的状态为合法 */
257 hmac_user->base_user->port_valid = HI_TRUE;
258
259 /* **************************************************************************
260 抛事件到DMAC层, 同步DMAC数据
261 ************************************************************************** */
262 ret = hmac_config_send_event(mac_vap, WLAN_CFGID_ADD_KEY, us_len, puc_param);
263 if (oal_unlikely(ret != HI_SUCCESS)) {
264 oam_warning_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_add_key:hmac_config_send_event fail[%d]}", ret);
265 }
266
267 return ret;
268 }
269
270 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
271 /* ****************************************************************************
272 功能描述 : 获取密钥,不需要抛事件到DMAC,直接从hmac数据区中拿数据
273 输入参数 : frw_event_mem_stru *event_mem
274 返 回 值 : 0:成功,其他:失败
275 修改历史 :
276 1.日 期 : 2013年8月16日
277 作 者 : HiSilicon
278 修改内容 : 新生成函数
279 2.日 期 : 2014年1月4日
280 作 者 : HiSilicon
281 修改内容 : 使用局部变量替代malloc,以减少释放内存的复杂度
282 **************************************************************************** */
hmac_config_11i_get_key(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)283 hi_u32 hmac_config_11i_get_key(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
284 {
285 wlan_priv_key_param_stru *priv_key = HI_NULL;
286 oal_key_params_stru key;
287 hi_u8 key_index;
288 hi_u8 pairwise;
289 hi_u8 *mac_addr = HI_NULL;
290 hi_void *cookie = HI_NULL;
291 mac_getkey_param_stru *payload_getkey_params = HI_NULL;
292 hi_u8 us_user_idx = MAC_INVALID_USER_ID;
293 hi_unref_param(us_len);
294
295 /* 2.1 获取参数 */
296 payload_getkey_params = (mac_getkey_param_stru *)puc_param;
297 key_index = payload_getkey_params->key_index;
298 pairwise = payload_getkey_params->pairwise;
299 mac_addr = payload_getkey_params->puc_mac_addr;
300 cookie = payload_getkey_params->cookie;
301
302 /* 2.2 索引值最大值检查 */
303 if (key_index >= WLAN_NUM_TK + WLAN_NUM_IGTK) {
304 oam_error_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_get_key::uc_key_index invalid[%d].}", key_index);
305 return HI_ERR_CODE_SECURITY_KEY_ID;
306 }
307
308 /* 3.1 获取密钥 */
309 priv_key = hmac_get_key_info(mac_vap, mac_addr, pairwise, key_index, &us_user_idx);
310 if (priv_key == HI_NULL) {
311 oam_error_log2(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_get_key::key is null.pairwise[%d], key_idx[%d]}",
312 pairwise, key_index);
313 return HI_ERR_CODE_PTR_NULL;
314 }
315
316 /* 四次握手获取密钥信息长度为0 是正常值,不应该为error 级别打印 */
317 if (priv_key->key_len == 0) {
318 oam_info_log2(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_get_key::key len = 0.pairwise[%d], key_idx[%d]}",
319 pairwise, key_index);
320 return HI_ERR_CODE_SECURITY_KEY_LEN;
321 }
322
323 /* 4.1 密钥赋值转换 */
324 /* 安全编程规则6.6例外(1) 对固定长度的数组进行初始化,或对固定长度的结构体进行内存初始化 */
325 memset_s(&key, sizeof(oal_key_params_stru), 0, sizeof(key));
326 key.key = priv_key->auc_key;
327 key.key_len = (hi_s32)priv_key->key_len;
328 key.seq = priv_key->auc_seq;
329 key.seq_len = (hi_s32)priv_key->seq_len;
330 key.cipher = priv_key->cipher;
331
332 /* 5.1 调用回调函数 */
333 if (payload_getkey_params->callback != HI_NULL) {
334 payload_getkey_params->callback(cookie, &key);
335 }
336
337 return HI_SUCCESS;
338 }
339 #endif
340
341 /* ****************************************************************************
342 功能描述 : 处理remove key事件,抛事件到DMAC
343 输入参数 : mac_vap_stru *pst_mac_vap, hi_u16 us_len, hi_u8 *puc_param
344 返 回 值 : 0:成功,其他:失败
345 修改历史 :
346 1.日 期 : 2014年1月4日
347 作 者 : HiSilicon
348 修改内容 : 新生成函数
349 **************************************************************************** */
hmac_config_11i_remove_key(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * param)350 hi_u32 hmac_config_11i_remove_key(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *param)
351 {
352 mac_removekey_param_stru *removekey = (mac_removekey_param_stru *)param;
353 mac_user_stru *mac_user = HI_NULL;
354 wlan_cfgid_enum_uint16 cfgid = WLAN_CFGID_REMOVE_WEP_KEY;
355 hi_u8 user_idx = MAC_INVALID_USER_ID;
356
357 /* 2.1 获取参数 */
358 hi_u8 key_index = removekey->key_index;
359 hi_u8 pairwise = removekey->pairwise;
360
361 oam_info_log2(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_remove_key::key%d,pairwise%d}", key_index, pairwise);
362
363 /* 2.2 索引值最大值检查 */
364 if ((key_index >= WLAN_NUM_TK + WLAN_NUM_IGTK) || (key_index >= WLAN_NUM_DOT11WEPDEFAULTKEYVALUE)) {
365 /* 内核会下发删除6 个组播密钥,驱动现有6个组播密钥保存空间 */
366 oam_info_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_remove_key::invalid key_index%d}", key_index);
367 return HI_SUCCESS;
368 }
369
370 /* 3.1 获取本地密钥信息 */
371 wlan_priv_key_param_stru *key = hmac_get_key_info(mac_vap, removekey->auc_mac_addr, pairwise, key_index, &user_idx);
372 if (key == HI_NULL) {
373 oam_warning_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_remove_key::user_idx=%d}", user_idx);
374 return ((user_idx == MAC_INVALID_USER_ID) ? HI_SUCCESS : HI_ERR_CODE_SECURITY_USER_INVAILD);
375 }
376
377 if (key->key_len == 0) {
378 /* 如果检测到密钥没有使用, 则直接返回正确 */
379 oam_info_log0(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_remove_key::ul_key_len=0.}");
380 return HI_SUCCESS;
381 }
382
383 /* 4.1 区分是wep还是wpa */
384 if ((key->cipher == WLAN_CIPHER_SUITE_WEP40) || (key->cipher == WLAN_CIPHER_SUITE_WEP104)) {
385 mac_mib_set_wep(mac_vap, key_index);
386 } else {
387 hi_u8 macaddr_is_zero = mac_addr_is_zero(removekey->auc_mac_addr);
388 if (mac_11i_is_ptk(macaddr_is_zero, pairwise)) {
389 mac_user = mac_vap_get_user_by_addr(mac_vap, removekey->auc_mac_addr);
390 if (mac_user == HI_NULL) {
391 return HI_ERR_CODE_SECURITY_USER_INVAILD;
392 }
393 mac_user->user_tx_info.security.cipher_key_type = HAL_KEY_TYPE_BUTT;
394 } else {
395 mac_user = mac_user_get_user_stru(mac_vap->multi_user_idx);
396 if (mac_user == HI_NULL) {
397 return HI_ERR_CODE_SECURITY_USER_INVAILD;
398 }
399 }
400 cfgid = WLAN_CFGID_REMOVE_KEY;
401 mac_user->port_valid = HI_FALSE;
402 }
403
404 /* 4.2 抛事件到dmac层处理 */
405 hi_u32 ret = hmac_config_send_event(mac_vap, cfgid, us_len, param);
406 if (oal_unlikely(ret != HI_SUCCESS)) {
407 oam_error_log2(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_remove_key:SendEvent Err%d,cfgid%d}", ret, cfgid);
408 return ret;
409 }
410
411 /* 5.1 删除密钥成功,设置密钥长度为0 */
412 key->key_len = 0;
413
414 return ret;
415 }
416
417 /* ****************************************************************************
418 函 数 名 : hmac_config_11i_set_default_key
419 功能描述 : 处理set default key事件,抛事件到DMAC
420 输入参数 : mac_vap_stru *pst_mac_vap, hi_u16 us_len, hi_u8 *puc_param
421 输出参数 : hi_u32
422 返 回 值 : 0:成功,其他:失败
423 修改历史 :
424 1.日 期 : 2014年1月4日
425 作 者 : HiSilicon
426 修改内容 : 新生成函数
427 2.日 期 : 2014年7月31日
428 作 者 : HiSilicon
429 修改内容 : 合并设置数据帧默认密钥和设置管理帧默认密钥函数
430 **************************************************************************** */
431 /* 用同一个事件回调表来定义的,改动一个就要改动所有的。有些需要const 有些不需要。现在没有办法改,lint_t告警屏蔽 */
hmac_config_11i_set_default_key(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)432 hi_u32 hmac_config_11i_set_default_key(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
433 {
434 hi_u32 ret = HI_SUCCESS;
435 hi_u8 key_index;
436 hi_u8 unicast;
437 hi_u8 multicast;
438 mac_setdefaultkey_param_stru *payload_setdefaultkey_params = HI_NULL;
439
440 /* 2.1 获取参数 */
441 payload_setdefaultkey_params = (mac_setdefaultkey_param_stru *)puc_param;
442 key_index = payload_setdefaultkey_params->key_index;
443 unicast = payload_setdefaultkey_params->unicast;
444 multicast = payload_setdefaultkey_params->multicast;
445
446 /* 2.2 索引值最大值检查 */
447 if (key_index >= (WLAN_NUM_TK + WLAN_NUM_IGTK)) {
448 oam_error_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_set_default_key::invalid uc_key_index[%d].}",
449 key_index);
450 return HI_ERR_CODE_SECURITY_KEY_ID;
451 }
452
453 /* 2.3 参数有效性检查 */
454 if ((multicast == HI_FALSE) && (unicast == HI_FALSE)) {
455 oam_error_log0(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_set_default_key::not ptk or gtk,invalid mode.}");
456 return HI_ERR_CODE_SECURITY_PARAMETERS;
457 }
458
459 if (key_index >= WLAN_NUM_TK) {
460 /* 3.1 设置default mgmt key属性 */
461 ret = mac_vap_set_default_mgmt_key(mac_vap, key_index);
462 } else {
463 ret = mac_vap_set_default_key(mac_vap, key_index);
464 }
465
466 if (ret != HI_SUCCESS) {
467 oam_error_log2(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_set_default_key::set key[%d] failed[%d].}",
468 key_index, ret);
469 return ret;
470 }
471
472 /* **************************************************************************
473 抛事件到DMAC层, 同步DMAC数据
474 ************************************************************************** */
475 ret = hmac_config_send_event(mac_vap, WLAN_CFGID_DEFAULT_KEY, us_len, puc_param);
476 if (oal_unlikely(ret != HI_SUCCESS)) {
477 oam_error_log1(mac_vap->vap_id, OAM_SF_WPA,
478 "{hmac_config_11i_set_default_key::hmac_config_send_event failed[%d].}", ret);
479 }
480 oam_info_log3(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_set_default_key::key_id[%d] un[%d] mu[%d] OK}",
481 key_index, unicast, multicast);
482 return ret;
483 }
484
485 /* ****************************************************************************
486 功能描述 : add wep加密,抛事件到DMAC
487 输入参数 : mac_vap_stru *pst_mac_vap, hi_u16 us_len, hi_u8 *puc_param
488 返 回 值 : 0:成功,其他:失败
489 修改历史 :
490 1.日 期 : 2013年11月13日
491 作 者 : HiSilicon
492 修改内容 : 新生成函数
493 **************************************************************************** */
hmac_config_11i_add_wep_entry(mac_vap_stru * mac_vap,hi_u16 us_len,const hi_u8 * puc_param)494 hi_u32 hmac_config_11i_add_wep_entry(mac_vap_stru *mac_vap, hi_u16 us_len, const hi_u8 *puc_param)
495 {
496 mac_user_stru *mac_user = HI_NULL;
497 hi_u32 ret;
498
499 mac_user = mac_vap_get_user_by_addr(mac_vap, puc_param);
500 if (mac_user == HI_NULL) {
501 oam_error_log0(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_add_wep_entry::mac_user NULL}");
502 return HI_ERR_CODE_PTR_NULL;
503 }
504
505 ret = mac_user_update_wep_key(mac_user, mac_vap->multi_user_idx);
506 if (ret != HI_SUCCESS) {
507 oam_error_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_add_wep_entry::mac_wep_add_usr_key failed[%d].}",
508 ret);
509 return ret;
510 }
511
512 /* **************************************************************************
513 抛事件到DMAC层, 同步DMAC数据
514 ************************************************************************** */
515 ret = hmac_config_send_event(mac_vap, WLAN_CFGID_ADD_WEP_ENTRY, us_len, puc_param);
516 if (oal_unlikely(ret != HI_SUCCESS)) {
517 oam_warning_log1(mac_vap->vap_id, OAM_SF_WPA,
518 "{hmac_config_11i_add_wep_entry::hmac_config_send_event failed[%d].}", ret);
519 }
520
521 /* 设置用户的发送加密套件 */
522 oam_info_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_config_11i_add_wep_entry:: usridx[%d] OK.}",
523 mac_user->us_assoc_id);
524
525 return ret;
526 }
527
528 /* ****************************************************************************
529 功能描述 : 初始化加密数据。
530 修改历史 :
531 1.日 期 : 2013年10月18日
532 作 者 : HiSilicon
533 修改内容 : 新生成函数
534 **************************************************************************** */
hmac_init_security(mac_vap_stru * mac_vap,hi_u8 * mac_addr,hi_u16 addr_len)535 hi_u32 hmac_init_security(mac_vap_stru *mac_vap, hi_u8 *mac_addr, hi_u16 addr_len)
536 {
537 hi_u32 ret = HI_SUCCESS;
538 hi_u16 us_len;
539 hi_u8 *puc_param = HI_NULL;
540
541 if (mac_is_wep_enabled(mac_vap) == HI_TRUE) {
542 puc_param = mac_addr;
543 us_len = addr_len;
544 ret = hmac_config_11i_add_wep_entry(mac_vap, us_len, puc_param);
545 }
546 return ret;
547 }
548
549 /* ****************************************************************************
550 功能描述 : 检测单播wpa密钥是否匹配
551 输入参数 : wlan_mib_ieee802dot11_stru *pst_mib_info
552 hi_u8 uc_policy
553 返 回 值 : hi_u8 HI_TRUE:匹配成功
554 HI_FALSE:匹配失败
555 修改历史 :
556 1.日 期 : 2013年8月31日
557 作 者 : HiSilicon
558 修改内容 : 新生成函数
559 **************************************************************************** */
hmac_check_pcip_wpa_policy(const wlan_mib_ieee802dot11_stru * mib_info,hi_u8 policy)560 hi_u8 hmac_check_pcip_wpa_policy(const wlan_mib_ieee802dot11_stru *mib_info, hi_u8 policy)
561 {
562 hi_u8 loop = 0;
563 for (loop = 0; loop < MAC_PAIRWISE_CIPHER_SUITES_NUM; loop++) {
564 /* 检测单播密钥是否使能和匹配 */
565 if ((mib_info->ast_wlan_mib_rsna_cfg_wpa_pairwise_cipher[loop].dot11_rsna_config_pairwise_cipher_activated == HI_TRUE) &&
566 (mib_info->ast_wlan_mib_rsna_cfg_wpa_pairwise_cipher[loop].dot11_rsna_config_pairwise_cipher_implemented == policy)) {
567 return HI_TRUE;
568 }
569 }
570 return HI_FALSE;
571 }
572
573 /* ****************************************************************************
574 功能描述 : 检测单播wpa2密钥是否匹配
575 输入参数 : wlan_mib_ieee802dot11_stru *pst_mib_info
576 hi_u8 uc_policy
577 返 回 值 : hi_u8 HI_TRUE:匹配成功
578 HI_FALSE:匹配失败
579 修改历史 :
580 1.日 期 : 2013年8月31日
581 作 者 : HiSilicon
582 修改内容 : 新生成函数
583 **************************************************************************** */
hmac_check_pcip_wpa2_policy(const wlan_mib_ieee802dot11_stru * mib_info,hi_u8 policy)584 hi_u8 hmac_check_pcip_wpa2_policy(const wlan_mib_ieee802dot11_stru *mib_info, hi_u8 policy)
585 {
586 hi_u8 loop = 0;
587 for (loop = 0; loop < MAC_PAIRWISE_CIPHER_SUITES_NUM; loop++) {
588 /* 检测单播密钥是否使能和匹配 */
589 if ((mib_info->ast_wlan_mib_rsna_cfg_wpa2_pairwise_cipher[loop].dot11_rsna_config_pairwise_cipher_activated == HI_TRUE) &&
590 (mib_info->ast_wlan_mib_rsna_cfg_wpa2_pairwise_cipher[loop].dot11_rsna_config_pairwise_cipher_implemented == policy)) {
591 return HI_TRUE;
592 }
593 }
594 return HI_FALSE;
595 }
596
597 /* ****************************************************************************
598 功能描述 : 检测单播密钥是否匹配
599 输入参数 : wlan_mib_ieee802dot11_stru *pst_mib_info
600 hi_u8 uc_policy
601 hi_u8 uc_80211i_mode
602 返 回 值 : hi_u32 HI_SUCCESS:匹配成功
603 HI_FAIL:匹配失败
604 修改历史 :
605 1.日 期 : 2013年12月13日
606 作 者 : HiSilicon
607 修改内容 : 新生成函数
608 **************************************************************************** */
hmac_check_pcip_policy(const wlan_mib_ieee802dot11_stru * mib_info,hi_u8 policy,hi_u8 is_80211i_mode)609 hi_u32 hmac_check_pcip_policy(const wlan_mib_ieee802dot11_stru *mib_info, hi_u8 policy, hi_u8 is_80211i_mode)
610 {
611 hi_u8 ret = HI_FALSE;
612
613 if (is_80211i_mode == DMAC_WPA_802_11I) {
614 ret = hmac_check_pcip_wpa_policy(mib_info, policy);
615 } else if (is_80211i_mode == DMAC_RSNA_802_11I) {
616 ret = hmac_check_pcip_wpa2_policy(mib_info, policy);
617 } else {
618 ret = HI_FALSE;
619 }
620
621 if (ret == HI_TRUE) {
622 return HI_SUCCESS;
623 } else {
624 return HI_ERR_CODE_SECURITY_CHIPER_TYPE;
625 }
626 }
627
628 /* ****************************************************************************
629 功能描述 : 检查RSN能力是否匹配
630 输入参数 : [1]mac_vap
631 [2]puc_rsn_ie
632 [3]pen_status_code
633 返 回 值 : hi_u32
634 **************************************************************************** */
hmac_check_rsn_capability(const mac_vap_stru * mac_vap,const hi_u8 * puc_rsn_ie,mac_status_code_enum_uint16 * pen_status_code)635 hi_u32 hmac_check_rsn_capability(const mac_vap_stru *mac_vap, const hi_u8 *puc_rsn_ie,
636 mac_status_code_enum_uint16 *pen_status_code)
637 {
638 wlan_mib_ieee802dot11_stru *mib_info = HI_NULL;
639 hi_u16 us_rsn_capability;
640 hi_u8 preauth_activated;
641 hi_u8 dot11_rsnamfpr;
642 hi_u8 dot11_rsnamfpc;
643
644 mib_info = mac_vap->mib_info;
645 if (mib_info == HI_NULL) {
646 *pen_status_code = MAC_INVALID_RSN_INFO_CAP;
647 oam_error_log0(mac_vap->vap_id, OAM_SF_WPA, "{hmac_check_rsn_capability::pst_mib_info null.}");
648 return HI_ERR_CODE_PTR_NULL;
649 }
650
651 us_rsn_capability = mac_get_rsn_capability(puc_rsn_ie);
652
653 /* 2.1 预认证能力检查 */
654 preauth_activated = us_rsn_capability & BIT0;
655 if (preauth_activated != mib_info->wlan_mib_privacy.dot11_rsna_preauthentication_activated) {
656 *pen_status_code = MAC_INVALID_RSN_INFO_CAP;
657 oam_warning_log1(mac_vap->vap_id, OAM_SF_WPA,
658 "{hmac_check_rsn_capability::VAP not supported PreauthActivated[%d].}", preauth_activated);
659 return HI_ERR_CODE_SECURITY_AUTH_TYPE;
660 }
661
662 /* 3.1 管理帧加密(80211w)能力检查 */
663 dot11_rsnamfpr = (us_rsn_capability & BIT6) ? HI_TRUE : HI_FALSE;
664 dot11_rsnamfpc = (us_rsn_capability & BIT7) ? HI_TRUE : HI_FALSE;
665 /* 3.1.1 本地强制,对端没有MFP能力 */
666 if ((mib_info->wlan_mib_privacy.dot11_rsnamfpr == HI_TRUE) && (dot11_rsnamfpc == HI_FALSE)) {
667 *pen_status_code = MAC_MFP_VIOLATION;
668 oam_warning_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_check_rsn_capability::refuse with NON MFP[%d].}",
669 preauth_activated);
670 return HI_ERR_CODE_SECURITY_CAP_MFP;
671 }
672 /* 3.1.2 对端强制,本地没有MFP能力 */
673 if ((mib_info->wlan_mib_privacy.dot11_rsnamfpc == HI_FALSE) && (dot11_rsnamfpr == HI_TRUE)) {
674 *pen_status_code = MAC_MFP_VIOLATION;
675 oam_warning_log1(mac_vap->vap_id, OAM_SF_WPA, "{hmac_check_rsn_capability::VAP not supported RSNA MFP[%d].}",
676 preauth_activated);
677 return HI_ERR_CODE_SECURITY_CAP_MFP;
678 }
679 return HI_SUCCESS;
680 }
681
682 /* ****************************************************************************
683 功能描述 : 根据WPA/WPA2模式获取WPA/WPA2 oui
684 修改历史 :
685 1.日 期 : 2013年12月17日
686 作 者 : HiSilicon
687 修改内容 : 新生成函数
688 **************************************************************************** */
hmac_get_security_oui(hi_u8 is_80211i_mode,hi_u8 * auc_oui)689 hi_u32 hmac_get_security_oui(hi_u8 is_80211i_mode, hi_u8 *auc_oui)
690 {
691 if (is_80211i_mode == DMAC_WPA_802_11I) {
692 auc_oui[0] = (hi_u8)MAC_WLAN_OUI_MICRO0;
693 auc_oui[1] = (hi_u8)MAC_WLAN_OUI_MICRO1;
694 auc_oui[2] = (hi_u8)MAC_WLAN_OUI_MICRO2; /* 2 元素索引 */
695 } else if (is_80211i_mode == DMAC_RSNA_802_11I) {
696 auc_oui[0] = (hi_u8)MAC_WLAN_OUI_RSN0;
697 auc_oui[1] = (hi_u8)MAC_WLAN_OUI_RSN1;
698 auc_oui[2] = (hi_u8)MAC_WLAN_OUI_RSN2; /* 2 元素索引 */
699 } else {
700 return HI_ERR_WIFI_HMAC_INVALID_PARAMETER;
701 }
702 return HI_SUCCESS;
703 }
704
705 /* ****************************************************************************
706 功能描述 : 从数据包中提取出单播加密套件信息
707 输入参数 : hi_u8 *puc_frame WPA/WPA2 信息元素中,保存的单播起始地址
708 hi_u8 *puc_len 加密信息长度
709 hi_u8 *puc_oui WPA/WPA2 信息元素OUI
710 返 回 值 : hi_u8 获取的单播套件信息
711 修改历史 :
712 1.日 期 : 2013年8月26日
713 作 者 : HiSilicon
714 修改内容 : 新生成函数
715 **************************************************************************** */
hmac_get_pcip_policy_auth(const hi_u8 * puc_frame,hi_u8 * puc_len)716 hi_u8 hmac_get_pcip_policy_auth(const hi_u8 *puc_frame, hi_u8 *puc_len)
717 {
718 hi_u8 indext;
719 hi_u8 pcip_policy = 0;
720
721 /* *********************************************************************** */
722 /* RSN Element Pairwise Ciper Format */
723 /* --------------------------------------------------------------------- */
724 /* | Pairwise Cipher Count | Pairwise Cipher Suite List | */
725 /* --------------------------------------------------------------------- */
726 /* | 2 | 4*m | */
727 /* --------------------------------------------------------------------- */
728 /* *********************************************************************** */
729 /* 获取数据包中,成对密钥套件总的字节数 */
730 *puc_len = (hi_u8)(puc_frame[0] * 4) + 2; /* 4 2 用于计算 */
731
732 /* ASSOC REQ 中的单播套件个数只能为1个 */
733 if (puc_frame[0] == 1) {
734 indext = 2; /* 忽略单播套件的2 字节 */
735 indext += MAC_OUI_LEN; /* 忽略OUI 长度 */
736 pcip_policy = puc_frame[indext]; /* 获取单播加密套件 */
737 } else {
738 pcip_policy = 0xFF;
739 }
740
741 return pcip_policy;
742 }
743
744 /* ****************************************************************************
745 功能描述 : 从数据包中提取出认证套件信息
746 输入参数 : [1]puc_frame
747 [2]len
748 返 回 值 : hi_u8
749 **************************************************************************** */
hmac_get_auth_policy_auth(const hi_u8 * puc_frame,hi_u8 * len)750 hi_u8 hmac_get_auth_policy_auth(const hi_u8 *puc_frame, hi_u8 *len)
751 {
752 hi_u8 index;
753 hi_u8 auth_policy = 0;
754
755 /* *********************************************************************** */
756 /* RSN Element AKM Suite Format */
757 /* --------------------------------------------------------------------- */
758 /* | AKM Cipher Count | AKM Cipher Suite List | */
759 /* --------------------------------------------------------------------- */
760 /* | 2 | 4*s | */
761 /* --------------------------------------------------------------------- */
762 /* *********************************************************************** */
763 /* 获取数据包中,认证套件总的字节数 */
764 *len = (hi_u8)(puc_frame[0] * 4) + 2; /* 4 2 用于计算 */
765
766 /* ASSOC REQ 中的单播套件个数只能为1个 */
767 if (puc_frame[0] == 1) {
768 index = 2; /* 忽略AKM 套件数的2字节 */
769 index += MAC_OUI_LEN; /* 忽略OUI 长度 */
770 auth_policy = puc_frame[index]; /* 获取认证套件 */
771 } else {
772 auth_policy = 0xFF;
773 }
774 return auth_policy;
775 }
776
777 /* ****************************************************************************
778 功能描述 : STA 检测扫描到的单播加密能力和设备能力是否匹配。
779 输入参数 : [1]mib_info
780 [2]puc_pcip_policy_match
781 [3]is_802_11i_mode
782 [4]puc_pcip_policy
783 返 回 值 : hi_u32
784 **************************************************************************** */
hmac_check_join_req_parewise_cipher_supplicant(const wlan_mib_ieee802dot11_stru * mib_info,hi_u8 * puc_pcip_policy_match,hi_u8 is_802_11i_mode,const hi_u8 * puc_pcip_policy)785 hi_u32 hmac_check_join_req_parewise_cipher_supplicant(const wlan_mib_ieee802dot11_stru *mib_info,
786 hi_u8 *puc_pcip_policy_match, hi_u8 is_802_11i_mode, const hi_u8 *puc_pcip_policy)
787 {
788 hi_u8 loop = 0;
789 hi_u8 ret = HI_FALSE;
790 if (puc_pcip_policy == HI_NULL || puc_pcip_policy_match == HI_NULL) {
791 oam_error_log0(0, OAM_SF_ANY,
792 "{hmac_check_join_req_parewise_cipher_supplicant::puc_pcip_policy/puc_pcip_policy_match is NULL!}\r\n");
793 return HI_ERR_CODE_PTR_NULL;
794 }
795
796 /* 初始设置单播匹配为无效数据 */
797 *puc_pcip_policy_match = 0xFF;
798
799 /* 从STA mib 中查找和 AP 能力匹配的单播加密方式 */
800 for (loop = 0; loop < MAC_PAIRWISE_CIPHER_SUITES_NUM; loop++) {
801 if (puc_pcip_policy[loop] == WLAN_80211_CIPHER_SUITE_GROUP_CIPHER) {
802 /* 成对密钥套件选择组播加密套件 */
803 *puc_pcip_policy_match = WLAN_80211_CIPHER_SUITE_GROUP_CIPHER;
804 break;
805 } else if (puc_pcip_policy[loop] == 0xFF) {
806 /* 如果没有找到,继续查找成对加密套件 */
807 continue;
808 }
809
810 /* 检测成对密钥套件 */
811 /* 检测单播密钥套件 */
812 if (is_802_11i_mode == DMAC_WPA_802_11I) {
813 ret = hmac_check_pcip_wpa_policy(mib_info, puc_pcip_policy[loop]);
814 } else {
815 ret = hmac_check_pcip_wpa2_policy(mib_info, puc_pcip_policy[loop]);
816 }
817 if (ret == HI_TRUE) {
818 *puc_pcip_policy_match = puc_pcip_policy[loop];
819 if (WLAN_80211_CIPHER_SUITE_CCMP == puc_pcip_policy[loop]) {
820 break;
821 }
822 }
823 }
824
825 /* 检测单播密钥是否匹配成功 */
826 if (*puc_pcip_policy_match == 0xFF) {
827 oam_error_log0(0, OAM_SF_WPA, "{hmac_check_join_req_parewise_cipher_supplicant::pariwise not match.}");
828 for (loop = 0; loop < MAC_PAIRWISE_CIPHER_SUITES_NUM; loop++) {
829 oam_error_log2(0, OAM_SF_WPA, "{hmac_check_join_req_parewise_cipher_supplicant::user pairwise[%d]=%d.}",
830 loop, puc_pcip_policy[loop]);
831 }
832 return HI_ERR_CODE_SECURITY_CHIPER_TYPE;
833 }
834 return HI_SUCCESS;
835 }
836
837 /* ****************************************************************************
838 功能描述 : STA 检测扫描到的认证套件和设备能力是否匹配。
839 输入参数 : [1]pst_mib_info
840 [2]puc_auth_policy_match
841 [3]puc_auth_policy
842 返 回 值 : static hi_u32
843 **************************************************************************** */
hmac_check_join_req_auth_suite_supplicant(const wlan_mib_ieee802dot11_stru * mib_info,hi_u8 * puc_auth_policy_match,const hi_u8 * puc_auth_policy)844 static hi_u32 hmac_check_join_req_auth_suite_supplicant(const wlan_mib_ieee802dot11_stru *mib_info,
845 hi_u8 *puc_auth_policy_match, const hi_u8 *puc_auth_policy)
846 {
847 hi_u8 loop = 0;
848
849 /* 设置认证匹配为无效数据 */
850 *puc_auth_policy_match = 0xFF;
851
852 /* 查找STA 和 AP 能力匹配的认证方式 */
853 for (loop = 0; loop < MAC_AUTHENTICATION_SUITE_NUM; loop++) {
854 /* 如果没有找到对应的认证套件,则继续 */
855 if (puc_auth_policy[loop] == 0xFF) {
856 continue;
857 }
858
859 /* 如果找到对应认证套件,则和本地认证套件比较 */
860 if (mac_check_auth_policy(mib_info, puc_auth_policy[loop]) == HI_TRUE) {
861 *puc_auth_policy_match = puc_auth_policy[loop];
862 }
863 }
864
865 if (*puc_auth_policy_match == 0xFF) {
866 oam_error_log1(0, OAM_SF_WPA, "{hmac_check_join_req_security_cap_supplicant::user auth=%d.}",
867 puc_auth_policy[0]);
868 return HI_ERR_CODE_SECURITY_AUTH_TYPE;
869 }
870 return HI_SUCCESS;
871 }
872
873 /* ****************************************************************************
874 功能描述 : STA 检测扫描到的 RSN/WPA 加密能力和设备能力是否匹配。
875 输入参数 : mac_bss_dscr_stru *st_bss_dscr AP 的BSS 结构
876 hi_u8 uc_802_11i_mode STA 支持的安全加密模式
877 hi_u8 *puc_grp_policy_match
878 hi_u8 *puc_pcip_policy_match
879 hi_u8 *puc_auth_policy_match
880 hi_u8 uc_802_11i_mode WPA/WPA2
881 返 回 值 : hi_u32 HI_SUCCESS 匹配成功
882 HI_FAIL 匹配失败
883 修改历史 :
884 1.日 期 : 2013年8月22日
885 作 者 : HiSilicon
886 修改内容 : 新生成函数
887 **************************************************************************** */
hmac_check_join_req_security_cap_supplicant(mac_bss_dscr_stru * bss_dscr,const wlan_mib_ieee802dot11_stru * mib_info,const hmac_cap_supplicant_info_stru * cap_supplicant_info,hi_u8 is_802_11i_mode)888 static hi_u32 hmac_check_join_req_security_cap_supplicant(mac_bss_dscr_stru *bss_dscr,
889 const wlan_mib_ieee802dot11_stru *mib_info, const hmac_cap_supplicant_info_stru *cap_supplicant_info,
890 hi_u8 is_802_11i_mode)
891 {
892 hi_u8 *puc_pcip_policy = HI_NULL;
893 hi_u8 *puc_auth_policy = HI_NULL;
894 hi_u8 grp_policy = 0;
895 hi_u32 check_status;
896
897 if ((bss_dscr->bss_sec_info.bss_80211i_mode & is_802_11i_mode) != is_802_11i_mode) {
898 oam_error_log1(0, OAM_SF_WPA, "{hmac_check_join_req_security_cap_supplicant::80211i modeh=%d.}",
899 is_802_11i_mode);
900 return HI_ERR_CODE_SECURITY_CHIPER_TYPE;
901 }
902
903 if (is_802_11i_mode == DMAC_RSNA_802_11I) {
904 puc_pcip_policy = bss_dscr->bss_sec_info.auc_rsn_pairwise_policy;
905 puc_auth_policy = bss_dscr->bss_sec_info.auc_rsn_auth_policy;
906 grp_policy = bss_dscr->bss_sec_info.rsn_grp_policy;
907 } else {
908 puc_pcip_policy = bss_dscr->bss_sec_info.auc_wpa_pairwise_policy;
909 puc_auth_policy = bss_dscr->bss_sec_info.auc_wpa_auth_policy;
910 grp_policy = bss_dscr->bss_sec_info.wpa_grp_policy;
911 }
912
913 /* 组播密钥 */
914 *(cap_supplicant_info->puc_grp_policy_match) = grp_policy;
915
916 /* 检查单播密钥套件 */
917 check_status = hmac_check_join_req_parewise_cipher_supplicant(mib_info, cap_supplicant_info->puc_pcip_policy_match,
918 is_802_11i_mode, puc_pcip_policy);
919 if (check_status != HI_SUCCESS) {
920 return HI_ERR_CODE_SECURITY_CHIPER_TYPE;
921 }
922
923 /* 检查认证密钥套件 */
924 check_status = hmac_check_join_req_auth_suite_supplicant(mib_info, cap_supplicant_info->puc_auth_policy_match,
925 puc_auth_policy);
926 if (check_status != HI_SUCCESS) {
927 return HI_ERR_CODE_SECURITY_AUTH_TYPE;
928 }
929
930 oam_info_log3(0, OAM_SF_WPA, "{hmac_check_join_req_security_cap_supplicant::group=%d, pairwise=%d, auth=%d.}",
931 *(cap_supplicant_info->puc_grp_policy_match), *(cap_supplicant_info->puc_pcip_policy_match),
932 *(cap_supplicant_info->puc_auth_policy_match));
933
934 return HI_SUCCESS;
935 }
936
hmac_check_security_capability_supplicant_check(const mac_vap_stru * mac_vap,const mac_bss_dscr_stru * bss_dscr)937 static hi_u32 hmac_check_security_capability_supplicant_check(const mac_vap_stru *mac_vap,
938 const mac_bss_dscr_stru *bss_dscr)
939 {
940 oam_info_log4(mac_vap->vap_id, OAM_SF_WPA,
941 "{hmac_check_security_capability_supplicant_check :: mode %d,active %d,wpa %d,wpa2 %d}",
942 bss_dscr->bss_sec_info.bss_80211i_mode, mac_vap->mib_info->wlan_mib_privacy.dot11_rsna_activated,
943 mac_vap->cap_flag.wpa, mac_vap->cap_flag.wpa2);
944
945 hmac_vap_stru *hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
946 if (hmac_vap == HI_NULL) {
947 oam_error_log0(mac_vap->vap_id, OAM_SF_CFG,
948 "{hmac_check_security_capability_supplicant_check::pst_hmac_vap null.}");
949 return HI_ERR_CODE_PTR_NULL;
950 }
951
952 if (hmac_vap->wps_active == HI_TRUE) {
953 oam_info_log0(mac_vap->vap_id, OAM_SF_WPA, "{hmac_check_security_capability_supplicant_check::WPS enable.}");
954 return HI_CONTINUE;
955 }
956 #ifdef _PRE_WLAN_FEATURE_MESH
957 if (bss_dscr->is_hisi_mesh == HI_TRUE) {
958 oam_info_log0(0, OAM_SF_WPA,
959 "{hmac_check_security_capability_supplicant_check::Connect Hisi-Mesh,no need check!.}");
960 return HI_CONTINUE;
961 }
962 #endif
963
964 return HI_SUCCESS;
965 }
966
967
968 /* ****************************************************************************
969 功能描述 : STA 在JOIN 前检测加密能力是否匹配
970 输入参数 : mac_vap_stru pst_mac_vap
971 mac_bss_dscr_stru *pst_bss_dscr
972 返 回 值 : hi_u32 HI_SUCCESS 匹配成功
973 HI_FAIL 匹配失败
974 修改历史 :
975 1.日 期 : 2013年9月25日
976 作 者 : HiSilicon
977 修改内容 : 新生成函数
978 **************************************************************************** */
hmac_check_security_capability_supplicant(const mac_vap_stru * mac_vap,mac_bss_dscr_stru * bss_dscr)979 static hi_u32 hmac_check_security_capability_supplicant(const mac_vap_stru *mac_vap, mac_bss_dscr_stru *bss_dscr)
980 {
981 hi_u8 grp_policy_match = 0xFF;
982 hi_u8 pcip_policy_match = 0xFF;
983 hi_u8 auth_policy_match = 0xFF;
984 hi_u8 is_80211i_mode = 0x00;
985 hi_u32 ret = HI_FAIL;
986 hmac_cap_supplicant_info_stru supplicant_info;
987 wlan_mib_ieee802dot11_stru *mib_info = mac_vap->mib_info; /* 本机的 MIB 值 */
988
989 hi_u32 retval = hmac_check_security_capability_supplicant_check(mac_vap, bss_dscr);
990 if (retval == HI_ERR_CODE_PTR_NULL) {
991 return HI_ERR_CODE_PTR_NULL;
992 } else if (retval == HI_CONTINUE) {
993 return HI_SUCCESS;
994 }
995
996 if (mac_vap->mib_info->wlan_mib_privacy.dot11_rsna_activated == HI_TRUE) {
997 /* 检查STA 和 AP 加密能力是否匹配, 并更新到对应的match 中 */
998 /* 在WPA/WPA2 混合模式下,优先选择WPA2 */
999 supplicant_info.puc_grp_policy_match = &grp_policy_match;
1000 supplicant_info.puc_pcip_policy_match = &pcip_policy_match;
1001 supplicant_info.puc_auth_policy_match = &auth_policy_match;
1002 if ((bss_dscr->bss_sec_info.bss_80211i_mode & DMAC_RSNA_802_11I) && (mac_vap->cap_flag.wpa2 == HI_TRUE)) {
1003 ret = hmac_check_join_req_security_cap_supplicant(bss_dscr, mib_info, &supplicant_info, DMAC_RSNA_802_11I);
1004 if (ret == HI_SUCCESS) {
1005 is_80211i_mode = DMAC_RSNA_802_11I;
1006 }
1007 }
1008
1009 if ((ret == HI_FAIL) && (bss_dscr->bss_sec_info.bss_80211i_mode & DMAC_WPA_802_11I) &&
1010 (mac_vap->cap_flag.wpa == HI_TRUE)) {
1011 ret = hmac_check_join_req_security_cap_supplicant(bss_dscr, mib_info, &supplicant_info, DMAC_WPA_802_11I);
1012 if (ret == HI_SUCCESS) {
1013 is_80211i_mode = DMAC_WPA_802_11I;
1014 }
1015 }
1016
1017 if (ret != HI_SUCCESS) {
1018 oam_error_log1(0, OAM_SF_WPA, "{hmac_check_security_capability_supplicant::WPA & WPA2 not match[%d]}", ret);
1019 return HI_ERR_CODE_SECURITY_CHIPER_TYPE;
1020 }
1021
1022 bss_dscr->bss_sec_info.bss_80211i_mode = is_80211i_mode;
1023 bss_dscr->bss_sec_info.grp_policy_match = grp_policy_match;
1024 bss_dscr->bss_sec_info.pairwise_policy_match = pcip_policy_match;
1025 bss_dscr->bss_sec_info.auth_policy_match = auth_policy_match;
1026 } else { /* 本vap不支持rsn,对端支持rsn, 返回失败 */
1027 if (bss_dscr->bss_sec_info.bss_80211i_mode & (DMAC_RSNA_802_11I | DMAC_WPA_802_11I)) {
1028 oam_error_log1(0, OAM_SF_WPA, "{hmac_check_security_capability_supplicant::WPA/WPA2 not support! mode=%d}",
1029 bss_dscr->bss_sec_info.bss_80211i_mode);
1030 return HI_ERR_CODE_SECURITY_CHIPER_TYPE;
1031 }
1032 }
1033
1034 return HI_SUCCESS;
1035 }
1036
1037 /* ****************************************************************************
1038 功能描述 : 检测期望join 的AP能力信息是否匹配
1039 输入参数 : mac_vap_stru pst_mac_vap STA 自己
1040 mac_bss_dscr_stru *pst_bss_dscr AP bss 信息
1041 返 回 值 : hi_u32 HI_SUCCESS 匹配成功
1042 HI_FAIL 匹配失败
1043 修改历史 :
1044 1.日 期 : 2013年9月25日
1045 作 者 : HiSilicon
1046 修改内容 : 新生成函数
1047 **************************************************************************** */
hmac_check_capability_mac_phy_supplicant(mac_vap_stru * mac_vap,mac_bss_dscr_stru * bss_dscr)1048 hi_u32 hmac_check_capability_mac_phy_supplicant(mac_vap_stru *mac_vap, mac_bss_dscr_stru *bss_dscr)
1049 {
1050 hi_u32 ret;
1051
1052 /* 根据协议模式重新初始化STA HT/VHT mib值 */
1053 mac_vap_config_vht_ht_mib_by_protocol(mac_vap);
1054
1055 hi_u8 check_bss_ret = hmac_check_bss_cap_info(bss_dscr->us_cap_info, mac_vap);
1056 if (check_bss_ret != HI_TRUE) {
1057 oam_warning_log1(mac_vap->vap_id, OAM_SF_WPA,
1058 "{hmac_check_capability_mac_phy_supplicant::hmac_check_bss_cap_info Err[%d]}", check_bss_ret);
1059 }
1060
1061 /* check bss capability info PHY,忽略PHY能力不匹配的AP */
1062 mac_vap_check_bss_cap_info_phy_ap(bss_dscr->us_cap_info, mac_vap);
1063
1064 ret = hmac_check_security_capability_supplicant(mac_vap, bss_dscr);
1065 if (ret != HI_SUCCESS) {
1066 oam_warning_log1(mac_vap->vap_id, OAM_SF_WPA,
1067 "{hmac_check_capability_mac_phy_supplicant::hmac_check_security_capability_supplicant failed[%d].}", ret);
1068 }
1069
1070 return HI_SUCCESS;
1071 }
1072
1073 /* ****************************************************************************
1074 功能描述 : 根据STA 的单播加密方式和保护模式,更新STA 工作速率
1075 在WEP / TKIP 加密模式下,不能工作在HT MODE
1076 输入参数 : mac_vap_stru *pst_mac_vap
1077 修改历史 :
1078 1.日 期 : 2013年9月30日
1079 作 者 : HiSilicon
1080 修改内容 : 新生成函数
1081 **************************************************************************** */
hmac_update_pcip_policy_prot_supplicant(mac_vap_stru * mac_vap,hi_u8 pcip_policy_match)1082 hi_void hmac_update_pcip_policy_prot_supplicant(mac_vap_stru *mac_vap, hi_u8 pcip_policy_match)
1083 {
1084 hmac_vap_stru *hmac_vap = HI_NULL;
1085 mac_cfg_mode_param_stru cfg_mode;
1086 hi_u8 protocol_fall_flag = HI_FALSE;
1087
1088 cfg_mode.protocol = mac_vap->protocol;
1089
1090 if ((pcip_policy_match == WLAN_80211_CIPHER_SUITE_TKIP) ||
1091 (pcip_policy_match == WLAN_80211_CIPHER_SUITE_WEP_104) ||
1092 (pcip_policy_match == WLAN_80211_CIPHER_SUITE_WEP_40) ||
1093 (pcip_policy_match == WLAN_80211_CIPHER_SUITE_WAPI)) {
1094 if ((mac_vap->protocol >= WLAN_HT_MODE) && (mac_vap->protocol < WLAN_PROTOCOL_BUTT)) {
1095 if (mac_vap->channel.band == WLAN_BAND_2G) {
1096 cfg_mode.protocol = WLAN_MIXED_ONE_11G_MODE;
1097 mac_vap->channel.en_bandwidth = WLAN_BAND_WIDTH_20M;
1098 protocol_fall_flag = HI_TRUE;
1099 }
1100 }
1101 }
1102 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
1103 if (hmac_vap == HI_NULL) {
1104 oam_error_log0(mac_vap->vap_id, OAM_SF_CFG, "{hmac_update_pcip_policy_prot_supplicant::pst_hmac_vap null.}");
1105 return;
1106 }
1107 /* 降协议或恢复后需要对bit_protocol_fall更新 */
1108 hmac_vap->protocol_fall = protocol_fall_flag;
1109
1110 if (cfg_mode.protocol >= WLAN_HT_MODE) {
1111 hmac_vap->tx_aggr_on = HI_TRUE;
1112 } else {
1113 hmac_vap->tx_aggr_on = HI_FALSE;
1114 }
1115
1116 mac_vap_init_by_protocol(mac_vap, cfg_mode.protocol);
1117
1118 oam_info_log2(mac_vap->vap_id, OAM_SF_WPA,
1119 "{hmac_update_pcip_policy_prot_supplicant::en_protocol=%d, bandwidth=%d.}", mac_vap->protocol,
1120 mac_vap->channel.en_bandwidth);
1121 }
1122
1123 /* ****************************************************************************
1124 功能描述 : 更新STA 加密的mib 信息
1125 输入参数 : mac_vap_stru *pst_mac_vap STA 本机信息
1126 hmac_join_req_stru *pst_join_req STA join 的AP bss 信息
1127 修改历史 :
1128 1.日 期 : 2013年8月21日
1129 作 者 : HiSilicon
1130 修改内容 : 新生成函数
1131 **************************************************************************** */
hmac_update_current_join_req_parms_11i(mac_vap_stru * mac_vap,const mac_bss_80211i_info_stru * is_11i)1132 hi_u32 hmac_update_current_join_req_parms_11i(mac_vap_stru *mac_vap, const mac_bss_80211i_info_stru *is_11i)
1133 {
1134 hmac_vap_stru *hmac_vap = HI_NULL;
1135 hi_u8 grp_policy_match; /* STA 和 AP 能力匹配的组播加密套件 */
1136 hi_u8 pcip_policy_match; /* STA 和 AP 能力匹配的单播加密套件 */
1137 hi_u8 auth_policy_match; /* STA 和 AP 能力匹配的认证模式 */
1138 hi_u8 is_80211i_mode; /* STA 自己支持的安全模式 */
1139 hi_u16 ciphersize = 0;
1140
1141 /* 根据匹配值来设置join 时候STA 的mib */
1142 grp_policy_match = is_11i->grp_policy_match;
1143 pcip_policy_match = is_11i->pairwise_policy_match;
1144 auth_policy_match = is_11i->auth_policy_match;
1145 is_80211i_mode = is_11i->bss_80211i_mode;
1146
1147 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
1148 if (hmac_vap == HI_NULL) {
1149 oam_error_log0(mac_vap->vap_id, OAM_SF_CFG, "{hmac_update_current_join_req_parms_11i::pst_hmac_vap null.}");
1150 return HI_ERR_CODE_PTR_NULL;
1151 }
1152
1153 if (mac_vap->mib_info->wlan_mib_privacy.dot11_privacy_invoked != HI_TRUE) {
1154 if (hmac_vap->protocol_fall == HI_TRUE) {
1155 hmac_update_pcip_policy_prot_supplicant(mac_vap, WLAN_80211_CIPHER_SUITE_NO_ENCRYP);
1156 }
1157 return HI_SUCCESS;
1158 }
1159
1160 /* 使能RSN */
1161 if (mac_vap->mib_info->wlan_mib_privacy.dot11_rsna_activated != HI_TRUE) {
1162 /* 在WEP / TKIP 加密模式下,不能工作在HT MODE */
1163 hmac_update_pcip_policy_prot_supplicant(mac_vap, WLAN_80211_CIPHER_SUITE_WEP_40);
1164 return HI_SUCCESS;
1165 }
1166
1167 /* 在WEP / TKIP 加密模式下,不能工作在HT MODE */
1168 hmac_update_pcip_policy_prot_supplicant(mac_vap, pcip_policy_match);
1169
1170 /* 配置STA 的MIB 信息 */
1171 /* 配置组播mib 值,组播信息来自于AP */
1172 if (mac_vap->mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_group_cipher != grp_policy_match) {
1173 mac_vap->mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_group_cipher = grp_policy_match;
1174 if (grp_policy_match == WLAN_80211_CIPHER_SUITE_CCMP) {
1175 ciphersize = WLAN_CCMP_KEY_LEN * 8; /* CCMP 加密方式的密钥长度(BITS) 8: 8位 */
1176 } else if (grp_policy_match == WLAN_80211_CIPHER_SUITE_TKIP) {
1177 ciphersize = WLAN_TKIP_KEY_LEN * 8; /* TKIP 加密方式下的密钥长度(BITS) 8: 8位 */
1178 }
1179 mac_vap->mib_info->wlan_mib_rsna_cfg.dot11_rsna_config_group_cipher_size = ciphersize;
1180 }
1181
1182 /* 更新MIB 值 */
1183 mac_vap->mib_info->wlan_mib_rsna_cfg.dot11_rsna_pairwise_cipher_requested = pcip_policy_match;
1184 mac_vap->mib_info->wlan_mib_rsna_cfg.dot11_rsna_group_cipher_requested = grp_policy_match;
1185
1186 /* STA 保存本机 80211i_mode 指定为WPA 或者 WPA2 */
1187 hmac_vap->is80211i_mode = is_80211i_mode;
1188
1189 oam_info_log4(mac_vap->vap_id, OAM_SF_WPA,
1190 "{hmac_update_current_join_req_parms_11i::mode=%d group=%d pairwise=%d auth=%d.}", is_80211i_mode,
1191 grp_policy_match, pcip_policy_match, auth_policy_match);
1192 return HI_SUCCESS;
1193 }
1194
1195 /* ****************************************************************************
1196 功能描述 : 增加mic校验码
1197 输出参数 : iv头的长度
1198 修改历史 :
1199 1.日 期 : 2014年1月23日
1200 作 者 : HiSilicon
1201 修改内容 : 新生成函数
1202 **************************************************************************** */
hmac_en_mic(const hmac_user_stru * hmac_user,oal_netbuf_stru * netbuf,hi_u8 * puc_iv_len)1203 hi_u32 hmac_en_mic(const hmac_user_stru *hmac_user, oal_netbuf_stru *netbuf, hi_u8 *puc_iv_len)
1204 {
1205 wlan_priv_key_param_stru *key = HI_NULL;
1206 hi_u32 ret = HI_SUCCESS;
1207 wlan_ciper_protocol_type_enum_uint8 cipher_type;
1208 wlan_cipher_key_type_enum_uint8 key_type;
1209
1210 *puc_iv_len = 0;
1211 key_type = hmac_user->base_user->user_tx_info.security.cipher_key_type;
1212 cipher_type = hmac_user->base_user->key_info.cipher_type;
1213 key = mac_user_get_key(hmac_user->base_user, key_type - 1);
1214 if (key == HI_NULL) {
1215 oam_error_log1(0, OAM_SF_WPA, "{hmac_en_mic::mac_user_get_key FAIL. en_key_type[%d]}", key_type);
1216 return HI_ERR_CODE_SECURITY_KEY_ID;
1217 }
1218
1219 switch (cipher_type) {
1220 case WLAN_80211_CIPHER_SUITE_TKIP:
1221 if (key_type == 0 || key_type > 5) { /* 5 边界 */
1222 return HI_ERR_CODE_SECURITY_KEY_TYPE;
1223 }
1224
1225 ret = hmac_crypto_tkip_enmic(key, netbuf);
1226 if (ret != HI_SUCCESS) {
1227 oam_error_log1(0, OAM_SF_WPA, "{hmac_en_mic::hmac_crypto_tkip_enmic failed[%d].}", ret);
1228 return ret;
1229 }
1230
1231 *puc_iv_len = WEP_IV_FIELD_SIZE + EXT_IV_FIELD_SIZE;
1232 break;
1233 case WLAN_80211_CIPHER_SUITE_CCMP:
1234 *puc_iv_len = WEP_IV_FIELD_SIZE + EXT_IV_FIELD_SIZE;
1235 break;
1236 default:
1237 break;
1238 }
1239
1240 return HI_SUCCESS;
1241 }
1242
1243 /* ****************************************************************************
1244 功能描述 : mic码校验
1245 修改历史 :
1246 1.日 期 : 2014年1月23日
1247 作 者 : HiSilicon
1248 修改内容 : 新生成函数
1249 **************************************************************************** */
hmac_de_mic(const hmac_user_stru * hmac_user,oal_netbuf_stru * netbuf)1250 hi_u32 hmac_de_mic(const hmac_user_stru *hmac_user, oal_netbuf_stru *netbuf)
1251 {
1252 wlan_priv_key_param_stru *key = HI_NULL;
1253 hi_u32 ret = HI_SUCCESS;
1254 wlan_ciper_protocol_type_enum_uint8 cipher_type;
1255 wlan_cipher_key_type_enum_uint8 key_type;
1256
1257 key_type = hmac_user->base_user->user_tx_info.security.cipher_key_type;
1258 cipher_type = hmac_user->base_user->key_info.cipher_type;
1259 key = mac_user_get_key(hmac_user->base_user, key_type - 1);
1260 if (key == HI_NULL) {
1261 oam_error_log1(0, OAM_SF_WPA, "{hmac_de_mic::mac_user_get_key FAIL. en_key_type[%d]}", key_type);
1262 return HI_ERR_CODE_SECURITY_KEY_ID;
1263 }
1264
1265 switch (cipher_type) {
1266 case WLAN_80211_CIPHER_SUITE_TKIP:
1267 if (key_type == 0 || key_type > 5) { /* 5 边界 */
1268 oam_error_log0(hmac_user->base_user->vap_id, OAM_SF_WPA,
1269 "{hmac_de_mic::key_type is err code security key type.}");
1270 return HI_ERR_CODE_SECURITY_KEY_TYPE;
1271 }
1272 ret = hmac_crypto_tkip_demic(key, netbuf);
1273 if (ret != HI_SUCCESS) {
1274 oam_error_log1(hmac_user->base_user->vap_id, OAM_SF_WPA,
1275 "{hmac_de_mic::hmac_crypto_tkip_demic failed[%d].}", ret);
1276 return ret;
1277 }
1278 break;
1279 default:
1280 break;
1281 }
1282
1283 return HI_SUCCESS;
1284 }
1285
1286 /* ****************************************************************************
1287 功能描述 : ap 和 sta 接收到MIC faile 事件处理
1288 输入参数 :
1289 修改历史 :
1290 1.日 期 : 2013年8月28日
1291 作 者 : HiSilicon
1292 修改内容 : 新生成函数
1293 **************************************************************************** */
hmac_rx_tkip_mic_failure_process(frw_event_mem_stru * event_mem)1294 hi_u32 hmac_rx_tkip_mic_failure_process(frw_event_mem_stru *event_mem)
1295 {
1296 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
1297 frw_event_stru *event = HI_NULL;
1298 frw_event_mem_stru *hmac_event_mem = HI_NULL;
1299 frw_event_hdr_stru *event_hdr = HI_NULL;
1300 dmac_to_hmac_mic_event_stru *mic_event = HI_NULL;
1301
1302 /* 获取事件头和事件结构体指针 */
1303 event = (frw_event_stru *)event_mem->puc_data;
1304 event_hdr = &(event->event_hdr);
1305 mic_event = (dmac_to_hmac_mic_event_stru *)(event->auc_event_data);
1306
1307 /* 将mic事件抛到WAL */
1308 hmac_event_mem = frw_event_alloc(sizeof(dmac_to_hmac_mic_event_stru));
1309 if (hmac_event_mem == HI_NULL) {
1310 oam_error_log0(event_hdr->vap_id, OAM_SF_WPA, "{hmac_rx_tkip_mic_failure_process::pst_hmac_event_mem null.}");
1311 return HI_ERR_CODE_PTR_NULL;
1312 }
1313
1314 /* 填写事件 */
1315 event = (frw_event_stru *)hmac_event_mem->puc_data;
1316
1317 frw_event_hdr_init(&(event->event_hdr), FRW_EVENT_TYPE_HOST_CTX, HMAC_HOST_CTX_EVENT_SUB_TYPE_MIC_FAILURE,
1318 sizeof(dmac_to_hmac_mic_event_stru), FRW_EVENT_PIPELINE_STAGE_0, event_hdr->vap_id);
1319
1320 /* 去关联的STA mac地址 */
1321 if (memcpy_s((hi_u8 *)frw_get_event_payload(event_mem), sizeof(dmac_to_hmac_mic_event_stru), (hi_u8 *)mic_event,
1322 sizeof(dmac_to_hmac_mic_event_stru)) != EOK) {
1323 oam_error_log0(0, OAM_SF_CFG, "hmac_rx_tkip_mic_failure_process::pst_mic_event memcpy_s fail.");
1324 frw_event_free(hmac_event_mem);
1325 return HI_FAIL;
1326 }
1327
1328 /* 分发事件 */
1329 frw_event_dispatch_event(hmac_event_mem);
1330 frw_event_free(hmac_event_mem);
1331 return HI_SUCCESS;
1332 #else
1333 hi_unref_param(event_mem);
1334 return HI_SUCCESS;
1335 #endif
1336 }
1337
1338 /* ****************************************************************************
1339 功能描述 : 接收数据,安全相关过滤
1340 输入参数 : (1)vap
1341 (2)mac地址
1342 (3)接收数据类型
1343 返 回 值 : 成功或者失败
1344 修改历史 :
1345 1.日 期 : 2014年1月6日
1346 作 者 : HiSilicon
1347 修改内容 : 新生成函数
1348 **************************************************************************** */
hmac_11i_ether_type_filter(const hmac_vap_stru * hmac_vap,const hi_u8 * mac_addr,hi_u16 us_ether_type)1349 hi_u32 hmac_11i_ether_type_filter(const hmac_vap_stru *hmac_vap, const hi_u8 *mac_addr, hi_u16 us_ether_type)
1350 {
1351 mac_user_stru *mac_user = HI_NULL;
1352 mac_vap_stru *mac_vap = HI_NULL;
1353 hi_u32 ret = HI_SUCCESS;
1354
1355 mac_vap = hmac_vap->base_vap;
1356 if (mac_vap->mib_info->wlan_mib_privacy.dot11_rsna_activated == HI_TRUE) { /* 判断是否使能WPA/WPA2 */
1357 mac_user = mac_vap_get_user_by_addr(hmac_vap->base_vap, mac_addr);
1358 if (mac_user == HI_NULL) {
1359 oam_info_log0(mac_vap->vap_id, OAM_SF_WPA, "{hmac_11i_ether_type_filter:: user filterd.}");
1360 return HI_ERR_CODE_SECURITY_USER_INVAILD;
1361 }
1362
1363 if (mac_user->port_valid != HI_TRUE) { /* 判断端口是否打开 */
1364 /* 接收数据时,针对非EAPOL 的数据帧做过滤 */
1365 if (hi_swap_byteorder_16(ETHER_TYPE_PAE) != us_ether_type) {
1366 oam_warning_log1(mac_vap->vap_id, OAM_SF_WPA,
1367 "{hmac_11i_ether_type_filter::TYPE 0x%04x not permission.}", us_ether_type);
1368 ret = HI_ERR_CODE_SECURITY_PORT_INVALID;
1369 }
1370 } else if (hi_swap_byteorder_16(ETHER_TYPE_PAE) == us_ether_type) { /* EAPOL收发维测信息 */
1371 oam_info_log0(mac_vap->vap_id, OAM_SF_WPA, "{hmac_11i_ether_type_filter::rx EAPOL.}");
1372 }
1373 }
1374 return ret;
1375 }
1376
1377 #ifdef __cplusplus
1378 #if __cplusplus
1379 }
1380 #endif
1381 #endif
1382