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 * 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
49 #include <linux/file.h>
73 /* static int msglevel = MSG_LEVEL_DEBUG; */
74 static int msglevel =MSG_LEVEL_INFO;
77 * define module options
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);
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);
92 #define RX_DESC_DEF0 64
93 DEVICE_PARAM(RxDescriptors0,"Number of receive usb desc buffer");
95 #define TX_DESC_DEF0 64
96 DEVICE_PARAM(TxDescriptors0,"Number of transmit usb desc buffer");
99 DEVICE_PARAM(Channel, "Channel number");
101 /* PreambleType[] is the preamble length used for transmit.
102 0: indicate allows long preamble type
103 1: indicate allows short preamble type
106 #define PREAMBLE_TYPE_DEF 1
108 DEVICE_PARAM(PreambleType, "Preamble Type");
110 #define RTS_THRESH_DEF 2347
111 DEVICE_PARAM(RTSThreshold, "RTS threshold");
113 #define FRAG_THRESH_DEF 2346
114 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
116 #define DATA_RATE_DEF 13
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
134 DEVICE_PARAM(ConnectionRate, "Connection data rate");
136 #define OP_MODE_DEF 0
137 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
139 /* OpMode[] is used for transmit.
140 0: indicate infrastruct mode used
141 1: indicate adhoc mode used
142 2: indicate AP mode used
146 0: indicate disable power saving mode
147 1: indicate enable power saving mode
150 #define PS_MODE_DEF 0
151 DEVICE_PARAM(PSMode, "Power saving mode");
153 #define SHORT_RETRY_DEF 8
154 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
156 #define LONG_RETRY_DEF 4
157 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
159 /* BasebandType[] baseband type selected
160 0: indicate 802.11a type
161 1: indicate 802.11b type
162 2: indicate 802.11g type
165 #define BBP_TYPE_DEF 2
166 DEVICE_PARAM(BasebandType, "baseband type");
169 0: indicate disable 802.11h
170 1: indicate enable 802.11h
173 #define X80211h_MODE_DEF 0
175 DEVICE_PARAM(b80211hEnable, "802.11h mode");
178 * Static vars definitions
181 static struct usb_device_id vt6656_table[] = {
182 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
186 /* frequency list (map channels to frequencies) */
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
196 static const struct iw_handler_def iwctl_handler_def;
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);
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 */
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);
215 static int device_init_registers(struct vnt_private *pDevice);
216 static bool device_init_defrag_cb(struct vnt_private *pDevice);
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);
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,
229 unsigned char *source);
231 static void usb_device_reset(struct vnt_private *pDevice);
234 device_set_options(struct vnt_private *pDevice) {
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};
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);
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;
266 * initialization of MAC & BBP registers
268 static int device_init_registers(struct vnt_private *pDevice)
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};
279 int ntStatus = STATUS_SUCCESS;
281 u8 byCalibTXIQ = 0, byCalibTXDC = 0, byCalibRXIQ = 0;
283 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n",
284 DEVICE_INIT_COLD, pDevice->byPacketType);
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);
290 if (!vnt_check_firmware_version(pDevice)) {
291 if (vnt_download_firmware(pDevice) == true) {
292 if (vnt_firmware_branch_to_sram(pDevice) == false) {
293 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
294 " vnt_firmware_branch_to_sram fail\n");
298 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
299 " FIRMWAREbDownload fail\n");
304 if (!BBbVT3184Init(pDevice)) {
305 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail\n");
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;
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");
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");
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)
340 /* do MACbSoftwareReset in MACvInitialize */
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;
349 if (pDevice->byBBType == BB_TYPE_11B)
350 pDevice->wCurrentRate = RATE_11M;
352 pDevice->wCurrentRate = RATE_54M;
355 CHvInitChannelTable(pDevice);
357 pDevice->byTopOFDMBasicRate = RATE_24M;
358 pDevice->byTopCCKBasicRate = RATE_1M;
360 /* target to IF pin while programming to RF chip */
361 pDevice->byCurPwr = 0xFF;
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];
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;
379 * original zonetype is USA, but custom zonetype is Europe,
380 * then need to recover 12, 13, 14 channels with 11 channel
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];
391 pDevice->byOFDMPwrA = 0x34; /* same as RFbMA2829SelectChannel */
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];
398 if (pDevice->abyOFDMAPwrTbl[ii] == 0)
399 pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA;
402 byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA];
404 if (byAntenna & EEP_ANTINV)
405 pDevice->bTxRxAntInv = true;
407 pDevice->bTxRxAntInv = false;
409 byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
411 if (byAntenna == 0) /* if not set default is both */
412 byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
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;
420 if (pDevice->bTxRxAntInv == true)
421 pDevice->byRxAntennaMode = ANT_A;
423 pDevice->byRxAntennaMode = ANT_B;
425 pDevice->byAntennaCount = 1;
426 pDevice->dwTxAntennaSel = 0;
427 pDevice->dwRxAntennaSel = 0;
429 if (byAntenna & EEP_ANTENNA_AUX) {
430 pDevice->byTxAntennaMode = ANT_A;
432 if (pDevice->bTxRxAntInv == true)
433 pDevice->byRxAntennaMode = ANT_B;
435 pDevice->byRxAntennaMode = ANT_A;
437 pDevice->byTxAntennaMode = ANT_B;
439 if (pDevice->bTxRxAntInv == true)
440 pDevice->byRxAntennaMode = ANT_A;
442 pDevice->byRxAntennaMode = ANT_B;
446 /* get Auto Fall Back type */
447 pDevice->byAutoFBCtrl = AUTO_FB_0;
449 /* default Auto Mode */
450 /* pDevice->NetworkType = Ndis802_11Automode; */
451 pDevice->eConfigPHYMode = PHY_TYPE_AUTO;
452 pDevice->byBBType = BB_TYPE_11G;
454 /* get channel range */
455 pDevice->byMinChannel = 1;
456 pDevice->byMaxChannel = CB_MAX_CHANNEL;
459 pDevice->byRFType = init_rsp->rf_type;
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)) {
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,
475 /* CR251, TX I/Q Imbalance Calibration */
476 vnt_control_out_u8(pDevice,
477 MESSAGE_REQUEST_BBREG,
480 /* CR252, TX DC-Offset Calibration */
481 vnt_control_out_u8(pDevice,
482 MESSAGE_REQUEST_BBREG,
485 /* CR253, RX I/Q Imbalance Calibration */
486 vnt_control_out_u8(pDevice,
487 MESSAGE_REQUEST_BBREG,
491 /* CR255, turn off BB Calibration compensation */
492 vnt_control_out_u8(pDevice,
493 MESSAGE_REQUEST_BBREG,
500 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
501 pMgmt->uCurrChannel = pDevice->uChannel;
502 pMgmt->uIBSSChannel = pDevice->uChannel;
504 vnt_set_channel(pDevice, pMgmt->uCurrChannel);
506 /* get permanent network address */
507 memcpy(pDevice->abyPermanentNetAddr, init_rsp->net_addr, 6);
508 memcpy(pDevice->abyCurrentNetAddr,
509 pDevice->abyPermanentNetAddr, ETH_ALEN);
511 /* if exist SW network address, use it */
512 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n",
513 pDevice->abyCurrentNetAddr);
516 * set BB and packet type at the same time
517 * set Short Slot Time, xIFS, and RSPINF
519 if (pDevice->byBBType == BB_TYPE_11A) {
520 vnt_add_basic_rate(pDevice, RATE_6M);
521 pDevice->bShortSlotTime = true;
523 vnt_add_basic_rate(pDevice, RATE_1M);
524 pDevice->bShortSlotTime = false;
527 BBvSetShortSlotTime(pDevice);
528 vnt_set_bss_mode(pDevice);
530 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
531 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
533 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
535 pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL];
536 pDevice->bHWRadioOff = false;
538 if ((pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0) {
539 ntStatus = vnt_control_in(pDevice, MESSAGE_TYPE_READ,
540 MAC_REG_GPIOCTL1, MESSAGE_REQUEST_MACREG, 1, &byTmp);
542 if (ntStatus != STATUS_SUCCESS)
545 if ((byTmp & GPIO3_DATA) == 0) {
546 pDevice->bHWRadioOff = true;
547 vnt_mac_reg_bits_on(pDevice, MAC_REG_GPIOCTL1,
550 vnt_mac_reg_bits_off(pDevice, MAC_REG_GPIOCTL1,
552 pDevice->bHWRadioOff = false;
557 vnt_mac_set_led(pDevice, LEDSTS_TMLEN, 0x38);
559 vnt_mac_set_led(pDevice, LEDSTS_STS, LEDSTS_SLOW);
561 vnt_mac_reg_bits_on(pDevice, MAC_REG_GPIOCTL0, 0x01);
563 if ((pDevice->bHWRadioOff == true) ||
564 (pDevice->bRadioControlOff == true)) {
565 vnt_radio_power_off(pDevice);
567 vnt_radio_power_on(pDevice);
570 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n");
575 static const struct net_device_ops device_netdev_ops = {
576 .ndo_open = device_open,
577 .ndo_stop = device_close,
578 .ndo_do_ioctl = device_ioctl,
579 .ndo_get_stats = device_get_stats,
580 .ndo_start_xmit = device_xmit,
581 .ndo_set_rx_mode = device_set_multi,
584 static void device_free_tx_bufs(struct vnt_private *priv)
586 struct vnt_usb_send_context *tx_context;
589 for (ii = 0; ii < priv->cbTD; ii++) {
590 tx_context = priv->apTD[ii];
591 /* deallocate URBs */
592 if (tx_context->urb) {
593 usb_kill_urb(tx_context->urb);
594 usb_free_urb(tx_context->urb);
603 static void device_free_rx_bufs(struct vnt_private *priv)
608 for (ii = 0; ii < priv->cbRD; ii++) {
609 rcb = priv->apRCB[ii];
611 /* deallocate URBs */
613 usb_kill_urb(rcb->pUrb);
614 usb_free_urb(rcb->pUrb);
619 dev_kfree_skb(rcb->skb);
622 kfree(priv->pRCBMem);
627 static void usb_device_reset(struct vnt_private *pDevice)
630 status = usb_reset_device(pDevice->usb);
632 printk("usb_device_reset fail status=%d\n",status);
636 static void device_free_int_bufs(struct vnt_private *priv)
638 kfree(priv->int_buf.data_buf);
643 static bool device_alloc_bufs(struct vnt_private *priv)
645 struct vnt_usb_send_context *tx_context;
649 for (ii = 0; ii < priv->cbTD; ii++) {
650 tx_context = kmalloc(sizeof(struct vnt_usb_send_context),
652 if (tx_context == NULL) {
653 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
654 "%s : allocate tx usb context failed\n",
659 priv->apTD[ii] = tx_context;
660 tx_context->priv = priv;
663 tx_context->urb = usb_alloc_urb(0, GFP_ATOMIC);
664 if (!tx_context->urb) {
665 DBG_PRT(MSG_LEVEL_ERR,
666 KERN_ERR "alloc tx urb failed\n");
670 tx_context->in_use = false;
673 /* allocate RCB mem */
674 priv->pRCBMem = kzalloc((sizeof(struct vnt_rcb) * priv->cbRD),
676 if (priv->pRCBMem == NULL) {
677 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
678 "%s : alloc rx usb context failed\n",
683 priv->FirstRecvFreeList = NULL;
684 priv->LastRecvFreeList = NULL;
685 priv->FirstRecvMngList = NULL;
686 priv->LastRecvMngList = NULL;
687 priv->NumRecvFreeList = 0;
689 rcb = (struct vnt_rcb *)priv->pRCBMem;
691 for (ii = 0; ii < priv->cbRD; ii++) {
692 priv->apRCB[ii] = rcb;
696 rcb->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
697 if (rcb->pUrb == NULL) {
698 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
699 " Failed to alloc rx urb\n");
703 rcb->skb = dev_alloc_skb(priv->rx_buf_sz);
704 if (rcb->skb == NULL) {
705 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
706 " Failed to alloc rx skb\n");
710 rcb->bBoolInUse = false;
712 EnqueueRCB(priv->FirstRecvFreeList,
713 priv->LastRecvFreeList, rcb);
715 priv->NumRecvFreeList++;
719 priv->pInterruptURB = usb_alloc_urb(0, GFP_ATOMIC);
720 if (priv->pInterruptURB == NULL) {
721 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR"Failed to alloc int urb\n");
725 priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
726 if (priv->int_buf.data_buf == NULL) {
727 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR"Failed to alloc int buf\n");
728 usb_free_urb(priv->pInterruptURB);
735 device_free_rx_bufs(priv);
738 device_free_tx_bufs(priv);
743 static bool device_init_defrag_cb(struct vnt_private *pDevice)
746 PSDeFragControlBlock pDeF;
748 /* Init the fragment ctl entries */
749 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
750 pDeF = &(pDevice->sRxDFCB[i]);
751 if (!device_alloc_frag_buf(pDevice, pDeF)) {
752 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
757 pDevice->cbDFCB = CB_MAX_RX_FRAG;
758 pDevice->cbFreeDFCB = pDevice->cbDFCB;
762 device_free_frag_bufs(pDevice);
766 static void device_free_frag_bufs(struct vnt_private *pDevice)
768 PSDeFragControlBlock pDeF;
771 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
773 pDeF = &(pDevice->sRxDFCB[i]);
776 dev_kfree_skb(pDeF->skb);
780 int device_alloc_frag_buf(struct vnt_private *pDevice,
781 PSDeFragControlBlock pDeF)
783 pDeF->skb = netdev_alloc_skb(pDevice->dev, pDevice->rx_buf_sz);
790 static int device_open(struct net_device *dev)
792 struct vnt_private *pDevice = netdev_priv(dev);
794 pDevice->fWPA_Authened = false;
796 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");
798 pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
800 if (device_alloc_bufs(pDevice) == false) {
801 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n");
805 if (device_init_defrag_cb(pDevice)== false) {
806 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n");
810 MP_CLEAR_FLAG(pDevice, fMP_DISCONNECTED);
811 MP_SET_FLAG(pDevice, fMP_POST_READS);
812 MP_SET_FLAG(pDevice, fMP_POST_WRITES);
814 /* read config file */
815 Read_config_file(pDevice);
817 if (device_init_registers(pDevice) == false) {
818 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n");
822 /* init for key management */
823 KeyvInitTable(pDevice,&pDevice->sKey);
824 memcpy(pDevice->vnt_mgmt.abyMACAddr,
825 pDevice->abyCurrentNetAddr, ETH_ALEN);
826 memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN);
827 pDevice->bStopTx0Pkt = false;
828 pDevice->bStopDataPkt = false;
829 pDevice->bRoaming = false;
830 pDevice->bIsRoaming = false;
831 pDevice->bEnableRoaming = false;
833 vMgrObjectInit(pDevice);
835 schedule_delayed_work(&pDevice->second_callback_work, HZ);
837 pDevice->int_interval = 1; /* bInterval is set to 1 */
838 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
840 pDevice->bIsRxWorkItemQueued = true;
842 pDevice->bWPADEVUp = false;
843 pDevice->bwextstep0 = false;
844 pDevice->bwextstep1 = false;
845 pDevice->bwextstep2 = false;
846 pDevice->bwextstep3 = false;
847 pDevice->bWPASuppWextEnabled = false;
848 pDevice->byReAssocCount = 0;
850 schedule_work(&pDevice->read_work_item);
851 INTvWorkItem(pDevice);
853 /* if WEP key already set by iwconfig but device not yet open */
854 if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) {
855 KeybSetDefaultKey( pDevice,
857 pDevice->byKeyIndex | (1 << 31),
864 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
867 if (pDevice->vnt_mgmt.eConfigMode == WMAC_CONFIG_AP)
868 bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL);
870 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
872 netif_stop_queue(pDevice->dev);
873 pDevice->flags |= DEVICE_FLAGS_OPENED;
875 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success..\n");
879 device_free_frag_bufs(pDevice);
881 device_free_rx_bufs(pDevice);
882 device_free_tx_bufs(pDevice);
883 device_free_int_bufs(pDevice);
884 usb_kill_urb(pDevice->pInterruptURB);
885 usb_free_urb(pDevice->pInterruptURB);
887 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open fail.. \n");
891 static int device_close(struct net_device *dev)
893 struct vnt_private *pDevice = netdev_priv(dev);
894 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
897 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1\n");
901 if (pDevice->bLinkPass) {
902 bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL);
906 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
907 pMgmt->bShareKeyAlgorithm = false;
908 pDevice->bEncryptionEnable = false;
909 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
911 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
912 vnt_mac_disable_keyentry(pDevice, uu);
914 if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == false)
915 vnt_mac_shutdown(pDevice);
917 netif_stop_queue(pDevice->dev);
918 MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
919 MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES);
920 MP_CLEAR_FLAG(pDevice, fMP_POST_READS);
922 cancel_delayed_work_sync(&pDevice->run_command_work);
923 cancel_delayed_work_sync(&pDevice->second_callback_work);
925 cancel_work_sync(&pDevice->rx_mng_work_item);
926 cancel_work_sync(&pDevice->read_work_item);
928 pDevice->bRoaming = false;
929 pDevice->bIsRoaming = false;
930 pDevice->bEnableRoaming = false;
931 pDevice->bCmdRunning = false;
932 pDevice->bLinkPass = false;
933 memset(pMgmt->abyCurrBSSID, 0, 6);
934 pMgmt->eCurrState = WMAC_STATE_IDLE;
936 pDevice->flags &= ~DEVICE_FLAGS_OPENED;
938 device_free_tx_bufs(pDevice);
939 device_free_rx_bufs(pDevice);
940 device_free_int_bufs(pDevice);
941 device_free_frag_bufs(pDevice);
943 usb_kill_urb(pDevice->pInterruptURB);
944 usb_free_urb(pDevice->pInterruptURB);
946 BSSvClearNodeDBTable(pDevice, 0);
948 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n");
953 static void vnt_tx_80211(struct ieee80211_hw *hw,
954 struct ieee80211_tx_control *control, struct sk_buff *skb)
956 struct vnt_private *priv = hw->priv;
958 ieee80211_stop_queues(hw);
960 if (vnt_tx_packet(priv, skb)) {
961 ieee80211_free_txskb(hw, skb);
963 ieee80211_wake_queues(hw);
967 static int vnt_start(struct ieee80211_hw *hw)
969 struct vnt_private *priv = hw->priv;
971 priv->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
973 if (device_alloc_bufs(priv) == false) {
974 dev_dbg(&priv->usb->dev, "device_alloc_bufs fail...\n");
978 MP_CLEAR_FLAG(priv, fMP_DISCONNECTED);
979 MP_SET_FLAG(priv, fMP_POST_READS);
980 MP_SET_FLAG(priv, fMP_POST_WRITES);
982 if (device_init_registers(priv) == false) {
983 dev_dbg(&priv->usb->dev, " init register fail\n");
987 priv->int_interval = 1; /* bInterval is set to 1 */
989 schedule_work(&priv->read_work_item);
992 priv->flags |= DEVICE_FLAGS_OPENED;
994 ieee80211_wake_queues(hw);
999 device_free_rx_bufs(priv);
1000 device_free_tx_bufs(priv);
1001 device_free_int_bufs(priv);
1003 usb_kill_urb(priv->pInterruptURB);
1004 usb_free_urb(priv->pInterruptURB);
1009 static void vnt_stop(struct ieee80211_hw *hw)
1011 struct vnt_private *priv = hw->priv;
1017 for (i = 0; i < MAX_KEY_TABLE; i++)
1018 vnt_mac_disable_keyentry(priv, i);
1020 /* clear all keys */
1021 priv->key_entry_inuse = 0;
1023 if ((priv->flags & DEVICE_FLAGS_UNPLUG) == false)
1024 vnt_mac_shutdown(priv);
1026 ieee80211_stop_queues(hw);
1028 MP_SET_FLAG(priv, fMP_DISCONNECTED);
1029 MP_CLEAR_FLAG(priv, fMP_POST_WRITES);
1030 MP_CLEAR_FLAG(priv, fMP_POST_READS);
1032 cancel_delayed_work_sync(&priv->run_command_work);
1033 cancel_work_sync(&priv->read_work_item);
1035 priv->bCmdRunning = false;
1037 priv->flags &= ~DEVICE_FLAGS_OPENED;
1039 device_free_tx_bufs(priv);
1040 device_free_rx_bufs(priv);
1041 device_free_int_bufs(priv);
1043 usb_kill_urb(priv->pInterruptURB);
1044 usb_free_urb(priv->pInterruptURB);
1049 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1051 struct vnt_private *priv = hw->priv;
1055 switch (vif->type) {
1056 case NL80211_IFTYPE_STATION:
1058 case NL80211_IFTYPE_ADHOC:
1059 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
1061 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1064 case NL80211_IFTYPE_AP:
1065 vnt_mac_reg_bits_off(priv, MAC_REG_RCR, RCR_UNICAST);
1067 vnt_mac_reg_bits_on(priv, MAC_REG_HOSTCR, HOSTCR_AP);
1074 priv->op_mode = vif->type;
1076 /* LED blink on TX */
1077 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_INTER);
1082 static void vnt_remove_interface(struct ieee80211_hw *hw,
1083 struct ieee80211_vif *vif)
1085 struct vnt_private *priv = hw->priv;
1087 switch (vif->type) {
1088 case NL80211_IFTYPE_STATION:
1090 case NL80211_IFTYPE_ADHOC:
1091 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1092 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1093 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1095 case NL80211_IFTYPE_AP:
1096 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1097 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1098 vnt_mac_reg_bits_off(priv, MAC_REG_HOSTCR, HOSTCR_AP);
1104 vnt_radio_power_off(priv);
1106 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
1108 /* LED slow blink */
1109 vnt_mac_set_led(priv, LEDSTS_STS, LEDSTS_SLOW);
1114 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
1116 struct vnt_private *priv = hw->priv;
1117 struct ieee80211_conf *conf = &hw->conf;
1120 if (changed & IEEE80211_CONF_CHANGE_PS) {
1121 if (conf->flags & IEEE80211_CONF_PS)
1122 vnt_enable_power_saving(priv, conf->listen_interval);
1124 vnt_disable_power_saving(priv);
1127 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
1128 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
1129 vnt_set_channel(priv, conf->chandef.chan->hw_value);
1131 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
1132 bb_type = BB_TYPE_11A;
1134 bb_type = BB_TYPE_11G;
1136 if (priv->byBBType != bb_type) {
1137 priv->byBBType = bb_type;
1139 vnt_set_bss_mode(priv);
1143 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1144 if (priv->byBBType == BB_TYPE_11B)
1145 priv->wCurrentRate = RATE_1M;
1147 priv->wCurrentRate = RATE_54M;
1149 vnt_rf_setpower(priv, priv->wCurrentRate,
1150 conf->chandef.chan->hw_value);
1156 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
1157 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
1160 struct vnt_private *priv = hw->priv;
1161 priv->current_aid = conf->aid;
1163 if (changed & BSS_CHANGED_BSSID)
1164 vnt_mac_set_bssid_addr(priv, (u8 *)conf->bssid);
1167 if (changed & BSS_CHANGED_BASIC_RATES) {
1168 priv->wBasicRate = conf->basic_rates;
1170 vnt_update_top_rates(priv);
1172 dev_dbg(&priv->usb->dev, "basic rates %x\n", conf->basic_rates);
1175 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1176 if (conf->use_short_preamble) {
1177 vnt_mac_enable_barker_preamble_mode(priv);
1178 priv->byPreambleType = true;
1180 vnt_mac_disable_barker_preamble_mode(priv);
1181 priv->byPreambleType = false;
1185 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1186 if (conf->use_cts_prot)
1187 vnt_mac_enable_protect_mode(priv);
1189 vnt_mac_disable_protect_mode(priv);
1192 if (changed & BSS_CHANGED_ERP_SLOT) {
1193 if (conf->use_short_slot)
1194 priv->bShortSlotTime = true;
1196 priv->bShortSlotTime = false;
1198 BBvSetShortSlotTime(priv);
1199 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
1200 BBvUpdatePreEDThreshold(priv, false);
1203 if (changed & BSS_CHANGED_TXPOWER)
1204 vnt_rf_setpower(priv, priv->wCurrentRate,
1205 conf->chandef.chan->hw_value);
1207 if (changed & BSS_CHANGED_BEACON_ENABLED) {
1208 dev_dbg(&priv->usb->dev,
1209 "Beacon enable %d\n", conf->enable_beacon);
1211 if (conf->enable_beacon) {
1212 vnt_beacon_enable(priv, vif, conf);
1214 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1216 vnt_mac_reg_bits_off(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1221 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
1222 struct netdev_hw_addr_list *mc_list)
1224 struct vnt_private *priv = hw->priv;
1225 struct netdev_hw_addr *ha;
1229 netdev_hw_addr_list_for_each(ha, mc_list) {
1230 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1232 mc_filter |= 1ULL << (bit_nr & 0x3f);
1235 priv->mc_list_count = mc_list->count;
1240 static void vnt_configure(struct ieee80211_hw *hw,
1241 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
1243 struct vnt_private *priv = hw->priv;
1247 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS |
1248 FIF_BCN_PRBRESP_PROMISC;
1250 rc = vnt_control_in(priv, MESSAGE_TYPE_READ, MAC_REG_RCR,
1251 MESSAGE_REQUEST_MACREG, sizeof(u8), &rx_mode);
1254 rx_mode = RCR_MULTICAST | RCR_BROADCAST;
1256 dev_dbg(&priv->usb->dev, "rx mode in = %x\n", rx_mode);
1258 if (changed_flags & FIF_PROMISC_IN_BSS) {
1259 /* unconditionally log net taps */
1260 if (*total_flags & FIF_PROMISC_IN_BSS)
1261 rx_mode |= RCR_UNICAST;
1263 rx_mode &= ~RCR_UNICAST;
1266 if (changed_flags & FIF_ALLMULTI) {
1267 if (*total_flags & FIF_ALLMULTI) {
1268 if (priv->mc_list_count > 2)
1269 vnt_mac_set_filter(priv, ~0);
1271 vnt_mac_set_filter(priv, multicast);
1273 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1275 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
1280 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
1281 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
1282 rx_mode &= ~RCR_BSSID;
1284 rx_mode |= RCR_BSSID;
1287 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, rx_mode);
1289 dev_dbg(&priv->usb->dev, "rx mode out= %x\n", rx_mode);
1294 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1295 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1296 struct ieee80211_key_conf *key)
1298 struct vnt_private *priv = hw->priv;
1302 if (vnt_set_keys(hw, sta, vif, key))
1306 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
1307 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
1315 static void vnt_sw_scan_start(struct ieee80211_hw *hw)
1317 struct vnt_private *priv = hw->priv;
1319 /* Set max sensitivity*/
1320 BBvUpdatePreEDThreshold(priv, true);
1323 static void vnt_sw_scan_complete(struct ieee80211_hw *hw)
1325 struct vnt_private *priv = hw->priv;
1327 /* Return sensitivity to channel level*/
1328 BBvUpdatePreEDThreshold(priv, false);
1331 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1333 struct vnt_private *priv = hw->priv;
1335 return priv->qwCurrTSF;
1338 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1341 struct vnt_private *priv = hw->priv;
1343 vnt_update_next_tbtt(priv, tsf, vif->bss_conf.beacon_int);
1346 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1348 struct vnt_private *priv = hw->priv;
1350 vnt_mac_reg_bits_off(priv, MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1352 vnt_clear_current_tsf(priv);
1355 static const struct ieee80211_ops vnt_mac_ops = {
1359 .add_interface = vnt_add_interface,
1360 .remove_interface = vnt_remove_interface,
1361 .config = vnt_config,
1362 .bss_info_changed = vnt_bss_info_changed,
1363 .prepare_multicast = vnt_prepare_multicast,
1364 .configure_filter = vnt_configure,
1365 .set_key = vnt_set_key,
1366 .sw_scan_start = vnt_sw_scan_start,
1367 .sw_scan_complete = vnt_sw_scan_complete,
1368 .get_tsf = vnt_get_tsf,
1369 .set_tsf = vnt_set_tsf,
1370 .reset_tsf = vnt_reset_tsf,
1373 int vnt_init(struct vnt_private *priv)
1376 if (!(device_init_registers(priv)))
1379 SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyPermanentNetAddr);
1381 vnt_init_bands(priv);
1383 if (ieee80211_register_hw(priv->hw))
1390 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
1392 struct usb_device *udev;
1393 struct vnt_private *priv;
1394 struct ieee80211_hw *hw;
1395 struct wiphy *wiphy;
1398 udev = usb_get_dev(interface_to_usbdev(intf));
1400 dev_notice(&udev->dev, "%s Ver. %s\n",
1401 DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1402 dev_notice(&udev->dev,
1403 "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
1405 hw = ieee80211_alloc_hw(sizeof(struct vnt_private), &vnt_mac_ops);
1407 dev_err(&udev->dev, "could not register ieee80211_hw\n");
1415 device_set_options(priv);
1417 spin_lock_init(&priv->lock);
1418 mutex_init(&priv->usb_lock);
1420 INIT_DELAYED_WORK(&priv->run_command_work, vRunCommand);
1421 INIT_WORK(&priv->read_work_item, RXvWorkItem);
1423 priv->vnt_mgmt.pAdapter = priv;
1425 usb_set_intfdata(intf, priv);
1427 wiphy = priv->hw->wiphy;
1429 wiphy->frag_threshold = FRAG_THRESH_DEF;
1430 wiphy->rts_threshold = RTS_THRESH_DEF;
1431 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1432 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1434 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1435 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
1436 IEEE80211_HW_SIGNAL_DBM |
1437 IEEE80211_HW_TIMING_BEACON_ONLY;
1439 priv->hw->rate_control_algorithm = "pid";
1440 priv->hw->max_signal = 100;
1442 SET_IEEE80211_DEV(priv->hw, &intf->dev);
1444 usb_device_reset(priv);
1454 static void vt6656_disconnect(struct usb_interface *intf)
1456 struct vnt_private *priv = usb_get_intfdata(intf);
1461 ieee80211_unregister_hw(priv->hw);
1463 usb_set_intfdata(intf, NULL);
1464 usb_put_dev(interface_to_usbdev(intf));
1466 priv->flags |= DEVICE_FLAGS_UNPLUG;
1468 ieee80211_free_hw(priv->hw);
1473 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
1478 static int vt6656_resume(struct usb_interface *intf)
1483 #endif /* CONFIG_PM */
1485 static int device_xmit(struct sk_buff *skb, struct net_device *dev)
1487 struct vnt_private *pDevice = netdev_priv(dev);
1488 struct net_device_stats *stats = &pDevice->stats;
1489 unsigned long flags;
1491 spin_lock_irqsave(&pDevice->lock, flags);
1493 netif_stop_queue(dev);
1495 if (!pDevice->bLinkPass) {
1496 dev_kfree_skb_irq(skb);
1500 if (pDevice->bStopDataPkt) {
1501 dev_kfree_skb_irq(skb);
1502 stats->tx_dropped++;
1506 if (nsDMA_tx_packet(pDevice, skb)) {
1507 if (netif_queue_stopped(dev))
1508 netif_wake_queue(dev);
1512 spin_unlock_irqrestore(&pDevice->lock, flags);
1514 return NETDEV_TX_OK;
1517 /* find out the start position of str2 from str1 */
1518 static unsigned char *kstrstr(const unsigned char *str1,
1519 const unsigned char *str2) {
1520 int str1_len = strlen(str1);
1521 int str2_len = strlen(str2);
1523 while (str1_len >= str2_len) {
1525 if(memcmp(str1,str2,str2_len)==0)
1526 return (unsigned char *) str1;
1532 static int Config_FileGetParameter(unsigned char *string,
1533 unsigned char *dest,
1534 unsigned char *source)
1536 unsigned char buf1[100];
1537 unsigned char buf2[100];
1538 unsigned char *start_p = NULL, *end_p = NULL, *tmp_p = NULL;
1542 strcat(buf1, string);
1544 source+=strlen(buf1);
1546 /* find target string start point */
1547 start_p = kstrstr(source,buf1);
1548 if (start_p == NULL)
1551 /* check if current config line is marked by "#" */
1552 for (ii = 1; ; ii++) {
1553 if (memcmp(start_p - ii, "\n", 1) == 0)
1555 if (memcmp(start_p - ii, "#", 1) == 0)
1559 /* find target string end point */
1560 end_p = kstrstr(start_p,"\n");
1561 if (end_p == NULL) { /* can't find "\n", but don't care */
1562 end_p = start_p + strlen(start_p); /* no include "\n" */
1566 memcpy(buf2, start_p, end_p-start_p); /* get the target line */
1567 buf2[end_p-start_p]='\0';
1570 start_p = kstrstr(buf2,"=");
1571 if (start_p == NULL)
1574 strcpy(buf1,start_p+1);
1578 while(*tmp_p != 0x00) {
1585 memcpy(dest,tmp_p,strlen(tmp_p));
1589 /* if read fails, return NULL, or return data pointer */
1590 static unsigned char *Config_FileOperation(struct vnt_private *pDevice)
1592 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
1596 printk("allocate mem for file fail?\n");
1600 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
1603 printk("Config_FileOperation file Not exist\n");
1607 if (kernel_read(file, 0, buffer, 1024) < 0) {
1608 printk("read file error?\n");
1617 /* return --->-1:fail; >=0:successful */
1618 static int Read_config_file(struct vnt_private *pDevice)
1621 unsigned char tmpbuffer[100];
1622 unsigned char *buffer = NULL;
1624 /* init config setting */
1625 pDevice->config_file.ZoneType = -1;
1626 pDevice->config_file.eAuthenMode = -1;
1627 pDevice->config_file.eEncryptionStatus = -1;
1629 buffer = Config_FileOperation(pDevice);
1630 if (buffer == NULL) {
1637 memset(tmpbuffer,0,sizeof(tmpbuffer));
1638 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==true) {
1639 if(memcmp(tmpbuffer,"USA",3)==0) {
1640 pDevice->config_file.ZoneType=ZoneType_USA;
1642 else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
1643 pDevice->config_file.ZoneType=ZoneType_Japan;
1645 else if(memcmp(tmpbuffer,"EUROPE",6)==0) {
1646 pDevice->config_file.ZoneType=ZoneType_Europe;
1649 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
1654 /* get other parameter */
1656 memset(tmpbuffer,0,sizeof(tmpbuffer));
1657 if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==true) {
1658 pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10);
1661 memset(tmpbuffer,0,sizeof(tmpbuffer));
1662 if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==true) {
1663 pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10);
1671 static void device_set_multi(struct net_device *dev)
1673 struct vnt_private *priv = netdev_priv(dev);
1674 unsigned long flags;
1676 if (priv->flags & DEVICE_FLAGS_OPENED) {
1677 spin_lock_irqsave(&priv->lock, flags);
1679 bScheduleCommand(priv, WLAN_CMD_CONFIGURE_FILTER, NULL);
1681 spin_unlock_irqrestore(&priv->lock, flags);
1685 void vnt_configure_filter(struct vnt_private *priv)
1687 struct net_device *dev = priv->dev;
1688 struct vnt_manager *mgmt = &priv->vnt_mgmt;
1689 struct netdev_hw_addr *ha;
1694 rc = vnt_control_in(priv, MESSAGE_TYPE_READ,
1695 MAC_REG_RCR, MESSAGE_REQUEST_MACREG, 1, &tmp);
1697 priv->byRxMode = tmp;
1699 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "priv->byRxMode in= %x\n",
1702 if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
1703 DBG_PRT(MSG_LEVEL_ERR, KERN_NOTICE
1704 "%s: Promiscuous mode enabled.\n", dev->name);
1705 /* unconditionally log net taps */
1706 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
1707 } else if ((netdev_mc_count(dev) > priv->multicast_limit) ||
1708 (dev->flags & IFF_ALLMULTI)) {
1710 vnt_mac_set_filter(priv, mc_filter);
1712 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1714 netdev_for_each_mc_addr(ha, dev) {
1715 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1717 mc_filter |= 1ULL << (bit_nr & 0x3f);
1720 vnt_mac_set_filter(priv, mc_filter);
1722 priv->byRxMode &= ~(RCR_UNICAST);
1723 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1726 if (mgmt->eConfigMode == WMAC_CONFIG_AP) {
1728 * If AP mode, don't enable RCR_UNICAST since HW only compares
1729 * addr1 with local MAC
1731 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1732 priv->byRxMode &= ~(RCR_UNICAST);
1735 vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
1736 MAC_REG_RCR, priv->byRxMode);
1738 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1739 "priv->byRxMode out= %x\n", priv->byRxMode);
1742 static struct net_device_stats *device_get_stats(struct net_device *dev)
1744 struct vnt_private *pDevice = netdev_priv(dev);
1746 return &pDevice->stats;
1749 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1755 return ethtool_ioctl(dev, rq);
1762 static int ethtool_ioctl(struct net_device *dev, struct ifreq *rq)
1766 if (copy_from_user(ðcmd, rq->ifr_data, sizeof(ethcmd)))
1770 case ETHTOOL_GDRVINFO: {
1771 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
1772 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
1773 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
1774 if (copy_to_user(rq->ifr_data, &info, sizeof(info)))
1784 MODULE_DEVICE_TABLE(usb, vt6656_table);
1786 static struct usb_driver vt6656_driver = {
1787 .name = DEVICE_NAME,
1788 .probe = vt6656_probe,
1789 .disconnect = vt6656_disconnect,
1790 .id_table = vt6656_table,
1792 .suspend = vt6656_suspend,
1793 .resume = vt6656_resume,
1794 #endif /* CONFIG_PM */
1797 module_usb_driver(vt6656_driver);