2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
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.
21 * Purpose: MAC Data structure
34 #include <linux/modversions.h>
35 #endif /* MODVERSIONS */
36 #include <linux/module.h>
39 #include <linux/types.h>
40 #include <linux/init.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>
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>
66 #include <asm/uaccess.h>
68 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
69 #include <linux/ethtool.h>
71 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
73 /* Include Wireless Extension definition and check version - Jean II */
74 #include <linux/wireless.h>
75 #include <net/iw_handler.h> // New driver API
77 #ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
78 #define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
81 //2007-0920-01<Add>by MikeLiu
84 //please copy below macro to driver_event.c for API
85 #define RT_INSMOD_EVENT_FLAG 0x0101
86 #define RT_UPDEV_EVENT_FLAG 0x0102
87 #define RT_DISCONNECTED_EVENT_FLAG 0x0103
88 #define RT_WPACONNECTED_EVENT_FLAG 0x0104
89 #define RT_DOWNDEV_EVENT_FLAG 0x0105
90 #define RT_RMMOD_EVENT_FLAG 0x0106
97 #if !defined(_KCOMPAT_H)
101 #if !defined(__DEVICE_CONFIG_H)
102 #include "device_cfg.h"
105 #if !defined(__TTYPE_H__)
108 #if !defined(__80211HDR_H__)
109 #include "80211hdr.h"
111 #if !defined(__TETHER_H__)
114 #if !defined(__WMGR_H__)
117 #if !defined(__WCMD_H__)
120 #if !defined(__MIB_H__)
123 #if !defined(__SROM_H__)
126 #if !defined(__RC4_H__)
129 #if !defined(__TPCI_H__)
132 #if !defined(__DESC_H__)
135 #if !defined(__KEY_H__)
138 #if !defined(__CARD_H__)
142 /*--------------------- Export Definitions -------------------------*/
143 #define VNT_USB_VENDOR_ID 0x160A
144 #define VNT_USB_PRODUCT_ID 0x3184
146 #define MAC_MAX_CONTEXT_REG (256+128)
148 #define MAX_MULTICAST_ADDRESS_NUM 32
149 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * U_ETHER_ADDR_LEN)
152 //#define OP_MODE_INFRASTRUCTURE 0
153 //#define OP_MODE_ADHOC 1
154 //#define OP_MODE_AP 2
156 #define DUPLICATE_RX_CACHE_LENGTH 5
158 #define NUM_KEY_ENTRY 11
160 #define TX_WEP_NONE 0
163 #define TX_WEP_SWOTP 3
164 #define TX_WEP_OTPSW 4
165 #define TX_WEP_SW232 5
167 #define KEYSEL_WEP40 0
168 #define KEYSEL_WEP104 1
169 #define KEYSEL_TKIP 2
170 #define KEYSEL_CCMP 3
174 #define AUTO_FB_NONE 0
184 #define ANT_DIVERSITY 2
185 #define ANT_RXD_TXA 3
186 #define ANT_RXD_TXB 4
187 #define ANT_UNKNOWN 0xFF
194 #define MAXCHECKHANGCNT 4
197 #define TX_PKT_UNI 0x00
198 #define TX_PKT_MULTI 0x01
199 #define TX_PKT_BROAD 0x02
201 #define BB_VGA_LEVEL 4
202 #define BB_VGA_CHANGE_THRESHOLD 3
207 #define RUN_AT(x) (jiffies+(x))
211 #define RESERV_AC0DMA 4
213 #define PRIVATE_Message 0
215 /*--------------------- Export Types ------------------------------*/
217 #define DBG_PRT(l, p, args...) {if (l<=msglevel) printk( p ,##args);}
218 #define PRINT_K(p, args...) {if (PRIVATE_Message) printk( p ,##args);}
220 typedef enum __device_msg_level
{
221 MSG_LEVEL_ERR
=0, //Errors that will cause abnormal operation.
222 MSG_LEVEL_NOTICE
=1, //Some errors need users to be notified.
223 MSG_LEVEL_INFO
=2, //Normal message.
224 MSG_LEVEL_VERBOSE
=3, //Will report all trival errors.
225 MSG_LEVEL_DEBUG
=4 //Only for debug purpose.
226 } DEVICE_MSG_LEVEL
, *PDEVICE_MSG_LEVEL
;
228 typedef enum __device_init_type
{
229 DEVICE_INIT_COLD
=0, // cold init
230 DEVICE_INIT_RESET
, // reset init or Dx to D0 power remain init
231 DEVICE_INIT_DXPL
// Dx to D0 power lost init
232 } DEVICE_INIT_TYPE
, *PDEVICE_INIT_TYPE
;
238 // Enum of context types for SendPacket
240 typedef enum _CONTEXT_TYPE
{
241 CONTEXT_DATA_PACKET
= 1,
248 // RCB (Receive Control Block)
255 SRxMgmtPacket sMngPacket
;
262 // used to track bulk out irps
263 typedef struct _USB_SEND_CONTEXT
{
265 struct sk_buff
*pPacket
;
269 SEthernetHeader sEthHeader
;
272 UCHAR Data
[MAX_TOTAL_SIZE_WITH_ALL_HEADERS
];
273 } USB_SEND_CONTEXT
, *PUSB_SEND_CONTEXT
;
276 //structure got from configuration file as user desired default setting.
277 typedef struct _DEFAULT_CONFIG
{
280 INT eAuthenMode
; //open/wep/wpa
281 INT bShareKeyAlgorithm
; //open-open/open-sharekey/wep-sharekey
282 INT keyidx
; //wepkey index
283 INT eEncryptionStatus
;
285 }DEFAULT_CONFIG
,*PDEFAULT_CONFIG
;
288 // Structure to keep track of usb interrupt packets
295 } INT_BUFFER
, *PINT_BUFFER
;
300 typedef enum _VIA_BB_TYPE
305 } VIA_BB_TYPE
, *PVIA_BB_TYPE
;
307 //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
308 typedef enum _VIA_PKT_TYPE
314 } VIA_PKT_TYPE
, *PVIA_PKT_TYPE
;
321 #define NDIS_STATUS int
324 typedef enum __DEVICE_NDIS_STATUS
{
329 } DEVICE_NDIS_STATUS
, *PDEVICE_NDIS_STATUS
;
332 #define MAX_BSSIDINFO_4_PMKID 16
333 #define MAX_PMKIDLIST 5
334 //Flags for PMKID Candidate list structure
335 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
338 typedef UCHAR NDIS_802_11_PMKID_VALUE
[16];
341 typedef enum _NDIS_802_11_WEP_STATUS
343 Ndis802_11WEPEnabled
,
344 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
345 Ndis802_11WEPDisabled
,
346 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
347 Ndis802_11WEPKeyAbsent
,
348 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
349 Ndis802_11WEPNotSupported
,
350 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
351 Ndis802_11Encryption2Enabled
,
352 Ndis802_11Encryption2KeyAbsent
,
353 Ndis802_11Encryption3Enabled
,
354 Ndis802_11Encryption3KeyAbsent
355 } NDIS_802_11_WEP_STATUS
, *PNDIS_802_11_WEP_STATUS
,
356 NDIS_802_11_ENCRYPTION_STATUS
, *PNDIS_802_11_ENCRYPTION_STATUS
;
359 typedef enum _NDIS_802_11_STATUS_TYPE
361 Ndis802_11StatusType_Authentication
,
362 Ndis802_11StatusType_MediaStreamMode
,
363 Ndis802_11StatusType_PMKID_CandidateList
,
364 Ndis802_11StatusTypeMax
// not a real type, defined as an upper bound
365 } NDIS_802_11_STATUS_TYPE
, *PNDIS_802_11_STATUS_TYPE
;
367 //Added new types for PMKID Candidate lists.
368 typedef struct _PMKID_CANDIDATE
{
369 NDIS_802_11_MAC_ADDRESS BSSID
;
371 } PMKID_CANDIDATE
, *PPMKID_CANDIDATE
;
374 typedef struct _BSSID_INFO
376 NDIS_802_11_MAC_ADDRESS BSSID
;
377 NDIS_802_11_PMKID_VALUE PMKID
;
378 } BSSID_INFO
, *PBSSID_INFO
;
380 typedef struct tagSPMKID
{
382 ULONG BSSIDInfoCount
;
383 BSSID_INFO BSSIDInfo
[MAX_BSSIDINFO_4_PMKID
];
386 typedef struct tagSPMKIDCandidateEvent
{
387 NDIS_802_11_STATUS_TYPE StatusType
;
388 ULONG Version
; // Version of the structure
389 ULONG NumCandidates
; // No. of pmkid candidates
390 PMKID_CANDIDATE CandidateList
[MAX_PMKIDLIST
];
391 } SPMKIDCandidateEvent
, *PSPMKIDCandidateEvent
;
396 #define MAX_QUIET_COUNT 8
398 typedef struct tagSQuietControl
{
403 } SQuietControl
, *PSQuietControl
;
408 // The receive duplicate detection cache entry
409 typedef struct tagSCacheEntry
{
411 BYTE abyAddr2
[U_ETHER_ADDR_LEN
];
413 } SCacheEntry
, *PSCacheEntry
;
415 typedef struct tagSCache
{
416 /* The receive cache is updated circularly. The next entry to be written is
417 * indexed by the "InPtr".
419 UINT uInPtr
; // Place to use next
420 SCacheEntry asCacheEntry
[DUPLICATE_RX_CACHE_LENGTH
];
423 #define CB_MAX_RX_FRAG 64
424 // DeFragment Control Block, used for collecting fragments prior to reassembly
425 typedef struct tagSDeFragControlBlock
429 BYTE abyAddr2
[U_ETHER_ADDR_LEN
];
435 } SDeFragControlBlock
, *PSDeFragControlBlock
;
440 #define DEVICE_FLAGS_UNPLUG 0x00000001UL
441 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
442 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
443 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
444 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
446 //flags for driver status
447 #define DEVICE_FLAGS_OPENED 0x00010000UL
448 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
449 //flags for capbilities
450 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
451 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
452 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
454 //flags for MII status
455 #define DEVICE_LINK_FAIL 0x00000001UL
456 #define DEVICE_SPEED_10 0x00000002UL
457 #define DEVICE_SPEED_100 0x00000004UL
458 #define DEVICE_SPEED_1000 0x00000008UL
459 #define DEVICE_DUPLEX_FULL 0x00000010UL
460 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
461 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
462 //for device_set_media_duplex
463 #define DEVICE_LINK_CHANGE 0x00000001UL
466 typedef struct __device_opt
{
467 int nRxDescs0
; //Number of RX descriptors0
468 int nTxDescs0
; //Number of TX descriptors 0, 1, 2, 3
469 int rts_thresh
; //rts threshold
478 } OPTIONS
, *POPTIONS
;
481 typedef struct __device_info
{
484 struct usb_device
* usb
;
485 struct net_device
* dev
;
486 struct net_device_stats stats
;
490 struct tasklet_struct CmdWorkItem
;
491 struct tasklet_struct EventWorkItem
;
492 struct tasklet_struct ReadWorkItem
;
493 struct tasklet_struct RxMngWorkItem
;
510 SDeFragControlBlock sRxDFCB
[CB_MAX_RX_FRAG
];
513 UINT uCurrentDFCBIdx
;
517 struct urb
*pControlURB
;
518 struct urb
*pInterruptURB
;
519 struct usb_ctrlrequest sUsbCtlRequest
;
523 // Variables to track resources for the BULK In Pipe
526 PRCB apRCB
[CB_MAX_RX_DESC
];
528 PRCB FirstRecvFreeList
;
529 PRCB LastRecvFreeList
;
530 UINT NumRecvFreeList
;
531 PRCB FirstRecvMngList
;
532 PRCB LastRecvMngList
;
534 BOOL bIsRxWorkItemQueued
;
535 BOOL bIsRxMngWorkItemQueued
;
536 ULONG ulRcvRefCount
; // number of packets that have not been returned back
539 // Variables to track resources for the BULK Out Pipe
542 PUSB_SEND_CONTEXT apTD
[CB_MAX_TX_DESC
];
546 // Variables to track resources for the Interript In Pipe
549 BOOL fKillEventPollingThread
;
550 BOOL bEventAvailable
;
553 //default config from file by user setting
554 DEFAULT_CONFIG config_file
;
559 // protect with spinlock
560 ULONG ulBulkInPosted
;
562 ULONG ulBulkInContCRCError
;
563 ULONG ulBulkInBytesRead
;
565 ULONG ulBulkOutPosted
;
566 ULONG ulBulkOutError
;
567 ULONG ulBulkOutContCRCError
;
568 ULONG ulBulkOutBytesWrite
;
572 ULONG ulIntInContCRCError
;
573 ULONG ulIntInBytesRead
;
577 WORD wFirmwareVersion
;
586 BYTE byOriginalZonetype
;
588 BOOL bLinkPass
; // link status: OK or fail
589 BYTE abyCurrentNetAddr
[U_ETHER_ADDR_LEN
];
590 BYTE abyPermanentNetAddr
[U_ETHER_ADDR_LEN
];
591 // SW network address
592 // BYTE abySoftwareNetAddr[U_ETHER_ADDR_LEN];
593 BOOL bExistSWNetAddr
;
595 // Adapter statistics
596 SStatCounter scStatistic
;
598 SDot11Counters s802_11Counter
;
601 // Maintain statistical debug info.
603 ULONG packetsReceived
;
604 ULONG packetsReceivedDropped
;
605 ULONG packetsReceivedOverflow
;
607 ULONG packetsSentDropped
;
608 ULONG SendContextsInUse
;
609 ULONG RcvBuffersInUse
;
613 SMgmtObject sMgmtObj
;
619 // 802.11 MAC specific
626 DWORD dwRxAntennaSel
;
627 DWORD dwTxAntennaSel
;
629 BYTE byRxAntennaMode
;
630 BYTE byTxAntennaMode
;
634 //SQ3 functions for antenna diversity
635 struct timer_list TimerSQ3Tmax1
;
636 struct timer_list TimerSQ3Tmax2
;
637 struct timer_list TimerSQ3Tmax3
;
639 BOOL bDiversityRegCtlON
;
640 BOOL bDiversityEnable
;
641 ULONG ulDiversityNValue
;
642 ULONG ulDiversityMValue
;
650 ULONG ulRatio_State0
;
651 ULONG ulRatio_State1
;
655 ULONG aulSQ3Val
[MAX_RATE
];
656 ULONG aulPktNum
[MAX_RATE
];
659 UINT uSIFS
; //Current SIFS
660 UINT uDIFS
; //Current DIFS
661 UINT uEIFS
; //Current EIFS
662 UINT uSlot
; //Current SlotTime
663 UINT uCwMin
; //Current CwMin
664 UINT uCwMax
; //CwMax is fixed on 1023.
673 VIA_BB_TYPE byBBType
; //0: 11A, 1:11B, 2:11G
674 VIA_PKT_TYPE byPacketType
; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
677 BYTE byTopOFDMBasicRate
;
678 BYTE byTopCCKBasicRate
;
681 DWORD dwAotoRateTxOkCnt
;
682 DWORD dwAotoRateTxFailCnt
;
683 DWORD dwErrorRateThreshold
[13];
684 DWORD dwTPTable
[MAX_RATE
];
685 BYTE abyEEPROM
[EEP_MAX_CONTEXT_SIZE
]; //DWORD alignment
689 UINT uConnectionRate
;
692 BYTE byShortPreamble
;
696 // For RF Power table
701 BYTE abyCCKPwrTbl
[14];
702 BYTE abyOFDMPwrTbl
[14];
703 BYTE abyOFDMAPwrTbl
[42];
707 WORD wFragmentationThreshold
;
708 BYTE byShortRetryLimit
;
709 BYTE byLongRetryLimit
;
710 CARD_OP_MODE eOPMode
;
712 WORD wMaxTransmitMSDULifetime
;
713 BYTE abyBSSID
[U_ETHER_ADDR_LEN
];
714 BYTE abyDesireBSSID
[U_ETHER_ADDR_LEN
];
715 WORD wCTSDuration
; // update while speed change
716 WORD wACKDuration
; // update while speed change
717 WORD wRTSTransmitLen
; // update while speed change
718 BYTE byRTSServiceField
; // update while speed change
719 BYTE byRTSSignalField
; // update while speed change
721 DWORD dwMaxReceiveLifetime
; // dot11MaxReceiveLifetime
724 BOOL bEncryptionEnable
;
726 BOOL bSoftwareGenCrcErr
;
730 BOOL bBarkerPreambleMd
;
733 WORD wUseProtectCntDown
;
735 BOOL bRadioControlOff
;
740 WORD wListenInterval
;
742 WMAC_POWER_MODE ePSMode
;
743 ULONG ulPSModeWaitTx
;
748 BOOL bBeaconBufReady
;
754 CMD_STATE eCommandState
;
763 UINT uAutoReConnectTime
;
768 CMD_ITEM eCmdQueue
[CMD_Q_SIZE
];
776 BOOL bEnableRoaming
; //DavidWang
777 BOOL bIsRoaming
; //DavidWang
778 BOOL bFastRoaming
; //DavidWang
779 BYTE bSameBSSMaxNum
; //Davidwang
780 BYTE bSameBSSCurNum
; //DavidWang
786 NDIS_802_11_WEP_STATUS eEncryptionStatus
;
789 //2007-0925-01<Add>by MikeLiu
790 //mike add :save old Encryption
791 NDIS_802_11_WEP_STATUS eOldEncryptionStatus
;
798 BYTE abyPRNG
[WLAN_WEPMAX_KEYLEN
+3];
805 BYTE abyKey
[WLAN_WEP232_KEYLEN
];
821 // For Update BaseBand VGA Gain Offset
823 UINT uBBVGADiffCount
;
826 BYTE abyBBVGA
[BB_VGA_LEVEL
];
827 LONG ldBmThreshold
[BB_VGA_LEVEL
];
834 DWORD dwDiagRefCount
;
839 // For Auto Power Tunning
841 BYTE byAutoPwrTunning
;
843 // BaseBand Loopback Use
850 struct timer_list sTimerCommand
;
852 //2007-0115-01<Add>by MikeLiu
854 struct timer_list sTimerTxData
;
855 ULONG nTxDataTimeCout
;
857 BOOL IsTxDataTrigger
;
860 #ifdef WPA_SM_Transtatus
861 BOOL fWPA_Authened
; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
863 BYTE byReAssocCount
; //mike add:re-association retry times!
864 BYTE byLinkWaitCount
;
866 SEthernetHeader sTxEthHeader
;
867 SEthernetHeader sRxEthHeader
;
868 BYTE abyBroadcastAddr
[U_ETHER_ADDR_LEN
];
869 BYTE abySNAP_RFC1042
[U_ETHER_ADDR_LEN
];
870 BYTE abySNAP_Bridgetunnel
[U_ETHER_ADDR_LEN
];
872 // Pre-Authentication & PMK cache
874 SPMKIDCandidateEvent gsPMKIDCandidate
;
882 BYTE byChannelSwitchCount
;
884 //WPA supplicant daemon
885 struct net_device
*wpadev
;
890 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
895 BOOL bWPASuppWextEnabled
;
899 // user space daemon: hostapd, is used for HOSTAP
903 struct net_device
*apdev
;
904 int (*tx_80211
)(struct sk_buff
*skb
, struct net_device
*dev
);
908 struct iw_statistics wstats
; // wireless stats
911 } DEVICE_INFO
, *PSDevice
;
916 #define EnqueueRCB(_Head, _Tail, _RCB) \
922 _Tail->Next = _RCB; \
928 #define DequeueRCB(Head, Tail) \
938 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
939 if ((uVar) >= ((uModulo) - 1)) \
946 #define fMP_RESET_IN_PROGRESS 0x00000001
947 #define fMP_DISCONNECTED 0x00000002
948 #define fMP_HALT_IN_PROGRESS 0x00000004
949 #define fMP_SURPRISE_REMOVED 0x00000008
950 #define fMP_RECV_LOOKASIDE 0x00000010
951 #define fMP_INIT_IN_PROGRESS 0x00000020
952 #define fMP_SEND_SIDE_RESOURCE_ALLOCATED 0x00000040
953 #define fMP_RECV_SIDE_RESOURCE_ALLOCATED 0x00000080
954 #define fMP_POST_READS 0x00000100
955 #define fMP_POST_WRITES 0x00000200
956 #define fMP_CONTROL_READS 0x00000400
957 #define fMP_CONTROL_WRITES 0x00000800
961 #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
962 #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
963 #define MP_TEST_FLAG(_M, _F) (((_M)->Flags & (_F)) != 0)
964 #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
966 #define MP_IS_READY(_M) (((_M)->Flags & \
967 (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_HALT_IN_PROGRESS | fMP_INIT_IN_PROGRESS | fMP_SURPRISE_REMOVED)) == 0)
969 /*--------------------- Export Functions --------------------------*/
971 //BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, UINT uNodeIndex);
972 BOOL
device_alloc_frag_buf(PSDevice pDevice
, PSDeFragControlBlock pDeF
);