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