cdc_ether.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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. if ( rndis &&
  198. header.usb_cdc_acm_descriptor &&
  199. header.usb_cdc_acm_descriptor->bmCapabilities) {
  200. dev_dbg(&intf->dev,
  201. "ACM capabilities %02x, not really RNDIS?\n",
  202. header.usb_cdc_acm_descriptor->bmCapabilities);
  203. goto bad_desc;
  204. }
  205. if (header.usb_cdc_ether_desc) {
  206. dev->hard_mtu = le16_to_cpu(info->ether->wMaxSegmentSize);
  207. /* because of Zaurus, we may be ignoring the host
  208. * side link address we were given.
  209. */
  210. }
  211. if (header.usb_cdc_mdlm_desc &&
  212. memcmp(header.usb_cdc_mdlm_desc->bGUID, mbm_guid, 16)) {
  213. dev_dbg(&intf->dev, "GUID doesn't match\n");
  214. goto bad_desc;
  215. }
  216. if (header.usb_cdc_mdlm_detail_desc &&
  217. header.usb_cdc_mdlm_detail_desc->bLength <
  218. (sizeof(struct usb_cdc_mdlm_detail_desc) + 1)) {
  219. dev_dbg(&intf->dev, "Descriptor too short\n");
  220. goto bad_desc;
  221. }
  222. /* Microsoft ActiveSync based and some regular RNDIS devices lack the
  223. * CDC descriptors, so we'll hard-wire the interfaces and not check
  224. * for descriptors.
  225. *
  226. * Some Android RNDIS devices have a CDC Union descriptor pointing
  227. * to non-existing interfaces. Ignore that and attempt the same
  228. * hard-wired 0 and 1 interfaces.
  229. */
  230. if (rndis && (!info->u || android_rndis_quirk)) {
  231. info->control = usb_ifnum_to_if(dev->udev, 0);
  232. info->data = usb_ifnum_to_if(dev->udev, 1);
  233. if (!info->control || !info->data || info->control != intf) {
  234. dev_dbg(&intf->dev,
  235. "rndis: master #0/%p slave #1/%p\n",
  236. info->control,
  237. info->data);
  238. goto bad_desc;
  239. }
  240. } else if (!info->header || (!rndis && !info->ether)) {
  241. dev_dbg(&intf->dev, "missing cdc %s%s%sdescriptor\n",
  242. info->header ? "" : "header ",
  243. info->u ? "" : "union ",
  244. info->ether ? "" : "ether ");
  245. goto bad_desc;
  246. }
  247. /* claim data interface and set it up ... with side effects.
  248. * network traffic can't flow until an altsetting is enabled.
  249. */
  250. if (info->data != info->control) {
  251. status = usb_driver_claim_interface(driver, info->data, dev);
  252. if (status < 0)
  253. return status;
  254. }
  255. status = usbnet_get_endpoints(dev, info->data);
  256. if (status < 0) {
  257. /* ensure immediate exit from usbnet_disconnect */
  258. usb_set_intfdata(info->data, NULL);
  259. if (info->data != info->control)
  260. usb_driver_release_interface(driver, info->data);
  261. return status;
  262. }
  263. /* status endpoint: optional for CDC Ethernet, not RNDIS (or ACM) */
  264. if (info->data != info->control)
  265. dev->status = NULL;
  266. if (info->control->cur_altsetting->desc.bNumEndpoints == 1) {
  267. struct usb_endpoint_descriptor *desc;
  268. dev->status = &info->control->cur_altsetting->endpoint [0];
  269. desc = &dev->status->desc;
  270. if (!usb_endpoint_is_int_in(desc) ||
  271. (le16_to_cpu(desc->wMaxPacketSize)
  272. < sizeof(struct usb_cdc_notification)) ||
  273. !desc->bInterval) {
  274. dev_dbg(&intf->dev, "bad notification endpoint\n");
  275. dev->status = NULL;
  276. }
  277. }
  278. if (rndis && !dev->status) {
  279. dev_dbg(&intf->dev, "missing RNDIS status endpoint\n");
  280. usb_set_intfdata(info->data, NULL);
  281. usb_driver_release_interface(driver, info->data);
  282. return -ENODEV;
  283. }
  284. return 0;
  285. bad_desc:
  286. dev_info(&dev->udev->dev, "bad CDC descriptors\n");
  287. return -ENODEV;
  288. }
  289. EXPORT_SYMBOL_GPL(usbnet_generic_cdc_bind);
  290. /* like usbnet_generic_cdc_bind() but handles filter initialization
  291. * correctly
  292. */
  293. int usbnet_ether_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
  294. {
  295. int rv;
  296. rv = usbnet_generic_cdc_bind(dev, intf);
  297. if (rv < 0)
  298. goto bail_out;
  299. /* Some devices don't initialise properly. In particular
  300. * the packet filter is not reset. There are devices that
  301. * don't do reset all the way. So the packet filter should
  302. * be set to a sane initial value.
  303. */
  304. usbnet_cdc_update_filter(dev);
  305. bail_out:
  306. return rv;
  307. }
  308. EXPORT_SYMBOL_GPL(usbnet_ether_cdc_bind);
  309. void usbnet_cdc_unbind(struct usbnet *dev, struct usb_interface *intf)
  310. {
  311. struct cdc_state *info = (void *) &dev->data;
  312. struct usb_driver *driver = driver_of(intf);
  313. /* combined interface - nothing to do */
  314. if (info->data == info->control)
  315. return;
  316. /* disconnect master --> disconnect slave */
  317. if (intf == info->control && info->data) {
  318. /* ensure immediate exit from usbnet_disconnect */
  319. usb_set_intfdata(info->data, NULL);
  320. usb_driver_release_interface(driver, info->data);
  321. info->data = NULL;
  322. }
  323. /* and vice versa (just in case) */
  324. else if (intf == info->data && info->control) {
  325. /* ensure immediate exit from usbnet_disconnect */
  326. usb_set_intfdata(info->control, NULL);
  327. usb_driver_release_interface(driver, info->control);
  328. info->control = NULL;
  329. }
  330. }
  331. EXPORT_SYMBOL_GPL(usbnet_cdc_unbind);
  332. /* Communications Device Class, Ethernet Control model
  333. *
  334. * Takes two interfaces. The DATA interface is inactive till an altsetting
  335. * is selected. Configuration data includes class descriptors. There's
  336. * an optional status endpoint on the control interface.
  337. *
  338. * This should interop with whatever the 2.4 "CDCEther.c" driver
  339. * (by Brad Hards) talked with, with more functionality.
  340. */
  341. static void dumpspeed(struct usbnet *dev, __le32 *speeds)
  342. {
  343. netif_info(dev, timer, dev->net,
  344. "link speeds: %u kbps up, %u kbps down\n",
  345. __le32_to_cpu(speeds[0]) / 1000,
  346. __le32_to_cpu(speeds[1]) / 1000);
  347. }
  348. void usbnet_cdc_status(struct usbnet *dev, struct urb *urb)
  349. {
  350. struct usb_cdc_notification *event;
  351. if (urb->actual_length < sizeof(*event))
  352. return;
  353. /* SPEED_CHANGE can get split into two 8-byte packets */
  354. if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) {
  355. dumpspeed(dev, (__le32 *) urb->transfer_buffer);
  356. return;
  357. }
  358. event = urb->transfer_buffer;
  359. switch (event->bNotificationType) {
  360. case USB_CDC_NOTIFY_NETWORK_CONNECTION:
  361. netif_dbg(dev, timer, dev->net, "CDC: carrier %s\n",
  362. event->wValue ? "on" : "off");
  363. usbnet_link_change(dev, !!event->wValue, 0);
  364. break;
  365. case USB_CDC_NOTIFY_SPEED_CHANGE: /* tx/rx rates */
  366. netif_dbg(dev, timer, dev->net, "CDC: speed change (len %d)\n",
  367. urb->actual_length);
  368. if (urb->actual_length != (sizeof(*event) + 8))
  369. set_bit(EVENT_STS_SPLIT, &dev->flags);
  370. else
  371. dumpspeed(dev, (__le32 *) &event[1]);
  372. break;
  373. /* USB_CDC_NOTIFY_RESPONSE_AVAILABLE can happen too (e.g. RNDIS),
  374. * but there are no standard formats for the response data.
  375. */
  376. default:
  377. netdev_err(dev->net, "CDC: unexpected notification %02x!\n",
  378. event->bNotificationType);
  379. break;
  380. }
  381. }
  382. EXPORT_SYMBOL_GPL(usbnet_cdc_status);
  383. int usbnet_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
  384. {
  385. int status;
  386. struct cdc_state *info = (void *) &dev->data;
  387. BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data)
  388. < sizeof(struct cdc_state)));
  389. status = usbnet_ether_cdc_bind(dev, intf);
  390. if (status < 0)
  391. return status;
  392. status = usbnet_get_ethernet_addr(dev, info->ether->iMACAddress);
  393. if (status < 0) {
  394. usb_set_intfdata(info->data, NULL);
  395. usb_driver_release_interface(driver_of(intf), info->data);
  396. return status;
  397. }
  398. return 0;
  399. }
  400. EXPORT_SYMBOL_GPL(usbnet_cdc_bind);
  401. static int usbnet_cdc_zte_bind(struct usbnet *dev, struct usb_interface *intf)
  402. {
  403. int status = usbnet_cdc_bind(dev, intf);
  404. if (!status && (dev->net->dev_addr[0] & 0x02))
  405. eth_hw_addr_random(dev->net);
  406. return status;
  407. }
  408. /* Make sure packets have correct destination MAC address
  409. *
  410. * A firmware bug observed on some devices (ZTE MF823/831/910) is that the
  411. * device sends packets with a static, bogus, random MAC address (event if
  412. * device MAC address has been updated). Always set MAC address to that of the
  413. * device.
  414. */
  415. static int usbnet_cdc_zte_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  416. {
  417. if (skb->len < ETH_HLEN || !(skb->data[0] & 0x02))
  418. return 1;
  419. skb_reset_mac_header(skb);
  420. ether_addr_copy(eth_hdr(skb)->h_dest, dev->net->dev_addr);
  421. return 1;
  422. }
  423. /* Ensure correct link state
  424. *
  425. * Some devices (ZTE MF823/831/910) export two carrier on notifications when
  426. * connected. This causes the link state to be incorrect. Work around this by
  427. * always setting the state to off, then on.
  428. */
  429. static void usbnet_cdc_zte_status(struct usbnet *dev, struct urb *urb)
  430. {
  431. struct usb_cdc_notification *event;
  432. if (urb->actual_length < sizeof(*event))
  433. return;
  434. event = urb->transfer_buffer;
  435. if (event->bNotificationType != USB_CDC_NOTIFY_NETWORK_CONNECTION) {
  436. usbnet_cdc_status(dev, urb);
  437. return;
  438. }
  439. netif_dbg(dev, timer, dev->net, "CDC: carrier %s\n",
  440. event->wValue ? "on" : "off");
  441. if (event->wValue &&
  442. netif_carrier_ok(dev->net))
  443. netif_carrier_off(dev->net);
  444. usbnet_link_change(dev, !!event->wValue, 0);
  445. }
  446. static const struct driver_info cdc_info = {
  447. .description = "CDC Ethernet Device",
  448. .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
  449. .bind = usbnet_cdc_bind,
  450. .unbind = usbnet_cdc_unbind,
  451. .status = usbnet_cdc_status,
  452. .set_rx_mode = usbnet_cdc_update_filter,
  453. .manage_power = usbnet_manage_power,
  454. };
  455. static const struct driver_info zte_cdc_info = {
  456. .description = "ZTE CDC Ethernet Device",
  457. .flags = FLAG_ETHER | FLAG_POINTTOPOINT,
  458. .bind = usbnet_cdc_zte_bind,
  459. .unbind = usbnet_cdc_unbind,
  460. .status = usbnet_cdc_zte_status,
  461. .set_rx_mode = usbnet_cdc_update_filter,
  462. .manage_power = usbnet_manage_power,
  463. .rx_fixup = usbnet_cdc_zte_rx_fixup,
  464. };
  465. static const struct driver_info wwan_info = {
  466. .description = "Mobile Broadband Network Device",
  467. .flags = FLAG_WWAN,
  468. .bind = usbnet_cdc_bind,
  469. .unbind = usbnet_cdc_unbind,
  470. .status = usbnet_cdc_status,
  471. .set_rx_mode = usbnet_cdc_update_filter,
  472. .manage_power = usbnet_manage_power,
  473. };
  474. /*-------------------------------------------------------------------------*/
  475. #define HUAWEI_VENDOR_ID 0x12D1
  476. #define NOVATEL_VENDOR_ID 0x1410
  477. #define ZTE_VENDOR_ID 0x19D2
  478. #define DELL_VENDOR_ID 0x413C
  479. #define REALTEK_VENDOR_ID 0x0bda
  480. #define SAMSUNG_VENDOR_ID 0x04e8
  481. #define LENOVO_VENDOR_ID 0x17ef
  482. #define LINKSYS_VENDOR_ID 0x13b1
  483. #define NVIDIA_VENDOR_ID 0x0955
  484. #define HP_VENDOR_ID 0x03f0
  485. #define MICROSOFT_VENDOR_ID 0x045e
  486. #define UBLOX_VENDOR_ID 0x1546
  487. #define TPLINK_VENDOR_ID 0x2357
  488. static const struct usb_device_id products[] = {
  489. /* BLACKLIST !!
  490. *
  491. * First blacklist any products that are egregiously nonconformant
  492. * with the CDC Ethernet specs. Minor braindamage we cope with; when
  493. * they're not even trying, needing a separate driver is only the first
  494. * of the differences to show up.
  495. */
  496. #define ZAURUS_MASTER_INTERFACE \
  497. .bInterfaceClass = USB_CLASS_COMM, \
  498. .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
  499. .bInterfaceProtocol = USB_CDC_PROTO_NONE
  500. /* SA-1100 based Sharp Zaurus ("collie"), or compatible;
  501. * wire-incompatible with true CDC Ethernet implementations.
  502. * (And, it seems, needlessly so...)
  503. */
  504. {
  505. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  506. | USB_DEVICE_ID_MATCH_DEVICE,
  507. .idVendor = 0x04DD,
  508. .idProduct = 0x8004,
  509. ZAURUS_MASTER_INTERFACE,
  510. .driver_info = 0,
  511. },
  512. /* PXA-25x based Sharp Zaurii. Note that it seems some of these
  513. * (later models especially) may have shipped only with firmware
  514. * advertising false "CDC MDLM" compatibility ... but we're not
  515. * clear which models did that, so for now let's assume the worst.
  516. */
  517. {
  518. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  519. | USB_DEVICE_ID_MATCH_DEVICE,
  520. .idVendor = 0x04DD,
  521. .idProduct = 0x8005, /* A-300 */
  522. ZAURUS_MASTER_INTERFACE,
  523. .driver_info = 0,
  524. }, {
  525. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  526. | USB_DEVICE_ID_MATCH_DEVICE,
  527. .idVendor = 0x04DD,
  528. .idProduct = 0x8006, /* B-500/SL-5600 */
  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 = 0x8007, /* C-700 */
  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 = 0x9031, /* C-750 C-760 */
  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 = 0x9032, /* SL-6000 */
  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. /* reported with some C860 units */
  557. .idProduct = 0x9050, /* C-860 */
  558. ZAURUS_MASTER_INTERFACE,
  559. .driver_info = 0,
  560. },
  561. /* Olympus has some models with a Zaurus-compatible option.
  562. * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
  563. */
  564. {
  565. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  566. | USB_DEVICE_ID_MATCH_DEVICE,
  567. .idVendor = 0x07B4,
  568. .idProduct = 0x0F02, /* R-1000 */
  569. ZAURUS_MASTER_INTERFACE,
  570. .driver_info = 0,
  571. },
  572. /* LG Electronics VL600 wants additional headers on every frame */
  573. {
  574. USB_DEVICE_AND_INTERFACE_INFO(0x1004, 0x61aa, USB_CLASS_COMM,
  575. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  576. .driver_info = 0,
  577. },
  578. /* Logitech Harmony 900 - uses the pseudo-MDLM (BLAN) driver */
  579. {
  580. USB_DEVICE_AND_INTERFACE_INFO(0x046d, 0xc11f, USB_CLASS_COMM,
  581. USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
  582. .driver_info = 0,
  583. },
  584. /* Novatel USB551L and MC551 - handled by qmi_wwan */
  585. {
  586. USB_DEVICE_AND_INTERFACE_INFO(NOVATEL_VENDOR_ID, 0xB001, USB_CLASS_COMM,
  587. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  588. .driver_info = 0,
  589. },
  590. /* Novatel E362 - handled by qmi_wwan */
  591. {
  592. USB_DEVICE_AND_INTERFACE_INFO(NOVATEL_VENDOR_ID, 0x9010, 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, 0x8195, USB_CLASS_COMM,
  599. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  600. .driver_info = 0,
  601. },
  602. /* Dell Wireless 5800 (Novatel E362) - handled by qmi_wwan */
  603. {
  604. USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x8196, USB_CLASS_COMM,
  605. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  606. .driver_info = 0,
  607. },
  608. /* Dell Wireless 5804 (Novatel E371) - handled by qmi_wwan */
  609. {
  610. USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x819b, USB_CLASS_COMM,
  611. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  612. .driver_info = 0,
  613. },
  614. /* Novatel Expedite E371 - handled by qmi_wwan */
  615. {
  616. USB_DEVICE_AND_INTERFACE_INFO(NOVATEL_VENDOR_ID, 0x9011, USB_CLASS_COMM,
  617. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  618. .driver_info = 0,
  619. },
  620. /* HP lt2523 (Novatel E371) - handled by qmi_wwan */
  621. {
  622. USB_DEVICE_AND_INTERFACE_INFO(HP_VENDOR_ID, 0x421d, USB_CLASS_COMM,
  623. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  624. .driver_info = 0,
  625. },
  626. /* AnyDATA ADU960S - handled by qmi_wwan */
  627. {
  628. USB_DEVICE_AND_INTERFACE_INFO(0x16d5, 0x650a, USB_CLASS_COMM,
  629. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  630. .driver_info = 0,
  631. },
  632. /* Huawei E1820 - handled by qmi_wwan */
  633. {
  634. USB_DEVICE_INTERFACE_NUMBER(HUAWEI_VENDOR_ID, 0x14ac, 1),
  635. .driver_info = 0,
  636. },
  637. /* Realtek RTL8152 Based USB 2.0 Ethernet Adapters */
  638. {
  639. USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8152, USB_CLASS_COMM,
  640. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  641. .driver_info = 0,
  642. },
  643. /* Realtek RTL8153 Based USB 3.0 Ethernet Adapters */
  644. {
  645. USB_DEVICE_AND_INTERFACE_INFO(REALTEK_VENDOR_ID, 0x8153, USB_CLASS_COMM,
  646. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  647. .driver_info = 0,
  648. },
  649. /* Samsung USB Ethernet Adapters */
  650. {
  651. USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, 0xa101, USB_CLASS_COMM,
  652. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  653. .driver_info = 0,
  654. },
  655. #if IS_ENABLED(CONFIG_USB_RTL8152)
  656. /* Linksys USB3GIGV1 Ethernet Adapter */
  657. {
  658. USB_DEVICE_AND_INTERFACE_INFO(LINKSYS_VENDOR_ID, 0x0041, USB_CLASS_COMM,
  659. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  660. .driver_info = 0,
  661. },
  662. #endif
  663. /* ThinkPad USB-C Dock (based on Realtek RTL8153) */
  664. {
  665. USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x3062, USB_CLASS_COMM,
  666. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  667. .driver_info = 0,
  668. },
  669. /* ThinkPad Thunderbolt 3 Dock (based on Realtek RTL8153) */
  670. {
  671. USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x3069, USB_CLASS_COMM,
  672. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  673. .driver_info = 0,
  674. },
  675. /* Lenovo Thinkpad USB 3.0 Ethernet Adapters (based on Realtek RTL8153) */
  676. {
  677. USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x7205, USB_CLASS_COMM,
  678. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  679. .driver_info = 0,
  680. },
  681. /* Lenovo USB C to Ethernet Adapter (based on Realtek RTL8153) */
  682. {
  683. USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x720c, USB_CLASS_COMM,
  684. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  685. .driver_info = 0,
  686. },
  687. /* Lenovo USB-C Travel Hub (based on Realtek RTL8153) */
  688. {
  689. USB_DEVICE_AND_INTERFACE_INFO(LENOVO_VENDOR_ID, 0x7214, USB_CLASS_COMM,
  690. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  691. .driver_info = 0,
  692. },
  693. /* NVIDIA Tegra USB 3.0 Ethernet Adapters (based on Realtek RTL8153) */
  694. {
  695. USB_DEVICE_AND_INTERFACE_INFO(NVIDIA_VENDOR_ID, 0x09ff, USB_CLASS_COMM,
  696. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  697. .driver_info = 0,
  698. },
  699. /* Microsoft Surface 2 dock (based on Realtek RTL8152) */
  700. {
  701. USB_DEVICE_AND_INTERFACE_INFO(MICROSOFT_VENDOR_ID, 0x07ab, USB_CLASS_COMM,
  702. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  703. .driver_info = 0,
  704. },
  705. /* Microsoft Surface 3 dock (based on Realtek RTL8153) */
  706. {
  707. USB_DEVICE_AND_INTERFACE_INFO(MICROSOFT_VENDOR_ID, 0x07c6, USB_CLASS_COMM,
  708. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  709. .driver_info = 0,
  710. },
  711. /* TP-LINK UE300 USB 3.0 Ethernet Adapters (based on Realtek RTL8153) */
  712. {
  713. USB_DEVICE_AND_INTERFACE_INFO(TPLINK_VENDOR_ID, 0x0601, USB_CLASS_COMM,
  714. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  715. .driver_info = 0,
  716. },
  717. /* WHITELIST!!!
  718. *
  719. * CDC Ether uses two interfaces, not necessarily consecutive.
  720. * We match the main interface, ignoring the optional device
  721. * class so we could handle devices that aren't exclusively
  722. * CDC ether.
  723. *
  724. * NOTE: this match must come AFTER entries blacklisting devices
  725. * because of bugs/quirks in a given product (like Zaurus, above).
  726. */
  727. {
  728. /* ZTE (Vodafone) K3805-Z */
  729. USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1003, USB_CLASS_COMM,
  730. USB_CDC_SUBCLASS_ETHERNET,
  731. USB_CDC_PROTO_NONE),
  732. .driver_info = (unsigned long)&wwan_info,
  733. }, {
  734. /* ZTE (Vodafone) K3806-Z */
  735. USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1015, USB_CLASS_COMM,
  736. USB_CDC_SUBCLASS_ETHERNET,
  737. USB_CDC_PROTO_NONE),
  738. .driver_info = (unsigned long)&wwan_info,
  739. }, {
  740. /* ZTE (Vodafone) K4510-Z */
  741. USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1173, USB_CLASS_COMM,
  742. USB_CDC_SUBCLASS_ETHERNET,
  743. USB_CDC_PROTO_NONE),
  744. .driver_info = (unsigned long)&wwan_info,
  745. }, {
  746. /* ZTE (Vodafone) K3770-Z */
  747. USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1177, USB_CLASS_COMM,
  748. USB_CDC_SUBCLASS_ETHERNET,
  749. USB_CDC_PROTO_NONE),
  750. .driver_info = (unsigned long)&wwan_info,
  751. }, {
  752. /* ZTE (Vodafone) K3772-Z */
  753. USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1181, USB_CLASS_COMM,
  754. USB_CDC_SUBCLASS_ETHERNET,
  755. USB_CDC_PROTO_NONE),
  756. .driver_info = (unsigned long)&wwan_info,
  757. }, {
  758. /* Telit modules */
  759. USB_VENDOR_AND_INTERFACE_INFO(0x1bc7, USB_CLASS_COMM,
  760. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  761. .driver_info = (kernel_ulong_t) &wwan_info,
  762. }, {
  763. /* Dell DW5580 modules */
  764. USB_DEVICE_AND_INTERFACE_INFO(DELL_VENDOR_ID, 0x81ba, USB_CLASS_COMM,
  765. USB_CDC_SUBCLASS_ETHERNET, USB_CDC_PROTO_NONE),
  766. .driver_info = (kernel_ulong_t)&wwan_info,
  767. }, {
  768. /* Huawei ME906 and ME909 */
  769. USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, 0x15c1, USB_CLASS_COMM,
  770. USB_CDC_SUBCLASS_ETHERNET,
  771. USB_CDC_PROTO_NONE),
  772. .driver_info = (unsigned long)&wwan_info,
  773. }, {
  774. /* ZTE modules */
  775. USB_VENDOR_AND_INTERFACE_INFO(ZTE_VENDOR_ID, USB_CLASS_COMM,
  776. USB_CDC_SUBCLASS_ETHERNET,
  777. USB_CDC_PROTO_NONE),
  778. .driver_info = (unsigned long)&zte_cdc_info,
  779. }, {
  780. /* U-blox TOBY-L2 */
  781. USB_DEVICE_AND_INTERFACE_INFO(UBLOX_VENDOR_ID, 0x1143, USB_CLASS_COMM,
  782. USB_CDC_SUBCLASS_ETHERNET,
  783. USB_CDC_PROTO_NONE),
  784. .driver_info = (unsigned long)&wwan_info,
  785. }, {
  786. /* U-blox SARA-U2 */
  787. USB_DEVICE_AND_INTERFACE_INFO(UBLOX_VENDOR_ID, 0x1104, USB_CLASS_COMM,
  788. USB_CDC_SUBCLASS_ETHERNET,
  789. USB_CDC_PROTO_NONE),
  790. .driver_info = (unsigned long)&wwan_info,
  791. }, {
  792. USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ETHERNET,
  793. USB_CDC_PROTO_NONE),
  794. .driver_info = (unsigned long) &cdc_info,
  795. }, {
  796. USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
  797. USB_CDC_PROTO_NONE),
  798. .driver_info = (unsigned long)&wwan_info,
  799. }, {
  800. /* Various Huawei modems with a network port like the UMG1831 */
  801. USB_VENDOR_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, USB_CLASS_COMM,
  802. USB_CDC_SUBCLASS_ETHERNET, 255),
  803. .driver_info = (unsigned long)&wwan_info,
  804. },
  805. { }, /* END */
  806. };
  807. MODULE_DEVICE_TABLE(usb, products);
  808. static struct usb_driver cdc_driver = {
  809. .name = "cdc_ether",
  810. .id_table = products,
  811. .probe = usbnet_probe,
  812. .disconnect = usbnet_disconnect,
  813. .suspend = usbnet_suspend,
  814. .resume = usbnet_resume,
  815. .reset_resume = usbnet_resume,
  816. .supports_autosuspend = 1,
  817. .disable_hub_initiated_lpm = 1,
  818. };
  819. module_usb_driver(cdc_driver);
  820. MODULE_AUTHOR("David Brownell");
  821. MODULE_DESCRIPTION("USB CDC Ethernet devices");
  822. MODULE_LICENSE("GPL");