1 | /* $Id: RemoteUSBBackend.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VirtualBox Remote USB backend
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox base platform packages, as
|
---|
11 | * available from https://www.virtualbox.org.
|
---|
12 | *
|
---|
13 | * This program is free software; you can redistribute it and/or
|
---|
14 | * modify it under the terms of the GNU General Public License
|
---|
15 | * as published by the Free Software Foundation, in version 3 of the
|
---|
16 | * License.
|
---|
17 | *
|
---|
18 | * This program is distributed in the hope that it will be useful, but
|
---|
19 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | * General Public License for more details.
|
---|
22 | *
|
---|
23 | * You should have received a copy of the GNU General Public License
|
---|
24 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 | *
|
---|
26 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
27 | */
|
---|
28 |
|
---|
29 | #ifndef MAIN_INCLUDED_RemoteUSBBackend_h
|
---|
30 | #define MAIN_INCLUDED_RemoteUSBBackend_h
|
---|
31 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
32 | # pragma once
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include "RemoteUSBDeviceImpl.h"
|
---|
36 |
|
---|
37 | #include <VBox/RemoteDesktop/VRDE.h>
|
---|
38 | #include <VBox/vrdpusb.h>
|
---|
39 |
|
---|
40 | #include <iprt/critsect.h>
|
---|
41 |
|
---|
42 | //typedef enum
|
---|
43 | //{
|
---|
44 | // RDLIdle = 0,
|
---|
45 | // RDLReqSent,
|
---|
46 | // RDLObtained
|
---|
47 | //} RDLState;
|
---|
48 |
|
---|
49 | class Console;
|
---|
50 | class ConsoleVRDPServer;
|
---|
51 |
|
---|
52 | DECLCALLBACK(int) USBClientResponseCallback (void *pv, uint32_t u32ClientId, uint8_t code, const void *pvRet, uint32_t cbRet);
|
---|
53 |
|
---|
54 |
|
---|
55 | /* How many remote devices can be attached to a remote client.
|
---|
56 | * Normally a client computer has 2-8 physical USB ports, so 16 devices
|
---|
57 | * should be usually enough.
|
---|
58 | */
|
---|
59 | #define VRDP_MAX_USB_DEVICES_PER_CLIENT (16)
|
---|
60 |
|
---|
61 | class RemoteUSBBackendListable
|
---|
62 | {
|
---|
63 | public:
|
---|
64 | RemoteUSBBackendListable *pNext;
|
---|
65 | RemoteUSBBackendListable *pPrev;
|
---|
66 |
|
---|
67 | RemoteUSBBackendListable() : pNext (NULL), pPrev (NULL) {};
|
---|
68 | };
|
---|
69 |
|
---|
70 | class RemoteUSBBackend: public RemoteUSBBackendListable
|
---|
71 | {
|
---|
72 | public:
|
---|
73 | RemoteUSBBackend(Console *console, ConsoleVRDPServer *server, uint32_t u32ClientId);
|
---|
74 | ~RemoteUSBBackend();
|
---|
75 |
|
---|
76 | uint32_t ClientId (void) { return mu32ClientId; }
|
---|
77 |
|
---|
78 | void AddRef (void);
|
---|
79 | void Release (void);
|
---|
80 |
|
---|
81 | REMOTEUSBCALLBACK *GetBackendCallbackPointer (void) { return &mCallback; }
|
---|
82 |
|
---|
83 | void NotifyDelete (void);
|
---|
84 |
|
---|
85 | void PollRemoteDevices (void);
|
---|
86 |
|
---|
87 | public: /* Functions for internal use. */
|
---|
88 | ConsoleVRDPServer *VRDPServer (void) { return mServer; };
|
---|
89 |
|
---|
90 | bool pollingEnabledURB (void) { return mfPollURB; }
|
---|
91 |
|
---|
92 | int saveDeviceList (const void *pvList, uint32_t cbList);
|
---|
93 |
|
---|
94 | int negotiateResponse (const VRDEUSBREQNEGOTIATERET *pret, uint32_t cbRet);
|
---|
95 |
|
---|
96 | int reapURB (const void *pvBody, uint32_t cbBody);
|
---|
97 |
|
---|
98 | void request (void);
|
---|
99 | void release (void);
|
---|
100 |
|
---|
101 | PREMOTEUSBDEVICE deviceFromId (VRDEUSBDEVID id);
|
---|
102 |
|
---|
103 | void addDevice (PREMOTEUSBDEVICE pDevice);
|
---|
104 | void removeDevice (PREMOTEUSBDEVICE pDevice);
|
---|
105 |
|
---|
106 | bool addUUID (const Guid *pUuid);
|
---|
107 | bool findUUID (const Guid *pUuid);
|
---|
108 | void removeUUID (const Guid *pUuid);
|
---|
109 |
|
---|
110 | private:
|
---|
111 | Console *mConsole;
|
---|
112 | ConsoleVRDPServer *mServer;
|
---|
113 |
|
---|
114 | int cRefs;
|
---|
115 |
|
---|
116 | uint32_t mu32ClientId;
|
---|
117 |
|
---|
118 | RTCRITSECT mCritsect;
|
---|
119 |
|
---|
120 | REMOTEUSBCALLBACK mCallback;
|
---|
121 |
|
---|
122 | bool mfHasDeviceList;
|
---|
123 |
|
---|
124 | void *mpvDeviceList;
|
---|
125 | uint32_t mcbDeviceList;
|
---|
126 |
|
---|
127 | typedef enum {
|
---|
128 | PollRemoteDevicesStatus_Negotiate,
|
---|
129 | PollRemoteDevicesStatus_WaitNegotiateResponse,
|
---|
130 | PollRemoteDevicesStatus_SendRequest,
|
---|
131 | PollRemoteDevicesStatus_WaitResponse,
|
---|
132 | PollRemoteDevicesStatus_Dereferenced
|
---|
133 | } PollRemoteDevicesStatus;
|
---|
134 |
|
---|
135 | PollRemoteDevicesStatus menmPollRemoteDevicesStatus;
|
---|
136 |
|
---|
137 | bool mfPollURB;
|
---|
138 |
|
---|
139 | PREMOTEUSBDEVICE mpDevices;
|
---|
140 |
|
---|
141 | bool mfWillBeDeleted;
|
---|
142 |
|
---|
143 | Guid aGuids[VRDP_MAX_USB_DEVICES_PER_CLIENT];
|
---|
144 |
|
---|
145 | /* VRDP_USB_VERSION_2: the client version. */
|
---|
146 | uint32_t mClientVersion;
|
---|
147 |
|
---|
148 | /* VRDP_USB_VERSION_3: the client sends VRDE_USB_REQ_DEVICE_LIST_EXT_RET. */
|
---|
149 | bool mfDescExt;
|
---|
150 | };
|
---|
151 |
|
---|
152 | #endif /* !MAIN_INCLUDED_RemoteUSBBackend_h */
|
---|
153 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|