VirtualBox

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

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

dhcp config/launch fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 116.9 KB
Line 
1/* $Id: ConsoleImpl2.cpp 17961 2009-03-16 17:47:47Z 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.215389.xyz. 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 if(!networkName.isNull())
1812 {
1813 ComPtr<IDhcpServer> dhcpServer;
1814 hrc = virtualBox->FindDhcpServerByName(networkName.mutableRaw(), dhcpServer.asOutParam());
1815 if(SUCCEEDED(hrc))
1816 {
1817 /* there is a DHCP server available for this network */
1818 BOOL bEnabled;
1819 hrc = dhcpServer->COMGETTER(Enabled)(&bEnabled);
1820 if(FAILED(hrc))
1821 {
1822 LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (0x%x)", hrc));
1823 H();
1824 }
1825
1826 if(bEnabled)
1827 {
1828 Bstr ip, mask, lowerIp, upperIp;
1829
1830 hrc = dhcpServer->COMGETTER(IPAddress)(ip.asOutParam());
1831 if(FAILED(hrc))
1832 {
1833 LogRel(("DHCP svr: COMGETTER(IPAddress) failed, hrc (0x%x)", hrc));
1834 H();
1835 }
1836
1837 hrc = dhcpServer->COMGETTER(NetworkMask)(mask.asOutParam());
1838 if(FAILED(hrc))
1839 {
1840 LogRel(("DHCP svr: COMGETTER(NetworkMask) failed, hrc (0x%x)", hrc));
1841 H();
1842 }
1843
1844 hrc = dhcpServer->COMGETTER(LowerIP)(lowerIp.asOutParam());
1845 if(FAILED(hrc))
1846 {
1847 LogRel(("DHCP svr: COMGETTER(LowerIP) failed, hrc (0x%x)", hrc));
1848 H();
1849 }
1850
1851 hrc = dhcpServer->COMGETTER(UpperIP)(upperIp.asOutParam());
1852 if(FAILED(hrc))
1853 {
1854 LogRel(("DHCP svr: COMGETTER(UpperIP) failed, hrc (0x%x)", hrc));
1855 H();
1856 }
1857
1858 char strMAC[13];
1859 Guid guid;
1860 guid.create();
1861 RTStrPrintf (strMAC, sizeof(strMAC), "080027%02X%02X%02X",
1862 guid.ptr()->au8[0], guid.ptr()->au8[1], guid.ptr()->au8[2]);
1863
1864 rc = CFGMR3InsertString(pCfg, "DhcpIPAddress", Utf8Str(ip).raw()); RC_CHECK();
1865 rc = CFGMR3InsertString(pCfg, "DhcpNetworkMask", Utf8Str(mask).raw()); RC_CHECK();
1866 rc = CFGMR3InsertString(pCfg, "DhcpLowerIP", Utf8Str(lowerIp).raw()); RC_CHECK();
1867 rc = CFGMR3InsertString(pCfg, "DhcpUpperIP", Utf8Str(upperIp).raw()); RC_CHECK();
1868 rc = CFGMR3InsertString(pCfg, "DhcpMacAddress", strMAC); RC_CHECK();
1869 }
1870 }
1871 else
1872 {
1873 hrc = S_OK;
1874 }
1875 }
1876
1877 }
1878
1879 /*
1880 * Serial (UART) Ports
1881 */
1882 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1883 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1884 {
1885 ComPtr<ISerialPort> serialPort;
1886 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1887 BOOL fEnabled = FALSE;
1888 if (serialPort)
1889 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1890 if (!fEnabled)
1891 continue;
1892
1893 char szInstance[4]; Assert(ulInstance <= 999);
1894 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1895
1896 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1897 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1898
1899 ULONG ulIRQ, ulIOBase;
1900 PortMode_T HostMode;
1901 Bstr path;
1902 BOOL fServer;
1903 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1904 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1905 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1906 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1907 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1908 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1909 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1910 if (HostMode != PortMode_Disconnected)
1911 {
1912 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1913 if (HostMode == PortMode_HostPipe)
1914 {
1915 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1916 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1917 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1918 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1919 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1920 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1921 }
1922 else if (HostMode == PortMode_HostDevice)
1923 {
1924 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1925 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1926 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1927 }
1928 }
1929 }
1930
1931 /*
1932 * Parallel (LPT) Ports
1933 */
1934 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1935 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1936 {
1937 ComPtr<IParallelPort> parallelPort;
1938 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1939 BOOL fEnabled = FALSE;
1940 if (parallelPort)
1941 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1942 if (!fEnabled)
1943 continue;
1944
1945 char szInstance[4]; Assert(ulInstance <= 999);
1946 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1947
1948 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1949 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1950
1951 ULONG ulIRQ, ulIOBase;
1952 Bstr DevicePath;
1953 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1954 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1955 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1956 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1957 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1958 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1959 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1960 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1961 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1962 }
1963
1964 /*
1965 * VMM Device
1966 */
1967 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1968 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1969 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1970 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1971 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1972 Assert(!afPciDeviceNo[4]);
1973 afPciDeviceNo[4] = true;
1974 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1975 Bstr hwVersion;
1976 hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
1977 if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
1978 {
1979 CFGMR3InsertInteger(pCfg, "HeapEnabled", 0); RC_CHECK();
1980 }
1981
1982 /* the VMM device's Main driver */
1983 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1984 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1985 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1986 VMMDev *pVMMDev = pConsole->mVMMDev;
1987 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1988
1989 /*
1990 * Attach the status driver.
1991 */
1992 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1993 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1994 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1995 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1996 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1997 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1998
1999 /*
2000 * Audio Sniffer Device
2001 */
2002 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
2003 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2004 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2005
2006 /* the Audio Sniffer device's Main driver */
2007 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2008 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
2009 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2010 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
2011 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
2012
2013 /*
2014 * AC'97 ICH / SoundBlaster16 audio
2015 */
2016 BOOL enabled;
2017 ComPtr<IAudioAdapter> audioAdapter;
2018 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
2019 if (audioAdapter)
2020 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
2021
2022 if (enabled)
2023 {
2024 AudioControllerType_T audioController;
2025 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
2026 switch (audioController)
2027 {
2028 case AudioControllerType_AC97:
2029 {
2030 /* default: ICH AC97 */
2031 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
2032 rc = CFGMR3InsertNode(pDev, "0", &pInst);
2033 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2034 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
2035 Assert(!afPciDeviceNo[5]);
2036 afPciDeviceNo[5] = true;
2037 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2038 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2039 break;
2040 }
2041 case AudioControllerType_SB16:
2042 {
2043 /* legacy SoundBlaster16 */
2044 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
2045 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2046 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2047 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2048 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
2049 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
2050 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
2051 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
2052 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
2053 break;
2054 }
2055 }
2056
2057 /* the Audio driver */
2058 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2059 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
2060 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2061
2062 AudioDriverType_T audioDriver;
2063 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
2064 switch (audioDriver)
2065 {
2066 case AudioDriverType_Null:
2067 {
2068 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
2069 break;
2070 }
2071#ifdef RT_OS_WINDOWS
2072#ifdef VBOX_WITH_WINMM
2073 case AudioDriverType_WinMM:
2074 {
2075 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
2076 break;
2077 }
2078#endif
2079 case AudioDriverType_DirectSound:
2080 {
2081 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
2082 break;
2083 }
2084#endif /* RT_OS_WINDOWS */
2085#ifdef RT_OS_SOLARIS
2086 case AudioDriverType_SolAudio:
2087 {
2088 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
2089 break;
2090 }
2091#endif
2092#ifdef RT_OS_LINUX
2093 case AudioDriverType_OSS:
2094 {
2095 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
2096 break;
2097 }
2098# ifdef VBOX_WITH_ALSA
2099 case AudioDriverType_ALSA:
2100 {
2101 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
2102 break;
2103 }
2104# endif
2105# ifdef VBOX_WITH_PULSE
2106 case AudioDriverType_Pulse:
2107 {
2108 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
2109 break;
2110 }
2111# endif
2112#endif /* RT_OS_LINUX */
2113#ifdef RT_OS_DARWIN
2114 case AudioDriverType_CoreAudio:
2115 {
2116 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
2117 break;
2118 }
2119#endif
2120 }
2121 hrc = pMachine->COMGETTER(Name)(&str); H();
2122 STR_CONV();
2123 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
2124 STR_FREE();
2125 }
2126
2127 /*
2128 * The USB Controller.
2129 */
2130 ComPtr<IUSBController> USBCtlPtr;
2131 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
2132 if (USBCtlPtr)
2133 {
2134 BOOL fEnabled;
2135 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
2136 if (fEnabled)
2137 {
2138 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
2139 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2140 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2141 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
2142 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
2143 Assert(!afPciDeviceNo[6]);
2144 afPciDeviceNo[6] = true;
2145 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2146
2147 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2148 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2149 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2150
2151 /*
2152 * Attach the status driver.
2153 */
2154 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2155 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2156 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2157 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
2158 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2159 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2160
2161#ifdef VBOX_WITH_EHCI
2162 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
2163 if (fEnabled)
2164 {
2165 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
2166 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2167 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2168 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2169 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
2170 Assert(!afPciDeviceNo[11]);
2171 afPciDeviceNo[11] = true;
2172 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2173
2174 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2175 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2176 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2177
2178 /*
2179 * Attach the status driver.
2180 */
2181 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2182 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2183 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2184 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
2185 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2186 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2187 }
2188 else
2189#endif
2190 {
2191 /*
2192 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
2193 * on a per device level now.
2194 */
2195 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
2196 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
2197 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
2198 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
2199 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
2200 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
2201 // that it's documented somewhere.) Users needing it can use:
2202 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
2203 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
2204 }
2205 }
2206 }
2207
2208 /*
2209 * Clipboard
2210 */
2211 {
2212 ClipboardMode_T mode = ClipboardMode_Disabled;
2213 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
2214
2215 if (mode != ClipboardMode_Disabled)
2216 {
2217 /* Load the service */
2218 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
2219
2220 if (RT_FAILURE (rc))
2221 {
2222 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
2223 /* That is not a fatal failure. */
2224 rc = VINF_SUCCESS;
2225 }
2226 else
2227 {
2228 /* Setup the service. */
2229 VBOXHGCMSVCPARM parm;
2230
2231 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2232
2233 switch (mode)
2234 {
2235 default:
2236 case ClipboardMode_Disabled:
2237 {
2238 LogRel(("VBoxSharedClipboard mode: Off\n"));
2239 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
2240 break;
2241 }
2242 case ClipboardMode_GuestToHost:
2243 {
2244 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
2245 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
2246 break;
2247 }
2248 case ClipboardMode_HostToGuest:
2249 {
2250 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
2251 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
2252 break;
2253 }
2254 case ClipboardMode_Bidirectional:
2255 {
2256 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
2257 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
2258 break;
2259 }
2260 }
2261
2262 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
2263
2264 Log(("Set VBoxSharedClipboard mode\n"));
2265 }
2266 }
2267 }
2268
2269#ifdef VBOX_WITH_CROGL
2270/* Currently broken on Snow Leopard 64-bit */
2271# if !(defined(RT_OS_DARWIN) && defined(RT_ARCH_AMD64))
2272 /*
2273 * crOpenGL
2274 */
2275 {
2276 BOOL fEnabled = false;
2277 hrc = pMachine->COMGETTER(Accelerate3DEnabled) (&fEnabled); H();
2278
2279 if (fEnabled)
2280 {
2281 /* Load the service */
2282 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
2283 if (RT_FAILURE(rc))
2284 {
2285 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
2286 /* That is not a fatal failure. */
2287 rc = VINF_SUCCESS;
2288 }
2289 else
2290 {
2291 LogRel(("Shared crOpenGL service loaded.\n"));
2292
2293 /* Setup the service. */
2294 VBOXHGCMSVCPARM parm;
2295 parm.type = VBOX_HGCM_SVC_PARM_PTR;
2296
2297 //parm.u.pointer.addr = static_cast <IConsole *> (pData->pVMMDev->getParent());
2298 parm.u.pointer.addr = pConsole->mVMMDev->getParent()->getDisplay()->getFramebuffer();
2299 parm.u.pointer.size = sizeof(IFramebuffer *);
2300
2301 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_FRAMEBUFFER, 1, &parm);
2302 if (!RT_SUCCESS(rc))
2303 AssertMsgFailed(("SHCRGL_HOST_FN_SET_FRAMEBUFFER failed with %Rrc\n", rc));
2304 }
2305 }
2306 }
2307# endif
2308#endif
2309
2310#ifdef VBOX_WITH_GUEST_PROPS
2311 /*
2312 * Guest property service
2313 */
2314 {
2315 /* Load the service */
2316 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
2317
2318 if (RT_FAILURE (rc))
2319 {
2320 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
2321 /* That is not a fatal failure. */
2322 rc = VINF_SUCCESS;
2323 }
2324 else
2325 {
2326 /* Pull over the properties from the server. */
2327 SafeArray <BSTR> namesOut;
2328 SafeArray <BSTR> valuesOut;
2329 SafeArray <ULONG64> timestampsOut;
2330 SafeArray <BSTR> flagsOut;
2331 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
2332 ComSafeArrayAsOutParam(valuesOut),
2333 ComSafeArrayAsOutParam(timestampsOut),
2334 ComSafeArrayAsOutParam(flagsOut)); H();
2335 size_t cProps = namesOut.size();
2336 if ( valuesOut.size() != cProps
2337 || timestampsOut.size() != cProps
2338 || flagsOut.size() != cProps
2339 )
2340 rc = VERR_INVALID_PARAMETER;
2341
2342 std::vector <Utf8Str> utf8Names, utf8Values, utf8Flags;
2343 std::vector <char *> names, values, flags;
2344 std::vector <ULONG64> timestamps;
2345 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2346 if ( !VALID_PTR(namesOut[i])
2347 || !VALID_PTR(valuesOut[i])
2348 || !VALID_PTR(flagsOut[i])
2349 )
2350 rc = VERR_INVALID_POINTER;
2351 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2352 {
2353 utf8Names.push_back(Bstr(namesOut[i]));
2354 utf8Values.push_back(Bstr(valuesOut[i]));
2355 timestamps.push_back(timestampsOut[i]);
2356 utf8Flags.push_back(Bstr(flagsOut[i]));
2357 if ( utf8Names.back().isNull()
2358 || utf8Values.back().isNull()
2359 || utf8Flags.back().isNull()
2360 )
2361 throw std::bad_alloc();
2362 }
2363 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2364 {
2365 names.push_back(utf8Names[i].mutableRaw());
2366 values.push_back(utf8Values[i].mutableRaw());
2367 flags.push_back(utf8Flags[i].mutableRaw());
2368 }
2369 names.push_back(NULL);
2370 values.push_back(NULL);
2371 timestamps.push_back(0);
2372 flags.push_back(NULL);
2373
2374 /* Setup the service. */
2375 VBOXHGCMSVCPARM parms[4];
2376
2377 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
2378 parms[0].u.pointer.addr = &names.front();
2379 parms[0].u.pointer.size = 0; /* We don't actually care. */
2380 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
2381 parms[1].u.pointer.addr = &values.front();
2382 parms[1].u.pointer.size = 0; /* We don't actually care. */
2383 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
2384 parms[2].u.pointer.addr = &timestamps.front();
2385 parms[2].u.pointer.size = 0; /* We don't actually care. */
2386 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
2387 parms[3].u.pointer.addr = &flags.front();
2388 parms[3].u.pointer.size = 0; /* We don't actually care. */
2389
2390 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4, &parms[0]);
2391
2392 /* Register the host notification callback */
2393 HGCMSVCEXTHANDLE hDummy;
2394 HGCMHostRegisterServiceExtension (&hDummy, "VBoxGuestPropSvc",
2395 Console::doGuestPropNotification,
2396 pvConsole);
2397
2398 Log(("Set VBoxGuestPropSvc property store\n"));
2399 }
2400 }
2401#endif /* VBOX_WITH_GUEST_PROPS defined */
2402
2403 /*
2404 * CFGM overlay handling.
2405 *
2406 * Here we check the extra data entries for CFGM values
2407 * and create the nodes and insert the values on the fly. Existing
2408 * values will be removed and reinserted. CFGM is typed, so by default
2409 * we will guess whether it's a string or an integer (byte arrays are
2410 * not currently supported). It's possible to override this autodetection
2411 * by adding "string:", "integer:" or "bytes:" (future).
2412 *
2413 * We first perform a run on global extra data, then on the machine
2414 * extra data to support global settings with local overrides.
2415 *
2416 */
2417 /** @todo add support for removing nodes and byte blobs. */
2418 Bstr strExtraDataKey;
2419 bool fGlobalExtraData = true;
2420 for (;;)
2421 {
2422 /*
2423 * Get the next key
2424 */
2425 Bstr strNextExtraDataKey;
2426 Bstr strExtraDataValue;
2427 if (fGlobalExtraData)
2428 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2429 strExtraDataValue.asOutParam());
2430 else
2431 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2432 strExtraDataValue.asOutParam());
2433
2434 /* stop if for some reason there's nothing more to request */
2435 if (FAILED(hrc) || !strNextExtraDataKey)
2436 {
2437 /* if we're out of global keys, continue with machine, otherwise we're done */
2438 if (fGlobalExtraData)
2439 {
2440 fGlobalExtraData = false;
2441 strExtraDataKey.setNull();
2442 continue;
2443 }
2444 break;
2445 }
2446 strExtraDataKey = strNextExtraDataKey;
2447
2448 /*
2449 * We only care about keys starting with "VBoxInternal/"
2450 */
2451 Utf8Str strExtraDataKeyUtf8(strExtraDataKey);
2452 char *pszExtraDataKey = (char *)strExtraDataKeyUtf8.raw();
2453 if (strncmp(pszExtraDataKey, "VBoxInternal/", sizeof("VBoxInternal/") - 1) != 0)
2454 continue;
2455 pszExtraDataKey += sizeof("VBoxInternal/") - 1;
2456
2457 /*
2458 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2459 * Split the two and get the node, delete the value and create the node
2460 * if necessary.
2461 */
2462 PCFGMNODE pNode;
2463 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2464 if (pszCFGMValueName)
2465 {
2466 /* terminate the node and advance to the value (Utf8Str might not
2467 offically like this but wtf) */
2468 *pszCFGMValueName = '\0';
2469 pszCFGMValueName++;
2470
2471 /* does the node already exist? */
2472 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2473 if (pNode)
2474 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2475 else
2476 {
2477 /* create the node */
2478 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2479 if (RT_FAILURE(rc))
2480 {
2481 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2482 continue;
2483 }
2484 Assert(pNode);
2485 }
2486 }
2487 else
2488 {
2489 /* root value (no node path). */
2490 pNode = pRoot;
2491 pszCFGMValueName = pszExtraDataKey;
2492 pszExtraDataKey--;
2493 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2494 }
2495
2496 /*
2497 * Now let's have a look at the value.
2498 * Empty strings means that we should remove the value, which we've
2499 * already done above.
2500 */
2501 Utf8Str strCFGMValueUtf8(strExtraDataValue);
2502 const char *pszCFGMValue = strCFGMValueUtf8.raw();
2503 if ( pszCFGMValue
2504 && *pszCFGMValue)
2505 {
2506 uint64_t u64Value;
2507
2508 /* check for type prefix first. */
2509 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
2510 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
2511 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
2512 {
2513 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
2514 if (RT_SUCCESS(rc))
2515 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2516 }
2517 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
2518 rc = VERR_NOT_IMPLEMENTED;
2519 /* auto detect type. */
2520 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
2521 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2522 else
2523 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
2524 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
2525 }
2526 }
2527
2528#undef H
2529#undef RC_CHECK
2530#undef STR_FREE
2531#undef STR_CONV
2532
2533 /* Register VM state change handler */
2534 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2535 AssertRC (rc2);
2536 if (RT_SUCCESS (rc))
2537 rc = rc2;
2538
2539 /* Register VM runtime error handler */
2540 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2541 AssertRC (rc2);
2542 if (RT_SUCCESS (rc))
2543 rc = rc2;
2544
2545 /* Save the VM pointer in the machine object */
2546 pConsole->mpVM = pVM;
2547
2548 LogFlowFunc (("vrc = %Rrc\n", rc));
2549 LogFlowFuncLeave();
2550
2551 return rc;
2552}
2553/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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