VirtualBox

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

Last change on this file since 58466 was 58158, checked in by vboxsync, 9 years ago

USBPROXYDEV: nits.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1/* $Id: USBProxyDevice.h 58158 2015-10-09 17:25:13Z vboxsync $ */
2/** @file
3 * USBPROXY - USB proxy header
4 */
5
6/*
7 * Copyright (C) 2006-2015 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 /** The device descriptor. */
191 VUSBDESCDEVICE DevDesc;
192 /** The configuration descriptor array. */
193 PVUSBDESCCONFIGEX paCfgDescs;
194#ifndef RDESKTOP
195 /** The descriptor cache.
196 * Contains &DevDesc and paConfigDescs. */
197 PDMUSBDESCCACHE DescCache;
198 /** Pointer to the PDM USB device instance. */
199 PPDMUSBINS pUsbIns;
200#endif
201
202 /** Pointer to the backend. */
203 PCUSBPROXYBACK pOps;
204 /** The currently active configuration.
205 * It's -1 if no configuration is active. This is set to -1 before open and reset,
206 * the backend will change it if open or reset implies SET_CONFIGURATION. */
207 int iActiveCfg;
208 /** Ignore one or two SET_CONFIGURATION operation.
209 * See usbProxyDevSetCfg for details. */
210 int cIgnoreSetConfigs;
211 /** Mask of the interfaces that the guest shall doesn't see.
212 * This is experimental!
213 */
214 uint32_t fMaskedIfs;
215 /** Whether we've opened the device or not.
216 * For dealing with failed construction (the destruct method is always called). */
217 bool fOpened;
218 /** Whether we've called pfnInit or not.
219 * For dealing with failed construction (the destruct method is always called). */
220 bool fInited;
221 /** Whether the device has been detached.
222 * This is hack for making PDMUSBREG::pfnUsbQueue return the right status code. */
223 bool fDetached;
224 /** Backend specific data, the size is stored in pOps::cbBackend. */
225 void *pvInstanceDataR3;
226
227#ifdef RDESKTOP
228 /** @name VRDP client (rdesktop) related members.
229 * @{ */
230 /** The vrdp device ID. */
231 uint32_t idVrdp;
232 /** The VUSB device structure - must be the first structure member. */
233 VUSBDEV Dev;
234 /** The next device in rdesktop-vrdp's linked list. */
235 PUSBPROXYDEV pNext;
236 /** The previous device in rdesktop-vrdp's linked list. */
237 PUSBPROXYDEV pPrev;
238 /** Linked list of in-flight URBs */
239 PVUSBURB pUrbs;
240 /** @} */
241#endif
242} USBPROXYDEV;
243
244/** @def USBPROXYDEV_2_DATA
245 * Converts a USB proxy Device, pointer to a pointer to the backend specific instance data.
246 */
247#define USBPROXYDEV_2_DATA(a_pProxyDev, a_Type) ( (a_Type)(a_pProxyDev)->pvInstanceDataR3 )
248
249
250DECLINLINE(const char *) usbProxyGetName(PUSBPROXYDEV pProxyDev)
251{
252#ifndef RDESKTOP
253 return pProxyDev->pUsbIns->pszName;
254#else
255 return pProxyDev->Dev.pszName;
256#endif
257}
258
259#ifdef RDESKTOP
260DECLINLINE(PUSBPROXYDEV) usbProxyFromVusbDev(PVUSBDEV pDev)
261{
262 return RT_FROM_MEMBER(pDev, USBPROXYDEV, Dev);
263}
264#endif
265
266#ifdef RT_OS_LINUX
267RTDECL(int) USBProxyDeviceLinuxGetFD(PUSBPROXYDEV pProxyDev);
268#endif
269
270RT_C_DECLS_END
271
272#endif
273
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