VirtualBox

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

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

add rudimentary support for ICH6 IDE controller

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