1 /* $FreeBSD$ */ 2 /*- 3 * SPDX-License-Identifier: BSD-2-Clause 4 * 5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 6 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 7 * Copyright (c) 1998 Lennart Augustsson. All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 #ifndef _USB_IOCTL_H_ 32 #define _USB_IOCTL_H_ 33 34 #ifndef USB_GLOBAL_INCLUDE_FILE 35 #include <sys/ioccom.h> 36 #include <sys/cdefs.h> 37 38 /* Building "kdump" depends on these includes */ 39 40 #include <dev/usb/usb_endian.h> 41 #include <dev/usb/usb.h> 42 #endif 43 44 #define USB_DEVICE_NAME "usbctl" 45 #define USB_DEVICE_DIR "usb" 46 #define USB_GENERIC_NAME "ugen" 47 #define USB_TEMPLATE_SYSCTL "hw.usb.template" /* integer type */ 48 49 /* Definition of valid template sysctl values */ 50 51 enum { 52 USB_TEMP_MSC, /* USB Mass Storage */ 53 USB_TEMP_CDCE, /* USB CDC Ethernet */ 54 USB_TEMP_MTP, /* Message Transfer Protocol */ 55 USB_TEMP_MODEM, /* USB CDC Modem */ 56 USB_TEMP_AUDIO, /* USB Audio */ 57 USB_TEMP_KBD, /* USB Keyboard */ 58 USB_TEMP_MOUSE, /* USB Mouse */ 59 USB_TEMP_PHONE, /* USB Phone */ 60 USB_TEMP_SERIALNET, /* USB CDC Ethernet and Modem */ 61 USB_TEMP_MIDI, /* USB MIDI */ 62 USB_TEMP_MULTI, /* USB Ethernet, serial, and storage */ 63 USB_TEMP_CDCEEM, /* USB Ethernet Emulation Model */ 64 USB_TEMP_MAX, 65 }; 66 67 struct usb_read_dir { 68 void *urd_data; 69 uint32_t urd_startentry; 70 uint32_t urd_maxlen; 71 }; 72 73 struct usb_ctl_request { 74 void *ucr_data; 75 uint16_t ucr_flags; 76 uint16_t ucr_actlen; /* actual length transferred */ 77 uint8_t ucr_addr; /* zero - currently not used */ 78 struct usb_device_request ucr_request; 79 }; 80 81 struct usb_alt_interface { 82 uint8_t uai_interface_index; 83 uint8_t uai_alt_index; 84 }; 85 86 struct usb_gen_descriptor { 87 void *ugd_data; 88 uint16_t ugd_lang_id; 89 uint16_t ugd_maxlen; 90 uint16_t ugd_actlen; 91 uint16_t ugd_offset; 92 uint8_t ugd_config_index; 93 uint8_t ugd_string_index; 94 uint8_t ugd_iface_index; 95 uint8_t ugd_altif_index; 96 uint8_t ugd_endpt_index; 97 uint8_t ugd_report_type; 98 uint8_t reserved[8]; 99 }; 100 101 struct usb_device_info { 102 uint16_t udi_productNo; 103 uint16_t udi_vendorNo; 104 uint16_t udi_releaseNo; 105 uint16_t udi_power; /* power consumption in mA, 0 if 106 * selfpowered */ 107 uint8_t udi_bus; 108 uint8_t udi_addr; /* device address */ 109 uint8_t udi_index; /* device index */ 110 uint8_t udi_class; 111 uint8_t udi_subclass; 112 uint8_t udi_protocol; 113 uint8_t udi_config_no; /* current config number */ 114 uint8_t udi_config_index; /* current config index */ 115 uint8_t udi_speed; /* see "USB_SPEED_XXX" */ 116 uint8_t udi_mode; /* see "USB_MODE_XXX" */ 117 uint8_t udi_nports; 118 uint8_t udi_hubaddr; /* parent HUB address */ 119 uint8_t udi_hubindex; /* parent HUB device index */ 120 uint8_t udi_hubport; /* parent HUB port */ 121 uint8_t udi_power_mode; /* see "USB_POWER_MODE_XXX" */ 122 uint8_t udi_suspended; /* set if device is suspended */ 123 uint16_t udi_bustypeNo; 124 uint8_t udi_reserved[14]; /* leave space for the future */ 125 char udi_product[128]; 126 char udi_vendor[128]; 127 char udi_serial[64]; 128 char udi_release[8]; 129 }; 130 131 #define USB_DEVICE_PORT_PATH_MAX 32 132 133 struct usb_device_port_path { 134 uint8_t udp_bus; /* which bus we are on */ 135 uint8_t udp_index; /* which device index */ 136 uint8_t udp_port_level; /* how many levels: 0, 1, 2 ... */ 137 uint8_t udp_port_no[USB_DEVICE_PORT_PATH_MAX]; 138 }; 139 140 struct usb_device_stats { 141 uint32_t uds_requests_ok[4]; /* Indexed by transfer type UE_XXX */ 142 uint32_t uds_requests_fail[4]; /* Indexed by transfer type UE_XXX */ 143 }; 144 145 struct usb_fs_start { 146 uint8_t ep_index; 147 }; 148 149 struct usb_fs_stop { 150 uint8_t ep_index; 151 }; 152 153 struct usb_fs_complete { 154 uint8_t ep_index; 155 }; 156 157 /* This structure is used for all endpoint types */ 158 struct usb_fs_endpoint { 159 /* 160 * NOTE: isochronous USB transfer only use one buffer, but can have 161 * multiple frame lengths ! 162 */ 163 void **ppBuffer; /* pointer to userland buffers */ 164 uint32_t *pLength; /* pointer to frame lengths, updated 165 * to actual length */ 166 uint32_t nFrames; /* number of frames */ 167 uint32_t aFrames; /* actual number of frames */ 168 uint16_t flags; 169 /* a single short frame will terminate */ 170 #define USB_FS_FLAG_SINGLE_SHORT_OK 0x0001 171 /* multiple short frames are allowed */ 172 #define USB_FS_FLAG_MULTI_SHORT_OK 0x0002 173 /* all frame(s) transmitted are short terminated */ 174 #define USB_FS_FLAG_FORCE_SHORT 0x0004 175 /* will do a clear-stall before xfer */ 176 #define USB_FS_FLAG_CLEAR_STALL 0x0008 177 uint16_t timeout; /* in milliseconds */ 178 /* isocronous completion time in milliseconds - used for echo cancel */ 179 uint16_t isoc_time_complete; 180 /* timeout value for no timeout */ 181 #define USB_FS_TIMEOUT_NONE 0 182 int status; /* see USB_ERR_XXX */ 183 }; 184 185 struct usb_fs_init { 186 /* userland pointer to endpoints structure */ 187 struct usb_fs_endpoint *pEndpoints; 188 /* maximum number of endpoints */ 189 uint8_t ep_index_max; 190 }; 191 192 struct usb_fs_uninit { 193 uint8_t dummy; /* zero */ 194 }; 195 196 struct usb_fs_open { 197 #define USB_FS_MAX_BUFSIZE (1 << 25) /* 32 MBytes */ 198 uint32_t max_bufsize; 199 #define USB_FS_MAX_FRAMES (1U << 12) 200 #define USB_FS_MAX_FRAMES_PRE_SCALE (1U << 31) /* for ISOCHRONOUS transfers */ 201 uint32_t max_frames; /* read and write */ 202 uint16_t max_packet_length; /* read only */ 203 uint8_t dev_index; /* currently unused */ 204 uint8_t ep_index; 205 uint8_t ep_no; /* bEndpointNumber */ 206 }; 207 208 struct usb_fs_open_stream { 209 struct usb_fs_open fs_open; 210 uint16_t stream_id; /* stream ID */ 211 }; 212 213 struct usb_fs_close { 214 uint8_t ep_index; 215 }; 216 217 struct usb_fs_clear_stall_sync { 218 uint8_t ep_index; 219 }; 220 221 struct usb_gen_quirk { 222 uint16_t index; /* Quirk Index */ 223 uint16_t vid; /* Vendor ID */ 224 uint16_t pid; /* Product ID */ 225 uint16_t bcdDeviceLow; /* Low Device Revision */ 226 uint16_t bcdDeviceHigh; /* High Device Revision */ 227 uint16_t reserved[2]; 228 /* 229 * String version of quirk including terminating zero. See 230 * UQ_XXX in "usb_quirk.h". 231 */ 232 char quirkname[64 - 14]; 233 }; 234 235 /* USB controller */ 236 #define USB_REQUEST _IOWR('U', 1, struct usb_ctl_request) 237 #define USB_SETDEBUG _IOW ('U', 2, int) 238 #define USB_DISCOVER _IO ('U', 3) 239 #define USB_DEVICEINFO _IOWR('U', 4, struct usb_device_info) 240 #define USB_DEVICESTATS _IOR ('U', 5, struct usb_device_stats) 241 #define USB_DEVICEENUMERATE _IOW ('U', 6, int) 242 243 /* Generic HID device. Numbers 26 and 30-39 are occupied by hidraw. */ 244 #define USB_GET_REPORT_DESC _IOWR('U', 21, struct usb_gen_descriptor) 245 #define USB_SET_IMMED _IOW ('U', 22, int) 246 #define USB_GET_REPORT _IOWR('U', 23, struct usb_gen_descriptor) 247 #define USB_SET_REPORT _IOW ('U', 24, struct usb_gen_descriptor) 248 #define USB_GET_REPORT_ID _IOR ('U', 25, int) 249 250 /* Generic USB device */ 251 #define USB_GET_CONFIG _IOR ('U', 100, int) 252 #define USB_SET_CONFIG _IOW ('U', 101, int) 253 #define USB_GET_ALTINTERFACE _IOWR('U', 102, struct usb_alt_interface) 254 #define USB_SET_ALTINTERFACE _IOWR('U', 103, struct usb_alt_interface) 255 #define USB_GET_DEVICE_DESC _IOR ('U', 105, struct usb_device_descriptor) 256 #define USB_GET_CONFIG_DESC _IOR ('U', 106, struct usb_config_descriptor) 257 #define USB_GET_RX_INTERFACE_DESC _IOR ('U', 107, struct usb_interface_descriptor) 258 #define USB_GET_RX_ENDPOINT_DESC _IOR ('U', 108, struct usb_endpoint_descriptor) 259 #define USB_GET_FULL_DESC _IOWR('U', 109, struct usb_gen_descriptor) 260 #define USB_GET_STRING_DESC _IOWR('U', 110, struct usb_gen_descriptor) 261 #define USB_DO_REQUEST _IOWR('U', 111, struct usb_ctl_request) 262 #define USB_GET_DEVICEINFO _IOR ('U', 112, struct usb_device_info) 263 #define USB_SET_RX_SHORT_XFER _IOW ('U', 113, int) 264 #define USB_SET_RX_TIMEOUT _IOW ('U', 114, int) 265 #define USB_GET_RX_FRAME_SIZE _IOR ('U', 115, int) 266 #define USB_GET_RX_BUFFER_SIZE _IOR ('U', 117, int) 267 #define USB_SET_RX_BUFFER_SIZE _IOW ('U', 118, int) 268 #define USB_SET_RX_STALL_FLAG _IOW ('U', 119, int) 269 #define USB_SET_TX_STALL_FLAG _IOW ('U', 120, int) 270 #define USB_GET_IFACE_DRIVER _IOWR('U', 121, struct usb_gen_descriptor) 271 #define USB_CLAIM_INTERFACE _IOW ('U', 122, int) 272 #define USB_RELEASE_INTERFACE _IOW ('U', 123, int) 273 #define USB_IFACE_DRIVER_ACTIVE _IOW ('U', 124, int) 274 #define USB_IFACE_DRIVER_DETACH _IOW ('U', 125, int) 275 #define USB_GET_PLUGTIME _IOR ('U', 126, uint32_t) 276 #define USB_READ_DIR _IOW ('U', 127, struct usb_read_dir) 277 /* 128 - 133 unused */ 278 #define USB_GET_DEV_PORT_PATH _IOR ('U', 134, struct usb_device_port_path) 279 #define USB_GET_POWER_USAGE _IOR ('U', 135, int) 280 #define USB_SET_TX_FORCE_SHORT _IOW ('U', 136, int) 281 #define USB_SET_TX_TIMEOUT _IOW ('U', 137, int) 282 #define USB_GET_TX_FRAME_SIZE _IOR ('U', 138, int) 283 #define USB_GET_TX_BUFFER_SIZE _IOR ('U', 139, int) 284 #define USB_SET_TX_BUFFER_SIZE _IOW ('U', 140, int) 285 #define USB_GET_TX_INTERFACE_DESC _IOR ('U', 141, struct usb_interface_descriptor) 286 #define USB_GET_TX_ENDPOINT_DESC _IOR ('U', 142, struct usb_endpoint_descriptor) 287 #define USB_SET_PORT_ENABLE _IOW ('U', 143, int) 288 #define USB_SET_PORT_DISABLE _IOW ('U', 144, int) 289 #define USB_SET_POWER_MODE _IOW ('U', 145, int) 290 #define USB_GET_POWER_MODE _IOR ('U', 146, int) 291 #define USB_SET_TEMPLATE _IOW ('U', 147, int) 292 #define USB_GET_TEMPLATE _IOR ('U', 148, int) 293 294 /* Modem device */ 295 #define USB_GET_CM_OVER_DATA _IOR ('U', 180, int) 296 #define USB_SET_CM_OVER_DATA _IOW ('U', 181, int) 297 298 /* GPIO control */ 299 #define USB_GET_GPIO _IOR ('U', 182, int) 300 #define USB_SET_GPIO _IOW ('U', 183, int) 301 302 /* USB file system interface */ 303 #define USB_FS_START _IOW ('U', 192, struct usb_fs_start) 304 #define USB_FS_STOP _IOW ('U', 193, struct usb_fs_stop) 305 #define USB_FS_COMPLETE _IOR ('U', 194, struct usb_fs_complete) 306 #define USB_FS_INIT _IOW ('U', 195, struct usb_fs_init) 307 #define USB_FS_UNINIT _IOW ('U', 196, struct usb_fs_uninit) 308 #define USB_FS_OPEN _IOWR('U', 197, struct usb_fs_open) 309 #define USB_FS_CLOSE _IOW ('U', 198, struct usb_fs_close) 310 #define USB_FS_CLEAR_STALL_SYNC _IOW ('U', 199, struct usb_fs_clear_stall_sync) 311 #define USB_FS_OPEN_STREAM _IOWR('U', 200, struct usb_fs_open_stream) 312 313 /* USB quirk system interface */ 314 #define USB_DEV_QUIRK_GET _IOWR('Q', 0, struct usb_gen_quirk) 315 #define USB_QUIRK_NAME_GET _IOWR('Q', 1, struct usb_gen_quirk) 316 #define USB_DEV_QUIRK_ADD _IOW ('Q', 2, struct usb_gen_quirk) 317 #define USB_DEV_QUIRK_REMOVE _IOW ('Q', 3, struct usb_gen_quirk) 318 319 #ifdef _KERNEL 320 #ifdef COMPAT_FREEBSD32 321 322 struct usb_read_dir32 { 323 uint32_t urd_data; 324 uint32_t urd_startentry; 325 uint32_t urd_maxlen; 326 }; 327 #define USB_READ_DIR32 \ 328 _IOC_NEWTYPE(USB_READ_DIR, struct usb_read_dir32) 329 330 struct usb_ctl_request32 { 331 uint32_t ucr_data; 332 uint16_t ucr_flags; 333 uint16_t ucr_actlen; 334 uint8_t ucr_addr; 335 struct usb_device_request ucr_request; 336 }; 337 #define USB_REQUEST32 _IOC_NEWTYPE(USB_REQUEST, struct usb_ctl_request32) 338 #define USB_DO_REQUEST32 _IOC_NEWTYPE(USB_DO_REQUEST, struct usb_ctl_request32) 339 340 struct usb_gen_descriptor32 { 341 uint32_t ugd_data; /* void * */ 342 uint16_t ugd_lang_id; 343 uint16_t ugd_maxlen; 344 uint16_t ugd_actlen; 345 uint16_t ugd_offset; 346 uint8_t ugd_config_index; 347 uint8_t ugd_string_index; 348 uint8_t ugd_iface_index; 349 uint8_t ugd_altif_index; 350 uint8_t ugd_endpt_index; 351 uint8_t ugd_report_type; 352 uint8_t reserved[8]; 353 }; 354 355 #define USB_GET_REPORT_DESC32 \ 356 _IOC_NEWTYPE(USB_GET_REPORT_DESC, struct usb_gen_descriptor32) 357 #define USB_GET_REPORT32 \ 358 _IOC_NEWTYPE(USB_GET_REPORT, struct usb_gen_descriptor32) 359 #define USB_SET_REPORT32 \ 360 _IOC_NEWTYPE(USB_SET_REPORT, struct usb_gen_descriptor32) 361 #define USB_GET_FULL_DESC32 \ 362 _IOC_NEWTYPE(USB_GET_FULL_DESC, struct usb_gen_descriptor32) 363 #define USB_GET_STRING_DESC32 \ 364 _IOC_NEWTYPE(USB_GET_STRING_DESC, struct usb_gen_descriptor32) 365 #define USB_GET_IFACE_DRIVER32 \ 366 _IOC_NEWTYPE(USB_GET_IFACE_DRIVER, struct usb_gen_descriptor32) 367 368 void usb_gen_descriptor_from32(struct usb_gen_descriptor *ugd, 369 const struct usb_gen_descriptor32 *ugd32); 370 void update_usb_gen_descriptor32(struct usb_gen_descriptor32 *ugd32, 371 struct usb_gen_descriptor *ugd); 372 373 struct usb_fs_endpoint32 { 374 uint32_t ppBuffer; /* void ** */ 375 uint32_t pLength; /* uint32_t * */ 376 uint32_t nFrames; 377 uint32_t aFrames; 378 uint16_t flags; 379 uint16_t timeout; 380 uint16_t isoc_time_complete; 381 int status; 382 }; 383 384 struct usb_fs_init32 { 385 uint32_t pEndpoints; /* struct usb_fs_endpoint32 * */ 386 uint8_t ep_index_max; 387 }; 388 389 #define USB_FS_INIT32 _IOC_NEWTYPE(USB_FS_INIT, struct usb_fs_init32) 390 391 #endif /* COMPAT_FREEBSD32 */ 392 #endif /* _KERNEL */ 393 394 #endif /* _USB_IOCTL_H_ */ 395