PageRenderTime 30ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/include/uapi/linux/usb/functionfs.h

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