OSDN Git Service

Add rtl8723bu driver version 4.4.5
[android-x86/external-kernel-drivers.git] / rtl8723bu / include / sta_info.h
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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  * 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
17  *
18  *
19  ******************************************************************************/
20 #ifndef __STA_INFO_H_
21 #define __STA_INFO_H_
22
23
24 #define IBSS_START_MAC_ID       2
25 #define NUM_STA MACID_NUM_SW_LIMIT
26 #define NUM_ACL 16
27
28 #ifdef CONFIG_TDLS
29 #define MAX_ALLOWED_TDLS_STA_NUM        4
30 #endif
31
32 enum sta_info_update_type {
33         STA_INFO_UPDATE_NONE = 0,
34         STA_INFO_UPDATE_BW = BIT(0),
35         STA_INFO_UPDATE_RATE = BIT(1),
36         STA_INFO_UPDATE_PROTECTION_MODE = BIT(2),
37         STA_INFO_UPDATE_CAP = BIT(3),
38         STA_INFO_UPDATE_HT_CAP = BIT(4),
39         STA_INFO_UPDATE_VHT_CAP = BIT(5),
40         STA_INFO_UPDATE_ALL = STA_INFO_UPDATE_BW
41                                                         |STA_INFO_UPDATE_RATE
42                                                         |STA_INFO_UPDATE_PROTECTION_MODE
43                                                         |STA_INFO_UPDATE_CAP
44                                                         |STA_INFO_UPDATE_HT_CAP
45                                                         |STA_INFO_UPDATE_VHT_CAP,
46         STA_INFO_UPDATE_MAX
47 };
48
49 //if mode ==0, then the sta is allowed once the addr is hit.
50 //if mode ==1, then the sta is rejected once the addr is non-hit.
51 struct rtw_wlan_acl_node {
52         _list                   list;
53         u8       addr[ETH_ALEN];
54         u8       valid;
55 };
56
57 //mode=0, disable
58 //mode=1, accept unless in deny list
59 //mode=2, deny unless in accept list
60 struct wlan_acl_pool {
61         int mode;
62         int num;
63         struct rtw_wlan_acl_node aclnode[NUM_ACL];
64         _queue  acl_node_q;
65 };
66
67 typedef struct _RSSI_STA{
68         s32     UndecoratedSmoothedPWDB;
69         s32     UndecoratedSmoothedCCK;
70         s32     UndecoratedSmoothedOFDM;
71         u32     OFDM_pkt;
72         u64     PacketMap;
73         u8      ValidBit;
74 }RSSI_STA, *PRSSI_STA;
75
76 struct  stainfo_stats   {
77
78         u64 rx_mgnt_pkts;
79                 u64 rx_beacon_pkts;
80                 u64 rx_probereq_pkts;
81                 u64 rx_probersp_pkts;
82                 u64 rx_probersp_bm_pkts;
83                 u64 rx_probersp_uo_pkts;
84         u64 rx_ctrl_pkts;
85         u64 rx_data_pkts;
86         u64 rx_data_qos_pkts[TID_NUM];
87         u64     last_rx_mgnt_pkts;
88                 u64 last_rx_beacon_pkts;
89                 u64 last_rx_probereq_pkts;
90                 u64 last_rx_probersp_pkts;
91                 u64 last_rx_probersp_bm_pkts;
92                 u64 last_rx_probersp_uo_pkts;
93         u64     last_rx_ctrl_pkts;
94         u64     last_rx_data_pkts;
95         u64 last_rx_data_qos_pkts[TID_NUM];
96 #ifdef CONFIG_TDLS
97         u64 rx_tdls_disc_rsp_pkts;
98         u64 last_rx_tdls_disc_rsp_pkts;
99 #endif
100         u64     rx_bytes;
101         u64     rx_drops;
102
103         u64     tx_pkts;
104         u64     tx_bytes;
105         u64  tx_drops;
106 };
107
108 #ifndef DBG_SESSION_TRACKER
109 #define DBG_SESSION_TRACKER 0
110 #endif
111
112 /* session tracker status */
113 #define ST_STATUS_NONE          0
114 #define ST_STATUS_CHECK         BIT0
115 #define ST_STATUS_ESTABLISH     BIT1
116 #define ST_STATUS_EXPIRE        BIT2
117
118 #define ST_EXPIRE_MS (10 * 1000)
119
120 struct session_tracker {
121         _list list; /* session_tracker_queue */
122         u32 local_naddr;
123         u16 local_port;
124         u32 remote_naddr;
125         u16 remote_port;
126         u32 set_time;
127         u8 status;
128 };
129
130 /* session tracker cmd */
131 #define ST_CMD_ADD 0
132 #define ST_CMD_DEL 1
133 #define ST_CMD_CHK 2
134
135 struct st_cmd_parm {
136         u8 cmd;
137         struct sta_info *sta;
138         u32 local_naddr; /* TODO: IPV6 */
139         u16 local_port;
140         u32 remote_naddr; /* TODO: IPV6 */
141         u16 remote_port;
142 };
143
144 typedef bool (*st_match_rule)(_adapter *adapter, u8 *local_naddr, u8 *local_port, u8 *remote_naddr, u8 *remote_port);
145
146 struct st_register {
147         u8 s_proto;
148         st_match_rule rule;
149 };
150
151 #define SESSION_TRACKER_REG_ID_WFD 0
152 #define SESSION_TRACKER_REG_ID_NUM 1
153
154 struct st_ctl_t {
155         struct st_register reg[SESSION_TRACKER_REG_ID_NUM];
156         _queue tracker_q;
157 };
158
159 void rtw_st_ctl_init(struct st_ctl_t *st_ctl);
160 void rtw_st_ctl_deinit(struct st_ctl_t *st_ctl);
161 void rtw_st_ctl_register(struct st_ctl_t *st_ctl, u8 st_reg_id, struct st_register *reg);
162 void rtw_st_ctl_unregister(struct st_ctl_t *st_ctl, u8 st_reg_id);
163 bool rtw_st_ctl_chk_reg_s_proto(struct st_ctl_t *st_ctl, u8 s_proto);
164 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);
165 void dump_st_ctl(void *sel, struct st_ctl_t *st_ctl);
166
167 #ifdef CONFIG_TDLS
168 struct TDLS_PeerKey {
169         u8 kck[16]; /* TPK-KCK */
170         u8 tk[16]; /* TPK-TK; only CCMP will be used */
171 } ;
172 #endif //CONFIG_TDLS
173
174 struct sta_info {
175
176         _lock   lock;
177         _list   list; //free_sta_queue
178         _list   hash_list; //sta_hash
179         //_list asoc_list; //20061114
180         //_list sleep_list;//sleep_q
181         //_list wakeup_list;//wakeup_q
182         _adapter *padapter;
183
184         struct sta_xmit_priv sta_xmitpriv;
185         struct sta_recv_priv sta_recvpriv;
186
187         _queue sleep_q;
188         unsigned int sleepq_len;
189
190         uint state;
191         uint aid;
192         uint mac_id;
193         uint qos_option;
194         u8      hwaddr[ETH_ALEN];
195         u16 hwseq;
196         u8      ra_rpt_linked;
197
198         uint    ieee8021x_blocked;      //0: allowed, 1:blocked
199         uint    dot118021XPrivacy; //aes, tkip...
200         union Keytype   dot11tkiptxmickey;
201         union Keytype   dot11tkiprxmickey;
202         union Keytype   dot118021x_UncstKey;
203         union pn48              dot11txpn;                      // PN48 used for Unicast xmit
204 #ifdef CONFIG_GTK_OL
205         u8 kek[RTW_KEK_LEN];
206         u8 kck[RTW_KCK_LEN];
207         u8 replay_ctr[RTW_REPLAY_CTR_LEN];
208 #endif //CONFIG_GTK_OL
209 #ifdef CONFIG_IEEE80211W
210         union pn48              dot11wtxpn;                     // PN48 used for Unicast mgmt xmit.
211         _timer dot11w_expire_timer;
212 #endif //CONFIG_IEEE80211W
213         union pn48              dot11rxpn;                      // PN48 used for Unicast recv.
214
215
216         u8      bssrateset[16];
217         u32     bssratelen;
218         s32  rssi;
219         s32     signal_quality;
220
221         u8      cts2self;
222         u8      rtsen;
223
224         u8      raid;
225         u8      init_rate;
226         u64     ra_mask;
227         u8      wireless_mode;  // NETWORK_TYPE
228         u8      bw_mode;
229
230         u8      ldpc;
231         u8      stbc;
232
233
234         struct stainfo_stats sta_stats;
235
236 #ifdef CONFIG_TDLS
237         u32     tdls_sta_state;
238         u8      SNonce[32];
239         u8      ANonce[32];
240         u32     TDLS_PeerKey_Lifetime;
241         u32     TPK_count;
242         _timer  TPK_timer;
243         struct TDLS_PeerKey     tpk;
244 #ifdef CONFIG_TDLS_CH_SW
245         u16     ch_switch_time;
246         u16     ch_switch_timeout;
247         //u8    option;
248         _timer  ch_sw_timer;
249         _timer  delay_timer;
250         _timer  stay_on_base_chnl_timer;
251         _timer  ch_sw_monitor_timer;
252 #endif
253         _timer handshake_timer;
254         u8 alive_count;
255         _timer  pti_timer;
256         u8      TDLS_RSNIE[20]; /* Save peer's RSNIE, used for sending TDLS_SETUP_RSP */
257 #endif /* CONFIG_TDLS */
258
259         //for A-MPDU TX, ADDBA timeout check
260         _timer addba_retry_timer;
261
262         //for A-MPDU Rx reordering buffer control
263         struct recv_reorder_ctrl recvreorder_ctrl[TID_NUM];
264         ATOMIC_T continual_no_rx_packet[TID_NUM];
265         //for A-MPDU Tx
266         //unsigned char         ampdu_txen_bitmap;
267         u16     BA_starting_seqctrl[16];
268
269
270 #ifdef CONFIG_80211N_HT
271         struct ht_priv  htpriv;
272 #endif
273
274
275         //Notes:
276         //STA_Mode:
277         //curr_network(mlme_priv/security_priv/qos/ht) + sta_info: (STA & AP) CAP/INFO
278         //scan_q: AP CAP/INFO
279
280         //AP_Mode:
281         //curr_network(mlme_priv/security_priv/qos/ht) : AP CAP/INFO
282         //sta_info: (AP & STA) CAP/INFO
283
284         unsigned int expire_to;
285
286 #ifdef CONFIG_AP_MODE
287
288         _list asoc_list;
289         _list auth_list;
290
291         unsigned int auth_seq;
292         unsigned int authalg;
293         unsigned char chg_txt[128];
294
295         u16 capability;
296         int flags;
297
298         int dot8021xalg;//0:disable, 1:psk, 2:802.1x
299         int wpa_psk;//0:disable, bit(0): WPA, bit(1):WPA2
300         int wpa_group_cipher;
301         int wpa2_group_cipher;
302         int wpa_pairwise_cipher;
303         int wpa2_pairwise_cipher;
304
305         u8 bpairwise_key_installed;
306
307 #ifdef CONFIG_NATIVEAP_MLME
308         u8 wpa_ie[32];
309
310         u8 nonerp_set;
311         u8 no_short_slot_time_set;
312         u8 no_short_preamble_set;
313         u8 no_ht_gf_set;
314         u8 no_ht_set;
315         u8 ht_20mhz_set;
316         u8 ht_40mhz_intolerant;
317 #endif  // CONFIG_NATIVEAP_MLME
318
319 #ifdef CONFIG_ATMEL_RC_PATCH
320         u8 flag_atmel_rc;
321 #endif
322
323         u8 qos_info;
324
325         u8 max_sp_len;
326         u8 uapsd_bk;//BIT(0): Delivery enabled, BIT(1): Trigger enabled
327         u8 uapsd_be;
328         u8 uapsd_vi;
329         u8 uapsd_vo;
330
331         u8 has_legacy_ac;
332         unsigned int sleepq_ac_len;
333
334 #ifdef CONFIG_P2P
335         //p2p priv data
336         u8 is_p2p_device;
337         u8 p2p_status_code;
338
339         //p2p client info
340         u8 dev_addr[ETH_ALEN];
341         //u8 iface_addr[ETH_ALEN];//= hwaddr[ETH_ALEN]
342         u8 dev_cap;
343         u16 config_methods;
344         u8 primary_dev_type[8];
345         u8 num_of_secdev_type;
346         u8 secdev_types_list[32];// 32/8 == 4;
347         u16 dev_name_len;
348         u8 dev_name[32];
349 #endif //CONFIG_P2P
350
351 #ifdef CONFIG_WFD
352         u8 op_wfd_mode;
353 #endif
354
355 #ifdef CONFIG_TX_MCAST2UNI
356         u8 under_exist_checking;
357 #endif  // CONFIG_TX_MCAST2UNI
358
359         u8 keep_alive_trycnt;
360
361 #ifdef CONFIG_AUTO_AP_MODE
362         u8 isrc; //this device is rc
363         u16 pid; // pairing id
364 #endif
365
366 #endif  // CONFIG_AP_MODE
367
368 #ifdef CONFIG_IOCTL_CFG80211
369         u8 *passoc_req;
370         u32 assoc_req_len;
371 #endif
372
373         //for DM
374         RSSI_STA         rssi_stat;
375
376         //ODM_STA_INFO_T
377         // ================ODM Relative Info=======================
378         // Please be care, dont declare too much structure here. It will cost memory * STA support num.
379         //
380         //
381         // 2011/10/20 MH Add for ODM STA info.
382         //
383         // Driver Write
384         u8              bValid;                         // record the sta status link or not?
385         //u8            WirelessMode;           //
386         u8              IOTPeer;                        // Enum value.  HT_IOT_PEER_E
387         // ODM Write
388         //1 PHY_STATUS_INFO
389         u8              RSSI_Path[4];           //
390         u8              RSSI_Ave;
391         u8              RXEVM[4];
392         u8              RXSNR[4];
393
394         u8              rssi_level;                     //for Refresh RA mask
395         // ODM Write
396         //1 TX_INFO (may changed by IC)
397         //TX_INFO_T             pTxInfo;                                // Define in IC folder. Move lower layer.
398         //
399         // ================ODM Relative Info=======================
400         //
401
402         /* To store the sequence number of received management frame */
403         u16 RxMgmtFrameSeqNum;
404
405         struct st_ctl_t st_ctl;
406 };
407
408 #define sta_rx_pkts(sta) \
409         (sta->sta_stats.rx_mgnt_pkts \
410         + sta->sta_stats.rx_ctrl_pkts \
411         + sta->sta_stats.rx_data_pkts)
412
413 #define sta_last_rx_pkts(sta) \
414         (sta->sta_stats.last_rx_mgnt_pkts \
415         + sta->sta_stats.last_rx_ctrl_pkts \
416         + sta->sta_stats.last_rx_data_pkts)
417
418 #define sta_rx_data_pkts(sta) \
419         (sta->sta_stats.rx_data_pkts)
420
421 #define sta_rx_data_qos_pkts(sta, i) \
422         (sta->sta_stats.rx_data_qos_pkts[i])
423
424 #define sta_last_rx_data_pkts(sta) \
425         (sta->sta_stats.last_rx_data_pkts)
426
427 #define sta_last_rx_data_qos_pkts(sta, i) \
428         (sta->sta_stats.last_rx_data_qos_pkts[i])
429
430 #define sta_rx_mgnt_pkts(sta) \
431         (sta->sta_stats.rx_mgnt_pkts)
432
433 #define sta_last_rx_mgnt_pkts(sta) \
434         (sta->sta_stats.last_rx_mgnt_pkts)
435
436 #define sta_rx_beacon_pkts(sta) \
437         (sta->sta_stats.rx_beacon_pkts)
438
439 #define sta_last_rx_beacon_pkts(sta) \
440         (sta->sta_stats.last_rx_beacon_pkts)
441
442 #define sta_rx_probereq_pkts(sta) \
443         (sta->sta_stats.rx_probereq_pkts)
444
445 #define sta_last_rx_probereq_pkts(sta) \
446         (sta->sta_stats.last_rx_probereq_pkts)
447
448 #define sta_rx_probersp_pkts(sta) \
449         (sta->sta_stats.rx_probersp_pkts)
450
451 #define sta_last_rx_probersp_pkts(sta) \
452         (sta->sta_stats.last_rx_probersp_pkts)
453
454 #define sta_rx_probersp_bm_pkts(sta) \
455         (sta->sta_stats.rx_probersp_bm_pkts)
456
457 #define sta_last_rx_probersp_bm_pkts(sta) \
458         (sta->sta_stats.last_rx_probersp_bm_pkts)
459
460 #define sta_rx_probersp_uo_pkts(sta) \
461         (sta->sta_stats.rx_probersp_uo_pkts)
462
463 #define sta_last_rx_probersp_uo_pkts(sta) \
464         (sta->sta_stats.last_rx_probersp_uo_pkts)
465
466 #define sta_update_last_rx_pkts(sta) \
467         do { \
468                 sta->sta_stats.last_rx_mgnt_pkts = sta->sta_stats.rx_mgnt_pkts; \
469                 sta->sta_stats.last_rx_beacon_pkts = sta->sta_stats.rx_beacon_pkts; \
470                 sta->sta_stats.last_rx_probereq_pkts = sta->sta_stats.rx_probereq_pkts; \
471                 sta->sta_stats.last_rx_probersp_pkts = sta->sta_stats.rx_probersp_pkts; \
472                 sta->sta_stats.last_rx_probersp_bm_pkts = sta->sta_stats.rx_probersp_bm_pkts; \
473                 sta->sta_stats.last_rx_probersp_uo_pkts = sta->sta_stats.rx_probersp_uo_pkts; \
474                 sta->sta_stats.last_rx_ctrl_pkts = sta->sta_stats.rx_ctrl_pkts; \
475                 sta->sta_stats.last_rx_data_pkts = sta->sta_stats.rx_data_pkts; \
476         } while(0)
477
478 #define STA_RX_PKTS_ARG(sta) \
479         sta->sta_stats.rx_mgnt_pkts \
480         , sta->sta_stats.rx_ctrl_pkts \
481         , sta->sta_stats.rx_data_pkts
482
483 #define STA_LAST_RX_PKTS_ARG(sta) \
484         sta->sta_stats.last_rx_mgnt_pkts \
485         , sta->sta_stats.last_rx_ctrl_pkts \
486         , sta->sta_stats.last_rx_data_pkts
487
488 #define STA_RX_PKTS_DIFF_ARG(sta) \
489         sta->sta_stats.rx_mgnt_pkts - sta->sta_stats.last_rx_mgnt_pkts \
490         , sta->sta_stats.rx_ctrl_pkts - sta->sta_stats.last_rx_ctrl_pkts \
491         , sta->sta_stats.rx_data_pkts -sta->sta_stats.last_rx_data_pkts
492
493 #define STA_PKTS_FMT "(m:%llu, c:%llu, d:%llu)"
494
495 #ifdef CONFIG_WFD
496 #define STA_OP_WFD_MODE(sta) (sta)->op_wfd_mode
497 #define STA_SET_OP_WFD_MODE(sta, mode) (sta)->op_wfd_mode = (mode)
498 #else
499 #define STA_OP_WFD_MODE(sta) 0
500 #define STA_SET_OP_WFD_MODE(sta, mode) do {} while (0)
501 #endif
502
503 struct  sta_priv {
504
505         u8 *pallocated_stainfo_buf;
506         u8 *pstainfo_buf;
507         _queue  free_sta_queue;
508
509         _lock sta_hash_lock;
510         _list   sta_hash[NUM_STA];
511         int asoc_sta_count;
512         _queue sleep_q;
513         _queue wakeup_q;
514
515         _adapter *padapter;
516
517         u32 adhoc_expire_to;
518
519 #ifdef CONFIG_AP_MODE
520         _list asoc_list;
521         _list auth_list;
522         _lock asoc_list_lock;
523         _lock auth_list_lock;
524         u8 asoc_list_cnt;
525         u8 auth_list_cnt;
526
527         unsigned int auth_to;  //sec, time to expire in authenticating.
528         unsigned int assoc_to; //sec, time to expire before associating.
529         unsigned int expire_to; //sec , time to expire after associated.
530
531         /* pointers to STA info; based on allocated AID or NULL if AID free
532          * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
533          * and so on
534          */
535         struct sta_info *sta_aid[NUM_STA];
536
537         u16 sta_dz_bitmap;//only support 15 stations, staion aid bitmap for sleeping sta.
538         u16 tim_bitmap;//only support 15 stations, aid=0~15 mapping bit0~bit15
539
540         u16 max_num_sta;
541
542         struct wlan_acl_pool acl_list;
543 #endif
544
545 #ifdef CONFIG_ATMEL_RC_PATCH
546         u8 atmel_rc_pattern [6];
547 #endif
548
549 };
550
551
552 static u32 wifi_mac_hash(const u8 *mac)
553 {
554         u32 x;
555
556         x = mac[0];
557         x = (x << 2) ^ mac[1];
558         x = (x << 2) ^ mac[2];
559         x = (x << 2) ^ mac[3];
560         x = (x << 2) ^ mac[4];
561         x = (x << 2) ^ mac[5];
562
563         x ^= x >> 8;
564         x  = x & (NUM_STA - 1);
565
566         return x;
567 }
568
569
570 extern u32      _rtw_init_sta_priv(struct sta_priv *pstapriv);
571 extern u32      _rtw_free_sta_priv(struct sta_priv *pstapriv);
572
573 #define stainfo_offset_valid(offset) (offset < NUM_STA && offset >= 0)
574 int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta);
575 struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset);
576
577 extern struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr);
578 extern u32      rtw_free_stainfo(_adapter *padapter , struct sta_info *psta);
579 extern void rtw_free_all_stainfo(_adapter *padapter);
580 extern struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr);
581 extern u32 rtw_init_bcmc_stainfo(_adapter* padapter);
582 extern struct sta_info* rtw_get_bcmc_stainfo(_adapter* padapter);
583 extern u8 rtw_access_ctrl(_adapter *padapter, u8 *mac_addr);
584
585 #endif //_STA_INFO_H_