VirtualBox

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

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

remove tap for non-linux platforms

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