1 | /* $Id: ConsoleVRDPServer.cpp 47117 2013-07-12 12:48:17Z 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 | mcInResize = 0;
|
---|
1337 |
|
---|
1338 | m_fGuestWantsAbsolute = false;
|
---|
1339 | m_mousex = 0;
|
---|
1340 | m_mousey = 0;
|
---|
1341 |
|
---|
1342 | m_InputSynch.cGuestNumLockAdaptions = 2;
|
---|
1343 | m_InputSynch.cGuestCapsLockAdaptions = 2;
|
---|
1344 |
|
---|
1345 | m_InputSynch.fGuestNumLock = false;
|
---|
1346 | m_InputSynch.fGuestCapsLock = false;
|
---|
1347 | m_InputSynch.fGuestScrollLock = false;
|
---|
1348 |
|
---|
1349 | m_InputSynch.fClientNumLock = false;
|
---|
1350 | m_InputSynch.fClientCapsLock = false;
|
---|
1351 | m_InputSynch.fClientScrollLock = false;
|
---|
1352 |
|
---|
1353 | RT_ZERO(maFramebuffers);
|
---|
1354 |
|
---|
1355 | {
|
---|
1356 | ComPtr<IEventSource> es;
|
---|
1357 | console->COMGETTER(EventSource)(es.asOutParam());
|
---|
1358 | ComObjPtr<VRDPConsoleListenerImpl> aConsoleListener;
|
---|
1359 | aConsoleListener.createObject();
|
---|
1360 | aConsoleListener->init(new VRDPConsoleListener(), this);
|
---|
1361 | mConsoleListener = aConsoleListener;
|
---|
1362 | com::SafeArray <VBoxEventType_T> eventTypes;
|
---|
1363 | eventTypes.push_back(VBoxEventType_OnMousePointerShapeChanged);
|
---|
1364 | eventTypes.push_back(VBoxEventType_OnMouseCapabilityChanged);
|
---|
1365 | eventTypes.push_back(VBoxEventType_OnKeyboardLedsChanged);
|
---|
1366 | es->RegisterListener(mConsoleListener, ComSafeArrayAsInParam(eventTypes), true);
|
---|
1367 | }
|
---|
1368 |
|
---|
1369 | mVRDPBindPort = -1;
|
---|
1370 |
|
---|
1371 | mAuthLibrary = 0;
|
---|
1372 |
|
---|
1373 | mu32AudioInputClientId = 0;
|
---|
1374 |
|
---|
1375 | /*
|
---|
1376 | * Optional interfaces.
|
---|
1377 | */
|
---|
1378 | m_fInterfaceImage = false;
|
---|
1379 | RT_ZERO(m_interfaceImage);
|
---|
1380 | RT_ZERO(m_interfaceCallbacksImage);
|
---|
1381 | RT_ZERO(m_interfaceMousePtr);
|
---|
1382 | RT_ZERO(m_interfaceSCard);
|
---|
1383 | RT_ZERO(m_interfaceCallbacksSCard);
|
---|
1384 | RT_ZERO(m_interfaceTSMF);
|
---|
1385 | RT_ZERO(m_interfaceCallbacksTSMF);
|
---|
1386 | RT_ZERO(m_interfaceVideoIn);
|
---|
1387 | RT_ZERO(m_interfaceCallbacksVideoIn);
|
---|
1388 |
|
---|
1389 | rc = RTCritSectInit(&mTSMFLock);
|
---|
1390 | AssertRC(rc);
|
---|
1391 | }
|
---|
1392 |
|
---|
1393 | ConsoleVRDPServer::~ConsoleVRDPServer()
|
---|
1394 | {
|
---|
1395 | Stop();
|
---|
1396 |
|
---|
1397 | if (mConsoleListener)
|
---|
1398 | {
|
---|
1399 | ComPtr<IEventSource> es;
|
---|
1400 | mConsole->COMGETTER(EventSource)(es.asOutParam());
|
---|
1401 | es->UnregisterListener(mConsoleListener);
|
---|
1402 | mConsoleListener.setNull();
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | unsigned i;
|
---|
1406 | for (i = 0; i < RT_ELEMENTS(maFramebuffers); i++)
|
---|
1407 | {
|
---|
1408 | if (maFramebuffers[i])
|
---|
1409 | {
|
---|
1410 | maFramebuffers[i]->Release();
|
---|
1411 | maFramebuffers[i] = NULL;
|
---|
1412 | }
|
---|
1413 | }
|
---|
1414 |
|
---|
1415 | if (RTCritSectIsInitialized(&mCritSect))
|
---|
1416 | {
|
---|
1417 | RTCritSectDelete(&mCritSect);
|
---|
1418 | RT_ZERO(mCritSect);
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | if (RTCritSectIsInitialized(&mTSMFLock))
|
---|
1422 | {
|
---|
1423 | RTCritSectDelete(&mTSMFLock);
|
---|
1424 | RT_ZERO(mTSMFLock);
|
---|
1425 | }
|
---|
1426 | }
|
---|
1427 |
|
---|
1428 | int ConsoleVRDPServer::Launch(void)
|
---|
1429 | {
|
---|
1430 | LogFlowThisFunc(("\n"));
|
---|
1431 |
|
---|
1432 | IVRDEServer *server = mConsole->getVRDEServer();
|
---|
1433 | AssertReturn(server, VERR_INTERNAL_ERROR_2);
|
---|
1434 |
|
---|
1435 | /*
|
---|
1436 | * Check if VRDE is enabled.
|
---|
1437 | */
|
---|
1438 | BOOL fEnabled;
|
---|
1439 | HRESULT hrc = server->COMGETTER(Enabled)(&fEnabled);
|
---|
1440 | AssertComRCReturn(hrc, Global::vboxStatusCodeFromCOM(hrc));
|
---|
1441 | if (!fEnabled)
|
---|
1442 | return VINF_SUCCESS;
|
---|
1443 |
|
---|
1444 | /*
|
---|
1445 | * Check that a VRDE extension pack name is set and resolve it into a
|
---|
1446 | * library path.
|
---|
1447 | */
|
---|
1448 | Bstr bstrExtPack;
|
---|
1449 | hrc = server->COMGETTER(VRDEExtPack)(bstrExtPack.asOutParam());
|
---|
1450 | if (FAILED(hrc))
|
---|
1451 | return Global::vboxStatusCodeFromCOM(hrc);
|
---|
1452 | if (bstrExtPack.isEmpty())
|
---|
1453 | return VINF_NOT_SUPPORTED;
|
---|
1454 |
|
---|
1455 | Utf8Str strExtPack(bstrExtPack);
|
---|
1456 | Utf8Str strVrdeLibrary;
|
---|
1457 | int vrc = VINF_SUCCESS;
|
---|
1458 | if (strExtPack.equals(VBOXVRDP_KLUDGE_EXTPACK_NAME))
|
---|
1459 | strVrdeLibrary = "VBoxVRDP";
|
---|
1460 | else
|
---|
1461 | {
|
---|
1462 | #ifdef VBOX_WITH_EXTPACK
|
---|
1463 | ExtPackManager *pExtPackMgr = mConsole->getExtPackManager();
|
---|
1464 | vrc = pExtPackMgr->getVrdeLibraryPathForExtPack(&strExtPack, &strVrdeLibrary);
|
---|
1465 | #else
|
---|
1466 | vrc = VERR_FILE_NOT_FOUND;
|
---|
1467 | #endif
|
---|
1468 | }
|
---|
1469 | if (RT_SUCCESS(vrc))
|
---|
1470 | {
|
---|
1471 | /*
|
---|
1472 | * Load the VRDE library and start the server, if it is enabled.
|
---|
1473 | */
|
---|
1474 | vrc = loadVRDPLibrary(strVrdeLibrary.c_str());
|
---|
1475 | if (RT_SUCCESS(vrc))
|
---|
1476 | {
|
---|
1477 | VRDEENTRYPOINTS_4 *pEntryPoints4;
|
---|
1478 | vrc = mpfnVRDECreateServer(&mCallbacks.header, this, (VRDEINTERFACEHDR **)&pEntryPoints4, &mhServer);
|
---|
1479 |
|
---|
1480 | if (RT_SUCCESS(vrc))
|
---|
1481 | {
|
---|
1482 | mServerInterfaceVersion = 4;
|
---|
1483 | mEntryPoints = *pEntryPoints4;
|
---|
1484 | mpEntryPoints = &mEntryPoints;
|
---|
1485 | }
|
---|
1486 | else if (vrc == VERR_VERSION_MISMATCH)
|
---|
1487 | {
|
---|
1488 | /* An older version of VRDE is installed, try version 3. */
|
---|
1489 | VRDEENTRYPOINTS_3 *pEntryPoints3;
|
---|
1490 |
|
---|
1491 | static VRDECALLBACKS_3 sCallbacks3 =
|
---|
1492 | {
|
---|
1493 | { VRDE_INTERFACE_VERSION_3, sizeof(VRDECALLBACKS_3) },
|
---|
1494 | ConsoleVRDPServer::VRDPCallbackQueryProperty,
|
---|
1495 | ConsoleVRDPServer::VRDPCallbackClientLogon,
|
---|
1496 | ConsoleVRDPServer::VRDPCallbackClientConnect,
|
---|
1497 | ConsoleVRDPServer::VRDPCallbackClientDisconnect,
|
---|
1498 | ConsoleVRDPServer::VRDPCallbackIntercept,
|
---|
1499 | ConsoleVRDPServer::VRDPCallbackUSB,
|
---|
1500 | ConsoleVRDPServer::VRDPCallbackClipboard,
|
---|
1501 | ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
|
---|
1502 | ConsoleVRDPServer::VRDPCallbackFramebufferLock,
|
---|
1503 | ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
|
---|
1504 | ConsoleVRDPServer::VRDPCallbackInput,
|
---|
1505 | ConsoleVRDPServer::VRDPCallbackVideoModeHint,
|
---|
1506 | ConsoleVRDPServer::VRDECallbackAudioIn
|
---|
1507 | };
|
---|
1508 |
|
---|
1509 | vrc = mpfnVRDECreateServer(&sCallbacks3.header, this, (VRDEINTERFACEHDR **)&pEntryPoints3, &mhServer);
|
---|
1510 | if (RT_SUCCESS(vrc))
|
---|
1511 | {
|
---|
1512 | mServerInterfaceVersion = 3;
|
---|
1513 | mEntryPoints.header = pEntryPoints3->header;
|
---|
1514 | mEntryPoints.VRDEDestroy = pEntryPoints3->VRDEDestroy;
|
---|
1515 | mEntryPoints.VRDEEnableConnections = pEntryPoints3->VRDEEnableConnections;
|
---|
1516 | mEntryPoints.VRDEDisconnect = pEntryPoints3->VRDEDisconnect;
|
---|
1517 | mEntryPoints.VRDEResize = pEntryPoints3->VRDEResize;
|
---|
1518 | mEntryPoints.VRDEUpdate = pEntryPoints3->VRDEUpdate;
|
---|
1519 | mEntryPoints.VRDEColorPointer = pEntryPoints3->VRDEColorPointer;
|
---|
1520 | mEntryPoints.VRDEHidePointer = pEntryPoints3->VRDEHidePointer;
|
---|
1521 | mEntryPoints.VRDEAudioSamples = pEntryPoints3->VRDEAudioSamples;
|
---|
1522 | mEntryPoints.VRDEAudioVolume = pEntryPoints3->VRDEAudioVolume;
|
---|
1523 | mEntryPoints.VRDEUSBRequest = pEntryPoints3->VRDEUSBRequest;
|
---|
1524 | mEntryPoints.VRDEClipboard = pEntryPoints3->VRDEClipboard;
|
---|
1525 | mEntryPoints.VRDEQueryInfo = pEntryPoints3->VRDEQueryInfo;
|
---|
1526 | mEntryPoints.VRDERedirect = pEntryPoints3->VRDERedirect;
|
---|
1527 | mEntryPoints.VRDEAudioInOpen = pEntryPoints3->VRDEAudioInOpen;
|
---|
1528 | mEntryPoints.VRDEAudioInClose = pEntryPoints3->VRDEAudioInClose;
|
---|
1529 | mEntryPoints.VRDEGetInterface = NULL;
|
---|
1530 | mpEntryPoints = &mEntryPoints;
|
---|
1531 | }
|
---|
1532 | else if (vrc == VERR_VERSION_MISMATCH)
|
---|
1533 | {
|
---|
1534 | /* An older version of VRDE is installed, try version 1. */
|
---|
1535 | VRDEENTRYPOINTS_1 *pEntryPoints1;
|
---|
1536 |
|
---|
1537 | static VRDECALLBACKS_1 sCallbacks1 =
|
---|
1538 | {
|
---|
1539 | { VRDE_INTERFACE_VERSION_1, sizeof(VRDECALLBACKS_1) },
|
---|
1540 | ConsoleVRDPServer::VRDPCallbackQueryProperty,
|
---|
1541 | ConsoleVRDPServer::VRDPCallbackClientLogon,
|
---|
1542 | ConsoleVRDPServer::VRDPCallbackClientConnect,
|
---|
1543 | ConsoleVRDPServer::VRDPCallbackClientDisconnect,
|
---|
1544 | ConsoleVRDPServer::VRDPCallbackIntercept,
|
---|
1545 | ConsoleVRDPServer::VRDPCallbackUSB,
|
---|
1546 | ConsoleVRDPServer::VRDPCallbackClipboard,
|
---|
1547 | ConsoleVRDPServer::VRDPCallbackFramebufferQuery,
|
---|
1548 | ConsoleVRDPServer::VRDPCallbackFramebufferLock,
|
---|
1549 | ConsoleVRDPServer::VRDPCallbackFramebufferUnlock,
|
---|
1550 | ConsoleVRDPServer::VRDPCallbackInput,
|
---|
1551 | ConsoleVRDPServer::VRDPCallbackVideoModeHint
|
---|
1552 | };
|
---|
1553 |
|
---|
1554 | vrc = mpfnVRDECreateServer(&sCallbacks1.header, this, (VRDEINTERFACEHDR **)&pEntryPoints1, &mhServer);
|
---|
1555 | if (RT_SUCCESS(vrc))
|
---|
1556 | {
|
---|
1557 | mServerInterfaceVersion = 1;
|
---|
1558 | mEntryPoints.header = pEntryPoints1->header;
|
---|
1559 | mEntryPoints.VRDEDestroy = pEntryPoints1->VRDEDestroy;
|
---|
1560 | mEntryPoints.VRDEEnableConnections = pEntryPoints1->VRDEEnableConnections;
|
---|
1561 | mEntryPoints.VRDEDisconnect = pEntryPoints1->VRDEDisconnect;
|
---|
1562 | mEntryPoints.VRDEResize = pEntryPoints1->VRDEResize;
|
---|
1563 | mEntryPoints.VRDEUpdate = pEntryPoints1->VRDEUpdate;
|
---|
1564 | mEntryPoints.VRDEColorPointer = pEntryPoints1->VRDEColorPointer;
|
---|
1565 | mEntryPoints.VRDEHidePointer = pEntryPoints1->VRDEHidePointer;
|
---|
1566 | mEntryPoints.VRDEAudioSamples = pEntryPoints1->VRDEAudioSamples;
|
---|
1567 | mEntryPoints.VRDEAudioVolume = pEntryPoints1->VRDEAudioVolume;
|
---|
1568 | mEntryPoints.VRDEUSBRequest = pEntryPoints1->VRDEUSBRequest;
|
---|
1569 | mEntryPoints.VRDEClipboard = pEntryPoints1->VRDEClipboard;
|
---|
1570 | mEntryPoints.VRDEQueryInfo = pEntryPoints1->VRDEQueryInfo;
|
---|
1571 | mEntryPoints.VRDERedirect = NULL;
|
---|
1572 | mEntryPoints.VRDEAudioInOpen = NULL;
|
---|
1573 | mEntryPoints.VRDEAudioInClose = NULL;
|
---|
1574 | mEntryPoints.VRDEGetInterface = NULL;
|
---|
1575 | mpEntryPoints = &mEntryPoints;
|
---|
1576 | }
|
---|
1577 | }
|
---|
1578 | }
|
---|
1579 |
|
---|
1580 | if (RT_SUCCESS(vrc))
|
---|
1581 | {
|
---|
1582 | LogRel(("VRDE: loaded version %d of the server.\n", mServerInterfaceVersion));
|
---|
1583 |
|
---|
1584 | if (mServerInterfaceVersion >= 4)
|
---|
1585 | {
|
---|
1586 | /* The server supports optional interfaces. */
|
---|
1587 | Assert(mpEntryPoints->VRDEGetInterface != NULL);
|
---|
1588 |
|
---|
1589 | /* Image interface. */
|
---|
1590 | m_interfaceImage.header.u64Version = 1;
|
---|
1591 | m_interfaceImage.header.u64Size = sizeof(m_interfaceImage);
|
---|
1592 |
|
---|
1593 | m_interfaceCallbacksImage.header.u64Version = 1;
|
---|
1594 | m_interfaceCallbacksImage.header.u64Size = sizeof(m_interfaceCallbacksImage);
|
---|
1595 | m_interfaceCallbacksImage.VRDEImageCbNotify = VRDEImageCbNotify;
|
---|
1596 |
|
---|
1597 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1598 | VRDE_IMAGE_INTERFACE_NAME,
|
---|
1599 | &m_interfaceImage.header,
|
---|
1600 | &m_interfaceCallbacksImage.header,
|
---|
1601 | this);
|
---|
1602 | if (RT_SUCCESS(vrc))
|
---|
1603 | {
|
---|
1604 | LogRel(("VRDE: [%s]\n", VRDE_IMAGE_INTERFACE_NAME));
|
---|
1605 | m_fInterfaceImage = true;
|
---|
1606 | }
|
---|
1607 |
|
---|
1608 | /* Mouse pointer interface. */
|
---|
1609 | m_interfaceMousePtr.header.u64Version = 1;
|
---|
1610 | m_interfaceMousePtr.header.u64Size = sizeof(m_interfaceMousePtr);
|
---|
1611 |
|
---|
1612 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1613 | VRDE_MOUSEPTR_INTERFACE_NAME,
|
---|
1614 | &m_interfaceMousePtr.header,
|
---|
1615 | NULL,
|
---|
1616 | this);
|
---|
1617 | if (RT_SUCCESS(vrc))
|
---|
1618 | {
|
---|
1619 | LogRel(("VRDE: [%s]\n", VRDE_MOUSEPTR_INTERFACE_NAME));
|
---|
1620 | }
|
---|
1621 | else
|
---|
1622 | {
|
---|
1623 | RT_ZERO(m_interfaceMousePtr);
|
---|
1624 | }
|
---|
1625 |
|
---|
1626 | /* Smartcard interface. */
|
---|
1627 | m_interfaceSCard.header.u64Version = 1;
|
---|
1628 | m_interfaceSCard.header.u64Size = sizeof(m_interfaceSCard);
|
---|
1629 |
|
---|
1630 | m_interfaceCallbacksSCard.header.u64Version = 1;
|
---|
1631 | m_interfaceCallbacksSCard.header.u64Size = sizeof(m_interfaceCallbacksSCard);
|
---|
1632 | m_interfaceCallbacksSCard.VRDESCardCbNotify = VRDESCardCbNotify;
|
---|
1633 | m_interfaceCallbacksSCard.VRDESCardCbResponse = VRDESCardCbResponse;
|
---|
1634 |
|
---|
1635 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1636 | VRDE_SCARD_INTERFACE_NAME,
|
---|
1637 | &m_interfaceSCard.header,
|
---|
1638 | &m_interfaceCallbacksSCard.header,
|
---|
1639 | this);
|
---|
1640 | if (RT_SUCCESS(vrc))
|
---|
1641 | {
|
---|
1642 | LogRel(("VRDE: [%s]\n", VRDE_SCARD_INTERFACE_NAME));
|
---|
1643 | }
|
---|
1644 | else
|
---|
1645 | {
|
---|
1646 | RT_ZERO(m_interfaceSCard);
|
---|
1647 | }
|
---|
1648 |
|
---|
1649 | /* Raw TSMF interface. */
|
---|
1650 | m_interfaceTSMF.header.u64Version = 1;
|
---|
1651 | m_interfaceTSMF.header.u64Size = sizeof(m_interfaceTSMF);
|
---|
1652 |
|
---|
1653 | m_interfaceCallbacksTSMF.header.u64Version = 1;
|
---|
1654 | m_interfaceCallbacksTSMF.header.u64Size = sizeof(m_interfaceCallbacksTSMF);
|
---|
1655 | m_interfaceCallbacksTSMF.VRDETSMFCbNotify = VRDETSMFCbNotify;
|
---|
1656 |
|
---|
1657 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1658 | VRDE_TSMF_INTERFACE_NAME,
|
---|
1659 | &m_interfaceTSMF.header,
|
---|
1660 | &m_interfaceCallbacksTSMF.header,
|
---|
1661 | this);
|
---|
1662 | if (RT_SUCCESS(vrc))
|
---|
1663 | {
|
---|
1664 | LogRel(("VRDE: [%s]\n", VRDE_TSMF_INTERFACE_NAME));
|
---|
1665 | }
|
---|
1666 | else
|
---|
1667 | {
|
---|
1668 | RT_ZERO(m_interfaceTSMF);
|
---|
1669 | }
|
---|
1670 |
|
---|
1671 | /* VideoIn interface. */
|
---|
1672 | m_interfaceVideoIn.header.u64Version = 1;
|
---|
1673 | m_interfaceVideoIn.header.u64Size = sizeof(m_interfaceVideoIn);
|
---|
1674 |
|
---|
1675 | m_interfaceCallbacksVideoIn.header.u64Version = 1;
|
---|
1676 | m_interfaceCallbacksVideoIn.header.u64Size = sizeof(m_interfaceCallbacksVideoIn);
|
---|
1677 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInNotify = VRDECallbackVideoInNotify;
|
---|
1678 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInDeviceDesc = VRDECallbackVideoInDeviceDesc;
|
---|
1679 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInControl = VRDECallbackVideoInControl;
|
---|
1680 | m_interfaceCallbacksVideoIn.VRDECallbackVideoInFrame = VRDECallbackVideoInFrame;
|
---|
1681 |
|
---|
1682 | vrc = mpEntryPoints->VRDEGetInterface(mhServer,
|
---|
1683 | VRDE_VIDEOIN_INTERFACE_NAME,
|
---|
1684 | &m_interfaceVideoIn.header,
|
---|
1685 | &m_interfaceCallbacksVideoIn.header,
|
---|
1686 | this);
|
---|
1687 | if (RT_SUCCESS(vrc))
|
---|
1688 | {
|
---|
1689 | LogRel(("VRDE: [%s]\n", VRDE_VIDEOIN_INTERFACE_NAME));
|
---|
1690 | }
|
---|
1691 | else
|
---|
1692 | {
|
---|
1693 | RT_ZERO(m_interfaceVideoIn);
|
---|
1694 | }
|
---|
1695 |
|
---|
1696 | /* Since these interfaces are optional, it is always a success here. */
|
---|
1697 | vrc = VINF_SUCCESS;
|
---|
1698 | }
|
---|
1699 | #ifdef VBOX_WITH_USB
|
---|
1700 | remoteUSBThreadStart();
|
---|
1701 | #endif
|
---|
1702 | }
|
---|
1703 | else
|
---|
1704 | {
|
---|
1705 | if (vrc != VERR_NET_ADDRESS_IN_USE)
|
---|
1706 | LogRel(("VRDE: Could not start the server rc = %Rrc\n", vrc));
|
---|
1707 | /* Don't unload the lib, because it prevents us trying again or
|
---|
1708 | because there may be other users? */
|
---|
1709 | }
|
---|
1710 | }
|
---|
1711 | }
|
---|
1712 |
|
---|
1713 | return vrc;
|
---|
1714 | }
|
---|
1715 |
|
---|
1716 | typedef struct H3DORInstance
|
---|
1717 | {
|
---|
1718 | ConsoleVRDPServer *pThis;
|
---|
1719 | HVRDEIMAGE hImageBitmap;
|
---|
1720 | int32_t x;
|
---|
1721 | int32_t y;
|
---|
1722 | uint32_t w;
|
---|
1723 | uint32_t h;
|
---|
1724 | bool fCreated;
|
---|
1725 | bool fFallback;
|
---|
1726 | } H3DORInstance;
|
---|
1727 |
|
---|
1728 | #define H3DORLOG Log
|
---|
1729 |
|
---|
1730 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORBegin(const void *pvContext, void **ppvInstance,
|
---|
1731 | const char *pszFormat)
|
---|
1732 | {
|
---|
1733 | H3DORLOG(("H3DORBegin: ctx %p [%s]\n", pvContext, pszFormat));
|
---|
1734 |
|
---|
1735 | H3DORInstance *p = (H3DORInstance *)RTMemAlloc(sizeof(H3DORInstance));
|
---|
1736 |
|
---|
1737 | if (p)
|
---|
1738 | {
|
---|
1739 | p->pThis = (ConsoleVRDPServer *)pvContext;
|
---|
1740 | p->hImageBitmap = NULL;
|
---|
1741 | p->x = 0;
|
---|
1742 | p->y = 0;
|
---|
1743 | p->w = 0;
|
---|
1744 | p->h = 0;
|
---|
1745 | p->fCreated = false;
|
---|
1746 | p->fFallback = false;
|
---|
1747 |
|
---|
1748 | /* Host 3D service passes the actual format of data in this redirect instance.
|
---|
1749 | * That is what will be in the H3DORFrame's parameters pvData and cbData.
|
---|
1750 | */
|
---|
1751 | if (RTStrICmp(pszFormat, H3DOR_FMT_RGBA_TOPDOWN) == 0)
|
---|
1752 | {
|
---|
1753 | /* Accept it. */
|
---|
1754 | }
|
---|
1755 | else
|
---|
1756 | {
|
---|
1757 | RTMemFree(p);
|
---|
1758 | p = NULL;
|
---|
1759 | }
|
---|
1760 | }
|
---|
1761 |
|
---|
1762 | H3DORLOG(("H3DORBegin: ins %p\n", p));
|
---|
1763 |
|
---|
1764 | /* Caller checks this for NULL. */
|
---|
1765 | *ppvInstance = p;
|
---|
1766 | }
|
---|
1767 |
|
---|
1768 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORGeometry(void *pvInstance,
|
---|
1769 | int32_t x, int32_t y, uint32_t w, uint32_t h)
|
---|
1770 | {
|
---|
1771 | H3DORLOG(("H3DORGeometry: ins %p %d,%d %dx%d\n", pvInstance, x, y, w, h));
|
---|
1772 |
|
---|
1773 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
1774 | Assert(p);
|
---|
1775 | Assert(p->pThis);
|
---|
1776 |
|
---|
1777 | /* @todo find out what to do if size changes to 0x0 from non zero */
|
---|
1778 | if (w == 0 || h == 0)
|
---|
1779 | {
|
---|
1780 | /* Do nothing. */
|
---|
1781 | return;
|
---|
1782 | }
|
---|
1783 |
|
---|
1784 | RTRECT rect;
|
---|
1785 | rect.xLeft = x;
|
---|
1786 | rect.yTop = y;
|
---|
1787 | rect.xRight = x + w;
|
---|
1788 | rect.yBottom = y + h;
|
---|
1789 |
|
---|
1790 | if (p->hImageBitmap)
|
---|
1791 | {
|
---|
1792 | /* An image handle has been already created,
|
---|
1793 | * check if it has the same size as the reported geometry.
|
---|
1794 | */
|
---|
1795 | if ( p->x == x
|
---|
1796 | && p->y == y
|
---|
1797 | && p->w == w
|
---|
1798 | && p->h == h)
|
---|
1799 | {
|
---|
1800 | H3DORLOG(("H3DORGeometry: geometry not changed\n"));
|
---|
1801 | /* Do nothing. Continue using the existing handle. */
|
---|
1802 | }
|
---|
1803 | else
|
---|
1804 | {
|
---|
1805 | int rc = p->fFallback?
|
---|
1806 | VERR_NOT_SUPPORTED: /* Try to go out of fallback mode. */
|
---|
1807 | p->pThis->m_interfaceImage.VRDEImageGeometrySet(p->hImageBitmap, &rect);
|
---|
1808 | if (RT_SUCCESS(rc))
|
---|
1809 | {
|
---|
1810 | p->x = x;
|
---|
1811 | p->y = y;
|
---|
1812 | p->w = w;
|
---|
1813 | p->h = h;
|
---|
1814 | }
|
---|
1815 | else
|
---|
1816 | {
|
---|
1817 | /* The handle must be recreated. Delete existing handle here. */
|
---|
1818 | p->pThis->m_interfaceImage.VRDEImageHandleClose(p->hImageBitmap);
|
---|
1819 | p->hImageBitmap = NULL;
|
---|
1820 | }
|
---|
1821 | }
|
---|
1822 | }
|
---|
1823 |
|
---|
1824 | if (!p->hImageBitmap)
|
---|
1825 | {
|
---|
1826 | /* Create a new bitmap handle. */
|
---|
1827 | uint32_t u32ScreenId = 0; /* @todo clip to corresponding screens.
|
---|
1828 | * Clipping can be done here or in VRDP server.
|
---|
1829 | * If VRDP does clipping, then uScreenId parameter
|
---|
1830 | * is not necessary and coords must be global.
|
---|
1831 | * (have to check which coords are used in opengl service).
|
---|
1832 | * Since all VRDE API uses a ScreenId,
|
---|
1833 | * the clipping must be done here in ConsoleVRDPServer
|
---|
1834 | */
|
---|
1835 | uint32_t fu32CompletionFlags = 0;
|
---|
1836 | p->fFallback = false;
|
---|
1837 | int rc = p->pThis->m_interfaceImage.VRDEImageHandleCreate(p->pThis->mhServer,
|
---|
1838 | &p->hImageBitmap,
|
---|
1839 | p,
|
---|
1840 | u32ScreenId,
|
---|
1841 | VRDE_IMAGE_F_CREATE_CONTENT_3D
|
---|
1842 | | VRDE_IMAGE_F_CREATE_WINDOW,
|
---|
1843 | &rect,
|
---|
1844 | VRDE_IMAGE_FMT_ID_BITMAP_BGRA8,
|
---|
1845 | NULL,
|
---|
1846 | 0,
|
---|
1847 | &fu32CompletionFlags);
|
---|
1848 | if (RT_FAILURE(rc))
|
---|
1849 | {
|
---|
1850 | /* No support for a 3D + WINDOW. Try bitmap updates. */
|
---|
1851 | H3DORLOG(("H3DORGeometry: Fallback to bitmaps\n"));
|
---|
1852 | fu32CompletionFlags = 0;
|
---|
1853 | p->fFallback = true;
|
---|
1854 | rc = p->pThis->m_interfaceImage.VRDEImageHandleCreate(p->pThis->mhServer,
|
---|
1855 | &p->hImageBitmap,
|
---|
1856 | p,
|
---|
1857 | u32ScreenId,
|
---|
1858 | 0,
|
---|
1859 | &rect,
|
---|
1860 | VRDE_IMAGE_FMT_ID_BITMAP_BGRA8,
|
---|
1861 | NULL,
|
---|
1862 | 0,
|
---|
1863 | &fu32CompletionFlags);
|
---|
1864 | }
|
---|
1865 |
|
---|
1866 | H3DORLOG(("H3DORGeometry: Image handle create %Rrc, flags 0x%RX32\n", rc, fu32CompletionFlags));
|
---|
1867 |
|
---|
1868 | if (RT_SUCCESS(rc))
|
---|
1869 | {
|
---|
1870 | p->x = x;
|
---|
1871 | p->y = y;
|
---|
1872 | p->w = w;
|
---|
1873 | p->h = h;
|
---|
1874 |
|
---|
1875 | if ((fu32CompletionFlags & VRDE_IMAGE_F_COMPLETE_ASYNC) == 0)
|
---|
1876 | {
|
---|
1877 | p->fCreated = true;
|
---|
1878 | }
|
---|
1879 | }
|
---|
1880 | else
|
---|
1881 | {
|
---|
1882 | p->hImageBitmap = NULL;
|
---|
1883 | p->w = 0;
|
---|
1884 | p->h = 0;
|
---|
1885 | }
|
---|
1886 | }
|
---|
1887 |
|
---|
1888 | H3DORLOG(("H3DORGeometry: ins %p completed\n", pvInstance));
|
---|
1889 | }
|
---|
1890 |
|
---|
1891 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORVisibleRegion(void *pvInstance,
|
---|
1892 | uint32_t cRects, const RTRECT *paRects)
|
---|
1893 | {
|
---|
1894 | H3DORLOG(("H3DORVisibleRegion: ins %p %d\n", pvInstance, cRects));
|
---|
1895 |
|
---|
1896 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
1897 | Assert(p);
|
---|
1898 | Assert(p->pThis);
|
---|
1899 |
|
---|
1900 | if (cRects == 0)
|
---|
1901 | {
|
---|
1902 | /* Complete image is visible. */
|
---|
1903 | RTRECT rect;
|
---|
1904 | rect.xLeft = p->x;
|
---|
1905 | rect.yTop = p->y;
|
---|
1906 | rect.xRight = p->x + p->w;
|
---|
1907 | rect.yBottom = p->y + p->h;
|
---|
1908 | p->pThis->m_interfaceImage.VRDEImageRegionSet (p->hImageBitmap,
|
---|
1909 | 1,
|
---|
1910 | &rect);
|
---|
1911 | }
|
---|
1912 | else
|
---|
1913 | {
|
---|
1914 | p->pThis->m_interfaceImage.VRDEImageRegionSet (p->hImageBitmap,
|
---|
1915 | cRects,
|
---|
1916 | paRects);
|
---|
1917 | }
|
---|
1918 |
|
---|
1919 | H3DORLOG(("H3DORVisibleRegion: ins %p completed\n", pvInstance));
|
---|
1920 | }
|
---|
1921 |
|
---|
1922 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DORFrame(void *pvInstance,
|
---|
1923 | void *pvData, uint32_t cbData)
|
---|
1924 | {
|
---|
1925 | H3DORLOG(("H3DORFrame: ins %p %p %d\n", pvInstance, pvData, cbData));
|
---|
1926 |
|
---|
1927 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
1928 | Assert(p);
|
---|
1929 | Assert(p->pThis);
|
---|
1930 |
|
---|
1931 | /* Currently only a topdown BGR0 bitmap format is supported. */
|
---|
1932 | VRDEIMAGEBITMAP image;
|
---|
1933 |
|
---|
1934 | image.cWidth = p->w;
|
---|
1935 | image.cHeight = p->h;
|
---|
1936 | image.pvData = pvData;
|
---|
1937 | image.cbData = cbData;
|
---|
1938 | image.pvScanLine0 = (uint8_t *)pvData + (p->h - 1) * p->w * 4;
|
---|
1939 | image.iScanDelta = -4 * p->w;
|
---|
1940 |
|
---|
1941 | p->pThis->m_interfaceImage.VRDEImageUpdate (p->hImageBitmap,
|
---|
1942 | p->x,
|
---|
1943 | p->y,
|
---|
1944 | p->w,
|
---|
1945 | p->h,
|
---|
1946 | &image,
|
---|
1947 | sizeof(VRDEIMAGEBITMAP));
|
---|
1948 |
|
---|
1949 | H3DORLOG(("H3DORFrame: ins %p completed\n", pvInstance));
|
---|
1950 | }
|
---|
1951 |
|
---|
1952 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::H3DOREnd(void *pvInstance)
|
---|
1953 | {
|
---|
1954 | H3DORLOG(("H3DOREnd: ins %p\n", pvInstance));
|
---|
1955 |
|
---|
1956 | H3DORInstance *p = (H3DORInstance *)pvInstance;
|
---|
1957 | Assert(p);
|
---|
1958 | Assert(p->pThis);
|
---|
1959 |
|
---|
1960 | p->pThis->m_interfaceImage.VRDEImageHandleClose(p->hImageBitmap);
|
---|
1961 |
|
---|
1962 | RTMemFree(p);
|
---|
1963 |
|
---|
1964 | H3DORLOG(("H3DOREnd: ins %p completed\n", pvInstance));
|
---|
1965 | }
|
---|
1966 |
|
---|
1967 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::H3DORContextProperty(const void *pvContext, uint32_t index,
|
---|
1968 | void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut)
|
---|
1969 | {
|
---|
1970 | int rc = VINF_SUCCESS;
|
---|
1971 |
|
---|
1972 | H3DORLOG(("H3DORContextProperty: index %d\n", index));
|
---|
1973 |
|
---|
1974 | if (index == H3DOR_PROP_FORMATS)
|
---|
1975 | {
|
---|
1976 | /* Return a comma separated list of supported formats. */
|
---|
1977 | static const char *pszSupportedFormats = H3DOR_FMT_RGBA_TOPDOWN;
|
---|
1978 | uint32_t cbOut = (uint32_t)strlen(pszSupportedFormats) + 1;
|
---|
1979 | if (cbOut <= cbBuffer)
|
---|
1980 | {
|
---|
1981 | memcpy(pvBuffer, pszSupportedFormats, cbOut);
|
---|
1982 | }
|
---|
1983 | else
|
---|
1984 | {
|
---|
1985 | rc = VERR_BUFFER_OVERFLOW;
|
---|
1986 | }
|
---|
1987 | *pcbOut = cbOut;
|
---|
1988 | }
|
---|
1989 | else
|
---|
1990 | {
|
---|
1991 | rc = VERR_NOT_SUPPORTED;
|
---|
1992 | }
|
---|
1993 |
|
---|
1994 | H3DORLOG(("H3DORContextProperty: %Rrc\n", rc));
|
---|
1995 | return rc;
|
---|
1996 | }
|
---|
1997 |
|
---|
1998 | void ConsoleVRDPServer::remote3DRedirect(void)
|
---|
1999 | {
|
---|
2000 | if (!m_fInterfaceImage)
|
---|
2001 | {
|
---|
2002 | /* No redirect without corresponding interface. */
|
---|
2003 | return;
|
---|
2004 | }
|
---|
2005 |
|
---|
2006 | /* Check if 3D redirection has been enabled. */
|
---|
2007 | com::Bstr bstr;
|
---|
2008 | HRESULT hrc = mConsole->getVRDEServer()->GetVRDEProperty(Bstr("H3DRedirect/Enabled").raw(), bstr.asOutParam());
|
---|
2009 |
|
---|
2010 | if (hrc != S_OK)
|
---|
2011 | {
|
---|
2012 | bstr = "";
|
---|
2013 | }
|
---|
2014 |
|
---|
2015 | com::Utf8Str value = bstr;
|
---|
2016 |
|
---|
2017 | bool fEnabled = RTStrICmp(value.c_str(), "true") == 0
|
---|
2018 | || RTStrICmp(value.c_str(), "1") == 0;
|
---|
2019 |
|
---|
2020 | if (!fEnabled)
|
---|
2021 | {
|
---|
2022 | return;
|
---|
2023 | }
|
---|
2024 |
|
---|
2025 | /* Tell the host 3D service to redirect output using the ConsoleVRDPServer callbacks. */
|
---|
2026 | H3DOUTPUTREDIRECT outputRedirect =
|
---|
2027 | {
|
---|
2028 | this,
|
---|
2029 | H3DORBegin,
|
---|
2030 | H3DORGeometry,
|
---|
2031 | H3DORVisibleRegion,
|
---|
2032 | H3DORFrame,
|
---|
2033 | H3DOREnd,
|
---|
2034 | H3DORContextProperty
|
---|
2035 | };
|
---|
2036 |
|
---|
2037 | VBOXHGCMSVCPARM parm;
|
---|
2038 |
|
---|
2039 | parm.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2040 | parm.u.pointer.addr = &outputRedirect;
|
---|
2041 | parm.u.pointer.size = sizeof(outputRedirect);
|
---|
2042 |
|
---|
2043 | VMMDev *pVMMDev = mConsole->getVMMDev();
|
---|
2044 |
|
---|
2045 | if (!pVMMDev)
|
---|
2046 | {
|
---|
2047 | AssertMsgFailed(("remote3DRedirect no vmmdev\n"));
|
---|
2048 | return;
|
---|
2049 | }
|
---|
2050 |
|
---|
2051 | int rc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL",
|
---|
2052 | SHCRGL_HOST_FN_SET_OUTPUT_REDIRECT,
|
---|
2053 | SHCRGL_CPARMS_SET_OUTPUT_REDIRECT,
|
---|
2054 | &parm);
|
---|
2055 |
|
---|
2056 | if (!RT_SUCCESS(rc))
|
---|
2057 | {
|
---|
2058 | AssertMsgFailed(("SHCRGL_HOST_FN_SET_CONSOLE failed with %Rrc\n", rc));
|
---|
2059 | return;
|
---|
2060 | }
|
---|
2061 |
|
---|
2062 | LogRel(("VRDE: Enabled 3D redirect.\n"));
|
---|
2063 |
|
---|
2064 | return;
|
---|
2065 | }
|
---|
2066 |
|
---|
2067 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDEImageCbNotify (void *pvContext,
|
---|
2068 | void *pvUser,
|
---|
2069 | HVRDEIMAGE hVideo,
|
---|
2070 | uint32_t u32Id,
|
---|
2071 | void *pvData,
|
---|
2072 | uint32_t cbData)
|
---|
2073 | {
|
---|
2074 | H3DORLOG(("H3DOR: VRDEImageCbNotify: pvContext %p, pvUser %p, hVideo %p, u32Id %u, pvData %p, cbData %d\n",
|
---|
2075 | pvContext, pvUser, hVideo, u32Id, pvData, cbData));
|
---|
2076 |
|
---|
2077 | ConsoleVRDPServer *pServer = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2078 | H3DORInstance *p = (H3DORInstance *)pvUser;
|
---|
2079 | Assert(p);
|
---|
2080 | Assert(p->pThis);
|
---|
2081 | Assert(p->pThis == pServer);
|
---|
2082 |
|
---|
2083 | if (u32Id == VRDE_IMAGE_NOTIFY_HANDLE_CREATE)
|
---|
2084 | {
|
---|
2085 | if (cbData != sizeof(uint32_t))
|
---|
2086 | {
|
---|
2087 | AssertFailed();
|
---|
2088 | return VERR_INVALID_PARAMETER;
|
---|
2089 | }
|
---|
2090 |
|
---|
2091 | uint32_t u32StreamId = *(uint32_t *)pvData;
|
---|
2092 | H3DORLOG(("H3DOR: VRDE_IMAGE_NOTIFY_HANDLE_CREATE u32StreamId %d\n",
|
---|
2093 | u32StreamId));
|
---|
2094 |
|
---|
2095 | if (u32StreamId != 0)
|
---|
2096 | {
|
---|
2097 | p->fCreated = true; // @todo not needed?
|
---|
2098 | }
|
---|
2099 | else
|
---|
2100 | {
|
---|
2101 | /* The stream has not been created. */
|
---|
2102 | }
|
---|
2103 | }
|
---|
2104 |
|
---|
2105 | return VINF_SUCCESS;
|
---|
2106 | }
|
---|
2107 |
|
---|
2108 | #undef H3DORLOG
|
---|
2109 |
|
---|
2110 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDESCardCbNotify(void *pvContext,
|
---|
2111 | uint32_t u32Id,
|
---|
2112 | void *pvData,
|
---|
2113 | uint32_t cbData)
|
---|
2114 | {
|
---|
2115 | #ifdef VBOX_WITH_USB_CARDREADER
|
---|
2116 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2117 | UsbCardReader *pReader = pThis->mConsole->getUsbCardReader();
|
---|
2118 | return pReader->VRDENotify(u32Id, pvData, cbData);
|
---|
2119 | #else
|
---|
2120 | NOREF(pvContext);
|
---|
2121 | NOREF(u32Id);
|
---|
2122 | NOREF(pvData);
|
---|
2123 | NOREF(cbData);
|
---|
2124 | return VERR_NOT_SUPPORTED;
|
---|
2125 | #endif
|
---|
2126 | }
|
---|
2127 |
|
---|
2128 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::VRDESCardCbResponse(void *pvContext,
|
---|
2129 | int rcRequest,
|
---|
2130 | void *pvUser,
|
---|
2131 | uint32_t u32Function,
|
---|
2132 | void *pvData,
|
---|
2133 | uint32_t cbData)
|
---|
2134 | {
|
---|
2135 | #ifdef VBOX_WITH_USB_CARDREADER
|
---|
2136 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2137 | UsbCardReader *pReader = pThis->mConsole->getUsbCardReader();
|
---|
2138 | return pReader->VRDEResponse(rcRequest, pvUser, u32Function, pvData, cbData);
|
---|
2139 | #else
|
---|
2140 | NOREF(pvContext);
|
---|
2141 | NOREF(rcRequest);
|
---|
2142 | NOREF(pvUser);
|
---|
2143 | NOREF(u32Function);
|
---|
2144 | NOREF(pvData);
|
---|
2145 | NOREF(cbData);
|
---|
2146 | return VERR_NOT_SUPPORTED;
|
---|
2147 | #endif
|
---|
2148 | }
|
---|
2149 |
|
---|
2150 | int ConsoleVRDPServer::SCardRequest(void *pvUser, uint32_t u32Function, const void *pvData, uint32_t cbData)
|
---|
2151 | {
|
---|
2152 | int rc = VINF_SUCCESS;
|
---|
2153 |
|
---|
2154 | if (mhServer && mpEntryPoints && m_interfaceSCard.VRDESCardRequest)
|
---|
2155 | {
|
---|
2156 | rc = m_interfaceSCard.VRDESCardRequest(mhServer, pvUser, u32Function, pvData, cbData);
|
---|
2157 | }
|
---|
2158 | else
|
---|
2159 | {
|
---|
2160 | rc = VERR_NOT_SUPPORTED;
|
---|
2161 | }
|
---|
2162 |
|
---|
2163 | return rc;
|
---|
2164 | }
|
---|
2165 |
|
---|
2166 |
|
---|
2167 | struct TSMFHOSTCHCTX;
|
---|
2168 | struct TSMFVRDPCTX;
|
---|
2169 |
|
---|
2170 | typedef struct TSMFHOSTCHCTX
|
---|
2171 | {
|
---|
2172 | ConsoleVRDPServer *pThis;
|
---|
2173 |
|
---|
2174 | struct TSMFVRDPCTX *pVRDPCtx; /* NULL if no corresponding host channel context. */
|
---|
2175 |
|
---|
2176 | void *pvDataReceived;
|
---|
2177 | uint32_t cbDataReceived;
|
---|
2178 | uint32_t cbDataAllocated;
|
---|
2179 | } TSMFHOSTCHCTX;
|
---|
2180 |
|
---|
2181 | typedef struct TSMFVRDPCTX
|
---|
2182 | {
|
---|
2183 | ConsoleVRDPServer *pThis;
|
---|
2184 |
|
---|
2185 | VBOXHOSTCHANNELCALLBACKS *pCallbacks;
|
---|
2186 | void *pvCallbacks;
|
---|
2187 |
|
---|
2188 | TSMFHOSTCHCTX *pHostChCtx; /* NULL if no corresponding host channel context. */
|
---|
2189 |
|
---|
2190 | uint32_t u32ChannelHandle;
|
---|
2191 | } TSMFVRDPCTX;
|
---|
2192 |
|
---|
2193 | static int tsmfContextsAlloc(TSMFHOSTCHCTX **ppHostChCtx, TSMFVRDPCTX **ppVRDPCtx)
|
---|
2194 | {
|
---|
2195 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)RTMemAllocZ(sizeof(TSMFHOSTCHCTX));
|
---|
2196 | if (!pHostChCtx)
|
---|
2197 | {
|
---|
2198 | return VERR_NO_MEMORY;
|
---|
2199 | }
|
---|
2200 |
|
---|
2201 | TSMFVRDPCTX *pVRDPCtx = (TSMFVRDPCTX *)RTMemAllocZ(sizeof(TSMFVRDPCTX));
|
---|
2202 | if (!pVRDPCtx)
|
---|
2203 | {
|
---|
2204 | RTMemFree(pHostChCtx);
|
---|
2205 | return VERR_NO_MEMORY;
|
---|
2206 | }
|
---|
2207 |
|
---|
2208 | *ppHostChCtx = pHostChCtx;
|
---|
2209 | *ppVRDPCtx = pVRDPCtx;
|
---|
2210 | return VINF_SUCCESS;
|
---|
2211 | }
|
---|
2212 |
|
---|
2213 | int ConsoleVRDPServer::tsmfLock(void)
|
---|
2214 | {
|
---|
2215 | int rc = RTCritSectEnter(&mTSMFLock);
|
---|
2216 | AssertRC(rc);
|
---|
2217 | return rc;
|
---|
2218 | }
|
---|
2219 |
|
---|
2220 | void ConsoleVRDPServer::tsmfUnlock(void)
|
---|
2221 | {
|
---|
2222 | RTCritSectLeave(&mTSMFLock);
|
---|
2223 | }
|
---|
2224 |
|
---|
2225 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelAttach(void *pvProvider,
|
---|
2226 | void **ppvChannel,
|
---|
2227 | uint32_t u32Flags,
|
---|
2228 | VBOXHOSTCHANNELCALLBACKS *pCallbacks,
|
---|
2229 | void *pvCallbacks)
|
---|
2230 | {
|
---|
2231 | LogFlowFunc(("\n"));
|
---|
2232 |
|
---|
2233 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvProvider);
|
---|
2234 |
|
---|
2235 | /* Create 2 context structures: for the VRDP server and for the host service. */
|
---|
2236 | TSMFHOSTCHCTX *pHostChCtx = NULL;
|
---|
2237 | TSMFVRDPCTX *pVRDPCtx = NULL;
|
---|
2238 |
|
---|
2239 | int rc = tsmfContextsAlloc(&pHostChCtx, &pVRDPCtx);
|
---|
2240 | if (RT_FAILURE(rc))
|
---|
2241 | {
|
---|
2242 | return rc;
|
---|
2243 | }
|
---|
2244 |
|
---|
2245 | pHostChCtx->pThis = pThis;
|
---|
2246 | pHostChCtx->pVRDPCtx = pVRDPCtx;
|
---|
2247 |
|
---|
2248 | pVRDPCtx->pThis = pThis;
|
---|
2249 | pVRDPCtx->pCallbacks = pCallbacks;
|
---|
2250 | pVRDPCtx->pvCallbacks = pvCallbacks;
|
---|
2251 | pVRDPCtx->pHostChCtx = pHostChCtx;
|
---|
2252 |
|
---|
2253 | rc = pThis->m_interfaceTSMF.VRDETSMFChannelCreate(pThis->mhServer, pVRDPCtx, u32Flags);
|
---|
2254 |
|
---|
2255 | if (RT_SUCCESS(rc))
|
---|
2256 | {
|
---|
2257 | /* @todo contexts should be in a list for accounting. */
|
---|
2258 | *ppvChannel = pHostChCtx;
|
---|
2259 | }
|
---|
2260 | else
|
---|
2261 | {
|
---|
2262 | RTMemFree(pHostChCtx);
|
---|
2263 | RTMemFree(pVRDPCtx);
|
---|
2264 | }
|
---|
2265 |
|
---|
2266 | return rc;
|
---|
2267 | }
|
---|
2268 |
|
---|
2269 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::tsmfHostChannelDetach(void *pvChannel)
|
---|
2270 | {
|
---|
2271 | LogFlowFunc(("\n"));
|
---|
2272 |
|
---|
2273 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
|
---|
2274 | ConsoleVRDPServer *pThis = pHostChCtx->pThis;
|
---|
2275 |
|
---|
2276 | int rc = pThis->tsmfLock();
|
---|
2277 | if (RT_SUCCESS(rc))
|
---|
2278 | {
|
---|
2279 | bool fClose = false;
|
---|
2280 | uint32_t u32ChannelHandle = 0;
|
---|
2281 |
|
---|
2282 | if (pHostChCtx->pVRDPCtx)
|
---|
2283 | {
|
---|
2284 | /* There is still a VRDP context for this channel. */
|
---|
2285 | pHostChCtx->pVRDPCtx->pHostChCtx = NULL;
|
---|
2286 | u32ChannelHandle = pHostChCtx->pVRDPCtx->u32ChannelHandle;
|
---|
2287 | fClose = true;
|
---|
2288 | }
|
---|
2289 |
|
---|
2290 | pThis->tsmfUnlock();
|
---|
2291 |
|
---|
2292 | RTMemFree(pHostChCtx);
|
---|
2293 |
|
---|
2294 | if (fClose)
|
---|
2295 | {
|
---|
2296 | LogFlowFunc(("Closing VRDE channel %d.\n", u32ChannelHandle));
|
---|
2297 | pThis->m_interfaceTSMF.VRDETSMFChannelClose(pThis->mhServer, u32ChannelHandle);
|
---|
2298 | }
|
---|
2299 | else
|
---|
2300 | {
|
---|
2301 | LogFlowFunc(("No VRDE channel.\n"));
|
---|
2302 | }
|
---|
2303 | }
|
---|
2304 | }
|
---|
2305 |
|
---|
2306 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelSend(void *pvChannel,
|
---|
2307 | const void *pvData,
|
---|
2308 | uint32_t cbData)
|
---|
2309 | {
|
---|
2310 | LogFlowFunc(("cbData %d\n", cbData));
|
---|
2311 |
|
---|
2312 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
|
---|
2313 | ConsoleVRDPServer *pThis = pHostChCtx->pThis;
|
---|
2314 |
|
---|
2315 | int rc = pThis->tsmfLock();
|
---|
2316 | if (RT_SUCCESS(rc))
|
---|
2317 | {
|
---|
2318 | bool fSend = false;
|
---|
2319 | uint32_t u32ChannelHandle = 0;
|
---|
2320 |
|
---|
2321 | if (pHostChCtx->pVRDPCtx)
|
---|
2322 | {
|
---|
2323 | u32ChannelHandle = pHostChCtx->pVRDPCtx->u32ChannelHandle;
|
---|
2324 | fSend = true;
|
---|
2325 | }
|
---|
2326 |
|
---|
2327 | pThis->tsmfUnlock();
|
---|
2328 |
|
---|
2329 | if (fSend)
|
---|
2330 | {
|
---|
2331 | LogFlowFunc(("Send to VRDE channel %d.\n", u32ChannelHandle));
|
---|
2332 | rc = pThis->m_interfaceTSMF.VRDETSMFChannelSend(pThis->mhServer, u32ChannelHandle,
|
---|
2333 | pvData, cbData);
|
---|
2334 | }
|
---|
2335 | }
|
---|
2336 |
|
---|
2337 | return rc;
|
---|
2338 | }
|
---|
2339 |
|
---|
2340 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelRecv(void *pvChannel,
|
---|
2341 | void *pvData,
|
---|
2342 | uint32_t cbData,
|
---|
2343 | uint32_t *pcbReceived,
|
---|
2344 | uint32_t *pcbRemaining)
|
---|
2345 | {
|
---|
2346 | LogFlowFunc(("cbData %d\n", cbData));
|
---|
2347 |
|
---|
2348 | TSMFHOSTCHCTX *pHostChCtx = (TSMFHOSTCHCTX *)pvChannel;
|
---|
2349 | ConsoleVRDPServer *pThis = pHostChCtx->pThis;
|
---|
2350 |
|
---|
2351 | int rc = pThis->tsmfLock();
|
---|
2352 | if (RT_SUCCESS(rc))
|
---|
2353 | {
|
---|
2354 | uint32_t cbToCopy = RT_MIN(cbData, pHostChCtx->cbDataReceived);
|
---|
2355 | uint32_t cbRemaining = pHostChCtx->cbDataReceived - cbToCopy;
|
---|
2356 |
|
---|
2357 | LogFlowFunc(("cbToCopy %d, cbRemaining %d\n", cbToCopy, cbRemaining));
|
---|
2358 |
|
---|
2359 | if (cbToCopy != 0)
|
---|
2360 | {
|
---|
2361 | memcpy(pvData, pHostChCtx->pvDataReceived, cbToCopy);
|
---|
2362 |
|
---|
2363 | if (cbRemaining != 0)
|
---|
2364 | {
|
---|
2365 | memmove(pHostChCtx->pvDataReceived, (uint8_t *)pHostChCtx->pvDataReceived + cbToCopy, cbRemaining);
|
---|
2366 | }
|
---|
2367 |
|
---|
2368 | pHostChCtx->cbDataReceived = cbRemaining;
|
---|
2369 | }
|
---|
2370 |
|
---|
2371 | pThis->tsmfUnlock();
|
---|
2372 |
|
---|
2373 | *pcbRemaining = cbRemaining;
|
---|
2374 | *pcbReceived = cbToCopy;
|
---|
2375 | }
|
---|
2376 |
|
---|
2377 | return rc;
|
---|
2378 | }
|
---|
2379 |
|
---|
2380 | /* static */ DECLCALLBACK(int) ConsoleVRDPServer::tsmfHostChannelControl(void *pvChannel,
|
---|
2381 | uint32_t u32Code,
|
---|
2382 | const void *pvParm,
|
---|
2383 | uint32_t cbParm,
|
---|
2384 | const void *pvData,
|
---|
2385 | uint32_t cbData,
|
---|
2386 | uint32_t *pcbDataReturned)
|
---|
2387 | {
|
---|
2388 | LogFlowFunc(("u32Code %u\n", u32Code));
|
---|
2389 |
|
---|
2390 | if (!pvChannel)
|
---|
2391 | {
|
---|
2392 | /* Special case, the provider must answer rather than a channel instance. */
|
---|
2393 | if (u32Code == VBOX_HOST_CHANNEL_CTRL_EXISTS)
|
---|
2394 | {
|
---|
2395 | *pcbDataReturned = 0;
|
---|
2396 | return VINF_SUCCESS;
|
---|
2397 | }
|
---|
2398 |
|
---|
2399 | return VERR_NOT_IMPLEMENTED;
|
---|
2400 | }
|
---|
2401 |
|
---|
2402 | /* Channels do not support this. */
|
---|
2403 | return VERR_NOT_IMPLEMENTED;
|
---|
2404 | }
|
---|
2405 |
|
---|
2406 |
|
---|
2407 | void ConsoleVRDPServer::setupTSMF(void)
|
---|
2408 | {
|
---|
2409 | if (m_interfaceTSMF.header.u64Size == 0)
|
---|
2410 | {
|
---|
2411 | return;
|
---|
2412 | }
|
---|
2413 |
|
---|
2414 | /* Register with the host channel service. */
|
---|
2415 | VBOXHOSTCHANNELINTERFACE hostChannelInterface =
|
---|
2416 | {
|
---|
2417 | this,
|
---|
2418 | tsmfHostChannelAttach,
|
---|
2419 | tsmfHostChannelDetach,
|
---|
2420 | tsmfHostChannelSend,
|
---|
2421 | tsmfHostChannelRecv,
|
---|
2422 | tsmfHostChannelControl
|
---|
2423 | };
|
---|
2424 |
|
---|
2425 | VBoxHostChannelHostRegister parms;
|
---|
2426 |
|
---|
2427 | static char szProviderName[] = "/vrde/tsmf";
|
---|
2428 |
|
---|
2429 | parms.name.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2430 | parms.name.u.pointer.addr = &szProviderName[0];
|
---|
2431 | parms.name.u.pointer.size = sizeof(szProviderName);
|
---|
2432 |
|
---|
2433 | parms.iface.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2434 | parms.iface.u.pointer.addr = &hostChannelInterface;
|
---|
2435 | parms.iface.u.pointer.size = sizeof(hostChannelInterface);
|
---|
2436 |
|
---|
2437 | VMMDev *pVMMDev = mConsole->getVMMDev();
|
---|
2438 |
|
---|
2439 | if (!pVMMDev)
|
---|
2440 | {
|
---|
2441 | AssertMsgFailed(("setupTSMF no vmmdev\n"));
|
---|
2442 | return;
|
---|
2443 | }
|
---|
2444 |
|
---|
2445 | int rc = pVMMDev->hgcmHostCall("VBoxHostChannel",
|
---|
2446 | VBOX_HOST_CHANNEL_HOST_FN_REGISTER,
|
---|
2447 | 2,
|
---|
2448 | &parms.name);
|
---|
2449 |
|
---|
2450 | if (!RT_SUCCESS(rc))
|
---|
2451 | {
|
---|
2452 | Log(("VBOX_HOST_CHANNEL_HOST_FN_REGISTER failed with %Rrc\n", rc));
|
---|
2453 | return;
|
---|
2454 | }
|
---|
2455 |
|
---|
2456 | LogRel(("VRDE: Enabled TSMF channel.\n"));
|
---|
2457 |
|
---|
2458 | return;
|
---|
2459 | }
|
---|
2460 |
|
---|
2461 | /* @todo these defines must be in a header, which is used by guest component as well. */
|
---|
2462 | #define VBOX_TSMF_HCH_CREATE_ACCEPTED (VBOX_HOST_CHANNEL_EVENT_USER + 0)
|
---|
2463 | #define VBOX_TSMF_HCH_CREATE_DECLINED (VBOX_HOST_CHANNEL_EVENT_USER + 1)
|
---|
2464 | #define VBOX_TSMF_HCH_DISCONNECTED (VBOX_HOST_CHANNEL_EVENT_USER + 2)
|
---|
2465 |
|
---|
2466 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDETSMFCbNotify(void *pvContext,
|
---|
2467 | uint32_t u32Notification,
|
---|
2468 | void *pvChannel,
|
---|
2469 | const void *pvParm,
|
---|
2470 | uint32_t cbParm)
|
---|
2471 | {
|
---|
2472 | int rc = VINF_SUCCESS;
|
---|
2473 |
|
---|
2474 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvContext);
|
---|
2475 |
|
---|
2476 | TSMFVRDPCTX *pVRDPCtx = (TSMFVRDPCTX *)pvChannel;
|
---|
2477 |
|
---|
2478 | Assert(pVRDPCtx->pThis == pThis);
|
---|
2479 |
|
---|
2480 | if (pVRDPCtx->pCallbacks == NULL)
|
---|
2481 | {
|
---|
2482 | LogFlowFunc(("tsmfHostChannel: Channel disconnected. Skipping.\n"));
|
---|
2483 | return;
|
---|
2484 | }
|
---|
2485 |
|
---|
2486 | switch (u32Notification)
|
---|
2487 | {
|
---|
2488 | case VRDE_TSMF_N_CREATE_ACCEPTED:
|
---|
2489 | {
|
---|
2490 | VRDETSMFNOTIFYCREATEACCEPTED *p = (VRDETSMFNOTIFYCREATEACCEPTED *)pvParm;
|
---|
2491 | Assert(cbParm == sizeof(VRDETSMFNOTIFYCREATEACCEPTED));
|
---|
2492 |
|
---|
2493 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_CREATE_ACCEPTED(%p): p->u32ChannelHandle %d\n",
|
---|
2494 | pVRDPCtx, p->u32ChannelHandle));
|
---|
2495 |
|
---|
2496 | pVRDPCtx->u32ChannelHandle = p->u32ChannelHandle;
|
---|
2497 |
|
---|
2498 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2499 | VBOX_TSMF_HCH_CREATE_ACCEPTED,
|
---|
2500 | NULL, 0);
|
---|
2501 | } break;
|
---|
2502 |
|
---|
2503 | case VRDE_TSMF_N_CREATE_DECLINED:
|
---|
2504 | {
|
---|
2505 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_CREATE_DECLINED(%p)\n", pVRDPCtx));
|
---|
2506 |
|
---|
2507 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2508 | VBOX_TSMF_HCH_CREATE_DECLINED,
|
---|
2509 | NULL, 0);
|
---|
2510 | } break;
|
---|
2511 |
|
---|
2512 | case VRDE_TSMF_N_DATA:
|
---|
2513 | {
|
---|
2514 | /* Save the data in the intermediate buffer and send the event. */
|
---|
2515 | VRDETSMFNOTIFYDATA *p = (VRDETSMFNOTIFYDATA *)pvParm;
|
---|
2516 | Assert(cbParm == sizeof(VRDETSMFNOTIFYDATA));
|
---|
2517 |
|
---|
2518 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DATA(%p): p->cbData %d\n", pVRDPCtx, p->cbData));
|
---|
2519 |
|
---|
2520 | VBOXHOSTCHANNELEVENTRECV ev;
|
---|
2521 | ev.u32SizeAvailable = 0;
|
---|
2522 |
|
---|
2523 | rc = pThis->tsmfLock();
|
---|
2524 |
|
---|
2525 | if (RT_SUCCESS(rc))
|
---|
2526 | {
|
---|
2527 | TSMFHOSTCHCTX *pHostChCtx = pVRDPCtx->pHostChCtx;
|
---|
2528 |
|
---|
2529 | if (pHostChCtx)
|
---|
2530 | {
|
---|
2531 | if (pHostChCtx->pvDataReceived)
|
---|
2532 | {
|
---|
2533 | uint32_t cbAlloc = p->cbData + pHostChCtx->cbDataReceived;
|
---|
2534 | pHostChCtx->pvDataReceived = RTMemRealloc(pHostChCtx->pvDataReceived, cbAlloc);
|
---|
2535 | memcpy((uint8_t *)pHostChCtx->pvDataReceived + pHostChCtx->cbDataReceived, p->pvData, p->cbData);
|
---|
2536 |
|
---|
2537 | pHostChCtx->cbDataReceived += p->cbData;
|
---|
2538 | pHostChCtx->cbDataAllocated = cbAlloc;
|
---|
2539 | }
|
---|
2540 | else
|
---|
2541 | {
|
---|
2542 | pHostChCtx->pvDataReceived = RTMemAlloc(p->cbData);
|
---|
2543 | memcpy(pHostChCtx->pvDataReceived, p->pvData, p->cbData);
|
---|
2544 |
|
---|
2545 | pHostChCtx->cbDataReceived = p->cbData;
|
---|
2546 | pHostChCtx->cbDataAllocated = p->cbData;
|
---|
2547 | }
|
---|
2548 |
|
---|
2549 | ev.u32SizeAvailable = p->cbData;
|
---|
2550 | }
|
---|
2551 | else
|
---|
2552 | {
|
---|
2553 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DATA: no host channel. Skipping\n"));
|
---|
2554 | }
|
---|
2555 |
|
---|
2556 | pThis->tsmfUnlock();
|
---|
2557 | }
|
---|
2558 |
|
---|
2559 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2560 | VBOX_HOST_CHANNEL_EVENT_RECV,
|
---|
2561 | &ev, sizeof(ev));
|
---|
2562 | } break;
|
---|
2563 |
|
---|
2564 | case VRDE_TSMF_N_DISCONNECTED:
|
---|
2565 | {
|
---|
2566 | LogFlowFunc(("tsmfHostChannel: VRDE_TSMF_N_DISCONNECTED(%p)\n", pVRDPCtx));
|
---|
2567 |
|
---|
2568 | pVRDPCtx->pCallbacks->HostChannelCallbackEvent(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx,
|
---|
2569 | VBOX_TSMF_HCH_DISCONNECTED,
|
---|
2570 | NULL, 0);
|
---|
2571 |
|
---|
2572 | /* The callback context will not be used anymore. */
|
---|
2573 | pVRDPCtx->pCallbacks->HostChannelCallbackDeleted(pVRDPCtx->pvCallbacks, pVRDPCtx->pHostChCtx);
|
---|
2574 | pVRDPCtx->pCallbacks = NULL;
|
---|
2575 | pVRDPCtx->pvCallbacks = NULL;
|
---|
2576 |
|
---|
2577 | rc = pThis->tsmfLock();
|
---|
2578 | if (RT_SUCCESS(rc))
|
---|
2579 | {
|
---|
2580 | if (pVRDPCtx->pHostChCtx)
|
---|
2581 | {
|
---|
2582 | /* There is still a host channel context for this channel. */
|
---|
2583 | pVRDPCtx->pHostChCtx->pVRDPCtx = NULL;
|
---|
2584 | }
|
---|
2585 |
|
---|
2586 | pThis->tsmfUnlock();
|
---|
2587 |
|
---|
2588 | RT_ZERO(*pVRDPCtx);
|
---|
2589 | RTMemFree(pVRDPCtx);
|
---|
2590 | }
|
---|
2591 | } break;
|
---|
2592 |
|
---|
2593 | default:
|
---|
2594 | {
|
---|
2595 | AssertFailed();
|
---|
2596 | } break;
|
---|
2597 | }
|
---|
2598 | }
|
---|
2599 |
|
---|
2600 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInNotify(void *pvCallback,
|
---|
2601 | uint32_t u32Id,
|
---|
2602 | const void *pvData,
|
---|
2603 | uint32_t cbData)
|
---|
2604 | {
|
---|
2605 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
2606 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2607 | EmWebcam *pWebcam = pThis->mConsole->getEmWebcam();
|
---|
2608 | pWebcam->EmWebcamCbNotify(u32Id, pvData, cbData);
|
---|
2609 | #else
|
---|
2610 | NOREF(pvCallback);
|
---|
2611 | NOREF(u32Id);
|
---|
2612 | NOREF(pvData);
|
---|
2613 | NOREF(cbData);
|
---|
2614 | #endif
|
---|
2615 | }
|
---|
2616 |
|
---|
2617 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInDeviceDesc(void *pvCallback,
|
---|
2618 | int rcRequest,
|
---|
2619 | void *pDeviceCtx,
|
---|
2620 | void *pvUser,
|
---|
2621 | const VRDEVIDEOINDEVICEDESC *pDeviceDesc,
|
---|
2622 | uint32_t cbDevice)
|
---|
2623 | {
|
---|
2624 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
2625 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2626 | EmWebcam *pWebcam = pThis->mConsole->getEmWebcam();
|
---|
2627 | pWebcam->EmWebcamCbDeviceDesc(rcRequest, pDeviceCtx, pvUser, pDeviceDesc, cbDevice);
|
---|
2628 | #else
|
---|
2629 | NOREF(pvCallback);
|
---|
2630 | NOREF(rcRequest);
|
---|
2631 | NOREF(pDeviceCtx);
|
---|
2632 | NOREF(pvUser);
|
---|
2633 | NOREF(pDeviceDesc);
|
---|
2634 | NOREF(cbDevice);
|
---|
2635 | #endif
|
---|
2636 | }
|
---|
2637 |
|
---|
2638 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInControl(void *pvCallback,
|
---|
2639 | int rcRequest,
|
---|
2640 | void *pDeviceCtx,
|
---|
2641 | void *pvUser,
|
---|
2642 | const VRDEVIDEOINCTRLHDR *pControl,
|
---|
2643 | uint32_t cbControl)
|
---|
2644 | {
|
---|
2645 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
2646 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2647 | EmWebcam *pWebcam = pThis->mConsole->getEmWebcam();
|
---|
2648 | pWebcam->EmWebcamCbControl(rcRequest, pDeviceCtx, pvUser, pControl, cbControl);
|
---|
2649 | #else
|
---|
2650 | NOREF(pvCallback);
|
---|
2651 | NOREF(rcRequest);
|
---|
2652 | NOREF(pDeviceCtx);
|
---|
2653 | NOREF(pvUser);
|
---|
2654 | NOREF(pControl);
|
---|
2655 | NOREF(cbControl);
|
---|
2656 | #endif
|
---|
2657 | }
|
---|
2658 |
|
---|
2659 | /* static */ DECLCALLBACK(void) ConsoleVRDPServer::VRDECallbackVideoInFrame(void *pvCallback,
|
---|
2660 | int rcRequest,
|
---|
2661 | void *pDeviceCtx,
|
---|
2662 | const VRDEVIDEOINPAYLOADHDR *pFrame,
|
---|
2663 | uint32_t cbFrame)
|
---|
2664 | {
|
---|
2665 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
2666 | ConsoleVRDPServer *pThis = static_cast<ConsoleVRDPServer*>(pvCallback);
|
---|
2667 | EmWebcam *pWebcam = pThis->mConsole->getEmWebcam();
|
---|
2668 | pWebcam->EmWebcamCbFrame(rcRequest, pDeviceCtx, pFrame, cbFrame);
|
---|
2669 | #else
|
---|
2670 | NOREF(pvCallback);
|
---|
2671 | NOREF(rcRequest);
|
---|
2672 | NOREF(pDeviceCtx);
|
---|
2673 | NOREF(pFrame);
|
---|
2674 | NOREF(cbFrame);
|
---|
2675 | #endif
|
---|
2676 | }
|
---|
2677 |
|
---|
2678 | int ConsoleVRDPServer::VideoInDeviceAttach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle, void *pvDeviceCtx)
|
---|
2679 | {
|
---|
2680 | int rc;
|
---|
2681 |
|
---|
2682 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInDeviceAttach)
|
---|
2683 | {
|
---|
2684 | rc = m_interfaceVideoIn.VRDEVideoInDeviceAttach(mhServer, pDeviceHandle, pvDeviceCtx);
|
---|
2685 | }
|
---|
2686 | else
|
---|
2687 | {
|
---|
2688 | rc = VERR_NOT_SUPPORTED;
|
---|
2689 | }
|
---|
2690 |
|
---|
2691 | return rc;
|
---|
2692 | }
|
---|
2693 |
|
---|
2694 | int ConsoleVRDPServer::VideoInDeviceDetach(const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle)
|
---|
2695 | {
|
---|
2696 | int rc;
|
---|
2697 |
|
---|
2698 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInDeviceDetach)
|
---|
2699 | {
|
---|
2700 | rc = m_interfaceVideoIn.VRDEVideoInDeviceDetach(mhServer, pDeviceHandle);
|
---|
2701 | }
|
---|
2702 | else
|
---|
2703 | {
|
---|
2704 | rc = VERR_NOT_SUPPORTED;
|
---|
2705 | }
|
---|
2706 |
|
---|
2707 | return rc;
|
---|
2708 | }
|
---|
2709 |
|
---|
2710 | int ConsoleVRDPServer::VideoInGetDeviceDesc(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle)
|
---|
2711 | {
|
---|
2712 | int rc;
|
---|
2713 |
|
---|
2714 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInGetDeviceDesc)
|
---|
2715 | {
|
---|
2716 | rc = m_interfaceVideoIn.VRDEVideoInGetDeviceDesc(mhServer, pvUser, pDeviceHandle);
|
---|
2717 | }
|
---|
2718 | else
|
---|
2719 | {
|
---|
2720 | rc = VERR_NOT_SUPPORTED;
|
---|
2721 | }
|
---|
2722 |
|
---|
2723 | return rc;
|
---|
2724 | }
|
---|
2725 |
|
---|
2726 | int ConsoleVRDPServer::VideoInControl(void *pvUser, const VRDEVIDEOINDEVICEHANDLE *pDeviceHandle,
|
---|
2727 | const VRDEVIDEOINCTRLHDR *pReq, uint32_t cbReq)
|
---|
2728 | {
|
---|
2729 | int rc;
|
---|
2730 |
|
---|
2731 | if (mhServer && mpEntryPoints && m_interfaceVideoIn.VRDEVideoInControl)
|
---|
2732 | {
|
---|
2733 | rc = m_interfaceVideoIn.VRDEVideoInControl(mhServer, pvUser, pDeviceHandle, pReq, cbReq);
|
---|
2734 | }
|
---|
2735 | else
|
---|
2736 | {
|
---|
2737 | rc = VERR_NOT_SUPPORTED;
|
---|
2738 | }
|
---|
2739 |
|
---|
2740 | return rc;
|
---|
2741 | }
|
---|
2742 |
|
---|
2743 | void ConsoleVRDPServer::EnableConnections(void)
|
---|
2744 | {
|
---|
2745 | if (mpEntryPoints && mhServer)
|
---|
2746 | {
|
---|
2747 | mpEntryPoints->VRDEEnableConnections(mhServer, true);
|
---|
2748 |
|
---|
2749 | /* Redirect 3D output if it is enabled. */
|
---|
2750 | remote3DRedirect();
|
---|
2751 |
|
---|
2752 | /* Setup the generic TSMF channel. */
|
---|
2753 | setupTSMF();
|
---|
2754 | }
|
---|
2755 | }
|
---|
2756 |
|
---|
2757 | void ConsoleVRDPServer::DisconnectClient(uint32_t u32ClientId, bool fReconnect)
|
---|
2758 | {
|
---|
2759 | if (mpEntryPoints && mhServer)
|
---|
2760 | {
|
---|
2761 | mpEntryPoints->VRDEDisconnect(mhServer, u32ClientId, fReconnect);
|
---|
2762 | }
|
---|
2763 | }
|
---|
2764 |
|
---|
2765 | int ConsoleVRDPServer::MousePointer(BOOL alpha,
|
---|
2766 | ULONG xHot,
|
---|
2767 | ULONG yHot,
|
---|
2768 | ULONG width,
|
---|
2769 | ULONG height,
|
---|
2770 | const uint8_t *pu8Shape)
|
---|
2771 | {
|
---|
2772 | int rc = VINF_SUCCESS;
|
---|
2773 |
|
---|
2774 | if (mhServer && mpEntryPoints && m_interfaceMousePtr.VRDEMousePtr)
|
---|
2775 | {
|
---|
2776 | size_t cbMask = (((width + 7) / 8) * height + 3) & ~3;
|
---|
2777 | size_t cbData = width * height * 4;
|
---|
2778 |
|
---|
2779 | size_t cbDstMask = alpha? 0: cbMask;
|
---|
2780 |
|
---|
2781 | size_t cbPointer = sizeof(VRDEMOUSEPTRDATA) + cbDstMask + cbData;
|
---|
2782 | uint8_t *pu8Pointer = (uint8_t *)RTMemAlloc(cbPointer);
|
---|
2783 | if (pu8Pointer != NULL)
|
---|
2784 | {
|
---|
2785 | VRDEMOUSEPTRDATA *pPointer = (VRDEMOUSEPTRDATA *)pu8Pointer;
|
---|
2786 |
|
---|
2787 | pPointer->u16HotX = (uint16_t)xHot;
|
---|
2788 | pPointer->u16HotY = (uint16_t)yHot;
|
---|
2789 | pPointer->u16Width = (uint16_t)width;
|
---|
2790 | pPointer->u16Height = (uint16_t)height;
|
---|
2791 | pPointer->u16MaskLen = (uint16_t)cbDstMask;
|
---|
2792 | pPointer->u32DataLen = (uint32_t)cbData;
|
---|
2793 |
|
---|
2794 | /* AND mask. */
|
---|
2795 | uint8_t *pu8Mask = pu8Pointer + sizeof(VRDEMOUSEPTRDATA);
|
---|
2796 | if (cbDstMask)
|
---|
2797 | {
|
---|
2798 | memcpy(pu8Mask, pu8Shape, cbDstMask);
|
---|
2799 | }
|
---|
2800 |
|
---|
2801 | /* XOR mask */
|
---|
2802 | uint8_t *pu8Data = pu8Mask + pPointer->u16MaskLen;
|
---|
2803 | memcpy(pu8Data, pu8Shape + cbMask, cbData);
|
---|
2804 |
|
---|
2805 | m_interfaceMousePtr.VRDEMousePtr(mhServer, pPointer);
|
---|
2806 |
|
---|
2807 | RTMemFree(pu8Pointer);
|
---|
2808 | }
|
---|
2809 | else
|
---|
2810 | {
|
---|
2811 | rc = VERR_NO_MEMORY;
|
---|
2812 | }
|
---|
2813 | }
|
---|
2814 | else
|
---|
2815 | {
|
---|
2816 | rc = VERR_NOT_SUPPORTED;
|
---|
2817 | }
|
---|
2818 |
|
---|
2819 | return rc;
|
---|
2820 | }
|
---|
2821 |
|
---|
2822 | void ConsoleVRDPServer::MousePointerUpdate(const VRDECOLORPOINTER *pPointer)
|
---|
2823 | {
|
---|
2824 | if (mpEntryPoints && mhServer)
|
---|
2825 | {
|
---|
2826 | mpEntryPoints->VRDEColorPointer(mhServer, pPointer);
|
---|
2827 | }
|
---|
2828 | }
|
---|
2829 |
|
---|
2830 | void ConsoleVRDPServer::MousePointerHide(void)
|
---|
2831 | {
|
---|
2832 | if (mpEntryPoints && mhServer)
|
---|
2833 | {
|
---|
2834 | mpEntryPoints->VRDEHidePointer(mhServer);
|
---|
2835 | }
|
---|
2836 | }
|
---|
2837 |
|
---|
2838 | void ConsoleVRDPServer::Stop(void)
|
---|
2839 | {
|
---|
2840 | Assert(VALID_PTR(this)); /** @todo r=bird: there are(/was) some odd cases where this buster was invalid on
|
---|
2841 | * linux. Just remove this when it's 100% sure that problem has been fixed. */
|
---|
2842 |
|
---|
2843 | #ifdef VBOX_WITH_USB
|
---|
2844 | remoteUSBThreadStop();
|
---|
2845 | #endif /* VBOX_WITH_USB */
|
---|
2846 |
|
---|
2847 | if (mhServer)
|
---|
2848 | {
|
---|
2849 | HVRDESERVER hServer = mhServer;
|
---|
2850 |
|
---|
2851 | /* Reset the handle to avoid further calls to the server. */
|
---|
2852 | mhServer = 0;
|
---|
2853 |
|
---|
2854 | /* Workaround for VM process hangs on termination.
|
---|
2855 | *
|
---|
2856 | * Make sure that the server is not currently processing a resize.
|
---|
2857 | * mhServer 0 will not allow to enter the server again.
|
---|
2858 | * Wait until any current resize returns from the server.
|
---|
2859 | */
|
---|
2860 | if (mcInResize)
|
---|
2861 | {
|
---|
2862 | LogRel(("VRDP: waiting for resize %d\n", mcInResize));
|
---|
2863 |
|
---|
2864 | int i = 0;
|
---|
2865 | while (mcInResize && ++i < 100)
|
---|
2866 | {
|
---|
2867 | RTThreadSleep(10);
|
---|
2868 | }
|
---|
2869 | }
|
---|
2870 |
|
---|
2871 | if (mpEntryPoints && hServer)
|
---|
2872 | {
|
---|
2873 | mpEntryPoints->VRDEDestroy(hServer);
|
---|
2874 | }
|
---|
2875 | }
|
---|
2876 |
|
---|
2877 | mpfnAuthEntry = NULL;
|
---|
2878 | mpfnAuthEntry2 = NULL;
|
---|
2879 | mpfnAuthEntry3 = NULL;
|
---|
2880 |
|
---|
2881 | if (mAuthLibrary)
|
---|
2882 | {
|
---|
2883 | RTLdrClose(mAuthLibrary);
|
---|
2884 | mAuthLibrary = 0;
|
---|
2885 | }
|
---|
2886 | }
|
---|
2887 |
|
---|
2888 | /* Worker thread for Remote USB. The thread polls the clients for
|
---|
2889 | * the list of attached USB devices.
|
---|
2890 | * The thread is also responsible for attaching/detaching devices
|
---|
2891 | * to/from the VM.
|
---|
2892 | *
|
---|
2893 | * It is expected that attaching/detaching is not a frequent operation.
|
---|
2894 | *
|
---|
2895 | * The thread is always running when the VRDP server is active.
|
---|
2896 | *
|
---|
2897 | * The thread scans backends and requests the device list every 2 seconds.
|
---|
2898 | *
|
---|
2899 | * When device list is available, the thread calls the Console to process it.
|
---|
2900 | *
|
---|
2901 | */
|
---|
2902 | #define VRDP_DEVICE_LIST_PERIOD_MS (2000)
|
---|
2903 |
|
---|
2904 | #ifdef VBOX_WITH_USB
|
---|
2905 | static DECLCALLBACK(int) threadRemoteUSB(RTTHREAD self, void *pvUser)
|
---|
2906 | {
|
---|
2907 | ConsoleVRDPServer *pOwner = (ConsoleVRDPServer *)pvUser;
|
---|
2908 |
|
---|
2909 | LogFlow(("Console::threadRemoteUSB: start. owner = %p.\n", pOwner));
|
---|
2910 |
|
---|
2911 | pOwner->notifyRemoteUSBThreadRunning(self);
|
---|
2912 |
|
---|
2913 | while (pOwner->isRemoteUSBThreadRunning())
|
---|
2914 | {
|
---|
2915 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
2916 |
|
---|
2917 | while ((pRemoteUSBBackend = pOwner->usbBackendGetNext(pRemoteUSBBackend)) != NULL)
|
---|
2918 | {
|
---|
2919 | pRemoteUSBBackend->PollRemoteDevices();
|
---|
2920 | }
|
---|
2921 |
|
---|
2922 | pOwner->waitRemoteUSBThreadEvent(VRDP_DEVICE_LIST_PERIOD_MS);
|
---|
2923 |
|
---|
2924 | LogFlow(("Console::threadRemoteUSB: iteration. owner = %p.\n", pOwner));
|
---|
2925 | }
|
---|
2926 |
|
---|
2927 | return VINF_SUCCESS;
|
---|
2928 | }
|
---|
2929 |
|
---|
2930 | void ConsoleVRDPServer::notifyRemoteUSBThreadRunning(RTTHREAD thread)
|
---|
2931 | {
|
---|
2932 | mUSBBackends.thread = thread;
|
---|
2933 | mUSBBackends.fThreadRunning = true;
|
---|
2934 | int rc = RTThreadUserSignal(thread);
|
---|
2935 | AssertRC(rc);
|
---|
2936 | }
|
---|
2937 |
|
---|
2938 | bool ConsoleVRDPServer::isRemoteUSBThreadRunning(void)
|
---|
2939 | {
|
---|
2940 | return mUSBBackends.fThreadRunning;
|
---|
2941 | }
|
---|
2942 |
|
---|
2943 | void ConsoleVRDPServer::waitRemoteUSBThreadEvent(RTMSINTERVAL cMillies)
|
---|
2944 | {
|
---|
2945 | int rc = RTSemEventWait(mUSBBackends.event, cMillies);
|
---|
2946 | Assert(RT_SUCCESS(rc) || rc == VERR_TIMEOUT);
|
---|
2947 | NOREF(rc);
|
---|
2948 | }
|
---|
2949 |
|
---|
2950 | void ConsoleVRDPServer::remoteUSBThreadStart(void)
|
---|
2951 | {
|
---|
2952 | int rc = RTSemEventCreate(&mUSBBackends.event);
|
---|
2953 |
|
---|
2954 | if (RT_FAILURE(rc))
|
---|
2955 | {
|
---|
2956 | AssertFailed();
|
---|
2957 | mUSBBackends.event = 0;
|
---|
2958 | }
|
---|
2959 |
|
---|
2960 | if (RT_SUCCESS(rc))
|
---|
2961 | {
|
---|
2962 | rc = RTThreadCreate(&mUSBBackends.thread, threadRemoteUSB, this, 65536,
|
---|
2963 | RTTHREADTYPE_VRDP_IO, RTTHREADFLAGS_WAITABLE, "remote usb");
|
---|
2964 | }
|
---|
2965 |
|
---|
2966 | if (RT_FAILURE(rc))
|
---|
2967 | {
|
---|
2968 | LogRel(("Warning: could not start the remote USB thread, rc = %Rrc!!!\n", rc));
|
---|
2969 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
2970 | }
|
---|
2971 | else
|
---|
2972 | {
|
---|
2973 | /* Wait until the thread is ready. */
|
---|
2974 | rc = RTThreadUserWait(mUSBBackends.thread, 60000);
|
---|
2975 | AssertRC(rc);
|
---|
2976 | Assert (mUSBBackends.fThreadRunning || RT_FAILURE(rc));
|
---|
2977 | }
|
---|
2978 | }
|
---|
2979 |
|
---|
2980 | void ConsoleVRDPServer::remoteUSBThreadStop(void)
|
---|
2981 | {
|
---|
2982 | mUSBBackends.fThreadRunning = false;
|
---|
2983 |
|
---|
2984 | if (mUSBBackends.thread != NIL_RTTHREAD)
|
---|
2985 | {
|
---|
2986 | Assert (mUSBBackends.event != 0);
|
---|
2987 |
|
---|
2988 | RTSemEventSignal(mUSBBackends.event);
|
---|
2989 |
|
---|
2990 | int rc = RTThreadWait(mUSBBackends.thread, 60000, NULL);
|
---|
2991 | AssertRC(rc);
|
---|
2992 |
|
---|
2993 | mUSBBackends.thread = NIL_RTTHREAD;
|
---|
2994 | }
|
---|
2995 |
|
---|
2996 | if (mUSBBackends.event)
|
---|
2997 | {
|
---|
2998 | RTSemEventDestroy(mUSBBackends.event);
|
---|
2999 | mUSBBackends.event = 0;
|
---|
3000 | }
|
---|
3001 | }
|
---|
3002 | #endif /* VBOX_WITH_USB */
|
---|
3003 |
|
---|
3004 | typedef struct AuthCtx
|
---|
3005 | {
|
---|
3006 | AuthResult result;
|
---|
3007 |
|
---|
3008 | PAUTHENTRY3 pfnAuthEntry3;
|
---|
3009 | PAUTHENTRY2 pfnAuthEntry2;
|
---|
3010 | PAUTHENTRY pfnAuthEntry;
|
---|
3011 |
|
---|
3012 | const char *pszCaller;
|
---|
3013 | PAUTHUUID pUuid;
|
---|
3014 | AuthGuestJudgement guestJudgement;
|
---|
3015 | const char *pszUser;
|
---|
3016 | const char *pszPassword;
|
---|
3017 | const char *pszDomain;
|
---|
3018 | int fLogon;
|
---|
3019 | unsigned clientId;
|
---|
3020 | } AuthCtx;
|
---|
3021 |
|
---|
3022 | static DECLCALLBACK(int) authThread(RTTHREAD self, void *pvUser)
|
---|
3023 | {
|
---|
3024 | AuthCtx *pCtx = (AuthCtx *)pvUser;
|
---|
3025 |
|
---|
3026 | if (pCtx->pfnAuthEntry3)
|
---|
3027 | {
|
---|
3028 | pCtx->result = pCtx->pfnAuthEntry3(pCtx->pszCaller, pCtx->pUuid, pCtx->guestJudgement,
|
---|
3029 | pCtx->pszUser, pCtx->pszPassword, pCtx->pszDomain,
|
---|
3030 | pCtx->fLogon, pCtx->clientId);
|
---|
3031 | }
|
---|
3032 | else if (pCtx->pfnAuthEntry2)
|
---|
3033 | {
|
---|
3034 | pCtx->result = pCtx->pfnAuthEntry2(pCtx->pUuid, pCtx->guestJudgement,
|
---|
3035 | pCtx->pszUser, pCtx->pszPassword, pCtx->pszDomain,
|
---|
3036 | pCtx->fLogon, pCtx->clientId);
|
---|
3037 | }
|
---|
3038 | else if (pCtx->pfnAuthEntry)
|
---|
3039 | {
|
---|
3040 | pCtx->result = pCtx->pfnAuthEntry(pCtx->pUuid, pCtx->guestJudgement,
|
---|
3041 | pCtx->pszUser, pCtx->pszPassword, pCtx->pszDomain);
|
---|
3042 | }
|
---|
3043 | return VINF_SUCCESS;
|
---|
3044 | }
|
---|
3045 |
|
---|
3046 | static AuthResult authCall(AuthCtx *pCtx)
|
---|
3047 | {
|
---|
3048 | AuthResult result = AuthResultAccessDenied;
|
---|
3049 |
|
---|
3050 | /* Use a separate thread because external modules might need a lot of stack space. */
|
---|
3051 | RTTHREAD thread = NIL_RTTHREAD;
|
---|
3052 | int rc = RTThreadCreate(&thread, authThread, pCtx, 512*_1K,
|
---|
3053 | RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "VRDEAuth");
|
---|
3054 | LogFlow(("authCall: RTThreadCreate %Rrc\n", rc));
|
---|
3055 |
|
---|
3056 | if (RT_SUCCESS(rc))
|
---|
3057 | {
|
---|
3058 | rc = RTThreadWait(thread, RT_INDEFINITE_WAIT, NULL);
|
---|
3059 | LogFlow(("authCall: RTThreadWait %Rrc\n", rc));
|
---|
3060 | }
|
---|
3061 |
|
---|
3062 | if (RT_SUCCESS(rc))
|
---|
3063 | {
|
---|
3064 | /* Only update the result if the thread finished without errors. */
|
---|
3065 | result = pCtx->result;
|
---|
3066 | }
|
---|
3067 | else
|
---|
3068 | {
|
---|
3069 | LogRel(("AUTH: unable to execute the auth thread %Rrc\n", rc));
|
---|
3070 | }
|
---|
3071 |
|
---|
3072 | return result;
|
---|
3073 | }
|
---|
3074 |
|
---|
3075 | AuthResult ConsoleVRDPServer::Authenticate(const Guid &uuid, AuthGuestJudgement guestJudgement,
|
---|
3076 | const char *pszUser, const char *pszPassword, const char *pszDomain,
|
---|
3077 | uint32_t u32ClientId)
|
---|
3078 | {
|
---|
3079 | AUTHUUID rawuuid;
|
---|
3080 |
|
---|
3081 | memcpy(rawuuid, uuid.raw(), sizeof(rawuuid));
|
---|
3082 |
|
---|
3083 | LogFlow(("ConsoleVRDPServer::Authenticate: uuid = %RTuuid, guestJudgement = %d, pszUser = %s, pszPassword = %s, pszDomain = %s, u32ClientId = %d\n",
|
---|
3084 | rawuuid, guestJudgement, pszUser, pszPassword, pszDomain, u32ClientId));
|
---|
3085 |
|
---|
3086 | /*
|
---|
3087 | * Called only from VRDP input thread. So thread safety is not required.
|
---|
3088 | */
|
---|
3089 |
|
---|
3090 | if (!mAuthLibrary)
|
---|
3091 | {
|
---|
3092 | /* Load the external authentication library. */
|
---|
3093 | Bstr authLibrary;
|
---|
3094 | mConsole->getVRDEServer()->COMGETTER(AuthLibrary)(authLibrary.asOutParam());
|
---|
3095 |
|
---|
3096 | Utf8Str filename = authLibrary;
|
---|
3097 |
|
---|
3098 | LogRel(("AUTH: loading external authentication library '%ls'\n", authLibrary.raw()));
|
---|
3099 |
|
---|
3100 | int rc;
|
---|
3101 | if (RTPathHavePath(filename.c_str()))
|
---|
3102 | rc = RTLdrLoad(filename.c_str(), &mAuthLibrary);
|
---|
3103 | else
|
---|
3104 | {
|
---|
3105 | rc = RTLdrLoadAppPriv(filename.c_str(), &mAuthLibrary);
|
---|
3106 | if (RT_FAILURE(rc))
|
---|
3107 | {
|
---|
3108 | /* Backward compatibility with old default 'VRDPAuth' name.
|
---|
3109 | * Try to load new default 'VBoxAuth' instead.
|
---|
3110 | */
|
---|
3111 | if (filename == "VRDPAuth")
|
---|
3112 | {
|
---|
3113 | LogRel(("AUTH: ConsoleVRDPServer::Authenticate: loading external authentication library VBoxAuth\n"));
|
---|
3114 | rc = RTLdrLoadAppPriv("VBoxAuth", &mAuthLibrary);
|
---|
3115 | }
|
---|
3116 | }
|
---|
3117 | }
|
---|
3118 |
|
---|
3119 | if (RT_FAILURE(rc))
|
---|
3120 | LogRel(("AUTH: Failed to load external authentication library. Error code: %Rrc\n", rc));
|
---|
3121 |
|
---|
3122 | if (RT_SUCCESS(rc))
|
---|
3123 | {
|
---|
3124 | typedef struct AuthEntryInfoStruct
|
---|
3125 | {
|
---|
3126 | const char *pszName;
|
---|
3127 | void **ppvAddress;
|
---|
3128 |
|
---|
3129 | } AuthEntryInfo;
|
---|
3130 | AuthEntryInfo entries[] =
|
---|
3131 | {
|
---|
3132 | { AUTHENTRY3_NAME, (void **)&mpfnAuthEntry3 },
|
---|
3133 | { AUTHENTRY2_NAME, (void **)&mpfnAuthEntry2 },
|
---|
3134 | { AUTHENTRY_NAME, (void **)&mpfnAuthEntry },
|
---|
3135 | { NULL, NULL }
|
---|
3136 | };
|
---|
3137 |
|
---|
3138 | /* Get the entry point. */
|
---|
3139 | AuthEntryInfo *pEntryInfo = &entries[0];
|
---|
3140 | while (pEntryInfo->pszName)
|
---|
3141 | {
|
---|
3142 | *pEntryInfo->ppvAddress = NULL;
|
---|
3143 |
|
---|
3144 | int rc2 = RTLdrGetSymbol(mAuthLibrary, pEntryInfo->pszName, pEntryInfo->ppvAddress);
|
---|
3145 | if (RT_SUCCESS(rc2))
|
---|
3146 | {
|
---|
3147 | /* Found an entry point. */
|
---|
3148 | LogRel(("AUTH: Using entry point '%s'.\n", pEntryInfo->pszName));
|
---|
3149 | rc = VINF_SUCCESS;
|
---|
3150 | break;
|
---|
3151 | }
|
---|
3152 |
|
---|
3153 | if (rc2 != VERR_SYMBOL_NOT_FOUND)
|
---|
3154 | {
|
---|
3155 | LogRel(("AUTH: Could not resolve import '%s'. Error code: %Rrc\n", pEntryInfo->pszName, rc2));
|
---|
3156 | }
|
---|
3157 | rc = rc2;
|
---|
3158 |
|
---|
3159 | pEntryInfo++;
|
---|
3160 | }
|
---|
3161 | }
|
---|
3162 |
|
---|
3163 | if (RT_FAILURE(rc))
|
---|
3164 | {
|
---|
3165 | mConsole->setError(E_FAIL,
|
---|
3166 | mConsole->tr("Could not load the external authentication library '%s' (%Rrc)"),
|
---|
3167 | filename.c_str(),
|
---|
3168 | rc);
|
---|
3169 |
|
---|
3170 | mpfnAuthEntry = NULL;
|
---|
3171 | mpfnAuthEntry2 = NULL;
|
---|
3172 | mpfnAuthEntry3 = NULL;
|
---|
3173 |
|
---|
3174 | if (mAuthLibrary)
|
---|
3175 | {
|
---|
3176 | RTLdrClose(mAuthLibrary);
|
---|
3177 | mAuthLibrary = 0;
|
---|
3178 | }
|
---|
3179 |
|
---|
3180 | return AuthResultAccessDenied;
|
---|
3181 | }
|
---|
3182 | }
|
---|
3183 |
|
---|
3184 | Assert(mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2 || mpfnAuthEntry3));
|
---|
3185 |
|
---|
3186 | AuthCtx ctx;
|
---|
3187 | ctx.result = AuthResultAccessDenied; /* Denied by default. */
|
---|
3188 | ctx.pfnAuthEntry3 = mpfnAuthEntry3;
|
---|
3189 | ctx.pfnAuthEntry2 = mpfnAuthEntry2;
|
---|
3190 | ctx.pfnAuthEntry = mpfnAuthEntry;
|
---|
3191 | ctx.pszCaller = "vrde";
|
---|
3192 | ctx.pUuid = &rawuuid;
|
---|
3193 | ctx.guestJudgement = guestJudgement;
|
---|
3194 | ctx.pszUser = pszUser;
|
---|
3195 | ctx.pszPassword = pszPassword;
|
---|
3196 | ctx.pszDomain = pszDomain;
|
---|
3197 | ctx.fLogon = true;
|
---|
3198 | ctx.clientId = u32ClientId;
|
---|
3199 |
|
---|
3200 | AuthResult result = authCall(&ctx);
|
---|
3201 |
|
---|
3202 | switch (result)
|
---|
3203 | {
|
---|
3204 | case AuthResultAccessDenied:
|
---|
3205 | LogRel(("AUTH: external authentication module returned 'access denied'\n"));
|
---|
3206 | break;
|
---|
3207 | case AuthResultAccessGranted:
|
---|
3208 | LogRel(("AUTH: external authentication module returned 'access granted'\n"));
|
---|
3209 | break;
|
---|
3210 | case AuthResultDelegateToGuest:
|
---|
3211 | LogRel(("AUTH: external authentication module returned 'delegate request to guest'\n"));
|
---|
3212 | break;
|
---|
3213 | default:
|
---|
3214 | LogRel(("AUTH: external authentication module returned incorrect return code %d\n", result));
|
---|
3215 | result = AuthResultAccessDenied;
|
---|
3216 | }
|
---|
3217 |
|
---|
3218 | LogFlow(("ConsoleVRDPServer::Authenticate: result = %d\n", result));
|
---|
3219 |
|
---|
3220 | return result;
|
---|
3221 | }
|
---|
3222 |
|
---|
3223 | void ConsoleVRDPServer::AuthDisconnect(const Guid &uuid, uint32_t u32ClientId)
|
---|
3224 | {
|
---|
3225 | AUTHUUID rawuuid;
|
---|
3226 |
|
---|
3227 | memcpy(rawuuid, uuid.raw(), sizeof(rawuuid));
|
---|
3228 |
|
---|
3229 | LogFlow(("ConsoleVRDPServer::AuthDisconnect: uuid = %RTuuid, u32ClientId = %d\n",
|
---|
3230 | rawuuid, u32ClientId));
|
---|
3231 |
|
---|
3232 | Assert(mAuthLibrary && (mpfnAuthEntry || mpfnAuthEntry2 || mpfnAuthEntry3));
|
---|
3233 |
|
---|
3234 | AuthCtx ctx;
|
---|
3235 | ctx.result = AuthResultAccessDenied; /* Not used. */
|
---|
3236 | ctx.pfnAuthEntry3 = mpfnAuthEntry3;
|
---|
3237 | ctx.pfnAuthEntry2 = mpfnAuthEntry2;
|
---|
3238 | ctx.pfnAuthEntry = NULL; /* Does not use disconnect notification. */
|
---|
3239 | ctx.pszCaller = "vrde";
|
---|
3240 | ctx.pUuid = &rawuuid;
|
---|
3241 | ctx.guestJudgement = AuthGuestNotAsked;
|
---|
3242 | ctx.pszUser = NULL;
|
---|
3243 | ctx.pszPassword = NULL;
|
---|
3244 | ctx.pszDomain = NULL;
|
---|
3245 | ctx.fLogon = false;
|
---|
3246 | ctx.clientId = u32ClientId;
|
---|
3247 |
|
---|
3248 | authCall(&ctx);
|
---|
3249 | }
|
---|
3250 |
|
---|
3251 | int ConsoleVRDPServer::lockConsoleVRDPServer(void)
|
---|
3252 | {
|
---|
3253 | int rc = RTCritSectEnter(&mCritSect);
|
---|
3254 | AssertRC(rc);
|
---|
3255 | return rc;
|
---|
3256 | }
|
---|
3257 |
|
---|
3258 | void ConsoleVRDPServer::unlockConsoleVRDPServer(void)
|
---|
3259 | {
|
---|
3260 | RTCritSectLeave(&mCritSect);
|
---|
3261 | }
|
---|
3262 |
|
---|
3263 | DECLCALLBACK(int) ConsoleVRDPServer::ClipboardCallback(void *pvCallback,
|
---|
3264 | uint32_t u32ClientId,
|
---|
3265 | uint32_t u32Function,
|
---|
3266 | uint32_t u32Format,
|
---|
3267 | const void *pvData,
|
---|
3268 | uint32_t cbData)
|
---|
3269 | {
|
---|
3270 | LogFlowFunc(("pvCallback = %p, u32ClientId = %d, u32Function = %d, u32Format = 0x%08X, pvData = %p, cbData = %d\n",
|
---|
3271 | pvCallback, u32ClientId, u32Function, u32Format, pvData, cbData));
|
---|
3272 |
|
---|
3273 | int rc = VINF_SUCCESS;
|
---|
3274 |
|
---|
3275 | ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvCallback);
|
---|
3276 |
|
---|
3277 | NOREF(u32ClientId);
|
---|
3278 |
|
---|
3279 | switch (u32Function)
|
---|
3280 | {
|
---|
3281 | case VRDE_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE:
|
---|
3282 | {
|
---|
3283 | if (pServer->mpfnClipboardCallback)
|
---|
3284 | {
|
---|
3285 | pServer->mpfnClipboardCallback(VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE,
|
---|
3286 | u32Format,
|
---|
3287 | (void *)pvData,
|
---|
3288 | cbData);
|
---|
3289 | }
|
---|
3290 | } break;
|
---|
3291 |
|
---|
3292 | case VRDE_CLIPBOARD_FUNCTION_DATA_READ:
|
---|
3293 | {
|
---|
3294 | if (pServer->mpfnClipboardCallback)
|
---|
3295 | {
|
---|
3296 | pServer->mpfnClipboardCallback(VBOX_CLIPBOARD_EXT_FN_DATA_READ,
|
---|
3297 | u32Format,
|
---|
3298 | (void *)pvData,
|
---|
3299 | cbData);
|
---|
3300 | }
|
---|
3301 | } break;
|
---|
3302 |
|
---|
3303 | default:
|
---|
3304 | rc = VERR_NOT_SUPPORTED;
|
---|
3305 | }
|
---|
3306 |
|
---|
3307 | return rc;
|
---|
3308 | }
|
---|
3309 |
|
---|
3310 | DECLCALLBACK(int) ConsoleVRDPServer::ClipboardServiceExtension(void *pvExtension,
|
---|
3311 | uint32_t u32Function,
|
---|
3312 | void *pvParms,
|
---|
3313 | uint32_t cbParms)
|
---|
3314 | {
|
---|
3315 | LogFlowFunc(("pvExtension = %p, u32Function = %d, pvParms = %p, cbParms = %d\n",
|
---|
3316 | pvExtension, u32Function, pvParms, cbParms));
|
---|
3317 |
|
---|
3318 | int rc = VINF_SUCCESS;
|
---|
3319 |
|
---|
3320 | ConsoleVRDPServer *pServer = static_cast <ConsoleVRDPServer *>(pvExtension);
|
---|
3321 |
|
---|
3322 | VBOXCLIPBOARDEXTPARMS *pParms = (VBOXCLIPBOARDEXTPARMS *)pvParms;
|
---|
3323 |
|
---|
3324 | switch (u32Function)
|
---|
3325 | {
|
---|
3326 | case VBOX_CLIPBOARD_EXT_FN_SET_CALLBACK:
|
---|
3327 | {
|
---|
3328 | pServer->mpfnClipboardCallback = pParms->u.pfnCallback;
|
---|
3329 | } break;
|
---|
3330 |
|
---|
3331 | case VBOX_CLIPBOARD_EXT_FN_FORMAT_ANNOUNCE:
|
---|
3332 | {
|
---|
3333 | /* The guest announces clipboard formats. This must be delivered to all clients. */
|
---|
3334 | if (mpEntryPoints && pServer->mhServer)
|
---|
3335 | {
|
---|
3336 | mpEntryPoints->VRDEClipboard(pServer->mhServer,
|
---|
3337 | VRDE_CLIPBOARD_FUNCTION_FORMAT_ANNOUNCE,
|
---|
3338 | pParms->u32Format,
|
---|
3339 | NULL,
|
---|
3340 | 0,
|
---|
3341 | NULL);
|
---|
3342 | }
|
---|
3343 | } break;
|
---|
3344 |
|
---|
3345 | case VBOX_CLIPBOARD_EXT_FN_DATA_READ:
|
---|
3346 | {
|
---|
3347 | /* The clipboard service expects that the pvData buffer will be filled
|
---|
3348 | * with clipboard data. The server returns the data from the client that
|
---|
3349 | * announced the requested format most recently.
|
---|
3350 | */
|
---|
3351 | if (mpEntryPoints && pServer->mhServer)
|
---|
3352 | {
|
---|
3353 | mpEntryPoints->VRDEClipboard(pServer->mhServer,
|
---|
3354 | VRDE_CLIPBOARD_FUNCTION_DATA_READ,
|
---|
3355 | pParms->u32Format,
|
---|
3356 | pParms->u.pvData,
|
---|
3357 | pParms->cbData,
|
---|
3358 | &pParms->cbData);
|
---|
3359 | }
|
---|
3360 | } break;
|
---|
3361 |
|
---|
3362 | case VBOX_CLIPBOARD_EXT_FN_DATA_WRITE:
|
---|
3363 | {
|
---|
3364 | if (mpEntryPoints && pServer->mhServer)
|
---|
3365 | {
|
---|
3366 | mpEntryPoints->VRDEClipboard(pServer->mhServer,
|
---|
3367 | VRDE_CLIPBOARD_FUNCTION_DATA_WRITE,
|
---|
3368 | pParms->u32Format,
|
---|
3369 | pParms->u.pvData,
|
---|
3370 | pParms->cbData,
|
---|
3371 | NULL);
|
---|
3372 | }
|
---|
3373 | } break;
|
---|
3374 |
|
---|
3375 | default:
|
---|
3376 | rc = VERR_NOT_SUPPORTED;
|
---|
3377 | }
|
---|
3378 |
|
---|
3379 | return rc;
|
---|
3380 | }
|
---|
3381 |
|
---|
3382 | void ConsoleVRDPServer::ClipboardCreate(uint32_t u32ClientId)
|
---|
3383 | {
|
---|
3384 | int rc = lockConsoleVRDPServer();
|
---|
3385 |
|
---|
3386 | if (RT_SUCCESS(rc))
|
---|
3387 | {
|
---|
3388 | if (mcClipboardRefs == 0)
|
---|
3389 | {
|
---|
3390 | rc = HGCMHostRegisterServiceExtension(&mhClipboard, "VBoxSharedClipboard", ClipboardServiceExtension, this);
|
---|
3391 |
|
---|
3392 | if (RT_SUCCESS(rc))
|
---|
3393 | {
|
---|
3394 | mcClipboardRefs++;
|
---|
3395 | }
|
---|
3396 | }
|
---|
3397 |
|
---|
3398 | unlockConsoleVRDPServer();
|
---|
3399 | }
|
---|
3400 | }
|
---|
3401 |
|
---|
3402 | void ConsoleVRDPServer::ClipboardDelete(uint32_t u32ClientId)
|
---|
3403 | {
|
---|
3404 | int rc = lockConsoleVRDPServer();
|
---|
3405 |
|
---|
3406 | if (RT_SUCCESS(rc))
|
---|
3407 | {
|
---|
3408 | mcClipboardRefs--;
|
---|
3409 |
|
---|
3410 | if (mcClipboardRefs == 0)
|
---|
3411 | {
|
---|
3412 | HGCMHostUnregisterServiceExtension(mhClipboard);
|
---|
3413 | }
|
---|
3414 |
|
---|
3415 | unlockConsoleVRDPServer();
|
---|
3416 | }
|
---|
3417 | }
|
---|
3418 |
|
---|
3419 | /* That is called on INPUT thread of the VRDP server.
|
---|
3420 | * The ConsoleVRDPServer keeps a list of created backend instances.
|
---|
3421 | */
|
---|
3422 | void ConsoleVRDPServer::USBBackendCreate(uint32_t u32ClientId, void **ppvIntercept)
|
---|
3423 | {
|
---|
3424 | #ifdef VBOX_WITH_USB
|
---|
3425 | LogFlow(("ConsoleVRDPServer::USBBackendCreate: u32ClientId = %d\n", u32ClientId));
|
---|
3426 |
|
---|
3427 | /* Create a new instance of the USB backend for the new client. */
|
---|
3428 | RemoteUSBBackend *pRemoteUSBBackend = new RemoteUSBBackend(mConsole, this, u32ClientId);
|
---|
3429 |
|
---|
3430 | if (pRemoteUSBBackend)
|
---|
3431 | {
|
---|
3432 | pRemoteUSBBackend->AddRef(); /* 'Release' called in USBBackendDelete. */
|
---|
3433 |
|
---|
3434 | /* Append the new instance in the list. */
|
---|
3435 | int rc = lockConsoleVRDPServer();
|
---|
3436 |
|
---|
3437 | if (RT_SUCCESS(rc))
|
---|
3438 | {
|
---|
3439 | pRemoteUSBBackend->pNext = mUSBBackends.pHead;
|
---|
3440 | if (mUSBBackends.pHead)
|
---|
3441 | {
|
---|
3442 | mUSBBackends.pHead->pPrev = pRemoteUSBBackend;
|
---|
3443 | }
|
---|
3444 | else
|
---|
3445 | {
|
---|
3446 | mUSBBackends.pTail = pRemoteUSBBackend;
|
---|
3447 | }
|
---|
3448 |
|
---|
3449 | mUSBBackends.pHead = pRemoteUSBBackend;
|
---|
3450 |
|
---|
3451 | unlockConsoleVRDPServer();
|
---|
3452 |
|
---|
3453 | if (ppvIntercept)
|
---|
3454 | {
|
---|
3455 | *ppvIntercept = pRemoteUSBBackend;
|
---|
3456 | }
|
---|
3457 | }
|
---|
3458 |
|
---|
3459 | if (RT_FAILURE(rc))
|
---|
3460 | {
|
---|
3461 | pRemoteUSBBackend->Release();
|
---|
3462 | }
|
---|
3463 | }
|
---|
3464 | #endif /* VBOX_WITH_USB */
|
---|
3465 | }
|
---|
3466 |
|
---|
3467 | void ConsoleVRDPServer::USBBackendDelete(uint32_t u32ClientId)
|
---|
3468 | {
|
---|
3469 | #ifdef VBOX_WITH_USB
|
---|
3470 | LogFlow(("ConsoleVRDPServer::USBBackendDelete: u32ClientId = %d\n", u32ClientId));
|
---|
3471 |
|
---|
3472 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
3473 |
|
---|
3474 | /* Find the instance. */
|
---|
3475 | int rc = lockConsoleVRDPServer();
|
---|
3476 |
|
---|
3477 | if (RT_SUCCESS(rc))
|
---|
3478 | {
|
---|
3479 | pRemoteUSBBackend = usbBackendFind(u32ClientId);
|
---|
3480 |
|
---|
3481 | if (pRemoteUSBBackend)
|
---|
3482 | {
|
---|
3483 | /* Notify that it will be deleted. */
|
---|
3484 | pRemoteUSBBackend->NotifyDelete();
|
---|
3485 | }
|
---|
3486 |
|
---|
3487 | unlockConsoleVRDPServer();
|
---|
3488 | }
|
---|
3489 |
|
---|
3490 | if (pRemoteUSBBackend)
|
---|
3491 | {
|
---|
3492 | /* Here the instance has been excluded from the list and can be dereferenced. */
|
---|
3493 | pRemoteUSBBackend->Release();
|
---|
3494 | }
|
---|
3495 | #endif
|
---|
3496 | }
|
---|
3497 |
|
---|
3498 | void *ConsoleVRDPServer::USBBackendRequestPointer(uint32_t u32ClientId, const Guid *pGuid)
|
---|
3499 | {
|
---|
3500 | #ifdef VBOX_WITH_USB
|
---|
3501 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
3502 |
|
---|
3503 | /* Find the instance. */
|
---|
3504 | int rc = lockConsoleVRDPServer();
|
---|
3505 |
|
---|
3506 | if (RT_SUCCESS(rc))
|
---|
3507 | {
|
---|
3508 | pRemoteUSBBackend = usbBackendFind(u32ClientId);
|
---|
3509 |
|
---|
3510 | if (pRemoteUSBBackend)
|
---|
3511 | {
|
---|
3512 | /* Inform the backend instance that it is referenced by the Guid. */
|
---|
3513 | bool fAdded = pRemoteUSBBackend->addUUID(pGuid);
|
---|
3514 |
|
---|
3515 | if (fAdded)
|
---|
3516 | {
|
---|
3517 | /* Reference the instance because its pointer is being taken. */
|
---|
3518 | pRemoteUSBBackend->AddRef(); /* 'Release' is called in USBBackendReleasePointer. */
|
---|
3519 | }
|
---|
3520 | else
|
---|
3521 | {
|
---|
3522 | pRemoteUSBBackend = NULL;
|
---|
3523 | }
|
---|
3524 | }
|
---|
3525 |
|
---|
3526 | unlockConsoleVRDPServer();
|
---|
3527 | }
|
---|
3528 |
|
---|
3529 | if (pRemoteUSBBackend)
|
---|
3530 | {
|
---|
3531 | return pRemoteUSBBackend->GetBackendCallbackPointer();
|
---|
3532 | }
|
---|
3533 |
|
---|
3534 | #endif
|
---|
3535 | return NULL;
|
---|
3536 | }
|
---|
3537 |
|
---|
3538 | void ConsoleVRDPServer::USBBackendReleasePointer(const Guid *pGuid)
|
---|
3539 | {
|
---|
3540 | #ifdef VBOX_WITH_USB
|
---|
3541 | RemoteUSBBackend *pRemoteUSBBackend = NULL;
|
---|
3542 |
|
---|
3543 | /* Find the instance. */
|
---|
3544 | int rc = lockConsoleVRDPServer();
|
---|
3545 |
|
---|
3546 | if (RT_SUCCESS(rc))
|
---|
3547 | {
|
---|
3548 | pRemoteUSBBackend = usbBackendFindByUUID(pGuid);
|
---|
3549 |
|
---|
3550 | if (pRemoteUSBBackend)
|
---|
3551 | {
|
---|
3552 | pRemoteUSBBackend->removeUUID(pGuid);
|
---|
3553 | }
|
---|
3554 |
|
---|
3555 | unlockConsoleVRDPServer();
|
---|
3556 |
|
---|
3557 | if (pRemoteUSBBackend)
|
---|
3558 | {
|
---|
3559 | pRemoteUSBBackend->Release();
|
---|
3560 | }
|
---|
3561 | }
|
---|
3562 | #endif
|
---|
3563 | }
|
---|
3564 |
|
---|
3565 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendGetNext(RemoteUSBBackend *pRemoteUSBBackend)
|
---|
3566 | {
|
---|
3567 | LogFlow(("ConsoleVRDPServer::usbBackendGetNext: pBackend = %p\n", pRemoteUSBBackend));
|
---|
3568 |
|
---|
3569 | RemoteUSBBackend *pNextRemoteUSBBackend = NULL;
|
---|
3570 | #ifdef VBOX_WITH_USB
|
---|
3571 |
|
---|
3572 | int rc = lockConsoleVRDPServer();
|
---|
3573 |
|
---|
3574 | if (RT_SUCCESS(rc))
|
---|
3575 | {
|
---|
3576 | if (pRemoteUSBBackend == NULL)
|
---|
3577 | {
|
---|
3578 | /* The first backend in the list is requested. */
|
---|
3579 | pNextRemoteUSBBackend = mUSBBackends.pHead;
|
---|
3580 | }
|
---|
3581 | else
|
---|
3582 | {
|
---|
3583 | /* Get pointer to the next backend. */
|
---|
3584 | pNextRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3585 | }
|
---|
3586 |
|
---|
3587 | if (pNextRemoteUSBBackend)
|
---|
3588 | {
|
---|
3589 | pNextRemoteUSBBackend->AddRef();
|
---|
3590 | }
|
---|
3591 |
|
---|
3592 | unlockConsoleVRDPServer();
|
---|
3593 |
|
---|
3594 | if (pRemoteUSBBackend)
|
---|
3595 | {
|
---|
3596 | pRemoteUSBBackend->Release();
|
---|
3597 | }
|
---|
3598 | }
|
---|
3599 | #endif
|
---|
3600 |
|
---|
3601 | return pNextRemoteUSBBackend;
|
---|
3602 | }
|
---|
3603 |
|
---|
3604 | #ifdef VBOX_WITH_USB
|
---|
3605 | /* Internal method. Called under the ConsoleVRDPServerLock. */
|
---|
3606 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendFind(uint32_t u32ClientId)
|
---|
3607 | {
|
---|
3608 | RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
|
---|
3609 |
|
---|
3610 | while (pRemoteUSBBackend)
|
---|
3611 | {
|
---|
3612 | if (pRemoteUSBBackend->ClientId() == u32ClientId)
|
---|
3613 | {
|
---|
3614 | break;
|
---|
3615 | }
|
---|
3616 |
|
---|
3617 | pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3618 | }
|
---|
3619 |
|
---|
3620 | return pRemoteUSBBackend;
|
---|
3621 | }
|
---|
3622 |
|
---|
3623 | /* Internal method. Called under the ConsoleVRDPServerLock. */
|
---|
3624 | RemoteUSBBackend *ConsoleVRDPServer::usbBackendFindByUUID(const Guid *pGuid)
|
---|
3625 | {
|
---|
3626 | RemoteUSBBackend *pRemoteUSBBackend = mUSBBackends.pHead;
|
---|
3627 |
|
---|
3628 | while (pRemoteUSBBackend)
|
---|
3629 | {
|
---|
3630 | if (pRemoteUSBBackend->findUUID(pGuid))
|
---|
3631 | {
|
---|
3632 | break;
|
---|
3633 | }
|
---|
3634 |
|
---|
3635 | pRemoteUSBBackend = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3636 | }
|
---|
3637 |
|
---|
3638 | return pRemoteUSBBackend;
|
---|
3639 | }
|
---|
3640 | #endif
|
---|
3641 |
|
---|
3642 | /* Internal method. Called by the backend destructor. */
|
---|
3643 | void ConsoleVRDPServer::usbBackendRemoveFromList(RemoteUSBBackend *pRemoteUSBBackend)
|
---|
3644 | {
|
---|
3645 | #ifdef VBOX_WITH_USB
|
---|
3646 | int rc = lockConsoleVRDPServer();
|
---|
3647 | AssertRC(rc);
|
---|
3648 |
|
---|
3649 | /* Exclude the found instance from the list. */
|
---|
3650 | if (pRemoteUSBBackend->pNext)
|
---|
3651 | {
|
---|
3652 | pRemoteUSBBackend->pNext->pPrev = pRemoteUSBBackend->pPrev;
|
---|
3653 | }
|
---|
3654 | else
|
---|
3655 | {
|
---|
3656 | mUSBBackends.pTail = (RemoteUSBBackend *)pRemoteUSBBackend->pPrev;
|
---|
3657 | }
|
---|
3658 |
|
---|
3659 | if (pRemoteUSBBackend->pPrev)
|
---|
3660 | {
|
---|
3661 | pRemoteUSBBackend->pPrev->pNext = pRemoteUSBBackend->pNext;
|
---|
3662 | }
|
---|
3663 | else
|
---|
3664 | {
|
---|
3665 | mUSBBackends.pHead = (RemoteUSBBackend *)pRemoteUSBBackend->pNext;
|
---|
3666 | }
|
---|
3667 |
|
---|
3668 | pRemoteUSBBackend->pNext = pRemoteUSBBackend->pPrev = NULL;
|
---|
3669 |
|
---|
3670 | unlockConsoleVRDPServer();
|
---|
3671 | #endif
|
---|
3672 | }
|
---|
3673 |
|
---|
3674 |
|
---|
3675 | void ConsoleVRDPServer::SendUpdate(unsigned uScreenId, void *pvUpdate, uint32_t cbUpdate) const
|
---|
3676 | {
|
---|
3677 | if (mpEntryPoints && mhServer)
|
---|
3678 | {
|
---|
3679 | mpEntryPoints->VRDEUpdate(mhServer, uScreenId, pvUpdate, cbUpdate);
|
---|
3680 | }
|
---|
3681 | }
|
---|
3682 |
|
---|
3683 | void ConsoleVRDPServer::SendResize(void)
|
---|
3684 | {
|
---|
3685 | if (mpEntryPoints && mhServer)
|
---|
3686 | {
|
---|
3687 | ++mcInResize;
|
---|
3688 | mpEntryPoints->VRDEResize(mhServer);
|
---|
3689 | --mcInResize;
|
---|
3690 | }
|
---|
3691 | }
|
---|
3692 |
|
---|
3693 | void ConsoleVRDPServer::SendUpdateBitmap(unsigned uScreenId, uint32_t x, uint32_t y, uint32_t w, uint32_t h) const
|
---|
3694 | {
|
---|
3695 | VRDEORDERHDR update;
|
---|
3696 | update.x = x;
|
---|
3697 | update.y = y;
|
---|
3698 | update.w = w;
|
---|
3699 | update.h = h;
|
---|
3700 | if (mpEntryPoints && mhServer)
|
---|
3701 | {
|
---|
3702 | mpEntryPoints->VRDEUpdate(mhServer, uScreenId, &update, sizeof(update));
|
---|
3703 | }
|
---|
3704 | }
|
---|
3705 |
|
---|
3706 | void ConsoleVRDPServer::SendAudioSamples(void *pvSamples, uint32_t cSamples, VRDEAUDIOFORMAT format) const
|
---|
3707 | {
|
---|
3708 | if (mpEntryPoints && mhServer)
|
---|
3709 | {
|
---|
3710 | mpEntryPoints->VRDEAudioSamples(mhServer, pvSamples, cSamples, format);
|
---|
3711 | }
|
---|
3712 | }
|
---|
3713 |
|
---|
3714 | void ConsoleVRDPServer::SendAudioVolume(uint16_t left, uint16_t right) const
|
---|
3715 | {
|
---|
3716 | if (mpEntryPoints && mhServer)
|
---|
3717 | {
|
---|
3718 | mpEntryPoints->VRDEAudioVolume(mhServer, left, right);
|
---|
3719 | }
|
---|
3720 | }
|
---|
3721 |
|
---|
3722 | void ConsoleVRDPServer::SendUSBRequest(uint32_t u32ClientId, void *pvParms, uint32_t cbParms) const
|
---|
3723 | {
|
---|
3724 | if (mpEntryPoints && mhServer)
|
---|
3725 | {
|
---|
3726 | mpEntryPoints->VRDEUSBRequest(mhServer, u32ClientId, pvParms, cbParms);
|
---|
3727 | }
|
---|
3728 | }
|
---|
3729 |
|
---|
3730 | /* @todo rc not needed? */
|
---|
3731 | int ConsoleVRDPServer::SendAudioInputBegin(void **ppvUserCtx,
|
---|
3732 | void *pvContext,
|
---|
3733 | uint32_t cSamples,
|
---|
3734 | uint32_t iSampleHz,
|
---|
3735 | uint32_t cChannels,
|
---|
3736 | uint32_t cBits)
|
---|
3737 | {
|
---|
3738 | if (mpEntryPoints && mhServer && mpEntryPoints->VRDEAudioInOpen)
|
---|
3739 | {
|
---|
3740 | uint32_t u32ClientId = ASMAtomicReadU32(&mu32AudioInputClientId);
|
---|
3741 | if (u32ClientId != 0) /* 0 would mean broadcast to all clients. */
|
---|
3742 | {
|
---|
3743 | VRDEAUDIOFORMAT audioFormat = VRDE_AUDIO_FMT_MAKE(iSampleHz, cChannels, cBits, 0);
|
---|
3744 | mpEntryPoints->VRDEAudioInOpen (mhServer,
|
---|
3745 | pvContext,
|
---|
3746 | u32ClientId,
|
---|
3747 | audioFormat,
|
---|
3748 | cSamples);
|
---|
3749 | *ppvUserCtx = NULL; /* This is the ConsoleVRDPServer context.
|
---|
3750 | * Currently not used because only one client is allowed to
|
---|
3751 | * do audio input and the client id is saved by the ConsoleVRDPServer.
|
---|
3752 | */
|
---|
3753 |
|
---|
3754 | return VINF_SUCCESS;
|
---|
3755 | }
|
---|
3756 | }
|
---|
3757 | return VERR_NOT_SUPPORTED;
|
---|
3758 | }
|
---|
3759 |
|
---|
3760 | void ConsoleVRDPServer::SendAudioInputEnd(void *pvUserCtx)
|
---|
3761 | {
|
---|
3762 | if (mpEntryPoints && mhServer && mpEntryPoints->VRDEAudioInClose)
|
---|
3763 | {
|
---|
3764 | uint32_t u32ClientId = ASMAtomicReadU32(&mu32AudioInputClientId);
|
---|
3765 | if (u32ClientId != 0) /* 0 would mean broadcast to all clients. */
|
---|
3766 | {
|
---|
3767 | mpEntryPoints->VRDEAudioInClose(mhServer, u32ClientId);
|
---|
3768 | }
|
---|
3769 | }
|
---|
3770 | }
|
---|
3771 |
|
---|
3772 | #ifdef VBOX_WITH_USB_VIDEO
|
---|
3773 | int ConsoleVRDPServer::GetVideoFrameDimensions(uint16_t *pu16Heigh, uint16_t *pu16Width)
|
---|
3774 | {
|
---|
3775 | *pu16Heigh = 640;
|
---|
3776 | *pu16Width = 480;
|
---|
3777 | return VINF_SUCCESS;
|
---|
3778 | }
|
---|
3779 |
|
---|
3780 | int ConsoleVRDPServer::SendVideoSreamOn(bool fFetch)
|
---|
3781 | {
|
---|
3782 | /* Here we inform server that guest is starting/stopping
|
---|
3783 | * the stream
|
---|
3784 | */
|
---|
3785 | return VINF_SUCCESS;
|
---|
3786 | }
|
---|
3787 | #endif
|
---|
3788 |
|
---|
3789 |
|
---|
3790 |
|
---|
3791 | void ConsoleVRDPServer::QueryInfo(uint32_t index, void *pvBuffer, uint32_t cbBuffer, uint32_t *pcbOut) const
|
---|
3792 | {
|
---|
3793 | if (index == VRDE_QI_PORT)
|
---|
3794 | {
|
---|
3795 | uint32_t cbOut = sizeof(int32_t);
|
---|
3796 |
|
---|
3797 | if (cbBuffer >= cbOut)
|
---|
3798 | {
|
---|
3799 | *pcbOut = cbOut;
|
---|
3800 | *(int32_t *)pvBuffer = (int32_t)mVRDPBindPort;
|
---|
3801 | }
|
---|
3802 | }
|
---|
3803 | else if (mpEntryPoints && mhServer)
|
---|
3804 | {
|
---|
3805 | mpEntryPoints->VRDEQueryInfo(mhServer, index, pvBuffer, cbBuffer, pcbOut);
|
---|
3806 | }
|
---|
3807 | }
|
---|
3808 |
|
---|
3809 | /* static */ int ConsoleVRDPServer::loadVRDPLibrary(const char *pszLibraryName)
|
---|
3810 | {
|
---|
3811 | int rc = VINF_SUCCESS;
|
---|
3812 |
|
---|
3813 | if (mVRDPLibrary == NIL_RTLDRMOD)
|
---|
3814 | {
|
---|
3815 | RTERRINFOSTATIC ErrInfo;
|
---|
3816 | RTErrInfoInitStatic(&ErrInfo);
|
---|
3817 |
|
---|
3818 | if (RTPathHavePath(pszLibraryName))
|
---|
3819 | rc = SUPR3HardenedLdrLoadPlugIn(pszLibraryName, &mVRDPLibrary, &ErrInfo.Core);
|
---|
3820 | else
|
---|
3821 | rc = SUPR3HardenedLdrLoadAppPriv(pszLibraryName, &mVRDPLibrary, RTLDRLOAD_FLAGS_LOCAL, &ErrInfo.Core);
|
---|
3822 | if (RT_SUCCESS(rc))
|
---|
3823 | {
|
---|
3824 | struct SymbolEntry
|
---|
3825 | {
|
---|
3826 | const char *name;
|
---|
3827 | void **ppfn;
|
---|
3828 | };
|
---|
3829 |
|
---|
3830 | #define DEFSYMENTRY(a) { #a, (void**)&mpfn##a }
|
---|
3831 |
|
---|
3832 | static const struct SymbolEntry s_aSymbols[] =
|
---|
3833 | {
|
---|
3834 | DEFSYMENTRY(VRDECreateServer)
|
---|
3835 | };
|
---|
3836 |
|
---|
3837 | #undef DEFSYMENTRY
|
---|
3838 |
|
---|
3839 | for (unsigned i = 0; i < RT_ELEMENTS(s_aSymbols); i++)
|
---|
3840 | {
|
---|
3841 | rc = RTLdrGetSymbol(mVRDPLibrary, s_aSymbols[i].name, s_aSymbols[i].ppfn);
|
---|
3842 |
|
---|
3843 | if (RT_FAILURE(rc))
|
---|
3844 | {
|
---|
3845 | LogRel(("VRDE: Error resolving symbol '%s', rc %Rrc.\n", s_aSymbols[i].name, rc));
|
---|
3846 | break;
|
---|
3847 | }
|
---|
3848 | }
|
---|
3849 | }
|
---|
3850 | else
|
---|
3851 | {
|
---|
3852 | if (RTErrInfoIsSet(&ErrInfo.Core))
|
---|
3853 | LogRel(("VRDE: Error loading the library '%s': %s (%Rrc)\n", pszLibraryName, ErrInfo.Core.pszMsg, rc));
|
---|
3854 | else
|
---|
3855 | LogRel(("VRDE: Error loading the library '%s' rc = %Rrc.\n", pszLibraryName, rc));
|
---|
3856 |
|
---|
3857 | mVRDPLibrary = NIL_RTLDRMOD;
|
---|
3858 | }
|
---|
3859 | }
|
---|
3860 |
|
---|
3861 | if (RT_FAILURE(rc))
|
---|
3862 | {
|
---|
3863 | if (mVRDPLibrary != NIL_RTLDRMOD)
|
---|
3864 | {
|
---|
3865 | RTLdrClose(mVRDPLibrary);
|
---|
3866 | mVRDPLibrary = NIL_RTLDRMOD;
|
---|
3867 | }
|
---|
3868 | }
|
---|
3869 |
|
---|
3870 | return rc;
|
---|
3871 | }
|
---|
3872 |
|
---|
3873 | /*
|
---|
3874 | * IVRDEServerInfo implementation.
|
---|
3875 | */
|
---|
3876 | // constructor / destructor
|
---|
3877 | /////////////////////////////////////////////////////////////////////////////
|
---|
3878 |
|
---|
3879 | VRDEServerInfo::VRDEServerInfo()
|
---|
3880 | : mParent(NULL)
|
---|
3881 | {
|
---|
3882 | }
|
---|
3883 |
|
---|
3884 | VRDEServerInfo::~VRDEServerInfo()
|
---|
3885 | {
|
---|
3886 | }
|
---|
3887 |
|
---|
3888 |
|
---|
3889 | HRESULT VRDEServerInfo::FinalConstruct()
|
---|
3890 | {
|
---|
3891 | return BaseFinalConstruct();
|
---|
3892 | }
|
---|
3893 |
|
---|
3894 | void VRDEServerInfo::FinalRelease()
|
---|
3895 | {
|
---|
3896 | uninit();
|
---|
3897 | BaseFinalRelease();
|
---|
3898 | }
|
---|
3899 |
|
---|
3900 | // public methods only for internal purposes
|
---|
3901 | /////////////////////////////////////////////////////////////////////////////
|
---|
3902 |
|
---|
3903 | /**
|
---|
3904 | * Initializes the guest object.
|
---|
3905 | */
|
---|
3906 | HRESULT VRDEServerInfo::init(Console *aParent)
|
---|
3907 | {
|
---|
3908 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
3909 |
|
---|
3910 | ComAssertRet(aParent, E_INVALIDARG);
|
---|
3911 |
|
---|
3912 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
3913 | AutoInitSpan autoInitSpan(this);
|
---|
3914 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
3915 |
|
---|
3916 | unconst(mParent) = aParent;
|
---|
3917 |
|
---|
3918 | /* Confirm a successful initialization */
|
---|
3919 | autoInitSpan.setSucceeded();
|
---|
3920 |
|
---|
3921 | return S_OK;
|
---|
3922 | }
|
---|
3923 |
|
---|
3924 | /**
|
---|
3925 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
3926 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
3927 | */
|
---|
3928 | void VRDEServerInfo::uninit()
|
---|
3929 | {
|
---|
3930 | LogFlowThisFunc(("\n"));
|
---|
3931 |
|
---|
3932 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
3933 | AutoUninitSpan autoUninitSpan(this);
|
---|
3934 | if (autoUninitSpan.uninitDone())
|
---|
3935 | return;
|
---|
3936 |
|
---|
3937 | unconst(mParent) = NULL;
|
---|
3938 | }
|
---|
3939 |
|
---|
3940 | // IVRDEServerInfo properties
|
---|
3941 | /////////////////////////////////////////////////////////////////////////////
|
---|
3942 |
|
---|
3943 | #define IMPL_GETTER_BOOL(_aType, _aName, _aIndex) \
|
---|
3944 | STDMETHODIMP VRDEServerInfo::COMGETTER(_aName)(_aType *a##_aName) \
|
---|
3945 | { \
|
---|
3946 | if (!a##_aName) \
|
---|
3947 | return E_POINTER; \
|
---|
3948 | \
|
---|
3949 | AutoCaller autoCaller(this); \
|
---|
3950 | if (FAILED(autoCaller.rc())) return autoCaller.rc(); \
|
---|
3951 | \
|
---|
3952 | /* todo: Not sure if a AutoReadLock would be sufficient. */ \
|
---|
3953 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
|
---|
3954 | \
|
---|
3955 | uint32_t value; \
|
---|
3956 | uint32_t cbOut = 0; \
|
---|
3957 | \
|
---|
3958 | mParent->consoleVRDPServer()->QueryInfo \
|
---|
3959 | (_aIndex, &value, sizeof(value), &cbOut); \
|
---|
3960 | \
|
---|
3961 | *a##_aName = cbOut? !!value: FALSE; \
|
---|
3962 | \
|
---|
3963 | return S_OK; \
|
---|
3964 | } \
|
---|
3965 | extern void IMPL_GETTER_BOOL_DUMMY(void)
|
---|
3966 |
|
---|
3967 | #define IMPL_GETTER_SCALAR(_aType, _aName, _aIndex, _aValueMask) \
|
---|
3968 | STDMETHODIMP VRDEServerInfo::COMGETTER(_aName)(_aType *a##_aName) \
|
---|
3969 | { \
|
---|
3970 | if (!a##_aName) \
|
---|
3971 | return E_POINTER; \
|
---|
3972 | \
|
---|
3973 | AutoCaller autoCaller(this); \
|
---|
3974 | if (FAILED(autoCaller.rc())) return autoCaller.rc(); \
|
---|
3975 | \
|
---|
3976 | /* todo: Not sure if a AutoReadLock would be sufficient. */ \
|
---|
3977 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
|
---|
3978 | \
|
---|
3979 | _aType value; \
|
---|
3980 | uint32_t cbOut = 0; \
|
---|
3981 | \
|
---|
3982 | mParent->consoleVRDPServer()->QueryInfo \
|
---|
3983 | (_aIndex, &value, sizeof(value), &cbOut); \
|
---|
3984 | \
|
---|
3985 | if (_aValueMask) value &= (_aValueMask); \
|
---|
3986 | *a##_aName = cbOut? value: 0; \
|
---|
3987 | \
|
---|
3988 | return S_OK; \
|
---|
3989 | } \
|
---|
3990 | extern void IMPL_GETTER_SCALAR_DUMMY(void)
|
---|
3991 |
|
---|
3992 | #define IMPL_GETTER_BSTR(_aType, _aName, _aIndex) \
|
---|
3993 | STDMETHODIMP VRDEServerInfo::COMGETTER(_aName)(_aType *a##_aName) \
|
---|
3994 | { \
|
---|
3995 | if (!a##_aName) \
|
---|
3996 | return E_POINTER; \
|
---|
3997 | \
|
---|
3998 | AutoCaller autoCaller(this); \
|
---|
3999 | if (FAILED(autoCaller.rc())) return autoCaller.rc(); \
|
---|
4000 | \
|
---|
4001 | /* todo: Not sure if a AutoReadLock would be sufficient. */ \
|
---|
4002 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); \
|
---|
4003 | \
|
---|
4004 | uint32_t cbOut = 0; \
|
---|
4005 | \
|
---|
4006 | mParent->consoleVRDPServer()->QueryInfo \
|
---|
4007 | (_aIndex, NULL, 0, &cbOut); \
|
---|
4008 | \
|
---|
4009 | if (cbOut == 0) \
|
---|
4010 | { \
|
---|
4011 | Bstr str(""); \
|
---|
4012 | str.cloneTo(a##_aName); \
|
---|
4013 | return S_OK; \
|
---|
4014 | } \
|
---|
4015 | \
|
---|
4016 | char *pchBuffer = (char *)RTMemTmpAlloc(cbOut); \
|
---|
4017 | \
|
---|
4018 | if (!pchBuffer) \
|
---|
4019 | { \
|
---|
4020 | Log(("VRDEServerInfo::" \
|
---|
4021 | #_aName \
|
---|
4022 | ": Failed to allocate memory %d bytes\n", cbOut)); \
|
---|
4023 | return E_OUTOFMEMORY; \
|
---|
4024 | } \
|
---|
4025 | \
|
---|
4026 | mParent->consoleVRDPServer()->QueryInfo \
|
---|
4027 | (_aIndex, pchBuffer, cbOut, &cbOut); \
|
---|
4028 | \
|
---|
4029 | Bstr str(pchBuffer); \
|
---|
4030 | \
|
---|
4031 | str.cloneTo(a##_aName); \
|
---|
4032 | \
|
---|
4033 | RTMemTmpFree(pchBuffer); \
|
---|
4034 | \
|
---|
4035 | return S_OK; \
|
---|
4036 | } \
|
---|
4037 | extern void IMPL_GETTER_BSTR_DUMMY(void)
|
---|
4038 |
|
---|
4039 | IMPL_GETTER_BOOL (BOOL, Active, VRDE_QI_ACTIVE);
|
---|
4040 | IMPL_GETTER_SCALAR (LONG, Port, VRDE_QI_PORT, 0);
|
---|
4041 | IMPL_GETTER_SCALAR (ULONG, NumberOfClients, VRDE_QI_NUMBER_OF_CLIENTS, 0);
|
---|
4042 | IMPL_GETTER_SCALAR (LONG64, BeginTime, VRDE_QI_BEGIN_TIME, 0);
|
---|
4043 | IMPL_GETTER_SCALAR (LONG64, EndTime, VRDE_QI_END_TIME, 0);
|
---|
4044 | IMPL_GETTER_SCALAR (LONG64, BytesSent, VRDE_QI_BYTES_SENT, INT64_MAX);
|
---|
4045 | IMPL_GETTER_SCALAR (LONG64, BytesSentTotal, VRDE_QI_BYTES_SENT_TOTAL, INT64_MAX);
|
---|
4046 | IMPL_GETTER_SCALAR (LONG64, BytesReceived, VRDE_QI_BYTES_RECEIVED, INT64_MAX);
|
---|
4047 | IMPL_GETTER_SCALAR (LONG64, BytesReceivedTotal, VRDE_QI_BYTES_RECEIVED_TOTAL, INT64_MAX);
|
---|
4048 | IMPL_GETTER_BSTR (BSTR, User, VRDE_QI_USER);
|
---|
4049 | IMPL_GETTER_BSTR (BSTR, Domain, VRDE_QI_DOMAIN);
|
---|
4050 | IMPL_GETTER_BSTR (BSTR, ClientName, VRDE_QI_CLIENT_NAME);
|
---|
4051 | IMPL_GETTER_BSTR (BSTR, ClientIP, VRDE_QI_CLIENT_IP);
|
---|
4052 | IMPL_GETTER_SCALAR (ULONG, ClientVersion, VRDE_QI_CLIENT_VERSION, 0);
|
---|
4053 | IMPL_GETTER_SCALAR (ULONG, EncryptionStyle, VRDE_QI_ENCRYPTION_STYLE, 0);
|
---|
4054 |
|
---|
4055 | #undef IMPL_GETTER_BSTR
|
---|
4056 | #undef IMPL_GETTER_SCALAR
|
---|
4057 | #undef IMPL_GETTER_BOOL
|
---|
4058 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|