usbnet.c (94558e265b9539b2ecec98d037bae51c902663c1) | usbnet.c (ef6cd1301e06e0a5de24938b92c5859d5021ea5d) |
---|---|
1/* 2 * USB Network driver infrastructure 3 * Copyright (C) 2000-2005 by David Brownell 4 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 28 unchanged lines hidden (view full) --- 37#include <linux/netdevice.h> 38#include <linux/etherdevice.h> 39#include <linux/ctype.h> 40#include <linux/ethtool.h> 41#include <linux/workqueue.h> 42#include <linux/mii.h> 43#include <linux/usb.h> 44#include <linux/usb/usbnet.h> | 1/* 2 * USB Network driver infrastructure 3 * Copyright (C) 2000-2005 by David Brownell 4 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or --- 28 unchanged lines hidden (view full) --- 37#include <linux/netdevice.h> 38#include <linux/etherdevice.h> 39#include <linux/ctype.h> 40#include <linux/ethtool.h> 41#include <linux/workqueue.h> 42#include <linux/mii.h> 43#include <linux/usb.h> 44#include <linux/usb/usbnet.h> |
45#include <linux/usb/cdc.h> | |
46#include <linux/slab.h> 47#include <linux/kernel.h> 48#include <linux/pm_runtime.h> 49 50#define DRIVER_VERSION "22-Aug-2005" 51 52 53/*-------------------------------------------------------------------------*/ --- 1913 unchanged lines hidden (view full) --- 1967 cmd, reqtype, value, index, buf, size, 1968 USB_CTRL_SET_TIMEOUT); 1969 kfree(buf); 1970 1971out: 1972 return err; 1973} 1974 | 45#include <linux/slab.h> 46#include <linux/kernel.h> 47#include <linux/pm_runtime.h> 48 49#define DRIVER_VERSION "22-Aug-2005" 50 51 52/*-------------------------------------------------------------------------*/ --- 1913 unchanged lines hidden (view full) --- 1966 cmd, reqtype, value, index, buf, size, 1967 USB_CTRL_SET_TIMEOUT); 1968 kfree(buf); 1969 1970out: 1971 return err; 1972} 1973 |
1975int cdc_parse_cdc_header(struct usb_cdc_parsed_header *hdr, 1976 struct usb_interface *intf, 1977 u8 *buffer, 1978 int buflen) 1979{ 1980 /* duplicates are ignored */ 1981 struct usb_cdc_union_desc *union_header = NULL; 1982 1983 /* duplicates are not tolerated */ 1984 struct usb_cdc_header_desc *header = NULL; 1985 struct usb_cdc_ether_desc *ether = NULL; 1986 struct usb_cdc_mdlm_detail_desc *detail = NULL; 1987 struct usb_cdc_mdlm_desc *desc = NULL; 1988 1989 unsigned int elength; 1990 int cnt = 0; 1991 1992 memset(hdr, 0x00, sizeof(struct usb_cdc_parsed_header)); 1993 hdr->phonet_magic_present = false; 1994 while (buflen > 0) { 1995 elength = buffer[0]; 1996 if (!elength) { 1997 dev_err(&intf->dev, "skipping garbage byte\n"); 1998 elength = 1; 1999 goto next_desc; 2000 } 2001 if (buffer[1] != USB_DT_CS_INTERFACE) { 2002 dev_err(&intf->dev, "skipping garbage\n"); 2003 goto next_desc; 2004 } 2005 2006 switch (buffer[2]) { 2007 case USB_CDC_UNION_TYPE: /* we've found it */ 2008 if (elength < sizeof(struct usb_cdc_union_desc)) 2009 goto next_desc; 2010 if (union_header) { 2011 dev_err(&intf->dev, "More than one union descriptor, skipping ...\n"); 2012 goto next_desc; 2013 } 2014 union_header = (struct usb_cdc_union_desc *)buffer; 2015 break; 2016 case USB_CDC_COUNTRY_TYPE: 2017 if (elength < sizeof(struct usb_cdc_country_functional_desc)) 2018 goto next_desc; 2019 hdr->usb_cdc_country_functional_desc = 2020 (struct usb_cdc_country_functional_desc *)buffer; 2021 break; 2022 case USB_CDC_HEADER_TYPE: 2023 if (elength != sizeof(struct usb_cdc_header_desc)) 2024 goto next_desc; 2025 if (header) 2026 return -EINVAL; 2027 header = (struct usb_cdc_header_desc *)buffer; 2028 break; 2029 case USB_CDC_ACM_TYPE: 2030 if (elength < sizeof(struct usb_cdc_acm_descriptor)) 2031 goto next_desc; 2032 hdr->usb_cdc_acm_descriptor = 2033 (struct usb_cdc_acm_descriptor *)buffer; 2034 break; 2035 case USB_CDC_ETHERNET_TYPE: 2036 if (elength != sizeof(struct usb_cdc_ether_desc)) 2037 goto next_desc; 2038 if (ether) 2039 return -EINVAL; 2040 ether = (struct usb_cdc_ether_desc *)buffer; 2041 break; 2042 case USB_CDC_CALL_MANAGEMENT_TYPE: 2043 if (elength < sizeof(struct usb_cdc_call_mgmt_descriptor)) 2044 goto next_desc; 2045 hdr->usb_cdc_call_mgmt_descriptor = 2046 (struct usb_cdc_call_mgmt_descriptor *)buffer; 2047 break; 2048 case USB_CDC_DMM_TYPE: 2049 if (elength < sizeof(struct usb_cdc_dmm_desc)) 2050 goto next_desc; 2051 hdr->usb_cdc_dmm_desc = 2052 (struct usb_cdc_dmm_desc *)buffer; 2053 break; 2054 case USB_CDC_MDLM_TYPE: 2055 if (elength < sizeof(struct usb_cdc_mdlm_desc *)) 2056 goto next_desc; 2057 if (desc) 2058 return -EINVAL; 2059 desc = (struct usb_cdc_mdlm_desc *)buffer; 2060 break; 2061 case USB_CDC_MDLM_DETAIL_TYPE: 2062 if (elength < sizeof(struct usb_cdc_mdlm_detail_desc *)) 2063 goto next_desc; 2064 if (detail) 2065 return -EINVAL; 2066 detail = (struct usb_cdc_mdlm_detail_desc *)buffer; 2067 break; 2068 case USB_CDC_NCM_TYPE: 2069 if (elength < sizeof(struct usb_cdc_ncm_desc)) 2070 goto next_desc; 2071 hdr->usb_cdc_ncm_desc = (struct usb_cdc_ncm_desc *)buffer; 2072 break; 2073 case USB_CDC_MBIM_TYPE: 2074 if (elength < sizeof(struct usb_cdc_mbim_desc)) 2075 goto next_desc; 2076 2077 hdr->usb_cdc_mbim_desc = (struct usb_cdc_mbim_desc *)buffer; 2078 break; 2079 case USB_CDC_MBIM_EXTENDED_TYPE: 2080 if (elength < sizeof(struct usb_cdc_mbim_extended_desc)) 2081 break; 2082 hdr->usb_cdc_mbim_extended_desc = 2083 (struct usb_cdc_mbim_extended_desc *)buffer; 2084 break; 2085 case CDC_PHONET_MAGIC_NUMBER: 2086 hdr->phonet_magic_present = true; 2087 break; 2088 default: 2089 /* 2090 * there are LOTS more CDC descriptors that 2091 * could legitimately be found here. 2092 */ 2093 dev_dbg(&intf->dev, "Ignoring descriptor: type %02x, length %ud\n", 2094 buffer[2], elength); 2095 goto next_desc; 2096 } 2097 cnt++; 2098next_desc: 2099 buflen -= elength; 2100 buffer += elength; 2101 } 2102 hdr->usb_cdc_union_desc = union_header; 2103 hdr->usb_cdc_header_desc = header; 2104 hdr->usb_cdc_mdlm_detail_desc = detail; 2105 hdr->usb_cdc_mdlm_desc = desc; 2106 hdr->usb_cdc_ether_desc = ether; 2107 return cnt; 2108} 2109 2110EXPORT_SYMBOL(cdc_parse_cdc_header); 2111 | |
2112/* 2113 * The function can't be called inside suspend/resume callback, 2114 * otherwise deadlock will be caused. 2115 */ 2116int usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, 2117 u16 value, u16 index, void *data, u16 size) 2118{ 2119 int ret; --- 75 unchanged lines hidden (view full) --- 2195 int err = -ENOMEM; 2196 void *buf = NULL; 2197 2198 netdev_dbg(dev->net, "usbnet_write_cmd cmd=0x%02x reqtype=%02x" 2199 " value=0x%04x index=0x%04x size=%d\n", 2200 cmd, reqtype, value, index, size); 2201 2202 urb = usb_alloc_urb(0, GFP_ATOMIC); | 1974/* 1975 * The function can't be called inside suspend/resume callback, 1976 * otherwise deadlock will be caused. 1977 */ 1978int usbnet_read_cmd(struct usbnet *dev, u8 cmd, u8 reqtype, 1979 u16 value, u16 index, void *data, u16 size) 1980{ 1981 int ret; --- 75 unchanged lines hidden (view full) --- 2057 int err = -ENOMEM; 2058 void *buf = NULL; 2059 2060 netdev_dbg(dev->net, "usbnet_write_cmd cmd=0x%02x reqtype=%02x" 2061 " value=0x%04x index=0x%04x size=%d\n", 2062 cmd, reqtype, value, index, size); 2063 2064 urb = usb_alloc_urb(0, GFP_ATOMIC); |
2203 if (!urb) { 2204 netdev_err(dev->net, "Error allocating URB in" 2205 " %s!\n", __func__); | 2065 if (!urb) |
2206 goto fail; | 2066 goto fail; |
2207 } | |
2208 2209 if (data) { 2210 buf = kmemdup(data, size, GFP_ATOMIC); 2211 if (!buf) { 2212 netdev_err(dev->net, "Error allocating buffer" 2213 " in %s!\n", __func__); 2214 goto fail_free; 2215 } --- 57 unchanged lines hidden --- | 2067 2068 if (data) { 2069 buf = kmemdup(data, size, GFP_ATOMIC); 2070 if (!buf) { 2071 netdev_err(dev->net, "Error allocating buffer" 2072 " in %s!\n", __func__); 2073 goto fail_free; 2074 } --- 57 unchanged lines hidden --- |