VirtualBox

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

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

Main: firmware type setter

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