VirtualBox

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

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

Older 82543GC chip support, works in linux only.

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

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