Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: ethernet gadget interop with MCCI Windows driver

It turns out that minor tweaks to the "CDC Subset" support in the Ethernet
gadget driver, just updating a config descriptor, let it be automagically
recognized by a Windows driver supported by MCCI.

This patch adds those descriptors, so systems using PXA 255 processors
(like Gumstix etc) can interop with those commercial MS-Windows drivers.
This is a Good Thing since Microsoft's RNDIS code has bugginess issues,
which are unfortunately compounded by "won't fix" issues as well as "the
published specs are incomplete and wrong" issues. Being able to talk to
the MCCI driver gives Windows users another connectivity option. (MCCI
also has CDC Ethernet drivers, which can help most non-PXA processors.)

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

David Brownell and committed by
Greg Kroah-Hartman
11d54898 1737bf2c

+103 -39
+103 -39
drivers/usb/gadget/ether.c
··· 72 72 * 73 73 * There's some hardware that can't talk CDC. We make that hardware 74 74 * implement a "minimalist" vendor-agnostic CDC core: same framing, but 75 - * link-level setup only requires activating the configuration. 76 - * Linux supports it, but other host operating systems may not. 77 - * (This is a subset of CDC Ethernet.) 75 + * link-level setup only requires activating the configuration. Only the 76 + * endpoint descriptors, and product/vendor IDs, are relevant; no control 77 + * operations are available. Linux supports it, but other host operating 78 + * systems may not. (This is a subset of CDC Ethernet.) 79 + * 80 + * It turns out that if you add a few descriptors to that "CDC Subset", 81 + * (Windows) host side drivers from MCCI can treat it as one submode of 82 + * a proprietary scheme called "SAFE" ... without needing to know about 83 + * specific product/vendor IDs. So we do that, making it easier to use 84 + * those MS-Windows drivers. Those added descriptors make it resemble a 85 + * CDC MDLM device, but they don't change device behavior at all. (See 86 + * MCCI Engineering report 950198 "SAFE Networking Functions".) 78 87 * 79 88 * A third option is also in use. Rather than CDC Ethernet, or something 80 89 * simpler, Microsoft pushes their own approach: RNDIS. The published ··· 263 254 #define DEV_CONFIG_CDC 264 255 #endif 265 256 257 + #ifdef CONFIG_USB_GADGET_S3C2410 258 + #define DEV_CONFIG_CDC 259 + #endif 260 + 266 261 #ifdef CONFIG_USB_GADGET_AT91 267 262 #define DEV_CONFIG_CDC 268 263 #endif ··· 296 283 #define DEV_CONFIG_SUBSET 297 284 #endif 298 285 299 - #ifdef CONFIG_USB_GADGET_S3C2410 300 - #define DEV_CONFIG_CDC 301 - #endif 302 286 303 287 /*-------------------------------------------------------------------------*/ 304 288 ··· 497 487 * endpoint. Both have a "data" interface and two bulk endpoints. 498 488 * There are also differences in how control requests are handled. 499 489 * 500 - * RNDIS shares a lot with CDC-Ethernet, since it's a variant of 501 - * the CDC-ACM (modem) spec. 490 + * RNDIS shares a lot with CDC-Ethernet, since it's a variant of the 491 + * CDC-ACM (modem) spec. Unfortunately MSFT's RNDIS driver is buggy; it 492 + * may hang or oops. Since bugfixes (or accurate specs, letting Linux 493 + * work around those bugs) are unlikely to ever come from MSFT, you may 494 + * wish to avoid using RNDIS. 495 + * 496 + * MCCI offers an alternative to RNDIS if you need to connect to Windows 497 + * but have hardware that can't support CDC Ethernet. We add descriptors 498 + * to present the CDC Subset as a (nonconformant) CDC MDLM variant called 499 + * "SAFE". That borrows from both CDC Ethernet and CDC MDLM. You can 500 + * get those drivers from MCCI, or bundled with various products. 502 501 */ 503 502 504 503 #ifdef DEV_CONFIG_CDC ··· 541 522 }; 542 523 #endif 543 524 544 - #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 545 - 546 525 static const struct usb_cdc_header_desc header_desc = { 547 526 .bLength = sizeof header_desc, 548 527 .bDescriptorType = USB_DT_CS_INTERFACE, ··· 548 531 549 532 .bcdCDC = __constant_cpu_to_le16 (0x0110), 550 533 }; 534 + 535 + #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 551 536 552 537 static const struct usb_cdc_union_desc union_desc = { 553 538 .bLength = sizeof union_desc, ··· 583 564 584 565 #endif 585 566 586 - #ifdef DEV_CONFIG_CDC 567 + #ifndef DEV_CONFIG_CDC 568 + 569 + /* "SAFE" loosely follows CDC WMC MDLM, violating the spec in various 570 + * ways: data endpoints live in the control interface, there's no data 571 + * interface, and it's not used to talk to a cell phone radio. 572 + */ 573 + 574 + static const struct usb_cdc_mdlm_desc mdlm_desc = { 575 + .bLength = sizeof mdlm_desc, 576 + .bDescriptorType = USB_DT_CS_INTERFACE, 577 + .bDescriptorSubType = USB_CDC_MDLM_TYPE, 578 + 579 + .bcdVersion = __constant_cpu_to_le16(0x0100), 580 + .bGUID = { 581 + 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6, 582 + 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f, 583 + }, 584 + }; 585 + 586 + /* since "usb_cdc_mdlm_detail_desc" is a variable length structure, we 587 + * can't really use its struct. All we do here is say that we're using 588 + * the submode of "SAFE" which directly matches the CDC Subset. 589 + */ 590 + static const u8 mdlm_detail_desc[] = { 591 + 6, 592 + USB_DT_CS_INTERFACE, 593 + USB_CDC_MDLM_DETAIL_TYPE, 594 + 595 + 0, /* "SAFE" */ 596 + 0, /* network control capabilities (none) */ 597 + 0, /* network data capabilities ("raw" encapsulation) */ 598 + }; 599 + 600 + #endif 587 601 588 602 static const struct usb_cdc_ether_desc ether_desc = { 589 603 .bLength = sizeof ether_desc, ··· 631 579 .bNumberPowerFilters = 0, 632 580 }; 633 581 634 - #endif 635 582 636 583 #if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 637 584 ··· 723 672 /* 724 673 * "Simple" CDC-subset option is a simple vendor-neutral model that most 725 674 * full speed controllers can handle: one interface, two bulk endpoints. 675 + * 676 + * To assist host side drivers, we fancy it up a bit, and add descriptors 677 + * so some host side drivers will understand it as a "SAFE" variant. 726 678 */ 727 679 728 680 static const struct usb_interface_descriptor ··· 736 682 .bInterfaceNumber = 0, 737 683 .bAlternateSetting = 0, 738 684 .bNumEndpoints = 2, 739 - .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 740 - .bInterfaceSubClass = 0, 685 + .bInterfaceClass = USB_CLASS_COMM, 686 + .bInterfaceSubClass = USB_CDC_SUBCLASS_MDLM, 741 687 .bInterfaceProtocol = 0, 742 688 .iInterface = STRING_DATA, 743 689 }; ··· 785 731 static inline void __init fs_subset_descriptors(void) 786 732 { 787 733 #ifdef DEV_CONFIG_SUBSET 734 + /* behavior is "CDC Subset"; extra descriptors say "SAFE" */ 788 735 fs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf; 789 - fs_eth_function[2] = (struct usb_descriptor_header *) &fs_source_desc; 790 - fs_eth_function[3] = (struct usb_descriptor_header *) &fs_sink_desc; 791 - fs_eth_function[4] = NULL; 736 + fs_eth_function[2] = (struct usb_descriptor_header *) &header_desc; 737 + fs_eth_function[3] = (struct usb_descriptor_header *) &mdlm_desc; 738 + fs_eth_function[4] = (struct usb_descriptor_header *) &mdlm_detail_desc; 739 + fs_eth_function[5] = (struct usb_descriptor_header *) &ether_desc; 740 + fs_eth_function[6] = (struct usb_descriptor_header *) &fs_source_desc; 741 + fs_eth_function[7] = (struct usb_descriptor_header *) &fs_sink_desc; 742 + fs_eth_function[8] = NULL; 792 743 #else 793 744 fs_eth_function[1] = NULL; 794 745 #endif ··· 887 828 static inline void __init hs_subset_descriptors(void) 888 829 { 889 830 #ifdef DEV_CONFIG_SUBSET 831 + /* behavior is "CDC Subset"; extra descriptors say "SAFE" */ 890 832 hs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf; 891 - hs_eth_function[2] = (struct usb_descriptor_header *) &fs_source_desc; 892 - hs_eth_function[3] = (struct usb_descriptor_header *) &fs_sink_desc; 893 - hs_eth_function[4] = NULL; 833 + hs_eth_function[2] = (struct usb_descriptor_header *) &header_desc; 834 + hs_eth_function[3] = (struct usb_descriptor_header *) &mdlm_desc; 835 + hs_eth_function[4] = (struct usb_descriptor_header *) &mdlm_detail_desc; 836 + hs_eth_function[5] = (struct usb_descriptor_header *) &ether_desc; 837 + hs_eth_function[6] = (struct usb_descriptor_header *) &hs_source_desc; 838 + hs_eth_function[7] = (struct usb_descriptor_header *) &hs_sink_desc; 839 + hs_eth_function[8] = NULL; 894 840 #else 895 841 hs_eth_function[1] = NULL; 896 842 #endif ··· 942 878 static char product_desc [40] = DRIVER_DESC; 943 879 static char serial_number [20]; 944 880 945 - #ifdef DEV_CONFIG_CDC 946 881 /* address that the host will use ... usually assigned at random */ 947 882 static char ethaddr [2 * ETH_ALEN + 1]; 948 - #endif 949 883 950 884 /* static strings, in UTF-8 */ 951 885 static struct usb_string strings [] = { ··· 951 889 { STRING_PRODUCT, product_desc, }, 952 890 { STRING_SERIALNUMBER, serial_number, }, 953 891 { STRING_DATA, "Ethernet Data", }, 892 + { STRING_ETHADDR, ethaddr, }, 954 893 #ifdef DEV_CONFIG_CDC 955 894 { STRING_CDC, "CDC Ethernet", }, 956 - { STRING_ETHADDR, ethaddr, }, 957 895 { STRING_CONTROL, "CDC Communications Control", }, 958 896 #endif 959 897 #ifdef DEV_CONFIG_SUBSET ··· 1048 986 } 1049 987 #endif 1050 988 1051 - dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); 989 + dev->in = ep_desc(gadget, &hs_source_desc, &fs_source_desc); 1052 990 dev->in_ep->driver_data = dev; 1053 991 1054 - dev->out = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc); 992 + dev->out = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc); 1055 993 dev->out_ep->driver_data = dev; 1056 994 1057 995 /* With CDC, the host isn't allowed to use these two data ··· 2340 2278 "RNDIS/%s", driver_desc); 2341 2279 2342 2280 /* CDC subset ... recognized by Linux since 2.4.10, but Windows 2343 - * drivers aren't widely available. 2281 + * drivers aren't widely available. (That may be improved by 2282 + * supporting one submode of the "SAFE" variant of MDLM.) 2344 2283 */ 2345 2284 } else if (!cdc) { 2346 - device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC; 2347 2285 device_desc.idVendor = 2348 2286 __constant_cpu_to_le16(SIMPLE_VENDOR_NUM); 2349 2287 device_desc.idProduct = ··· 2414 2352 if (!cdc) { 2415 2353 eth_config.bNumInterfaces = 1; 2416 2354 eth_config.iConfiguration = STRING_SUBSET; 2355 + 2356 + /* use functions to set these up, in case we're built to work 2357 + * with multiple controllers and must override CDC Ethernet. 2358 + */ 2417 2359 fs_subset_descriptors(); 2418 2360 hs_subset_descriptors(); 2419 2361 } ··· 2481 2415 2482 2416 /* Module params for these addresses should come from ID proms. 2483 2417 * The host side address is used with CDC and RNDIS, and commonly 2484 - * ends up in a persistent config database. 2418 + * ends up in a persistent config database. It's not clear if 2419 + * host side code for the SAFE thing cares -- its original BLAN 2420 + * thing didn't, Sharp never assigned those addresses on Zaurii. 2485 2421 */ 2486 2422 if (get_ether_addr(dev_addr, net->dev_addr)) 2487 2423 dev_warn(&gadget->dev, 2488 2424 "using random %s ethernet address\n", "self"); 2489 - if (cdc || rndis) { 2490 - if (get_ether_addr(host_addr, dev->host_mac)) 2491 - dev_warn(&gadget->dev, 2492 - "using random %s ethernet address\n", "host"); 2493 - #ifdef DEV_CONFIG_CDC 2494 - snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X", 2495 - dev->host_mac [0], dev->host_mac [1], 2496 - dev->host_mac [2], dev->host_mac [3], 2497 - dev->host_mac [4], dev->host_mac [5]); 2498 - #endif 2499 - } 2425 + if (get_ether_addr(host_addr, dev->host_mac)) 2426 + dev_warn(&gadget->dev, 2427 + "using random %s ethernet address\n", "host"); 2428 + snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X", 2429 + dev->host_mac [0], dev->host_mac [1], 2430 + dev->host_mac [2], dev->host_mac [3], 2431 + dev->host_mac [4], dev->host_mac [5]); 2500 2432 2501 2433 if (rndis) { 2502 2434 status = rndis_init();