1 | /* $Id: USBProxyDevice-vrdp.cpp 49814 2013-12-06 21:38:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * USB device proxy - the VRDP backend, calls the RemoteUSBBackend methods.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2010 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 | #define LOG_GROUP LOG_GROUP_DRV_USBPROXY
|
---|
19 |
|
---|
20 | #include <VBox/log.h>
|
---|
21 | #include <VBox/err.h>
|
---|
22 | #include <VBox/vrdpusb.h>
|
---|
23 | #include <VBox/vmm/pdm.h>
|
---|
24 |
|
---|
25 | #include <iprt/assert.h>
|
---|
26 | #include <iprt/alloc.h>
|
---|
27 | #include <iprt/string.h>
|
---|
28 |
|
---|
29 | #include "../USBProxyDevice.h"
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Backend data for the VRDP USB Proxy device backend.
|
---|
33 | */
|
---|
34 | typedef struct USBPROXYDEVVRDP
|
---|
35 | {
|
---|
36 | REMOTEUSBCALLBACK *pCallback;
|
---|
37 | PREMOTEUSBDEVICE pDevice;
|
---|
38 | } USBPROXYDEVVRDP, *PUSBPROXYDEVVRDP;
|
---|
39 |
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * The USB proxy device functions.
|
---|
43 | */
|
---|
44 |
|
---|
45 | static int usbProxyVrdpOpen(PUSBPROXYDEV pProxyDev, const char *pszAddress, void *pvBackend)
|
---|
46 | {
|
---|
47 | LogFlow(("usbProxyVrdpOpen: pProxyDev=%p pszAddress=%s, pvBackend=%p\n", pProxyDev, pszAddress, pvBackend));
|
---|
48 |
|
---|
49 | int rc = VINF_SUCCESS;
|
---|
50 |
|
---|
51 | if (strncmp (pszAddress, REMOTE_USB_BACKEND_PREFIX_S, REMOTE_USB_BACKEND_PREFIX_LEN) == 0)
|
---|
52 | {
|
---|
53 | REMOTEUSBCALLBACK *pCallback = (REMOTEUSBCALLBACK *)pvBackend;
|
---|
54 | PREMOTEUSBDEVICE pDevice = NULL;
|
---|
55 |
|
---|
56 | rc = pCallback->pfnOpen (pCallback->pInstance, pszAddress, strlen (pszAddress) + 1, &pDevice);
|
---|
57 |
|
---|
58 | if (RT_SUCCESS (rc))
|
---|
59 | {
|
---|
60 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)RTMemAlloc (sizeof(*pDevVrdp));
|
---|
61 | if (pDevVrdp)
|
---|
62 | {
|
---|
63 | pDevVrdp->pCallback = pCallback;
|
---|
64 | pDevVrdp->pDevice = pDevice;
|
---|
65 | pProxyDev->Backend.pv = pDevVrdp;
|
---|
66 | pProxyDev->iActiveCfg = 1; /** @todo that may not be always true. */
|
---|
67 | pProxyDev->cIgnoreSetConfigs = 1;
|
---|
68 | return VINF_SUCCESS;
|
---|
69 | }
|
---|
70 |
|
---|
71 | pCallback->pfnClose (pDevice);
|
---|
72 | rc = VERR_NO_MEMORY;
|
---|
73 | }
|
---|
74 | }
|
---|
75 | else
|
---|
76 | {
|
---|
77 | AssertFailed();
|
---|
78 | rc = VERR_INVALID_PARAMETER;
|
---|
79 | }
|
---|
80 |
|
---|
81 | return rc;
|
---|
82 | }
|
---|
83 |
|
---|
84 | static void usbProxyVrdpClose(PUSBPROXYDEV pProxyDev)
|
---|
85 | {
|
---|
86 | LogFlow(("usbProxyVrdpClose: pProxyDev = %p\n", pProxyDev));
|
---|
87 |
|
---|
88 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
89 |
|
---|
90 | pDevVrdp->pCallback->pfnClose (pDevVrdp->pDevice);
|
---|
91 | }
|
---|
92 |
|
---|
93 | static int usbProxyVrdpReset(PUSBPROXYDEV pProxyDev, bool fResetOnLinux)
|
---|
94 | {
|
---|
95 | LogFlow(("usbProxyVrdpReset: pProxyDev = %p\n", pProxyDev));
|
---|
96 |
|
---|
97 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
98 |
|
---|
99 | int rc = pDevVrdp->pCallback->pfnReset (pDevVrdp->pDevice);
|
---|
100 |
|
---|
101 | if (rc == VERR_VUSB_DEVICE_NOT_ATTACHED)
|
---|
102 | {
|
---|
103 | Log(("usb-vrdp: remote device %p unplugged!!\n", pDevVrdp->pDevice));
|
---|
104 | pProxyDev->fDetached = true;
|
---|
105 | }
|
---|
106 |
|
---|
107 | pProxyDev->iActiveCfg = -1;
|
---|
108 | pProxyDev->cIgnoreSetConfigs = 2;
|
---|
109 |
|
---|
110 | return rc;
|
---|
111 | }
|
---|
112 |
|
---|
113 | static int usbProxyVrdpSetConfig(PUSBPROXYDEV pProxyDev, int cfg)
|
---|
114 | {
|
---|
115 | LogFlow(("usbProxyVrdpSetConfig: pProxyDev=%s cfg=%#x\n", pProxyDev->pUsbIns->pszName, cfg));
|
---|
116 |
|
---|
117 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
118 |
|
---|
119 | int rc = pDevVrdp->pCallback->pfnSetConfig (pDevVrdp->pDevice, (uint8_t)cfg);
|
---|
120 |
|
---|
121 | if (rc == VERR_VUSB_DEVICE_NOT_ATTACHED)
|
---|
122 | {
|
---|
123 | Log(("usb-vrdp: remote device %p unplugged!!\n", pDevVrdp->pDevice));
|
---|
124 | pProxyDev->fDetached = true;
|
---|
125 | }
|
---|
126 |
|
---|
127 | return RT_SUCCESS(rc);
|
---|
128 | }
|
---|
129 |
|
---|
130 | static int usbProxyVrdpClaimInterface(PUSBPROXYDEV pProxyDev, int ifnum)
|
---|
131 | {
|
---|
132 | LogFlow(("usbProxyVrdpClaimInterface: pProxyDev=%s ifnum=%#x\n", pProxyDev->pUsbIns->pszName, ifnum));
|
---|
133 |
|
---|
134 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
135 |
|
---|
136 | int rc = pDevVrdp->pCallback->pfnClaimInterface (pDevVrdp->pDevice, (uint8_t)ifnum);
|
---|
137 |
|
---|
138 | if (rc == VERR_VUSB_DEVICE_NOT_ATTACHED)
|
---|
139 | {
|
---|
140 | Log(("usb-vrdp: remote device %p unplugged!!\n", pDevVrdp->pDevice));
|
---|
141 | pProxyDev->fDetached = true;
|
---|
142 | }
|
---|
143 |
|
---|
144 | return RT_SUCCESS(rc);
|
---|
145 | }
|
---|
146 |
|
---|
147 | static int usbProxyVrdpReleaseInterface(PUSBPROXYDEV pProxyDev, int ifnum)
|
---|
148 | {
|
---|
149 | LogFlow(("usbProxyVrdpReleaseInterface: pProxyDev=%s ifnum=%#x\n", pProxyDev->pUsbIns->pszName, ifnum));
|
---|
150 |
|
---|
151 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
152 |
|
---|
153 | int rc = pDevVrdp->pCallback->pfnReleaseInterface (pDevVrdp->pDevice, (uint8_t)ifnum);
|
---|
154 |
|
---|
155 | if (rc == VERR_VUSB_DEVICE_NOT_ATTACHED)
|
---|
156 | {
|
---|
157 | Log(("usb-vrdp: remote device %p unplugged!!\n", pDevVrdp->pDevice));
|
---|
158 | pProxyDev->fDetached = true;
|
---|
159 | }
|
---|
160 |
|
---|
161 | return RT_SUCCESS(rc);
|
---|
162 | }
|
---|
163 |
|
---|
164 | static int usbProxyVrdpSetInterface(PUSBPROXYDEV pProxyDev, int ifnum, int setting)
|
---|
165 | {
|
---|
166 | LogFlow(("usbProxyVrdpSetInterface: pProxyDev=%p ifnum=%#x setting=%#x\n", pProxyDev, ifnum, setting));
|
---|
167 |
|
---|
168 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
169 |
|
---|
170 | int rc = pDevVrdp->pCallback->pfnInterfaceSetting (pDevVrdp->pDevice, (uint8_t)ifnum, (uint8_t)setting);
|
---|
171 |
|
---|
172 | if (rc == VERR_VUSB_DEVICE_NOT_ATTACHED)
|
---|
173 | {
|
---|
174 | Log(("usb-vrdp: remote device %p unplugged!!\n", pDevVrdp->pDevice));
|
---|
175 | pProxyDev->fDetached = true;
|
---|
176 | }
|
---|
177 |
|
---|
178 | return RT_SUCCESS(rc);
|
---|
179 | }
|
---|
180 |
|
---|
181 | static bool usbProxyVrdpClearHaltedEp(PUSBPROXYDEV pProxyDev, unsigned int ep)
|
---|
182 | {
|
---|
183 | LogFlow(("usbProxyVrdpClearHaltedEp: pProxyDev=%s ep=%u\n", pProxyDev->pUsbIns->pszName, ep));
|
---|
184 |
|
---|
185 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
186 |
|
---|
187 | int rc = pDevVrdp->pCallback->pfnClearHaltedEP (pDevVrdp->pDevice, (uint8_t)ep);
|
---|
188 |
|
---|
189 | if (rc == VERR_VUSB_DEVICE_NOT_ATTACHED)
|
---|
190 | {
|
---|
191 | Log(("usb-vrdp: remote device %p unplugged!!\n", pDevVrdp->pDevice));
|
---|
192 | pProxyDev->fDetached = true;
|
---|
193 | }
|
---|
194 |
|
---|
195 | return RT_SUCCESS(rc);
|
---|
196 | }
|
---|
197 |
|
---|
198 | static int usbProxyVrdpUrbQueue(PVUSBURB pUrb)
|
---|
199 | {
|
---|
200 | LogFlow(("usbProxyVrdpUrbQueue: pUrb=%p\n", pUrb));
|
---|
201 |
|
---|
202 | /** @todo implement isochronous transfers for USB over VRDP. */
|
---|
203 | if (pUrb->enmType == VUSBXFERTYPE_ISOC)
|
---|
204 | {
|
---|
205 | Log(("usbproxy: isochronous transfers aren't implemented yet.\n"));
|
---|
206 | return false;
|
---|
207 | }
|
---|
208 |
|
---|
209 | PUSBPROXYDEV pProxyDev = PDMINS_2_DATA(pUrb->pUsbIns, PUSBPROXYDEV);
|
---|
210 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
211 |
|
---|
212 | int rc = pDevVrdp->pCallback->pfnQueueURB (pDevVrdp->pDevice, pUrb->enmType, pUrb->EndPt, pUrb->enmDir, pUrb->cbData,
|
---|
213 | pUrb->abData, pUrb, (PREMOTEUSBQURB *)&pUrb->Dev.pvPrivate);
|
---|
214 |
|
---|
215 | if (rc == VERR_VUSB_DEVICE_NOT_ATTACHED)
|
---|
216 | {
|
---|
217 | Log(("usb-vrdp: remote device %p unplugged!!\n", pDevVrdp->pDevice));
|
---|
218 | pProxyDev->fDetached = true;
|
---|
219 | }
|
---|
220 |
|
---|
221 | return RT_SUCCESS(rc);
|
---|
222 | }
|
---|
223 |
|
---|
224 | static PVUSBURB usbProxyVrdpUrbReap(PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies)
|
---|
225 | {
|
---|
226 | LogFlow(("usbProxyVrdpUrbReap: pProxyDev=%s\n", pProxyDev->pUsbIns->pszName));
|
---|
227 |
|
---|
228 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
229 |
|
---|
230 | PVUSBURB pUrb = NULL;
|
---|
231 | uint32_t cbData = 0;
|
---|
232 | uint32_t u32Err = VUSBSTATUS_OK;
|
---|
233 |
|
---|
234 | int rc = pDevVrdp->pCallback->pfnReapURB (pDevVrdp->pDevice, cMillies, (void **)&pUrb, &cbData, &u32Err);
|
---|
235 |
|
---|
236 | LogFlow(("usbProxyVrdpUrbReap: rc = %Rrc, pUrb = %p\n", rc, pUrb));
|
---|
237 |
|
---|
238 | if (RT_SUCCESS(rc) && pUrb)
|
---|
239 | {
|
---|
240 | pUrb->enmStatus = (VUSBSTATUS)u32Err;
|
---|
241 | pUrb->cbData = cbData;
|
---|
242 | pUrb->Dev.pvPrivate = NULL;
|
---|
243 | }
|
---|
244 |
|
---|
245 | if (rc == VERR_VUSB_DEVICE_NOT_ATTACHED)
|
---|
246 | {
|
---|
247 | Log(("usb-vrdp: remote device %p unplugged!!\n", pDevVrdp->pDevice));
|
---|
248 | pProxyDev->fDetached = true;
|
---|
249 | }
|
---|
250 |
|
---|
251 | return pUrb;
|
---|
252 | }
|
---|
253 |
|
---|
254 | static void usbProxyVrdpUrbCancel(PVUSBURB pUrb)
|
---|
255 | {
|
---|
256 | LogFlow(("usbProxyVrdpUrbCancel: pUrb=%p\n", pUrb));
|
---|
257 |
|
---|
258 | PUSBPROXYDEV pProxyDev = PDMINS_2_DATA(pUrb->pUsbIns, PUSBPROXYDEV);
|
---|
259 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
260 |
|
---|
261 | pDevVrdp->pCallback->pfnCancelURB (pDevVrdp->pDevice, (PREMOTEUSBQURB)pUrb->Dev.pvPrivate);
|
---|
262 | }
|
---|
263 |
|
---|
264 | static int usbProxyVrdpWakeup(PUSBPROXYDEV pProxyDev)
|
---|
265 | {
|
---|
266 | LogFlow(("usbProxyVrdpWakeup: pProxyDev=%s\n", pProxyDev->pUsbIns->pszName));
|
---|
267 |
|
---|
268 | PUSBPROXYDEVVRDP pDevVrdp = (PUSBPROXYDEVVRDP)pProxyDev->Backend.pv;
|
---|
269 |
|
---|
270 | return pDevVrdp->pCallback->pfnWakeup (pDevVrdp->pDevice);
|
---|
271 | }
|
---|
272 |
|
---|
273 | /**
|
---|
274 | * The VRDP USB Proxy Backend operations.
|
---|
275 | */
|
---|
276 | extern const USBPROXYBACK g_USBProxyDeviceVRDP =
|
---|
277 | {
|
---|
278 | "vrdp",
|
---|
279 | usbProxyVrdpOpen,
|
---|
280 | NULL,
|
---|
281 | usbProxyVrdpClose,
|
---|
282 | usbProxyVrdpReset,
|
---|
283 | usbProxyVrdpSetConfig,
|
---|
284 | usbProxyVrdpClaimInterface,
|
---|
285 | usbProxyVrdpReleaseInterface,
|
---|
286 | usbProxyVrdpSetInterface,
|
---|
287 | usbProxyVrdpClearHaltedEp,
|
---|
288 | usbProxyVrdpUrbQueue,
|
---|
289 | usbProxyVrdpUrbCancel,
|
---|
290 | usbProxyVrdpUrbReap,
|
---|
291 | usbProxyVrdpWakeup,
|
---|
292 | 0
|
---|
293 | };
|
---|
294 |
|
---|