VirtualBox

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

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

Main/GuestProperties: compile-time option to make guest properties read-only for the guest

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

© 2023 Oracle
ContactPrivacy policyTerms of Use