1 #ifndef _UAPI__LINUX_FUNCTIONFS_H__
2 #define _UAPI__LINUX_FUNCTIONFS_H__
5 #include <linux/types.h>
6 #include <linux/ioctl.h>
8 #include <linux/usb/ch9.h>
12 FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
13 FUNCTIONFS_STRINGS_MAGIC = 2,
14 FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
17 enum functionfs_flags {
18 FUNCTIONFS_HAS_FS_DESC = 1,
19 FUNCTIONFS_HAS_HS_DESC = 2,
20 FUNCTIONFS_HAS_SS_DESC = 4,
25 /* Descriptor of an non-audio endpoint */
26 struct usb_endpoint_descriptor_no_audio {
30 __u8 bEndpointAddress;
32 __le16 wMaxPacketSize;
34 } __attribute__((packed));
36 /* Legacy format, deprecated as of 3.14. */
37 struct usb_functionfs_descs_head {
42 } __attribute__((packed, deprecated));
47 * | off | name | type | description |
48 * |-----+-----------+--------------+--------------------------------------|
49 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 |
50 * | 4 | length | LE32 | length of the whole data chunk |
51 * | 8 | flags | LE32 | combination of functionfs_flags |
52 * | | fs_count | LE32 | number of full-speed descriptors |
53 * | | hs_count | LE32 | number of high-speed descriptors |
54 * | | ss_count | LE32 | number of super-speed descriptors |
55 * | | fs_descrs | Descriptor[] | list of full-speed descriptors |
56 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
57 * | | ss_descrs | Descriptor[] | list of super-speed descriptors |
59 * Depending on which flags are set, various fields may be missing in the
60 * structure. Any flags that are not recognised cause the whole block to be
61 * rejected with -ENOSYS.
63 * Legacy descriptors format:
65 * | off | name | type | description |
66 * |-----+-----------+--------------+--------------------------------------|
67 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC |
68 * | 4 | length | LE32 | length of the whole data chunk |
69 * | 8 | fs_count | LE32 | number of full-speed descriptors |
70 * | 12 | hs_count | LE32 | number of high-speed descriptors |
71 * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
72 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
74 * All numbers must be in little endian order.
76 * Descriptor[] is an array of valid USB descriptors which have the following
79 * | off | name | type | description |
80 * |-----+-----------------+------+--------------------------|
81 * | 0 | bLength | U8 | length of the descriptor |
82 * | 1 | bDescriptorType | U8 | descriptor type |
83 * | 2 | payload | | descriptor's payload |
86 struct usb_functionfs_strings_head {
91 } __attribute__((packed));
96 * | off | name | type | description |
97 * |-----+------------+-----------------------+----------------------------|
98 * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC |
99 * | 4 | length | LE32 | length of the data chunk |
100 * | 8 | str_count | LE32 | number of strings |
101 * | 12 | lang_count | LE32 | number of languages |
102 * | 16 | stringtab | StringTab[lang_count] | table of strings per lang |
104 * For each language there is one stringtab entry (ie. there are lang_count
105 * stringtab entires). Each StringTab has following format:
107 * | off | name | type | description |
108 * |-----+---------+-------------------+------------------------------------|
109 * | 0 | lang | LE16 | language code |
110 * | 2 | strings | String[str_count] | array of strings in given language |
112 * For each string there is one strings entry (ie. there are str_count
113 * string entries). Each String is a NUL terminated string encoded in
121 * Events are delivered on the ep0 file descriptor, when the user mode driver
122 * reads from this file descriptor after writing the descriptors. Don't
123 * stop polling this descriptor.
126 enum usb_functionfs_event_type {
139 /* NOTE: this structure must stay the same size and layout on
140 * both 32-bit and 64-bit kernels.
142 struct usb_functionfs_event {
144 /* SETUP: packet; DATA phase i/o precedes next event
145 *(setup.bmRequestType & USB_DIR_IN) flags direction */
146 struct usb_ctrlrequest setup;
147 } __attribute__((packed)) u;
149 /* enum usb_functionfs_event_type */
152 } __attribute__((packed));
155 /* Endpoint ioctls */
156 /* The same as in gadgetfs */
158 /* IN transfers may be reported to the gadget driver as complete
159 * when the fifo is loaded, before the host reads the data;
160 * OUT transfers may be reported to the host's "client" driver as
161 * complete when they're sitting in the FIFO unread.
162 * THIS returns how many bytes are "unclaimed" in the endpoint fifo
163 * (needed for precise fault handling, when the hardware allows it)
165 #define FUNCTIONFS_FIFO_STATUS _IO('g', 1)
167 /* discards any unclaimed data in the fifo. */
168 #define FUNCTIONFS_FIFO_FLUSH _IO('g', 2)
170 /* resets endpoint halt+toggle; used to implement set_interface.
171 * some hardware (like pxa2xx) can't support this.
173 #define FUNCTIONFS_CLEAR_HALT _IO('g', 3)
175 /* Specific for functionfs */
178 * Returns reverse mapping of an interface. Called on EP0. If there
179 * is no such interface returns -EDOM. If function is not active
182 #define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128)
185 * Returns real bEndpointAddress of an endpoint. If function is not
186 * active returns -ENODEV.
188 #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129)
192 #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */