xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8189fs/include/sta_info.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2019 Realtek Corporation.
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 <cmn_info/rtw_sta_info.h>
19 
20 #define IBSS_START_MAC_ID	2
21 #define NUM_STA MACID_NUM_SW_LIMIT
22 
23 #ifndef CONFIG_RTW_MACADDR_ACL
24 	#ifdef CONFIG_AP_MODE
25 	#define CONFIG_RTW_MACADDR_ACL 1
26 	#else
27 	#define CONFIG_RTW_MACADDR_ACL 0
28 	#endif
29 #endif
30 
31 #ifndef CONFIG_RTW_PRE_LINK_STA
32 	#define CONFIG_RTW_PRE_LINK_STA 0
33 #endif
34 
35 #define NUM_ACL 16
36 
37 #define RTW_ACL_PERIOD_DEV 0
38 #define RTW_ACL_PERIOD_BSS 1
39 #define RTW_ACL_PERIOD_NUM 2
40 
41 #define RTW_ACL_MODE_DISABLED				0
42 #define RTW_ACL_MODE_ACCEPT_UNLESS_LISTED	1
43 #define RTW_ACL_MODE_DENY_UNLESS_LISTED		2
44 #define RTW_ACL_MODE_MAX					3
45 
46 #if CONFIG_RTW_MACADDR_ACL
47 extern const char *const _acl_period_str[RTW_ACL_PERIOD_NUM];
48 #define acl_period_str(mode) (((mode) >= RTW_ACL_PERIOD_NUM) ? "INVALID" : _acl_period_str[(mode)])
49 extern const char *const _acl_mode_str[RTW_ACL_MODE_MAX];
50 #define acl_mode_str(mode) (((mode) >= RTW_ACL_MODE_MAX) ? "INVALID" : _acl_mode_str[(mode)])
51 #endif
52 
53 #ifndef RTW_PRE_LINK_STA_NUM
54 	#define RTW_PRE_LINK_STA_NUM 8
55 #endif
56 
57 struct pre_link_sta_node_t {
58 	u8 valid;
59 	u8 addr[ETH_ALEN];
60 };
61 
62 struct pre_link_sta_ctl_t {
63 	_lock lock;
64 	u8 num;
65 	struct pre_link_sta_node_t node[RTW_PRE_LINK_STA_NUM];
66 };
67 
68 #ifdef CONFIG_TDLS
69 #define MAX_ALLOWED_TDLS_STA_NUM	4
70 #endif
71 
72 enum sta_info_update_type {
73 	STA_INFO_UPDATE_NONE = 0,
74 	STA_INFO_UPDATE_BW = BIT(0),
75 	STA_INFO_UPDATE_RATE = BIT(1),
76 	STA_INFO_UPDATE_PROTECTION_MODE = BIT(2),
77 	STA_INFO_UPDATE_CAP = BIT(3),
78 	STA_INFO_UPDATE_HT_CAP = BIT(4),
79 	STA_INFO_UPDATE_VHT_CAP = BIT(5),
80 	STA_INFO_UPDATE_ALL = STA_INFO_UPDATE_BW
81 			      | STA_INFO_UPDATE_RATE
82 			      | STA_INFO_UPDATE_PROTECTION_MODE
83 			      | STA_INFO_UPDATE_CAP
84 			      | STA_INFO_UPDATE_HT_CAP
85 			      | STA_INFO_UPDATE_VHT_CAP,
86 	STA_INFO_UPDATE_MAX
87 };
88 
89 struct rtw_wlan_acl_node {
90 	_list		        list;
91 	u8       addr[ETH_ALEN];
92 	u8       valid;
93 };
94 
95 struct wlan_acl_pool {
96 	int mode;
97 	int num;
98 	struct rtw_wlan_acl_node aclnode[NUM_ACL];
99 	_queue	acl_node_q;
100 };
101 
102 struct	stainfo_stats	{
103 	systime last_rx_time;
104 
105 	u64 rx_mgnt_pkts;
106 	u64 rx_beacon_pkts;
107 	u64 rx_probereq_pkts;
108 	u64 rx_probersp_pkts; /* unicast to self */
109 	u64 rx_probersp_bm_pkts;
110 	u64 rx_probersp_uo_pkts; /* unicast to others */
111 	u64 rx_ctrl_pkts;
112 	u64 rx_data_pkts;
113 	u64 rx_data_bc_pkts;
114 	u64 rx_data_mc_pkts;
115 	u64 rx_data_qos_pkts[TID_NUM]; /* unicast only */
116 
117 	u64	last_rx_mgnt_pkts;
118 	u64 last_rx_beacon_pkts;
119 	u64 last_rx_probereq_pkts;
120 	u64 last_rx_probersp_pkts; /* unicast to self */
121 	u64 last_rx_probersp_bm_pkts;
122 	u64 last_rx_probersp_uo_pkts; /* unicast to others */
123 	u64	last_rx_ctrl_pkts;
124 	u64	last_rx_data_pkts;
125 	u64 last_rx_data_bc_pkts;
126 	u64 last_rx_data_mc_pkts;
127 	u64 last_rx_data_qos_pkts[TID_NUM]; /* unicast only */
128 
129 #ifdef CONFIG_TDLS
130 	u64 rx_tdls_disc_rsp_pkts;
131 	u64 last_rx_tdls_disc_rsp_pkts;
132 #endif
133 
134 	u64	rx_bytes;
135 	u64	rx_bc_bytes;
136 	u64	rx_mc_bytes;
137 	u64	last_rx_bytes;
138 	u64 last_rx_bc_bytes;
139 	u64 last_rx_mc_bytes;
140 	u64	rx_drops; /* TBD */
141 	u32 rx_tp_kbits;
142 	u32 smooth_rx_tp_kbits;
143 
144 	u64	tx_pkts;
145 	u64	last_tx_pkts;
146 
147 	u64	tx_bytes;
148 	u64	last_tx_bytes;
149 	u64 tx_drops; /* TBD */
150 	u32 tx_tp_kbits;
151 	u32 smooth_tx_tp_kbits;
152 
153 #ifdef CONFIG_LPS_CHK_BY_TP
154 	u64 acc_tx_bytes;
155 	u64 acc_rx_bytes;
156 #endif
157 
158 	/* unicast only */
159 	u64 last_rx_data_uc_pkts; /* For Read & Clear requirement in proc_get_rx_stat() */
160 	u32 duplicate_cnt;	/* Read & Clear, in proc_get_rx_stat() */
161 	u32 rxratecnt[128];	/* Read & Clear, in proc_get_rx_stat() */
162 	u32 tx_ok_cnt;		/* Read & Clear, in proc_get_tx_stat() */
163 	u32 tx_fail_cnt;	/* Read & Clear, in proc_get_tx_stat() */
164 	u32 tx_retry_cnt;	/* Read & Clear, in proc_get_tx_stat() */
165 #ifdef CONFIG_RTW_MESH
166 	u32 rx_hwmp_pkts;
167 	u32 last_rx_hwmp_pkts;
168 #endif
169 };
170 
171 #ifndef DBG_SESSION_TRACKER
172 #define DBG_SESSION_TRACKER 0
173 #endif
174 
175 /* session tracker status */
176 #define ST_STATUS_NONE		0
177 #define ST_STATUS_CHECK		BIT0
178 #define ST_STATUS_ESTABLISH	BIT1
179 #define ST_STATUS_EXPIRE	BIT2
180 
181 #define ST_EXPIRE_MS (10 * 1000)
182 
183 struct session_tracker {
184 	_list list; /* session_tracker_queue */
185 	u32 local_naddr;
186 	u16 local_port;
187 	u32 remote_naddr;
188 	u16 remote_port;
189 	systime set_time;
190 	u8 status;
191 };
192 
193 /* session tracker cmd */
194 #define ST_CMD_ADD 0
195 #define ST_CMD_DEL 1
196 #define ST_CMD_CHK 2
197 
198 struct st_cmd_parm {
199 	u8 cmd;
200 	struct sta_info *sta;
201 	u32 local_naddr; /* TODO: IPV6 */
202 	u16 local_port;
203 	u32 remote_naddr; /* TODO: IPV6 */
204 	u16 remote_port;
205 };
206 
207 typedef bool (*st_match_rule)(_adapter *adapter, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port);
208 
209 struct st_register {
210 	u8 s_proto;
211 	st_match_rule rule;
212 };
213 
214 #define SESSION_TRACKER_REG_ID_WFD 0
215 #define SESSION_TRACKER_REG_ID_NUM 1
216 
217 struct st_ctl_t {
218 	struct st_register reg[SESSION_TRACKER_REG_ID_NUM];
219 	_queue tracker_q;
220 };
221 
222 void rtw_st_ctl_init(struct st_ctl_t *st_ctl);
223 void rtw_st_ctl_deinit(struct st_ctl_t *st_ctl);
224 void rtw_st_ctl_register(struct st_ctl_t *st_ctl, u8 st_reg_id, struct st_register *reg);
225 void rtw_st_ctl_unregister(struct st_ctl_t *st_ctl, u8 st_reg_id);
226 bool rtw_st_ctl_chk_reg_s_proto(struct st_ctl_t *st_ctl, u8 s_proto);
227 bool rtw_st_ctl_chk_reg_rule(struct st_ctl_t *st_ctl, _adapter *adapter, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port);
228 void rtw_st_ctl_rx(struct sta_info *sta, u8 *ehdr_pos);
229 void dump_st_ctl(void *sel, struct st_ctl_t *st_ctl);
230 
231 #ifdef CONFIG_TDLS
232 struct TDLS_PeerKey {
233 	u8 kck[16]; /* TPK-KCK */
234 	u8 tk[16]; /* TPK-TK; only CCMP will be used */
235 } ;
236 #endif /* CONFIG_TDLS */
237 
238 #ifdef DBG_RX_DFRAME_RAW_DATA
239 struct sta_recv_dframe_info {
240 
241 	u8 sta_data_rate;
242 	u8 sta_sgi;
243 	u8 sta_bw_mode;
244 	s8 sta_mimo_signal_strength[4];
245 	s8 sta_RxPwr[4];
246 	u8 sta_ofdm_snr[4];
247 };
248 #endif
249 
250 #ifdef CONFIG_RTW_MESH
251 struct mesh_plink_ent;
252 struct rtw_ewma_err_rate {
253 	unsigned long internal;
254 };
255 
256 /* Mesh airtime link metrics parameters */
257 struct rtw_atlm_param {
258 	struct rtw_ewma_err_rate err_rate; /* Now is PACKET error rate */
259 	u16 data_rate; /* The unit is 100Kbps */
260 	u16 total_pkt;
261 	u16 overhead; /* Channel access overhead */
262 };
263 #endif
264 
265 struct sta_info {
266 
267 	_lock	lock;
268 	_list	list; /* free_sta_queue */
269 	_list	hash_list; /* sta_hash */
270 	/* _list asoc_list; */ /* 20061114 */
271 	/* _list sleep_list; */ /* sleep_q */
272 	/* _list wakeup_list; */ /* wakeup_q */
273 	_adapter *padapter;
274 	struct cmn_sta_info cmn;
275 
276 	struct sta_xmit_priv sta_xmitpriv;
277 	struct sta_recv_priv sta_recvpriv;
278 
279 #ifdef DBG_RX_DFRAME_RAW_DATA
280 	struct sta_recv_dframe_info  sta_dframe_info;
281 	struct sta_recv_dframe_info  sta_dframe_info_bmc;
282 #endif
283 	_queue sleep_q;
284 	unsigned int sleepq_len;
285 
286 	uint state;
287 	uint qos_option;
288 	u16 hwseq;
289 
290 #ifdef CONFIG_RTW_80211K
291 	u8 rm_en_cap[5];
292 	u8 rm_diag_token;
293 #endif /* CONFIG_RTW_80211K */
294 
295 	systime	resp_nonenc_eapol_key_starttime;
296 	uint	ieee8021x_blocked;	/* 0: allowed, 1:blocked */
297 	uint	dot118021XPrivacy; /* aes, tkip... */
298 	union Keytype	dot11tkiptxmickey;
299 	union Keytype	dot11tkiprxmickey;
300 	union Keytype	dot118021x_UncstKey;
301 	union pn48		dot11txpn;			/* PN48 used for Unicast xmit */
302 	union pn48		dot11rxpn;			/* PN48 used for Unicast recv. */
303 	ATOMIC_T	keytrack;
304 #ifdef CONFIG_RTW_MESH
305 	/* peer's GTK, RX only */
306 	u8 group_privacy;
307 	u8 gtk_bmp;
308 	union Keytype gtk;
309 	union pn48 gtk_pn;
310 	#ifdef CONFIG_IEEE80211W
311 	/* peer's IGTK, RX only */
312 	enum security_type dot11wCipher;
313 	u8 igtk_bmp;
314 	u8 igtk_id;
315 	union Keytype igtk;
316 	union pn48 igtk_pn;
317 	#endif /* CONFIG_IEEE80211W */
318 #endif /* CONFIG_RTW_MESH */
319 #ifdef CONFIG_GTK_OL
320 	u8 kek[RTW_KEK_LEN];
321 	u8 kck[RTW_KCK_LEN];
322 	u8 replay_ctr[RTW_REPLAY_CTR_LEN];
323 #endif /* CONFIG_GTK_OL */
324 #ifdef CONFIG_IEEE80211W
325 	_timer dot11w_expire_timer;
326 #endif /* CONFIG_IEEE80211W */
327 
328 	u8	bssrateset[16];
329 	u32	bssratelen;
330 
331 	u8	cts2self;
332 	u8	rtsen;
333 
334 	u8	init_rate;
335 	u8	wireless_mode;	/* NETWORK_TYPE */
336 
337 	struct stainfo_stats sta_stats;
338 
339 #ifdef CONFIG_TDLS
340 	u32	tdls_sta_state;
341 	u8	SNonce[32];
342 	u8	ANonce[32];
343 	u32	TDLS_PeerKey_Lifetime;
344 	u32	TPK_count;
345 	_timer	TPK_timer;
346 	struct TDLS_PeerKey	tpk;
347 #ifdef CONFIG_TDLS_CH_SW
348 	u16	ch_switch_time;
349 	u16	ch_switch_timeout;
350 	/* u8	option; */
351 	_timer	ch_sw_timer;
352 	_timer	delay_timer;
353 	_timer	stay_on_base_chnl_timer;
354 	_timer	ch_sw_monitor_timer;
355 #endif
356 	_timer handshake_timer;
357 	u8 alive_count;
358 	_timer	pti_timer;
359 	u8	TDLS_RSNIE[20];	/* Save peer's RSNIE, used for sending TDLS_SETUP_RSP */
360 #endif /* CONFIG_TDLS */
361 
362 	/* for A-MPDU TX, ADDBA timeout check	 */
363 	_timer addba_retry_timer;
364 
365 	/* for A-MPDU Rx reordering buffer control */
366 	struct recv_reorder_ctrl recvreorder_ctrl[TID_NUM];
367 	ATOMIC_T continual_no_rx_packet[TID_NUM];
368 	/* for A-MPDU Tx */
369 	/* unsigned char		ampdu_txen_bitmap; */
370 	u16	BA_starting_seqctrl[16];
371 
372 
373 #ifdef CONFIG_80211N_HT
374 	struct ht_priv	htpriv;
375 #endif
376 
377 #ifdef CONFIG_80211AC_VHT
378 	struct vht_priv	vhtpriv;
379 #endif
380 
381 	/* Notes:	 */
382 	/* STA_Mode: */
383 	/* curr_network(mlme_priv/security_priv/qos/ht) + sta_info: (STA & AP) CAP/INFO	 */
384 	/* scan_q: AP CAP/INFO */
385 
386 	/* AP_Mode: */
387 	/* curr_network(mlme_priv/security_priv/qos/ht) : AP CAP/INFO */
388 	/* sta_info: (AP & STA) CAP/INFO */
389 
390 	unsigned int expire_to;
391 
392 	int flags;
393 
394 	u8 bpairwise_key_installed;
395 
396 #ifdef CONFIG_AP_MODE
397 
398 	_list asoc_list;
399 	_list auth_list;
400 
401 	unsigned int auth_seq;
402 	unsigned int authalg;
403 	unsigned char chg_txt[128];
404 
405 	u16 capability;
406 
407 	int dot8021xalg;/* 0:disable, 1:psk, 2:802.1x */
408 	int wpa_psk;/* 0:disable, bit(0): WPA, bit(1):WPA2 */
409 	int wpa_group_cipher;
410 	int wpa2_group_cipher;
411 	int wpa_pairwise_cipher;
412 	int wpa2_pairwise_cipher;
413 
414 	u32 akm_suite_type;
415 
416 #ifdef CONFIG_RTW_80211R
417 	u8 ft_pairwise_key_installed;
418 #endif
419 
420 #ifdef CONFIG_NATIVEAP_MLME
421 	u8 wpa_ie[32];
422 
423 	u8 nonerp_set;
424 	u8 no_short_slot_time_set;
425 	u8 no_short_preamble_set;
426 	u8 no_ht_gf_set;
427 	u8 no_ht_set;
428 	u8 ht_20mhz_set;
429 	u8 ht_40mhz_intolerant;
430 #endif /* CONFIG_NATIVEAP_MLME */
431 
432 #ifdef CONFIG_ATMEL_RC_PATCH
433 	u8 flag_atmel_rc;
434 #endif
435 
436 	u8 qos_info;
437 
438 	u8 max_sp_len;
439 	u8 uapsd_bk;/* BIT(0): Delivery enabled, BIT(1): Trigger enabled */
440 	u8 uapsd_be;
441 	u8 uapsd_vi;
442 	u8 uapsd_vo;
443 
444 	u8 has_legacy_ac;
445 	unsigned int sleepq_ac_len;
446 
447 #ifdef CONFIG_P2P
448 	/* p2p priv data */
449 	u8 is_p2p_device;
450 	u8 p2p_status_code;
451 
452 	/* p2p client info */
453 	u8 dev_addr[ETH_ALEN];
454 	/* u8 iface_addr[ETH_ALEN]; */ /* = hwaddr[ETH_ALEN] */
455 	u8 dev_cap;
456 	u16 config_methods;
457 	u8 primary_dev_type[8];
458 	u8 num_of_secdev_type;
459 	u8 secdev_types_list[32];/* 32/8 == 4; */
460 	u16 dev_name_len;
461 	u8 dev_name[32];
462 #endif /* CONFIG_P2P */
463 
464 #ifdef CONFIG_WFD
465 	u8 op_wfd_mode;
466 #endif
467 
468 #if !defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && defined(CONFIG_80211N_HT)
469 	u8 under_exist_checking;
470 #endif
471 
472 	u8 keep_alive_trycnt;
473 
474 #ifdef CONFIG_AUTO_AP_MODE
475 	u8 isrc; /* this device is rc */
476 	u16 pid; /* pairing id */
477 #endif
478 
479 #endif /* CONFIG_AP_MODE	 */
480 
481 #ifdef CONFIG_RTW_MESH
482 	struct mesh_plink_ent *plink;
483 
484 	u8 local_mps;
485 	u8 peer_mps;
486 	u8 nonpeer_mps;
487 
488 	struct rtw_atlm_param metrics;
489 	/* The reference for nexthop_lookup */
490 	BOOLEAN alive;
491 #endif
492 
493 #ifdef CONFIG_IOCTL_CFG80211
494 	u8 *pauth_frame;
495 	u32 auth_len;
496 	u8 *passoc_req;
497 	u32 assoc_req_len;
498 #endif
499 
500 	u8		IOTPeer;			/* Enum value.	HT_IOT_PEER_E */
501 #ifdef CONFIG_LPS_PG
502 	u8		lps_pg_rssi_lv;
503 #endif
504 
505 	/* To store the sequence number of received management frame */
506 	u16 RxMgmtFrameSeqNum;
507 
508 	struct st_ctl_t st_ctl;
509 	u8 max_agg_num_minimal_record; /*keep minimal tx desc max_agg_num setting*/
510 	u8 curr_rx_rate;
511 	u8 curr_rx_rate_bmc;
512 #ifdef CONFIG_RTS_FULL_BW
513 	bool vendor_8812;
514 #endif
515 
516 #ifdef CONFIG_RTW_TOKEN_BASED_XMIT
517 	u8 tbtx_enable;			/* Does this sta_info support & enable TBTX function? */
518 //	u8 tbtx_timeslot;		/* This sta_info belong to which time slot.	*/
519 #endif
520 
521 	/*
522 	 * Vaiables for queuing TX pkt a short period of time
523 	 * to wait something ready.
524 	 */
525 	u8 tx_q_enable;
526 	struct __queue tx_queue;
527 	_workitem tx_q_work;
528 };
529 
530 #ifdef CONFIG_RTW_MESH
531 #define STA_SET_MESH_PLINK(sta, link) (sta)->plink = link
532 #else
533 #define STA_SET_MESH_PLINK(sta, link) do {} while (0)
534 #endif
535 
536 #define sta_tx_pkts(sta) \
537 	(sta->sta_stats.tx_pkts)
538 
539 #define sta_last_tx_pkts(sta) \
540 	(sta->sta_stats.last_tx_pkts)
541 
542 #define sta_rx_pkts(sta) \
543 	(sta->sta_stats.rx_mgnt_pkts \
544 	 + sta->sta_stats.rx_ctrl_pkts \
545 	 + sta->sta_stats.rx_data_pkts)
546 
547 #define sta_last_rx_pkts(sta) \
548 	(sta->sta_stats.last_rx_mgnt_pkts \
549 	 + sta->sta_stats.last_rx_ctrl_pkts \
550 	 + sta->sta_stats.last_rx_data_pkts)
551 
552 #define sta_rx_data_pkts(sta) (sta->sta_stats.rx_data_pkts)
553 #define sta_last_rx_data_pkts(sta) (sta->sta_stats.last_rx_data_pkts)
554 
555 #define sta_rx_data_uc_pkts(sta) (sta->sta_stats.rx_data_pkts - sta->sta_stats.rx_data_bc_pkts - sta->sta_stats.rx_data_mc_pkts)
556 #define sta_last_rx_data_uc_pkts(sta) (sta->sta_stats.last_rx_data_pkts - sta->sta_stats.last_rx_data_bc_pkts - sta->sta_stats.last_rx_data_mc_pkts)
557 
558 #define sta_rx_data_qos_pkts(sta, i) \
559 	(sta->sta_stats.rx_data_qos_pkts[i])
560 
561 #define sta_last_rx_data_qos_pkts(sta, i) \
562 	(sta->sta_stats.last_rx_data_qos_pkts[i])
563 
564 #define sta_rx_mgnt_pkts(sta) \
565 	(sta->sta_stats.rx_mgnt_pkts)
566 
567 #define sta_last_rx_mgnt_pkts(sta) \
568 	(sta->sta_stats.last_rx_mgnt_pkts)
569 
570 #define sta_rx_beacon_pkts(sta) \
571 	(sta->sta_stats.rx_beacon_pkts)
572 
573 #define sta_last_rx_beacon_pkts(sta) \
574 	(sta->sta_stats.last_rx_beacon_pkts)
575 
576 #define sta_rx_probereq_pkts(sta) \
577 	(sta->sta_stats.rx_probereq_pkts)
578 
579 #define sta_last_rx_probereq_pkts(sta) \
580 	(sta->sta_stats.last_rx_probereq_pkts)
581 
582 #define sta_rx_probersp_pkts(sta) \
583 	(sta->sta_stats.rx_probersp_pkts)
584 
585 #define sta_last_rx_probersp_pkts(sta) \
586 	(sta->sta_stats.last_rx_probersp_pkts)
587 
588 #define sta_rx_probersp_bm_pkts(sta) \
589 	(sta->sta_stats.rx_probersp_bm_pkts)
590 
591 #define sta_last_rx_probersp_bm_pkts(sta) \
592 	(sta->sta_stats.last_rx_probersp_bm_pkts)
593 
594 #define sta_rx_probersp_uo_pkts(sta) \
595 	(sta->sta_stats.rx_probersp_uo_pkts)
596 
597 #define sta_last_rx_probersp_uo_pkts(sta) \
598 	(sta->sta_stats.last_rx_probersp_uo_pkts)
599 
600 #ifdef CONFIG_RTW_MESH
601 #define update_last_rx_hwmp_pkts(sta) \
602 	do { \
603 		sta->sta_stats.last_rx_hwmp_pkts = sta->sta_stats.rx_hwmp_pkts; \
604 	} while(0)
605 #else
606 #define update_last_rx_hwmp_pkts(sta) do {} while(0)
607 #endif
608 
609 #define sta_update_last_rx_pkts(sta) \
610 	do { \
611 		int __i; \
612 		\
613 		sta->sta_stats.last_rx_mgnt_pkts = sta->sta_stats.rx_mgnt_pkts; \
614 		sta->sta_stats.last_rx_beacon_pkts = sta->sta_stats.rx_beacon_pkts; \
615 		sta->sta_stats.last_rx_probereq_pkts = sta->sta_stats.rx_probereq_pkts; \
616 		sta->sta_stats.last_rx_probersp_pkts = sta->sta_stats.rx_probersp_pkts; \
617 		sta->sta_stats.last_rx_probersp_bm_pkts = sta->sta_stats.rx_probersp_bm_pkts; \
618 		sta->sta_stats.last_rx_probersp_uo_pkts = sta->sta_stats.rx_probersp_uo_pkts; \
619 		sta->sta_stats.last_rx_ctrl_pkts = sta->sta_stats.rx_ctrl_pkts; \
620 		update_last_rx_hwmp_pkts(sta); \
621 		\
622 		sta->sta_stats.last_rx_data_pkts = sta->sta_stats.rx_data_pkts; \
623 		sta->sta_stats.last_rx_data_bc_pkts = sta->sta_stats.rx_data_bc_pkts; \
624 		sta->sta_stats.last_rx_data_mc_pkts = sta->sta_stats.rx_data_mc_pkts; \
625 		for (__i = 0; __i < TID_NUM; __i++) \
626 			sta->sta_stats.last_rx_data_qos_pkts[__i] = sta->sta_stats.rx_data_qos_pkts[__i]; \
627 	} while (0)
628 
629 #define STA_RX_PKTS_ARG(sta) \
630 	sta->sta_stats.rx_mgnt_pkts \
631 	, sta->sta_stats.rx_ctrl_pkts \
632 	, sta->sta_stats.rx_data_pkts
633 
634 #define STA_LAST_RX_PKTS_ARG(sta) \
635 	sta->sta_stats.last_rx_mgnt_pkts \
636 	, sta->sta_stats.last_rx_ctrl_pkts \
637 	, sta->sta_stats.last_rx_data_pkts
638 
639 #define STA_RX_PKTS_DIFF_ARG(sta) \
640 	sta->sta_stats.rx_mgnt_pkts - sta->sta_stats.last_rx_mgnt_pkts \
641 	, sta->sta_stats.rx_ctrl_pkts - sta->sta_stats.last_rx_ctrl_pkts \
642 	, sta->sta_stats.rx_data_pkts - sta->sta_stats.last_rx_data_pkts
643 
644 #define STA_PKTS_FMT "(m:%llu, c:%llu, d:%llu)"
645 
646 #define sta_rx_uc_bytes(sta) (sta->sta_stats.rx_bytes - sta->sta_stats.rx_bc_bytes - sta->sta_stats.rx_mc_bytes)
647 #define sta_last_rx_uc_bytes(sta) (sta->sta_stats.last_rx_bytes - sta->sta_stats.last_rx_bc_bytes - sta->sta_stats.last_rx_mc_bytes)
648 
649 #ifdef CONFIG_WFD
650 #define STA_OP_WFD_MODE(sta) (sta)->op_wfd_mode
651 #define STA_SET_OP_WFD_MODE(sta, mode) (sta)->op_wfd_mode = (mode)
652 #else
653 #define STA_OP_WFD_MODE(sta) 0
654 #define STA_SET_OP_WFD_MODE(sta, mode) do {} while (0)
655 #endif
656 
657 #define AID_BMP_LEN(max_aid) ((max_aid + 1) / 8 + (((max_aid + 1) % 8) ? 1 : 0))
658 
659 struct	sta_priv {
660 
661 	u8 *pallocated_stainfo_buf;
662 	u8 *pstainfo_buf;
663 	_queue	free_sta_queue;
664 
665 	_lock sta_hash_lock;
666 	_list   sta_hash[NUM_STA];
667 	int asoc_sta_count;
668 	_queue sleep_q;
669 	_queue wakeup_q;
670 
671 	_adapter *padapter;
672 
673 	u32 adhoc_expire_to;
674 
675 	int rx_chk_limit;
676 
677 #ifdef CONFIG_AP_MODE
678 	_list asoc_list;
679 	_list auth_list;
680 	_lock asoc_list_lock;
681 	_lock auth_list_lock;
682 	u8 asoc_list_cnt;
683 	u8 auth_list_cnt;
684 
685 	unsigned int auth_to;  /* sec, time to expire in authenticating. */
686 	unsigned int assoc_to; /* sec, time to expire before associating. */
687 	unsigned int expire_to; /* sec , time to expire after associated. */
688 
689 	/*
690 	* pointers to STA info; based on allocated AID or NULL if AID free
691 	* AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
692 	*/
693 	struct sta_info **sta_aid;
694 	u16 max_aid;
695 	u16 started_aid; /* started AID for allocation search */
696 	bool rr_aid; /* round robin AID allocation, will modify started_aid */
697 	u8 aid_bmp_len; /* in byte */
698 	u8 *sta_dz_bitmap;
699 	u8 *tim_bitmap;
700 
701 	u16 max_num_sta;
702 
703 #if CONFIG_RTW_MACADDR_ACL
704 	struct wlan_acl_pool acl_list[RTW_ACL_PERIOD_NUM];
705 #endif
706 
707 	#if CONFIG_RTW_PRE_LINK_STA
708 	struct pre_link_sta_ctl_t pre_link_sta_ctl;
709 	#endif
710 #ifdef CONFIG_RTW_TOKEN_BASED_XMIT
711 	u8 tbtx_asoc_list_cnt;
712 	struct sta_info *token_holder[NR_MAXSTA_INSLOT];
713 	struct sta_info *last_token_holder;
714 	ATOMIC_T nr_token_keeper;
715 #endif
716 #endif /* CONFIG_AP_MODE */
717 
718 #ifdef CONFIG_ATMEL_RC_PATCH
719 	u8 atmel_rc_pattern[6];
720 #endif
721 	u8 c2h_sta_mac[ETH_ALEN];
722 	u8 c2h_adapter_id;
723 	struct submit_ctx *gotc2h;
724 };
725 
726 
wifi_mac_hash(const u8 * mac)727 __inline static u32 wifi_mac_hash(const u8 *mac)
728 {
729 	u32 x;
730 
731 	x = mac[0];
732 	x = (x << 2) ^ mac[1];
733 	x = (x << 2) ^ mac[2];
734 	x = (x << 2) ^ mac[3];
735 	x = (x << 2) ^ mac[4];
736 	x = (x << 2) ^ mac[5];
737 
738 	x ^= x >> 8;
739 	x  = x & (NUM_STA - 1);
740 
741 	return x;
742 }
743 
744 
745 extern u32	_rtw_init_sta_priv(struct sta_priv *pstapriv);
746 extern u32	_rtw_free_sta_priv(struct sta_priv *pstapriv);
747 
748 #define stainfo_offset_valid(offset) (offset < NUM_STA && offset >= 0)
749 int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta);
750 struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset);
751 
752 extern struct sta_info *rtw_alloc_stainfo(struct	sta_priv *pstapriv, const u8 *hwaddr);
753 extern u32	rtw_free_stainfo(_adapter *padapter , struct sta_info *psta);
754 extern void rtw_free_all_stainfo(_adapter *padapter);
755 extern struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr);
756 extern u32 rtw_init_bcmc_stainfo(_adapter *padapter);
757 extern struct sta_info *rtw_get_bcmc_stainfo(_adapter *padapter);
758 
759 #ifdef CONFIG_AP_MODE
760 u16 rtw_aid_alloc(_adapter *adapter, struct sta_info *sta);
761 void dump_aid_status(void *sel, _adapter *adapter);
762 #endif
763 
764 #if CONFIG_RTW_MACADDR_ACL
765 extern u8 rtw_access_ctrl(_adapter *adapter, const u8 *mac_addr);
766 void dump_macaddr_acl(void *sel, _adapter *adapter);
767 #endif
768 
769 bool rtw_is_pre_link_sta(struct sta_priv *stapriv, u8 *addr);
770 #if CONFIG_RTW_PRE_LINK_STA
771 struct sta_info *rtw_pre_link_sta_add(struct sta_priv *stapriv, u8 *hwaddr);
772 void rtw_pre_link_sta_del(struct sta_priv *stapriv, u8 *hwaddr);
773 void rtw_pre_link_sta_ctl_reset(struct sta_priv *stapriv);
774 void rtw_pre_link_sta_ctl_init(struct sta_priv *stapriv);
775 void rtw_pre_link_sta_ctl_deinit(struct sta_priv *stapriv);
776 void dump_pre_link_sta_ctl(void *sel, struct sta_priv *stapriv);
777 #endif /* CONFIG_RTW_PRE_LINK_STA */
778 
779 #endif /* _STA_INFO_H_ */
780