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 \
85 "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
86 MODULE_AUTHOR(DRIVER_AUTHOR);
87 MODULE_LICENSE("GPL");
88 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
90 #define DEVICE_PARAM(N,D) \
91 static int N[MAX_UINTS]=OPTION_DEFAULT;\
92 module_param_array(N, int, NULL, 0);\
93 MODULE_PARM_DESC(N, D);
95 #define RX_DESC_DEF0 64
96 DEVICE_PARAM(RxDescriptors0,"Number of receive usb desc buffer");
99 #define TX_DESC_DEF0 64
100 DEVICE_PARAM(TxDescriptors0,"Number of transmit usb desc buffer");
102 #define CHANNEL_DEF 6
103 DEVICE_PARAM(Channel, "Channel number");
106 /* PreambleType[] is the preamble length used for transmit.
107 0: indicate allows long preamble type
108 1: indicate allows short preamble type
111 #define PREAMBLE_TYPE_DEF 1
113 DEVICE_PARAM(PreambleType, "Preamble Type");
115 #define RTS_THRESH_DEF 2347
116 DEVICE_PARAM(RTSThreshold, "RTS threshold");
118 #define FRAG_THRESH_DEF 2346
119 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
122 #define DATA_RATE_DEF 13
124 0: indicate 1 Mbps 0x02
125 1: indicate 2 Mbps 0x04
126 2: indicate 5.5 Mbps 0x0B
127 3: indicate 11 Mbps 0x16
128 4: indicate 6 Mbps 0x0c
129 5: indicate 9 Mbps 0x12
130 6: indicate 12 Mbps 0x18
131 7: indicate 18 Mbps 0x24
132 8: indicate 24 Mbps 0x30
133 9: indicate 36 Mbps 0x48
134 10: indicate 48 Mbps 0x60
135 11: indicate 54 Mbps 0x6c
136 12: indicate 72 Mbps 0x90
137 13: indicate auto rate
140 DEVICE_PARAM(ConnectionRate, "Connection data rate");
142 #define OP_MODE_DEF 0
143 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
145 /* OpMode[] is used for transmit.
146 0: indicate infrastruct mode used
147 1: indicate adhoc mode used
148 2: indicate AP mode used
153 0: indicate disable power saving mode
154 1: indicate enable power saving mode
157 #define PS_MODE_DEF 0
158 DEVICE_PARAM(PSMode, "Power saving mode");
161 #define SHORT_RETRY_DEF 8
162 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
164 #define LONG_RETRY_DEF 4
165 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
167 /* BasebandType[] baseband type selected
168 0: indicate 802.11a type
169 1: indicate 802.11b type
170 2: indicate 802.11g type
173 #define BBP_TYPE_DEF 2
174 DEVICE_PARAM(BasebandType, "baseband type");
179 0: indicate disable 802.11h
180 1: indicate enable 802.11h
183 #define X80211h_MODE_DEF 0
185 DEVICE_PARAM(b80211hEnable, "802.11h mode");
189 * Static vars definitions
192 static struct usb_device_id vt6656_table[] = {
193 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
197 /* frequency list (map channels to frequencies) */
199 static const long frequency_list[] = {
200 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
201 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
202 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
203 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
204 5700, 5745, 5765, 5785, 5805, 5825
208 static const struct iw_handler_def iwctl_handler_def;
211 /*--------------------- Static Functions --------------------------*/
213 static int vt6656_probe(struct usb_interface *intf,
214 const struct usb_device_id *id);
215 static void vt6656_disconnect(struct usb_interface *intf);
217 #ifdef CONFIG_PM /* Minimal support for suspend and resume */
218 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message);
219 static int vt6656_resume(struct usb_interface *intf);
220 #endif /* CONFIG_PM */
222 static struct net_device_stats *device_get_stats(struct net_device *dev);
223 static int device_open(struct net_device *dev);
224 static int device_xmit(struct sk_buff *skb, struct net_device *dev);
225 static void device_set_multi(struct net_device *dev);
226 static int device_close(struct net_device *dev);
227 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
229 static int device_init_registers(struct vnt_private *pDevice,
230 DEVICE_INIT_TYPE InitType);
231 static bool device_init_defrag_cb(struct vnt_private *pDevice);
232 static void device_init_diversity_timer(struct vnt_private *pDevice);
233 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
235 static int ethtool_ioctl(struct net_device *dev, void *useraddr);
236 static void device_free_tx_bufs(struct vnt_private *pDevice);
237 static void device_free_rx_bufs(struct vnt_private *pDevice);
238 static void device_free_int_bufs(struct vnt_private *pDevice);
239 static void device_free_frag_bufs(struct vnt_private *pDevice);
240 static bool device_alloc_bufs(struct vnt_private *pDevice);
242 static int Read_config_file(struct vnt_private *pDevice);
243 static unsigned char *Config_FileOperation(struct vnt_private *pDevice);
244 static int Config_FileGetParameter(unsigned char *string,
246 unsigned char *source);
249 static void usb_device_reset(struct vnt_private *pDevice);
253 /*--------------------- Export Variables --------------------------*/
255 /*--------------------- Export Functions --------------------------*/
259 device_set_options(struct vnt_private *pDevice) {
261 BYTE abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
262 BYTE abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
263 u8 abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
265 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
266 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
267 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
269 pDevice->cbTD = TX_DESC_DEF0;
270 pDevice->cbRD = RX_DESC_DEF0;
271 pDevice->uChannel = CHANNEL_DEF;
272 pDevice->wRTSThreshold = RTS_THRESH_DEF;
273 pDevice->wFragmentationThreshold = FRAG_THRESH_DEF;
274 pDevice->byShortRetryLimit = SHORT_RETRY_DEF;
275 pDevice->byLongRetryLimit = LONG_RETRY_DEF;
276 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
277 pDevice->byShortPreamble = PREAMBLE_TYPE_DEF;
278 pDevice->ePSMode = PS_MODE_DEF;
279 pDevice->b11hEnable = X80211h_MODE_DEF;
280 pDevice->eOPMode = OP_MODE_DEF;
281 pDevice->uConnectionRate = DATA_RATE_DEF;
282 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true;
283 pDevice->byBBType = BBP_TYPE_DEF;
284 pDevice->byPacketType = pDevice->byBBType;
285 pDevice->byAutoFBCtrl = AUTO_FB_0;
286 pDevice->bUpdateBBVGA = true;
287 pDevice->byFOETuning = 0;
288 pDevice->byAutoPwrTunning = 0;
289 pDevice->wCTSDuration = 0;
290 pDevice->byPreambleType = 0;
291 pDevice->bExistSWNetAddr = false;
292 /* pDevice->bDiversityRegCtlON = true; */
293 pDevice->bDiversityRegCtlON = false;
297 static void device_init_diversity_timer(struct vnt_private *pDevice)
299 init_timer(&pDevice->TimerSQ3Tmax1);
300 pDevice->TimerSQ3Tmax1.data = (unsigned long)pDevice;
301 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
302 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
304 init_timer(&pDevice->TimerSQ3Tmax2);
305 pDevice->TimerSQ3Tmax2.data = (unsigned long)pDevice;
306 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
307 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
309 init_timer(&pDevice->TimerSQ3Tmax3);
310 pDevice->TimerSQ3Tmax3.data = (unsigned long)pDevice;
311 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerSQ3Tmax3CallBack;
312 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
319 * initialization of MAC & BBP registers
322 static int device_init_registers(struct vnt_private *pDevice,
323 DEVICE_INIT_TYPE InitType)
325 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
326 u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
327 u8 abySNAP_RFC1042[ETH_ALEN] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
328 u8 abySNAP_Bridgetunnel[ETH_ALEN]
329 = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8};
332 CMD_CARD_INIT sInitCmd;
333 int ntStatus = STATUS_SUCCESS;
334 RSP_CARD_INIT sInitRsp;
336 u8 byCalibTXIQ = 0, byCalibTXDC = 0, byCalibRXIQ = 0;
338 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n", InitType, pDevice->byPacketType);
339 spin_lock_irq(&pDevice->lock);
340 if (InitType == DEVICE_INIT_COLD) {
341 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
342 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
343 memcpy(pDevice->abySNAP_Bridgetunnel,
344 abySNAP_Bridgetunnel,
347 if ( !FIRMWAREbCheckVersion(pDevice) ) {
348 if (FIRMWAREbDownload(pDevice) == true) {
349 if (FIRMWAREbBrach2Sram(pDevice) == false) {
350 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbBrach2Sram fail \n");
351 spin_unlock_irq(&pDevice->lock);
356 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbDownload fail \n");
357 spin_unlock_irq(&pDevice->lock);
362 if ( !BBbVT3184Init(pDevice) ) {
363 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail \n");
364 spin_unlock_irq(&pDevice->lock);
369 sInitCmd.byInitClass = (BYTE)InitType;
370 sInitCmd.bExistSWNetAddr = (BYTE) pDevice->bExistSWNetAddr;
371 for (ii = 0; ii < 6; ii++)
372 sInitCmd.bySWNetAddr[ii] = pDevice->abyCurrentNetAddr[ii];
373 sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit;
374 sInitCmd.byLongRetryLimit = pDevice->byLongRetryLimit;
376 /* issue card_init command to device */
377 ntStatus = CONTROLnsRequestOut(pDevice,
378 MESSAGE_TYPE_CARDINIT,
381 sizeof(CMD_CARD_INIT),
382 (PBYTE) &(sInitCmd));
384 if ( ntStatus != STATUS_SUCCESS ) {
385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail \n");
386 spin_unlock_irq(&pDevice->lock);
389 if (InitType == DEVICE_INIT_COLD) {
391 ntStatus = CONTROLnsRequestIn(pDevice,MESSAGE_TYPE_INIT_RSP,0,0,sizeof(RSP_CARD_INIT), (PBYTE) &(sInitRsp));
393 if (ntStatus != STATUS_SUCCESS) {
394 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Cardinit request in status fail!\n");
395 spin_unlock_irq(&pDevice->lock);
399 /* local ID for AES functions */
400 ntStatus = CONTROLnsRequestIn(pDevice,
403 MESSAGE_REQUEST_MACREG,
405 &pDevice->byLocalID);
407 if ( ntStatus != STATUS_SUCCESS ) {
408 spin_unlock_irq(&pDevice->lock);
412 /* do MACbSoftwareReset in MACvInitialize */
415 pDevice->bCCK = true;
416 pDevice->bProtectMode = false;
417 /* only used in 11g type, sync with ERP IE */
418 pDevice->bNonERPPresent = false;
419 pDevice->bBarkerPreambleMd = false;
420 if ( pDevice->bFixRate ) {
421 pDevice->wCurrentRate = (WORD) pDevice->uConnectionRate;
423 if ( pDevice->byBBType == BB_TYPE_11B )
424 pDevice->wCurrentRate = RATE_11M;
426 pDevice->wCurrentRate = RATE_54M;
429 CHvInitChannelTable(pDevice);
431 pDevice->byTopOFDMBasicRate = RATE_24M;
432 pDevice->byTopCCKBasicRate = RATE_1M;
433 pDevice->byRevId = 0;
434 /* target to IF pin while programming to RF chip */
435 pDevice->byCurPwr = 0xFF;
437 pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK];
438 pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG];
439 /* load power table */
440 for (ii = 0; ii < 14; ii++) {
441 pDevice->abyCCKPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_CCK_PWR_TBL];
442 if (pDevice->abyCCKPwrTbl[ii] == 0)
443 pDevice->abyCCKPwrTbl[ii] = pDevice->byCCKPwr;
444 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDM_PWR_TBL];
445 if (pDevice->abyOFDMPwrTbl[ii] == 0)
446 pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG;
450 * original zonetype is USA, but custom zonetype is Europe,
451 * then need to recover 12, 13, 14 channels with 11 channel
453 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
454 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
455 (pDevice->byOriginalZonetype == ZoneType_USA)) {
456 for (ii = 11; ii < 14; ii++) {
457 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
458 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
462 pDevice->byOFDMPwrA = 0x34; /* same as RFbMA2829SelectChannel */
464 /* load OFDM A power table */
465 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
466 pDevice->abyOFDMAPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDMA_PWR_TBL];
467 if (pDevice->abyOFDMAPwrTbl[ii] == 0)
468 pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA;
471 byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA];
472 if (byAntenna & EEP_ANTINV)
473 pDevice->bTxRxAntInv = true;
475 pDevice->bTxRxAntInv = false;
477 byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
479 if (byAntenna == 0) /* if not set default is both */
480 byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
482 if (byAntenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
483 pDevice->byAntennaCount = 2;
484 pDevice->byTxAntennaMode = ANT_B;
485 pDevice->dwTxAntennaSel = 1;
486 pDevice->dwRxAntennaSel = 1;
487 if (pDevice->bTxRxAntInv == true)
488 pDevice->byRxAntennaMode = ANT_A;
490 pDevice->byRxAntennaMode = ANT_B;
492 if (pDevice->bDiversityRegCtlON)
493 pDevice->bDiversityEnable = true;
495 pDevice->bDiversityEnable = false;
497 pDevice->bDiversityEnable = false;
498 pDevice->byAntennaCount = 1;
499 pDevice->dwTxAntennaSel = 0;
500 pDevice->dwRxAntennaSel = 0;
501 if (byAntenna & EEP_ANTENNA_AUX) {
502 pDevice->byTxAntennaMode = ANT_A;
503 if (pDevice->bTxRxAntInv == true)
504 pDevice->byRxAntennaMode = ANT_B;
506 pDevice->byRxAntennaMode = ANT_A;
508 pDevice->byTxAntennaMode = ANT_B;
509 if (pDevice->bTxRxAntInv == true)
510 pDevice->byRxAntennaMode = ANT_A;
512 pDevice->byRxAntennaMode = ANT_B;
515 pDevice->ulDiversityNValue = 100*255;
516 pDevice->ulDiversityMValue = 100*16;
518 pDevice->byTMax2 = 4;
519 pDevice->ulSQ3TH = 0;
520 pDevice->byTMax3 = 64;
522 /* get Auto Fall Back type */
523 pDevice->byAutoFBCtrl = AUTO_FB_0;
526 pDevice->uScanTime = WLAN_SCAN_MINITIME;
528 /* default Auto Mode */
529 /* pDevice->NetworkType = Ndis802_11Automode; */
530 pDevice->eConfigPHYMode = PHY_TYPE_AUTO;
531 pDevice->byBBType = BB_TYPE_11G;
533 /* initialize BBP registers */
534 pDevice->ulTxPower = 25;
536 /* get channel range */
537 pDevice->byMinChannel = 1;
538 pDevice->byMaxChannel = CB_MAX_CHANNEL;
541 pDevice->byRFType = sInitRsp.byRFType;
543 if ((pDevice->byRFType & RF_EMU) != 0) {
544 /* force change RevID for VT3253 emu */
545 pDevice->byRevId = 0x80;
548 /* load vt3266 calibration parameters in EEPROM */
549 if (pDevice->byRFType == RF_VT3226D0) {
550 if((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) &&
551 (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) {
552 byCalibTXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_IQ];
553 byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC];
554 byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ];
555 if( (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) ) {
556 /* CR255, enable TX/RX IQ and DC compensation mode */
557 ControlvWriteByte(pDevice,
558 MESSAGE_REQUEST_BBREG,
561 /* CR251, TX I/Q Imbalance Calibration */
562 ControlvWriteByte(pDevice,
563 MESSAGE_REQUEST_BBREG,
566 /* CR252, TX DC-Offset Calibration */
567 ControlvWriteByte(pDevice,
568 MESSAGE_REQUEST_BBREG,
571 /* CR253, RX I/Q Imbalance Calibration */
572 ControlvWriteByte(pDevice,
573 MESSAGE_REQUEST_BBREG,
577 /* CR255, turn off BB Calibration compensation */
578 ControlvWriteByte(pDevice,
579 MESSAGE_REQUEST_BBREG,
585 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
586 pMgmt->uCurrChannel = pDevice->uChannel;
587 pMgmt->uIBSSChannel = pDevice->uChannel;
588 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
590 /* get permanent network address */
591 memcpy(pDevice->abyPermanentNetAddr,&(sInitRsp.byNetAddr[0]),6);
592 memcpy(pDevice->abyCurrentNetAddr,
593 pDevice->abyPermanentNetAddr,
596 /* if exist SW network address, use it */
597 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n",
598 pDevice->abyCurrentNetAddr);
602 * set BB and packet type at the same time
603 * set Short Slot Time, xIFS, and RSPINF
605 if (pDevice->byBBType == BB_TYPE_11A) {
606 CARDbAddBasicRate(pDevice, RATE_6M);
607 pDevice->bShortSlotTime = true;
609 CARDbAddBasicRate(pDevice, RATE_1M);
610 pDevice->bShortSlotTime = false;
612 BBvSetShortSlotTime(pDevice);
613 CARDvSetBSSMode(pDevice);
615 if (pDevice->bUpdateBBVGA) {
616 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
617 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
618 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
621 pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL];
622 pDevice->bHWRadioOff = false;
623 if ( (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0 ) {
624 ntStatus = CONTROLnsRequestIn(pDevice,
627 MESSAGE_REQUEST_MACREG,
631 if ( ntStatus != STATUS_SUCCESS ) {
632 spin_unlock_irq(&pDevice->lock);
635 if ( (byTmp & GPIO3_DATA) == 0 ) {
636 pDevice->bHWRadioOff = true;
637 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
639 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
640 pDevice->bHWRadioOff = false;
645 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_TMLEN,0x38);
646 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
647 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL0,0x01);
649 if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) {
650 CARDbRadioPowerOff(pDevice);
652 CARDbRadioPowerOn(pDevice);
655 spin_unlock_irq(&pDevice->lock);
656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n");
660 #ifdef CONFIG_PM /* Minimal support for suspend and resume */
662 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
664 struct vnt_private *device = usb_get_intfdata(intf);
666 if (!device || !device->dev)
669 if (device->flags & DEVICE_FLAGS_OPENED)
670 device_close(device->dev);
675 static int vt6656_resume(struct usb_interface *intf)
677 struct vnt_private *device = usb_get_intfdata(intf);
679 if (!device || !device->dev)
682 if (!(device->flags & DEVICE_FLAGS_OPENED))
683 device_open(device->dev);
688 #endif /* CONFIG_PM */
690 static const struct net_device_ops device_netdev_ops = {
691 .ndo_open = device_open,
692 .ndo_stop = device_close,
693 .ndo_do_ioctl = device_ioctl,
694 .ndo_get_stats = device_get_stats,
695 .ndo_start_xmit = device_xmit,
696 .ndo_set_rx_mode = device_set_multi,
700 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
702 u8 fake_mac[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
703 struct usb_device *udev = interface_to_usbdev(intf);
705 struct net_device *netdev = NULL;
706 struct vnt_private *pDevice;
708 printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
709 printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
711 udev = usb_get_dev(udev);
712 netdev = alloc_etherdev(sizeof(struct vnt_private));
714 printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n");
719 pDevice = netdev_priv(netdev);
720 memset(pDevice, 0, sizeof(struct vnt_private));
722 pDevice->dev = netdev;
725 device_set_options(pDevice);
726 spin_lock_init(&pDevice->lock);
728 pDevice->tx_80211 = device_dma0_tx_80211;
729 pDevice->vnt_mgmt.pAdapter = (void *) pDevice;
731 netdev->netdev_ops = &device_netdev_ops;
732 netdev->wireless_handlers =
733 (struct iw_handler_def *) &iwctl_handler_def;
735 usb_set_intfdata(intf, pDevice);
736 SET_NETDEV_DEV(netdev, &intf->dev);
737 memcpy(pDevice->dev->dev_addr, fake_mac, ETH_ALEN);
738 rc = register_netdev(netdev);
740 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
744 usb_device_reset(pDevice);
756 static void device_free_tx_bufs(struct vnt_private *pDevice)
758 PUSB_SEND_CONTEXT pTxContext;
761 for (ii = 0; ii < pDevice->cbTD; ii++) {
763 pTxContext = pDevice->apTD[ii];
764 /* deallocate URBs */
765 if (pTxContext->pUrb) {
766 usb_kill_urb(pTxContext->pUrb);
767 usb_free_urb(pTxContext->pUrb);
775 static void device_free_rx_bufs(struct vnt_private *pDevice)
780 for (ii = 0; ii < pDevice->cbRD; ii++) {
782 pRCB = pDevice->apRCB[ii];
783 /* deallocate URBs */
785 usb_kill_urb(pRCB->pUrb);
786 usb_free_urb(pRCB->pUrb);
790 dev_kfree_skb(pRCB->skb);
792 kfree(pDevice->pRCBMem);
797 static void usb_device_reset(struct vnt_private *pDevice)
800 status = usb_reset_device(pDevice->usb);
802 printk("usb_device_reset fail status=%d\n",status);
806 static void device_free_int_bufs(struct vnt_private *pDevice)
808 kfree(pDevice->intBuf.pDataBuf);
813 static bool device_alloc_bufs(struct vnt_private *pDevice)
816 PUSB_SEND_CONTEXT pTxContext;
821 for (ii = 0; ii < pDevice->cbTD; ii++) {
823 pTxContext = kmalloc(sizeof(USB_SEND_CONTEXT), GFP_KERNEL);
824 if (pTxContext == NULL) {
825 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate tx usb context failed\n", pDevice->dev->name);
828 pDevice->apTD[ii] = pTxContext;
829 pTxContext->pDevice = (void *) pDevice;
831 pTxContext->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
832 if (pTxContext->pUrb == NULL) {
833 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "alloc tx urb failed\n");
836 pTxContext->bBoolInUse = false;
839 /* allocate RCB mem */
840 pDevice->pRCBMem = kzalloc((sizeof(RCB) * pDevice->cbRD), GFP_KERNEL);
841 if (pDevice->pRCBMem == NULL) {
842 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : alloc rx usb context failed\n", pDevice->dev->name);
847 pDevice->FirstRecvFreeList = NULL;
848 pDevice->LastRecvFreeList = NULL;
849 pDevice->FirstRecvMngList = NULL;
850 pDevice->LastRecvMngList = NULL;
851 pDevice->NumRecvFreeList = 0;
852 pRCB = (PRCB) pDevice->pRCBMem;
854 for (ii = 0; ii < pDevice->cbRD; ii++) {
856 pDevice->apRCB[ii] = pRCB;
857 pRCB->pDevice = (void *) pDevice;
859 pRCB->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
861 if (pRCB->pUrb == NULL) {
862 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx urb\n");
865 pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
866 if (pRCB->skb == NULL) {
867 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx skb\n");
870 pRCB->skb->dev = pDevice->dev;
871 pRCB->bBoolInUse = false;
872 EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB);
873 pDevice->NumRecvFreeList++;
878 pDevice->pControlURB = usb_alloc_urb(0, GFP_ATOMIC);
879 if (pDevice->pControlURB == NULL) {
880 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc control urb\n");
884 pDevice->pInterruptURB = usb_alloc_urb(0, GFP_ATOMIC);
885 if (pDevice->pInterruptURB == NULL) {
886 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int urb\n");
887 usb_free_urb(pDevice->pControlURB);
891 pDevice->intBuf.pDataBuf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
892 if (pDevice->intBuf.pDataBuf == NULL) {
893 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int buf\n");
894 usb_free_urb(pDevice->pControlURB);
895 usb_free_urb(pDevice->pInterruptURB);
902 device_free_rx_bufs(pDevice);
905 device_free_tx_bufs(pDevice);
913 static bool device_init_defrag_cb(struct vnt_private *pDevice)
916 PSDeFragControlBlock pDeF;
918 /* Init the fragment ctl entries */
919 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
920 pDeF = &(pDevice->sRxDFCB[i]);
921 if (!device_alloc_frag_buf(pDevice, pDeF)) {
922 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
927 pDevice->cbDFCB = CB_MAX_RX_FRAG;
928 pDevice->cbFreeDFCB = pDevice->cbDFCB;
932 device_free_frag_bufs(pDevice);
938 static void device_free_frag_bufs(struct vnt_private *pDevice)
940 PSDeFragControlBlock pDeF;
943 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
945 pDeF = &(pDevice->sRxDFCB[i]);
948 dev_kfree_skb(pDeF->skb);
954 int device_alloc_frag_buf(struct vnt_private *pDevice,
955 PSDeFragControlBlock pDeF)
958 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
959 if (pDeF->skb == NULL)
962 pDeF->skb->dev = pDevice->dev;
968 /*-----------------------------------------------------------------*/
970 static int device_open(struct net_device *dev)
972 struct vnt_private *pDevice = netdev_priv(dev);
974 pDevice->fWPA_Authened = false;
976 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");
979 pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
981 if (device_alloc_bufs(pDevice) == false) {
982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n");
986 if (device_init_defrag_cb(pDevice)== false) {
987 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n");
991 MP_CLEAR_FLAG(pDevice, fMP_DISCONNECTED);
992 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
993 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
994 MP_SET_FLAG(pDevice, fMP_POST_READS);
995 MP_SET_FLAG(pDevice, fMP_POST_WRITES);
997 /* read config file */
998 Read_config_file(pDevice);
1000 if (device_init_registers(pDevice, DEVICE_INIT_COLD) == false) {
1001 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n");
1005 device_set_multi(pDevice->dev);
1007 /* init for key management */
1008 KeyvInitTable(pDevice,&pDevice->sKey);
1009 memcpy(pDevice->vnt_mgmt.abyMACAddr,
1010 pDevice->abyCurrentNetAddr, ETH_ALEN);
1011 memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN);
1012 pDevice->bStopTx0Pkt = false;
1013 pDevice->bStopDataPkt = false;
1014 pDevice->bRoaming = false;
1015 pDevice->bIsRoaming = false;
1016 pDevice->bEnableRoaming = false;
1017 if (pDevice->bDiversityRegCtlON) {
1018 device_init_diversity_timer(pDevice);
1021 vMgrObjectInit(pDevice);
1022 tasklet_init(&pDevice->RxMngWorkItem, (void *)RXvMngWorkItem, (unsigned long)pDevice);
1023 tasklet_init(&pDevice->ReadWorkItem, (void *)RXvWorkItem, (unsigned long)pDevice);
1024 tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice);
1025 add_timer(&pDevice->vnt_mgmt.sTimerSecondCallback);
1026 pDevice->int_interval = 100; /* max 100 microframes */
1027 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1029 pDevice->bIsRxWorkItemQueued = true;
1030 pDevice->fKillEventPollingThread = false;
1031 pDevice->bEventAvailable = false;
1033 pDevice->bWPADEVUp = false;
1034 pDevice->bwextstep0 = false;
1035 pDevice->bwextstep1 = false;
1036 pDevice->bwextstep2 = false;
1037 pDevice->bwextstep3 = false;
1038 pDevice->bWPASuppWextEnabled = false;
1039 pDevice->byReAssocCount = 0;
1041 RXvWorkItem(pDevice);
1042 INTvWorkItem(pDevice);
1044 /* if WEP key already set by iwconfig but device not yet open */
1045 if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) {
1046 spin_lock_irq(&pDevice->lock);
1047 KeybSetDefaultKey( pDevice,
1049 pDevice->byKeyIndex | (1 << 31),
1050 pDevice->uKeyLength,
1055 spin_unlock_irq(&pDevice->lock);
1056 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1059 if (pDevice->vnt_mgmt.eConfigMode == WMAC_CONFIG_AP)
1060 bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL);
1062 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1065 netif_stop_queue(pDevice->dev);
1066 pDevice->flags |= DEVICE_FLAGS_OPENED;
1068 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success..\n");
1072 device_free_frag_bufs(pDevice);
1074 device_free_rx_bufs(pDevice);
1075 device_free_tx_bufs(pDevice);
1076 device_free_int_bufs(pDevice);
1077 usb_kill_urb(pDevice->pControlURB);
1078 usb_kill_urb(pDevice->pInterruptURB);
1079 usb_free_urb(pDevice->pControlURB);
1080 usb_free_urb(pDevice->pInterruptURB);
1082 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open fail.. \n");
1088 static int device_close(struct net_device *dev)
1090 struct vnt_private *pDevice = netdev_priv(dev);
1091 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1094 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1\n");
1095 if (pDevice == NULL)
1098 if (pDevice->bLinkPass) {
1099 bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1104 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1105 pMgmt->bShareKeyAlgorithm = false;
1106 pDevice->bEncryptionEnable = false;
1107 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1108 spin_lock_irq(&pDevice->lock);
1109 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1110 MACvDisableKeyEntry(pDevice,uu);
1111 spin_unlock_irq(&pDevice->lock);
1113 if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == false) {
1114 MACbShutdown(pDevice);
1116 netif_stop_queue(pDevice->dev);
1117 MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
1118 MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES);
1119 MP_CLEAR_FLAG(pDevice, fMP_POST_READS);
1120 pDevice->fKillEventPollingThread = true;
1121 del_timer(&pDevice->sTimerCommand);
1122 del_timer(&pMgmt->sTimerSecondCallback);
1124 del_timer(&pDevice->sTimerTxData);
1126 if (pDevice->bDiversityRegCtlON) {
1127 del_timer(&pDevice->TimerSQ3Tmax1);
1128 del_timer(&pDevice->TimerSQ3Tmax2);
1129 del_timer(&pDevice->TimerSQ3Tmax3);
1131 tasklet_kill(&pDevice->RxMngWorkItem);
1132 tasklet_kill(&pDevice->ReadWorkItem);
1133 tasklet_kill(&pDevice->EventWorkItem);
1135 pDevice->bRoaming = false;
1136 pDevice->bIsRoaming = false;
1137 pDevice->bEnableRoaming = false;
1138 pDevice->bCmdRunning = false;
1139 pDevice->bLinkPass = false;
1140 memset(pMgmt->abyCurrBSSID, 0, 6);
1141 pMgmt->eCurrState = WMAC_STATE_IDLE;
1143 device_free_tx_bufs(pDevice);
1144 device_free_rx_bufs(pDevice);
1145 device_free_int_bufs(pDevice);
1146 device_free_frag_bufs(pDevice);
1148 usb_kill_urb(pDevice->pControlURB);
1149 usb_kill_urb(pDevice->pInterruptURB);
1150 usb_free_urb(pDevice->pControlURB);
1151 usb_free_urb(pDevice->pInterruptURB);
1153 BSSvClearNodeDBTable(pDevice, 0);
1154 pDevice->flags &=(~DEVICE_FLAGS_OPENED);
1156 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n");
1161 static void vt6656_disconnect(struct usb_interface *intf)
1163 struct vnt_private *device = usb_get_intfdata(intf);
1169 usb_set_intfdata(intf, NULL);
1170 usb_put_dev(interface_to_usbdev(intf));
1172 device->flags |= DEVICE_FLAGS_UNPLUG;
1175 unregister_netdev(device->dev);
1176 free_netdev(device->dev);
1181 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1183 struct vnt_private *pDevice = netdev_priv(dev);
1185 spin_lock_irq(&pDevice->lock);
1187 if (unlikely(pDevice->bStopTx0Pkt))
1188 dev_kfree_skb_irq(skb);
1190 vDMA0_tx_80211(pDevice, skb);
1192 spin_unlock_irq(&pDevice->lock);
1194 return NETDEV_TX_OK;
1197 static int device_xmit(struct sk_buff *skb, struct net_device *dev)
1199 struct vnt_private *pDevice = netdev_priv(dev);
1200 struct net_device_stats *stats = &pDevice->stats;
1202 spin_lock_irq(&pDevice->lock);
1204 netif_stop_queue(dev);
1206 if (!pDevice->bLinkPass) {
1207 dev_kfree_skb_irq(skb);
1211 if (pDevice->bStopDataPkt) {
1212 dev_kfree_skb_irq(skb);
1213 stats->tx_dropped++;
1217 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb)) {
1218 if (netif_queue_stopped(dev))
1219 netif_wake_queue(dev);
1223 spin_unlock_irq(&pDevice->lock);
1225 return NETDEV_TX_OK;
1228 static unsigned const ethernet_polynomial = 0x04c11db7U;
1229 static inline u32 ether_crc(int length, unsigned char *data)
1233 while(--length >= 0) {
1234 unsigned char current_octet = *data++;
1236 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
1238 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
1244 /* find out the start position of str2 from str1 */
1245 static unsigned char *kstrstr(const unsigned char *str1,
1246 const unsigned char *str2) {
1247 int str1_len = strlen(str1);
1248 int str2_len = strlen(str2);
1250 while (str1_len >= str2_len) {
1252 if(memcmp(str1,str2,str2_len)==0)
1253 return (unsigned char *) str1;
1259 static int Config_FileGetParameter(unsigned char *string,
1260 unsigned char *dest,
1261 unsigned char *source)
1263 unsigned char buf1[100];
1264 unsigned char buf2[100];
1265 unsigned char *start_p = NULL, *end_p = NULL, *tmp_p = NULL;
1269 strcat(buf1, string);
1271 source+=strlen(buf1);
1273 /* find target string start point */
1274 start_p = kstrstr(source,buf1);
1275 if (start_p == NULL)
1278 /* check if current config line is marked by "#" */
1279 for (ii = 1; ; ii++) {
1280 if (memcmp(start_p - ii, "\n", 1) == 0)
1282 if (memcmp(start_p - ii, "#", 1) == 0)
1286 /* find target string end point */
1287 end_p = kstrstr(start_p,"\n");
1288 if (end_p == NULL) { /* can't find "\n", but don't care */
1289 end_p = start_p + strlen(start_p); /* no include "\n" */
1293 memcpy(buf2, start_p, end_p-start_p); /* get the target line */
1294 buf2[end_p-start_p]='\0';
1297 start_p = kstrstr(buf2,"=");
1298 if (start_p == NULL)
1301 strcpy(buf1,start_p+1);
1305 while(*tmp_p != 0x00) {
1312 memcpy(dest,tmp_p,strlen(tmp_p));
1316 /* if read fails, return NULL, or return data pointer */
1317 static unsigned char *Config_FileOperation(struct vnt_private *pDevice)
1319 unsigned char *config_path = CONFIG_PATH;
1320 unsigned char *buffer = NULL;
1321 struct file *filp=NULL;
1322 mm_segment_t old_fs = get_fs();
1329 filp = filp_open(config_path, O_RDWR, 0);
1331 printk("Config_FileOperation file Not exist\n");
1336 if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
1337 printk("file %s is not read or writeable?\n",config_path);
1342 buffer = kmalloc(1024, GFP_KERNEL);
1344 printk("allocate mem for file fail?\n");
1349 if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
1350 printk("read file error?\n");
1355 if(filp_close(filp,NULL))
1356 printk("Config_FileOperation:close file fail\n");
1368 /* return --->-1:fail; >=0:successful */
1369 static int Read_config_file(struct vnt_private *pDevice)
1372 unsigned char tmpbuffer[100];
1373 unsigned char *buffer = NULL;
1375 /* init config setting */
1376 pDevice->config_file.ZoneType = -1;
1377 pDevice->config_file.eAuthenMode = -1;
1378 pDevice->config_file.eEncryptionStatus = -1;
1380 buffer = Config_FileOperation(pDevice);
1381 if (buffer == NULL) {
1388 memset(tmpbuffer,0,sizeof(tmpbuffer));
1389 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==true) {
1390 if(memcmp(tmpbuffer,"USA",3)==0) {
1391 pDevice->config_file.ZoneType=ZoneType_USA;
1393 else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
1394 pDevice->config_file.ZoneType=ZoneType_Japan;
1396 else if(memcmp(tmpbuffer,"EUROPE",6)==0) {
1397 pDevice->config_file.ZoneType=ZoneType_Europe;
1400 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
1405 /* get other parameter */
1407 memset(tmpbuffer,0,sizeof(tmpbuffer));
1408 if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==true) {
1409 pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10);
1412 memset(tmpbuffer,0,sizeof(tmpbuffer));
1413 if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==true) {
1414 pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10);
1422 static void device_set_multi(struct net_device *dev)
1424 struct vnt_private *pDevice = netdev_priv(dev);
1425 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1426 struct netdev_hw_addr *ha;
1429 u8 pbyData[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1434 spin_lock_irq(&pDevice->lock);
1435 rc = CONTROLnsRequestIn(pDevice,
1438 MESSAGE_REQUEST_MACREG,
1442 if (rc == 0) pDevice->byRxMode = byTmpMode;
1444 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode in= %x\n", pDevice->byRxMode);
1446 if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
1447 DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
1448 /* unconditionally log net taps */
1449 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
1451 else if ((netdev_mc_count(dev) > pDevice->multicast_limit) ||
1452 (dev->flags & IFF_ALLMULTI)) {
1453 CONTROLnsRequestOut(pDevice,
1456 MESSAGE_REQUEST_MACREG,
1460 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1463 memset(mc_filter, 0, sizeof(mc_filter));
1464 netdev_for_each_mc_addr(ha, dev) {
1465 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1466 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
1468 for (ii = 0; ii < 4; ii++) {
1469 MACvWriteMultiAddr(pDevice, ii, *((PBYTE)&mc_filter[0] + ii));
1470 MACvWriteMultiAddr(pDevice, ii+ 4, *((PBYTE)&mc_filter[1] + ii));
1472 pDevice->byRxMode &= ~(RCR_UNICAST);
1473 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1476 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1478 * If AP mode, don't enable RCR_UNICAST since HW only compares
1479 * addr1 with local MAC
1481 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1482 pDevice->byRxMode &= ~(RCR_UNICAST);
1484 ControlvWriteByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, pDevice->byRxMode);
1485 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode out= %x\n", pDevice->byRxMode);
1486 spin_unlock_irq(&pDevice->lock);
1490 static struct net_device_stats *device_get_stats(struct net_device *dev)
1492 struct vnt_private *pDevice = netdev_priv(dev);
1494 return &pDevice->stats;
1497 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1499 struct vnt_private *pDevice = netdev_priv(dev);
1500 struct iwreq *wrq = (struct iwreq *) rq;
1505 case IOCTL_CMD_HOSTAPD:
1507 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
1510 rc = vt6656_hostap_ioctl(pDevice, &wrq->u.data);
1514 return ethtool_ioctl(dev, (void *) rq->ifr_data);
1522 static int ethtool_ioctl(struct net_device *dev, void *useraddr)
1526 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
1530 case ETHTOOL_GDRVINFO: {
1531 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
1532 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
1533 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
1534 if (copy_to_user(useraddr, &info, sizeof(info)))
1544 MODULE_DEVICE_TABLE(usb, vt6656_table);
1546 static struct usb_driver vt6656_driver = {
1547 .name = DEVICE_NAME,
1548 .probe = vt6656_probe,
1549 .disconnect = vt6656_disconnect,
1550 .id_table = vt6656_table,
1552 .suspend = vt6656_suspend,
1553 .resume = vt6656_resume,
1554 #endif /* CONFIG_PM */
1557 module_usb_driver(vt6656_driver);