Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Merged with mainline rtllib.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 RTLLIB_H
0021 #define RTLLIB_H
0022 #include <linux/if_ether.h> /* ETH_ALEN */
0023 #include <linux/kernel.h>   /* ARRAY_SIZE */
0024 #include <linux/module.h>
0025 #include <linux/interrupt.h>
0026 #include <linux/jiffies.h>
0027 #include <linux/timer.h>
0028 #include <linux/sched.h>
0029 #include <linux/mutex.h>
0030 
0031 #include <linux/delay.h>
0032 #include <linux/wireless.h>
0033 
0034 #include "rtllib_debug.h"
0035 #include "rtl819x_HT.h"
0036 #include "rtl819x_BA.h"
0037 #include "rtl819x_TS.h"
0038 
0039 #include <linux/netdevice.h>
0040 #include <linux/if_arp.h> /* ARPHRD_ETHER */
0041 #include <net/lib80211.h>
0042 
0043 #define MAX_PRECMD_CNT 16
0044 #define MAX_RFDEPENDCMD_CNT 16
0045 #define MAX_POSTCMD_CNT 16
0046 
0047 #ifndef WIRELESS_SPY
0048 #define WIRELESS_SPY
0049 #endif
0050 #include <net/iw_handler.h>
0051 
0052 #ifndef IW_MODE_MONITOR
0053 #define IW_MODE_MONITOR 6
0054 #endif
0055 
0056 #ifndef IWEVCUSTOM
0057 #define IWEVCUSTOM 0x8c02
0058 #endif
0059 
0060 #ifndef IW_CUSTOM_MAX
0061 /* Max number of char in custom event - use multiple of them if needed */
0062 #define IW_CUSTOM_MAX   256 /* In bytes */
0063 #endif
0064 
0065 #define skb_tail_pointer_rsl(skb) skb_tail_pointer(skb)
0066 
0067 #define queue_delayed_work_rsl(x, y, z) queue_delayed_work(x, y, z)
0068 #define INIT_DELAYED_WORK_RSL(x, y, z) INIT_DELAYED_WORK(x, y)
0069 
0070 #define queue_work_rsl(x, y) queue_work(x, y)
0071 #define INIT_WORK_RSL(x, y, z) INIT_WORK(x, y)
0072 
0073 #define container_of_work_rsl(x, y, z) container_of(x, y, z)
0074 #define container_of_dwork_rsl(x, y, z)             \
0075     container_of(to_delayed_work(x), y, z)
0076 
0077 #define iwe_stream_add_event_rsl(info, start, stop, iwe, len)   \
0078     iwe_stream_add_event(info, start, stop, iwe, len)
0079 
0080 #define iwe_stream_add_point_rsl(info, start, stop, iwe, p) \
0081     iwe_stream_add_point(info, start, stop, iwe, p)
0082 
0083 static inline void *netdev_priv_rsl(struct net_device *dev)
0084 {
0085     return netdev_priv(dev);
0086 }
0087 
0088 #define KEY_TYPE_NA     0x0
0089 #define KEY_TYPE_WEP40      0x1
0090 #define KEY_TYPE_TKIP       0x2
0091 #define KEY_TYPE_CCMP       0x4
0092 #define KEY_TYPE_WEP104     0x5
0093 /* added for rtl819x tx procedure */
0094 #define MAX_QUEUE_SIZE      0x10
0095 
0096 #define BK_QUEUE                   0
0097 #define BE_QUEUE                   1
0098 #define VI_QUEUE                   2
0099 #define VO_QUEUE                   3
0100 #define HCCA_QUEUE               4
0101 #define TXCMD_QUEUE             5
0102 #define MGNT_QUEUE               6
0103 #define HIGH_QUEUE               7
0104 #define BEACON_QUEUE               8
0105 
0106 #ifndef IW_MODE_MESH
0107 #define IW_MODE_MESH            7
0108 #endif
0109 
0110 #define IE_CISCO_FLAG_POSITION      0x08
0111 #define SUPPORT_CKIP_MIC            0x08
0112 #define SUPPORT_CKIP_PK         0x10
0113 #define RT_RF_OFF_LEVL_HALT_NIC     BIT3
0114 #define RT_IN_PS_LEVEL(pPSC, _PS_FLAG)      \
0115     ((pPSC->CurPsLevel & _PS_FLAG) ? true : false)
0116 #define RT_CLEAR_PS_LEVEL(pPSC, _PS_FLAG)   \
0117     (pPSC->CurPsLevel &= (~(_PS_FLAG)))
0118 #define RT_SET_PS_LEVEL(pPSC, _PS_FLAG) (pPSC->CurPsLevel |= _PS_FLAG)
0119 
0120 /* defined for skb cb field */
0121 /* At most 28 byte */
0122 struct cb_desc {
0123     /* Tx Desc Related flags (8-9) */
0124     u8 bLastIniPkt:1;
0125     u8 bCmdOrInit:1;
0126     u8 bFirstSeg:1;
0127     u8 bLastSeg:1;
0128     u8 bEncrypt:1;
0129     u8 bTxDisableRateFallBack:1;
0130     u8 bTxUseDriverAssingedRate:1;
0131     u8 bHwSec:1;
0132 
0133     u8 nStuckCount;
0134 
0135     /* Tx Firmware Related flags (10-11)*/
0136     u8 bCTSEnable:1;
0137     u8 bRTSEnable:1;
0138     u8 bUseShortGI:1;
0139     u8 bUseShortPreamble:1;
0140     u8 bTxEnableFwCalcDur:1;
0141     u8 bAMPDUEnable:1;
0142     u8 bRTSSTBC:1;
0143     u8 RTSSC:1;
0144 
0145     u8 bRTSBW:1;
0146     u8 bPacketBW:1;
0147     u8 bRTSUseShortPreamble:1;
0148     u8 bRTSUseShortGI:1;
0149     u8 bMulticast:1;
0150     u8 bBroadcast:1;
0151     u8 drv_agg_enable:1;
0152     u8 reserved2:1;
0153 
0154     /* Tx Desc related element(12-19) */
0155     u8 rata_index;
0156     u8 queue_index;
0157     u16 txbuf_size;
0158     u8 RATRIndex;
0159     u8 bAMSDU:1;
0160     u8 bFromAggrQ:1;
0161     u8 reserved6:6;
0162     u8 macId;
0163     u8 priority;
0164 
0165     /* Tx firmware related element(20-27) */
0166     u8 data_rate;
0167     u8 rts_rate;
0168     u8 ampdu_factor;
0169     u8 ampdu_density;
0170     u8 DrvAggrNum;
0171     u8 bdhcp;
0172     u16 pkt_size;
0173     u8 bIsSpecialDataFrame;
0174 
0175     u8 bBTTxPacket;
0176     u8 bIsBTProbRsp;
0177 };
0178 
0179 enum sw_chnl_cmd_id {
0180     CmdID_End,
0181     CmdID_SetTxPowerLevel,
0182     CmdID_BBRegWrite10,
0183     CmdID_WritePortUlong,
0184     CmdID_WritePortUshort,
0185     CmdID_WritePortUchar,
0186     CmdID_RF_WriteReg,
0187 };
0188 
0189 struct sw_chnl_cmd {
0190     enum sw_chnl_cmd_id CmdID;
0191     u32         Para1;
0192     u32         Para2;
0193     u32         msDelay;
0194 } __packed;
0195 
0196 /*--------------------------Define -------------------------------------------*/
0197 #define MGN_1M        0x02
0198 #define MGN_2M        0x04
0199 #define MGN_5_5M        0x0b
0200 #define MGN_11M      0x16
0201 
0202 #define MGN_6M        0x0c
0203 #define MGN_9M        0x12
0204 #define MGN_12M      0x18
0205 #define MGN_18M      0x24
0206 #define MGN_24M      0x30
0207 #define MGN_36M      0x48
0208 #define MGN_48M      0x60
0209 #define MGN_54M      0x6c
0210 
0211 #define MGN_MCS0        0x80
0212 #define MGN_MCS1        0x81
0213 #define MGN_MCS2        0x82
0214 #define MGN_MCS3        0x83
0215 #define MGN_MCS4        0x84
0216 #define MGN_MCS5        0x85
0217 #define MGN_MCS6        0x86
0218 #define MGN_MCS7        0x87
0219 #define MGN_MCS8        0x88
0220 #define MGN_MCS9        0x89
0221 #define MGN_MCS10          0x8a
0222 #define MGN_MCS11          0x8b
0223 #define MGN_MCS12          0x8c
0224 #define MGN_MCS13          0x8d
0225 #define MGN_MCS14          0x8e
0226 #define MGN_MCS15          0x8f
0227 
0228 enum hw_variables {
0229     HW_VAR_ETHER_ADDR,
0230     HW_VAR_MULTICAST_REG,
0231     HW_VAR_BASIC_RATE,
0232     HW_VAR_BSSID,
0233     HW_VAR_MEDIA_STATUS,
0234     HW_VAR_SECURITY_CONF,
0235     HW_VAR_BEACON_INTERVAL,
0236     HW_VAR_ATIM_WINDOW,
0237     HW_VAR_LISTEN_INTERVAL,
0238     HW_VAR_CS_COUNTER,
0239     HW_VAR_DEFAULTKEY0,
0240     HW_VAR_DEFAULTKEY1,
0241     HW_VAR_DEFAULTKEY2,
0242     HW_VAR_DEFAULTKEY3,
0243     HW_VAR_SIFS,
0244     HW_VAR_DIFS,
0245     HW_VAR_EIFS,
0246     HW_VAR_SLOT_TIME,
0247     HW_VAR_ACK_PREAMBLE,
0248     HW_VAR_CW_CONFIG,
0249     HW_VAR_CW_VALUES,
0250     HW_VAR_RATE_FALLBACK_CONTROL,
0251     HW_VAR_CONTENTION_WINDOW,
0252     HW_VAR_RETRY_COUNT,
0253     HW_VAR_TR_SWITCH,
0254     HW_VAR_COMMAND,
0255     HW_VAR_WPA_CONFIG,
0256     HW_VAR_AMPDU_MIN_SPACE,
0257     HW_VAR_SHORTGI_DENSITY,
0258     HW_VAR_AMPDU_FACTOR,
0259     HW_VAR_MCS_RATE_AVAILABLE,
0260     HW_VAR_AC_PARAM,
0261     HW_VAR_ACM_CTRL,
0262     HW_VAR_DIS_Req_Qsize,
0263     HW_VAR_CCX_CHNL_LOAD,
0264     HW_VAR_CCX_NOISE_HISTOGRAM,
0265     HW_VAR_CCX_CLM_NHM,
0266     HW_VAR_TxOPLimit,
0267     HW_VAR_TURBO_MODE,
0268     HW_VAR_RF_STATE,
0269     HW_VAR_RF_OFF_BY_HW,
0270     HW_VAR_BUS_SPEED,
0271     HW_VAR_SET_DEV_POWER,
0272 
0273     HW_VAR_RCR,
0274     HW_VAR_RATR_0,
0275     HW_VAR_RRSR,
0276     HW_VAR_CPU_RST,
0277     HW_VAR_CECHK_BSSID,
0278     HW_VAR_LBK_MODE,
0279     HW_VAR_AES_11N_FIX,
0280     HW_VAR_USB_RX_AGGR,
0281     HW_VAR_USER_CONTROL_TURBO_MODE,
0282     HW_VAR_RETRY_LIMIT,
0283     HW_VAR_INIT_TX_RATE,
0284     HW_VAR_TX_RATE_REG,
0285     HW_VAR_EFUSE_USAGE,
0286     HW_VAR_EFUSE_BYTES,
0287     HW_VAR_AUTOLOAD_STATUS,
0288     HW_VAR_RF_2R_DISABLE,
0289     HW_VAR_SET_RPWM,
0290     HW_VAR_H2C_FW_PWRMODE,
0291     HW_VAR_H2C_FW_JOINBSSRPT,
0292     HW_VAR_1X1_RECV_COMBINE,
0293     HW_VAR_STOP_SEND_BEACON,
0294     HW_VAR_TSF_TIMER,
0295     HW_VAR_IO_CMD,
0296 
0297     HW_VAR_RF_RECOVERY,
0298     HW_VAR_H2C_FW_UPDATE_GTK,
0299     HW_VAR_WF_MASK,
0300     HW_VAR_WF_CRC,
0301     HW_VAR_WF_IS_MAC_ADDR,
0302     HW_VAR_H2C_FW_OFFLOAD,
0303     HW_VAR_RESET_WFCRC,
0304 
0305     HW_VAR_HANDLE_FW_C2H,
0306     HW_VAR_DL_FW_RSVD_PAGE,
0307     HW_VAR_AID,
0308     HW_VAR_HW_SEQ_ENABLE,
0309     HW_VAR_CORRECT_TSF,
0310     HW_VAR_BCN_VALID,
0311     HW_VAR_FWLPS_RF_ON,
0312     HW_VAR_DUAL_TSF_RST,
0313     HW_VAR_SWITCH_EPHY_WoWLAN,
0314     HW_VAR_INT_MIGRATION,
0315     HW_VAR_INT_AC,
0316     HW_VAR_RF_TIMING,
0317 };
0318 
0319 enum rt_op_mode {
0320     RT_OP_MODE_AP,
0321     RT_OP_MODE_INFRASTRUCTURE,
0322     RT_OP_MODE_IBSS,
0323     RT_OP_MODE_NO_LINK,
0324 };
0325 
0326 
0327 #define aSifsTime                       \
0328      (((priv->rtllib->current_network.mode == IEEE_A)   \
0329     || (priv->rtllib->current_network.mode == IEEE_N_24G)   \
0330     || (priv->rtllib->current_network.mode == IEEE_N_5G)) ? 16 : 10)
0331 
0332 #define MGMT_QUEUE_NUM 5
0333 
0334 #define MAX_IE_LEN  0xff
0335 
0336 #define msleep_interruptible_rsl  msleep_interruptible
0337 
0338 /* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
0339  * 6.2.1.1.2.
0340  *
0341  * The figure in section 7.1.2 suggests a body size of up to 2312
0342  * bytes is allowed, which is a bit confusing, I suspect this
0343  * represents the 2304 bytes of real data, plus a possible 8 bytes of
0344  * WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro)
0345  */
0346 #define RTLLIB_1ADDR_LEN 10
0347 #define RTLLIB_2ADDR_LEN 16
0348 #define RTLLIB_3ADDR_LEN 24
0349 #define RTLLIB_4ADDR_LEN 30
0350 #define RTLLIB_FCS_LEN    4
0351 
0352 #define RTLLIB_SKBBUFFER_SIZE 2500
0353 
0354 #define MIN_FRAG_THRESHOLD     256U
0355 #define MAX_FRAG_THRESHOLD     2346U
0356 
0357 /* Frame control field constants */
0358 #define RTLLIB_FCTL_FTYPE       0x000c
0359 #define RTLLIB_FCTL_STYPE       0x00f0
0360 #define RTLLIB_FCTL_FRAMETYPE   0x00fc
0361 #define RTLLIB_FCTL_TODS        0x0100
0362 #define RTLLIB_FCTL_FROMDS      0x0200
0363 #define RTLLIB_FCTL_DSTODS      0x0300
0364 #define RTLLIB_FCTL_MOREFRAGS   0x0400
0365 #define RTLLIB_FCTL_RETRY       0x0800
0366 #define RTLLIB_FCTL_PM      0x1000
0367 #define RTLLIB_FCTL_MOREDATA        0x2000
0368 #define RTLLIB_FCTL_WEP     0x4000
0369 #define RTLLIB_FCTL_ORDER       0x8000
0370 
0371 #define RTLLIB_FTYPE_MGMT       0x0000
0372 #define RTLLIB_FTYPE_CTL        0x0004
0373 #define RTLLIB_FTYPE_DATA       0x0008
0374 
0375 /* management */
0376 #define RTLLIB_STYPE_ASSOC_REQ  0x0000
0377 #define RTLLIB_STYPE_ASSOC_RESP     0x0010
0378 #define RTLLIB_STYPE_REASSOC_REQ    0x0020
0379 #define RTLLIB_STYPE_REASSOC_RESP   0x0030
0380 #define RTLLIB_STYPE_PROBE_REQ  0x0040
0381 #define RTLLIB_STYPE_PROBE_RESP 0x0050
0382 #define RTLLIB_STYPE_BEACON     0x0080
0383 #define RTLLIB_STYPE_ATIM       0x0090
0384 #define RTLLIB_STYPE_DISASSOC   0x00A0
0385 #define RTLLIB_STYPE_AUTH       0x00B0
0386 #define RTLLIB_STYPE_DEAUTH     0x00C0
0387 #define RTLLIB_STYPE_MANAGE_ACT 0x00D0
0388 
0389 /* control */
0390 #define RTLLIB_STYPE_PSPOLL     0x00A0
0391 #define RTLLIB_STYPE_RTS        0x00B0
0392 #define RTLLIB_STYPE_CTS        0x00C0
0393 #define RTLLIB_STYPE_ACK        0x00D0
0394 
0395 /* data */
0396 #define RTLLIB_STYPE_DATA       0x0000
0397 #define RTLLIB_STYPE_DATA_CFACK 0x0010
0398 #define RTLLIB_STYPE_DATA_CFPOLL    0x0020
0399 #define RTLLIB_STYPE_DATA_CFACKPOLL 0x0030
0400 #define RTLLIB_STYPE_NULLFUNC   0x0040
0401 #define RTLLIB_STYPE_QOS_DATA   0x0080
0402 #define RTLLIB_STYPE_QOS_NULL   0x00C0
0403 
0404 #define RTLLIB_SCTL_FRAG        0x000F
0405 #define RTLLIB_SCTL_SEQ     0xFFF0
0406 
0407 /* QOS control */
0408 #define RTLLIB_QCTL_TID       0x000F
0409 
0410 #define FC_QOS_BIT                  BIT7
0411 #define IsDataFrame(pdu)    (((pdu[0] & 0x0C) == 0x08) ? true : false)
0412 #define IsLegacyDataFrame(pdu)  (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)))
0413 #define IsQoSDataFrame(pframe)          \
0414     ((*(u16 *)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) ==  \
0415     (RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA))
0416 #define Frame_Order(pframe)     (*(u16 *)pframe&RTLLIB_FCTL_ORDER)
0417 #define SN_LESS(a, b)       (((a-b)&0x800) != 0)
0418 #define SN_EQUAL(a, b)  (a == b)
0419 #define MAX_DEV_ADDR_SIZE 8
0420 
0421 enum act_category {
0422     ACT_CAT_QOS = 1,
0423     ACT_CAT_DLS = 2,
0424     ACT_CAT_BA  = 3,
0425     ACT_CAT_HT  = 7,
0426     ACT_CAT_WMM = 17,
0427 };
0428 
0429 enum ba_action {
0430     ACT_ADDBAREQ = 0,
0431     ACT_ADDBARSP = 1,
0432     ACT_DELBA    = 2,
0433 };
0434 
0435 enum init_gain_op_type {
0436     IG_Backup = 0,
0437     IG_Restore,
0438     IG_Max
0439 };
0440 
0441 enum led_ctl_mode {
0442     LED_CTL_POWER_ON = 1,
0443     LED_CTL_LINK = 2,
0444     LED_CTL_NO_LINK = 3,
0445     LED_CTL_TX = 4,
0446     LED_CTL_RX = 5,
0447     LED_CTL_SITE_SURVEY = 6,
0448     LED_CTL_POWER_OFF = 7,
0449     LED_CTL_START_TO_LINK = 8,
0450 };
0451 
0452 enum rt_rf_type_def {
0453     RF_1T2R = 0,
0454     RF_2T4R,
0455 };
0456 
0457 enum wireless_mode {
0458     WIRELESS_MODE_UNKNOWN = 0x00,
0459     WIRELESS_MODE_A = 0x01,
0460     WIRELESS_MODE_B = 0x02,
0461     WIRELESS_MODE_G = 0x04,
0462     WIRELESS_MODE_AUTO = 0x08,
0463     WIRELESS_MODE_N_24G = 0x10,
0464     WIRELESS_MODE_N_5G = 0x20
0465 };
0466 
0467 #ifndef ETH_P_PAE
0468 #define ETH_P_PAE   0x888E      /* Port Access Entity (IEEE 802.1X) */
0469 #define ETH_P_IP    0x0800      /* Internet Protocol packet */
0470 #define ETH_P_ARP   0x0806      /* Address Resolution packet    */
0471 #endif /* ETH_P_PAE */
0472 
0473 #ifndef ETH_P_80211_RAW
0474 #define ETH_P_80211_RAW (ETH_P_ECONET + 1)
0475 #endif
0476 
0477 /* IEEE 802.11 defines */
0478 
0479 #define P80211_OUI_LEN 3
0480 
0481 struct rtllib_snap_hdr {
0482     u8    dsap;   /* always 0xAA */
0483     u8    ssap;   /* always 0xAA */
0484     u8    ctrl;   /* always 0x03 */
0485     u8    oui[P80211_OUI_LEN];    /* organizational universal id */
0486 
0487 } __packed;
0488 
0489 enum _REG_PREAMBLE_MODE {
0490     PREAMBLE_LONG = 1,
0491     PREAMBLE_AUTO = 2,
0492     PREAMBLE_SHORT = 3,
0493 };
0494 
0495 #define SNAP_SIZE sizeof(struct rtllib_snap_hdr)
0496 
0497 #define WLAN_FC_GET_TYPE(fc) ((fc) & RTLLIB_FCTL_FTYPE)
0498 #define WLAN_FC_GET_STYPE(fc) ((fc) & RTLLIB_FCTL_STYPE)
0499 #define WLAN_FC_MORE_DATA(fc) ((fc) & RTLLIB_FCTL_MOREDATA)
0500 
0501 #define WLAN_FC_GET_FRAMETYPE(fc) ((fc) & RTLLIB_FCTL_FRAMETYPE)
0502 #define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTLLIB_SCTL_FRAG)
0503 #define WLAN_GET_SEQ_SEQ(seq)  (((seq) & RTLLIB_SCTL_SEQ) >> 4)
0504 
0505 /* Authentication algorithms */
0506 #define WLAN_AUTH_OPEN 0
0507 #define WLAN_AUTH_SHARED_KEY 1
0508 #define WLAN_AUTH_LEAP 128
0509 
0510 #define WLAN_CAPABILITY_ESS (1<<0)
0511 #define WLAN_CAPABILITY_IBSS (1<<1)
0512 #define WLAN_CAPABILITY_PRIVACY (1<<4)
0513 #define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
0514 #define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
0515 
0516 #define RTLLIB_STATMASK_SIGNAL (1<<0)
0517 #define RTLLIB_STATMASK_RSSI (1<<1)
0518 #define RTLLIB_STATMASK_NOISE (1<<2)
0519 #define RTLLIB_STATMASK_WEMASK 0x7
0520 
0521 #define RTLLIB_CCK_MODULATION    (1<<0)
0522 #define RTLLIB_OFDM_MODULATION   (1<<1)
0523 
0524 #define RTLLIB_24GHZ_BAND     (1<<0)
0525 #define RTLLIB_52GHZ_BAND     (1<<1)
0526 
0527 #define RTLLIB_CCK_RATE_LEN     4
0528 #define RTLLIB_CCK_RATE_1MB         0x02
0529 #define RTLLIB_CCK_RATE_2MB         0x04
0530 #define RTLLIB_CCK_RATE_5MB         0x0B
0531 #define RTLLIB_CCK_RATE_11MB            0x16
0532 #define RTLLIB_OFDM_RATE_LEN        8
0533 #define RTLLIB_OFDM_RATE_6MB            0x0C
0534 #define RTLLIB_OFDM_RATE_9MB            0x12
0535 #define RTLLIB_OFDM_RATE_12MB       0x18
0536 #define RTLLIB_OFDM_RATE_18MB       0x24
0537 #define RTLLIB_OFDM_RATE_24MB       0x30
0538 #define RTLLIB_OFDM_RATE_36MB       0x48
0539 #define RTLLIB_OFDM_RATE_48MB       0x60
0540 #define RTLLIB_OFDM_RATE_54MB       0x6C
0541 #define RTLLIB_BASIC_RATE_MASK      0x80
0542 
0543 /* this is stolen and modified from the madwifi driver*/
0544 #define RTLLIB_FC0_TYPE_MASK        0x0c
0545 #define RTLLIB_FC0_TYPE_DATA        0x08
0546 #define RTLLIB_FC0_SUBTYPE_MASK 0xB0
0547 #define RTLLIB_FC0_SUBTYPE_QOS  0x80
0548 
0549 #define RTLLIB_QOS_HAS_SEQ(fc) \
0550     (((fc) & (RTLLIB_FC0_TYPE_MASK | RTLLIB_FC0_SUBTYPE_MASK)) == \
0551      (RTLLIB_FC0_TYPE_DATA | RTLLIB_FC0_SUBTYPE_QOS))
0552 
0553 /* this is stolen from ipw2200 driver */
0554 #define IEEE_IBSS_MAC_HASH_SIZE 31
0555 struct ieee_ibss_seq {
0556     u8 mac[ETH_ALEN];
0557     u16 seq_num[17];
0558     u16 frag_num[17];
0559     unsigned long packet_time[17];
0560     struct list_head list;
0561 };
0562 
0563 /* NOTE: This data is for statistical purposes; not all hardware provides this
0564  *       information for frames received.  Not setting these will not cause
0565  *       any adverse affects.
0566  */
0567 struct rtllib_rx_stats {
0568     u64 mac_time;
0569     s8  rssi;
0570     u8  signal;
0571     u8  noise;
0572     u16 rate; /* in 100 kbps */
0573     u8  received_channel;
0574     u8  control;
0575     u8  mask;
0576     u8  freq;
0577     u16 len;
0578     u64 tsf;
0579     u32 beacon_time;
0580     u8  nic_type;
0581     u16 Length;
0582     u8  SignalQuality;
0583     s32 RecvSignalPower;
0584     s8  RxPower;
0585     u8  SignalStrength;
0586     u16 bHwError:1;
0587     u16 bCRC:1;
0588     u16 bICV:1;
0589     u16 bShortPreamble:1;
0590     u16 Antenna:1;
0591     u16 Decrypted:1;
0592     u16 Wakeup:1;
0593     u16 Reserved0:1;
0594     u8  AGC;
0595     u32 TimeStampLow;
0596     u32 TimeStampHigh;
0597     bool bShift;
0598     bool bIsQosData;
0599 
0600     u8    RxDrvInfoSize;
0601     u8    RxBufShift;
0602     bool  bIsAMPDU;
0603     bool  bFirstMPDU;
0604     bool  bContainHTC;
0605     bool  RxIs40MHzPacket;
0606     u32   RxPWDBAll;
0607     u8    RxMIMOSignalStrength[4];
0608     s8    RxMIMOSignalQuality[2];
0609     bool  bPacketMatchBSSID;
0610     bool  bIsCCK;
0611     bool  bPacketToSelf;
0612     u16    packetlength;
0613     u16    fraglength;
0614     u16    fragoffset;
0615     u16    ntotalfrag;
0616     bool   bPacketBeacon;
0617     bool   bToSelfBA;
0618     u16    Seq_Num;
0619 };
0620 
0621 /* IEEE 802.11 requires that STA supports concurrent reception of at least
0622  * three fragmented frames. This define can be increased to support more
0623  * concurrent frames, but it should be noted that each entry can consume about
0624  * 2 kB of RAM and increasing cache size will slow down frame reassembly.
0625  */
0626 #define RTLLIB_FRAG_CACHE_LEN 4
0627 
0628 struct rtllib_frag_entry {
0629     unsigned long first_frag_time;
0630     unsigned int seq;
0631     unsigned int last_frag;
0632     struct sk_buff *skb;
0633     u8 src_addr[ETH_ALEN];
0634     u8 dst_addr[ETH_ALEN];
0635 };
0636 
0637 struct rtllib_device;
0638 
0639 #define SEC_ACTIVE_KEY    (1<<4)
0640 #define SEC_AUTH_MODE     (1<<5)
0641 #define SEC_UNICAST_GROUP (1<<6)
0642 #define SEC_LEVEL    (1<<7)
0643 #define SEC_ENABLED       (1<<8)
0644 
0645 #define SEC_LEVEL_0      0 /* None */
0646 #define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
0647 #define SEC_LEVEL_2      2 /* Level 1 + TKIP */
0648 #define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
0649 #define SEC_LEVEL_3      4 /* Level 2 + CCMP */
0650 
0651 #define SEC_ALG_NONE        0
0652 #define SEC_ALG_WEP     1
0653 #define SEC_ALG_TKIP        2
0654 #define SEC_ALG_CCMP        4
0655 
0656 #define WEP_KEY_LEN     13
0657 #define SCM_KEY_LEN     32
0658 
0659 struct rtllib_security {
0660     u16 active_key:2,
0661         enabled:1,
0662         auth_mode:2,
0663         auth_algo:4,
0664         unicast_uses_group:1,
0665         encrypt:1;
0666     u8 key_sizes[NUM_WEP_KEYS];
0667     u8 keys[NUM_WEP_KEYS][SCM_KEY_LEN];
0668     u8 level;
0669     u16 flags;
0670 } __packed;
0671 
0672 
0673 /* 802.11 data frame from AP
0674  *       ,-------------------------------------------------------------------.
0675  * Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
0676  *       |------|------|---------|---------|---------|------|---------|------|
0677  * Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
0678  *       |      | tion | (BSSID) |         |         | ence |  data   |      |
0679  *       `-------------------------------------------------------------------'
0680  * Total: 28-2340 bytes
0681  */
0682 
0683 /* Management Frame Information Element Types */
0684 enum rtllib_mfie {
0685     MFIE_TYPE_SSID = 0,
0686     MFIE_TYPE_RATES = 1,
0687     MFIE_TYPE_FH_SET = 2,
0688     MFIE_TYPE_DS_SET = 3,
0689     MFIE_TYPE_CF_SET = 4,
0690     MFIE_TYPE_TIM = 5,
0691     MFIE_TYPE_IBSS_SET = 6,
0692     MFIE_TYPE_COUNTRY = 7,
0693     MFIE_TYPE_HOP_PARAMS = 8,
0694     MFIE_TYPE_HOP_TABLE = 9,
0695     MFIE_TYPE_REQUEST = 10,
0696     MFIE_TYPE_CHALLENGE = 16,
0697     MFIE_TYPE_POWER_CONSTRAINT = 32,
0698     MFIE_TYPE_POWER_CAPABILITY = 33,
0699     MFIE_TYPE_TPC_REQUEST = 34,
0700     MFIE_TYPE_TPC_REPORT = 35,
0701     MFIE_TYPE_SUPP_CHANNELS = 36,
0702     MFIE_TYPE_CSA = 37,
0703     MFIE_TYPE_MEASURE_REQUEST = 38,
0704     MFIE_TYPE_MEASURE_REPORT = 39,
0705     MFIE_TYPE_QUIET = 40,
0706     MFIE_TYPE_IBSS_DFS = 41,
0707     MFIE_TYPE_ERP = 42,
0708     MFIE_TYPE_HT_CAP = 45,
0709     MFIE_TYPE_RSN = 48,
0710     MFIE_TYPE_RATES_EX = 50,
0711     MFIE_TYPE_HT_INFO = 61,
0712     MFIE_TYPE_AIRONET = 133,
0713     MFIE_TYPE_GENERIC = 221,
0714     MFIE_TYPE_QOS_PARAMETER = 222,
0715 };
0716 
0717 /* Minimal header; can be used for passing 802.11 frames with sufficient
0718  * information to determine what type of underlying data type is actually
0719  * stored in the data.
0720  */
0721 struct rtllib_pspoll_hdr {
0722     __le16 frame_ctl;
0723     __le16 aid;
0724     u8 bssid[ETH_ALEN];
0725     u8 ta[ETH_ALEN];
0726 } __packed;
0727 
0728 struct rtllib_hdr {
0729     __le16 frame_ctl;
0730     __le16 duration_id;
0731     u8 payload[];
0732 } __packed;
0733 
0734 struct rtllib_hdr_1addr {
0735     __le16 frame_ctl;
0736     __le16 duration_id;
0737     u8 addr1[ETH_ALEN];
0738     u8 payload[];
0739 } __packed;
0740 
0741 struct rtllib_hdr_2addr {
0742     __le16 frame_ctl;
0743     __le16 duration_id;
0744     u8 addr1[ETH_ALEN];
0745     u8 addr2[ETH_ALEN];
0746     u8 payload[];
0747 } __packed;
0748 
0749 struct rtllib_hdr_3addr {
0750     __le16 frame_ctl;
0751     __le16 duration_id;
0752     u8 addr1[ETH_ALEN];
0753     u8 addr2[ETH_ALEN];
0754     u8 addr3[ETH_ALEN];
0755     __le16 seq_ctl;
0756     u8 payload[];
0757 } __packed;
0758 
0759 struct rtllib_hdr_4addr {
0760     __le16 frame_ctl;
0761     __le16 duration_id;
0762     u8 addr1[ETH_ALEN];
0763     u8 addr2[ETH_ALEN];
0764     u8 addr3[ETH_ALEN];
0765     __le16 seq_ctl;
0766     u8 addr4[ETH_ALEN];
0767     u8 payload[];
0768 } __packed;
0769 
0770 struct rtllib_hdr_3addrqos {
0771     __le16 frame_ctl;
0772     __le16 duration_id;
0773     u8 addr1[ETH_ALEN];
0774     u8 addr2[ETH_ALEN];
0775     u8 addr3[ETH_ALEN];
0776     __le16 seq_ctl;
0777     __le16 qos_ctl;
0778     u8 payload[];
0779 } __packed;
0780 
0781 struct rtllib_hdr_4addrqos {
0782     __le16 frame_ctl;
0783     __le16 duration_id;
0784     u8 addr1[ETH_ALEN];
0785     u8 addr2[ETH_ALEN];
0786     u8 addr3[ETH_ALEN];
0787     __le16 seq_ctl;
0788     u8 addr4[ETH_ALEN];
0789     __le16 qos_ctl;
0790     u8 payload[];
0791 } __packed;
0792 
0793 struct rtllib_info_element {
0794     u8 id;
0795     u8 len;
0796     u8 data[];
0797 } __packed;
0798 
0799 struct rtllib_authentication {
0800     struct rtllib_hdr_3addr header;
0801     __le16 algorithm;
0802     __le16 transaction;
0803     __le16 status;
0804     /*challenge*/
0805     struct rtllib_info_element info_element[];
0806 } __packed;
0807 
0808 struct rtllib_disauth {
0809     struct rtllib_hdr_3addr header;
0810     __le16 reason;
0811 } __packed;
0812 
0813 struct rtllib_disassoc {
0814     struct rtllib_hdr_3addr header;
0815     __le16 reason;
0816 } __packed;
0817 
0818 struct rtllib_probe_request {
0819     struct rtllib_hdr_3addr header;
0820     /* SSID, supported rates */
0821     struct rtllib_info_element info_element[];
0822 } __packed;
0823 
0824 struct rtllib_probe_response {
0825     struct rtllib_hdr_3addr header;
0826     u32 time_stamp[2];
0827     __le16 beacon_interval;
0828     __le16 capability;
0829     /* SSID, supported rates, FH params, DS params,
0830      * CF params, IBSS params, TIM (if beacon), RSN
0831      */
0832     struct rtllib_info_element info_element[];
0833 } __packed;
0834 
0835 /* Alias beacon for probe_response */
0836 #define rtllib_beacon rtllib_probe_response
0837 
0838 struct rtllib_assoc_request_frame {
0839     struct rtllib_hdr_3addr header;
0840     __le16 capability;
0841     __le16 listen_interval;
0842     /* SSID, supported rates, RSN */
0843     struct rtllib_info_element info_element[];
0844 } __packed;
0845 
0846 struct rtllib_assoc_response_frame {
0847     struct rtllib_hdr_3addr header;
0848     __le16 capability;
0849     __le16 status;
0850     __le16 aid;
0851     struct rtllib_info_element info_element[]; /* supported rates */
0852 } __packed;
0853 
0854 struct rtllib_txb {
0855     u8 nr_frags;
0856     u8 encrypted;
0857     u8 queue_index;
0858     u8 rts_included;
0859     u16 reserved;
0860     __le16 frag_size;
0861     __le16 payload_size;
0862     struct sk_buff *fragments[];
0863 };
0864 
0865 #define MAX_SUBFRAME_COUNT        64
0866 struct rtllib_rxb {
0867     u8 nr_subframes;
0868     struct sk_buff *subframes[MAX_SUBFRAME_COUNT];
0869     u8 dst[ETH_ALEN];
0870     u8 src[ETH_ALEN];
0871 } __packed;
0872 
0873 union frameqos {
0874     u16 shortdata;
0875     u8  chardata[2];
0876     struct {
0877         u16 tid:4;
0878         u16 eosp:1;
0879         u16 ack_policy:2;
0880         u16 reserved:1;
0881         u16 txop:8;
0882     } field;
0883 };
0884 
0885 /* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
0886  * only use 8, and then use extended rates for the remaining supported
0887  * rates.  Other APs, however, stick all of their supported rates on the
0888  * main rates information element...
0889  */
0890 #define MAX_RATES_LENGTH          ((u8)12)
0891 #define MAX_RATES_EX_LENGTH        ((u8)16)
0892 #define MAX_NETWORK_COUNT         96
0893 
0894 #define MAX_CHANNEL_NUMBER       161
0895 #define RTLLIB_SOFTMAC_SCAN_TIME       100
0896 #define RTLLIB_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
0897 
0898 #define MAX_WPA_IE_LEN 64
0899 #define MAX_WZC_IE_LEN 256
0900 
0901 #define NETWORK_EMPTY_ESSID (1<<0)
0902 #define NETWORK_HAS_OFDM    (1<<1)
0903 #define NETWORK_HAS_CCK     (1<<2)
0904 
0905 /* QoS structure */
0906 #define NETWORK_HAS_QOS_PARAMETERS      (1<<3)
0907 #define NETWORK_HAS_QOS_INFORMATION     (1<<4)
0908 #define NETWORK_HAS_QOS_MASK        (NETWORK_HAS_QOS_PARAMETERS | \
0909                      NETWORK_HAS_QOS_INFORMATION)
0910 /* 802.11h */
0911 #define NETWORK_HAS_ERP_VALUE      (1<<10)
0912 
0913 #define QOS_QUEUE_NUM          4
0914 #define QOS_OUI_LEN          3
0915 #define QOS_OUI_TYPE            2
0916 #define QOS_ELEMENT_ID        221
0917 #define QOS_OUI_INFO_SUB_TYPE      0
0918 #define QOS_OUI_PARAM_SUB_TYPE    1
0919 #define QOS_VERSION_1          1
0920 
0921 struct rtllib_qos_information_element {
0922     u8 elementID;
0923     u8 length;
0924     u8 qui[QOS_OUI_LEN];
0925     u8 qui_type;
0926     u8 qui_subtype;
0927     u8 version;
0928     u8 ac_info;
0929 } __packed;
0930 
0931 struct rtllib_qos_ac_parameter {
0932     u8 aci_aifsn;
0933     u8 ecw_min_max;
0934     __le16 tx_op_limit;
0935 } __packed;
0936 
0937 struct rtllib_qos_parameter_info {
0938     struct rtllib_qos_information_element info_element;
0939     u8 reserved;
0940     struct rtllib_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
0941 } __packed;
0942 
0943 struct rtllib_qos_parameters {
0944     __le16 cw_min[QOS_QUEUE_NUM];
0945     __le16 cw_max[QOS_QUEUE_NUM];
0946     u8 aifs[QOS_QUEUE_NUM];
0947     u8 flag[QOS_QUEUE_NUM];
0948     __le16 tx_op_limit[QOS_QUEUE_NUM];
0949 } __packed;
0950 
0951 struct rtllib_qos_data {
0952     struct rtllib_qos_parameters parameters;
0953     unsigned int wmm_acm;
0954     int active;
0955     int supported;
0956     u8 param_count;
0957     u8 old_param_count;
0958 };
0959 
0960 struct rtllib_tim_parameters {
0961     u8 tim_count;
0962     u8 tim_period;
0963 } __packed;
0964 
0965 struct rtllib_wmm_ac_param {
0966     u8 ac_aci_acm_aifsn;
0967     u8 ac_ecwmin_ecwmax;
0968     u16 ac_txop_limit;
0969 };
0970 
0971 enum eap_type {
0972     EAP_PACKET = 0,
0973     EAPOL_START,
0974     EAPOL_LOGOFF,
0975     EAPOL_KEY,
0976     EAPOL_ENCAP_ASF_ALERT
0977 };
0978 
0979 static const char * const eap_types[] = {
0980     [EAP_PACKET]        = "EAP-Packet",
0981     [EAPOL_START]       = "EAPOL-Start",
0982     [EAPOL_LOGOFF]      = "EAPOL-Logoff",
0983     [EAPOL_KEY]     = "EAPOL-Key",
0984     [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
0985 };
0986 
0987 static inline const char *eap_get_type(int type)
0988 {
0989     return ((u32)type >= ARRAY_SIZE(eap_types)) ? "Unknown" :
0990          eap_types[type];
0991 }
0992 static inline u8 Frame_QoSTID(u8 *buf)
0993 {
0994     struct rtllib_hdr_3addr *hdr;
0995     u16 fc;
0996 
0997     hdr = (struct rtllib_hdr_3addr *)buf;
0998     fc = le16_to_cpu(hdr->frame_ctl);
0999     return (u8)((union frameqos *)(buf + (((fc & RTLLIB_FCTL_TODS) &&
1000             (fc & RTLLIB_FCTL_FROMDS)) ? 30 : 24)))->field.tid;
1001 }
1002 
1003 
1004 struct eapol {
1005     u8 snap[6];
1006     u16 ethertype;
1007     u8 version;
1008     u8 type;
1009     u16 length;
1010 } __packed;
1011 
1012 struct rtllib_softmac_stats {
1013     unsigned int rx_ass_ok;
1014     unsigned int rx_ass_err;
1015     unsigned int rx_probe_rq;
1016     unsigned int tx_probe_rs;
1017     unsigned int tx_beacons;
1018     unsigned int rx_auth_rq;
1019     unsigned int rx_auth_rs_ok;
1020     unsigned int rx_auth_rs_err;
1021     unsigned int tx_auth_rq;
1022     unsigned int no_auth_rs;
1023     unsigned int no_ass_rs;
1024     unsigned int tx_ass_rq;
1025     unsigned int rx_ass_rq;
1026     unsigned int tx_probe_rq;
1027     unsigned int reassoc;
1028     unsigned int swtxstop;
1029     unsigned int swtxawake;
1030     unsigned char CurrentShowTxate;
1031     unsigned char last_packet_rate;
1032     unsigned int txretrycount;
1033 };
1034 
1035 /* These are the data types that can make up management packets
1036  *
1037  * u16 auth_algorithm;
1038  * u16 auth_sequence;
1039  * u16 beacon_interval;
1040  * u16 capability;
1041  * u8 current_ap[ETH_ALEN];
1042  * u16 listen_interval;
1043  * struct {
1044  *   u16 association_id:14, reserved:2;
1045  * } __packed;
1046  * u32 time_stamp[2];
1047  * u16 reason;
1048  * u16 status;
1049  */
1050 
1051 #define RTLLIB_DEFAULT_TX_ESSID "Penguin"
1052 #define RTLLIB_DEFAULT_BASIC_RATE 2
1053 
1054 enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
1055 #define MAX_SP_Len  (WMM_all_frame << 4)
1056 #define RTLLIB_QOS_TID 0x0f
1057 #define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
1058 
1059 #define RTLLIB_DTIM_MBCAST 4
1060 #define RTLLIB_DTIM_UCAST 2
1061 #define RTLLIB_DTIM_VALID 1
1062 #define RTLLIB_DTIM_INVALID 0
1063 
1064 #define RTLLIB_PS_DISABLED 0
1065 #define RTLLIB_PS_UNICAST RTLLIB_DTIM_UCAST
1066 #define RTLLIB_PS_MBCAST RTLLIB_DTIM_MBCAST
1067 
1068 #define WME_AC_BK   0x00
1069 #define WME_AC_BE   0x01
1070 #define WME_AC_VI   0x02
1071 #define WME_AC_VO   0x03
1072 #define WME_AC_PRAM_LEN 16
1073 
1074 #define MAX_RECEIVE_BUFFER_SIZE 9100
1075 
1076 #define UP2AC(up) (        \
1077     ((up) < 1) ? WME_AC_BE : \
1078     ((up) < 3) ? WME_AC_BK : \
1079     ((up) < 4) ? WME_AC_BE : \
1080     ((up) < 6) ? WME_AC_VI : \
1081     WME_AC_VO)
1082 
1083 #define ETHER_ADDR_LEN      6   /* length of an Ethernet address */
1084 #define ETHERNET_HEADER_SIZE    14      /* length of two Ethernet address
1085                      * plus ether type
1086                      */
1087 
1088 enum erp_t {
1089     ERP_NonERPpresent   = 0x01,
1090     ERP_UseProtection   = 0x02,
1091     ERP_BarkerPreambleMode = 0x04,
1092 };
1093 
1094 struct rtllib_network {
1095     /* These entries are used to identify a unique network */
1096     u8 bssid[ETH_ALEN];
1097     u8 channel;
1098     /* Ensure null-terminated for any debug msgs */
1099     u8 ssid[IW_ESSID_MAX_SIZE + 1];
1100     u8 ssid_len;
1101     u8 hidden_ssid[IW_ESSID_MAX_SIZE + 1];
1102     u8 hidden_ssid_len;
1103     struct rtllib_qos_data qos_data;
1104 
1105     bool    bWithAironetIE;
1106     bool    bCkipSupported;
1107     bool    bCcxRmEnable;
1108     u8  CcxRmState[2];
1109     bool    bMBssidValid;
1110     u8  MBssidMask;
1111     u8  MBssid[ETH_ALEN];
1112     bool    bWithCcxVerNum;
1113     u8  BssCcxVerNumber;
1114     /* These are network statistics */
1115     struct rtllib_rx_stats stats;
1116     u16 capability;
1117     u8  rates[MAX_RATES_LENGTH];
1118     u8  rates_len;
1119     u8  rates_ex[MAX_RATES_EX_LENGTH];
1120     u8  rates_ex_len;
1121     unsigned long last_scanned;
1122     u8  mode;
1123     u32 flags;
1124     u32 time_stamp[2];
1125     u16 beacon_interval;
1126     u16 listen_interval;
1127     u16 atim_window;
1128     u8  erp_value;
1129     u8  wpa_ie[MAX_WPA_IE_LEN];
1130     size_t wpa_ie_len;
1131     u8  rsn_ie[MAX_WPA_IE_LEN];
1132     size_t rsn_ie_len;
1133     u8  wzc_ie[MAX_WZC_IE_LEN];
1134     size_t wzc_ie_len;
1135 
1136     struct rtllib_tim_parameters tim;
1137     u8  dtim_period;
1138     u8  dtim_data;
1139     u64 last_dtim_sta_time;
1140 
1141     u8 wmm_info;
1142     struct rtllib_wmm_ac_param wmm_param[4];
1143     u8 Turbo_Enable;
1144     u16 CountryIeLen;
1145     u8 CountryIeBuf[MAX_IE_LEN];
1146     struct bss_ht bssht;
1147     bool broadcom_cap_exist;
1148     bool realtek_cap_exit;
1149     bool marvell_cap_exist;
1150     bool ralink_cap_exist;
1151     bool atheros_cap_exist;
1152     bool cisco_cap_exist;
1153     bool airgo_cap_exist;
1154     bool unknown_cap_exist;
1155     bool    berp_info_valid;
1156     bool buseprotection;
1157     u8 SignalStrength;
1158     u8 RSSI;
1159     struct list_head list;
1160 };
1161 
1162 enum rtllib_state {
1163 
1164     /* the card is not linked at all */
1165     RTLLIB_NOLINK = 0,
1166 
1167     /* RTLLIB_ASSOCIATING* are for BSS client mode
1168      * the driver shall not perform RX filtering unless
1169      * the state is LINKED.
1170      * The driver shall just check for the state LINKED and
1171      * defaults to NOLINK for ALL the other states (including
1172      * LINKED_SCANNING)
1173      */
1174 
1175     /* the association procedure will start (wq scheduling)*/
1176     RTLLIB_ASSOCIATING,
1177     RTLLIB_ASSOCIATING_RETRY,
1178 
1179     /* the association procedure is sending AUTH request*/
1180     RTLLIB_ASSOCIATING_AUTHENTICATING,
1181 
1182     /* the association procedure has successfully authenticated
1183      * and is sending association request
1184      */
1185     RTLLIB_ASSOCIATING_AUTHENTICATED,
1186 
1187     /* the link is ok. the card associated to a BSS or linked
1188      * to a ibss cell or acting as an AP and creating the bss
1189      */
1190     RTLLIB_LINKED,
1191 
1192     /* same as LINKED, but the driver shall apply RX filter
1193      * rules as we are in NO_LINK mode. As the card is still
1194      * logically linked, but it is doing a syncro site survey
1195      * then it will be back to LINKED state.
1196      */
1197     RTLLIB_LINKED_SCANNING,
1198 };
1199 
1200 #define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1201 #define DEFAULT_FTS 2346
1202 
1203 #define CFG_RTLLIB_RESERVE_FCS (1<<0)
1204 #define CFG_RTLLIB_COMPUTE_FCS (1<<1)
1205 
1206 struct tx_pending {
1207     int frag;
1208     struct rtllib_txb *txb;
1209 };
1210 
1211 struct bandwidth_autoswitch {
1212     long threshold_20Mhzto40Mhz;
1213     long    threshold_40Mhzto20Mhz;
1214     bool bforced_tx20Mhz;
1215     bool bautoswitch_enable;
1216 };
1217 
1218 
1219 
1220 #define REORDER_WIN_SIZE    128
1221 #define REORDER_ENTRY_NUM   128
1222 struct rx_reorder_entry {
1223     struct list_head    List;
1224     u16         SeqNum;
1225     struct rtllib_rxb *prxb;
1226 };
1227 enum fsync_state {
1228     Default_Fsync,
1229     HW_Fsync,
1230     SW_Fsync
1231 };
1232 
1233 enum rt_ps_mode {
1234     eActive,
1235     eMaxPs,
1236     eFastPs,
1237     eAutoPs,
1238 };
1239 
1240 enum ips_callback_function {
1241     IPS_CALLBACK_NONE = 0,
1242     IPS_CALLBACK_MGNT_LINK_REQUEST = 1,
1243     IPS_CALLBACK_JOIN_REQUEST = 2,
1244 };
1245 
1246 enum rt_rf_power_state {
1247     eRfOn,
1248     eRfSleep,
1249     eRfOff
1250 };
1251 
1252 struct rt_pwr_save_ctrl {
1253 
1254     bool                bInactivePs;
1255     bool                bIPSModeBackup;
1256     bool                bSwRfProcessing;
1257     enum rt_rf_power_state eInactivePowerState;
1258     enum ips_callback_function ReturnPoint;
1259 
1260     bool                bLeisurePs;
1261     u8              LpsIdleCount;
1262     u8              RegMaxLPSAwakeIntvl;
1263     u8              LPSAwakeIntvl;
1264 
1265     u32             CurPsLevel;
1266     u32             RegRfPsLevel;
1267 
1268     bool                bFwCtrlLPS;
1269 
1270 };
1271 
1272 #define RT_RF_CHANGE_SOURCE u32
1273 
1274 #define RF_CHANGE_BY_SW BIT31
1275 #define RF_CHANGE_BY_HW BIT30
1276 #define RF_CHANGE_BY_PS BIT29
1277 #define RF_CHANGE_BY_IPS BIT28
1278 #define RF_CHANGE_BY_INIT   0
1279 
1280 enum country_code_type {
1281     COUNTRY_CODE_FCC = 0,
1282     COUNTRY_CODE_IC = 1,
1283     COUNTRY_CODE_ETSI = 2,
1284     COUNTRY_CODE_SPAIN = 3,
1285     COUNTRY_CODE_FRANCE = 4,
1286     COUNTRY_CODE_MKK = 5,
1287     COUNTRY_CODE_MKK1 = 6,
1288     COUNTRY_CODE_ISRAEL = 7,
1289     COUNTRY_CODE_TELEC = 8,
1290     COUNTRY_CODE_MIC = 9,
1291     COUNTRY_CODE_GLOBAL_DOMAIN = 10,
1292     COUNTRY_CODE_WORLD_WIDE_13 = 11,
1293     COUNTRY_CODE_TELEC_NETGEAR = 12,
1294     COUNTRY_CODE_MAX
1295 };
1296 
1297 enum scan_op_backup_opt {
1298     SCAN_OPT_BACKUP = 0,
1299     SCAN_OPT_RESTORE,
1300     SCAN_OPT_MAX
1301 };
1302 
1303 enum fw_cmd_io_type {
1304     FW_CMD_DIG_ENABLE = 0,
1305     FW_CMD_DIG_DISABLE = 1,
1306     FW_CMD_DIG_HALT = 2,
1307     FW_CMD_DIG_RESUME = 3,
1308     FW_CMD_HIGH_PWR_ENABLE = 4,
1309     FW_CMD_HIGH_PWR_DISABLE = 5,
1310     FW_CMD_RA_RESET = 6,
1311     FW_CMD_RA_ACTIVE = 7,
1312     FW_CMD_RA_REFRESH_N = 8,
1313     FW_CMD_RA_REFRESH_BG = 9,
1314     FW_CMD_RA_INIT = 10,
1315     FW_CMD_IQK_ENABLE = 11,
1316     FW_CMD_TXPWR_TRACK_ENABLE = 12,
1317     FW_CMD_TXPWR_TRACK_DISABLE = 13,
1318     FW_CMD_TXPWR_TRACK_THERMAL = 14,
1319     FW_CMD_PAUSE_DM_BY_SCAN = 15,
1320     FW_CMD_RESUME_DM_BY_SCAN = 16,
1321     FW_CMD_RA_REFRESH_N_COMB = 17,
1322     FW_CMD_RA_REFRESH_BG_COMB = 18,
1323     FW_CMD_ANTENNA_SW_ENABLE = 19,
1324     FW_CMD_ANTENNA_SW_DISABLE = 20,
1325     FW_CMD_TX_FEEDBACK_CCX_ENABLE = 21,
1326     FW_CMD_LPS_ENTER = 22,
1327     FW_CMD_LPS_LEAVE = 23,
1328 };
1329 
1330 #define RT_MAX_LD_SLOT_NUM  10
1331 struct rt_link_detect {
1332 
1333     u32             NumRecvBcnInPeriod;
1334     u32             NumRecvDataInPeriod;
1335 
1336     u32             RxBcnNum[RT_MAX_LD_SLOT_NUM];
1337     u32             RxDataNum[RT_MAX_LD_SLOT_NUM];
1338     u16             SlotNum;
1339     u16             SlotIndex;
1340 
1341     u32             NumTxOkInPeriod;
1342     u32             NumRxOkInPeriod;
1343     u32             NumRxUnicastOkInPeriod;
1344     bool                bBusyTraffic;
1345     bool                bHigherBusyTraffic;
1346     bool                bHigherBusyRxTraffic;
1347 };
1348 
1349 struct sw_cam_table {
1350 
1351     u8              macaddr[ETH_ALEN];
1352     bool                bused;
1353     u8              key_buf[16];
1354     u16             key_type;
1355     u8              useDK;
1356     u8              key_index;
1357 
1358 };
1359 #define   TOTAL_CAM_ENTRY               32
1360 struct rate_adaptive {
1361     u8              rate_adaptive_disabled;
1362     u8              ratr_state;
1363     u16             reserve;
1364 
1365     u32             high_rssi_thresh_for_ra;
1366     u32             high2low_rssi_thresh_for_ra;
1367     u8              low2high_rssi_thresh_for_ra40M;
1368     u32             low_rssi_thresh_for_ra40M;
1369     u8              low2high_rssi_thresh_for_ra20M;
1370     u32             low_rssi_thresh_for_ra20M;
1371     u32             upper_rssi_threshold_ratr;
1372     u32             middle_rssi_threshold_ratr;
1373     u32             low_rssi_threshold_ratr;
1374     u32             low_rssi_threshold_ratr_40M;
1375     u32             low_rssi_threshold_ratr_20M;
1376     u8              ping_rssi_enable;
1377     u32             ping_rssi_ratr;
1378     u32             ping_rssi_thresh_for_ra;
1379     u32             last_ratr;
1380     u8              PreRATRState;
1381 
1382 };
1383 
1384 #define NUM_PMKID_CACHE     16
1385 struct rt_pmkid_list {
1386     u8 Bssid[ETH_ALEN];
1387     u8 PMKID[16];
1388     u8 SsidBuf[33];
1389     u8 bUsed;
1390 };
1391 
1392 struct rt_intel_promisc_mode {
1393     bool bPromiscuousOn;
1394     bool bFilterSourceStationFrame;
1395 };
1396 
1397 
1398 /*************** DRIVER STATUS   *****/
1399 #define STATUS_SCANNING         0
1400 /*************** DRIVER STATUS   *****/
1401 
1402 enum {
1403     LPS_IS_WAKE = 0,
1404     LPS_IS_SLEEP = 1,
1405     LPS_WAIT_NULL_DATA_SEND = 2,
1406 };
1407 
1408 struct rtllib_device {
1409     struct pci_dev *pdev;
1410     struct net_device *dev;
1411     struct rtllib_security sec;
1412 
1413     bool disable_mgnt_queue;
1414 
1415     unsigned long status;
1416     u8  CntAfterLink;
1417 
1418     enum rt_op_mode OpMode;
1419 
1420     /* The last AssocReq/Resp IEs */
1421     u8 *assocreq_ies, *assocresp_ies;
1422     size_t assocreq_ies_len, assocresp_ies_len;
1423 
1424     bool    bForcedBgMode;
1425     u8 RF_Type;
1426 
1427     u8 hwsec_active;
1428     bool is_silent_reset;
1429     bool is_roaming;
1430     bool ieee_up;
1431     bool cannot_notify;
1432     bool bSupportRemoteWakeUp;
1433     bool actscanning;
1434     bool FirstIe_InScan;
1435     bool be_scan_inprogress;
1436     bool beinretry;
1437     enum rt_rf_power_state eRFPowerState;
1438     RT_RF_CHANGE_SOURCE RfOffReason;
1439     bool is_set_key;
1440     bool wx_set_enc;
1441     struct rt_hi_throughput *pHTInfo;
1442 
1443     spinlock_t reorder_spinlock;
1444     u8  Regdot11HTOperationalRateSet[16];
1445     u8  Regdot11TxHTOperationalRateSet[16];
1446     u8  dot11HTOperationalRateSet[16];
1447     u8  RegHTSuppRateSet[16];
1448     u8  HTCurrentOperaRate;
1449     u8  HTHighestOperaRate;
1450     u8  bTxDisableRateFallBack;
1451     u8  bTxUseDriverAssingedRate;
1452     u8  bTxEnableFwCalcDur;
1453     atomic_t    atm_swbw;
1454 
1455     struct list_head        Tx_TS_Admit_List;
1456     struct list_head        Tx_TS_Pending_List;
1457     struct list_head        Tx_TS_Unused_List;
1458     struct tx_ts_record TxTsRecord[TOTAL_TS_NUM];
1459     struct list_head        Rx_TS_Admit_List;
1460     struct list_head        Rx_TS_Pending_List;
1461     struct list_head        Rx_TS_Unused_List;
1462     struct rx_ts_record RxTsRecord[TOTAL_TS_NUM];
1463     struct rx_reorder_entry RxReorderEntry[128];
1464     struct list_head        RxReorder_Unused_List;
1465 
1466 
1467     /* Bookkeeping structures */
1468     struct net_device_stats stats;
1469     struct rtllib_softmac_stats softmac_stats;
1470 
1471     /* Probe / Beacon management */
1472     struct list_head network_free_list;
1473     struct list_head network_list;
1474     struct rtllib_network *networks;
1475     int scans;
1476     int scan_age;
1477 
1478     int iw_mode; /* operating mode (IW_MODE_*) */
1479     bool bNetPromiscuousMode;
1480     struct rt_intel_promisc_mode IntelPromiscuousModeInfo;
1481 
1482     spinlock_t lock;
1483     spinlock_t wpax_suitlist_lock;
1484 
1485     int tx_headroom; /* Set to size of any additional room needed at front
1486               * of allocated Tx SKBs
1487               */
1488     u32 config;
1489 
1490     /* WEP and other encryption related settings at the device level */
1491     int open_wep; /* Set to 1 to allow unencrypted frames */
1492     int auth_mode;
1493     int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
1494                  * WEP key changes
1495                  */
1496 
1497     /* If the host performs {en,de}cryption, then set to 1 */
1498     int host_encrypt;
1499     int host_decrypt;
1500 
1501     int ieee802_1x; /* is IEEE 802.1X used */
1502 
1503     /* WPA data */
1504     bool bHalfWirelessN24GMode;
1505     int wpa_enabled;
1506     int drop_unencrypted;
1507     int tkip_countermeasures;
1508     int privacy_invoked;
1509     size_t wpa_ie_len;
1510     u8 *wpa_ie;
1511     size_t wps_ie_len;
1512     u8 *wps_ie;
1513     u8 ap_mac_addr[ETH_ALEN];
1514     u16 pairwise_key_type;
1515     u16 group_key_type;
1516 
1517     struct lib80211_crypt_info crypt_info;
1518 
1519     struct sw_cam_table swcamtable[TOTAL_CAM_ENTRY];
1520 
1521     struct rt_pmkid_list PMKIDList[NUM_PMKID_CACHE];
1522 
1523     /* Fragmentation structures */
1524     struct rtllib_frag_entry frag_cache[17][RTLLIB_FRAG_CACHE_LEN];
1525     unsigned int frag_next_idx[17];
1526     u16 fts; /* Fragmentation Threshold */
1527 #define DEFAULT_RTS_THRESHOLD 2346U
1528 #define MIN_RTS_THRESHOLD 1
1529 #define MAX_RTS_THRESHOLD 2346U
1530     u16 rts; /* RTS threshold */
1531 
1532     /* Association info */
1533     u8 bssid[ETH_ALEN];
1534 
1535     /* This stores infos for the current network.
1536      * Either the network we are associated in INFRASTRUCTURE
1537      * or the network that we are creating in MASTER mode.
1538      * ad-hoc is a mixture ;-).
1539      * Note that in infrastructure mode, even when not associated,
1540      * fields bssid and essid may be valid (if wpa_set and essid_set
1541      * are true) as thy carry the value set by the user via iwconfig
1542      */
1543     struct rtllib_network current_network;
1544 
1545     enum rtllib_state state;
1546 
1547     int short_slot;
1548     int mode;       /* A, B, G */
1549     int modulation; /* CCK, OFDM */
1550 
1551     /* used for forcing the ibss workqueue to terminate
1552      * without wait for the syncro scan to terminate
1553      */
1554     short sync_scan_hurryup;
1555     u16 scan_watch_dog;
1556 
1557     /* map of allowed channels. 0 is dummy */
1558     void *dot11d_info;
1559     bool global_domain;
1560     u8 active_channel_map[MAX_CHANNEL_NUMBER+1];
1561 
1562     u8   bss_start_channel;
1563     u8   ibss_maxjoin_chal;
1564 
1565     int rate;       /* current rate */
1566     int basic_rate;
1567 
1568     short active_scan;
1569 
1570     /* this contains flags for selectively enable softmac support */
1571     u16 softmac_features;
1572 
1573     /* if the sequence control field is not filled by HW */
1574     u16 seq_ctrl[5];
1575 
1576     /* association procedure transaction sequence number */
1577     u16 associate_seq;
1578 
1579     /* AID for RTXed association responses */
1580     u16 assoc_id;
1581 
1582     /* power save mode related*/
1583     u8 ack_tx_to_ieee;
1584     short ps;
1585     short sta_sleep;
1586     int ps_timeout;
1587     int ps_period;
1588     struct work_struct ps_task;
1589     u64 ps_time;
1590     bool polling;
1591 
1592     short raw_tx;
1593     /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1594     short queue_stop;
1595     short scanning_continue;
1596     short proto_started;
1597     short proto_stoppping;
1598 
1599     struct mutex wx_mutex;
1600     struct mutex scan_mutex;
1601     struct mutex ips_mutex;
1602 
1603     spinlock_t mgmt_tx_lock;
1604     spinlock_t beacon_lock;
1605 
1606     short beacon_txing;
1607 
1608     short wap_set;
1609     short ssid_set;
1610 
1611     /* set on initialization */
1612     unsigned int wmm_acm;
1613 
1614     /* for discarding duplicated packets in IBSS */
1615     struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
1616 
1617     /* for discarding duplicated packets in BSS */
1618     u16 last_rxseq_num[17]; /* rx seq previous per-tid */
1619     u16 last_rxfrag_num[17];/* tx frag previous per-tid */
1620     unsigned long last_packet_time[17];
1621 
1622     /* for PS mode */
1623     unsigned long last_rx_ps_time;
1624     bool            bAwakePktSent;
1625     u8          LPSDelayCnt;
1626 
1627     /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
1628     struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
1629     int mgmt_queue_head;
1630     int mgmt_queue_tail;
1631     u8 AsocRetryCount;
1632     struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE];
1633     struct sk_buff_head  skb_aggQ[MAX_QUEUE_SIZE];
1634 
1635     bool    bdynamic_txpower_enable;
1636 
1637     bool bCTSToSelfEnable;
1638 
1639     u32 fsync_time_interval;
1640     u32 fsync_rate_bitmap;
1641     u8  fsync_rssi_threshold;
1642     bool    bfsync_enable;
1643 
1644     u8  fsync_multiple_timeinterval;
1645     u32 fsync_firstdiff_ratethreshold;
1646     u32 fsync_seconddiff_ratethreshold;
1647     enum fsync_state fsync_state;
1648     bool        bis_any_nonbepkts;
1649     struct bandwidth_autoswitch bandwidth_auto_switch;
1650     bool FwRWRF;
1651 
1652     struct rt_link_detect LinkDetectInfo;
1653     bool bIsAggregateFrame;
1654     struct rt_pwr_save_ctrl PowerSaveControl;
1655 
1656     /* used if IEEE_SOFTMAC_TX_QUEUE is set */
1657     struct tx_pending tx_pending;
1658 
1659     /* used if IEEE_SOFTMAC_ASSOCIATE is set */
1660     struct timer_list associate_timer;
1661 
1662     /* used if IEEE_SOFTMAC_BEACONS is set */
1663     struct timer_list beacon_timer;
1664     u8 need_sw_enc;
1665     struct work_struct associate_complete_wq;
1666     struct work_struct ips_leave_wq;
1667     struct delayed_work associate_procedure_wq;
1668     struct delayed_work softmac_scan_wq;
1669     struct delayed_work associate_retry_wq;
1670     struct delayed_work start_ibss_wq;
1671     struct delayed_work hw_wakeup_wq;
1672     struct delayed_work hw_sleep_wq;
1673     struct delayed_work link_change_wq;
1674     struct work_struct wx_sync_scan_wq;
1675 
1676     union {
1677         struct rtllib_rxb *RfdArray[REORDER_WIN_SIZE];
1678         struct rtllib_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
1679         struct rtllib_rxb *prxbIndicateArray[REORDER_WIN_SIZE];
1680         struct {
1681             struct sw_chnl_cmd PreCommonCmd[MAX_PRECMD_CNT];
1682             struct sw_chnl_cmd PostCommonCmd[MAX_POSTCMD_CNT];
1683             struct sw_chnl_cmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
1684         };
1685     };
1686 
1687     /* Callback functions */
1688     void (*set_security)(struct net_device *dev,
1689                  struct rtllib_security *sec);
1690 
1691     /* Used to TX data frame by using txb structs.
1692      * this is not used if in the softmac_features
1693      * is set the flag IEEE_SOFTMAC_TX_QUEUE
1694      */
1695     int (*hard_start_xmit)(struct rtllib_txb *txb,
1696                    struct net_device *dev);
1697 
1698     int (*reset_port)(struct net_device *dev);
1699 
1700     /* Softmac-generated frames (management) are TXed via this
1701      * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
1702      * not set. As some cards may have different HW queues that
1703      * one might want to use for data and management frames
1704      * the option to have two callbacks might be useful.
1705      * This function can't sleep.
1706      */
1707     int (*softmac_hard_start_xmit)(struct sk_buff *skb,
1708                    struct net_device *dev);
1709 
1710     /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
1711      * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
1712      * frames. If the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
1713      * then also management frames are sent via this callback.
1714      * This function can't sleep.
1715      */
1716     void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
1717                    struct net_device *dev, int rate);
1718 
1719     /* stops the HW queue for DATA frames. Useful to avoid
1720      * waste time to TX data frame when we are reassociating
1721      * This function can sleep.
1722      */
1723     void (*data_hard_stop)(struct net_device *dev);
1724 
1725     /* OK this is complementing to data_poll_hard_stop */
1726     void (*data_hard_resume)(struct net_device *dev);
1727 
1728     /* ask to the driver to retune the radio.
1729      * This function can sleep. the driver should ensure
1730      * the radio has been switched before return.
1731      */
1732     void (*set_chan)(struct net_device *dev, short ch);
1733 
1734     void (*rtllib_start_hw_scan)(struct net_device *dev);
1735     void (*rtllib_stop_hw_scan)(struct net_device *dev);
1736 
1737     /* indicate the driver that the link state is changed
1738      * for example it may indicate the card is associated now.
1739      * Driver might be interested in this to apply RX filter
1740      * rules or simply light the LINK led
1741      */
1742     void (*link_change)(struct net_device *dev);
1743 
1744     /* these two function indicates to the HW when to start
1745      * and stop to send beacons. This is used when the
1746      * IEEE_SOFTMAC_BEACONS is not set. For now the
1747      * stop_send_bacons is NOT guaranteed to be called only
1748      * after start_send_beacons.
1749      */
1750     void (*start_send_beacons)(struct net_device *dev);
1751     void (*stop_send_beacons)(struct net_device *dev);
1752 
1753     /* power save mode related */
1754     void (*sta_wake_up)(struct net_device *dev);
1755     void (*enter_sleep_state)(struct net_device *dev, u64 time);
1756     short (*ps_is_queue_empty)(struct net_device *dev);
1757     int (*handle_beacon)(struct net_device *dev,
1758                  struct rtllib_beacon *beacon,
1759                  struct rtllib_network *network);
1760     int (*handle_assoc_response)(struct net_device *dev,
1761                      struct rtllib_assoc_response_frame *resp,
1762                      struct rtllib_network *network);
1763 
1764 
1765     /* check whether Tx hw resource available */
1766     short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
1767     void (*SetBWModeHandler)(struct net_device *dev,
1768                  enum ht_channel_width Bandwidth,
1769                  enum ht_extchnl_offset Offset);
1770     bool (*GetNmodeSupportBySecCfg)(struct net_device *dev);
1771     void (*SetWirelessMode)(struct net_device *dev, u8 wireless_mode);
1772     bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device *dev);
1773     u8   (*rtllib_ap_sec_type)(struct rtllib_device *ieee);
1774     void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
1775     bool (*SetFwCmdHandler)(struct net_device *dev,
1776                 enum fw_cmd_io_type FwCmdIO);
1777     void (*UpdateBeaconInterruptHandler)(struct net_device *dev,
1778                          bool start);
1779     void (*ScanOperationBackupHandler)(struct net_device *dev,
1780                        u8 Operation);
1781     void (*LedControlHandler)(struct net_device *dev,
1782                   enum led_ctl_mode LedAction);
1783     void (*SetHwRegHandler)(struct net_device *dev, u8 variable, u8 *val);
1784 
1785     void (*AllowAllDestAddrHandler)(struct net_device *dev,
1786                     bool bAllowAllDA, bool WriteIntoReg);
1787 
1788     void (*rtllib_ips_leave_wq)(struct net_device *dev);
1789     void (*rtllib_ips_leave)(struct net_device *dev);
1790     void (*LeisurePSLeave)(struct net_device *dev);
1791 
1792     /* This must be the last item so that it points to the data
1793      * allocated beyond this structure by alloc_rtllib
1794      */
1795     u8 priv[];
1796 };
1797 
1798 #define IEEE_A      (1<<0)
1799 #define IEEE_B      (1<<1)
1800 #define IEEE_G      (1<<2)
1801 #define IEEE_N_24G        (1<<4)
1802 #define IEEE_N_5G         (1<<5)
1803 #define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
1804 
1805 /* Generate a 802.11 header */
1806 
1807 /* Uses the channel change callback directly
1808  * instead of [start/stop] scan callbacks
1809  */
1810 #define IEEE_SOFTMAC_SCAN (1<<2)
1811 
1812 /* Perform authentication and association handshake */
1813 #define IEEE_SOFTMAC_ASSOCIATE (1<<3)
1814 
1815 /* Generate probe requests */
1816 #define IEEE_SOFTMAC_PROBERQ (1<<4)
1817 
1818 /* Generate response to probe requests */
1819 #define IEEE_SOFTMAC_PROBERS (1<<5)
1820 
1821 /* The ieee802.11 stack will manage the netif queue
1822  * wake/stop for the driver, taking care of 802.11
1823  * fragmentation. See softmac.c for details.
1824  */
1825 #define IEEE_SOFTMAC_TX_QUEUE (1<<7)
1826 
1827 /* Uses only the softmac_data_hard_start_xmit
1828  * even for TX management frames.
1829  */
1830 #define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
1831 
1832 /* Generate beacons.  The stack will enqueue beacons
1833  * to the card
1834  */
1835 #define IEEE_SOFTMAC_BEACONS (1<<6)
1836 
1837 
1838 static inline void *rtllib_priv(struct net_device *dev)
1839 {
1840     return ((struct rtllib_device *)netdev_priv(dev))->priv;
1841 }
1842 
1843 static inline int rtllib_is_empty_essid(const char *essid, int essid_len)
1844 {
1845     /* Single white space is for Linksys APs */
1846     if (essid_len == 1 && essid[0] == ' ')
1847         return 1;
1848 
1849     /* Otherwise, if the entire essid is 0, we assume it is hidden */
1850     while (essid_len) {
1851         essid_len--;
1852         if (essid[essid_len] != '\0')
1853             return 0;
1854     }
1855 
1856     return 1;
1857 }
1858 
1859 static inline int rtllib_get_hdrlen(u16 fc)
1860 {
1861     int hdrlen = RTLLIB_3ADDR_LEN;
1862 
1863     switch (WLAN_FC_GET_TYPE(fc)) {
1864     case RTLLIB_FTYPE_DATA:
1865         if ((fc & RTLLIB_FCTL_FROMDS) && (fc & RTLLIB_FCTL_TODS))
1866             hdrlen = RTLLIB_4ADDR_LEN; /* Addr4 */
1867         if (RTLLIB_QOS_HAS_SEQ(fc))
1868             hdrlen += 2; /* QOS ctrl*/
1869         break;
1870     case RTLLIB_FTYPE_CTL:
1871         switch (WLAN_FC_GET_STYPE(fc)) {
1872         case RTLLIB_STYPE_CTS:
1873         case RTLLIB_STYPE_ACK:
1874             hdrlen = RTLLIB_1ADDR_LEN;
1875             break;
1876         default:
1877             hdrlen = RTLLIB_2ADDR_LEN;
1878             break;
1879         }
1880         break;
1881     }
1882 
1883     return hdrlen;
1884 }
1885 
1886 static inline u8 *rtllib_get_payload(struct rtllib_hdr *hdr)
1887 {
1888     switch (rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
1889     case RTLLIB_1ADDR_LEN:
1890         return ((struct rtllib_hdr_1addr *)hdr)->payload;
1891     case RTLLIB_2ADDR_LEN:
1892         return ((struct rtllib_hdr_2addr *)hdr)->payload;
1893     case RTLLIB_3ADDR_LEN:
1894         return ((struct rtllib_hdr_3addr *)hdr)->payload;
1895     case RTLLIB_4ADDR_LEN:
1896         return ((struct rtllib_hdr_4addr *)hdr)->payload;
1897     }
1898     return NULL;
1899 }
1900 
1901 static inline int rtllib_is_ofdm_rate(u8 rate)
1902 {
1903     switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
1904     case RTLLIB_OFDM_RATE_6MB:
1905     case RTLLIB_OFDM_RATE_9MB:
1906     case RTLLIB_OFDM_RATE_12MB:
1907     case RTLLIB_OFDM_RATE_18MB:
1908     case RTLLIB_OFDM_RATE_24MB:
1909     case RTLLIB_OFDM_RATE_36MB:
1910     case RTLLIB_OFDM_RATE_48MB:
1911     case RTLLIB_OFDM_RATE_54MB:
1912         return 1;
1913     }
1914     return 0;
1915 }
1916 
1917 static inline int rtllib_is_cck_rate(u8 rate)
1918 {
1919     switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
1920     case RTLLIB_CCK_RATE_1MB:
1921     case RTLLIB_CCK_RATE_2MB:
1922     case RTLLIB_CCK_RATE_5MB:
1923     case RTLLIB_CCK_RATE_11MB:
1924         return 1;
1925     }
1926     return 0;
1927 }
1928 
1929 
1930 /* rtllib.c */
1931 void free_rtllib(struct net_device *dev);
1932 struct net_device *alloc_rtllib(int sizeof_priv);
1933 
1934 /* rtllib_tx.c */
1935 
1936 int rtllib_encrypt_fragment(
1937     struct rtllib_device *ieee,
1938     struct sk_buff *frag,
1939     int hdr_len);
1940 
1941 int rtllib_xmit(struct sk_buff *skb,  struct net_device *dev);
1942 void rtllib_txb_free(struct rtllib_txb *txb);
1943 
1944 /* rtllib_rx.c */
1945 int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
1946           struct rtllib_rx_stats *rx_stats);
1947 void rtllib_rx_probe_rq(struct rtllib_device *ieee,
1948             struct sk_buff *skb);
1949 int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel);
1950 
1951 /* rtllib_wx.c */
1952 int rtllib_wx_get_scan(struct rtllib_device *ieee,
1953                struct iw_request_info *info,
1954                union iwreq_data *wrqu, char *key);
1955 int rtllib_wx_set_encode(struct rtllib_device *ieee,
1956              struct iw_request_info *info,
1957              union iwreq_data *wrqu, char *key);
1958 int rtllib_wx_get_encode(struct rtllib_device *ieee,
1959              struct iw_request_info *info,
1960              union iwreq_data *wrqu, char *key);
1961 int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
1962                  struct iw_request_info *info,
1963                  union iwreq_data *wrqu, char *extra);
1964 int rtllib_wx_set_auth(struct rtllib_device *ieee,
1965                struct iw_request_info *info,
1966                struct iw_param *data, char *extra);
1967 int rtllib_wx_set_mlme(struct rtllib_device *ieee,
1968                struct iw_request_info *info,
1969                union iwreq_data *wrqu, char *extra);
1970 int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len);
1971 
1972 /* rtllib_softmac.c */
1973 int rtllib_rx_frame_softmac(struct rtllib_device *ieee, struct sk_buff *skb,
1974                 struct rtllib_rx_stats *rx_stats, u16 type,
1975                 u16 stype);
1976 void rtllib_softmac_new_net(struct rtllib_device *ieee,
1977                 struct rtllib_network *net);
1978 
1979 void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn);
1980 void rtllib_softmac_xmit(struct rtllib_txb *txb, struct rtllib_device *ieee);
1981 
1982 void rtllib_start_ibss(struct rtllib_device *ieee);
1983 int rtllib_softmac_init(struct rtllib_device *ieee);
1984 void rtllib_softmac_free(struct rtllib_device *ieee);
1985 void rtllib_disassociate(struct rtllib_device *ieee);
1986 void rtllib_stop_scan(struct rtllib_device *ieee);
1987 bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan);
1988 void rtllib_stop_scan_syncro(struct rtllib_device *ieee);
1989 void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
1990 void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee, short pwr);
1991 void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee);
1992 void rtllib_start_protocol(struct rtllib_device *ieee);
1993 void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown);
1994 
1995 void rtllib_EnableNetMonitorMode(struct net_device *dev, bool bInitState);
1996 void rtllib_DisableNetMonitorMode(struct net_device *dev, bool bInitState);
1997 void rtllib_EnableIntelPromiscuousMode(struct net_device *dev, bool bInitState);
1998 void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
1999                     bool bInitState);
2000 void rtllib_softmac_stop_protocol(struct rtllib_device *ieee,
2001                   u8 mesh_flag, u8 shutdown);
2002 void rtllib_softmac_start_protocol(struct rtllib_device *ieee, u8 mesh_flag);
2003 
2004 void rtllib_reset_queue(struct rtllib_device *ieee);
2005 void rtllib_wake_all_queues(struct rtllib_device *ieee);
2006 void rtllib_stop_all_queues(struct rtllib_device *ieee);
2007 struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee);
2008 void rtllib_start_send_beacons(struct rtllib_device *ieee);
2009 void rtllib_stop_send_beacons(struct rtllib_device *ieee);
2010 
2011 void notify_wx_assoc_event(struct rtllib_device *ieee);
2012 void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success);
2013 
2014 void softmac_mgmt_xmit(struct sk_buff *skb, struct rtllib_device *ieee);
2015 u8 rtllib_ap_sec_type(struct rtllib_device *ieee);
2016 
2017 /* rtllib_softmac_wx.c */
2018 
2019 int rtllib_wx_get_wap(struct rtllib_device *ieee, struct iw_request_info *info,
2020               union iwreq_data *wrqu, char *ext);
2021 
2022 int rtllib_wx_set_wap(struct rtllib_device *ieee, struct iw_request_info *info,
2023               union iwreq_data *awrq, char *extra);
2024 
2025 int rtllib_wx_get_essid(struct rtllib_device *ieee, struct iw_request_info *a,
2026             union iwreq_data *wrqu, char *b);
2027 
2028 int rtllib_wx_set_rate(struct rtllib_device *ieee, struct iw_request_info *info,
2029                union iwreq_data *wrqu, char *extra);
2030 
2031 int rtllib_wx_get_rate(struct rtllib_device *ieee, struct iw_request_info *info,
2032                union iwreq_data *wrqu, char *extra);
2033 
2034 int rtllib_wx_set_mode(struct rtllib_device *ieee, struct iw_request_info *a,
2035                union iwreq_data *wrqu, char *b);
2036 
2037 int rtllib_wx_set_scan(struct rtllib_device *ieee, struct iw_request_info *a,
2038                union iwreq_data *wrqu, char *b);
2039 
2040 int rtllib_wx_set_essid(struct rtllib_device *ieee, struct iw_request_info *a,
2041             union iwreq_data *wrqu, char *extra);
2042 
2043 int rtllib_wx_get_mode(struct rtllib_device *ieee, struct iw_request_info *a,
2044                union iwreq_data *wrqu, char *b);
2045 
2046 int rtllib_wx_set_freq(struct rtllib_device *ieee, struct iw_request_info *a,
2047                union iwreq_data *wrqu, char *b);
2048 
2049 int rtllib_wx_get_freq(struct rtllib_device *ieee, struct iw_request_info *a,
2050                union iwreq_data *wrqu, char *b);
2051 void rtllib_wx_sync_scan_wq(void *data);
2052 
2053 int rtllib_wx_set_rawtx(struct rtllib_device *ieee,
2054             struct iw_request_info *info,
2055             union iwreq_data *wrqu, char *extra);
2056 
2057 int rtllib_wx_get_name(struct rtllib_device *ieee, struct iw_request_info *info,
2058                union iwreq_data *wrqu, char *extra);
2059 
2060 int rtllib_wx_set_power(struct rtllib_device *ieee,
2061             struct iw_request_info *info,
2062             union iwreq_data *wrqu, char *extra);
2063 
2064 int rtllib_wx_get_power(struct rtllib_device *ieee,
2065             struct iw_request_info *info,
2066             union iwreq_data *wrqu, char *extra);
2067 
2068 int rtllib_wx_set_rts(struct rtllib_device *ieee, struct iw_request_info *info,
2069               union iwreq_data *wrqu, char *extra);
2070 
2071 int rtllib_wx_get_rts(struct rtllib_device *ieee, struct iw_request_info *info,
2072               union iwreq_data *wrqu, char *extra);
2073 #define MAX_RECEIVE_BUFFER_SIZE 9100
2074 
2075 void HTSetConnectBwMode(struct rtllib_device *ieee,
2076             enum ht_channel_width Bandwidth,
2077             enum ht_extchnl_offset Offset);
2078 void HTUpdateDefaultSetting(struct rtllib_device *ieee);
2079 void HTConstructCapabilityElement(struct rtllib_device *ieee,
2080                   u8 *posHTCap, u8 *len,
2081                   u8 isEncrypt, bool bAssoc);
2082 void HTConstructInfoElement(struct rtllib_device *ieee,
2083                 u8 *posHTInfo, u8 *len, u8 isEncrypt);
2084 void HTConstructRT2RTAggElement(struct rtllib_device *ieee,
2085                 u8 *posRT2RTAgg, u8 *len);
2086 void HTOnAssocRsp(struct rtllib_device *ieee);
2087 void HTInitializeHTInfo(struct rtllib_device *ieee);
2088 void HTInitializeBssDesc(struct bss_ht *pBssHT);
2089 void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee,
2090                    struct rtllib_network *pNetwork);
2091 void HT_update_self_and_peer_setting(struct rtllib_device *ieee,
2092                      struct rtllib_network *pNetwork);
2093 u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet,
2094                u8 *pMCSFilter);
2095 extern u8 MCS_FILTER_ALL[];
2096 extern u16 MCS_DATA_RATE[2][2][77];
2097 u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame);
2098 void HTResetIOTSetting(struct rt_hi_throughput *pHTInfo);
2099 bool IsHTHalfNmodeAPs(struct rtllib_device *ieee);
2100 u16  TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate);
2101 int rtllib_rx_ADDBAReq(struct rtllib_device *ieee, struct sk_buff *skb);
2102 int rtllib_rx_ADDBARsp(struct rtllib_device *ieee, struct sk_buff *skb);
2103 int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb);
2104 void TsInitAddBA(struct rtllib_device *ieee, struct tx_ts_record *pTS,
2105          u8 Policy, u8 bOverwritePending);
2106 void TsInitDelBA(struct rtllib_device *ieee,
2107          struct ts_common_info *pTsCommonInfo,
2108          enum tr_select TxRxSelect);
2109 void BaSetupTimeOut(struct timer_list *t);
2110 void TxBaInactTimeout(struct timer_list *t);
2111 void RxBaInactTimeout(struct timer_list *t);
2112 void ResetBaEntry(struct ba_record *pBA);
2113 bool GetTs(struct rtllib_device *ieee, struct ts_common_info **ppTS, u8 *Addr,
2114        u8 TID, enum tr_select TxRxSelect, bool bAddNewTs);
2115 void TSInitialize(struct rtllib_device *ieee);
2116 void TsStartAddBaProcess(struct rtllib_device *ieee,
2117              struct tx_ts_record *pTxTS);
2118 void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr);
2119 void RemoveAllTS(struct rtllib_device *ieee);
2120 
2121 extern const long rtllib_wlan_frequencies[];
2122 
2123 static inline const char *escape_essid(const char *essid, u8 essid_len)
2124 {
2125     static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
2126 
2127     if (rtllib_is_empty_essid(essid, essid_len)) {
2128         memcpy(escaped, "<hidden>", sizeof("<hidden>"));
2129         return escaped;
2130     }
2131 
2132     snprintf(escaped, sizeof(escaped), "%*pE", essid_len, essid);
2133     return escaped;
2134 }
2135 
2136 /* fun with the built-in rtllib stack... */
2137 bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn);
2138 
2139 
2140 /* For the function is more related to hardware setting, it's better to use the
2141  * ieee handler to refer to it.
2142  */
2143 void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,
2144                  struct rx_ts_record *pTS);
2145 int rtllib_parse_info_param(struct rtllib_device *ieee,
2146                 struct rtllib_info_element *info_element,
2147                 u16 length,
2148                 struct rtllib_network *network,
2149                 struct rtllib_rx_stats *stats);
2150 
2151 void rtllib_indicate_packets(struct rtllib_device *ieee,
2152                  struct rtllib_rxb **prxbIndicateArray, u8  index);
2153 void HTUseDefaultSetting(struct rtllib_device *ieee);
2154 #define RT_ASOC_RETRY_LIMIT 5
2155 u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee);
2156 
2157 #endif /* RTLLIB_H */