xref: /linux-6.15/include/uapi/linux/usb/functionfs.h (revision f0175ab5)
15e1ddb48SDavid Howells #ifndef _UAPI__LINUX_FUNCTIONFS_H__
25e1ddb48SDavid Howells #define _UAPI__LINUX_FUNCTIONFS_H__
35e1ddb48SDavid Howells 
45e1ddb48SDavid Howells 
55e1ddb48SDavid Howells #include <linux/types.h>
65e1ddb48SDavid Howells #include <linux/ioctl.h>
75e1ddb48SDavid Howells 
85e1ddb48SDavid Howells #include <linux/usb/ch9.h>
95e1ddb48SDavid Howells 
105e1ddb48SDavid Howells 
115e1ddb48SDavid Howells enum {
125e1ddb48SDavid Howells 	FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
13ac8dde11SMichal Nazarewicz 	FUNCTIONFS_STRINGS_MAGIC = 2,
14ac8dde11SMichal Nazarewicz 	FUNCTIONFS_DESCRIPTORS_MAGIC_V2 = 3,
155e1ddb48SDavid Howells };
165e1ddb48SDavid Howells 
17ac8dde11SMichal Nazarewicz enum functionfs_flags {
18ac8dde11SMichal Nazarewicz 	FUNCTIONFS_HAS_FS_DESC = 1,
19ac8dde11SMichal Nazarewicz 	FUNCTIONFS_HAS_HS_DESC = 2,
20ac8dde11SMichal Nazarewicz 	FUNCTIONFS_HAS_SS_DESC = 4,
21*f0175ab5SAndrzej Pietrasiewicz 	FUNCTIONFS_HAS_MS_OS_DESC = 8,
22ac8dde11SMichal Nazarewicz };
235e1ddb48SDavid Howells 
245e1ddb48SDavid Howells /* Descriptor of an non-audio endpoint */
255e1ddb48SDavid Howells struct usb_endpoint_descriptor_no_audio {
265e1ddb48SDavid Howells 	__u8  bLength;
275e1ddb48SDavid Howells 	__u8  bDescriptorType;
285e1ddb48SDavid Howells 
295e1ddb48SDavid Howells 	__u8  bEndpointAddress;
305e1ddb48SDavid Howells 	__u8  bmAttributes;
315e1ddb48SDavid Howells 	__le16 wMaxPacketSize;
325e1ddb48SDavid Howells 	__u8  bInterval;
335e1ddb48SDavid Howells } __attribute__((packed));
345e1ddb48SDavid Howells 
35*f0175ab5SAndrzej Pietrasiewicz /* MS OS Descriptor header */
36*f0175ab5SAndrzej Pietrasiewicz struct usb_os_desc_header {
37*f0175ab5SAndrzej Pietrasiewicz 	__u8	interface;
38*f0175ab5SAndrzej Pietrasiewicz 	__le32	dwLength;
39*f0175ab5SAndrzej Pietrasiewicz 	__le16	bcdVersion;
40*f0175ab5SAndrzej Pietrasiewicz 	__le16	wIndex;
41*f0175ab5SAndrzej Pietrasiewicz 	union {
42*f0175ab5SAndrzej Pietrasiewicz 		struct {
43*f0175ab5SAndrzej Pietrasiewicz 			__u8	bCount;
44*f0175ab5SAndrzej Pietrasiewicz 			__u8	Reserved;
45*f0175ab5SAndrzej Pietrasiewicz 		};
46*f0175ab5SAndrzej Pietrasiewicz 		__le16	wCount;
47*f0175ab5SAndrzej Pietrasiewicz 	};
48*f0175ab5SAndrzej Pietrasiewicz } __attribute__((packed));
49*f0175ab5SAndrzej Pietrasiewicz 
50*f0175ab5SAndrzej Pietrasiewicz struct usb_ext_compat_desc {
51*f0175ab5SAndrzej Pietrasiewicz 	__u8	bFirstInterfaceNumber;
52*f0175ab5SAndrzej Pietrasiewicz 	__u8	Reserved1;
53*f0175ab5SAndrzej Pietrasiewicz 	__u8	CompatibleID[8];
54*f0175ab5SAndrzej Pietrasiewicz 	__u8	SubCompatibleID[8];
55*f0175ab5SAndrzej Pietrasiewicz 	__u8	Reserved2[6];
56*f0175ab5SAndrzej Pietrasiewicz };
57*f0175ab5SAndrzej Pietrasiewicz 
58*f0175ab5SAndrzej Pietrasiewicz struct usb_ext_prop_desc {
59*f0175ab5SAndrzej Pietrasiewicz 	__le32	dwSize;
60*f0175ab5SAndrzej Pietrasiewicz 	__le32	dwPropertyDataType;
61*f0175ab5SAndrzej Pietrasiewicz 	__le16	wPropertyNameLength;
62*f0175ab5SAndrzej Pietrasiewicz } __attribute__((packed));
63*f0175ab5SAndrzej Pietrasiewicz 
64*f0175ab5SAndrzej Pietrasiewicz #ifndef __KERNEL__
655e1ddb48SDavid Howells 
665e1ddb48SDavid Howells /*
675e1ddb48SDavid Howells  * Descriptors format:
685e1ddb48SDavid Howells  *
695e1ddb48SDavid Howells  * | off | name      | type         | description                          |
705e1ddb48SDavid Howells  * |-----+-----------+--------------+--------------------------------------|
71ac8dde11SMichal Nazarewicz  * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC_V2      |
72ac8dde11SMichal Nazarewicz  * |   4 | length    | LE32         | length of the whole data chunk       |
73ac8dde11SMichal Nazarewicz  * |   8 | flags     | LE32         | combination of functionfs_flags      |
74ac8dde11SMichal Nazarewicz  * |     | fs_count  | LE32         | number of full-speed descriptors     |
75ac8dde11SMichal Nazarewicz  * |     | hs_count  | LE32         | number of high-speed descriptors     |
76ac8dde11SMichal Nazarewicz  * |     | ss_count  | LE32         | number of super-speed descriptors    |
77*f0175ab5SAndrzej Pietrasiewicz  * |     | os_count  | LE32         | number of MS OS descriptors          |
78ac8dde11SMichal Nazarewicz  * |     | fs_descrs | Descriptor[] | list of full-speed descriptors       |
79ac8dde11SMichal Nazarewicz  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
80ac8dde11SMichal Nazarewicz  * |     | ss_descrs | Descriptor[] | list of super-speed descriptors      |
81*f0175ab5SAndrzej Pietrasiewicz  * |     | os_descrs | OSDesc[]     | list of MS OS descriptors            |
82ac8dde11SMichal Nazarewicz  *
83ac8dde11SMichal Nazarewicz  * Depending on which flags are set, various fields may be missing in the
84ac8dde11SMichal Nazarewicz  * structure.  Any flags that are not recognised cause the whole block to be
85ac8dde11SMichal Nazarewicz  * rejected with -ENOSYS.
86ac8dde11SMichal Nazarewicz  *
87ac8dde11SMichal Nazarewicz  * Legacy descriptors format:
88ac8dde11SMichal Nazarewicz  *
89ac8dde11SMichal Nazarewicz  * | off | name      | type         | description                          |
90ac8dde11SMichal Nazarewicz  * |-----+-----------+--------------+--------------------------------------|
91ac8dde11SMichal Nazarewicz  * |   0 | magic     | LE32         | FUNCTIONFS_DESCRIPTORS_MAGIC         |
925e1ddb48SDavid Howells  * |   4 | length    | LE32         | length of the whole data chunk       |
935e1ddb48SDavid Howells  * |   8 | fs_count  | LE32         | number of full-speed descriptors     |
945e1ddb48SDavid Howells  * |  12 | hs_count  | LE32         | number of high-speed descriptors     |
955e1ddb48SDavid Howells  * |  16 | fs_descrs | Descriptor[] | list of full-speed descriptors       |
965e1ddb48SDavid Howells  * |     | hs_descrs | Descriptor[] | list of high-speed descriptors       |
975e1ddb48SDavid Howells  *
98ac8dde11SMichal Nazarewicz  * All numbers must be in little endian order.
99ac8dde11SMichal Nazarewicz  *
100ac8dde11SMichal Nazarewicz  * Descriptor[] is an array of valid USB descriptors which have the following
101ac8dde11SMichal Nazarewicz  * format:
1025e1ddb48SDavid Howells  *
1035e1ddb48SDavid Howells  * | off | name            | type | description              |
1045e1ddb48SDavid Howells  * |-----+-----------------+------+--------------------------|
1055e1ddb48SDavid Howells  * |   0 | bLength         | U8   | length of the descriptor |
1065e1ddb48SDavid Howells  * |   1 | bDescriptorType | U8   | descriptor type          |
1075e1ddb48SDavid Howells  * |   2 | payload         |      | descriptor's payload     |
108*f0175ab5SAndrzej Pietrasiewicz  *
109*f0175ab5SAndrzej Pietrasiewicz  * OSDesc[] is an array of valid MS OS Feature Descriptors which have one of
110*f0175ab5SAndrzej Pietrasiewicz  * the following formats:
111*f0175ab5SAndrzej Pietrasiewicz  *
112*f0175ab5SAndrzej Pietrasiewicz  * | off | name            | type | description              |
113*f0175ab5SAndrzej Pietrasiewicz  * |-----+-----------------+------+--------------------------|
114*f0175ab5SAndrzej Pietrasiewicz  * |   0 | inteface        | U8   | related interface number |
115*f0175ab5SAndrzej Pietrasiewicz  * |   1 | dwLength        | U32  | length of the descriptor |
116*f0175ab5SAndrzej Pietrasiewicz  * |   5 | bcdVersion      | U16  | currently supported: 1   |
117*f0175ab5SAndrzej Pietrasiewicz  * |   7 | wIndex          | U16  | currently supported: 4   |
118*f0175ab5SAndrzej Pietrasiewicz  * |   9 | bCount          | U8   | number of ext. compat.   |
119*f0175ab5SAndrzej Pietrasiewicz  * |  10 | Reserved        | U8   | 0                        |
120*f0175ab5SAndrzej Pietrasiewicz  * |  11 | ExtCompat[]     |      | list of ext. compat. d.  |
121*f0175ab5SAndrzej Pietrasiewicz  *
122*f0175ab5SAndrzej Pietrasiewicz  * | off | name            | type | description              |
123*f0175ab5SAndrzej Pietrasiewicz  * |-----+-----------------+------+--------------------------|
124*f0175ab5SAndrzej Pietrasiewicz  * |   0 | inteface        | U8   | related interface number |
125*f0175ab5SAndrzej Pietrasiewicz  * |   1 | dwLength        | U32  | length of the descriptor |
126*f0175ab5SAndrzej Pietrasiewicz  * |   5 | bcdVersion      | U16  | currently supported: 1   |
127*f0175ab5SAndrzej Pietrasiewicz  * |   7 | wIndex          | U16  | currently supported: 5   |
128*f0175ab5SAndrzej Pietrasiewicz  * |   9 | wCount          | U16  | number of ext. compat.   |
129*f0175ab5SAndrzej Pietrasiewicz  * |  11 | ExtProp[]       |      | list of ext. prop. d.    |
130*f0175ab5SAndrzej Pietrasiewicz  *
131*f0175ab5SAndrzej Pietrasiewicz  * ExtCompat[] is an array of valid Extended Compatiblity descriptors
132*f0175ab5SAndrzej Pietrasiewicz  * which have the following format:
133*f0175ab5SAndrzej Pietrasiewicz  *
134*f0175ab5SAndrzej Pietrasiewicz  * | off | name                  | type | description                         |
135*f0175ab5SAndrzej Pietrasiewicz  * |-----+-----------------------+------+-------------------------------------|
136*f0175ab5SAndrzej Pietrasiewicz  * |   0 | bFirstInterfaceNumber | U8   | index of the interface or of the 1st|
137*f0175ab5SAndrzej Pietrasiewicz  * |     |                       |      | interface in an IAD group           |
138*f0175ab5SAndrzej Pietrasiewicz  * |   1 | Reserved              | U8   | 0                                   |
139*f0175ab5SAndrzej Pietrasiewicz  * |   2 | CompatibleID          | U8[8]| compatible ID string                |
140*f0175ab5SAndrzej Pietrasiewicz  * |  10 | SubCompatibleID       | U8[8]| subcompatible ID string             |
141*f0175ab5SAndrzej Pietrasiewicz  * |  18 | Reserved              | U8[6]| 0                                   |
142*f0175ab5SAndrzej Pietrasiewicz  *
143*f0175ab5SAndrzej Pietrasiewicz  * ExtProp[] is an array of valid Extended Properties descriptors
144*f0175ab5SAndrzej Pietrasiewicz  * which have the following format:
145*f0175ab5SAndrzej Pietrasiewicz  *
146*f0175ab5SAndrzej Pietrasiewicz  * | off | name                  | type | description                         |
147*f0175ab5SAndrzej Pietrasiewicz  * |-----+-----------------------+------+-------------------------------------|
148*f0175ab5SAndrzej Pietrasiewicz  * |   0 | dwSize                | U32  | length of the descriptor            |
149*f0175ab5SAndrzej Pietrasiewicz  * |   4 | dwPropertyDataType    | U32  | 1..7                                |
150*f0175ab5SAndrzej Pietrasiewicz  * |   8 | wPropertyNameLength   | U16  | bPropertyName length (NL)           |
151*f0175ab5SAndrzej Pietrasiewicz  * |  10 | bPropertyName         |U8[NL]| name of this property               |
152*f0175ab5SAndrzej Pietrasiewicz  * |10+NL| dwPropertyDataLength  | U32  | bPropertyData length (DL)           |
153*f0175ab5SAndrzej Pietrasiewicz  * |14+NL| bProperty             |U8[DL]| payload of this property            |
1545e1ddb48SDavid Howells  */
1555e1ddb48SDavid Howells 
1565e1ddb48SDavid Howells struct usb_functionfs_strings_head {
1575e1ddb48SDavid Howells 	__le32 magic;
1585e1ddb48SDavid Howells 	__le32 length;
1595e1ddb48SDavid Howells 	__le32 str_count;
1605e1ddb48SDavid Howells 	__le32 lang_count;
1615e1ddb48SDavid Howells } __attribute__((packed));
1625e1ddb48SDavid Howells 
1635e1ddb48SDavid Howells /*
1645e1ddb48SDavid Howells  * Strings format:
1655e1ddb48SDavid Howells  *
1665e1ddb48SDavid Howells  * | off | name       | type                  | description                |
1675e1ddb48SDavid Howells  * |-----+------------+-----------------------+----------------------------|
1685e1ddb48SDavid Howells  * |   0 | magic      | LE32                  | FUNCTIONFS_STRINGS_MAGIC   |
1695e1ddb48SDavid Howells  * |   4 | length     | LE32                  | length of the data chunk   |
1705e1ddb48SDavid Howells  * |   8 | str_count  | LE32                  | number of strings          |
1715e1ddb48SDavid Howells  * |  12 | lang_count | LE32                  | number of languages        |
1725e1ddb48SDavid Howells  * |  16 | stringtab  | StringTab[lang_count] | table of strings per lang  |
1735e1ddb48SDavid Howells  *
1745e1ddb48SDavid Howells  * For each language there is one stringtab entry (ie. there are lang_count
1755e1ddb48SDavid Howells  * stringtab entires).  Each StringTab has following format:
1765e1ddb48SDavid Howells  *
1775e1ddb48SDavid Howells  * | off | name    | type              | description                        |
1785e1ddb48SDavid Howells  * |-----+---------+-------------------+------------------------------------|
1795e1ddb48SDavid Howells  * |   0 | lang    | LE16              | language code                      |
1805e1ddb48SDavid Howells  * |   2 | strings | String[str_count] | array of strings in given language |
1815e1ddb48SDavid Howells  *
1825e1ddb48SDavid Howells  * For each string there is one strings entry (ie. there are str_count
1835e1ddb48SDavid Howells  * string entries).  Each String is a NUL terminated string encoded in
1845e1ddb48SDavid Howells  * UTF-8.
1855e1ddb48SDavid Howells  */
1865e1ddb48SDavid Howells 
1875e1ddb48SDavid Howells #endif
1885e1ddb48SDavid Howells 
1895e1ddb48SDavid Howells 
1905e1ddb48SDavid Howells /*
1915e1ddb48SDavid Howells  * Events are delivered on the ep0 file descriptor, when the user mode driver
1925e1ddb48SDavid Howells  * reads from this file descriptor after writing the descriptors.  Don't
1935e1ddb48SDavid Howells  * stop polling this descriptor.
1945e1ddb48SDavid Howells  */
1955e1ddb48SDavid Howells 
1965e1ddb48SDavid Howells enum usb_functionfs_event_type {
1975e1ddb48SDavid Howells 	FUNCTIONFS_BIND,
1985e1ddb48SDavid Howells 	FUNCTIONFS_UNBIND,
1995e1ddb48SDavid Howells 
2005e1ddb48SDavid Howells 	FUNCTIONFS_ENABLE,
2015e1ddb48SDavid Howells 	FUNCTIONFS_DISABLE,
2025e1ddb48SDavid Howells 
2035e1ddb48SDavid Howells 	FUNCTIONFS_SETUP,
2045e1ddb48SDavid Howells 
2055e1ddb48SDavid Howells 	FUNCTIONFS_SUSPEND,
2065e1ddb48SDavid Howells 	FUNCTIONFS_RESUME
2075e1ddb48SDavid Howells };
2085e1ddb48SDavid Howells 
2095e1ddb48SDavid Howells /* NOTE:  this structure must stay the same size and layout on
2105e1ddb48SDavid Howells  * both 32-bit and 64-bit kernels.
2115e1ddb48SDavid Howells  */
2125e1ddb48SDavid Howells struct usb_functionfs_event {
2135e1ddb48SDavid Howells 	union {
2145e1ddb48SDavid Howells 		/* SETUP: packet; DATA phase i/o precedes next event
2155e1ddb48SDavid Howells 		 *(setup.bmRequestType & USB_DIR_IN) flags direction */
2165e1ddb48SDavid Howells 		struct usb_ctrlrequest	setup;
2175e1ddb48SDavid Howells 	} __attribute__((packed)) u;
2185e1ddb48SDavid Howells 
2195e1ddb48SDavid Howells 	/* enum usb_functionfs_event_type */
2205e1ddb48SDavid Howells 	__u8				type;
2215e1ddb48SDavid Howells 	__u8				_pad[3];
2225e1ddb48SDavid Howells } __attribute__((packed));
2235e1ddb48SDavid Howells 
2245e1ddb48SDavid Howells 
2255e1ddb48SDavid Howells /* Endpoint ioctls */
2265e1ddb48SDavid Howells /* The same as in gadgetfs */
2275e1ddb48SDavid Howells 
2285e1ddb48SDavid Howells /* IN transfers may be reported to the gadget driver as complete
2295e1ddb48SDavid Howells  *	when the fifo is loaded, before the host reads the data;
2305e1ddb48SDavid Howells  * OUT transfers may be reported to the host's "client" driver as
2315e1ddb48SDavid Howells  *	complete when they're sitting in the FIFO unread.
2325e1ddb48SDavid Howells  * THIS returns how many bytes are "unclaimed" in the endpoint fifo
2335e1ddb48SDavid Howells  * (needed for precise fault handling, when the hardware allows it)
2345e1ddb48SDavid Howells  */
2355e1ddb48SDavid Howells #define	FUNCTIONFS_FIFO_STATUS	_IO('g', 1)
2365e1ddb48SDavid Howells 
2375e1ddb48SDavid Howells /* discards any unclaimed data in the fifo. */
2385e1ddb48SDavid Howells #define	FUNCTIONFS_FIFO_FLUSH	_IO('g', 2)
2395e1ddb48SDavid Howells 
2405e1ddb48SDavid Howells /* resets endpoint halt+toggle; used to implement set_interface.
2415e1ddb48SDavid Howells  * some hardware (like pxa2xx) can't support this.
2425e1ddb48SDavid Howells  */
2435e1ddb48SDavid Howells #define	FUNCTIONFS_CLEAR_HALT	_IO('g', 3)
2445e1ddb48SDavid Howells 
2455e1ddb48SDavid Howells /* Specific for functionfs */
2465e1ddb48SDavid Howells 
2475e1ddb48SDavid Howells /*
2485e1ddb48SDavid Howells  * Returns reverse mapping of an interface.  Called on EP0.  If there
2495e1ddb48SDavid Howells  * is no such interface returns -EDOM.  If function is not active
2505e1ddb48SDavid Howells  * returns -ENODEV.
2515e1ddb48SDavid Howells  */
2525e1ddb48SDavid Howells #define	FUNCTIONFS_INTERFACE_REVMAP	_IO('g', 128)
2535e1ddb48SDavid Howells 
2545e1ddb48SDavid Howells /*
2555e1ddb48SDavid Howells  * Returns real bEndpointAddress of an endpoint.  If function is not
2565e1ddb48SDavid Howells  * active returns -ENODEV.
2575e1ddb48SDavid Howells  */
2585e1ddb48SDavid Howells #define	FUNCTIONFS_ENDPOINT_REVMAP	_IO('g', 129)
2595e1ddb48SDavid Howells 
2605e1ddb48SDavid Howells 
2615e1ddb48SDavid Howells 
2625e1ddb48SDavid Howells #endif /* _UAPI__LINUX_FUNCTIONFS_H__ */
263