[1] | 1 | /** @file
|
---|
| 2 | * USBLIB - USB Support Library:
|
---|
| 3 | * This module implements the basic low-level OS interfaces for Windows hosts.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[8155] | 7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
[1] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 16 | *
|
---|
| 17 | * The contents of this file may alternatively be used under the terms
|
---|
| 18 | * of the Common Development and Distribution License Version 1.0
|
---|
| 19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
| 20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
| 21 | * CDDL are applicable instead of those of the GPL.
|
---|
| 22 | *
|
---|
| 23 | * You may elect to license modified versions of this file under the
|
---|
| 24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[8155] | 25 | *
|
---|
| 26 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
| 27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
| 28 | * additional information or have any questions.
|
---|
[1] | 29 | */
|
---|
| 30 |
|
---|
[5563] | 31 | #ifndef ___VBox_usblib_win_h
|
---|
| 32 | #define ___VBox_usblib_win_h
|
---|
[1] | 33 |
|
---|
| 34 | #include <VBox/cdefs.h>
|
---|
| 35 | #include <VBox/types.h>
|
---|
| 36 | #include <VBox/usb.h>
|
---|
| 37 |
|
---|
[3758] | 38 | #ifdef RT_OS_WINDOWS
|
---|
| 39 |
|
---|
[1] | 40 | #include <initguid.h>
|
---|
| 41 | // {6068EB61-98E7-4c98-9E20-1F068295909A}
|
---|
| 42 | DEFINE_GUID(GUID_CLASS_VBOXUSB, 0x873fdf, 0xCAFE, 0x80EE, 0xaa, 0x5e, 0x0, 0xc0, 0x4f, 0xb1, 0x72, 0xb);
|
---|
| 43 |
|
---|
| 44 | #define USBFLT_SERVICE_NAME "\\\\.\\VBoxUSBFlt"
|
---|
| 45 | #define USBFLT_NTDEVICE_NAME_STRING L"\\Device\\VBoxUSBFlt"
|
---|
| 46 | #define USBFLT_SYMBOLIC_NAME_STRING L"\\DosDevices\\VBoxUSBFlt"
|
---|
| 47 |
|
---|
[2575] | 48 | #define USBMON_SERVICE_NAME "VBoxUSBMon"
|
---|
| 49 | #define USBMON_DEVICE_NAME "\\\\.\\VBoxUSBMon"
|
---|
| 50 | #define USBMON_DEVICE_NAME_NT L"\\Device\\VBoxUSBMon"
|
---|
| 51 | #define USBMON_DEVICE_NAME_DOS L"\\DosDevices\\VBoxUSBMon"
|
---|
| 52 |
|
---|
[1] | 53 | /*
|
---|
| 54 | * IOCtl numbers.
|
---|
| 55 | * We're using the Win32 type of numbers here, thus the macros below.
|
---|
| 56 | */
|
---|
| 57 |
|
---|
| 58 | #ifndef CTL_CODE
|
---|
[3638] | 59 | # if defined(RT_OS_WINDOWS)
|
---|
[1] | 60 | # define CTL_CODE(DeviceType, Function, Method, Access) \
|
---|
| 61 | ( ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
|
---|
| 62 | #else /* unix: */
|
---|
| 63 | # define CTL_CODE(DeviceType, Function, Method_ignored, Access_ignored) \
|
---|
| 64 | ( (3 << 30) | ((DeviceType) << 8) | (Function) | (sizeof(SUPDRVIOCTLDATA) << 16) )
|
---|
| 65 | # endif
|
---|
| 66 | #endif
|
---|
| 67 | #ifndef METHOD_BUFFERED
|
---|
| 68 | # define METHOD_BUFFERED 0
|
---|
| 69 | #endif
|
---|
| 70 | #ifndef FILE_WRITE_ACCESS
|
---|
| 71 | # define FILE_WRITE_ACCESS 0x0002
|
---|
| 72 | #endif
|
---|
| 73 | #ifndef FILE_DEVICE_UNKNOWN
|
---|
| 74 | # define FILE_DEVICE_UNKNOWN 0x00000022
|
---|
| 75 | #endif
|
---|
| 76 |
|
---|
| 77 | #define USBFLT_MAJOR_VERSION 1
|
---|
[2648] | 78 | #define USBFLT_MINOR_VERSION 2
|
---|
[1] | 79 |
|
---|
[2625] | 80 | #define USBMON_MAJOR_VERSION 1
|
---|
[2838] | 81 | #define USBMON_MINOR_VERSION 1
|
---|
[2625] | 82 |
|
---|
[6591] | 83 | #define USBDRV_MAJOR_VERSION 2
|
---|
[7790] | 84 | #define USBDRV_MINOR_VERSION 1
|
---|
[1] | 85 |
|
---|
| 86 | #define SUPUSB_IOCTL_TEST CTL_CODE(FILE_DEVICE_UNKNOWN, 0x601, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 87 | #define SUPUSB_IOCTL_GET_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x603, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 88 | #define SUPUSB_IOCTL_SEND_URB CTL_CODE(FILE_DEVICE_UNKNOWN, 0x607, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 89 | #define SUPUSB_IOCTL_USB_RESET CTL_CODE(FILE_DEVICE_UNKNOWN, 0x608, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 90 | #define SUPUSB_IOCTL_USB_SELECT_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x609, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 91 | #define SUPUSB_IOCTL_USB_SET_CONFIG CTL_CODE(FILE_DEVICE_UNKNOWN, 0x60A, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 92 | #define SUPUSB_IOCTL_USB_CLAIM_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x60B, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 93 | #define SUPUSB_IOCTL_USB_RELEASE_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x60C, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 94 | #define SUPUSB_IOCTL_IS_OPERATIONAL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x60D, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 95 | #define SUPUSB_IOCTL_USB_CLEAR_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN, 0x60E, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 96 | #define SUPUSB_IOCTL_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, 0x60F, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 97 |
|
---|
| 98 | #define SUPUSBFLT_IOCTL_GET_NUM_DEVICES CTL_CODE(FILE_DEVICE_UNKNOWN, 0x602, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 99 | #define SUPUSBFLT_IOCTL_USB_CHANGE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x604, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 100 | #define SUPUSBFLT_IOCTL_DISABLE_CAPTURE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x605, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 101 | #define SUPUSBFLT_IOCTL_ENABLE_CAPTURE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x606, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 102 | #define SUPUSBFLT_IOCTL_IGNORE_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x60F, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 103 | #define SUPUSBFLT_IOCTL_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, 0x610, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 104 | #define SUPUSBFLT_IOCTL_ADD_FILTER CTL_CODE(FILE_DEVICE_UNKNOWN, 0x611, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
| 105 | #define SUPUSBFLT_IOCTL_REMOVE_FILTER CTL_CODE(FILE_DEVICE_UNKNOWN, 0x612, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
[2664] | 106 | #define SUPUSBFLT_IOCTL_CAPTURE_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x613, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
[2838] | 107 | #define SUPUSBFLT_IOCTL_RELEASE_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x614, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
[1] | 108 |
|
---|
| 109 | #pragma pack(4)
|
---|
| 110 |
|
---|
| 111 | #define MAX_FILTER_NAME 128
|
---|
| 112 | #define MAX_USB_SERIAL_STRING 64
|
---|
| 113 |
|
---|
| 114 | typedef struct
|
---|
| 115 | {
|
---|
| 116 | uint16_t vid, did, rev;
|
---|
| 117 | char serial_hash[MAX_USB_SERIAL_STRING];
|
---|
| 118 |
|
---|
| 119 | uint8_t fAttached;
|
---|
[7788] | 120 | uint8_t fHiSpeed;
|
---|
[1] | 121 | } USBSUP_GETDEV, *PUSBSUP_GETDEV;
|
---|
| 122 |
|
---|
| 123 | typedef struct
|
---|
| 124 | {
|
---|
| 125 | uint32_t u32Major;
|
---|
| 126 | uint32_t u32Minor;
|
---|
| 127 | } USBSUP_VERSION, *PUSBSUP_VERSION;
|
---|
| 128 |
|
---|
[3758] | 129 | #endif /* RT_OS_WINDOWS */
|
---|
| 130 |
|
---|
[1] | 131 | #define MAX_VENDOR_NAME 16
|
---|
| 132 | #define MAX_PRODUCT_NAME MAX_VENDOR_NAME
|
---|
| 133 | #define MAX_REVISION_NAME MAX_VENDOR_NAME
|
---|
| 134 |
|
---|
| 135 | typedef struct
|
---|
| 136 | {
|
---|
| 137 | char szVendor[MAX_VENDOR_NAME];
|
---|
| 138 | char szProduct[MAX_PRODUCT_NAME];
|
---|
| 139 | char szRevision[MAX_REVISION_NAME];
|
---|
| 140 | uintptr_t id;
|
---|
| 141 | } USBSUP_FILTER, *PUSBSUP_FILTER;
|
---|
| 142 |
|
---|
[2664] | 143 |
|
---|
[1] | 144 | typedef struct
|
---|
| 145 | {
|
---|
[2664] | 146 | USHORT usVendorId;
|
---|
| 147 | USHORT usProductId;
|
---|
| 148 | USHORT usRevision;
|
---|
[2666] | 149 | } USBSUP_CAPTURE, *PUSBSUP_CAPTURE;
|
---|
[2664] | 150 |
|
---|
[2838] | 151 | typedef USBSUP_CAPTURE USBSUP_RELEASE;
|
---|
| 152 | typedef PUSBSUP_CAPTURE PUSBSUP_RELEASE;
|
---|
[2664] | 153 |
|
---|
| 154 | typedef struct
|
---|
| 155 | {
|
---|
[1] | 156 | uint8_t bInterfaceNumber;
|
---|
| 157 | uint8_t fClaimed;
|
---|
| 158 | } USBSUP_CLAIMDEV, *PUSBSUP_CLAIMDEV;
|
---|
| 159 |
|
---|
| 160 | typedef USBSUP_CLAIMDEV USBSUP_RELEASEDEV;
|
---|
| 161 | typedef PUSBSUP_CLAIMDEV PUSBSUP_RELEASEDEV;
|
---|
| 162 |
|
---|
| 163 | typedef struct
|
---|
| 164 | {
|
---|
| 165 | uint32_t cUSBDevices;
|
---|
| 166 | } USBSUP_GETNUMDEV, *PUSBSUP_GETNUMDEV;
|
---|
| 167 |
|
---|
| 168 | typedef struct
|
---|
| 169 | {
|
---|
| 170 | uint8_t fUSBChange;
|
---|
[2624] | 171 | uint32_t cUSBStateChange;
|
---|
[1] | 172 | } USBSUP_USB_CHANGE, *PUSBSUP_USB_CHANGE;
|
---|
| 173 |
|
---|
| 174 | typedef struct
|
---|
| 175 | {
|
---|
| 176 | uint8_t bConfigurationValue;
|
---|
| 177 | } USBSUP_SET_CONFIG, *PUSBSUP_SET_CONFIG;
|
---|
| 178 |
|
---|
| 179 | typedef struct
|
---|
| 180 | {
|
---|
| 181 | uint8_t bInterfaceNumber;
|
---|
| 182 | uint8_t bAlternateSetting;
|
---|
| 183 | } USBSUP_SELECT_INTERFACE, *PUSBSUP_SELECT_INTERFACE;
|
---|
| 184 |
|
---|
| 185 | typedef struct
|
---|
| 186 | {
|
---|
| 187 | uint8_t bEndpoint;
|
---|
| 188 | } USBSUP_CLEAR_ENDPOINT, *PUSBSUP_CLEAR_ENDPOINT;
|
---|
| 189 |
|
---|
| 190 | typedef enum
|
---|
| 191 | {
|
---|
| 192 | USBSUP_TRANSFER_TYPE_CTRL = 0,
|
---|
| 193 | USBSUP_TRANSFER_TYPE_ISOC = 1,
|
---|
| 194 | USBSUP_TRANSFER_TYPE_BULK = 2,
|
---|
| 195 | USBSUP_TRANSFER_TYPE_INTR = 3,
|
---|
| 196 | USBSUP_TRANSFER_TYPE_MSG = 4
|
---|
| 197 | } USBSUP_TRANSFER_TYPE;
|
---|
| 198 |
|
---|
| 199 | typedef enum
|
---|
| 200 | {
|
---|
| 201 | USBSUP_DIRECTION_SETUP = 0,
|
---|
| 202 | USBSUP_DIRECTION_IN = 1,
|
---|
| 203 | USBSUP_DIRECTION_OUT = 2
|
---|
| 204 | } USBSUP_DIRECTION;
|
---|
| 205 |
|
---|
| 206 |
|
---|
| 207 | typedef enum
|
---|
| 208 | {
|
---|
| 209 | USBSUP_XFER_OK = 0,
|
---|
| 210 | USBSUP_XFER_STALL = 1,
|
---|
| 211 | USBSUP_XFER_DNR = 2,
|
---|
[6476] | 212 | USBSUP_XFER_CRC = 3,
|
---|
| 213 | USBSUP_XFER_NAC = 4
|
---|
[1] | 214 | } USBSUP_ERROR;
|
---|
| 215 |
|
---|
[6591] | 216 | typedef struct USBSUP_ISOCPKT
|
---|
| 217 | {
|
---|
| 218 | uint16_t cb; /* [in/out] packet size/size transferred */
|
---|
| 219 | uint16_t off; /* [in] offset of packet in buffer */
|
---|
| 220 | USBSUP_ERROR stat; /* [out] packet status */
|
---|
| 221 | } USBSUP_ISOCPKT;
|
---|
| 222 |
|
---|
[1] | 223 | typedef struct
|
---|
| 224 | {
|
---|
[6591] | 225 | USBSUP_TRANSFER_TYPE type; /* [in] QUSB_TRANSFER_TYPE_XXX */
|
---|
| 226 | uint32_t ep; /* [in] index to dev->pipe */
|
---|
| 227 | USBSUP_DIRECTION dir; /* [in] QUSB_DIRECTION_XXX */
|
---|
| 228 | USBSUP_ERROR error; /* [out] QUSB_XFER_XXX */
|
---|
| 229 | size_t len; /* [in/out] may change */
|
---|
| 230 | void *buf; /* [in/out] depends on dir */
|
---|
| 231 | uint32_t numIsoPkts; /* [in] number of isochronous packets (8 max) */
|
---|
| 232 | USBSUP_ISOCPKT aIsoPkts[8]; /* [in/out] isochronous packet descriptors */
|
---|
[1] | 233 | } USBSUP_URB, *PUSBSUP_URB;
|
---|
| 234 |
|
---|
| 235 | #pragma pack() /* paranoia */
|
---|
| 236 |
|
---|
| 237 |
|
---|
| 238 | __BEGIN_DECLS
|
---|
| 239 |
|
---|
| 240 | #ifdef IN_RING3
|
---|
| 241 |
|
---|
| 242 | /** @defgroup grp_usblib_r3 USBLIB Host Context Ring 3 API
|
---|
| 243 | * @{
|
---|
| 244 | */
|
---|
| 245 |
|
---|
[1569] | 246 | /**
|
---|
[1] | 247 | * Initialize the USB library
|
---|
| 248 | *
|
---|
| 249 | * @returns VBox status code.
|
---|
| 250 | */
|
---|
[1569] | 251 | VBOXDDU_DECL(int) usbLibInit();
|
---|
[1] | 252 |
|
---|
[1569] | 253 | /**
|
---|
[1] | 254 | * Terminate the USB library
|
---|
| 255 | *
|
---|
| 256 | * @returns VBox status code.
|
---|
| 257 | */
|
---|
[1569] | 258 | VBOXDDU_DECL(int) usbLibTerm();
|
---|
[1] | 259 |
|
---|
[1569] | 260 | /**
|
---|
[1] | 261 | * Add USB device filter
|
---|
| 262 | *
|
---|
| 263 | * @returns VBox status code.
|
---|
| 264 | * @param pszVendor Vendor filter string
|
---|
| 265 | * @param pszProduct Product filter string
|
---|
| 266 | * @param pszRevision Revision filter string
|
---|
| 267 | * @param ppID Pointer to filter id
|
---|
| 268 | */
|
---|
[1569] | 269 | VBOXDDU_DECL(int) usbLibInsertFilter(const char *pszVendor, const char *pszProduct, const char *pszRevision, void **ppID);
|
---|
[1] | 270 |
|
---|
[1569] | 271 | /**
|
---|
[1] | 272 | * Remove USB device filter
|
---|
| 273 | *
|
---|
| 274 | * @returns VBox status code.
|
---|
| 275 | * @param aID Filter id
|
---|
| 276 | */
|
---|
[1569] | 277 | VBOXDDU_DECL(int) usbLibRemoveFilter (void *aID);
|
---|
[1] | 278 |
|
---|
[1569] | 279 | /**
|
---|
[1] | 280 | * Return all attached USB devices.
|
---|
| 281 | *
|
---|
| 282 | * @returns VBox status code
|
---|
| 283 | * @param ppDevices Receives pointer to list of devices
|
---|
| 284 | * @param pcbNumDevices Number of USB devices in the list
|
---|
| 285 | */
|
---|
[1569] | 286 | VBOXDDU_DECL(int) usbLibGetDevices(PUSBDEVICE *ppDevices, uint32_t *pcbNumDevices);
|
---|
[1] | 287 |
|
---|
[1569] | 288 | /**
|
---|
[1] | 289 | * Check for USB device arrivals or removals
|
---|
| 290 | *
|
---|
| 291 | * @returns boolean
|
---|
| 292 | */
|
---|
[1569] | 293 | VBOXDDU_DECL(bool) usbLibHasPendingDeviceChanges();
|
---|
[1] | 294 |
|
---|
[2648] | 295 |
|
---|
| 296 | /**
|
---|
[2659] | 297 | * Capture specified USB device
|
---|
[2648] | 298 | *
|
---|
[2658] | 299 | * @returns VBox status code
|
---|
| 300 | * @param usVendorId Vendor id
|
---|
| 301 | * @param usProductId Product id
|
---|
| 302 | * @param usRevision Revision
|
---|
[2648] | 303 | */
|
---|
[2658] | 304 | VBOXDDU_DECL(int) usbLibCaptureDevice(USHORT usVendorId, USHORT usProductId, USHORT usRevision);
|
---|
[2648] | 305 |
|
---|
[2836] | 306 | /**
|
---|
| 307 | * Release specified USB device to the host.
|
---|
| 308 | *
|
---|
| 309 | * @returns VBox status code
|
---|
| 310 | * @param usVendorId Vendor id
|
---|
| 311 | * @param usProductId Product id
|
---|
| 312 | * @param usRevision Revision
|
---|
| 313 | */
|
---|
[2847] | 314 | VBOXDDU_DECL(int) usbLibReleaseDevice(USHORT usVendorId, USHORT usProductId, USHORT usRevision);
|
---|
[2836] | 315 |
|
---|
[2844] | 316 |
|
---|
[1] | 317 | /** @} */
|
---|
| 318 | #endif
|
---|
| 319 |
|
---|
| 320 | /** @} */
|
---|
| 321 |
|
---|
| 322 | __END_DECLS
|
---|
| 323 |
|
---|
| 324 |
|
---|
| 325 | #endif
|
---|
| 326 |
|
---|