VirtualBox

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

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

crOpenGL: disabled for Snow Leopard 64-bit

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 113.8 KB
Line 
1/* $Id: ConsoleImpl2.cpp 17885 2009-03-15 14:36:01Z 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 NetworkAttachmentType_T networkAttachment;
1302 hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H();
1303 switch (networkAttachment)
1304 {
1305 case NetworkAttachmentType_Null:
1306 break;
1307
1308 case NetworkAttachmentType_NAT:
1309 {
1310 if (fSniffer)
1311 {
1312 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1313 }
1314 else
1315 {
1316 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1317 }
1318 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
1319 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1320 /* (Port forwarding goes here.) */
1321
1322 /* Configure TFTP prefix and boot filename. */
1323 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
1324 STR_CONV();
1325 if (psz && *psz)
1326 {
1327 char *pszTFTPPrefix = NULL;
1328 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
1329 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix); RC_CHECK();
1330 RTStrFree(pszTFTPPrefix);
1331 }
1332 STR_FREE();
1333 hrc = pMachine->COMGETTER(Name)(&str); H();
1334 STR_CONV();
1335 char *pszBootFile = NULL;
1336 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
1337 STR_FREE();
1338 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile); RC_CHECK();
1339 RTStrFree(pszBootFile);
1340
1341 hrc = networkAdapter->COMGETTER(NATNetwork)(&str); H();
1342 if (str)
1343 {
1344 STR_CONV();
1345 if (psz && *psz)
1346 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1347 STR_FREE();
1348 }
1349 break;
1350 }
1351
1352 case NetworkAttachmentType_Bridged:
1353 {
1354 /*
1355 * Perform the attachment if required (don't return on error!)
1356 */
1357 hrc = pConsole->attachToBridgedInterface(networkAdapter);
1358 if (SUCCEEDED(hrc))
1359 {
1360#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
1361 Assert ((int)pConsole->maTapFD[ulInstance] >= 0);
1362 if ((int)pConsole->maTapFD[ulInstance] >= 0)
1363 {
1364 if (fSniffer)
1365 {
1366 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1367 }
1368 else
1369 {
1370 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1371 }
1372 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1373 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1374 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pConsole->maTapFD[ulInstance]); RC_CHECK();
1375 }
1376#elif defined(VBOX_WITH_NETFLT)
1377 /*
1378 * This is the new VBoxNetFlt+IntNet stuff.
1379 */
1380 if (fSniffer)
1381 {
1382 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1383 }
1384 else
1385 {
1386 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1387 }
1388
1389 Bstr HifName;
1390 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1391 if(FAILED(hrc))
1392 {
1393 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1394 H();
1395 }
1396
1397 Utf8Str HifNameUtf8(HifName);
1398 const char *pszHifName = HifNameUtf8.raw();
1399
1400# if defined(RT_OS_DARWIN)
1401 /* The name is on the form 'ifX: long name', chop it off at the colon. */
1402 char szTrunk[8];
1403 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
1404 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1405 if (!pszColon)
1406 {
1407 hrc = networkAdapter->Detach(); H();
1408 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1409 N_("Malformed host interface networking name '%ls'"),
1410 HifName.raw());
1411 }
1412 *pszColon = '\0';
1413 const char *pszTrunk = szTrunk;
1414
1415# elif defined(RT_OS_SOLARIS)
1416 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
1417 char szTrunk[256];
1418 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
1419 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
1420
1421 /*
1422 * Currently don't bother about malformed names here for the sake of people using
1423 * VBoxManage and setting only the NIC name from there. If there is a space we
1424 * chop it off and proceed, otherwise just use whatever we've got.
1425 */
1426 if (pszSpace)
1427 *pszSpace = '\0';
1428
1429 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
1430 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1431 if (pszColon)
1432 *pszColon = '\0';
1433
1434 const char *pszTrunk = szTrunk;
1435
1436# elif defined(RT_OS_WINDOWS)
1437 ComPtr<IHostNetworkInterface> hostInterface;
1438 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1439 if (!SUCCEEDED(rc))
1440 {
1441 AssertBreakpoint();
1442 LogRel(("NetworkAttachmentType_Bridged: FindByName failed, rc (0x%x)", rc));
1443 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1444 N_("Inexistent host networking interface, name '%ls'"),
1445 HifName.raw());
1446 }
1447
1448 HostNetworkInterfaceType_T ifType;
1449 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
1450 if(FAILED(hrc))
1451 {
1452 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
1453 H();
1454 }
1455
1456 if(ifType != HostNetworkInterfaceType_Bridged)
1457 {
1458 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1459 N_("Interface ('%ls') is not a Bridged Adapter interface"),
1460 HifName.raw());
1461 }
1462
1463 Guid hostIFGuid;
1464 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1465 if(FAILED(hrc))
1466 {
1467 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1468 H();
1469 }
1470 char szDriverGUID[RTUUID_STR_LENGTH];
1471 strcpy(szDriverGUID , hostIFGuid.toString().raw());
1472 const char *pszTrunk = szDriverGUID;
1473# elif defined(RT_OS_LINUX)
1474 /* @todo Check for malformed names. */
1475 const char *pszTrunk = pszHifName;
1476
1477# else
1478# error "PORTME (VBOX_WITH_NETFLT)"
1479# endif
1480
1481 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1482 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1483 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1484 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1485 char szNetwork[80];
1486 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1487 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1488
1489# if defined(RT_OS_DARWIN)
1490 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
1491 if ( strstr(pszHifName, "Wireless")
1492 || strstr(pszHifName, "AirPort" ))
1493 {
1494 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1495 }
1496# elif defined(RT_OS_LINUX)
1497 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
1498 if (iSock >= 0)
1499 {
1500 struct iwreq WRq;
1501
1502 memset(&WRq, 0, sizeof(WRq));
1503 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
1504 if (ioctl(iSock, SIOCGIWNAME, &WRq) >= 0)
1505 {
1506 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1507 Log(("Set SharedMacOnWire\n"));
1508 }
1509 else
1510 {
1511 Log(("Failed to get wireless name\n"));
1512 }
1513 close(iSock);
1514 }
1515 else
1516 {
1517 Log(("Failed to open wireless socket\n"));
1518 }
1519# elif defined(RT_OS_WINDOWS)
1520# define DEVNAME_PREFIX L"\\\\.\\"
1521 INetCfg *pNc;
1522 LPWSTR lpszApp;
1523 HRESULT hr;
1524 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
1525
1526 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
1527 * there is a pretty long way till there though since we need to obtain the symbolic link name
1528 * for the adapter device we are going to query given the device Guid */
1529 hr = VBoxNetCfgWinQueryINetCfg( FALSE,
1530 L"VirtualBox",
1531 &pNc,
1532 &lpszApp );
1533 Assert(hr == S_OK);
1534 if(hr == S_OK)
1535 {
1536 /* get the adapter's INetCfgComponent*/
1537 INetCfgComponent *pAdaptorComponent;
1538 hr = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), &pAdaptorComponent);
1539 Assert(hr == S_OK);
1540 if(hr == S_OK)
1541 {
1542 /* now get the bind name */
1543 LPWSTR pName;
1544 hr = pAdaptorComponent->GetBindName(&pName);
1545 Assert(hr == S_OK);
1546 if(hr == S_OK)
1547 {
1548 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
1549 wchar_t FileName[MAX_PATH];
1550 wcscpy(FileName, DEVNAME_PREFIX);
1551 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pName);
1552
1553 /* open the device */
1554 HANDLE hDevice = CreateFile(FileName,
1555 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
1556 NULL,
1557 OPEN_EXISTING,
1558 FILE_ATTRIBUTE_NORMAL,
1559 NULL);
1560 if (hDevice != INVALID_HANDLE_VALUE)
1561 {
1562 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
1563 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
1564 NDIS_PHYSICAL_MEDIUM PhMedium;
1565 DWORD cbResult;
1566 if (DeviceIoControl(hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, &Oid, sizeof(Oid), &PhMedium, sizeof(PhMedium), &cbResult, NULL))
1567 {
1568 /* that was simple, now examine PhMedium */
1569 if(PhMedium == NdisPhysicalMediumWirelessWan
1570 || PhMedium == NdisPhysicalMediumWirelessLan
1571 || PhMedium == NdisPhysicalMediumNative802_11
1572 || PhMedium == NdisPhysicalMediumBluetooth
1573 /*|| PhMedium == NdisPhysicalMediumWiMax*/
1574 )
1575 {
1576 Log(("this is a wireles adapter"));
1577 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1578 Log(("Set SharedMacOnWire\n"));
1579 }
1580 else
1581 {
1582 Log(("this is NOT a wireles adapter"));
1583 }
1584 }
1585 else
1586 {
1587 int winEr = GetLastError();
1588 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
1589 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
1590 }
1591
1592 CloseHandle(hDevice);
1593 }
1594 else
1595 {
1596 int winEr = GetLastError();
1597 LogRel(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
1598 AssertBreakpoint();
1599 }
1600 CoTaskMemFree(pName);
1601 }
1602 VBoxNetCfgWinReleaseRef(pAdaptorComponent);
1603 }
1604 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1605 }
1606# else
1607 /** @todo PORTME: wireless detection */
1608# endif
1609
1610# if defined(RT_OS_SOLARIS)
1611# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
1612 /* Zone access restriction, don't allow snopping the global zone. */
1613 zoneid_t ZoneId = getzoneid();
1614 if (ZoneId != GLOBAL_ZONEID)
1615 {
1616 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
1617 }
1618# endif
1619# endif
1620
1621#elif defined(RT_OS_WINDOWS)
1622 if (fSniffer)
1623 {
1624 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1625 }
1626 else
1627 {
1628 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1629 }
1630 Bstr hostInterfaceName;
1631 hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
1632 ComPtr<IHostNetworkInterface> hostInterface;
1633 rc = host->FindHostNetworkInterfaceByName(hostInterfaceName, hostInterface.asOutParam());
1634 if (!SUCCEEDED(rc))
1635 {
1636 AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
1637 hrc = networkAdapter->Detach(); H();
1638 }
1639 else
1640 {
1641# ifndef VBOX_WITH_NETFLT
1642 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1643 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1644 rc = CFGMR3InsertString(pCfg, "HostInterfaceName", Utf8Str(hostInterfaceName)); RC_CHECK();
1645# else
1646 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1647 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1648 rc = CFGMR3InsertString(pCfg, "Trunk", Utf8Str(hostInterfaceName)); RC_CHECK();
1649 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1650# endif
1651 Guid hostIFGuid;
1652 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1653 char szDriverGUID[256] = {0};
1654 /* add curly brackets */
1655 szDriverGUID[0] = '{';
1656 strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
1657 strcat(szDriverGUID, "}");
1658 rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
1659 }
1660#elif defined(RT_OS_LINUX)
1661/// @todo aleksey: is there anything to be done here?
1662#elif defined(RT_OS_FREEBSD)
1663/** @todo FreeBSD: Check out this later (HIF networking). */
1664#else
1665# error "Port me"
1666#endif
1667 }
1668 else
1669 {
1670 switch (hrc)
1671 {
1672#ifdef RT_OS_LINUX
1673 case VERR_ACCESS_DENIED:
1674 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1675 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1676 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
1677 "change the group of that node and make yourself a member of that group. Make "
1678 "sure that these changes are permanent, especially if you are "
1679 "using udev"));
1680#endif /* RT_OS_LINUX */
1681 default:
1682 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1683 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1684 "Failed to initialize Host Interface Networking"));
1685 }
1686 }
1687 break;
1688 }
1689
1690 case NetworkAttachmentType_Internal:
1691 {
1692 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1693 if (str)
1694 {
1695 STR_CONV();
1696 if (psz && *psz)
1697 {
1698 if (fSniffer)
1699 {
1700 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1701 }
1702 else
1703 {
1704 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1705 }
1706 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1707 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1708 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1709 }
1710 STR_FREE();
1711 }
1712 break;
1713 }
1714
1715 case NetworkAttachmentType_HostOnly:
1716 {
1717 if (fSniffer)
1718 {
1719 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1720 }
1721 else
1722 {
1723 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1724 }
1725
1726 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1727 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1728#if defined(RT_OS_WINDOWS)
1729 Bstr HifName;
1730 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1731 if(FAILED(hrc))
1732 {
1733 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1734 H();
1735 }
1736
1737 Utf8Str HifNameUtf8(HifName);
1738 const char *pszHifName = HifNameUtf8.raw();
1739 ComPtr<IHostNetworkInterface> hostInterface;
1740 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1741 if (!SUCCEEDED(rc))
1742 {
1743 AssertBreakpoint();
1744 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)", rc));
1745 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1746 N_("Inexistent host networking interface, name '%ls'"),
1747 HifName.raw());
1748 }
1749
1750 HostNetworkInterfaceType_T ifType;
1751 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
1752 if(FAILED(hrc))
1753 {
1754 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
1755 H();
1756 }
1757
1758 if(ifType != HostNetworkInterfaceType_HostOnly)
1759 {
1760 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1761 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
1762 HifName.raw());
1763 }
1764
1765
1766 Guid hostIFGuid;
1767 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1768 if(FAILED(hrc))
1769 {
1770 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1771 H();
1772 }
1773 char szDriverGUID[RTUUID_STR_LENGTH];
1774 strcpy(szDriverGUID , hostIFGuid.toString().raw());
1775 const char *pszTrunk = szDriverGUID;
1776
1777 /* TODO: set the proper Trunk and Network values, currently the driver uses the first adapter instance */
1778 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
1779 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1780 char szNetwork[80];
1781 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1782 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1783#elif defined(RT_OS_DARWIN)
1784 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK();
1785 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0"); RC_CHECK();
1786 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
1787#else
1788 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK();
1789 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0"); RC_CHECK();
1790 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1791#endif
1792 break;
1793 }
1794
1795 default:
1796 AssertMsgFailed(("should not get here!\n"));
1797 break;
1798 }
1799 }
1800
1801 /*
1802 * Serial (UART) Ports
1803 */
1804 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1805 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1806 {
1807 ComPtr<ISerialPort> serialPort;
1808 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1809 BOOL fEnabled = FALSE;
1810 if (serialPort)
1811 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1812 if (!fEnabled)
1813 continue;
1814
1815 char szInstance[4]; Assert(ulInstance <= 999);
1816 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1817
1818 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1819 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1820
1821 ULONG ulIRQ, ulIOBase;
1822 PortMode_T HostMode;
1823 Bstr path;
1824 BOOL fServer;
1825 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1826 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1827 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1828 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1829 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1830 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1831 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1832 if (HostMode != PortMode_Disconnected)
1833 {
1834 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1835 if (HostMode == PortMode_HostPipe)
1836 {
1837 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1838 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1839 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1840 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1841 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1842 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1843 }
1844 else if (HostMode == PortMode_HostDevice)
1845 {
1846 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1847 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1848 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1849 }
1850 }
1851 }
1852
1853 /*
1854 * Parallel (LPT) Ports
1855 */
1856 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1857 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1858 {
1859 ComPtr<IParallelPort> parallelPort;
1860 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1861 BOOL fEnabled = FALSE;
1862 if (parallelPort)
1863 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1864 if (!fEnabled)
1865 continue;
1866
1867 char szInstance[4]; Assert(ulInstance <= 999);
1868 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1869
1870 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1871 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1872
1873 ULONG ulIRQ, ulIOBase;
1874 Bstr DevicePath;
1875 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1876 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1877 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1878 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1879 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1880 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1881 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1882 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1883 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1884 }
1885
1886 /*
1887 * VMM Device
1888 */
1889 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1890 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1891 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1892 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1893 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1894 Assert(!afPciDeviceNo[4]);
1895 afPciDeviceNo[4] = true;
1896 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1897 Bstr hwVersion;
1898 hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
1899 if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
1900 {
1901 CFGMR3InsertInteger(pCfg, "HeapEnabled", 0); RC_CHECK();
1902 }
1903
1904 /* the VMM device's Main driver */
1905 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1906 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1907 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1908 VMMDev *pVMMDev = pConsole->mVMMDev;
1909 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1910
1911 /*
1912 * Attach the status driver.
1913 */
1914 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1915 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1916 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1917 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1918 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1919 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1920
1921 /*
1922 * Audio Sniffer Device
1923 */
1924 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1925 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1926 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1927
1928 /* the Audio Sniffer device's Main driver */
1929 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1930 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1931 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1932 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1933 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1934
1935 /*
1936 * AC'97 ICH / SoundBlaster16 audio
1937 */
1938 BOOL enabled;
1939 ComPtr<IAudioAdapter> audioAdapter;
1940 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1941 if (audioAdapter)
1942 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1943
1944 if (enabled)
1945 {
1946 AudioControllerType_T audioController;
1947 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
1948 switch (audioController)
1949 {
1950 case AudioControllerType_AC97:
1951 {
1952 /* default: ICH AC97 */
1953 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
1954 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1955 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1956 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1957 Assert(!afPciDeviceNo[5]);
1958 afPciDeviceNo[5] = true;
1959 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1960 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1961 break;
1962 }
1963 case AudioControllerType_SB16:
1964 {
1965 /* legacy SoundBlaster16 */
1966 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
1967 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1968 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1969 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1970 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
1971 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
1972 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
1973 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
1974 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
1975 break;
1976 }
1977 }
1978
1979 /* the Audio driver */
1980 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1981 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1982 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1983
1984 AudioDriverType_T audioDriver;
1985 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1986 switch (audioDriver)
1987 {
1988 case AudioDriverType_Null:
1989 {
1990 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1991 break;
1992 }
1993#ifdef RT_OS_WINDOWS
1994#ifdef VBOX_WITH_WINMM
1995 case AudioDriverType_WinMM:
1996 {
1997 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1998 break;
1999 }
2000#endif
2001 case AudioDriverType_DirectSound:
2002 {
2003 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
2004 break;
2005 }
2006#endif /* RT_OS_WINDOWS */
2007#ifdef RT_OS_SOLARIS
2008 case AudioDriverType_SolAudio:
2009 {
2010 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
2011 break;
2012 }
2013#endif
2014#ifdef RT_OS_LINUX
2015 case AudioDriverType_OSS:
2016 {
2017 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
2018 break;
2019 }
2020# ifdef VBOX_WITH_ALSA
2021 case AudioDriverType_ALSA:
2022 {
2023 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
2024 break;
2025 }
2026# endif
2027# ifdef VBOX_WITH_PULSE
2028 case AudioDriverType_Pulse:
2029 {
2030 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
2031 break;
2032 }
2033# endif
2034#endif /* RT_OS_LINUX */
2035#ifdef RT_OS_DARWIN
2036 case AudioDriverType_CoreAudio:
2037 {
2038 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
2039 break;
2040 }
2041#endif
2042 }
2043 hrc = pMachine->COMGETTER(Name)(&str); H();
2044 STR_CONV();
2045 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
2046 STR_FREE();
2047 }
2048
2049 /*
2050 * The USB Controller.
2051 */
2052 ComPtr<IUSBController> USBCtlPtr;
2053 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
2054 if (USBCtlPtr)
2055 {
2056 BOOL fEnabled;
2057 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
2058 if (fEnabled)
2059 {
2060 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
2061 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2062 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2063 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
2064 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
2065 Assert(!afPciDeviceNo[6]);
2066 afPciDeviceNo[6] = true;
2067 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2068
2069 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2070 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2071 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2072
2073 /*
2074 * Attach the status driver.
2075 */
2076 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2077 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2078 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2079 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
2080 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2081 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2082
2083#ifdef VBOX_WITH_EHCI
2084 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
2085 if (fEnabled)
2086 {
2087 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
2088 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2089 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2090 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2091 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
2092 Assert(!afPciDeviceNo[11]);
2093 afPciDeviceNo[11] = true;
2094 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2095
2096 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2097 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2098 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2099
2100 /*
2101 * Attach the status driver.
2102 */
2103 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2104 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2105 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2106 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
2107 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2108 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2109 }
2110 else
2111#endif
2112 {
2113 /*
2114 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
2115 * on a per device level now.
2116 */
2117 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
2118 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
2119 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
2120 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
2121 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
2122 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
2123 // that it's documented somewhere.) Users needing it can use:
2124 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
2125 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
2126 }
2127 }
2128 }
2129
2130 /*
2131 * Clipboard
2132 */
2133 {
2134 ClipboardMode_T mode = ClipboardMode_Disabled;
2135 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
2136
2137 if (mode != ClipboardMode_Disabled)
2138 {
2139 /* Load the service */
2140 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
2141
2142 if (RT_FAILURE (rc))
2143 {
2144 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
2145 /* That is not a fatal failure. */
2146 rc = VINF_SUCCESS;
2147 }
2148 else
2149 {
2150 /* Setup the service. */
2151 VBOXHGCMSVCPARM parm;
2152
2153 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2154
2155 switch (mode)
2156 {
2157 default:
2158 case ClipboardMode_Disabled:
2159 {
2160 LogRel(("VBoxSharedClipboard mode: Off\n"));
2161 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
2162 break;
2163 }
2164 case ClipboardMode_GuestToHost:
2165 {
2166 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
2167 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
2168 break;
2169 }
2170 case ClipboardMode_HostToGuest:
2171 {
2172 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
2173 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
2174 break;
2175 }
2176 case ClipboardMode_Bidirectional:
2177 {
2178 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
2179 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
2180 break;
2181 }
2182 }
2183
2184 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
2185
2186 Log(("Set VBoxSharedClipboard mode\n"));
2187 }
2188 }
2189 }
2190
2191#ifdef VBOX_WITH_CROGL
2192/* Currently broken on Snow Leopard 64-bit */
2193# if !(defined(RT_OS_DARWIN) && defined(RT_ARCH_AMD64))
2194 /*
2195 * crOpenGL
2196 */
2197 {
2198 BOOL fEnabled = false;
2199 hrc = pMachine->COMGETTER(Accelerate3DEnabled) (&fEnabled); H();
2200
2201 if (fEnabled)
2202 {
2203 /* Load the service */
2204 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
2205 if (RT_FAILURE(rc))
2206 {
2207 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
2208 /* That is not a fatal failure. */
2209 rc = VINF_SUCCESS;
2210 }
2211 else
2212 {
2213 LogRel(("Shared crOpenGL service loaded.\n"));
2214
2215 /* Setup the service. */
2216 VBOXHGCMSVCPARM parm;
2217 parm.type = VBOX_HGCM_SVC_PARM_PTR;
2218
2219 //parm.u.pointer.addr = static_cast <IConsole *> (pData->pVMMDev->getParent());
2220 parm.u.pointer.addr = pConsole->mVMMDev->getParent()->getDisplay()->getFramebuffer();
2221 parm.u.pointer.size = sizeof(IFramebuffer *);
2222
2223 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_FRAMEBUFFER, 1, &parm);
2224 if (!RT_SUCCESS(rc))
2225 AssertMsgFailed(("SHCRGL_HOST_FN_SET_FRAMEBUFFER failed with %Rrc\n", rc));
2226 }
2227 }
2228 }
2229# endif
2230#endif
2231
2232#ifdef VBOX_WITH_GUEST_PROPS
2233 /*
2234 * Guest property service
2235 */
2236 {
2237 /* Load the service */
2238 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
2239
2240 if (RT_FAILURE (rc))
2241 {
2242 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
2243 /* That is not a fatal failure. */
2244 rc = VINF_SUCCESS;
2245 }
2246 else
2247 {
2248 /* Pull over the properties from the server. */
2249 SafeArray <BSTR> namesOut;
2250 SafeArray <BSTR> valuesOut;
2251 SafeArray <ULONG64> timestampsOut;
2252 SafeArray <BSTR> flagsOut;
2253 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
2254 ComSafeArrayAsOutParam(valuesOut),
2255 ComSafeArrayAsOutParam(timestampsOut),
2256 ComSafeArrayAsOutParam(flagsOut)); H();
2257 size_t cProps = namesOut.size();
2258 if ( valuesOut.size() != cProps
2259 || timestampsOut.size() != cProps
2260 || flagsOut.size() != cProps
2261 )
2262 rc = VERR_INVALID_PARAMETER;
2263
2264 std::vector <Utf8Str> utf8Names, utf8Values, utf8Flags;
2265 std::vector <char *> names, values, flags;
2266 std::vector <ULONG64> timestamps;
2267 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2268 if ( !VALID_PTR(namesOut[i])
2269 || !VALID_PTR(valuesOut[i])
2270 || !VALID_PTR(flagsOut[i])
2271 )
2272 rc = VERR_INVALID_POINTER;
2273 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2274 {
2275 utf8Names.push_back(Bstr(namesOut[i]));
2276 utf8Values.push_back(Bstr(valuesOut[i]));
2277 timestamps.push_back(timestampsOut[i]);
2278 utf8Flags.push_back(Bstr(flagsOut[i]));
2279 if ( utf8Names.back().isNull()
2280 || utf8Values.back().isNull()
2281 || utf8Flags.back().isNull()
2282 )
2283 throw std::bad_alloc();
2284 }
2285 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2286 {
2287 names.push_back(utf8Names[i].mutableRaw());
2288 values.push_back(utf8Values[i].mutableRaw());
2289 flags.push_back(utf8Flags[i].mutableRaw());
2290 }
2291 names.push_back(NULL);
2292 values.push_back(NULL);
2293 timestamps.push_back(0);
2294 flags.push_back(NULL);
2295
2296 /* Setup the service. */
2297 VBOXHGCMSVCPARM parms[4];
2298
2299 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
2300 parms[0].u.pointer.addr = &names.front();
2301 parms[0].u.pointer.size = 0; /* We don't actually care. */
2302 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
2303 parms[1].u.pointer.addr = &values.front();
2304 parms[1].u.pointer.size = 0; /* We don't actually care. */
2305 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
2306 parms[2].u.pointer.addr = &timestamps.front();
2307 parms[2].u.pointer.size = 0; /* We don't actually care. */
2308 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
2309 parms[3].u.pointer.addr = &flags.front();
2310 parms[3].u.pointer.size = 0; /* We don't actually care. */
2311
2312 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4, &parms[0]);
2313
2314 /* Register the host notification callback */
2315 HGCMSVCEXTHANDLE hDummy;
2316 HGCMHostRegisterServiceExtension (&hDummy, "VBoxGuestPropSvc",
2317 Console::doGuestPropNotification,
2318 pvConsole);
2319
2320 Log(("Set VBoxGuestPropSvc property store\n"));
2321 }
2322 }
2323#endif /* VBOX_WITH_GUEST_PROPS defined */
2324
2325 /*
2326 * CFGM overlay handling.
2327 *
2328 * Here we check the extra data entries for CFGM values
2329 * and create the nodes and insert the values on the fly. Existing
2330 * values will be removed and reinserted. CFGM is typed, so by default
2331 * we will guess whether it's a string or an integer (byte arrays are
2332 * not currently supported). It's possible to override this autodetection
2333 * by adding "string:", "integer:" or "bytes:" (future).
2334 *
2335 * We first perform a run on global extra data, then on the machine
2336 * extra data to support global settings with local overrides.
2337 *
2338 */
2339 /** @todo add support for removing nodes and byte blobs. */
2340 Bstr strExtraDataKey;
2341 bool fGlobalExtraData = true;
2342 for (;;)
2343 {
2344 /*
2345 * Get the next key
2346 */
2347 Bstr strNextExtraDataKey;
2348 Bstr strExtraDataValue;
2349 if (fGlobalExtraData)
2350 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2351 strExtraDataValue.asOutParam());
2352 else
2353 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2354 strExtraDataValue.asOutParam());
2355
2356 /* stop if for some reason there's nothing more to request */
2357 if (FAILED(hrc) || !strNextExtraDataKey)
2358 {
2359 /* if we're out of global keys, continue with machine, otherwise we're done */
2360 if (fGlobalExtraData)
2361 {
2362 fGlobalExtraData = false;
2363 strExtraDataKey.setNull();
2364 continue;
2365 }
2366 break;
2367 }
2368 strExtraDataKey = strNextExtraDataKey;
2369
2370 /*
2371 * We only care about keys starting with "VBoxInternal/"
2372 */
2373 Utf8Str strExtraDataKeyUtf8(strExtraDataKey);
2374 char *pszExtraDataKey = (char *)strExtraDataKeyUtf8.raw();
2375 if (strncmp(pszExtraDataKey, "VBoxInternal/", sizeof("VBoxInternal/") - 1) != 0)
2376 continue;
2377 pszExtraDataKey += sizeof("VBoxInternal/") - 1;
2378
2379 /*
2380 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2381 * Split the two and get the node, delete the value and create the node
2382 * if necessary.
2383 */
2384 PCFGMNODE pNode;
2385 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2386 if (pszCFGMValueName)
2387 {
2388 /* terminate the node and advance to the value (Utf8Str might not
2389 offically like this but wtf) */
2390 *pszCFGMValueName = '\0';
2391 pszCFGMValueName++;
2392
2393 /* does the node already exist? */
2394 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2395 if (pNode)
2396 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2397 else
2398 {
2399 /* create the node */
2400 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2401 if (RT_FAILURE(rc))
2402 {
2403 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2404 continue;
2405 }
2406 Assert(pNode);
2407 }
2408 }
2409 else
2410 {
2411 /* root value (no node path). */
2412 pNode = pRoot;
2413 pszCFGMValueName = pszExtraDataKey;
2414 pszExtraDataKey--;
2415 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2416 }
2417
2418 /*
2419 * Now let's have a look at the value.
2420 * Empty strings means that we should remove the value, which we've
2421 * already done above.
2422 */
2423 Utf8Str strCFGMValueUtf8(strExtraDataValue);
2424 const char *pszCFGMValue = strCFGMValueUtf8.raw();
2425 if ( pszCFGMValue
2426 && *pszCFGMValue)
2427 {
2428 uint64_t u64Value;
2429
2430 /* check for type prefix first. */
2431 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
2432 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
2433 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
2434 {
2435 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
2436 if (RT_SUCCESS(rc))
2437 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2438 }
2439 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
2440 rc = VERR_NOT_IMPLEMENTED;
2441 /* auto detect type. */
2442 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
2443 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2444 else
2445 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
2446 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
2447 }
2448 }
2449
2450#undef H
2451#undef RC_CHECK
2452#undef STR_FREE
2453#undef STR_CONV
2454
2455 /* Register VM state change handler */
2456 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2457 AssertRC (rc2);
2458 if (RT_SUCCESS (rc))
2459 rc = rc2;
2460
2461 /* Register VM runtime error handler */
2462 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2463 AssertRC (rc2);
2464 if (RT_SUCCESS (rc))
2465 rc = rc2;
2466
2467 /* Save the VM pointer in the machine object */
2468 pConsole->mpVM = pVM;
2469
2470 LogFlowFunc (("vrc = %Rrc\n", rc));
2471 LogFlowFuncLeave();
2472
2473 return rc;
2474}
2475/* 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