VirtualBox

source: vbox/trunk/src/VBox/Devices/USB/USBProxyDevice.h@ 49882

Last change on this file since 49882 was 49814, checked in by vboxsync, 11 years ago

Devices/USB: First part of the rework, move most of the work to dedicated threads to improve performance

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/* $Id: USBProxyDevice.h 49814 2013-12-06 21:38:28Z vboxsync $ */
2/** @file
3 * USBPROXY - USB proxy header
4 */
5
6/*
7 * Copyright (C) 2006-2011 Oracle Corporation
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 (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___USBProxyDevice_h
19#define ___USBProxyDevice_h
20
21#include <VBox/cdefs.h>
22#include <VBox/vusb.h>
23
24RT_C_DECLS_BEGIN
25
26
27/**
28 * Arguments passed to the USB proxy device constructor.
29 */
30typedef struct USBPROXYDEVARGS
31{
32 /** Whether this is a remote (VRDP) or local (Host) device. */
33 bool fRemote;
34 /** Host specific USB device address. */
35 const char *pszAddress;
36 /** Pointer to backend specific data. */
37 void *pvBackend;
38} USBPROXYDEVARGS;
39/** Pointer to proxy device creation structure. */
40typedef USBPROXYDEVARGS *PUSBPROXYDEVARGS;
41
42
43/** Pointer to a USB proxy device. */
44typedef struct USBPROXYDEV *PUSBPROXYDEV;
45
46/**
47 * USB Proxy Device Backend
48 */
49typedef struct USBPROXYBACK
50{
51 /** Name of the backend. */
52 const char *pszName;
53
54 /**
55 * Opens the USB device specfied by pszAddress.
56 *
57 * This method will initialize backend private data. If the backend has
58 * already selected a configuration for the device, this must be indicated
59 * in USBPROXYDEV::iActiveCfg.
60 *
61 * @returns VBox status code.
62 * @param pProxyDev The USB Proxy Device instance.
63 * @param pszAddress Host specific USB device address.
64 * @param pvBackend Pointer to backend specific data.
65 */
66 int (* pfnOpen)(PUSBPROXYDEV pProxyDev, const char *pszAddress, void *pvBackend);
67
68 /**
69 * Optional callback for initializing the device after the configuration
70 * has been established.
71 *
72 * @returns VBox status code.
73 * @param pProxyDev The USB Proxy Device instance.
74 */
75 int (* pfnInit)(PUSBPROXYDEV pProxyDev);
76
77 /** Closes handle to the host USB device.
78 *
79 * @param pDev The USB Proxy Device instance.
80 */
81 void (* pfnClose)(PUSBPROXYDEV pProxyDev);
82
83 /**
84 * Reset a device.
85 *
86 * The backend must update iActualCfg and fIgnoreEqualSetConfig.
87 *
88 * @returns VBox status code.
89 * @param pDev The device to reset.
90 * @param fResetOnLinux It's safe to do reset on linux, we can deal with devices
91 * being logically reconnected.
92 */
93 int (* pfnReset)(PUSBPROXYDEV pProxyDev, bool fResetOnLinux);
94
95 /** @todo make it return a VBox status code! */
96 int (* pfnSetConfig)(PUSBPROXYDEV pProxyDev, int iCfg);
97
98 /** @todo make it return a VBox status code! */
99 int (* pfnClaimInterface)(PUSBPROXYDEV pProxyDev, int iIf);
100
101 /** @todo make it return a VBox status code! */
102 int (* pfnReleaseInterface)(PUSBPROXYDEV pProxyDev, int iIf);
103
104 /** @todo make it return a VBox status code! */
105 int (* pfnSetInterface)(PUSBPROXYDEV pProxyDev, int iIf, int setting);
106
107 /** @todo make it return a VBox status code! */
108 bool (* pfnClearHaltedEndpoint)(PUSBPROXYDEV pDev, unsigned int iEp);
109
110 /** @todo make it return a VBox status code! Add pDev. */
111 int (* pfnUrbQueue)(PVUSBURB pUrb);
112
113 /**
114 * Cancel an in-flight URB.
115 *
116 * @param pUrb The URB to cancel.
117 * @todo make it return a VBox status code! Add pDev.
118 */
119 void (* pfnUrbCancel)(PVUSBURB pUrb);
120
121 /**
122 * Reap URBs in-flight on a device.
123 *
124 * @returns Pointer to a completed URB.
125 * @returns NULL if no URB was completed.
126 * @param pDev The device.
127 * @param cMillies Number of milliseconds to wait. Use 0 to not
128 * wait at all.
129 */
130 PVUSBURB (* pfnUrbReap)(PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies);
131
132 /**
133 * Kicks the thread waiting in pfnUrbReap to make it return.
134 *
135 * @returns VBox status code.
136 * @param pProxyDev The device.
137 */
138 int (* pfnWakeup)(PUSBPROXYDEV pProxyDev);
139
140 /** Dummy entry for making sure we've got all members initialized. */
141 uint32_t uDummy;
142} USBPROXYBACK;
143/** Pointer to a USB Proxy Device Backend. */
144typedef USBPROXYBACK *PUSBPROXYBACK;
145/** Pointer to a const USB Proxy Device Backend. */
146typedef const USBPROXYBACK *PCUSBPROXYBACK;
147
148/** The Host backend. */
149extern const USBPROXYBACK g_USBProxyDeviceHost;
150/** The remote desktop backend. */
151extern const USBPROXYBACK g_USBProxyDeviceVRDP;
152
153#ifdef RDESKTOP
154typedef struct VUSBDEV
155{
156 char* pszName;
157} VUSBDEV, *PVUSBDEV;
158#endif
159
160/**
161 * USB Proxy device.
162 */
163typedef struct USBPROXYDEV
164{
165#ifdef RDESKTOP
166 /** The VUSB device structure - must be the first structure member. */
167 VUSBDEV Dev;
168 /** The next device in rdesktop-vrdp's linked list */
169 PUSBPROXYDEV pNext;
170 /** The previous device in rdesktop-vrdp's linked list */
171 PUSBPROXYDEV pPrev;
172 /** The vrdp device ID */
173 uint32_t devid;
174 /** Linked list of in-flight URBs */
175 PVUSBURB pUrbs;
176#endif
177 /** The device descriptor. */
178 VUSBDESCDEVICE DevDesc;
179 /** The configuration descriptor array. */
180 PVUSBDESCCONFIGEX paCfgDescs;
181#ifndef RDESKTOP
182 /** The descriptor cache.
183 * Contains &DevDesc and paConfigDescs. */
184 PDMUSBDESCCACHE DescCache;
185 /** Pointer to the PDM USB device instance. */
186 PPDMUSBINS pUsbIns;
187#endif
188
189 /** Pointer to the backend. */
190 PCUSBPROXYBACK pOps;
191 /** The currently active configuration.
192 * It's -1 if no configuration is active. This is set to -1 before open and reset,
193 * the backend will change it if open or reset implies SET_CONFIGURATION. */
194 int iActiveCfg;
195 /** Ignore one or two SET_CONFIGURATION operation.
196 * See usbProxyDevSetCfg for details. */
197 int cIgnoreSetConfigs;
198 /** Mask of the interfaces that the guest shall doesn't see.
199 * This is experimental!
200 */
201 uint32_t fMaskedIfs;
202 /** Whether we've opened the device or not.
203 * For dealing with failed construction (the destruct method is always called). */
204 bool fOpened;
205 /** Whether we've called pfnInit or not.
206 * For dealing with failed construction (the destruct method is always called). */
207 bool fInited;
208 /** Whether the device has been detached.
209 * This is hack for making PDMUSBREG::pfnUsbQueue return the right status code. */
210 bool fDetached;
211 /** Backend specific data */
212 union USBPROXYBACKENDDATA
213 {
214 /** Pointer to some backend data.
215 * The Linux and Darwin backends are making use of this. */
216 void *pv;
217 RTFILE hFile;
218 int fd;
219 struct vrdp_priv
220 {
221 void *pCallback;
222 void *pDevice;
223 } vrdp;
224 } Backend;
225} USBPROXYDEV;
226
227static inline char *usbProxyGetName(PUSBPROXYDEV pProxyDev)
228{
229#ifndef RDESKTOP
230 return pProxyDev->pUsbIns->pszName;
231#else
232 return pProxyDev->Dev.pszName;
233#endif
234}
235
236#ifdef RDESKTOP
237static inline PUSBPROXYDEV usbProxyFromVusbDev(PVUSBDEV pDev)
238{
239 return (PUSBPROXYDEV)pDev;
240}
241#endif
242
243#ifdef RT_OS_LINUX
244RTDECL(int) USBProxyDeviceLinuxGetFD(PUSBPROXYDEV pProxyDev);
245#endif
246
247RT_C_DECLS_END
248
249#endif
250
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