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 * vntwusb_found1 - 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 - asynchrous data tx function
33 * device_set_multi - set mac filter
34 * device_ioctl - ioctl entry
35 * device_close - shutdown mac/bbp & free dma/descripter 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 bufferred 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
79 /*--------------------- Static Definitions -------------------------*/
80 //static int msglevel =MSG_LEVEL_DEBUG;
81 static int msglevel
=MSG_LEVEL_INFO
;
84 // Define module options
87 // Version Information
88 #define DRIVER_AUTHOR "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
89 MODULE_AUTHOR(DRIVER_AUTHOR
);
90 MODULE_LICENSE("GPL");
91 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM
);
93 #define DEVICE_PARAM(N,D) \
94 static int N[MAX_UINTS]=OPTION_DEFAULT;\
95 module_param_array(N, int, NULL, 0);\
96 MODULE_PARM_DESC(N, D);
98 #define RX_DESC_MIN0 16
99 #define RX_DESC_MAX0 128
100 #define RX_DESC_DEF0 64
101 DEVICE_PARAM(RxDescriptors0
,"Number of receive usb desc buffer");
104 #define TX_DESC_MIN0 16
105 #define TX_DESC_MAX0 128
106 #define TX_DESC_DEF0 64
107 DEVICE_PARAM(TxDescriptors0
,"Number of transmit usb desc buffer");
110 #define CHANNEL_MIN 1
111 #define CHANNEL_MAX 14
112 #define CHANNEL_DEF 6
114 DEVICE_PARAM(Channel
, "Channel number");
117 /* PreambleType[] is the preamble length used for transmit.
118 0: indicate allows long preamble type
119 1: indicate allows short preamble type
122 #define PREAMBLE_TYPE_DEF 1
124 DEVICE_PARAM(PreambleType
, "Preamble Type");
127 #define RTS_THRESH_MIN 512
128 #define RTS_THRESH_MAX 2347
129 #define RTS_THRESH_DEF 2347
131 DEVICE_PARAM(RTSThreshold
, "RTS threshold");
134 #define FRAG_THRESH_MIN 256
135 #define FRAG_THRESH_MAX 2346
136 #define FRAG_THRESH_DEF 2346
138 DEVICE_PARAM(FragThreshold
, "Fragmentation threshold");
141 #define DATA_RATE_MIN 0
142 #define DATA_RATE_MAX 13
143 #define DATA_RATE_DEF 13
145 0: indicate 1 Mbps 0x02
146 1: indicate 2 Mbps 0x04
147 2: indicate 5.5 Mbps 0x0B
148 3: indicate 11 Mbps 0x16
149 4: indicate 6 Mbps 0x0c
150 5: indicate 9 Mbps 0x12
151 6: indicate 12 Mbps 0x18
152 7: indicate 18 Mbps 0x24
153 8: indicate 24 Mbps 0x30
154 9: indicate 36 Mbps 0x48
155 10: indicate 48 Mbps 0x60
156 11: indicate 54 Mbps 0x6c
157 12: indicate 72 Mbps 0x90
158 13: indicate auto rate
161 DEVICE_PARAM(ConnectionRate
, "Connection data rate");
163 #define OP_MODE_MAX 2
164 #define OP_MODE_DEF 0
165 #define OP_MODE_MIN 0
167 DEVICE_PARAM(OPMode
, "Infrastruct, adhoc, AP mode ");
169 /* OpMode[] is used for transmit.
170 0: indicate infrastruct mode used
171 1: indicate adhoc mode used
172 2: indicate AP mode used
177 0: indicate disable power saving mode
178 1: indicate enable power saving mode
181 #define PS_MODE_DEF 0
183 DEVICE_PARAM(PSMode
, "Power saving mode");
186 #define SHORT_RETRY_MIN 0
187 #define SHORT_RETRY_MAX 31
188 #define SHORT_RETRY_DEF 8
191 DEVICE_PARAM(ShortRetryLimit
, "Short frame retry limits");
193 #define LONG_RETRY_MIN 0
194 #define LONG_RETRY_MAX 15
195 #define LONG_RETRY_DEF 4
198 DEVICE_PARAM(LongRetryLimit
, "long frame retry limits");
201 /* BasebandType[] baseband type selected
202 0: indicate 802.11a type
203 1: indicate 802.11b type
204 2: indicate 802.11g type
206 #define BBP_TYPE_MIN 0
207 #define BBP_TYPE_MAX 2
208 #define BBP_TYPE_DEF 2
210 DEVICE_PARAM(BasebandType
, "baseband type");
215 0: indicate disable 802.11h
216 1: indicate enable 802.11h
219 #define X80211h_MODE_DEF 0
221 DEVICE_PARAM(b80211hEnable
, "802.11h mode");
225 // Static vars definitions
230 static struct usb_device_id vntwusb_table
[] = {
231 {USB_DEVICE(VNT_USB_VENDOR_ID
, VNT_USB_PRODUCT_ID
)},
237 // Frequency list (map channels to frequencies)
239 static const long frequency_list[] = {
240 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
241 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
242 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
243 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
244 5700, 5745, 5765, 5785, 5805, 5825
248 #ifndef IW_ENCODE_NOKEY
249 #define IW_ENCODE_NOKEY 0x0800
250 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
253 static const struct iw_handler_def iwctl_handler_def;
258 /*--------------------- Static Functions --------------------------*/
259 static int vntwusb_found1(struct usb_interface
*intf
, const struct usb_device_id
*id
);
260 static void vntwusb_disconnect(struct usb_interface
*intf
);
261 #ifdef CONFIG_PM /* Minimal support for suspend and resume */
262 static int vntwusb_suspend(struct usb_interface
*intf
, pm_message_t message
);
263 static int vntwusb_resume(struct usb_interface
*intf
);
265 static struct net_device_stats
*device_get_stats(struct net_device
*dev
);
266 static int device_open(struct net_device
*dev
);
267 static int device_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
268 static void device_set_multi(struct net_device
*dev
);
269 static int device_close(struct net_device
*dev
);
270 static int device_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
272 static BOOL
device_init_registers(PSDevice pDevice
, DEVICE_INIT_TYPE InitType
);
273 static BOOL
device_init_defrag_cb(PSDevice pDevice
);
274 static void device_init_diversity_timer(PSDevice pDevice
);
275 static int device_dma0_tx_80211(struct sk_buff
*skb
, struct net_device
*dev
);
277 static int ethtool_ioctl(struct net_device
*dev
, void *useraddr
);
278 static void device_free_tx_bufs(PSDevice pDevice
);
279 static void device_free_rx_bufs(PSDevice pDevice
);
280 static void device_free_int_bufs(PSDevice pDevice
);
281 static void device_free_frag_bufs(PSDevice pDevice
);
282 static BOOL
device_alloc_bufs(PSDevice pDevice
);
284 static int Read_config_file(PSDevice pDevice
);
285 static UCHAR
*Config_FileOperation(PSDevice pDevice
);
286 static int Config_FileGetParameter(UCHAR
*string
, UCHAR
*dest
,UCHAR
*source
);
288 //2008-0714<Add>by Mike Liu
289 static BOOL
device_release_WPADEV(PSDevice pDevice
);
291 static void usb_device_reset(PSDevice pDevice
);
295 /*--------------------- Export Variables --------------------------*/
297 /*--------------------- Export Functions --------------------------*/
301 device_set_options(PSDevice pDevice
) {
303 BYTE abyBroadcastAddr
[U_ETHER_ADDR_LEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
304 BYTE abySNAP_RFC1042
[U_ETHER_ADDR_LEN
] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
305 BYTE abySNAP_Bridgetunnel
[U_ETHER_ADDR_LEN
] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
308 memcpy(pDevice
->abyBroadcastAddr
, abyBroadcastAddr
, U_ETHER_ADDR_LEN
);
309 memcpy(pDevice
->abySNAP_RFC1042
, abySNAP_RFC1042
, U_ETHER_ADDR_LEN
);
310 memcpy(pDevice
->abySNAP_Bridgetunnel
, abySNAP_Bridgetunnel
, U_ETHER_ADDR_LEN
);
312 pDevice
->cbTD
= TX_DESC_DEF0
;
313 pDevice
->cbRD
= RX_DESC_DEF0
;
314 pDevice
->uChannel
= CHANNEL_DEF
;
315 pDevice
->wRTSThreshold
= RTS_THRESH_DEF
;
316 pDevice
->wFragmentationThreshold
= FRAG_THRESH_DEF
;
317 pDevice
->byShortRetryLimit
= SHORT_RETRY_DEF
;
318 pDevice
->byLongRetryLimit
= LONG_RETRY_DEF
;
319 pDevice
->wMaxTransmitMSDULifetime
= DEFAULT_MSDU_LIFETIME
;
320 pDevice
->byShortPreamble
= PREAMBLE_TYPE_DEF
;
321 pDevice
->ePSMode
= PS_MODE_DEF
;
322 pDevice
->b11hEnable
= X80211h_MODE_DEF
;
323 pDevice
->eOPMode
= OP_MODE_DEF
;
324 pDevice
->uConnectionRate
= DATA_RATE_DEF
;
325 if (pDevice
->uConnectionRate
< RATE_AUTO
) pDevice
->bFixRate
= TRUE
;
326 pDevice
->byBBType
= BBP_TYPE_DEF
;
327 pDevice
->byPacketType
= pDevice
->byBBType
;
328 pDevice
->byAutoFBCtrl
= AUTO_FB_0
;
329 pDevice
->bUpdateBBVGA
= TRUE
;
330 pDevice
->byFOETuning
= 0;
331 pDevice
->byAutoPwrTunning
= 0;
332 pDevice
->wCTSDuration
= 0;
333 pDevice
->byPreambleType
= 0;
334 pDevice
->bExistSWNetAddr
= FALSE
;
335 // pDevice->bDiversityRegCtlON = TRUE;
336 pDevice
->bDiversityRegCtlON
= FALSE
;
340 static VOID
device_init_diversity_timer(PSDevice pDevice
) {
342 init_timer(&pDevice
->TimerSQ3Tmax1
);
343 pDevice
->TimerSQ3Tmax1
.data
= (ULONG
)pDevice
;
344 pDevice
->TimerSQ3Tmax1
.function
= (TimerFunction
)TimerSQ3CallBack
;
345 pDevice
->TimerSQ3Tmax1
.expires
= RUN_AT(HZ
);
347 init_timer(&pDevice
->TimerSQ3Tmax2
);
348 pDevice
->TimerSQ3Tmax2
.data
= (ULONG
)pDevice
;
349 pDevice
->TimerSQ3Tmax2
.function
= (TimerFunction
)TimerSQ3CallBack
;
350 pDevice
->TimerSQ3Tmax2
.expires
= RUN_AT(HZ
);
352 init_timer(&pDevice
->TimerSQ3Tmax3
);
353 pDevice
->TimerSQ3Tmax3
.data
= (ULONG
)pDevice
;
354 pDevice
->TimerSQ3Tmax3
.function
= (TimerFunction
)TimerSQ3Tmax3CallBack
;
355 pDevice
->TimerSQ3Tmax3
.expires
= RUN_AT(HZ
);
362 // Initialiation of MAC & BBP registers
365 static BOOL
device_init_registers(PSDevice pDevice
, DEVICE_INIT_TYPE InitType
)
367 BYTE abyBroadcastAddr
[U_ETHER_ADDR_LEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
368 BYTE abySNAP_RFC1042
[U_ETHER_ADDR_LEN
] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
369 BYTE abySNAP_Bridgetunnel
[U_ETHER_ADDR_LEN
] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
372 CMD_CARD_INIT sInitCmd
;
373 NTSTATUS ntStatus
= STATUS_SUCCESS
;
374 RSP_CARD_INIT sInitRsp
;
375 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
377 BYTE byCalibTXIQ
= 0;
378 BYTE byCalibTXDC
= 0;
379 BYTE byCalibRXIQ
= 0;
381 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---->INIbInitAdapter. [%d][%d]\n", InitType
, pDevice
->byPacketType
);
382 spin_lock_irq(&pDevice
->lock
);
383 if (InitType
== DEVICE_INIT_COLD
) {
384 memcpy(pDevice
->abyBroadcastAddr
, abyBroadcastAddr
, U_ETHER_ADDR_LEN
);
385 memcpy(pDevice
->abySNAP_RFC1042
, abySNAP_RFC1042
, U_ETHER_ADDR_LEN
);
386 memcpy(pDevice
->abySNAP_Bridgetunnel
, abySNAP_Bridgetunnel
, U_ETHER_ADDR_LEN
);
388 if ( !FIRMWAREbCheckVersion(pDevice
) ) {
389 if (FIRMWAREbDownload(pDevice
) == TRUE
) {
390 if (FIRMWAREbBrach2Sram(pDevice
) == FALSE
) {
391 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" FIRMWAREbBrach2Sram fail \n");
392 spin_unlock_irq(&pDevice
->lock
);
397 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" FIRMWAREbDownload fail \n");
398 spin_unlock_irq(&pDevice
->lock
);
403 if ( !BBbVT3184Init(pDevice
) ) {
404 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" BBbVT3184Init fail \n");
405 spin_unlock_irq(&pDevice
->lock
);
410 sInitCmd
.byInitClass
= (BYTE
)InitType
;
411 sInitCmd
.bExistSWNetAddr
= (BYTE
) pDevice
->bExistSWNetAddr
;
413 sInitCmd
.bySWNetAddr
[ii
] = pDevice
->abyCurrentNetAddr
[ii
];
414 sInitCmd
.byShortRetryLimit
= pDevice
->byShortRetryLimit
;
415 sInitCmd
.byLongRetryLimit
= pDevice
->byLongRetryLimit
;
417 //issue Card_init command to device
418 ntStatus
= CONTROLnsRequestOut(pDevice
,
419 MESSAGE_TYPE_CARDINIT
,
422 sizeof(CMD_CARD_INIT
),
423 (PBYTE
) &(sInitCmd
));
425 if ( ntStatus
!= STATUS_SUCCESS
) {
426 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Issue Card init fail \n");
427 spin_unlock_irq(&pDevice
->lock
);
430 if (InitType
== DEVICE_INIT_COLD
) {
432 ntStatus
= CONTROLnsRequestIn(pDevice
,MESSAGE_TYPE_INIT_RSP
,0,0,sizeof(RSP_CARD_INIT
), (PBYTE
) &(sInitRsp
));
434 if (ntStatus
!= STATUS_SUCCESS
) {
435 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Cardinit request in status fail!\n");
436 spin_unlock_irq(&pDevice
->lock
);
440 //Local ID for AES functions
441 ntStatus
= CONTROLnsRequestIn(pDevice
,
444 MESSAGE_REQUEST_MACREG
,
446 &pDevice
->byLocalID
);
448 if ( ntStatus
!= STATUS_SUCCESS
) {
449 spin_unlock_irq(&pDevice
->lock
);
453 // Do MACbSoftwareReset in MACvInitialize
455 pDevice
->bCCK
= TRUE
;
456 pDevice
->bProtectMode
= FALSE
; //Only used in 11g type, sync with ERP IE
457 pDevice
->bNonERPPresent
= FALSE
;
458 pDevice
->bBarkerPreambleMd
= FALSE
;
459 if ( pDevice
->bFixRate
) {
460 pDevice
->wCurrentRate
= (WORD
) pDevice
->uConnectionRate
;
462 if ( pDevice
->byBBType
== BB_TYPE_11B
)
463 pDevice
->wCurrentRate
= RATE_11M
;
465 pDevice
->wCurrentRate
= RATE_54M
;
468 CHvInitChannelTable(pDevice
);
470 pDevice
->byTopOFDMBasicRate
= RATE_24M
;
471 pDevice
->byTopCCKBasicRate
= RATE_1M
;
472 pDevice
->byRevId
= 0; //Target to IF pin while programming to RF chip.
473 pDevice
->byCurPwr
= 0xFF;
475 pDevice
->byCCKPwr
= pDevice
->abyEEPROM
[EEP_OFS_PWR_CCK
];
476 pDevice
->byOFDMPwrG
= pDevice
->abyEEPROM
[EEP_OFS_PWR_OFDMG
];
478 for (ii
=0;ii
<14;ii
++) {
479 pDevice
->abyCCKPwrTbl
[ii
] = pDevice
->abyEEPROM
[ii
+ EEP_OFS_CCK_PWR_TBL
];
480 if (pDevice
->abyCCKPwrTbl
[ii
] == 0)
481 pDevice
->abyCCKPwrTbl
[ii
] = pDevice
->byCCKPwr
;
482 pDevice
->abyOFDMPwrTbl
[ii
] = pDevice
->abyEEPROM
[ii
+ EEP_OFS_OFDM_PWR_TBL
];
483 if (pDevice
->abyOFDMPwrTbl
[ii
] == 0)
484 pDevice
->abyOFDMPwrTbl
[ii
] = pDevice
->byOFDMPwrG
;
487 //original zonetype is USA,but customize zonetype is europe,
488 // then need recover 12,13 ,14 channel with 11 channel
489 if(((pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
] == ZoneType_Japan
) ||
490 (pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
] == ZoneType_Europe
))&&
491 (pDevice
->byOriginalZonetype
== ZoneType_USA
)) {
492 for(ii
=11;ii
<14;ii
++) {
493 pDevice
->abyCCKPwrTbl
[ii
] = pDevice
->abyCCKPwrTbl
[10];
494 pDevice
->abyOFDMPwrTbl
[ii
] = pDevice
->abyOFDMPwrTbl
[10];
498 //{{ RobertYu: 20041124
499 pDevice
->byOFDMPwrA
= 0x34; // same as RFbMA2829SelectChannel
500 // Load OFDM A Power Table
501 for (ii
=0;ii
<CB_MAX_CHANNEL_5G
;ii
++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
502 pDevice
->abyOFDMAPwrTbl
[ii
] = pDevice
->abyEEPROM
[ii
+ EEP_OFS_OFDMA_PWR_TBL
];
503 if (pDevice
->abyOFDMAPwrTbl
[ii
] == 0)
504 pDevice
->abyOFDMAPwrTbl
[ii
] = pDevice
->byOFDMPwrA
;
508 byAntenna
= pDevice
->abyEEPROM
[EEP_OFS_ANTENNA
];
509 if (byAntenna
& EEP_ANTINV
)
510 pDevice
->bTxRxAntInv
= TRUE
;
512 pDevice
->bTxRxAntInv
= FALSE
;
514 byAntenna
&= (EEP_ANTENNA_AUX
| EEP_ANTENNA_MAIN
);
516 if (byAntenna
== 0) // if not set default is All
517 byAntenna
= (EEP_ANTENNA_AUX
| EEP_ANTENNA_MAIN
);
519 if (byAntenna
== (EEP_ANTENNA_AUX
| EEP_ANTENNA_MAIN
)) {
520 pDevice
->byAntennaCount
= 2;
521 pDevice
->byTxAntennaMode
= ANT_B
;
522 pDevice
->dwTxAntennaSel
= 1;
523 pDevice
->dwRxAntennaSel
= 1;
524 if (pDevice
->bTxRxAntInv
== TRUE
)
525 pDevice
->byRxAntennaMode
= ANT_A
;
527 pDevice
->byRxAntennaMode
= ANT_B
;
529 if (pDevice
->bDiversityRegCtlON
)
530 pDevice
->bDiversityEnable
= TRUE
;
532 pDevice
->bDiversityEnable
= FALSE
;
534 pDevice
->bDiversityEnable
= FALSE
;
535 pDevice
->byAntennaCount
= 1;
536 pDevice
->dwTxAntennaSel
= 0;
537 pDevice
->dwRxAntennaSel
= 0;
538 if (byAntenna
& EEP_ANTENNA_AUX
) {
539 pDevice
->byTxAntennaMode
= ANT_A
;
540 if (pDevice
->bTxRxAntInv
== TRUE
)
541 pDevice
->byRxAntennaMode
= ANT_B
;
543 pDevice
->byRxAntennaMode
= ANT_A
;
545 pDevice
->byTxAntennaMode
= ANT_B
;
546 if (pDevice
->bTxRxAntInv
== TRUE
)
547 pDevice
->byRxAntennaMode
= ANT_A
;
549 pDevice
->byRxAntennaMode
= ANT_B
;
552 pDevice
->ulDiversityNValue
= 100*255;
553 pDevice
->ulDiversityMValue
= 100*16;
555 pDevice
->byTMax2
= 4;
556 pDevice
->ulSQ3TH
= 0;
557 pDevice
->byTMax3
= 64;
558 // -----------------------------------------------------------------
560 //Get Auto Fall Back Type
561 pDevice
->byAutoFBCtrl
= AUTO_FB_0
;
564 pDevice
->uScanTime
= WLAN_SCAN_MINITIME
;
567 //pDevice->NetworkType = Ndis802_11Automode;
568 pDevice
->eConfigPHYMode
= PHY_TYPE_AUTO
;
569 pDevice
->byBBType
= BB_TYPE_11G
;
571 // initialize BBP registers
572 pDevice
->ulTxPower
= 25;
575 pDevice
->byMinChannel
= 1;
576 pDevice
->byMaxChannel
= CB_MAX_CHANNEL
;
579 pDevice
->byRFType
= sInitRsp
.byRFType
;
581 if ((pDevice
->byRFType
& RF_EMU
) != 0) {
582 // force change RevID for VT3253 emu
583 pDevice
->byRevId
= 0x80;
586 // Load EEPROM calibrated vt3266 parameters
587 if (pDevice
->byRFType
== RF_VT3226D0
) {
588 if((pDevice
->abyEEPROM
[EEP_OFS_MAJOR_VER
] == 0x1) &&
589 (pDevice
->abyEEPROM
[EEP_OFS_MINOR_VER
] >= 0x4)) {
590 byCalibTXIQ
= pDevice
->abyEEPROM
[EEP_OFS_CALIB_TX_IQ
];
591 byCalibTXDC
= pDevice
->abyEEPROM
[EEP_OFS_CALIB_TX_DC
];
592 byCalibRXIQ
= pDevice
->abyEEPROM
[EEP_OFS_CALIB_RX_IQ
];
593 if( (byCalibTXIQ
|| byCalibTXDC
|| byCalibRXIQ
) ) {
594 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_BBREG
, 0xFF, 0x03); // CR255, Set BB to support TX/RX IQ and DC compensation Mode
595 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_BBREG
, 0xFB, byCalibTXIQ
); // CR251, TX I/Q Imbalance Calibration
596 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_BBREG
, 0xFC, byCalibTXDC
); // CR252, TX DC-Offset Calibration
597 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_BBREG
, 0xFD, byCalibRXIQ
); // CR253, RX I/Q Imbalance Calibration
599 // turn off BB Calibration compensation
600 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_BBREG
, 0xFF, 0x0); // CR255
604 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
605 pMgmt
->uCurrChannel
= pDevice
->uChannel
;
606 pMgmt
->uIBSSChannel
= pDevice
->uChannel
;
607 CARDbSetMediaChannel(pDevice
, pMgmt
->uCurrChannel
);
609 // get Permanent network address
610 memcpy(pDevice
->abyPermanentNetAddr
,&(sInitRsp
.byNetAddr
[0]),6);
611 memcpy(pDevice
->abyCurrentNetAddr
, pDevice
->abyPermanentNetAddr
, U_ETHER_ADDR_LEN
);
613 // if exist SW network address, use SW network address.
615 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",
616 pDevice
->abyCurrentNetAddr
[0],
617 pDevice
->abyCurrentNetAddr
[1],
618 pDevice
->abyCurrentNetAddr
[2],
619 pDevice
->abyCurrentNetAddr
[3],
620 pDevice
->abyCurrentNetAddr
[4],
621 pDevice
->abyCurrentNetAddr
[5]);
626 // Set BB and packet type at the same time.
627 // Set Short Slot Time, xIFS, and RSPINF.
628 if (pDevice
->byBBType
== BB_TYPE_11A
) {
629 CARDbAddBasicRate(pDevice
, RATE_6M
);
630 pDevice
->bShortSlotTime
= TRUE
;
632 CARDbAddBasicRate(pDevice
, RATE_1M
);
633 pDevice
->bShortSlotTime
= FALSE
;
635 BBvSetShortSlotTime(pDevice
);
636 CARDvSetBSSMode(pDevice
);
638 if (pDevice
->bUpdateBBVGA
) {
639 pDevice
->byBBVGACurrent
= pDevice
->abyBBVGA
[0];
640 pDevice
->byBBVGANew
= pDevice
->byBBVGACurrent
;
641 BBvSetVGAGainOffset(pDevice
, pDevice
->abyBBVGA
[0]);
644 pDevice
->byRadioCtl
= pDevice
->abyEEPROM
[EEP_OFS_RADIOCTL
];
645 pDevice
->bHWRadioOff
= FALSE
;
646 if ( (pDevice
->byRadioCtl
& EEP_RADIOCTL_ENABLE
) != 0 ) {
647 ntStatus
= CONTROLnsRequestIn(pDevice
,
650 MESSAGE_REQUEST_MACREG
,
654 if ( ntStatus
!= STATUS_SUCCESS
) {
655 spin_unlock_irq(&pDevice
->lock
);
658 if ( (byTmp
& GPIO3_DATA
) == 0 ) {
659 pDevice
->bHWRadioOff
= TRUE
;
660 MACvRegBitsOn(pDevice
,MAC_REG_GPIOCTL1
,GPIO3_INTMD
);
662 MACvRegBitsOff(pDevice
,MAC_REG_GPIOCTL1
,GPIO3_INTMD
);
663 pDevice
->bHWRadioOff
= FALSE
;
666 } //EEP_RADIOCTL_ENABLE
668 ControlvMaskByte(pDevice
,MESSAGE_REQUEST_MACREG
,MAC_REG_PAPEDELAY
,LEDSTS_TMLEN
,0x38);
669 ControlvMaskByte(pDevice
,MESSAGE_REQUEST_MACREG
,MAC_REG_PAPEDELAY
,LEDSTS_STS
,LEDSTS_SLOW
);
670 MACvRegBitsOn(pDevice
,MAC_REG_GPIOCTL0
,0x01);
672 if ((pDevice
->bHWRadioOff
== TRUE
) || (pDevice
->bRadioControlOff
== TRUE
)) {
673 CARDbRadioPowerOff(pDevice
);
675 CARDbRadioPowerOn(pDevice
);
678 spin_unlock_irq(&pDevice
->lock
);
679 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"<----INIbInitAdapter Exit\n");
683 static BOOL
device_release_WPADEV(PSDevice pDevice
)
685 viawget_wpa_header
*wpahdr
;
687 // wait_queue_head_t Set_wait;
688 //send device close to wpa_supplicnat layer
689 if (pDevice
->bWPADEVUp
==TRUE
) {
690 wpahdr
= (viawget_wpa_header
*)pDevice
->skb
->data
;
691 wpahdr
->type
= VIAWGET_DEVICECLOSE_MSG
;
692 wpahdr
->resp_ie_len
= 0;
693 wpahdr
->req_ie_len
= 0;
694 skb_put(pDevice
->skb
, sizeof(viawget_wpa_header
));
695 pDevice
->skb
->dev
= pDevice
->wpadev
;
696 skb_reset_mac_header(pDevice
->skb
);
697 pDevice
->skb
->pkt_type
= PACKET_HOST
;
698 pDevice
->skb
->protocol
= htons(ETH_P_802_2
);
699 memset(pDevice
->skb
->cb
, 0, sizeof(pDevice
->skb
->cb
));
700 netif_rx(pDevice
->skb
);
701 pDevice
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
703 //wait release WPADEV
704 // init_waitqueue_head(&Set_wait);
705 // wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ); //1s wait
706 while(pDevice
->bWPADEVUp
==TRUE
) {
707 set_current_state(TASK_UNINTERRUPTIBLE
);
708 schedule_timeout (HZ
/20); //wait 50ms
717 #ifdef CONFIG_PM /* Minimal support for suspend and resume */
718 static int vntwusb_suspend(struct usb_interface
*intf
, pm_message_t message
)
720 PSDevice pDevice
= usb_get_intfdata(intf
);
721 struct net_device
*dev
= pDevice
->dev
;
723 printk("VNTWUSB Suspend Start======>\n");
725 if(pDevice
->flags
& DEVICE_FLAGS_OPENED
)
729 usb_put_dev(interface_to_usbdev(intf
));
733 static int vntwusb_resume(struct usb_interface
*intf
)
735 PSDevice pDevice
= usb_get_intfdata(intf
);
736 struct net_device
*dev
= pDevice
->dev
;
738 printk("VNTWUSB Resume Start======>\n");
740 usb_get_dev(interface_to_usbdev(intf
));
741 if(!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
742 if(device_open(dev
)!=0)
743 printk("VNTWUSB Resume Start======>open fail\n");
751 static const struct net_device_ops device_netdev_ops
= {
752 .ndo_open
= device_open
,
753 .ndo_stop
= device_close
,
754 .ndo_do_ioctl
= device_ioctl
,
755 .ndo_get_stats
= device_get_stats
,
756 .ndo_start_xmit
= device_xmit
,
757 .ndo_set_multicast_list
= device_set_multi
,
762 vntwusb_found1(struct usb_interface
*intf
, const struct usb_device_id
*id
)
764 BYTE fake_mac
[U_ETHER_ADDR_LEN
] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};//fake MAC address
765 struct usb_device
*udev
= interface_to_usbdev(intf
);
767 struct net_device
*netdev
= NULL
;
768 PSDevice pDevice
= NULL
;
771 printk(KERN_NOTICE
"%s Ver. %s\n",DEVICE_FULL_DRV_NAM
, DEVICE_VERSION
);
772 printk(KERN_NOTICE
"Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
774 udev
= usb_get_dev(udev
);
776 netdev
= alloc_etherdev(sizeof(DEVICE_INFO
));
778 if (netdev
== NULL
) {
779 printk(KERN_ERR DEVICE_NAME
": allocate net device failed \n");
784 pDevice
= netdev_priv(netdev
);
785 memset(pDevice
, 0, sizeof(DEVICE_INFO
));
787 pDevice
->dev
= netdev
;
790 // Set initial settings
791 device_set_options(pDevice
);
792 spin_lock_init(&pDevice
->lock
);
794 pDevice
->tx_80211
= device_dma0_tx_80211
;
795 pDevice
->sMgmtObj
.pAdapter
= (PVOID
)pDevice
;
797 netdev
->netdev_ops
= &device_netdev_ops
;
799 netdev
->wireless_handlers
= (struct iw_handler_def
*)&iwctl_handler_def
;
801 //2008-0623-01<Remark>by MikeLiu
802 //2007-0821-01<Add>by MikeLiu
803 usb_set_intfdata(intf
, pDevice
);
804 SET_NETDEV_DEV(netdev
, &intf
->dev
);
805 memcpy(pDevice
->dev
->dev_addr
, fake_mac
, U_ETHER_ADDR_LEN
); //use fake mac address
806 rc
= register_netdev(netdev
);
808 printk(KERN_ERR DEVICE_NAME
" Failed to register netdev\n");
813 //2008-0623-02<Remark>by MikeLiu
814 //2007-0821-01<Add>by MikeLiu
815 //#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
816 //usb_set_intfdata(intf, pDevice);
817 //SET_NETDEV_DEV(netdev, &intf->dev);
820 //2008-07-21-01<Add>by MikeLiu
823 if(wpa_set_wpadev(pDevice
, 1)!=0) {
824 printk("Fail to Register WPADEV?\n");
825 unregister_netdev(pDevice
->dev
);
830 usb_device_reset(pDevice
);
834 union iwreq_data wrqu
;
835 memset(&wrqu
, 0, sizeof(wrqu
));
836 wrqu
.data
.flags
= RT_INSMOD_EVENT_FLAG
;
837 wrqu
.data
.length
=IFNAMSIZ
;
838 wireless_send_event(pDevice
->dev
, IWEVCUSTOM
, &wrqu
, pDevice
->dev
->name
);
846 //2008-0922-01<Add>by MikeLiu, decrease usb counter.
853 static VOID
device_free_tx_bufs(PSDevice pDevice
) {
854 PUSB_SEND_CONTEXT pTxContext
;
857 for (ii
= 0; ii
< pDevice
->cbTD
; ii
++) {
859 pTxContext
= pDevice
->apTD
[ii
];
861 if (pTxContext
->pUrb
) {
862 usb_kill_urb(pTxContext
->pUrb
);
863 usb_free_urb(pTxContext
->pUrb
);
872 static VOID
device_free_rx_bufs(PSDevice pDevice
) {
876 for (ii
= 0; ii
< pDevice
->cbRD
; ii
++) {
878 pRCB
= pDevice
->apRCB
[ii
];
881 usb_kill_urb(pRCB
->pUrb
);
882 usb_free_urb(pRCB
->pUrb
);
886 dev_kfree_skb(pRCB
->skb
);
888 if (pDevice
->pRCBMem
)
889 kfree(pDevice
->pRCBMem
);
894 //2007-1107-02<Add>by MikeLiu
895 static void usb_device_reset(PSDevice pDevice
)
898 status
= usb_reset_device(pDevice
->usb
);
900 printk("usb_device_reset fail status=%d\n",status
);
904 static VOID
device_free_int_bufs(PSDevice pDevice
) {
906 if (pDevice
->intBuf
.pDataBuf
!= NULL
)
907 kfree(pDevice
->intBuf
.pDataBuf
);
912 static BOOL
device_alloc_bufs(PSDevice pDevice
) {
914 PUSB_SEND_CONTEXT pTxContext
;
919 for (ii
= 0; ii
< pDevice
->cbTD
; ii
++) {
921 pTxContext
= kmalloc(sizeof(USB_SEND_CONTEXT
), GFP_KERNEL
);
922 if (pTxContext
== NULL
) {
923 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s : allocate tx usb context failed\n", pDevice
->dev
->name
);
926 pDevice
->apTD
[ii
] = pTxContext
;
927 pTxContext
->pDevice
= (PVOID
) pDevice
;
929 pTxContext
->pUrb
= usb_alloc_urb(0, GFP_ATOMIC
);
930 if (pTxContext
->pUrb
== NULL
) {
931 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"alloc tx urb failed\n");
934 pTxContext
->bBoolInUse
= FALSE
;
938 pDevice
->pRCBMem
= kmalloc((sizeof(RCB
) * pDevice
->cbRD
), GFP_KERNEL
);
939 if (pDevice
->pRCBMem
== NULL
) {
940 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s : alloc rx usb context failed\n", pDevice
->dev
->name
);
945 pDevice
->FirstRecvFreeList
= NULL
;
946 pDevice
->LastRecvFreeList
= NULL
;
947 pDevice
->FirstRecvMngList
= NULL
;
948 pDevice
->LastRecvMngList
= NULL
;
949 pDevice
->NumRecvFreeList
= 0;
950 memset(pDevice
->pRCBMem
, 0, (sizeof(RCB
) * pDevice
->cbRD
));
951 pRCB
= (PRCB
) pDevice
->pRCBMem
;
953 for (ii
= 0; ii
< pDevice
->cbRD
; ii
++) {
955 pDevice
->apRCB
[ii
] = pRCB
;
956 pRCB
->pDevice
= (PVOID
) pDevice
;
958 pRCB
->pUrb
= usb_alloc_urb(0, GFP_ATOMIC
);
960 if (pRCB
->pUrb
== NULL
) {
961 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
" Failed to alloc rx urb\n");
964 pRCB
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
965 if (pRCB
->skb
== NULL
) {
966 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
" Failed to alloc rx skb\n");
969 pRCB
->skb
->dev
= pDevice
->dev
;
970 pRCB
->bBoolInUse
= FALSE
;
971 EnqueueRCB(pDevice
->FirstRecvFreeList
, pDevice
->LastRecvFreeList
, pRCB
);
972 pDevice
->NumRecvFreeList
++;
977 pDevice
->pControlURB
= usb_alloc_urb(0, GFP_ATOMIC
);
978 if (pDevice
->pControlURB
== NULL
) {
979 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"Failed to alloc control urb\n");
983 pDevice
->pInterruptURB
= usb_alloc_urb(0, GFP_ATOMIC
);
984 if (pDevice
->pInterruptURB
== NULL
) {
985 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"Failed to alloc int urb\n");
986 usb_kill_urb(pDevice
->pControlURB
);
987 usb_free_urb(pDevice
->pControlURB
);
991 pDevice
->intBuf
.pDataBuf
= kmalloc(MAX_INTERRUPT_SIZE
, GFP_KERNEL
);
992 if (pDevice
->intBuf
.pDataBuf
== NULL
) {
993 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"Failed to alloc int buf\n");
994 usb_kill_urb(pDevice
->pControlURB
);
995 usb_kill_urb(pDevice
->pInterruptURB
);
996 usb_free_urb(pDevice
->pControlURB
);
997 usb_free_urb(pDevice
->pInterruptURB
);
1004 device_free_rx_bufs(pDevice
);
1007 device_free_tx_bufs(pDevice
);
1015 static BOOL
device_init_defrag_cb(PSDevice pDevice
) {
1017 PSDeFragControlBlock pDeF
;
1019 /* Init the fragment ctl entries */
1020 for (i
= 0; i
< CB_MAX_RX_FRAG
; i
++) {
1021 pDeF
= &(pDevice
->sRxDFCB
[i
]);
1022 if (!device_alloc_frag_buf(pDevice
, pDeF
)) {
1023 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc frag bufs\n",
1024 pDevice
->dev
->name
);
1028 pDevice
->cbDFCB
= CB_MAX_RX_FRAG
;
1029 pDevice
->cbFreeDFCB
= pDevice
->cbDFCB
;
1033 device_free_frag_bufs(pDevice
);
1039 static void device_free_frag_bufs(PSDevice pDevice
) {
1040 PSDeFragControlBlock pDeF
;
1043 for (i
= 0; i
< CB_MAX_RX_FRAG
; i
++) {
1045 pDeF
= &(pDevice
->sRxDFCB
[i
]);
1048 dev_kfree_skb(pDeF
->skb
);
1054 BOOL
device_alloc_frag_buf(PSDevice pDevice
, PSDeFragControlBlock pDeF
) {
1056 pDeF
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1057 if (pDeF
->skb
== NULL
)
1060 pDeF
->skb
->dev
= pDevice
->dev
;
1066 /*-----------------------------------------------------------------*/
1068 static int device_open(struct net_device
*dev
) {
1069 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
1071 #ifdef WPA_SM_Transtatus
1072 extern SWPAResult wpa_Result
;
1073 memset(wpa_Result
.ifname
,0,sizeof(wpa_Result
.ifname
));
1074 wpa_Result
.proto
= 0;
1075 wpa_Result
.key_mgmt
= 0;
1076 wpa_Result
.eap_type
= 0;
1077 wpa_Result
.authenticated
= FALSE
;
1078 pDevice
->fWPA_Authened
= FALSE
;
1081 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" device_open...\n");
1084 pDevice
->rx_buf_sz
= MAX_TOTAL_SIZE_WITH_ALL_HEADERS
;
1086 if (device_alloc_bufs(pDevice
) == FALSE
) {
1087 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" device_alloc_bufs fail... \n");
1091 if (device_init_defrag_cb(pDevice
)== FALSE
) {
1092 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Initial defragement cb fail \n");
1096 MP_CLEAR_FLAG(pDevice
, fMP_DISCONNECTED
);
1097 MP_CLEAR_FLAG(pDevice
, fMP_CONTROL_READS
);
1098 MP_CLEAR_FLAG(pDevice
, fMP_CONTROL_WRITES
);
1099 MP_SET_FLAG(pDevice
, fMP_POST_READS
);
1100 MP_SET_FLAG(pDevice
, fMP_POST_WRITES
);
1103 Read_config_file(pDevice
);
1105 if (device_init_registers(pDevice
, DEVICE_INIT_COLD
) == FALSE
) {
1106 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" init register fail\n");
1110 device_set_multi(pDevice
->dev
);
1111 // Init for Key Management
1113 KeyvInitTable(pDevice
,&pDevice
->sKey
);
1114 memcpy(pDevice
->sMgmtObj
.abyMACAddr
, pDevice
->abyCurrentNetAddr
, U_ETHER_ADDR_LEN
);
1115 memcpy(pDevice
->dev
->dev_addr
, pDevice
->abyCurrentNetAddr
, U_ETHER_ADDR_LEN
);
1116 pDevice
->bStopTx0Pkt
= FALSE
;
1117 pDevice
->bStopDataPkt
= FALSE
;
1118 pDevice
->bRoaming
= FALSE
; //DavidWang
1119 pDevice
->bIsRoaming
= FALSE
;//DavidWang
1120 pDevice
->bEnableRoaming
= FALSE
;
1121 if (pDevice
->bDiversityRegCtlON
) {
1122 device_init_diversity_timer(pDevice
);
1125 vMgrObjectInit(pDevice
);
1126 tasklet_init(&pDevice
->RxMngWorkItem
, (void *)RXvMngWorkItem
, (unsigned long)pDevice
);
1127 tasklet_init(&pDevice
->ReadWorkItem
, (void *)RXvWorkItem
, (unsigned long)pDevice
);
1128 tasklet_init(&pDevice
->EventWorkItem
, (void *)INTvWorkItem
, (unsigned long)pDevice
);
1129 add_timer(&(pDevice
->sMgmtObj
.sTimerSecondCallback
));
1130 pDevice
->int_interval
= 100; //Max 100 microframes.
1131 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1133 pDevice
->bIsRxWorkItemQueued
= TRUE
;
1134 pDevice
->fKillEventPollingThread
= FALSE
;
1135 pDevice
->bEventAvailable
= FALSE
;
1137 pDevice
->bWPADEVUp
= FALSE
;
1138 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1139 pDevice
->bwextstep0
= FALSE
;
1140 pDevice
->bwextstep1
= FALSE
;
1141 pDevice
->bwextstep2
= FALSE
;
1142 pDevice
->bwextstep3
= FALSE
;
1143 pDevice
->bWPASuppWextEnabled
= FALSE
;
1145 pDevice
->byReAssocCount
= 0;
1147 RXvWorkItem(pDevice
);
1148 INTvWorkItem(pDevice
);
1150 // Patch: if WEP key already set by iwconfig but device not yet open
1151 if ((pDevice
->bEncryptionEnable
== TRUE
) && (pDevice
->bTransmitKey
== TRUE
)) {
1152 spin_lock_irq(&pDevice
->lock
);
1153 KeybSetDefaultKey( pDevice
,
1155 pDevice
->byKeyIndex
| (1 << 31),
1156 pDevice
->uKeyLength
,
1161 spin_unlock_irq(&pDevice
->lock
);
1162 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1165 if (pDevice
->sMgmtObj
.eConfigMode
== WMAC_CONFIG_AP
) {
1166 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_RUN_AP
, NULL
);
1169 //mike:mark@2008-11-10
1170 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
1171 //bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SSID, NULL);
1175 netif_stop_queue(pDevice
->dev
);
1176 pDevice
->flags
|= DEVICE_FLAGS_OPENED
;
1180 union iwreq_data wrqu
;
1181 memset(&wrqu
, 0, sizeof(wrqu
));
1182 wrqu
.data
.flags
= RT_UPDEV_EVENT_FLAG
;
1183 wireless_send_event(pDevice
->dev
, IWEVCUSTOM
, &wrqu
, NULL
);
1187 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_open success.. \n");
1191 device_free_frag_bufs(pDevice
);
1193 device_free_rx_bufs(pDevice
);
1194 device_free_tx_bufs(pDevice
);
1195 device_free_int_bufs(pDevice
);
1196 usb_kill_urb(pDevice
->pControlURB
);
1197 usb_kill_urb(pDevice
->pInterruptURB
);
1198 usb_free_urb(pDevice
->pControlURB
);
1199 usb_free_urb(pDevice
->pInterruptURB
);
1201 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_open fail.. \n");
1207 static int device_close(struct net_device
*dev
) {
1208 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
1209 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1213 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_close1 \n");
1214 if (pDevice
== NULL
)
1219 union iwreq_data wrqu
;
1220 memset(&wrqu
, 0, sizeof(wrqu
));
1221 wrqu
.data
.flags
= RT_DOWNDEV_EVENT_FLAG
;
1222 wireless_send_event(pDevice
->dev
, IWEVCUSTOM
, &wrqu
, NULL
);
1226 //2007-1121-02<Add>by EinsnLiu
1227 if (pDevice
->bLinkPass
) {
1228 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_DISASSOCIATE
, NULL
);
1233 //2008-0714-01<Add>by MikeLiu
1234 device_release_WPADEV(pDevice
);
1236 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
1237 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1238 pDevice
->bEncryptionEnable
= FALSE
;
1239 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1240 spin_lock_irq(&pDevice
->lock
);
1241 for(uu
=0;uu
<MAX_KEY_TABLE
;uu
++)
1242 MACvDisableKeyEntry(pDevice
,uu
);
1243 spin_unlock_irq(&pDevice
->lock
);
1245 if ((pDevice
->flags
& DEVICE_FLAGS_UNPLUG
) == FALSE
) {
1246 MACbShutdown(pDevice
);
1248 netif_stop_queue(pDevice
->dev
);
1249 MP_SET_FLAG(pDevice
, fMP_DISCONNECTED
);
1250 MP_CLEAR_FLAG(pDevice
, fMP_POST_WRITES
);
1251 MP_CLEAR_FLAG(pDevice
, fMP_POST_READS
);
1252 pDevice
->fKillEventPollingThread
= TRUE
;
1253 del_timer(&pDevice
->sTimerCommand
);
1254 del_timer(&pMgmt
->sTimerSecondCallback
);
1256 //2007-0115-02<Add>by MikeLiu
1258 del_timer(&pDevice
->sTimerTxData
);
1261 if (pDevice
->bDiversityRegCtlON
) {
1262 del_timer(&pDevice
->TimerSQ3Tmax1
);
1263 del_timer(&pDevice
->TimerSQ3Tmax2
);
1264 del_timer(&pDevice
->TimerSQ3Tmax3
);
1266 tasklet_kill(&pDevice
->RxMngWorkItem
);
1267 tasklet_kill(&pDevice
->ReadWorkItem
);
1268 tasklet_kill(&pDevice
->EventWorkItem
);
1270 pDevice
->bRoaming
= FALSE
; //DavidWang
1271 pDevice
->bIsRoaming
= FALSE
;//DavidWang
1272 pDevice
->bEnableRoaming
= FALSE
;
1273 pDevice
->bCmdRunning
= FALSE
;
1274 pDevice
->bLinkPass
= FALSE
;
1275 memset(pMgmt
->abyCurrBSSID
, 0, 6);
1276 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
1278 device_free_tx_bufs(pDevice
);
1279 device_free_rx_bufs(pDevice
);
1280 device_free_int_bufs(pDevice
);
1281 device_free_frag_bufs(pDevice
);
1283 usb_kill_urb(pDevice
->pControlURB
);
1284 usb_kill_urb(pDevice
->pInterruptURB
);
1285 usb_free_urb(pDevice
->pControlURB
);
1286 usb_free_urb(pDevice
->pInterruptURB
);
1288 BSSvClearNodeDBTable(pDevice
, 0);
1289 pDevice
->flags
&=(~DEVICE_FLAGS_OPENED
);
1291 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_close2 \n");
1297 static void vntwusb_disconnect(struct usb_interface
*intf
)
1301 PSDevice pDevice
= usb_get_intfdata(intf
);
1303 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_disconnect1.. \n");
1304 if (pDevice
== NULL
)
1309 union iwreq_data wrqu
;
1310 memset(&wrqu
, 0, sizeof(wrqu
));
1311 wrqu
.data
.flags
= RT_RMMOD_EVENT_FLAG
;
1312 wireless_send_event(pDevice
->dev
, IWEVCUSTOM
, &wrqu
, NULL
);
1316 //2008-0714-01<Add>by MikeLiu
1317 device_release_WPADEV(pDevice
);
1319 usb_set_intfdata(intf
, NULL
);
1320 //2008-0922-01<Add>by MikeLiu, decrease usb counter.
1321 usb_put_dev(interface_to_usbdev(intf
));
1323 pDevice
->flags
|= DEVICE_FLAGS_UNPLUG
;
1324 if (pDevice
->dev
!= NULL
) {
1325 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unregister_netdev..\n");
1326 unregister_netdev(pDevice
->dev
);
1328 //2008-07-21-01<Add>by MikeLiu
1330 if(wpa_set_wpadev(pDevice
, 0)!=0)
1331 printk("unregister wpadev fail?\n");
1333 free_netdev(pDevice
->dev
);
1337 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_disconnect3.. \n");
1343 static int device_dma0_tx_80211(struct sk_buff
*skb
, struct net_device
*dev
) {
1344 PSDevice pDevice
=netdev_priv(dev
);
1349 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_dma0_tx_80211\n");
1350 spin_lock_irq(&pDevice
->lock
);
1352 if (pDevice
->bStopTx0Pkt
== TRUE
) {
1353 dev_kfree_skb_irq(skb
);
1354 spin_unlock_irq(&pDevice
->lock
);
1359 cbMPDULen
= skb
->len
;
1362 vDMA0_tx_80211(pDevice
, skb
);
1364 spin_unlock_irq(&pDevice
->lock
);
1371 static int device_xmit(struct sk_buff
*skb
, struct net_device
*dev
) {
1372 PSDevice pDevice
=netdev_priv(dev
);
1373 struct net_device_stats
* pStats
= &pDevice
->stats
;
1376 spin_lock_irq(&pDevice
->lock
);
1378 netif_stop_queue(pDevice
->dev
);
1380 if (pDevice
->bLinkPass
== FALSE
) {
1381 dev_kfree_skb_irq(skb
);
1382 spin_unlock_irq(&pDevice
->lock
);
1385 if (pDevice
->bStopDataPkt
== TRUE
) {
1386 dev_kfree_skb_irq(skb
);
1387 pStats
->tx_dropped
++;
1388 spin_unlock_irq(&pDevice
->lock
);
1392 if(nsDMA_tx_packet(pDevice
, TYPE_AC0DMA
, skb
) !=0) { //mike add:xmit fail!
1393 if (netif_queue_stopped(pDevice
->dev
))
1394 netif_wake_queue(pDevice
->dev
);
1397 spin_unlock_irq(&pDevice
->lock
);
1404 static unsigned const ethernet_polynomial
= 0x04c11db7U
;
1405 static inline u32
ether_crc(int length
, unsigned char *data
)
1409 while(--length
>= 0) {
1410 unsigned char current_octet
= *data
++;
1412 for (bit
= 0; bit
< 8; bit
++, current_octet
>>= 1) {
1414 ((crc
< 0) ^ (current_octet
& 1) ? ethernet_polynomial
: 0);
1420 //find out the start position of str2 from str1
1421 static UCHAR
*kstrstr(const UCHAR
*str1
,const UCHAR
*str2
) {
1422 int str1_len
=strlen(str1
);
1423 int str2_len
=strlen(str2
);
1425 while (str1_len
>= str2_len
) {
1427 if(memcmp(str1
,str2
,str2_len
)==0)
1428 return (UCHAR
*)str1
;
1434 static int Config_FileGetParameter(UCHAR
*string
, UCHAR
*dest
,UCHAR
*source
)
1438 UCHAR
*start_p
=NULL
,*end_p
=NULL
,*tmp_p
=NULL
;
1442 strcat(buf1
, string
);
1444 source
+=strlen(buf1
);
1446 //find target string start point
1447 if((start_p
= kstrstr(source
,buf1
))==NULL
)
1450 //check if current config line is marked by "#" ??
1452 if(memcmp(start_p
-ii
,"\n",1)==0)
1454 if(memcmp(start_p
-ii
,"#",1)==0)
1458 //find target string end point
1459 if((end_p
= kstrstr(start_p
,"\n"))==NULL
) { //cann't find "\n",but don't care
1460 end_p
=start_p
+strlen(start_p
); //no include "\n"
1464 memcpy(buf2
,start_p
,end_p
-start_p
); //get the tartget line
1465 buf2
[end_p
-start_p
]='\0';
1468 if((start_p
= kstrstr(buf2
,"="))==NULL
)
1471 strcpy(buf1
,start_p
+1);
1475 while(*tmp_p
!= 0x00) {
1482 memcpy(dest
,tmp_p
,strlen(tmp_p
));
1486 //if read fail,return NULL,or return data pointer;
1487 static UCHAR
*Config_FileOperation(PSDevice pDevice
) {
1488 UCHAR
*config_path
=CONFIG_PATH
;
1490 struct file
*filp
=NULL
;
1491 mm_segment_t old_fs
= get_fs();
1492 //int oldfsuid=0,oldfsgid=0;
1496 /* Can't do this anymore, so we rely on correct filesystem permissions:
1497 //Make sure a caller can read or write power as root
1498 oldfsuid=current->fsuid;
1499 oldfsgid=current->fsgid;
1505 filp
= filp_open(config_path
, O_RDWR
, 0);
1507 printk("Config_FileOperation file Not exist\n");
1512 if(!(filp
->f_op
) || !(filp
->f_op
->read
) ||!(filp
->f_op
->write
)) {
1513 printk("file %s cann't readable or writable?\n",config_path
);
1518 buffer
= (UCHAR
*)kmalloc(1024, GFP_KERNEL
);
1520 printk("alllocate mem for file fail?\n");
1525 if(filp
->f_op
->read(filp
, buffer
, 1024, &filp
->f_pos
)<0) {
1526 printk("read file error?\n");
1531 if(filp_close(filp
,NULL
))
1532 printk("Config_FileOperation:close file fail\n");
1538 current->fsuid=oldfsuid;
1539 current->fsgid=oldfsgid;
1550 //return --->-1:fail; >=0:sucessful
1551 static int Read_config_file(PSDevice pDevice
) {
1553 UCHAR tmpbuffer
[100];
1556 //init config setting
1557 pDevice
->config_file
.ZoneType
= -1;
1558 pDevice
->config_file
.eAuthenMode
= -1;
1559 pDevice
->config_file
.eEncryptionStatus
= -1;
1561 if((buffer
=Config_FileOperation(pDevice
)) ==NULL
) {
1568 memset(tmpbuffer
,0,sizeof(tmpbuffer
));
1569 if(Config_FileGetParameter("ZONETYPE",tmpbuffer
,buffer
) ==TRUE
) {
1570 if(memcmp(tmpbuffer
,"USA",3)==0) {
1571 pDevice
->config_file
.ZoneType
=ZoneType_USA
;
1573 else if(memcmp(tmpbuffer
,"JAPAN",5)==0) {
1574 pDevice
->config_file
.ZoneType
=ZoneType_Japan
;
1576 else if(memcmp(tmpbuffer
,"EUROPE",6)==0) {
1577 pDevice
->config_file
.ZoneType
=ZoneType_Europe
;
1580 printk("Unknown Zonetype[%s]?\n",tmpbuffer
);
1586 //get other parameter
1588 memset(tmpbuffer
,0,sizeof(tmpbuffer
));
1589 if(Config_FileGetParameter("AUTHENMODE",tmpbuffer
,buffer
)==TRUE
) {
1590 pDevice
->config_file
.eAuthenMode
= (int) simple_strtol(tmpbuffer
, NULL
, 10);
1593 memset(tmpbuffer
,0,sizeof(tmpbuffer
));
1594 if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer
,buffer
)==TRUE
) {
1595 pDevice
->config_file
.eEncryptionStatus
= (int) simple_strtol(tmpbuffer
, NULL
, 10);
1604 static void device_set_multi(struct net_device
*dev
) {
1605 PSDevice pDevice
= (PSDevice
) netdev_priv(dev
);
1606 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1609 struct dev_mc_list
*mclist
;
1610 BYTE pbyData
[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
1615 spin_lock_irq(&pDevice
->lock
);
1616 rc
= CONTROLnsRequestIn(pDevice
,
1619 MESSAGE_REQUEST_MACREG
,
1623 if (rc
== 0) pDevice
->byRxMode
= byTmpMode
;
1625 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pDevice->byRxMode in= %x\n", pDevice
->byRxMode
);
1627 if (dev
->flags
& IFF_PROMISC
) { // Set promiscuous.
1628 DBG_PRT(MSG_LEVEL_ERR
,KERN_NOTICE
"%s: Promiscuous mode enabled.\n", dev
->name
);
1629 // Unconditionally log net taps.
1630 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
|RCR_UNICAST
);
1632 else if ((dev
->mc_count
> pDevice
->multicast_limit
) || (dev
->flags
& IFF_ALLMULTI
)) {
1633 CONTROLnsRequestOut(pDevice
,
1636 MESSAGE_REQUEST_MACREG
,
1640 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
1643 memset(mc_filter
, 0, sizeof(mc_filter
));
1644 for (ii
= 0, mclist
= dev
->mc_list
; mclist
&& ii
< dev
->mc_count
;
1645 ii
++, mclist
= mclist
->next
) {
1646 int bit_nr
= ether_crc(ETH_ALEN
, mclist
->dmi_addr
) >> 26;
1647 mc_filter
[bit_nr
>> 5] |= cpu_to_le32(1 << (bit_nr
& 31));
1649 for (ii
= 0; ii
< 4; ii
++) {
1650 MACvWriteMultiAddr(pDevice
, ii
, *((PBYTE
)&mc_filter
[0] + ii
));
1651 MACvWriteMultiAddr(pDevice
, ii
+ 4, *((PBYTE
)&mc_filter
[1] + ii
));
1653 pDevice
->byRxMode
&= ~(RCR_UNICAST
);
1654 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
1657 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
1658 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
1659 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
1660 pDevice
->byRxMode
&= ~(RCR_UNICAST
);
1662 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_MACREG
, MAC_REG_RCR
, pDevice
->byRxMode
);
1663 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pDevice->byRxMode out= %x\n", pDevice
->byRxMode
);
1664 spin_unlock_irq(&pDevice
->lock
);
1669 static struct net_device_stats
*device_get_stats(struct net_device
*dev
) {
1670 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
1672 return &pDevice
->stats
;
1676 static int device_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
) {
1677 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1678 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1680 //BOOL bCommit = FALSE;
1681 struct iwreq
*wrq
= (struct iwreq
*) rq
;
1684 if (pMgmt
== NULL
) {
1692 rc
= iwctl_giwname(dev
, NULL
, (char *)&(wrq
->u
.name
), NULL
);
1699 case SIOCGIWNWID
: //0x8b03 support
1700 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1701 rc
= iwctl_giwnwid(dev
, NULL
, &(wrq
->u
.nwid
), NULL
);
1707 // Set frequency/channel
1709 rc
= iwctl_siwfreq(dev
, NULL
, &(wrq
->u
.freq
), NULL
);
1712 // Get frequency/channel
1714 rc
= iwctl_giwfreq(dev
, NULL
, &(wrq
->u
.freq
), NULL
);
1717 // Set desired network name (ESSID)
1721 char essid
[IW_ESSID_MAX_SIZE
+1];
1722 if (wrq
->u
.essid
.length
> IW_ESSID_MAX_SIZE
) {
1726 if (copy_from_user(essid
, wrq
->u
.essid
.pointer
,
1727 wrq
->u
.essid
.length
)) {
1731 rc
= iwctl_siwessid(dev
, NULL
,
1732 &(wrq
->u
.essid
), essid
);
1737 // Get current network name (ESSID)
1741 char essid
[IW_ESSID_MAX_SIZE
+1];
1742 if (wrq
->u
.essid
.pointer
)
1743 rc
= iwctl_giwessid(dev
, NULL
,
1744 &(wrq
->u
.essid
), essid
);
1745 if (copy_to_user(wrq
->u
.essid
.pointer
,
1747 wrq
->u
.essid
.length
) )
1754 rc
= iwctl_siwap(dev
, NULL
, &(wrq
->u
.ap_addr
), NULL
);
1758 // Get current Access Point (BSSID)
1760 rc
= iwctl_giwap(dev
, NULL
, &(wrq
->u
.ap_addr
), NULL
);
1764 // Set desired station name
1766 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWNICKN \n");
1770 // Get current station name
1772 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWNICKN \n");
1776 // Set the desired bit-rate
1778 rc
= iwctl_siwrate(dev
, NULL
, &(wrq
->u
.bitrate
), NULL
);
1781 // Get the current bit-rate
1784 rc
= iwctl_giwrate(dev
, NULL
, &(wrq
->u
.bitrate
), NULL
);
1787 // Set the desired RTS threshold
1790 rc
= iwctl_siwrts(dev
, NULL
, &(wrq
->u
.rts
), NULL
);
1793 // Get the current RTS threshold
1796 rc
= iwctl_giwrts(dev
, NULL
, &(wrq
->u
.rts
), NULL
);
1799 // Set the desired fragmentation threshold
1802 rc
= iwctl_siwfrag(dev
, NULL
, &(wrq
->u
.frag
), NULL
);
1805 // Get the current fragmentation threshold
1808 rc
= iwctl_giwfrag(dev
, NULL
, &(wrq
->u
.frag
), NULL
);
1811 // Set mode of operation
1813 rc
= iwctl_siwmode(dev
, NULL
, &(wrq
->u
.mode
), NULL
);
1816 // Get mode of operation
1818 rc
= iwctl_giwmode(dev
, NULL
, &(wrq
->u
.mode
), NULL
);
1821 // Set WEP keys and mode
1824 char abyKey
[WLAN_WEP232_KEYLEN
];
1826 if (wrq
->u
.encoding
.pointer
) {
1829 if (wrq
->u
.encoding
.length
> WLAN_WEP232_KEYLEN
) {
1833 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
1834 if (copy_from_user(abyKey
,
1835 wrq
->u
.encoding
.pointer
,
1836 wrq
->u
.encoding
.length
)) {
1840 } else if (wrq
->u
.encoding
.length
!= 0) {
1844 rc
= iwctl_siwencode(dev
, NULL
, &(wrq
->u
.encoding
), abyKey
);
1848 // Get the WEP keys and mode
1851 if (!capable(CAP_NET_ADMIN
)) {
1856 char abyKey
[WLAN_WEP232_KEYLEN
];
1858 rc
= iwctl_giwencode(dev
, NULL
, &(wrq
->u
.encoding
), abyKey
);
1860 if (wrq
->u
.encoding
.pointer
) {
1861 if (copy_to_user(wrq
->u
.encoding
.pointer
,
1863 wrq
->u
.encoding
.length
))
1869 // Get the current Tx-Power
1871 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWTXPOW \n");
1876 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWTXPOW \n");
1882 rc
= iwctl_siwretry(dev
, NULL
, &(wrq
->u
.retry
), NULL
);
1887 rc
= iwctl_giwretry(dev
, NULL
, &(wrq
->u
.retry
), NULL
);
1890 // Get range of parameters
1894 struct iw_range range
;
1896 rc
= iwctl_giwrange(dev
, NULL
, &(wrq
->u
.data
), (char *) &range
);
1897 if (copy_to_user(wrq
->u
.data
.pointer
, &range
, sizeof(struct iw_range
)))
1905 rc
= iwctl_giwpower(dev
, NULL
, &(wrq
->u
.power
), NULL
);
1911 rc
= iwctl_siwpower(dev
, NULL
, &(wrq
->u
.power
), NULL
);
1917 rc
= iwctl_giwsens(dev
, NULL
, &(wrq
->u
.sens
), NULL
);
1921 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSENS \n");
1927 char buffer
[IW_MAX_AP
* (sizeof(struct sockaddr
) + sizeof(struct iw_quality
))];
1929 if (wrq
->u
.data
.pointer
) {
1930 rc
= iwctl_giwaplist(dev
, NULL
, &(wrq
->u
.data
), buffer
);
1932 if (copy_to_user(wrq
->u
.data
.pointer
,
1934 (wrq
->u
.data
.length
* (sizeof(struct sockaddr
) + sizeof(struct iw_quality
)))
1947 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSPY \n");
1954 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSPY \n");
1958 #endif // WIRELESS_SPY
1961 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPRIV \n");
1964 if(wrq->u.data.pointer) {
1965 wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
1967 if(copy_to_user(wrq->u.data.pointer,
1968 (u_char *) iwctl_private_args,
1969 sizeof(iwctl_private_args)))
1976 //2008-0409-07, <Add> by Einsn Liu
1977 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1979 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH \n");
1980 rc
= iwctl_siwauth(dev
, NULL
, &(wrq
->u
.param
), NULL
);
1984 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAUTH \n");
1985 rc
= iwctl_giwauth(dev
, NULL
, &(wrq
->u
.param
), NULL
);
1989 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWGENIE \n");
1990 rc
= iwctl_siwgenie(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
1994 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWGENIE \n");
1995 rc
= iwctl_giwgenie(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
1998 case SIOCSIWENCODEEXT
:
2000 char extra
[sizeof(struct iw_encode_ext
)+MAX_KEY_LEN
+1];
2001 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODEEXT \n");
2002 if(wrq
->u
.encoding
.pointer
){
2003 memset(extra
, 0, sizeof(struct iw_encode_ext
)+MAX_KEY_LEN
+1);
2004 if(wrq
->u
.encoding
.length
> (sizeof(struct iw_encode_ext
)+ MAX_KEY_LEN
)){
2008 if(copy_from_user(extra
, wrq
->u
.encoding
.pointer
,wrq
->u
.encoding
.length
)){
2012 }else if(wrq
->u
.encoding
.length
!= 0){
2016 rc
= iwctl_siwencodeext(dev
, NULL
, &(wrq
->u
.encoding
), extra
);
2020 case SIOCGIWENCODEEXT
:
2021 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODEEXT \n");
2022 rc
= iwctl_giwencodeext(dev
, NULL
, &(wrq
->u
.encoding
), NULL
);
2026 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMLME \n");
2027 rc
= iwctl_siwmlme(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
2030 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2031 //End Add -- //2008-0409-07, <Add> by Einsn Liu
2033 case IOCTL_CMD_TEST
:
2035 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
2041 pReq
= (PSCmdRequest
)rq
;
2043 //20080130-01,<Remark> by Mike Liu
2044 // if(pDevice->bLinkPass==TRUE)
2045 pReq
->wResult
= MAGIC_CODE
; //Linking status:0x3142
2046 //20080130-02,<Remark> by Mike Liu
2048 // pReq->wResult = MAGIC_CODE+1; //disconnect status:0x3143
2052 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
) &&
2053 (((PSCmdRequest
)rq
)->wCmdCode
!=WLAN_CMD_SET_WPA
))
2061 if (test_and_set_bit( 0, (void*)&(pMgmt
->uCmdBusy
))) {
2064 rc
= private_ioctl(pDevice
, rq
);
2065 clear_bit( 0, (void*)&(pMgmt
->uCmdBusy
));
2068 case IOCTL_CMD_HOSTAPD
:
2070 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
2077 rc
= hostap_ioctl(pDevice
, &wrq
->u
.data
);
2082 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
2089 rc
= wpa_ioctl(pDevice
, &wrq
->u
.data
);
2093 return ethtool_ioctl(dev
, (void *) rq
->ifr_data
);
2094 // All other calls are currently unsupported
2098 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Ioctl command not support..%x\n", cmd
);
2103 if (pDevice
->bCommit
) {
2104 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
2105 netif_stop_queue(pDevice
->dev
);
2106 spin_lock_irq(&pDevice
->lock
);
2107 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_RUN_AP
, NULL
);
2108 spin_unlock_irq(&pDevice
->lock
);
2111 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Commit the settings\n");
2112 spin_lock_irq(&pDevice
->lock
);
2113 //2007-1121-01<Modify>by EinsnLiu
2114 if (pDevice
->bLinkPass
&&
2115 memcmp(pMgmt
->abyCurrSSID
,pMgmt
->abyDesireSSID
,WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
)) {
2116 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_DISASSOCIATE
, NULL
);
2118 pDevice
->bLinkPass
= FALSE
;
2119 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
2120 memset(pMgmt
->abyCurrBSSID
, 0, 6);
2122 ControlvMaskByte(pDevice
,MESSAGE_REQUEST_MACREG
,MAC_REG_PAPEDELAY
,LEDSTS_STS
,LEDSTS_SLOW
);
2124 netif_stop_queue(pDevice
->dev
);
2125 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2126 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
2127 if(pDevice
->bWPASuppWextEnabled
!=TRUE
)
2129 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_BSSID_SCAN
, pMgmt
->abyDesireSSID
);
2130 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_SSID
, NULL
);
2131 spin_unlock_irq(&pDevice
->lock
);
2133 pDevice
->bCommit
= FALSE
;
2141 static int ethtool_ioctl(struct net_device
*dev
, void *useraddr
)
2145 if (copy_from_user(ðcmd
, useraddr
, sizeof(ethcmd
)))
2149 case ETHTOOL_GDRVINFO
: {
2150 struct ethtool_drvinfo info
= {ETHTOOL_GDRVINFO
};
2151 strncpy(info
.driver
, DEVICE_NAME
, sizeof(info
.driver
)-1);
2152 strncpy(info
.version
, DEVICE_VERSION
, sizeof(info
.version
)-1);
2153 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
2164 /*------------------------------------------------------------------*/
2167 MODULE_DEVICE_TABLE(usb
, vntwusb_table
);
2170 static struct usb_driver vntwusb_driver
= {
2171 .name
= DEVICE_NAME
,
2172 .probe
= vntwusb_found1
,
2173 .disconnect
= vntwusb_disconnect
,
2174 .id_table
= vntwusb_table
,
2176 //2008-0920-01<Add>by MikeLiu
2177 //for supporting S3 & S4 function
2179 .suspend
= vntwusb_suspend
,
2180 .resume
= vntwusb_resume
,
2184 static int __init
vntwusb_init_module(void)
2186 printk(KERN_NOTICE DEVICE_FULL_DRV_NAM
" " DEVICE_VERSION
);
2187 return usb_register(&vntwusb_driver
);
2190 static void __exit
vntwusb_cleanup_module(void)
2192 usb_deregister(&vntwusb_driver
);
2195 module_init(vntwusb_init_module
);
2196 module_exit(vntwusb_cleanup_module
);