VirtualBox

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

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

dhcp runner fixes + disabled launching code

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