VirtualBox

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

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

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

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