1 | /* $Id: ConsoleVRDPServer.cpp 44528 2013-02-04 14:27:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Console VRDP Helper class
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2013 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include "ConsoleVRDPServer.h"
|
---|
19 | #include "ConsoleImpl.h"
|
---|
20 | #include "DisplayImpl.h"
|
---|
21 | #include "KeyboardImpl.h"
|
---|
22 | #include "MouseImpl.h"
|
---|
23 | #include "AudioSnifferInterface.h"
|
---|
24 | #ifdef VBOX_WITH_EXTPACK
|
---|
25 | # include "ExtPackManagerImpl.h"
|
---|
26 | #endif
|
---|
27 | #include "VMMDev.h"
|
---|
28 | #ifdef VBOX_WITH_USB_CARDREADER
|
---|
29 | # include "UsbCardReader.h"
|
---|
30 | #endif
|
---|
31 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
32 | # include "UsbWebcamInterface.h"
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include "Global.h"
|
---|
36 | #include "AutoCaller.h"
|
---|
37 | #include "Logging.h"
|
---|
38 |
|
---|
39 | #include <iprt/asm.h>
|
---|
40 | #include <iprt/alloca.h>
|
---|
41 | #include <iprt/ldr.h>
|
---|
42 | #include <iprt/param.h>
|
---|
43 | #include <iprt/path.h>
|
---|
44 | #include <iprt/cpp/utils.h>
|
---|
45 |
|
---|
46 | #include <VBox/err.h>
|
---|
47 | #include <VBox/RemoteDesktop/VRDEOrders.h>
|
---|
48 | #include <VBox/com/listeners.h>
|
---|
49 | #include <VBox/HostServices/VBoxCrOpenGLSvc.h>
|
---|
50 |
|
---|
51 | class VRDPConsoleListener
|
---|
52 | {
|
---|
53 | public:
|
---|
54 | VRDPConsoleListener()
|
---|
55 | {
|
---|
56 | }
|
---|
57 |
|
---|
58 | HRESULT init(ConsoleVRDPServer *server)
|
---|
59 | {
|
---|
60 | m_server = server;
|
---|
61 | return S_OK;
|
---|
62 | }
|
---|
63 |
|
---|
64 | void uninit()
|
---|
65 | {
|
---|
66 | }
|
---|
67 |
|
---|
68 | STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
|
---|
69 | {
|
---|
70 | switch (aType)
|
---|
71 | {
|
---|
72 | case VBoxEventType_OnMousePointerShapeChanged:
|
---|
73 | {
|
---|
74 | ComPtr<IMousePointerShapeChangedEvent> mpscev = aEvent;
|
---|
75 | Assert(mpscev);
|
---|
76 | BOOL visible, alpha;
|
---|
77 | ULONG xHot, yHot, width, height;
|
---|
78 | com::SafeArray <BYTE> shape;
|
---|
79 |
|
---|
80 | mpscev->COMGETTER(Visible)(&visible);
|
---|
81 | mpscev->COMGETTER(Alpha)(&alpha);
|
---|
82 | mpscev->COMGETTER(Xhot)(&xHot);
|
---|
83 | mpscev->COMGETTER(Yhot)(&yHot);
|
---|
84 | mpscev->COMGETTER(Width)(&width);
|
---|
85 | mpscev->COMGETTER(Height)(&height);
|
---|
86 | mpscev->COMGETTER(Shape)(ComSafeArrayAsOutParam(shape));
|
---|
87 |
|
---|
88 | OnMousePointerShapeChange(visible, alpha, xHot, yHot, width, height, ComSafeArrayAsInParam(shape));
|
---|
89 | break;
|
---|
90 | }
|
---|
91 | case VBoxEventType_OnMouseCapabilityChanged:
|
---|
92 | {
|
---|
93 | ComPtr<IMouseCapabilityChangedEvent> mccev = aEvent;
|
---|
94 | Assert(mccev);
|
---|
95 | if (m_server)
|
---|
96 | {
|
---|
97 | BOOL fAbsoluteMouse;
|
---|
98 | mccev->COMGETTER(SupportsAbsolute)(&fAbsoluteMouse);
|
---|
99 | m_server->NotifyAbsoluteMouse(!!fAbsoluteMouse);
|
---|
100 | }
|
---|
101 | break;
|
---|
102 | }
|
---|
103 | case VBoxEventType_OnKeyboardLedsChanged:
|
---|
104 | {
|
---|
105 | ComPtr<IKeyboardLedsChangedEvent> klcev = aEvent;
|
---|
106 | Assert(klcev);
|
---|
107 |
|
---|
108 | if (m_server)
|
---|
109 | {
|
---|
110 | BOOL fNumLock, fCapsLock, fScrollLock;
|
---|
111 | klcev->COMGETTER(NumLock)(&fNumLock);
|
---|
112 | klcev->COMGETTER(CapsLock)(&fCapsLock);
|
---|
113 | klcev->COMGETTER(ScrollLock)(&fScrollLock);
|
---|
114 | m_server->NotifyKeyboardLedsChange(fNumLock, fCapsLock, fScrollLock);
|
---|
115 | }
|
---|
116 | break;
|
---|
117 | }
|
---|
118 |
|
---|
119 | default:
|
---|
120 | AssertFailed();
|
---|
121 | }
|
---|
122 |
|
---|
123 | return S_OK;
|
---|
124 | }
|
---|
125 |
|
---|
126 | private:
|
---|
127 | STDMETHOD(OnMousePointerShapeChange)(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
|
---|
128 | ULONG width, ULONG height, ComSafeArrayIn(BYTE,shape));
|
---|
129 | ConsoleVRDPServer *m_server;
|
---|
130 | };
|
---|
131 |
|
---|
132 | typedef ListenerImpl<VRDPConsoleListener, ConsoleVRDPServer*> VRDPConsoleListenerImpl;
|
---|
133 |
|
---|
134 | VBOX_LISTENER_DECLARE(VRDPConsoleListenerImpl)
|
---|
135 |
|
---|
136 | #ifdef DEBUG_sunlover
|
---|
137 | #define LOGDUMPPTR Log
|
---|
138 | void dumpPointer(const uint8_t *pu8Shape, uint32_t width, uint32_t height, bool fXorMaskRGB32)
|
---|
139 | {
|
---|
140 | unsigned i;
|
---|
141 |
|
---|
142 | const uint8_t *pu8And = pu8Shape;
|
---|
143 |
|
---|
144 | for (i = 0; i < height; i++)
|
---|
145 | {
|
---|
146 | unsigned j;
|
---|
147 | LOGDUMPPTR(("%p: ", pu8And));
|
---|
148 | for (j = 0; j < (width + 7) / 8; j++)
|
---|
149 | {
|
---|
150 | unsigned k;
|
---|
151 | for (k = 0; k < 8; k++)
|
---|
152 | {
|
---|
153 | LOGDUMPPTR(("%d", ((*pu8And) & (1 << (7 - k)))? 1: 0));
|
---|
154 | }
|
---|
155 |
|
---|
156 | pu8And++;
|
---|
157 | }
|
---|
158 | LOGDUMPPTR(("\n"));
|
---|
159 | }
|
---|
160 |
|
---|
161 | if (fXorMaskRGB32)
|
---|
162 | {
|
---|
163 | uint32_t *pu32Xor = (uint32_t*)(pu8Shape + ((((width + 7) / 8) * height + 3) & ~3));
|
---|
164 |
|
---|
165 | for (i = 0; i < height; i++)
|
---|
166 | {
|
---|
167 | unsigned j;
|
---|
168 | LOGDUMPPTR(("%p: ", pu32Xor));
|
---|
169 | for (j = 0; j < width; j++)
|
---|
170 | {
|
---|
171 | LOGDUMPPTR(("%08X", *pu32Xor++));
|
---|
172 | }
|
---|
173 | LOGDUMPPTR(("\n"));
|
---|
174 | }
|
---|
175 | }
|
---|
176 | else
|
---|
177 | {
|
---|
178 | /* RDP 24 bit RGB mask. */
|
---|
179 | uint8_t *pu8Xor = (uint8_t*)(pu8Shape + ((((width + 7) / 8) * height + 3) & ~3));
|
---|
180 | for (i = 0; i < height; i++)
|
---|
181 | {
|
---|
182 | unsigned j;
|
---|
183 | LOGDUMPPTR(("%p: ", pu8Xor));
|
---|
184 | for (j = 0; j < width; j++)
|
---|
185 | {
|
---|
186 | LOGDUMPPTR(("%02X%02X%02X", pu8Xor[2], pu8Xor[1], pu8Xor[0]));
|
---|
187 | pu8Xor += 3;
|
---|
188 | }
|
---|
189 | LOGDUMPPTR(("\n"));
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 | #else
|
---|
194 | #define dumpPointer(a, b, c, d) do {} while (0)
|
---|
195 | #endif /* DEBUG_sunlover */
|
---|
196 |
|
---|
197 | static void findTopLeftBorder(const uint8_t *pu8AndMask, const uint8_t *pu8XorMask, uint32_t width, uint32_t height, uint32_t *pxSkip, uint32_t *pySkip)
|
---|
198 | {
|
---|
199 | /*
|
---|
200 | * Find the top border of the AND mask. First assign to special value.
|
---|
201 | */
|
---|
202 | uint32_t ySkipAnd = ~0;
|
---|
203 |
|
---|
204 | const uint8_t *pu8And = pu8AndMask;
|
---|
205 | const uint32_t cbAndRow = (width + 7) / 8;
|
---|
206 | const uint8_t maskLastByte = (uint8_t)( 0xFF << (cbAndRow * 8 - width) );
|
---|
207 |
|
---|
208 | Assert(cbAndRow > 0);
|
---|
209 |
|
---|
210 | unsigned y;
|
---|
211 | unsigned x;
|
---|
212 |
|
---|
213 | for (y = 0; y < height && ySkipAnd == ~(uint32_t)0; y++, pu8And += cbAndRow)
|
---|
214 | {
|
---|
215 | /* For each complete byte in the row. */
|
---|
216 | for (x = 0; x < cbAndRow - 1; x++)
|
---|
217 | {
|
---|
218 | if (pu8And[x] != 0xFF)
|
---|
219 | {
|
---|
220 | ySkipAnd = y;
|
---|
221 | break;
|
---|
222 | }
|
---|
223 | }
|
---|
224 |
|
---|
225 | if (ySkipAnd == ~(uint32_t)0)
|
---|
226 | {
|
---|
227 | /* Last byte. */
|
---|
228 | if ((pu8And[cbAndRow - 1] & maskLastByte) != maskLastByte)
|
---|
229 | {
|
---|
230 | ySkipAnd = y;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | if (ySkipAnd == ~(uint32_t)0)
|
---|
236 | {
|
---|
237 | ySkipAnd = 0;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /*
|
---|
241 | * Find the left border of the AND mask.
|
---|
242 | */
|
---|
243 | uint32_t xSkipAnd = ~0;
|
---|
244 |
|
---|
245 | /* For all bit columns. */
|
---|
246 | for (x = 0; x < width && xSkipAnd == ~(uint32_t)0; x++)
|
---|
247 | {
|
---|
248 | pu8And = pu8AndMask + x/8; /* Currently checking byte. */
|
---|
249 | uint8_t mask = 1 << (7 - x%8); /* Currently checking bit in the byte. */
|
---|
250 |
|
---|
251 | for (y = ySkipAnd; y < height; y++, pu8And += cbAndRow)
|
---|
252 | {
|
---|
253 | if ((*pu8And & mask) == 0)
|
---|
254 | {
|
---|
255 | xSkipAnd = x;
|
---|
256 | break;
|
---|
257 | }
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | if (xSkipAnd == ~(uint32_t)0)
|
---|
262 | {
|
---|
263 | xSkipAnd = 0;
|
---|
264 | }
|
---|
265 |
|
---|
266 | /*
|
---|
267 | * Find the XOR mask top border.
|
---|
268 | */
|
---|
269 | uint32_t ySkipXor = ~0;
|
---|
270 |
|
---|
271 | uint32_t *pu32XorStart = (uint32_t *)pu8XorMask;
|
---|
272 |
|
---|
273 | uint32_t *pu32Xor = pu32XorStart;
|
---|
274 |
|
---|
275 | for (y = 0; y < height && ySkipXor == ~(uint32_t)0; y++, pu32Xor += width)
|
---|
276 | {
|
---|
277 | for (x = 0; x < width; x++)
|
---|
278 | {
|
---|
279 | if (pu32Xor[x] != 0)
|
---|
280 | {
|
---|
281 | ySkipXor = y;
|
---|
282 | break;
|
---|
283 | }
|
---|
284 | }
|
---|
285 | }
|
---|
286 |
|
---|
287 | if (ySkipXor == ~(uint32_t)0)
|
---|
288 | {
|
---|
289 | ySkipXor = 0;
|
---|
290 | }
|
---|
291 |
|
---|
292 | /*
|
---|
293 | * Find the left border of the XOR mask.
|
---|
294 | */
|
---|
295 | uint32_t xSkipXor = ~(uint32_t)0;
|
---|
296 |
|
---|
297 | /* For all columns. */
|
---|
298 | for (x = 0; x < width && xSkipXor == ~(uint32_t)0; x++)
|
---|
299 | {
|
---|
300 | pu32Xor = pu32XorStart + x; /* Currently checking dword. */
|
---|
301 |
|
---|
302 | for (y = ySkipXor; y < height; y++, pu32Xor += width)
|
---|
303 | {
|
---|
304 | if (*pu32Xor != 0)
|
---|
305 | {
|
---|
306 | xSkipXor = x;
|
---|
307 | break;
|
---|
308 | }
|
---|
309 | }
|
---|
310 | }
|
---|
311 |
|
---|
312 | if (xSkipXor == ~(uint32_t)0)
|
---|
313 | {
|
---|
314 | xSkipXor = 0;
|
---|
315 | }
|
---|
316 |
|
---|
317 | *pxSkip = RT_MIN(xSkipAnd, xSkipXor);
|
---|
318 | *pySkip = RT_MIN(ySkipAnd, ySkipXor);
|
---|
319 | }
|
---|
320 |
|
---|
321 | /* Generate an AND mask for alpha pointers here, because
|
---|
322 | * guest driver does not do that correctly for Vista pointers.
|
---|
323 | * Similar fix, changing the alpha threshold, could be applied
|
---|
324 | * for the guest driver, but then additions reinstall would be
|
---|
325 | * necessary, which we try to avoid.
|
---|
326 | */
|
---|
327 | static void mousePointerGenerateANDMask(uint8_t *pu8DstAndMask, int cbDstAndMask, const uint8_t *pu8SrcAlpha, int w, int h)
|
---|
328 | {
|
---|
329 | memset(pu8DstAndMask, 0xFF, cbDstAndMask);
|
---|
330 |
|
---|
331 | int y;
|
---|
332 | for (y = 0; y < h; y++)
|
---|
333 | {
|
---|
334 | uint8_t bitmask = 0x80;
|
---|
335 |
|
---|
336 | int x;
|
---|
337 | for (x = 0; x < w; x++, bitmask >>= 1)
|
---|
338 | {
|
---|
339 | if (bitmask == 0)
|
---|
340 | {
|
---|
341 | bitmask = 0x80;
|
---|
342 | }
|
---|
343 |
|
---|
344 | /* Whether alpha channel value is not transparent enough for the pixel to be seen. */
|
---|
345 | if (pu8SrcAlpha[x * 4 + 3] > 0x7f)
|
---|
346 | {
|
---|
347 | pu8DstAndMask[x / 8] &= ~bitmask;
|
---|
348 | }
|
---|
349 | }
|
---|
350 |
|
---|
351 | /* Point to next source and dest scans. */
|
---|
352 | pu8SrcAlpha += w * 4;
|
---|
353 | pu8DstAndMask += (w + 7) / 8;
|
---|
354 | }
|
---|
355 | }
|
---|
356 |
|
---|
357 | STDMETHODIMP VRDPConsoleListener::OnMousePointerShapeChange(BOOL visible,
|
---|
358 | BOOL alpha,
|
---|
359 | ULONG xHot,
|
---|
360 | ULONG yHot,
|
---|
361 | ULONG width,
|
---|
362 | ULONG height,
|
---|
363 | ComSafeArrayIn(BYTE,inShape))
|
---|
364 | {
|
---|
365 | LogSunlover(("VRDPConsoleListener::OnMousePointerShapeChange: %d, %d, %lux%lu, @%lu,%lu\n", visible, alpha, width, height, xHot, yHot));
|
---|
366 |
|
---|
367 | if (m_server)
|
---|
368 | {
|
---|
369 | com::SafeArray <BYTE> aShape(ComSafeArrayInArg(inShape));
|
---|
370 | if (aShape.size() == 0)
|
---|
371 | {
|
---|
372 | if (!visible)
|
---|
373 | {
|
---|
374 | m_server->MousePointerHide();
|
---|
375 | }
|
---|
376 | }
|
---|
377 | else if (width != 0 && height != 0)
|
---|
378 | {
|
---|
379 | uint8_t* shape = aShape.raw();
|
---|
380 |
|
---|
381 | dumpPointer(shape, width, height, true);
|
---|
382 |
|
---|
383 | if (m_server->MousePointer(alpha, xHot, yHot, width, height, shape) == VINF_SUCCESS)
|
---|
384 | {
|
---|
385 | return S_OK;
|
---|
386 | }
|
---|
387 |
|
---|
388 | /* Pointer consists of 1 bpp AND and 24 BPP XOR masks.
|
---|
389 | * 'shape' AND mask followed by XOR mask.
|
---|
390 | * XOR mask contains 32 bit (lsb)BGR0(msb) values.
|
---|
391 | *
|
---|
392 | * We convert this to RDP color format which consist of
|
---|
393 | * one bpp AND mask and 24 BPP (BGR) color XOR image.
|
---|
394 | *
|
---|
395 | * RDP clients expect 8 aligned width and height of
|
---|
396 | * pointer (preferably 32x32).
|
---|
397 | *
|
---|
398 | * They even contain bugs which do not appear for
|
---|
399 | * 32x32 pointers but would appear for a 41x32 one.
|
---|
400 | *
|
---|
401 | * So set pointer size to 32x32. This can be done safely
|
---|
402 | * because most pointers are 32x32.
|
---|
403 | */
|
---|
404 |
|
---|
405 | int cbDstAndMask = (((width + 7) / 8) * height + 3) & ~3;
|
---|
406 |
|
---|
407 | uint8_t *pu8AndMask = shape;
|
---|
408 | uint8_t *pu8XorMask = shape + cbDstAndMask;
|
---|
409 |
|
---|
410 | if (alpha)
|
---|
411 | {
|
---|
412 | pu8AndMask = (uint8_t*)alloca(cbDstAndMask);
|
---|
413 |
|
---|
414 | mousePointerGenerateANDMask(pu8AndMask, cbDstAndMask, pu8XorMask, width, height);
|
---|
415 | }
|
---|
416 |
|
---|
417 | /* Windows guest alpha pointers are wider than 32 pixels.
|
---|
418 | * Try to find out the top-left border of the pointer and
|
---|
419 | * then copy only meaningful bits. All complete top rows
|
---|
420 | * and all complete left columns where (AND == 1 && XOR == 0)
|
---|
421 | * are skipped. Hot spot is adjusted.
|
---|
422 | */
|
---|
423 | uint32_t ySkip = 0; /* How many rows to skip at the top. */
|
---|
424 | uint32_t xSkip = 0; /* How many columns to skip at the left. */
|
---|
425 |
|
---|
426 | findTopLeftBorder(pu8AndMask, pu8XorMask, width, height, &xSkip, &ySkip);
|
---|
427 |
|
---|
428 | /* Must not skip the hot spot. */
|
---|
429 | xSkip = RT_MIN(xSkip, xHot);
|
---|
430 | ySkip = RT_MIN(ySkip, yHot);
|
---|
431 |
|
---|
432 | /*
|
---|
433 | * Compute size and allocate memory for the pointer.
|
---|
434 | */
|
---|
435 | const uint32_t dstwidth = 32;
|
---|
436 | const uint32_t dstheight = 32;
|
---|
437 |
|
---|
438 | VRDECOLORPOINTER *pointer = NULL;
|
---|
439 |
|
---|
440 | uint32_t dstmaskwidth = (dstwidth + 7) / 8;
|
---|
441 |
|
---|
442 | uint32_t rdpmaskwidth = dstmaskwidth;
|
---|
443 | uint32_t rdpmasklen = dstheight * rdpmaskwidth;
|
---|
444 |
|
---|
445 | uint32_t rdpdatawidth = dstwidth * 3;
|
---|
446 | uint32_t rdpdatalen = dstheight * rdpdatawidth;
|
---|
447 |
|
---|
448 | pointer = (VRDECOLORPOINTER *)RTMemTmpAlloc(sizeof(VRDECOLORPOINTER) + rdpmasklen + rdpdatalen);
|
---|
449 |
|
---|
450 | if (pointer)
|
---|
451 | {
|
---|
452 | uint8_t *maskarray = (uint8_t*)pointer + sizeof(VRDECOLORPOINTER);
|
---|
453 | uint8_t *dataarray = maskarray + rdpmasklen;
|
---|
454 |
|
---|
455 | memset(maskarray, 0xFF, rdpmasklen);
|
---|
456 | memset(dataarray, 0x00, rdpdatalen);
|
---|
457 |
|
---|
458 | uint32_t srcmaskwidth = (width + 7) / 8;
|
---|
459 | uint32_t srcdatawidth = width * 4;
|
---|
460 |
|
---|
461 | /* Copy AND mask. */
|
---|
462 | uint8_t *src = pu8AndMask + ySkip * srcmaskwidth;
|
---|
463 | uint8_t *dst = maskarray + (dstheight - 1) * rdpmaskwidth;
|
---|
464 |
|
---|
465 | uint32_t minheight = RT_MIN(height - ySkip, dstheight);
|
---|
466 | uint32_t minwidth = RT_MIN(width - xSkip, dstwidth);
|
---|
467 |
|
---|
468 | unsigned x, y;
|
---|
469 |
|
---|
470 | for (y = 0; y < minheight; y++)
|
---|
471 | {
|
---|
472 | for (x = 0; x < minwidth; x++)
|
---|
473 | {
|
---|
474 | uint32_t byteIndex = (x + xSkip) / 8;
|
---|
475 | uint32_t bitIndex = (x + xSkip) % 8;
|
---|
476 |
|
---|
477 | bool bit = (src[byteIndex] & (1 << (7 - bitIndex))) != 0;
|
---|
478 |
|
---|
479 | if (!bit)
|
---|
480 | {
|
---|
481 | byteIndex = x / 8;
|
---|
482 | bitIndex = x % 8;
|
---|
483 |
|
---|
484 | dst[byteIndex] &= ~(1 << (7 - bitIndex));
|
---|
485 | }
|
---|
486 | }
|
---|
487 |
|
---|
488 | src += srcmaskwidth;
|
---|
489 | dst -= rdpmaskwidth;
|
---|
490 | }
|
---|
491 |
|
---|
492 | /* Point src to XOR mask */
|
---|
493 | src = pu8XorMask + ySkip * srcdatawidth;
|
---|
494 | dst = dataarray + (dstheight - 1) * rdpdatawidth;
|
---|
495 |
|
---|
496 | for (y = 0; y < minheight ; y++)
|
---|
497 | {
|
---|
498 | for (x = 0; x < minwidth; x++)
|
---|
499 | {
|
---|
500 | memcpy(dst + x * 3, &src[4 * (x + xSkip)], 3);
|
---|
501 | }
|
---|
502 |
|
---|
503 | src += srcdatawidth;
|
---|
504 | dst -= rdpdatawidth;
|
---|
505 | }
|
---|
506 |
|
---|
507 | pointer->u16HotX = (uint16_t)(xHot - xSkip);
|
---|
508 | pointer->u16HotY = (uint16_t)(yHot - ySkip);
|
---|
509 |
|
---|
510 | pointer->u16Width = (uint16_t)dstwidth;
|
---|
511 | pointer->u16Height = (uint16_t)dstheight;
|
---|
512 |
|
---|
513 | pointer->u16MaskLen = (uint16_t)rdpmasklen;
|
---|
514 | pointer->u16DataLen = (uint16_t)rdpdatalen;
|
---|
515 |
|
---|
516 | dumpPointer((uint8_t*)pointer + sizeof(*pointer), dstwidth, dstheight, false);
|
---|
517 |
|
---|
518 | m_server->MousePointerUpdate(pointer);
|
---|
519 |
|
---|
520 | RTMemTmpFree(pointer);
|
---|
521 | }
|
---|
522 | }
|
---|
523 | }
|
---|
524 |
|
---|
525 | return S_OK;
|
---|
526 | }
|
---|
527 |
|
---|
528 |
|
---|
529 | // ConsoleVRDPServer
|
---|
530 | ////////////////////////////////////////////////////////////////////////////////
|
---|
531 |
|
---|
532 | RTLDRMOD ConsoleVRDPServer::mVRDPLibrary = NIL_RTLDRMOD;
|
---|
533 |
|
---|
534 | PFNVRDECREATESERVER ConsoleVRDPServer::mpfnVRDECreateServer = NULL;
|
---|
535 |
|
---|
536 | VRDEENTRYPOINTS_4 ConsoleVRDPServer::mEntryPoints; /* A copy of the server entry points. */
|
---|
537 | VRDEENTRYPOINTS_4 *ConsoleVRDPServer::mpEntryPoints = NULL;
|
---|
538 |
|
---|
539 | VRDECALLBACKS_4 ConsoleVRDPServer::mCallbacks =
|
---|
540 | {
|
---|
541 | { VRDE_INTERFACE_VERSION_4, sizeof(VRDECALLBACKS_4) },
|
---|
542 | ConsoleVRDPServer::VRDPCallbackQueryProperty,
|
---|
543 | ConsoleVRDPServer::VRDPCallbackClientLogon,
|
---|
544 | ConsoleVRDPServer::VRDPCallbackClientConnect,
|
---|
545 | ConsoleVRDPServer::VRDPCallbackClientDisconnect,
|
---|
546 | ConsoleVRDPServer::VRDPCallbackIntercept,
|
---|
547 | ConsoleVRDPServer::VRDPCallbackUSB,
|
---|
548 | ConsoleVRDPServer::VRDPCallbackClipboard,
|
---|
549 | ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
|
---|
550 | ConsoleVRDPServer::VRDPCallbackFramebufferLock,
|
---|
551 | ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
|
---|
552 | ConsoleVRDPServer::VRDPCallbackInput,
|
---|
553 | ConsoleVRDPServer::VRDPCallbackVideoModeHint,
|
---|
554 | ConsoleVRDPServer::VRDECallbackAudioIn
|
---|
555 | };
|
---|
556 |
|
---|
557 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackQueryProperty(void *pvCallback, uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut)
|
---|
558 | {
|
---|
559 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
560 |
|
---|
561 | int rc = VERR_NOT_SUPPORTED;
|
---|
562 |
|
---|
563 | switch (index)
|
---|
564 | {
|
---|
565 | case VRDE_QP_NETWORK_PORT:
|
---|
566 | {
|
---|
567 | /* This is obsolete, the VRDE server uses VRDE_QP_NETWORK_PORT_RANGE instead. */
|
---|
568 | ULONG port = 0;
|
---|
569 |
|
---|
570 | if (cbBuffer >= sizeof(uint32_t))
|
---|
571 | {
|
---|
572 | *(uint32_t *)pvBuffer = (uint32_t)port;
|
---|
573 | rc = VINF_SUCCESS;
|
---|
574 | }
|
---|
575 | else
|
---|
576 | {
|
---|
577 | rc = VINF_BUFFER_OVERFLOW;
|
---|
578 | }
|
---|
579 |
|
---|
580 | *pcbOut = sizeof(uint32_t);
|
---|
581 | } break;
|
---|
582 |
|
---|
583 | case VRDE_QP_NETWORK_ADDRESS:
|
---|
584 | {
|
---|
585 | com::Bstr bstr;
|
---|
586 | server->mConsole->getVRDEServer()->GetVRDEProperty(Bstr("TCP/Address").raw(), bstr.asOutParam());
|
---|
587 |
|
---|
588 | /* The server expects UTF8. */
|
---|
589 | com::Utf8Str address = bstr;
|
---|
590 |
|
---|
591 | size_t cbAddress = address.length() + 1;
|
---|
592 |
|
---|
593 | if (cbAddress >= 0x10000)
|
---|
594 | {
|
---|
595 | /* More than 64K seems to be an invalid address. */
|
---|
596 | rc = VERR_TOO_MUCH_DATA;
|
---|
597 | break;
|
---|
598 | }
|
---|
599 |
|
---|
600 | if ((size_t)cbBuffer >= cbAddress)
|
---|
601 | {
|
---|
602 | memcpy(pvBuffer, address.c_str(), cbAddress);
|
---|
603 | rc = VINF_SUCCESS;
|
---|
604 | }
|
---|
605 | else
|
---|
606 | {
|
---|
607 | rc = VINF_BUFFER_OVERFLOW;
|
---|
608 | }
|
---|
609 |
|
---|
610 | *pcbOut = (uint32_t)cbAddress;
|
---|
611 | } break;
|
---|
612 |
|
---|
613 | case VRDE_QP_NUMBER_MONITORS:
|
---|
614 | {
|
---|
615 | ULONG cMonitors = 1;
|
---|
616 |
|
---|
617 | server->mConsole->machine()->COMGETTER(MonitorCount)(&cMonitors);
|
---|
618 |
|
---|
619 | if (cbBuffer >= sizeof(uint32_t))
|
---|
620 | {
|
---|
621 | *(uint32_t *)pvBuffer = (uint32_t)cMonitors;
|
---|
622 | rc = VINF_SUCCESS;
|
---|
623 | }
|
---|
624 | else
|
---|
625 | {
|
---|
626 | rc = VINF_BUFFER_OVERFLOW;
|
---|
627 | }
|
---|
628 |
|
---|
629 | *pcbOut = sizeof(uint32_t);
|
---|
630 | } break;
|
---|
631 |
|
---|
632 | case VRDE_QP_NETWORK_PORT_RANGE:
|
---|
633 | {
|
---|
634 | com::Bstr bstr;
|
---|
635 | HRESULT hrc = server->mConsole->getVRDEServer()->GetVRDEProperty(Bstr("TCP/Ports").raw(), bstr.asOutParam());
|
---|
636 |
|
---|
637 | if (hrc != S_OK)
|
---|
638 | {
|
---|
639 | bstr = "";
|
---|
640 | }
|
---|
641 |
|
---|
642 | if (bstr == "0")
|
---|
643 | {
|
---|
644 | bstr = "3389";
|
---|
645 | }
|
---|
646 |
|
---|
647 | /* The server expects UTF8. */
|
---|
648 | com::Utf8Str portRange = bstr;
|
---|
649 |
|
---|
650 | size_t cbPortRange = portRange.length() + 1;
|
---|
651 |
|
---|
652 | if (cbPortRange >= 0x10000)
|
---|
653 | {
|
---|
654 | /* More than 64K seems to be an invalid port range string. */
|
---|
655 | rc = VERR_TOO_MUCH_DATA;
|
---|
656 | break;
|
---|
657 | }
|
---|
658 |
|
---|
659 | if ((size_t)cbBuffer >= cbPortRange)
|
---|
660 | {
|
---|
661 | memcpy(pvBuffer, portRange.c_str(), cbPortRange);
|
---|
662 | rc = VINF_SUCCESS;
|
---|
663 | }
|
---|
664 | else
|
---|
665 | {
|
---|
666 | rc = VINF_BUFFER_OVERFLOW;
|
---|
667 | }
|
---|
668 |
|
---|
669 | *pcbOut = (uint32_t)cbPortRange;
|
---|
670 | } break;
|
---|
671 |
|
---|
672 | case VRDE_QP_VIDEO_CHANNEL:
|
---|
673 | {
|
---|
674 | com::Bstr bstr;
|
---|
675 | HRESULT hrc = server->mConsole->getVRDEServer()->GetVRDEProperty(Bstr("VideoChannel/Enabled").raw(), bstr.asOutParam());
|
---|
676 |
|
---|
677 | if (hrc != S_OK)
|
---|
678 | {
|
---|
679 | bstr = "";
|
---|
680 | }
|
---|
681 |
|
---|
682 | com::Utf8Str value = bstr;
|
---|
683 |
|
---|
684 | BOOL fVideoEnabled = RTStrICmp(value.c_str(), "true") == 0
|
---|
685 | || RTStrICmp(value.c_str(), "1") == 0;
|
---|
686 |
|
---|
687 | if (cbBuffer >= sizeof(uint32_t))
|
---|
688 | {
|
---|
689 | *(uint32_t *)pvBuffer = (uint32_t)fVideoEnabled;
|
---|
690 | rc = VINF_SUCCESS;
|
---|
691 | }
|
---|
692 | else
|
---|
693 | {
|
---|
694 | rc = VINF_BUFFER_OVERFLOW;
|
---|
695 | }
|
---|
696 |
|
---|
697 | *pcbOut = sizeof(uint32_t);
|
---|
698 | } break;
|
---|
699 |
|
---|
700 | case VRDE_QP_VIDEO_CHANNEL_QUALITY:
|
---|
701 | {
|
---|
702 | com::Bstr bstr;
|
---|
703 | HRESULT hrc = server->mConsole->getVRDEServer()->GetVRDEProperty(Bstr("VideoChannel/Quality").raw(), bstr.asOutParam());
|
---|
704 |
|
---|
705 | if (hrc != S_OK)
|
---|
706 | {
|
---|
707 | bstr = "";
|
---|
708 | }
|
---|
709 |
|
---|
710 | com::Utf8Str value = bstr;
|
---|
711 |
|
---|
712 | ULONG ulQuality = RTStrToUInt32(value.c_str()); /* This returns 0 on invalid string which is ok. */
|
---|
713 |
|
---|
714 | if (cbBuffer >= sizeof(uint32_t))
|
---|
715 | {
|
---|
716 | *(uint32_t *)pvBuffer = (uint32_t)ulQuality;
|
---|
717 | rc = VINF_SUCCESS;
|
---|
718 | }
|
---|
719 | else
|
---|
720 | {
|
---|
721 | rc = VINF_BUFFER_OVERFLOW;
|
---|
722 | }
|
---|
723 |
|
---|
724 | *pcbOut = sizeof(uint32_t);
|
---|
725 | } break;
|
---|
726 |
|
---|
727 | case VRDE_QP_VIDEO_CHANNEL_SUNFLSH:
|
---|
728 | {
|
---|
729 | ULONG ulSunFlsh = 1;
|
---|
730 |
|
---|
731 | com::Bstr bstr;
|
---|
732 | HRESULT hrc = server->mConsole->machine()->GetExtraData(Bstr("VRDP/SunFlsh").raw(),
|
---|
733 | bstr.asOutParam());
|
---|
734 | if (hrc == S_OK && !bstr.isEmpty())
|
---|
735 | {
|
---|
736 | com::Utf8Str sunFlsh = bstr;
|
---|
737 | if (!sunFlsh.isEmpty())
|
---|
738 | {
|
---|
739 | ulSunFlsh = sunFlsh.toUInt32();
|
---|
740 | }
|
---|
741 | }
|
---|
742 |
|
---|
743 | if (cbBuffer >= sizeof(uint32_t))
|
---|
744 | {
|
---|
745 | *(uint32_t *)pvBuffer = (uint32_t)ulSunFlsh;
|
---|
746 | rc = VINF_SUCCESS;
|
---|
747 | }
|
---|
748 | else
|
---|
749 | {
|
---|
750 | rc = VINF_BUFFER_OVERFLOW;
|
---|
751 | }
|
---|
752 |
|
---|
753 | *pcbOut = sizeof(uint32_t);
|
---|
754 | } break;
|
---|
755 |
|
---|
756 | case VRDE_QP_FEATURE:
|
---|
757 | {
|
---|
758 | if (cbBuffer < sizeof(VRDEFEATURE))
|
---|
759 | {
|
---|
760 | rc = VERR_INVALID_PARAMETER;
|
---|
761 | break;
|
---|
762 | }
|
---|
763 |
|
---|
764 | size_t cbInfo = cbBuffer - RT_OFFSETOF(VRDEFEATURE, achInfo);
|
---|
765 |
|
---|
766 | VRDEFEATURE *pFeature = (VRDEFEATURE *)pvBuffer;
|
---|
767 |
|
---|
768 | size_t cchInfo = 0;
|
---|
769 | rc = RTStrNLenEx(pFeature->achInfo, cbInfo, &cchInfo);
|
---|
770 |
|
---|
771 | if (RT_FAILURE(rc))
|
---|
772 | {
|
---|
773 | rc = VERR_INVALID_PARAMETER;
|
---|
774 | break;
|
---|
775 | }
|
---|
776 |
|
---|
777 | Log(("VRDE_QP_FEATURE [%s]\n", pFeature->achInfo));
|
---|
778 |
|
---|
779 | com::Bstr bstrValue;
|
---|
780 |
|
---|
781 | if ( RTStrICmp(pFeature->achInfo, "Client/DisableDisplay") == 0
|
---|
782 | || RTStrICmp(pFeature->achInfo, "Client/DisableInput") == 0
|
---|
783 | || RTStrICmp(pFeature->achInfo, "Client/DisableAudio") == 0
|
---|
784 | || RTStrICmp(pFeature->achInfo, "Client/DisableUSB") == 0
|
---|
785 | || RTStrICmp(pFeature->achInfo, "Client/DisableClipboard") == 0
|
---|
786 | )
|
---|
787 | {
|
---|
788 | /* @todo these features should be per client. */
|
---|
789 | NOREF(pFeature->u32ClientId);
|
---|
790 |
|
---|
791 | /* These features are mapped to "VRDE/Feature/NAME" extra data. */
|
---|
792 | com::Utf8Str extraData("VRDE/Feature/");
|
---|
793 | extraData += pFeature->achInfo;
|
---|
794 |
|
---|
795 | HRESULT hrc = server->mConsole->machine()->GetExtraData(com::Bstr(extraData).raw(),
|
---|
796 | bstrValue.asOutParam());
|
---|
797 | if (FAILED(hrc) || bstrValue.isEmpty())
|
---|
798 | {
|
---|
799 | /* Also try the old "VRDP/Feature/NAME" */
|
---|
800 | extraData = "VRDP/Feature/";
|
---|
801 | extraData += pFeature->achInfo;
|
---|
802 |
|
---|
803 | hrc = server->mConsole->machine()->GetExtraData(com::Bstr(extraData).raw(),
|
---|
804 | bstrValue.asOutParam());
|
---|
805 | if (FAILED(hrc))
|
---|
806 | {
|
---|
807 | rc = VERR_NOT_SUPPORTED;
|
---|
808 | }
|
---|
809 | }
|
---|
810 | }
|
---|
811 | else if (RTStrNCmp(pFeature->achInfo, "Property/", 9) == 0)
|
---|
812 | {
|
---|
813 | /* Generic properties. */
|
---|
814 | const char *pszPropertyName = &pFeature->achInfo[9];
|
---|
815 | HRESULT hrc = server->mConsole->getVRDEServer()->GetVRDEProperty(Bstr(pszPropertyName).raw(), bstrValue.asOutParam());
|
---|
816 | if (FAILED(hrc))
|
---|
817 | {
|
---|
818 | rc = VERR_NOT_SUPPORTED;
|
---|
819 | }
|
---|
820 | }
|
---|
821 | else
|
---|
822 | {
|
---|
823 | rc = VERR_NOT_SUPPORTED;
|
---|
824 | }
|
---|
825 |
|
---|
826 | /* Copy the value string to the callers buffer. */
|
---|
827 | if (rc == VINF_SUCCESS)
|
---|
828 | {
|
---|
829 | com::Utf8Str value = bstrValue;
|
---|
830 |
|
---|
831 | size_t cb = value.length() + 1;
|
---|
832 |
|
---|
833 | if ((size_t)cbInfo >= cb)
|
---|
834 | {
|
---|
835 | memcpy(pFeature->achInfo, value.c_str(), cb);
|
---|
836 | }
|
---|
837 | else
|
---|
838 | {
|
---|
839 | rc = VINF_BUFFER_OVERFLOW;
|
---|
840 | }
|
---|
841 |
|
---|
842 | *pcbOut = (uint32_t)cb;
|
---|
843 | }
|
---|
844 | } break;
|
---|
845 |
|
---|
846 | case VRDE_SP_NETWORK_BIND_PORT:
|
---|
847 | {
|
---|
848 | if (cbBuffer != sizeof(uint32_t))
|
---|
849 | {
|
---|
850 | rc = VERR_INVALID_PARAMETER;
|
---|
851 | break;
|
---|
852 | }
|
---|
853 |
|
---|
854 | ULONG port = *(uint32_t *)pvBuffer;
|
---|
855 |
|
---|
856 | server->mVRDPBindPort = port;
|
---|
857 |
|
---|
858 | rc = VINF_SUCCESS;
|
---|
859 |
|
---|
860 | if (pcbOut)
|
---|
861 | {
|
---|
862 | *pcbOut = sizeof(uint32_t);
|
---|
863 | }
|
---|
864 |
|
---|
865 | server->mConsole->onVRDEServerInfoChange();
|
---|
866 | } break;
|
---|
867 |
|
---|
868 | case VRDE_SP_CLIENT_STATUS:
|
---|
869 | {
|
---|
870 | if (cbBuffer < sizeof(VRDECLIENTSTATUS))
|
---|
871 | {
|
---|
872 | rc = VERR_INVALID_PARAMETER;
|
---|
873 | break;
|
---|
874 | }
|
---|
875 |
|
---|
876 | size_t cbStatus = cbBuffer - RT_UOFFSETOF(VRDECLIENTSTATUS, achStatus);
|
---|
877 |
|
---|
878 | VRDECLIENTSTATUS *pStatus = (VRDECLIENTSTATUS *)pvBuffer;
|
---|
879 |
|
---|
880 | if (cbBuffer < RT_UOFFSETOF(VRDECLIENTSTATUS, achStatus) + pStatus->cbStatus)
|
---|
881 | {
|
---|
882 | rc = VERR_INVALID_PARAMETER;
|
---|
883 | break;
|
---|
884 | }
|
---|
885 |
|
---|
886 | size_t cchStatus = 0;
|
---|
887 | rc = RTStrNLenEx(pStatus->achStatus, cbStatus, &cchStatus);
|
---|
888 |
|
---|
889 | if (RT_FAILURE(rc))
|
---|
890 | {
|
---|
891 | rc = VERR_INVALID_PARAMETER;
|
---|
892 | break;
|
---|
893 | }
|
---|
894 |
|
---|
895 | Log(("VRDE_SP_CLIENT_STATUS [%s]\n", pStatus->achStatus));
|
---|
896 |
|
---|
897 | server->mConsole->VRDPClientStatusChange(pStatus->u32ClientId, pStatus->achStatus);
|
---|
898 |
|
---|
899 | rc = VINF_SUCCESS;
|
---|
900 |
|
---|
901 | if (pcbOut)
|
---|
902 | {
|
---|
903 | *pcbOut = cbBuffer;
|
---|
904 | }
|
---|
905 |
|
---|
906 | server->mConsole->onVRDEServerInfoChange();
|
---|
907 | } break;
|
---|
908 |
|
---|
909 | default:
|
---|
910 | break;
|
---|
911 | }
|
---|
912 |
|
---|
913 | return rc;
|
---|
914 | }
|
---|
915 |
|
---|
916 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClientLogon(void *pvCallback, uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain)
|
---|
917 | {
|
---|
918 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
919 |
|
---|
920 | return server->mConsole->VRDPClientLogon(u32ClientId, pszUser, pszPassword, pszDomain);
|
---|
921 | }
|
---|
922 |
|
---|
923 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackClientConnect(void *pvCallback, uint32_t u32ClientId)
|
---|
924 | {
|
---|
925 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
926 |
|
---|
927 | server->mConsole->VRDPClientConnect(u32ClientId);
|
---|
928 | }
|
---|
929 |
|
---|
930 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackClientDisconnect(void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercepted)
|
---|
931 | {
|
---|
932 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
933 |
|
---|
934 | server->mConsole->VRDPClientDisconnect(u32ClientId, fu32Intercepted);
|
---|
935 |
|
---|
936 | if (ASMAtomicReadU32(&server->mu32AudioInputClientId) == u32ClientId)
|
---|
937 | {
|
---|
938 | Log(("AUDIOIN: disconnected client %u\n", u32ClientId));
|
---|
939 | ASMAtomicWriteU32(&server->mu32AudioInputClientId, 0);
|
---|
940 |
|
---|
941 | PPDMIAUDIOSNIFFERPORT pPort = server->mConsole->getAudioSniffer()->getAudioSnifferPort();
|
---|
942 | if (pPort)
|
---|
943 | {
|
---|
944 | pPort->pfnAudioInputIntercept(pPort, false);
|
---|
945 | }
|
---|
946 | else
|
---|
947 | {
|
---|
948 | AssertFailed();
|
---|
949 | }
|
---|
950 | }
|
---|
951 | }
|
---|
952 |
|
---|
953 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackIntercept(void *pvCallback, uint32_t u32ClientId, uint32_t fu32Intercept, void **ppvIntercept)
|
---|
954 | {
|
---|
955 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
956 |
|
---|
957 | LogFlowFunc(("%x\n", fu32Intercept));
|
---|
958 |
|
---|
959 | int rc = VERR_NOT_SUPPORTED;
|
---|
960 |
|
---|
961 | switch (fu32Intercept)
|
---|
962 | {
|
---|
963 | case VRDE_CLIENT_INTERCEPT_AUDIO:
|
---|
964 | {
|
---|
965 | server->mConsole->VRDPInterceptAudio(u32ClientId);
|
---|
966 | if (ppvIntercept)
|
---|
967 | {
|
---|
968 | *ppvIntercept = server;
|
---|
969 | }
|
---|
970 | rc = VINF_SUCCESS;
|
---|
971 | } break;
|
---|
972 |
|
---|
973 | case VRDE_CLIENT_INTERCEPT_USB:
|
---|
974 | {
|
---|
975 | server->mConsole->VRDPInterceptUSB(u32ClientId, ppvIntercept);
|
---|
976 | rc = VINF_SUCCESS;
|
---|
977 | } break;
|
---|
978 |
|
---|
979 | case VRDE_CLIENT_INTERCEPT_CLIPBOARD:
|
---|
980 | {
|
---|
981 | server->mConsole->VRDPInterceptClipboard(u32ClientId);
|
---|
982 | if (ppvIntercept)
|
---|
983 | {
|
---|
984 | *ppvIntercept = server;
|
---|
985 | }
|
---|
986 | rc = VINF_SUCCESS;
|
---|
987 | } break;
|
---|
988 |
|
---|
989 | case VRDE_CLIENT_INTERCEPT_AUDIO_INPUT:
|
---|
990 | {
|
---|
991 | /* This request is processed internally by the ConsoleVRDPServer.
|
---|
992 | * Only one client is allowed to intercept audio input.
|
---|
993 | */
|
---|
994 | if (ASMAtomicCmpXchgU32(&server->mu32AudioInputClientId, u32ClientId, 0) == true)
|
---|
995 | {
|
---|
996 | Log(("AUDIOIN: connected client %u\n", u32ClientId));
|
---|
997 |
|
---|
998 | PPDMIAUDIOSNIFFERPORT pPort = server->mConsole->getAudioSniffer()->getAudioSnifferPort();
|
---|
999 | if (pPort)
|
---|
1000 | {
|
---|
1001 | pPort->pfnAudioInputIntercept(pPort, true);
|
---|
1002 | if (ppvIntercept)
|
---|
1003 | {
|
---|
1004 | *ppvIntercept = server;
|
---|
1005 | }
|
---|
1006 | }
|
---|
1007 | else
|
---|
1008 | {
|
---|
1009 | AssertFailed();
|
---|
1010 | ASMAtomicWriteU32(&server->mu32AudioInputClientId, 0);
|
---|
1011 | rc = VERR_NOT_SUPPORTED;
|
---|
1012 | }
|
---|
1013 | }
|
---|
1014 | else
|
---|
1015 | {
|
---|
1016 | Log(("AUDIOIN: ignored client %u, active client %u\n", u32ClientId, server->mu32AudioInputClientId));
|
---|
1017 | rc = VERR_NOT_SUPPORTED;
|
---|
1018 | }
|
---|
1019 | } break;
|
---|
1020 |
|
---|
1021 | default:
|
---|
1022 | break;
|
---|
1023 | }
|
---|
1024 |
|
---|
1025 | return rc;
|
---|
1026 | }
|
---|
1027 |
|
---|
1028 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackUSB(void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint8_t u8Code, const void *pvRet, uint32_t cbRet)
|
---|
1029 | {
|
---|
1030 | #ifdef VBOX_WITH_USB
|
---|
1031 | return USBClientResponseCallback(pvIntercept, u32ClientId, u8Code, pvRet, cbRet);
|
---|
1032 | #else
|
---|
1033 | return VERR_NOT_SUPPORTED;
|
---|
1034 | #endif
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | DECLCALLBACK(int) ConsoleVRDPServer::VRDPCallbackClipboard(void *pvCallback, void *pvIntercept, uint32_t u32ClientId, uint32_t u32Function, uint32_t u32Format, const void *pvData, uint32_t cbData)
|
---|
1038 | {
|
---|
1039 | return ClipboardCallback(pvIntercept, u32ClientId, u32Function, u32Format, pvData, cbData);
|
---|
1040 | }
|
---|
1041 |
|
---|
1042 | DECLCALLBACK(bool) ConsoleVRDPServer::VRDPCallbackFramebufferQuery(void *pvCallback, unsigned uScreenId, VRDEFRAMEBUFFERINFO *pInfo)
|
---|
1043 | {
|
---|
1044 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
1045 |
|
---|
1046 | bool fAvailable = false;
|
---|
1047 |
|
---|
1048 | IFramebuffer *pfb = NULL;
|
---|
1049 | LONG xOrigin = 0;
|
---|
1050 | LONG yOrigin = 0;
|
---|
1051 |
|
---|
1052 | server->mConsole->getDisplay()->GetFramebuffer(uScreenId, &pfb, &xOrigin, &yOrigin);
|
---|
1053 |
|
---|
1054 | if (pfb)
|
---|
1055 | {
|
---|
1056 | pfb->Lock ();
|
---|
1057 |
|
---|
1058 | /* Query framebuffer parameters. */
|
---|
1059 | ULONG lineSize = 0;
|
---|
1060 | pfb->COMGETTER(BytesPerLine)(&lineSize);
|
---|
1061 |
|
---|
1062 | ULONG bitsPerPixel = 0;
|
---|
1063 | pfb->COMGETTER(BitsPerPixel)(&bitsPerPixel);
|
---|
1064 |
|
---|
1065 | BYTE *address = NULL;
|
---|
1066 | pfb->COMGETTER(Address)(&address);
|
---|
1067 |
|
---|
1068 | ULONG height = 0;
|
---|
1069 | pfb->COMGETTER(Height)(&height);
|
---|
1070 |
|
---|
1071 | ULONG width = 0;
|
---|
1072 | pfb->COMGETTER(Width)(&width);
|
---|
1073 |
|
---|
1074 | /* Now fill the information as requested by the caller. */
|
---|
1075 | pInfo->pu8Bits = address;
|
---|
1076 | pInfo->xOrigin = xOrigin;
|
---|
1077 | pInfo->yOrigin = yOrigin;
|
---|
1078 | pInfo->cWidth = width;
|
---|
1079 | pInfo->cHeight = height;
|
---|
1080 | pInfo->cBitsPerPixel = bitsPerPixel;
|
---|
1081 | pInfo->cbLine = lineSize;
|
---|
1082 |
|
---|
1083 | pfb->Unlock();
|
---|
1084 |
|
---|
1085 | fAvailable = true;
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | if (server->maFramebuffers[uScreenId])
|
---|
1089 | {
|
---|
1090 | server->maFramebuffers[uScreenId]->Release();
|
---|
1091 | }
|
---|
1092 | server->maFramebuffers[uScreenId] = pfb;
|
---|
1093 |
|
---|
1094 | return fAvailable;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferLock(void *pvCallback, unsigned uScreenId)
|
---|
1098 | {
|
---|
1099 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
1100 |
|
---|
1101 | if (server->maFramebuffers[uScreenId])
|
---|
1102 | {
|
---|
1103 | server->maFramebuffers[uScreenId]->Lock();
|
---|
1104 | }
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackFramebufferUnlock(void *pvCallback, unsigned uScreenId)
|
---|
1108 | {
|
---|
1109 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
1110 |
|
---|
1111 | if (server->maFramebuffers[uScreenId])
|
---|
1112 | {
|
---|
1113 | server->maFramebuffers[uScreenId]->Unlock();
|
---|
1114 | }
|
---|
1115 | }
|
---|
1116 |
|
---|
1117 | static void fixKbdLockStatus(VRDPInputSynch *pInputSynch, IKeyboard *pKeyboard)
|
---|
1118 | {
|
---|
1119 | if ( pInputSynch->cGuestNumLockAdaptions
|
---|
1120 | && (pInputSynch->fGuestNumLock != pInputSynch->fClientNumLock))
|
---|
1121 | {
|
---|
1122 | pInputSynch->cGuestNumLockAdaptions--;
|
---|
1123 | pKeyboard->PutScancode(0x45);
|
---|
1124 | pKeyboard->PutScancode(0x45 | 0x80);
|
---|
1125 | }
|
---|
1126 | if ( pInputSynch->cGuestCapsLockAdaptions
|
---|
1127 | && (pInputSynch->fGuestCapsLock != pInputSynch->fClientCapsLock))
|
---|
1128 | {
|
---|
1129 | pInputSynch->cGuestCapsLockAdaptions--;
|
---|
1130 | pKeyboard->PutScancode(0x3a);
|
---|
1131 | pKeyboard->PutScancode(0x3a | 0x80);
|
---|
1132 | }
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackInput(void *pvCallback, int type, const void *pvInput, unsigned cbInput)
|
---|
1136 | {
|
---|
1137 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
1138 | Console *pConsole = server->mConsole;
|
---|
1139 |
|
---|
1140 | switch (type)
|
---|
1141 | {
|
---|
1142 | case VRDE_INPUT_SCANCODE:
|
---|
1143 | {
|
---|
1144 | if (cbInput == sizeof(VRDEINPUTSCANCODE))
|
---|
1145 | {
|
---|
1146 | IKeyboard *pKeyboard = pConsole->getKeyboard();
|
---|
1147 |
|
---|
1148 | const VRDEINPUTSCANCODE *pInputScancode = (VRDEINPUTSCANCODE *)pvInput;
|
---|
1149 |
|
---|
1150 | /* Track lock keys. */
|
---|
1151 | if (pInputScancode->uScancode == 0x45)
|
---|
1152 | {
|
---|
1153 | server->m_InputSynch.fClientNumLock = !server->m_InputSynch.fClientNumLock;
|
---|
1154 | }
|
---|
1155 | else if (pInputScancode->uScancode == 0x3a)
|
---|
1156 | {
|
---|
1157 | server->m_InputSynch.fClientCapsLock = !server->m_InputSynch.fClientCapsLock;
|
---|
1158 | }
|
---|
1159 | else if (pInputScancode->uScancode == 0x46)
|
---|
1160 | {
|
---|
1161 | server->m_InputSynch.fClientScrollLock = !server->m_InputSynch.fClientScrollLock;
|
---|
1162 | }
|
---|
1163 | else if ((pInputScancode->uScancode & 0x80) == 0)
|
---|
1164 | {
|
---|
1165 | /* Key pressed. */
|
---|
1166 | fixKbdLockStatus(&server->m_InputSynch, pKeyboard);
|
---|
1167 | }
|
---|
1168 |
|
---|
1169 | pKeyboard->PutScancode((LONG)pInputScancode->uScancode);
|
---|
1170 | }
|
---|
1171 | } break;
|
---|
1172 |
|
---|
1173 | case VRDE_INPUT_POINT:
|
---|
1174 | {
|
---|
1175 | if (cbInput == sizeof(VRDEINPUTPOINT))
|
---|
1176 | {
|
---|
1177 | const VRDEINPUTPOINT *pInputPoint = (VRDEINPUTPOINT *)pvInput;
|
---|
1178 |
|
---|
1179 | int mouseButtons = 0;
|
---|
1180 | int iWheel = 0;
|
---|
1181 |
|
---|
1182 | if (pInputPoint->uButtons & VRDE_INPUT_POINT_BUTTON1)
|
---|
1183 | {
|
---|
1184 | mouseButtons |= MouseButtonState_LeftButton;
|
---|
1185 | }
|
---|
1186 | if (pInputPoint->uButtons & VRDE_INPUT_POINT_BUTTON2)
|
---|
1187 | {
|
---|
1188 | mouseButtons |= MouseButtonState_RightButton;
|
---|
1189 | }
|
---|
1190 | if (pInputPoint->uButtons & VRDE_INPUT_POINT_BUTTON3)
|
---|
1191 | {
|
---|
1192 | mouseButtons |= MouseButtonState_MiddleButton;
|
---|
1193 | }
|
---|
1194 | if (pInputPoint->uButtons & VRDE_INPUT_POINT_WHEEL_UP)
|
---|
1195 | {
|
---|
1196 | mouseButtons |= MouseButtonState_WheelUp;
|
---|
1197 | iWheel = -1;
|
---|
1198 | }
|
---|
1199 | if (pInputPoint->uButtons & VRDE_INPUT_POINT_WHEEL_DOWN)
|
---|
1200 | {
|
---|
1201 | mouseButtons |= MouseButtonState_WheelDown;
|
---|
1202 | iWheel = 1;
|
---|
1203 | }
|
---|
1204 |
|
---|
1205 | if (server->m_fGuestWantsAbsolute)
|
---|
1206 | {
|
---|
1207 | pConsole->getMouse()->PutMouseEventAbsolute(pInputPoint->x + 1, pInputPoint->y + 1, iWheel, 0 /* Horizontal wheel */, mouseButtons);
|
---|
1208 | } else
|
---|
1209 | {
|
---|
1210 | pConsole->getMouse()->PutMouseEvent(pInputPoint->x - server->m_mousex,
|
---|
1211 | pInputPoint->y - server->m_mousey,
|
---|
1212 | iWheel, 0 /* Horizontal wheel */, mouseButtons);
|
---|
1213 | server->m_mousex = pInputPoint->x;
|
---|
1214 | server->m_mousey = pInputPoint->y;
|
---|
1215 | }
|
---|
1216 | }
|
---|
1217 | } break;
|
---|
1218 |
|
---|
1219 | case VRDE_INPUT_CAD:
|
---|
1220 | {
|
---|
1221 | pConsole->getKeyboard()->PutCAD();
|
---|
1222 | } break;
|
---|
1223 |
|
---|
1224 | case VRDE_INPUT_RESET:
|
---|
1225 | {
|
---|
1226 | pConsole->Reset();
|
---|
1227 | } break;
|
---|
1228 |
|
---|
1229 | case VRDE_INPUT_SYNCH:
|
---|
1230 | {
|
---|
1231 | if (cbInput == sizeof(VRDEINPUTSYNCH))
|
---|
1232 | {
|
---|
1233 | IKeyboard *pKeyboard = pConsole->getKeyboard();
|
---|
1234 |
|
---|
1235 | const VRDEINPUTSYNCH *pInputSynch = (VRDEINPUTSYNCH *)pvInput;
|
---|
1236 |
|
---|
1237 | server->m_InputSynch.fClientNumLock = (pInputSynch->uLockStatus & VRDE_INPUT_SYNCH_NUMLOCK) != 0;
|
---|
1238 | server->m_InputSynch.fClientCapsLock = (pInputSynch->uLockStatus & VRDE_INPUT_SYNCH_CAPITAL) != 0;
|
---|
1239 | server->m_InputSynch.fClientScrollLock = (pInputSynch->uLockStatus & VRDE_INPUT_SYNCH_SCROLL) != 0;
|
---|
1240 |
|
---|
1241 | /* The client initiated synchronization. Always make the guest to reflect the client state.
|
---|
1242 | * Than means, when the guest changes the state itself, it is forced to return to the client
|
---|
1243 | * state.
|
---|
1244 | */
|
---|
1245 | if (server->m_InputSynch.fClientNumLock != server->m_InputSynch.fGuestNumLock)
|
---|
1246 | {
|
---|
1247 | server->m_InputSynch.cGuestNumLockAdaptions = 2;
|
---|
1248 | }
|
---|
1249 |
|
---|
1250 | if (server->m_InputSynch.fClientCapsLock != server->m_InputSynch.fGuestCapsLock)
|
---|
1251 | {
|
---|
1252 | server->m_InputSynch.cGuestCapsLockAdaptions = 2;
|
---|
1253 | }
|
---|
1254 |
|
---|
1255 | fixKbdLockStatus(&server->m_InputSynch, pKeyboard);
|
---|
1256 | }
|
---|
1257 | } break;
|
---|
1258 |
|
---|
1259 | default:
|
---|
1260 | break;
|
---|
1261 | }
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | DECLCALLBACK(void) ConsoleVRDPServer::VRDPCallbackVideoModeHint(void *pvCallback, unsigned cWidth, unsigned cHeight, unsigned cBitsPerPixel, unsigned uScreenId)
|
---|
1265 | {
|
---|
1266 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
1267 |
|
---|
1268 | server->mConsole->getDisplay()->SetVideoModeHint(uScreenId, TRUE /*=enabled*/,
|
---|
1269 | FALSE /*=changeOrigin*/, 0/*=OriginX*/, 0/*=OriginY*/,
|
---|
1270 | cWidth, cHeight, cBitsPerPixel);
|
---|
1271 | }
|
---|
1272 |
|
---|
1273 | DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackAudioIn(void *pvCallback,
|
---|
1274 | void *pvCtx,
|
---|
1275 | uint32_t u32ClientId,
|
---|
1276 | uint32_t u32Event,
|
---|
1277 | const void *pvData,
|
---|
1278 | uint32_t cbData)
|
---|
1279 | {
|
---|
1280 | ConsoleVRDPServer *server = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
1281 |
|
---|
1282 | PPDMIAUDIOSNIFFERPORT pPort = server->mConsole->getAudioSniffer()->getAudioSnifferPort();
|
---|
1283 |
|
---|
1284 | switch (u32Event)
|
---|
1285 | {
|
---|
1286 | case VRDE_AUDIOIN_BEGIN:
|
---|
1287 | {
|
---|
1288 | const VRDEAUDIOINBEGIN *pParms = (const VRDEAUDIOINBEGIN *)pvData;
|
---|
1289 |
|
---|
1290 | pPort->pfnAudioInputEventBegin (pPort, pvCtx,
|
---|
1291 | VRDE_AUDIO_FMT_SAMPLE_FREQ(pParms->fmt),
|
---|
1292 | VRDE_AUDIO_FMT_CHANNELS(pParms->fmt),
|
---|
1293 | VRDE_AUDIO_FMT_BITS_PER_SAMPLE(pParms->fmt),
|
---|
1294 | VRDE_AUDIO_FMT_SIGNED(pParms->fmt)
|
---|
1295 | );
|
---|
1296 | } break;
|
---|
1297 |
|
---|
1298 | case VRDE_AUDIOIN_DATA:
|
---|
1299 | {
|
---|
1300 | pPort->pfnAudioInputEventData (pPort, pvCtx, pvData, cbData);
|
---|
1301 | } break;
|
---|
1302 |
|
---|
1303 | case VRDE_AUDIOIN_END:
|
---|
1304 | {
|
---|
1305 | pPort->pfnAudioInputEventEnd (pPort, pvCtx);
|
---|
1306 | } break;
|
---|
1307 |
|
---|
1308 | default:
|
---|
1309 | return;
|
---|
1310 | }
|
---|
1311 | }
|
---|
1312 |
|
---|
1313 |
|
---|
1314 | ConsoleVRDPServer::ConsoleVRDPServer(Console *console)
|
---|
1315 | {
|
---|
1316 | mConsole = console;
|
---|
1317 |
|
---|
1318 | int rc = RTCritSectInit(&mCritSect);
|
---|
1319 | AssertRC(rc);
|
---|
1320 |
|
---|
1321 | mcClipboardRefs = 0;
|
---|
1322 | mpfnClipboardCallback = NULL;
|
---|
1323 |
|
---|
1324 | #ifdef VBOX_WITH_USB
|
---|
1325 | mUSBBackends.pHead = NULL;
|
---|
1326 | mUSBBackends.pTail = NULL;
|
---|
1327 |
|
---|
1328 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
1329 | mUSBBackends.fThreadRunning = false;
|
---|
1330 | mUSBBackends.event = 0;
|
---|
1331 | #endif
|
---|
1332 |
|
---|
1333 | mhServer = 0;
|
---|
1334 | mServerInterfaceVersion = 0;
|
---|
1335 |
|
---|
1336 | m_fGuestWantsAbsolute = false;
|
---|
1337 | m_mousex = 0;
|
---|
1338 | m_mousey = 0;
|
---|
1339 |
|
---|
1340 | m_InputSynch.cGuestNumLockAdaptions = 2;
|
---|
1341 | m_InputSynch.cGuestCapsLockAdaptions = 2;
|
---|
1342 |
|
---|
1343 | m_InputSynch.fGuestNumLock = false;
|
---|
1344 | m_InputSynch.fGuestCapsLock = false;
|
---|
1345 | m_InputSynch.fGuestScrollLock = false;
|
---|
1346 |
|
---|
1347 | m_InputSynch.fClientNumLock = false;
|
---|
1348 | m_InputSynch.fClientCapsLock = false;
|
---|
1349 | m_InputSynch.fClientScrollLock = false;
|
---|
1350 |
|
---|
1351 | memset(maFramebuffers, 0, sizeof(maFramebuffers));
|
---|
1352 |
|
---|
1353 | {
|
---|
1354 | ComPtr<IEventSource> es;
|
---|
1355 | console->COMGETTER(EventSource)(es.asOutParam());
|
---|
1356 | ComObjPtr<VRDPConsoleListenerImpl> aConsoleListener;
|
---|
1357 | aConsoleListener.createObject();
|
---|
1358 | aConsoleListener->init(new VRDPConsoleListener(), this);
|
---|
1359 | mConsoleListener = aConsoleListener;
|
---|
1360 | com::SafeArray <VBoxEventType_T> eventTypes;
|
---|
1361 | eventTypes.push_back(VBoxEventType_OnMousePointerShapeChanged);
|
---|
1362 | eventTypes.push_back(VBoxEventType_OnMouseCapabilityChanged);
|
---|
1363 | eventTypes.push_back(VBoxEventType_OnKeyboardLedsChanged);
|
---|
1364 | es->RegisterListener(mConsoleListener, ComSafeArrayAsInParam(eventTypes), true);
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 | mVRDPBindPort = -1;
|
---|
1368 |
|
---|
1369 | mAuthLibrary = 0;
|
---|
1370 |
|
---|
1371 | mu32AudioInputClientId = 0;
|
---|
1372 |
|
---|
1373 | /*
|
---|
1374 | * Optional interfaces.
|
---|
1375 | */
|
---|
1376 | m_fInterfaceImage = false;
|
---|
1377 | memset(&m_interfaceImage, 0, sizeof (m_interfaceImage));
|
---|
1378 | memset(&m_interfaceCallbacksImage, 0, sizeof (m_interfaceCallbacksImage));
|
---|
1379 | RT_ZERO(m_interfaceMousePtr);
|
---|
1380 | RT_ZERO(m_interfaceSCard);
|
---|
1381 | RT_ZERO(m_interfaceCallbacksSCard);
|
---|
1382 | RT_ZERO(m_interfaceTSMF);
|
---|
1383 | RT_ZERO(m_interfaceCallbacksTSMF);
|
---|
1384 | RT_ZERO(m_interfaceVideoIn);
|
---|
1385 | RT_ZERO(m_interfaceCallbacksVideoIn);
|
---|
1386 |
|
---|
1387 | rc = RTCritSectInit(&mTSMFLock);
|
---|
1388 | AssertRC(rc);
|
---|
1389 | }
|
---|
1390 |
|
---|
1391 | ConsoleVRDPServer::~ConsoleVRDPServer()
|
---|
1392 | {
|
---|
1393 | Stop();
|
---|
1394 |
|
---|
1395 | if (mConsoleListener)
|
---|
1396 | {
|
---|
1397 | ComPtr<IEventSource> es;
|
---|
1398 | mConsole->COMGETTER(EventSource)(es.asOutParam());
|
---|
1399 | es->UnregisterListener(mConsoleListener);
|
---|
1400 | mConsoleListener.setNull();
|
---|
1401 | }
|
---|
1402 |
|
---|
1403 | unsigned i;
|
---|
1404 | for (i = 0; i < RT_ELEMENTS(maFramebuffers); i++)
|
---|
1405 | {
|
---|
1406 | if (maFramebuffers[i])
|
---|
1407 | {
|
---|
1408 | maFramebuffers[i]->Release();
|
---|
1409 | maFramebuffers[i] = NULL;
|
---|
1410 | }
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 | if (RTCritSectIsInitialized(&mCritSect))
|
---|
1414 | {
|
---|
1415 | RTCritSectDelete(&mCritSect);
|
---|
1416 | memset(&mCritSect, 0, sizeof(mCritSect));
|
---|
1417 | }
|
---|
1418 |
|
---|
1419 | if (RTCritSectIsInitialized(&mTSMFLock))
|
---|
1420 | {
|
---|
1421 | RTCritSectDelete(&mTSMFLock);
|
---|
1422 | memset(&mTSMFLock, 0, sizeof(mTSMFLock));
|
---|
1423 | }
|
---|
1424 | }
|
---|
1425 |
|
---|
1426 | int ConsoleVRDPServer::Launch(void)
|
---|
1427 | {
|
---|
1428 | LogFlowThisFunc(("\n"));
|
---|
1429 |
|
---|
1430 | IVRDEServer *server = mConsole->getVRDEServer();
|
---|
1431 | AssertReturn(server, VERR_INTERNAL_ERROR_2);
|
---|
1432 |
|
---|
1433 | /*
|
---|
1434 | * Check if VRDE is enabled.
|
---|
1435 | */
|
---|
1436 | BOOL fEnabled;
|
---|
1437 | HRESULT hrc = server->COMGETTER(Enabled)(&fEnabled);
|
---|
1438 | AssertComRCReturn(hrc, Global::vboxStatusCodeFromCOM(hrc));
|
---|
1439 | if (!fEnabled)
|
---|
1440 | return VINF_SUCCESS;
|
---|
1441 |
|
---|
1442 | /*
|
---|
1443 | * Check that a VRDE extension pack name is set and resolve it into a
|
---|
1444 | * library path.
|
---|
1445 | */
|
---|
1446 | Bstr bstrExtPack;
|
---|
1447 | hrc = server->COMGETTER(VRDEExtPack)(bstrExtPack.asOutParam());
|
---|
1448 | if (FAILED(hrc))
|
---|
1449 | return Global::vboxStatusCodeFromCOM(hrc);
|
---|
1450 | if (bstrExtPack.isEmpty())
|
---|
1451 | return VINF_NOT_SUPPORTED;
|
---|
1452 |
|
---|
1453 | Utf8Str strExtPack(bstrExtPack);
|
---|
1454 | Utf8Str strVrdeLibrary;
|
---|
1455 | int vrc = VINF_SUCCESS;
|
---|
1456 | if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
|
---|
1457 | strVrdeLibrary = "VBoxVRDP";
|
---|
1458 | else
|
---|
1459 | {
|
---|
1460 | #ifdef VBOX_WITH_EXTPACK
|
---|
1461 | ExtPackManager *pExtPackMgr = mConsole->getExtPackManager();
|
---|
1462 | vrc = pExtPackMgr->getVrdeLibraryPathForExtPack(&strExtPack, &strVrdeLibrary);
|
---|
1463 | #else
|
---|
1464 | vrc = VERR_FILE_NOT_FOUND;
|
---|
1465 | #endif
|
---|
1466 | }
|
---|
1467 | if (RT_SUCCESS(vrc))
|
---|
1468 | {
|
---|
1469 | /*
|
---|
1470 | * Load the VRDE library and start the server, if it is enabled.
|
---|
1471 | */
|
---|
1472 | vrc = loadVRDPLibrary(strVrdeLibrary.c_str());
|
---|
1473 | if (RT_SUCCESS(vrc))
|
---|
1474 | {
|
---|
1475 | VRDEENTRYPOINTS_4 *pEntryPoints4;
|
---|
1476 | vrc = mpfnVRDECreateServer(&mCallbacks.header, this, (VRDEINTERFACEHDR **)&pEntryPoints4, &mhServer);
|
---|
1477 |
|
---|
1478 | if (RT_SUCCESS(vrc))
|
---|
1479 | {
|
---|
1480 | mServerInterfaceVersion = 4;
|
---|
1481 | mEntryPoints = *pEntryPoints4;
|
---|
1482 | mpEntryPoints = &mEntryPoints;
|
---|
1483 | }
|
---|
1484 | else if (vrc == VERR_VERSION_MISMATCH)
|
---|
1485 | {
|
---|
1486 | /* An older version of VRDE is installed, try version 3. */
|
---|
1487 | VRDEENTRYPOINTS_3 *pEntryPoints3;
|
---|
1488 |
|
---|
1489 | static VRDECALLBACKS_3 sCallbacks3 =
|
---|
1490 | {
|
---|
1491 | { VRDE_INTERFACE_VERSION_3, sizeof(VRDECALLBACKS_3) },
|
---|
1492 | ConsoleVRDPServer::VRDPCallbackQueryProperty,
|
---|
1493 | ConsoleVRDPServer::VRDPCallbackClientLogon,
|
---|
1494 | ConsoleVRDPServer::VRDPCallbackClientConnect,
|
---|
1495 | ConsoleVRDPServer::VRDPCallbackClientDisconnect,
|
---|
1496 | ConsoleVRDPServer::VRDPCallbackIntercept,
|
---|
1497 | ConsoleVRDPServer::VRDPCallbackUSB,
|
---|
1498 | ConsoleVRDPServer::VRDPCallbackClipboard,
|
---|
1499 | ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
|
---|
1500 | ConsoleVRDPServer::VRDPCallbackFramebufferLock,
|
---|
1501 | ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
|
---|
1502 | ConsoleVRDPServer::VRDPCallbackInput,
|
---|
1503 | ConsoleVRDPServer::VRDPCallbackVideoModeHint,
|
---|
1504 | ConsoleVRDPServer::VRDECallbackAudioIn
|
---|
1505 | };
|
---|
1506 |
|
---|
1507 | vrc = mpfnVRDECreateServer(&sCallbacks3.header, this, (VRDEINTERFACEHDR **)&pEntryPoints3, &mhServer);
|
---|
1508 | if (RT_SUCCESS(vrc))
|
---|
1509 | {
|
---|
1510 | mServerInterfaceVersion = 3;
|
---|
1511 | mEntryPoints.header = pEntryPoints3->header;
|
---|
1512 | mEntryPoints.VRDEDestroy = pEntryPoints3->VRDEDestroy;
|
---|
1513 | mEntryPoints.VRDEEnableConnections = pEntryPoints3->VRDEEnableConnections;
|
---|
1514 | mEntryPoints.VRDEDisconnect = pEntryPoints3->VRDEDisconnect;
|
---|
1515 | mEntryPoints.VRDEResize = pEntryPoints3->VRDEResize;
|
---|
1516 | mEntryPoints.VRDEUpdate = pEntryPoints3->VRDEUpdate;
|
---|
1517 | mEntryPoints.VRDEColorPointer = pEntryPoints3->VRDEColorPointer;
|
---|
1518 | mEntryPoints.VRDEHidePointer = pEntryPoints3->VRDEHidePointer;
|
---|
1519 | mEntryPoints.VRDEAudioSamples = pEntryPoints3->VRDEAudioSamples;
|
---|
1520 | mEntryPoints.VRDEAudioVolume = pEntryPoints3->VRDEAudioVolume;
|
---|
1521 | mEntryPoints.VRDEUSBRequest = pEntryPoints3->VRDEUSBRequest;
|
---|
1522 | mEntryPoints.VRDEClipboard = pEntryPoints3->VRDEClipboard;
|
---|
1523 | mEntryPoints.VRDEQueryInfo = pEntryPoints3->VRDEQueryInfo;
|
---|
1524 | mEntryPoints.VRDERedirect = pEntryPoints3->VRDERedirect;
|
---|
1525 | mEntryPoints.VRDEAudioInOpen = pEntryPoints3->VRDEAudioInOpen;
|
---|
1526 | mEntryPoints.VRDEAudioInClose = pEntryPoints3->VRDEAudioInClose;
|
---|
1527 | mEntryPoints.VRDEGetInterface = NULL;
|
---|
1528 | mpEntryPoints = &mEntryPoints;
|
---|
1529 | }
|
---|
1530 | else if (vrc == VERR_VERSION_MISMATCH)
|
---|
1531 | {
|
---|
1532 | /* An older version of VRDE is installed, try version 1. */
|
---|
1533 | VRDEENTRYPOINTS_1 *pEntryPoints1;
|
---|
1534 |
|
---|
1535 | static VRDECALLBACKS_1 sCallbacks1 =
|
---|
1536 | {
|
---|
1537 | { VRDE_INTERFACE_VERSION_1, sizeof(VRDECALLBACKS_1) },
|
---|
1538 | ConsoleVRDPServer::VRDPCallbackQueryProperty,
|
---|
1539 | ConsoleVRDPServer::VRDPCallbackClientLogon,
|
---|
1540 | ConsoleVRDPServer::VRDPCallbackClientConnect,
|
---|
1541 | ConsoleVRDPServer::VRDPCallbackClientDisconnect,
|
---|
1542 | ConsoleVRDPServer::VRDPCallbackIntercept,
|
---|
1543 | ConsoleVRDPServer::VRDPCallbackUSB,
|
---|
1544 | ConsoleVRDPServer::VRDPCallbackClipboard,
|
---|
1545 | ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
|
---|
1546 | ConsoleVRDPServer::VRDPCallbackFramebufferLock,
|
---|
1547 | ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
|
---|
1548 | ConsoleVRDPServer::VRDPCallbackInput,
|
---|
1549 | ConsoleVRDPServer::VRDPCallbackVideoModeHint
|
---|
1550 | };
|
---|
1551 |
|
---|
1552 | vrc = mpfnVRDECreateServer(&sCallbacks1.header, this, (VRDEINTERFACEHDR **)&pEntryPoints1, &mhServer);
|
---|
1553 | if (RT_SUCCESS(vrc))
|
---|
1554 | {
|
---|
1555 | mServerInterfaceVersion = 1;
|
---|
1556 | mEntryPoints.header = pEntryPoints1->header;
|
---|
1557 | mEntryPoints.VRDEDestroy = pEntryPoints1->VRDEDestroy;
|
---|
1558 | mEntryPoints.VRDEEnableConnections = pEntryPoints1->VRDEEnableConnections;
|
---|
1559 | mEntryPoints.VRDEDisconnect = pEntryPoints1->VRDEDisconnect;
|
---|
1560 | mEntryPoints.VRDEResize = pEntryPoints1->VRDEResize;
|
---|
1561 | mEntryPoints.VRDEUpdate = pEntryPoints1->VRDEUpdate;
|
---|
1562 | mEntryPoints.VRDEColorPointer = pEntryPoints1->VRDEColorPointer;
|
---|
1563 | mEntryPoints.VRDEHidePointer = pEntryPoints1->VRDEHidePointer;
|
---|
1564 | mEntryPoints.VRDEAudioSamples = pEntryPoints1->VRDEAudioSamples;
|
---|
1565 | mEntryPoints.VRDEAudioVolume = pEntryPoints1->VRDEAudioVolume;
|
---|
1566 | mEntryPoints.VRDEUSBRequest = pEntryPoints1->VRDEUSBRequest;
|
---|
1567 | mEntryPoints.VRDEClipboard = pEntryPoints1->VRDEClipboard;
|
---|
1568 | mEntryPoints.VRDEQueryInfo = pEntryPoints1->VRDEQueryInfo;
|
---|
1569 | mEntryPoints.VRDERedirect = NULL;
|
---|
1570 | mEntryPoints.VRDEAudioInOpen = NULL;
|
---|
1571 | mEntryPoints.VRDEAudioInClose = NULL;
|
---|
1572 | mEntryPoints.VRDEGetInterface = NULL;
|
---|
1573 | mpEntryPoints = &mEntryPoints;
|
---|
1574 | }
|
---|
1575 | }
|
---|
1576 | }
|
---|
1577 |
|
---|
1578 | if (RT_SUCCESS(vrc))
|
---|
1579 | {
|
---|
1580 | LogRel(("VRDE: loaded version %d of the server.\n", mServerInterfaceVersion));
|
---|
1581 |
|
---|
1582 | if (mServerInterfaceVersion >= 4)
|
---|
1583 | {
|
---|
1584 | /* The server supports optional interfaces. */
|
---|
1585 | Assert(mpEntryPoints->VRDEGetInterface != NULL);
|
---|
1586 |
|
---|
1587 | /* Image interface. */
|
---|
1588 | m_interfaceImage.header.u64Version = 1;
|
---|
1589 | m_interfaceImage.header.u64Size = sizeof(m_interfaceImage);
|
---|
1590 |
|
---|
1591 | m_interfaceCallbacksImage.header.u64Version = 1;
|
---|
1592 | m_interfaceCallbacksImage.header.u64Size = sizeof(m_interfaceCallbacksImage);
|
---|
1593 | m_interfaceCallbacksImage.VRDEImageCbNotify = VRDEImageCbNotify;
|
---|
1594 |
|
---|
1595 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1596 | VRDE_IMAGE_INTERFACE_NAME,
|
---|
1597 | &m_interfaceImage.header,
|
---|
1598 | &m_interfaceCallbacksImage.header,
|
---|
1599 | this);
|
---|
1600 | if (RT_SUCCESS(vrc))
|
---|
1601 | {
|
---|
1602 | LogRel(("VRDE: [%s]\n", VRDE_IMAGE_INTERFACE_NAME));
|
---|
1603 | m_fInterfaceImage = true;
|
---|
1604 | }
|
---|
1605 |
|
---|
1606 | /* Mouse pointer interface. */
|
---|
1607 | m_interfaceMousePtr.header.u64Version = 1;
|
---|
1608 | m_interfaceMousePtr.header.u64Size = sizeof(m_interfaceMousePtr);
|
---|
1609 |
|
---|
1610 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1611 | VRDE_MOUSEPTR_INTERFACE_NAME,
|
---|
1612 | &m_interfaceMousePtr.header,
|
---|
1613 | NULL,
|
---|
1614 | this);
|
---|
1615 | if (RT_SUCCESS(vrc))
|
---|
1616 | {
|
---|
1617 | LogRel(("VRDE: [%s]\n", VRDE_MOUSEPTR_INTERFACE_NAME));
|
---|
1618 | }
|
---|
1619 | else
|
---|
1620 | {
|
---|
1621 | RT_ZERO(m_interfaceMousePtr);
|
---|
1622 | }
|
---|
1623 |
|
---|
1624 | /* Smartcard interface. */
|
---|
1625 | m_interfaceSCard.header.u64Version = 1;
|
---|
1626 | m_interfaceSCard.header.u64Size = sizeof(m_interfaceSCard);
|
---|
1627 |
|
---|
1628 | m_interfaceCallbacksSCard.header.u64Version = 1;
|
---|
1629 | m_interfaceCallbacksSCard.header.u64Size = sizeof(m_interfaceCallbacksSCard);
|
---|
1630 | m_interfaceCallbacksSCard.VRDESCardCbNotify = VRDESCardCbNotify;
|
---|
1631 | m_interfaceCallbacksSCard.VRDESCardCbResponse = VRDESCardCbResponse;
|
---|
1632 |
|
---|
1633 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1634 | VRDE_SCARD_INTERFACE_NAME,
|
---|
1635 | &m_interfaceSCard.header,
|
---|
1636 | &m_interfaceCallbacksSCard.header,
|
---|
1637 | this);
|
---|
1638 | if (RT_SUCCESS(vrc))
|
---|
1639 | {
|
---|
1640 | LogRel(("VRDE: [%s]\n", VRDE_SCARD_INTERFACE_NAME));
|
---|
1641 | }
|
---|
1642 | else
|
---|
1643 | {
|
---|
1644 | RT_ZERO(m_interfaceSCard);
|
---|
1645 | }
|
---|
1646 |
|
---|
1647 | /* Raw TSMF interface. */
|
---|
1648 | m_interfaceTSMF.header.u64Version = 1;
|
---|
1649 | m_interfaceTSMF.header.u64Size = sizeof(m_interfaceTSMF);
|
---|
1650 |
|
---|
1651 | m_interfaceCallbacksTSMF.header.u64Version = 1;
|
---|
1652 | m_interfaceCallbacksTSMF.header.u64Size = sizeof(m_interfaceCallbacksTSMF);
|
---|
1653 | m_interfaceCallbacksTSMF.VRDETSMFCbNotify = VRDETSMFCbNotify;
|
---|
1654 |
|
---|
1655 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1656 | VRDE_TSMF_INTERFACE_NAME,
|
---|
1657 | &m_interfaceTSMF.header,
|
---|
1658 | &m_interfaceCallbacksTSMF.header,
|
---|
1659 | this);
|
---|
1660 | if (RT_SUCCESS(vrc))
|
---|
1661 | {
|
---|
1662 | LogRel(("VRDE: [%s]\n", VRDE_TSMF_INTERFACE_NAME));
|
---|
1663 | }
|
---|
1664 | else
|
---|
1665 | {
|
---|
1666 | RT_ZERO(m_interfaceTSMF);
|
---|
1667 | }
|
---|
1668 |
|
---|
1669 | /* VideoIn interface. */
|
---|
1670 | m_interfaceVideoIn.header.u64Version = 1;
|
---|
1671 | m_interfaceVideoIn.header.u64Size = sizeof(m_interfaceVideoIn);
|
---|
1672 |
|
---|
1673 | m_interfaceCallbacksVideoIn.header.u64Version = 1;
|
---|
1674 | m_interfaceCallbacksVideoIn.header.u64Size = sizeof(m_interfaceCallbacksVideoIn);
|
---|
1675 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInNotify = VRDECallbackVideoInNotify;
|
---|
1676 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInDeviceDesc = VRDECallbackVideoInDeviceDesc;
|
---|
1677 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInControl = VRDECallbackVideoInControl;
|
---|
1678 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInFrame = VRDECallbackVideoInFrame;
|
---|
1679 |
|
---|
1680 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1681 | VRDE_VIDEOIN_INTERFACE_NAME,
|
---|
1682 | &m_interfaceVideoIn.header,
|
---|
1683 | &m_interfaceCallbacksVideoIn.header,
|
---|
1684 | this);
|
---|
1685 | if (RT_SUCCESS(vrc))
|
---|
1686 | {
|
---|
1687 | LogRel(("VRDE: [%s]\n", VRDE_VIDEOIN_INTERFACE_NAME));
|
---|
1688 | }
|
---|
1689 | else
|
---|
1690 | {
|
---|
1691 | RT_ZERO(m_interfaceVideoIn);
|
---|
1692 | }
|
---|
1693 |
|
---|
1694 | /* Since these interfaces are optional, it is always a success here. */
|
---|
1695 | vrc = VINF_SUCCESS;
|
---|
1696 | }
|
---|
1697 | #ifdef VBOX_WITH_USB
|
---|
1698 | remoteUSBThreadStart();
|
---|
1699 | #endif
|
---|
1700 | }
|
---|
1701 | else
|
---|
1702 | {
|
---|
1703 | if (vrc != VERR_NET_ADDRESS_IN_USE)
|
---|
1704 | LogRel(("VRDE: Could not start the server rc = %Rrc\n", vrc));
|
---|
1705 | /* Don't unload the lib, because it prevents us trying again or
|
---|
1706 | because there may be other users? */
|
---|
1707 | }
|
---|
1708 | }
|
---|
1709 | }
|
---|
1710 |
|
---|
1711 | return vrc;
|
---|
1712 | }
|
---|
1713 |
|
---|
1714 | typedef struct H3DORInstance
|
---|
1715 | {
|
---|
1716 | ConsoleVRDPServer *pThis;
|
---|
1717 | HVRDEIMAGE hImageBitmap;
|
---|
1718 | int32_t x;
|
---|
1719 | int32_t y;
|
---|
1720 | uint32_t w;
|
---|
1721 | uint32_t h;
|
---|
1722 | bool fCreated;
|
---|
1723 | } H3DORInstance;
|
---|
1724 |
|
---|
1725 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORBegin(const void *pvContext, void **ppvInstance,
|
---|
1726 | const char *pszFormat)
|
---|
1727 | {
|
---|
1728 | LogFlowFunc(("ctx %p\n", pvContext));
|
---|
1729 |
|
---|
1730 | H3DORInstance *p = (H3DORInstance *)RTMemAlloc(sizeof (H3DORInstance));
|
---|
1731 |
|
---|
1732 | if (p)
|
---|
1733 | {
|
---|
1734 | p->pThis = (ConsoleVRDPServer *)pvContext;
|
---|
1735 | p->hImageBitmap = NULL;
|
---|
1736 | p->x = 0;
|
---|
1737 | p->y = 0;
|
---|
1738 | p->w = 0;
|
---|
1739 | p->h = 0;
|
---|
1740 | p->fCreated = false;
|
---|
1741 |
|
---|
1742 | /* Host 3D service passes the actual format of data in this redirect instance.
|
---|
1743 | * That is what will be in the H3DORFrame's parameters pvData and cbData.
|
---|
1744 | */
|
---|
1745 | if (RTStrICmp(pszFormat, H3DOR_FMT_RGBA_TOPDOWN) == 0)
|
---|
1746 | {
|
---|
1747 | /* Accept it. */
|
---|
1748 | }
|
---|
1749 | else
|
---|
1750 | {
|
---|
1751 | RTMemFree(p);
|
---|
1752 | p = NULL;
|
---|
1753 | }
|
---|
1754 | }
|
---|
1755 |
|
---|
1756 | /* Caller check this for NULL. */
|
---|
1757 | *ppvInstance = p;
|
---|
1758 | }
|
---|
1759 |
|
---|
1760 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORGeometry(void *pvInstance,
|
---|
1761 | int32_t x, int32_t y, uint32_t w, uint32_t h)
|
---|
1762 | {
|
---|
1763 | LogFlowFunc(("ins %p %d,%d %dx%d\n", pvInstance, x, y, w, h));
|
---|
1764 |
|
---|
1765 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
1766 | Assert(p);
|
---|
1767 | Assert(p->pThis);
|
---|
1768 |
|
---|
1769 | /* @todo find out what to do if size changes to 0x0 from non zero */
|
---|
1770 | if (w == 0 || h == 0)
|
---|
1771 | {
|
---|
1772 | /* Do nothing. */
|
---|
1773 | return;
|
---|
1774 | }
|
---|
1775 |
|
---|
1776 | RTRECT rect;
|
---|
1777 | rect.xLeft = x;
|
---|
1778 | rect.yTop = y;
|
---|
1779 | rect.xRight = x + w;
|
---|
1780 | rect.yBottom = y + h;
|
---|
1781 |
|
---|
1782 | if (p->hImageBitmap)
|
---|
1783 | {
|
---|
1784 | /* An image handle has been already created,
|
---|
1785 | * check if it has the same size as the reported geometry.
|
---|
1786 | */
|
---|
1787 | if ( p->x == x
|
---|
1788 | && p->y == y
|
---|
1789 | && p->w == w
|
---|
1790 | && p->h == h)
|
---|
1791 | {
|
---|
1792 | LogFlowFunc(("geometry not changed\n"));
|
---|
1793 | /* Do nothing. Continue using the existing handle. */
|
---|
1794 | }
|
---|
1795 | else
|
---|
1796 | {
|
---|
1797 | int rc = p->pThis->m_interfaceImage.VRDEImageGeometrySet(p->hImageBitmap, &rect);
|
---|
1798 | if (RT_SUCCESS(rc))
|
---|
1799 | {
|
---|
1800 | p->x = x;
|
---|
1801 | p->y = y;
|
---|
1802 | p->w = w;
|
---|
1803 | p->h = h;
|
---|
1804 | }
|
---|
1805 | else
|
---|
1806 | {
|
---|
1807 | /* The handle must be recreated. Delete existing handle here. */
|
---|
1808 | p->pThis->m_interfaceImage.VRDEImageHandleClose(p->hImageBitmap);
|
---|
1809 | p->hImageBitmap = NULL;
|
---|
1810 | }
|
---|
1811 | }
|
---|
1812 | }
|
---|
1813 |
|
---|
1814 | if (!p->hImageBitmap)
|
---|
1815 | {
|
---|
1816 | /* Create a new bitmap handle. */
|
---|
1817 | uint32_t u32ScreenId = 0; /* @todo clip to corresponding screens.
|
---|
1818 | * Clipping can be done here or in VRDP server.
|
---|
1819 | * If VRDP does clipping, then uScreenId parameter
|
---|
1820 | * is not necessary and coords must be global.
|
---|
1821 | * (have to check which coords are used in opengl service).
|
---|
1822 | * Since all VRDE API uses a ScreenId,
|
---|
1823 | * the clipping must be done here in ConsoleVRDPServer
|
---|
1824 | */
|
---|
1825 | uint32_t fu32CompletionFlags = 0;
|
---|
1826 | int rc = p->pThis->m_interfaceImage.VRDEImageHandleCreate(p->pThis->mhServer,
|
---|
1827 | &p->hImageBitmap,
|
---|
1828 | p,
|
---|
1829 | u32ScreenId,
|
---|
1830 | VRDE_IMAGE_F_CREATE_CONTENT_3D
|
---|
1831 | | VRDE_IMAGE_F_CREATE_WINDOW,
|
---|
1832 | &rect,
|
---|
1833 | VRDE_IMAGE_FMT_ID_BITMAP_BGRA8,
|
---|
1834 | NULL,
|
---|
1835 | 0,
|
---|
1836 | &fu32CompletionFlags);
|
---|
1837 | if (RT_FAILURE(rc))
|
---|
1838 | {
|
---|
1839 | /* No support for a 3D + WINDOW. Try bitmap updates. */
|
---|
1840 | fu32CompletionFlags = 0;
|
---|
1841 | rc = p->pThis->m_interfaceImage.VRDEImageHandleCreate(p->pThis->mhServer,
|
---|
1842 | &p->hImageBitmap,
|
---|
1843 | p,
|
---|
1844 | u32ScreenId,
|
---|
1845 | 0,
|
---|
1846 | &rect,
|
---|
1847 | VRDE_IMAGE_FMT_ID_BITMAP_BGRA8,
|
---|
1848 | NULL,
|
---|
1849 | 0,
|
---|
1850 | &fu32CompletionFlags);
|
---|
1851 | }
|
---|
1852 |
|
---|
1853 | if (RT_SUCCESS(rc))
|
---|
1854 | {
|
---|
1855 | p->x = x;
|
---|
1856 | p->y = y;
|
---|
1857 | p->w = w;
|
---|
1858 | p->h = h;
|
---|
1859 |
|
---|
1860 | if ((fu32CompletionFlags & VRDE_IMAGE_F_COMPLETE_ASYNC) == 0)
|
---|
1861 | {
|
---|
1862 | p->fCreated = true;
|
---|
1863 | }
|
---|
1864 | }
|
---|
1865 | else
|
---|
1866 | {
|
---|
1867 | p->hImageBitmap = NULL;
|
---|
1868 | p->w = 0;
|
---|
1869 | p->h = 0;
|
---|
1870 | }
|
---|
1871 | }
|
---|
1872 | }
|
---|
1873 |
|
---|
1874 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORVisibleRegion(void *pvInstance,
|
---|
1875 | uint32_t cRects, const RTRECT *paRects)
|
---|
1876 | {
|
---|
1877 | LogFlowFunc(("ins %p %d\n", pvInstance, cRects));
|
---|
1878 |
|
---|
1879 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
1880 | Assert(p);
|
---|
1881 | Assert(p->pThis);
|
---|
1882 |
|
---|
1883 | if (cRects == 0)
|
---|
1884 | {
|
---|
1885 | /* Complete image is visible. */
|
---|
1886 | RTRECT rect;
|
---|
1887 | rect.xLeft = p->x;
|
---|
1888 | rect.yTop = p->y;
|
---|
1889 | rect.xRight = p->x + p->w;
|
---|
1890 | rect.yBottom = p->y + p->h;
|
---|
1891 | p->pThis->m_interfaceImage.VRDEImageRegionSet (p->hImageBitmap,
|
---|
1892 | 1,
|
---|
1893 | &rect);
|
---|
1894 | }
|
---|
1895 | else
|
---|
1896 | {
|
---|
1897 | p->pThis->m_interfaceImage.VRDEImageRegionSet (p->hImageBitmap,
|
---|
1898 | cRects,
|
---|
1899 | paRects);
|
---|
1900 | }
|
---|
1901 | }
|
---|
1902 |
|
---|
1903 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORFrame(void *pvInstance,
|
---|
1904 | void *pvData, uint32_t cbData)
|
---|
1905 | {
|
---|
1906 | LogFlowFunc(("ins %p %p %d\n", pvInstance, pvData, cbData));
|
---|
1907 |
|
---|
1908 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
1909 | Assert(p);
|
---|
1910 | Assert(p->pThis);
|
---|
1911 |
|
---|
1912 | /* Currently only a topdown BGR0 bitmap format is supported. */
|
---|
1913 | VRDEIMAGEBITMAP image;
|
---|
1914 |
|
---|
1915 | image.cWidth = p->w;
|
---|
1916 | image.cHeight = p->h;
|
---|
1917 | image.pvData = pvData;
|
---|
1918 | image.cbData = cbData;
|
---|
1919 | image.pvScanLine0 = (uint8_t *)pvData + (p->h - 1) * p->w * 4;
|
---|
1920 | image.iScanDelta = -4 * p->w;
|
---|
1921 |
|
---|
1922 | p->pThis->m_interfaceImage.VRDEImageUpdate (p->hImageBitmap,
|
---|
1923 | p->x,
|
---|
1924 | p->y,
|
---|
1925 | p->w,
|
---|
1926 | p->h,
|
---|
1927 | &image,
|
---|
1928 | sizeof(VRDEIMAGEBITMAP));
|
---|
1929 | }
|
---|
1930 |
|
---|
1931 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DOREnd(void *pvInstance)
|
---|
1932 | {
|
---|
1933 | LogFlowFunc(("ins %p\n", pvInstance));
|
---|
1934 |
|
---|
1935 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
1936 | Assert(p);
|
---|
1937 | Assert(p->pThis);
|
---|
1938 |
|
---|
1939 | p->pThis->m_interfaceImage.VRDEImageHandleClose(p->hImageBitmap);
|
---|
1940 |
|
---|
1941 | RTMemFree(p);
|
---|
1942 | }
|
---|
1943 |
|
---|
1944 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::H3DORContextProperty(const void *pvContext, uint32_t index,
|
---|
1945 | void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut)
|
---|
1946 | {
|
---|
1947 | int rc = VINF_SUCCESS;
|
---|
1948 |
|
---|
1949 | if (index == H3DOR_PROP_FORMATS)
|
---|
1950 | {
|
---|
1951 | /* Return a comma separated list of supported formats. */
|
---|
1952 | static const char *pszSupportedFormats = H3DOR_FMT_RGBA_TOPDOWN;
|
---|
1953 | uint32_t cbOut = (uint32_t)strlen(pszSupportedFormats) + 1;
|
---|
1954 | if (cbOut <= cbBuffer)
|
---|
1955 | {
|
---|
1956 | memcpy(pvBuffer, pszSupportedFormats, cbOut);
|
---|
1957 | }
|
---|
1958 | else
|
---|
1959 | {
|
---|
1960 | rc = VERR_BUFFER_OVERFLOW;
|
---|
1961 | }
|
---|
1962 | *pcbOut = cbOut;
|
---|
1963 | }
|
---|
1964 | else
|
---|
1965 | {
|
---|
1966 | rc = VERR_NOT_SUPPORTED;
|
---|
1967 | }
|
---|
1968 |
|
---|
1969 | return rc;
|
---|
1970 | }
|
---|
1971 |
|
---|
1972 | void ConsoleVRDPServer::remote3DRedirect(void)
|
---|
1973 | {
|
---|
1974 | if (!m_fInterfaceImage)
|
---|
1975 | {
|
---|
1976 | /* No redirect without corresponding interface. */
|
---|
1977 | return;
|
---|
1978 | }
|
---|
1979 |
|
---|
1980 | /* Check if 3D redirection has been enabled. */
|
---|
1981 | com::Bstr bstr;
|
---|
1982 | HRESULT hrc = mConsole->getVRDEServer()->GetVRDEProperty(Bstr("H3DRedirect/Enabled").raw(), bstr.asOutParam());
|
---|
1983 |
|
---|
1984 | if (hrc != S_OK)
|
---|
1985 | {
|
---|
1986 | bstr = "";
|
---|
1987 | }
|
---|
1988 |
|
---|
1989 | com::Utf8Str value = bstr;
|
---|
1990 |
|
---|
1991 | bool fEnabled = RTStrICmp(value.c_str(), "true") == 0
|
---|
1992 | || RTStrICmp(value.c_str(), "1") == 0;
|
---|
1993 |
|
---|
1994 | if (!fEnabled)
|
---|
1995 | {
|
---|
1996 | return;
|
---|
1997 | }
|
---|
1998 |
|
---|
1999 | /* Tell the host 3D service to redirect output using the ConsoleVRDPServer callbacks. */
|
---|
2000 | H3DOUTPUTREDIRECT outputRedirect =
|
---|
2001 | {
|
---|
2002 | this,
|
---|
2003 | H3DORBegin,
|
---|
2004 | H3DORGeometry,
|
---|
2005 | H3DORVisibleRegion,
|
---|
2006 | H3DORFrame,
|
---|
2007 | H3DOREnd,
|
---|
2008 | H3DORContextProperty
|
---|
2009 | };
|
---|
2010 |
|
---|
2011 | VBOXHGCMSVCPARM parm;
|
---|
2012 |
|
---|
2013 | parm.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2014 | parm.u.pointer.addr = &outputRedirect;
|
---|
2015 | parm.u.pointer.size = sizeof(outputRedirect);
|
---|
2016 |
|
---|
2017 | VMMDev *pVMMDev = mConsole->getVMMDev();
|
---|
2018 |
|
---|
2019 | if (!pVMMDev)
|
---|
2020 | {
|
---|
2021 | AssertMsgFailed(("remote3DRedirect no vmmdev\n"));
|
---|
2022 | return;
|
---|
2023 | }
|
---|
2024 |
|
---|
2025 | int rc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL",
|
---|
2026 | SHCRGL_HOST_FN_SET_OUTPUT_REDIRECT,
|
---|
2027 | SHCRGL_CPARMS_SET_OUTPUT_REDIRECT,
|
---|
2028 | &parm);
|
---|
2029 |
|
---|
2030 | if (!RT_SUCCESS(rc))
|
---|
2031 | {
|
---|
2032 | AssertMsgFailed(("SHCRGL_HOST_FN_SET_CONSOLE failed with %Rrc\n", rc));
|
---|
2033 | return;
|
---|
2034 | }
|
---|
2035 |
|
---|
2036 | LogRel(("VRDE: Enabled 3D redirect.\n"));
|
---|
2037 |
|
---|
2038 | return;
|
---|
2039 | }
|
---|
2040 |
|
---|
2041 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDEImageCbNotify (void *pvContext,
|
---|
2042 | void *pvUser,
|
---|
2043 | HVRDEIMAGE hVideo,
|
---|
2044 | uint32_t u32Id,
|
---|
2045 | void *pvData,
|
---|
2046 | uint32_t cbData)
|
---|
2047 | {
|
---|
2048 | LogFlowFunc(("pvContext %p, pvUser %p, hVideo %p, u32Id %u, pvData %p, cbData %d\n",
|
---|
2049 | pvContext, pvUser, hVideo, u32Id, pvData, cbData));
|
---|
2050 |
|
---|
2051 | ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2052 | H3DORInstance *p = (H3DORInstance *)pvUser;
|
---|
2053 | Assert(p);
|
---|
2054 | Assert(p->pThis);
|
---|
2055 | Assert(p->pThis == pServer);
|
---|
2056 |
|
---|
2057 | if (u32Id == VRDE_IMAGE_NOTIFY_HANDLE_CREATE)
|
---|
2058 | {
|
---|
2059 | if (cbData != sizeof(uint32_t))
|
---|
2060 | {
|
---|
2061 | AssertFailed();
|
---|
2062 | return VERR_INVALID_PARAMETER;
|
---|
2063 | }
|
---|
2064 |
|
---|
2065 | uint32_t u32StreamId = *(uint32_t *)pvData;
|
---|
2066 | LogFlowFunc(("VRDE_IMAGE_NOTIFY_HANDLE_CREATE u32StreamId %d\n",
|
---|
2067 | u32StreamId));
|
---|
2068 |
|
---|
2069 | if (u32StreamId != 0)
|
---|
2070 | {
|
---|
2071 | p->fCreated = true; // @todo not needed?
|
---|
2072 | }
|
---|
2073 | else
|
---|
2074 | {
|
---|
2075 | /* The stream has not been created. */
|
---|
2076 | }
|
---|
2077 | }
|
---|
2078 |
|
---|
2079 | return VINF_SUCCESS;
|
---|
2080 | }
|
---|
2081 |
|
---|
2082 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDESCardCbNotify(void *pvContext,
|
---|
2083 | uint32_t u32Id,
|
---|
2084 | void *pvData,
|
---|
2085 | uint32_t cbData)
|
---|
2086 | {
|
---|
2087 | #ifdef VBOX_WITH_USB_CARDREADER
|
---|
2088 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2089 | UsbCardReader *pReader = pThis->mConsole->getUsbCardReader();
|
---|
2090 | return pReader->VRDENotify(u32Id, pvData, cbData);
|
---|
2091 | #else
|
---|
2092 | NOREF(pvContext);
|
---|
2093 | NOREF(u32Id);
|
---|
2094 | NOREF(pvData);
|
---|
2095 | NOREF(cbData);
|
---|
2096 | return VERR_NOT_SUPPORTED;
|
---|
2097 | #endif
|
---|
2098 | }
|
---|
2099 |
|
---|
2100 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDESCardCbResponse(void *pvContext,
|
---|
2101 | int rcRequest,
|
---|
2102 | void *pvUser,
|
---|
2103 | uint32_t u32Function,
|
---|
2104 | void *pvData,
|
---|
2105 | uint32_t cbData)
|
---|
2106 | {
|
---|
2107 | #ifdef VBOX_WITH_USB_CARDREADER
|
---|
2108 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2109 | UsbCardReader *pReader = pThis->mConsole->getUsbCardReader();
|
---|
2110 | return pReader->VRDEResponse(rcRequest, pvUser, u32Function, pvData, cbData);
|
---|
2111 | #else
|
---|
2112 | NOREF(pvContext);
|
---|
2113 | NOREF(rcRequest);
|
---|
2114 | NOREF(pvUser);
|
---|
2115 | NOREF(u32Function);
|
---|
2116 | NOREF(pvData);
|
---|
2117 | NOREF(cbData);
|
---|
2118 | return VERR_NOT_SUPPORTED;
|
---|
2119 | #endif
|
---|
2120 | }
|
---|
2121 |
|
---|
2122 | int ConsoleVRDPServer::SCardRequest(void *pvUser, uint32_t u32Function, const void *pvData, uint32_t cbData)
|
---|
2123 | {
|
---|
2124 | int rc = VINF_SUCCESS;
|
---|
2125 |
|
---|
2126 | if (mhServer && mpEntryPoints && m_interfaceSCard.VRDESCardRequest)
|
---|
2127 | {
|
---|
2128 | rc = m_interfaceSCard.VRDESCardRequest(mhServer, pvUser, u32Function, pvData, cbData);
|
---|
2129 | }
|
---|
2130 | else
|
---|
2131 | {
|
---|
2132 | rc = VERR_NOT_SUPPORTED;
|
---|
2133 | }
|
---|
2134 |
|
---|
2135 | return rc;
|
---|
2136 | }
|
---|
2137 |
|
---|
2138 |
|
---|
2139 | struct TSMFHOSTCHCTX;
|
---|
2140 | struct TSMFVRDPCTX;
|
---|
2141 |
|
---|
2142 | typedef struct TSMFHOSTCHCTX
|
---|
2143 | {
|
---|
2144 | ConsoleVRDPServer *pThis;
|
---|
2145 |
|
---|
2146 | struct TSMFVRDPCTX *pVRDPCtx; /* NULL if no corresponding host channel context. */
|
---|
2147 |
|
---|
2148 | void *pvDataReceived;
|
---|
2149 | uint32_t cbDataReceived;
|
---|
2150 | uint32_t cbDataAllocated;
|
---|
2151 | } TSMFHOSTCHCTX;
|
---|
2152 |
|
---|
2153 | typedef struct TSMFVRDPCTX
|
---|
2154 | {
|
---|
2155 | ConsoleVRDPServer *pThis;
|
---|
2156 |
|
---|
2157 | VBOXHOSTCHANNELCALLBACKS *pCallbacks;
|
---|
2158 | void *pvCallbacks;
|
---|
2159 |
|
---|
2160 | TSMFHOSTCHCTX *pHostChCtx; /* NULL if no corresponding host channel context. */
|
---|
2161 |
|
---|
2162 | uint32_t u32ChannelHandle;
|
---|
2163 | } TSMFVRDPCTX;
|
---|
2164 |
|
---|
2165 | static int tsmfContextsAlloc(TSMFHOSTCHCTX **ppHostChCtx, TSMFVRDPCTX **ppVRDPCtx)
|
---|
2166 | {
|
---|
2167 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)RTMemAllocZ(sizeof(TSMFHOSTCHCTX));
|
---|
2168 | if (!pHostChCtx)
|
---|
2169 | {
|
---|
2170 | return VERR_NO_MEMORY;
|
---|
2171 | }
|
---|
2172 |
|
---|
2173 | TSMFVRDPCTX *pVRDPCtx = (TSMFVRDPCTX *)RTMemAllocZ(sizeof(TSMFVRDPCTX));
|
---|
2174 | if (!pVRDPCtx)
|
---|
2175 | {
|
---|
2176 | RTMemFree(pHostChCtx);
|
---|
2177 | return VERR_NO_MEMORY;
|
---|
2178 | }
|
---|
2179 |
|
---|
2180 | *ppHostChCtx = pHostChCtx;
|
---|
2181 | *ppVRDPCtx = pVRDPCtx;
|
---|
2182 | return VINF_SUCCESS;
|
---|
2183 | }
|
---|
2184 |
|
---|
2185 | int ConsoleVRDPServer::tsmfLock(void)
|
---|
2186 | {
|
---|
2187 | int rc = RTCritSectEnter(&mTSMFLock);
|
---|
2188 | AssertRC(rc);
|
---|
2189 | return rc;
|
---|
2190 | }
|
---|
2191 |
|
---|
2192 | void ConsoleVRDPServer::tsmfUnlock(void)
|
---|
2193 | {
|
---|
2194 | RTCritSectLeave(&mTSMFLock);
|
---|
2195 | }
|
---|
2196 |
|
---|
2197 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelAttach(void *pvProvider,
|
---|
2198 | void **ppvChannel,
|
---|
2199 | uint32_t u32Flags,
|
---|
2200 | VBOXHOSTCHANNELCALLBACKS *pCallbacks,
|
---|
2201 | void *pvCallbacks)
|
---|
2202 | {
|
---|
2203 | LogFlowFunc(("\n"));
|
---|
2204 |
|
---|
2205 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvProvider);
|
---|
2206 |
|
---|
2207 | /* Create 2 context structures: for the VRDP server and for the host service. */
|
---|
2208 | TSMFHOSTCHCTX *pHostChCtx = NULL;
|
---|
2209 | TSMFVRDPCTX *pVRDPCtx = NULL;
|
---|
2210 |
|
---|
2211 | int rc = tsmfContextsAlloc(&pHostChCtx, &pVRDPCtx);
|
---|
2212 | if (RT_FAILURE(rc))
|
---|
2213 | {
|
---|
2214 | return rc;
|
---|
2215 | }
|
---|
2216 |
|
---|
2217 | pHostChCtx->pThis = pThis;
|
---|
2218 | pHostChCtx->pVRDPCtx = pVRDPCtx;
|
---|
2219 |
|
---|
2220 | pVRDPCtx->pThis = pThis;
|
---|
2221 | pVRDPCtx->pCallbacks = pCallbacks;
|
---|
2222 | pVRDPCtx->pvCallbacks = pvCallbacks;
|
---|
2223 | pVRDPCtx->pHostChCtx = pHostChCtx;
|
---|
2224 |
|
---|
2225 | rc = pThis->m_interfaceTSMF.VRDETSMFChannelCreate(pThis->mhServer, pVRDPCtx, u32Flags);
|
---|
2226 |
|
---|
2227 | if (RT_SUCCESS(rc))
|
---|
2228 | {
|
---|
2229 | /* @todo contexts should be in a list for accounting. */
|
---|
2230 | *ppvChannel = pHostChCtx;
|
---|
2231 | }
|
---|
2232 | else
|
---|
2233 | {
|
---|
2234 | RTMemFree(pHostChCtx);
|
---|
2235 | RTMemFree(pVRDPCtx);
|
---|
2236 | }
|
---|
2237 |
|
---|
2238 | return rc;
|
---|
2239 | }
|
---|
2240 |
|
---|
2241 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::tsmfHostChannelDetach(void *pvChannel)
|
---|
2242 | {
|
---|
2243 | LogFlowFunc(("\n"));
|
---|
2244 |
|
---|
2245 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
|
---|
2246 | ConsoleVRDPServer *pThis = pHostChCtx->pThis;
|
---|
2247 |
|
---|
2248 | int rc = pThis->tsmfLock();
|
---|
2249 | if (RT_SUCCESS(rc))
|
---|
2250 | {
|
---|
2251 | bool fClose = false;
|
---|
2252 | uint32_t u32ChannelHandle = 0;
|
---|
2253 |
|
---|
2254 | if (pHostChCtx->pVRDPCtx)
|
---|
2255 | {
|
---|
2256 | /* There is still a VRDP context for this channel. */
|
---|
2257 | pHostChCtx->pVRDPCtx->pHostChCtx = NULL;
|
---|
2258 | u32ChannelHandle = pHostChCtx->pVRDPCtx->u32ChannelHandle;
|
---|
2259 | fClose = true;
|
---|
2260 | }
|
---|
2261 |
|
---|
2262 | pThis->tsmfUnlock();
|
---|
2263 |
|
---|
2264 | RTMemFree(pHostChCtx);
|
---|
2265 |
|
---|
2266 | if (fClose)
|
---|
2267 | {
|
---|
2268 | LogFlowFunc(("Closing VRDE channel %d.\n", u32ChannelHandle));
|
---|
2269 | pThis->m_interfaceTSMF.VRDETSMFChannelClose(pThis->mhServer, u32ChannelHandle);
|
---|
2270 | }
|
---|
2271 | else
|
---|
2272 | {
|
---|
2273 | LogFlowFunc(("No VRDE channel.\n"));
|
---|
2274 | }
|
---|
2275 | }
|
---|
2276 | }
|
---|
2277 |
|
---|
2278 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelSend(void *pvChannel,
|
---|
2279 | const void *pvData,
|
---|
2280 | uint32_t cbData)
|
---|
2281 | {
|
---|
2282 | LogFlowFunc(("cbData %d\n", cbData));
|
---|
2283 |
|
---|
2284 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
|
---|
2285 | ConsoleVRDPServer *pThis = pHostChCtx->pThis;
|
---|
2286 |
|
---|
2287 | int rc = pThis->tsmfLock();
|
---|
2288 | if (RT_SUCCESS(rc))
|
---|
2289 | {
|
---|
2290 | bool fSend = false;
|
---|
2291 | uint32_t u32ChannelHandle = 0;
|
---|
2292 |
|
---|
2293 | if (pHostChCtx->pVRDPCtx)
|
---|
2294 | {
|
---|
2295 | u32ChannelHandle = pHostChCtx->pVRDPCtx->u32ChannelHandle;
|
---|
2296 | fSend = true;
|
---|
2297 | }
|
---|
2298 |
|
---|
2299 | pThis->tsmfUnlock();
|
---|
2300 |
|
---|
2301 | if (fSend)
|
---|
2302 | {
|
---|
2303 | LogFlowFunc(("Send to VRDE channel %d.\n", u32ChannelHandle));
|
---|
2304 | rc = pThis->m_interfaceTSMF.VRDETSMFChannelSend(pThis->mhServer, u32ChannelHandle,
|
---|
2305 | pvData, cbData);
|
---|
2306 | }
|
---|
2307 | }
|
---|
2308 |
|
---|
2309 | return rc;
|
---|
2310 | }
|
---|
2311 |
|
---|
2312 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelRecv(void *pvChannel,
|
---|
2313 | void *pvData,
|
---|
2314 | uint32_t cbData,
|
---|
2315 | uint32_t *pcbReceived,
|
---|
2316 | uint32_t *pcbRemaining)
|
---|
2317 | {
|
---|
2318 | LogFlowFunc(("cbData %d\n", cbData));
|
---|
2319 |
|
---|
2320 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
|
---|
2321 | ConsoleVRDPServer *pThis = pHostChCtx->pThis;
|
---|
2322 |
|
---|
2323 | int rc = pThis->tsmfLock();
|
---|
2324 | if (RT_SUCCESS(rc))
|
---|
2325 | {
|
---|
2326 | uint32_t cbToCopy = RT_MIN(cbData, pHostChCtx->cbDataReceived);
|
---|
2327 | uint32_t cbRemaining = pHostChCtx->cbDataReceived - cbToCopy;
|
---|
2328 |
|
---|
2329 | LogFlowFunc(("cbToCopy %d, cbRemaining %d\n", cbToCopy, cbRemaining));
|
---|
2330 |
|
---|
2331 | if (cbToCopy != 0)
|
---|
2332 | {
|
---|
2333 | memcpy(pvData, pHostChCtx->pvDataReceived, cbToCopy);
|
---|
2334 |
|
---|
2335 | if (cbRemaining != 0)
|
---|
2336 | {
|
---|
2337 | memmove(pHostChCtx->pvDataReceived, (uint8_t *)pHostChCtx->pvDataReceived + cbToCopy, cbRemaining);
|
---|
2338 | }
|
---|
2339 |
|
---|
2340 | pHostChCtx->cbDataReceived = cbRemaining;
|
---|
2341 | }
|
---|
2342 |
|
---|
2343 | pThis->tsmfUnlock();
|
---|
2344 |
|
---|
2345 | *pcbRemaining = cbRemaining;
|
---|
2346 | *pcbReceived = cbToCopy;
|
---|
2347 | }
|
---|
2348 |
|
---|
2349 | return rc;
|
---|
2350 | }
|
---|
2351 |
|
---|
2352 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelControl(void *pvChannel,
|
---|
2353 | uint32_t u32Code,
|
---|
2354 | const void *pvParm,
|
---|
2355 | uint32_t cbParm,
|
---|
2356 | const void *pvData,
|
---|
2357 | uint32_t cbData,
|
---|
2358 | uint32_t *pcbDataReturned)
|
---|
2359 | {
|
---|
2360 | LogFlowFunc(("u32Code %u\n", u32Code));
|
---|
2361 |
|
---|
2362 | if (!pvChannel)
|
---|
2363 | {
|
---|
2364 | /* Special case, the provider must answer rather than a channel instance. */
|
---|
2365 | if (u32Code == VBOX_HOST_CHANNEL_CTRL_EXISTS)
|
---|
2366 | {
|
---|
2367 | *pcbDataReturned = 0;
|
---|
2368 | return VINF_SUCCESS;
|
---|
2369 | }
|
---|
2370 |
|
---|
2371 | return VERR_NOT_IMPLEMENTED;
|
---|
2372 | }
|
---|
2373 |
|
---|
2374 | /* Channels do not support this. */
|
---|
2375 | return VERR_NOT_IMPLEMENTED;
|
---|
2376 | }
|
---|
2377 |
|
---|
2378 |
|
---|
2379 | void ConsoleVRDPServer::setupTSMF(void)
|
---|
2380 | {
|
---|
2381 | if (m_interfaceTSMF.header.u64Size == 0)
|
---|
2382 | {
|
---|
2383 | return;
|
---|
2384 | }
|
---|
2385 |
|
---|
2386 | /* Register with the host channel service. */
|
---|
2387 | VBOXHOSTCHANNELINTERFACE hostChannelInterface =
|
---|
2388 | {
|
---|
2389 | this,
|
---|
2390 | tsmfHostChannelAttach,
|
---|
2391 | tsmfHostChannelDetach,
|
---|
2392 | tsmfHostChannelSend,
|
---|
2393 | tsmfHostChannelRecv,
|
---|
2394 | tsmfHostChannelControl
|
---|
2395 | };
|
---|
2396 |
|
---|
2397 | VBoxHostChannelHostRegister parms;
|
---|
2398 |
|
---|
2399 | static char szProviderName[] = "/vrde/tsmf";
|
---|
2400 |
|
---|
2401 | parms.name.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2402 | parms.name.u.pointer.addr = &szProviderName[0];
|
---|
2403 | parms.name.u.pointer.size = sizeof(szProviderName);
|
---|
2404 |
|
---|
2405 | parms.iface.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2406 | parms.iface.u.pointer.addr = &hostChannelInterface;
|
---|
2407 | parms.iface.u.pointer.size = sizeof(hostChannelInterface);
|
---|
2408 |
|
---|
2409 | VMMDev *pVMMDev = mConsole->getVMMDev();
|
---|
2410 |
|
---|
2411 | if (!pVMMDev)
|
---|
2412 | {
|
---|
2413 | AssertMsgFailed(("setupTSMF no vmmdev\n"));
|
---|
2414 | return;
|
---|
2415 | }
|
---|
2416 |
|
---|
2417 | int rc = pVMMDev->hgcmHostCall("VBoxHostChannel",
|
---|
2418 | VBOX_HOST_CHANNEL_HOST_FN_REGISTER,
|
---|
2419 | 2,
|
---|
2420 | &parms.name);
|
---|
2421 |
|
---|
2422 | if (!RT_SUCCESS(rc))
|
---|
2423 | {
|
---|
2424 | Log(("VBOX_HOST_CHANNEL_HOST_FN_REGISTER failed with %Rrc\n", rc));
|
---|
2425 | return;
|
---|
2426 | }
|
---|
2427 |
|
---|
2428 | LogRel(("VRDE: Enabled TSMF channel.\n"));
|
---|
2429 |
|
---|
2430 | return;
|
---|
2431 | }
|
---|
2432 |
|
---|
2433 | /* @todo these defines must be in a header, which is used by guest component as well. */
|
---|
2434 | #define VBOX_TSMF_HCH_CREATE_ACCEPTED (VBOX_HOST_CHANNEL_EVENT_USER + 0)
|
---|
2435 | #define VBOX_TSMF_HCH_CREATE_DECLINED (VBOX_HOST_CHANNEL_EVENT_USER + 1)
|
---|
2436 | #define VBOX_TSMF_HCH_DISCONNECTED (VBOX_HOST_CHANNEL_EVENT_USER + 2)
|
---|
2437 |
|
---|
2438 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDETSMFCbNotify(void *pvContext,
|
---|
2439 | uint32_t u32Notification,
|
---|
2440 | void *pvChannel,
|
---|
2441 | const void *pvParm,
|
---|
2442 | uint32_t cbParm)
|
---|
2443 | {
|
---|
2444 | int rc = VINF_SUCCESS;
|
---|
2445 |
|
---|
2446 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2447 |
|
---|
2448 | TSMFVRDPCTX *pVRDPCtx = (TSMFVRDPCTX *)pvChannel;
|
---|
2449 |
|
---|
2450 | Assert(pVRDPCtx->pThis == pThis);
|
---|
2451 |
|
---|
2452 | if (pVRDPCtx->pCallbacks == NULL)
|
---|
2453 | {
|
---|
2454 | LogFlowFunc(("tsmfHostChannel: Channel disconnected. Skipping.\n"));
|
---|
2455 | return;
|
---|
2456 | }
|
---|
2457 |
|
---|
2458 | switch (u32Notification)
|
---|
2459 | {
|
---|
2460 | case VRDE_TSMF_N_CREATE_ACCEPTED:
|
---|
2461 | {
|
---|
2462 | VRDETSMFNOTIFYCREATEACCEPTED *p = (VRDETSMFNOTIFYCREATEACCEPTED *)pvParm;
|
---|
2463 | Assert(cbParm == sizeof(VRDETSMFNOTIFYCREATEACCEPTED));
|
---|
2464 |
|
---|
2465 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_CREATE_ACCEPTED(%p): p->u32ChannelHandle %d\n",
|
---|
2466 | pVRDPCtx, p->u32ChannelHandle));
|
---|
2467 |
|
---|
2468 | pVRDPCtx->u32ChannelHandle = p->u32ChannelHandle;
|
---|
2469 |
|
---|
2470 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2471 | VBOX_TSMF_HCH_CREATE_ACCEPTED,
|
---|
2472 | NULL, 0);
|
---|
2473 | } break;
|
---|
2474 |
|
---|
2475 | case VRDE_TSMF_N_CREATE_DECLINED:
|
---|
2476 | {
|
---|
2477 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_CREATE_DECLINED(%p)\n", pVRDPCtx));
|
---|
2478 |
|
---|
2479 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2480 | VBOX_TSMF_HCH_CREATE_DECLINED,
|
---|
2481 | NULL, 0);
|
---|
2482 | } break;
|
---|
2483 |
|
---|
2484 | case VRDE_TSMF_N_DATA:
|
---|
2485 | {
|
---|
2486 | /* Save the data in the intermediate buffer and send the event. */
|
---|
2487 | VRDETSMFNOTIFYDATA *p = (VRDETSMFNOTIFYDATA *)pvParm;
|
---|
2488 | Assert(cbParm == sizeof(VRDETSMFNOTIFYDATA));
|
---|
2489 |
|
---|
2490 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DATA(%p): p->cbData %d\n", pVRDPCtx, p->cbData));
|
---|
2491 |
|
---|
2492 | VBOXHOSTCHANNELEVENTRECV ev;
|
---|
2493 | ev.u32SizeAvailable = 0;
|
---|
2494 |
|
---|
2495 | rc = pThis->tsmfLock();
|
---|
2496 |
|
---|
2497 | if (RT_SUCCESS(rc))
|
---|
2498 | {
|
---|
2499 | TSMFHOSTCHCTX *pHostChCtx = pVRDPCtx->pHostChCtx;
|
---|
2500 |
|
---|
2501 | if (pHostChCtx)
|
---|
2502 | {
|
---|
2503 | if (pHostChCtx->pvDataReceived)
|
---|
2504 | {
|
---|
2505 | uint32_t cbAlloc = p->cbData + pHostChCtx->cbDataReceived;
|
---|
2506 | pHostChCtx->pvDataReceived = RTMemRealloc(pHostChCtx->pvDataReceived, cbAlloc);
|
---|
2507 | memcpy((uint8_t *)pHostChCtx->pvDataReceived + pHostChCtx->cbDataReceived, p->pvData, p->cbData);
|
---|
2508 |
|
---|
2509 | pHostChCtx->cbDataReceived += p->cbData;
|
---|
2510 | pHostChCtx->cbDataAllocated = cbAlloc;
|
---|
2511 | }
|
---|
2512 | else
|
---|
2513 | {
|
---|
2514 | pHostChCtx->pvDataReceived = RTMemAlloc(p->cbData);
|
---|
2515 | memcpy(pHostChCtx->pvDataReceived, p->pvData, p->cbData);
|
---|
2516 |
|
---|
2517 | pHostChCtx->cbDataReceived = p->cbData;
|
---|
2518 | pHostChCtx->cbDataAllocated = p->cbData;
|
---|
2519 | }
|
---|
2520 |
|
---|
2521 | ev.u32SizeAvailable = p->cbData;
|
---|
2522 | }
|
---|
2523 | else
|
---|
2524 | {
|
---|
2525 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DATA: no host channel. Skipping\n"));
|
---|
2526 | }
|
---|
2527 |
|
---|
2528 | pThis->tsmfUnlock();
|
---|
2529 | }
|
---|
2530 |
|
---|
2531 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2532 | VBOX_HOST_CHANNEL_EVENT_RECV,
|
---|
2533 | &ev, sizeof(ev));
|
---|
2534 | } break;
|
---|
2535 |
|
---|
2536 | case VRDE_TSMF_N_DISCONNECTED:
|
---|
2537 | {
|
---|
2538 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DISCONNECTED(%p)\n", pVRDPCtx));
|
---|
2539 |
|
---|
2540 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2541 | VBOX_TSMF_HCH_DISCONNECTED,
|
---|
2542 | NULL, 0);
|
---|
2543 |
|
---|
2544 | /* The callback context will not be used anymore. */
|
---|
2545 | pVRDPCtx->pCallbacks->HostChannelCallbackDeleted(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx);
|
---|
2546 | pVRDPCtx->pCallbacks = NULL;
|
---|
2547 | pVRDPCtx->pvCallbacks = NULL;
|
---|
2548 |
|
---|
2549 | rc = pThis->tsmfLock();
|
---|
2550 | if (RT_SUCCESS(rc))
|
---|
2551 | {
|
---|
2552 | if (pVRDPCtx->pHostChCtx)
|
---|
2553 | {
|
---|
2554 | /* There is still a host channel context for this channel. */
|
---|
2555 | pVRDPCtx->pHostChCtx->pVRDPCtx = NULL;
|
---|
2556 | }
|
---|
2557 |
|
---|
2558 | pThis->tsmfUnlock();
|
---|
2559 |
|
---|
2560 | memset(pVRDPCtx, 0, sizeof(*pVRDPCtx));
|
---|
2561 | RTMemFree(pVRDPCtx);
|
---|
2562 | }
|
---|
2563 | } break;
|
---|
2564 |
|
---|
2565 | default:
|
---|
2566 | {
|
---|
2567 | AssertFailed();
|
---|
2568 | } break;
|
---|
2569 | }
|
---|
2570 | }
|
---|
2571 |
|
---|
2572 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInNotify(void *pvCallback,
|
---|
2573 | uint32_t u32Id,
|
---|
2574 | const void *pvData,
|
---|
2575 | uint32_t cbData)
|
---|
2576 | {
|
---|
2577 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
2578 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2579 | EmWebcam *pWebcam = pThis->mConsole->getEmWebcam();
|
---|
2580 | pWebcam->EmWebcamCbNotify(u32Id, pvData, cbData);
|
---|
2581 | #else
|
---|
2582 | NOREF(pvCallback);
|
---|
2583 | NOREF(u32Id);
|
---|
2584 | NOREF(pvData);
|
---|
2585 | NOREF(cbData);
|
---|
2586 | #endif
|
---|
2587 | }
|
---|
2588 |
|
---|
2589 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInDeviceDesc(void *pvCallback,
|
---|
2590 | int rcRequest,
|
---|
2591 | void *pDeviceCtx,
|
---|
2592 | void *pvUser,
|
---|
2593 | const VRDEVIDEOINDEVICEDESC *pDeviceDesc,
|
---|
2594 | uint32_t cbDevice)
|
---|
2595 | {
|
---|
2596 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
2597 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2598 | EmWebcam *pWebcam = pThis->mConsole->getEmWebcam();
|
---|
2599 | pWebcam->EmWebcamCbDeviceDesc(rcRequest, pDeviceCtx, pvUser, pDeviceDesc, cbDevice);
|
---|
2600 | #else
|
---|
2601 | NOREF(pvCallback);
|
---|
2602 | NOREF(rcRequest);
|
---|
2603 | NOREF(pDeviceCtx);
|
---|
2604 | NOREF(pvUser);
|
---|
2605 | NOREF(pDeviceDesc);
|
---|
2606 | NOREF(cbDevice);
|
---|
2607 | #endif
|
---|
2608 | }
|
---|
2609 |
|
---|
2610 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInControl(void *pvCallback,
|
---|
2611 | int rcRequest,
|
---|
2612 | void *pDeviceCtx,
|
---|
2613 | void *pvUser,
|
---|
2614 | const VRDEVIDEOINCTRLHDR *pControl,
|
---|
2615 | uint32_t cbControl)
|
---|
2616 | {
|
---|
2617 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
2618 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2619 | EmWebcam *pWebcam = pThis->mConsole->getEmWebcam();
|
---|
2620 | pWebcam->EmWebcamCbControl(rcRequest, pDeviceCtx, pvUser, pControl, cbControl);
|
---|
2621 | #else
|
---|
2622 | NOREF(pvCallback);
|
---|
2623 | NOREF(rcRequest);
|
---|
2624 | NOREF(pDeviceCtx);
|
---|
2625 | NOREF(pvUser);
|
---|
2626 | NOREF(pControl);
|
---|
2627 | NOREF(cbControl);
|
---|
2628 | #endif
|
---|
2629 | }
|
---|
2630 |
|
---|
2631 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInFrame(void *pvCallback,
|
---|
2632 | int rcRequest,
|
---|
2633 | void *pDeviceCtx,
|
---|
2634 | const VRDEVIDEOINPAYLOADHDR *pFrame,
|
---|
2635 | uint32_t cbFrame)
|
---|
2636 | {
|
---|
2637 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
2638 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2639 | EmWebcam *pWebcam = pThis->mConsole->getEmWebcam();
|
---|
2640 | pWebcam->EmWebcamCbFrame(rcRequest, pDeviceCtx, pFrame, cbFrame);
|
---|
2641 | #else
|
---|
2642 | NOREF(pvCallback);
|
---|
2643 | NOREF(rcRequest);
|
---|
2644 | NOREF(pDeviceCtx);
|
---|
2645 | NOREF(pFrame);
|
---|
2646 | NOREF(cbFrame);
|
---|
2647 | #endif
|
---|
2648 | }
|
---|
2649 |
|
---|
2650 | int ConsoleVRDPServer::VideoInDeviceAttach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle, void *pvDeviceCtx)
|
---|
2651 | {
|
---|
2652 | int rc;
|
---|
2653 |
|
---|
2654 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInDeviceAttach)
|
---|
2655 | {
|
---|
2656 | rc = m_interfaceVideoIn.VRDEVideoInDeviceAttach(mhServer, pDeviceHandle, pvDeviceCtx);
|
---|
2657 | }
|
---|
2658 | else
|
---|
2659 | {
|
---|
2660 | rc = VERR_NOT_SUPPORTED;
|
---|
2661 | }
|
---|
2662 |
|
---|
2663 | return rc;
|
---|
2664 | }
|
---|
2665 |
|
---|
2666 | int ConsoleVRDPServer::VideoInDeviceDetach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle)
|
---|
2667 | {
|
---|
2668 | int rc;
|
---|
2669 |
|
---|
2670 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInDeviceDetach)
|
---|
2671 | {
|
---|
2672 | rc = m_interfaceVideoIn.VRDEVideoInDeviceDetach(mhServer, pDeviceHandle);
|
---|
2673 | }
|
---|
2674 | else
|
---|
2675 | {
|
---|
2676 | rc = VERR_NOT_SUPPORTED;
|
---|
2677 | }
|
---|
2678 |
|
---|
2679 | return rc;
|
---|
2680 | }
|
---|
2681 |
|
---|
2682 | int ConsoleVRDPServer::VideoInGetDeviceDesc(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle)
|
---|
2683 | {
|
---|
2684 | int rc;
|
---|
2685 |
|
---|
2686 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInGetDeviceDesc)
|
---|
2687 | {
|
---|
2688 | rc = m_interfaceVideoIn.VRDEVideoInGetDeviceDesc(mhServer, pvUser, pDeviceHandle);
|
---|
2689 | }
|
---|
2690 | else
|
---|
2691 | {
|
---|
2692 | rc = VERR_NOT_SUPPORTED;
|
---|
2693 | }
|
---|
2694 |
|
---|
2695 | return rc;
|
---|
2696 | }
|
---|
2697 |
|
---|
2698 | int ConsoleVRDPServer::VideoInControl(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle,
|
---|
2699 | const VRDEVIDEOINCTRLHDR *pReq, uint32_t cbReq)
|
---|
2700 | {
|
---|
2701 | int rc;
|
---|
2702 |
|
---|
2703 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInControl)
|
---|
2704 | {
|
---|
2705 | rc = m_interfaceVideoIn.VRDEVideoInControl(mhServer, pvUser, pDeviceHandle, pReq, cbReq);
|
---|
2706 | }
|
---|
2707 | else
|
---|
2708 | {
|
---|
2709 | rc = VERR_NOT_SUPPORTED;
|
---|
2710 | }
|
---|
2711 |
|
---|
2712 | return rc;
|
---|
2713 | }
|
---|
2714 |
|
---|
2715 | void ConsoleVRDPServer::EnableConnections(void)
|
---|
2716 | {
|
---|
2717 | if (mpEntryPoints && mhServer)
|
---|
2718 | {
|
---|
2719 | mpEntryPoints->VRDEEnableConnections(mhServer, true);
|
---|
2720 |
|
---|
2721 | /* Redirect 3D output if it is enabled. */
|
---|
2722 | remote3DRedirect();
|
---|
2723 |
|
---|
2724 | /* Setup the generic TSMF channel. */
|
---|
2725 | setupTSMF();
|
---|
2726 | }
|
---|
2727 | }
|
---|
2728 |
|
---|
2729 | void ConsoleVRDPServer::DisconnectClient(uint32_t u32ClientId, bool fReconnect)
|
---|
2730 | {
|
---|
2731 | if (mpEntryPoints && mhServer)
|
---|
2732 | {
|
---|
2733 | mpEntryPoints->VRDEDisconnect(mhServer, u32ClientId, fReconnect);
|
---|
2734 | }
|
---|
2735 | }
|
---|
2736 |
|
---|
2737 | int ConsoleVRDPServer::MousePointer(BOOL alpha,
|
---|
2738 | ULONG xHot,
|
---|
2739 | ULONG yHot,
|
---|
2740 | ULONG width,
|
---|
2741 | ULONG height,
|
---|
2742 | const uint8_t *pu8Shape)
|
---|
2743 | {
|
---|
2744 | int rc = VINF_SUCCESS;
|
---|
2745 |
|
---|
2746 | if (mhServer && mpEntryPoints && m_interfaceMousePtr.VRDEMousePtr)
|
---|
2747 | {
|
---|
2748 | size_t cbMask = (((width + 7) / 8) * height + 3) & ~3;
|
---|
2749 | size_t cbData = width * height * 4;
|
---|
2750 |
|
---|
2751 | size_t cbDstMask = alpha? 0: cbMask;
|
---|
2752 |
|
---|
2753 | size_t cbPointer = sizeof(VRDEMOUSEPTRDATA) + cbDstMask + cbData;
|
---|
2754 | uint8_t *pu8Pointer = (uint8_t *)RTMemAlloc(cbPointer);
|
---|
2755 | if (pu8Pointer != NULL)
|
---|
2756 | {
|
---|
2757 | VRDEMOUSEPTRDATA *pPointer = (VRDEMOUSEPTRDATA *)pu8Pointer;
|
---|
2758 |
|
---|
2759 | pPointer->u16HotX = (uint16_t)xHot;
|
---|
2760 | pPointer->u16HotY = (uint16_t)yHot;
|
---|
2761 | pPointer->u16Width = (uint16_t)width;
|
---|
2762 | pPointer->u16Height = (uint16_t)height;
|
---|
2763 | pPointer->u16MaskLen = (uint16_t)cbDstMask;
|
---|
2764 | pPointer->u32DataLen = (uint32_t)cbData;
|
---|
2765 |
|
---|
2766 | /* AND mask. */
|
---|
2767 | uint8_t *pu8Mask = pu8Pointer + sizeof(VRDEMOUSEPTRDATA);
|
---|
2768 | if (cbDstMask)
|
---|
2769 | {
|
---|
2770 | memcpy(pu8Mask, pu8Shape, cbDstMask);
|
---|
2771 | }
|
---|
2772 |
|
---|
2773 | /* XOR mask */
|
---|
2774 | uint8_t *pu8Data = pu8Mask + pPointer->u16MaskLen;
|
---|
2775 | memcpy(pu8Data, pu8Shape + cbMask, cbData);
|
---|
2776 |
|
---|
2777 | m_interfaceMousePtr.VRDEMousePtr(mhServer, pPointer);
|
---|
2778 |
|
---|
2779 | RTMemFree(pu8Pointer);
|
---|
2780 | }
|
---|
2781 | else
|
---|
2782 | {
|
---|
2783 | rc = VERR_NO_MEMORY;
|
---|
2784 | }
|
---|
2785 | }
|
---|
2786 | else
|
---|
2787 | {
|
---|
2788 | rc = VERR_NOT_SUPPORTED;
|
---|
2789 | }
|
---|
2790 |
|
---|
2791 | return rc;
|
---|
2792 | }
|
---|
2793 |
|
---|
2794 | void ConsoleVRDPServer::MousePointerUpdate(const VRDECOLORPOINTER *pPointer)
|
---|
2795 | {
|
---|
2796 | if (mpEntryPoints && mhServer)
|
---|
2797 | {
|
---|
2798 | mpEntryPoints->VRDEColorPointer(mhServer, pPointer);
|
---|
2799 | }
|
---|
2800 | }
|
---|
2801 |
|
---|
2802 | void ConsoleVRDPServer::MousePointerHide(void)
|
---|
2803 | {
|
---|
2804 | if (mpEntryPoints && mhServer)
|
---|
2805 | {
|
---|
2806 | mpEntryPoints->VRDEHidePointer(mhServer);
|
---|
2807 | }
|
---|
2808 | }
|
---|
2809 |
|
---|
2810 | void ConsoleVRDPServer::Stop(void)
|
---|
2811 | {
|
---|
2812 | Assert(VALID_PTR(this)); /** @todo r=bird: there are(/was) some odd cases where this buster was invalid on
|
---|
2813 | * linux. Just remove this when it's 100% sure that problem has been fixed. */
|
---|
2814 | if (mhServer)
|
---|
2815 | {
|
---|
2816 | HVRDESERVER hServer = mhServer;
|
---|
2817 |
|
---|
2818 | /* Reset the handle to avoid further calls to the server. */
|
---|
2819 | mhServer = 0;
|
---|
2820 |
|
---|
2821 | if (mpEntryPoints && hServer)
|
---|
2822 | {
|
---|
2823 | mpEntryPoints->VRDEDestroy(hServer);
|
---|
2824 | }
|
---|
2825 | }
|
---|
2826 |
|
---|
2827 | #ifdef VBOX_WITH_USB
|
---|
2828 | remoteUSBThreadStop();
|
---|
2829 | #endif /* VBOX_WITH_USB */
|
---|
2830 |
|
---|
2831 | mpfnAuthEntry = NULL;
|
---|
2832 | mpfnAuthEntry2 = NULL;
|
---|
2833 | mpfnAuthEntry3 = NULL;
|
---|
2834 |
|
---|
2835 | if (mAuthLibrary)
|
---|
2836 | {
|
---|
2837 | RTLdrClose(mAuthLibrary);
|
---|
2838 | mAuthLibrary = 0;
|
---|
2839 | }
|
---|
2840 | }
|
---|
2841 |
|
---|
2842 | /* Worker thread for Remote USB. The thread polls the clients for
|
---|
2843 | * the list of attached USB devices.
|
---|
2844 | * The thread is also responsible for attaching/detaching devices
|
---|
2845 | * to/from the VM.
|
---|
2846 | *
|
---|
2847 | * It is expected that attaching/detaching is not a frequent operation.
|
---|
2848 | *
|
---|
2849 | * The thread is always running when the VRDP server is active.
|
---|
2850 | *
|
---|
2851 | * The thread scans backends and requests the device list every 2 seconds.
|
---|
2852 | *
|
---|
2853 | * When device list is available, the thread calls the Console to process it.
|
---|
2854 | *
|
---|
2855 | */
|
---|
2856 | #define VRDP_DEVICE_LIST_PERIOD_MS (2000)
|
---|
2857 |
|
---|
2858 | #ifdef VBOX_WITH_USB
|
---|
2859 | static DECLCALLBACK(int) threadRemoteUSB(RTTHREAD self, void *pvUser)
|
---|
2860 | {
|
---|
2861 | ConsoleVRDPServer *pOwner = (ConsoleVRDPServer *)pvUser;
|
---|
2862 |
|
---|
2863 | LogFlow(("Console::threadRemoteUSB: start. owner = %p.\n", pOwner));
|
---|
2864 |
|
---|
2865 | pOwner->notifyRemoteUSBThreadRunning(self);
|
---|
2866 |
|
---|
2867 | while (pOwner->isRemoteUSBThreadRunning())
|
---|
2868 | {
|
---|
2869 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
2870 |
|
---|
2871 | while ((pRemoteUSBBackend = pOwner->usbBackendGetNext(pRemoteUSBBackend)) != NULL)
|
---|
2872 | {
|
---|
2873 | pRemoteUSBBackend->PollRemoteDevices();
|
---|
2874 | }
|
---|
2875 |
|
---|
2876 | pOwner->waitRemoteUSBThreadEvent(VRDP_DEVICE_LIST_PERIOD_MS);
|
---|
2877 |
|
---|
2878 | LogFlow(("Console::threadRemoteUSB: iteration. owner = %p.\n", pOwner));
|
---|
2879 | }
|
---|
2880 |
|
---|
2881 | return VINF_SUCCESS;
|
---|
2882 | }
|
---|
2883 |
|
---|
2884 | void ConsoleVRDPServer::notifyRemoteUSBThreadRunning(RTTHREAD thread)
|
---|
2885 | {
|
---|
2886 | mUSBBackends.thread = thread;
|
---|
2887 | mUSBBackends.fThreadRunning = true;
|
---|
2888 | int rc = RTThreadUserSignal(thread);
|
---|
2889 | AssertRC(rc);
|
---|
2890 | }
|
---|
2891 |
|
---|
2892 | bool ConsoleVRDPServer::isRemoteUSBThreadRunning(void)
|
---|
2893 | {
|
---|
2894 | return mUSBBackends.fThreadRunning;
|
---|
2895 | }
|
---|
2896 |
|
---|
2897 | void ConsoleVRDPServer::waitRemoteUSBThreadEvent(RTMSINTERVAL cMillies)
|
---|
2898 | {
|
---|
2899 | int rc = RTSemEventWait(mUSBBackends.event, cMillies);
|
---|
2900 | Assert(RT_SUCCESS(rc) || rc == VERR_TIMEOUT);
|
---|
2901 | NOREF(rc);
|
---|
2902 | }
|
---|
2903 |
|
---|
2904 | void ConsoleVRDPServer::remoteUSBThreadStart(void)
|
---|
2905 | {
|
---|
2906 | int rc = RTSemEventCreate(&mUSBBackends.event);
|
---|
2907 |
|
---|
2908 | if (RT_FAILURE(rc))
|
---|
2909 | {
|
---|
2910 | AssertFailed();
|
---|
2911 | mUSBBackends.event = 0;
|
---|
2912 | }
|
---|
2913 |
|
---|
2914 | if (RT_SUCCESS(rc))
|
---|
2915 | {
|
---|
2916 | rc = RTThreadCreate(&mUSBBackends.thread, threadRemoteUSB, this, 65536,
|
---|
2917 | RTTHREADTYPE_VRDP_IO, RTTHREADFLAGS_WAITABLE, "remote usb");
|
---|
2918 | }
|
---|
2919 |
|
---|
2920 | if (RT_FAILURE(rc))
|
---|
2921 | {
|
---|
2922 | LogRel(("Warning: could not start the remote USB thread, rc = %Rrc!!!\n", rc));
|
---|
2923 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
2924 | }
|
---|
2925 | else
|
---|
2926 | {
|
---|
2927 | /* Wait until the thread is ready. */
|
---|
2928 | rc = RTThreadUserWait(mUSBBackends.thread, 60000);
|
---|
2929 | AssertRC(rc);
|
---|
2930 | Assert (mUSBBackends.fThreadRunning || RT_FAILURE(rc));
|
---|
2931 | }
|
---|
2932 | }
|
---|
2933 |
|
---|
2934 | void ConsoleVRDPServer::remoteUSBThreadStop(void)
|
---|
2935 | {
|
---|
2936 | mUSBBackends.fThreadRunning = false;
|
---|
2937 |
|
---|
2938 | if (mUSBBackends.thread != NIL_RTTHREAD)
|
---|
2939 | {
|
---|
2940 | Assert (mUSBBackends.event != 0);
|
---|
2941 |
|
---|
2942 | RTSemEventSignal(mUSBBackends.event);
|
---|
2943 |
|
---|
2944 | int rc = RTThreadWait(mUSBBackends.thread, 60000, NULL);
|
---|
2945 | AssertRC(rc);
|
---|
2946 |
|
---|
2947 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
2948 | }
|
---|
2949 |
|
---|
2950 | if (mUSBBackends.event)
|
---|
2951 | {
|
---|
2952 | RTSemEventDestroy(mUSBBackends.event);
|
---|
2953 | mUSBBackends.event = 0;
|
---|
2954 | }
|
---|
2955 | }
|
---|
2956 | #endif /* VBOX_WITH_USB */
|
---|
2957 |
|
---|
2958 | typedef struct AuthCtx
|
---|
2959 | {
|
---|
2960 | AuthResult result;
|
---|
2961 |
|
---|
2962 | PAUTHENTRY3 pfnAuthEntry3;
|
---|
2963 | PAUTHENTRY2 pfnAuthEntry2;
|
---|
2964 | PAUTHENTRY pfnAuthEntry;
|
---|
2965 |
|
---|
2966 | const char *pszCaller;
|
---|
2967 | PAUTHUUID pUuid;
|
---|
2968 | AuthGuestJudgement guestJudgement;
|
---|
2969 | const char *pszUser;
|
---|
2970 | const char *pszPassword;
|
---|
2971 | const char *pszDomain;
|
---|
2972 | int fLogon;
|
---|
2973 | unsigned clientId;
|
---|
2974 | } AuthCtx;
|
---|
2975 |
|
---|
2976 | static DECLCALLBACK(int) authThread(RTTHREAD self, void *pvUser)
|
---|
2977 | {
|
---|
2978 | AuthCtx *pCtx = (AuthCtx *)pvUser;
|
---|
2979 |
|
---|
2980 | if (pCtx->pfnAuthEntry3)
|
---|
2981 | {
|
---|
2982 | pCtx->result = pCtx->pfnAuthEntry3(pCtx->pszCaller, pCtx->pUuid, pCtx->guestJudgement,
|
---|
2983 | pCtx->pszUser, pCtx->pszPassword, pCtx->pszDomain,
|
---|
2984 | pCtx->fLogon, pCtx->clientId);
|
---|
2985 | }
|
---|
2986 | else if (pCtx->pfnAuthEntry2)
|
---|
2987 | {
|
---|
2988 | pCtx->result = pCtx->pfnAuthEntry2(pCtx->pUuid, pCtx->guestJudgement,
|
---|
2989 | pCtx->pszUser, pCtx->pszPassword, pCtx->pszDomain,
|
---|
2990 | pCtx->fLogon, pCtx->clientId);
|
---|
2991 | }
|
---|
2992 | else if (pCtx->pfnAuthEntry)
|
---|
2993 | {
|
---|
2994 | pCtx->result = pCtx->pfnAuthEntry(pCtx->pUuid, pCtx->guestJudgement,
|
---|
2995 | pCtx->pszUser, pCtx->pszPassword, pCtx->pszDomain);
|
---|
2996 | }
|
---|
2997 | return VINF_SUCCESS;
|
---|
2998 | }
|
---|
2999 |
|
---|
3000 | static AuthResult authCall(AuthCtx *pCtx)
|
---|
3001 | {
|
---|
3002 | AuthResult result = AuthResultAccessDenied;
|
---|
3003 |
|
---|
3004 | /* Use a separate thread because external modules might need a lot of stack space. */
|
---|
3005 | RTTHREAD thread = NIL_RTTHREAD;
|
---|
3006 | int rc = RTThreadCreate(&thread, authThread, pCtx, 512*_1K,
|
---|
3007 | RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "VRDEAuth");
|
---|
3008 | LogFlow(("authCall: RTThreadCreate %Rrc\n", rc));
|
---|
3009 |
|
---|
3010 | if (RT_SUCCESS(rc))
|
---|
3011 | {
|
---|
3012 | rc = RTThreadWait(thread, RT_INDEFINITE_WAIT, NULL);
|
---|
3013 | LogFlow(("authCall: RTThreadWait %Rrc\n", rc));
|
---|
3014 | }
|
---|
3015 |
|
---|
3016 | if (RT_SUCCESS(rc))
|
---|
3017 | {
|
---|
3018 | /* Only update the result if the thread finished without errors. */
|
---|
3019 | result = pCtx->result;
|
---|
3020 | }
|
---|
3021 | else
|
---|
3022 | {
|
---|
3023 | LogRel(("AUTH: unable to execute the auth thread %Rrc\n", rc));
|
---|
3024 | }
|
---|
3025 |
|
---|
3026 | return result;
|
---|
3027 | }
|
---|
3028 |
|
---|
3029 | AuthResult ConsoleVRDPServer::Authenticate(const Guid &uuid, AuthGuestJudgement guestJudgement,
|
---|
3030 | const char *pszUser, const char *pszPassword, const char *pszDomain,
|
---|
3031 | uint32_t u32ClientId)
|
---|
3032 | {
|
---|
3033 | AUTHUUID rawuuid;
|
---|
3034 |
|
---|
3035 | memcpy(rawuuid, uuid.raw(), sizeof(rawuuid));
|
---|
3036 |
|
---|
3037 | LogFlow(("ConsoleVRDPServer::Authenticate: uuid = %RTuuid, guestJudgement = %d, pszUser = %s, pszPassword = %s, pszDomain = %s, u32ClientId = %d\n",
|
---|
3038 | rawuuid, guestJudgement, pszUser, pszPassword, pszDomain, u32ClientId));
|
---|
3039 |
|
---|
3040 | /*
|
---|
3041 | * Called only from VRDP input thread. So thread safety is not required.
|
---|
3042 | */
|
---|
3043 |
|
---|
3044 | if (!mAuthLibrary)
|
---|
3045 | {
|
---|
3046 | /* Load the external authentication library. */
|
---|
3047 | Bstr authLibrary;
|
---|
3048 | mConsole->getVRDEServer()->COMGETTER(AuthLibrary)(authLibrary.asOutParam());
|
---|
3049 |
|
---|
3050 | Utf8Str filename = authLibrary;
|
---|
3051 |
|
---|
3052 | LogRel(("AUTH: loading external authentication library '%ls'\n", authLibrary.raw()));
|
---|
3053 |
|
---|
3054 | int rc;
|
---|
3055 | if (RTPathHavePath(filename.c_str()))
|
---|
3056 | rc = RTLdrLoad(filename.c_str(), &mAuthLibrary);
|
---|
3057 | else
|
---|
3058 | {
|
---|
3059 | rc = RTLdrLoadAppPriv(filename.c_str(), &mAuthLibrary);
|
---|
3060 | if (RT_FAILURE(rc))
|
---|
3061 | {
|
---|
3062 | /* Backward compatibility with old default 'VRDPAuth' name.
|
---|
3063 | * Try to load new default 'VBoxAuth' instead.
|
---|
3064 | */
|
---|
3065 | if (filename == "VRDPAuth")
|
---|
3066 | {
|
---|
3067 | LogRel(("AUTH: ConsoleVRDPServer::Authenticate: loading external authentication library VBoxAuth\n"));
|
---|
3068 | rc = RTLdrLoadAppPriv("VBoxAuth", &mAuthLibrary);
|
---|
3069 | }
|
---|
3070 | }
|
---|
3071 | }
|
---|
3072 |
|
---|
3073 | if (RT_FAILURE(rc))
|
---|
3074 | LogRel(("AUTH: Failed to load external authentication library. Error code: %Rrc\n", rc));
|
---|
3075 |
|
---|
3076 | if (RT_SUCCESS(rc))
|
---|
3077 | {
|
---|
3078 | typedef struct AuthEntryInfoStruct
|
---|
3079 | {
|
---|
3080 | const char *pszName;
|
---|
3081 | void **ppvAddress;
|
---|
3082 |
|
---|
3083 | } AuthEntryInfo;
|
---|
3084 | AuthEntryInfo entries[] =
|
---|
3085 | {
|
---|
3086 | { AUTHENTRY3_NAME, (void **)&mpfnAuthEntry3 },
|
---|
3087 | { AUTHENTRY2_NAME, (void **)&mpfnAuthEntry2 },
|
---|
3088 | { AUTHENTRY_NAME, (void **)&mpfnAuthEntry },
|
---|
3089 | { NULL, NULL }
|
---|
3090 | };
|
---|
3091 |
|
---|
3092 | /* Get the entry point. */
|
---|
3093 | AuthEntryInfo *pEntryInfo = &entries[0];
|
---|
3094 | while (pEntryInfo->pszName)
|
---|
3095 | {
|
---|
3096 | *pEntryInfo->ppvAddress = NULL;
|
---|
3097 |
|
---|
3098 | int rc2 = RTLdrGetSymbol(mAuthLibrary, pEntryInfo->pszName, pEntryInfo->ppvAddress);
|
---|
3099 | if (RT_SUCCESS(rc2))
|
---|
3100 | {
|
---|
3101 | /* Found an entry point. */
|
---|
3102 | LogRel(("AUTH: Using entry point '%s'.\n", pEntryInfo->pszName));
|
---|
3103 | rc = VINF_SUCCESS;
|
---|
3104 | break;
|
---|
3105 | }
|
---|
3106 |
|
---|
3107 | if (rc2 != VERR_SYMBOL_NOT_FOUND)
|
---|
3108 | {
|
---|
3109 | LogRel(("AUTH: Could not resolve import '%s'. Error code: %Rrc\n", pEntryInfo->pszName, rc2));
|
---|
3110 | }
|
---|
3111 | rc = rc2;
|
---|
3112 |
|
---|
3113 | pEntryInfo++;
|
---|
3114 | }
|
---|
3115 | }
|
---|
3116 |
|
---|
3117 | if (RT_FAILURE(rc))
|
---|
3118 | {
|
---|
3119 | mConsole->setError(E_FAIL,
|
---|
3120 | mConsole->tr("Could not load the external authentication library '%s' (%Rrc)"),
|
---|
3121 | filename.c_str(),
|
---|
3122 | rc);
|
---|
3123 |
|
---|
3124 | mpfnAuthEntry = NULL;
|
---|
3125 | mpfnAuthEntry2 = NULL;
|
---|
3126 | mpfnAuthEntry3 = NULL;
|
---|
3127 |
|
---|
3128 | if (mAuthLibrary)
|
---|
3129 | {
|
---|
3130 | RTLdrClose(mAuthLibrary);
|
---|
3131 | mAuthLibrary = 0;
|
---|
3132 | }
|
---|
3133 |
|
---|
3134 | return AuthResultAccessDenied;
|
---|
3135 | }
|
---|
3136 | }
|
---|
3137 |
|
---|
3138 | Assert(mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2 || mpfnAuthEntry3));
|
---|
3139 |
|
---|
3140 | AuthCtx ctx;
|
---|
3141 | ctx.result = AuthResultAccessDenied; /* Denied by default. */
|
---|
3142 | ctx.pfnAuthEntry3 = mpfnAuthEntry3;
|
---|
3143 | ctx.pfnAuthEntry2 = mpfnAuthEntry2;
|
---|
3144 | ctx.pfnAuthEntry = mpfnAuthEntry;
|
---|
3145 | ctx.pszCaller = "vrde";
|
---|
3146 | ctx.pUuid = &rawuuid;
|
---|
3147 | ctx.guestJudgement = guestJudgement;
|
---|
3148 | ctx.pszUser = pszUser;
|
---|
3149 | ctx.pszPassword = pszPassword;
|
---|
3150 | ctx.pszDomain = pszDomain;
|
---|
3151 | ctx.fLogon = true;
|
---|
3152 | ctx.clientId = u32ClientId;
|
---|
3153 |
|
---|
3154 | AuthResult result = authCall(&ctx);
|
---|
3155 |
|
---|
3156 | switch (result)
|
---|
3157 | {
|
---|
3158 | case AuthResultAccessDenied:
|
---|
3159 | LogRel(("AUTH: external authentication module returned 'access denied'\n"));
|
---|
3160 | break;
|
---|
3161 | case AuthResultAccessGranted:
|
---|
3162 | LogRel(("AUTH: external authentication module returned 'access granted'\n"));
|
---|
3163 | break;
|
---|
3164 | case AuthResultDelegateToGuest:
|
---|
3165 | LogRel(("AUTH: external authentication module returned 'delegate request to guest'\n"));
|
---|
3166 | break;
|
---|
3167 | default:
|
---|
3168 | LogRel(("AUTH: external authentication module returned incorrect return code %d\n", result));
|
---|
3169 | result = AuthResultAccessDenied;
|
---|
3170 | }
|
---|
3171 |
|
---|
3172 | LogFlow(("ConsoleVRDPServer::Authenticate: result = %d\n", result));
|
---|
3173 |
|
---|
3174 | return result;
|
---|
3175 | }
|
---|
3176 |
|
---|
3177 | void ConsoleVRDPServer::AuthDisconnect(const Guid &uuid, uint32_t u32ClientId)
|
---|
3178 | {
|
---|
3179 | AUTHUUID rawuuid;
|
---|
3180 |
|
---|
3181 | memcpy(rawuuid, uuid.raw(), sizeof(rawuuid));
|
---|
3182 |
|
---|
3183 | LogFlow(("ConsoleVRDPServer::AuthDisconnect: uuid = %RTuuid, u32ClientId = %d\n",
|
---|
3184 | rawuuid, u32ClientId));
|
---|
3185 |
|
---|
3186 | Assert(mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2 || mpfnAuthEntry3));
|
---|
3187 |
|
---|
3188 | AuthCtx ctx;
|
---|
3189 | ctx.result = AuthResultAccessDenied; /* Not used. */
|
---|
3190 | ctx.pfnAuthEntry3 = mpfnAuthEntry3;
|
---|
3191 | ctx.pfnAuthEntry2 = mpfnAuthEntry2;
|
---|
3192 | ctx.pfnAuthEntry = NULL; /* Does not use disconnect notification. */
|
---|
3193 | ctx.pszCaller = "vrde";
|
---|
3194 | ctx.pUuid = &rawuuid;
|
---|
3195 | ctx.guestJudgement = AuthGuestNotAsked;
|
---|
3196 | ctx.pszUser = NULL;
|
---|
3197 | ctx.pszPassword = NULL;
|
---|
3198 | ctx.pszDomain = NULL;
|
---|
3199 | ctx.fLogon = false;
|
---|
3200 | ctx.clientId = u32ClientId;
|
---|
3201 |
|
---|
3202 | authCall(&ctx);
|
---|
3203 | }
|
---|
3204 |
|
---|
3205 | int ConsoleVRDPServer::lockConsoleVRDPServer(void)
|
---|
3206 | {
|
---|
3207 | int rc = RTCritSectEnter(&mCritSect);
|
---|
3208 | AssertRC(rc);
|
---|
3209 | return rc;
|
---|
3210 | }
|
---|
3211 |
|
---|
3212 | void ConsoleVRDPServer::unlockConsoleVRDPServer(void)
|
---|
3213 | {
|
---|
3214 | RTCritSectLeave(&mCritSect);
|
---|
3215 | }
|
---|
3216 |
|
---|
3217 | DECLCALLBACK(int) ConsoleVRDPServer::ClipboardCallback(void *pvCallback,
|
---|
3218 | uint32_t u32ClientId,
|
---|
3219 | uint32_t u32Function,
|
---|
3220 | uint32_t u32Format,
|
---|
3221 | const void *pvData,
|
---|
3222 | uint32_t cbData)
|
---|
3223 | {
|
---|
3224 | LogFlowFunc(("pvCallback = %p, u32ClientId = %d, u32Function = %d, u32Format = 0x%08X, pvData = %p, cbData = %d\n",
|
---|
3225 | pvCallback, u32ClientId, u32Function, u32Format, pvData, cbData));
|
---|
3226 |
|
---|
3227 | int rc = VINF_SUCCESS;
|
---|
3228 |
|
---|
3229 | ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvCallback);
|
---|
3230 |
|
---|
3231 | NOREF(u32ClientId);
|
---|
3232 |
|
---|
3233 | switch (u32Function)
|
---|
3234 | {
|
---|
3235 | case VRDE_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE:
|
---|
3236 | {
|
---|
3237 | if (pServer->mpfnClipboardCallback)
|
---|
3238 | {
|
---|
3239 | pServer->mpfnClipboardCallback(VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE,
|
---|
3240 | u32Format,
|
---|
3241 | (void *)pvData,
|
---|
3242 | cbData);
|
---|
3243 | }
|
---|
3244 | } break;
|
---|
3245 |
|
---|
3246 | case VRDE_CLIPBOARD_FUNCTION_DATA_READ:
|
---|
3247 | {
|
---|
3248 | if (pServer->mpfnClipboardCallback)
|
---|
3249 | {
|
---|
3250 | pServer->mpfnClipboardCallback(VBOX_CLIPBOARD_EXT_FN_DATA_READ,
|
---|
3251 | u32Format,
|
---|
3252 | (void *)pvData,
|
---|
3253 | cbData);
|
---|
3254 | }
|
---|
3255 | } break;
|
---|
3256 |
|
---|
3257 | default:
|
---|
3258 | rc = VERR_NOT_SUPPORTED;
|
---|
3259 | }
|
---|
3260 |
|
---|
3261 | return rc;
|
---|
3262 | }
|
---|
3263 |
|
---|
3264 | DECLCALLBACK(int) ConsoleVRDPServer::ClipboardServiceExtension(void *pvExtension,
|
---|
3265 | uint32_t u32Function,
|
---|
3266 | void *pvParms,
|
---|
3267 | uint32_t cbParms)
|
---|
3268 | {
|
---|
3269 | LogFlowFunc(("pvExtension = %p, u32Function = %d, pvParms = %p, cbParms = %d\n",
|
---|
3270 | pvExtension, u32Function, pvParms, cbParms));
|
---|
3271 |
|
---|
3272 | int rc = VINF_SUCCESS;
|
---|
3273 |
|
---|
3274 | ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvExtension);
|
---|
3275 |
|
---|
3276 | VBOXCLIPBOARDEXTPARMS *pParms = (VBOXCLIPBOARDEXTPARMS *)pvParms;
|
---|
3277 |
|
---|
3278 | switch (u32Function)
|
---|
3279 | {
|
---|
3280 | case VBOX_CLIPBOARD_EXT_FN_SET_CALLBACK:
|
---|
3281 | {
|
---|
3282 | pServer->mpfnClipboardCallback = pParms->u.pfnCallback;
|
---|
3283 | } break;
|
---|
3284 |
|
---|
3285 | case VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE:
|
---|
3286 | {
|
---|
3287 | /* The guest announces clipboard formats. This must be delivered to all clients. */
|
---|
3288 | if (mpEntryPoints && pServer->mhServer)
|
---|
3289 | {
|
---|
3290 | mpEntryPoints->VRDEClipboard(pServer->mhServer,
|
---|
3291 | VRDE_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE,
|
---|
3292 | pParms->u32Format,
|
---|
3293 | NULL,
|
---|
3294 | 0,
|
---|
3295 | NULL);
|
---|
3296 | }
|
---|
3297 | } break;
|
---|
3298 |
|
---|
3299 | case VBOX_CLIPBOARD_EXT_FN_DATA_READ:
|
---|
3300 | {
|
---|
3301 | /* The clipboard service expects that the pvData buffer will be filled
|
---|
3302 | * with clipboard data. The server returns the data from the client that
|
---|
3303 | * announced the requested format most recently.
|
---|
3304 | */
|
---|
3305 | if (mpEntryPoints && pServer->mhServer)
|
---|
3306 | {
|
---|
3307 | mpEntryPoints->VRDEClipboard(pServer->mhServer,
|
---|
3308 | VRDE_CLIPBOARD_FUNCTION_DATA_READ,
|
---|
3309 | pParms->u32Format,
|
---|
3310 | pParms->u.pvData,
|
---|
3311 | pParms->cbData,
|
---|
3312 | &pParms->cbData);
|
---|
3313 | }
|
---|
3314 | } break;
|
---|
3315 |
|
---|
3316 | case VBOX_CLIPBOARD_EXT_FN_DATA_WRITE:
|
---|
3317 | {
|
---|
3318 | if (mpEntryPoints && pServer->mhServer)
|
---|
3319 | {
|
---|
3320 | mpEntryPoints->VRDEClipboard(pServer->mhServer,
|
---|
3321 | VRDE_CLIPBOARD_FUNCTION_DATA_WRITE,
|
---|
3322 | pParms->u32Format,
|
---|
3323 | pParms->u.pvData,
|
---|
3324 | pParms->cbData,
|
---|
3325 | NULL);
|
---|
3326 | }
|
---|
3327 | } break;
|
---|
3328 |
|
---|
3329 | default:
|
---|
3330 | rc = VERR_NOT_SUPPORTED;
|
---|
3331 | }
|
---|
3332 |
|
---|
3333 | return rc;
|
---|
3334 | }
|
---|
3335 |
|
---|
3336 | void ConsoleVRDPServer::ClipboardCreate(uint32_t u32ClientId)
|
---|
3337 | {
|
---|
3338 | int rc = lockConsoleVRDPServer();
|
---|
3339 |
|
---|
3340 | if (RT_SUCCESS(rc))
|
---|
3341 | {
|
---|
3342 | if (mcClipboardRefs == 0)
|
---|
3343 | {
|
---|
3344 | rc = HGCMHostRegisterServiceExtension(&mhClipboard, "VBoxSharedClipboard", ClipboardServiceExtension, this);
|
---|
3345 |
|
---|
3346 | if (RT_SUCCESS(rc))
|
---|
3347 | {
|
---|
3348 | mcClipboardRefs++;
|
---|
3349 | }
|
---|
3350 | }
|
---|
3351 |
|
---|
3352 | unlockConsoleVRDPServer();
|
---|
3353 | }
|
---|
3354 | }
|
---|
3355 |
|
---|
3356 | void ConsoleVRDPServer::ClipboardDelete(uint32_t u32ClientId)
|
---|
3357 | {
|
---|
3358 | int rc = lockConsoleVRDPServer();
|
---|
3359 |
|
---|
3360 | if (RT_SUCCESS(rc))
|
---|
3361 | {
|
---|
3362 | mcClipboardRefs--;
|
---|
3363 |
|
---|
3364 | if (mcClipboardRefs == 0)
|
---|
3365 | {
|
---|
3366 | HGCMHostUnregisterServiceExtension(mhClipboard);
|
---|
3367 | }
|
---|
3368 |
|
---|
3369 | unlockConsoleVRDPServer();
|
---|
3370 | }
|
---|
3371 | }
|
---|
3372 |
|
---|
3373 | /* That is called on INPUT thread of the VRDP server.
|
---|
3374 | * The ConsoleVRDPServer keeps a list of created backend instances.
|
---|
3375 | */
|
---|
3376 | void ConsoleVRDPServer::USBBackendCreate(uint32_t u32ClientId, void **ppvIntercept)
|
---|
3377 | {
|
---|
3378 | #ifdef VBOX_WITH_USB
|
---|
3379 | LogFlow(("ConsoleVRDPServer::USBBackendCreate: u32ClientId = %d\n", u32ClientId));
|
---|
3380 |
|
---|
3381 | /* Create a new instance of the USB backend for the new client. */
|
---|
3382 | RemoteUSBBackend *pRemoteUSBBackend = new RemoteUSBBackend(mConsole, this, u32ClientId);
|
---|
3383 |
|
---|
3384 | if (pRemoteUSBBackend)
|
---|
3385 | {
|
---|
3386 | pRemoteUSBBackend->AddRef(); /* 'Release' called in USBBackendDelete. */
|
---|
3387 |
|
---|
3388 | /* Append the new instance in the list. */
|
---|
3389 | int rc = lockConsoleVRDPServer();
|
---|
3390 |
|
---|
3391 | if (RT_SUCCESS(rc))
|
---|
3392 | {
|
---|
3393 | pRemoteUSBBackend->pNext = mUSBBackends.pHead;
|
---|
3394 | if (mUSBBackends.pHead)
|
---|
3395 | {
|
---|
3396 | mUSBBackends.pHead->pPrev = pRemoteUSBBackend;
|
---|
3397 | }
|
---|
3398 | else
|
---|
3399 | {
|
---|
3400 | mUSBBackends.pTail = pRemoteUSBBackend;
|
---|
3401 | }
|
---|
3402 |
|
---|
3403 | mUSBBackends.pHead = pRemoteUSBBackend;
|
---|
3404 |
|
---|
3405 | unlockConsoleVRDPServer();
|
---|
3406 |
|
---|
3407 | if (ppvIntercept)
|
---|
3408 | {
|
---|
3409 | *ppvIntercept = pRemoteUSBBackend;
|
---|
3410 | }
|
---|
3411 | }
|
---|
3412 |
|
---|
3413 | if (RT_FAILURE(rc))
|
---|
3414 | {
|
---|
3415 | pRemoteUSBBackend->Release();
|
---|
3416 | }
|
---|
3417 | }
|
---|
3418 | #endif /* VBOX_WITH_USB */
|
---|
3419 | }
|
---|
3420 |
|
---|
3421 | void ConsoleVRDPServer::USBBackendDelete(uint32_t u32ClientId)
|
---|
3422 | {
|
---|
3423 | #ifdef VBOX_WITH_USB
|
---|
3424 | LogFlow(("ConsoleVRDPServer::USBBackendDelete: u32ClientId = %d\n", u32ClientId));
|
---|
3425 |
|
---|
3426 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
3427 |
|
---|
3428 | /* Find the instance. */
|
---|
3429 | int rc = lockConsoleVRDPServer();
|
---|
3430 |
|
---|
3431 | if (RT_SUCCESS(rc))
|
---|
3432 | {
|
---|
3433 | pRemoteUSBBackend = usbBackendFind(u32ClientId);
|
---|
3434 |
|
---|
3435 | if (pRemoteUSBBackend)
|
---|
3436 | {
|
---|
3437 | /* Notify that it will be deleted. */
|
---|
3438 | pRemoteUSBBackend->NotifyDelete();
|
---|
3439 | }
|
---|
3440 |
|
---|
3441 | unlockConsoleVRDPServer();
|
---|
3442 | }
|
---|
3443 |
|
---|
3444 | if (pRemoteUSBBackend)
|
---|
3445 | {
|
---|
3446 | /* Here the instance has been excluded from the list and can be dereferenced. */
|
---|
3447 | pRemoteUSBBackend->Release();
|
---|
3448 | }
|
---|
3449 | #endif
|
---|
3450 | }
|
---|
3451 |
|
---|
3452 | void *ConsoleVRDPServer::USBBackendRequestPointer(uint32_t u32ClientId, const Guid *pGuid)
|
---|
3453 | {
|
---|
3454 | #ifdef VBOX_WITH_USB
|
---|
3455 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
3456 |
|
---|
3457 | /* Find the instance. */
|
---|
3458 | int rc = lockConsoleVRDPServer();
|
---|
3459 |
|
---|
3460 | if (RT_SUCCESS(rc))
|
---|
3461 | {
|
---|
3462 | pRemoteUSBBackend = usbBackendFind(u32ClientId);
|
---|
3463 |
|
---|
3464 | if (pRemoteUSBBackend)
|
---|
3465 | {
|
---|
3466 | /* Inform the backend instance that it is referenced by the Guid. */
|
---|
3467 | bool fAdded = pRemoteUSBBackend->addUUID(pGuid);
|
---|
3468 |
|
---|
3469 | if (fAdded)
|
---|
3470 | {
|
---|
3471 | /* Reference the instance because its pointer is being taken. */
|
---|
3472 | pRemoteUSBBackend->AddRef(); /* 'Release' is called in USBBackendReleasePointer. */
|
---|
3473 | }
|
---|
3474 | else
|
---|
3475 | {
|
---|
3476 | pRemoteUSBBackend = NULL;
|
---|
3477 | }
|
---|
3478 | }
|
---|
3479 |
|
---|
3480 | unlockConsoleVRDPServer();
|
---|
3481 | }
|
---|
3482 |
|
---|
3483 | if (pRemoteUSBBackend)
|
---|
3484 | {
|
---|
3485 | return pRemoteUSBBackend->GetBackendCallbackPointer();
|
---|
3486 | }
|
---|
3487 |
|
---|
3488 | #endif
|
---|
3489 | return NULL;
|
---|
3490 | }
|
---|
3491 |
|
---|
3492 | void ConsoleVRDPServer::USBBackendReleasePointer(const Guid *pGuid)
|
---|
3493 | {
|
---|
3494 | #ifdef VBOX_WITH_USB
|
---|
3495 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
3496 |
|
---|
3497 | /* Find the instance. */
|
---|
3498 | int rc = lockConsoleVRDPServer();
|
---|
3499 |
|
---|
3500 | if (RT_SUCCESS(rc))
|
---|
3501 | {
|
---|
3502 | pRemoteUSBBackend = usbBackendFindByUUID(pGuid);
|
---|
3503 |
|
---|
3504 | if (pRemoteUSBBackend)
|
---|
3505 | {
|
---|
3506 | pRemoteUSBBackend->removeUUID(pGuid);
|
---|
3507 | }
|
---|
3508 |
|
---|
3509 | unlockConsoleVRDPServer();
|
---|
3510 |
|
---|
3511 | if (pRemoteUSBBackend)
|
---|
3512 | {
|
---|
3513 | pRemoteUSBBackend->Release();
|
---|
3514 | }
|
---|
3515 | }
|
---|
3516 | #endif
|
---|
3517 | }
|
---|
3518 |
|
---|
3519 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendGetNext(RemoteUSBBackend *pRemoteUSBBackend)
|
---|
3520 | {
|
---|
3521 | LogFlow(("ConsoleVRDPServer::usbBackendGetNext: pBackend = %p\n", pRemoteUSBBackend));
|
---|
3522 |
|
---|
3523 | RemoteUSBBackend *pNextRemoteUSBBackend = NULL;
|
---|
3524 | #ifdef VBOX_WITH_USB
|
---|
3525 |
|
---|
3526 | int rc = lockConsoleVRDPServer();
|
---|
3527 |
|
---|
3528 | if (RT_SUCCESS(rc))
|
---|
3529 | {
|
---|
3530 | if (pRemoteUSBBackend == NULL)
|
---|
3531 | {
|
---|
3532 | /* The first backend in the list is requested. */
|
---|
3533 | pNextRemoteUSBBackend = mUSBBackends.pHead;
|
---|
3534 | }
|
---|
3535 | else
|
---|
3536 | {
|
---|
3537 | /* Get pointer to the next backend. */
|
---|
3538 | pNextRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3539 | }
|
---|
3540 |
|
---|
3541 | if (pNextRemoteUSBBackend)
|
---|
3542 | {
|
---|
3543 | pNextRemoteUSBBackend->AddRef();
|
---|
3544 | }
|
---|
3545 |
|
---|
3546 | unlockConsoleVRDPServer();
|
---|
3547 |
|
---|
3548 | if (pRemoteUSBBackend)
|
---|
3549 | {
|
---|
3550 | pRemoteUSBBackend->Release();
|
---|
3551 | }
|
---|
3552 | }
|
---|
3553 | #endif
|
---|
3554 |
|
---|
3555 | return pNextRemoteUSBBackend;
|
---|
3556 | }
|
---|
3557 |
|
---|
3558 | #ifdef VBOX_WITH_USB
|
---|
3559 | /* Internal method. Called under the ConsoleVRDPServerLock. */
|
---|
3560 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendFind(uint32_t u32ClientId)
|
---|
3561 | {
|
---|
3562 | RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
|
---|
3563 |
|
---|
3564 | while (pRemoteUSBBackend)
|
---|
3565 | {
|
---|
3566 | if (pRemoteUSBBackend->ClientId() == u32ClientId)
|
---|
3567 | {
|
---|
3568 | break;
|
---|
3569 | }
|
---|
3570 |
|
---|
3571 | pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3572 | }
|
---|
3573 |
|
---|
3574 | return pRemoteUSBBackend;
|
---|
3575 | }
|
---|
3576 |
|
---|
3577 | /* Internal method. Called under the ConsoleVRDPServerLock. */
|
---|
3578 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendFindByUUID(const Guid *pGuid)
|
---|
3579 | {
|
---|
3580 | RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
|
---|
3581 |
|
---|
3582 | while (pRemoteUSBBackend)
|
---|
3583 | {
|
---|
3584 | if (pRemoteUSBBackend->findUUID(pGuid))
|
---|
3585 | {
|
---|
3586 | break;
|
---|
3587 | }
|
---|
3588 |
|
---|
3589 | pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3590 | }
|
---|
3591 |
|
---|
3592 | return pRemoteUSBBackend;
|
---|
3593 | }
|
---|
3594 | #endif
|
---|
3595 |
|
---|
3596 | /* Internal method. Called by the backend destructor. */
|
---|
3597 | void ConsoleVRDPServer::usbBackendRemoveFromList(RemoteUSBBackend *pRemoteUSBBackend)
|
---|
3598 | {
|
---|
3599 | #ifdef VBOX_WITH_USB
|
---|
3600 | int rc = lockConsoleVRDPServer();
|
---|
3601 | AssertRC(rc);
|
---|
3602 |
|
---|
3603 | /* Exclude the found instance from the list. */
|
---|
3604 | if (pRemoteUSBBackend->pNext)
|
---|
3605 | {
|
---|
3606 | pRemoteUSBBackend->pNext->pPrev = pRemoteUSBBackend->pPrev;
|
---|
3607 | }
|
---|
3608 | else
|
---|
3609 | {
|
---|
3610 | mUSBBackends.pTail = (RemoteUSBBackend *)pRemoteUSBBackend->pPrev;
|
---|
3611 | }
|
---|
3612 |
|
---|
3613 | if (pRemoteUSBBackend->pPrev)
|
---|
3614 | {
|
---|
3615 | pRemoteUSBBackend->pPrev->pNext = pRemoteUSBBackend->pNext;
|
---|
3616 | }
|
---|
3617 | else
|
---|
3618 | {
|
---|
3619 | mUSBBackends.pHead = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3620 | }
|
---|
3621 |
|
---|
3622 | pRemoteUSBBackend->pNext = pRemoteUSBBackend->pPrev = NULL;
|
---|
3623 |
|
---|
3624 | unlockConsoleVRDPServer();
|
---|
3625 | #endif
|
---|
3626 | }
|
---|
3627 |
|
---|
3628 |
|
---|
3629 | void ConsoleVRDPServer::SendUpdate(unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const
|
---|
3630 | {
|
---|
3631 | if (mpEntryPoints && mhServer)
|
---|
3632 | {
|
---|
3633 | mpEntryPoints->VRDEUpdate(mhServer, uScreenId, pvUpdate, cbUpdate);
|
---|
3634 | }
|
---|
3635 | }
|
---|
3636 |
|
---|
3637 | void ConsoleVRDPServer::SendResize(void) const
|
---|
3638 | {
|
---|
3639 | if (mpEntryPoints && mhServer)
|
---|
3640 | {
|
---|
3641 | mpEntryPoints->VRDEResize(mhServer);
|
---|
3642 | }
|
---|
3643 | }
|
---|
3644 |
|
---|
3645 | void ConsoleVRDPServer::SendUpdateBitmap(unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const
|
---|
3646 | {
|
---|
3647 | VRDEORDERHDR update;
|
---|
3648 | update.x = x;
|
---|
3649 | update.y = y;
|
---|
3650 | update.w = w;
|
---|
3651 | update.h = h;
|
---|
3652 | if (mpEntryPoints && mhServer)
|
---|
3653 | {
|
---|
3654 | mpEntryPoints->VRDEUpdate(mhServer, uScreenId, &update, sizeof(update));
|
---|
3655 | }
|
---|
3656 | }
|
---|
3657 |
|
---|
3658 | void ConsoleVRDPServer::SendAudioSamples(void *pvSamples, uint32_t cSamples, VRDEAUDIOFORMAT format) const
|
---|
3659 | {
|
---|
3660 | if (mpEntryPoints && mhServer)
|
---|
3661 | {
|
---|
3662 | mpEntryPoints->VRDEAudioSamples(mhServer, pvSamples, cSamples, format);
|
---|
3663 | }
|
---|
3664 | }
|
---|
3665 |
|
---|
3666 | void ConsoleVRDPServer::SendAudioVolume(uint16_t left, uint16_t right) const
|
---|
3667 | {
|
---|
3668 | if (mpEntryPoints && mhServer)
|
---|
3669 | {
|
---|
3670 | mpEntryPoints->VRDEAudioVolume(mhServer, left, right);
|
---|
3671 | }
|
---|
3672 | }
|
---|
3673 |
|
---|
3674 | void ConsoleVRDPServer::SendUSBRequest(uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const
|
---|
3675 | {
|
---|
3676 | if (mpEntryPoints && mhServer)
|
---|
3677 | {
|
---|
3678 | mpEntryPoints->VRDEUSBRequest(mhServer, u32ClientId, pvParms, cbParms);
|
---|
3679 | }
|
---|
3680 | }
|
---|
3681 |
|
---|
3682 | /* @todo rc not needed? */
|
---|
3683 | int ConsoleVRDPServer::SendAudioInputBegin(void **ppvUserCtx,
|
---|
3684 | void *pvContext,
|
---|
3685 | uint32_t cSamples,
|
---|
3686 | uint32_t iSampleHz,
|
---|
3687 | uint32_t cChannels,
|
---|
3688 | uint32_t cBits)
|
---|
3689 | {
|
---|
3690 | if (mpEntryPoints && mhServer && mpEntryPoints->VRDEAudioInOpen)
|
---|
3691 | {
|
---|
3692 | uint32_t u32ClientId = ASMAtomicReadU32(&mu32AudioInputClientId);
|
---|
3693 | if (u32ClientId != 0) /* 0 would mean broadcast to all clients. */
|
---|
3694 | {
|
---|
3695 | VRDEAUDIOFORMAT audioFormat = VRDE_AUDIO_FMT_MAKE(iSampleHz, cChannels, cBits, 0);
|
---|
3696 | mpEntryPoints->VRDEAudioInOpen (mhServer,
|
---|
3697 | pvContext,
|
---|
3698 | u32ClientId,
|
---|
3699 | audioFormat,
|
---|
3700 | cSamples);
|
---|
3701 | *ppvUserCtx = NULL; /* This is the ConsoleVRDPServer context.
|
---|
3702 | * Currently not used because only one client is allowed to
|
---|
3703 | * do audio input and the client id is saved by the ConsoleVRDPServer.
|
---|
3704 | */
|
---|
3705 |
|
---|
3706 | return VINF_SUCCESS;
|
---|
3707 | }
|
---|
3708 | }
|
---|
3709 | return VERR_NOT_SUPPORTED;
|
---|
3710 | }
|
---|
3711 |
|
---|
3712 | void ConsoleVRDPServer::SendAudioInputEnd(void *pvUserCtx)
|
---|
3713 | {
|
---|
3714 | if (mpEntryPoints && mhServer && mpEntryPoints->VRDEAudioInClose)
|
---|
3715 | {
|
---|
3716 | uint32_t u32ClientId = ASMAtomicReadU32(&mu32AudioInputClientId);
|
---|
3717 | if (u32ClientId != 0) /* 0 would mean broadcast to all clients. */
|
---|
3718 | {
|
---|
3719 | mpEntryPoints->VRDEAudioInClose(mhServer, u32ClientId);
|
---|
3720 | }
|
---|
3721 | }
|
---|
3722 | }
|
---|
3723 |
|
---|
3724 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
3725 | int ConsoleVRDPServer::GetVideoFrameDimensions(uint16_t *pu16Heigh, uint16_t *pu16Width)
|
---|
3726 | {
|
---|
3727 | *pu16Heigh = 640;
|
---|
3728 | *pu16Width = 480;
|
---|
3729 | return VINF_SUCCESS;
|
---|
3730 | }
|
---|
3731 |
|
---|
3732 | int ConsoleVRDPServer::SendVideoSreamOn(bool fFetch)
|
---|
3733 | {
|
---|
3734 | /* Here we inform server that guest is starting/stopping
|
---|
3735 | * the stream
|
---|
3736 | */
|
---|
3737 | return VINF_SUCCESS;
|
---|
3738 | }
|
---|
3739 | #endif
|
---|
3740 |
|
---|
3741 |
|
---|
3742 |
|
---|
3743 | void ConsoleVRDPServer::QueryInfo(uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const
|
---|
3744 | {
|
---|
3745 | if (index == VRDE_QI_PORT)
|
---|
3746 | {
|
---|
3747 | uint32_t cbOut = sizeof(int32_t);
|
---|
3748 |
|
---|
3749 | if (cbBuffer >= cbOut)
|
---|
3750 | {
|
---|
3751 | *pcbOut = cbOut;
|
---|
3752 | *(int32_t *)pvBuffer = (int32_t)mVRDPBindPort;
|
---|
3753 | }
|
---|
3754 | }
|
---|
3755 | else if (mpEntryPoints && mhServer)
|
---|
3756 | {
|
---|
3757 | mpEntryPoints->VRDEQueryInfo(mhServer, index, pvBuffer, cbBuffer, pcbOut);
|
---|
3758 | }
|
---|
3759 | }
|
---|
3760 |
|
---|
3761 | /* static */ int ConsoleVRDPServer::loadVRDPLibrary(const char *pszLibraryName)
|
---|
3762 | {
|
---|
3763 | int rc = VINF_SUCCESS;
|
---|
3764 |
|
---|
3765 | if (mVRDPLibrary == NIL_RTLDRMOD)
|
---|
3766 | {
|
---|
3767 | RTERRINFOSTATIC ErrInfo;
|
---|
3768 | RTErrInfoInitStatic(&ErrInfo);
|
---|
3769 |
|
---|
3770 | if (RTPathHavePath(pszLibraryName))
|
---|
3771 | rc = SUPR3HardenedLdrLoadPlugIn(pszLibraryName, &mVRDPLibrary, &ErrInfo.Core);
|
---|
3772 | else
|
---|
3773 | rc = SUPR3HardenedLdrLoadAppPriv(pszLibraryName, &mVRDPLibrary, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
|
---|
3774 | if (RT_SUCCESS(rc))
|
---|
3775 | {
|
---|
3776 | struct SymbolEntry
|
---|
3777 | {
|
---|
3778 | const char *name;
|
---|
3779 | void **ppfn;
|
---|
3780 | };
|
---|
3781 |
|
---|
3782 | #define DEFSYMENTRY(a) { #a, (void**)&mpfn##a }
|
---|
3783 |
|
---|
3784 | static const struct SymbolEntry s_aSymbols[] =
|
---|
3785 | {
|
---|
3786 | DEFSYMENTRY(VRDECreateServer)
|
---|
3787 | };
|
---|
3788 |
|
---|
3789 | #undef DEFSYMENTRY
|
---|
3790 |
|
---|
3791 | for (unsigned i = 0; i < RT_ELEMENTS(s_aSymbols); i++)
|
---|
3792 | {
|
---|
3793 | rc = RTLdrGetSymbol(mVRDPLibrary, s_aSymbols[i].name, s_aSymbols[i].ppfn);
|
---|
3794 |
|
---|
3795 | if (RT_FAILURE(rc))
|
---|
3796 | {
|
---|
3797 | LogRel(("VRDE: Error resolving symbol '%s', rc %Rrc.\n", s_aSymbols[i].name, rc));
|
---|
3798 | break;
|
---|
3799 | }
|
---|
3800 | }
|
---|
3801 | }
|
---|
3802 | else
|
---|
3803 | {
|
---|
3804 | if (RTErrInfoIsSet(&ErrInfo.Core))
|
---|
3805 | LogRel(("VRDE: Error loading the library '%s': %s (%Rrc)\n", pszLibraryName, ErrInfo.Core.pszMsg, rc));
|
---|
3806 | else
|
---|
3807 | LogRel(("VRDE: Error loading the library '%s' rc = %Rrc.\n", pszLibraryName, rc));
|
---|
3808 |
|
---|
3809 | mVRDPLibrary = NIL_RTLDRMOD;
|
---|
3810 | }
|
---|
3811 | }
|
---|
3812 |
|
---|
3813 | if (RT_FAILURE(rc))
|
---|
3814 | {
|
---|
3815 | if (mVRDPLibrary != NIL_RTLDRMOD)
|
---|
3816 | {
|
---|
3817 | RTLdrClose(mVRDPLibrary);
|
---|
3818 | mVRDPLibrary = NIL_RTLDRMOD;
|
---|
3819 | }
|
---|
3820 | }
|
---|
3821 |
|
---|
3822 | return rc;
|
---|
3823 | }
|
---|
3824 |
|
---|
3825 | /*
|
---|
3826 | * IVRDEServerInfo implementation.
|
---|
3827 | */
|
---|
3828 | // constructor / destructor
|
---|
3829 | /////////////////////////////////////////////////////////////////////////////
|
---|
3830 |
|
---|
3831 | VRDEServerInfo::VRDEServerInfo()
|
---|
3832 | : mParent(NULL)
|
---|
3833 | {
|
---|
3834 | }
|
---|
3835 |
|
---|
3836 | VRDEServerInfo::~VRDEServerInfo()
|
---|
3837 | {
|
---|
3838 | }
|
---|
3839 |
|
---|
3840 |
|
---|
3841 | HRESULT VRDEServerInfo::FinalConstruct()
|
---|
3842 | {
|
---|
3843 | return BaseFinalConstruct();
|
---|
3844 | }
|
---|
3845 |
|
---|
3846 | void VRDEServerInfo::FinalRelease()
|
---|
3847 | {
|
---|
3848 | uninit();
|
---|
3849 | BaseFinalRelease();
|
---|
3850 | }
|
---|
3851 |
|
---|
3852 | // public methods only for internal purposes
|
---|
3853 | /////////////////////////////////////////////////////////////////////////////
|
---|
3854 |
|
---|
3855 | /**
|
---|
3856 | * Initializes the guest object.
|
---|
3857 | */
|
---|
3858 | HRESULT VRDEServerInfo::init(Console *aParent)
|
---|
3859 | {
|
---|
3860 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
3861 |
|
---|
3862 | ComAssertRet(aParent, E_INVALIDARG);
|
---|
3863 |
|
---|
3864 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
3865 | AutoInitSpan autoInitSpan(this);
|
---|
3866 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
3867 |
|
---|
3868 | unconst(mParent) = aParent;
|
---|
3869 |
|
---|
3870 | /* Confirm a successful initialization */
|
---|
3871 | autoInitSpan.setSucceeded();
|
---|
3872 |
|
---|
3873 | return S_OK;
|
---|
3874 | }
|
---|
3875 |
|
---|
3876 | /**
|
---|
3877 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
3878 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
3879 | */
|
---|
3880 | void VRDEServerInfo::uninit()
|
---|
3881 | {
|
---|
3882 | LogFlowThisFunc(("\n"));
|
---|
3883 |
|
---|
3884 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
3885 | AutoUninitSpan autoUninitSpan(this);
|
---|
3886 | if (autoUninitSpan.uninitDone())
|
---|
3887 | return;
|
---|
3888 |
|
---|
3889 | unconst(mParent) = NULL;
|
---|
3890 | }
|
---|
3891 |
|
---|
3892 | // IVRDEServerInfo properties
|
---|
3893 | /////////////////////////////////////////////////////////////////////////////
|
---|
3894 |
|
---|
3895 | #define IMPL_GETTER_BOOL(_aType, _aName, _aIndex) \
|
---|
3896 | STDMETHODIMP VRDEServerInfo::COMGETTER(_aName)(_aType *a##_aName) \
|
---|
3897 | { \
|
---|
3898 | if (!a##_aName) \
|
---|
3899 | return E_POINTER; \
|
---|
3900 | \
|
---|
3901 | AutoCaller autoCaller(this); \
|
---|
3902 | if (FAILED(autoCaller.rc())) return autoCaller.rc(); \
|
---|
3903 | \
|
---|
3904 | /* todo: Not sure if a AutoReadLock would be sufficient. */ \
|
---|
3905 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
|
---|
3906 | \
|
---|
3907 | uint32_t value; \
|
---|
3908 | uint32_t cbOut = 0; \
|
---|
3909 | \
|
---|
3910 | mParent->consoleVRDPServer()->QueryInfo \
|
---|
3911 | (_aIndex, &value, sizeof(value), &cbOut); \
|
---|
3912 | \
|
---|
3913 | *a##_aName = cbOut? !!value: FALSE; \
|
---|
3914 | \
|
---|
3915 | return S_OK; \
|
---|
3916 | } \
|
---|
3917 | extern void IMPL_GETTER_BOOL_DUMMY(void)
|
---|
3918 |
|
---|
3919 | #define IMPL_GETTER_SCALAR(_aType, _aName, _aIndex, _aValueMask) \
|
---|
3920 | STDMETHODIMP VRDEServerInfo::COMGETTER(_aName)(_aType *a##_aName) \
|
---|
3921 | { \
|
---|
3922 | if (!a##_aName) \
|
---|
3923 | return E_POINTER; \
|
---|
3924 | \
|
---|
3925 | AutoCaller autoCaller(this); \
|
---|
3926 | if (FAILED(autoCaller.rc())) return autoCaller.rc(); \
|
---|
3927 | \
|
---|
3928 | /* todo: Not sure if a AutoReadLock would be sufficient. */ \
|
---|
3929 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
|
---|
3930 | \
|
---|
3931 | _aType value; \
|
---|
3932 | uint32_t cbOut = 0; \
|
---|
3933 | \
|
---|
3934 | mParent->consoleVRDPServer()->QueryInfo \
|
---|
3935 | (_aIndex, &value, sizeof(value), &cbOut); \
|
---|
3936 | \
|
---|
3937 | if (_aValueMask) value &= (_aValueMask); \
|
---|
3938 | *a##_aName = cbOut? value: 0; \
|
---|
3939 | \
|
---|
3940 | return S_OK; \
|
---|
3941 | } \
|
---|
3942 | extern void IMPL_GETTER_SCALAR_DUMMY(void)
|
---|
3943 |
|
---|
3944 | #define IMPL_GETTER_BSTR(_aType, _aName, _aIndex) \
|
---|
3945 | STDMETHODIMP VRDEServerInfo::COMGETTER(_aName)(_aType *a##_aName) \
|
---|
3946 | { \
|
---|
3947 | if (!a##_aName) \
|
---|
3948 | return E_POINTER; \
|
---|
3949 | \
|
---|
3950 | AutoCaller autoCaller(this); \
|
---|
3951 | if (FAILED(autoCaller.rc())) return autoCaller.rc(); \
|
---|
3952 | \
|
---|
3953 | /* todo: Not sure if a AutoReadLock would be sufficient. */ \
|
---|
3954 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
|
---|
3955 | \
|
---|
3956 | uint32_t cbOut = 0; \
|
---|
3957 | \
|
---|
3958 | mParent->consoleVRDPServer()->QueryInfo \
|
---|
3959 | (_aIndex, NULL, 0, &cbOut); \
|
---|
3960 | \
|
---|
3961 | if (cbOut == 0) \
|
---|
3962 | { \
|
---|
3963 | Bstr str(""); \
|
---|
3964 | str.cloneTo(a##_aName); \
|
---|
3965 | return S_OK; \
|
---|
3966 | } \
|
---|
3967 | \
|
---|
3968 | char *pchBuffer = (char *)RTMemTmpAlloc(cbOut); \
|
---|
3969 | \
|
---|
3970 | if (!pchBuffer) \
|
---|
3971 | { \
|
---|
3972 | Log(("VRDEServerInfo::" \
|
---|
3973 | #_aName \
|
---|
3974 | ": Failed to allocate memory %d bytes\n", cbOut)); \
|
---|
3975 | return E_OUTOFMEMORY; \
|
---|
3976 | } \
|
---|
3977 | \
|
---|
3978 | mParent->consoleVRDPServer()->QueryInfo \
|
---|
3979 | (_aIndex, pchBuffer, cbOut, &cbOut); \
|
---|
3980 | \
|
---|
3981 | Bstr str(pchBuffer); \
|
---|
3982 | \
|
---|
3983 | str.cloneTo(a##_aName); \
|
---|
3984 | \
|
---|
3985 | RTMemTmpFree(pchBuffer); \
|
---|
3986 | \
|
---|
3987 | return S_OK; \
|
---|
3988 | } \
|
---|
3989 | extern void IMPL_GETTER_BSTR_DUMMY(void)
|
---|
3990 |
|
---|
3991 | IMPL_GETTER_BOOL (BOOL, Active, VRDE_QI_ACTIVE);
|
---|
3992 | IMPL_GETTER_SCALAR (LONG, Port, VRDE_QI_PORT, 0);
|
---|
3993 | IMPL_GETTER_SCALAR (ULONG, NumberOfClients, VRDE_QI_NUMBER_OF_CLIENTS, 0);
|
---|
3994 | IMPL_GETTER_SCALAR (LONG64, BeginTime, VRDE_QI_BEGIN_TIME, 0);
|
---|
3995 | IMPL_GETTER_SCALAR (LONG64, EndTime, VRDE_QI_END_TIME, 0);
|
---|
3996 | IMPL_GETTER_SCALAR (LONG64, BytesSent, VRDE_QI_BYTES_SENT, INT64_MAX);
|
---|
3997 | IMPL_GETTER_SCALAR (LONG64, BytesSentTotal, VRDE_QI_BYTES_SENT_TOTAL, INT64_MAX);
|
---|
3998 | IMPL_GETTER_SCALAR (LONG64, BytesReceived, VRDE_QI_BYTES_RECEIVED, INT64_MAX);
|
---|
3999 | IMPL_GETTER_SCALAR (LONG64, BytesReceivedTotal, VRDE_QI_BYTES_RECEIVED_TOTAL, INT64_MAX);
|
---|
4000 | IMPL_GETTER_BSTR (BSTR, User, VRDE_QI_USER);
|
---|
4001 | IMPL_GETTER_BSTR (BSTR, Domain, VRDE_QI_DOMAIN);
|
---|
4002 | IMPL_GETTER_BSTR (BSTR, ClientName, VRDE_QI_CLIENT_NAME);
|
---|
4003 | IMPL_GETTER_BSTR (BSTR, ClientIP, VRDE_QI_CLIENT_IP);
|
---|
4004 | IMPL_GETTER_SCALAR (ULONG, ClientVersion, VRDE_QI_CLIENT_VERSION, 0);
|
---|
4005 | IMPL_GETTER_SCALAR (ULONG, EncryptionStyle, VRDE_QI_ENCRYPTION_STYLE, 0);
|
---|
4006 |
|
---|
4007 | #undef IMPL_GETTER_BSTR
|
---|
4008 | #undef IMPL_GETTER_SCALAR
|
---|
4009 | #undef IMPL_GETTER_BOOL
|
---|
4010 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|