8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / 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 //if mode ==0, then the sta is allowed once the addr is hit.
33 //if mode ==1, then the sta is rejected once the addr is non-hit.
34 struct rtw_wlan_acl_node {
35         _list                   list;
36         u8       addr[ETH_ALEN];
37         u8       valid;
38 };
39
40 //mode=0, disable
41 //mode=1, accept unless in deny list
42 //mode=2, deny unless in accept list
43 struct wlan_acl_pool {
44         int mode;
45         int num;
46         struct rtw_wlan_acl_node aclnode[NUM_ACL];
47         _queue  acl_node_q;
48 };
49
50 typedef struct _RSSI_STA{
51         s32     UndecoratedSmoothedPWDB;
52         s32     UndecoratedSmoothedCCK;
53         s32     UndecoratedSmoothedOFDM;
54         u64     PacketMap;
55         u8      ValidBit;
56 }RSSI_STA, *PRSSI_STA;
57
58 struct  stainfo_stats   {
59
60         u64 rx_mgnt_pkts;
61                 u64 rx_beacon_pkts;
62                 u64 rx_probereq_pkts;
63                 u64 rx_probersp_pkts;
64                 u64 rx_probersp_bm_pkts;
65                 u64 rx_probersp_uo_pkts;
66         u64 rx_ctrl_pkts;
67         u64 rx_data_pkts;
68
69         u64     last_rx_mgnt_pkts;
70                 u64 last_rx_beacon_pkts;
71                 u64 last_rx_probereq_pkts;
72                 u64 last_rx_probersp_pkts;
73                 u64 last_rx_probersp_bm_pkts;
74                 u64 last_rx_probersp_uo_pkts;
75         u64     last_rx_ctrl_pkts;
76         u64     last_rx_data_pkts;
77         
78         u64     rx_bytes;
79         u64     rx_drops;
80
81         u64     tx_pkts;
82         u64     tx_bytes;
83         u64  tx_drops;
84 };
85
86 #ifdef CONFIG_TDLS
87 struct TDLS_PeerKey {
88         u8 kck[16]; /* TPK-KCK */
89         u8 tk[16]; /* TPK-TK; only CCMP will be used */
90 } ;
91 #endif //CONFIG_TDLS
92
93 struct sta_info {
94
95         _lock   lock;
96         _list   list; //free_sta_queue
97         _list   hash_list; //sta_hash
98         //_list asoc_list; //20061114
99         //_list sleep_list;//sleep_q
100         //_list wakeup_list;//wakeup_q
101         _adapter *padapter;
102         
103         struct sta_xmit_priv sta_xmitpriv;
104         struct sta_recv_priv sta_recvpriv;
105         
106         _queue sleep_q;
107         unsigned int sleepq_len;
108         
109         uint state;
110         uint aid;
111         uint mac_id;
112         uint qos_option;
113         u8      hwaddr[ETH_ALEN];
114
115         uint    ieee8021x_blocked;      //0: allowed, 1:blocked 
116         uint    dot118021XPrivacy; //aes, tkip...
117         union Keytype   dot11tkiptxmickey;
118         union Keytype   dot11tkiprxmickey;
119         union Keytype   dot118021x_UncstKey;    
120         union pn48              dot11txpn;                      // PN48 used for Unicast xmit
121 #ifdef CONFIG_GTK_OL
122         u8 kek[RTW_KEK_LEN];
123         u8 kck[RTW_KCK_LEN];
124         u8 replay_ctr[RTW_REPLAY_CTR_LEN];
125 #endif //CONFIG_GTK_OL
126 #ifdef CONFIG_IEEE80211W
127         union pn48              dot11wtxpn;                     // PN48 used for Unicast mgmt xmit.
128 #endif //CONFIG_IEEE80211W
129         union pn48              dot11rxpn;                      // PN48 used for Unicast recv.
130
131
132         u8      bssrateset[16];
133         u32     bssratelen;
134         s32  rssi;
135         s32     signal_quality;
136         
137         u8      cts2self;
138         u8      rtsen;
139
140         u8      raid;
141         u8      init_rate;
142         u64     ra_mask;
143         u8      wireless_mode;  // NETWORK_TYPE
144         u8      bw_mode;
145
146         u8      ldpc;
147         u8      stbc;
148
149         struct stainfo_stats sta_stats;
150
151 #ifdef CONFIG_TDLS
152         u32     tdls_sta_state;
153         u8      SNonce[32];
154         u8      ANonce[32];
155         u32     TDLS_PeerKey_Lifetime;
156         u16     TPK_count;
157         _timer  TPK_timer;
158         struct TDLS_PeerKey     tpk;
159 #ifdef CONFIG_TDLS_CH_SW        
160         u16     ch_switch_time;
161         u16     ch_switch_timeout;
162         //u8    option;
163         _timer  ch_sw_timer;
164         _timer  delay_timer;
165 #endif  
166         _timer handshake_timer;
167         u8 alive_count;
168         _timer  pti_timer;
169         u8      TDLS_RSNIE[20]; /* Save peer's RSNIE, used for sending TDLS_SETUP_RSP */
170 #endif /* CONFIG_TDLS */
171
172         //for A-MPDU TX, ADDBA timeout check    
173         _timer addba_retry_timer;
174         
175         //for A-MPDU Rx reordering buffer control 
176         struct recv_reorder_ctrl recvreorder_ctrl[16];
177
178         //for A-MPDU Tx
179         //unsigned char         ampdu_txen_bitmap;
180         u16     BA_starting_seqctrl[16];
181         
182
183 #ifdef CONFIG_80211N_HT
184         struct ht_priv  htpriv;
185 #endif
186
187 #ifdef CONFIG_80211AC_VHT
188         struct vht_priv vhtpriv;
189 #endif
190
191         //Notes:        
192         //STA_Mode:
193         //curr_network(mlme_priv/security_priv/qos/ht) + sta_info: (STA & AP) CAP/INFO  
194         //scan_q: AP CAP/INFO
195
196         //AP_Mode:
197         //curr_network(mlme_priv/security_priv/qos/ht) : AP CAP/INFO
198         //sta_info: (AP & STA) CAP/INFO
199                 
200 #ifdef CONFIG_AP_MODE
201
202         _list asoc_list;
203         _list auth_list;
204          
205         unsigned int expire_to;
206         unsigned int auth_seq;
207         unsigned int authalg;
208         unsigned char chg_txt[128];
209
210         u16 capability; 
211         int flags;      
212
213         int dot8021xalg;//0:disable, 1:psk, 2:802.1x
214         int wpa_psk;//0:disable, bit(0): WPA, bit(1):WPA2
215         int wpa_group_cipher;
216         int wpa2_group_cipher;
217         int wpa_pairwise_cipher;
218         int wpa2_pairwise_cipher;       
219
220         u8 bpairwise_key_installed;
221
222 #ifdef CONFIG_NATIVEAP_MLME
223         u8 wpa_ie[32];
224
225         u8 nonerp_set;
226         u8 no_short_slot_time_set;
227         u8 no_short_preamble_set;
228         u8 no_ht_gf_set;
229         u8 no_ht_set;
230         u8 ht_20mhz_set;
231 #endif  // CONFIG_NATIVEAP_MLME
232
233 #ifdef CONFIG_ATMEL_RC_PATCH
234         u8 flag_atmel_rc;
235 #endif
236
237         unsigned int tx_ra_bitmap;
238         u8 qos_info;
239
240         u8 max_sp_len;
241         u8 uapsd_bk;//BIT(0): Delivery enabled, BIT(1): Trigger enabled
242         u8 uapsd_be;
243         u8 uapsd_vi;
244         u8 uapsd_vo;    
245
246         u8 has_legacy_ac;
247         unsigned int sleepq_ac_len;
248
249 #ifdef CONFIG_P2P
250         //p2p priv data
251         u8 is_p2p_device;
252         u8 p2p_status_code;
253
254         //p2p client info
255         u8 dev_addr[ETH_ALEN];
256         //u8 iface_addr[ETH_ALEN];//= hwaddr[ETH_ALEN]
257         u8 dev_cap;
258         u16 config_methods;
259         u8 primary_dev_type[8];
260         u8 num_of_secdev_type;
261         u8 secdev_types_list[32];// 32/8 == 4;
262         u16 dev_name_len;
263         u8 dev_name[32];        
264 #endif //CONFIG_P2P
265
266 #ifdef CONFIG_TX_MCAST2UNI
267         u8 under_exist_checking;
268 #endif  // CONFIG_TX_MCAST2UNI
269         
270         u8 keep_alive_trycnt;
271
272 #ifdef CONFIG_AUTO_AP_MODE
273         u8 isrc; //this device is rc
274         u16 pid; // pairing id
275 #endif
276
277 #endif  // CONFIG_AP_MODE       
278
279 #ifdef CONFIG_IOCTL_CFG80211
280         u8 *passoc_req;
281         u32 assoc_req_len;
282 #endif
283
284         //for DM
285         RSSI_STA         rssi_stat;
286         
287         //ODM_STA_INFO_T
288         // ================ODM Relative Info=======================
289         // Please be care, dont declare too much structure here. It will cost memory * STA support num.
290         //
291         //
292         // 2011/10/20 MH Add for ODM STA info.  
293         //
294         // Driver Write
295         u8              bValid;                         // record the sta status link or not?
296         //u8            WirelessMode;           // 
297         u8              IOTPeer;                        // Enum value.  HT_IOT_PEER_E
298         // ODM Write
299         //1 PHY_STATUS_INFO
300         u8              RSSI_Path[4];           // 
301         u8              RSSI_Ave;
302         u8              RXEVM[4];
303         u8              RXSNR[4];
304
305         u8              rssi_level;                     //for Refresh RA mask
306         // ODM Write
307         //1 TX_INFO (may changed by IC)
308         //TX_INFO_T             pTxInfo;                                // Define in IC folder. Move lower layer.
309         //
310         // ================ODM Relative Info=======================
311         //
312
313         /* To store the sequence number of received management frame */
314         u16 RxMgmtFrameSeqNum;
315 };
316
317 #define sta_rx_pkts(sta) \
318         (sta->sta_stats.rx_mgnt_pkts \
319         + sta->sta_stats.rx_ctrl_pkts \
320         + sta->sta_stats.rx_data_pkts)
321
322 #define sta_last_rx_pkts(sta) \
323         (sta->sta_stats.last_rx_mgnt_pkts \
324         + sta->sta_stats.last_rx_ctrl_pkts \
325         + sta->sta_stats.last_rx_data_pkts)
326
327 #define sta_rx_data_pkts(sta) \
328         (sta->sta_stats.rx_data_pkts)
329
330 #define sta_last_rx_data_pkts(sta) \
331         (sta->sta_stats.last_rx_data_pkts)
332
333 #define sta_rx_mgnt_pkts(sta) \
334         (sta->sta_stats.rx_mgnt_pkts)
335
336 #define sta_last_rx_mgnt_pkts(sta) \
337         (sta->sta_stats.last_rx_mgnt_pkts)
338
339 #define sta_rx_beacon_pkts(sta) \
340         (sta->sta_stats.rx_beacon_pkts)
341
342 #define sta_last_rx_beacon_pkts(sta) \
343         (sta->sta_stats.last_rx_beacon_pkts)
344
345 #define sta_rx_probereq_pkts(sta) \
346         (sta->sta_stats.rx_probereq_pkts)
347
348 #define sta_last_rx_probereq_pkts(sta) \
349         (sta->sta_stats.last_rx_probereq_pkts)
350
351 #define sta_rx_probersp_pkts(sta) \
352         (sta->sta_stats.rx_probersp_pkts)
353
354 #define sta_last_rx_probersp_pkts(sta) \
355         (sta->sta_stats.last_rx_probersp_pkts)
356
357 #define sta_rx_probersp_bm_pkts(sta) \
358         (sta->sta_stats.rx_probersp_bm_pkts)
359
360 #define sta_last_rx_probersp_bm_pkts(sta) \
361         (sta->sta_stats.last_rx_probersp_bm_pkts)
362
363 #define sta_rx_probersp_uo_pkts(sta) \
364         (sta->sta_stats.rx_probersp_uo_pkts)
365
366 #define sta_last_rx_probersp_uo_pkts(sta) \
367         (sta->sta_stats.last_rx_probersp_uo_pkts)
368
369 #define sta_update_last_rx_pkts(sta) \
370         do { \
371                 sta->sta_stats.last_rx_mgnt_pkts = sta->sta_stats.rx_mgnt_pkts; \
372                 sta->sta_stats.last_rx_beacon_pkts = sta->sta_stats.rx_beacon_pkts; \
373                 sta->sta_stats.last_rx_probereq_pkts = sta->sta_stats.rx_probereq_pkts; \
374                 sta->sta_stats.last_rx_probersp_pkts = sta->sta_stats.rx_probersp_pkts; \
375                 sta->sta_stats.last_rx_probersp_bm_pkts = sta->sta_stats.rx_probersp_bm_pkts; \
376                 sta->sta_stats.last_rx_probersp_uo_pkts = sta->sta_stats.rx_probersp_uo_pkts; \
377                 sta->sta_stats.last_rx_ctrl_pkts = sta->sta_stats.rx_ctrl_pkts; \
378                 sta->sta_stats.last_rx_data_pkts = sta->sta_stats.rx_data_pkts; \
379         } while(0)
380
381 #define STA_RX_PKTS_ARG(sta) \
382         sta->sta_stats.rx_mgnt_pkts \
383         , sta->sta_stats.rx_ctrl_pkts \
384         , sta->sta_stats.rx_data_pkts
385
386 #define STA_LAST_RX_PKTS_ARG(sta) \
387         sta->sta_stats.last_rx_mgnt_pkts \
388         , sta->sta_stats.last_rx_ctrl_pkts \
389         , sta->sta_stats.last_rx_data_pkts
390
391 #define STA_RX_PKTS_DIFF_ARG(sta) \
392         sta->sta_stats.rx_mgnt_pkts - sta->sta_stats.last_rx_mgnt_pkts \
393         , sta->sta_stats.rx_ctrl_pkts - sta->sta_stats.last_rx_ctrl_pkts \
394         , sta->sta_stats.rx_data_pkts -sta->sta_stats.last_rx_data_pkts
395
396 #define STA_PKTS_FMT "(m:%llu, c:%llu, d:%llu)"
397         
398 struct  sta_priv {
399         
400         u8 *pallocated_stainfo_buf;
401         u8 *pstainfo_buf;
402         _queue  free_sta_queue;
403         
404         _lock sta_hash_lock;
405         _list   sta_hash[NUM_STA];
406         int asoc_sta_count;
407         _queue sleep_q;
408         _queue wakeup_q;
409         
410         _adapter *padapter;
411         
412
413 #ifdef CONFIG_AP_MODE
414         _list asoc_list;
415         _list auth_list;
416         _lock asoc_list_lock;
417         _lock auth_list_lock;
418         u8 asoc_list_cnt;
419         u8 auth_list_cnt;
420
421         unsigned int auth_to;  //sec, time to expire in authenticating.
422         unsigned int assoc_to; //sec, time to expire before associating.
423         unsigned int expire_to; //sec , time to expire after associated.
424         
425         /* pointers to STA info; based on allocated AID or NULL if AID free
426          * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
427          * and so on
428          */
429         struct sta_info *sta_aid[NUM_STA];
430
431         u16 sta_dz_bitmap;//only support 15 stations, staion aid bitmap for sleeping sta.
432         u16 tim_bitmap;//only support 15 stations, aid=0~15 mapping bit0~bit15  
433
434         u16 max_num_sta;
435
436         struct wlan_acl_pool acl_list;
437 #endif
438
439 #ifdef CONFIG_ATMEL_RC_PATCH
440         u8 atmel_rc_pattern [6];
441 #endif
442
443 };
444
445
446 __inline static u32 wifi_mac_hash(u8 *mac)
447 {
448         u32 x;
449
450         x = mac[0];
451         x = (x << 2) ^ mac[1];
452         x = (x << 2) ^ mac[2];
453         x = (x << 2) ^ mac[3];
454         x = (x << 2) ^ mac[4];
455         x = (x << 2) ^ mac[5];
456
457         x ^= x >> 8;
458         x  = x & (NUM_STA - 1);
459                 
460         return x;
461 }
462
463
464 extern u32      _rtw_init_sta_priv(struct sta_priv *pstapriv);
465 extern u32      _rtw_free_sta_priv(struct sta_priv *pstapriv);
466
467 #define stainfo_offset_valid(offset) (offset < NUM_STA && offset >= 0)
468 int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta);
469 struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset);
470
471 extern struct sta_info *rtw_alloc_stainfo(struct        sta_priv *pstapriv, u8 *hwaddr);
472 extern u32      rtw_free_stainfo(_adapter *padapter , struct sta_info *psta);
473 extern void rtw_free_all_stainfo(_adapter *padapter);
474 extern struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr);
475 extern u32 rtw_init_bcmc_stainfo(_adapter* padapter);
476 extern struct sta_info* rtw_get_bcmc_stainfo(_adapter* padapter);
477 extern u8 rtw_access_ctrl(_adapter *padapter, u8 *mac_addr);
478
479 #endif //_STA_INFO_H_
480