VirtualBox

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

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

fixed Windows burns

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