VirtualBox

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

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

Main: remaining firmware selection bits

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

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