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