gadget_multi.rst 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. ==============================
  2. Multifunction Composite Gadget
  3. ==============================
  4. Overview
  5. ========
  6. The Multifunction Composite Gadget (or g_multi) is a composite gadget
  7. that makes extensive use of the composite framework to provide
  8. a... multifunction gadget.
  9. In its standard configuration it provides a single USB configuration
  10. with RNDIS[1] (that is Ethernet), USB CDC[2] ACM (that is serial) and
  11. USB Mass Storage functions.
  12. A CDC ECM (Ethernet) function may be turned on via a Kconfig option
  13. and RNDIS can be turned off. If they are both enabled the gadget will
  14. have two configurations -- one with RNDIS and another with CDC ECM[3].
  15. Please note that if you use non-standard configuration (that is enable
  16. CDC ECM) you may need to change vendor and/or product ID.
  17. Host drivers
  18. ============
  19. To make use of the gadget one needs to make it work on host side --
  20. without that there's no hope of achieving anything with the gadget.
  21. As one might expect, things one need to do very from system to system.
  22. Linux host drivers
  23. ------------------
  24. Since the gadget uses standard composite framework and appears as such
  25. to Linux host it does not need any additional drivers on Linux host
  26. side. All the functions are handled by respective drivers developed
  27. for them.
  28. This is also true for two configuration set-up with RNDIS
  29. configuration being the first one. Linux host will use the second
  30. configuration with CDC ECM which should work better under Linux.
  31. Windows host drivers
  32. --------------------
  33. For the gadget to work under Windows two conditions have to be met:
  34. Detecting as composite gadget
  35. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  36. First of all, Windows need to detect the gadget as an USB composite
  37. gadget which on its own have some conditions[4]. If they are met,
  38. Windows lets USB Generic Parent Driver[5] handle the device which then
  39. tries to match drivers for each individual interface (sort of, don't
  40. get into too many details).
  41. The good news is: you do not have to worry about most of the
  42. conditions!
  43. The only thing to worry is that the gadget has to have a single
  44. configuration so a dual RNDIS and CDC ECM gadget won't work unless you
  45. create a proper INF -- and of course, if you do submit it!
  46. Installing drivers for each function
  47. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  48. The other, trickier thing is making Windows install drivers for each
  49. individual function.
  50. For mass storage it is trivial since Windows detect it's an interface
  51. implementing USB Mass Storage class and selects appropriate driver.
  52. Things are harder with RDNIS and CDC ACM.
  53. RNDIS
  54. .....
  55. To make Windows select RNDIS drivers for the first function in the
  56. gadget, one needs to use the [[file:linux.inf]] file provided with this
  57. document. It "attaches" Window's RNDIS driver to the first interface
  58. of the gadget.
  59. Please note, that while testing we encountered some issues[6] when
  60. RNDIS was not the first interface. You do not need to worry abut it
  61. unless you are trying to develop your own gadget in which case watch
  62. out for this bug.
  63. CDC ACM
  64. .......
  65. Similarly, [[file:linux-cdc-acm.inf]] is provided for CDC ACM.
  66. Customising the gadget
  67. ......................
  68. If you intend to hack the g_multi gadget be advised that rearranging
  69. functions will obviously change interface numbers for each of the
  70. functionality. As an effect provided INFs won't work since they have
  71. interface numbers hard-coded in them (it's not hard to change those
  72. though[7]).
  73. This also means, that after experimenting with g_multi and changing
  74. provided functions one should change gadget's vendor and/or product ID
  75. so there will be no collision with other customised gadgets or the
  76. original gadget.
  77. Failing to comply may cause brain damage after wondering for hours why
  78. things don't work as intended before realising Windows have cached
  79. some drivers information (changing USB port may sometimes help plus
  80. you might try using USBDeview[8] to remove the phantom device).
  81. INF testing
  82. ...........
  83. Provided INF files have been tested on Windows XP SP3, Windows Vista
  84. and Windows 7, all 32-bit versions. It should work on 64-bit versions
  85. as well. It most likely won't work on Windows prior to Windows XP
  86. SP2.
  87. Other systems
  88. -------------
  89. At this moment, drivers for any other systems have not been tested.
  90. Knowing how MacOS is based on BSD and BSD is an Open Source it is
  91. believed that it should (read: "I have no idea whether it will") work
  92. out-of-the-box.
  93. For more exotic systems I have even less to say...
  94. Any testing and drivers *are* *welcome*!
  95. Authors
  96. =======
  97. This document has been written by Michal Nazarewicz
  98. ([[mailto:mina86@mina86.com]]). INF files have been hacked with
  99. support of Marek Szyprowski ([[mailto:m.szyprowski@samsung.com]]) and
  100. Xiaofan Chen ([[mailto:xiaofanc@gmail.com]]) basing on the MS RNDIS
  101. template[9], Microchip's CDC ACM INF file and David Brownell's
  102. ([[mailto:dbrownell@users.sourceforge.net]]) original INF files.
  103. Footnotes
  104. =========
  105. [1] Remote Network Driver Interface Specification,
  106. [[https://msdn.microsoft.com/en-us/library/ee484414.aspx]].
  107. [2] Communications Device Class Abstract Control Model, spec for this
  108. and other USB classes can be found at
  109. [[http://www.usb.org/developers/devclass_docs/]].
  110. [3] CDC Ethernet Control Model.
  111. [4] [[https://msdn.microsoft.com/en-us/library/ff537109(v=VS.85).aspx]]
  112. [5] [[https://msdn.microsoft.com/en-us/library/ff539234(v=VS.85).aspx]]
  113. [6] To put it in some other nice words, Windows failed to respond to
  114. any user input.
  115. [7] You may find [[http://www.cygnal.org/ubb/Forum9/HTML/001050.html]]
  116. useful.
  117. [8] https://www.nirsoft.net/utils/usb_devices_view.html
  118. [9] [[https://msdn.microsoft.com/en-us/library/ff570620.aspx]]