GNU Linux-libre 4.9.337-gnu1
[releases.git] / include / uapi / linux / usb / functionfs.h
1 #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
11 enum {
12         FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
13         FUNCTIONFS_STRINGS_MAGIC = 2,
14         FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
15 };
16
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,
22         FUNCTIONFS_VIRTUAL_ADDR = 16,
23         FUNCTIONFS_EVENTFD = 32,
24         FUNCTIONFS_ALL_CTRL_RECIP = 64,
25         FUNCTIONFS_CONFIG0_SETUP = 128,
26 };
27
28 /* Descriptor of an non-audio endpoint */
29 struct usb_endpoint_descriptor_no_audio {
30         __u8  bLength;
31         __u8  bDescriptorType;
32
33         __u8  bEndpointAddress;
34         __u8  bmAttributes;
35         __le16 wMaxPacketSize;
36         __u8  bInterval;
37 } __attribute__((packed));
38
39 struct usb_functionfs_descs_head_v2 {
40         __le32 magic;
41         __le32 length;
42         __le32 flags;
43         /*
44          * __le32 fs_count, hs_count, fs_count; must be included manually in
45          * the structure taking flags into consideration.
46          */
47 } __attribute__((packed));
48
49 /* Legacy format, deprecated as of 3.14. */
50 struct usb_functionfs_descs_head {
51         __le32 magic;
52         __le32 length;
53         __le32 fs_count;
54         __le32 hs_count;
55 } __attribute__((packed, deprecated));
56
57 /* MS OS Descriptor header */
58 struct usb_os_desc_header {
59         __u8    interface;
60         __le32  dwLength;
61         __le16  bcdVersion;
62         __le16  wIndex;
63         union {
64                 struct {
65                         __u8    bCount;
66                         __u8    Reserved;
67                 };
68                 __le16  wCount;
69         };
70 } __attribute__((packed));
71
72 struct usb_ext_compat_desc {
73         __u8    bFirstInterfaceNumber;
74         __u8    Reserved1;
75         __u8    CompatibleID[8];
76         __u8    SubCompatibleID[8];
77         __u8    Reserved2[6];
78 };
79
80 struct usb_ext_prop_desc {
81         __le32  dwSize;
82         __le32  dwPropertyDataType;
83         __le16  wPropertyNameLength;
84 } __attribute__((packed));
85
86 #ifndef __KERNEL__
87
88 /*
89  * Descriptors format:
90  *
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  * |     | fs_count  | LE32         | number of full-speed descriptors     |
97  * |     | hs_count  | LE32         | number of high-speed descriptors     |
98  * |     | ss_count  | LE32         | number of super-speed descriptors    |
99  * |     | os_count  | LE32         | number of MS OS descriptors          |
100  * |     | fs_descrs | Descriptor[] | list of full-speed descriptors       |
101  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
102  * |     | ss_descrs | Descriptor[] | list of super-speed descriptors      |
103  * |     | os_descrs | OSDesc[]     | list of MS OS descriptors            |
104  *
105  * Depending on which flags are set, various fields may be missing in the
106  * structure.  Any flags that are not recognised cause the whole block to be
107  * rejected with -ENOSYS.
108  *
109  * Legacy descriptors format (deprecated as of 3.14):
110  *
111  * | off | name      | type         | description                          |
112  * |-----+-----------+--------------+--------------------------------------|
113  * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC         |
114  * |   4 | length    | LE32         | length of the whole data chunk       |
115  * |   8 | fs_count  | LE32         | number of full-speed descriptors     |
116  * |  12 | hs_count  | LE32         | number of high-speed descriptors     |
117  * |  16 | fs_descrs | Descriptor[] | list of full-speed descriptors       |
118  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
119  *
120  * All numbers must be in little endian order.
121  *
122  * Descriptor[] is an array of valid USB descriptors which have the following
123  * format:
124  *
125  * | off | name            | type | description              |
126  * |-----+-----------------+------+--------------------------|
127  * |   0 | bLength         | U8   | length of the descriptor |
128  * |   1 | bDescriptorType | U8   | descriptor type          |
129  * |   2 | payload         |      | descriptor's payload     |
130  *
131  * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
132  * the following formats:
133  *
134  * | off | name            | type | description              |
135  * |-----+-----------------+------+--------------------------|
136  * |   0 | inteface        | U8   | related interface number |
137  * |   1 | dwLength        | U32  | length of the descriptor |
138  * |   5 | bcdVersion      | U16  | currently supported: 1   |
139  * |   7 | wIndex          | U16  | currently supported: 4   |
140  * |   9 | bCount          | U8   | number of ext. compat.   |
141  * |  10 | Reserved        | U8   | 0                        |
142  * |  11 | ExtCompat[]     |      | list of ext. compat. d.  |
143  *
144  * | off | name            | type | description              |
145  * |-----+-----------------+------+--------------------------|
146  * |   0 | inteface        | U8   | related interface number |
147  * |   1 | dwLength        | U32  | length of the descriptor |
148  * |   5 | bcdVersion      | U16  | currently supported: 1   |
149  * |   7 | wIndex          | U16  | currently supported: 5   |
150  * |   9 | wCount          | U16  | number of ext. compat.   |
151  * |  11 | ExtProp[]       |      | list of ext. prop. d.    |
152  *
153  * ExtCompat[] is an array of valid Extended Compatiblity descriptors
154  * which have the following format:
155  *
156  * | off | name                  | type | description                         |
157  * |-----+-----------------------+------+-------------------------------------|
158  * |   0 | bFirstInterfaceNumber | U8   | index of the interface or of the 1st|
159  * |     |                       |      | interface in an IAD group           |
160  * |   1 | Reserved              | U8   | 0                                   |
161  * |   2 | CompatibleID          | U8[8]| compatible ID string                |
162  * |  10 | SubCompatibleID       | U8[8]| subcompatible ID string             |
163  * |  18 | Reserved              | U8[6]| 0                                   |
164  *
165  * ExtProp[] is an array of valid Extended Properties descriptors
166  * which have the following format:
167  *
168  * | off | name                  | type | description                         |
169  * |-----+-----------------------+------+-------------------------------------|
170  * |   0 | dwSize                | U32  | length of the descriptor            |
171  * |   4 | dwPropertyDataType    | U32  | 1..7                                |
172  * |   8 | wPropertyNameLength   | U16  | bPropertyName length (NL)           |
173  * |  10 | bPropertyName         |U8[NL]| name of this property               |
174  * |10+NL| dwPropertyDataLength  | U32  | bPropertyData length (DL)           |
175  * |14+NL| bProperty             |U8[DL]| payload of this property            |
176  */
177
178 struct usb_functionfs_strings_head {
179         __le32 magic;
180         __le32 length;
181         __le32 str_count;
182         __le32 lang_count;
183 } __attribute__((packed));
184
185 /*
186  * Strings format:
187  *
188  * | off | name       | type                  | description                |
189  * |-----+------------+-----------------------+----------------------------|
190  * |   0 | magic      | LE32                  | FUNCTIONFS_STRINGS_MAGIC   |
191  * |   4 | length     | LE32                  | length of the data chunk   |
192  * |   8 | str_count  | LE32                  | number of strings          |
193  * |  12 | lang_count | LE32                  | number of languages        |
194  * |  16 | stringtab  | StringTab[lang_count] | table of strings per lang  |
195  *
196  * For each language there is one stringtab entry (ie. there are lang_count
197  * stringtab entires).  Each StringTab has following format:
198  *
199  * | off | name    | type              | description                        |
200  * |-----+---------+-------------------+------------------------------------|
201  * |   0 | lang    | LE16              | language code                      |
202  * |   2 | strings | String[str_count] | array of strings in given language |
203  *
204  * For each string there is one strings entry (ie. there are str_count
205  * string entries).  Each String is a NUL terminated string encoded in
206  * UTF-8.
207  */
208
209 #endif
210
211
212 /*
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.
216  */
217
218 enum usb_functionfs_event_type {
219         FUNCTIONFS_BIND,
220         FUNCTIONFS_UNBIND,
221
222         FUNCTIONFS_ENABLE,
223         FUNCTIONFS_DISABLE,
224
225         FUNCTIONFS_SETUP,
226
227         FUNCTIONFS_SUSPEND,
228         FUNCTIONFS_RESUME
229 };
230
231 /* NOTE:  this structure must stay the same size and layout on
232  * both 32-bit and 64-bit kernels.
233  */
234 struct usb_functionfs_event {
235         union {
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;
240
241         /* enum usb_functionfs_event_type */
242         __u8                            type;
243         __u8                            _pad[3];
244 } __attribute__((packed));
245
246
247 /* Endpoint ioctls */
248 /* The same as in gadgetfs */
249
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)
256  */
257 #define FUNCTIONFS_FIFO_STATUS  _IO('g', 1)
258
259 /* discards any unclaimed data in the fifo. */
260 #define FUNCTIONFS_FIFO_FLUSH   _IO('g', 2)
261
262 /* resets endpoint halt+toggle; used to implement set_interface.
263  * some hardware (like pxa2xx) can't support this.
264  */
265 #define FUNCTIONFS_CLEAR_HALT   _IO('g', 3)
266
267 /* Specific for functionfs */
268
269 /*
270  * Returns reverse mapping of an interface.  Called on EP0.  If there
271  * is no such interface returns -EDOM.  If function is not active
272  * returns -ENODEV.
273  */
274 #define FUNCTIONFS_INTERFACE_REVMAP     _IO('g', 128)
275
276 /*
277  * Returns real bEndpointAddress of an endpoint.  If function is not
278  * active returns -ENODEV.
279  */
280 #define FUNCTIONFS_ENDPOINT_REVMAP      _IO('g', 129)
281
282 /*
283  * Returns endpoint descriptor. If function is not active returns -ENODEV.
284  */
285 #define FUNCTIONFS_ENDPOINT_DESC        _IOR('g', 130, \
286                                              struct usb_endpoint_descriptor)
287
288
289
290 #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */