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