VirtualBox

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

Last change on this file since 26834 was 26753, checked in by vboxsync, 15 years ago

Main: Bstr makeover (third attempt) -- make Bstr(NULL) and Bstr() behave the same; resulting cleanup; make some more internal methods use Utf8Str instead of Bstr; fix a lot of CheckComArgNotNull??() usage

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 150.8 KB
Line 
1/* $Id: ConsoleImpl2.cpp 26753 2010-02-24 16:24:33Z 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 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23 * Clara, CA 95054 USA or visit http://www.sun.com if you need
24 * additional information or have any questions.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include "ConsoleImpl.h"
31#include "DisplayImpl.h"
32#include "VMMDev.h"
33
34// generated header
35#include "SchemaDefs.h"
36
37#include "AutoCaller.h"
38#include "Logging.h"
39
40#include <iprt/buildconfig.h>
41#include <iprt/string.h>
42#include <iprt/path.h>
43#include <iprt/dir.h>
44#include <iprt/param.h>
45#if 0 /* enable to play with lots of memory. */
46# include <iprt/env.h>
47#endif
48#include <iprt/file.h>
49
50#include <VBox/vmapi.h>
51#include <VBox/err.h>
52#include <VBox/version.h>
53#include <VBox/HostServices/VBoxClipboardSvc.h>
54#ifdef VBOX_WITH_CROGL
55#include <VBox/HostServices/VBoxCrOpenGLSvc.h>
56#endif
57#ifdef VBOX_WITH_GUEST_PROPS
58# include <VBox/HostServices/GuestPropertySvc.h>
59# include <VBox/com/defs.h>
60# include <VBox/com/array.h>
61# include <hgcm/HGCM.h> /** @todo it should be possible to register a service
62 * extension using a VMMDev callback. */
63# include <vector>
64#endif /* VBOX_WITH_GUEST_PROPS */
65#include <VBox/intnet.h>
66
67#include <VBox/com/com.h>
68#include <VBox/com/string.h>
69#include <VBox/com/array.h>
70
71#if defined(RT_OS_SOLARIS) && defined(VBOX_WITH_NETFLT)
72# include <zone.h>
73#endif
74
75#if defined(RT_OS_LINUX) && defined(VBOX_WITH_NETFLT)
76# include <unistd.h>
77# include <sys/ioctl.h>
78# include <sys/socket.h>
79# include <linux/types.h>
80# include <linux/if.h>
81# include <linux/wireless.h>
82#endif
83
84#if defined(RT_OS_FREEBSD) && defined(VBOX_WITH_NETFLT)
85# include <unistd.h>
86# include <sys/types.h>
87# include <sys/ioctl.h>
88# include <sys/socket.h>
89# include <net/if.h>
90# include <net80211/ieee80211_ioctl.h>
91#endif
92
93#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
94# include <VBox/WinNetConfig.h>
95# include <Ntddndis.h>
96# include <devguid.h>
97#endif
98
99#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
100# include <HostNetworkInterfaceImpl.h>
101# include <netif.h>
102# include <stdlib.h>
103#endif
104
105#include "DHCPServerRunner.h"
106
107#include <VBox/param.h>
108#include <VBox/pdmapi.h> /* For PDMR3DriverAttach/PDMR3DriverDetach */
109
110#if defined(RT_OS_DARWIN) && !defined(VBOX_OSE)
111
112# include "IOKit/IOKitLib.h"
113
114int DarwinSmcKey(char* aKey, uint32_t iKeySize)
115{
116 /*
117 * Method as described in Amit Singh's article:
118 * http://osxbook.com/book/bonus/chapter7/tpmdrmmyth/
119 */
120 typedef struct {
121 uint32_t key;
122 uint8_t pad0[22];
123 uint32_t datasize;
124 uint8_t pad1[10];
125 uint8_t cmd;
126 uint32_t pad2;
127 uint8_t data[32];
128 } AppleSMCBuffer;
129
130
131 if (iKeySize < 65)
132 return VERR_INTERNAL_ERROR;
133
134 io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
135 IOServiceMatching("AppleSMC"));
136 if (!service)
137 return VERR_INTERNAL_ERROR;
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 VERR_INTERNAL_ERROR;
145
146 AppleSMCBuffer inputStruct = { 0, {0}, 32, {0}, 5, }, outputStruct;
147 size_t outputStructCnt = sizeof(outputStruct);
148
149 for (int i = 0; i < 2; i++)
150 {
151 inputStruct.key = (uint32_t)((i == 0) ? 'OSK0' : 'OSK1');
152 kr = IOConnectCallStructMethod((mach_port_t)port,
153 (uint32_t)2,
154 (const void*)&inputStruct,
155 sizeof(inputStruct),
156 (void*)&outputStruct,
157 &outputStructCnt);
158 if (kr != kIOReturnSuccess)
159 return VERR_INTERNAL_ERROR;
160
161 for (int j=0; j<32; j++)
162 aKey[j + i*32] = outputStruct.data[j];
163 }
164
165 IOServiceClose(port);
166
167 aKey[64] = 0;
168
169 return VINF_SUCCESS;
170}
171
172#endif
173
174#undef PVM
175
176/* Comment out the following line to remove VMWare compatibility hack. */
177#define VMWARE_NET_IN_SLOT_11
178
179/**
180 * Translate IDE StorageControllerType_T to string representation.
181 */
182const char* controllerString(StorageControllerType_T enmType)
183{
184 switch (enmType)
185 {
186 case StorageControllerType_PIIX3:
187 return "PIIX3";
188 case StorageControllerType_PIIX4:
189 return "PIIX4";
190 case StorageControllerType_ICH6:
191 return "ICH6";
192 default:
193 return "Unknown";
194 }
195}
196
197/*
198 * VC++ 8 / amd64 has some serious trouble with this function.
199 * As a temporary measure, we'll drop global optimizations.
200 */
201#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
202# pragma optimize("g", off)
203#endif
204
205static int findEfiRom(IVirtualBox* vbox, FirmwareType_T aFirmwareType, Utf8Str& aEfiRomFile)
206{
207 int rc;
208 BOOL fPresent = FALSE;
209 Bstr aFilePath, empty;
210
211 rc = vbox->CheckFirmwarePresent(aFirmwareType, empty,
212 empty.asOutParam(), aFilePath.asOutParam(), &fPresent);
213 if (RT_FAILURE(rc))
214 AssertComRCReturn (rc, VERR_FILE_NOT_FOUND);
215
216 if (!fPresent)
217 return VERR_FILE_NOT_FOUND;
218
219 aEfiRomFile = Utf8Str(aFilePath);
220
221 return S_OK;
222}
223
224static int getSmcDeviceKey(IMachine* pMachine, BSTR * aKey)
225{
226 int rc;
227
228# if defined(RT_OS_DARWIN) && !defined(VBOX_OSE)
229 char aKeyBuf[65];
230
231 rc = DarwinSmcKey(aKeyBuf, sizeof aKeyBuf);
232 if (SUCCEEDED(rc))
233 {
234 Bstr(aKeyBuf).detachTo(aKey);
235 return rc;
236 }
237#endif
238
239 return pMachine->GetExtraData(Bstr("VBoxInternal2/SmcDeviceKey"), aKey);
240}
241
242/**
243 * Construct the VM configuration tree (CFGM).
244 *
245 * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
246 * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
247 * is done here.
248 *
249 * @param pVM VM handle.
250 * @param pvConsole Pointer to the VMPowerUpTask object.
251 * @return VBox status code.
252 *
253 * @note Locks the Console object for writing.
254 */
255DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
256{
257 LogFlowFuncEnter();
258 /* Note: hardcoded assumption about number of slots; see rom bios */
259 bool afPciDeviceNo[32] = {false};
260 bool fFdcEnabled = false;
261 BOOL fIs64BitGuest = false;
262
263#if !defined (VBOX_WITH_XPCOM)
264 {
265 /* initialize COM */
266 HRESULT hrc = CoInitializeEx(NULL,
267 COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
268 COINIT_SPEED_OVER_MEMORY);
269 LogFlow (("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
270 AssertComRCReturn (hrc, VERR_GENERAL_FAILURE);
271 }
272#endif
273
274 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
275 ComObjPtr<Console> pConsole = static_cast <Console *> (pvConsole);
276
277 AutoCaller autoCaller(pConsole);
278 AssertComRCReturn (autoCaller.rc(), VERR_ACCESS_DENIED);
279
280 /* lock the console because we widely use internal fields and methods */
281 AutoWriteLock alock(pConsole COMMA_LOCKVAL_SRC_POS);
282
283 /* Save the VM pointer in the machine object */
284 pConsole->mpVM = pVM;
285
286 ComPtr<IMachine> pMachine = pConsole->machine();
287
288 int rc;
289 HRESULT hrc;
290 BSTR str = NULL;
291
292#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } } while (0)
293#define RC_CHECK() do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc)); STR_FREE(); return rc; } } while (0)
294#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
295
296 /*
297 * Get necessary objects and frequently used parameters.
298 */
299 ComPtr<IVirtualBox> virtualBox;
300 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
301
302 ComPtr<IHost> host;
303 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
304
305 ComPtr<ISystemProperties> systemProperties;
306 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
307
308 ComPtr<IBIOSSettings> biosSettings;
309 hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
310
311 hrc = pMachine->COMGETTER(HardwareUUID)(&str); H();
312 RTUUID HardwareUuid;
313 rc = RTUuidFromUtf16(&HardwareUuid, str); RC_CHECK();
314 STR_FREE();
315
316 ULONG cRamMBs;
317 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
318#if 0 /* enable to play with lots of memory. */
319 if (RTEnvExist("VBOX_RAM_SIZE"))
320 cRamMBs = RTStrToUInt64(RTEnvGet("VBOX_RAM_SIZE"));
321#endif
322 uint64_t const cbRam = cRamMBs * (uint64_t)_1M;
323 uint32_t const cbRamHole = MM_RAM_HOLE_SIZE_DEFAULT;
324
325 ULONG cCpus = 1;
326 hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
327
328 Bstr osTypeId;
329 hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
330
331 BOOL fIOAPIC;
332 hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
333
334 ComPtr<IGuestOSType> guestOSType;
335 hrc = virtualBox->GetGuestOSType(osTypeId, guestOSType.asOutParam()); H();
336
337 /*
338 * Get root node first.
339 * This is the only node in the tree.
340 */
341 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
342 Assert(pRoot);
343
344 /*
345 * Set the root (and VMM) level values.
346 */
347 hrc = pMachine->COMGETTER(Name)(&str); H();
348 rc = CFGMR3InsertStringW(pRoot, "Name", str); RC_CHECK();
349 rc = CFGMR3InsertBytes(pRoot, "UUID", &HardwareUuid, sizeof(HardwareUuid)); RC_CHECK();
350 rc = CFGMR3InsertInteger(pRoot, "RamSize", cbRam); RC_CHECK();
351 rc = CFGMR3InsertInteger(pRoot, "RamHoleSize", cbRamHole); RC_CHECK();
352 rc = CFGMR3InsertInteger(pRoot, "NumCPUs", cCpus); RC_CHECK();
353 rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10); RC_CHECK();
354#ifdef VBOX_WITH_RAW_MODE
355 rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1); /* boolean */ RC_CHECK();
356 rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1); /* boolean */ RC_CHECK();
357 /** @todo Config: RawR0, PATMEnabled and CSAMEnabled needs attention later. */
358 rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1); /* boolean */ RC_CHECK();
359 rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1); /* boolean */ RC_CHECK();
360#endif
361
362 /* cpuid leaf overrides. */
363 static uint32_t const s_auCpuIdRanges[] =
364 {
365 UINT32_C(0x00000000), UINT32_C(0x0000000a),
366 UINT32_C(0x80000000), UINT32_C(0x8000000a)
367 };
368 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
369 for (uint32_t uLeaf = s_auCpuIdRanges[i]; uLeaf < s_auCpuIdRanges[i + 1]; uLeaf++)
370 {
371 ULONG ulEax, ulEbx, ulEcx, ulEdx;
372 hrc = pMachine->GetCpuIdLeaf(uLeaf, &ulEax, &ulEbx, &ulEcx, &ulEdx);
373 if (SUCCEEDED(hrc))
374 {
375 PCFGMNODE pLeaf;
376 rc = CFGMR3InsertNodeF(pRoot, &pLeaf, "CPUM/HostCPUID/%RX32", uLeaf); RC_CHECK();
377
378 rc = CFGMR3InsertInteger(pLeaf, "eax", ulEax); RC_CHECK();
379 rc = CFGMR3InsertInteger(pLeaf, "ebx", ulEbx); RC_CHECK();
380 rc = CFGMR3InsertInteger(pLeaf, "ecx", ulEcx); RC_CHECK();
381 rc = CFGMR3InsertInteger(pLeaf, "edx", ulEdx); RC_CHECK();
382 }
383 else if (hrc != E_INVALIDARG) H();
384 }
385
386 if (osTypeId == "WindowsNT4")
387 {
388 /*
389 * We must limit CPUID count for Windows NT 4, as otherwise it stops
390 * with error 0x3e (MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED).
391 */
392 LogRel(("Limiting CPUID leaf count for NT4 guests\n"));
393 PCFGMNODE pCPUM;
394 rc = CFGMR3InsertNode(pRoot, "CPUM", &pCPUM); RC_CHECK();
395 rc = CFGMR3InsertInteger(pCPUM, "NT4LeafLimit", true); RC_CHECK();
396 }
397
398 if (osTypeId == "MacOS")
399 {
400 /*
401 * Expose extended MWAIT features to Mac OS guests.
402 */
403 LogRel(("Using MWAIT extensions\n"));
404 PCFGMNODE pCPUM;
405 rc = CFGMR3InsertNode(pRoot, "CPUM", &pCPUM); RC_CHECK();
406 rc = CFGMR3InsertInteger(pCPUM, "MWaitExtensions", true); RC_CHECK();
407 }
408
409 /* hardware virtualization extensions */
410 BOOL fHWVirtExEnabled;
411 BOOL fHwVirtExtForced;
412#ifdef VBOX_WITH_RAW_MODE
413 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Enabled, &fHWVirtExEnabled); H();
414 if (cCpus > 1) /** @todo SMP: This isn't nice, but things won't work on mac otherwise. */
415 fHWVirtExEnabled = TRUE;
416# ifdef RT_OS_DARWIN
417 fHwVirtExtForced = fHWVirtExEnabled;
418# else
419 /* - With more than 4GB PGM will use different RAMRANGE sizes for raw
420 mode and hv mode to optimize lookup times.
421 - With more than one virtual CPU, raw-mode isn't a fallback option. */
422 fHwVirtExtForced = fHWVirtExEnabled
423 && ( cbRam > (_4G - cbRamHole)
424 || cCpus > 1);
425# endif
426#else /* !VBOX_WITH_RAW_MODE */
427 fHWVirtExEnabled = fHwVirtExtForced = TRUE;
428#endif /* !VBOX_WITH_RAW_MODE */
429 rc = CFGMR3InsertInteger(pRoot, "HwVirtExtForced", fHwVirtExtForced); RC_CHECK();
430
431 PCFGMNODE pHWVirtExt;
432 rc = CFGMR3InsertNode(pRoot, "HWVirtExt", &pHWVirtExt); RC_CHECK();
433 if (fHWVirtExEnabled)
434 {
435 rc = CFGMR3InsertInteger(pHWVirtExt, "Enabled", 1); RC_CHECK();
436
437 /* Indicate whether 64-bit guests are supported or not. */
438 /** @todo This is currently only forced off on 32-bit hosts only because it
439 * makes a lof of difference there (REM and Solaris performance).
440 */
441 BOOL fSupportsLongMode = false;
442 hrc = host->GetProcessorFeature(ProcessorFeature_LongMode,
443 &fSupportsLongMode); H();
444 hrc = guestOSType->COMGETTER(Is64Bit)(&fIs64BitGuest); H();
445
446 if (fSupportsLongMode && fIs64BitGuest)
447 {
448 rc = CFGMR3InsertInteger(pHWVirtExt, "64bitEnabled", 1); RC_CHECK();
449#if ARCH_BITS == 32 /* The recompiler must use VBoxREM64 (32-bit host only). */
450 PCFGMNODE pREM;
451 rc = CFGMR3InsertNode(pRoot, "REM", &pREM); RC_CHECK();
452 rc = CFGMR3InsertInteger(pREM, "64bitEnabled", 1); RC_CHECK();
453#endif
454 }
455#if ARCH_BITS == 32 /* 32-bit guests only. */
456 else
457 {
458 rc = CFGMR3InsertInteger(pHWVirtExt, "64bitEnabled", 0); RC_CHECK();
459 }
460#endif
461
462 /** @todo Not exactly pretty to check strings; VBOXOSTYPE would be better, but that requires quite a bit of API change in Main. */
463 if ( !fIs64BitGuest
464 && fIOAPIC
465 && ( osTypeId == "WindowsNT4"
466 || osTypeId == "Windows2000"
467 || osTypeId == "WindowsXP"
468 || osTypeId == "Windows2003"))
469 {
470 /* Only allow TPR patching for NT, Win2k, XP and Windows Server 2003. (32 bits mode)
471 * We may want to consider adding more guest OSes (Solaris) later on.
472 */
473 rc = CFGMR3InsertInteger(pHWVirtExt, "TPRPatchingEnabled", 1); RC_CHECK();
474 }
475 }
476
477 /* HWVirtEx exclusive mode */
478 BOOL fHWVirtExExclusive = true;
479 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Exclusive, &fHWVirtExExclusive); H();
480 rc = CFGMR3InsertInteger(pHWVirtExt, "Exclusive", fHWVirtExExclusive); RC_CHECK();
481
482 /* Nested paging (VT-x/AMD-V) */
483 BOOL fEnableNestedPaging = false;
484 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &fEnableNestedPaging); H();
485 rc = CFGMR3InsertInteger(pHWVirtExt, "EnableNestedPaging", fEnableNestedPaging); RC_CHECK();
486
487 /* VPID (VT-x) */
488 BOOL fEnableVPID = false;
489 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &fEnableVPID); H();
490 rc = CFGMR3InsertInteger(pHWVirtExt, "EnableVPID", fEnableVPID); RC_CHECK();
491
492 /* Physical Address Extension (PAE) */
493 BOOL fEnablePAE = false;
494 hrc = pMachine->GetCpuProperty(CpuPropertyType_PAE, &fEnablePAE); H();
495 rc = CFGMR3InsertInteger(pRoot, "EnablePAE", fEnablePAE); RC_CHECK();
496
497 /* Synthetic CPU */
498 BOOL fSyntheticCpu = false;
499 hrc = pMachine->GetCpuProperty(CpuPropertyType_Synthetic, &fSyntheticCpu); H();
500 rc = CFGMR3InsertInteger(pRoot, "SyntheticCpu", fSyntheticCpu); RC_CHECK();
501
502 BOOL fPXEDebug;
503 hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
504
505 /*
506 * PDM config.
507 * Load drivers in VBoxC.[so|dll]
508 */
509 PCFGMNODE pPDM;
510 PCFGMNODE pDrivers;
511 PCFGMNODE pMod;
512 rc = CFGMR3InsertNode(pRoot, "PDM", &pPDM); RC_CHECK();
513 rc = CFGMR3InsertNode(pPDM, "Drivers", &pDrivers); RC_CHECK();
514 rc = CFGMR3InsertNode(pDrivers, "VBoxC", &pMod); RC_CHECK();
515#ifdef VBOX_WITH_XPCOM
516 // VBoxC is located in the components subdirectory
517 char szPathVBoxC[RTPATH_MAX];
518 rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
519 strcat(szPathVBoxC, "/components/VBoxC");
520 rc = CFGMR3InsertString(pMod, "Path", szPathVBoxC); RC_CHECK();
521#else
522 rc = CFGMR3InsertString(pMod, "Path", "VBoxC"); RC_CHECK();
523#endif
524
525 /*
526 * Devices
527 */
528 PCFGMNODE pDevices = NULL; /* /Devices */
529 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
530 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
531 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
532 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
533 PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
534 PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
535 PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
536
537 rc = CFGMR3InsertNode(pRoot, "Devices", &pDevices); RC_CHECK();
538
539 /*
540 * PC Arch.
541 */
542 rc = CFGMR3InsertNode(pDevices, "pcarch", &pDev); RC_CHECK();
543 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
544 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
545 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
546
547 /*
548 * The time offset
549 */
550 LONG64 timeOffset;
551 hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
552 PCFGMNODE pTMNode;
553 rc = CFGMR3InsertNode(pRoot, "TM", &pTMNode); RC_CHECK();
554 rc = CFGMR3InsertInteger(pTMNode, "UTCOffset", timeOffset * 1000000); RC_CHECK();
555
556 /*
557 * DMA
558 */
559 rc = CFGMR3InsertNode(pDevices, "8237A", &pDev); RC_CHECK();
560 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
561 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
562
563 /*
564 * PCI buses.
565 */
566 rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */ RC_CHECK();
567 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
568 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
569 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
570 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
571
572#if 0 /* enable this to test PCI bridging */
573 rc = CFGMR3InsertNode(pDevices, "pcibridge", &pDev); RC_CHECK();
574 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
575 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
576 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
577 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 14); RC_CHECK();
578 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
579 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 0);/* -> pci[0] */ RC_CHECK();
580
581 rc = CFGMR3InsertNode(pDev, "1", &pInst); RC_CHECK();
582 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
583 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
584 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 1); RC_CHECK();
585 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
586 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
587
588 rc = CFGMR3InsertNode(pDev, "2", &pInst); RC_CHECK();
589 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
590 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
591 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 3); RC_CHECK();
592 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
593 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
594#endif
595
596 Bstr tmpStr2;
597 hrc = guestOSType->COMGETTER(FamilyId)(tmpStr2.asOutParam()); H();
598 /*
599 * Enable 3 following devices: HPET, SMC, LPC on MacOS X guests
600 */
601 BOOL fExtProfile = tmpStr2 == Bstr("MacOS");
602
603 /*
604 * High Precision Event Timer (HPET)
605 */
606 BOOL fHpetEnabled;
607#ifdef VBOX_WITH_HPET
608 /* Other guests may wish to use HPET too, but MacOS X not functional without it */
609 hrc = pMachine->COMGETTER(HpetEnabled)(&fHpetEnabled); H();
610 /* so always enable HPET in extended profile */
611 fHpetEnabled |= fExtProfile;
612#else
613 fHpetEnabled = false;
614#endif
615 if (fHpetEnabled)
616 {
617 rc = CFGMR3InsertNode(pDevices, "hpet", &pDev); RC_CHECK();
618 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
619 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
620 }
621
622 /*
623 * System Management Controller (SMC)
624 */
625 BOOL fSmcEnabled;
626#ifdef VBOX_WITH_SMC
627 fSmcEnabled = fExtProfile;
628#else
629 fSmcEnabled = false;
630#endif
631 if (fSmcEnabled)
632 {
633 rc = CFGMR3InsertNode(pDevices, "smc", &pDev); RC_CHECK();
634 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
635 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
636 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
637 rc = getSmcDeviceKey(pMachine, tmpStr2.asOutParam()); RC_CHECK();
638 rc = CFGMR3InsertString(pCfg, "DeviceKey", Utf8Str(tmpStr2).raw());RC_CHECK();
639 }
640
641 /*
642 * Low Pin Count (LPC) bus
643 */
644 BOOL fLpcEnabled;
645 /** @todo: implement appropriate getter */
646#ifdef VBOX_WITH_LPC
647 fLpcEnabled = fExtProfile;
648#else
649 fLpcEnabled = false;
650#endif
651 if (fLpcEnabled)
652 {
653 rc = CFGMR3InsertNode(pDevices, "lpc", &pDev); RC_CHECK();
654 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
655 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
656 }
657
658 /*
659 * PS/2 keyboard & mouse.
660 */
661 rc = CFGMR3InsertNode(pDevices, "pckbd", &pDev); RC_CHECK();
662 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
663 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
664 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
665
666 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
667 rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); RC_CHECK();
668 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
669 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); RC_CHECK();
670
671 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
672 rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard"); RC_CHECK();
673 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
674 Keyboard *pKeyboard = pConsole->mKeyboard;
675 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pKeyboard); RC_CHECK();
676
677 rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL0); RC_CHECK();
678 rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); RC_CHECK();
679 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
680 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); RC_CHECK();
681
682 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
683 rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse"); RC_CHECK();
684 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
685 Mouse *pMouse = pConsole->mMouse;
686 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse); RC_CHECK();
687
688 /*
689 * i8254 Programmable Interval Timer And Dummy Speaker
690 */
691 rc = CFGMR3InsertNode(pDevices, "i8254", &pDev); RC_CHECK();
692 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
693 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
694#ifdef DEBUG
695 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
696#endif
697
698 /*
699 * i8259 Programmable Interrupt Controller.
700 */
701 rc = CFGMR3InsertNode(pDevices, "i8259", &pDev); RC_CHECK();
702 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
703 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
704 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
705
706 /*
707 * Advanced Programmable Interrupt Controller.
708 * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
709 * thus only single insert
710 */
711 rc = CFGMR3InsertNode(pDevices, "apic", &pDev); RC_CHECK();
712 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
713 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
714 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
715 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
716 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
717
718 if (fIOAPIC)
719 {
720 /*
721 * I/O Advanced Programmable Interrupt Controller.
722 */
723 rc = CFGMR3InsertNode(pDevices, "ioapic", &pDev); RC_CHECK();
724 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
725 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
726 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
727 }
728
729 /*
730 * RTC MC146818.
731 */
732 rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); RC_CHECK();
733 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
734 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
735 BOOL fRTCUseUTC;
736 hrc = pMachine->COMGETTER(RTCUseUTC)(&fRTCUseUTC); H();
737 rc = CFGMR3InsertInteger(pCfg, "UseUTC", fRTCUseUTC ? 1 : 0);
738
739 /*
740 * VGA.
741 */
742 rc = CFGMR3InsertNode(pDevices, "vga", &pDev); RC_CHECK();
743 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
744 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
745 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 2); RC_CHECK();
746 Assert(!afPciDeviceNo[2]);
747 afPciDeviceNo[2] = true;
748 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
749 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
750 ULONG cVRamMBs;
751 hrc = pMachine->COMGETTER(VRAMSize)(&cVRamMBs); H();
752 rc = CFGMR3InsertInteger(pCfg, "VRamSize", cVRamMBs * _1M); RC_CHECK();
753 ULONG cMonitorCount;
754 hrc = pMachine->COMGETTER(MonitorCount)(&cMonitorCount); H();
755 rc = CFGMR3InsertInteger(pCfg, "MonitorCount", cMonitorCount); RC_CHECK();
756#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */ /** @todo this needs fixing !!! No wonder VGA is slooooooooow on 32-bit darwin! */
757 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", fHWVirtExEnabled); RC_CHECK();
758#endif
759
760 /*
761 * BIOS logo
762 */
763 BOOL fFadeIn;
764 hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
765 rc = CFGMR3InsertInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0); RC_CHECK();
766 BOOL fFadeOut;
767 hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
768 rc = CFGMR3InsertInteger(pCfg, "FadeOut", fFadeOut ? 1: 0); RC_CHECK();
769 ULONG logoDisplayTime;
770 hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
771 rc = CFGMR3InsertInteger(pCfg, "LogoTime", logoDisplayTime); RC_CHECK();
772 Bstr logoImagePath;
773 hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
774 rc = CFGMR3InsertString(pCfg, "LogoFile", logoImagePath ? Utf8Str(logoImagePath).c_str() : ""); RC_CHECK();
775
776 /*
777 * Boot menu
778 */
779 BIOSBootMenuMode_T eBootMenuMode;
780 int iShowBootMenu;
781 biosSettings->COMGETTER(BootMenuMode)(&eBootMenuMode);
782 switch (eBootMenuMode)
783 {
784 case BIOSBootMenuMode_Disabled: iShowBootMenu = 0; break;
785 case BIOSBootMenuMode_MenuOnly: iShowBootMenu = 1; break;
786 default: iShowBootMenu = 2; break;
787 }
788 rc = CFGMR3InsertInteger(pCfg, "ShowBootMenu", iShowBootMenu); RC_CHECK();
789
790 /* Custom VESA mode list */
791 unsigned cModes = 0;
792 for (unsigned iMode = 1; iMode <= 16; ++iMode)
793 {
794 char szExtraDataKey[sizeof("CustomVideoModeXX")];
795 RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%u", iMode);
796 hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), &str); H();
797 if (!str || !*str)
798 break;
799 rc = CFGMR3InsertStringW(pCfg, szExtraDataKey, str); RC_CHECK();
800 STR_FREE();
801 ++cModes;
802 }
803 STR_FREE();
804 rc = CFGMR3InsertInteger(pCfg, "CustomVideoModes", cModes);
805
806 /* VESA height reduction */
807 ULONG ulHeightReduction;
808 IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
809 if (pFramebuffer)
810 {
811 hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
812 }
813 else
814 {
815 /* If framebuffer is not available, there is no height reduction. */
816 ulHeightReduction = 0;
817 }
818 rc = CFGMR3InsertInteger(pCfg, "HeightReduction", ulHeightReduction); RC_CHECK();
819
820 /* Attach the display. */
821 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
822 rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay"); RC_CHECK();
823 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
824 Display *pDisplay = pConsole->mDisplay;
825 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pDisplay); RC_CHECK();
826
827
828 /*
829 * Firmware.
830 */
831 FirmwareType_T eFwType = FirmwareType_BIOS;
832 hrc = pMachine->COMGETTER(FirmwareType)(&eFwType); H();
833
834#ifdef VBOX_WITH_EFI
835 BOOL fEfiEnabled = (eFwType >= FirmwareType_EFI) && (eFwType <= FirmwareType_EFIDUAL);
836#else
837 BOOL fEfiEnabled = false;
838#endif
839 if (!fEfiEnabled)
840 {
841 /*
842 * PC Bios.
843 */
844 rc = CFGMR3InsertNode(pDevices, "pcbios", &pDev); RC_CHECK();
845 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
846 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
847 rc = CFGMR3InsertNode(pInst, "Config", &pBiosCfg); RC_CHECK();
848 rc = CFGMR3InsertInteger(pBiosCfg, "RamSize", cbRam); RC_CHECK();
849 rc = CFGMR3InsertInteger(pBiosCfg, "RamHoleSize", cbRamHole); RC_CHECK();
850 rc = CFGMR3InsertInteger(pBiosCfg, "NumCPUs", cCpus); RC_CHECK();
851 rc = CFGMR3InsertString(pBiosCfg, "HardDiskDevice", "piix3ide"); RC_CHECK();
852 rc = CFGMR3InsertString(pBiosCfg, "FloppyDevice", "i82078"); RC_CHECK();
853 rc = CFGMR3InsertInteger(pBiosCfg, "IOAPIC", fIOAPIC); RC_CHECK();
854 rc = CFGMR3InsertInteger(pBiosCfg, "PXEDebug", fPXEDebug); RC_CHECK();
855 rc = CFGMR3InsertBytes(pBiosCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));RC_CHECK();
856
857 DeviceType_T bootDevice;
858 if (SchemaDefs::MaxBootPosition > 9)
859 {
860 AssertMsgFailed (("Too many boot devices %d\n",
861 SchemaDefs::MaxBootPosition));
862 return VERR_INVALID_PARAMETER;
863 }
864
865 for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; ++pos)
866 {
867 hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
868
869 char szParamName[] = "BootDeviceX";
870 szParamName[sizeof (szParamName) - 2] = ((char (pos - 1)) + '0');
871
872 const char *pszBootDevice;
873 switch (bootDevice)
874 {
875 case DeviceType_Null:
876 pszBootDevice = "NONE";
877 break;
878 case DeviceType_HardDisk:
879 pszBootDevice = "IDE";
880 break;
881 case DeviceType_DVD:
882 pszBootDevice = "DVD";
883 break;
884 case DeviceType_Floppy:
885 pszBootDevice = "FLOPPY";
886 break;
887 case DeviceType_Network:
888 pszBootDevice = "LAN";
889 break;
890 default:
891 AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
892 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
893 N_("Invalid boot device '%d'"), bootDevice);
894 }
895 rc = CFGMR3InsertString(pBiosCfg, szParamName, pszBootDevice); RC_CHECK();
896 }
897 }
898 else
899 {
900 Utf8Str efiRomFile;
901
902 /* Autodetect firmware type, basing on guest type */
903 if (eFwType == FirmwareType_EFI)
904 {
905 eFwType =
906 fIs64BitGuest ?
907 (FirmwareType_T)FirmwareType_EFI64
908 :
909 (FirmwareType_T)FirmwareType_EFI32;
910 }
911 bool f64BitEntry = eFwType == FirmwareType_EFI64;
912
913 rc = findEfiRom(virtualBox, eFwType, efiRomFile); RC_CHECK();
914
915 /* Get boot args */
916 Bstr bootArgs;
917 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiBootArgs"), bootArgs.asOutParam()); H();
918
919 /* Get device props */
920 Bstr deviceProps;
921 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiDeviceProps"), deviceProps.asOutParam()); H();
922 /* Get GOP mode settings */
923 STR_FREE();
924 uint32_t u32GopMode = UINT32_MAX;
925 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiGopMode"), &str); H();
926 if (str && *str)
927 {
928 u32GopMode = Utf8Str(str).toUInt32();
929 }
930 /* UGA mode settings */
931 STR_FREE();
932 uint32_t u32UgaHorisontal = 0;
933 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaHorizontalResolution"), &str); H();
934 if (str && *str)
935 {
936 u32UgaHorisontal = Utf8Str(str).toUInt32();
937 }
938
939 STR_FREE();
940 uint32_t u32UgaVertical = 0;
941 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaVerticalResolution"), &str); H();
942 if (str && *str)
943 {
944 u32UgaVertical = Utf8Str(str).toUInt32();
945 }
946 STR_FREE();
947
948 /*
949 * EFI subtree.
950 */
951 rc = CFGMR3InsertNode(pDevices, "efi", &pDev); RC_CHECK();
952 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
953 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
954 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
955 rc = CFGMR3InsertInteger(pCfg, "RamSize", cbRam); RC_CHECK();
956 rc = CFGMR3InsertInteger(pCfg, "RamHoleSize", cbRamHole); RC_CHECK();
957 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
958 rc = CFGMR3InsertString(pCfg, "EfiRom", efiRomFile.raw()); RC_CHECK();
959 rc = CFGMR3InsertString(pCfg, "BootArgs", Utf8Str(bootArgs).raw());RC_CHECK();
960 rc = CFGMR3InsertString(pCfg, "DeviceProps", Utf8Str(deviceProps).raw());RC_CHECK();
961 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
962 rc = CFGMR3InsertBytes(pCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));RC_CHECK();
963 rc = CFGMR3InsertInteger(pCfg, "64BitEntry", f64BitEntry); /* boolean */ RC_CHECK();
964 rc = CFGMR3InsertInteger(pCfg, "GopMode", u32GopMode); RC_CHECK();
965 rc = CFGMR3InsertInteger(pCfg, "UgaHorizontalResolution", u32UgaHorisontal); RC_CHECK();
966 rc = CFGMR3InsertInteger(pCfg, "UgaVerticalResolution", u32UgaVertical); RC_CHECK();
967
968 /* For OS X guests we'll force passing host's DMI info to the guest */
969 if (fExtProfile)
970 {
971 rc = CFGMR3InsertInteger(pCfg, "DmiUseHostInfo", 1); RC_CHECK();
972 }
973 }
974
975 /*
976 * Storage controllers.
977 */
978 com::SafeIfaceArray<IStorageController> ctrls;
979 PCFGMNODE aCtrlNodes[StorageControllerType_LsiLogicSas + 1] = {};
980 hrc = pMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(ctrls)); H();
981
982 for (size_t i = 0; i < ctrls.size(); ++ i)
983 {
984 DeviceType_T *paLedDevType = NULL;
985
986 StorageControllerType_T enmCtrlType;
987 rc = ctrls[i]->COMGETTER(ControllerType)(&enmCtrlType); H();
988 AssertRelease((unsigned)enmCtrlType < RT_ELEMENTS(aCtrlNodes));
989
990 StorageBus_T enmBus;
991 rc = ctrls[i]->COMGETTER(Bus)(&enmBus); H();
992
993 Bstr controllerName;
994 rc = ctrls[i]->COMGETTER(Name)(controllerName.asOutParam()); H();
995
996 ULONG ulInstance = 999;
997 rc = ctrls[i]->COMGETTER(Instance)(&ulInstance); H();
998
999 /* /Devices/<ctrldev>/ */
1000 const char *pszCtrlDev = pConsole->convertControllerTypeToDev(enmCtrlType);
1001 pDev = aCtrlNodes[enmCtrlType];
1002 if (!pDev)
1003 {
1004 rc = CFGMR3InsertNode(pDevices, pszCtrlDev, &pDev); RC_CHECK();
1005 aCtrlNodes[enmCtrlType] = pDev; /* IDE variants are handled in the switch */
1006 }
1007
1008 /* /Devices/<ctrldev>/<instance>/ */
1009 PCFGMNODE pCtlInst = NULL;
1010 rc = CFGMR3InsertNodeF(pDev, &pCtlInst, "%u", ulInstance); RC_CHECK();
1011
1012 /* Device config: /Devices/<ctrldev>/<instance>/<values> & /ditto/Config/<values> */
1013 rc = CFGMR3InsertInteger(pCtlInst, "Trusted", 1); RC_CHECK();
1014 rc = CFGMR3InsertNode(pCtlInst, "Config", &pCfg); RC_CHECK();
1015
1016 switch (enmCtrlType)
1017 {
1018 case StorageControllerType_LsiLogic:
1019 {
1020 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 20); RC_CHECK();
1021 Assert(!afPciDeviceNo[20]);
1022 afPciDeviceNo[20] = true;
1023 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
1024
1025 /* Attach the status driver */
1026 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
1027 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1028 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1029 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedScsi]); RC_CHECK();
1030 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1031 Assert(cLedScsi >= 16);
1032 rc = CFGMR3InsertInteger(pCfg, "Last", 15); RC_CHECK();
1033 paLedDevType = &pConsole->maStorageDevType[iLedScsi];
1034 break;
1035 }
1036
1037 case StorageControllerType_BusLogic:
1038 {
1039 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 21); RC_CHECK();
1040 Assert(!afPciDeviceNo[21]);
1041 afPciDeviceNo[21] = true;
1042 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
1043
1044 /* Attach the status driver */
1045 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
1046 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1047 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1048 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedScsi]); RC_CHECK();
1049 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1050 Assert(cLedScsi >= 16);
1051 rc = CFGMR3InsertInteger(pCfg, "Last", 15); RC_CHECK();
1052 paLedDevType = &pConsole->maStorageDevType[iLedScsi];
1053 break;
1054 }
1055
1056 case StorageControllerType_IntelAhci:
1057 {
1058 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 13); RC_CHECK();
1059 Assert(!afPciDeviceNo[13]);
1060 afPciDeviceNo[13] = true;
1061 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
1062
1063 ULONG cPorts = 0;
1064 hrc = ctrls[i]->COMGETTER(PortCount)(&cPorts); H();
1065 rc = CFGMR3InsertInteger(pCfg, "PortCount", cPorts); RC_CHECK();
1066
1067 /* Needed configuration values for the bios. */
1068 if (pBiosCfg)
1069 {
1070 rc = CFGMR3InsertString(pBiosCfg, "SataHardDiskDevice", "ahci"); RC_CHECK();
1071 }
1072
1073 for (uint32_t j = 0; j < 4; ++j)
1074 {
1075 static const char * const s_apszConfig[4] =
1076 { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
1077 static const char * const s_apszBiosConfig[4] =
1078 { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
1079
1080 LONG lPortNumber = -1;
1081 hrc = ctrls[i]->GetIDEEmulationPort(j, &lPortNumber); H();
1082 rc = CFGMR3InsertInteger(pCfg, s_apszConfig[j], lPortNumber); RC_CHECK();
1083 if (pBiosCfg)
1084 {
1085 rc = CFGMR3InsertInteger(pBiosCfg, s_apszBiosConfig[j], lPortNumber); RC_CHECK();
1086 }
1087 }
1088
1089 /* Attach the status driver */
1090 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
1091 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1092 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1093 AssertRelease(cPorts <= cLedSata);
1094 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedSata]); RC_CHECK();
1095 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1096 rc = CFGMR3InsertInteger(pCfg, "Last", cPorts - 1); RC_CHECK();
1097 paLedDevType = &pConsole->maStorageDevType[iLedSata];
1098 break;
1099 }
1100
1101 case StorageControllerType_PIIX3:
1102 case StorageControllerType_PIIX4:
1103 case StorageControllerType_ICH6:
1104 {
1105 /*
1106 * IDE (update this when the main interface changes)
1107 */
1108 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 1); RC_CHECK();
1109 Assert(!afPciDeviceNo[1]);
1110 afPciDeviceNo[1] = true;
1111 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 1); RC_CHECK();
1112 rc = CFGMR3InsertString(pCfg, "Type", controllerString(enmCtrlType)); RC_CHECK();
1113
1114 /* Attach the status driver */
1115 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
1116 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1117 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1118 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedIde]); RC_CHECK();
1119 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1120 Assert(cLedIde >= 4);
1121 rc = CFGMR3InsertInteger(pCfg, "Last", 3); RC_CHECK();
1122 paLedDevType = &pConsole->maStorageDevType[iLedIde];
1123
1124 /* IDE flavors */
1125 aCtrlNodes[StorageControllerType_PIIX3] = pDev;
1126 aCtrlNodes[StorageControllerType_PIIX4] = pDev;
1127 aCtrlNodes[StorageControllerType_ICH6] = pDev;
1128 break;
1129 }
1130
1131 case StorageControllerType_I82078:
1132 {
1133 /*
1134 * i82078 Floppy drive controller
1135 */
1136 fFdcEnabled = true;
1137 rc = CFGMR3InsertInteger(pCfg, "IRQ", 6); RC_CHECK();
1138 rc = CFGMR3InsertInteger(pCfg, "DMA", 2); RC_CHECK();
1139 rc = CFGMR3InsertInteger(pCfg, "MemMapped", 0 ); RC_CHECK();
1140 rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x3f0); RC_CHECK();
1141
1142 /* Attach the status driver */
1143 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
1144 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1145 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1146 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedFloppy]); RC_CHECK();
1147 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1148 Assert(cLedFloppy >= 1);
1149 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1150 paLedDevType = &pConsole->maStorageDevType[iLedFloppy];
1151 break;
1152 }
1153
1154 case StorageControllerType_LsiLogicSas:
1155 {
1156 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 21); RC_CHECK();
1157 Assert(!afPciDeviceNo[21]);
1158 afPciDeviceNo[21] = true;
1159 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
1160
1161 rc = CFGMR3InsertString(pCfg, "ControllerType", "SAS1068"); RC_CHECK();
1162
1163 /* Attach the status driver */
1164 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
1165 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1166 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1167 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedScsi]); RC_CHECK();
1168 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1169 Assert(cLedScsi >= 16);
1170 rc = CFGMR3InsertInteger(pCfg, "Last", 15) ; RC_CHECK();
1171 paLedDevType = &pConsole->maStorageDevType[iLedScsi];
1172 break;
1173 }
1174
1175 default:
1176 AssertMsgFailedReturn(("invalid storage controller type: %d\n", enmCtrlType), VERR_GENERAL_FAILURE);
1177 }
1178
1179 /* Attach the media to the storage controllers. */
1180 com::SafeIfaceArray<IMediumAttachment> atts;
1181 hrc = pMachine->GetMediumAttachmentsOfController(controllerName,
1182 ComSafeArrayAsOutParam(atts)); H();
1183
1184 for (size_t j = 0; j < atts.size(); ++j)
1185 {
1186 ComPtr<IMedium> medium;
1187 hrc = atts[j]->COMGETTER(Medium)(medium.asOutParam()); H();
1188 LONG lDev;
1189 hrc = atts[j]->COMGETTER(Device)(&lDev); H();
1190 LONG lPort;
1191 hrc = atts[j]->COMGETTER(Port)(&lPort); H();
1192 DeviceType_T lType;
1193 hrc = atts[j]->COMGETTER(Type)(&lType); H();
1194
1195 unsigned uLUN;
1196 hrc = pConsole->convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN); H();
1197 rc = CFGMR3InsertNodeF(pCtlInst, &pLunL0, "LUN#%u", uLUN); RC_CHECK();
1198
1199 /* SCSI has a another driver between device and block. */
1200 if (enmBus == StorageBus_SCSI || enmBus == StorageBus_SAS)
1201 {
1202 rc = CFGMR3InsertString(pLunL0, "Driver", "SCSI"); RC_CHECK();
1203 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1204
1205 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1206 }
1207
1208 BOOL fHostDrive = FALSE;
1209 if (!medium.isNull())
1210 {
1211 hrc = medium->COMGETTER(HostDrive)(&fHostDrive); H();
1212 }
1213
1214 if (fHostDrive)
1215 {
1216 Assert(!medium.isNull());
1217 if (lType == DeviceType_DVD)
1218 {
1219 rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
1220 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1221
1222 hrc = medium->COMGETTER(Location)(&str); H();
1223 rc = CFGMR3InsertStringW(pCfg, "Path", str); RC_CHECK();
1224 STR_FREE();
1225
1226 BOOL fPassthrough;
1227 hrc = atts[j]->COMGETTER(Passthrough)(&fPassthrough); H();
1228 rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough); RC_CHECK();
1229 }
1230 else if (lType == DeviceType_Floppy)
1231 {
1232 rc = CFGMR3InsertString(pLunL0, "Driver", "HostFloppy"); RC_CHECK();
1233 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1234
1235 hrc = medium->COMGETTER(Location)(&str); H();
1236 rc = CFGMR3InsertStringW(pCfg, "Path", str); RC_CHECK();
1237 STR_FREE();
1238 }
1239 }
1240 else
1241 {
1242 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
1243 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1244 switch (lType)
1245 {
1246 case DeviceType_DVD:
1247 rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
1248 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
1249 break;
1250 case DeviceType_Floppy:
1251 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
1252 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
1253 break;
1254 case DeviceType_HardDisk:
1255 default:
1256 rc = CFGMR3InsertString(pCfg, "Type", "HardDisk"); RC_CHECK();
1257 rc = CFGMR3InsertInteger(pCfg, "Mountable", 0); RC_CHECK();
1258 }
1259
1260 if (!medium.isNull())
1261 {
1262 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1263 rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
1264 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
1265
1266 hrc = medium->COMGETTER(Location)(&str); H();
1267 rc = CFGMR3InsertStringW(pCfg, "Path", str); RC_CHECK();
1268 STR_FREE();
1269
1270 hrc = medium->COMGETTER(Format)(&str); H();
1271 rc = CFGMR3InsertStringW(pCfg, "Format", str); RC_CHECK();
1272 STR_FREE();
1273
1274 /* DVDs are always readonly */
1275 if (lType == DeviceType_DVD)
1276 {
1277 rc = CFGMR3InsertInteger(pCfg, "ReadOnly", 1); RC_CHECK();
1278 }
1279 /* Start without exclusive write access to the images. */
1280 /** @todo Live Migration: I don't quite like this, we risk screwing up when
1281 * we're resuming the VM if some 3rd dude have any of the VDIs open
1282 * with write sharing denied. However, if the two VMs are sharing a
1283 * image it really is necessary....
1284 *
1285 * So, on the "lock-media" command, the target teleporter should also
1286 * make DrvVD undo TempReadOnly. It gets interesting if we fail after
1287 * that. Grumble. */
1288 else if (pConsole->mMachineState == MachineState_TeleportingIn)
1289 {
1290 rc = CFGMR3InsertInteger(pCfg, "TempReadOnly", 1); RC_CHECK();
1291 }
1292
1293 /* Pass all custom parameters. */
1294 bool fHostIP = true;
1295 SafeArray<BSTR> names;
1296 SafeArray<BSTR> values;
1297 hrc = medium->GetProperties(NULL,
1298 ComSafeArrayAsOutParam(names),
1299 ComSafeArrayAsOutParam(values)); H();
1300
1301 if (names.size() != 0)
1302 {
1303 PCFGMNODE pVDC;
1304 rc = CFGMR3InsertNode(pCfg, "VDConfig", &pVDC); RC_CHECK();
1305 for (size_t ii = 0; ii < names.size(); ++ii)
1306 {
1307 if (values[ii] && *values[ii])
1308 {
1309 Utf8Str name = names[ii];
1310 Utf8Str value = values[ii];
1311 rc = CFGMR3InsertString(pVDC, name.c_str(), value.c_str()); RC_CHECK();
1312 if ( name.compare("HostIPStack") == 0
1313 && value.compare("0") == 0)
1314 fHostIP = false;
1315 }
1316 }
1317 }
1318
1319 /* Create an inversed tree of parents. */
1320 ComPtr<IMedium> parentMedium = medium;
1321 for (PCFGMNODE pParent = pCfg;;)
1322 {
1323 hrc = parentMedium->COMGETTER(Parent)(medium.asOutParam()); H();
1324 if (medium.isNull())
1325 break;
1326
1327 PCFGMNODE pCur;
1328 rc = CFGMR3InsertNode(pParent, "Parent", &pCur); RC_CHECK();
1329 hrc = medium->COMGETTER(Location)(&str); H();
1330 rc = CFGMR3InsertStringW(pCur, "Path", str); RC_CHECK();
1331 STR_FREE();
1332
1333 hrc = medium->COMGETTER(Format)(&str); H();
1334 rc = CFGMR3InsertStringW(pCur, "Format", str); RC_CHECK();
1335 STR_FREE();
1336
1337 /* Pass all custom parameters. */
1338 SafeArray<BSTR> aNames;
1339 SafeArray<BSTR> aValues;
1340 hrc = medium->GetProperties(NULL,
1341 ComSafeArrayAsOutParam(aNames),
1342 ComSafeArrayAsOutParam(aValues)); H();
1343
1344 if (aNames.size() != 0)
1345 {
1346 PCFGMNODE pVDC;
1347 rc = CFGMR3InsertNode(pCur, "VDConfig", &pVDC); RC_CHECK();
1348 for (size_t ii = 0; ii < aNames.size(); ++ii)
1349 {
1350 if (aValues[ii] && *aValues[ii])
1351 {
1352 Utf8Str name = aNames[ii];
1353 Utf8Str value = aValues[ii];
1354 rc = CFGMR3InsertString(pVDC, name.c_str(), value.c_str()); RC_CHECK();
1355 if ( name.compare("HostIPStack") == 0
1356 && value.compare("0") == 0)
1357 fHostIP = false;
1358 }
1359 }
1360 }
1361
1362 /* Custom code: put marker to not use host IP stack to driver
1363 * configuration node. Simplifies life of DrvVD a bit. */
1364 if (!fHostIP)
1365 {
1366 rc = CFGMR3InsertInteger(pCfg, "HostIPStack", 0); RC_CHECK();
1367 }
1368
1369 /* next */
1370 pParent = pCur;
1371 parentMedium = medium;
1372 }
1373 }
1374 }
1375
1376 if (paLedDevType)
1377 paLedDevType[uLUN] = lType;
1378 }
1379 H();
1380 }
1381 H();
1382
1383 /*
1384 * Network adapters
1385 */
1386#ifdef VMWARE_NET_IN_SLOT_11
1387 bool fSwapSlots3and11 = false;
1388#endif
1389 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
1390 rc = CFGMR3InsertNode(pDevices, "pcnet", &pDevPCNet); RC_CHECK();
1391#ifdef VBOX_WITH_E1000
1392 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
1393 rc = CFGMR3InsertNode(pDevices, "e1000", &pDevE1000); RC_CHECK();
1394#endif
1395#ifdef VBOX_WITH_VIRTIO
1396 PCFGMNODE pDevVirtioNet = NULL; /* Virtio network devices */
1397 rc = CFGMR3InsertNode(pDevices, "virtio-net", &pDevVirtioNet); RC_CHECK();
1398#endif /* VBOX_WITH_VIRTIO */
1399 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ++ulInstance)
1400 {
1401 ComPtr<INetworkAdapter> networkAdapter;
1402 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
1403 BOOL fEnabled = FALSE;
1404 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
1405 if (!fEnabled)
1406 continue;
1407
1408 /*
1409 * The virtual hardware type. Create appropriate device first.
1410 */
1411 const char *pszAdapterName = "pcnet";
1412 NetworkAdapterType_T adapterType;
1413 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
1414 switch (adapterType)
1415 {
1416 case NetworkAdapterType_Am79C970A:
1417 case NetworkAdapterType_Am79C973:
1418 pDev = pDevPCNet;
1419 break;
1420#ifdef VBOX_WITH_E1000
1421 case NetworkAdapterType_I82540EM:
1422 case NetworkAdapterType_I82543GC:
1423 case NetworkAdapterType_I82545EM:
1424 pDev = pDevE1000;
1425 pszAdapterName = "e1000";
1426 break;
1427#endif
1428#ifdef VBOX_WITH_VIRTIO
1429 case NetworkAdapterType_Virtio:
1430 pDev = pDevVirtioNet;
1431 pszAdapterName = "virtio-net";
1432 break;
1433#endif /* VBOX_WITH_VIRTIO */
1434 default:
1435 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
1436 adapterType, ulInstance));
1437 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1438 N_("Invalid network adapter type '%d' for slot '%d'"),
1439 adapterType, ulInstance);
1440 }
1441
1442 rc = CFGMR3InsertNodeF(pDev, &pInst, "%u", ulInstance); RC_CHECK();
1443 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1444 /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
1445 * next 4 get 16..19. */
1446 unsigned iPciDeviceNo = 3;
1447 if (ulInstance)
1448 {
1449 if (ulInstance < 4)
1450 iPciDeviceNo = ulInstance - 1 + 8;
1451 else
1452 iPciDeviceNo = ulInstance - 4 + 16;
1453 }
1454#ifdef VMWARE_NET_IN_SLOT_11
1455 /*
1456 * Dirty hack for PCI slot compatibility with VMWare,
1457 * it assigns slot 11 to the first network controller.
1458 */
1459 if (iPciDeviceNo == 3 && adapterType == NetworkAdapterType_I82545EM)
1460 {
1461 iPciDeviceNo = 0x11;
1462 fSwapSlots3and11 = true;
1463 }
1464 else if (iPciDeviceNo == 0x11 && fSwapSlots3and11)
1465 iPciDeviceNo = 3;
1466#endif
1467 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
1468 Assert(!afPciDeviceNo[iPciDeviceNo]);
1469 afPciDeviceNo[iPciDeviceNo] = true;
1470 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1471 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1472#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
1473 if (pDev == pDevPCNet)
1474 {
1475 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", false); RC_CHECK();
1476 }
1477#endif
1478
1479 /*
1480 * The virtual hardware type. PCNet supports two types.
1481 */
1482 switch (adapterType)
1483 {
1484 case NetworkAdapterType_Am79C970A:
1485 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
1486 break;
1487 case NetworkAdapterType_Am79C973:
1488 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
1489 break;
1490 case NetworkAdapterType_I82540EM:
1491 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
1492 break;
1493 case NetworkAdapterType_I82543GC:
1494 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
1495 break;
1496 case NetworkAdapterType_I82545EM:
1497 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 2); RC_CHECK();
1498 break;
1499 }
1500
1501 /*
1502 * Get the MAC address and convert it to binary representation
1503 */
1504 Bstr macAddr;
1505 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1506 Assert(macAddr);
1507 Utf8Str macAddrUtf8 = macAddr;
1508 char *macStr = (char*)macAddrUtf8.raw();
1509 Assert(strlen(macStr) == 12);
1510 RTMAC Mac;
1511 memset(&Mac, 0, sizeof(Mac));
1512 char *pMac = (char*)&Mac;
1513 for (uint32_t i = 0; i < 6; ++i)
1514 {
1515 char c1 = *macStr++ - '0';
1516 if (c1 > 9)
1517 c1 -= 7;
1518 char c2 = *macStr++ - '0';
1519 if (c2 > 9)
1520 c2 -= 7;
1521 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1522 }
1523 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1524
1525 /*
1526 * Check if the cable is supposed to be unplugged
1527 */
1528 BOOL fCableConnected;
1529 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1530 rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
1531
1532 /*
1533 * Line speed to report from custom drivers
1534 */
1535 ULONG ulLineSpeed;
1536 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1537 rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
1538
1539 /*
1540 * Attach the status driver.
1541 */
1542 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1543 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1544 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1545 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
1546
1547 /*
1548 * Configure the network card now
1549 */
1550 rc = configNetwork(pConsole, pszAdapterName, ulInstance, 0, networkAdapter,
1551 pCfg, pLunL0, pInst, false /*fAttachDetach*/); RC_CHECK();
1552 }
1553
1554 /*
1555 * Serial (UART) Ports
1556 */
1557 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1558 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ++ulInstance)
1559 {
1560 ComPtr<ISerialPort> serialPort;
1561 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1562 BOOL fEnabled = FALSE;
1563 if (serialPort)
1564 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1565 if (!fEnabled)
1566 continue;
1567
1568 rc = CFGMR3InsertNodeF(pDev, &pInst, "%u", ulInstance); RC_CHECK();
1569 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1570
1571 ULONG ulIRQ;
1572 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1573 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1574 ULONG ulIOBase;
1575 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1576 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1577 BOOL fServer;
1578 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1579 hrc = serialPort->COMGETTER(Path)(&str); H();
1580 PortMode_T eHostMode;
1581 hrc = serialPort->COMGETTER(HostMode)(&eHostMode); H();
1582 if (eHostMode != PortMode_Disconnected)
1583 {
1584 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1585 if (eHostMode == PortMode_HostPipe)
1586 {
1587 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1588 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1589 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1590 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1591 rc = CFGMR3InsertStringW(pLunL2, "Location", str); RC_CHECK();
1592 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1593 }
1594 else if (eHostMode == PortMode_HostDevice)
1595 {
1596 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1597 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1598 rc = CFGMR3InsertStringW(pLunL1, "DevicePath", str); RC_CHECK();
1599 }
1600 else if (eHostMode == PortMode_RawFile)
1601 {
1602 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1603 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1604 rc = CFGMR3InsertString(pLunL1, "Driver", "RawFile"); RC_CHECK();
1605 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1606 rc = CFGMR3InsertStringW(pLunL2, "Location", str); RC_CHECK();
1607 }
1608 }
1609 STR_FREE();
1610 }
1611
1612 /*
1613 * Parallel (LPT) Ports
1614 */
1615 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1616 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ++ulInstance)
1617 {
1618 ComPtr<IParallelPort> parallelPort;
1619 hrc = pMachine->GetParallelPort(ulInstance, parallelPort.asOutParam()); H();
1620 BOOL fEnabled = FALSE;
1621 if (parallelPort)
1622 {
1623 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1624 }
1625 if (!fEnabled)
1626 continue;
1627
1628 rc = CFGMR3InsertNodeF(pDev, &pInst, "%u", ulInstance); RC_CHECK();
1629 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1630
1631 ULONG ulIRQ;
1632 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1633 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1634 ULONG ulIOBase;
1635 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1636 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1637 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1638 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1639 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1640 hrc = parallelPort->COMGETTER(Path)(&str); H();
1641 rc = CFGMR3InsertStringW(pLunL1, "DevicePath", str); RC_CHECK();
1642 STR_FREE();
1643 }
1644
1645 /*
1646 * VMM Device
1647 */
1648 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1649 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1650 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1651 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1652 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1653 Assert(!afPciDeviceNo[4]);
1654 afPciDeviceNo[4] = true;
1655 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1656 Bstr hwVersion;
1657 hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
1658 if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
1659 {
1660 CFGMR3InsertInteger(pCfg, "HeapEnabled", 0); RC_CHECK();
1661 }
1662
1663 /* the VMM device's Main driver */
1664 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1665 rc = CFGMR3InsertString(pLunL0, "Driver", "HGCM"); RC_CHECK();
1666 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1667 VMMDev *pVMMDev = pConsole->mVMMDev;
1668 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1669
1670 /*
1671 * Attach the status driver.
1672 */
1673 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1674 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1675 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1676 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1677 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1678 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1679
1680 /*
1681 * Audio Sniffer Device
1682 */
1683 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1684 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1685 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1686
1687 /* the Audio Sniffer device's Main driver */
1688 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1689 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1690 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1691 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1692 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1693
1694 /*
1695 * AC'97 ICH / SoundBlaster16 audio
1696 */
1697 BOOL enabled;
1698 ComPtr<IAudioAdapter> audioAdapter;
1699 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1700 if (audioAdapter)
1701 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1702
1703 if (enabled)
1704 {
1705 AudioControllerType_T audioController;
1706 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
1707 switch (audioController)
1708 {
1709 case AudioControllerType_AC97:
1710 {
1711 /* default: ICH AC97 */
1712 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
1713 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1714 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1715 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1716 Assert(!afPciDeviceNo[5]);
1717 afPciDeviceNo[5] = true;
1718 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1719 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1720 break;
1721 }
1722 case AudioControllerType_SB16:
1723 {
1724 /* legacy SoundBlaster16 */
1725 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
1726 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1727 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1728 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1729 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
1730 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
1731 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
1732 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
1733 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
1734 break;
1735 }
1736 }
1737
1738 /* the Audio driver */
1739 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1740 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1741 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1742
1743 AudioDriverType_T audioDriver;
1744 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1745 switch (audioDriver)
1746 {
1747 case AudioDriverType_Null:
1748 {
1749 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1750 break;
1751 }
1752#ifdef RT_OS_WINDOWS
1753#ifdef VBOX_WITH_WINMM
1754 case AudioDriverType_WinMM:
1755 {
1756 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1757 break;
1758 }
1759#endif
1760 case AudioDriverType_DirectSound:
1761 {
1762 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
1763 break;
1764 }
1765#endif /* RT_OS_WINDOWS */
1766#ifdef RT_OS_SOLARIS
1767 case AudioDriverType_SolAudio:
1768 {
1769 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
1770 break;
1771 }
1772#endif
1773#ifdef RT_OS_LINUX
1774# ifdef VBOX_WITH_ALSA
1775 case AudioDriverType_ALSA:
1776 {
1777 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
1778 break;
1779 }
1780# endif
1781# ifdef VBOX_WITH_PULSE
1782 case AudioDriverType_Pulse:
1783 {
1784 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
1785 break;
1786 }
1787# endif
1788#endif /* RT_OS_LINUX */
1789#if defined (RT_OS_LINUX) || defined (RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
1790 case AudioDriverType_OSS:
1791 {
1792 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
1793 break;
1794 }
1795#endif
1796#ifdef RT_OS_FREEBSD
1797# ifdef VBOX_WITH_PULSE
1798 case AudioDriverType_Pulse:
1799 {
1800 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
1801 break;
1802 }
1803# endif
1804#endif
1805#ifdef RT_OS_DARWIN
1806 case AudioDriverType_CoreAudio:
1807 {
1808 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1809 break;
1810 }
1811#endif
1812 }
1813 hrc = pMachine->COMGETTER(Name)(&str); H();
1814 rc = CFGMR3InsertStringW(pCfg, "StreamName", str); RC_CHECK();
1815 STR_FREE();
1816 }
1817
1818 /*
1819 * The USB Controller.
1820 */
1821 ComPtr<IUSBController> USBCtlPtr;
1822 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1823 if (USBCtlPtr)
1824 {
1825 BOOL fEnabled;
1826 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1827 if (fEnabled)
1828 {
1829 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
1830 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1831 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1832 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1833 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
1834 Assert(!afPciDeviceNo[6]);
1835 afPciDeviceNo[6] = true;
1836 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1837
1838 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1839 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1840 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1841
1842 /*
1843 * Attach the status driver.
1844 */
1845 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1846 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1847 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1848 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
1849 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1850 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1851
1852 PCFGMNODE pUsbDevices = NULL;
1853#ifdef VBOX_WITH_EHCI
1854 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
1855 if (fEnabled)
1856 {
1857 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
1858 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1859 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1860 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1861 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
1862 Assert(!afPciDeviceNo[11]);
1863 afPciDeviceNo[11] = true;
1864 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1865
1866 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1867 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1868 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1869
1870 /*
1871 * Attach the status driver.
1872 */
1873 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1874 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1875 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1876 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
1877 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1878 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1879 }
1880 else
1881#endif
1882 {
1883 /*
1884 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
1885 * on a per device level now.
1886 */
1887 rc = CFGMR3InsertNode(pRoot, "USB", &pUsbDevices); RC_CHECK();
1888 rc = CFGMR3InsertNode(pUsbDevices, "USBProxy", &pCfg); RC_CHECK();
1889 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
1890 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
1891 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
1892 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
1893 // that it's documented somewhere.) Users needing it can use:
1894 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
1895 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
1896 }
1897
1898#if 1 /* Enable+edit this to play with the virtual USB devices). */
1899 if (!pUsbDevices)
1900 {
1901 rc = CFGMR3InsertNode(pRoot, "USB", &pUsbDevices); RC_CHECK();
1902 }
1903
1904# if 0 /* Virtual MSD*/
1905
1906 rc = CFGMR3InsertNode(pUsbDevices, "Msd", &pDev); RC_CHECK();
1907 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1908 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1909 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1910
1911 rc = CFGMR3InsertString(pLunL0, "Driver", "SCSI"); RC_CHECK();
1912 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1913
1914 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1915 rc = CFGMR3InsertString(pLunL1, "Driver", "Block"); RC_CHECK();
1916 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
1917 rc = CFGMR3InsertString(pCfg, "Type", "HardDisk"); RC_CHECK();
1918 rc = CFGMR3InsertInteger(pCfg, "Mountable", 0); RC_CHECK();
1919
1920 rc = CFGMR3InsertNode(pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
1921 rc = CFGMR3InsertString(pLunL2, "Driver", "VD"); RC_CHECK();
1922 rc = CFGMR3InsertNode(pLunL2, "Config", &pCfg); RC_CHECK();
1923 rc = CFGMR3InsertString(pCfg, "Path", "/Volumes/DataHFS/bird/VDIs/linux.vdi"); RC_CHECK();
1924 rc = CFGMR3InsertString(pCfg, "Format", "VDI"); RC_CHECK();
1925# endif
1926
1927 /* Virtual USB Mouse/Tablet */
1928 PointingHidType_T aPointingHid;
1929 hrc = pMachine->COMGETTER(PointingHidType)(&aPointingHid); H();
1930 if (aPointingHid == PointingHidType_USBMouse || aPointingHid == PointingHidType_USBTablet)
1931 {
1932 rc = CFGMR3InsertNode(pUsbDevices, "HidMouse", &pDev); RC_CHECK();
1933 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1934 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1935
1936 if (aPointingHid == PointingHidType_USBTablet)
1937 {
1938 rc = CFGMR3InsertInteger(pCfg, "Absolute", 1); RC_CHECK();
1939 }
1940 else
1941 {
1942 rc = CFGMR3InsertInteger(pCfg, "Absolute", 0); RC_CHECK();
1943 }
1944 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1945 rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); RC_CHECK();
1946 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1947 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); RC_CHECK();
1948
1949 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1950 rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse"); RC_CHECK();
1951 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
1952 pMouse = pConsole->mMouse;
1953 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse); RC_CHECK();
1954 }
1955
1956 /* Virtual USB Keyboard */
1957 KeyboardHidType_T aKbdHid;
1958 hrc = pMachine->COMGETTER(KeyboardHidType)(&aKbdHid); H();
1959 if (aKbdHid == KeyboardHidType_USBKeyboard)
1960 {
1961 rc = CFGMR3InsertNode(pUsbDevices, "HidKeyboard", &pDev); RC_CHECK();
1962 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1963 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1964
1965 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1966 rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); RC_CHECK();
1967 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1968 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); RC_CHECK();
1969
1970 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1971 rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard"); RC_CHECK();
1972 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
1973 pKeyboard = pConsole->mKeyboard;
1974 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pKeyboard); RC_CHECK();
1975 }
1976#endif
1977 }
1978 }
1979
1980 /*
1981 * Clipboard
1982 */
1983 {
1984 ClipboardMode_T mode = ClipboardMode_Disabled;
1985 hrc = pMachine->COMGETTER(ClipboardMode)(&mode); H();
1986
1987 if (mode != ClipboardMode_Disabled)
1988 {
1989 /* Load the service */
1990 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
1991
1992 if (RT_FAILURE(rc))
1993 {
1994 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
1995 /* That is not a fatal failure. */
1996 rc = VINF_SUCCESS;
1997 }
1998 else
1999 {
2000 /* Setup the service. */
2001 VBOXHGCMSVCPARM parm;
2002
2003 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2004
2005 switch (mode)
2006 {
2007 default:
2008 case ClipboardMode_Disabled:
2009 {
2010 LogRel(("VBoxSharedClipboard mode: Off\n"));
2011 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
2012 break;
2013 }
2014 case ClipboardMode_GuestToHost:
2015 {
2016 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
2017 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
2018 break;
2019 }
2020 case ClipboardMode_HostToGuest:
2021 {
2022 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
2023 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
2024 break;
2025 }
2026 case ClipboardMode_Bidirectional:
2027 {
2028 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
2029 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
2030 break;
2031 }
2032 }
2033
2034 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
2035
2036 Log(("Set VBoxSharedClipboard mode\n"));
2037 }
2038 }
2039 }
2040
2041#ifdef VBOX_WITH_CROGL
2042 /*
2043 * crOpenGL
2044 */
2045 {
2046 BOOL fEnabled = false;
2047 hrc = pMachine->COMGETTER(Accelerate3DEnabled)(&fEnabled); H();
2048
2049 if (fEnabled)
2050 {
2051 /* Load the service */
2052 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
2053 if (RT_FAILURE(rc))
2054 {
2055 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
2056 /* That is not a fatal failure. */
2057 rc = VINF_SUCCESS;
2058 }
2059 else
2060 {
2061 LogRel(("Shared crOpenGL service loaded.\n"));
2062
2063 /* Setup the service. */
2064 VBOXHGCMSVCPARM parm;
2065 parm.type = VBOX_HGCM_SVC_PARM_PTR;
2066
2067 parm.u.pointer.addr = pConsole->getDisplay()->getFramebuffer();
2068 parm.u.pointer.size = sizeof(IFramebuffer *);
2069
2070 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_FRAMEBUFFER, 1, &parm);
2071 if (!RT_SUCCESS(rc))
2072 AssertMsgFailed(("SHCRGL_HOST_FN_SET_FRAMEBUFFER failed with %Rrc\n", rc));
2073
2074 parm.u.pointer.addr = pVM;
2075 parm.u.pointer.size = sizeof(pVM);
2076 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VM, 1, &parm);
2077 if (!RT_SUCCESS(rc))
2078 AssertMsgFailed(("SHCRGL_HOST_FN_SET_VM failed with %Rrc\n", rc));
2079 }
2080
2081 }
2082 }
2083#endif
2084
2085#ifdef VBOX_WITH_GUEST_PROPS
2086 /*
2087 * Guest property service
2088 */
2089
2090 rc = configGuestProperties(pConsole);
2091#endif /* VBOX_WITH_GUEST_PROPS defined */
2092
2093 /*
2094 * ACPI
2095 */
2096 BOOL fACPI;
2097 hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
2098 if (fACPI)
2099 {
2100 BOOL fCpuHotPlug = false;
2101 BOOL fShowCpu = fExtProfile;
2102 /* Always show the CPU leafs when we have multiple VCPUs or when the IO-APIC is enabled.
2103 * The Windows SMP kernel needs a CPU leaf or else its idle loop will burn cpu cycles; the
2104 * intelppm driver refuses to register an idle state handler.
2105 */
2106 if ((cCpus > 1) || fIOAPIC)
2107 fShowCpu = true;
2108
2109 hrc = pMachine->COMGETTER(CPUHotPlugEnabled)(&fCpuHotPlug); H();
2110
2111 rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); RC_CHECK();
2112 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2113 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
2114 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2115 rc = CFGMR3InsertInteger(pCfg, "RamSize", cbRam); RC_CHECK();
2116 rc = CFGMR3InsertInteger(pCfg, "RamHoleSize", cbRamHole); RC_CHECK();
2117 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
2118
2119 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
2120 rc = CFGMR3InsertInteger(pCfg, "FdcEnabled", fFdcEnabled); RC_CHECK();
2121 rc = CFGMR3InsertInteger(pCfg, "HpetEnabled", fHpetEnabled); RC_CHECK();
2122#ifdef VBOX_WITH_SMC
2123 rc = CFGMR3InsertInteger(pCfg, "SmcEnabled", fSmcEnabled); RC_CHECK();
2124#endif
2125 rc = CFGMR3InsertInteger(pCfg, "ShowRtc", fExtProfile); RC_CHECK();
2126
2127 rc = CFGMR3InsertInteger(pCfg, "ShowCpu", fShowCpu); RC_CHECK();
2128 rc = CFGMR3InsertInteger(pCfg, "CpuHotPlug", fCpuHotPlug); RC_CHECK();
2129 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
2130 Assert(!afPciDeviceNo[7]);
2131 afPciDeviceNo[7] = true;
2132 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2133
2134 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2135 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
2136 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2137
2138 /* Attach the dummy CPU drivers */
2139 for (ULONG iCpuCurr = 1; iCpuCurr < cCpus; iCpuCurr++)
2140 {
2141 BOOL fCpuAttached = true;
2142
2143 if (fCpuHotPlug)
2144 {
2145 hrc = pMachine->GetCPUStatus(iCpuCurr, &fCpuAttached); H();
2146 }
2147
2148 if (fCpuAttached)
2149 {
2150 rc = CFGMR3InsertNodeF(pInst, &pLunL0, "LUN#%u", iCpuCurr); RC_CHECK();
2151 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPICpu"); RC_CHECK();
2152 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2153 }
2154 }
2155 }
2156
2157
2158 /*
2159 * CFGM overlay handling.
2160 *
2161 * Here we check the extra data entries for CFGM values
2162 * and create the nodes and insert the values on the fly. Existing
2163 * values will be removed and reinserted. CFGM is typed, so by default
2164 * we will guess whether it's a string or an integer (byte arrays are
2165 * not currently supported). It's possible to override this autodetection
2166 * by adding "string:", "integer:" or "bytes:" (future).
2167 *
2168 * We first perform a run on global extra data, then on the machine
2169 * extra data to support global settings with local overrides.
2170 *
2171 */
2172 /** @todo add support for removing nodes and byte blobs. */
2173 SafeArray<BSTR> aGlobalExtraDataKeys;
2174 SafeArray<BSTR> aMachineExtraDataKeys;
2175 /*
2176 * Get the next key
2177 */
2178 if (FAILED(hrc = virtualBox->GetExtraDataKeys(ComSafeArrayAsOutParam(aGlobalExtraDataKeys))))
2179 AssertMsgFailed(("VirtualBox::GetExtraDataKeys failed with %Rrc\n", hrc));
2180
2181 // remember the no. of global values so we can call the correct method below
2182 size_t cGlobalValues = aGlobalExtraDataKeys.size();
2183
2184 if (FAILED(hrc = pMachine->GetExtraDataKeys(ComSafeArrayAsOutParam(aMachineExtraDataKeys))))
2185 AssertMsgFailed(("IMachine::GetExtraDataKeys failed with %Rrc\n", hrc));
2186
2187 // build a combined list from global keys...
2188 std::list<Utf8Str> llExtraDataKeys;
2189 size_t i = 0;
2190
2191 for (i = 0; i < aGlobalExtraDataKeys.size(); ++i)
2192 llExtraDataKeys.push_back(Utf8Str(aGlobalExtraDataKeys[i]));
2193 // ... and machine keys
2194 for (i = 0; i < aMachineExtraDataKeys.size(); ++i)
2195 llExtraDataKeys.push_back(Utf8Str(aMachineExtraDataKeys[i]));
2196
2197 i = 0;
2198 for (std::list<Utf8Str>::const_iterator it = llExtraDataKeys.begin();
2199 it != llExtraDataKeys.end();
2200 ++it, ++i)
2201 {
2202 const Utf8Str &strKey = *it;
2203
2204 /*
2205 * We only care about keys starting with "VBoxInternal/" (skip "G:" or "M:")
2206 */
2207 if (!strKey.startsWith("VBoxInternal/"))
2208 continue;
2209
2210 const char *pszExtraDataKey = strKey.raw() + sizeof("VBoxInternal/") - 1;
2211
2212 // get the value
2213 Bstr strExtraDataValue;
2214 if (i < cGlobalValues)
2215 // this is still one of the global values:
2216 hrc = virtualBox->GetExtraData(Bstr(strKey), strExtraDataValue.asOutParam());
2217 else
2218 hrc = pMachine->GetExtraData(Bstr(strKey), strExtraDataValue.asOutParam());
2219 if (FAILED(hrc))
2220 LogRel(("Warning: Cannot get extra data key %s, rc = %Rrc\n", strKey.raw(), hrc));
2221
2222 /*
2223 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2224 * Split the two and get the node, delete the value and create the node
2225 * if necessary.
2226 */
2227 PCFGMNODE pNode;
2228 const char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2229 if (pszCFGMValueName)
2230 {
2231 /* terminate the node and advance to the value (Utf8Str might not
2232 offically like this but wtf) */
2233 *(char*)pszCFGMValueName = '\0';
2234 ++pszCFGMValueName;
2235
2236 /* does the node already exist? */
2237 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2238 if (pNode)
2239 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2240 else
2241 {
2242 /* create the node */
2243 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2244 if (RT_FAILURE(rc))
2245 {
2246 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2247 continue;
2248 }
2249 Assert(pNode);
2250 }
2251 }
2252 else
2253 {
2254 /* root value (no node path). */
2255 pNode = pRoot;
2256 pszCFGMValueName = pszExtraDataKey;
2257 pszExtraDataKey--;
2258 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2259 }
2260
2261 /*
2262 * Now let's have a look at the value.
2263 * Empty strings means that we should remove the value, which we've
2264 * already done above.
2265 */
2266 Utf8Str strCFGMValueUtf8(strExtraDataValue);
2267 const char *pszCFGMValue = strCFGMValueUtf8.raw();
2268 if ( pszCFGMValue
2269 && *pszCFGMValue)
2270 {
2271 uint64_t u64Value;
2272
2273 /* check for type prefix first. */
2274 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
2275 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
2276 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
2277 {
2278 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
2279 if (RT_SUCCESS(rc))
2280 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2281 }
2282 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
2283 rc = VERR_NOT_IMPLEMENTED;
2284 /* auto detect type. */
2285 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
2286 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2287 else
2288 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
2289 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
2290 }
2291 }
2292
2293#undef STR_FREE
2294#undef H
2295#undef RC_CHECK
2296
2297 /* Register VM state change handler */
2298 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2299 AssertRC(rc2);
2300 if (RT_SUCCESS(rc))
2301 rc = rc2;
2302
2303 /* Register VM runtime error handler */
2304 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2305 AssertRC(rc2);
2306 if (RT_SUCCESS(rc))
2307 rc = rc2;
2308
2309 LogFlowFunc (("vrc = %Rrc\n", rc));
2310 LogFlowFuncLeave();
2311
2312 return rc;
2313}
2314
2315/**
2316 * Ellipsis to va_list wrapper for calling setVMRuntimeErrorCallback.
2317 */
2318/*static*/ void Console::setVMRuntimeErrorCallbackF(PVM pVM, void *pvConsole, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
2319{
2320 va_list va;
2321 va_start(va, pszFormat);
2322 setVMRuntimeErrorCallback(pVM, pvConsole, fFlags, pszErrorId, pszFormat, va);
2323 va_end(va);
2324}
2325
2326/**
2327 * Construct the Network configuration tree
2328 *
2329 * @returns VBox status code.
2330 *
2331 * @param pThis Pointer to the Console object.
2332 * @param pszDevice The PDM device name.
2333 * @param uInstance The PDM device instance.
2334 * @param uLun The PDM LUN number of the drive.
2335 * @param aNetworkAdapter The network adapter whose attachment needs to be changed
2336 * @param pCfg Configuration node for the device
2337 * @param pLunL0 To store the pointer to the LUN#0.
2338 * @param pInst The instance CFGM node
2339 * @param fAttachDetach To determine if the network attachment should
2340 * be attached/detached after/before
2341 * configuration.
2342 *
2343 * @note Locks the Console object for writing.
2344 */
2345/*static*/ int Console::configNetwork(Console *pThis, const char *pszDevice,
2346 unsigned uInstance, unsigned uLun,
2347 INetworkAdapter *aNetworkAdapter,
2348 PCFGMNODE pCfg, PCFGMNODE pLunL0,
2349 PCFGMNODE pInst, bool fAttachDetach)
2350{
2351 int rc = VINF_SUCCESS;
2352
2353 AutoCaller autoCaller(pThis);
2354 AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
2355
2356 /*
2357 * Locking the object before doing VMR3* calls is quite safe here, since
2358 * we're on EMT. Write lock is necessary because we indirectly modify the
2359 * meAttachmentType member.
2360 */
2361 AutoWriteLock alock(pThis COMMA_LOCKVAL_SRC_POS);
2362
2363 PVM pVM = pThis->mpVM;
2364 BSTR str = NULL;
2365
2366#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } } while (0)
2367#define RC_CHECK() do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc)); STR_FREE(); return rc; } } while (0)
2368#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
2369
2370 HRESULT hrc;
2371 ComPtr<IMachine> pMachine = pThis->machine();
2372
2373 ComPtr<IVirtualBox> virtualBox;
2374 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam());
2375 H();
2376
2377 ComPtr<IHost> host;
2378 hrc = virtualBox->COMGETTER(Host)(host.asOutParam());
2379 H();
2380
2381 BOOL fSniffer;
2382 hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer);
2383 H();
2384
2385 if (fAttachDetach && fSniffer)
2386 {
2387 const char *pszNetDriver = "IntNet";
2388 if (pThis->meAttachmentType[uInstance] == NetworkAttachmentType_NAT)
2389 pszNetDriver = "NAT";
2390#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
2391 if (pThis->meAttachmentType[uInstance] == NetworkAttachmentType_Bridged)
2392 pszNetDriver = "HostInterface";
2393#endif
2394
2395 rc = PDMR3DriverDetach(pVM, pszDevice, uInstance, uLun, pszNetDriver, 0, 0 /*fFlags*/);
2396 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
2397 rc = VINF_SUCCESS;
2398 AssertLogRelRCReturn(rc, rc);
2399
2400 pLunL0 = CFGMR3GetChildF(pInst, "LUN#%u", uLun);
2401 PCFGMNODE pLunAD = CFGMR3GetChildF(pLunL0, "AttachedDriver");
2402 if (pLunAD)
2403 {
2404 CFGMR3RemoveNode(pLunAD);
2405 }
2406 else
2407 {
2408 CFGMR3RemoveNode(pLunL0);
2409 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2410 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
2411 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2412 hrc = aNetworkAdapter->COMGETTER(TraceFile)(&str); H();
2413 if (str) /* check convention for indicating default file. */
2414 {
2415 rc = CFGMR3InsertStringW(pCfg, "File", str); RC_CHECK();
2416 }
2417 STR_FREE();
2418 }
2419 }
2420 else if (fAttachDetach && !fSniffer)
2421 {
2422 rc = PDMR3DeviceDetach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/);
2423 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
2424 rc = VINF_SUCCESS;
2425 AssertLogRelRCReturn(rc, rc);
2426
2427 /* nuke anything which might have been left behind. */
2428 CFGMR3RemoveNode(CFGMR3GetChildF(pInst, "LUN#%u", uLun));
2429 }
2430 else if (!fAttachDetach && fSniffer)
2431 {
2432 /* insert the sniffer filter driver. */
2433 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2434 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
2435 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2436 hrc = aNetworkAdapter->COMGETTER(TraceFile)(&str); H();
2437 if (str) /* check convention for indicating default file. */
2438 {
2439 rc = CFGMR3InsertStringW(pCfg, "File", str); RC_CHECK();
2440 }
2441 STR_FREE();
2442 }
2443
2444 Bstr networkName, trunkName, trunkType;
2445 NetworkAttachmentType_T eAttachmentType;
2446 hrc = aNetworkAdapter->COMGETTER(AttachmentType)(&eAttachmentType); H();
2447 switch (eAttachmentType)
2448 {
2449 case NetworkAttachmentType_Null:
2450 break;
2451
2452 case NetworkAttachmentType_NAT:
2453 {
2454 if (fSniffer)
2455 {
2456 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
2457 }
2458 else
2459 {
2460 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2461 }
2462 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
2463 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2464
2465 /* Configure TFTP prefix and boot filename. */
2466 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
2467 if (str && *str)
2468 {
2469 rc = CFGMR3InsertStringF(pCfg, "TFTPPrefix", "%ls%c%s", str, RTPATH_DELIMITER, "TFTP"); RC_CHECK();
2470 }
2471 STR_FREE();
2472 hrc = pMachine->COMGETTER(Name)(&str); H();
2473 rc = CFGMR3InsertStringF(pCfg, "BootFile", "%ls.pxe", str); RC_CHECK();
2474 STR_FREE();
2475
2476 hrc = aNetworkAdapter->COMGETTER(NATNetwork)(&str); H();
2477 if (str && *str)
2478 {
2479 rc = CFGMR3InsertStringW(pCfg, "Network", str); RC_CHECK();
2480 /* NAT uses its own DHCP implementation */
2481 //networkName = Bstr(psz);
2482 }
2483 STR_FREE();
2484 break;
2485 }
2486
2487 case NetworkAttachmentType_Bridged:
2488 {
2489#if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT)
2490 hrc = pThis->attachToTapInterface(aNetworkAdapter);
2491 if (FAILED(hrc))
2492 {
2493 switch (hrc)
2494 {
2495 case VERR_ACCESS_DENIED:
2496 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2497 "Failed to open '/dev/net/tun' for read/write access. Please check the "
2498 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
2499 "change the group of that node and make yourself a member of that group. Make "
2500 "sure that these changes are permanent, especially if you are "
2501 "using udev"));
2502 default:
2503 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
2504 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2505 "Failed to initialize Host Interface Networking"));
2506 }
2507 }
2508
2509 Assert((int)pThis->maTapFD[uInstance] >= 0);
2510 if ((int)pThis->maTapFD[uInstance] >= 0)
2511 {
2512 if (fSniffer)
2513 {
2514 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
2515 }
2516 else
2517 {
2518 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2519 }
2520 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
2521 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2522 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pThis->maTapFD[uInstance]); RC_CHECK();
2523 }
2524
2525#elif defined(VBOX_WITH_NETFLT)
2526 /*
2527 * This is the new VBoxNetFlt+IntNet stuff.
2528 */
2529 if (fSniffer)
2530 {
2531 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
2532 }
2533 else
2534 {
2535 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2536 }
2537
2538 Bstr HifName;
2539 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
2540 if (FAILED(hrc))
2541 {
2542 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
2543 H();
2544 }
2545
2546 Utf8Str HifNameUtf8(HifName);
2547 const char *pszHifName = HifNameUtf8.raw();
2548
2549# if defined(RT_OS_DARWIN)
2550 /* The name is on the form 'ifX: long name', chop it off at the colon. */
2551 char szTrunk[8];
2552 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
2553 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
2554 if (!pszColon)
2555 {
2556 hrc = aNetworkAdapter->Detach(); H();
2557 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2558 N_("Malformed host interface networking name '%ls'"),
2559 HifName.raw());
2560 }
2561 *pszColon = '\0';
2562 const char *pszTrunk = szTrunk;
2563
2564# elif defined(RT_OS_SOLARIS)
2565 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
2566 char szTrunk[256];
2567 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
2568 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
2569
2570 /*
2571 * Currently don't bother about malformed names here for the sake of people using
2572 * VBoxManage and setting only the NIC name from there. If there is a space we
2573 * chop it off and proceed, otherwise just use whatever we've got.
2574 */
2575 if (pszSpace)
2576 *pszSpace = '\0';
2577
2578 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
2579 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
2580 if (pszColon)
2581 *pszColon = '\0';
2582
2583 const char *pszTrunk = szTrunk;
2584
2585# elif defined(RT_OS_WINDOWS)
2586 ComPtr<IHostNetworkInterface> hostInterface;
2587 hrc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
2588 if (!SUCCEEDED(hrc))
2589 {
2590 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: FindByName failed, rc=%Rhrc (0x%x)", hrc, hrc));
2591 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2592 N_("Inexistent host networking interface, name '%ls'"),
2593 HifName.raw());
2594 }
2595
2596 HostNetworkInterfaceType_T eIfType;
2597 hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
2598 if (FAILED(hrc))
2599 {
2600 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
2601 H();
2602 }
2603
2604 if (eIfType != HostNetworkInterfaceType_Bridged)
2605 {
2606 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2607 N_("Interface ('%ls') is not a Bridged Adapter interface"),
2608 HifName.raw());
2609 }
2610
2611 hrc = hostInterface->COMGETTER(Id)(&str);
2612 if (FAILED(hrc))
2613 {
2614 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
2615 H();
2616 }
2617 Guid hostIFGuid(str);
2618 STR_FREE();
2619
2620 INetCfg *pNc;
2621 ComPtr<INetCfgComponent> pAdaptorComponent;
2622 LPWSTR pszApp;
2623 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
2624
2625 hrc = VBoxNetCfgWinQueryINetCfg(FALSE /*fGetWriteLock*/,
2626 L"VirtualBox",
2627 &pNc,
2628 &pszApp);
2629 Assert(hrc == S_OK);
2630 if (hrc == S_OK)
2631 {
2632 /* get the adapter's INetCfgComponent*/
2633 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
2634 if (hrc != S_OK)
2635 {
2636 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2637 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2638 H();
2639 }
2640 }
2641#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
2642 char szTrunkName[INTNET_MAX_TRUNK_NAME];
2643 char *pszTrunkName = szTrunkName;
2644 wchar_t * pswzBindName;
2645 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
2646 Assert(hrc == S_OK);
2647 if (hrc == S_OK)
2648 {
2649 int cwBindName = (int)wcslen(pswzBindName) + 1;
2650 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
2651 if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
2652 {
2653 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
2654 pszTrunkName += cbFullBindNamePrefix-1;
2655 if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
2656 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
2657 {
2658 DWORD err = GetLastError();
2659 hrc = HRESULT_FROM_WIN32(err);
2660 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
2661 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
2662 }
2663 }
2664 else
2665 {
2666 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
2667 /** @todo set appropriate error code */
2668 hrc = E_FAIL;
2669 }
2670
2671 if (hrc != S_OK)
2672 {
2673 AssertFailed();
2674 CoTaskMemFree(pswzBindName);
2675 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2676 H();
2677 }
2678
2679 /* we're not freeing the bind name since we'll use it later for detecting wireless*/
2680 }
2681 else
2682 {
2683 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2684 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2685 H();
2686 }
2687 const char *pszTrunk = szTrunkName;
2688 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
2689
2690# elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
2691# if defined(RT_OS_FREEBSD)
2692 /*
2693 * If we bridge to a tap interface open it the `old' direct way.
2694 * This works and performs better than bridging a physical
2695 * interface via the current FreeBSD vboxnetflt implementation.
2696 */
2697 if (!strncmp(pszHifName, "tap", sizeof "tap" - 1)) {
2698 hrc = pThis->attachToTapInterface(aNetworkAdapter);
2699 if (FAILED(hrc))
2700 {
2701 switch (hrc)
2702 {
2703 case VERR_ACCESS_DENIED:
2704 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2705 "Failed to open '/dev/%s' for read/write access. Please check the "
2706 "permissions of that node, and that the net.link.tap.user_open "
2707 "sysctl is set. Either run 'chmod 0666 /dev/%s' or "
2708 "change the group of that node to vboxusers and make yourself "
2709 "a member of that group. Make sure that these changes are permanent."), pszHifName, pszHifName);
2710 default:
2711 AssertMsgFailed(("Could not attach to tap interface! Bad!\n"));
2712 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2713 "Failed to initialize Host Interface Networking"));
2714 }
2715 }
2716
2717 Assert((int)pThis->maTapFD[uInstance] >= 0);
2718 if ((int)pThis->maTapFD[uInstance] >= 0)
2719 {
2720 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
2721 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2722 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pThis->maTapFD[uInstance]); RC_CHECK();
2723 }
2724 break;
2725 }
2726# endif
2727 /** @todo Check for malformed names. */
2728 const char *pszTrunk = pszHifName;
2729
2730 /* Issue a warning if the interface is down */
2731 {
2732 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
2733 if (iSock >= 0)
2734 {
2735 struct ifreq Req;
2736
2737 memset(&Req, 0, sizeof(Req));
2738 strncpy(Req.ifr_name, pszHifName, sizeof(Req.ifr_name) - 1);
2739 if (ioctl(iSock, SIOCGIFFLAGS, &Req) >= 0)
2740 if ((Req.ifr_flags & IFF_UP) == 0)
2741 {
2742 setVMRuntimeErrorCallbackF(pVM, pThis, 0, "BridgedInterfaceDown", "Bridged interface %s is down. Guest will not be able to use this interface", pszHifName);
2743 }
2744
2745 close(iSock);
2746 }
2747 }
2748
2749# else
2750# error "PORTME (VBOX_WITH_NETFLT)"
2751# endif
2752
2753 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
2754 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2755 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
2756 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
2757 RC_CHECK();
2758 char szNetwork[INTNET_MAX_NETWORK_NAME];
2759 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
2760 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
2761 networkName = Bstr(szNetwork);
2762 trunkName = Bstr(pszTrunk);
2763 trunkType = Bstr(TRUNKTYPE_NETFLT);
2764
2765# if defined(RT_OS_DARWIN)
2766 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
2767 if ( strstr(pszHifName, "Wireless")
2768 || strstr(pszHifName, "AirPort" ))
2769 {
2770 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
2771 }
2772# elif defined(RT_OS_LINUX)
2773 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
2774 if (iSock >= 0)
2775 {
2776 struct iwreq WRq;
2777
2778 memset(&WRq, 0, sizeof(WRq));
2779 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
2780 bool fSharedMacOnWire = ioctl(iSock, SIOCGIWNAME, &WRq) >= 0;
2781 close(iSock);
2782 if (fSharedMacOnWire)
2783 {
2784 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
2785 RC_CHECK();
2786 Log(("Set SharedMacOnWire\n"));
2787 }
2788 else
2789 Log(("Failed to get wireless name\n"));
2790 }
2791 else
2792 Log(("Failed to open wireless socket\n"));
2793# elif defined(RT_OS_FREEBSD)
2794 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
2795 if (iSock >= 0)
2796 {
2797 struct ieee80211req WReq;
2798 uint8_t abData[32];
2799
2800 memset(&WReq, 0, sizeof(WReq));
2801 strncpy(WReq.i_name, pszHifName, sizeof(WReq.i_name));
2802 WReq.i_type = IEEE80211_IOC_SSID;
2803 WReq.i_val = -1;
2804 WReq.i_data = abData;
2805 WReq.i_len = sizeof(abData);
2806
2807 bool fSharedMacOnWire = ioctl(iSock, SIOCG80211, &WReq) >= 0;
2808 close(iSock);
2809 if (fSharedMacOnWire)
2810 {
2811 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
2812 RC_CHECK();
2813 Log(("Set SharedMacOnWire\n"));
2814 }
2815 else
2816 Log(("Failed to get wireless name\n"));
2817 }
2818 else
2819 Log(("Failed to open wireless socket\n"));
2820# elif defined(RT_OS_WINDOWS)
2821# define DEVNAME_PREFIX L"\\\\.\\"
2822 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
2823 * there is a pretty long way till there though since we need to obtain the symbolic link name
2824 * for the adapter device we are going to query given the device Guid */
2825
2826
2827 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
2828
2829 wchar_t FileName[MAX_PATH];
2830 wcscpy(FileName, DEVNAME_PREFIX);
2831 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
2832
2833 /* open the device */
2834 HANDLE hDevice = CreateFile(FileName,
2835 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
2836 NULL,
2837 OPEN_EXISTING,
2838 FILE_ATTRIBUTE_NORMAL,
2839 NULL);
2840
2841 if (hDevice != INVALID_HANDLE_VALUE)
2842 {
2843 bool fSharedMacOnWire = false;
2844
2845 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
2846 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
2847 NDIS_PHYSICAL_MEDIUM PhMedium;
2848 DWORD cbResult;
2849 if (DeviceIoControl(hDevice,
2850 IOCTL_NDIS_QUERY_GLOBAL_STATS,
2851 &Oid,
2852 sizeof(Oid),
2853 &PhMedium,
2854 sizeof(PhMedium),
2855 &cbResult,
2856 NULL))
2857 {
2858 /* that was simple, now examine PhMedium */
2859 if ( PhMedium == NdisPhysicalMediumWirelessWan
2860 || PhMedium == NdisPhysicalMediumWirelessLan
2861 || PhMedium == NdisPhysicalMediumNative802_11
2862 || PhMedium == NdisPhysicalMediumBluetooth)
2863 fSharedMacOnWire = true;
2864 }
2865 else
2866 {
2867 int winEr = GetLastError();
2868 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
2869 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
2870 }
2871 CloseHandle(hDevice);
2872
2873 if (fSharedMacOnWire)
2874 {
2875 Log(("this is a wireless adapter"));
2876 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
2877 Log(("Set SharedMacOnWire\n"));
2878 }
2879 else
2880 Log(("this is NOT a wireless adapter"));
2881 }
2882 else
2883 {
2884 int winEr = GetLastError();
2885 AssertLogRelMsgFailed(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
2886 }
2887
2888 CoTaskMemFree(pswzBindName);
2889
2890 pAdaptorComponent.setNull();
2891 /* release the pNc finally */
2892 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2893# else
2894 /** @todo PORTME: wireless detection */
2895# endif
2896
2897# if defined(RT_OS_SOLARIS)
2898# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
2899 /* Zone access restriction, don't allow snopping the global zone. */
2900 zoneid_t ZoneId = getzoneid();
2901 if (ZoneId != GLOBAL_ZONEID)
2902 {
2903 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
2904 }
2905# endif
2906# endif
2907
2908#elif defined(RT_OS_WINDOWS) /* not defined NetFlt */
2909 /* NOTHING TO DO HERE */
2910#elif defined(RT_OS_LINUX)
2911/// @todo aleksey: is there anything to be done here?
2912#elif defined(RT_OS_FREEBSD)
2913/** @todo FreeBSD: Check out this later (HIF networking). */
2914#else
2915# error "Port me"
2916#endif
2917 break;
2918 }
2919
2920 case NetworkAttachmentType_Internal:
2921 {
2922 hrc = aNetworkAdapter->COMGETTER(InternalNetwork)(&str); H();
2923 if (str && *str)
2924 {
2925 if (fSniffer)
2926 {
2927 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2928 RC_CHECK();
2929 }
2930 else
2931 {
2932 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2933 RC_CHECK();
2934 }
2935 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
2936 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2937 rc = CFGMR3InsertStringW(pCfg, "Network", str); RC_CHECK();
2938 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone); RC_CHECK();
2939 networkName = str;
2940 trunkType = Bstr(TRUNKTYPE_WHATEVER);
2941 }
2942 STR_FREE();
2943 break;
2944 }
2945
2946 case NetworkAttachmentType_HostOnly:
2947 {
2948 if (fSniffer)
2949 {
2950 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2951 RC_CHECK();
2952 }
2953 else
2954 {
2955 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2956 RC_CHECK();
2957 }
2958
2959 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
2960 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2961
2962 Bstr HifName;
2963 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
2964 if (FAILED(hrc))
2965 {
2966 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)\n", hrc));
2967 H();
2968 }
2969
2970 Utf8Str HifNameUtf8(HifName);
2971 const char *pszHifName = HifNameUtf8.raw();
2972 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface): %s\n", pszHifName));
2973 ComPtr<IHostNetworkInterface> hostInterface;
2974 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
2975 if (!SUCCEEDED(rc))
2976 {
2977 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)\n", rc));
2978 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2979 N_("Inexistent host networking interface, name '%ls'"),
2980 HifName.raw());
2981 }
2982
2983 char szNetwork[INTNET_MAX_NETWORK_NAME];
2984 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
2985
2986#if defined(RT_OS_WINDOWS)
2987# ifndef VBOX_WITH_NETFLT
2988 hrc = E_NOTIMPL;
2989 LogRel(("NetworkAttachmentType_HostOnly: Not Implemented\n"));
2990 H();
2991# else /* defined VBOX_WITH_NETFLT*/
2992 /** @todo r=bird: Put this in a function. */
2993
2994 HostNetworkInterfaceType_T eIfType;
2995 hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
2996 if (FAILED(hrc))
2997 {
2998 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)\n", hrc));
2999 H();
3000 }
3001
3002 if (eIfType != HostNetworkInterfaceType_HostOnly)
3003 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
3004 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
3005 HifName.raw());
3006
3007 hrc = hostInterface->COMGETTER(Id)(&str);
3008 if (FAILED(hrc))
3009 {
3010 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)\n", hrc));
3011 H();
3012 }
3013 Guid hostIFGuid(str);
3014 STR_FREE();
3015
3016 INetCfg *pNc;
3017 ComPtr<INetCfgComponent> pAdaptorComponent;
3018 LPWSTR pszApp;
3019 rc = VERR_INTNET_FLT_IF_NOT_FOUND;
3020
3021 hrc = VBoxNetCfgWinQueryINetCfg(FALSE,
3022 L"VirtualBox",
3023 &pNc,
3024 &pszApp);
3025 Assert(hrc == S_OK);
3026 if (hrc == S_OK)
3027 {
3028 /* get the adapter's INetCfgComponent*/
3029 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
3030 if (hrc != S_OK)
3031 {
3032 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3033 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
3034 H();
3035 }
3036 }
3037#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
3038 char szTrunkName[INTNET_MAX_TRUNK_NAME];
3039 char *pszTrunkName = szTrunkName;
3040 wchar_t * pswzBindName;
3041 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
3042 Assert(hrc == S_OK);
3043 if (hrc == S_OK)
3044 {
3045 int cwBindName = (int)wcslen(pswzBindName) + 1;
3046 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
3047 if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
3048 {
3049 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
3050 pszTrunkName += cbFullBindNamePrefix-1;
3051 if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
3052 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
3053 {
3054 DWORD err = GetLastError();
3055 hrc = HRESULT_FROM_WIN32(err);
3056 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
3057 }
3058 }
3059 else
3060 {
3061 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
3062 /** @todo set appropriate error code */
3063 hrc = E_FAIL;
3064 }
3065
3066 if (hrc != S_OK)
3067 {
3068 AssertFailed();
3069 CoTaskMemFree(pswzBindName);
3070 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3071 H();
3072 }
3073 }
3074 else
3075 {
3076 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3077 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
3078 H();
3079 }
3080
3081
3082 CoTaskMemFree(pswzBindName);
3083
3084 pAdaptorComponent.setNull();
3085 /* release the pNc finally */
3086 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3087
3088 const char *pszTrunk = szTrunkName;
3089
3090 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
3091 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
3092 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
3093 networkName = Bstr(szNetwork);
3094 trunkName = Bstr(pszTrunk);
3095 trunkType = TRUNKTYPE_NETADP;
3096# endif /* defined VBOX_WITH_NETFLT*/
3097#elif defined(RT_OS_DARWIN)
3098 rc = CFGMR3InsertString(pCfg, "Trunk", pszHifName); RC_CHECK();
3099 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
3100 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
3101 networkName = Bstr(szNetwork);
3102 trunkName = Bstr(pszHifName);
3103 trunkType = TRUNKTYPE_NETADP;
3104#else
3105 rc = CFGMR3InsertString(pCfg, "Trunk", pszHifName); RC_CHECK();
3106 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
3107 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
3108 networkName = Bstr(szNetwork);
3109 trunkName = Bstr(pszHifName);
3110 trunkType = TRUNKTYPE_NETFLT;
3111#endif
3112#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
3113
3114 Bstr tmpAddr, tmpMask;
3115
3116 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPAddress", pszHifName), tmpAddr.asOutParam());
3117 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
3118 {
3119 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPNetMask", pszHifName), tmpMask.asOutParam());
3120 if (SUCCEEDED(hrc) && !tmpMask.isEmpty())
3121 hrc = hostInterface->EnableStaticIpConfig(tmpAddr, tmpMask);
3122 else
3123 hrc = hostInterface->EnableStaticIpConfig(tmpAddr,
3124 Bstr(VBOXNET_IPV4MASK_DEFAULT));
3125 }
3126 else
3127 {
3128 /* Grab the IP number from the 'vboxnetX' instance number (see netif.h) */
3129 hrc = hostInterface->EnableStaticIpConfig(getDefaultIPv4Address(Bstr(pszHifName)),
3130 Bstr(VBOXNET_IPV4MASK_DEFAULT));
3131 }
3132
3133 ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
3134
3135 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6Address", pszHifName), tmpAddr.asOutParam());
3136 if (SUCCEEDED(hrc))
3137 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6NetMask", pszHifName), tmpMask.asOutParam());
3138 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty() && !tmpMask.isEmpty())
3139 {
3140 hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
3141 ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
3142 }
3143#endif
3144 break;
3145 }
3146
3147 default:
3148 AssertMsgFailed(("should not get here!\n"));
3149 break;
3150 }
3151
3152 /*
3153 * Attempt to attach the driver.
3154 */
3155 switch (eAttachmentType)
3156 {
3157 case NetworkAttachmentType_Null:
3158 break;
3159
3160 case NetworkAttachmentType_Bridged:
3161 case NetworkAttachmentType_Internal:
3162 case NetworkAttachmentType_HostOnly:
3163 case NetworkAttachmentType_NAT:
3164 {
3165 if (SUCCEEDED(hrc) && SUCCEEDED(rc))
3166 {
3167 if (fAttachDetach)
3168 {
3169 rc = PDMR3DriverAttach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /* ppBase */);
3170 AssertRC(rc);
3171 }
3172
3173 {
3174 /** @todo pritesh: get the dhcp server name from the
3175 * previous network configuration and then stop the server
3176 * else it may conflict with the dhcp server running with
3177 * the current attachment type
3178 */
3179 /* Stop the hostonly DHCP Server */
3180 }
3181
3182 if (!networkName.isEmpty())
3183 {
3184 /*
3185 * Until we implement service reference counters DHCP Server will be stopped
3186 * by DHCPServerRunner destructor.
3187 */
3188 ComPtr<IDHCPServer> dhcpServer;
3189 hrc = virtualBox->FindDHCPServerByNetworkName(networkName, dhcpServer.asOutParam());
3190 if (SUCCEEDED(hrc))
3191 {
3192 /* there is a DHCP server available for this network */
3193 BOOL fEnabled;
3194 hrc = dhcpServer->COMGETTER(Enabled)(&fEnabled);
3195 if (FAILED(hrc))
3196 {
3197 LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (%Rhrc)", hrc));
3198 H();
3199 }
3200
3201 if (fEnabled)
3202 hrc = dhcpServer->Start(networkName, trunkName, trunkType);
3203 }
3204 else
3205 hrc = S_OK;
3206 }
3207 }
3208
3209 break;
3210 }
3211
3212 default:
3213 AssertMsgFailed(("should not get here!\n"));
3214 break;
3215 }
3216
3217 pThis->meAttachmentType[uInstance] = eAttachmentType;
3218
3219#undef STR_FREE
3220#undef H
3221#undef RC_CHECK
3222
3223 return VINF_SUCCESS;
3224}
3225
3226#ifdef VBOX_WITH_GUEST_PROPS
3227/**
3228 * Set an array of guest properties
3229 */
3230static void configSetProperties(VMMDev * const pVMMDev, void *names,
3231 void *values, void *timestamps, void *flags)
3232{
3233 VBOXHGCMSVCPARM parms[4];
3234
3235 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
3236 parms[0].u.pointer.addr = names;
3237 parms[0].u.pointer.size = 0; /* We don't actually care. */
3238 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
3239 parms[1].u.pointer.addr = values;
3240 parms[1].u.pointer.size = 0; /* We don't actually care. */
3241 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
3242 parms[2].u.pointer.addr = timestamps;
3243 parms[2].u.pointer.size = 0; /* We don't actually care. */
3244 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
3245 parms[3].u.pointer.addr = flags;
3246 parms[3].u.pointer.size = 0; /* We don't actually care. */
3247
3248 pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4,
3249 &parms[0]);
3250}
3251
3252/**
3253 * Set a single guest property
3254 */
3255static void configSetProperty(VMMDev * const pVMMDev, const char *pszName,
3256 const char *pszValue, const char *pszFlags)
3257{
3258 VBOXHGCMSVCPARM parms[4];
3259
3260 AssertPtrReturnVoid(pszName);
3261 AssertPtrReturnVoid(pszValue);
3262 AssertPtrReturnVoid(pszFlags);
3263 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
3264 parms[0].u.pointer.addr = (void *)pszName;
3265 parms[0].u.pointer.size = strlen(pszName) + 1;
3266 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
3267 parms[1].u.pointer.addr = (void *)pszValue;
3268 parms[1].u.pointer.size = strlen(pszValue) + 1;
3269 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
3270 parms[2].u.pointer.addr = (void *)pszFlags;
3271 parms[2].u.pointer.size = strlen(pszFlags) + 1;
3272 pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3,
3273 &parms[0]);
3274}
3275
3276/**
3277 * Set the global flags value by calling the service
3278 * @returns the status returned by the call to the service
3279 *
3280 * @param pTable the service instance handle
3281 * @param eFlags the flags to set
3282 */
3283int configSetGlobalPropertyFlags(VMMDev * const pVMMDev,
3284 guestProp::ePropFlags eFlags)
3285{
3286 VBOXHGCMSVCPARM paParm;
3287 paParm.setUInt32(eFlags);
3288 int rc = pVMMDev->hgcmHostCall ("VBoxGuestPropSvc",
3289 guestProp::SET_GLOBAL_FLAGS_HOST, 1,
3290 &paParm);
3291 if (RT_FAILURE(rc))
3292 {
3293 char szFlags[guestProp::MAX_FLAGS_LEN];
3294 if (RT_FAILURE(writeFlags(eFlags, szFlags)))
3295 Log(("Failed to set the global flags.\n"));
3296 else
3297 Log(("Failed to set the global flags \"%s\".\n", szFlags));
3298 }
3299 return rc;
3300}
3301#endif /* VBOX_WITH_GUEST_PROPS */
3302
3303/**
3304 * Set up the Guest Property service, populate it with properties read from
3305 * the machine XML and set a couple of initial properties.
3306 */
3307/* static */ int Console::configGuestProperties(void *pvConsole)
3308{
3309#ifdef VBOX_WITH_GUEST_PROPS
3310 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
3311 ComObjPtr<Console> pConsole = static_cast <Console *> (pvConsole);
3312
3313 /* Load the service */
3314 int rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
3315
3316 if (RT_FAILURE(rc))
3317 {
3318 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
3319 /* That is not a fatal failure. */
3320 rc = VINF_SUCCESS;
3321 }
3322 else
3323 {
3324 /*
3325 * Initialize built-in properties that can be changed and saved.
3326 *
3327 * These are typically transient properties that the guest cannot
3328 * change.
3329 */
3330
3331 /* Sysprep execution by VBoxService. */
3332 configSetProperty(pConsole->mVMMDev,
3333 "/VirtualBox/HostGuest/SysprepExec", "",
3334 "TRANSIENT, RDONLYGUEST");
3335 configSetProperty(pConsole->mVMMDev,
3336 "/VirtualBox/HostGuest/SysprepArgs", "",
3337 "TRANSIENT, RDONLYGUEST");
3338
3339 /*
3340 * Pull over the properties from the server.
3341 */
3342 SafeArray<BSTR> namesOut;
3343 SafeArray<BSTR> valuesOut;
3344 SafeArray<ULONG64> timestampsOut;
3345 SafeArray<BSTR> flagsOut;
3346 HRESULT hrc;
3347 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
3348 ComSafeArrayAsOutParam(valuesOut),
3349 ComSafeArrayAsOutParam(timestampsOut),
3350 ComSafeArrayAsOutParam(flagsOut));
3351 AssertMsgReturn(SUCCEEDED(hrc), ("hrc=%Rrc\n", hrc), VERR_GENERAL_FAILURE);
3352 size_t cProps = namesOut.size();
3353 size_t cAlloc = cProps + 1;
3354 if ( valuesOut.size() != cProps
3355 || timestampsOut.size() != cProps
3356 || flagsOut.size() != cProps
3357 )
3358 AssertFailedReturn(VERR_INVALID_PARAMETER);
3359
3360 char **papszNames, **papszValues, **papszFlags;
3361 char szEmpty[] = "";
3362 ULONG64 *pau64Timestamps;
3363 papszNames = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
3364 papszValues = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
3365 pau64Timestamps = (ULONG64 *)RTMemTmpAllocZ(sizeof(ULONG64) * cAlloc);
3366 papszFlags = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
3367 if (papszNames && papszValues && pau64Timestamps && papszFlags)
3368 {
3369 for (unsigned i = 0; RT_SUCCESS(rc) && i < cProps; ++i)
3370 {
3371 AssertPtrReturn(namesOut[i], VERR_INVALID_PARAMETER);
3372 rc = RTUtf16ToUtf8(namesOut[i], &papszNames[i]);
3373 if (RT_FAILURE(rc))
3374 break;
3375 if (valuesOut[i])
3376 rc = RTUtf16ToUtf8(valuesOut[i], &papszValues[i]);
3377 else
3378 papszValues[i] = szEmpty;
3379 if (RT_FAILURE(rc))
3380 break;
3381 pau64Timestamps[i] = timestampsOut[i];
3382 if (flagsOut[i])
3383 rc = RTUtf16ToUtf8(flagsOut[i], &papszFlags[i]);
3384 else
3385 papszFlags[i] = szEmpty;
3386 }
3387 if (RT_SUCCESS(rc))
3388 configSetProperties(pConsole->mVMMDev,
3389 (void *)papszNames,
3390 (void *)papszValues,
3391 (void *)pau64Timestamps,
3392 (void *)papszFlags);
3393 for (unsigned i = 0; i < cProps; ++i)
3394 {
3395 RTStrFree(papszNames[i]);
3396 if (valuesOut[i])
3397 RTStrFree(papszValues[i]);
3398 if (flagsOut[i])
3399 RTStrFree(papszFlags[i]);
3400 }
3401 }
3402 else
3403 rc = VERR_NO_MEMORY;
3404 RTMemTmpFree(papszNames);
3405 RTMemTmpFree(papszValues);
3406 RTMemTmpFree(pau64Timestamps);
3407 RTMemTmpFree(papszFlags);
3408 AssertRCReturn(rc, rc);
3409
3410 /*
3411 * These properties have to be set before pulling over the properties
3412 * from the machine XML, to ensure that properties saved in the XML
3413 * will override them.
3414 */
3415 /* Set the VBox version string as a guest property */
3416 configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxVer",
3417 VBOX_VERSION_STRING, "TRANSIENT, RDONLYGUEST");
3418 /* Set the VBox SVN revision as a guest property */
3419 configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxRev",
3420 RTBldCfgRevisionStr(), "TRANSIENT, RDONLYGUEST");
3421
3422 /*
3423 * Register the host notification callback
3424 */
3425 HGCMSVCEXTHANDLE hDummy;
3426 HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestPropSvc",
3427 Console::doGuestPropNotification,
3428 pvConsole);
3429
3430#ifdef VBOX_WITH_GUEST_PROPS_RDONLY_GUEST
3431 rc = configSetGlobalPropertyFlags(pConsole->mVMMDev,
3432 guestProp::RDONLYGUEST);
3433 AssertRCReturn(rc, rc);
3434#endif
3435
3436 Log(("Set VBoxGuestPropSvc property store\n"));
3437 }
3438 return VINF_SUCCESS;
3439#else /* !VBOX_WITH_GUEST_PROPS */
3440 return VERR_NOT_SUPPORTED;
3441#endif /* !VBOX_WITH_GUEST_PROPS */
3442}
Note: See TracBrowser for help on using the repository browser.

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