VirtualBox

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

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

ConsoleImpl2.cpp: Prep for lots of ram.

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

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