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