VirtualBox

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

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

HPET&SMC config

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