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 DUPLICATE_RX_CACHE_LENGTH 5
111 #define NUM_KEY_ENTRY 11
113 #define TX_WEP_NONE 0
116 #define TX_WEP_SWOTP 3
117 #define TX_WEP_OTPSW 4
118 #define TX_WEP_SW232 5
120 #define KEYSEL_WEP40 0
121 #define KEYSEL_WEP104 1
122 #define KEYSEL_TKIP 2
123 #define KEYSEL_CCMP 3
125 #define AUTO_FB_NONE 0
135 #define ANT_DIVERSITY 2
136 #define ANT_RXD_TXA 3
137 #define ANT_RXD_TXB 4
138 #define ANT_UNKNOWN 0xFF
145 #define MAXCHECKHANGCNT 4
148 #define TX_PKT_UNI 0x00
149 #define TX_PKT_MULTI 0x01
150 #define TX_PKT_BROAD 0x02
152 #define BB_VGA_LEVEL 4
153 #define BB_VGA_CHANGE_THRESHOLD 3
156 #define RUN_AT(x) (jiffies+(x))
160 #define RESERV_AC0DMA 4
162 #define PRIVATE_Message 0
164 /*--------------------- Export Types ------------------------------*/
166 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
167 #define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
169 typedef enum __device_msg_level {
170 MSG_LEVEL_ERR = 0, /* Errors causing abnormal operation */
171 MSG_LEVEL_NOTICE = 1, /* Errors needing user notification */
172 MSG_LEVEL_INFO = 2, /* Normal message. */
173 MSG_LEVEL_VERBOSE = 3, /* Will report all trival errors. */
174 MSG_LEVEL_DEBUG = 4 /* Only for debug purpose. */
175 } DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
177 typedef enum __device_init_type {
178 DEVICE_INIT_COLD = 0, /* cold init */
179 DEVICE_INIT_RESET, /* reset init or Dx to D0 power remain */
180 DEVICE_INIT_DXPL /* Dx to D0 power lost init */
181 } DEVICE_INIT_TYPE, *PDEVICE_INIT_TYPE;
186 // Enum of context types for SendPacket
188 typedef enum _CONTEXT_TYPE {
189 CONTEXT_DATA_PACKET = 1,
193 // RCB (Receive Control Block)
200 SRxMgmtPacket sMngPacket;
206 // used to track bulk out irps
207 typedef struct _USB_SEND_CONTEXT {
209 struct sk_buff *pPacket;
211 unsigned int uBufLen;
213 SEthernetHeader sEthHeader;
216 unsigned char Data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
217 } USB_SEND_CONTEXT, *PUSB_SEND_CONTEXT;
219 /* structure got from configuration file as user-desired default settings */
220 typedef struct _DEFAULT_CONFIG {
222 signed int eConfigMode;
223 signed int eAuthenMode; /* open/wep/wpa */
224 signed int bShareKeyAlgorithm; /* open-open/{open,wep}-sharekey */
225 signed int keyidx; /* wepkey index */
226 signed int eEncryptionStatus;
227 } DEFAULT_CONFIG, *PDEFAULT_CONFIG;
230 // Structure to keep track of usb interrupt packets
233 unsigned int uDataLen;
237 } INT_BUFFER, *PINT_BUFFER;
240 typedef enum _VIA_BB_TYPE
245 } VIA_BB_TYPE, *PVIA_BB_TYPE;
247 //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
248 typedef enum _VIA_PKT_TYPE
254 } VIA_PKT_TYPE, *PVIA_PKT_TYPE;
258 typedef enum __DEVICE_NDIS_STATUS {
263 } DEVICE_NDIS_STATUS, *PDEVICE_NDIS_STATUS;
265 #define MAX_BSSIDINFO_4_PMKID 16
266 #define MAX_PMKIDLIST 5
267 //Flags for PMKID Candidate list structure
268 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
271 typedef unsigned char NDIS_802_11_PMKID_VALUE[16];
274 typedef enum _NDIS_802_11_WEP_STATUS
276 Ndis802_11WEPEnabled,
277 Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
278 Ndis802_11WEPDisabled,
279 Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
280 Ndis802_11WEPKeyAbsent,
281 Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
282 Ndis802_11WEPNotSupported,
283 Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
284 Ndis802_11Encryption2Enabled,
285 Ndis802_11Encryption2KeyAbsent,
286 Ndis802_11Encryption3Enabled,
287 Ndis802_11Encryption3KeyAbsent
288 } NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
289 NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
292 typedef enum _NDIS_802_11_STATUS_TYPE
294 Ndis802_11StatusType_Authentication,
295 Ndis802_11StatusType_MediaStreamMode,
296 Ndis802_11StatusType_PMKID_CandidateList,
297 Ndis802_11StatusTypeMax // not a real type, defined as an upper bound
298 } NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
300 //Added new types for PMKID Candidate lists.
301 typedef struct _PMKID_CANDIDATE {
302 NDIS_802_11_MAC_ADDRESS BSSID;
304 } PMKID_CANDIDATE, *PPMKID_CANDIDATE;
307 typedef struct _BSSID_INFO
309 NDIS_802_11_MAC_ADDRESS BSSID;
310 NDIS_802_11_PMKID_VALUE PMKID;
311 } BSSID_INFO, *PBSSID_INFO;
313 typedef struct tagSPMKID {
314 unsigned long Length;
315 unsigned long BSSIDInfoCount;
316 BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
319 typedef struct tagSPMKIDCandidateEvent {
320 NDIS_802_11_STATUS_TYPE StatusType;
321 unsigned long Version; /* Version of the structure */
322 unsigned long NumCandidates; /* No. of pmkid candidates */
323 PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST];
324 } SPMKIDCandidateEvent, *PSPMKIDCandidateEvent;
329 #define MAX_QUIET_COUNT 8
331 typedef struct tagSQuietControl {
336 } SQuietControl, *PSQuietControl;
341 // The receive duplicate detection cache entry
342 typedef struct tagSCacheEntry{
344 BYTE abyAddr2[ETH_ALEN];
346 } SCacheEntry, *PSCacheEntry;
348 typedef struct tagSCache{
349 /* The receive cache is updated circularly. The next entry to be written is
350 * indexed by the "InPtr".
352 unsigned int uInPtr; /* Place to use next */
353 SCacheEntry asCacheEntry[DUPLICATE_RX_CACHE_LENGTH];
356 #define CB_MAX_RX_FRAG 64
357 // DeFragment Control Block, used for collecting fragments prior to reassembly
358 typedef struct tagSDeFragControlBlock
362 BYTE abyAddr2[ETH_ALEN];
363 unsigned int uLifetime;
366 unsigned int cbFrameLength;
368 } SDeFragControlBlock, *PSDeFragControlBlock;
373 #define DEVICE_FLAGS_UNPLUG 0x00000001UL
374 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
375 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
376 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
377 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
379 //flags for driver status
380 #define DEVICE_FLAGS_OPENED 0x00010000UL
381 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
382 //flags for capbilities
383 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
384 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
385 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
387 //flags for MII status
388 #define DEVICE_LINK_FAIL 0x00000001UL
389 #define DEVICE_SPEED_10 0x00000002UL
390 #define DEVICE_SPEED_100 0x00000004UL
391 #define DEVICE_SPEED_1000 0x00000008UL
392 #define DEVICE_DUPLEX_FULL 0x00000010UL
393 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
394 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
395 //for device_set_media_duplex
396 #define DEVICE_LINK_CHANGE 0x00000001UL
399 typedef struct __device_opt {
400 int nRxDescs0; //Number of RX descriptors0
401 int nTxDescs0; //Number of TX descriptors 0, 1, 2, 3
402 int rts_thresh; //rts threshold
411 } OPTIONS, *POPTIONS;
414 typedef struct __device_info {
417 struct usb_device* usb;
418 struct net_device* dev;
419 struct net_device_stats stats;
421 const struct firmware *firmware;
425 struct tasklet_struct CmdWorkItem;
426 struct tasklet_struct EventWorkItem;
427 struct tasklet_struct ReadWorkItem;
428 struct tasklet_struct RxMngWorkItem;
445 SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG];
447 unsigned int cbFreeDFCB;
448 unsigned int uCurrentDFCBIdx;
452 struct urb *pControlURB;
453 struct urb *pInterruptURB;
454 struct usb_ctrlrequest sUsbCtlRequest;
456 unsigned int int_interval;
458 // Variables to track resources for the BULK In Pipe
461 PRCB apRCB[CB_MAX_RX_DESC];
463 PRCB FirstRecvFreeList;
464 PRCB LastRecvFreeList;
465 unsigned int NumRecvFreeList;
466 PRCB FirstRecvMngList;
467 PRCB LastRecvMngList;
468 unsigned int NumRecvMngList;
469 BOOL bIsRxWorkItemQueued;
470 BOOL bIsRxMngWorkItemQueued;
471 unsigned long ulRcvRefCount; /* packets that have not returned back */
474 // Variables to track resources for the BULK Out Pipe
477 PUSB_SEND_CONTEXT apTD[CB_MAX_TX_DESC];
481 // Variables to track resources for the Interript In Pipe
484 BOOL fKillEventPollingThread;
485 BOOL bEventAvailable;
488 //default config from file by user setting
489 DEFAULT_CONFIG config_file;
494 // protect with spinlock
495 unsigned long ulBulkInPosted;
496 unsigned long ulBulkInError;
497 unsigned long ulBulkInContCRCError;
498 unsigned long ulBulkInBytesRead;
500 unsigned long ulBulkOutPosted;
501 unsigned long ulBulkOutError;
502 unsigned long ulBulkOutContCRCError;
503 unsigned long ulBulkOutBytesWrite;
505 unsigned long ulIntInPosted;
506 unsigned long ulIntInError;
507 unsigned long ulIntInContCRCError;
508 unsigned long ulIntInBytesRead;
512 WORD wFirmwareVersion;
521 BYTE byOriginalZonetype;
523 BOOL bLinkPass; // link status: OK or fail
524 BYTE abyCurrentNetAddr[ETH_ALEN];
525 BYTE abyPermanentNetAddr[ETH_ALEN];
526 // SW network address
527 /* u8 abySoftwareNetAddr[ETH_ALEN]; */
528 BOOL bExistSWNetAddr;
530 // Adapter statistics
531 SStatCounter scStatistic;
533 SDot11Counters s802_11Counter;
536 // Maintain statistical debug info.
538 unsigned long packetsReceived;
539 unsigned long packetsReceivedDropped;
540 unsigned long packetsReceivedOverflow;
541 unsigned long packetsSent;
542 unsigned long packetsSentDropped;
543 unsigned long SendContextsInUse;
544 unsigned long RcvBuffersInUse;
548 SMgmtObject sMgmtObj;
551 unsigned int cbBulkInMax;
554 // 802.11 MAC specific
555 unsigned int uCurrRSSI;
561 DWORD dwRxAntennaSel;
562 DWORD dwTxAntennaSel;
564 BYTE byRxAntennaMode;
565 BYTE byTxAntennaMode;
569 //SQ3 functions for antenna diversity
570 struct timer_list TimerSQ3Tmax1;
571 struct timer_list TimerSQ3Tmax2;
572 struct timer_list TimerSQ3Tmax3;
574 BOOL bDiversityRegCtlON;
575 BOOL bDiversityEnable;
576 unsigned long ulDiversityNValue;
577 unsigned long ulDiversityMValue;
581 unsigned long ulSQ3TH;
583 unsigned long uDiversityCnt;
585 unsigned long ulRatio_State0;
586 unsigned long ulRatio_State1;
587 unsigned long ulSQ3_State0;
588 unsigned long ulSQ3_State1;
590 unsigned long aulSQ3Val[MAX_RATE];
591 unsigned long aulPktNum[MAX_RATE];
594 unsigned int uSIFS; /* Current SIFS */
595 unsigned int uDIFS; /* Current DIFS */
596 unsigned int uEIFS; /* Current EIFS */
597 unsigned int uSlot; /* Current SlotTime */
598 unsigned int uCwMin; /* Current CwMin */
599 unsigned int uCwMax; /* CwMax is fixed on 1023 */
609 VIA_BB_TYPE byBBType; //0: 11A, 1:11B, 2:11G
610 VIA_PKT_TYPE byPacketType; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
613 BYTE byTopOFDMBasicRate;
614 BYTE byTopCCKBasicRate;
617 DWORD dwAotoRateTxOkCnt;
618 DWORD dwAotoRateTxFailCnt;
619 DWORD dwErrorRateThreshold[13];
620 DWORD dwTPTable[MAX_RATE];
621 BYTE abyEEPROM[EEP_MAX_CONTEXT_SIZE]; //DWORD alignment
625 unsigned int uConnectionRate;
628 BYTE byShortPreamble;
632 // For RF Power table
637 BYTE abyCCKPwrTbl[14];
638 BYTE abyOFDMPwrTbl[14];
639 BYTE abyOFDMAPwrTbl[42];
643 WORD wFragmentationThreshold;
644 BYTE byShortRetryLimit;
645 BYTE byLongRetryLimit;
646 CARD_OP_MODE eOPMode;
648 WORD wMaxTransmitMSDULifetime;
649 BYTE abyBSSID[ETH_ALEN];
650 BYTE abyDesireBSSID[ETH_ALEN];
651 WORD wCTSDuration; // update while speed change
652 WORD wACKDuration; // update while speed change
653 WORD wRTSTransmitLen; // update while speed change
654 BYTE byRTSServiceField; // update while speed change
655 BYTE byRTSSignalField; // update while speed change
657 DWORD dwMaxReceiveLifetime; // dot11MaxReceiveLifetime
660 BOOL bEncryptionEnable;
662 BOOL bSoftwareGenCrcErr;
666 BOOL bBarkerPreambleMd;
669 WORD wUseProtectCntDown;
671 BOOL bRadioControlOff;
676 WORD wListenInterval;
678 WMAC_POWER_MODE ePSMode;
679 unsigned long ulPSModeWaitTx;
684 BOOL bBeaconBufReady;
688 unsigned int uScanTime;
690 CMD_STATE eCommandState;
699 unsigned int uAutoReConnectTime;
700 unsigned int uIsroamingTime;
704 CMD_ITEM eCmdQueue[CMD_Q_SIZE];
705 unsigned int uCmdDequeueIdx;
706 unsigned int uCmdEnqueueIdx;
707 unsigned int cbFreeCmdQueue;
719 unsigned long ulTxPower;
722 NDIS_802_11_WEP_STATUS eEncryptionStatus;
725 //mike add :save old Encryption
726 NDIS_802_11_WEP_STATUS eOldEncryptionStatus;
733 BYTE abyPRNG[WLAN_WEPMAX_KEYLEN+3];
739 unsigned int uKeyLength;
740 BYTE abyKey[WLAN_WEP232_KEYLEN];
743 unsigned int uAssocCount;
756 // For Update BaseBand VGA Gain Offset
758 unsigned int uBBVGADiffCount;
761 BYTE abyBBVGA[BB_VGA_LEVEL];
762 signed long ldBmThreshold[BB_VGA_LEVEL];
769 DWORD dwDiagRefCount;
774 // For Auto Power Tunning
776 BYTE byAutoPwrTunning;
778 // BaseBand Loopback Use
785 struct timer_list sTimerCommand;
787 struct timer_list sTimerTxData;
788 unsigned long nTxDataTimeCout;
790 BOOL IsTxDataTrigger;
792 BOOL fWPA_Authened; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
793 BYTE byReAssocCount; //mike add:re-association retry times!
794 BYTE byLinkWaitCount;
796 SEthernetHeader sTxEthHeader;
797 SEthernetHeader sRxEthHeader;
798 BYTE abyBroadcastAddr[ETH_ALEN];
799 BYTE abySNAP_RFC1042[ETH_ALEN];
800 BYTE abySNAP_Bridgetunnel[ETH_ALEN];
802 // Pre-Authentication & PMK cache
804 SPMKIDCandidateEvent gsPMKIDCandidate;
812 BYTE byChannelSwitchCount;
814 //WPA supplicant daemon
815 struct net_device *wpadev;
820 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
825 BOOL bWPASuppWextEnabled;
829 // user space daemon: hostapd, is used for HOSTAP
833 struct net_device *apdev;
834 int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
836 unsigned int uChannel;
838 struct iw_statistics wstats; // wireless stats
841 } DEVICE_INFO, *PSDevice;
846 #define EnqueueRCB(_Head, _Tail, _RCB) \
852 _Tail->Next = _RCB; \
858 #define DequeueRCB(Head, Tail) \
868 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
869 if ((uVar) >= ((uModulo) - 1)) \
876 #define fMP_RESET_IN_PROGRESS 0x00000001
877 #define fMP_DISCONNECTED 0x00000002
878 #define fMP_HALT_IN_PROGRESS 0x00000004
879 #define fMP_SURPRISE_REMOVED 0x00000008
880 #define fMP_RECV_LOOKASIDE 0x00000010
881 #define fMP_INIT_IN_PROGRESS 0x00000020
882 #define fMP_SEND_SIDE_RESOURCE_ALLOCATED 0x00000040
883 #define fMP_RECV_SIDE_RESOURCE_ALLOCATED 0x00000080
884 #define fMP_POST_READS 0x00000100
885 #define fMP_POST_WRITES 0x00000200
886 #define fMP_CONTROL_READS 0x00000400
887 #define fMP_CONTROL_WRITES 0x00000800
889 #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
890 #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
891 #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
893 #define MP_IS_READY(_M) (((_M)->Flags & \
894 (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_HALT_IN_PROGRESS | fMP_INIT_IN_PROGRESS | fMP_SURPRISE_REMOVED)) == 0)
896 /*--------------------- Export Functions --------------------------*/
898 /* BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb,
899 * unsigned int uNodeIndex);
901 BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF);