VirtualBox

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

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

NetFlt/win: fix for wireless problem

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

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