Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Merged with mainline ieee80211.h in Aug 2004.  Original ieee802_11
0004  * remains copyright by the original authors
0005  *
0006  * Portions of the merged code are based on Host AP (software wireless
0007  * LAN access point) driver for Intersil Prism2/2.5/3.
0008  *
0009  * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
0010  * <jkmaline@cc.hut.fi>
0011  * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
0012  *
0013  * Adaption to a generic IEEE 802.11 stack by James Ketrenos
0014  * <jketreno@linux.intel.com>
0015  * Copyright (c) 2004, Intel Corporation
0016  *
0017  * Modified for Realtek's wi-fi cards by Andrea Merello
0018  * <andrea.merello@gmail.com>
0019  */
0020 #ifndef IEEE80211_H
0021 #define IEEE80211_H
0022 #include <linux/if_ether.h> /* ETH_ALEN */
0023 #include <linux/kernel.h>
0024 #include <linux/module.h>
0025 #include <linux/jiffies.h>
0026 #include <linux/timer.h>
0027 #include <linux/sched.h>
0028 #include <linux/semaphore.h>
0029 #include <linux/interrupt.h>
0030 
0031 #include <linux/delay.h>
0032 #include <linux/wireless.h>
0033 #include <linux/ieee80211.h>
0034 
0035 #include "rtl819x_HT.h"
0036 #include "rtl819x_BA.h"
0037 #include "rtl819x_TS.h"
0038 
0039 
0040 #ifndef IW_MODE_MONITOR
0041 #define IW_MODE_MONITOR 6
0042 #endif
0043 
0044 #ifndef IWEVCUSTOM
0045 #define IWEVCUSTOM 0x8c02
0046 #endif
0047 
0048 #define KEY_TYPE_NA     0x0
0049 #define KEY_TYPE_WEP40      0x1
0050 #define KEY_TYPE_TKIP       0x2
0051 #define KEY_TYPE_CCMP       0x4
0052 #define KEY_TYPE_WEP104     0x5
0053 
0054 /* added for rtl819x tx procedure */
0055 #define MAX_QUEUE_SIZE      0x10
0056 
0057 //
0058 // 8190 queue mapping
0059 //
0060 #define BK_QUEUE                               0
0061 #define BE_QUEUE                               1
0062 #define VI_QUEUE                               2
0063 #define VO_QUEUE                               3
0064 #define HCCA_QUEUE                             4
0065 #define TXCMD_QUEUE                            5
0066 #define MGNT_QUEUE                             6
0067 #define HIGH_QUEUE                             7
0068 #define BEACON_QUEUE                           8
0069 
0070 #define LOW_QUEUE                              BE_QUEUE
0071 #define NORMAL_QUEUE                           MGNT_QUEUE
0072 
0073 //added by amy for ps
0074 #define SWRF_TIMEOUT                50
0075 
0076 //added by amy for LEAP related
0077 #define IE_CISCO_FLAG_POSITION      0x08    // Flag byte: byte 8, numbered from 0.
0078 #define SUPPORT_CKIP_MIC            0x08    // bit3
0079 #define SUPPORT_CKIP_PK         0x10    // bit4
0080 /* defined for skb cb field */
0081 /* At most 28 byte */
0082 struct cb_desc {
0083     /* Tx Desc Related flags (8-9) */
0084     u8 bLastIniPkt:1;
0085     u8 bCmdOrInit:1;
0086     u8 bFirstSeg:1;
0087     u8 bLastSeg:1;
0088     u8 bEncrypt:1;
0089     u8 bTxDisableRateFallBack:1;
0090     u8 bTxUseDriverAssingedRate:1;
0091     u8 bHwSec:1; //indicate whether use Hw security. WB
0092 
0093     u8 reserved1;
0094 
0095     /* Tx Firmware Relaged flags (10-11)*/
0096     u8 bCTSEnable:1;
0097     u8 bRTSEnable:1;
0098     u8 bUseShortGI:1;
0099     u8 bUseShortPreamble:1;
0100     u8 bTxEnableFwCalcDur:1;
0101     u8 bAMPDUEnable:1;
0102     u8 bRTSSTBC:1;
0103     u8 RTSSC:1;
0104 
0105     u8 bRTSBW:1;
0106     u8 bPacketBW:1;
0107     u8 bRTSUseShortPreamble:1;
0108     u8 bRTSUseShortGI:1;
0109     u8 bMulticast:1;
0110     u8 bBroadcast:1;
0111     //u8 reserved2:2;
0112     u8 drv_agg_enable:1;
0113     u8 reserved2:1;
0114 
0115     /* Tx Desc related element(12-19) */
0116     u8 rata_index;
0117     u8 queue_index;
0118     //u8 reserved3;
0119     //u8 reserved4;
0120     u16 txbuf_size;
0121     //u8 reserved5;
0122     u8 RATRIndex;
0123     u8 reserved6;
0124     u8 reserved7;
0125     u8 reserved8;
0126 
0127     /* Tx firmware related element(20-27) */
0128     u8 data_rate;
0129     u8 rts_rate;
0130     u8 ampdu_factor;
0131     u8 ampdu_density;
0132     //u8 reserved9;
0133     //u8 reserved10;
0134     //u8 reserved11;
0135     u8 DrvAggrNum;
0136     u16 pkt_size;
0137     u8 reserved12;
0138 };
0139 
0140 /*--------------------------Define -------------------------------------------*/
0141 #define MGN_1M                  0x02
0142 #define MGN_2M                  0x04
0143 #define MGN_5_5M                0x0b
0144 #define MGN_11M                 0x16
0145 
0146 #define MGN_6M                  0x0c
0147 #define MGN_9M                  0x12
0148 #define MGN_12M                 0x18
0149 #define MGN_18M                 0x24
0150 #define MGN_24M                 0x30
0151 #define MGN_36M                 0x48
0152 #define MGN_48M                 0x60
0153 #define MGN_54M                 0x6c
0154 
0155 #define MGN_MCS0                0x80
0156 #define MGN_MCS1                0x81
0157 #define MGN_MCS2                0x82
0158 #define MGN_MCS3                0x83
0159 #define MGN_MCS4                0x84
0160 #define MGN_MCS5                0x85
0161 #define MGN_MCS6                0x86
0162 #define MGN_MCS7                0x87
0163 #define MGN_MCS8                0x88
0164 #define MGN_MCS9                0x89
0165 #define MGN_MCS10               0x8a
0166 #define MGN_MCS11               0x8b
0167 #define MGN_MCS12               0x8c
0168 #define MGN_MCS13               0x8d
0169 #define MGN_MCS14               0x8e
0170 #define MGN_MCS15               0x8f
0171 
0172 #define aSifsTime ((priv->ieee80211->current_network.mode == IEEE_A ||     \
0173             priv->ieee80211->current_network.mode == IEEE_N_24G || \
0174             priv->ieee80211->current_network.mode == IEEE_N_5G) ?  \
0175            16 : 10)
0176 
0177 #define MGMT_QUEUE_NUM 5
0178 
0179 #define IEEE_CMD_SET_WPA_PARAM          1
0180 #define IEEE_CMD_SET_WPA_IE         2
0181 #define IEEE_CMD_SET_ENCRYPTION         3
0182 #define IEEE_CMD_MLME               4
0183 
0184 #define IEEE_PARAM_WPA_ENABLED          1
0185 #define IEEE_PARAM_TKIP_COUNTERMEASURES     2
0186 #define IEEE_PARAM_DROP_UNENCRYPTED     3
0187 #define IEEE_PARAM_PRIVACY_INVOKED      4
0188 #define IEEE_PARAM_AUTH_ALGS            5
0189 #define IEEE_PARAM_IEEE_802_1X          6
0190 //It should consistent with the driver_XXX.c
0191 //   David, 2006.9.26
0192 #define IEEE_PARAM_WPAX_SELECT          7
0193 //Added for notify the encryption type selection
0194 //   David, 2006.9.26
0195 #define IEEE_PROTO_WPA              1
0196 #define IEEE_PROTO_RSN              2
0197 //Added for notify the encryption type selection
0198 //   David, 2006.9.26
0199 #define IEEE_WPAX_USEGROUP          0
0200 #define IEEE_WPAX_WEP40             1
0201 #define IEEE_WPAX_TKIP              2
0202 #define IEEE_WPAX_WRAP              3
0203 #define IEEE_WPAX_CCMP              4
0204 #define IEEE_WPAX_WEP104            5
0205 
0206 #define IEEE_KEY_MGMT_IEEE8021X         1
0207 #define IEEE_KEY_MGMT_PSK           2
0208 
0209 #define IEEE_MLME_STA_DEAUTH            1
0210 #define IEEE_MLME_STA_DISASSOC          2
0211 
0212 
0213 #define IEEE_CRYPT_ERR_UNKNOWN_ALG      2
0214 #define IEEE_CRYPT_ERR_UNKNOWN_ADDR     3
0215 #define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED    4
0216 #define IEEE_CRYPT_ERR_KEY_SET_FAILED       5
0217 #define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED    6
0218 #define IEEE_CRYPT_ERR_CARD_CONF_FAILED     7
0219 
0220 
0221 #define IEEE_CRYPT_ALG_NAME_LEN         16
0222 
0223 #define MAX_IE_LEN  0xff
0224 
0225 // added for kernel conflict
0226 #define ieee80211_crypt_deinit_entries  ieee80211_crypt_deinit_entries_rsl
0227 #define ieee80211_crypt_deinit_handler  ieee80211_crypt_deinit_handler_rsl
0228 #define ieee80211_crypt_delayed_deinit  ieee80211_crypt_delayed_deinit_rsl
0229 #define ieee80211_register_crypto_ops   ieee80211_register_crypto_ops_rsl
0230 #define ieee80211_unregister_crypto_ops ieee80211_unregister_crypto_ops_rsl
0231 #define ieee80211_get_crypto_ops    ieee80211_get_crypto_ops_rsl
0232 
0233 #define ieee80211_ccmp_null     ieee80211_ccmp_null_rsl
0234 
0235 #define ieee80211_tkip_null     ieee80211_tkip_null_rsl
0236 
0237 #define free_ieee80211          free_ieee80211_rsl
0238 #define alloc_ieee80211         alloc_ieee80211_rsl
0239 
0240 #define ieee80211_rx            ieee80211_rx_rsl
0241 #define ieee80211_rx_mgt        ieee80211_rx_mgt_rsl
0242 
0243 #define ieee80211_get_beacon        ieee80211_get_beacon_rsl
0244 #define ieee80211_wake_queue        ieee80211_wake_queue_rsl
0245 #define ieee80211_stop_queue        ieee80211_stop_queue_rsl
0246 #define ieee80211_reset_queue       ieee80211_reset_queue_rsl
0247 #define ieee80211_softmac_stop_protocol ieee80211_softmac_stop_protocol_rsl
0248 #define ieee80211_softmac_start_protocol ieee80211_softmac_start_protocol_rsl
0249 #define ieee80211_is_shortslot      ieee80211_is_shortslot_rsl
0250 #define ieee80211_is_54g        ieee80211_is_54g_rsl
0251 #define ieee80211_wpa_supplicant_ioctl  ieee80211_wpa_supplicant_ioctl_rsl
0252 #define ieee80211_ps_tx_ack     ieee80211_ps_tx_ack_rsl
0253 #define ieee80211_softmac_xmit      ieee80211_softmac_xmit_rsl
0254 #define ieee80211_stop_send_beacons ieee80211_stop_send_beacons_rsl
0255 #define notify_wx_assoc_event       notify_wx_assoc_event_rsl
0256 #define SendDisassociation      SendDisassociation_rsl
0257 #define ieee80211_disassociate      ieee80211_disassociate_rsl
0258 #define ieee80211_start_send_beacons    ieee80211_start_send_beacons_rsl
0259 #define ieee80211_stop_scan     ieee80211_stop_scan_rsl
0260 #define ieee80211_send_probe_requests   ieee80211_send_probe_requests_rsl
0261 #define ieee80211_softmac_scan_syncro   ieee80211_softmac_scan_syncro_rsl
0262 #define ieee80211_start_scan_syncro ieee80211_start_scan_syncro_rsl
0263 
0264 #define ieee80211_wx_get_essid      ieee80211_wx_get_essid_rsl
0265 #define ieee80211_wx_set_essid      ieee80211_wx_set_essid_rsl
0266 #define ieee80211_wx_set_rate       ieee80211_wx_set_rate_rsl
0267 #define ieee80211_wx_get_rate       ieee80211_wx_get_rate_rsl
0268 #define ieee80211_wx_set_wap        ieee80211_wx_set_wap_rsl
0269 #define ieee80211_wx_get_wap        ieee80211_wx_get_wap_rsl
0270 #define ieee80211_wx_set_mode       ieee80211_wx_set_mode_rsl
0271 #define ieee80211_wx_get_mode       ieee80211_wx_get_mode_rsl
0272 #define ieee80211_wx_set_scan       ieee80211_wx_set_scan_rsl
0273 #define ieee80211_wx_get_freq       ieee80211_wx_get_freq_rsl
0274 #define ieee80211_wx_set_freq       ieee80211_wx_set_freq_rsl
0275 #define ieee80211_wx_set_rawtx      ieee80211_wx_set_rawtx_rsl
0276 #define ieee80211_wx_get_name       ieee80211_wx_get_name_rsl
0277 #define ieee80211_wx_set_power      ieee80211_wx_set_power_rsl
0278 #define ieee80211_wx_get_power      ieee80211_wx_get_power_rsl
0279 #define ieee80211_wlan_frequencies  ieee80211_wlan_frequencies_rsl
0280 #define ieee80211_wx_set_rts        ieee80211_wx_set_rts_rsl
0281 #define ieee80211_wx_get_rts        ieee80211_wx_get_rts_rsl
0282 
0283 #define ieee80211_txb_free      ieee80211_txb_free_rsl
0284 
0285 #define ieee80211_wx_set_gen_ie     ieee80211_wx_set_gen_ie_rsl
0286 #define ieee80211_wx_get_scan       ieee80211_wx_get_scan_rsl
0287 #define ieee80211_wx_set_encode     ieee80211_wx_set_encode_rsl
0288 #define ieee80211_wx_get_encode     ieee80211_wx_get_encode_rsl
0289 #define ieee80211_wx_set_mlme       ieee80211_wx_set_mlme_rsl
0290 #define ieee80211_wx_set_auth       ieee80211_wx_set_auth_rsl
0291 #define ieee80211_wx_set_encode_ext ieee80211_wx_set_encode_ext_rsl
0292 #define ieee80211_wx_get_encode_ext ieee80211_wx_get_encode_ext_rsl
0293 
0294 
0295 struct ieee_param {
0296     u32 cmd;
0297     u8 sta_addr[ETH_ALEN];
0298     union {
0299         struct {
0300             u8 name;
0301             u32 value;
0302         } wpa_param;
0303         struct {
0304             u32 len;
0305             u8 reserved[32];
0306             u8 data[];
0307         } wpa_ie;
0308         struct{
0309             int command;
0310             int reason_code;
0311         } mlme;
0312         struct {
0313             u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
0314             u8 set_tx;
0315             u32 err;
0316             u8 idx;
0317             u8 seq[8]; /* sequence counter (set: RX, get: TX) */
0318             u16 key_len;
0319             u8 key[];
0320         } crypt;
0321     } u;
0322 };
0323 
0324 
0325 // linux under 2.6.9 release may not support it, so modify it for common use
0326 #define IEEE80211_DATA_LEN      2304
0327 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
0328  *   6.2.1.1.2.
0329  *
0330  *   The figure in section 7.1.2 suggests a body size of up to 2312
0331  *   bytes is allowed, which is a bit confusing, I suspect this
0332  *   represents the 2304 bytes of real data, plus a possible 8 bytes of
0333  *   WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro)
0334  */
0335 #define IEEE80211_1ADDR_LEN 10
0336 #define IEEE80211_2ADDR_LEN 16
0337 #define IEEE80211_3ADDR_LEN 24
0338 #define IEEE80211_4ADDR_LEN 30
0339 #define IEEE80211_FCS_LEN    4
0340 #define IEEE80211_HLEN                  (IEEE80211_4ADDR_LEN)
0341 #define IEEE80211_FRAME_LEN             (IEEE80211_DATA_LEN + IEEE80211_HLEN)
0342 #define IEEE80211_MGMT_HDR_LEN 24
0343 #define IEEE80211_DATA_HDR3_LEN 24
0344 #define IEEE80211_DATA_HDR4_LEN 30
0345 
0346 #define MIN_FRAG_THRESHOLD     256U
0347 #define MAX_FRAG_THRESHOLD     2346U
0348 
0349 
0350 /* Frame control field constants */
0351 #define IEEE80211_FCTL_VERS     0x0003
0352 #define IEEE80211_FCTL_FTYPE        0x000c
0353 #define IEEE80211_FCTL_STYPE        0x00f0
0354 #define IEEE80211_FCTL_FRAMETYPE    0x00fc
0355 #define IEEE80211_FCTL_TODS     0x0100
0356 #define IEEE80211_FCTL_FROMDS       0x0200
0357 #define IEEE80211_FCTL_DSTODS       0x0300 //added by david
0358 #define IEEE80211_FCTL_MOREFRAGS    0x0400
0359 #define IEEE80211_FCTL_RETRY        0x0800
0360 #define IEEE80211_FCTL_PM       0x1000
0361 #define IEEE80211_FCTL_MOREDATA     0x2000
0362 #define IEEE80211_FCTL_WEP      0x4000
0363 #define IEEE80211_FCTL_ORDER        0x8000
0364 
0365 #define IEEE80211_FTYPE_MGMT        0x0000
0366 #define IEEE80211_FTYPE_CTL     0x0004
0367 #define IEEE80211_FTYPE_DATA        0x0008
0368 
0369 /* management */
0370 #define IEEE80211_STYPE_ASSOC_REQ   0x0000
0371 #define IEEE80211_STYPE_ASSOC_RESP  0x0010
0372 #define IEEE80211_STYPE_REASSOC_REQ 0x0020
0373 #define IEEE80211_STYPE_REASSOC_RESP    0x0030
0374 #define IEEE80211_STYPE_PROBE_REQ   0x0040
0375 #define IEEE80211_STYPE_PROBE_RESP  0x0050
0376 #define IEEE80211_STYPE_BEACON      0x0080
0377 #define IEEE80211_STYPE_ATIM        0x0090
0378 #define IEEE80211_STYPE_DISASSOC    0x00A0
0379 #define IEEE80211_STYPE_AUTH        0x00B0
0380 #define IEEE80211_STYPE_DEAUTH      0x00C0
0381 #define IEEE80211_STYPE_MANAGE_ACT  0x00D0
0382 
0383 /* control */
0384 #define IEEE80211_STYPE_PSPOLL      0x00A0
0385 #define IEEE80211_STYPE_RTS     0x00B0
0386 #define IEEE80211_STYPE_CTS     0x00C0
0387 #define IEEE80211_STYPE_ACK     0x00D0
0388 #define IEEE80211_STYPE_CFEND       0x00E0
0389 #define IEEE80211_STYPE_CFENDACK    0x00F0
0390 #define IEEE80211_STYPE_BLOCKACK    0x0094
0391 
0392 /* data */
0393 #define IEEE80211_STYPE_DATA        0x0000
0394 #define IEEE80211_STYPE_DATA_CFACK  0x0010
0395 #define IEEE80211_STYPE_DATA_CFPOLL 0x0020
0396 #define IEEE80211_STYPE_DATA_CFACKPOLL  0x0030
0397 #define IEEE80211_STYPE_NULLFUNC    0x0040
0398 #define IEEE80211_STYPE_CFACK       0x0050
0399 #define IEEE80211_STYPE_CFPOLL      0x0060
0400 #define IEEE80211_STYPE_CFACKPOLL   0x0070
0401 #define IEEE80211_STYPE_QOS_DATA    0x0080 //added for WMM 2006/8/2
0402 #define IEEE80211_STYPE_QOS_NULL    0x00C0
0403 
0404 #define IEEE80211_SCTL_FRAG     0x000F
0405 #define IEEE80211_SCTL_SEQ      0xFFF0
0406 
0407 /* QOS control */
0408 #define IEEE80211_QCTL_TID              0x000F
0409 
0410 #define FC_QOS_BIT                  BIT(7)
0411 #define IsDataFrame(pdu)            (((pdu[0] & 0x0C) == 0x08) ? true : false)
0412 #define IsLegacyDataFrame(pdu)  (IsDataFrame(pdu) && (!(pdu[0] & FC_QOS_BIT)))
0413 //added by wb. Is this right?
0414 #define IsQoSDataFrame(pframe)  ((*(u16 *)pframe & (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA)) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
0415 #define Frame_Order(pframe)     (*(u16 *)pframe & IEEE80211_FCTL_ORDER)
0416 #define SN_LESS(a, b)       (((a - b) & 0x800) != 0)
0417 #define SN_EQUAL(a, b)  (a == b)
0418 #define MAX_DEV_ADDR_SIZE 8
0419 typedef enum _ACT_CATEGORY {
0420     ACT_CAT_QOS = 1,
0421     ACT_CAT_DLS = 2,
0422     ACT_CAT_BA  = 3,
0423     ACT_CAT_HT  = 7,
0424     ACT_CAT_WMM = 17,
0425 } ACT_CATEGORY, *PACT_CATEGORY;
0426 
0427 typedef enum _TS_ACTION {
0428     ACT_ADDTSREQ = 0,
0429     ACT_ADDTSRSP = 1,
0430     ACT_DELTS    = 2,
0431     ACT_SCHEDULE = 3,
0432 } TS_ACTION, *PTS_ACTION;
0433 
0434 typedef enum _BA_ACTION {
0435     ACT_ADDBAREQ = 0,
0436     ACT_ADDBARSP = 1,
0437     ACT_DELBA    = 2,
0438 } BA_ACTION, *PBA_ACTION;
0439 
0440 typedef enum _InitialGainOpType {
0441     IG_Backup = 0,
0442     IG_Restore,
0443     IG_Max
0444 } InitialGainOpType;
0445 
0446 /* debug macros */
0447 #define CONFIG_IEEE80211_DEBUG
0448 #ifdef CONFIG_IEEE80211_DEBUG
0449 extern u32 ieee80211_debug_level;
0450 #define IEEE80211_DEBUG(level, fmt, args...) \
0451 do { if (ieee80211_debug_level & (level)) \
0452   printk(KERN_DEBUG "ieee80211: " fmt, ## args); } while (0)
0453 //wb added to debug out data buf
0454 //if you want print DATA buffer related BA, please set ieee80211_debug_level to DATA|BA
0455 #define IEEE80211_DEBUG_DATA(level, data, datalen)                             \
0456     do { if ((ieee80211_debug_level & (level)) == (level))                 \
0457         {                                                              \
0458             int i;                                                 \
0459             u8 *pdata = (u8 *)data;                                \
0460             printk(KERN_DEBUG "ieee80211: %s()\n", __func__);      \
0461             for (i = 0; i < (int)(datalen); i++) {                 \
0462                 printk("%2x ", pdata[i]);                      \
0463                 if ((i + 1) % 16 == 0)                         \
0464                     printk("\n");                          \
0465             }                                                      \
0466             printk("\n");                                          \
0467         }                                                              \
0468     } while (0)
0469 #else
0470 #define IEEE80211_DEBUG(level, fmt, args...)
0471 #define IEEE80211_DEBUG_DATA(level, data, datalen)
0472 #endif  /* CONFIG_IEEE80211_DEBUG */
0473 
0474 /* debug macros not dependent on CONFIG_IEEE80211_DEBUG */
0475 
0476 /*
0477  * To use the debug system;
0478  *
0479  * If you are defining a new debug classification, simply add it to the #define
0480  * list here in the form of:
0481  *
0482  * #define IEEE80211_DL_xxxx VALUE
0483  *
0484  * shifting value to the left one bit from the previous entry.  xxxx should be
0485  * the name of the classification (for example, WEP)
0486  *
0487  * You then need to either add a IEEE80211_xxxx_DEBUG() macro definition for your
0488  * classification, or use IEEE80211_DEBUG(IEEE80211_DL_xxxx, ...) whenever you want
0489  * to send output to that classification.
0490  *
0491  * To add your debug level to the list of levels seen when you perform
0492  *
0493  * % cat /proc/net/ipw/debug_level
0494  *
0495  * you simply need to add your entry to the ipw_debug_levels array.
0496  *
0497  * If you do not see debug_level in /proc/net/ipw then you do not have
0498  * CONFIG_IEEE80211_DEBUG defined in your kernel configuration
0499  *
0500  */
0501 
0502 #define IEEE80211_DL_INFO          (1<<0)
0503 #define IEEE80211_DL_WX            (1<<1)
0504 #define IEEE80211_DL_SCAN          (1<<2)
0505 #define IEEE80211_DL_STATE         (1<<3)
0506 #define IEEE80211_DL_MGMT          (1<<4)
0507 #define IEEE80211_DL_FRAG          (1<<5)
0508 #define IEEE80211_DL_EAP           (1<<6)
0509 #define IEEE80211_DL_DROP          (1<<7)
0510 
0511 #define IEEE80211_DL_TX            (1<<8)
0512 #define IEEE80211_DL_RX            (1<<9)
0513 
0514 #define IEEE80211_DL_HT        (1<<10)  //HT
0515 #define IEEE80211_DL_BA        (1<<11)  //ba
0516 #define IEEE80211_DL_TS        (1<<12)  //TS
0517 #define IEEE80211_DL_QOS           (1<<13)
0518 #define IEEE80211_DL_REORDER       (1<<14)
0519 #define IEEE80211_DL_IOT       (1<<15)
0520 #define IEEE80211_DL_IPS       (1<<16)
0521 #define IEEE80211_DL_TRACE     (1<<29)  //trace function, need to user net_ratelimit() together in order not to print too much to the screen
0522 #define IEEE80211_DL_DATA      (1<<30)   //use this flag to control whether print data buf out.
0523 #define IEEE80211_DL_ERR       (1<<31)   //always open
0524 #define IEEE80211_ERROR(f, a...) printk(KERN_ERR "ieee80211: " f, ## a)
0525 #define IEEE80211_WARNING(f, a...) printk(KERN_WARNING "ieee80211: " f, ## a)
0526 #define IEEE80211_DEBUG_INFO(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_INFO, f, ## a)
0527 
0528 #define IEEE80211_DEBUG_WX(f, a...)     IEEE80211_DEBUG(IEEE80211_DL_WX, f, ## a)
0529 #define IEEE80211_DEBUG_SCAN(f, a...)   IEEE80211_DEBUG(IEEE80211_DL_SCAN, f, ## a)
0530 #define IEEE80211_DEBUG_STATE(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_STATE, f, ## a)
0531 #define IEEE80211_DEBUG_MGMT(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_MGMT, f, ## a)
0532 #define IEEE80211_DEBUG_FRAG(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_FRAG, f, ## a)
0533 #define IEEE80211_DEBUG_EAP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_EAP, f, ## a)
0534 #define IEEE80211_DEBUG_DROP(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_DROP, f, ## a)
0535 #define IEEE80211_DEBUG_TX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_TX, f, ## a)
0536 #define IEEE80211_DEBUG_RX(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_RX, f, ## a)
0537 #define IEEE80211_DEBUG_QOS(f, a...)  IEEE80211_DEBUG(IEEE80211_DL_QOS, f, ## a)
0538 
0539 #include <linux/if_arp.h> /* ARPHRD_ETHER */
0540 
0541 #ifndef WIRELESS_SPY
0542 #define WIRELESS_SPY        // enable iwspy support
0543 #endif
0544 #include <net/iw_handler.h> // new driver API
0545 
0546 #ifndef ETH_P_PAE
0547 #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
0548 #endif /* ETH_P_PAE */
0549 
0550 #define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
0551 
0552 #ifndef ETH_P_80211_RAW
0553 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
0554 #endif
0555 
0556 /* IEEE 802.11 defines */
0557 
0558 #define P80211_OUI_LEN 3
0559 
0560 struct ieee80211_snap_hdr {
0561 
0562     u8    dsap;   /* always 0xAA */
0563     u8    ssap;   /* always 0xAA */
0564     u8    ctrl;   /* always 0x03 */
0565     u8    oui[P80211_OUI_LEN];    /* organizational universal id */
0566 
0567 } __packed;
0568 
0569 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
0570 
0571 #define WLAN_FC_GET_VERS(fc) ((fc) & IEEE80211_FCTL_VERS)
0572 #define WLAN_FC_GET_TYPE(fc) ((fc) & IEEE80211_FCTL_FTYPE)
0573 #define WLAN_FC_GET_STYPE(fc) ((fc) & IEEE80211_FCTL_STYPE)
0574 
0575 #define WLAN_FC_GET_FRAMETYPE(fc) ((fc) & IEEE80211_FCTL_FRAMETYPE)
0576 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & IEEE80211_SCTL_FRAG)
0577 #define WLAN_GET_SEQ_SEQ(seq)  (((seq) & IEEE80211_SCTL_SEQ) >> 4)
0578 
0579 #define WLAN_CAPABILITY_BSS (1<<0)
0580 #define WLAN_CAPABILITY_IBSS (1<<1)
0581 #define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
0582 #define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
0583 #define WLAN_CAPABILITY_PRIVACY (1<<4)
0584 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
0585 #define WLAN_CAPABILITY_PBCC (1<<6)
0586 #define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
0587 #define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
0588 #define WLAN_CAPABILITY_QOS (1<<9)
0589 #define WLAN_CAPABILITY_SHORT_SLOT (1<<10)
0590 #define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
0591 
0592 /* 802.11g ERP information element */
0593 #define WLAN_ERP_NON_ERP_PRESENT (1<<0)
0594 #define WLAN_ERP_USE_PROTECTION (1<<1)
0595 #define WLAN_ERP_BARKER_PREAMBLE (1<<2)
0596 
0597 #define IEEE80211_STATMASK_SIGNAL (1<<0)
0598 #define IEEE80211_STATMASK_RSSI (1<<1)
0599 #define IEEE80211_STATMASK_NOISE (1<<2)
0600 #define IEEE80211_STATMASK_RATE (1<<3)
0601 #define IEEE80211_STATMASK_WEMASK 0x7
0602 
0603 #define IEEE80211_CCK_MODULATION    (1<<0)
0604 #define IEEE80211_OFDM_MODULATION   (1<<1)
0605 
0606 #define IEEE80211_24GHZ_BAND     (1<<0)
0607 #define IEEE80211_52GHZ_BAND     (1<<1)
0608 
0609 #define IEEE80211_CCK_RATE_LEN          4
0610 #define IEEE80211_CCK_RATE_1MB          0x02
0611 #define IEEE80211_CCK_RATE_2MB          0x04
0612 #define IEEE80211_CCK_RATE_5MB          0x0B
0613 #define IEEE80211_CCK_RATE_11MB         0x16
0614 #define IEEE80211_OFDM_RATE_LEN         8
0615 #define IEEE80211_OFDM_RATE_6MB         0x0C
0616 #define IEEE80211_OFDM_RATE_9MB         0x12
0617 #define IEEE80211_OFDM_RATE_12MB        0x18
0618 #define IEEE80211_OFDM_RATE_18MB        0x24
0619 #define IEEE80211_OFDM_RATE_24MB        0x30
0620 #define IEEE80211_OFDM_RATE_36MB        0x48
0621 #define IEEE80211_OFDM_RATE_48MB        0x60
0622 #define IEEE80211_OFDM_RATE_54MB        0x6C
0623 #define IEEE80211_BASIC_RATE_MASK       0x80
0624 
0625 #define IEEE80211_CCK_RATE_1MB_MASK     (1<<0)
0626 #define IEEE80211_CCK_RATE_2MB_MASK     (1<<1)
0627 #define IEEE80211_CCK_RATE_5MB_MASK     (1<<2)
0628 #define IEEE80211_CCK_RATE_11MB_MASK        (1<<3)
0629 #define IEEE80211_OFDM_RATE_6MB_MASK        (1<<4)
0630 #define IEEE80211_OFDM_RATE_9MB_MASK        (1<<5)
0631 #define IEEE80211_OFDM_RATE_12MB_MASK       (1<<6)
0632 #define IEEE80211_OFDM_RATE_18MB_MASK       (1<<7)
0633 #define IEEE80211_OFDM_RATE_24MB_MASK       (1<<8)
0634 #define IEEE80211_OFDM_RATE_36MB_MASK       (1<<9)
0635 #define IEEE80211_OFDM_RATE_48MB_MASK       (1<<10)
0636 #define IEEE80211_OFDM_RATE_54MB_MASK       (1<<11)
0637 
0638 #define IEEE80211_CCK_RATES_MASK        0x0000000F
0639 #define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
0640     IEEE80211_CCK_RATE_2MB_MASK)
0641 #define IEEE80211_CCK_DEFAULT_RATES_MASK    (IEEE80211_CCK_BASIC_RATES_MASK | \
0642     IEEE80211_CCK_RATE_5MB_MASK | \
0643     IEEE80211_CCK_RATE_11MB_MASK)
0644 
0645 #define IEEE80211_OFDM_RATES_MASK       0x00000FF0
0646 #define IEEE80211_OFDM_BASIC_RATES_MASK (IEEE80211_OFDM_RATE_6MB_MASK | \
0647     IEEE80211_OFDM_RATE_12MB_MASK | \
0648     IEEE80211_OFDM_RATE_24MB_MASK)
0649 #define IEEE80211_OFDM_DEFAULT_RATES_MASK   (IEEE80211_OFDM_BASIC_RATES_MASK | \
0650     IEEE80211_OFDM_RATE_9MB_MASK  | \
0651     IEEE80211_OFDM_RATE_18MB_MASK | \
0652     IEEE80211_OFDM_RATE_36MB_MASK | \
0653     IEEE80211_OFDM_RATE_48MB_MASK | \
0654     IEEE80211_OFDM_RATE_54MB_MASK)
0655 #define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
0656                 IEEE80211_CCK_DEFAULT_RATES_MASK)
0657 
0658 #define IEEE80211_NUM_OFDM_RATES        8
0659 #define IEEE80211_NUM_CCK_RATES         4
0660 #define IEEE80211_OFDM_SHIFT_MASK_A         4
0661 
0662 
0663 /* this is stolen and modified from the madwifi driver*/
0664 #define IEEE80211_FC0_TYPE_MASK     0x0c
0665 #define IEEE80211_FC0_TYPE_DATA     0x08
0666 #define IEEE80211_FC0_SUBTYPE_MASK  0xB0
0667 #define IEEE80211_FC0_SUBTYPE_QOS   0x80
0668 
0669 #define IEEE80211_QOS_HAS_SEQ(fc) \
0670     (((fc) & (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_MASK)) == \
0671      (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS))
0672 
0673 /* this is stolen from ipw2200 driver */
0674 #define IEEE_IBSS_MAC_HASH_SIZE 31
0675 struct ieee_ibss_seq {
0676     u8 mac[ETH_ALEN];
0677     u16 seq_num[17];
0678     u16 frag_num[17];
0679     unsigned long packet_time[17];
0680     struct list_head list;
0681 };
0682 
0683 /* NOTE: This data is for statistical purposes; not all hardware provides this
0684  *       information for frames received.  Not setting these will not cause
0685  *       any adverse affects.
0686  */
0687 struct ieee80211_rx_stats {
0688     u32 mac_time[2];
0689     s8 rssi;
0690     u8 signal;
0691     u8 noise;
0692     u16 rate; /* in 100 kbps */
0693     u8 received_channel;
0694     u8 control;
0695     u8 mask;
0696     u8 freq;
0697     u16 len;
0698     u64 tsf;
0699     u32 beacon_time;
0700     u8 nic_type;
0701     u16       Length;
0702     //      u8        DataRate;      // In 0.5 Mbps
0703     u8        SignalQuality; // in 0-100 index.
0704     s32       RecvSignalPower; // Real power in dBm for this packet, no beautification and aggregation.
0705     s8        RxPower; // in dBm Translate from PWdB
0706     u8        SignalStrength; // in 0-100 index.
0707     u16       bHwError:1;
0708     u16       bCRC:1;
0709     u16       bICV:1;
0710     u16       bShortPreamble:1;
0711     u16       Antenna:1;      //for rtl8185
0712     u16       Decrypted:1;    //for rtl8185, rtl8187
0713     u16       Wakeup:1;       //for rtl8185
0714     u16       Reserved0:1;    //for rtl8185
0715     u8        AGC;
0716     u32       TimeStampLow;
0717     u32       TimeStampHigh;
0718     bool      bShift;
0719     bool      bIsQosData;             // Added by Annie, 2005-12-22.
0720     u8        UserPriority;
0721 
0722     //1!!!!!!!!!!!!!!!!!!!!!!!!!!!
0723     //1Attention Please!!!<11n or 8190 specific code should be put below this line>
0724     //1!!!!!!!!!!!!!!!!!!!!!!!!!!!
0725 
0726     u8        RxDrvInfoSize;
0727     u8        RxBufShift;
0728     bool      bIsAMPDU;
0729     bool      bFirstMPDU;
0730     bool      bContainHTC;
0731     bool      RxIs40MHzPacket;
0732     u32       RxPWDBAll;
0733     u8        RxMIMOSignalStrength[4];        // in 0~100 index
0734     s8        RxMIMOSignalQuality[2];
0735     bool      bPacketMatchBSSID;
0736     bool      bIsCCK;
0737     bool      bPacketToSelf;
0738     //added by amy
0739     u8        *virtual_address;
0740     u16          packetlength;              // Total packet length: Must equal to sum of all FragLength
0741     u16          fraglength;                        // FragLength should equal to PacketLength in non-fragment case
0742     u16          fragoffset;                        // Data offset for this fragment
0743     u16          ntotalfrag;
0744     bool          bisrxaggrsubframe;
0745     bool          bPacketBeacon;    //cosa add for rssi
0746     bool          bToSelfBA;        //cosa add for rssi
0747     s8        cck_adc_pwdb[4];  //cosa add for rx path selection
0748     u16       Seq_Num;
0749 
0750 };
0751 
0752 /* IEEE 802.11 requires that STA supports concurrent reception of at least
0753  * three fragmented frames. This define can be increased to support more
0754  * concurrent frames, but it should be noted that each entry can consume about
0755  * 2 kB of RAM and increasing cache size will slow down frame reassembly.
0756  */
0757 #define IEEE80211_FRAG_CACHE_LEN 4
0758 
0759 struct ieee80211_frag_entry {
0760     unsigned long first_frag_time;
0761     unsigned int seq;
0762     unsigned int last_frag;
0763     struct sk_buff *skb;
0764     u8 src_addr[ETH_ALEN];
0765     u8 dst_addr[ETH_ALEN];
0766 };
0767 
0768 struct ieee80211_stats {
0769     unsigned int tx_unicast_frames;
0770     unsigned int tx_multicast_frames;
0771     unsigned int tx_fragments;
0772     unsigned int tx_unicast_octets;
0773     unsigned int tx_multicast_octets;
0774     unsigned int tx_deferred_transmissions;
0775     unsigned int tx_single_retry_frames;
0776     unsigned int tx_multiple_retry_frames;
0777     unsigned int tx_retry_limit_exceeded;
0778     unsigned int tx_discards;
0779     unsigned int rx_unicast_frames;
0780     unsigned int rx_multicast_frames;
0781     unsigned int rx_fragments;
0782     unsigned int rx_unicast_octets;
0783     unsigned int rx_multicast_octets;
0784     unsigned int rx_fcs_errors;
0785     unsigned int rx_discards_no_buffer;
0786     unsigned int tx_discards_wrong_sa;
0787     unsigned int rx_discards_undecryptable;
0788     unsigned int rx_message_in_msg_fragments;
0789     unsigned int rx_message_in_bad_msg_fragments;
0790 };
0791 
0792 struct ieee80211_device;
0793 
0794 #include "ieee80211_crypt.h"
0795 
0796 #define SEC_KEY_1         (1<<0)
0797 #define SEC_KEY_2         (1<<1)
0798 #define SEC_KEY_3         (1<<2)
0799 #define SEC_KEY_4         (1<<3)
0800 #define SEC_ACTIVE_KEY    (1<<4)
0801 #define SEC_AUTH_MODE     (1<<5)
0802 #define SEC_UNICAST_GROUP (1<<6)
0803 #define SEC_LEVEL         (1<<7)
0804 #define SEC_ENABLED       (1<<8)
0805 #define SEC_ENCRYPT       (1<<9)
0806 
0807 #define SEC_LEVEL_0      0 /* None */
0808 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
0809 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
0810 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
0811 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
0812 
0813 #define SEC_ALG_NONE            0
0814 #define SEC_ALG_WEP             1
0815 #define SEC_ALG_TKIP            2
0816 #define SEC_ALG_CCMP            3
0817 
0818 #define WEP_KEYS        4
0819 #define WEP_KEY_LEN     13
0820 #define SCM_KEY_LEN             32
0821 #define SCM_TEMPORAL_KEY_LENGTH 16
0822 
0823 struct ieee80211_security {
0824     u16 active_key:2,
0825         enabled:1,
0826         auth_algo:4,
0827         unicast_uses_group:1,
0828         encrypt:1;
0829     u8 auth_mode;
0830     u8 key_sizes[WEP_KEYS];
0831     u8 keys[WEP_KEYS][SCM_KEY_LEN];
0832     u8 level;
0833     u16 flags;
0834 } __packed;
0835 
0836 
0837 /*
0838  *  802.11 data frame from AP
0839  *       ,-------------------------------------------------------------------.
0840  * Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
0841  *       |------|------|---------|---------|---------|------|---------|------|
0842  * Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
0843  *       |      | tion | (BSSID) |         |         | ence |  data   |      |
0844  *       `-------------------------------------------------------------------'
0845  *  Total: 28-2340 bytes
0846  */
0847 
0848 /* Management Frame Information Element Types */
0849 enum ieee80211_mfie {
0850     MFIE_TYPE_SSID = 0,
0851     MFIE_TYPE_RATES = 1,
0852     MFIE_TYPE_FH_SET = 2,
0853     MFIE_TYPE_DS_SET = 3,
0854     MFIE_TYPE_CF_SET = 4,
0855     MFIE_TYPE_TIM = 5,
0856     MFIE_TYPE_IBSS_SET = 6,
0857     MFIE_TYPE_COUNTRY = 7,
0858     MFIE_TYPE_HOP_PARAMS = 8,
0859     MFIE_TYPE_HOP_TABLE = 9,
0860     MFIE_TYPE_REQUEST = 10,
0861     MFIE_TYPE_CHALLENGE = 16,
0862     MFIE_TYPE_POWER_CONSTRAINT = 32,
0863     MFIE_TYPE_POWER_CAPABILITY = 33,
0864     MFIE_TYPE_TPC_REQUEST = 34,
0865     MFIE_TYPE_TPC_REPORT = 35,
0866     MFIE_TYPE_SUPP_CHANNELS = 36,
0867     MFIE_TYPE_CSA = 37,
0868     MFIE_TYPE_MEASURE_REQUEST = 38,
0869     MFIE_TYPE_MEASURE_REPORT = 39,
0870     MFIE_TYPE_QUIET = 40,
0871     MFIE_TYPE_IBSS_DFS = 41,
0872     MFIE_TYPE_ERP = 42,
0873     MFIE_TYPE_RSN = 48,
0874     MFIE_TYPE_RATES_EX = 50,
0875     MFIE_TYPE_HT_CAP = 45,
0876      MFIE_TYPE_HT_INFO = 61,
0877      MFIE_TYPE_AIRONET = 133,
0878     MFIE_TYPE_GENERIC = 221,
0879     MFIE_TYPE_QOS_PARAMETER = 222,
0880 };
0881 
0882 /* Minimal header; can be used for passing 802.11 frames with sufficient
0883  * information to determine what type of underlying data type is actually
0884  * stored in the data.
0885  */
0886 struct rtl_80211_hdr {
0887     __le16 frame_ctl;
0888     __le16 duration_id;
0889     u8 payload[];
0890 } __packed;
0891 
0892 struct rtl_80211_hdr_1addr {
0893     __le16 frame_ctl;
0894     __le16 duration_id;
0895     u8 addr1[ETH_ALEN];
0896     u8 payload[];
0897 } __packed;
0898 
0899 struct rtl_80211_hdr_2addr {
0900     __le16 frame_ctl;
0901     __le16 duration_id;
0902     u8 addr1[ETH_ALEN];
0903     u8 addr2[ETH_ALEN];
0904     u8 payload[];
0905 } __packed;
0906 
0907 struct rtl_80211_hdr_3addr {
0908     __le16 frame_ctl;
0909     __le16 duration_id;
0910     u8 addr1[ETH_ALEN];
0911     u8 addr2[ETH_ALEN];
0912     u8 addr3[ETH_ALEN];
0913     __le16 seq_ctl;
0914     u8 payload[];
0915 } __packed;
0916 
0917 struct rtl_80211_hdr_4addr {
0918     __le16 frame_ctl;
0919     __le16 duration_id;
0920     u8 addr1[ETH_ALEN];
0921     u8 addr2[ETH_ALEN];
0922     u8 addr3[ETH_ALEN];
0923     __le16 seq_ctl;
0924     u8 addr4[ETH_ALEN];
0925     u8 payload[];
0926 } __packed;
0927 
0928 struct rtl_80211_hdr_3addrqos {
0929     __le16 frame_ctl;
0930     __le16 duration_id;
0931     u8 addr1[ETH_ALEN];
0932     u8 addr2[ETH_ALEN];
0933     u8 addr3[ETH_ALEN];
0934     __le16 seq_ctl;
0935     u8 payload[0];
0936     __le16 qos_ctl;
0937 } __packed;
0938 
0939 struct rtl_80211_hdr_4addrqos {
0940     __le16 frame_ctl;
0941     __le16 duration_id;
0942     u8 addr1[ETH_ALEN];
0943     u8 addr2[ETH_ALEN];
0944     u8 addr3[ETH_ALEN];
0945     __le16 seq_ctl;
0946     u8 addr4[ETH_ALEN];
0947     u8 payload[0];
0948     __le16 qos_ctl;
0949 } __packed;
0950 
0951 struct ieee80211_info_element {
0952     u8 id;
0953     u8 len;
0954     u8 data[];
0955 } __packed;
0956 
0957 struct ieee80211_authentication {
0958     struct rtl_80211_hdr_3addr header;
0959     __le16 algorithm;
0960     __le16 transaction;
0961     __le16 status;
0962     /*challenge*/
0963     struct ieee80211_info_element info_element[];
0964 } __packed;
0965 
0966 struct ieee80211_disassoc {
0967     struct rtl_80211_hdr_3addr header;
0968     __le16 reason;
0969 } __packed;
0970 
0971 struct ieee80211_probe_request {
0972     struct rtl_80211_hdr_3addr header;
0973     /* SSID, supported rates */
0974     struct ieee80211_info_element info_element[];
0975 } __packed;
0976 
0977 struct ieee80211_probe_response {
0978     struct rtl_80211_hdr_3addr header;
0979     __le32 time_stamp[2];
0980     __le16 beacon_interval;
0981     __le16 capability;
0982     /* SSID, supported rates, FH params, DS params,
0983      * CF params, IBSS params, TIM (if beacon), RSN
0984      */
0985     struct ieee80211_info_element info_element[];
0986 } __packed;
0987 
0988 /* Alias beacon for probe_response */
0989 #define ieee80211_beacon ieee80211_probe_response
0990 
0991 struct ieee80211_assoc_request_frame {
0992     struct rtl_80211_hdr_3addr header;
0993     __le16 capability;
0994     __le16 listen_interval;
0995     /* SSID, supported rates, RSN */
0996     struct ieee80211_info_element info_element[];
0997 } __packed;
0998 
0999 struct ieee80211_reassoc_request_frame {
1000     struct rtl_80211_hdr_3addr header;
1001     __le16 capability;
1002     __le16 listen_interval;
1003     u8 current_ap[ETH_ALEN];
1004     /* SSID, supported rates, RSN */
1005     struct ieee80211_info_element info_element[];
1006 } __packed;
1007 
1008 struct ieee80211_assoc_response_frame {
1009     struct rtl_80211_hdr_3addr header;
1010     __le16 capability;
1011     __le16 status;
1012     __le16 aid;
1013     struct ieee80211_info_element info_element[]; /* supported rates */
1014 } __packed;
1015 
1016 struct ieee80211_txb {
1017     u8 nr_frags;
1018     u8 encrypted;
1019     u8 queue_index;
1020     u8 rts_included;
1021     u16 reserved;
1022     __le16 frag_size;
1023     __le16 payload_size;
1024     struct sk_buff *fragments[];
1025 };
1026 
1027 #define MAX_TX_AGG_COUNT          16
1028 struct ieee80211_drv_agg_txb {
1029     u8 nr_drv_agg_frames;
1030     struct sk_buff *tx_agg_frames[MAX_TX_AGG_COUNT];
1031 } __packed;
1032 
1033 #define MAX_SUBFRAME_COUNT        64
1034 struct ieee80211_rxb {
1035     u8 nr_subframes;
1036     struct sk_buff *subframes[MAX_SUBFRAME_COUNT];
1037     u8 dst[ETH_ALEN];
1038     u8 src[ETH_ALEN];
1039 } __packed;
1040 
1041 typedef union _frameqos {
1042     u16 shortdata;
1043     u8  chardata[2];
1044     struct {
1045         u16 tid:4;
1046         u16 eosp:1;
1047         u16 ack_policy:2;
1048         u16 reserved:1;
1049         u16 txop:8;
1050     } field;
1051 } frameqos, *pframeqos;
1052 
1053 /* SWEEP TABLE ENTRIES NUMBER*/
1054 #define MAX_SWEEP_TAB_ENTRIES         42
1055 #define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
1056 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
1057  * only use 8, and then use extended rates for the remaining supported
1058  * rates.  Other APs, however, stick all of their supported rates on the
1059  * main rates information element...
1060  */
1061 #define MAX_RATES_LENGTH                  ((u8)12)
1062 #define MAX_RATES_EX_LENGTH               ((u8)16)
1063 #define MAX_NETWORK_COUNT                  128
1064 
1065 #define MAX_CHANNEL_NUMBER                 161
1066 #define IEEE80211_SOFTMAC_SCAN_TIME    100
1067 //(HZ / 2)
1068 #define IEEE80211_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
1069 
1070 #define CRC_LENGTH                 4U
1071 
1072 #define MAX_WPA_IE_LEN 64
1073 
1074 #define NETWORK_EMPTY_ESSID (1<<0)
1075 #define NETWORK_HAS_OFDM    (1<<1)
1076 #define NETWORK_HAS_CCK     (1<<2)
1077 
1078 /* QoS structure */
1079 #define NETWORK_HAS_QOS_PARAMETERS      (1<<3)
1080 #define NETWORK_HAS_QOS_INFORMATION     (1<<4)
1081 #define NETWORK_HAS_QOS_MASK            (NETWORK_HAS_QOS_PARAMETERS | \
1082                      NETWORK_HAS_QOS_INFORMATION)
1083 /* 802.11h */
1084 #define NETWORK_HAS_POWER_CONSTRAINT    (1<<5)
1085 #define NETWORK_HAS_CSA                 (1<<6)
1086 #define NETWORK_HAS_QUIET               (1<<7)
1087 #define NETWORK_HAS_IBSS_DFS            (1<<8)
1088 #define NETWORK_HAS_TPC_REPORT          (1<<9)
1089 
1090 #define NETWORK_HAS_ERP_VALUE           (1<<10)
1091 
1092 #define QOS_QUEUE_NUM                   4
1093 #define QOS_OUI_LEN                     3
1094 #define QOS_OUI_TYPE                    2
1095 #define QOS_ELEMENT_ID                  221
1096 #define QOS_OUI_INFO_SUB_TYPE           0
1097 #define QOS_OUI_PARAM_SUB_TYPE          1
1098 #define QOS_VERSION_1                   1
1099 #define QOS_AIFSN_MIN_VALUE             2
1100 struct ieee80211_qos_information_element {
1101     u8 elementID;
1102     u8 length;
1103     u8 qui[QOS_OUI_LEN];
1104     u8 qui_type;
1105     u8 qui_subtype;
1106     u8 version;
1107     u8 ac_info;
1108 } __packed;
1109 
1110 struct ieee80211_qos_ac_parameter {
1111     u8 aci_aifsn;
1112     u8 ecw_min_max;
1113     __le16 tx_op_limit;
1114 } __packed;
1115 
1116 struct ieee80211_qos_parameter_info {
1117     struct ieee80211_qos_information_element info_element;
1118     u8 reserved;
1119     struct ieee80211_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
1120 } __packed;
1121 
1122 struct ieee80211_qos_parameters {
1123     __le16 cw_min[QOS_QUEUE_NUM];
1124     __le16 cw_max[QOS_QUEUE_NUM];
1125     u8 aifs[QOS_QUEUE_NUM];
1126     u8 flag[QOS_QUEUE_NUM];
1127     __le16 tx_op_limit[QOS_QUEUE_NUM];
1128 } __packed;
1129 
1130 struct ieee80211_qos_data {
1131     struct ieee80211_qos_parameters parameters;
1132     int active;
1133     int supported;
1134     u8 param_count;
1135     u8 old_param_count;
1136 };
1137 
1138 struct ieee80211_tim_parameters {
1139     u8 tim_count;
1140     u8 tim_period;
1141 } __packed;
1142 
1143 //#else
1144 struct ieee80211_wmm_ts_info {
1145     u8 ac_dir_tid;
1146     u8 ac_up_psb;
1147     u8 reserved;
1148 } __packed;
1149 
1150 struct ieee80211_wmm_tspec_elem {
1151     struct ieee80211_wmm_ts_info ts_info;
1152     u16 norm_msdu_size;
1153     u16 max_msdu_size;
1154     u32 min_serv_inter;
1155     u32 max_serv_inter;
1156     u32 inact_inter;
1157     u32 suspen_inter;
1158     u32 serv_start_time;
1159     u32 min_data_rate;
1160     u32 mean_data_rate;
1161     u32 peak_data_rate;
1162     u32 max_burst_size;
1163     u32 delay_bound;
1164     u32 min_phy_rate;
1165     u16 surp_band_allow;
1166     u16 medium_time;
1167 } __packed;
1168 enum eap_type {
1169     EAP_PACKET = 0,
1170     EAPOL_START,
1171     EAPOL_LOGOFF,
1172     EAPOL_KEY,
1173     EAPOL_ENCAP_ASF_ALERT
1174 };
1175 
1176 static const char *eap_types[] = {
1177     [EAP_PACKET]        = "EAP-Packet",
1178     [EAPOL_START]       = "EAPOL-Start",
1179     [EAPOL_LOGOFF]      = "EAPOL-Logoff",
1180     [EAPOL_KEY]     = "EAPOL-Key",
1181     [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
1182 };
1183 
1184 static inline const char *eap_get_type(int type)
1185 {
1186     return ((u32)type >= ARRAY_SIZE(eap_types)) ? "Unknown" : eap_types[type];
1187 }
1188 //added by amy for reorder
1189 static inline u8 Frame_QoSTID(u8 *buf)
1190 {
1191     struct rtl_80211_hdr_3addr *hdr;
1192     u16 fc;
1193     hdr = (struct rtl_80211_hdr_3addr *)buf;
1194     fc = le16_to_cpu(hdr->frame_ctl);
1195     return (u8)((frameqos *)(buf + (((fc & IEEE80211_FCTL_TODS) && (fc & IEEE80211_FCTL_FROMDS)) ? 30 : 24)))->field.tid;
1196 }
1197 
1198 //added by amy for reorder
1199 
1200 struct eapol {
1201     u8 snap[6];
1202     u16 ethertype;
1203     u8 version;
1204     u8 type;
1205     u16 length;
1206 } __packed;
1207 
1208 struct ieee80211_softmac_stats {
1209     unsigned int rx_ass_ok;
1210     unsigned int rx_ass_err;
1211     unsigned int rx_probe_rq;
1212     unsigned int tx_probe_rs;
1213     unsigned int tx_beacons;
1214     unsigned int rx_auth_rq;
1215     unsigned int rx_auth_rs_ok;
1216     unsigned int rx_auth_rs_err;
1217     unsigned int tx_auth_rq;
1218     unsigned int no_auth_rs;
1219     unsigned int no_ass_rs;
1220     unsigned int tx_ass_rq;
1221     unsigned int rx_ass_rq;
1222     unsigned int tx_probe_rq;
1223     unsigned int reassoc;
1224     unsigned int swtxstop;
1225     unsigned int swtxawake;
1226     unsigned char CurrentShowTxate;
1227     unsigned char last_packet_rate;
1228     unsigned int txretrycount;
1229 };
1230 
1231 #define BEACON_PROBE_SSID_ID_POSITION 12
1232 
1233 struct ieee80211_info_element_hdr {
1234     u8 id;
1235     u8 len;
1236 } __packed;
1237 
1238 /*
1239  * These are the data types that can make up management packets
1240  *
1241     u16 auth_algorithm;
1242     u16 auth_sequence;
1243     u16 beacon_interval;
1244     u16 capability;
1245     u8 current_ap[ETH_ALEN];
1246     u16 listen_interval;
1247     struct {
1248         u16 association_id:14, reserved:2;
1249     } __packed;
1250     u32 time_stamp[2];
1251     u16 reason;
1252     u16 status;
1253 */
1254 
1255 #define IEEE80211_DEFAULT_TX_ESSID "Penguin"
1256 #define IEEE80211_DEFAULT_BASIC_RATE 2 //1Mbps
1257 
1258 enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
1259 #define MAX_SP_Len  (WMM_all_frame << 4)
1260 #define IEEE80211_QOS_TID 0x0f
1261 #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
1262 
1263 #define IEEE80211_DTIM_MBCAST 4
1264 #define IEEE80211_DTIM_UCAST 2
1265 #define IEEE80211_DTIM_VALID 1
1266 #define IEEE80211_DTIM_INVALID 0
1267 
1268 #define IEEE80211_PS_DISABLED 0
1269 #define IEEE80211_PS_UNICAST IEEE80211_DTIM_UCAST
1270 #define IEEE80211_PS_MBCAST IEEE80211_DTIM_MBCAST
1271 
1272 //added by David for QoS 2006/6/30
1273 //#define WMM_Hang_8187
1274 #ifdef WMM_Hang_8187
1275 #undef WMM_Hang_8187
1276 #endif
1277 
1278 #define WME_AC_BK   0x00
1279 #define WME_AC_BE   0x01
1280 #define WME_AC_VI   0x02
1281 #define WME_AC_VO   0x03
1282 #define WME_ACI_MASK 0x03
1283 #define WME_AIFSN_MASK 0x03
1284 #define WME_AC_PRAM_LEN 16
1285 
1286 #define MAX_RECEIVE_BUFFER_SIZE 9100
1287 
1288 //UP Mapping to AC, using in MgntQuery_SequenceNumber() and maybe for DSCP
1289 //#define UP2AC(up) ((up<3) ? ((up==0)?1:0) : (up>>1))
1290 #define UP2AC(up) (        \
1291     ((up) < 1) ? WME_AC_BE : \
1292     ((up) < 3) ? WME_AC_BK : \
1293     ((up) < 4) ? WME_AC_BE : \
1294     ((up) < 6) ? WME_AC_VI : \
1295     WME_AC_VO)
1296 //AC Mapping to UP, using in Tx part for selecting the corresponding TX queue
1297 #define AC2UP(_ac)  (       \
1298     ((_ac) == WME_AC_VO) ? 6 : \
1299     ((_ac) == WME_AC_VI) ? 5 : \
1300     ((_ac) == WME_AC_BK) ? 1 : \
1301     0)
1302 
1303 #define ETHER_ADDR_LEN      6   /* length of an Ethernet address */
1304 #define ETHERNET_HEADER_SIZE    14      /* length of two Ethernet address plus ether type*/
1305 
1306 struct  ether_header {
1307     u8 ether_dhost[ETHER_ADDR_LEN];
1308     u8 ether_shost[ETHER_ADDR_LEN];
1309     u16 ether_type;
1310 } __packed;
1311 
1312 #ifndef ETHERTYPE_PAE
1313 #define ETHERTYPE_PAE   0x888e      /* EAPOL PAE/802.1x */
1314 #endif
1315 #ifndef ETHERTYPE_IP
1316 #define ETHERTYPE_IP    0x0800      /* IP protocol */
1317 #endif
1318 
1319 typedef enum _erp_t {
1320     ERP_NonERPpresent   = 0x01,
1321     ERP_UseProtection   = 0x02,
1322     ERP_BarkerPreambleMode = 0x04,
1323 } erp_t;
1324 
1325 
1326 struct ieee80211_network {
1327     /* These entries are used to identify a unique network */
1328     u8 bssid[ETH_ALEN];   /* u16 aligned! */
1329     u8 channel;
1330 
1331     // CCXv4 S59, MBSSID.
1332     bool    bMBssidValid;
1333     u8  MBssid[ETH_ALEN];    /* u16 aligned! */
1334     u8  MBssidMask;
1335     /* Ensure null-terminated for any debug msgs */
1336     u8 ssid[IW_ESSID_MAX_SIZE + 1];
1337     u8 ssid_len;
1338     struct ieee80211_qos_data qos_data;
1339 
1340     //added by amy for LEAP
1341     bool    bWithAironetIE;
1342     bool    bCkipSupported;
1343     bool    bCcxRmEnable;
1344     u16 CcxRmState[2];
1345     // CCX 2 S38, WLAN Device Version Number element. Annie, 2006-08-20.
1346     bool    bWithCcxVerNum;
1347     u8  BssCcxVerNumber;
1348     /* These are network statistics */
1349     struct ieee80211_rx_stats stats;
1350     u16 capability;
1351     u8  rates[MAX_RATES_LENGTH];
1352     u8  rates_len;
1353     u8  rates_ex[MAX_RATES_EX_LENGTH];
1354     u8  rates_ex_len;
1355     unsigned long last_scanned;
1356     u8  mode;
1357     u32 flags;
1358     u32 last_associate;
1359     u32 time_stamp[2];
1360     u16 beacon_interval;
1361     u16 listen_interval;
1362     u16 atim_window;
1363     u8  erp_value;
1364     u8  wpa_ie[MAX_WPA_IE_LEN];
1365     size_t wpa_ie_len;
1366     u8  rsn_ie[MAX_WPA_IE_LEN];
1367     size_t rsn_ie_len;
1368 
1369     struct ieee80211_tim_parameters tim;
1370     u8  dtim_period;
1371     u8  dtim_data;
1372     u32 last_dtim_sta_time[2];
1373 
1374     //appeded for QoS
1375     u8 wmm_info;
1376     struct ieee80211_wmm_ac_param wmm_param[4];
1377     u8 QoS_Enable;
1378 #ifdef THOMAS_TURBO
1379     u8 Turbo_Enable;//enable turbo mode, added by thomas
1380 #endif
1381     u16 CountryIeLen;
1382     u8 CountryIeBuf[MAX_IE_LEN];
1383     // HT Related, by amy, 2008.04.29
1384     BSS_HT  bssht;
1385     // Add to handle broadcom AP management frame CCK rate.
1386     bool broadcom_cap_exist;
1387     bool ralink_cap_exist;
1388     bool atheros_cap_exist;
1389     bool cisco_cap_exist;
1390     bool unknown_cap_exist;
1391 //  u8  berp_info;
1392     bool    berp_info_valid;
1393     bool buseprotection;
1394     //put at the end of the structure.
1395     struct list_head list;
1396 };
1397 
1398 enum ieee80211_state {
1399 
1400     /* the card is not linked at all */
1401     IEEE80211_NOLINK = 0,
1402 
1403     /* IEEE80211_ASSOCIATING* are for BSS client mode
1404      * the driver shall not perform RX filtering unless
1405      * the state is LINKED.
1406      * The driver shall just check for the state LINKED and
1407      * defaults to NOLINK for ALL the other states (including
1408      * LINKED_SCANNING)
1409      */
1410 
1411     /* the association procedure will start (wq scheduling)*/
1412     IEEE80211_ASSOCIATING,
1413     IEEE80211_ASSOCIATING_RETRY,
1414 
1415     /* the association procedure is sending AUTH request*/
1416     IEEE80211_ASSOCIATING_AUTHENTICATING,
1417 
1418     /* the association procedure has successfully authentcated
1419      * and is sending association request
1420      */
1421     IEEE80211_ASSOCIATING_AUTHENTICATED,
1422 
1423     /* the link is ok. the card associated to a BSS or linked
1424      * to a ibss cell or acting as an AP and creating the bss
1425      */
1426     IEEE80211_LINKED,
1427 
1428     /* same as LINKED, but the driver shall apply RX filter
1429      * rules as we are in NO_LINK mode. As the card is still
1430      * logically linked, but it is doing a syncro site survey
1431      * then it will be back to LINKED state.
1432      */
1433     IEEE80211_LINKED_SCANNING,
1434 
1435 };
1436 
1437 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1438 #define DEFAULT_FTS 2346
1439 
1440 #define CFG_IEEE80211_RESERVE_FCS (1<<0)
1441 #define CFG_IEEE80211_COMPUTE_FCS (1<<1)
1442 #define CFG_IEEE80211_RTS (1<<2)
1443 
1444 #define IEEE80211_24GHZ_MIN_CHANNEL 1
1445 #define IEEE80211_24GHZ_MAX_CHANNEL 14
1446 #define IEEE80211_24GHZ_CHANNELS (IEEE80211_24GHZ_MAX_CHANNEL - \
1447                   IEEE80211_24GHZ_MIN_CHANNEL + 1)
1448 
1449 #define IEEE80211_52GHZ_MIN_CHANNEL 34
1450 #define IEEE80211_52GHZ_MAX_CHANNEL 165
1451 #define IEEE80211_52GHZ_CHANNELS (IEEE80211_52GHZ_MAX_CHANNEL - \
1452                   IEEE80211_52GHZ_MIN_CHANNEL + 1)
1453 
1454 
1455 
1456 struct tx_pending {
1457     int frag;
1458     struct ieee80211_txb *txb;
1459 };
1460 
1461 struct bandwidth_autoswitch {
1462     long threshold_20Mhzto40Mhz;
1463     long    threshold_40Mhzto20Mhz;
1464     bool bforced_tx20Mhz;
1465     bool bautoswitch_enable;
1466 };
1467 
1468 
1469 //added by amy for order
1470 
1471 #define REORDER_WIN_SIZE    128
1472 #define REORDER_ENTRY_NUM   128
1473 struct rx_reorder_entry {
1474     struct list_head    List;
1475     u16         SeqNum;
1476     struct ieee80211_rxb *prxb;
1477 };
1478 //added by amy for order
1479 typedef enum _Fsync_State {
1480     Default_Fsync,
1481     HW_Fsync,
1482     SW_Fsync
1483 } Fsync_State;
1484 
1485 // Power save mode configured.
1486 typedef enum _RT_PS_MODE {
1487     eActive,    // Active/Continuous access.
1488     eMaxPs,     // Max power save mode.
1489     eFastPs     // Fast power save mode.
1490 } RT_PS_MODE;
1491 
1492 typedef enum _IPS_CALLBACK_FUNCION {
1493     IPS_CALLBACK_NONE = 0,
1494     IPS_CALLBACK_MGNT_LINK_REQUEST = 1,
1495     IPS_CALLBACK_JOIN_REQUEST = 2,
1496 } IPS_CALLBACK_FUNCION;
1497 
1498 typedef enum _RT_JOIN_ACTION {
1499     RT_JOIN_INFRA   = 1,
1500     RT_JOIN_IBSS  = 2,
1501     RT_START_IBSS = 3,
1502     RT_NO_ACTION  = 4,
1503 } RT_JOIN_ACTION;
1504 
1505 struct ibss_parms {
1506     u16   atimWin;
1507 };
1508 #define MAX_NUM_RATES   264 // Max num of support rates element: 8,  Max num of ext. support rate: 255. 061122, by rcnjko.
1509 
1510 // RF state.
1511 typedef enum _RT_RF_POWER_STATE {
1512     eRfOn,
1513     eRfSleep,
1514     eRfOff
1515 } RT_RF_POWER_STATE;
1516 
1517 struct rt_power_save_control {
1518 
1519     //
1520     // Inactive Power Save(IPS) : Disable RF when disconnected
1521     //
1522     bool                bInactivePs;
1523     bool                bIPSModeBackup;
1524     bool                bSwRfProcessing;
1525     RT_RF_POWER_STATE   eInactivePowerState;
1526     struct work_struct  InactivePsWorkItem;
1527     struct timer_list   InactivePsTimer;
1528 
1529     // Return point for join action
1530     IPS_CALLBACK_FUNCION    ReturnPoint;
1531 
1532     // Recored Parameters for rescheduled JoinRequest
1533     bool                bTmpBssDesc;
1534     RT_JOIN_ACTION      tmpJoinAction;
1535     struct ieee80211_network tmpBssDesc;
1536 
1537     // Recored Parameters for rescheduled MgntLinkRequest
1538     bool                bTmpScanOnly;
1539     bool                bTmpActiveScan;
1540     bool                bTmpFilterHiddenAP;
1541     bool                bTmpUpdateParms;
1542     u8                  tmpSsidBuf[33];
1543     struct octet_string         tmpSsid2Scan;
1544     bool                bTmpSsid2Scan;
1545     u8                  tmpNetworkType;
1546     u8                  tmpChannelNumber;
1547     u16                 tmpBcnPeriod;
1548     u8                  tmpDtimPeriod;
1549     u16                 tmpmCap;
1550     struct octet_string         tmpSuppRateSet;
1551     u8                  tmpSuppRateBuf[MAX_NUM_RATES];
1552     bool                bTmpSuppRate;
1553     struct ibss_parms           tmpIbpm;
1554     bool                bTmpIbpm;
1555 
1556     //
1557     // Leisre Poswer Save : Disable RF if connected but traffic is not busy
1558     //
1559     bool                bLeisurePs;
1560 
1561 };
1562 
1563 typedef u32 RT_RF_CHANGE_SOURCE;
1564 #define RF_CHANGE_BY_SW     BIT(31)
1565 #define RF_CHANGE_BY_HW     BIT(30)
1566 #define RF_CHANGE_BY_PS     BIT(29)
1567 #define RF_CHANGE_BY_IPS    BIT(28)
1568 #define RF_CHANGE_BY_INIT   0   // Do not change the RFOff reason. Defined by Bruce, 2008-01-17.
1569 
1570 typedef enum {
1571     COUNTRY_CODE_FCC = 0,
1572     COUNTRY_CODE_IC = 1,
1573     COUNTRY_CODE_ETSI = 2,
1574     COUNTRY_CODE_SPAIN = 3,
1575     COUNTRY_CODE_FRANCE = 4,
1576     COUNTRY_CODE_MKK = 5,
1577     COUNTRY_CODE_MKK1 = 6,
1578     COUNTRY_CODE_ISRAEL = 7,
1579     COUNTRY_CODE_TELEC,
1580     COUNTRY_CODE_MIC,
1581     COUNTRY_CODE_GLOBAL_DOMAIN
1582 } country_code_type_t;
1583 
1584 #define RT_MAX_LD_SLOT_NUM  10
1585 struct rt_link_detect {
1586 
1587     u32             NumRecvBcnInPeriod;
1588     u32             NumRecvDataInPeriod;
1589 
1590     u32             RxBcnNum[RT_MAX_LD_SLOT_NUM];   // number of Rx beacon / CheckForHang_period  to determine link status
1591     u32             RxDataNum[RT_MAX_LD_SLOT_NUM];  // number of Rx data / CheckForHang_period  to determine link status
1592     u16             SlotNum;    // number of CheckForHang period to determine link status
1593     u16             SlotIndex;
1594 
1595     u32             NumTxOkInPeriod;
1596     u32             NumRxOkInPeriod;
1597     bool                bBusyTraffic;
1598 };
1599 
1600 
1601 struct ieee80211_device {
1602     struct net_device *dev;
1603     struct ieee80211_security sec;
1604 
1605     //hw security related
1606 //  u8 hwsec_support; //support?
1607     u8 hwsec_active;  //hw security active.
1608     bool is_silent_reset;
1609     bool ieee_up;
1610     //added by amy
1611     bool bSupportRemoteWakeUp;
1612     RT_PS_MODE  dot11PowerSaveMode; // Power save mode configured.
1613     bool actscanning;
1614     bool beinretry;
1615     RT_RF_POWER_STATE       eRFPowerState;
1616     RT_RF_CHANGE_SOURCE RfOffReason;
1617     bool is_set_key;
1618     //11n spec related I wonder if These info structure need to be moved out of ieee80211_device
1619 
1620     //11n HT below
1621     PRT_HIGH_THROUGHPUT pHTInfo;
1622     //struct timer_list     SwBwTimer;
1623 //  spinlock_t chnlop_spinlock;
1624     spinlock_t bw_spinlock;
1625 
1626     spinlock_t reorder_spinlock;
1627     // for HT operation rate set.  we use this one for HT data rate to separate different descriptors
1628     //the way fill this is the same as in the IE
1629     u8  Regdot11HTOperationalRateSet[16];       //use RATR format
1630     u8  dot11HTOperationalRateSet[16];      //use RATR format
1631     u8  RegHTSuppRateSet[16];
1632     u8              HTCurrentOperaRate;
1633     u8              HTHighestOperaRate;
1634     //wb added for rate operation mode to firmware
1635     u8  bTxDisableRateFallBack;
1636     u8  bTxUseDriverAssingedRate;
1637     atomic_t    atm_chnlop;
1638     atomic_t    atm_swbw;
1639 //  u8  HTHighestOperaRate;
1640 //  u8  HTCurrentOperaRate;
1641 
1642     // 802.11e and WMM Traffic Stream Info (TX)
1643     struct list_head        Tx_TS_Admit_List;
1644     struct list_head        Tx_TS_Pending_List;
1645     struct list_head        Tx_TS_Unused_List;
1646     struct tx_ts_record     TxTsRecord[TOTAL_TS_NUM];
1647     // 802.11e and WMM Traffic Stream Info (RX)
1648     struct list_head        Rx_TS_Admit_List;
1649     struct list_head        Rx_TS_Pending_List;
1650     struct list_head        Rx_TS_Unused_List;
1651     struct rx_ts_record     RxTsRecord[TOTAL_TS_NUM];
1652     struct rx_reorder_entry RxReorderEntry[128];
1653     struct list_head        RxReorder_Unused_List;
1654     // Qos related. Added by Annie, 2005-11-01.
1655 //  PSTA_QOS            pStaQos;
1656     u8              ForcedPriority;     // Force per-packet priority 1~7. (default: 0, not to force it.)
1657 
1658 
1659     /* Bookkeeping structures */
1660     struct net_device_stats stats;
1661     struct ieee80211_stats ieee_stats;
1662     struct ieee80211_softmac_stats softmac_stats;
1663 
1664     /* Probe / Beacon management */
1665     struct list_head network_free_list;
1666     struct list_head network_list;
1667     struct ieee80211_network *networks;
1668     int scans;
1669     int scan_age;
1670 
1671     int iw_mode; /* operating mode (IW_MODE_*) */
1672     struct iw_spy_data spy_data;
1673 
1674     spinlock_t lock;
1675     spinlock_t wpax_suitlist_lock;
1676 
1677     int tx_headroom; /* Set to size of any additional room needed at front
1678               * of allocated Tx SKBs
1679               */
1680     u32 config;
1681 
1682     /* WEP and other encryption related settings at the device level */
1683     int open_wep; /* Set to 1 to allow unencrypted frames */
1684     int auth_mode;
1685     int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
1686                  * WEP key changes
1687                  */
1688 
1689     /* If the host performs {en,de}cryption, then set to 1 */
1690     int host_encrypt;
1691     int host_encrypt_msdu;
1692     int host_decrypt;
1693     /* host performs multicast decryption */
1694     int host_mc_decrypt;
1695 
1696     /* host should strip IV and ICV from protected frames */
1697     /* meaningful only when hardware decryption is being used */
1698     int host_strip_iv_icv;
1699 
1700     int host_open_frag;
1701     int host_build_iv;
1702     int ieee802_1x; /* is IEEE 802.1X used */
1703 
1704     /* WPA data */
1705     bool bHalfWirelessN24GMode;
1706     int wpa_enabled;
1707     int drop_unencrypted;
1708     int tkip_countermeasures;
1709     int privacy_invoked;
1710     size_t wpa_ie_len;
1711     u8 *wpa_ie;
1712     u8 ap_mac_addr[6];
1713     u16 pairwise_key_type;
1714     u16 group_key_type;
1715     struct list_head crypt_deinit_list;
1716     struct ieee80211_crypt_data *crypt[WEP_KEYS];
1717     int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
1718     struct timer_list crypt_deinit_timer;
1719     int crypt_quiesced;
1720 
1721     int bcrx_sta_key; /* use individual keys to override default keys even
1722                * with RX of broad/multicast frames
1723                */
1724 
1725     /* Fragmentation structures */
1726     // each streaming contain a entry
1727     struct ieee80211_frag_entry frag_cache[17][IEEE80211_FRAG_CACHE_LEN];
1728     unsigned int frag_next_idx[17];
1729     u16 fts; /* Fragmentation Threshold */
1730 #define DEFAULT_RTS_THRESHOLD 2346U
1731 #define MIN_RTS_THRESHOLD 1
1732 #define MAX_RTS_THRESHOLD 2346U
1733     u16 rts; /* RTS threshold */
1734 
1735     /* Association info */
1736     u8 bssid[ETH_ALEN];
1737 
1738     /* This stores infos for the current network.
1739      * Either the network we are associated in INFRASTRUCTURE
1740      * or the network that we are creating in MASTER mode.
1741      * ad-hoc is a mixture ;-).
1742      * Note that in infrastructure mode, even when not associated,
1743      * fields bssid and essid may be valid (if wpa_set and essid_set
1744      * are true) as thy carry the value set by the user via iwconfig
1745      */
1746     struct ieee80211_network current_network;
1747 
1748     enum ieee80211_state state;
1749 
1750     int short_slot;
1751     int reg_mode;
1752     int mode;       /* A, B, G */
1753     int modulation; /* CCK, OFDM */
1754     int freq_band;  /* 2.4Ghz, 5.2Ghz, Mixed */
1755     int abg_true;   /* ABG flag              */
1756 
1757     /* used for forcing the ibss workqueue to terminate
1758      * without wait for the syncro scan to terminate
1759      */
1760     short sync_scan_hurryup;
1761 
1762     int perfect_rssi;
1763     int worst_rssi;
1764 
1765     u16 prev_seq_ctl;       /* used to drop duplicate frames */
1766 
1767     /* map of allowed channels. 0 is dummy */
1768     // FIXME: remember to default to a basic channel plan depending of the PHY type
1769     void *dot11d_info;
1770     bool bGlobalDomain;
1771     int rate;       /* current rate */
1772     int basic_rate;
1773     //FIXME: pleace callback, see if redundant with softmac_features
1774     short active_scan;
1775 
1776     /* this contains flags for selectively enable softmac support */
1777     u16 softmac_features;
1778 
1779     /* if the sequence control field is not filled by HW */
1780     u16 seq_ctrl[5];
1781 
1782     /* association procedure transaction sequence number */
1783     u16 associate_seq;
1784 
1785     /* AID for RTXed association responses */
1786     u16 assoc_id;
1787 
1788     /* power save mode related*/
1789     short ps;
1790     short sta_sleep;
1791     int ps_timeout;
1792     int ps_period;
1793     struct work_struct ps_task;
1794     u32 ps_th;
1795     u32 ps_tl;
1796 
1797     short raw_tx;
1798     /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1799     short queue_stop;
1800     short scanning;
1801     short proto_started;
1802 
1803     struct mutex wx_mutex;
1804     struct mutex scan_mutex;
1805 
1806     spinlock_t mgmt_tx_lock;
1807     spinlock_t beacon_lock;
1808 
1809     short beacon_txing;
1810 
1811     short wap_set;
1812     short ssid_set;
1813 
1814     u8  wpax_type_set;    //{added by David, 2006.9.28}
1815     u32 wpax_type_notify; //{added by David, 2006.9.26}
1816 
1817     /* QoS related flag */
1818     s8  init_wmmparam_flag;
1819     /* set on initialization */
1820     u8  qos_support;
1821 
1822     /* for discarding duplicated packets in IBSS */
1823     struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
1824 
1825     /* for discarding duplicated packets in BSS */
1826     u16 last_rxseq_num[17]; /* rx seq previous per-tid */
1827     u16 last_rxfrag_num[17];/* tx frag previous per-tid */
1828     unsigned long last_packet_time[17];
1829 
1830     /* for PS mode */
1831     unsigned long last_rx_ps_time;
1832 
1833     /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
1834     struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
1835     int mgmt_queue_head;
1836     int mgmt_queue_tail;
1837 //{ added for rtl819x
1838 #define IEEE80211_QUEUE_LIMIT 128
1839     u8 AsocRetryCount;
1840     unsigned int hw_header;
1841     struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE];
1842     struct sk_buff_head  skb_aggQ[MAX_QUEUE_SIZE];
1843     struct sk_buff_head  skb_drv_aggQ[MAX_QUEUE_SIZE];
1844     u32 sta_edca_param[4];
1845     bool aggregation;
1846     // Enable/Disable Rx immediate BA capability.
1847     bool enable_rx_imm_BA;
1848     bool bibsscoordinator;
1849 
1850     //+by amy for DM ,080515
1851     //Dynamic Tx power for near/far range enable/Disable  , by amy , 2008-05-15
1852     bool    bdynamic_txpower_enable;
1853 
1854     bool bCTSToSelfEnable;
1855     u8  CTSToSelfTH;
1856 
1857     u32 fsync_time_interval;
1858     u32 fsync_rate_bitmap;
1859     u8  fsync_rssi_threshold;
1860     bool    bfsync_enable;
1861 
1862     u8  fsync_multiple_timeinterval;        // FsyncMultipleTimeInterval * FsyncTimeInterval
1863     u32 fsync_firstdiff_ratethreshold;      // low threshold
1864     u32 fsync_seconddiff_ratethreshold;  // decrease threshold
1865     Fsync_State         fsync_state;
1866     bool        bis_any_nonbepkts;
1867     //20Mhz 40Mhz AutoSwitch Threshold
1868     struct bandwidth_autoswitch bandwidth_auto_switch;
1869     //for txpower tracking
1870     bool FwRWRF;
1871 
1872     //added by amy for AP roaming
1873     struct rt_link_detect LinkDetectInfo;
1874     //added by amy for ps
1875     struct rt_power_save_control PowerSaveControl;
1876 //}
1877     /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1878     struct  tx_pending tx_pending;
1879 
1880     /* used if IEEE_SOFTMAC_ASSOCIATE is set */
1881     struct timer_list associate_timer;
1882 
1883     /* used if IEEE_SOFTMAC_BEACONS is set */
1884     struct timer_list beacon_timer;
1885     struct work_struct associate_complete_wq;
1886     struct work_struct associate_procedure_wq;
1887     struct delayed_work softmac_scan_wq;
1888     struct delayed_work associate_retry_wq;
1889      struct delayed_work start_ibss_wq;
1890     struct work_struct wx_sync_scan_wq;
1891     struct workqueue_struct *wq;
1892     // Qos related. Added by Annie, 2005-11-01.
1893     //STA_QOS  StaQos;
1894 
1895     //u32 STA_EDCA_PARAM[4];
1896     //CHANNEL_ACCESS_SETTING ChannelAccessSetting;
1897 
1898     struct ieee80211_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
1899 
1900     /* Callback functions */
1901     void (*set_security)(struct net_device *dev,
1902                  struct ieee80211_security *sec);
1903 
1904     /* Used to TX data frame by using txb structs.
1905      * this is not used if in the softmac_features
1906      * is set the flag IEEE_SOFTMAC_TX_QUEUE
1907      */
1908     int (*hard_start_xmit)(struct ieee80211_txb *txb,
1909                    struct net_device *dev);
1910 
1911     int (*reset_port)(struct net_device *dev);
1912     int (*is_queue_full)(struct net_device *dev, int pri);
1913 
1914     int (*handle_management)(struct net_device *dev,
1915                   struct ieee80211_network *network, u16 type);
1916     int (*is_qos_active)(struct net_device *dev, struct sk_buff *skb);
1917 
1918     /* Softmac-generated frames (management) are TXed via this
1919      * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
1920      * not set. As some cards may have different HW queues that
1921      * one might want to use for data and management frames
1922      * the option to have two callbacks might be useful.
1923      * This function can't sleep.
1924      */
1925     int (*softmac_hard_start_xmit)(struct sk_buff *skb,
1926                    struct net_device *dev);
1927 
1928     /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
1929      * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
1930      * frames. I the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
1931      * then also management frames are sent via this callback.
1932      * This function can't sleep.
1933      */
1934     void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
1935                    struct net_device *dev, int rate);
1936 
1937     /* stops the HW queue for DATA frames. Useful to avoid
1938      * waste time to TX data frame when we are reassociating
1939      * This function can sleep.
1940      */
1941     void (*data_hard_stop)(struct net_device *dev);
1942 
1943     /* OK this is complementar to data_poll_hard_stop */
1944     void (*data_hard_resume)(struct net_device *dev);
1945 
1946     /* ask to the driver to retune the radio .
1947      * This function can sleep. the driver should ensure
1948      * the radio has been switched before return.
1949      */
1950     void (*set_chan)(struct net_device *dev, short ch);
1951 
1952     /* These are not used if the ieee stack takes care of
1953      * scanning (IEEE_SOFTMAC_SCAN feature set).
1954      * In this case only the set_chan is used.
1955      *
1956      * The syncro version is similar to the start_scan but
1957      * does not return until all channels has been scanned.
1958      * this is called in user context and should sleep,
1959      * it is called in a work_queue when switching to ad-hoc mode
1960      * or in behalf of iwlist scan when the card is associated
1961      * and root user ask for a scan.
1962      * the function stop_scan should stop both the syncro and
1963      * background scanning and can sleep.
1964      * The function start_scan should initiate the background
1965      * scanning and can't sleep.
1966      */
1967     void (*scan_syncro)(struct net_device *dev);
1968     void (*start_scan)(struct net_device *dev);
1969     void (*stop_scan)(struct net_device *dev);
1970 
1971     /* indicate the driver that the link state is changed
1972      * for example it may indicate the card is associated now.
1973      * Driver might be interested in this to apply RX filter
1974      * rules or simply light the LINK led
1975      */
1976     void (*link_change)(struct net_device *dev);
1977 
1978     /* these two function indicates to the HW when to start
1979      * and stop to send beacons. This is used when the
1980      * IEEE_SOFTMAC_BEACONS is not set. For now the
1981      * stop_send_bacons is NOT guaranteed to be called only
1982      * after start_send_beacons.
1983      */
1984     void (*start_send_beacons)(struct net_device *dev, u16 tx_rate);
1985     void (*stop_send_beacons)(struct net_device *dev);
1986 
1987     /* power save mode related */
1988     void (*sta_wake_up)(struct net_device *dev);
1989     void (*ps_request_tx_ack)(struct net_device *dev);
1990     void (*enter_sleep_state)(struct net_device *dev, u32 th, u32 tl);
1991     short (*ps_is_queue_empty)(struct net_device *dev);
1992     int (*handle_beacon)(struct net_device *dev, struct ieee80211_beacon *beacon, struct ieee80211_network *network);
1993     int (*handle_assoc_response)(struct net_device *dev, struct ieee80211_assoc_response_frame *resp, struct ieee80211_network *network);
1994 
1995 
1996     /* check whether Tx hw resource available */
1997     short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
1998     //added by wb for HT related
1999 //  void (*SwChnlByTimerHandler)(struct net_device *dev, int channel);
2000     void (*SetBWModeHandler)(struct net_device *dev, enum ht_channel_width Bandwidth, enum ht_extension_chan_offset Offset);
2001 //  void (*UpdateHalRATRTableHandler)(struct net_device* dev, u8* pMcsRate);
2002     bool (*GetNmodeSupportBySecCfg)(struct net_device *dev);
2003     void (*SetWirelessMode)(struct net_device *dev, u8 wireless_mode);
2004     bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device *dev);
2005     void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
2006 
2007     /* This must be the last item so that it points to the data
2008      * allocated beyond this structure by alloc_ieee80211
2009      */
2010     u8 priv[];
2011 };
2012 
2013 #define IEEE_A            (1<<0)
2014 #define IEEE_B            (1<<1)
2015 #define IEEE_G            (1<<2)
2016 #define IEEE_N_24G        (1<<4)
2017 #define IEEE_N_5G         (1<<5)
2018 #define IEEE_MODE_MASK    (IEEE_A | IEEE_B | IEEE_G)
2019 
2020 /* Generate a 802.11 header */
2021 
2022 /* Uses the channel change callback directly
2023  * instead of [start/stop] scan callbacks
2024  */
2025 #define IEEE_SOFTMAC_SCAN (1<<2)
2026 
2027 /* Perform authentication and association handshake */
2028 #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
2029 
2030 /* Generate probe requests */
2031 #define IEEE_SOFTMAC_PROBERQ (1<<4)
2032 
2033 /* Generate respones to probe requests */
2034 #define IEEE_SOFTMAC_PROBERS (1<<5)
2035 
2036 /* The ieee802.11 stack will manages the netif queue
2037  * wake/stop for the driver, taking care of 802.11
2038  * fragmentation. See softmac.c for details.
2039  */
2040 #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
2041 
2042 /* Uses only the softmac_data_hard_start_xmit
2043  * even for TX management frames.
2044  */
2045 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
2046 
2047 /* Generate beacons.  The stack will enqueue beacons
2048  * to the card
2049  */
2050 #define IEEE_SOFTMAC_BEACONS (1<<6)
2051 
2052 static inline void *ieee80211_priv(struct net_device *dev)
2053 {
2054     return ((struct ieee80211_device *)netdev_priv(dev))->priv;
2055 }
2056 
2057 static inline int ieee80211_is_empty_essid(const char *essid, int essid_len)
2058 {
2059     /* Single white space is for Linksys APs */
2060     if (essid_len == 1 && essid[0] == ' ')
2061         return 1;
2062 
2063     /* Otherwise, if the entire essid is 0, we assume it is hidden */
2064     while (essid_len) {
2065         essid_len--;
2066         if (essid[essid_len] != '\0')
2067             return 0;
2068     }
2069 
2070     return 1;
2071 }
2072 
2073 static inline int ieee80211_is_valid_mode(struct ieee80211_device *ieee, int mode)
2074 {
2075     /*
2076      * It is possible for both access points and our device to support
2077      * combinations of modes, so as long as there is one valid combination
2078      * of ap/device supported modes, then return success
2079      *
2080      */
2081     if ((mode & IEEE_A) &&
2082         (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
2083         (ieee->freq_band & IEEE80211_52GHZ_BAND))
2084         return 1;
2085 
2086     if ((mode & IEEE_G) &&
2087         (ieee->modulation & IEEE80211_OFDM_MODULATION) &&
2088         (ieee->freq_band & IEEE80211_24GHZ_BAND))
2089         return 1;
2090 
2091     if ((mode & IEEE_B) &&
2092         (ieee->modulation & IEEE80211_CCK_MODULATION) &&
2093         (ieee->freq_band & IEEE80211_24GHZ_BAND))
2094         return 1;
2095 
2096     return 0;
2097 }
2098 
2099 static inline int ieee80211_get_hdrlen(u16 fc)
2100 {
2101     int hdrlen = IEEE80211_3ADDR_LEN;
2102 
2103     switch (WLAN_FC_GET_TYPE(fc)) {
2104     case IEEE80211_FTYPE_DATA:
2105         if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
2106             hdrlen = IEEE80211_4ADDR_LEN; /* Addr4 */
2107         if (IEEE80211_QOS_HAS_SEQ(fc))
2108             hdrlen += 2; /* QOS ctrl*/
2109         break;
2110     case IEEE80211_FTYPE_CTL:
2111         switch (WLAN_FC_GET_STYPE(fc)) {
2112         case IEEE80211_STYPE_CTS:
2113         case IEEE80211_STYPE_ACK:
2114             hdrlen = IEEE80211_1ADDR_LEN;
2115             break;
2116         default:
2117             hdrlen = IEEE80211_2ADDR_LEN;
2118             break;
2119         }
2120         break;
2121     }
2122 
2123     return hdrlen;
2124 }
2125 
2126 static inline u8 *ieee80211_get_payload(struct rtl_80211_hdr *hdr)
2127 {
2128     switch (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
2129     case IEEE80211_1ADDR_LEN:
2130         return ((struct rtl_80211_hdr_1addr *)hdr)->payload;
2131     case IEEE80211_2ADDR_LEN:
2132         return ((struct rtl_80211_hdr_2addr *)hdr)->payload;
2133     case IEEE80211_3ADDR_LEN:
2134         return ((struct rtl_80211_hdr_3addr *)hdr)->payload;
2135     case IEEE80211_4ADDR_LEN:
2136         return ((struct rtl_80211_hdr_4addr *)hdr)->payload;
2137     }
2138     return NULL;
2139 }
2140 
2141 static inline int ieee80211_is_ofdm_rate(u8 rate)
2142 {
2143     switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
2144     case IEEE80211_OFDM_RATE_6MB:
2145     case IEEE80211_OFDM_RATE_9MB:
2146     case IEEE80211_OFDM_RATE_12MB:
2147     case IEEE80211_OFDM_RATE_18MB:
2148     case IEEE80211_OFDM_RATE_24MB:
2149     case IEEE80211_OFDM_RATE_36MB:
2150     case IEEE80211_OFDM_RATE_48MB:
2151     case IEEE80211_OFDM_RATE_54MB:
2152         return 1;
2153     }
2154     return 0;
2155 }
2156 
2157 static inline int ieee80211_is_cck_rate(u8 rate)
2158 {
2159     switch (rate & ~IEEE80211_BASIC_RATE_MASK) {
2160     case IEEE80211_CCK_RATE_1MB:
2161     case IEEE80211_CCK_RATE_2MB:
2162     case IEEE80211_CCK_RATE_5MB:
2163     case IEEE80211_CCK_RATE_11MB:
2164         return 1;
2165     }
2166     return 0;
2167 }
2168 
2169 
2170 /* ieee80211.c */
2171 void free_ieee80211(struct net_device *dev);
2172 struct net_device *alloc_ieee80211(int sizeof_priv);
2173 
2174 int ieee80211_set_encryption(struct ieee80211_device *ieee);
2175 
2176 /* ieee80211_tx.c */
2177 
2178 int ieee80211_encrypt_fragment(struct ieee80211_device *ieee,
2179                    struct sk_buff *frag, int hdr_len);
2180 
2181 int ieee80211_xmit(struct sk_buff *skb, struct net_device *dev);
2182 void ieee80211_txb_free(struct ieee80211_txb *txb);
2183 
2184 
2185 /* ieee80211_rx.c */
2186 int ieee80211_rx(struct ieee80211_device *ieee, struct sk_buff *skb,
2187          struct ieee80211_rx_stats *rx_stats);
2188 void ieee80211_rx_mgt(struct ieee80211_device *ieee,
2189               struct rtl_80211_hdr_4addr *header,
2190               struct ieee80211_rx_stats *stats);
2191 
2192 /* ieee80211_wx.c */
2193 int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
2194               struct iw_request_info *info,
2195               union iwreq_data *wrqu, char *key);
2196 int ieee80211_wx_set_encode(struct ieee80211_device *ieee,
2197                 struct iw_request_info *info,
2198                 union iwreq_data *wrqu, char *key);
2199 int ieee80211_wx_get_encode(struct ieee80211_device *ieee,
2200                 struct iw_request_info *info,
2201                 union iwreq_data *wrqu, char *key);
2202 int ieee80211_wx_get_encode_ext(struct ieee80211_device *ieee,
2203                 struct iw_request_info *info,
2204                 union iwreq_data *wrqu, char *extra);
2205 int ieee80211_wx_set_encode_ext(struct ieee80211_device *ieee,
2206                 struct iw_request_info *info,
2207                 union iwreq_data *wrqu, char *extra);
2208 int ieee80211_wx_set_auth(struct ieee80211_device *ieee,
2209               struct iw_request_info *info,
2210               struct iw_param *data, char *extra);
2211 int ieee80211_wx_set_mlme(struct ieee80211_device *ieee,
2212               struct iw_request_info *info,
2213               union iwreq_data *wrqu, char *extra);
2214 int ieee80211_wx_set_gen_ie(struct ieee80211_device *ieee, u8 *ie, size_t len);
2215 
2216 /* ieee80211_softmac.c */
2217 short ieee80211_is_54g(const struct ieee80211_network *net);
2218 short ieee80211_is_shortslot(const struct ieee80211_network *net);
2219 int ieee80211_rx_frame_softmac(struct ieee80211_device *ieee,
2220                    struct sk_buff *skb,
2221                    struct ieee80211_rx_stats *rx_stats,
2222                    u16 type, u16 stype);
2223 void ieee80211_softmac_new_net(struct ieee80211_device *ieee,
2224                    struct ieee80211_network *net);
2225 
2226 void SendDisassociation(struct ieee80211_device *ieee, u8 *asSta, u8 asRsn);
2227 void ieee80211_softmac_xmit(struct ieee80211_txb *txb,
2228                 struct ieee80211_device *ieee);
2229 
2230 void ieee80211_stop_send_beacons(struct ieee80211_device *ieee);
2231 void notify_wx_assoc_event(struct ieee80211_device *ieee);
2232 void ieee80211_softmac_check_all_nets(struct ieee80211_device *ieee);
2233 void ieee80211_start_bss(struct ieee80211_device *ieee);
2234 void ieee80211_start_master_bss(struct ieee80211_device *ieee);
2235 void ieee80211_start_ibss(struct ieee80211_device *ieee);
2236 void ieee80211_softmac_init(struct ieee80211_device *ieee);
2237 void ieee80211_softmac_free(struct ieee80211_device *ieee);
2238 void ieee80211_associate_abort(struct ieee80211_device *ieee);
2239 void ieee80211_disassociate(struct ieee80211_device *ieee);
2240 void ieee80211_stop_scan(struct ieee80211_device *ieee);
2241 void ieee80211_start_scan_syncro(struct ieee80211_device *ieee);
2242 void ieee80211_check_all_nets(struct ieee80211_device *ieee);
2243 void ieee80211_start_protocol(struct ieee80211_device *ieee);
2244 void ieee80211_stop_protocol(struct ieee80211_device *ieee);
2245 void ieee80211_softmac_start_protocol(struct ieee80211_device *ieee);
2246 void ieee80211_softmac_stop_protocol(struct ieee80211_device *ieee);
2247 void ieee80211_reset_queue(struct ieee80211_device *ieee);
2248 void ieee80211_wake_queue(struct ieee80211_device *ieee);
2249 void ieee80211_stop_queue(struct ieee80211_device *ieee);
2250 struct sk_buff *ieee80211_get_beacon(struct ieee80211_device *ieee);
2251 void ieee80211_start_send_beacons(struct ieee80211_device *ieee);
2252 int ieee80211_wpa_supplicant_ioctl(struct ieee80211_device *ieee,
2253                    struct iw_point *p);
2254 void ieee80211_ps_tx_ack(struct ieee80211_device *ieee, short success);
2255 
2256 void softmac_mgmt_xmit(struct sk_buff *skb, struct ieee80211_device *ieee);
2257 
2258 /* ieee80211_crypt_ccmp&tkip&wep.c */
2259 void ieee80211_tkip_null(void);
2260 
2261 int ieee80211_crypto_init(void);
2262 void ieee80211_crypto_deinit(void);
2263 int ieee80211_crypto_tkip_init(void);
2264 void ieee80211_crypto_tkip_exit(void);
2265 int ieee80211_crypto_ccmp_init(void);
2266 void ieee80211_crypto_ccmp_exit(void);
2267 int ieee80211_crypto_wep_init(void);
2268 void ieee80211_crypto_wep_exit(void);
2269 
2270 /* ieee80211_softmac_wx.c */
2271 
2272 int ieee80211_wx_get_wap(struct ieee80211_device *ieee,
2273              struct iw_request_info *info,
2274              union iwreq_data *wrqu, char *ext);
2275 
2276 int ieee80211_wx_set_wap(struct ieee80211_device *ieee,
2277              struct iw_request_info *info,
2278              union iwreq_data *awrq,
2279              char *extra);
2280 
2281 int ieee80211_wx_get_essid(struct ieee80211_device *ieee,
2282                struct iw_request_info *a,
2283                union iwreq_data *wrqu, char *b);
2284 
2285 int ieee80211_wx_set_rate(struct ieee80211_device *ieee,
2286               struct iw_request_info *info,
2287               union iwreq_data *wrqu, char *extra);
2288 
2289 int ieee80211_wx_get_rate(struct ieee80211_device *ieee,
2290               struct iw_request_info *info,
2291               union iwreq_data *wrqu, char *extra);
2292 
2293 int ieee80211_wx_set_mode(struct ieee80211_device *ieee,
2294               struct iw_request_info *a,
2295               union iwreq_data *wrqu, char *b);
2296 
2297 int ieee80211_wx_set_scan(struct ieee80211_device *ieee,
2298               struct iw_request_info *a,
2299               union iwreq_data *wrqu, char *b);
2300 
2301 int ieee80211_wx_set_essid(struct ieee80211_device *ieee,
2302                struct iw_request_info *a,
2303                union iwreq_data *wrqu, char *extra);
2304 
2305 int ieee80211_wx_get_mode(struct ieee80211_device *ieee,
2306               struct iw_request_info *a,
2307               union iwreq_data *wrqu, char *b);
2308 
2309 int ieee80211_wx_set_freq(struct ieee80211_device *ieee,
2310               struct iw_request_info *a,
2311               union iwreq_data *wrqu, char *b);
2312 
2313 int ieee80211_wx_get_freq(struct ieee80211_device *ieee,
2314               struct iw_request_info *a,
2315               union iwreq_data *wrqu, char *b);
2316 
2317 /* ieee80211_module.c */
2318 #ifdef CONFIG_IEEE80211_DEBUG
2319 int ieee80211_debug_init(void);
2320 void ieee80211_debug_exit(void);
2321 #else
2322 static inline int ieee80211_debug_init(void) { return 0; }
2323 static inline void ieee80211_debug_exit(void) { }
2324 #endif
2325 
2326 //extern void ieee80211_wx_sync_scan_wq(struct ieee80211_device *ieee);
2327 void ieee80211_wx_sync_scan_wq(struct work_struct *work);
2328 
2329 
2330 int ieee80211_wx_set_rawtx(struct ieee80211_device *ieee,
2331                struct iw_request_info *info,
2332                    union iwreq_data *wrqu, char *extra);
2333 
2334 int ieee80211_wx_get_name(struct ieee80211_device *ieee,
2335               struct iw_request_info *info,
2336               union iwreq_data *wrqu, char *extra);
2337 
2338 int ieee80211_wx_set_power(struct ieee80211_device *ieee,
2339                struct iw_request_info *info,
2340                union iwreq_data *wrqu, char *extra);
2341 
2342 int ieee80211_wx_get_power(struct ieee80211_device *ieee,
2343                struct iw_request_info *info,
2344                union iwreq_data *wrqu, char *extra);
2345 
2346 int ieee80211_wx_set_rts(struct ieee80211_device *ieee,
2347              struct iw_request_info *info,
2348              union iwreq_data *wrqu, char *extra);
2349 
2350 int ieee80211_wx_get_rts(struct ieee80211_device *ieee,
2351              struct iw_request_info *info,
2352              union iwreq_data *wrqu, char *extra);
2353 //HT
2354 #define MAX_RECEIVE_BUFFER_SIZE 9100  //
2355 void HTDebugHTCapability(u8 *CapIE, u8 *TitleString);
2356 void HTDebugHTInfo(u8 *InfoIE, u8 *TitleString);
2357 
2358 void HTSetConnectBwMode(struct ieee80211_device *ieee,
2359             enum ht_channel_width Bandwidth, enum ht_extension_chan_offset Offset);
2360 void HTUpdateDefaultSetting(struct ieee80211_device *ieee);
2361 void HTConstructCapabilityElement(struct ieee80211_device *ieee, u8 *posHTCap,
2362                   u8 *len, u8 isEncrypt);
2363 void HTConstructInfoElement(struct ieee80211_device *ieee, u8 *posHTInfo,
2364                 u8 *len, u8 isEncrypt);
2365 void HTConstructRT2RTAggElement(struct ieee80211_device *ieee, u8 *posRT2RTAgg,
2366                 u8 *len);
2367 void HTOnAssocRsp(struct ieee80211_device *ieee);
2368 void HTInitializeHTInfo(struct ieee80211_device *ieee);
2369 void HTInitializeBssDesc(PBSS_HT pBssHT);
2370 void HTResetSelfAndSavePeerSetting(struct ieee80211_device *ieee,
2371                    struct ieee80211_network *pNetwork);
2372 void HTUpdateSelfAndPeerSetting(struct ieee80211_device *ieee,
2373                 struct ieee80211_network *pNetwork);
2374 u8 HTGetHighestMCSRate(struct ieee80211_device *ieee,
2375                u8 *pMCSRateSet, u8 *pMCSFilter);
2376 extern u8 MCS_FILTER_ALL[];
2377 extern u16 MCS_DATA_RATE[2][2][77];
2378 u8 HTCCheck(struct ieee80211_device *ieee, u8 *pFrame);
2379 void HTResetIOTSetting(PRT_HIGH_THROUGHPUT pHTInfo);
2380 bool IsHTHalfNmodeAPs(struct ieee80211_device *ieee);
2381 u16 TxCountToDataRate(struct ieee80211_device *ieee, u8 nDataRate);
2382 //function in BAPROC.c
2383 int ieee80211_rx_ADDBAReq(struct ieee80211_device *ieee, struct sk_buff *skb);
2384 int ieee80211_rx_ADDBARsp(struct ieee80211_device *ieee, struct sk_buff *skb);
2385 int ieee80211_rx_DELBA(struct ieee80211_device *ieee, struct sk_buff *skb);
2386 void TsInitAddBA(struct ieee80211_device *ieee, struct tx_ts_record *pTS,
2387          u8 Policy, u8 bOverwritePending);
2388 void TsInitDelBA(struct ieee80211_device *ieee,
2389          struct ts_common_info *pTsCommonInfo, enum tr_select TxRxSelect);
2390 void BaSetupTimeOut(struct timer_list *t);
2391 void TxBaInactTimeout(struct timer_list *t);
2392 void RxBaInactTimeout(struct timer_list *t);
2393 void ResetBaEntry(struct ba_record *pBA);
2394 //function in TS.c
2395 bool GetTs(
2396     struct ieee80211_device     *ieee,
2397     struct ts_common_info           **ppTS,
2398     u8                              *Addr,
2399     u8                              TID,
2400     enum tr_select                  TxRxSelect,  //Rx:1, Tx:0
2401     bool                            bAddNewTs
2402     );
2403 void TSInitialize(struct ieee80211_device *ieee);
2404 void TsStartAddBaProcess(struct ieee80211_device *ieee, struct tx_ts_record   *pTxTS);
2405 void RemovePeerTS(struct ieee80211_device *ieee, u8 *Addr);
2406 void RemoveAllTS(struct ieee80211_device *ieee);
2407 void ieee80211_softmac_scan_syncro(struct ieee80211_device *ieee);
2408 
2409 extern const long ieee80211_wlan_frequencies[];
2410 
2411 static inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
2412 {
2413     ieee->scans++;
2414 }
2415 
2416 static inline int ieee80211_get_scans(struct ieee80211_device *ieee)
2417 {
2418     return ieee->scans;
2419 }
2420 
2421 static inline const char *escape_essid(const char *essid, u8 essid_len)
2422 {
2423     static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
2424 
2425     if (ieee80211_is_empty_essid(essid, essid_len)) {
2426         memcpy(escaped, "<hidden>", sizeof("<hidden>"));
2427         return escaped;
2428     }
2429 
2430     snprintf(escaped, sizeof(escaped), "%*pE", essid_len, essid);
2431     return escaped;
2432 }
2433 
2434 /* For the function is more related to hardware setting, it's better to use the
2435  * ieee handler to refer to it.
2436  */
2437 short check_nic_enough_desc(struct net_device *dev, int queue_index);
2438 int ieee80211_data_xmit(struct sk_buff *skb, struct net_device *dev);
2439 int ieee80211_parse_info_param(struct ieee80211_device *ieee,
2440                    struct ieee80211_info_element *info_element,
2441                    u16 length,
2442                    struct ieee80211_network *network,
2443                    struct ieee80211_rx_stats *stats);
2444 
2445 void ieee80211_indicate_packets(struct ieee80211_device *ieee,
2446                 struct ieee80211_rxb **prxbIndicateArray,
2447                 u8 index);
2448 #define RT_ASOC_RETRY_LIMIT 5
2449 #endif /* IEEE80211_H */