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>
47 #include <net/mac80211.h>
50 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
51 #include <linux/ethtool.h>
53 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
71 #define VNT_USB_VENDOR_ID 0x160a
72 #define VNT_USB_PRODUCT_ID 0x3184
74 #define DEVICE_NAME "vt6656"
75 #define DEVICE_FULL_DRV_NAM "VIA Networking Wireless LAN USB Driver"
77 #define DEVICE_VERSION "1.19_12"
79 #define CONFIG_PATH "/etc/vntconfiguration.dat"
82 #define OPTION_DEFAULT { [0 ... MAX_UINTS-1] = -1}
84 #define DUPLICATE_RX_CACHE_LENGTH 5
86 #define AUTO_FB_NONE 0
96 #define ANT_DIVERSITY 2
99 #define ANT_UNKNOWN 0xFF
105 #define BB_VGA_LEVEL 4
106 #define BB_VGA_CHANGE_THRESHOLD 3
108 #define EEP_MAX_CONTEXT_SIZE 256
110 /* Contents in the EEPROM */
111 #define EEP_OFS_PAR 0x0
112 #define EEP_OFS_ANTENNA 0x17
113 #define EEP_OFS_RADIOCTL 0x18
114 #define EEP_OFS_RFTYPE 0x1b
115 #define EEP_OFS_MINCHANNEL 0x1c
116 #define EEP_OFS_MAXCHANNEL 0x1d
117 #define EEP_OFS_SIGNATURE 0x1e
118 #define EEP_OFS_ZONETYPE 0x1f
119 #define EEP_OFS_RFTABLE 0x20
120 #define EEP_OFS_PWR_CCK 0x20
121 #define EEP_OFS_SETPT_CCK 0x21
122 #define EEP_OFS_PWR_OFDMG 0x23
124 #define EEP_OFS_CALIB_TX_IQ 0x24
125 #define EEP_OFS_CALIB_TX_DC 0x25
126 #define EEP_OFS_CALIB_RX_IQ 0x26
128 #define EEP_OFS_MAJOR_VER 0x2e
129 #define EEP_OFS_MINOR_VER 0x2f
131 #define EEP_OFS_CCK_PWR_TBL 0x30
132 #define EEP_OFS_OFDM_PWR_TBL 0x40
133 #define EEP_OFS_OFDMA_PWR_TBL 0x50
135 /* Bits in EEP_OFS_ANTENNA */
136 #define EEP_ANTENNA_MAIN 0x1
137 #define EEP_ANTENNA_AUX 0x2
138 #define EEP_ANTINV 0x4
140 /* Bits in EEP_OFS_RADIOCTL */
141 #define EEP_RADIOCTL_ENABLE 0x80
143 /* control commands */
144 #define MESSAGE_TYPE_READ 0x1
145 #define MESSAGE_TYPE_WRITE 0x0
146 #define MESSAGE_TYPE_LOCK_OR 0x2
147 #define MESSAGE_TYPE_LOCK_AND 0x3
148 #define MESSAGE_TYPE_WRITE_MASK 0x4
149 #define MESSAGE_TYPE_CARDINIT 0x5
150 #define MESSAGE_TYPE_INIT_RSP 0x6
151 #define MESSAGE_TYPE_MACSHUTDOWN 0x7
152 #define MESSAGE_TYPE_SETKEY 0x8
153 #define MESSAGE_TYPE_CLRKEYENTRY 0x9
154 #define MESSAGE_TYPE_WRITE_MISCFF 0xa
155 #define MESSAGE_TYPE_SET_ANTMD 0xb
156 #define MESSAGE_TYPE_SELECT_CHANNLE 0xc
157 #define MESSAGE_TYPE_SET_TSFTBTT 0xd
158 #define MESSAGE_TYPE_SET_SSTIFS 0xe
159 #define MESSAGE_TYPE_CHANGE_BBTYPE 0xf
160 #define MESSAGE_TYPE_DISABLE_PS 0x10
161 #define MESSAGE_TYPE_WRITE_IFRF 0x11
163 /* command read/write(index) */
164 #define MESSAGE_REQUEST_MEM 0x1
165 #define MESSAGE_REQUEST_BBREG 0x2
166 #define MESSAGE_REQUEST_MACREG 0x3
167 #define MESSAGE_REQUEST_EEPROM 0x4
168 #define MESSAGE_REQUEST_TSF 0x5
169 #define MESSAGE_REQUEST_TBTT 0x6
170 #define MESSAGE_REQUEST_BBAGC 0x7
171 #define MESSAGE_REQUEST_VERSION 0x8
172 #define MESSAGE_REQUEST_RF_INIT 0x9
173 #define MESSAGE_REQUEST_RF_INIT2 0xa
174 #define MESSAGE_REQUEST_RF_CH0 0xb
175 #define MESSAGE_REQUEST_RF_CH1 0xc
176 #define MESSAGE_REQUEST_RF_CH2 0xd
179 #define USB_REG4 0x604
182 #define RUN_AT(x) (jiffies+(x))
185 #define PRIVATE_Message 0
187 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
188 #define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
190 typedef enum __device_msg_level {
191 MSG_LEVEL_ERR = 0, /* Errors causing abnormal operation */
192 MSG_LEVEL_NOTICE = 1, /* Errors needing user notification */
193 MSG_LEVEL_INFO = 2, /* Normal message. */
194 MSG_LEVEL_VERBOSE = 3, /* Will report all trival errors. */
195 MSG_LEVEL_DEBUG = 4 /* Only for debug purpose. */
196 } DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
198 #define DEVICE_INIT_COLD 0x0 /* cold init */
199 #define DEVICE_INIT_RESET 0x1 /* reset init or Dx to D0 power remain */
200 #define DEVICE_INIT_DXPL 0x2 /* Dx to D0 power lost init */
203 struct vnt_cmd_card_init {
205 u8 exist_sw_net_addr;
207 u8 short_retry_limit;
211 struct vnt_rsp_card_init {
222 * Enum of context types for SendPacket
225 CONTEXT_DATA_PACKET = 1,
227 CONTEXT_BEACON_PACKET
230 /* RCB (Receive Control Block) */
236 struct vnt_rx_mgmt sMngPacket;
241 /* used to track bulk out irps */
242 struct vnt_usb_send_context {
246 struct ieee80211_hdr *hdr;
247 unsigned int buf_len;
251 unsigned char data[MAX_TOTAL_SIZE_WITH_ALL_HEADERS];
254 /* tx packet info for rxtx */
255 struct vnt_tx_pkt_info {
257 u8 dest_addr[ETH_ALEN];
260 /* structure got from configuration file as user-desired default settings */
261 typedef struct _DEFAULT_CONFIG {
263 signed int eConfigMode;
264 signed int eAuthenMode; /* open/wep/wpa */
265 signed int bShareKeyAlgorithm; /* open-open/{open,wep}-sharekey */
266 signed int keyidx; /* wepkey index */
267 signed int eEncryptionStatus;
268 } DEFAULT_CONFIG, *PDEFAULT_CONFIG;
271 * Structure to keep track of USB interrupt packets
273 struct vnt_interrupt_buffer {
280 typedef enum __DEVICE_NDIS_STATUS {
285 } DEVICE_NDIS_STATUS, *PDEVICE_NDIS_STATUS;
287 #define MAX_BSSIDINFO_4_PMKID 16
288 #define MAX_PMKIDLIST 5
289 /* flags for PMKID Candidate list structure */
290 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
292 /* PMKID Structures */
293 typedef unsigned char NDIS_802_11_PMKID_VALUE[16];
295 typedef enum _NDIS_802_11_WEP_STATUS
297 Ndis802_11WEPEnabled,
298 Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
299 Ndis802_11WEPDisabled,
300 Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
301 Ndis802_11WEPKeyAbsent,
302 Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
303 Ndis802_11WEPNotSupported,
304 Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
305 Ndis802_11Encryption2Enabled,
306 Ndis802_11Encryption2KeyAbsent,
307 Ndis802_11Encryption3Enabled,
308 Ndis802_11Encryption3KeyAbsent
309 } NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
310 NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
312 typedef enum _NDIS_802_11_STATUS_TYPE
314 Ndis802_11StatusType_Authentication,
315 Ndis802_11StatusType_MediaStreamMode,
316 Ndis802_11StatusType_PMKID_CandidateList,
317 Ndis802_11StatusTypeMax, /* not a real type, defined as upper bound */
318 } NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
320 /* added new types for PMKID Candidate lists */
321 typedef struct _PMKID_CANDIDATE {
322 NDIS_802_11_MAC_ADDRESS BSSID;
324 } PMKID_CANDIDATE, *PPMKID_CANDIDATE;
326 typedef struct _BSSID_INFO
328 NDIS_802_11_MAC_ADDRESS BSSID;
329 NDIS_802_11_PMKID_VALUE PMKID;
330 } BSSID_INFO, *PBSSID_INFO;
332 typedef struct tagSPMKID {
333 unsigned long Length;
334 unsigned long BSSIDInfoCount;
335 BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
338 typedef struct tagSPMKIDCandidateEvent {
339 NDIS_802_11_STATUS_TYPE StatusType;
340 unsigned long Version; /* Version of the structure */
341 unsigned long NumCandidates; /* No. of pmkid candidates */
342 PMKID_CANDIDATE CandidateList[MAX_PMKIDLIST];
343 } SPMKIDCandidateEvent, *PSPMKIDCandidateEvent;
345 /* The receive duplicate detection cache entry */
346 typedef struct tagSCacheEntry{
348 u8 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
362 * DeFragment Control Block, used for collecting fragments prior to reassembly
364 typedef struct tagSDeFragControlBlock
368 u8 abyAddr2[ETH_ALEN];
369 unsigned int uLifetime;
372 unsigned int cbFrameLength;
374 } SDeFragControlBlock, *PSDeFragControlBlock;
376 /* flags for options */
377 #define DEVICE_FLAGS_UNPLUG 0x00000001UL
379 /* flags for driver status */
380 #define DEVICE_FLAGS_OPENED 0x00010000UL
382 typedef struct __device_opt {
383 int nRxDescs0; /* number of RX descriptors 0 */
384 int nTxDescs0; /* number of TX descriptors 0, 1, 2, 3 */
385 int rts_thresh; /* RTS threshold */
394 } OPTIONS, *POPTIONS;
398 struct ieee80211_hw *hw;
399 struct ieee80211_vif *vif;
402 struct usb_device *usb;
403 struct net_device *dev;
404 struct net_device_stats stats;
408 struct work_struct read_work_item;
409 struct work_struct rx_mng_work_item;
420 struct mutex usb_lock;
429 SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG];
435 struct urb *pInterruptURB;
438 /* Variables to track resources for the BULK In Pipe */
439 struct vnt_rcb *pRCBMem;
440 struct vnt_rcb *apRCB[CB_MAX_RX_DESC];
442 struct vnt_rcb *FirstRecvFreeList;
443 struct vnt_rcb *LastRecvFreeList;
445 struct vnt_rcb *FirstRecvMngList;
446 struct vnt_rcb *LastRecvMngList;
448 int bIsRxWorkItemQueued;
449 int bIsRxMngWorkItemQueued;
450 unsigned long ulRcvRefCount; /* packets that have not returned back */
452 /* Variables to track resources for the BULK Out Pipe */
453 struct vnt_usb_send_context *apTD[CB_MAX_TX_DESC];
455 struct vnt_tx_pkt_info pkt_info[16];
457 /* Variables to track resources for the Interrupt In Pipe */
458 struct vnt_interrupt_buffer int_buf;
460 /* default config from file by user setting */
461 DEFAULT_CONFIG config_file;
463 /* Version control */
464 u16 wFirmwareVersion;
472 u8 byOriginalZonetype;
474 int bLinkPass; /* link status: OK or fail */
475 struct vnt_cmd_card_init init_command;
476 struct vnt_rsp_card_init init_response;
477 u8 abyCurrentNetAddr[ETH_ALEN];
478 u8 abyPermanentNetAddr[ETH_ALEN];
482 /* Maintain statistical debug info. */
483 unsigned long SendContextsInUse;
484 unsigned long RcvBuffersInUse;
486 /* 802.11 management */
487 struct vnt_manager vnt_mgmt;
493 /* 802.11 MAC specific */
497 /* Antenna Diversity */
508 u32 uSIFS; /* Current SIFS */
509 u32 uDIFS; /* Current DIFS */
510 u32 uEIFS; /* Current EIFS */
511 u32 uSlot; /* Current SlotTime */
512 u32 uCwMin; /* Current CwMin */
513 u32 uCwMax; /* CwMax is fixed on 1023 */
523 u8 byBBType; /* 0: 11A, 1:11B, 2:11G */
524 u8 byPacketType; /* 0:11a 1:11b 2:11gb 3:11ga */
526 u8 byTopOFDMBasicRate;
527 u8 byTopCCKBasicRate;
529 u8 abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /*u32 alignment */
540 /* For RF Power table */
546 u8 abyOFDMPwrTbl[14];
547 u8 abyOFDMAPwrTbl[42];
554 u16 wFragmentationThreshold;
555 u8 byShortRetryLimit;
558 enum nl80211_iftype op_mode;
561 u16 wMaxTransmitMSDULifetime;
562 u8 abyBSSID[ETH_ALEN];
563 u8 abyDesireBSSID[ETH_ALEN];
565 u32 dwMaxReceiveLifetime; /* dot11MaxReceiveLifetime */
567 int bEncryptionEnable;
571 int bBarkerPreambleMd;
574 u16 wUseProtectCntDown;
576 int bRadioControlOff;
584 WMAC_POWER_MODE ePSMode;
585 unsigned long ulPSModeWaitTx;
588 /* Beacon releated */
595 CMD_STATE eCommandState;
604 u32 uAutoReConnectTime;
609 CMD_ITEM eCmdQueue[CMD_Q_SIZE];
626 NDIS_802_11_WEP_STATUS eEncryptionStatus;
628 NDIS_802_11_WEP_STATUS eOldEncryptionStatus;
633 u8 abyPRNG[WLAN_WEPMAX_KEYLEN+3];
637 u8 abyKey[WLAN_WEP232_KEYLEN];
638 unsigned long key_entry_inuse;
652 /* For Update BaseBand VGA Gain Offset */
656 u8 abyBBVGA[BB_VGA_LEVEL];
657 signed long ldBmThreshold[BB_VGA_LEVEL];
665 struct delayed_work run_command_work;
666 /* One second callback */
667 struct delayed_work second_callback_work;
671 int fWPA_Authened; /*is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? */
675 struct ethhdr sTxEthHeader;
676 struct ethhdr sRxEthHeader;
677 u8 abyBroadcastAddr[ETH_ALEN];
678 u8 abySNAP_RFC1042[ETH_ALEN];
679 u8 abySNAP_Bridgetunnel[ETH_ALEN];
681 /* Pre-Authentication & PMK cache */
683 SPMKIDCandidateEvent gsPMKIDCandidate;
690 u8 byChannelSwitchCount;
692 /* WPA supplicant daemon */
698 int bWPASuppWextEnabled;
702 struct iw_statistics wstats; /* wireless stats */
708 #define EnqueueRCB(_Head, _Tail, _RCB) \
714 _Tail->Next = _RCB; \
720 #define DequeueRCB(Head, Tail) \
722 struct vnt_rcb *RCB = Head; \
729 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
730 if ((uVar) >= ((uModulo) - 1)) \
736 #define fMP_DISCONNECTED 0x00000002
737 #define fMP_POST_READS 0x00000100
738 #define fMP_POST_WRITES 0x00000200
740 #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
741 #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
742 #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
744 #define MP_IS_READY(_M) (((_M)->Flags & fMP_DISCONNECTED) == 0)
746 int device_alloc_frag_buf(struct vnt_private *, PSDeFragControlBlock pDeF);
747 void vnt_configure_filter(struct vnt_private *);
748 int vnt_init(struct vnt_private *priv);