VirtualBox

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

Last change on this file since 24293 was 24286, checked in by vboxsync, 16 years ago

ConsoleImpl2.cpp: r=bird: Why aren't VDConfig inserts checked properly? (Aligned H+RC_CHECKS for storage and fussed around the code a bit.)

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