functionfs.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. };
  16. #ifndef __KERNEL__
  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. /*
  27. * Descriptors format:
  28. *
  29. * | off | name | type | description |
  30. * |-----+-----------+--------------+--------------------------------------|
  31. * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 |
  32. * | 4 | length | LE32 | length of the whole data chunk |
  33. * | 8 | flags | LE32 | combination of functionfs_flags |
  34. * | | fs_count | LE32 | number of full-speed descriptors |
  35. * | | hs_count | LE32 | number of high-speed descriptors |
  36. * | | ss_count | LE32 | number of super-speed descriptors |
  37. * | | fs_descrs | Descriptor[] | list of full-speed descriptors |
  38. * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
  39. * | | ss_descrs | Descriptor[] | list of super-speed descriptors |
  40. *
  41. * Depending on which flags are set, various fields may be missing in the
  42. * structure. Any flags that are not recognised cause the whole block to be
  43. * rejected with -ENOSYS.
  44. *
  45. * Legacy descriptors format:
  46. *
  47. * | off | name | type | description |
  48. * |-----+-----------+--------------+--------------------------------------|
  49. * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC |
  50. * | 4 | length | LE32 | length of the whole data chunk |
  51. * | 8 | fs_count | LE32 | number of full-speed descriptors |
  52. * | 12 | hs_count | LE32 | number of high-speed descriptors |
  53. * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
  54. * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
  55. *
  56. * All numbers must be in little endian order.
  57. *
  58. * Descriptor[] is an array of valid USB descriptors which have the following
  59. * format:
  60. *
  61. * | off | name | type | description |
  62. * |-----+-----------------+------+--------------------------|
  63. * | 0 | bLength | U8 | length of the descriptor |
  64. * | 1 | bDescriptorType | U8 | descriptor type |
  65. * | 2 | payload | | descriptor's payload |
  66. */
  67. struct usb_functionfs_strings_head {
  68. __le32 magic;
  69. __le32 length;
  70. __le32 str_count;
  71. __le32 lang_count;
  72. } __attribute__((packed));
  73. /*
  74. * Strings format:
  75. *
  76. * | off | name | type | description |
  77. * |-----+------------+-----------------------+----------------------------|
  78. * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC |
  79. * | 4 | length | LE32 | length of the data chunk |
  80. * | 8 | str_count | LE32 | number of strings |
  81. * | 12 | lang_count | LE32 | number of languages |
  82. * | 16 | stringtab | StringTab[lang_count] | table of strings per lang |
  83. *
  84. * For each language there is one stringtab entry (ie. there are lang_count
  85. * stringtab entires). Each StringTab has following format:
  86. *
  87. * | off | name | type | description |
  88. * |-----+---------+-------------------+------------------------------------|
  89. * | 0 | lang | LE16 | language code |
  90. * | 2 | strings | String[str_count] | array of strings in given language |
  91. *
  92. * For each string there is one strings entry (ie. there are str_count
  93. * string entries). Each String is a NUL terminated string encoded in
  94. * UTF-8.
  95. */
  96. #endif
  97. /*
  98. * Events are delivered on the ep0 file descriptor, when the user mode driver
  99. * reads from this file descriptor after writing the descriptors. Don't
  100. * stop polling this descriptor.
  101. */
  102. enum usb_functionfs_event_type {
  103. FUNCTIONFS_BIND,
  104. FUNCTIONFS_UNBIND,
  105. FUNCTIONFS_ENABLE,
  106. FUNCTIONFS_DISABLE,
  107. FUNCTIONFS_SETUP,
  108. FUNCTIONFS_SUSPEND,
  109. FUNCTIONFS_RESUME
  110. };
  111. /* NOTE: this structure must stay the same size and layout on
  112. * both 32-bit and 64-bit kernels.
  113. */
  114. struct usb_functionfs_event {
  115. union {
  116. /* SETUP: packet; DATA phase i/o precedes next event
  117. *(setup.bmRequestType & USB_DIR_IN) flags direction */
  118. struct usb_ctrlrequest setup;
  119. } __attribute__((packed)) u;
  120. /* enum usb_functionfs_event_type */
  121. __u8 type;
  122. __u8 _pad[3];
  123. } __attribute__((packed));
  124. /* Endpoint ioctls */
  125. /* The same as in gadgetfs */
  126. /* IN transfers may be reported to the gadget driver as complete
  127. * when the fifo is loaded, before the host reads the data;
  128. * OUT transfers may be reported to the host's "client" driver as
  129. * complete when they're sitting in the FIFO unread.
  130. * THIS returns how many bytes are "unclaimed" in the endpoint fifo
  131. * (needed for precise fault handling, when the hardware allows it)
  132. */
  133. #define FUNCTIONFS_FIFO_STATUS _IO('g', 1)
  134. /* discards any unclaimed data in the fifo. */
  135. #define FUNCTIONFS_FIFO_FLUSH _IO('g', 2)
  136. /* resets endpoint halt+toggle; used to implement set_interface.
  137. * some hardware (like pxa2xx) can't support this.
  138. */
  139. #define FUNCTIONFS_CLEAR_HALT _IO('g', 3)
  140. /* Specific for functionfs */
  141. /*
  142. * Returns reverse mapping of an interface. Called on EP0. If there
  143. * is no such interface returns -EDOM. If function is not active
  144. * returns -ENODEV.
  145. */
  146. #define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128)
  147. /*
  148. * Returns real bEndpointAddress of an endpoint. If function is not
  149. * active returns -ENODEV.
  150. */
  151. #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129)
  152. #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */