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