VirtualBox

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

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

NetFlt/win: addition err logging in net settings construction

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