VirtualBox

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

Last change on this file since 23009 was 23008, checked in by vboxsync, 16 years ago

Main: increased the maximum length of host-only internal network names from 80 to INTNET_MAX_NETWORK_NAME (128) characters

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

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