linux/drivers/staging/rtl8192e/rtllib.h
<<
>>
Prefs
   1/*
   2 * Merged with mainline rtllib.h in Aug 2004.  Original ieee802_11
   3 * remains copyright by the original authors
   4 *
   5 * Portions of the merged code are based on Host AP (software wireless
   6 * LAN access point) driver for Intersil Prism2/2.5/3.
   7 *
   8 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
   9 * <jkmaline@cc.hut.fi>
  10 * Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
  11 *
  12 * Adaption to a generic IEEE 802.11 stack by James Ketrenos
  13 * <jketreno@linux.intel.com>
  14 * Copyright (c) 2004, Intel Corporation
  15 *
  16 * Modified for Realtek's wi-fi cards by Andrea Merello
  17 * <andrea.merello@gmail.com>
  18 *
  19 * This program is free software; you can redistribute it and/or modify
  20 * it under the terms of the GNU General Public License version 2 as
  21 * published by the Free Software Foundation. See README and COPYING for
  22 * more details.
  23 */
  24#ifndef RTLLIB_H
  25#define RTLLIB_H
  26#include <linux/if_ether.h> /* ETH_ALEN */
  27#include <linux/kernel.h>   /* ARRAY_SIZE */
  28#include <linux/module.h>
  29#include <linux/interrupt.h>
  30#include <linux/jiffies.h>
  31#include <linux/timer.h>
  32#include <linux/sched.h>
  33#include <linux/semaphore.h>
  34
  35#include <linux/delay.h>
  36#include <linux/wireless.h>
  37
  38#include "rtllib_debug.h"
  39#include "rtl819x_HT.h"
  40#include "rtl819x_BA.h"
  41#include "rtl819x_TS.h"
  42
  43#include <linux/netdevice.h>
  44#include <linux/if_arp.h> /* ARPHRD_ETHER */
  45#include <net/lib80211.h>
  46
  47#define MAX_PRECMD_CNT 16
  48#define MAX_RFDEPENDCMD_CNT 16
  49#define MAX_POSTCMD_CNT 16
  50
  51#ifndef WIRELESS_SPY
  52#define WIRELESS_SPY
  53#endif
  54#include <net/iw_handler.h>
  55
  56#ifndef IW_MODE_MONITOR
  57#define IW_MODE_MONITOR 6
  58#endif
  59
  60#ifndef IWEVCUSTOM
  61#define IWEVCUSTOM 0x8c02
  62#endif
  63
  64#ifndef IW_CUSTOM_MAX
  65/* Max number of char in custom event - use multiple of them if needed */
  66#define IW_CUSTOM_MAX   256     /* In bytes */
  67#endif
  68
  69#ifndef container_of
  70/**
  71 * container_of - cast a member of a structure out to the containing structure
  72 *
  73 * @ptr:        the pointer to the member.
  74 * @type:       the type of the container struct this is embedded in.
  75 * @member:     the name of the member within the struct.
  76 *
  77 */
  78#define container_of(ptr, type, member) ({                    \
  79        const typeof(((type *)0)->member)*__mptr = (ptr);    \
  80        (type *)((char *)__mptr - offsetof(type, member)); })
  81#endif
  82
  83#define skb_tail_pointer_rsl(skb) skb_tail_pointer(skb)
  84
  85#define EXPORT_SYMBOL_RSL(x) EXPORT_SYMBOL(x)
  86
  87
  88#define queue_delayed_work_rsl(x, y, z) queue_delayed_work(x, y, z)
  89#define INIT_DELAYED_WORK_RSL(x, y, z) INIT_DELAYED_WORK(x, y)
  90
  91#define queue_work_rsl(x, y) queue_work(x, y)
  92#define INIT_WORK_RSL(x, y, z) INIT_WORK(x, y)
  93
  94#define container_of_work_rsl(x, y, z) container_of(x, y, z)
  95#define container_of_dwork_rsl(x, y, z)                         \
  96        container_of(container_of(x, struct delayed_work, work), y, z)
  97
  98#define iwe_stream_add_event_rsl(info, start, stop, iwe, len)   \
  99        iwe_stream_add_event(info, start, stop, iwe, len)
 100
 101#define iwe_stream_add_point_rsl(info, start, stop, iwe, p)     \
 102        iwe_stream_add_point(info, start, stop, iwe, p)
 103
 104#define usb_alloc_urb_rsl(x, y) usb_alloc_urb(x, y)
 105#define usb_submit_urb_rsl(x, y) usb_submit_urb(x, y)
 106
 107static inline void *netdev_priv_rsl(struct net_device *dev)
 108{
 109        return netdev_priv(dev);
 110}
 111
 112#define KEY_TYPE_NA             0x0
 113#define KEY_TYPE_WEP40          0x1
 114#define KEY_TYPE_TKIP           0x2
 115#define KEY_TYPE_CCMP           0x4
 116#define KEY_TYPE_WEP104         0x5
 117/* added for rtl819x tx procedure */
 118#define MAX_QUEUE_SIZE          0x10
 119
 120#define BK_QUEUE                               0
 121#define BE_QUEUE                               1
 122#define VI_QUEUE                               2
 123#define VO_QUEUE                               3
 124#define HCCA_QUEUE                           4
 125#define TXCMD_QUEUE                         5
 126#define MGNT_QUEUE                           6
 127#define HIGH_QUEUE                           7
 128#define BEACON_QUEUE                       8
 129
 130#define LOW_QUEUE                             BE_QUEUE
 131#define NORMAL_QUEUE                       MGNT_QUEUE
 132
 133#ifndef IW_MODE_MESH
 134#define IW_MODE_MESH                    7
 135#endif
 136#define AMSDU_SUBHEADER_LEN 14
 137#define SWRF_TIMEOUT                            50
 138
 139#define IE_CISCO_FLAG_POSITION          0x08
 140#define SUPPORT_CKIP_MIC                        0x08
 141#define SUPPORT_CKIP_PK                 0x10
 142#define RT_RF_OFF_LEVL_ASPM                     BIT0
 143#define RT_RF_OFF_LEVL_CLK_REQ          BIT1
 144#define RT_RF_OFF_LEVL_PCI_D3                   BIT2
 145#define RT_RF_OFF_LEVL_HALT_NIC         BIT3
 146#define RT_RF_OFF_LEVL_FREE_FW          BIT4
 147#define RT_RF_OFF_LEVL_FW_32K           BIT5
 148#define RT_RF_PS_LEVEL_ALWAYS_ASPM      BIT6
 149#define RT_RF_LPS_DISALBE_2R                    BIT30
 150#define RT_RF_LPS_LEVEL_ASPM                    BIT31
 151#define RT_IN_PS_LEVEL(pPSC, _PS_FLAG)          \
 152        ((pPSC->CurPsLevel & _PS_FLAG) ? true : false)
 153#define RT_CLEAR_PS_LEVEL(pPSC, _PS_FLAG)       \
 154        (pPSC->CurPsLevel &= (~(_PS_FLAG)))
 155#define RT_SET_PS_LEVEL(pPSC, _PS_FLAG) (pPSC->CurPsLevel |= _PS_FLAG)
 156
 157/* defined for skb cb field */
 158/* At most 28 byte */
 159struct cb_desc {
 160        /* Tx Desc Related flags (8-9) */
 161        u8 bLastIniPkt:1;
 162        u8 bCmdOrInit:1;
 163        u8 bFirstSeg:1;
 164        u8 bLastSeg:1;
 165        u8 bEncrypt:1;
 166        u8 bTxDisableRateFallBack:1;
 167        u8 bTxUseDriverAssingedRate:1;
 168        u8 bHwSec:1;
 169
 170        u8 nStuckCount;
 171
 172        /* Tx Firmware Related flags (10-11)*/
 173        u8 bCTSEnable:1;
 174        u8 bRTSEnable:1;
 175        u8 bUseShortGI:1;
 176        u8 bUseShortPreamble:1;
 177        u8 bTxEnableFwCalcDur:1;
 178        u8 bAMPDUEnable:1;
 179        u8 bRTSSTBC:1;
 180        u8 RTSSC:1;
 181
 182        u8 bRTSBW:1;
 183        u8 bPacketBW:1;
 184        u8 bRTSUseShortPreamble:1;
 185        u8 bRTSUseShortGI:1;
 186        u8 bMulticast:1;
 187        u8 bBroadcast:1;
 188        u8 drv_agg_enable:1;
 189        u8 reserved2:1;
 190
 191        /* Tx Desc related element(12-19) */
 192        u8 rata_index;
 193        u8 queue_index;
 194        u16 txbuf_size;
 195        u8 RATRIndex;
 196        u8 bAMSDU:1;
 197        u8 bFromAggrQ:1;
 198        u8 reserved6:6;
 199        u8 macId;
 200        u8 priority;
 201
 202        /* Tx firmware related element(20-27) */
 203        u8 data_rate;
 204        u8 rts_rate;
 205        u8 ampdu_factor;
 206        u8 ampdu_density;
 207        u8 DrvAggrNum;
 208        u8 bdhcp;
 209        u16 pkt_size;
 210        u8 bIsSpecialDataFrame;
 211
 212        u8 bBTTxPacket;
 213        u8 bIsBTProbRsp;
 214};
 215
 216enum sw_chnl_cmd_id {
 217        CmdID_End,
 218        CmdID_SetTxPowerLevel,
 219        CmdID_BBRegWrite10,
 220        CmdID_WritePortUlong,
 221        CmdID_WritePortUshort,
 222        CmdID_WritePortUchar,
 223        CmdID_RF_WriteReg,
 224};
 225
 226struct sw_chnl_cmd {
 227        enum sw_chnl_cmd_id CmdID;
 228        u32                     Para1;
 229        u32                     Para2;
 230        u32                     msDelay;
 231} __packed;
 232
 233/*--------------------------Define -------------------------------------------*/
 234#define MGN_1M            0x02
 235#define MGN_2M            0x04
 236#define MGN_5_5M                0x0b
 237#define MGN_11M          0x16
 238
 239#define MGN_6M            0x0c
 240#define MGN_9M            0x12
 241#define MGN_12M          0x18
 242#define MGN_18M          0x24
 243#define MGN_24M          0x30
 244#define MGN_36M          0x48
 245#define MGN_48M          0x60
 246#define MGN_54M          0x6c
 247
 248#define MGN_MCS0                0x80
 249#define MGN_MCS1                0x81
 250#define MGN_MCS2                0x82
 251#define MGN_MCS3                0x83
 252#define MGN_MCS4                0x84
 253#define MGN_MCS5                0x85
 254#define MGN_MCS6                0x86
 255#define MGN_MCS7                0x87
 256#define MGN_MCS8                0x88
 257#define MGN_MCS9                0x89
 258#define MGN_MCS10              0x8a
 259#define MGN_MCS11              0x8b
 260#define MGN_MCS12              0x8c
 261#define MGN_MCS13              0x8d
 262#define MGN_MCS14              0x8e
 263#define MGN_MCS15              0x8f
 264#define MGN_MCS0_SG                     0x90
 265#define MGN_MCS1_SG                     0x91
 266#define MGN_MCS2_SG                     0x92
 267#define MGN_MCS3_SG                     0x93
 268#define MGN_MCS4_SG                     0x94
 269#define MGN_MCS5_SG                     0x95
 270#define MGN_MCS6_SG                     0x96
 271#define MGN_MCS7_SG                     0x97
 272#define MGN_MCS8_SG                     0x98
 273#define MGN_MCS9_SG                     0x99
 274#define MGN_MCS10_SG            0x9a
 275#define MGN_MCS11_SG            0x9b
 276#define MGN_MCS12_SG            0x9c
 277#define MGN_MCS13_SG            0x9d
 278#define MGN_MCS14_SG            0x9e
 279#define MGN_MCS15_SG            0x9f
 280
 281
 282enum    _ReasonCode {
 283        unspec_reason   = 0x1,
 284        auth_not_valid  = 0x2,
 285        deauth_lv_ss    = 0x3,
 286        inactivity              = 0x4,
 287        ap_overload     = 0x5,
 288        class2_err              = 0x6,
 289        class3_err              = 0x7,
 290        disas_lv_ss     = 0x8,
 291        asoc_not_auth   = 0x9,
 292
 293        mic_failure     = 0xe,
 294
 295        invalid_IE              = 0x0d,
 296        four_way_tmout  = 0x0f,
 297        two_way_tmout   = 0x10,
 298        IE_dismatch     = 0x11,
 299        invalid_Gcipher = 0x12,
 300        invalid_Pcipher = 0x13,
 301        invalid_AKMP    = 0x14,
 302        unsup_RSNIEver = 0x15,
 303        invalid_RSNIE   = 0x16,
 304        auth_802_1x_fail = 0x17,
 305        ciper_reject            = 0x18,
 306
 307        QoS_unspec              = 0x20,
 308        QAP_bandwidth   = 0x21,
 309        poor_condition  = 0x22,
 310        no_facility     = 0x23,
 311        req_declined    = 0x25,
 312        invalid_param   = 0x26,
 313        req_not_honored = 0x27,
 314        TS_not_created  = 0x2F,
 315        DL_not_allowed  = 0x30,
 316        dest_not_exist  = 0x31,
 317        dest_not_QSTA   = 0x32,
 318};
 319
 320enum hal_def_variable {
 321        HAL_DEF_TPC_ENABLE,
 322        HAL_DEF_INIT_GAIN,
 323        HAL_DEF_PROT_IMP_MODE,
 324        HAL_DEF_HIGH_POWER_MECHANISM,
 325        HAL_DEF_RATE_ADAPTIVE_MECHANISM,
 326        HAL_DEF_ANTENNA_DIVERSITY_MECHANISM,
 327        HAL_DEF_LED,
 328        HAL_DEF_CW_MAX_MIN,
 329
 330        HAL_DEF_WOWLAN,
 331        HAL_DEF_ENDPOINTS,
 332        HAL_DEF_MIN_TX_POWER_DBM,
 333        HAL_DEF_MAX_TX_POWER_DBM,
 334        HW_DEF_EFUSE_REPG_SECTION1_FLAG,
 335        HW_DEF_EFUSE_REPG_DATA,
 336        HW_DEF_GPIO,
 337        HAL_DEF_PCI_SUPPORT_ASPM,
 338        HAL_DEF_THERMAL_VALUE,
 339        HAL_DEF_USB_IN_TOKEN_REV,
 340};
 341
 342enum hw_variables {
 343        HW_VAR_ETHER_ADDR,
 344        HW_VAR_MULTICAST_REG,
 345        HW_VAR_BASIC_RATE,
 346        HW_VAR_BSSID,
 347        HW_VAR_MEDIA_STATUS,
 348        HW_VAR_SECURITY_CONF,
 349        HW_VAR_BEACON_INTERVAL,
 350        HW_VAR_ATIM_WINDOW,
 351        HW_VAR_LISTEN_INTERVAL,
 352        HW_VAR_CS_COUNTER,
 353        HW_VAR_DEFAULTKEY0,
 354        HW_VAR_DEFAULTKEY1,
 355        HW_VAR_DEFAULTKEY2,
 356        HW_VAR_DEFAULTKEY3,
 357        HW_VAR_SIFS,
 358        HW_VAR_DIFS,
 359        HW_VAR_EIFS,
 360        HW_VAR_SLOT_TIME,
 361        HW_VAR_ACK_PREAMBLE,
 362        HW_VAR_CW_CONFIG,
 363        HW_VAR_CW_VALUES,
 364        HW_VAR_RATE_FALLBACK_CONTROL,
 365        HW_VAR_CONTENTION_WINDOW,
 366        HW_VAR_RETRY_COUNT,
 367        HW_VAR_TR_SWITCH,
 368        HW_VAR_COMMAND,
 369        HW_VAR_WPA_CONFIG,
 370        HW_VAR_AMPDU_MIN_SPACE,
 371        HW_VAR_SHORTGI_DENSITY,
 372        HW_VAR_AMPDU_FACTOR,
 373        HW_VAR_MCS_RATE_AVAILABLE,
 374        HW_VAR_AC_PARAM,
 375        HW_VAR_ACM_CTRL,
 376        HW_VAR_DIS_Req_Qsize,
 377        HW_VAR_CCX_CHNL_LOAD,
 378        HW_VAR_CCX_NOISE_HISTOGRAM,
 379        HW_VAR_CCX_CLM_NHM,
 380        HW_VAR_TxOPLimit,
 381        HW_VAR_TURBO_MODE,
 382        HW_VAR_RF_STATE,
 383        HW_VAR_RF_OFF_BY_HW,
 384        HW_VAR_BUS_SPEED,
 385        HW_VAR_SET_DEV_POWER,
 386
 387        HW_VAR_RCR,
 388        HW_VAR_RATR_0,
 389        HW_VAR_RRSR,
 390        HW_VAR_CPU_RST,
 391        HW_VAR_CECHK_BSSID,
 392        HW_VAR_LBK_MODE,
 393        HW_VAR_AES_11N_FIX,
 394        HW_VAR_USB_RX_AGGR,
 395        HW_VAR_USER_CONTROL_TURBO_MODE,
 396        HW_VAR_RETRY_LIMIT,
 397        HW_VAR_INIT_TX_RATE,
 398        HW_VAR_TX_RATE_REG,
 399        HW_VAR_EFUSE_USAGE,
 400        HW_VAR_EFUSE_BYTES,
 401        HW_VAR_AUTOLOAD_STATUS,
 402        HW_VAR_RF_2R_DISABLE,
 403        HW_VAR_SET_RPWM,
 404        HW_VAR_H2C_FW_PWRMODE,
 405        HW_VAR_H2C_FW_JOINBSSRPT,
 406        HW_VAR_1X1_RECV_COMBINE,
 407        HW_VAR_STOP_SEND_BEACON,
 408        HW_VAR_TSF_TIMER,
 409        HW_VAR_IO_CMD,
 410
 411        HW_VAR_RF_RECOVERY,
 412        HW_VAR_H2C_FW_UPDATE_GTK,
 413        HW_VAR_WF_MASK,
 414        HW_VAR_WF_CRC,
 415        HW_VAR_WF_IS_MAC_ADDR,
 416        HW_VAR_H2C_FW_OFFLOAD,
 417        HW_VAR_RESET_WFCRC,
 418
 419        HW_VAR_HANDLE_FW_C2H,
 420        HW_VAR_DL_FW_RSVD_PAGE,
 421        HW_VAR_AID,
 422        HW_VAR_HW_SEQ_ENABLE,
 423        HW_VAR_CORRECT_TSF,
 424        HW_VAR_BCN_VALID,
 425        HW_VAR_FWLPS_RF_ON,
 426        HW_VAR_DUAL_TSF_RST,
 427        HW_VAR_SWITCH_EPHY_WoWLAN,
 428        HW_VAR_INT_MIGRATION,
 429        HW_VAR_INT_AC,
 430        HW_VAR_RF_TIMING,
 431};
 432
 433enum rt_op_mode {
 434        RT_OP_MODE_AP,
 435        RT_OP_MODE_INFRASTRUCTURE,
 436        RT_OP_MODE_IBSS,
 437        RT_OP_MODE_NO_LINK,
 438};
 439
 440
 441#define aSifsTime                                               \
 442         (((priv->rtllib->current_network.mode == IEEE_A)       \
 443        || (priv->rtllib->current_network.mode == IEEE_N_24G)   \
 444        || (priv->rtllib->current_network.mode == IEEE_N_5G)) ? 16 : 10)
 445
 446#define MGMT_QUEUE_NUM 5
 447
 448#define IEEE_CMD_SET_WPA_PARAM                  1
 449#define IEEE_CMD_SET_WPA_IE                     2
 450#define IEEE_CMD_SET_ENCRYPTION                 3
 451#define IEEE_CMD_MLME                           4
 452
 453#define IEEE_PARAM_WPA_ENABLED                  1
 454#define IEEE_PARAM_TKIP_COUNTERMEASURES         2
 455#define IEEE_PARAM_DROP_UNENCRYPTED             3
 456#define IEEE_PARAM_PRIVACY_INVOKED              4
 457#define IEEE_PARAM_AUTH_ALGS                    5
 458#define IEEE_PARAM_IEEE_802_1X                  6
 459#define IEEE_PARAM_WPAX_SELECT                  7
 460#define IEEE_PROTO_WPA                          1
 461#define IEEE_PROTO_RSN                          2
 462#define IEEE_WPAX_USEGROUP                      0
 463#define IEEE_WPAX_WEP40                         1
 464#define IEEE_WPAX_TKIP                          2
 465#define IEEE_WPAX_WRAP                          3
 466#define IEEE_WPAX_CCMP                          4
 467#define IEEE_WPAX_WEP104                        5
 468
 469#define IEEE_KEY_MGMT_IEEE8021X                 1
 470#define IEEE_KEY_MGMT_PSK                       2
 471
 472#define IEEE_MLME_STA_DEAUTH                    1
 473#define IEEE_MLME_STA_DISASSOC                  2
 474
 475
 476#define IEEE_CRYPT_ERR_UNKNOWN_ALG              2
 477#define IEEE_CRYPT_ERR_UNKNOWN_ADDR             3
 478#define IEEE_CRYPT_ERR_CRYPT_INIT_FAILED        4
 479#define IEEE_CRYPT_ERR_KEY_SET_FAILED           5
 480#define IEEE_CRYPT_ERR_TX_KEY_SET_FAILED        6
 481#define IEEE_CRYPT_ERR_CARD_CONF_FAILED         7
 482#define IEEE_CRYPT_ALG_NAME_LEN                 16
 483
 484#define MAX_IE_LEN  0xff
 485#define RT_ASSERT_RET(_Exp) do {} while (0)
 486#define RT_ASSERT_RET_VALUE(_Exp, Ret)          \
 487        do {} while (0)
 488
 489struct ieee_param {
 490        u32 cmd;
 491        u8 sta_addr[ETH_ALEN];
 492        union {
 493                struct {
 494                        u8 name;
 495                        u32 value;
 496                } wpa_param;
 497                struct {
 498                        u32 len;
 499                        u8 reserved[32];
 500                        u8 data[0];
 501                } wpa_ie;
 502                struct {
 503                        int command;
 504                        int reason_code;
 505                } mlme;
 506                struct {
 507                        u8 alg[IEEE_CRYPT_ALG_NAME_LEN];
 508                        u8 set_tx;
 509                        u32 err;
 510                        u8 idx;
 511                        u8 seq[8]; /* sequence counter (set: RX, get: TX) */
 512                        u16 key_len;
 513                        u8 key[0];
 514                } crypt;
 515        } u;
 516};
 517
 518
 519#if WIRELESS_EXT < 17
 520#define IW_QUAL_QUAL_INVALID   0x10
 521#define IW_QUAL_LEVEL_INVALID  0x20
 522#define IW_QUAL_NOISE_INVALID  0x40
 523#define IW_QUAL_QUAL_UPDATED   0x1
 524#define IW_QUAL_LEVEL_UPDATED  0x2
 525#define IW_QUAL_NOISE_UPDATED  0x4
 526#endif
 527
 528#define MSECS(t) msecs_to_jiffies(t)
 529#define msleep_interruptible_rsl  msleep_interruptible
 530
 531#define RTLLIB_DATA_LEN         2304
 532/* Maximum size for the MA-UNITDATA primitive, 802.11 standard section
 533   6.2.1.1.2.
 534
 535   The figure in section 7.1.2 suggests a body size of up to 2312
 536   bytes is allowed, which is a bit confusing, I suspect this
 537   represents the 2304 bytes of real data, plus a possible 8 bytes of
 538   WEP IV and ICV. (this interpretation suggested by Ramiro Barreiro) */
 539#define RTLLIB_1ADDR_LEN 10
 540#define RTLLIB_2ADDR_LEN 16
 541#define RTLLIB_3ADDR_LEN 24
 542#define RTLLIB_4ADDR_LEN 30
 543#define RTLLIB_FCS_LEN    4
 544#define RTLLIB_HLEN               (RTLLIB_4ADDR_LEN)
 545#define RTLLIB_FRAME_LEN             (RTLLIB_DATA_LEN + RTLLIB_HLEN)
 546#define RTLLIB_MGMT_HDR_LEN 24
 547#define RTLLIB_DATA_HDR3_LEN 24
 548#define RTLLIB_DATA_HDR4_LEN 30
 549
 550#define RTLLIB_SKBBUFFER_SIZE 2500
 551
 552#define MIN_FRAG_THRESHOLD     256U
 553#define MAX_FRAG_THRESHOLD     2346U
 554#define MAX_HT_DATA_FRAG_THRESHOLD 0x2000
 555
 556#define HT_AMSDU_SIZE_4K 3839
 557#define HT_AMSDU_SIZE_8K 7935
 558
 559/* Frame control field constants */
 560#define RTLLIB_FCTL_VERS                0x0003
 561#define RTLLIB_FCTL_FTYPE               0x000c
 562#define RTLLIB_FCTL_STYPE               0x00f0
 563#define RTLLIB_FCTL_FRAMETYPE   0x00fc
 564#define RTLLIB_FCTL_TODS                0x0100
 565#define RTLLIB_FCTL_FROMDS              0x0200
 566#define RTLLIB_FCTL_DSTODS              0x0300
 567#define RTLLIB_FCTL_MOREFRAGS   0x0400
 568#define RTLLIB_FCTL_RETRY               0x0800
 569#define RTLLIB_FCTL_PM          0x1000
 570#define RTLLIB_FCTL_MOREDATA            0x2000
 571#define RTLLIB_FCTL_WEP         0x4000
 572#define RTLLIB_FCTL_ORDER               0x8000
 573
 574#define RTLLIB_FTYPE_MGMT               0x0000
 575#define RTLLIB_FTYPE_CTL                0x0004
 576#define RTLLIB_FTYPE_DATA               0x0008
 577
 578/* management */
 579#define RTLLIB_STYPE_ASSOC_REQ  0x0000
 580#define RTLLIB_STYPE_ASSOC_RESP         0x0010
 581#define RTLLIB_STYPE_REASSOC_REQ        0x0020
 582#define RTLLIB_STYPE_REASSOC_RESP       0x0030
 583#define RTLLIB_STYPE_PROBE_REQ  0x0040
 584#define RTLLIB_STYPE_PROBE_RESP 0x0050
 585#define RTLLIB_STYPE_BEACON             0x0080
 586#define RTLLIB_STYPE_ATIM               0x0090
 587#define RTLLIB_STYPE_DISASSOC   0x00A0
 588#define RTLLIB_STYPE_AUTH               0x00B0
 589#define RTLLIB_STYPE_DEAUTH             0x00C0
 590#define RTLLIB_STYPE_MANAGE_ACT 0x00D0
 591
 592/* control */
 593#define RTLLIB_STYPE_PSPOLL             0x00A0
 594#define RTLLIB_STYPE_RTS                0x00B0
 595#define RTLLIB_STYPE_CTS                0x00C0
 596#define RTLLIB_STYPE_ACK                0x00D0
 597#define RTLLIB_STYPE_CFEND              0x00E0
 598#define RTLLIB_STYPE_CFENDACK   0x00F0
 599#define RTLLIB_STYPE_BLOCKACK   0x0094
 600
 601/* data */
 602#define RTLLIB_STYPE_DATA               0x0000
 603#define RTLLIB_STYPE_DATA_CFACK 0x0010
 604#define RTLLIB_STYPE_DATA_CFPOLL        0x0020
 605#define RTLLIB_STYPE_DATA_CFACKPOLL     0x0030
 606#define RTLLIB_STYPE_NULLFUNC   0x0040
 607#define RTLLIB_STYPE_CFACK              0x0050
 608#define RTLLIB_STYPE_CFPOLL             0x0060
 609#define RTLLIB_STYPE_CFACKPOLL  0x0070
 610#define RTLLIB_STYPE_QOS_DATA   0x0080
 611#define RTLLIB_STYPE_QOS_NULL   0x00C0
 612
 613#define RTLLIB_SCTL_FRAG                0x000F
 614#define RTLLIB_SCTL_SEQ         0xFFF0
 615
 616/* QOS control */
 617#define RTLLIB_QCTL_TID       0x000F
 618
 619#define FC_QOS_BIT                                      BIT7
 620#define IsDataFrame(pdu)        (((pdu[0] & 0x0C) == 0x08) ? true : false)
 621#define IsLegacyDataFrame(pdu)  (IsDataFrame(pdu) && (!(pdu[0]&FC_QOS_BIT)))
 622#define IsQoSDataFrame(pframe)                  \
 623        ((*(u16 *)pframe&(RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) ==  \
 624        (RTLLIB_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA))
 625#define Frame_Order(pframe)     (*(u16 *)pframe&RTLLIB_FCTL_ORDER)
 626#define SN_LESS(a, b)           (((a-b)&0x800) != 0)
 627#define SN_EQUAL(a, b)  (a == b)
 628#define MAX_DEV_ADDR_SIZE 8
 629
 630enum act_category {
 631        ACT_CAT_QOS = 1,
 632        ACT_CAT_DLS = 2,
 633        ACT_CAT_BA  = 3,
 634        ACT_CAT_HT  = 7,
 635        ACT_CAT_WMM = 17,
 636};
 637
 638enum ts_action {
 639        ACT_ADDTSREQ = 0,
 640        ACT_ADDTSRSP = 1,
 641        ACT_DELTS    = 2,
 642        ACT_SCHEDULE = 3,
 643};
 644
 645enum ba_action {
 646        ACT_ADDBAREQ = 0,
 647        ACT_ADDBARSP = 1,
 648        ACT_DELBA    = 2,
 649};
 650
 651enum init_gain_op_type {
 652        IG_Backup = 0,
 653        IG_Restore,
 654        IG_Max
 655};
 656
 657enum led_ctl_mode {
 658        LED_CTL_POWER_ON = 1,
 659        LED_CTL_LINK = 2,
 660        LED_CTL_NO_LINK = 3,
 661        LED_CTL_TX = 4,
 662        LED_CTL_RX = 5,
 663        LED_CTL_SITE_SURVEY = 6,
 664        LED_CTL_POWER_OFF = 7,
 665        LED_CTL_START_TO_LINK = 8,
 666        LED_CTL_START_WPS = 9,
 667        LED_CTL_STOP_WPS = 10,
 668        LED_CTL_START_WPS_BOTTON = 11,
 669        LED_CTL_STOP_WPS_FAIL = 12,
 670         LED_CTL_STOP_WPS_FAIL_OVERLAP = 13,
 671};
 672
 673enum rt_rf_type_def {
 674        RF_1T2R = 0,
 675        RF_2T4R,
 676        RF_2T2R,
 677        RF_1T1R,
 678        RF_2T2R_GREEN,
 679        RF_819X_MAX_TYPE
 680};
 681
 682enum wireless_mode {
 683        WIRELESS_MODE_UNKNOWN = 0x00,
 684        WIRELESS_MODE_A = 0x01,
 685        WIRELESS_MODE_B = 0x02,
 686        WIRELESS_MODE_G = 0x04,
 687        WIRELESS_MODE_AUTO = 0x08,
 688        WIRELESS_MODE_N_24G = 0x10,
 689        WIRELESS_MODE_N_5G = 0x20
 690};
 691
 692enum wireless_network_type {
 693        WIRELESS_11B = 1,
 694        WIRELESS_11G = 2,
 695        WIRELESS_11A = 4,
 696        WIRELESS_11N = 8
 697};
 698
 699#define OUI_SUBTYPE_WMM_INFO            0
 700#define OUI_SUBTYPE_WMM_PARAM   1
 701#define OUI_SUBTYPE_QOS_CAPABI  5
 702
 703/* debug macros */
 704extern u32 rtllib_debug_level;
 705#define RTLLIB_DEBUG(level, fmt, args...) \
 706do {                                                            \
 707        if (rtllib_debug_level & (level))                       \
 708                printk(KERN_DEBUG "rtllib: " fmt, ## args);     \
 709} while (0)
 710
 711#define RTLLIB_DEBUG_DATA(level, data, datalen) \
 712        do {                                                    \
 713                if ((rtllib_debug_level & (level)) == (level)) {        \
 714                        int i;                                  \
 715                        u8 *pdata = (u8 *)data;                 \
 716                        printk(KERN_DEBUG "rtllib: %s()\n", __func__);  \
 717                        for (i = 0; i < (int)(datalen); i++)    {       \
 718                                printk("%2.2x ", pdata[i]);             \
 719                                if ((i+1)%16 == 0)                      \
 720                                        printk("\n");   \
 721                        }                               \
 722                        printk("\n");                   \
 723                }                                       \
 724        } while (0)
 725
 726/*
 727 * To use the debug system;
 728 *
 729 * If you are defining a new debug classification, simply add it to the #define
 730 * list here in the form of:
 731 *
 732 * #define RTLLIB_DL_xxxx VALUE
 733 *
 734 * shifting value to the left one bit from the previous entry.  xxxx should be
 735 * the name of the classification (for example, WEP)
 736 *
 737 * You then need to either add a RTLLIB_xxxx_DEBUG() macro definition for your
 738 * classification, or use RTLLIB_DEBUG(RTLLIB_DL_xxxx, ...) whenever you want
 739 * to send output to that classification.
 740 *
 741 * To add your debug level to the list of levels seen when you perform
 742 *
 743 * % cat /proc/net/ipw/debug_level
 744 *
 745 * you simply need to add your entry to the ipw_debug_levels array.
 746 *
 747 *
 748 */
 749
 750#define RTLLIB_DL_INFO    (1<<0)
 751#define RTLLIB_DL_WX        (1<<1)
 752#define RTLLIB_DL_SCAN    (1<<2)
 753#define RTLLIB_DL_STATE  (1<<3)
 754#define RTLLIB_DL_MGMT    (1<<4)
 755#define RTLLIB_DL_FRAG    (1<<5)
 756#define RTLLIB_DL_EAP      (1<<6)
 757#define RTLLIB_DL_DROP    (1<<7)
 758
 759#define RTLLIB_DL_TX        (1<<8)
 760#define RTLLIB_DL_RX        (1<<9)
 761
 762#define RTLLIB_DL_HT               (1<<10)
 763#define RTLLIB_DL_BA               (1<<11)
 764#define RTLLIB_DL_TS               (1<<12)
 765#define RTLLIB_DL_QOS      (1<<13)
 766#define RTLLIB_DL_REORDER          (1<<14)
 767#define RTLLIB_DL_IOT      (1<<15)
 768#define RTLLIB_DL_IPS      (1<<16)
 769#define RTLLIB_DL_TRACE    (1<<29)
 770#define RTLLIB_DL_DATA     (1<<30)
 771#define RTLLIB_DL_ERR      (1<<31)
 772#define RTLLIB_ERROR(f, a...) printk(KERN_ERR "rtllib: " f, ## a)
 773#define RTLLIB_WARNING(f, a...) printk(KERN_WARNING "rtllib: " f, ## a)
 774#define RTLLIB_DEBUG_INFO(f, a...)   RTLLIB_DEBUG(RTLLIB_DL_INFO, f, ## a)
 775
 776#define RTLLIB_DEBUG_WX(f, a...)     RTLLIB_DEBUG(RTLLIB_DL_WX, f, ## a)
 777#define RTLLIB_DEBUG_SCAN(f, a...)   RTLLIB_DEBUG(RTLLIB_DL_SCAN, f, ## a)
 778#define RTLLIB_DEBUG_STATE(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_STATE, f, ## a)
 779#define RTLLIB_DEBUG_MGMT(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_MGMT, f, ## a)
 780#define RTLLIB_DEBUG_FRAG(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_FRAG, f, ## a)
 781#define RTLLIB_DEBUG_EAP(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_EAP, f, ## a)
 782#define RTLLIB_DEBUG_DROP(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_DROP, f, ## a)
 783#define RTLLIB_DEBUG_TX(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_TX, f, ## a)
 784#define RTLLIB_DEBUG_RX(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_RX, f, ## a)
 785#define RTLLIB_DEBUG_QOS(f, a...)  RTLLIB_DEBUG(RTLLIB_DL_QOS, f, ## a)
 786
 787/* Added by Annie, 2005-11-22. */
 788#define MAX_STR_LEN     64
 789/* I want to see ASCII 33 to 126 only. Otherwise, I print '?'. */
 790#define PRINTABLE(_ch)  (_ch > '!' && _ch < '~')
 791#define RTLLIB_PRINT_STR(_Comp, _TitleString, _Ptr, _Len)               \
 792        if ((_Comp) & level) {                                         \
 793                int          __i;                                   \
 794                u8  struct buffer[MAX_STR_LEN];                         \
 795                int length = (_Len < MAX_STR_LEN) ? _Len : (MAX_STR_LEN-1) ;\
 796                memset(struct buffer, 0, MAX_STR_LEN);          \
 797                memcpy(struct buffer, (u8 *)_Ptr, length);              \
 798                for (__i = 0; __i < MAX_STR_LEN; __i++) {               \
 799                        if (!PRINTABLE(struct buffer[__i]))             \
 800                                struct buffer[__i] = '?';               \
 801                }                                                       \
 802                struct buffer[length] = '\0';                           \
 803                printk(KERN_INFO "Rtl819x: ");                          \
 804                printk(_TitleString);                                   \
 805                printk(": %d, <%s>\n", _Len, struct buffer);            \
 806        }
 807#ifndef ETH_P_PAE
 808#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
 809#define ETH_P_IP        0x0800          /* Internet Protocol packet     */
 810#define ETH_P_ARP       0x0806          /* Address Resolution packet    */
 811#endif /* ETH_P_PAE */
 812
 813#define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
 814
 815#ifndef ETH_P_80211_RAW
 816#define ETH_P_80211_RAW (ETH_P_ECONET + 1)
 817#endif
 818
 819/* IEEE 802.11 defines */
 820
 821#define P80211_OUI_LEN 3
 822
 823struct rtllib_snap_hdr {
 824
 825        u8    dsap;   /* always 0xAA */
 826        u8    ssap;   /* always 0xAA */
 827        u8    ctrl;   /* always 0x03 */
 828        u8    oui[P80211_OUI_LEN];    /* organizational universal id */
 829
 830} __packed;
 831
 832enum _REG_PREAMBLE_MODE {
 833        PREAMBLE_LONG = 1,
 834        PREAMBLE_AUTO = 2,
 835        PREAMBLE_SHORT = 3,
 836};
 837
 838#define SNAP_SIZE sizeof(struct rtllib_snap_hdr)
 839
 840#define WLAN_FC_GET_VERS(fc) ((fc) & RTLLIB_FCTL_VERS)
 841#define WLAN_FC_GET_TYPE(fc) ((fc) & RTLLIB_FCTL_FTYPE)
 842#define WLAN_FC_GET_STYPE(fc) ((fc) & RTLLIB_FCTL_STYPE)
 843#define WLAN_FC_MORE_DATA(fc) ((fc) & RTLLIB_FCTL_MOREDATA)
 844
 845#define WLAN_FC_GET_FRAMETYPE(fc) ((fc) & RTLLIB_FCTL_FRAMETYPE)
 846#define WLAN_GET_SEQ_FRAG(seq) ((seq) & RTLLIB_SCTL_FRAG)
 847#define WLAN_GET_SEQ_SEQ(seq)  (((seq) & RTLLIB_SCTL_SEQ) >> 4)
 848
 849/* Authentication algorithms */
 850#define WLAN_AUTH_OPEN 0
 851#define WLAN_AUTH_SHARED_KEY 1
 852#define WLAN_AUTH_LEAP 128
 853
 854#define WLAN_AUTH_CHALLENGE_LEN 128
 855
 856#define WLAN_CAPABILITY_ESS (1<<0)
 857#define WLAN_CAPABILITY_IBSS (1<<1)
 858#define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
 859#define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
 860#define WLAN_CAPABILITY_PRIVACY (1<<4)
 861#define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
 862#define WLAN_CAPABILITY_PBCC (1<<6)
 863#define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
 864#define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
 865#define WLAN_CAPABILITY_QOS (1<<9)
 866#define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
 867#define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
 868
 869/* 802.11g ERP information element */
 870#define WLAN_ERP_NON_ERP_PRESENT (1<<0)
 871#define WLAN_ERP_USE_PROTECTION (1<<1)
 872#define WLAN_ERP_BARKER_PREAMBLE (1<<2)
 873
 874#define RTLLIB_STATMASK_SIGNAL (1<<0)
 875#define RTLLIB_STATMASK_RSSI (1<<1)
 876#define RTLLIB_STATMASK_NOISE (1<<2)
 877#define RTLLIB_STATMASK_RATE (1<<3)
 878#define RTLLIB_STATMASK_WEMASK 0x7
 879
 880#define RTLLIB_CCK_MODULATION    (1<<0)
 881#define RTLLIB_OFDM_MODULATION   (1<<1)
 882
 883#define RTLLIB_24GHZ_BAND     (1<<0)
 884#define RTLLIB_52GHZ_BAND     (1<<1)
 885
 886#define RTLLIB_CCK_RATE_LEN             4
 887#define RTLLIB_CCK_RATE_1MB                     0x02
 888#define RTLLIB_CCK_RATE_2MB                     0x04
 889#define RTLLIB_CCK_RATE_5MB                     0x0B
 890#define RTLLIB_CCK_RATE_11MB                    0x16
 891#define RTLLIB_OFDM_RATE_LEN            8
 892#define RTLLIB_OFDM_RATE_6MB                    0x0C
 893#define RTLLIB_OFDM_RATE_9MB                    0x12
 894#define RTLLIB_OFDM_RATE_12MB           0x18
 895#define RTLLIB_OFDM_RATE_18MB           0x24
 896#define RTLLIB_OFDM_RATE_24MB           0x30
 897#define RTLLIB_OFDM_RATE_36MB           0x48
 898#define RTLLIB_OFDM_RATE_48MB           0x60
 899#define RTLLIB_OFDM_RATE_54MB           0x6C
 900#define RTLLIB_BASIC_RATE_MASK          0x80
 901
 902#define RTLLIB_CCK_RATE_1MB_MASK                (1<<0)
 903#define RTLLIB_CCK_RATE_2MB_MASK                (1<<1)
 904#define RTLLIB_CCK_RATE_5MB_MASK                (1<<2)
 905#define RTLLIB_CCK_RATE_11MB_MASK               (1<<3)
 906#define RTLLIB_OFDM_RATE_6MB_MASK               (1<<4)
 907#define RTLLIB_OFDM_RATE_9MB_MASK               (1<<5)
 908#define RTLLIB_OFDM_RATE_12MB_MASK              (1<<6)
 909#define RTLLIB_OFDM_RATE_18MB_MASK              (1<<7)
 910#define RTLLIB_OFDM_RATE_24MB_MASK              (1<<8)
 911#define RTLLIB_OFDM_RATE_36MB_MASK              (1<<9)
 912#define RTLLIB_OFDM_RATE_48MB_MASK              (1<<10)
 913#define RTLLIB_OFDM_RATE_54MB_MASK              (1<<11)
 914
 915#define RTLLIB_CCK_RATES_MASK           0x0000000F
 916#define RTLLIB_CCK_BASIC_RATES_MASK     (RTLLIB_CCK_RATE_1MB_MASK | \
 917        RTLLIB_CCK_RATE_2MB_MASK)
 918#define RTLLIB_CCK_DEFAULT_RATES_MASK   (RTLLIB_CCK_BASIC_RATES_MASK | \
 919        RTLLIB_CCK_RATE_5MB_MASK | \
 920        RTLLIB_CCK_RATE_11MB_MASK)
 921
 922#define RTLLIB_OFDM_RATES_MASK          0x00000FF0
 923#define RTLLIB_OFDM_BASIC_RATES_MASK    (RTLLIB_OFDM_RATE_6MB_MASK | \
 924        RTLLIB_OFDM_RATE_12MB_MASK | \
 925        RTLLIB_OFDM_RATE_24MB_MASK)
 926#define RTLLIB_OFDM_DEFAULT_RATES_MASK  (RTLLIB_OFDM_BASIC_RATES_MASK | \
 927        RTLLIB_OFDM_RATE_9MB_MASK  | \
 928        RTLLIB_OFDM_RATE_18MB_MASK | \
 929        RTLLIB_OFDM_RATE_36MB_MASK | \
 930        RTLLIB_OFDM_RATE_48MB_MASK | \
 931        RTLLIB_OFDM_RATE_54MB_MASK)
 932#define RTLLIB_DEFAULT_RATES_MASK (RTLLIB_OFDM_DEFAULT_RATES_MASK | \
 933                                RTLLIB_CCK_DEFAULT_RATES_MASK)
 934
 935#define RTLLIB_NUM_OFDM_RATES       8
 936#define RTLLIB_NUM_CCK_RATES                4
 937#define RTLLIB_OFDM_SHIFT_MASK_A         4
 938
 939
 940/* this is stolen and modified from the madwifi driver*/
 941#define RTLLIB_FC0_TYPE_MASK            0x0c
 942#define RTLLIB_FC0_TYPE_DATA            0x08
 943#define RTLLIB_FC0_SUBTYPE_MASK 0xB0
 944#define RTLLIB_FC0_SUBTYPE_QOS  0x80
 945
 946#define RTLLIB_QOS_HAS_SEQ(fc) \
 947        (((fc) & (RTLLIB_FC0_TYPE_MASK | RTLLIB_FC0_SUBTYPE_MASK)) == \
 948         (RTLLIB_FC0_TYPE_DATA | RTLLIB_FC0_SUBTYPE_QOS))
 949
 950/* this is stolen from ipw2200 driver */
 951#define IEEE_IBSS_MAC_HASH_SIZE 31
 952struct ieee_ibss_seq {
 953        u8 mac[ETH_ALEN];
 954        u16 seq_num[17];
 955        u16 frag_num[17];
 956        unsigned long packet_time[17];
 957        struct list_head list;
 958};
 959
 960/* NOTE: This data is for statistical purposes; not all hardware provides this
 961 *       information for frames received.  Not setting these will not cause
 962 *       any adverse affects. */
 963struct rtllib_rx_stats {
 964        u64 mac_time;
 965        s8  rssi;
 966        u8  signal;
 967        u8  noise;
 968        u16 rate; /* in 100 kbps */
 969        u8  received_channel;
 970        u8  control;
 971        u8  mask;
 972        u8  freq;
 973        u16 len;
 974        u64 tsf;
 975        u32 beacon_time;
 976        u8  nic_type;
 977        u16 Length;
 978        u8  SignalQuality;
 979        s32 RecvSignalPower;
 980        s8  RxPower;
 981        u8  SignalStrength;
 982        u16 bHwError:1;
 983        u16 bCRC:1;
 984        u16 bICV:1;
 985        u16 bShortPreamble:1;
 986        u16 Antenna:1;
 987        u16 Decrypted:1;
 988        u16 Wakeup:1;
 989        u16 Reserved0:1;
 990        u8  AGC;
 991        u32 TimeStampLow;
 992        u32 TimeStampHigh;
 993        bool bShift;
 994        bool bIsQosData;
 995        u8   UserPriority;
 996
 997        u8    RxDrvInfoSize;
 998        u8    RxBufShift;
 999        bool  bIsAMPDU;
1000        bool  bFirstMPDU;
1001        bool  bContainHTC;
1002        bool  RxIs40MHzPacket;
1003        u32   RxPWDBAll;
1004        u8    RxMIMOSignalStrength[4];
1005        s8    RxMIMOSignalQuality[2];
1006        bool  bPacketMatchBSSID;
1007        bool  bIsCCK;
1008        bool  bPacketToSelf;
1009        u8 *virtual_address;
1010        u16    packetlength;
1011        u16    fraglength;
1012        u16    fragoffset;
1013        u16    ntotalfrag;
1014        bool   bisrxaggrsubframe;
1015        bool   bPacketBeacon;
1016        bool   bToSelfBA;
1017        char   cck_adc_pwdb[4];
1018        u16    Seq_Num;
1019        u8     nTotalAggPkt;
1020};
1021
1022/* IEEE 802.11 requires that STA supports concurrent reception of at least
1023 * three fragmented frames. This define can be increased to support more
1024 * concurrent frames, but it should be noted that each entry can consume about
1025 * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
1026#define RTLLIB_FRAG_CACHE_LEN 4
1027
1028struct rtllib_frag_entry {
1029        unsigned long first_frag_time;
1030        unsigned int seq;
1031        unsigned int last_frag;
1032        struct sk_buff *skb;
1033        u8 src_addr[ETH_ALEN];
1034        u8 dst_addr[ETH_ALEN];
1035};
1036
1037struct rtllib_stats {
1038        unsigned int tx_unicast_frames;
1039        unsigned int tx_multicast_frames;
1040        unsigned int tx_fragments;
1041        unsigned int tx_unicast_octets;
1042        unsigned int tx_multicast_octets;
1043        unsigned int tx_deferred_transmissions;
1044        unsigned int tx_single_retry_frames;
1045        unsigned int tx_multiple_retry_frames;
1046        unsigned int tx_retry_limit_exceeded;
1047        unsigned int tx_discards;
1048        unsigned int rx_unicast_frames;
1049        unsigned int rx_multicast_frames;
1050        unsigned int rx_fragments;
1051        unsigned int rx_unicast_octets;
1052        unsigned int rx_multicast_octets;
1053        unsigned int rx_fcs_errors;
1054        unsigned int rx_discards_no_buffer;
1055        unsigned int tx_discards_wrong_sa;
1056        unsigned int rx_discards_undecryptable;
1057        unsigned int rx_message_in_msg_fragments;
1058        unsigned int rx_message_in_bad_msg_fragments;
1059};
1060
1061struct rtllib_device;
1062
1063#define SEC_KEY_1        (1<<0)
1064#define SEC_KEY_2        (1<<1)
1065#define SEC_KEY_3        (1<<2)
1066#define SEC_KEY_4        (1<<3)
1067#define SEC_ACTIVE_KEY    (1<<4)
1068#define SEC_AUTH_MODE     (1<<5)
1069#define SEC_UNICAST_GROUP (1<<6)
1070#define SEC_LEVEL        (1<<7)
1071#define SEC_ENABLED       (1<<8)
1072#define SEC_ENCRYPT       (1<<9)
1073
1074#define SEC_LEVEL_0      0 /* None */
1075#define SEC_LEVEL_1      1 /* WEP 40 and 104 bit */
1076#define SEC_LEVEL_2      2 /* Level 1 + TKIP */
1077#define SEC_LEVEL_2_CKIP 3 /* Level 1 + CKIP */
1078#define SEC_LEVEL_3      4 /* Level 2 + CCMP */
1079
1080#define SEC_ALG_NONE            0
1081#define SEC_ALG_WEP             1
1082#define SEC_ALG_TKIP            2
1083#define SEC_ALG_CCMP            4
1084
1085#define WEP_KEY_LEN             13
1086#define SCM_KEY_LEN             32
1087#define SCM_TEMPORAL_KEY_LENGTH 16
1088
1089struct rtllib_security {
1090        u16 active_key:2,
1091            enabled:1,
1092            auth_mode:2,
1093            auth_algo:4,
1094            unicast_uses_group:1,
1095            encrypt:1;
1096        u8 key_sizes[NUM_WEP_KEYS];
1097        u8 keys[NUM_WEP_KEYS][SCM_KEY_LEN];
1098        u8 level;
1099        u16 flags;
1100} __packed;
1101
1102
1103/*
1104 802.11 data frame from AP
1105      ,-------------------------------------------------------------------.
1106Bytes |  2   |  2   |    6    |    6    |    6    |  2   | 0..2312 |   4  |
1107      |------|------|---------|---------|---------|------|---------|------|
1108Desc. | ctrl | dura |  DA/RA  |   TA    |    SA   | Sequ |  frame  |  fcs |
1109      |      | tion | (BSSID) |  |       | ence |  data   |      |
1110      `-------------------------------------------------------------------'
1111Total: 28-2340 bytes
1112*/
1113
1114/* Management Frame Information Element Types */
1115enum rtllib_mfie {
1116        MFIE_TYPE_SSID = 0,
1117        MFIE_TYPE_RATES = 1,
1118        MFIE_TYPE_FH_SET = 2,
1119        MFIE_TYPE_DS_SET = 3,
1120        MFIE_TYPE_CF_SET = 4,
1121        MFIE_TYPE_TIM = 5,
1122        MFIE_TYPE_IBSS_SET = 6,
1123        MFIE_TYPE_COUNTRY = 7,
1124        MFIE_TYPE_HOP_PARAMS = 8,
1125        MFIE_TYPE_HOP_TABLE = 9,
1126        MFIE_TYPE_REQUEST = 10,
1127        MFIE_TYPE_CHALLENGE = 16,
1128        MFIE_TYPE_POWER_CONSTRAINT = 32,
1129        MFIE_TYPE_POWER_CAPABILITY = 33,
1130        MFIE_TYPE_TPC_REQUEST = 34,
1131        MFIE_TYPE_TPC_REPORT = 35,
1132        MFIE_TYPE_SUPP_CHANNELS = 36,
1133        MFIE_TYPE_CSA = 37,
1134        MFIE_TYPE_MEASURE_REQUEST = 38,
1135        MFIE_TYPE_MEASURE_REPORT = 39,
1136        MFIE_TYPE_QUIET = 40,
1137        MFIE_TYPE_IBSS_DFS = 41,
1138        MFIE_TYPE_ERP = 42,
1139        MFIE_TYPE_HT_CAP = 45,
1140        MFIE_TYPE_RSN = 48,
1141        MFIE_TYPE_RATES_EX = 50,
1142        MFIE_TYPE_HT_INFO = 61,
1143        MFIE_TYPE_AIRONET = 133,
1144        MFIE_TYPE_GENERIC = 221,
1145        MFIE_TYPE_QOS_PARAMETER = 222,
1146};
1147
1148/* Minimal header; can be used for passing 802.11 frames with sufficient
1149 * information to determine what type of underlying data type is actually
1150 * stored in the data. */
1151struct rtllib_pspoll_hdr {
1152        __le16 frame_ctl;
1153        __le16 aid;
1154        u8 bssid[ETH_ALEN];
1155        u8 ta[ETH_ALEN];
1156} __packed;
1157
1158struct rtllib_hdr {
1159        __le16 frame_ctl;
1160        __le16 duration_id;
1161        u8 payload[0];
1162} __packed;
1163
1164struct rtllib_hdr_1addr {
1165        __le16 frame_ctl;
1166        __le16 duration_id;
1167        u8 addr1[ETH_ALEN];
1168        u8 payload[0];
1169} __packed;
1170
1171struct rtllib_hdr_2addr {
1172        __le16 frame_ctl;
1173        __le16 duration_id;
1174        u8 addr1[ETH_ALEN];
1175        u8 addr2[ETH_ALEN];
1176        u8 payload[0];
1177} __packed;
1178
1179struct rtllib_hdr_3addr {
1180        __le16 frame_ctl;
1181        __le16 duration_id;
1182        u8 addr1[ETH_ALEN];
1183        u8 addr2[ETH_ALEN];
1184        u8 addr3[ETH_ALEN];
1185        __le16 seq_ctl;
1186        u8 payload[0];
1187} __packed;
1188
1189struct rtllib_hdr_4addr {
1190        __le16 frame_ctl;
1191        __le16 duration_id;
1192        u8 addr1[ETH_ALEN];
1193        u8 addr2[ETH_ALEN];
1194        u8 addr3[ETH_ALEN];
1195        __le16 seq_ctl;
1196        u8 addr4[ETH_ALEN];
1197        u8 payload[0];
1198} __packed;
1199
1200struct rtllib_hdr_3addrqos {
1201        __le16 frame_ctl;
1202        __le16 duration_id;
1203        u8 addr1[ETH_ALEN];
1204        u8 addr2[ETH_ALEN];
1205        u8 addr3[ETH_ALEN];
1206        __le16 seq_ctl;
1207        __le16 qos_ctl;
1208        u8 payload[0];
1209} __packed;
1210
1211struct rtllib_hdr_4addrqos {
1212        __le16 frame_ctl;
1213        __le16 duration_id;
1214        u8 addr1[ETH_ALEN];
1215        u8 addr2[ETH_ALEN];
1216        u8 addr3[ETH_ALEN];
1217        __le16 seq_ctl;
1218        u8 addr4[ETH_ALEN];
1219        __le16 qos_ctl;
1220        u8 payload[0];
1221} __packed;
1222
1223struct rtllib_info_element {
1224        u8 id;
1225        u8 len;
1226        u8 data[0];
1227} __packed;
1228
1229struct rtllib_authentication {
1230        struct rtllib_hdr_3addr header;
1231        __le16 algorithm;
1232        __le16 transaction;
1233        __le16 status;
1234        /*challenge*/
1235        struct rtllib_info_element info_element[0];
1236} __packed;
1237
1238struct rtllib_disauth {
1239        struct rtllib_hdr_3addr header;
1240        __le16 reason;
1241} __packed;
1242
1243struct rtllib_disassoc {
1244        struct rtllib_hdr_3addr header;
1245        __le16 reason;
1246} __packed;
1247
1248struct rtllib_probe_request {
1249        struct rtllib_hdr_3addr header;
1250        /* SSID, supported rates */
1251        struct rtllib_info_element info_element[0];
1252} __packed;
1253
1254struct rtllib_probe_response {
1255        struct rtllib_hdr_3addr header;
1256        u32 time_stamp[2];
1257        __le16 beacon_interval;
1258        __le16 capability;
1259        /* SSID, supported rates, FH params, DS params,
1260         * CF params, IBSS params, TIM (if beacon), RSN */
1261        struct rtllib_info_element info_element[0];
1262} __packed;
1263
1264/* Alias beacon for probe_response */
1265#define rtllib_beacon rtllib_probe_response
1266
1267struct rtllib_assoc_request_frame {
1268        struct rtllib_hdr_3addr header;
1269        __le16 capability;
1270        __le16 listen_interval;
1271        /* SSID, supported rates, RSN */
1272        struct rtllib_info_element info_element[0];
1273} __packed;
1274
1275struct rtllib_reassoc_request_frame {
1276        struct rtllib_hdr_3addr header;
1277        __le16 capability;
1278        __le16 listen_interval;
1279        u8 current_ap[ETH_ALEN];
1280        /* SSID, supported rates, RSN */
1281        struct rtllib_info_element info_element[0];
1282} __packed;
1283
1284struct rtllib_assoc_response_frame {
1285        struct rtllib_hdr_3addr header;
1286        __le16 capability;
1287        __le16 status;
1288        __le16 aid;
1289        struct rtllib_info_element info_element[0]; /* supported rates */
1290} __packed;
1291
1292struct rtllib_txb {
1293        u8 nr_frags;
1294        u8 encrypted;
1295        u8 queue_index;
1296        u8 rts_included;
1297        u16 reserved;
1298        __le16 frag_size;
1299        __le16 payload_size;
1300        struct sk_buff *fragments[0];
1301};
1302
1303#define MAX_TX_AGG_COUNT                  16
1304struct rtllib_drv_agg_txb {
1305        u8 nr_drv_agg_frames;
1306        struct sk_buff *tx_agg_frames[MAX_TX_AGG_COUNT];
1307} __packed;
1308
1309#define MAX_SUBFRAME_COUNT                64
1310struct rtllib_rxb {
1311        u8 nr_subframes;
1312        struct sk_buff *subframes[MAX_SUBFRAME_COUNT];
1313        u8 dst[ETH_ALEN];
1314        u8 src[ETH_ALEN];
1315} __packed;
1316
1317union frameqos {
1318        u16 shortdata;
1319        u8  chardata[2];
1320        struct {
1321                u16 tid:4;
1322                u16 eosp:1;
1323                u16 ack_policy:2;
1324                u16 reserved:1;
1325                u16 txop:8;
1326        } field;
1327};
1328
1329/* SWEEP TABLE ENTRIES NUMBER*/
1330#define MAX_SWEEP_TAB_ENTRIES             42
1331#define MAX_SWEEP_TAB_ENTRIES_PER_PACKET  7
1332/* MAX_RATES_LENGTH needs to be 12.  The spec says 8, and many APs
1333 * only use 8, and then use extended rates for the remaining supported
1334 * rates.  Other APs, however, stick all of their supported rates on the
1335 * main rates information element... */
1336#define MAX_RATES_LENGTH                  ((u8)12)
1337#define MAX_RATES_EX_LENGTH            ((u8)16)
1338#define MAX_NETWORK_COUNT                 96
1339
1340#define MAX_CHANNEL_NUMBER               161
1341#define RTLLIB_SOFTMAC_SCAN_TIME           100
1342#define RTLLIB_SOFTMAC_ASSOC_RETRY_TIME (HZ * 2)
1343
1344#define CRC_LENGTH               4U
1345
1346#define MAX_WPA_IE_LEN 64
1347#define MAX_WZC_IE_LEN 256
1348
1349#define NETWORK_EMPTY_ESSID (1<<0)
1350#define NETWORK_HAS_OFDM    (1<<1)
1351#define NETWORK_HAS_CCK     (1<<2)
1352
1353/* QoS structure */
1354#define NETWORK_HAS_QOS_PARAMETERS      (1<<3)
1355#define NETWORK_HAS_QOS_INFORMATION     (1<<4)
1356#define NETWORK_HAS_QOS_MASK        (NETWORK_HAS_QOS_PARAMETERS | \
1357                                         NETWORK_HAS_QOS_INFORMATION)
1358/* 802.11h */
1359#define NETWORK_HAS_POWER_CONSTRAINT    (1<<5)
1360#define NETWORK_HAS_CSA          (1<<6)
1361#define NETWORK_HAS_QUIET              (1<<7)
1362#define NETWORK_HAS_IBSS_DFS        (1<<8)
1363#define NETWORK_HAS_TPC_REPORT    (1<<9)
1364
1365#define NETWORK_HAS_ERP_VALUE      (1<<10)
1366
1367#define QOS_QUEUE_NUM              4
1368#define QOS_OUI_LEN                  3
1369#define QOS_OUI_TYPE                2
1370#define QOS_ELEMENT_ID            221
1371#define QOS_OUI_INFO_SUB_TYPE      0
1372#define QOS_OUI_PARAM_SUB_TYPE    1
1373#define QOS_VERSION_1              1
1374#define QOS_AIFSN_MIN_VALUE          2
1375
1376struct rtllib_qos_information_element {
1377        u8 elementID;
1378        u8 length;
1379        u8 qui[QOS_OUI_LEN];
1380        u8 qui_type;
1381        u8 qui_subtype;
1382        u8 version;
1383        u8 ac_info;
1384} __packed;
1385
1386struct rtllib_qos_ac_parameter {
1387        u8 aci_aifsn;
1388        u8 ecw_min_max;
1389        __le16 tx_op_limit;
1390} __packed;
1391
1392struct rtllib_qos_parameter_info {
1393        struct rtllib_qos_information_element info_element;
1394        u8 reserved;
1395        struct rtllib_qos_ac_parameter ac_params_record[QOS_QUEUE_NUM];
1396} __packed;
1397
1398struct rtllib_qos_parameters {
1399        __le16 cw_min[QOS_QUEUE_NUM];
1400        __le16 cw_max[QOS_QUEUE_NUM];
1401        u8 aifs[QOS_QUEUE_NUM];
1402        u8 flag[QOS_QUEUE_NUM];
1403        __le16 tx_op_limit[QOS_QUEUE_NUM];
1404} __packed;
1405
1406struct rtllib_qos_data {
1407        struct rtllib_qos_parameters parameters;
1408        unsigned int wmm_acm;
1409        int active;
1410        int supported;
1411        u8 param_count;
1412        u8 old_param_count;
1413};
1414
1415struct rtllib_tim_parameters {
1416        u8 tim_count;
1417        u8 tim_period;
1418} __packed;
1419
1420struct rtllib_wmm_ac_param {
1421        u8 ac_aci_acm_aifsn;
1422        u8 ac_ecwmin_ecwmax;
1423        u16 ac_txop_limit;
1424};
1425
1426struct rtllib_wmm_ts_info {
1427        u8 ac_dir_tid;
1428        u8 ac_up_psb;
1429        u8 reserved;
1430} __packed;
1431
1432struct rtllib_wmm_tspec_elem {
1433        struct rtllib_wmm_ts_info ts_info;
1434        u16 norm_msdu_size;
1435        u16 max_msdu_size;
1436        u32 min_serv_inter;
1437        u32 max_serv_inter;
1438        u32 inact_inter;
1439        u32 suspen_inter;
1440        u32 serv_start_time;
1441        u32 min_data_rate;
1442        u32 mean_data_rate;
1443        u32 peak_data_rate;
1444        u32 max_burst_size;
1445        u32 delay_bound;
1446        u32 min_phy_rate;
1447        u16 surp_band_allow;
1448        u16 medium_time;
1449} __packed;
1450
1451enum eap_type {
1452        EAP_PACKET = 0,
1453        EAPOL_START,
1454        EAPOL_LOGOFF,
1455        EAPOL_KEY,
1456        EAPOL_ENCAP_ASF_ALERT
1457};
1458
1459static const char * const eap_types[] = {
1460        [EAP_PACKET]            = "EAP-Packet",
1461        [EAPOL_START]           = "EAPOL-Start",
1462        [EAPOL_LOGOFF]          = "EAPOL-Logoff",
1463        [EAPOL_KEY]             = "EAPOL-Key",
1464        [EAPOL_ENCAP_ASF_ALERT] = "EAPOL-Encap-ASF-Alert"
1465};
1466
1467static inline const char *eap_get_type(int type)
1468{
1469        return ((u32)type >= ARRAY_SIZE(eap_types)) ? "Unknown" :
1470                 eap_types[type];
1471}
1472static inline u8 Frame_QoSTID(u8 *buf)
1473{
1474        struct rtllib_hdr_3addr *hdr;
1475        u16 fc;
1476
1477        hdr = (struct rtllib_hdr_3addr *)buf;
1478        fc = le16_to_cpu(hdr->frame_ctl);
1479        return (u8)((union frameqos *)(buf + (((fc & RTLLIB_FCTL_TODS) &&
1480                    (fc & RTLLIB_FCTL_FROMDS)) ? 30 : 24)))->field.tid;
1481}
1482
1483
1484struct eapol {
1485        u8 snap[6];
1486        u16 ethertype;
1487        u8 version;
1488        u8 type;
1489        u16 length;
1490} __packed;
1491
1492struct rtllib_softmac_stats {
1493        unsigned int rx_ass_ok;
1494        unsigned int rx_ass_err;
1495        unsigned int rx_probe_rq;
1496        unsigned int tx_probe_rs;
1497        unsigned int tx_beacons;
1498        unsigned int rx_auth_rq;
1499        unsigned int rx_auth_rs_ok;
1500        unsigned int rx_auth_rs_err;
1501        unsigned int tx_auth_rq;
1502        unsigned int no_auth_rs;
1503        unsigned int no_ass_rs;
1504        unsigned int tx_ass_rq;
1505        unsigned int rx_ass_rq;
1506        unsigned int tx_probe_rq;
1507        unsigned int reassoc;
1508        unsigned int swtxstop;
1509        unsigned int swtxawake;
1510        unsigned char CurrentShowTxate;
1511        unsigned char last_packet_rate;
1512        unsigned int txretrycount;
1513};
1514
1515#define BEACON_PROBE_SSID_ID_POSITION 12
1516
1517struct rtllib_info_element_hdr {
1518        u8 id;
1519        u8 len;
1520} __packed;
1521
1522/*
1523 * These are the data types that can make up management packets
1524 *
1525        u16 auth_algorithm;
1526        u16 auth_sequence;
1527        u16 beacon_interval;
1528        u16 capability;
1529        u8 current_ap[ETH_ALEN];
1530        u16 listen_interval;
1531        struct {
1532                u16 association_id:14, reserved:2;
1533        } __packed;
1534        u32 time_stamp[2];
1535        u16 reason;
1536        u16 status;
1537*/
1538
1539#define RTLLIB_DEFAULT_TX_ESSID "Penguin"
1540#define RTLLIB_DEFAULT_BASIC_RATE 2
1541
1542enum {WMM_all_frame, WMM_two_frame, WMM_four_frame, WMM_six_frame};
1543#define MAX_SP_Len  (WMM_all_frame << 4)
1544#define RTLLIB_QOS_TID 0x0f
1545#define QOS_CTL_NOTCONTAIN_ACK (0x01 << 5)
1546
1547#define RTLLIB_DTIM_MBCAST 4
1548#define RTLLIB_DTIM_UCAST 2
1549#define RTLLIB_DTIM_VALID 1
1550#define RTLLIB_DTIM_INVALID 0
1551
1552#define RTLLIB_PS_DISABLED 0
1553#define RTLLIB_PS_UNICAST RTLLIB_DTIM_UCAST
1554#define RTLLIB_PS_MBCAST RTLLIB_DTIM_MBCAST
1555
1556#define WME_AC_BK   0x00
1557#define WME_AC_BE   0x01
1558#define WME_AC_VI   0x02
1559#define WME_AC_VO   0x03
1560#define WME_ACI_MASK 0x03
1561#define WME_AIFSN_MASK 0x03
1562#define WME_AC_PRAM_LEN 16
1563
1564#define MAX_RECEIVE_BUFFER_SIZE 9100
1565
1566#define UP2AC(up) (                \
1567        ((up) < 1) ? WME_AC_BE : \
1568        ((up) < 3) ? WME_AC_BK : \
1569        ((up) < 4) ? WME_AC_BE : \
1570        ((up) < 6) ? WME_AC_VI : \
1571        WME_AC_VO)
1572
1573#define AC2UP(_ac)      (       \
1574        ((_ac) == WME_AC_VO) ? 6 : \
1575        ((_ac) == WME_AC_VI) ? 5 : \
1576        ((_ac) == WME_AC_BK) ? 1 : \
1577        0)
1578
1579#define ETHER_ADDR_LEN          6       /* length of an Ethernet address */
1580#define ETHERNET_HEADER_SIZE    14      /* length of two Ethernet address
1581                                         * plus ether type*/
1582
1583struct  ether_header {
1584        u8 ether_dhost[ETHER_ADDR_LEN];
1585        u8 ether_shost[ETHER_ADDR_LEN];
1586        u16 ether_type;
1587} __packed;
1588
1589#ifndef ETHERTYPE_PAE
1590#define ETHERTYPE_PAE   0x888e          /* EAPOL PAE/802.1x */
1591#endif
1592#ifndef ETHERTYPE_IP
1593#define ETHERTYPE_IP    0x0800          /* IP protocol */
1594#endif
1595
1596
1597enum erp_t {
1598        ERP_NonERPpresent       = 0x01,
1599        ERP_UseProtection       = 0x02,
1600        ERP_BarkerPreambleMode = 0x04,
1601};
1602
1603struct rtllib_network {
1604        /* These entries are used to identify a unique network */
1605        u8 bssid[ETH_ALEN];
1606        u8 channel;
1607        /* Ensure null-terminated for any debug msgs */
1608        u8 ssid[IW_ESSID_MAX_SIZE + 1];
1609        u8 ssid_len;
1610        u8 hidden_ssid[IW_ESSID_MAX_SIZE + 1];
1611        u8 hidden_ssid_len;
1612        struct rtllib_qos_data qos_data;
1613
1614        bool    bWithAironetIE;
1615        bool    bCkipSupported;
1616        bool    bCcxRmEnable;
1617        u16     CcxRmState[2];
1618        bool    bMBssidValid;
1619        u8      MBssidMask;
1620        u8      MBssid[6];
1621        bool    bWithCcxVerNum;
1622        u8      BssCcxVerNumber;
1623        /* These are network statistics */
1624        struct rtllib_rx_stats stats;
1625        u16 capability;
1626        u8  rates[MAX_RATES_LENGTH];
1627        u8  rates_len;
1628        u8  rates_ex[MAX_RATES_EX_LENGTH];
1629        u8  rates_ex_len;
1630        unsigned long last_scanned;
1631        u8  mode;
1632        u32 flags;
1633        u32 last_associate;
1634        u32 time_stamp[2];
1635        u16 beacon_interval;
1636        u16 listen_interval;
1637        u16 atim_window;
1638        u8  erp_value;
1639        u8  wpa_ie[MAX_WPA_IE_LEN];
1640        size_t wpa_ie_len;
1641        u8  rsn_ie[MAX_WPA_IE_LEN];
1642        size_t rsn_ie_len;
1643        u8  wzc_ie[MAX_WZC_IE_LEN];
1644        size_t wzc_ie_len;
1645
1646        struct rtllib_tim_parameters tim;
1647        u8  dtim_period;
1648        u8  dtim_data;
1649        u64 last_dtim_sta_time;
1650
1651        u8 wmm_info;
1652        struct rtllib_wmm_ac_param wmm_param[4];
1653        u8 Turbo_Enable;
1654        u16 CountryIeLen;
1655        u8 CountryIeBuf[MAX_IE_LEN];
1656        struct bss_ht bssht;
1657        bool broadcom_cap_exist;
1658        bool realtek_cap_exit;
1659        bool marvell_cap_exist;
1660        bool ralink_cap_exist;
1661        bool atheros_cap_exist;
1662        bool cisco_cap_exist;
1663        bool airgo_cap_exist;
1664        bool unknown_cap_exist;
1665        bool    berp_info_valid;
1666        bool buseprotection;
1667        bool bIsNetgear854T;
1668        u8 SignalStrength;
1669        u8 RSSI;
1670        struct list_head list;
1671};
1672
1673#if 1
1674enum rtllib_state {
1675
1676        /* the card is not linked at all */
1677        RTLLIB_NOLINK = 0,
1678
1679        /* RTLLIB_ASSOCIATING* are for BSS client mode
1680         * the driver shall not perform RX filtering unless
1681         * the state is LINKED.
1682         * The driver shall just check for the state LINKED and
1683         * defaults to NOLINK for ALL the other states (including
1684         * LINKED_SCANNING)
1685         */
1686
1687        /* the association procedure will start (wq scheduling)*/
1688        RTLLIB_ASSOCIATING,
1689        RTLLIB_ASSOCIATING_RETRY,
1690
1691        /* the association procedure is sending AUTH request*/
1692        RTLLIB_ASSOCIATING_AUTHENTICATING,
1693
1694        /* the association procedure has successfully authenticated
1695         * and is sending association request
1696         */
1697        RTLLIB_ASSOCIATING_AUTHENTICATED,
1698
1699        /* the link is ok. the card associated to a BSS or linked
1700         * to a ibss cell or acting as an AP and creating the bss
1701         */
1702        RTLLIB_LINKED,
1703
1704        /* same as LINKED, but the driver shall apply RX filter
1705         * rules as we are in NO_LINK mode. As the card is still
1706         * logically linked, but it is doing a syncro site survey
1707         * then it will be back to LINKED state.
1708         */
1709        RTLLIB_LINKED_SCANNING,
1710};
1711#else
1712enum rtllib_state {
1713        RTLLIB_UNINITIALIZED = 0,
1714        RTLLIB_INITIALIZED,
1715        RTLLIB_ASSOCIATING,
1716        RTLLIB_ASSOCIATED,
1717        RTLLIB_AUTHENTICATING,
1718        RTLLIB_AUTHENTICATED,
1719        RTLLIB_SHUTDOWN
1720};
1721#endif
1722
1723#define DEFAULT_MAX_SCAN_AGE (15 * HZ)
1724#define DEFAULT_FTS 2346
1725
1726#define CFG_RTLLIB_RESERVE_FCS (1<<0)
1727#define CFG_RTLLIB_COMPUTE_FCS (1<<1)
1728#define CFG_RTLLIB_RTS (1<<2)
1729
1730#define RTLLIB_24GHZ_MIN_CHANNEL 1
1731#define RTLLIB_24GHZ_MAX_CHANNEL 14
1732#define RTLLIB_24GHZ_CHANNELS (RTLLIB_24GHZ_MAX_CHANNEL - \
1733                                  RTLLIB_24GHZ_MIN_CHANNEL + 1)
1734
1735#define RTLLIB_52GHZ_MIN_CHANNEL 34
1736#define RTLLIB_52GHZ_MAX_CHANNEL 165
1737#define RTLLIB_52GHZ_CHANNELS (RTLLIB_52GHZ_MAX_CHANNEL - \
1738                                  RTLLIB_52GHZ_MIN_CHANNEL + 1)
1739#ifndef eqMacAddr
1740#define eqMacAddr(a, b)                                 \
1741        (((a)[0] == (b)[0] && (a)[1] == (b)[1] && (a)[2] == (b)[2] &&   \
1742        (a)[3] == (b)[3] && (a)[4] == (b)[4] && (a)[5] == (b)[5]) ? 1 : 0)
1743#endif
1744struct tx_pending {
1745        int frag;
1746        struct rtllib_txb *txb;
1747};
1748
1749struct bandwidth_autoswitch {
1750        long threshold_20Mhzto40Mhz;
1751        long    threshold_40Mhzto20Mhz;
1752        bool bforced_tx20Mhz;
1753        bool bautoswitch_enable;
1754};
1755
1756
1757
1758#define REORDER_WIN_SIZE        128
1759#define REORDER_ENTRY_NUM       128
1760struct rx_reorder_entry {
1761        struct list_head        List;
1762        u16                     SeqNum;
1763        struct rtllib_rxb *prxb;
1764};
1765enum fsync_state {
1766        Default_Fsync,
1767        HW_Fsync,
1768        SW_Fsync
1769};
1770
1771enum rt_ps_mode {
1772        eActive,
1773        eMaxPs,
1774        eFastPs,
1775        eAutoPs,
1776};
1777
1778enum ips_callback_function {
1779        IPS_CALLBACK_NONE = 0,
1780        IPS_CALLBACK_MGNT_LINK_REQUEST = 1,
1781        IPS_CALLBACK_JOIN_REQUEST = 2,
1782};
1783
1784enum rt_join_action {
1785        RT_JOIN_INFRA   = 1,
1786        RT_JOIN_IBSS  = 2,
1787        RT_START_IBSS = 3,
1788        RT_NO_ACTION  = 4,
1789};
1790
1791struct ibss_parms {
1792        u16   atimWin;
1793};
1794#define MAX_NUM_RATES   264
1795
1796enum rt_rf_power_state {
1797        eRfOn,
1798        eRfSleep,
1799        eRfOff
1800};
1801
1802#define MAX_SUPPORT_WOL_PATTERN_NUM             8
1803
1804#define MAX_WOL_BIT_MASK_SIZE           16
1805#define MAX_WOL_PATTERN_SIZE            128
1806
1807enum wol_pattern_type {
1808        eNetBIOS = 0,
1809        eIPv4IPv6ARP,
1810        eIPv4IPv6TCPSYN,
1811        eMACIDOnly,
1812        eNoDefined,
1813};
1814
1815struct rt_pm_wol_info {
1816        u32     PatternId;
1817        u32     Mask[4];
1818        u16     CrcRemainder;
1819        u8      WFMIndex;
1820        enum wol_pattern_type PatternType;
1821};
1822
1823struct rt_pwr_save_ctrl {
1824
1825        bool                            bInactivePs;
1826        bool                            bIPSModeBackup;
1827        bool                            bHaltAdapterClkRQ;
1828        bool                            bSwRfProcessing;
1829        enum rt_rf_power_state eInactivePowerState;
1830        struct work_struct              InactivePsWorkItem;
1831        struct timer_list       InactivePsTimer;
1832
1833        enum ips_callback_function ReturnPoint;
1834
1835        bool                            bTmpBssDesc;
1836        enum rt_join_action tmpJoinAction;
1837        struct rtllib_network tmpBssDesc;
1838
1839        bool                            bTmpScanOnly;
1840        bool                            bTmpActiveScan;
1841        bool                            bTmpFilterHiddenAP;
1842        bool                            bTmpUpdateParms;
1843        u8                              tmpSsidBuf[33];
1844        struct octet_string tmpSsid2Scan;
1845        bool                            bTmpSsid2Scan;
1846        u8                              tmpNetworkType;
1847        u8                              tmpChannelNumber;
1848        u16                             tmpBcnPeriod;
1849        u8                              tmpDtimPeriod;
1850        u16                             tmpmCap;
1851        struct octet_string tmpSuppRateSet;
1852        u8                              tmpSuppRateBuf[MAX_NUM_RATES];
1853        bool                            bTmpSuppRate;
1854        struct ibss_parms tmpIbpm;
1855        bool                            bTmpIbpm;
1856
1857        bool                            bLeisurePs;
1858        u32                             PowerProfile;
1859        u8                              LpsIdleCount;
1860        u8                              RegMaxLPSAwakeIntvl;
1861        u8                              LPSAwakeIntvl;
1862
1863        u32                             CurPsLevel;
1864        u32                             RegRfPsLevel;
1865
1866        bool                            bFwCtrlLPS;
1867        u8                              FWCtrlPSMode;
1868
1869        bool                            LinkReqInIPSRFOffPgs;
1870        bool                            BufConnectinfoBefore;
1871
1872
1873        bool                            bGpioRfSw;
1874
1875        u8                              RegAMDPciASPM;
1876
1877        u8                              oWLANMode;
1878        struct rt_pm_wol_info PmWoLPatternInfo[MAX_SUPPORT_WOL_PATTERN_NUM];
1879
1880};
1881
1882#define RT_RF_CHANGE_SOURCE u32
1883
1884#define RF_CHANGE_BY_SW BIT31
1885#define RF_CHANGE_BY_HW BIT30
1886#define RF_CHANGE_BY_PS BIT29
1887#define RF_CHANGE_BY_IPS BIT28
1888#define RF_CHANGE_BY_INIT       0
1889
1890enum country_code_type {
1891        COUNTRY_CODE_FCC = 0,
1892        COUNTRY_CODE_IC = 1,
1893        COUNTRY_CODE_ETSI = 2,
1894        COUNTRY_CODE_SPAIN = 3,
1895        COUNTRY_CODE_FRANCE = 4,
1896        COUNTRY_CODE_MKK = 5,
1897        COUNTRY_CODE_MKK1 = 6,
1898        COUNTRY_CODE_ISRAEL = 7,
1899        COUNTRY_CODE_TELEC = 8,
1900        COUNTRY_CODE_MIC = 9,
1901        COUNTRY_CODE_GLOBAL_DOMAIN = 10,
1902        COUNTRY_CODE_WORLD_WIDE_13 = 11,
1903        COUNTRY_CODE_TELEC_NETGEAR = 12,
1904        COUNTRY_CODE_MAX
1905};
1906
1907enum scan_op_backup_opt {
1908        SCAN_OPT_BACKUP = 0,
1909        SCAN_OPT_RESTORE,
1910        SCAN_OPT_MAX
1911};
1912
1913enum fw_cmd_io_type {
1914        FW_CMD_DIG_ENABLE = 0,
1915        FW_CMD_DIG_DISABLE = 1,
1916        FW_CMD_DIG_HALT = 2,
1917        FW_CMD_DIG_RESUME = 3,
1918        FW_CMD_HIGH_PWR_ENABLE = 4,
1919        FW_CMD_HIGH_PWR_DISABLE = 5,
1920        FW_CMD_RA_RESET = 6,
1921        FW_CMD_RA_ACTIVE = 7,
1922        FW_CMD_RA_REFRESH_N = 8,
1923        FW_CMD_RA_REFRESH_BG = 9,
1924        FW_CMD_RA_INIT = 10,
1925        FW_CMD_IQK_ENABLE = 11,
1926        FW_CMD_TXPWR_TRACK_ENABLE = 12,
1927        FW_CMD_TXPWR_TRACK_DISABLE = 13,
1928        FW_CMD_TXPWR_TRACK_THERMAL = 14,
1929        FW_CMD_PAUSE_DM_BY_SCAN = 15,
1930        FW_CMD_RESUME_DM_BY_SCAN = 16,
1931        FW_CMD_RA_REFRESH_N_COMB = 17,
1932        FW_CMD_RA_REFRESH_BG_COMB = 18,
1933        FW_CMD_ANTENNA_SW_ENABLE = 19,
1934        FW_CMD_ANTENNA_SW_DISABLE = 20,
1935        FW_CMD_TX_FEEDBACK_CCX_ENABLE = 21,
1936        FW_CMD_LPS_ENTER = 22,
1937        FW_CMD_LPS_LEAVE = 23,
1938        FW_CMD_DIG_MODE_SS = 24,
1939        FW_CMD_DIG_MODE_FA = 25,
1940        FW_CMD_ADD_A2_ENTRY = 26,
1941        FW_CMD_CTRL_DM_BY_DRIVER = 27,
1942        FW_CMD_CTRL_DM_BY_DRIVER_NEW = 28,
1943        FW_CMD_PAPE_CONTROL = 29,
1944        FW_CMD_CHAN_SET = 30,
1945};
1946
1947#define RT_MAX_LD_SLOT_NUM      10
1948struct rt_link_detect {
1949
1950        u32                             NumRecvBcnInPeriod;
1951        u32                             NumRecvDataInPeriod;
1952
1953        u32                             RxBcnNum[RT_MAX_LD_SLOT_NUM];
1954        u32                             RxDataNum[RT_MAX_LD_SLOT_NUM];
1955        u16                             SlotNum;
1956        u16                             SlotIndex;
1957
1958        u32                             NumTxOkInPeriod;
1959        u32                             NumRxOkInPeriod;
1960        u32                             NumRxUnicastOkInPeriod;
1961        bool                            bBusyTraffic;
1962        bool                            bHigherBusyTraffic;
1963        bool                            bHigherBusyRxTraffic;
1964        u8                              IdleCount;
1965        u32                             NumTxUnicastOkInPeriod;
1966        u32                             LastNumTxUnicast;
1967        u32                             LastNumRxUnicast;
1968};
1969
1970struct sw_cam_table {
1971
1972        u8                              macaddr[6];
1973        bool                            bused;
1974        u8                              key_buf[16];
1975        u16                             key_type;
1976        u8                              useDK;
1977        u8                              key_index;
1978
1979};
1980#define   TOTAL_CAM_ENTRY                               32
1981struct rate_adaptive {
1982        u8                              rate_adaptive_disabled;
1983        u8                              ratr_state;
1984        u16                             reserve;
1985
1986        u32                             high_rssi_thresh_for_ra;
1987        u32                             high2low_rssi_thresh_for_ra;
1988        u8                              low2high_rssi_thresh_for_ra40M;
1989        u32                             low_rssi_thresh_for_ra40M;
1990        u8                              low2high_rssi_thresh_for_ra20M;
1991        u32                             low_rssi_thresh_for_ra20M;
1992        u32                             upper_rssi_threshold_ratr;
1993        u32                             middle_rssi_threshold_ratr;
1994        u32                             low_rssi_threshold_ratr;
1995        u32                             low_rssi_threshold_ratr_40M;
1996        u32                             low_rssi_threshold_ratr_20M;
1997        u8                              ping_rssi_enable;
1998        u32                             ping_rssi_ratr;
1999        u32                             ping_rssi_thresh_for_ra;
2000        u32                             last_ratr;
2001        u8                              PreRATRState;
2002
2003};
2004enum ratr_table_mode_8192s {
2005        RATR_INX_WIRELESS_NGB = 0,
2006        RATR_INX_WIRELESS_NG = 1,
2007        RATR_INX_WIRELESS_NB = 2,
2008        RATR_INX_WIRELESS_N = 3,
2009        RATR_INX_WIRELESS_GB = 4,
2010        RATR_INX_WIRELESS_G = 5,
2011        RATR_INX_WIRELESS_B = 6,
2012        RATR_INX_WIRELESS_MC = 7,
2013        RATR_INX_WIRELESS_A = 8,
2014};
2015
2016#define NUM_PMKID_CACHE         16
2017struct rt_pmkid_list {
2018        u8 bUsed;
2019        u8 Bssid[6];
2020        u8 PMKID[16];
2021        u8 SsidBuf[33];
2022        u8 *ssid_octet;
2023        u16 ssid_length;
2024};
2025
2026struct rt_intel_promisc_mode {
2027        bool bPromiscuousOn;
2028        bool bFilterSourceStationFrame;
2029};
2030
2031
2032/*************** DRIVER STATUS   *****/
2033#define STATUS_SCANNING                 0
2034#define STATUS_SCAN_HW                  1
2035#define STATUS_SCAN_ABORTING    2
2036#define STATUS_SETTING_CHAN             3
2037/*************** DRIVER STATUS   *****/
2038
2039enum {
2040        NO_USE          = 0,
2041        USED            = 1,
2042        HW_SEC          = 2,
2043        SW_SEC          = 3,
2044};
2045
2046enum {
2047        LPS_IS_WAKE = 0,
2048        LPS_IS_SLEEP = 1,
2049        LPS_WAIT_NULL_DATA_SEND = 2,
2050};
2051
2052struct rtllib_device {
2053        struct pci_dev *pdev;
2054        struct net_device *dev;
2055        struct rtllib_security sec;
2056
2057        bool disable_mgnt_queue;
2058
2059        unsigned long status;
2060        short hwscan_ch_bk;
2061        enum ht_extchnl_offset chan_offset_bk;
2062        enum ht_channel_width bandwidth_bk;
2063        u8 hwscan_sem_up;
2064        u8      CntAfterLink;
2065
2066        enum rt_op_mode OpMode;
2067
2068        u8 VersionID;
2069        /* The last AssocReq/Resp IEs */
2070        u8 *assocreq_ies, *assocresp_ies;
2071        size_t assocreq_ies_len, assocresp_ies_len;
2072
2073        bool b_customer_lenovo_id;
2074        bool    bForcedShowRxRate;
2075        bool    bForcedShowRateStill;
2076        u8      SystemQueryDataRateCount;
2077        bool    bForcedBgMode;
2078        bool bUseRAMask;
2079        bool b1x1RecvCombine;
2080        u8 RF_Type;
2081        bool b1SSSupport;
2082
2083        u8 hwsec_active;
2084        bool is_silent_reset;
2085        bool force_mic_error;
2086        bool is_roaming;
2087        bool ieee_up;
2088        bool cannot_notify;
2089        bool bSupportRemoteWakeUp;
2090        enum rt_ps_mode dot11PowerSaveMode;
2091        bool actscanning;
2092        bool FirstIe_InScan;
2093        bool be_scan_inprogress;
2094        bool beinretry;
2095        enum rt_rf_power_state eRFPowerState;
2096        RT_RF_CHANGE_SOURCE     RfOffReason;
2097        bool is_set_key;
2098        bool wx_set_enc;
2099        struct rt_hi_throughput *pHTInfo;
2100        spinlock_t bw_spinlock;
2101
2102        spinlock_t reorder_spinlock;
2103        u8      Regdot11HTOperationalRateSet[16];
2104        u8      Regdot11TxHTOperationalRateSet[16];
2105        u8      dot11HTOperationalRateSet[16];
2106        u8      RegHTSuppRateSet[16];
2107        u8      HTCurrentOperaRate;
2108        u8      HTHighestOperaRate;
2109        u8      MinSpaceCfg;
2110        u8      MaxMssDensity;
2111        u8      bTxDisableRateFallBack;
2112        u8      bTxUseDriverAssingedRate;
2113        u8      bTxEnableFwCalcDur;
2114        atomic_t        atm_chnlop;
2115        atomic_t        atm_swbw;
2116
2117        struct list_head                Tx_TS_Admit_List;
2118        struct list_head                Tx_TS_Pending_List;
2119        struct list_head                Tx_TS_Unused_List;
2120        struct tx_ts_record TxTsRecord[TOTAL_TS_NUM];
2121        struct list_head                Rx_TS_Admit_List;
2122        struct list_head                Rx_TS_Pending_List;
2123        struct list_head                Rx_TS_Unused_List;
2124        struct rx_ts_record RxTsRecord[TOTAL_TS_NUM];
2125        struct rx_reorder_entry RxReorderEntry[128];
2126        struct list_head                RxReorder_Unused_List;
2127        u8                              ForcedPriority;
2128
2129
2130        /* Bookkeeping structures */
2131        struct net_device_stats stats;
2132        struct rtllib_stats ieee_stats;
2133        struct rtllib_softmac_stats softmac_stats;
2134
2135        /* Probe / Beacon management */
2136        struct list_head network_free_list;
2137        struct list_head network_list;
2138        struct rtllib_network *networks;
2139        int scans;
2140        int scan_age;
2141
2142        int iw_mode; /* operating mode (IW_MODE_*) */
2143        bool bNetPromiscuousMode;
2144        struct rt_intel_promisc_mode IntelPromiscuousModeInfo;
2145
2146        struct iw_spy_data spy_data;
2147
2148        spinlock_t lock;
2149        spinlock_t wpax_suitlist_lock;
2150
2151        int tx_headroom; /* Set to size of any additional room needed at front
2152                          * of allocated Tx SKBs */
2153        u32 config;
2154
2155        /* WEP and other encryption related settings at the device level */
2156        int open_wep; /* Set to 1 to allow unencrypted frames */
2157        int auth_mode;
2158        int reset_on_keychange; /* Set to 1 if the HW needs to be reset on
2159                                 * WEP key changes */
2160
2161        /* If the host performs {en,de}cryption, then set to 1 */
2162        int host_encrypt;
2163        int host_encrypt_msdu;
2164        int host_decrypt;
2165        /* host performs multicast decryption */
2166        int host_mc_decrypt;
2167
2168        /* host should strip IV and ICV from protected frames */
2169        /* meaningful only when hardware decryption is being used */
2170        int host_strip_iv_icv;
2171
2172        int host_open_frag;
2173        int host_build_iv;
2174        int ieee802_1x; /* is IEEE 802.1X used */
2175
2176        /* WPA data */
2177        bool bHalfNMode;
2178        bool bHalfWirelessN24GMode;
2179        int wpa_enabled;
2180        int drop_unencrypted;
2181        int tkip_countermeasures;
2182        int privacy_invoked;
2183        size_t wpa_ie_len;
2184        u8 *wpa_ie;
2185        size_t wps_ie_len;
2186        u8 *wps_ie;
2187        u8 ap_mac_addr[6];
2188        u16 pairwise_key_type;
2189        u16 group_key_type;
2190
2191        struct lib80211_crypt_info crypt_info;
2192
2193        struct sw_cam_table swcamtable[TOTAL_CAM_ENTRY];
2194        int bcrx_sta_key; /* use individual keys to override default keys even
2195                           * with RX of broad/multicast frames */
2196
2197        struct rt_pmkid_list PMKIDList[NUM_PMKID_CACHE];
2198
2199        /* Fragmentation structures */
2200        struct rtllib_frag_entry frag_cache[17][RTLLIB_FRAG_CACHE_LEN];
2201        unsigned int frag_next_idx[17];
2202        u16 fts; /* Fragmentation Threshold */
2203#define DEFAULT_RTS_THRESHOLD 2346U
2204#define MIN_RTS_THRESHOLD 1
2205#define MAX_RTS_THRESHOLD 2346U
2206        u16 rts; /* RTS threshold */
2207
2208        /* Association info */
2209        u8 bssid[ETH_ALEN];
2210
2211        /* This stores infos for the current network.
2212         * Either the network we are associated in INFRASTRUCTURE
2213         * or the network that we are creating in MASTER mode.
2214         * ad-hoc is a mixture ;-).
2215         * Note that in infrastructure mode, even when not associated,
2216         * fields bssid and essid may be valid (if wpa_set and essid_set
2217         * are true) as thy carry the value set by the user via iwconfig
2218         */
2219        struct rtllib_network current_network;
2220
2221        enum rtllib_state state;
2222
2223        int short_slot;
2224        int reg_mode;
2225        int mode;       /* A, B, G */
2226        int modulation; /* CCK, OFDM */
2227        int freq_band;  /* 2.4Ghz, 5.2Ghz, Mixed */
2228        int abg_true;   /* ABG flag           */
2229
2230        /* used for forcing the ibss workqueue to terminate
2231         * without wait for the syncro scan to terminate
2232         */
2233        short sync_scan_hurryup;
2234        u16 scan_watch_dog;
2235        int perfect_rssi;
2236        int worst_rssi;
2237
2238        u16 prev_seq_ctl;       /* used to drop duplicate frames */
2239
2240        /* map of allowed channels. 0 is dummy */
2241        void *pDot11dInfo;
2242        bool bGlobalDomain;
2243        u8 active_channel_map[MAX_CHANNEL_NUMBER+1];
2244
2245        u8   IbssStartChnl;
2246        u8   ibss_maxjoin_chal;
2247
2248        int rate;       /* current rate */
2249        int basic_rate;
2250        u32     currentRate;
2251
2252        short active_scan;
2253
2254        /* this contains flags for selectively enable softmac support */
2255        u16 softmac_features;
2256
2257        /* if the sequence control field is not filled by HW */
2258        u16 seq_ctrl[5];
2259
2260        /* association procedure transaction sequence number */
2261        u16 associate_seq;
2262
2263        /* AID for RTXed association responses */
2264        u16 assoc_id;
2265
2266        /* power save mode related*/
2267        u8 ack_tx_to_ieee;
2268        short ps;
2269        short sta_sleep;
2270        int ps_timeout;
2271        int ps_period;
2272        struct tasklet_struct ps_task;
2273        u64 ps_time;
2274        bool polling;
2275
2276        short raw_tx;
2277        /* used if IEEE_SOFTMAC_TX_QUEUE is set */
2278        short queue_stop;
2279        short scanning_continue ;
2280        short proto_started;
2281        short proto_stoppping;
2282
2283        struct semaphore wx_sem;
2284        struct semaphore scan_sem;
2285        struct semaphore ips_sem;
2286
2287        spinlock_t mgmt_tx_lock;
2288        spinlock_t beacon_lock;
2289
2290        short beacon_txing;
2291
2292        short wap_set;
2293        short ssid_set;
2294
2295        /* set on initialization */
2296        u8  qos_support;
2297        unsigned int wmm_acm;
2298
2299        /* for discarding duplicated packets in IBSS */
2300        struct list_head ibss_mac_hash[IEEE_IBSS_MAC_HASH_SIZE];
2301
2302        /* for discarding duplicated packets in BSS */
2303        u16 last_rxseq_num[17]; /* rx seq previous per-tid */
2304        u16 last_rxfrag_num[17];/* tx frag previous per-tid */
2305        unsigned long last_packet_time[17];
2306
2307        /* for PS mode */
2308        unsigned long last_rx_ps_time;
2309        bool                    bAwakePktSent;
2310        u8                      LPSDelayCnt;
2311
2312        /* used if IEEE_SOFTMAC_SINGLE_QUEUE is set */
2313        struct sk_buff *mgmt_queue_ring[MGMT_QUEUE_NUM];
2314        int mgmt_queue_head;
2315        int mgmt_queue_tail;
2316#define RTLLIB_QUEUE_LIMIT 128
2317        u8 AsocRetryCount;
2318        unsigned int hw_header;
2319        struct sk_buff_head skb_waitQ[MAX_QUEUE_SIZE];
2320        struct sk_buff_head  skb_aggQ[MAX_QUEUE_SIZE];
2321        struct sk_buff_head  skb_drv_aggQ[MAX_QUEUE_SIZE];
2322        u32     sta_edca_param[4];
2323        bool aggregation;
2324        bool enable_rx_imm_BA;
2325        bool bibsscoordinator;
2326
2327        bool    bdynamic_txpower_enable;
2328
2329        bool bCTSToSelfEnable;
2330        u8      CTSToSelfTH;
2331
2332        u32     fsync_time_interval;
2333        u32     fsync_rate_bitmap;
2334        u8      fsync_rssi_threshold;
2335        bool    bfsync_enable;
2336
2337        u8      fsync_multiple_timeinterval;
2338        u32     fsync_firstdiff_ratethreshold;
2339        u32     fsync_seconddiff_ratethreshold;
2340        enum fsync_state fsync_state;
2341        bool            bis_any_nonbepkts;
2342        struct bandwidth_autoswitch bandwidth_auto_switch;
2343        bool FwRWRF;
2344
2345        struct rt_link_detect LinkDetectInfo;
2346        bool bIsAggregateFrame;
2347        struct rt_pwr_save_ctrl PowerSaveControl;
2348        u8 amsdu_in_process;
2349
2350        /* used if IEEE_SOFTMAC_TX_QUEUE is set */
2351        struct tx_pending tx_pending;
2352
2353        /* used if IEEE_SOFTMAC_ASSOCIATE is set */
2354        struct timer_list associate_timer;
2355
2356        /* used if IEEE_SOFTMAC_BEACONS is set */
2357        struct timer_list beacon_timer;
2358        u8 need_sw_enc;
2359        struct work_struct associate_complete_wq;
2360        struct work_struct ips_leave_wq;
2361        struct delayed_work associate_procedure_wq;
2362        struct delayed_work softmac_scan_wq;
2363        struct delayed_work softmac_hint11d_wq;
2364        struct delayed_work associate_retry_wq;
2365        struct delayed_work start_ibss_wq;
2366        struct delayed_work hw_wakeup_wq;
2367        struct delayed_work hw_sleep_wq;
2368        struct delayed_work link_change_wq;
2369        struct work_struct wx_sync_scan_wq;
2370
2371        struct workqueue_struct *wq;
2372        union {
2373                struct rtllib_rxb *RfdArray[REORDER_WIN_SIZE];
2374                struct rtllib_rxb *stats_IndicateArray[REORDER_WIN_SIZE];
2375                struct rtllib_rxb *prxbIndicateArray[REORDER_WIN_SIZE];
2376                struct {
2377                        struct sw_chnl_cmd PreCommonCmd[MAX_PRECMD_CNT];
2378                        struct sw_chnl_cmd PostCommonCmd[MAX_POSTCMD_CNT];
2379                        struct sw_chnl_cmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
2380                };
2381        };
2382
2383        /* Callback functions */
2384        void (*set_security)(struct net_device *dev,
2385                             struct rtllib_security *sec);
2386
2387        /* Used to TX data frame by using txb structs.
2388         * this is not used if in the softmac_features
2389         * is set the flag IEEE_SOFTMAC_TX_QUEUE
2390         */
2391        int (*hard_start_xmit)(struct rtllib_txb *txb,
2392                               struct net_device *dev);
2393
2394        int (*reset_port)(struct net_device *dev);
2395        int (*is_queue_full)(struct net_device *dev, int pri);
2396
2397        int (*handle_management)(struct net_device *dev,
2398                                 struct rtllib_network *network, u16 type);
2399        int (*is_qos_active)(struct net_device *dev, struct sk_buff *skb);
2400
2401        /* Softmac-generated frames (management) are TXed via this
2402         * callback if the flag IEEE_SOFTMAC_SINGLE_QUEUE is
2403         * not set. As some cards may have different HW queues that
2404         * one might want to use for data and management frames
2405         * the option to have two callbacks might be useful.
2406         * This function can't sleep.
2407         */
2408        int (*softmac_hard_start_xmit)(struct sk_buff *skb,
2409                               struct net_device *dev);
2410
2411        /* used instead of hard_start_xmit (not softmac_hard_start_xmit)
2412         * if the IEEE_SOFTMAC_TX_QUEUE feature is used to TX data
2413         * frames. If the option IEEE_SOFTMAC_SINGLE_QUEUE is also set
2414         * then also management frames are sent via this callback.
2415         * This function can't sleep.
2416         */
2417        void (*softmac_data_hard_start_xmit)(struct sk_buff *skb,
2418                               struct net_device *dev, int rate);
2419
2420        /* stops the HW queue for DATA frames. Useful to avoid
2421         * waste time to TX data frame when we are reassociating
2422         * This function can sleep.
2423         */
2424        void (*data_hard_stop)(struct net_device *dev);
2425
2426        /* OK this is complementing to data_poll_hard_stop */
2427        void (*data_hard_resume)(struct net_device *dev);
2428
2429        /* ask to the driver to retune the radio .
2430         * This function can sleep. the driver should ensure
2431         * the radio has been switched before return.
2432         */
2433        void (*set_chan)(struct net_device *dev, short ch);
2434
2435        /* These are not used if the ieee stack takes care of
2436         * scanning (IEEE_SOFTMAC_SCAN feature set).
2437         * In this case only the set_chan is used.
2438         *
2439         * The syncro version is similar to the start_scan but
2440         * does not return until all channels has been scanned.
2441         * this is called in user context and should sleep,
2442         * it is called in a work_queue when switching to ad-hoc mode
2443         * or in behalf of iwlist scan when the card is associated
2444         * and root user ask for a scan.
2445         * the function stop_scan should stop both the syncro and
2446         * background scanning and can sleep.
2447         * The function start_scan should initiate the background
2448         * scanning and can't sleep.
2449         */
2450        void (*scan_syncro)(struct net_device *dev);
2451        void (*start_scan)(struct net_device *dev);
2452        void (*stop_scan)(struct net_device *dev);
2453
2454        void (*rtllib_start_hw_scan)(struct net_device *dev);
2455        void (*rtllib_stop_hw_scan)(struct net_device *dev);
2456
2457        /* indicate the driver that the link state is changed
2458         * for example it may indicate the card is associated now.
2459         * Driver might be interested in this to apply RX filter
2460         * rules or simply light the LINK led
2461         */
2462        void (*link_change)(struct net_device *dev);
2463
2464        /* these two function indicates to the HW when to start
2465         * and stop to send beacons. This is used when the
2466         * IEEE_SOFTMAC_BEACONS is not set. For now the
2467         * stop_send_bacons is NOT guaranteed to be called only
2468         * after start_send_beacons.
2469         */
2470        void (*start_send_beacons)(struct net_device *dev);
2471        void (*stop_send_beacons)(struct net_device *dev);
2472
2473        /* power save mode related */
2474        void (*sta_wake_up)(struct net_device *dev);
2475        void (*enter_sleep_state)(struct net_device *dev, u64 time);
2476        short (*ps_is_queue_empty)(struct net_device *dev);
2477        int (*handle_beacon)(struct net_device *dev,
2478                             struct rtllib_beacon *beacon,
2479                             struct rtllib_network *network);
2480        int (*handle_assoc_response)(struct net_device *dev,
2481                                     struct rtllib_assoc_response_frame *resp,
2482                                     struct rtllib_network *network);
2483
2484
2485        /* check whether Tx hw resource available */
2486        short (*check_nic_enough_desc)(struct net_device *dev, int queue_index);
2487        short (*get_nic_desc_num)(struct net_device *dev, int queue_index);
2488        void (*SetBWModeHandler)(struct net_device *dev,
2489                                 enum ht_channel_width Bandwidth,
2490                                 enum ht_extchnl_offset Offset);
2491        bool (*GetNmodeSupportBySecCfg)(struct net_device *dev);
2492        void (*SetWirelessMode)(struct net_device *dev, u8 wireless_mode);
2493        bool (*GetHalfNmodeSupportByAPsHandler)(struct net_device *dev);
2494        u8   (*rtllib_ap_sec_type)(struct rtllib_device *ieee);
2495        void (*HalUsbRxAggrHandler)(struct net_device *dev, bool Value);
2496        void (*InitialGainHandler)(struct net_device *dev, u8 Operation);
2497        bool (*SetFwCmdHandler)(struct net_device *dev,
2498                                enum fw_cmd_io_type FwCmdIO);
2499        void (*UpdateHalRAMaskHandler)(struct net_device *dev, bool bMulticast,
2500                                       u8 macId, u8 MimoPs, u8 WirelessMode,
2501                                       u8 bCurTxBW40MHz, u8 rssi_level);
2502        void (*UpdateBeaconInterruptHandler)(struct net_device *dev,
2503                                             bool start);
2504        void (*UpdateInterruptMaskHandler)(struct net_device *dev, u32 AddMSR,
2505                                           u32 RemoveMSR);
2506        u16  (*rtl_11n_user_show_rates)(struct net_device *dev);
2507        void (*ScanOperationBackupHandler)(struct net_device *dev,
2508                                           u8 Operation);
2509        void (*LedControlHandler)(struct net_device *dev,
2510                                  enum led_ctl_mode LedAction);
2511        void (*SetHwRegHandler)(struct net_device *dev, u8 variable, u8 *val);
2512        void (*GetHwRegHandler)(struct net_device *dev, u8 variable, u8 *val);
2513
2514        void (*AllowAllDestAddrHandler)(struct net_device *dev,
2515                                        bool bAllowAllDA, bool WriteIntoReg);
2516
2517        void (*rtllib_ips_leave_wq)(struct net_device *dev);
2518        void (*rtllib_ips_leave)(struct net_device *dev);
2519        void (*LeisurePSLeave)(struct net_device *dev);
2520        void (*rtllib_rfkill_poll)(struct net_device *dev);
2521
2522        /* This must be the last item so that it points to the data
2523         * allocated beyond this structure by alloc_rtllib */
2524        u8 priv[0];
2525};
2526
2527#define IEEE_A      (1<<0)
2528#define IEEE_B      (1<<1)
2529#define IEEE_G      (1<<2)
2530#define IEEE_N_24G                (1<<4)
2531#define IEEE_N_5G                 (1<<5)
2532#define IEEE_MODE_MASK    (IEEE_A|IEEE_B|IEEE_G)
2533
2534/* Generate a 802.11 header */
2535
2536/* Uses the channel change callback directly
2537 * instead of [start/stop] scan callbacks
2538 */
2539#define IEEE_SOFTMAC_SCAN (1<<2)
2540
2541/* Perform authentication and association handshake */
2542#define IEEE_SOFTMAC_ASSOCIATE (1<<3)
2543
2544/* Generate probe requests */
2545#define IEEE_SOFTMAC_PROBERQ (1<<4)
2546
2547/* Generate response to probe requests */
2548#define IEEE_SOFTMAC_PROBERS (1<<5)
2549
2550/* The ieee802.11 stack will manage the netif queue
2551 * wake/stop for the driver, taking care of 802.11
2552 * fragmentation. See softmac.c for details. */
2553#define IEEE_SOFTMAC_TX_QUEUE (1<<7)
2554
2555/* Uses only the softmac_data_hard_start_xmit
2556 * even for TX management frames.
2557 */
2558#define IEEE_SOFTMAC_SINGLE_QUEUE (1<<8)
2559
2560/* Generate beacons.  The stack will enqueue beacons
2561 * to the card
2562 */
2563#define IEEE_SOFTMAC_BEACONS (1<<6)
2564
2565
2566static inline void *rtllib_priv(struct net_device *dev)
2567{
2568        return ((struct rtllib_device *)netdev_priv(dev))->priv;
2569}
2570
2571static inline int rtllib_is_empty_essid(const char *essid, int essid_len)
2572{
2573        /* Single white space is for Linksys APs */
2574        if (essid_len == 1 && essid[0] == ' ')
2575                return 1;
2576
2577        /* Otherwise, if the entire essid is 0, we assume it is hidden */
2578        while (essid_len) {
2579                essid_len--;
2580                if (essid[essid_len] != '\0')
2581                        return 0;
2582        }
2583
2584        return 1;
2585}
2586
2587static inline int rtllib_is_valid_mode(struct rtllib_device *ieee, int mode)
2588{
2589        /*
2590         * It is possible for both access points and our device to support
2591         * combinations of modes, so as long as there is one valid combination
2592         * of ap/device supported modes, then return success
2593         *
2594         */
2595        if ((mode & IEEE_A) &&
2596            (ieee->modulation & RTLLIB_OFDM_MODULATION) &&
2597            (ieee->freq_band & RTLLIB_52GHZ_BAND))
2598                return 1;
2599
2600        if ((mode & IEEE_G) &&
2601            (ieee->modulation & RTLLIB_OFDM_MODULATION) &&
2602            (ieee->freq_band & RTLLIB_24GHZ_BAND))
2603                return 1;
2604
2605        if ((mode & IEEE_B) &&
2606            (ieee->modulation & RTLLIB_CCK_MODULATION) &&
2607            (ieee->freq_band & RTLLIB_24GHZ_BAND))
2608                return 1;
2609
2610        return 0;
2611}
2612
2613static inline int rtllib_get_hdrlen(u16 fc)
2614{
2615        int hdrlen = RTLLIB_3ADDR_LEN;
2616
2617        switch (WLAN_FC_GET_TYPE(fc)) {
2618        case RTLLIB_FTYPE_DATA:
2619                if ((fc & RTLLIB_FCTL_FROMDS) && (fc & RTLLIB_FCTL_TODS))
2620                        hdrlen = RTLLIB_4ADDR_LEN; /* Addr4 */
2621                if (RTLLIB_QOS_HAS_SEQ(fc))
2622                        hdrlen += 2; /* QOS ctrl*/
2623                break;
2624        case RTLLIB_FTYPE_CTL:
2625                switch (WLAN_FC_GET_STYPE(fc)) {
2626                case RTLLIB_STYPE_CTS:
2627                case RTLLIB_STYPE_ACK:
2628                        hdrlen = RTLLIB_1ADDR_LEN;
2629                        break;
2630                default:
2631                        hdrlen = RTLLIB_2ADDR_LEN;
2632                        break;
2633                }
2634                break;
2635        }
2636
2637        return hdrlen;
2638}
2639
2640static inline u8 *rtllib_get_payload(struct rtllib_hdr *hdr)
2641{
2642        switch (rtllib_get_hdrlen(le16_to_cpu(hdr->frame_ctl))) {
2643        case RTLLIB_1ADDR_LEN:
2644                return ((struct rtllib_hdr_1addr *)hdr)->payload;
2645        case RTLLIB_2ADDR_LEN:
2646                return ((struct rtllib_hdr_2addr *)hdr)->payload;
2647        case RTLLIB_3ADDR_LEN:
2648                return ((struct rtllib_hdr_3addr *)hdr)->payload;
2649        case RTLLIB_4ADDR_LEN:
2650                return ((struct rtllib_hdr_4addr *)hdr)->payload;
2651        }
2652        return NULL;
2653}
2654
2655static inline int rtllib_is_ofdm_rate(u8 rate)
2656{
2657        switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
2658        case RTLLIB_OFDM_RATE_6MB:
2659        case RTLLIB_OFDM_RATE_9MB:
2660        case RTLLIB_OFDM_RATE_12MB:
2661        case RTLLIB_OFDM_RATE_18MB:
2662        case RTLLIB_OFDM_RATE_24MB:
2663        case RTLLIB_OFDM_RATE_36MB:
2664        case RTLLIB_OFDM_RATE_48MB:
2665        case RTLLIB_OFDM_RATE_54MB:
2666                return 1;
2667        }
2668        return 0;
2669}
2670
2671static inline int rtllib_is_cck_rate(u8 rate)
2672{
2673        switch (rate & ~RTLLIB_BASIC_RATE_MASK) {
2674        case RTLLIB_CCK_RATE_1MB:
2675        case RTLLIB_CCK_RATE_2MB:
2676        case RTLLIB_CCK_RATE_5MB:
2677        case RTLLIB_CCK_RATE_11MB:
2678                return 1;
2679        }
2680        return 0;
2681}
2682
2683
2684/* rtllib.c */
2685extern void free_rtllib(struct net_device *dev);
2686extern struct net_device *alloc_rtllib(int sizeof_priv);
2687
2688extern int rtllib_set_encryption(struct rtllib_device *ieee);
2689
2690/* rtllib_tx.c */
2691
2692extern int rtllib_encrypt_fragment(
2693        struct rtllib_device *ieee,
2694        struct sk_buff *frag,
2695        int hdr_len);
2696
2697extern int rtllib_xmit(struct sk_buff *skb,  struct net_device *dev);
2698extern int rtllib_xmit_inter(struct sk_buff *skb, struct net_device *dev);
2699extern void rtllib_txb_free(struct rtllib_txb *);
2700
2701/* rtllib_rx.c */
2702extern int rtllib_rx(struct rtllib_device *ieee, struct sk_buff *skb,
2703                        struct rtllib_rx_stats *rx_stats);
2704extern void rtllib_rx_mgt(struct rtllib_device *ieee,
2705                             struct sk_buff *skb,
2706                             struct rtllib_rx_stats *stats);
2707extern void rtllib_rx_probe_rq(struct rtllib_device *ieee,
2708                           struct sk_buff *skb);
2709extern int rtllib_legal_channel(struct rtllib_device *rtllib, u8 channel);
2710
2711/* rtllib_wx.c */
2712extern int rtllib_wx_get_scan(struct rtllib_device *ieee,
2713                                 struct iw_request_info *info,
2714                                 union iwreq_data *wrqu, char *key);
2715extern int rtllib_wx_set_encode(struct rtllib_device *ieee,
2716                                   struct iw_request_info *info,
2717                                   union iwreq_data *wrqu, char *key);
2718extern int rtllib_wx_get_encode(struct rtllib_device *ieee,
2719                                   struct iw_request_info *info,
2720                                   union iwreq_data *wrqu, char *key);
2721#if WIRELESS_EXT >= 18
2722extern int rtllib_wx_get_encode_ext(struct rtllib_device *ieee,
2723                            struct iw_request_info *info,
2724                            union iwreq_data *wrqu, char *extra);
2725extern int rtllib_wx_set_encode_ext(struct rtllib_device *ieee,
2726                            struct iw_request_info *info,
2727                            union iwreq_data *wrqu, char *extra);
2728#endif
2729extern int rtllib_wx_set_auth(struct rtllib_device *ieee,
2730                               struct iw_request_info *info,
2731                               struct iw_param *data, char *extra);
2732extern int rtllib_wx_set_mlme(struct rtllib_device *ieee,
2733                               struct iw_request_info *info,
2734                               union iwreq_data *wrqu, char *extra);
2735extern int rtllib_wx_set_gen_ie(struct rtllib_device *ieee, u8 *ie, size_t len);
2736
2737/* rtllib_softmac.c */
2738extern short rtllib_is_54g(struct rtllib_network *net);
2739extern short rtllib_is_shortslot(const struct rtllib_network *net);
2740extern int rtllib_rx_frame_softmac(struct rtllib_device *ieee,
2741                                   struct sk_buff *skb,
2742                                   struct rtllib_rx_stats *rx_stats, u16 type,
2743                                   u16 stype);
2744extern void rtllib_softmac_new_net(struct rtllib_device *ieee,
2745                                   struct rtllib_network *net);
2746
2747void SendDisassociation(struct rtllib_device *ieee, bool deauth, u16 asRsn);
2748extern void rtllib_softmac_xmit(struct rtllib_txb *txb,
2749                                struct rtllib_device *ieee);
2750
2751extern void rtllib_stop_send_beacons(struct rtllib_device *ieee);
2752extern void notify_wx_assoc_event(struct rtllib_device *ieee);
2753extern void rtllib_softmac_check_all_nets(struct rtllib_device *ieee);
2754extern void rtllib_start_bss(struct rtllib_device *ieee);
2755extern void rtllib_start_master_bss(struct rtllib_device *ieee);
2756extern void rtllib_start_ibss(struct rtllib_device *ieee);
2757extern void rtllib_softmac_init(struct rtllib_device *ieee);
2758extern void rtllib_softmac_free(struct rtllib_device *ieee);
2759extern void rtllib_associate_abort(struct rtllib_device *ieee);
2760extern void rtllib_disassociate(struct rtllib_device *ieee);
2761extern void rtllib_stop_scan(struct rtllib_device *ieee);
2762extern bool rtllib_act_scanning(struct rtllib_device *ieee, bool sync_scan);
2763extern void rtllib_stop_scan_syncro(struct rtllib_device *ieee);
2764extern void rtllib_start_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
2765extern void rtllib_sta_ps_send_null_frame(struct rtllib_device *ieee,
2766                                          short pwr);
2767extern void rtllib_sta_wakeup(struct rtllib_device *ieee, short nl);
2768extern void rtllib_sta_ps_send_pspoll_frame(struct rtllib_device *ieee);
2769extern void rtllib_check_all_nets(struct rtllib_device *ieee);
2770extern void rtllib_start_protocol(struct rtllib_device *ieee);
2771extern void rtllib_stop_protocol(struct rtllib_device *ieee, u8 shutdown);
2772
2773extern void rtllib_EnableNetMonitorMode(struct net_device *dev,
2774                                        bool bInitState);
2775extern void rtllib_DisableNetMonitorMode(struct net_device *dev,
2776                                         bool bInitState);
2777extern void rtllib_EnableIntelPromiscuousMode(struct net_device *dev,
2778                                              bool bInitState);
2779extern void rtllib_DisableIntelPromiscuousMode(struct net_device *dev,
2780                                               bool bInitState);
2781extern void rtllib_send_probe_requests(struct rtllib_device *ieee, u8 is_mesh);
2782
2783extern void rtllib_softmac_stop_protocol(struct rtllib_device *ieee,
2784                                         u8 mesh_flag, u8 shutdown);
2785extern void rtllib_softmac_start_protocol(struct rtllib_device *ieee,
2786                                          u8 mesh_flag);
2787
2788extern void rtllib_reset_queue(struct rtllib_device *ieee);
2789extern void rtllib_wake_queue(struct rtllib_device *ieee);
2790extern void rtllib_stop_queue(struct rtllib_device *ieee);
2791extern void rtllib_wake_all_queues(struct rtllib_device *ieee);
2792extern void rtllib_stop_all_queues(struct rtllib_device *ieee);
2793extern struct sk_buff *rtllib_get_beacon(struct rtllib_device *ieee);
2794extern void rtllib_start_send_beacons(struct rtllib_device *ieee);
2795extern void rtllib_stop_send_beacons(struct rtllib_device *ieee);
2796extern int rtllib_wpa_supplicant_ioctl(struct rtllib_device *ieee,
2797                                       struct iw_point *p, u8 is_mesh);
2798
2799extern void notify_wx_assoc_event(struct rtllib_device *ieee);
2800extern void rtllib_ps_tx_ack(struct rtllib_device *ieee, short success);
2801
2802extern void softmac_mgmt_xmit(struct sk_buff *skb,
2803                              struct rtllib_device *ieee);
2804extern u16 rtllib_query_seqnum(struct rtllib_device *ieee,
2805                               struct sk_buff *skb, u8 *dst);
2806extern u8 rtllib_ap_sec_type(struct rtllib_device *ieee);
2807
2808/* rtllib_crypt_ccmp&tkip&wep.c */
2809extern void rtllib_tkip_null(void);
2810extern void rtllib_wep_null(void);
2811extern void rtllib_ccmp_null(void);
2812
2813/* rtllib_softmac_wx.c */
2814
2815extern int rtllib_wx_get_wap(struct rtllib_device *ieee,
2816                             struct iw_request_info *info,
2817                             union iwreq_data *wrqu, char *ext);
2818
2819extern int rtllib_wx_set_wap(struct rtllib_device *ieee,
2820                             struct iw_request_info *info,
2821                             union iwreq_data *awrq,
2822                             char *extra);
2823
2824extern int rtllib_wx_get_essid(struct rtllib_device *ieee,
2825                               struct iw_request_info *a,
2826                               union iwreq_data *wrqu, char *b);
2827
2828extern int rtllib_wx_set_rate(struct rtllib_device *ieee,
2829                              struct iw_request_info *info,
2830                              union iwreq_data *wrqu, char *extra);
2831
2832extern int rtllib_wx_get_rate(struct rtllib_device *ieee,
2833                              struct iw_request_info *info,
2834                              union iwreq_data *wrqu, char *extra);
2835
2836extern int rtllib_wx_set_mode(struct rtllib_device *ieee,
2837                              struct iw_request_info *a,
2838                              union iwreq_data *wrqu, char *b);
2839
2840extern int rtllib_wx_set_scan(struct rtllib_device *ieee,
2841                              struct iw_request_info *a,
2842                              union iwreq_data *wrqu, char *b);
2843
2844extern int rtllib_wx_set_essid(struct rtllib_device *ieee,
2845                              struct iw_request_info *a,
2846                              union iwreq_data *wrqu, char *extra);
2847
2848extern int rtllib_wx_get_mode(struct rtllib_device *ieee,
2849                              struct iw_request_info *a,
2850                              union iwreq_data *wrqu, char *b);
2851
2852extern int rtllib_wx_set_freq(struct rtllib_device *ieee,
2853                              struct iw_request_info *a,
2854                              union iwreq_data *wrqu, char *b);
2855
2856extern int rtllib_wx_get_freq(struct rtllib_device *ieee,
2857                              struct iw_request_info *a,
2858                              union iwreq_data *wrqu, char *b);
2859extern void rtllib_wx_sync_scan_wq(void *data);
2860
2861extern int rtllib_wx_set_rawtx(struct rtllib_device *ieee,
2862                               struct iw_request_info *info,
2863                               union iwreq_data *wrqu, char *extra);
2864
2865extern int rtllib_wx_get_name(struct rtllib_device *ieee,
2866                             struct iw_request_info *info,
2867                             union iwreq_data *wrqu, char *extra);
2868
2869extern int rtllib_wx_set_power(struct rtllib_device *ieee,
2870                                 struct iw_request_info *info,
2871                                 union iwreq_data *wrqu, char *extra);
2872
2873extern int rtllib_wx_get_power(struct rtllib_device *ieee,
2874                                 struct iw_request_info *info,
2875                                 union iwreq_data *wrqu, char *extra);
2876
2877extern int rtllib_wx_set_rts(struct rtllib_device *ieee,
2878                             struct iw_request_info *info,
2879                             union iwreq_data *wrqu, char *extra);
2880
2881extern int rtllib_wx_get_rts(struct rtllib_device *ieee,
2882                             struct iw_request_info *info,
2883                             union iwreq_data *wrqu, char *extra);
2884#define MAX_RECEIVE_BUFFER_SIZE 9100
2885extern void HTDebugHTCapability(u8 *CapIE, u8 *TitleString);
2886extern void HTDebugHTInfo(u8 *InfoIE, u8 *TitleString);
2887
2888void HTSetConnectBwMode(struct rtllib_device *ieee,
2889                        enum ht_channel_width Bandwidth,
2890                        enum ht_extchnl_offset Offset);
2891extern void HTUpdateDefaultSetting(struct rtllib_device *ieee);
2892extern void HTConstructCapabilityElement(struct rtllib_device *ieee,
2893                                         u8 *posHTCap, u8 *len,
2894                                         u8 isEncrypt, bool bAssoc);
2895extern void HTConstructInfoElement(struct rtllib_device *ieee,
2896                                   u8 *posHTInfo, u8 *len, u8 isEncrypt);
2897extern void HTConstructRT2RTAggElement(struct rtllib_device *ieee,
2898                                       u8 *posRT2RTAgg, u8 *len);
2899extern void HTOnAssocRsp(struct rtllib_device *ieee);
2900extern void HTInitializeHTInfo(struct rtllib_device *ieee);
2901extern void HTInitializeBssDesc(struct bss_ht *pBssHT);
2902extern void HTResetSelfAndSavePeerSetting(struct rtllib_device *ieee,
2903                                          struct rtllib_network *pNetwork);
2904extern void HT_update_self_and_peer_setting(struct rtllib_device *ieee,
2905                                            struct rtllib_network *pNetwork);
2906extern u8 HTGetHighestMCSRate(struct rtllib_device *ieee, u8 *pMCSRateSet,
2907                              u8 *pMCSFilter);
2908extern u8 MCS_FILTER_ALL[];
2909extern u16 MCS_DATA_RATE[2][2][77] ;
2910extern u8 HTCCheck(struct rtllib_device *ieee, u8 *pFrame);
2911extern void HTResetIOTSetting(struct rt_hi_throughput *pHTInfo);
2912extern bool IsHTHalfNmodeAPs(struct rtllib_device *ieee);
2913extern u16 HTHalfMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate);
2914extern u16 HTMcsToDataRate(struct rtllib_device *ieee, u8 nMcsRate);
2915extern u16  TxCountToDataRate(struct rtllib_device *ieee, u8 nDataRate);
2916extern int rtllib_rx_ADDBAReq(struct rtllib_device *ieee, struct sk_buff *skb);
2917extern int rtllib_rx_ADDBARsp(struct rtllib_device *ieee, struct sk_buff *skb);
2918extern int rtllib_rx_DELBA(struct rtllib_device *ieee, struct sk_buff *skb);
2919extern void TsInitAddBA(struct rtllib_device *ieee, struct tx_ts_record *pTS,
2920                        u8 Policy, u8 bOverwritePending);
2921extern void TsInitDelBA(struct rtllib_device *ieee,
2922                        struct ts_common_info *pTsCommonInfo,
2923                        enum tr_select TxRxSelect);
2924extern void BaSetupTimeOut(unsigned long data);
2925extern void TxBaInactTimeout(unsigned long data);
2926extern void RxBaInactTimeout(unsigned long data);
2927extern void ResetBaEntry(struct ba_record *pBA);
2928extern bool GetTs(
2929        struct rtllib_device *ieee,
2930        struct ts_common_info **ppTS,
2931        u8 *Addr,
2932        u8 TID,
2933        enum tr_select TxRxSelect,
2934        bool bAddNewTs
2935);
2936extern void TSInitialize(struct rtllib_device *ieee);
2937extern  void TsStartAddBaProcess(struct rtllib_device *ieee,
2938                                  struct tx_ts_record *pTxTS);
2939extern void RemovePeerTS(struct rtllib_device *ieee, u8 *Addr);
2940extern void RemoveAllTS(struct rtllib_device *ieee);
2941void rtllib_softmac_scan_syncro(struct rtllib_device *ieee, u8 is_mesh);
2942
2943extern const long rtllib_wlan_frequencies[];
2944
2945static inline void rtllib_increment_scans(struct rtllib_device *ieee)
2946{
2947        ieee->scans++;
2948}
2949
2950static inline int rtllib_get_scans(struct rtllib_device *ieee)
2951{
2952        return ieee->scans;
2953}
2954
2955static inline const char *escape_essid(const char *essid, u8 essid_len)
2956{
2957        static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
2958
2959        if (rtllib_is_empty_essid(essid, essid_len)) {
2960                memcpy(escaped, "<hidden>", sizeof("<hidden>"));
2961                return escaped;
2962        }
2963
2964        snprintf(escaped, sizeof(escaped), "%*pEn", essid_len, essid);
2965        return escaped;
2966}
2967
2968#define CONVERT_RATE(_ieee, _MGN_RATE)                  \
2969        ((_MGN_RATE < MGN_MCS0) ? (_MGN_RATE) :         \
2970        (HTMcsToDataRate(_ieee, (u8)_MGN_RATE)))
2971
2972/* fun with the built-in rtllib stack... */
2973bool rtllib_MgntDisconnect(struct rtllib_device *rtllib, u8 asRsn);
2974
2975
2976/* For the function is more related to hardware setting, it's better to use the
2977 * ieee handler to refer to it.
2978 */
2979extern void rtllib_update_active_chan_map(struct rtllib_device *ieee);
2980extern void rtllib_FlushRxTsPendingPkts(struct rtllib_device *ieee,
2981                                        struct rx_ts_record *pTS);
2982extern int rtllib_data_xmit(struct sk_buff *skb, struct net_device *dev);
2983extern int rtllib_parse_info_param(struct rtllib_device *ieee,
2984                struct rtllib_info_element *info_element,
2985                u16 length,
2986                struct rtllib_network *network,
2987                struct rtllib_rx_stats *stats);
2988
2989void rtllib_indicate_packets(struct rtllib_device *ieee,
2990                             struct rtllib_rxb **prxbIndicateArray, u8  index);
2991extern u8 HTFilterMCSRate(struct rtllib_device *ieee, u8 *pSupportMCS,
2992                          u8 *pOperateMCS);
2993extern void HTUseDefaultSetting(struct rtllib_device *ieee);
2994#define RT_ASOC_RETRY_LIMIT     5
2995u8 MgntQuery_TxRateExcludeCCKRates(struct rtllib_device *ieee);
2996extern void rtllib_TURBO_Info(struct rtllib_device *ieee, u8 **tag_p);
2997#ifndef ENABLE_LOCK_DEBUG
2998#define SPIN_LOCK_IEEE(plock) spin_lock_irqsave((plock), flags)
2999#define SPIN_UNLOCK_IEEE(plock) spin_unlock_irqrestore((plock), flags)
3000#define SPIN_LOCK_IEEE_REORDER(plock) spin_lock_irqsave((plock), flags)
3001#define SPIN_UNLOCK_IEEE_REORDER(plock) spin_unlock_irqrestore((plock), flags)
3002#define SPIN_LOCK_IEEE_WPAX(plock) spin_lock_irqsave((plock), flags)
3003#define SPIN_UNLOCK_IEEE_WPAX(plock) spin_unlock_irqrestore((plock), flags)
3004#define SPIN_LOCK_IEEE_MGNTTX(plock) spin_lock_irqsave((plock), flags)
3005#define SPIN_UNLOCK_IEEE_MGNTTX(plock) spin_unlock_irqrestore((plock), flags)
3006#define SPIN_LOCK_IEEE_BCN(plock) spin_lock_irqsave((plock), flags)
3007#define SPIN_UNLOCK_IEEE_BCN(plock) spin_unlock_irqrestore((plock), flags)
3008#define SPIN_LOCK_MSH_STAINFO(plock) spin_lock_irqsave((plock), flags)
3009#define SPIN_UNLOCK_MSH_STAINFO(plock) spin_unlock_irqrestore((plock), flags)
3010#define SPIN_LOCK_MSH_PREQ(plock) spin_lock_irqsave((plock), flags)
3011#define SPIN_UNLOCK_MSH_PREQ(plock) spin_unlock_irqrestore((plock), flags)
3012#define SPIN_LOCK_MSH_QUEUE(plock) spin_lock_irqsave((plock), flags)
3013#define SPIN_UNLOCK_MSH_QUEUE(plock) spin_unlock_irqrestore((plock), flags)
3014#define SPIN_LOCK_PRIV_RFPS(plock) spin_lock_irqsave((plock), flags)
3015#define SPIN_UNLOCK_PRIV_RFPS(plock) spin_unlock_irqrestore((plock), flags)
3016#define SPIN_LOCK_PRIV_IRQTH(plock) spin_lock_irqsave((plock), flags)
3017#define SPIN_UNLOCK_PRIV_IRQTH(plock) spin_unlock_irqrestore((plock), flags)
3018#define SPIN_LOCK_PRIV_TX(plock) spin_lock_irqsave((plock), flags)
3019#define SPIN_UNLOCK_PRIV_TX(plock) spin_unlock_irqrestore((plock), flags)
3020#define SPIN_LOCK_PRIV_D3(plock) spin_lock_irqsave((plock), flags)
3021#define SPIN_UNLOCK_PRIV_D3(plock) spin_unlock_irqrestore((plock), flags)
3022#define SPIN_LOCK_PRIV_RF(plock) spin_lock_irqsave((plock), flags)
3023#define SPIN_UNLOCK_PRIV_RF(plock) spin_unlock_irqrestore((plock), flags)
3024#define SPIN_LOCK_PRIV_PS(plock) spin_lock_irqsave((plock), flags)
3025#define SPIN_UNLOCK_PRIV_PS(plock) spin_unlock_irqrestore((plock), flags)
3026#define SEM_DOWN_IEEE_WX(psem) down(psem)
3027#define SEM_UP_IEEE_WX(psem) up(psem)
3028#define SEM_DOWN_IEEE_SCAN(psem) down(psem)
3029#define SEM_UP_IEEE_SCAN(psem) up(psem)
3030#define SEM_DOWN_IEEE_IPS(psem) down(psem)
3031#define SEM_UP_IEEE_IPS(psem) up(psem)
3032#define SEM_DOWN_PRIV_WX(psem) down(psem)
3033#define SEM_UP_PRIV_WX(psem) up(psem)
3034#define SEM_DOWN_PRIV_RF(psem) down(psem)
3035#define SEM_UP_PRIV_RF(psem) up(psem)
3036#define MUTEX_LOCK_PRIV(pmutex) mutex_lock(pmutex)
3037#define MUTEX_UNLOCK_PRIV(pmutex) mutex_unlock(pmutex)
3038#endif
3039
3040#endif /* RTLLIB_H */
3041