functionfs.h 10.0 KB

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