1 | /** @file
|
---|
2 | * VUSB - VirtualBox USB.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * If you received this file as part of a commercial VirtualBox
|
---|
17 | * distribution, then only the terms of your commercial VirtualBox
|
---|
18 | * license agreement apply instead of the previous paragraph.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #ifndef __VBox_vusb_h__
|
---|
22 | #define __VBox_vusb_h__
|
---|
23 |
|
---|
24 | #include <VBox/cdefs.h>
|
---|
25 | #include <VBox/types.h>
|
---|
26 |
|
---|
27 | __BEGIN_DECLS
|
---|
28 |
|
---|
29 | /** @defgroup grp_vusb VBox USB API
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | /** Frequency of USB bus (from spec). */
|
---|
34 | #define VUSB_BUS_HZ 12000000
|
---|
35 |
|
---|
36 |
|
---|
37 | /** Pointer to a VBox USB device interface. */
|
---|
38 | typedef struct VUSBIDEVICE *PVUSBIDEVICE;
|
---|
39 |
|
---|
40 | /** Pointer to a VUSB RootHub port interface. */
|
---|
41 | typedef struct VUSBIROOTHUBPORT *PVUSBIROOTHUBPORT;
|
---|
42 |
|
---|
43 | /** Pointer to an USB request descriptor. */
|
---|
44 | typedef struct vusb_urb *PVUSBURB;
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * VBox USB port bitmap.
|
---|
50 | *
|
---|
51 | * Bit 0 == Port 0, ... , Bit 127 == Port 127.
|
---|
52 | */
|
---|
53 | typedef struct VUSBPORTBITMAP
|
---|
54 | {
|
---|
55 | /** 128 bits */
|
---|
56 | char ach[16];
|
---|
57 | } VUSBPORTBITMAP;
|
---|
58 | /** Pointer to a VBox USB port bitmap. */
|
---|
59 | typedef VUSBPORTBITMAP *PVUSBPORTBITMAP;
|
---|
60 |
|
---|
61 |
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * The VUSB RootHub port interface provided by the HCI.
|
---|
67 | */
|
---|
68 | typedef struct VUSBIROOTHUBPORT
|
---|
69 | {
|
---|
70 | /**
|
---|
71 | * Get the number of avilable ports in the hub.
|
---|
72 | *
|
---|
73 | * @returns The number of ports available.
|
---|
74 | * @param pInterface Pointer to this structure.
|
---|
75 | * @param pAvailable Bitmap indicating the available ports. Set bit == available port.
|
---|
76 | */
|
---|
77 | DECLR3CALLBACKMEMBER(unsigned, pfnGetAvailablePorts,(PVUSBIROOTHUBPORT pInterface, PVUSBPORTBITMAP pAvailable));
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * A device is being attached to a port in the roothub.
|
---|
81 | *
|
---|
82 | * @param pInterface Pointer to this structure.
|
---|
83 | * @param pDev Pointer to the device being attached.
|
---|
84 | * @param uPort The port number assigned to the device.
|
---|
85 | */
|
---|
86 | DECLR3CALLBACKMEMBER(int, pfnAttach,(PVUSBIROOTHUBPORT pInterface, PVUSBIDEVICE pDev, unsigned uPort));
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * A device is being detached from a port in the roothub.
|
---|
90 | *
|
---|
91 | * @param pInterface Pointer to this structure.
|
---|
92 | * @param pDev Pointer to the device being detached.
|
---|
93 | * @param uPort The port number assigned to the device.
|
---|
94 | */
|
---|
95 | DECLR3CALLBACKMEMBER(void, pfnDetach,(PVUSBIROOTHUBPORT pInterface, PVUSBIDEVICE pDev, unsigned uPort));
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Reset the root hub.
|
---|
99 | *
|
---|
100 | * @returns VBox status code.
|
---|
101 | * @param pInterface Pointer to this structure.
|
---|
102 | * @param pResetOnLinux Whether or not to do real reset on linux.
|
---|
103 | */
|
---|
104 | DECLR3CALLBACKMEMBER(int, pfnReset,(PVUSBIROOTHUBPORT pInterface, bool fResetOnLinux));
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Do transmit preparations.
|
---|
108 | *
|
---|
109 | * VUSB will call this upon submitting the URB request.
|
---|
110 | *
|
---|
111 | * @param pInterface Pointer to this structure.
|
---|
112 | * @param pUrb Pointer to the URB in question.
|
---|
113 | */
|
---|
114 | DECLR3CALLBACKMEMBER(void, pfnXferPrepare,(PVUSBIROOTHUBPORT pInterface, PVUSBURB pUrb));
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Transfer completion callback routine.
|
---|
118 | *
|
---|
119 | * VUSB will call this when a transfer have been completed
|
---|
120 | * in a one or another way.
|
---|
121 | *
|
---|
122 | * @param pInterface Pointer to this structure.
|
---|
123 | * @param pUrb Pointer to the URB in question.
|
---|
124 | */
|
---|
125 | DECLR3CALLBACKMEMBER(void, pfnXferCompletion,(PVUSBIROOTHUBPORT pInterface, PVUSBURB urb));
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Handle transfer errors.
|
---|
129 | *
|
---|
130 | * VUSB calls this when a transfer attempt failed. This function will respond
|
---|
131 | * indicating wheter to retry or complete the URB with failure.
|
---|
132 | *
|
---|
133 | * @returns Retry indicator.
|
---|
134 | * @param pInterface Pointer to this structure.
|
---|
135 | * @param pUrb Pointer to the URB in question.
|
---|
136 | */
|
---|
137 | DECLR3CALLBACKMEMBER(bool, pfnXferError,(PVUSBIROOTHUBPORT pInterface, PVUSBURB pUrb));
|
---|
138 |
|
---|
139 | } VUSBIROOTHUBPORT;
|
---|
140 |
|
---|
141 |
|
---|
142 | /** Pointer to a VUSB RootHub connector interface. */
|
---|
143 | typedef struct VUSBIROOTHUBCONNECTOR *PVUSBIROOTHUBCONNECTOR;
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * The VUSB RootHub connector interface provided by the VBox USB RootHub driver.
|
---|
147 | */
|
---|
148 | typedef struct VUSBIROOTHUBCONNECTOR
|
---|
149 | {
|
---|
150 | /**
|
---|
151 | * Allocates a new URB for a transfer.
|
---|
152 | *
|
---|
153 | * Either submit using pfnSubmitUrb or free using VUSBUrbFree().
|
---|
154 | *
|
---|
155 | * @returns Pointer to a new URB.
|
---|
156 | * @returns NULL on failure - try again later.
|
---|
157 | * This will not fail if the device wasn't found. We'll fail it
|
---|
158 | * at submit time, since that makes the usage of this api simpler.
|
---|
159 | * @param pInterface Pointer to this struct.
|
---|
160 | * @param DstAddress The destination address of the URB.
|
---|
161 | * @param cbData The amount of data space required.
|
---|
162 | * @param cTds The amount of TD space.
|
---|
163 | */
|
---|
164 | DECLR3CALLBACKMEMBER(PVUSBURB, pfnNewUrb,(PVUSBIROOTHUBCONNECTOR pInterface, uint8_t DstAddress, uint32_t cbData, uint32_t cTds));
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Submits a URB for transfer.
|
---|
168 | * The transfer will do asynchronously if possible.
|
---|
169 | *
|
---|
170 | * @returns VBox status code.
|
---|
171 | * @param pInterface Pointer to this struct.
|
---|
172 | * @param pUrb Pointer to the URB returned by pfnNewUrb.
|
---|
173 | * The URB will be freed in case of failure.
|
---|
174 | */
|
---|
175 | DECLR3CALLBACKMEMBER(int, pfnSubmitUrb,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb));
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * Call to service asynchronous URB completions in a polling fashion.
|
---|
179 | *
|
---|
180 | * Reaped URBs will be finished by calling the completion callback,
|
---|
181 | * thus there is no return code or input or anything from this function
|
---|
182 | * except for potential state changes elsewhere.
|
---|
183 | *
|
---|
184 | * @returns VINF_SUCCESS if no URBs are pending upon return.
|
---|
185 | * @returns VERR_TIMEOUT if one or more URBs are still in flight upon returning.
|
---|
186 | * @returns Other VBox status code.
|
---|
187 | *
|
---|
188 | * @param pInterface Pointer to this struct.
|
---|
189 | * @param cMillies Number of milliseconds to poll for completion.
|
---|
190 | */
|
---|
191 | DECLR3CALLBACKMEMBER(void, pfnReapAsyncUrbs,(PVUSBIROOTHUBCONNECTOR pInterface, unsigned cMillies));
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Cancels and completes - with CRC failure - all in-flight async URBs.
|
---|
195 | * This is typically done before saving a state.
|
---|
196 | *
|
---|
197 | * @param pInterface Pointer to this struct.
|
---|
198 | */
|
---|
199 | DECLR3CALLBACKMEMBER(void, pfnCancelAllUrbs,(PVUSBIROOTHUBCONNECTOR pInterface));
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * Attach the device to the root hub.
|
---|
203 | * The device must not be attached to any hub for this call to succeed.
|
---|
204 | *
|
---|
205 | * @returns VBox status code.
|
---|
206 | * @param pInterface Pointer to this struct.
|
---|
207 | * @param pDevice Pointer to the device (interface) attach.
|
---|
208 | */
|
---|
209 | DECLR3CALLBACKMEMBER(int, pfnAttachDevice,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice));
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Detach the device from the root hub.
|
---|
213 | * The device must already be attached for this call to succeed.
|
---|
214 | *
|
---|
215 | * @returns VBox status code.
|
---|
216 | * @param pInterface Pointer to this struct.
|
---|
217 | * @param pDevice Pointer to the device (interface) to detach.
|
---|
218 | */
|
---|
219 | DECLR3CALLBACKMEMBER(int, pfnDetachDevice,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice));
|
---|
220 |
|
---|
221 | } VUSBIROOTHUBCONNECTOR;
|
---|
222 |
|
---|
223 |
|
---|
224 | #ifdef IN_RING3
|
---|
225 | /** @copydoc VUSBIROOTHUBCONNECTOR::pfnNewUrb */
|
---|
226 | DECLINLINE(PVUSBURB) VUSBIRhNewUrb(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t DstAddress, uint32_t cbData, uint32_t cTds)
|
---|
227 | {
|
---|
228 | return pInterface->pfnNewUrb(pInterface, DstAddress, cbData, cTds);
|
---|
229 | }
|
---|
230 |
|
---|
231 | /** @copydoc VUSBIROOTHUBCONNECTOR::pfnSubmitUrb */
|
---|
232 | DECLINLINE(int) VUSBIRhSubmitUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb)
|
---|
233 | {
|
---|
234 | return pInterface->pfnSubmitUrb(pInterface, pUrb);
|
---|
235 | }
|
---|
236 |
|
---|
237 | /** @copydoc VUSBIROOTHUBCONNECTOR::pfnReapAsyncUrbs */
|
---|
238 | DECLINLINE(void) VUSBIRhReapAsyncUrbs(PVUSBIROOTHUBCONNECTOR pInterface, unsigned cMillies)
|
---|
239 | {
|
---|
240 | pInterface->pfnReapAsyncUrbs(pInterface, cMillies);
|
---|
241 | }
|
---|
242 |
|
---|
243 | /** @copydoc VUSBIROOTHUBCONNECTOR::pfnCancelAllUrbs */
|
---|
244 | DECLINLINE(void) VUSBIRhCancelAllUrbs(PVUSBIROOTHUBCONNECTOR pInterface)
|
---|
245 | {
|
---|
246 | pInterface->pfnCancelAllUrbs(pInterface);
|
---|
247 | }
|
---|
248 |
|
---|
249 | /** @copydoc VUSBIROOTHUBCONNECTOR::pfnAttachDevice */
|
---|
250 | DECLINLINE(int) VUSBIRhAttachDevice(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice)
|
---|
251 | {
|
---|
252 | return pInterface->pfnAttachDevice(pInterface, pDevice);
|
---|
253 | }
|
---|
254 |
|
---|
255 | /** @copydoc VUSBIROOTHUBCONNECTOR::pfnDetachDevice */
|
---|
256 | DECLINLINE(int) VUSBIRhDetachDevice(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice)
|
---|
257 | {
|
---|
258 | return pInterface->pfnDetachDevice(pInterface, pDevice);
|
---|
259 | }
|
---|
260 | #endif /* IN_RING3 */
|
---|
261 |
|
---|
262 |
|
---|
263 |
|
---|
264 | /** Pointer to a Root Hub Configuration Interface. */
|
---|
265 | typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
|
---|
266 |
|
---|
267 | /**
|
---|
268 | * Root Hub Configuration Interface (intended for MAIN).
|
---|
269 | */
|
---|
270 | typedef struct VUSBIRHCONFIG
|
---|
271 | {
|
---|
272 | /**
|
---|
273 | * Creates a USB proxy device and attaches it to the root hub.
|
---|
274 | *
|
---|
275 | * @returns VBox status code.
|
---|
276 | * @param pInterface Pointer to the root hub configuration interface structure.
|
---|
277 | * @param pUuid Pointer to the UUID for the new device.
|
---|
278 | * @param fRemote Whether the device must use the VRDP backend.
|
---|
279 | * @param pszAddress OS specific device address.
|
---|
280 | * @param pvBackend An opaque pointer for the backend. Only used by
|
---|
281 | * the VRDP backend so far.
|
---|
282 | */
|
---|
283 | DECLR3CALLBACKMEMBER(int, pfnCreateProxyDevice,(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid, bool fRemote, const char *pszAddress, void *pvBackend));
|
---|
284 |
|
---|
285 | /**
|
---|
286 | * Removes a USB proxy device from the root hub and destroys it.
|
---|
287 | *
|
---|
288 | * @returns VBox status code.
|
---|
289 | * @param pInterface Pointer to the root hub configuration interface structure.
|
---|
290 | * @param pUuid Pointer to the UUID for the device.
|
---|
291 | */
|
---|
292 | DECLR3CALLBACKMEMBER(int, pfnDestroyProxyDevice,(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid));
|
---|
293 |
|
---|
294 | } VUSBIRHCONFIG;
|
---|
295 |
|
---|
296 | #ifdef IN_RING3
|
---|
297 | /** @copydoc VUSBIRHCONFIG::pfnCreateProxyDevice */
|
---|
298 | DECLINLINE(int) VUSBIRhCreateProxyDevice(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid, bool fRemote, const char *pszAddress, void *pvBackend)
|
---|
299 | {
|
---|
300 | return pInterface->pfnCreateProxyDevice(pInterface, pUuid, fRemote, pszAddress, pvBackend);
|
---|
301 | }
|
---|
302 |
|
---|
303 | /** @copydoc VUSBIRHCONFIG::pfnDestroyProxyDevice */
|
---|
304 | DECLINLINE(int) VUSBIRhDestroyProxyDevice(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid)
|
---|
305 | {
|
---|
306 | return pInterface->pfnDestroyProxyDevice(pInterface, pUuid);
|
---|
307 | }
|
---|
308 | #endif /* IN_RING3 */
|
---|
309 |
|
---|
310 |
|
---|
311 |
|
---|
312 | /**
|
---|
313 | * VUSB device reset completion callback function.
|
---|
314 | * This is called by the reset thread when the reset has been completed.
|
---|
315 | *
|
---|
316 | * @param pDev Pointer to the virtual USB device core.
|
---|
317 | * @param rc The VBox status code of the reset operation.
|
---|
318 | * @param pvUser User specific argument.
|
---|
319 | *
|
---|
320 | * @thread The reset thread or EMT.
|
---|
321 | */
|
---|
322 | typedef DECLCALLBACK(void) FNVUSBRESETDONE(PVUSBIDEVICE pDevice, int rc, void *pvUser);
|
---|
323 | /** Pointer to a device reset completion callback function (FNUSBRESETDONE). */
|
---|
324 | typedef FNVUSBRESETDONE *PFNVUSBRESETDONE;
|
---|
325 |
|
---|
326 | /**
|
---|
327 | * The state of a VUSB Device.
|
---|
328 | *
|
---|
329 | * @remark The order of these states is vital.
|
---|
330 | */
|
---|
331 | typedef enum VUSBDEVICESTATE
|
---|
332 | {
|
---|
333 | VUSB_DEVICE_STATE_INVALID = 0,
|
---|
334 | VUSB_DEVICE_STATE_DETACHED,
|
---|
335 | VUSB_DEVICE_STATE_ATTACHED,
|
---|
336 | VUSB_DEVICE_STATE_POWERED,
|
---|
337 | VUSB_DEVICE_STATE_DEFAULT,
|
---|
338 | VUSB_DEVICE_STATE_ADDRESS,
|
---|
339 | VUSB_DEVICE_STATE_CONFIGURED,
|
---|
340 | VUSB_DEVICE_STATE_SUSPENDED,
|
---|
341 | /** The device is being reset. Don't mess with it.
|
---|
342 | * Next states: VUSB_DEVICE_STATE_DEFAULT, VUSB_DEVICE_STATE_RESET_DESTROY
|
---|
343 | */
|
---|
344 | VUSB_DEVICE_STATE_RESET,
|
---|
345 | /** The device is being reset and should be destroyed. Don't mess with it.
|
---|
346 | * Prev state: VUSB_DEVICE_STATE_RESET
|
---|
347 | * Next state: VUSB_DEVICE_STATE_DESTROY
|
---|
348 | */
|
---|
349 | VUSB_DEVICE_STATE_RESET_DESTROY,
|
---|
350 | /** The device is being destroyed.
|
---|
351 | * Prev state: Any but VUSB_DEVICE_STATE_RESET
|
---|
352 | * Next state: VUSB_DEVICE_STATE_DESTROYED
|
---|
353 | */
|
---|
354 | VUSB_DEVICE_STATE_DESTROY,
|
---|
355 | /** The device has been destroy. */
|
---|
356 | VUSB_DEVICE_STATE_DESTROYED,
|
---|
357 | /** The usual 32-bit hack. */
|
---|
358 | VUSB_DEVICE_STATE_32BIT_HACK = 0x7fffffff
|
---|
359 | } VUSBDEVICESTATE;
|
---|
360 |
|
---|
361 |
|
---|
362 | /**
|
---|
363 | * USB Device Interface.
|
---|
364 | */
|
---|
365 | typedef struct VUSBIDEVICE
|
---|
366 | {
|
---|
367 | /**
|
---|
368 | * Resets the device.
|
---|
369 | *
|
---|
370 | * Since a device reset shall take at least 10ms from the guest point of view,
|
---|
371 | * it must be performed asynchronously. We create a thread which performs this
|
---|
372 | * operation and ensures it will take at least 10ms.
|
---|
373 | *
|
---|
374 | * At times - like init - a synchronous reset is required, this can be done
|
---|
375 | * by passing NULL for pfnDone.
|
---|
376 | *
|
---|
377 | * -- internal stuff, move it --
|
---|
378 | * While the device is being reset it is in the VUSB_DEVICE_STATE_RESET state.
|
---|
379 | * On completion it will be in the VUSB_DEVICE_STATE_DEFAULT state if successful,
|
---|
380 | * or in the VUSB_DEVICE_STATE_DETACHED state if the rest failed.
|
---|
381 | * -- internal stuff, move it --
|
---|
382 | *
|
---|
383 | * @returns VBox status code.
|
---|
384 | * @param pInterface Pointer to this structure.
|
---|
385 | * @param fResetOnLinux Set if we can permit a real reset and a potential logical
|
---|
386 | * device reconnect on linux hosts.
|
---|
387 | * @param pfnDone Pointer to the completion routine. If NULL a synchronous
|
---|
388 | * reset is preformed not respecting the 10ms.
|
---|
389 | * @param pvUser User argument to the completion routine.
|
---|
390 | * @param pVM Pointer to the VM handle if callback in EMT is required. (optional)
|
---|
391 | */
|
---|
392 | DECLR3CALLBACKMEMBER(int, pfnReset,(PVUSBIDEVICE pInterface, bool fResetOnLinux,
|
---|
393 | PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM));
|
---|
394 |
|
---|
395 | /**
|
---|
396 | * Powers on the device.
|
---|
397 | *
|
---|
398 | * @returns VBox status code.
|
---|
399 | * @param pInterface Pointer to the device interface structure.
|
---|
400 | */
|
---|
401 | DECLR3CALLBACKMEMBER(int, pfnPowerOn,(PVUSBIDEVICE pInterface));
|
---|
402 |
|
---|
403 | /**
|
---|
404 | * Powers off the device.
|
---|
405 | *
|
---|
406 | * @returns VBox status code.
|
---|
407 | * @param pInterface Pointer to the device interface structure.
|
---|
408 | */
|
---|
409 | DECLR3CALLBACKMEMBER(int, pfnPowerOff,(PVUSBIDEVICE pInterface));
|
---|
410 |
|
---|
411 | /**
|
---|
412 | * Get the state of the device.
|
---|
413 | *
|
---|
414 | * @returns Device state.
|
---|
415 | * @param pInterface Pointer to the device interface structure.
|
---|
416 | */
|
---|
417 | DECLR3CALLBACKMEMBER(VUSBDEVICESTATE, pfnGetState,(PVUSBIDEVICE pInterface));
|
---|
418 |
|
---|
419 | } VUSBIDEVICE;
|
---|
420 |
|
---|
421 |
|
---|
422 | #ifdef IN_RING3
|
---|
423 | /**
|
---|
424 | * Resets the device.
|
---|
425 | *
|
---|
426 | * Since a device reset shall take at least 10ms from the guest point of view,
|
---|
427 | * it must be performed asynchronously. We create a thread which performs this
|
---|
428 | * operation and ensures it will take at least 10ms.
|
---|
429 | *
|
---|
430 | * At times - like init - a synchronous reset is required, this can be done
|
---|
431 | * by passing NULL for pfnDone.
|
---|
432 | *
|
---|
433 | * -- internal stuff, move it --
|
---|
434 | * While the device is being reset it is in the VUSB_DEVICE_STATE_RESET state.
|
---|
435 | * On completion it will be in the VUSB_DEVICE_STATE_DEFAULT state if successful,
|
---|
436 | * or in the VUSB_DEVICE_STATE_DETACHED state if the rest failed.
|
---|
437 | * -- internal stuff, move it --
|
---|
438 | *
|
---|
439 | * @returns VBox status code.
|
---|
440 | * @param pInterface Pointer to the device interface structure.
|
---|
441 | * @param fResetOnLinux Set if we can permit a real reset and a potential logical
|
---|
442 | * device reconnect on linux hosts.
|
---|
443 | * @param pfnDone Pointer to the completion routine. If NULL a synchronous
|
---|
444 | * reset is preformed not respecting the 10ms.
|
---|
445 | * @param pvUser User argument to the completion routine.
|
---|
446 | * @param pVM Pointer to the VM handle if callback in EMT is required. (optional)
|
---|
447 | */
|
---|
448 | DECLINLINE(int) VUSBIDevReset(PVUSBIDEVICE pInterface, bool fResetOnLinux, PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM)
|
---|
449 | {
|
---|
450 | return pInterface->pfnReset(pInterface, fResetOnLinux, pfnDone, pvUser, pVM);
|
---|
451 | }
|
---|
452 |
|
---|
453 | /**
|
---|
454 | * Powers on the device.
|
---|
455 | *
|
---|
456 | * @returns VBox status code.
|
---|
457 | * @param pInterface Pointer to the device interface structure.
|
---|
458 | */
|
---|
459 | DECLINLINE(int) VUSBIDevPowerOn(PVUSBIDEVICE pInterface)
|
---|
460 | {
|
---|
461 | return pInterface->pfnPowerOn(pInterface);
|
---|
462 | }
|
---|
463 |
|
---|
464 | /**
|
---|
465 | * Powers off the device.
|
---|
466 | *
|
---|
467 | * @returns VBox status code.
|
---|
468 | * @param pInterface Pointer to the device interface structure.
|
---|
469 | */
|
---|
470 | DECLINLINE(int) VUSBIDevPowerOff(PVUSBIDEVICE pInterface)
|
---|
471 | {
|
---|
472 | return pInterface->pfnPowerOff(pInterface);
|
---|
473 | }
|
---|
474 |
|
---|
475 | /**
|
---|
476 | * Get the state of the device.
|
---|
477 | *
|
---|
478 | * @returns Device state.
|
---|
479 | * @param pInterface Pointer to the device interface structure.
|
---|
480 | */
|
---|
481 | DECLINLINE(VUSBDEVICESTATE) VUSBIDevGetState(PVUSBIDEVICE pInterface)
|
---|
482 | {
|
---|
483 | return pInterface->pfnGetState(pInterface);
|
---|
484 | }
|
---|
485 | #endif /* IN_RING3 */
|
---|
486 |
|
---|
487 |
|
---|
488 | /** @name URB
|
---|
489 | * @{ */
|
---|
490 |
|
---|
491 | /**
|
---|
492 | * VUSB Transfer status codes.
|
---|
493 | */
|
---|
494 | typedef enum VUSBSTATUS
|
---|
495 | {
|
---|
496 | /** Transer was ok. */
|
---|
497 | VUSBSTATUS_OK = 0,
|
---|
498 | #define VUSB_XFER_OK VUSBSTATUS_OK
|
---|
499 | /** Transfer stalled, endpoint halted. */
|
---|
500 | VUSBSTATUS_STALL,
|
---|
501 | #define VUSB_XFER_STALL VUSBSTATUS_STALL
|
---|
502 | /** Device not responding. */
|
---|
503 | VUSBSTATUS_DNR,
|
---|
504 | #define VUSB_XFER_DNR VUSBSTATUS_DNR
|
---|
505 | /** CRC error. */
|
---|
506 | VUSBSTATUS_CRC,
|
---|
507 | #define VUSB_XFER_CRC VUSBSTATUS_CRC
|
---|
508 | /** Underflow error. */
|
---|
509 | VUSBSTATUS_UNDERFLOW,
|
---|
510 | /** The isochronous buffer hasn't been touched. */
|
---|
511 | VUSBSTATUS_NOT_ACCESSED,
|
---|
512 | /** Invalid status. */
|
---|
513 | VUSBSTATUS_INVALID = 0x7f
|
---|
514 | } VUSBSTATUS;
|
---|
515 |
|
---|
516 |
|
---|
517 | /**
|
---|
518 | * VUSB Transfer types.
|
---|
519 | */
|
---|
520 | typedef enum VUSBXFERTYPE
|
---|
521 | {
|
---|
522 | /** Control message. Used to represent a single control transfer. */
|
---|
523 | VUSBXFERTYPE_CTRL = 0,
|
---|
524 | #define VUSB_TRANSFER_TYPE_CTRL VUSBXFERTYPE_CTRL
|
---|
525 | /* Isochronous transfer. */
|
---|
526 | VUSBXFERTYPE_ISOC,
|
---|
527 | #define VUSB_TRANSFER_TYPE_ISOC VUSBXFERTYPE_ISOC
|
---|
528 | /** Bulk transfer. */
|
---|
529 | VUSBXFERTYPE_BULK,
|
---|
530 | #define VUSB_TRANSFER_TYPE_BULK VUSBXFERTYPE_BULK
|
---|
531 | /** Interrupt transfer. */
|
---|
532 | VUSBXFERTYPE_INTR,
|
---|
533 | #define VUSB_TRANSFER_TYPE_INTR VUSBXFERTYPE_INTR
|
---|
534 | /** Complete control message. Used to represent an entire control message. */
|
---|
535 | VUSBXFERTYPE_MSG,
|
---|
536 | #define VUSB_TRANSFER_TYPE_MSG VUSBXFERTYPE_MSG
|
---|
537 | /** Invalid transfer type. */
|
---|
538 | VUSBXFERTYPE_INVALID = 0x7f
|
---|
539 | } VUSBXFERTYPE;
|
---|
540 |
|
---|
541 |
|
---|
542 | /**
|
---|
543 | * VUSB transfer direction.
|
---|
544 | */
|
---|
545 | typedef enum VUSBDIRECTION
|
---|
546 | {
|
---|
547 | /** Setup */
|
---|
548 | VUSBDIRECTION_SETUP = 0,
|
---|
549 | #define VUSB_DIRECTION_SETUP VUSBDIRECTION_SETUP
|
---|
550 | /** In - Device to host. */
|
---|
551 | VUSBDIRECTION_IN = 1,
|
---|
552 | #define VUSB_DIRECTION_IN VUSBDIRECTION_IN
|
---|
553 | /** Out - Host to device. */
|
---|
554 | VUSBDIRECTION_OUT = 2,
|
---|
555 | #define VUSB_DIRECTION_OUT VUSBDIRECTION_OUT
|
---|
556 | /** Invalid direction */
|
---|
557 | VUSBDIRECTION_INVALID = 0x7f
|
---|
558 | } VUSBDIRECTION;
|
---|
559 |
|
---|
560 | /**
|
---|
561 | * The URB states
|
---|
562 | */
|
---|
563 | typedef enum VUSBURBSTATE
|
---|
564 | {
|
---|
565 | /** The usual invalid state. */
|
---|
566 | VUSBURBSTATE_INVALID = 0,
|
---|
567 | /** The URB is free, i.e. not in use.
|
---|
568 | * Next state: ALLOCATED */
|
---|
569 | VUSBURBSTATE_FREE,
|
---|
570 | /** The URB is allocated, i.e. being prepared for submission.
|
---|
571 | * Next state: FREE, IN_FLIGHT */
|
---|
572 | VUSBURBSTATE_ALLOCATED,
|
---|
573 | /** The URB is in flight.
|
---|
574 | * Next state: REAPED, CANCELLED */
|
---|
575 | VUSBURBSTATE_IN_FLIGHT,
|
---|
576 | /** The URB has been reaped and is being completed.
|
---|
577 | * Next state: FREE */
|
---|
578 | VUSBURBSTATE_REAPED,
|
---|
579 | /** The URB has been cancelled and is awaiting reaping and immediate freeing.
|
---|
580 | * Next state: FREE */
|
---|
581 | VUSBURBSTATE_CANCELLED,
|
---|
582 | /** The end of the valid states (exclusive). */
|
---|
583 | VUSBURBSTATE_END,
|
---|
584 | /** The usual 32-bit blow up. */
|
---|
585 | VUSBURBSTATE_32BIT_HACK = 0x7fffffff
|
---|
586 | } VUSBURBSTATE;
|
---|
587 |
|
---|
588 |
|
---|
589 | /**
|
---|
590 | * Information about a isochronous packet.
|
---|
591 | */
|
---|
592 | typedef struct VUSBURBISOCPKT
|
---|
593 | {
|
---|
594 | /** The size of the packet.
|
---|
595 | * IN: The packet size. I.e. the number of bytes to the next packet or end of buffer.
|
---|
596 | * OUT: The actual size transfered. */
|
---|
597 | uint16_t cb;
|
---|
598 | /** The offset of the packet. (Relative to VUSBURB::abData[0].)
|
---|
599 | * OUT: This can be changed by the USB device if it does some kind of buffer squeezing. */
|
---|
600 | uint16_t off;
|
---|
601 | /** The status of the transfer.
|
---|
602 | * IN: VUSBSTATUS_INVALID
|
---|
603 | * OUT: VUSBSTATUS_INVALID if nothing was done, otherwise the correct status. */
|
---|
604 | VUSBSTATUS enmStatus;
|
---|
605 | } VUSBURBISOCPKT;
|
---|
606 | /** Pointer to a isochronous packet. */
|
---|
607 | typedef VUSBURBISOCPKT *PVUSBURBISOCPTK;
|
---|
608 | /** Pointer to a const isochronous packet. */
|
---|
609 | typedef const VUSBURBISOCPKT *PCVUSBURBISOCPKT;
|
---|
610 |
|
---|
611 | /**
|
---|
612 | * Asynchronous USB request descriptor
|
---|
613 | */
|
---|
614 | typedef struct vusb_urb
|
---|
615 | {
|
---|
616 | /** URB magic value. */
|
---|
617 | uint32_t u32Magic;
|
---|
618 | /** The USR state. */
|
---|
619 | VUSBURBSTATE enmState;
|
---|
620 |
|
---|
621 | /** The VUSB data. */
|
---|
622 | struct VUSBURBVUSB
|
---|
623 | {
|
---|
624 | /** URB chain pointer. */
|
---|
625 | PVUSBURB pNext;
|
---|
626 | /** URB chain pointer. */
|
---|
627 | PVUSBURB *ppPrev;
|
---|
628 | /** Pointer to the original for control messages. */
|
---|
629 | PVUSBURB pCtrlUrb;
|
---|
630 | /** Sepcific to the pfnFree function. */
|
---|
631 | void *pvFreeCtx;
|
---|
632 | /**
|
---|
633 | * Callback which will free the URB once it's reaped and completed.
|
---|
634 | * @param pUrb The URB.
|
---|
635 | */
|
---|
636 | DECLCALLBACKMEMBER(void, pfnFree)(PVUSBURB pUrb);
|
---|
637 | /** Submit timestamp. (logging only) */
|
---|
638 | uint64_t u64SubmitTS;
|
---|
639 | /** The allocated data length. */
|
---|
640 | uint32_t cbDataAllocated;
|
---|
641 | /** The allocated TD length. */
|
---|
642 | uint32_t cTdsAllocated;
|
---|
643 | } VUsb;
|
---|
644 |
|
---|
645 | /** The host controller data. */
|
---|
646 | struct VUSBURBHCI
|
---|
647 | {
|
---|
648 | /** The endpoint descriptor address. */
|
---|
649 | uint32_t EdAddr;
|
---|
650 | /** Number of Tds in the array. */
|
---|
651 | uint32_t cTds;
|
---|
652 | /** Pointer to an array of TD info items.*/
|
---|
653 | struct VUSBURBHCITD
|
---|
654 | {
|
---|
655 | /** The address of the */
|
---|
656 | uint32_t TdAddr;
|
---|
657 | /** A copy of the TD. */
|
---|
658 | uint32_t TdCopy[8];
|
---|
659 | } *paTds;
|
---|
660 | /** URB chain pointer. */
|
---|
661 | PVUSBURB pNext;
|
---|
662 | /** When this URB was created.
|
---|
663 | * (Used for isochronous frames and for logging.) */
|
---|
664 | uint32_t u32FrameNo;
|
---|
665 | /** Flag indicating that the TDs have been unlinked. */
|
---|
666 | bool fUnlinked;
|
---|
667 | } Hci;
|
---|
668 |
|
---|
669 | /** The device data. */
|
---|
670 | struct VUSBURBDEV
|
---|
671 | {
|
---|
672 | /** Pointer to the proxy URB. */
|
---|
673 | void *pvProxyUrb;
|
---|
674 | } Dev;
|
---|
675 |
|
---|
676 | /** The device - can be NULL untill submit is attempted.
|
---|
677 | * This is set when allocating the URB. */
|
---|
678 | struct vusb_dev *pDev;
|
---|
679 | /** The device address.
|
---|
680 | * This is set at allocation time. */
|
---|
681 | uint8_t DstAddress;
|
---|
682 |
|
---|
683 | /** The endpoint.
|
---|
684 | * IN: Must be set before submitting the URB. */
|
---|
685 | uint8_t EndPt;
|
---|
686 | /** The transfer type.
|
---|
687 | * IN: Must be set before submitting the URB. */
|
---|
688 | VUSBXFERTYPE enmType;
|
---|
689 | /** The transfer direction.
|
---|
690 | * IN: Must be set before submitting the URB. */
|
---|
691 | VUSBDIRECTION enmDir;
|
---|
692 | /** Indicates whether it is OK to receive/send less data than requested.
|
---|
693 | * IN: Must be initialized before submitting the URB. */
|
---|
694 | bool fShortNotOk;
|
---|
695 | /** The transfer status.
|
---|
696 | * OUT: This is set when reaping the URB. */
|
---|
697 | VUSBSTATUS enmStatus;
|
---|
698 |
|
---|
699 | /** The number of isochronous packets describe in aIsocPkts.
|
---|
700 | * This is ignored when enmType isn't VUSBXFERTYPE_ISOC. */
|
---|
701 | uint32_t cIsocPkts;
|
---|
702 | /** The iso packets within abData.
|
---|
703 | * This is ignored when enmType isn't VUSBXFERTYPE_ISOC. */
|
---|
704 | VUSBURBISOCPKT aIsocPkts[8];
|
---|
705 |
|
---|
706 | /** The message length.
|
---|
707 | * IN: The amount of data to send / receive - set at allocation time.
|
---|
708 | * OUT: The amount of data sent / received. */
|
---|
709 | uint32_t cbData;
|
---|
710 | /** The message data.
|
---|
711 | * IN: On host to device transfers, the data to send.
|
---|
712 | * OUT: On device to host transfers, the data to received. */
|
---|
713 | uint8_t abData[8*_1K];
|
---|
714 | } VUSBURB;
|
---|
715 |
|
---|
716 | /** The magic value of a valid VUSBURB. (Murakami Haruki) */
|
---|
717 | #define VUSBURB_MAGIC 0x19490112
|
---|
718 |
|
---|
719 | /** @} */
|
---|
720 |
|
---|
721 |
|
---|
722 | /** @} */
|
---|
723 |
|
---|
724 | __END_DECLS
|
---|
725 |
|
---|
726 | #endif
|
---|