VirtualBox

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

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

Guest properties: initial commit of new interface

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 86.9 KB
Line 
1/** $Id: ConsoleImpl2.cpp 10797 2008-07-22 08:12:42Z 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#endif /* VBOX_WITH_GUEST_PROPS */
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_GUEST_PROPS
247 PCFGMNODE pGuest = NULL; /* /Guest */
248 PCFGMNODE pRegistry = NULL; /* /Guest/Registry */
249#endif /* VBOX_WITH_GUEST_PROPS 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 /*
858 * Create cfgm nodes for async transport driver because VMDK is currently the only
859 * one which may support async I/O. This has to be made generic based on the capabiliy flags
860 * when the new HardDisk interface is merged.
861 */
862 rc = CFGMR3InsertNode(pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
863 rc = CFGMR3InsertString(pLunL2, "Driver", "TransportAsync"); RC_CHECK();
864 /* The async transport driver has no config options yet. */
865 }
866 else if (hddType == HardDiskStorageType_CustomHardDisk)
867 {
868 ComPtr<ICustomHardDisk> customHardDisk = hardDisk;
869 AssertBreakStmt (!customHardDisk.isNull(), hrc = E_FAIL);
870
871 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
872 rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
873 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
874 hrc = customHardDisk->COMGETTER(Location)(&str); H();
875 STR_CONV();
876 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
877 STR_FREE();
878 hrc = customHardDisk->COMGETTER(Format)(&str); H();
879 STR_CONV();
880 rc = CFGMR3InsertString(pCfg, "Format", psz); RC_CHECK();
881 STR_FREE();
882 }
883 else if (hddType == HardDiskStorageType_VHDImage)
884 {
885 ComPtr<IVHDImage> vhdDisk = hardDisk;
886 AssertBreakStmt (!vhdDisk.isNull(), hrc = E_FAIL);
887
888 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
889 rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
890 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
891 hrc = vhdDisk->COMGETTER(FilePath)(&str); H();
892 STR_CONV();
893 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
894 rc = CFGMR3InsertString(pCfg, "Format", "VHD"); RC_CHECK();
895 STR_FREE();
896 }
897 else
898 AssertFailed();
899 }
900 }
901 H();
902
903 ComPtr<IDVDDrive> dvdDrive;
904 hrc = pMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam()); H();
905 if (dvdDrive)
906 {
907 // ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
908 rc = CFGMR3InsertNode(pIdeInst, "LUN#2", &pLunL0); RC_CHECK();
909 ComPtr<IHostDVDDrive> hostDvdDrive;
910 hrc = dvdDrive->GetHostDrive(hostDvdDrive.asOutParam()); H();
911 if (hostDvdDrive)
912 {
913 pConsole->meDVDState = DriveState_HostDriveCaptured;
914 rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
915 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
916 hrc = hostDvdDrive->COMGETTER(Name)(&str); H();
917 STR_CONV();
918 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
919 STR_FREE();
920 BOOL fPassthrough;
921 hrc = dvdDrive->COMGETTER(Passthrough)(&fPassthrough); H();
922 rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough); RC_CHECK();
923 }
924 else
925 {
926 pConsole->meDVDState = DriveState_NotMounted;
927 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
928 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
929 rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
930 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
931
932 ComPtr<IDVDImage> dvdImage;
933 hrc = dvdDrive->GetImage(dvdImage.asOutParam()); H();
934 if (dvdImage)
935 {
936 pConsole->meDVDState = DriveState_ImageMounted;
937 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
938 rc = CFGMR3InsertString(pLunL1, "Driver", "MediaISO"); RC_CHECK();
939 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
940 hrc = dvdImage->COMGETTER(FilePath)(&str); H();
941 STR_CONV();
942 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
943 STR_FREE();
944 }
945 }
946 }
947
948 /*
949 * Network adapters
950 */
951 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
952 rc = CFGMR3InsertNode(pDevices, "pcnet", &pDevPCNet); RC_CHECK();
953#ifdef VBOX_WITH_E1000
954 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
955 rc = CFGMR3InsertNode(pDevices, "e1000", &pDevE1000); RC_CHECK();
956#endif
957 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ulInstance++)
958 {
959 ComPtr<INetworkAdapter> networkAdapter;
960 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
961 BOOL fEnabled = FALSE;
962 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
963 if (!fEnabled)
964 continue;
965
966 /*
967 * The virtual hardware type. Create appropriate device first.
968 */
969 NetworkAdapterType_T adapterType;
970 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
971 switch (adapterType)
972 {
973 case NetworkAdapterType_Am79C970A:
974 case NetworkAdapterType_Am79C973:
975 pDev = pDevPCNet;
976 break;
977#ifdef VBOX_WITH_E1000
978 case NetworkAdapterType_I82540EM:
979 case NetworkAdapterType_I82543GC:
980 pDev = pDevE1000;
981 break;
982#endif
983 default:
984 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
985 adapterType, ulInstance));
986 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
987 N_("Invalid network adapter type '%d' for slot '%d'"),
988 adapterType, ulInstance);
989 }
990
991 char szInstance[4]; Assert(ulInstance <= 999);
992 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
993 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
994 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
995 /* the first network card gets the PCI ID 3, the next 3 gets 8..10. */
996 const unsigned iPciDeviceNo = !ulInstance ? 3 : ulInstance - 1 + 8;
997 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
998 Assert(!afPciDeviceNo[iPciDeviceNo]);
999 afPciDeviceNo[iPciDeviceNo] = true;
1000 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1001 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1002
1003 /*
1004 * The virtual hardware type. PCNet supports two types.
1005 */
1006 switch (adapterType)
1007 {
1008 case NetworkAdapterType_Am79C970A:
1009 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
1010 break;
1011 case NetworkAdapterType_Am79C973:
1012 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
1013 break;
1014 case NetworkAdapterType_I82540EM:
1015 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
1016 break;
1017 case NetworkAdapterType_I82543GC:
1018 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
1019 break;
1020 }
1021
1022 /*
1023 * Get the MAC address and convert it to binary representation
1024 */
1025 Bstr macAddr;
1026 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1027 Assert(macAddr);
1028 Utf8Str macAddrUtf8 = macAddr;
1029 char *macStr = (char*)macAddrUtf8.raw();
1030 Assert(strlen(macStr) == 12);
1031 PDMMAC Mac;
1032 memset(&Mac, 0, sizeof(Mac));
1033 char *pMac = (char*)&Mac;
1034 for (uint32_t i = 0; i < 6; i++)
1035 {
1036 char c1 = *macStr++ - '0';
1037 if (c1 > 9)
1038 c1 -= 7;
1039 char c2 = *macStr++ - '0';
1040 if (c2 > 9)
1041 c2 -= 7;
1042 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1043 }
1044 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1045
1046 /*
1047 * Check if the cable is supposed to be unplugged
1048 */
1049 BOOL fCableConnected;
1050 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1051 rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
1052
1053 /*
1054 * Line speed to report from custom drivers
1055 */
1056 ULONG ulLineSpeed;
1057 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1058 rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
1059
1060 /*
1061 * Attach the status driver.
1062 */
1063 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1064 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1065 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1066 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
1067
1068 /*
1069 * Enable the packet sniffer if requested.
1070 */
1071 BOOL fSniffer;
1072 hrc = networkAdapter->COMGETTER(TraceEnabled)(&fSniffer); H();
1073 if (fSniffer)
1074 {
1075 /* insert the sniffer filter driver. */
1076 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1077 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
1078 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1079 hrc = networkAdapter->COMGETTER(TraceFile)(&str); H();
1080 if (str) /* check convention for indicating default file. */
1081 {
1082 STR_CONV();
1083 rc = CFGMR3InsertString(pCfg, "File", psz); RC_CHECK();
1084 STR_FREE();
1085 }
1086 }
1087
1088 NetworkAttachmentType_T networkAttachment;
1089 hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H();
1090 switch (networkAttachment)
1091 {
1092 case NetworkAttachmentType_Null:
1093 break;
1094
1095 case NetworkAttachmentType_NAT:
1096 {
1097 if (fSniffer)
1098 {
1099 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1100 }
1101 else
1102 {
1103 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1104 }
1105 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
1106 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1107 /* (Port forwarding goes here.) */
1108
1109 /* Configure TFTP prefix and boot filename. */
1110 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
1111 STR_CONV();
1112 if (psz && *psz)
1113 {
1114 char *pszTFTPPrefix = NULL;
1115 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
1116 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix); RC_CHECK();
1117 RTStrFree(pszTFTPPrefix);
1118 }
1119 STR_FREE();
1120 hrc = pMachine->COMGETTER(Name)(&str); H();
1121 STR_CONV();
1122 char *pszBootFile = NULL;
1123 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
1124 STR_FREE();
1125 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile); RC_CHECK();
1126 RTStrFree(pszBootFile);
1127
1128 hrc = networkAdapter->COMGETTER(NATNetwork)(&str); H();
1129 if (str)
1130 {
1131 STR_CONV();
1132 if (psz && *psz)
1133 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1134 STR_FREE();
1135 }
1136 break;
1137 }
1138
1139 case NetworkAttachmentType_HostInterface:
1140 {
1141 /*
1142 * Perform the attachment if required (don't return on error!)
1143 */
1144 hrc = pConsole->attachToHostInterface(networkAdapter);
1145 if (SUCCEEDED(hrc))
1146 {
1147#ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
1148 Assert (pConsole->maTapFD[ulInstance] >= 0);
1149 if (pConsole->maTapFD[ulInstance] >= 0)
1150 {
1151 if (fSniffer)
1152 {
1153 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1154 }
1155 else
1156 {
1157 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1158 }
1159 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1160 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1161# if defined(RT_OS_SOLARIS)
1162 /* Device name/number is required for Solaris as we need it for TAP PPA. */
1163 Bstr tapDeviceName;
1164 networkAdapter->COMGETTER(HostInterface)(tapDeviceName.asOutParam());
1165 if (!tapDeviceName.isEmpty())
1166 rc = CFGMR3InsertString(pCfg, "Device", Utf8Str(tapDeviceName)); RC_CHECK();
1167
1168 /* TAP setup application/script */
1169 Bstr tapSetupApp;
1170 networkAdapter->COMGETTER(TAPSetupApplication)(tapSetupApp.asOutParam());
1171 if (!tapSetupApp.isEmpty())
1172 rc = CFGMR3InsertString(pCfg, "TAPSetupApplication", Utf8Str(tapSetupApp)); RC_CHECK();
1173
1174 /* TAP terminate application/script */
1175 Bstr tapTerminateApp;
1176 networkAdapter->COMGETTER(TAPTerminateApplication)(tapTerminateApp.asOutParam());
1177 if (!tapTerminateApp.isEmpty())
1178 rc = CFGMR3InsertString(pCfg, "TAPTerminateApplication", Utf8Str(tapTerminateApp)); RC_CHECK();
1179
1180 /* "FileHandle" must NOT be inserted here, it is done in DrvTAP.cpp */
1181
1182# ifdef VBOX_WITH_CROSSBOW
1183 /* Crossbow: needs the MAC address for setting up TAP. */
1184 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1185# endif
1186# else
1187 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pConsole->maTapFD[ulInstance]); RC_CHECK();
1188# endif
1189 }
1190#elif defined(RT_OS_WINDOWS)
1191 if (fSniffer)
1192 {
1193 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1194 }
1195 else
1196 {
1197 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1198 }
1199 Bstr hostInterfaceName;
1200 hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
1201 ComPtr<IHostNetworkInterfaceCollection> coll;
1202 hrc = host->COMGETTER(NetworkInterfaces)(coll.asOutParam()); H();
1203 ComPtr<IHostNetworkInterface> hostInterface;
1204 rc = coll->FindByName(hostInterfaceName, hostInterface.asOutParam());
1205 if (!SUCCEEDED(rc))
1206 {
1207 AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
1208 hrc = networkAdapter->Detach(); H();
1209 }
1210 else
1211 {
1212 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1213 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1214 rc = CFGMR3InsertString(pCfg, "HostInterfaceName", Utf8Str(hostInterfaceName)); RC_CHECK();
1215 Guid hostIFGuid;
1216 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1217 char szDriverGUID[256] = {0};
1218 /* add curly brackets */
1219 szDriverGUID[0] = '{';
1220 strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
1221 strcat(szDriverGUID, "}");
1222 rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
1223 }
1224#else
1225# error "Port me"
1226#endif
1227 }
1228 else
1229 {
1230 switch (hrc)
1231 {
1232#ifdef RT_OS_LINUX
1233 case VERR_ACCESS_DENIED:
1234 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1235 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1236 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
1237 "change the group of that node and make yourself a member of that group. Make "
1238 "sure that these changes are permanent, especially if you are "
1239 "using udev"));
1240#endif /* RT_OS_LINUX */
1241 default:
1242 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1243 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1244 "Failed to initialize Host Interface Networking"));
1245 }
1246 }
1247 break;
1248 }
1249
1250 case NetworkAttachmentType_Internal:
1251 {
1252 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1253 if (str)
1254 {
1255 STR_CONV();
1256 if (psz && *psz)
1257 {
1258 if (fSniffer)
1259 {
1260 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1261 }
1262 else
1263 {
1264 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1265 }
1266 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1267 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1268 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1269 }
1270 STR_FREE();
1271 }
1272 break;
1273 }
1274
1275 default:
1276 AssertMsgFailed(("should not get here!\n"));
1277 break;
1278 }
1279 }
1280
1281 /*
1282 * Serial (UART) Ports
1283 */
1284 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1285 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1286 {
1287 ComPtr<ISerialPort> serialPort;
1288 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1289 BOOL fEnabled = FALSE;
1290 if (serialPort)
1291 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1292 if (!fEnabled)
1293 continue;
1294
1295 char szInstance[4]; Assert(ulInstance <= 999);
1296 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1297
1298 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1299 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1300
1301 ULONG ulIRQ, ulIOBase;
1302 PortMode_T HostMode;
1303 Bstr path;
1304 BOOL fServer;
1305 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1306 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1307 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1308 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1309 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1310 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1311 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1312 if (HostMode != PortMode_Disconnected)
1313 {
1314 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1315 if (HostMode == PortMode_HostPipe)
1316 {
1317 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1318 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1319 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1320 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1321 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1322 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1323 }
1324 else if (HostMode == PortMode_HostDevice)
1325 {
1326 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1327 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1328 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1329 }
1330 }
1331 }
1332
1333 /*
1334 * Parallel (LPT) Ports
1335 */
1336 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1337 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1338 {
1339 ComPtr<IParallelPort> parallelPort;
1340 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1341 BOOL fEnabled = FALSE;
1342 if (parallelPort)
1343 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1344 if (!fEnabled)
1345 continue;
1346
1347 char szInstance[4]; Assert(ulInstance <= 999);
1348 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1349
1350 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1351 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1352
1353 ULONG ulIRQ, ulIOBase;
1354 Bstr DevicePath;
1355 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1356 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1357 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1358 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1359 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1360 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1361 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1362 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1363 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1364 }
1365
1366 /*
1367 * VMM Device
1368 */
1369 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1370 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1371 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1372 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1373 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1374 Assert(!afPciDeviceNo[4]);
1375 afPciDeviceNo[4] = true;
1376 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1377
1378 /* the VMM device's Main driver */
1379 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1380 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1381 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1382 VMMDev *pVMMDev = pConsole->mVMMDev;
1383 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1384
1385 /*
1386 * Attach the status driver.
1387 */
1388 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1389 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1390 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1391 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1392 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1393 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1394
1395 /*
1396 * Audio Sniffer Device
1397 */
1398 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1399 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1400 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1401
1402 /* the Audio Sniffer device's Main driver */
1403 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1404 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1405 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1406 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1407 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1408
1409 /*
1410 * AC'97 ICH / SoundBlaster16 audio
1411 */
1412 ComPtr<IAudioAdapter> audioAdapter;
1413 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1414 if (audioAdapter)
1415 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1416
1417 if (enabled)
1418 {
1419 AudioControllerType_T audioController;
1420 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
1421 switch (audioController)
1422 {
1423 case AudioControllerType_AC97:
1424 {
1425 /* default: ICH AC97 */
1426 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
1427 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1428 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1429 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1430 Assert(!afPciDeviceNo[5]);
1431 afPciDeviceNo[5] = true;
1432 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1433 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1434 break;
1435 }
1436 case AudioControllerType_SB16:
1437 {
1438 /* legacy SoundBlaster16 */
1439 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
1440 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1441 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1442 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1443 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
1444 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
1445 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
1446 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
1447 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
1448 break;
1449 }
1450 }
1451
1452 /* the Audio driver */
1453 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1454 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1455 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1456
1457 AudioDriverType_T audioDriver;
1458 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1459 switch (audioDriver)
1460 {
1461 case AudioDriverType_Null:
1462 {
1463 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1464 break;
1465 }
1466#ifdef RT_OS_WINDOWS
1467#ifdef VBOX_WITH_WINMM
1468 case AudioDriverType_WinMM:
1469 {
1470 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1471 break;
1472 }
1473#endif
1474 case AudioDriverType_DirectSound:
1475 {
1476 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
1477 break;
1478 }
1479#endif /* RT_OS_WINDOWS */
1480#ifdef RT_OS_SOLARIS
1481 case AudioDriverType_SolAudio:
1482 {
1483 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
1484 break;
1485 }
1486#endif
1487#ifdef RT_OS_LINUX
1488 case AudioDriverType_OSS:
1489 {
1490 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
1491 break;
1492 }
1493# ifdef VBOX_WITH_ALSA
1494 case AudioDriverType_ALSA:
1495 {
1496 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
1497 break;
1498 }
1499# endif
1500# ifdef VBOX_WITH_PULSE
1501 case AudioDriverType_Pulse:
1502 {
1503 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
1504 break;
1505 }
1506# endif
1507#endif /* RT_OS_LINUX */
1508#ifdef RT_OS_DARWIN
1509 case AudioDriverType_CoreAudio:
1510 {
1511 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1512 break;
1513 }
1514#endif
1515 }
1516 hrc = pMachine->COMGETTER(Name)(&str); H();
1517 STR_CONV();
1518 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
1519 STR_FREE();
1520 }
1521
1522 /*
1523 * The USB Controller.
1524 */
1525 ComPtr<IUSBController> USBCtlPtr;
1526 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1527 if (USBCtlPtr)
1528 {
1529 BOOL fEnabled;
1530 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1531 if (fEnabled)
1532 {
1533 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
1534 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1535 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1536 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1537 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
1538 Assert(!afPciDeviceNo[6]);
1539 afPciDeviceNo[6] = true;
1540 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1541
1542 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1543 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1544 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1545
1546 /*
1547 * Attach the status driver.
1548 */
1549 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1550 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1551 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1552 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
1553 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1554 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1555
1556#ifdef VBOX_WITH_EHCI
1557 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
1558 if (fEnabled)
1559 {
1560 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
1561 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1562 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1563 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1564 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
1565 Assert(!afPciDeviceNo[11]);
1566 afPciDeviceNo[11] = true;
1567 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1568
1569 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1570 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1571 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1572
1573 /*
1574 * Attach the status driver.
1575 */
1576 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1577 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1578 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1579 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
1580 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1581 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1582 }
1583 else
1584#endif
1585 {
1586 /*
1587 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
1588 * on a per device level now.
1589 */
1590 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
1591 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
1592 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
1593 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
1594 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
1595 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
1596 // that it's documented somewhere.) Users needing it can use:
1597 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
1598 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
1599 }
1600 }
1601 }
1602
1603 /*
1604 * Clipboard
1605 */
1606 {
1607 ClipboardMode_T mode = ClipboardMode_Disabled;
1608 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
1609
1610 if (mode != ClipboardMode_Disabled)
1611 {
1612 /* Load the service */
1613 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
1614
1615 if (VBOX_FAILURE (rc))
1616 {
1617 LogRel(("VBoxSharedClipboard is not available. rc = %Vrc\n", rc));
1618 /* That is not a fatal failure. */
1619 rc = VINF_SUCCESS;
1620 }
1621 else
1622 {
1623 /* Setup the service. */
1624 VBOXHGCMSVCPARM parm;
1625
1626 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
1627
1628 switch (mode)
1629 {
1630 default:
1631 case ClipboardMode_Disabled:
1632 {
1633 LogRel(("VBoxSharedClipboard mode: Off\n"));
1634 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
1635 break;
1636 }
1637 case ClipboardMode_GuestToHost:
1638 {
1639 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
1640 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
1641 break;
1642 }
1643 case ClipboardMode_HostToGuest:
1644 {
1645 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
1646 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
1647 break;
1648 }
1649 case ClipboardMode_Bidirectional:
1650 {
1651 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
1652 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
1653 break;
1654 }
1655 }
1656
1657 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
1658
1659 Log(("Set VBoxSharedClipboard mode\n"));
1660 }
1661 }
1662 }
1663#ifdef VBOX_WITH_GUEST_PROPS
1664 /*
1665 * Shared information services
1666 */
1667 {
1668 /* Load the service */
1669 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
1670
1671 if (VBOX_FAILURE (rc))
1672 {
1673 LogRel(("VBoxGuestPropSvc is not available. rc = %Vrc\n", rc));
1674 /* That is not a fatal failure. */
1675 rc = VINF_SUCCESS;
1676 }
1677 else
1678 {
1679 rc = CFGMR3InsertNode(pRoot, "Guest", &pGuest); RC_CHECK();
1680 rc = CFGMR3InsertNode(pGuest, "Registry", &pRegistry); RC_CHECK();
1681 /* Load the saved machine registry. This is stored as extra data
1682 * keys in the machine XML file, starting with the prefix
1683 * VBOX_SHARED_INFO_KEY_PREFIX. */
1684 Bstr strExtraDataKey;
1685 for (;;)
1686 {
1687 Bstr strNextExtraDataKey;
1688 Bstr strExtraDataValue;
1689
1690 /* get the next key */
1691 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1692 strExtraDataValue.asOutParam());
1693
1694 /* stop if for some reason there's nothing more to request */
1695 if (FAILED(hrc) || !strNextExtraDataKey)
1696 break;
1697
1698 strExtraDataKey = strNextExtraDataKey;
1699 Utf8Str strExtraDataKeyUtf8 = Utf8Str(strExtraDataKey);
1700
1701 /* we only care about keys starting with VBOX_SHARED_INFO_KEY_PREFIX */
1702 if (strncmp(strExtraDataKeyUtf8.raw(), VBOX_SHARED_INFO_KEY_PREFIX, VBOX_SHARED_INFO_PREFIX_LEN) != 0)
1703 continue;
1704 char *pszCFGMValueName = (char*)strExtraDataKeyUtf8.raw() + VBOX_SHARED_INFO_PREFIX_LEN;
1705
1706 /* now let's have a look at the value */
1707 Utf8Str strCFGMValueUtf8 = Utf8Str(strExtraDataValue);
1708 const char *pszCFGMValue = strCFGMValueUtf8.raw();
1709 /* empty value means remove value which we've already done */
1710 if (pszCFGMValue && *pszCFGMValue)
1711 {
1712 rc = CFGMR3InsertString(pRegistry, pszCFGMValueName, pszCFGMValue);
1713 AssertMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszCFGMValueName));
1714 }
1715 }
1716
1717 /* Setup the service. */
1718 VBOXHGCMSVCPARM parm;
1719
1720 parm.type = VBOX_HGCM_SVC_PARM_PTR;
1721 parm.u.pointer.addr = pRegistry;
1722 parm.u.pointer.size = sizeof(pRegistry); /* We don't actually care. */
1723
1724 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_CFGM_NODE, 1, &parm);
1725
1726 Log(("Set VBoxGuestPropSvc property store\n"));
1727 }
1728 }
1729#endif /* VBOX_WITH_GUEST_PROPS defined */
1730
1731 /*
1732 * CFGM overlay handling.
1733 *
1734 * Here we check the extra data entries for CFGM values
1735 * and create the nodes and insert the values on the fly. Existing
1736 * values will be removed and reinserted. If a value is a valid number,
1737 * it will be inserted as a number, otherwise as a string.
1738 *
1739 * We first perform a run on global extra data, then on the machine
1740 * extra data to support global settings with local overrides.
1741 *
1742 */
1743 Bstr strExtraDataKey;
1744 bool fGlobalExtraData = true;
1745 for (;;)
1746 {
1747 Bstr strNextExtraDataKey;
1748 Bstr strExtraDataValue;
1749
1750 /* get the next key */
1751 if (fGlobalExtraData)
1752 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1753 strExtraDataValue.asOutParam());
1754 else
1755 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1756 strExtraDataValue.asOutParam());
1757
1758 /* stop if for some reason there's nothing more to request */
1759 if (FAILED(hrc) || !strNextExtraDataKey)
1760 {
1761 /* if we're out of global keys, continue with machine, otherwise we're done */
1762 if (fGlobalExtraData)
1763 {
1764 fGlobalExtraData = false;
1765 strExtraDataKey.setNull();
1766 continue;
1767 }
1768 break;
1769 }
1770
1771 strExtraDataKey = strNextExtraDataKey;
1772 Utf8Str strExtraDataKeyUtf8 = Utf8Str(strExtraDataKey);
1773
1774 /* we only care about keys starting with "VBoxInternal/" */
1775 if (strncmp(strExtraDataKeyUtf8.raw(), "VBoxInternal/", 13) != 0)
1776 continue;
1777 char *pszExtraDataKey = (char*)strExtraDataKeyUtf8.raw() + 13;
1778
1779 /* the key will be in the format "Node1/Node2/Value" or simply "Value". */
1780 PCFGMNODE pNode;
1781 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
1782 if (pszCFGMValueName)
1783 {
1784 /* terminate the node and advance to the value */
1785 *pszCFGMValueName = '\0';
1786 pszCFGMValueName++;
1787
1788 /* does the node already exist? */
1789 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
1790 if (pNode)
1791 {
1792 /* the value might already exist, remove it to be safe */
1793 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1794 }
1795 else
1796 {
1797 /* create the node */
1798 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
1799 AssertMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
1800 if (VBOX_FAILURE(rc) || !pNode)
1801 continue;
1802 }
1803 }
1804 else
1805 {
1806 pNode = pRoot;
1807 pszCFGMValueName = pszExtraDataKey;
1808 pszExtraDataKey--;
1809
1810 /* the value might already exist, remove it to be safe */
1811 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1812 }
1813
1814 /* now let's have a look at the value */
1815 Utf8Str strCFGMValueUtf8 = Utf8Str(strExtraDataValue);
1816 const char *pszCFGMValue = strCFGMValueUtf8.raw();
1817 /* empty value means remove value which we've already done */
1818 if (pszCFGMValue && *pszCFGMValue)
1819 {
1820 /* if it's a valid number, we'll insert it as such, otherwise string */
1821 uint64_t u64Value;
1822 char *pszNext = NULL;
1823 if ( RTStrToUInt64Ex(pszCFGMValue, &pszNext, 0, &u64Value) == VINF_SUCCESS
1824 && (!pszNext || *pszNext == '\0') /* check if the _whole_ string is a valid number */
1825 )
1826 {
1827 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
1828 }
1829 else
1830 {
1831 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
1832 }
1833 AssertMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
1834 }
1835 }
1836
1837#undef H
1838#undef RC_CHECK
1839#undef STR_FREE
1840#undef STR_CONV
1841
1842 /* Register VM state change handler */
1843 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
1844 AssertRC (rc2);
1845 if (VBOX_SUCCESS (rc))
1846 rc = rc2;
1847
1848 /* Register VM runtime error handler */
1849 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
1850 AssertRC (rc2);
1851 if (VBOX_SUCCESS (rc))
1852 rc = rc2;
1853
1854 /* Save the VM pointer in the machine object */
1855 pConsole->mpVM = pVM;
1856
1857 LogFlowFunc (("vrc = %Vrc\n", rc));
1858 LogFlowFuncLeave();
1859
1860 return rc;
1861}
1862
1863
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