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
32 #include <linux/module.h>
33 #include <linux/types.h>
34 #include <linux/init.h>
36 #include <linux/errno.h>
37 #include <linux/ioport.h>
38 #include <linux/pci.h>
39 #include <linux/kernel.h>
40 #include <linux/netdevice.h>
41 #include <linux/etherdevice.h>
42 #include <linux/skbuff.h>
43 #include <linux/delay.h>
44 #include <linux/timer.h>
45 #include <linux/slab.h>
46 #include <linux/interrupt.h>
47 #include <linux/string.h>
48 #include <linux/wait.h>
49 #include <linux/if_arp.h>
50 #include <linux/sched.h>
52 #include <linux/rtnetlink.h>//James
53 #include <linux/proc_fs.h>
54 #include <linux/inetdevice.h>
55 #include <linux/reboot.h>
56 #include <linux/usb.h>
57 #include <linux/signal.h>
58 #include <linux/firmware.h>
60 #include <asm/uaccess.h>
62 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
63 #include <linux/ethtool.h>
65 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
67 /* Include Wireless Extension definition and check version - Jean II */
68 #include <linux/wireless.h>
69 #include <net/iw_handler.h> // New driver API
71 #ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
72 #define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
75 //please copy below macro to driver_event.c for API
76 #define RT_INSMOD_EVENT_FLAG 0x0101
77 #define RT_UPDEV_EVENT_FLAG 0x0102
78 #define RT_DISCONNECTED_EVENT_FLAG 0x0103
79 #define RT_WPACONNECTED_EVENT_FLAG 0x0104
80 #define RT_DOWNDEV_EVENT_FLAG 0x0105
81 #define RT_RMMOD_EVENT_FLAG 0x0106
87 #include "device_cfg.h"
100 /*--------------------- Export Definitions -------------------------*/
101 #define VNT_USB_VENDOR_ID 0x160a
102 #define VNT_USB_PRODUCT_ID 0x3184
104 #define MAC_MAX_CONTEXT_REG (256+128)
106 #define MAX_MULTICAST_ADDRESS_NUM 32
107 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * ETH_ALEN)
109 //#define OP_MODE_INFRASTRUCTURE 0
110 //#define OP_MODE_ADHOC 1
111 //#define OP_MODE_AP 2
113 #define DUPLICATE_RX_CACHE_LENGTH 5
115 #define NUM_KEY_ENTRY 11
117 #define TX_WEP_NONE 0
120 #define TX_WEP_SWOTP 3
121 #define TX_WEP_OTPSW 4
122 #define TX_WEP_SW232 5
124 #define KEYSEL_WEP40 0
125 #define KEYSEL_WEP104 1
126 #define KEYSEL_TKIP 2
127 #define KEYSEL_CCMP 3
129 #define AUTO_FB_NONE 0
139 #define ANT_DIVERSITY 2
140 #define ANT_RXD_TXA 3
141 #define ANT_RXD_TXB 4
142 #define ANT_UNKNOWN 0xFF
149 #define MAXCHECKHANGCNT 4
152 #define TX_PKT_UNI 0x00
153 #define TX_PKT_MULTI 0x01
154 #define TX_PKT_BROAD 0x02
156 #define BB_VGA_LEVEL 4
157 #define BB_VGA_CHANGE_THRESHOLD 3
160 #define RUN_AT(x) (jiffies+(x))
164 #define RESERV_AC0DMA 4
166 #define PRIVATE_Message 0
168 /*--------------------- Export Types ------------------------------*/
170 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
171 #define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
173 typedef enum __device_msg_level
{
174 MSG_LEVEL_ERR
= 0, /* Errors causing abnormal operation */
175 MSG_LEVEL_NOTICE
= 1, /* Errors needing user notification */
176 MSG_LEVEL_INFO
= 2, /* Normal message. */
177 MSG_LEVEL_VERBOSE
= 3, /* Will report all trival errors. */
178 MSG_LEVEL_DEBUG
= 4 /* Only for debug purpose. */
179 } DEVICE_MSG_LEVEL
, *PDEVICE_MSG_LEVEL
;
181 typedef enum __device_init_type
{
182 DEVICE_INIT_COLD
= 0, /* cold init */
183 DEVICE_INIT_RESET
, /* reset init or Dx to D0 power remain */
184 DEVICE_INIT_DXPL
/* Dx to D0 power lost init */
185 } DEVICE_INIT_TYPE
, *PDEVICE_INIT_TYPE
;
190 // Enum of context types for SendPacket
192 typedef enum _CONTEXT_TYPE
{
193 CONTEXT_DATA_PACKET
= 1,
197 // RCB (Receive Control Block)
204 SRxMgmtPacket sMngPacket
;
210 // used to track bulk out irps
211 typedef struct _USB_SEND_CONTEXT
{
213 struct sk_buff
*pPacket
;
215 unsigned int uBufLen
;
217 SEthernetHeader sEthHeader
;
220 unsigned char Data
[MAX_TOTAL_SIZE_WITH_ALL_HEADERS
];
221 } USB_SEND_CONTEXT
, *PUSB_SEND_CONTEXT
;
223 /* structure got from configuration file as user-desired default settings */
224 typedef struct _DEFAULT_CONFIG
{
226 signed int eConfigMode
;
227 signed int eAuthenMode
; /* open/wep/wpa */
228 signed int bShareKeyAlgorithm
; /* open-open/{open,wep}-sharekey */
229 signed int keyidx
; /* wepkey index */
230 signed int eEncryptionStatus
;
231 } DEFAULT_CONFIG
, *PDEFAULT_CONFIG
;
234 // Structure to keep track of usb interrupt packets
237 unsigned int uDataLen
;
241 } INT_BUFFER
, *PINT_BUFFER
;
244 typedef enum _VIA_BB_TYPE
249 } VIA_BB_TYPE
, *PVIA_BB_TYPE
;
251 //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
252 typedef enum _VIA_PKT_TYPE
258 } VIA_PKT_TYPE
, *PVIA_PKT_TYPE
;
262 typedef enum __DEVICE_NDIS_STATUS
{
267 } DEVICE_NDIS_STATUS
, *PDEVICE_NDIS_STATUS
;
269 #define MAX_BSSIDINFO_4_PMKID 16
270 #define MAX_PMKIDLIST 5
271 //Flags for PMKID Candidate list structure
272 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
275 typedef unsigned char NDIS_802_11_PMKID_VALUE
[16];
278 typedef enum _NDIS_802_11_WEP_STATUS
280 Ndis802_11WEPEnabled
,
281 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
282 Ndis802_11WEPDisabled
,
283 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
284 Ndis802_11WEPKeyAbsent
,
285 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
286 Ndis802_11WEPNotSupported
,
287 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
288 Ndis802_11Encryption2Enabled
,
289 Ndis802_11Encryption2KeyAbsent
,
290 Ndis802_11Encryption3Enabled
,
291 Ndis802_11Encryption3KeyAbsent
292 } NDIS_802_11_WEP_STATUS
, *PNDIS_802_11_WEP_STATUS
,
293 NDIS_802_11_ENCRYPTION_STATUS
, *PNDIS_802_11_ENCRYPTION_STATUS
;
296 typedef enum _NDIS_802_11_STATUS_TYPE
298 Ndis802_11StatusType_Authentication
,
299 Ndis802_11StatusType_MediaStreamMode
,
300 Ndis802_11StatusType_PMKID_CandidateList
,
301 Ndis802_11StatusTypeMax
// not a real type, defined as an upper bound
302 } NDIS_802_11_STATUS_TYPE
, *PNDIS_802_11_STATUS_TYPE
;
304 //Added new types for PMKID Candidate lists.
305 typedef struct _PMKID_CANDIDATE
{
306 NDIS_802_11_MAC_ADDRESS BSSID
;
308 } PMKID_CANDIDATE
, *PPMKID_CANDIDATE
;
311 typedef struct _BSSID_INFO
313 NDIS_802_11_MAC_ADDRESS BSSID
;
314 NDIS_802_11_PMKID_VALUE PMKID
;
315 } BSSID_INFO
, *PBSSID_INFO
;
317 typedef struct tagSPMKID
{
318 unsigned long Length
;
319 unsigned long BSSIDInfoCount
;
320 BSSID_INFO BSSIDInfo
[MAX_BSSIDINFO_4_PMKID
];
323 typedef struct tagSPMKIDCandidateEvent
{
324 NDIS_802_11_STATUS_TYPE StatusType
;
325 unsigned long Version
; /* Version of the structure */
326 unsigned long NumCandidates
; /* No. of pmkid candidates */
327 PMKID_CANDIDATE CandidateList
[MAX_PMKIDLIST
];
328 } SPMKIDCandidateEvent
, *PSPMKIDCandidateEvent
;
333 #define MAX_QUIET_COUNT 8
335 typedef struct tagSQuietControl
{
340 } SQuietControl
, *PSQuietControl
;
345 // The receive duplicate detection cache entry
346 typedef struct tagSCacheEntry
{
348 BYTE abyAddr2
[ETH_ALEN
];
350 } SCacheEntry
, *PSCacheEntry
;
352 typedef struct tagSCache
{
353 /* The receive cache is updated circularly. The next entry to be written is
354 * indexed by the "InPtr".
356 unsigned int uInPtr
; /* Place to use next */
357 SCacheEntry asCacheEntry
[DUPLICATE_RX_CACHE_LENGTH
];
360 #define CB_MAX_RX_FRAG 64
361 // DeFragment Control Block, used for collecting fragments prior to reassembly
362 typedef struct tagSDeFragControlBlock
366 BYTE abyAddr2
[ETH_ALEN
];
367 unsigned int uLifetime
;
370 unsigned int cbFrameLength
;
372 } SDeFragControlBlock
, *PSDeFragControlBlock
;
377 #define DEVICE_FLAGS_UNPLUG 0x00000001UL
378 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
379 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
380 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
381 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
383 //flags for driver status
384 #define DEVICE_FLAGS_OPENED 0x00010000UL
385 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
386 //flags for capbilities
387 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
388 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
389 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
391 //flags for MII status
392 #define DEVICE_LINK_FAIL 0x00000001UL
393 #define DEVICE_SPEED_10 0x00000002UL
394 #define DEVICE_SPEED_100 0x00000004UL
395 #define DEVICE_SPEED_1000 0x00000008UL
396 #define DEVICE_DUPLEX_FULL 0x00000010UL
397 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
398 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
399 //for device_set_media_duplex
400 #define DEVICE_LINK_CHANGE 0x00000001UL
403 typedef struct __device_opt
{
404 int nRxDescs0
; //Number of RX descriptors0
405 int nTxDescs0
; //Number of TX descriptors 0, 1, 2, 3
406 int rts_thresh
; //rts threshold
415 } OPTIONS
, *POPTIONS
;
418 typedef struct __device_info
{
421 struct usb_device
* usb
;
422 struct net_device
* dev
;
423 struct net_device_stats stats
;
425 const struct firmware
*firmware
;
429 struct tasklet_struct CmdWorkItem
;
430 struct tasklet_struct EventWorkItem
;
431 struct tasklet_struct ReadWorkItem
;
432 struct tasklet_struct RxMngWorkItem
;
449 SDeFragControlBlock sRxDFCB
[CB_MAX_RX_FRAG
];
451 unsigned int cbFreeDFCB
;
452 unsigned int uCurrentDFCBIdx
;
456 struct urb
*pControlURB
;
457 struct urb
*pInterruptURB
;
458 struct usb_ctrlrequest sUsbCtlRequest
;
460 unsigned int int_interval
;
462 // Variables to track resources for the BULK In Pipe
465 PRCB apRCB
[CB_MAX_RX_DESC
];
467 PRCB FirstRecvFreeList
;
468 PRCB LastRecvFreeList
;
469 unsigned int NumRecvFreeList
;
470 PRCB FirstRecvMngList
;
471 PRCB LastRecvMngList
;
472 unsigned int NumRecvMngList
;
473 BOOL bIsRxWorkItemQueued
;
474 BOOL bIsRxMngWorkItemQueued
;
475 unsigned long ulRcvRefCount
; /* packets that have not returned back */
478 // Variables to track resources for the BULK Out Pipe
481 PUSB_SEND_CONTEXT apTD
[CB_MAX_TX_DESC
];
485 // Variables to track resources for the Interript In Pipe
488 BOOL fKillEventPollingThread
;
489 BOOL bEventAvailable
;
492 //default config from file by user setting
493 DEFAULT_CONFIG config_file
;
498 // protect with spinlock
499 unsigned long ulBulkInPosted
;
500 unsigned long ulBulkInError
;
501 unsigned long ulBulkInContCRCError
;
502 unsigned long ulBulkInBytesRead
;
504 unsigned long ulBulkOutPosted
;
505 unsigned long ulBulkOutError
;
506 unsigned long ulBulkOutContCRCError
;
507 unsigned long ulBulkOutBytesWrite
;
509 unsigned long ulIntInPosted
;
510 unsigned long ulIntInError
;
511 unsigned long ulIntInContCRCError
;
512 unsigned long ulIntInBytesRead
;
516 WORD wFirmwareVersion
;
525 BYTE byOriginalZonetype
;
527 BOOL bLinkPass
; // link status: OK or fail
528 BYTE abyCurrentNetAddr
[ETH_ALEN
];
529 BYTE abyPermanentNetAddr
[ETH_ALEN
];
530 // SW network address
531 /* u8 abySoftwareNetAddr[ETH_ALEN]; */
532 BOOL bExistSWNetAddr
;
534 // Adapter statistics
535 SStatCounter scStatistic
;
537 SDot11Counters s802_11Counter
;
540 // Maintain statistical debug info.
542 unsigned long packetsReceived
;
543 unsigned long packetsReceivedDropped
;
544 unsigned long packetsReceivedOverflow
;
545 unsigned long packetsSent
;
546 unsigned long packetsSentDropped
;
547 unsigned long SendContextsInUse
;
548 unsigned long RcvBuffersInUse
;
552 SMgmtObject sMgmtObj
;
555 unsigned int cbBulkInMax
;
558 // 802.11 MAC specific
559 unsigned int uCurrRSSI
;
565 DWORD dwRxAntennaSel
;
566 DWORD dwTxAntennaSel
;
568 BYTE byRxAntennaMode
;
569 BYTE byTxAntennaMode
;
573 //SQ3 functions for antenna diversity
574 struct timer_list TimerSQ3Tmax1
;
575 struct timer_list TimerSQ3Tmax2
;
576 struct timer_list TimerSQ3Tmax3
;
578 BOOL bDiversityRegCtlON
;
579 BOOL bDiversityEnable
;
580 unsigned long ulDiversityNValue
;
581 unsigned long ulDiversityMValue
;
585 unsigned long ulSQ3TH
;
587 unsigned long uDiversityCnt
;
589 unsigned long ulRatio_State0
;
590 unsigned long ulRatio_State1
;
591 unsigned long ulSQ3_State0
;
592 unsigned long ulSQ3_State1
;
594 unsigned long aulSQ3Val
[MAX_RATE
];
595 unsigned long aulPktNum
[MAX_RATE
];
598 unsigned int uSIFS
; /* Current SIFS */
599 unsigned int uDIFS
; /* Current DIFS */
600 unsigned int uEIFS
; /* Current EIFS */
601 unsigned int uSlot
; /* Current SlotTime */
602 unsigned int uCwMin
; /* Current CwMin */
603 unsigned int uCwMax
; /* CwMax is fixed on 1023 */
613 VIA_BB_TYPE byBBType
; //0: 11A, 1:11B, 2:11G
614 VIA_PKT_TYPE byPacketType
; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
617 BYTE byTopOFDMBasicRate
;
618 BYTE byTopCCKBasicRate
;
621 DWORD dwAotoRateTxOkCnt
;
622 DWORD dwAotoRateTxFailCnt
;
623 DWORD dwErrorRateThreshold
[13];
624 DWORD dwTPTable
[MAX_RATE
];
625 BYTE abyEEPROM
[EEP_MAX_CONTEXT_SIZE
]; //DWORD alignment
629 unsigned int uConnectionRate
;
632 BYTE byShortPreamble
;
636 // For RF Power table
641 BYTE abyCCKPwrTbl
[14];
642 BYTE abyOFDMPwrTbl
[14];
643 BYTE abyOFDMAPwrTbl
[42];
647 WORD wFragmentationThreshold
;
648 BYTE byShortRetryLimit
;
649 BYTE byLongRetryLimit
;
650 CARD_OP_MODE eOPMode
;
652 WORD wMaxTransmitMSDULifetime
;
653 BYTE abyBSSID
[ETH_ALEN
];
654 BYTE abyDesireBSSID
[ETH_ALEN
];
655 WORD wCTSDuration
; // update while speed change
656 WORD wACKDuration
; // update while speed change
657 WORD wRTSTransmitLen
; // update while speed change
658 BYTE byRTSServiceField
; // update while speed change
659 BYTE byRTSSignalField
; // update while speed change
661 DWORD dwMaxReceiveLifetime
; // dot11MaxReceiveLifetime
664 BOOL bEncryptionEnable
;
666 BOOL bSoftwareGenCrcErr
;
670 BOOL bBarkerPreambleMd
;
673 WORD wUseProtectCntDown
;
675 BOOL bRadioControlOff
;
680 WORD wListenInterval
;
682 WMAC_POWER_MODE ePSMode
;
683 unsigned long ulPSModeWaitTx
;
688 BOOL bBeaconBufReady
;
692 unsigned int uScanTime
;
694 CMD_STATE eCommandState
;
703 unsigned int uAutoReConnectTime
;
704 unsigned int uIsroamingTime
;
708 CMD_ITEM eCmdQueue
[CMD_Q_SIZE
];
709 unsigned int uCmdDequeueIdx
;
710 unsigned int uCmdEnqueueIdx
;
711 unsigned int cbFreeCmdQueue
;
723 unsigned long ulTxPower
;
726 NDIS_802_11_WEP_STATUS eEncryptionStatus
;
729 //mike add :save old Encryption
730 NDIS_802_11_WEP_STATUS eOldEncryptionStatus
;
737 BYTE abyPRNG
[WLAN_WEPMAX_KEYLEN
+3];
743 unsigned int uKeyLength
;
744 BYTE abyKey
[WLAN_WEP232_KEYLEN
];
747 unsigned int uAssocCount
;
760 // For Update BaseBand VGA Gain Offset
762 unsigned int uBBVGADiffCount
;
765 BYTE abyBBVGA
[BB_VGA_LEVEL
];
766 signed long ldBmThreshold
[BB_VGA_LEVEL
];
773 DWORD dwDiagRefCount
;
778 // For Auto Power Tunning
780 BYTE byAutoPwrTunning
;
782 // BaseBand Loopback Use
789 struct timer_list sTimerCommand
;
791 struct timer_list sTimerTxData
;
792 unsigned long nTxDataTimeCout
;
794 BOOL IsTxDataTrigger
;
796 BOOL fWPA_Authened
; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
797 BYTE byReAssocCount
; //mike add:re-association retry times!
798 BYTE byLinkWaitCount
;
800 SEthernetHeader sTxEthHeader
;
801 SEthernetHeader sRxEthHeader
;
802 BYTE abyBroadcastAddr
[ETH_ALEN
];
803 BYTE abySNAP_RFC1042
[ETH_ALEN
];
804 BYTE abySNAP_Bridgetunnel
[ETH_ALEN
];
806 // Pre-Authentication & PMK cache
808 SPMKIDCandidateEvent gsPMKIDCandidate
;
816 BYTE byChannelSwitchCount
;
818 //WPA supplicant daemon
819 struct net_device
*wpadev
;
824 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
829 BOOL bWPASuppWextEnabled
;
833 // user space daemon: hostapd, is used for HOSTAP
837 struct net_device
*apdev
;
838 int (*tx_80211
)(struct sk_buff
*skb
, struct net_device
*dev
);
840 unsigned int uChannel
;
842 struct iw_statistics wstats
; // wireless stats
845 } DEVICE_INFO
, *PSDevice
;
850 #define EnqueueRCB(_Head, _Tail, _RCB) \
856 _Tail->Next = _RCB; \
862 #define DequeueRCB(Head, Tail) \
872 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
873 if ((uVar) >= ((uModulo) - 1)) \
880 #define fMP_RESET_IN_PROGRESS 0x00000001
881 #define fMP_DISCONNECTED 0x00000002
882 #define fMP_HALT_IN_PROGRESS 0x00000004
883 #define fMP_SURPRISE_REMOVED 0x00000008
884 #define fMP_RECV_LOOKASIDE 0x00000010
885 #define fMP_INIT_IN_PROGRESS 0x00000020
886 #define fMP_SEND_SIDE_RESOURCE_ALLOCATED 0x00000040
887 #define fMP_RECV_SIDE_RESOURCE_ALLOCATED 0x00000080
888 #define fMP_POST_READS 0x00000100
889 #define fMP_POST_WRITES 0x00000200
890 #define fMP_CONTROL_READS 0x00000400
891 #define fMP_CONTROL_WRITES 0x00000800
893 #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
894 #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
895 #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
897 #define MP_IS_READY(_M) (((_M)->Flags & \
898 (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_HALT_IN_PROGRESS | fMP_INIT_IN_PROGRESS | fMP_SURPRISE_REMOVED)) == 0)
900 /*--------------------- Export Functions --------------------------*/
902 /* BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb,
903 * unsigned int uNodeIndex);
905 BOOL
device_alloc_frag_buf(PSDevice pDevice
, PSDeFragControlBlock pDeF
);