1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47#undef __NO_VERSION__
48
49#include "device.h"
50#include "card.h"
51#include "baseband.h"
52#include "mac.h"
53#include "tether.h"
54#include "wmgr.h"
55#include "wctl.h"
56#include "power.h"
57#include "wcmd.h"
58#include "iocmd.h"
59#include "tcrc.h"
60#include "rxtx.h"
61#include "bssdb.h"
62#include "hostap.h"
63#include "wpactl.h"
64#include "ioctl.h"
65#include "iwctl.h"
66#include "dpc.h"
67#include "iocmd.h"
68#include "datarate.h"
69#include "rf.h"
70#include "firmware.h"
71#include "mac.h"
72#include "rndis.h"
73#include "control.h"
74#include "channel.h"
75#include "int.h"
76#include "iowpa.h"
77
78
79
80static int msglevel =MSG_LEVEL_INFO;
81
82
83
84
85
86
87#define DRIVER_AUTHOR "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
88MODULE_AUTHOR(DRIVER_AUTHOR);
89MODULE_LICENSE("GPL");
90MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
91
92#define DEVICE_PARAM(N,D) \
93 static int N[MAX_UINTS]=OPTION_DEFAULT;\
94 module_param_array(N, int, NULL, 0);\
95 MODULE_PARM_DESC(N, D);
96
97#define RX_DESC_MIN0 16
98#define RX_DESC_MAX0 128
99#define RX_DESC_DEF0 64
100DEVICE_PARAM(RxDescriptors0,"Number of receive usb desc buffer");
101
102
103#define TX_DESC_MIN0 16
104#define TX_DESC_MAX0 128
105#define TX_DESC_DEF0 64
106DEVICE_PARAM(TxDescriptors0,"Number of transmit usb desc buffer");
107
108
109#define CHANNEL_MIN 1
110#define CHANNEL_MAX 14
111#define CHANNEL_DEF 6
112
113DEVICE_PARAM(Channel, "Channel number");
114
115
116
117
118
119
120
121#define PREAMBLE_TYPE_DEF 1
122
123DEVICE_PARAM(PreambleType, "Preamble Type");
124
125
126#define RTS_THRESH_MIN 512
127#define RTS_THRESH_MAX 2347
128#define RTS_THRESH_DEF 2347
129
130DEVICE_PARAM(RTSThreshold, "RTS threshold");
131
132
133#define FRAG_THRESH_MIN 256
134#define FRAG_THRESH_MAX 2346
135#define FRAG_THRESH_DEF 2346
136
137DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
138
139
140#define DATA_RATE_MIN 0
141#define DATA_RATE_MAX 13
142#define DATA_RATE_DEF 13
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160DEVICE_PARAM(ConnectionRate, "Connection data rate");
161
162#define OP_MODE_MAX 2
163#define OP_MODE_DEF 0
164#define OP_MODE_MIN 0
165
166DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
167
168
169
170
171
172
173
174
175
176
177
178
179
180#define PS_MODE_DEF 0
181
182DEVICE_PARAM(PSMode, "Power saving mode");
183
184
185#define SHORT_RETRY_MIN 0
186#define SHORT_RETRY_MAX 31
187#define SHORT_RETRY_DEF 8
188
189
190DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
191
192#define LONG_RETRY_MIN 0
193#define LONG_RETRY_MAX 15
194#define LONG_RETRY_DEF 4
195
196
197DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
198
199
200
201
202
203
204
205#define BBP_TYPE_MIN 0
206#define BBP_TYPE_MAX 2
207#define BBP_TYPE_DEF 2
208
209DEVICE_PARAM(BasebandType, "baseband type");
210
211
212
213
214
215
216
217
218#define X80211h_MODE_DEF 0
219
220DEVICE_PARAM(b80211hEnable, "802.11h mode");
221
222
223
224
225
226
227
228
229static struct usb_device_id vntwusb_table[] = {
230 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
231 {}
232};
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258static int vntwusb_found1(struct usb_interface *intf, const struct usb_device_id *id);
259static void vntwusb_disconnect(struct usb_interface *intf);
260#ifdef CONFIG_PM
261static int vntwusb_suspend(struct usb_interface *intf, pm_message_t message);
262static int vntwusb_resume(struct usb_interface *intf);
263#endif
264static struct net_device_stats *device_get_stats(struct net_device *dev);
265static int device_open(struct net_device *dev);
266static int device_xmit(struct sk_buff *skb, struct net_device *dev);
267static void device_set_multi(struct net_device *dev);
268static int device_close(struct net_device *dev);
269static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
270
271static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
272static BOOL device_init_defrag_cb(PSDevice pDevice);
273static void device_init_diversity_timer(PSDevice pDevice);
274static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
275
276static int ethtool_ioctl(struct net_device *dev, void *useraddr);
277static void device_free_tx_bufs(PSDevice pDevice);
278static void device_free_rx_bufs(PSDevice pDevice);
279static void device_free_int_bufs(PSDevice pDevice);
280static void device_free_frag_bufs(PSDevice pDevice);
281static BOOL device_alloc_bufs(PSDevice pDevice);
282
283static int Read_config_file(PSDevice pDevice);
284static UCHAR *Config_FileOperation(PSDevice pDevice);
285static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source);
286
287
288static BOOL device_release_WPADEV(PSDevice pDevice);
289
290static void usb_device_reset(PSDevice pDevice);
291
292
293
294
295
296
297
298
299static void
300device_set_options(PSDevice pDevice) {
301
302 BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
303 BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
304 BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
305
306
307 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);
308 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);
309 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);
310
311 pDevice->cbTD = TX_DESC_DEF0;
312 pDevice->cbRD = RX_DESC_DEF0;
313 pDevice->uChannel = CHANNEL_DEF;
314 pDevice->wRTSThreshold = RTS_THRESH_DEF;
315 pDevice->wFragmentationThreshold = FRAG_THRESH_DEF;
316 pDevice->byShortRetryLimit = SHORT_RETRY_DEF;
317 pDevice->byLongRetryLimit = LONG_RETRY_DEF;
318 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
319 pDevice->byShortPreamble = PREAMBLE_TYPE_DEF;
320 pDevice->ePSMode = PS_MODE_DEF;
321 pDevice->b11hEnable = X80211h_MODE_DEF;
322 pDevice->eOPMode = OP_MODE_DEF;
323 pDevice->uConnectionRate = DATA_RATE_DEF;
324 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;
325 pDevice->byBBType = BBP_TYPE_DEF;
326 pDevice->byPacketType = pDevice->byBBType;
327 pDevice->byAutoFBCtrl = AUTO_FB_0;
328 pDevice->bUpdateBBVGA = TRUE;
329 pDevice->byFOETuning = 0;
330 pDevice->byAutoPwrTunning = 0;
331 pDevice->wCTSDuration = 0;
332 pDevice->byPreambleType = 0;
333 pDevice->bExistSWNetAddr = FALSE;
334
335 pDevice->bDiversityRegCtlON = FALSE;
336}
337
338
339static VOID device_init_diversity_timer(PSDevice pDevice) {
340
341 init_timer(&pDevice->TimerSQ3Tmax1);
342 pDevice->TimerSQ3Tmax1.data = (ULONG)pDevice;
343 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
344 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
345
346 init_timer(&pDevice->TimerSQ3Tmax2);
347 pDevice->TimerSQ3Tmax2.data = (ULONG)pDevice;
348 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
349 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
350
351 init_timer(&pDevice->TimerSQ3Tmax3);
352 pDevice->TimerSQ3Tmax3.data = (ULONG)pDevice;
353 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerSQ3Tmax3CallBack;
354 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
355
356 return;
357}
358
359
360
361
362
363
364static BOOL device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
365{
366 BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
367 BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
368 BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
369 BYTE byAntenna;
370 UINT ii;
371 CMD_CARD_INIT sInitCmd;
372 NTSTATUS ntStatus = STATUS_SUCCESS;
373 RSP_CARD_INIT sInitRsp;
374 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
375 BYTE byTmp;
376 BYTE byCalibTXIQ = 0;
377 BYTE byCalibTXDC = 0;
378 BYTE byCalibRXIQ = 0;
379
380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n", InitType, pDevice->byPacketType);
381 spin_lock_irq(&pDevice->lock);
382 if (InitType == DEVICE_INIT_COLD) {
383 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);
384 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);
385 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);
386
387 if ( !FIRMWAREbCheckVersion(pDevice) ) {
388 if (FIRMWAREbDownload(pDevice) == TRUE) {
389 if (FIRMWAREbBrach2Sram(pDevice) == FALSE) {
390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbBrach2Sram fail \n");
391 spin_unlock_irq(&pDevice->lock);
392 return FALSE;
393 }
394 } else {
395
396 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbDownload fail \n");
397 spin_unlock_irq(&pDevice->lock);
398 return FALSE;
399 }
400 }
401
402 if ( !BBbVT3184Init(pDevice) ) {
403 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail \n");
404 spin_unlock_irq(&pDevice->lock);
405 return FALSE;
406 }
407 }
408
409 sInitCmd.byInitClass = (BYTE)InitType;
410 sInitCmd.bExistSWNetAddr = (BYTE) pDevice->bExistSWNetAddr;
411 for(ii=0;ii<6;ii++)
412 sInitCmd.bySWNetAddr[ii] = pDevice->abyCurrentNetAddr[ii];
413 sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit;
414 sInitCmd.byLongRetryLimit = pDevice->byLongRetryLimit;
415
416
417 ntStatus = CONTROLnsRequestOut(pDevice,
418 MESSAGE_TYPE_CARDINIT,
419 0,
420 0,
421 sizeof(CMD_CARD_INIT),
422 (PBYTE) &(sInitCmd));
423
424 if ( ntStatus != STATUS_SUCCESS ) {
425 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail \n");
426 spin_unlock_irq(&pDevice->lock);
427 return FALSE;
428 }
429 if (InitType == DEVICE_INIT_COLD) {
430
431 ntStatus = CONTROLnsRequestIn(pDevice,MESSAGE_TYPE_INIT_RSP,0,0,sizeof(RSP_CARD_INIT), (PBYTE) &(sInitRsp));
432
433 if (ntStatus != STATUS_SUCCESS) {
434 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Cardinit request in status fail!\n");
435 spin_unlock_irq(&pDevice->lock);
436 return FALSE;
437 }
438
439
440 ntStatus = CONTROLnsRequestIn(pDevice,
441 MESSAGE_TYPE_READ,
442 MAC_REG_LOCALID,
443 MESSAGE_REQUEST_MACREG,
444 1,
445 &pDevice->byLocalID);
446
447 if ( ntStatus != STATUS_SUCCESS ) {
448 spin_unlock_irq(&pDevice->lock);
449 return FALSE;
450 }
451
452
453
454 pDevice->bCCK = TRUE;
455 pDevice->bProtectMode = FALSE;
456 pDevice->bNonERPPresent = FALSE;
457 pDevice->bBarkerPreambleMd = FALSE;
458 if ( pDevice->bFixRate ) {
459 pDevice->wCurrentRate = (WORD) pDevice->uConnectionRate;
460 } else {
461 if ( pDevice->byBBType == BB_TYPE_11B )
462 pDevice->wCurrentRate = RATE_11M;
463 else
464 pDevice->wCurrentRate = RATE_54M;
465 }
466
467 CHvInitChannelTable(pDevice);
468
469 pDevice->byTopOFDMBasicRate = RATE_24M;
470 pDevice->byTopCCKBasicRate = RATE_1M;
471 pDevice->byRevId = 0;
472 pDevice->byCurPwr = 0xFF;
473
474 pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK];
475 pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG];
476
477 for (ii=0;ii<14;ii++) {
478 pDevice->abyCCKPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_CCK_PWR_TBL];
479 if (pDevice->abyCCKPwrTbl[ii] == 0)
480 pDevice->abyCCKPwrTbl[ii] = pDevice->byCCKPwr;
481 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDM_PWR_TBL];
482 if (pDevice->abyOFDMPwrTbl[ii] == 0)
483 pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG;
484 }
485
486
487
488 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
489 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
490 (pDevice->byOriginalZonetype == ZoneType_USA)) {
491 for(ii=11;ii<14;ii++) {
492 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
493 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
494 }
495 }
496
497
498 pDevice->byOFDMPwrA = 0x34;
499
500 for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) {
501 pDevice->abyOFDMAPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDMA_PWR_TBL];
502 if (pDevice->abyOFDMAPwrTbl[ii] == 0)
503 pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA;
504 }
505
506
507 byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA];
508 if (byAntenna & EEP_ANTINV)
509 pDevice->bTxRxAntInv = TRUE;
510 else
511 pDevice->bTxRxAntInv = FALSE;
512
513 byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
514
515 if (byAntenna == 0)
516 byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
517
518 if (byAntenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
519 pDevice->byAntennaCount = 2;
520 pDevice->byTxAntennaMode = ANT_B;
521 pDevice->dwTxAntennaSel = 1;
522 pDevice->dwRxAntennaSel = 1;
523 if (pDevice->bTxRxAntInv == TRUE)
524 pDevice->byRxAntennaMode = ANT_A;
525 else
526 pDevice->byRxAntennaMode = ANT_B;
527
528 if (pDevice->bDiversityRegCtlON)
529 pDevice->bDiversityEnable = TRUE;
530 else
531 pDevice->bDiversityEnable = FALSE;
532 } else {
533 pDevice->bDiversityEnable = FALSE;
534 pDevice->byAntennaCount = 1;
535 pDevice->dwTxAntennaSel = 0;
536 pDevice->dwRxAntennaSel = 0;
537 if (byAntenna & EEP_ANTENNA_AUX) {
538 pDevice->byTxAntennaMode = ANT_A;
539 if (pDevice->bTxRxAntInv == TRUE)
540 pDevice->byRxAntennaMode = ANT_B;
541 else
542 pDevice->byRxAntennaMode = ANT_A;
543 } else {
544 pDevice->byTxAntennaMode = ANT_B;
545 if (pDevice->bTxRxAntInv == TRUE)
546 pDevice->byRxAntennaMode = ANT_A;
547 else
548 pDevice->byRxAntennaMode = ANT_B;
549 }
550 }
551 pDevice->ulDiversityNValue = 100*255;
552 pDevice->ulDiversityMValue = 100*16;
553 pDevice->byTMax = 1;
554 pDevice->byTMax2 = 4;
555 pDevice->ulSQ3TH = 0;
556 pDevice->byTMax3 = 64;
557
558
559
560 pDevice->byAutoFBCtrl = AUTO_FB_0;
561
562
563 pDevice->uScanTime = WLAN_SCAN_MINITIME;
564
565
566
567 pDevice->eConfigPHYMode = PHY_TYPE_AUTO;
568 pDevice->byBBType = BB_TYPE_11G;
569
570
571 pDevice->ulTxPower = 25;
572
573
574 pDevice->byMinChannel = 1;
575 pDevice->byMaxChannel = CB_MAX_CHANNEL;
576
577
578 pDevice->byRFType = sInitRsp.byRFType;
579
580 if ((pDevice->byRFType & RF_EMU) != 0) {
581
582 pDevice->byRevId = 0x80;
583 }
584
585
586 if (pDevice->byRFType == RF_VT3226D0) {
587 if((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) &&
588 (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) {
589 byCalibTXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_IQ];
590 byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC];
591 byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ];
592 if( (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) ) {
593 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFF, 0x03);
594 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFB, byCalibTXIQ);
595 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFC, byCalibTXDC);
596 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFD, byCalibRXIQ);
597 } else {
598
599 ControlvWriteByte(pDevice, MESSAGE_REQUEST_BBREG, 0xFF, 0x0);
600 }
601 }
602 }
603 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
604 pMgmt->uCurrChannel = pDevice->uChannel;
605 pMgmt->uIBSSChannel = pDevice->uChannel;
606 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
607
608
609 memcpy(pDevice->abyPermanentNetAddr,&(sInitRsp.byNetAddr[0]),6);
610 memcpy(pDevice->abyCurrentNetAddr, pDevice->abyPermanentNetAddr, U_ETHER_ADDR_LEN);
611
612
613
614 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",
615 pDevice->abyCurrentNetAddr[0],
616 pDevice->abyCurrentNetAddr[1],
617 pDevice->abyCurrentNetAddr[2],
618 pDevice->abyCurrentNetAddr[3],
619 pDevice->abyCurrentNetAddr[4],
620 pDevice->abyCurrentNetAddr[5]);
621 }
622
623
624
625
626
627 if (pDevice->byBBType == BB_TYPE_11A) {
628 CARDbAddBasicRate(pDevice, RATE_6M);
629 pDevice->bShortSlotTime = TRUE;
630 } else {
631 CARDbAddBasicRate(pDevice, RATE_1M);
632 pDevice->bShortSlotTime = FALSE;
633 }
634 BBvSetShortSlotTime(pDevice);
635 CARDvSetBSSMode(pDevice);
636
637 if (pDevice->bUpdateBBVGA) {
638 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
639 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
640 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
641 }
642
643 pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL];
644 pDevice->bHWRadioOff = FALSE;
645 if ( (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0 ) {
646 ntStatus = CONTROLnsRequestIn(pDevice,
647 MESSAGE_TYPE_READ,
648 MAC_REG_GPIOCTL1,
649 MESSAGE_REQUEST_MACREG,
650 1,
651 &byTmp);
652
653 if ( ntStatus != STATUS_SUCCESS ) {
654 spin_unlock_irq(&pDevice->lock);
655 return FALSE;
656 }
657 if ( (byTmp & GPIO3_DATA) == 0 ) {
658 pDevice->bHWRadioOff = TRUE;
659 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
660 } else {
661 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
662 pDevice->bHWRadioOff = FALSE;
663 }
664
665 }
666
667 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_TMLEN,0x38);
668 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
669 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL0,0x01);
670
671 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
672 CARDbRadioPowerOff(pDevice);
673 } else {
674 CARDbRadioPowerOn(pDevice);
675 }
676
677 spin_unlock_irq(&pDevice->lock);
678 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n");
679 return TRUE;
680}
681
682static BOOL device_release_WPADEV(PSDevice pDevice)
683{
684 viawget_wpa_header *wpahdr;
685 int ii=0;
686
687
688 if (pDevice->bWPADEVUp==TRUE) {
689 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
690 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
691 wpahdr->resp_ie_len = 0;
692 wpahdr->req_ie_len = 0;
693 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
694 pDevice->skb->dev = pDevice->wpadev;
695 skb_reset_mac_header(pDevice->skb);
696 pDevice->skb->pkt_type = PACKET_HOST;
697 pDevice->skb->protocol = htons(ETH_P_802_2);
698 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
699 netif_rx(pDevice->skb);
700 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
701
702
703
704
705 while(pDevice->bWPADEVUp==TRUE) {
706 set_current_state(TASK_UNINTERRUPTIBLE);
707 schedule_timeout (HZ/20);
708 ii++;
709 if(ii>20)
710 break;
711 }
712 };
713 return TRUE;
714}
715
716#ifdef CONFIG_PM
717static int vntwusb_suspend(struct usb_interface *intf, pm_message_t message)
718{
719 PSDevice pDevice = usb_get_intfdata(intf);
720 struct net_device *dev = pDevice->dev;
721
722 printk("VNTWUSB Suspend Start======>\n");
723if(dev != NULL) {
724 if(pDevice->flags & DEVICE_FLAGS_OPENED)
725 device_close(dev);
726}
727
728 usb_put_dev(interface_to_usbdev(intf));
729 return 0;
730}
731
732static int vntwusb_resume(struct usb_interface *intf)
733{
734 PSDevice pDevice = usb_get_intfdata(intf);
735 struct net_device *dev = pDevice->dev;
736
737 printk("VNTWUSB Resume Start======>\n");
738 if(dev != NULL) {
739 usb_get_dev(interface_to_usbdev(intf));
740 if(!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
741 if(device_open(dev)!=0)
742 printk("VNTWUSB Resume Start======>open fail\n");
743 }
744 }
745 return 0;
746}
747#endif
748
749
750static const struct net_device_ops device_netdev_ops = {
751 .ndo_open = device_open,
752 .ndo_stop = device_close,
753 .ndo_do_ioctl = device_ioctl,
754 .ndo_get_stats = device_get_stats,
755 .ndo_start_xmit = device_xmit,
756 .ndo_set_multicast_list = device_set_multi,
757};
758
759
760static int
761vntwusb_found1(struct usb_interface *intf, const struct usb_device_id *id)
762{
763 BYTE fake_mac[U_ETHER_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
764 struct usb_device *udev = interface_to_usbdev(intf);
765 int rc = 0;
766 struct net_device *netdev = NULL;
767 PSDevice pDevice = NULL;
768
769
770 printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
771 printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
772
773 udev = usb_get_dev(udev);
774
775 netdev = alloc_etherdev(sizeof(DEVICE_INFO));
776
777 if (netdev == NULL) {
778 printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
779 kfree(pDevice);
780 goto err_nomem;
781 }
782
783 pDevice = netdev_priv(netdev);
784 memset(pDevice, 0, sizeof(DEVICE_INFO));
785
786 pDevice->dev = netdev;
787 pDevice->usb = udev;
788
789
790 device_set_options(pDevice);
791 spin_lock_init(&pDevice->lock);
792
793 pDevice->tx_80211 = device_dma0_tx_80211;
794 pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
795
796 netdev->netdev_ops = &device_netdev_ops;
797
798 netdev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
799
800
801
802 usb_set_intfdata(intf, pDevice);
803 SET_NETDEV_DEV(netdev, &intf->dev);
804 memcpy(pDevice->dev->dev_addr, fake_mac, U_ETHER_ADDR_LEN);
805 rc = register_netdev(netdev);
806 if (rc != 0) {
807 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
808 free_netdev(netdev);
809 kfree(pDevice);
810 return -ENODEV;
811 }
812
813
814
815
816
817
818
819
820
821#if 0
822 if(wpa_set_wpadev(pDevice, 1)!=0) {
823 printk("Fail to Register WPADEV?\n");
824 unregister_netdev(pDevice->dev);
825 free_netdev(netdev);
826 kfree(pDevice);
827 }
828#endif
829 usb_device_reset(pDevice);
830
831#ifdef SndEvt_ToAPI
832{
833 union iwreq_data wrqu;
834 memset(&wrqu, 0, sizeof(wrqu));
835 wrqu.data.flags = RT_INSMOD_EVENT_FLAG;
836 wrqu.data.length =IFNAMSIZ;
837 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, pDevice->dev->name);
838}
839#endif
840
841 return 0;
842
843
844err_nomem:
845
846 usb_put_dev(udev);
847
848 return -ENOMEM;
849}
850
851
852static VOID device_free_tx_bufs(PSDevice pDevice) {
853 PUSB_SEND_CONTEXT pTxContext;
854 int ii;
855
856 for (ii = 0; ii < pDevice->cbTD; ii++) {
857
858 pTxContext = pDevice->apTD[ii];
859
860 if (pTxContext->pUrb) {
861 usb_kill_urb(pTxContext->pUrb);
862 usb_free_urb(pTxContext->pUrb);
863 }
864 if (pTxContext)
865 kfree(pTxContext);
866 }
867 return;
868}
869
870
871static VOID device_free_rx_bufs(PSDevice pDevice) {
872 PRCB pRCB;
873 int ii;
874
875 for (ii = 0; ii < pDevice->cbRD; ii++) {
876
877 pRCB = pDevice->apRCB[ii];
878
879 if (pRCB->pUrb) {
880 usb_kill_urb(pRCB->pUrb);
881 usb_free_urb(pRCB->pUrb);
882 }
883
884 if (pRCB->skb)
885 dev_kfree_skb(pRCB->skb);
886 }
887 if (pDevice->pRCBMem)
888 kfree(pDevice->pRCBMem);
889
890 return;
891}
892
893
894static void usb_device_reset(PSDevice pDevice)
895{
896 int status;
897 status = usb_reset_device(pDevice->usb);
898 if (status)
899 printk("usb_device_reset fail status=%d\n",status);
900 return ;
901}
902
903static VOID device_free_int_bufs(PSDevice pDevice) {
904
905 if (pDevice->intBuf.pDataBuf != NULL)
906 kfree(pDevice->intBuf.pDataBuf);
907 return;
908}
909
910
911static BOOL device_alloc_bufs(PSDevice pDevice) {
912
913 PUSB_SEND_CONTEXT pTxContext;
914 PRCB pRCB;
915 int ii;
916
917
918 for (ii = 0; ii < pDevice->cbTD; ii++) {
919
920 pTxContext = kmalloc(sizeof(USB_SEND_CONTEXT), GFP_KERNEL);
921 if (pTxContext == NULL) {
922 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate tx usb context failed\n", pDevice->dev->name);
923 goto free_tx;
924 }
925 pDevice->apTD[ii] = pTxContext;
926 pTxContext->pDevice = (PVOID) pDevice;
927
928 pTxContext->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
929 if (pTxContext->pUrb == NULL) {
930 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "alloc tx urb failed\n");
931 goto free_tx;
932 }
933 pTxContext->bBoolInUse = FALSE;
934 }
935
936
937 pDevice->pRCBMem = kmalloc((sizeof(RCB) * pDevice->cbRD), GFP_KERNEL);
938 if (pDevice->pRCBMem == NULL) {
939 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : alloc rx usb context failed\n", pDevice->dev->name);
940 goto free_tx;
941 }
942
943
944 pDevice->FirstRecvFreeList = NULL;
945 pDevice->LastRecvFreeList = NULL;
946 pDevice->FirstRecvMngList = NULL;
947 pDevice->LastRecvMngList = NULL;
948 pDevice->NumRecvFreeList = 0;
949 memset(pDevice->pRCBMem, 0, (sizeof(RCB) * pDevice->cbRD));
950 pRCB = (PRCB) pDevice->pRCBMem;
951
952 for (ii = 0; ii < pDevice->cbRD; ii++) {
953
954 pDevice->apRCB[ii] = pRCB;
955 pRCB->pDevice = (PVOID) pDevice;
956
957 pRCB->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
958
959 if (pRCB->pUrb == NULL) {
960 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx urb\n");
961 goto free_rx_tx;
962 }
963 pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
964 if (pRCB->skb == NULL) {
965 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx skb\n");
966 goto free_rx_tx;
967 }
968 pRCB->skb->dev = pDevice->dev;
969 pRCB->bBoolInUse = FALSE;
970 EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB);
971 pDevice->NumRecvFreeList++;
972 pRCB++;
973 }
974
975
976 pDevice->pControlURB = usb_alloc_urb(0, GFP_ATOMIC);
977 if (pDevice->pControlURB == NULL) {
978 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc control urb\n");
979 goto free_rx_tx;
980 }
981
982 pDevice->pInterruptURB = usb_alloc_urb(0, GFP_ATOMIC);
983 if (pDevice->pInterruptURB == NULL) {
984 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int urb\n");
985 usb_kill_urb(pDevice->pControlURB);
986 usb_free_urb(pDevice->pControlURB);
987 goto free_rx_tx;
988 }
989
990 pDevice->intBuf.pDataBuf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
991 if (pDevice->intBuf.pDataBuf == NULL) {
992 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int buf\n");
993 usb_kill_urb(pDevice->pControlURB);
994 usb_kill_urb(pDevice->pInterruptURB);
995 usb_free_urb(pDevice->pControlURB);
996 usb_free_urb(pDevice->pInterruptURB);
997 goto free_rx_tx;
998 }
999
1000 return TRUE;
1001
1002free_rx_tx:
1003 device_free_rx_bufs(pDevice);
1004
1005free_tx:
1006 device_free_tx_bufs(pDevice);
1007
1008 return FALSE;
1009}
1010
1011
1012
1013
1014static BOOL device_init_defrag_cb(PSDevice pDevice) {
1015 int i;
1016 PSDeFragControlBlock pDeF;
1017
1018
1019 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1020 pDeF = &(pDevice->sRxDFCB[i]);
1021 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1022 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
1023 pDevice->dev->name);
1024 goto free_frag;
1025 };
1026 }
1027 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1028 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1029 return TRUE;
1030
1031free_frag:
1032 device_free_frag_bufs(pDevice);
1033 return FALSE;
1034}
1035
1036
1037
1038static void device_free_frag_bufs(PSDevice pDevice) {
1039 PSDeFragControlBlock pDeF;
1040 int i;
1041
1042 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1043
1044 pDeF = &(pDevice->sRxDFCB[i]);
1045
1046 if (pDeF->skb)
1047 dev_kfree_skb(pDeF->skb);
1048 }
1049}
1050
1051
1052
1053BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
1054
1055 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1056 if (pDeF->skb == NULL)
1057 return FALSE;
1058 ASSERT(pDeF->skb);
1059 pDeF->skb->dev = pDevice->dev;
1060
1061 return TRUE;
1062}
1063
1064
1065
1066
1067static int device_open(struct net_device *dev) {
1068 PSDevice pDevice=(PSDevice) netdev_priv(dev);
1069
1070#ifdef WPA_SM_Transtatus
1071 extern SWPAResult wpa_Result;
1072 memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
1073 wpa_Result.proto = 0;
1074 wpa_Result.key_mgmt = 0;
1075 wpa_Result.eap_type = 0;
1076 wpa_Result.authenticated = FALSE;
1077 pDevice->fWPA_Authened = FALSE;
1078#endif
1079
1080 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");
1081
1082
1083 pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
1084
1085 if (device_alloc_bufs(pDevice) == FALSE) {
1086 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n");
1087 return -ENOMEM;
1088 }
1089
1090 if (device_init_defrag_cb(pDevice)== FALSE) {
1091 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragement cb fail \n");
1092 goto free_rx_tx;
1093 }
1094
1095 MP_CLEAR_FLAG(pDevice, fMP_DISCONNECTED);
1096 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
1097 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
1098 MP_SET_FLAG(pDevice, fMP_POST_READS);
1099 MP_SET_FLAG(pDevice, fMP_POST_WRITES);
1100
1101
1102 Read_config_file(pDevice);
1103
1104 if (device_init_registers(pDevice, DEVICE_INIT_COLD) == FALSE) {
1105 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n");
1106 goto free_all;
1107 }
1108
1109 device_set_multi(pDevice->dev);
1110
1111
1112 KeyvInitTable(pDevice,&pDevice->sKey);
1113 memcpy(pDevice->sMgmtObj.abyMACAddr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN);
1114 memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN);
1115 pDevice->bStopTx0Pkt = FALSE;
1116 pDevice->bStopDataPkt = FALSE;
1117 pDevice->bRoaming = FALSE;
1118 pDevice->bIsRoaming = FALSE;
1119 pDevice->bEnableRoaming = FALSE;
1120 if (pDevice->bDiversityRegCtlON) {
1121 device_init_diversity_timer(pDevice);
1122 }
1123
1124 vMgrObjectInit(pDevice);
1125 tasklet_init(&pDevice->RxMngWorkItem, (void *)RXvMngWorkItem, (unsigned long)pDevice);
1126 tasklet_init(&pDevice->ReadWorkItem, (void *)RXvWorkItem, (unsigned long)pDevice);
1127 tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice);
1128 add_timer(&(pDevice->sMgmtObj.sTimerSecondCallback));
1129 pDevice->int_interval = 100;
1130 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1131
1132 pDevice->bIsRxWorkItemQueued = TRUE;
1133 pDevice->fKillEventPollingThread = FALSE;
1134 pDevice->bEventAvailable = FALSE;
1135
1136 pDevice->bWPADEVUp = FALSE;
1137#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1138 pDevice->bwextstep0 = FALSE;
1139 pDevice->bwextstep1 = FALSE;
1140 pDevice->bwextstep2 = FALSE;
1141 pDevice->bwextstep3 = FALSE;
1142 pDevice->bWPASuppWextEnabled = FALSE;
1143#endif
1144 pDevice->byReAssocCount = 0;
1145
1146 RXvWorkItem(pDevice);
1147 INTvWorkItem(pDevice);
1148
1149
1150 if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) {
1151 spin_lock_irq(&pDevice->lock);
1152 KeybSetDefaultKey( pDevice,
1153 &(pDevice->sKey),
1154 pDevice->byKeyIndex | (1 << 31),
1155 pDevice->uKeyLength,
1156 NULL,
1157 pDevice->abyKey,
1158 KEY_CTL_WEP
1159 );
1160 spin_unlock_irq(&pDevice->lock);
1161 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1162 }
1163
1164 if (pDevice->sMgmtObj.eConfigMode == WMAC_CONFIG_AP) {
1165 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
1166 }
1167 else {
1168
1169 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1170
1171 }
1172
1173
1174 netif_stop_queue(pDevice->dev);
1175 pDevice->flags |= DEVICE_FLAGS_OPENED;
1176
1177#ifdef SndEvt_ToAPI
1178{
1179 union iwreq_data wrqu;
1180 memset(&wrqu, 0, sizeof(wrqu));
1181 wrqu.data.flags = RT_UPDEV_EVENT_FLAG;
1182 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, NULL);
1183}
1184#endif
1185
1186 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
1187 return 0;
1188
1189free_all:
1190 device_free_frag_bufs(pDevice);
1191free_rx_tx:
1192 device_free_rx_bufs(pDevice);
1193 device_free_tx_bufs(pDevice);
1194 device_free_int_bufs(pDevice);
1195 usb_kill_urb(pDevice->pControlURB);
1196 usb_kill_urb(pDevice->pInterruptURB);
1197 usb_free_urb(pDevice->pControlURB);
1198 usb_free_urb(pDevice->pInterruptURB);
1199
1200 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open fail.. \n");
1201 return -ENOMEM;
1202}
1203
1204
1205
1206static int device_close(struct net_device *dev) {
1207 PSDevice pDevice=(PSDevice) netdev_priv(dev);
1208 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1209
1210 int uu;
1211
1212 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1 \n");
1213 if (pDevice == NULL)
1214 return -ENODEV;
1215
1216#ifdef SndEvt_ToAPI
1217{
1218 union iwreq_data wrqu;
1219 memset(&wrqu, 0, sizeof(wrqu));
1220 wrqu.data.flags = RT_DOWNDEV_EVENT_FLAG;
1221 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, NULL);
1222}
1223#endif
1224
1225
1226 if (pDevice->bLinkPass) {
1227 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1228 mdelay(30);
1229 }
1230
1231
1232
1233device_release_WPADEV(pDevice);
1234
1235 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1236 pMgmt->bShareKeyAlgorithm = FALSE;
1237 pDevice->bEncryptionEnable = FALSE;
1238 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1239 spin_lock_irq(&pDevice->lock);
1240 for(uu=0;uu<MAX_KEY_TABLE;uu++)
1241 MACvDisableKeyEntry(pDevice,uu);
1242 spin_unlock_irq(&pDevice->lock);
1243
1244 if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == FALSE) {
1245 MACbShutdown(pDevice);
1246 }
1247 netif_stop_queue(pDevice->dev);
1248 MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
1249 MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES);
1250 MP_CLEAR_FLAG(pDevice, fMP_POST_READS);
1251 pDevice->fKillEventPollingThread = TRUE;
1252 del_timer(&pDevice->sTimerCommand);
1253 del_timer(&pMgmt->sTimerSecondCallback);
1254
1255
1256#ifdef TxInSleep
1257 del_timer(&pDevice->sTimerTxData);
1258#endif
1259
1260 if (pDevice->bDiversityRegCtlON) {
1261 del_timer(&pDevice->TimerSQ3Tmax1);
1262 del_timer(&pDevice->TimerSQ3Tmax2);
1263 del_timer(&pDevice->TimerSQ3Tmax3);
1264 }
1265 tasklet_kill(&pDevice->RxMngWorkItem);
1266 tasklet_kill(&pDevice->ReadWorkItem);
1267 tasklet_kill(&pDevice->EventWorkItem);
1268
1269 pDevice->bRoaming = FALSE;
1270 pDevice->bIsRoaming = FALSE;
1271 pDevice->bEnableRoaming = FALSE;
1272 pDevice->bCmdRunning = FALSE;
1273 pDevice->bLinkPass = FALSE;
1274 memset(pMgmt->abyCurrBSSID, 0, 6);
1275 pMgmt->eCurrState = WMAC_STATE_IDLE;
1276
1277 device_free_tx_bufs(pDevice);
1278 device_free_rx_bufs(pDevice);
1279 device_free_int_bufs(pDevice);
1280 device_free_frag_bufs(pDevice);
1281
1282 usb_kill_urb(pDevice->pControlURB);
1283 usb_kill_urb(pDevice->pInterruptURB);
1284 usb_free_urb(pDevice->pControlURB);
1285 usb_free_urb(pDevice->pInterruptURB);
1286
1287 BSSvClearNodeDBTable(pDevice, 0);
1288 pDevice->flags &=(~DEVICE_FLAGS_OPENED);
1289
1290 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n");
1291
1292 return 0;
1293}
1294
1295
1296static void vntwusb_disconnect(struct usb_interface *intf)
1297
1298{
1299
1300 PSDevice pDevice = usb_get_intfdata(intf);
1301
1302 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_disconnect1.. \n");
1303 if (pDevice == NULL)
1304 return;
1305
1306#ifdef SndEvt_ToAPI
1307{
1308 union iwreq_data wrqu;
1309 memset(&wrqu, 0, sizeof(wrqu));
1310 wrqu.data.flags = RT_RMMOD_EVENT_FLAG;
1311 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, NULL);
1312}
1313#endif
1314
1315
1316device_release_WPADEV(pDevice);
1317
1318 usb_set_intfdata(intf, NULL);
1319
1320 usb_put_dev(interface_to_usbdev(intf));
1321
1322 pDevice->flags |= DEVICE_FLAGS_UNPLUG;
1323 if (pDevice->dev != NULL) {
1324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "unregister_netdev..\n");
1325 unregister_netdev(pDevice->dev);
1326
1327
1328
1329 if(wpa_set_wpadev(pDevice, 0)!=0)
1330 printk("unregister wpadev fail?\n");
1331
1332 free_netdev(pDevice->dev);
1333 }
1334
1335 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_disconnect3.. \n");
1336}
1337
1338
1339
1340
1341static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
1342 PSDevice pDevice=netdev_priv(dev);
1343 PBYTE pbMPDU;
1344 UINT cbMPDULen = 0;
1345
1346
1347 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
1348 spin_lock_irq(&pDevice->lock);
1349
1350 if (pDevice->bStopTx0Pkt == TRUE) {
1351 dev_kfree_skb_irq(skb);
1352 spin_unlock_irq(&pDevice->lock);
1353 return 0;
1354 };
1355
1356
1357 cbMPDULen = skb->len;
1358 pbMPDU = skb->data;
1359
1360 vDMA0_tx_80211(pDevice, skb);
1361
1362 spin_unlock_irq(&pDevice->lock);
1363
1364 return 0;
1365
1366}
1367
1368
1369static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
1370 PSDevice pDevice=netdev_priv(dev);
1371 struct net_device_stats* pStats = &pDevice->stats;
1372
1373
1374 spin_lock_irq(&pDevice->lock);
1375
1376 netif_stop_queue(pDevice->dev);
1377
1378 if (pDevice->bLinkPass == FALSE) {
1379 dev_kfree_skb_irq(skb);
1380 spin_unlock_irq(&pDevice->lock);
1381 return 0;
1382 }
1383 if (pDevice->bStopDataPkt == TRUE) {
1384 dev_kfree_skb_irq(skb);
1385 pStats->tx_dropped++;
1386 spin_unlock_irq(&pDevice->lock);
1387 return 0;
1388 }
1389
1390 if(nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb) !=0) {
1391 if (netif_queue_stopped(pDevice->dev))
1392 netif_wake_queue(pDevice->dev);
1393 }
1394
1395 spin_unlock_irq(&pDevice->lock);
1396
1397 return 0;
1398}
1399
1400
1401
1402static unsigned const ethernet_polynomial = 0x04c11db7U;
1403static inline u32 ether_crc(int length, unsigned char *data)
1404{
1405 int crc = -1;
1406
1407 while(--length >= 0) {
1408 unsigned char current_octet = *data++;
1409 int bit;
1410 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
1411 crc = (crc << 1) ^
1412 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
1413 }
1414 }
1415 return crc;
1416}
1417
1418
1419static UCHAR *kstrstr(const UCHAR *str1,const UCHAR *str2) {
1420 int str1_len=strlen(str1);
1421 int str2_len=strlen(str2);
1422
1423 while (str1_len >= str2_len) {
1424 str1_len--;
1425 if(memcmp(str1,str2,str2_len)==0)
1426 return (UCHAR *)str1;
1427 str1++;
1428 }
1429 return NULL;
1430}
1431
1432static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source)
1433{
1434 UCHAR buf1[100];
1435 UCHAR buf2[100];
1436 UCHAR *start_p=NULL,*end_p=NULL,*tmp_p=NULL;
1437 int ii;
1438
1439 memset(buf1,0,100);
1440 strcat(buf1, string);
1441 strcat(buf1, "=");
1442 source+=strlen(buf1);
1443
1444
1445 if((start_p = kstrstr(source,buf1))==NULL)
1446 return FALSE;
1447
1448
1449for(ii=1;;ii++) {
1450 if(memcmp(start_p-ii,"\n",1)==0)
1451 break;
1452 if(memcmp(start_p-ii,"#",1)==0)
1453 return FALSE;
1454}
1455
1456
1457 if((end_p = kstrstr(start_p,"\n"))==NULL) {
1458 end_p=start_p+strlen(start_p);
1459 }
1460
1461 memset(buf2,0,100);
1462 memcpy(buf2,start_p,end_p-start_p);
1463 buf2[end_p-start_p]='\0';
1464
1465
1466 if((start_p = kstrstr(buf2,"="))==NULL)
1467 return FALSE;
1468 memset(buf1,0,100);
1469 strcpy(buf1,start_p+1);
1470
1471
1472 tmp_p = buf1;
1473 while(*tmp_p != 0x00) {
1474 if(*tmp_p==' ')
1475 tmp_p++;
1476 else
1477 break;
1478 }
1479
1480 memcpy(dest,tmp_p,strlen(tmp_p));
1481 return TRUE;
1482}
1483
1484
1485static UCHAR *Config_FileOperation(PSDevice pDevice) {
1486 UCHAR *config_path=CONFIG_PATH;
1487 UCHAR *buffer=NULL;
1488 struct file *filp=NULL;
1489 mm_segment_t old_fs = get_fs();
1490
1491 int result=0;
1492
1493 set_fs (KERNEL_DS);
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503 filp = filp_open(config_path, O_RDWR, 0);
1504 if (IS_ERR(filp)) {
1505 printk("Config_FileOperation file Not exist\n");
1506 result=-1;
1507 goto error2;
1508 }
1509
1510 if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
1511 printk("file %s cann't readable or writable?\n",config_path);
1512 result = -1;
1513 goto error1;
1514 }
1515
1516 buffer = (UCHAR *)kmalloc(1024, GFP_KERNEL);
1517 if(buffer==NULL) {
1518 printk("alllocate mem for file fail?\n");
1519 result = -1;
1520 goto error1;
1521 }
1522
1523 if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
1524 printk("read file error?\n");
1525 result = -1;
1526 }
1527
1528error1:
1529 if(filp_close(filp,NULL))
1530 printk("Config_FileOperation:close file fail\n");
1531
1532error2:
1533 set_fs (old_fs);
1534
1535
1536
1537
1538
1539
1540if(result!=0) {
1541 if(buffer)
1542 kfree(buffer);
1543 buffer=NULL;
1544}
1545 return buffer;
1546}
1547
1548
1549static int Read_config_file(PSDevice pDevice) {
1550 int result=0;
1551 UCHAR tmpbuffer[100];
1552 UCHAR *buffer=NULL;
1553
1554
1555 pDevice->config_file.ZoneType = -1;
1556 pDevice->config_file.eAuthenMode = -1;
1557 pDevice->config_file.eEncryptionStatus = -1;
1558
1559 if((buffer=Config_FileOperation(pDevice)) ==NULL) {
1560 result =-1;
1561 return result;
1562 }
1563
1564
1565{
1566 memset(tmpbuffer,0,sizeof(tmpbuffer));
1567 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==TRUE) {
1568 if(memcmp(tmpbuffer,"USA",3)==0) {
1569 pDevice->config_file.ZoneType=ZoneType_USA;
1570 }
1571 else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
1572 pDevice->config_file.ZoneType=ZoneType_Japan;
1573 }
1574 else if(memcmp(tmpbuffer,"EUROPE",6)==0) {
1575 pDevice->config_file.ZoneType=ZoneType_Europe;
1576 }
1577 else {
1578 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
1579 }
1580 }
1581}
1582
1583#if 1
1584
1585 {
1586 memset(tmpbuffer,0,sizeof(tmpbuffer));
1587 if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==TRUE) {
1588 pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10);
1589 }
1590
1591 memset(tmpbuffer,0,sizeof(tmpbuffer));
1592 if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==TRUE) {
1593 pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10);
1594 }
1595 }
1596#endif
1597
1598 kfree(buffer);
1599 return result;
1600}
1601
1602static void device_set_multi(struct net_device *dev) {
1603 PSDevice pDevice = (PSDevice) netdev_priv(dev);
1604 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1605 u32 mc_filter[2];
1606 int ii;
1607 struct dev_mc_list *mclist;
1608 BYTE pbyData[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
1609 BYTE byTmpMode = 0;
1610 int rc;
1611
1612
1613 spin_lock_irq(&pDevice->lock);
1614 rc = CONTROLnsRequestIn(pDevice,
1615 MESSAGE_TYPE_READ,
1616 MAC_REG_RCR,
1617 MESSAGE_REQUEST_MACREG,
1618 1,
1619 &byTmpMode
1620 );
1621 if (rc == 0) pDevice->byRxMode = byTmpMode;
1622
1623 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode in= %x\n", pDevice->byRxMode);
1624
1625 if (dev->flags & IFF_PROMISC) {
1626 DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
1627
1628 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
1629 }
1630 else if ((dev->mc_count > pDevice->multicast_limit) || (dev->flags & IFF_ALLMULTI)) {
1631 CONTROLnsRequestOut(pDevice,
1632 MESSAGE_TYPE_WRITE,
1633 MAC_REG_MAR0,
1634 MESSAGE_REQUEST_MACREG,
1635 8,
1636 pbyData
1637 );
1638 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1639 }
1640 else {
1641 memset(mc_filter, 0, sizeof(mc_filter));
1642 for (ii = 0, mclist = dev->mc_list; mclist && ii < dev->mc_count;
1643 ii++, mclist = mclist->next) {
1644 int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
1645 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
1646 }
1647 for (ii = 0; ii < 4; ii++) {
1648 MACvWriteMultiAddr(pDevice, ii, *((PBYTE)&mc_filter[0] + ii));
1649 MACvWriteMultiAddr(pDevice, ii+ 4, *((PBYTE)&mc_filter[1] + ii));
1650 }
1651 pDevice->byRxMode &= ~(RCR_UNICAST);
1652 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1653 }
1654
1655 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1656
1657 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1658 pDevice->byRxMode &= ~(RCR_UNICAST);
1659 }
1660 ControlvWriteByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, pDevice->byRxMode);
1661 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode out= %x\n", pDevice->byRxMode);
1662 spin_unlock_irq(&pDevice->lock);
1663
1664}
1665
1666
1667static struct net_device_stats *device_get_stats(struct net_device *dev) {
1668 PSDevice pDevice=(PSDevice) netdev_priv(dev);
1669
1670 return &pDevice->stats;
1671}
1672
1673
1674static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
1675 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1676 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1677 PSCmdRequest pReq;
1678
1679 struct iwreq *wrq = (struct iwreq *) rq;
1680 int rc =0;
1681
1682 if (pMgmt == NULL) {
1683 rc = -EFAULT;
1684 return rc;
1685 }
1686
1687 switch(cmd) {
1688
1689 case SIOCGIWNAME:
1690 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
1691 break;
1692
1693 case SIOCSIWNWID:
1694 rc = -EOPNOTSUPP;
1695 break;
1696
1697 case SIOCGIWNWID:
1698 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1699 rc = iwctl_giwnwid(dev, NULL, &(wrq->u.nwid), NULL);
1700 #else
1701 rc = -EOPNOTSUPP;
1702 #endif
1703 break;
1704
1705
1706 case SIOCSIWFREQ:
1707 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
1708 break;
1709
1710
1711 case SIOCGIWFREQ:
1712 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
1713 break;
1714
1715
1716 case SIOCSIWESSID:
1717
1718 {
1719 char essid[IW_ESSID_MAX_SIZE+1];
1720 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
1721 rc = -E2BIG;
1722 break;
1723 }
1724 if (copy_from_user(essid, wrq->u.essid.pointer,
1725 wrq->u.essid.length)) {
1726 rc = -EFAULT;
1727 break;
1728 }
1729 rc = iwctl_siwessid(dev, NULL,
1730 &(wrq->u.essid), essid);
1731 }
1732 break;
1733
1734
1735
1736 case SIOCGIWESSID:
1737
1738 {
1739 char essid[IW_ESSID_MAX_SIZE+1];
1740 if (wrq->u.essid.pointer)
1741 rc = iwctl_giwessid(dev, NULL,
1742 &(wrq->u.essid), essid);
1743 if (copy_to_user(wrq->u.essid.pointer,
1744 essid,
1745 wrq->u.essid.length) )
1746 rc = -EFAULT;
1747 }
1748 break;
1749
1750 case SIOCSIWAP:
1751
1752 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
1753 break;
1754
1755
1756
1757 case SIOCGIWAP:
1758 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
1759 break;
1760
1761
1762
1763 case SIOCSIWNICKN:
1764 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
1765 rc = -EOPNOTSUPP;
1766 break;
1767
1768
1769 case SIOCGIWNICKN:
1770 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
1771 rc = -EOPNOTSUPP;
1772 break;
1773
1774
1775 case SIOCSIWRATE:
1776 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
1777 break;
1778
1779
1780 case SIOCGIWRATE:
1781
1782 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
1783 break;
1784
1785
1786 case SIOCSIWRTS:
1787
1788 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
1789 break;
1790
1791
1792 case SIOCGIWRTS:
1793
1794 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
1795 break;
1796
1797
1798 case SIOCSIWFRAG:
1799
1800 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
1801 break;
1802
1803
1804 case SIOCGIWFRAG:
1805
1806 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
1807 break;
1808
1809
1810 case SIOCSIWMODE:
1811 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
1812 break;
1813
1814
1815 case SIOCGIWMODE:
1816 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
1817 break;
1818
1819
1820 case SIOCSIWENCODE:
1821 {
1822 char abyKey[WLAN_WEP232_KEYLEN];
1823
1824 if (wrq->u.encoding.pointer) {
1825
1826
1827 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
1828 rc = -E2BIG;
1829 break;
1830 }
1831 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
1832 if (copy_from_user(abyKey,
1833 wrq->u.encoding.pointer,
1834 wrq->u.encoding.length)) {
1835 rc = -EFAULT;
1836 break;
1837 }
1838 } else if (wrq->u.encoding.length != 0) {
1839 rc = -EINVAL;
1840 break;
1841 }
1842 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
1843 }
1844 break;
1845
1846
1847 case SIOCGIWENCODE:
1848
1849 if (!capable(CAP_NET_ADMIN)) {
1850 rc = -EPERM;
1851 break;
1852 }
1853 {
1854 char abyKey[WLAN_WEP232_KEYLEN];
1855
1856 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
1857 if (rc != 0) break;
1858 if (wrq->u.encoding.pointer) {
1859 if (copy_to_user(wrq->u.encoding.pointer,
1860 abyKey,
1861 wrq->u.encoding.length))
1862 rc = -EFAULT;
1863 }
1864 }
1865 break;
1866
1867
1868 case SIOCGIWTXPOW:
1869 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
1870 rc = -EOPNOTSUPP;
1871 break;
1872
1873 case SIOCSIWTXPOW:
1874 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
1875 rc = -EOPNOTSUPP;
1876 break;
1877
1878 case SIOCSIWRETRY:
1879
1880 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
1881 break;
1882
1883 case SIOCGIWRETRY:
1884
1885 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
1886 break;
1887
1888
1889 case SIOCGIWRANGE:
1890
1891 {
1892 struct iw_range range;
1893
1894 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *) &range);
1895 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
1896 rc = -EFAULT;
1897 }
1898
1899 break;
1900
1901 case SIOCGIWPOWER:
1902
1903 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
1904 break;
1905
1906
1907 case SIOCSIWPOWER:
1908
1909 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
1910 break;
1911
1912
1913 case SIOCGIWSENS:
1914
1915 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
1916 break;
1917
1918 case SIOCSIWSENS:
1919 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
1920 rc = -EOPNOTSUPP;
1921 break;
1922
1923 case SIOCGIWAPLIST:
1924 {
1925 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
1926
1927 if (wrq->u.data.pointer) {
1928 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
1929 if (rc == 0) {
1930 if (copy_to_user(wrq->u.data.pointer,
1931 buffer,
1932 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
1933 ))
1934 rc = -EFAULT;
1935 }
1936 }
1937 }
1938 break;
1939
1940
1941#ifdef WIRELESS_SPY
1942
1943 case SIOCSIWSPY:
1944
1945 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
1946 rc = -EOPNOTSUPP;
1947 break;
1948
1949
1950 case SIOCGIWSPY:
1951
1952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
1953 rc = -EOPNOTSUPP;
1954 break;
1955
1956#endif
1957
1958 case SIOCGIWPRIV:
1959 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
1960 rc = -EOPNOTSUPP;
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971 break;
1972
1973
1974
1975#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1976 case SIOCSIWAUTH:
1977 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
1978 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
1979 break;
1980
1981 case SIOCGIWAUTH:
1982 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH \n");
1983 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
1984 break;
1985
1986 case SIOCSIWGENIE:
1987 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE \n");
1988 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
1989 break;
1990
1991 case SIOCGIWGENIE:
1992 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE \n");
1993 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
1994 break;
1995
1996 case SIOCSIWENCODEEXT:
1997 {
1998 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
1999 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
2000 if(wrq->u.encoding.pointer){
2001 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1);
2002 if(wrq->u.encoding.length > (sizeof(struct iw_encode_ext)+ MAX_KEY_LEN)){
2003 rc = -E2BIG;
2004 break;
2005 }
2006 if(copy_from_user(extra, wrq->u.encoding.pointer,wrq->u.encoding.length)){
2007 rc = -EFAULT;
2008 break;
2009 }
2010 }else if(wrq->u.encoding.length != 0){
2011 rc = -EINVAL;
2012 break;
2013 }
2014 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
2015 }
2016 break;
2017
2018 case SIOCGIWENCODEEXT:
2019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
2020 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
2021 break;
2022
2023 case SIOCSIWMLME:
2024 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME \n");
2025 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2026 break;
2027
2028#endif
2029
2030
2031 case IOCTL_CMD_TEST:
2032
2033 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
2034 rc = -EFAULT;
2035 break;
2036 } else {
2037 rc = 0;
2038 }
2039 pReq = (PSCmdRequest)rq;
2040
2041
2042
2043 pReq->wResult = MAGIC_CODE;
2044
2045
2046
2047 break;
2048
2049 case IOCTL_CMD_SET:
2050 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
2051 (((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_WPA))
2052 {
2053 rc = -EFAULT;
2054 break;
2055 } else {
2056 rc = 0;
2057 }
2058
2059 if (test_and_set_bit( 0, (void*)&(pMgmt->uCmdBusy))) {
2060 return -EBUSY;
2061 }
2062 rc = private_ioctl(pDevice, rq);
2063 clear_bit( 0, (void*)&(pMgmt->uCmdBusy));
2064 break;
2065
2066 case IOCTL_CMD_HOSTAPD:
2067
2068 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
2069 rc = -EFAULT;
2070 break;
2071 } else {
2072 rc = 0;
2073 }
2074
2075 rc = hostap_ioctl(pDevice, &wrq->u.data);
2076 break;
2077
2078 case IOCTL_CMD_WPA:
2079
2080 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
2081 rc = -EFAULT;
2082 break;
2083 } else {
2084 rc = 0;
2085 }
2086
2087 rc = wpa_ioctl(pDevice, &wrq->u.data);
2088 break;
2089
2090 case SIOCETHTOOL:
2091 return ethtool_ioctl(dev, (void *) rq->ifr_data);
2092
2093
2094 default:
2095 rc = -EOPNOTSUPP;
2096 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
2097
2098
2099 }
2100
2101 if (pDevice->bCommit) {
2102 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2103 netif_stop_queue(pDevice->dev);
2104 spin_lock_irq(&pDevice->lock);
2105 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
2106 spin_unlock_irq(&pDevice->lock);
2107 }
2108 else {
2109 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
2110 spin_lock_irq(&pDevice->lock);
2111
2112 if (pDevice->bLinkPass&&
2113 memcmp(pMgmt->abyCurrSSID,pMgmt->abyDesireSSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN)) {
2114 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2115 } else {
2116 pDevice->bLinkPass = FALSE;
2117 pMgmt->eCurrState = WMAC_STATE_IDLE;
2118 memset(pMgmt->abyCurrBSSID, 0, 6);
2119 }
2120 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
2121
2122 netif_stop_queue(pDevice->dev);
2123#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2124 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
2125 if(pDevice->bWPASuppWextEnabled !=TRUE)
2126#endif
2127 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
2128 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
2129 spin_unlock_irq(&pDevice->lock);
2130 }
2131 pDevice->bCommit = FALSE;
2132 }
2133
2134
2135 return rc;
2136}
2137
2138
2139static int ethtool_ioctl(struct net_device *dev, void *useraddr)
2140{
2141 u32 ethcmd;
2142
2143 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
2144 return -EFAULT;
2145
2146 switch (ethcmd) {
2147 case ETHTOOL_GDRVINFO: {
2148 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
2149 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
2150 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
2151 if (copy_to_user(useraddr, &info, sizeof(info)))
2152 return -EFAULT;
2153 return 0;
2154 }
2155
2156 }
2157
2158 return -EOPNOTSUPP;
2159}
2160
2161
2162
2163
2164
2165MODULE_DEVICE_TABLE(usb, vntwusb_table);
2166
2167
2168static struct usb_driver vntwusb_driver = {
2169 .name = DEVICE_NAME,
2170 .probe = vntwusb_found1,
2171 .disconnect = vntwusb_disconnect,
2172 .id_table = vntwusb_table,
2173
2174
2175
2176#ifdef CONFIG_PM
2177 .suspend = vntwusb_suspend,
2178 .resume = vntwusb_resume,
2179#endif
2180};
2181
2182static int __init vntwusb_init_module(void)
2183{
2184 printk(KERN_NOTICE DEVICE_FULL_DRV_NAM " " DEVICE_VERSION);
2185 return usb_register(&vntwusb_driver);
2186}
2187
2188static void __exit vntwusb_cleanup_module(void)
2189{
2190 usb_deregister(&vntwusb_driver);
2191}
2192
2193module_init(vntwusb_init_module);
2194module_exit(vntwusb_cleanup_module);
2195
2196