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/kernel.h>
34 #include <linux/slab.h>
35 #include <linux/init.h>
36 #include <linux/delay.h>
37 #include <linux/device.h>
38 #include <linux/firmware.h>
39 #include <linux/etherdevice.h>
40 #include <linux/suspend.h>
41 #include <linux/if_arp.h>
42 #include <linux/wireless.h>
43 #include <net/iw_handler.h>
44 #include <net/cfg80211.h>
45 #include <linux/timer.h>
46 #include <linux/usb.h>
50 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
51 #include <linux/ethtool.h>
53 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
56 /* please copy below macro to driver_event.c for API */
57 #define RT_INSMOD_EVENT_FLAG 0x0101
58 #define RT_UPDEV_EVENT_FLAG 0x0102
59 #define RT_DISCONNECTED_EVENT_FLAG 0x0103
60 #define RT_WPACONNECTED_EVENT_FLAG 0x0104
61 #define RT_DOWNDEV_EVENT_FLAG 0x0105
62 #define RT_RMMOD_EVENT_FLAG 0x0106
68 #include "device_cfg.h"
81 /*--------------------- Export Definitions -------------------------*/
82 #define VNT_USB_VENDOR_ID 0x160a
83 #define VNT_USB_PRODUCT_ID 0x3184
85 #define MAC_MAX_CONTEXT_REG (256+128)
87 #define MAX_MULTICAST_ADDRESS_NUM 32
88 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * ETH_ALEN)
90 #define DUPLICATE_RX_CACHE_LENGTH 5
92 #define NUM_KEY_ENTRY 11
97 #define TX_WEP_SWOTP 3
98 #define TX_WEP_OTPSW 4
99 #define TX_WEP_SW232 5
101 #define KEYSEL_WEP40 0
102 #define KEYSEL_WEP104 1
103 #define KEYSEL_TKIP 2
104 #define KEYSEL_CCMP 3
106 #define AUTO_FB_NONE 0
116 #define ANT_DIVERSITY 2
117 #define ANT_RXD_TXA 3
118 #define ANT_RXD_TXB 4
119 #define ANT_UNKNOWN 0xFF
126 #define MAXCHECKHANGCNT 4
129 #define TX_PKT_UNI 0x00
130 #define TX_PKT_MULTI 0x01
131 #define TX_PKT_BROAD 0x02
133 #define BB_VGA_LEVEL 4
134 #define BB_VGA_CHANGE_THRESHOLD 3
137 #define RUN_AT(x) (jiffies+(x))
141 #define RESERV_AC0DMA 4
143 #define PRIVATE_Message 0
145 /*--------------------- Export Types ------------------------------*/
147 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
148 #define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
150 typedef enum __device_msg_level {
151 MSG_LEVEL_ERR = 0, /* Errors causing abnormal operation */
152 MSG_LEVEL_NOTICE = 1, /* Errors needing user notification */
153 MSG_LEVEL_INFO = 2, /* Normal message. */
154 MSG_LEVEL_VERBOSE = 3, /* Will report all trival errors. */
155 MSG_LEVEL_DEBUG = 4 /* Only for debug purpose. */
156 } DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
158 typedef enum __device_init_type {
159 DEVICE_INIT_COLD = 0, /* cold init */
160 DEVICE_INIT_RESET, /* reset init or Dx to D0 power remain */
161 DEVICE_INIT_DXPL /* Dx to D0 power lost init */
162 } DEVICE_INIT_TYPE, *PDEVICE_INIT_TYPE;
167 * Enum of context types for SendPacket
169 typedef enum _CONTEXT_TYPE {
170 CONTEXT_DATA_PACKET = 1,
174 /* RCB (Receive Control Block) */
181 struct vnt_rx_mgmt sMngPacket;
187 /* used to track bulk out irps */
188 typedef struct _USB_SEND_CONTEXT {
190 struct sk_buff *pPacket;
192 unsigned int uBufLen;
194 SEthernetHeader sEthHeader;
197 unsigned char Data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
198 } USB_SEND_CONTEXT, *PUSB_SEND_CONTEXT;
200 /* structure got from configuration file as user-desired default settings */
201 typedef struct _DEFAULT_CONFIG {
203 signed int eConfigMode;
204 signed int eAuthenMode; /* open/wep/wpa */
205 signed int bShareKeyAlgorithm; /* open-open/{open,wep}-sharekey */
206 signed int keyidx; /* wepkey index */
207 signed int eEncryptionStatus;
208 } DEFAULT_CONFIG, *PDEFAULT_CONFIG;
211 * Structure to keep track of USB interrupt packets
214 unsigned int uDataLen;
216 /* struct urb *pUrb; */
218 } INT_BUFFER, *PINT_BUFFER;
220 /* 0:11A 1:11B 2:11G */
221 typedef enum _VIA_BB_TYPE
226 } VIA_BB_TYPE, *PVIA_BB_TYPE;
228 /* 0:11a, 1:11b, 2:11gb (only CCK in BasicRate), 3:11ga(OFDM in BasicRate) */
229 typedef enum _VIA_PKT_TYPE
235 } VIA_PKT_TYPE, *PVIA_PKT_TYPE;
239 typedef enum __DEVICE_NDIS_STATUS {
244 } DEVICE_NDIS_STATUS, *PDEVICE_NDIS_STATUS;
246 #define MAX_BSSIDINFO_4_PMKID 16
247 #define MAX_PMKIDLIST 5
248 /* flags for PMKID Candidate list structure */
249 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
251 /* PMKID Structures */
252 typedef unsigned char NDIS_802_11_PMKID_VALUE[16];
255 typedef enum _NDIS_802_11_WEP_STATUS
257 Ndis802_11WEPEnabled,
258 Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
259 Ndis802_11WEPDisabled,
260 Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
261 Ndis802_11WEPKeyAbsent,
262 Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
263 Ndis802_11WEPNotSupported,
264 Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
265 Ndis802_11Encryption2Enabled,
266 Ndis802_11Encryption2KeyAbsent,
267 Ndis802_11Encryption3Enabled,
268 Ndis802_11Encryption3KeyAbsent
269 } NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
270 NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
273 typedef enum _NDIS_802_11_STATUS_TYPE
275 Ndis802_11StatusType_Authentication,
276 Ndis802_11StatusType_MediaStreamMode,
277 Ndis802_11StatusType_PMKID_CandidateList,
278 Ndis802_11StatusTypeMax, /* not a real type, defined as upper bound */
279 } NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
281 /* added new types for PMKID Candidate lists */
282 typedef struct _PMKID_CANDIDATE {
283 NDIS_802_11_MAC_ADDRESS BSSID;
285 } PMKID_CANDIDATE, *PPMKID_CANDIDATE;
288 typedef struct _BSSID_INFO
290 NDIS_802_11_MAC_ADDRESS BSSID;
291 NDIS_802_11_PMKID_VALUE PMKID;
292 } BSSID_INFO, *PBSSID_INFO;
294 typedef struct tagSPMKID {
295 unsigned long Length;
296 unsigned long BSSIDInfoCount;
297 BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
300 typedef struct tagSPMKIDCandidateEvent {
301 NDIS_802_11_STATUS_TYPE StatusType;
302 unsigned long Version; /* Version of the structure */
303 unsigned long NumCandidates; /* No. of pmkid candidates */
304 PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST];
305 } SPMKIDCandidateEvent, *PSPMKIDCandidateEvent;
307 /*++ 802.11h related */
308 #define MAX_QUIET_COUNT 8
310 typedef struct tagSQuietControl {
315 } SQuietControl, *PSQuietControl;
317 /* The receive duplicate detection cache entry */
318 typedef struct tagSCacheEntry{
320 BYTE abyAddr2[ETH_ALEN];
322 } SCacheEntry, *PSCacheEntry;
324 typedef struct tagSCache{
325 /* The receive cache is updated circularly. The next entry to be written is
326 * indexed by the "InPtr".
328 unsigned int uInPtr; /* Place to use next */
329 SCacheEntry asCacheEntry[DUPLICATE_RX_CACHE_LENGTH];
332 #define CB_MAX_RX_FRAG 64
334 * DeFragment Control Block, used for collecting fragments prior to reassembly
336 typedef struct tagSDeFragControlBlock
340 BYTE abyAddr2[ETH_ALEN];
341 unsigned int uLifetime;
344 unsigned int cbFrameLength;
346 } SDeFragControlBlock, *PSDeFragControlBlock;
348 /* flags for options */
349 #define DEVICE_FLAGS_UNPLUG 0x00000001UL
350 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
351 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
352 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
353 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
355 /* flags for driver status */
356 #define DEVICE_FLAGS_OPENED 0x00010000UL
357 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
358 /* flags for capabilities */
359 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
360 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
361 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
363 /* flags for MII status */
364 #define DEVICE_LINK_FAIL 0x00000001UL
365 #define DEVICE_SPEED_10 0x00000002UL
366 #define DEVICE_SPEED_100 0x00000004UL
367 #define DEVICE_SPEED_1000 0x00000008UL
368 #define DEVICE_DUPLEX_FULL 0x00000010UL
369 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
370 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
371 /* for device_set_media_duplex */
372 #define DEVICE_LINK_CHANGE 0x00000001UL
375 typedef struct __device_opt {
376 int nRxDescs0; /* number of RX descriptors 0 */
377 int nTxDescs0; /* number of TX descriptors 0, 1, 2, 3 */
378 int rts_thresh; /* RTS threshold */
387 } OPTIONS, *POPTIONS;
392 struct usb_device *usb;
393 struct net_device *dev;
394 struct net_device_stats stats;
398 struct tasklet_struct CmdWorkItem;
399 struct tasklet_struct EventWorkItem;
400 struct tasklet_struct ReadWorkItem;
401 struct tasklet_struct RxMngWorkItem;
418 SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG];
425 struct urb *pControlURB;
426 struct urb *pInterruptURB;
427 struct usb_ctrlrequest sUsbCtlRequest;
430 /* Variables to track resources for the BULK In Pipe */
432 PRCB apRCB[CB_MAX_RX_DESC];
434 PRCB FirstRecvFreeList;
435 PRCB LastRecvFreeList;
437 PRCB FirstRecvMngList;
438 PRCB LastRecvMngList;
440 int bIsRxWorkItemQueued;
441 int bIsRxMngWorkItemQueued;
442 unsigned long ulRcvRefCount; /* packets that have not returned back */
444 /* Variables to track resources for the BULK Out Pipe */
445 PUSB_SEND_CONTEXT apTD[CB_MAX_TX_DESC];
448 /* Variables to track resources for the Interrupt In Pipe */
450 int fKillEventPollingThread;
453 /* default config from file by user setting */
454 DEFAULT_CONFIG config_file;
457 /* Statistic for USB */
458 unsigned long ulBulkInPosted;
459 unsigned long ulBulkInError;
460 unsigned long ulBulkInContCRCError;
461 unsigned long ulBulkInBytesRead;
463 unsigned long ulBulkOutPosted;
464 unsigned long ulBulkOutError;
465 unsigned long ulBulkOutContCRCError;
466 unsigned long ulBulkOutBytesWrite;
468 unsigned long ulIntInPosted;
469 unsigned long ulIntInError;
470 unsigned long ulIntInContCRCError;
471 unsigned long ulIntInBytesRead;
474 /* Version control */
475 u16 wFirmwareVersion;
484 u8 byOriginalZonetype;
486 int bLinkPass; /* link status: OK or fail */
487 u8 abyCurrentNetAddr[ETH_ALEN];
488 u8 abyPermanentNetAddr[ETH_ALEN];
492 /* Adapter statistics */
493 SStatCounter scStatistic;
495 SDot11Counters s802_11Counter;
497 /* Maintain statistical debug info. */
498 unsigned long packetsReceived;
499 unsigned long packetsReceivedDropped;
500 unsigned long packetsReceivedOverflow;
501 unsigned long packetsSent;
502 unsigned long packetsSentDropped;
503 unsigned long SendContextsInUse;
504 unsigned long RcvBuffersInUse;
506 /* 802.11 management */
507 struct vnt_manager vnt_mgmt;
513 /* 802.11 MAC specific */
517 /* Antenna Diversity */
527 /* SQ3 functions for antenna diversity */
528 struct timer_list TimerSQ3Tmax1;
529 struct timer_list TimerSQ3Tmax2;
530 struct timer_list TimerSQ3Tmax3;
532 int bDiversityRegCtlON;
533 int bDiversityEnable;
534 unsigned long ulDiversityNValue;
535 unsigned long ulDiversityMValue;
539 unsigned long ulSQ3TH;
541 unsigned long uDiversityCnt;
543 unsigned long ulRatio_State0;
544 unsigned long ulRatio_State1;
545 unsigned long ulSQ3_State0;
546 unsigned long ulSQ3_State1;
548 unsigned long aulSQ3Val[MAX_RATE];
549 unsigned long aulPktNum[MAX_RATE];
552 u32 uSIFS; /* Current SIFS */
553 u32 uDIFS; /* Current DIFS */
554 u32 uEIFS; /* Current EIFS */
555 u32 uSlot; /* Current SlotTime */
556 u32 uCwMin; /* Current CwMin */
557 u32 uCwMax; /* CwMax is fixed on 1023 */
567 VIA_BB_TYPE byBBType; /* 0: 11A, 1:11B, 2:11G */
568 VIA_PKT_TYPE byPacketType; /* 0:11a 1:11b 2:11gb 3:11ga */
571 u8 byTopOFDMBasicRate;
572 u8 byTopCCKBasicRate;
575 u32 dwAotoRateTxOkCnt;
576 u32 dwAotoRateTxFailCnt;
577 u32 dwErrorRateThreshold[13];
578 u32 dwTPTable[MAX_RATE];
579 u8 abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /*u32 alignment */
590 /* For RF Power table */
596 u8 abyOFDMPwrTbl[14];
597 u8 abyOFDMAPwrTbl[42];
601 u16 wFragmentationThreshold;
602 u8 byShortRetryLimit;
604 CARD_OP_MODE eOPMode;
606 u16 wMaxTransmitMSDULifetime;
607 u8 abyBSSID[ETH_ALEN];
608 u8 abyDesireBSSID[ETH_ALEN];
610 u16 wCTSDuration; /* update while speed change */
613 u8 byRTSServiceField;
616 u32 dwMaxReceiveLifetime; /* dot11MaxReceiveLifetime */
619 int bEncryptionEnable;
621 int bSoftwareGenCrcErr;
625 int bBarkerPreambleMd;
628 u16 wUseProtectCntDown;
630 int bRadioControlOff;
637 WMAC_POWER_MODE ePSMode;
638 unsigned long ulPSModeWaitTx;
641 /* Beacon releated */
649 CMD_STATE eCommandState;
658 u32 uAutoReConnectTime;
663 CMD_ITEM eCmdQueue[CMD_Q_SIZE];
678 unsigned long ulTxPower;
681 NDIS_802_11_WEP_STATUS eEncryptionStatus;
683 NDIS_802_11_WEP_STATUS eOldEncryptionStatus;
689 u8 abyPRNG[WLAN_WEPMAX_KEYLEN+3];
695 u8 abyKey[WLAN_WEP232_KEYLEN];
711 /* For Update BaseBand VGA Gain Offset */
716 u8 abyBBVGA[BB_VGA_LEVEL];
717 signed long ldBmThreshold[BB_VGA_LEVEL];
729 /* For Auto Power Tunning */
732 /* BaseBand Loopback Use */
739 struct timer_list sTimerCommand;
741 struct timer_list sTimerTxData;
742 unsigned long nTxDataTimeCout;
746 int fWPA_Authened; /*is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? */
750 SEthernetHeader sTxEthHeader;
751 SEthernetHeader sRxEthHeader;
752 u8 abyBroadcastAddr[ETH_ALEN];
753 u8 abySNAP_RFC1042[ETH_ALEN];
754 u8 abySNAP_Bridgetunnel[ETH_ALEN];
756 /* Pre-Authentication & PMK cache */
758 SPMKIDCandidateEvent gsPMKIDCandidate;
766 u8 byChannelSwitchCount;
768 /* WPA supplicant daemon */
774 int bWPASuppWextEnabled;
776 /* user space daemon: hostapd, is used for HOSTAP */
780 struct net_device *apdev;
781 int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
785 struct iw_statistics wstats; /* wireless stats */
794 #define EnqueueRCB(_Head, _Tail, _RCB) \
800 _Tail->Next = _RCB; \
806 #define DequeueRCB(Head, Tail) \
816 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
817 if ((uVar) >= ((uModulo) - 1)) \
824 #define fMP_RESET_IN_PROGRESS 0x00000001
825 #define fMP_DISCONNECTED 0x00000002
826 #define fMP_HALT_IN_PROGRESS 0x00000004
827 #define fMP_SURPRISE_REMOVED 0x00000008
828 #define fMP_RECV_LOOKASIDE 0x00000010
829 #define fMP_INIT_IN_PROGRESS 0x00000020
830 #define fMP_SEND_SIDE_RESOURCE_ALLOCATED 0x00000040
831 #define fMP_RECV_SIDE_RESOURCE_ALLOCATED 0x00000080
832 #define fMP_POST_READS 0x00000100
833 #define fMP_POST_WRITES 0x00000200
834 #define fMP_CONTROL_READS 0x00000400
835 #define fMP_CONTROL_WRITES 0x00000800
837 #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
838 #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
839 #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
841 #define MP_IS_READY(_M) (((_M)->Flags & \
842 (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_HALT_IN_PROGRESS | fMP_INIT_IN_PROGRESS | fMP_SURPRISE_REMOVED)) == 0)
844 /*--------------------- Export Functions --------------------------*/
846 int device_alloc_frag_buf(struct vnt_private *, PSDeFragControlBlock pDeF);