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