VirtualBox

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

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

compile fix for Linux netflt code

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