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