functionfs.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #ifndef __LINUX_FUNCTIONFS_H__
  2. #define __LINUX_FUNCTIONFS_H__
  3. #include <linux/types.h>
  4. #include <linux/ioctl.h>
  5. #include <linux/usb/ch9.h>
  6. enum {
  7. FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
  8. FUNCTIONFS_STRINGS_MAGIC = 2,
  9. FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
  10. };
  11. enum functionfs_flags {
  12. FUNCTIONFS_HAS_FS_DESC = 1,
  13. FUNCTIONFS_HAS_HS_DESC = 2,
  14. FUNCTIONFS_HAS_SS_DESC = 4,
  15. FUNCTIONFS_HAS_MS_OS_DESC = 8,
  16. FUNCTIONFS_VIRTUAL_ADDR = 16,
  17. FUNCTIONFS_EVENTFD = 32,
  18. };
  19. /* Descriptor of an non-audio endpoint */
  20. struct usb_endpoint_descriptor_no_audio {
  21. __u8 bLength;
  22. __u8 bDescriptorType;
  23. __u8 bEndpointAddress;
  24. __u8 bmAttributes;
  25. __le16 wMaxPacketSize;
  26. __u8 bInterval;
  27. } __attribute__((packed));
  28. struct usb_functionfs_descs_head_v2 {
  29. __le32 magic;
  30. __le32 length;
  31. __le32 flags;
  32. /*
  33. * __le32 fs_count, hs_count, fs_count; must be included manually in
  34. * the structure taking flags into consideration.
  35. */
  36. } __attribute__((packed));
  37. /* Legacy format, deprecated as of 3.14. */
  38. struct usb_functionfs_descs_head {
  39. __le32 magic;
  40. __le32 length;
  41. __le32 fs_count;
  42. __le32 hs_count;
  43. } __attribute__((packed, deprecated));
  44. /* MS OS Descriptor header */
  45. struct usb_os_desc_header {
  46. __u8 interface;
  47. __le32 dwLength;
  48. __le16 bcdVersion;
  49. __le16 wIndex;
  50. union {
  51. struct {
  52. __u8 bCount;
  53. __u8 Reserved;
  54. };
  55. __le16 wCount;
  56. };
  57. } __attribute__((packed));
  58. struct usb_ext_compat_desc {
  59. __u8 bFirstInterfaceNumber;
  60. __u8 Reserved1;
  61. __u8 CompatibleID[8];
  62. __u8 SubCompatibleID[8];
  63. __u8 Reserved2[6];
  64. };
  65. struct usb_ext_prop_desc {
  66. __le32 dwSize;
  67. __le32 dwPropertyDataType;
  68. __le16 wPropertyNameLength;
  69. } __attribute__((packed));
  70. /*
  71. * Descriptors format:
  72. *
  73. * | off | name | type | description |
  74. * |-----+-----------+--------------+--------------------------------------|
  75. * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 |
  76. * | 4 | length | LE32 | length of the whole data chunk |
  77. * | 8 | flags | LE32 | combination of functionfs_flags |
  78. * | | fs_count | LE32 | number of full-speed descriptors |
  79. * | | hs_count | LE32 | number of high-speed descriptors |
  80. * | | ss_count | LE32 | number of super-speed descriptors |
  81. * | | os_count | LE32 | number of MS OS descriptors |
  82. * | | fs_descrs | Descriptor[] | list of full-speed descriptors |
  83. * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
  84. * | | ss_descrs | Descriptor[] | list of super-speed descriptors |
  85. * | | os_descrs | OSDesc[] | list of MS OS descriptors |
  86. *
  87. * Depending on which flags are set, various fields may be missing in the
  88. * structure. Any flags that are not recognised cause the whole block to be
  89. * rejected with -ENOSYS.
  90. *
  91. * Legacy descriptors format (deprecated as of 3.14):
  92. *
  93. * | off | name | type | description |
  94. * |-----+-----------+--------------+--------------------------------------|
  95. * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC |
  96. * | 4 | length | LE32 | length of the whole data chunk |
  97. * | 8 | fs_count | LE32 | number of full-speed descriptors |
  98. * | 12 | hs_count | LE32 | number of high-speed descriptors |
  99. * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
  100. * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
  101. *
  102. * All numbers must be in little endian order.
  103. *
  104. * Descriptor[] is an array of valid USB descriptors which have the following
  105. * format:
  106. *
  107. * | off | name | type | description |
  108. * |-----+-----------------+------+--------------------------|
  109. * | 0 | bLength | U8 | length of the descriptor |
  110. * | 1 | bDescriptorType | U8 | descriptor type |
  111. * | 2 | payload | | descriptor's payload |
  112. *
  113. * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
  114. * the following formats:
  115. *
  116. * | off | name | type | description |
  117. * |-----+-----------------+------+--------------------------|
  118. * | 0 | inteface | U8 | related interface number |
  119. * | 1 | dwLength | U32 | length of the descriptor |
  120. * | 5 | bcdVersion | U16 | currently supported: 1 |
  121. * | 7 | wIndex | U16 | currently supported: 4 |
  122. * | 9 | bCount | U8 | number of ext. compat. |
  123. * | 10 | Reserved | U8 | 0 |
  124. * | 11 | ExtCompat[] | | list of ext. compat. d. |
  125. *
  126. * | off | name | type | description |
  127. * |-----+-----------------+------+--------------------------|
  128. * | 0 | inteface | U8 | related interface number |
  129. * | 1 | dwLength | U32 | length of the descriptor |
  130. * | 5 | bcdVersion | U16 | currently supported: 1 |
  131. * | 7 | wIndex | U16 | currently supported: 5 |
  132. * | 9 | wCount | U16 | number of ext. compat. |
  133. * | 11 | ExtProp[] | | list of ext. prop. d. |
  134. *
  135. * ExtCompat[] is an array of valid Extended Compatiblity descriptors
  136. * which have the following format:
  137. *
  138. * | off | name | type | description |
  139. * |-----+-----------------------+------+-------------------------------------|
  140. * | 0 | bFirstInterfaceNumber | U8 | index of the interface or of the 1st|
  141. * | | | | interface in an IAD group |
  142. * | 1 | Reserved | U8 | 0 |
  143. * | 2 | CompatibleID | U8[8]| compatible ID string |
  144. * | 10 | SubCompatibleID | U8[8]| subcompatible ID string |
  145. * | 18 | Reserved | U8[6]| 0 |
  146. *
  147. * ExtProp[] is an array of valid Extended Properties descriptors
  148. * which have the following format:
  149. *
  150. * | off | name | type | description |
  151. * |-----+-----------------------+------+-------------------------------------|
  152. * | 0 | dwSize | U32 | length of the descriptor |
  153. * | 4 | dwPropertyDataType | U32 | 1..7 |
  154. * | 8 | wPropertyNameLength | U16 | bPropertyName length (NL) |
  155. * | 10 | bPropertyName |U8[NL]| name of this property |
  156. * |10+NL| dwPropertyDataLength | U32 | bPropertyData length (DL) |
  157. * |14+NL| bProperty |U8[DL]| payload of this property |
  158. */
  159. struct usb_functionfs_strings_head {
  160. __le32 magic;
  161. __le32 length;
  162. __le32 str_count;
  163. __le32 lang_count;
  164. } __attribute__((packed));
  165. /*
  166. * Strings format:
  167. *
  168. * | off | name | type | description |
  169. * |-----+------------+-----------------------+----------------------------|
  170. * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC |
  171. * | 4 | length | LE32 | length of the data chunk |
  172. * | 8 | str_count | LE32 | number of strings |
  173. * | 12 | lang_count | LE32 | number of languages |
  174. * | 16 | stringtab | StringTab[lang_count] | table of strings per lang |
  175. *
  176. * For each language there is one stringtab entry (ie. there are lang_count
  177. * stringtab entires). Each StringTab has following format:
  178. *
  179. * | off | name | type | description |
  180. * |-----+---------+-------------------+------------------------------------|
  181. * | 0 | lang | LE16 | language code |
  182. * | 2 | strings | String[str_count] | array of strings in given language |
  183. *
  184. * For each string there is one strings entry (ie. there are str_count
  185. * string entries). Each String is a NUL terminated string encoded in
  186. * UTF-8.
  187. */
  188. /*
  189. * Events are delivered on the ep0 file descriptor, when the user mode driver
  190. * reads from this file descriptor after writing the descriptors. Don't
  191. * stop polling this descriptor.
  192. */
  193. enum usb_functionfs_event_type {
  194. FUNCTIONFS_BIND,
  195. FUNCTIONFS_UNBIND,
  196. FUNCTIONFS_ENABLE,
  197. FUNCTIONFS_DISABLE,
  198. FUNCTIONFS_SETUP,
  199. FUNCTIONFS_SUSPEND,
  200. FUNCTIONFS_RESUME
  201. };
  202. /* NOTE: this structure must stay the same size and layout on
  203. * both 32-bit and 64-bit kernels.
  204. */
  205. struct usb_functionfs_event {
  206. union {
  207. /* SETUP: packet; DATA phase i/o precedes next event
  208. *(setup.bmRequestType & USB_DIR_IN) flags direction */
  209. struct usb_ctrlrequest setup;
  210. } __attribute__((packed)) u;
  211. /* enum usb_functionfs_event_type */
  212. __u8 type;
  213. __u8 _pad[3];
  214. } __attribute__((packed));
  215. /* Endpoint ioctls */
  216. /* The same as in gadgetfs */
  217. /* IN transfers may be reported to the gadget driver as complete
  218. * when the fifo is loaded, before the host reads the data;
  219. * OUT transfers may be reported to the host's "client" driver as
  220. * complete when they're sitting in the FIFO unread.
  221. * THIS returns how many bytes are "unclaimed" in the endpoint fifo
  222. * (needed for precise fault handling, when the hardware allows it)
  223. */
  224. #define FUNCTIONFS_FIFO_STATUS _IO('g', 1)
  225. /* discards any unclaimed data in the fifo. */
  226. #define FUNCTIONFS_FIFO_FLUSH _IO('g', 2)
  227. /* resets endpoint halt+toggle; used to implement set_interface.
  228. * some hardware (like pxa2xx) can't support this.
  229. */
  230. #define FUNCTIONFS_CLEAR_HALT _IO('g', 3)
  231. /* Specific for functionfs */
  232. /*
  233. * Returns reverse mapping of an interface. Called on EP0. If there
  234. * is no such interface returns -EDOM. If function is not active
  235. * returns -ENODEV.
  236. */
  237. #define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128)
  238. /*
  239. * Returns real bEndpointAddress of an endpoint. If function is not
  240. * active returns -ENODEV.
  241. */
  242. #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129)
  243. /*
  244. * Returns endpoint descriptor. If function is not active returns -ENODEV.
  245. */
  246. #define FUNCTIONFS_ENDPOINT_DESC _IOR('g', 130, \
  247. struct usb_endpoint_descriptor)
  248. #endif /* __LINUX_FUNCTIONFS_H__ */