VirtualBox

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

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

Backed out 29633 & 29635 again

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