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