VirtualBox

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

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

Main: Applied SATA changes from #2406. Increased XML settings version format from 1.2 to 1.3.pre.

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