VirtualBox

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

Last change on this file since 10695 was 10693, checked in by vboxsync, 17 years ago

Added setting for nested paging (default on).

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

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