VirtualBox

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

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

REM: implement config check heuristic, to select which REM to load

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