functionfs.h 9.9 KB

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