Staging: vt6656: remove dependency on kernel version
[firefly-linux-kernel-4.4.55.git] / drivers / staging / vt6656 / device.h
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * File: device.h
20  *
21  * Purpose: MAC Data structure
22  *
23  * Author: Tevin Chen
24  *
25  * Date: Mar 17, 1997
26  *
27  */
28
29 #ifndef __DEVICE_H__
30 #define __DEVICE_H__
31
32 #ifdef MODULE
33 #ifdef MODVERSIONS
34 #include <linux/modversions.h>
35 #endif /* MODVERSIONS */
36 #include <linux/module.h>
37 #endif /* MODULE */
38
39 #include <linux/types.h>
40 #include <linux/init.h>
41 #include <linux/mm.h>
42 #include <linux/errno.h>
43 #include <linux/ioport.h>
44 #include <linux/pci.h>
45 #include <linux/kernel.h>
46 #include <linux/netdevice.h>
47 #include <linux/etherdevice.h>
48 #include <linux/skbuff.h>
49 #include <linux/delay.h>
50 #include <linux/timer.h>
51 #include <linux/slab.h>
52 #include <linux/interrupt.h>
53 #include <linux/version.h>
54 #include <linux/string.h>
55 #include <linux/wait.h>
56 #include <linux/if_arp.h>
57 #include <linux/sched.h>
58 #include <linux/if.h>
59 #include <linux/rtnetlink.h>//James
60 #include <linux/proc_fs.h>
61 #include <linux/inetdevice.h>
62 #include <linux/reboot.h>
63 #include <linux/usb.h>
64 #include <linux/signal.h>
65 #include <asm/io.h>
66 #include <asm/uaccess.h>
67 #ifdef SIOCETHTOOL
68 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
69 #include <linux/ethtool.h>
70 #else
71 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
72 #endif
73 /* Include Wireless Extension definition and check version - Jean II */
74 #include <linux/wireless.h>
75 #if WIRELESS_EXT > 12
76 #include <net/iw_handler.h>     // New driver API
77 #endif  /* WIRELESS_EXT > 12 */
78
79 //2008-0409-07, <Add> by Einsn Liu
80 #if WIRELESS_EXT > 17
81 #ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
82 #define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
83 #endif
84 #endif
85
86 //2007-0920-01<Add>by MikeLiu
87 #ifndef SndEvt_ToAPI
88 #define SndEvt_ToAPI
89 //please copy below macro to driver_event.c for API
90 #define RT_INSMOD_EVENT_FLAG                             0x0101
91 #define RT_UPDEV_EVENT_FLAG                               0x0102
92 #define RT_DISCONNECTED_EVENT_FLAG               0x0103
93 #define RT_WPACONNECTED_EVENT_FLAG             0x0104
94 #define RT_DOWNDEV_EVENT_FLAG                        0x0105
95 #define RT_RMMOD_EVENT_FLAG                              0x0106
96 #endif
97
98 //
99 // device specific
100 //
101
102 #if !defined(_KCOMPAT_H)
103 #include "kcompat.h"
104 #endif
105
106 #if !defined(__DEVICE_CONFIG_H)
107 #include "device_cfg.h"
108 #endif
109
110 #if !defined(__TTYPE_H__)
111 #include "ttype.h"
112 #endif
113 #if !defined(__80211HDR_H__)
114 #include "80211hdr.h"
115 #endif
116 #if !defined(__TETHER_H__)
117 #include "tether.h"
118 #endif
119 #if !defined(__WMGR_H__)
120 #include "wmgr.h"
121 #endif
122 #if !defined(__WCMD_H__)
123 #include "wcmd.h"
124 #endif
125 #if !defined(__MIB_H__)
126 #include "mib.h"
127 #endif
128 #if !defined(__SROM_H__)
129 #include "srom.h"
130 #endif
131 #if !defined(__RC4_H__)
132 #include "rc4.h"
133 #endif
134 #if !defined(__TPCI_H__)
135 #include "tpci.h"
136 #endif
137 #if !defined(__DESC_H__)
138 #include "desc.h"
139 #endif
140 #if !defined(__KEY_H__)
141 #include "key.h"
142 #endif
143 #if !defined(__CARD_H__)
144 #include "card.h"
145 #endif
146
147 /*---------------------  Export Definitions -------------------------*/
148 #define VNT_USB_VENDOR_ID                     0x160A
149 #define VNT_USB_PRODUCT_ID                    0x3184
150
151 #define MAC_MAX_CONTEXT_REG     (256+128)
152
153 #define MAX_MULTICAST_ADDRESS_NUM       32
154 #define MULTICAST_ADDRESS_LIST_SIZE     (MAX_MULTICAST_ADDRESS_NUM * U_ETHER_ADDR_LEN)
155
156
157 //#define OP_MODE_INFRASTRUCTURE  0
158 //#define OP_MODE_ADHOC           1
159 //#define OP_MODE_AP              2
160
161 #define DUPLICATE_RX_CACHE_LENGTH       5
162
163 #define NUM_KEY_ENTRY                   11
164
165 #define TX_WEP_NONE                     0
166 #define TX_WEP_OTF                      1
167 #define TX_WEP_SW                       2
168 #define TX_WEP_SWOTP                    3
169 #define TX_WEP_OTPSW                    4
170 #define TX_WEP_SW232                    5
171
172 #define KEYSEL_WEP40                    0
173 #define KEYSEL_WEP104                   1
174 #define KEYSEL_TKIP                     2
175 #define KEYSEL_CCMP                     3
176
177
178
179 #define AUTO_FB_NONE            0
180 #define AUTO_FB_0               1
181 #define AUTO_FB_1               2
182
183 #define FB_RATE0                0
184 #define FB_RATE1                1
185
186 // Antenna Mode
187 #define ANT_A                   0
188 #define ANT_B                   1
189 #define ANT_DIVERSITY           2
190 #define ANT_RXD_TXA             3
191 #define ANT_RXD_TXB             4
192 #define ANT_UNKNOWN             0xFF
193 #define ANT_TXA                 0
194 #define ANT_TXB                 1
195 #define ANT_RXA                 2
196 #define ANT_RXB                 3
197
198
199 #define MAXCHECKHANGCNT         4
200
201 //Packet type
202 #define TX_PKT_UNI              0x00
203 #define TX_PKT_MULTI            0x01
204 #define TX_PKT_BROAD            0x02
205
206 #define BB_VGA_LEVEL            4
207 #define BB_VGA_CHANGE_THRESHOLD 3
208
209
210
211 #ifndef RUN_AT
212 #define RUN_AT(x)                       (jiffies+(x))
213 #endif
214
215 // DMA related
216 #define RESERV_AC0DMA                   4
217
218 #define PRIVATE_Message                 0
219
220 /*---------------------  Export Types  ------------------------------*/
221
222 #define DBG_PRT(l, p, args...) {if (l<=msglevel) printk( p ,##args);}
223 #define PRINT_K(p, args...) {if (PRIVATE_Message) printk( p ,##args);}
224
225 typedef enum __device_msg_level {
226     MSG_LEVEL_ERR=0,            //Errors that will cause abnormal operation.
227     MSG_LEVEL_NOTICE=1,         //Some errors need users to be notified.
228     MSG_LEVEL_INFO=2,           //Normal message.
229     MSG_LEVEL_VERBOSE=3,        //Will report all trival errors.
230     MSG_LEVEL_DEBUG=4           //Only for debug purpose.
231 } DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
232
233 typedef enum __device_init_type {
234     DEVICE_INIT_COLD=0,         // cold init
235     DEVICE_INIT_RESET,          // reset init or Dx to D0 power remain init
236     DEVICE_INIT_DXPL            // Dx to D0 power lost init
237 } DEVICE_INIT_TYPE, *PDEVICE_INIT_TYPE;
238
239
240 //USB
241
242 //
243 // Enum of context types for SendPacket
244 //
245 typedef enum _CONTEXT_TYPE {
246     CONTEXT_DATA_PACKET = 1,
247     CONTEXT_MGMT_PACKET
248 } CONTEXT_TYPE;
249
250
251
252
253 // RCB (Receive Control Block)
254 typedef struct _RCB
255 {
256     PVOID                   Next;
257     LONG                    Ref;
258     PVOID                   pDevice;
259     struct urb              *pUrb;
260     SRxMgmtPacket           sMngPacket;
261     struct sk_buff*         skb;
262     BOOL                    bBoolInUse;
263
264 } RCB, *PRCB;
265
266
267 // used to track bulk out irps
268 typedef struct _USB_SEND_CONTEXT {
269     PVOID           pDevice;
270     struct sk_buff *pPacket;
271     struct urb      *pUrb;
272     UINT            uBufLen;
273     CONTEXT_TYPE    Type;
274     SEthernetHeader sEthHeader;
275     PVOID           Next;
276     BOOL            bBoolInUse;
277     UCHAR           Data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
278 } USB_SEND_CONTEXT, *PUSB_SEND_CONTEXT;
279
280
281 //structure got from configuration file as user desired default setting.
282 typedef struct _DEFAULT_CONFIG{
283     INT    ZoneType;
284     INT    eConfigMode;
285     INT    eAuthenMode;    //open/wep/wpa
286     INT    bShareKeyAlgorithm;  //open-open/open-sharekey/wep-sharekey
287     INT    keyidx;               //wepkey index
288     INT    eEncryptionStatus;
289
290 }DEFAULT_CONFIG,*PDEFAULT_CONFIG;
291
292 //
293 // Structure to keep track of usb interrupt packets
294 //
295 typedef struct {
296     UINT            uDataLen;
297     PBYTE           pDataBuf;
298 //    struct urb      *pUrb;
299     BOOL            bInUse;
300 } INT_BUFFER, *PINT_BUFFER;
301
302
303
304 //0:11A 1:11B 2:11G
305 typedef enum _VIA_BB_TYPE
306 {
307     BB_TYPE_11A=0,
308     BB_TYPE_11B,
309     BB_TYPE_11G
310 } VIA_BB_TYPE, *PVIA_BB_TYPE;
311
312 //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
313 typedef enum _VIA_PKT_TYPE
314 {
315     PK_TYPE_11A=0,
316     PK_TYPE_11B,
317     PK_TYPE_11GB,
318     PK_TYPE_11GA
319 } VIA_PKT_TYPE, *PVIA_PKT_TYPE;
320
321
322
323
324 //++ NDIS related
325
326 #define NDIS_STATUS     int
327 #define NTSTATUS        int
328
329 typedef enum __DEVICE_NDIS_STATUS {
330     STATUS_SUCCESS=0,
331     STATUS_FAILURE,
332     STATUS_RESOURCES,
333     STATUS_PENDING,
334 } DEVICE_NDIS_STATUS, *PDEVICE_NDIS_STATUS;
335
336
337 #define MAX_BSSIDINFO_4_PMKID   16
338 #define MAX_PMKIDLIST           5
339 //Flags for PMKID Candidate list structure
340 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED     0x01
341
342 // PMKID Structures
343 typedef UCHAR   NDIS_802_11_PMKID_VALUE[16];
344
345
346 typedef enum _NDIS_802_11_WEP_STATUS
347 {
348     Ndis802_11WEPEnabled,
349     Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
350     Ndis802_11WEPDisabled,
351     Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
352     Ndis802_11WEPKeyAbsent,
353     Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
354     Ndis802_11WEPNotSupported,
355     Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
356     Ndis802_11Encryption2Enabled,
357     Ndis802_11Encryption2KeyAbsent,
358     Ndis802_11Encryption3Enabled,
359     Ndis802_11Encryption3KeyAbsent
360 } NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
361   NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
362
363
364 typedef enum _NDIS_802_11_STATUS_TYPE
365 {
366     Ndis802_11StatusType_Authentication,
367     Ndis802_11StatusType_MediaStreamMode,
368     Ndis802_11StatusType_PMKID_CandidateList,
369     Ndis802_11StatusTypeMax    // not a real type, defined as an upper bound
370 } NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
371
372 //Added new types for PMKID Candidate lists.
373 typedef struct _PMKID_CANDIDATE {
374     NDIS_802_11_MAC_ADDRESS BSSID;
375     ULONG Flags;
376 } PMKID_CANDIDATE, *PPMKID_CANDIDATE;
377
378
379 typedef struct _BSSID_INFO
380 {
381     NDIS_802_11_MAC_ADDRESS BSSID;
382     NDIS_802_11_PMKID_VALUE PMKID;
383 } BSSID_INFO, *PBSSID_INFO;
384
385 typedef struct tagSPMKID {
386     ULONG Length;
387     ULONG BSSIDInfoCount;
388     BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
389 } SPMKID, *PSPMKID;
390
391 typedef struct tagSPMKIDCandidateEvent {
392     NDIS_802_11_STATUS_TYPE     StatusType;
393     ULONG Version;       // Version of the structure
394     ULONG NumCandidates; // No. of pmkid candidates
395     PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST];
396 } SPMKIDCandidateEvent, DEF* PSPMKIDCandidateEvent;
397
398 //--
399
400 //++ 802.11h related
401 #define MAX_QUIET_COUNT     8
402
403 typedef struct tagSQuietControl {
404     BOOL        bEnable;
405     DWORD       dwStartTime;
406     BYTE        byPeriod;
407     WORD        wDuration;
408 } SQuietControl, DEF* PSQuietControl;
409
410 //--
411
412
413 // The receive duplicate detection cache entry
414 typedef struct tagSCacheEntry{
415     WORD        wFmSequence;
416     BYTE        abyAddr2[U_ETHER_ADDR_LEN];
417     WORD        wFrameCtl;
418 } SCacheEntry, *PSCacheEntry;
419
420 typedef struct tagSCache{
421 /* The receive cache is updated circularly.  The next entry to be written is
422  * indexed by the "InPtr".
423 */
424     UINT            uInPtr;         // Place to use next
425     SCacheEntry     asCacheEntry[DUPLICATE_RX_CACHE_LENGTH];
426 } SCache, *PSCache;
427
428 #define CB_MAX_RX_FRAG                 64
429 // DeFragment Control Block, used for collecting fragments prior to reassembly
430 typedef struct tagSDeFragControlBlock
431 {
432     WORD            wSequence;
433     WORD            wFragNum;
434     BYTE            abyAddr2[U_ETHER_ADDR_LEN];
435         UINT            uLifetime;
436     struct sk_buff* skb;
437     PBYTE           pbyRxBuffer;
438     UINT            cbFrameLength;
439     BOOL            bInUse;
440 } SDeFragControlBlock, DEF* PSDeFragControlBlock;
441
442
443
444 //flags for options
445 #define     DEVICE_FLAGS_UNPLUG          0x00000001UL
446 #define     DEVICE_FLAGS_PREAMBLE_TYPE   0x00000002UL
447 #define     DEVICE_FLAGS_OP_MODE         0x00000004UL
448 #define     DEVICE_FLAGS_PS_MODE         0x00000008UL
449 #define         DEVICE_FLAGS_80211h_MODE         0x00000010UL
450
451 //flags for driver status
452 #define     DEVICE_FLAGS_OPENED          0x00010000UL
453 #define     DEVICE_FLAGS_WOL_ENABLED     0x00080000UL
454 //flags for capbilities
455 #define     DEVICE_FLAGS_TX_ALIGN        0x01000000UL
456 #define     DEVICE_FLAGS_HAVE_CAM        0x02000000UL
457 #define     DEVICE_FLAGS_FLOW_CTRL       0x04000000UL
458
459 //flags for MII status
460 #define     DEVICE_LINK_FAIL             0x00000001UL
461 #define     DEVICE_SPEED_10              0x00000002UL
462 #define     DEVICE_SPEED_100             0x00000004UL
463 #define     DEVICE_SPEED_1000            0x00000008UL
464 #define     DEVICE_DUPLEX_FULL           0x00000010UL
465 #define     DEVICE_AUTONEG_ENABLE        0x00000020UL
466 #define     DEVICE_FORCED_BY_EEPROM      0x00000040UL
467 //for device_set_media_duplex
468 #define     DEVICE_LINK_CHANGE           0x00000001UL
469
470
471 typedef struct __device_opt {
472     int         nRxDescs0;    //Number of RX descriptors0
473     int         nTxDescs0;    //Number of TX descriptors 0, 1, 2, 3
474     int         rts_thresh;   //rts threshold
475     int         frag_thresh;
476     int         OpMode;
477     int         data_rate;
478     int         channel_num;
479     int         short_retry;
480     int         long_retry;
481     int         bbp_type;
482     U32         flags;
483 } OPTIONS, *POPTIONS;
484
485
486 typedef struct __device_info {
487
488 // netdev
489         struct usb_device*          usb;
490     struct net_device*          dev;
491     struct net_device_stats     stats;
492
493     OPTIONS                     sOpts;
494
495         struct tasklet_struct       CmdWorkItem;
496         struct tasklet_struct       EventWorkItem;
497         struct tasklet_struct       ReadWorkItem;
498         struct tasklet_struct       RxMngWorkItem;
499
500     U32                         rx_buf_sz;
501     int                         multicast_limit;
502     BYTE                        byRxMode;
503
504     spinlock_t                  lock;
505
506     U32                         rx_bytes;
507
508     BYTE                        byRevId;
509
510     U32                         flags;
511     ULONG                       Flags;
512
513     SCache                      sDupRxCache;
514
515     SDeFragControlBlock         sRxDFCB[CB_MAX_RX_FRAG];
516     UINT                        cbDFCB;
517     UINT                        cbFreeDFCB;
518     UINT                        uCurrentDFCBIdx;
519
520     // +++USB
521
522     struct urb                  *pControlURB;
523     struct urb                  *pInterruptURB;
524         struct usb_ctrlrequest      sUsbCtlRequest;
525
526     UINT                        int_interval;
527     //
528     // Variables to track resources for the BULK In Pipe
529     //
530     PRCB                        pRCBMem;
531     PRCB                        apRCB[CB_MAX_RX_DESC];
532     UINT                        cbRD;
533     PRCB                        FirstRecvFreeList;
534     PRCB                        LastRecvFreeList;
535     UINT                        NumRecvFreeList;
536     PRCB                        FirstRecvMngList;
537     PRCB                        LastRecvMngList;
538     UINT                        NumRecvMngList;
539     BOOL                        bIsRxWorkItemQueued;
540     BOOL                        bIsRxMngWorkItemQueued;
541     ULONG                       ulRcvRefCount;      // number of packets that have not been returned back
542
543     //
544     //  Variables to track resources for the BULK Out Pipe
545     //
546
547     PUSB_SEND_CONTEXT           apTD[CB_MAX_TX_DESC];
548     UINT                        cbTD;
549
550     //
551     //  Variables to track resources for the Interript In Pipe
552     //
553     INT_BUFFER                  intBuf;
554     BOOL                        fKillEventPollingThread;
555     BOOL                        bEventAvailable;
556
557
558   //default config from file by user setting
559     DEFAULT_CONFIG    config_file;
560
561
562     //
563     // Statistic for USB
564     // protect with spinlock
565     ULONG                       ulBulkInPosted;
566     ULONG                       ulBulkInError;
567     ULONG                       ulBulkInContCRCError;
568     ULONG                       ulBulkInBytesRead;
569
570     ULONG                       ulBulkOutPosted;
571     ULONG                       ulBulkOutError;
572     ULONG                       ulBulkOutContCRCError;
573     ULONG                       ulBulkOutBytesWrite;
574
575     ULONG                       ulIntInPosted;
576     ULONG                       ulIntInError;
577     ULONG                       ulIntInContCRCError;
578     ULONG                       ulIntInBytesRead;
579
580
581     // Version control
582     WORD                        wFirmwareVersion;
583     BYTE                        byLocalID;
584     BYTE                        byRFType;
585     BYTE                        byBBRxConf;
586
587
588     BYTE                        byZoneType;
589     BOOL                        bZoneRegExist;
590
591     BYTE                        byOriginalZonetype;
592
593     BOOL                        bLinkPass;          // link status: OK or fail
594     BYTE                        abyCurrentNetAddr[U_ETHER_ADDR_LEN];
595     BYTE                        abyPermanentNetAddr[U_ETHER_ADDR_LEN];
596     // SW network address
597 //    BYTE                        abySoftwareNetAddr[U_ETHER_ADDR_LEN];
598     BOOL                        bExistSWNetAddr;
599
600     // Adapter statistics
601     SStatCounter                scStatistic;
602     // 802.11 counter
603     SDot11Counters              s802_11Counter;
604
605     //
606     // Maintain statistical debug info.
607     //
608     ULONG                       packetsReceived;
609     ULONG                       packetsReceivedDropped;
610     ULONG                       packetsReceivedOverflow;
611     ULONG                       packetsSent;
612     ULONG                       packetsSentDropped;
613     ULONG                       SendContextsInUse;
614     ULONG                       RcvBuffersInUse;
615
616
617     // 802.11 management
618     SMgmtObject                 sMgmtObj;
619
620     QWORD                       qwCurrTSF;
621     UINT                        cbBulkInMax;
622     BOOL                        bPSRxBeacon;
623
624     // 802.11 MAC specific
625     UINT                        uCurrRSSI;
626     BYTE                        byCurrSQ;
627
628
629     //Antenna Diversity
630     BOOL                        bTxRxAntInv;
631     DWORD                       dwRxAntennaSel;
632     DWORD                       dwTxAntennaSel;
633     BYTE                        byAntennaCount;
634     BYTE                        byRxAntennaMode;
635     BYTE                        byTxAntennaMode;
636     BYTE                        byRadioCtl;
637     BYTE                        bHWRadioOff;
638
639     //SQ3 functions for antenna diversity
640     struct timer_list           TimerSQ3Tmax1;
641     struct timer_list           TimerSQ3Tmax2;
642     struct timer_list           TimerSQ3Tmax3;
643
644     BOOL                        bDiversityRegCtlON;
645     BOOL                        bDiversityEnable;
646     ULONG                       ulDiversityNValue;
647     ULONG                       ulDiversityMValue;
648     BYTE                        byTMax;
649     BYTE                        byTMax2;
650     BYTE                        byTMax3;
651     ULONG                       ulSQ3TH;
652
653     ULONG                       uDiversityCnt;
654     BYTE                        byAntennaState;
655     ULONG                       ulRatio_State0;
656     ULONG                       ulRatio_State1;
657     ULONG                       ulSQ3_State0;
658     ULONG                       ulSQ3_State1;
659
660     ULONG                       aulSQ3Val[MAX_RATE];
661     ULONG                       aulPktNum[MAX_RATE];
662
663     // IFS & Cw
664     UINT                        uSIFS;    //Current SIFS
665     UINT                        uDIFS;    //Current DIFS
666     UINT                        uEIFS;    //Current EIFS
667     UINT                        uSlot;    //Current SlotTime
668     UINT                        uCwMin;   //Current CwMin
669     UINT                        uCwMax;   //CwMax is fixed on 1023.
670     // PHY parameter
671     BYTE                        bySIFS;
672     BYTE                        byDIFS;
673     BYTE                        byEIFS;
674     BYTE                        bySlot;
675     BYTE                        byCWMaxMin;
676
677     // Rate
678     VIA_BB_TYPE                 byBBType; //0: 11A, 1:11B, 2:11G
679     VIA_PKT_TYPE                byPacketType; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
680     WORD                        wBasicRate;
681     BYTE                        byACKRate;
682     BYTE                        byTopOFDMBasicRate;
683     BYTE                        byTopCCKBasicRate;
684
685
686     DWORD                       dwAotoRateTxOkCnt;
687     DWORD                       dwAotoRateTxFailCnt;
688     DWORD                       dwErrorRateThreshold[13];
689     DWORD                       dwTPTable[MAX_RATE];
690     BYTE                        abyEEPROM[EEP_MAX_CONTEXT_SIZE];  //DWORD alignment
691
692     BYTE                        byMinChannel;
693     BYTE                        byMaxChannel;
694     UINT                        uConnectionRate;
695
696     BYTE                        byPreambleType;
697     BYTE                        byShortPreamble;
698     // CARD_PHY_TYPE
699     BYTE                        eConfigPHYMode;
700
701     // For RF Power table
702     BYTE                        byCCKPwr;
703     BYTE                        byOFDMPwrG;
704     BYTE                        byOFDMPwrA;
705     BYTE                        byCurPwr;
706     BYTE                        abyCCKPwrTbl[14];
707     BYTE                        abyOFDMPwrTbl[14];
708     BYTE                        abyOFDMAPwrTbl[42];
709
710     WORD                        wCurrentRate;
711     WORD                        wRTSThreshold;
712     WORD                        wFragmentationThreshold;
713     BYTE                        byShortRetryLimit;
714     BYTE                        byLongRetryLimit;
715     CARD_OP_MODE                eOPMode;
716     BOOL                        bBSSIDFilter;
717     WORD                        wMaxTransmitMSDULifetime;
718     BYTE                        abyBSSID[U_ETHER_ADDR_LEN];
719     BYTE                        abyDesireBSSID[U_ETHER_ADDR_LEN];
720     WORD                        wCTSDuration;       // update while speed change
721     WORD                        wACKDuration;       // update while speed change
722     WORD                        wRTSTransmitLen;    // update while speed change
723     BYTE                        byRTSServiceField;  // update while speed change
724     BYTE                        byRTSSignalField;   // update while speed change
725
726     DWORD                       dwMaxReceiveLifetime;       // dot11MaxReceiveLifetime
727
728     BOOL                        bCCK;
729     BOOL                        bEncryptionEnable;
730     BOOL                        bLongHeader;
731     BOOL                        bSoftwareGenCrcErr;
732     BOOL                        bShortSlotTime;
733     BOOL                        bProtectMode;
734     BOOL                        bNonERPPresent;
735     BOOL                        bBarkerPreambleMd;
736
737     BYTE                        byERPFlag;
738     WORD                        wUseProtectCntDown;
739
740     BOOL                        bRadioControlOff;
741     BOOL                        bRadioOff;
742
743     // Power save
744     BOOL                        bEnablePSMode;
745     WORD                        wListenInterval;
746     BOOL                        bPWBitOn;
747     WMAC_POWER_MODE             ePSMode;
748     ULONG                       ulPSModeWaitTx;
749     BOOL                        bPSModeTxBurst;
750
751     // Beacon releated
752     WORD                    wSeqCounter;
753     BOOL                    bBeaconBufReady;
754     BOOL                    bBeaconSent;
755     BOOL                    bFixRate;
756     BYTE                    byCurrentCh;
757     UINT                    uScanTime;
758
759     CMD_STATE               eCommandState;
760
761     CMD_CODE                eCommand;
762     BOOL                    bBeaconTx;
763     BYTE                    byScanBBType;
764
765     BOOL                    bStopBeacon;
766     BOOL                    bStopDataPkt;
767     BOOL                    bStopTx0Pkt;
768     UINT                    uAutoReConnectTime;
769     UINT                    uIsroamingTime;
770
771     // 802.11 counter
772
773     CMD_ITEM                eCmdQueue[CMD_Q_SIZE];
774     UINT                    uCmdDequeueIdx;
775     UINT                    uCmdEnqueueIdx;
776     UINT                    cbFreeCmdQueue;
777     BOOL                    bCmdRunning;
778     BOOL                    bCmdClear;
779     BOOL                    bNeedRadioOFF;
780
781     BOOL                    bEnableRoaming;  //DavidWang
782     BOOL                    bIsRoaming;  //DavidWang
783     BOOL                    bFastRoaming;  //DavidWang
784     BYTE                    bSameBSSMaxNum;  //Davidwang
785     BYTE                    bSameBSSCurNum;  //DavidWang
786     BOOL                    bRoaming;
787     BOOL                    b11hEable;
788     ULONG                   ulTxPower;
789
790     // Encryption
791     NDIS_802_11_WEP_STATUS  eEncryptionStatus;
792     BOOL                    bTransmitKey;
793
794 //2007-0925-01<Add>by MikeLiu
795 //mike add :save old Encryption
796     NDIS_802_11_WEP_STATUS  eOldEncryptionStatus;
797
798     SKeyManagement          sKey;
799     DWORD                   dwIVCounter;
800
801
802     RC4Ext                  SBox;
803     BYTE                    abyPRNG[WLAN_WEPMAX_KEYLEN+3];
804     BYTE                    byKeyIndex;
805
806     BOOL                    bAES;
807     BYTE                    byCntMeasure;
808
809     UINT                    uKeyLength;
810     BYTE                    abyKey[WLAN_WEP232_KEYLEN];
811
812     // for AP mode
813     UINT                    uAssocCount;
814     BOOL                    bMoreData;
815
816     // QoS
817     BOOL                    bGrpAckPolicy;
818
819
820     BYTE                    byAutoFBCtrl;
821
822     BOOL                    bTxMICFail;
823     BOOL                    bRxMICFail;
824
825
826     // For Update BaseBand VGA Gain Offset
827     BOOL                    bUpdateBBVGA;
828     UINT                    uBBVGADiffCount;
829     BYTE                    byBBVGANew;
830     BYTE                    byBBVGACurrent;
831     BYTE                    abyBBVGA[BB_VGA_LEVEL];
832     LONG                    ldBmThreshold[BB_VGA_LEVEL];
833
834     BYTE                    byBBPreEDRSSI;
835     BYTE                    byBBPreEDIndex;
836
837
838     BOOL                    bRadioCmd;
839     DWORD                   dwDiagRefCount;
840
841     // For FOE Tuning
842     BYTE                    byFOETuning;
843
844     // For Auto Power Tunning
845
846     BYTE                    byAutoPwrTunning;
847
848     // BaseBand Loopback Use
849     BYTE                    byBBCR4d;
850     BYTE                    byBBCRc9;
851     BYTE                    byBBCR88;
852     BYTE                    byBBCR09;
853
854     // command timer
855     struct timer_list       sTimerCommand;
856
857 //2007-0115-01<Add>by MikeLiu
858 #ifdef TxInSleep
859      struct timer_list       sTimerTxData;
860      ULONG                       nTxDataTimeCout;
861      BOOL  fTxDataInSleep;
862      BOOL  IsTxDataTrigger;
863 #endif
864
865 #ifdef WPA_SM_Transtatus
866     BOOL  fWPA_Authened;           //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
867 #endif
868     BYTE            byReAssocCount;   //mike add:re-association retry times!
869     BYTE            byLinkWaitCount;
870
871     SEthernetHeader         sTxEthHeader;
872     SEthernetHeader         sRxEthHeader;
873     BYTE                    abyBroadcastAddr[U_ETHER_ADDR_LEN];
874     BYTE                    abySNAP_RFC1042[U_ETHER_ADDR_LEN];
875     BYTE                    abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN];
876
877     // Pre-Authentication & PMK cache
878     SPMKID                  gsPMKID;
879     SPMKIDCandidateEvent    gsPMKIDCandidate;
880
881
882     // for 802.11h
883     BOOL                    b11hEnable;
884
885     BOOL                    bChannelSwitch;
886     BYTE                    byNewChannel;
887     BYTE                    byChannelSwitchCount;
888
889     //WPA supplicant daemon
890         struct net_device       *wpadev;
891         BOOL                    bWPADEVUp;
892     struct sk_buff          *skb;
893     //--
894
895 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
896         BOOL                 bwextstep0;
897         BOOL                 bwextstep1;
898         BOOL                 bwextstep2;
899         BOOL                 bwextstep3;
900         BOOL                 bWPASuppWextEnabled;
901 #endif
902
903 #ifdef HOSTAP
904     // user space daemon: hostapd, is used for HOSTAP
905         BOOL                    bEnableHostapd;
906         BOOL                    bEnable8021x;
907         BOOL                    bEnableHostWEP;
908         struct net_device       *apdev;
909         int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
910 #endif
911     UINT                    uChannel;
912
913 #ifdef WIRELESS_EXT
914         struct iw_statistics    wstats;         // wireless stats
915 #endif /* WIRELESS_EXT */
916     BOOL                    bCommit;
917
918 } DEVICE_INFO, *PSDevice;
919
920
921
922
923 #define EnqueueRCB(_Head, _Tail, _RCB)                  \
924 {                                                       \
925     if (!_Head) {                                       \
926         _Head = _RCB;                                   \
927     }                                                   \
928     else {                                              \
929         _Tail->Next = _RCB;                             \
930     }                                                   \
931     _RCB->Next = NULL;                                  \
932     _Tail = _RCB;                                       \
933 }
934
935 #define DequeueRCB(Head, Tail)                          \
936 {                                                       \
937     PRCB   RCB = Head;                                  \
938     if (!RCB->Next) {                                   \
939         Tail = NULL;                                    \
940     }                                                   \
941     Head = RCB->Next;                                   \
942 }
943
944
945 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) {   \
946     if ((uVar) >= ((uModulo) - 1))                  \
947         (uVar) = 0;                                 \
948     else                                            \
949         (uVar)++;                                   \
950 }
951
952
953 #define fMP_RESET_IN_PROGRESS               0x00000001
954 #define fMP_DISCONNECTED                    0x00000002
955 #define fMP_HALT_IN_PROGRESS                0x00000004
956 #define fMP_SURPRISE_REMOVED                0x00000008
957 #define fMP_RECV_LOOKASIDE                  0x00000010
958 #define fMP_INIT_IN_PROGRESS                0x00000020
959 #define fMP_SEND_SIDE_RESOURCE_ALLOCATED    0x00000040
960 #define fMP_RECV_SIDE_RESOURCE_ALLOCATED    0x00000080
961 #define fMP_POST_READS                      0x00000100
962 #define fMP_POST_WRITES                     0x00000200
963 #define fMP_CONTROL_READS                   0x00000400
964 #define fMP_CONTROL_WRITES                  0x00000800
965
966
967
968 #define MP_SET_FLAG(_M, _F)             ((_M)->Flags |= (_F))
969 #define MP_CLEAR_FLAG(_M, _F)            ((_M)->Flags &= ~(_F))
970 #define MP_TEST_FLAG(_M, _F)            (((_M)->Flags & (_F)) != 0)
971 #define MP_TEST_FLAGS(_M, _F)            (((_M)->Flags & (_F)) == (_F))
972
973 #define MP_IS_READY(_M)        (((_M)->Flags & \
974                                  (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_HALT_IN_PROGRESS | fMP_INIT_IN_PROGRESS | fMP_SURPRISE_REMOVED)) == 0)
975
976 /*---------------------  Export Functions  --------------------------*/
977
978 //BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, UINT uNodeIndex);
979 BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF);
980
981 #endif
982
983