VirtualBox

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

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

Solaris/Main/VBoxNet: use different network for auto vboxnet IP assigning.

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

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