• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #ifndef __HMAC_USER_H__
20 #define __HMAC_USER_H__
21 
22 /* ****************************************************************************
23   1 其他头文件包含
24 **************************************************************************** */
25 #include "mac_user.h"
26 #include "mac_resource.h"
27 #include "dmac_ext_if.h"
28 
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif
33 #endif
34 
35 /* ****************************************************************************
36   2 宏定义
37 **************************************************************************** */
38 #define HMAC_ADDBA_EXCHANGE_ATTEMPTS 10 /* 试图建立ADDBA会话的最大允许次数 */
39 
40 #define hmac_user_is_amsdu_support(_user, _tid)         (((_user)->amsdu_supported) & (0x01 << ((_tid) & 0x07)))
41 #define hmac_user_set_amsdu_support(_user, _tid)        (((_user)->amsdu_supported) |= (0x01 << ((_tid) & 0x07)))
42 #define hmac_user_set_amsdu_not_support(_user, _tid)    (((_user)->amsdu_supported) &= \
43     (hi_u8)(~(0x01 << ((_tid) & 0x07))))
44 
45 #ifdef _PRE_WLAN_FEATURE_TX_CLASSIFY_LAN_TO_WLAN
46 #define MAX_JUDGE_CACHE_LENGTH 20 /* 业务识别-用户待识别队列长度 */
47 #define MAX_CONFIRMED_FLOW_NUM 2  /* 业务识别-用户已识别业务总数 */
48 #endif
49 
50 #define hmac_user_stats_pkt_incr(_member, _cnt) ((_member) += (_cnt))
51 
52 /* ****************************************************************************
53   3 枚举定义
54 **************************************************************************** */
55 typedef enum {
56     WLAN_TX_TCP_DATA = 0, /* 发送TCP data */
57     WLAN_RX_TCP_DATA = 1, /* 接收TCP data */
58     WLAN_TX_UDP_DATA = 2, /* 发送UDP data */
59     WLAN_RX_UDP_DATA = 3, /* 接收UDP data */
60 
61     WLAN_TXRX_DATA_BUTT = 4,
62 } wlan_txrx_data_type_enum;
63 typedef hi_u8 wlan_txrx_data_enum_uint8;
64 /* ****************************************************************************
65   4 全局变量声明
66 **************************************************************************** */
67 /* ****************************************************************************
68   5 消息头定义
69 **************************************************************************** */
70 /* ****************************************************************************
71   6 消息定义
72 **************************************************************************** */
73 /* ****************************************************************************
74   7 STRUCT定义
75 **************************************************************************** */
76 typedef struct {
77     oal_netbuf_head_stru            msdu_head;         /* msdu链表头 */
78     frw_timeout_stru                amsdu_timer;
79     oal_spin_lock_stru              st_amsdu_lock;        /* amsdu task lock */
80     hi_u8                       last_pad_len;      /* 最后一个msdu的pad长度 */
81     hi_u8                       msdu_num     : 4;  /* Number of sub-MSDUs accumulated */
82     hi_u8                       amsdu_maxnum : 4;  /* 最大聚合个数 value = 12个 */
83     hi_u16                      us_amsdu_size;        /* Present size of the AMSDU */
84 
85     hi_u8                       auc_eth_da[WLAN_MAC_ADDR_LEN];
86     hi_u8                       auc_eth_sa[WLAN_MAC_ADDR_LEN];
87 } hmac_amsdu_stru;
88 /* TID对应的发送BA会话的状态 */
89 typedef struct {
90     dmac_ba_conn_status_enum_uint8  ba_status;       /* 该TID对应的BA会话的状态 */
91     hi_u8                       dialog_token;    /* 随机标记数 */
92     hi_u8                       uc_resv[2]; /* 2 保留字节 */
93     frw_timeout_stru                addba_timer;
94     dmac_ba_alarm_stru              alarm_data;
95 } hmac_ba_tx_stru;
96 
97 typedef struct {
98     hi_u8 in_use;                     /* 缓存BUF是否被使用 */
99     hi_u8 num_buf;                    /* MPDU占用的netbuf(接收描述符)个数 */
100     hi_u16 us_seq_num;                /* MPDU对应的序列号 */
101     oal_netbuf_head_stru netbuf_head; /* MPDU对应的描述符首地址 */
102     hi_u32 rx_time;                   /* 报文被缓存的时间戳 */
103 } hmac_rx_buf_stru;
104 
105 typedef struct {
106     hi_void                             *ba;
107     hi_u8                               tid;
108     hi_u8                               vap_id;
109     hi_u16                              us_timeout_times;
110 } hmac_ba_alarm_stru;
111 
112 /* Hmac侧接收侧BA会话句柄 */
113 typedef struct {
114     hi_u16 us_baw_start; /* 第一个未收到的MPDU的序列号 */
115     hi_u16 us_baw_end;   /* 最后一个可以接收的MPDU的序列号 */
116     hi_u16 us_baw_tail;  /* 目前Re-Order队列中,最大的序列号 */
117     hi_u16 us_baw_size;  /* Block_Ack会话的buffer size大小 */
118 
119     oal_spin_lock_stru st_ba_lock; /* 02用于hcc线程和事件线程并发 */
120 
121     hi_u8 timer_triggered;                    /* 上一次上报是否为定时器上报 */
122     hi_u8 is_ba;                              /* Session Valid Flag */
123     dmac_ba_conn_status_enum_uint8 ba_status; /* 该TID对应的BA会话的状态 */
124     hi_u8 mpdu_cnt;                           /* 当前Re-Order队列中,MPDU的数目 */
125 
126     hmac_rx_buf_stru                ast_re_order_list[WLAN_AMPDU_RX_BUFFER_SIZE];  /* Re-Order队列 */
127     hmac_ba_alarm_stru              alarm_data;
128     frw_timeout_stru                ba_timer;                /* 接收重排序缓冲超时 */
129 
130     /* 以下action帧相关 */
131     mac_back_variant_enum_uint8     back_var;        /* BA会话的变体 */
132     hi_u8                       dialog_token;        /* ADDBA交互帧的dialog token */
133     hi_u8                       ba_policy;           /* Immediate=1 Delayed=0 */
134     hi_u8                       lut_index;           /* 接收端Session H/w LUT Index */
135     hi_u16                      us_status_code;      /* 返回状态码 */
136     hi_u16                      us_ba_timeout;       /* BA会话交互超时时间 */
137     hi_u8                      *puc_transmit_addr;   /* BA会话发送端地址 */
138     hi_u8                       amsdu_supp;      /* BLOCK ACK支持AMSDU的标识 */
139     hi_u8                       auc_resv1[1];
140     hi_u16                      us_baw_head;         /* bitmap的起始序列号 */
141     hi_u32                      aul_rx_buf_bitmap[2]; /* 元素个数为2 */
142 } hmac_ba_rx_stru;
143 
144 /* user结构中,TID对应的BA信息的保存结构 */
145 typedef struct {
146     hi_u8               tid_no;
147     hi_u8               ampdu_start;            /* 标识该tid下的AMPDU是否已经被设置 */
148     hi_u8               tx_ba_attemps;
149     hi_u8               ba_flag;                /* 大于等于5时表示是否可以建立BA会话。用户初始化、删除BA会话时清零 */
150     hmac_ba_tx_stru        *ba_tx_info;
151     hmac_ba_rx_stru        *ba_rx_info;             /* 由于部分处理上移,这部分内存到LocalMem中申请 */
152 } hmac_tid_stru;
153 
154 typedef struct {
155     hi_u32  short_preamble          : 1,        /* 是否支持802.11b短前导码 0=不支持, 1=支持 */
156                 erp                 : 1,        /* AP保存STA能力使用,指示user是否有ERP能力, 0=不支持,1=支持 */
157                 short_slot_time     : 1,        /* 短时隙: 0=不支持, 1=支持 */
158                 ac2g                : 1,
159                 bit_resv            : 28;
160 } hmac_user_cap_info_stru;
161 
162 #ifdef _PRE_WLAN_FEATURE_WAPI
163 #define WAPI_KEY_LEN                    16
164 #define WAPI_PN_LEN                     16
165 #define HMAC_WAPI_MAX_KEYID             2
166 
167 typedef struct {
168     hi_u32 ulrx_mic_calc_fail; /* 由于参数错误导致mic计算错误 */
169     hi_u32 ultx_ucast_drop;    /* 由于协议没有完成,将帧drop掉 */
170     hi_u32 ultx_wai;
171     hi_u32 ultx_port_valid;      /* 协商完成的情况下,发送的帧个数 */
172     hi_u32 ulrx_port_valid;      /* 协商完成的情况下,接收的帧个数 */
173     hi_u32 ulrx_idx_err;         /* 接收idx错误错误 */
174     hi_u32 ulrx_netbuff_len_err; /* 接收netbuff长度错误 */
175     hi_u32 ulrx_idx_update_err;  /* 密钥更新错误 */
176     hi_u32 ulrx_key_en_err;      /* 密钥没有使能 */
177     hi_u32 ulrx_pn_odd_err;      /* PN奇偶校验出错 */
178     hi_u32 ulrx_pn_replay_err;   /* PN重放 */
179     hi_u32 ulrx_memalloc_err;    /* rx内存申请失败 */
180     hi_u32 ulrx_decrypt_ok;      /* 解密成功的次数 */
181 
182     hi_u32 ultx_memalloc_err;    /* 内存分配失败 */
183     hi_u32 ultx_mic_calc_fail;   /* 由于参数错误导致mic计算错误 */
184     hi_u32 ultx_encrypt_ok;      /* 加密成功的次数 */
185     hi_u8 aucrx_pn[WAPI_PN_LEN]; /* 问题发生时,记录接收方向帧的PN,此pn会随时被刷新 */
186 } hmac_wapi_debug;
187 
188 typedef struct {
189     hi_u8 auc_wpi_ek[WAPI_KEY_LEN];
190     hi_u8 auc_wpi_ck[WAPI_KEY_LEN];
191     hi_u8 auc_pn_rx[WAPI_PN_LEN];
192     hi_u8 auc_pn_tx[WAPI_PN_LEN];
193     hi_u8 key_en;
194     hi_u8 auc_rsv[3]; /* 3 保留字节 */
195 } hmac_wapi_key_stru;
196 
197 typedef struct tag_hmac_wapi_stru {
198     hi_u8 port_valid; /* wapi控制端口 */
199     hi_u8 keyidx;
200     hi_u8 keyupdate_flg; /* key更新标志 */
201     hi_u8 pn_inc;        /* pn步进值 */
202 
203     hmac_wapi_key_stru ast_wapi_key[HMAC_WAPI_MAX_KEYID]; /* keyed: 0~1 */
204 
205 #ifdef _PRE_WAPI_DEBUG
206     hmac_wapi_debug debug; /* 维侧 */
207 #endif
208 
209     hi_u8 (*wapi_filter_frame)(struct tag_hmac_wapi_stru *pst_wapi, oal_netbuf_stru *pst_netbuff);
210     hi_u8 (*wapi_is_pn_odd)(const hi_u8 *puc_pn); /* 判断pn是否为奇数 */
211     hi_u32 (*wapi_decrypt)(struct tag_hmac_wapi_stru *pst_wapi, oal_netbuf_stru *pst_netbuff);
212     hi_u32 (*wapi_encrypt)(struct tag_hmac_wapi_stru *pst_wapi, oal_netbuf_stru *pst_netbuf);
213     oal_netbuf_stru *(*wapi_netbuff_txhandle)(struct tag_hmac_wapi_stru *pst_wapi, oal_netbuf_stru *pst_netbuf);
214     oal_netbuf_stru *(*wapi_netbuff_rxhandle)(struct tag_hmac_wapi_stru *pst_wapi, oal_netbuf_stru *pst_netbuf);
215 } hmac_wapi_stru;
216 
217 #endif
218 
219 #ifdef _PRE_WLAN_FEATURE_TX_CLASSIFY_LAN_TO_WLAN
220 /* 业务识别-五元组结构体: 用于唯一地标识业务流 */
221 typedef struct {
222     hi_u32 sip; /* ip */
223     hi_u32 dip;
224 
225     hi_u16 us_sport; /* 端口 */
226     hi_u16 us_dport;
227 
228     hi_u32 proto; /* 协议 */
229 } hmac_tx_flow_info_stru;
230 
231 /* 业务识别-待识别队列结构体: */
232 typedef struct {
233     hmac_tx_flow_info_stru flow_info;
234 
235     hi_u32 len; /* 来包长度 */
236     hi_u8  flag; /* 有效位,用于计数 */
237 
238     hi_u8  udp_flag; /* udp flag为1即为UDP帧 */
239     hi_u8  tcp_flag; /* tcp flag为1即为TCP帧 */
240 
241     hi_u8  rtpver;        /* RTP version */
242     hi_u32 rtpssrc;      /* RTP SSRC */
243     hi_u32 payload_type; /* RTP:标记1bit、有效载荷类型(PT)7bit */
244 } hmac_tx_judge_info_stru;
245 
246 /* 业务识别-待识别队列主要业务结构体: */
247 typedef struct {
248     hmac_tx_flow_info_stru flow_info;
249 
250     hi_u32 average_len; /* 业务来包平均长度 */
251     hi_u8  flag;         /* 有效位 */
252 
253     hi_u8  udp_flag; /* udp flag为1即为UDP帧 */
254     hi_u8  tcp_flag; /* tcp flag为1即为TCP帧 */
255 
256     hi_u8  rtpver;        /* RTP version */
257     hi_u32 rtpssrc;      /* RTP SSRC */
258     hi_u32 payload_type; /* 标记1bit、有效载荷类型(PT)7bit */
259 
260     hi_u32 wait_check_num; /* 待检测列表中此业务包个数 */
261 } hmac_tx_major_flow_stru;
262 
263 /* 业务识别-用户已识别结构体: */
264 typedef struct {
265     hmac_tx_flow_info_stru cfm_flow_info; /* 已识别业务的五元组信息 */
266 
267     hi_u32 last_jiffies; /* 记录已识别业务的最新来包时间 */
268     hi_u16 us_cfm_tid;   /* 已识别业务tid */
269 
270     hi_u16 us_cfm_flag; /* 有效位 */
271 } hmac_tx_cfm_flow_stru;
272 
273 /* 业务识别-用户待识别业务队列: */
274 typedef struct {
275     hi_u32 jiffies_st; /* 记录待识别业务队列的起始时间与最新来包时间 */
276     hi_u32 jiffies_end;
277     hi_u32 to_judge_num; /* 用户待识别业务队列长度 */
278 
279     hmac_tx_judge_info_stru ast_judge_cache[MAX_JUDGE_CACHE_LENGTH]; /* 待识别流队列 */
280 } hmac_tx_judge_list_stru;
281 #endif
282 
283 typedef struct {
284     hi_u8                       amsdu_supported;             /* 每个位代表某个TID是否支持AMSDU */
285     mac_user_stats_flag_stru    user_stats_flag;             /* 1byte 当user是sta时候,指示user是否被统计到对应项 */
286     hi_u16                      us_amsdu_maxsize;            /* amsdu最大长度 */
287 
288     hmac_amsdu_stru            *past_hmac_amsdu[WLAN_WME_MAX_TID_NUM];     /* amsdu指针数组 */
289     hmac_tid_stru               ast_tid_info[WLAN_TID_MAX_NUM];            /* 保存与TID相关的信息 */
290     hi_u8                      *ch_text;                                  /* WEP用的挑战明文 */
291     frw_timeout_stru            mgmt_timer;                              /* 认证关联用定时器 */
292     frw_timeout_stru            defrag_timer;                            /* 去分片超时定时器 */
293     oal_netbuf_stru            *defrag_netbuf;
294 #ifdef _PRE_WLAN_FEATURE_PMF
295     mac_sa_query_stru           sa_query_info;                      /* sa query流程的控制信息 */
296 #endif
297     mac_rate_stru               op_rates;                           /* user可选速率 AP侧保存STA速率;STA侧保存AP速率 */
298     hmac_user_cap_info_stru     hmac_cap_info;                      /* hmac侧用户能力标志位 */
299     hi_u32                      assoc_req_ie_len;
300     hi_u8                      *puc_assoc_req_ie_buff;
301 
302 #ifdef _PRE_WLAN_FEATURE_EDCA_OPT_AP
303     /* 发送/接收 tcp/udp be,bk,vi,vo报文 计数到HMAC_EDCA_OPT_PKT_NUM u16足够 */
304     hi_u16                      txrx_data_stat[WLAN_WME_AC_BUTT][WLAN_TXRX_DATA_BUTT];
305 #endif
306 #ifdef _PRE_WLAN_FEATURE_WAPI
307     hmac_wapi_stru              wapi;
308 #endif
309 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
310     hi_u32                      rssi_last_timestamp;                /* 获取user rssi所用时间戳, 1s最多更新一次rssi */
311 #endif
312 #ifdef _PRE_WLAN_FEATURE_TX_CLASSIFY_LAN_TO_WLAN
313     hi_u8                       cfm_num;                            /* 用户已被识别业务个数 */
314     hi_u8                       auc_resv2[3]; /* 3 保留字节 */
315     hmac_tx_cfm_flow_stru       ast_cfm_flow_list[MAX_CONFIRMED_FLOW_NUM];  /* 已识别业务 */
316     hmac_tx_judge_list_stru     judge_list;                                 /* 待识别流队列 */
317 #endif
318 #ifdef _PRE_WLAN_FEATURE_MESH
319     /* 标志当前Mesh用户AMPE关联阶段是否已经收到并上报Confirm帧,关联成功时重置 */
320     hi_u8                       has_rx_mesh_confirm;
321     hi_u8                       mesh_resv[3];   /* 3:预留 4字节对齐 */
322 #endif
323     /* 此项变量仅能处于HMAC USER结构体内的最后一项 且不能修改和释放 由模块初始化时与mac user指针一一对应 */
324     mac_user_stru              *base_user;
325 } hmac_user_stru;
326 
327 /* SA Query 超时定时器 和 间隔定时器 的超时函数入参结构 */
328 typedef struct {
329     mac_vap_stru     *mac_vap;                  /* 发送SA Query request的mac vap信息 */
330     hmac_user_stru   *hmac_user;                /* 目标user */
331 } hmac_maxtimeout_timer_stru;
332 typedef struct {
333     mac_vap_stru       *mac_vap;                  /* 发送SA Query request的mac vap信息 */
334     hmac_user_stru     *hmac_user;                /* 目标user */
335     hi_u16              us_trans_id;              /* SA Query request帧的trans id */
336     hi_u8               is_protected;             /* SA Query管理帧加密的使能开关 */
337     hi_u8               resv;
338 } hmac_interval_timer_stru;
339 
340 /* 存储AP关联请求帧的ie信息,用于上报内核 */
341 typedef struct {
342     hi_u32 assoc_req_ie_len;
343     hi_u8 *puc_assoc_req_ie_buff;
344     hi_u8  auc_user_mac_addr[WLAN_MAC_ADDR_LEN];
345     hi_u8  uc_resv[2]; /* 2 保留字节 */
346 } hmac_asoc_user_req_ie_stru;
347 
348 /* ****************************************************************************
349   8 UNION定义
350 **************************************************************************** */
351 /* ****************************************************************************
352   9 OTHERS定义
353 **************************************************************************** */
354 /* ****************************************************************************
355  函 数 名  : hmac_user_ht_support
356  功能描述  : 是否为HT用户
357  输入参数  : 无
358  输出参数  : 无
359  返 回 值  : HI_TRUE是,HI_FALSE不是
360  调用函数  :
361  被调函数  :
362 
363  修改历史      :
364   1.日    期   : 2013年4月11日
365     作    者   : HiSilicon
366     修改内容   : 新生成函数
367 
368 **************************************************************************** */
hmac_user_ht_support(const hmac_user_stru * hmac_user)369 static inline hi_u8 hmac_user_ht_support(const hmac_user_stru *hmac_user)
370 {
371     if (hmac_user->base_user->ht_hdl.ht_capable == HI_TRUE) {
372         return HI_TRUE;
373     }
374 
375     return HI_FALSE;
376 }
377 
378 /* ****************************************************************************
379  功能描述  : 是否支持ht/vht聚合
380  输入参数  : hmac_user_stru *pst_hmac_user
381  返 回 值  : static inline hi_u8
382  修改历史      :
383   1.日    期   : 2013年12月12日,星期四
384     作    者   : HiSilicon
385     修改内容   : 新生成函数
386 **************************************************************************** */
hmac_user_xht_support(const hmac_user_stru * hmac_user)387 static inline hi_u8 hmac_user_xht_support(const hmac_user_stru *hmac_user)
388 {
389     if ((hmac_user->base_user->cur_protocol_mode >= WLAN_HT_MODE) &&
390         (hmac_user->base_user->cur_protocol_mode < WLAN_PROTOCOL_BUTT)) {
391         return HI_TRUE;
392     }
393 
394     return HI_FALSE;
395 }
396 
397 /* ****************************************************************************
398   10 函数声明
399 **************************************************************************** */
400 hi_void hmac_user_res_exit(hi_void);
401 hi_u32 hmac_user_res_init(hi_void);
402 hi_u32 hmac_user_alloc(hi_u8 *puc_user_idx);
403 hi_u8 *hmac_user_get_user_stru(hi_u8 idx);
404 hi_u32 hmac_user_free(hi_u8 idx);
405 hi_u32 hmac_user_set_avail_num_space_stream(mac_user_stru *mac_user, wlan_nss_enum_uint8 vap_nss);
406 hi_u32 hmac_send_del_user_event(const mac_vap_stru *mac_vap, const hi_u8 *da_mac_addr, hi_u8 user_idx);
407 hi_u32 hmac_user_del(mac_vap_stru *mac_vap, hmac_user_stru *hmac_user);
408 hi_u32 hmac_user_add(mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 mac_addr_len, hi_u8 *puc_user_index);
409 hi_u32 hmac_user_add_multi_user(const mac_vap_stru *mac_vap, hi_u8 *puc_user_index);
410 hi_u32 hmac_user_del_multi_user(hi_u8 idx);
411 hi_u32 hmac_user_add_notify_alg(const mac_vap_stru *mac_vap, hi_u8 user_idx);
412 hi_u32 hmac_update_user_last_active_time(mac_vap_stru *mac_vap, hi_u8 len, hi_u8 *puc_param);
413 hi_void hmac_tid_clear(mac_vap_stru *mac_vap, hmac_user_stru *hmac_user);
414 hmac_user_stru *mac_vap_get_hmac_user_by_addr(mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 addr_len);
415 
416 #ifdef _PRE_WLAN_FEATURE_WAPI
417 hmac_wapi_stru *hmac_user_get_wapi_ptr(const mac_vap_stru *mac_vap, hi_bool pairwise, hi_u8 pairwise_idx);
418 hi_u8 hmac_user_is_wapi_connected(hi_void);
419 #endif
420 hi_u32 hmac_user_asoc_info_report(mac_vap_stru *mac_vap, const mac_user_stru *mac_user, hi_u8 asoc_state);
421 #ifdef _PRE_WLAN_FEATURE_MESH
422 hi_u32 hmac_set_multicast_user_whitelist(const mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 mac_addr_len);
423 hi_u32 hmac_del_multicast_user_whitelist(const mac_vap_stru *mac_vap, const hi_u8 *mac_addr, hi_u8 mac_addr_len);
424 #endif
425 
426 #ifdef __cplusplus
427 #if __cplusplus
428 }
429 #endif
430 #endif
431 
432 #endif /* _HMAC_USER_H__ */
433