cdc_ether.c 28 KB

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