• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #ifndef __STA_INFO_H_
21 #define __STA_INFO_H_
22 
23 #include <osdep_service.h>
24 #include <drv_types.h>
25 #include <wifi.h>
26 
27 #define IBSS_START_MAC_ID	2
28 #define NUM_STA 32
29 #define NUM_ACL 16
30 
31 /* if mode ==0, then the sta is allowed once the addr is hit. */
32 /* if mode ==1, then the sta is rejected once the addr is non-hit. */
33 struct rtw_wlan_acl_node {
34 	struct list_head list;
35 	u8       addr[ETH_ALEN];
36 	u8       valid;
37 };
38 
39 /* mode=0, disable */
40 /* mode=1, accept unless in deny list */
41 /* mode=2, deny unless in accept list */
42 struct wlan_acl_pool {
43 	int mode;
44 	int num;
45 	struct rtw_wlan_acl_node aclnode[NUM_ACL];
46 	struct __queue acl_node_q;
47 };
48 
49 struct rssi_sta {
50 	s32	UndecoratedSmoothedPWDB;
51 	s32	UndecoratedSmoothedCCK;
52 	s32	UndecoratedSmoothedOFDM;
53 	u64	PacketMap;
54 	u8	ValidBit;
55 };
56 
57 struct	stainfo_stats	{
58 	u64 rx_mgnt_pkts;
59 	u64 rx_beacon_pkts;
60 	u64 rx_probereq_pkts;
61 	u64 rx_probersp_pkts;
62 	u64 rx_probersp_bm_pkts;
63 	u64 rx_probersp_uo_pkts;
64 	u64 rx_ctrl_pkts;
65 	u64 rx_data_pkts;
66 
67 	u64	last_rx_mgnt_pkts;
68 	u64 last_rx_beacon_pkts;
69 	u64 last_rx_probereq_pkts;
70 	u64 last_rx_probersp_pkts;
71 	u64 last_rx_probersp_bm_pkts;
72 	u64 last_rx_probersp_uo_pkts;
73 	u64	last_rx_ctrl_pkts;
74 	u64	last_rx_data_pkts;
75 	u64	rx_bytes;
76 	u64	rx_drops;
77 	u64	tx_pkts;
78 	u64	tx_bytes;
79 	u64  tx_drops;
80 };
81 
82 struct sta_info {
83 	spinlock_t lock;
84 	struct list_head list; /* free_sta_queue */
85 	struct list_head hash_list; /* sta_hash */
86 
87 	struct sta_xmit_priv sta_xmitpriv;
88 	struct sta_recv_priv sta_recvpriv;
89 
90 	struct __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 	u8	bssrateset[16];
107 	u32	bssratelen;
108 	s32  rssi;
109 	s32	signal_quality;
110 
111 	u8	cts2self;
112 	u8	rtsen;
113 
114 	u8	raid;
115 	u8	init_rate;
116 	u32	ra_mask;
117 	u8	wireless_mode;	/*  NETWORK_TYPE */
118 	struct stainfo_stats sta_stats;
119 
120 	/* for A-MPDU TX, ADDBA timeout check */
121 	struct timer_list addba_retry_timer;
122 
123 	/* for A-MPDU Rx reordering buffer control */
124 	struct recv_reorder_ctrl recvreorder_ctrl[16];
125 
126 	/* for A-MPDU Tx */
127 	/* unsigned char		ampdu_txen_bitmap; */
128 	u16	BA_starting_seqctrl[16];
129 
130 	struct ht_priv	htpriv;
131 
132 	/* Notes: */
133 	/* STA_Mode: */
134 	/* curr_network(mlme_priv/security_priv/qos/ht) +
135 	 * sta_info: (STA & AP) CAP/INFO */
136 	/* scan_q: AP CAP/INFO */
137 
138 	/* AP_Mode: */
139 	/* curr_network(mlme_priv/security_priv/qos/ht) : AP CAP/INFO */
140 	/* sta_info: (AP & STA) CAP/INFO */
141 
142 	struct list_head asoc_list;
143 #ifdef CONFIG_88EU_AP_MODE
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 #endif	/*  CONFIG_88EU_AP_MODE */
184 
185 	u8 under_exist_checking;
186 	u8 keep_alive_trycnt;
187 
188 	/* for DM */
189 	struct rssi_sta rssi_stat;
190 
191 	/*  ================ODM Relative Info======================= */
192 	/*  Please be careful, don't declare too much structure here.
193 	 *  It will cost memory * STA support num. */
194 	/*  2011/10/20 MH Add for ODM STA info. */
195 	/*  Driver Write */
196 	u8	bValid;		/*  record the sta status link or not? */
197 	u8	IOTPeer;	/*  Enum value.	HT_IOT_PEER_E */
198 	u8	rssi_level;	/* for Refresh RA mask */
199 	/*  ODM Write */
200 	/* 1 PHY_STATUS_INFO */
201 	u8		RSSI_Path[4];		/*  */
202 	u8		RSSI_Ave;
203 	u8		RXEVM[4];
204 	u8		RXSNR[4];
205 
206 	/*  ================ODM Relative Info======================= */
207 	/*  */
208 
209 	/* To store the sequence number of received management frame */
210 	u16 RxMgmtFrameSeqNum;
211 };
212 
213 #define sta_rx_pkts(sta) \
214 	(sta->sta_stats.rx_mgnt_pkts \
215 	+ sta->sta_stats.rx_ctrl_pkts \
216 	+ sta->sta_stats.rx_data_pkts)
217 
218 #define sta_last_rx_pkts(sta) \
219 	(sta->sta_stats.last_rx_mgnt_pkts \
220 	+ sta->sta_stats.last_rx_ctrl_pkts \
221 	+ sta->sta_stats.last_rx_data_pkts)
222 
223 #define sta_rx_data_pkts(sta) \
224 	(sta->sta_stats.rx_data_pkts)
225 
226 #define sta_last_rx_data_pkts(sta) \
227 	(sta->sta_stats.last_rx_data_pkts)
228 
229 #define sta_rx_mgnt_pkts(sta) \
230 	(sta->sta_stats.rx_mgnt_pkts)
231 
232 #define sta_last_rx_mgnt_pkts(sta) \
233 	(sta->sta_stats.last_rx_mgnt_pkts)
234 
235 #define sta_rx_beacon_pkts(sta) \
236 	(sta->sta_stats.rx_beacon_pkts)
237 
238 #define sta_last_rx_beacon_pkts(sta) \
239 	(sta->sta_stats.last_rx_beacon_pkts)
240 
241 #define sta_rx_probereq_pkts(sta) \
242 	(sta->sta_stats.rx_probereq_pkts)
243 
244 #define sta_last_rx_probereq_pkts(sta) \
245 	(sta->sta_stats.last_rx_probereq_pkts)
246 
247 #define sta_rx_probersp_pkts(sta) \
248 	(sta->sta_stats.rx_probersp_pkts)
249 
250 #define sta_last_rx_probersp_pkts(sta) \
251 	(sta->sta_stats.last_rx_probersp_pkts)
252 
253 #define sta_rx_probersp_bm_pkts(sta) \
254 	(sta->sta_stats.rx_probersp_bm_pkts)
255 
256 #define sta_last_rx_probersp_bm_pkts(sta) \
257 	(sta->sta_stats.last_rx_probersp_bm_pkts)
258 
259 #define sta_rx_probersp_uo_pkts(sta) \
260 	(sta->sta_stats.rx_probersp_uo_pkts)
261 
262 #define sta_last_rx_probersp_uo_pkts(sta) \
263 	(sta->sta_stats.last_rx_probersp_uo_pkts)
264 
265 #define sta_update_last_rx_pkts(sta) \
266 do { \
267 	sta->sta_stats.last_rx_mgnt_pkts = sta->sta_stats.rx_mgnt_pkts; \
268 	sta->sta_stats.last_rx_beacon_pkts = sta->sta_stats.rx_beacon_pkts; \
269 	sta->sta_stats.last_rx_probereq_pkts = sta->sta_stats.rx_probereq_pkts; \
270 	sta->sta_stats.last_rx_probersp_pkts = sta->sta_stats.rx_probersp_pkts; \
271 	sta->sta_stats.last_rx_probersp_bm_pkts = sta->sta_stats.rx_probersp_bm_pkts; \
272 	sta->sta_stats.last_rx_probersp_uo_pkts = sta->sta_stats.rx_probersp_uo_pkts; \
273 	sta->sta_stats.last_rx_ctrl_pkts = sta->sta_stats.rx_ctrl_pkts; \
274 	sta->sta_stats.last_rx_data_pkts = sta->sta_stats.rx_data_pkts; \
275 } while (0)
276 
277 #define STA_RX_PKTS_ARG(sta) \
278 	sta->sta_stats.rx_mgnt_pkts \
279 	, sta->sta_stats.rx_ctrl_pkts \
280 	, sta->sta_stats.rx_data_pkts
281 
282 #define STA_LAST_RX_PKTS_ARG(sta) \
283 	sta->sta_stats.last_rx_mgnt_pkts \
284 	, sta->sta_stats.last_rx_ctrl_pkts \
285 	, sta->sta_stats.last_rx_data_pkts
286 
287 #define STA_RX_PKTS_DIFF_ARG(sta) \
288 	sta->sta_stats.rx_mgnt_pkts - sta->sta_stats.last_rx_mgnt_pkts \
289 	, sta->sta_stats.rx_ctrl_pkts - sta->sta_stats.last_rx_ctrl_pkts \
290 	, sta->sta_stats.rx_data_pkts - sta->sta_stats.last_rx_data_pkts
291 
292 #define STA_PKTS_FMT "(m:%llu, c:%llu, d:%llu)"
293 
294 struct	sta_priv {
295 	u8 *pallocated_stainfo_buf;
296 	u8 *pstainfo_buf;
297 	struct __queue free_sta_queue;
298 
299 	spinlock_t sta_hash_lock;
300 	struct list_head sta_hash[NUM_STA];
301 	int asoc_sta_count;
302 	struct __queue sleep_q;
303 	struct __queue wakeup_q;
304 
305 	struct adapter *padapter;
306 
307 	spinlock_t asoc_list_lock;
308 	struct list_head asoc_list;
309 
310 #ifdef CONFIG_88EU_AP_MODE
311 	struct list_head auth_list;
312 	spinlock_t auth_list_lock;
313 	u8 asoc_list_cnt;
314 	u8 auth_list_cnt;
315 
316 	unsigned int auth_to;  /* sec, time to expire in authenticating. */
317 	unsigned int assoc_to; /* sec, time to expire before associating. */
318 	unsigned int expire_to; /* sec , time to expire after associated. */
319 
320 	/* pointers to STA info; based on allocated AID or NULL if AID free
321 	 * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
322 	 * and so on
323 	 */
324 	struct sta_info *sta_aid[NUM_STA];
325 
326 	u16 sta_dz_bitmap;/* only support 15 stations, station aid bitmap
327 			   * for sleeping sta. */
328 	u16 tim_bitmap;	/* only support 15 stations, aid=0~15 mapping
329 			 * bit0~bit15 */
330 
331 	u16 max_num_sta;
332 
333 	struct wlan_acl_pool acl_list;
334 #endif
335 
336 };
337 
wifi_mac_hash(u8 * mac)338 static inline u32 wifi_mac_hash(u8 *mac)
339 {
340 	u32 x;
341 
342 	x = mac[0];
343 	x = (x << 2) ^ mac[1];
344 	x = (x << 2) ^ mac[2];
345 	x = (x << 2) ^ mac[3];
346 	x = (x << 2) ^ mac[4];
347 	x = (x << 2) ^ mac[5];
348 
349 	x ^= x >> 8;
350 	x  = x & (NUM_STA - 1);
351 	return x;
352 }
353 
354 extern u32	_rtw_init_sta_priv(struct sta_priv *pstapriv);
355 extern u32	_rtw_free_sta_priv(struct sta_priv *pstapriv);
356 
357 #define stainfo_offset_valid(offset) (offset < NUM_STA && offset >= 0)
358 int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta);
359 struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int off);
360 
361 extern struct sta_info *rtw_alloc_stainfo(struct sta_priv *stapriv, u8 *hwaddr);
362 extern u32	rtw_free_stainfo(struct adapter *adapt, struct sta_info *psta);
363 extern void rtw_free_all_stainfo(struct adapter *adapt);
364 extern struct sta_info *rtw_get_stainfo(struct sta_priv *stapriv, u8 *hwaddr);
365 extern u32 rtw_init_bcmc_stainfo(struct adapter *adapt);
366 extern struct sta_info *rtw_get_bcmc_stainfo(struct adapter *padapter);
367 extern u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr);
368 
369 #endif /* _STA_INFO_H_ */
370