VirtualBox

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

Last change on this file since 54785 was 50234, checked in by vboxsync, 11 years ago

USB/Proxy: More code cleanup and finish a few todos, also some new ones so it doesn't get boring

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1/* $Id: USBProxyDevice.h 50234 2014-01-24 22:48:13Z 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/** Pointer to a USB proxy device. */
28typedef struct USBPROXYDEV *PUSBPROXYDEV;
29
30/**
31 * USB Proxy Device Backend
32 */
33typedef struct USBPROXYBACK
34{
35 /** Name of the backend. */
36 const char *pszName;
37 /** Size of the backend specific data. */
38 size_t cbBackend;
39
40 /**
41 * Opens the USB device specfied by pszAddress.
42 *
43 * This method will initialize backend private data. If the backend has
44 * already selected a configuration for the device, this must be indicated
45 * in USBPROXYDEV::iActiveCfg.
46 *
47 * @returns VBox status code.
48 * @param pProxyDev The USB Proxy Device instance.
49 * @param pszAddress Host specific USB device address.
50 * @param pvBackend Pointer to backend specific data.
51 */
52 DECLR3CALLBACKMEMBER(int, pfnOpen, (PUSBPROXYDEV pProxyDev, const char *pszAddress, void *pvBackend));
53
54 /**
55 * Optional callback for initializing the device after the configuration
56 * has been established.
57 *
58 * @returns VBox status code.
59 * @param pProxyDev The USB Proxy Device instance.
60 */
61 DECLR3CALLBACKMEMBER(int, pfnInit, (PUSBPROXYDEV pProxyDev));
62
63 /**
64 * Closes handle to the host USB device.
65 *
66 * @param pProxyDev The USB Proxy Device instance.
67 */
68 DECLR3CALLBACKMEMBER(void, pfnClose, (PUSBPROXYDEV pProxyDev));
69
70 /**
71 * Reset a device.
72 *
73 * The backend must update iActualCfg and fIgnoreEqualSetConfig.
74 *
75 * @returns VBox status code.
76 * @param pProxyDev The USB Proxy Device instance.
77 * @param fResetOnLinux It's safe to do reset on linux, we can deal with devices
78 * being logically reconnected.
79 */
80 DECLR3CALLBACKMEMBER(int, pfnReset, (PUSBPROXYDEV pProxyDev, bool fResetOnLinux));
81
82 /**
83 * Sets the given configuration of the device.
84 *
85 * @returns VBox status code.
86 * @param pProxyDev The USB Proxy Device instance.
87 * @param iCfg The configuration to set.
88 */
89 DECLR3CALLBACKMEMBER(int, pfnSetConfig, (PUSBPROXYDEV pProxyDev, int iCfg));
90
91 /**
92 * Claim an interface for use by the prox device.
93 *
94 * @returns VBox status code.
95 * @param pProxyDev The USB Proxy Device instance.
96 * @param iIf Interface number to claim.
97 */
98 DECLR3CALLBACKMEMBER(int, pfnClaimInterface, (PUSBPROXYDEV pProxyDev, int iIf));
99
100 /**
101 * Releases an interface which was claimed before.
102 *
103 * @returns VBox status code.
104 * @param pProxyDev The USB Proxy Device instance.
105 * @param iIf Interface number to release.
106 */
107 DECLR3CALLBACKMEMBER(int, pfnReleaseInterface, (PUSBPROXYDEV pProxyDev, int iIf));
108
109 /**
110 * Sets the given alternate interface for the device.
111 *
112 * @returns VBox status code.
113 * @param pProxyDev The USB Proxy Device instance.
114 * @param iIf Interface to use.
115 * @param iSetting The alternate setting to use.
116 */
117 DECLR3CALLBACKMEMBER(int, pfnSetInterface, (PUSBPROXYDEV pProxyDev, int iIf, int iSetting));
118
119 /**
120 * Clears the given halted endpoint.
121 *
122 * @returns VBox status code.
123 * @param pProxyDev The USB Proxy Device instance.
124 * @param iEp The endpoint to clear.
125 */
126 DECLR3CALLBACKMEMBER(int, pfnClearHaltedEndpoint, (PUSBPROXYDEV pDev, unsigned int iEp));
127
128 /**
129 * Queue a new URB.
130 *
131 * @returns VBox status code.
132 * @param pProxyDev The USB Proxy Device instance.
133 * @param pUrb The URB to queue.
134 */
135 DECLR3CALLBACKMEMBER(int, pfnUrbQueue, (PUSBPROXYDEV pProxyDev, PVUSBURB pUrb));
136
137 /**
138 * Cancel an in-flight URB.
139 *
140 * @returns VBox status code.
141 * @param pProxyDev The USB Proxy Device instance.
142 * @param pUrb The URB to cancel.
143 */
144 DECLR3CALLBACKMEMBER(int, pfnUrbCancel, (PUSBPROXYDEV pProxyDev, PVUSBURB pUrb));
145
146 /**
147 * Reap URBs in-flight on a device.
148 *
149 * @returns Pointer to a completed URB.
150 * @returns NULL if no URB was completed.
151 * @param pProxyDev The USB Proxy Device instance.
152 * @param cMillies Number of milliseconds to wait. Use 0 to not
153 * wait at all.
154 */
155 DECLR3CALLBACKMEMBER(PVUSBURB, pfnUrbReap, (PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies));
156
157 /**
158 * Kicks the thread waiting in pfnUrbReap to make it return.
159 *
160 * @returns VBox status code.
161 * @param pProxyDev The USB Proxy Device instance.
162 */
163 DECLR3CALLBACKMEMBER(int, pfnWakeup, (PUSBPROXYDEV pProxyDev));
164
165 /** Dummy entry for making sure we've got all members initialized. */
166 uint32_t uDummy;
167} USBPROXYBACK;
168/** Pointer to a USB Proxy Device Backend. */
169typedef USBPROXYBACK *PUSBPROXYBACK;
170/** Pointer to a const USB Proxy Device Backend. */
171typedef const USBPROXYBACK *PCUSBPROXYBACK;
172
173/** The Host backend. */
174extern const USBPROXYBACK g_USBProxyDeviceHost;
175/** The remote desktop backend. */
176extern const USBPROXYBACK g_USBProxyDeviceVRDP;
177
178#ifdef RDESKTOP
179typedef struct VUSBDEV
180{
181 char* pszName;
182} VUSBDEV, *PVUSBDEV;
183#endif
184
185/**
186 * USB Proxy device.
187 */
188typedef struct USBPROXYDEV
189{
190#ifdef RDESKTOP
191 /** The VUSB device structure - must be the first structure member. */
192 VUSBDEV Dev;
193 /** The next device in rdesktop-vrdp's linked list */
194 PUSBPROXYDEV pNext;
195 /** The previous device in rdesktop-vrdp's linked list */
196 PUSBPROXYDEV pPrev;
197 /** The vrdp device ID */
198 uint32_t devid;
199 /** Linked list of in-flight URBs */
200 PVUSBURB pUrbs;
201#endif
202 /** The device descriptor. */
203 VUSBDESCDEVICE DevDesc;
204 /** The configuration descriptor array. */
205 PVUSBDESCCONFIGEX paCfgDescs;
206#ifndef RDESKTOP
207 /** The descriptor cache.
208 * Contains &DevDesc and paConfigDescs. */
209 PDMUSBDESCCACHE DescCache;
210 /** Pointer to the PDM USB device instance. */
211 PPDMUSBINS pUsbIns;
212#endif
213
214 /** Pointer to the backend. */
215 PCUSBPROXYBACK pOps;
216 /** The currently active configuration.
217 * It's -1 if no configuration is active. This is set to -1 before open and reset,
218 * the backend will change it if open or reset implies SET_CONFIGURATION. */
219 int iActiveCfg;
220 /** Ignore one or two SET_CONFIGURATION operation.
221 * See usbProxyDevSetCfg for details. */
222 int cIgnoreSetConfigs;
223 /** Mask of the interfaces that the guest shall doesn't see.
224 * This is experimental!
225 */
226 uint32_t fMaskedIfs;
227 /** Whether we've opened the device or not.
228 * For dealing with failed construction (the destruct method is always called). */
229 bool fOpened;
230 /** Whether we've called pfnInit or not.
231 * For dealing with failed construction (the destruct method is always called). */
232 bool fInited;
233 /** Whether the device has been detached.
234 * This is hack for making PDMUSBREG::pfnUsbQueue return the right status code. */
235 bool fDetached;
236 /** Backend specific data, the size is stored in pOps::cbBackend. */
237 void *pvInstanceDataR3;
238} USBPROXYDEV;
239
240/** @def USBPROXYDEV_2_DATA
241 * Converts a USB proxy Device, pointer to a pointer to the backend specific instance data.
242 */
243#define USBPROXYDEV_2_DATA(a_pProxyDev, a_Type) ( (a_Type)(a_pProxyDev)->pvInstanceDataR3 )
244
245static inline char *usbProxyGetName(PUSBPROXYDEV pProxyDev)
246{
247#ifndef RDESKTOP
248 return pProxyDev->pUsbIns->pszName;
249#else
250 return pProxyDev->Dev.pszName;
251#endif
252}
253
254#ifdef RDESKTOP
255static inline PUSBPROXYDEV usbProxyFromVusbDev(PVUSBDEV pDev)
256{
257 return (PUSBPROXYDEV)pDev;
258}
259#endif
260
261#ifdef RT_OS_LINUX
262RTDECL(int) USBProxyDeviceLinuxGetFD(PUSBPROXYDEV pProxyDev);
263#endif
264
265RT_C_DECLS_END
266
267#endif
268
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