VirtualBox

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

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

AssertBreak -> AssertBreakStmt.

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