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));
40 * | off | name | type | description |
41 * |-----+-----------+--------------+--------------------------------------|
42 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 |
43 * | 4 | length | LE32 | length of the whole data chunk |
44 * | 8 | flags | LE32 | combination of functionfs_flags |
45 * | | fs_count | LE32 | number of full-speed descriptors |
46 * | | hs_count | LE32 | number of high-speed descriptors |
47 * | | ss_count | LE32 | number of super-speed descriptors |
48 * | | fs_descrs | Descriptor[] | list of full-speed descriptors |
49 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
50 * | | ss_descrs | Descriptor[] | list of super-speed descriptors |
52 * Depending on which flags are set, various fields may be missing in the
53 * structure. Any flags that are not recognised cause the whole block to be
54 * rejected with -ENOSYS.
56 * Legacy descriptors format:
58 * | off | name | type | description |
59 * |-----+-----------+--------------+--------------------------------------|
60 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC |
61 * | 4 | length | LE32 | length of the whole data chunk |
62 * | 8 | fs_count | LE32 | number of full-speed descriptors |
63 * | 12 | hs_count | LE32 | number of high-speed descriptors |
64 * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
65 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
67 * All numbers must be in little endian order.
69 * Descriptor[] is an array of valid USB descriptors which have the following
72 * | off | name | type | description |
73 * |-----+-----------------+------+--------------------------|
74 * | 0 | bLength | U8 | length of the descriptor |
75 * | 1 | bDescriptorType | U8 | descriptor type |
76 * | 2 | payload | | descriptor's payload |
79 struct usb_functionfs_strings_head {
84 } __attribute__((packed));
89 * | off | name | type | description |
90 * |-----+------------+-----------------------+----------------------------|
91 * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC |
92 * | 4 | length | LE32 | length of the data chunk |
93 * | 8 | str_count | LE32 | number of strings |
94 * | 12 | lang_count | LE32 | number of languages |
95 * | 16 | stringtab | StringTab[lang_count] | table of strings per lang |
97 * For each language there is one stringtab entry (ie. there are lang_count
98 * stringtab entires). Each StringTab has following format:
100 * | off | name | type | description |
101 * |-----+---------+-------------------+------------------------------------|
102 * | 0 | lang | LE16 | language code |
103 * | 2 | strings | String[str_count] | array of strings in given language |
105 * For each string there is one strings entry (ie. there are str_count
106 * string entries). Each String is a NUL terminated string encoded in
114 * Events are delivered on the ep0 file descriptor, when the user mode driver
115 * reads from this file descriptor after writing the descriptors. Don't
116 * stop polling this descriptor.
119 enum usb_functionfs_event_type {
132 /* NOTE: this structure must stay the same size and layout on
133 * both 32-bit and 64-bit kernels.
135 struct usb_functionfs_event {
137 /* SETUP: packet; DATA phase i/o precedes next event
138 *(setup.bmRequestType & USB_DIR_IN) flags direction */
139 struct usb_ctrlrequest setup;
140 } __attribute__((packed)) u;
142 /* enum usb_functionfs_event_type */
145 } __attribute__((packed));
148 /* Endpoint ioctls */
149 /* The same as in gadgetfs */
151 /* IN transfers may be reported to the gadget driver as complete
152 * when the fifo is loaded, before the host reads the data;
153 * OUT transfers may be reported to the host's "client" driver as
154 * complete when they're sitting in the FIFO unread.
155 * THIS returns how many bytes are "unclaimed" in the endpoint fifo
156 * (needed for precise fault handling, when the hardware allows it)
158 #define FUNCTIONFS_FIFO_STATUS _IO('g', 1)
160 /* discards any unclaimed data in the fifo. */
161 #define FUNCTIONFS_FIFO_FLUSH _IO('g', 2)
163 /* resets endpoint halt+toggle; used to implement set_interface.
164 * some hardware (like pxa2xx) can't support this.
166 #define FUNCTIONFS_CLEAR_HALT _IO('g', 3)
168 /* Specific for functionfs */
171 * Returns reverse mapping of an interface. Called on EP0. If there
172 * is no such interface returns -EDOM. If function is not active
175 #define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128)
178 * Returns real bEndpointAddress of an endpoint. If function is not
179 * active returns -ENODEV.
181 #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129)
185 #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */