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