VirtualBox

source: vbox/trunk/src/VBox/Devices/USB/linux/USBProxyDevice-linux.cpp@ 80585

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

Logging.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 56.9 KB
Line 
1/* $Id: USBProxyDevice-linux.cpp 76819 2019-01-14 16:54:29Z vboxsync $ */
2/** @file
3 * USB device proxy - the Linux backend.
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
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 *
55static inline int rtcsNoop() { return VINF_SUCCESS; }
56static 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 */
85typedef 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 */
118typedef 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 waiking up - writing end. */
133 RTPIPE hPipeWakeupW;
134 /** Pipe handle for waiking 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*********************************************************************************************************************************/
147static void usbProxLinuxUrbUnplugged(PUSBPROXYDEV pProxyDev);
148static DECLCALLBACK(int) usbProxyLinuxClaimInterface(PUSBPROXYDEV pProxyDev, int iIf);
149static 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 */
166static 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 */
198static 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 */
230static 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 */
258static 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 */
272static 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 */
294static 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 */
336static 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 */
357static 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 */
393static 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 */
527static 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 */
556static 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 */
571RTDECL(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 */
591static 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=%s!\n", pProxyDev, pszAddress,
671 RTErrGetShort(rc)));
672
673 NOREF(pvBackend);
674 return rc;
675}
676
677
678/**
679 * Claims all the interfaces and figures out the
680 * current configuration.
681 *
682 * @returns VINF_SUCCESS.
683 * @param pProxyDev The proxy device.
684 */
685static DECLCALLBACK(int) usbProxyLinuxInit(PUSBPROXYDEV pProxyDev)
686{
687 PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
688
689 /*
690 * Brute force rulez.
691 * usbProxyLinuxSetConnected check for masked interfaces.
692 */
693 unsigned iIf;
694 for (iIf = 0; iIf < 256; iIf++)
695 usbProxyLinuxSetConnected(pProxyDev, iIf, false, true);
696
697 /*
698 * Determine the active configuration.
699 *
700 * If there isn't any active configuration, we will get EHOSTUNREACH (113) errors
701 * when trying to read the device descriptors in usbProxyDevCreate. So, we'll make
702 * the first one active (usually 1) then.
703 */
704 pProxyDev->cIgnoreSetConfigs = 1;
705 int iFirstCfg;
706 pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->pszPath, &iFirstCfg);
707 if (pProxyDev->iActiveCfg == -1)
708 {
709 usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_SETCONFIGURATION, &iFirstCfg, false, UINT32_MAX);
710 pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->pszPath, NULL);
711 Log(("usbProxyLinuxInit: No active config! Tried to set %d: iActiveCfg=%d\n", iFirstCfg, pProxyDev->iActiveCfg));
712 }
713 else
714 Log(("usbProxyLinuxInit(%p): iActiveCfg=%d\n", pProxyDev, pProxyDev->iActiveCfg));
715 return VINF_SUCCESS;
716}
717
718
719/**
720 * Closes the proxy device.
721 */
722static DECLCALLBACK(void) usbProxyLinuxClose(PUSBPROXYDEV pProxyDev)
723{
724 LogFlow(("usbProxyLinuxClose: pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
725 PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
726 AssertPtrReturnVoid(pDevLnx);
727
728 /*
729 * Try put the device in a state which linux can cope with before we release it.
730 * Resetting it would be a nice start, although we must remember
731 * that it might have been disconnected...
732 *
733 * Don't reset if we're masking interfaces or if construction failed.
734 */
735 if (pProxyDev->fInited)
736 {
737 /* ASSUMES: thread == EMT */
738 if ( pProxyDev->fMaskedIfs
739 || !usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_RESET, NULL, false, 10))
740 {
741 /* Connect drivers. */
742 unsigned iIf;
743 for (iIf = 0; iIf < 256; iIf++)
744 usbProxyLinuxSetConnected(pProxyDev, iIf, true, true);
745 Log(("USB: Successfully reset device pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
746 }
747 else if (errno != ENODEV)
748 LogRel(("USB: Reset failed, errno=%d, pProxyDev=%s.\n", errno, usbProxyGetName(pProxyDev)));
749 else /* This will happen if device was detached. */
750 Log(("USB: Reset failed, errno=%d (ENODEV), pProxyDev=%s.\n", errno, usbProxyGetName(pProxyDev)));
751 }
752
753 /*
754 * Now we can free all the resources and close the device.
755 */
756 RTCritSectDelete(&pDevLnx->CritSect);
757
758 PUSBPROXYURBLNX pUrbLnx;
759 PUSBPROXYURBLNX pUrbLnxNext;
760 RTListForEachSafe(&pDevLnx->ListInFlight, pUrbLnx, pUrbLnxNext, USBPROXYURBLNX, NodeList)
761 {
762 RTListNodeRemove(&pUrbLnx->NodeList);
763
764 if ( usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_DISCARDURB, &pUrbLnx->KUrb, false, UINT32_MAX)
765 && errno != ENODEV
766 && errno != ENOENT)
767 AssertMsgFailed(("errno=%d\n", errno));
768
769 if (pUrbLnx->pSplitHead)
770 {
771 PUSBPROXYURBLNX pCur = pUrbLnx->pSplitNext;
772 while (pCur)
773 {
774 PUSBPROXYURBLNX pFree = pCur;
775 pCur = pFree->pSplitNext;
776 if ( !pFree->fSplitElementReaped
777 && usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_DISCARDURB, &pFree->KUrb, false, UINT32_MAX)
778 && errno != ENODEV
779 && errno != ENOENT)
780 AssertMsgFailed(("errno=%d\n", errno));
781 RTMemFree(pFree);
782 }
783 }
784 else
785 Assert(!pUrbLnx->pSplitNext);
786 RTMemFree(pUrbLnx);
787 }
788
789 RTListForEachSafe(&pDevLnx->ListFree, pUrbLnx, pUrbLnxNext, USBPROXYURBLNX, NodeList)
790 {
791 RTListNodeRemove(&pUrbLnx->NodeList);
792 RTMemFree(pUrbLnx);
793 }
794
795 RTFileClose(pDevLnx->hFile);
796 pDevLnx->hFile = NIL_RTFILE;
797
798 RTPipeClose(pDevLnx->hPipeWakeupR);
799 RTPipeClose(pDevLnx->hPipeWakeupW);
800
801 RTStrFree(pDevLnx->pszPath);
802
803 LogFlow(("usbProxyLinuxClose: returns\n"));
804}
805
806
807/** @interface_method_impl{USBPROXYBACK,pfnReset} */
808static DECLCALLBACK(int) usbProxyLinuxReset(PUSBPROXYDEV pProxyDev, bool fResetOnLinux)
809{
810 PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
811 RT_NOREF(fResetOnLinux);
812 Assert(!pProxyDev->fMaskedIfs);
813 LogFlow(("usbProxyLinuxReset: pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
814
815 uint32_t fActiveIfsMask = pDevLnx->fClaimedIfsMask;
816 unsigned i;
817
818 /*
819 * Before reset, release claimed interfaces. This less than obvious move
820 * prevents Linux from rebinding in-kernel drivers to the device after reset.
821 */
822 for (i = 0; i < (sizeof(fActiveIfsMask) * 8); ++i)
823 {
824 if (fActiveIfsMask & RT_BIT(i))
825 {
826 usbProxyLinuxReleaseInterface(pProxyDev, i);
827 }
828 }
829
830 if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_RESET, NULL, false, 10))
831 {
832 int rc = errno;
833 LogRel(("usb-linux: Reset failed, rc=%s errno=%d.\n",
834 RTErrGetShort(RTErrConvertFromErrno(rc)), rc));
835 pProxyDev->iActiveCfg = -1;
836 return RTErrConvertFromErrno(rc);
837 }
838
839 /*
840 * Now reclaim previously claimed interfaces. If that doesn't work, let's hope
841 * the guest/VUSB can recover from that. Can happen if reset changes configuration.
842 */
843 for (i = 0; i < (sizeof(fActiveIfsMask) * 8); ++i)
844 {
845 if (fActiveIfsMask & RT_BIT(i))
846 {
847 usbProxyLinuxClaimInterface(pProxyDev, i);
848 }
849 }
850
851 /* find the active config - damn annoying. */
852 pProxyDev->iActiveCfg = usbProxyLinuxFindActiveConfig(pProxyDev, pDevLnx->pszPath, NULL);
853 LogFlow(("usbProxyLinuxReset: returns successfully iActiveCfg=%d\n", pProxyDev->iActiveCfg));
854
855 pProxyDev->cIgnoreSetConfigs = 2;
856 return VINF_SUCCESS;
857}
858
859
860/**
861 * SET_CONFIGURATION.
862 *
863 * The caller makes sure that it's not called first time after open or reset
864 * with the active interface.
865 *
866 * @returns success indicator.
867 * @param pProxyDev The device instance data.
868 * @param iCfg The configuration to set.
869 */
870static DECLCALLBACK(int) usbProxyLinuxSetConfig(PUSBPROXYDEV pProxyDev, int iCfg)
871{
872 LogFlow(("usbProxyLinuxSetConfig: pProxyDev=%s cfg=%#x\n",
873 usbProxyGetName(pProxyDev), iCfg));
874
875 if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_SETCONFIGURATION, &iCfg, true, UINT32_MAX))
876 {
877 Log(("usb-linux: Set configuration. errno=%d\n", errno));
878 return RTErrConvertFromErrno(errno);
879 }
880 return VINF_SUCCESS;
881}
882
883
884/**
885 * Claims an interface.
886 * @returns success indicator.
887 */
888static DECLCALLBACK(int) usbProxyLinuxClaimInterface(PUSBPROXYDEV pProxyDev, int iIf)
889{
890 PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
891
892 LogFlow(("usbProxyLinuxClaimInterface: pProxyDev=%s ifnum=%#x\n", usbProxyGetName(pProxyDev), iIf));
893 usbProxyLinuxSetConnected(pProxyDev, iIf, false, false);
894
895 if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_CLAIMINTERFACE, &iIf, true, UINT32_MAX))
896 {
897 pDevLnx->fClaimedIfsMask &= ~RT_BIT(iIf);
898 LogRel(("usb-linux: Claim interface. errno=%d pProxyDev=%s\n", errno, usbProxyGetName(pProxyDev)));
899 return RTErrConvertFromErrno(errno);
900 }
901 pDevLnx->fClaimedIfsMask |= RT_BIT(iIf);
902 return VINF_SUCCESS;
903}
904
905
906/**
907 * Releases an interface.
908 * @returns success indicator.
909 */
910static DECLCALLBACK(int) usbProxyLinuxReleaseInterface(PUSBPROXYDEV pProxyDev, int iIf)
911{
912 PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
913
914 LogFlow(("usbProxyLinuxReleaseInterface: pProxyDev=%s ifnum=%#x\n", usbProxyGetName(pProxyDev), iIf));
915
916 if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_RELEASEINTERFACE, &iIf, true, UINT32_MAX))
917 {
918 LogRel(("usb-linux: Release interface, errno=%d. pProxyDev=%s\n", errno, usbProxyGetName(pProxyDev)));
919 return RTErrConvertFromErrno(errno);
920 }
921 pDevLnx->fClaimedIfsMask &= ~RT_BIT(iIf);
922 return VINF_SUCCESS;
923}
924
925
926/**
927 * SET_INTERFACE.
928 *
929 * @returns success indicator.
930 */
931static DECLCALLBACK(int) usbProxyLinuxSetInterface(PUSBPROXYDEV pProxyDev, int iIf, int iAlt)
932{
933 struct usbdevfs_setinterface SetIf;
934 LogFlow(("usbProxyLinuxSetInterface: pProxyDev=%p iIf=%#x iAlt=%#x\n", pProxyDev, iIf, iAlt));
935
936 SetIf.interface = iIf;
937 SetIf.altsetting = iAlt;
938 if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_SETINTERFACE, &SetIf, true, UINT32_MAX))
939 {
940 Log(("usb-linux: Set interface, errno=%d. pProxyDev=%s\n", errno, usbProxyGetName(pProxyDev)));
941 return RTErrConvertFromErrno(errno);
942 }
943 return VINF_SUCCESS;
944}
945
946
947/**
948 * Clears the halted endpoint 'EndPt'.
949 */
950static DECLCALLBACK(int) usbProxyLinuxClearHaltedEp(PUSBPROXYDEV pProxyDev, unsigned int EndPt)
951{
952 LogFlow(("usbProxyLinuxClearHaltedEp: pProxyDev=%s EndPt=%u\n", usbProxyGetName(pProxyDev), EndPt));
953
954 if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_CLEAR_HALT, &EndPt, true, UINT32_MAX))
955 {
956 /*
957 * Unfortunately this doesn't work on control pipes.
958 * Windows doing this on the default endpoint and possibly other pipes too,
959 * so we'll feign success for ENOENT errors.
960 */
961 if (errno == ENOENT)
962 {
963 Log(("usb-linux: clear_halted_ep failed errno=%d. pProxyDev=%s ep=%d - IGNORED\n",
964 errno, usbProxyGetName(pProxyDev), EndPt));
965 return VINF_SUCCESS;
966 }
967 Log(("usb-linux: clear_halted_ep failed errno=%d. pProxyDev=%s ep=%d\n",
968 errno, usbProxyGetName(pProxyDev), EndPt));
969 return RTErrConvertFromErrno(errno);
970 }
971 return VINF_SUCCESS;
972}
973
974
975/**
976 * Setup packet byte-swapping routines.
977 */
978static void usbProxyLinuxUrbSwapSetup(PVUSBSETUP pSetup)
979{
980 pSetup->wValue = RT_H2LE_U16(pSetup->wValue);
981 pSetup->wIndex = RT_H2LE_U16(pSetup->wIndex);
982 pSetup->wLength = RT_H2LE_U16(pSetup->wLength);
983}
984
985
986/**
987 * Clean up after a failed URB submit.
988 */
989static void usbProxyLinuxCleanupFailedSubmit(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pUrbLnx, PUSBPROXYURBLNX pCur, PVUSBURB pUrb, bool *pfUnplugged)
990{
991 if (pUrb->enmType == VUSBXFERTYPE_MSG)
992 usbProxyLinuxUrbSwapSetup((PVUSBSETUP)pUrb->abData);
993
994 /* discard and reap later (walking with pUrbLnx). */
995 if (pUrbLnx != pCur)
996 {
997 for (;;)
998 {
999 pUrbLnx->fCanceledBySubmit = true;
1000 pUrbLnx->KUrb.usercontext = NULL;
1001 if (usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_DISCARDURB, &pUrbLnx->KUrb, false, UINT32_MAX))
1002 {
1003 if (errno == ENODEV)
1004 *pfUnplugged = true;
1005 else if (errno == ENOENT)
1006 pUrbLnx->fSplitElementReaped = true;
1007 else
1008 LogRel(("USB: Failed to discard %p! errno=%d (pUrb=%p)\n", pUrbLnx->KUrb.usercontext, errno, pUrb)); /* serious! */
1009 }
1010 if (pUrbLnx->pSplitNext == pCur)
1011 {
1012 pUrbLnx->pSplitNext = NULL;
1013 break;
1014 }
1015 pUrbLnx = pUrbLnx->pSplitNext; Assert(pUrbLnx);
1016 }
1017 }
1018
1019 /* free the unsubmitted ones. */
1020 while (pCur)
1021 {
1022 PUSBPROXYURBLNX pFree = pCur;
1023 pCur = pCur->pSplitNext;
1024 usbProxyLinuxUrbFree(pProxyDev, pFree);
1025 }
1026
1027 /* send unplug event if we failed with ENODEV originally. */
1028 if (*pfUnplugged)
1029 usbProxLinuxUrbUnplugged(pProxyDev);
1030}
1031
1032/**
1033 * Submit one URB through the usbfs IOCTL interface, with
1034 * retries
1035 *
1036 * @returns VBox status code.
1037 */
1038static int usbProxyLinuxSubmitURB(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pCur, PVUSBURB pUrb, bool *pfUnplugged)
1039{
1040 RT_NOREF(pUrb);
1041 PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
1042 unsigned cTries = 0;
1043
1044 while (ioctl(RTFileToNative(pDevLnx->hFile), USBDEVFS_SUBMITURB, &pCur->KUrb))
1045 {
1046 if (errno == EINTR)
1047 continue;
1048 if (errno == ENODEV)
1049 {
1050 Log(("usbProxyLinuxSubmitURB: ENODEV -> unplugged. pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
1051 *pfUnplugged = true;
1052 return RTErrConvertFromErrno(errno);
1053 }
1054
1055 Log(("usb-linux: Submit URB %p -> %d!!! type=%d ep=%#x buffer_length=%#x cTries=%d\n",
1056 pUrb, errno, pCur->KUrb.type, pCur->KUrb.endpoint, pCur->KUrb.buffer_length, cTries));
1057 if (errno != EBUSY && ++cTries < 3) /* this doesn't work for the floppy :/ */
1058 continue;
1059
1060 return RTErrConvertFromErrno(errno);
1061 }
1062 return VINF_SUCCESS;
1063}
1064
1065/** The split size. 16K in known Linux kernel versions. */
1066#define SPLIT_SIZE 0x4000
1067
1068/**
1069 * Create a URB fragment of up to SPLIT_SIZE size and hook it
1070 * into the list of fragments.
1071 *
1072 * @returns pointer to newly allocated URB fragment or NULL.
1073 */
1074static PUSBPROXYURBLNX usbProxyLinuxSplitURBFragment(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pHead, PUSBPROXYURBLNX pCur)
1075{
1076 PUSBPROXYURBLNX pNew;
1077 uint32_t cbLeft = pCur->cbSplitRemaining;
1078 uint8_t *pb = (uint8_t *)pCur->KUrb.buffer;
1079
1080 LogFlowFunc(("pProxyDev=%p pHead=%p pCur=%p\n", pProxyDev, pHead, pCur));
1081
1082 Assert(cbLeft != 0);
1083 pNew = pCur->pSplitNext = usbProxyLinuxUrbAlloc(pProxyDev, pHead);
1084 if (!pNew)
1085 {
1086 usbProxyLinuxUrbFreeSplitList(pProxyDev, pHead);
1087 return NULL;
1088 }
1089 Assert(pNew->pSplitHead == pHead);
1090 Assert(pNew->pSplitNext == NULL);
1091
1092 pNew->KUrb = pHead->KUrb;
1093 pNew->KUrb.buffer = pb + pCur->KUrb.buffer_length;
1094 pNew->KUrb.buffer_length = RT_MIN(cbLeft, SPLIT_SIZE);
1095 pNew->KUrb.actual_length = 0;
1096
1097 cbLeft -= pNew->KUrb.buffer_length;
1098 Assert(cbLeft < INT32_MAX);
1099 pNew->cbSplitRemaining = cbLeft;
1100 LogFlowFunc(("returns pNew=%p\n", pNew));
1101 return pNew;
1102}
1103
1104/**
1105 * Try splitting up a VUSB URB into smaller URBs which the
1106 * linux kernel (usbfs) can deal with.
1107 *
1108 * NB: For ShortOK reads things get a little tricky - we don't
1109 * know how much data is going to arrive and not all the
1110 * fragment URBs might be filled. We can only safely set up one
1111 * URB at a time -> worse performance but correct behaviour.
1112 *
1113 * @returns VBox status code.
1114 * @param pProxyDev The proxy device.
1115 * @param pUrbLnx The linux URB which was rejected because of being too big.
1116 * @param pUrb The VUSB URB.
1117 */
1118static int usbProxyLinuxUrbQueueSplit(PUSBPROXYDEV pProxyDev, PUSBPROXYURBLNX pUrbLnx, PVUSBURB pUrb)
1119{
1120 /*
1121 * Split it up into SPLIT_SIZE sized blocks.
1122 */
1123 const unsigned cKUrbs = (pUrb->cbData + SPLIT_SIZE - 1) / SPLIT_SIZE;
1124 LogFlow(("usbProxyLinuxUrbQueueSplit: pUrb=%p cKUrbs=%d cbData=%d\n", pUrb, cKUrbs, pUrb->cbData));
1125
1126 uint32_t cbLeft = pUrb->cbData;
1127 uint8_t *pb = &pUrb->abData[0];
1128
1129 /* the first one (already allocated) */
1130 switch (pUrb->enmType)
1131 {
1132 default: /* shut up gcc */
1133 case VUSBXFERTYPE_BULK: pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_BULK; break;
1134 case VUSBXFERTYPE_INTR: pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_INTERRUPT; break;
1135 case VUSBXFERTYPE_MSG: pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_CONTROL; break;
1136 case VUSBXFERTYPE_ISOC:
1137 AssertMsgFailed(("We can't split isochronous URBs!\n"));
1138 usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
1139 return VERR_INVALID_PARAMETER; /** @todo Better status code. */
1140 }
1141 pUrbLnx->KUrb.endpoint = pUrb->EndPt;
1142 if (pUrb->enmDir == VUSBDIRECTION_IN)
1143 pUrbLnx->KUrb.endpoint |= 0x80;
1144 pUrbLnx->KUrb.flags = 0;
1145 if (pUrb->enmDir == VUSBDIRECTION_IN && pUrb->fShortNotOk)
1146 pUrbLnx->KUrb.flags |= USBDEVFS_URB_SHORT_NOT_OK;
1147 pUrbLnx->KUrb.status = 0;
1148 pUrbLnx->KUrb.buffer = pb;
1149 pUrbLnx->KUrb.buffer_length = RT_MIN(cbLeft, SPLIT_SIZE);
1150 pUrbLnx->KUrb.actual_length = 0;
1151 pUrbLnx->KUrb.start_frame = 0;
1152 pUrbLnx->KUrb.number_of_packets = 0;
1153 pUrbLnx->KUrb.error_count = 0;
1154 pUrbLnx->KUrb.signr = 0;
1155 pUrbLnx->KUrb.usercontext = pUrb;
1156 pUrbLnx->pSplitHead = pUrbLnx;
1157 pUrbLnx->pSplitNext = NULL;
1158
1159 PUSBPROXYURBLNX pCur = pUrbLnx;
1160
1161 cbLeft -= pUrbLnx->KUrb.buffer_length;
1162 pUrbLnx->cbSplitRemaining = cbLeft;
1163
1164 int rc = VINF_SUCCESS;
1165 bool fUnplugged = false;
1166 if (pUrb->enmDir == VUSBDIRECTION_IN && !pUrb->fShortNotOk)
1167 {
1168 /* Subsequent fragments will be queued only after the previous fragment is reaped
1169 * and only if necessary.
1170 */
1171 Log(("usb-linux: Large ShortOK read, only queuing first fragment.\n"));
1172 Assert(pUrbLnx->cbSplitRemaining > 0 && pUrbLnx->cbSplitRemaining < 256 * _1K);
1173 rc = usbProxyLinuxSubmitURB(pProxyDev, pUrbLnx, pUrb, &fUnplugged);
1174 }
1175 else
1176 {
1177 /* the rest. */
1178 unsigned i;
1179 for (i = 1; i < cKUrbs; i++)
1180 {
1181 pCur = usbProxyLinuxSplitURBFragment(pProxyDev, pUrbLnx, pCur);
1182 if (!pCur)
1183 return VERR_NO_MEMORY;
1184 }
1185 Assert(pCur->cbSplitRemaining == 0);
1186
1187 /* Submit the blocks. */
1188 pCur = pUrbLnx;
1189 for (i = 0; i < cKUrbs; i++, pCur = pCur->pSplitNext)
1190 {
1191 rc = usbProxyLinuxSubmitURB(pProxyDev, pCur, pUrb, &fUnplugged);
1192 if (RT_FAILURE(rc))
1193 break;
1194 }
1195 }
1196
1197 if (RT_SUCCESS(rc))
1198 {
1199 pUrb->Dev.pvPrivate = pUrbLnx;
1200 usbProxyLinuxUrbLinkInFlight(USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX), pUrbLnx);
1201 LogFlow(("usbProxyLinuxUrbQueueSplit: ok\n"));
1202 return VINF_SUCCESS;
1203 }
1204
1205 usbProxyLinuxCleanupFailedSubmit(pProxyDev, pUrbLnx, pCur, pUrb, &fUnplugged);
1206 return rc;
1207}
1208
1209
1210/**
1211 * @interface_method_impl{USBPROXYBACK,pfnUrbQueue}
1212 */
1213static DECLCALLBACK(int) usbProxyLinuxUrbQueue(PUSBPROXYDEV pProxyDev, PVUSBURB pUrb)
1214{
1215 int rc = VINF_SUCCESS;
1216 unsigned cTries;
1217 PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
1218 LogFlow(("usbProxyLinuxUrbQueue: pProxyDev=%s pUrb=%p EndPt=%d cbData=%d\n",
1219 usbProxyGetName(pProxyDev), pUrb, pUrb->EndPt, pUrb->cbData));
1220
1221 /*
1222 * Allocate a linux urb.
1223 */
1224 PUSBPROXYURBLNX pUrbLnx = usbProxyLinuxUrbAlloc(pProxyDev, NULL);
1225 if (!pUrbLnx)
1226 return VERR_NO_MEMORY;
1227
1228 pUrbLnx->KUrb.endpoint = pUrb->EndPt | (pUrb->enmDir == VUSBDIRECTION_IN ? 0x80 : 0);
1229 pUrbLnx->KUrb.status = 0;
1230 pUrbLnx->KUrb.flags = 0;
1231 if (pUrb->enmDir == VUSBDIRECTION_IN && pUrb->fShortNotOk)
1232 pUrbLnx->KUrb.flags |= USBDEVFS_URB_SHORT_NOT_OK;
1233 pUrbLnx->KUrb.buffer = pUrb->abData;
1234 pUrbLnx->KUrb.buffer_length = pUrb->cbData;
1235 pUrbLnx->KUrb.actual_length = 0;
1236 pUrbLnx->KUrb.start_frame = 0;
1237 pUrbLnx->KUrb.number_of_packets = 0;
1238 pUrbLnx->KUrb.error_count = 0;
1239 pUrbLnx->KUrb.signr = 0;
1240 pUrbLnx->KUrb.usercontext = pUrb;
1241
1242 switch (pUrb->enmType)
1243 {
1244 case VUSBXFERTYPE_MSG:
1245 pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_CONTROL;
1246 if (pUrb->cbData < sizeof(VUSBSETUP))
1247 {
1248 usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
1249 return VERR_BUFFER_UNDERFLOW;
1250 }
1251 usbProxyLinuxUrbSwapSetup((PVUSBSETUP)pUrb->abData);
1252 LogFlow(("usbProxyLinuxUrbQueue: message\n"));
1253 break;
1254 case VUSBXFERTYPE_BULK:
1255 pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_BULK;
1256 break;
1257 case VUSBXFERTYPE_ISOC:
1258 pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_ISO;
1259 pUrbLnx->KUrb.flags |= USBDEVFS_URB_ISO_ASAP;
1260 pUrbLnx->KUrb.number_of_packets = pUrb->cIsocPkts;
1261 unsigned i;
1262 for (i = 0; i < pUrb->cIsocPkts; i++)
1263 {
1264#if RT_GNUC_PREREQ(4, 6)
1265# pragma GCC diagnostic push
1266# pragma GCC diagnostic ignored "-Warray-bounds"
1267#endif
1268 pUrbLnx->KUrb.iso_frame_desc[i].length = pUrb->aIsocPkts[i].cb;
1269 pUrbLnx->KUrb.iso_frame_desc[i].actual_length = 0;
1270 pUrbLnx->KUrb.iso_frame_desc[i].status = 0x7fff;
1271#if RT_GNUC_PREREQ(4, 6)
1272# pragma GCC diagnostic pop
1273#endif
1274 }
1275 break;
1276 case VUSBXFERTYPE_INTR:
1277 pUrbLnx->KUrb.type = USBDEVFS_URB_TYPE_INTERRUPT;
1278 break;
1279 default:
1280 rc = VERR_INVALID_PARAMETER; /** @todo better status code. */
1281 }
1282
1283 /*
1284 * We have to serialize access by using the critial section here because this
1285 * thread might be suspended after submitting the URB but before linking it into
1286 * the in flight list. This would get us in trouble when reaping the URB on another
1287 * thread while it isn't in the in flight list.
1288 *
1289 * Linking the URB into the list before submitting it like it was done in the past is not
1290 * possible either because submitting the URB might fail here because the device gets
1291 * detached. The reaper thread gets this event too and might race this thread before we
1292 * can unlink the URB from the active list and the common code might end up freeing
1293 * the common URB structure twice.
1294 */
1295 RTCritSectEnter(&pDevLnx->CritSect);
1296 /*
1297 * Submit it.
1298 */
1299 cTries = 0;
1300 while (ioctl(RTFileToNative(pDevLnx->hFile), USBDEVFS_SUBMITURB, &pUrbLnx->KUrb))
1301 {
1302 if (errno == EINTR)
1303 continue;
1304 if (errno == ENODEV)
1305 {
1306 rc = RTErrConvertFromErrno(errno);
1307 Log(("usbProxyLinuxUrbQueue: ENODEV -> unplugged. pProxyDev=%s\n", usbProxyGetName(pProxyDev)));
1308 if (pUrb->enmType == VUSBXFERTYPE_MSG)
1309 usbProxyLinuxUrbSwapSetup((PVUSBSETUP)pUrb->abData);
1310
1311 RTCritSectLeave(&pDevLnx->CritSect);
1312 usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
1313 usbProxLinuxUrbUnplugged(pProxyDev);
1314 return rc;
1315 }
1316
1317 /*
1318 * usbfs has or used to have a low buffer limit (16KB) in order to prevent
1319 * processes wasting kmalloc'ed memory. It will return EINVAL if break that
1320 * limit, and we'll have to split the VUSB URB up into multiple linux URBs.
1321 *
1322 * Since this is a limit which is subject to change, we cannot check for it
1323 * before submitting the URB. We just have to try and fail.
1324 */
1325 if ( errno == EINVAL
1326 && pUrb->cbData >= 8*_1K)
1327 {
1328 rc = usbProxyLinuxUrbQueueSplit(pProxyDev, pUrbLnx, pUrb);
1329 RTCritSectLeave(&pDevLnx->CritSect);
1330 return rc;
1331 }
1332
1333 Log(("usb-linux: Queue URB %p -> %d!!! type=%d ep=%#x buffer_length=%#x cTries=%d\n",
1334 pUrb, errno, pUrbLnx->KUrb.type, pUrbLnx->KUrb.endpoint, pUrbLnx->KUrb.buffer_length, cTries));
1335 if (errno != EBUSY && ++cTries < 3) /* this doesn't work for the floppy :/ */
1336 continue;
1337
1338 RTCritSectLeave(&pDevLnx->CritSect);
1339 rc = RTErrConvertFromErrno(errno);
1340 if (pUrb->enmType == VUSBXFERTYPE_MSG)
1341 usbProxyLinuxUrbSwapSetup((PVUSBSETUP)pUrb->abData);
1342 usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
1343 return rc;
1344 }
1345
1346 usbProxyLinuxUrbLinkInFlight(pDevLnx, pUrbLnx);
1347 RTCritSectLeave(&pDevLnx->CritSect);
1348
1349 LogFlow(("usbProxyLinuxUrbQueue: ok\n"));
1350 pUrb->Dev.pvPrivate = pUrbLnx;
1351 return rc;
1352}
1353
1354
1355/**
1356 * Translate the linux status to a VUSB status.
1357 *
1358 * @remarks see cc_to_error in ohci.h, uhci_map_status in uhci-q.c,
1359 * sitd_complete+itd_complete in ehci-sched.c, and qtd_copy_status in
1360 * ehci-q.c.
1361 */
1362static VUSBSTATUS vusbProxyLinuxStatusToVUsbStatus(int iStatus)
1363{
1364 switch (iStatus)
1365 {
1366 /** @todo VUSBSTATUS_NOT_ACCESSED */
1367 case -EXDEV: /* iso transfer, partial result. */
1368 case 0:
1369 return VUSBSTATUS_OK;
1370
1371 case -EILSEQ:
1372 return VUSBSTATUS_CRC;
1373
1374 case -EREMOTEIO: /* ehci and ohci uses this for underflow error. */
1375 return VUSBSTATUS_DATA_UNDERRUN;
1376 case -EOVERFLOW:
1377 return VUSBSTATUS_DATA_OVERRUN;
1378
1379 case -ETIME:
1380 case -ENODEV:
1381 return VUSBSTATUS_DNR;
1382
1383 //case -ECOMM:
1384 // return VUSBSTATUS_BUFFER_OVERRUN;
1385 //case -ENOSR:
1386 // return VUSBSTATUS_BUFFER_UNDERRUN;
1387
1388 case -EPROTO:
1389 Log(("vusbProxyLinuxStatusToVUsbStatus: DNR/EPPROTO!!\n"));
1390 return VUSBSTATUS_DNR;
1391
1392 case -EPIPE:
1393 Log(("vusbProxyLinuxStatusToVUsbStatus: STALL/EPIPE!!\n"));
1394 return VUSBSTATUS_STALL;
1395
1396 case -ESHUTDOWN:
1397 Log(("vusbProxyLinuxStatusToVUsbStatus: SHUTDOWN!!\n"));
1398 return VUSBSTATUS_STALL;
1399
1400 case -ENOENT:
1401 Log(("vusbProxyLinuxStatusToVUsbStatus: ENOENT!!\n"));
1402 return VUSBSTATUS_STALL;
1403
1404 default:
1405 Log(("vusbProxyLinuxStatusToVUsbStatus: status %d!!\n", iStatus));
1406 return VUSBSTATUS_STALL;
1407 }
1408}
1409
1410
1411/**
1412 * Get and translates the linux status to a VUSB status.
1413 */
1414static VUSBSTATUS vusbProxyLinuxUrbGetStatus(PUSBPROXYURBLNX pUrbLnx)
1415{
1416 return vusbProxyLinuxStatusToVUsbStatus(pUrbLnx->KUrb.status);
1417}
1418
1419
1420/**
1421 * Reap URBs in-flight on a device.
1422 *
1423 * @returns Pointer to a completed URB.
1424 * @returns NULL if no URB was completed.
1425 * @param pProxyDev The device.
1426 * @param cMillies Number of milliseconds to wait. Use 0 to not wait at all.
1427 */
1428static DECLCALLBACK(PVUSBURB) usbProxyLinuxUrbReap(PUSBPROXYDEV pProxyDev, RTMSINTERVAL cMillies)
1429{
1430 PUSBPROXYURBLNX pUrbLnx = NULL;
1431 PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
1432
1433 /*
1434 * Block for requested period.
1435 *
1436 * It seems to me that the path of poll() is shorter and
1437 * involves less semaphores than ioctl() on usbfs. So, we'll
1438 * do a poll regardless of whether cMillies == 0 or not.
1439 */
1440 if (cMillies)
1441 {
1442 int cMilliesWait = cMillies == RT_INDEFINITE_WAIT ? -1 : cMillies;
1443
1444 for (;;)
1445 {
1446 struct pollfd pfd[2];
1447 pfd[0].fd = RTFileToNative(pDevLnx->hFile);
1448 pfd[0].events = POLLOUT | POLLWRNORM /* completed async */
1449 | POLLERR | POLLHUP /* disconnected */;
1450 pfd[0].revents = 0;
1451
1452 pfd[1].fd = RTPipeToNative(pDevLnx->hPipeWakeupR);
1453 pfd[1].events = POLLIN | POLLHUP;
1454 pfd[1].revents = 0;
1455
1456 int rc = poll(&pfd[0], 2, cMilliesWait);
1457 Log(("usbProxyLinuxUrbReap: poll rc = %d\n", rc));
1458 if (rc >= 1)
1459 {
1460 /* If the pipe caused the return drain it. */
1461 if (pfd[1].revents & POLLIN)
1462 {
1463 uint8_t bRead;
1464 size_t cbIgnored = 0;
1465 RTPipeRead(pDevLnx->hPipeWakeupR, &bRead, 1, &cbIgnored);
1466 }
1467 break;
1468 }
1469 if (rc >= 0)
1470 return NULL;
1471
1472 if (errno != EAGAIN)
1473 {
1474 Log(("usb-linux: Reap URB - poll -> %d errno=%d pProxyDev=%s\n", rc, errno, usbProxyGetName(pProxyDev)));
1475 return NULL;
1476 }
1477 Log(("usbProxyLinuxUrbReap: poll again - weird!!!\n"));
1478 }
1479 }
1480
1481 /*
1482 * Reap URBs, non-blocking.
1483 */
1484 for (;;)
1485 {
1486 struct usbdevfs_urb *pKUrb;
1487 while (ioctl(RTFileToNative(pDevLnx->hFile), USBDEVFS_REAPURBNDELAY, &pKUrb))
1488 if (errno != EINTR)
1489 {
1490 if (errno == ENODEV)
1491 usbProxLinuxUrbUnplugged(pProxyDev);
1492 else
1493 Log(("usb-linux: Reap URB. errno=%d pProxyDev=%s\n", errno, usbProxyGetName(pProxyDev)));
1494 return NULL;
1495 }
1496 pUrbLnx = (PUSBPROXYURBLNX)pKUrb;
1497
1498 /* split list: Is the entire split list done yet? */
1499 if (pUrbLnx->pSplitHead)
1500 {
1501 pUrbLnx->fSplitElementReaped = true;
1502
1503 /* for variable size URBs, we may need to queue more if the just-reaped URB was completely filled */
1504 if (pUrbLnx->cbSplitRemaining && (pKUrb->actual_length == pKUrb->buffer_length) && !pUrbLnx->pSplitNext)
1505 {
1506 bool fUnplugged = false;
1507 bool fSucceeded;
1508
1509 Assert(pUrbLnx->pSplitHead);
1510 Assert((pKUrb->endpoint & 0x80) && !(pKUrb->flags & USBDEVFS_URB_SHORT_NOT_OK));
1511 PUSBPROXYURBLNX pNew = usbProxyLinuxSplitURBFragment(pProxyDev, pUrbLnx->pSplitHead, pUrbLnx);
1512 if (!pNew)
1513 {
1514 Log(("usb-linux: Allocating URB fragment failed. errno=%d pProxyDev=%s\n", errno, usbProxyGetName(pProxyDev)));
1515 return NULL;
1516 }
1517 PVUSBURB pUrb = (PVUSBURB)pUrbLnx->KUrb.usercontext;
1518 fSucceeded = usbProxyLinuxSubmitURB(pProxyDev, pNew, pUrb, &fUnplugged);
1519 if (fUnplugged)
1520 usbProxLinuxUrbUnplugged(pProxyDev);
1521 if (!fSucceeded)
1522 return NULL;
1523 continue; /* try reaping another URB */
1524 }
1525 PUSBPROXYURBLNX pCur;
1526 for (pCur = pUrbLnx->pSplitHead; pCur; pCur = pCur->pSplitNext)
1527 if (!pCur->fSplitElementReaped)
1528 {
1529 pUrbLnx = NULL;
1530 break;
1531 }
1532 if (!pUrbLnx)
1533 continue;
1534 pUrbLnx = pUrbLnx->pSplitHead;
1535 }
1536 break;
1537 }
1538
1539 /*
1540 * Ok, we got one!
1541 */
1542 PVUSBURB pUrb = (PVUSBURB)pUrbLnx->KUrb.usercontext;
1543 if ( pUrb
1544 && !pUrbLnx->fCanceledBySubmit)
1545 {
1546 if (pUrbLnx->pSplitHead)
1547 {
1548 /* split - find the end byte and the first error status. */
1549 Assert(pUrbLnx == pUrbLnx->pSplitHead);
1550 uint8_t *pbEnd = &pUrb->abData[0];
1551 pUrb->enmStatus = VUSBSTATUS_OK;
1552 PUSBPROXYURBLNX pCur;
1553 for (pCur = pUrbLnx; pCur; pCur = pCur->pSplitNext)
1554 {
1555 if (pCur->KUrb.actual_length)
1556 pbEnd = (uint8_t *)pCur->KUrb.buffer + pCur->KUrb.actual_length;
1557 if (pUrb->enmStatus == VUSBSTATUS_OK)
1558 pUrb->enmStatus = vusbProxyLinuxUrbGetStatus(pCur);
1559 }
1560 pUrb->cbData = pbEnd - &pUrb->abData[0];
1561 usbProxyLinuxUrbUnlinkInFlight(pDevLnx, pUrbLnx);
1562 usbProxyLinuxUrbFreeSplitList(pProxyDev, pUrbLnx);
1563 }
1564 else
1565 {
1566 /* unsplit. */
1567 pUrb->enmStatus = vusbProxyLinuxUrbGetStatus(pUrbLnx);
1568 pUrb->cbData = pUrbLnx->KUrb.actual_length;
1569 if (pUrb->enmType == VUSBXFERTYPE_ISOC)
1570 {
1571 unsigned i, off;
1572 for (i = 0, off = 0; i < pUrb->cIsocPkts; i++)
1573 {
1574#if RT_GNUC_PREREQ(4, 6)
1575# pragma GCC diagnostic push
1576# pragma GCC diagnostic ignored "-Warray-bounds"
1577#endif
1578 pUrb->aIsocPkts[i].enmStatus = vusbProxyLinuxStatusToVUsbStatus(pUrbLnx->KUrb.iso_frame_desc[i].status);
1579 Assert(pUrb->aIsocPkts[i].off == off);
1580 pUrb->aIsocPkts[i].cb = pUrbLnx->KUrb.iso_frame_desc[i].actual_length;
1581 off += pUrbLnx->KUrb.iso_frame_desc[i].length;
1582#if RT_GNUC_PREREQ(4, 6)
1583# pragma GCC diagnostic pop
1584#endif
1585 }
1586 }
1587 usbProxyLinuxUrbUnlinkInFlight(pDevLnx, pUrbLnx);
1588 usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
1589 }
1590 pUrb->Dev.pvPrivate = NULL;
1591
1592 /* some adjustments for message transfers. */
1593 if (pUrb->enmType == VUSBXFERTYPE_MSG)
1594 {
1595 pUrb->cbData += sizeof(VUSBSETUP);
1596 usbProxyLinuxUrbSwapSetup((PVUSBSETUP)pUrb->abData);
1597 }
1598 }
1599 else
1600 {
1601 usbProxyLinuxUrbUnlinkInFlight(pDevLnx, pUrbLnx);
1602 usbProxyLinuxUrbFree(pProxyDev, pUrbLnx);
1603 pUrb = NULL;
1604 }
1605
1606 LogFlow(("usbProxyLinuxUrbReap: pProxyDev=%s returns %p\n", usbProxyGetName(pProxyDev), pUrb));
1607 return pUrb;
1608}
1609
1610
1611/**
1612 * Cancels the URB.
1613 * The URB requires reaping, so we don't change its state.
1614 */
1615static DECLCALLBACK(int) usbProxyLinuxUrbCancel(PUSBPROXYDEV pProxyDev, PVUSBURB pUrb)
1616{
1617 int rc = VINF_SUCCESS;
1618 PUSBPROXYURBLNX pUrbLnx = (PUSBPROXYURBLNX)pUrb->Dev.pvPrivate;
1619 if (pUrbLnx->pSplitHead)
1620 {
1621 /* split */
1622 Assert(pUrbLnx == pUrbLnx->pSplitHead);
1623 PUSBPROXYURBLNX pCur;
1624 for (pCur = pUrbLnx; pCur; pCur = pCur->pSplitNext)
1625 {
1626 if (pCur->fSplitElementReaped)
1627 continue;
1628 if ( !usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_DISCARDURB, &pCur->KUrb, true, UINT32_MAX)
1629 || errno == ENOENT)
1630 continue;
1631 if (errno == ENODEV)
1632 break;
1633 /** @todo Think about how to handle errors wrt. to the status code. */
1634 Log(("usb-linux: Discard URB %p failed, errno=%d. pProxyDev=%s!!! (split)\n",
1635 pUrb, errno, usbProxyGetName(pProxyDev)));
1636 }
1637 }
1638 else
1639 {
1640 /* unsplit */
1641 if ( usbProxyLinuxDoIoCtl(pProxyDev, USBDEVFS_DISCARDURB, &pUrbLnx->KUrb, true, UINT32_MAX)
1642 && errno != ENODEV /* deal with elsewhere. */
1643 && errno != ENOENT)
1644 {
1645 Log(("usb-linux: Discard URB %p failed, errno=%d. pProxyDev=%s!!!\n",
1646 pUrb, errno, usbProxyGetName(pProxyDev)));
1647 rc = RTErrConvertFromErrno(errno);
1648 }
1649 }
1650
1651 return rc;
1652}
1653
1654
1655static DECLCALLBACK(int) usbProxyLinuxWakeup(PUSBPROXYDEV pProxyDev)
1656{
1657 PUSBPROXYDEVLNX pDevLnx = USBPROXYDEV_2_DATA(pProxyDev, PUSBPROXYDEVLNX);
1658 size_t cbIgnored;
1659
1660 LogFlowFunc(("pProxyDev=%p\n", pProxyDev));
1661
1662 return RTPipeWrite(pDevLnx->hPipeWakeupW, "", 1, &cbIgnored);
1663}
1664
1665/**
1666 * The Linux USB Proxy Backend.
1667 */
1668const USBPROXYBACK g_USBProxyDeviceHost =
1669{
1670 /* pszName */
1671 "host",
1672 /* cbBackend */
1673 sizeof(USBPROXYDEVLNX),
1674 usbProxyLinuxOpen,
1675 usbProxyLinuxInit,
1676 usbProxyLinuxClose,
1677 usbProxyLinuxReset,
1678 usbProxyLinuxSetConfig,
1679 usbProxyLinuxClaimInterface,
1680 usbProxyLinuxReleaseInterface,
1681 usbProxyLinuxSetInterface,
1682 usbProxyLinuxClearHaltedEp,
1683 usbProxyLinuxUrbQueue,
1684 usbProxyLinuxUrbCancel,
1685 usbProxyLinuxUrbReap,
1686 usbProxyLinuxWakeup,
1687 0
1688};
1689
1690
1691/*
1692 * Local Variables:
1693 * mode: c
1694 * c-file-style: "bsd"
1695 * c-basic-offset: 4
1696 * End:
1697 */
1698
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