📄 usb_main_dev.c
字号:
/* ************************************************************************* * Ralink Tech Inc. * 5F., No.36, Taiyuan St., Jhubei City, * Hsinchu County 302, * Taiwan, R.O.C. * * (c) Copyright 2002-2007, Ralink Technology, Inc. * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * * *************************************************************************/#include "rt_config.h"// Following information will be show when you run 'modinfo'// *** If you have a solution for the bug in current version of driver, please mail to me.// Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. ***MODULE_AUTHOR("Paul Lin <paul_lin@ralinktech.com>");MODULE_DESCRIPTION("RT2870 Wireless Lan Linux Driver");MODULE_LICENSE("GPL");#ifdef CONFIG_STA_SUPPORT#ifdef MODULE_VERSIONMODULE_VERSION(STA_DRIVER_VERSION);#endif#endif // CONFIG_STA_SUPPORT ///* module table */struct usb_device_id rtusb_usb_id[] = {#ifdef RT2870 {USB_DEVICE(0x148F,0x2770)}, /* Ralink */ {USB_DEVICE(0x148F,0x2870)}, /* Ralink */ {USB_DEVICE(0x07B8,0x2870)}, /* AboCom */ {USB_DEVICE(0x07B8,0x2770)}, /* AboCom */ {USB_DEVICE(0x0DF6,0x0039)}, /* Sitecom 2770 */ {USB_DEVICE(0x083A,0x7512)}, /* Arcadyan 2770 */ {USB_DEVICE(0x0789,0x0162)}, /* Logitec 2870 */ {USB_DEVICE(0x0789,0x0163)}, /* Logitec 2870 */ {USB_DEVICE(0x0789,0x0164)}, /* Logitec 2870 */ {USB_DEVICE(0x177f,0x0302)}, /* lsusb */ {USB_DEVICE(0x0B05,0x1731)}, /* Asus */ {USB_DEVICE(0x0B05,0x1732)}, /* Asus */ {USB_DEVICE(0x0B05,0x1742)}, /* Asus */ {USB_DEVICE(0x0DF6,0x0017)}, /* Sitecom */ {USB_DEVICE(0x0DF6,0x002B)}, /* Sitecom */ {USB_DEVICE(0x0DF6,0x002C)}, /* Sitecom */ {USB_DEVICE(0x0DF6,0x002D)}, /* Sitecom */ {USB_DEVICE(0x14B2,0x3C06)}, /* Conceptronic */ {USB_DEVICE(0x14B2,0x3C28)}, /* Conceptronic */ {USB_DEVICE(0x2019,0xED06)}, /* Planex Communications, Inc. */ {USB_DEVICE(0x07D1,0x3C09)}, /* D-Link */ {USB_DEVICE(0x07D1,0x3C11)}, /* D-Link */ {USB_DEVICE(0x14B2,0x3C07)}, /* AL */ {USB_DEVICE(0x050D,0x8053)}, /* Belkin */ {USB_DEVICE(0x14B2,0x3C23)}, /* Airlink */ {USB_DEVICE(0x14B2,0x3C27)}, /* Airlink */ {USB_DEVICE(0x07AA,0x002F)}, /* Corega */ {USB_DEVICE(0x07AA,0x003C)}, /* Corega */ {USB_DEVICE(0x07AA,0x003F)}, /* Corega */ {USB_DEVICE(0x1044,0x800B)}, /* Gigabyte */ {USB_DEVICE(0x15A9,0x0006)}, /* Sparklan */ {USB_DEVICE(0x083A,0xB522)}, /* SMC */ {USB_DEVICE(0x083A,0xA618)}, /* SMC */ {USB_DEVICE(0x083A,0x8522)}, /* Arcadyan */ {USB_DEVICE(0x083A,0x7522)}, /* Arcadyan */ {USB_DEVICE(0x0CDE,0x0022)}, /* ZCOM */ {USB_DEVICE(0x0586,0x3416)}, /* Zyxel */ {USB_DEVICE(0x0CDE,0x0025)}, /* Zyxel */ {USB_DEVICE(0x1740,0x9701)}, /* EnGenius */ {USB_DEVICE(0x1740,0x9702)}, /* EnGenius */ {USB_DEVICE(0x0471,0x200f)}, /* Philips */ {USB_DEVICE(0x14B2,0x3C25)}, /* Draytek */ {USB_DEVICE(0x13D3,0x3247)}, /* AzureWave */ {USB_DEVICE(0x083A,0x6618)}, /* Accton */ {USB_DEVICE(0x15c5,0x0008)}, /* Amit */ {USB_DEVICE(0x0E66,0x0001)}, /* Hawking */ {USB_DEVICE(0x0E66,0x0003)}, /* Hawking */ {USB_DEVICE(0x129B,0x1828)}, /* Siemens */ {USB_DEVICE(0x157E,0x300E)}, /* U-Media */ {USB_DEVICE(0x050d,0x805c)}, {USB_DEVICE(0x050d,0x815c)}, {USB_DEVICE(0x1482,0x3C09)}, /* Abocom*/ {USB_DEVICE(0x14B2,0x3C09)}, /* Alpha */ {USB_DEVICE(0x04E8,0x2018)}, /* samsung */ {USB_DEVICE(0x5A57,0x0280)}, /* Zinwell */ {USB_DEVICE(0x5A57,0x0282)}, /* Zinwell */ {USB_DEVICE(0x7392,0x7718)}, {USB_DEVICE(0x7392,0x7717)}, {USB_DEVICE(0x1737,0x0070)}, /* Linksys WUSB100 */ {USB_DEVICE(0x1737,0x0071)}, /* Linksys WUSB600N */ {USB_DEVICE(0x0411,0x00e8)}, /* Buffalo WLI-UC-G300N*/ {USB_DEVICE(0x050d,0x815c)}, /* Belkin F5D8053 */#endif // RT2870 // { }/* Terminating entry */};INT const rtusb_usb_id_len = sizeof(rtusb_usb_id) / sizeof(struct usb_device_id);MODULE_DEVICE_TABLE(usb, rtusb_usb_id);static void rt2870_disconnect( IN struct usb_device *dev, IN PRTMP_ADAPTER pAd);static int __devinit rt2870_probe( IN struct usb_interface *intf, IN struct usb_device *usb_dev, IN const struct usb_device_id *dev_id, IN RTMP_ADAPTER **ppAd);#ifndef PF_NOFREEZE#define PF_NOFREEZE 0#endifextern int rt28xx_close(IN struct net_device *net_dev);extern int rt28xx_open(struct net_device *net_dev);static BOOLEAN USBDevConfigInit( IN struct usb_device *dev, IN struct usb_interface *intf, IN RTMP_ADAPTER *pAd); /*========================================================================Routine Description: Check the chipset vendor/product ID.Arguments: _dev_p Point to the PCI or USB deviceReturn Value: TRUE Check ok FALSE Check failNote:========================================================================*/BOOLEAN RT28XXChipsetCheck( IN void *_dev_p){#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) /* kernel 2.4 series */ struct usb_device *dev_p = (struct usb_device *)_dev_p;#else struct usb_interface *intf = (struct usb_interface *)_dev_p; struct usb_device *dev_p = interface_to_usbdev(intf);#endif // LINUX_VERSION_CODE // UINT32 i; for(i=0; i<rtusb_usb_id_len; i++) { if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor && dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct) { printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n", dev_p->descriptor.idVendor, dev_p->descriptor.idProduct); break; } } if (i == rtusb_usb_id_len) { printk("rt2870: Error! Device Descriptor not matching!\n"); return FALSE; } return TRUE;}#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)/**************************************************************************//**************************************************************************///tested for kernel 2.4 series/**************************************************************************//**************************************************************************/static void *rtusb_probe(struct usb_device *dev, UINT interface, const struct usb_device_id *id_table);static void rtusb_disconnect(struct usb_device *dev, void *ptr);struct usb_driver rtusb_driver = { name:"rt2870", probe:rtusb_probe, disconnect:rtusb_disconnect, id_table:rtusb_usb_id, };static BOOLEAN USBDevConfigInit( IN struct usb_device *dev, IN struct usb_interface *intf, IN RTMP_ADAPTER *pAd){ struct usb_interface_descriptor *iface_desc; struct usb_endpoint_descriptor *endpoint; ULONG BulkOutIdx; UINT32 i; iface_desc = &intf->altsetting[0]; /* get # of enpoints */ pAd->NumberOfPipes = iface_desc->bNumEndpoints; DBGPRINT(RT_DEBUG_TRACE, ("NumEndpoints=%d\n", iface_desc->bNumEndpoints)); /* Configure Pipes */ endpoint = &iface_desc->endpoint[0]; BulkOutIdx = 0; for(i=0; i<pAd->NumberOfPipes; i++) { if ((endpoint[i].bmAttributes == USB_ENDPOINT_XFER_BULK) && ((endpoint[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)) { pAd->BulkInEpAddr = endpoint[i].bEndpointAddress; pAd->BulkInMaxPacketSize = endpoint[i].wMaxPacketSize; DBGPRINT_RAW(RT_DEBUG_TRACE, ("BULK IN MaximumPacketSize = %d\n", pAd->BulkInMaxPacketSize)); DBGPRINT_RAW(RT_DEBUG_TRACE, ("EP address = 0x%2x \n", endpoint[i].bEndpointAddress)); } else if ((endpoint[i].bmAttributes == USB_ENDPOINT_XFER_BULK) && ((endpoint[i].bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT)) { // There are 6 bulk out EP. EP6 highest priority. // EP1-4 is EDCA. EP5 is HCCA. pAd->BulkOutEpAddr[BulkOutIdx++] = endpoint[i].bEndpointAddress; pAd->BulkOutMaxPacketSize = endpoint[i].wMaxPacketSize; DBGPRINT_RAW(RT_DEBUG_TRACE, ("BULK OUT MaximumPacketSize = %d\n", pAd->BulkOutMaxPacketSize)); DBGPRINT_RAW(RT_DEBUG_TRACE, ("EP address = 0x%2x \n", endpoint[i].bEndpointAddress)); } } if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0])) { printk("Could not find both bulk-in and bulk-out endpoints\n"); return FALSE; } pAd->config = dev->config; return TRUE; }static void *rtusb_probe(struct usb_device *dev, UINT interface, const struct usb_device_id *id){ struct usb_interface *intf; RTMP_ADAPTER *pAd; int rv; /* get the active interface descriptor */ intf = &dev->actconfig->interface[interface]; // call generic probe procedure. rv = rt2870_probe(intf, dev, id, &pAd); if (rv != 0) pAd = NULL; return (void *)pAd;}//Disconnect function is called within exit routinestatic void rtusb_disconnect(struct usb_device *dev, void *ptr){ rt2870_disconnect(dev, ((PRTMP_ADAPTER)ptr));}#else // else if we are kernel 2.6 series/**************************************************************************//**************************************************************************///tested for kernel 2.6series/**************************************************************************//**************************************************************************/#ifdef CONFIG_PM#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)#define pm_message_t u32#endifstatic int rt2870_suspend(struct usb_interface *intf, pm_message_t state);static int rt2870_resume(struct usb_interface *intf);#endif // CONFIG_PM //static int rtusb_probe (struct usb_interface *intf, const struct usb_device_id *id);static void rtusb_disconnect(struct usb_interface *intf);static BOOLEAN USBDevConfigInit( IN struct usb_device *dev, IN struct usb_interface *intf, IN RTMP_ADAPTER *pAd){ struct usb_host_interface *iface_desc; ULONG BulkOutIdx; UINT32 i; /* get the active interface descriptor */ iface_desc = intf->cur_altsetting; /* get # of enpoints */ pAd->NumberOfPipes = iface_desc->desc.bNumEndpoints; DBGPRINT(RT_DEBUG_TRACE, ("NumEndpoints=%d\n", iface_desc->desc.bNumEndpoints)); /* Configure Pipes */ BulkOutIdx = 0; for(i=0; i<pAd->NumberOfPipes; i++) { if ((iface_desc->endpoint[i].desc.bmAttributes == USB_ENDPOINT_XFER_BULK) && ((iface_desc->endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)) { pAd->BulkInEpAddr = iface_desc->endpoint[i].desc.bEndpointAddress; pAd->BulkInMaxPacketSize = iface_desc->endpoint[i].desc.wMaxPacketSize; DBGPRINT_RAW(RT_DEBUG_TRACE, ("BULK IN MaxPacketSize = %d\n", pAd->BulkInMaxPacketSize)); DBGPRINT_RAW(RT_DEBUG_TRACE, ("EP address = 0x%2x\n", iface_desc->endpoint[i].desc.bEndpointAddress)); } else if ((iface_desc->endpoint[i].desc.bmAttributes == USB_ENDPOINT_XFER_BULK) && ((iface_desc->endpoint[i].desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT)) { // there are 6 bulk out EP. EP6 highest priority. // EP1-4 is EDCA. EP5 is HCCA. pAd->BulkOutEpAddr[BulkOutIdx++] = iface_desc->endpoint[i].desc.bEndpointAddress; pAd->BulkOutMaxPacketSize = iface_desc->endpoint[i].desc.wMaxPacketSize; DBGPRINT_RAW(RT_DEBUG_TRACE, ("BULK OUT MaxPacketSize = %d\n", pAd->BulkOutMaxPacketSize)); DBGPRINT_RAW(RT_DEBUG_TRACE, ("EP address = 0x%2x \n", iface_desc->endpoint[i].desc.bEndpointAddress)); } } if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0])) { printk("%s: Could not find both bulk-in and bulk-out endpoints\n", __FUNCTION__); return FALSE; } pAd->config = &dev->config->desc; usb_set_intfdata(intf, pAd); return TRUE; }static int rtusb_probe (struct usb_interface *intf, const struct usb_device_id *id){ RTMP_ADAPTER *pAd; struct usb_device *dev; int rv; dev = interface_to_usbdev(intf); dev = usb_get_dev(dev); rv = rt2870_probe(intf, dev, id, &pAd); if (rv != 0) usb_put_dev(dev); return rv;}static void rtusb_disconnect(struct usb_interface *intf){ struct usb_device *dev = interface_to_usbdev(intf); PRTMP_ADAPTER pAd; pAd = usb_get_intfdata(intf); usb_set_intfdata(intf, NULL); rt2870_disconnect(dev, pAd);}struct usb_driver rtusb_driver = {#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15) .owner = THIS_MODULE,#endif .name="rt2870", .probe=rtusb_probe, .disconnect=rtusb_disconnect, .id_table=rtusb_usb_id,#ifdef CONFIG_PM suspend: rt2870_suspend, resume: rt2870_resume,#endif };#ifdef CONFIG_PMVOID RT2870RejectPendingPackets( IN PRTMP_ADAPTER pAd){ // clear PS packets // clear TxSw packets}static int rt2870_suspend( struct usb_interface *intf, pm_message_t state){ struct net_device *net_dev; PRTMP_ADAPTER pAd = usb_get_intfdata(intf); DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_suspend()\n")); net_dev = pAd->net_dev; netif_device_detach(net_dev); pAd->PM_FlgSuspend = 1; if (netif_running(net_dev)) { RTUSBCancelPendingBulkInIRP(pAd); RTUSBCancelPendingBulkOutIRP(pAd); } DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_suspend()\n")); return 0;}static int rt2870_resume( struct usb_interface *intf){ struct net_device *net_dev; PRTMP_ADAPTER pAd = usb_get_intfdata(intf); DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_resume()\n")); pAd->PM_FlgSuspend = 0; net_dev = pAd->net_dev; netif_device_attach(net_dev); netif_start_queue(net_dev); netif_carrier_on(net_dev); netif_wake_queue(net_dev); DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_resume()\n")); return 0;}#endif // CONFIG_PM //#endif // LINUX_VERSION_CODE //// Init driver moduleINT __init rtusb_init(void){ printk("rtusb init --->\n"); return usb_register(&rtusb_driver);}// Deinit driver moduleVOID __exit rtusb_exit(void){ usb_deregister(&rtusb_driver); printk("<--- rtusb exit\n");}module_init(rtusb_init);module_exit(rtusb_exit);/*--------------------------------------------------------------------- *//* function declarations *//*--------------------------------------------------------------------- *//*========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -