VirtualBox

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

Last change on this file since 24408 was 24406, checked in by vboxsync, 15 years ago

Main/CPUM: Use /CPUM/HostCPUID instead of /CPUM/CPUID since the latter is already used for the uncensored overrides. Share more code in CPUM.

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