VirtualBox

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

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

FreeBSD: Use the old TAP code when bridging to a TAP device and set the SharedMaxOnWire flag for a WLAN interface (contributed by Juergen Lock, thanks)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 139.0 KB
Line 
1/* $Id: ConsoleImpl2.cpp 25698 2010-01-08 23:23:51Z vboxsync $ */
2/** @file
3 * VBox Console COM Class implementation
4 *
5 * @remark We've split out the code that the 64-bit VC++ v8 compiler finds
6 * problematic to optimize so we can disable optimizations and later,
7 * perhaps, find a real solution for it (like rewriting the code and
8 * to stop resemble a tonne of spaghetti).
9 */
10
11/*
12 * Copyright (C) 2006-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_DARWIN
1627 case AudioDriverType_CoreAudio:
1628 {
1629 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1630 break;
1631 }
1632#endif
1633 }
1634 hrc = pMachine->COMGETTER(Name)(&str); H();
1635 rc = CFGMR3InsertStringW(pCfg, "StreamName", str); RC_CHECK();
1636 STR_FREE();
1637 }
1638
1639 /*
1640 * The USB Controller.
1641 */
1642 ComPtr<IUSBController> USBCtlPtr;
1643 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1644 if (USBCtlPtr)
1645 {
1646 BOOL fEnabled;
1647 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1648 if (fEnabled)
1649 {
1650 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
1651 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1652 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1653 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1654 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
1655 Assert(!afPciDeviceNo[6]);
1656 afPciDeviceNo[6] = true;
1657 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1658
1659 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1660 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1661 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1662
1663 /*
1664 * Attach the status driver.
1665 */
1666 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1667 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1668 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1669 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
1670 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1671 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1672
1673#ifdef VBOX_WITH_EHCI
1674 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
1675 if (fEnabled)
1676 {
1677 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
1678 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1679 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1680 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1681 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
1682 Assert(!afPciDeviceNo[11]);
1683 afPciDeviceNo[11] = true;
1684 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1685
1686 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1687 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1688 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1689
1690 /*
1691 * Attach the status driver.
1692 */
1693 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1694 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1695 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1696 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
1697 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1698 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1699 }
1700 else
1701#endif
1702 {
1703 /*
1704 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
1705 * on a per device level now.
1706 */
1707 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
1708 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
1709 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
1710 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
1711 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
1712 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
1713 // that it's documented somewhere.) Users needing it can use:
1714 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
1715 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
1716 }
1717 }
1718 }
1719
1720 /*
1721 * Clipboard
1722 */
1723 {
1724 ClipboardMode_T mode = ClipboardMode_Disabled;
1725 hrc = pMachine->COMGETTER(ClipboardMode)(&mode); H();
1726
1727 if (mode != ClipboardMode_Disabled)
1728 {
1729 /* Load the service */
1730 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
1731
1732 if (RT_FAILURE(rc))
1733 {
1734 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
1735 /* That is not a fatal failure. */
1736 rc = VINF_SUCCESS;
1737 }
1738 else
1739 {
1740 /* Setup the service. */
1741 VBOXHGCMSVCPARM parm;
1742
1743 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
1744
1745 switch (mode)
1746 {
1747 default:
1748 case ClipboardMode_Disabled:
1749 {
1750 LogRel(("VBoxSharedClipboard mode: Off\n"));
1751 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
1752 break;
1753 }
1754 case ClipboardMode_GuestToHost:
1755 {
1756 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
1757 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
1758 break;
1759 }
1760 case ClipboardMode_HostToGuest:
1761 {
1762 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
1763 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
1764 break;
1765 }
1766 case ClipboardMode_Bidirectional:
1767 {
1768 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
1769 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
1770 break;
1771 }
1772 }
1773
1774 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
1775
1776 Log(("Set VBoxSharedClipboard mode\n"));
1777 }
1778 }
1779 }
1780
1781#ifdef VBOX_WITH_CROGL
1782 /*
1783 * crOpenGL
1784 */
1785 {
1786 BOOL fEnabled = false;
1787 hrc = pMachine->COMGETTER(Accelerate3DEnabled)(&fEnabled); H();
1788
1789 if (fEnabled)
1790 {
1791 /* Load the service */
1792 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
1793 if (RT_FAILURE(rc))
1794 {
1795 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
1796 /* That is not a fatal failure. */
1797 rc = VINF_SUCCESS;
1798 }
1799 else
1800 {
1801 LogRel(("Shared crOpenGL service loaded.\n"));
1802
1803 /* Setup the service. */
1804 VBOXHGCMSVCPARM parm;
1805 parm.type = VBOX_HGCM_SVC_PARM_PTR;
1806
1807 parm.u.pointer.addr = pConsole->getDisplay()->getFramebuffer();
1808 parm.u.pointer.size = sizeof(IFramebuffer *);
1809
1810 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_FRAMEBUFFER, 1, &parm);
1811 if (!RT_SUCCESS(rc))
1812 AssertMsgFailed(("SHCRGL_HOST_FN_SET_FRAMEBUFFER failed with %Rrc\n", rc));
1813
1814 parm.u.pointer.addr = pVM;
1815 parm.u.pointer.size = sizeof(pVM);
1816 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VM, 1, &parm);
1817 if (!RT_SUCCESS(rc))
1818 AssertMsgFailed(("SHCRGL_HOST_FN_SET_VM failed with %Rrc\n", rc));
1819 }
1820
1821 }
1822 }
1823#endif
1824
1825#ifdef VBOX_WITH_GUEST_PROPS
1826 /*
1827 * Guest property service
1828 */
1829
1830 rc = configGuestProperties(pConsole);
1831#endif /* VBOX_WITH_GUEST_PROPS defined */
1832
1833 /*
1834 * CFGM overlay handling.
1835 *
1836 * Here we check the extra data entries for CFGM values
1837 * and create the nodes and insert the values on the fly. Existing
1838 * values will be removed and reinserted. CFGM is typed, so by default
1839 * we will guess whether it's a string or an integer (byte arrays are
1840 * not currently supported). It's possible to override this autodetection
1841 * by adding "string:", "integer:" or "bytes:" (future).
1842 *
1843 * We first perform a run on global extra data, then on the machine
1844 * extra data to support global settings with local overrides.
1845 *
1846 */
1847 /** @todo add support for removing nodes and byte blobs. */
1848 SafeArray<BSTR> aGlobalExtraDataKeys;
1849 SafeArray<BSTR> aMachineExtraDataKeys;
1850 /*
1851 * Get the next key
1852 */
1853 if (FAILED(hrc = virtualBox->GetExtraDataKeys(ComSafeArrayAsOutParam(aGlobalExtraDataKeys))))
1854 AssertMsgFailed(("VirtualBox::GetExtraDataKeys failed with %Rrc\n", hrc));
1855
1856 // remember the no. of global values so we can call the correct method below
1857 size_t cGlobalValues = aGlobalExtraDataKeys.size();
1858
1859 if (FAILED(hrc = pMachine->GetExtraDataKeys(ComSafeArrayAsOutParam(aMachineExtraDataKeys))))
1860 AssertMsgFailed(("IMachine::GetExtraDataKeys failed with %Rrc\n", hrc));
1861
1862 // build a combined list from global keys...
1863 std::list<Utf8Str> llExtraDataKeys;
1864 size_t i = 0;
1865
1866 for (i = 0; i < aGlobalExtraDataKeys.size(); ++i)
1867 llExtraDataKeys.push_back(Utf8Str(aGlobalExtraDataKeys[i]));
1868 // ... and machine keys
1869 for (i = 0; i < aMachineExtraDataKeys.size(); ++i)
1870 llExtraDataKeys.push_back(Utf8Str(aMachineExtraDataKeys[i]));
1871
1872 i = 0;
1873 for (std::list<Utf8Str>::const_iterator it = llExtraDataKeys.begin();
1874 it != llExtraDataKeys.end();
1875 ++it, ++i)
1876 {
1877 const Utf8Str &strKey = *it;
1878
1879 /*
1880 * We only care about keys starting with "VBoxInternal/" (skip "G:" or "M:")
1881 */
1882 if (!strKey.startsWith("VBoxInternal/"))
1883 continue;
1884
1885 const char *pszExtraDataKey = strKey.raw() + sizeof("VBoxInternal/") - 1;
1886
1887 // get the value
1888 Bstr strExtraDataValue;
1889 if (i < cGlobalValues)
1890 // this is still one of the global values:
1891 hrc = virtualBox->GetExtraData(Bstr(strKey), strExtraDataValue.asOutParam());
1892 else
1893 hrc = pMachine->GetExtraData(Bstr(strKey), strExtraDataValue.asOutParam());
1894 if (FAILED(hrc))
1895 LogRel(("Warning: Cannot get extra data key %s, rc = %Rrc\n", strKey.raw(), hrc));
1896
1897 /*
1898 * The key will be in the format "Node1/Node2/Value" or simply "Value".
1899 * Split the two and get the node, delete the value and create the node
1900 * if necessary.
1901 */
1902 PCFGMNODE pNode;
1903 const char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
1904 if (pszCFGMValueName)
1905 {
1906 /* terminate the node and advance to the value (Utf8Str might not
1907 offically like this but wtf) */
1908 *(char*)pszCFGMValueName = '\0';
1909 ++pszCFGMValueName;
1910
1911 /* does the node already exist? */
1912 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
1913 if (pNode)
1914 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1915 else
1916 {
1917 /* create the node */
1918 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
1919 if (RT_FAILURE(rc))
1920 {
1921 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
1922 continue;
1923 }
1924 Assert(pNode);
1925 }
1926 }
1927 else
1928 {
1929 /* root value (no node path). */
1930 pNode = pRoot;
1931 pszCFGMValueName = pszExtraDataKey;
1932 pszExtraDataKey--;
1933 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1934 }
1935
1936 /*
1937 * Now let's have a look at the value.
1938 * Empty strings means that we should remove the value, which we've
1939 * already done above.
1940 */
1941 Utf8Str strCFGMValueUtf8(strExtraDataValue);
1942 const char *pszCFGMValue = strCFGMValueUtf8.raw();
1943 if ( pszCFGMValue
1944 && *pszCFGMValue)
1945 {
1946 uint64_t u64Value;
1947
1948 /* check for type prefix first. */
1949 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
1950 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
1951 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
1952 {
1953 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
1954 if (RT_SUCCESS(rc))
1955 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
1956 }
1957 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
1958 rc = VERR_NOT_IMPLEMENTED;
1959 /* auto detect type. */
1960 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
1961 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
1962 else
1963 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
1964 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
1965 }
1966 }
1967
1968 /*
1969 * ACPI
1970 */
1971 BOOL fACPI;
1972 hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
1973 if (fACPI)
1974 {
1975 BOOL fShowCpu = fExtProfile;
1976 /* Always show the CPU leafs when we have multiple VCPUs or when the IO-APIC is enabled.
1977 * The Windows SMP kernel needs a CPU leaf or else its idle loop will burn cpu cycles; the
1978 * intelppm driver refuses to register an idle state handler.
1979 */
1980 if ((cCpus > 1) || fIOAPIC)
1981 fShowCpu = true;
1982
1983 rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); RC_CHECK();
1984 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1985 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1986 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1987 rc = CFGMR3InsertInteger(pCfg, "RamSize", cbRam); RC_CHECK();
1988 rc = CFGMR3InsertInteger(pCfg, "RamHoleSize", cbRamHole); RC_CHECK();
1989 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
1990
1991 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
1992 rc = CFGMR3InsertInteger(pCfg, "FdcEnabled", fFdcEnabled); RC_CHECK();
1993#ifdef VBOX_WITH_HPET
1994 rc = CFGMR3InsertInteger(pCfg, "HpetEnabled", fHpetEnabled); RC_CHECK();
1995#endif
1996#ifdef VBOX_WITH_SMC
1997 rc = CFGMR3InsertInteger(pCfg, "SmcEnabled", fSmcEnabled); RC_CHECK();
1998#endif
1999 rc = CFGMR3InsertInteger(pCfg, "ShowRtc", fExtProfile); RC_CHECK();
2000
2001 rc = CFGMR3InsertInteger(pCfg, "ShowCpu", fShowCpu); RC_CHECK();
2002 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
2003 Assert(!afPciDeviceNo[7]);
2004 afPciDeviceNo[7] = true;
2005 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2006
2007 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2008 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
2009 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2010 }
2011
2012#undef STR_FREE
2013#undef H
2014#undef RC_CHECK
2015
2016 /* Register VM state change handler */
2017 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2018 AssertRC (rc2);
2019 if (RT_SUCCESS(rc))
2020 rc = rc2;
2021
2022 /* Register VM runtime error handler */
2023 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2024 AssertRC (rc2);
2025 if (RT_SUCCESS(rc))
2026 rc = rc2;
2027
2028 LogFlowFunc (("vrc = %Rrc\n", rc));
2029 LogFlowFuncLeave();
2030
2031 return rc;
2032}
2033
2034/**
2035 * Ellipsis to va_list wrapper for calling setVMRuntimeErrorCallback.
2036 */
2037/*static*/ void Console::setVMRuntimeErrorCallbackF(PVM pVM, void *pvConsole, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
2038{
2039 va_list va;
2040 va_start(va, pszFormat);
2041 setVMRuntimeErrorCallback(pVM, pvConsole, fFlags, pszErrorId, pszFormat, va);
2042 va_end(va);
2043}
2044
2045/**
2046 * Construct the Network configuration tree
2047 *
2048 * @returns VBox status code.
2049 *
2050 * @param pThis Pointer to the Console object.
2051 * @param pszDevice The PDM device name.
2052 * @param uInstance The PDM device instance.
2053 * @param uLun The PDM LUN number of the drive.
2054 * @param aNetworkAdapter The network adapter whose attachment needs to be changed
2055 * @param pCfg Configuration node for the device
2056 * @param pLunL0 To store the pointer to the LUN#0.
2057 * @param pInst The instance CFGM node
2058 * @param fAttachDetach To determine if the network attachment should
2059 * be attached/detached after/before
2060 * configuration.
2061 *
2062 * @note Locks the Console object for writing.
2063 */
2064/*static*/ int Console::configNetwork(Console *pThis, const char *pszDevice,
2065 unsigned uInstance, unsigned uLun,
2066 INetworkAdapter *aNetworkAdapter,
2067 PCFGMNODE pCfg, PCFGMNODE pLunL0,
2068 PCFGMNODE pInst, bool fAttachDetach)
2069{
2070 int rc = VINF_SUCCESS;
2071
2072 AutoCaller autoCaller(pThis);
2073 AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
2074
2075 /*
2076 * Locking the object before doing VMR3* calls is quite safe here, since
2077 * we're on EMT. Write lock is necessary because we indirectly modify the
2078 * meAttachmentType member.
2079 */
2080 AutoWriteLock alock(pThis COMMA_LOCKVAL_SRC_POS);
2081
2082 PVM pVM = pThis->mpVM;
2083 BSTR str = NULL;
2084
2085#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } } while (0)
2086#define RC_CHECK() do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc)); STR_FREE(); return rc; } } while (0)
2087#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
2088
2089 HRESULT hrc;
2090 ComPtr<IMachine> pMachine = pThis->machine();
2091
2092 ComPtr<IVirtualBox> virtualBox;
2093 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam());
2094 H();
2095
2096 ComPtr<IHost> host;
2097 hrc = virtualBox->COMGETTER(Host)(host.asOutParam());
2098 H();
2099
2100 BOOL fSniffer;
2101 hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer);
2102 H();
2103
2104 if (fAttachDetach && fSniffer)
2105 {
2106 const char *pszNetDriver = "IntNet";
2107 if (pThis->meAttachmentType[uInstance] == NetworkAttachmentType_NAT)
2108 pszNetDriver = "NAT";
2109#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
2110 if (pThis->meAttachmentType[uInstance] == NetworkAttachmentType_Bridged)
2111 pszNetDriver = "HostInterface";
2112#endif
2113
2114 rc = PDMR3DriverDetach(pVM, pszDevice, uInstance, uLun, pszNetDriver, 0, 0 /*fFlags*/);
2115 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
2116 rc = VINF_SUCCESS;
2117 AssertLogRelRCReturn(rc, rc);
2118
2119 pLunL0 = CFGMR3GetChildF(pInst, "LUN#%u", uLun);
2120 PCFGMNODE pLunAD = CFGMR3GetChildF(pLunL0, "AttachedDriver");
2121 if (pLunAD)
2122 {
2123 CFGMR3RemoveNode(pLunAD);
2124 }
2125 else
2126 {
2127 CFGMR3RemoveNode(pLunL0);
2128 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2129 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
2130 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2131 hrc = aNetworkAdapter->COMGETTER(TraceFile)(&str); H();
2132 if (str) /* check convention for indicating default file. */
2133 {
2134 rc = CFGMR3InsertStringW(pCfg, "File", str); RC_CHECK();
2135 }
2136 STR_FREE();
2137 }
2138 }
2139 else if (fAttachDetach && !fSniffer)
2140 {
2141 rc = PDMR3DeviceDetach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/);
2142 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
2143 rc = VINF_SUCCESS;
2144 AssertLogRelRCReturn(rc, rc);
2145
2146 /* nuke anything which might have been left behind. */
2147 CFGMR3RemoveNode(CFGMR3GetChildF(pInst, "LUN#%u", uLun));
2148 }
2149 else if (!fAttachDetach && fSniffer)
2150 {
2151 /* insert the sniffer filter driver. */
2152 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2153 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
2154 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2155 hrc = aNetworkAdapter->COMGETTER(TraceFile)(&str); H();
2156 if (str) /* check convention for indicating default file. */
2157 {
2158 rc = CFGMR3InsertStringW(pCfg, "File", str); RC_CHECK();
2159 }
2160 STR_FREE();
2161 }
2162
2163 Bstr networkName, trunkName, trunkType;
2164 NetworkAttachmentType_T eAttachmentType;
2165 hrc = aNetworkAdapter->COMGETTER(AttachmentType)(&eAttachmentType); H();
2166 switch (eAttachmentType)
2167 {
2168 case NetworkAttachmentType_Null:
2169 break;
2170
2171 case NetworkAttachmentType_NAT:
2172 {
2173 if (fSniffer)
2174 {
2175 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
2176 }
2177 else
2178 {
2179 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2180 }
2181 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
2182 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2183
2184 /* Configure TFTP prefix and boot filename. */
2185 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
2186 if (str && *str)
2187 {
2188 rc = CFGMR3InsertStringF(pCfg, "TFTPPrefix", "%ls%c%s", str, RTPATH_DELIMITER, "TFTP"); RC_CHECK();
2189 }
2190 STR_FREE();
2191 hrc = pMachine->COMGETTER(Name)(&str); H();
2192 rc = CFGMR3InsertStringF(pCfg, "BootFile", "%ls.pxe", str); RC_CHECK();
2193 STR_FREE();
2194
2195 hrc = aNetworkAdapter->COMGETTER(NATNetwork)(&str); H();
2196 if (str && *str)
2197 {
2198 rc = CFGMR3InsertStringW(pCfg, "Network", str); RC_CHECK();
2199 /* NAT uses its own DHCP implementation */
2200 //networkName = Bstr(psz);
2201 }
2202 STR_FREE();
2203 break;
2204 }
2205
2206 case NetworkAttachmentType_Bridged:
2207 {
2208#if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT)
2209 hrc = pThis->attachToTapInterface(aNetworkAdapter);
2210 if (FAILED(hrc))
2211 {
2212 switch (hrc)
2213 {
2214 case VERR_ACCESS_DENIED:
2215 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2216 "Failed to open '/dev/net/tun' for read/write access. Please check the "
2217 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
2218 "change the group of that node and make yourself a member of that group. Make "
2219 "sure that these changes are permanent, especially if you are "
2220 "using udev"));
2221 default:
2222 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
2223 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2224 "Failed to initialize Host Interface Networking"));
2225 }
2226 }
2227
2228 Assert ((int)pThis->maTapFD[uInstance] >= 0);
2229 if ((int)pThis->maTapFD[uInstance] >= 0)
2230 {
2231 if (fSniffer)
2232 {
2233 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
2234 }
2235 else
2236 {
2237 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2238 }
2239 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
2240 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2241 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pThis->maTapFD[uInstance]); RC_CHECK();
2242 }
2243
2244#elif defined(VBOX_WITH_NETFLT)
2245 /*
2246 * This is the new VBoxNetFlt+IntNet stuff.
2247 */
2248 if (fSniffer)
2249 {
2250 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
2251 }
2252 else
2253 {
2254 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2255 }
2256
2257 Bstr HifName;
2258 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
2259 if (FAILED(hrc))
2260 {
2261 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
2262 H();
2263 }
2264
2265 Utf8Str HifNameUtf8(HifName);
2266 const char *pszHifName = HifNameUtf8.raw();
2267
2268# if defined(RT_OS_DARWIN)
2269 /* The name is on the form 'ifX: long name', chop it off at the colon. */
2270 char szTrunk[8];
2271 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
2272 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
2273 if (!pszColon)
2274 {
2275 hrc = aNetworkAdapter->Detach(); H();
2276 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2277 N_("Malformed host interface networking name '%ls'"),
2278 HifName.raw());
2279 }
2280 *pszColon = '\0';
2281 const char *pszTrunk = szTrunk;
2282
2283# elif defined(RT_OS_SOLARIS)
2284 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
2285 char szTrunk[256];
2286 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
2287 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
2288
2289 /*
2290 * Currently don't bother about malformed names here for the sake of people using
2291 * VBoxManage and setting only the NIC name from there. If there is a space we
2292 * chop it off and proceed, otherwise just use whatever we've got.
2293 */
2294 if (pszSpace)
2295 *pszSpace = '\0';
2296
2297 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
2298 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
2299 if (pszColon)
2300 *pszColon = '\0';
2301
2302 const char *pszTrunk = szTrunk;
2303
2304# elif defined(RT_OS_WINDOWS)
2305 ComPtr<IHostNetworkInterface> hostInterface;
2306 hrc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
2307 if (!SUCCEEDED(hrc))
2308 {
2309 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: FindByName failed, rc=%Rhrc (0x%x)", hrc, hrc));
2310 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2311 N_("Inexistent host networking interface, name '%ls'"),
2312 HifName.raw());
2313 }
2314
2315 HostNetworkInterfaceType_T eIfType;
2316 hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
2317 if (FAILED(hrc))
2318 {
2319 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
2320 H();
2321 }
2322
2323 if (eIfType != HostNetworkInterfaceType_Bridged)
2324 {
2325 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2326 N_("Interface ('%ls') is not a Bridged Adapter interface"),
2327 HifName.raw());
2328 }
2329
2330 hrc = hostInterface->COMGETTER(Id)(&str);
2331 if (FAILED(hrc))
2332 {
2333 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
2334 H();
2335 }
2336 Guid hostIFGuid(str);
2337 STR_FREE();
2338
2339 INetCfg *pNc;
2340 ComPtr<INetCfgComponent> pAdaptorComponent;
2341 LPWSTR pszApp;
2342 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
2343
2344 hrc = VBoxNetCfgWinQueryINetCfg(FALSE /*fGetWriteLock*/,
2345 L"VirtualBox",
2346 &pNc,
2347 &pszApp);
2348 Assert(hrc == S_OK);
2349 if (hrc == S_OK)
2350 {
2351 /* get the adapter's INetCfgComponent*/
2352 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
2353 if (hrc != S_OK)
2354 {
2355 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2356 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2357 H();
2358 }
2359 }
2360#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
2361 char szTrunkName[INTNET_MAX_TRUNK_NAME];
2362 char *pszTrunkName = szTrunkName;
2363 wchar_t * pswzBindName;
2364 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
2365 Assert(hrc == S_OK);
2366 if (hrc == S_OK)
2367 {
2368 int cwBindName = (int)wcslen(pswzBindName) + 1;
2369 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
2370 if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
2371 {
2372 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
2373 pszTrunkName += cbFullBindNamePrefix-1;
2374 if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
2375 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
2376 {
2377 DWORD err = GetLastError();
2378 hrc = HRESULT_FROM_WIN32(err);
2379 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
2380 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
2381 }
2382 }
2383 else
2384 {
2385 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
2386 /** @todo set appropriate error code */
2387 hrc = E_FAIL;
2388 }
2389
2390 if (hrc != S_OK)
2391 {
2392 AssertFailed();
2393 CoTaskMemFree(pswzBindName);
2394 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2395 H();
2396 }
2397
2398 /* we're not freeing the bind name since we'll use it later for detecting wireless*/
2399 }
2400 else
2401 {
2402 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2403 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2404 H();
2405 }
2406 const char *pszTrunk = szTrunkName;
2407 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
2408
2409# elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
2410# if defined(RT_OS_FREEBSD)
2411 /*
2412 * If we bridge to a tap interface open it the `old' direct way.
2413 * This works and performs better than bridging a physical
2414 * interface via the current FreeBSD vboxnetflt implementation.
2415 */
2416 if (!strncmp(pszHifName, "tap", sizeof "tap" - 1)) {
2417 hrc = pThis->attachToTapInterface(aNetworkAdapter);
2418 if (FAILED(hrc))
2419 {
2420 switch (hrc)
2421 {
2422 case VERR_ACCESS_DENIED:
2423 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2424 "Failed to open '/dev/%s' for read/write access. Please check the "
2425 "permissions of that node, and that the net.link.tap.user_open "
2426 "sysctl is set. Either run 'chmod 0666 /dev/%s' or "
2427 "change the group of that node to vboxusers and make yourself "
2428 "a member of that group. Make sure that these changes are permanent."), pszHifName, pszHifName);
2429 default:
2430 AssertMsgFailed(("Could not attach to tap interface! Bad!\n"));
2431 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2432 "Failed to initialize Host Interface Networking"));
2433 }
2434 }
2435
2436 Assert ((int)pThis->maTapFD[uInstance] >= 0);
2437 if ((int)pThis->maTapFD[uInstance] >= 0)
2438 {
2439 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
2440 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2441 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pThis->maTapFD[uInstance]); RC_CHECK();
2442 }
2443 break;
2444 }
2445# endif
2446 /** @todo Check for malformed names. */
2447 const char *pszTrunk = pszHifName;
2448
2449 /* Issue a warning if the interface is down */
2450 {
2451 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
2452 if (iSock >= 0)
2453 {
2454 struct ifreq Req;
2455
2456 memset(&Req, 0, sizeof(Req));
2457 strncpy(Req.ifr_name, pszHifName, sizeof(Req.ifr_name) - 1);
2458 if (ioctl(iSock, SIOCGIFFLAGS, &Req) >= 0)
2459 if ((Req.ifr_flags & IFF_UP) == 0)
2460 {
2461 setVMRuntimeErrorCallbackF(pVM, pThis, 0, "BridgedInterfaceDown", "Bridged interface %s is down. Guest will not be able to use this interface", pszHifName);
2462 }
2463
2464 close(iSock);
2465 }
2466 }
2467
2468# else
2469# error "PORTME (VBOX_WITH_NETFLT)"
2470# endif
2471
2472 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
2473 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2474 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
2475 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
2476 RC_CHECK();
2477 char szNetwork[INTNET_MAX_NETWORK_NAME];
2478 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
2479 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
2480 networkName = Bstr(szNetwork);
2481 trunkName = Bstr(pszTrunk);
2482 trunkType = Bstr(TRUNKTYPE_NETFLT);
2483
2484# if defined(RT_OS_DARWIN)
2485 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
2486 if ( strstr(pszHifName, "Wireless")
2487 || strstr(pszHifName, "AirPort" ))
2488 {
2489 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
2490 }
2491# elif defined(RT_OS_LINUX)
2492 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
2493 if (iSock >= 0)
2494 {
2495 struct iwreq WRq;
2496
2497 memset(&WRq, 0, sizeof(WRq));
2498 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
2499 bool fSharedMacOnWire = ioctl(iSock, SIOCGIWNAME, &WRq) >= 0;
2500 close(iSock);
2501 if (fSharedMacOnWire)
2502 {
2503 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
2504 RC_CHECK();
2505 Log(("Set SharedMacOnWire\n"));
2506 }
2507 else
2508 Log(("Failed to get wireless name\n"));
2509 }
2510 else
2511 Log(("Failed to open wireless socket\n"));
2512# elif defined(RT_OS_FREEBSD)
2513 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
2514 if (iSock >= 0)
2515 {
2516 struct ieee80211req WReq;
2517 uint8_t abData[32];
2518
2519 memset(&WReq, 0, sizeof(WReq));
2520 strncpy(WReq.i_name, pszHifName, sizeof(WReq.i_name));
2521 WReq.i_type = IEEE80211_IOC_SSID;
2522 WReq.i_val = -1;
2523 WReq.i_data = abData;
2524 WReq.i_len = sizeof(abData);
2525
2526 bool fSharedMacOnWire = ioctl(iSock, SIOCG80211, &WReq) >= 0;
2527 close(iSock);
2528 if (fSharedMacOnWire)
2529 {
2530 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
2531 RC_CHECK();
2532 Log(("Set SharedMacOnWire\n"));
2533 }
2534 else
2535 Log(("Failed to get wireless name\n"));
2536 }
2537 else
2538 Log(("Failed to open wireless socket\n"));
2539# elif defined(RT_OS_WINDOWS)
2540# define DEVNAME_PREFIX L"\\\\.\\"
2541 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
2542 * there is a pretty long way till there though since we need to obtain the symbolic link name
2543 * for the adapter device we are going to query given the device Guid */
2544
2545
2546 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
2547
2548 wchar_t FileName[MAX_PATH];
2549 wcscpy(FileName, DEVNAME_PREFIX);
2550 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
2551
2552 /* open the device */
2553 HANDLE hDevice = CreateFile(FileName,
2554 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
2555 NULL,
2556 OPEN_EXISTING,
2557 FILE_ATTRIBUTE_NORMAL,
2558 NULL);
2559
2560 if (hDevice != INVALID_HANDLE_VALUE)
2561 {
2562 bool fSharedMacOnWire = false;
2563
2564 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
2565 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
2566 NDIS_PHYSICAL_MEDIUM PhMedium;
2567 DWORD cbResult;
2568 if (DeviceIoControl(hDevice,
2569 IOCTL_NDIS_QUERY_GLOBAL_STATS,
2570 &Oid,
2571 sizeof(Oid),
2572 &PhMedium,
2573 sizeof(PhMedium),
2574 &cbResult,
2575 NULL))
2576 {
2577 /* that was simple, now examine PhMedium */
2578 if ( PhMedium == NdisPhysicalMediumWirelessWan
2579 || PhMedium == NdisPhysicalMediumWirelessLan
2580 || PhMedium == NdisPhysicalMediumNative802_11
2581 || PhMedium == NdisPhysicalMediumBluetooth)
2582 fSharedMacOnWire = true;
2583 }
2584 else
2585 {
2586 int winEr = GetLastError();
2587 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
2588 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
2589 }
2590 CloseHandle(hDevice);
2591
2592 if (fSharedMacOnWire)
2593 {
2594 Log(("this is a wireless adapter"));
2595 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
2596 Log(("Set SharedMacOnWire\n"));
2597 }
2598 else
2599 Log(("this is NOT a wireless adapter"));
2600 }
2601 else
2602 {
2603 int winEr = GetLastError();
2604 AssertLogRelMsgFailed(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
2605 }
2606
2607 CoTaskMemFree(pswzBindName);
2608
2609 pAdaptorComponent.setNull();
2610 /* release the pNc finally */
2611 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2612# else
2613 /** @todo PORTME: wireless detection */
2614# endif
2615
2616# if defined(RT_OS_SOLARIS)
2617# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
2618 /* Zone access restriction, don't allow snopping the global zone. */
2619 zoneid_t ZoneId = getzoneid();
2620 if (ZoneId != GLOBAL_ZONEID)
2621 {
2622 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
2623 }
2624# endif
2625# endif
2626
2627#elif defined(RT_OS_WINDOWS) /* not defined NetFlt */
2628 /* NOTHING TO DO HERE */
2629#elif defined(RT_OS_LINUX)
2630/// @todo aleksey: is there anything to be done here?
2631#elif defined(RT_OS_FREEBSD)
2632/** @todo FreeBSD: Check out this later (HIF networking). */
2633#else
2634# error "Port me"
2635#endif
2636 break;
2637 }
2638
2639 case NetworkAttachmentType_Internal:
2640 {
2641 hrc = aNetworkAdapter->COMGETTER(InternalNetwork)(&str); H();
2642 if (str && *str)
2643 {
2644 if (fSniffer)
2645 {
2646 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2647 RC_CHECK();
2648 }
2649 else
2650 {
2651 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2652 RC_CHECK();
2653 }
2654 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
2655 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2656 rc = CFGMR3InsertStringW(pCfg, "Network", str); RC_CHECK();
2657 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone); RC_CHECK();
2658 networkName = str;
2659 trunkType = Bstr(TRUNKTYPE_WHATEVER);
2660 }
2661 STR_FREE();
2662 break;
2663 }
2664
2665 case NetworkAttachmentType_HostOnly:
2666 {
2667 if (fSniffer)
2668 {
2669 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2670 RC_CHECK();
2671 }
2672 else
2673 {
2674 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2675 RC_CHECK();
2676 }
2677
2678 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
2679 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2680
2681 Bstr HifName;
2682 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
2683 if (FAILED(hrc))
2684 {
2685 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)\n", hrc));
2686 H();
2687 }
2688
2689 Utf8Str HifNameUtf8(HifName);
2690 const char *pszHifName = HifNameUtf8.raw();
2691 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface): %s\n", pszHifName));
2692 ComPtr<IHostNetworkInterface> hostInterface;
2693 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
2694 if (!SUCCEEDED(rc))
2695 {
2696 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)\n", rc));
2697 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2698 N_("Inexistent host networking interface, name '%ls'"),
2699 HifName.raw());
2700 }
2701
2702 char szNetwork[INTNET_MAX_NETWORK_NAME];
2703 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
2704
2705#if defined(RT_OS_WINDOWS)
2706# ifndef VBOX_WITH_NETFLT
2707 hrc = E_NOTIMPL;
2708 LogRel(("NetworkAttachmentType_HostOnly: Not Implemented\n"));
2709 H();
2710# else /* defined VBOX_WITH_NETFLT*/
2711 /** @todo r=bird: Put this in a function. */
2712
2713 HostNetworkInterfaceType_T eIfType;
2714 hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
2715 if (FAILED(hrc))
2716 {
2717 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)\n", hrc));
2718 H();
2719 }
2720
2721 if (eIfType != HostNetworkInterfaceType_HostOnly)
2722 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2723 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
2724 HifName.raw());
2725
2726 hrc = hostInterface->COMGETTER(Id)(&str);
2727 if (FAILED(hrc))
2728 {
2729 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)\n", hrc));
2730 H();
2731 }
2732 Guid hostIFGuid(str);
2733 STR_FREE();
2734
2735 INetCfg *pNc;
2736 ComPtr<INetCfgComponent> pAdaptorComponent;
2737 LPWSTR pszApp;
2738 rc = VERR_INTNET_FLT_IF_NOT_FOUND;
2739
2740 hrc = VBoxNetCfgWinQueryINetCfg(FALSE,
2741 L"VirtualBox",
2742 &pNc,
2743 &pszApp);
2744 Assert(hrc == S_OK);
2745 if (hrc == S_OK)
2746 {
2747 /* get the adapter's INetCfgComponent*/
2748 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
2749 if (hrc != S_OK)
2750 {
2751 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2752 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
2753 H();
2754 }
2755 }
2756#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
2757 char szTrunkName[INTNET_MAX_TRUNK_NAME];
2758 char *pszTrunkName = szTrunkName;
2759 wchar_t * pswzBindName;
2760 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
2761 Assert(hrc == S_OK);
2762 if (hrc == S_OK)
2763 {
2764 int cwBindName = (int)wcslen(pswzBindName) + 1;
2765 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
2766 if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
2767 {
2768 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
2769 pszTrunkName += cbFullBindNamePrefix-1;
2770 if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
2771 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
2772 {
2773 DWORD err = GetLastError();
2774 hrc = HRESULT_FROM_WIN32(err);
2775 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
2776 }
2777 }
2778 else
2779 {
2780 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
2781 /** @todo set appropriate error code */
2782 hrc = E_FAIL;
2783 }
2784
2785 if (hrc != S_OK)
2786 {
2787 AssertFailed();
2788 CoTaskMemFree(pswzBindName);
2789 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2790 H();
2791 }
2792 }
2793 else
2794 {
2795 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2796 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
2797 H();
2798 }
2799
2800
2801 CoTaskMemFree(pswzBindName);
2802
2803 pAdaptorComponent.setNull();
2804 /* release the pNc finally */
2805 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2806
2807 const char *pszTrunk = szTrunkName;
2808
2809 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
2810 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
2811 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
2812 networkName = Bstr(szNetwork);
2813 trunkName = Bstr(pszTrunk);
2814 trunkType = TRUNKTYPE_NETADP;
2815# endif /* defined VBOX_WITH_NETFLT*/
2816#elif defined(RT_OS_DARWIN)
2817 rc = CFGMR3InsertString(pCfg, "Trunk", pszHifName); RC_CHECK();
2818 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
2819 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
2820 networkName = Bstr(szNetwork);
2821 trunkName = Bstr(pszHifName);
2822 trunkType = TRUNKTYPE_NETADP;
2823#else
2824 rc = CFGMR3InsertString(pCfg, "Trunk", pszHifName); RC_CHECK();
2825 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
2826 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
2827 networkName = Bstr(szNetwork);
2828 trunkName = Bstr(pszHifName);
2829 trunkType = TRUNKTYPE_NETFLT;
2830#endif
2831#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
2832
2833 Bstr tmpAddr, tmpMask;
2834
2835 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPAddress", pszHifName), tmpAddr.asOutParam());
2836 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
2837 {
2838 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPNetMask", pszHifName), tmpMask.asOutParam());
2839 if (SUCCEEDED(hrc) && !tmpMask.isEmpty())
2840 hrc = hostInterface->EnableStaticIpConfig(tmpAddr, tmpMask);
2841 else
2842 hrc = hostInterface->EnableStaticIpConfig(tmpAddr,
2843 Bstr(VBOXNET_IPV4MASK_DEFAULT));
2844 }
2845 else
2846 hrc = hostInterface->EnableStaticIpConfig(Bstr(VBOXNET_IPV4ADDR_DEFAULT),
2847 Bstr(VBOXNET_IPV4MASK_DEFAULT));
2848 ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
2849
2850 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6Address", pszHifName), tmpAddr.asOutParam());
2851 if (SUCCEEDED(hrc))
2852 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6NetMask", pszHifName), tmpMask.asOutParam());
2853 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty() && !tmpMask.isEmpty())
2854 {
2855 hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
2856 ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
2857 }
2858#endif
2859 break;
2860 }
2861
2862 default:
2863 AssertMsgFailed(("should not get here!\n"));
2864 break;
2865 }
2866
2867 /*
2868 * Attempt to attach the driver.
2869 */
2870 switch (eAttachmentType)
2871 {
2872 case NetworkAttachmentType_Null:
2873 break;
2874
2875 case NetworkAttachmentType_Bridged:
2876 case NetworkAttachmentType_Internal:
2877 case NetworkAttachmentType_HostOnly:
2878 case NetworkAttachmentType_NAT:
2879 {
2880 if (SUCCEEDED(hrc) && SUCCEEDED(rc))
2881 {
2882 if (fAttachDetach)
2883 {
2884 rc = PDMR3DriverAttach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /* ppBase */);
2885 AssertRC(rc);
2886 }
2887
2888 {
2889 /** @todo pritesh: get the dhcp server name from the
2890 * previous network configuration and then stop the server
2891 * else it may conflict with the dhcp server running with
2892 * the current attachment type
2893 */
2894 /* Stop the hostonly DHCP Server */
2895 }
2896
2897 if (!networkName.isNull())
2898 {
2899 /*
2900 * Until we implement service reference counters DHCP Server will be stopped
2901 * by DHCPServerRunner destructor.
2902 */
2903 ComPtr<IDHCPServer> dhcpServer;
2904 hrc = virtualBox->FindDHCPServerByNetworkName(networkName.mutableRaw(), dhcpServer.asOutParam());
2905 if (SUCCEEDED(hrc))
2906 {
2907 /* there is a DHCP server available for this network */
2908 BOOL fEnabled;
2909 hrc = dhcpServer->COMGETTER(Enabled)(&fEnabled);
2910 if (FAILED(hrc))
2911 {
2912 LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (%Rhrc)", hrc));
2913 H();
2914 }
2915
2916 if (fEnabled)
2917 hrc = dhcpServer->Start(networkName, trunkName, trunkType);
2918 }
2919 else
2920 hrc = S_OK;
2921 }
2922 }
2923
2924 break;
2925 }
2926
2927 default:
2928 AssertMsgFailed(("should not get here!\n"));
2929 break;
2930 }
2931
2932 pThis->meAttachmentType[uInstance] = eAttachmentType;
2933
2934#undef STR_FREE
2935#undef H
2936#undef RC_CHECK
2937
2938 return VINF_SUCCESS;
2939}
2940
2941#ifdef VBOX_WITH_GUEST_PROPS
2942/**
2943 * Set an array of guest properties
2944 */
2945static void configSetProperties(VMMDev * const pVMMDev, void *names,
2946 void *values, void *timestamps, void *flags)
2947{
2948 VBOXHGCMSVCPARM parms[4];
2949
2950 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
2951 parms[0].u.pointer.addr = names;
2952 parms[0].u.pointer.size = 0; /* We don't actually care. */
2953 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
2954 parms[1].u.pointer.addr = values;
2955 parms[1].u.pointer.size = 0; /* We don't actually care. */
2956 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
2957 parms[2].u.pointer.addr = timestamps;
2958 parms[2].u.pointer.size = 0; /* We don't actually care. */
2959 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
2960 parms[3].u.pointer.addr = flags;
2961 parms[3].u.pointer.size = 0; /* We don't actually care. */
2962
2963 pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4,
2964 &parms[0]);
2965}
2966
2967/**
2968 * Set a single guest property
2969 */
2970static void configSetProperty(VMMDev * const pVMMDev, const char *pszName,
2971 const char *pszValue, const char *pszFlags)
2972{
2973 VBOXHGCMSVCPARM parms[4];
2974
2975 AssertPtrReturnVoid(pszName);
2976 AssertPtrReturnVoid(pszValue);
2977 AssertPtrReturnVoid(pszFlags);
2978 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
2979 parms[0].u.pointer.addr = (void *)pszName;
2980 parms[0].u.pointer.size = strlen(pszName) + 1;
2981 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
2982 parms[1].u.pointer.addr = (void *)pszValue;
2983 parms[1].u.pointer.size = strlen(pszValue) + 1;
2984 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
2985 parms[2].u.pointer.addr = (void *)pszFlags;
2986 parms[2].u.pointer.size = strlen(pszFlags) + 1;
2987 pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3,
2988 &parms[0]);
2989}
2990
2991/**
2992 * Set the global flags value by calling the service
2993 * @returns the status returned by the call to the service
2994 *
2995 * @param pTable the service instance handle
2996 * @param eFlags the flags to set
2997 */
2998int configSetGlobalPropertyFlags(VMMDev * const pVMMDev,
2999 guestProp::ePropFlags eFlags)
3000{
3001 VBOXHGCMSVCPARM paParm;
3002 paParm.setUInt32(eFlags);
3003 int rc = pVMMDev->hgcmHostCall ("VBoxGuestPropSvc",
3004 guestProp::SET_GLOBAL_FLAGS_HOST, 1,
3005 &paParm);
3006 if (RT_FAILURE(rc))
3007 {
3008 char szFlags[guestProp::MAX_FLAGS_LEN];
3009 if (RT_FAILURE(writeFlags(eFlags, szFlags)))
3010 Log(("Failed to set the global flags.\n"));
3011 else
3012 Log(("Failed to set the global flags \"%s\".\n", szFlags));
3013 }
3014 return rc;
3015}
3016#endif /* VBOX_WITH_GUEST_PROPS */
3017
3018/**
3019 * Set up the Guest Property service, populate it with properties read from
3020 * the machine XML and set a couple of initial properties.
3021 */
3022/* static */ int Console::configGuestProperties(void *pvConsole)
3023{
3024#ifdef VBOX_WITH_GUEST_PROPS
3025 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
3026 ComObjPtr<Console> pConsole = static_cast <Console *> (pvConsole);
3027
3028 /* Load the service */
3029 int rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
3030
3031 if (RT_FAILURE(rc))
3032 {
3033 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
3034 /* That is not a fatal failure. */
3035 rc = VINF_SUCCESS;
3036 }
3037 else
3038 {
3039 /*
3040 * Initialize built-in properties that can be changed and saved.
3041 *
3042 * These are typically transient properties that the guest cannot
3043 * change.
3044 */
3045
3046 /* Sysprep execution by VBoxService. */
3047 configSetProperty(pConsole->mVMMDev,
3048 "/VirtualBox/HostGuest/SysprepExec", "",
3049 "TRANSIENT, RDONLYGUEST");
3050 configSetProperty(pConsole->mVMMDev,
3051 "/VirtualBox/HostGuest/SysprepArgs", "",
3052 "TRANSIENT, RDONLYGUEST");
3053
3054 /*
3055 * Pull over the properties from the server.
3056 */
3057 SafeArray<BSTR> namesOut;
3058 SafeArray<BSTR> valuesOut;
3059 SafeArray<ULONG64> timestampsOut;
3060 SafeArray<BSTR> flagsOut;
3061 HRESULT hrc;
3062 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
3063 ComSafeArrayAsOutParam(valuesOut),
3064 ComSafeArrayAsOutParam(timestampsOut),
3065 ComSafeArrayAsOutParam(flagsOut));
3066 AssertMsgReturn(SUCCEEDED(hrc), ("hrc=%Rrc\n", hrc), VERR_GENERAL_FAILURE);
3067 size_t cProps = namesOut.size();
3068 size_t cAlloc = cProps + 1;
3069 if ( valuesOut.size() != cProps
3070 || timestampsOut.size() != cProps
3071 || flagsOut.size() != cProps
3072 )
3073 AssertFailedReturn(VERR_INVALID_PARAMETER);
3074
3075 char **papszNames, **papszValues, **papszFlags;
3076 char szEmpty[] = "";
3077 ULONG64 *pau64Timestamps;
3078 papszNames = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
3079 papszValues = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
3080 pau64Timestamps = (ULONG64 *)RTMemTmpAllocZ(sizeof(ULONG64) * cAlloc);
3081 papszFlags = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
3082 if (papszNames && papszValues && pau64Timestamps && papszFlags)
3083 {
3084 for (unsigned i = 0; RT_SUCCESS(rc) && i < cProps; ++i)
3085 {
3086 AssertPtrReturn(namesOut[i], VERR_INVALID_PARAMETER);
3087 rc = RTUtf16ToUtf8(namesOut[i], &papszNames[i]);
3088 if (RT_FAILURE(rc))
3089 break;
3090 if (valuesOut[i])
3091 rc = RTUtf16ToUtf8(valuesOut[i], &papszValues[i]);
3092 else
3093 papszValues[i] = szEmpty;
3094 if (RT_FAILURE(rc))
3095 break;
3096 pau64Timestamps[i] = timestampsOut[i];
3097 if (flagsOut[i])
3098 rc = RTUtf16ToUtf8(flagsOut[i], &papszFlags[i]);
3099 else
3100 papszFlags[i] = szEmpty;
3101 }
3102 if (RT_SUCCESS(rc))
3103 configSetProperties(pConsole->mVMMDev,
3104 (void *)papszNames,
3105 (void *)papszValues,
3106 (void *)pau64Timestamps,
3107 (void *)papszFlags);
3108 for (unsigned i = 0; i < cProps; ++i)
3109 {
3110 RTStrFree(papszNames[i]);
3111 if (valuesOut[i])
3112 RTStrFree(papszValues[i]);
3113 if (flagsOut[i])
3114 RTStrFree(papszFlags[i]);
3115 }
3116 }
3117 else
3118 rc = VERR_NO_MEMORY;
3119 RTMemTmpFree(papszNames);
3120 RTMemTmpFree(papszValues);
3121 RTMemTmpFree(pau64Timestamps);
3122 RTMemTmpFree(papszFlags);
3123 AssertRCReturn(rc, rc);
3124
3125 /*
3126 * These properties have to be set before pulling over the properties
3127 * from the machine XML, to ensure that properties saved in the XML
3128 * will override them.
3129 */
3130 /* Set the VBox version string as a guest property */
3131 configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxVer",
3132 VBOX_VERSION_STRING, "TRANSIENT, RDONLYGUEST");
3133 /* Set the VBox SVN revision as a guest property */
3134 configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxRev",
3135 RTBldCfgRevisionStr(), "TRANSIENT, RDONLYGUEST");
3136
3137 /*
3138 * Register the host notification callback
3139 */
3140 HGCMSVCEXTHANDLE hDummy;
3141 HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestPropSvc",
3142 Console::doGuestPropNotification,
3143 pvConsole);
3144
3145#ifdef VBOX_WITH_GUEST_PROPS_RDONLY_GUEST
3146 rc = configSetGlobalPropertyFlags(pConsole->mVMMDev,
3147 guestProp::RDONLYGUEST);
3148 AssertRCReturn(rc, rc);
3149#endif
3150
3151 Log(("Set VBoxGuestPropSvc property store\n"));
3152 }
3153 return VINF_SUCCESS;
3154#else /* !VBOX_WITH_GUEST_PROPS */
3155 return VERR_NOT_SUPPORTED;
3156#endif /* !VBOX_WITH_GUEST_PROPS */
3157}
Note: See TracBrowser for help on using the repository browser.

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