VirtualBox

source: vbox/trunk/src/VBox/Main/include/ConsoleImpl.h@ 53364

Last change on this file since 53364 was 53062, checked in by vboxsync, 10 years ago

USB: Integrate USB sniffer. Make it possible to specify a file to dump the traffic to when attaching a USB device with VBoxManage

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 42.6 KB
Line 
1/* $Id: ConsoleImpl.h 53062 2014-10-15 12:34:18Z vboxsync $ */
2/** @file
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2005-2014 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#ifndef ____H_CONSOLEIMPL
19#define ____H_CONSOLEIMPL
20
21#include "VirtualBoxBase.h"
22#include "VBox/com/array.h"
23#include "EventImpl.h"
24#include "ConsoleWrap.h"
25
26class Guest;
27class Keyboard;
28class Mouse;
29class Display;
30class MachineDebugger;
31class TeleporterStateSrc;
32class OUSBDevice;
33class RemoteUSBDevice;
34class SharedFolder;
35class VRDEServerInfo;
36class EmulatedUSB;
37#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
38class AudioVRDE;
39#else
40class AudioSniffer;
41#endif
42class Nvram;
43#ifdef VBOX_WITH_USB_CARDREADER
44class UsbCardReader;
45#endif
46class ConsoleVRDPServer;
47class VMMDev;
48class Progress;
49class BusAssignmentManager;
50COM_STRUCT_OR_CLASS(IEventListener);
51#ifdef VBOX_WITH_EXTPACK
52class ExtPackManager;
53#endif
54class VMMDevMouseInterface;
55class DisplayMouseInterface;
56
57#include <iprt/uuid.h>
58#include <iprt/memsafer.h>
59#include <VBox/RemoteDesktop/VRDE.h>
60#include <VBox/vmm/pdmdrv.h>
61#ifdef VBOX_WITH_GUEST_PROPS
62# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
63#endif
64
65#ifdef RT_OS_WINDOWS
66# include "../src-server/win/VBoxComEvents.h"
67#endif
68
69struct VUSBIRHCONFIG;
70typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
71
72#include <list>
73#include <vector>
74
75// defines
76///////////////////////////////////////////////////////////////////////////////
77
78/**
79 * Checks the availability of the underlying VM device driver corresponding
80 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
81 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
82 * The translatable error message is defined in null context.
83 *
84 * Intended to used only within Console children (i.e. Keyboard, Mouse,
85 * Display, etc.).
86 *
87 * @param drv driver pointer to check (compare it with NULL)
88 */
89#define CHECK_CONSOLE_DRV(drv) \
90 do { \
91 if (!(drv)) \
92 return setError(E_ACCESSDENIED, tr("The console is not powered up")); \
93 } while (0)
94
95// Console
96///////////////////////////////////////////////////////////////////////////////
97
98class ConsoleMouseInterface
99{
100public:
101 virtual VMMDevMouseInterface *i_getVMMDevMouseInterface(){return NULL;}
102 virtual DisplayMouseInterface *i_getDisplayMouseInterface(){return NULL;}
103 virtual void i_onMouseCapabilityChange(BOOL supportsAbsolute,
104 BOOL supportsRelative,
105 BOOL supportsMT,
106 BOOL needsHostCursor){NOREF(supportsAbsolute); NOREF(supportsRelative); NOREF(supportsMT); NOREF(needsHostCursor);}
107};
108
109/** IConsole implementation class */
110class ATL_NO_VTABLE Console :
111 public ConsoleWrap,
112 public ConsoleMouseInterface
113{
114
115public:
116
117 DECLARE_EMPTY_CTOR_DTOR(Console)
118
119 HRESULT FinalConstruct();
120 void FinalRelease();
121
122 // public initializers/uninitializers for internal purposes only
123 HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType);
124 void uninit();
125
126
127 // public methods for internal purposes only
128
129 /*
130 * Note: the following methods do not increase refcount. intended to be
131 * called only by the VM execution thread.
132 */
133
134 Guest *i_getGuest() const { return mGuest; }
135 Keyboard *i_getKeyboard() const { return mKeyboard; }
136 Mouse *i_getMouse() const { return mMouse; }
137 Display *i_getDisplay() const { return mDisplay; }
138 MachineDebugger *i_getMachineDebugger() const { return mDebugger; }
139#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
140 AudioVRDE *i_getAudioVRDE() const { return mAudioVRDE; }
141#else
142 AudioSniffer *i_getAudioSniffer() const { return mAudioSniffer; }
143#endif
144
145 const ComPtr<IMachine> &i_machine() const { return mMachine; }
146
147 bool i_useHostClipboard() { return mfUseHostClipboard; }
148
149 /** Method is called only from ConsoleVRDPServer */
150 IVRDEServer *i_getVRDEServer() const { return mVRDEServer; }
151
152 ConsoleVRDPServer *i_consoleVRDPServer() const { return mConsoleVRDPServer; }
153
154 HRESULT i_updateMachineState(MachineState_T aMachineState);
155
156 // events from IInternalSessionControl
157 HRESULT i_onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
158 HRESULT i_onSerialPortChange(ISerialPort *aSerialPort);
159 HRESULT i_onParallelPortChange(IParallelPort *aParallelPort);
160 HRESULT i_onStorageControllerChange();
161 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
162 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
163 HRESULT i_onCPUExecutionCapChange(ULONG aExecutionCap);
164 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
165 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
166 HRESULT i_onVRDEServerChange(BOOL aRestart);
167 HRESULT i_onVideoCaptureChange();
168 HRESULT i_onUSBControllerChange();
169 HRESULT i_onSharedFolderChange(BOOL aGlobal);
170 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs,
171 const Utf8Str &aCaptureFilename);
172 HRESULT i_onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
173 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
174 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
175 HRESULT i_onExtraDataChange(IN_BSTR aMachineId, IN_BSTR aKey, IN_BSTR aVal);
176
177 HRESULT i_getGuestProperty(const Utf8Str &aName, Utf8Str *aValue, LONG64 *aTimestamp, Utf8Str *aFlags);
178 HRESULT i_setGuestProperty(const Utf8Str &aName, const Utf8Str &aValue, const Utf8Str &aFlags);
179 HRESULT i_deleteGuestProperty(const Utf8Str &aName);
180 HRESULT i_enumerateGuestProperties(const Utf8Str &aPatterns,
181 std::vector<Utf8Str> &aNames,
182 std::vector<Utf8Str> &aValues,
183 std::vector<LONG64> &aTimestamps,
184 std::vector<Utf8Str> &aFlags);
185 HRESULT i_onlineMergeMedium(IMediumAttachment *aMediumAttachment,
186 ULONG aSourceIdx, ULONG aTargetIdx,
187 IProgress *aProgress);
188 int i_hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName);
189 VMMDev *i_getVMMDev() { return m_pVMMDev; }
190#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
191 AudioVRDE *i_getAudioVRDE() { return mAudioVRDE; }
192#else
193 AudioSniffer *i_getAudioSniffer() { return mAudioSniffer; }
194#endif
195
196#ifdef VBOX_WITH_EXTPACK
197 ExtPackManager *i_getExtPackManager();
198#endif
199 EventSource *i_getEventSource() { return mEventSource; }
200#ifdef VBOX_WITH_USB_CARDREADER
201 UsbCardReader *i_getUsbCardReader() { return mUsbCardReader; }
202#endif
203
204 int i_VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
205 void i_VRDPClientStatusChange(uint32_t u32ClientId, const char *pszStatus);
206 void i_VRDPClientConnect(uint32_t u32ClientId);
207 void i_VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
208 void i_VRDPInterceptAudio(uint32_t u32ClientId);
209 void i_VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
210 void i_VRDPInterceptClipboard(uint32_t u32ClientId);
211
212 void i_processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList, bool fDescExt);
213 void i_reportVmStatistics(ULONG aValidStats, ULONG aCpuUser,
214 ULONG aCpuKernel, ULONG aCpuIdle,
215 ULONG aMemTotal, ULONG aMemFree,
216 ULONG aMemBalloon, ULONG aMemShared,
217 ULONG aMemCache, ULONG aPageTotal,
218 ULONG aAllocVMM, ULONG aFreeVMM,
219 ULONG aBalloonedVMM, ULONG aSharedVMM,
220 ULONG aVmNetRx, ULONG aVmNetTx)
221 {
222 mControl->ReportVmStatistics(aValidStats, aCpuUser, aCpuKernel, aCpuIdle,
223 aMemTotal, aMemFree, aMemBalloon, aMemShared,
224 aMemCache, aPageTotal, aAllocVMM, aFreeVMM,
225 aBalloonedVMM, aSharedVMM, aVmNetRx, aVmNetTx);
226 }
227 void i_enableVMMStatistics(BOOL aEnable);
228
229 HRESULT i_pause(Reason_T aReason);
230 HRESULT i_resume(Reason_T aReason);
231 HRESULT i_saveState(Reason_T aReason, IProgress **aProgress);
232
233 // callback callers (partly; for some events console callbacks are notified
234 // directly from IInternalSessionControl event handlers declared above)
235 void i_onMousePointerShapeChange(bool fVisible, bool fAlpha,
236 uint32_t xHot, uint32_t yHot,
237 uint32_t width, uint32_t height,
238 const uint8_t *pu8Shape,
239 uint32_t cbShape);
240 void i_onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative,
241 BOOL supportsMT, BOOL needsHostCursor);
242 void i_onStateChange(MachineState_T aMachineState);
243 void i_onAdditionsStateChange();
244 void i_onAdditionsOutdated();
245 void i_onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
246 void i_onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
247 IVirtualBoxErrorInfo *aError);
248 void i_onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
249 HRESULT i_onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId);
250 void i_onVRDEServerInfoChange();
251
252 static const PDMDRVREG DrvStatusReg;
253
254 static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
255 HRESULT i_setInvalidMachineStateError();
256
257 static const char *i_convertControllerTypeToDev(StorageControllerType_T enmCtrlType);
258 static HRESULT i_convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
259 // Called from event listener
260 HRESULT i_onNATRedirectRuleChange(ULONG ulInstance, BOOL aNatRuleRemove,
261 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
262
263 // Mouse interface
264 VMMDevMouseInterface *i_getVMMDevMouseInterface();
265 DisplayMouseInterface *i_getDisplayMouseInterface();
266
267 EmulatedUSB *i_getEmulatedUSB(void) { return mEmulatedUSB; }
268
269 /**
270 * Sets the disk encryption keys.
271 *
272 * @returns COM status code.
273 * @þaram strCfg The config for the disks.
274 *
275 * @note: One line in the config string contains all required data for one disk.
276 * The format for one disk is some sort of comma separated value using
277 * key=value pairs.
278 * There are two keys defined at the moment:
279 * - uuid: The uuid of the base image the key is for (with or without)
280 * the curly braces.
281 * - dek: The data encryption key in base64 encoding
282 */
283 HRESULT i_setDiskEncryptionKeys(const Utf8Str &strCfg);
284
285private:
286
287 // wraped IConsole properties
288 HRESULT getMachine(ComPtr<IMachine> &aMachine);
289 HRESULT getState(MachineState_T *aState);
290 HRESULT getGuest(ComPtr<IGuest> &aGuest);
291 HRESULT getKeyboard(ComPtr<IKeyboard> &aKeyboard);
292 HRESULT getMouse(ComPtr<IMouse> &aMouse);
293 HRESULT getDisplay(ComPtr<IDisplay> &aDisplay);
294 HRESULT getDebugger(ComPtr<IMachineDebugger> &aDebugger);
295 HRESULT getUSBDevices(std::vector<ComPtr<IUSBDevice> > &aUSBDevices);
296 HRESULT getRemoteUSBDevices(std::vector<ComPtr<IHostUSBDevice> > &aRemoteUSBDevices);
297 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
298 HRESULT getVRDEServerInfo(ComPtr<IVRDEServerInfo> &aVRDEServerInfo);
299 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
300 HRESULT getAttachedPCIDevices(std::vector<ComPtr<IPCIDeviceAttachment> > &aAttachedPCIDevices);
301 HRESULT getUseHostClipboard(BOOL *aUseHostClipboard);
302 HRESULT setUseHostClipboard(BOOL aUseHostClipboard);
303 HRESULT getEmulatedUSB(ComPtr<IEmulatedUSB> &aEmulatedUSB);
304
305 // wraped IConsole methods
306 HRESULT powerUp(ComPtr<IProgress> &aProgress);
307 HRESULT powerUpPaused(ComPtr<IProgress> &aProgress);
308 HRESULT powerDown(ComPtr<IProgress> &aProgress);
309 HRESULT reset();
310 HRESULT pause();
311 HRESULT resume();
312 HRESULT powerButton();
313 HRESULT sleepButton();
314 HRESULT getPowerButtonHandled(BOOL *aHandled);
315 HRESULT getGuestEnteredACPIMode(BOOL *aEntered);
316 HRESULT saveState(ComPtr<IProgress> &aProgress);
317 HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
318 HRESULT discardSavedState(BOOL aFRemoveFile);
319 HRESULT getDeviceActivity(const std::vector<DeviceType_T> &aType,
320 std::vector<DeviceActivity_T> &aActivity);
321 HRESULT attachUSBDevice(const com::Guid &aId, const com::Utf8Str &aCaptureFilename);
322 HRESULT detachUSBDevice(const com::Guid &aId,
323 ComPtr<IUSBDevice> &aDevice);
324 HRESULT findUSBDeviceByAddress(const com::Utf8Str &aName,
325 ComPtr<IUSBDevice> &aDevice);
326 HRESULT findUSBDeviceById(const com::Guid &aId,
327 ComPtr<IUSBDevice> &aDevice);
328 HRESULT createSharedFolder(const com::Utf8Str &aName,
329 const com::Utf8Str &aHostPath,
330 BOOL aWritable,
331 BOOL aAutomount);
332 HRESULT removeSharedFolder(const com::Utf8Str &aName);
333 HRESULT takeSnapshot(const com::Utf8Str &aName,
334 const com::Utf8Str &aDescription,
335 ComPtr<IProgress> &aProgress);
336 HRESULT deleteSnapshot(const com::Guid &aId,
337 ComPtr<IProgress> &aProgress);
338 HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
339 ComPtr<IProgress> &aProgress);
340 HRESULT deleteSnapshotRange(const com::Guid &aStartId,
341 const com::Guid &aEndId,
342 ComPtr<IProgress> &aProgress);
343 HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
344 ComPtr<IProgress> &aProgress);
345 HRESULT teleport(const com::Utf8Str &aHostname,
346 ULONG aTcpport,
347 const com::Utf8Str &aPassword,
348 ULONG aMaxDowntime,
349 ComPtr<IProgress> &aProgress);
350
351 /**
352 * Base template for AutoVMCaller and SafeVMPtr. Template arguments
353 * have the same meaning as arguments of Console::addVMCaller().
354 */
355 template <bool taQuiet = false, bool taAllowNullVM = false>
356 class AutoVMCallerBase
357 {
358 public:
359 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(E_FAIL)
360 {
361 Assert(aThat);
362 mRC = aThat->i_addVMCaller(taQuiet, taAllowNullVM);
363 }
364 ~AutoVMCallerBase()
365 {
366 doRelease();
367 }
368 /** Decreases the number of callers before the instance is destroyed. */
369 void releaseCaller()
370 {
371 Assert(SUCCEEDED(mRC));
372 doRelease();
373 }
374 /** Restores the number of callers after by #release(). #rc() must be
375 * rechecked to ensure the operation succeeded. */
376 void addYY()
377 {
378 AssertReturnVoid(!SUCCEEDED(mRC));
379 mRC = mThat->i_addVMCaller(taQuiet, taAllowNullVM);
380 }
381 /** Returns the result of Console::addVMCaller() */
382 HRESULT rc() const { return mRC; }
383 /** Shortcut to SUCCEEDED(rc()) */
384 bool isOk() const { return SUCCEEDED(mRC); }
385 protected:
386 Console *mThat;
387 void doRelease()
388 {
389 if (SUCCEEDED(mRC))
390 {
391 mThat->i_releaseVMCaller();
392 mRC = E_FAIL;
393 }
394 }
395 private:
396 HRESULT mRC; /* Whether the caller was added. */
397 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase)
398 };
399
400#if 0
401 /**
402 * Helper class that protects sections of code using the mpUVM pointer by
403 * automatically calling addVMCaller() on construction and
404 * releaseVMCaller() on destruction. Intended for Console methods dealing
405 * with mpUVM. The usage pattern is:
406 * <code>
407 * AutoVMCaller autoVMCaller(this);
408 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
409 * ...
410 * VMR3ReqCall (mpUVM, ...
411 * </code>
412 *
413 * @note Temporarily locks the argument for writing.
414 *
415 * @sa SafeVMPtr, SafeVMPtrQuiet
416 * @obsolete Use SafeVMPtr
417 */
418 typedef AutoVMCallerBase<false, false> AutoVMCaller;
419#endif
420
421 /**
422 * Same as AutoVMCaller but doesn't set extended error info on failure.
423 *
424 * @note Temporarily locks the argument for writing.
425 * @obsolete Use SafeVMPtrQuiet
426 */
427 typedef AutoVMCallerBase<true, false> AutoVMCallerQuiet;
428
429 /**
430 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
431 * instead of assertion).
432 *
433 * @note Temporarily locks the argument for writing.
434 * @obsolete Use SafeVMPtr
435 */
436 typedef AutoVMCallerBase<false, true> AutoVMCallerWeak;
437
438 /**
439 * Same as AutoVMCaller but doesn't set extended error info on failure
440 * and allows a null VM pointer (to trigger an error instead of
441 * assertion).
442 *
443 * @note Temporarily locks the argument for writing.
444 * @obsolete Use SafeVMPtrQuiet
445 */
446 typedef AutoVMCallerBase<true, true> AutoVMCallerQuietWeak;
447
448 /**
449 * Base template for SafeVMPtr and SafeVMPtrQuiet.
450 */
451 template<bool taQuiet = false>
452 class SafeVMPtrBase : public AutoVMCallerBase<taQuiet, true>
453 {
454 typedef AutoVMCallerBase<taQuiet, true> Base;
455 public:
456 SafeVMPtrBase(Console *aThat) : Base(aThat), mRC(E_FAIL), mpUVM(NULL)
457 {
458 if (Base::isOk())
459 mRC = aThat->i_safeVMPtrRetainer(&mpUVM, taQuiet);
460 }
461 ~SafeVMPtrBase()
462 {
463 doRelease();
464 }
465 /** Direct PUVM access. */
466 PUVM rawUVM() const { return mpUVM; }
467 /** Release the handles. */
468 void release()
469 {
470 Assert(SUCCEEDED(mRC));
471 doRelease();
472 }
473
474 /** The combined result of Console::addVMCaller() and Console::safeVMPtrRetainer */
475 HRESULT rc() const { return Base::isOk()? mRC: Base::rc(); }
476 /** Shortcut to SUCCEEDED(rc()) */
477 bool isOk() const { return SUCCEEDED(mRC) && Base::isOk(); }
478
479 private:
480 void doRelease()
481 {
482 if (SUCCEEDED(mRC))
483 {
484 Base::mThat->i_safeVMPtrReleaser(&mpUVM);
485 mRC = E_FAIL;
486 }
487 Base::doRelease();
488 }
489 HRESULT mRC; /* Whether the VM ptr was retained. */
490 PUVM mpUVM;
491 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase)
492 };
493
494public:
495
496 /*
497 * Helper class that safely manages the Console::mpUVM pointer
498 * by calling addVMCaller() on construction and releaseVMCaller() on
499 * destruction. Intended for Console children. The usage pattern is:
500 * <code>
501 * Console::SafeVMPtr ptrVM(mParent);
502 * if (!ptrVM.isOk())
503 * return ptrVM.rc();
504 * ...
505 * VMR3ReqCall(ptrVM.rawUVM(), ...
506 * ...
507 * printf("%p\n", ptrVM.rawUVM());
508 * </code>
509 *
510 * @note Temporarily locks the argument for writing.
511 *
512 * @sa SafeVMPtrQuiet, AutoVMCaller
513 */
514 typedef SafeVMPtrBase<false> SafeVMPtr;
515
516 /**
517 * A deviation of SafeVMPtr that doesn't set the error info on failure.
518 * Intended for pieces of code that don't need to return the VM access
519 * failure to the caller. The usage pattern is:
520 * <code>
521 * Console::SafeVMPtrQuiet pVM(mParent);
522 * if (pVM.rc())
523 * VMR3ReqCall(pVM, ...
524 * return S_OK;
525 * </code>
526 *
527 * @note Temporarily locks the argument for writing.
528 *
529 * @sa SafeVMPtr, AutoVMCaller
530 */
531 typedef SafeVMPtrBase<true> SafeVMPtrQuiet;
532
533 class SharedFolderData
534 {
535 public:
536 SharedFolderData()
537 { }
538
539 SharedFolderData(const Utf8Str &aHostPath,
540 bool aWritable,
541 bool aAutoMount)
542 : m_strHostPath(aHostPath),
543 m_fWritable(aWritable),
544 m_fAutoMount(aAutoMount)
545 { }
546
547 // copy constructor
548 SharedFolderData(const SharedFolderData& aThat)
549 : m_strHostPath(aThat.m_strHostPath),
550 m_fWritable(aThat.m_fWritable),
551 m_fAutoMount(aThat.m_fAutoMount)
552 { }
553
554 Utf8Str m_strHostPath;
555 bool m_fWritable;
556 bool m_fAutoMount;
557 };
558
559 /**
560 * Class for managing emulated USB MSDs.
561 */
562 class USBStorageDevice
563 {
564 public:
565 USBStorageDevice()
566 { }
567 /** The UUID associated with the USB device. */
568 RTUUID mUuid;
569 /** Port of the storage device. */
570 LONG iPort;
571 };
572
573 /**
574 * Class for managing cryptographic keys.
575 * @todo: Replace with a keystore implementation once it is ready.
576 */
577 class SecretKey
578 {
579 public:
580 SecretKey() { }
581
582 SecretKey(uint8_t *pbKey, size_t cbKey)
583 : m_cRefs(0),
584 m_pbKey(pbKey),
585 m_cbKey(cbKey)
586 { }
587
588 ~SecretKey()
589 {
590 RTMemSaferFree(m_pbKey, m_cbKey);
591 m_cRefs = 0;
592 m_pbKey = NULL;
593 m_cbKey = 0;
594 }
595
596 /** Reference counter of the key. */
597 volatile uint32_t m_cRefs;
598 /** Key material. */
599 uint8_t *m_pbKey;
600 /** Size of the key in bytes. */
601 size_t m_cbKey;
602 };
603
604 typedef std::map<Utf8Str, ComObjPtr<SharedFolder> > SharedFolderMap;
605 typedef std::map<Utf8Str, SharedFolderData> SharedFolderDataMap;
606 typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
607 typedef std::list <USBStorageDevice> USBStorageDeviceList;
608 typedef std::map<Utf8Str, SecretKey *> SecretKeyMap;
609
610private:
611
612 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
613 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
614
615 HRESULT i_addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
616 void i_releaseVMCaller();
617 HRESULT i_safeVMPtrRetainer(PUVM *a_ppUVM, bool aQuiet);
618 void i_safeVMPtrReleaser(PUVM *a_ppUVM);
619
620 HRESULT i_consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
621
622 HRESULT i_powerUp(IProgress **aProgress, bool aPaused);
623 HRESULT i_powerDown(IProgress *aProgress = NULL);
624
625/* Note: FreeBSD needs this whether netflt is used or not. */
626#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
627 HRESULT i_attachToTapInterface(INetworkAdapter *networkAdapter);
628 HRESULT i_detachFromTapInterface(INetworkAdapter *networkAdapter);
629#endif
630 HRESULT i_powerDownHostInterfaces();
631
632 HRESULT i_setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
633 HRESULT i_setMachineStateLocally(MachineState_T aMachineState)
634 {
635 return i_setMachineState(aMachineState, false /* aUpdateServer */);
636 }
637
638 HRESULT i_findSharedFolder(const Utf8Str &strName,
639 ComObjPtr<SharedFolder> &aSharedFolder,
640 bool aSetError = false);
641
642 HRESULT i_fetchSharedFolders(BOOL aGlobal);
643 bool i_findOtherSharedFolder(const Utf8Str &straName,
644 SharedFolderDataMap::const_iterator &aIt);
645
646 HRESULT i_createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData);
647 HRESULT i_removeSharedFolder(const Utf8Str &strName);
648
649 HRESULT i_suspendBeforeConfigChange(PUVM pUVM, AutoWriteLock *pAlock, bool *pfResume);
650 void i_resumeAfterConfigChange(PUVM pUVM);
651
652 static DECLCALLBACK(int) i_configConstructor(PUVM pUVM, PVM pVM, void *pvConsole);
653 int i_configConstructorInner(PUVM pUVM, PVM pVM, AutoWriteLock *pAlock);
654 int i_configCfgmOverlay(PCFGMNODE pRoot, IVirtualBox *pVirtualBox, IMachine *pMachine);
655 int i_configDumpAPISettingsTweaks(IVirtualBox *pVirtualBox, IMachine *pMachine);
656
657 int i_configGraphicsController(PCFGMNODE pDevices,
658 const GraphicsControllerType_T graphicsController,
659 BusAssignmentManager *pBusMgr,
660 const ComPtr<IMachine> &pMachine,
661 const ComPtr<IBIOSSettings> &biosSettings,
662 bool fHMEnabled);
663 int i_configMediumAttachment(PCFGMNODE pCtlInst,
664 const char *pcszDevice,
665 unsigned uInstance,
666 StorageBus_T enmBus,
667 bool fUseHostIOCache,
668 bool fBuiltinIoCache,
669 bool fSetupMerge,
670 unsigned uMergeSource,
671 unsigned uMergeTarget,
672 IMediumAttachment *pMediumAtt,
673 MachineState_T aMachineState,
674 HRESULT *phrc,
675 bool fAttachDetach,
676 bool fForceUnmount,
677 bool fHotplug,
678 PUVM pUVM,
679 DeviceType_T *paLedDevType,
680 PCFGMNODE *ppLunL0);
681 int i_configMedium(PCFGMNODE pLunL0,
682 bool fPassthrough,
683 DeviceType_T enmType,
684 bool fUseHostIOCache,
685 bool fBuiltinIoCache,
686 bool fSetupMerge,
687 unsigned uMergeSource,
688 unsigned uMergeTarget,
689 const char *pcszBwGroup,
690 bool fDiscard,
691 IMedium *pMedium,
692 MachineState_T aMachineState,
693 HRESULT *phrc);
694 static DECLCALLBACK(int) i_reconfigureMediumAttachment(Console *pThis,
695 PUVM pUVM,
696 const char *pcszDevice,
697 unsigned uInstance,
698 StorageBus_T enmBus,
699 bool fUseHostIOCache,
700 bool fBuiltinIoCache,
701 bool fSetupMerge,
702 unsigned uMergeSource,
703 unsigned uMergeTarget,
704 IMediumAttachment *aMediumAtt,
705 MachineState_T aMachineState,
706 HRESULT *phrc);
707 static DECLCALLBACK(int) i_changeRemovableMedium(Console *pThis,
708 PUVM pUVM,
709 const char *pcszDevice,
710 unsigned uInstance,
711 StorageBus_T enmBus,
712 bool fUseHostIOCache,
713 IMediumAttachment *aMediumAtt,
714 bool fForce);
715
716 HRESULT i_attachRawPCIDevices(PUVM pUVM, BusAssignmentManager *BusMgr, PCFGMNODE pDevices);
717 void i_attachStatusDriver(PCFGMNODE pCtlInst, PPDMLED *papLeds,
718 uint64_t uFirst, uint64_t uLast,
719 Console::MediumAttachmentMap *pmapMediumAttachments,
720 const char *pcszDevice, unsigned uInstance);
721
722 int i_configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
723 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
724 PCFGMNODE pLunL0, PCFGMNODE pInst,
725 bool fAttachDetach, bool fIgnoreConnectFailure);
726
727 static DECLCALLBACK(int) i_configGuestProperties(void *pvConsole, PUVM pUVM);
728 static DECLCALLBACK(int) i_configGuestControl(void *pvConsole);
729 static DECLCALLBACK(void) i_vmstateChangeCallback(PUVM pUVM, VMSTATE enmState, VMSTATE enmOldState, void *pvUser);
730 static DECLCALLBACK(int) i_unplugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
731 static DECLCALLBACK(int) i_plugCpu(Console *pThis, PUVM pUVM, VMCPUID idCpu);
732 HRESULT i_doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM);
733 HRESULT i_doCPURemove(ULONG aCpu, PUVM pUVM);
734 HRESULT i_doCPUAdd(ULONG aCpu, PUVM pUVM);
735
736 HRESULT i_doNetworkAdapterChange(PUVM pUVM, const char *pszDevice, unsigned uInstance,
737 unsigned uLun, INetworkAdapter *aNetworkAdapter);
738 static DECLCALLBACK(int) i_changeNetworkAttachment(Console *pThis, PUVM pUVM, const char *pszDevice,
739 unsigned uInstance, unsigned uLun,
740 INetworkAdapter *aNetworkAdapter);
741
742 void i_changeClipboardMode(ClipboardMode_T aClipboardMode);
743 int i_changeDnDMode(DnDMode_T aDnDMode);
744
745#ifdef VBOX_WITH_USB
746 HRESULT i_attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs, const Utf8Str &aCaptureFilename);
747 HRESULT i_detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
748
749 static DECLCALLBACK(int) i_usbAttachCallback(Console *that, PUVM pUVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
750 bool aRemote, const char *aAddress, void *pvRemoteBackend,
751 USHORT aPortVersion, ULONG aMaskedIfs, const char *pszCaptureFilename);
752 static DECLCALLBACK(int) i_usbDetachCallback(Console *that, PUVM pUVM, PCRTUUID aUuid);
753#endif
754
755 static DECLCALLBACK(int) i_attachStorageDevice(Console *pThis,
756 PUVM pUVM,
757 const char *pcszDevice,
758 unsigned uInstance,
759 StorageBus_T enmBus,
760 bool fUseHostIOCache,
761 IMediumAttachment *aMediumAtt,
762 bool fSilent);
763 static DECLCALLBACK(int) i_detachStorageDevice(Console *pThis,
764 PUVM pUVM,
765 const char *pcszDevice,
766 unsigned uInstance,
767 StorageBus_T enmBus,
768 IMediumAttachment *aMediumAtt,
769 bool fSilent);
770 HRESULT i_doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
771 HRESULT i_doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, bool fSilent);
772
773 static DECLCALLBACK(int) i_fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
774
775 static DECLCALLBACK(int) i_stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
776
777 static DECLCALLBACK(void) i_genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int rc, RT_SRC_POS_DECL,
778 const char *pszErrorFmt, va_list va);
779
780 void i_setVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
781 static DECLCALLBACK(void) i_setVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
782 const char *pszErrorId, const char *pszFormat, va_list va);
783
784 HRESULT i_captureUSBDevices(PUVM pUVM);
785 void i_detachAllUSBDevices(bool aDone);
786
787 static DECLCALLBACK(int) i_powerUpThread(RTTHREAD Thread, void *pvUser);
788 static DECLCALLBACK(int) i_saveStateThread(RTTHREAD Thread, void *pvUser);
789 static DECLCALLBACK(int) i_powerDownThread(RTTHREAD Thread, void *pvUser);
790
791 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
792 static DECLCALLBACK(void) i_vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
793 static DECLCALLBACK(void) i_vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
794 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
795 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
796 static DECLCALLBACK(void) i_vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
797
798 static DECLCALLBACK(void *) i_drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
799 static DECLCALLBACK(void) i_drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
800 static DECLCALLBACK(int) i_drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
801 static DECLCALLBACK(void) i_drvStatus_Destruct(PPDMDRVINS pDrvIns);
802 static DECLCALLBACK(int) i_drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
803
804 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
805 size_t *pcbKey);
806 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId);
807
808 int mcAudioRefs;
809 volatile uint32_t mcVRDPClients;
810 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
811 volatile bool mcGuestCredentialsProvided;
812
813 static const char *sSSMConsoleUnit;
814 static uint32_t sSSMConsoleVer;
815
816 HRESULT i_loadDataFromSavedState();
817 int i_loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
818
819 static DECLCALLBACK(void) i_saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
820 static DECLCALLBACK(int) i_loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
821
822#ifdef VBOX_WITH_GUEST_PROPS
823 static DECLCALLBACK(int) i_doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
824 HRESULT i_doEnumerateGuestProperties(const Utf8Str &aPatterns,
825 std::vector<Utf8Str> &aNames,
826 std::vector<Utf8Str> &aValues,
827 std::vector<LONG64> &aTimestamps,
828 std::vector<Utf8Str> &aFlags);
829
830 void i_guestPropertiesHandleVMReset(void);
831 bool i_guestPropertiesVRDPEnabled(void);
832 void i_guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
833 void i_guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
834 void i_guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
835 void i_guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
836 void i_guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
837 void i_guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
838 void i_guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
839 void i_guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
840#endif
841
842 bool i_isResetTurnedIntoPowerOff(void);
843
844 /** @name Disk encryption support
845 * @{ */
846 HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
847 HRESULT i_configureEncryptionForDisk(const char *pszUuid);
848 HRESULT i_clearDiskEncryptionKeysOnAllAttachments(void);
849 int i_consoleParseKeyValue(const char *psz, const char **ppszEnd,
850 char **ppszKey, char **ppszVal);
851 /** @} */
852
853 /** @name Teleporter support
854 * @{ */
855 static DECLCALLBACK(int) i_teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
856 HRESULT i_teleporterSrc(TeleporterStateSrc *pState);
857 HRESULT i_teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
858 HRESULT i_teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
859 HRESULT i_teleporterTrg(PUVM pUVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
860 Progress *pProgress, bool *pfPowerOffOnFailure);
861 static DECLCALLBACK(int) i_teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
862 /** @} */
863
864 bool mSavedStateDataLoaded : 1;
865
866 const ComPtr<IMachine> mMachine;
867 const ComPtr<IInternalMachineControl> mControl;
868
869 const ComPtr<IVRDEServer> mVRDEServer;
870
871 ConsoleVRDPServer * const mConsoleVRDPServer;
872 bool mfVRDEChangeInProcess;
873 bool mfVRDEChangePending;
874
875 const ComObjPtr<Guest> mGuest;
876 const ComObjPtr<Keyboard> mKeyboard;
877 const ComObjPtr<Mouse> mMouse;
878 const ComObjPtr<Display> mDisplay;
879 const ComObjPtr<MachineDebugger> mDebugger;
880 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
881 /** This can safely be used without holding any locks.
882 * An AutoCaller suffices to prevent it being destroy while in use and
883 * internally there is a lock providing the necessary serialization. */
884 const ComObjPtr<EventSource> mEventSource;
885#ifdef VBOX_WITH_EXTPACK
886 const ComObjPtr<ExtPackManager> mptrExtPackManager;
887#endif
888 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
889
890 USBDeviceList mUSBDevices;
891 RemoteUSBDeviceList mRemoteUSBDevices;
892
893 SharedFolderDataMap m_mapGlobalSharedFolders;
894 SharedFolderDataMap m_mapMachineSharedFolders;
895 SharedFolderMap m_mapSharedFolders; // the console instances
896
897 /** The user mode VM handle. */
898 PUVM mpUVM;
899 /** Holds the number of "readonly" mpUVM callers (users). */
900 uint32_t mVMCallers;
901 /** Semaphore posted when the number of mpUVM callers drops to zero. */
902 RTSEMEVENT mVMZeroCallersSem;
903 /** true when Console has entered the mpUVM destruction phase. */
904 bool mVMDestroying : 1;
905 /** true when power down is initiated by vmstateChangeCallback (EMT). */
906 bool mVMPoweredOff : 1;
907 /** true when vmstateChangeCallback shouldn't initiate a power down. */
908 bool mVMIsAlreadyPoweringOff : 1;
909 /** true if we already showed the snapshot folder size warning. */
910 bool mfSnapshotFolderSizeWarningShown : 1;
911 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
912 bool mfSnapshotFolderExt4WarningShown : 1;
913 /** true if we already listed the disk type of the snapshot folder. */
914 bool mfSnapshotFolderDiskTypeShown : 1;
915 /** true if a USB controller is available (i.e. USB devices can be attached). */
916 bool mfVMHasUsbController : 1;
917 /** true if the VM power off was caused by reset. */
918 bool mfPowerOffCausedByReset : 1;
919
920 /** Pointer to the VMM -> User (that's us) callbacks. */
921 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
922 {
923 Console *pConsole;
924 } *mpVmm2UserMethods;
925
926 /** The current network attachment type in the VM.
927 * This doesn't have to match the network attachment type maintained in the
928 * NetworkAdapter. This is needed to change the network attachment
929 * dynamically.
930 */
931 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
932 NetworkAttachmentTypeVector meAttachmentType;
933
934 VMMDev * m_pVMMDev;
935#ifdef VBOX_WITH_PDM_AUDIO_DRIVER
936 AudioVRDE * const mAudioVRDE;
937#else
938 AudioSniffer * const mAudioSniffer;
939#endif
940 Nvram * const mNvram;
941#ifdef VBOX_WITH_USB_CARDREADER
942 UsbCardReader * const mUsbCardReader;
943#endif
944 BusAssignmentManager* mBusMgr;
945
946 enum
947 {
948 iLedFloppy = 0,
949 cLedFloppy = 2,
950 iLedIde = iLedFloppy + cLedFloppy,
951 cLedIde = 4,
952 iLedSata = iLedIde + cLedIde,
953 cLedSata = 30,
954 iLedScsi = iLedSata + cLedSata,
955 cLedScsi = 16,
956 iLedSas = iLedScsi + cLedScsi,
957 cLedSas = 8,
958 iLedUsb = iLedSas + cLedSas,
959 cLedUsb = 8,
960 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas + cLedUsb
961 };
962 DeviceType_T maStorageDevType[cLedStorage];
963 PPDMLED mapStorageLeds[cLedStorage];
964 PPDMLED mapNetworkLeds[36]; /**< @todo adapt this to the maximum network card count */
965 PPDMLED mapSharedFolderLed;
966 PPDMLED mapUSBLed[2];
967 PPDMLED mapCrOglLed;
968
969 MediumAttachmentMap mapMediumAttachments;
970
971 /** List of attached USB storage devices. */
972 USBStorageDeviceList mUSBStorageDevices;
973
974 /** Map of secret keys used for disk encryption. */
975 SecretKeyMap m_mapSecretKeys;
976
977 /** Pointer to the key consumer -> provider (that's us) callbacks. */
978 struct MYPDMISECKEY : public PDMISECKEY
979 {
980 Console *pConsole;
981 } *mpIfSecKey;
982
983/* Note: FreeBSD needs this whether netflt is used or not. */
984#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
985 Utf8Str maTAPDeviceName[8];
986 RTFILE maTapFD[8];
987#endif
988
989 bool mVMStateChangeCallbackDisabled;
990
991 bool mfUseHostClipboard;
992
993 /** Local machine state value. */
994 MachineState_T mMachineState;
995
996 /** Pointer to the progress object of a live cancelable task.
997 *
998 * This is currently only used by Console::Teleport(), but is intended to later
999 * be used by the live snapshot code path as well. Actions like
1000 * Console::PowerDown, which automatically cancels out the running snapshot /
1001 * teleportation operation, will cancel the teleportation / live snapshot
1002 * operation before starting. */
1003 ComObjPtr<Progress> mptrCancelableProgress;
1004
1005 ComPtr<IEventListener> mVmListener;
1006
1007 friend struct VMTask;
1008};
1009
1010#endif // !____H_CONSOLEIMPL
1011/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette