VirtualBox

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

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

ConsoleImpl2.cpp: Minore BSTR leak (not on branches). Good pratice to keep initialized variables on separate lines.

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

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