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
55 /* please copy below macro to driver_event.c for API */
56 #define RT_INSMOD_EVENT_FLAG 0x0101
57 #define RT_UPDEV_EVENT_FLAG 0x0102
58 #define RT_DISCONNECTED_EVENT_FLAG 0x0103
59 #define RT_WPACONNECTED_EVENT_FLAG 0x0104
60 #define RT_DOWNDEV_EVENT_FLAG 0x0105
61 #define RT_RMMOD_EVENT_FLAG 0x0106
67 #include "device_cfg.h"
79 #define VNT_USB_VENDOR_ID 0x160a
80 #define VNT_USB_PRODUCT_ID 0x3184
82 #define MAC_MAX_CONTEXT_REG (256+128)
84 #define MAX_MULTICAST_ADDRESS_NUM 32
85 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * ETH_ALEN)
87 #define DUPLICATE_RX_CACHE_LENGTH 5
89 #define NUM_KEY_ENTRY 11
94 #define TX_WEP_SWOTP 3
95 #define TX_WEP_OTPSW 4
96 #define TX_WEP_SW232 5
98 #define KEYSEL_WEP40 0
99 #define KEYSEL_WEP104 1
100 #define KEYSEL_TKIP 2
101 #define KEYSEL_CCMP 3
103 #define AUTO_FB_NONE 0
113 #define ANT_DIVERSITY 2
114 #define ANT_RXD_TXA 3
115 #define ANT_RXD_TXB 4
116 #define ANT_UNKNOWN 0xFF
122 #define MAXCHECKHANGCNT 4
125 #define TX_PKT_UNI 0x00
126 #define TX_PKT_MULTI 0x01
127 #define TX_PKT_BROAD 0x02
129 #define BB_VGA_LEVEL 4
130 #define BB_VGA_CHANGE_THRESHOLD 3
133 #define RUN_AT(x) (jiffies+(x))
137 #define RESERV_AC0DMA 4
139 #define PRIVATE_Message 0
141 #define DBG_PRT(l, p, args...) { if (l <= msglevel) printk(p, ##args); }
142 #define PRINT_K(p, args...) { if (PRIVATE_Message) printk(p, ##args); }
144 typedef enum __device_msg_level
{
145 MSG_LEVEL_ERR
= 0, /* Errors causing abnormal operation */
146 MSG_LEVEL_NOTICE
= 1, /* Errors needing user notification */
147 MSG_LEVEL_INFO
= 2, /* Normal message. */
148 MSG_LEVEL_VERBOSE
= 3, /* Will report all trival errors. */
149 MSG_LEVEL_DEBUG
= 4 /* Only for debug purpose. */
150 } DEVICE_MSG_LEVEL
, *PDEVICE_MSG_LEVEL
;
152 #define DEVICE_INIT_COLD 0x0 /* cold init */
153 #define DEVICE_INIT_RESET 0x1 /* reset init or Dx to D0 power remain */
154 #define DEVICE_INIT_DXPL 0x2 /* Dx to D0 power lost init */
159 * Enum of context types for SendPacket
162 CONTEXT_DATA_PACKET
= 1,
166 /* RCB (Receive Control Block) */
172 struct vnt_rx_mgmt sMngPacket
;
177 /* used to track bulk out irps */
178 struct vnt_usb_send_context
{
180 struct sk_buff
*pPacket
;
182 unsigned int uBufLen
;
185 unsigned char Data
[MAX_TOTAL_SIZE_WITH_ALL_HEADERS
];
188 /* tx packet info for rxtx */
189 struct vnt_tx_pkt_info
{
191 u8 dest_addr
[ETH_ALEN
];
194 /* structure got from configuration file as user-desired default settings */
195 typedef struct _DEFAULT_CONFIG
{
197 signed int eConfigMode
;
198 signed int eAuthenMode
; /* open/wep/wpa */
199 signed int bShareKeyAlgorithm
; /* open-open/{open,wep}-sharekey */
200 signed int keyidx
; /* wepkey index */
201 signed int eEncryptionStatus
;
202 } DEFAULT_CONFIG
, *PDEFAULT_CONFIG
;
205 * Structure to keep track of USB interrupt packets
207 struct vnt_interrupt_buffer
{
214 typedef enum __DEVICE_NDIS_STATUS
{
219 } DEVICE_NDIS_STATUS
, *PDEVICE_NDIS_STATUS
;
221 #define MAX_BSSIDINFO_4_PMKID 16
222 #define MAX_PMKIDLIST 5
223 /* flags for PMKID Candidate list structure */
224 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
226 /* PMKID Structures */
227 typedef unsigned char NDIS_802_11_PMKID_VALUE
[16];
229 typedef enum _NDIS_802_11_WEP_STATUS
231 Ndis802_11WEPEnabled
,
232 Ndis802_11Encryption1Enabled
= Ndis802_11WEPEnabled
,
233 Ndis802_11WEPDisabled
,
234 Ndis802_11EncryptionDisabled
= Ndis802_11WEPDisabled
,
235 Ndis802_11WEPKeyAbsent
,
236 Ndis802_11Encryption1KeyAbsent
= Ndis802_11WEPKeyAbsent
,
237 Ndis802_11WEPNotSupported
,
238 Ndis802_11EncryptionNotSupported
= Ndis802_11WEPNotSupported
,
239 Ndis802_11Encryption2Enabled
,
240 Ndis802_11Encryption2KeyAbsent
,
241 Ndis802_11Encryption3Enabled
,
242 Ndis802_11Encryption3KeyAbsent
243 } NDIS_802_11_WEP_STATUS
, *PNDIS_802_11_WEP_STATUS
,
244 NDIS_802_11_ENCRYPTION_STATUS
, *PNDIS_802_11_ENCRYPTION_STATUS
;
246 typedef enum _NDIS_802_11_STATUS_TYPE
248 Ndis802_11StatusType_Authentication
,
249 Ndis802_11StatusType_MediaStreamMode
,
250 Ndis802_11StatusType_PMKID_CandidateList
,
251 Ndis802_11StatusTypeMax
, /* not a real type, defined as upper bound */
252 } NDIS_802_11_STATUS_TYPE
, *PNDIS_802_11_STATUS_TYPE
;
254 /* added new types for PMKID Candidate lists */
255 typedef struct _PMKID_CANDIDATE
{
256 NDIS_802_11_MAC_ADDRESS BSSID
;
258 } PMKID_CANDIDATE
, *PPMKID_CANDIDATE
;
260 typedef struct _BSSID_INFO
262 NDIS_802_11_MAC_ADDRESS BSSID
;
263 NDIS_802_11_PMKID_VALUE PMKID
;
264 } BSSID_INFO
, *PBSSID_INFO
;
266 typedef struct tagSPMKID
{
267 unsigned long Length
;
268 unsigned long BSSIDInfoCount
;
269 BSSID_INFO BSSIDInfo
[MAX_BSSIDINFO_4_PMKID
];
272 typedef struct tagSPMKIDCandidateEvent
{
273 NDIS_802_11_STATUS_TYPE StatusType
;
274 unsigned long Version
; /* Version of the structure */
275 unsigned long NumCandidates
; /* No. of pmkid candidates */
276 PMKID_CANDIDATE CandidateList
[MAX_PMKIDLIST
];
277 } SPMKIDCandidateEvent
, *PSPMKIDCandidateEvent
;
279 /* The receive duplicate detection cache entry */
280 typedef struct tagSCacheEntry
{
282 u8 abyAddr2
[ETH_ALEN
];
284 } SCacheEntry
, *PSCacheEntry
;
286 typedef struct tagSCache
{
287 /* The receive cache is updated circularly. The next entry to be written is
288 * indexed by the "InPtr".
290 unsigned int uInPtr
; /* Place to use next */
291 SCacheEntry asCacheEntry
[DUPLICATE_RX_CACHE_LENGTH
];
294 #define CB_MAX_RX_FRAG 64
296 * DeFragment Control Block, used for collecting fragments prior to reassembly
298 typedef struct tagSDeFragControlBlock
302 u8 abyAddr2
[ETH_ALEN
];
303 unsigned int uLifetime
;
306 unsigned int cbFrameLength
;
308 } SDeFragControlBlock
, *PSDeFragControlBlock
;
310 /* flags for options */
311 #define DEVICE_FLAGS_UNPLUG 0x00000001UL
312 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
313 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
314 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
315 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
317 /* flags for driver status */
318 #define DEVICE_FLAGS_OPENED 0x00010000UL
319 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
320 /* flags for capabilities */
321 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
322 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
323 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
325 /* flags for MII status */
326 #define DEVICE_LINK_FAIL 0x00000001UL
327 #define DEVICE_SPEED_10 0x00000002UL
328 #define DEVICE_SPEED_100 0x00000004UL
329 #define DEVICE_SPEED_1000 0x00000008UL
330 #define DEVICE_DUPLEX_FULL 0x00000010UL
331 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
332 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
333 /* for device_set_media_duplex */
334 #define DEVICE_LINK_CHANGE 0x00000001UL
336 typedef struct __device_opt
{
337 int nRxDescs0
; /* number of RX descriptors 0 */
338 int nTxDescs0
; /* number of TX descriptors 0, 1, 2, 3 */
339 int rts_thresh
; /* RTS threshold */
348 } OPTIONS
, *POPTIONS
;
352 struct usb_device
*usb
;
353 struct net_device
*dev
;
354 struct net_device_stats stats
;
358 struct work_struct read_work_item
;
359 struct work_struct rx_mng_work_item
;
376 SDeFragControlBlock sRxDFCB
[CB_MAX_RX_FRAG
];
382 struct urb
*pControlURB
;
383 struct urb
*pInterruptURB
;
384 struct usb_ctrlrequest sUsbCtlRequest
;
387 /* Variables to track resources for the BULK In Pipe */
388 struct vnt_rcb
*pRCBMem
;
389 struct vnt_rcb
*apRCB
[CB_MAX_RX_DESC
];
391 struct vnt_rcb
*FirstRecvFreeList
;
392 struct vnt_rcb
*LastRecvFreeList
;
394 struct vnt_rcb
*FirstRecvMngList
;
395 struct vnt_rcb
*LastRecvMngList
;
397 int bIsRxWorkItemQueued
;
398 int bIsRxMngWorkItemQueued
;
399 unsigned long ulRcvRefCount
; /* packets that have not returned back */
401 /* Variables to track resources for the BULK Out Pipe */
402 struct vnt_usb_send_context
*apTD
[CB_MAX_TX_DESC
];
404 struct vnt_tx_pkt_info pkt_info
[16];
406 /* Variables to track resources for the Interrupt In Pipe */
407 struct vnt_interrupt_buffer int_buf
;
409 /* default config from file by user setting */
410 DEFAULT_CONFIG config_file
;
412 /* Version control */
413 u16 wFirmwareVersion
;
421 u8 byOriginalZonetype
;
423 int bLinkPass
; /* link status: OK or fail */
424 struct vnt_cmd_card_init init_command
;
425 struct vnt_rsp_card_init init_response
;
426 u8 abyCurrentNetAddr
[ETH_ALEN
];
427 u8 abyPermanentNetAddr
[ETH_ALEN
];
431 /* Maintain statistical debug info. */
432 unsigned long SendContextsInUse
;
433 unsigned long RcvBuffersInUse
;
435 /* 802.11 management */
436 struct vnt_manager vnt_mgmt
;
442 /* 802.11 MAC specific */
446 /* Antenna Diversity */
456 /* SQ3 functions for antenna diversity */
457 struct timer_list TimerSQ3Tmax1
;
458 struct timer_list TimerSQ3Tmax2
;
459 struct timer_list TimerSQ3Tmax3
;
461 int bDiversityRegCtlON
;
462 int bDiversityEnable
;
463 unsigned long ulDiversityNValue
;
464 unsigned long ulDiversityMValue
;
468 unsigned long ulSQ3TH
;
470 unsigned long uDiversityCnt
;
472 unsigned long ulRatio_State0
;
473 unsigned long ulRatio_State1
;
474 unsigned long ulSQ3_State0
;
475 unsigned long ulSQ3_State1
;
477 unsigned long aulSQ3Val
[MAX_RATE
];
478 unsigned long aulPktNum
[MAX_RATE
];
481 u32 uSIFS
; /* Current SIFS */
482 u32 uDIFS
; /* Current DIFS */
483 u32 uEIFS
; /* Current EIFS */
484 u32 uSlot
; /* Current SlotTime */
485 u32 uCwMin
; /* Current CwMin */
486 u32 uCwMax
; /* CwMax is fixed on 1023 */
496 u8 byBBType
; /* 0: 11A, 1:11B, 2:11G */
497 u8 byPacketType
; /* 0:11a 1:11b 2:11gb 3:11ga */
500 u8 byTopOFDMBasicRate
;
501 u8 byTopCCKBasicRate
;
503 u32 dwAotoRateTxOkCnt
;
504 u32 dwAotoRateTxFailCnt
;
505 u32 dwErrorRateThreshold
[13];
506 u32 dwTPTable
[MAX_RATE
];
507 u8 abyEEPROM
[EEP_MAX_CONTEXT_SIZE
]; /*u32 alignment */
518 /* For RF Power table */
524 u8 abyOFDMPwrTbl
[14];
525 u8 abyOFDMAPwrTbl
[42];
532 u16 wFragmentationThreshold
;
533 u8 byShortRetryLimit
;
536 enum nl80211_iftype op_mode
;
539 u16 wMaxTransmitMSDULifetime
;
540 u8 abyBSSID
[ETH_ALEN
];
541 u8 abyDesireBSSID
[ETH_ALEN
];
543 u32 dwMaxReceiveLifetime
; /* dot11MaxReceiveLifetime */
546 int bEncryptionEnable
;
550 int bBarkerPreambleMd
;
553 u16 wUseProtectCntDown
;
555 int bRadioControlOff
;
562 WMAC_POWER_MODE ePSMode
;
563 unsigned long ulPSModeWaitTx
;
566 /* Beacon releated */
574 CMD_STATE eCommandState
;
583 u32 uAutoReConnectTime
;
588 CMD_ITEM eCmdQueue
[CMD_Q_SIZE
];
603 unsigned long ulTxPower
;
606 NDIS_802_11_WEP_STATUS eEncryptionStatus
;
608 NDIS_802_11_WEP_STATUS eOldEncryptionStatus
;
613 u8 abyPRNG
[WLAN_WEPMAX_KEYLEN
+3];
617 u8 abyKey
[WLAN_WEP232_KEYLEN
];
631 /* For Update BaseBand VGA Gain Offset */
636 u8 abyBBVGA
[BB_VGA_LEVEL
];
637 signed long ldBmThreshold
[BB_VGA_LEVEL
];
647 /* For Auto Power Tunning */
650 /* BaseBand Loopback Use */
657 struct delayed_work run_command_work
;
658 /* One second callback */
659 struct delayed_work second_callback_work
;
663 int fWPA_Authened
; /*is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? */
667 struct ethhdr sTxEthHeader
;
668 struct ethhdr sRxEthHeader
;
669 u8 abyBroadcastAddr
[ETH_ALEN
];
670 u8 abySNAP_RFC1042
[ETH_ALEN
];
671 u8 abySNAP_Bridgetunnel
[ETH_ALEN
];
673 /* Pre-Authentication & PMK cache */
675 SPMKIDCandidateEvent gsPMKIDCandidate
;
682 u8 byChannelSwitchCount
;
684 /* WPA supplicant daemon */
690 int bWPASuppWextEnabled
;
692 /* user space daemon: hostapd, is used for HOSTAP */
696 struct net_device
*apdev
;
697 int (*tx_80211
)(struct sk_buff
*skb
, struct net_device
*dev
);
701 struct iw_statistics wstats
; /* wireless stats */
707 #define EnqueueRCB(_Head, _Tail, _RCB) \
713 _Tail->Next = _RCB; \
719 #define DequeueRCB(Head, Tail) \
721 struct vnt_rcb *RCB = Head; \
728 #define ADD_ONE_WITH_WRAP_AROUND(uVar, uModulo) { \
729 if ((uVar) >= ((uModulo) - 1)) \
735 #define fMP_RESET_IN_PROGRESS 0x00000001
736 #define fMP_DISCONNECTED 0x00000002
737 #define fMP_HALT_IN_PROGRESS 0x00000004
738 #define fMP_SURPRISE_REMOVED 0x00000008
739 #define fMP_RECV_LOOKASIDE 0x00000010
740 #define fMP_INIT_IN_PROGRESS 0x00000020
741 #define fMP_SEND_SIDE_RESOURCE_ALLOCATED 0x00000040
742 #define fMP_RECV_SIDE_RESOURCE_ALLOCATED 0x00000080
743 #define fMP_POST_READS 0x00000100
744 #define fMP_POST_WRITES 0x00000200
745 #define fMP_CONTROL_READS 0x00000400
746 #define fMP_CONTROL_WRITES 0x00000800
748 #define MP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F))
749 #define MP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F))
750 #define MP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F))
752 #define MP_IS_READY(_M) (((_M)->Flags & \
753 (fMP_DISCONNECTED | fMP_RESET_IN_PROGRESS | fMP_HALT_IN_PROGRESS | fMP_INIT_IN_PROGRESS | fMP_SURPRISE_REMOVED)) == 0)
755 int device_alloc_frag_buf(struct vnt_private
*, PSDeFragControlBlock pDeF
);
756 void vnt_configure_filter(struct vnt_private
*);