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