VirtualBox

source: vbox/trunk/include/VBox/usblib.h@ 3758

Last change on this file since 3758 was 3758, checked in by vboxsync, 17 years ago

More USBFILTER changes.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette