1 | /** @file
|
---|
2 | * USBLIB - USB Support Library:
|
---|
3 | * This module implements the basic low-level OS interfaces for Windows hosts.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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
|
---|
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.
|
---|
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.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #ifndef ___VBox_usblib_win_h
|
---|
32 | #define ___VBox_usblib_win_h
|
---|
33 |
|
---|
34 | #include <VBox/cdefs.h>
|
---|
35 | #include <VBox/types.h>
|
---|
36 | #include <VBox/usb.h>
|
---|
37 |
|
---|
38 | #ifdef RT_OS_WINDOWS
|
---|
39 |
|
---|
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 |
|
---|
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 |
|
---|
53 | /*
|
---|
54 | * IOCtl numbers.
|
---|
55 | * We're using the Win32 type of numbers here, thus the macros below.
|
---|
56 | */
|
---|
57 |
|
---|
58 | #ifndef CTL_CODE
|
---|
59 | # if defined(RT_OS_WINDOWS)
|
---|
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
|
---|
78 | #define USBFLT_MINOR_VERSION 3
|
---|
79 |
|
---|
80 | #define USBMON_MAJOR_VERSION 1
|
---|
81 | #define USBMON_MINOR_VERSION 1
|
---|
82 |
|
---|
83 | #define USBDRV_MAJOR_VERSION 2
|
---|
84 | #define USBDRV_MINOR_VERSION 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)
|
---|
106 | #define SUPUSBFLT_IOCTL_CAPTURE_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x613, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
107 | #define SUPUSBFLT_IOCTL_RELEASE_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x614, METHOD_BUFFERED, FILE_WRITE_ACCESS)
|
---|
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;
|
---|
120 | uint8_t fHiSpeed;
|
---|
121 | } USBSUP_GETDEV, *PUSBSUP_GETDEV;
|
---|
122 |
|
---|
123 | typedef struct
|
---|
124 | {
|
---|
125 | uint32_t u32Major;
|
---|
126 | uint32_t u32Minor;
|
---|
127 | } USBSUP_VERSION, *PUSBSUP_VERSION;
|
---|
128 |
|
---|
129 | #endif /* RT_OS_WINDOWS */
|
---|
130 |
|
---|
131 | typedef struct USBSUP_FLTADDOUT
|
---|
132 | {
|
---|
133 | uintptr_t uId; /* The ID. */
|
---|
134 | int rc; /* The return code. */
|
---|
135 | } USBSUP_FLTADDOUT, *PUSBSUP_FLTADDOUT;
|
---|
136 |
|
---|
137 | typedef struct
|
---|
138 | {
|
---|
139 | uint16_t usVendorId;
|
---|
140 | uint16_t usProductId;
|
---|
141 | uint16_t usRevision;
|
---|
142 | } USBSUP_CAPTURE, *PUSBSUP_CAPTURE;
|
---|
143 |
|
---|
144 | typedef USBSUP_CAPTURE USBSUP_RELEASE;
|
---|
145 | typedef PUSBSUP_CAPTURE PUSBSUP_RELEASE;
|
---|
146 |
|
---|
147 | typedef struct
|
---|
148 | {
|
---|
149 | uint8_t bInterfaceNumber;
|
---|
150 | uint8_t fClaimed;
|
---|
151 | } USBSUP_CLAIMDEV, *PUSBSUP_CLAIMDEV;
|
---|
152 |
|
---|
153 | typedef USBSUP_CLAIMDEV USBSUP_RELEASEDEV;
|
---|
154 | typedef PUSBSUP_CLAIMDEV PUSBSUP_RELEASEDEV;
|
---|
155 |
|
---|
156 | typedef struct
|
---|
157 | {
|
---|
158 | uint32_t cUSBDevices;
|
---|
159 | } USBSUP_GETNUMDEV, *PUSBSUP_GETNUMDEV;
|
---|
160 |
|
---|
161 | typedef struct
|
---|
162 | {
|
---|
163 | uint8_t fUSBChange;
|
---|
164 | uint32_t cUSBStateChange;
|
---|
165 | } USBSUP_USB_CHANGE, *PUSBSUP_USB_CHANGE;
|
---|
166 |
|
---|
167 | typedef struct
|
---|
168 | {
|
---|
169 | uint8_t bConfigurationValue;
|
---|
170 | } USBSUP_SET_CONFIG, *PUSBSUP_SET_CONFIG;
|
---|
171 |
|
---|
172 | typedef struct
|
---|
173 | {
|
---|
174 | uint8_t bInterfaceNumber;
|
---|
175 | uint8_t bAlternateSetting;
|
---|
176 | } USBSUP_SELECT_INTERFACE, *PUSBSUP_SELECT_INTERFACE;
|
---|
177 |
|
---|
178 | typedef struct
|
---|
179 | {
|
---|
180 | uint8_t bEndpoint;
|
---|
181 | } USBSUP_CLEAR_ENDPOINT, *PUSBSUP_CLEAR_ENDPOINT;
|
---|
182 |
|
---|
183 | typedef enum
|
---|
184 | {
|
---|
185 | USBSUP_TRANSFER_TYPE_CTRL = 0,
|
---|
186 | USBSUP_TRANSFER_TYPE_ISOC = 1,
|
---|
187 | USBSUP_TRANSFER_TYPE_BULK = 2,
|
---|
188 | USBSUP_TRANSFER_TYPE_INTR = 3,
|
---|
189 | USBSUP_TRANSFER_TYPE_MSG = 4
|
---|
190 | } USBSUP_TRANSFER_TYPE;
|
---|
191 |
|
---|
192 | typedef enum
|
---|
193 | {
|
---|
194 | USBSUP_DIRECTION_SETUP = 0,
|
---|
195 | USBSUP_DIRECTION_IN = 1,
|
---|
196 | USBSUP_DIRECTION_OUT = 2
|
---|
197 | } USBSUP_DIRECTION;
|
---|
198 |
|
---|
199 |
|
---|
200 | typedef enum
|
---|
201 | {
|
---|
202 | USBSUP_XFER_OK = 0,
|
---|
203 | USBSUP_XFER_STALL = 1,
|
---|
204 | USBSUP_XFER_DNR = 2,
|
---|
205 | USBSUP_XFER_CRC = 3,
|
---|
206 | USBSUP_XFER_NAC = 4
|
---|
207 | } USBSUP_ERROR;
|
---|
208 |
|
---|
209 | typedef struct USBSUP_ISOCPKT
|
---|
210 | {
|
---|
211 | uint16_t cb; /* [in/out] packet size/size transferred */
|
---|
212 | uint16_t off; /* [in] offset of packet in buffer */
|
---|
213 | USBSUP_ERROR stat; /* [out] packet status */
|
---|
214 | } USBSUP_ISOCPKT;
|
---|
215 |
|
---|
216 | typedef struct
|
---|
217 | {
|
---|
218 | USBSUP_TRANSFER_TYPE type; /* [in] QUSB_TRANSFER_TYPE_XXX */
|
---|
219 | uint32_t ep; /* [in] index to dev->pipe */
|
---|
220 | USBSUP_DIRECTION dir; /* [in] QUSB_DIRECTION_XXX */
|
---|
221 | USBSUP_ERROR error; /* [out] QUSB_XFER_XXX */
|
---|
222 | size_t len; /* [in/out] may change */
|
---|
223 | void *buf; /* [in/out] depends on dir */
|
---|
224 | uint32_t numIsoPkts; /* [in] number of isochronous packets (8 max) */
|
---|
225 | USBSUP_ISOCPKT aIsoPkts[8]; /* [in/out] isochronous packet descriptors */
|
---|
226 | } USBSUP_URB, *PUSBSUP_URB;
|
---|
227 |
|
---|
228 | #pragma pack() /* paranoia */
|
---|
229 |
|
---|
230 |
|
---|
231 | __BEGIN_DECLS
|
---|
232 |
|
---|
233 | #ifdef IN_RING3
|
---|
234 |
|
---|
235 | /** @defgroup grp_usblib_r3 USBLIB Host Context Ring 3 API
|
---|
236 | * @{
|
---|
237 | */
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Return all attached USB devices.
|
---|
241 | *
|
---|
242 | * @returns VBox status code
|
---|
243 | * @param ppDevices Receives pointer to list of devices
|
---|
244 | * @param pcbNumDevices Number of USB devices in the list
|
---|
245 | */
|
---|
246 | USBLIB_DECL(int) USBLibGetDevices(PUSBDEVICE *ppDevices, uint32_t *pcbNumDevices);
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Check for USB device arrivals or removals
|
---|
250 | *
|
---|
251 | * @returns boolean
|
---|
252 | */
|
---|
253 | USBLIB_DECL(bool) USBLibHasPendingDeviceChanges(void);
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * Capture specified USB device
|
---|
257 | *
|
---|
258 | * @returns VBox status code
|
---|
259 | * @param usVendorId Vendor id
|
---|
260 | * @param usProductId Product id
|
---|
261 | * @param usRevision Revision
|
---|
262 | */
|
---|
263 | USBLIB_DECL(int) USBLibCaptureDevice(uint16_t usVendorId, uint16_t usProductId, uint16_t usRevision);
|
---|
264 |
|
---|
265 | /**
|
---|
266 | * Release specified USB device to the host.
|
---|
267 | *
|
---|
268 | * @returns VBox status code
|
---|
269 | * @param usVendorId Vendor id
|
---|
270 | * @param usProductId Product id
|
---|
271 | * @param usRevision Revision
|
---|
272 | */
|
---|
273 | USBLIB_DECL(int) USBLibReleaseDevice(uint16_t usVendorId, uint16_t usProductId, uint16_t usRevision);
|
---|
274 |
|
---|
275 | /** @} */
|
---|
276 | #endif
|
---|
277 |
|
---|
278 | /** @} */
|
---|
279 |
|
---|
280 | __END_DECLS
|
---|
281 |
|
---|
282 |
|
---|
283 | #endif
|
---|
284 |
|
---|