functionfs.h 10 KB

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