functionfs.h 9.3 KB

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