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