VirtualBox

source: vbox/trunk/include/VBox/usb.h@ 8006

Last change on this file since 8006 was 7745, checked in by vboxsync, 16 years ago

Added enmSpeed to USBDEVICE, needed to figure out where to attach a device.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use