1 | /* $Id: USBGetDevices.h 98292 2023-01-25 01:14:53Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Linux host USB device enumeration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 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 | #ifndef MAIN_INCLUDED_USBGetDevices_h
|
---|
29 | #define MAIN_INCLUDED_USBGetDevices_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #include <VBox/usb.h>
|
---|
35 | #include <iprt/mem.h>
|
---|
36 | #include <iprt/string.h>
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Free all the members of a USB device created by the Linux enumeration code.
|
---|
40 | *
|
---|
41 | * @note This duplicates a USBProxyService method which we needed access too
|
---|
42 | * without pulling in the rest of the proxy service code.
|
---|
43 | *
|
---|
44 | * @param pDevice Pointer to the device.
|
---|
45 | */
|
---|
46 | DECLINLINE(void) deviceFreeMembers(PUSBDEVICE pDevice)
|
---|
47 | {
|
---|
48 | RTStrFree((char *)pDevice->pszManufacturer);
|
---|
49 | pDevice->pszManufacturer = NULL;
|
---|
50 | RTStrFree((char *)pDevice->pszProduct);
|
---|
51 | pDevice->pszProduct = NULL;
|
---|
52 | RTStrFree((char *)pDevice->pszSerialNumber);
|
---|
53 | pDevice->pszSerialNumber = NULL;
|
---|
54 |
|
---|
55 | RTStrFree((char *)pDevice->pszAddress);
|
---|
56 | pDevice->pszAddress = NULL;
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Free one USB device created by the Linux enumeration code.
|
---|
61 | *
|
---|
62 | * @note This duplicates a USBProxyService method which we needed access too
|
---|
63 | * without pulling in the rest of the proxy service code.
|
---|
64 | *
|
---|
65 | * @param pDevice Pointer to the device. NULL is OK.
|
---|
66 | */
|
---|
67 | DECLINLINE(void) deviceFree(PUSBDEVICE pDevice)
|
---|
68 | {
|
---|
69 | if (pDevice)
|
---|
70 | {
|
---|
71 | deviceFreeMembers(pDevice);
|
---|
72 | RTMemFree(pDevice);
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Free a linked list of USB devices created by the Linux enumeration code.
|
---|
78 | * @param ppHead Pointer to the first device in the linked list
|
---|
79 | */
|
---|
80 | DECLINLINE(void) deviceListFree(PUSBDEVICE *ppHead)
|
---|
81 | {
|
---|
82 | PUSBDEVICE pHead = *ppHead;
|
---|
83 | while (pHead)
|
---|
84 | {
|
---|
85 | PUSBDEVICE pNext = pHead->pNext;
|
---|
86 | deviceFree(pHead);
|
---|
87 | pHead = pNext;
|
---|
88 | }
|
---|
89 | *ppHead = NULL;
|
---|
90 | }
|
---|
91 |
|
---|
92 | RT_C_DECLS_BEGIN
|
---|
93 |
|
---|
94 | extern bool USBProxyLinuxCheckDeviceRoot(const char *pcszRoot, bool fIsDeviceNodes);
|
---|
95 |
|
---|
96 | #ifdef UNIT_TEST
|
---|
97 | void TestUSBSetupInit(const char *pcszUsbfsRoot, bool fUsbfsAccessible,
|
---|
98 | const char *pcszDevicesRoot, bool fDevicesAccessible,
|
---|
99 | int vrcMethodInitResult);
|
---|
100 | void TestUSBSetEnv(const char *pcszEnvUsb, const char *pcszEnvUsbRoot);
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | extern int USBProxyLinuxChooseMethod(bool *pfUsingUsbfsDevices, const char **ppcszDevicesRoot);
|
---|
104 | #ifdef UNIT_TEST
|
---|
105 | extern void TestUSBSetAvailableUsbfsDevices(const char **pacszDeviceAddresses);
|
---|
106 | extern void TestUSBSetAccessibleFiles(const char **pacszAccessibleFiles);
|
---|
107 | #endif
|
---|
108 |
|
---|
109 | extern PUSBDEVICE USBProxyLinuxGetDevices(const char *pcszDevicesRoot, bool fUseSysfs);
|
---|
110 |
|
---|
111 | RT_C_DECLS_END
|
---|
112 |
|
---|
113 | #endif /* !MAIN_INCLUDED_USBGetDevices_h */
|
---|
114 |
|
---|