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
);
1335 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_disconnect3.. \n");
1341 static int device_dma0_tx_80211(struct sk_buff
*skb
, struct net_device
*dev
) {
1342 PSDevice pDevice
=netdev_priv(dev
);
1347 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_dma0_tx_80211\n");
1348 spin_lock_irq(&pDevice
->lock
);
1350 if (pDevice
->bStopTx0Pkt
== TRUE
) {
1351 dev_kfree_skb_irq(skb
);
1352 spin_unlock_irq(&pDevice
->lock
);
1357 cbMPDULen
= skb
->len
;
1360 vDMA0_tx_80211(pDevice
, skb
);
1362 spin_unlock_irq(&pDevice
->lock
);
1369 static int device_xmit(struct sk_buff
*skb
, struct net_device
*dev
) {
1370 PSDevice pDevice
=netdev_priv(dev
);
1371 struct net_device_stats
* pStats
= &pDevice
->stats
;
1374 spin_lock_irq(&pDevice
->lock
);
1376 netif_stop_queue(pDevice
->dev
);
1378 if (pDevice
->bLinkPass
== FALSE
) {
1379 dev_kfree_skb_irq(skb
);
1380 spin_unlock_irq(&pDevice
->lock
);
1383 if (pDevice
->bStopDataPkt
== TRUE
) {
1384 dev_kfree_skb_irq(skb
);
1385 pStats
->tx_dropped
++;
1386 spin_unlock_irq(&pDevice
->lock
);
1390 if(nsDMA_tx_packet(pDevice
, TYPE_AC0DMA
, skb
) !=0) { //mike add:xmit fail!
1391 if (netif_queue_stopped(pDevice
->dev
))
1392 netif_wake_queue(pDevice
->dev
);
1395 spin_unlock_irq(&pDevice
->lock
);
1402 static unsigned const ethernet_polynomial
= 0x04c11db7U
;
1403 static inline u32
ether_crc(int length
, unsigned char *data
)
1407 while(--length
>= 0) {
1408 unsigned char current_octet
= *data
++;
1410 for (bit
= 0; bit
< 8; bit
++, current_octet
>>= 1) {
1412 ((crc
< 0) ^ (current_octet
& 1) ? ethernet_polynomial
: 0);
1418 //find out the start position of str2 from str1
1419 static UCHAR
*kstrstr(const UCHAR
*str1
,const UCHAR
*str2
) {
1420 int str1_len
=strlen(str1
);
1421 int str2_len
=strlen(str2
);
1423 while (str1_len
>= str2_len
) {
1425 if(memcmp(str1
,str2
,str2_len
)==0)
1426 return (UCHAR
*)str1
;
1432 static int Config_FileGetParameter(UCHAR
*string
, UCHAR
*dest
,UCHAR
*source
)
1436 UCHAR
*start_p
=NULL
,*end_p
=NULL
,*tmp_p
=NULL
;
1440 strcat(buf1
, string
);
1442 source
+=strlen(buf1
);
1444 //find target string start point
1445 if((start_p
= kstrstr(source
,buf1
))==NULL
)
1448 //check if current config line is marked by "#" ??
1450 if(memcmp(start_p
-ii
,"\n",1)==0)
1452 if(memcmp(start_p
-ii
,"#",1)==0)
1456 //find target string end point
1457 if((end_p
= kstrstr(start_p
,"\n"))==NULL
) { //cann't find "\n",but don't care
1458 end_p
=start_p
+strlen(start_p
); //no include "\n"
1462 memcpy(buf2
,start_p
,end_p
-start_p
); //get the tartget line
1463 buf2
[end_p
-start_p
]='\0';
1466 if((start_p
= kstrstr(buf2
,"="))==NULL
)
1469 strcpy(buf1
,start_p
+1);
1473 while(*tmp_p
!= 0x00) {
1480 memcpy(dest
,tmp_p
,strlen(tmp_p
));
1484 //if read fail,return NULL,or return data pointer;
1485 static UCHAR
*Config_FileOperation(PSDevice pDevice
) {
1486 UCHAR
*config_path
=CONFIG_PATH
;
1488 struct file
*filp
=NULL
;
1489 mm_segment_t old_fs
= get_fs();
1490 //int oldfsuid=0,oldfsgid=0;
1494 /* Can't do this anymore, so we rely on correct filesystem permissions:
1495 //Make sure a caller can read or write power as root
1496 oldfsuid=current->fsuid;
1497 oldfsgid=current->fsgid;
1503 filp
= filp_open(config_path
, O_RDWR
, 0);
1505 printk("Config_FileOperation file Not exist\n");
1510 if(!(filp
->f_op
) || !(filp
->f_op
->read
) ||!(filp
->f_op
->write
)) {
1511 printk("file %s cann't readable or writable?\n",config_path
);
1516 buffer
= (UCHAR
*)kmalloc(1024, GFP_KERNEL
);
1518 printk("alllocate mem for file fail?\n");
1523 if(filp
->f_op
->read(filp
, buffer
, 1024, &filp
->f_pos
)<0) {
1524 printk("read file error?\n");
1529 if(filp_close(filp
,NULL
))
1530 printk("Config_FileOperation:close file fail\n");
1536 current->fsuid=oldfsuid;
1537 current->fsgid=oldfsgid;
1548 //return --->-1:fail; >=0:sucessful
1549 static int Read_config_file(PSDevice pDevice
) {
1551 UCHAR tmpbuffer
[100];
1554 //init config setting
1555 pDevice
->config_file
.ZoneType
= -1;
1556 pDevice
->config_file
.eAuthenMode
= -1;
1557 pDevice
->config_file
.eEncryptionStatus
= -1;
1559 if((buffer
=Config_FileOperation(pDevice
)) ==NULL
) {
1566 memset(tmpbuffer
,0,sizeof(tmpbuffer
));
1567 if(Config_FileGetParameter("ZONETYPE",tmpbuffer
,buffer
) ==TRUE
) {
1568 if(memcmp(tmpbuffer
,"USA",3)==0) {
1569 pDevice
->config_file
.ZoneType
=ZoneType_USA
;
1571 else if(memcmp(tmpbuffer
,"JAPAN",5)==0) {
1572 pDevice
->config_file
.ZoneType
=ZoneType_Japan
;
1574 else if(memcmp(tmpbuffer
,"EUROPE",6)==0) {
1575 pDevice
->config_file
.ZoneType
=ZoneType_Europe
;
1578 printk("Unknown Zonetype[%s]?\n",tmpbuffer
);
1584 //get other parameter
1586 memset(tmpbuffer
,0,sizeof(tmpbuffer
));
1587 if(Config_FileGetParameter("AUTHENMODE",tmpbuffer
,buffer
)==TRUE
) {
1588 pDevice
->config_file
.eAuthenMode
= (int) simple_strtol(tmpbuffer
, NULL
, 10);
1591 memset(tmpbuffer
,0,sizeof(tmpbuffer
));
1592 if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer
,buffer
)==TRUE
) {
1593 pDevice
->config_file
.eEncryptionStatus
= (int) simple_strtol(tmpbuffer
, NULL
, 10);
1602 static void device_set_multi(struct net_device
*dev
) {
1603 PSDevice pDevice
= (PSDevice
) netdev_priv(dev
);
1604 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1607 struct dev_mc_list
*mclist
;
1608 BYTE pbyData
[8] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
1613 spin_lock_irq(&pDevice
->lock
);
1614 rc
= CONTROLnsRequestIn(pDevice
,
1617 MESSAGE_REQUEST_MACREG
,
1621 if (rc
== 0) pDevice
->byRxMode
= byTmpMode
;
1623 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pDevice->byRxMode in= %x\n", pDevice
->byRxMode
);
1625 if (dev
->flags
& IFF_PROMISC
) { // Set promiscuous.
1626 DBG_PRT(MSG_LEVEL_ERR
,KERN_NOTICE
"%s: Promiscuous mode enabled.\n", dev
->name
);
1627 // Unconditionally log net taps.
1628 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
|RCR_UNICAST
);
1630 else if ((dev
->mc_count
> pDevice
->multicast_limit
) || (dev
->flags
& IFF_ALLMULTI
)) {
1631 CONTROLnsRequestOut(pDevice
,
1634 MESSAGE_REQUEST_MACREG
,
1638 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
1641 memset(mc_filter
, 0, sizeof(mc_filter
));
1642 for (ii
= 0, mclist
= dev
->mc_list
; mclist
&& ii
< dev
->mc_count
;
1643 ii
++, mclist
= mclist
->next
) {
1644 int bit_nr
= ether_crc(ETH_ALEN
, mclist
->dmi_addr
) >> 26;
1645 mc_filter
[bit_nr
>> 5] |= cpu_to_le32(1 << (bit_nr
& 31));
1647 for (ii
= 0; ii
< 4; ii
++) {
1648 MACvWriteMultiAddr(pDevice
, ii
, *((PBYTE
)&mc_filter
[0] + ii
));
1649 MACvWriteMultiAddr(pDevice
, ii
+ 4, *((PBYTE
)&mc_filter
[1] + ii
));
1651 pDevice
->byRxMode
&= ~(RCR_UNICAST
);
1652 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
1655 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
1656 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
1657 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
1658 pDevice
->byRxMode
&= ~(RCR_UNICAST
);
1660 ControlvWriteByte(pDevice
, MESSAGE_REQUEST_MACREG
, MAC_REG_RCR
, pDevice
->byRxMode
);
1661 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pDevice->byRxMode out= %x\n", pDevice
->byRxMode
);
1662 spin_unlock_irq(&pDevice
->lock
);
1667 static struct net_device_stats
*device_get_stats(struct net_device
*dev
) {
1668 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
1670 return &pDevice
->stats
;
1674 static int device_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
) {
1675 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1676 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1678 //BOOL bCommit = FALSE;
1679 struct iwreq
*wrq
= (struct iwreq
*) rq
;
1682 if (pMgmt
== NULL
) {
1690 rc
= iwctl_giwname(dev
, NULL
, (char *)&(wrq
->u
.name
), NULL
);
1697 case SIOCGIWNWID
: //0x8b03 support
1698 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1699 rc
= iwctl_giwnwid(dev
, NULL
, &(wrq
->u
.nwid
), NULL
);
1705 // Set frequency/channel
1707 rc
= iwctl_siwfreq(dev
, NULL
, &(wrq
->u
.freq
), NULL
);
1710 // Get frequency/channel
1712 rc
= iwctl_giwfreq(dev
, NULL
, &(wrq
->u
.freq
), NULL
);
1715 // Set desired network name (ESSID)
1719 char essid
[IW_ESSID_MAX_SIZE
+1];
1720 if (wrq
->u
.essid
.length
> IW_ESSID_MAX_SIZE
) {
1724 if (copy_from_user(essid
, wrq
->u
.essid
.pointer
,
1725 wrq
->u
.essid
.length
)) {
1729 rc
= iwctl_siwessid(dev
, NULL
,
1730 &(wrq
->u
.essid
), essid
);
1735 // Get current network name (ESSID)
1739 char essid
[IW_ESSID_MAX_SIZE
+1];
1740 if (wrq
->u
.essid
.pointer
)
1741 rc
= iwctl_giwessid(dev
, NULL
,
1742 &(wrq
->u
.essid
), essid
);
1743 if (copy_to_user(wrq
->u
.essid
.pointer
,
1745 wrq
->u
.essid
.length
) )
1752 rc
= iwctl_siwap(dev
, NULL
, &(wrq
->u
.ap_addr
), NULL
);
1756 // Get current Access Point (BSSID)
1758 rc
= iwctl_giwap(dev
, NULL
, &(wrq
->u
.ap_addr
), NULL
);
1762 // Set desired station name
1764 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWNICKN \n");
1768 // Get current station name
1770 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWNICKN \n");
1774 // Set the desired bit-rate
1776 rc
= iwctl_siwrate(dev
, NULL
, &(wrq
->u
.bitrate
), NULL
);
1779 // Get the current bit-rate
1782 rc
= iwctl_giwrate(dev
, NULL
, &(wrq
->u
.bitrate
), NULL
);
1785 // Set the desired RTS threshold
1788 rc
= iwctl_siwrts(dev
, NULL
, &(wrq
->u
.rts
), NULL
);
1791 // Get the current RTS threshold
1794 rc
= iwctl_giwrts(dev
, NULL
, &(wrq
->u
.rts
), NULL
);
1797 // Set the desired fragmentation threshold
1800 rc
= iwctl_siwfrag(dev
, NULL
, &(wrq
->u
.frag
), NULL
);
1803 // Get the current fragmentation threshold
1806 rc
= iwctl_giwfrag(dev
, NULL
, &(wrq
->u
.frag
), NULL
);
1809 // Set mode of operation
1811 rc
= iwctl_siwmode(dev
, NULL
, &(wrq
->u
.mode
), NULL
);
1814 // Get mode of operation
1816 rc
= iwctl_giwmode(dev
, NULL
, &(wrq
->u
.mode
), NULL
);
1819 // Set WEP keys and mode
1822 char abyKey
[WLAN_WEP232_KEYLEN
];
1824 if (wrq
->u
.encoding
.pointer
) {
1827 if (wrq
->u
.encoding
.length
> WLAN_WEP232_KEYLEN
) {
1831 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
1832 if (copy_from_user(abyKey
,
1833 wrq
->u
.encoding
.pointer
,
1834 wrq
->u
.encoding
.length
)) {
1838 } else if (wrq
->u
.encoding
.length
!= 0) {
1842 rc
= iwctl_siwencode(dev
, NULL
, &(wrq
->u
.encoding
), abyKey
);
1846 // Get the WEP keys and mode
1849 if (!capable(CAP_NET_ADMIN
)) {
1854 char abyKey
[WLAN_WEP232_KEYLEN
];
1856 rc
= iwctl_giwencode(dev
, NULL
, &(wrq
->u
.encoding
), abyKey
);
1858 if (wrq
->u
.encoding
.pointer
) {
1859 if (copy_to_user(wrq
->u
.encoding
.pointer
,
1861 wrq
->u
.encoding
.length
))
1867 // Get the current Tx-Power
1869 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWTXPOW \n");
1874 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWTXPOW \n");
1880 rc
= iwctl_siwretry(dev
, NULL
, &(wrq
->u
.retry
), NULL
);
1885 rc
= iwctl_giwretry(dev
, NULL
, &(wrq
->u
.retry
), NULL
);
1888 // Get range of parameters
1892 struct iw_range range
;
1894 rc
= iwctl_giwrange(dev
, NULL
, &(wrq
->u
.data
), (char *) &range
);
1895 if (copy_to_user(wrq
->u
.data
.pointer
, &range
, sizeof(struct iw_range
)))
1903 rc
= iwctl_giwpower(dev
, NULL
, &(wrq
->u
.power
), NULL
);
1909 rc
= iwctl_siwpower(dev
, NULL
, &(wrq
->u
.power
), NULL
);
1915 rc
= iwctl_giwsens(dev
, NULL
, &(wrq
->u
.sens
), NULL
);
1919 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSENS \n");
1925 char buffer
[IW_MAX_AP
* (sizeof(struct sockaddr
) + sizeof(struct iw_quality
))];
1927 if (wrq
->u
.data
.pointer
) {
1928 rc
= iwctl_giwaplist(dev
, NULL
, &(wrq
->u
.data
), buffer
);
1930 if (copy_to_user(wrq
->u
.data
.pointer
,
1932 (wrq
->u
.data
.length
* (sizeof(struct sockaddr
) + sizeof(struct iw_quality
)))
1945 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSPY \n");
1952 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSPY \n");
1956 #endif // WIRELESS_SPY
1959 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPRIV \n");
1962 if(wrq->u.data.pointer) {
1963 wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
1965 if(copy_to_user(wrq->u.data.pointer,
1966 (u_char *) iwctl_private_args,
1967 sizeof(iwctl_private_args)))
1974 //2008-0409-07, <Add> by Einsn Liu
1975 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1977 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH \n");
1978 rc
= iwctl_siwauth(dev
, NULL
, &(wrq
->u
.param
), NULL
);
1982 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAUTH \n");
1983 rc
= iwctl_giwauth(dev
, NULL
, &(wrq
->u
.param
), NULL
);
1987 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWGENIE \n");
1988 rc
= iwctl_siwgenie(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
1992 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWGENIE \n");
1993 rc
= iwctl_giwgenie(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
1996 case SIOCSIWENCODEEXT
:
1998 char extra
[sizeof(struct iw_encode_ext
)+MAX_KEY_LEN
+1];
1999 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODEEXT \n");
2000 if(wrq
->u
.encoding
.pointer
){
2001 memset(extra
, 0, sizeof(struct iw_encode_ext
)+MAX_KEY_LEN
+1);
2002 if(wrq
->u
.encoding
.length
> (sizeof(struct iw_encode_ext
)+ MAX_KEY_LEN
)){
2006 if(copy_from_user(extra
, wrq
->u
.encoding
.pointer
,wrq
->u
.encoding
.length
)){
2010 }else if(wrq
->u
.encoding
.length
!= 0){
2014 rc
= iwctl_siwencodeext(dev
, NULL
, &(wrq
->u
.encoding
), extra
);
2018 case SIOCGIWENCODEEXT
:
2019 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODEEXT \n");
2020 rc
= iwctl_giwencodeext(dev
, NULL
, &(wrq
->u
.encoding
), NULL
);
2024 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMLME \n");
2025 rc
= iwctl_siwmlme(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
2028 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2029 //End Add -- //2008-0409-07, <Add> by Einsn Liu
2031 case IOCTL_CMD_TEST
:
2033 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
2039 pReq
= (PSCmdRequest
)rq
;
2041 //20080130-01,<Remark> by Mike Liu
2042 // if(pDevice->bLinkPass==TRUE)
2043 pReq
->wResult
= MAGIC_CODE
; //Linking status:0x3142
2044 //20080130-02,<Remark> by Mike Liu
2046 // pReq->wResult = MAGIC_CODE+1; //disconnect status:0x3143
2050 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
) &&
2051 (((PSCmdRequest
)rq
)->wCmdCode
!=WLAN_CMD_SET_WPA
))
2059 if (test_and_set_bit( 0, (void*)&(pMgmt
->uCmdBusy
))) {
2062 rc
= private_ioctl(pDevice
, rq
);
2063 clear_bit( 0, (void*)&(pMgmt
->uCmdBusy
));
2066 case IOCTL_CMD_HOSTAPD
:
2068 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
2075 rc
= hostap_ioctl(pDevice
, &wrq
->u
.data
);
2080 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
2087 rc
= wpa_ioctl(pDevice
, &wrq
->u
.data
);
2091 return ethtool_ioctl(dev
, (void *) rq
->ifr_data
);
2092 // All other calls are currently unsupported
2096 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Ioctl command not support..%x\n", cmd
);
2101 if (pDevice
->bCommit
) {
2102 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
2103 netif_stop_queue(pDevice
->dev
);
2104 spin_lock_irq(&pDevice
->lock
);
2105 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_RUN_AP
, NULL
);
2106 spin_unlock_irq(&pDevice
->lock
);
2109 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Commit the settings\n");
2110 spin_lock_irq(&pDevice
->lock
);
2111 //2007-1121-01<Modify>by EinsnLiu
2112 if (pDevice
->bLinkPass
&&
2113 memcmp(pMgmt
->abyCurrSSID
,pMgmt
->abyDesireSSID
,WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
)) {
2114 bScheduleCommand((HANDLE
)pDevice
, WLAN_CMD_DISASSOCIATE
, NULL
);
2116 pDevice
->bLinkPass
= FALSE
;
2117 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
2118 memset(pMgmt
->abyCurrBSSID
, 0, 6);
2120 ControlvMaskByte(pDevice
,MESSAGE_REQUEST_MACREG
,MAC_REG_PAPEDELAY
,LEDSTS_STS
,LEDSTS_SLOW
);
2122 netif_stop_queue(pDevice
->dev
);
2123 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2124 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
2125 if(pDevice
->bWPASuppWextEnabled
!=TRUE
)
2127 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_BSSID_SCAN
, pMgmt
->abyDesireSSID
);
2128 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_SSID
, NULL
);
2129 spin_unlock_irq(&pDevice
->lock
);
2131 pDevice
->bCommit
= FALSE
;
2139 static int ethtool_ioctl(struct net_device
*dev
, void *useraddr
)
2143 if (copy_from_user(ðcmd
, useraddr
, sizeof(ethcmd
)))
2147 case ETHTOOL_GDRVINFO
: {
2148 struct ethtool_drvinfo info
= {ETHTOOL_GDRVINFO
};
2149 strncpy(info
.driver
, DEVICE_NAME
, sizeof(info
.driver
)-1);
2150 strncpy(info
.version
, DEVICE_VERSION
, sizeof(info
.version
)-1);
2151 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
2162 /*------------------------------------------------------------------*/
2165 MODULE_DEVICE_TABLE(usb
, vntwusb_table
);
2168 static struct usb_driver vntwusb_driver
= {
2169 .name
= DEVICE_NAME
,
2170 .probe
= vntwusb_found1
,
2171 .disconnect
= vntwusb_disconnect
,
2172 .id_table
= vntwusb_table
,
2174 //2008-0920-01<Add>by MikeLiu
2175 //for supporting S3 & S4 function
2177 .suspend
= vntwusb_suspend
,
2178 .resume
= vntwusb_resume
,
2182 static int __init
vntwusb_init_module(void)
2184 printk(KERN_NOTICE DEVICE_FULL_DRV_NAM
" " DEVICE_VERSION
);
2185 return usb_register(&vntwusb_driver
);
2188 static void __exit
vntwusb_cleanup_module(void)
2190 usb_deregister(&vntwusb_driver
);
2193 module_init(vntwusb_init_module
);
2194 module_exit(vntwusb_cleanup_module
);