VirtualBox

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

Last change on this file since 8429 was 8375, checked in by vboxsync, 17 years ago

Main: Same as r30155 but for NetworkAttachmentType_Internal.

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