VirtualBox

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

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

#3569: DHCP Server is now started from VBoxSVC and terminates with it.

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