diff options
author | Oliver Neukum <oneukum@suse.com> | 2016-07-14 09:41:30 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-07-18 11:46:57 -0400 |
commit | e4c6fb779498243ec001c5547b3504fe6b1993ec (patch) | |
tree | f9cb73a1017afbd0962ee2c4fbd3c6179d17b744 /drivers/net/usb | |
parent | a1ca2c6b2924a602bb19dce7390a6e9604dd45bf (diff) |
usbnet: move the CDC parser into USB core
The dependencies were impossible to handle preventing
drivers for CDC devices not which are not network drivers
from using the common parser.
Signed-off-by: Oliver Neukum <ONeukum@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/net/usb')
-rw-r--r-- | drivers/net/usb/usbnet.c | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index 61ba46404937..b56d78ab4139 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c | |||
@@ -42,7 +42,6 @@ | |||
42 | #include <linux/mii.h> | 42 | #include <linux/mii.h> |
43 | #include <linux/usb.h> | 43 | #include <linux/usb.h> |
44 | #include <linux/usb/usbnet.h> | 44 | #include <linux/usb/usbnet.h> |
45 | #include <linux/usb/cdc.h> | ||
46 | #include <linux/slab.h> | 45 | #include <linux/slab.h> |
47 | #include <linux/kernel.h> | 46 | #include <linux/kernel.h> |
48 | #include <linux/pm_runtime.h> | 47 | #include <linux/pm_runtime.h> |
@@ -1968,143 +1967,6 @@ out: | |||
1968 | return err; | 1967 | return err; |
1969 | } | 1968 | } |
1970 | 1969 | ||
1971 | int cdc_parse_cdc_header(struct usb_cdc_parsed_header *hdr, | ||
1972 | struct usb_interface *intf, | ||
1973 | u8 *buffer, | ||
1974 | int buflen) | ||
1975 | { | ||
1976 | /* duplicates are ignored */ | ||
1977 | struct usb_cdc_union_desc *union_header = NULL; | ||
1978 | |||
1979 | /* duplicates are not tolerated */ | ||
1980 | struct usb_cdc_header_desc *header = NULL; | ||
1981 | struct usb_cdc_ether_desc *ether = NULL; | ||
1982 | struct usb_cdc_mdlm_detail_desc *detail = NULL; | ||
1983 | struct usb_cdc_mdlm_desc *desc = NULL; | ||
1984 | |||
1985 | unsigned int elength; | ||
1986 | int cnt = 0; | ||
1987 | |||
1988 | memset(hdr, 0x00, sizeof(struct usb_cdc_parsed_header)); | ||
1989 | hdr->phonet_magic_present = false; | ||
1990 | while (buflen > 0) { | ||
1991 | elength = buffer[0]; | ||
1992 | if (!elength) { | ||
1993 | dev_err(&intf->dev, "skipping garbage byte\n"); | ||
1994 | elength = 1; | ||
1995 | goto next_desc; | ||
1996 | } | ||
1997 | if (buffer[1] != USB_DT_CS_INTERFACE) { | ||
1998 | dev_err(&intf->dev, "skipping garbage\n"); | ||
1999 | goto next_desc; | ||
2000 | } | ||
2001 | |||
2002 | switch (buffer[2]) { | ||
2003 | case USB_CDC_UNION_TYPE: /* we've found it */ | ||
2004 | if (elength < sizeof(struct usb_cdc_union_desc)) | ||
2005 | goto next_desc; | ||
2006 | if (union_header) { | ||
2007 | dev_err(&intf->dev, "More than one union descriptor, skipping ...\n"); | ||
2008 | goto next_desc; | ||
2009 | } | ||
2010 | union_header = (struct usb_cdc_union_desc *)buffer; | ||
2011 | break; | ||
2012 | case USB_CDC_COUNTRY_TYPE: | ||
2013 | if (elength < sizeof(struct usb_cdc_country_functional_desc)) | ||
2014 | goto next_desc; | ||
2015 | hdr->usb_cdc_country_functional_desc = | ||
2016 | (struct usb_cdc_country_functional_desc *)buffer; | ||
2017 | break; | ||
2018 | case USB_CDC_HEADER_TYPE: | ||
2019 | if (elength != sizeof(struct usb_cdc_header_desc)) | ||
2020 | goto next_desc; | ||
2021 | if (header) | ||
2022 | return -EINVAL; | ||
2023 | header = (struct usb_cdc_header_desc *)buffer; | ||
2024 | break; | ||
2025 | case USB_CDC_ACM_TYPE: | ||
2026 | if (elength < sizeof(struct usb_cdc_acm_descriptor)) | ||
2027 | goto next_desc; | ||
2028 | hdr->usb_cdc_acm_descriptor = | ||
2029 | (struct usb_cdc_acm_descriptor *)buffer; | ||
2030 | break; | ||
2031 | case USB_CDC_ETHERNET_TYPE: | ||
2032 | if (elength != sizeof(struct usb_cdc_ether_desc)) | ||
2033 | goto next_desc; | ||
2034 | if (ether) | ||
2035 | return -EINVAL; | ||
2036 | ether = (struct usb_cdc_ether_desc *)buffer; | ||
2037 | break; | ||
2038 | case USB_CDC_CALL_MANAGEMENT_TYPE: | ||
2039 | if (elength < sizeof(struct usb_cdc_call_mgmt_descriptor)) | ||
2040 | goto next_desc; | ||
2041 | hdr->usb_cdc_call_mgmt_descriptor = | ||
2042 | (struct usb_cdc_call_mgmt_descriptor *)buffer; | ||
2043 | break; | ||
2044 | case USB_CDC_DMM_TYPE: | ||
2045 | if (elength < sizeof(struct usb_cdc_dmm_desc)) | ||
2046 | goto next_desc; | ||
2047 | hdr->usb_cdc_dmm_desc = | ||
2048 | (struct usb_cdc_dmm_desc *)buffer; | ||
2049 | break; | ||
2050 | case USB_CDC_MDLM_TYPE: | ||
2051 | if (elength < sizeof(struct usb_cdc_mdlm_desc *)) | ||
2052 | goto next_desc; | ||
2053 | if (desc) | ||
2054 | return -EINVAL; | ||
2055 | desc = (struct usb_cdc_mdlm_desc *)buffer; | ||
2056 | break; | ||
2057 | case USB_CDC_MDLM_DETAIL_TYPE: | ||
2058 | if (elength < sizeof(struct usb_cdc_mdlm_detail_desc *)) | ||
2059 | goto next_desc; | ||
2060 | if (detail) | ||
2061 | return -EINVAL; | ||
2062 | detail = (struct usb_cdc_mdlm_detail_desc *)buffer; | ||
2063 | break; | ||
2064 | case USB_CDC_NCM_TYPE: | ||
2065 | if (elength < sizeof(struct usb_cdc_ncm_desc)) | ||
2066 | goto next_desc; | ||
2067 | hdr->usb_cdc_ncm_desc = (struct usb_cdc_ncm_desc *)buffer; | ||
2068 | break; | ||
2069 | case USB_CDC_MBIM_TYPE: | ||
2070 | if (elength < sizeof(struct usb_cdc_mbim_desc)) | ||
2071 | goto next_desc; | ||
2072 | |||
2073 | hdr->usb_cdc_mbim_desc = (struct usb_cdc_mbim_desc *)buffer; | ||
2074 | break; | ||
2075 | case USB_CDC_MBIM_EXTENDED_TYPE: | ||
2076 | if (elength < sizeof(struct usb_cdc_mbim_extended_desc)) | ||
2077 | break; | ||
2078 | hdr->usb_cdc_mbim_extended_desc = | ||
2079 | (struct usb_cdc_mbim_extended_desc *)buffer; | ||
2080 | break; | ||
2081 | case CDC_PHONET_MAGIC_NUMBER: | ||
2082 | hdr->phonet_magic_present = true; | ||
2083 | break; | ||
2084 | default: | ||
2085 | /* | ||
2086 | * there are LOTS more CDC descriptors that | ||
2087 | * could legitimately be found here. | ||
2088 | */ | ||
2089 | dev_dbg(&intf->dev, "Ignoring descriptor: type %02x, length %ud\n", | ||
2090 | buffer[2], elength); | ||
2091 | goto next_desc; | ||
2092 | } | ||
2093 | cnt++; | ||
2094 | next_desc: | ||
2095 | buflen -= elength; | ||
2096 | buffer += elength; | ||
2097 | } | ||
2098 | hdr->usb_cdc_union_desc = union_header; | ||
2099 | hdr->usb_cdc_header_desc = header; | ||
2100 | hdr->usb_cdc_mdlm_detail_desc = detail; | ||
2101 | hdr->usb_cdc_mdlm_desc = desc; | ||
2102 | hdr->usb_cdc_ether_desc = ether; | ||
2103 | return cnt; | ||
2104 | } | ||
2105 | |||
2106 | EXPORT_SYMBOL(cdc_parse_cdc_header); | ||
2107 | |||
2108 | /* | 1970 | /* |
2109 | * The function can't be called inside suspend/resume callback, | 1971 | * The function can't be called inside suspend/resume callback, |
2110 | * otherwise deadlock will be caused. | 1972 | * otherwise deadlock will be caused. |