1 | /* $Id: USBProxyDevice-linux.cpp 87855 2021-02-24 07:31:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * USB device proxy - the Linux backend.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 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 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Defined Constants And Macros *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 |
|
---|
23 |
|
---|
24 | /*********************************************************************************************************************************
|
---|
25 | * Header Files *
|
---|
26 | *********************************************************************************************************************************/
|
---|
27 | #define LOG_GROUP LOG_GROUP_DRV_USBPROXY
|
---|
28 |
|
---|
29 | #include <iprt/stdint.h>
|
---|
30 | #include <iprt/err.h>
|
---|
31 | #include <iprt/pipe.h>
|
---|
32 |
|
---|
33 | #include <sys/types.h>
|
---|
34 | #include <sys/stat.h>
|
---|
35 | #include <sys/vfs.h>
|
---|
36 | #include <sys/ioctl.h>
|
---|
37 | #include <sys/poll.h>
|
---|
38 | #include <stdint.h>
|
---|
39 | #include <stdio.h>
|
---|
40 | #include <string.h>
|
---|
41 | #include <stdlib.h>
|
---|
42 | #include <limits.h>
|
---|
43 | #include <unistd.h>
|
---|
44 | #include <fcntl.h>
|
---|
45 | #include <errno.h>
|
---|
46 | #ifdef VBOX_WITH_LINUX_COMPILER_H
|
---|
47 | # include <linux/compiler.h>
|
---|
48 | #endif
|
---|
49 | #include <linux/usbdevice_fs.h>
|
---|
50 |
|
---|
51 | #ifndef RDESKTOP
|
---|
52 | # include <VBox/vmm/pdm.h>
|
---|
53 | #else
|
---|
54 | # define RTCRITSECT void *
|
---|
55 | static inline int rtcsNoop() { return VINF_SUCCESS; }
|
---|
56 | static inline bool rtcsTrue() { return true; }
|
---|
57 | # define RTCritSectInit(a) rtcsNoop()
|
---|
58 | # define RTCritSectDelete(a) rtcsNoop()
|
---|
59 | # define RTCritSectEnter(a) rtcsNoop()
|
---|
60 | # define RTCritSectLeave(a) rtcsNoop()
|
---|
61 | # define RTCritSectIsOwner(a) rtcsTrue()
|
---|
62 | #endif
|
---|
63 | #include <VBox/err.h>
|
---|
64 | #include <VBox/log.h>
|
---|
65 | #include <iprt/alloc.h>
|
---|
66 | #include <iprt/assert.h>
|
---|
67 | #include <iprt/asm.h>
|
---|
68 | #include <iprt/ctype.h>
|
---|
69 | #include <iprt/file.h>
|
---|
70 | #include <iprt/linux/sysfs.h>
|
---|
71 | #include <iprt/stream.h>
|
---|
72 | #include <iprt/string.h>
|
---|
73 | #include <iprt/list.h>
|
---|
74 | #include <iprt/time.h>
|
---|
75 | #include "../USBProxyDevice.h"
|
---|
76 |
|
---|
77 |
|
---|
78 | /*********************************************************************************************************************************
|
---|
79 | * Structures and Typedefs *
|
---|
80 | *********************************************************************************************************************************/
|
---|
81 | /**
|
---|
82 | * Wrapper around the linux urb request structure.
|
---|
83 | * This is required to track in-flight and landed URBs.
|
---|
84 | */
|
---|
85 | typedef struct USBPROXYURBLNX
|
---|
86 | {
|
---|
87 | /** The kernel URB data. */
|
---|
88 | #if RT_GNUC_PREREQ(6, 0)
|
---|
89 | /* gcc 6.2 complains about the [] member of KUrb */
|
---|
90 | # pragma GCC diagnostic push
|
---|
91 | # pragma GCC diagnostic ignored "-Wpedantic"
|
---|
92 | #endif
|
---|
93 | struct usbdevfs_urb KUrb;
|
---|
94 | #if RT_GNUC_PREREQ(6, 0)
|
---|
95 | # pragma GCC diagnostic pop
|
---|
96 | #endif
|
---|
97 | /** Space filler for the isochronous packets. */
|
---|
98 | struct usbdevfs_iso_packet_desc aIsocPktsDonUseTheseUseTheOnesInKUrb[8];
|
---|
99 | /** Node to link the URB in of the existing lists. */
|
---|
100 | RTLISTNODE NodeList;
|
---|
101 | /** If we've split the VUSBURB up into multiple linux URBs, this is points to the head. */
|
---|
102 | struct USBPROXYURBLNX *pSplitHead;
|
---|
103 | /** The next linux URB if split up. */
|
---|
104 | struct USBPROXYURBLNX *pSplitNext;
|
---|
105 | /** Don't report these back. */
|
---|
106 | bool fCanceledBySubmit;
|
---|
107 | /** This split element is reaped. */
|
---|
108 | bool fSplitElementReaped;
|
---|
109 | /** This URB was discarded. */
|
---|
110 | bool fDiscarded;
|
---|
111 | /** Size to transfer in remaining fragments of a split URB */
|
---|
112 | uint32_t cbSplitRemaining;
|
---|
113 | } USBPROXYURBLNX, *PUSBPROXYURBLNX;
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Data for the linux usb proxy backend.
|
---|
117 | */
|
---|
118 | typedef struct USBPROXYDEVLNX
|
---|
119 | {
|
---|
120 | /** The open file. */
|
---|
121 | RTFILE hFile;
|
---|
122 | /** Critical section protecting the lists. */
|
---|
123 | RTCRITSECT CritSect;
|
---|
124 | /** The list of free linux URBs (USBPROXYURBLNX). */
|
---|
125 | RTLISTANCHOR ListFree;
|
---|
126 | /** The list of active linux URBs.
|
---|
127 | * We must maintain this so we can properly reap URBs of a detached device.
|
---|
128 | * Only the split head will appear in this list. (USBPROXYURBLNX) */
|
---|
129 | RTLISTANCHOR ListInFlight;
|
---|
130 | /** Are we using sysfs to find the active configuration? */
|
---|
131 | bool fUsingSysfs;
|
---|
132 | /** Pipe handle for waking up - writing end. */
|
---|
133 | RTPIPE hPipeWakeupW;
|
---|
134 | /** Pipe handle for waking up - reading end. */
|
---|
135 | RTPIPE hPipeWakeupR;
|
---|
136 | /** The device node/sysfs path of the device.
|
---|
137 | * Used to figure out the configuration after a reset. */
|
---|
138 | char *pszPath;
|
---|
139 | /** Mask of claimed interfaces. */
|
---|
140 | uint32_t fClaimedIfsMask;
|
---|
141 | } USBPROXYDEVLNX, *PUSBPROXYDEVLNX;
|
---|
142 |
|
---|
143 |
|
---|
144 | /*********************************************************************************************************************************
|
---|
145 | * Internal Functions *
|
---|
146 | *********************************************************************************************************************************/
|
---|
147 | static void usbProxLinuxUrbUnplugged(PUSBPROXYDEV pProxyDev);
|
---|
148 | static DECLCALLBACK(int) usbProxyLinuxClaimInterface(PUSBPROXYDEV pProxyDev, int iIf);
|
---|
149 | static DECLCALLBACK(int) usbProxyLinuxReleaseInterface(PUSBPROXYDEV pProxyDev, int iIf);
|
---|
150 |
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Wrapper for the ioctl call.
|
---|
154 | *
|
---|
155 | * This wrapper will repeat the call if we get an EINTR or EAGAIN. It can also
|
---|
156 | * handle ENODEV (detached device) errors.
|
---|
157 | *
|
---|
158 | * @returns whatever ioctl returns.
|
---|
159 | * @param pProxyDev The proxy device.
|
---|
160 | * @param iCmd The ioctl command / function.
|
---|
161 | * @param pvArg The ioctl argument / data.
|
---|
162 | * @param fHandleNoDev Whether to handle ENODEV.
|
---|
163 | * @param cTries The number of retries. Use UINT32_MAX for (kind of) indefinite retries.
|
---|
164 | * @internal
|
---|
165 | */
|
---|
166 | static int usbProxyLinuxDoIoCtl(PUSBPROXYDEV pProxyDev, unsigned long iCmd, void *pvArg, bool fHandleNoDev, uint32_t cTries)
|
---|
167 | {
|
---|
168 | int rc;
|
---|
169 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
170 | do
|
---|
171 | {
|
---|
172 | do
|
---|
173 | {
|
---|
174 | rc = ioctl(RTFileToNative(pDevLnx->hFile), iCmd, pvArg);
|
---|
175 | if (rc >= 0)
|
---|
176 | return rc;
|
---|
177 | } while (errno == EINTR);
|
---|
178 |
|
---|
179 | if (errno == ENODEV && fHandleNoDev)
|
---|
180 | {
|
---|
181 | usbProxLinuxUrbUnplugged(pProxyDev);
|
---|
182 | Log(("usb-linux: ENODEV -> unplugged. pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
|
---|
183 | errno = ENODEV;
|
---|
184 | break;
|
---|
185 | }
|
---|
186 | if (errno != EAGAIN)
|
---|
187 | break;
|
---|
188 | } while (cTries-- > 0);
|
---|
189 |
|
---|
190 | return rc;
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * The device has been unplugged.
|
---|
196 | * Cancel all in-flight URBs and put them up for reaping.
|
---|
197 | */
|
---|
198 | static void usbProxLinuxUrbUnplugged(PUSBPROXYDEV pProxyDev)
|
---|
199 | {
|
---|
200 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
201 |
|
---|
202 | /*
|
---|
203 | * Shoot down all flying URBs.
|
---|
204 | */
|
---|
205 | RTCritSectEnter(&pDevLnx->CritSect);
|
---|
206 | pProxyDev->fDetached = true;
|
---|
207 |
|
---|
208 | PUSBPROXYURBLNX pUrbLnx;
|
---|
209 | PUSBPROXYURBLNX pUrbLnxNext;
|
---|
210 | RTListForEachSafe(&pDevLnx->ListInFlight, pUrbLnx, pUrbLnxNext, USBPROXYURBLNX, NodeList)
|
---|
211 | {
|
---|
212 | if (!pUrbLnx->fDiscarded)
|
---|
213 | {
|
---|
214 | pUrbLnx->fDiscarded = true;
|
---|
215 | /* Cancel the URB. It will be reaped normally. */
|
---|
216 | ioctl(RTFileToNative(pDevLnx->hFile), USBDEVFS_DISCARDURB, &pUrbLnx->KUrb);
|
---|
217 | if (!pUrbLnx->KUrb.status)
|
---|
218 | pUrbLnx->KUrb.status = -ENODEV;
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | RTCritSectLeave(&pDevLnx->CritSect);
|
---|
223 | }
|
---|
224 |
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * Set the connect state seen by kernel drivers
|
---|
228 | * @internal
|
---|
229 | */
|
---|
230 | static void usbProxyLinuxSetConnected(PUSBPROXYDEV pProxyDev, int iIf, bool fConnect, bool fQuiet)
|
---|
231 | {
|
---|
232 | if ( iIf >= 32
|
---|
233 | || !(pProxyDev->fMaskedIfs & RT_BIT(iIf)))
|
---|
234 | {
|
---|
235 | struct usbdevfs_ioctl IoCtl;
|
---|
236 | if (!fQuiet)
|
---|
237 | LogFlow(("usbProxyLinuxSetConnected: pProxyDev=%s iIf=%#x fConnect=%s\n",
|
---|
238 | usbProxyGetName(pProxyDev), iIf, fConnect ? "true" : "false"));
|
---|
239 |
|
---|
240 | IoCtl.ifno = iIf;
|
---|
241 | IoCtl.ioctl_code = fConnect ? USBDEVFS_CONNECT : USBDEVFS_DISCONNECT;
|
---|
242 | IoCtl.data = NULL;
|
---|
243 | if ( usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_IOCTL, &IoCtl, true, UINT32_MAX)
|
---|
244 | && !fQuiet)
|
---|
245 | Log(("usbProxyLinuxSetConnected: failure, errno=%d. pProxyDev=%s\n",
|
---|
246 | errno, usbProxyGetName(pProxyDev)));
|
---|
247 | }
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 | /**
|
---|
252 | * Links the given URB into the in flight list.
|
---|
253 | *
|
---|
254 | * @returns nothing.
|
---|
255 | * @param pDevLnx The proxy device instance - Linux specific data.
|
---|
256 | * @param pUrbLnx The URB to link into the in flight list.
|
---|
257 | */
|
---|
258 | static void usbProxyLinuxUrbLinkInFlight(PUSBPROXYDEVLNX pDevLnx, PUSBPROXYURBLNX pUrbLnx)
|
---|
259 | {
|
---|
260 | LogFlowFunc(("pDevLnx=%p pUrbLnx=%p\n", pDevLnx, pUrbLnx));
|
---|
261 | Assert(RTCritSectIsOwner(&pDevLnx->CritSect));
|
---|
262 | Assert(!pUrbLnx->pSplitHead || pUrbLnx->pSplitHead == pUrbLnx);
|
---|
263 | RTListAppend(&pDevLnx->ListInFlight, &pUrbLnx->NodeList);
|
---|
264 | }
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * Unlinks the given URB from the in flight list.
|
---|
268 | * @returns nothing.
|
---|
269 | * @param pDevLnx The proxy device instance - Linux specific data.
|
---|
270 | * @param pUrbLnx The URB to link into the in flight list.
|
---|
271 | */
|
---|
272 | static void usbProxyLinuxUrbUnlinkInFlight(PUSBPROXYDEVLNX pDevLnx, PUSBPROXYURBLNX pUrbLnx)
|
---|
273 | {
|
---|
274 | LogFlowFunc(("pDevLnx=%p pUrbLnx=%p\n", pDevLnx, pUrbLnx));
|
---|
275 | RTCritSectEnter(&pDevLnx->CritSect);
|
---|
276 |
|
---|
277 | /*
|
---|
278 | * Remove from the active list.
|
---|
279 | */
|
---|
280 | Assert(!pUrbLnx->pSplitHead || pUrbLnx->pSplitHead == pUrbLnx);
|
---|
281 |
|
---|
282 | RTListNodeRemove(&pUrbLnx->NodeList);
|
---|
283 |
|
---|
284 | RTCritSectLeave(&pDevLnx->CritSect);
|
---|
285 | }
|
---|
286 |
|
---|
287 | /**
|
---|
288 | * Allocates a linux URB request structure.
|
---|
289 | * @returns Pointer to an active URB request.
|
---|
290 | * @returns NULL on failure.
|
---|
291 | * @param pProxyDev The proxy device instance.
|
---|
292 | * @param pSplitHead The split list head if allocating for a split list.
|
---|
293 | */
|
---|
294 | static PUSBPROXYURBLNX usbProxyLinuxUrbAlloc(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pSplitHead)
|
---|
295 | {
|
---|
296 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
297 | PUSBPROXYURBLNX pUrbLnx;
|
---|
298 |
|
---|
299 | LogFlowFunc(("pProxyDev=%p pSplitHead=%p\n", pProxyDev, pSplitHead));
|
---|
300 |
|
---|
301 | RTCritSectEnter(&pDevLnx->CritSect);
|
---|
302 |
|
---|
303 | /*
|
---|
304 | * Try remove a linux URB from the free list, if none there allocate a new one.
|
---|
305 | */
|
---|
306 | pUrbLnx = RTListGetFirst(&pDevLnx->ListFree, USBPROXYURBLNX, NodeList);
|
---|
307 | if (pUrbLnx)
|
---|
308 | {
|
---|
309 | RTListNodeRemove(&pUrbLnx->NodeList);
|
---|
310 | RTCritSectLeave(&pDevLnx->CritSect);
|
---|
311 | }
|
---|
312 | else
|
---|
313 | {
|
---|
314 | RTCritSectLeave(&pDevLnx->CritSect);
|
---|
315 | pUrbLnx = (PUSBPROXYURBLNX)RTMemAlloc(sizeof(*pUrbLnx));
|
---|
316 | if (!pUrbLnx)
|
---|
317 | return NULL;
|
---|
318 | }
|
---|
319 |
|
---|
320 | pUrbLnx->pSplitHead = pSplitHead;
|
---|
321 | pUrbLnx->pSplitNext = NULL;
|
---|
322 | pUrbLnx->fCanceledBySubmit = false;
|
---|
323 | pUrbLnx->fSplitElementReaped = false;
|
---|
324 | pUrbLnx->fDiscarded = false;
|
---|
325 | LogFlowFunc(("returns pUrbLnx=%p\n", pUrbLnx));
|
---|
326 | return pUrbLnx;
|
---|
327 | }
|
---|
328 |
|
---|
329 |
|
---|
330 | /**
|
---|
331 | * Frees a linux URB request structure.
|
---|
332 | *
|
---|
333 | * @param pProxyDev The proxy device instance.
|
---|
334 | * @param pUrbLnx The linux URB to free.
|
---|
335 | */
|
---|
336 | static void usbProxyLinuxUrbFree(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pUrbLnx)
|
---|
337 | {
|
---|
338 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
339 |
|
---|
340 | LogFlowFunc(("pProxyDev=%p pUrbLnx=%p\n", pProxyDev, pUrbLnx));
|
---|
341 |
|
---|
342 | /*
|
---|
343 | * Link it into the free list.
|
---|
344 | */
|
---|
345 | RTCritSectEnter(&pDevLnx->CritSect);
|
---|
346 | RTListAppend(&pDevLnx->ListFree, &pUrbLnx->NodeList);
|
---|
347 | RTCritSectLeave(&pDevLnx->CritSect);
|
---|
348 | }
|
---|
349 |
|
---|
350 |
|
---|
351 | /**
|
---|
352 | * Frees split list of a linux URB request structure.
|
---|
353 | *
|
---|
354 | * @param pProxyDev The proxy device instance.
|
---|
355 | * @param pUrbLnx A linux URB to in the split list to be freed.
|
---|
356 | */
|
---|
357 | static void usbProxyLinuxUrbFreeSplitList(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pUrbLnx)
|
---|
358 | {
|
---|
359 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
360 |
|
---|
361 | LogFlowFunc(("pProxyDev=%p pUrbLnx=%p\n", pProxyDev, pUrbLnx));
|
---|
362 |
|
---|
363 | RTCritSectEnter(&pDevLnx->CritSect);
|
---|
364 |
|
---|
365 | pUrbLnx = pUrbLnx->pSplitHead;
|
---|
366 | Assert(pUrbLnx);
|
---|
367 | while (pUrbLnx)
|
---|
368 | {
|
---|
369 | PUSBPROXYURBLNX pFree = pUrbLnx;
|
---|
370 | pUrbLnx = pUrbLnx->pSplitNext;
|
---|
371 | Assert(pFree->pSplitHead);
|
---|
372 | pFree->pSplitHead = pFree->pSplitNext = NULL;
|
---|
373 | usbProxyLinuxUrbFree(pProxyDev, pFree);
|
---|
374 | }
|
---|
375 |
|
---|
376 | RTCritSectLeave(&pDevLnx->CritSect);
|
---|
377 | }
|
---|
378 |
|
---|
379 |
|
---|
380 | /**
|
---|
381 | * This finds the device in the /proc/bus/usb/bus/addr file and finds
|
---|
382 | * the config with an asterix.
|
---|
383 | *
|
---|
384 | * @returns The Cfg#.
|
---|
385 | * @returns -1 if no active config.
|
---|
386 | * @param pProxyDev The proxy device instance.
|
---|
387 | * @param pszDevNode The path to the device. We infere the location of
|
---|
388 | * the devices file, which bus and device number we're
|
---|
389 | * looking for.
|
---|
390 | * @param piFirstCfg The first configuration. (optional)
|
---|
391 | * @internal
|
---|
392 | */
|
---|
393 | static int usbProxyLinuxFindActiveConfigUsbfs(PUSBPROXYDEV pProxyDev, const char *pszDevNode, int *piFirstCfg)
|
---|
394 | {
|
---|
395 | RT_NOREF(pProxyDev);
|
---|
396 |
|
---|
397 | /*
|
---|
398 | * Set return defaults.
|
---|
399 | */
|
---|
400 | int iActiveCfg = -1;
|
---|
401 | if (piFirstCfg)
|
---|
402 | *piFirstCfg = 1;
|
---|
403 |
|
---|
404 | /*
|
---|
405 | * Parse the usbfs device node path and turn it into a path to the "devices" file,
|
---|
406 | * picking up the device number and bus along the way.
|
---|
407 | */
|
---|
408 | size_t cchDevNode = strlen(pszDevNode);
|
---|
409 | char *pszDevices = (char *)RTMemDupEx(pszDevNode, cchDevNode, sizeof("devices"));
|
---|
410 | AssertReturn(pszDevices, iActiveCfg);
|
---|
411 |
|
---|
412 | /* the device number */
|
---|
413 | char *psz = pszDevices + cchDevNode;
|
---|
414 | while (*psz != '/')
|
---|
415 | psz--;
|
---|
416 | Assert(pszDevices < psz);
|
---|
417 | uint32_t uDev;
|
---|
418 | int rc = RTStrToUInt32Ex(psz + 1, NULL, 10, &uDev);
|
---|
419 | if (RT_SUCCESS(rc))
|
---|
420 | {
|
---|
421 | /* the bus number */
|
---|
422 | *psz-- = '\0';
|
---|
423 | while (*psz != '/')
|
---|
424 | psz--;
|
---|
425 | Assert(pszDevices < psz);
|
---|
426 | uint32_t uBus;
|
---|
427 | rc = RTStrToUInt32Ex(psz + 1, NULL, 10, &uBus);
|
---|
428 | if (RT_SUCCESS(rc))
|
---|
429 | {
|
---|
430 | strcpy(psz + 1, "devices");
|
---|
431 |
|
---|
432 | /*
|
---|
433 | * Open and scan the devices file.
|
---|
434 | * We're ASSUMING that each device starts off with a 'T:' line.
|
---|
435 | */
|
---|
436 | PRTSTREAM pFile;
|
---|
437 | rc = RTStrmOpen(pszDevices, "r", &pFile);
|
---|
438 | if (RT_SUCCESS(rc))
|
---|
439 | {
|
---|
440 | char szLine[1024];
|
---|
441 | while (RT_SUCCESS(RTStrmGetLine(pFile, szLine, sizeof(szLine))))
|
---|
442 | {
|
---|
443 | /* we're only interested in 'T:' lines. */
|
---|
444 | psz = RTStrStripL(szLine);
|
---|
445 | if (psz[0] != 'T' || psz[1] != ':')
|
---|
446 | continue;
|
---|
447 |
|
---|
448 | /* Skip ahead to 'Bus' and compare */
|
---|
449 | psz = RTStrStripL(psz + 2); Assert(!strncmp(psz, RT_STR_TUPLE("Bus=")));
|
---|
450 | psz = RTStrStripL(psz + 4);
|
---|
451 | char *pszNext;
|
---|
452 | uint32_t u;
|
---|
453 | rc = RTStrToUInt32Ex(psz, &pszNext, 10, &u); AssertRC(rc);
|
---|
454 | if (RT_FAILURE(rc))
|
---|
455 | continue;
|
---|
456 | if (u != uBus)
|
---|
457 | continue;
|
---|
458 |
|
---|
459 | /* Skip ahead to 'Dev#' and compare */
|
---|
460 | psz = strstr(psz, "Dev#="); Assert(psz);
|
---|
461 | if (!psz)
|
---|
462 | continue;
|
---|
463 | psz = RTStrStripL(psz + 5);
|
---|
464 | rc = RTStrToUInt32Ex(psz, &pszNext, 10, &u); AssertRC(rc);
|
---|
465 | if (RT_FAILURE(rc))
|
---|
466 | continue;
|
---|
467 | if (u != uDev)
|
---|
468 | continue;
|
---|
469 |
|
---|
470 | /*
|
---|
471 | * Ok, we've found the device.
|
---|
472 | * Scan until we find a selected configuration, the next device, or EOF.
|
---|
473 | */
|
---|
474 | while (RT_SUCCESS(RTStrmGetLine(pFile, szLine, sizeof(szLine))))
|
---|
475 | {
|
---|
476 | psz = RTStrStripL(szLine);
|
---|
477 | if (psz[0] == 'T')
|
---|
478 | break;
|
---|
479 | if (psz[0] != 'C' || psz[1] != ':')
|
---|
480 | continue;
|
---|
481 | const bool fActive = psz[2] == '*';
|
---|
482 | if (!fActive && !piFirstCfg)
|
---|
483 | continue;
|
---|
484 |
|
---|
485 | /* Get the 'Cfg#' value. */
|
---|
486 | psz = strstr(psz, "Cfg#="); Assert(psz);
|
---|
487 | if (psz)
|
---|
488 | {
|
---|
489 | psz = RTStrStripL(psz + 5);
|
---|
490 | rc = RTStrToUInt32Ex(psz, &pszNext, 10, &u); AssertRC(rc);
|
---|
491 | if (RT_SUCCESS(rc))
|
---|
492 | {
|
---|
493 | if (piFirstCfg)
|
---|
494 | {
|
---|
495 | *piFirstCfg = u;
|
---|
496 | piFirstCfg = NULL;
|
---|
497 | }
|
---|
498 | if (fActive)
|
---|
499 | iActiveCfg = u;
|
---|
500 | }
|
---|
501 | }
|
---|
502 | if (fActive)
|
---|
503 | break;
|
---|
504 | }
|
---|
505 | break;
|
---|
506 | }
|
---|
507 | RTStrmClose(pFile);
|
---|
508 | }
|
---|
509 | }
|
---|
510 | }
|
---|
511 | RTMemFree(pszDevices);
|
---|
512 |
|
---|
513 | return iActiveCfg;
|
---|
514 | }
|
---|
515 |
|
---|
516 |
|
---|
517 | /**
|
---|
518 | * This finds the active configuration from sysfs.
|
---|
519 | *
|
---|
520 | * @returns The Cfg#.
|
---|
521 | * @returns -1 if no active config.
|
---|
522 | * @param pProxyDev The proxy device instance.
|
---|
523 | * @param pszPath The sysfs path for the device.
|
---|
524 | * @param piFirstCfg The first configuration. (optional)
|
---|
525 | * @internal
|
---|
526 | */
|
---|
527 | static int usbProxyLinuxFindActiveConfigSysfs(PUSBPROXYDEV pProxyDev, const char *pszPath, int *piFirstCfg)
|
---|
528 | {
|
---|
529 | #ifdef VBOX_USB_WITH_SYSFS
|
---|
530 | if (piFirstCfg != NULL)
|
---|
531 | *piFirstCfg = pProxyDev->paCfgDescs != NULL
|
---|
532 | ? pProxyDev->paCfgDescs[0].Core.bConfigurationValue
|
---|
533 | : 1;
|
---|
534 | int64_t bCfg = 0;
|
---|
535 | int rc = RTLinuxSysFsReadIntFile(10, &bCfg, "%s/bConfigurationValue", pszPath);
|
---|
536 | if (RT_FAILURE(rc))
|
---|
537 | bCfg = -1;
|
---|
538 | return (int)bCfg;
|
---|
539 | #else /* !VBOX_USB_WITH_SYSFS */
|
---|
540 | return -1;
|
---|
541 | #endif /* !VBOX_USB_WITH_SYSFS */
|
---|
542 | }
|
---|
543 |
|
---|
544 |
|
---|
545 | /**
|
---|
546 | * This finds the active configuration.
|
---|
547 | *
|
---|
548 | * @returns The Cfg#.
|
---|
549 | * @returns -1 if no active config.
|
---|
550 | * @param pProxyDev The proxy device instance.
|
---|
551 | * @param pszPath The sysfs path for the device, or the usbfs device
|
---|
552 | * node path.
|
---|
553 | * @param piFirstCfg The first configuration. (optional)
|
---|
554 | * @internal
|
---|
555 | */
|
---|
556 | static int usbProxyLinuxFindActiveConfig(PUSBPROXYDEV pProxyDev, const char *pszPath, int *piFirstCfg)
|
---|
557 | {
|
---|
558 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
559 | if (pDevLnx->fUsingSysfs)
|
---|
560 | return usbProxyLinuxFindActiveConfigSysfs(pProxyDev, pszPath, piFirstCfg);
|
---|
561 | return usbProxyLinuxFindActiveConfigUsbfs(pProxyDev, pszPath, piFirstCfg);
|
---|
562 | }
|
---|
563 |
|
---|
564 |
|
---|
565 | /**
|
---|
566 | * Extracts the Linux file descriptor associated with the kernel USB device.
|
---|
567 | * This is used by rdesktop-vrdp for polling for events.
|
---|
568 | * @returns the FD, or asserts and returns -1 on error
|
---|
569 | * @param pProxyDev The device instance
|
---|
570 | */
|
---|
571 | RTDECL(int) USBProxyDeviceLinuxGetFD(PUSBPROXYDEV pProxyDev)
|
---|
572 | {
|
---|
573 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
574 | AssertReturn(pDevLnx->hFile != NIL_RTFILE, -1);
|
---|
575 | return RTFileToNative(pDevLnx->hFile);
|
---|
576 | }
|
---|
577 |
|
---|
578 |
|
---|
579 | /**
|
---|
580 | * Opens the device file.
|
---|
581 | *
|
---|
582 | * @returns VBox status code.
|
---|
583 | * @param pProxyDev The device instance.
|
---|
584 | * @param pszAddress If we are using usbfs, this is the path to the
|
---|
585 | * device. If we are using sysfs, this is a string of
|
---|
586 | * the form "sysfs:<sysfs path>//device:<device node>".
|
---|
587 | * In the second case, the two paths are guaranteed
|
---|
588 | * not to contain the substring "//".
|
---|
589 | * @param pvBackend Backend specific pointer, unused for the linux backend.
|
---|
590 | */
|
---|
591 | static DECLCALLBACK(int) usbProxyLinuxOpen(PUSBPROXYDEV pProxyDev, const char *pszAddress, void *pvBackend)
|
---|
592 | {
|
---|
593 | LogFlow(("usbProxyLinuxOpen: pProxyDev=%p pszAddress=%s\n", pProxyDev, pszAddress));
|
---|
594 | const char *pszDevNode;
|
---|
595 | const char *pszPath;
|
---|
596 | size_t cchPath;
|
---|
597 | bool fUsingSysfs;
|
---|
598 |
|
---|
599 | /*
|
---|
600 | * Are we using sysfs or usbfs?
|
---|
601 | */
|
---|
602 | #ifdef VBOX_USB_WITH_SYSFS
|
---|
603 | fUsingSysfs = strncmp(pszAddress, RT_STR_TUPLE("sysfs:")) == 0;
|
---|
604 | if (fUsingSysfs)
|
---|
605 | {
|
---|
606 | pszDevNode = strstr(pszAddress, "//device:");
|
---|
607 | if (!pszDevNode)
|
---|
608 | {
|
---|
609 | LogRel(("usbProxyLinuxOpen: Invalid device address: '%s'\n", pszAddress));
|
---|
610 | return VERR_INVALID_PARAMETER;
|
---|
611 | }
|
---|
612 |
|
---|
613 | pszPath = pszAddress + sizeof("sysfs:") - 1;
|
---|
614 | cchPath = pszDevNode - pszPath;
|
---|
615 | pszDevNode += sizeof("//device:") - 1;
|
---|
616 | }
|
---|
617 | else
|
---|
618 | #endif /* VBOX_USB_WITH_SYSFS */
|
---|
619 | {
|
---|
620 | #ifndef VBOX_USB_WITH_SYSFS
|
---|
621 | fUsingSysfs = false;
|
---|
622 | #endif
|
---|
623 | pszPath = pszDevNode = pszAddress;
|
---|
624 | cchPath = strlen(pszPath);
|
---|
625 | }
|
---|
626 |
|
---|
627 | /*
|
---|
628 | * Try open the device node.
|
---|
629 | */
|
---|
630 | RTFILE hFile;
|
---|
631 | int rc = RTFileOpen(&hFile, pszDevNode, RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
|
---|
632 | if (RT_SUCCESS(rc))
|
---|
633 | {
|
---|
634 | /*
|
---|
635 | * Initialize the linux backend data.
|
---|
636 | */
|
---|
637 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
638 |
|
---|
639 | RTListInit(&pDevLnx->ListFree);
|
---|
640 | RTListInit(&pDevLnx->ListInFlight);
|
---|
641 | pDevLnx->pszPath = RTStrDupN(pszPath, cchPath);
|
---|
642 | if (pDevLnx->pszPath)
|
---|
643 | {
|
---|
644 | rc = RTPipeCreate(&pDevLnx->hPipeWakeupR, &pDevLnx->hPipeWakeupW, 0);
|
---|
645 | if (RT_SUCCESS(rc))
|
---|
646 | {
|
---|
647 | pDevLnx->fUsingSysfs = fUsingSysfs;
|
---|
648 | pDevLnx->hFile = hFile;
|
---|
649 | pDevLnx->fClaimedIfsMask = 0;
|
---|
650 | rc = RTCritSectInit(&pDevLnx->CritSect);
|
---|
651 | if (RT_SUCCESS(rc))
|
---|
652 | {
|
---|
653 | LogFlow(("usbProxyLinuxOpen(%p, %s): returns successfully File=%RTfile iActiveCfg=%d\n",
|
---|
654 | pProxyDev, pszAddress, pDevLnx->hFile, pProxyDev->iActiveCfg));
|
---|
655 |
|
---|
656 | return VINF_SUCCESS;
|
---|
657 | }
|
---|
658 | RTPipeClose(pDevLnx->hPipeWakeupR);
|
---|
659 | RTPipeClose(pDevLnx->hPipeWakeupW);
|
---|
660 | }
|
---|
661 | }
|
---|
662 | else
|
---|
663 | rc = VERR_NO_MEMORY;
|
---|
664 |
|
---|
665 | RTFileClose(hFile);
|
---|
666 | }
|
---|
667 | else if (rc == VERR_ACCESS_DENIED)
|
---|
668 | rc = VERR_VUSB_USBFS_PERMISSION;
|
---|
669 |
|
---|
670 | Log(("usbProxyLinuxOpen(%p, %s) failed, rc=%Rrc!\n", pProxyDev, pszAddress, rc));
|
---|
671 |
|
---|
672 | NOREF(pvBackend);
|
---|
673 | return rc;
|
---|
674 | }
|
---|
675 |
|
---|
676 |
|
---|
677 | /**
|
---|
678 | * Claims all the interfaces and figures out the
|
---|
679 | * current configuration.
|
---|
680 | *
|
---|
681 | * @returns VINF_SUCCESS.
|
---|
682 | * @param pProxyDev The proxy device.
|
---|
683 | */
|
---|
684 | static DECLCALLBACK(int) usbProxyLinuxInit(PUSBPROXYDEV pProxyDev)
|
---|
685 | {
|
---|
686 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
687 |
|
---|
688 | /*
|
---|
689 | * Brute force rulez.
|
---|
690 | * usbProxyLinuxSetConnected check for masked interfaces.
|
---|
691 | */
|
---|
692 | unsigned iIf;
|
---|
693 | for (iIf = 0; iIf < 256; iIf++)
|
---|
694 | usbProxyLinuxSetConnected(pProxyDev, iIf, false, true);
|
---|
695 |
|
---|
696 | /*
|
---|
697 | * Determine the active configuration.
|
---|
698 | *
|
---|
699 | * If there isn't any active configuration, we will get EHOSTUNREACH (113) errors
|
---|
700 | * when trying to read the device descriptors in usbProxyDevCreate. So, we'll make
|
---|
701 | * the first one active (usually 1) then.
|
---|
702 | */
|
---|
703 | pProxyDev->cIgnoreSetConfigs = 1;
|
---|
704 | int iFirstCfg;
|
---|
705 | pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->pszPath, &iFirstCfg);
|
---|
706 | if (pProxyDev->iActiveCfg == -1)
|
---|
707 | {
|
---|
708 | usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_SETCONFIGURATION, &iFirstCfg, false, UINT32_MAX);
|
---|
709 | pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->pszPath, NULL);
|
---|
710 | Log(("usbProxyLinuxInit: No active config! Tried to set %d: iActiveCfg=%d\n", iFirstCfg, pProxyDev->iActiveCfg));
|
---|
711 | }
|
---|
712 | else
|
---|
713 | Log(("usbProxyLinuxInit(%p): iActiveCfg=%d\n", pProxyDev, pProxyDev->iActiveCfg));
|
---|
714 | return VINF_SUCCESS;
|
---|
715 | }
|
---|
716 |
|
---|
717 |
|
---|
718 | /**
|
---|
719 | * Closes the proxy device.
|
---|
720 | */
|
---|
721 | static DECLCALLBACK(void) usbProxyLinuxClose(PUSBPROXYDEV pProxyDev)
|
---|
722 | {
|
---|
723 | LogFlow(("usbProxyLinuxClose: pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
|
---|
724 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
725 | AssertPtrReturnVoid(pDevLnx);
|
---|
726 |
|
---|
727 | /*
|
---|
728 | * Try put the device in a state which linux can cope with before we release it.
|
---|
729 | * Resetting it would be a nice start, although we must remember
|
---|
730 | * that it might have been disconnected...
|
---|
731 | *
|
---|
732 | * Don't reset if we're masking interfaces or if construction failed.
|
---|
733 | */
|
---|
734 | if (pProxyDev->fInited)
|
---|
735 | {
|
---|
736 | /* ASSUMES: thread == EMT */
|
---|
737 | if ( pProxyDev->fMaskedIfs
|
---|
738 | || !usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_RESET, NULL, false, 10))
|
---|
739 | {
|
---|
740 | /* Connect drivers. */
|
---|
741 | unsigned iIf;
|
---|
742 | for (iIf = 0; iIf < 256; iIf++)
|
---|
743 | usbProxyLinuxSetConnected(pProxyDev, iIf, true, true);
|
---|
744 | Log(("USB: Successfully reset device pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
|
---|
745 | }
|
---|
746 | else if (errno != ENODEV)
|
---|
747 | LogRel(("USB: Reset failed, errno=%d, pProxyDev=%s.\n", errno, usbProxyGetName(pProxyDev)));
|
---|
748 | else /* This will happen if device was detached. */
|
---|
749 | Log(("USB: Reset failed, errno=%d (ENODEV), pProxyDev=%s.\n", errno, usbProxyGetName(pProxyDev)));
|
---|
750 | }
|
---|
751 |
|
---|
752 | /*
|
---|
753 | * Now we can free all the resources and close the device.
|
---|
754 | */
|
---|
755 | RTCritSectDelete(&pDevLnx->CritSect);
|
---|
756 |
|
---|
757 | PUSBPROXYURBLNX pUrbLnx;
|
---|
758 | PUSBPROXYURBLNX pUrbLnxNext;
|
---|
759 | RTListForEachSafe(&pDevLnx->ListInFlight, pUrbLnx, pUrbLnxNext, USBPROXYURBLNX, NodeList)
|
---|
760 | {
|
---|
761 | RTListNodeRemove(&pUrbLnx->NodeList);
|
---|
762 |
|
---|
763 | if ( usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_DISCARDURB, &pUrbLnx->KUrb, false, UINT32_MAX)
|
---|
764 | && errno != ENODEV
|
---|
765 | && errno != ENOENT)
|
---|
766 | AssertMsgFailed(("errno=%d\n", errno));
|
---|
767 |
|
---|
768 | if (pUrbLnx->pSplitHead)
|
---|
769 | {
|
---|
770 | PUSBPROXYURBLNX pCur = pUrbLnx->pSplitNext;
|
---|
771 | while (pCur)
|
---|
772 | {
|
---|
773 | PUSBPROXYURBLNX pFree = pCur;
|
---|
774 | pCur = pFree->pSplitNext;
|
---|
775 | if ( !pFree->fSplitElementReaped
|
---|
776 | && usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_DISCARDURB, &pFree->KUrb, false, UINT32_MAX)
|
---|
777 | && errno != ENODEV
|
---|
778 | && errno != ENOENT)
|
---|
779 | AssertMsgFailed(("errno=%d\n", errno));
|
---|
780 | RTMemFree(pFree);
|
---|
781 | }
|
---|
782 | }
|
---|
783 | else
|
---|
784 | Assert(!pUrbLnx->pSplitNext);
|
---|
785 | RTMemFree(pUrbLnx);
|
---|
786 | }
|
---|
787 |
|
---|
788 | RTListForEachSafe(&pDevLnx->ListFree, pUrbLnx, pUrbLnxNext, USBPROXYURBLNX, NodeList)
|
---|
789 | {
|
---|
790 | RTListNodeRemove(&pUrbLnx->NodeList);
|
---|
791 | RTMemFree(pUrbLnx);
|
---|
792 | }
|
---|
793 |
|
---|
794 | RTFileClose(pDevLnx->hFile);
|
---|
795 | pDevLnx->hFile = NIL_RTFILE;
|
---|
796 |
|
---|
797 | RTPipeClose(pDevLnx->hPipeWakeupR);
|
---|
798 | RTPipeClose(pDevLnx->hPipeWakeupW);
|
---|
799 |
|
---|
800 | RTStrFree(pDevLnx->pszPath);
|
---|
801 |
|
---|
802 | LogFlow(("usbProxyLinuxClose: returns\n"));
|
---|
803 | }
|
---|
804 |
|
---|
805 |
|
---|
806 | /** @interface_method_impl{USBPROXYBACK,pfnReset} */
|
---|
807 | static DECLCALLBACK(int) usbProxyLinuxReset(PUSBPROXYDEV pProxyDev, bool fResetOnLinux)
|
---|
808 | {
|
---|
809 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
810 | RT_NOREF(fResetOnLinux);
|
---|
811 | Assert(!pProxyDev->fMaskedIfs);
|
---|
812 | LogFlow(("usbProxyLinuxReset: pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
|
---|
813 |
|
---|
814 | uint32_t fActiveIfsMask = pDevLnx->fClaimedIfsMask;
|
---|
815 | unsigned i;
|
---|
816 |
|
---|
817 | /*
|
---|
818 | * Before reset, release claimed interfaces. This less than obvious move
|
---|
819 | * prevents Linux from rebinding in-kernel drivers to the device after reset.
|
---|
820 | */
|
---|
821 | for (i = 0; i < (sizeof(fActiveIfsMask) * 8); ++i)
|
---|
822 | {
|
---|
823 | if (fActiveIfsMask & RT_BIT(i))
|
---|
824 | {
|
---|
825 | usbProxyLinuxReleaseInterface(pProxyDev, i);
|
---|
826 | }
|
---|
827 | }
|
---|
828 |
|
---|
829 | if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_RESET, NULL, false, 10))
|
---|
830 | {
|
---|
831 | int rc = errno;
|
---|
832 | LogRel(("usb-linux: Reset failed, rc=%Rrc errno=%d.\n", RTErrConvertFromErrno(rc), rc));
|
---|
833 | pProxyDev->iActiveCfg = -1;
|
---|
834 | return RTErrConvertFromErrno(rc);
|
---|
835 | }
|
---|
836 |
|
---|
837 | /*
|
---|
838 | * Now reclaim previously claimed interfaces. If that doesn't work, let's hope
|
---|
839 | * the guest/VUSB can recover from that. Can happen if reset changes configuration.
|
---|
840 | */
|
---|
841 | for (i = 0; i < (sizeof(fActiveIfsMask) * 8); ++i)
|
---|
842 | {
|
---|
843 | if (fActiveIfsMask & RT_BIT(i))
|
---|
844 | {
|
---|
845 | usbProxyLinuxClaimInterface(pProxyDev, i);
|
---|
846 | }
|
---|
847 | }
|
---|
848 |
|
---|
849 | /* find the active config - damn annoying. */
|
---|
850 | pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->pszPath, NULL);
|
---|
851 | LogFlow(("usbProxyLinuxReset: returns successfully iActiveCfg=%d\n", pProxyDev->iActiveCfg));
|
---|
852 |
|
---|
853 | pProxyDev->cIgnoreSetConfigs = 2;
|
---|
854 | return VINF_SUCCESS;
|
---|
855 | }
|
---|
856 |
|
---|
857 |
|
---|
858 | /**
|
---|
859 | * SET_CONFIGURATION.
|
---|
860 | *
|
---|
861 | * The caller makes sure that it's not called first time after open or reset
|
---|
862 | * with the active interface.
|
---|
863 | *
|
---|
864 | * @returns success indicator.
|
---|
865 | * @param pProxyDev The device instance data.
|
---|
866 | * @param iCfg The configuration to set.
|
---|
867 | */
|
---|
868 | static DECLCALLBACK(int) usbProxyLinuxSetConfig(PUSBPROXYDEV pProxyDev, int iCfg)
|
---|
869 | {
|
---|
870 | LogFlow(("usbProxyLinuxSetConfig: pProxyDev=%s cfg=%#x\n",
|
---|
871 | usbProxyGetName(pProxyDev), iCfg));
|
---|
872 |
|
---|
873 | if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_SETCONFIGURATION, &iCfg, true, UINT32_MAX))
|
---|
874 | {
|
---|
875 | Log(("usb-linux: Set configuration. errno=%d\n", errno));
|
---|
876 | return RTErrConvertFromErrno(errno);
|
---|
877 | }
|
---|
878 | return VINF_SUCCESS;
|
---|
879 | }
|
---|
880 |
|
---|
881 |
|
---|
882 | /**
|
---|
883 | * Claims an interface.
|
---|
884 | * @returns success indicator.
|
---|
885 | */
|
---|
886 | static DECLCALLBACK(int) usbProxyLinuxClaimInterface(PUSBPROXYDEV pProxyDev, int iIf)
|
---|
887 | {
|
---|
888 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
889 |
|
---|
890 | LogFlow(("usbProxyLinuxClaimInterface: pProxyDev=%s ifnum=%#x\n", usbProxyGetName(pProxyDev), iIf));
|
---|
891 | usbProxyLinuxSetConnected(pProxyDev, iIf, false, false);
|
---|
892 |
|
---|
893 | if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_CLAIMINTERFACE, &iIf, true, UINT32_MAX))
|
---|
894 | {
|
---|
895 | pDevLnx->fClaimedIfsMask &= ~RT_BIT(iIf);
|
---|
896 | LogRel(("usb-linux: Claim interface. errno=%d pProxyDev=%s\n", errno, usbProxyGetName(pProxyDev)));
|
---|
897 | return RTErrConvertFromErrno(errno);
|
---|
898 | }
|
---|
899 | pDevLnx->fClaimedIfsMask |= RT_BIT(iIf);
|
---|
900 | return VINF_SUCCESS;
|
---|
901 | }
|
---|
902 |
|
---|
903 |
|
---|
904 | /**
|
---|
905 | * Releases an interface.
|
---|
906 | * @returns success indicator.
|
---|
907 | */
|
---|
908 | static DECLCALLBACK(int) usbProxyLinuxReleaseInterface(PUSBPROXYDEV pProxyDev, int iIf)
|
---|
909 | {
|
---|
910 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
911 |
|
---|
912 | LogFlow(("usbProxyLinuxReleaseInterface: pProxyDev=%s ifnum=%#x\n", usbProxyGetName(pProxyDev), iIf));
|
---|
913 |
|
---|
914 | if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_RELEASEINTERFACE, &iIf, true, UINT32_MAX))
|
---|
915 | {
|
---|
916 | LogRel(("usb-linux: Release interface, errno=%d. pProxyDev=%s\n", errno, usbProxyGetName(pProxyDev)));
|
---|
917 | return RTErrConvertFromErrno(errno);
|
---|
918 | }
|
---|
919 | pDevLnx->fClaimedIfsMask &= ~RT_BIT(iIf);
|
---|
920 | return VINF_SUCCESS;
|
---|
921 | }
|
---|
922 |
|
---|
923 |
|
---|
924 | /**
|
---|
925 | * SET_INTERFACE.
|
---|
926 | *
|
---|
927 | * @returns success indicator.
|
---|
928 | */
|
---|
929 | static DECLCALLBACK(int) usbProxyLinuxSetInterface(PUSBPROXYDEV pProxyDev, int iIf, int iAlt)
|
---|
930 | {
|
---|
931 | struct usbdevfs_setinterface SetIf;
|
---|
932 | LogFlow(("usbProxyLinuxSetInterface: pProxyDev=%p iIf=%#x iAlt=%#x\n", pProxyDev, iIf, iAlt));
|
---|
933 |
|
---|
934 | SetIf.interface = iIf;
|
---|
935 | SetIf.altsetting = iAlt;
|
---|
936 | if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_SETINTERFACE, &SetIf, true, UINT32_MAX))
|
---|
937 | {
|
---|
938 | Log(("usb-linux: Set interface, errno=%d. pProxyDev=%s\n", errno, usbProxyGetName(pProxyDev)));
|
---|
939 | return RTErrConvertFromErrno(errno);
|
---|
940 | }
|
---|
941 | return VINF_SUCCESS;
|
---|
942 | }
|
---|
943 |
|
---|
944 |
|
---|
945 | /**
|
---|
946 | * Clears the halted endpoint 'EndPt'.
|
---|
947 | */
|
---|
948 | static DECLCALLBACK(int) usbProxyLinuxClearHaltedEp(PUSBPROXYDEV pProxyDev, unsigned int EndPt)
|
---|
949 | {
|
---|
950 | LogFlow(("usbProxyLinuxClearHaltedEp: pProxyDev=%s EndPt=%u\n", usbProxyGetName(pProxyDev), EndPt));
|
---|
951 |
|
---|
952 | if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_CLEAR_HALT, &EndPt, true, UINT32_MAX))
|
---|
953 | {
|
---|
954 | /*
|
---|
955 | * Unfortunately this doesn't work on control pipes.
|
---|
956 | * Windows doing this on the default endpoint and possibly other pipes too,
|
---|
957 | * so we'll feign success for ENOENT errors.
|
---|
958 | */
|
---|
959 | if (errno == ENOENT)
|
---|
960 | {
|
---|
961 | Log(("usb-linux: clear_halted_ep failed errno=%d. pProxyDev=%s ep=%d - IGNORED\n",
|
---|
962 | errno, usbProxyGetName(pProxyDev), EndPt));
|
---|
963 | return VINF_SUCCESS;
|
---|
964 | }
|
---|
965 | Log(("usb-linux: clear_halted_ep failed errno=%d. pProxyDev=%s ep=%d\n",
|
---|
966 | errno, usbProxyGetName(pProxyDev), EndPt));
|
---|
967 | return RTErrConvertFromErrno(errno);
|
---|
968 | }
|
---|
969 | return VINF_SUCCESS;
|
---|
970 | }
|
---|
971 |
|
---|
972 |
|
---|
973 | /**
|
---|
974 | * Setup packet byte-swapping routines.
|
---|
975 | */
|
---|
976 | static void usbProxyLinuxUrbSwapSetup(PVUSBSETUP pSetup)
|
---|
977 | {
|
---|
978 | pSetup->wValue = RT_H2LE_U16(pSetup->wValue);
|
---|
979 | pSetup->wIndex = RT_H2LE_U16(pSetup->wIndex);
|
---|
980 | pSetup->wLength = RT_H2LE_U16(pSetup->wLength);
|
---|
981 | }
|
---|
982 |
|
---|
983 |
|
---|
984 | /**
|
---|
985 | * Clean up after a failed URB submit.
|
---|
986 | */
|
---|
987 | static void usbProxyLinuxCleanupFailedSubmit(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pUrbLnx, PUSBPROXYURBLNX pCur, PVUSBURB pUrb, bool *pfUnplugged)
|
---|
988 | {
|
---|
989 | if (pUrb->enmType == VUSBXFERTYPE_MSG)
|
---|
990 | usbProxyLinuxUrbSwapSetup((PVUSBSETUP)pUrb->abData);
|
---|
991 |
|
---|
992 | /* discard and reap later (walking with pUrbLnx). */
|
---|
993 | if (pUrbLnx != pCur)
|
---|
994 | {
|
---|
995 | for (;;)
|
---|
996 | {
|
---|
997 | pUrbLnx->fCanceledBySubmit = true;
|
---|
998 | pUrbLnx->KUrb.usercontext = NULL;
|
---|
999 | if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_DISCARDURB, &pUrbLnx->KUrb, false, UINT32_MAX))
|
---|
1000 | {
|
---|
1001 | if (errno == ENODEV)
|
---|
1002 | *pfUnplugged = true;
|
---|
1003 | else if (errno == ENOENT)
|
---|
1004 | pUrbLnx->fSplitElementReaped = true;
|
---|
1005 | else
|
---|
1006 | LogRel(("USB: Failed to discard %p! errno=%d (pUrb=%p)\n", pUrbLnx->KUrb.usercontext, errno, pUrb)); /* serious! */
|
---|
1007 | }
|
---|
1008 | if (pUrbLnx->pSplitNext == pCur)
|
---|
1009 | {
|
---|
1010 | pUrbLnx->pSplitNext = NULL;
|
---|
1011 | break;
|
---|
1012 | }
|
---|
1013 | pUrbLnx = pUrbLnx->pSplitNext; Assert(pUrbLnx);
|
---|
1014 | }
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | /* free the unsubmitted ones. */
|
---|
1018 | while (pCur)
|
---|
1019 | {
|
---|
1020 | PUSBPROXYURBLNX pFree = pCur;
|
---|
1021 | pCur = pCur->pSplitNext;
|
---|
1022 | usbProxyLinuxUrbFree(pProxyDev, pFree);
|
---|
1023 | }
|
---|
1024 |
|
---|
1025 | /* send unplug event if we failed with ENODEV originally. */
|
---|
1026 | if (*pfUnplugged)
|
---|
1027 | usbProxLinuxUrbUnplugged(pProxyDev);
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 | /**
|
---|
1031 | * Submit one URB through the usbfs IOCTL interface, with
|
---|
1032 | * retries
|
---|
1033 | *
|
---|
1034 | * @returns VBox status code.
|
---|
1035 | */
|
---|
1036 | static int usbProxyLinuxSubmitURB(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pCur, PVUSBURB pUrb, bool *pfUnplugged)
|
---|
1037 | {
|
---|
1038 | RT_NOREF(pUrb);
|
---|
1039 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
1040 | unsigned cTries = 0;
|
---|
1041 |
|
---|
1042 | while (ioctl(RTFileToNative(pDevLnx->hFile), USBDEVFS_SUBMITURB, &pCur->KUrb))
|
---|
1043 | {
|
---|
1044 | if (errno == EINTR)
|
---|
1045 | continue;
|
---|
1046 | if (errno == ENODEV)
|
---|
1047 | {
|
---|
1048 | Log(("usbProxyLinuxSubmitURB: ENODEV -> unplugged. pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
|
---|
1049 | *pfUnplugged = true;
|
---|
1050 | return RTErrConvertFromErrno(errno);
|
---|
1051 | }
|
---|
1052 |
|
---|
1053 | Log(("usb-linux: Submit URB %p -> %d!!! type=%d ep=%#x buffer_length=%#x cTries=%d\n",
|
---|
1054 | pUrb, errno, pCur->KUrb.type, pCur->KUrb.endpoint, pCur->KUrb.buffer_length, cTries));
|
---|
1055 | if (errno != EBUSY && ++cTries < 3) /* this doesn't work for the floppy :/ */
|
---|
1056 | continue;
|
---|
1057 |
|
---|
1058 | return RTErrConvertFromErrno(errno);
|
---|
1059 | }
|
---|
1060 | return VINF_SUCCESS;
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | /** The split size. 16K in known Linux kernel versions. */
|
---|
1064 | #define SPLIT_SIZE 0x4000
|
---|
1065 |
|
---|
1066 | /**
|
---|
1067 | * Create a URB fragment of up to SPLIT_SIZE size and hook it
|
---|
1068 | * into the list of fragments.
|
---|
1069 | *
|
---|
1070 | * @returns pointer to newly allocated URB fragment or NULL.
|
---|
1071 | */
|
---|
1072 | static PUSBPROXYURBLNX usbProxyLinuxSplitURBFragment(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pHead, PUSBPROXYURBLNX pCur)
|
---|
1073 | {
|
---|
1074 | PUSBPROXYURBLNX pNew;
|
---|
1075 | uint32_t cbLeft = pCur->cbSplitRemaining;
|
---|
1076 | uint8_t *pb = (uint8_t *)pCur->KUrb.buffer;
|
---|
1077 |
|
---|
1078 | LogFlowFunc(("pProxyDev=%p pHead=%p pCur=%p\n", pProxyDev, pHead, pCur));
|
---|
1079 |
|
---|
1080 | Assert(cbLeft != 0);
|
---|
1081 | pNew = pCur->pSplitNext = usbProxyLinuxUrbAlloc(pProxyDev, pHead);
|
---|
1082 | if (!pNew)
|
---|
1083 | {
|
---|
1084 | usbProxyLinuxUrbFreeSplitList(pProxyDev, pHead);
|
---|
1085 | return NULL;
|
---|
1086 | }
|
---|
1087 | Assert(pNew->pSplitHead == pHead);
|
---|
1088 | Assert(pNew->pSplitNext == NULL);
|
---|
1089 |
|
---|
1090 | pNew->KUrb = pHead->KUrb;
|
---|
1091 | pNew->KUrb.buffer = pb + pCur->KUrb.buffer_length;
|
---|
1092 | pNew->KUrb.buffer_length = RT_MIN(cbLeft, SPLIT_SIZE);
|
---|
1093 | pNew->KUrb.actual_length = 0;
|
---|
1094 |
|
---|
1095 | cbLeft -= pNew->KUrb.buffer_length;
|
---|
1096 | Assert(cbLeft < INT32_MAX);
|
---|
1097 | pNew->cbSplitRemaining = cbLeft;
|
---|
1098 | LogFlowFunc(("returns pNew=%p\n", pNew));
|
---|
1099 | return pNew;
|
---|
1100 | }
|
---|
1101 |
|
---|
1102 | /**
|
---|
1103 | * Try splitting up a VUSB URB into smaller URBs which the
|
---|
1104 | * linux kernel (usbfs) can deal with.
|
---|
1105 | *
|
---|
1106 | * NB: For ShortOK reads things get a little tricky - we don't
|
---|
1107 | * know how much data is going to arrive and not all the
|
---|
1108 | * fragment URBs might be filled. We can only safely set up one
|
---|
1109 | * URB at a time -> worse performance but correct behaviour.
|
---|
1110 | *
|
---|
1111 | * @returns VBox status code.
|
---|
1112 | * @param pProxyDev The proxy device.
|
---|
1113 | * @param pUrbLnx The linux URB which was rejected because of being too big.
|
---|
1114 | * @param pUrb The VUSB URB.
|
---|
1115 | */
|
---|
1116 | static int usbProxyLinuxUrbQueueSplit(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pUrbLnx, PVUSBURB pUrb)
|
---|
1117 | {
|
---|
1118 | /*
|
---|
1119 | * Split it up into SPLIT_SIZE sized blocks.
|
---|
1120 | */
|
---|
1121 | const unsigned cKUrbs = (pUrb->cbData + SPLIT_SIZE - 1) / SPLIT_SIZE;
|
---|
1122 | LogFlow(("usbProxyLinuxUrbQueueSplit: pUrb=%p cKUrbs=%d cbData=%d\n", pUrb, cKUrbs, pUrb->cbData));
|
---|
1123 |
|
---|
1124 | uint32_t cbLeft = pUrb->cbData;
|
---|
1125 | uint8_t *pb = &pUrb->abData[0];
|
---|
1126 |
|
---|
1127 | /* the first one (already allocated) */
|
---|
1128 | switch (pUrb->enmType)
|
---|
1129 | {
|
---|
1130 | default: /* shut up gcc */
|
---|
1131 | case VUSBXFERTYPE_BULK: pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_BULK; break;
|
---|
1132 | case VUSBXFERTYPE_INTR: pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_INTERRUPT; break;
|
---|
1133 | case VUSBXFERTYPE_MSG: pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_CONTROL; break;
|
---|
1134 | case VUSBXFERTYPE_ISOC:
|
---|
1135 | AssertMsgFailed(("We can't split isochronous URBs!\n"));
|
---|
1136 | usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
|
---|
1137 | return VERR_INVALID_PARAMETER; /** @todo Better status code. */
|
---|
1138 | }
|
---|
1139 | pUrbLnx->KUrb.endpoint = pUrb->EndPt;
|
---|
1140 | if (pUrb->enmDir == VUSBDIRECTION_IN)
|
---|
1141 | pUrbLnx->KUrb.endpoint |= 0x80;
|
---|
1142 | pUrbLnx->KUrb.flags = 0;
|
---|
1143 | if (pUrb->enmDir == VUSBDIRECTION_IN && pUrb->fShortNotOk)
|
---|
1144 | pUrbLnx->KUrb.flags |= USBDEVFS_URB_SHORT_NOT_OK;
|
---|
1145 | pUrbLnx->KUrb.status = 0;
|
---|
1146 | pUrbLnx->KUrb.buffer = pb;
|
---|
1147 | pUrbLnx->KUrb.buffer_length = RT_MIN(cbLeft, SPLIT_SIZE);
|
---|
1148 | pUrbLnx->KUrb.actual_length = 0;
|
---|
1149 | pUrbLnx->KUrb.start_frame = 0;
|
---|
1150 | pUrbLnx->KUrb.number_of_packets = 0;
|
---|
1151 | pUrbLnx->KUrb.error_count = 0;
|
---|
1152 | pUrbLnx->KUrb.signr = 0;
|
---|
1153 | pUrbLnx->KUrb.usercontext = pUrb;
|
---|
1154 | pUrbLnx->pSplitHead = pUrbLnx;
|
---|
1155 | pUrbLnx->pSplitNext = NULL;
|
---|
1156 |
|
---|
1157 | PUSBPROXYURBLNX pCur = pUrbLnx;
|
---|
1158 |
|
---|
1159 | cbLeft -= pUrbLnx->KUrb.buffer_length;
|
---|
1160 | pUrbLnx->cbSplitRemaining = cbLeft;
|
---|
1161 |
|
---|
1162 | int rc = VINF_SUCCESS;
|
---|
1163 | bool fUnplugged = false;
|
---|
1164 | if (pUrb->enmDir == VUSBDIRECTION_IN && !pUrb->fShortNotOk)
|
---|
1165 | {
|
---|
1166 | /* Subsequent fragments will be queued only after the previous fragment is reaped
|
---|
1167 | * and only if necessary.
|
---|
1168 | */
|
---|
1169 | Log(("usb-linux: Large ShortOK read, only queuing first fragment.\n"));
|
---|
1170 | Assert(pUrbLnx->cbSplitRemaining > 0 && pUrbLnx->cbSplitRemaining < 256 * _1K);
|
---|
1171 | rc = usbProxyLinuxSubmitURB(pProxyDev, pUrbLnx, pUrb, &fUnplugged);
|
---|
1172 | }
|
---|
1173 | else
|
---|
1174 | {
|
---|
1175 | /* the rest. */
|
---|
1176 | unsigned i;
|
---|
1177 | for (i = 1; i < cKUrbs; i++)
|
---|
1178 | {
|
---|
1179 | pCur = usbProxyLinuxSplitURBFragment(pProxyDev, pUrbLnx, pCur);
|
---|
1180 | if (!pCur)
|
---|
1181 | return VERR_NO_MEMORY;
|
---|
1182 | }
|
---|
1183 | Assert(pCur->cbSplitRemaining == 0);
|
---|
1184 |
|
---|
1185 | /* Submit the blocks. */
|
---|
1186 | pCur = pUrbLnx;
|
---|
1187 | for (i = 0; i < cKUrbs; i++, pCur = pCur->pSplitNext)
|
---|
1188 | {
|
---|
1189 | rc = usbProxyLinuxSubmitURB(pProxyDev, pCur, pUrb, &fUnplugged);
|
---|
1190 | if (RT_FAILURE(rc))
|
---|
1191 | break;
|
---|
1192 | }
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | if (RT_SUCCESS(rc))
|
---|
1196 | {
|
---|
1197 | pUrb->Dev.pvPrivate = pUrbLnx;
|
---|
1198 | usbProxyLinuxUrbLinkInFlight(USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX), pUrbLnx);
|
---|
1199 | LogFlow(("usbProxyLinuxUrbQueueSplit: ok\n"));
|
---|
1200 | return VINF_SUCCESS;
|
---|
1201 | }
|
---|
1202 |
|
---|
1203 | usbProxyLinuxCleanupFailedSubmit(pProxyDev, pUrbLnx, pCur, pUrb, &fUnplugged);
|
---|
1204 | return rc;
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 |
|
---|
1208 | /**
|
---|
1209 | * @interface_method_impl{USBPROXYBACK,pfnUrbQueue}
|
---|
1210 | */
|
---|
1211 | static DECLCALLBACK(int) usbProxyLinuxUrbQueue(PUSBPROXYDEV pProxyDev, PVUSBURB pUrb)
|
---|
1212 | {
|
---|
1213 | int rc = VINF_SUCCESS;
|
---|
1214 | unsigned cTries;
|
---|
1215 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
1216 | LogFlow(("usbProxyLinuxUrbQueue: pProxyDev=%s pUrb=%p EndPt=%d cbData=%d\n",
|
---|
1217 | usbProxyGetName(pProxyDev), pUrb, pUrb->EndPt, pUrb->cbData));
|
---|
1218 |
|
---|
1219 | /*
|
---|
1220 | * Allocate a linux urb.
|
---|
1221 | */
|
---|
1222 | PUSBPROXYURBLNX pUrbLnx = usbProxyLinuxUrbAlloc(pProxyDev, NULL);
|
---|
1223 | if (!pUrbLnx)
|
---|
1224 | return VERR_NO_MEMORY;
|
---|
1225 |
|
---|
1226 | pUrbLnx->KUrb.endpoint = pUrb->EndPt | (pUrb->enmDir == VUSBDIRECTION_IN ? 0x80 : 0);
|
---|
1227 | pUrbLnx->KUrb.status = 0;
|
---|
1228 | pUrbLnx->KUrb.flags = 0;
|
---|
1229 | if (pUrb->enmDir == VUSBDIRECTION_IN && pUrb->fShortNotOk)
|
---|
1230 | pUrbLnx->KUrb.flags |= USBDEVFS_URB_SHORT_NOT_OK;
|
---|
1231 | pUrbLnx->KUrb.buffer = pUrb->abData;
|
---|
1232 | pUrbLnx->KUrb.buffer_length = pUrb->cbData;
|
---|
1233 | pUrbLnx->KUrb.actual_length = 0;
|
---|
1234 | pUrbLnx->KUrb.start_frame = 0;
|
---|
1235 | pUrbLnx->KUrb.number_of_packets = 0;
|
---|
1236 | pUrbLnx->KUrb.error_count = 0;
|
---|
1237 | pUrbLnx->KUrb.signr = 0;
|
---|
1238 | pUrbLnx->KUrb.usercontext = pUrb;
|
---|
1239 |
|
---|
1240 | switch (pUrb->enmType)
|
---|
1241 | {
|
---|
1242 | case VUSBXFERTYPE_MSG:
|
---|
1243 | pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_CONTROL;
|
---|
1244 | if (pUrb->cbData < sizeof(VUSBSETUP))
|
---|
1245 | {
|
---|
1246 | usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
|
---|
1247 | return VERR_BUFFER_UNDERFLOW;
|
---|
1248 | }
|
---|
1249 | usbProxyLinuxUrbSwapSetup((PVUSBSETUP)pUrb->abData);
|
---|
1250 | LogFlow(("usbProxyLinuxUrbQueue: message\n"));
|
---|
1251 | break;
|
---|
1252 | case VUSBXFERTYPE_BULK:
|
---|
1253 | pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_BULK;
|
---|
1254 | break;
|
---|
1255 | case VUSBXFERTYPE_ISOC:
|
---|
1256 | pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_ISO;
|
---|
1257 | pUrbLnx->KUrb.flags |= USBDEVFS_URB_ISO_ASAP;
|
---|
1258 | pUrbLnx->KUrb.number_of_packets = pUrb->cIsocPkts;
|
---|
1259 | unsigned i;
|
---|
1260 | for (i = 0; i < pUrb->cIsocPkts; i++)
|
---|
1261 | {
|
---|
1262 | #if RT_GNUC_PREREQ(4, 6)
|
---|
1263 | # pragma GCC diagnostic push
|
---|
1264 | # pragma GCC diagnostic ignored "-Warray-bounds"
|
---|
1265 | #endif
|
---|
1266 | pUrbLnx->KUrb.iso_frame_desc[i].length = pUrb->aIsocPkts[i].cb;
|
---|
1267 | pUrbLnx->KUrb.iso_frame_desc[i].actual_length = 0;
|
---|
1268 | pUrbLnx->KUrb.iso_frame_desc[i].status = 0x7fff;
|
---|
1269 | #if RT_GNUC_PREREQ(4, 6)
|
---|
1270 | # pragma GCC diagnostic pop
|
---|
1271 | #endif
|
---|
1272 | }
|
---|
1273 | break;
|
---|
1274 | case VUSBXFERTYPE_INTR:
|
---|
1275 | pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_INTERRUPT;
|
---|
1276 | break;
|
---|
1277 | default:
|
---|
1278 | rc = VERR_INVALID_PARAMETER; /** @todo better status code. */
|
---|
1279 | }
|
---|
1280 |
|
---|
1281 | /*
|
---|
1282 | * We have to serialize access by using the critial section here because this
|
---|
1283 | * thread might be suspended after submitting the URB but before linking it into
|
---|
1284 | * the in flight list. This would get us in trouble when reaping the URB on another
|
---|
1285 | * thread while it isn't in the in flight list.
|
---|
1286 | *
|
---|
1287 | * Linking the URB into the list before submitting it like it was done in the past is not
|
---|
1288 | * possible either because submitting the URB might fail here because the device gets
|
---|
1289 | * detached. The reaper thread gets this event too and might race this thread before we
|
---|
1290 | * can unlink the URB from the active list and the common code might end up freeing
|
---|
1291 | * the common URB structure twice.
|
---|
1292 | */
|
---|
1293 | RTCritSectEnter(&pDevLnx->CritSect);
|
---|
1294 | /*
|
---|
1295 | * Submit it.
|
---|
1296 | */
|
---|
1297 | cTries = 0;
|
---|
1298 | while (ioctl(RTFileToNative(pDevLnx->hFile), USBDEVFS_SUBMITURB, &pUrbLnx->KUrb))
|
---|
1299 | {
|
---|
1300 | if (errno == EINTR)
|
---|
1301 | continue;
|
---|
1302 | if (errno == ENODEV)
|
---|
1303 | {
|
---|
1304 | rc = RTErrConvertFromErrno(errno);
|
---|
1305 | Log(("usbProxyLinuxUrbQueue: ENODEV -> unplugged. pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
|
---|
1306 | if (pUrb->enmType == VUSBXFERTYPE_MSG)
|
---|
1307 | usbProxyLinuxUrbSwapSetup((PVUSBSETUP)pUrb->abData);
|
---|
1308 |
|
---|
1309 | RTCritSectLeave(&pDevLnx->CritSect);
|
---|
1310 | usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
|
---|
1311 | usbProxLinuxUrbUnplugged(pProxyDev);
|
---|
1312 | return rc;
|
---|
1313 | }
|
---|
1314 |
|
---|
1315 | /*
|
---|
1316 | * usbfs has or used to have a low buffer limit (16KB) in order to prevent
|
---|
1317 | * processes wasting kmalloc'ed memory. It will return EINVAL if break that
|
---|
1318 | * limit, and we'll have to split the VUSB URB up into multiple linux URBs.
|
---|
1319 | *
|
---|
1320 | * Since this is a limit which is subject to change, we cannot check for it
|
---|
1321 | * before submitting the URB. We just have to try and fail.
|
---|
1322 | */
|
---|
1323 | if ( errno == EINVAL
|
---|
1324 | && pUrb->cbData >= 8*_1K)
|
---|
1325 | {
|
---|
1326 | rc = usbProxyLinuxUrbQueueSplit(pProxyDev, pUrbLnx, pUrb);
|
---|
1327 | RTCritSectLeave(&pDevLnx->CritSect);
|
---|
1328 | return rc;
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | Log(("usb-linux: Queue URB %p -> %d!!! type=%d ep=%#x buffer_length=%#x cTries=%d\n",
|
---|
1332 | pUrb, errno, pUrbLnx->KUrb.type, pUrbLnx->KUrb.endpoint, pUrbLnx->KUrb.buffer_length, cTries));
|
---|
1333 | if (errno != EBUSY && ++cTries < 3) /* this doesn't work for the floppy :/ */
|
---|
1334 | continue;
|
---|
1335 |
|
---|
1336 | RTCritSectLeave(&pDevLnx->CritSect);
|
---|
1337 | rc = RTErrConvertFromErrno(errno);
|
---|
1338 | if (pUrb->enmType == VUSBXFERTYPE_MSG)
|
---|
1339 | usbProxyLinuxUrbSwapSetup((PVUSBSETUP)pUrb->abData);
|
---|
1340 | usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
|
---|
1341 | return rc;
|
---|
1342 | }
|
---|
1343 |
|
---|
1344 | usbProxyLinuxUrbLinkInFlight(pDevLnx, pUrbLnx);
|
---|
1345 | RTCritSectLeave(&pDevLnx->CritSect);
|
---|
1346 |
|
---|
1347 | LogFlow(("usbProxyLinuxUrbQueue: ok\n"));
|
---|
1348 | pUrb->Dev.pvPrivate = pUrbLnx;
|
---|
1349 | return rc;
|
---|
1350 | }
|
---|
1351 |
|
---|
1352 |
|
---|
1353 | /**
|
---|
1354 | * Translate the linux status to a VUSB status.
|
---|
1355 | *
|
---|
1356 | * @remarks see cc_to_error in ohci.h, uhci_map_status in uhci-q.c,
|
---|
1357 | * sitd_complete+itd_complete in ehci-sched.c, and qtd_copy_status in
|
---|
1358 | * ehci-q.c.
|
---|
1359 | */
|
---|
1360 | static VUSBSTATUS vusbProxyLinuxStatusToVUsbStatus(int iStatus)
|
---|
1361 | {
|
---|
1362 | switch (iStatus)
|
---|
1363 | {
|
---|
1364 | /** @todo VUSBSTATUS_NOT_ACCESSED */
|
---|
1365 | case -EXDEV: /* iso transfer, partial result. */
|
---|
1366 | case 0:
|
---|
1367 | return VUSBSTATUS_OK;
|
---|
1368 |
|
---|
1369 | case -EILSEQ:
|
---|
1370 | return VUSBSTATUS_CRC;
|
---|
1371 |
|
---|
1372 | case -EREMOTEIO: /* ehci and ohci uses this for underflow error. */
|
---|
1373 | return VUSBSTATUS_DATA_UNDERRUN;
|
---|
1374 | case -EOVERFLOW:
|
---|
1375 | return VUSBSTATUS_DATA_OVERRUN;
|
---|
1376 |
|
---|
1377 | case -ETIME:
|
---|
1378 | case -ENODEV:
|
---|
1379 | return VUSBSTATUS_DNR;
|
---|
1380 |
|
---|
1381 | //case -ECOMM:
|
---|
1382 | // return VUSBSTATUS_BUFFER_OVERRUN;
|
---|
1383 | //case -ENOSR:
|
---|
1384 | // return VUSBSTATUS_BUFFER_UNDERRUN;
|
---|
1385 |
|
---|
1386 | case -EPROTO:
|
---|
1387 | Log(("vusbProxyLinuxStatusToVUsbStatus: DNR/EPPROTO!!\n"));
|
---|
1388 | return VUSBSTATUS_DNR;
|
---|
1389 |
|
---|
1390 | case -EPIPE:
|
---|
1391 | Log(("vusbProxyLinuxStatusToVUsbStatus: STALL/EPIPE!!\n"));
|
---|
1392 | return VUSBSTATUS_STALL;
|
---|
1393 |
|
---|
1394 | case -ESHUTDOWN:
|
---|
1395 | Log(("vusbProxyLinuxStatusToVUsbStatus: SHUTDOWN!!\n"));
|
---|
1396 | return VUSBSTATUS_STALL;
|
---|
1397 |
|
---|
1398 | case -ENOENT:
|
---|
1399 | Log(("vusbProxyLinuxStatusToVUsbStatus: ENOENT!!\n"));
|
---|
1400 | return VUSBSTATUS_STALL;
|
---|
1401 |
|
---|
1402 | default:
|
---|
1403 | Log(("vusbProxyLinuxStatusToVUsbStatus: status %d!!\n", iStatus));
|
---|
1404 | return VUSBSTATUS_STALL;
|
---|
1405 | }
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 |
|
---|
1409 | /**
|
---|
1410 | * Get and translates the linux status to a VUSB status.
|
---|
1411 | */
|
---|
1412 | static VUSBSTATUS vusbProxyLinuxUrbGetStatus(PUSBPROXYURBLNX pUrbLnx)
|
---|
1413 | {
|
---|
1414 | return vusbProxyLinuxStatusToVUsbStatus(pUrbLnx->KUrb.status);
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 |
|
---|
1418 | /**
|
---|
1419 | * Reap URBs in-flight on a device.
|
---|
1420 | *
|
---|
1421 | * @returns Pointer to a completed URB.
|
---|
1422 | * @returns NULL if no URB was completed.
|
---|
1423 | * @param pProxyDev The device.
|
---|
1424 | * @param cMillies Number of milliseconds to wait. Use 0 to not wait at all.
|
---|
1425 | */
|
---|
1426 | static DECLCALLBACK(PVUSBURB) usbProxyLinuxUrbReap(PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies)
|
---|
1427 | {
|
---|
1428 | PUSBPROXYURBLNX pUrbLnx = NULL;
|
---|
1429 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
1430 |
|
---|
1431 | /*
|
---|
1432 | * Block for requested period.
|
---|
1433 | *
|
---|
1434 | * It seems to me that the path of poll() is shorter and
|
---|
1435 | * involves less semaphores than ioctl() on usbfs. So, we'll
|
---|
1436 | * do a poll regardless of whether cMillies == 0 or not.
|
---|
1437 | */
|
---|
1438 | if (cMillies)
|
---|
1439 | {
|
---|
1440 | int cMilliesWait = cMillies == RT_INDEFINITE_WAIT ? -1 : cMillies;
|
---|
1441 |
|
---|
1442 | for (;;)
|
---|
1443 | {
|
---|
1444 | struct pollfd pfd[2];
|
---|
1445 | pfd[0].fd = RTFileToNative(pDevLnx->hFile);
|
---|
1446 | pfd[0].events = POLLOUT | POLLWRNORM /* completed async */
|
---|
1447 | | POLLERR | POLLHUP /* disconnected */;
|
---|
1448 | pfd[0].revents = 0;
|
---|
1449 |
|
---|
1450 | pfd[1].fd = RTPipeToNative(pDevLnx->hPipeWakeupR);
|
---|
1451 | pfd[1].events = POLLIN | POLLHUP;
|
---|
1452 | pfd[1].revents = 0;
|
---|
1453 |
|
---|
1454 | int rc = poll(&pfd[0], 2, cMilliesWait);
|
---|
1455 | Log(("usbProxyLinuxUrbReap: poll rc = %d\n", rc));
|
---|
1456 | if (rc >= 1)
|
---|
1457 | {
|
---|
1458 | /* If the pipe caused the return drain it. */
|
---|
1459 | if (pfd[1].revents & POLLIN)
|
---|
1460 | {
|
---|
1461 | uint8_t bRead;
|
---|
1462 | size_t cbIgnored = 0;
|
---|
1463 | RTPipeRead(pDevLnx->hPipeWakeupR, &bRead, 1, &cbIgnored);
|
---|
1464 | }
|
---|
1465 | break;
|
---|
1466 | }
|
---|
1467 | if (rc >= 0)
|
---|
1468 | return NULL;
|
---|
1469 |
|
---|
1470 | if (errno != EAGAIN)
|
---|
1471 | {
|
---|
1472 | Log(("usb-linux: Reap URB - poll -> %d errno=%d pProxyDev=%s\n", rc, errno, usbProxyGetName(pProxyDev)));
|
---|
1473 | return NULL;
|
---|
1474 | }
|
---|
1475 | Log(("usbProxyLinuxUrbReap: poll again - weird!!!\n"));
|
---|
1476 | }
|
---|
1477 | }
|
---|
1478 |
|
---|
1479 | /*
|
---|
1480 | * Reap URBs, non-blocking.
|
---|
1481 | */
|
---|
1482 | for (;;)
|
---|
1483 | {
|
---|
1484 | struct usbdevfs_urb *pKUrb;
|
---|
1485 | while (ioctl(RTFileToNative(pDevLnx->hFile), USBDEVFS_REAPURBNDELAY, &pKUrb))
|
---|
1486 | if (errno != EINTR)
|
---|
1487 | {
|
---|
1488 | if (errno == ENODEV)
|
---|
1489 | usbProxLinuxUrbUnplugged(pProxyDev);
|
---|
1490 | else
|
---|
1491 | Log(("usb-linux: Reap URB. errno=%d pProxyDev=%s\n", errno, usbProxyGetName(pProxyDev)));
|
---|
1492 | return NULL;
|
---|
1493 | }
|
---|
1494 | pUrbLnx = (PUSBPROXYURBLNX)pKUrb;
|
---|
1495 |
|
---|
1496 | /* split list: Is the entire split list done yet? */
|
---|
1497 | if (pUrbLnx->pSplitHead)
|
---|
1498 | {
|
---|
1499 | pUrbLnx->fSplitElementReaped = true;
|
---|
1500 |
|
---|
1501 | /* for variable size URBs, we may need to queue more if the just-reaped URB was completely filled */
|
---|
1502 | if (pUrbLnx->cbSplitRemaining && (pKUrb->actual_length == pKUrb->buffer_length) && !pUrbLnx->pSplitNext)
|
---|
1503 | {
|
---|
1504 | bool fUnplugged = false;
|
---|
1505 | bool fSucceeded;
|
---|
1506 |
|
---|
1507 | Assert(pUrbLnx->pSplitHead);
|
---|
1508 | Assert((pKUrb->endpoint & 0x80) && !(pKUrb->flags & USBDEVFS_URB_SHORT_NOT_OK));
|
---|
1509 | PUSBPROXYURBLNX pNew = usbProxyLinuxSplitURBFragment(pProxyDev, pUrbLnx->pSplitHead, pUrbLnx);
|
---|
1510 | if (!pNew)
|
---|
1511 | {
|
---|
1512 | Log(("usb-linux: Allocating URB fragment failed. errno=%d pProxyDev=%s\n", errno, usbProxyGetName(pProxyDev)));
|
---|
1513 | return NULL;
|
---|
1514 | }
|
---|
1515 | PVUSBURB pUrb = (PVUSBURB)pUrbLnx->KUrb.usercontext;
|
---|
1516 | fSucceeded = usbProxyLinuxSubmitURB(pProxyDev, pNew, pUrb, &fUnplugged);
|
---|
1517 | if (fUnplugged)
|
---|
1518 | usbProxLinuxUrbUnplugged(pProxyDev);
|
---|
1519 | if (!fSucceeded)
|
---|
1520 | return NULL;
|
---|
1521 | continue; /* try reaping another URB */
|
---|
1522 | }
|
---|
1523 | PUSBPROXYURBLNX pCur;
|
---|
1524 | for (pCur = pUrbLnx->pSplitHead; pCur; pCur = pCur->pSplitNext)
|
---|
1525 | if (!pCur->fSplitElementReaped)
|
---|
1526 | {
|
---|
1527 | pUrbLnx = NULL;
|
---|
1528 | break;
|
---|
1529 | }
|
---|
1530 | if (!pUrbLnx)
|
---|
1531 | continue;
|
---|
1532 | pUrbLnx = pUrbLnx->pSplitHead;
|
---|
1533 | }
|
---|
1534 | break;
|
---|
1535 | }
|
---|
1536 |
|
---|
1537 | /*
|
---|
1538 | * Ok, we got one!
|
---|
1539 | */
|
---|
1540 | PVUSBURB pUrb = (PVUSBURB)pUrbLnx->KUrb.usercontext;
|
---|
1541 | if ( pUrb
|
---|
1542 | && !pUrbLnx->fCanceledBySubmit)
|
---|
1543 | {
|
---|
1544 | if (pUrbLnx->pSplitHead)
|
---|
1545 | {
|
---|
1546 | /* split - find the end byte and the first error status. */
|
---|
1547 | Assert(pUrbLnx == pUrbLnx->pSplitHead);
|
---|
1548 | uint8_t *pbEnd = &pUrb->abData[0];
|
---|
1549 | pUrb->enmStatus = VUSBSTATUS_OK;
|
---|
1550 | PUSBPROXYURBLNX pCur;
|
---|
1551 | for (pCur = pUrbLnx; pCur; pCur = pCur->pSplitNext)
|
---|
1552 | {
|
---|
1553 | if (pCur->KUrb.actual_length)
|
---|
1554 | pbEnd = (uint8_t *)pCur->KUrb.buffer + pCur->KUrb.actual_length;
|
---|
1555 | if (pUrb->enmStatus == VUSBSTATUS_OK)
|
---|
1556 | pUrb->enmStatus = vusbProxyLinuxUrbGetStatus(pCur);
|
---|
1557 | }
|
---|
1558 | pUrb->cbData = pbEnd - &pUrb->abData[0];
|
---|
1559 | usbProxyLinuxUrbUnlinkInFlight(pDevLnx, pUrbLnx);
|
---|
1560 | usbProxyLinuxUrbFreeSplitList(pProxyDev, pUrbLnx);
|
---|
1561 | }
|
---|
1562 | else
|
---|
1563 | {
|
---|
1564 | /* unsplit. */
|
---|
1565 | pUrb->enmStatus = vusbProxyLinuxUrbGetStatus(pUrbLnx);
|
---|
1566 | pUrb->cbData = pUrbLnx->KUrb.actual_length;
|
---|
1567 | if (pUrb->enmType == VUSBXFERTYPE_ISOC)
|
---|
1568 | {
|
---|
1569 | unsigned i, off;
|
---|
1570 | for (i = 0, off = 0; i < pUrb->cIsocPkts; i++)
|
---|
1571 | {
|
---|
1572 | #if RT_GNUC_PREREQ(4, 6)
|
---|
1573 | # pragma GCC diagnostic push
|
---|
1574 | # pragma GCC diagnostic ignored "-Warray-bounds"
|
---|
1575 | #endif
|
---|
1576 | pUrb->aIsocPkts[i].enmStatus = vusbProxyLinuxStatusToVUsbStatus(pUrbLnx->KUrb.iso_frame_desc[i].status);
|
---|
1577 | Assert(pUrb->aIsocPkts[i].off == off);
|
---|
1578 | pUrb->aIsocPkts[i].cb = pUrbLnx->KUrb.iso_frame_desc[i].actual_length;
|
---|
1579 | off += pUrbLnx->KUrb.iso_frame_desc[i].length;
|
---|
1580 | #if RT_GNUC_PREREQ(4, 6)
|
---|
1581 | # pragma GCC diagnostic pop
|
---|
1582 | #endif
|
---|
1583 | }
|
---|
1584 | }
|
---|
1585 | usbProxyLinuxUrbUnlinkInFlight(pDevLnx, pUrbLnx);
|
---|
1586 | usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
|
---|
1587 | }
|
---|
1588 | pUrb->Dev.pvPrivate = NULL;
|
---|
1589 |
|
---|
1590 | /* some adjustments for message transfers. */
|
---|
1591 | if (pUrb->enmType == VUSBXFERTYPE_MSG)
|
---|
1592 | {
|
---|
1593 | pUrb->cbData += sizeof(VUSBSETUP);
|
---|
1594 | usbProxyLinuxUrbSwapSetup((PVUSBSETUP)pUrb->abData);
|
---|
1595 | }
|
---|
1596 | }
|
---|
1597 | else
|
---|
1598 | {
|
---|
1599 | usbProxyLinuxUrbUnlinkInFlight(pDevLnx, pUrbLnx);
|
---|
1600 | usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
|
---|
1601 | pUrb = NULL;
|
---|
1602 | }
|
---|
1603 |
|
---|
1604 | LogFlow(("usbProxyLinuxUrbReap: pProxyDev=%s returns %p\n", usbProxyGetName(pProxyDev), pUrb));
|
---|
1605 | return pUrb;
|
---|
1606 | }
|
---|
1607 |
|
---|
1608 |
|
---|
1609 | /**
|
---|
1610 | * Cancels the URB.
|
---|
1611 | * The URB requires reaping, so we don't change its state.
|
---|
1612 | */
|
---|
1613 | static DECLCALLBACK(int) usbProxyLinuxUrbCancel(PUSBPROXYDEV pProxyDev, PVUSBURB pUrb)
|
---|
1614 | {
|
---|
1615 | int rc = VINF_SUCCESS;
|
---|
1616 | PUSBPROXYURBLNX pUrbLnx = (PUSBPROXYURBLNX)pUrb->Dev.pvPrivate;
|
---|
1617 | if (pUrbLnx->pSplitHead)
|
---|
1618 | {
|
---|
1619 | /* split */
|
---|
1620 | Assert(pUrbLnx == pUrbLnx->pSplitHead);
|
---|
1621 | PUSBPROXYURBLNX pCur;
|
---|
1622 | for (pCur = pUrbLnx; pCur; pCur = pCur->pSplitNext)
|
---|
1623 | {
|
---|
1624 | if (pCur->fSplitElementReaped)
|
---|
1625 | continue;
|
---|
1626 | if ( !usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_DISCARDURB, &pCur->KUrb, true, UINT32_MAX)
|
---|
1627 | || errno == ENOENT)
|
---|
1628 | continue;
|
---|
1629 | if (errno == ENODEV)
|
---|
1630 | break;
|
---|
1631 | /** @todo Think about how to handle errors wrt. to the status code. */
|
---|
1632 | Log(("usb-linux: Discard URB %p failed, errno=%d. pProxyDev=%s!!! (split)\n",
|
---|
1633 | pUrb, errno, usbProxyGetName(pProxyDev)));
|
---|
1634 | }
|
---|
1635 | }
|
---|
1636 | else
|
---|
1637 | {
|
---|
1638 | /* unsplit */
|
---|
1639 | if ( usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_DISCARDURB, &pUrbLnx->KUrb, true, UINT32_MAX)
|
---|
1640 | && errno != ENODEV /* deal with elsewhere. */
|
---|
1641 | && errno != ENOENT)
|
---|
1642 | {
|
---|
1643 | Log(("usb-linux: Discard URB %p failed, errno=%d. pProxyDev=%s!!!\n",
|
---|
1644 | pUrb, errno, usbProxyGetName(pProxyDev)));
|
---|
1645 | rc = RTErrConvertFromErrno(errno);
|
---|
1646 | }
|
---|
1647 | }
|
---|
1648 |
|
---|
1649 | return rc;
|
---|
1650 | }
|
---|
1651 |
|
---|
1652 |
|
---|
1653 | static DECLCALLBACK(int) usbProxyLinuxWakeup(PUSBPROXYDEV pProxyDev)
|
---|
1654 | {
|
---|
1655 | PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
|
---|
1656 | size_t cbIgnored;
|
---|
1657 |
|
---|
1658 | LogFlowFunc(("pProxyDev=%p\n", pProxyDev));
|
---|
1659 |
|
---|
1660 | return RTPipeWrite(pDevLnx->hPipeWakeupW, "", 1, &cbIgnored);
|
---|
1661 | }
|
---|
1662 |
|
---|
1663 | /**
|
---|
1664 | * The Linux USB Proxy Backend.
|
---|
1665 | */
|
---|
1666 | const USBPROXYBACK g_USBProxyDeviceHost =
|
---|
1667 | {
|
---|
1668 | /* pszName */
|
---|
1669 | "host",
|
---|
1670 | /* cbBackend */
|
---|
1671 | sizeof(USBPROXYDEVLNX),
|
---|
1672 | usbProxyLinuxOpen,
|
---|
1673 | usbProxyLinuxInit,
|
---|
1674 | usbProxyLinuxClose,
|
---|
1675 | usbProxyLinuxReset,
|
---|
1676 | usbProxyLinuxSetConfig,
|
---|
1677 | usbProxyLinuxClaimInterface,
|
---|
1678 | usbProxyLinuxReleaseInterface,
|
---|
1679 | usbProxyLinuxSetInterface,
|
---|
1680 | usbProxyLinuxClearHaltedEp,
|
---|
1681 | usbProxyLinuxUrbQueue,
|
---|
1682 | usbProxyLinuxUrbCancel,
|
---|
1683 | usbProxyLinuxUrbReap,
|
---|
1684 | usbProxyLinuxWakeup,
|
---|
1685 | 0
|
---|
1686 | };
|
---|
1687 |
|
---|
1688 |
|
---|
1689 | /*
|
---|
1690 | * Local Variables:
|
---|
1691 | * mode: c
|
---|
1692 | * c-file-style: "bsd"
|
---|
1693 | * c-basic-offset: 4
|
---|
1694 | * End:
|
---|
1695 | */
|
---|
1696 |
|
---|