VirtualBox

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

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

EFI: few missed changes

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