blob: 295ba299e7bdb6b57f59b2f642fe43cae348e86a [file] [log] [blame]
David Howells5e1ddb42012-10-09 09:49:07 +01001#ifndef _UAPI__LINUX_FUNCTIONFS_H__
2#define _UAPI__LINUX_FUNCTIONFS_H__
3
4
5#include <linux/types.h>
6#include <linux/ioctl.h>
7
8#include <linux/usb/ch9.h>
9
10
11enum {
12 FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
Michal Nazarewiczac8dde12014-02-28 16:50:23 +053013 FUNCTIONFS_STRINGS_MAGIC = 2,
14 FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
David Howells5e1ddb42012-10-09 09:49:07 +010015};
16
Michal Nazarewiczac8dde12014-02-28 16:50:23 +053017enum functionfs_flags {
18 FUNCTIONFS_HAS_FS_DESC = 1,
19 FUNCTIONFS_HAS_HS_DESC = 2,
20 FUNCTIONFS_HAS_SS_DESC = 4,
Andrzej Pietrasiewiczf0175ab2014-07-09 12:20:08 +020021 FUNCTIONFS_HAS_MS_OS_DESC = 8,
Robert Baldyga1b0bf882014-09-09 08:23:17 +020022 FUNCTIONFS_VIRTUAL_ADDR = 16,
Michal Nazarewiczac8dde12014-02-28 16:50:23 +053023};
David Howells5e1ddb42012-10-09 09:49:07 +010024
David Howells5e1ddb42012-10-09 09:49:07 +010025/* Descriptor of an non-audio endpoint */
26struct usb_endpoint_descriptor_no_audio {
27 __u8 bLength;
28 __u8 bDescriptorType;
29
30 __u8 bEndpointAddress;
31 __u8 bmAttributes;
32 __le16 wMaxPacketSize;
33 __u8 bInterval;
34} __attribute__((packed));
35
Michal Nazarewicz1df22b42014-08-27 22:58:45 +020036struct usb_functionfs_descs_head_v2 {
37 __le32 magic;
38 __le32 length;
39 __le32 flags;
40 /*
41 * __le32 fs_count, hs_count, fs_count; must be included manually in
42 * the structure taking flags into consideration.
43 */
44} __attribute__((packed));
45
Michal Nazarewicz09122142014-06-13 15:38:04 +020046/* Legacy format, deprecated as of 3.14. */
47struct usb_functionfs_descs_head {
48 __le32 magic;
49 __le32 length;
50 __le32 fs_count;
51 __le32 hs_count;
52} __attribute__((packed, deprecated));
David Howells5e1ddb42012-10-09 09:49:07 +010053
Andrzej Pietrasiewiczf0175ab2014-07-09 12:20:08 +020054/* MS OS Descriptor header */
55struct usb_os_desc_header {
56 __u8 interface;
57 __le32 dwLength;
58 __le16 bcdVersion;
59 __le16 wIndex;
60 union {
61 struct {
62 __u8 bCount;
63 __u8 Reserved;
64 };
65 __le16 wCount;
66 };
67} __attribute__((packed));
68
69struct usb_ext_compat_desc {
70 __u8 bFirstInterfaceNumber;
71 __u8 Reserved1;
72 __u8 CompatibleID[8];
73 __u8 SubCompatibleID[8];
74 __u8 Reserved2[6];
75};
76
77struct usb_ext_prop_desc {
78 __le32 dwSize;
79 __le32 dwPropertyDataType;
80 __le16 wPropertyNameLength;
81} __attribute__((packed));
82
83#ifndef __KERNEL__
David Howells5e1ddb42012-10-09 09:49:07 +010084
85/*
David Howells5e1ddb42012-10-09 09:49:07 +010086 * Descriptors format:
87 *
88 * | off | name | type | description |
89 * |-----+-----------+--------------+--------------------------------------|
Michal Nazarewiczac8dde12014-02-28 16:50:23 +053090 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC_V2 |
91 * | 4 | length | LE32 | length of the whole data chunk |
92 * | 8 | flags | LE32 | combination of functionfs_flags |
93 * | | fs_count | LE32 | number of full-speed descriptors |
94 * | | hs_count | LE32 | number of high-speed descriptors |
95 * | | ss_count | LE32 | number of super-speed descriptors |
Andrzej Pietrasiewiczf0175ab2014-07-09 12:20:08 +020096 * | | os_count | LE32 | number of MS OS descriptors |
Michal Nazarewiczac8dde12014-02-28 16:50:23 +053097 * | | fs_descrs | Descriptor[] | list of full-speed descriptors |
98 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
99 * | | ss_descrs | Descriptor[] | list of super-speed descriptors |
Andrzej Pietrasiewiczf0175ab2014-07-09 12:20:08 +0200100 * | | os_descrs | OSDesc[] | list of MS OS descriptors |
Michal Nazarewiczac8dde12014-02-28 16:50:23 +0530101 *
102 * Depending on which flags are set, various fields may be missing in the
103 * structure. Any flags that are not recognised cause the whole block to be
104 * rejected with -ENOSYS.
105 *
Michal Nazarewicz51c208c2014-08-27 22:58:46 +0200106 * Legacy descriptors format (deprecated as of 3.14):
Michal Nazarewiczac8dde12014-02-28 16:50:23 +0530107 *
108 * | off | name | type | description |
109 * |-----+-----------+--------------+--------------------------------------|
110 * | 0 | magic | LE32 | FUNCTIONFS_DESCRIPTORS_MAGIC |
David Howells5e1ddb42012-10-09 09:49:07 +0100111 * | 4 | length | LE32 | length of the whole data chunk |
112 * | 8 | fs_count | LE32 | number of full-speed descriptors |
113 * | 12 | hs_count | LE32 | number of high-speed descriptors |
114 * | 16 | fs_descrs | Descriptor[] | list of full-speed descriptors |
115 * | | hs_descrs | Descriptor[] | list of high-speed descriptors |
116 *
Michal Nazarewiczac8dde12014-02-28 16:50:23 +0530117 * All numbers must be in little endian order.
118 *
119 * Descriptor[] is an array of valid USB descriptors which have the following
120 * format:
David Howells5e1ddb42012-10-09 09:49:07 +0100121 *
122 * | off | name | type | description |
123 * |-----+-----------------+------+--------------------------|
124 * | 0 | bLength | U8 | length of the descriptor |
125 * | 1 | bDescriptorType | U8 | descriptor type |
126 * | 2 | payload | | descriptor's payload |
Andrzej Pietrasiewiczf0175ab2014-07-09 12:20:08 +0200127 *
128 * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
129 * the following formats:
130 *
131 * | off | name | type | description |
132 * |-----+-----------------+------+--------------------------|
133 * | 0 | inteface | U8 | related interface number |
134 * | 1 | dwLength | U32 | length of the descriptor |
135 * | 5 | bcdVersion | U16 | currently supported: 1 |
136 * | 7 | wIndex | U16 | currently supported: 4 |
137 * | 9 | bCount | U8 | number of ext. compat. |
138 * | 10 | Reserved | U8 | 0 |
139 * | 11 | ExtCompat[] | | list of ext. compat. d. |
140 *
141 * | off | name | type | description |
142 * |-----+-----------------+------+--------------------------|
143 * | 0 | inteface | U8 | related interface number |
144 * | 1 | dwLength | U32 | length of the descriptor |
145 * | 5 | bcdVersion | U16 | currently supported: 1 |
146 * | 7 | wIndex | U16 | currently supported: 5 |
147 * | 9 | wCount | U16 | number of ext. compat. |
148 * | 11 | ExtProp[] | | list of ext. prop. d. |
149 *
150 * ExtCompat[] is an array of valid Extended Compatiblity descriptors
151 * which have the following format:
152 *
153 * | off | name | type | description |
154 * |-----+-----------------------+------+-------------------------------------|
155 * | 0 | bFirstInterfaceNumber | U8 | index of the interface or of the 1st|
156 * | | | | interface in an IAD group |
157 * | 1 | Reserved | U8 | 0 |
158 * | 2 | CompatibleID | U8[8]| compatible ID string |
159 * | 10 | SubCompatibleID | U8[8]| subcompatible ID string |
160 * | 18 | Reserved | U8[6]| 0 |
161 *
162 * ExtProp[] is an array of valid Extended Properties descriptors
163 * which have the following format:
164 *
165 * | off | name | type | description |
166 * |-----+-----------------------+------+-------------------------------------|
167 * | 0 | dwSize | U32 | length of the descriptor |
168 * | 4 | dwPropertyDataType | U32 | 1..7 |
169 * | 8 | wPropertyNameLength | U16 | bPropertyName length (NL) |
170 * | 10 | bPropertyName |U8[NL]| name of this property |
171 * |10+NL| dwPropertyDataLength | U32 | bPropertyData length (DL) |
172 * |14+NL| bProperty |U8[DL]| payload of this property |
David Howells5e1ddb42012-10-09 09:49:07 +0100173 */
174
175struct usb_functionfs_strings_head {
176 __le32 magic;
177 __le32 length;
178 __le32 str_count;
179 __le32 lang_count;
180} __attribute__((packed));
181
182/*
183 * Strings format:
184 *
185 * | off | name | type | description |
186 * |-----+------------+-----------------------+----------------------------|
187 * | 0 | magic | LE32 | FUNCTIONFS_STRINGS_MAGIC |
188 * | 4 | length | LE32 | length of the data chunk |
189 * | 8 | str_count | LE32 | number of strings |
190 * | 12 | lang_count | LE32 | number of languages |
191 * | 16 | stringtab | StringTab[lang_count] | table of strings per lang |
192 *
193 * For each language there is one stringtab entry (ie. there are lang_count
194 * stringtab entires). Each StringTab has following format:
195 *
196 * | off | name | type | description |
197 * |-----+---------+-------------------+------------------------------------|
198 * | 0 | lang | LE16 | language code |
199 * | 2 | strings | String[str_count] | array of strings in given language |
200 *
201 * For each string there is one strings entry (ie. there are str_count
202 * string entries). Each String is a NUL terminated string encoded in
203 * UTF-8.
204 */
205
206#endif
207
208
209/*
210 * Events are delivered on the ep0 file descriptor, when the user mode driver
211 * reads from this file descriptor after writing the descriptors. Don't
212 * stop polling this descriptor.
213 */
214
215enum usb_functionfs_event_type {
216 FUNCTIONFS_BIND,
217 FUNCTIONFS_UNBIND,
218
219 FUNCTIONFS_ENABLE,
220 FUNCTIONFS_DISABLE,
221
222 FUNCTIONFS_SETUP,
223
224 FUNCTIONFS_SUSPEND,
225 FUNCTIONFS_RESUME
226};
227
228/* NOTE: this structure must stay the same size and layout on
229 * both 32-bit and 64-bit kernels.
230 */
231struct usb_functionfs_event {
232 union {
233 /* SETUP: packet; DATA phase i/o precedes next event
234 *(setup.bmRequestType & USB_DIR_IN) flags direction */
235 struct usb_ctrlrequest setup;
236 } __attribute__((packed)) u;
237
238 /* enum usb_functionfs_event_type */
239 __u8 type;
240 __u8 _pad[3];
241} __attribute__((packed));
242
243
244/* Endpoint ioctls */
245/* The same as in gadgetfs */
246
247/* IN transfers may be reported to the gadget driver as complete
248 * when the fifo is loaded, before the host reads the data;
249 * OUT transfers may be reported to the host's "client" driver as
250 * complete when they're sitting in the FIFO unread.
251 * THIS returns how many bytes are "unclaimed" in the endpoint fifo
252 * (needed for precise fault handling, when the hardware allows it)
253 */
254#define FUNCTIONFS_FIFO_STATUS _IO('g', 1)
255
256/* discards any unclaimed data in the fifo. */
257#define FUNCTIONFS_FIFO_FLUSH _IO('g', 2)
258
259/* resets endpoint halt+toggle; used to implement set_interface.
260 * some hardware (like pxa2xx) can't support this.
261 */
262#define FUNCTIONFS_CLEAR_HALT _IO('g', 3)
263
264/* Specific for functionfs */
265
266/*
267 * Returns reverse mapping of an interface. Called on EP0. If there
268 * is no such interface returns -EDOM. If function is not active
269 * returns -ENODEV.
270 */
271#define FUNCTIONFS_INTERFACE_REVMAP _IO('g', 128)
272
273/*
274 * Returns real bEndpointAddress of an endpoint. If function is not
275 * active returns -ENODEV.
276 */
277#define FUNCTIONFS_ENDPOINT_REVMAP _IO('g', 129)
278
Robert Baldygac559a352014-09-09 08:23:16 +0200279/*
280 * Returns endpoint descriptor. If function is not active returns -ENODEV.
281 */
282#define FUNCTIONFS_ENDPOINT_DESC _IOR('g', 130, \
283 struct usb_endpoint_descriptor)
284
David Howells5e1ddb42012-10-09 09:49:07 +0100285
286
287#endif /* _UAPI__LINUX_FUNCTIONFS_H__ */