1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 文 件 名 : hmac_blockack.h
15 生成日期 : 2013年4月8日
16 功能描述 : hmac_blockack.c 的头文件
17 */
18
19 #ifndef HMAC_BLOCKACK_H
20 #define HMAC_BLOCKACK_H
21
22 /*****************************************************************************
23 1 其他头文件包含
24 *****************************************************************************/
25 #include "hmac_user.h"
26 #include "hmac_main.h"
27 #include "hmac_rx_data.h"
28 #include "hmac_vap.h"
29 #include "hmac_tx_mgmt.h"
30
31 #ifdef __cplusplus
32 #if __cplusplus
33 extern "C" {
34 #endif
35 #endif
36
37
38 #undef THIS_FILE_ID
39 #define THIS_FILE_ID OAM_FILE_ID_HMAC_BLOCKACK_H
40
41 /*****************************************************************************
42 2 宏定义
43 *****************************************************************************/
44
45 #define HMAC_TX_BUF_BITMAP_LOG2_WORD_SIZE 5 /* log2(32) == 5 */
46 /* 发送BA窗口记录seq number的bitmap所使用的类型长度 */
47 #define HMAC_TX_BUF_BITMAP_WORD_SIZE 32
48
49 #define HMAC_TX_BUF_BITMAP_WORD_MASK (HMAC_TX_BUF_BITMAP_WORD_SIZE - 1)
50
51 /* 重排序队列保留bitmap用于缓存乱序帧 */
52 #define HMAC_BA_BMP_SIZE 64
53
54 /* 判断index为n 在bitmap中的bit位是否是1 */
55 #define hmac_ba_bit_isset(_bm, _n) (((_n) < (HMAC_BA_BMP_SIZE)) && \
56 (((_bm)[(_n) >> 5] & (1 << ((_n) & 31))) != 0))
57
58 /* 判断一个seq num是否在发送窗口内 */
59 #define hmac_baw_within(_start, _bawsz, _seqno) \
60 ((((osal_u32)((_seqno) - (_start))) & 4095) < (_bawsz))
61
62 /* Default values for receive timeout */
63 #define HMAC_BA_RX_VO_TIMEOUT 40 /* 40 milliseconds */
64 #define HMAC_BA_RX_VI_TIMEOUT 100 /* 100 milliseconds */
65 #define HMAC_BA_RX_BE_TIMEOUT 60 /* 100 milliseconds */
66 #define HMAC_BA_RX_BK_TIMEOUT 100 /* 100 milliseconds */
67
68 #define HMAC_BA_SEQNO_MASK 0x0FFF /* max sequece number */
69 #define hmac_ba_seqno_sub(_seq1, _seq2) ((osal_u32)((_seq1) - (_seq2)) & HMAC_BA_SEQNO_MASK)
70 #define hmac_ba_seqno_add(_seq1, _seq2) ((osal_u32)((_seq1) + (_seq2)) & HMAC_BA_SEQNO_MASK)
71
72 #define WLAN_RX_RESET_BA_THREHOLD 32 /* BA会话未建立收到一定聚合帧发送DELBA */
73
74 /*****************************************************************************
75 3 枚举定义
76 *****************************************************************************/
77
78
79 /*****************************************************************************
80 4 全局变量声明
81 *****************************************************************************/
82
83 /*****************************************************************************
84 5 消息头定义
85 *****************************************************************************/
86
87
88 /*****************************************************************************
89 6 消息定义
90 *****************************************************************************/
91
92
93 /*****************************************************************************
94 7 STRUCT定义
95 *****************************************************************************/
96
97 /*****************************************************************************
98 8 UNION定义
99 *****************************************************************************/
100
101
102 /*****************************************************************************
103 9 OTHERS定义
104 *****************************************************************************/
105
106
107 /*****************************************************************************
108 10 inline函数定义
109 *****************************************************************************/
110 /*****************************************************************************
111 函 数 名 : hmac_ba_rx_seqno_lt
112 功能描述 : 判断seq1是否小于seq2
113 输入参数 : 无
114 输出参数 : 无
115 *****************************************************************************/
hmac_ba_rx_seqno_lt(osal_u16 seq1,osal_u16 seq2)116 OAL_STATIC OAL_INLINE oal_bool_enum_uint8 hmac_ba_rx_seqno_lt(osal_u16 seq1, osal_u16 seq2)
117 {
118 if (((seq1 < seq2) && ((seq2 - seq1) < HMAC_BA_MAX_SEQNO_BY_TWO)) ||
119 ((seq1 > seq2) && ((seq1 - seq2) > HMAC_BA_MAX_SEQNO_BY_TWO))) {
120 return OAL_TRUE;
121 }
122
123 return OAL_FALSE;
124 }
125
126 /*****************************************************************************
127 函 数 名 : hmac_ba_rx_seqno_gt
128 功能描述 : 判断seq1是否大于seq2
129 输入参数 : 无
130 输出参数 : 无
131 *****************************************************************************/
hmac_ba_rx_seqno_gt(osal_u16 seq1,osal_u16 seq2)132 OAL_STATIC OAL_INLINE oal_bool_enum_uint8 hmac_ba_rx_seqno_gt(osal_u16 seq1, osal_u16 seq2)
133 {
134 return hmac_ba_rx_seqno_lt(seq2, seq1);
135 }
136
137 /*****************************************************************************
138 函 数 名 : hmac_ba_seqno_lt
139 功能描述 : 判断seq1是否小于seq2
140 输入参数 : 无
141 输出参数 : 无
142 *****************************************************************************/
hmac_ba_seqno_lt(osal_u16 seq1,osal_u16 seq2)143 OAL_STATIC OAL_INLINE oal_bool_enum_uint8 hmac_ba_seqno_lt(osal_u16 seq1, osal_u16 seq2)
144 {
145 if (((seq1 < seq2) && ((seq2 - seq1) < HMAC_BA_MAX_SEQNO_BY_TWO)) ||
146 ((seq1 > seq2) && ((seq1 - seq2) > HMAC_BA_MAX_SEQNO_BY_TWO))) {
147 return OAL_TRUE;
148 }
149
150 return OAL_FALSE;
151 }
152
153 /*****************************************************************************
154 函 数 名 : hmac_ba_seqno_gt
155 输入参数 : 无
156 输出参数 : 无
157 *****************************************************************************/
hmac_ba_seqno_gt(osal_u16 seq1,osal_u16 seq2)158 OAL_STATIC OAL_INLINE oal_bool_enum_uint8 hmac_ba_seqno_gt(osal_u16 seq1, osal_u16 seq2)
159 {
160 return hmac_ba_seqno_lt(seq2, seq1);
161 }
162
163 /*****************************************************************************
164 函 数 名 : hmac_ba_rx_seqno_leq
165 功能描述 : 判断seq1是否小于或等于seq2
166 输入参数 : 无
167 输出参数 : 无
168 *****************************************************************************/
hmac_ba_rx_seqno_leq(osal_u16 seq1,osal_u16 seq2)169 OAL_STATIC OAL_INLINE oal_bool_enum_uint8 hmac_ba_rx_seqno_leq(osal_u16 seq1, osal_u16 seq2)
170 {
171 if (((seq1 <= seq2) && ((seq2 - seq1) < HMAC_BA_MAX_SEQNO_BY_TWO)) ||
172 ((seq1 > seq2) && ((seq1 - seq2) > HMAC_BA_MAX_SEQNO_BY_TWO))) {
173 return OAL_TRUE;
174 }
175
176 return OAL_FALSE;
177 }
178
179 /*****************************************************************************
180 函 数 名 : hmac_ba_rx_seqno_geq
181 功能描述 : 判断seq1是否大于或等于seq2
182 输入参数 : 无
183 输出参数 : 无
184 *****************************************************************************/
hmac_ba_rx_seqno_geq(osal_u16 seq1,osal_u16 seq2)185 OAL_STATIC OAL_INLINE oal_bool_enum_uint8 hmac_ba_rx_seqno_geq(osal_u16 seq1, osal_u16 seq2)
186 {
187 return hmac_ba_rx_seqno_leq(seq2, seq1);
188 }
189
190 /*****************************************************************************
191 函 数 名 : hmac_ba_isset
192 输入参数 : 无
193 输出参数 : 无
194 *****************************************************************************/
hmac_ba_isset(hmac_ba_rx_stru * ba_rx_hdl,osal_u16 seqno)195 OAL_STATIC OAL_INLINE oal_bool_enum_uint8 hmac_ba_isset(hmac_ba_rx_stru *ba_rx_hdl, osal_u16 seqno)
196 {
197 osal_u16 us_index;
198
199 if (hmac_baw_within(ba_rx_hdl->baw_head, HMAC_BA_BMP_SIZE, seqno) == OSAL_TRUE) {
200 us_index = seqno & (HMAC_BA_BMP_SIZE - 1);
201
202 if (hmac_ba_bit_isset(ba_rx_hdl->rx_buf_bitmap, us_index) == OSAL_TRUE) {
203 return OAL_TRUE;
204 }
205 }
206
207 return OAL_FALSE;
208 }
209
210 /*****************************************************************************
211 函 数 名 : hmac_ba_addto_rx_bitmap
212 输入参数 : 无
213 输出参数 : 无
214 *****************************************************************************/
hmac_ba_addto_rx_bitmap(hmac_ba_rx_stru * ba_rx_hdl,osal_u16 seqno)215 OAL_STATIC OAL_INLINE osal_void hmac_ba_addto_rx_bitmap(hmac_ba_rx_stru *ba_rx_hdl, osal_u16 seqno)
216 {
217 osal_u16 us_index;
218
219 if (hmac_baw_within(ba_rx_hdl->baw_head, HMAC_BA_BMP_SIZE, seqno) == OSAL_TRUE) {
220 us_index = seqno & (HMAC_BA_BMP_SIZE - 1);
221 ba_rx_hdl->rx_buf_bitmap[us_index >> HMAC_TX_BUF_BITMAP_LOG2_WORD_SIZE] |=
222 (1 << (us_index & HMAC_TX_BUF_BITMAP_WORD_MASK));
223 }
224 }
225
226 /*****************************************************************************
227 函 数 名 : hmac_ba_clear_rx_bitmap
228 输入参数 : 无
229 输出参数 : 无
230 *****************************************************************************/
hmac_ba_clear_rx_bitmap(hmac_ba_rx_stru * ba_rx_hdl)231 OAL_STATIC OAL_INLINE osal_void hmac_ba_clear_rx_bitmap(hmac_ba_rx_stru *ba_rx_hdl)
232 {
233 osal_u16 us_index;
234
235 us_index = ((osal_u16)hmac_ba_seqno_sub(ba_rx_hdl->baw_head, 1)) & (osal_u16)(HMAC_BA_BMP_SIZE - 1);
236 ba_rx_hdl->rx_buf_bitmap[us_index >> HMAC_TX_BUF_BITMAP_LOG2_WORD_SIZE] &=
237 ~((osal_u32)(1 << (us_index & HMAC_TX_BUF_BITMAP_WORD_MASK)));
238 }
239
240 /*****************************************************************************
241 函 数 名 : hmac_ba_update_rx_bitmap
242 输入参数 : 无
243 输出参数 : 无
244 *****************************************************************************/
hmac_ba_update_rx_bitmap(hmac_user_stru * hmac_user,mac_ieee80211_frame_stru * frame_hdr)245 OAL_STATIC OAL_INLINE osal_void hmac_ba_update_rx_bitmap(hmac_user_stru *hmac_user,
246 mac_ieee80211_frame_stru *frame_hdr)
247 {
248 oal_bool_enum_uint8 is_4addr;
249 osal_u8 is_tods;
250 osal_u8 is_from_ds;
251 osal_u8 tid;
252 hmac_ba_rx_stru *ba_rx_hdl;
253
254 /* 考虑四地址情况获取报文的tid */
255 is_tods = mac_hdr_get_to_ds((osal_u8 *)frame_hdr);
256 is_from_ds = mac_hdr_get_from_ds((osal_u8 *)frame_hdr);
257 is_4addr = (is_tods != OSAL_FALSE) && (is_from_ds != OSAL_FALSE);
258 tid = mac_get_tid_value((osal_u8 *)frame_hdr, is_4addr);
259
260 ba_rx_hdl = hmac_user->tx_tid_queue[tid].ba_rx_info;
261 if (ba_rx_hdl == OAL_PTR_NULL) {
262 return;
263 }
264 if (ba_rx_hdl->ba_status != HMAC_BA_COMPLETE) {
265 return;
266 }
267
268 osal_spin_lock(&ba_rx_hdl->ba_lock);
269
270 while (hmac_ba_seqno_lt(ba_rx_hdl->baw_head,
271 (osal_u16)hmac_ba_seqno_sub(ba_rx_hdl->baw_start, (HMAC_BA_BMP_SIZE - 1))) == OAL_TRUE) {
272 ba_rx_hdl->baw_head = (osal_u16)hmac_ba_seqno_add(ba_rx_hdl->baw_head, 1);
273 hmac_ba_clear_rx_bitmap(ba_rx_hdl);
274 }
275
276 hmac_ba_addto_rx_bitmap(ba_rx_hdl, mac_get_seq_num((osal_u8 *)frame_hdr));
277 osal_spin_unlock(&ba_rx_hdl->ba_lock);
278
279 return;
280 }
281
282 /*****************************************************************************
283 函 数 名 : hmac_ba_seqno_bound_chk
284 功能描述 : This function compares the given sequence number with the specified
285 upper and lower bounds and returns its position relative to them.
286 输入参数 : 无
287 输出参数 : 无
288 *****************************************************************************/
hmac_ba_seqno_bound_chk(osal_u16 seq_lo,osal_u16 seq_hi,osal_u16 seq)289 OAL_STATIC OAL_INLINE osal_u8 hmac_ba_seqno_bound_chk(osal_u16 seq_lo, osal_u16 seq_hi, osal_u16 seq)
290 {
291 oal_bool_enum_uint8 lo_chk;
292 oal_bool_enum_uint8 hi_chk;
293 osal_u8 chk_res = 0;
294
295 lo_chk = hmac_ba_rx_seqno_leq(seq_lo, seq);
296 hi_chk = hmac_ba_rx_seqno_leq(seq, seq_hi);
297 if ((lo_chk == OSAL_TRUE) && (hi_chk == OSAL_TRUE)) {
298 chk_res = HMAC_BA_BETWEEN_SEQLO_SEQHI;
299 } else if (hi_chk == OSAL_FALSE) {
300 chk_res = HMAC_BA_GREATER_THAN_SEQHI;
301 }
302
303 return chk_res;
304 }
305
306 /* This function reads out the TX-Dscr indexed by the specified sequence number in */
307 /* the Retry-Q Ring-Buffer. */
308 /*****************************************************************************
309 函 数 名 : hmac_remove_frame_from_reorder_q
310 功能描述 :This function reads out the TX-Dscr indexed by the specified sequence number in
311 the Retry-Q Ring-Buffer.
312 输入参数 : 无
313 输出参数 : 无
314 *****************************************************************************/
hmac_remove_frame_from_reorder_q(hmac_ba_rx_stru * ba_rx_hdl,osal_u16 seq_num)315 OAL_STATIC OAL_INLINE hmac_rx_buf_stru *hmac_remove_frame_from_reorder_q(hmac_ba_rx_stru *ba_rx_hdl,
316 osal_u16 seq_num)
317 {
318 osal_u16 idx;
319 hmac_rx_buf_stru *rx_buff;
320
321 idx = (seq_num & (WLAN_AMPDU_RX_BUFFER_SIZE - 1));
322
323 rx_buff = &(ba_rx_hdl->re_order_list[idx]);
324
325 osal_spin_lock(&ba_rx_hdl->ba_lock);
326
327 if ((rx_buff->in_use == 0) || (rx_buff->seq_num != seq_num)) {
328 osal_spin_unlock(&ba_rx_hdl->ba_lock);
329 return OAL_PTR_NULL;
330 }
331
332 rx_buff->in_use = 0;
333
334 osal_spin_unlock(&ba_rx_hdl->ba_lock);
335
336 return rx_buff;
337 }
338
339 /*****************************************************************************
340 函 数 名 : hmac_get_frame_from_reorder_q
341 功能描述 :This function reads out the TX-Dscr indexed by the specified sequence number in
342 the Retry-Q Ring-Buffer.
343 输入参数 : 无
344 输出参数 : 无
345 *****************************************************************************/
hmac_get_frame_from_reorder_q(hmac_ba_rx_stru * ba_rx_hdl,osal_u16 seq_num)346 OAL_STATIC OAL_INLINE hmac_rx_buf_stru *hmac_get_frame_from_reorder_q(hmac_ba_rx_stru *ba_rx_hdl,
347 osal_u16 seq_num)
348 {
349 osal_u16 idx;
350 hmac_rx_buf_stru *rx_buff;
351
352 idx = (seq_num & (WLAN_AMPDU_RX_BUFFER_SIZE - 1));
353
354 rx_buff = &(ba_rx_hdl->re_order_list[idx]);
355
356 if ((rx_buff->in_use == 0) || (rx_buff->seq_num != seq_num)) {
357 return OAL_PTR_NULL;
358 }
359
360 return rx_buff;
361 }
362
363
hmac_ba_get_lut_index(osal_u8 * ba_lut_index_table,osal_u16 start,osal_u16 stop)364 OAL_STATIC OAL_INLINE osal_u8 hmac_ba_get_lut_index(osal_u8 *ba_lut_index_table, osal_u16 start,
365 osal_u16 stop)
366 {
367 return oal_get_lut_index(ba_lut_index_table, MAC_RX_BA_LUT_BMAP_LEN, HAL_MAX_RX_BA_LUT_SIZE, start, stop);
368 }
369
hmac_ba_del_lut_index(osal_u8 * ba_lut_index_table,osal_u8 lut_index)370 OAL_STATIC OAL_INLINE osal_void hmac_ba_del_lut_index(osal_u8 *ba_lut_index_table, osal_u8 lut_index)
371 {
372 oal_del_lut_index(ba_lut_index_table, lut_index);
373 }
374
375 /*****************************************************************************
376 10 函数声明
377 *****************************************************************************/
378 extern osal_u32 hmac_ba_filter_serv_etc(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
379 mac_rx_ctl_stru *cb_ctrl, oal_netbuf_head_stru *netbuf_header, oal_bool_enum_uint8 *is_ba_buf);
380
381
382 extern osal_u32 hmac_ba_timeout_fn_etc(osal_void *p_arg);
383
384 extern osal_u8 hmac_mgmt_check_set_rx_ba_ok_etc(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user,
385 hmac_ba_rx_stru *ba_rx_info, hmac_device_stru *hmac_device, hmac_tid_stru *tid_info);
386
387 extern osal_void hmac_reorder_ba_rx_buffer_bar_etc(hmac_ba_rx_stru *rx_ba, osal_u16 start_seq_num,
388 hmac_vap_stru *hmac_vap);
389 extern osal_u32 hmac_ba_reset_rx_handle_etc(hmac_device_stru *hmac_device, hmac_user_stru *hmac_user,
390 osal_u8 tid, oal_bool_enum_uint8 is_aging);
391 extern osal_void hmac_up_rx_bar_etc(hmac_vap_stru *hmac_vap, dmac_rx_ctl_stru *rx_ctl,
392 oal_netbuf_stru *netbuf);
393
394 osal_u32 hmac_ba_filter_serv(hmac_vap_stru *hmac_vap, hmac_user_stru *hmac_user, const dmac_rx_ctl_stru *cb_ctrl,
395 const mac_ieee80211_frame_stru *frame_hdr, hmac_ba_rx_stru **ba_rx_hdl);
396 osal_u32 hmac_ba_check_rx_aggr(const hmac_vap_stru *hmac_vap, const mac_ieee80211_frame_stru *frame_hdr);
397 osal_void hmac_ba_reset_tx_handle(hmac_vap_stru *hmac_vap, osal_u16 user_id, osal_u8 tid);
398 osal_void hmac_clear_tx_qos_seq_num(const hmac_user_stru *hmac_user);
399 osal_void hmac_clear_tx_nonqos_seq_num(const hmac_vap_stru *hmac_vap);
400 #ifdef _PRE_WLAN_FEATURE_AMPDU_TX_HW
401 osal_u32 hmac_ba_tx_ampdu_switch(const hmac_vap_stru *hmac_vap, const mac_cfg_ampdu_tx_on_param_stru *ampdu_tx_on);
402 #endif
403
404 #ifdef __cplusplus
405 #if __cplusplus
406 }
407 #endif
408 #endif
409
410 #endif /* end of hmac_blockack.h */
411