VirtualBox

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

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

SMC: configurability

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

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