net: wireless: rockchip_wlan: add rtl8723bs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bs / 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 #ifdef CONFIG_BEAMFORMING
234         u16 txbf_paid;
235         u16 txbf_gid;
236 #endif
237                 
238         struct stainfo_stats sta_stats;
239
240 #ifdef CONFIG_TDLS
241         u32     tdls_sta_state;
242         u8      SNonce[32];
243         u8      ANonce[32];
244         u32     TDLS_PeerKey_Lifetime;
245         u32     TPK_count;
246         _timer  TPK_timer;
247         struct TDLS_PeerKey     tpk;
248 #ifdef CONFIG_TDLS_CH_SW        
249         u16     ch_switch_time;
250         u16     ch_switch_timeout;
251         //u8    option;
252         _timer  ch_sw_timer;
253         _timer  delay_timer;
254         _timer  stay_on_base_chnl_timer;
255         _timer  ch_sw_monitor_timer;
256 #endif  
257         _timer handshake_timer;
258         u8 alive_count;
259         _timer  pti_timer;
260         u8      TDLS_RSNIE[20]; /* Save peer's RSNIE, used for sending TDLS_SETUP_RSP */
261 #endif /* CONFIG_TDLS */
262
263         //for A-MPDU TX, ADDBA timeout check    
264         _timer addba_retry_timer;
265         
266         //for A-MPDU Rx reordering buffer control 
267         struct recv_reorder_ctrl recvreorder_ctrl[TID_NUM];
268         ATOMIC_T continual_no_rx_packet[TID_NUM];
269         //for A-MPDU Tx
270         //unsigned char         ampdu_txen_bitmap;
271         u16     BA_starting_seqctrl[16];
272         
273
274 #ifdef CONFIG_80211N_HT
275         struct ht_priv  htpriv;
276 #endif
277
278 #ifdef CONFIG_80211AC_VHT
279         struct vht_priv vhtpriv;
280 #endif
281
282         //Notes:        
283         //STA_Mode:
284         //curr_network(mlme_priv/security_priv/qos/ht) + sta_info: (STA & AP) CAP/INFO  
285         //scan_q: AP CAP/INFO
286
287         //AP_Mode:
288         //curr_network(mlme_priv/security_priv/qos/ht) : AP CAP/INFO
289         //sta_info: (AP & STA) CAP/INFO
290
291         unsigned int expire_to;
292
293 #ifdef CONFIG_AP_MODE
294
295         _list asoc_list;
296         _list auth_list;
297
298         unsigned int auth_seq;
299         unsigned int authalg;
300         unsigned char chg_txt[128];
301
302         u16 capability; 
303         int flags;      
304
305         int dot8021xalg;//0:disable, 1:psk, 2:802.1x
306         int wpa_psk;//0:disable, bit(0): WPA, bit(1):WPA2
307         int wpa_group_cipher;
308         int wpa2_group_cipher;
309         int wpa_pairwise_cipher;
310         int wpa2_pairwise_cipher;       
311
312         u8 bpairwise_key_installed;
313
314 #ifdef CONFIG_NATIVEAP_MLME
315         u8 wpa_ie[32];
316
317         u8 nonerp_set;
318         u8 no_short_slot_time_set;
319         u8 no_short_preamble_set;
320         u8 no_ht_gf_set;
321         u8 no_ht_set;
322         u8 ht_20mhz_set;
323         u8 ht_40mhz_intolerant;
324 #endif  // CONFIG_NATIVEAP_MLME
325
326 #ifdef CONFIG_ATMEL_RC_PATCH
327         u8 flag_atmel_rc;
328 #endif
329
330         u8 qos_info;
331
332         u8 max_sp_len;
333         u8 uapsd_bk;//BIT(0): Delivery enabled, BIT(1): Trigger enabled
334         u8 uapsd_be;
335         u8 uapsd_vi;
336         u8 uapsd_vo;    
337
338         u8 has_legacy_ac;
339         unsigned int sleepq_ac_len;
340
341 #ifdef CONFIG_P2P
342         //p2p priv data
343         u8 is_p2p_device;
344         u8 p2p_status_code;
345
346         //p2p client info
347         u8 dev_addr[ETH_ALEN];
348         //u8 iface_addr[ETH_ALEN];//= hwaddr[ETH_ALEN]
349         u8 dev_cap;
350         u16 config_methods;
351         u8 primary_dev_type[8];
352         u8 num_of_secdev_type;
353         u8 secdev_types_list[32];// 32/8 == 4;
354         u16 dev_name_len;
355         u8 dev_name[32];        
356 #endif //CONFIG_P2P
357
358 #ifdef CONFIG_WFD
359         u8 op_wfd_mode;
360 #endif
361
362 #ifdef CONFIG_TX_MCAST2UNI
363         u8 under_exist_checking;
364 #endif  // CONFIG_TX_MCAST2UNI
365         
366         u8 keep_alive_trycnt;
367
368 #ifdef CONFIG_AUTO_AP_MODE
369         u8 isrc; //this device is rc
370         u16 pid; // pairing id
371 #endif
372
373 #endif  // CONFIG_AP_MODE       
374
375 #ifdef CONFIG_IOCTL_CFG80211
376         u8 *passoc_req;
377         u32 assoc_req_len;
378 #endif
379
380         //for DM
381         RSSI_STA         rssi_stat;
382         
383         //ODM_STA_INFO_T
384         // ================ODM Relative Info=======================
385         // Please be care, dont declare too much structure here. It will cost memory * STA support num.
386         //
387         //
388         // 2011/10/20 MH Add for ODM STA info.  
389         //
390         // Driver Write
391         u8              bValid;                         // record the sta status link or not?
392         //u8            WirelessMode;           // 
393         u8              IOTPeer;                        // Enum value.  HT_IOT_PEER_E
394         // ODM Write
395         //1 PHY_STATUS_INFO
396         u8              RSSI_Path[4];           // 
397         u8              RSSI_Ave;
398         u8              RXEVM[4];
399         u8              RXSNR[4];
400
401         u8              rssi_level;                     //for Refresh RA mask
402         // ODM Write
403         //1 TX_INFO (may changed by IC)
404         //TX_INFO_T             pTxInfo;                                // Define in IC folder. Move lower layer.
405         //
406         // ================ODM Relative Info=======================
407         //
408
409         /* To store the sequence number of received management frame */
410         u16 RxMgmtFrameSeqNum;
411
412         struct st_ctl_t st_ctl;
413 };
414
415 #define sta_rx_pkts(sta) \
416         (sta->sta_stats.rx_mgnt_pkts \
417         + sta->sta_stats.rx_ctrl_pkts \
418         + sta->sta_stats.rx_data_pkts)
419
420 #define sta_last_rx_pkts(sta) \
421         (sta->sta_stats.last_rx_mgnt_pkts \
422         + sta->sta_stats.last_rx_ctrl_pkts \
423         + sta->sta_stats.last_rx_data_pkts)
424
425 #define sta_rx_data_pkts(sta) \
426         (sta->sta_stats.rx_data_pkts)
427
428 #define sta_rx_data_qos_pkts(sta, i) \
429         (sta->sta_stats.rx_data_qos_pkts[i])
430
431 #define sta_last_rx_data_pkts(sta) \
432         (sta->sta_stats.last_rx_data_pkts)
433
434 #define sta_last_rx_data_qos_pkts(sta, i) \
435         (sta->sta_stats.last_rx_data_qos_pkts[i])
436
437 #define sta_rx_mgnt_pkts(sta) \
438         (sta->sta_stats.rx_mgnt_pkts)
439
440 #define sta_last_rx_mgnt_pkts(sta) \
441         (sta->sta_stats.last_rx_mgnt_pkts)
442
443 #define sta_rx_beacon_pkts(sta) \
444         (sta->sta_stats.rx_beacon_pkts)
445
446 #define sta_last_rx_beacon_pkts(sta) \
447         (sta->sta_stats.last_rx_beacon_pkts)
448
449 #define sta_rx_probereq_pkts(sta) \
450         (sta->sta_stats.rx_probereq_pkts)
451
452 #define sta_last_rx_probereq_pkts(sta) \
453         (sta->sta_stats.last_rx_probereq_pkts)
454
455 #define sta_rx_probersp_pkts(sta) \
456         (sta->sta_stats.rx_probersp_pkts)
457
458 #define sta_last_rx_probersp_pkts(sta) \
459         (sta->sta_stats.last_rx_probersp_pkts)
460
461 #define sta_rx_probersp_bm_pkts(sta) \
462         (sta->sta_stats.rx_probersp_bm_pkts)
463
464 #define sta_last_rx_probersp_bm_pkts(sta) \
465         (sta->sta_stats.last_rx_probersp_bm_pkts)
466
467 #define sta_rx_probersp_uo_pkts(sta) \
468         (sta->sta_stats.rx_probersp_uo_pkts)
469
470 #define sta_last_rx_probersp_uo_pkts(sta) \
471         (sta->sta_stats.last_rx_probersp_uo_pkts)
472
473 #define sta_update_last_rx_pkts(sta) \
474         do { \
475                 sta->sta_stats.last_rx_mgnt_pkts = sta->sta_stats.rx_mgnt_pkts; \
476                 sta->sta_stats.last_rx_beacon_pkts = sta->sta_stats.rx_beacon_pkts; \
477                 sta->sta_stats.last_rx_probereq_pkts = sta->sta_stats.rx_probereq_pkts; \
478                 sta->sta_stats.last_rx_probersp_pkts = sta->sta_stats.rx_probersp_pkts; \
479                 sta->sta_stats.last_rx_probersp_bm_pkts = sta->sta_stats.rx_probersp_bm_pkts; \
480                 sta->sta_stats.last_rx_probersp_uo_pkts = sta->sta_stats.rx_probersp_uo_pkts; \
481                 sta->sta_stats.last_rx_ctrl_pkts = sta->sta_stats.rx_ctrl_pkts; \
482                 sta->sta_stats.last_rx_data_pkts = sta->sta_stats.rx_data_pkts; \
483         } while(0)
484
485 #define STA_RX_PKTS_ARG(sta) \
486         sta->sta_stats.rx_mgnt_pkts \
487         , sta->sta_stats.rx_ctrl_pkts \
488         , sta->sta_stats.rx_data_pkts
489
490 #define STA_LAST_RX_PKTS_ARG(sta) \
491         sta->sta_stats.last_rx_mgnt_pkts \
492         , sta->sta_stats.last_rx_ctrl_pkts \
493         , sta->sta_stats.last_rx_data_pkts
494
495 #define STA_RX_PKTS_DIFF_ARG(sta) \
496         sta->sta_stats.rx_mgnt_pkts - sta->sta_stats.last_rx_mgnt_pkts \
497         , sta->sta_stats.rx_ctrl_pkts - sta->sta_stats.last_rx_ctrl_pkts \
498         , sta->sta_stats.rx_data_pkts -sta->sta_stats.last_rx_data_pkts
499
500 #define STA_PKTS_FMT "(m:%llu, c:%llu, d:%llu)"
501
502 #ifdef CONFIG_WFD
503 #define STA_OP_WFD_MODE(sta) (sta)->op_wfd_mode
504 #define STA_SET_OP_WFD_MODE(sta, mode) (sta)->op_wfd_mode = (mode)
505 #else
506 #define STA_OP_WFD_MODE(sta) 0
507 #define STA_SET_OP_WFD_MODE(sta, mode) do {} while (0)
508 #endif
509
510 struct  sta_priv {
511         
512         u8 *pallocated_stainfo_buf;
513         u8 *pstainfo_buf;
514         _queue  free_sta_queue;
515         
516         _lock sta_hash_lock;
517         _list   sta_hash[NUM_STA];
518         int asoc_sta_count;
519         _queue sleep_q;
520         _queue wakeup_q;
521         
522         _adapter *padapter;
523
524         u32 adhoc_expire_to;
525
526 #ifdef CONFIG_AP_MODE
527         _list asoc_list;
528         _list auth_list;
529         _lock asoc_list_lock;
530         _lock auth_list_lock;
531         u8 asoc_list_cnt;
532         u8 auth_list_cnt;
533
534         unsigned int auth_to;  //sec, time to expire in authenticating.
535         unsigned int assoc_to; //sec, time to expire before associating.
536         unsigned int expire_to; //sec , time to expire after associated.
537         
538         /* pointers to STA info; based on allocated AID or NULL if AID free
539          * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
540          * and so on
541          */
542         struct sta_info *sta_aid[NUM_STA];
543
544         u16 sta_dz_bitmap;//only support 15 stations, staion aid bitmap for sleeping sta.
545         u16 tim_bitmap;//only support 15 stations, aid=0~15 mapping bit0~bit15  
546
547         u16 max_num_sta;
548
549         struct wlan_acl_pool acl_list;
550 #endif
551
552 #ifdef CONFIG_ATMEL_RC_PATCH
553         u8 atmel_rc_pattern [6];
554 #endif
555
556 };
557
558
559 static u32 wifi_mac_hash(const u8 *mac)
560 {
561         u32 x;
562
563         x = mac[0];
564         x = (x << 2) ^ mac[1];
565         x = (x << 2) ^ mac[2];
566         x = (x << 2) ^ mac[3];
567         x = (x << 2) ^ mac[4];
568         x = (x << 2) ^ mac[5];
569
570         x ^= x >> 8;
571         x  = x & (NUM_STA - 1);
572                 
573         return x;
574 }
575
576
577 extern u32      _rtw_init_sta_priv(struct sta_priv *pstapriv);
578 extern u32      _rtw_free_sta_priv(struct sta_priv *pstapriv);
579
580 #define stainfo_offset_valid(offset) (offset < NUM_STA && offset >= 0)
581 int rtw_stainfo_offset(struct sta_priv *stapriv, struct sta_info *sta);
582 struct sta_info *rtw_get_stainfo_by_offset(struct sta_priv *stapriv, int offset);
583
584 extern struct sta_info *rtw_alloc_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr);
585 extern u32      rtw_free_stainfo(_adapter *padapter , struct sta_info *psta);
586 extern void rtw_free_all_stainfo(_adapter *padapter);
587 extern struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, const u8 *hwaddr);
588 extern u32 rtw_init_bcmc_stainfo(_adapter* padapter);
589 extern struct sta_info* rtw_get_bcmc_stainfo(_adapter* padapter);
590 extern u8 rtw_access_ctrl(_adapter *padapter, u8 *mac_addr);
591
592 #endif //_STA_INFO_H_
593