cdc_ether.c 29 KB

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