functionfs.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. };
  17. /* Descriptor of an non-audio endpoint */
  18. struct usb_endpoint_descriptor_no_audio {
  19. __u8 bLength;
  20. __u8 bDescriptorType;
  21. __u8 bEndpointAddress;
  22. __u8 bmAttributes;
  23. __le16 wMaxPacketSize;
  24. __u8 bInterval;
  25. } __attribute__((packed));
  26. struct usb_functionfs_descs_head_v2 {
  27. __le32 magic;
  28. __le32 length;
  29. __le32 flags;
  30. /*
  31. * __le32 fs_count, hs_count, fs_count; must be included manually in
  32. * the structure taking flags into consideration.
  33. */
  34. } __attribute__((packed));
  35. /* Legacy format, deprecated as of 3.14. */
  36. struct usb_functionfs_descs_head {
  37. __le32 magic;
  38. __le32 length;
  39. __le32 fs_count;
  40. __le32 hs_count;
  41. } __attribute__((packed, deprecated));
  42. /* MS OS Descriptor header */
  43. struct usb_os_desc_header {
  44. __u8 interface;
  45. __le32 dwLength;
  46. __le16 bcdVersion;
  47. __le16 wIndex;
  48. union {
  49. struct {
  50. __u8 bCount;
  51. __u8 Reserved;
  52. };
  53. __le16 wCount;
  54. };
  55. } __attribute__((packed));
  56. struct usb_ext_compat_desc {
  57. __u8 bFirstInterfaceNumber;
  58. __u8 Reserved1;
  59. __u8 CompatibleID[8];
  60. __u8 SubCompatibleID[8];
  61. __u8 Reserved2[6];
  62. };
  63. struct usb_ext_prop_desc {
  64. __le32 dwSize;
  65. __le32 dwPropertyDataType;
  66. __le16 wPropertyNameLength;
  67. } __attribute__((packed));
  68. #ifndef __KERNEL__
  69. /*
  70. * Descriptors format:
  71. *
  72. * | off | name | type | description |
  73. * |-----+-----------+--------------+--------------------------------------|
  74. * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 |
  75. * | 4 | length | LE32 | length of the whole data chunk |
  76. * | 8 | flags | LE32 | combination of functionfs_flags |
  77. * | | fs_count | LE32 | number of full-speed descriptors |
  78. * | | hs_count | LE32 | number of high-speed descriptors |
  79. * | | ss_count | LE32 | number of super-speed descriptors |
  80. * | | os_count | LE32 | number of MS OS descriptors |
  81. * | | fs_descrs | Descriptor[] | list of full-speed descriptors |
  82. * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
  83. * | | ss_descrs | Descriptor[] | list of super-speed descriptors |
  84. * | | os_descrs | OSDesc[] | list of MS OS descriptors |
  85. *
  86. * Depending on which flags are set, various fields may be missing in the
  87. * structure. Any flags that are not recognised cause the whole block to be
  88. * rejected with -ENOSYS.
  89. *
  90. * Legacy descriptors format:
  91. *
  92. * | off | name | type | description |
  93. * |-----+-----------+--------------+--------------------------------------|
  94. * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC |
  95. * | 4 | length | LE32 | length of the whole data chunk |
  96. * | 8 | fs_count | LE32 | number of full-speed descriptors |
  97. * | 12 | hs_count | LE32 | number of high-speed descriptors |
  98. * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
  99. * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
  100. *
  101. * All numbers must be in little endian order.
  102. *
  103. * Descriptor[] is an array of valid USB descriptors which have the following
  104. * format:
  105. *
  106. * | off | name | type | description |
  107. * |-----+-----------------+------+--------------------------|
  108. * | 0 | bLength | U8 | length of the descriptor |
  109. * | 1 | bDescriptorType | U8 | descriptor type |
  110. * | 2 | payload | | descriptor's payload |
  111. *
  112. * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
  113. * the following formats:
  114. *
  115. * | off | name | type | description |
  116. * |-----+-----------------+------+--------------------------|
  117. * | 0 | inteface | U8 | related interface number |
  118. * | 1 | dwLength | U32 | length of the descriptor |
  119. * | 5 | bcdVersion | U16 | currently supported: 1 |
  120. * | 7 | wIndex | U16 | currently supported: 4 |
  121. * | 9 | bCount | U8 | number of ext. compat. |
  122. * | 10 | Reserved | U8 | 0 |
  123. * | 11 | ExtCompat[] | | list of ext. compat. d. |
  124. *
  125. * | off | name | type | description |
  126. * |-----+-----------------+------+--------------------------|
  127. * | 0 | inteface | U8 | related interface number |
  128. * | 1 | dwLength | U32 | length of the descriptor |
  129. * | 5 | bcdVersion | U16 | currently supported: 1 |
  130. * | 7 | wIndex | U16 | currently supported: 5 |
  131. * | 9 | wCount | U16 | number of ext. compat. |
  132. * | 11 | ExtProp[] | | list of ext. prop. d. |
  133. *
  134. * ExtCompat[] is an array of valid Extended Compatiblity descriptors
  135. * which have the following format:
  136. *
  137. * | off | name | type | description |
  138. * |-----+-----------------------+------+-------------------------------------|
  139. * | 0 | bFirstInterfaceNumber | U8 | index of the interface or of the 1st|
  140. * | | | | interface in an IAD group |
  141. * | 1 | Reserved | U8 | 0 |
  142. * | 2 | CompatibleID | U8[8]| compatible ID string |
  143. * | 10 | SubCompatibleID | U8[8]| subcompatible ID string |
  144. * | 18 | Reserved | U8[6]| 0 |
  145. *
  146. * ExtProp[] is an array of valid Extended Properties descriptors
  147. * which have the following format:
  148. *
  149. * | off | name | type | description |
  150. * |-----+-----------------------+------+-------------------------------------|
  151. * | 0 | dwSize | U32 | length of the descriptor |
  152. * | 4 | dwPropertyDataType | U32 | 1..7 |
  153. * | 8 | wPropertyNameLength | U16 | bPropertyName length (NL) |
  154. * | 10 | bPropertyName |U8[NL]| name of this property |
  155. * |10+NL| dwPropertyDataLength | U32 | bPropertyData length (DL) |
  156. * |14+NL| bProperty |U8[DL]| payload of this property |
  157. */
  158. struct usb_functionfs_strings_head {
  159. __le32 magic;
  160. __le32 length;
  161. __le32 str_count;
  162. __le32 lang_count;
  163. } __attribute__((packed));
  164. /*
  165. * Strings format:
  166. *
  167. * | off | name | type | description |
  168. * |-----+------------+-----------------------+----------------------------|
  169. * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC |
  170. * | 4 | length | LE32 | length of the data chunk |
  171. * | 8 | str_count | LE32 | number of strings |
  172. * | 12 | lang_count | LE32 | number of languages |
  173. * | 16 | stringtab | StringTab[lang_count] | table of strings per lang |
  174. *
  175. * For each language there is one stringtab entry (ie. there are lang_count
  176. * stringtab entires). Each StringTab has following format:
  177. *
  178. * | off | name | type | description |
  179. * |-----+---------+-------------------+------------------------------------|
  180. * | 0 | lang | LE16 | language code |
  181. * | 2 | strings | String[str_count] | array of strings in given language |
  182. *
  183. * For each string there is one strings entry (ie. there are str_count
  184. * string entries). Each String is a NUL terminated string encoded in
  185. * UTF-8.
  186. */
  187. #endif
  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. #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */