Merge tag 'staging-3.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[cascardo/linux.git] / drivers / staging / vt6656 / main_usb.c
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
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.
9  *
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.
14  *
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.
18  *
19  * File: main_usb.c
20  *
21  * Purpose: driver entry for initial, open, close, tx and rx.
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: Dec 8, 2005
26  *
27  * Functions:
28  *
29  *   vt6656_probe - module initial (insmod) driver entry
30  *   device_remove1 - module remove entry
31  *   device_open - allocate dma/descripter resource & initial mac/bbp function
32  *   device_xmit - asynchronous data tx function
33  *   device_set_multi - set mac filter
34  *   device_ioctl - ioctl entry
35  *   device_close - shutdown mac/bbp & free dma/descriptor resource
36  *   device_alloc_frag_buf - rx fragement pre-allocated function
37  *   device_free_tx_bufs - free tx buffer function
38  *   device_dma0_tx_80211- tx 802.11 frame via dma0
39  *   device_dma0_xmit- tx PS buffered frame via dma0
40  *   device_init_registers- initial MAC & BBP & RF internal registers.
41  *   device_init_rings- initial tx/rx ring buffer
42  *   device_init_defrag_cb- initial & allocate de-fragement buffer.
43  *   device_tx_srv- tx interrupt service function
44  *
45  * Revision History:
46  */
47 #undef __NO_VERSION__
48
49 #include <linux/file.h>
50 #include "device.h"
51 #include "card.h"
52 #include "baseband.h"
53 #include "mac.h"
54 #include "tether.h"
55 #include "wmgr.h"
56 #include "wctl.h"
57 #include "power.h"
58 #include "wcmd.h"
59 #include "iocmd.h"
60 #include "rxtx.h"
61 #include "bssdb.h"
62 #include "wpactl.h"
63 #include "iwctl.h"
64 #include "dpc.h"
65 #include "datarate.h"
66 #include "rf.h"
67 #include "firmware.h"
68 #include "usbpipe.h"
69 #include "channel.h"
70 #include "int.h"
71 #include "iowpa.h"
72
73 /* static int msglevel = MSG_LEVEL_DEBUG; */
74 static int          msglevel                =MSG_LEVEL_INFO;
75
76 /*
77  * define module options
78  */
79
80 /* version information */
81 #define DRIVER_AUTHOR \
82         "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
83 MODULE_AUTHOR(DRIVER_AUTHOR);
84 MODULE_LICENSE("GPL");
85 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
86
87 #define DEVICE_PARAM(N,D) \
88         static int N[MAX_UINTS]=OPTION_DEFAULT;\
89         module_param_array(N, int, NULL, 0);\
90         MODULE_PARM_DESC(N, D);
91
92 #define RX_DESC_DEF0     64
93 DEVICE_PARAM(RxDescriptors0,"Number of receive usb desc buffer");
94
95 #define TX_DESC_DEF0     64
96 DEVICE_PARAM(TxDescriptors0,"Number of transmit usb desc buffer");
97
98 #define CHANNEL_DEF     6
99 DEVICE_PARAM(Channel, "Channel number");
100
101 /* PreambleType[] is the preamble length used for transmit.
102    0: indicate allows long preamble type
103    1: indicate allows short preamble type
104 */
105
106 #define PREAMBLE_TYPE_DEF     1
107
108 DEVICE_PARAM(PreambleType, "Preamble Type");
109
110 #define RTS_THRESH_DEF     2347
111 DEVICE_PARAM(RTSThreshold, "RTS threshold");
112
113 #define FRAG_THRESH_DEF     2346
114 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
115
116 #define DATA_RATE_DEF     13
117 /* datarate[] index
118    0: indicate 1 Mbps   0x02
119    1: indicate 2 Mbps   0x04
120    2: indicate 5.5 Mbps 0x0B
121    3: indicate 11 Mbps  0x16
122    4: indicate 6 Mbps   0x0c
123    5: indicate 9 Mbps   0x12
124    6: indicate 12 Mbps  0x18
125    7: indicate 18 Mbps  0x24
126    8: indicate 24 Mbps  0x30
127    9: indicate 36 Mbps  0x48
128   10: indicate 48 Mbps  0x60
129   11: indicate 54 Mbps  0x6c
130   12: indicate 72 Mbps  0x90
131   13: indicate auto rate
132 */
133
134 DEVICE_PARAM(ConnectionRate, "Connection data rate");
135
136 #define OP_MODE_DEF     0
137 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
138
139 /* OpMode[] is used for transmit.
140    0: indicate infrastruct mode used
141    1: indicate adhoc mode used
142    2: indicate AP mode used
143 */
144
145 /* PSMode[]
146    0: indicate disable power saving mode
147    1: indicate enable power saving mode
148 */
149
150 #define PS_MODE_DEF     0
151 DEVICE_PARAM(PSMode, "Power saving mode");
152
153 #define SHORT_RETRY_DEF     8
154 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
155
156 #define LONG_RETRY_DEF     4
157 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
158
159 /* BasebandType[] baseband type selected
160    0: indicate 802.11a type
161    1: indicate 802.11b type
162    2: indicate 802.11g type
163 */
164
165 #define BBP_TYPE_DEF     2
166 DEVICE_PARAM(BasebandType, "baseband type");
167
168 /* 80211hEnable[]
169    0: indicate disable 802.11h
170    1: indicate enable 802.11h
171 */
172
173 #define X80211h_MODE_DEF     0
174
175 DEVICE_PARAM(b80211hEnable, "802.11h mode");
176
177 /*
178  * Static vars definitions
179  */
180
181 static struct usb_device_id vt6656_table[] = {
182         {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
183         {}
184 };
185
186 /* frequency list (map channels to frequencies) */
187 /*
188 static const long frequency_list[] = {
189     2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
190     4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
191     5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
192     5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
193     5700, 5745, 5765, 5785, 5805, 5825
194         };
195
196 static const struct iw_handler_def      iwctl_handler_def;
197 */
198
199 static int vt6656_probe(struct usb_interface *intf,
200                         const struct usb_device_id *id);
201 static void vt6656_disconnect(struct usb_interface *intf);
202
203 #ifdef CONFIG_PM        /* Minimal support for suspend and resume */
204 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message);
205 static int vt6656_resume(struct usb_interface *intf);
206 #endif /* CONFIG_PM */
207
208 static struct net_device_stats *device_get_stats(struct net_device *dev);
209 static int  device_open(struct net_device *dev);
210 static int  device_xmit(struct sk_buff *skb, struct net_device *dev);
211 static void device_set_multi(struct net_device *dev);
212 static int  device_close(struct net_device *dev);
213 static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
214
215 static int device_init_registers(struct vnt_private *pDevice);
216 static bool device_init_defrag_cb(struct vnt_private *pDevice);
217
218 static int  ethtool_ioctl(struct net_device *dev, struct ifreq *);
219 static void device_free_tx_bufs(struct vnt_private *pDevice);
220 static void device_free_rx_bufs(struct vnt_private *pDevice);
221 static void device_free_int_bufs(struct vnt_private *pDevice);
222 static void device_free_frag_bufs(struct vnt_private *pDevice);
223 static bool device_alloc_bufs(struct vnt_private *pDevice);
224
225 static int Read_config_file(struct vnt_private *pDevice);
226 static unsigned char *Config_FileOperation(struct vnt_private *pDevice);
227 static int Config_FileGetParameter(unsigned char *string,
228                                    unsigned char *dest,
229                                    unsigned char *source);
230
231 static void usb_device_reset(struct vnt_private *pDevice);
232
233 static void
234 device_set_options(struct vnt_private *pDevice) {
235
236     u8    abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
237     u8    abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
238     u8 abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
239
240     memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
241     memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
242     memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
243
244     pDevice->cbTD = TX_DESC_DEF0;
245     pDevice->cbRD = RX_DESC_DEF0;
246     pDevice->uChannel = CHANNEL_DEF;
247     pDevice->wRTSThreshold = RTS_THRESH_DEF;
248     pDevice->wFragmentationThreshold = FRAG_THRESH_DEF;
249     pDevice->byShortRetryLimit = SHORT_RETRY_DEF;
250     pDevice->byLongRetryLimit = LONG_RETRY_DEF;
251     pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
252     pDevice->byShortPreamble = PREAMBLE_TYPE_DEF;
253     pDevice->ePSMode = PS_MODE_DEF;
254     pDevice->b11hEnable = X80211h_MODE_DEF;
255     pDevice->op_mode = NL80211_IFTYPE_UNSPECIFIED;
256     pDevice->uConnectionRate = DATA_RATE_DEF;
257     if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true;
258     pDevice->byBBType = BBP_TYPE_DEF;
259     pDevice->byPacketType = pDevice->byBBType;
260     pDevice->byAutoFBCtrl = AUTO_FB_0;
261     pDevice->byPreambleType = 0;
262     pDevice->bExistSWNetAddr = false;
263 }
264
265 /*
266  * initialization of MAC & BBP registers
267  */
268 static int device_init_registers(struct vnt_private *pDevice)
269 {
270         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
271         struct vnt_cmd_card_init *init_cmd = &pDevice->init_command;
272         struct vnt_rsp_card_init *init_rsp = &pDevice->init_response;
273         u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
274         u8 abySNAP_RFC1042[ETH_ALEN] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
275         u8 abySNAP_Bridgetunnel[ETH_ALEN]
276                 = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8};
277         u8 byAntenna;
278         int ii;
279         int ntStatus = STATUS_SUCCESS;
280         u8 byTmp;
281         u8 byCalibTXIQ = 0, byCalibTXDC = 0, byCalibRXIQ = 0;
282
283         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n",
284                                 DEVICE_INIT_COLD, pDevice->byPacketType);
285
286         memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
287         memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
288         memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
289
290         if (!FIRMWAREbCheckVersion(pDevice)) {
291                 if (FIRMWAREbDownload(pDevice) == true) {
292                         if (FIRMWAREbBrach2Sram(pDevice) == false) {
293                                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
294                                         " FIRMWAREbBrach2Sram fail\n");
295                                 return false;
296                         }
297                 } else {
298                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
299                                 " FIRMWAREbDownload fail\n");
300                         return false;
301                 }
302         }
303
304         if (!BBbVT3184Init(pDevice)) {
305                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail\n");
306                 return false;
307         }
308
309         init_cmd->init_class = DEVICE_INIT_COLD;
310         init_cmd->exist_sw_net_addr = (u8) pDevice->bExistSWNetAddr;
311         for (ii = 0; ii < 6; ii++)
312                 init_cmd->sw_net_addr[ii] = pDevice->abyCurrentNetAddr[ii];
313         init_cmd->short_retry_limit = pDevice->byShortRetryLimit;
314         init_cmd->long_retry_limit = pDevice->byLongRetryLimit;
315
316         /* issue card_init command to device */
317         ntStatus = vnt_control_out(pDevice,
318                 MESSAGE_TYPE_CARDINIT, 0, 0,
319                 sizeof(struct vnt_cmd_card_init), (u8 *)init_cmd);
320         if (ntStatus != STATUS_SUCCESS) {
321                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail\n");
322                 return false;
323         }
324
325         ntStatus = vnt_control_in(pDevice, MESSAGE_TYPE_INIT_RSP, 0, 0,
326                 sizeof(struct vnt_rsp_card_init), (u8 *)init_rsp);
327         if (ntStatus != STATUS_SUCCESS) {
328                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
329                         "Cardinit request in status fail!\n");
330                 return false;
331         }
332
333         /* local ID for AES functions */
334         ntStatus = vnt_control_in(pDevice, MESSAGE_TYPE_READ,
335                 MAC_REG_LOCALID, MESSAGE_REQUEST_MACREG, 1,
336                         &pDevice->byLocalID);
337         if (ntStatus != STATUS_SUCCESS)
338                 return false;
339
340         /* do MACbSoftwareReset in MACvInitialize */
341
342         pDevice->bProtectMode = false;
343         /* only used in 11g type, sync with ERP IE */
344         pDevice->bNonERPPresent = false;
345         pDevice->bBarkerPreambleMd = false;
346         if (pDevice->bFixRate) {
347                 pDevice->wCurrentRate = (u16)pDevice->uConnectionRate;
348         } else {
349                 if (pDevice->byBBType == BB_TYPE_11B)
350                         pDevice->wCurrentRate = RATE_11M;
351                 else
352                         pDevice->wCurrentRate = RATE_54M;
353         }
354
355         CHvInitChannelTable(pDevice);
356
357         pDevice->byTopOFDMBasicRate = RATE_24M;
358         pDevice->byTopCCKBasicRate = RATE_1M;
359
360         /* target to IF pin while programming to RF chip */
361         pDevice->byCurPwr = 0xFF;
362
363         pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK];
364         pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG];
365         /* load power table */
366         for (ii = 0; ii < 14; ii++) {
367                 pDevice->abyCCKPwrTbl[ii] =
368                         pDevice->abyEEPROM[ii + EEP_OFS_CCK_PWR_TBL];
369
370                 if (pDevice->abyCCKPwrTbl[ii] == 0)
371                         pDevice->abyCCKPwrTbl[ii] = pDevice->byCCKPwr;
372                 pDevice->abyOFDMPwrTbl[ii] =
373                                 pDevice->abyEEPROM[ii + EEP_OFS_OFDM_PWR_TBL];
374                 if (pDevice->abyOFDMPwrTbl[ii] == 0)
375                         pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG;
376         }
377
378         /*
379          * original zonetype is USA, but custom zonetype is Europe,
380          * then need to recover 12, 13, 14 channels with 11 channel
381          */
382         if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
383                 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) &&
384                 (pDevice->byOriginalZonetype == ZoneType_USA)) {
385                 for (ii = 11; ii < 14; ii++) {
386                         pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
387                         pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
388                 }
389         }
390
391         pDevice->byOFDMPwrA = 0x34; /* same as RFbMA2829SelectChannel */
392
393         /* load OFDM A power table */
394         for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
395                 pDevice->abyOFDMAPwrTbl[ii] =
396                         pDevice->abyEEPROM[ii + EEP_OFS_OFDMA_PWR_TBL];
397
398                 if (pDevice->abyOFDMAPwrTbl[ii] == 0)
399                         pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA;
400         }
401
402         byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA];
403
404         if (byAntenna & EEP_ANTINV)
405                 pDevice->bTxRxAntInv = true;
406         else
407                 pDevice->bTxRxAntInv = false;
408
409         byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
410
411         if (byAntenna == 0) /* if not set default is both */
412                 byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
413
414         if (byAntenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
415                 pDevice->byAntennaCount = 2;
416                 pDevice->byTxAntennaMode = ANT_B;
417                 pDevice->dwTxAntennaSel = 1;
418                 pDevice->dwRxAntennaSel = 1;
419
420                 if (pDevice->bTxRxAntInv == true)
421                         pDevice->byRxAntennaMode = ANT_A;
422                 else
423                         pDevice->byRxAntennaMode = ANT_B;
424         } else  {
425                 pDevice->byAntennaCount = 1;
426                 pDevice->dwTxAntennaSel = 0;
427                 pDevice->dwRxAntennaSel = 0;
428
429                 if (byAntenna & EEP_ANTENNA_AUX) {
430                         pDevice->byTxAntennaMode = ANT_A;
431
432                         if (pDevice->bTxRxAntInv == true)
433                                 pDevice->byRxAntennaMode = ANT_B;
434                         else
435                                 pDevice->byRxAntennaMode = ANT_A;
436                 } else {
437                         pDevice->byTxAntennaMode = ANT_B;
438
439                 if (pDevice->bTxRxAntInv == true)
440                         pDevice->byRxAntennaMode = ANT_A;
441                 else
442                         pDevice->byRxAntennaMode = ANT_B;
443                 }
444         }
445
446         /* get Auto Fall Back type */
447         pDevice->byAutoFBCtrl = AUTO_FB_0;
448
449         /* default Auto Mode */
450         /* pDevice->NetworkType = Ndis802_11Automode; */
451         pDevice->eConfigPHYMode = PHY_TYPE_AUTO;
452         pDevice->byBBType = BB_TYPE_11G;
453
454         /* get channel range */
455         pDevice->byMinChannel = 1;
456         pDevice->byMaxChannel = CB_MAX_CHANNEL;
457
458         /* get RFType */
459         pDevice->byRFType = init_rsp->rf_type;
460
461         /* load vt3266 calibration parameters in EEPROM */
462         if (pDevice->byRFType == RF_VT3226D0) {
463                 if ((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) &&
464                         (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) {
465
466                         byCalibTXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_IQ];
467                         byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC];
468                         byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ];
469                         if (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) {
470                         /* CR255, enable TX/RX IQ and DC compensation mode */
471                                 vnt_control_out_u8(pDevice,
472                                         MESSAGE_REQUEST_BBREG,
473                                         0xff,
474                                         0x03);
475                         /* CR251, TX I/Q Imbalance Calibration */
476                                 vnt_control_out_u8(pDevice,
477                                         MESSAGE_REQUEST_BBREG,
478                                         0xfb,
479                                         byCalibTXIQ);
480                         /* CR252, TX DC-Offset Calibration */
481                                 vnt_control_out_u8(pDevice,
482                                         MESSAGE_REQUEST_BBREG,
483                                         0xfC,
484                                         byCalibTXDC);
485                         /* CR253, RX I/Q Imbalance Calibration */
486                                 vnt_control_out_u8(pDevice,
487                                         MESSAGE_REQUEST_BBREG,
488                                         0xfd,
489                                         byCalibRXIQ);
490                         } else {
491                         /* CR255, turn off BB Calibration compensation */
492                                 vnt_control_out_u8(pDevice,
493                                         MESSAGE_REQUEST_BBREG,
494                                         0xff,
495                                         0x0);
496                         }
497                 }
498         }
499
500         pMgmt->eScanType = WMAC_SCAN_PASSIVE;
501         pMgmt->uCurrChannel = pDevice->uChannel;
502         pMgmt->uIBSSChannel = pDevice->uChannel;
503         CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
504
505         /* get permanent network address */
506         memcpy(pDevice->abyPermanentNetAddr, init_rsp->net_addr, 6);
507         memcpy(pDevice->abyCurrentNetAddr,
508                                 pDevice->abyPermanentNetAddr, ETH_ALEN);
509
510         /* if exist SW network address, use it */
511         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n",
512                 pDevice->abyCurrentNetAddr);
513
514         /*
515         * set BB and packet type at the same time
516         * set Short Slot Time, xIFS, and RSPINF
517         */
518         if (pDevice->byBBType == BB_TYPE_11A) {
519                 CARDbAddBasicRate(pDevice, RATE_6M);
520                 pDevice->bShortSlotTime = true;
521         } else {
522                 CARDbAddBasicRate(pDevice, RATE_1M);
523                 pDevice->bShortSlotTime = false;
524         }
525
526         BBvSetShortSlotTime(pDevice);
527         CARDvSetBSSMode(pDevice);
528
529         pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
530         pDevice->byBBVGANew = pDevice->byBBVGACurrent;
531
532         BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
533
534         pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL];
535         pDevice->bHWRadioOff = false;
536
537         if ((pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0) {
538                 ntStatus = vnt_control_in(pDevice, MESSAGE_TYPE_READ,
539                         MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG, 1, &byTmp);
540
541                 if (ntStatus != STATUS_SUCCESS)
542                         return false;
543
544                 if ((byTmp & GPIO3_DATA) == 0) {
545                         pDevice->bHWRadioOff = true;
546                         MACvRegBitsOn(pDevice, MAC_REG_GPIOCTL1, GPIO3_INTMD);
547                 } else {
548                         MACvRegBitsOff(pDevice, MAC_REG_GPIOCTL1, GPIO3_INTMD);
549                         pDevice->bHWRadioOff = false;
550                 }
551
552         }
553
554         vnt_mac_set_led(pDevice, LEDSTS_TMLEN, 0x38);
555
556         vnt_mac_set_led(pDevice, LEDSTS_STS, LEDSTS_SLOW);
557
558         MACvRegBitsOn(pDevice, MAC_REG_GPIOCTL0, 0x01);
559
560         if ((pDevice->bHWRadioOff == true) ||
561                                 (pDevice->bRadioControlOff == true)) {
562                 CARDbRadioPowerOff(pDevice);
563         } else {
564                 CARDbRadioPowerOn(pDevice);
565         }
566
567         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n");
568
569         return true;
570 }
571
572 #ifdef CONFIG_PM        /* Minimal support for suspend and resume */
573
574 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
575 {
576         struct vnt_private *device = usb_get_intfdata(intf);
577
578         if (!device || !device->dev)
579                 return -ENODEV;
580
581         if (device->flags & DEVICE_FLAGS_OPENED)
582                 device_close(device->dev);
583
584         return 0;
585 }
586
587 static int vt6656_resume(struct usb_interface *intf)
588 {
589         struct vnt_private *device = usb_get_intfdata(intf);
590
591         if (!device || !device->dev)
592                 return -ENODEV;
593
594         if (!(device->flags & DEVICE_FLAGS_OPENED))
595                 device_open(device->dev);
596
597         return 0;
598 }
599
600 #endif /* CONFIG_PM */
601
602 static const struct net_device_ops device_netdev_ops = {
603     .ndo_open               = device_open,
604     .ndo_stop               = device_close,
605     .ndo_do_ioctl           = device_ioctl,
606     .ndo_get_stats          = device_get_stats,
607     .ndo_start_xmit         = device_xmit,
608     .ndo_set_rx_mode        = device_set_multi,
609 };
610
611 static int
612 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
613 {
614         u8 fake_mac[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
615         struct usb_device *udev = interface_to_usbdev(intf);
616         int rc = 0;
617         struct net_device *netdev = NULL;
618         struct vnt_private *pDevice;
619
620         printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
621         printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
622
623         udev = usb_get_dev(udev);
624         netdev = alloc_etherdev(sizeof(struct vnt_private));
625         if (!netdev) {
626                 printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n");
627                 rc = -ENOMEM;
628                 goto err_nomem;
629         }
630
631         pDevice = netdev_priv(netdev);
632         memset(pDevice, 0, sizeof(struct vnt_private));
633
634         pDevice->dev = netdev;
635         pDevice->usb = udev;
636
637         device_set_options(pDevice);
638         spin_lock_init(&pDevice->lock);
639         mutex_init(&pDevice->usb_lock);
640
641         INIT_DELAYED_WORK(&pDevice->run_command_work, vRunCommand);
642         INIT_DELAYED_WORK(&pDevice->second_callback_work, BSSvSecondCallBack);
643         INIT_WORK(&pDevice->read_work_item, RXvWorkItem);
644         INIT_WORK(&pDevice->rx_mng_work_item, RXvMngWorkItem);
645
646         pDevice->vnt_mgmt.pAdapter = (void *) pDevice;
647
648         netdev->netdev_ops = &device_netdev_ops;
649         netdev->wireless_handlers =
650                 (struct iw_handler_def *) &iwctl_handler_def;
651
652         usb_set_intfdata(intf, pDevice);
653         SET_NETDEV_DEV(netdev, &intf->dev);
654         memcpy(pDevice->dev->dev_addr, fake_mac, ETH_ALEN);
655
656         usb_device_reset(pDevice);
657
658         rc = register_netdev(netdev);
659         if (rc) {
660                 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
661                 goto err_netdev;
662         }
663
664         return 0;
665
666 err_netdev:
667         free_netdev(netdev);
668 err_nomem:
669         usb_put_dev(udev);
670
671         return rc;
672 }
673
674 static void device_free_tx_bufs(struct vnt_private *priv)
675 {
676         struct vnt_usb_send_context *tx_context;
677         int ii;
678
679         for (ii = 0; ii < priv->cbTD; ii++) {
680                 tx_context = priv->apTD[ii];
681                 /* deallocate URBs */
682                 if (tx_context->urb) {
683                         usb_kill_urb(tx_context->urb);
684                         usb_free_urb(tx_context->urb);
685                 }
686
687                 kfree(tx_context);
688         }
689
690         return;
691 }
692
693 static void device_free_rx_bufs(struct vnt_private *priv)
694 {
695         struct vnt_rcb *rcb;
696         int ii;
697
698         for (ii = 0; ii < priv->cbRD; ii++) {
699                 rcb = priv->apRCB[ii];
700
701                 /* deallocate URBs */
702                 if (rcb->pUrb) {
703                         usb_kill_urb(rcb->pUrb);
704                         usb_free_urb(rcb->pUrb);
705                 }
706
707                 /* deallocate skb */
708                 if (rcb->skb)
709                         dev_kfree_skb(rcb->skb);
710         }
711
712         kfree(priv->pRCBMem);
713
714         return;
715 }
716
717 static void usb_device_reset(struct vnt_private *pDevice)
718 {
719  int status;
720  status = usb_reset_device(pDevice->usb);
721         if (status)
722             printk("usb_device_reset fail status=%d\n",status);
723         return ;
724 }
725
726 static void device_free_int_bufs(struct vnt_private *priv)
727 {
728         kfree(priv->int_buf.data_buf);
729
730         return;
731 }
732
733 static bool device_alloc_bufs(struct vnt_private *priv)
734 {
735         struct vnt_usb_send_context *tx_context;
736         struct vnt_rcb *rcb;
737         int ii;
738
739         for (ii = 0; ii < priv->cbTD; ii++) {
740                 tx_context = kmalloc(sizeof(struct vnt_usb_send_context),
741                                                                 GFP_KERNEL);
742                 if (tx_context == NULL) {
743                         DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
744                                 "%s : allocate tx usb context failed\n",
745                                         priv->dev->name);
746                         goto free_tx;
747                 }
748
749                 priv->apTD[ii] = tx_context;
750                 tx_context->priv = priv;
751
752                 /* allocate URBs */
753                 tx_context->urb = usb_alloc_urb(0, GFP_ATOMIC);
754                 if (!tx_context->urb) {
755                         DBG_PRT(MSG_LEVEL_ERR,
756                                 KERN_ERR "alloc tx urb failed\n");
757                         goto free_tx;
758                 }
759
760                 tx_context->in_use = false;
761         }
762
763         /* allocate RCB mem */
764         priv->pRCBMem = kzalloc((sizeof(struct vnt_rcb) * priv->cbRD),
765                                                                 GFP_KERNEL);
766         if (priv->pRCBMem == NULL) {
767                 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
768                         "%s : alloc rx usb context failed\n",
769                                 priv->dev->name);
770                 goto free_tx;
771         }
772
773         priv->FirstRecvFreeList = NULL;
774         priv->LastRecvFreeList = NULL;
775         priv->FirstRecvMngList = NULL;
776         priv->LastRecvMngList = NULL;
777         priv->NumRecvFreeList = 0;
778
779         rcb = (struct vnt_rcb *)priv->pRCBMem;
780
781         for (ii = 0; ii < priv->cbRD; ii++) {
782                 priv->apRCB[ii] = rcb;
783                 rcb->pDevice = priv;
784
785                 /* allocate URBs */
786                 rcb->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
787                 if (rcb->pUrb == NULL) {
788                         DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
789                                 " Failed to alloc rx urb\n");
790                         goto free_rx_tx;
791                 }
792
793                 rcb->skb = netdev_alloc_skb(priv->dev, priv->rx_buf_sz);
794                 if (rcb->skb == NULL) {
795                         DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
796                                                 " Failed to alloc rx skb\n");
797                         goto free_rx_tx;
798                 }
799
800                 rcb->bBoolInUse = false;
801
802                 EnqueueRCB(priv->FirstRecvFreeList,
803                                                 priv->LastRecvFreeList, rcb);
804
805                 priv->NumRecvFreeList++;
806                 rcb++;
807         }
808
809         priv->pInterruptURB = usb_alloc_urb(0, GFP_ATOMIC);
810         if (priv->pInterruptURB == NULL) {
811                 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR"Failed to alloc int urb\n");
812                 goto free_rx_tx;
813         }
814
815         priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
816         if (priv->int_buf.data_buf == NULL) {
817                 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR"Failed to alloc int buf\n");
818                 usb_free_urb(priv->pInterruptURB);
819                 goto free_rx_tx;
820         }
821
822         return true;
823
824 free_rx_tx:
825         device_free_rx_bufs(priv);
826
827 free_tx:
828         device_free_tx_bufs(priv);
829
830         return false;
831 }
832
833 static bool device_init_defrag_cb(struct vnt_private *pDevice)
834 {
835         int i;
836         PSDeFragControlBlock pDeF;
837
838     /* Init the fragment ctl entries */
839     for (i = 0; i < CB_MAX_RX_FRAG; i++) {
840         pDeF = &(pDevice->sRxDFCB[i]);
841         if (!device_alloc_frag_buf(pDevice, pDeF)) {
842             DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
843                 pDevice->dev->name);
844             goto free_frag;
845         }
846     }
847     pDevice->cbDFCB = CB_MAX_RX_FRAG;
848     pDevice->cbFreeDFCB = pDevice->cbDFCB;
849     return true;
850
851 free_frag:
852     device_free_frag_bufs(pDevice);
853     return false;
854 }
855
856 static void device_free_frag_bufs(struct vnt_private *pDevice)
857 {
858         PSDeFragControlBlock pDeF;
859         int i;
860
861     for (i = 0; i < CB_MAX_RX_FRAG; i++) {
862
863         pDeF = &(pDevice->sRxDFCB[i]);
864
865         if (pDeF->skb)
866             dev_kfree_skb(pDeF->skb);
867     }
868 }
869
870 int device_alloc_frag_buf(struct vnt_private *pDevice,
871                 PSDeFragControlBlock pDeF)
872 {
873         pDeF->skb = netdev_alloc_skb(pDevice->dev, pDevice->rx_buf_sz);
874         if (!pDeF->skb)
875                 return false;
876
877         return true;
878 }
879
880 static int  device_open(struct net_device *dev)
881 {
882         struct vnt_private *pDevice = netdev_priv(dev);
883
884      pDevice->fWPA_Authened = false;
885
886     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");
887
888     pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
889
890     if (device_alloc_bufs(pDevice) == false) {
891         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n");
892         return -ENOMEM;
893     }
894
895     if (device_init_defrag_cb(pDevice)== false) {
896         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n");
897         goto free_rx_tx;
898     }
899
900     MP_CLEAR_FLAG(pDevice, fMP_DISCONNECTED);
901     MP_SET_FLAG(pDevice, fMP_POST_READS);
902     MP_SET_FLAG(pDevice, fMP_POST_WRITES);
903
904     /* read config file */
905     Read_config_file(pDevice);
906
907         if (device_init_registers(pDevice) == false) {
908                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n");
909                 goto free_all;
910         }
911
912     /* init for key management */
913     KeyvInitTable(pDevice,&pDevice->sKey);
914         memcpy(pDevice->vnt_mgmt.abyMACAddr,
915                 pDevice->abyCurrentNetAddr, ETH_ALEN);
916     memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN);
917     pDevice->bStopTx0Pkt = false;
918     pDevice->bStopDataPkt = false;
919     pDevice->bRoaming = false;
920     pDevice->bIsRoaming = false;
921     pDevice->bEnableRoaming = false;
922
923     vMgrObjectInit(pDevice);
924
925         schedule_delayed_work(&pDevice->second_callback_work, HZ);
926
927         pDevice->int_interval = 1;  /* bInterval is set to 1 */
928     pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
929
930     pDevice->bIsRxWorkItemQueued = true;
931
932    pDevice->bWPADEVUp = false;
933      pDevice->bwextstep0 = false;
934      pDevice->bwextstep1 = false;
935      pDevice->bwextstep2 = false;
936      pDevice->bwextstep3 = false;
937      pDevice->bWPASuppWextEnabled = false;
938     pDevice->byReAssocCount = 0;
939
940         schedule_work(&pDevice->read_work_item);
941     INTvWorkItem(pDevice);
942
943     /* if WEP key already set by iwconfig but device not yet open */
944     if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) {
945          KeybSetDefaultKey( pDevice,
946                             &(pDevice->sKey),
947                             pDevice->byKeyIndex | (1 << 31),
948                             pDevice->uKeyLength,
949                             NULL,
950                             pDevice->abyKey,
951                             KEY_CTL_WEP
952                           );
953
954          pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
955     }
956
957         if (pDevice->vnt_mgmt.eConfigMode == WMAC_CONFIG_AP)
958                 bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL);
959         else
960                 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
961
962     netif_stop_queue(pDevice->dev);
963     pDevice->flags |= DEVICE_FLAGS_OPENED;
964
965         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success..\n");
966         return 0;
967
968 free_all:
969     device_free_frag_bufs(pDevice);
970 free_rx_tx:
971     device_free_rx_bufs(pDevice);
972     device_free_tx_bufs(pDevice);
973     device_free_int_bufs(pDevice);
974         usb_kill_urb(pDevice->pInterruptURB);
975     usb_free_urb(pDevice->pInterruptURB);
976
977     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open fail.. \n");
978     return -ENOMEM;
979 }
980
981 static int device_close(struct net_device *dev)
982 {
983         struct vnt_private *pDevice = netdev_priv(dev);
984         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
985         u8 uu;
986
987         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1\n");
988     if (pDevice == NULL)
989         return -ENODEV;
990
991     if (pDevice->bLinkPass) {
992         bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL);
993         mdelay(30);
994     }
995
996         memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
997         pMgmt->bShareKeyAlgorithm = false;
998         pDevice->bEncryptionEnable = false;
999         pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1000
1001         for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1002                 MACvDisableKeyEntry(pDevice,uu);
1003
1004     if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == false) {
1005         MACbShutdown(pDevice);
1006     }
1007     netif_stop_queue(pDevice->dev);
1008     MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
1009     MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES);
1010     MP_CLEAR_FLAG(pDevice, fMP_POST_READS);
1011
1012         cancel_delayed_work_sync(&pDevice->run_command_work);
1013         cancel_delayed_work_sync(&pDevice->second_callback_work);
1014
1015         cancel_work_sync(&pDevice->rx_mng_work_item);
1016         cancel_work_sync(&pDevice->read_work_item);
1017
1018    pDevice->bRoaming = false;
1019    pDevice->bIsRoaming = false;
1020    pDevice->bEnableRoaming = false;
1021     pDevice->bCmdRunning = false;
1022     pDevice->bLinkPass = false;
1023     memset(pMgmt->abyCurrBSSID, 0, 6);
1024     pMgmt->eCurrState = WMAC_STATE_IDLE;
1025
1026         pDevice->flags &= ~DEVICE_FLAGS_OPENED;
1027
1028     device_free_tx_bufs(pDevice);
1029     device_free_rx_bufs(pDevice);
1030     device_free_int_bufs(pDevice);
1031     device_free_frag_bufs(pDevice);
1032
1033         usb_kill_urb(pDevice->pInterruptURB);
1034     usb_free_urb(pDevice->pInterruptURB);
1035
1036     BSSvClearNodeDBTable(pDevice, 0);
1037
1038     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n");
1039
1040     return 0;
1041 }
1042
1043 static void vt6656_disconnect(struct usb_interface *intf)
1044 {
1045         struct vnt_private *device = usb_get_intfdata(intf);
1046
1047         if (!device)
1048                 return;
1049
1050         usb_set_intfdata(intf, NULL);
1051         usb_put_dev(interface_to_usbdev(intf));
1052
1053         device->flags |= DEVICE_FLAGS_UNPLUG;
1054
1055         if (device->dev) {
1056                 unregister_netdev(device->dev);
1057                 free_netdev(device->dev);
1058         }
1059 }
1060
1061 static int device_xmit(struct sk_buff *skb, struct net_device *dev)
1062 {
1063         struct vnt_private *pDevice = netdev_priv(dev);
1064         struct net_device_stats *stats = &pDevice->stats;
1065         unsigned long flags;
1066
1067         spin_lock_irqsave(&pDevice->lock, flags);
1068
1069         netif_stop_queue(dev);
1070
1071         if (!pDevice->bLinkPass) {
1072                 dev_kfree_skb_irq(skb);
1073                 goto out;
1074         }
1075
1076         if (pDevice->bStopDataPkt) {
1077                 dev_kfree_skb_irq(skb);
1078                 stats->tx_dropped++;
1079                 goto out;
1080         }
1081
1082         if (nsDMA_tx_packet(pDevice, skb)) {
1083                 if (netif_queue_stopped(dev))
1084                         netif_wake_queue(dev);
1085         }
1086
1087 out:
1088         spin_unlock_irqrestore(&pDevice->lock, flags);
1089
1090         return NETDEV_TX_OK;
1091 }
1092
1093 /* find out the start position of str2 from str1 */
1094 static unsigned char *kstrstr(const unsigned char *str1,
1095                               const unsigned char *str2) {
1096   int str1_len = strlen(str1);
1097   int str2_len = strlen(str2);
1098
1099   while (str1_len >= str2_len) {
1100        str1_len--;
1101       if(memcmp(str1,str2,str2_len)==0)
1102         return (unsigned char *) str1;
1103         str1++;
1104   }
1105   return NULL;
1106 }
1107
1108 static int Config_FileGetParameter(unsigned char *string,
1109                                    unsigned char *dest,
1110                                    unsigned char *source)
1111 {
1112   unsigned char buf1[100];
1113   unsigned char buf2[100];
1114   unsigned char *start_p = NULL, *end_p = NULL, *tmp_p = NULL;
1115   int ii;
1116
1117     memset(buf1,0,100);
1118     strcat(buf1, string);
1119     strcat(buf1, "=");
1120     source+=strlen(buf1);
1121
1122     /* find target string start point */
1123     start_p = kstrstr(source,buf1);
1124     if (start_p == NULL)
1125         return false;
1126
1127     /* check if current config line is marked by "#" */
1128     for (ii = 1; ; ii++) {
1129         if (memcmp(start_p - ii, "\n", 1) == 0)
1130                 break;
1131         if (memcmp(start_p - ii, "#", 1) == 0)
1132                 return false;
1133     }
1134
1135     /* find target string end point */
1136      end_p = kstrstr(start_p,"\n");
1137      if (end_p == NULL) {       /* can't find "\n", but don't care */
1138              end_p = start_p + strlen(start_p);   /* no include "\n" */
1139      }
1140
1141    memset(buf2,0,100);
1142    memcpy(buf2, start_p, end_p-start_p); /* get the target line */
1143    buf2[end_p-start_p]='\0';
1144
1145    /* find value */
1146    start_p = kstrstr(buf2,"=");
1147    if (start_p == NULL)
1148       return false;
1149    memset(buf1,0,100);
1150    strcpy(buf1,start_p+1);
1151
1152    /* except space */
1153   tmp_p = buf1;
1154   while(*tmp_p != 0x00) {
1155         if(*tmp_p==' ')
1156             tmp_p++;
1157          else
1158           break;
1159   }
1160
1161    memcpy(dest,tmp_p,strlen(tmp_p));
1162  return true;
1163 }
1164
1165 /* if read fails, return NULL, or return data pointer */
1166 static unsigned char *Config_FileOperation(struct vnt_private *pDevice)
1167 {
1168         unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
1169         struct file   *file;
1170
1171         if (!buffer) {
1172                 printk("allocate mem for file fail?\n");
1173                 return NULL;
1174         }
1175
1176         file = filp_open(CONFIG_PATH, O_RDONLY, 0);
1177         if (IS_ERR(file)) {
1178                 kfree(buffer);
1179                 printk("Config_FileOperation file Not exist\n");
1180                 return NULL;
1181         }
1182
1183         if (kernel_read(file, 0, buffer, 1024) < 0) {
1184                 printk("read file error?\n");
1185                 kfree(buffer);
1186                 buffer = NULL;
1187         }
1188
1189         fput(file);
1190         return buffer;
1191 }
1192
1193 /* return --->-1:fail; >=0:successful */
1194 static int Read_config_file(struct vnt_private *pDevice)
1195 {
1196         int result = 0;
1197         unsigned char tmpbuffer[100];
1198         unsigned char *buffer = NULL;
1199
1200         /* init config setting */
1201  pDevice->config_file.ZoneType = -1;
1202  pDevice->config_file.eAuthenMode = -1;
1203  pDevice->config_file.eEncryptionStatus = -1;
1204
1205   buffer = Config_FileOperation(pDevice);
1206   if (buffer == NULL) {
1207      result =-1;
1208      return result;
1209   }
1210
1211 /* get zonetype */
1212 {
1213     memset(tmpbuffer,0,sizeof(tmpbuffer));
1214     if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==true) {
1215     if(memcmp(tmpbuffer,"USA",3)==0) {
1216       pDevice->config_file.ZoneType=ZoneType_USA;
1217     }
1218     else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
1219       pDevice->config_file.ZoneType=ZoneType_Japan;
1220     }
1221     else if(memcmp(tmpbuffer,"EUROPE",6)==0) {
1222      pDevice->config_file.ZoneType=ZoneType_Europe;
1223     }
1224     else {
1225       printk("Unknown Zonetype[%s]?\n",tmpbuffer);
1226    }
1227  }
1228 }
1229
1230 /* get other parameter */
1231   {
1232         memset(tmpbuffer,0,sizeof(tmpbuffer));
1233        if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==true) {
1234          pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10);
1235        }
1236
1237         memset(tmpbuffer,0,sizeof(tmpbuffer));
1238        if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==true) {
1239          pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10);
1240        }
1241   }
1242
1243   kfree(buffer);
1244   return result;
1245 }
1246
1247 static void device_set_multi(struct net_device *dev)
1248 {
1249         struct vnt_private *priv = netdev_priv(dev);
1250         unsigned long flags;
1251
1252         if (priv->flags & DEVICE_FLAGS_OPENED) {
1253                 spin_lock_irqsave(&priv->lock, flags);
1254
1255                 bScheduleCommand(priv, WLAN_CMD_CONFIGURE_FILTER, NULL);
1256
1257                 spin_unlock_irqrestore(&priv->lock, flags);
1258         }
1259 }
1260
1261 void vnt_configure_filter(struct vnt_private *priv)
1262 {
1263         struct net_device *dev = priv->dev;
1264         struct vnt_manager *mgmt = &priv->vnt_mgmt;
1265         struct netdev_hw_addr *ha;
1266         u64 mc_filter = 0;
1267         u8 tmp = 0;
1268         int rc;
1269
1270         rc = vnt_control_in(priv, MESSAGE_TYPE_READ,
1271                 MAC_REG_RCR, MESSAGE_REQUEST_MACREG, 1, &tmp);
1272         if (rc == 0)
1273                 priv->byRxMode = tmp;
1274
1275         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "priv->byRxMode in= %x\n",
1276                                                         priv->byRxMode);
1277
1278         if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
1279                 DBG_PRT(MSG_LEVEL_ERR, KERN_NOTICE
1280                         "%s: Promiscuous mode enabled.\n", dev->name);
1281                 /* unconditionally log net taps */
1282                 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
1283         } else if ((netdev_mc_count(dev) > priv->multicast_limit) ||
1284                         (dev->flags & IFF_ALLMULTI)) {
1285                 mc_filter = ~0x0;
1286                 MACvWriteMultiAddr(priv, mc_filter);
1287
1288                 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1289         } else {
1290                 netdev_for_each_mc_addr(ha, dev) {
1291                         int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1292
1293                         mc_filter |= 1ULL << (bit_nr & 0x3f);
1294                 }
1295
1296                 MACvWriteMultiAddr(priv, mc_filter);
1297
1298                 priv->byRxMode &= ~(RCR_UNICAST);
1299                 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1300         }
1301
1302         if (mgmt->eConfigMode == WMAC_CONFIG_AP) {
1303                 /*
1304                  * If AP mode, don't enable RCR_UNICAST since HW only compares
1305                  * addr1 with local MAC
1306                  */
1307                 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1308                 priv->byRxMode &= ~(RCR_UNICAST);
1309         }
1310
1311         vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
1312                                         MAC_REG_RCR, priv->byRxMode);
1313
1314         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1315                                 "priv->byRxMode out= %x\n", priv->byRxMode);
1316 }
1317
1318 static struct net_device_stats *device_get_stats(struct net_device *dev)
1319 {
1320         struct vnt_private *pDevice = netdev_priv(dev);
1321
1322         return &pDevice->stats;
1323 }
1324
1325 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1326 {
1327         int rc = 0;
1328
1329         switch (cmd) {
1330         case SIOCETHTOOL:
1331                 return ethtool_ioctl(dev, rq);
1332
1333         }
1334
1335         return rc;
1336 }
1337
1338 static int ethtool_ioctl(struct net_device *dev, struct ifreq *rq)
1339 {
1340         u32 ethcmd;
1341
1342         if (copy_from_user(&ethcmd, rq->ifr_data, sizeof(ethcmd)))
1343                 return -EFAULT;
1344
1345         switch (ethcmd) {
1346         case ETHTOOL_GDRVINFO: {
1347                 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
1348                 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
1349                 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
1350                 if (copy_to_user(rq->ifr_data, &info, sizeof(info)))
1351                         return -EFAULT;
1352                 return 0;
1353         }
1354
1355         }
1356
1357         return -EOPNOTSUPP;
1358 }
1359
1360 MODULE_DEVICE_TABLE(usb, vt6656_table);
1361
1362 static struct usb_driver vt6656_driver = {
1363         .name =         DEVICE_NAME,
1364         .probe =        vt6656_probe,
1365         .disconnect =   vt6656_disconnect,
1366         .id_table =     vt6656_table,
1367 #ifdef CONFIG_PM
1368         .suspend = vt6656_suspend,
1369         .resume = vt6656_resume,
1370 #endif /* CONFIG_PM */
1371 };
1372
1373 module_usb_driver(vt6656_driver);