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: driver entry for initial, open, close, tx and rx.
29 * vt6656_probe - module initial (insmod) driver entry
30 * device_remove1 - module remove entry
31 * device_open - allocate dma/descripter resource & initial mac/bbp function
32 * device_xmit - asynchronous data tx function
33 * device_set_multi - set mac filter
34 * device_ioctl - ioctl entry
35 * device_close - shutdown mac/bbp & free dma/descriptor resource
36 * device_alloc_frag_buf - rx fragement pre-allocated function
37 * device_free_tx_bufs - free tx buffer function
38 * device_dma0_tx_80211- tx 802.11 frame via dma0
39 * device_dma0_xmit- tx PS buffered frame via dma0
40 * device_init_registers- initial MAC & BBP & RF internal registers.
41 * device_init_rings- initial tx/rx ring buffer
42 * device_init_defrag_cb- initial & allocate de-fragement buffer.
43 * device_tx_srv- tx interrupt service function
75 /*--------------------- Static Definitions -------------------------*/
76 //static int msglevel =MSG_LEVEL_DEBUG;
77 static int msglevel =MSG_LEVEL_INFO;
80 // Define module options
83 // Version Information
84 #define DRIVER_AUTHOR "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
85 MODULE_AUTHOR(DRIVER_AUTHOR);
86 MODULE_LICENSE("GPL");
87 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
89 #define DEVICE_PARAM(N,D) \
90 static int N[MAX_UINTS]=OPTION_DEFAULT;\
91 module_param_array(N, int, NULL, 0);\
92 MODULE_PARM_DESC(N, D);
94 #define RX_DESC_DEF0 64
95 DEVICE_PARAM(RxDescriptors0,"Number of receive usb desc buffer");
98 #define TX_DESC_DEF0 64
99 DEVICE_PARAM(TxDescriptors0,"Number of transmit usb desc buffer");
101 #define CHANNEL_DEF 6
102 DEVICE_PARAM(Channel, "Channel number");
105 /* PreambleType[] is the preamble length used for transmit.
106 0: indicate allows long preamble type
107 1: indicate allows short preamble type
110 #define PREAMBLE_TYPE_DEF 1
112 DEVICE_PARAM(PreambleType, "Preamble Type");
114 #define RTS_THRESH_DEF 2347
115 DEVICE_PARAM(RTSThreshold, "RTS threshold");
117 #define FRAG_THRESH_DEF 2346
118 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
121 #define DATA_RATE_DEF 13
123 0: indicate 1 Mbps 0x02
124 1: indicate 2 Mbps 0x04
125 2: indicate 5.5 Mbps 0x0B
126 3: indicate 11 Mbps 0x16
127 4: indicate 6 Mbps 0x0c
128 5: indicate 9 Mbps 0x12
129 6: indicate 12 Mbps 0x18
130 7: indicate 18 Mbps 0x24
131 8: indicate 24 Mbps 0x30
132 9: indicate 36 Mbps 0x48
133 10: indicate 48 Mbps 0x60
134 11: indicate 54 Mbps 0x6c
135 12: indicate 72 Mbps 0x90
136 13: indicate auto rate
139 DEVICE_PARAM(ConnectionRate, "Connection data rate");
141 #define OP_MODE_DEF 0
142 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
144 /* OpMode[] is used for transmit.
145 0: indicate infrastruct mode used
146 1: indicate adhoc mode used
147 2: indicate AP mode used
152 0: indicate disable power saving mode
153 1: indicate enable power saving mode
156 #define PS_MODE_DEF 0
157 DEVICE_PARAM(PSMode, "Power saving mode");
160 #define SHORT_RETRY_DEF 8
161 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
163 #define LONG_RETRY_DEF 4
164 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
166 /* BasebandType[] baseband type selected
167 0: indicate 802.11a type
168 1: indicate 802.11b type
169 2: indicate 802.11g type
172 #define BBP_TYPE_DEF 2
173 DEVICE_PARAM(BasebandType, "baseband type");
178 0: indicate disable 802.11h
179 1: indicate enable 802.11h
182 #define X80211h_MODE_DEF 0
184 DEVICE_PARAM(b80211hEnable, "802.11h mode");
188 // Static vars definitions
191 static struct usb_device_id vt6656_table[] = {
192 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
196 // Frequency list (map channels to frequencies)
198 static const long frequency_list[] = {
199 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
200 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
201 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
202 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
203 5700, 5745, 5765, 5785, 5805, 5825
207 static const struct iw_handler_def iwctl_handler_def;
210 /*--------------------- Static Functions --------------------------*/
212 static int vt6656_probe(struct usb_interface *intf,
213 const struct usb_device_id *id);
214 static void vt6656_disconnect(struct usb_interface *intf);
216 #ifdef CONFIG_PM /* Minimal support for suspend and resume */
217 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message);
218 static int vt6656_resume(struct usb_interface *intf);
219 #endif /* CONFIG_PM */
221 static struct net_device_stats *device_get_stats(struct net_device *dev);
222 static int device_open(struct net_device *dev);
223 static int device_xmit(struct sk_buff *skb, struct net_device *dev);
224 static void device_set_multi(struct net_device *dev);
225 static int device_close(struct net_device *dev);
226 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
228 static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
229 static BOOL device_init_defrag_cb(PSDevice pDevice);
230 static void device_init_diversity_timer(PSDevice pDevice);
231 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
233 static int ethtool_ioctl(struct net_device *dev, void *useraddr);
234 static void device_free_tx_bufs(PSDevice pDevice);
235 static void device_free_rx_bufs(PSDevice pDevice);
236 static void device_free_int_bufs(PSDevice pDevice);
237 static void device_free_frag_bufs(PSDevice pDevice);
238 static BOOL device_alloc_bufs(PSDevice pDevice);
240 static int Read_config_file(PSDevice pDevice);
241 static unsigned char *Config_FileOperation(PSDevice pDevice);
242 static int Config_FileGetParameter(unsigned char *string,
244 unsigned char *source);
247 static void usb_device_reset(PSDevice pDevice);
251 /*--------------------- Export Variables --------------------------*/
253 /*--------------------- Export Functions --------------------------*/
257 device_set_options(PSDevice pDevice) {
259 BYTE abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
260 BYTE abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
261 u8 abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
263 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
264 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
265 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
267 pDevice->cbTD = TX_DESC_DEF0;
268 pDevice->cbRD = RX_DESC_DEF0;
269 pDevice->uChannel = CHANNEL_DEF;
270 pDevice->wRTSThreshold = RTS_THRESH_DEF;
271 pDevice->wFragmentationThreshold = FRAG_THRESH_DEF;
272 pDevice->byShortRetryLimit = SHORT_RETRY_DEF;
273 pDevice->byLongRetryLimit = LONG_RETRY_DEF;
274 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
275 pDevice->byShortPreamble = PREAMBLE_TYPE_DEF;
276 pDevice->ePSMode = PS_MODE_DEF;
277 pDevice->b11hEnable = X80211h_MODE_DEF;
278 pDevice->eOPMode = OP_MODE_DEF;
279 pDevice->uConnectionRate = DATA_RATE_DEF;
280 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;
281 pDevice->byBBType = BBP_TYPE_DEF;
282 pDevice->byPacketType = pDevice->byBBType;
283 pDevice->byAutoFBCtrl = AUTO_FB_0;
284 pDevice->bUpdateBBVGA = TRUE;
285 pDevice->byFOETuning = 0;
286 pDevice->byAutoPwrTunning = 0;
287 pDevice->wCTSDuration = 0;
288 pDevice->byPreambleType = 0;
289 pDevice->bExistSWNetAddr = FALSE;
290 // pDevice->bDiversityRegCtlON = TRUE;
291 pDevice->bDiversityRegCtlON = FALSE;
295 static void device_init_diversity_timer(PSDevice pDevice)
297 init_timer(&pDevice->TimerSQ3Tmax1);
298 pDevice->TimerSQ3Tmax1.data = (unsigned long)pDevice;
299 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
300 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
302 init_timer(&pDevice->TimerSQ3Tmax2);
303 pDevice->TimerSQ3Tmax2.data = (unsigned long)pDevice;
304 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
305 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
307 init_timer(&pDevice->TimerSQ3Tmax3);
308 pDevice->TimerSQ3Tmax3.data = (unsigned long)pDevice;
309 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerSQ3Tmax3CallBack;
310 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
317 // Initialization of MAC & BBP registers
320 static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
322 u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
323 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
324 u8 abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
327 CMD_CARD_INIT sInitCmd;
328 int ntStatus = STATUS_SUCCESS;
329 RSP_CARD_INIT sInitRsp;
330 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
332 BYTE byCalibTXIQ = 0;
333 BYTE byCalibTXDC = 0;
334 BYTE byCalibRXIQ = 0;
336 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n", InitType, pDevice->byPacketType);
337 spin_lock_irq(&pDevice->lock);
338 if (InitType == DEVICE_INIT_COLD) {
339 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
340 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
341 memcpy(pDevice->abySNAP_Bridgetunnel,
342 abySNAP_Bridgetunnel,
345 if ( !FIRMWAREbCheckVersion(pDevice) ) {
346 if (FIRMWAREbDownload(pDevice) == TRUE) {
347 if (FIRMWAREbBrach2Sram(pDevice) == FALSE) {
348 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbBrach2Sram fail \n");
349 spin_unlock_irq(&pDevice->lock);
354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbDownload fail \n");
355 spin_unlock_irq(&pDevice->lock);
360 if ( !BBbVT3184Init(pDevice) ) {
361 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail \n");
362 spin_unlock_irq(&pDevice->lock);
367 sInitCmd.byInitClass = (BYTE)InitType;
368 sInitCmd.bExistSWNetAddr = (BYTE) pDevice->bExistSWNetAddr;
369 for (ii = 0; ii < 6; ii++)
370 sInitCmd.bySWNetAddr[ii] = pDevice->abyCurrentNetAddr[ii];
371 sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit;
372 sInitCmd.byLongRetryLimit = pDevice->byLongRetryLimit;
374 //issue Card_init command to device
375 ntStatus = CONTROLnsRequestOut(pDevice,
376 MESSAGE_TYPE_CARDINIT,
379 sizeof(CMD_CARD_INIT),
380 (PBYTE) &(sInitCmd));
382 if ( ntStatus != STATUS_SUCCESS ) {
383 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail \n");
384 spin_unlock_irq(&pDevice->lock);
387 if (InitType == DEVICE_INIT_COLD) {
389 ntStatus = CONTROLnsRequestIn(pDevice,MESSAGE_TYPE_INIT_RSP,0,0,sizeof(RSP_CARD_INIT), (PBYTE) &(sInitRsp));
391 if (ntStatus != STATUS_SUCCESS) {
392 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Cardinit request in status fail!\n");
393 spin_unlock_irq(&pDevice->lock);
397 //Local ID for AES functions
398 ntStatus = CONTROLnsRequestIn(pDevice,
401 MESSAGE_REQUEST_MACREG,
403 &pDevice->byLocalID);
405 if ( ntStatus != STATUS_SUCCESS ) {
406 spin_unlock_irq(&pDevice->lock);
410 // Do MACbSoftwareReset in MACvInitialize
412 pDevice->bCCK = TRUE;
413 pDevice->bProtectMode = FALSE; //Only used in 11g type, sync with ERP IE
414 pDevice->bNonERPPresent = FALSE;
415 pDevice->bBarkerPreambleMd = FALSE;
416 if ( pDevice->bFixRate ) {
417 pDevice->wCurrentRate = (WORD) pDevice->uConnectionRate;
419 if ( pDevice->byBBType == BB_TYPE_11B )
420 pDevice->wCurrentRate = RATE_11M;
422 pDevice->wCurrentRate = RATE_54M;
425 CHvInitChannelTable(pDevice);
427 pDevice->byTopOFDMBasicRate = RATE_24M;
428 pDevice->byTopCCKBasicRate = RATE_1M;
429 pDevice->byRevId = 0; //Target to IF pin while programming to RF chip.
430 pDevice->byCurPwr = 0xFF;
432 pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK];
433 pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG];
435 for (ii=0;ii<14;ii++) {
436 pDevice->abyCCKPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_CCK_PWR_TBL];
437 if (pDevice->abyCCKPwrTbl[ii] == 0)
438 pDevice->abyCCKPwrTbl[ii] = pDevice->byCCKPwr;
439 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDM_PWR_TBL];
440 if (pDevice->abyOFDMPwrTbl[ii] == 0)
441 pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG;
444 //original zonetype is USA,but customize zonetype is europe,
445 // then need recover 12,13 ,14 channel with 11 channel
446 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
447 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
448 (pDevice->byOriginalZonetype == ZoneType_USA)) {
449 for (ii = 11; ii < 14; ii++) {
450 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
451 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
455 //{{ RobertYu: 20041124
456 pDevice->byOFDMPwrA = 0x34; // same as RFbMA2829SelectChannel
457 // Load OFDM A Power Table
458 for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
459 pDevice->abyOFDMAPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDMA_PWR_TBL];
460 if (pDevice->abyOFDMAPwrTbl[ii] == 0)
461 pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA;
465 byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA];
466 if (byAntenna & EEP_ANTINV)
467 pDevice->bTxRxAntInv = TRUE;
469 pDevice->bTxRxAntInv = FALSE;
471 byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
473 if (byAntenna == 0) // if not set default is All
474 byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
476 if (byAntenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
477 pDevice->byAntennaCount = 2;
478 pDevice->byTxAntennaMode = ANT_B;
479 pDevice->dwTxAntennaSel = 1;
480 pDevice->dwRxAntennaSel = 1;
481 if (pDevice->bTxRxAntInv == TRUE)
482 pDevice->byRxAntennaMode = ANT_A;
484 pDevice->byRxAntennaMode = ANT_B;
486 if (pDevice->bDiversityRegCtlON)
487 pDevice->bDiversityEnable = TRUE;
489 pDevice->bDiversityEnable = FALSE;
491 pDevice->bDiversityEnable = FALSE;
492 pDevice->byAntennaCount = 1;
493 pDevice->dwTxAntennaSel = 0;
494 pDevice->dwRxAntennaSel = 0;
495 if (byAntenna & EEP_ANTENNA_AUX) {
496 pDevice->byTxAntennaMode = ANT_A;
497 if (pDevice->bTxRxAntInv == TRUE)
498 pDevice->byRxAntennaMode = ANT_B;
500 pDevice->byRxAntennaMode = ANT_A;
502 pDevice->byTxAntennaMode = ANT_B;
503 if (pDevice->bTxRxAntInv == TRUE)
504 pDevice->byRxAntennaMode = ANT_A;
506 pDevice->byRxAntennaMode = ANT_B;
509 pDevice->ulDiversityNValue = 100*255;
510 pDevice->ulDiversityMValue = 100*16;
512 pDevice->byTMax2 = 4;
513 pDevice->ulSQ3TH = 0;
514 pDevice->byTMax3 = 64;
515 // -----------------------------------------------------------------
517 //Get Auto Fall Back Type
518 pDevice->byAutoFBCtrl = AUTO_FB_0;
521 pDevice->uScanTime = WLAN_SCAN_MINITIME;
524 //pDevice->NetworkType = Ndis802_11Automode;
525 pDevice->eConfigPHYMode = PHY_TYPE_AUTO;
526 pDevice->byBBType = BB_TYPE_11G;
528 // initialize BBP registers
529 pDevice->ulTxPower = 25;
532 pDevice->byMinChannel = 1;
533 pDevice->byMaxChannel = CB_MAX_CHANNEL;
536 pDevice->byRFType = sInitRsp.byRFType;
538 if ((pDevice->byRFType & RF_EMU) != 0) {
539 // force change RevID for VT3253 emu
540 pDevice->byRevId = 0x80;
543 // Load EEPROM calibrated vt3266 parameters
544 if (pDevice->byRFType == RF_VT3226D0) {
545 if((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) &&
546 (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) {
547 byCalibTXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_IQ];
548 byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC];
549 byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ];
550 if( (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) ) {
551 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFF, 0x03); // CR255, Set BB to support TX/RX IQ and DC compensation Mode
552 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFB, byCalibTXIQ); // CR251, TX I/Q Imbalance Calibration
553 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFC, byCalibTXDC); // CR252, TX DC-Offset Calibration
554 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFD, byCalibRXIQ); // CR253, RX I/Q Imbalance Calibration
556 // turn off BB Calibration compensation
557 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFF, 0x0); // CR255
561 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
562 pMgmt->uCurrChannel = pDevice->uChannel;
563 pMgmt->uIBSSChannel = pDevice->uChannel;
564 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
566 // get Permanent network address
567 memcpy(pDevice->abyPermanentNetAddr,&(sInitRsp.byNetAddr[0]),6);
568 memcpy(pDevice->abyCurrentNetAddr,
569 pDevice->abyPermanentNetAddr,
572 // if exist SW network address, use SW network address.
574 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n",
575 pDevice->abyCurrentNetAddr);
578 // Set BB and packet type at the same time.
579 // Set Short Slot Time, xIFS, and RSPINF.
580 if (pDevice->byBBType == BB_TYPE_11A) {
581 CARDbAddBasicRate(pDevice, RATE_6M);
582 pDevice->bShortSlotTime = TRUE;
584 CARDbAddBasicRate(pDevice, RATE_1M);
585 pDevice->bShortSlotTime = FALSE;
587 BBvSetShortSlotTime(pDevice);
588 CARDvSetBSSMode(pDevice);
590 if (pDevice->bUpdateBBVGA) {
591 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
592 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
593 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
596 pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL];
597 pDevice->bHWRadioOff = FALSE;
598 if ( (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0 ) {
599 ntStatus = CONTROLnsRequestIn(pDevice,
602 MESSAGE_REQUEST_MACREG,
606 if ( ntStatus != STATUS_SUCCESS ) {
607 spin_unlock_irq(&pDevice->lock);
610 if ( (byTmp & GPIO3_DATA) == 0 ) {
611 pDevice->bHWRadioOff = TRUE;
612 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
614 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
615 pDevice->bHWRadioOff = FALSE;
618 } //EEP_RADIOCTL_ENABLE
620 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_TMLEN,0x38);
621 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
622 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL0,0x01);
624 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
625 CARDbRadioPowerOff(pDevice);
627 CARDbRadioPowerOn(pDevice);
630 spin_unlock_irq(&pDevice->lock);
631 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n");
635 #ifdef CONFIG_PM /* Minimal support for suspend and resume */
637 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
639 PSDevice device = usb_get_intfdata(intf);
641 if (!device || !device->dev)
644 if (device->flags & DEVICE_FLAGS_OPENED)
645 device_close(device->dev);
647 usb_put_dev(interface_to_usbdev(intf));
652 static int vt6656_resume(struct usb_interface *intf)
654 PSDevice device = usb_get_intfdata(intf);
656 if (!device || !device->dev)
659 usb_get_dev(interface_to_usbdev(intf));
661 if (!(device->flags & DEVICE_FLAGS_OPENED))
662 device_open(device->dev);
667 #endif /* CONFIG_PM */
669 static const struct net_device_ops device_netdev_ops = {
670 .ndo_open = device_open,
671 .ndo_stop = device_close,
672 .ndo_do_ioctl = device_ioctl,
673 .ndo_get_stats = device_get_stats,
674 .ndo_start_xmit = device_xmit,
675 .ndo_set_rx_mode = device_set_multi,
679 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
681 u8 fake_mac[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
682 struct usb_device *udev = interface_to_usbdev(intf);
684 struct net_device *netdev = NULL;
685 PSDevice pDevice = NULL;
687 printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
688 printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
690 udev = usb_get_dev(udev);
691 netdev = alloc_etherdev(sizeof(DEVICE_INFO));
693 printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n");
698 pDevice = netdev_priv(netdev);
699 memset(pDevice, 0, sizeof(DEVICE_INFO));
701 pDevice->dev = netdev;
704 device_set_options(pDevice);
705 spin_lock_init(&pDevice->lock);
707 pDevice->tx_80211 = device_dma0_tx_80211;
708 pDevice->sMgmtObj.pAdapter = (void *) pDevice;
710 netdev->netdev_ops = &device_netdev_ops;
711 netdev->wireless_handlers =
712 (struct iw_handler_def *) &iwctl_handler_def;
714 usb_set_intfdata(intf, pDevice);
715 SET_NETDEV_DEV(netdev, &intf->dev);
716 memcpy(pDevice->dev->dev_addr, fake_mac, ETH_ALEN);
717 rc = register_netdev(netdev);
719 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
723 usb_device_reset(pDevice);
735 static void device_free_tx_bufs(PSDevice pDevice)
737 PUSB_SEND_CONTEXT pTxContext;
740 for (ii = 0; ii < pDevice->cbTD; ii++) {
742 pTxContext = pDevice->apTD[ii];
744 if (pTxContext->pUrb) {
745 usb_kill_urb(pTxContext->pUrb);
746 usb_free_urb(pTxContext->pUrb);
754 static void device_free_rx_bufs(PSDevice pDevice)
759 for (ii = 0; ii < pDevice->cbRD; ii++) {
761 pRCB = pDevice->apRCB[ii];
764 usb_kill_urb(pRCB->pUrb);
765 usb_free_urb(pRCB->pUrb);
769 dev_kfree_skb(pRCB->skb);
771 kfree(pDevice->pRCBMem);
776 static void usb_device_reset(PSDevice pDevice)
779 status = usb_reset_device(pDevice->usb);
781 printk("usb_device_reset fail status=%d\n",status);
785 static void device_free_int_bufs(PSDevice pDevice)
787 kfree(pDevice->intBuf.pDataBuf);
792 static BOOL device_alloc_bufs(PSDevice pDevice) {
794 PUSB_SEND_CONTEXT pTxContext;
799 for (ii = 0; ii < pDevice->cbTD; ii++) {
801 pTxContext = kmalloc(sizeof(USB_SEND_CONTEXT), GFP_KERNEL);
802 if (pTxContext == NULL) {
803 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate tx usb context failed\n", pDevice->dev->name);
806 pDevice->apTD[ii] = pTxContext;
807 pTxContext->pDevice = (void *) pDevice;
809 pTxContext->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
810 if (pTxContext->pUrb == NULL) {
811 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "alloc tx urb failed\n");
814 pTxContext->bBoolInUse = FALSE;
818 pDevice->pRCBMem = kzalloc((sizeof(RCB) * pDevice->cbRD), GFP_KERNEL);
819 if (pDevice->pRCBMem == NULL) {
820 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : alloc rx usb context failed\n", pDevice->dev->name);
825 pDevice->FirstRecvFreeList = NULL;
826 pDevice->LastRecvFreeList = NULL;
827 pDevice->FirstRecvMngList = NULL;
828 pDevice->LastRecvMngList = NULL;
829 pDevice->NumRecvFreeList = 0;
830 pRCB = (PRCB) pDevice->pRCBMem;
832 for (ii = 0; ii < pDevice->cbRD; ii++) {
834 pDevice->apRCB[ii] = pRCB;
835 pRCB->pDevice = (void *) pDevice;
837 pRCB->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
839 if (pRCB->pUrb == NULL) {
840 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx urb\n");
843 pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
844 if (pRCB->skb == NULL) {
845 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx skb\n");
848 pRCB->skb->dev = pDevice->dev;
849 pRCB->bBoolInUse = FALSE;
850 EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB);
851 pDevice->NumRecvFreeList++;
856 pDevice->pControlURB = usb_alloc_urb(0, GFP_ATOMIC);
857 if (pDevice->pControlURB == NULL) {
858 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc control urb\n");
862 pDevice->pInterruptURB = usb_alloc_urb(0, GFP_ATOMIC);
863 if (pDevice->pInterruptURB == NULL) {
864 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int urb\n");
865 usb_free_urb(pDevice->pControlURB);
869 pDevice->intBuf.pDataBuf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
870 if (pDevice->intBuf.pDataBuf == NULL) {
871 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int buf\n");
872 usb_free_urb(pDevice->pControlURB);
873 usb_free_urb(pDevice->pInterruptURB);
880 device_free_rx_bufs(pDevice);
883 device_free_tx_bufs(pDevice);
891 static BOOL device_init_defrag_cb(PSDevice pDevice) {
893 PSDeFragControlBlock pDeF;
895 /* Init the fragment ctl entries */
896 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
897 pDeF = &(pDevice->sRxDFCB[i]);
898 if (!device_alloc_frag_buf(pDevice, pDeF)) {
899 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
904 pDevice->cbDFCB = CB_MAX_RX_FRAG;
905 pDevice->cbFreeDFCB = pDevice->cbDFCB;
909 device_free_frag_bufs(pDevice);
915 static void device_free_frag_bufs(PSDevice pDevice) {
916 PSDeFragControlBlock pDeF;
919 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
921 pDeF = &(pDevice->sRxDFCB[i]);
924 dev_kfree_skb(pDeF->skb);
930 BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
932 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
933 if (pDeF->skb == NULL)
936 pDeF->skb->dev = pDevice->dev;
942 /*-----------------------------------------------------------------*/
944 static int device_open(struct net_device *dev) {
945 PSDevice pDevice=(PSDevice) netdev_priv(dev);
947 pDevice->fWPA_Authened = FALSE;
949 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");
952 pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
954 if (device_alloc_bufs(pDevice) == FALSE) {
955 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n");
959 if (device_init_defrag_cb(pDevice)== FALSE) {
960 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n");
964 MP_CLEAR_FLAG(pDevice, fMP_DISCONNECTED);
965 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
966 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
967 MP_SET_FLAG(pDevice, fMP_POST_READS);
968 MP_SET_FLAG(pDevice, fMP_POST_WRITES);
971 Read_config_file(pDevice);
973 if (device_init_registers(pDevice, DEVICE_INIT_COLD) == FALSE) {
974 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n");
978 device_set_multi(pDevice->dev);
979 // Init for Key Management
981 KeyvInitTable(pDevice,&pDevice->sKey);
982 memcpy(pDevice->sMgmtObj.abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN);
983 memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN);
984 pDevice->bStopTx0Pkt = FALSE;
985 pDevice->bStopDataPkt = FALSE;
986 pDevice->bRoaming = FALSE;
987 pDevice->bIsRoaming = FALSE;
988 pDevice->bEnableRoaming = FALSE;
989 if (pDevice->bDiversityRegCtlON) {
990 device_init_diversity_timer(pDevice);
993 vMgrObjectInit(pDevice);
994 tasklet_init(&pDevice->RxMngWorkItem, (void *)RXvMngWorkItem, (unsigned long)pDevice);
995 tasklet_init(&pDevice->ReadWorkItem, (void *)RXvWorkItem, (unsigned long)pDevice);
996 tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice);
997 add_timer(&(pDevice->sMgmtObj.sTimerSecondCallback));
998 pDevice->int_interval = 100; //Max 100 microframes.
999 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1001 pDevice->bIsRxWorkItemQueued = TRUE;
1002 pDevice->fKillEventPollingThread = FALSE;
1003 pDevice->bEventAvailable = FALSE;
1005 pDevice->bWPADEVUp = FALSE;
1006 pDevice->bwextstep0 = FALSE;
1007 pDevice->bwextstep1 = FALSE;
1008 pDevice->bwextstep2 = FALSE;
1009 pDevice->bwextstep3 = FALSE;
1010 pDevice->bWPASuppWextEnabled = FALSE;
1011 pDevice->byReAssocCount = 0;
1013 RXvWorkItem(pDevice);
1014 INTvWorkItem(pDevice);
1016 // Patch: if WEP key already set by iwconfig but device not yet open
1017 if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) {
1018 spin_lock_irq(&pDevice->lock);
1019 KeybSetDefaultKey( pDevice,
1021 pDevice->byKeyIndex | (1 << 31),
1022 pDevice->uKeyLength,
1027 spin_unlock_irq(&pDevice->lock);
1028 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1031 if (pDevice->sMgmtObj.eConfigMode == WMAC_CONFIG_AP) {
1032 bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL);
1035 //mike:mark@2008-11-10
1036 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1037 /* bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL); */
1041 netif_stop_queue(pDevice->dev);
1042 pDevice->flags |= DEVICE_FLAGS_OPENED;
1044 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success..\n");
1048 device_free_frag_bufs(pDevice);
1050 device_free_rx_bufs(pDevice);
1051 device_free_tx_bufs(pDevice);
1052 device_free_int_bufs(pDevice);
1053 usb_kill_urb(pDevice->pControlURB);
1054 usb_kill_urb(pDevice->pInterruptURB);
1055 usb_free_urb(pDevice->pControlURB);
1056 usb_free_urb(pDevice->pInterruptURB);
1058 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open fail.. \n");
1064 static int device_close(struct net_device *dev) {
1065 PSDevice pDevice=(PSDevice) netdev_priv(dev);
1066 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1070 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1 \n");
1071 if (pDevice == NULL)
1074 if (pDevice->bLinkPass) {
1075 bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1080 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1081 pMgmt->bShareKeyAlgorithm = FALSE;
1082 pDevice->bEncryptionEnable = FALSE;
1083 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1084 spin_lock_irq(&pDevice->lock);
1085 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1086 MACvDisableKeyEntry(pDevice,uu);
1087 spin_unlock_irq(&pDevice->lock);
1089 if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == FALSE) {
1090 MACbShutdown(pDevice);
1092 netif_stop_queue(pDevice->dev);
1093 MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
1094 MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES);
1095 MP_CLEAR_FLAG(pDevice, fMP_POST_READS);
1096 pDevice->fKillEventPollingThread = TRUE;
1097 del_timer(&pDevice->sTimerCommand);
1098 del_timer(&pMgmt->sTimerSecondCallback);
1100 del_timer(&pDevice->sTimerTxData);
1102 if (pDevice->bDiversityRegCtlON) {
1103 del_timer(&pDevice->TimerSQ3Tmax1);
1104 del_timer(&pDevice->TimerSQ3Tmax2);
1105 del_timer(&pDevice->TimerSQ3Tmax3);
1107 tasklet_kill(&pDevice->RxMngWorkItem);
1108 tasklet_kill(&pDevice->ReadWorkItem);
1109 tasklet_kill(&pDevice->EventWorkItem);
1111 pDevice->bRoaming = FALSE;
1112 pDevice->bIsRoaming = FALSE;
1113 pDevice->bEnableRoaming = FALSE;
1114 pDevice->bCmdRunning = FALSE;
1115 pDevice->bLinkPass = FALSE;
1116 memset(pMgmt->abyCurrBSSID, 0, 6);
1117 pMgmt->eCurrState = WMAC_STATE_IDLE;
1119 device_free_tx_bufs(pDevice);
1120 device_free_rx_bufs(pDevice);
1121 device_free_int_bufs(pDevice);
1122 device_free_frag_bufs(pDevice);
1124 usb_kill_urb(pDevice->pControlURB);
1125 usb_kill_urb(pDevice->pInterruptURB);
1126 usb_free_urb(pDevice->pControlURB);
1127 usb_free_urb(pDevice->pInterruptURB);
1129 BSSvClearNodeDBTable(pDevice, 0);
1130 pDevice->flags &=(~DEVICE_FLAGS_OPENED);
1132 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n");
1137 static void vt6656_disconnect(struct usb_interface *intf)
1139 PSDevice device = usb_get_intfdata(intf);
1145 usb_set_intfdata(intf, NULL);
1146 usb_put_dev(interface_to_usbdev(intf));
1148 device->flags |= DEVICE_FLAGS_UNPLUG;
1151 unregister_netdev(device->dev);
1152 free_netdev(device->dev);
1157 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1159 PSDevice pDevice = netdev_priv(dev);
1161 spin_lock_irq(&pDevice->lock);
1163 if (unlikely(pDevice->bStopTx0Pkt))
1164 dev_kfree_skb_irq(skb);
1166 vDMA0_tx_80211(pDevice, skb);
1168 spin_unlock_irq(&pDevice->lock);
1170 return NETDEV_TX_OK;
1173 static int device_xmit(struct sk_buff *skb, struct net_device *dev)
1175 PSDevice pDevice = netdev_priv(dev);
1176 struct net_device_stats *stats = &pDevice->stats;
1178 spin_lock_irq(&pDevice->lock);
1180 netif_stop_queue(dev);
1182 if (!pDevice->bLinkPass) {
1183 dev_kfree_skb_irq(skb);
1187 if (pDevice->bStopDataPkt) {
1188 dev_kfree_skb_irq(skb);
1189 stats->tx_dropped++;
1193 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb)) {
1194 if (netif_queue_stopped(dev))
1195 netif_wake_queue(dev);
1199 spin_unlock_irq(&pDevice->lock);
1201 return NETDEV_TX_OK;
1204 static unsigned const ethernet_polynomial = 0x04c11db7U;
1205 static inline u32 ether_crc(int length, unsigned char *data)
1209 while(--length >= 0) {
1210 unsigned char current_octet = *data++;
1212 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
1214 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
1220 //find out the start position of str2 from str1
1221 static unsigned char *kstrstr(const unsigned char *str1,
1222 const unsigned char *str2) {
1223 int str1_len = strlen(str1);
1224 int str2_len = strlen(str2);
1226 while (str1_len >= str2_len) {
1228 if(memcmp(str1,str2,str2_len)==0)
1229 return (unsigned char *) str1;
1235 static int Config_FileGetParameter(unsigned char *string,
1236 unsigned char *dest,
1237 unsigned char *source)
1239 unsigned char buf1[100];
1240 unsigned char buf2[100];
1241 unsigned char *start_p = NULL, *end_p = NULL, *tmp_p = NULL;
1245 strcat(buf1, string);
1247 source+=strlen(buf1);
1249 //find target string start point
1250 start_p = kstrstr(source,buf1);
1251 if (start_p == NULL)
1254 //check if current config line is marked by "#" ??
1255 for (ii = 1; ; ii++) {
1256 if (memcmp(start_p - ii, "\n", 1) == 0)
1258 if (memcmp(start_p - ii, "#", 1) == 0)
1262 //find target string end point
1263 end_p = kstrstr(start_p,"\n");
1264 if (end_p == NULL) { //can't find "\n",but don't care
1265 end_p=start_p+strlen(start_p); //no include "\n"
1269 memcpy(buf2,start_p,end_p-start_p); //get the target line
1270 buf2[end_p-start_p]='\0';
1273 start_p = kstrstr(buf2,"=");
1274 if (start_p == NULL)
1277 strcpy(buf1,start_p+1);
1281 while(*tmp_p != 0x00) {
1288 memcpy(dest,tmp_p,strlen(tmp_p));
1292 //if read fail,return NULL,or return data pointer;
1293 static unsigned char *Config_FileOperation(PSDevice pDevice)
1295 unsigned char *config_path = CONFIG_PATH;
1296 unsigned char *buffer = NULL;
1297 struct file *filp=NULL;
1298 mm_segment_t old_fs = get_fs();
1299 //int oldfsuid=0,oldfsgid=0;
1303 /* Can't do this anymore, so we rely on correct filesystem permissions:
1304 //Make sure a caller can read or write power as root
1305 oldfsuid=current->fsuid;
1306 oldfsgid=current->fsgid;
1312 filp = filp_open(config_path, O_RDWR, 0);
1314 printk("Config_FileOperation file Not exist\n");
1319 if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
1320 printk("file %s is not read or writeable?\n",config_path);
1325 buffer = kmalloc(1024, GFP_KERNEL);
1327 printk("allocate mem for file fail?\n");
1332 if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
1333 printk("read file error?\n");
1338 if(filp_close(filp,NULL))
1339 printk("Config_FileOperation:close file fail\n");
1345 current->fsuid=oldfsuid;
1346 current->fsgid=oldfsgid;
1356 //return --->-1:fail; >=0:successful
1357 static int Read_config_file(PSDevice pDevice) {
1359 unsigned char tmpbuffer[100];
1360 unsigned char *buffer = NULL;
1362 //init config setting
1363 pDevice->config_file.ZoneType = -1;
1364 pDevice->config_file.eAuthenMode = -1;
1365 pDevice->config_file.eEncryptionStatus = -1;
1367 buffer = Config_FileOperation(pDevice);
1368 if (buffer == NULL) {
1375 memset(tmpbuffer,0,sizeof(tmpbuffer));
1376 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==TRUE) {
1377 if(memcmp(tmpbuffer,"USA",3)==0) {
1378 pDevice->config_file.ZoneType=ZoneType_USA;
1380 else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
1381 pDevice->config_file.ZoneType=ZoneType_Japan;
1383 else if(memcmp(tmpbuffer,"EUROPE",6)==0) {
1384 pDevice->config_file.ZoneType=ZoneType_Europe;
1387 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
1392 //get other parameter
1394 memset(tmpbuffer,0,sizeof(tmpbuffer));
1395 if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==TRUE) {
1396 pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10);
1399 memset(tmpbuffer,0,sizeof(tmpbuffer));
1400 if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==TRUE) {
1401 pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10);
1409 static void device_set_multi(struct net_device *dev) {
1410 PSDevice pDevice = (PSDevice) netdev_priv(dev);
1411 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1414 struct netdev_hw_addr *ha;
1415 BYTE pbyData[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
1420 spin_lock_irq(&pDevice->lock);
1421 rc = CONTROLnsRequestIn(pDevice,
1424 MESSAGE_REQUEST_MACREG,
1428 if (rc == 0) pDevice->byRxMode = byTmpMode;
1430 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode in= %x\n", pDevice->byRxMode);
1432 if (dev->flags & IFF_PROMISC) { // Set promiscuous.
1433 DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
1434 // Unconditionally log net taps.
1435 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
1437 else if ((netdev_mc_count(dev) > pDevice->multicast_limit) ||
1438 (dev->flags & IFF_ALLMULTI)) {
1439 CONTROLnsRequestOut(pDevice,
1442 MESSAGE_REQUEST_MACREG,
1446 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1449 memset(mc_filter, 0, sizeof(mc_filter));
1450 netdev_for_each_mc_addr(ha, dev) {
1451 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1452 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
1454 for (ii = 0; ii < 4; ii++) {
1455 MACvWriteMultiAddr(pDevice, ii, *((PBYTE)&mc_filter[0] + ii));
1456 MACvWriteMultiAddr(pDevice, ii+ 4, *((PBYTE)&mc_filter[1] + ii));
1458 pDevice->byRxMode &= ~(RCR_UNICAST);
1459 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1462 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1463 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
1464 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1465 pDevice->byRxMode &= ~(RCR_UNICAST);
1467 ControlvWriteByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, pDevice->byRxMode);
1468 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode out= %x\n", pDevice->byRxMode);
1469 spin_unlock_irq(&pDevice->lock);
1473 static struct net_device_stats *device_get_stats(struct net_device *dev)
1475 PSDevice pDevice=(PSDevice) netdev_priv(dev);
1477 return &pDevice->stats;
1480 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1482 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1483 struct iwreq *wrq = (struct iwreq *) rq;
1488 case IOCTL_CMD_HOSTAPD:
1490 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
1493 rc = vt6656_hostap_ioctl(pDevice, &wrq->u.data);
1497 return ethtool_ioctl(dev, (void *) rq->ifr_data);
1505 static int ethtool_ioctl(struct net_device *dev, void *useraddr)
1509 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
1513 case ETHTOOL_GDRVINFO: {
1514 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
1515 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
1516 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
1517 if (copy_to_user(useraddr, &info, sizeof(info)))
1528 /*------------------------------------------------------------------*/
1530 MODULE_DEVICE_TABLE(usb, vt6656_table);
1532 static struct usb_driver vt6656_driver = {
1533 .name = DEVICE_NAME,
1534 .probe = vt6656_probe,
1535 .disconnect = vt6656_disconnect,
1536 .id_table = vt6656_table,
1538 .suspend = vt6656_suspend,
1539 .resume = vt6656_resume,
1540 #endif /* CONFIG_PM */
1543 module_usb_driver(vt6656_driver);