VirtualBox

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

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

AHCI/Main/VBoxManage: Add configuration parameter to set the number of ports on the sata controller. FreeBSD cannot handle more than 8 and would crash otherwise. Also adds the previously forgotten BIOS configuration parameters for booting from SATA

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