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>
35 #include <linux/errno.h>
36 #include <linux/ioport.h>
37 #include <linux/pci.h>
38 #include <linux/kernel.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/skbuff.h>
42 #include <linux/delay.h>
43 #include <linux/timer.h>
44 #include <linux/slab.h>
45 #include <linux/interrupt.h>
46 #include <linux/string.h>
47 #include <linux/wait.h>
48 #include <linux/if_arp.h>
49 #include <linux/sched.h>
52 #include <linux/crc32.h>
53 #include <linux/uaccess.h>
54 #include <linux/proc_fs.h>
55 #include <linux/inetdevice.h>
56 #include <linux/reboot.h>
57 #include <linux/ethtool.h>
58 /* Include Wireless Extension definition and check version - Jean II */
59 #include <net/mac80211.h>
60 #include <linux/wireless.h>
61 #include <net/iw_handler.h> /* New driver API */
63 #ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
64 #define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
69 #include "device_cfg.h"
82 /*--------------------- Export Definitions -------------------------*/
84 #define MAC_MAX_CONTEXT_REG (256+128)
86 #define MAX_MULTICAST_ADDRESS_NUM 32
87 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * ETH_ALEN)
89 #define DUPLICATE_RX_CACHE_LENGTH 5
91 #define NUM_KEY_ENTRY 11
96 #define TX_WEP_SWOTP 3
97 #define TX_WEP_OTPSW 4
98 #define TX_WEP_SW232 5
100 #define KEYSEL_WEP40 0
101 #define KEYSEL_WEP104 1
102 #define KEYSEL_TKIP 2
103 #define KEYSEL_CCMP 3
105 #define AUTO_FB_NONE 0
115 #define ANT_DIVERSITY 2
116 #define ANT_RXD_TXA 3
117 #define ANT_RXD_TXB 4
118 #define ANT_UNKNOWN 0xFF
120 #define MAXCHECKHANGCNT 4
122 #define BB_VGA_LEVEL 4
123 #define BB_VGA_CHANGE_THRESHOLD 16
126 #define RUN_AT(x) (jiffies+(x))
130 #define RESERV_AC0DMA 4
134 #define AVAIL_TD(p, q) ((p)->sOpts.nTxDescs[(q)] - ((p)->iTDUsed[(q)]))
138 #define PRIVATE_Message 0
140 /*--------------------- Export Types ------------------------------*/
142 #define PRINT_K(p, args...) \
144 if (PRIVATE_Message) \
148 /* 0:11A 1:11B 2:11G */
149 typedef enum _VIA_BB_TYPE
154 } VIA_BB_TYPE, *PVIA_BB_TYPE;
156 /* 0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate) */
157 typedef enum _VIA_PKT_TYPE
163 } VIA_PKT_TYPE, *PVIA_PKT_TYPE;
165 typedef enum __device_msg_level {
166 MSG_LEVEL_ERR = 0, /* Errors that will cause abnormal operation. */
167 MSG_LEVEL_NOTICE = 1, /* Some errors need users to be notified. */
168 MSG_LEVEL_INFO = 2, /* Normal message. */
169 MSG_LEVEL_VERBOSE = 3, /* Will report all trival errors. */
170 MSG_LEVEL_DEBUG = 4 /* Only for debug purpose. */
171 } DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
174 #define MAX_BSSIDINFO_4_PMKID 16
175 #define MAX_PMKIDLIST 5
176 /* Flags for PMKID Candidate list structure */
177 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
179 /* PMKID Structures */
180 typedef unsigned char NDIS_802_11_PMKID_VALUE[16];
182 typedef enum _NDIS_802_11_WEP_STATUS {
183 Ndis802_11WEPEnabled,
184 Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
185 Ndis802_11WEPDisabled,
186 Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
187 Ndis802_11WEPKeyAbsent,
188 Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
189 Ndis802_11WEPNotSupported,
190 Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
191 Ndis802_11Encryption2Enabled,
192 Ndis802_11Encryption2KeyAbsent,
193 Ndis802_11Encryption3Enabled,
194 Ndis802_11Encryption3KeyAbsent
195 } NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
196 NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
198 typedef enum _NDIS_802_11_STATUS_TYPE {
199 Ndis802_11StatusType_Authentication,
200 Ndis802_11StatusType_MediaStreamMode,
201 Ndis802_11StatusType_PMKID_CandidateList,
202 Ndis802_11StatusTypeMax /* defined as an upper bound */
203 } NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
205 /* Added new types for PMKID Candidate lists. */
206 struct pmkid_candidate {
207 NDIS_802_11_MAC_ADDRESS BSSID;
211 typedef struct _BSSID_INFO {
212 NDIS_802_11_MAC_ADDRESS BSSID;
213 NDIS_802_11_PMKID_VALUE PMKID;
214 } BSSID_INFO, *PBSSID_INFO;
216 typedef struct tagSPMKID {
217 unsigned long Length;
218 unsigned long BSSIDInfoCount;
219 BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
222 typedef struct tagSPMKIDCandidateEvent {
223 NDIS_802_11_STATUS_TYPE StatusType;
224 unsigned long Version; /* Version of the structure */
225 unsigned long NumCandidates; /* No. of pmkid candidates */
226 struct pmkid_candidate CandidateList[MAX_PMKIDLIST];
227 } SPMKIDCandidateEvent, *PSPMKIDCandidateEvent;
229 /* 802.11h related */
230 #define MAX_QUIET_COUNT 8
232 typedef struct tagSQuietControl {
234 unsigned long dwStartTime;
235 unsigned char byPeriod;
236 unsigned short wDuration;
237 } SQuietControl, *PSQuietControl;
239 typedef struct __chip_info_tbl {
245 } CHIP_INFO, *PCHIP_INFO;
250 } DEVICE_OWNER_TYPE, *PDEVICE_OWNER_TYPE;
252 /* The receive duplicate detection cache entry */
253 typedef struct tagSCacheEntry {
254 unsigned short wFmSequence;
255 unsigned char abyAddr2[ETH_ALEN];
256 } SCacheEntry, *PSCacheEntry;
258 typedef struct tagSCache {
259 /* The receive cache is updated circularly. The next entry to be written is
260 * indexed by the "InPtr".
262 unsigned int uInPtr; /* Place to use next */
263 SCacheEntry asCacheEntry[DUPLICATE_RX_CACHE_LENGTH];
266 #define CB_MAX_RX_FRAG 64
267 /* DeFragment Control Block, used for collecting fragments prior to reassembly */
268 typedef struct tagSDeFragControlBlock {
269 unsigned short wSequence;
270 unsigned short wFragNum;
271 unsigned char abyAddr2[ETH_ALEN];
272 unsigned int uLifetime;
274 unsigned char *pbyRxBuffer;
275 unsigned int cbFrameLength;
277 } SDeFragControlBlock, *PSDeFragControlBlock;
279 /* flags for options */
280 #define DEVICE_FLAGS_IP_ALIGN 0x00000001UL
281 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
282 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
283 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
284 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
285 #define DEVICE_FLAGS_DiversityANT 0x00000020UL
287 /* flags for driver status */
288 #define DEVICE_FLAGS_OPENED 0x00010000UL
289 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
290 /* flags for capabilities */
291 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
292 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
293 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
295 /* flags for MII status */
296 #define DEVICE_LINK_FAIL 0x00000001UL
297 #define DEVICE_SPEED_10 0x00000002UL
298 #define DEVICE_SPEED_100 0x00000004UL
299 #define DEVICE_SPEED_1000 0x00000008UL
300 #define DEVICE_DUPLEX_FULL 0x00000010UL
301 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
302 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
303 /* for device_set_media_duplex */
304 #define DEVICE_LINK_CHANGE 0x00000001UL
306 typedef struct __device_opt {
307 int nRxDescs0; /* Number of RX descriptors0 */
308 int nRxDescs1; /* Number of RX descriptors1 */
309 int nTxDescs[2]; /* Number of TX descriptors 0, 1 */
310 int int_works; /* interrupt limits */
311 int rts_thresh; /* rts threshold */
319 } OPTIONS, *POPTIONS;
322 struct pci_dev *pcid;
324 struct ieee80211_hw *hw;
325 struct ieee80211_vif *vif;
326 unsigned long key_entry_inuse;
328 struct net_device *dev;
330 /* dma addr, rx/tx pool */
332 dma_addr_t rd0_pool_dma;
333 dma_addr_t rd1_pool_dma;
335 dma_addr_t td0_pool_dma;
336 dma_addr_t td1_pool_dma;
338 dma_addr_t tx_bufs_dma0;
339 dma_addr_t tx_bufs_dma1;
340 dma_addr_t tx_beacon_dma;
342 unsigned char *tx0_bufs;
343 unsigned char *tx1_bufs;
344 unsigned char *tx_beacon_bufs;
348 void __iomem *PortOffset;
354 unsigned char byRevId;
355 unsigned char byRxMode;
356 unsigned short SubSystemID;
357 unsigned short SubVendorID;
362 volatile int iTDUsed[TYPE_MAXTD];
364 volatile PSTxDesc apCurrTD[TYPE_MAXTD];
365 volatile PSTxDesc apTailTD[TYPE_MAXTD];
367 volatile PSTxDesc apTD0Rings;
368 volatile PSTxDesc apTD1Rings;
370 volatile PSRxDesc aRD0Ring;
371 volatile PSRxDesc aRD1Ring;
372 volatile PSRxDesc pCurrRD[TYPE_MAXRD];
375 SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG];
377 unsigned int cbFreeDFCB;
378 unsigned int uCurrentDFCBIdx;
389 struct completion notify;
390 struct semaphore mlme_semaphore;
394 /* Version control */
395 unsigned char byLocalID;
396 unsigned char byRFType;
398 unsigned char byMaxPwrLevel;
399 unsigned char byZoneType;
401 unsigned char byOriginalZonetype;
402 unsigned char abyMacContext[MAC_MAX_CONTEXT_REG];
403 unsigned char abyCurrentNetAddr[ETH_ALEN];
404 bool bLinkPass; /* link status: OK or fail */
406 /* Adapter statistics */
407 SStatCounter scStatistic;
409 SDot11Counters s802_11Counter;
411 /* 802.11 management */
413 SMgmtObject sMgmtObj;
415 /* 802.11 MAC specific */
416 unsigned int uCurrRSSI;
417 unsigned char byCurrSQ;
419 unsigned long dwTxAntennaSel;
420 unsigned long dwRxAntennaSel;
421 unsigned char byAntennaCount;
422 unsigned char byRxAntennaMode;
423 unsigned char byTxAntennaMode;
426 unsigned char *pbyTmpBuff;
427 unsigned int uSIFS; /* Current SIFS */
428 unsigned int uDIFS; /* Current DIFS */
429 unsigned int uEIFS; /* Current EIFS */
430 unsigned int uSlot; /* Current SlotTime */
431 unsigned int uCwMin; /* Current CwMin */
432 unsigned int uCwMax; /* CwMax is fixed on 1023. */
434 unsigned char bySIFS;
435 unsigned char byDIFS;
436 unsigned char byEIFS;
437 unsigned char bySlot;
438 unsigned char byCWMaxMin;
439 CARD_PHY_TYPE eCurrentPHYType;
441 VIA_BB_TYPE byBBType; /* 0:11A, 1:11B, 2:11G */
442 VIA_PKT_TYPE byPacketType; /*
443 * 0:11a,1:11b,2:11gb (only CCK
444 * in BasicRate), 3:11ga (OFDM in
447 unsigned short wBasicRate;
448 unsigned char byACKRate;
449 unsigned char byTopOFDMBasicRate;
450 unsigned char byTopCCKBasicRate;
452 unsigned char byMinChannel;
453 unsigned char byMaxChannel;
454 unsigned int uConnectionRate;
456 unsigned char byPreambleType;
457 unsigned char byShortPreamble;
459 unsigned short wCurrentRate;
460 unsigned short wRTSThreshold;
461 unsigned short wFragmentationThreshold;
462 unsigned char byShortRetryLimit;
463 unsigned char byLongRetryLimit;
464 enum nl80211_iftype op_mode;
465 unsigned char byOpMode;
467 unsigned short wMaxTransmitMSDULifetime;
468 unsigned char abyBSSID[ETH_ALEN];
469 unsigned char abyDesireBSSID[ETH_ALEN];
470 unsigned short wACKDuration; /* update while speed change */
471 unsigned short wRTSTransmitLen; /* update while speed change */
472 unsigned char byRTSServiceField; /* update while speed change */
473 unsigned char byRTSSignalField; /* update while speed change */
475 unsigned long dwMaxReceiveLifetime; /* dot11MaxReceiveLifetime */
477 bool bEncryptionEnable;
482 bool bBarkerPreambleMd;
484 unsigned char byERPFlag;
485 unsigned short wUseProtectCntDown;
487 bool bRadioControlOff;
490 unsigned short wListenInterval;
492 WMAC_POWER_MODE ePSMode;
494 /* GPIO Radio Control */
495 unsigned char byRadioCtl;
496 unsigned char byGPIO;
498 bool bPrvActive4RadioOFF;
502 unsigned short wSeqCounter;
503 unsigned short wBCNBufLen;
504 bool bBeaconBufReady;
506 bool bIsBeaconBufReadySet;
507 unsigned int cbBeaconBufReadySetCnt;
509 unsigned char byCurrentCh;
510 unsigned int uScanTime;
512 CMD_STATE eCommandState;
520 unsigned int uAutoReConnectTime;
524 CMD_ITEM eCmdQueue[CMD_Q_SIZE];
525 unsigned int uCmdDequeueIdx;
526 unsigned int uCmdEnqueueIdx;
527 unsigned int cbFreeCmdQueue;
532 unsigned char abyIPAddr[4];
534 unsigned long ulTxPower;
535 NDIS_802_11_WEP_STATUS eEncryptionStatus;
537 NDIS_802_11_WEP_STATUS eOldEncryptionStatus;
540 unsigned long dwIVCounter;
542 u64 qwPacketNumber; /* For CCMP and TKIP as TSC(6 bytes) */
543 unsigned int uCurrentWEPMode;
546 unsigned char abyPRNG[WLAN_WEPMAX_KEYLEN+3];
547 unsigned char byKeyIndex;
548 unsigned int uKeyLength;
549 unsigned char abyKey[WLAN_WEP232_KEYLEN];
552 unsigned char byCntMeasure;
555 unsigned int uAssocCount;
561 /* for OID_802_11_ASSOCIATION_INFORMATION */
564 unsigned char byAutoFBCtrl;
569 unsigned int uRATEIdx;
571 /* For Update BaseBand VGA Gain Offset */
573 unsigned int uBBVGADiffCount;
574 unsigned char byBBVGANew;
575 unsigned char byBBVGACurrent;
576 unsigned char abyBBVGA[BB_VGA_LEVEL];
577 long ldBmThreshold[BB_VGA_LEVEL];
579 unsigned char byBBPreEDRSSI;
580 unsigned char byBBPreEDIndex;
583 unsigned long dwDiagRefCount;
586 unsigned char byFOETuning;
588 /* For Auto Power Tunning */
589 unsigned char byAutoPwrTunning;
591 short sPSetPointOFDMG;
592 short sPSetPointOFDMA;
593 long lPFormulaOffset;
598 /* For RF Power table */
599 unsigned char byCCKPwr;
600 unsigned char byOFDMPwrG;
601 unsigned char byCurPwr;
603 unsigned char abyCCKPwrTbl[CB_MAX_CHANNEL_24G+1];
604 unsigned char abyOFDMPwrTbl[CB_MAX_CHANNEL+1];
605 char abyCCKDefaultPwr[CB_MAX_CHANNEL_24G+1];
606 char abyOFDMDefaultPwr[CB_MAX_CHANNEL+1];
607 char abyRegPwr[CB_MAX_CHANNEL+1];
608 char abyLocalPwr[CB_MAX_CHANNEL+1];
610 /* BaseBand Loopback Use */
611 unsigned char byBBCR4d;
612 unsigned char byBBCRc9;
613 unsigned char byBBCR88;
614 unsigned char byBBCR09;
617 struct timer_list sTimerCommand;
618 struct timer_list sTimerTxData;
619 unsigned long nTxDataTimeCout;
621 bool IsTxDataTrigger;
623 #ifdef WPA_SM_Transtatus
624 bool fWPA_Authened; /* is WPA/WPA-PSK or WPA2/WPA2-PSK authen?? */
626 unsigned char byReAssocCount;
627 unsigned char byLinkWaitCount;
629 unsigned char abyNodeName[17];
631 bool bDiversityRegCtlON;
632 bool bDiversityEnable;
633 unsigned long ulDiversityNValue;
634 unsigned long ulDiversityMValue;
635 unsigned char byTMax;
636 unsigned char byTMax2;
637 unsigned char byTMax3;
638 unsigned long ulSQ3TH;
641 unsigned long uDiversityCnt;
642 unsigned char byAntennaState;
643 unsigned long ulRatio_State0;
644 unsigned long ulRatio_State1;
646 /* SQ3 functions for antenna diversity */
647 struct timer_list TimerSQ3Tmax1;
648 struct timer_list TimerSQ3Tmax2;
649 struct timer_list TimerSQ3Tmax3;
651 unsigned long uNumSQ3[MAX_RATE];
652 unsigned short wAntDiversityMaxRate;
654 SEthernetHeader sTxEthHeader;
655 SEthernetHeader sRxEthHeader;
656 unsigned char abyBroadcastAddr[ETH_ALEN];
657 unsigned char abySNAP_RFC1042[ETH_ALEN];
658 unsigned char abySNAP_Bridgetunnel[ETH_ALEN];
659 unsigned char abyEEPROM[EEP_MAX_CONTEXT_SIZE]; /* unsigned long alignment */
660 /* Pre-Authentication & PMK cache */
662 SPMKIDCandidateEvent gsPMKIDCandidate;
666 unsigned char abyCountryCode[3];
667 /* for 802.11h DFS */
668 unsigned int uNumOfMeasureEIDs;
669 PWLAN_IE_MEASURE_REQ pCurrMeasureEID;
670 bool bMeasureInProgress;
671 unsigned char byOrgChannel;
672 unsigned char byOrgRCR;
673 unsigned long dwOrgMAR0;
674 unsigned long dwOrgMAR4;
675 unsigned char byBasicMap;
676 unsigned char byCCAFraction;
677 unsigned char abyRPIs[8];
678 unsigned long dwRPIs[8];
680 unsigned char byNewChannel;
681 unsigned char byChannelSwitchCount;
683 bool bEnableFirstQuiet;
684 unsigned char byQuietStartCount;
685 unsigned int uQuietEnqueue;
686 unsigned long dwCurrentQuietEndTime;
687 SQuietControl sQuiet[MAX_QUIET_COUNT];
688 /* for 802.11h TPC */
690 bool bCountryInfo24G;
692 unsigned short wBeaconInterval;
694 /* WPA supplicant deamon */
695 struct net_device *wpadev;
698 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
699 unsigned int bwextcount;
700 bool bWPASuppWextEnabled;
704 /* user space daemon: hostapd, is used for HOSTAP */
708 struct net_device *apdev;
709 int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
711 unsigned int uChannel;
714 struct iw_statistics wstats; /* wireless stats */
718 static inline bool device_get_ip(struct vnt_private *pInfo)
720 struct in_device *in_dev = (struct in_device *)pInfo->dev->ip_ptr;
721 struct in_ifaddr *ifa;
723 if (in_dev != NULL) {
724 ifa = (struct in_ifaddr *)in_dev->ifa_list;
726 memcpy(pInfo->abyIPAddr, &ifa->ifa_address, 4);
733 static inline PDEVICE_RD_INFO alloc_rd_info(void)
735 return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC);
738 static inline PDEVICE_TD_INFO alloc_td_info(void)
740 return kzalloc(sizeof(DEVICE_TD_INFO), GFP_ATOMIC);
743 /*--------------------- Export Functions --------------------------*/
745 bool device_dma0_xmit(struct vnt_private *pDevice,
746 struct sk_buff *skb, unsigned int uNodeIndex);
747 bool device_alloc_frag_buf(struct vnt_private *pDevice,
748 PSDeFragControlBlock pDeF);
749 int Config_FileOperation(struct vnt_private *pDevice,
750 bool fwrite, unsigned char *Parameter);