1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef __LINUX_FUNCTIONFS_H__
3 #define __LINUX_FUNCTIONFS_H__
6 #include <linux/types.h>
7 #include <linux/ioctl.h>
9 #include <linux/usb/ch9.h>
13 FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
14 FUNCTIONFS_STRINGS_MAGIC = 2,
15 FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
18 enum functionfs_flags {
19 FUNCTIONFS_HAS_FS_DESC = 1,
20 FUNCTIONFS_HAS_HS_DESC = 2,
21 FUNCTIONFS_HAS_SS_DESC = 4,
22 FUNCTIONFS_HAS_MS_OS_DESC = 8,
23 FUNCTIONFS_VIRTUAL_ADDR = 16,
24 FUNCTIONFS_EVENTFD = 32,
25 FUNCTIONFS_ALL_CTRL_RECIP = 64,
26 FUNCTIONFS_CONFIG0_SETUP = 128,
29 /* Descriptor of an non-audio endpoint */
30 struct usb_endpoint_descriptor_no_audio {
34 __u8 bEndpointAddress;
36 __le16 wMaxPacketSize;
38 } __attribute__((packed));
40 struct usb_functionfs_descs_head_v2 {
45 * __le32 fs_count, hs_count, fs_count; must be included manually in
46 * the structure taking flags into consideration.
48 } __attribute__((packed));
50 /* Legacy format, deprecated as of 3.14. */
51 struct usb_functionfs_descs_head {
56 } __attribute__((packed, deprecated));
58 /* MS OS Descriptor header */
59 struct usb_os_desc_header {
71 } __attribute__((packed));
73 struct usb_ext_compat_desc {
74 __u8 bFirstInterfaceNumber;
77 __u8 SubCompatibleID[8];
81 struct usb_ext_prop_desc {
83 __le32 dwPropertyDataType;
84 __le16 wPropertyNameLength;
85 } __attribute__((packed));
91 * | off | name | type | description |
92 * |-----+-----------+--------------+--------------------------------------|
93 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 |
94 * | 4 | length | LE32 | length of the whole data chunk |
95 * | 8 | flags | LE32 | combination of functionfs_flags |
96 * | | eventfd | LE32 | eventfd file descriptor |
97 * | | fs_count | LE32 | number of full-speed descriptors |
98 * | | hs_count | LE32 | number of high-speed descriptors |
99 * | | ss_count | LE32 | number of super-speed descriptors |
100 * | | os_count | LE32 | number of MS OS descriptors |
101 * | | fs_descrs | Descriptor[] | list of full-speed descriptors |
102 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
103 * | | ss_descrs | Descriptor[] | list of super-speed descriptors |
104 * | | os_descrs | OSDesc[] | list of MS OS descriptors |
106 * Depending on which flags are set, various fields may be missing in the
107 * structure. Any flags that are not recognised cause the whole block to be
108 * rejected with -ENOSYS.
110 * Legacy descriptors format (deprecated as of 3.14):
112 * | off | name | type | description |
113 * |-----+-----------+--------------+--------------------------------------|
114 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC |
115 * | 4 | length | LE32 | length of the whole data chunk |
116 * | 8 | fs_count | LE32 | number of full-speed descriptors |
117 * | 12 | hs_count | LE32 | number of high-speed descriptors |
118 * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
119 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
121 * All numbers must be in little endian order.
123 * Descriptor[] is an array of valid USB descriptors which have the following
126 * | off | name | type | description |
127 * |-----+-----------------+------+--------------------------|
128 * | 0 | bLength | U8 | length of the descriptor |
129 * | 1 | bDescriptorType | U8 | descriptor type |
130 * | 2 | payload | | descriptor's payload |
132 * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
133 * the following formats:
135 * | off | name | type | description |
136 * |-----+-----------------+------+--------------------------|
137 * | 0 | inteface | U8 | related interface number |
138 * | 1 | dwLength | U32 | length of the descriptor |
139 * | 5 | bcdVersion | U16 | currently supported: 1 |
140 * | 7 | wIndex | U16 | currently supported: 4 |
141 * | 9 | bCount | U8 | number of ext. compat. |
142 * | 10 | Reserved | U8 | 0 |
143 * | 11 | ExtCompat[] | | list of ext. compat. d. |
145 * | off | name | type | description |
146 * |-----+-----------------+------+--------------------------|
147 * | 0 | inteface | U8 | related interface number |
148 * | 1 | dwLength | U32 | length of the descriptor |
149 * | 5 | bcdVersion | U16 | currently supported: 1 |
150 * | 7 | wIndex | U16 | currently supported: 5 |
151 * | 9 | wCount | U16 | number of ext. compat. |
152 * | 11 | ExtProp[] | | list of ext. prop. d. |
154 * ExtCompat[] is an array of valid Extended Compatiblity descriptors
155 * which have the following format:
157 * | off | name | type | description |
158 * |-----+-----------------------+------+-------------------------------------|
159 * | 0 | bFirstInterfaceNumber | U8 | index of the interface or of the 1st|
160 * | | | | interface in an IAD group |
161 * | 1 | Reserved | U8 | 1 |
162 * | 2 | CompatibleID | U8[8]| compatible ID string |
163 * | 10 | SubCompatibleID | U8[8]| subcompatible ID string |
164 * | 18 | Reserved | U8[6]| 0 |
166 * ExtProp[] is an array of valid Extended Properties descriptors
167 * which have the following format:
169 * | off | name | type | description |
170 * |-----+-----------------------+------+-------------------------------------|
171 * | 0 | dwSize | U32 | length of the descriptor |
172 * | 4 | dwPropertyDataType | U32 | 1..7 |
173 * | 8 | wPropertyNameLength | U16 | bPropertyName length (NL) |
174 * | 10 | bPropertyName |U8[NL]| name of this property |
175 * |10+NL| dwPropertyDataLength | U32 | bPropertyData length (DL) |
176 * |14+NL| bProperty |U8[DL]| payload of this property |
179 struct usb_functionfs_strings_head {
184 } __attribute__((packed));
189 * | off | name | type | description |
190 * |-----+------------+-----------------------+----------------------------|
191 * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC |
192 * | 4 | length | LE32 | length of the data chunk |
193 * | 8 | str_count | LE32 | number of strings |
194 * | 12 | lang_count | LE32 | number of languages |
195 * | 16 | stringtab | StringTab[lang_count] | table of strings per lang |
197 * For each language there is one stringtab entry (ie. there are lang_count
198 * stringtab entires). Each StringTab has following format:
200 * | off | name | type | description |
201 * |-----+---------+-------------------+------------------------------------|
202 * | 0 | lang | LE16 | language code |
203 * | 2 | strings | String[str_count] | array of strings in given language |
205 * For each string there is one strings entry (ie. there are str_count
206 * string entries). Each String is a NUL terminated string encoded in
213 * Events are delivered on the ep0 file descriptor, when the user mode driver
214 * reads from this file descriptor after writing the descriptors. Don't
215 * stop polling this descriptor.
218 enum usb_functionfs_event_type {
231 /* NOTE: this structure must stay the same size and layout on
232 * both 32-bit and 64-bit kernels.
234 struct usb_functionfs_event {
236 /* SETUP: packet; DATA phase i/o precedes next event
237 *(setup.bmRequestType & USB_DIR_IN) flags direction */
238 struct usb_ctrlrequest setup;
239 } __attribute__((packed)) u;
241 /* enum usb_functionfs_event_type */
244 } __attribute__((packed));
247 /* Endpoint ioctls */
248 /* The same as in gadgetfs */
250 /* IN transfers may be reported to the gadget driver as complete
251 * when the fifo is loaded, before the host reads the data;
252 * OUT transfers may be reported to the host's "client" driver as
253 * complete when they're sitting in the FIFO unread.
254 * THIS returns how many bytes are "unclaimed" in the endpoint fifo
255 * (needed for precise fault handling, when the hardware allows it)
257 #define FUNCTIONFS_FIFO_STATUS _IO('g', 1)
259 /* discards any unclaimed data in the fifo. */
260 #define FUNCTIONFS_FIFO_FLUSH _IO('g', 2)
262 /* resets endpoint halt+toggle; used to implement set_interface.
263 * some hardware (like pxa2xx) can't support this.
265 #define FUNCTIONFS_CLEAR_HALT _IO('g', 3)
267 /* Specific for functionfs */
270 * Returns reverse mapping of an interface. Called on EP0. If there
271 * is no such interface returns -EDOM. If function is not active
274 #define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128)
277 * Returns real bEndpointAddress of an endpoint. If endpoint shuts down
278 * during the call, returns -ESHUTDOWN.
280 #define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129)
283 * Returns endpoint descriptor. If endpoint shuts down during the call,
284 * returns -ESHUTDOWN.
286 #define FUNCTIONFS_ENDPOINT_DESC _IOR('g', 130, \
287 struct usb_endpoint_descriptor)
291 #endif /* __LINUX_FUNCTIONFS_H__ */