VirtualBox

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

Last change on this file since 76565 was 76565, checked in by vboxsync, 6 years ago

Devices: Use VBOX_INCLUDED_SRC_ as header guard prefix with scm.

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