sta_info.h revision 6e8bc71df6aeed8722256f5465b5857235c046a3
1/******************************************************************************
2 *
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 ******************************************************************************/
15#ifndef __STA_INFO_H_
16#define __STA_INFO_H_
17
18#include <osdep_service.h>
19#include <drv_types.h>
20#include <wifi.h>
21
22#define IBSS_START_MAC_ID	2
23#define NUM_STA 32
24#define NUM_ACL 16
25
26
27/* if mode ==0, then the sta is allowed once the addr is hit. */
28/* if mode ==1, then the sta is rejected once the addr is non-hit. */
29struct rtw_wlan_acl_node {
30	struct list_head	list;
31	u8       addr[ETH_ALEN];
32	u8       valid;
33};
34
35/* mode=0, disable */
36/* mode=1, accept unless in deny list */
37/* mode=2, deny unless in accept list */
38struct wlan_acl_pool {
39	int mode;
40	int num;
41	struct rtw_wlan_acl_node aclnode[NUM_ACL];
42	struct rtw_queue	acl_node_q;
43};
44
45struct rssi_sta  {
46	s32	UndecoratedSmoothedPWDB;
47	s32	UndecoratedSmoothedCCK;
48	s32	UndecoratedSmoothedOFDM;
49	u64	PacketMap;
50	u8	ValidBit;
51};
52
53struct	stainfo_stats	{
54	u64 rx_mgnt_pkts;
55		u64 rx_beacon_pkts;
56		u64 rx_probereq_pkts;
57		u64 rx_probersp_pkts;
58		u64 rx_probersp_bm_pkts;
59		u64 rx_probersp_uo_pkts;
60	u64 rx_ctrl_pkts;
61	u64 rx_data_pkts;
62
63	u64	last_rx_mgnt_pkts;
64		u64 last_rx_beacon_pkts;
65		u64 last_rx_probereq_pkts;
66		u64 last_rx_probersp_pkts;
67		u64 last_rx_probersp_bm_pkts;
68		u64 last_rx_probersp_uo_pkts;
69	u64	last_rx_ctrl_pkts;
70	u64	last_rx_data_pkts;
71
72	u64	rx_bytes;
73	u64	rx_drops;
74
75	u64	tx_pkts;
76	u64	tx_bytes;
77	u64  tx_drops;
78
79};
80
81struct sta_info {
82	spinlock_t	lock;
83	struct list_head	list; /* free_sta_queue */
84	struct list_head	hash_list; /* sta_hash */
85	struct rtw_adapter *padapter;
86
87	struct sta_xmit_priv sta_xmitpriv;
88	struct sta_recv_priv sta_recvpriv;
89
90	struct rtw_queue sleep_q;
91	unsigned int sleepq_len;
92
93	uint state;
94	uint aid;
95	uint mac_id;
96	uint qos_option;
97	u8	hwaddr[ETH_ALEN];
98
99	uint	ieee8021x_blocked;	/* 0: allowed, 1:blocked */
100	uint	dot118021XPrivacy; /* aes, tkip... */
101	union Keytype	dot11tkiptxmickey;
102	union Keytype	dot11tkiprxmickey;
103	union Keytype	dot118021x_UncstKey;
104	union pn48		dot11txpn;			/*  PN48 used for Unicast xmit. */
105	union pn48		dot11rxpn;			/*  PN48 used for Unicast recv. */
106
107
108	u8	bssrateset[16];
109	u32	bssratelen;
110	s32  rssi;
111	s32	signal_quality;
112
113	u8	cts2self;
114	u8	rtsen;
115
116	u8	raid;
117	u8	init_rate;
118	u32	ra_mask;
119	u8	wireless_mode;	/*  NETWORK_TYPE */
120	struct stainfo_stats sta_stats;
121
122	/* for A-MPDU TX, ADDBA timeout check */
123	struct timer_list addba_retry_timer;
124
125	/* for A-MPDU Rx reordering buffer control */
126	struct recv_reorder_ctrl recvreorder_ctrl[16];
127
128	/* for A-MPDU Tx */
129	/* unsigned char		ampdu_txen_bitmap; */
130	u16	BA_starting_seqctrl[16];
131
132	struct ht_priv	htpriv;
133
134	/* Notes: */
135	/* STA_Mode: */
136	/* curr_network(mlme_priv/security_priv/qos/ht) + sta_info: (STA & AP) CAP/INFO */
137	/* scan_q: AP CAP/INFO */
138
139	/* AP_Mode: */
140	/* curr_network(mlme_priv/security_priv/qos/ht) : AP CAP/INFO */
141	/* sta_info: (AP & STA) CAP/INFO */
142
143	struct list_head asoc_list;
144	struct list_head auth_list;
145
146	unsigned int expire_to;
147	unsigned int auth_seq;
148	unsigned int authalg;
149	unsigned char chg_txt[128];
150
151	u16 capability;
152	int flags;
153
154	int dot8021xalg;/* 0:disable, 1:psk, 2:802.1x */
155	int wpa_psk;/* 0:disable, bit(0): WPA, bit(1):WPA2 */
156	int wpa_group_cipher;
157	int wpa2_group_cipher;
158	int wpa_pairwise_cipher;
159	int wpa2_pairwise_cipher;
160
161	u8 bpairwise_key_installed;
162
163	u8 wpa_ie[32];
164
165	u8 nonerp_set;
166	u8 no_short_slot_time_set;
167	u8 no_short_preamble_set;
168	u8 no_ht_gf_set;
169	u8 no_ht_set;
170	u8 ht_20mhz_set;
171
172	unsigned int tx_ra_bitmap;
173	u8 qos_info;
174
175	u8 max_sp_len;
176	u8 uapsd_bk;/* BIT(0): Delivery enabled, BIT(1): Trigger enabled */
177	u8 uapsd_be;
178	u8 uapsd_vi;
179	u8 uapsd_vo;
180
181	u8 has_legacy_ac;
182	unsigned int sleepq_ac_len;
183
184	/* p2p priv data */
185	u8 is_p2p_device;
186	u8 p2p_status_code;
187
188	u8 keep_alive_trycnt;
189
190	/* p2p client info */
191	u8 dev_addr[ETH_ALEN];
192	u8 dev_cap;
193	u16 config_methods;
194	u8 primary_dev_type[8];
195	u8 num_of_secdev_type;
196	u8 secdev_types_list[32];/*  32/8 == 4; */
197	u16 dev_name_len;
198	u8 dev_name[32];
199	u8 *passoc_req;
200	u32 assoc_req_len;
201
202	/* for DM */
203	struct rssi_sta	 rssi_stat;
204
205	/*  */
206	/*  ================ODM Relative Info======================= */
207	/*  Please be care, dont declare too much structure here. It will cost memory * STA support num. */
208	/*  */
209	/*  */
210	/*  2011/10/20 MH Add for ODM STA info. */
211	/*  */
212	/*  Driver Write */
213	u8		bValid;				/*  record the sta status link or not? */
214	u8		IOTPeer;			/*  Enum value.	HT_IOT_PEER_E */
215	u8		rssi_level;			/* for Refresh RA mask */
216	/*  ODM Write */
217	/* 1 PHY_STATUS_INFO */
218	u8		RSSI_Path[4];		/*  */
219	u8		RSSI_Ave;
220	u8		RXEVM[4];
221	u8		RXSNR[4];
222
223	/*  ODM Write */
224	/* 1 TX_INFO (may changed by IC) */
225	/*  ================ODM Relative Info======================= */
226	/*  */
227
228	/* To store the sequence number of received management frame */
229	u16 RxMgmtFrameSeqNum;
230};
231
232#define sta_rx_pkts(sta) \
233	(sta->sta_stats.rx_mgnt_pkts \
234	+ sta->sta_stats.rx_ctrl_pkts \
235	+ sta->sta_stats.rx_data_pkts)
236
237#define sta_last_rx_pkts(sta) \
238	(sta->sta_stats.last_rx_mgnt_pkts \
239	+ sta->sta_stats.last_rx_ctrl_pkts \
240	+ sta->sta_stats.last_rx_data_pkts)
241
242#define sta_rx_data_pkts(sta) \
243	(sta->sta_stats.rx_data_pkts)
244
245#define sta_last_rx_data_pkts(sta) \
246	(sta->sta_stats.last_rx_data_pkts)
247
248#define sta_rx_mgnt_pkts(sta) \
249	(sta->sta_stats.rx_mgnt_pkts)
250
251#define sta_last_rx_mgnt_pkts(sta) \
252	(sta->sta_stats.last_rx_mgnt_pkts)
253
254#define sta_rx_beacon_pkts(sta) \
255	(sta->sta_stats.rx_beacon_pkts)
256
257#define sta_last_rx_beacon_pkts(sta) \
258	(sta->sta_stats.last_rx_beacon_pkts)
259
260#define sta_rx_probereq_pkts(sta) \
261	(sta->sta_stats.rx_probereq_pkts)
262
263#define sta_last_rx_probereq_pkts(sta) \
264	(sta->sta_stats.last_rx_probereq_pkts)
265
266#define sta_rx_probersp_pkts(sta) \
267	(sta->sta_stats.rx_probersp_pkts)
268
269#define sta_last_rx_probersp_pkts(sta) \
270	(sta->sta_stats.last_rx_probersp_pkts)
271
272#define sta_rx_probersp_bm_pkts(sta) \
273	(sta->sta_stats.rx_probersp_bm_pkts)
274
275#define sta_last_rx_probersp_bm_pkts(sta) \
276	(sta->sta_stats.last_rx_probersp_bm_pkts)
277
278#define sta_rx_probersp_uo_pkts(sta) \
279	(sta->sta_stats.rx_probersp_uo_pkts)
280
281#define sta_last_rx_probersp_uo_pkts(sta) \
282	(sta->sta_stats.last_rx_probersp_uo_pkts)
283
284#define sta_update_last_rx_pkts(sta) \
285	do { \
286		sta->sta_stats.last_rx_mgnt_pkts = sta->sta_stats.rx_mgnt_pkts; \
287		sta->sta_stats.last_rx_beacon_pkts = sta->sta_stats.rx_beacon_pkts; \
288		sta->sta_stats.last_rx_probereq_pkts = sta->sta_stats.rx_probereq_pkts; \
289		sta->sta_stats.last_rx_probersp_pkts = sta->sta_stats.rx_probersp_pkts; \
290		sta->sta_stats.last_rx_probersp_bm_pkts = sta->sta_stats.rx_probersp_bm_pkts; \
291		sta->sta_stats.last_rx_probersp_uo_pkts = sta->sta_stats.rx_probersp_uo_pkts; \
292		sta->sta_stats.last_rx_ctrl_pkts = sta->sta_stats.rx_ctrl_pkts; \
293		sta->sta_stats.last_rx_data_pkts = sta->sta_stats.rx_data_pkts; \
294	} while (0)
295
296#define STA_RX_PKTS_ARG(sta) \
297	sta->sta_stats.rx_mgnt_pkts \
298	, sta->sta_stats.rx_ctrl_pkts \
299	, sta->sta_stats.rx_data_pkts
300
301#define STA_LAST_RX_PKTS_ARG(sta) \
302	sta->sta_stats.last_rx_mgnt_pkts, \
303	sta->sta_stats.last_rx_ctrl_pkts, \
304	sta->sta_stats.last_rx_data_pkts
305
306#define STA_RX_PKTS_DIFF_ARG(sta) \
307	sta->sta_stats.rx_mgnt_pkts - sta->sta_stats.last_rx_mgnt_pkts, \
308	sta->sta_stats.rx_ctrl_pkts - sta->sta_stats.last_rx_ctrl_pkts, \
309	sta->sta_stats.rx_data_pkts - sta->sta_stats.last_rx_data_pkts
310
311#define STA_PKTS_FMT "(m:%llu, c:%llu, d:%llu)"
312
313struct sta_priv {
314	spinlock_t sta_hash_lock;
315	struct list_head sta_hash[NUM_STA];
316	int asoc_sta_count;
317	struct rtw_queue sleep_q;
318	struct rtw_queue wakeup_q;
319
320	struct rtw_adapter *padapter;
321	struct list_head asoc_list;
322	struct list_head auth_list;
323	spinlock_t asoc_list_lock;
324	spinlock_t auth_list_lock;
325	u8 asoc_list_cnt;
326	u8 auth_list_cnt;
327
328	unsigned int auth_to;  /* sec, time to expire in authenticating. */
329	unsigned int assoc_to; /* sec, time to expire before associating. */
330	unsigned int expire_to; /* sec , time to expire after associated. */
331
332	/* pointers to STA info; based on allocated AID or NULL if AID free
333	 * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
334	 * and so on
335	 */
336	struct sta_info *sta_aid[NUM_STA];
337
338	u16 sta_dz_bitmap;/* only support 15 stations, staion aid bitmap
339			   * for sleeping sta. */
340	u16 tim_bitmap;/* only support 15 stations,
341			* aid=0~15 mapping bit0~bit15 */
342
343	u16 max_num_sta;
344
345	struct wlan_acl_pool acl_list;
346};
347
348static inline u32 wifi_mac_hash(const u8 *mac)
349{
350	u32 x;
351
352	x = mac[0];
353	x = (x << 2) ^ mac[1];
354	x = (x << 2) ^ mac[2];
355	x = (x << 2) ^ mac[3];
356	x = (x << 2) ^ mac[4];
357	x = (x << 2) ^ mac[5];
358
359	x ^= x >> 8;
360	x  = x & (NUM_STA - 1);
361
362	return x;
363}
364
365u32	_rtw_init_sta_priv23a(struct sta_priv *pstapriv);
366u32	_rtw_free_sta_priv23a(struct sta_priv *pstapriv);
367
368struct sta_info *rtw_alloc_stainfo23a(struct sta_priv *pstapriv, u8 *hwaddr, int gfp);
369u32 rtw_free_stainfo23a(struct rtw_adapter *padapter, struct sta_info *psta);
370void rtw_free_all_stainfo23a(struct rtw_adapter *padapter);
371struct sta_info *rtw_get_stainfo23a(struct sta_priv *pstapriv, const u8 *hwaddr);
372u32 rtw_init_bcmc_stainfo23a(struct rtw_adapter *padapter);
373struct sta_info *rtw_get_bcmc_stainfo23a(struct rtw_adapter *padapter);
374u8 rtw_access_ctrl23a(struct rtw_adapter *padapter, u8 *mac_addr);
375
376#endif /* _STA_INFO_H_ */
377