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
78 /*--------------------- Static Definitions -------------------------*/
79 //static int msglevel =MSG_LEVEL_DEBUG;
80 static int msglevel
=MSG_LEVEL_INFO
;
83 // Define module options
86 // Version Information
87 #define DRIVER_AUTHOR "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
88 MODULE_AUTHOR(DRIVER_AUTHOR
);
89 MODULE_LICENSE("GPL");
90 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM
);
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);
97 #define RX_DESC_MIN0 16
98 #define RX_DESC_MAX0 128
99 #define RX_DESC_DEF0 64
100 DEVICE_PARAM(RxDescriptors0
,"Number of receive usb desc buffer");
103 #define TX_DESC_MIN0 16
104 #define TX_DESC_MAX0 128
105 #define TX_DESC_DEF0 64
106 DEVICE_PARAM(TxDescriptors0
,"Number of transmit usb desc buffer");
109 #define CHANNEL_MIN 1
110 #define CHANNEL_MAX 14
111 #define CHANNEL_DEF 6
113 DEVICE_PARAM(Channel
, "Channel number");
116 /* PreambleType[] is the preamble length used for transmit.
117 0: indicate allows long preamble type
118 1: indicate allows short preamble type
121 #define PREAMBLE_TYPE_DEF 1
123 DEVICE_PARAM(PreambleType
, "Preamble Type");
126 #define RTS_THRESH_MIN 512
127 #define RTS_THRESH_MAX 2347
128 #define RTS_THRESH_DEF 2347
130 DEVICE_PARAM(RTSThreshold
, "RTS threshold");
133 #define FRAG_THRESH_MIN 256
134 #define FRAG_THRESH_MAX 2346
135 #define FRAG_THRESH_DEF 2346
137 DEVICE_PARAM(FragThreshold
, "Fragmentation threshold");
140 #define DATA_RATE_MIN 0
141 #define DATA_RATE_MAX 13
142 #define DATA_RATE_DEF 13
144 0: indicate 1 Mbps 0x02
145 1: indicate 2 Mbps 0x04
146 2: indicate 5.5 Mbps 0x0B
147 3: indicate 11 Mbps 0x16
148 4: indicate 6 Mbps 0x0c
149 5: indicate 9 Mbps 0x12
150 6: indicate 12 Mbps 0x18
151 7: indicate 18 Mbps 0x24
152 8: indicate 24 Mbps 0x30
153 9: indicate 36 Mbps 0x48
154 10: indicate 48 Mbps 0x60
155 11: indicate 54 Mbps 0x6c
156 12: indicate 72 Mbps 0x90
157 13: indicate auto rate
160 DEVICE_PARAM(ConnectionRate
, "Connection data rate");
162 #define OP_MODE_MAX 2
163 #define OP_MODE_DEF 0
164 #define OP_MODE_MIN 0
166 DEVICE_PARAM(OPMode
, "Infrastruct, adhoc, AP mode ");
168 /* OpMode[] is used for transmit.
169 0: indicate infrastruct mode used
170 1: indicate adhoc mode used
171 2: indicate AP mode used
176 0: indicate disable power saving mode
177 1: indicate enable power saving mode
180 #define PS_MODE_DEF 0
182 DEVICE_PARAM(PSMode
, "Power saving mode");
185 #define SHORT_RETRY_MIN 0
186 #define SHORT_RETRY_MAX 31
187 #define SHORT_RETRY_DEF 8
190 DEVICE_PARAM(ShortRetryLimit
, "Short frame retry limits");
192 #define LONG_RETRY_MIN 0
193 #define LONG_RETRY_MAX 15
194 #define LONG_RETRY_DEF 4
197 DEVICE_PARAM(LongRetryLimit
, "long frame retry limits");
200 /* BasebandType[] baseband type selected
201 0: indicate 802.11a type
202 1: indicate 802.11b type
203 2: indicate 802.11g type
205 #define BBP_TYPE_MIN 0
206 #define BBP_TYPE_MAX 2
207 #define BBP_TYPE_DEF 2
209 DEVICE_PARAM(BasebandType
, "baseband type");
214 0: indicate disable 802.11h
215 1: indicate enable 802.11h
218 #define X80211h_MODE_DEF 0
220 DEVICE_PARAM(b80211hEnable
, "802.11h mode");
224 // Static vars definitions
229 static struct usb_device_id vntwusb_table
[] = {
230 {USB_DEVICE(VNT_USB_VENDOR_ID
, VNT_USB_PRODUCT_ID
)},
236 // Frequency list (map channels to frequencies)
238 static const long frequency_list[] = {
239 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
240 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
241 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
242 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
243 5700, 5745, 5765, 5785, 5805, 5825
247 #ifndef IW_ENCODE_NOKEY
248 #define IW_ENCODE_NOKEY 0x0800
249 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
252 static const struct iw_handler_def iwctl_handler_def;
257 /*--------------------- Static Functions --------------------------*/
258 static int vntwusb_found1(struct usb_interface
*intf
, const struct usb_device_id
*id
);
259 static void vntwusb_disconnect(struct usb_interface
*intf
);
260 #ifdef CONFIG_PM /* Minimal support for suspend and resume */
261 static int vntwusb_suspend(struct usb_interface
*intf
, pm_message_t message
);
262 static int vntwusb_resume(struct usb_interface
*intf
);
264 static struct net_device_stats
*device_get_stats(struct net_device
*dev
);
265 static int device_open(struct net_device
*dev
);
266 static int device_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
267 static void device_set_multi(struct net_device
*dev
);
268 static int device_close(struct net_device
*dev
);
269 static int device_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
271 static BOOL
device_init_registers(PSDevice pDevice
, DEVICE_INIT_TYPE InitType
);
272 static BOOL
device_init_defrag_cb(PSDevice pDevice
);
273 static void device_init_diversity_timer(PSDevice pDevice
);
274 static int device_dma0_tx_80211(struct sk_buff
*skb
, struct net_device
*dev
);
276 static int ethtool_ioctl(struct net_device
*dev
, void *useraddr
);
277 static void device_free_tx_bufs(PSDevice pDevice
);
278 static void device_free_rx_bufs(PSDevice pDevice
);
279 static void device_free_int_bufs(PSDevice pDevice
);
280 static void device_free_frag_bufs(PSDevice pDevice
);
281 static BOOL
device_alloc_bufs(PSDevice pDevice
);
283 static int Read_config_file(PSDevice pDevice
);
284 static UCHAR
*Config_FileOperation(PSDevice pDevice
);
285 static int Config_FileGetParameter(UCHAR
*string
, UCHAR
*dest
,UCHAR
*source
);
287 //2008-0714<Add>by Mike Liu
288 static BOOL
device_release_WPADEV(PSDevice pDevice
);
290 static void usb_device_reset(PSDevice pDevice
);
294 /*--------------------- Export Variables --------------------------*/
296 /*--------------------- Export Functions --------------------------*/
300 device_set_options(PSDevice pDevice
) {
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};
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
);
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 // pDevice->bDiversityRegCtlON = TRUE;
335 pDevice
->bDiversityRegCtlON
= FALSE
;
339 static VOID
device_init_diversity_timer(PSDevice pDevice
) {
341 init_timer(&pDevice
->TimerSQ3Tmax1
);
342 pDevice
->TimerSQ3Tmax1
.data
= (ULONG
)pDevice
;
343 pDevice
->TimerSQ3Tmax1
.function
= (TimerFunction
)TimerSQ3CallBack
;
344 pDevice
->TimerSQ3Tmax1
.expires
= RUN_AT(HZ
);
346 init_timer(&pDevice
->TimerSQ3Tmax2
);
347 pDevice
->TimerSQ3Tmax2
.data
= (ULONG
)pDevice
;
348 pDevice
->TimerSQ3Tmax2
.function
= (TimerFunction
)TimerSQ3CallBack
;
349 pDevice
->TimerSQ3Tmax2
.expires
= RUN_AT(HZ
);
351 init_timer(&pDevice
->TimerSQ3Tmax3
);
352 pDevice
->TimerSQ3Tmax3
.data
= (ULONG
)pDevice
;
353 pDevice
->TimerSQ3Tmax3
.function
= (TimerFunction
)TimerSQ3Tmax3CallBack
;
354 pDevice
->TimerSQ3Tmax3
.expires
= RUN_AT(HZ
);
361 // Initialiation of MAC & BBP registers
364 static BOOL
device_init_registers(PSDevice pDevice
, DEVICE_INIT_TYPE InitType
)
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};
371 CMD_CARD_INIT sInitCmd
;
372 NTSTATUS ntStatus
= STATUS_SUCCESS
;
373 RSP_CARD_INIT sInitRsp
;
374 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
376 BYTE byCalibTXIQ
= 0;
377 BYTE byCalibTXDC
= 0;
378 BYTE byCalibRXIQ
= 0;
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
);
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
);
396 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" FIRMWAREbDownload fail \n");
397 spin_unlock_irq(&pDevice
->lock
);
402 if ( !BBbVT3184Init(pDevice
) ) {
403 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" BBbVT3184Init fail \n");
404 spin_unlock_irq(&pDevice
->lock
);
409 sInitCmd
.byInitClass
= (BYTE
)InitType
;
410 sInitCmd
.bExistSWNetAddr
= (BYTE
) pDevice
->bExistSWNetAddr
;
412 sInitCmd
.bySWNetAddr
[ii
] = pDevice
->abyCurrentNetAddr
[ii
];
413 sInitCmd
.byShortRetryLimit
= pDevice
->byShortRetryLimit
;
414 sInitCmd
.byLongRetryLimit
= pDevice
->byLongRetryLimit
;
416 //issue Card_init command to device
417 ntStatus
= CONTROLnsRequestOut(pDevice
,
418 MESSAGE_TYPE_CARDINIT
,
421 sizeof(CMD_CARD_INIT
),
422 (PBYTE
) &(sInitCmd
));
424 if ( ntStatus
!= STATUS_SUCCESS
) {
425 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Issue Card init fail \n");
426 spin_unlock_irq(&pDevice
->lock
);
429 if (InitType
== DEVICE_INIT_COLD
) {
431 ntStatus
= CONTROLnsRequestIn(pDevice
,MESSAGE_TYPE_INIT_RSP
,0,0,sizeof(RSP_CARD_INIT
), (PBYTE
) &(sInitRsp
));
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
);
439 //Local ID for AES functions
440 ntStatus
= CONTROLnsRequestIn(pDevice
,
443 MESSAGE_REQUEST_MACREG
,
445 &pDevice
->byLocalID
);
447 if ( ntStatus
!= STATUS_SUCCESS
) {
448 spin_unlock_irq(&pDevice
->lock
);
452 // Do MACbSoftwareReset in MACvInitialize
454 pDevice
->bCCK
= TRUE
;
455 pDevice
->bProtectMode
= FALSE
; //Only used in 11g type, sync with ERP IE
456 pDevice
->bNonERPPresent
= FALSE
;
457 pDevice
->bBarkerPreambleMd
= FALSE
;
458 if ( pDevice
->bFixRate
) {
459 pDevice
->wCurrentRate
= (WORD
) pDevice
->uConnectionRate
;
461 if ( pDevice
->byBBType
== BB_TYPE_11B
)
462 pDevice
->wCurrentRate
= RATE_11M
;
464 pDevice
->wCurrentRate
= RATE_54M
;
467 CHvInitChannelTable(pDevice
);
469 pDevice
->byTopOFDMBasicRate
= RATE_24M
;
470 pDevice
->byTopCCKBasicRate
= RATE_1M
;
471 pDevice
->byRevId
= 0; //Target to IF pin while programming to RF chip.
472 pDevice
->byCurPwr
= 0xFF;
474 pDevice
->byCCKPwr
= pDevice
->abyEEPROM
[EEP_OFS_PWR_CCK
];
475 pDevice
->byOFDMPwrG
= pDevice
->abyEEPROM
[EEP_OFS_PWR_OFDMG
];
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
;
486 //original zonetype is USA,but customize zonetype is europe,
487 // then need recover 12,13 ,14 channel with 11 channel
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];
497 //{{ RobertYu: 20041124
498 pDevice
->byOFDMPwrA
= 0x34; // same as RFbMA2829SelectChannel
499 // Load OFDM A Power Table
500 for (ii
=0;ii
<CB_MAX_CHANNEL_5G
;ii
++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
501 pDevice
->abyOFDMAPwrTbl
[ii
] = pDevice
->abyEEPROM
[ii
+ EEP_OFS_OFDMA_PWR_TBL
];
502 if (pDevice
->abyOFDMAPwrTbl
[ii
] == 0)
503 pDevice
->abyOFDMAPwrTbl
[ii
] = pDevice
->byOFDMPwrA
;
507 byAntenna
= pDevice
->abyEEPROM
[EEP_OFS_ANTENNA
];
508 if (byAntenna
& EEP_ANTINV
)
509 pDevice
->bTxRxAntInv
= TRUE
;
511 pDevice
->bTxRxAntInv
= FALSE
;
513 byAntenna
&= (EEP_ANTENNA_AUX
| EEP_ANTENNA_MAIN
);
515 if (byAntenna
== 0) // if not set default is All
516 byAntenna
= (EEP_ANTENNA_AUX
| EEP_ANTENNA_MAIN
);
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
;
526 pDevice
->byRxAntennaMode
= ANT_B
;
528 if (pDevice
->bDiversityRegCtlON
)
529 pDevice
->bDiversityEnable
= TRUE
;
531 pDevice
->bDiversityEnable
= FALSE
;
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
;
542 pDevice
->byRxAntennaMode
= ANT_A
;
544 pDevice
->byTxAntennaMode
= ANT_B
;
545 if (pDevice
->bTxRxAntInv
== TRUE
)
546 pDevice
->byRxAntennaMode
= ANT_A
;
548 pDevice
->byRxAntennaMode
= ANT_B
;
551 pDevice
->ulDiversityNValue
= 100*255;
552 pDevice
->ulDiversityMValue
= 100*16;
554 pDevice
->byTMax2
= 4;
555 pDevice
->ulSQ3TH
= 0;
556 pDevice
->byTMax3
= 64;
557 // -----------------------------------------------------------------
559 //Get Auto Fall Back Type
560 pDevice
->byAutoFBCtrl
= AUTO_FB_0
;
563 pDevice
->uScanTime
= WLAN_SCAN_MINITIME
;
566 //pDevice->NetworkType = Ndis802_11Automode;
567 pDevice
->eConfigPHYMode
= PHY_TYPE_AUTO
;
568 pDevice
->byBBType
= BB_TYPE_11G
;
570 // initialize BBP registers
571 pDevice
->ulTxPower
= 25;
574 pDevice
->byMinChannel
= 1;
575 pDevice
->byMaxChannel
= CB_MAX_CHANNEL
;
578 pDevice
->byRFType
= sInitRsp
.byRFType
;
580 if ((pDevice
->byRFType
& RF_EMU
) != 0) {
581 // force change RevID for VT3253 emu
582 pDevice
->byRevId
= 0x80;
585 // Load EEPROM calibrated vt3266 parameters
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); // CR255, Set BB to support TX/RX IQ and DC compensation Mode
594 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_BBREG
, 0xFB, byCalibTXIQ
); // CR251, TX I/Q Imbalance Calibration
595 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_BBREG
, 0xFC, byCalibTXDC
); // CR252, TX DC-Offset Calibration
596 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_BBREG
, 0xFD, byCalibRXIQ
); // CR253, RX I/Q Imbalance Calibration
598 // turn off BB Calibration compensation
599 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_BBREG
, 0xFF, 0x0); // CR255
603 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
604 pMgmt
->uCurrChannel
= pDevice
->uChannel
;
605 pMgmt
->uIBSSChannel
= pDevice
->uChannel
;
606 CARDbSetMediaChannel(pDevice
, pMgmt
->uCurrChannel
);
608 // get Permanent network address
609 memcpy(pDevice
->abyPermanentNetAddr
,&(sInitRsp
.byNetAddr
[0]),6);
610 memcpy(pDevice
->abyCurrentNetAddr
, pDevice
->abyPermanentNetAddr
, U_ETHER_ADDR_LEN
);
612 // if exist SW network address, use SW network address.
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]);
625 // Set BB and packet type at the same time.
626 // Set Short Slot Time, xIFS, and RSPINF.
627 if (pDevice
->byBBType
== BB_TYPE_11A
) {
628 CARDbAddBasicRate(pDevice
, RATE_6M
);
629 pDevice
->bShortSlotTime
= TRUE
;
631 CARDbAddBasicRate(pDevice
, RATE_1M
);
632 pDevice
->bShortSlotTime
= FALSE
;
634 BBvSetShortSlotTime(pDevice
);
635 CARDvSetBSSMode(pDevice
);
637 if (pDevice
->bUpdateBBVGA
) {
638 pDevice
->byBBVGACurrent
= pDevice
->abyBBVGA
[0];
639 pDevice
->byBBVGANew
= pDevice
->byBBVGACurrent
;
640 BBvSetVGAGainOffset(pDevice
, pDevice
->abyBBVGA
[0]);
643 pDevice
->byRadioCtl
= pDevice
->abyEEPROM
[EEP_OFS_RADIOCTL
];
644 pDevice
->bHWRadioOff
= FALSE
;
645 if ( (pDevice
->byRadioCtl
& EEP_RADIOCTL_ENABLE
) != 0 ) {
646 ntStatus
= CONTROLnsRequestIn(pDevice
,
649 MESSAGE_REQUEST_MACREG
,
653 if ( ntStatus
!= STATUS_SUCCESS
) {
654 spin_unlock_irq(&pDevice
->lock
);
657 if ( (byTmp
& GPIO3_DATA
) == 0 ) {
658 pDevice
->bHWRadioOff
= TRUE
;
659 MACvRegBitsOn(pDevice
,MAC_REG_GPIOCTL1
,GPIO3_INTMD
);
661 MACvRegBitsOff(pDevice
,MAC_REG_GPIOCTL1
,GPIO3_INTMD
);
662 pDevice
->bHWRadioOff
= FALSE
;
665 } //EEP_RADIOCTL_ENABLE
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);
671 if ((pDevice
->bHWRadioOff
== TRUE
) || (pDevice
->bRadioControlOff
== TRUE
)) {
672 CARDbRadioPowerOff(pDevice
);
674 CARDbRadioPowerOn(pDevice
);
677 spin_unlock_irq(&pDevice
->lock
);
678 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"<----INIbInitAdapter Exit\n");
682 static BOOL
device_release_WPADEV(PSDevice pDevice
)
684 viawget_wpa_header
*wpahdr
;
686 // wait_queue_head_t Set_wait;
687 //send device close to wpa_supplicnat layer
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
);
702 //wait release WPADEV
703 // init_waitqueue_head(&Set_wait);
704 // wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ); //1s wait
705 while(pDevice
->bWPADEVUp
==TRUE
) {
706 set_current_state(TASK_UNINTERRUPTIBLE
);
707 schedule_timeout (HZ
/20); //wait 50ms
716 #ifdef CONFIG_PM /* Minimal support for suspend and resume */
717 static int vntwusb_suspend(struct usb_interface
*intf
, pm_message_t message
)
719 PSDevice pDevice
= usb_get_intfdata(intf
);
720 struct net_device
*dev
= pDevice
->dev
;
722 printk("VNTWUSB Suspend Start======>\n");
724 if(pDevice
->flags
& DEVICE_FLAGS_OPENED
)
728 usb_put_dev(interface_to_usbdev(intf
));
732 static int vntwusb_resume(struct usb_interface
*intf
)
734 PSDevice pDevice
= usb_get_intfdata(intf
);
735 struct net_device
*dev
= pDevice
->dev
;
737 printk("VNTWUSB Resume Start======>\n");
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");
750 static 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
,
761 vntwusb_found1(struct usb_interface
*intf
, const struct usb_device_id
*id
)
763 BYTE fake_mac
[U_ETHER_ADDR_LEN
] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};//fake MAC address
764 struct usb_device
*udev
= interface_to_usbdev(intf
);
766 struct net_device
*netdev
= NULL
;
767 PSDevice pDevice
= NULL
;
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");
773 udev
= usb_get_dev(udev
);
775 netdev
= alloc_etherdev(sizeof(DEVICE_INFO
));
777 if (netdev
== NULL
) {
778 printk(KERN_ERR DEVICE_NAME
": allocate net device failed \n");
783 pDevice
= netdev_priv(netdev
);
784 memset(pDevice
, 0, sizeof(DEVICE_INFO
));
786 pDevice
->dev
= netdev
;
789 // Set initial settings
790 device_set_options(pDevice
);
791 spin_lock_init(&pDevice
->lock
);
793 pDevice
->tx_80211
= device_dma0_tx_80211
;
794 pDevice
->sMgmtObj
.pAdapter
= (PVOID
)pDevice
;
796 netdev
->netdev_ops
= &device_netdev_ops
;
798 netdev
->wireless_handlers
= (struct iw_handler_def
*)&iwctl_handler_def
;
800 //2008-0623-01<Remark>by MikeLiu
801 //2007-0821-01<Add>by MikeLiu
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
); //use fake mac address
805 rc
= register_netdev(netdev
);
807 printk(KERN_ERR DEVICE_NAME
" Failed to register netdev\n");
812 //2008-0623-02<Remark>by MikeLiu
813 //2007-0821-01<Add>by MikeLiu
814 //#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21)
815 //usb_set_intfdata(intf, pDevice);
816 //SET_NETDEV_DEV(netdev, &intf->dev);
819 //2008-07-21-01<Add>by MikeLiu
822 if(wpa_set_wpadev(pDevice
, 1)!=0) {
823 printk("Fail to Register WPADEV?\n");
824 unregister_netdev(pDevice
->dev
);
829 usb_device_reset(pDevice
);
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
);
845 //2008-0922-01<Add>by MikeLiu, decrease usb counter.
852 static VOID
device_free_tx_bufs(PSDevice pDevice
) {
853 PUSB_SEND_CONTEXT pTxContext
;
856 for (ii
= 0; ii
< pDevice
->cbTD
; ii
++) {
858 pTxContext
= pDevice
->apTD
[ii
];
860 if (pTxContext
->pUrb
) {
861 usb_kill_urb(pTxContext
->pUrb
);
862 usb_free_urb(pTxContext
->pUrb
);
871 static VOID
device_free_rx_bufs(PSDevice pDevice
) {
875 for (ii
= 0; ii
< pDevice
->cbRD
; ii
++) {
877 pRCB
= pDevice
->apRCB
[ii
];
880 usb_kill_urb(pRCB
->pUrb
);
881 usb_free_urb(pRCB
->pUrb
);
885 dev_kfree_skb(pRCB
->skb
);
887 if (pDevice
->pRCBMem
)
888 kfree(pDevice
->pRCBMem
);
893 //2007-1107-02<Add>by MikeLiu
894 static void usb_device_reset(PSDevice pDevice
)
897 status
= usb_reset_device(pDevice
->usb
);
899 printk("usb_device_reset fail status=%d\n",status
);
903 static VOID
device_free_int_bufs(PSDevice pDevice
) {
905 if (pDevice
->intBuf
.pDataBuf
!= NULL
)
906 kfree(pDevice
->intBuf
.pDataBuf
);
911 static BOOL
device_alloc_bufs(PSDevice pDevice
) {
913 PUSB_SEND_CONTEXT pTxContext
;
918 for (ii
= 0; ii
< pDevice
->cbTD
; ii
++) {
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
);
925 pDevice
->apTD
[ii
] = pTxContext
;
926 pTxContext
->pDevice
= (PVOID
) pDevice
;
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");
933 pTxContext
->bBoolInUse
= FALSE
;
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
);
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
;
952 for (ii
= 0; ii
< pDevice
->cbRD
; ii
++) {
954 pDevice
->apRCB
[ii
] = pRCB
;
955 pRCB
->pDevice
= (PVOID
) pDevice
;
957 pRCB
->pUrb
= usb_alloc_urb(0, GFP_ATOMIC
);
959 if (pRCB
->pUrb
== NULL
) {
960 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
" Failed to alloc rx urb\n");
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");
968 pRCB
->skb
->dev
= pDevice
->dev
;
969 pRCB
->bBoolInUse
= FALSE
;
970 EnqueueRCB(pDevice
->FirstRecvFreeList
, pDevice
->LastRecvFreeList
, pRCB
);
971 pDevice
->NumRecvFreeList
++;
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");
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
);
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
);
1003 device_free_rx_bufs(pDevice
);
1006 device_free_tx_bufs(pDevice
);
1014 static BOOL
device_init_defrag_cb(PSDevice pDevice
) {
1016 PSDeFragControlBlock pDeF
;
1018 /* Init the fragment ctl entries */
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
);
1027 pDevice
->cbDFCB
= CB_MAX_RX_FRAG
;
1028 pDevice
->cbFreeDFCB
= pDevice
->cbDFCB
;
1032 device_free_frag_bufs(pDevice
);
1038 static void device_free_frag_bufs(PSDevice pDevice
) {
1039 PSDeFragControlBlock pDeF
;
1042 for (i
= 0; i
< CB_MAX_RX_FRAG
; i
++) {
1044 pDeF
= &(pDevice
->sRxDFCB
[i
]);
1047 dev_kfree_skb(pDeF
->skb
);
1053 BOOL
device_alloc_frag_buf(PSDevice pDevice
, PSDeFragControlBlock pDeF
) {
1055 pDeF
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1056 if (pDeF
->skb
== NULL
)
1059 pDeF
->skb
->dev
= pDevice
->dev
;
1065 /*-----------------------------------------------------------------*/
1067 static int device_open(struct net_device
*dev
) {
1068 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
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
;
1080 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" device_open...\n");
1083 pDevice
->rx_buf_sz
= MAX_TOTAL_SIZE_WITH_ALL_HEADERS
;
1085 if (device_alloc_bufs(pDevice
) == FALSE
) {
1086 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" device_alloc_bufs fail... \n");
1090 if (device_init_defrag_cb(pDevice
)== FALSE
) {
1091 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Initial defragement cb fail \n");
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
);
1102 Read_config_file(pDevice
);
1104 if (device_init_registers(pDevice
, DEVICE_INIT_COLD
) == FALSE
) {
1105 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" init register fail\n");
1109 device_set_multi(pDevice
->dev
);
1110 // Init for Key Management
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
; //DavidWang
1118 pDevice
->bIsRoaming
= FALSE
;//DavidWang
1119 pDevice
->bEnableRoaming
= FALSE
;
1120 if (pDevice
->bDiversityRegCtlON
) {
1121 device_init_diversity_timer(pDevice
);
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; //Max 100 microframes.
1130 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1132 pDevice
->bIsRxWorkItemQueued
= TRUE
;
1133 pDevice
->fKillEventPollingThread
= FALSE
;
1134 pDevice
->bEventAvailable
= FALSE
;
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
;
1144 pDevice
->byReAssocCount
= 0;
1146 RXvWorkItem(pDevice
);
1147 INTvWorkItem(pDevice
);
1149 // Patch: if WEP key already set by iwconfig but device not yet open
1150 if ((pDevice
->bEncryptionEnable
== TRUE
) && (pDevice
->bTransmitKey
== TRUE
)) {
1151 spin_lock_irq(&pDevice
->lock
);
1152 KeybSetDefaultKey( pDevice
,
1154 pDevice
->byKeyIndex
| (1 << 31),
1155 pDevice
->uKeyLength
,
1160 spin_unlock_irq(&pDevice
->lock
);
1161 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1164 if (pDevice
->sMgmtObj
.eConfigMode
== WMAC_CONFIG_AP
) {
1165 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_RUN_AP
, NULL
);
1168 //mike:mark@2008-11-10
1169 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
1170 //bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SSID, NULL);
1174 netif_stop_queue(pDevice
->dev
);
1175 pDevice
->flags
|= DEVICE_FLAGS_OPENED
;
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
);
1186 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_open success.. \n");
1190 device_free_frag_bufs(pDevice
);
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
);
1200 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_open fail.. \n");
1206 static int device_close(struct net_device
*dev
) {
1207 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
1208 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1212 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_close1 \n");
1213 if (pDevice
== NULL
)
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
);
1225 //2007-1121-02<Add>by EinsnLiu
1226 if (pDevice
->bLinkPass
) {
1227 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_DISASSOCIATE
, NULL
);
1232 //2008-0714-01<Add>by MikeLiu
1233 device_release_WPADEV(pDevice
);
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
);
1244 if ((pDevice
->flags
& DEVICE_FLAGS_UNPLUG
) == FALSE
) {
1245 MACbShutdown(pDevice
);
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
);
1255 //2007-0115-02<Add>by MikeLiu
1257 del_timer(&pDevice
->sTimerTxData
);
1260 if (pDevice
->bDiversityRegCtlON
) {
1261 del_timer(&pDevice
->TimerSQ3Tmax1
);
1262 del_timer(&pDevice
->TimerSQ3Tmax2
);
1263 del_timer(&pDevice
->TimerSQ3Tmax3
);
1265 tasklet_kill(&pDevice
->RxMngWorkItem
);
1266 tasklet_kill(&pDevice
->ReadWorkItem
);
1267 tasklet_kill(&pDevice
->EventWorkItem
);
1269 pDevice
->bRoaming
= FALSE
; //DavidWang
1270 pDevice
->bIsRoaming
= FALSE
;//DavidWang
1271 pDevice
->bEnableRoaming
= FALSE
;
1272 pDevice
->bCmdRunning
= FALSE
;
1273 pDevice
->bLinkPass
= FALSE
;
1274 memset(pMgmt
->abyCurrBSSID
, 0, 6);
1275 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
1277 device_free_tx_bufs(pDevice
);
1278 device_free_rx_bufs(pDevice
);
1279 device_free_int_bufs(pDevice
);
1280 device_free_frag_bufs(pDevice
);
1282 usb_kill_urb(pDevice
->pControlURB
);
1283 usb_kill_urb(pDevice
->pInterruptURB
);
1284 usb_free_urb(pDevice
->pControlURB
);
1285 usb_free_urb(pDevice
->pInterruptURB
);
1287 BSSvClearNodeDBTable(pDevice
, 0);
1288 pDevice
->flags
&=(~DEVICE_FLAGS_OPENED
);
1290 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_close2 \n");
1296 static void vntwusb_disconnect(struct usb_interface
*intf
)
1300 PSDevice pDevice
= usb_get_intfdata(intf
);
1302 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_disconnect1.. \n");
1303 if (pDevice
== NULL
)
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
);
1315 //2008-0714-01<Add>by MikeLiu
1316 device_release_WPADEV(pDevice
);
1318 usb_set_intfdata(intf
, NULL
);
1319 //2008-0922-01<Add>by MikeLiu, decrease usb counter.
1320 usb_put_dev(interface_to_usbdev(intf
));
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
);
1327 //2008-07-21-01<Add>by MikeLiu
1329 if(wpa_set_wpadev(pDevice
, 0)!=0)
1330 printk("unregister wpadev fail?\n");
1332 free_netdev(pDevice
->dev
);
1336 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_disconnect3.. \n");
1342 static int device_dma0_tx_80211(struct sk_buff
*skb
, struct net_device
*dev
) {
1343 PSDevice pDevice
=netdev_priv(dev
);
1348 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_dma0_tx_80211\n");
1349 spin_lock_irq(&pDevice
->lock
);
1351 if (pDevice
->bStopTx0Pkt
== TRUE
) {
1352 dev_kfree_skb_irq(skb
);
1353 spin_unlock_irq(&pDevice
->lock
);
1358 cbMPDULen
= skb
->len
;
1361 vDMA0_tx_80211(pDevice
, skb
);
1363 spin_unlock_irq(&pDevice
->lock
);
1370 static int device_xmit(struct sk_buff
*skb
, struct net_device
*dev
) {
1371 PSDevice pDevice
=netdev_priv(dev
);
1372 struct net_device_stats
* pStats
= &pDevice
->stats
;
1375 spin_lock_irq(&pDevice
->lock
);
1377 netif_stop_queue(pDevice
->dev
);
1379 if (pDevice
->bLinkPass
== FALSE
) {
1380 dev_kfree_skb_irq(skb
);
1381 spin_unlock_irq(&pDevice
->lock
);
1384 if (pDevice
->bStopDataPkt
== TRUE
) {
1385 dev_kfree_skb_irq(skb
);
1386 pStats
->tx_dropped
++;
1387 spin_unlock_irq(&pDevice
->lock
);
1391 if(nsDMA_tx_packet(pDevice
, TYPE_AC0DMA
, skb
) !=0) { //mike add:xmit fail!
1392 if (netif_queue_stopped(pDevice
->dev
))
1393 netif_wake_queue(pDevice
->dev
);
1396 spin_unlock_irq(&pDevice
->lock
);
1403 static unsigned const ethernet_polynomial
= 0x04c11db7U
;
1404 static inline u32
ether_crc(int length
, unsigned char *data
)
1408 while(--length
>= 0) {
1409 unsigned char current_octet
= *data
++;
1411 for (bit
= 0; bit
< 8; bit
++, current_octet
>>= 1) {
1413 ((crc
< 0) ^ (current_octet
& 1) ? ethernet_polynomial
: 0);
1419 //find out the start position of str2 from str1
1420 static UCHAR
*kstrstr(const UCHAR
*str1
,const UCHAR
*str2
) {
1421 int str1_len
=strlen(str1
);
1422 int str2_len
=strlen(str2
);
1424 while (str1_len
>= str2_len
) {
1426 if(memcmp(str1
,str2
,str2_len
)==0)
1427 return (UCHAR
*)str1
;
1433 static int Config_FileGetParameter(UCHAR
*string
, UCHAR
*dest
,UCHAR
*source
)
1437 UCHAR
*start_p
=NULL
,*end_p
=NULL
,*tmp_p
=NULL
;
1441 strcat(buf1
, string
);
1443 source
+=strlen(buf1
);
1445 //find target string start point
1446 if((start_p
= kstrstr(source
,buf1
))==NULL
)
1449 //check if current config line is marked by "#" ??
1451 if(memcmp(start_p
-ii
,"\n",1)==0)
1453 if(memcmp(start_p
-ii
,"#",1)==0)
1457 //find target string end point
1458 if((end_p
= kstrstr(start_p
,"\n"))==NULL
) { //cann't find "\n",but don't care
1459 end_p
=start_p
+strlen(start_p
); //no include "\n"
1463 memcpy(buf2
,start_p
,end_p
-start_p
); //get the tartget line
1464 buf2
[end_p
-start_p
]='\0';
1467 if((start_p
= kstrstr(buf2
,"="))==NULL
)
1470 strcpy(buf1
,start_p
+1);
1474 while(*tmp_p
!= 0x00) {
1481 memcpy(dest
,tmp_p
,strlen(tmp_p
));
1485 //if read fail,return NULL,or return data pointer;
1486 static UCHAR
*Config_FileOperation(PSDevice pDevice
) {
1487 UCHAR
*config_path
=CONFIG_PATH
;
1489 struct file
*filp
=NULL
;
1490 mm_segment_t old_fs
= get_fs();
1491 //int oldfsuid=0,oldfsgid=0;
1495 /* Can't do this anymore, so we rely on correct filesystem permissions:
1496 //Make sure a caller can read or write power as root
1497 oldfsuid=current->fsuid;
1498 oldfsgid=current->fsgid;
1504 filp
= filp_open(config_path
, O_RDWR
, 0);
1506 printk("Config_FileOperation file Not exist\n");
1511 if(!(filp
->f_op
) || !(filp
->f_op
->read
) ||!(filp
->f_op
->write
)) {
1512 printk("file %s cann't readable or writable?\n",config_path
);
1517 buffer
= (UCHAR
*)kmalloc(1024, GFP_KERNEL
);
1519 printk("alllocate mem for file fail?\n");
1524 if(filp
->f_op
->read(filp
, buffer
, 1024, &filp
->f_pos
)<0) {
1525 printk("read file error?\n");
1530 if(filp_close(filp
,NULL
))
1531 printk("Config_FileOperation:close file fail\n");
1537 current->fsuid=oldfsuid;
1538 current->fsgid=oldfsgid;
1549 //return --->-1:fail; >=0:sucessful
1550 static int Read_config_file(PSDevice pDevice
) {
1552 UCHAR tmpbuffer
[100];
1555 //init config setting
1556 pDevice
->config_file
.ZoneType
= -1;
1557 pDevice
->config_file
.eAuthenMode
= -1;
1558 pDevice
->config_file
.eEncryptionStatus
= -1;
1560 if((buffer
=Config_FileOperation(pDevice
)) ==NULL
) {
1567 memset(tmpbuffer
,0,sizeof(tmpbuffer
));
1568 if(Config_FileGetParameter("ZONETYPE",tmpbuffer
,buffer
) ==TRUE
) {
1569 if(memcmp(tmpbuffer
,"USA",3)==0) {
1570 pDevice
->config_file
.ZoneType
=ZoneType_USA
;
1572 else if(memcmp(tmpbuffer
,"JAPAN",5)==0) {
1573 pDevice
->config_file
.ZoneType
=ZoneType_Japan
;
1575 else if(memcmp(tmpbuffer
,"EUROPE",6)==0) {
1576 pDevice
->config_file
.ZoneType
=ZoneType_Europe
;
1579 printk("Unknown Zonetype[%s]?\n",tmpbuffer
);
1585 //get other parameter
1587 memset(tmpbuffer
,0,sizeof(tmpbuffer
));
1588 if(Config_FileGetParameter("AUTHENMODE",tmpbuffer
,buffer
)==TRUE
) {
1589 pDevice
->config_file
.eAuthenMode
= (int) simple_strtol(tmpbuffer
, NULL
, 10);
1592 memset(tmpbuffer
,0,sizeof(tmpbuffer
));
1593 if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer
,buffer
)==TRUE
) {
1594 pDevice
->config_file
.eEncryptionStatus
= (int) simple_strtol(tmpbuffer
, NULL
, 10);
1603 static void device_set_multi(struct net_device
*dev
) {
1604 PSDevice pDevice
= (PSDevice
) netdev_priv(dev
);
1605 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1608 struct dev_mc_list
*mclist
;
1609 BYTE pbyData
[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
1614 spin_lock_irq(&pDevice
->lock
);
1615 rc
= CONTROLnsRequestIn(pDevice
,
1618 MESSAGE_REQUEST_MACREG
,
1622 if (rc
== 0) pDevice
->byRxMode
= byTmpMode
;
1624 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pDevice->byRxMode in= %x\n", pDevice
->byRxMode
);
1626 if (dev
->flags
& IFF_PROMISC
) { // Set promiscuous.
1627 DBG_PRT(MSG_LEVEL_ERR
,KERN_NOTICE
"%s: Promiscuous mode enabled.\n", dev
->name
);
1628 // Unconditionally log net taps.
1629 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
|RCR_UNICAST
);
1631 else if ((dev
->mc_count
> pDevice
->multicast_limit
) || (dev
->flags
& IFF_ALLMULTI
)) {
1632 CONTROLnsRequestOut(pDevice
,
1635 MESSAGE_REQUEST_MACREG
,
1639 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
1642 memset(mc_filter
, 0, sizeof(mc_filter
));
1643 for (ii
= 0, mclist
= dev
->mc_list
; mclist
&& ii
< dev
->mc_count
;
1644 ii
++, mclist
= mclist
->next
) {
1645 int bit_nr
= ether_crc(ETH_ALEN
, mclist
->dmi_addr
) >> 26;
1646 mc_filter
[bit_nr
>> 5] |= cpu_to_le32(1 << (bit_nr
& 31));
1648 for (ii
= 0; ii
< 4; ii
++) {
1649 MACvWriteMultiAddr(pDevice
, ii
, *((PBYTE
)&mc_filter
[0] + ii
));
1650 MACvWriteMultiAddr(pDevice
, ii
+ 4, *((PBYTE
)&mc_filter
[1] + ii
));
1652 pDevice
->byRxMode
&= ~(RCR_UNICAST
);
1653 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
1656 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
1657 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
1658 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
1659 pDevice
->byRxMode
&= ~(RCR_UNICAST
);
1661 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_MACREG
, MAC_REG_RCR
, pDevice
->byRxMode
);
1662 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pDevice->byRxMode out= %x\n", pDevice
->byRxMode
);
1663 spin_unlock_irq(&pDevice
->lock
);
1668 static struct net_device_stats
*device_get_stats(struct net_device
*dev
) {
1669 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
1671 return &pDevice
->stats
;
1675 static int device_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
) {
1676 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1677 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1679 //BOOL bCommit = FALSE;
1680 struct iwreq
*wrq
= (struct iwreq
*) rq
;
1683 if (pMgmt
== NULL
) {
1691 rc
= iwctl_giwname(dev
, NULL
, (char *)&(wrq
->u
.name
), NULL
);
1698 case SIOCGIWNWID
: //0x8b03 support
1699 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1700 rc
= iwctl_giwnwid(dev
, NULL
, &(wrq
->u
.nwid
), NULL
);
1706 // Set frequency/channel
1708 rc
= iwctl_siwfreq(dev
, NULL
, &(wrq
->u
.freq
), NULL
);
1711 // Get frequency/channel
1713 rc
= iwctl_giwfreq(dev
, NULL
, &(wrq
->u
.freq
), NULL
);
1716 // Set desired network name (ESSID)
1720 char essid
[IW_ESSID_MAX_SIZE
+1];
1721 if (wrq
->u
.essid
.length
> IW_ESSID_MAX_SIZE
) {
1725 if (copy_from_user(essid
, wrq
->u
.essid
.pointer
,
1726 wrq
->u
.essid
.length
)) {
1730 rc
= iwctl_siwessid(dev
, NULL
,
1731 &(wrq
->u
.essid
), essid
);
1736 // Get current network name (ESSID)
1740 char essid
[IW_ESSID_MAX_SIZE
+1];
1741 if (wrq
->u
.essid
.pointer
)
1742 rc
= iwctl_giwessid(dev
, NULL
,
1743 &(wrq
->u
.essid
), essid
);
1744 if (copy_to_user(wrq
->u
.essid
.pointer
,
1746 wrq
->u
.essid
.length
) )
1753 rc
= iwctl_siwap(dev
, NULL
, &(wrq
->u
.ap_addr
), NULL
);
1757 // Get current Access Point (BSSID)
1759 rc
= iwctl_giwap(dev
, NULL
, &(wrq
->u
.ap_addr
), NULL
);
1763 // Set desired station name
1765 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWNICKN \n");
1769 // Get current station name
1771 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWNICKN \n");
1775 // Set the desired bit-rate
1777 rc
= iwctl_siwrate(dev
, NULL
, &(wrq
->u
.bitrate
), NULL
);
1780 // Get the current bit-rate
1783 rc
= iwctl_giwrate(dev
, NULL
, &(wrq
->u
.bitrate
), NULL
);
1786 // Set the desired RTS threshold
1789 rc
= iwctl_siwrts(dev
, NULL
, &(wrq
->u
.rts
), NULL
);
1792 // Get the current RTS threshold
1795 rc
= iwctl_giwrts(dev
, NULL
, &(wrq
->u
.rts
), NULL
);
1798 // Set the desired fragmentation threshold
1801 rc
= iwctl_siwfrag(dev
, NULL
, &(wrq
->u
.frag
), NULL
);
1804 // Get the current fragmentation threshold
1807 rc
= iwctl_giwfrag(dev
, NULL
, &(wrq
->u
.frag
), NULL
);
1810 // Set mode of operation
1812 rc
= iwctl_siwmode(dev
, NULL
, &(wrq
->u
.mode
), NULL
);
1815 // Get mode of operation
1817 rc
= iwctl_giwmode(dev
, NULL
, &(wrq
->u
.mode
), NULL
);
1820 // Set WEP keys and mode
1823 char abyKey
[WLAN_WEP232_KEYLEN
];
1825 if (wrq
->u
.encoding
.pointer
) {
1828 if (wrq
->u
.encoding
.length
> WLAN_WEP232_KEYLEN
) {
1832 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
1833 if (copy_from_user(abyKey
,
1834 wrq
->u
.encoding
.pointer
,
1835 wrq
->u
.encoding
.length
)) {
1839 } else if (wrq
->u
.encoding
.length
!= 0) {
1843 rc
= iwctl_siwencode(dev
, NULL
, &(wrq
->u
.encoding
), abyKey
);
1847 // Get the WEP keys and mode
1850 if (!capable(CAP_NET_ADMIN
)) {
1855 char abyKey
[WLAN_WEP232_KEYLEN
];
1857 rc
= iwctl_giwencode(dev
, NULL
, &(wrq
->u
.encoding
), abyKey
);
1859 if (wrq
->u
.encoding
.pointer
) {
1860 if (copy_to_user(wrq
->u
.encoding
.pointer
,
1862 wrq
->u
.encoding
.length
))
1868 // Get the current Tx-Power
1870 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWTXPOW \n");
1875 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWTXPOW \n");
1881 rc
= iwctl_siwretry(dev
, NULL
, &(wrq
->u
.retry
), NULL
);
1886 rc
= iwctl_giwretry(dev
, NULL
, &(wrq
->u
.retry
), NULL
);
1889 // Get range of parameters
1893 struct iw_range range
;
1895 rc
= iwctl_giwrange(dev
, NULL
, &(wrq
->u
.data
), (char *) &range
);
1896 if (copy_to_user(wrq
->u
.data
.pointer
, &range
, sizeof(struct iw_range
)))
1904 rc
= iwctl_giwpower(dev
, NULL
, &(wrq
->u
.power
), NULL
);
1910 rc
= iwctl_siwpower(dev
, NULL
, &(wrq
->u
.power
), NULL
);
1916 rc
= iwctl_giwsens(dev
, NULL
, &(wrq
->u
.sens
), NULL
);
1920 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSENS \n");
1926 char buffer
[IW_MAX_AP
* (sizeof(struct sockaddr
) + sizeof(struct iw_quality
))];
1928 if (wrq
->u
.data
.pointer
) {
1929 rc
= iwctl_giwaplist(dev
, NULL
, &(wrq
->u
.data
), buffer
);
1931 if (copy_to_user(wrq
->u
.data
.pointer
,
1933 (wrq
->u
.data
.length
* (sizeof(struct sockaddr
) + sizeof(struct iw_quality
)))
1946 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSPY \n");
1953 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSPY \n");
1957 #endif // WIRELESS_SPY
1960 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPRIV \n");
1963 if(wrq->u.data.pointer) {
1964 wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
1966 if(copy_to_user(wrq->u.data.pointer,
1967 (u_char *) iwctl_private_args,
1968 sizeof(iwctl_private_args)))
1975 //2008-0409-07, <Add> by Einsn Liu
1976 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1978 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH \n");
1979 rc
= iwctl_siwauth(dev
, NULL
, &(wrq
->u
.param
), NULL
);
1983 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAUTH \n");
1984 rc
= iwctl_giwauth(dev
, NULL
, &(wrq
->u
.param
), NULL
);
1988 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWGENIE \n");
1989 rc
= iwctl_siwgenie(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
1993 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWGENIE \n");
1994 rc
= iwctl_giwgenie(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
1997 case SIOCSIWENCODEEXT
:
1999 char extra
[sizeof(struct iw_encode_ext
)+MAX_KEY_LEN
+1];
2000 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODEEXT \n");
2001 if(wrq
->u
.encoding
.pointer
){
2002 memset(extra
, 0, sizeof(struct iw_encode_ext
)+MAX_KEY_LEN
+1);
2003 if(wrq
->u
.encoding
.length
> (sizeof(struct iw_encode_ext
)+ MAX_KEY_LEN
)){
2007 if(copy_from_user(extra
, wrq
->u
.encoding
.pointer
,wrq
->u
.encoding
.length
)){
2011 }else if(wrq
->u
.encoding
.length
!= 0){
2015 rc
= iwctl_siwencodeext(dev
, NULL
, &(wrq
->u
.encoding
), extra
);
2019 case SIOCGIWENCODEEXT
:
2020 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODEEXT \n");
2021 rc
= iwctl_giwencodeext(dev
, NULL
, &(wrq
->u
.encoding
), NULL
);
2025 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMLME \n");
2026 rc
= iwctl_siwmlme(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
2029 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2030 //End Add -- //2008-0409-07, <Add> by Einsn Liu
2032 case IOCTL_CMD_TEST
:
2034 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
2040 pReq
= (PSCmdRequest
)rq
;
2042 //20080130-01,<Remark> by Mike Liu
2043 // if(pDevice->bLinkPass==TRUE)
2044 pReq
->wResult
= MAGIC_CODE
; //Linking status:0x3142
2045 //20080130-02,<Remark> by Mike Liu
2047 // pReq->wResult = MAGIC_CODE+1; //disconnect status:0x3143
2051 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
) &&
2052 (((PSCmdRequest
)rq
)->wCmdCode
!=WLAN_CMD_SET_WPA
))
2060 if (test_and_set_bit( 0, (void*)&(pMgmt
->uCmdBusy
))) {
2063 rc
= private_ioctl(pDevice
, rq
);
2064 clear_bit( 0, (void*)&(pMgmt
->uCmdBusy
));
2067 case IOCTL_CMD_HOSTAPD
:
2069 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
2076 rc
= hostap_ioctl(pDevice
, &wrq
->u
.data
);
2081 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
2088 rc
= wpa_ioctl(pDevice
, &wrq
->u
.data
);
2092 return ethtool_ioctl(dev
, (void *) rq
->ifr_data
);
2093 // All other calls are currently unsupported
2097 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Ioctl command not support..%x\n", cmd
);
2102 if (pDevice
->bCommit
) {
2103 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
2104 netif_stop_queue(pDevice
->dev
);
2105 spin_lock_irq(&pDevice
->lock
);
2106 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_RUN_AP
, NULL
);
2107 spin_unlock_irq(&pDevice
->lock
);
2110 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Commit the settings\n");
2111 spin_lock_irq(&pDevice
->lock
);
2112 //2007-1121-01<Modify>by EinsnLiu
2113 if (pDevice
->bLinkPass
&&
2114 memcmp(pMgmt
->abyCurrSSID
,pMgmt
->abyDesireSSID
,WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
)) {
2115 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_DISASSOCIATE
, NULL
);
2117 pDevice
->bLinkPass
= FALSE
;
2118 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
2119 memset(pMgmt
->abyCurrBSSID
, 0, 6);
2121 ControlvMaskByte(pDevice
,MESSAGE_REQUEST_MACREG
,MAC_REG_PAPEDELAY
,LEDSTS_STS
,LEDSTS_SLOW
);
2123 netif_stop_queue(pDevice
->dev
);
2124 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2125 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
2126 if(pDevice
->bWPASuppWextEnabled
!=TRUE
)
2128 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_BSSID_SCAN
, pMgmt
->abyDesireSSID
);
2129 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_SSID
, NULL
);
2130 spin_unlock_irq(&pDevice
->lock
);
2132 pDevice
->bCommit
= FALSE
;
2140 static int ethtool_ioctl(struct net_device
*dev
, void *useraddr
)
2144 if (copy_from_user(ðcmd
, useraddr
, sizeof(ethcmd
)))
2148 case ETHTOOL_GDRVINFO
: {
2149 struct ethtool_drvinfo info
= {ETHTOOL_GDRVINFO
};
2150 strncpy(info
.driver
, DEVICE_NAME
, sizeof(info
.driver
)-1);
2151 strncpy(info
.version
, DEVICE_VERSION
, sizeof(info
.version
)-1);
2152 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
2163 /*------------------------------------------------------------------*/
2166 MODULE_DEVICE_TABLE(usb
, vntwusb_table
);
2169 static struct usb_driver vntwusb_driver
= {
2170 .name
= DEVICE_NAME
,
2171 .probe
= vntwusb_found1
,
2172 .disconnect
= vntwusb_disconnect
,
2173 .id_table
= vntwusb_table
,
2175 //2008-0920-01<Add>by MikeLiu
2176 //for supporting S3 & S4 function
2178 .suspend
= vntwusb_suspend
,
2179 .resume
= vntwusb_resume
,
2183 static int __init
vntwusb_init_module(void)
2185 printk(KERN_NOTICE DEVICE_FULL_DRV_NAM
" " DEVICE_VERSION
);
2186 return usb_register(&vntwusb_driver
);
2189 static void __exit
vntwusb_cleanup_module(void)
2191 usb_deregister(&vntwusb_driver
);
2194 module_init(vntwusb_init_module
);
2195 module_exit(vntwusb_cleanup_module
);