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