VirtualBox

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

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

LsiLogic: Add SAS support for Main and Frontends

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

© 2023 Oracle
ContactPrivacy policyTerms of Use