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/delay.h>
36 #include <linux/device.h>
37 #include <linux/firmware.h>
38 #include <linux/etherdevice.h>
39 #include <linux/suspend.h>
40 #include <linux/if_arp.h>
41 #include <linux/wireless.h>
42 #include <net/iw_handler.h>
43 #include <net/cfg80211.h>
44 #include <linux/timer.h>
45 #include <linux/usb.h>
46 #include <linux/crc32.h>
49 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
50 #include <linux/ethtool.h>
52 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
70 #define VNT_USB_VENDOR_ID 0x160a
71 #define VNT_USB_PRODUCT_ID 0x3184
73 #define DEVICE_NAME "vt6656"
74 #define DEVICE_FULL_DRV_NAM "VIA Networking Wireless LAN USB Driver"
76 #define DEVICE_VERSION "1.19_12"
78 #define CONFIG_PATH "/etc/vntconfiguration.dat"
81 #define OPTION_DEFAULT { [0 ... MAX_UINTS-1] = -1}
83 #define DUPLICATE_RX_CACHE_LENGTH 5
85 #define AUTO_FB_NONE 0
95 #define ANT_DIVERSITY 2
98 #define ANT_UNKNOWN 0xFF
104 #define BB_VGA_LEVEL 4
105 #define BB_VGA_CHANGE_THRESHOLD 3
107 #define EEP_MAX_CONTEXT_SIZE 256
109 /* Contents in the EEPROM */
110 #define EEP_OFS_PAR 0x0
111 #define EEP_OFS_ANTENNA 0x17
112 #define EEP_OFS_RADIOCTL 0x18
113 #define EEP_OFS_RFTYPE 0x1b
114 #define EEP_OFS_MINCHANNEL 0x1c
115 #define EEP_OFS_MAXCHANNEL 0x1d
116 #define EEP_OFS_SIGNATURE 0x1e
117 #define EEP_OFS_ZONETYPE 0x1f
118 #define EEP_OFS_RFTABLE 0x20
119 #define EEP_OFS_PWR_CCK 0x20
120 #define EEP_OFS_SETPT_CCK 0x21
121 #define EEP_OFS_PWR_OFDMG 0x23
123 #define EEP_OFS_CALIB_TX_IQ 0x24
124 #define EEP_OFS_CALIB_TX_DC 0x25
125 #define EEP_OFS_CALIB_RX_IQ 0x26
127 #define EEP_OFS_MAJOR_VER 0x2e
128 #define EEP_OFS_MINOR_VER 0x2f
130 #define EEP_OFS_CCK_PWR_TBL 0x30
131 #define EEP_OFS_OFDM_PWR_TBL 0x40
132 #define EEP_OFS_OFDMA_PWR_TBL 0x50
134 /* Bits in EEP_OFS_ANTENNA */
135 #define EEP_ANTENNA_MAIN 0x1
136 #define EEP_ANTENNA_AUX 0x2
137 #define EEP_ANTINV 0x4
139 /* Bits in EEP_OFS_RADIOCTL */
140 #define EEP_RADIOCTL_ENABLE 0x80
142 /* control commands */
143 #define MESSAGE_TYPE_READ 0x1
144 #define MESSAGE_TYPE_WRITE 0x0
145 #define MESSAGE_TYPE_LOCK_OR 0x2
146 #define MESSAGE_TYPE_LOCK_AND 0x3
147 #define MESSAGE_TYPE_WRITE_MASK 0x4
148 #define MESSAGE_TYPE_CARDINIT 0x5
149 #define MESSAGE_TYPE_INIT_RSP 0x6
150 #define MESSAGE_TYPE_MACSHUTDOWN 0x7
151 #define MESSAGE_TYPE_SETKEY 0x8
152 #define MESSAGE_TYPE_CLRKEYENTRY 0x9
153 #define MESSAGE_TYPE_WRITE_MISCFF 0xa
154 #define MESSAGE_TYPE_SET_ANTMD 0xb
155 #define MESSAGE_TYPE_SELECT_CHANNLE 0xc
156 #define MESSAGE_TYPE_SET_TSFTBTT 0xd
157 #define MESSAGE_TYPE_SET_SSTIFS 0xe
158 #define MESSAGE_TYPE_CHANGE_BBTYPE 0xf
159 #define MESSAGE_TYPE_DISABLE_PS 0x10
160 #define MESSAGE_TYPE_WRITE_IFRF 0x11
162 /* command read/write(index) */
163 #define MESSAGE_REQUEST_MEM 0x1
164 #define MESSAGE_REQUEST_BBREG 0x2
165 #define MESSAGE_REQUEST_MACREG 0x3
166 #define MESSAGE_REQUEST_EEPROM 0x4
167 #define MESSAGE_REQUEST_TSF 0x5
168 #define MESSAGE_REQUEST_TBTT 0x6
169 #define MESSAGE_REQUEST_BBAGC 0x7
170 #define MESSAGE_REQUEST_VERSION 0x8
171 #define MESSAGE_REQUEST_RF_INIT 0x9
172 #define MESSAGE_REQUEST_RF_INIT2 0xa
173 #define MESSAGE_REQUEST_RF_CH0 0xb
174 #define MESSAGE_REQUEST_RF_CH1 0xc
175 #define MESSAGE_REQUEST_RF_CH2 0xd
178 #define USB_REG4 0x604
181 #define RUN_AT(x) (jiffies+(x))
184 #define PRIVATE_Message 0
186 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
187 #define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
189 typedef enum __device_msg_level {
190 MSG_LEVEL_ERR = 0, /* Errors causing abnormal operation */
191 MSG_LEVEL_NOTICE = 1, /* Errors needing user notification */
192 MSG_LEVEL_INFO = 2, /* Normal message. */
193 MSG_LEVEL_VERBOSE = 3, /* Will report all trival errors. */
194 MSG_LEVEL_DEBUG = 4 /* Only for debug purpose. */
195 } DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
197 #define DEVICE_INIT_COLD 0x0 /* cold init */
198 #define DEVICE_INIT_RESET 0x1 /* reset init or Dx to D0 power remain */
199 #define DEVICE_INIT_DXPL 0x2 /* Dx to D0 power lost init */
202 struct vnt_cmd_card_init {
204 u8 exist_sw_net_addr;
206 u8 short_retry_limit;
210 struct vnt_rsp_card_init {
221 * Enum of context types for SendPacket
224 CONTEXT_DATA_PACKET = 1,
228 /* RCB (Receive Control Block) */
234 struct vnt_rx_mgmt sMngPacket;
239 /* used to track bulk out irps */
240 struct vnt_usb_send_context {
244 unsigned int buf_len;
247 unsigned char data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
250 /* tx packet info for rxtx */
251 struct vnt_tx_pkt_info {
253 u8 dest_addr[ETH_ALEN];
256 /* structure got from configuration file as user-desired default settings */
257 typedef struct _DEFAULT_CONFIG {
259 signed int eConfigMode;
260 signed int eAuthenMode; /* open/wep/wpa */
261 signed int bShareKeyAlgorithm; /* open-open/{open,wep}-sharekey */
262 signed int keyidx; /* wepkey index */
263 signed int eEncryptionStatus;
264 } DEFAULT_CONFIG, *PDEFAULT_CONFIG;
267 * Structure to keep track of USB interrupt packets
269 struct vnt_interrupt_buffer {
276 typedef enum __DEVICE_NDIS_STATUS {
281 } DEVICE_NDIS_STATUS, *PDEVICE_NDIS_STATUS;
283 #define MAX_BSSIDINFO_4_PMKID 16
284 #define MAX_PMKIDLIST 5
285 /* flags for PMKID Candidate list structure */
286 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
288 /* PMKID Structures */
289 typedef unsigned char NDIS_802_11_PMKID_VALUE[16];
291 typedef enum _NDIS_802_11_WEP_STATUS
293 Ndis802_11WEPEnabled,
294 Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
295 Ndis802_11WEPDisabled,
296 Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
297 Ndis802_11WEPKeyAbsent,
298 Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
299 Ndis802_11WEPNotSupported,
300 Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
301 Ndis802_11Encryption2Enabled,
302 Ndis802_11Encryption2KeyAbsent,
303 Ndis802_11Encryption3Enabled,
304 Ndis802_11Encryption3KeyAbsent
305 } NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
306 NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
308 typedef enum _NDIS_802_11_STATUS_TYPE
310 Ndis802_11StatusType_Authentication,
311 Ndis802_11StatusType_MediaStreamMode,
312 Ndis802_11StatusType_PMKID_CandidateList,
313 Ndis802_11StatusTypeMax, /* not a real type, defined as upper bound */
314 } NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
316 /* added new types for PMKID Candidate lists */
317 typedef struct _PMKID_CANDIDATE {
318 NDIS_802_11_MAC_ADDRESS BSSID;
320 } PMKID_CANDIDATE, *PPMKID_CANDIDATE;
322 typedef struct _BSSID_INFO
324 NDIS_802_11_MAC_ADDRESS BSSID;
325 NDIS_802_11_PMKID_VALUE PMKID;
326 } BSSID_INFO, *PBSSID_INFO;
328 typedef struct tagSPMKID {
329 unsigned long Length;
330 unsigned long BSSIDInfoCount;
331 BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
334 typedef struct tagSPMKIDCandidateEvent {
335 NDIS_802_11_STATUS_TYPE StatusType;
336 unsigned long Version; /* Version of the structure */
337 unsigned long NumCandidates; /* No. of pmkid candidates */
338 PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST];
339 } SPMKIDCandidateEvent, *PSPMKIDCandidateEvent;
341 /* The receive duplicate detection cache entry */
342 typedef struct tagSCacheEntry{
344 u8 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
358 * DeFragment Control Block, used for collecting fragments prior to reassembly
360 typedef struct tagSDeFragControlBlock
364 u8 abyAddr2[ETH_ALEN];
365 unsigned int uLifetime;
368 unsigned int cbFrameLength;
370 } SDeFragControlBlock, *PSDeFragControlBlock;
372 /* flags for options */
373 #define DEVICE_FLAGS_UNPLUG 0x00000001UL
375 /* flags for driver status */
376 #define DEVICE_FLAGS_OPENED 0x00010000UL
378 typedef struct __device_opt {
379 int nRxDescs0; /* number of RX descriptors 0 */
380 int nTxDescs0; /* number of TX descriptors 0, 1, 2, 3 */
381 int rts_thresh; /* RTS threshold */
390 } OPTIONS, *POPTIONS;
394 struct usb_device *usb;
395 struct net_device *dev;
396 struct net_device_stats stats;
400 struct work_struct read_work_item;
401 struct work_struct rx_mng_work_item;
408 struct mutex usb_lock;
417 SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG];
423 struct urb *pInterruptURB;
426 /* Variables to track resources for the BULK In Pipe */
427 struct vnt_rcb *pRCBMem;
428 struct vnt_rcb *apRCB[CB_MAX_RX_DESC];
430 struct vnt_rcb *FirstRecvFreeList;
431 struct vnt_rcb *LastRecvFreeList;
433 struct vnt_rcb *FirstRecvMngList;
434 struct vnt_rcb *LastRecvMngList;
436 int bIsRxWorkItemQueued;
437 int bIsRxMngWorkItemQueued;
438 unsigned long ulRcvRefCount; /* packets that have not returned back */
440 /* Variables to track resources for the BULK Out Pipe */
441 struct vnt_usb_send_context *apTD[CB_MAX_TX_DESC];
443 struct vnt_tx_pkt_info pkt_info[16];
445 /* Variables to track resources for the Interrupt In Pipe */
446 struct vnt_interrupt_buffer int_buf;
448 /* default config from file by user setting */
449 DEFAULT_CONFIG config_file;
451 /* Version control */
452 u16 wFirmwareVersion;
460 u8 byOriginalZonetype;
462 int bLinkPass; /* link status: OK or fail */
463 struct vnt_cmd_card_init init_command;
464 struct vnt_rsp_card_init init_response;
465 u8 abyCurrentNetAddr[ETH_ALEN];
466 u8 abyPermanentNetAddr[ETH_ALEN];
470 /* Maintain statistical debug info. */
471 unsigned long SendContextsInUse;
472 unsigned long RcvBuffersInUse;
474 /* 802.11 management */
475 struct vnt_manager vnt_mgmt;
481 /* 802.11 MAC specific */
485 /* Antenna Diversity */
496 u32 uSIFS; /* Current SIFS */
497 u32 uDIFS; /* Current DIFS */
498 u32 uEIFS; /* Current EIFS */
499 u32 uSlot; /* Current SlotTime */
500 u32 uCwMin; /* Current CwMin */
501 u32 uCwMax; /* CwMax is fixed on 1023 */
511 u8 byBBType; /* 0: 11A, 1:11B, 2:11G */
512 u8 byPacketType; /* 0:11a 1:11b 2:11gb 3:11ga */
514 u8 byTopOFDMBasicRate;
515 u8 byTopCCKBasicRate;
517 u8 abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /*u32 alignment */
528 /* For RF Power table */
534 u8 abyOFDMPwrTbl[14];
535 u8 abyOFDMAPwrTbl[42];
542 u16 wFragmentationThreshold;
543 u8 byShortRetryLimit;
546 enum nl80211_iftype op_mode;
549 u16 wMaxTransmitMSDULifetime;
550 u8 abyBSSID[ETH_ALEN];
551 u8 abyDesireBSSID[ETH_ALEN];
553 u32 dwMaxReceiveLifetime; /* dot11MaxReceiveLifetime */
555 int bEncryptionEnable;
559 int bBarkerPreambleMd;
562 u16 wUseProtectCntDown;
564 int bRadioControlOff;
571 WMAC_POWER_MODE ePSMode;
572 unsigned long ulPSModeWaitTx;
575 /* Beacon releated */
582 CMD_STATE eCommandState;
591 u32 uAutoReConnectTime;
596 CMD_ITEM eCmdQueue[CMD_Q_SIZE];
613 NDIS_802_11_WEP_STATUS eEncryptionStatus;
615 NDIS_802_11_WEP_STATUS eOldEncryptionStatus;
620 u8 abyPRNG[WLAN_WEPMAX_KEYLEN+3];
624 u8 abyKey[WLAN_WEP232_KEYLEN];
638 /* For Update BaseBand VGA Gain Offset */
642 u8 abyBBVGA[BB_VGA_LEVEL];
643 signed long ldBmThreshold[BB_VGA_LEVEL];
651 struct delayed_work run_command_work;
652 /* One second callback */
653 struct delayed_work second_callback_work;
657 int fWPA_Authened; /*is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? */
661 struct ethhdr sTxEthHeader;
662 struct ethhdr sRxEthHeader;
663 u8 abyBroadcastAddr[ETH_ALEN];
664 u8 abySNAP_RFC1042[ETH_ALEN];
665 u8 abySNAP_Bridgetunnel[ETH_ALEN];
667 /* Pre-Authentication & PMK cache */
669 SPMKIDCandidateEvent gsPMKIDCandidate;
676 u8 byChannelSwitchCount;
678 /* WPA supplicant daemon */
684 int bWPASuppWextEnabled;
688 struct iw_statistics wstats; /* wireless stats */
694 #define EnqueueRCB(_Head, _Tail, _RCB) \
700 _Tail->Next = _RCB; \
706 #define DequeueRCB(Head, Tail) \
708 struct vnt_rcb *RCB = Head; \
715 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
716 if ((uVar) >= ((uModulo) - 1)) \
722 #define fMP_DISCONNECTED 0x00000002
723 #define fMP_POST_READS 0x00000100
724 #define fMP_POST_WRITES 0x00000200
726 #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
727 #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
728 #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
730 #define MP_IS_READY(_M) (((_M)->Flags & fMP_DISCONNECTED) == 0)
732 int device_alloc_frag_buf(struct vnt_private *, PSDeFragControlBlock pDeF);
733 void vnt_configure_filter(struct vnt_private *);