1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
24 #define IBSS_START_MAC_ID 2
25 #define NUM_STA MACID_NUM_SW_LIMIT
27 #ifndef CONFIG_RTW_MACADDR_ACL
28 #define CONFIG_RTW_MACADDR_ACL 1
31 #ifndef CONFIG_RTW_PRE_LINK_STA
32 #define CONFIG_RTW_PRE_LINK_STA 0
36 #define RTW_ACL_MODE_DISABLED 0
37 #define RTW_ACL_MODE_ACCEPT_UNLESS_LISTED 1
38 #define RTW_ACL_MODE_DENY_UNLESS_LISTED 2
39 #define RTW_ACL_MODE_MAX 3
41 #if CONFIG_RTW_MACADDR_ACL
42 extern const char *const _acl_mode_str[];
43 #define acl_mode_str(mode) (((mode) >= RTW_ACL_MODE_MAX) ? _acl_mode_str[RTW_ACL_MODE_DISABLED] : _acl_mode_str[(mode)])
46 #ifndef RTW_PRE_LINK_STA_NUM
47 #define RTW_PRE_LINK_STA_NUM 8
50 struct pre_link_sta_node_t {
55 struct pre_link_sta_ctl_t {
58 struct pre_link_sta_node_t node[RTW_PRE_LINK_STA_NUM];
62 #define MAX_ALLOWED_TDLS_STA_NUM 4
65 enum sta_info_update_type {
66 STA_INFO_UPDATE_NONE = 0,
67 STA_INFO_UPDATE_BW = BIT(0),
68 STA_INFO_UPDATE_RATE = BIT(1),
69 STA_INFO_UPDATE_PROTECTION_MODE = BIT(2),
70 STA_INFO_UPDATE_CAP = BIT(3),
71 STA_INFO_UPDATE_HT_CAP = BIT(4),
72 STA_INFO_UPDATE_VHT_CAP = BIT(5),
73 STA_INFO_UPDATE_ALL = STA_INFO_UPDATE_BW
74 | STA_INFO_UPDATE_RATE
75 | STA_INFO_UPDATE_PROTECTION_MODE
77 | STA_INFO_UPDATE_HT_CAP
78 | STA_INFO_UPDATE_VHT_CAP,
82 struct rtw_wlan_acl_node {
88 struct wlan_acl_pool {
91 struct rtw_wlan_acl_node aclnode[NUM_ACL];
95 typedef struct _RSSI_STA {
97 s32 undecorated_smoothed_pwdb;
98 s32 undecorated_smoothed_cck;
99 s32 undecorated_smoothed_ofdm;
106 } RSSI_STA, *PRSSI_STA;
108 struct stainfo_stats {
112 u64 rx_probereq_pkts;
113 u64 rx_probersp_pkts;
114 u64 rx_probersp_bm_pkts;
115 u64 rx_probersp_uo_pkts;
118 u64 rx_data_last_pkts; /* For Read & Clear requirement in proc_get_rx_stat() */
119 u64 rx_data_qos_pkts[TID_NUM];
120 u64 last_rx_mgnt_pkts;
121 u64 last_rx_beacon_pkts;
122 u64 last_rx_probereq_pkts;
123 u64 last_rx_probersp_pkts;
124 u64 last_rx_probersp_bm_pkts;
125 u64 last_rx_probersp_uo_pkts;
126 u64 last_rx_ctrl_pkts;
127 u64 last_rx_data_pkts;
128 u64 last_rx_data_qos_pkts[TID_NUM];
130 u64 rx_tdls_disc_rsp_pkts;
131 u64 last_rx_tdls_disc_rsp_pkts;
140 u32 duplicate_cnt; /* Read & Clear, in proc_get_rx_stat() */
141 u32 rxratecnt[128]; /* Read & Clear, in proc_get_rx_stat() */
142 u32 tx_ok_cnt; /* Read & Clear, in proc_get_tx_stat() */
143 u32 tx_fail_cnt; /* Read & Clear, in proc_get_tx_stat() */
144 u32 tx_retry_cnt; /* Read & Clear, in proc_get_tx_stat() */
147 #ifndef DBG_SESSION_TRACKER
148 #define DBG_SESSION_TRACKER 0
151 /* session tracker status */
152 #define ST_STATUS_NONE 0
153 #define ST_STATUS_CHECK BIT0
154 #define ST_STATUS_ESTABLISH BIT1
155 #define ST_STATUS_EXPIRE BIT2
157 #define ST_EXPIRE_MS (10 * 1000)
159 struct session_tracker {
160 _list list; /* session_tracker_queue */
169 /* session tracker cmd */
176 struct sta_info *sta;
177 u32 local_naddr; /* TODO: IPV6 */
179 u32 remote_naddr; /* TODO: IPV6 */
183 typedef bool (*st_match_rule)(_adapter *adapter, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port);
190 #define SESSION_TRACKER_REG_ID_WFD 0
191 #define SESSION_TRACKER_REG_ID_NUM 1
194 struct st_register reg[SESSION_TRACKER_REG_ID_NUM];
198 void rtw_st_ctl_init(struct st_ctl_t *st_ctl);
199 void rtw_st_ctl_deinit(struct st_ctl_t *st_ctl);
200 void rtw_st_ctl_register(struct st_ctl_t *st_ctl, u8 st_reg_id, struct st_register *reg);
201 void rtw_st_ctl_unregister(struct st_ctl_t *st_ctl, u8 st_reg_id);
202 bool rtw_st_ctl_chk_reg_s_proto(struct st_ctl_t *st_ctl, u8 s_proto);
203 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);
204 void dump_st_ctl(void *sel, struct st_ctl_t *st_ctl);
207 struct TDLS_PeerKey {
208 u8 kck[16]; /* TPK-KCK */
209 u8 tk[16]; /* TPK-TK; only CCMP will be used */
211 #endif /* CONFIG_TDLS */
213 #ifdef DBG_RX_DFRAME_RAW_DATA
214 struct sta_recv_dframe_info {
219 s8 sta_mimo_signal_strength[4];
228 _list list; /* free_sta_queue */
229 _list hash_list; /* sta_hash */
230 /* _list asoc_list; */ /* 20061114 */
231 /* _list sleep_list; */ /* sleep_q */
232 /* _list wakeup_list; */ /* wakeup_q */
235 struct sta_xmit_priv sta_xmitpriv;
236 struct sta_recv_priv sta_recvpriv;
238 #ifdef DBG_RX_DFRAME_RAW_DATA
239 struct sta_recv_dframe_info sta_dframe_info;
242 unsigned int sleepq_len;
252 uint ieee8021x_blocked; /* 0: allowed, 1:blocked */
253 uint dot118021XPrivacy; /* aes, tkip... */
254 union Keytype dot11tkiptxmickey;
255 union Keytype dot11tkiprxmickey;
256 union Keytype dot118021x_UncstKey;
257 union pn48 dot11txpn; /* PN48 used for Unicast xmit */
261 u8 replay_ctr[RTW_REPLAY_CTR_LEN];
262 #endif /* CONFIG_GTK_OL */
263 #ifdef CONFIG_IEEE80211W
264 union pn48 dot11wtxpn; /* PN48 used for Unicast mgmt xmit. */
265 _timer dot11w_expire_timer;
266 #endif /* CONFIG_IEEE80211W */
267 union pn48 dot11rxpn; /* PN48 used for Unicast recv. */
281 u8 wireless_mode; /* NETWORK_TYPE */
287 #ifdef CONFIG_BEAMFORMING
292 struct stainfo_stats sta_stats;
298 u32 TDLS_PeerKey_Lifetime;
301 struct TDLS_PeerKey tpk;
302 #ifdef CONFIG_TDLS_CH_SW
304 u16 ch_switch_timeout;
308 _timer stay_on_base_chnl_timer;
309 _timer ch_sw_monitor_timer;
311 _timer handshake_timer;
314 u8 TDLS_RSNIE[20]; /* Save peer's RSNIE, used for sending TDLS_SETUP_RSP */
315 #endif /* CONFIG_TDLS */
317 /* for A-MPDU TX, ADDBA timeout check */
318 _timer addba_retry_timer;
320 /* for A-MPDU Rx reordering buffer control */
321 struct recv_reorder_ctrl recvreorder_ctrl[TID_NUM];
322 ATOMIC_T continual_no_rx_packet[TID_NUM];
324 /* unsigned char ampdu_txen_bitmap; */
325 u16 BA_starting_seqctrl[16];
328 #ifdef CONFIG_80211N_HT
329 struct ht_priv htpriv;
332 #ifdef CONFIG_80211AC_VHT
333 struct vht_priv vhtpriv;
338 /* curr_network(mlme_priv/security_priv/qos/ht) + sta_info: (STA & AP) CAP/INFO */
339 /* scan_q: AP CAP/INFO */
342 /* curr_network(mlme_priv/security_priv/qos/ht) : AP CAP/INFO */
343 /* sta_info: (AP & STA) CAP/INFO */
345 unsigned int expire_to;
347 #ifdef CONFIG_AP_MODE
352 unsigned int auth_seq;
353 unsigned int authalg;
354 unsigned char chg_txt[128];
359 int dot8021xalg;/* 0:disable, 1:psk, 2:802.1x */
360 int wpa_psk;/* 0:disable, bit(0): WPA, bit(1):WPA2 */
361 int wpa_group_cipher;
362 int wpa2_group_cipher;
363 int wpa_pairwise_cipher;
364 int wpa2_pairwise_cipher;
366 u8 bpairwise_key_installed;
367 #ifdef CONFIG_RTW_80211R
368 u8 ft_pairwise_key_installed;
371 #ifdef CONFIG_NATIVEAP_MLME
375 u8 no_short_slot_time_set;
376 u8 no_short_preamble_set;
380 u8 ht_40mhz_intolerant;
381 #endif /* CONFIG_NATIVEAP_MLME */
383 #ifdef CONFIG_ATMEL_RC_PATCH
390 u8 uapsd_bk;/* BIT(0): Delivery enabled, BIT(1): Trigger enabled */
396 unsigned int sleepq_ac_len;
403 /* p2p client info */
404 u8 dev_addr[ETH_ALEN];
405 /* u8 iface_addr[ETH_ALEN]; */ /* = hwaddr[ETH_ALEN] */
408 u8 primary_dev_type[8];
409 u8 num_of_secdev_type;
410 u8 secdev_types_list[32];/* 32/8 == 4; */
413 #endif /* CONFIG_P2P */
419 #ifdef CONFIG_TX_MCAST2UNI
420 u8 under_exist_checking;
421 #endif /* CONFIG_TX_MCAST2UNI */
423 u8 keep_alive_trycnt;
425 #ifdef CONFIG_AUTO_AP_MODE
426 u8 isrc; /* this device is rc */
427 u16 pid; /* pairing id */
430 #endif /* CONFIG_AP_MODE */
432 #ifdef CONFIG_IOCTL_CFG80211
441 /* ================ODM Relative Info======================= */
442 /* Please be care, dont declare too much structure here. It will cost memory * STA support num. */
445 /* 2011/10/20 MH Add for ODM STA info. */
448 u8 bValid; /* record the sta status link or not? */
449 /* u8 WirelessMode; */ /* */
450 u8 IOTPeer; /* Enum value. HT_IOT_PEER_E */
452 /* 1 PHY_STATUS_INFO */
453 u8 RSSI_Path[4]; /* */
458 u8 rssi_level; /* for Refresh RA mask */
460 /* 1 TX_INFO (may changed by IC) */
461 /* TX_INFO_T pTxInfo; */ /* Define in IC folder. Move lower layer. */
463 /* ================ODM Relative Info======================= */
466 /* To store the sequence number of received management frame */
467 u16 RxMgmtFrameSeqNum;
469 struct st_ctl_t st_ctl;
472 #define sta_rx_pkts(sta) \
473 (sta->sta_stats.rx_mgnt_pkts \
474 + sta->sta_stats.rx_ctrl_pkts \
475 + sta->sta_stats.rx_data_pkts)
477 #define sta_last_rx_pkts(sta) \
478 (sta->sta_stats.last_rx_mgnt_pkts \
479 + sta->sta_stats.last_rx_ctrl_pkts \
480 + sta->sta_stats.last_rx_data_pkts)
482 #define sta_rx_data_pkts(sta) \
483 (sta->sta_stats.rx_data_pkts)
485 #define sta_rx_data_qos_pkts(sta, i) \
486 (sta->sta_stats.rx_data_qos_pkts[i])
488 #define sta_last_rx_data_pkts(sta) \
489 (sta->sta_stats.last_rx_data_pkts)
491 #define sta_last_rx_data_qos_pkts(sta, i) \
492 (sta->sta_stats.last_rx_data_qos_pkts[i])
494 #define sta_rx_mgnt_pkts(sta) \
495 (sta->sta_stats.rx_mgnt_pkts)
497 #define sta_last_rx_mgnt_pkts(sta) \
498 (sta->sta_stats.last_rx_mgnt_pkts)
500 #define sta_rx_beacon_pkts(sta) \
501 (sta->sta_stats.rx_beacon_pkts)
503 #define sta_last_rx_beacon_pkts(sta) \
504 (sta->sta_stats.last_rx_beacon_pkts)
506 #define sta_rx_probereq_pkts(sta) \
507 (sta->sta_stats.rx_probereq_pkts)
509 #define sta_last_rx_probereq_pkts(sta) \
510 (sta->sta_stats.last_rx_probereq_pkts)
512 #define sta_rx_probersp_pkts(sta) \
513 (sta->sta_stats.rx_probersp_pkts)
515 #define sta_last_rx_probersp_pkts(sta) \
516 (sta->sta_stats.last_rx_probersp_pkts)
518 #define sta_rx_probersp_bm_pkts(sta) \
519 (sta->sta_stats.rx_probersp_bm_pkts)
521 #define sta_last_rx_probersp_bm_pkts(sta) \
522 (sta->sta_stats.last_rx_probersp_bm_pkts)
524 #define sta_rx_probersp_uo_pkts(sta) \
525 (sta->sta_stats.rx_probersp_uo_pkts)
527 #define sta_last_rx_probersp_uo_pkts(sta) \
528 (sta->sta_stats.last_rx_probersp_uo_pkts)
530 #define sta_update_last_rx_pkts(sta) \
532 sta->sta_stats.last_rx_mgnt_pkts = sta->sta_stats.rx_mgnt_pkts; \
533 sta->sta_stats.last_rx_beacon_pkts = sta->sta_stats.rx_beacon_pkts; \
534 sta->sta_stats.last_rx_probereq_pkts = sta->sta_stats.rx_probereq_pkts; \
535 sta->sta_stats.last_rx_probersp_pkts = sta->sta_stats.rx_probersp_pkts; \
536 sta->sta_stats.last_rx_probersp_bm_pkts = sta->sta_stats.rx_probersp_bm_pkts; \
537 sta->sta_stats.last_rx_probersp_uo_pkts = sta->sta_stats.rx_probersp_uo_pkts; \
538 sta->sta_stats.last_rx_ctrl_pkts = sta->sta_stats.rx_ctrl_pkts; \
539 sta->sta_stats.last_rx_data_pkts = sta->sta_stats.rx_data_pkts; \
542 #define STA_RX_PKTS_ARG(sta) \
543 sta->sta_stats.rx_mgnt_pkts \
544 , sta->sta_stats.rx_ctrl_pkts \
545 , sta->sta_stats.rx_data_pkts
547 #define STA_LAST_RX_PKTS_ARG(sta) \
548 sta->sta_stats.last_rx_mgnt_pkts \
549 , sta->sta_stats.last_rx_ctrl_pkts \
550 , sta->sta_stats.last_rx_data_pkts
552 #define STA_RX_PKTS_DIFF_ARG(sta) \
553 sta->sta_stats.rx_mgnt_pkts - sta->sta_stats.last_rx_mgnt_pkts \
554 , sta->sta_stats.rx_ctrl_pkts - sta->sta_stats.last_rx_ctrl_pkts \
555 , sta->sta_stats.rx_data_pkts - sta->sta_stats.last_rx_data_pkts
557 #define STA_PKTS_FMT "(m:%llu, c:%llu, d:%llu)"
560 #define STA_OP_WFD_MODE(sta) (sta)->op_wfd_mode
561 #define STA_SET_OP_WFD_MODE(sta, mode) (sta)->op_wfd_mode = (mode)
563 #define STA_OP_WFD_MODE(sta) 0
564 #define STA_SET_OP_WFD_MODE(sta, mode) do {} while (0)
569 u8 *pallocated_stainfo_buf;
571 _queue free_sta_queue;
574 _list sta_hash[NUM_STA];
583 #ifdef CONFIG_AP_MODE
586 _lock asoc_list_lock;
587 _lock auth_list_lock;
591 unsigned int auth_to; /* sec, time to expire in authenticating. */
592 unsigned int assoc_to; /* sec, time to expire before associating. */
593 unsigned int expire_to; /* sec , time to expire after associated. */
595 /* pointers to STA info; based on allocated AID or NULL if AID free
596 * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
599 struct sta_info *sta_aid[NUM_STA];
601 u16 sta_dz_bitmap;/* only support 15 stations, staion aid bitmap for sleeping sta. */
602 u16 tim_bitmap;/* only support 15 stations, aid=0~15 mapping bit0~bit15 */
606 #if CONFIG_RTW_MACADDR_ACL
607 struct wlan_acl_pool acl_list;
610 #if CONFIG_RTW_PRE_LINK_STA
611 struct pre_link_sta_ctl_t pre_link_sta_ctl;
614 #endif /* CONFIG_AP_MODE */
616 #ifdef CONFIG_ATMEL_RC_PATCH
617 u8 atmel_rc_pattern[6];
619 struct sta_info *c2h_sta;
620 struct submit_ctx *gotc2h;
624 __inline static u32 wifi_mac_hash(u8 *mac)
629 x = (x << 2) ^ mac[1];
630 x = (x << 2) ^ mac[2];
631 x = (x << 2) ^ mac[3];
632 x = (x << 2) ^ mac[4];
633 x = (x << 2) ^ mac[5];
636 x = x & (NUM_STA - 1);
642 extern u32 _rtw_init_sta_priv(struct sta_priv *pstapriv);
643 extern u32 _rtw_free_sta_priv(struct sta_priv *pstapriv);
645 #define stainfo_offset_valid(offset) (offset < NUM_STA && offset >= 0)
646 int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta);
647 struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset);
649 extern struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, u8 *hwaddr);
650 extern u32 rtw_free_stainfo(_adapter *padapter , struct sta_info *psta);
651 extern void rtw_free_all_stainfo(_adapter *padapter);
652 extern struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr);
653 extern u32 rtw_init_bcmc_stainfo(_adapter *padapter);
654 extern struct sta_info *rtw_get_bcmc_stainfo(_adapter *padapter);
656 #if CONFIG_RTW_MACADDR_ACL
657 extern u8 rtw_access_ctrl(_adapter *adapter, u8 *mac_addr);
658 void dump_macaddr_acl(void *sel, _adapter *adapter);
661 bool rtw_is_pre_link_sta(struct sta_priv *stapriv, u8 *addr);
662 #if CONFIG_RTW_PRE_LINK_STA
663 struct sta_info *rtw_pre_link_sta_add(struct sta_priv *stapriv, u8 *hwaddr);
664 void rtw_pre_link_sta_del(struct sta_priv *stapriv, u8 *hwaddr);
665 void rtw_pre_link_sta_ctl_reset(struct sta_priv *stapriv);
666 void rtw_pre_link_sta_ctl_init(struct sta_priv *stapriv);
667 void rtw_pre_link_sta_ctl_deinit(struct sta_priv *stapriv);
668 void dump_pre_link_sta_ctl(void *sel, struct sta_priv *stapriv);
669 #endif /* CONFIG_RTW_PRE_LINK_STA */
671 #endif /* _STA_INFO_H_ */