1 | /** @file
|
---|
2 | * USB - Universal Serial Bus.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | *
|
---|
25 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___VBox_usb_h
|
---|
31 | #define ___VBox_usb_h
|
---|
32 |
|
---|
33 | #include <VBox/types.h>
|
---|
34 |
|
---|
35 | __BEGIN_DECLS
|
---|
36 |
|
---|
37 | #ifdef USBDEVICE_WITH_EVERYTHING
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * USB device interface endpoint.
|
---|
41 | */
|
---|
42 | typedef struct USBENDPOINT
|
---|
43 | {
|
---|
44 | /** The address of the endpoint on the USB device described by this descriptor. */
|
---|
45 | uint8_t bEndpointAddress;
|
---|
46 | /** This field describes the endpoint's attributes when it is configured using the bConfigurationValue. */
|
---|
47 | uint8_t bmAttributes;
|
---|
48 | /** Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. */
|
---|
49 | uint16_t wMaxPacketSize;
|
---|
50 | /** Interval for polling endpoint for data transfers. Expressed in milliseconds.
|
---|
51 | * This is interpreted the bInterval value. */
|
---|
52 | uint16_t u16Interval;
|
---|
53 | } USBENDPOINT;
|
---|
54 | /** Pointer to a USB device interface endpoint. */
|
---|
55 | typedef USBENDPOINT *PUSBENDPOINT;
|
---|
56 | /** Pointer to a const USB device interface endpoint. */
|
---|
57 | typedef const USBENDPOINT *PCUSBENDPOINT;
|
---|
58 |
|
---|
59 | /** USBENDPOINT::bmAttributes values.
|
---|
60 | * @{ */
|
---|
61 | #define USB_EP_ATTR_CONTROL 0
|
---|
62 | #define USB_EP_ATTR_ISOCHRONOUS 1
|
---|
63 | #define USB_EP_ATTR_BULK 2
|
---|
64 | #define USB_EP_ATTR_INTERRUPT 3
|
---|
65 | /** @} */
|
---|
66 |
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * USB device interface.
|
---|
70 | */
|
---|
71 | typedef struct USBINTERFACE
|
---|
72 | {
|
---|
73 | /** Number of interface. */
|
---|
74 | uint8_t bInterfaceNumber;
|
---|
75 | /** Value used to select alternate setting for the interface identified in the prior field. */
|
---|
76 | uint8_t bAlternateSetting;
|
---|
77 | /** Number of endpoints used by this interface (excluding endpoint zero). */
|
---|
78 | uint8_t bNumEndpoints;
|
---|
79 | /** Pointer to an array of endpoints. */
|
---|
80 | PUSBENDPOINT paEndpoints;
|
---|
81 | /** Interface class. */
|
---|
82 | uint8_t bInterfaceClass;
|
---|
83 | /** Interface subclass. */
|
---|
84 | uint8_t bInterfaceSubClass;
|
---|
85 | /** Protocol code. */
|
---|
86 | uint8_t bInterfaceProtocol;
|
---|
87 | /** Number of alternate settings. */
|
---|
88 | uint8_t cAlts;
|
---|
89 | /** Pointer to an array of alternate interface settings. */
|
---|
90 | struct USBINTERFACE *paAlts;
|
---|
91 | /** String describing this interface. */
|
---|
92 | const char *pszInterface;
|
---|
93 | /** String containing the driver name.
|
---|
94 | * This is a NULL pointer if the interface is not in use. */
|
---|
95 | const char *pszDriver;
|
---|
96 | } USBINTERFACE;
|
---|
97 | /** Pointer to a USB device interface description. */
|
---|
98 | typedef USBINTERFACE *PUSBINTERFACE;
|
---|
99 | /** Pointer to a const USB device interface description. */
|
---|
100 | typedef const USBINTERFACE *PCUSBINTERFACE;
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Device configuration.
|
---|
104 | */
|
---|
105 | typedef struct USBCONFIG
|
---|
106 | {
|
---|
107 | /** Set if this is the active configuration. */
|
---|
108 | bool fActive;
|
---|
109 | /** Number of interfaces. */
|
---|
110 | uint8_t bNumInterfaces;
|
---|
111 | /** Pointer to an array of interfaces. */
|
---|
112 | PUSBINTERFACE paInterfaces;
|
---|
113 | /** Configuration number. (For SetConfiguration().) */
|
---|
114 | uint8_t bConfigurationValue;
|
---|
115 | /** Configuration description string. */
|
---|
116 | const char *pszConfiguration;
|
---|
117 | /** Configuration characteristics. */
|
---|
118 | uint8_t bmAttributes;
|
---|
119 | /** Maximum power consumption of the USB device in this config.
|
---|
120 | * (This field does NOT need shifting like in the USB config descriptor.) */
|
---|
121 | uint16_t u16MaxPower;
|
---|
122 | } USBCONFIG;
|
---|
123 | /** Pointer to a USB configuration. */
|
---|
124 | typedef USBCONFIG *PUSBCONFIG;
|
---|
125 | /** Pointer to a const USB configuration. */
|
---|
126 | typedef const USBCONFIG *PCUSBCONFIG;
|
---|
127 |
|
---|
128 | #endif /* USBDEVICE_WITH_EVERYTHING */
|
---|
129 |
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * The USB host device state.
|
---|
133 | */
|
---|
134 | typedef enum USBDEVICESTATE
|
---|
135 | {
|
---|
136 | /** The device is unsupported. */
|
---|
137 | USBDEVICESTATE_UNSUPPORTED = 1,
|
---|
138 | /** The device is in use by the host. */
|
---|
139 | USBDEVICESTATE_USED_BY_HOST,
|
---|
140 | /** The device is in use by the host but could perhaps be captured even so. */
|
---|
141 | USBDEVICESTATE_USED_BY_HOST_CAPTURABLE,
|
---|
142 | /** The device is not used by the host or any guest. */
|
---|
143 | USBDEVICESTATE_UNUSED,
|
---|
144 | /** The device is held by the proxy for later guest usage. */
|
---|
145 | USBDEVICESTATE_HELD_BY_PROXY,
|
---|
146 | /** The device in use by a guest. */
|
---|
147 | USBDEVICESTATE_USED_BY_GUEST,
|
---|
148 | /** The usual 32-bit hack. */
|
---|
149 | USBDEVICESTATE_32BIT_HACK = 0x7fffffff
|
---|
150 | } USBDEVICESTATE;
|
---|
151 |
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * The USB device speed.
|
---|
155 | */
|
---|
156 | typedef enum USBDEVICESPEED
|
---|
157 | {
|
---|
158 | /** Unknown. */
|
---|
159 | USBDEVICESPEED_UNKNOWN = 0,
|
---|
160 | /** Low speed (1.5 Mbit/s). */
|
---|
161 | USBDEVICESPEED_LOW,
|
---|
162 | /** Full speed (12 Mbit/s). */
|
---|
163 | USBDEVICESPEED_FULL,
|
---|
164 | /** High speed (480 Mbit/s). */
|
---|
165 | USBDEVICESPEED_HIGH,
|
---|
166 | /** Variable speed - USB 2.5 / wireless. */
|
---|
167 | USBDEVICESPEED_VARIABLE,
|
---|
168 | /** The usual 32-bit hack. */
|
---|
169 | USBDEVICESPEED_32BIT_HACK = 0x7fffffff
|
---|
170 | } USBDEVICESPEED;
|
---|
171 |
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * USB host device description.
|
---|
175 | * Used for enumeration of USB devices.
|
---|
176 | */
|
---|
177 | typedef struct USBDEVICE
|
---|
178 | {
|
---|
179 | /** If linked, this is the pointer to the next device in the list. */
|
---|
180 | struct USBDEVICE *pNext;
|
---|
181 | /** If linked doubly, this is the pointer to the prev device in the list. */
|
---|
182 | struct USBDEVICE *pPrev;
|
---|
183 | /** Manufacturer string. */
|
---|
184 | const char *pszManufacturer;
|
---|
185 | /** Product string. */
|
---|
186 | const char *pszProduct;
|
---|
187 | /** Serial number string. */
|
---|
188 | const char *pszSerialNumber;
|
---|
189 | /** The address of the device. */
|
---|
190 | const char *pszAddress;
|
---|
191 |
|
---|
192 | /** Vendor ID. */
|
---|
193 | uint16_t idVendor;
|
---|
194 | /** Product ID. */
|
---|
195 | uint16_t idProduct;
|
---|
196 | /** Revision, integer part. */
|
---|
197 | uint16_t bcdDevice;
|
---|
198 | /** USB version number. */
|
---|
199 | uint16_t bcdUSB;
|
---|
200 | /** Device class. */
|
---|
201 | uint8_t bDeviceClass;
|
---|
202 | /** Device subclass. */
|
---|
203 | uint8_t bDeviceSubClass;
|
---|
204 | /** Device protocol */
|
---|
205 | uint8_t bDeviceProtocol;
|
---|
206 | /** Number of configurations. */
|
---|
207 | uint8_t bNumConfigurations;
|
---|
208 | /** The device state. */
|
---|
209 | USBDEVICESTATE enmState;
|
---|
210 | /** The device speed. */
|
---|
211 | USBDEVICESPEED enmSpeed;
|
---|
212 | /** Serial hash. */
|
---|
213 | uint64_t u64SerialHash;
|
---|
214 | /** The USB Bus number. */
|
---|
215 | uint8_t bBus;
|
---|
216 | /** The port number. */
|
---|
217 | uint8_t bPort;
|
---|
218 | #if defined(RT_OS_LINUX)
|
---|
219 | /** Device number. */
|
---|
220 | uint8_t bDevNum;
|
---|
221 | #endif
|
---|
222 | #ifdef USBDEVICE_WITH_EVERYTHING
|
---|
223 | /** Parent device number. */
|
---|
224 | uint8_t bDevNumParent;
|
---|
225 | /** The level in topologly for this bus. */
|
---|
226 | uint8_t bLevel;
|
---|
227 | /** Number of devices on this level. */
|
---|
228 | uint8_t bNumDevices;
|
---|
229 | /** Maximum number of children. */
|
---|
230 | uint8_t bMaxChildren;
|
---|
231 | /** Pointer to an array of configurations. */
|
---|
232 | PUSBCONFIG paConfigurations;
|
---|
233 | #endif
|
---|
234 | #ifdef RT_OS_WINDOWS
|
---|
235 | /** Alternate address. Can be NULL. */
|
---|
236 | char *pszAltAddress;
|
---|
237 | /** The hub name. */
|
---|
238 | char *pszHubName;
|
---|
239 | #endif
|
---|
240 | } USBDEVICE;
|
---|
241 | /** Pointer to a USB device. */
|
---|
242 | typedef USBDEVICE *PUSBDEVICE;
|
---|
243 | /** Pointer to a const USB device. */
|
---|
244 | typedef USBDEVICE *PCUSBDEVICE;
|
---|
245 |
|
---|
246 |
|
---|
247 | #ifdef VBOX_USB_H_INCL_DESCRIPTORS /* for the time being, since this may easily conflict with system headers */
|
---|
248 |
|
---|
249 | /**
|
---|
250 | * USB device descriptor.
|
---|
251 | */
|
---|
252 | #pragma pack(1)
|
---|
253 | typedef struct USBDESCHDR
|
---|
254 | {
|
---|
255 | /** The descriptor length. */
|
---|
256 | uint8_t bLength;
|
---|
257 | /** The descriptor type. */
|
---|
258 | uint8_t bDescriptorType;
|
---|
259 | } USBDESCHDR;
|
---|
260 | #pragma pack()
|
---|
261 | /** Pointer to an USB descriptor header. */
|
---|
262 | typedef USBDESCHDR *PUSBDESCHDR;
|
---|
263 |
|
---|
264 | /** @name Descriptor Type values (bDescriptorType)
|
---|
265 | * {@ */
|
---|
266 | #if !defined(USB_DT_DEVICE) && !defined(USB_DT_ENDPOINT)
|
---|
267 | # define USB_DT_DEVICE 0x01
|
---|
268 | # define USB_DT_CONFIG 0x02
|
---|
269 | # define USB_DT_STRING 0x03
|
---|
270 | # define USB_DT_INTERFACE 0x04
|
---|
271 | # define USB_DT_ENDPOINT 0x05
|
---|
272 |
|
---|
273 | # define USB_DT_HID 0x21
|
---|
274 | # define USB_DT_REPORT 0x22
|
---|
275 | # define USB_DT_PHYSICAL 0x23
|
---|
276 | # define USB_DT_HUB 0x29
|
---|
277 | #endif
|
---|
278 | /** @} */
|
---|
279 |
|
---|
280 |
|
---|
281 | /**
|
---|
282 | * USB device descriptor.
|
---|
283 | */
|
---|
284 | #pragma pack(1)
|
---|
285 | typedef struct USBDEVICEDESC
|
---|
286 | {
|
---|
287 | /** The descriptor length. (Usually sizeof(USBDEVICEDESC).) */
|
---|
288 | uint8_t bLength;
|
---|
289 | /** The descriptor type. (USB_DT_DEVICE) */
|
---|
290 | uint8_t bDescriptorType;
|
---|
291 | /** USB version number. */
|
---|
292 | uint16_t bcdUSB;
|
---|
293 | /** Device class. */
|
---|
294 | uint8_t bDeviceClass;
|
---|
295 | /** Device subclass. */
|
---|
296 | uint8_t bDeviceSubClass;
|
---|
297 | /** Device protocol */
|
---|
298 | uint8_t bDeviceProtocol;
|
---|
299 | /** The max packet size of the default control pipe. */
|
---|
300 | uint8_t bMaxPacketSize0;
|
---|
301 | /** Vendor ID. */
|
---|
302 | uint16_t idVendor;
|
---|
303 | /** Product ID. */
|
---|
304 | uint16_t idProduct;
|
---|
305 | /** Revision, integer part. */
|
---|
306 | uint16_t bcdDevice;
|
---|
307 | /** Manufacturer string index. */
|
---|
308 | uint8_t iManufacturer;
|
---|
309 | /** Product string index. */
|
---|
310 | uint8_t iProduct;
|
---|
311 | /** Serial number string index. */
|
---|
312 | uint8_t iSerialNumber;
|
---|
313 | /** Number of configurations. */
|
---|
314 | uint8_t bNumConfigurations;
|
---|
315 | } USBDEVICEDESC;
|
---|
316 | #pragma pack()
|
---|
317 | /** Pointer to an USB device descriptor. */
|
---|
318 | typedef USBDEVICEDESC *PUSBDEVICEDESC;
|
---|
319 |
|
---|
320 | /** @name Class codes (bDeviceClass)
|
---|
321 | * @{ */
|
---|
322 | #ifndef USB_HUB_CLASSCODE
|
---|
323 | # define USB_HUB_CLASSCODE 0x09
|
---|
324 | #endif
|
---|
325 | /** @} */
|
---|
326 |
|
---|
327 | /**
|
---|
328 | * USB configuration descriptor.
|
---|
329 | */
|
---|
330 | #pragma pack(1)
|
---|
331 | typedef struct USBCONFIGDESC
|
---|
332 | {
|
---|
333 | /** The descriptor length. (Usually sizeof(USBCONFIGDESC).) */
|
---|
334 | uint8_t bLength;
|
---|
335 | /** The descriptor type. (USB_DT_CONFIG) */
|
---|
336 | uint8_t bDescriptorType;
|
---|
337 | /** The length of the configuration descriptor plus all associated descriptors. */
|
---|
338 | uint16_t wTotalLength;
|
---|
339 | /** Number of interfaces. */
|
---|
340 | uint8_t bNumInterfaces;
|
---|
341 | /** Configuration number. (For SetConfiguration().) */
|
---|
342 | uint8_t bConfigurationValue;
|
---|
343 | /** Configuration description string. */
|
---|
344 | uint8_t iConfiguration;
|
---|
345 | /** Configuration characteristics. */
|
---|
346 | uint8_t bmAttributes;
|
---|
347 | /** Maximum power consumption of the USB device in this config. */
|
---|
348 | uint8_t MaxPower;
|
---|
349 | } USBCONFIGDESC;
|
---|
350 | #pragma pack()
|
---|
351 | /** Pointer to an USB configuration descriptor. */
|
---|
352 | typedef USBCONFIGDESC *PUSBCONFIGDESC;
|
---|
353 |
|
---|
354 | #endif /* VBOX_USB_H_INCL_DESCRIPTORS */
|
---|
355 |
|
---|
356 | __END_DECLS
|
---|
357 |
|
---|
358 | #endif
|
---|
359 |
|
---|