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