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,
21 FUNCTIONFS_HAS_MS_OS_DESC = 8,
24 /* Descriptor of an non-audio endpoint */
25 struct usb_endpoint_descriptor_no_audio {
29 __u8 bEndpointAddress;
31 __le16 wMaxPacketSize;
33 } __attribute__((packed));
35 struct usb_functionfs_descs_head_v2 {
40 * __le32 fs_count, hs_count, fs_count; must be included manually in
41 * the structure taking flags into consideration.
43 } __attribute__((packed));
45 /* Legacy format, deprecated as of 3.14. */
46 struct usb_functionfs_descs_head {
51 } __attribute__((packed, deprecated));
53 /* MS OS Descriptor header */
54 struct usb_os_desc_header {
66 } __attribute__((packed));
68 struct usb_ext_compat_desc {
69 __u8 bFirstInterfaceNumber;
72 __u8 SubCompatibleID[8];
76 struct usb_ext_prop_desc {
78 __le32 dwPropertyDataType;
79 __le16 wPropertyNameLength;
80 } __attribute__((packed));
87 * | off | name | type | description |
88 * |-----+-----------+--------------+--------------------------------------|
89 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 |
90 * | 4 | length | LE32 | length of the whole data chunk |
91 * | 8 | flags | LE32 | combination of functionfs_flags |
92 * | | fs_count | LE32 | number of full-speed descriptors |
93 * | | hs_count | LE32 | number of high-speed descriptors |
94 * | | ss_count | LE32 | number of super-speed descriptors |
95 * | | os_count | LE32 | number of MS OS descriptors |
96 * | | fs_descrs | Descriptor[] | list of full-speed descriptors |
97 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
98 * | | ss_descrs | Descriptor[] | list of super-speed descriptors |
99 * | | os_descrs | OSDesc[] | list of MS OS descriptors |
101 * Depending on which flags are set, various fields may be missing in the
102 * structure. Any flags that are not recognised cause the whole block to be
103 * rejected with -ENOSYS.
105 * Legacy descriptors format:
107 * | off | name | type | description |
108 * |-----+-----------+--------------+--------------------------------------|
109 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC |
110 * | 4 | length | LE32 | length of the whole data chunk |
111 * | 8 | fs_count | LE32 | number of full-speed descriptors |
112 * | 12 | hs_count | LE32 | number of high-speed descriptors |
113 * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
114 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
116 * All numbers must be in little endian order.
118 * Descriptor[] is an array of valid USB descriptors which have the following
121 * | off | name | type | description |
122 * |-----+-----------------+------+--------------------------|
123 * | 0 | bLength | U8 | length of the descriptor |
124 * | 1 | bDescriptorType | U8 | descriptor type |
125 * | 2 | payload | | descriptor's payload |
127 * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
128 * the following formats:
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: 4 |
136 * | 9 | bCount | U8 | number of ext. compat. |
137 * | 10 | Reserved | U8 | 0 |
138 * | 11 | ExtCompat[] | | list of ext. compat. d. |
140 * | off | name | type | description |
141 * |-----+-----------------+------+--------------------------|
142 * | 0 | inteface | U8 | related interface number |
143 * | 1 | dwLength | U32 | length of the descriptor |
144 * | 5 | bcdVersion | U16 | currently supported: 1 |
145 * | 7 | wIndex | U16 | currently supported: 5 |
146 * | 9 | wCount | U16 | number of ext. compat. |
147 * | 11 | ExtProp[] | | list of ext. prop. d. |
149 * ExtCompat[] is an array of valid Extended Compatiblity descriptors
150 * which have the following format:
152 * | off | name | type | description |
153 * |-----+-----------------------+------+-------------------------------------|
154 * | 0 | bFirstInterfaceNumber | U8 | index of the interface or of the 1st|
155 * | | | | interface in an IAD group |
156 * | 1 | Reserved | U8 | 0 |
157 * | 2 | CompatibleID | U8[8]| compatible ID string |
158 * | 10 | SubCompatibleID | U8[8]| subcompatible ID string |
159 * | 18 | Reserved | U8[6]| 0 |
161 * ExtProp[] is an array of valid Extended Properties descriptors
162 * which have the following format:
164 * | off | name | type | description |
165 * |-----+-----------------------+------+-------------------------------------|
166 * | 0 | dwSize | U32 | length of the descriptor |
167 * | 4 | dwPropertyDataType | U32 | 1..7 |
168 * | 8 | wPropertyNameLength | U16 | bPropertyName length (NL) |
169 * | 10 | bPropertyName |U8[NL]| name of this property |
170 * |10+NL| dwPropertyDataLength | U32 | bPropertyData length (DL) |
171 * |14+NL| bProperty |U8[DL]| payload of this property |
174 struct usb_functionfs_strings_head {
179 } __attribute__((packed));
184 * | off | name | type | description |
185 * |-----+------------+-----------------------+----------------------------|
186 * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC |
187 * | 4 | length | LE32 | length of the data chunk |
188 * | 8 | str_count | LE32 | number of strings |
189 * | 12 | lang_count | LE32 | number of languages |
190 * | 16 | stringtab | StringTab[lang_count] | table of strings per lang |
192 * For each language there is one stringtab entry (ie. there are lang_count
193 * stringtab entires). Each StringTab has following format:
195 * | off | name | type | description |
196 * |-----+---------+-------------------+------------------------------------|
197 * | 0 | lang | LE16 | language code |
198 * | 2 | strings | String[str_count] | array of strings in given language |
200 * For each string there is one strings entry (ie. there are str_count
201 * string entries). Each String is a NUL terminated string encoded in
209 * Events are delivered on the ep0 file descriptor, when the user mode driver
210 * reads from this file descriptor after writing the descriptors. Don't
211 * stop polling this descriptor.
214 enum usb_functionfs_event_type {
227 /* NOTE: this structure must stay the same size and layout on
228 * both 32-bit and 64-bit kernels.
230 struct usb_functionfs_event {
232 /* SETUP: packet; DATA phase i/o precedes next event
233 *(setup.bmRequestType & USB_DIR_IN) flags direction */
234 struct usb_ctrlrequest setup;
235 } __attribute__((packed)) u;
237 /* enum usb_functionfs_event_type */
240 } __attribute__((packed));
243 /* Endpoint ioctls */
244 /* The same as in gadgetfs */
246 /* IN transfers may be reported to the gadget driver as complete
247 * when the fifo is loaded, before the host reads the data;
248 * OUT transfers may be reported to the host's "client" driver as
249 * complete when they're sitting in the FIFO unread.
250 * THIS returns how many bytes are "unclaimed" in the endpoint fifo
251 * (needed for precise fault handling, when the hardware allows it)
253 #define FUNCTIONFS_FIFO_STATUS _IO('g', 1)
255 /* discards any unclaimed data in the fifo. */
256 #define FUNCTIONFS_FIFO_FLUSH _IO('g', 2)
258 /* resets endpoint halt+toggle; used to implement set_interface.
259 * some hardware (like pxa2xx) can't support this.
261 #define FUNCTIONFS_CLEAR_HALT _IO('g', 3)
263 /* Specific for functionfs */
266 * Returns reverse mapping of an interface. Called on EP0. If there
267 * is no such interface returns -EDOM. If function is not active
270 #define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128)
273 * Returns real bEndpointAddress of an endpoint. If function is not
274 * active returns -ENODEV.
276 #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129)
280 #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */