VirtualBox

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

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

Main/ConsoleImpl: fix iSCSI over IntNet config for good.

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

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