VirtualBox

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

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

CPU hotplug: Merge 4th patch. Implements the Main API and a VBoxManage interface to turn CPU hotplug on/off and to add/remove CPUs while the VM is running

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

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