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