⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zdusb.c

📁 Atheros USB WiFi Card 驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* src/zdusb.c
*
* Implements the functions of the ZyDAS zd1211 MAC
*
* Copyright (C) 2004 ZyDAS Inc.  All Rights Reserved.
* --------------------------------------------------------------------
*
*
*
*   The contents of this file are subject to the Mozilla Public
*   License Version 1.1 (the "License"); you may not use this file
*   except in compliance with the License. You may obtain a copy of
*   the License at http://www.mozilla.org/MPL/
*
*   Software distributed under the License is distributed on an "AS
*   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
*   implied. See the License for the specific language governing
*   rights and limitations under the License.
*
*   Alternatively, the contents of this file may be used under the
*   terms of the GNU Public License version 2 (the "GPL"), in which
*   case the provisions of the GPL are applicable instead of the
*   above.  If you wish to allow the use of your version of this file
*   only under the terms of the GPL and not to allow others to use
*   your version of this file under the MPL, indicate your decision
*   by deleting the provisions above and replace them with the notice
*   and other provisions required by the GPL.  If you do not delete
*   the provisions above, a recipient may use your version of this
*   file under either the MPL or the GPL.
*
* -------------------------------------------------------------------- */

#include <linux/version.h>

#ifdef MODVERSIONS
#include <linux/modversions.h>
#endif

#include <linux/module.h>

#include <linux/usb.h>
#include <linux/pm.h>

#include "zd1205.h"
#include "zdusb.h"
#include "zddebug.h"
#include "zdversion.h"
#include "zd1211.h"

#define ZD1211_DBG_LEVEL    1

MODULE_AUTHOR("Yarco Yang");
MODULE_DESCRIPTION("ZyDAS 802.11b/g USB Wireless LAN adapter");
MODULE_LICENSE("GPL");

#ifdef ZD1211
static const char driver_name[] = "zd1211";
#elif defined(ZD1211B)
static const char driver_name[] = "zd1211b";
#endif


/* table of devices that work with this driver */
static struct usb_device_id zd1211_ids [] = {
#ifdef ZD1211B
	{ USB_DEVICE(VENDOR_ZYDAS, 0x1215) },
    { USB_DEVICE(VENDOR_ZYDAS, 0xA215) },
#if ZDCONF_FULL_IDS == 1
    { USB_DEVICE(0x0053, 0x5301) },
    { USB_DEVICE(0x0053, 0x5302) },
    { USB_DEVICE(0x2019, 0x5303) }, //Add, 2006.04.17
    { USB_DEVICE(0x050D, 0x4050) },
    { USB_DEVICE(0x050D, 0x705C) },
    { USB_DEVICE(0x0586, 0x340F) },
    { USB_DEVICE(0x079B, 0x0062) },
    { USB_DEVICE(0x083A, 0x4505) },
    { USB_DEVICE(0x083A, 0xE501) },
    { USB_DEVICE(0x0BAF, 0x0121) },
    { USB_DEVICE(0x0CDE, 0x001A) },
    { USB_DEVICE(0x0DF6, 0x9075) },
    { USB_DEVICE(0x0F88, 0x3014) },
    { USB_DEVICE(0x1233, 0x0471) },
    { USB_DEVICE(0x1582, 0x6003) },
#endif
#elif defined(ZD1211)
	{ USB_DEVICE(VENDOR_ZYDAS, PRODUCT_1211) },
    { USB_DEVICE(VENDOR_ZYDAS, PRODUCT_A211) },
#if ZDCONF_FULL_IDS == 1
    { USB_DEVICE(VENDOR_ZYXEL, PRODUCT_G220) },
    { USB_DEVICE(VENDOR_3COM,  PRODUCT_A727) },
    { USB_DEVICE(0x2019, 0xc008) },
    { USB_DEVICE(0x2019, 0xc009) },
    { USB_DEVICE(0x079b, 0x004a) },
    { USB_DEVICE(0x07b8, 0x6001) },
    { USB_DEVICE(0x0b3b, 0x1630) },
    { USB_DEVICE(0x0b3b, 0x5630) },
    { USB_DEVICE(0x0b3b, 0x6630) },
    { USB_DEVICE(0x0cde, 0x0011) },
    { USB_DEVICE(0x0df6, 0x9071) },
    { USB_DEVICE(0x126f, 0xa006) },
    { USB_DEVICE(0x129b, 0x1666) },
    { USB_DEVICE(0x1435, 0x0711) },
    { USB_DEVICE(0x0DF6, 0x9071) },
    { USB_DEVICE(0x0105, 0x145F) },
#endif
    
#endif
	{ }					/* Terminating entry */
};


MODULE_DEVICE_TABLE(usb, zd1211_ids);
int zd1211_FirstLoad = 1;
int zd1211_OperationMode = 1; //Infrastructure=1, AP=4, IBSS=0, PSEUDO=3
#if 1
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
module_param(zd1211_FirstLoad, int, S_IRUGO);
module_param(zd1211_OperationMode, int, S_IRUGO);
#else
MODULE_PARM(zd1211_OperationMode, "i");
#endif
#endif

extern struct net_device *g_dev;
#if ZDCONF_ACPI_SUPPORT == 1
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22))
static int zd1211_suspend(struct usb_interface *intf,pm_message_t message)
{
    struct zd1205_private *macp = (struct zd1205_private *)usb_get_intfdata(intf);
    printk("zd1211: Start to suspend\n");

    set_bit(ZD1211_UNPLUG, &macp->flags);
    macp->bUSBDeveiceAttached = 0;

    if(netif_running(macp->device))
    {
        zd1205_close(macp->device);
        flush_scheduled_work();
        mdelay(10);
        zd1211_free_all_urbs(macp);
        printk("zd1211: Finish to suspend\n");
    }
    return 0;
}

static int zd1211_resume(struct usb_interface *intf)
{
    struct zd1205_private *macp = usb_get_intfdata(intf);
    extern unsigned char zd1205_hw_init(struct zd1205_private *macp);
 

    printk("zd1211: Start to resume\n");
    clear_bit(ZD1211_UNPLUG, &macp->flags);
    set_bit(ZD1211_RUNNING, &macp->flags);
    macp->bUSBDeveiceAttached = 1;

    if (!zd1211_alloc_all_urbs(macp)){
        printk("Calling zd1211_alloc_all_urbs fails in %s\n", __func__);
    }   
    if (zd1211_Download_IncludeFile(macp) != 0){
        printk(KERN_ERR "zd1211_Download_IncludeFile failed in %s\n", __func__);
    }
    if ((usb_control_msg(macp->usb, usb_sndctrlpipe(macp->usb,0),USB_REQ_SET_CONFIGURATION,0, 1, 0, NULL, 0, HZ))<0)
    {
        printk(KERN_ERR "usb_set_configuration() failed, in %s\n",__func__);
    }


#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
    usb_fill_int_urb(macp->intr_urb, macp->usb,
            usb_rcvintpipe(macp->usb, EP_INT_IN),
            macp->IntEPBuffer, MAX_EPINT_BUFFER,
            zd1211_intr_cb, macp, macp->in_interval);
#else  //fake it
    usb_fill_bulk_urb(macp->intr_urb, macp->usb,
            usb_rcvbulkpipe(macp->usb, EP_INT_IN),
            macp->IntEPBuffer, MAX_EPINT_BUFFER,
            zd1211_intr_cb, macp);
#endif

#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
    macp->intr_urb->transfer_flags |= URB_ASYNC_UNLINK;
#endif
    int res;
    if ((res = usb_submit_urb(macp->intr_urb, GFP_KERNEL))){
        printk(KERN_ERR "zd1211: failed intr_urb, in %s\n", __func__);
        //zd1211_DumpErrorCode(macp, res);
        return false;
    }
    netif_device_attach(macp->device);
    zd_writel(0x01, AfterPNP);
    zd_writel(0x00, GPI_EN);

    zd1205_hw_init(macp);
    zd1205_disable_int();

    if(netif_running(macp->device))
    {
        zd1205_open(macp->device);
        printk("zd1211: Finish to resume\n");
    }



    return 0;
}
#endif
#endif

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22))
static int zd1211_suspend(struct usb_interface *intf,pm_message_t message)
{
    struct zd1205_private *macp = (struct zd1205_private *)usb_get_intfdata(intf);
    printk("zd1211: Start to suspend\n");

    set_bit(ZD1211_UNPLUG, &macp->flags);
    macp->bUSBDeveiceAttached = 0;

    if(netif_running(macp->device))
    {
        zd1205_close(macp->device);
        flush_scheduled_work();
        mdelay(10);
        zd1211_free_all_urbs(macp);
        printk("zd1211: Finish to suspend\n");
    }
    return 0;
}

static int zd1211_resume(struct usb_interface *intf)
{
    struct zd1205_private *macp = usb_get_intfdata(intf);
    extern unsigned char zd1205_hw_init(struct zd1205_private *macp);

    printk("zd1211: Start to resume\n");
    clear_bit(ZD1211_UNPLUG, &macp->flags);
    set_bit(ZD1211_RUNNING, &macp->flags);
    macp->bUSBDeveiceAttached = 1;

    if (!zd1211_alloc_all_urbs(macp)){
        printk("Calling zd1211_alloc_all_urbs fails in %s\n", __func__);
    }   
    if (zd1211_Download_IncludeFile(macp) != 0){
        printk(KERN_ERR "zd1211_Download_IncludeFile failed in %s\n", __func__);
    }
    if ((usb_control_msg(macp->usb, usb_sndctrlpipe(macp->usb,0),USB_REQ_SET_CONFIGURATION,0, 1, 0, NULL, 0, HZ))<0)
    {
        printk(KERN_ERR "usb_set_configuration() failed, in %s\n",__func__);
    }


#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
    usb_fill_int_urb(macp->intr_urb, macp->usb,
            usb_rcvintpipe(macp->usb, EP_INT_IN),
            macp->IntEPBuffer, MAX_EPINT_BUFFER,
            zd1211_intr_cb, macp, macp->in_interval);
#else  //fake it
    usb_fill_bulk_urb(macp->intr_urb, macp->usb,
            usb_rcvbulkpipe(macp->usb, EP_INT_IN),
            macp->IntEPBuffer, MAX_EPINT_BUFFER,
            zd1211_intr_cb, macp);
#endif

#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
    macp->intr_urb->transfer_flags |= URB_ASYNC_UNLINK;
#endif
    int res;
    if ((res = usb_submit_urb(macp->intr_urb, GFP_KERNEL))){
        printk(KERN_ERR "zd1211: failed intr_urb, in %s\n", __func__);
        //zd1211_DumpErrorCode(macp, res);
        return false;
    }
    netif_device_attach(macp->device);
    zd_writel(0x01, AfterPNP);
    zd_writel(0x00, GPI_EN);

    zd1205_hw_init(macp);
    zd1205_disable_int();

    if(netif_running(macp->device))
    {
        zd1205_open(macp->device);
        printk("zd1211: Finish to resume\n");
    }



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -