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