cdc_ether.c 29 KB

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