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