xref: /linux/drivers/net/usb/cdc_ether.c (revision 91a4855d6c03e770e42f17c798a36a3c46e63de2)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * CDC Ethernet based networking peripherals
4  * Copyright (C) 2003-2005 by David Brownell
5  * Copyright (C) 2006 by Ole Andre Vadla Ravnas (ActiveSync)
6  */
7 
8 // #define	DEBUG			// error path messages, extra info
9 // #define	VERBOSE			// more; success messages
10 
11 #include <linux/module.h>
12 #include <linux/netdevice.h>
13 #include <linux/etherdevice.h>
14 #include <linux/ethtool.h>
15 #include <linux/workqueue.h>
16 #include <linux/mii.h>
17 #include <linux/usb.h>
18 #include <linux/usb/cdc.h>
19 #include <linux/usb/usbnet.h>
20 
21 
22 #if IS_ENABLED(CONFIG_USB_NET_RNDIS_HOST)
23 
24 static int is_rndis(struct usb_interface_descriptor *desc)
25 {
26 	return (desc->bInterfaceClass == USB_CLASS_COMM &&
27 		desc->bInterfaceSubClass == 2 &&
28 		desc->bInterfaceProtocol == 0xff);
29 }
30 
31 static int is_activesync(struct usb_interface_descriptor *desc)
32 {
33 	return (desc->bInterfaceClass == USB_CLASS_MISC &&
34 		desc->bInterfaceSubClass == 1 &&
35 		desc->bInterfaceProtocol == 1);
36 }
37 
38 static int is_wireless_rndis(struct usb_interface_descriptor *desc)
39 {
40 	return (desc->bInterfaceClass == USB_CLASS_WIRELESS_CONTROLLER &&
41 		desc->bInterfaceSubClass == 1 &&
42 		desc->bInterfaceProtocol == 3);
43 }
44 
45 static int is_novatel_rndis(struct usb_interface_descriptor *desc)
46 {
47 	return (desc->bInterfaceClass == USB_CLASS_MISC &&
48 		desc->bInterfaceSubClass == 4 &&
49 		desc->bInterfaceProtocol == 1);
50 }
51 
52 #else
53 
54 #define is_rndis(desc)		0
55 #define is_activesync(desc)	0
56 #define is_wireless_rndis(desc)	0
57 #define is_novatel_rndis(desc)	0
58 
59 #endif
60 
61 static const u8 mbm_guid[16] = {
62 	0xa3, 0x17, 0xa8, 0x8b, 0x04, 0x5e, 0x4f, 0x01,
63 	0xa6, 0x07, 0xc0, 0xff, 0xcb, 0x7e, 0x39, 0x2a,
64 };
65 
66 void usbnet_cdc_update_filter(struct usbnet *dev)
67 {
68 	struct net_device	*net = dev->net;
69 
70 	u16 cdc_filter = USB_CDC_PACKET_TYPE_DIRECTED
71 			| USB_CDC_PACKET_TYPE_BROADCAST;
72 
73 	/* filtering on the device is an optional feature and not worth
74 	 * the hassle so we just roughly care about snooping and if any
75 	 * multicast is requested, we take every multicast
76 	 */
77 	if (net->flags & IFF_PROMISC)
78 		cdc_filter |= USB_CDC_PACKET_TYPE_PROMISCUOUS;
79 	if (!netdev_mc_empty(net) || (net->flags & IFF_ALLMULTI))
80 		cdc_filter |= USB_CDC_PACKET_TYPE_ALL_MULTICAST;
81 
82 	usb_control_msg(dev->udev,
83 			usb_sndctrlpipe(dev->udev, 0),
84 			USB_CDC_SET_ETHERNET_PACKET_FILTER,
85 			USB_TYPE_CLASS | USB_RECIP_INTERFACE,
86 			cdc_filter,
87 			dev->intf->cur_altsetting->desc.bInterfaceNumber,
88 			NULL,
89 			0,
90 			USB_CTRL_SET_TIMEOUT
91 		);
92 }
93 EXPORT_SYMBOL_GPL(usbnet_cdc_update_filter);
94 
95 /* We need to override usbnet_*_link_ksettings in bind() */
96 static const struct ethtool_ops cdc_ether_ethtool_ops = {
97 	.get_link		= usbnet_get_link,
98 	.nway_reset		= usbnet_nway_reset,
99 	.get_drvinfo		= usbnet_get_drvinfo,
100 	.get_msglevel		= usbnet_get_msglevel,
101 	.set_msglevel		= usbnet_set_msglevel,
102 	.get_ts_info		= ethtool_op_get_ts_info,
103 	.get_link_ksettings	= usbnet_get_link_ksettings_internal,
104 	.set_link_ksettings	= NULL,
105 };
106 
107 /* probes control interface, claims data interface, collects the bulk
108  * endpoints, activates data interface (if needed), maybe sets MTU.
109  * all pure cdc, except for certain firmware workarounds, and knowing
110  * that rndis uses one different rule.
111  */
112 int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
113 {
114 	u8				*buf = intf->cur_altsetting->extra;
115 	int				len = intf->cur_altsetting->extralen;
116 	struct usb_interface_descriptor	*d;
117 	struct cdc_state		*info = (void *) &dev->data;
118 	int				status = -ENODEV;
119 	int				rndis;
120 	bool				android_rndis_quirk = false;
121 	struct usb_driver		*driver = driver_of(intf);
122 	struct usb_cdc_parsed_header header;
123 
124 	if (sizeof(dev->data) < sizeof(*info))
125 		return -EDOM;
126 
127 	/* expect strict spec conformance for the descriptors, but
128 	 * cope with firmware which stores them in the wrong place
129 	 */
130 	if (len == 0 && dev->udev->actconfig->extralen) {
131 		/* Motorola SB4100 (and others: Brad Hards says it's
132 		 * from a Broadcom design) put CDC descriptors here
133 		 */
134 		buf = dev->udev->actconfig->extra;
135 		len = dev->udev->actconfig->extralen;
136 		dev_dbg(&intf->dev, "CDC descriptors on config\n");
137 	}
138 
139 	/* Maybe CDC descriptors are after the endpoint?  This bug has
140 	 * been seen on some 2Wire Inc RNDIS-ish products.
141 	 */
142 	if (len == 0) {
143 		struct usb_host_endpoint	*hep;
144 
145 		hep = intf->cur_altsetting->endpoint;
146 		if (hep) {
147 			buf = hep->extra;
148 			len = hep->extralen;
149 		}
150 		if (len)
151 			dev_dbg(&intf->dev,
152 				"CDC descriptors on endpoint\n");
153 	}
154 
155 	/* this assumes that if there's a non-RNDIS vendor variant
156 	 * of cdc-acm, it'll fail RNDIS requests cleanly.
157 	 */
158 	rndis = (is_rndis(&intf->cur_altsetting->desc) ||
159 		 is_activesync(&intf->cur_altsetting->desc) ||
160 		 is_wireless_rndis(&intf->cur_altsetting->desc) ||
161 		 is_novatel_rndis(&intf->cur_altsetting->desc));
162 
163 	memset(info, 0, sizeof(*info));
164 	info->control = intf;
165 
166 	cdc_parse_cdc_header(&header, intf, buf, len);
167 
168 	info->u = header.usb_cdc_union_desc;
169 	info->header = header.usb_cdc_header_desc;
170 	info->ether = header.usb_cdc_ether_desc;
171 	if (!info->u) {
172 		if (rndis) {
173 			goto skip;
174 		} else {
175 			/* in that case a quirk is mandatory */
176 			dev_err(&dev->udev->dev, "No union descriptors\n");
177 			goto bad_desc;
178 		}
179 	}
180 	/* we need a master/control interface (what we're
181 	 * probed with) and a slave/data interface; union
182 	 * descriptors sort this all out.
183 	 */
184 	info->control = usb_ifnum_to_if(dev->udev, info->u->bMasterInterface0);
185 	info->data = usb_ifnum_to_if(dev->udev, info->u->bSlaveInterface0);
186 	if (!info->control || !info->data) {
187 		dev_dbg(&intf->dev,
188 			"master #%u/%p slave #%u/%p\n",
189 			info->u->bMasterInterface0,
190 			info->control,
191 			info->u->bSlaveInterface0,
192 			info->data);
193 		/* fall back to hard-wiring for RNDIS */
194 		if (rndis) {
195 			android_rndis_quirk = true;
196 			goto skip;
197 		}
198 		dev_err(&intf->dev, "bad CDC descriptors\n");
199 		goto bad_desc;
200 	}
201 	if (info->control != intf) {
202 		/* Ambit USB Cable Modem (and maybe others)
203 		 * interchanges master and slave interface.
204 		 */
205 		if (info->data == intf) {
206 			info->data = info->control;
207 			info->control = intf;
208 		} else {
209 			dev_err(&intf->dev, "bogus CDC Union\n");
210 			goto bad_desc;
211 		}
212 	}
213 
214 	/* some devices merge these - skip class check */
215 	if (info->control == info->data)
216 		goto skip;
217 
218 	/* a data interface altsetting does the real i/o */
219 	d = &info->data->cur_altsetting->desc;
220 	if (d->bInterfaceClass != USB_CLASS_CDC_DATA) {
221 		dev_err(&intf->dev, "slave class %u\n", d->bInterfaceClass);
222 		goto bad_desc;
223 	}
224 skip:
225 	/* Communication class functions with bmCapabilities are not
226 	 * RNDIS.  But some Wireless class RNDIS functions use
227 	 * bmCapabilities for their own purpose. The failsafe is
228 	 * therefore applied only to Communication class RNDIS
229 	 * functions.  The rndis test is redundant, but a cheap
230 	 * optimization.
231 	 */
232 	if (rndis && is_rndis(&intf->cur_altsetting->desc) &&
233 	    header.usb_cdc_acm_descriptor &&
234 	    header.usb_cdc_acm_descriptor->bmCapabilities) {
235 		dev_err(&intf->dev,
236 			"ACM capabilities %02x, not really RNDIS?\n",
237 			header.usb_cdc_acm_descriptor->bmCapabilities);
238 		goto bad_desc;
239 	}
240 
241 	if (header.usb_cdc_ether_desc && info->ether->wMaxSegmentSize) {
242 		dev->hard_mtu = le16_to_cpu(info->ether->wMaxSegmentSize);
243 		/* because of Zaurus, we may be ignoring the host
244 		 * side link address we were given.
245 		 */
246 	}
247 
248 	if (header.usb_cdc_mdlm_desc &&
249 	    memcmp(header.usb_cdc_mdlm_desc->bGUID, mbm_guid, 16)) {
250 		dev_err(&intf->dev, "GUID doesn't match\n");
251 		goto bad_desc;
252 	}
253 
254 	if (header.usb_cdc_mdlm_detail_desc &&
255 		header.usb_cdc_mdlm_detail_desc->bLength <
256 			(sizeof(struct usb_cdc_mdlm_detail_desc) + 1)) {
257 		dev_err(&intf->dev, "Descriptor too short\n");
258 		goto bad_desc;
259 	}
260 
261 
262 
263 	/* Microsoft ActiveSync based and some regular RNDIS devices lack the
264 	 * CDC descriptors, so we'll hard-wire the interfaces and not check
265 	 * for descriptors.
266 	 *
267 	 * Some Android RNDIS devices have a CDC Union descriptor pointing
268 	 * to non-existing interfaces.  Ignore that and attempt the same
269 	 * hard-wired 0 and 1 interfaces.
270 	 */
271 	if (rndis && (!info->u || android_rndis_quirk)) {
272 		info->control = usb_ifnum_to_if(dev->udev, 0);
273 		info->data = usb_ifnum_to_if(dev->udev, 1);
274 		if (!info->control || !info->data || info->control != intf) {
275 			dev_err(&intf->dev,
276 				"rndis: master #0/%p slave #1/%p\n",
277 				info->control,
278 				info->data);
279 			goto bad_desc;
280 		}
281 
282 	} else if (!info->header || (!rndis && !info->ether)) {
283 		dev_err(&intf->dev, "missing cdc %s%s%sdescriptor\n",
284 			info->header ? "" : "header ",
285 			info->u ? "" : "union ",
286 			info->ether ? "" : "ether ");
287 		goto bad_desc;
288 	}
289 
290 	/* claim data interface and set it up ... with side effects.
291 	 * network traffic can't flow until an altsetting is enabled.
292 	 */
293 	if (info->data != info->control) {
294 		status = usb_driver_claim_interface(driver, info->data, dev);
295 		if (status < 0) {
296 			dev_err(&intf->dev, "Second interface unclaimable\n");
297 			goto bad_desc;
298 		}
299 	}
300 	status = usbnet_get_endpoints(dev, info->data);
301 	if (status < 0) {
302 		dev_dbg(&intf->dev, "Mandatory endpoints missing\n");
303 		goto bail_out_and_release;
304 	}
305 
306 	/* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */
307 	if (info->data != info->control)
308 		dev->status = NULL;
309 	if (info->control->cur_altsetting->desc.bNumEndpoints == 1) {
310 		struct usb_endpoint_descriptor	*desc;
311 
312 		dev->status = &info->control->cur_altsetting->endpoint[0];
313 		desc = &dev->status->desc;
314 		if (!usb_endpoint_is_int_in(desc) ||
315 		    (le16_to_cpu(desc->wMaxPacketSize)
316 		     < sizeof(struct usb_cdc_notification)) ||
317 		    !desc->bInterval) {
318 			dev_dbg(&intf->dev, "bad notification endpoint\n");
319 			dev->status = NULL;
320 		}
321 	}
322 	if (rndis && !dev->status) {
323 		dev_err(&intf->dev, "missing RNDIS status endpoint\n");
324 		status = -ENODEV;
325 		goto bail_out_and_release;
326 	}
327 
328 	/* override ethtool_ops */
329 	dev->net->ethtool_ops = &cdc_ether_ethtool_ops;
330 
331 	return 0;
332 
333 bail_out_and_release:
334 	usb_set_intfdata(info->data, NULL);
335 	if (info->data != info->control)
336 		usb_driver_release_interface(driver, info->data);
337 bad_desc:
338 	return status;
339 }
340 EXPORT_SYMBOL_GPL(usbnet_generic_cdc_bind);
341 
342 
343 /* like usbnet_generic_cdc_bind() but handles filter initialization
344  * correctly
345  */
346 int usbnet_ether_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
347 {
348 	int rv;
349 
350 	rv = usbnet_generic_cdc_bind(dev, intf);
351 	if (rv < 0)
352 		goto bail_out;
353 
354 	/* Some devices don't initialise properly. In particular
355 	 * the packet filter is not reset. There are devices that
356 	 * don't do reset all the way. So the packet filter should
357 	 * be set to a sane initial value.
358 	 */
359 	usbnet_cdc_update_filter(dev);
360 
361 bail_out:
362 	return rv;
363 }
364 EXPORT_SYMBOL_GPL(usbnet_ether_cdc_bind);
365 
366 void usbnet_cdc_unbind(struct usbnet *dev, struct usb_interface *intf)
367 {
368 	struct cdc_state		*info = (void *) &dev->data;
369 	struct usb_driver		*driver = driver_of(intf);
370 
371 	/* combined interface - nothing  to do */
372 	if (info->data == info->control)
373 		return;
374 
375 	/* disconnect master --> disconnect slave */
376 	if (intf == info->control && info->data) {
377 		/* ensure immediate exit from usbnet_disconnect */
378 		usb_set_intfdata(info->data, NULL);
379 		usb_driver_release_interface(driver, info->data);
380 		info->data = NULL;
381 	}
382 
383 	/* and vice versa (just in case) */
384 	else if (intf == info->data && info->control) {
385 		/* ensure immediate exit from usbnet_disconnect */
386 		usb_set_intfdata(info->control, NULL);
387 		usb_driver_release_interface(driver, info->control);
388 		info->control = NULL;
389 	}
390 }
391 EXPORT_SYMBOL_GPL(usbnet_cdc_unbind);
392 
393 /* Communications Device Class, Ethernet Control model
394  *
395  * Takes two interfaces.  The DATA interface is inactive till an altsetting
396  * is selected.  Configuration data includes class descriptors.  There's
397  * an optional status endpoint on the control interface.
398  *
399  * This should interop with whatever the 2.4 "CDCEther.c" driver
400  * (by Brad Hards) talked with, with more functionality.
401  */
402 
403 static void speed_change(struct usbnet *dev, __le32 *speeds)
404 {
405 	dev->tx_speed = __le32_to_cpu(speeds[0]);
406 	dev->rx_speed = __le32_to_cpu(speeds[1]);
407 }
408 
409 void usbnet_cdc_status(struct usbnet *dev, struct urb *urb)
410 {
411 	struct usb_cdc_notification	*event;
412 
413 	if (urb->actual_length < sizeof(*event))
414 		return;
415 
416 	/* SPEED_CHANGE can get split into two 8-byte packets */
417 	if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) {
418 		speed_change(dev, (__le32 *) urb->transfer_buffer);
419 		return;
420 	}
421 
422 	event = urb->transfer_buffer;
423 	switch (event->bNotificationType) {
424 	case USB_CDC_NOTIFY_NETWORK_CONNECTION:
425 		netif_dbg(dev, timer, dev->net, "CDC: carrier %s\n",
426 			  event->wValue ? "on" : "off");
427 		if (netif_carrier_ok(dev->net) != !!event->wValue)
428 			usbnet_link_change(dev, !!event->wValue, 0);
429 		break;
430 	case USB_CDC_NOTIFY_SPEED_CHANGE:	/* tx/rx rates */
431 		netif_dbg(dev, timer, dev->net, "CDC: speed change (len %d)\n",
432 			  urb->actual_length);
433 		if (urb->actual_length != (sizeof(*event) + 8))
434 			set_bit(EVENT_STS_SPLIT, &dev->flags);
435 		else
436 			speed_change(dev, (__le32 *) &event[1]);
437 		break;
438 	/* USB_CDC_NOTIFY_RESPONSE_AVAILABLE can happen too (e.g. RNDIS),
439 	 * but there are no standard formats for the response data.
440 	 */
441 	default:
442 		netdev_err(dev->net, "CDC: unexpected notification %02x!\n",
443 			   event->bNotificationType);
444 		break;
445 	}
446 }
447 EXPORT_SYMBOL_GPL(usbnet_cdc_status);
448 
449 int usbnet_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
450 {
451 	int				status;
452 	struct cdc_state		*info = (void *) &dev->data;
453 
454 	BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data)
455 			< sizeof(struct cdc_state)));
456 
457 	status = usbnet_ether_cdc_bind(dev, intf);
458 	if (status < 0)
459 		return status;
460 
461 	status = usbnet_get_ethernet_addr(dev, info->ether->iMACAddress);
462 	if (status < 0) {
463 		usb_set_intfdata(info->data, NULL);
464 		usb_driver_release_interface(driver_of(intf), info->data);
465 		return status;
466 	}
467 
468 	return 0;
469 }
470 EXPORT_SYMBOL_GPL(usbnet_cdc_bind);
471 
472 static int usbnet_cdc_zte_bind(struct usbnet *dev, struct usb_interface *intf)
473 {
474 	int status = usbnet_cdc_bind(dev, intf);
475 
476 	if (!status && (dev->net->dev_addr[0] & 0x02))
477 		eth_hw_addr_random(dev->net);
478 
479 	return status;
480 }
481 
482 /* Make sure packets have correct destination MAC address
483  *
484  * A firmware bug observed on some devices (ZTE MF823/831/910) is that the
485  * device sends packets with a static, bogus, random MAC address (event if
486  * device MAC address has been updated). Always set MAC address to that of the
487  * device.
488  */
489 int usbnet_cdc_zte_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
490 {
491 	if (skb->len < ETH_HLEN || !(skb->data[0] & 0x02))
492 		return 1;
493 
494 	skb_reset_mac_header(skb);
495 	ether_addr_copy(eth_hdr(skb)->h_dest, dev->net->dev_addr);
496 
497 	return 1;
498 }
499 EXPORT_SYMBOL_GPL(usbnet_cdc_zte_rx_fixup);
500 
501 /* Ensure correct link state
502  *
503  * Some devices (ZTE MF823/831/910) export two carrier on notifications when
504  * connected. This causes the link state to be incorrect. Work around this by
505  * always setting the state to off, then on.
506  */
507 static void usbnet_cdc_zte_status(struct usbnet *dev, struct urb *urb)
508 {
509 	struct usb_cdc_notification *event;
510 
511 	if (urb->actual_length < sizeof(*event))
512 		return;
513 
514 	event = urb->transfer_buffer;
515 
516 	if (event->bNotificationType != USB_CDC_NOTIFY_NETWORK_CONNECTION) {
517 		usbnet_cdc_status(dev, urb);
518 		return;
519 	}
520 
521 	netif_dbg(dev, timer, dev->net, "CDC: carrier %s\n",
522 		  event->wValue ? "on" : "off");
523 
524 	if (event->wValue &&
525 	    netif_carrier_ok(dev->net))
526 		netif_carrier_off(dev->net);
527 
528 	usbnet_link_change(dev, !!event->wValue, 0);
529 }
530 
531 static const struct driver_info	cdc_info = {
532 	.description =	"CDC Ethernet Device",
533 	.flags =	FLAG_ETHER | FLAG_POINTTOPOINT,
534 	.bind =		usbnet_cdc_bind,
535 	.unbind =	usbnet_cdc_unbind,
536 	.status =	usbnet_cdc_status,
537 	.set_rx_mode =	usbnet_cdc_update_filter,
538 	.manage_power =	usbnet_manage_power,
539 };
540 
541 static const struct driver_info	zte_cdc_info = {
542 	.description =	"ZTE CDC Ethernet Device",
543 	.flags =	FLAG_ETHER | FLAG_POINTTOPOINT,
544 	.bind =		usbnet_cdc_zte_bind,
545 	.unbind =	usbnet_cdc_unbind,
546 	.status =	usbnet_cdc_zte_status,
547 	.set_rx_mode =	usbnet_cdc_update_filter,
548 	.manage_power =	usbnet_manage_power,
549 	.rx_fixup = usbnet_cdc_zte_rx_fixup,
550 };
551 
552 static const struct driver_info wwan_info = {
553 	.description =	"Mobile Broadband Network Device",
554 	.flags =	FLAG_WWAN,
555 	.bind =		usbnet_cdc_bind,
556 	.unbind =	usbnet_cdc_unbind,
557 	.status =	usbnet_cdc_status,
558 	.set_rx_mode =	usbnet_cdc_update_filter,
559 	.manage_power =	usbnet_manage_power,
560 };
561 
562 /*-------------------------------------------------------------------------*/
563 
564 #define HUAWEI_VENDOR_ID	0x12D1
565 #define NOVATEL_VENDOR_ID	0x1410
566 #define ZTE_VENDOR_ID		0x19D2
567 #define DELL_VENDOR_ID		0x413C
568 #define REALTEK_VENDOR_ID	0x0bda
569 #define SAMSUNG_VENDOR_ID	0x04e8
570 #define LENOVO_VENDOR_ID	0x17ef
571 #define LINKSYS_VENDOR_ID	0x13b1
572 #define NVIDIA_VENDOR_ID	0x0955
573 #define HP_VENDOR_ID		0x03f0
574 #define MICROSOFT_VENDOR_ID	0x045e
575 #define UBLOX_VENDOR_ID		0x1546
576 #define TPLINK_VENDOR_ID	0x2357
577 #define AQUANTIA_VENDOR_ID	0x2eca
578 #define ASIX_VENDOR_ID		0x0b95
579 
580 static const struct usb_device_id	products[] = {
581 /* BLACKLIST !!
582  *
583  * First blacklist any products that are egregiously nonconformant
584  * with the CDC Ethernet specs.  Minor braindamage we cope with; when
585  * they're not even trying, needing a separate driver is only the first
586  * of the differences to show up.
587  */
588 
589 #define	ZAURUS_MASTER_INTERFACE \
590 	.bInterfaceClass	= USB_CLASS_COMM, \
591 	.bInterfaceSubClass	= USB_CDC_SUBCLASS_ETHERNET, \
592 	.bInterfaceProtocol	= USB_CDC_PROTO_NONE
593 
594 #define ZAURUS_FAKE_INTERFACE \
595 	.bInterfaceClass	= USB_CLASS_COMM, \
596 	.bInterfaceSubClass	= USB_CDC_SUBCLASS_MDLM, \
597 	.bInterfaceProtocol	= USB_CDC_PROTO_NONE
598 
599 /* SA-1100 based Sharp Zaurus ("collie"), or compatible;
600  * wire-incompatible with true CDC Ethernet implementations.
601  * (And, it seems, needlessly so...)
602  */
603 {
604 	.match_flags	=   USB_DEVICE_ID_MATCH_INT_INFO
605 			  | USB_DEVICE_ID_MATCH_DEVICE,
606 	.idVendor		= 0x04DD,
607 	.idProduct		= 0x8004,
608 	ZAURUS_MASTER_INTERFACE,
609 	.driver_info		= 0,
610 },
611 
612 /* PXA-25x based Sharp Zaurii.  Note that it seems some of these
613  * (later models especially) may have shipped only with firmware
614  * advertising false "CDC MDLM" compatibility ... but we're not
615  * clear which models did that, so for now let's assume the worst.
616  */
617 {
618 	.match_flags	=   USB_DEVICE_ID_MATCH_INT_INFO
619 			  | USB_DEVICE_ID_MATCH_DEVICE,
620 	.idVendor		= 0x04DD,
621 	.idProduct		= 0x8005,	/* A-300 */
622 	ZAURUS_MASTER_INTERFACE,
623 	.driver_info		= 0,
624 }, {
625 	.match_flags	=   USB_DEVICE_ID_MATCH_INT_INFO
626 			  | USB_DEVICE_ID_MATCH_DEVICE,
627 	.idVendor		= 0x04DD,
628 	.idProduct		= 0x8005,   /* A-300 */
629 	ZAURUS_FAKE_INTERFACE,
630 	.driver_info        = 0,
631 }, {
632 	.match_flags    =   USB_DEVICE_ID_MATCH_INT_INFO
633 			  | USB_DEVICE_ID_MATCH_DEVICE,
634 	.idVendor		= 0x04DD,
635 	.idProduct		= 0x8006,	/* B-500/SL-5600 */
636 	ZAURUS_MASTER_INTERFACE,
637 	.driver_info		= 0,
638 }, {
639 	.match_flags    =   USB_DEVICE_ID_MATCH_INT_INFO
640 			  | USB_DEVICE_ID_MATCH_DEVICE,
641 	.idVendor		= 0x04DD,
642 	.idProduct		= 0x8006,   /* B-500/SL-5600 */
643 	ZAURUS_FAKE_INTERFACE,
644 	.driver_info        = 0,
645 }, {
646 	.match_flags    =   USB_DEVICE_ID_MATCH_INT_INFO
647 			  | USB_DEVICE_ID_MATCH_DEVICE,
648 	.idVendor		= 0x04DD,
649 	.idProduct		= 0x8007,	/* C-700 */
650 	ZAURUS_MASTER_INTERFACE,
651 	.driver_info		= 0,
652 }, {
653 	.match_flags    =   USB_DEVICE_ID_MATCH_INT_INFO
654 			  | USB_DEVICE_ID_MATCH_DEVICE,
655 	.idVendor		= 0x04DD,
656 	.idProduct		= 0x8007,   /* C-700 */
657 	ZAURUS_FAKE_INTERFACE,
658 	.driver_info        = 0,
659 }, {
660 	.match_flags    =   USB_DEVICE_ID_MATCH_INT_INFO
661 		 | USB_DEVICE_ID_MATCH_DEVICE,
662 	.idVendor               = 0x04DD,
663 	.idProduct              = 0x9031,	/* C-750 C-760 */
664 	ZAURUS_MASTER_INTERFACE,
665 	.driver_info		= 0,
666 }, {
667 	.match_flags    =   USB_DEVICE_ID_MATCH_INT_INFO
668 		 | USB_DEVICE_ID_MATCH_DEVICE,
669 	.idVendor               = 0x04DD,
670 	.idProduct              = 0x9032,	/* SL-6000 */
671 	ZAURUS_MASTER_INTERFACE,
672 	.driver_info		= 0,
673 }, {
674 	.match_flags    =   USB_DEVICE_ID_MATCH_INT_INFO
675 		 | USB_DEVICE_ID_MATCH_DEVICE,
676 	.idVendor               = 0x04DD,
677 	.idProduct              = 0x9032,	/* SL-6000 */
678 	ZAURUS_FAKE_INTERFACE,
679 	.driver_info		= 0,
680 }, {
681 	.match_flags    =   USB_DEVICE_ID_MATCH_INT_INFO
682 		 | USB_DEVICE_ID_MATCH_DEVICE,
683 	.idVendor               = 0x04DD,
684 	/* reported with some C860 units */
685 	.idProduct              = 0x9050,	/* C-860 */
686 	ZAURUS_MASTER_INTERFACE,
687 	.driver_info		= 0,
688 },
689 
690 /* Olympus has some models with a Zaurus-compatible option.
691  * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
692  */
693 {
694 	.match_flags    =   USB_DEVICE_ID_MATCH_INT_INFO
695 		 | USB_DEVICE_ID_MATCH_DEVICE,
696 	.idVendor               = 0x07B4,
697 	.idProduct              = 0x0F02,	/* R-1000 */
698 	ZAURUS_MASTER_INTERFACE,
699 	.driver_info		= 0,
700 },
701 
702 /* LG Electronics VL600 wants additional headers on every frame */
703 {
704 	USB_DEVICE_AND_INTERFACE_INFO(0x1004, 0x61aa, USB_CLASS_COMM,
705 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
706 	.driver_info = 0,
707 },
708 
709 /* Logitech Harmony 900 - uses the pseudo-MDLM (BLAN) driver */
710 {
711 	USB_DEVICE_AND_INTERFACE_INFO(0x046d, 0xc11f, USB_CLASS_COMM,
712 			USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
713 	.driver_info		= 0,
714 },
715 
716 /* Novatel USB551L and MC551 - handled by qmi_wwan */
717 {
718 	USB_DEVICE_AND_INTERFACE_INFO(NOVATEL_VENDOR_ID, 0xB001, USB_CLASS_COMM,
719 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
720 	.driver_info = 0,
721 },
722 
723 /* Novatel E362 - handled by qmi_wwan */
724 {
725 	USB_DEVICE_AND_INTERFACE_INFO(NOVATEL_VENDOR_ID, 0x9010, USB_CLASS_COMM,
726 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
727 	.driver_info = 0,
728 },
729 
730 /* Dell Wireless 5800 (Novatel E362) - handled by qmi_wwan */
731 {
732 	USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x8195, USB_CLASS_COMM,
733 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
734 	.driver_info = 0,
735 },
736 
737 /* Dell Wireless 5800 (Novatel E362) - handled by qmi_wwan */
738 {
739 	USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x8196, USB_CLASS_COMM,
740 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
741 	.driver_info = 0,
742 },
743 
744 /* Dell Wireless 5804 (Novatel E371) - handled by qmi_wwan */
745 {
746 	USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x819b, USB_CLASS_COMM,
747 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
748 	.driver_info = 0,
749 },
750 
751 /* Novatel Expedite E371 - handled by qmi_wwan */
752 {
753 	USB_DEVICE_AND_INTERFACE_INFO(NOVATEL_VENDOR_ID, 0x9011, USB_CLASS_COMM,
754 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
755 	.driver_info = 0,
756 },
757 
758 /* HP lt2523 (Novatel E371) - handled by qmi_wwan */
759 {
760 	USB_DEVICE_AND_INTERFACE_INFO(HP_VENDOR_ID, 0x421d, USB_CLASS_COMM,
761 				      USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
762 	.driver_info = 0,
763 },
764 
765 /* AnyDATA ADU960S - handled by qmi_wwan */
766 {
767 	USB_DEVICE_AND_INTERFACE_INFO(0x16d5, 0x650a, USB_CLASS_COMM,
768 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
769 	.driver_info = 0,
770 },
771 
772 /* Huawei E1820 - handled by qmi_wwan */
773 {
774 	USB_DEVICE_INTERFACE_NUMBER(HUAWEI_VENDOR_ID, 0x14ac, 1),
775 	.driver_info = 0,
776 },
777 
778 /* Realtek RTL8153 Based USB 3.0 Ethernet Adapters */
779 {
780 	USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8153, USB_CLASS_COMM,
781 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
782 	.driver_info = 0,
783 },
784 
785 /* Lenovo Powered USB-C Travel Hub (4X90S92381, based on Realtek RTL8153) */
786 {
787 	USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x721e, USB_CLASS_COMM,
788 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
789 	.driver_info = 0,
790 },
791 
792 /* Lenovo ThinkPad Hybrid USB-C with USB-A Dock (40af0135eu, based on Realtek RTL8153) */
793 {
794 	USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0xa359, USB_CLASS_COMM,
795 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
796 	.driver_info = 0,
797 },
798 
799 /* Aquantia AQtion USB to 5GbE Controller (based on AQC111U) */
800 {
801 	USB_DEVICE_AND_INTERFACE_INFO(AQUANTIA_VENDOR_ID, 0xc101,
802 				      USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
803 				      USB_CDC_PROTO_NONE),
804 	.driver_info = 0,
805 },
806 
807 /* ASIX USB 3.1 Gen1 to 5G Multi-Gigabit Ethernet Adapter(based on AQC111U) */
808 {
809 	USB_DEVICE_AND_INTERFACE_INFO(ASIX_VENDOR_ID, 0x2790, USB_CLASS_COMM,
810 				      USB_CDC_SUBCLASS_ETHERNET,
811 				      USB_CDC_PROTO_NONE),
812 	.driver_info = 0,
813 },
814 
815 /* ASIX USB 3.1 Gen1 to 2.5G Multi-Gigabit Ethernet Adapter(based on AQC112U) */
816 {
817 	USB_DEVICE_AND_INTERFACE_INFO(ASIX_VENDOR_ID, 0x2791, USB_CLASS_COMM,
818 				      USB_CDC_SUBCLASS_ETHERNET,
819 				      USB_CDC_PROTO_NONE),
820 	.driver_info = 0,
821 },
822 
823 /* USB-C 3.1 to 5GBASE-T Ethernet Adapter (based on AQC111U) */
824 {
825 	USB_DEVICE_AND_INTERFACE_INFO(0x20f4, 0xe05a, USB_CLASS_COMM,
826 				      USB_CDC_SUBCLASS_ETHERNET,
827 				      USB_CDC_PROTO_NONE),
828 	.driver_info = 0,
829 },
830 
831 /* QNAP QNA-UC5G1T USB to 5GbE Adapter (based on AQC111U) */
832 {
833 	USB_DEVICE_AND_INTERFACE_INFO(0x1c04, 0x0015, USB_CLASS_COMM,
834 				      USB_CDC_SUBCLASS_ETHERNET,
835 				      USB_CDC_PROTO_NONE),
836 	.driver_info = 0,
837 },
838 
839 /* WHITELIST!!!
840  *
841  * CDC Ether uses two interfaces, not necessarily consecutive.
842  * We match the main interface, ignoring the optional device
843  * class so we could handle devices that aren't exclusively
844  * CDC ether.
845  *
846  * NOTE:  this match must come AFTER entries blacklisting devices
847  * because of bugs/quirks in a given product (like Zaurus, above).
848  */
849 {
850 	/* ZTE (Vodafone) K3805-Z */
851 	USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1003, USB_CLASS_COMM,
852 				      USB_CDC_SUBCLASS_ETHERNET,
853 				      USB_CDC_PROTO_NONE),
854 	.driver_info = (unsigned long)&wwan_info,
855 }, {
856 	/* ZTE (Vodafone) K3806-Z */
857 	USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1015, USB_CLASS_COMM,
858 				      USB_CDC_SUBCLASS_ETHERNET,
859 				      USB_CDC_PROTO_NONE),
860 	.driver_info = (unsigned long)&wwan_info,
861 }, {
862 	/* ZTE (Vodafone) K4510-Z */
863 	USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1173, USB_CLASS_COMM,
864 				      USB_CDC_SUBCLASS_ETHERNET,
865 				      USB_CDC_PROTO_NONE),
866 	.driver_info = (unsigned long)&wwan_info,
867 }, {
868 	/* ZTE (Vodafone) K3770-Z */
869 	USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1177, USB_CLASS_COMM,
870 				      USB_CDC_SUBCLASS_ETHERNET,
871 				      USB_CDC_PROTO_NONE),
872 	.driver_info = (unsigned long)&wwan_info,
873 }, {
874 	/* ZTE (Vodafone) K3772-Z */
875 	USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1181, USB_CLASS_COMM,
876 				      USB_CDC_SUBCLASS_ETHERNET,
877 				      USB_CDC_PROTO_NONE),
878 	.driver_info = (unsigned long)&wwan_info,
879 }, {
880 	/* Telit modules */
881 	USB_VENDOR_AND_INTERFACE_INFO(0x1bc7, USB_CLASS_COMM,
882 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
883 	.driver_info = (kernel_ulong_t) &wwan_info,
884 }, {
885 	/* Dell DW5580 modules */
886 	USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x81ba, USB_CLASS_COMM,
887 			USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
888 	.driver_info = (kernel_ulong_t)&wwan_info,
889 }, {
890 	/* Huawei ME906 and ME909 */
891 	USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x15c1, USB_CLASS_COMM,
892 				      USB_CDC_SUBCLASS_ETHERNET,
893 				      USB_CDC_PROTO_NONE),
894 	.driver_info = (unsigned long)&wwan_info,
895 }, {
896 	/* ZTE modules */
897 	USB_VENDOR_AND_INTERFACE_INFO(ZTE_VENDOR_ID, USB_CLASS_COMM,
898 				      USB_CDC_SUBCLASS_ETHERNET,
899 				      USB_CDC_PROTO_NONE),
900 	.driver_info = (unsigned long)&zte_cdc_info,
901 }, {
902 	/* U-blox TOBY-L2 */
903 	USB_DEVICE_AND_INTERFACE_INFO(UBLOX_VENDOR_ID, 0x1143, USB_CLASS_COMM,
904 				      USB_CDC_SUBCLASS_ETHERNET,
905 				      USB_CDC_PROTO_NONE),
906 	.driver_info = (unsigned long)&wwan_info,
907 }, {
908 	/* U-blox SARA-U2 */
909 	USB_DEVICE_AND_INTERFACE_INFO(UBLOX_VENDOR_ID, 0x1104, USB_CLASS_COMM,
910 				      USB_CDC_SUBCLASS_ETHERNET,
911 				      USB_CDC_PROTO_NONE),
912 	.driver_info = (unsigned long)&wwan_info,
913 }, {
914 	/* U-blox LARA-R6 01B */
915 	USB_DEVICE_AND_INTERFACE_INFO(UBLOX_VENDOR_ID, 0x1313, USB_CLASS_COMM,
916 				      USB_CDC_SUBCLASS_ETHERNET,
917 				      USB_CDC_PROTO_NONE),
918 	.driver_info = (unsigned long)&wwan_info,
919 }, {
920 	/* U-blox LARA-L6 */
921 	USB_DEVICE_AND_INTERFACE_INFO(UBLOX_VENDOR_ID, 0x1343, USB_CLASS_COMM,
922 				      USB_CDC_SUBCLASS_ETHERNET,
923 				      USB_CDC_PROTO_NONE),
924 	.driver_info = (unsigned long)&wwan_info,
925 }, {
926 	/* Cinterion PLS8 modem by GEMALTO */
927 	USB_DEVICE_AND_INTERFACE_INFO(0x1e2d, 0x0061, USB_CLASS_COMM,
928 				      USB_CDC_SUBCLASS_ETHERNET,
929 				      USB_CDC_PROTO_NONE),
930 	.driver_info = (unsigned long)&wwan_info,
931 }, {
932 	/* Cinterion AHS3 modem by GEMALTO */
933 	USB_DEVICE_AND_INTERFACE_INFO(0x1e2d, 0x0055, USB_CLASS_COMM,
934 				      USB_CDC_SUBCLASS_ETHERNET,
935 				      USB_CDC_PROTO_NONE),
936 	.driver_info = (unsigned long)&wwan_info,
937 }, {
938 	/* Cinterion PLS62-W modem by GEMALTO/THALES */
939 	USB_DEVICE_AND_INTERFACE_INFO(0x1e2d, 0x005b, USB_CLASS_COMM,
940 				      USB_CDC_SUBCLASS_ETHERNET,
941 				      USB_CDC_PROTO_NONE),
942 	.driver_info = (unsigned long)&wwan_info,
943 }, {
944 	/* Cinterion PLS83/PLS63 modem by GEMALTO/THALES */
945 	USB_DEVICE_AND_INTERFACE_INFO(0x1e2d, 0x0069, USB_CLASS_COMM,
946 				      USB_CDC_SUBCLASS_ETHERNET,
947 				      USB_CDC_PROTO_NONE),
948 	.driver_info = (unsigned long)&wwan_info,
949 }, {
950 	USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
951 			USB_CDC_PROTO_NONE),
952 	.driver_info = (unsigned long) &cdc_info,
953 }, {
954 	USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
955 			USB_CDC_PROTO_NONE),
956 	.driver_info = (unsigned long)&wwan_info,
957 
958 }, {
959 	/* Various Huawei modems with a network port like the UMG1831 */
960 	USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_COMM,
961 				      USB_CDC_SUBCLASS_ETHERNET, 255),
962 	.driver_info = (unsigned long)&wwan_info,
963 },
964 	{ },		/* END */
965 };
966 MODULE_DEVICE_TABLE(usb, products);
967 
968 static struct usb_driver cdc_driver = {
969 	.name =		"cdc_ether",
970 	.id_table =	products,
971 	.probe =	usbnet_probe,
972 	.disconnect =	usbnet_disconnect,
973 	.suspend =	usbnet_suspend,
974 	.resume =	usbnet_resume,
975 	.reset_resume =	usbnet_resume,
976 	.supports_autosuspend = 1,
977 	.disable_hub_initiated_lpm = 1,
978 };
979 
980 module_usb_driver(cdc_driver);
981 
982 MODULE_AUTHOR("David Brownell");
983 MODULE_DESCRIPTION("USB CDC Ethernet devices");
984 MODULE_LICENSE("GPL");
985