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/config.h>
54 #include <linux/uaccess.h>
55 #include <linux/proc_fs.h>
56 #include <linux/inetdevice.h>
57 #include <linux/reboot.h>
59 #define DEVICE_ETHTOOL_IOCTL_SUPPORT
60 #include <linux/ethtool.h>
62 #undef DEVICE_ETHTOOL_IOCTL_SUPPORT
64 /* Include Wireless Extension definition and check version - Jean II */
65 #include <linux/wireless.h>
66 #include <net/iw_handler.h> // New driver API
68 //2008-0409-07, <Add> by Einsn Liu
69 #ifndef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
70 #define WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
77 #include "device_cfg.h"
90 /*--------------------- Export Definitions -------------------------*/
92 #define MAC_MAX_CONTEXT_REG (256+128)
94 #define MAX_MULTICAST_ADDRESS_NUM 32
95 #define MULTICAST_ADDRESS_LIST_SIZE (MAX_MULTICAST_ADDRESS_NUM * ETH_ALEN)
97 #define DUPLICATE_RX_CACHE_LENGTH 5
99 #define NUM_KEY_ENTRY 11
101 #define TX_WEP_NONE 0
104 #define TX_WEP_SWOTP 3
105 #define TX_WEP_OTPSW 4
106 #define TX_WEP_SW232 5
108 #define KEYSEL_WEP40 0
109 #define KEYSEL_WEP104 1
110 #define KEYSEL_TKIP 2
111 #define KEYSEL_CCMP 3
113 #define AUTO_FB_NONE 0
123 #define ANT_DIVERSITY 2
124 #define ANT_RXD_TXA 3
125 #define ANT_RXD_TXB 4
126 #define ANT_UNKNOWN 0xFF
128 #define MAXCHECKHANGCNT 4
130 #define BB_VGA_LEVEL 4
131 #define BB_VGA_CHANGE_THRESHOLD 16
134 #define RUN_AT(x) (jiffies+(x))
138 #define RESERV_AC0DMA 4
142 #define AVAIL_TD(p, q) ((p)->sOpts.nTxDescs[(q)] - ((p)->iTDUsed[(q)]))
146 #define PRIVATE_Message 0
148 /*--------------------- Export Types ------------------------------*/
150 #define PRINT_K(p, args...) \
152 if (PRIVATE_Message) \
157 typedef enum _VIA_BB_TYPE
162 } VIA_BB_TYPE, *PVIA_BB_TYPE;
164 //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
165 typedef enum _VIA_PKT_TYPE
171 } VIA_PKT_TYPE, *PVIA_PKT_TYPE;
173 typedef enum __device_msg_level {
174 MSG_LEVEL_ERR = 0, //Errors that will cause abnormal operation.
175 MSG_LEVEL_NOTICE = 1, //Some errors need users to be notified.
176 MSG_LEVEL_INFO = 2, //Normal message.
177 MSG_LEVEL_VERBOSE = 3, //Will report all trival errors.
178 MSG_LEVEL_DEBUG = 4 //Only for debug purpose.
179 } DEVICE_MSG_LEVEL, *PDEVICE_MSG_LEVEL;
183 #define MAX_BSSIDINFO_4_PMKID 16
184 #define MAX_PMKIDLIST 5
185 //Flags for PMKID Candidate list structure
186 #define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01
189 typedef unsigned char NDIS_802_11_PMKID_VALUE[16];
191 typedef enum _NDIS_802_11_WEP_STATUS {
192 Ndis802_11WEPEnabled,
193 Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
194 Ndis802_11WEPDisabled,
195 Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
196 Ndis802_11WEPKeyAbsent,
197 Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
198 Ndis802_11WEPNotSupported,
199 Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
200 Ndis802_11Encryption2Enabled,
201 Ndis802_11Encryption2KeyAbsent,
202 Ndis802_11Encryption3Enabled,
203 Ndis802_11Encryption3KeyAbsent
204 } NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS,
205 NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS;
207 typedef enum _NDIS_802_11_STATUS_TYPE {
208 Ndis802_11StatusType_Authentication,
209 Ndis802_11StatusType_MediaStreamMode,
210 Ndis802_11StatusType_PMKID_CandidateList,
211 Ndis802_11StatusTypeMax // not a real type, defined as an upper bound
212 } NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE;
214 //Added new types for PMKID Candidate lists.
215 struct pmkid_candidate {
216 NDIS_802_11_MAC_ADDRESS BSSID;
220 typedef struct _BSSID_INFO {
221 NDIS_802_11_MAC_ADDRESS BSSID;
222 NDIS_802_11_PMKID_VALUE PMKID;
223 } BSSID_INFO, *PBSSID_INFO;
225 typedef struct tagSPMKID {
226 unsigned long Length;
227 unsigned long BSSIDInfoCount;
228 BSSID_INFO BSSIDInfo[MAX_BSSIDINFO_4_PMKID];
231 typedef struct tagSPMKIDCandidateEvent {
232 NDIS_802_11_STATUS_TYPE StatusType;
233 unsigned long Version; // Version of the structure
234 unsigned long NumCandidates; // No. of pmkid candidates
235 struct pmkid_candidate CandidateList[MAX_PMKIDLIST];
236 } SPMKIDCandidateEvent, *PSPMKIDCandidateEvent;
241 #define MAX_QUIET_COUNT 8
243 typedef struct tagSQuietControl {
245 unsigned long dwStartTime;
246 unsigned char byPeriod;
247 unsigned short wDuration;
248 } SQuietControl, *PSQuietControl;
251 typedef struct __chip_info_tbl {
257 } CHIP_INFO, *PCHIP_INFO;
262 } DEVICE_OWNER_TYPE, *PDEVICE_OWNER_TYPE;
264 // The receive duplicate detection cache entry
265 typedef struct tagSCacheEntry {
266 unsigned short wFmSequence;
267 unsigned char abyAddr2[ETH_ALEN];
268 } SCacheEntry, *PSCacheEntry;
270 typedef struct tagSCache {
271 /* The receive cache is updated circularly. The next entry to be written is
272 * indexed by the "InPtr".
274 unsigned int uInPtr; // Place to use next
275 SCacheEntry asCacheEntry[DUPLICATE_RX_CACHE_LENGTH];
278 #define CB_MAX_RX_FRAG 64
279 // DeFragment Control Block, used for collecting fragments prior to reassembly
280 typedef struct tagSDeFragControlBlock {
281 unsigned short wSequence;
282 unsigned short wFragNum;
283 unsigned char abyAddr2[ETH_ALEN];
284 unsigned int uLifetime;
286 unsigned char *pbyRxBuffer;
287 unsigned int cbFrameLength;
289 } SDeFragControlBlock, *PSDeFragControlBlock;
292 #define DEVICE_FLAGS_IP_ALIGN 0x00000001UL
293 #define DEVICE_FLAGS_PREAMBLE_TYPE 0x00000002UL
294 #define DEVICE_FLAGS_OP_MODE 0x00000004UL
295 #define DEVICE_FLAGS_PS_MODE 0x00000008UL
296 #define DEVICE_FLAGS_80211h_MODE 0x00000010UL
297 #define DEVICE_FLAGS_DiversityANT 0x00000020UL
299 //flags for driver status
300 #define DEVICE_FLAGS_OPENED 0x00010000UL
301 #define DEVICE_FLAGS_WOL_ENABLED 0x00080000UL
302 //flags for capabilities
303 #define DEVICE_FLAGS_TX_ALIGN 0x01000000UL
304 #define DEVICE_FLAGS_HAVE_CAM 0x02000000UL
305 #define DEVICE_FLAGS_FLOW_CTRL 0x04000000UL
307 //flags for MII status
308 #define DEVICE_LINK_FAIL 0x00000001UL
309 #define DEVICE_SPEED_10 0x00000002UL
310 #define DEVICE_SPEED_100 0x00000004UL
311 #define DEVICE_SPEED_1000 0x00000008UL
312 #define DEVICE_DUPLEX_FULL 0x00000010UL
313 #define DEVICE_AUTONEG_ENABLE 0x00000020UL
314 #define DEVICE_FORCED_BY_EEPROM 0x00000040UL
315 //for device_set_media_duplex
316 #define DEVICE_LINK_CHANGE 0x00000001UL
318 typedef struct __device_opt {
319 int nRxDescs0; //Number of RX descriptors0
320 int nRxDescs1; //Number of RX descriptors1
321 int nTxDescs[2]; //Number of TX descriptors 0, 1
322 int int_works; //interrupt limits
323 int rts_thresh; //rts threshold
331 } OPTIONS, *POPTIONS;
334 struct pci_dev *pcid;
337 struct net_device *dev;
338 struct net_device_stats stats;
340 //dma addr, rx/tx pool
342 dma_addr_t rd0_pool_dma;
343 dma_addr_t rd1_pool_dma;
345 dma_addr_t td0_pool_dma;
346 dma_addr_t td1_pool_dma;
348 dma_addr_t tx_bufs_dma0;
349 dma_addr_t tx_bufs_dma1;
350 dma_addr_t tx_beacon_dma;
352 unsigned char *tx0_bufs;
353 unsigned char *tx1_bufs;
354 unsigned char *tx_beacon_bufs;
358 void __iomem *PortOffset;
364 unsigned char byRevId;
365 unsigned short SubSystemID;
366 unsigned short SubVendorID;
369 volatile int iTDUsed[TYPE_MAXTD];
371 volatile PSTxDesc apCurrTD[TYPE_MAXTD];
372 volatile PSTxDesc apTailTD[TYPE_MAXTD];
374 volatile PSTxDesc apTD0Rings;
375 volatile PSTxDesc apTD1Rings;
377 volatile PSRxDesc aRD0Ring;
378 volatile PSRxDesc aRD1Ring;
379 volatile PSRxDesc pCurrRD[TYPE_MAXRD];
382 SDeFragControlBlock sRxDFCB[CB_MAX_RX_FRAG];
384 unsigned int cbFreeDFCB;
385 unsigned int uCurrentDFCBIdx;
393 unsigned char byRxMode;
398 struct completion notify;
399 struct semaphore mlme_semaphore;
404 unsigned char byLocalID;
405 unsigned char byRFType;
407 unsigned char byMaxPwrLevel;
408 unsigned char byZoneType;
410 unsigned char byOriginalZonetype;
411 unsigned char abyMacContext[MAC_MAX_CONTEXT_REG];
412 bool bLinkPass; // link status: OK or fail
413 unsigned char abyCurrentNetAddr[ETH_ALEN];
415 // Adapter statistics
416 SStatCounter scStatistic;
418 SDot11Counters s802_11Counter;
422 SMgmtObject sMgmtObj;
424 // 802.11 MAC specific
425 unsigned int uCurrRSSI;
426 unsigned char byCurrSQ;
428 unsigned long dwTxAntennaSel;
429 unsigned long dwRxAntennaSel;
430 unsigned char byAntennaCount;
431 unsigned char byRxAntennaMode;
432 unsigned char byTxAntennaMode;
435 unsigned char *pbyTmpBuff;
436 unsigned int uSIFS; //Current SIFS
437 unsigned int uDIFS; //Current DIFS
438 unsigned int uEIFS; //Current EIFS
439 unsigned int uSlot; //Current SlotTime
440 unsigned int uCwMin; //Current CwMin
441 unsigned int uCwMax; //CwMax is fixed on 1023.
443 unsigned char bySIFS;
444 unsigned char byDIFS;
445 unsigned char byEIFS;
446 unsigned char bySlot;
447 unsigned char byCWMaxMin;
448 CARD_PHY_TYPE eCurrentPHYType;
450 VIA_BB_TYPE byBBType; //0: 11A, 1:11B, 2:11G
451 VIA_PKT_TYPE byPacketType; //0:11a,1:11b,2:11gb(only CCK in BasicRate),3:11ga(OFDM in Basic Rate)
452 unsigned short wBasicRate;
453 unsigned char byACKRate;
454 unsigned char byTopOFDMBasicRate;
455 unsigned char byTopCCKBasicRate;
457 unsigned char byMinChannel;
458 unsigned char byMaxChannel;
459 unsigned int uConnectionRate;
461 unsigned char byPreambleType;
462 unsigned char byShortPreamble;
464 unsigned short wCurrentRate;
465 unsigned short wRTSThreshold;
466 unsigned short wFragmentationThreshold;
467 unsigned char byShortRetryLimit;
468 unsigned char byLongRetryLimit;
469 enum nl80211_iftype op_mode;
470 unsigned char byOpMode;
472 unsigned short wMaxTransmitMSDULifetime;
473 unsigned char abyBSSID[ETH_ALEN];
474 unsigned char abyDesireBSSID[ETH_ALEN];
475 unsigned short wACKDuration; // update while speed change
476 unsigned short wRTSTransmitLen; // update while speed change
477 unsigned char byRTSServiceField; // update while speed change
478 unsigned char byRTSSignalField; // update while speed change
480 unsigned long dwMaxReceiveLifetime; // dot11MaxReceiveLifetime
482 bool bEncryptionEnable;
487 bool bBarkerPreambleMd;
489 unsigned char byERPFlag;
490 unsigned short wUseProtectCntDown;
492 bool bRadioControlOff;
495 unsigned short wListenInterval;
497 WMAC_POWER_MODE ePSMode;
499 // GPIO Radio Control
500 unsigned char byRadioCtl;
501 unsigned char byGPIO;
503 bool bPrvActive4RadioOFF;
507 unsigned short wSeqCounter;
508 unsigned short wBCNBufLen;
509 bool bBeaconBufReady;
511 bool bIsBeaconBufReadySet;
512 unsigned int cbBeaconBufReadySetCnt;
514 unsigned char byCurrentCh;
515 unsigned int uScanTime;
517 CMD_STATE eCommandState;
525 unsigned int uAutoReConnectTime;
529 CMD_ITEM eCmdQueue[CMD_Q_SIZE];
530 unsigned int uCmdDequeueIdx;
531 unsigned int uCmdEnqueueIdx;
532 unsigned int cbFreeCmdQueue;
538 unsigned char abyIPAddr[4];
540 unsigned long ulTxPower;
541 NDIS_802_11_WEP_STATUS eEncryptionStatus;
543 //2007-0925-01<Add>by MikeLiu
544 //mike add :save old Encryption
545 NDIS_802_11_WEP_STATUS eOldEncryptionStatus;
548 unsigned long dwIVCounter;
550 u64 qwPacketNumber; /* For CCMP and TKIP as TSC(6 bytes) */
551 unsigned int uCurrentWEPMode;
554 unsigned char abyPRNG[WLAN_WEPMAX_KEYLEN+3];
555 unsigned char byKeyIndex;
556 unsigned int uKeyLength;
557 unsigned char abyKey[WLAN_WEP232_KEYLEN];
560 unsigned char byCntMeasure;
563 unsigned int uAssocCount;
569 // for OID_802_11_ASSOCIATION_INFORMATION
572 unsigned char byAutoFBCtrl;
577 unsigned int uRATEIdx;
579 // For Update BaseBand VGA Gain Offset
581 unsigned int uBBVGADiffCount;
582 unsigned char byBBVGANew;
583 unsigned char byBBVGACurrent;
584 unsigned char abyBBVGA[BB_VGA_LEVEL];
585 long ldBmThreshold[BB_VGA_LEVEL];
587 unsigned char byBBPreEDRSSI;
588 unsigned char byBBPreEDIndex;
591 unsigned long dwDiagRefCount;
594 unsigned char byFOETuning;
596 // For Auto Power Tunning
598 unsigned char byAutoPwrTunning;
600 short sPSetPointOFDMG;
601 short sPSetPointOFDMA;
602 long lPFormulaOffset;
607 // For RF Power table
608 unsigned char byCCKPwr;
609 unsigned char byOFDMPwrG;
610 unsigned char byCurPwr;
612 unsigned char abyCCKPwrTbl[CB_MAX_CHANNEL_24G+1];
613 unsigned char abyOFDMPwrTbl[CB_MAX_CHANNEL+1];
614 char abyCCKDefaultPwr[CB_MAX_CHANNEL_24G+1];
615 char abyOFDMDefaultPwr[CB_MAX_CHANNEL+1];
616 char abyRegPwr[CB_MAX_CHANNEL+1];
617 char abyLocalPwr[CB_MAX_CHANNEL+1];
619 // BaseBand Loopback Use
620 unsigned char byBBCR4d;
621 unsigned char byBBCRc9;
622 unsigned char byBBCR88;
623 unsigned char byBBCR09;
626 struct timer_list sTimerCommand;
627 struct timer_list sTimerTxData;
628 unsigned long nTxDataTimeCout;
630 bool IsTxDataTrigger;
632 #ifdef WPA_SM_Transtatus
633 bool fWPA_Authened; //is WPA/WPA-PSK or WPA2/WPA2-PSK authen??
635 unsigned char byReAssocCount; //mike add:re-association retry times!
636 unsigned char byLinkWaitCount;
638 unsigned char abyNodeName[17];
640 bool bDiversityRegCtlON;
641 bool bDiversityEnable;
642 unsigned long ulDiversityNValue;
643 unsigned long ulDiversityMValue;
644 unsigned char byTMax;
645 unsigned char byTMax2;
646 unsigned char byTMax3;
647 unsigned long ulSQ3TH;
650 unsigned long uDiversityCnt;
651 unsigned char byAntennaState;
652 unsigned long ulRatio_State0;
653 unsigned long ulRatio_State1;
655 //SQ3 functions for antenna diversity
656 struct timer_list TimerSQ3Tmax1;
657 struct timer_list TimerSQ3Tmax2;
658 struct timer_list TimerSQ3Tmax3;
660 unsigned long uNumSQ3[MAX_RATE];
661 unsigned short wAntDiversityMaxRate;
663 SEthernetHeader sTxEthHeader;
664 SEthernetHeader sRxEthHeader;
665 unsigned char abyBroadcastAddr[ETH_ALEN];
666 unsigned char abySNAP_RFC1042[ETH_ALEN];
667 unsigned char abySNAP_Bridgetunnel[ETH_ALEN];
668 unsigned char abyEEPROM[EEP_MAX_CONTEXT_SIZE]; //unsigned long alignment
669 // Pre-Authentication & PMK cache
671 SPMKIDCandidateEvent gsPMKIDCandidate;
675 unsigned char abyCountryCode[3];
677 unsigned int uNumOfMeasureEIDs;
678 PWLAN_IE_MEASURE_REQ pCurrMeasureEID;
679 bool bMeasureInProgress;
680 unsigned char byOrgChannel;
681 unsigned char byOrgRCR;
682 unsigned long dwOrgMAR0;
683 unsigned long dwOrgMAR4;
684 unsigned char byBasicMap;
685 unsigned char byCCAFraction;
686 unsigned char abyRPIs[8];
687 unsigned long dwRPIs[8];
689 unsigned char byNewChannel;
690 unsigned char byChannelSwitchCount;
692 bool bEnableFirstQuiet;
693 unsigned char byQuietStartCount;
694 unsigned int uQuietEnqueue;
695 unsigned long dwCurrentQuietEndTime;
696 SQuietControl sQuiet[MAX_QUIET_COUNT];
699 bool bCountryInfo24G;
701 unsigned short wBeaconInterval;
703 //WPA supplicant deamon
704 struct net_device *wpadev;
707 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
708 unsigned int bwextcount;
709 bool bWPASuppWextEnabled;
714 // user space daemon: hostapd, is used for HOSTAP
718 struct net_device *apdev;
719 int (*tx_80211)(struct sk_buff *skb, struct net_device *dev);
721 unsigned int uChannel;
724 struct iw_statistics wstats; // wireless stats
728 static inline bool device_get_ip(struct vnt_private *pInfo)
730 struct in_device *in_dev = (struct in_device *)pInfo->dev->ip_ptr;
731 struct in_ifaddr *ifa;
733 if (in_dev != NULL) {
734 ifa = (struct in_ifaddr *)in_dev->ifa_list;
736 memcpy(pInfo->abyIPAddr, &ifa->ifa_address, 4);
743 static inline PDEVICE_RD_INFO alloc_rd_info(void)
745 return kzalloc(sizeof(DEVICE_RD_INFO), GFP_ATOMIC);
748 static inline PDEVICE_TD_INFO alloc_td_info(void)
750 return kzalloc(sizeof(DEVICE_TD_INFO), GFP_ATOMIC);
753 /*--------------------- Export Functions --------------------------*/
755 bool device_dma0_xmit(struct vnt_private *pDevice,
756 struct sk_buff *skb, unsigned int uNodeIndex);
757 bool device_alloc_frag_buf(struct vnt_private *pDevice,
758 PSDeFragControlBlock pDeF);
759 int Config_FileOperation(struct vnt_private *pDevice,
760 bool fwrite, unsigned char *Parameter);