0a5e7158d66b7302b358053eac6e363e46539c81
[pandora-kernel.git] / drivers / staging / rtl8187se / ieee80211 / ieee80211.h
1 /*
2  * Merged with mainline ieee80211.h in Aug 2004.  Original ieee802_11
3  * remains copyright by the original authors
4  *
5  * Portions of the merged code are based on Host AP (software wireless
6  * LAN access point) driver for Intersil Prism2/2.5/3.
7  *
8  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
9  * <jkmaline@cc.hut.fi>
10  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
11  *
12  * Adaption to a generic IEEE 802.11 stack by James Ketrenos
13  * <jketreno@linux.intel.com>
14  * Copyright (c) 2004, Intel Corporation
15  *
16  * Modified for Realtek's wi-fi cards by Andrea Merello
17  * <andreamrl@tiscali.it>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License version 2 as
21  * published by the Free Software Foundation. See README and COPYING for
22  * more details.
23  */
24 #ifndef IEEE80211_H
25 #define IEEE80211_H
26 #include <linux/if_ether.h> /* ETH_ALEN */
27 #include <linux/kernel.h>   /* ARRAY_SIZE */
28 #include <linux/version.h>
29 #include <linux/jiffies.h>
30 #include <linux/timer.h>
31 #include <linux/sched.h>
32 #include <linux/wireless.h>
33
34 /*
35 #ifndef bool
36 #define bool int
37 #endif
38
39 #ifndef true
40 #define true   1
41 #endif
42
43 #ifndef false
44 #define false  0
45 #endif
46 */
47
48 #define KEY_TYPE_NA             0x0
49 #define KEY_TYPE_WEP40          0x1
50 #define KEY_TYPE_TKIP           0x2
51 #define KEY_TYPE_CCMP           0x4
52 #define KEY_TYPE_WEP104         0x5
53
54 #define aSifsTime                                       10
55
56 #define MGMT_QUEUE_NUM 5
57
58
59 #define IEEE_CMD_SET_WPA_PARAM                  1
60 #define IEEE_CMD_SET_WPA_IE                     2
61 #define IEEE_CMD_SET_ENCRYPTION                 3
62 #define IEEE_CMD_MLME                           4
63
64 #define IEEE_PARAM_WPA_ENABLED                  1
65 #define IEEE_PARAM_TKIP_COUNTERMEASURES         2
66 #define IEEE_PARAM_DROP_UNENCRYPTED             3
67 #define IEEE_PARAM_PRIVACY_INVOKED              4
68 #define IEEE_PARAM_AUTH_ALGS                    5
69 #define IEEE_PARAM_IEEE_802_1X                  6
70 //It should consistent with the driver_XXX.c
71 //   David, 2006.9.26
72 #define IEEE_PARAM_WPAX_SELECT                  7
73 //Added for notify the encryption type selection
74 //   David, 2006.9.26
75 #define IEEE_PROTO_WPA                          1
76 #define IEEE_PROTO_RSN                          2
77 //Added for notify the encryption type selection
78 //   David, 2006.9.26
79 #define IEEE_WPAX_USEGROUP                      0
80 #define IEEE_WPAX_WEP40                         1
81 #define IEEE_WPAX_TKIP                          2
82 #define IEEE_WPAX_WRAP                          3
83 #define IEEE_WPAX_CCMP                          4
84 #define IEEE_WPAX_WEP104                        5
85
86 #define IEEE_KEY_MGMT_IEEE8021X                 1
87 #define IEEE_KEY_MGMT_PSK                       2
88
89
90
91 #define IEEE_MLME_STA_DEAUTH                    1
92 #define IEEE_MLME_STA_DISASSOC                  2
93
94
95 #define IEEE_CRYPT_ERR_UNKNOWN_ALG              2
96 #define IEEE_CRYPT_ERR_UNKNOWN_ADDR             3
97 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED                4
98 #define IEEE_CRYPT_ERR_KEY_SET_FAILED           5
99 #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED                6
100 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED         7
101
102
103 #define IEEE_CRYPT_ALG_NAME_LEN                 16
104
105 //by amy for ps
106 typedef struct ieee_param {
107         u32 cmd;
108         u8 sta_addr[ETH_ALEN];
109         union {
110                 struct {
111                         u8 name;
112                         u32 value;
113                 } wpa_param;
114                 struct {
115                         u32 len;
116                         u8 reserved[32];
117                         u8 data[0];
118                 } wpa_ie;
119                 struct{
120                         int command;
121                         int reason_code;
122                 } mlme;
123                 struct {
124                         u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
125                         u8 set_tx;
126                         u32 err;
127                         u8 idx;
128                         u8 seq[8]; /* sequence counter (set: RX, get: TX) */
129                         u16 key_len;
130                         u8 key[0];
131                 } crypt;
132
133         } u;
134 }ieee_param;
135
136
137 #define MSECS(t) msecs_to_jiffies(t)
138 #define msleep_interruptible_rtl  msleep_interruptible
139
140 #define IEEE80211_DATA_LEN              2304
141 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
142    6.2.1.1.2.
143
144    The figure in section 7.1.2 suggests a body size of up to 2312
145    bytes is allowed, which is a bit confusing, I suspect this
146    represents the 2304 bytes of real data, plus a possible 8 bytes of
147    WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
148
149
150 #define IEEE80211_HLEN                  30
151 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
152
153 /* this is stolen and modified from the madwifi driver*/
154 #define IEEE80211_FC0_TYPE_MASK         0x0c
155 #define IEEE80211_FC0_TYPE_DATA         0x08
156 #define IEEE80211_FC0_SUBTYPE_MASK      0xB0
157 #define IEEE80211_FC0_SUBTYPE_QOS       0x80
158
159 #define IEEE80211_QOS_HAS_SEQ(fc) \
160         (((fc) & (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) == \
161          (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
162
163 /* this is stolen from ipw2200 driver */
164 #define IEEE_IBSS_MAC_HASH_SIZE 31
165 struct ieee_ibss_seq {
166         u8 mac[ETH_ALEN];
167         u16 seq_num[17];
168         u16 frag_num[17];
169         unsigned long packet_time[17];
170         struct list_head list;
171 };
172
173 struct ieee80211_hdr {
174         u16 frame_ctl;
175         u16 duration_id;
176         u8 addr1[ETH_ALEN];
177         u8 addr2[ETH_ALEN];
178         u8 addr3[ETH_ALEN];
179         u16 seq_ctl;
180         u8 addr4[ETH_ALEN];
181 } __attribute__ ((packed));
182
183 struct ieee80211_hdr_QOS {
184         u16 frame_ctl;
185         u16 duration_id;
186         u8 addr1[ETH_ALEN];
187         u8 addr2[ETH_ALEN];
188         u8 addr3[ETH_ALEN];
189         u16 seq_ctl;
190         u8 addr4[ETH_ALEN];
191         u16 QOS_ctl;
192 } __attribute__ ((packed));
193
194 struct ieee80211_hdr_3addr {
195         u16 frame_ctl;
196         u16 duration_id;
197         u8 addr1[ETH_ALEN];
198         u8 addr2[ETH_ALEN];
199         u8 addr3[ETH_ALEN];
200         u16 seq_ctl;
201 } __attribute__ ((packed));
202
203 struct ieee80211_hdr_3addr_QOS {
204         u16 frame_ctl;
205         u16 duration_id;
206         u8 addr1[ETH_ALEN];
207         u8 addr2[ETH_ALEN];
208         u8 addr3[ETH_ALEN];
209         u16 seq_ctl;
210         u16 QOS_ctl;
211 } __attribute__ ((packed));
212
213 enum eap_type {
214         EAP_PACKET = 0,
215         EAPOL_START,
216         EAPOL_LOGOFF,
217         EAPOL_KEY,
218         EAPOL_ENCAP_ASF_ALERT
219 };
220
221 static const char *eap_types[] = {
222         [EAP_PACKET]            = "EAP-Packet",
223         [EAPOL_START]           = "EAPOL-Start",
224         [EAPOL_LOGOFF]          = "EAPOL-Logoff",
225         [EAPOL_KEY]             = "EAPOL-Key",
226         [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
227 };
228
229 static inline const char *eap_get_type(int type)
230 {
231         return (type >= ARRAY_SIZE(eap_types)) ? "Unknown" : eap_types[type];
232 }
233
234 struct eapol {
235         u8 snap[6];
236         u16 ethertype;
237         u8 version;
238         u8 type;
239         u16 length;
240 } __attribute__ ((packed));
241
242 #define IEEE80211_3ADDR_LEN 24
243 #define IEEE80211_4ADDR_LEN 30
244 #define IEEE80211_FCS_LEN    4
245
246 #define MIN_FRAG_THRESHOLD     256U
247 #define MAX_FRAG_THRESHOLD     2346U
248
249 /* Frame control field constants */
250 #define IEEE80211_FCTL_VERS             0x0002
251 #define IEEE80211_FCTL_FTYPE            0x000c
252 #define IEEE80211_FCTL_STYPE            0x00f0
253 #define IEEE80211_FCTL_TODS             0x0100
254 #define IEEE80211_FCTL_FROMDS           0x0200
255 #define IEEE80211_FCTL_DSTODS           0x0300 //added by david
256 #define IEEE80211_FCTL_MOREFRAGS        0x0400
257 #define IEEE80211_FCTL_RETRY            0x0800
258 #define IEEE80211_FCTL_PM               0x1000
259 #define IEEE80211_FCTL_MOREDATA 0x2000
260 #define IEEE80211_FCTL_WEP              0x4000
261 #define IEEE80211_FCTL_ORDER            0x8000
262
263 #define IEEE80211_FTYPE_MGMT            0x0000
264 #define IEEE80211_FTYPE_CTL             0x0004
265 #define IEEE80211_FTYPE_DATA            0x0008
266
267 /* management */
268 #define IEEE80211_STYPE_ASSOC_REQ       0x0000
269 #define IEEE80211_STYPE_ASSOC_RESP      0x0010
270 #define IEEE80211_STYPE_REASSOC_REQ     0x0020
271 #define IEEE80211_STYPE_REASSOC_RESP    0x0030
272 #define IEEE80211_STYPE_PROBE_REQ       0x0040
273 #define IEEE80211_STYPE_PROBE_RESP      0x0050
274 #define IEEE80211_STYPE_BEACON          0x0080
275 #define IEEE80211_STYPE_ATIM            0x0090
276 #define IEEE80211_STYPE_DISASSOC        0x00A0
277 #define IEEE80211_STYPE_AUTH            0x00B0
278 #define IEEE80211_STYPE_DEAUTH          0x00C0
279 #define IEEE80211_STYPE_MANAGE_ACT      0x00D0
280
281 /* control */
282 #define IEEE80211_STYPE_PSPOLL          0x00A0
283 #define IEEE80211_STYPE_RTS             0x00B0
284 #define IEEE80211_STYPE_CTS             0x00C0
285 #define IEEE80211_STYPE_ACK             0x00D0
286 #define IEEE80211_STYPE_CFEND           0x00E0
287 #define IEEE80211_STYPE_CFENDACK        0x00F0
288
289 /* data */
290 #define IEEE80211_STYPE_DATA            0x0000
291 #define IEEE80211_STYPE_DATA_CFACK      0x0010
292 #define IEEE80211_STYPE_DATA_CFPOLL     0x0020
293 #define IEEE80211_STYPE_DATA_CFACKPOLL  0x0030
294 #define IEEE80211_STYPE_NULLFUNC        0x0040
295 #define IEEE80211_STYPE_CFACK           0x0050
296 #define IEEE80211_STYPE_CFPOLL          0x0060
297 #define IEEE80211_STYPE_CFACKPOLL       0x0070
298 #define IEEE80211_STYPE_QOS_DATA        0x0080 //added for WMM 2006/8/2
299 #define IEEE80211_STYPE_QOS_NULL        0x00C0
300
301
302 #define IEEE80211_SCTL_FRAG             0x000F
303 #define IEEE80211_SCTL_SEQ              0xFFF0
304
305
306 /* debug macros */
307
308 #ifdef CONFIG_IEEE80211_DEBUG
309 extern u32 ieee80211_debug_level;
310 #define IEEE80211_DEBUG(level, fmt, args...) \
311 do { if (ieee80211_debug_level & (level)) \
312   printk(KERN_DEBUG "ieee80211: %c %s " fmt, \
313          in_interrupt() ? 'I' : 'U', __func__ , ## args); } while (0)
314 #else
315 #define IEEE80211_DEBUG(level, fmt, args...) do {} while (0)
316 #endif  /* CONFIG_IEEE80211_DEBUG */
317
318 /*
319  * To use the debug system;
320  *
321  * If you are defining a new debug classification, simply add it to the #define
322  * list here in the form of:
323  *
324  * #define IEEE80211_DL_xxxx VALUE
325  *
326  * shifting value to the left one bit from the previous entry.  xxxx should be
327  * the name of the classification (for example, WEP)
328  *
329  * You then need to either add a IEEE80211_xxxx_DEBUG() macro definition for your
330  * classification, or use IEEE80211_DEBUG(IEEE80211_DL_xxxx, ...) whenever you want
331  * to send output to that classification.
332  *
333  * To add your debug level to the list of levels seen when you perform
334  *
335  * % cat /proc/net/ipw/debug_level
336  *
337  * you simply need to add your entry to the ipw_debug_levels array.
338  *
339  * If you do not see debug_level in /proc/net/ipw then you do not have
340  * CONFIG_IEEE80211_DEBUG defined in your kernel configuration
341  *
342  */
343
344 #define IEEE80211_DL_INFO          (1<<0)
345 #define IEEE80211_DL_WX            (1<<1)
346 #define IEEE80211_DL_SCAN          (1<<2)
347 #define IEEE80211_DL_STATE         (1<<3)
348 #define IEEE80211_DL_MGMT          (1<<4)
349 #define IEEE80211_DL_FRAG          (1<<5)
350 #define IEEE80211_DL_EAP           (1<<6)
351 #define IEEE80211_DL_DROP          (1<<7)
352
353 #define IEEE80211_DL_TX            (1<<8)
354 #define IEEE80211_DL_RX            (1<<9)
355
356 #define IEEE80211_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a)
357 #define IEEE80211_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a)
358 #define IEEE80211_DEBUG_INFO(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_INFO, f, ## a)
359
360 #define IEEE80211_DEBUG_WX(f, a...)     IEEE80211_DEBUG(IEEE80211_DL_WX, f, ## a)
361 #define IEEE80211_DEBUG_SCAN(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_SCAN, f, ## a)
362 //#define IEEE_DEBUG_SCAN  IEEE80211_WARNING
363 #define IEEE80211_DEBUG_STATE(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_STATE, f, ## a)
364 #define IEEE80211_DEBUG_MGMT(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_MGMT, f, ## a)
365 #define IEEE80211_DEBUG_FRAG(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_FRAG, f, ## a)
366 #define IEEE80211_DEBUG_EAP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_EAP, f, ## a)
367 #define IEEE80211_DEBUG_DROP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_DROP, f, ## a)
368 #define IEEE80211_DEBUG_TX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_TX, f, ## a)
369 #define IEEE80211_DEBUG_RX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_RX, f, ## a)
370 #include <linux/netdevice.h>
371 #include <linux/wireless.h>
372 #include <linux/if_arp.h> /* ARPHRD_ETHER */
373
374 #ifndef WIRELESS_SPY
375 #define WIRELESS_SPY            // enable iwspy support
376 #endif
377 #include <net/iw_handler.h>     // new driver API
378
379 #ifndef ETH_P_PAE
380 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
381 #endif /* ETH_P_PAE */
382
383 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
384
385 #ifndef ETH_P_80211_RAW
386 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
387 #endif
388
389 /* IEEE 802.11 defines */
390
391 #define P80211_OUI_LEN 3
392
393 struct ieee80211_snap_hdr {
394
395         u8    dsap;   /* always 0xAA */
396         u8    ssap;   /* always 0xAA */
397         u8    ctrl;   /* always 0x03 */
398         u8    oui[P80211_OUI_LEN];    /* organizational universal id */
399
400 } __attribute__ ((packed));
401
402 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
403
404 #define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
405 #define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
406
407 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
408 #define WLAN_GET_SEQ_SEQ(seq)  ((seq) & IEEE80211_SCTL_SEQ)
409
410 /* Authentication algorithms */
411 #define WLAN_AUTH_OPEN 0
412 #define WLAN_AUTH_SHARED_KEY 1
413
414 #define WLAN_AUTH_CHALLENGE_LEN 128
415
416 #define WLAN_CAPABILITY_BSS (1<<0)
417 #define WLAN_CAPABILITY_IBSS (1<<1)
418 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
419 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
420 #define WLAN_CAPABILITY_PRIVACY (1<<4)
421 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
422 #define WLAN_CAPABILITY_PBCC (1<<6)
423 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
424 #define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
425
426 /* Status codes */
427 #define WLAN_STATUS_SUCCESS 0
428 #define WLAN_STATUS_UNSPECIFIED_FAILURE 1
429 #define WLAN_STATUS_CAPS_UNSUPPORTED 10
430 #define WLAN_STATUS_REASSOC_NO_ASSOC 11
431 #define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
432 #define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
433 #define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
434 #define WLAN_STATUS_CHALLENGE_FAIL 15
435 #define WLAN_STATUS_AUTH_TIMEOUT 16
436 #define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
437 #define WLAN_STATUS_ASSOC_DENIED_RATES 18
438 /* 802.11b */
439 #define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
440 #define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
441 #define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
442
443 /* Reason codes */
444 #define WLAN_REASON_UNSPECIFIED 1
445 #define WLAN_REASON_PREV_AUTH_NOT_VALID 2
446 #define WLAN_REASON_DEAUTH_LEAVING 3
447 #define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
448 #define WLAN_REASON_DISASSOC_AP_BUSY 5
449 #define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
450 #define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
451 #define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
452 #define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
453
454
455 /* Information Element IDs */
456 #define WLAN_EID_SSID 0
457 #define WLAN_EID_SUPP_RATES 1
458 #define WLAN_EID_FH_PARAMS 2
459 #define WLAN_EID_DS_PARAMS 3
460 #define WLAN_EID_CF_PARAMS 4
461 #define WLAN_EID_TIM 5
462 #define WLAN_EID_IBSS_PARAMS 6
463 #define WLAN_EID_CHALLENGE 16
464 #define WLAN_EID_RSN 48
465 #define WLAN_EID_GENERIC 221
466
467 #define IEEE80211_MGMT_HDR_LEN 24
468 #define IEEE80211_DATA_HDR3_LEN 24
469 #define IEEE80211_DATA_HDR4_LEN 30
470
471
472 #define IEEE80211_STATMASK_SIGNAL (1<<0)
473 #define IEEE80211_STATMASK_RSSI (1<<1)
474 #define IEEE80211_STATMASK_NOISE (1<<2)
475 #define IEEE80211_STATMASK_RATE (1<<3)
476 #define IEEE80211_STATMASK_WEMASK 0x7
477
478
479 #define IEEE80211_CCK_MODULATION    (1<<0)
480 #define IEEE80211_OFDM_MODULATION   (1<<1)
481
482 #define IEEE80211_24GHZ_BAND     (1<<0)
483 #define IEEE80211_52GHZ_BAND     (1<<1)
484
485 #define IEEE80211_CCK_RATE_LEN                  4
486 #define IEEE80211_CCK_RATE_1MB                  0x02
487 #define IEEE80211_CCK_RATE_2MB                  0x04
488 #define IEEE80211_CCK_RATE_5MB                  0x0B
489 #define IEEE80211_CCK_RATE_11MB                 0x16
490 #define IEEE80211_OFDM_RATE_LEN                 8
491 #define IEEE80211_OFDM_RATE_6MB                 0x0C
492 #define IEEE80211_OFDM_RATE_9MB                 0x12
493 #define IEEE80211_OFDM_RATE_12MB                0x18
494 #define IEEE80211_OFDM_RATE_18MB                0x24
495 #define IEEE80211_OFDM_RATE_24MB                0x30
496 #define IEEE80211_OFDM_RATE_36MB                0x48
497 #define IEEE80211_OFDM_RATE_48MB                0x60
498 #define IEEE80211_OFDM_RATE_54MB                0x6C
499 #define IEEE80211_BASIC_RATE_MASK               0x80
500
501 #define IEEE80211_CCK_RATE_1MB_MASK             (1<<0)
502 #define IEEE80211_CCK_RATE_2MB_MASK             (1<<1)
503 #define IEEE80211_CCK_RATE_5MB_MASK             (1<<2)
504 #define IEEE80211_CCK_RATE_11MB_MASK            (1<<3)
505 #define IEEE80211_OFDM_RATE_6MB_MASK            (1<<4)
506 #define IEEE80211_OFDM_RATE_9MB_MASK            (1<<5)
507 #define IEEE80211_OFDM_RATE_12MB_MASK           (1<<6)
508 #define IEEE80211_OFDM_RATE_18MB_MASK           (1<<7)
509 #define IEEE80211_OFDM_RATE_24MB_MASK           (1<<8)
510 #define IEEE80211_OFDM_RATE_36MB_MASK           (1<<9)
511 #define IEEE80211_OFDM_RATE_48MB_MASK           (1<<10)
512 #define IEEE80211_OFDM_RATE_54MB_MASK           (1<<11)
513
514 #define IEEE80211_CCK_RATES_MASK                0x0000000F
515 #define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
516         IEEE80211_CCK_RATE_2MB_MASK)
517 #define IEEE80211_CCK_DEFAULT_RATES_MASK        (IEEE80211_CCK_BASIC_RATES_MASK | \
518         IEEE80211_CCK_RATE_5MB_MASK | \
519         IEEE80211_CCK_RATE_11MB_MASK)
520
521 #define IEEE80211_OFDM_RATES_MASK               0x00000FF0
522 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
523         IEEE80211_OFDM_RATE_12MB_MASK | \
524         IEEE80211_OFDM_RATE_24MB_MASK)
525 #define IEEE80211_OFDM_DEFAULT_RATES_MASK       (IEEE80211_OFDM_BASIC_RATES_MASK | \
526         IEEE80211_OFDM_RATE_9MB_MASK  | \
527         IEEE80211_OFDM_RATE_18MB_MASK | \
528         IEEE80211_OFDM_RATE_36MB_MASK | \
529         IEEE80211_OFDM_RATE_48MB_MASK | \
530         IEEE80211_OFDM_RATE_54MB_MASK)
531 #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
532                                 IEEE80211_CCK_DEFAULT_RATES_MASK)
533
534 #define IEEE80211_NUM_OFDM_RATES            8
535 #define IEEE80211_NUM_CCK_RATES             4
536 #define IEEE80211_OFDM_SHIFT_MASK_A         4
537
538
539
540
541 /* NOTE: This data is for statistical purposes; not all hardware provides this
542  *       information for frames received.  Not setting these will not cause
543  *       any adverse affects. */
544 struct ieee80211_rx_stats {
545         u32 mac_time[2];
546         u8 signalstrength;
547         s8 rssi;
548         u8 signal;
549         u8 noise;
550         u16 rate; /* in 100 kbps */
551         u8 received_channel;
552         u8 control;
553         u8 mask;
554         u8 freq;
555         u16 len;
556         u8 nic_type;
557 };
558
559 /* IEEE 802.11 requires that STA supports concurrent reception of at least
560  * three fragmented frames. This define can be increased to support more
561  * concurrent frames, but it should be noted that each entry can consume about
562  * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
563 #define IEEE80211_FRAG_CACHE_LEN 4
564
565 struct ieee80211_frag_entry {
566         unsigned long first_frag_time;
567         unsigned int seq;
568         unsigned int last_frag;
569         struct sk_buff *skb;
570         u8 src_addr[ETH_ALEN];
571         u8 dst_addr[ETH_ALEN];
572 };
573
574 struct ieee80211_stats {
575         unsigned int tx_unicast_frames;
576         unsigned int tx_multicast_frames;
577         unsigned int tx_fragments;
578         unsigned int tx_unicast_octets;
579         unsigned int tx_multicast_octets;
580         unsigned int tx_deferred_transmissions;
581         unsigned int tx_single_retry_frames;
582         unsigned int tx_multiple_retry_frames;
583         unsigned int tx_retry_limit_exceeded;
584         unsigned int tx_discards;
585         unsigned int rx_unicast_frames;
586         unsigned int rx_multicast_frames;
587         unsigned int rx_fragments;
588         unsigned int rx_unicast_octets;
589         unsigned int rx_multicast_octets;
590         unsigned int rx_fcs_errors;
591         unsigned int rx_discards_no_buffer;
592         unsigned int tx_discards_wrong_sa;
593         unsigned int rx_discards_undecryptable;
594         unsigned int rx_message_in_msg_fragments;
595         unsigned int rx_message_in_bad_msg_fragments;
596 };
597
598 struct ieee80211_softmac_stats{
599         unsigned int rx_ass_ok;
600         unsigned int rx_ass_err;
601         unsigned int rx_probe_rq;
602         unsigned int tx_probe_rs;
603         unsigned int tx_beacons;
604         unsigned int rx_auth_rq;
605         unsigned int rx_auth_rs_ok;
606         unsigned int rx_auth_rs_err;
607         unsigned int tx_auth_rq;
608         unsigned int no_auth_rs;
609         unsigned int no_ass_rs;
610         unsigned int tx_ass_rq;
611         unsigned int rx_ass_rq;
612         unsigned int tx_probe_rq;
613         unsigned int reassoc;
614         unsigned int swtxstop;
615         unsigned int swtxawake;
616 };
617
618 struct ieee80211_device;
619
620 #include "ieee80211_crypt.h"
621
622 #define SEC_KEY_1         (1<<0)
623 #define SEC_KEY_2         (1<<1)
624 #define SEC_KEY_3         (1<<2)
625 #define SEC_KEY_4         (1<<3)
626 #define SEC_ACTIVE_KEY    (1<<4)
627 #define SEC_AUTH_MODE     (1<<5)
628 #define SEC_UNICAST_GROUP (1<<6)
629 #define SEC_LEVEL         (1<<7)
630 #define SEC_ENABLED       (1<<8)
631
632 #define SEC_LEVEL_0      0 /* None */
633 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
634 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
635 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
636 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
637
638 #define WEP_KEYS 4
639 #define WEP_KEY_LEN 13
640
641 #define WEP_KEY_LEN_MODIF 32
642
643 struct ieee80211_security {
644         u16 active_key:2,
645             enabled:1,
646             auth_mode:2,
647             auth_algo:4,
648             unicast_uses_group:1;
649         u8 key_sizes[WEP_KEYS];
650         u8 keys[WEP_KEYS][WEP_KEY_LEN_MODIF];
651         u8 level;
652         u16 flags;
653 } __attribute__ ((packed));
654
655
656 /*
657
658  802.11 data frame from AP
659
660       ,-------------------------------------------------------------------.
661 Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
662       |------|------|---------|---------|---------|------|---------|------|
663 Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
664       |      | tion | (BSSID) |         |         | ence |  data   |      |
665       `-------------------------------------------------------------------'
666
667 Total: 28-2340 bytes
668
669 */
670
671 struct ieee80211_header_data {
672         u16 frame_ctl;
673         u16 duration_id;
674         u8 addr1[6];
675         u8 addr2[6];
676         u8 addr3[6];
677         u16 seq_ctrl;
678 };
679
680 #define BEACON_PROBE_SSID_ID_POSITION 12
681
682 /* Management Frame Information Element Types */
683 #define MFIE_TYPE_SSID       0
684 #define MFIE_TYPE_RATES      1
685 #define MFIE_TYPE_FH_SET     2
686 #define MFIE_TYPE_DS_SET     3
687 #define MFIE_TYPE_CF_SET     4
688 #define MFIE_TYPE_TIM        5
689 #define MFIE_TYPE_IBSS_SET   6
690 #define MFIE_TYPE_COUNTRY  7 //+YJ,080625
691 #define MFIE_TYPE_CHALLENGE  16
692 #define MFIE_TYPE_ERP        42
693 #define MFIE_TYPE_RSN        48
694 #define MFIE_TYPE_RATES_EX   50
695 #define MFIE_TYPE_GENERIC    221
696
697 typedef enum
698 {
699         COUNTRY_CODE_FCC = 0,
700         COUNTRY_CODE_IC = 1,
701         COUNTRY_CODE_ETSI = 2,
702         COUNTRY_CODE_SPAIN = 3,
703         COUNTRY_CODE_FRANCE = 4,
704         COUNTRY_CODE_MKK = 5,
705         COUNTRY_CODE_MKK1 = 6,
706         COUNTRY_CODE_ISRAEL = 7,
707         COUNTRY_CODE_TELEC = 8,
708         COUNTRY_CODE_GLOBAL_DOMAIN = 9,
709         COUNTRY_CODE_WORLD_WIDE_13_INDEX = 10
710 }country_code_type_t;
711
712 struct ieee80211_info_element_hdr {
713         u8 id;
714         u8 len;
715 } __attribute__ ((packed));
716
717 struct ieee80211_info_element {
718         u8 id;
719         u8 len;
720         u8 data[0];
721 } __attribute__ ((packed));
722
723 /*
724  * These are the data types that can make up management packets
725  *
726         u16 auth_algorithm;
727         u16 auth_sequence;
728         u16 beacon_interval;
729         u16 capability;
730         u8 current_ap[ETH_ALEN];
731         u16 listen_interval;
732         struct {
733                 u16 association_id:14, reserved:2;
734         } __attribute__ ((packed));
735         u32 time_stamp[2];
736         u16 reason;
737         u16 status;
738 */
739
740 #define IEEE80211_DEFAULT_TX_ESSID "Penguin"
741 #define IEEE80211_DEFAULT_BASIC_RATE 10
742
743 struct ieee80211_authentication {
744         struct ieee80211_header_data header;
745         u16 algorithm;
746         u16 transaction;
747         u16 status;
748         //struct ieee80211_info_element_hdr info_element;
749 } __attribute__ ((packed));
750
751
752 struct ieee80211_probe_response {
753         struct ieee80211_header_data header;
754         u32 time_stamp[2];
755         u16 beacon_interval;
756         u16 capability;
757         struct ieee80211_info_element info_element;
758 } __attribute__ ((packed));
759
760 struct ieee80211_probe_request {
761         struct ieee80211_header_data header;
762         /*struct ieee80211_info_element info_element;*/
763 } __attribute__ ((packed));
764
765 struct ieee80211_assoc_request_frame {
766         struct ieee80211_hdr_3addr header;
767         u16 capability;
768         u16 listen_interval;
769         //u8 current_ap[ETH_ALEN];
770         struct ieee80211_info_element_hdr info_element;
771 } __attribute__ ((packed));
772
773 struct ieee80211_assoc_response_frame {
774         struct ieee80211_hdr_3addr header;
775         u16 capability;
776         u16 status;
777         u16 aid;
778         struct ieee80211_info_element info_element; /* supported rates */
779 } __attribute__ ((packed));
780
781 struct ieee80211_disassoc_frame{
782         struct ieee80211_hdr_3addr header;
783         u16    reasoncode;
784 }__attribute__ ((packed));
785
786 struct ieee80211_txb {
787         u8 nr_frags;
788         u8 encrypted;
789         u16 reserved;
790         u16 frag_size;
791         u16 payload_size;
792         struct sk_buff *fragments[0];
793 };
794
795 struct ieee80211_wmm_ac_param {
796         u8 ac_aci_acm_aifsn;
797         u8 ac_ecwmin_ecwmax;
798         u16 ac_txop_limit;
799 };
800
801 struct ieee80211_wmm_ts_info {
802         u8 ac_dir_tid;
803         u8 ac_up_psb;
804         u8 reserved;
805 } __attribute__ ((packed));
806
807 struct ieee80211_wmm_tspec_elem {
808         struct ieee80211_wmm_ts_info ts_info;
809         u16 norm_msdu_size;
810         u16 max_msdu_size;
811         u32 min_serv_inter;
812         u32 max_serv_inter;
813         u32 inact_inter;
814         u32 suspen_inter;
815         u32 serv_start_time;
816         u32 min_data_rate;
817         u32 mean_data_rate;
818         u32 peak_data_rate;
819         u32 max_burst_size;
820         u32 delay_bound;
821         u32 min_phy_rate;
822         u16 surp_band_allow;
823         u16 medium_time;
824 }__attribute__((packed));
825
826 enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
827 #define MAX_SP_Len  (WMM_all_frame << 4)
828 #define IEEE80211_QOS_TID 0x0f
829 #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
830
831 /* SWEEP TABLE ENTRIES NUMBER*/
832 #define MAX_SWEEP_TAB_ENTRIES             42
833 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
834 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
835  * only use 8, and then use extended rates for the remaining supported
836  * rates.  Other APs, however, stick all of their supported rates on the
837  * main rates information element... */
838 #define MAX_RATES_LENGTH                  ((u8)12)
839 #define MAX_RATES_EX_LENGTH               ((u8)16)
840 #define MAX_NETWORK_COUNT                  128
841 //#define MAX_CHANNEL_NUMBER                 161
842 #define MAX_CHANNEL_NUMBER                 165 //YJ,modified,080625
843 #define MAX_IE_LEN                                              0xFF //+YJ,080625
844
845 typedef struct _CHANNEL_LIST{
846         u8      Channel[MAX_CHANNEL_NUMBER + 1];
847         u8      Len;
848 }CHANNEL_LIST, *PCHANNEL_LIST;
849
850 #define IEEE80211_SOFTMAC_SCAN_TIME       100//400
851 //(HZ / 2)
852 //by amy for ps
853 #define IEEE80211_WATCH_DOG_TIME    2000
854 //by amy for ps
855 //by amy for antenna
856 #define ANTENNA_DIVERSITY_TIMER_PERIOD          1000 // 1000 m
857 //by amy for antenna
858 #define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
859
860 #define CRC_LENGTH                 4U
861
862 #define MAX_WPA_IE_LEN 64
863
864 #define NETWORK_EMPTY_ESSID (1<<0)
865 #define NETWORK_HAS_OFDM    (1<<1)
866 #define NETWORK_HAS_CCK     (1<<2)
867
868 #define IEEE80211_DTIM_MBCAST 4
869 #define IEEE80211_DTIM_UCAST 2
870 #define IEEE80211_DTIM_VALID 1
871 #define IEEE80211_DTIM_INVALID 0
872
873 #define IEEE80211_PS_DISABLED 0
874 #define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
875 #define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
876 #define IEEE80211_PS_ENABLE   IEEE80211_DTIM_VALID
877 //added by David for QoS 2006/6/30
878 //#define WMM_Hang_8187
879 #ifdef WMM_Hang_8187
880 #undef WMM_Hang_8187
881 #endif
882
883 #define WME_AC_BE   0x00
884 #define WME_AC_BK   0x01
885 #define WME_AC_VI   0x02
886 #define WME_AC_VO   0x03
887 #define WME_ACI_MASK 0x03
888 #define WME_AIFSN_MASK 0x03
889 #define WME_AC_PRAM_LEN 16
890
891 //UP Mapping to AC, using in MgntQuery_SequenceNumber() and maybe for DSCP
892 //#define UP2AC(up)     ((up<3) ? ((up==0)?1:0) : (up>>1))
893 #define UP2AC(up) (                \
894         ((up) < 1) ? WME_AC_BE : \
895         ((up) < 3) ? WME_AC_BK : \
896         ((up) < 4) ? WME_AC_BE : \
897         ((up) < 6) ? WME_AC_VI : \
898         WME_AC_VO)
899 //AC Mapping to UP, using in Tx part for selecting the corresponding TX queue
900 #define AC2UP(_ac)      (       \
901         ((_ac) == WME_AC_VO) ? 6 : \
902         ((_ac) == WME_AC_VI) ? 5 : \
903         ((_ac) == WME_AC_BK) ? 1 : \
904         0)
905
906 #define ETHER_ADDR_LEN          6       /* length of an Ethernet address */
907 struct  ether_header {
908         u8 ether_dhost[ETHER_ADDR_LEN];
909         u8 ether_shost[ETHER_ADDR_LEN];
910         u16 ether_type;
911 } __attribute__((packed));
912
913 #ifndef ETHERTYPE_PAE
914 #define ETHERTYPE_PAE   0x888e          /* EAPOL PAE/802.1x */
915 #endif
916 #ifndef ETHERTYPE_IP
917 #define ETHERTYPE_IP    0x0800          /* IP protocol */
918 #endif
919
920 struct ieee80211_network {
921         /* These entries are used to identify a unique network */
922         u8 bssid[ETH_ALEN];
923         u8 channel;
924         /* Ensure null-terminated for any debug msgs */
925         u8 ssid[IW_ESSID_MAX_SIZE + 1];
926         u8 ssid_len;
927
928         /* These are network statistics */
929         struct ieee80211_rx_stats stats;
930         u16 capability;
931         u8 rates[MAX_RATES_LENGTH];
932         u8 rates_len;
933         u8 rates_ex[MAX_RATES_EX_LENGTH];
934         u8 rates_ex_len;
935         unsigned long last_scanned;
936         u8 mode;
937         u8 flags;
938         u32 last_associate;
939         u32 time_stamp[2];
940         u16 beacon_interval;
941         u16 listen_interval;
942         u16 atim_window;
943         u8 wpa_ie[MAX_WPA_IE_LEN];
944         size_t wpa_ie_len;
945         u8 rsn_ie[MAX_WPA_IE_LEN];
946         size_t rsn_ie_len;
947         u8 dtim_period;
948         u8 dtim_data;
949         u32 last_dtim_sta_time[2];
950         struct list_head list;
951         //appeded for QoS
952         u8 wmm_info;
953         struct ieee80211_wmm_ac_param wmm_param[4];
954         u8 QoS_Enable;
955         u8 SignalStrength;
956 //by amy 080312
957         u8 HighestOperaRate;
958 //by amy 080312
959         u8 Turbo_Enable;//enable turbo mode, added by thomas
960         u16 CountryIeLen;
961         u8 CountryIeBuf[MAX_IE_LEN];
962 };
963
964 enum ieee80211_state {
965
966         /* the card is not linked at all */
967         IEEE80211_NOLINK = 0,
968
969         /* IEEE80211_ASSOCIATING* are for BSS client mode
970          * the driver shall not perform RX filtering unless
971          * the state is LINKED.
972          * The driver shall just check for the state LINKED and
973          * defaults to NOLINK for ALL the other states (including
974          * LINKED_SCANNING)
975          */
976
977         /* the association procedure will start (wq scheduling)*/
978         IEEE80211_ASSOCIATING,
979         IEEE80211_ASSOCIATING_RETRY,
980
981         /* the association procedure is sending AUTH request*/
982         IEEE80211_ASSOCIATING_AUTHENTICATING,
983
984         /* the association procedure has successfully authentcated
985          * and is sending association request
986          */
987         IEEE80211_ASSOCIATING_AUTHENTICATED,
988
989         /* the link is ok. the card associated to a BSS or linked
990          * to a ibss cell or acting as an AP and creating the bss
991          */
992         IEEE80211_LINKED,
993
994         /* same as LINKED, but the driver shall apply RX filter
995          * rules as we are in NO_LINK mode. As the card is still
996          * logically linked, but it is doing a syncro site survey
997          * then it will be back to LINKED state.
998          */
999         IEEE80211_LINKED_SCANNING,
1000
1001 };
1002
1003 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1004 #define DEFAULT_FTS 2346
1005 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
1006 #define MAC_ARG(x) ((u8*)(x))[0],((u8*)(x))[1],((u8*)(x))[2],((u8*)(x))[3],((u8*)(x))[4],((u8*)(x))[5]
1007
1008 #define CFG_IEEE80211_RESERVE_FCS (1<<0)
1009 #define CFG_IEEE80211_COMPUTE_FCS (1<<1)
1010
1011 typedef struct tx_pending_t{
1012         int frag;
1013         struct ieee80211_txb *txb;
1014 }tx_pending_t;
1015
1016
1017 struct ieee80211_device {
1018         struct net_device *dev;
1019
1020         /* Bookkeeping structures */
1021         struct net_device_stats stats;
1022         struct ieee80211_stats ieee_stats;
1023         struct ieee80211_softmac_stats softmac_stats;
1024
1025         /* Probe / Beacon management */
1026         struct list_head network_free_list;
1027         struct list_head network_list;
1028         struct ieee80211_network *networks;
1029         int scans;
1030         int scan_age;
1031
1032         int iw_mode; /* operating mode (IW_MODE_*) */
1033
1034         spinlock_t lock;
1035         spinlock_t wpax_suitlist_lock;
1036
1037         int tx_headroom; /* Set to size of any additional room needed at front
1038                           * of allocated Tx SKBs */
1039         u32 config;
1040
1041         /* WEP and other encryption related settings at the device level */
1042         int open_wep; /* Set to 1 to allow unencrypted frames */
1043
1044         int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
1045                                  * WEP key changes */
1046
1047         /* If the host performs {en,de}cryption, then set to 1 */
1048         int host_encrypt;
1049         int host_decrypt;
1050         int ieee802_1x; /* is IEEE 802.1X used */
1051
1052         /* WPA data */
1053         int wpa_enabled;
1054         int drop_unencrypted;
1055         int tkip_countermeasures;
1056         int privacy_invoked;
1057         size_t wpa_ie_len;
1058         u8 *wpa_ie;
1059
1060         u8 ap_mac_addr[6];
1061         u16 pairwise_key_type;
1062         u16 broadcast_key_type;
1063
1064         struct list_head crypt_deinit_list;
1065         struct ieee80211_crypt_data *crypt[WEP_KEYS];
1066         int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
1067         struct timer_list crypt_deinit_timer;
1068
1069         int bcrx_sta_key; /* use individual keys to override default keys even
1070                            * with RX of broad/multicast frames */
1071
1072         /* Fragmentation structures */
1073         // each streaming contain a entry
1074         struct ieee80211_frag_entry frag_cache[17][IEEE80211_FRAG_CACHE_LEN];
1075         unsigned int frag_next_idx[17];
1076         u16 fts; /* Fragmentation Threshold */
1077
1078         /* This stores infos for the current network.
1079          * Either the network we are associated in INFRASTRUCTURE
1080          * or the network that we are creating in MASTER mode.
1081          * ad-hoc is a mixture ;-).
1082          * Note that in infrastructure mode, even when not associated,
1083          * fields bssid and essid may be valid (if wpa_set and essid_set
1084          * are true) as thy carry the value set by the user via iwconfig
1085          */
1086         struct ieee80211_network current_network;
1087
1088
1089         enum ieee80211_state state;
1090
1091         int short_slot;
1092         int mode;       /* A, B, G */
1093         int modulation; /* CCK, OFDM */
1094         int freq_band;  /* 2.4Ghz, 5.2Ghz, Mixed */
1095         int abg_true;   /* ABG flag              */
1096
1097         /* used for forcing the ibss workqueue to terminate
1098          * without wait for the syncro scan to terminate
1099          */
1100         short sync_scan_hurryup;
1101
1102         void * pDot11dInfo;
1103         bool bGlobalDomain;
1104
1105         // For Liteon Ch12~13 passive scan
1106         u8      MinPassiveChnlNum;
1107         u8      IbssStartChnl;
1108
1109         int rate;       /* current rate */
1110         int basic_rate;
1111         //FIXME: pleace callback, see if redundant with softmac_features
1112         short active_scan;
1113
1114         /* this contains flags for selectively enable softmac support */
1115         u16 softmac_features;
1116
1117         /* if the sequence control field is not filled by HW */
1118         u16 seq_ctrl[5];
1119
1120         /* association procedure transaction sequence number */
1121         u16 associate_seq;
1122
1123         /* AID for RTXed association responses */
1124         u16 assoc_id;
1125
1126         /* power save mode related*/
1127         short ps;
1128         short sta_sleep;
1129         int ps_timeout;
1130         struct tasklet_struct ps_task;
1131         u32 ps_th;
1132         u32 ps_tl;
1133
1134         short raw_tx;
1135         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1136         short queue_stop;
1137         short scanning;
1138         short proto_started;
1139
1140         struct semaphore wx_sem;
1141         struct semaphore scan_sem;
1142
1143         spinlock_t mgmt_tx_lock;
1144         spinlock_t beacon_lock;
1145
1146         short beacon_txing;
1147
1148         short wap_set;
1149         short ssid_set;
1150
1151         u8  wpax_type_set;    //{added by David, 2006.9.28}
1152         u32 wpax_type_notify; //{added by David, 2006.9.26}
1153
1154         /* QoS related flag */
1155         char init_wmmparam_flag;
1156
1157         /* for discarding duplicated packets in IBSS */
1158         struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
1159
1160         /* for discarding duplicated packets in BSS */
1161         u16 last_rxseq_num[17]; /* rx seq previous per-tid */
1162         u16 last_rxfrag_num[17];/* tx frag previous per-tid */
1163         unsigned long last_packet_time[17];
1164
1165         /* for PS mode */
1166         unsigned long last_rx_ps_time;
1167
1168         /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
1169         struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
1170         int mgmt_queue_head;
1171         int mgmt_queue_tail;
1172
1173
1174         /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1175         struct  tx_pending_t tx_pending;
1176
1177         /* used if IEEE_SOFTMAC_ASSOCIATE is set */
1178         struct timer_list associate_timer;
1179
1180         /* used if IEEE_SOFTMAC_BEACONS is set */
1181         struct timer_list beacon_timer;
1182
1183         struct work_struct associate_complete_wq;
1184 //      struct work_struct associate_retry_wq;
1185         struct work_struct associate_procedure_wq;
1186 //      struct work_struct softmac_scan_wq;
1187         struct work_struct wx_sync_scan_wq;
1188         struct work_struct wmm_param_update_wq;
1189         struct work_struct ps_request_tx_ack_wq;//for ps
1190 //      struct work_struct hw_wakeup_wq;
1191 //      struct work_struct hw_sleep_wq;
1192 //      struct work_struct watch_dog_wq;
1193         bool bInactivePs;
1194         bool actscanning;
1195         bool beinretry;
1196         u16 ListenInterval;
1197         unsigned long NumRxDataInPeriod; //YJ,add,080828
1198         unsigned long NumRxBcnInPeriod;  //YJ,add,080828
1199         unsigned long NumRxOkTotal;
1200         unsigned long NumRxUnicast;//YJ,add,080828,for keep alive
1201         bool bHwRadioOff;
1202         struct delayed_work softmac_scan_wq;
1203         struct delayed_work associate_retry_wq;
1204         struct delayed_work hw_wakeup_wq;
1205         struct delayed_work hw_sleep_wq;//+by amy 080324
1206         struct delayed_work watch_dog_wq;
1207         struct delayed_work sw_antenna_wq;
1208         struct delayed_work  start_ibss_wq;
1209 //by amy for rate adaptive 080312
1210     struct delayed_work rate_adapter_wq;
1211 //by amy for rate adaptive
1212         struct delayed_work hw_dig_wq;
1213         struct delayed_work tx_pw_wq;
1214
1215 //Added for RF power on power off by lizhaoming 080512
1216         struct delayed_work GPIOChangeRFWorkItem;
1217
1218         struct workqueue_struct *wq;
1219
1220         /* Callback functions */
1221         void (*set_security)(struct net_device *dev,
1222                              struct ieee80211_security *sec);
1223
1224         /* Used to TX data frame by using txb structs.
1225          * this is not used if in the softmac_features
1226          * is set the flag IEEE_SOFTMAC_TX_QUEUE
1227          */
1228         int (*hard_start_xmit)(struct ieee80211_txb *txb,
1229                                struct net_device *dev);
1230
1231         int (*reset_port)(struct net_device *dev);
1232
1233         /* Softmac-generated frames (mamagement) are TXed via this
1234          * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
1235          * not set. As some cards may have different HW queues that
1236          * one might want to use for data and management frames
1237          * the option to have two callbacks might be useful.
1238          * This fucntion can't sleep.
1239          */
1240         int (*softmac_hard_start_xmit)(struct sk_buff *skb,
1241                                struct net_device *dev);
1242
1243         /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
1244          * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
1245          * frames. I the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
1246          * then also management frames are sent via this callback.
1247          * This function can't sleep.
1248          */
1249         void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
1250                                struct net_device *dev,int rate);
1251
1252         /* stops the HW queue for DATA frames. Useful to avoid
1253          * waste time to TX data frame when we are reassociating
1254          * This function can sleep.
1255          */
1256         void (*data_hard_stop)(struct net_device *dev);
1257
1258         /* OK this is complementar to data_poll_hard_stop */
1259         void (*data_hard_resume)(struct net_device *dev);
1260
1261         /* ask to the driver to retune the radio .
1262          * This function can sleep. the driver should ensure
1263          * the radio has been swithced before return.
1264          */
1265         void (*set_chan)(struct net_device *dev,short ch);
1266
1267         /* These are not used if the ieee stack takes care of
1268          * scanning (IEEE_SOFTMAC_SCAN feature set).
1269          * In this case only the set_chan is used.
1270          *
1271          * The syncro version is similar to the start_scan but
1272          * does not return until all channels has been scanned.
1273          * this is called in user context and should sleep,
1274          * it is called in a work_queue when swithcing to ad-hoc mode
1275          * or in behalf of iwlist scan when the card is associated
1276          * and root user ask for a scan.
1277          * the fucntion stop_scan should stop both the syncro and
1278          * background scanning and can sleep.
1279          * The fucntion start_scan should initiate the background
1280          * scanning and can't sleep.
1281          */
1282         void (*scan_syncro)(struct net_device *dev);
1283         void (*start_scan)(struct net_device *dev);
1284         void (*stop_scan)(struct net_device *dev);
1285
1286         /* indicate the driver that the link state is changed
1287          * for example it may indicate the card is associated now.
1288          * Driver might be interested in this to apply RX filter
1289          * rules or simply light the LINK led
1290          */
1291         void (*link_change)(struct net_device *dev);
1292
1293         /* these two function indicates to the HW when to start
1294          * and stop to send beacons. This is used when the
1295          * IEEE_SOFTMAC_BEACONS is not set. For now the
1296          * stop_send_bacons is NOT guaranteed to be called only
1297          * after start_send_beacons.
1298          */
1299         void (*start_send_beacons) (struct net_device *dev);
1300         void (*stop_send_beacons) (struct net_device *dev);
1301
1302         /* power save mode related */
1303         void (*sta_wake_up) (struct net_device *dev);
1304         void (*ps_request_tx_ack) (struct net_device *dev);
1305         void (*enter_sleep_state) (struct net_device *dev, u32 th, u32 tl);
1306         short (*ps_is_queue_empty) (struct net_device *dev);
1307
1308         /* QoS related */
1309         //void (*wmm_param_update) (struct net_device *dev, u8 *ac_param);
1310         //void (*wmm_param_update) (struct ieee80211_device *ieee);
1311
1312         /* This must be the last item so that it points to the data
1313          * allocated beyond this structure by alloc_ieee80211 */
1314         u8 priv[0];
1315 };
1316
1317 #define IEEE_A            (1<<0)
1318 #define IEEE_B            (1<<1)
1319 #define IEEE_G            (1<<2)
1320 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
1321
1322 /* Generate a 802.11 header */
1323
1324 /* Uses the channel change callback directly
1325  * instead of [start/stop] scan callbacks
1326  */
1327 #define IEEE_SOFTMAC_SCAN (1<<2)
1328
1329 /* Perform authentication and association handshake */
1330 #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
1331
1332 /* Generate probe requests */
1333 #define IEEE_SOFTMAC_PROBERQ (1<<4)
1334
1335 /* Generate respones to probe requests */
1336 #define IEEE_SOFTMAC_PROBERS (1<<5)
1337
1338 /* The ieee802.11 stack will manages the netif queue
1339  * wake/stop for the driver, taking care of 802.11
1340  * fragmentation. See softmac.c for details. */
1341 #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
1342
1343 /* Uses only the softmac_data_hard_start_xmit
1344  * even for TX management frames.
1345  */
1346 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
1347
1348 /* Generate beacons.  The stack will enqueue beacons
1349  * to the card
1350  */
1351 #define IEEE_SOFTMAC_BEACONS (1<<6)
1352
1353
1354
1355 static inline void *ieee80211_priv(struct net_device *dev)
1356 {
1357         return ((struct ieee80211_device *)netdev_priv(dev))->priv;
1358 }
1359
1360 extern inline int ieee80211_is_empty_essid(const char *essid, int essid_len)
1361 {
1362         /* Single white space is for Linksys APs */
1363         if (essid_len == 1 && essid[0] == ' ')
1364                 return 1;
1365
1366         /* Otherwise, if the entire essid is 0, we assume it is hidden */
1367         while (essid_len) {
1368                 essid_len--;
1369                 if (essid[essid_len] != '\0')
1370                         return 0;
1371         }
1372
1373         return 1;
1374 }
1375
1376 extern inline int ieee80211_is_valid_mode(struct ieee80211_device *ieee, int mode)
1377 {
1378         /*
1379          * It is possible for both access points and our device to support
1380          * combinations of modes, so as long as there is one valid combination
1381          * of ap/device supported modes, then return success
1382          *
1383          */
1384         if ((mode & IEEE_A) &&
1385             (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
1386             (ieee->freq_band & IEEE80211_52GHZ_BAND))
1387                 return 1;
1388
1389         if ((mode & IEEE_G) &&
1390             (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
1391             (ieee->freq_band & IEEE80211_24GHZ_BAND))
1392                 return 1;
1393
1394         if ((mode & IEEE_B) &&
1395             (ieee->modulation & IEEE80211_CCK_MODULATION) &&
1396             (ieee->freq_band & IEEE80211_24GHZ_BAND))
1397                 return 1;
1398
1399         return 0;
1400 }
1401
1402 extern inline int ieee80211_get_hdrlen(u16 fc)
1403 {
1404         int hdrlen = 24;
1405
1406         switch (WLAN_FC_GET_TYPE(fc)) {
1407         case IEEE80211_FTYPE_DATA:
1408                 if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
1409                         hdrlen = 30; /* Addr4 */
1410                 if(IEEE80211_QOS_HAS_SEQ(fc))
1411                         hdrlen += 2; /* QOS ctrl*/
1412                 break;
1413         case IEEE80211_FTYPE_CTL:
1414                 switch (WLAN_FC_GET_STYPE(fc)) {
1415                 case IEEE80211_STYPE_CTS:
1416                 case IEEE80211_STYPE_ACK:
1417                         hdrlen = 10;
1418                         break;
1419                 default:
1420                         hdrlen = 16;
1421                         break;
1422                 }
1423                 break;
1424         }
1425
1426         return hdrlen;
1427 }
1428
1429
1430
1431 /* ieee80211.c */
1432 extern void free_ieee80211(struct net_device *dev);
1433 extern struct net_device *alloc_ieee80211(int sizeof_priv);
1434
1435 extern int ieee80211_set_encryption(struct ieee80211_device *ieee);
1436
1437 /* ieee80211_tx.c */
1438
1439 extern int ieee80211_encrypt_fragment(
1440         struct ieee80211_device *ieee,
1441         struct sk_buff *frag,
1442         int hdr_len);
1443
1444 extern int ieee80211_xmit(struct sk_buff *skb,
1445                           struct net_device *dev);
1446 extern void ieee80211_txb_free(struct ieee80211_txb *);
1447
1448
1449 /* ieee80211_rx.c */
1450 extern int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
1451                         struct ieee80211_rx_stats *rx_stats);
1452 extern void ieee80211_rx_mgt(struct ieee80211_device *ieee,
1453                              struct ieee80211_hdr *header,
1454                              struct ieee80211_rx_stats *stats);
1455
1456 /* ieee80211_wx.c */
1457 extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
1458                                  struct iw_request_info *info,
1459                                  union iwreq_data *wrqu, char *key);
1460 extern int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
1461                                    struct iw_request_info *info,
1462                                    union iwreq_data *wrqu, char *key);
1463 extern int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
1464                                    struct iw_request_info *info,
1465                                    union iwreq_data *wrqu, char *key);
1466 extern int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
1467                             struct iw_request_info *info,
1468                             union iwreq_data* wrqu, char *extra);
1469 int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
1470                                struct iw_request_info *info,
1471                                struct iw_param *data, char *extra);
1472 int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
1473                                struct iw_request_info *info,
1474                                union iwreq_data *wrqu, char *extra);
1475
1476 int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len);
1477 /* ieee80211_softmac.c */
1478 extern short ieee80211_is_54g(struct ieee80211_network net);
1479 extern short ieee80211_is_shortslot(struct ieee80211_network net);
1480 extern int ieee80211_rx_frame_softmac(struct ieee80211_device *ieee, struct sk_buff *skb,
1481                         struct ieee80211_rx_stats *rx_stats, u16 type,
1482                         u16 stype);
1483 extern void ieee80211_softmac_new_net(struct ieee80211_device *ieee, struct ieee80211_network *net);
1484
1485 extern void ieee80211_softmac_xmit(struct ieee80211_txb *txb, struct ieee80211_device *ieee);
1486 extern void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee);
1487 extern void ieee80211_start_bss(struct ieee80211_device *ieee);
1488 extern void ieee80211_start_master_bss(struct ieee80211_device *ieee);
1489 extern void ieee80211_start_ibss(struct ieee80211_device *ieee);
1490 extern void ieee80211_softmac_init(struct ieee80211_device *ieee);
1491 extern void ieee80211_softmac_free(struct ieee80211_device *ieee);
1492 extern void ieee80211_associate_abort(struct ieee80211_device *ieee);
1493 extern void ieee80211_disassociate(struct ieee80211_device *ieee);
1494 extern void ieee80211_stop_scan(struct ieee80211_device *ieee);
1495 extern void ieee80211_start_scan_syncro(struct ieee80211_device *ieee);
1496 extern void ieee80211_check_all_nets(struct ieee80211_device *ieee);
1497 extern void ieee80211_start_protocol(struct ieee80211_device *ieee);
1498 extern void ieee80211_stop_protocol(struct ieee80211_device *ieee);
1499 extern void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee);
1500 extern void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee);
1501 extern void ieee80211_reset_queue(struct ieee80211_device *ieee);
1502 extern void ieee80211_wake_queue(struct ieee80211_device *ieee);
1503 extern void ieee80211_stop_queue(struct ieee80211_device *ieee);
1504 extern struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee);
1505 extern void ieee80211_start_send_beacons(struct ieee80211_device *ieee);
1506 extern void ieee80211_stop_send_beacons(struct ieee80211_device *ieee);
1507 extern int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee, struct iw_point *p);
1508 extern void notify_wx_assoc_event(struct ieee80211_device *ieee);
1509 extern void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success);
1510 extern void SendDisassociation(struct ieee80211_device *ieee,u8* asSta,u8 asRsn);
1511 extern void ieee80211_start_scan(struct ieee80211_device *ieee);
1512
1513 //Add for RF power on power off by lizhaoming 080512
1514 extern void SendDisassociation(struct ieee80211_device *ieee,
1515                          u8*                     asSta,
1516                          u8                      asRsn);
1517
1518 /* ieee80211_crypt_ccmp&tkip&wep.c */
1519 extern void ieee80211_tkip_null(void);
1520 extern void ieee80211_wep_null(void);
1521 extern void ieee80211_ccmp_null(void);
1522 /* ieee80211_softmac_wx.c */
1523
1524 extern int ieee80211_wx_get_wap(struct ieee80211_device *ieee,
1525                             struct iw_request_info *info,
1526                             union iwreq_data *wrqu, char *ext);
1527
1528 extern int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
1529                          struct iw_request_info *info,
1530                          union iwreq_data *awrq,
1531                          char *extra);
1532
1533 extern int ieee80211_wx_get_essid(struct ieee80211_device *ieee, struct iw_request_info *a,union iwreq_data *wrqu,char *b);
1534
1535 extern int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
1536                              struct iw_request_info *info,
1537                              union iwreq_data *wrqu, char *extra);
1538
1539 extern int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
1540                              struct iw_request_info *info,
1541                              union iwreq_data *wrqu, char *extra);
1542
1543 extern int ieee80211_wx_set_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
1544                              union iwreq_data *wrqu, char *b);
1545
1546 extern int ieee80211_wx_set_scan(struct ieee80211_device *ieee, struct iw_request_info *a,
1547                              union iwreq_data *wrqu, char *b);
1548
1549 extern int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
1550                               struct iw_request_info *a,
1551                               union iwreq_data *wrqu, char *extra);
1552
1553 extern int ieee80211_wx_get_mode(struct ieee80211_device *ieee, struct iw_request_info *a,
1554                              union iwreq_data *wrqu, char *b);
1555
1556 extern int ieee80211_wx_set_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
1557                              union iwreq_data *wrqu, char *b);
1558
1559 extern int ieee80211_wx_get_freq(struct ieee80211_device *ieee, struct iw_request_info *a,
1560                              union iwreq_data *wrqu, char *b);
1561
1562 extern void ieee80211_wx_sync_scan_wq(struct work_struct *work);
1563
1564 extern int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
1565                                struct iw_request_info *info,
1566                                union iwreq_data *wrqu, char *extra);
1567
1568 extern int ieee80211_wx_get_name(struct ieee80211_device *ieee,
1569                              struct iw_request_info *info,
1570                              union iwreq_data *wrqu, char *extra);
1571
1572 extern int ieee80211_wx_set_power(struct ieee80211_device *ieee,
1573                                  struct iw_request_info *info,
1574                                  union iwreq_data *wrqu, char *extra);
1575
1576 extern int ieee80211_wx_get_power(struct ieee80211_device *ieee,
1577                                  struct iw_request_info *info,
1578                                  union iwreq_data *wrqu, char *extra);
1579
1580 extern void ieee80211_softmac_ips_scan_syncro(struct ieee80211_device *ieee);
1581
1582 extern void ieee80211_sta_ps_send_null_frame(struct ieee80211_device *ieee, short pwr);
1583
1584 extern const long ieee80211_wlan_frequencies[];
1585
1586 extern inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
1587 {
1588         ieee->scans++;
1589 }
1590
1591 extern inline int ieee80211_get_scans(struct ieee80211_device *ieee)
1592 {
1593         return ieee->scans;
1594 }
1595
1596 static inline const char *escape_essid(const char *essid, u8 essid_len) {
1597         static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
1598         const char *s = essid;
1599         char *d = escaped;
1600
1601         if (ieee80211_is_empty_essid(essid, essid_len)) {
1602                 memcpy(escaped, "<hidden>", sizeof("<hidden>"));
1603                 return escaped;
1604         }
1605
1606         essid_len = min(essid_len, (u8)IW_ESSID_MAX_SIZE);
1607         while (essid_len--) {
1608                 if (*s == '\0') {
1609                         *d++ = '\\';
1610                         *d++ = '0';
1611                         s++;
1612                 } else {
1613                         *d++ = *s++;
1614                 }
1615         }
1616         *d = '\0';
1617         return escaped;
1618 }
1619 #endif /* IEEE80211_H */