xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8723cs/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 #ifdef CONFIG_RTW_MGMT_QUEUE
286 	_queue mgmt_sleep_q;
287 	unsigned int mgmt_sleepq_len;
288 #endif
289 
290 	uint state;
291 	uint qos_option;
292 	u16 hwseq;
293 
294 #ifdef CONFIG_RTW_80211K
295 	u8 rm_en_cap[5];
296 	u8 rm_diag_token;
297 #endif /* CONFIG_RTW_80211K */
298 
299 	systime	resp_nonenc_eapol_key_starttime;
300 	uint	ieee8021x_blocked;	/* 0: allowed, 1:blocked */
301 	uint	dot118021XPrivacy; /* aes, tkip... */
302 	union Keytype	dot11tkiptxmickey;
303 	union Keytype	dot11tkiprxmickey;
304 	union Keytype	dot118021x_UncstKey;
305 	union pn48		dot11txpn;			/* PN48 used for Unicast xmit */
306 	union pn48		dot11rxpn;			/* PN48 used for Unicast recv. */
307 #ifdef CONFIG_RTW_MESH
308 	/* peer's GTK, RX only */
309 	u8 group_privacy;
310 	u8 gtk_bmp;
311 	union Keytype gtk;
312 	union pn48 gtk_pn;
313 	#ifdef CONFIG_IEEE80211W
314 	/* peer's IGTK, RX only */
315 	enum security_type dot11wCipher;
316 	u8 igtk_bmp;
317 	u8 igtk_id;
318 	union Keytype igtk;
319 	union pn48 igtk_pn;
320 	#endif /* CONFIG_IEEE80211W */
321 #endif /* CONFIG_RTW_MESH */
322 #ifdef CONFIG_GTK_OL
323 	u8 kek[RTW_KEK_LEN];
324 	u8 kck[RTW_KCK_LEN];
325 	u8 replay_ctr[RTW_REPLAY_CTR_LEN];
326 #endif /* CONFIG_GTK_OL */
327 #ifdef CONFIG_IEEE80211W
328 	_timer dot11w_expire_timer;
329 #endif /* CONFIG_IEEE80211W */
330 
331 	u8	bssrateset[16];
332 	u32	bssratelen;
333 
334 	u8	cts2self;
335 	u8	rtsen;
336 
337 	u8	init_rate;
338 	u8	wireless_mode;	/* NETWORK_TYPE */
339 
340 	struct stainfo_stats sta_stats;
341 
342 #ifdef CONFIG_TDLS
343 	u32	tdls_sta_state;
344 	u8	SNonce[32];
345 	u8	ANonce[32];
346 	u32	TDLS_PeerKey_Lifetime;
347 	u32	TPK_count;
348 	_timer	TPK_timer;
349 	struct TDLS_PeerKey	tpk;
350 #ifdef CONFIG_TDLS_CH_SW
351 	u16	ch_switch_time;
352 	u16	ch_switch_timeout;
353 	/* u8	option; */
354 	_timer	ch_sw_timer;
355 	_timer	delay_timer;
356 	_timer	stay_on_base_chnl_timer;
357 	_timer	ch_sw_monitor_timer;
358 #endif
359 	_timer handshake_timer;
360 	u8 alive_count;
361 	_timer	pti_timer;
362 	u8	TDLS_RSNIE[20];	/* Save peer's RSNIE, used for sending TDLS_SETUP_RSP */
363 #endif /* CONFIG_TDLS */
364 
365 	/* for A-MPDU TX, ADDBA timeout check	 */
366 	_timer addba_retry_timer;
367 
368 	/* for A-MPDU Rx reordering buffer control */
369 	struct recv_reorder_ctrl recvreorder_ctrl[TID_NUM];
370 	ATOMIC_T continual_no_rx_packet[TID_NUM];
371 	/* for A-MPDU Tx */
372 	/* unsigned char		ampdu_txen_bitmap; */
373 	u16	BA_starting_seqctrl[16];
374 
375 
376 #ifdef CONFIG_80211N_HT
377 	struct ht_priv	htpriv;
378 #endif
379 
380 #ifdef CONFIG_80211AC_VHT
381 	struct vht_priv	vhtpriv;
382 #endif
383 
384 	/* Notes:	 */
385 	/* STA_Mode: */
386 	/* curr_network(mlme_priv/security_priv/qos/ht) + sta_info: (STA & AP) CAP/INFO	 */
387 	/* scan_q: AP CAP/INFO */
388 
389 	/* AP_Mode: */
390 	/* curr_network(mlme_priv/security_priv/qos/ht) : AP CAP/INFO */
391 	/* sta_info: (AP & STA) CAP/INFO */
392 
393 	unsigned int expire_to;
394 
395 	int flags;
396 
397 	u8 bpairwise_key_installed;
398 
399 #ifdef CONFIG_AP_MODE
400 
401 	_list asoc_list;
402 	_list auth_list;
403 
404 	unsigned int auth_seq;
405 	unsigned int authalg;
406 	unsigned char chg_txt[128];
407 
408 	u16 capability;
409 
410 	int dot8021xalg;/* 0:disable, 1:psk, 2:802.1x */
411 	int wpa_psk;/* 0:disable, bit(0): WPA, bit(1):WPA2 */
412 	int wpa_group_cipher;
413 	int wpa2_group_cipher;
414 	int wpa_pairwise_cipher;
415 	int wpa2_pairwise_cipher;
416 
417 	u32 akm_suite_type;
418 
419 #ifdef CONFIG_RTW_80211R
420 	u8 ft_pairwise_key_installed;
421 #endif
422 
423 #ifdef CONFIG_NATIVEAP_MLME
424 	u8 wpa_ie[32];
425 
426 	u8 nonerp_set;
427 	u8 no_short_slot_time_set;
428 	u8 no_short_preamble_set;
429 	u8 no_ht_gf_set;
430 	u8 no_ht_set;
431 	u8 ht_20mhz_set;
432 	u8 ht_40mhz_intolerant;
433 #endif /* CONFIG_NATIVEAP_MLME */
434 
435 #ifdef CONFIG_ATMEL_RC_PATCH
436 	u8 flag_atmel_rc;
437 #endif
438 
439 	u8 qos_info;
440 
441 	u8 max_sp_len;
442 	u8 uapsd_bk;/* BIT(0): Delivery enabled, BIT(1): Trigger enabled */
443 	u8 uapsd_be;
444 	u8 uapsd_vi;
445 	u8 uapsd_vo;
446 
447 	u8 has_legacy_ac;
448 	unsigned int sleepq_ac_len;
449 
450 #ifdef CONFIG_P2P
451 	/* p2p priv data */
452 	u8 is_p2p_device;
453 	u8 p2p_status_code;
454 
455 	/* p2p client info */
456 	u8 dev_addr[ETH_ALEN];
457 	/* u8 iface_addr[ETH_ALEN]; */ /* = hwaddr[ETH_ALEN] */
458 	u8 dev_cap;
459 	u16 config_methods;
460 	u8 primary_dev_type[8];
461 	u8 num_of_secdev_type;
462 	u8 secdev_types_list[32];/* 32/8 == 4; */
463 	u16 dev_name_len;
464 	u8 dev_name[32];
465 #endif /* CONFIG_P2P */
466 
467 #ifdef CONFIG_WFD
468 	u8 op_wfd_mode;
469 #endif
470 
471 #if !defined(CONFIG_ACTIVE_KEEP_ALIVE_CHECK) && defined(CONFIG_80211N_HT)
472 	u8 under_exist_checking;
473 #endif
474 
475 	u8 keep_alive_trycnt;
476 
477 #ifdef CONFIG_AUTO_AP_MODE
478 	u8 isrc; /* this device is rc */
479 	u16 pid; /* pairing id */
480 #endif
481 
482 #endif /* CONFIG_AP_MODE	 */
483 
484 #ifdef CONFIG_RTW_MESH
485 	struct mesh_plink_ent *plink;
486 
487 	u8 local_mps;
488 	u8 peer_mps;
489 	u8 nonpeer_mps;
490 
491 	struct rtw_atlm_param metrics;
492 	/* The reference for nexthop_lookup */
493 	BOOLEAN alive;
494 #endif
495 
496 #ifdef CONFIG_IOCTL_CFG80211
497 	u8 *pauth_frame;
498 	u32 auth_len;
499 	u8 *passoc_req;
500 	u32 assoc_req_len;
501 #endif
502 
503 	u8		IOTPeer;			/* Enum value.	HT_IOT_PEER_E */
504 #ifdef CONFIG_LPS_PG
505 	u8		lps_pg_rssi_lv;
506 #endif
507 
508 	/* To store the sequence number of received management frame */
509 	u16 RxMgmtFrameSeqNum;
510 
511 	struct st_ctl_t st_ctl;
512 	u8 max_agg_num_minimal_record; /*keep minimal tx desc max_agg_num setting*/
513 	u8 curr_rx_rate;
514 	u8 curr_rx_rate_bmc;
515 #ifdef CONFIG_RTS_FULL_BW
516 	bool vendor_8812;
517 #endif
518 
519 #ifdef CONFIG_RTW_TOKEN_BASED_XMIT
520 	u8 tbtx_enable;			/* Does this sta_info support & enable TBTX function? */
521 //	u8 tbtx_timeslot;		/* This sta_info belong to which time slot.	*/
522 #endif
523 
524 	/*
525 	 * Vaiables for queuing TX pkt a short period of time
526 	 * to wait something ready.
527 	 */
528 	u8 tx_q_enable;
529 	struct __queue tx_queue;
530 	_workitem tx_q_work;
531 };
532 
533 #ifdef CONFIG_RTW_MESH
534 #define STA_SET_MESH_PLINK(sta, link) (sta)->plink = link
535 #else
536 #define STA_SET_MESH_PLINK(sta, link) do {} while (0)
537 #endif
538 
539 #define sta_tx_pkts(sta) \
540 	(sta->sta_stats.tx_pkts)
541 
542 #define sta_last_tx_pkts(sta) \
543 	(sta->sta_stats.last_tx_pkts)
544 
545 #define sta_rx_pkts(sta) \
546 	(sta->sta_stats.rx_mgnt_pkts \
547 	 + sta->sta_stats.rx_ctrl_pkts \
548 	 + sta->sta_stats.rx_data_pkts)
549 
550 #define sta_last_rx_pkts(sta) \
551 	(sta->sta_stats.last_rx_mgnt_pkts \
552 	 + sta->sta_stats.last_rx_ctrl_pkts \
553 	 + sta->sta_stats.last_rx_data_pkts)
554 
555 #define sta_rx_data_pkts(sta) (sta->sta_stats.rx_data_pkts)
556 #define sta_last_rx_data_pkts(sta) (sta->sta_stats.last_rx_data_pkts)
557 
558 #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)
559 #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)
560 
561 #define sta_rx_data_qos_pkts(sta, i) \
562 	(sta->sta_stats.rx_data_qos_pkts[i])
563 
564 #define sta_last_rx_data_qos_pkts(sta, i) \
565 	(sta->sta_stats.last_rx_data_qos_pkts[i])
566 
567 #define sta_rx_mgnt_pkts(sta) \
568 	(sta->sta_stats.rx_mgnt_pkts)
569 
570 #define sta_last_rx_mgnt_pkts(sta) \
571 	(sta->sta_stats.last_rx_mgnt_pkts)
572 
573 #define sta_rx_beacon_pkts(sta) \
574 	(sta->sta_stats.rx_beacon_pkts)
575 
576 #define sta_last_rx_beacon_pkts(sta) \
577 	(sta->sta_stats.last_rx_beacon_pkts)
578 
579 #define sta_rx_probereq_pkts(sta) \
580 	(sta->sta_stats.rx_probereq_pkts)
581 
582 #define sta_last_rx_probereq_pkts(sta) \
583 	(sta->sta_stats.last_rx_probereq_pkts)
584 
585 #define sta_rx_probersp_pkts(sta) \
586 	(sta->sta_stats.rx_probersp_pkts)
587 
588 #define sta_last_rx_probersp_pkts(sta) \
589 	(sta->sta_stats.last_rx_probersp_pkts)
590 
591 #define sta_rx_probersp_bm_pkts(sta) \
592 	(sta->sta_stats.rx_probersp_bm_pkts)
593 
594 #define sta_last_rx_probersp_bm_pkts(sta) \
595 	(sta->sta_stats.last_rx_probersp_bm_pkts)
596 
597 #define sta_rx_probersp_uo_pkts(sta) \
598 	(sta->sta_stats.rx_probersp_uo_pkts)
599 
600 #define sta_last_rx_probersp_uo_pkts(sta) \
601 	(sta->sta_stats.last_rx_probersp_uo_pkts)
602 
603 #ifdef CONFIG_RTW_MESH
604 #define update_last_rx_hwmp_pkts(sta) \
605 	do { \
606 		sta->sta_stats.last_rx_hwmp_pkts = sta->sta_stats.rx_hwmp_pkts; \
607 	} while(0)
608 #else
609 #define update_last_rx_hwmp_pkts(sta) do {} while(0)
610 #endif
611 
612 #define sta_update_last_rx_pkts(sta) \
613 	do { \
614 		int __i; \
615 		\
616 		sta->sta_stats.last_rx_mgnt_pkts = sta->sta_stats.rx_mgnt_pkts; \
617 		sta->sta_stats.last_rx_beacon_pkts = sta->sta_stats.rx_beacon_pkts; \
618 		sta->sta_stats.last_rx_probereq_pkts = sta->sta_stats.rx_probereq_pkts; \
619 		sta->sta_stats.last_rx_probersp_pkts = sta->sta_stats.rx_probersp_pkts; \
620 		sta->sta_stats.last_rx_probersp_bm_pkts = sta->sta_stats.rx_probersp_bm_pkts; \
621 		sta->sta_stats.last_rx_probersp_uo_pkts = sta->sta_stats.rx_probersp_uo_pkts; \
622 		sta->sta_stats.last_rx_ctrl_pkts = sta->sta_stats.rx_ctrl_pkts; \
623 		update_last_rx_hwmp_pkts(sta); \
624 		\
625 		sta->sta_stats.last_rx_data_pkts = sta->sta_stats.rx_data_pkts; \
626 		sta->sta_stats.last_rx_data_bc_pkts = sta->sta_stats.rx_data_bc_pkts; \
627 		sta->sta_stats.last_rx_data_mc_pkts = sta->sta_stats.rx_data_mc_pkts; \
628 		for (__i = 0; __i < TID_NUM; __i++) \
629 			sta->sta_stats.last_rx_data_qos_pkts[__i] = sta->sta_stats.rx_data_qos_pkts[__i]; \
630 	} while (0)
631 
632 #define STA_RX_PKTS_ARG(sta) \
633 	sta->sta_stats.rx_mgnt_pkts \
634 	, sta->sta_stats.rx_ctrl_pkts \
635 	, sta->sta_stats.rx_data_pkts
636 
637 #define STA_LAST_RX_PKTS_ARG(sta) \
638 	sta->sta_stats.last_rx_mgnt_pkts \
639 	, sta->sta_stats.last_rx_ctrl_pkts \
640 	, sta->sta_stats.last_rx_data_pkts
641 
642 #define STA_RX_PKTS_DIFF_ARG(sta) \
643 	sta->sta_stats.rx_mgnt_pkts - sta->sta_stats.last_rx_mgnt_pkts \
644 	, sta->sta_stats.rx_ctrl_pkts - sta->sta_stats.last_rx_ctrl_pkts \
645 	, sta->sta_stats.rx_data_pkts - sta->sta_stats.last_rx_data_pkts
646 
647 #define STA_PKTS_FMT "(m:%llu, c:%llu, d:%llu)"
648 
649 #define sta_rx_uc_bytes(sta) (sta->sta_stats.rx_bytes - sta->sta_stats.rx_bc_bytes - sta->sta_stats.rx_mc_bytes)
650 #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)
651 
652 #ifdef CONFIG_WFD
653 #define STA_OP_WFD_MODE(sta) (sta)->op_wfd_mode
654 #define STA_SET_OP_WFD_MODE(sta, mode) (sta)->op_wfd_mode = (mode)
655 #else
656 #define STA_OP_WFD_MODE(sta) 0
657 #define STA_SET_OP_WFD_MODE(sta, mode) do {} while (0)
658 #endif
659 
660 #define AID_BMP_LEN(max_aid) ((max_aid + 1) / 8 + (((max_aid + 1) % 8) ? 1 : 0))
661 
662 struct	sta_priv {
663 
664 	u8 *pallocated_stainfo_buf;
665 	u8 *pstainfo_buf;
666 	_queue	free_sta_queue;
667 
668 	_lock sta_hash_lock;
669 	_list   sta_hash[NUM_STA];
670 	int asoc_sta_count;
671 	_queue sleep_q;
672 	_queue wakeup_q;
673 
674 	_adapter *padapter;
675 
676 	u32 adhoc_expire_to;
677 
678 	int rx_chk_limit;
679 
680 #ifdef CONFIG_AP_MODE
681 	_list asoc_list;
682 	_list auth_list;
683 	_lock asoc_list_lock;
684 	_lock auth_list_lock;
685 	u8 asoc_list_cnt;
686 	u8 auth_list_cnt;
687 
688 	unsigned int auth_to;  /* sec, time to expire in authenticating. */
689 	unsigned int assoc_to; /* sec, time to expire before associating. */
690 	unsigned int expire_to; /* sec , time to expire after associated. */
691 
692 	/*
693 	* pointers to STA info; based on allocated AID or NULL if AID free
694 	* AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
695 	*/
696 	struct sta_info **sta_aid;
697 	u16 max_aid;
698 	u16 started_aid; /* started AID for allocation search */
699 	bool rr_aid; /* round robin AID allocation, will modify started_aid */
700 	u8 aid_bmp_len; /* in byte */
701 	u8 *sta_dz_bitmap;
702 	u8 *tim_bitmap;
703 
704 	u16 max_num_sta;
705 
706 #if CONFIG_RTW_MACADDR_ACL
707 	struct wlan_acl_pool acl_list[RTW_ACL_PERIOD_NUM];
708 #endif
709 
710 	#if CONFIG_RTW_PRE_LINK_STA
711 	struct pre_link_sta_ctl_t pre_link_sta_ctl;
712 	#endif
713 #ifdef CONFIG_RTW_TOKEN_BASED_XMIT
714 	u8 tbtx_asoc_list_cnt;
715 	struct sta_info *token_holder[NR_MAXSTA_INSLOT];
716 	struct sta_info *last_token_holder;
717 	ATOMIC_T nr_token_keeper;
718 #endif
719 #endif /* CONFIG_AP_MODE */
720 
721 #ifdef CONFIG_ATMEL_RC_PATCH
722 	u8 atmel_rc_pattern[6];
723 #endif
724 	u8 c2h_sta_mac[ETH_ALEN];
725 	u8 c2h_adapter_id;
726 	struct submit_ctx *gotc2h;
727 };
728 
729 
wifi_mac_hash(const u8 * mac)730 __inline static u32 wifi_mac_hash(const u8 *mac)
731 {
732 	u32 x;
733 
734 	x = mac[0];
735 	x = (x << 2) ^ mac[1];
736 	x = (x << 2) ^ mac[2];
737 	x = (x << 2) ^ mac[3];
738 	x = (x << 2) ^ mac[4];
739 	x = (x << 2) ^ mac[5];
740 
741 	x ^= x >> 8;
742 	x  = x & (NUM_STA - 1);
743 
744 	return x;
745 }
746 
747 
748 extern u32	_rtw_init_sta_priv(struct sta_priv *pstapriv);
749 extern u32	_rtw_free_sta_priv(struct sta_priv *pstapriv);
750 
751 #define stainfo_offset_valid(offset) (offset < NUM_STA && offset >= 0)
752 int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta);
753 struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset);
754 
755 extern struct sta_info *rtw_alloc_stainfo(struct	sta_priv *pstapriv, const u8 *hwaddr);
756 extern u32	rtw_free_stainfo(_adapter *padapter , struct sta_info *psta);
757 extern void rtw_free_all_stainfo(_adapter *padapter);
758 extern struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr);
759 extern u32 rtw_init_bcmc_stainfo(_adapter *padapter);
760 extern struct sta_info *rtw_get_bcmc_stainfo(_adapter *padapter);
761 
762 #ifdef CONFIG_AP_MODE
763 u16 rtw_aid_alloc(_adapter *adapter, struct sta_info *sta);
764 void dump_aid_status(void *sel, _adapter *adapter);
765 #endif
766 
767 #if CONFIG_RTW_MACADDR_ACL
768 extern u8 rtw_access_ctrl(_adapter *adapter, const u8 *mac_addr);
769 void dump_macaddr_acl(void *sel, _adapter *adapter);
770 #endif
771 
772 bool rtw_is_pre_link_sta(struct sta_priv *stapriv, u8 *addr);
773 #if CONFIG_RTW_PRE_LINK_STA
774 struct sta_info *rtw_pre_link_sta_add(struct sta_priv *stapriv, u8 *hwaddr);
775 void rtw_pre_link_sta_del(struct sta_priv *stapriv, u8 *hwaddr);
776 void rtw_pre_link_sta_ctl_reset(struct sta_priv *stapriv);
777 void rtw_pre_link_sta_ctl_init(struct sta_priv *stapriv);
778 void rtw_pre_link_sta_ctl_deinit(struct sta_priv *stapriv);
779 void dump_pre_link_sta_ctl(void *sel, struct sta_priv *stapriv);
780 #endif /* CONFIG_RTW_PRE_LINK_STA */
781 
782 #endif /* _STA_INFO_H_ */
783