VirtualBox

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

Last change on this file since 95288 was 94342, checked in by vboxsync, 3 years ago

Main,VMM/PDMUsb,Devices/USB,VRDP: Drop passing pointers through CFGM in favor of using VMM2USERMETHODS::pfnQueryGenericObject, bugref:10053

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