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 "mac_frame.h"
23 #include "mac_user.h"
24 #include "mac_vap.h"
25 #include "mac_mib.h"
26 #include "dmac_ext_if.h"
27 #include "hmac_config.h"
28 #include "hmac_encap_frame_ap.h"
29 #include "hmac_main.h"
30 #include "hmac_tx_data.h"
31 #include "hmac_mgmt_ap.h"
32 #include "hmac_11i.h"
33 #include "hmac_blockack.h"
34 #include "frw_timer.h"
35
36 #ifdef __cplusplus
37 #if __cplusplus
38 extern "C" {
39 #endif
40 #endif
41
42 /* ****************************************************************************
43 3 函数实现
44 **************************************************************************** */
45 /* ****************************************************************************
46 功能描述 : 封装chtxt
47 修改历史 :
48 1.日 期 : 2013年7月18日
49 作 者 : HiSilicon
50 修改内容 : 新生成函数
51 **************************************************************************** */
hmac_mgmt_encap_chtxt(hi_u8 * puc_frame,const hi_u8 * puc_chtxt,hi_u16 * pus_auth_rsp_len,hmac_user_stru * hmac_user)52 static hi_void hmac_mgmt_encap_chtxt(hi_u8 *puc_frame, const hi_u8 *puc_chtxt, hi_u16 *pus_auth_rsp_len,
53 hmac_user_stru *hmac_user)
54 {
55 /* Challenge Text Element */
56 /* --------------------------------------- */
57 /* |Element ID | Length | Challenge Text | */
58 /* --------------------------------------- */
59 /* | 1 |1 |1 - 253 | */
60 /* --------------------------------------- */
61 puc_frame[6] = MAC_EID_CHALLENGE; /* 6 元素索引 */
62 puc_frame[7] = WLAN_CHTXT_SIZE; /* 7 元素索引 */
63
64 /* 认证帧长度增加Challenge Text Element的长度 */
65 *pus_auth_rsp_len += (WLAN_CHTXT_SIZE + MAC_IE_HDR_LEN);
66 /* 将challenge text拷贝到帧体中去 */
67 hi_u32 ret = (hi_u32)memcpy_s(&puc_frame[8], WLAN_CHTXT_SIZE, puc_chtxt, WLAN_CHTXT_SIZE); /* 8 挑战字段起始地址 */
68 if (ret != EOK) {
69 oam_error_log1(0, OAM_SF_CFG, "hmac_mgmt_encap_chtxt:: challenge text memcpy fail, ret[%d].", ret);
70 return;
71 }
72 /* 保存明文的challenge text */
73 if (hmac_user->ch_text == HI_NULL) {
74 /* 此处只负责申请由认证成功或者超时定时器释放 */
75 hmac_user->ch_text = (hi_u8 *)oal_mem_alloc(OAL_MEM_POOL_ID_LOCAL, WLAN_CHTXT_SIZE);
76 }
77
78 if (hmac_user->ch_text != HI_NULL) {
79 ret = (hi_u32)memcpy_s(hmac_user->ch_text, WLAN_CHTXT_SIZE, puc_chtxt, WLAN_CHTXT_SIZE);
80 if (ret != EOK) {
81 oam_error_log1(0, OAM_SF_CFG, "hmac_mgmt_encap_chtxt:: save challenge text fail, ret[%d].", ret);
82 return;
83 }
84 }
85 }
86
87 #ifdef _PRE_WLAN_FEATURE_PMF
88 /* ****************************************************************************
89 功能描述 : 计算得到 assoc rsp 中所需的assoc comeback time
90 输入参数 : pst_mac_vap : mac vap 指针
91 pst_hmac_user : hamc user 指针
92 返 回 值 : 计算得到的assoc comeback time值
93 修改历史 :
94 1.日 期 : 2014年4月28日
95 作 者 : HiSilicon
96 修改内容 : 新生成函数
97 **************************************************************************** */
hmac_get_assoc_comeback_time(const mac_vap_stru * mac_vap,const hmac_user_stru * hmac_user)98 static hi_u32 hmac_get_assoc_comeback_time(const mac_vap_stru *mac_vap, const hmac_user_stru *hmac_user)
99 {
100 hi_u32 timeout = 0;
101
102 hi_u32 now_time;
103 hi_u32 passed_time;
104 hi_u32 sa_query_maxtimeout;
105
106 /* 获取现在时间 */
107 now_time = (hi_u32)hi_get_milli_seconds();
108
109 /* 设置ASSOCIATION_COMEBACK_TIME,使STA在AP完成SA Query流程之后再发送关联请求 */
110 /* 获得sa Query Max timeout值 */
111 sa_query_maxtimeout = mac_mib_get_dot11_association_saquery_maximum_timeout(mac_vap);
112
113 /* 是否现在有sa Query流程正在进行 */
114 if ((hmac_user->sa_query_info.sa_query_interval_timer.is_enabled == HI_TRUE) &&
115 (now_time >= hmac_user->sa_query_info.sa_query_start_time)) {
116 /* 待现有SA Query流程结束后才可以接受STA发过来的关联帧 */
117 passed_time = now_time - hmac_user->sa_query_info.sa_query_start_time;
118 timeout = sa_query_maxtimeout - passed_time;
119 } else {
120 /* 给接下来的SA Query流程预留时间 */
121 timeout = sa_query_maxtimeout;
122 }
123
124 return timeout;
125 }
126 #endif
127
hmac_set_supported_rates_ie_asoc_rsp(const mac_user_stru * mac_user,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)128 hi_void hmac_set_supported_rates_ie_asoc_rsp(const mac_user_stru *mac_user, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
129 {
130 hi_u8 nrates;
131 hi_u8 idx;
132 /* *************************************************************************
133 ---------------------------------------
134 |Element ID | Length | Supported Rates|
135 ---------------------------------------
136 Octets: |1 | 1 | 1~8 |
137 ---------------------------------------
138 The Information field is encoded as 1 to 8 octets, where each octet describes a single Supported
139 Rate or BSS membership selector.
140 ************************************************************************* */
141 puc_buffer[0] = MAC_EID_RATES;
142 nrates = mac_user->avail_op_rates.rs_nrates;
143
144 if (nrates > MAC_MAX_SUPRATES) {
145 nrates = MAC_MAX_SUPRATES;
146 }
147
148 for (idx = 0; idx < nrates; idx++) {
149 puc_buffer[MAC_IE_HDR_LEN + idx] = mac_user->avail_op_rates.auc_rs_rates[idx];
150 }
151
152 puc_buffer[1] = nrates;
153 *puc_ie_len = MAC_IE_HDR_LEN + nrates;
154 }
155
hmac_set_exsup_rates_ie_asoc_rsp(const mac_user_stru * mac_user,hi_u8 * puc_buffer,hi_u8 * puc_ie_len)156 hi_void hmac_set_exsup_rates_ie_asoc_rsp(const mac_user_stru *mac_user, hi_u8 *puc_buffer, hi_u8 *puc_ie_len)
157 {
158 hi_u8 nrates;
159 hi_u8 idx;
160
161 /* **************************************************************************
162 -----------------------------------------------
163 |ElementID | Length | Extended Supported Rates|
164 -----------------------------------------------
165 Octets: |1 | 1 | 1-255 |
166 -----------------------------------------------
167 ************************************************************************** */
168 if (mac_user->avail_op_rates.rs_nrates <= MAC_MAX_SUPRATES) {
169 *puc_ie_len = 0;
170 return;
171 }
172
173 puc_buffer[0] = MAC_EID_XRATES;
174 nrates = mac_user->avail_op_rates.rs_nrates - MAC_MAX_SUPRATES;
175 puc_buffer[1] = nrates;
176
177 for (idx = 0; idx < nrates; idx++) {
178 puc_buffer[MAC_IE_HDR_LEN + idx] = mac_user->avail_op_rates.auc_rs_rates[idx + MAC_MAX_SUPRATES];
179 }
180
181 *puc_ie_len = MAC_IE_HDR_LEN + nrates;
182 }
183
184
hmac_mgmt_encap_asoc_rsp_ap_add_copy(const mac_vap_stru * mac_ap,const hmac_asoc_rsp_ap_info_stru * asoc_rsp_ap_info)185 hi_u32 hmac_mgmt_encap_asoc_rsp_ap_add_copy(const mac_vap_stru *mac_ap,
186 const hmac_asoc_rsp_ap_info_stru *asoc_rsp_ap_info)
187 {
188 if (mac_ap->mib_info == HI_NULL) {
189 return HI_ERR_CODE_PTR_NULL;
190 }
191
192 /* 设置 Frame Control field */
193 mac_hdr_set_frame_control(asoc_rsp_ap_info->puc_asoc_rsp, asoc_rsp_ap_info->us_type);
194 /* 设置 DA address1: STA MAC地址 设置 SA address2: dot11MACAddress 设置 DA address3: AP MAC地址 (BSSID) */
195 if ((memcpy_s(asoc_rsp_ap_info->puc_asoc_rsp + WLAN_HDR_ADDR1_OFFSET, WLAN_MAC_ADDR_LEN,
196 asoc_rsp_ap_info->puc_sta_addr, WLAN_MAC_ADDR_LEN) != EOK) ||
197 (memcpy_s(asoc_rsp_ap_info->puc_asoc_rsp + WLAN_HDR_ADDR2_OFFSET, WLAN_MAC_ADDR_LEN,
198 mac_ap->mib_info->wlan_mib_sta_config.auc_dot11_station_id, WLAN_MAC_ADDR_LEN) != EOK) ||
199 (memcpy_s(asoc_rsp_ap_info->puc_asoc_rsp + WLAN_HDR_ADDR3_OFFSET, WLAN_MAC_ADDR_LEN, mac_ap->auc_bssid,
200 WLAN_MAC_ADDR_LEN) != EOK)) {
201 oam_error_log0(0, 0, "{hmac_mgmt_encap_asoc_rsp_ap::memcpy_s fail.}");
202 return HI_FAIL;
203 }
204 return HI_SUCCESS;
205 }
206
207 /* ****************************************************************************
208 功能描述 : 组关联响应帧
209 修改历史 :
210 1.日 期 : 2013年7月9日
211 作 者 : HiSilicon
212 修改内容 : 新生成函数
213 **************************************************************************** */
hmac_mgmt_encap_asoc_rsp_ap(mac_vap_stru * mac_ap,hmac_asoc_rsp_ap_info_stru * asoc_rsp_ap_info)214 hi_u32 hmac_mgmt_encap_asoc_rsp_ap(mac_vap_stru *mac_ap, hmac_asoc_rsp_ap_info_stru *asoc_rsp_ap_info)
215 {
216 hi_u8 ie_len = 0;
217 hi_u16 us_app_ie_len;
218
219 /* 保存起始地址,方便计算长度 */
220 hi_u8 *puc_asoc_rsp_original = asoc_rsp_ap_info->puc_asoc_rsp;
221
222 /* 获取user */
223 mac_user_stru *mac_user = mac_user_get_user_stru(asoc_rsp_ap_info->assoc_id);
224 hmac_user_stru *hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(asoc_rsp_ap_info->assoc_id);
225 if (mac_user == HI_NULL || hmac_user == HI_NULL) {
226 oam_error_log3(0, OAM_SF_ASSOC, "{hmac_mgmt_encap_asoc_rsp_ap::mac_user/hmac_user(%d) is null mac=%p, hmac=%p}",
227 asoc_rsp_ap_info->assoc_id, (uintptr_t)mac_user, (uintptr_t)hmac_user);
228 return 0;
229 }
230 #ifdef _PRE_WLAN_FEATURE_PMF
231 mac_timeout_interval_type_enum tie_type =
232 (asoc_rsp_ap_info->status_code == MAC_REJECT_TEMP) ? MAC_TIE_ASSOCIATION_COMEBACK_TIME : MAC_TIE_BUTT;
233 #endif
234 /* *********************************************************************** */
235 /* Management Frame Format */
236 /* -------------------------------------------------------------------- */
237 /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS| */
238 /* -------------------------------------------------------------------- */
239 /* | 2 |2 |6 |6 |6 |2 |0 - 2312 |4 | */
240 /* -------------------------------------------------------------------- */
241 /* */
242 /* *********************************************************************** */
243 /* *********************************************************************** */
244 /* Set the fields in the frame header */
245 /* *********************************************************************** */
246 if (hmac_mgmt_encap_asoc_rsp_ap_add_copy(mac_ap, asoc_rsp_ap_info) != HI_SUCCESS) {
247 return 0;
248 }
249
250 asoc_rsp_ap_info->puc_asoc_rsp += MAC_80211_FRAME_LEN;
251
252 /* *********************************************************************** */
253 /* Set the contents of the frame body */
254 /* *********************************************************************** */
255 /* *********************************************************************** */
256 /* Association Response Frame - Frame Body */
257 /* --------------------------------------------------------------------- */
258 /* | Capability Information | Status Code | AID | Supported Rates | */
259 /* --------------------------------------------------------------------- */
260 /* |2 |2 |2 |3-10 | */
261 /* --------------------------------------------------------------------- */
262 /* */
263 /* *********************************************************************** */
264 /* 设置 capability information field */
265 mac_set_cap_info_ap((hi_void *)mac_ap, asoc_rsp_ap_info->puc_asoc_rsp);
266 asoc_rsp_ap_info->puc_asoc_rsp += MAC_CAP_INFO_LEN;
267 /* 设置 Status Code */
268 mac_set_status_code_ie(asoc_rsp_ap_info->puc_asoc_rsp, asoc_rsp_ap_info->status_code);
269 asoc_rsp_ap_info->puc_asoc_rsp += MAC_STATUS_CODE_LEN;
270 /* 设置 Association ID */
271 mac_set_aid_ie(asoc_rsp_ap_info->puc_asoc_rsp, (hi_u16)asoc_rsp_ap_info->assoc_id);
272 asoc_rsp_ap_info->puc_asoc_rsp += MAC_AID_LEN;
273 /* 设置 Supported Rates IE */
274 hmac_set_supported_rates_ie_asoc_rsp(mac_user, asoc_rsp_ap_info->puc_asoc_rsp, &ie_len);
275 asoc_rsp_ap_info->puc_asoc_rsp += ie_len;
276 /* 设置 Extended Supported Rates IE */
277 hmac_set_exsup_rates_ie_asoc_rsp(mac_user, asoc_rsp_ap_info->puc_asoc_rsp, &ie_len);
278 asoc_rsp_ap_info->puc_asoc_rsp += ie_len;
279 /* 设置 EDCA IE */
280 mac_set_wmm_params_ie((hi_void *)mac_ap, asoc_rsp_ap_info->puc_asoc_rsp, mac_user->cap_info.qos, &ie_len);
281 asoc_rsp_ap_info->puc_asoc_rsp += ie_len;
282 #ifdef _PRE_WLAN_FEATURE_PMF
283 /* 设置 Timeout Interval (Association Comeback time) IE */
284 hi_u32 timeout = hmac_get_assoc_comeback_time(mac_ap, hmac_user);
285 mac_set_timeout_interval_ie(asoc_rsp_ap_info->puc_asoc_rsp, &ie_len, tie_type, timeout);
286 asoc_rsp_ap_info->puc_asoc_rsp += ie_len;
287 #endif
288 if (mac_user->ht_hdl.ht_capable == HI_TRUE) {
289 /* 设置 HT-Capabilities Information IE */
290 mac_set_ht_capabilities_ie((hi_void *)mac_ap, asoc_rsp_ap_info->puc_asoc_rsp, &ie_len);
291 asoc_rsp_ap_info->puc_asoc_rsp += ie_len;
292 /* 设置 HT-Operation Information IE */
293 mac_set_ht_opern_ie((hi_void *)mac_ap, asoc_rsp_ap_info->puc_asoc_rsp, &ie_len);
294 asoc_rsp_ap_info->puc_asoc_rsp += ie_len;
295 /* 设置 Extended Capabilities Information IE */
296 mac_set_ext_capabilities_ie((hi_void *)mac_ap, asoc_rsp_ap_info->puc_asoc_rsp, &ie_len);
297 asoc_rsp_ap_info->puc_asoc_rsp += ie_len;
298 }
299
300 /* 填充WPS信息 */
301 mac_add_app_ie((hi_void *)mac_ap, asoc_rsp_ap_info->puc_asoc_rsp, &us_app_ie_len, OAL_APP_ASSOC_RSP_IE);
302 asoc_rsp_ap_info->puc_asoc_rsp += us_app_ie_len;
303
304 return (hi_u32)(asoc_rsp_ap_info->puc_asoc_rsp - puc_asoc_rsp_original);
305 }
306
307 /* ****************************************************************************
308 功能描述 : 判断两个challenge txt是否相等
309 修改历史 :
310 1.日 期 : 2013年6月29日
311 作 者 : HiSilicon
312 修改内容 : 新生成函数
313 **************************************************************************** */
hmac_mgmt_is_challenge_txt_equal(hi_u8 * puc_data,const hi_u8 * puc_chtxt)314 static hi_u8 hmac_mgmt_is_challenge_txt_equal(hi_u8 *puc_data, const hi_u8 *puc_chtxt)
315 {
316 hi_u8 *puc_ch_text = 0;
317 hi_u16 us_idx = 0;
318 hi_u8 ch_text_len;
319
320 if (puc_chtxt == HI_NULL) {
321 return HI_FALSE;
322 }
323 /* Challenge Text Element */
324 /* --------------------------------------- */
325 /* |Element ID | Length | Challenge Text | */
326 /* --------------------------------------- */
327 /* | 1 |1 |1 - 253 | */
328 /* --------------------------------------- */
329 ch_text_len = puc_data[1];
330 puc_ch_text = puc_data + 2; /* 加2 */
331
332 for (us_idx = 0; us_idx < ch_text_len; us_idx++) {
333 /* Return false on mismatch */
334 if (puc_ch_text[us_idx] != puc_chtxt[us_idx]) {
335 return HI_FALSE;
336 }
337 }
338
339 return HI_TRUE;
340 }
341
342
hmac_encap_auth_rsp_get_user_idx_seq(mac_vap_stru * mac_vap,hi_u8 is_seq1,hi_u8 * mac_addr,hi_u8 addr_len,hi_u8 * puc_user_index)343 hi_u32 hmac_encap_auth_rsp_get_user_idx_seq(mac_vap_stru *mac_vap, hi_u8 is_seq1, hi_u8 *mac_addr, hi_u8 addr_len,
344 hi_u8 *puc_user_index)
345 {
346 /* 在收到第一个认证帧时用户已创建 */
347 if (!is_seq1) {
348 oam_warning_log0(mac_vap->vap_id, OAM_SF_ANY, "{hmac_encap_auth_rsp_get_user_idx::user have been add at seq1}");
349 return HI_FAIL;
350 }
351 #ifdef _PRE_WLAN_FEATURE_MESH
352 /* Accepting Peer值控制Mesh关联,STA关联由Mesh Accepting STA控制 */
353 if (mac_vap->vap_mode == WLAN_VAP_MODE_MESH) {
354 if (mac_vap->mesh_accept_sta == HI_FALSE) {
355 oam_warning_log0(0, OAM_SF_ANY, "{hmac_encap_auth_rsp_get_user_idx:mesh vap not accept sta connect!}");
356 return HI_ERR_CODE_MESH_NOT_ACCEPT_PEER;
357 }
358 }
359 #endif
360 hi_u32 ret = hmac_user_add(mac_vap, mac_addr, addr_len, puc_user_index);
361 if (ret != HI_SUCCESS) {
362 if (ret == HI_ERR_CODE_CONFIG_EXCEED_SPEC) {
363 oam_warning_log0(0, OAM_SF_ANY, "{hmac_encap_auth_rsp_get_user_idx:add_assoc_user fail,users config spec}");
364 return HI_ERR_CODE_CONFIG_EXCEED_SPEC;
365 } else {
366 oam_error_log1(0, OAM_SF_ANY, "{hmac_encap_auth_rsp_get_user_idx:add_assoc_user fail %d}", *puc_user_index);
367 return HI_FAIL;
368 }
369 }
370
371 return HI_SUCCESS;
372 }
373
374 /* ****************************************************************************
375 功能描述 : 获取user idx,如果用户不存在,且resend置位的话,将sta加入ap
376 输入参数 : 1.vap指针
377 2.sta的mac地址
378 3.是否为seq1标志位.如果为真,表示如果用户不存在,需要将sta加入ap
379 输出参数 : 1. puc_auth_resend 用户存在的情况下收到seq1,seq1判定为重传帧,
380 置位此标志
381 2. puc_user_index 返回获取到的user idx
382 返 回 值 :获取正常或者失败
383 修改历史 :
384 1.日 期 : 2014年1月10日
385 作 者 : HiSilicon
386 修改内容 : 新生成函数
387 **************************************************************************** */
388 /* puc_user_index作为参数传入mac_vap_find_user_by_macaddr,在其中对其内容进行了修改,lin_t e818告警屏蔽 */
hmac_encap_auth_rsp_get_user_idx(mac_vap_stru * mac_vap,hmac_mac_addr_stru auth_mac_addr,hi_u8 is_seq1,hi_u8 * puc_auth_resend,hi_u8 * puc_user_index)389 hi_u32 hmac_encap_auth_rsp_get_user_idx(mac_vap_stru *mac_vap, hmac_mac_addr_stru auth_mac_addr, hi_u8 is_seq1,
390 hi_u8 *puc_auth_resend, hi_u8 *puc_user_index)
391 {
392 hi_u8 user_idx;
393 hi_u8 *mac_addr = auth_mac_addr.mac_addr;
394 hi_u8 addr_len = auth_mac_addr.addr_len;
395
396 hmac_vap_stru *hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
397 if (hmac_vap == HI_NULL) {
398 oam_error_log0(mac_vap->vap_id, OAM_SF_ANY, "{hmac_encap_auth_rsp_get_user_idx:hmac_vap_get_vap_stru failed!}");
399 return HI_FAIL;
400 }
401
402 *puc_auth_resend = HI_FALSE;
403 /* 找到用户 */
404 if (mac_vap_find_user_by_macaddr(hmac_vap->base_vap, mac_addr, addr_len, puc_user_index) == HI_SUCCESS) {
405 /* 获取hmac用户的状态,如果不是0,说明是重复帧 */
406 hmac_user_stru *hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(*puc_user_index);
407 if ((hmac_user == HI_NULL) || (hmac_user->base_user == HI_NULL)) {
408 oam_error_log0(mac_vap->vap_id, OAM_SF_ANY, "{hmac_encap_auth_rsp_get_user_idx::hmac_user_get_user null}");
409 return HI_FAIL;
410 }
411 /* en_user_asoc_state为枚举变量,取值为1~4,初始化为MAC_USER_STATE_BUTT,
412 * 应该使用!=MAC_USER_STATE_BUTT作为判断,否则会导致WEP share加密关联不上问题
413 */
414 if (hmac_user->base_user->user_asoc_state != MAC_USER_STATE_BUTT) {
415 *puc_auth_resend = HI_TRUE;
416 }
417
418 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
419 if (hmac_user->base_user->user_asoc_state == MAC_USER_STATE_ASSOC) {
420 oal_net_device_stru *netdev = hmac_vap_get_net_device(mac_vap->vap_id);
421 if (netdev != HI_NULL) {
422 oal_kobject_uevent_env_sta_leave(netdev, mac_addr);
423 }
424 }
425 #endif
426 return HI_SUCCESS;
427 }
428
429 /* 若在同一device下的其他VAP下找到该用户,删除之。否则导致业务不通。在DBAC下尤其常见 */
430 if (mac_device_find_user_by_macaddr(hmac_vap->base_vap, mac_addr, addr_len, &user_idx) == HI_SUCCESS) {
431 hmac_user_stru *hmac_user_tmp = (hmac_user_stru *)hmac_user_get_user_stru(user_idx);
432 if ((hmac_user_tmp != HI_NULL) && (hmac_user_tmp->base_user != HI_NULL)) {
433 mac_vap_stru *mac_vap_tmp = mac_vap_get_vap_stru(hmac_user_tmp->base_user->vap_id);
434 if (mac_vap_tmp != HI_NULL) {
435 hmac_user_del(mac_vap_tmp, hmac_user_tmp);
436 }
437 }
438 }
439
440 return hmac_encap_auth_rsp_get_user_idx_seq(mac_vap, is_seq1, mac_addr, addr_len, puc_user_index);
441 }
442
443 /* ****************************************************************************
444 功能描述 : 处理seq1的auth req
445 输入参数 : 1.auth_rsp_param 处理auth rsp所需的参数
446 输出参数 : 1.puc_code 错误码
447 2.pst_usr_ass_stat auth处理完成之后,置相应的user状态
448 返 回 值 :获取正常或者失败
449 修改历史 :
450 1.日 期 : 2014年1月10日
451 作 者 : HiSilicon
452 修改内容 : 新生成函数
453 **************************************************************************** */
hmac_encap_auth_rsp_seq1(const hmac_auth_rsp_param_stru * auth_rsp_param,hi_u8 * puc_code,mac_user_asoc_state_enum_uint8 * usr_ass_stat)454 hmac_ap_auth_process_code_enum_uint8 hmac_encap_auth_rsp_seq1(const hmac_auth_rsp_param_stru *auth_rsp_param,
455 hi_u8 *puc_code, mac_user_asoc_state_enum_uint8 *usr_ass_stat)
456 {
457 *puc_code = MAC_SUCCESSFUL_STATUSCODE;
458 *usr_ass_stat = MAC_USER_STATE_BUTT;
459 /* 如果不是重传 */
460 if (auth_rsp_param->auth_resend != HI_TRUE) {
461 if (auth_rsp_param->us_auth_type == WLAN_WITP_AUTH_OPEN_SYSTEM) {
462 *usr_ass_stat = MAC_USER_STATE_AUTH_COMPLETE;
463
464 return HMAC_AP_AUTH_SEQ1_OPEN_ANY;
465 }
466
467 if (auth_rsp_param->is_wep_allowed == HI_TRUE) {
468 *usr_ass_stat = MAC_USER_STATE_AUTH_KEY_SEQ1;
469 /* 此处返回后需要wep后操作 */
470 return HMAC_AP_AUTH_SEQ1_WEP_NOT_RESEND;
471 }
472
473 /* 不支持算法 */
474 *puc_code = MAC_UNSUPT_ALG;
475 return HMAC_AP_AUTH_BUTT;
476 }
477
478 /* 检查用户状态 */
479 if ((auth_rsp_param->user_asoc_state == MAC_USER_STATE_ASSOC) &&
480 (auth_rsp_param->us_auth_type == WLAN_WITP_AUTH_OPEN_SYSTEM)) {
481 /* 用户已经关联上了不需要任何操作 */
482 *usr_ass_stat = MAC_USER_STATE_AUTH_COMPLETE;
483 return HMAC_AP_AUTH_DUMMY;
484 }
485
486 if (auth_rsp_param->us_auth_type == WLAN_WITP_AUTH_OPEN_SYSTEM) {
487 *usr_ass_stat = MAC_USER_STATE_AUTH_COMPLETE;
488
489 return HMAC_AP_AUTH_SEQ1_OPEN_ANY;
490 }
491
492 if (auth_rsp_param->is_wep_allowed == HI_TRUE) {
493 /* seq为1 的认证帧重传 */
494 *usr_ass_stat = MAC_USER_STATE_AUTH_COMPLETE;
495 return HMAC_AP_AUTH_SEQ1_WEP_RESEND;
496 }
497 /* 不支持算法 */
498 *puc_code = MAC_UNSUPT_ALG;
499 return HMAC_AP_AUTH_BUTT;
500 }
501
502 /* ****************************************************************************
503 功能描述 : 处理seq3的auth req
504 输入参数 : 1.auth_rsp_param 处理auth rsp所需的参数
505
506 输出参数 : 1.puc_code 错误码
507 2.pst_usr_ass_stat auth处理完成之后,置相应的user状态
508
509 返 回 值 :获取正常或者失败
510 修改历史 :
511 1.日 期 : 2014年1月10日
512 作 者 : HiSilicon
513 修改内容 : 新生成函数
514 **************************************************************************** */
hmac_encap_auth_rsp_seq3(const hmac_auth_rsp_param_stru * auth_rsp_param,hi_u8 * puc_code,mac_user_asoc_state_enum_uint8 * usr_ass_stat)515 hmac_ap_auth_process_code_enum_uint8 hmac_encap_auth_rsp_seq3(const hmac_auth_rsp_param_stru *auth_rsp_param,
516 hi_u8 *puc_code, mac_user_asoc_state_enum_uint8 *usr_ass_stat)
517 {
518 /* 如果不存在,返回错误 */
519 if (auth_rsp_param->auth_resend == HI_FALSE) {
520 *usr_ass_stat = MAC_USER_STATE_BUTT;
521 *puc_code = MAC_SUCCESSFUL_STATUSCODE;
522 return HMAC_AP_AUTH_BUTT;
523 }
524 /* 检查用户状态 */
525 if ((auth_rsp_param->user_asoc_state == MAC_USER_STATE_ASSOC) &&
526 (auth_rsp_param->us_auth_type == WLAN_WITP_AUTH_OPEN_SYSTEM)) {
527 /* 用户已经关联上了不需要任何操作 */
528 *usr_ass_stat = MAC_USER_STATE_AUTH_COMPLETE;
529 *puc_code = MAC_SUCCESSFUL_STATUSCODE;
530 return HMAC_AP_AUTH_DUMMY;
531 }
532
533 if (auth_rsp_param->us_auth_type == WLAN_WITP_AUTH_OPEN_SYSTEM) {
534 *usr_ass_stat = MAC_USER_STATE_AUTH_COMPLETE;
535 *puc_code = MAC_SUCCESSFUL_STATUSCODE;
536 return HMAC_AP_AUTH_SEQ3_OPEN_ANY;
537 }
538
539 if (auth_rsp_param->user_asoc_state == MAC_USER_STATE_AUTH_KEY_SEQ1) {
540 *usr_ass_stat = MAC_USER_STATE_AUTH_COMPLETE;
541 *puc_code = MAC_SUCCESSFUL_STATUSCODE;
542 return HMAC_AP_AUTH_SEQ3_WEP_COMPLETE;
543 }
544
545 if (auth_rsp_param->user_asoc_state == MAC_USER_STATE_AUTH_COMPLETE) {
546 *usr_ass_stat = MAC_USER_STATE_AUTH_COMPLETE;
547 *puc_code = MAC_SUCCESSFUL_STATUSCODE;
548 return HMAC_AP_AUTH_SEQ3_WEP_COMPLETE;
549 }
550
551 if (auth_rsp_param->user_asoc_state == MAC_USER_STATE_ASSOC) {
552 *usr_ass_stat = MAC_USER_STATE_AUTH_KEY_SEQ1;
553 *puc_code = MAC_SUCCESSFUL_STATUSCODE;
554 return HMAC_AP_AUTH_SEQ3_WEP_ASSOC;
555 }
556
557 /* 不支持算法 */
558 *usr_ass_stat = MAC_USER_STATE_BUTT;
559 *puc_code = MAC_UNSUPT_ALG;
560 return HMAC_AP_AUTH_BUTT;
561 }
562
563 /* ****************************************************************************
564 功能描述 : 处理seq3的auth req
565 输入参数 : 1.auth_rsp_param 处理auth rsp所需的参数数组
566
567 输出参数 : 1.puc_code 错误码
568 2.pst_usr_ass_stat auth处理完成之后,置相应的user状态
569
570 返 回 值 :获取正常或者失败
571 修改历史 :
572 1.日 期 : 2014年1月10日
573 作 者 : HiSilicon
574 修改内容 : 新生成函数
575 **************************************************************************** */
hmac_encap_auth_rsp_get_func(hi_u16 us_auth_seq)576 hmac_auth_rsp_fun hmac_encap_auth_rsp_get_func(hi_u16 us_auth_seq)
577 {
578 hmac_auth_rsp_fun auth_rsp_fun = HI_NULL;
579 switch (us_auth_seq) {
580 case WLAN_AUTH_TRASACTION_NUM_ONE:
581 auth_rsp_fun = hmac_encap_auth_rsp_seq1;
582 break;
583 case WLAN_AUTH_TRASACTION_NUM_THREE:
584 auth_rsp_fun = hmac_encap_auth_rsp_seq3;
585 break;
586 default:
587 auth_rsp_fun = HI_NULL;
588 break;
589 }
590 return auth_rsp_fun;
591 }
592
593 /* ****************************************************************************
594 功能描述 : 判断认证类型是否支持
595 输入参数 : 1.pst_hmac_vap vap指针
596 2. us_auth_type 认证类型
597 返 回 值 :HI_SUCCESS-支持,其他-不支持
598 修改历史 :
599 1.日 期 : 2014年1月10日
600 作 者 : HiSilicon
601 修改内容 : 新生成函数
602 **************************************************************************** */
hmac_encap_auth_rsp_support(const hmac_vap_stru * hmac_vap,hi_u16 us_auth_type)603 hi_u32 hmac_encap_auth_rsp_support(const hmac_vap_stru *hmac_vap, hi_u16 us_auth_type)
604 {
605 /* 检测认证类型是否支持 不支持的话状态位置成UNSUPT_ALG */
606 if ((hmac_vap->auth_mode) != us_auth_type && (hmac_vap->auth_mode != WLAN_WITP_ALG_AUTH_BUTT)) {
607 return HI_ERR_CODE_CONFIG_UNSUPPORT;
608 }
609 return HI_SUCCESS;
610 }
611
612 /*****************************************************************************
613 功能描述 : 删除hmac tid相关的信息
614 修改历史 :
615 1.日 期 : 2014年8月13日
616 作 者 : HiSilicon
617 修改内容 : 新生成函数
618 **************************************************************************** */
hmac_tid_clear(mac_vap_stru * mac_vap,hmac_user_stru * hmac_user)619 hi_void hmac_tid_clear(mac_vap_stru *mac_vap, hmac_user_stru *hmac_user)
620 {
621 hi_u8 loop;
622 hmac_tid_stru *tid = HI_NULL;
623 #if defined(_PRE_WLAN_FEATURE_AMPDU_VAP)
624 hmac_vap_stru *hmac_vap = HI_NULL;
625 #endif
626
627 #if defined(_PRE_WLAN_FEATURE_AMPDU_VAP)
628 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
629 if (hmac_vap == HI_NULL) {
630 oam_error_log0(mac_vap->vap_id, OAM_SF_BA, "{hmac_tid_clear::pst_hmac_vap null.}");
631 return;
632 }
633 #else
634 hi_unref_param(mac_vap);
635 #endif
636 for (loop = 0; loop < WLAN_WME_MAX_TID_NUM; loop++) {
637 tid = &(hmac_user->ast_tid_info[loop]);
638 tid->tid_no = (hi_u8)loop;
639 /* 清除接收方向会话句柄 */
640 if (tid->ba_rx_info != HI_NULL) {
641 hmac_ba_reset_rx_handle(&tid->ba_rx_info, loop);
642 }
643 /* 清除发送方向会话句柄 */
644 if (tid->ba_tx_info != HI_NULL) {
645 hmac_ba_reset_tx_handle(&tid->ba_tx_info);
646 }
647 hmac_user->ast_tid_info[loop].ba_flag = 0;
648 }
649 }
650
651 /* ****************************************************************************
652 功能描述 : 封装auth rsp帧的帧体,CODE默认填写为SUCCESS,下一个函数刷新
653 **************************************************************************** */
hmac_encap_auth_rsp_body(const mac_vap_stru * mac_vap,oal_netbuf_stru * auth_rsp,const oal_netbuf_stru * auth_req)654 hi_u16 hmac_encap_auth_rsp_body(const mac_vap_stru *mac_vap, oal_netbuf_stru *auth_rsp, const oal_netbuf_stru *auth_req)
655 {
656 hi_u8 *puc_data = HI_NULL;
657 hi_u8 *puc_frame = HI_NULL;
658 hmac_tx_ctl_stru *tx_ctl = HI_NULL;
659 hi_u8 mac_addr[WLAN_MAC_ADDR_LEN] = {0};
660 hi_u16 auth_rsp_len;
661 hi_u16 auth_type;
662 hi_u16 auth_seq;
663
664 puc_data = (hi_u8 *)oal_netbuf_header(auth_rsp);
665 tx_ctl = (hmac_tx_ctl_stru *)oal_netbuf_cb(auth_rsp);
666 /* *********************************************************************** */
667 /* Management Frame Format */
668 /* -------------------------------------------------------------------- */
669 /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS| */
670 /* -------------------------------------------------------------------- */
671 /* | 2 |2 |6 |6 |6 |2 |0 - 2312 |4 | */
672 /* -------------------------------------------------------------------- */
673 /* */
674 /* *********************************************************************** */
675 /* *********************************************************************** */
676 /* Set the fields in the frame header */
677 /* *********************************************************************** */
678 /* 设置函数头的frame control字段 */
679 mac_hdr_set_frame_control(puc_data, WLAN_FC0_SUBTYPE_AUTH);
680 /* 获取STA的地址 */
681 mac_get_address2(oal_netbuf_header(auth_req), WLAN_MAC_ADDR_LEN, mac_addr, WLAN_MAC_ADDR_LEN);
682 /* 将DA设置为STA的地址 */
683 if (memcpy_s(((mac_ieee80211_frame_stru *)puc_data)->auc_address1, WLAN_MAC_ADDR_LEN, mac_addr,
684 WLAN_MAC_ADDR_LEN) != EOK) {
685 oam_error_log0(0, 0, "{hmac_encap_auth_rsp_body::copy address1 failed!}");
686 return 0;
687 }
688 /* 将SA设置为dot11MacAddress */
689 if (memcpy_s(((mac_ieee80211_frame_stru *)puc_data)->auc_address2, WLAN_MAC_ADDR_LEN,
690 mac_vap->mib_info->wlan_mib_sta_config.auc_dot11_station_id, WLAN_MAC_ADDR_LEN) != EOK) {
691 oam_error_log0(0, 0, "{hmac_encap_auth_rsp_body::copy address2 failed!}");
692 return 0;
693 }
694 /* 设置BSSID */
695 if (memcpy_s(((mac_ieee80211_frame_stru *)puc_data)->auc_address3, WLAN_MAC_ADDR_LEN, mac_vap->auc_bssid,
696 WLAN_MAC_ADDR_LEN) != EOK) {
697 oam_error_log0(0, 0, "{hmac_encap_auth_rsp_body::copy address3 failed!}");
698 return 0;
699 }
700
701 /* *********************************************************************** */
702 /* Set the contents of the frame body */
703 /* *********************************************************************** */
704 /* *********************************************************************** */
705 /* Authentication Frame - Frame Body */
706 /* --------------------------------------------------------------------- */
707 /* |Auth Algo Number|Auth Trans Seq Number|Status Code| Challenge Text | */
708 /* --------------------------------------------------------------------- */
709 /* | 2 |2 |2 | 3 - 256 | */
710 /* --------------------------------------------------------------------- */
711 /* */
712 /* *********************************************************************** */
713 /* 解析认证类型 */
714 auth_type = mac_get_auth_alg(oal_netbuf_header(auth_req));
715 /* 解析auth transaction number */
716 auth_seq = mac_get_auth_seq_num(oal_netbuf_header(auth_req));
717 if (auth_seq > WLAN_AUTH_TRASACTION_NUM_FOUR) {
718 oam_warning_log1(0, OAM_SF_AUTH, "{hmac_encap_auth_rsp_body::invalid auth seq [%d]}", auth_seq);
719 return 0;
720 }
721
722 puc_frame = (hi_u8 *)(puc_data + MAC_80211_FRAME_LEN);
723 /* 计算认证相应帧的长度 */
724 auth_rsp_len = MAC_80211_FRAME_LEN + MAC_AUTH_ALG_LEN + MAC_AUTH_TRANS_SEQ_NUM_LEN + MAC_STATUS_CODE_LEN;
725 tx_ctl->frame_header_length = MAC_80211_FRAME_LEN;
726 tx_ctl->frame_header = (mac_ieee80211_frame_stru *)oal_netbuf_header(auth_rsp);
727 tx_ctl->mac_head_type = 1;
728 /* 设置认证类型IE */
729 puc_frame[0] = (auth_type & 0x00FF);
730 puc_frame[1] = (auth_type & 0xFF00) >> 8; /* 右移8位 */
731 /* 将收到的transaction number + 1后复制给新的认证响应帧 */
732 puc_frame[2] = ((auth_seq + 1) & 0x00FF); /* 2 元素索引 */
733 puc_frame[3] = ((auth_seq + 1) & 0xFF00) >> 8; /* 3 元素索引 右移8位 */
734 /* 状态为初始化为成功 */
735 puc_frame[4] = MAC_SUCCESSFUL_STATUSCODE; /* 4 元素索引 */
736 puc_frame[5] = 0; /* 5 元素索引 */
737
738 return auth_rsp_len;
739 }
740
741 /* ****************************************************************************
742 功能描述 : 根据用户信息更新auth rsp帧的status code
743 **************************************************************************** */
hmac_update_status_code_by_user(const mac_vap_stru * mac_vap,hmac_tx_ctl_stru * tx_ctl,hi_u8 * puc_frame,hi_u16 auth_type,hi_u8 user_index)744 hi_u32 hmac_update_status_code_by_user(const mac_vap_stru *mac_vap, hmac_tx_ctl_stru *tx_ctl, hi_u8 *puc_frame,
745 hi_u16 auth_type, hi_u8 user_index)
746 {
747 hmac_user_stru *hmac_user = HI_NULL;
748 hmac_vap_stru *hmac_vap = HI_NULL;
749
750 /* 获取hmac user指针 */
751 hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(user_index);
752 if ((hmac_user == HI_NULL) || (hmac_user->base_user == HI_NULL)) {
753 oam_error_log0(mac_vap->vap_id, OAM_SF_AUTH, "{hmac_update_status_code_by_user::hmac_user is NULL}");
754 puc_frame[4] = MAC_UNSPEC_FAIL; /* 4 元素索引 */
755 return HI_FAIL;
756 }
757 /* 获取hmac vap指针 */
758 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
759 if ((hmac_vap == HI_NULL) || (hmac_vap->base_vap != mac_vap)) {
760 oam_error_log1(0, OAM_SF_AUTH,
761 "{hmac_update_status_code_by_user::vap is error, change user[idx=%d] state to BUTT!}",
762 hmac_user->base_user->us_assoc_id);
763 puc_frame[4] = MAC_UNSPEC_FAIL; /* 4 元素索引 */
764 mac_user_set_asoc_state(hmac_user->base_user, MAC_USER_STATE_BUTT);
765 return HI_FAIL;
766 }
767 tx_ctl->us_tx_user_idx = user_index;
768 /* 判断算法是否支持 */
769 if (hmac_encap_auth_rsp_support(hmac_vap, auth_type) != HI_SUCCESS) {
770 oam_warning_log1(0, OAM_SF_AUTH, "{hmac_update_status_code_by_user::auth type[%d] not support!}", auth_type);
771 puc_frame[4] = MAC_UNSUPT_ALG; /* 4 元素索引 */
772 hmac_user_set_asoc_state(hmac_vap->base_vap, hmac_user->base_user, MAC_USER_STATE_BUTT);
773 return HI_FAIL;
774 }
775 return HI_SUCCESS;
776 }
777
778 /* ****************************************************************************
779 功能描述 : 更新auth rsp帧的status code
780 **************************************************************************** */
hmac_update_auth_rsp_status_code(mac_vap_stru * mac_vap,oal_netbuf_stru * auth_rsp,const oal_netbuf_stru * auth_req,hi_u16 auth_rsp_len,hmac_auth_rsp_handle_stru * auth_rsp_handle)781 hi_u32 hmac_update_auth_rsp_status_code(mac_vap_stru *mac_vap, oal_netbuf_stru *auth_rsp,
782 const oal_netbuf_stru *auth_req, hi_u16 auth_rsp_len, hmac_auth_rsp_handle_stru *auth_rsp_handle)
783 {
784 hmac_tx_ctl_stru *tx_ctl = (hmac_tx_ctl_stru *)oal_netbuf_cb(auth_rsp);
785 hi_u8 *puc_data = (hi_u8 *)oal_netbuf_header(auth_rsp);
786 hi_u8 *puc_frame = (hi_u8 *)(puc_data + MAC_80211_FRAME_LEN); /* 除MAC HDR的帧体起始位置 */
787 hmac_mac_addr_stru auth_mac_addr = {0};
788 hi_u32 ret;
789 hi_u16 auth_type = mac_get_auth_alg(oal_netbuf_header(auth_req));
790 hi_u16 auth_seq = mac_get_auth_seq_num(oal_netbuf_header(auth_req)); /* auth transaction number */
791 hi_u8 zero_mac_addr[WLAN_MAC_ADDR_LEN] = {0};
792 hi_u8 mac_addr[WLAN_MAC_ADDR_LEN] = {0};
793 hi_u8 user_index = 0xff; /* 默认为无效用户id 0xff */
794
795 /* 获取STA的地址 */
796 mac_get_address2(oal_netbuf_header(auth_req), WLAN_MAC_ADDR_LEN, mac_addr, WLAN_MAC_ADDR_LEN);
797 if (memcmp(zero_mac_addr, mac_addr, WLAN_MAC_ADDR_LEN) == 0) {
798 oam_warning_log0(0, OAM_SF_AUTH, "{hmac_update_auth_rsp_status_code::user mac is all 0 !}");
799 puc_frame[4] = MAC_UNSPEC_FAIL; /* 4 元素索引 */
800 tx_ctl->us_tx_user_idx = MAC_INVALID_USER_ID;
801 tx_ctl->us_mpdu_len = auth_rsp_len;
802 return HI_FAIL;
803 }
804
805 /* 获取用户idx */
806 auth_mac_addr.mac_addr = mac_addr;
807 auth_mac_addr.addr_len = WLAN_MAC_ADDR_LEN;
808 ret = hmac_encap_auth_rsp_get_user_idx(mac_vap, auth_mac_addr, (WLAN_AUTH_TRASACTION_NUM_ONE == auth_seq),
809 &auth_rsp_handle->auth_rsp_param.auth_resend, &user_index);
810 if (ret != HI_SUCCESS) {
811 oam_warning_log1(0, OAM_SF_AUTH, "{hmac_encap_auth_rsp::get_user_idx fail, error code[%d]!}", ret);
812 puc_frame[4] = MAC_UNSPEC_FAIL; /* 4 元素索引 */
813 #ifdef _PRE_WLAN_FEATURE_MESH
814 if (ret == HI_ERR_CODE_MESH_NOT_ACCEPT_PEER) {
815 /* mesh用户满使用MAC_AP_FULL status code */
816 puc_frame[4] = MAC_AP_FULL; /* 4 元素索引 */
817 }
818 #endif
819 tx_ctl->us_tx_user_idx = MAC_INVALID_USER_ID;
820 tx_ctl->us_mpdu_len = auth_rsp_len;
821 return HI_FAIL;
822 }
823 /* 申请user并刷新status code */
824 tx_ctl->us_tx_user_idx = MAC_INVALID_USER_ID; /* 默认设置为无效ID */
825 tx_ctl->us_mpdu_len = auth_rsp_len;
826 /* 赋值出参 */
827 auth_rsp_handle->auth_rsp_param.us_auth_type = auth_type;
828 auth_rsp_handle->auth_rsp_fun = hmac_encap_auth_rsp_get_func(auth_seq);
829 return hmac_update_status_code_by_user(mac_vap, tx_ctl, puc_frame, auth_type, user_index);
830 }
831
832 /* ****************************************************************************
833 功能描述 : 根据auth回调的返回值进行auth后续处理
834 **************************************************************************** */
hmac_auth_rsp_handle_result(const hmac_vap_stru * hmac_vap,hmac_tx_ctl_stru * tx_ctl,hmac_ap_auth_process_code_enum_uint8 auth_proc_rst,hi_u8 * puc_frame,hi_u8 * puc_chtxt)835 hi_u16 hmac_auth_rsp_handle_result(const hmac_vap_stru *hmac_vap, hmac_tx_ctl_stru *tx_ctl,
836 hmac_ap_auth_process_code_enum_uint8 auth_proc_rst, hi_u8 *puc_frame, hi_u8 *puc_chtxt)
837 {
838 hi_u16 auth_rsp_len = (hi_u16)tx_ctl->us_mpdu_len;
839
840 /* 可直接获取hmac vap以及hmac user hmac_update_status_code_by_user已判空处理 */
841 hmac_user_stru *hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(tx_ctl->us_tx_user_idx);
842 if (hmac_user == HI_NULL) {
843 return 0;
844 }
845 /* 根据返回的code进行后续处理 */
846 switch (auth_proc_rst) {
847 case HMAC_AP_AUTH_SEQ1_OPEN_ANY:
848 case HMAC_AP_AUTH_SEQ3_OPEN_ANY:
849 mac_user_init_key(hmac_user->base_user);
850 break;
851
852 case HMAC_AP_AUTH_SEQ1_WEP_NOT_RESEND:
853 hmac_config_11i_add_wep_entry(hmac_vap->base_vap, WLAN_MAC_ADDR_LEN, hmac_user->base_user->user_mac_addr);
854 hmac_mgmt_encap_chtxt(puc_frame, puc_chtxt, &auth_rsp_len, hmac_user);
855 /* 为该用户启动一个定时器,超时认证失败 */
856 frw_timer_create_timer(&hmac_user->mgmt_timer, hmac_mgmt_timeout_ap,
857 (hi_u16)hmac_vap->base_vap->mib_info->wlan_mib_sta_config.dot11_authentication_response_time_out,
858 hmac_user, HI_FALSE);
859 hmac_user->base_user->key_info.cipher_type =
860 mac_get_wep_type(hmac_vap->base_vap, mac_mib_get_wep_default_keyid(hmac_vap->base_vap));
861 break;
862
863 case HMAC_AP_AUTH_SEQ1_WEP_RESEND:
864 /* seq为1 的认证帧重传 */
865 hmac_mgmt_encap_chtxt(puc_frame, puc_chtxt, &auth_rsp_len, hmac_user);
866 /* 重启超时定时器 */
867 frw_timer_restart_timer(&hmac_user->mgmt_timer, hmac_user->mgmt_timer.timeout, HI_FALSE);
868 break;
869
870 case HMAC_AP_AUTH_SEQ3_WEP_COMPLETE:
871 if (hmac_mgmt_is_challenge_txt_equal(puc_chtxt, hmac_user->ch_text) == HI_TRUE) {
872 mac_user_set_asoc_state(hmac_user->base_user, MAC_USER_STATE_AUTH_COMPLETE);
873 oal_mem_free(hmac_user->ch_text);
874 hmac_user->ch_text = HI_NULL;
875 /* cancel timer for auth */
876 frw_timer_immediate_destroy_timer(&hmac_user->mgmt_timer);
877 } else {
878 puc_frame[4] = MAC_CHLNG_FAIL; /* 4 元素索引 */
879 mac_user_set_asoc_state(hmac_user->base_user, MAC_USER_STATE_BUTT);
880 }
881 break;
882
883 case HMAC_AP_AUTH_SEQ3_WEP_ASSOC:
884 hmac_mgmt_encap_chtxt(puc_frame, puc_chtxt, &auth_rsp_len, hmac_user);
885 /* 开启超时定时器 */
886 frw_timer_create_timer(&hmac_user->mgmt_timer, hmac_mgmt_timeout_ap,
887 (hi_u16)hmac_vap->base_vap->mib_info->wlan_mib_sta_config.dot11_authentication_response_time_out,
888 hmac_user, HI_FALSE);
889 break;
890
891 case HMAC_AP_AUTH_DUMMY:
892 break;
893
894 default:
895 mac_user_init_key(hmac_user->base_user);
896 hmac_user->base_user->user_asoc_state = MAC_USER_STATE_BUTT;
897 break;
898 }
899
900 tx_ctl->us_mpdu_len = (hi_u32)auth_rsp_len; /* 长度可能变更,重新刷新CB字段长度信息 */
901 return auth_rsp_len;
902 }
903
904 /* ****************************************************************************
905 功能描述 : 封装auth rsp帧
906 输入参数 : [1]mac_vap
907 [2]puc_chtxt
908 [3]auth_req
909 输出参数 : [1]auth_rsp
910 返 回 值 : hi_u16
911 **************************************************************************** */
hmac_encap_auth_rsp(mac_vap_stru * mac_vap,oal_netbuf_stru * auth_rsp,const oal_netbuf_stru * auth_req,hi_u8 * puc_chtxt,hi_u16 chtxt_len)912 hi_u16 hmac_encap_auth_rsp(mac_vap_stru *mac_vap, oal_netbuf_stru *auth_rsp, const oal_netbuf_stru *auth_req,
913 hi_u8 *puc_chtxt, hi_u16 chtxt_len)
914 {
915 hmac_tx_ctl_stru *tx_ctl = (hmac_tx_ctl_stru *)oal_netbuf_cb(auth_rsp); /* rsp帧的tx cb字段 */
916 hmac_user_stru *hmac_user = HI_NULL;
917 hmac_vap_stru *hmac_vap = HI_NULL;
918 hi_u8 *puc_frame = HI_NULL;
919 hi_u16 auth_rsp_len;
920 hmac_ap_auth_process_code_enum_uint8 auth_proc_rst; /* 认证方法 */
921 hmac_auth_rsp_handle_stru auth_rsp_handle;
922
923 hi_unref_param(chtxt_len);
924 /* 组auth响应帧初值 状态码为SUCCESS */
925 auth_rsp_len = hmac_encap_auth_rsp_body(mac_vap, auth_rsp, auth_req);
926 if (auth_rsp_len == 0) {
927 return auth_rsp_len;
928 }
929 /* 刷新auth响应帧状态码的值 失败后不继续处理直接返回当前帧长 */
930 if (hmac_update_auth_rsp_status_code(mac_vap, auth_rsp, auth_req, auth_rsp_len, &auth_rsp_handle) != HI_SUCCESS) {
931 return auth_rsp_len;
932 }
933 /* 执行成功后 可直接获取hmac vap以及hmac user hmac_update_status_code_by_user已判空处理 */
934 hmac_user = (hmac_user_stru *)hmac_user_get_user_stru(tx_ctl->us_tx_user_idx);
935 hmac_vap = hmac_vap_get_vap_stru(mac_vap->vap_id);
936 if (hmac_user == HI_NULL || hmac_vap == HI_NULL) {
937 return 0;
938 }
939 /* 初始化处理参数 */
940 auth_rsp_handle.auth_rsp_param.is_wep_allowed = mac_is_wep_allowed(mac_vap);
941 auth_rsp_handle.auth_rsp_param.user_asoc_state = hmac_user->base_user->user_asoc_state;
942
943 /* 处理seq1或者seq3 */
944 puc_frame = (hi_u8 *)oal_netbuf_header(auth_rsp) + MAC_80211_FRAME_LEN; /* 除MAC HDR的帧体起始位置 */
945 if (auth_rsp_handle.auth_rsp_fun != HI_NULL) {
946 auth_proc_rst = auth_rsp_handle.auth_rsp_fun(&auth_rsp_handle.auth_rsp_param, &puc_frame[4], /* 4 元素索引 */
947 &hmac_user->base_user->user_asoc_state);
948 /* 清空 HMAC层TID信息 */
949 hmac_tid_clear(mac_vap, hmac_user);
950 } else {
951 auth_proc_rst = HMAC_AP_AUTH_BUTT;
952 mac_user_set_asoc_state(hmac_user->base_user, MAC_USER_STATE_BUTT);
953 puc_frame[4] = MAC_AUTH_SEQ_FAIL; /* 4 元素索引 */
954 }
955 oam_warning_log1(mac_vap->vap_id, OAM_SF_AUTH, "{hmac_encap_auth_rsp::ul_auth_proc_rst:%d}", auth_proc_rst);
956
957 /* 根据返回的code进行后续处理 */
958 if (auth_proc_rst == HMAC_AP_AUTH_SEQ3_WEP_COMPLETE) {
959 puc_chtxt = mac_get_auth_ch_text(oal_netbuf_header(auth_req)); /* seq3提取req的挑战字符串 */
960 }
961 puc_frame = (hi_u8 *)oal_netbuf_header(auth_rsp) + MAC_80211_FRAME_LEN; /* 取帧体起始指针 */
962 auth_rsp_len = hmac_auth_rsp_handle_result(hmac_vap, tx_ctl, auth_proc_rst, puc_frame, puc_chtxt);
963
964 #if (_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC == _PRE_MULTI_CORE_MODE)
965 /* dmac offload架构下,同步user关联状态信息到dmac */
966 if (hmac_config_user_asoc_state_syn(hmac_vap->base_vap, hmac_user->base_user) != HI_SUCCESS) {
967 oam_error_log0(0, OAM_SF_AUTH, "{hmac_ap_rx_auth_req::user_asoc_state_syn failed.}");
968 }
969 #endif
970 return auth_rsp_len;
971 }
972
973 #ifdef _PRE_WLAN_FEATURE_MESH
974 /* ****************************************************************************
975 功能描述 : 封装mesh peering open帧
976 输入参数 : 1. vap指针2.hi_u8 *puc_data 3.mac_mesh_action_data_stru *st_action_data
977 返 回 值 : 帧长度
978 1.日 期 : 2019年2月1日
979 作 者 : HiSilicon
980 修改内容 : 新生成函数
981 **************************************************************************** */
hmac_encap_mesh_peering_open_frame(mac_vap_stru * mac_vap,hi_u8 * data,const mac_action_data_stru * action)982 hi_u32 hmac_encap_mesh_peering_open_frame(mac_vap_stru *mac_vap, hi_u8 *data, const mac_action_data_stru *action)
983 {
984 hi_u8 ie_len = 0;
985 hi_u8 *puc_frame_origin = data; /* 保存起始地址,便于计算长度 */
986
987 if (mac_vap->mib_info == HI_NULL) {
988 return HI_ERR_CODE_PTR_NULL;
989 }
990
991 /* *********************************************************************** */
992 /* Management Frame Format */
993 /* -------------------------------------------------------------------- */
994 /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS| */
995 /* -------------------------------------------------------------------- */
996 /* | 2 |2 |6 |6 |6 |2 |0 - 2312 |4 | */
997 /* -------------------------------------------------------------------- */
998 /* */
999 /* *********************************************************************** */
1000 /* *********************************************************************** */
1001 /* Set the fields in the frame header */
1002 /* *********************************************************************** */
1003 /* 设置 Frame Control field */
1004 mac_hdr_set_frame_control(data, WLAN_FC0_SUBTYPE_ACTION);
1005
1006 /* 设置 DA address1: STA MAC地址 */
1007 /* 设置 SA address2: dot11MACAddress */
1008 /* 设置 DA address3::BSSID */
1009 if ((memcpy_s(data + WLAN_HDR_ADDR1_OFFSET, WLAN_MAC_ADDR_LEN, action->puc_dst, WLAN_MAC_ADDR_LEN) != EOK) ||
1010 (memcpy_s(data + WLAN_HDR_ADDR2_OFFSET, WLAN_MAC_ADDR_LEN,
1011 mac_vap->mib_info->wlan_mib_sta_config.auc_dot11_station_id, WLAN_MAC_ADDR_LEN) != EOK) ||
1012 (memcpy_s(data + WLAN_HDR_ADDR3_OFFSET, WLAN_MAC_ADDR_LEN, action->puc_bssid, WLAN_MAC_ADDR_LEN) != EOK)) {
1013 oam_error_log0(0, 0, "{hmac_encap_mesh_peering_open_frame::memcpy_s fail.}");
1014 return 0;
1015 }
1016
1017 data += MAC_80211_FRAME_LEN;
1018 /* *********************************************************************** */
1019 /* Set the contents of the frame body */
1020 /* *********************************************************************** */
1021 /* *********************************************************************** */
1022 /* Mesh peering open Frame - Frame Body */
1023 /* --------------------------------------------------------------------- */
1024 /* |Category|action code | Capability Information | Supported Rates | */
1025 /* --------------------------------------------------------------------- */
1026 /* |1 |1 |2 |3-10 | */
1027 /* --------------------------------------------------------------------- */
1028 /* --------------------------------------------------------------------- */
1029 /* |Externed Surpported rates|RSN | HT Capabilities | Extended Capabilities */
1030 /* --------------------------------------------------------------------- */
1031 /* |3-257 |4-256 | */
1032 /* --------------------------------------------------------------------- */
1033 /* --------------------------------------------------------------------- */
1034 /* | RSN | HT Capabilities | Extended Capabilities | */
1035 /* --------------------------------------------------------------------- */
1036 /* |36-256 |3 |28 |3-8 | */
1037 /* --------------------------------------------------------------------- */
1038 /* --------------------------------------------------------------------- */
1039 /* | MESH Element| MIC |Authenticated Mesh Peering Exchange| */
1040 /* --------------------------------------------------------------------- */
1041 /* |7-257 |X | */
1042 /* --------------------------------------------------------------------- */
1043 /* */
1044 /* *********************************************************************** */
1045 /* 设置Category 和Action Code */
1046 *data = MAC_ACTION_CATEGORY_SELF_PROTECTED;
1047 *(data + 1) = MAC_SP_ACTION_MESH_PEERING_OPEN;
1048 data += 2; /* 自增2 */
1049
1050 /* 设置Capability Info Field */
1051 mac_set_cap_info_ap((hi_void *)mac_vap, data);
1052 data += MAC_CAP_INFO_LEN;
1053
1054 /* 设置 Supported Rates IE */
1055 mac_set_supported_rates_ie((hi_void *)mac_vap, data, &ie_len);
1056 data += ie_len;
1057
1058 /* 设置 Extended Supported Rates IE */
1059 mac_set_exsup_rates_ie((hi_void *)mac_vap, data, &ie_len);
1060 data += ie_len;
1061
1062 /* 设置RSN IE */
1063 mac_set_rsn_mesh_ie_authenticator((hi_void *)mac_vap, data, WLAN_FC0_SUBTYPE_PROBE_RSP, &ie_len);
1064 data += ie_len;
1065
1066 /* 设置 HT-Capabilities Information IE */
1067 mac_set_ht_capabilities_ie((hi_void *)mac_vap, data, &ie_len);
1068 data += ie_len;
1069
1070 /* 设置 HT-Operation Information IE */
1071 mac_set_ht_opern_ie((hi_void *)mac_vap, data, &ie_len);
1072 data += ie_len;
1073
1074 /* 填充wmm信息 */
1075 mac_set_wmm_params_ie(mac_vap, data, mac_vap->mib_info->wlan_mib_sta_config.dot11_qos_option_implemented, &ie_len);
1076 data += ie_len;
1077
1078 /* 填充bss load信息 */
1079 mac_set_bssload_ie(mac_vap, data, &ie_len);
1080 data += ie_len;
1081
1082 /* 设置 Extended Capabilities Information IE */
1083 mac_set_ext_capabilities_ie((hi_void *)mac_vap, data, &ie_len);
1084 data += ie_len;
1085
1086 /* 设置Hisi-Mesh私有信息 */
1087 mac_set_hisi_mesh_optimization_ie((hi_void *)mac_vap, data, &ie_len);
1088 data += ie_len;
1089
1090 /* 填充WPS信息 */
1091 if (action->data_len > 0) {
1092 /* wpa带下来的action puc data携带category和Action code,共两个字节,用于驱动判断下发的帧类型,无需填充 */
1093 /* Mesh peering open action frame 字段 */
1094 /* Bytes |1 |1 |...| */
1095 /* ie |action category|action code|...| */
1096 if (memcpy_s(data, action->data_len - 2, action->puc_data + 2, action->data_len - 2) != EOK) { /* 2 计算偏差 */
1097 oam_error_log0(0, 0, "hmac_encap_mesh_peering_open_frame:: st_action_data->puc_data memcpy_s fail.");
1098 return HI_FAIL;
1099 }
1100 data += (action->data_len - 2); /* 减去2 */
1101 }
1102
1103 return (hi_u32)(data - puc_frame_origin);
1104 }
1105
1106 /* ****************************************************************************
1107 功能描述 : 封装mesh peering confirm帧
1108 输入参数 : 1. vap指针2.hmac_user指针3.hi_u8 *puc_data 4. mac_mesh_action_data_stru *st_action_data
1109 返 回 值 :帧长度
1110 修改历史 :
1111 1.日 期 : 2019年2月1日
1112 作 者 : HiSilicon
1113 修改内容 : 新生成函数
1114 **************************************************************************** */
hmac_encap_mesh_peering_confirm_frame(mac_vap_stru * mac_vap,hi_u8 * data,const mac_action_data_stru * action_data)1115 hi_u32 hmac_encap_mesh_peering_confirm_frame(mac_vap_stru *mac_vap, hi_u8 *data,
1116 const mac_action_data_stru *action_data)
1117 {
1118 hi_u8 ie_len = 0;
1119
1120 /* 保存起始地址,便于计算长度 */
1121 hi_u8 *puc_frame_origin = data;
1122
1123 if (mac_vap->mib_info == HI_NULL) {
1124 return HI_ERR_CODE_PTR_NULL;
1125 }
1126
1127 /* *********************************************************************** */
1128 /* Management Frame Format */
1129 /* -------------------------------------------------------------------- */
1130 /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS| */
1131 /* -------------------------------------------------------------------- */
1132 /* | 2 |2 |6 |6 |6 |2 |0 - 2312 |4 | */
1133 /* -------------------------------------------------------------------- */
1134 /* */
1135 /* *********************************************************************** */
1136 /* *********************************************************************** */
1137 /* Set the fields in the frame header */
1138 /* *********************************************************************** */
1139 /* 设置 Frame Control field */
1140 mac_hdr_set_frame_control(data, WLAN_FC0_SUBTYPE_ACTION);
1141
1142 /* 设置 DA address1: 远端节点MAC地址 */
1143 /* 设置 SA address2: dot11MACAddress */
1144 /* 设置 DA address3::BSSID */
1145 if ((memcpy_s(data + WLAN_HDR_ADDR1_OFFSET, WLAN_MAC_ADDR_LEN, action_data->puc_dst, WLAN_MAC_ADDR_LEN) != EOK) ||
1146 (memcpy_s(data + WLAN_HDR_ADDR2_OFFSET, WLAN_MAC_ADDR_LEN,
1147 mac_vap->mib_info->wlan_mib_sta_config.auc_dot11_station_id, WLAN_MAC_ADDR_LEN) != EOK) ||
1148 (memcpy_s(data + WLAN_HDR_ADDR3_OFFSET, WLAN_MAC_ADDR_LEN, action_data->puc_bssid, WLAN_MAC_ADDR_LEN) != EOK)) {
1149 oam_error_log0(0, 0, "{hmac_encap_mesh_peering_confirm_frame::memcpy_s fail.}");
1150 return 0;
1151 }
1152 data += MAC_80211_FRAME_LEN;
1153 /* *********************************************************************** */
1154 /* Set the contents of the frame body */
1155 /* *********************************************************************** */
1156 /* *********************************************************************** */
1157 /* Mesh peering confirm Frame - Frame Body */
1158 /* --------------------------------------------------------------------- */
1159 /* |Category|action code | Capability Information |AID| Supported Rates | */
1160 /* --------------------------------------------------------------------- */
1161 /* */
1162 /* --------------------------------------------------------------------- */
1163 /* --------------------------------------------------------------------- */
1164 /* |Externed Surpported rates|RSN | HT Capabilities | Extended Capabilities */
1165 /* --------------------------------------------------------------------- */
1166 /* */
1167 /* --------------------------------------------------------------------- */
1168 /* --------------------------------------------------------------------- */
1169 /* | MESH Element| MIC |Authenticated Mesh Peering Exchange| */
1170 /* --------------------------------------------------------------------- */
1171 /* *********************************************************************** */
1172 /* 设置Category 和Action Code */
1173 *data = MAC_ACTION_CATEGORY_SELF_PROTECTED;
1174 *(data + 1) = MAC_SP_ACTION_MESH_PEERING_CONFIRM;
1175 data += 2; /* 自增2 */
1176
1177 /* 设置Capability Info Field */
1178 mac_set_cap_info_ap((hi_void *)mac_vap, data);
1179 data += MAC_CAP_INFO_LEN;
1180
1181 /* 设置Mesh AID ,直接由wpa 下发 */
1182 if (memcpy_s(data, MAC_AID_LEN, action_data->puc_data + 2, MAC_AID_LEN) != EOK) { /* 2 用于计算偏差 */
1183 oam_error_log0(0, OAM_SF_CFG, "hmac_encap_mesh_peering_confirm_frame::st_action_data->puc_data memcpy_s fail.");
1184 return HI_FAIL;
1185 }
1186 data += MAC_AID_LEN;
1187
1188 /* 设置 Supported Rates IE */
1189 mac_set_supported_rates_ie((hi_void *)mac_vap, data, &ie_len);
1190 data += ie_len;
1191
1192 /* 设置 Extended Supported Rates IE */
1193 mac_set_exsup_rates_ie((hi_void *)mac_vap, data, &ie_len);
1194 data += ie_len;
1195
1196 /* 设置RSN IE */
1197 mac_set_rsn_mesh_ie_authenticator((hi_void *)mac_vap, data, WLAN_FC0_SUBTYPE_PROBE_RSP, &ie_len);
1198 data += ie_len;
1199
1200 /* 设置 HT-Capabilities Information IE */
1201 mac_set_ht_capabilities_ie((hi_void *)mac_vap, data, &ie_len);
1202 data += ie_len;
1203
1204 /* 设置 HT-Operation Information IE */
1205 mac_set_ht_opern_ie((hi_void *)mac_vap, data, &ie_len);
1206 data += ie_len;
1207
1208 /* 填充wmm信息 */
1209 mac_set_wmm_params_ie(mac_vap, data, mac_vap->mib_info->wlan_mib_sta_config.dot11_qos_option_implemented, &ie_len);
1210 data += ie_len;
1211
1212 /* 填充bss load信息 */
1213 mac_set_bssload_ie(mac_vap, data, &ie_len);
1214 data += ie_len;
1215
1216 /* 设置 Extended Capabilities Information IE */
1217 mac_set_ext_capabilities_ie((hi_void *)mac_vap, data, &ie_len);
1218 data += ie_len;
1219
1220 /* 填充WPS信息 */
1221 /* Mesh peering confirm action frame 字段 */
1222 /* Bytes |1 |1 |2|...| */
1223 /* ie |action category|action code|aid|...| */
1224 if (action_data->data_len > 0) {
1225 if (memcpy_s(data, action_data->data_len - 4, action_data->puc_data + 4, /* 4 用于计算偏差 */
1226 action_data->data_len - 4) != EOK) { /* 4 用于计算偏差 */
1227 oam_error_log0(0, 0, "hmac_encap_mesh_peering_confirm_frame::action_data->puc_data memcpy_s fail.");
1228 return HI_FAIL;
1229 }
1230 data += action_data->data_len - 4; /* 4 用于计算偏差 */
1231 }
1232
1233 return (hi_u32)(data - puc_frame_origin);
1234 }
1235
1236 /* ****************************************************************************
1237 功能描述 : 封装mesh peering close帧
1238 输入参数 : 1. vap指针2.hi_u8 *puc_data 3.hisi_action_data_stru *st_action_data
1239 返 回 值 : 帧长度
1240 1.日 期 : 2019年2月1日
1241 作 者 : HiSilicon
1242 修改内容 : 新生成函数
1243 **************************************************************************** */
hmac_encap_mesh_peering_close_frame(const mac_vap_stru * mac_vap,hi_u8 * puc_data,const mac_action_data_stru * action_data)1244 hi_u32 hmac_encap_mesh_peering_close_frame(const mac_vap_stru *mac_vap, hi_u8 *puc_data,
1245 const mac_action_data_stru *action_data)
1246 {
1247 hi_u8 *puc_frame_origin = HI_NULL;
1248 hi_u32 us_frame_len;
1249
1250 /* 保存起始地址,便于计算长度 */
1251 puc_frame_origin = puc_data;
1252
1253 if (mac_vap->mib_info == HI_NULL) {
1254 return HI_ERR_CODE_PTR_NULL;
1255 }
1256 /* *********************************************************************** */
1257 /* Management Frame Format */
1258 /* -------------------------------------------------------------------- */
1259 /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS| */
1260 /* -------------------------------------------------------------------- */
1261 /* | 2 |2 |6 |6 |6 |2 |0 - 2312 |4 | */
1262 /* -------------------------------------------------------------------- */
1263 /* */
1264 /* *********************************************************************** */
1265 /* *********************************************************************** */
1266 /* Set the fields in the frame header */
1267 /* *********************************************************************** */
1268 /* 设置 Frame Control field */
1269 mac_hdr_set_frame_control(puc_data, WLAN_FC0_SUBTYPE_ACTION);
1270
1271 /* 设置 DA address1: STA MAC地址 */
1272 if (memcpy_s(puc_data + WLAN_HDR_ADDR1_OFFSET, WLAN_MAC_ADDR_LEN,
1273 action_data->puc_dst, WLAN_MAC_ADDR_LEN) != EOK) {
1274 oam_error_log0(0, 0, "{hmac_encap_mesh_peering_close_frame::memcpy_s fail.}");
1275 return 0;
1276 }
1277 /* 设置 SA address2: dot11MACAddress */
1278 if (memcpy_s(puc_data + WLAN_HDR_ADDR2_OFFSET, WLAN_MAC_ADDR_LEN,
1279 mac_vap->mib_info->wlan_mib_sta_config.auc_dot11_station_id, WLAN_MAC_ADDR_LEN) != EOK) {
1280 oam_error_log0(0, 0, "{hmac_encap_mesh_peering_close_frame::memcpy_s fail.}");
1281 return 0;
1282 }
1283 /* 设置 DA address3::BSSID */
1284 if (memcpy_s(puc_data + WLAN_HDR_ADDR3_OFFSET, WLAN_MAC_ADDR_LEN, action_data->puc_bssid, WLAN_MAC_ADDR_LEN) !=
1285 EOK) {
1286 oam_error_log0(0, 0, "{hmac_encap_mesh_peering_close_frame::memcpy_s fail.}");
1287 return 0;
1288 }
1289 puc_data += MAC_80211_FRAME_LEN;
1290 /* *********************************************************************** */
1291 /* Set the contents of the frame body */
1292 /* *********************************************************************** */
1293 /* *********************************************************************** */
1294 /* Mesh peering close Frame - Frame Body */
1295 /* --------------------------------------------------------------------- */
1296 /* |Category|action code | Mesh Element | MIC Element |Authenticated Mesh Peering Exchange */
1297 /* --------------------------------------------------------------------- */
1298 /* *********************************************************************** */
1299 /* 设置Category 和Action Code */
1300 *puc_data = MAC_ACTION_CATEGORY_SELF_PROTECTED;
1301 *(puc_data + 1) = MAC_SP_ACTION_MESH_PEERING_CLOSE;
1302 puc_data += 2; /* 自增2 */
1303
1304 /* 填充WPS信息 */
1305 if (action_data->data_len > 0) {
1306 if (memcpy_s(puc_data, action_data->data_len - 2, action_data->puc_data + 2, /* 2 用于计算偏差 */
1307 action_data->data_len - 2) != EOK) { /* 2 用于计算偏差 */
1308 oam_error_log0(0, OAM_SF_CFG, "hmac_encap_mesh_peering_close_frame:: puc_data memcpy_s fail.");
1309 return HI_FAIL;
1310 }
1311 puc_data += action_data->data_len - 2; /* 2 用于计算偏差 */
1312 }
1313
1314 us_frame_len = (hi_u32)(puc_data - puc_frame_origin);
1315
1316 return us_frame_len;
1317 }
1318
1319 /* ****************************************************************************
1320 功能描述 : 封装MESH_GROUP_KEY_INFORM帧
1321 输入参数 : 1. vap指针2.hi_u8 *puc_data 3.hisi_action_data_stru *st_action_data
1322 返 回 值 : 帧长度
1323 1.日 期 : 2019年6月14日
1324 作 者 : HiSilicon
1325 修改内容 : 新生成函数
1326 **************************************************************************** */
hmac_encap_mesh_group_key_inform_frame(const mac_vap_stru * mac_vap,hi_u8 * puc_data,const mac_action_data_stru * action_data)1327 hi_u32 hmac_encap_mesh_group_key_inform_frame(const mac_vap_stru *mac_vap, hi_u8 *puc_data,
1328 const mac_action_data_stru *action_data)
1329 {
1330 hi_u8 *puc_frame_origin = HI_NULL;
1331 hi_u32 us_frame_len;
1332
1333 /* 保存起始地址,便于计算长度 */
1334 puc_frame_origin = puc_data;
1335
1336 if (mac_vap->mib_info == HI_NULL) {
1337 return HI_ERR_CODE_PTR_NULL;
1338 }
1339
1340 /* *********************************************************************** */
1341 /* Management Frame Format */
1342 /* -------------------------------------------------------------------- */
1343 /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS| */
1344 /* -------------------------------------------------------------------- */
1345 /* | 2 |2 |6 |6 |6 |2 |0 - 2312 |4 | */
1346 /* -------------------------------------------------------------------- */
1347 /* */
1348 /* *********************************************************************** */
1349 /* *********************************************************************** */
1350 /* Set the fields in the frame header */
1351 /* *********************************************************************** */
1352 /* 设置 Frame Control field */
1353 mac_hdr_set_frame_control(puc_data, WLAN_FC0_SUBTYPE_ACTION);
1354
1355 /* 设置 DA address1: STA MAC地址 */
1356 if (memcpy_s(puc_data + WLAN_HDR_ADDR1_OFFSET, WLAN_MAC_ADDR_LEN,
1357 action_data->puc_dst, WLAN_MAC_ADDR_LEN) != EOK) {
1358 oam_error_log0(0, 0, "{hmac_encap_mesh_group_key_inform_frame::memcpy_s fail.}");
1359 return 0;
1360 }
1361 /* 设置 SA address2: dot11MACAddress */
1362 if (memcpy_s(puc_data + WLAN_HDR_ADDR2_OFFSET, WLAN_MAC_ADDR_LEN,
1363 mac_vap->mib_info->wlan_mib_sta_config.auc_dot11_station_id, WLAN_MAC_ADDR_LEN) != EOK) {
1364 oam_error_log0(0, 0, "{hmac_encap_mesh_group_key_inform_frame::memcpy_s fail.}");
1365 return 0;
1366 }
1367 /* 设置 DA address3::BSSID */
1368 if (memcpy_s(puc_data + WLAN_HDR_ADDR3_OFFSET, WLAN_MAC_ADDR_LEN, action_data->puc_bssid, WLAN_MAC_ADDR_LEN) !=
1369 EOK) {
1370 oam_error_log0(0, 0, "{hmac_encap_mesh_group_key_inform_frame::memcpy_s fail.}");
1371 return 0;
1372 }
1373 puc_data += MAC_80211_FRAME_LEN;
1374 /* *********************************************************************** */
1375 /* Set the contents of the frame body */
1376 /* *********************************************************************** */
1377 /* *********************************************************************** */
1378 /* Mesh GROUP KEY INFORM Frame - Frame Body */
1379 /* --------------------------------------------------------------------- */
1380 /* |Category|action code | MIC Element |Authenticated Mesh Peering Exchange */
1381 /* --------------------------------------------------------------------- */
1382 /* --------------------------------------------------------------------- */
1383 /* *********************************************************************** */
1384 /* 设置Category 和Action Code */
1385 *puc_data = MAC_ACTION_CATEGORY_SELF_PROTECTED;
1386 *(puc_data + 1) = MAC_SP_ACTION_MESH_GROUP_KEY_INFORM;
1387 puc_data += 2; /* 自增2 */
1388
1389 /* 填充WPS信息 */
1390 if (action_data->data_len > 0) {
1391 if (memcpy_s(puc_data, action_data->data_len - 2, action_data->puc_data + 2, /* 2 用于计算偏差 */
1392 action_data->data_len - 2) != EOK) { /* 2 用于计算偏差 */
1393 oam_error_log0(0, OAM_SF_CFG, "hmac_encap_mesh_group_key_inform_frame:: puc_data memcpy_s fail.");
1394 return HI_FAIL;
1395 }
1396 puc_data += action_data->data_len - 2; /* 2 用于计算偏差 */
1397 }
1398
1399 us_frame_len = (hi_u32)(puc_data - puc_frame_origin);
1400
1401 return us_frame_len;
1402 }
1403
1404 /* ****************************************************************************
1405 功能描述 : 封装MESH_GROUP_KEY_ACK帧
1406 输入参数 : 1. vap指针2.hi_u8 *puc_data 3.hisi_action_data_stru *st_action_data
1407 返 回 值 : 帧长度
1408 1.日 期 : 2019年6月14日
1409 作 者 : HiSilicon
1410 修改内容 : 新生成函数
1411 **************************************************************************** */
hmac_encap_mesh_group_key_ack_frame(const mac_vap_stru * mac_vap,hi_u8 * puc_data,const mac_action_data_stru * action_data)1412 hi_u32 hmac_encap_mesh_group_key_ack_frame(const mac_vap_stru *mac_vap, hi_u8 *puc_data,
1413 const mac_action_data_stru *action_data)
1414 {
1415 hi_u8 *puc_frame_origin = HI_NULL;
1416 hi_u32 us_frame_len;
1417
1418 /* 保存起始地址,便于计算长度 */
1419 puc_frame_origin = puc_data;
1420
1421 if (mac_vap->mib_info == HI_NULL) {
1422 return HI_ERR_CODE_PTR_NULL;
1423 }
1424 /* *********************************************************************** */
1425 /* Management Frame Format */
1426 /* -------------------------------------------------------------------- */
1427 /* |Frame Control|Duration|DA|SA|BSSID|Sequence Control|Frame Body|FCS| */
1428 /* -------------------------------------------------------------------- */
1429 /* | 2 |2 |6 |6 |6 |2 |0 - 2312 |4 | */
1430 /* -------------------------------------------------------------------- */
1431 /* */
1432 /* *********************************************************************** */
1433 /* *********************************************************************** */
1434 /* Set the fields in the frame header */
1435 /* *********************************************************************** */
1436 /* 设置 Frame Control field */
1437 mac_hdr_set_frame_control(puc_data, WLAN_FC0_SUBTYPE_ACTION);
1438
1439 /* 设置 DA address1: STA MAC地址 */
1440 if (memcpy_s(puc_data + WLAN_HDR_ADDR1_OFFSET, WLAN_MAC_ADDR_LEN,
1441 action_data->puc_dst, WLAN_MAC_ADDR_LEN) != EOK) {
1442 oam_error_log0(0, 0, "{hmac_encap_mesh_group_key_ack_frame::memcpy_s fail.}");
1443 return 0;
1444 }
1445 /* 设置 SA address2: dot11MACAddress */
1446 if (memcpy_s(puc_data + WLAN_HDR_ADDR2_OFFSET, WLAN_MAC_ADDR_LEN,
1447 mac_vap->mib_info->wlan_mib_sta_config.auc_dot11_station_id, WLAN_MAC_ADDR_LEN) != EOK) {
1448 oam_error_log0(0, 0, "{hmac_encap_mesh_group_key_ack_frame::memcpy_s fail.}");
1449 return 0;
1450 }
1451 /* 设置 DA address3::BSSID */
1452 if (memcpy_s(puc_data + WLAN_HDR_ADDR3_OFFSET, WLAN_MAC_ADDR_LEN, action_data->puc_bssid, WLAN_MAC_ADDR_LEN) !=
1453 EOK) {
1454 oam_error_log0(0, 0, "{hmac_encap_mesh_group_key_ack_frame::memcpy_s fail.}");
1455 return 0;
1456 }
1457 puc_data += MAC_80211_FRAME_LEN;
1458 /* ************************************************************************** */
1459 /* Set the contents of the frame body */
1460 /* ************************************************************************** */
1461 /* ************************************************************************** */
1462 /* Mesh GROUP KEY ACK Frame - Frame Body */
1463 /* --------------------------------------------------------------------- */
1464 /* |Category|action code | MIC Element |Authenticated Mesh Peering Exchange */
1465 /* --------------------------------------------------------------------- */
1466 /* --------------------------------------------------------------------- */
1467 /* ************************************************************************** */
1468 /* 设置Category 和Action Code */
1469 *puc_data = MAC_ACTION_CATEGORY_SELF_PROTECTED;
1470 *(puc_data + 1) = MAC_SP_ACTION_MESH_GROUP_KEY_ACK;
1471 puc_data += 2; /* 自增2 */
1472
1473 /* 填充WPS信息 */
1474 if (action_data->data_len > 0) {
1475 if (memcpy_s(puc_data, action_data->data_len - 2, action_data->puc_data + 2, /* 2 用于计算偏差 */
1476 action_data->data_len - 2) != EOK) { /* 2 用于计算偏差 */
1477 oam_error_log0(0, OAM_SF_CFG, "hmac_encap_mesh_group_key_ack_frame:: puc_data memcpy_s fail.");
1478 return HI_FAIL;
1479 }
1480 puc_data += action_data->data_len - 2; /* 2 用于计算偏差 */
1481 }
1482
1483 us_frame_len = (hi_u32)(puc_data - puc_frame_origin);
1484
1485 return us_frame_len;
1486 }
1487 #endif
1488 #ifdef __cplusplus
1489 #if __cplusplus
1490 }
1491 #endif
1492 #endif
1493