VirtualBox

source: vbox/trunk/src/VBox/Main/ConsoleImpl2.cpp@ 32638

Last change on this file since 32638 was 32638, checked in by vboxsync, 14 years ago

typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 181.1 KB
Line 
1/* $Id: ConsoleImpl2.cpp 32638 2010-09-20 12:48:31Z vboxsync $ */
2/** @file
3 * VBox Console COM Class implementation
4 *
5 * @remark We've split out the code that the 64-bit VC++ v8 compiler finds
6 * problematic to optimize so we can disable optimizations and later,
7 * perhaps, find a real solution for it (like rewriting the code and
8 * to stop resemble a tonne of spaghetti).
9 */
10
11/*
12 * Copyright (C) 2006-2010 Oracle Corporation
13 *
14 * This file is part of VirtualBox Open Source Edition (OSE), as
15 * available from http://www.virtualbox.org. This file is free software;
16 * you can redistribute it and/or modify it under the terms of the GNU
17 * General Public License (GPL) as published by the Free Software
18 * Foundation, in version 2 as it comes in the "COPYING" file of the
19 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
20 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
21 */
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26// for some reason Windows burns in sdk\...\winsock.h if this isn't included first
27#include "VBox/com/ptr.h"
28
29#include "ConsoleImpl.h"
30#include "DisplayImpl.h"
31#ifdef VBOX_WITH_GUEST_CONTROL
32# include "GuestImpl.h"
33#endif
34#include "VMMDev.h"
35#include "Global.h"
36
37// generated header
38#include "SchemaDefs.h"
39
40#include "AutoCaller.h"
41#include "Logging.h"
42
43#include <iprt/buildconfig.h>
44#include <iprt/ctype.h>
45#include <iprt/dir.h>
46#include <iprt/file.h>
47#include <iprt/param.h>
48#include <iprt/path.h>
49#include <iprt/string.h>
50#include <iprt/system.h>
51#include <iprt/cpp/exception.h>
52#if 0 /* enable to play with lots of memory. */
53# include <iprt/env.h>
54#endif
55#include <iprt/stream.h>
56
57#include <VBox/vmapi.h>
58#include <VBox/err.h>
59#include <VBox/param.h>
60#include <VBox/pdmapi.h> /* For PDMR3DriverAttach/PDMR3DriverDetach */
61#include <VBox/version.h>
62#include <VBox/HostServices/VBoxClipboardSvc.h>
63#ifdef VBOX_WITH_CROGL
64# include <VBox/HostServices/VBoxCrOpenGLSvc.h>
65#endif
66#ifdef VBOX_WITH_GUEST_PROPS
67# include <VBox/HostServices/GuestPropertySvc.h>
68# include <VBox/com/defs.h>
69# include <VBox/com/array.h>
70# include <hgcm/HGCM.h> /** @todo it should be possible to register a service
71 * extension using a VMMDev callback. */
72# include <vector>
73#endif /* VBOX_WITH_GUEST_PROPS */
74#include <VBox/intnet.h>
75
76#include <VBox/com/com.h>
77#include <VBox/com/string.h>
78#include <VBox/com/array.h>
79
80#ifdef VBOX_WITH_NETFLT
81# if defined(RT_OS_SOLARIS)
82# include <zone.h>
83# elif defined(RT_OS_LINUX)
84# include <unistd.h>
85# include <sys/ioctl.h>
86# include <sys/socket.h>
87# include <linux/types.h>
88# include <linux/if.h>
89# include <linux/wireless.h>
90# elif defined(RT_OS_FREEBSD)
91# include <unistd.h>
92# include <sys/types.h>
93# include <sys/ioctl.h>
94# include <sys/socket.h>
95# include <net/if.h>
96# include <net80211/ieee80211_ioctl.h>
97# endif
98# if defined(RT_OS_WINDOWS)
99# include <VBox/WinNetConfig.h>
100# include <Ntddndis.h>
101# include <devguid.h>
102# else
103# include <HostNetworkInterfaceImpl.h>
104# include <netif.h>
105# include <stdlib.h>
106# endif
107#endif /* VBOX_WITH_NETFLT */
108
109#include "DHCPServerRunner.h"
110
111#if defined(RT_OS_DARWIN)
112
113# include "IOKit/IOKitLib.h"
114
115static int DarwinSmcKey(char *pabKey, uint32_t cbKey)
116{
117 /*
118 * Method as described in Amit Singh's article:
119 * http://osxbook.com/book/bonus/chapter7/tpmdrmmyth/
120 */
121 typedef struct
122 {
123 uint32_t key;
124 uint8_t pad0[22];
125 uint32_t datasize;
126 uint8_t pad1[10];
127 uint8_t cmd;
128 uint32_t pad2;
129 uint8_t data[32];
130 } AppleSMCBuffer;
131
132 AssertReturn(cbKey >= 65, VERR_INTERNAL_ERROR);
133
134 io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
135 IOServiceMatching("AppleSMC"));
136 if (!service)
137 return VERR_NOT_FOUND;
138
139 io_connect_t port = (io_connect_t)0;
140 kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
141 IOObjectRelease(service);
142
143 if (kr != kIOReturnSuccess)
144 return RTErrConvertFromDarwin(kr);
145
146 AppleSMCBuffer inputStruct = { 0, {0}, 32, {0}, 5, };
147 AppleSMCBuffer outputStruct;
148 size_t cbOutputStruct = sizeof(outputStruct);
149
150 for (int i = 0; i < 2; i++)
151 {
152 inputStruct.key = (uint32_t)((i == 0) ? 'OSK0' : 'OSK1');
153 kr = IOConnectCallStructMethod((mach_port_t)port,
154 (uint32_t)2,
155 (const void *)&inputStruct,
156 sizeof(inputStruct),
157 (void *)&outputStruct,
158 &cbOutputStruct);
159 if (kr != kIOReturnSuccess)
160 {
161 IOServiceClose(port);
162 return RTErrConvertFromDarwin(kr);
163 }
164
165 for (int j = 0; j < 32; j++)
166 pabKey[j + i*32] = outputStruct.data[j];
167 }
168
169 IOServiceClose(port);
170
171 pabKey[64] = 0;
172
173 return VINF_SUCCESS;
174}
175
176#endif /* RT_OS_DARWIN */
177
178/* Darwin compile cludge */
179#undef PVM
180
181/* Comment out the following line to remove VMWare compatibility hack. */
182#define VMWARE_NET_IN_SLOT_11
183
184/**
185 * Translate IDE StorageControllerType_T to string representation.
186 */
187const char* controllerString(StorageControllerType_T enmType)
188{
189 switch (enmType)
190 {
191 case StorageControllerType_PIIX3:
192 return "PIIX3";
193 case StorageControllerType_PIIX4:
194 return "PIIX4";
195 case StorageControllerType_ICH6:
196 return "ICH6";
197 default:
198 return "Unknown";
199 }
200}
201
202/**
203 * Simple class for storing network boot information.
204 */
205struct BootNic
206{
207 ULONG mInstance;
208 unsigned mPciDev;
209 unsigned mPciFn;
210 ULONG mBootPrio;
211 bool operator < (const BootNic &rhs) const
212 {
213 ULONG lval = mBootPrio - 1; /* 0 will wrap around and get the lowest priority. */
214 ULONG rval = rhs.mBootPrio - 1;
215 return lval < rval; /* Zero compares as highest number (lowest prio). */
216 }
217};
218
219/*
220 * VC++ 8 / amd64 has some serious trouble with this function.
221 * As a temporary measure, we'll drop global optimizations.
222 */
223#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
224# pragma optimize("g", off)
225#endif
226
227static int findEfiRom(IVirtualBox* vbox, FirmwareType_T aFirmwareType, Utf8Str& aEfiRomFile)
228{
229 int rc;
230 BOOL fPresent = FALSE;
231 Bstr aFilePath, empty;
232
233 rc = vbox->CheckFirmwarePresent(aFirmwareType, empty,
234 empty.asOutParam(), aFilePath.asOutParam(), &fPresent);
235 if (RT_FAILURE(rc))
236 AssertComRCReturn(rc, VERR_FILE_NOT_FOUND);
237
238 if (!fPresent)
239 return VERR_FILE_NOT_FOUND;
240
241 aEfiRomFile = Utf8Str(aFilePath);
242
243 return S_OK;
244}
245
246static int getSmcDeviceKey(IMachine *pMachine, BSTR *aKey, bool *pfGetKeyFromRealSMC)
247{
248 *pfGetKeyFromRealSMC = false;
249
250 /*
251 * The extra data takes precedence (if non-zero).
252 */
253 HRESULT hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/SmcDeviceKey"), aKey);
254 if (FAILED(hrc))
255 return Global::vboxStatusCodeFromCOM(hrc);
256 if ( SUCCEEDED(hrc)
257 && *aKey
258 && **aKey)
259 return VINF_SUCCESS;
260
261#ifdef RT_OS_DARWIN
262 /*
263 * Query it here and now.
264 */
265 char abKeyBuf[65];
266 int rc = DarwinSmcKey(abKeyBuf, sizeof(abKeyBuf));
267 if (SUCCEEDED(rc))
268 {
269 Bstr(abKeyBuf).detachTo(aKey);
270 return rc;
271 }
272 LogRel(("Warning: DarwinSmcKey failed with rc=%Rrc!\n", rc));
273
274#else
275 /*
276 * Is it apple hardware in bootcamp?
277 */
278 /** @todo implement + test RTSYSDMISTR_MANUFACTURER on all hosts.
279 * Currently falling back on the product name. */
280 char szManufacturer[256];
281 szManufacturer[0] = '\0';
282 RTSystemQueryDmiString(RTSYSDMISTR_MANUFACTURER, szManufacturer, sizeof(szManufacturer));
283 if (szManufacturer[0] != '\0')
284 {
285 if ( !strcmp(szManufacturer, "Apple Computer, Inc.")
286 || !strcmp(szManufacturer, "Apple Inc.")
287 )
288 *pfGetKeyFromRealSMC = true;
289 }
290 else
291 {
292 char szProdName[256];
293 szProdName[0] = '\0';
294 RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szProdName, sizeof(szProdName));
295 if ( ( !strncmp(szProdName, "Mac", 3)
296 || !strncmp(szProdName, "iMac", 4)
297 || !strncmp(szProdName, "iMac", 4)
298 || !strncmp(szProdName, "Xserve", 6)
299 )
300 && !strchr(szProdName, ' ') /* no spaces */
301 && RT_C_IS_DIGIT(szProdName[strlen(szProdName) - 1]) /* version number */
302 )
303 *pfGetKeyFromRealSMC = true;
304 }
305
306 int rc = VINF_SUCCESS;
307#endif
308
309 return rc;
310}
311
312class ConfigError : public iprt::Error
313{
314public:
315
316 ConfigError(const char *pcszFunction,
317 int vrc,
318 const char *pcszName)
319 : iprt::Error(Utf8StrFmt("%s failed: rc=%Rrc, pcszName=%s", pcszFunction, vrc, pcszName)),
320 m_vrc(vrc)
321 {
322 AssertMsgFailed(("%s\n", what())); // in strict mode, hit a breakpoint here
323 }
324
325 int m_vrc;
326};
327
328
329/**
330 * Helper that calls CFGMR3InsertString and throws an iprt::Error if that
331 * fails (C-string variant).
332 * @param pParent See CFGMR3InsertStringN.
333 * @param pcszNodeName See CFGMR3InsertStringN.
334 * @param pcszValue The string value.
335 */
336static void InsertConfigString(PCFGMNODE pNode,
337 const char *pcszName,
338 const char *pcszValue)
339{
340 int vrc = CFGMR3InsertString(pNode,
341 pcszName,
342 pcszValue);
343 if (RT_FAILURE(vrc))
344 throw ConfigError("CFGMR3InsertString", vrc, pcszName);
345}
346
347/**
348 * Helper that calls CFGMR3InsertString and throws an iprt::Error if that
349 * fails (Utf8Str variant).
350 * @param pParent See CFGMR3InsertStringN.
351 * @param pcszNodeName See CFGMR3InsertStringN.
352 * @param rStrValue The string value.
353 */
354static void InsertConfigString(PCFGMNODE pNode,
355 const char *pcszName,
356 const Utf8Str &rStrValue)
357{
358 int vrc = CFGMR3InsertStringN(pNode,
359 pcszName,
360 rStrValue.c_str(),
361 rStrValue.length());
362 if (RT_FAILURE(vrc))
363 throw ConfigError("CFGMR3InsertStringLengthKnown", vrc, pcszName);
364}
365
366/**
367 * Helper that calls CFGMR3InsertString and throws an iprt::Error if that
368 * fails (Bstr variant).
369 *
370 * @param pParent See CFGMR3InsertStringN.
371 * @param pcszNodeName See CFGMR3InsertStringN.
372 * @param rBstrValue The string value.
373 */
374static void InsertConfigString(PCFGMNODE pNode,
375 const char *pcszName,
376 const Bstr &rBstrValue)
377{
378 InsertConfigString(pNode, pcszName, Utf8Str(rBstrValue));
379}
380
381/**
382 * Helper that calls CFGMR3InsertBytes and throws an iprt::Error if that fails.
383 *
384 * @param pNode See CFGMR3InsertBytes.
385 * @param pcszName See CFGMR3InsertBytes.
386 * @param pvBytes See CFGMR3InsertBytes.
387 * @param cbBytes See CFGMR3InsertBytes.
388 */
389static void InsertConfigBytes(PCFGMNODE pNode,
390 const char *pcszName,
391 const void *pvBytes,
392 size_t cbBytes)
393{
394 int vrc = CFGMR3InsertBytes(pNode,
395 pcszName,
396 pvBytes,
397 cbBytes);
398 if (RT_FAILURE(vrc))
399 throw ConfigError("CFGMR3InsertBytes", vrc, pcszName);
400}
401
402/**
403 * Helper that calls CFGMR3InsertInteger and thows an iprt::Error if that
404 * fails.
405 *
406 * @param pNode See CFGMR3InsertInteger.
407 * @param pcszName See CFGMR3InsertInteger.
408 * @param u64Integer See CFGMR3InsertInteger.
409 */
410static void InsertConfigInteger(PCFGMNODE pNode,
411 const char *pcszName,
412 uint64_t u64Integer)
413{
414 int vrc = CFGMR3InsertInteger(pNode,
415 pcszName,
416 u64Integer);
417 if (RT_FAILURE(vrc))
418 throw ConfigError("CFGMR3InsertInteger", vrc, pcszName);
419}
420
421/**
422 * Helper that calls CFGMR3InsertNode and throws an iprt::Error if that fails.
423 *
424 * @param pNode See CFGMR3InsertNode.
425 * @param pcszName See CFGMR3InsertNode.
426 * @param ppChild See CFGMR3InsertNode.
427 */
428static void InsertConfigNode(PCFGMNODE pNode,
429 const char *pcszName,
430 PCFGMNODE *ppChild)
431{
432 int vrc = CFGMR3InsertNode(pNode, pcszName, ppChild);
433 if (RT_FAILURE(vrc))
434 throw ConfigError("CFGMR3InsertNode", vrc, pcszName);
435}
436
437/**
438 * Helper that calls CFGMR3RemoveValue and throws an iprt::Error if that fails.
439 *
440 * @param pNode See CFGMR3RemoveValue.
441 * @param pcszName See CFGMR3RemoveValue.
442 */
443static void RemoveConfigValue(PCFGMNODE pNode,
444 const char *pcszName)
445{
446 int vrc = CFGMR3RemoveValue(pNode, pcszName);
447 if (RT_FAILURE(vrc))
448 throw ConfigError("CFGMR3RemoveValue", vrc, pcszName);
449}
450
451
452/**
453 * Construct the VM configuration tree (CFGM).
454 *
455 * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
456 * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
457 * is done here.
458 *
459 * @param pVM VM handle.
460 * @param pvConsole Pointer to the VMPowerUpTask object.
461 * @return VBox status code.
462 *
463 * @note Locks the Console object for writing.
464 */
465DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
466{
467 LogFlowFuncEnter();
468 /* Note: hardcoded assumption about number of slots; see rom bios */
469 bool afPciDeviceNo[32] = {false};
470 bool fFdcEnabled = false;
471 BOOL fIs64BitGuest = false;
472
473#if !defined(VBOX_WITH_XPCOM)
474 {
475 /* initialize COM */
476 HRESULT hrc = CoInitializeEx(NULL,
477 COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
478 COINIT_SPEED_OVER_MEMORY);
479 LogFlow(("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
480 AssertComRCReturn(hrc, VERR_GENERAL_FAILURE);
481 }
482#endif
483
484 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
485 ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
486
487 AutoCaller autoCaller(pConsole);
488 AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
489
490 /* lock the console because we widely use internal fields and methods */
491 AutoWriteLock alock(pConsole COMMA_LOCKVAL_SRC_POS);
492
493 /* Save the VM pointer in the machine object */
494 pConsole->mpVM = pVM;
495
496 ComPtr<IMachine> pMachine = pConsole->machine();
497
498 int rc;
499 HRESULT hrc;
500 Bstr bstr;
501
502#define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
503
504 /*
505 * Get necessary objects and frequently used parameters.
506 */
507 ComPtr<IVirtualBox> virtualBox;
508 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
509
510 ComPtr<IHost> host;
511 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
512
513 ComPtr<ISystemProperties> systemProperties;
514 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
515
516 ComPtr<IBIOSSettings> biosSettings;
517 hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
518
519 hrc = pMachine->COMGETTER(HardwareUUID)(bstr.asOutParam()); H();
520 RTUUID HardwareUuid;
521 rc = RTUuidFromUtf16(&HardwareUuid, bstr.raw());
522 AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
523
524 ULONG cRamMBs;
525 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
526#if 0 /* enable to play with lots of memory. */
527 if (RTEnvExist("VBOX_RAM_SIZE"))
528 cRamMBs = RTStrToUInt64(RTEnvGet("VBOX_RAM_SIZE"));
529#endif
530 uint64_t const cbRam = cRamMBs * (uint64_t)_1M;
531 uint32_t cbRamHole = MM_RAM_HOLE_SIZE_DEFAULT;
532 uint64_t u64McfgBase = 0;
533 uint64_t u64McfgLength = 0;
534
535 ChipsetType_T chipsetType;
536 hrc = pMachine->COMGETTER(ChipsetType)(&chipsetType); H();
537 if (chipsetType == ChipsetType_ICH9)
538 {
539 u64McfgLength = 0x10000000;
540 cbRamHole += u64McfgLength;
541 u64McfgBase = _4G - cbRamHole;
542 }
543
544 ULONG cCpus = 1;
545 hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
546
547 ULONG ulCpuPriority = 100;
548 hrc = pMachine->COMGETTER(CPUPriority)(&ulCpuPriority); H();
549
550 Bstr osTypeId;
551 hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
552
553 BOOL fIOAPIC;
554 hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
555
556 ComPtr<IGuestOSType> guestOSType;
557 hrc = virtualBox->GetGuestOSType(osTypeId, guestOSType.asOutParam()); H();
558
559 Bstr guestTypeFamilyId;
560 hrc = guestOSType->COMGETTER(FamilyId)(guestTypeFamilyId.asOutParam()); H();
561 BOOL fOsXGuest = guestTypeFamilyId == Bstr("MacOS");
562
563 /*
564 * Get root node first.
565 * This is the only node in the tree.
566 */
567 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
568 Assert(pRoot);
569
570 // InsertConfigString throws
571 try
572 {
573
574 /*
575 * Set the root (and VMM) level values.
576 */
577 hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
578 InsertConfigString(pRoot, "Name", bstr);
579 InsertConfigBytes(pRoot, "UUID", &HardwareUuid, sizeof(HardwareUuid));
580 InsertConfigInteger(pRoot, "RamSize", cbRam);
581 InsertConfigInteger(pRoot, "RamHoleSize", cbRamHole);
582 InsertConfigInteger(pRoot, "NumCPUs", cCpus);
583 InsertConfigInteger(pRoot, "CpuPriority", ulCpuPriority);
584 InsertConfigInteger(pRoot, "TimerMillies", 10);
585#ifdef VBOX_WITH_RAW_MODE
586 InsertConfigInteger(pRoot, "RawR3Enabled", 1); /* boolean */
587 InsertConfigInteger(pRoot, "RawR0Enabled", 1); /* boolean */
588 /** @todo Config: RawR0, PATMEnabled and CSAMEnabled needs attention later. */
589 InsertConfigInteger(pRoot, "PATMEnabled", 1); /* boolean */
590 InsertConfigInteger(pRoot, "CSAMEnabled", 1); /* boolean */
591#endif
592 /* Not necessary, but to make sure these two settings end up in the release log. */
593 BOOL fPageFusion = FALSE;
594 hrc = pMachine->COMGETTER(PageFusionEnabled)(&fPageFusion); H();
595 InsertConfigInteger(pRoot, "PageFusion", fPageFusion); /* boolean */
596 ULONG ulBalloonSize = 0;
597 hrc = pMachine->COMGETTER(MemoryBalloonSize)(&ulBalloonSize); H();
598 InsertConfigInteger(pRoot, "MemBalloonSize", ulBalloonSize);
599
600 /*
601 * CPUM values.
602 */
603 PCFGMNODE pCPUM;
604 InsertConfigNode(pRoot, "CPUM", &pCPUM);
605
606 /* cpuid leaf overrides. */
607 static uint32_t const s_auCpuIdRanges[] =
608 {
609 UINT32_C(0x00000000), UINT32_C(0x0000000a),
610 UINT32_C(0x80000000), UINT32_C(0x8000000a)
611 };
612 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
613 for (uint32_t uLeaf = s_auCpuIdRanges[i]; uLeaf < s_auCpuIdRanges[i + 1]; uLeaf++)
614 {
615 ULONG ulEax, ulEbx, ulEcx, ulEdx;
616 hrc = pMachine->GetCPUIDLeaf(uLeaf, &ulEax, &ulEbx, &ulEcx, &ulEdx);
617 if (SUCCEEDED(hrc))
618 {
619 PCFGMNODE pLeaf;
620 InsertConfigNode(pCPUM, Utf8StrFmt("HostCPUID/%RX32", uLeaf).c_str(), &pLeaf);
621
622 InsertConfigInteger(pLeaf, "eax", ulEax);
623 InsertConfigInteger(pLeaf, "ebx", ulEbx);
624 InsertConfigInteger(pLeaf, "ecx", ulEcx);
625 InsertConfigInteger(pLeaf, "edx", ulEdx);
626 }
627 else if (hrc != E_INVALIDARG) H();
628 }
629
630 /* We must limit CPUID count for Windows NT 4, as otherwise it stops
631 with error 0x3e (MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED). */
632 if (osTypeId == "WindowsNT4")
633 {
634 LogRel(("Limiting CPUID leaf count for NT4 guests\n"));
635 InsertConfigInteger(pCPUM, "NT4LeafLimit", true);
636 }
637
638 /* Expose extended MWAIT features to Mac OS X guests. */
639 if (fOsXGuest)
640 {
641 LogRel(("Using MWAIT extensions\n"));
642 InsertConfigInteger(pCPUM, "MWaitExtensions", true);
643 }
644
645 /*
646 * Hardware virtualization extensions.
647 */
648 BOOL fHWVirtExEnabled;
649 BOOL fHwVirtExtForced = false;
650#ifdef VBOX_WITH_RAW_MODE
651 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Enabled, &fHWVirtExEnabled); H();
652 if (cCpus > 1) /** @todo SMP: This isn't nice, but things won't work on mac otherwise. */
653 fHWVirtExEnabled = TRUE;
654# ifdef RT_OS_DARWIN
655 fHwVirtExtForced = fHWVirtExEnabled;
656# else
657 /* - With more than 4GB PGM will use different RAMRANGE sizes for raw
658 mode and hv mode to optimize lookup times.
659 - With more than one virtual CPU, raw-mode isn't a fallback option. */
660 fHwVirtExtForced = fHWVirtExEnabled
661 && ( cbRam > (_4G - cbRamHole)
662 || cCpus > 1);
663# endif
664#else /* !VBOX_WITH_RAW_MODE */
665 fHWVirtExEnabled = fHwVirtExtForced = true;
666#endif /* !VBOX_WITH_RAW_MODE */
667 /* only honor the property value if there was no other reason to enable it */
668 if (!fHwVirtExtForced)
669 {
670 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Force, &fHwVirtExtForced); H();
671 }
672 InsertConfigInteger(pRoot, "HwVirtExtForced", fHwVirtExtForced);
673
674 PCFGMNODE pHWVirtExt;
675 InsertConfigNode(pRoot, "HWVirtExt", &pHWVirtExt);
676 if (fHWVirtExEnabled)
677 {
678 InsertConfigInteger(pHWVirtExt, "Enabled", 1);
679
680 /* Indicate whether 64-bit guests are supported or not. */
681 /** @todo This is currently only forced off on 32-bit hosts only because it
682 * makes a lof of difference there (REM and Solaris performance).
683 */
684 BOOL fSupportsLongMode = false;
685 hrc = host->GetProcessorFeature(ProcessorFeature_LongMode,
686 &fSupportsLongMode); H();
687 hrc = guestOSType->COMGETTER(Is64Bit)(&fIs64BitGuest); H();
688
689 if (fSupportsLongMode && fIs64BitGuest)
690 {
691 InsertConfigInteger(pHWVirtExt, "64bitEnabled", 1);
692#if ARCH_BITS == 32 /* The recompiler must use VBoxREM64 (32-bit host only). */
693 PCFGMNODE pREM;
694 InsertConfigNode(pRoot, "REM", &pREM);
695 InsertConfigInteger(pREM, "64bitEnabled", 1);
696#endif
697 }
698#if ARCH_BITS == 32 /* 32-bit guests only. */
699 else
700 {
701 InsertConfigInteger(pHWVirtExt, "64bitEnabled", 0);
702 }
703#endif
704
705 /** @todo Not exactly pretty to check strings; VBOXOSTYPE would be better, but that requires quite a bit of API change in Main. */
706 if ( !fIs64BitGuest
707 && fIOAPIC
708 && ( osTypeId == "WindowsNT4"
709 || osTypeId == "Windows2000"
710 || osTypeId == "WindowsXP"
711 || osTypeId == "Windows2003"))
712 {
713 /* Only allow TPR patching for NT, Win2k, XP and Windows Server 2003. (32 bits mode)
714 * We may want to consider adding more guest OSes (Solaris) later on.
715 */
716 InsertConfigInteger(pHWVirtExt, "TPRPatchingEnabled", 1);
717 }
718 }
719
720 /* HWVirtEx exclusive mode */
721 BOOL fHWVirtExExclusive = true;
722 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Exclusive, &fHWVirtExExclusive); H();
723 InsertConfigInteger(pHWVirtExt, "Exclusive", fHWVirtExExclusive);
724
725 /* Nested paging (VT-x/AMD-V) */
726 BOOL fEnableNestedPaging = false;
727 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &fEnableNestedPaging); H();
728 InsertConfigInteger(pHWVirtExt, "EnableNestedPaging", fEnableNestedPaging);
729
730 /* Large pages; requires nested paging */
731 BOOL fEnableLargePages = false;
732 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_LargePages, &fEnableLargePages); H();
733 InsertConfigInteger(pHWVirtExt, "EnableLargePages", fEnableLargePages);
734
735 /* VPID (VT-x) */
736 BOOL fEnableVPID = false;
737 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &fEnableVPID); H();
738 InsertConfigInteger(pHWVirtExt, "EnableVPID", fEnableVPID);
739
740 /* Physical Address Extension (PAE) */
741 BOOL fEnablePAE = false;
742 hrc = pMachine->GetCPUProperty(CPUPropertyType_PAE, &fEnablePAE); H();
743 InsertConfigInteger(pRoot, "EnablePAE", fEnablePAE);
744
745 /* Synthetic CPU */
746 BOOL fSyntheticCpu = false;
747 hrc = pMachine->GetCPUProperty(CPUPropertyType_Synthetic, &fSyntheticCpu); H();
748 InsertConfigInteger(pRoot, "SyntheticCpu", fSyntheticCpu);
749
750 BOOL fPXEDebug;
751 hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
752
753 /*
754 * PDM config.
755 * Load drivers in VBoxC.[so|dll]
756 */
757 PCFGMNODE pPDM;
758 PCFGMNODE pDrivers;
759 PCFGMNODE pMod;
760 InsertConfigNode(pRoot, "PDM", &pPDM);
761 InsertConfigNode(pPDM, "Drivers", &pDrivers);
762 InsertConfigNode(pDrivers, "VBoxC", &pMod);
763#ifdef VBOX_WITH_XPCOM
764 // VBoxC is located in the components subdirectory
765 char szPathVBoxC[RTPATH_MAX];
766 rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
767 strcat(szPathVBoxC, "/components/VBoxC");
768 InsertConfigString(pMod, "Path", szPathVBoxC);
769#else
770 InsertConfigString(pMod, "Path", "VBoxC");
771#endif
772
773 /*
774 * I/O settings (cach, max bandwidth, ...).
775 */
776 PCFGMNODE pPDMAc;
777 PCFGMNODE pPDMAcFile;
778 InsertConfigNode(pPDM, "AsyncCompletion", &pPDMAc);
779 InsertConfigNode(pPDMAc, "File", &pPDMAcFile);
780
781 /* Builtin I/O cache */
782 BOOL fIoCache = true;
783 hrc = pMachine->COMGETTER(IoCacheEnabled)(&fIoCache); H();
784 InsertConfigInteger(pPDMAcFile, "CacheEnabled", fIoCache);
785
786 /* I/O cache size */
787 ULONG ioCacheSize = 5;
788 hrc = pMachine->COMGETTER(IoCacheSize)(&ioCacheSize); H();
789 InsertConfigInteger(pPDMAcFile, "CacheSize", ioCacheSize * _1M);
790
791 /*
792 * Devices
793 */
794 PCFGMNODE pDevices = NULL; /* /Devices */
795 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
796 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
797 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
798 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
799 PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
800 PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
801 PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
802 PCFGMNODE pNetBootCfg = NULL; /* /Devices/pcbios/0/Config/NetBoot/ */
803
804 InsertConfigNode(pRoot, "Devices", &pDevices);
805
806 /*
807 * PC Arch.
808 */
809 InsertConfigNode(pDevices, "pcarch", &pDev);
810 InsertConfigNode(pDev, "0", &pInst);
811 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
812 InsertConfigNode(pInst, "Config", &pCfg);
813
814 /*
815 * The time offset
816 */
817 LONG64 timeOffset;
818 hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
819 PCFGMNODE pTMNode;
820 InsertConfigNode(pRoot, "TM", &pTMNode);
821 InsertConfigInteger(pTMNode, "UTCOffset", timeOffset * 1000000);
822
823 /*
824 * DMA
825 */
826 InsertConfigNode(pDevices, "8237A", &pDev);
827 InsertConfigNode(pDev, "0", &pInst);
828 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
829
830 /*
831 * PCI buses.
832 */
833 uint32_t u32IocPciAddress, u32HbcPciAddress;
834 switch (chipsetType)
835 {
836 default:
837 Assert(false);
838 case ChipsetType_PIIX3:
839 InsertConfigNode(pDevices, "pci", &pDev);
840 u32HbcPciAddress = 0;
841 u32IocPciAddress = (0x1 << 16) | 0; // ISA controller
842 break;
843 case ChipsetType_ICH9:
844 InsertConfigNode(pDevices, "ich9pci", &pDev);
845 u32HbcPciAddress = (0x1d << 16) | 0;
846 u32IocPciAddress = (0x1f << 16) | 0; // LPC controller
847 break;
848 }
849 InsertConfigNode(pDev, "0", &pInst);
850 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
851 InsertConfigNode(pInst, "Config", &pCfg);
852 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
853
854#if 0 /* enable this to test PCI bridging */
855 InsertConfigNode(pDevices, "pcibridge", &pDev);
856 InsertConfigNode(pDev, "0", &pInst);
857 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
858 InsertConfigNode(pInst, "Config", &pCfg);
859 InsertConfigInteger(pInst, "PCIDeviceNo", 14);
860 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
861 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 0);/* -> pci[0] */ RC_CHECK();
862
863 InsertConfigNode(pDev, "1", &pInst);
864 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
865 InsertConfigNode(pInst, "Config", &pCfg);
866 InsertConfigInteger(pInst, "PCIDeviceNo", 1);
867 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
868 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
869
870 InsertConfigNode(pDev, "2", &pInst);
871 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
872 InsertConfigNode(pInst, "Config", &pCfg);
873 InsertConfigInteger(pInst, "PCIDeviceNo", 3);
874 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
875 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
876#endif
877
878 /*
879 * Enable 3 following devices: HPET, SMC, LPC on MacOS X guests
880 */
881 /*
882 * High Precision Event Timer (HPET)
883 */
884 BOOL fHpetEnabled;
885 /* Other guests may wish to use HPET too, but MacOS X not functional without it */
886 hrc = pMachine->COMGETTER(HpetEnabled)(&fHpetEnabled); H();
887 /* so always enable HPET in extended profile */
888 fHpetEnabled |= fOsXGuest;
889 /* HPET is always present on ICH9 */
890 fHpetEnabled |= (chipsetType == ChipsetType_ICH9);
891 if (fHpetEnabled)
892 {
893 InsertConfigNode(pDevices, "hpet", &pDev);
894 InsertConfigNode(pDev, "0", &pInst);
895 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
896 }
897
898 /*
899 * System Management Controller (SMC)
900 */
901 BOOL fSmcEnabled;
902 fSmcEnabled = fOsXGuest;
903 if (fSmcEnabled)
904 {
905 InsertConfigNode(pDevices, "smc", &pDev);
906 InsertConfigNode(pDev, "0", &pInst);
907 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
908 InsertConfigNode(pInst, "Config", &pCfg);
909
910 bool fGetKeyFromRealSMC;
911 Bstr bstrKey;
912 rc = getSmcDeviceKey(pMachine, bstrKey.asOutParam(), &fGetKeyFromRealSMC);
913 AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
914
915 InsertConfigString(pCfg, "DeviceKey", bstrKey);
916 InsertConfigInteger(pCfg, "GetKeyFromRealSMC", fGetKeyFromRealSMC);
917 }
918
919 /*
920 * Low Pin Count (LPC) bus
921 */
922 BOOL fLpcEnabled;
923 /** @todo: implement appropriate getter */
924 fLpcEnabled = fOsXGuest || (chipsetType == ChipsetType_ICH9);
925 if (fLpcEnabled)
926 {
927 InsertConfigNode(pDevices, "lpc", &pDev);
928 InsertConfigNode(pDev, "0", &pInst);
929 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
930 }
931
932 /*
933 * PS/2 keyboard & mouse.
934 */
935 InsertConfigNode(pDevices, "pckbd", &pDev);
936 InsertConfigNode(pDev, "0", &pInst);
937 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
938 InsertConfigNode(pInst, "Config", &pCfg);
939
940 InsertConfigNode(pInst, "LUN#0", &pLunL0);
941 InsertConfigString(pLunL0, "Driver", "KeyboardQueue");
942 InsertConfigNode(pLunL0, "Config", &pCfg);
943 InsertConfigInteger(pCfg, "QueueSize", 64);
944
945 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
946 InsertConfigString(pLunL1, "Driver", "MainKeyboard");
947 InsertConfigNode(pLunL1, "Config", &pCfg);
948 Keyboard *pKeyboard = pConsole->mKeyboard;
949 InsertConfigInteger(pCfg, "Object", (uintptr_t)pKeyboard);
950
951 InsertConfigNode(pInst, "LUN#1", &pLunL0);
952 InsertConfigString(pLunL0, "Driver", "MouseQueue");
953 InsertConfigNode(pLunL0, "Config", &pCfg);
954 InsertConfigInteger(pCfg, "QueueSize", 128);
955
956 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
957 InsertConfigString(pLunL1, "Driver", "MainMouse");
958 InsertConfigNode(pLunL1, "Config", &pCfg);
959 Mouse *pMouse = pConsole->mMouse;
960 InsertConfigInteger(pCfg, "Object", (uintptr_t)pMouse);
961
962 /*
963 * i8254 Programmable Interval Timer And Dummy Speaker
964 */
965 InsertConfigNode(pDevices, "i8254", &pDev);
966 InsertConfigNode(pDev, "0", &pInst);
967 InsertConfigNode(pInst, "Config", &pCfg);
968#ifdef DEBUG
969 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
970#endif
971
972 /*
973 * i8259 Programmable Interrupt Controller.
974 */
975 InsertConfigNode(pDevices, "i8259", &pDev);
976 InsertConfigNode(pDev, "0", &pInst);
977 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
978 InsertConfigNode(pInst, "Config", &pCfg);
979
980 /*
981 * Advanced Programmable Interrupt Controller.
982 * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
983 * thus only single insert
984 */
985 InsertConfigNode(pDevices, "apic", &pDev);
986 InsertConfigNode(pDev, "0", &pInst);
987 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
988 InsertConfigNode(pInst, "Config", &pCfg);
989 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
990 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
991
992 if (fIOAPIC)
993 {
994 /*
995 * I/O Advanced Programmable Interrupt Controller.
996 */
997 InsertConfigNode(pDevices, "ioapic", &pDev);
998 InsertConfigNode(pDev, "0", &pInst);
999 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1000 InsertConfigNode(pInst, "Config", &pCfg);
1001 }
1002
1003 /*
1004 * RTC MC146818.
1005 */
1006 InsertConfigNode(pDevices, "mc146818", &pDev);
1007 InsertConfigNode(pDev, "0", &pInst);
1008 InsertConfigNode(pInst, "Config", &pCfg);
1009 BOOL fRTCUseUTC;
1010 hrc = pMachine->COMGETTER(RTCUseUTC)(&fRTCUseUTC); H();
1011 InsertConfigInteger(pCfg, "UseUTC", fRTCUseUTC ? 1 : 0);
1012
1013 /*
1014 * VGA.
1015 */
1016 InsertConfigNode(pDevices, "vga", &pDev);
1017 InsertConfigNode(pDev, "0", &pInst);
1018 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1019 InsertConfigInteger(pInst, "PCIDeviceNo", 2);
1020 Assert(!afPciDeviceNo[2]);
1021 afPciDeviceNo[2] = true;
1022 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
1023 InsertConfigNode(pInst, "Config", &pCfg);
1024 ULONG cVRamMBs;
1025 hrc = pMachine->COMGETTER(VRAMSize)(&cVRamMBs); H();
1026 InsertConfigInteger(pCfg, "VRamSize", cVRamMBs * _1M);
1027 ULONG cMonitorCount;
1028 hrc = pMachine->COMGETTER(MonitorCount)(&cMonitorCount); H();
1029 InsertConfigInteger(pCfg, "MonitorCount", cMonitorCount);
1030#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
1031 InsertConfigInteger(pCfg, "R0Enabled", fHWVirtExEnabled);
1032#endif
1033
1034 /*
1035 * BIOS logo
1036 */
1037 BOOL fFadeIn;
1038 hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
1039 InsertConfigInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0);
1040 BOOL fFadeOut;
1041 hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
1042 InsertConfigInteger(pCfg, "FadeOut", fFadeOut ? 1: 0);
1043 ULONG logoDisplayTime;
1044 hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
1045 InsertConfigInteger(pCfg, "LogoTime", logoDisplayTime);
1046 Bstr logoImagePath;
1047 hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
1048 InsertConfigString(pCfg, "LogoFile", Utf8Str(logoImagePath ? logoImagePath : "") );
1049
1050 /*
1051 * Boot menu
1052 */
1053 BIOSBootMenuMode_T eBootMenuMode;
1054 int iShowBootMenu;
1055 biosSettings->COMGETTER(BootMenuMode)(&eBootMenuMode);
1056 switch (eBootMenuMode)
1057 {
1058 case BIOSBootMenuMode_Disabled: iShowBootMenu = 0; break;
1059 case BIOSBootMenuMode_MenuOnly: iShowBootMenu = 1; break;
1060 default: iShowBootMenu = 2; break;
1061 }
1062 InsertConfigInteger(pCfg, "ShowBootMenu", iShowBootMenu);
1063
1064 /* Custom VESA mode list */
1065 unsigned cModes = 0;
1066 for (unsigned iMode = 1; iMode <= 16; ++iMode)
1067 {
1068 char szExtraDataKey[sizeof("CustomVideoModeXX")];
1069 RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%u", iMode);
1070 hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), bstr.asOutParam()); H();
1071 if (bstr.isEmpty())
1072 break;
1073 InsertConfigString(pCfg, szExtraDataKey, bstr);
1074 ++cModes;
1075 }
1076 InsertConfigInteger(pCfg, "CustomVideoModes", cModes);
1077
1078 /* VESA height reduction */
1079 ULONG ulHeightReduction;
1080 IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
1081 if (pFramebuffer)
1082 {
1083 hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
1084 }
1085 else
1086 {
1087 /* If framebuffer is not available, there is no height reduction. */
1088 ulHeightReduction = 0;
1089 }
1090 InsertConfigInteger(pCfg, "HeightReduction", ulHeightReduction);
1091
1092 /* Attach the display. */
1093 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1094 InsertConfigString(pLunL0, "Driver", "MainDisplay");
1095 InsertConfigNode(pLunL0, "Config", &pCfg);
1096 Display *pDisplay = pConsole->mDisplay;
1097 InsertConfigInteger(pCfg, "Object", (uintptr_t)pDisplay);
1098
1099
1100 /*
1101 * Firmware.
1102 */
1103 FirmwareType_T eFwType = FirmwareType_BIOS;
1104 hrc = pMachine->COMGETTER(FirmwareType)(&eFwType); H();
1105
1106#ifdef VBOX_WITH_EFI
1107 BOOL fEfiEnabled = (eFwType >= FirmwareType_EFI) && (eFwType <= FirmwareType_EFIDUAL);
1108#else
1109 BOOL fEfiEnabled = false;
1110#endif
1111 if (!fEfiEnabled)
1112 {
1113 /*
1114 * PC Bios.
1115 */
1116 InsertConfigNode(pDevices, "pcbios", &pDev);
1117 InsertConfigNode(pDev, "0", &pInst);
1118 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1119 InsertConfigNode(pInst, "Config", &pBiosCfg);
1120 InsertConfigInteger(pBiosCfg, "RamSize", cbRam);
1121 InsertConfigInteger(pBiosCfg, "RamHoleSize", cbRamHole);
1122 InsertConfigInteger(pBiosCfg, "NumCPUs", cCpus);
1123 InsertConfigString(pBiosCfg, "HardDiskDevice", "piix3ide");
1124 InsertConfigString(pBiosCfg, "FloppyDevice", "i82078");
1125 InsertConfigInteger(pBiosCfg, "IOAPIC", fIOAPIC);
1126 InsertConfigInteger(pBiosCfg, "PXEDebug", fPXEDebug);
1127 InsertConfigBytes(pBiosCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));
1128 InsertConfigNode(pBiosCfg, "NetBoot", &pNetBootCfg);
1129
1130 DeviceType_T bootDevice;
1131 if (SchemaDefs::MaxBootPosition > 9)
1132 {
1133 AssertMsgFailed(("Too many boot devices %d\n",
1134 SchemaDefs::MaxBootPosition));
1135 return VERR_INVALID_PARAMETER;
1136 }
1137
1138 for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; ++pos)
1139 {
1140 hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
1141
1142 char szParamName[] = "BootDeviceX";
1143 szParamName[sizeof(szParamName) - 2] = ((char (pos - 1)) + '0');
1144
1145 const char *pszBootDevice;
1146 switch (bootDevice)
1147 {
1148 case DeviceType_Null:
1149 pszBootDevice = "NONE";
1150 break;
1151 case DeviceType_HardDisk:
1152 pszBootDevice = "IDE";
1153 break;
1154 case DeviceType_DVD:
1155 pszBootDevice = "DVD";
1156 break;
1157 case DeviceType_Floppy:
1158 pszBootDevice = "FLOPPY";
1159 break;
1160 case DeviceType_Network:
1161 pszBootDevice = "LAN";
1162 break;
1163 default:
1164 AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
1165 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1166 N_("Invalid boot device '%d'"), bootDevice);
1167 }
1168 InsertConfigString(pBiosCfg, szParamName, pszBootDevice);
1169 }
1170 }
1171 else
1172 {
1173 Utf8Str efiRomFile;
1174
1175 /* Autodetect firmware type, basing on guest type */
1176 if (eFwType == FirmwareType_EFI)
1177 {
1178 eFwType =
1179 fIs64BitGuest ?
1180 (FirmwareType_T)FirmwareType_EFI64
1181 :
1182 (FirmwareType_T)FirmwareType_EFI32;
1183 }
1184 bool f64BitEntry = eFwType == FirmwareType_EFI64;
1185
1186 rc = findEfiRom(virtualBox, eFwType, efiRomFile);
1187 AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
1188
1189 /* Get boot args */
1190 Bstr bootArgs;
1191 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiBootArgs"), bootArgs.asOutParam()); H();
1192
1193 /* Get device props */
1194 Bstr deviceProps;
1195 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiDeviceProps"), deviceProps.asOutParam()); H();
1196 /* Get GOP mode settings */
1197 uint32_t u32GopMode = UINT32_MAX;
1198 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiGopMode"), bstr.asOutParam()); H();
1199 if (!bstr.isEmpty())
1200 u32GopMode = Utf8Str(bstr).toUInt32();
1201
1202 /* UGA mode settings */
1203 uint32_t u32UgaHorisontal = 0;
1204 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaHorizontalResolution"), bstr.asOutParam()); H();
1205 if (!bstr.isEmpty())
1206 u32UgaHorisontal = Utf8Str(bstr).toUInt32();
1207
1208 uint32_t u32UgaVertical = 0;
1209 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaVerticalResolution"), bstr.asOutParam()); H();
1210 if (!bstr.isEmpty())
1211 u32UgaVertical = Utf8Str(bstr).toUInt32();
1212
1213 /*
1214 * EFI subtree.
1215 */
1216 InsertConfigNode(pDevices, "efi", &pDev);
1217 InsertConfigNode(pDev, "0", &pInst);
1218 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1219 InsertConfigNode(pInst, "Config", &pCfg);
1220 InsertConfigInteger(pCfg, "RamSize", cbRam);
1221 InsertConfigInteger(pCfg, "RamHoleSize", cbRamHole);
1222 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
1223 InsertConfigString(pCfg, "EfiRom", efiRomFile);
1224 InsertConfigString(pCfg, "BootArgs", bootArgs);
1225 InsertConfigString(pCfg, "DeviceProps", deviceProps);
1226 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
1227 InsertConfigBytes(pCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));
1228 InsertConfigInteger(pCfg, "64BitEntry", f64BitEntry); /* boolean */
1229 InsertConfigInteger(pCfg, "GopMode", u32GopMode);
1230 InsertConfigInteger(pCfg, "UgaHorizontalResolution", u32UgaHorisontal);
1231 InsertConfigInteger(pCfg, "UgaVerticalResolution", u32UgaVertical);
1232
1233 /* For OS X guests we'll force passing host's DMI info to the guest */
1234 if (fOsXGuest)
1235 {
1236 InsertConfigInteger(pCfg, "DmiUseHostInfo", 1);
1237 InsertConfigInteger(pCfg, "DmiExposeMemoryTable", 1);
1238 }
1239 }
1240
1241 /*
1242 * Storage controllers.
1243 */
1244 com::SafeIfaceArray<IStorageController> ctrls;
1245 PCFGMNODE aCtrlNodes[StorageControllerType_LsiLogicSas + 1] = {};
1246 hrc = pMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(ctrls)); H();
1247
1248 for (size_t i = 0; i < ctrls.size(); ++i)
1249 {
1250 DeviceType_T *paLedDevType = NULL;
1251
1252 StorageControllerType_T enmCtrlType;
1253 rc = ctrls[i]->COMGETTER(ControllerType)(&enmCtrlType); H();
1254 AssertRelease((unsigned)enmCtrlType < RT_ELEMENTS(aCtrlNodes));
1255
1256 StorageBus_T enmBus;
1257 rc = ctrls[i]->COMGETTER(Bus)(&enmBus); H();
1258
1259 Bstr controllerName;
1260 rc = ctrls[i]->COMGETTER(Name)(controllerName.asOutParam()); H();
1261
1262 ULONG ulInstance = 999;
1263 rc = ctrls[i]->COMGETTER(Instance)(&ulInstance); H();
1264
1265 BOOL fUseHostIOCache;
1266 rc = ctrls[i]->COMGETTER(UseHostIOCache)(&fUseHostIOCache); H();
1267
1268 /* /Devices/<ctrldev>/ */
1269 const char *pszCtrlDev = pConsole->convertControllerTypeToDev(enmCtrlType);
1270 pDev = aCtrlNodes[enmCtrlType];
1271 if (!pDev)
1272 {
1273 InsertConfigNode(pDevices, pszCtrlDev, &pDev);
1274 aCtrlNodes[enmCtrlType] = pDev; /* IDE variants are handled in the switch */
1275 }
1276
1277 /* /Devices/<ctrldev>/<instance>/ */
1278 PCFGMNODE pCtlInst = NULL;
1279 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pCtlInst);
1280
1281 /* Device config: /Devices/<ctrldev>/<instance>/<values> & /ditto/Config/<values> */
1282 InsertConfigInteger(pCtlInst, "Trusted", 1);
1283 InsertConfigNode(pCtlInst, "Config", &pCfg);
1284
1285 switch (enmCtrlType)
1286 {
1287 case StorageControllerType_LsiLogic:
1288 {
1289 InsertConfigInteger(pCtlInst, "PCIDeviceNo", 20);
1290 Assert(!afPciDeviceNo[20]);
1291 afPciDeviceNo[20] = true;
1292 InsertConfigInteger(pCtlInst, "PCIFunctionNo", 0);
1293
1294 /* Attach the status driver */
1295 InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
1296 InsertConfigString(pLunL0, "Driver", "MainStatus");
1297 InsertConfigNode(pLunL0, "Config", &pCfg);
1298 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedScsi]);
1299 InsertConfigInteger(pCfg, "First", 0);
1300 Assert(cLedScsi >= 16);
1301 InsertConfigInteger(pCfg, "Last", 15);
1302 paLedDevType = &pConsole->maStorageDevType[iLedScsi];
1303 break;
1304 }
1305
1306 case StorageControllerType_BusLogic:
1307 {
1308 InsertConfigInteger(pCtlInst, "PCIDeviceNo", 21);
1309 Assert(!afPciDeviceNo[21]);
1310 afPciDeviceNo[21] = true;
1311 InsertConfigInteger(pCtlInst, "PCIFunctionNo", 0);
1312
1313 /* Attach the status driver */
1314 InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
1315 InsertConfigString(pLunL0, "Driver", "MainStatus");
1316 InsertConfigNode(pLunL0, "Config", &pCfg);
1317 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedScsi]);
1318 InsertConfigInteger(pCfg, "First", 0);
1319 Assert(cLedScsi >= 16);
1320 InsertConfigInteger(pCfg, "Last", 15);
1321 paLedDevType = &pConsole->maStorageDevType[iLedScsi];
1322 break;
1323 }
1324
1325 case StorageControllerType_IntelAhci:
1326 {
1327 InsertConfigInteger(pCtlInst, "PCIDeviceNo", 13);
1328 Assert(!afPciDeviceNo[13]);
1329 afPciDeviceNo[13] = true;
1330 InsertConfigInteger(pCtlInst, "PCIFunctionNo", 0);
1331
1332 ULONG cPorts = 0;
1333 hrc = ctrls[i]->COMGETTER(PortCount)(&cPorts); H();
1334 InsertConfigInteger(pCfg, "PortCount", cPorts);
1335
1336 /* Needed configuration values for the bios. */
1337 if (pBiosCfg)
1338 {
1339 InsertConfigString(pBiosCfg, "SataHardDiskDevice", "ahci");
1340 }
1341
1342 for (uint32_t j = 0; j < 4; ++j)
1343 {
1344 static const char * const s_apszConfig[4] =
1345 { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
1346 static const char * const s_apszBiosConfig[4] =
1347 { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
1348
1349 LONG lPortNumber = -1;
1350 hrc = ctrls[i]->GetIDEEmulationPort(j, &lPortNumber); H();
1351 InsertConfigInteger(pCfg, s_apszConfig[j], lPortNumber);
1352 if (pBiosCfg)
1353 InsertConfigInteger(pBiosCfg, s_apszBiosConfig[j], lPortNumber);
1354 }
1355
1356 /* Attach the status driver */
1357 InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
1358 InsertConfigString(pLunL0, "Driver", "MainStatus");
1359 InsertConfigNode(pLunL0, "Config", &pCfg);
1360 AssertRelease(cPorts <= cLedSata);
1361 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedSata]);
1362 InsertConfigInteger(pCfg, "First", 0);
1363 InsertConfigInteger(pCfg, "Last", cPorts - 1);
1364 paLedDevType = &pConsole->maStorageDevType[iLedSata];
1365 break;
1366 }
1367
1368 case StorageControllerType_PIIX3:
1369 case StorageControllerType_PIIX4:
1370 case StorageControllerType_ICH6:
1371 {
1372 /*
1373 * IDE (update this when the main interface changes)
1374 */
1375 InsertConfigInteger(pCtlInst, "PCIDeviceNo", 1);
1376 Assert(!afPciDeviceNo[1]);
1377 afPciDeviceNo[1] = true;
1378 InsertConfigInteger(pCtlInst, "PCIFunctionNo", 1);
1379 InsertConfigString(pCfg, "Type", controllerString(enmCtrlType));
1380
1381 /* Attach the status driver */
1382 InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
1383 InsertConfigString(pLunL0, "Driver", "MainStatus");
1384 InsertConfigNode(pLunL0, "Config", &pCfg);
1385 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedIde]);
1386 InsertConfigInteger(pCfg, "First", 0);
1387 Assert(cLedIde >= 4);
1388 InsertConfigInteger(pCfg, "Last", 3);
1389 paLedDevType = &pConsole->maStorageDevType[iLedIde];
1390
1391 /* IDE flavors */
1392 aCtrlNodes[StorageControllerType_PIIX3] = pDev;
1393 aCtrlNodes[StorageControllerType_PIIX4] = pDev;
1394 aCtrlNodes[StorageControllerType_ICH6] = pDev;
1395 break;
1396 }
1397
1398 case StorageControllerType_I82078:
1399 {
1400 /*
1401 * i82078 Floppy drive controller
1402 */
1403 fFdcEnabled = true;
1404 InsertConfigInteger(pCfg, "IRQ", 6);
1405 InsertConfigInteger(pCfg, "DMA", 2);
1406 InsertConfigInteger(pCfg, "MemMapped", 0 );
1407 InsertConfigInteger(pCfg, "IOBase", 0x3f0);
1408
1409 /* Attach the status driver */
1410 InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
1411 InsertConfigString(pLunL0, "Driver", "MainStatus");
1412 InsertConfigNode(pLunL0, "Config", &pCfg);
1413 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedFloppy]);
1414 InsertConfigInteger(pCfg, "First", 0);
1415 Assert(cLedFloppy >= 1);
1416 InsertConfigInteger(pCfg, "Last", 0);
1417 paLedDevType = &pConsole->maStorageDevType[iLedFloppy];
1418 break;
1419 }
1420
1421 case StorageControllerType_LsiLogicSas:
1422 {
1423 InsertConfigInteger(pCtlInst, "PCIDeviceNo", 22);
1424 Assert(!afPciDeviceNo[22]);
1425 afPciDeviceNo[22] = true;
1426 InsertConfigInteger(pCtlInst, "PCIFunctionNo", 0);
1427
1428 InsertConfigString(pCfg, "ControllerType", "SAS1068");
1429
1430 /* Attach the status driver */
1431 InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
1432 InsertConfigString(pLunL0, "Driver", "MainStatus");
1433 InsertConfigNode(pLunL0, "Config", &pCfg);
1434 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedSas]);
1435 InsertConfigInteger(pCfg, "First", 0);
1436 Assert(cLedSas >= 8);
1437 InsertConfigInteger(pCfg, "Last", 7);
1438 paLedDevType = &pConsole->maStorageDevType[iLedSas];
1439 break;
1440 }
1441
1442 default:
1443 AssertMsgFailedReturn(("invalid storage controller type: %d\n", enmCtrlType), VERR_GENERAL_FAILURE);
1444 }
1445
1446 /* Attach the media to the storage controllers. */
1447 com::SafeIfaceArray<IMediumAttachment> atts;
1448 hrc = pMachine->GetMediumAttachmentsOfController(controllerName,
1449 ComSafeArrayAsOutParam(atts)); H();
1450
1451 for (size_t j = 0; j < atts.size(); ++j)
1452 {
1453 rc = pConsole->configMediumAttachment(pCtlInst,
1454 pszCtrlDev,
1455 ulInstance,
1456 enmBus,
1457 fUseHostIOCache,
1458 false /* fSetupMerge */,
1459 0 /* uMergeSource */,
1460 0 /* uMergeTarget */,
1461 atts[j],
1462 pConsole->mMachineState,
1463 NULL /* phrc */,
1464 false /* fAttachDetach */,
1465 false /* fForceUnmount */,
1466 pVM,
1467 paLedDevType);
1468 if (RT_FAILURE(rc))
1469 return rc;
1470 }
1471 H();
1472 }
1473 H();
1474
1475 /*
1476 * Network adapters
1477 */
1478#ifdef VMWARE_NET_IN_SLOT_11
1479 bool fSwapSlots3and11 = false;
1480#endif
1481 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
1482 InsertConfigNode(pDevices, "pcnet", &pDevPCNet);
1483#ifdef VBOX_WITH_E1000
1484 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
1485 InsertConfigNode(pDevices, "e1000", &pDevE1000);
1486#endif
1487#ifdef VBOX_WITH_VIRTIO
1488 PCFGMNODE pDevVirtioNet = NULL; /* Virtio network devices */
1489 InsertConfigNode(pDevices, "virtio-net", &pDevVirtioNet);
1490#endif /* VBOX_WITH_VIRTIO */
1491 std::list<BootNic> llBootNics;
1492 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ++ulInstance)
1493 {
1494 ComPtr<INetworkAdapter> networkAdapter;
1495 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
1496 BOOL fEnabled = FALSE;
1497 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
1498 if (!fEnabled)
1499 continue;
1500
1501 /*
1502 * The virtual hardware type. Create appropriate device first.
1503 */
1504 const char *pszAdapterName = "pcnet";
1505 NetworkAdapterType_T adapterType;
1506 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
1507 switch (adapterType)
1508 {
1509 case NetworkAdapterType_Am79C970A:
1510 case NetworkAdapterType_Am79C973:
1511 pDev = pDevPCNet;
1512 break;
1513#ifdef VBOX_WITH_E1000
1514 case NetworkAdapterType_I82540EM:
1515 case NetworkAdapterType_I82543GC:
1516 case NetworkAdapterType_I82545EM:
1517 pDev = pDevE1000;
1518 pszAdapterName = "e1000";
1519 break;
1520#endif
1521#ifdef VBOX_WITH_VIRTIO
1522 case NetworkAdapterType_Virtio:
1523 pDev = pDevVirtioNet;
1524 pszAdapterName = "virtio-net";
1525 break;
1526#endif /* VBOX_WITH_VIRTIO */
1527 default:
1528 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
1529 adapterType, ulInstance));
1530 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1531 N_("Invalid network adapter type '%d' for slot '%d'"),
1532 adapterType, ulInstance);
1533 }
1534
1535 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
1536 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1537 /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
1538 * next 4 get 16..19. */
1539 unsigned iPciDeviceNo = 3;
1540 if (ulInstance)
1541 {
1542 if (ulInstance < 4)
1543 iPciDeviceNo = ulInstance - 1 + 8;
1544 else
1545 iPciDeviceNo = ulInstance - 4 + 16;
1546 }
1547#ifdef VMWARE_NET_IN_SLOT_11
1548 /*
1549 * Dirty hack for PCI slot compatibility with VMWare,
1550 * it assigns slot 11 to the first network controller.
1551 */
1552 if (iPciDeviceNo == 3 && adapterType == NetworkAdapterType_I82545EM)
1553 {
1554 iPciDeviceNo = 0x11;
1555 fSwapSlots3and11 = true;
1556 }
1557 else if (iPciDeviceNo == 0x11 && fSwapSlots3and11)
1558 iPciDeviceNo = 3;
1559#endif
1560 InsertConfigInteger(pInst, "PCIDeviceNo", iPciDeviceNo);
1561 Assert(!afPciDeviceNo[iPciDeviceNo]);
1562 afPciDeviceNo[iPciDeviceNo] = true;
1563 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
1564 InsertConfigNode(pInst, "Config", &pCfg);
1565#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
1566 if (pDev == pDevPCNet)
1567 {
1568 InsertConfigInteger(pCfg, "R0Enabled", false);
1569 }
1570#endif
1571 /*
1572 * Collect information needed for network booting and add it to the list.
1573 */
1574 BootNic nic;
1575
1576 nic.mInstance = ulInstance;
1577 nic.mPciDev = iPciDeviceNo;
1578 nic.mPciFn = 0;
1579
1580 hrc = networkAdapter->COMGETTER(BootPriority)(&nic.mBootPrio); H();
1581
1582 llBootNics.push_back(nic);
1583
1584 /*
1585 * The virtual hardware type. PCNet supports two types.
1586 */
1587 switch (adapterType)
1588 {
1589 case NetworkAdapterType_Am79C970A:
1590 InsertConfigInteger(pCfg, "Am79C973", 0);
1591 break;
1592 case NetworkAdapterType_Am79C973:
1593 InsertConfigInteger(pCfg, "Am79C973", 1);
1594 break;
1595 case NetworkAdapterType_I82540EM:
1596 InsertConfigInteger(pCfg, "AdapterType", 0);
1597 break;
1598 case NetworkAdapterType_I82543GC:
1599 InsertConfigInteger(pCfg, "AdapterType", 1);
1600 break;
1601 case NetworkAdapterType_I82545EM:
1602 InsertConfigInteger(pCfg, "AdapterType", 2);
1603 break;
1604 }
1605
1606 /*
1607 * Get the MAC address and convert it to binary representation
1608 */
1609 Bstr macAddr;
1610 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1611 Assert(macAddr);
1612 Utf8Str macAddrUtf8 = macAddr;
1613 char *macStr = (char*)macAddrUtf8.c_str();
1614 Assert(strlen(macStr) == 12);
1615 RTMAC Mac;
1616 memset(&Mac, 0, sizeof(Mac));
1617 char *pMac = (char*)&Mac;
1618 for (uint32_t i = 0; i < 6; ++i)
1619 {
1620 char c1 = *macStr++ - '0';
1621 if (c1 > 9)
1622 c1 -= 7;
1623 char c2 = *macStr++ - '0';
1624 if (c2 > 9)
1625 c2 -= 7;
1626 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1627 }
1628 InsertConfigBytes(pCfg, "MAC", &Mac, sizeof(Mac));
1629
1630 /*
1631 * Check if the cable is supposed to be unplugged
1632 */
1633 BOOL fCableConnected;
1634 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1635 InsertConfigInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0);
1636
1637 /*
1638 * Line speed to report from custom drivers
1639 */
1640 ULONG ulLineSpeed;
1641 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1642 InsertConfigInteger(pCfg, "LineSpeed", ulLineSpeed);
1643
1644 /*
1645 * Attach the status driver.
1646 */
1647 InsertConfigNode(pInst, "LUN#999", &pLunL0);
1648 InsertConfigString(pLunL0, "Driver", "MainStatus");
1649 InsertConfigNode(pLunL0, "Config", &pCfg);
1650 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]);
1651
1652 /*
1653 * Configure the network card now
1654 */
1655 rc = pConsole->configNetwork(pszAdapterName,
1656 ulInstance,
1657 0,
1658 networkAdapter,
1659 pCfg,
1660 pLunL0,
1661 pInst,
1662 false /*fAttachDetach*/);
1663 if (RT_FAILURE(rc))
1664 return rc;
1665 }
1666
1667 /*
1668 * Build network boot information and transfer it to the BIOS.
1669 */
1670 if (pNetBootCfg && !llBootNics.empty()) /* NetBoot node doesn't exist for EFI! */
1671 {
1672 llBootNics.sort(); /* Sort the list by boot priority. */
1673
1674 char achBootIdx[] = "0";
1675 unsigned uBootIdx = 0;
1676
1677 for (std::list<BootNic>::iterator it = llBootNics.begin(); it != llBootNics.end(); ++it)
1678 {
1679 /* A NIC with priority 0 is only used if it's first in the list. */
1680 if (it->mBootPrio == 0 && uBootIdx != 0)
1681 break;
1682
1683 PCFGMNODE pNetBtDevCfg;
1684 achBootIdx[0] = '0' + uBootIdx++; /* Boot device order. */
1685 InsertConfigNode(pNetBootCfg, achBootIdx, &pNetBtDevCfg);
1686 InsertConfigInteger(pNetBtDevCfg, "NIC", it->mInstance);
1687 InsertConfigInteger(pNetBtDevCfg, "PCIDeviceNo", it->mPciDev);
1688 InsertConfigInteger(pNetBtDevCfg, "PCIFunctionNo", it->mPciFn);
1689 }
1690 }
1691
1692 /*
1693 * Serial (UART) Ports
1694 */
1695 InsertConfigNode(pDevices, "serial", &pDev);
1696 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ++ulInstance)
1697 {
1698 ComPtr<ISerialPort> serialPort;
1699 hrc = pMachine->GetSerialPort(ulInstance, serialPort.asOutParam()); H();
1700 BOOL fEnabled = FALSE;
1701 if (serialPort)
1702 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1703 if (!fEnabled)
1704 continue;
1705
1706 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
1707 InsertConfigNode(pInst, "Config", &pCfg);
1708
1709 ULONG ulIRQ;
1710 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1711 InsertConfigInteger(pCfg, "IRQ", ulIRQ);
1712 ULONG ulIOBase;
1713 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1714 InsertConfigInteger(pCfg, "IOBase", ulIOBase);
1715 BOOL fServer;
1716 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1717 hrc = serialPort->COMGETTER(Path)(bstr.asOutParam()); H();
1718 PortMode_T eHostMode;
1719 hrc = serialPort->COMGETTER(HostMode)(&eHostMode); H();
1720 if (eHostMode != PortMode_Disconnected)
1721 {
1722 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1723 if (eHostMode == PortMode_HostPipe)
1724 {
1725 InsertConfigString(pLunL0, "Driver", "Char");
1726 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
1727 InsertConfigString(pLunL1, "Driver", "NamedPipe");
1728 InsertConfigNode(pLunL1, "Config", &pLunL2);
1729 InsertConfigString(pLunL2, "Location", bstr);
1730 InsertConfigInteger(pLunL2, "IsServer", fServer);
1731 }
1732 else if (eHostMode == PortMode_HostDevice)
1733 {
1734 InsertConfigString(pLunL0, "Driver", "Host Serial");
1735 InsertConfigNode(pLunL0, "Config", &pLunL1);
1736 InsertConfigString(pLunL1, "DevicePath", bstr);
1737 }
1738 else if (eHostMode == PortMode_RawFile)
1739 {
1740 InsertConfigString(pLunL0, "Driver", "Char");
1741 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
1742 InsertConfigString(pLunL1, "Driver", "RawFile");
1743 InsertConfigNode(pLunL1, "Config", &pLunL2);
1744 InsertConfigString(pLunL2, "Location", bstr);
1745 }
1746 }
1747 }
1748
1749 /*
1750 * Parallel (LPT) Ports
1751 */
1752 InsertConfigNode(pDevices, "parallel", &pDev);
1753 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ++ulInstance)
1754 {
1755 ComPtr<IParallelPort> parallelPort;
1756 hrc = pMachine->GetParallelPort(ulInstance, parallelPort.asOutParam()); H();
1757 BOOL fEnabled = FALSE;
1758 if (parallelPort)
1759 {
1760 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1761 }
1762 if (!fEnabled)
1763 continue;
1764
1765 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
1766 InsertConfigNode(pInst, "Config", &pCfg);
1767
1768 ULONG ulIRQ;
1769 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1770 InsertConfigInteger(pCfg, "IRQ", ulIRQ);
1771 ULONG ulIOBase;
1772 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1773 InsertConfigInteger(pCfg, "IOBase", ulIOBase);
1774 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1775 InsertConfigString(pLunL0, "Driver", "HostParallel");
1776 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
1777 hrc = parallelPort->COMGETTER(Path)(bstr.asOutParam()); H();
1778 InsertConfigString(pLunL1, "DevicePath", bstr);
1779 }
1780
1781 /*
1782 * VMM Device
1783 */
1784 InsertConfigNode(pDevices, "VMMDev", &pDev);
1785 InsertConfigNode(pDev, "0", &pInst);
1786 InsertConfigNode(pInst, "Config", &pCfg);
1787 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1788 InsertConfigInteger(pInst, "PCIDeviceNo", 4);
1789 Assert(!afPciDeviceNo[4]);
1790 afPciDeviceNo[4] = true;
1791 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
1792 Bstr hwVersion;
1793 hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
1794 InsertConfigInteger(pCfg, "RamSize", cbRam);
1795 if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
1796 InsertConfigInteger(pCfg, "HeapEnabled", 0);
1797
1798 /* the VMM device's Main driver */
1799 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1800 InsertConfigString(pLunL0, "Driver", "HGCM");
1801 InsertConfigNode(pLunL0, "Config", &pCfg);
1802 VMMDev *pVMMDev = pConsole->mVMMDev;
1803 InsertConfigInteger(pCfg, "Object", (uintptr_t)pVMMDev);
1804
1805 /*
1806 * Attach the status driver.
1807 */
1808 InsertConfigNode(pInst, "LUN#999", &pLunL0);
1809 InsertConfigString(pLunL0, "Driver", "MainStatus");
1810 InsertConfigNode(pLunL0, "Config", &pCfg);
1811 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed);
1812 InsertConfigInteger(pCfg, "First", 0);
1813 InsertConfigInteger(pCfg, "Last", 0);
1814
1815 /*
1816 * Audio Sniffer Device
1817 */
1818 InsertConfigNode(pDevices, "AudioSniffer", &pDev);
1819 InsertConfigNode(pDev, "0", &pInst);
1820 InsertConfigNode(pInst, "Config", &pCfg);
1821
1822 /* the Audio Sniffer device's Main driver */
1823 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1824 InsertConfigString(pLunL0, "Driver", "MainAudioSniffer");
1825 InsertConfigNode(pLunL0, "Config", &pCfg);
1826 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1827 InsertConfigInteger(pCfg, "Object", (uintptr_t)pAudioSniffer);
1828
1829 /*
1830 * AC'97 ICH / SoundBlaster16 audio / Intel HD Audio
1831 */
1832 BOOL fAudioEnabled;
1833 ComPtr<IAudioAdapter> audioAdapter;
1834 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1835 if (audioAdapter)
1836 hrc = audioAdapter->COMGETTER(Enabled)(&fAudioEnabled); H();
1837
1838 if (fAudioEnabled)
1839 {
1840 AudioControllerType_T audioController;
1841 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
1842 switch (audioController)
1843 {
1844 case AudioControllerType_AC97:
1845 {
1846 /* default: ICH AC97 */
1847 InsertConfigNode(pDevices, "ichac97", &pDev);
1848 InsertConfigNode(pDev, "0", &pInst);
1849 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1850 InsertConfigInteger(pInst, "PCIDeviceNo", 5);
1851 Assert(!afPciDeviceNo[5]);
1852 afPciDeviceNo[5] = true;
1853 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
1854 InsertConfigNode(pInst, "Config", &pCfg);
1855 break;
1856 }
1857 case AudioControllerType_SB16:
1858 {
1859 /* legacy SoundBlaster16 */
1860 InsertConfigNode(pDevices, "sb16", &pDev);
1861 InsertConfigNode(pDev, "0", &pInst);
1862 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1863 InsertConfigNode(pInst, "Config", &pCfg);
1864 InsertConfigInteger(pCfg, "IRQ", 5);
1865 InsertConfigInteger(pCfg, "DMA", 1);
1866 InsertConfigInteger(pCfg, "DMA16", 5);
1867 InsertConfigInteger(pCfg, "Port", 0x220);
1868 InsertConfigInteger(pCfg, "Version", 0x0405);
1869 break;
1870 }
1871 case AudioControllerType_HDA:
1872 {
1873 /* Intel HD Audio */
1874 InsertConfigNode(pDevices, "hda", &pDev);
1875 InsertConfigNode(pDev, "0", &pInst);
1876 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1877 InsertConfigInteger(pInst, "PCIDeviceNo", 5);
1878 Assert(!afPciDeviceNo[5]);
1879 afPciDeviceNo[5] = true;
1880 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
1881 InsertConfigNode(pInst, "Config", &pCfg);
1882 }
1883 }
1884
1885 /* the Audio driver */
1886 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1887 InsertConfigString(pLunL0, "Driver", "AUDIO");
1888 InsertConfigNode(pLunL0, "Config", &pCfg);
1889
1890 AudioDriverType_T audioDriver;
1891 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1892 switch (audioDriver)
1893 {
1894 case AudioDriverType_Null:
1895 {
1896 InsertConfigString(pCfg, "AudioDriver", "null");
1897 break;
1898 }
1899#ifdef RT_OS_WINDOWS
1900#ifdef VBOX_WITH_WINMM
1901 case AudioDriverType_WinMM:
1902 {
1903 InsertConfigString(pCfg, "AudioDriver", "winmm");
1904 break;
1905 }
1906#endif
1907 case AudioDriverType_DirectSound:
1908 {
1909 InsertConfigString(pCfg, "AudioDriver", "dsound");
1910 break;
1911 }
1912#endif /* RT_OS_WINDOWS */
1913#ifdef RT_OS_SOLARIS
1914 case AudioDriverType_SolAudio:
1915 {
1916 InsertConfigString(pCfg, "AudioDriver", "solaudio");
1917 break;
1918 }
1919#endif
1920#ifdef RT_OS_LINUX
1921# ifdef VBOX_WITH_ALSA
1922 case AudioDriverType_ALSA:
1923 {
1924 InsertConfigString(pCfg, "AudioDriver", "alsa");
1925 break;
1926 }
1927# endif
1928# ifdef VBOX_WITH_PULSE
1929 case AudioDriverType_Pulse:
1930 {
1931 InsertConfigString(pCfg, "AudioDriver", "pulse");
1932 break;
1933 }
1934# endif
1935#endif /* RT_OS_LINUX */
1936#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
1937 case AudioDriverType_OSS:
1938 {
1939 InsertConfigString(pCfg, "AudioDriver", "oss");
1940 break;
1941 }
1942#endif
1943#ifdef RT_OS_FREEBSD
1944# ifdef VBOX_WITH_PULSE
1945 case AudioDriverType_Pulse:
1946 {
1947 InsertConfigString(pCfg, "AudioDriver", "pulse");
1948 break;
1949 }
1950# endif
1951#endif
1952#ifdef RT_OS_DARWIN
1953 case AudioDriverType_CoreAudio:
1954 {
1955 InsertConfigString(pCfg, "AudioDriver", "coreaudio");
1956 break;
1957 }
1958#endif
1959 }
1960 hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
1961 InsertConfigString(pCfg, "StreamName", bstr);
1962 }
1963
1964 /*
1965 * The USB Controller.
1966 */
1967 ComPtr<IUSBController> USBCtlPtr;
1968 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1969 if (USBCtlPtr)
1970 {
1971 BOOL fOhciEnabled;
1972 hrc = USBCtlPtr->COMGETTER(Enabled)(&fOhciEnabled); H();
1973 if (fOhciEnabled)
1974 {
1975 InsertConfigNode(pDevices, "usb-ohci", &pDev);
1976 InsertConfigNode(pDev, "0", &pInst);
1977 InsertConfigNode(pInst, "Config", &pCfg);
1978 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1979 InsertConfigInteger(pInst, "PCIDeviceNo", 6);
1980 Assert(!afPciDeviceNo[6]);
1981 afPciDeviceNo[6] = true;
1982 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
1983
1984 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1985 InsertConfigString(pLunL0, "Driver", "VUSBRootHub");
1986 InsertConfigNode(pLunL0, "Config", &pCfg);
1987
1988 /*
1989 * Attach the status driver.
1990 */
1991 InsertConfigNode(pInst, "LUN#999", &pLunL0);
1992 InsertConfigString(pLunL0, "Driver", "MainStatus");
1993 InsertConfigNode(pLunL0, "Config", &pCfg);
1994 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);
1995 InsertConfigInteger(pCfg, "First", 0);
1996 InsertConfigInteger(pCfg, "Last", 0);
1997
1998#ifdef VBOX_WITH_EHCI
1999 BOOL fEhciEnabled;
2000 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEhciEnabled); H();
2001 if (fEhciEnabled)
2002 {
2003 InsertConfigNode(pDevices, "usb-ehci", &pDev);
2004 InsertConfigNode(pDev, "0", &pInst);
2005 InsertConfigNode(pInst, "Config", &pCfg);
2006 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2007 InsertConfigInteger(pInst, "PCIDeviceNo", 11);
2008 Assert(!afPciDeviceNo[11]);
2009 afPciDeviceNo[11] = true;
2010 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
2011
2012 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2013 InsertConfigString(pLunL0, "Driver", "VUSBRootHub");
2014 InsertConfigNode(pLunL0, "Config", &pCfg);
2015
2016 /*
2017 * Attach the status driver.
2018 */
2019 InsertConfigNode(pInst, "LUN#999", &pLunL0);
2020 InsertConfigString(pLunL0, "Driver", "MainStatus");
2021 InsertConfigNode(pLunL0, "Config", &pCfg);
2022 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);
2023 InsertConfigInteger(pCfg, "First", 0);
2024 InsertConfigInteger(pCfg, "Last", 0);
2025 }
2026#endif
2027
2028 /*
2029 * Virtual USB Devices.
2030 */
2031 PCFGMNODE pUsbDevices = NULL;
2032 InsertConfigNode(pRoot, "USB", &pUsbDevices);
2033
2034#ifdef VBOX_WITH_USB
2035 {
2036 /*
2037 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
2038 * on a per device level now.
2039 */
2040 InsertConfigNode(pUsbDevices, "USBProxy", &pCfg);
2041 InsertConfigNode(pCfg, "GlobalConfig", &pCfg);
2042 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
2043 //InsertConfigInteger(pCfg, "Force11Device", true);
2044 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
2045 // that it's documented somewhere.) Users needing it can use:
2046 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
2047 //InsertConfigInteger(pCfg, "Force11PacketSize", true);
2048 }
2049#endif
2050
2051# if 0 /* Virtual MSD*/
2052
2053 InsertConfigNode(pUsbDevices, "Msd", &pDev);
2054 InsertConfigNode(pDev, "0", &pInst);
2055 InsertConfigNode(pInst, "Config", &pCfg);
2056 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2057
2058 InsertConfigString(pLunL0, "Driver", "SCSI");
2059 InsertConfigNode(pLunL0, "Config", &pCfg);
2060
2061 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
2062 InsertConfigString(pLunL1, "Driver", "Block");
2063 InsertConfigNode(pLunL1, "Config", &pCfg);
2064 InsertConfigString(pCfg, "Type", "HardDisk");
2065 InsertConfigInteger(pCfg, "Mountable", 0);
2066
2067 InsertConfigNode(pLunL1, "AttachedDriver", &pLunL2);
2068 InsertConfigString(pLunL2, "Driver", "VD");
2069 InsertConfigNode(pLunL2, "Config", &pCfg);
2070 InsertConfigString(pCfg, "Path", "/Volumes/DataHFS/bird/VDIs/linux.vdi");
2071 InsertConfigString(pCfg, "Format", "VDI");
2072# endif
2073
2074 /* Virtual USB Mouse/Tablet */
2075 PointingHidType_T aPointingHid;
2076 hrc = pMachine->COMGETTER(PointingHidType)(&aPointingHid); H();
2077 if (aPointingHid == PointingHidType_USBMouse || aPointingHid == PointingHidType_USBTablet)
2078 {
2079 InsertConfigNode(pUsbDevices, "HidMouse", &pDev);
2080 InsertConfigNode(pDev, "0", &pInst);
2081 InsertConfigNode(pInst, "Config", &pCfg);
2082
2083 if (aPointingHid == PointingHidType_USBTablet)
2084 {
2085 InsertConfigInteger(pCfg, "Absolute", 1);
2086 }
2087 else
2088 {
2089 InsertConfigInteger(pCfg, "Absolute", 0);
2090 }
2091 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2092 InsertConfigString(pLunL0, "Driver", "MouseQueue");
2093 InsertConfigNode(pLunL0, "Config", &pCfg);
2094 InsertConfigInteger(pCfg, "QueueSize", 128);
2095
2096 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
2097 InsertConfigString(pLunL1, "Driver", "MainMouse");
2098 InsertConfigNode(pLunL1, "Config", &pCfg);
2099 pMouse = pConsole->mMouse;
2100 InsertConfigInteger(pCfg, "Object", (uintptr_t)pMouse);
2101 }
2102
2103 /* Virtual USB Keyboard */
2104 KeyboardHidType_T aKbdHid;
2105 hrc = pMachine->COMGETTER(KeyboardHidType)(&aKbdHid); H();
2106 if (aKbdHid == KeyboardHidType_USBKeyboard)
2107 {
2108 InsertConfigNode(pUsbDevices, "HidKeyboard", &pDev);
2109 InsertConfigNode(pDev, "0", &pInst);
2110 InsertConfigNode(pInst, "Config", &pCfg);
2111
2112 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2113 InsertConfigString(pLunL0, "Driver", "KeyboardQueue");
2114 InsertConfigNode(pLunL0, "Config", &pCfg);
2115 InsertConfigInteger(pCfg, "QueueSize", 64);
2116
2117 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
2118 InsertConfigString(pLunL1, "Driver", "MainKeyboard");
2119 InsertConfigNode(pLunL1, "Config", &pCfg);
2120 pKeyboard = pConsole->mKeyboard;
2121 InsertConfigInteger(pCfg, "Object", (uintptr_t)pKeyboard);
2122 }
2123 }
2124 }
2125
2126 /*
2127 * Clipboard
2128 */
2129 {
2130 ClipboardMode_T mode = ClipboardMode_Disabled;
2131 hrc = pMachine->COMGETTER(ClipboardMode)(&mode); H();
2132
2133 if (mode != ClipboardMode_Disabled)
2134 {
2135 /* Load the service */
2136 rc = pConsole->mVMMDev->hgcmLoadService("VBoxSharedClipboard", "VBoxSharedClipboard");
2137
2138 if (RT_FAILURE(rc))
2139 {
2140 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
2141 /* That is not a fatal failure. */
2142 rc = VINF_SUCCESS;
2143 }
2144 else
2145 {
2146 /* Setup the service. */
2147 VBOXHGCMSVCPARM parm;
2148
2149 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2150
2151 switch (mode)
2152 {
2153 default:
2154 case ClipboardMode_Disabled:
2155 {
2156 LogRel(("VBoxSharedClipboard mode: Off\n"));
2157 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
2158 break;
2159 }
2160 case ClipboardMode_GuestToHost:
2161 {
2162 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
2163 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
2164 break;
2165 }
2166 case ClipboardMode_HostToGuest:
2167 {
2168 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
2169 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
2170 break;
2171 }
2172 case ClipboardMode_Bidirectional:
2173 {
2174 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
2175 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
2176 break;
2177 }
2178 }
2179
2180 pConsole->mVMMDev->hgcmHostCall("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
2181
2182 Log(("Set VBoxSharedClipboard mode\n"));
2183 }
2184 }
2185 }
2186
2187#ifdef VBOX_WITH_CROGL
2188 /*
2189 * crOpenGL
2190 */
2191 {
2192 BOOL fEnabled = false;
2193 hrc = pMachine->COMGETTER(Accelerate3DEnabled)(&fEnabled); H();
2194
2195 if (fEnabled)
2196 {
2197 /* Load the service */
2198 rc = pConsole->mVMMDev->hgcmLoadService("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
2199 if (RT_FAILURE(rc))
2200 {
2201 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
2202 /* That is not a fatal failure. */
2203 rc = VINF_SUCCESS;
2204 }
2205 else
2206 {
2207 LogRel(("Shared crOpenGL service loaded.\n"));
2208
2209 /* Setup the service. */
2210 VBOXHGCMSVCPARM parm;
2211 parm.type = VBOX_HGCM_SVC_PARM_PTR;
2212
2213 parm.u.pointer.addr = (IConsole*) (Console*) pConsole;
2214 parm.u.pointer.size = sizeof(IConsole *);
2215
2216 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_CONSOLE,
2217 SHCRGL_CPARMS_SET_CONSOLE, &parm);
2218 if (!RT_SUCCESS(rc))
2219 AssertMsgFailed(("SHCRGL_HOST_FN_SET_CONSOLE failed with %Rrc\n", rc));
2220
2221 parm.u.pointer.addr = pVM;
2222 parm.u.pointer.size = sizeof(pVM);
2223 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VM,
2224 SHCRGL_CPARMS_SET_VM, &parm);
2225 if (!RT_SUCCESS(rc))
2226 AssertMsgFailed(("SHCRGL_HOST_FN_SET_VM failed with %Rrc\n", rc));
2227 }
2228
2229 }
2230 }
2231#endif
2232
2233#ifdef VBOX_WITH_GUEST_PROPS
2234 /*
2235 * Guest property service
2236 */
2237
2238 rc = configGuestProperties(pConsole);
2239#endif /* VBOX_WITH_GUEST_PROPS defined */
2240
2241#ifdef VBOX_WITH_GUEST_CONTROL
2242 /*
2243 * Guest control service
2244 */
2245
2246 rc = configGuestControl(pConsole);
2247#endif /* VBOX_WITH_GUEST_CONTROL defined */
2248
2249 /*
2250 * ACPI
2251 */
2252 BOOL fACPI;
2253 hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
2254 if (fACPI)
2255 {
2256 BOOL fCpuHotPlug = false;
2257 BOOL fShowCpu = fOsXGuest;
2258 /* Always show the CPU leafs when we have multiple VCPUs or when the IO-APIC is enabled.
2259 * The Windows SMP kernel needs a CPU leaf or else its idle loop will burn cpu cycles; the
2260 * intelppm driver refuses to register an idle state handler.
2261 */
2262 if ((cCpus > 1) || fIOAPIC)
2263 fShowCpu = true;
2264
2265 hrc = pMachine->COMGETTER(CPUHotPlugEnabled)(&fCpuHotPlug); H();
2266
2267 InsertConfigNode(pDevices, "acpi", &pDev);
2268 InsertConfigNode(pDev, "0", &pInst);
2269 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2270 InsertConfigNode(pInst, "Config", &pCfg);
2271 InsertConfigInteger(pCfg, "RamSize", cbRam);
2272 InsertConfigInteger(pCfg, "RamHoleSize", cbRamHole);
2273 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
2274
2275 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
2276 InsertConfigInteger(pCfg, "FdcEnabled", fFdcEnabled);
2277 InsertConfigInteger(pCfg, "HpetEnabled", fHpetEnabled);
2278 InsertConfigInteger(pCfg, "SmcEnabled", fSmcEnabled);
2279 InsertConfigInteger(pCfg, "ShowRtc", fOsXGuest);
2280 if (fOsXGuest && !llBootNics.empty())
2281 {
2282 BootNic aNic = llBootNics.front();
2283 uint32_t u32NicPciAddr = (aNic.mPciDev << 16) | aNic.mPciFn;
2284 InsertConfigInteger(pCfg, "NicPciAddress", u32NicPciAddr);
2285 }
2286 if (fOsXGuest && fAudioEnabled)
2287 {
2288 /** @todo: don't hardcode */
2289 uint32_t u32AudioPciAddr = (5 << 16) | 0;
2290 InsertConfigInteger(pCfg, "AudioPciAddress", u32AudioPciAddr);
2291 }
2292 InsertConfigInteger(pCfg, "IocPciAddress", u32IocPciAddress);
2293 if (chipsetType == ChipsetType_ICH9)
2294 {
2295 InsertConfigInteger(pCfg, "McfgBase", u64McfgBase);
2296 InsertConfigInteger(pCfg, "McfgLength", u64McfgLength);
2297 }
2298 InsertConfigInteger(pCfg, "HostBusPciAddress", u32HbcPciAddress);
2299 InsertConfigInteger(pCfg, "ShowCpu", fShowCpu);
2300 InsertConfigInteger(pCfg, "CpuHotPlug", fCpuHotPlug);
2301 InsertConfigInteger(pInst, "PCIDeviceNo", 7);
2302 Assert(!afPciDeviceNo[7]);
2303 afPciDeviceNo[7] = true;
2304 InsertConfigInteger(pInst, "PCIFunctionNo", 0);
2305
2306 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2307 InsertConfigString(pLunL0, "Driver", "ACPIHost");
2308 InsertConfigNode(pLunL0, "Config", &pCfg);
2309
2310 /* Attach the dummy CPU drivers */
2311 for (ULONG iCpuCurr = 1; iCpuCurr < cCpus; iCpuCurr++)
2312 {
2313 BOOL fCpuAttached = true;
2314
2315 if (fCpuHotPlug)
2316 {
2317 hrc = pMachine->GetCPUStatus(iCpuCurr, &fCpuAttached); H();
2318 }
2319
2320 if (fCpuAttached)
2321 {
2322 InsertConfigNode(pInst, Utf8StrFmt("LUN#%u", iCpuCurr).c_str(), &pLunL0);
2323 InsertConfigString(pLunL0, "Driver", "ACPICpu");
2324 InsertConfigNode(pLunL0, "Config", &pCfg);
2325 }
2326 }
2327 }
2328
2329 /*
2330 * CFGM overlay handling.
2331 *
2332 * Here we check the extra data entries for CFGM values
2333 * and create the nodes and insert the values on the fly. Existing
2334 * values will be removed and reinserted. CFGM is typed, so by default
2335 * we will guess whether it's a string or an integer (byte arrays are
2336 * not currently supported). It's possible to override this autodetection
2337 * by adding "string:", "integer:" or "bytes:" (future).
2338 *
2339 * We first perform a run on global extra data, then on the machine
2340 * extra data to support global settings with local overrides.
2341 */
2342 /** @todo add support for removing nodes and byte blobs. */
2343 SafeArray<BSTR> aGlobalExtraDataKeys;
2344 SafeArray<BSTR> aMachineExtraDataKeys;
2345 /*
2346 * Get the next key
2347 */
2348 if (FAILED(hrc = virtualBox->GetExtraDataKeys(ComSafeArrayAsOutParam(aGlobalExtraDataKeys))))
2349 AssertMsgFailed(("VirtualBox::GetExtraDataKeys failed with %Rrc\n", hrc));
2350
2351 // remember the no. of global values so we can call the correct method below
2352 size_t cGlobalValues = aGlobalExtraDataKeys.size();
2353
2354 if (FAILED(hrc = pMachine->GetExtraDataKeys(ComSafeArrayAsOutParam(aMachineExtraDataKeys))))
2355 AssertMsgFailed(("IMachine::GetExtraDataKeys failed with %Rrc\n", hrc));
2356
2357 // build a combined list from global keys...
2358 std::list<Utf8Str> llExtraDataKeys;
2359
2360 for (size_t i = 0; i < aGlobalExtraDataKeys.size(); ++i)
2361 llExtraDataKeys.push_back(Utf8Str(aGlobalExtraDataKeys[i]));
2362 // ... and machine keys
2363 for (size_t i = 0; i < aMachineExtraDataKeys.size(); ++i)
2364 llExtraDataKeys.push_back(Utf8Str(aMachineExtraDataKeys[i]));
2365
2366 size_t i2 = 0;
2367 for (std::list<Utf8Str>::const_iterator it = llExtraDataKeys.begin();
2368 it != llExtraDataKeys.end();
2369 ++it, ++i2)
2370 {
2371 const Utf8Str &strKey = *it;
2372
2373 /*
2374 * We only care about keys starting with "VBoxInternal/" (skip "G:" or "M:")
2375 */
2376 if (!strKey.startsWith("VBoxInternal/"))
2377 continue;
2378
2379 const char *pszExtraDataKey = strKey.c_str() + sizeof("VBoxInternal/") - 1;
2380
2381 // get the value
2382 Bstr bstrExtraDataValue;
2383 if (i2 < cGlobalValues)
2384 // this is still one of the global values:
2385 hrc = virtualBox->GetExtraData(Bstr(strKey), bstrExtraDataValue.asOutParam());
2386 else
2387 hrc = pMachine->GetExtraData(Bstr(strKey), bstrExtraDataValue.asOutParam());
2388 if (FAILED(hrc))
2389 LogRel(("Warning: Cannot get extra data key %s, rc = %Rrc\n", strKey.c_str(), hrc));
2390
2391 /*
2392 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2393 * Split the two and get the node, delete the value and create the node
2394 * if necessary.
2395 */
2396 PCFGMNODE pNode;
2397 const char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2398 if (pszCFGMValueName)
2399 {
2400 /* terminate the node and advance to the value (Utf8Str might not
2401 offically like this but wtf) */
2402 *(char*)pszCFGMValueName = '\0';
2403 ++pszCFGMValueName;
2404
2405 /* does the node already exist? */
2406 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2407 if (pNode)
2408 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2409 else
2410 {
2411 /* create the node */
2412 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2413 if (RT_FAILURE(rc))
2414 {
2415 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2416 continue;
2417 }
2418 Assert(pNode);
2419 }
2420 }
2421 else
2422 {
2423 /* root value (no node path). */
2424 pNode = pRoot;
2425 pszCFGMValueName = pszExtraDataKey;
2426 pszExtraDataKey--;
2427 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2428 }
2429
2430 /*
2431 * Now let's have a look at the value.
2432 * Empty strings means that we should remove the value, which we've
2433 * already done above.
2434 */
2435 Utf8Str strCFGMValueUtf8(bstrExtraDataValue);
2436 if (!strCFGMValueUtf8.isEmpty())
2437 {
2438 uint64_t u64Value;
2439
2440 /* check for type prefix first. */
2441 if (!strncmp(strCFGMValueUtf8.c_str(), "string:", sizeof("string:") - 1))
2442 InsertConfigString(pNode, pszCFGMValueName, strCFGMValueUtf8.c_str() + sizeof("string:") - 1);
2443 else if (!strncmp(strCFGMValueUtf8.c_str(), "integer:", sizeof("integer:") - 1))
2444 {
2445 rc = RTStrToUInt64Full(strCFGMValueUtf8.c_str() + sizeof("integer:") - 1, 0, &u64Value);
2446 if (RT_SUCCESS(rc))
2447 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2448 }
2449 else if (!strncmp(strCFGMValueUtf8.c_str(), "bytes:", sizeof("bytes:") - 1))
2450 rc = VERR_NOT_IMPLEMENTED;
2451 /* auto detect type. */
2452 else if (RT_SUCCESS(RTStrToUInt64Full(strCFGMValueUtf8.c_str(), 0, &u64Value)))
2453 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2454 else
2455 InsertConfigString(pNode, pszCFGMValueName, strCFGMValueUtf8);
2456 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", strCFGMValueUtf8.c_str(), pszExtraDataKey));
2457 }
2458 }
2459 }
2460 catch (ConfigError &x)
2461 {
2462 // InsertConfig threw something:
2463 return x.m_vrc;
2464 }
2465
2466#undef H
2467
2468 /* Register VM state change handler */
2469 int rc2 = VMR3AtStateRegister(pVM, Console::vmstateChangeCallback, pConsole);
2470 AssertRC(rc2);
2471 if (RT_SUCCESS(rc))
2472 rc = rc2;
2473
2474 /* Register VM runtime error handler */
2475 rc2 = VMR3AtRuntimeErrorRegister(pVM, Console::setVMRuntimeErrorCallback, pConsole);
2476 AssertRC(rc2);
2477 if (RT_SUCCESS(rc))
2478 rc = rc2;
2479
2480 LogFlowFunc(("vrc = %Rrc\n", rc));
2481 LogFlowFuncLeave();
2482
2483 return rc;
2484}
2485
2486/**
2487 * Ellipsis to va_list wrapper for calling setVMRuntimeErrorCallback.
2488 */
2489/*static*/
2490void Console::setVMRuntimeErrorCallbackF(PVM pVM, void *pvConsole, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
2491{
2492 va_list va;
2493 va_start(va, pszFormat);
2494 setVMRuntimeErrorCallback(pVM, pvConsole, fFlags, pszErrorId, pszFormat, va);
2495 va_end(va);
2496}
2497
2498/* XXX introduce RT format specifier */
2499static uint64_t formatDiskSize(uint64_t u64Size, const char **pszUnit)
2500{
2501 if (u64Size > INT64_C(5000)*_1G)
2502 {
2503 *pszUnit = "TB";
2504 return u64Size / _1T;
2505 }
2506 else if (u64Size > INT64_C(5000)*_1M)
2507 {
2508 *pszUnit = "GB";
2509 return u64Size / _1G;
2510 }
2511 else
2512 {
2513 *pszUnit = "MB";
2514 return u64Size / _1M;
2515 }
2516}
2517
2518int Console::configMediumAttachment(PCFGMNODE pCtlInst,
2519 const char *pcszDevice,
2520 unsigned uInstance,
2521 StorageBus_T enmBus,
2522 bool fUseHostIOCache,
2523 bool fSetupMerge,
2524 unsigned uMergeSource,
2525 unsigned uMergeTarget,
2526 IMediumAttachment *pMediumAtt,
2527 MachineState_T aMachineState,
2528 HRESULT *phrc,
2529 bool fAttachDetach,
2530 bool fForceUnmount,
2531 PVM pVM,
2532 DeviceType_T *paLedDevType)
2533{
2534 // InsertConfig* throws
2535 try
2536 {
2537 int rc = VINF_SUCCESS;
2538 HRESULT hrc;
2539 Bstr bstr;
2540
2541// #define RC_CHECK() AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc)
2542#define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
2543
2544 LONG lDev;
2545 hrc = pMediumAtt->COMGETTER(Device)(&lDev); H();
2546 LONG lPort;
2547 hrc = pMediumAtt->COMGETTER(Port)(&lPort); H();
2548 DeviceType_T lType;
2549 hrc = pMediumAtt->COMGETTER(Type)(&lType); H();
2550
2551 unsigned uLUN;
2552 PCFGMNODE pLunL0 = NULL;
2553 PCFGMNODE pCfg = NULL;
2554 hrc = Console::convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN); H();
2555
2556 /* First check if the LUN already exists. */
2557 pLunL0 = CFGMR3GetChildF(pCtlInst, "LUN#%u", uLUN);
2558 if (pLunL0)
2559 {
2560 if (fAttachDetach)
2561 {
2562 if (lType != DeviceType_HardDisk)
2563 {
2564 /* Unmount existing media only for floppy and DVD drives. */
2565 PPDMIBASE pBase;
2566 rc = PDMR3QueryLun(pVM, pcszDevice, uInstance, uLUN, &pBase);
2567 if (RT_FAILURE(rc))
2568 {
2569 if (rc == VERR_PDM_LUN_NOT_FOUND || rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
2570 rc = VINF_SUCCESS;
2571 AssertRC(rc);
2572 }
2573 else
2574 {
2575 PPDMIMOUNT pIMount = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMOUNT);
2576 AssertReturn(pIMount, VERR_INVALID_POINTER);
2577
2578 /* Unmount the media. */
2579 rc = pIMount->pfnUnmount(pIMount, fForceUnmount);
2580 if (rc == VERR_PDM_MEDIA_NOT_MOUNTED)
2581 rc = VINF_SUCCESS;
2582 }
2583 }
2584
2585 rc = PDMR3DeviceDetach(pVM, pcszDevice, 0, uLUN, PDM_TACH_FLAGS_NOT_HOT_PLUG);
2586 if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
2587 rc = VINF_SUCCESS;
2588 AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
2589
2590 CFGMR3RemoveNode(pLunL0);
2591 }
2592 else
2593 AssertFailedReturn(VERR_INTERNAL_ERROR);
2594 }
2595
2596 InsertConfigNode(pCtlInst, Utf8StrFmt("LUN#%u", uLUN).c_str(), &pLunL0);
2597
2598 /* SCSI has a another driver between device and block. */
2599 if (enmBus == StorageBus_SCSI || enmBus == StorageBus_SAS)
2600 {
2601 InsertConfigString(pLunL0, "Driver", "SCSI");
2602 InsertConfigNode(pLunL0, "Config", &pCfg);
2603
2604 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
2605 }
2606
2607 ComPtr<IMedium> pMedium;
2608 hrc = pMediumAtt->COMGETTER(Medium)(pMedium.asOutParam()); H();
2609
2610 /*
2611 * 1. Only check this for hard disk images.
2612 * 2. Only check during VM creation and not later, especially not during
2613 * taking an online snapshot!
2614 */
2615 if ( lType == DeviceType_HardDisk
2616 && aMachineState == MachineState_Starting)
2617 {
2618 /*
2619 * Some sanity checks.
2620 */
2621 ComPtr<IMediumFormat> pMediumFormat;
2622 hrc = pMedium->COMGETTER(MediumFormat)(pMediumFormat.asOutParam()); H();
2623 ULONG uCaps;
2624 hrc = pMediumFormat->COMGETTER(Capabilities)(&uCaps); H();
2625 if (uCaps & MediumFormatCapabilities_File)
2626 {
2627 Bstr strFile;
2628 hrc = pMedium->COMGETTER(Location)(strFile.asOutParam()); H();
2629 Utf8Str utfFile = Utf8Str(strFile);
2630 Bstr strSnap;
2631 ComPtr<IMachine> pMachine = machine();
2632 hrc = pMachine->COMGETTER(SnapshotFolder)(strSnap.asOutParam()); H();
2633 Utf8Str utfSnap = Utf8Str(strSnap);
2634 RTFSTYPE enmFsTypeFile = RTFSTYPE_UNKNOWN;
2635 RTFSTYPE enmFsTypeSnap = RTFSTYPE_UNKNOWN;
2636 int rc2 = RTFsQueryType(utfFile.c_str(), &enmFsTypeFile);
2637 AssertMsgRCReturn(rc2, ("Querying the file type of '%s' failed!\n", utfFile.c_str()), rc2);
2638 /* Ignore the error code. On error, the file system type is still 'unknown' so
2639 * none of the following pathes is taken. This can happen for new VMs which
2640 * still don't have a snapshot folder. */
2641 (void)RTFsQueryType(utfSnap.c_str(), &enmFsTypeSnap);
2642 LogRel(("File system of '%s' is %s\n", utfFile.c_str(), RTFsTypeName(enmFsTypeFile)));
2643 LONG64 i64Size;
2644 hrc = pMedium->COMGETTER(LogicalSize)(&i64Size); H();
2645#ifdef RT_OS_WINDOWS
2646 if ( enmFsTypeFile == RTFSTYPE_FAT
2647 && i64Size >= _4G)
2648 {
2649 const char *pszUnit;
2650 uint64_t u64Print = formatDiskSize((uint64_t)i64Size, &pszUnit);
2651 setVMRuntimeErrorCallbackF(pVM, this, 0,
2652 "FatPartitionDetected",
2653 N_("The medium '%ls' has a logical size of %RU64%s "
2654 "but the file system the medium is located on seems "
2655 "to be FAT(32) which cannot handle files bigger than 4GB.\n"
2656 "We strongly recommend to put all your virtual disk images and "
2657 "the snapshot folder onto an NTFS partition"),
2658 strFile.raw(), u64Print, pszUnit);
2659 }
2660#else /* !RT_OS_WINDOWS */
2661 if ( enmFsTypeFile == RTFSTYPE_FAT
2662 || enmFsTypeFile == RTFSTYPE_EXT
2663 || enmFsTypeFile == RTFSTYPE_EXT2
2664 || enmFsTypeFile == RTFSTYPE_EXT3
2665 || enmFsTypeFile == RTFSTYPE_EXT4)
2666 {
2667 RTFILE file;
2668 rc = RTFileOpen(&file, utfFile.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
2669 if (RT_SUCCESS(rc))
2670 {
2671 RTFOFF maxSize;
2672 /* Careful: This function will work only on selected local file systems! */
2673 rc = RTFileGetMaxSizeEx(file, &maxSize);
2674 RTFileClose(file);
2675 if ( RT_SUCCESS(rc)
2676 && maxSize > 0
2677 && i64Size > (LONG64)maxSize)
2678 {
2679 const char *pszUnitSiz;
2680 const char *pszUnitMax;
2681 uint64_t u64PrintSiz = formatDiskSize((LONG64)i64Size, &pszUnitSiz);
2682 uint64_t u64PrintMax = formatDiskSize(maxSize, &pszUnitMax);
2683 setVMRuntimeErrorCallbackF(pVM, this, 0,
2684 "FatPartitionDetected", /* <= not exact but ... */
2685 N_("The medium '%ls' has a logical size of %RU64%s "
2686 "but the file system the medium is located on can "
2687 "only handle files up to %RU64%s in theory.\n"
2688 "We strongly recommend to put all your virtual disk "
2689 "images and the snapshot folder onto a proper "
2690 "file system (e.g. ext3) with a sufficient size"),
2691 strFile.raw(), u64PrintSiz, pszUnitSiz, u64PrintMax, pszUnitMax);
2692 }
2693 }
2694 }
2695#endif /* !RT_OS_WINDOWS */
2696
2697 /*
2698 * Snapshot folder:
2699 * Here we test only for a FAT partition as we had to create a dummy file otherwise
2700 */
2701 if ( enmFsTypeSnap == RTFSTYPE_FAT
2702 && i64Size >= _4G
2703 && !mfSnapshotFolderSizeWarningShown)
2704 {
2705 const char *pszUnit;
2706 uint64_t u64Print = formatDiskSize(i64Size, &pszUnit);
2707 setVMRuntimeErrorCallbackF(pVM, this, 0,
2708 "FatPartitionDetected",
2709#ifdef RT_OS_WINDOWS
2710 N_("The snapshot folder of this VM '%ls' seems to be located on "
2711 "a FAT(32) file system. The logical size of the medium '%ls' "
2712 "(%RU64%s) is bigger than the maximum file size this file "
2713 "system can handle (4GB).\n"
2714 "We strongly recommend to put all your virtual disk images and "
2715 "the snapshot folder onto an NTFS partition"),
2716#else
2717 N_("The snapshot folder of this VM '%ls' seems to be located on "
2718 "a FAT(32) file system. The logical size of the medium '%ls' "
2719 "(%RU64%s) is bigger than the maximum file size this file "
2720 "system can handle (4GB).\n"
2721 "We strongly recommend to put all your virtual disk images and "
2722 "the snapshot folder onto a proper file system (e.g. ext3)"),
2723#endif
2724 strSnap.raw(), strFile.raw(), u64Print, pszUnit);
2725 /* Show this particular warning only once */
2726 mfSnapshotFolderSizeWarningShown = true;
2727 }
2728
2729#ifdef RT_OS_LINUX
2730 /*
2731 * Ext4 bug: Check if the host I/O cache is disabled and the disk image is located
2732 * on an ext4 partition. Later we have to check the Linux kernel version!
2733 * This bug apparently applies to the XFS file system as well.
2734 * Linux 2.6.36 is known to be fixed (tested with 2.6.36-rc4).
2735 */
2736
2737 char szOsRelease[128];
2738 rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szOsRelease, sizeof(szOsRelease));
2739 bool fKernelHasODirectBug = RT_FAILURE(rc)
2740 || (RTStrVersionCompare(szOsRelease, "2.6.36-rc4") < 0);
2741
2742 if ( (uCaps & MediumFormatCapabilities_Asynchronous)
2743 && !fUseHostIOCache
2744 && fKernelHasODirectBug)
2745 {
2746 if ( enmFsTypeFile == RTFSTYPE_EXT4
2747 || enmFsTypeFile == RTFSTYPE_XFS)
2748 {
2749 setVMRuntimeErrorCallbackF(pVM, this, 0,
2750 "Ext4PartitionDetected",
2751 N_("The host I/O cache for at least one controller is disabled "
2752 "and the medium '%ls' for this VM "
2753 "is located on an %s partition. There is a known Linux "
2754 "kernel bug which can lead to the corruption of the virtual "
2755 "disk image under these conditions.\n"
2756 "Either enable the host I/O cache permanently in the VM "
2757 "settings or put the disk image and the snapshot folder "
2758 "onto a different file system.\n"
2759 "The host I/O cache will now be enabled for this medium"),
2760 strFile.raw(), enmFsTypeFile == RTFSTYPE_EXT4 ? "ext4" : "xfs");
2761 fUseHostIOCache = true;
2762 }
2763 else if ( ( enmFsTypeSnap == RTFSTYPE_EXT4
2764 || enmFsTypeSnap == RTFSTYPE_XFS)
2765 && !mfSnapshotFolderExt4WarningShown)
2766 {
2767 setVMRuntimeErrorCallbackF(pVM, this, 0,
2768 "Ext4PartitionDetected",
2769 N_("The host I/O cache for at least one controller is disabled "
2770 "and the snapshot folder for this VM "
2771 "is located on an %s partition. There is a known Linux "
2772 "kernel bug which can lead to the corruption of the virtual "
2773 "disk image under these conditions.\n"
2774 "Either enable the host I/O cache permanently in the VM "
2775 "settings or put the disk image and the snapshot folder "
2776 "onto a different file system.\n"
2777 "The host I/O cache will now be enabled for this medium"),
2778 enmFsTypeSnap == RTFSTYPE_EXT4 ? "ext4" : "xfs");
2779 fUseHostIOCache = true;
2780 mfSnapshotFolderExt4WarningShown = true;
2781 }
2782 }
2783#endif
2784 }
2785 }
2786
2787 BOOL fPassthrough;
2788 hrc = pMediumAtt->COMGETTER(Passthrough)(&fPassthrough); H();
2789 rc = configMedium(pLunL0,
2790 !!fPassthrough,
2791 lType,
2792 fUseHostIOCache,
2793 fSetupMerge,
2794 uMergeSource,
2795 uMergeTarget,
2796 pMedium,
2797 aMachineState,
2798 phrc);
2799 if (RT_FAILURE(rc))
2800 return rc;
2801
2802 if (fAttachDetach)
2803 {
2804 /* Attach the new driver. */
2805 rc = PDMR3DeviceAttach(pVM, pcszDevice, 0, uLUN,
2806 PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/);
2807 AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
2808
2809 /* There is no need to handle removable medium mounting, as we
2810 * unconditionally replace everthing including the block driver level.
2811 * This means the new medium will be picked up automatically. */
2812 }
2813
2814 if (paLedDevType)
2815 paLedDevType[uLUN] = lType;
2816 }
2817 catch (ConfigError &x)
2818 {
2819 // InsertConfig threw something:
2820 return x.m_vrc;
2821 }
2822
2823#undef H
2824
2825 return VINF_SUCCESS;;
2826}
2827
2828int Console::configMedium(PCFGMNODE pLunL0,
2829 bool fPassthrough,
2830 DeviceType_T enmType,
2831 bool fUseHostIOCache,
2832 bool fSetupMerge,
2833 unsigned uMergeSource,
2834 unsigned uMergeTarget,
2835 IMedium *pMedium,
2836 MachineState_T aMachineState,
2837 HRESULT *phrc)
2838{
2839 // InsertConfig* throws
2840 try
2841 {
2842 int rc = VINF_SUCCESS;
2843 HRESULT hrc;
2844 Bstr bstr;
2845
2846#define H() AssertMsgReturnStmt(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), if (phrc) *phrc = hrc, VERR_GENERAL_FAILURE)
2847
2848 PCFGMNODE pLunL1 = NULL;
2849 PCFGMNODE pCfg = NULL;
2850
2851 BOOL fHostDrive = FALSE;
2852 MediumType_T mediumType = MediumType_Normal;
2853 if (pMedium)
2854 {
2855 hrc = pMedium->COMGETTER(HostDrive)(&fHostDrive); H();
2856 hrc = pMedium->COMGETTER(Type)(&mediumType); H();
2857 }
2858
2859 if (fHostDrive)
2860 {
2861 Assert(pMedium);
2862 if (enmType == DeviceType_DVD)
2863 {
2864 InsertConfigString(pLunL0, "Driver", "HostDVD");
2865 InsertConfigNode(pLunL0, "Config", &pCfg);
2866
2867 hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
2868 InsertConfigString(pCfg, "Path", bstr);
2869
2870 InsertConfigInteger(pCfg, "Passthrough", fPassthrough);
2871 }
2872 else if (enmType == DeviceType_Floppy)
2873 {
2874 InsertConfigString(pLunL0, "Driver", "HostFloppy");
2875 InsertConfigNode(pLunL0, "Config", &pCfg);
2876
2877 hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
2878 InsertConfigString(pCfg, "Path", bstr);
2879 }
2880 }
2881 else
2882 {
2883 InsertConfigString(pLunL0, "Driver", "Block");
2884 InsertConfigNode(pLunL0, "Config", &pCfg);
2885 switch (enmType)
2886 {
2887 case DeviceType_DVD:
2888 InsertConfigString(pCfg, "Type", "DVD");
2889 InsertConfigInteger(pCfg, "Mountable", 1);
2890 break;
2891 case DeviceType_Floppy:
2892 InsertConfigString(pCfg, "Type", "Floppy 1.44");
2893 InsertConfigInteger(pCfg, "Mountable", 1);
2894 break;
2895 case DeviceType_HardDisk:
2896 default:
2897 InsertConfigString(pCfg, "Type", "HardDisk");
2898 InsertConfigInteger(pCfg, "Mountable", 0);
2899 }
2900
2901 if ( pMedium
2902 && ( enmType == DeviceType_DVD
2903 || enmType == DeviceType_Floppy
2904 ))
2905 {
2906 // if this medium represents an ISO image and this image is inaccessible,
2907 // the ignore it instead of causing a failure; this can happen when we
2908 // restore a VM state and the ISO has disappeared, e.g. because the Guest
2909 // Additions were mounted and the user upgraded VirtualBox. Previously
2910 // we failed on startup, but that's not good because the only way out then
2911 // would be to discard the VM state...
2912 MediumState_T mediumState;
2913 rc = pMedium->RefreshState(&mediumState);
2914 AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc);
2915
2916 if (mediumState == MediumState_Inaccessible)
2917 {
2918 Bstr loc;
2919 rc = pMedium->COMGETTER(Location)(loc.asOutParam());
2920 if (FAILED(rc)) return rc;
2921
2922 setVMRuntimeErrorCallbackF(mpVM,
2923 this,
2924 0,
2925 "DvdOrFloppyImageInaccessible",
2926 "The image file '%ls' is inaccessible and is being ignored. Please select a different image file for the virtual %s drive.",
2927 loc.raw(),
2928 (enmType == DeviceType_DVD) ? "DVD" : "floppy");
2929 pMedium = NULL;
2930 }
2931 }
2932
2933 if (pMedium)
2934 {
2935 /* Start with length of parent chain, as the list is reversed */
2936 unsigned uImage = 0;
2937 IMedium *pTmp = pMedium;
2938 while (pTmp)
2939 {
2940 uImage++;
2941 hrc = pTmp->COMGETTER(Parent)(&pTmp); H();
2942 }
2943 /* Index of last image */
2944 uImage--;
2945
2946#if 0 /* Enable for I/O debugging */
2947 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
2948 InsertConfigString(pLunL0, "Driver", "DiskIntegrity");
2949 InsertConfigNode(pLunL0, "Config", &pCfg);
2950 InsertConfigInteger(pCfg, "CheckConsistency", 0);
2951 InsertConfigInteger(pCfg, "CheckDoubleCompletions", 1);
2952#endif
2953
2954 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
2955 InsertConfigString(pLunL1, "Driver", "VD");
2956 InsertConfigNode(pLunL1, "Config", &pCfg);
2957
2958 hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
2959 InsertConfigString(pCfg, "Path", bstr);
2960
2961 hrc = pMedium->COMGETTER(Format)(bstr.asOutParam()); H();
2962 InsertConfigString(pCfg, "Format", bstr);
2963
2964 /* DVDs are always readonly, floppies may be readonly */
2965 if (enmType == DeviceType_DVD)
2966 {
2967 InsertConfigInteger(pCfg, "ReadOnly", 1);
2968 }
2969 else if (enmType == DeviceType_Floppy)
2970 {
2971 InsertConfigInteger(pCfg, "MaybeReadOnly", 1);
2972 }
2973
2974 /* Start without exclusive write access to the images. */
2975 /** @todo Live Migration: I don't quite like this, we risk screwing up when
2976 * we're resuming the VM if some 3rd dude have any of the VDIs open
2977 * with write sharing denied. However, if the two VMs are sharing a
2978 * image it really is necessary....
2979 *
2980 * So, on the "lock-media" command, the target teleporter should also
2981 * make DrvVD undo TempReadOnly. It gets interesting if we fail after
2982 * that. Grumble. */
2983 else if ( aMachineState == MachineState_TeleportingIn
2984 || aMachineState == MachineState_FaultTolerantSyncing)
2985 {
2986 InsertConfigInteger(pCfg, "TempReadOnly", 1);
2987 }
2988
2989 /* Flag for opening the medium for sharing between VMs. This
2990 * is done at the moment only for the first (and only) medium
2991 * in the chain, as shared media can have no diffs. */
2992 if (mediumType == MediumType_Shareable)
2993 {
2994 InsertConfigInteger(pCfg, "Shareable", 1);
2995 }
2996
2997 if (!fUseHostIOCache)
2998 {
2999 InsertConfigInteger(pCfg, "UseNewIo", 1);
3000 }
3001
3002 if (fSetupMerge)
3003 {
3004 InsertConfigInteger(pCfg, "SetupMerge", 1);
3005 if (uImage == uMergeSource)
3006 {
3007 InsertConfigInteger(pCfg, "MergeSource", 1);
3008 }
3009 else if (uImage == uMergeTarget)
3010 {
3011 InsertConfigInteger(pCfg, "MergeTarget", 1);
3012 }
3013 }
3014
3015 /* Pass all custom parameters. */
3016 bool fHostIP = true;
3017 SafeArray<BSTR> names;
3018 SafeArray<BSTR> values;
3019 hrc = pMedium->GetProperties(NULL,
3020 ComSafeArrayAsOutParam(names),
3021 ComSafeArrayAsOutParam(values)); H();
3022
3023 if (names.size() != 0)
3024 {
3025 PCFGMNODE pVDC;
3026 InsertConfigNode(pCfg, "VDConfig", &pVDC);
3027 for (size_t ii = 0; ii < names.size(); ++ii)
3028 {
3029 if (values[ii] && *values[ii])
3030 {
3031 Utf8Str name = names[ii];
3032 Utf8Str value = values[ii];
3033 InsertConfigString(pVDC, name.c_str(), value);
3034 if ( name.compare("HostIPStack") == 0
3035 && value.compare("0") == 0)
3036 fHostIP = false;
3037 }
3038 }
3039 }
3040
3041 /* Create an inversed list of parents. */
3042 uImage--;
3043 IMedium *pParentMedium = pMedium;
3044 for (PCFGMNODE pParent = pCfg;; uImage--)
3045 {
3046 hrc = pParentMedium->COMGETTER(Parent)(&pMedium); H();
3047 if (!pMedium)
3048 break;
3049
3050 PCFGMNODE pCur;
3051 InsertConfigNode(pParent, "Parent", &pCur);
3052 hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
3053 InsertConfigString(pCur, "Path", bstr);
3054
3055 hrc = pMedium->COMGETTER(Format)(bstr.asOutParam()); H();
3056 InsertConfigString(pCur, "Format", bstr);
3057
3058 if (fSetupMerge)
3059 {
3060 if (uImage == uMergeSource)
3061 {
3062 InsertConfigInteger(pCur, "MergeSource", 1);
3063 }
3064 else if (uImage == uMergeTarget)
3065 {
3066 InsertConfigInteger(pCur, "MergeTarget", 1);
3067 }
3068 }
3069
3070 /* Pass all custom parameters. */
3071 SafeArray<BSTR> aNames;
3072 SafeArray<BSTR> aValues;
3073 hrc = pMedium->GetProperties(NULL,
3074 ComSafeArrayAsOutParam(aNames),
3075 ComSafeArrayAsOutParam(aValues)); H();
3076
3077 if (aNames.size() != 0)
3078 {
3079 PCFGMNODE pVDC;
3080 InsertConfigNode(pCur, "VDConfig", &pVDC);
3081 for (size_t ii = 0; ii < aNames.size(); ++ii)
3082 {
3083 if (aValues[ii] && *aValues[ii])
3084 {
3085 Utf8Str name = aNames[ii];
3086 Utf8Str value = aValues[ii];
3087 InsertConfigString(pVDC, name.c_str(), value);
3088 if ( name.compare("HostIPStack") == 0
3089 && value.compare("0") == 0)
3090 fHostIP = false;
3091 }
3092 }
3093 }
3094
3095 /* Custom code: put marker to not use host IP stack to driver
3096 * configuration node. Simplifies life of DrvVD a bit. */
3097 if (!fHostIP)
3098 {
3099 InsertConfigInteger(pCfg, "HostIPStack", 0);
3100 }
3101
3102 /* next */
3103 pParent = pCur;
3104 pParentMedium = pMedium;
3105 }
3106 }
3107 }
3108 }
3109 catch (ConfigError &x)
3110 {
3111 // InsertConfig threw something:
3112 return x.m_vrc;
3113 }
3114
3115#undef H
3116
3117 return VINF_SUCCESS;
3118}
3119
3120/**
3121 * Construct the Network configuration tree
3122 *
3123 * @returns VBox status code.
3124 *
3125 * @param pszDevice The PDM device name.
3126 * @param uInstance The PDM device instance.
3127 * @param uLun The PDM LUN number of the drive.
3128 * @param aNetworkAdapter The network adapter whose attachment needs to be changed
3129 * @param pCfg Configuration node for the device
3130 * @param pLunL0 To store the pointer to the LUN#0.
3131 * @param pInst The instance CFGM node
3132 * @param fAttachDetach To determine if the network attachment should
3133 * be attached/detached after/before
3134 * configuration.
3135 *
3136 * @note Locks this object for writing.
3137 */
3138int Console::configNetwork(const char *pszDevice,
3139 unsigned uInstance,
3140 unsigned uLun,
3141 INetworkAdapter *aNetworkAdapter,
3142 PCFGMNODE pCfg,
3143 PCFGMNODE pLunL0,
3144 PCFGMNODE pInst,
3145 bool fAttachDetach)
3146{
3147 AutoCaller autoCaller(this);
3148 AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
3149
3150 // InsertConfig* throws
3151 try
3152 {
3153 int rc = VINF_SUCCESS;
3154 HRESULT hrc;
3155 Bstr bstr;
3156
3157#define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
3158
3159 /*
3160 * Locking the object before doing VMR3* calls is quite safe here, since
3161 * we're on EMT. Write lock is necessary because we indirectly modify the
3162 * meAttachmentType member.
3163 */
3164 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
3165
3166 PVM pVM = mpVM;
3167
3168 ComPtr<IMachine> pMachine = machine();
3169
3170 ComPtr<IVirtualBox> virtualBox;
3171 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam());
3172 H();
3173
3174 ComPtr<IHost> host;
3175 hrc = virtualBox->COMGETTER(Host)(host.asOutParam());
3176 H();
3177
3178 BOOL fSniffer;
3179 hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer);
3180 H();
3181
3182 if (fAttachDetach && fSniffer)
3183 {
3184 const char *pszNetDriver = "IntNet";
3185 if (meAttachmentType[uInstance] == NetworkAttachmentType_NAT)
3186 pszNetDriver = "NAT";
3187#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
3188 if (meAttachmentType[uInstance] == NetworkAttachmentType_Bridged)
3189 pszNetDriver = "HostInterface";
3190#endif
3191
3192 rc = PDMR3DriverDetach(pVM, pszDevice, uInstance, uLun, pszNetDriver, 0, 0 /*fFlags*/);
3193 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
3194 rc = VINF_SUCCESS;
3195 AssertLogRelRCReturn(rc, rc);
3196
3197 pLunL0 = CFGMR3GetChildF(pInst, "LUN#%u", uLun);
3198 PCFGMNODE pLunAD = CFGMR3GetChildF(pLunL0, "AttachedDriver");
3199 if (pLunAD)
3200 {
3201 CFGMR3RemoveNode(pLunAD);
3202 }
3203 else
3204 {
3205 CFGMR3RemoveNode(pLunL0);
3206 InsertConfigNode(pInst, "LUN#0", &pLunL0);
3207 InsertConfigString(pLunL0, "Driver", "NetSniffer");
3208 InsertConfigNode(pLunL0, "Config", &pCfg);
3209 hrc = aNetworkAdapter->COMGETTER(TraceFile)(bstr.asOutParam()); H();
3210 if (!bstr.isEmpty()) /* check convention for indicating default file. */
3211 InsertConfigString(pCfg, "File", bstr);
3212 }
3213 }
3214 else if (fAttachDetach && !fSniffer)
3215 {
3216 rc = PDMR3DeviceDetach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/);
3217 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
3218 rc = VINF_SUCCESS;
3219 AssertLogRelRCReturn(rc, rc);
3220
3221 /* nuke anything which might have been left behind. */
3222 CFGMR3RemoveNode(CFGMR3GetChildF(pInst, "LUN#%u", uLun));
3223 }
3224 else if (!fAttachDetach && fSniffer)
3225 {
3226 /* insert the sniffer filter driver. */
3227 InsertConfigNode(pInst, "LUN#0", &pLunL0);
3228 InsertConfigString(pLunL0, "Driver", "NetSniffer");
3229 InsertConfigNode(pLunL0, "Config", &pCfg);
3230 hrc = aNetworkAdapter->COMGETTER(TraceFile)(bstr.asOutParam()); H();
3231 if (!bstr.isEmpty()) /* check convention for indicating default file. */
3232 InsertConfigString(pCfg, "File", bstr);
3233 }
3234
3235 Bstr networkName, trunkName, trunkType;
3236 NetworkAttachmentType_T eAttachmentType;
3237 hrc = aNetworkAdapter->COMGETTER(AttachmentType)(&eAttachmentType); H();
3238 switch (eAttachmentType)
3239 {
3240 case NetworkAttachmentType_Null:
3241 break;
3242
3243 case NetworkAttachmentType_NAT:
3244 {
3245 ComPtr<INATEngine> natDriver;
3246 hrc = aNetworkAdapter->COMGETTER(NatDriver)(natDriver.asOutParam()); H();
3247 if (fSniffer)
3248 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
3249 else
3250 InsertConfigNode(pInst, "LUN#0", &pLunL0);
3251 InsertConfigString(pLunL0, "Driver", "NAT");
3252 InsertConfigNode(pLunL0, "Config", &pCfg);
3253
3254 /* Configure TFTP prefix and boot filename. */
3255 hrc = virtualBox->COMGETTER(HomeFolder)(bstr.asOutParam()); H();
3256 if (!bstr.isEmpty())
3257 InsertConfigString(pCfg, "TFTPPrefix", Utf8StrFmt("%ls%c%s", bstr.raw(), RTPATH_DELIMITER, "TFTP"));
3258 hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
3259 InsertConfigString(pCfg, "BootFile", Utf8StrFmt("%ls.pxe", bstr.raw()));
3260
3261 hrc = natDriver->COMGETTER(Network)(bstr.asOutParam()); H();
3262 if (!bstr.isEmpty())
3263 InsertConfigString(pCfg, "Network", bstr);
3264 else
3265 {
3266 ULONG uSlot;
3267 hrc = aNetworkAdapter->COMGETTER(Slot)(&uSlot); H();
3268 InsertConfigString(pCfg, "Network", Utf8StrFmt("10.0.%d.0/24", uSlot+2));
3269 }
3270 hrc = natDriver->COMGETTER(HostIP)(bstr.asOutParam()); H();
3271 if (!bstr.isEmpty())
3272 InsertConfigString(pCfg, "BindIP", bstr);
3273 ULONG mtu = 0;
3274 ULONG sockSnd = 0;
3275 ULONG sockRcv = 0;
3276 ULONG tcpSnd = 0;
3277 ULONG tcpRcv = 0;
3278 hrc = natDriver->GetNetworkSettings(&mtu, &sockSnd, &sockRcv, &tcpSnd, &tcpRcv); H();
3279 if (mtu)
3280 InsertConfigInteger(pCfg, "SlirpMTU", mtu);
3281 if (sockRcv)
3282 InsertConfigInteger(pCfg, "SockRcv", sockRcv);
3283 if (sockSnd)
3284 InsertConfigInteger(pCfg, "SockSnd", sockSnd);
3285 if (tcpRcv)
3286 InsertConfigInteger(pCfg, "TcpRcv", tcpRcv);
3287 if (tcpSnd)
3288 InsertConfigInteger(pCfg, "TcpSnd", tcpSnd);
3289 hrc = natDriver->COMGETTER(TftpPrefix)(bstr.asOutParam()); H();
3290 if (!bstr.isEmpty())
3291 {
3292 RemoveConfigValue(pCfg, "TFTPPrefix");
3293 InsertConfigString(pCfg, "TFTPPrefix", bstr);
3294 }
3295 hrc = natDriver->COMGETTER(TftpBootFile)(bstr.asOutParam()); H();
3296 if (!bstr.isEmpty())
3297 {
3298 RemoveConfigValue(pCfg, "BootFile");
3299 InsertConfigString(pCfg, "BootFile", bstr);
3300 }
3301 hrc = natDriver->COMGETTER(TftpNextServer)(bstr.asOutParam()); H();
3302 if (!bstr.isEmpty())
3303 InsertConfigString(pCfg, "NextServer", bstr);
3304 BOOL fDnsFlag;
3305 hrc = natDriver->COMGETTER(DnsPassDomain)(&fDnsFlag); H();
3306 InsertConfigInteger(pCfg, "PassDomain", fDnsFlag);
3307 hrc = natDriver->COMGETTER(DnsProxy)(&fDnsFlag); H();
3308 InsertConfigInteger(pCfg, "DNSProxy", fDnsFlag);
3309 hrc = natDriver->COMGETTER(DnsUseHostResolver)(&fDnsFlag); H();
3310 InsertConfigInteger(pCfg, "UseHostResolver", fDnsFlag);
3311
3312 ULONG aliasMode;
3313 hrc = natDriver->COMGETTER(AliasMode)(&aliasMode); H();
3314 InsertConfigInteger(pCfg, "AliasMode", aliasMode);
3315
3316 /* port-forwarding */
3317 SafeArray<BSTR> pfs;
3318 hrc = natDriver->COMGETTER(Redirects)(ComSafeArrayAsOutParam(pfs)); H();
3319 PCFGMNODE pPF = NULL; /* /Devices/Dev/.../Config/PF#0/ */
3320 for (unsigned int i = 0; i < pfs.size(); ++i)
3321 {
3322 uint16_t port = 0;
3323 BSTR r = pfs[i];
3324 Utf8Str utf = Utf8Str(r);
3325 Utf8Str strName;
3326 Utf8Str strProto;
3327 Utf8Str strHostPort;
3328 Utf8Str strHostIP;
3329 Utf8Str strGuestPort;
3330 Utf8Str strGuestIP;
3331 size_t pos, ppos;
3332 pos = ppos = 0;
3333#define ITERATE_TO_NEXT_TERM(res, str, pos, ppos) \
3334 do { \
3335 pos = str.find(",", ppos); \
3336 if (pos == Utf8Str::npos) \
3337 { \
3338 Log(( #res " extracting from %s is failed\n", str.c_str())); \
3339 continue; \
3340 } \
3341 res = str.substr(ppos, pos - ppos); \
3342 Log2((#res " %s pos:%d, ppos:%d\n", res.c_str(), pos, ppos)); \
3343 ppos = pos + 1; \
3344 } while (0)
3345 ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos);
3346 ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos);
3347 ITERATE_TO_NEXT_TERM(strHostIP, utf, pos, ppos);
3348 ITERATE_TO_NEXT_TERM(strHostPort, utf, pos, ppos);
3349 ITERATE_TO_NEXT_TERM(strGuestIP, utf, pos, ppos);
3350 strGuestPort = utf.substr(ppos, utf.length() - ppos);
3351#undef ITERATE_TO_NEXT_TERM
3352
3353 uint32_t proto = strProto.toUInt32();
3354 bool fValid = true;
3355 switch (proto)
3356 {
3357 case NATProtocol_UDP:
3358 strProto = "UDP";
3359 break;
3360 case NATProtocol_TCP:
3361 strProto = "TCP";
3362 break;
3363 default:
3364 fValid = false;
3365 }
3366 /* continue with next rule if no valid proto was passed */
3367 if (!fValid)
3368 continue;
3369
3370 InsertConfigNode(pCfg, strName.c_str(), &pPF);
3371 InsertConfigString(pPF, "Protocol", strProto);
3372
3373 if (!strHostIP.isEmpty())
3374 InsertConfigString(pPF, "BindIP", strHostIP);
3375
3376 if (!strGuestIP.isEmpty())
3377 InsertConfigString(pPF, "GuestIP", strGuestIP);
3378
3379 port = RTStrToUInt16(strHostPort.c_str());
3380 if (port)
3381 InsertConfigInteger(pPF, "HostPort", port);
3382
3383 port = RTStrToUInt16(strGuestPort.c_str());
3384 if (port)
3385 InsertConfigInteger(pPF, "GuestPort", port);
3386 }
3387 break;
3388 }
3389
3390 case NetworkAttachmentType_Bridged:
3391 {
3392#if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT)
3393 hrc = attachToTapInterface(aNetworkAdapter);
3394 if (FAILED(hrc))
3395 {
3396 switch (hrc)
3397 {
3398 case VERR_ACCESS_DENIED:
3399 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
3400 "Failed to open '/dev/net/tun' for read/write access. Please check the "
3401 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
3402 "change the group of that node and make yourself a member of that group. Make "
3403 "sure that these changes are permanent, especially if you are "
3404 "using udev"));
3405 default:
3406 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
3407 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
3408 "Failed to initialize Host Interface Networking"));
3409 }
3410 }
3411
3412 Assert((int)maTapFD[uInstance] >= 0);
3413 if ((int)maTapFD[uInstance] >= 0)
3414 {
3415 if (fSniffer)
3416 {
3417 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
3418 }
3419 else
3420 {
3421 InsertConfigNode(pInst, "LUN#0", &pLunL0);
3422 }
3423 InsertConfigString(pLunL0, "Driver", "HostInterface");
3424 InsertConfigNode(pLunL0, "Config", &pCfg);
3425 InsertConfigInteger(pCfg, "FileHandle", maTapFD[uInstance]);
3426 }
3427
3428#elif defined(VBOX_WITH_NETFLT)
3429 /*
3430 * This is the new VBoxNetFlt+IntNet stuff.
3431 */
3432 if (fSniffer)
3433 {
3434 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
3435 }
3436 else
3437 {
3438 InsertConfigNode(pInst, "LUN#0", &pLunL0);
3439 }
3440
3441 Bstr HifName;
3442 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
3443 if (FAILED(hrc))
3444 {
3445 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
3446 H();
3447 }
3448
3449 Utf8Str HifNameUtf8(HifName);
3450 const char *pszHifName = HifNameUtf8.c_str();
3451
3452# if defined(RT_OS_DARWIN)
3453 /* The name is on the form 'ifX: long name', chop it off at the colon. */
3454 char szTrunk[8];
3455 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
3456 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
3457 if (!pszColon)
3458 {
3459 /*
3460 * Dynamic changing of attachment causes an attempt to configure
3461 * network with invalid host adapter (as it is must be changed before
3462 * the attachment), calling Detach here will cause a deadlock.
3463 * See #4750.
3464 * hrc = aNetworkAdapter->Detach(); H();
3465 */
3466 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
3467 N_("Malformed host interface networking name '%ls'"),
3468 HifName.raw());
3469 }
3470 *pszColon = '\0';
3471 const char *pszTrunk = szTrunk;
3472
3473# elif defined(RT_OS_SOLARIS)
3474 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
3475 char szTrunk[256];
3476 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
3477 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
3478
3479 /*
3480 * Currently don't bother about malformed names here for the sake of people using
3481 * VBoxManage and setting only the NIC name from there. If there is a space we
3482 * chop it off and proceed, otherwise just use whatever we've got.
3483 */
3484 if (pszSpace)
3485 *pszSpace = '\0';
3486
3487 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
3488 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
3489 if (pszColon)
3490 *pszColon = '\0';
3491
3492 const char *pszTrunk = szTrunk;
3493
3494# elif defined(RT_OS_WINDOWS)
3495 ComPtr<IHostNetworkInterface> hostInterface;
3496 hrc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
3497 if (!SUCCEEDED(hrc))
3498 {
3499 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: FindByName failed, rc=%Rhrc (0x%x)", hrc, hrc));
3500 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
3501 N_("Inexistent host networking interface, name '%ls'"),
3502 HifName.raw());
3503 }
3504
3505 HostNetworkInterfaceType_T eIfType;
3506 hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
3507 if (FAILED(hrc))
3508 {
3509 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
3510 H();
3511 }
3512
3513 if (eIfType != HostNetworkInterfaceType_Bridged)
3514 {
3515 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
3516 N_("Interface ('%ls') is not a Bridged Adapter interface"),
3517 HifName.raw());
3518 }
3519
3520 hrc = hostInterface->COMGETTER(Id)(bstr.asOutParam());
3521 if (FAILED(hrc))
3522 {
3523 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
3524 H();
3525 }
3526 Guid hostIFGuid(bstr);
3527
3528 INetCfg *pNc;
3529 ComPtr<INetCfgComponent> pAdaptorComponent;
3530 LPWSTR pszApp;
3531 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
3532
3533 hrc = VBoxNetCfgWinQueryINetCfg(FALSE /*fGetWriteLock*/,
3534 L"VirtualBox",
3535 &pNc,
3536 &pszApp);
3537 Assert(hrc == S_OK);
3538 if (hrc == S_OK)
3539 {
3540 /* get the adapter's INetCfgComponent*/
3541 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
3542 if (hrc != S_OK)
3543 {
3544 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3545 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
3546 H();
3547 }
3548 }
3549#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
3550 char szTrunkName[INTNET_MAX_TRUNK_NAME];
3551 char *pszTrunkName = szTrunkName;
3552 wchar_t * pswzBindName;
3553 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
3554 Assert(hrc == S_OK);
3555 if (hrc == S_OK)
3556 {
3557 int cwBindName = (int)wcslen(pswzBindName) + 1;
3558 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
3559 if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
3560 {
3561 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
3562 pszTrunkName += cbFullBindNamePrefix-1;
3563 if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
3564 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
3565 {
3566 DWORD err = GetLastError();
3567 hrc = HRESULT_FROM_WIN32(err);
3568 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
3569 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
3570 }
3571 }
3572 else
3573 {
3574 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
3575 /** @todo set appropriate error code */
3576 hrc = E_FAIL;
3577 }
3578
3579 if (hrc != S_OK)
3580 {
3581 AssertFailed();
3582 CoTaskMemFree(pswzBindName);
3583 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3584 H();
3585 }
3586
3587 /* we're not freeing the bind name since we'll use it later for detecting wireless*/
3588 }
3589 else
3590 {
3591 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3592 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
3593 H();
3594 }
3595 const char *pszTrunk = szTrunkName;
3596 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
3597
3598# elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
3599# if defined(RT_OS_FREEBSD)
3600 /*
3601 * If we bridge to a tap interface open it the `old' direct way.
3602 * This works and performs better than bridging a physical
3603 * interface via the current FreeBSD vboxnetflt implementation.
3604 */
3605 if (!strncmp(pszHifName, "tap", sizeof "tap" - 1)) {
3606 hrc = attachToTapInterface(aNetworkAdapter);
3607 if (FAILED(hrc))
3608 {
3609 switch (hrc)
3610 {
3611 case VERR_ACCESS_DENIED:
3612 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
3613 "Failed to open '/dev/%s' for read/write access. Please check the "
3614 "permissions of that node, and that the net.link.tap.user_open "
3615 "sysctl is set. Either run 'chmod 0666 /dev/%s' or "
3616 "change the group of that node to vboxusers and make yourself "
3617 "a member of that group. Make sure that these changes are permanent."), pszHifName, pszHifName);
3618 default:
3619 AssertMsgFailed(("Could not attach to tap interface! Bad!\n"));
3620 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
3621 "Failed to initialize Host Interface Networking"));
3622 }
3623 }
3624
3625 Assert((int)maTapFD[uInstance] >= 0);
3626 if ((int)maTapFD[uInstance] >= 0)
3627 {
3628 InsertConfigString(pLunL0, "Driver", "HostInterface");
3629 InsertConfigNode(pLunL0, "Config", &pCfg);
3630 InsertConfigInteger(pCfg, "FileHandle", maTapFD[uInstance]);
3631 }
3632 break;
3633 }
3634# endif
3635 /** @todo Check for malformed names. */
3636 const char *pszTrunk = pszHifName;
3637
3638 /* Issue a warning if the interface is down */
3639 {
3640 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
3641 if (iSock >= 0)
3642 {
3643 struct ifreq Req;
3644
3645 memset(&Req, 0, sizeof(Req));
3646 strncpy(Req.ifr_name, pszHifName, sizeof(Req.ifr_name) - 1);
3647 if (ioctl(iSock, SIOCGIFFLAGS, &Req) >= 0)
3648 if ((Req.ifr_flags & IFF_UP) == 0)
3649 {
3650 setVMRuntimeErrorCallbackF(pVM, this, 0, "BridgedInterfaceDown", "Bridged interface %s is down. Guest will not be able to use this interface", pszHifName);
3651 }
3652
3653 close(iSock);
3654 }
3655 }
3656
3657# else
3658# error "PORTME (VBOX_WITH_NETFLT)"
3659# endif
3660
3661 InsertConfigString(pLunL0, "Driver", "IntNet");
3662 InsertConfigNode(pLunL0, "Config", &pCfg);
3663 InsertConfigString(pCfg, "Trunk", pszTrunk);
3664 InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
3665 char szNetwork[INTNET_MAX_NETWORK_NAME];
3666 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
3667 InsertConfigString(pCfg, "Network", szNetwork);
3668 networkName = Bstr(szNetwork);
3669 trunkName = Bstr(pszTrunk);
3670 trunkType = Bstr(TRUNKTYPE_NETFLT);
3671
3672# if defined(RT_OS_DARWIN)
3673 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
3674 if ( strstr(pszHifName, "Wireless")
3675 || strstr(pszHifName, "AirPort" ))
3676 InsertConfigInteger(pCfg, "SharedMacOnWire", true);
3677# elif defined(RT_OS_LINUX)
3678 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
3679 if (iSock >= 0)
3680 {
3681 struct iwreq WRq;
3682
3683 memset(&WRq, 0, sizeof(WRq));
3684 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
3685 bool fSharedMacOnWire = ioctl(iSock, SIOCGIWNAME, &WRq) >= 0;
3686 close(iSock);
3687 if (fSharedMacOnWire)
3688 {
3689 InsertConfigInteger(pCfg, "SharedMacOnWire", true);
3690 Log(("Set SharedMacOnWire\n"));
3691 }
3692 else
3693 Log(("Failed to get wireless name\n"));
3694 }
3695 else
3696 Log(("Failed to open wireless socket\n"));
3697# elif defined(RT_OS_FREEBSD)
3698 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
3699 if (iSock >= 0)
3700 {
3701 struct ieee80211req WReq;
3702 uint8_t abData[32];
3703
3704 memset(&WReq, 0, sizeof(WReq));
3705 strncpy(WReq.i_name, pszHifName, sizeof(WReq.i_name));
3706 WReq.i_type = IEEE80211_IOC_SSID;
3707 WReq.i_val = -1;
3708 WReq.i_data = abData;
3709 WReq.i_len = sizeof(abData);
3710
3711 bool fSharedMacOnWire = ioctl(iSock, SIOCG80211, &WReq) >= 0;
3712 close(iSock);
3713 if (fSharedMacOnWire)
3714 {
3715 InsertConfigInteger(pCfg, "SharedMacOnWire", true);
3716 Log(("Set SharedMacOnWire\n"));
3717 }
3718 else
3719 Log(("Failed to get wireless name\n"));
3720 }
3721 else
3722 Log(("Failed to open wireless socket\n"));
3723# elif defined(RT_OS_WINDOWS)
3724# define DEVNAME_PREFIX L"\\\\.\\"
3725 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
3726 * there is a pretty long way till there though since we need to obtain the symbolic link name
3727 * for the adapter device we are going to query given the device Guid */
3728
3729
3730 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
3731
3732 wchar_t FileName[MAX_PATH];
3733 wcscpy(FileName, DEVNAME_PREFIX);
3734 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
3735
3736 /* open the device */
3737 HANDLE hDevice = CreateFile(FileName,
3738 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
3739 NULL,
3740 OPEN_EXISTING,
3741 FILE_ATTRIBUTE_NORMAL,
3742 NULL);
3743
3744 if (hDevice != INVALID_HANDLE_VALUE)
3745 {
3746 bool fSharedMacOnWire = false;
3747
3748 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
3749 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
3750 NDIS_PHYSICAL_MEDIUM PhMedium;
3751 DWORD cbResult;
3752 if (DeviceIoControl(hDevice,
3753 IOCTL_NDIS_QUERY_GLOBAL_STATS,
3754 &Oid,
3755 sizeof(Oid),
3756 &PhMedium,
3757 sizeof(PhMedium),
3758 &cbResult,
3759 NULL))
3760 {
3761 /* that was simple, now examine PhMedium */
3762 if ( PhMedium == NdisPhysicalMediumWirelessWan
3763 || PhMedium == NdisPhysicalMediumWirelessLan
3764 || PhMedium == NdisPhysicalMediumNative802_11
3765 || PhMedium == NdisPhysicalMediumBluetooth)
3766 fSharedMacOnWire = true;
3767 }
3768 else
3769 {
3770 int winEr = GetLastError();
3771 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
3772 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
3773 }
3774 CloseHandle(hDevice);
3775
3776 if (fSharedMacOnWire)
3777 {
3778 Log(("this is a wireless adapter"));
3779 InsertConfigInteger(pCfg, "SharedMacOnWire", true);
3780 Log(("Set SharedMacOnWire\n"));
3781 }
3782 else
3783 Log(("this is NOT a wireless adapter"));
3784 }
3785 else
3786 {
3787 int winEr = GetLastError();
3788 AssertLogRelMsgFailed(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
3789 }
3790
3791 CoTaskMemFree(pswzBindName);
3792
3793 pAdaptorComponent.setNull();
3794 /* release the pNc finally */
3795 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3796# else
3797 /** @todo PORTME: wireless detection */
3798# endif
3799
3800# if defined(RT_OS_SOLARIS)
3801# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
3802 /* Zone access restriction, don't allow snopping the global zone. */
3803 zoneid_t ZoneId = getzoneid();
3804 if (ZoneId != GLOBAL_ZONEID)
3805 {
3806 InsertConfigInteger(pCfg, "IgnoreAllPromisc", true);
3807 }
3808# endif
3809# endif
3810
3811#elif defined(RT_OS_WINDOWS) /* not defined NetFlt */
3812 /* NOTHING TO DO HERE */
3813#elif defined(RT_OS_LINUX)
3814/// @todo aleksey: is there anything to be done here?
3815#elif defined(RT_OS_FREEBSD)
3816/** @todo FreeBSD: Check out this later (HIF networking). */
3817#else
3818# error "Port me"
3819#endif
3820 break;
3821 }
3822
3823 case NetworkAttachmentType_Internal:
3824 {
3825 hrc = aNetworkAdapter->COMGETTER(InternalNetwork)(bstr.asOutParam()); H();
3826 if (!bstr.isEmpty())
3827 {
3828 if (fSniffer)
3829 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
3830 else
3831 InsertConfigNode(pInst, "LUN#0", &pLunL0);
3832 InsertConfigString(pLunL0, "Driver", "IntNet");
3833 InsertConfigNode(pLunL0, "Config", &pCfg);
3834 InsertConfigString(pCfg, "Network", bstr);
3835 InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone);
3836 networkName = bstr;
3837 trunkType = Bstr(TRUNKTYPE_WHATEVER);
3838 }
3839 break;
3840 }
3841
3842 case NetworkAttachmentType_HostOnly:
3843 {
3844 if (fSniffer)
3845 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
3846 else
3847 InsertConfigNode(pInst, "LUN#0", &pLunL0);
3848
3849 InsertConfigString(pLunL0, "Driver", "IntNet");
3850 InsertConfigNode(pLunL0, "Config", &pCfg);
3851
3852 Bstr HifName;
3853 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
3854 if (FAILED(hrc))
3855 {
3856 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)\n", hrc));
3857 H();
3858 }
3859
3860 Utf8Str HifNameUtf8(HifName);
3861 const char *pszHifName = HifNameUtf8.c_str();
3862 ComPtr<IHostNetworkInterface> hostInterface;
3863 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
3864 if (!SUCCEEDED(rc))
3865 {
3866 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)\n", rc));
3867 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
3868 N_("Inexistent host networking interface, name '%ls'"),
3869 HifName.raw());
3870 }
3871
3872 char szNetwork[INTNET_MAX_NETWORK_NAME];
3873 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
3874
3875#if defined(RT_OS_WINDOWS)
3876# ifndef VBOX_WITH_NETFLT
3877 hrc = E_NOTIMPL;
3878 LogRel(("NetworkAttachmentType_HostOnly: Not Implemented\n"));
3879 H();
3880# else /* defined VBOX_WITH_NETFLT*/
3881 /** @todo r=bird: Put this in a function. */
3882
3883 HostNetworkInterfaceType_T eIfType;
3884 hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
3885 if (FAILED(hrc))
3886 {
3887 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)\n", hrc));
3888 H();
3889 }
3890
3891 if (eIfType != HostNetworkInterfaceType_HostOnly)
3892 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
3893 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
3894 HifName.raw());
3895
3896 hrc = hostInterface->COMGETTER(Id)(bstr.asOutParam());
3897 if (FAILED(hrc))
3898 {
3899 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)\n", hrc));
3900 H();
3901 }
3902 Guid hostIFGuid(bstr);
3903
3904 INetCfg *pNc;
3905 ComPtr<INetCfgComponent> pAdaptorComponent;
3906 LPWSTR pszApp;
3907 rc = VERR_INTNET_FLT_IF_NOT_FOUND;
3908
3909 hrc = VBoxNetCfgWinQueryINetCfg(FALSE,
3910 L"VirtualBox",
3911 &pNc,
3912 &pszApp);
3913 Assert(hrc == S_OK);
3914 if (hrc == S_OK)
3915 {
3916 /* get the adapter's INetCfgComponent*/
3917 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
3918 if (hrc != S_OK)
3919 {
3920 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3921 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
3922 H();
3923 }
3924 }
3925#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
3926 char szTrunkName[INTNET_MAX_TRUNK_NAME];
3927 char *pszTrunkName = szTrunkName;
3928 wchar_t * pswzBindName;
3929 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
3930 Assert(hrc == S_OK);
3931 if (hrc == S_OK)
3932 {
3933 int cwBindName = (int)wcslen(pswzBindName) + 1;
3934 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
3935 if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
3936 {
3937 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
3938 pszTrunkName += cbFullBindNamePrefix-1;
3939 if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
3940 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
3941 {
3942 DWORD err = GetLastError();
3943 hrc = HRESULT_FROM_WIN32(err);
3944 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
3945 }
3946 }
3947 else
3948 {
3949 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
3950 /** @todo set appropriate error code */
3951 hrc = E_FAIL;
3952 }
3953
3954 if (hrc != S_OK)
3955 {
3956 AssertFailed();
3957 CoTaskMemFree(pswzBindName);
3958 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3959 H();
3960 }
3961 }
3962 else
3963 {
3964 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3965 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
3966 H();
3967 }
3968
3969
3970 CoTaskMemFree(pswzBindName);
3971
3972 pAdaptorComponent.setNull();
3973 /* release the pNc finally */
3974 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3975
3976 const char *pszTrunk = szTrunkName;
3977
3978 InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp);
3979 InsertConfigString(pCfg, "Trunk", pszTrunk);
3980 InsertConfigString(pCfg, "Network", szNetwork);
3981 networkName = Bstr(szNetwork);
3982 trunkName = Bstr(pszTrunk);
3983 trunkType = TRUNKTYPE_NETADP;
3984# endif /* defined VBOX_WITH_NETFLT*/
3985#elif defined(RT_OS_DARWIN)
3986 InsertConfigString(pCfg, "Trunk", pszHifName);
3987 InsertConfigString(pCfg, "Network", szNetwork);
3988 InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp);
3989 networkName = Bstr(szNetwork);
3990 trunkName = Bstr(pszHifName);
3991 trunkType = TRUNKTYPE_NETADP;
3992#else
3993 InsertConfigString(pCfg, "Trunk", pszHifName);
3994 InsertConfigString(pCfg, "Network", szNetwork);
3995 InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
3996 networkName = Bstr(szNetwork);
3997 trunkName = Bstr(pszHifName);
3998 trunkType = TRUNKTYPE_NETFLT;
3999#endif
4000#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
4001
4002 Bstr tmpAddr, tmpMask;
4003
4004 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPAddress", pszHifName), tmpAddr.asOutParam());
4005 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
4006 {
4007 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPNetMask", pszHifName), tmpMask.asOutParam());
4008 if (SUCCEEDED(hrc) && !tmpMask.isEmpty())
4009 hrc = hostInterface->EnableStaticIpConfig(tmpAddr, tmpMask);
4010 else
4011 hrc = hostInterface->EnableStaticIpConfig(tmpAddr,
4012 Bstr(VBOXNET_IPV4MASK_DEFAULT));
4013 }
4014 else
4015 {
4016 /* Grab the IP number from the 'vboxnetX' instance number (see netif.h) */
4017 hrc = hostInterface->EnableStaticIpConfig(getDefaultIPv4Address(Bstr(pszHifName)),
4018 Bstr(VBOXNET_IPV4MASK_DEFAULT));
4019 }
4020
4021 ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
4022
4023 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6Address", pszHifName), tmpAddr.asOutParam());
4024 if (SUCCEEDED(hrc))
4025 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6NetMask", pszHifName), tmpMask.asOutParam());
4026 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty() && !tmpMask.isEmpty())
4027 {
4028 hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
4029 ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
4030 }
4031#endif
4032 break;
4033 }
4034
4035#if defined(VBOX_WITH_VDE)
4036 case NetworkAttachmentType_VDE:
4037 {
4038 hrc = aNetworkAdapter->COMGETTER(VDENetwork)(bstr.asOutParam()); H();
4039 InsertConfigNode(pInst, "LUN#0", &pLunL0);
4040 InsertConfigString(pLunL0, "Driver", "VDE");
4041 InsertConfigNode(pLunL0, "Config", &pCfg);
4042 if (!bstr.isEmpty())
4043 {
4044 InsertConfigString(pCfg, "Network", bstr);
4045 networkName = bstr;
4046 }
4047 break;
4048 }
4049#endif
4050
4051 default:
4052 AssertMsgFailed(("should not get here!\n"));
4053 break;
4054 }
4055
4056 /*
4057 * Attempt to attach the driver.
4058 */
4059 switch (eAttachmentType)
4060 {
4061 case NetworkAttachmentType_Null:
4062 break;
4063
4064 case NetworkAttachmentType_Bridged:
4065 case NetworkAttachmentType_Internal:
4066 case NetworkAttachmentType_HostOnly:
4067 case NetworkAttachmentType_NAT:
4068#if defined(VBOX_WITH_VDE)
4069 case NetworkAttachmentType_VDE:
4070#endif
4071 {
4072 if (SUCCEEDED(hrc) && SUCCEEDED(rc))
4073 {
4074 if (fAttachDetach)
4075 {
4076 rc = PDMR3DriverAttach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /* ppBase */);
4077 //AssertRC(rc);
4078 }
4079
4080 {
4081 /** @todo pritesh: get the dhcp server name from the
4082 * previous network configuration and then stop the server
4083 * else it may conflict with the dhcp server running with
4084 * the current attachment type
4085 */
4086 /* Stop the hostonly DHCP Server */
4087 }
4088
4089 if (!networkName.isEmpty())
4090 {
4091 /*
4092 * Until we implement service reference counters DHCP Server will be stopped
4093 * by DHCPServerRunner destructor.
4094 */
4095 ComPtr<IDHCPServer> dhcpServer;
4096 hrc = virtualBox->FindDHCPServerByNetworkName(networkName, dhcpServer.asOutParam());
4097 if (SUCCEEDED(hrc))
4098 {
4099 /* there is a DHCP server available for this network */
4100 BOOL fEnabled;
4101 hrc = dhcpServer->COMGETTER(Enabled)(&fEnabled);
4102 if (FAILED(hrc))
4103 {
4104 LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (%Rhrc)", hrc));
4105 H();
4106 }
4107
4108 if (fEnabled)
4109 hrc = dhcpServer->Start(networkName, trunkName, trunkType);
4110 }
4111 else
4112 hrc = S_OK;
4113 }
4114 }
4115
4116 break;
4117 }
4118
4119 default:
4120 AssertMsgFailed(("should not get here!\n"));
4121 break;
4122 }
4123
4124 meAttachmentType[uInstance] = eAttachmentType;
4125 }
4126 catch (ConfigError &x)
4127 {
4128 // InsertConfig threw something:
4129 return x.m_vrc;
4130 }
4131
4132#undef H
4133
4134 return VINF_SUCCESS;
4135}
4136
4137#ifdef VBOX_WITH_GUEST_PROPS
4138/**
4139 * Set an array of guest properties
4140 */
4141static void configSetProperties(VMMDev * const pVMMDev,
4142 void *names,
4143 void *values,
4144 void *timestamps,
4145 void *flags)
4146{
4147 VBOXHGCMSVCPARM parms[4];
4148
4149 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
4150 parms[0].u.pointer.addr = names;
4151 parms[0].u.pointer.size = 0; /* We don't actually care. */
4152 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
4153 parms[1].u.pointer.addr = values;
4154 parms[1].u.pointer.size = 0; /* We don't actually care. */
4155 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
4156 parms[2].u.pointer.addr = timestamps;
4157 parms[2].u.pointer.size = 0; /* We don't actually care. */
4158 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
4159 parms[3].u.pointer.addr = flags;
4160 parms[3].u.pointer.size = 0; /* We don't actually care. */
4161
4162 pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4,
4163 &parms[0]);
4164}
4165
4166/**
4167 * Set a single guest property
4168 */
4169static void configSetProperty(VMMDev * const pVMMDev, const char *pszName,
4170 const char *pszValue, const char *pszFlags)
4171{
4172 VBOXHGCMSVCPARM parms[4];
4173
4174 AssertPtrReturnVoid(pszName);
4175 AssertPtrReturnVoid(pszValue);
4176 AssertPtrReturnVoid(pszFlags);
4177 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
4178 parms[0].u.pointer.addr = (void *)pszName;
4179 parms[0].u.pointer.size = strlen(pszName) + 1;
4180 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
4181 parms[1].u.pointer.addr = (void *)pszValue;
4182 parms[1].u.pointer.size = strlen(pszValue) + 1;
4183 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
4184 parms[2].u.pointer.addr = (void *)pszFlags;
4185 parms[2].u.pointer.size = strlen(pszFlags) + 1;
4186 pVMMDev->hgcmHostCall("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3,
4187 &parms[0]);
4188}
4189
4190/**
4191 * Set the global flags value by calling the service
4192 * @returns the status returned by the call to the service
4193 *
4194 * @param pTable the service instance handle
4195 * @param eFlags the flags to set
4196 */
4197int configSetGlobalPropertyFlags(VMMDev * const pVMMDev,
4198 guestProp::ePropFlags eFlags)
4199{
4200 VBOXHGCMSVCPARM paParm;
4201 paParm.setUInt32(eFlags);
4202 int rc = pVMMDev->hgcmHostCall("VBoxGuestPropSvc",
4203 guestProp::SET_GLOBAL_FLAGS_HOST, 1,
4204 &paParm);
4205 if (RT_FAILURE(rc))
4206 {
4207 char szFlags[guestProp::MAX_FLAGS_LEN];
4208 if (RT_FAILURE(writeFlags(eFlags, szFlags)))
4209 Log(("Failed to set the global flags.\n"));
4210 else
4211 Log(("Failed to set the global flags \"%s\".\n", szFlags));
4212 }
4213 return rc;
4214}
4215#endif /* VBOX_WITH_GUEST_PROPS */
4216
4217/**
4218 * Set up the Guest Property service, populate it with properties read from
4219 * the machine XML and set a couple of initial properties.
4220 */
4221/* static */ int Console::configGuestProperties(void *pvConsole)
4222{
4223#ifdef VBOX_WITH_GUEST_PROPS
4224 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
4225 ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
4226
4227 /* Load the service */
4228 int rc = pConsole->mVMMDev->hgcmLoadService("VBoxGuestPropSvc", "VBoxGuestPropSvc");
4229
4230 if (RT_FAILURE(rc))
4231 {
4232 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
4233 /* That is not a fatal failure. */
4234 rc = VINF_SUCCESS;
4235 }
4236 else
4237 {
4238 /*
4239 * Initialize built-in properties that can be changed and saved.
4240 *
4241 * These are typically transient properties that the guest cannot
4242 * change.
4243 */
4244
4245 /* Sysprep execution by VBoxService. */
4246 configSetProperty(pConsole->mVMMDev,
4247 "/VirtualBox/HostGuest/SysprepExec", "",
4248 "TRANSIENT, RDONLYGUEST");
4249 configSetProperty(pConsole->mVMMDev,
4250 "/VirtualBox/HostGuest/SysprepArgs", "",
4251 "TRANSIENT, RDONLYGUEST");
4252
4253 /*
4254 * Pull over the properties from the server.
4255 */
4256 SafeArray<BSTR> namesOut;
4257 SafeArray<BSTR> valuesOut;
4258 SafeArray<LONG64> timestampsOut;
4259 SafeArray<BSTR> flagsOut;
4260 HRESULT hrc;
4261 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
4262 ComSafeArrayAsOutParam(valuesOut),
4263 ComSafeArrayAsOutParam(timestampsOut),
4264 ComSafeArrayAsOutParam(flagsOut));
4265 AssertMsgReturn(SUCCEEDED(hrc), ("hrc=%Rrc\n", hrc), VERR_GENERAL_FAILURE);
4266 size_t cProps = namesOut.size();
4267 size_t cAlloc = cProps + 1;
4268 if ( valuesOut.size() != cProps
4269 || timestampsOut.size() != cProps
4270 || flagsOut.size() != cProps
4271 )
4272 AssertFailedReturn(VERR_INVALID_PARAMETER);
4273
4274 char **papszNames, **papszValues, **papszFlags;
4275 char szEmpty[] = "";
4276 LONG64 *pai64Timestamps;
4277 papszNames = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
4278 papszValues = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
4279 pai64Timestamps = (LONG64 *)RTMemTmpAllocZ(sizeof(LONG64) * cAlloc);
4280 papszFlags = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
4281 if (papszNames && papszValues && pai64Timestamps && papszFlags)
4282 {
4283 for (unsigned i = 0; RT_SUCCESS(rc) && i < cProps; ++i)
4284 {
4285 AssertPtrReturn(namesOut[i], VERR_INVALID_PARAMETER);
4286 rc = RTUtf16ToUtf8(namesOut[i], &papszNames[i]);
4287 if (RT_FAILURE(rc))
4288 break;
4289 if (valuesOut[i])
4290 rc = RTUtf16ToUtf8(valuesOut[i], &papszValues[i]);
4291 else
4292 papszValues[i] = szEmpty;
4293 if (RT_FAILURE(rc))
4294 break;
4295 pai64Timestamps[i] = timestampsOut[i];
4296 if (flagsOut[i])
4297 rc = RTUtf16ToUtf8(flagsOut[i], &papszFlags[i]);
4298 else
4299 papszFlags[i] = szEmpty;
4300 }
4301 if (RT_SUCCESS(rc))
4302 configSetProperties(pConsole->mVMMDev,
4303 (void *)papszNames,
4304 (void *)papszValues,
4305 (void *)pai64Timestamps,
4306 (void *)papszFlags);
4307 for (unsigned i = 0; i < cProps; ++i)
4308 {
4309 RTStrFree(papszNames[i]);
4310 if (valuesOut[i])
4311 RTStrFree(papszValues[i]);
4312 if (flagsOut[i])
4313 RTStrFree(papszFlags[i]);
4314 }
4315 }
4316 else
4317 rc = VERR_NO_MEMORY;
4318 RTMemTmpFree(papszNames);
4319 RTMemTmpFree(papszValues);
4320 RTMemTmpFree(pai64Timestamps);
4321 RTMemTmpFree(papszFlags);
4322 AssertRCReturn(rc, rc);
4323
4324 /*
4325 * These properties have to be set before pulling over the properties
4326 * from the machine XML, to ensure that properties saved in the XML
4327 * will override them.
4328 */
4329 /* Set the VBox version string as a guest property */
4330 configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxVer",
4331 VBOX_VERSION_STRING, "TRANSIENT, RDONLYGUEST");
4332 /* Set the VBox SVN revision as a guest property */
4333 configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxRev",
4334 RTBldCfgRevisionStr(), "TRANSIENT, RDONLYGUEST");
4335
4336 /*
4337 * Register the host notification callback
4338 */
4339 HGCMSVCEXTHANDLE hDummy;
4340 HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestPropSvc",
4341 Console::doGuestPropNotification,
4342 pvConsole);
4343
4344#ifdef VBOX_WITH_GUEST_PROPS_RDONLY_GUEST
4345 rc = configSetGlobalPropertyFlags(pConsole->mVMMDev,
4346 guestProp::RDONLYGUEST);
4347 AssertRCReturn(rc, rc);
4348#endif
4349
4350 Log(("Set VBoxGuestPropSvc property store\n"));
4351 }
4352 return VINF_SUCCESS;
4353#else /* !VBOX_WITH_GUEST_PROPS */
4354 return VERR_NOT_SUPPORTED;
4355#endif /* !VBOX_WITH_GUEST_PROPS */
4356}
4357
4358/**
4359 * Set up the Guest Control service.
4360 */
4361/* static */ int Console::configGuestControl(void *pvConsole)
4362{
4363#ifdef VBOX_WITH_GUEST_CONTROL
4364 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
4365 ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
4366
4367 /* Load the service */
4368 int rc = pConsole->mVMMDev->hgcmLoadService("VBoxGuestControlSvc", "VBoxGuestControlSvc");
4369
4370 if (RT_FAILURE(rc))
4371 {
4372 LogRel(("VBoxGuestControlSvc is not available. rc = %Rrc\n", rc));
4373 /* That is not a fatal failure. */
4374 rc = VINF_SUCCESS;
4375 }
4376 else
4377 {
4378 HGCMSVCEXTHANDLE hDummy;
4379 rc = HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestControlSvc",
4380 &Guest::doGuestCtrlNotification,
4381 pConsole->getGuest());
4382 if (RT_FAILURE(rc))
4383 Log(("Cannot register VBoxGuestControlSvc extension!\n"));
4384 else
4385 Log(("VBoxGuestControlSvc loaded\n"));
4386 }
4387
4388 return rc;
4389#else /* !VBOX_WITH_GUEST_CONTROL */
4390 return VERR_NOT_SUPPORTED;
4391#endif /* !VBOX_WITH_GUEST_CONTROL */
4392}
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