VirtualBox

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

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

Biggest check-in ever. New source code headers for all (C) innotek files.

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