VirtualBox

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

Last change on this file since 15078 was 15053, checked in by vboxsync, 16 years ago

Main: Pass custom hard disk properties to CFGM for child hard disk as well (and fix the wrong location of the for loop).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 101.8 KB
Line 
1/* $Id: ConsoleImpl2.cpp 15053 2008-12-05 17:38:57Z vboxsync $ */
2/** @file
3 * VBox Console COM Class implementation
4 *
5 * @remark We've split out the code that the 64-bit VC++ v8 compiler
6 * finds problematic to optimize so we can disable optimizations
7 * and later, perhaps, find a real solution for it.
8 */
9
10/*
11 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
12 *
13 * This file is part of VirtualBox Open Source Edition (OSE), as
14 * available from http://www.virtualbox.org. This file is free software;
15 * you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License (GPL) as published by the Free Software
17 * Foundation, in version 2 as it comes in the "COPYING" file of the
18 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
22 * Clara, CA 95054 USA or visit http://www.sun.com if you need
23 * additional information or have any questions.
24 */
25
26/*******************************************************************************
27* Header Files *
28*******************************************************************************/
29#include "ConsoleImpl.h"
30#include "DisplayImpl.h"
31#include "VMMDev.h"
32
33// generated header
34#include "SchemaDefs.h"
35
36#include "Logging.h"
37
38#include <iprt/string.h>
39#include <iprt/path.h>
40#include <iprt/dir.h>
41#include <iprt/param.h>
42
43#include <VBox/vmapi.h>
44#include <VBox/err.h>
45#include <VBox/version.h>
46#include <VBox/HostServices/VBoxClipboardSvc.h>
47#ifdef VBOX_WITH_CROGL
48#include <VBox/HostServices/VBoxCrOpenGLSvc.h>
49#endif
50#ifdef VBOX_WITH_GUEST_PROPS
51# include <VBox/HostServices/GuestPropertySvc.h>
52# include <VBox/com/defs.h>
53# include <VBox/com/array.h>
54# include <hgcm/HGCM.h> /** @todo it should be possible to register a service
55 * extension using a VMMDev callback. */
56# include <vector>
57#endif /* VBOX_WITH_GUEST_PROPS */
58#include <VBox/intnet.h>
59
60#include <VBox/com/string.h>
61#include <VBox/com/array.h>
62
63#if defined(RT_OS_SOLARIS) && defined(VBOX_WITH_NETFLT)
64# include <zone.h>
65#endif
66
67#if defined(RT_OS_LINUX) && defined(VBOX_WITH_NETFLT)
68# include <unistd.h>
69# include <sys/ioctl.h>
70# include <sys/socket.h>
71# include <linux/types.h>
72# include <linux/if.h>
73# include <linux/wireless.h>
74#endif
75
76#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
77# include <VBox/WinNetConfig.h>
78# include <Ntddndis.h>
79# include <devguid.h>
80#endif
81
82
83/*
84 * VC++ 8 / amd64 has some serious trouble with this function.
85 * As a temporary measure, we'll drop global optimizations.
86 */
87#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
88# pragma optimize("g", off)
89#endif
90
91/**
92 * Construct the VM configuration tree (CFGM).
93 *
94 * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
95 * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
96 * is done here.
97 *
98 * @param pVM VM handle.
99 * @param pvConsole Pointer to the VMPowerUpTask object.
100 * @return VBox status code.
101 *
102 * @note Locks the Console object for writing.
103 */
104DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
105{
106 LogFlowFuncEnter();
107 /* Note: hardcoded assumption about number of slots; see rom bios */
108 bool afPciDeviceNo[32] = {false};
109
110#if !defined (VBOX_WITH_XPCOM)
111 {
112 /* initialize COM */
113 HRESULT hrc = CoInitializeEx(NULL,
114 COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
115 COINIT_SPEED_OVER_MEMORY);
116 LogFlow (("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
117 AssertComRCReturn (hrc, VERR_GENERAL_FAILURE);
118 }
119#endif
120
121 AssertReturn (pvConsole, VERR_GENERAL_FAILURE);
122 ComObjPtr <Console> pConsole = static_cast <Console *> (pvConsole);
123
124 AutoCaller autoCaller (pConsole);
125 AssertComRCReturn (autoCaller.rc(), VERR_ACCESS_DENIED);
126
127 /* lock the console because we widely use internal fields and methods */
128 AutoWriteLock alock (pConsole);
129
130 ComPtr <IMachine> pMachine = pConsole->machine();
131
132 int rc;
133 HRESULT hrc;
134 char *psz = NULL;
135 BSTR str = NULL;
136
137 Bstr bstr; /* use this bstr when calling COM methods instead
138 of str as it manages memory! */
139
140#define STR_CONV() do { rc = RTUtf16ToUtf8(str, &psz); RC_CHECK(); } while (0)
141#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } if (psz) { RTStrFree(psz); psz = NULL; } } while (0)
142#define RC_CHECK() do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc)); STR_FREE(); return rc; } } while (0)
143#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
144
145 /*
146 * Get necessary objects and frequently used parameters.
147 */
148 ComPtr<IVirtualBox> virtualBox;
149 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
150
151 ComPtr<IHost> host;
152 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
153
154 ComPtr <ISystemProperties> systemProperties;
155 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
156
157 ComPtr<IBIOSSettings> biosSettings;
158 hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
159
160 Guid uuid;
161 hrc = pMachine->COMGETTER(Id)(uuid.asOutParam()); H();
162 PCRTUUID pUuid = uuid.raw();
163
164 ULONG cRamMBs;
165 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
166
167 ULONG cCpus = 1;
168#ifdef VBOX_WITH_SMP_GUESTS
169 hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
170#endif
171
172 /*
173 * Get root node first.
174 * This is the only node in the tree.
175 */
176 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
177 Assert(pRoot);
178
179 /*
180 * Set the root level values.
181 */
182 hrc = pMachine->COMGETTER(Name)(&str); H();
183 STR_CONV();
184 rc = CFGMR3InsertString(pRoot, "Name", psz); RC_CHECK();
185 STR_FREE();
186 rc = CFGMR3InsertBytes(pRoot, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
187 rc = CFGMR3InsertInteger(pRoot, "RamSize", cRamMBs * _1M); RC_CHECK();
188 rc = CFGMR3InsertInteger(pRoot, "NumCPUs", cCpus); RC_CHECK();
189 rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10); RC_CHECK();
190 rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1); /* boolean */ RC_CHECK();
191 rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1); /* boolean */ RC_CHECK();
192 /** @todo Config: RawR0, PATMEnabled and CASMEnabled needs attention later. */
193 rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1); /* boolean */ RC_CHECK();
194 rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1); /* boolean */ RC_CHECK();
195
196 /* hardware virtualization extensions */
197 TSBool_T hwVirtExEnabled;
198 BOOL fHWVirtExEnabled;
199 hrc = pMachine->COMGETTER(HWVirtExEnabled)(&hwVirtExEnabled); H();
200 if (hwVirtExEnabled == TSBool_Default)
201 {
202 /* check the default value */
203 hrc = systemProperties->COMGETTER(HWVirtExEnabled)(&fHWVirtExEnabled); H();
204 }
205 else
206 fHWVirtExEnabled = (hwVirtExEnabled == TSBool_True);
207#ifdef RT_OS_DARWIN
208 rc = CFGMR3InsertInteger(pRoot, "HwVirtExtForced", fHWVirtExEnabled); RC_CHECK();
209#else
210 rc = CFGMR3InsertInteger(pRoot, "HwVirtExtForced", 0); RC_CHECK();
211#endif
212 if (fHWVirtExEnabled)
213 {
214 PCFGMNODE pHWVirtExt;
215 rc = CFGMR3InsertNode(pRoot, "HWVirtExt", &pHWVirtExt); RC_CHECK();
216 rc = CFGMR3InsertInteger(pHWVirtExt, "Enabled", 1); RC_CHECK();
217 }
218
219 /* Nested paging (VT-x/AMD-V) */
220 BOOL fEnableNestedPaging = false;
221 hrc = pMachine->COMGETTER(HWVirtExNestedPagingEnabled)(&fEnableNestedPaging); H();
222 rc = CFGMR3InsertInteger(pRoot, "EnableNestedPaging", fEnableNestedPaging); RC_CHECK();
223
224 /* VPID (VT-x) */
225 BOOL fEnableVPID = false;
226 hrc = pMachine->COMGETTER(HWVirtExVPIDEnabled)(&fEnableVPID); H();
227 rc = CFGMR3InsertInteger(pRoot, "EnableVPID", fEnableVPID); RC_CHECK();
228
229 /* Physical Address Extension (PAE) */
230 BOOL fEnablePAE = false;
231 hrc = pMachine->COMGETTER(PAEEnabled)(&fEnablePAE); H();
232 rc = CFGMR3InsertInteger(pRoot, "EnablePAE", fEnablePAE); RC_CHECK();
233
234 BOOL fIOAPIC;
235 hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
236
237 BOOL fPXEDebug;
238 hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
239
240 /*
241 * Virtual IDE controller type.
242 */
243 IDEControllerType_T controllerType;
244 BOOL fPIIX4;
245 hrc = biosSettings->COMGETTER(IDEControllerType)(&controllerType); H();
246 switch (controllerType)
247 {
248 case IDEControllerType_PIIX3:
249 fPIIX4 = FALSE;
250 break;
251 case IDEControllerType_PIIX4:
252 fPIIX4 = TRUE;
253 break;
254 default:
255 AssertMsgFailed(("Invalid IDE controller type '%d'", controllerType));
256 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
257 N_("Invalid IDE controller type '%d'"), controllerType);
258 }
259
260 /*
261 * PDM config.
262 * Load drivers in VBoxC.[so|dll]
263 */
264 PCFGMNODE pPDM;
265 PCFGMNODE pDrivers;
266 PCFGMNODE pMod;
267 rc = CFGMR3InsertNode(pRoot, "PDM", &pPDM); RC_CHECK();
268 rc = CFGMR3InsertNode(pPDM, "Drivers", &pDrivers); RC_CHECK();
269 rc = CFGMR3InsertNode(pDrivers, "VBoxC", &pMod); RC_CHECK();
270#ifdef VBOX_WITH_XPCOM
271 // VBoxC is located in the components subdirectory
272 char szPathVBoxC[RTPATH_MAX];
273 rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
274 strcat(szPathVBoxC, "/components/VBoxC");
275 rc = CFGMR3InsertString(pMod, "Path", szPathVBoxC); RC_CHECK();
276#else
277 rc = CFGMR3InsertString(pMod, "Path", "VBoxC"); RC_CHECK();
278#endif
279
280 /*
281 * Devices
282 */
283 PCFGMNODE pDevices = NULL; /* /Devices */
284 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
285 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
286 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
287 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
288 PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
289 PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
290 PCFGMNODE pIdeInst = NULL; /* /Devices/piix3ide/0/ */
291 PCFGMNODE pSataInst = NULL; /* /Devices/ahci/0/ */
292 PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
293
294 rc = CFGMR3InsertNode(pRoot, "Devices", &pDevices); RC_CHECK();
295
296 /*
297 * PC Arch.
298 */
299 rc = CFGMR3InsertNode(pDevices, "pcarch", &pDev); RC_CHECK();
300 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
301 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
302 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
303
304 /*
305 * PC Bios.
306 */
307 rc = CFGMR3InsertNode(pDevices, "pcbios", &pDev); RC_CHECK();
308 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
309 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
310 rc = CFGMR3InsertNode(pInst, "Config", &pBiosCfg); RC_CHECK();
311 rc = CFGMR3InsertInteger(pBiosCfg, "RamSize", cRamMBs * _1M); RC_CHECK();
312 rc = CFGMR3InsertInteger(pBiosCfg, "NumCPUs", cCpus); RC_CHECK();
313 rc = CFGMR3InsertString(pBiosCfg, "HardDiskDevice", "piix3ide"); RC_CHECK();
314 rc = CFGMR3InsertString(pBiosCfg, "FloppyDevice", "i82078"); RC_CHECK();
315 rc = CFGMR3InsertInteger(pBiosCfg, "IOAPIC", fIOAPIC); RC_CHECK();
316 rc = CFGMR3InsertInteger(pBiosCfg, "PXEDebug", fPXEDebug); RC_CHECK();
317 rc = CFGMR3InsertBytes(pBiosCfg, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
318
319 DeviceType_T bootDevice;
320 if (SchemaDefs::MaxBootPosition > 9)
321 {
322 AssertMsgFailed (("Too many boot devices %d\n",
323 SchemaDefs::MaxBootPosition));
324 return VERR_INVALID_PARAMETER;
325 }
326
327 for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; pos ++)
328 {
329 hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
330
331 char szParamName[] = "BootDeviceX";
332 szParamName[sizeof (szParamName) - 2] = ((char (pos - 1)) + '0');
333
334 const char *pszBootDevice;
335 switch (bootDevice)
336 {
337 case DeviceType_Null:
338 pszBootDevice = "NONE";
339 break;
340 case DeviceType_HardDisk:
341 pszBootDevice = "IDE";
342 break;
343 case DeviceType_DVD:
344 pszBootDevice = "DVD";
345 break;
346 case DeviceType_Floppy:
347 pszBootDevice = "FLOPPY";
348 break;
349 case DeviceType_Network:
350 pszBootDevice = "LAN";
351 break;
352 default:
353 AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
354 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
355 N_("Invalid boot device '%d'"), bootDevice);
356 }
357 rc = CFGMR3InsertString(pBiosCfg, szParamName, pszBootDevice); RC_CHECK();
358 }
359
360 /*
361 * The time offset
362 */
363 LONG64 timeOffset;
364 hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
365 PCFGMNODE pTMNode;
366 rc = CFGMR3InsertNode(pRoot, "TM", &pTMNode); RC_CHECK();
367 rc = CFGMR3InsertInteger(pTMNode, "UTCOffset", timeOffset * 1000000); RC_CHECK();
368
369 /*
370 * DMA
371 */
372 rc = CFGMR3InsertNode(pDevices, "8237A", &pDev); RC_CHECK();
373 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
374 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
375
376 /*
377 * PCI buses.
378 */
379 rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */ 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 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
384
385#if 0 /* enable this to test PCI bridging */
386 rc = CFGMR3InsertNode(pDevices, "pcibridge", &pDev); RC_CHECK();
387 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
388 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
389 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
390 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 14); RC_CHECK();
391 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
392 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 0);/* -> pci[0] */ RC_CHECK();
393
394 rc = CFGMR3InsertNode(pDev, "1", &pInst); RC_CHECK();
395 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
396 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
397 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 1); RC_CHECK();
398 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
399 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
400
401 rc = CFGMR3InsertNode(pDev, "2", &pInst); RC_CHECK();
402 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
403 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
404 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 3); RC_CHECK();
405 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
406 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
407#endif
408
409 /*
410 * PS/2 keyboard & mouse.
411 */
412 rc = CFGMR3InsertNode(pDevices, "pckbd", &pDev); RC_CHECK();
413 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
414 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
415 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
416
417 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
418 rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); RC_CHECK();
419 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
420 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); RC_CHECK();
421
422 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
423 rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard"); RC_CHECK();
424 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
425 Keyboard *pKeyboard = pConsole->mKeyboard;
426 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pKeyboard); RC_CHECK();
427
428 rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL0); RC_CHECK();
429 rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); RC_CHECK();
430 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
431 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); RC_CHECK();
432
433 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
434 rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse"); RC_CHECK();
435 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
436 Mouse *pMouse = pConsole->mMouse;
437 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse); RC_CHECK();
438
439 /*
440 * i82078 Floppy drive controller
441 */
442 ComPtr<IFloppyDrive> floppyDrive;
443 hrc = pMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam()); H();
444 BOOL fFdcEnabled;
445 hrc = floppyDrive->COMGETTER(Enabled)(&fFdcEnabled); H();
446 if (fFdcEnabled)
447 {
448 rc = CFGMR3InsertNode(pDevices, "i82078", &pDev); RC_CHECK();
449 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
450 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); RC_CHECK();
451 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
452 rc = CFGMR3InsertInteger(pCfg, "IRQ", 6); RC_CHECK();
453 rc = CFGMR3InsertInteger(pCfg, "DMA", 2); RC_CHECK();
454 rc = CFGMR3InsertInteger(pCfg, "MemMapped", 0 ); RC_CHECK();
455 rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x3f0); RC_CHECK();
456
457 /* Attach the status driver */
458 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
459 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
460 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
461 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapFDLeds[0]); RC_CHECK();
462 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
463 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
464
465 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
466
467 ComPtr<IFloppyImage2> floppyImage;
468 hrc = floppyDrive->GetImage(floppyImage.asOutParam()); H();
469 if (floppyImage)
470 {
471 pConsole->meFloppyState = DriveState_ImageMounted;
472 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
473 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
474 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
475 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
476
477 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
478 rc = CFGMR3InsertString(pLunL1, "Driver", "RawImage"); RC_CHECK();
479 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
480 hrc = floppyImage->COMGETTER(Location)(&str); H();
481 STR_CONV();
482 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
483 STR_FREE();
484 }
485 else
486 {
487 ComPtr<IHostFloppyDrive> hostFloppyDrive;
488 hrc = floppyDrive->GetHostDrive(hostFloppyDrive.asOutParam()); H();
489 if (hostFloppyDrive)
490 {
491 pConsole->meFloppyState = DriveState_HostDriveCaptured;
492 rc = CFGMR3InsertString(pLunL0, "Driver", "HostFloppy"); RC_CHECK();
493 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
494 hrc = hostFloppyDrive->COMGETTER(Name)(&str); H();
495 STR_CONV();
496 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
497 STR_FREE();
498 }
499 else
500 {
501 pConsole->meFloppyState = DriveState_NotMounted;
502 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
503 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
504 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
505 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
506 }
507 }
508 }
509
510 /*
511 * ACPI
512 */
513 BOOL fACPI;
514 hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
515 if (fACPI)
516 {
517 rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); RC_CHECK();
518 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
519 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
520 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
521 rc = CFGMR3InsertInteger(pCfg, "RamSize", cRamMBs * _1M); RC_CHECK();
522 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
523
524 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
525 rc = CFGMR3InsertInteger(pCfg, "FdcEnabled", fFdcEnabled); RC_CHECK();
526 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
527 Assert(!afPciDeviceNo[7]);
528 afPciDeviceNo[7] = true;
529 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
530
531 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
532 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
533 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
534 }
535
536 /*
537 * i8254 Programmable Interval Timer And Dummy Speaker
538 */
539 rc = CFGMR3InsertNode(pDevices, "i8254", &pDev); RC_CHECK();
540 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
541 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
542#ifdef DEBUG
543 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
544#endif
545
546 /*
547 * i8259 Programmable Interrupt Controller.
548 */
549 rc = CFGMR3InsertNode(pDevices, "i8259", &pDev); RC_CHECK();
550 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
551 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
552 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
553
554 /*
555 * Advanced Programmable Interrupt Controller.
556 * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
557 * thus only single insert
558 */
559 rc = CFGMR3InsertNode(pDevices, "apic", &pDev); RC_CHECK();
560 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
561 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
562 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
563 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
564 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
565
566 /* SMP: @todo: IOAPIC may be required for SMP configs */
567 if (fIOAPIC)
568 {
569 /*
570 * I/O Advanced Programmable Interrupt Controller.
571 */
572 rc = CFGMR3InsertNode(pDevices, "ioapic", &pDev); RC_CHECK();
573 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
574 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
575 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
576 }
577
578 /*
579 * RTC MC146818.
580 */
581 rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); RC_CHECK();
582 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
583 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
584
585 /*
586 * VGA.
587 */
588 rc = CFGMR3InsertNode(pDevices, "vga", &pDev); RC_CHECK();
589 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
590 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
591 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 2); RC_CHECK();
592 Assert(!afPciDeviceNo[2]);
593 afPciDeviceNo[2] = true;
594 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
595 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
596 hrc = pMachine->COMGETTER(VRAMSize)(&cRamMBs); H();
597 rc = CFGMR3InsertInteger(pCfg, "VRamSize", cRamMBs * _1M); RC_CHECK();
598#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
599 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", fHWVirtExEnabled); RC_CHECK();
600#endif
601
602 /*
603 * BIOS logo
604 */
605 BOOL fFadeIn;
606 hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
607 rc = CFGMR3InsertInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0); RC_CHECK();
608 BOOL fFadeOut;
609 hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
610 rc = CFGMR3InsertInteger(pCfg, "FadeOut", fFadeOut ? 1: 0); RC_CHECK();
611 ULONG logoDisplayTime;
612 hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
613 rc = CFGMR3InsertInteger(pCfg, "LogoTime", logoDisplayTime); RC_CHECK();
614 Bstr logoImagePath;
615 hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
616 rc = CFGMR3InsertString(pCfg, "LogoFile", logoImagePath ? Utf8Str(logoImagePath) : ""); RC_CHECK();
617
618 /*
619 * Boot menu
620 */
621 BIOSBootMenuMode_T bootMenuMode;
622 int value;
623 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
624 switch (bootMenuMode)
625 {
626 case BIOSBootMenuMode_Disabled:
627 value = 0;
628 break;
629 case BIOSBootMenuMode_MenuOnly:
630 value = 1;
631 break;
632 default:
633 value = 2;
634 }
635 rc = CFGMR3InsertInteger(pCfg, "ShowBootMenu", value); RC_CHECK();
636
637 /* Custom VESA mode list */
638 unsigned cModes = 0;
639 for (unsigned iMode = 1; iMode <= 16; iMode++)
640 {
641 char szExtraDataKey[sizeof("CustomVideoModeXX")];
642 RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%d", iMode);
643 hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), &str); H();
644 if (!str || !*str)
645 break;
646 STR_CONV();
647 rc = CFGMR3InsertString(pCfg, szExtraDataKey, psz);
648 STR_FREE();
649 cModes++;
650 }
651 rc = CFGMR3InsertInteger(pCfg, "CustomVideoModes", cModes);
652
653 /* VESA height reduction */
654 ULONG ulHeightReduction;
655 IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
656 if (pFramebuffer)
657 {
658 hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
659 }
660 else
661 {
662 /* If framebuffer is not available, there is no height reduction. */
663 ulHeightReduction = 0;
664 }
665 rc = CFGMR3InsertInteger(pCfg, "HeightReduction", ulHeightReduction); RC_CHECK();
666
667 /* Attach the display. */
668 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
669 rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay"); RC_CHECK();
670 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
671 Display *pDisplay = pConsole->mDisplay;
672 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pDisplay); RC_CHECK();
673
674 /*
675 * IDE (update this when the main interface changes)
676 */
677 rc = CFGMR3InsertNode(pDevices, "piix3ide", &pDev); /* piix3 */ RC_CHECK();
678 rc = CFGMR3InsertNode(pDev, "0", &pIdeInst); RC_CHECK();
679 rc = CFGMR3InsertInteger(pIdeInst, "Trusted", 1); /* boolean */ RC_CHECK();
680 rc = CFGMR3InsertInteger(pIdeInst, "PCIDeviceNo", 1); RC_CHECK();
681 Assert(!afPciDeviceNo[1]);
682 afPciDeviceNo[1] = true;
683 rc = CFGMR3InsertInteger(pIdeInst, "PCIFunctionNo", 1); RC_CHECK();
684 rc = CFGMR3InsertNode(pIdeInst, "Config", &pCfg); RC_CHECK();
685 rc = CFGMR3InsertInteger(pCfg, "PIIX4", fPIIX4); /* boolean */ RC_CHECK();
686
687 /* Attach the status driver */
688 rc = CFGMR3InsertNode(pIdeInst, "LUN#999", &pLunL0); RC_CHECK();
689 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
690 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
691 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapIDELeds[0]);RC_CHECK();
692 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
693 rc = CFGMR3InsertInteger(pCfg, "Last", 3); RC_CHECK();
694
695 /*
696 * SATA controller
697 */
698 ComPtr<ISATAController> sataController;
699 hrc = pMachine->COMGETTER(SATAController)(sataController.asOutParam());
700 BOOL enabled = FALSE;
701
702 if (sataController)
703 {
704 hrc = sataController->COMGETTER(Enabled)(&enabled); H();
705
706 if (enabled)
707 {
708 rc = CFGMR3InsertNode(pDevices, "ahci", &pDev); RC_CHECK();
709 rc = CFGMR3InsertNode(pDev, "0", &pSataInst); RC_CHECK();
710 rc = CFGMR3InsertInteger(pSataInst, "Trusted", 1); RC_CHECK();
711 rc = CFGMR3InsertInteger(pSataInst, "PCIDeviceNo", 13); RC_CHECK();
712 Assert(!afPciDeviceNo[13]);
713 afPciDeviceNo[13] = true;
714 rc = CFGMR3InsertInteger(pSataInst, "PCIFunctionNo", 0); RC_CHECK();
715 rc = CFGMR3InsertNode(pSataInst, "Config", &pCfg); RC_CHECK();
716
717 ULONG cPorts = 0;
718 hrc = sataController->COMGETTER(PortCount)(&cPorts); H();
719 rc = CFGMR3InsertInteger(pCfg, "PortCount", cPorts); RC_CHECK();
720
721 /* Needed configuration values for the bios. */
722 rc = CFGMR3InsertString(pBiosCfg, "SataHardDiskDevice", "ahci"); RC_CHECK();
723
724 for (uint32_t i = 0; i < 4; i++)
725 {
726 static const char *s_apszConfig[4] =
727 { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
728 static const char *s_apszBiosConfig[4] =
729 { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
730
731 LONG lPortNumber = -1;
732 hrc = sataController->GetIDEEmulationPort(i, &lPortNumber); H();
733 rc = CFGMR3InsertInteger(pCfg, s_apszConfig[i], lPortNumber); RC_CHECK();
734 rc = CFGMR3InsertInteger(pBiosCfg, s_apszBiosConfig[i], lPortNumber); RC_CHECK();
735 }
736
737 /* Attach the status driver */
738 rc = CFGMR3InsertNode(pSataInst,"LUN#999", &pLunL0); RC_CHECK();
739 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
740 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
741 AssertRelease(cPorts <= RT_ELEMENTS(pConsole->mapSATALeds));
742 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSATALeds[0]); RC_CHECK();
743 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
744 rc = CFGMR3InsertInteger(pCfg, "Last", cPorts - 1); RC_CHECK();
745 }
746 }
747
748 /* Attach the hard disks */
749 {
750 com::SafeIfaceArray <IHardDisk2Attachment> atts;
751 hrc = pMachine->
752 COMGETTER(HardDisk2Attachments) (ComSafeArrayAsOutParam (atts)); H();
753
754 for (size_t i = 0; i < atts.size(); ++ i)
755 {
756 ComPtr <IHardDisk2> hardDisk;
757 hrc = atts [i]->COMGETTER(HardDisk) (hardDisk.asOutParam()); H();
758 StorageBus_T enmBus;
759 hrc = atts [i]->COMGETTER(Bus) (&enmBus); H();
760 LONG lDev;
761 hrc = atts [i]->COMGETTER(Device) (&lDev); H();
762 LONG lChannel;
763 hrc = atts [i]->COMGETTER(Channel) (&lChannel); H();
764
765 PCFGMNODE pHardDiskCtl = NULL;
766 int iLUN = 0;
767
768 switch (enmBus)
769 {
770 case StorageBus_IDE:
771 {
772 if (lChannel >= 2 || lChannel < 0)
773 {
774 AssertMsgFailed (("invalid controller channel number: "
775 "%d\n", lChannel));
776 return VERR_GENERAL_FAILURE;
777 }
778
779 if (lDev >= 2 || lDev < 0)
780 {
781 AssertMsgFailed (("invalid controller device number: "
782 "%d\n", lDev));
783 return VERR_GENERAL_FAILURE;
784 }
785
786 iLUN = 2 * lChannel + lDev;
787 pHardDiskCtl = pIdeInst;
788
789 break;
790 }
791 case StorageBus_SATA:
792 {
793 iLUN = lChannel;
794 pHardDiskCtl = enabled ? pSataInst : NULL;
795 break;
796 }
797 default:
798 {
799 AssertMsgFailed (("invalid disk controller type: "
800 "%d\n", enmBus));
801 return VERR_GENERAL_FAILURE;
802 }
803 }
804
805 /* Can be NULL if SATA controller is not enabled and current hard
806 * disk is attached to SATA controller. */
807 if (pHardDiskCtl == NULL)
808 continue;
809
810 char szLUN[16];
811 RTStrPrintf (szLUN, sizeof(szLUN), "LUN#%d", iLUN);
812
813 rc = CFGMR3InsertNode (pHardDiskCtl, szLUN, &pLunL0); RC_CHECK();
814 rc = CFGMR3InsertString (pLunL0, "Driver", "Block"); RC_CHECK();
815 rc = CFGMR3InsertNode (pLunL0, "Config", &pCfg); RC_CHECK();
816 rc = CFGMR3InsertString (pCfg, "Type", "HardDisk"); RC_CHECK();
817 rc = CFGMR3InsertInteger (pCfg, "Mountable", 0); RC_CHECK();
818
819 rc = CFGMR3InsertNode (pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
820 rc = CFGMR3InsertString (pLunL1, "Driver", "VD"); RC_CHECK();
821 rc = CFGMR3InsertNode (pLunL1, "Config", &pCfg); RC_CHECK();
822
823 hrc = hardDisk->COMGETTER(Location) (bstr.asOutParam()); H();
824 rc = CFGMR3InsertString (pCfg, "Path", Utf8Str (bstr)); RC_CHECK();
825
826 hrc = hardDisk->COMGETTER(Format) (bstr.asOutParam()); H();
827 rc = CFGMR3InsertString (pCfg, "Format", Utf8Str (bstr)); RC_CHECK();
828
829#if defined(VBOX_WITH_PDM_ASYNC_COMPLETION)
830 if (bstr == L"VMDK")
831 {
832 /* Create cfgm nodes for async transport driver because VMDK is
833 * currently the only one which may support async I/O. This has
834 * to be made generic based on the capabiliy flags when the new
835 * HardDisk interface is merged.
836 */
837 rc = CFGMR3InsertNode (pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
838 rc = CFGMR3InsertString (pLunL2, "Driver", "TransportAsync"); RC_CHECK();
839 /* The async transport driver has no config options yet. */
840 }
841#endif
842 /* Pass all custom parameters. */
843 SafeArray <BSTR> names;
844 SafeArray <BSTR> values;
845 hrc = hardDisk->GetProperties (NULL,
846 ComSafeArrayAsOutParam (names),
847 ComSafeArrayAsOutParam (values)); H();
848
849 if (names.size() != 0)
850 {
851 PCFGMNODE pVDC;
852 rc = CFGMR3InsertNode (pCfg, "VDConfig", &pVDC); RC_CHECK();
853 for (size_t i = 0; i < names.size(); ++ i)
854 {
855 rc = CFGMR3InsertString (pVDC, Utf8Str (names [i]),
856 Utf8Str (values [i])); RC_CHECK();
857 }
858 }
859
860 /* Create an inversed tree of parents. */
861 ComPtr <IHardDisk2> parentHardDisk = hardDisk;
862 for (PCFGMNODE pParent = pCfg;;)
863 {
864 hrc = parentHardDisk->
865 COMGETTER(Parent) (hardDisk.asOutParam()); H();
866 if (hardDisk.isNull())
867 break;
868
869 PCFGMNODE pCur;
870 rc = CFGMR3InsertNode (pParent, "Parent", &pCur); RC_CHECK();
871 hrc = hardDisk->COMGETTER(Location) (bstr.asOutParam()); H();
872 rc = CFGMR3InsertString (pCur, "Path", Utf8Str (bstr)); RC_CHECK();
873
874 hrc = hardDisk->COMGETTER(Format) (bstr.asOutParam()); H();
875 rc = CFGMR3InsertString (pCur, "Format", Utf8Str (bstr)); RC_CHECK();
876
877 /* Pass all custom parameters. */
878 SafeArray <BSTR> names;
879 SafeArray <BSTR> values;
880 hrc = hardDisk->GetProperties (NULL,
881 ComSafeArrayAsOutParam (names),
882 ComSafeArrayAsOutParam (values));H();
883
884 if (names.size() != 0)
885 {
886 PCFGMNODE pVDC;
887 rc = CFGMR3InsertNode (pCfg, "VDConfig", &pVDC); RC_CHECK();
888 for (size_t i = 0; i < names.size(); ++ i)
889 {
890 rc = CFGMR3InsertString (pVDC, Utf8Str (names [i]),
891 Utf8Str (values [i])); RC_CHECK();
892 }
893 }
894
895 /* next */
896 pParent = pCur;
897 parentHardDisk = hardDisk;
898 }
899 }
900 }
901 H();
902
903 ComPtr<IDVDDrive> dvdDrive;
904 hrc = pMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam()); H();
905 if (dvdDrive)
906 {
907 // ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
908 rc = CFGMR3InsertNode(pIdeInst, "LUN#2", &pLunL0); RC_CHECK();
909 ComPtr<IHostDVDDrive> hostDvdDrive;
910 hrc = dvdDrive->GetHostDrive(hostDvdDrive.asOutParam()); H();
911 if (hostDvdDrive)
912 {
913 pConsole->meDVDState = DriveState_HostDriveCaptured;
914 rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
915 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
916 hrc = hostDvdDrive->COMGETTER(Name)(&str); H();
917 STR_CONV();
918 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
919 STR_FREE();
920 BOOL fPassthrough;
921 hrc = dvdDrive->COMGETTER(Passthrough)(&fPassthrough); H();
922 rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough); RC_CHECK();
923 }
924 else
925 {
926 pConsole->meDVDState = DriveState_NotMounted;
927 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
928 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
929 rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
930 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
931
932 ComPtr<IDVDImage2> dvdImage;
933 hrc = dvdDrive->GetImage(dvdImage.asOutParam()); H();
934 if (dvdImage)
935 {
936 pConsole->meDVDState = DriveState_ImageMounted;
937 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
938 rc = CFGMR3InsertString(pLunL1, "Driver", "MediaISO"); RC_CHECK();
939 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
940 hrc = dvdImage->COMGETTER(Location)(&str); H();
941 STR_CONV();
942 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
943 STR_FREE();
944 }
945 }
946 }
947
948 /*
949 * Network adapters
950 */
951 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
952 rc = CFGMR3InsertNode(pDevices, "pcnet", &pDevPCNet); RC_CHECK();
953#ifdef VBOX_WITH_E1000
954 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
955 rc = CFGMR3InsertNode(pDevices, "e1000", &pDevE1000); RC_CHECK();
956#endif
957 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ulInstance++)
958 {
959 ComPtr<INetworkAdapter> networkAdapter;
960 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
961 BOOL fEnabled = FALSE;
962 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
963 if (!fEnabled)
964 continue;
965
966 /*
967 * The virtual hardware type. Create appropriate device first.
968 */
969 NetworkAdapterType_T adapterType;
970 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
971 switch (adapterType)
972 {
973 case NetworkAdapterType_Am79C970A:
974 case NetworkAdapterType_Am79C973:
975 pDev = pDevPCNet;
976 break;
977#ifdef VBOX_WITH_E1000
978 case NetworkAdapterType_I82540EM:
979 case NetworkAdapterType_I82543GC:
980 pDev = pDevE1000;
981 break;
982#endif
983 default:
984 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
985 adapterType, ulInstance));
986 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
987 N_("Invalid network adapter type '%d' for slot '%d'"),
988 adapterType, ulInstance);
989 }
990
991 char szInstance[4]; Assert(ulInstance <= 999);
992 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
993 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
994 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
995 /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
996 * next 4 get 16..19. */
997 unsigned iPciDeviceNo = 3;
998 if (ulInstance)
999 {
1000 if (ulInstance < 4)
1001 iPciDeviceNo = ulInstance - 1 + 8;
1002 else
1003 iPciDeviceNo = ulInstance - 4 + 16;
1004 }
1005 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
1006 Assert(!afPciDeviceNo[iPciDeviceNo]);
1007 afPciDeviceNo[iPciDeviceNo] = true;
1008 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1009 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1010#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
1011 if (pDev == pDevPCNet)
1012 {
1013 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", false); RC_CHECK();
1014 }
1015#endif
1016
1017 /*
1018 * The virtual hardware type. PCNet supports two types.
1019 */
1020 switch (adapterType)
1021 {
1022 case NetworkAdapterType_Am79C970A:
1023 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
1024 break;
1025 case NetworkAdapterType_Am79C973:
1026 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
1027 break;
1028 case NetworkAdapterType_I82540EM:
1029 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
1030 break;
1031 case NetworkAdapterType_I82543GC:
1032 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
1033 break;
1034 }
1035
1036 /*
1037 * Get the MAC address and convert it to binary representation
1038 */
1039 Bstr macAddr;
1040 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1041 Assert(macAddr);
1042 Utf8Str macAddrUtf8 = macAddr;
1043 char *macStr = (char*)macAddrUtf8.raw();
1044 Assert(strlen(macStr) == 12);
1045 RTMAC Mac;
1046 memset(&Mac, 0, sizeof(Mac));
1047 char *pMac = (char*)&Mac;
1048 for (uint32_t i = 0; i < 6; i++)
1049 {
1050 char c1 = *macStr++ - '0';
1051 if (c1 > 9)
1052 c1 -= 7;
1053 char c2 = *macStr++ - '0';
1054 if (c2 > 9)
1055 c2 -= 7;
1056 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1057 }
1058 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1059
1060 /*
1061 * Check if the cable is supposed to be unplugged
1062 */
1063 BOOL fCableConnected;
1064 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1065 rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
1066
1067 /*
1068 * Line speed to report from custom drivers
1069 */
1070 ULONG ulLineSpeed;
1071 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1072 rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
1073
1074 /*
1075 * Attach the status driver.
1076 */
1077 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1078 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1079 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1080 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
1081
1082 /*
1083 * Enable the packet sniffer if requested.
1084 */
1085 BOOL fSniffer;
1086 hrc = networkAdapter->COMGETTER(TraceEnabled)(&fSniffer); H();
1087 if (fSniffer)
1088 {
1089 /* insert the sniffer filter driver. */
1090 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1091 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
1092 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1093 hrc = networkAdapter->COMGETTER(TraceFile)(&str); H();
1094 if (str) /* check convention for indicating default file. */
1095 {
1096 STR_CONV();
1097 rc = CFGMR3InsertString(pCfg, "File", psz); RC_CHECK();
1098 STR_FREE();
1099 }
1100 }
1101
1102 NetworkAttachmentType_T networkAttachment;
1103 hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H();
1104 switch (networkAttachment)
1105 {
1106 case NetworkAttachmentType_Null:
1107 break;
1108
1109 case NetworkAttachmentType_NAT:
1110 {
1111 if (fSniffer)
1112 {
1113 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1114 }
1115 else
1116 {
1117 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1118 }
1119 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
1120 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1121 /* (Port forwarding goes here.) */
1122
1123 /* Configure TFTP prefix and boot filename. */
1124 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
1125 STR_CONV();
1126 if (psz && *psz)
1127 {
1128 char *pszTFTPPrefix = NULL;
1129 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
1130 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix); RC_CHECK();
1131 RTStrFree(pszTFTPPrefix);
1132 }
1133 STR_FREE();
1134 hrc = pMachine->COMGETTER(Name)(&str); H();
1135 STR_CONV();
1136 char *pszBootFile = NULL;
1137 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
1138 STR_FREE();
1139 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile); RC_CHECK();
1140 RTStrFree(pszBootFile);
1141
1142 hrc = networkAdapter->COMGETTER(NATNetwork)(&str); H();
1143 if (str)
1144 {
1145 STR_CONV();
1146 if (psz && *psz)
1147 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1148 STR_FREE();
1149 }
1150 break;
1151 }
1152
1153 case NetworkAttachmentType_HostInterface:
1154 {
1155 /*
1156 * Perform the attachment if required (don't return on error!)
1157 */
1158 hrc = pConsole->attachToHostInterface(networkAdapter);
1159 if (SUCCEEDED(hrc))
1160 {
1161#ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
1162 Assert ((int)pConsole->maTapFD[ulInstance] >= 0);
1163 if ((int)pConsole->maTapFD[ulInstance] >= 0)
1164 {
1165 if (fSniffer)
1166 {
1167 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1168 }
1169 else
1170 {
1171 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1172 }
1173 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1174 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1175# if defined(RT_OS_SOLARIS)
1176 /* Device name/number is required for Solaris as we need it for TAP PPA. */
1177 Bstr tapDeviceName;
1178 networkAdapter->COMGETTER(HostInterface)(tapDeviceName.asOutParam());
1179 if (!tapDeviceName.isEmpty())
1180 rc = CFGMR3InsertString(pCfg, "Device", Utf8Str(tapDeviceName)); RC_CHECK();
1181
1182 /* TAP setup application/script */
1183 Bstr tapSetupApp;
1184 networkAdapter->COMGETTER(TAPSetupApplication)(tapSetupApp.asOutParam());
1185 if (!tapSetupApp.isEmpty())
1186 rc = CFGMR3InsertString(pCfg, "TAPSetupApplication", Utf8Str(tapSetupApp)); RC_CHECK();
1187
1188 /* TAP terminate application/script */
1189 Bstr tapTerminateApp;
1190 networkAdapter->COMGETTER(TAPTerminateApplication)(tapTerminateApp.asOutParam());
1191 if (!tapTerminateApp.isEmpty())
1192 rc = CFGMR3InsertString(pCfg, "TAPTerminateApplication", Utf8Str(tapTerminateApp)); RC_CHECK();
1193
1194 /* "FileHandle" must NOT be inserted here, it is done in DrvTAP.cpp */
1195
1196# ifdef VBOX_WITH_CROSSBOW
1197 /* Crossbow: needs the MAC address for setting up TAP. */
1198 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1199# endif
1200# else
1201 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pConsole->maTapFD[ulInstance]); RC_CHECK();
1202# endif
1203 }
1204
1205#elif defined(VBOX_WITH_NETFLT)
1206 /*
1207 * This is the new VBoxNetFlt+IntNet stuff.
1208 */
1209 if (fSniffer)
1210 {
1211 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1212 }
1213 else
1214 {
1215 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1216 }
1217
1218 Bstr HifName;
1219 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1220 if(FAILED(hrc))
1221 {
1222 LogRel(("NetworkAttachmentType_HostInterface: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1223 H();
1224 }
1225
1226 Utf8Str HifNameUtf8(HifName);
1227 const char *pszHifName = HifNameUtf8.raw();
1228
1229# if defined(RT_OS_DARWIN)
1230 /* The name is on the form 'ifX: long name', chop it off at the colon. */
1231 char szTrunk[8];
1232 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
1233 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1234 if (!pszColon)
1235 {
1236 hrc = networkAdapter->Detach(); H();
1237 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1238 N_("Malformed host interface networking name '%ls'"),
1239 HifName.raw());
1240 }
1241 *pszColon = '\0';
1242 const char *pszTrunk = szTrunk;
1243
1244# elif defined(RT_OS_SOLARIS)
1245 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
1246 char szTrunk[256];
1247 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
1248 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
1249
1250 /*
1251 * Currently don't bother about malformed names here for the sake of people using
1252 * VBoxManage and setting only the NIC name from there. If there is a space we
1253 * chop it off and proceed, otherwise just use whatever we've got.
1254 */
1255 if (pszSpace)
1256 *pszSpace = '\0';
1257
1258 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
1259 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1260 if (pszColon)
1261 *pszColon = '\0';
1262
1263 const char *pszTrunk = szTrunk;
1264
1265# elif defined(RT_OS_WINDOWS)
1266 ComPtr<IHostNetworkInterfaceCollection> coll;
1267 hrc = host->COMGETTER(NetworkInterfaces)(coll.asOutParam());
1268 if(FAILED(hrc))
1269 {
1270 LogRel(("NetworkAttachmentType_HostInterface: COMGETTER(NetworkInterfaces) failed, hrc (0x%x)", hrc));
1271 H();
1272 }
1273 ComPtr<IHostNetworkInterface> hostInterface;
1274 rc = coll->FindByName(HifName, hostInterface.asOutParam());
1275 if (!SUCCEEDED(rc))
1276 {
1277 AssertBreakpoint();
1278 LogRel(("NetworkAttachmentType_HostInterface: FindByName failed, rc (0x%x)", rc));
1279 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1280 N_("Inexistent host networking interface, name '%ls'"),
1281 HifName.raw());
1282 }
1283
1284 Guid hostIFGuid;
1285 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1286 if(FAILED(hrc))
1287 {
1288 LogRel(("NetworkAttachmentType_HostInterface: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1289 H();
1290 }
1291 char szDriverGUID[RTUUID_STR_LENGTH];
1292 strcpy(szDriverGUID , hostIFGuid.toString().raw());
1293 const char *pszTrunk = szDriverGUID;
1294# elif defined(RT_OS_LINUX)
1295 /* @todo Check for malformed names. */
1296 const char *pszTrunk = pszHifName;
1297
1298# else
1299# error "PORTME (VBOX_WITH_NETFLT)"
1300# endif
1301
1302 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1303 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1304 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1305 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1306 char szNetwork[80];
1307 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1308 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1309
1310# if defined(RT_OS_DARWIN)
1311 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
1312 if ( strstr(pszHifName, "Wireless")
1313 || strstr(pszHifName, "AirPort" ))
1314 {
1315 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1316 }
1317# elif defined(RT_OS_LINUX)
1318 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
1319 if (iSock >= 0)
1320 {
1321 struct iwreq WRq;
1322
1323 memset(&WRq, 0, sizeof(WRq));
1324 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
1325 if (ioctl(iSock, SIOCGIWNAME, &WRq) >= 0)
1326 {
1327 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1328 Log(("Set SharedMacOnWire\n"));
1329 }
1330 else
1331 {
1332 Log(("Failed to get wireless name\n"));
1333 }
1334 close(iSock);
1335 }
1336 else
1337 {
1338 Log(("Failed to open wireless socket\n"));
1339 }
1340# elif defined(RT_OS_WINDOWS)
1341# define DEVNAME_PREFIX L"\\\\.\\"
1342 INetCfg *pNc;
1343 LPWSTR lpszApp;
1344 HRESULT hr;
1345 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
1346
1347 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
1348 * there is a pretty long way till there though since we need to obtain the symbolic link name
1349 * for the adapter device we are going to query given the device Guid */
1350 hr = VBoxNetCfgWinQueryINetCfg( FALSE,
1351 L"VirtualBox",
1352 &pNc,
1353 &lpszApp );
1354 Assert(hr == S_OK);
1355 if(hr == S_OK)
1356 {
1357 /* get the adapter's INetCfgComponent*/
1358 INetCfgComponent *pAdaptorComponent;
1359 hr = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), &pAdaptorComponent);
1360 Assert(hr == S_OK);
1361 if(hr == S_OK)
1362 {
1363 /* now get the bind name */
1364 LPWSTR pName;
1365 hr = pAdaptorComponent->GetBindName(&pName);
1366 Assert(hr == S_OK);
1367 if(hr == S_OK)
1368 {
1369 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
1370 wchar_t FileName[MAX_PATH];
1371 wcscpy(FileName, DEVNAME_PREFIX);
1372 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pName);
1373
1374 /* open the device */
1375 HANDLE hDevice = CreateFile(FileName,
1376 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
1377 NULL,
1378 OPEN_EXISTING,
1379 FILE_ATTRIBUTE_NORMAL,
1380 NULL);
1381 if (hDevice != INVALID_HANDLE_VALUE)
1382 {
1383 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
1384 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
1385 NDIS_PHYSICAL_MEDIUM PhMedium;
1386 DWORD cbResult;
1387 if (DeviceIoControl(hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, &Oid, sizeof(Oid), &PhMedium, sizeof(PhMedium), &cbResult, NULL))
1388 {
1389 /* that was simple, now examine PhMedium */
1390 if(PhMedium == NdisPhysicalMediumWirelessWan
1391 || PhMedium == NdisPhysicalMediumWirelessLan
1392 || PhMedium == NdisPhysicalMediumNative802_11
1393 || PhMedium == NdisPhysicalMediumBluetooth
1394 /*|| PhMedium == NdisPhysicalMediumWiMax*/
1395 )
1396 {
1397 Log(("this is a wireles adapter"));
1398 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1399 Log(("Set SharedMacOnWire\n"));
1400 }
1401 else
1402 {
1403 Log(("this is NOT a wireles adapter"));
1404 }
1405 }
1406 else
1407 {
1408 int winEr = GetLastError();
1409 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
1410 AssertBreakpoint();
1411 }
1412
1413 CloseHandle(hDevice);
1414 }
1415 else
1416 {
1417 int winEr = GetLastError();
1418 LogRel(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
1419 AssertBreakpoint();
1420 }
1421 CoTaskMemFree(pName);
1422 }
1423 VBoxNetCfgWinReleaseRef(pAdaptorComponent);
1424 }
1425 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1426 }
1427# else
1428 /** @todo PORTME: wireless detection */
1429# endif
1430
1431# if defined(RT_OS_SOLARIS)
1432# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
1433 /* Zone access restriction, don't allow snopping the global zone. */
1434 zoneid_t ZoneId = getzoneid();
1435 if (ZoneId != GLOBAL_ZONEID)
1436 {
1437 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
1438 }
1439# endif
1440# endif
1441
1442#elif defined(RT_OS_WINDOWS)
1443 if (fSniffer)
1444 {
1445 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1446 }
1447 else
1448 {
1449 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1450 }
1451 Bstr hostInterfaceName;
1452 hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
1453 ComPtr<IHostNetworkInterfaceCollection> coll;
1454 hrc = host->COMGETTER(NetworkInterfaces)(coll.asOutParam()); H();
1455 ComPtr<IHostNetworkInterface> hostInterface;
1456 rc = coll->FindByName(hostInterfaceName, hostInterface.asOutParam());
1457 if (!SUCCEEDED(rc))
1458 {
1459 AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
1460 hrc = networkAdapter->Detach(); H();
1461 }
1462 else
1463 {
1464# ifndef VBOX_WITH_NETFLT
1465 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1466 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1467 rc = CFGMR3InsertString(pCfg, "HostInterfaceName", Utf8Str(hostInterfaceName)); RC_CHECK();
1468# else
1469 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1470 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1471 rc = CFGMR3InsertString(pCfg, "Trunk", Utf8Str(hostInterfaceName)); RC_CHECK();
1472 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1473# endif
1474 Guid hostIFGuid;
1475 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1476 char szDriverGUID[256] = {0};
1477 /* add curly brackets */
1478 szDriverGUID[0] = '{';
1479 strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
1480 strcat(szDriverGUID, "}");
1481 rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
1482 }
1483#elif defined(RT_OS_LINUX)
1484/// @todo aleksey: is there anything to be done here?
1485#else
1486# error "Port me"
1487#endif
1488 }
1489 else
1490 {
1491 switch (hrc)
1492 {
1493#ifdef RT_OS_LINUX
1494 case VERR_ACCESS_DENIED:
1495 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1496 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1497 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
1498 "change the group of that node and make yourself a member of that group. Make "
1499 "sure that these changes are permanent, especially if you are "
1500 "using udev"));
1501#endif /* RT_OS_LINUX */
1502 default:
1503 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1504 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1505 "Failed to initialize Host Interface Networking"));
1506 }
1507 }
1508 break;
1509 }
1510
1511 case NetworkAttachmentType_Internal:
1512 {
1513 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1514 if (str)
1515 {
1516 STR_CONV();
1517 if (psz && *psz)
1518 {
1519 if (fSniffer)
1520 {
1521 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1522 }
1523 else
1524 {
1525 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1526 }
1527 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1528 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1529 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1530 }
1531 STR_FREE();
1532 }
1533 break;
1534 }
1535
1536 default:
1537 AssertMsgFailed(("should not get here!\n"));
1538 break;
1539 }
1540 }
1541
1542 /*
1543 * Serial (UART) Ports
1544 */
1545 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1546 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1547 {
1548 ComPtr<ISerialPort> serialPort;
1549 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1550 BOOL fEnabled = FALSE;
1551 if (serialPort)
1552 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1553 if (!fEnabled)
1554 continue;
1555
1556 char szInstance[4]; Assert(ulInstance <= 999);
1557 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1558
1559 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1560 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1561
1562 ULONG ulIRQ, ulIOBase;
1563 PortMode_T HostMode;
1564 Bstr path;
1565 BOOL fServer;
1566 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1567 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1568 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1569 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1570 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1571 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1572 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1573 if (HostMode != PortMode_Disconnected)
1574 {
1575 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1576 if (HostMode == PortMode_HostPipe)
1577 {
1578 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1579 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1580 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1581 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1582 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1583 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1584 }
1585 else if (HostMode == PortMode_HostDevice)
1586 {
1587 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1588 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1589 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1590 }
1591 }
1592 }
1593
1594 /*
1595 * Parallel (LPT) Ports
1596 */
1597 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1598 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1599 {
1600 ComPtr<IParallelPort> parallelPort;
1601 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1602 BOOL fEnabled = FALSE;
1603 if (parallelPort)
1604 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1605 if (!fEnabled)
1606 continue;
1607
1608 char szInstance[4]; Assert(ulInstance <= 999);
1609 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1610
1611 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1612 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1613
1614 ULONG ulIRQ, ulIOBase;
1615 Bstr DevicePath;
1616 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1617 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1618 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1619 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1620 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1621 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1622 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1623 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1624 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1625 }
1626
1627 /*
1628 * VMM Device
1629 */
1630 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1631 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1632 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1633 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1634 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1635 Assert(!afPciDeviceNo[4]);
1636 afPciDeviceNo[4] = true;
1637 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1638
1639 /* the VMM device's Main driver */
1640 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1641 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1642 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1643 VMMDev *pVMMDev = pConsole->mVMMDev;
1644 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1645
1646 /*
1647 * Attach the status driver.
1648 */
1649 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1650 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1651 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1652 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1653 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1654 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1655
1656 /*
1657 * Audio Sniffer Device
1658 */
1659 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1660 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1661 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1662
1663 /* the Audio Sniffer device's Main driver */
1664 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1665 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1666 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1667 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1668 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1669
1670 /*
1671 * AC'97 ICH / SoundBlaster16 audio
1672 */
1673 ComPtr<IAudioAdapter> audioAdapter;
1674 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1675 if (audioAdapter)
1676 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1677
1678 if (enabled)
1679 {
1680 AudioControllerType_T audioController;
1681 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
1682 switch (audioController)
1683 {
1684 case AudioControllerType_AC97:
1685 {
1686 /* default: ICH AC97 */
1687 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
1688 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1689 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1690 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1691 Assert(!afPciDeviceNo[5]);
1692 afPciDeviceNo[5] = true;
1693 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1694 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1695 break;
1696 }
1697 case AudioControllerType_SB16:
1698 {
1699 /* legacy SoundBlaster16 */
1700 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
1701 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1702 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1703 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1704 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
1705 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
1706 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
1707 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
1708 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
1709 break;
1710 }
1711 }
1712
1713 /* the Audio driver */
1714 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1715 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1716 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1717
1718 AudioDriverType_T audioDriver;
1719 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1720 switch (audioDriver)
1721 {
1722 case AudioDriverType_Null:
1723 {
1724 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1725 break;
1726 }
1727#ifdef RT_OS_WINDOWS
1728#ifdef VBOX_WITH_WINMM
1729 case AudioDriverType_WinMM:
1730 {
1731 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1732 break;
1733 }
1734#endif
1735 case AudioDriverType_DirectSound:
1736 {
1737 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
1738 break;
1739 }
1740#endif /* RT_OS_WINDOWS */
1741#ifdef RT_OS_SOLARIS
1742 case AudioDriverType_SolAudio:
1743 {
1744 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
1745 break;
1746 }
1747#endif
1748#ifdef RT_OS_LINUX
1749 case AudioDriverType_OSS:
1750 {
1751 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
1752 break;
1753 }
1754# ifdef VBOX_WITH_ALSA
1755 case AudioDriverType_ALSA:
1756 {
1757 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
1758 break;
1759 }
1760# endif
1761# ifdef VBOX_WITH_PULSE
1762 case AudioDriverType_Pulse:
1763 {
1764 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
1765 break;
1766 }
1767# endif
1768#endif /* RT_OS_LINUX */
1769#ifdef RT_OS_DARWIN
1770 case AudioDriverType_CoreAudio:
1771 {
1772 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1773 break;
1774 }
1775#endif
1776 }
1777 hrc = pMachine->COMGETTER(Name)(&str); H();
1778 STR_CONV();
1779 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
1780 STR_FREE();
1781 }
1782
1783 /*
1784 * The USB Controller.
1785 */
1786 ComPtr<IUSBController> USBCtlPtr;
1787 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1788 if (USBCtlPtr)
1789 {
1790 BOOL fEnabled;
1791 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1792 if (fEnabled)
1793 {
1794 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
1795 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1796 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1797 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1798 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
1799 Assert(!afPciDeviceNo[6]);
1800 afPciDeviceNo[6] = true;
1801 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1802
1803 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1804 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1805 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1806
1807 /*
1808 * Attach the status driver.
1809 */
1810 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1811 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1812 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1813 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
1814 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1815 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1816
1817#ifdef VBOX_WITH_EHCI
1818 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
1819 if (fEnabled)
1820 {
1821 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
1822 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1823 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1824 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1825 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
1826 Assert(!afPciDeviceNo[11]);
1827 afPciDeviceNo[11] = true;
1828 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1829
1830 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1831 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1832 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1833
1834 /*
1835 * Attach the status driver.
1836 */
1837 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1838 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1839 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1840 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
1841 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1842 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1843 }
1844 else
1845#endif
1846 {
1847 /*
1848 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
1849 * on a per device level now.
1850 */
1851 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
1852 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
1853 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
1854 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
1855 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
1856 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
1857 // that it's documented somewhere.) Users needing it can use:
1858 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
1859 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
1860 }
1861 }
1862 }
1863
1864 /*
1865 * Clipboard
1866 */
1867 {
1868 ClipboardMode_T mode = ClipboardMode_Disabled;
1869 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
1870
1871 if (mode != ClipboardMode_Disabled)
1872 {
1873 /* Load the service */
1874 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
1875
1876 if (RT_FAILURE (rc))
1877 {
1878 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
1879 /* That is not a fatal failure. */
1880 rc = VINF_SUCCESS;
1881 }
1882 else
1883 {
1884 /* Setup the service. */
1885 VBOXHGCMSVCPARM parm;
1886
1887 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
1888
1889 switch (mode)
1890 {
1891 default:
1892 case ClipboardMode_Disabled:
1893 {
1894 LogRel(("VBoxSharedClipboard mode: Off\n"));
1895 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
1896 break;
1897 }
1898 case ClipboardMode_GuestToHost:
1899 {
1900 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
1901 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
1902 break;
1903 }
1904 case ClipboardMode_HostToGuest:
1905 {
1906 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
1907 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
1908 break;
1909 }
1910 case ClipboardMode_Bidirectional:
1911 {
1912 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
1913 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
1914 break;
1915 }
1916 }
1917
1918 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
1919
1920 Log(("Set VBoxSharedClipboard mode\n"));
1921 }
1922 }
1923 }
1924
1925#ifdef VBOX_WITH_CROGL
1926 /*
1927 * crOpenGL
1928 */
1929 {
1930 BOOL fEnabled = false;
1931 hrc = pMachine->COMGETTER(Accelerate3DEnabled) (&fEnabled); H();
1932
1933 if (fEnabled)
1934 {
1935 /* Load the service */
1936 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
1937 if (RT_FAILURE(rc))
1938 {
1939 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
1940 /* That is not a fatal failure. */
1941 rc = VINF_SUCCESS;
1942 }
1943 else
1944 {
1945 LogRel(("Shared crOpenGL service loaded.\n"));
1946
1947 /* Setup the service. */
1948 VBOXHGCMSVCPARM parm;
1949 parm.type = VBOX_HGCM_SVC_PARM_PTR;
1950
1951 //parm.u.pointer.addr = static_cast <IConsole *> (pData->pVMMDev->getParent());
1952 parm.u.pointer.addr = pConsole->mVMMDev->getParent()->getDisplay()->getFramebuffer();
1953 parm.u.pointer.size = sizeof(IFramebuffer *);
1954
1955 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_FRAMEBUFFER, 1, &parm);
1956 if (!RT_SUCCESS(rc))
1957 AssertMsgFailed(("SHCRGL_HOST_FN_SET_FRAMEBUFFER failed with %Rrc\n", rc));
1958 }
1959 }
1960 }
1961#endif
1962
1963#ifdef VBOX_WITH_GUEST_PROPS
1964 /*
1965 * Guest property service
1966 */
1967 {
1968 /* Load the service */
1969 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
1970
1971 if (RT_FAILURE (rc))
1972 {
1973 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
1974 /* That is not a fatal failure. */
1975 rc = VINF_SUCCESS;
1976 }
1977 else
1978 {
1979 /* Pull over the properties from the server. */
1980 SafeArray <BSTR> namesOut;
1981 SafeArray <BSTR> valuesOut;
1982 SafeArray <ULONG64> timestampsOut;
1983 SafeArray <BSTR> flagsOut;
1984 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
1985 ComSafeArrayAsOutParam(valuesOut),
1986 ComSafeArrayAsOutParam(timestampsOut),
1987 ComSafeArrayAsOutParam(flagsOut)); H();
1988 size_t cProps = namesOut.size();
1989 if ( valuesOut.size() != cProps
1990 || timestampsOut.size() != cProps
1991 || flagsOut.size() != cProps
1992 )
1993 rc = VERR_INVALID_PARAMETER;
1994
1995 std::vector <Utf8Str> utf8Names, utf8Values, utf8Flags;
1996 std::vector <char *> names, values, flags;
1997 std::vector <ULONG64> timestamps;
1998 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
1999 if ( !VALID_PTR(namesOut[i])
2000 || !VALID_PTR(valuesOut[i])
2001 || !VALID_PTR(flagsOut[i])
2002 )
2003 rc = VERR_INVALID_POINTER;
2004 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2005 {
2006 utf8Names.push_back(Bstr(namesOut[i]));
2007 utf8Values.push_back(Bstr(valuesOut[i]));
2008 timestamps.push_back(timestampsOut[i]);
2009 utf8Flags.push_back(Bstr(flagsOut[i]));
2010 if ( utf8Names.back().isNull()
2011 || utf8Values.back().isNull()
2012 || utf8Flags.back().isNull()
2013 )
2014 throw std::bad_alloc();
2015 }
2016 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2017 {
2018 names.push_back(utf8Names[i].mutableRaw());
2019 values.push_back(utf8Values[i].mutableRaw());
2020 flags.push_back(utf8Flags[i].mutableRaw());
2021 }
2022 names.push_back(NULL);
2023 values.push_back(NULL);
2024 timestamps.push_back(0);
2025 flags.push_back(NULL);
2026
2027 /* Setup the service. */
2028 VBOXHGCMSVCPARM parms[4];
2029
2030 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
2031 parms[0].u.pointer.addr = &names.front();
2032 parms[0].u.pointer.size = 0; /* We don't actually care. */
2033 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
2034 parms[1].u.pointer.addr = &values.front();
2035 parms[1].u.pointer.size = 0; /* We don't actually care. */
2036 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
2037 parms[2].u.pointer.addr = &timestamps.front();
2038 parms[2].u.pointer.size = 0; /* We don't actually care. */
2039 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
2040 parms[3].u.pointer.addr = &flags.front();
2041 parms[3].u.pointer.size = 0; /* We don't actually care. */
2042
2043 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4, &parms[0]);
2044
2045 /* Register the host notification callback */
2046 HGCMSVCEXTHANDLE hDummy;
2047 HGCMHostRegisterServiceExtension (&hDummy, "VBoxGuestPropSvc",
2048 Console::doGuestPropNotification,
2049 pvConsole);
2050
2051 Log(("Set VBoxGuestPropSvc property store\n"));
2052 }
2053 }
2054#endif /* VBOX_WITH_GUEST_PROPS defined */
2055
2056 /*
2057 * CFGM overlay handling.
2058 *
2059 * Here we check the extra data entries for CFGM values
2060 * and create the nodes and insert the values on the fly. Existing
2061 * values will be removed and reinserted. CFGM is typed, so by default
2062 * we will guess whether it's a string or an integer (byte arrays are
2063 * not currently supported). It's possible to override this autodetection
2064 * by adding "string:", "integer:" or "bytes:" (future).
2065 *
2066 * We first perform a run on global extra data, then on the machine
2067 * extra data to support global settings with local overrides.
2068 *
2069 */
2070 /** @todo add support for removing nodes and byte blobs. */
2071 Bstr strExtraDataKey;
2072 bool fGlobalExtraData = true;
2073 for (;;)
2074 {
2075 /*
2076 * Get the next key
2077 */
2078 Bstr strNextExtraDataKey;
2079 Bstr strExtraDataValue;
2080 if (fGlobalExtraData)
2081 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2082 strExtraDataValue.asOutParam());
2083 else
2084 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2085 strExtraDataValue.asOutParam());
2086
2087 /* stop if for some reason there's nothing more to request */
2088 if (FAILED(hrc) || !strNextExtraDataKey)
2089 {
2090 /* if we're out of global keys, continue with machine, otherwise we're done */
2091 if (fGlobalExtraData)
2092 {
2093 fGlobalExtraData = false;
2094 strExtraDataKey.setNull();
2095 continue;
2096 }
2097 break;
2098 }
2099 strExtraDataKey = strNextExtraDataKey;
2100
2101 /*
2102 * We only care about keys starting with "VBoxInternal/"
2103 */
2104 Utf8Str strExtraDataKeyUtf8(strExtraDataKey);
2105 char *pszExtraDataKey = (char *)strExtraDataKeyUtf8.raw();
2106 if (strncmp(pszExtraDataKey, "VBoxInternal/", sizeof("VBoxInternal/") - 1) != 0)
2107 continue;
2108 pszExtraDataKey += sizeof("VBoxInternal/") - 1;
2109
2110 /*
2111 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2112 * Split the two and get the node, delete the value and create the node
2113 * if necessary.
2114 */
2115 PCFGMNODE pNode;
2116 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2117 if (pszCFGMValueName)
2118 {
2119 /* terminate the node and advance to the value (Utf8Str might not
2120 offically like this but wtf) */
2121 *pszCFGMValueName = '\0';
2122 pszCFGMValueName++;
2123
2124 /* does the node already exist? */
2125 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2126 if (pNode)
2127 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2128 else
2129 {
2130 /* create the node */
2131 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2132 if (RT_FAILURE(rc))
2133 {
2134 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2135 continue;
2136 }
2137 Assert(pNode);
2138 }
2139 }
2140 else
2141 {
2142 /* root value (no node path). */
2143 pNode = pRoot;
2144 pszCFGMValueName = pszExtraDataKey;
2145 pszExtraDataKey--;
2146 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2147 }
2148
2149 /*
2150 * Now let's have a look at the value.
2151 * Empty strings means that we should remove the value, which we've
2152 * already done above.
2153 */
2154 Utf8Str strCFGMValueUtf8(strExtraDataValue);
2155 const char *pszCFGMValue = strCFGMValueUtf8.raw();
2156 if ( pszCFGMValue
2157 && *pszCFGMValue)
2158 {
2159 uint64_t u64Value;
2160
2161 /* check for type prefix first. */
2162 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
2163 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
2164 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
2165 {
2166 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
2167 if (RT_SUCCESS(rc))
2168 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2169 }
2170 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
2171 rc = VERR_NOT_IMPLEMENTED;
2172 /* auto detect type. */
2173 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
2174 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2175 else
2176 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
2177 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
2178 }
2179 }
2180
2181#undef H
2182#undef RC_CHECK
2183#undef STR_FREE
2184#undef STR_CONV
2185
2186 /* Register VM state change handler */
2187 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2188 AssertRC (rc2);
2189 if (RT_SUCCESS (rc))
2190 rc = rc2;
2191
2192 /* Register VM runtime error handler */
2193 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2194 AssertRC (rc2);
2195 if (RT_SUCCESS (rc))
2196 rc = rc2;
2197
2198 /* Save the VM pointer in the machine object */
2199 pConsole->mpVM = pVM;
2200
2201 LogFlowFunc (("vrc = %Rrc\n", rc));
2202 LogFlowFuncLeave();
2203
2204 return rc;
2205}
2206/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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