VirtualBox

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

Last change on this file since 19169 was 19124, checked in by vboxsync, 16 years ago

ConsoleImpl2.cpp: anything goes for VBoxInternal2/UseEFI.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 124.3 KB
Line 
1/* $Id: ConsoleImpl2.cpp 19124 2009-04-22 21:57:04Z 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#if 0 /* enable to play with lots of memory. */
43# include <iprt/env.h>
44# include <iprt/string.h>
45#endif
46
47#include <VBox/vmapi.h>
48#include <VBox/err.h>
49#include <VBox/version.h>
50#include <VBox/HostServices/VBoxClipboardSvc.h>
51#ifdef VBOX_WITH_CROGL
52#include <VBox/HostServices/VBoxCrOpenGLSvc.h>
53#endif
54#ifdef VBOX_WITH_GUEST_PROPS
55# include <VBox/HostServices/GuestPropertySvc.h>
56# include <VBox/com/defs.h>
57# include <VBox/com/array.h>
58# include <hgcm/HGCM.h> /** @todo it should be possible to register a service
59 * extension using a VMMDev callback. */
60# include <vector>
61#endif /* VBOX_WITH_GUEST_PROPS */
62#include <VBox/intnet.h>
63
64#include <VBox/com/string.h>
65#include <VBox/com/array.h>
66
67#if defined(RT_OS_SOLARIS) && defined(VBOX_WITH_NETFLT)
68# include <zone.h>
69#endif
70
71#if defined(RT_OS_LINUX) && defined(VBOX_WITH_NETFLT)
72# include <unistd.h>
73# include <sys/ioctl.h>
74# include <sys/socket.h>
75# include <linux/types.h>
76# include <linux/if.h>
77# include <linux/wireless.h>
78#endif
79
80#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
81# include <VBox/WinNetConfig.h>
82# include <Ntddndis.h>
83# include <devguid.h>
84#endif
85
86#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
87# include <HostNetworkInterfaceImpl.h>
88# include <netif.h>
89#endif
90
91#include "DHCPServerRunner.h"
92
93#include <VBox/param.h>
94
95/* Comment out the following line to remove VMWare compatibility hack. */
96#define VMWARE_NET_IN_SLOT_11
97
98/**
99 * Translate IDE StorageControllerType_T to string representation.
100 */
101const char* controllerString(StorageControllerType_T enmType)
102{
103 switch (enmType)
104 {
105 case StorageControllerType_PIIX3:
106 return "PIIX3";
107 case StorageControllerType_PIIX4:
108 return "PIIX4";
109 case StorageControllerType_ICH6:
110 return "ICH6";
111 default:
112 return "Unknown";
113 }
114}
115
116/*
117 * VC++ 8 / amd64 has some serious trouble with this function.
118 * As a temporary measure, we'll drop global optimizations.
119 */
120#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
121# pragma optimize("g", off)
122#endif
123
124/**
125 * Construct the VM configuration tree (CFGM).
126 *
127 * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
128 * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
129 * is done here.
130 *
131 * @param pVM VM handle.
132 * @param pvConsole Pointer to the VMPowerUpTask object.
133 * @return VBox status code.
134 *
135 * @note Locks the Console object for writing.
136 */
137DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
138{
139 LogFlowFuncEnter();
140 /* Note: hardcoded assumption about number of slots; see rom bios */
141 bool afPciDeviceNo[32] = {false};
142
143#if !defined (VBOX_WITH_XPCOM)
144 {
145 /* initialize COM */
146 HRESULT hrc = CoInitializeEx(NULL,
147 COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
148 COINIT_SPEED_OVER_MEMORY);
149 LogFlow (("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
150 AssertComRCReturn (hrc, VERR_GENERAL_FAILURE);
151 }
152#endif
153
154 AssertReturn (pvConsole, VERR_GENERAL_FAILURE);
155 ComObjPtr <Console> pConsole = static_cast <Console *> (pvConsole);
156
157 AutoCaller autoCaller (pConsole);
158 AssertComRCReturn (autoCaller.rc(), VERR_ACCESS_DENIED);
159
160 /* lock the console because we widely use internal fields and methods */
161 AutoWriteLock alock (pConsole);
162
163 ComPtr <IMachine> pMachine = pConsole->machine();
164
165 int rc;
166 HRESULT hrc;
167 char *psz = NULL;
168 BSTR str = NULL;
169
170 Bstr bstr; /* use this bstr when calling COM methods instead
171 of str as it manages memory! */
172
173#define STR_CONV() do { rc = RTUtf16ToUtf8(str, &psz); RC_CHECK(); } while (0)
174#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } if (psz) { RTStrFree(psz); psz = NULL; } } while (0)
175#define RC_CHECK() do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc)); STR_FREE(); return rc; } } while (0)
176#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
177
178 /*
179 * Get necessary objects and frequently used parameters.
180 */
181 ComPtr<IVirtualBox> virtualBox;
182 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
183
184 ComPtr<IHost> host;
185 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
186
187 ComPtr <ISystemProperties> systemProperties;
188 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
189
190 ComPtr<IBIOSSettings> biosSettings;
191 hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
192
193 Guid uuid;
194 hrc = pMachine->COMGETTER(Id)(uuid.asOutParam()); H();
195 PCRTUUID pUuid = uuid.raw();
196
197 ULONG cRamMBs;
198 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
199#if 0 /* enable to play with lots of memory. */
200 if (RTEnvExist("VBOX_RAM_SIZE"))
201 cRamMBs = RTStrToUInt64(RTEnvGet("VBOX_RAM_SIZE"));
202#endif
203 uint64_t const cbRam = cRamMBs * (uint64_t)_1M;
204 uint32_t const cbRamHole = MM_RAM_HOLE_SIZE_DEFAULT;
205
206 ULONG cCpus = 1;
207#ifdef VBOX_WITH_SMP_GUESTS
208 hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
209#endif
210
211 /*
212 * Get root node first.
213 * This is the only node in the tree.
214 */
215 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
216 Assert(pRoot);
217
218 /*
219 * Set the root (and VMM) level values.
220 */
221 hrc = pMachine->COMGETTER(Name)(&str); H();
222 STR_CONV();
223 rc = CFGMR3InsertString(pRoot, "Name", psz); RC_CHECK();
224 STR_FREE();
225 rc = CFGMR3InsertBytes(pRoot, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
226 rc = CFGMR3InsertInteger(pRoot, "RamSize", cbRam); RC_CHECK();
227 rc = CFGMR3InsertInteger(pRoot, "RamHoleSize", cbRamHole); RC_CHECK();
228 rc = CFGMR3InsertInteger(pRoot, "NumCPUs", cCpus); RC_CHECK();
229 rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10); RC_CHECK();
230 rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1); /* boolean */ RC_CHECK();
231 rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1); /* boolean */ RC_CHECK();
232 /** @todo Config: RawR0, PATMEnabled and CASMEnabled needs attention later. */
233 rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1); /* boolean */ RC_CHECK();
234 rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1); /* boolean */ RC_CHECK();
235
236 /* hardware virtualization extensions */
237 TSBool_T hwVirtExEnabled;
238 BOOL fHWVirtExEnabled;
239 hrc = pMachine->COMGETTER(HWVirtExEnabled)(&hwVirtExEnabled); H();
240 if (hwVirtExEnabled == TSBool_Default)
241 {
242 /* check the default value */
243 hrc = systemProperties->COMGETTER(HWVirtExEnabled)(&fHWVirtExEnabled); H();
244 }
245 else
246 fHWVirtExEnabled = (hwVirtExEnabled == TSBool_True);
247#ifdef RT_OS_DARWIN
248 rc = CFGMR3InsertInteger(pRoot, "HwVirtExtForced", fHWVirtExEnabled); RC_CHECK();
249#else
250 /* With more than 4GB PGM will use different RAMRANGE sizes for raw mode and hv mode to optimize lookup times. */
251 rc = CFGMR3InsertInteger(pRoot, "HwVirtExtForced", fHWVirtExEnabled && cbRam > (_4G - cbRamHole)); RC_CHECK();
252#endif
253
254 PCFGMNODE pHWVirtExt;
255 rc = CFGMR3InsertNode(pRoot, "HWVirtExt", &pHWVirtExt); RC_CHECK();
256 if (fHWVirtExEnabled)
257 {
258 rc = CFGMR3InsertInteger(pHWVirtExt, "Enabled", 1); RC_CHECK();
259
260 /* Indicate whether 64-bit guests are supported or not. */
261 /** @todo This is currently only forced off on 32-bit hosts only because it
262 * makes a lof of difference there (REM and Solaris performance).
263 */
264
265 Bstr osTypeId;
266 hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
267
268 ComPtr <IGuestOSType> guestOSType;
269 hrc = virtualBox->GetGuestOSType(osTypeId, guestOSType.asOutParam()); H();
270
271 BOOL fSupportsLongMode = false;
272 hrc = host->GetProcessorFeature(ProcessorFeature_LongMode,
273 &fSupportsLongMode); H();
274 BOOL fIs64BitGuest = false;
275 hrc = guestOSType->COMGETTER(Is64Bit)(&fIs64BitGuest); H();
276
277 if (fSupportsLongMode && fIs64BitGuest)
278 {
279 rc = CFGMR3InsertInteger(pHWVirtExt, "64bitEnabled", 1); RC_CHECK();
280#if ARCH_BITS == 32 /* The recompiler must use load VBoxREM64 (32-bit host only). */
281 PCFGMNODE pREM;
282 rc = CFGMR3InsertNode(pRoot, "REM", &pREM); RC_CHECK();
283 rc = CFGMR3InsertInteger(pREM, "64bitEnabled", 1); RC_CHECK();
284#endif
285 }
286#if ARCH_BITS == 32 /* 32-bit guests only. */
287 else
288 {
289 rc = CFGMR3InsertInteger(pHWVirtExt, "64bitEnabled", 0); RC_CHECK();
290 }
291#endif
292 }
293
294 /* Nested paging (VT-x/AMD-V) */
295 BOOL fEnableNestedPaging = false;
296 hrc = pMachine->COMGETTER(HWVirtExNestedPagingEnabled)(&fEnableNestedPaging); H();
297 rc = CFGMR3InsertInteger(pRoot, "EnableNestedPaging", fEnableNestedPaging); RC_CHECK();
298
299 /* VPID (VT-x) */
300 BOOL fEnableVPID = false;
301 hrc = pMachine->COMGETTER(HWVirtExVPIDEnabled)(&fEnableVPID); H();
302 rc = CFGMR3InsertInteger(pRoot, "EnableVPID", fEnableVPID); RC_CHECK();
303
304 /* Physical Address Extension (PAE) */
305 BOOL fEnablePAE = false;
306 hrc = pMachine->COMGETTER(PAEEnabled)(&fEnablePAE); H();
307 rc = CFGMR3InsertInteger(pRoot, "EnablePAE", fEnablePAE); RC_CHECK();
308
309 BOOL fIOAPIC;
310 hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
311
312 BOOL fPXEDebug;
313 hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
314
315 /*
316 * PDM config.
317 * Load drivers in VBoxC.[so|dll]
318 */
319 PCFGMNODE pPDM;
320 PCFGMNODE pDrivers;
321 PCFGMNODE pMod;
322 rc = CFGMR3InsertNode(pRoot, "PDM", &pPDM); RC_CHECK();
323 rc = CFGMR3InsertNode(pPDM, "Drivers", &pDrivers); RC_CHECK();
324 rc = CFGMR3InsertNode(pDrivers, "VBoxC", &pMod); RC_CHECK();
325#ifdef VBOX_WITH_XPCOM
326 // VBoxC is located in the components subdirectory
327 char szPathVBoxC[RTPATH_MAX];
328 rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
329 strcat(szPathVBoxC, "/components/VBoxC");
330 rc = CFGMR3InsertString(pMod, "Path", szPathVBoxC); RC_CHECK();
331#else
332 rc = CFGMR3InsertString(pMod, "Path", "VBoxC"); RC_CHECK();
333#endif
334
335 /*
336 * Devices
337 */
338 PCFGMNODE pDevices = NULL; /* /Devices */
339 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
340 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
341 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
342 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
343 PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
344 PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
345 PCFGMNODE pIdeInst = NULL; /* /Devices/piix3ide/0/ */
346 PCFGMNODE pSataInst = NULL; /* /Devices/ahci/0/ */
347 PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
348
349 rc = CFGMR3InsertNode(pRoot, "Devices", &pDevices); RC_CHECK();
350
351 /*
352 * PC Arch.
353 */
354 rc = CFGMR3InsertNode(pDevices, "pcarch", &pDev); RC_CHECK();
355 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
356 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
357 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
358
359 /*
360 * Firmware.
361 */
362#ifdef VBOX_WITH_EFI
363 /** @todo: implement appropriate getter */
364 Bstr tmpStr1;
365 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/UseEFI"), tmpStr1.asOutParam()); H();
366 BOOL fEfiEnabled = !tmpStr1.isEmpty();
367#else
368 BOOL fEfiEnabled = false;
369#endif
370 if (!fEfiEnabled)
371 {
372 /*
373 * PC Bios.
374 */
375 rc = CFGMR3InsertNode(pDevices, "pcbios", &pDev); RC_CHECK();
376 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
377 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
378 rc = CFGMR3InsertNode(pInst, "Config", &pBiosCfg); RC_CHECK();
379 rc = CFGMR3InsertInteger(pBiosCfg, "RamSize", cbRam); RC_CHECK();
380 rc = CFGMR3InsertInteger(pBiosCfg, "RamHoleSize", cbRamHole); RC_CHECK();
381 rc = CFGMR3InsertInteger(pBiosCfg, "NumCPUs", cCpus); RC_CHECK();
382 rc = CFGMR3InsertString(pBiosCfg, "HardDiskDevice", "piix3ide"); RC_CHECK();
383 rc = CFGMR3InsertString(pBiosCfg, "FloppyDevice", "i82078"); RC_CHECK();
384 rc = CFGMR3InsertInteger(pBiosCfg, "IOAPIC", fIOAPIC); RC_CHECK();
385 rc = CFGMR3InsertInteger(pBiosCfg, "PXEDebug", fPXEDebug); RC_CHECK();
386 rc = CFGMR3InsertBytes(pBiosCfg, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
387
388 DeviceType_T bootDevice;
389 if (SchemaDefs::MaxBootPosition > 9)
390 {
391 AssertMsgFailed (("Too many boot devices %d\n",
392 SchemaDefs::MaxBootPosition));
393 return VERR_INVALID_PARAMETER;
394 }
395
396 for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; pos ++)
397 {
398 hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
399
400 char szParamName[] = "BootDeviceX";
401 szParamName[sizeof (szParamName) - 2] = ((char (pos - 1)) + '0');
402
403 const char *pszBootDevice;
404 switch (bootDevice)
405 {
406 case DeviceType_Null:
407 pszBootDevice = "NONE";
408 break;
409 case DeviceType_HardDisk:
410 pszBootDevice = "IDE";
411 break;
412 case DeviceType_DVD:
413 pszBootDevice = "DVD";
414 break;
415 case DeviceType_Floppy:
416 pszBootDevice = "FLOPPY";
417 break;
418 case DeviceType_Network:
419 pszBootDevice = "LAN";
420 break;
421 default:
422 AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
423 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
424 N_("Invalid boot device '%d'"), bootDevice);
425 }
426 rc = CFGMR3InsertString(pBiosCfg, szParamName, pszBootDevice); RC_CHECK();
427 }
428 }
429 else
430 {
431 /*
432 * EFI.
433 */
434 rc = CFGMR3InsertNode(pDevices, "efi", &pDev); RC_CHECK();
435 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
436 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
437 }
438
439 /*
440 * The time offset
441 */
442 LONG64 timeOffset;
443 hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
444 PCFGMNODE pTMNode;
445 rc = CFGMR3InsertNode(pRoot, "TM", &pTMNode); RC_CHECK();
446 rc = CFGMR3InsertInteger(pTMNode, "UTCOffset", timeOffset * 1000000); RC_CHECK();
447
448 /*
449 * DMA
450 */
451 rc = CFGMR3InsertNode(pDevices, "8237A", &pDev); RC_CHECK();
452 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
453 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
454
455 /*
456 * PCI buses.
457 */
458 rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */ RC_CHECK();
459 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
460 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
461 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
462 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
463
464#if 0 /* enable this to test PCI bridging */
465 rc = CFGMR3InsertNode(pDevices, "pcibridge", &pDev); RC_CHECK();
466 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
467 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
468 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
469 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 14); RC_CHECK();
470 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
471 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 0);/* -> pci[0] */ RC_CHECK();
472
473 rc = CFGMR3InsertNode(pDev, "1", &pInst); RC_CHECK();
474 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
475 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
476 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 1); RC_CHECK();
477 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
478 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
479
480 rc = CFGMR3InsertNode(pDev, "2", &pInst); RC_CHECK();
481 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
482 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
483 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 3); RC_CHECK();
484 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
485 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
486#endif
487
488 /*
489 * Temporary hack for enabling the next three devices and various ACPI features.
490 */
491 Bstr tmpStr2;
492 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/SupportExtHwProfile"), tmpStr2.asOutParam()); H();
493 BOOL fExtProfile = tmpStr2 == Bstr("on");
494
495 /*
496 * High Precision Event Timer (HPET)
497 */
498 BOOL fHpetEnabled;
499#ifdef VBOX_WITH_HPET
500 fHpetEnabled = fExtProfile;
501#else
502 fHpetEnabled = false;
503#endif
504 if (fHpetEnabled)
505 {
506 rc = CFGMR3InsertNode(pDevices, "hpet", &pDev); RC_CHECK();
507 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
508 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
509 }
510
511 /*
512 * System Management Controller (SMC)
513 */
514 BOOL fSmcEnabled;
515#ifdef VBOX_WITH_SMC
516 fSmcEnabled = fExtProfile;
517#else
518 fSmcEnabled = false;
519#endif
520 if (fSmcEnabled)
521 {
522 rc = CFGMR3InsertNode(pDevices, "smc", &pDev); RC_CHECK();
523 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
524 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
525 }
526
527 /*
528 * Low Pin Count (LPC) bus
529 */
530 BOOL fLpcEnabled;
531 /** @todo: implement appropriate getter */
532#ifdef VBOX_WITH_LPC
533 fLpcEnabled = fExtProfile;
534#else
535 fLpcEnabled = false;
536#endif
537 if (fLpcEnabled)
538 {
539 rc = CFGMR3InsertNode(pDevices, "lpc", &pDev); RC_CHECK();
540 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
541 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
542 }
543
544 /*
545 * PS/2 keyboard & mouse.
546 */
547 rc = CFGMR3InsertNode(pDevices, "pckbd", &pDev); RC_CHECK();
548 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
549 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
550 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
551
552 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
553 rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); RC_CHECK();
554 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
555 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); RC_CHECK();
556
557 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
558 rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard"); RC_CHECK();
559 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
560 Keyboard *pKeyboard = pConsole->mKeyboard;
561 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pKeyboard); RC_CHECK();
562
563 rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL0); RC_CHECK();
564 rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); RC_CHECK();
565 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
566 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); RC_CHECK();
567
568 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
569 rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse"); RC_CHECK();
570 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
571 Mouse *pMouse = pConsole->mMouse;
572 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse); RC_CHECK();
573
574 /*
575 * i82078 Floppy drive controller
576 */
577 ComPtr<IFloppyDrive> floppyDrive;
578 hrc = pMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam()); H();
579 BOOL fFdcEnabled;
580 hrc = floppyDrive->COMGETTER(Enabled)(&fFdcEnabled); H();
581 if (fFdcEnabled)
582 {
583 rc = CFGMR3InsertNode(pDevices, "i82078", &pDev); RC_CHECK();
584 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
585 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); RC_CHECK();
586 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
587 rc = CFGMR3InsertInteger(pCfg, "IRQ", 6); RC_CHECK();
588 rc = CFGMR3InsertInteger(pCfg, "DMA", 2); RC_CHECK();
589 rc = CFGMR3InsertInteger(pCfg, "MemMapped", 0 ); RC_CHECK();
590 rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x3f0); RC_CHECK();
591
592 /* Attach the status driver */
593 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
594 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
595 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
596 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapFDLeds[0]); RC_CHECK();
597 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
598 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
599
600 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
601
602 ComPtr<IFloppyImage> floppyImage;
603 hrc = floppyDrive->GetImage(floppyImage.asOutParam()); H();
604 if (floppyImage)
605 {
606 pConsole->meFloppyState = DriveState_ImageMounted;
607 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
608 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
609 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
610 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
611
612 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
613 rc = CFGMR3InsertString(pLunL1, "Driver", "RawImage"); RC_CHECK();
614 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
615 hrc = floppyImage->COMGETTER(Location)(&str); H();
616 STR_CONV();
617 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
618 STR_FREE();
619 }
620 else
621 {
622 ComPtr<IHostFloppyDrive> hostFloppyDrive;
623 hrc = floppyDrive->GetHostDrive(hostFloppyDrive.asOutParam()); H();
624 if (hostFloppyDrive)
625 {
626 pConsole->meFloppyState = DriveState_HostDriveCaptured;
627 rc = CFGMR3InsertString(pLunL0, "Driver", "HostFloppy"); RC_CHECK();
628 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
629 hrc = hostFloppyDrive->COMGETTER(Name)(&str); H();
630 STR_CONV();
631 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
632 STR_FREE();
633 }
634 else
635 {
636 pConsole->meFloppyState = DriveState_NotMounted;
637 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
638 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
639 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
640 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
641 }
642 }
643 }
644
645 /*
646 * ACPI
647 */
648 BOOL fACPI;
649 hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
650 if (fACPI)
651 {
652 rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); RC_CHECK();
653 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
654 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
655 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
656 rc = CFGMR3InsertInteger(pCfg, "RamSize", cbRam); RC_CHECK();
657 rc = CFGMR3InsertInteger(pCfg, "RamHoleSize", cbRamHole); RC_CHECK();
658 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
659
660 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
661 rc = CFGMR3InsertInteger(pCfg, "FdcEnabled", fFdcEnabled); RC_CHECK();
662#ifdef VBOX_WITH_HPET
663 rc = CFGMR3InsertInteger(pCfg, "HpetEnabled", fHpetEnabled); RC_CHECK();
664#endif
665#ifdef VBOX_WITH_SMC
666 rc = CFGMR3InsertInteger(pCfg, "SmcEnabled", fSmcEnabled); RC_CHECK();
667#endif
668 rc = CFGMR3InsertInteger(pCfg, "ShowRtc", fExtProfile); RC_CHECK();
669 rc = CFGMR3InsertInteger(pCfg, "ShowCpu", fExtProfile); RC_CHECK();
670 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
671 Assert(!afPciDeviceNo[7]);
672 afPciDeviceNo[7] = true;
673 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
674
675 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
676 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
677 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
678 }
679
680 /*
681 * i8254 Programmable Interval Timer And Dummy Speaker
682 */
683 rc = CFGMR3InsertNode(pDevices, "i8254", &pDev); RC_CHECK();
684 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
685 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
686#ifdef DEBUG
687 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
688#endif
689
690 /*
691 * i8259 Programmable Interrupt Controller.
692 */
693 rc = CFGMR3InsertNode(pDevices, "i8259", &pDev); RC_CHECK();
694 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
695 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
696 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
697
698 /*
699 * Advanced Programmable Interrupt Controller.
700 * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
701 * thus only single insert
702 */
703 rc = CFGMR3InsertNode(pDevices, "apic", &pDev); RC_CHECK();
704 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
705 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
706 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
707 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
708 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
709
710 /* SMP: @todo: IOAPIC may be required for SMP configs */
711 if (fIOAPIC)
712 {
713 /*
714 * I/O Advanced Programmable Interrupt Controller.
715 */
716 rc = CFGMR3InsertNode(pDevices, "ioapic", &pDev); RC_CHECK();
717 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
718 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
719 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
720 }
721
722 /*
723 * RTC MC146818.
724 */
725 rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); RC_CHECK();
726 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
727 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
728
729 /*
730 * VGA.
731 */
732 rc = CFGMR3InsertNode(pDevices, "vga", &pDev); RC_CHECK();
733 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
734 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
735 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 2); RC_CHECK();
736 Assert(!afPciDeviceNo[2]);
737 afPciDeviceNo[2] = true;
738 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
739 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
740 ULONG cVRamMBs;
741 hrc = pMachine->COMGETTER(VRAMSize)(&cVRamMBs); H();
742 rc = CFGMR3InsertInteger(pCfg, "VRamSize", cVRamMBs * _1M); RC_CHECK();
743#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
744 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", fHWVirtExEnabled); RC_CHECK();
745#endif
746
747 /*
748 * BIOS logo
749 */
750 BOOL fFadeIn;
751 hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
752 rc = CFGMR3InsertInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0); RC_CHECK();
753 BOOL fFadeOut;
754 hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
755 rc = CFGMR3InsertInteger(pCfg, "FadeOut", fFadeOut ? 1: 0); RC_CHECK();
756 ULONG logoDisplayTime;
757 hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
758 rc = CFGMR3InsertInteger(pCfg, "LogoTime", logoDisplayTime); RC_CHECK();
759 Bstr logoImagePath;
760 hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
761 rc = CFGMR3InsertString(pCfg, "LogoFile", logoImagePath ? Utf8Str(logoImagePath) : ""); RC_CHECK();
762
763 /*
764 * Boot menu
765 */
766 BIOSBootMenuMode_T bootMenuMode;
767 int value;
768 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
769 switch (bootMenuMode)
770 {
771 case BIOSBootMenuMode_Disabled:
772 value = 0;
773 break;
774 case BIOSBootMenuMode_MenuOnly:
775 value = 1;
776 break;
777 default:
778 value = 2;
779 }
780 rc = CFGMR3InsertInteger(pCfg, "ShowBootMenu", value); RC_CHECK();
781
782 /* Custom VESA mode list */
783 unsigned cModes = 0;
784 for (unsigned iMode = 1; iMode <= 16; iMode++)
785 {
786 char szExtraDataKey[sizeof("CustomVideoModeXX")];
787 RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%d", iMode);
788 hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), &str); H();
789 if (!str || !*str)
790 break;
791 STR_CONV();
792 rc = CFGMR3InsertString(pCfg, szExtraDataKey, psz);
793 STR_FREE();
794 cModes++;
795 }
796 rc = CFGMR3InsertInteger(pCfg, "CustomVideoModes", cModes);
797
798 /* VESA height reduction */
799 ULONG ulHeightReduction;
800 IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
801 if (pFramebuffer)
802 {
803 hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
804 }
805 else
806 {
807 /* If framebuffer is not available, there is no height reduction. */
808 ulHeightReduction = 0;
809 }
810 rc = CFGMR3InsertInteger(pCfg, "HeightReduction", ulHeightReduction); RC_CHECK();
811
812 /* Attach the display. */
813 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
814 rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay"); RC_CHECK();
815 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
816 Display *pDisplay = pConsole->mDisplay;
817 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pDisplay); RC_CHECK();
818
819 /*
820 * Storage controllers.
821 */
822 com::SafeIfaceArray<IStorageController> ctrls;
823 hrc = pMachine->
824 COMGETTER(StorageControllers) (ComSafeArrayAsOutParam (ctrls)); H();
825
826 for (size_t i = 0; i < ctrls.size(); ++ i)
827 {
828 PCFGMNODE pCtlInst = NULL; /* /Devices/<name>/0/ */
829 StorageControllerType_T enmCtrlType;
830 StorageBus_T enmBus;
831 bool fSCSI = false;
832 BSTR controllerName;
833
834 rc = ctrls[i]->COMGETTER(ControllerType)(&enmCtrlType); H();
835 rc = ctrls[i]->COMGETTER(Bus)(&enmBus); H();
836 rc = ctrls[i]->COMGETTER(Name)(&controllerName); H();
837
838 switch(enmCtrlType)
839 {
840 case StorageControllerType_LsiLogic:
841 {
842 rc = CFGMR3InsertNode(pDevices, "lsilogicscsi", &pDev); RC_CHECK();
843 rc = CFGMR3InsertNode(pDev, "0", &pCtlInst); RC_CHECK();
844 rc = CFGMR3InsertInteger(pCtlInst, "Trusted", 1); RC_CHECK();
845 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 20); RC_CHECK();
846 Assert(!afPciDeviceNo[20]);
847 afPciDeviceNo[20] = true;
848 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
849 rc = CFGMR3InsertNode(pCtlInst, "Config", &pCfg); RC_CHECK();
850 fSCSI = true;
851
852 /* Attach the status driver */
853 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
854 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
855 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
856 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSCSILeds[0]); RC_CHECK();
857 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
858 rc = CFGMR3InsertInteger(pCfg, "Last", 15); RC_CHECK();
859 break;
860 }
861 case StorageControllerType_BusLogic:
862 {
863 rc = CFGMR3InsertNode(pDevices, "buslogic", &pDev); RC_CHECK();
864 rc = CFGMR3InsertNode(pDev, "0", &pCtlInst); RC_CHECK();
865 rc = CFGMR3InsertInteger(pCtlInst, "Trusted", 1); RC_CHECK();
866 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 21); RC_CHECK();
867 Assert(!afPciDeviceNo[21]);
868 afPciDeviceNo[21] = true;
869 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
870 rc = CFGMR3InsertNode(pCtlInst, "Config", &pCfg); RC_CHECK();
871 fSCSI = true;
872
873 /* Attach the status driver */
874 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
875 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
876 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
877 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSCSILeds[0]); RC_CHECK();
878 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
879 rc = CFGMR3InsertInteger(pCfg, "Last", 15); RC_CHECK();
880 break;
881 }
882 case StorageControllerType_IntelAhci:
883 {
884 rc = CFGMR3InsertNode(pDevices, "ahci", &pDev); RC_CHECK();
885 rc = CFGMR3InsertNode(pDev, "0", &pCtlInst); RC_CHECK();
886 rc = CFGMR3InsertInteger(pCtlInst, "Trusted", 1); RC_CHECK();
887 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 13); RC_CHECK();
888 Assert(!afPciDeviceNo[13]);
889 afPciDeviceNo[13] = true;
890 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
891 rc = CFGMR3InsertNode(pCtlInst, "Config", &pCfg); RC_CHECK();
892
893 ULONG cPorts = 0;
894 hrc = ctrls[i]->COMGETTER(PortCount)(&cPorts); H();
895 rc = CFGMR3InsertInteger(pCfg, "PortCount", cPorts); RC_CHECK();
896
897 /* Needed configuration values for the bios. */
898 if (pBiosCfg)
899 {
900 rc = CFGMR3InsertString(pBiosCfg, "SataHardDiskDevice", "ahci"); RC_CHECK();
901 }
902
903 for (uint32_t j = 0; j < 4; j++)
904 {
905 static const char *s_apszConfig[4] =
906 { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
907 static const char *s_apszBiosConfig[4] =
908 { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
909
910 LONG lPortNumber = -1;
911 hrc = ctrls[i]->GetIDEEmulationPort(j, &lPortNumber); H();
912 rc = CFGMR3InsertInteger(pCfg, s_apszConfig[j], lPortNumber); RC_CHECK();
913 if (pBiosCfg)
914 {
915 rc = CFGMR3InsertInteger(pBiosCfg, s_apszBiosConfig[j], lPortNumber); RC_CHECK();
916 }
917 }
918
919 /* Attach the status driver */
920 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
921 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
922 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
923 AssertRelease(cPorts <= RT_ELEMENTS(pConsole->mapSATALeds));
924 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSATALeds[0]); RC_CHECK();
925 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
926 rc = CFGMR3InsertInteger(pCfg, "Last", cPorts - 1); RC_CHECK();
927 break;
928 }
929 case StorageControllerType_PIIX3:
930 case StorageControllerType_PIIX4:
931 case StorageControllerType_ICH6:
932 {
933 /*
934 * IDE (update this when the main interface changes)
935 */
936 rc = CFGMR3InsertNode(pDevices, "piix3ide", &pDev); /* piix3 */ RC_CHECK();
937 rc = CFGMR3InsertNode(pDev, "0", &pCtlInst); RC_CHECK();
938 rc = CFGMR3InsertInteger(pCtlInst, "Trusted", 1); /* boolean */ RC_CHECK();
939 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 1); RC_CHECK();
940 Assert(!afPciDeviceNo[1]);
941 afPciDeviceNo[1] = true;
942 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 1); RC_CHECK();
943 rc = CFGMR3InsertNode(pCtlInst, "Config", &pCfg); RC_CHECK();
944 rc = CFGMR3InsertString(pCfg, "Type", controllerString(enmCtrlType)); RC_CHECK();
945
946 /* Attach the status driver */
947 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
948 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
949 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
950 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapIDELeds[0]);RC_CHECK();
951 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
952 rc = CFGMR3InsertInteger(pCfg, "Last", 3); RC_CHECK();
953
954 /*
955 * Attach the CD/DVD driver now
956 */
957 ComPtr<IDVDDrive> dvdDrive;
958 hrc = pMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam()); H();
959 if (dvdDrive)
960 {
961 // ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
962 rc = CFGMR3InsertNode(pCtlInst, "LUN#2", &pLunL0); RC_CHECK();
963 ComPtr<IHostDVDDrive> hostDvdDrive;
964 hrc = dvdDrive->GetHostDrive(hostDvdDrive.asOutParam()); H();
965 if (hostDvdDrive)
966 {
967 pConsole->meDVDState = DriveState_HostDriveCaptured;
968 rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
969 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
970 hrc = hostDvdDrive->COMGETTER(Name)(&str); H();
971 STR_CONV();
972 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
973 STR_FREE();
974 BOOL fPassthrough;
975 hrc = dvdDrive->COMGETTER(Passthrough)(&fPassthrough); H();
976 rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough); RC_CHECK();
977 }
978 else
979 {
980 pConsole->meDVDState = DriveState_NotMounted;
981 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
982 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
983 rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
984 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
985
986 ComPtr<IDVDImage> dvdImage;
987 hrc = dvdDrive->GetImage(dvdImage.asOutParam()); H();
988 if (dvdImage)
989 {
990 pConsole->meDVDState = DriveState_ImageMounted;
991 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
992 rc = CFGMR3InsertString(pLunL1, "Driver", "MediaISO"); RC_CHECK();
993 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
994 hrc = dvdImage->COMGETTER(Location)(&str); H();
995 STR_CONV();
996 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
997 STR_FREE();
998 }
999 }
1000 }
1001 break;
1002 }
1003 default:
1004 AssertMsgFailed (("invalid storage controller type: "
1005 "%d\n", enmCtrlType));
1006 return VERR_GENERAL_FAILURE;
1007 }
1008
1009 /* At the moment we only support one controller per type. So the instance id is always 0. */
1010 rc = ctrls[i]->COMSETTER(Instance)(0); H();
1011
1012 /* Attach the hard disks. */
1013 com::SafeIfaceArray<IHardDiskAttachment> atts;
1014 hrc = pMachine->
1015 GetHardDiskAttachmentsOfController (controllerName,
1016 ComSafeArrayAsOutParam (atts)); H();
1017
1018 for (size_t j = 0; j < atts.size(); ++ j)
1019 {
1020 ComPtr<IHardDisk> hardDisk;
1021 hrc = atts [j]->COMGETTER(HardDisk) (hardDisk.asOutParam()); H();
1022 LONG lDev;
1023 hrc = atts [j]->COMGETTER(Device) (&lDev); H();
1024 LONG lPort;
1025 hrc = atts [j]->COMGETTER(Port) (&lPort); H();
1026
1027 int iLUN = 0;
1028
1029 switch (enmBus)
1030 {
1031 case StorageBus_IDE:
1032 {
1033 if (lPort >= 2 || lPort < 0)
1034 {
1035 AssertMsgFailed (("invalid controller channel number: "
1036 "%d\n", lPort));
1037 return VERR_GENERAL_FAILURE;
1038 }
1039
1040 if (lDev >= 2 || lDev < 0)
1041 {
1042 AssertMsgFailed (("invalid controller device number: "
1043 "%d\n", lDev));
1044 return VERR_GENERAL_FAILURE;
1045 }
1046
1047 iLUN = 2 * lPort + lDev;
1048 break;
1049 }
1050 case StorageBus_SATA:
1051 case StorageBus_SCSI:
1052 {
1053 iLUN = lPort;
1054 break;
1055 }
1056 default:
1057 {
1058 AssertMsgFailed (("invalid storage bus type: "
1059 "%d\n", enmBus));
1060 return VERR_GENERAL_FAILURE;
1061 }
1062 }
1063
1064 char szLUN[16];
1065 RTStrPrintf (szLUN, sizeof(szLUN), "LUN#%d", iLUN);
1066
1067 rc = CFGMR3InsertNode (pCtlInst, szLUN, &pLunL0); RC_CHECK();
1068 /* SCSI has a another driver between device and block. */
1069 if (fSCSI)
1070 {
1071 rc = CFGMR3InsertString (pLunL0, "Driver", "SCSI"); RC_CHECK();
1072 rc = CFGMR3InsertNode (pLunL0, "Config", &pCfg); RC_CHECK();
1073
1074 rc = CFGMR3InsertNode (pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1075 }
1076 rc = CFGMR3InsertString (pLunL0, "Driver", "Block"); RC_CHECK();
1077 rc = CFGMR3InsertNode (pLunL0, "Config", &pCfg); RC_CHECK();
1078 rc = CFGMR3InsertString (pCfg, "Type", "HardDisk"); RC_CHECK();
1079 rc = CFGMR3InsertInteger (pCfg, "Mountable", 0); RC_CHECK();
1080
1081 rc = CFGMR3InsertNode (pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1082 rc = CFGMR3InsertString (pLunL1, "Driver", "VD"); RC_CHECK();
1083 rc = CFGMR3InsertNode (pLunL1, "Config", &pCfg); RC_CHECK();
1084
1085 hrc = hardDisk->COMGETTER(Location) (bstr.asOutParam()); H();
1086 rc = CFGMR3InsertString (pCfg, "Path", Utf8Str (bstr)); RC_CHECK();
1087
1088 hrc = hardDisk->COMGETTER(Format) (bstr.asOutParam()); H();
1089 rc = CFGMR3InsertString (pCfg, "Format", Utf8Str (bstr)); RC_CHECK();
1090
1091#if defined(VBOX_WITH_PDM_ASYNC_COMPLETION)
1092 if (bstr == L"VMDK")
1093 {
1094 /* Create cfgm nodes for async transport driver because VMDK is
1095 * currently the only one which may support async I/O. This has
1096 * to be made generic based on the capabiliy flags when the new
1097 * HardDisk interface is merged.
1098 */
1099 rc = CFGMR3InsertNode (pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
1100 rc = CFGMR3InsertString (pLunL2, "Driver", "TransportAsync"); RC_CHECK();
1101 /* The async transport driver has no config options yet. */
1102 }
1103#endif
1104 /* Pass all custom parameters. */
1105 bool fHostIP = true;
1106 SafeArray <BSTR> names;
1107 SafeArray <BSTR> values;
1108 hrc = hardDisk->GetProperties (NULL,
1109 ComSafeArrayAsOutParam (names),
1110 ComSafeArrayAsOutParam (values)); H();
1111
1112 if (names.size() != 0)
1113 {
1114 PCFGMNODE pVDC;
1115 rc = CFGMR3InsertNode (pCfg, "VDConfig", &pVDC); RC_CHECK();
1116 for (size_t ii = 0; ii < names.size(); ++ ii)
1117 {
1118 if (values [ii])
1119 {
1120 Utf8Str name = names [ii];
1121 Utf8Str value = values [ii];
1122 rc = CFGMR3InsertString (pVDC, name, value);
1123 if ( !(name.compare("HostIPStack"))
1124 && !(value.compare("0")))
1125 fHostIP = false;
1126 }
1127 }
1128 }
1129
1130 /* Create an inversed tree of parents. */
1131 ComPtr<IHardDisk> parentHardDisk = hardDisk;
1132 for (PCFGMNODE pParent = pCfg;;)
1133 {
1134 hrc = parentHardDisk->
1135 COMGETTER(Parent) (hardDisk.asOutParam()); H();
1136 if (hardDisk.isNull())
1137 break;
1138
1139 PCFGMNODE pCur;
1140 rc = CFGMR3InsertNode (pParent, "Parent", &pCur); RC_CHECK();
1141 hrc = hardDisk->COMGETTER(Location) (bstr.asOutParam()); H();
1142 rc = CFGMR3InsertString (pCur, "Path", Utf8Str (bstr)); RC_CHECK();
1143
1144 hrc = hardDisk->COMGETTER(Format) (bstr.asOutParam()); H();
1145 rc = CFGMR3InsertString (pCur, "Format", Utf8Str (bstr)); RC_CHECK();
1146
1147 /* Pass all custom parameters. */
1148 SafeArray <BSTR> names;
1149 SafeArray <BSTR> values;
1150 hrc = hardDisk->GetProperties (NULL,
1151 ComSafeArrayAsOutParam (names),
1152 ComSafeArrayAsOutParam (values));H();
1153
1154 if (names.size() != 0)
1155 {
1156 PCFGMNODE pVDC;
1157 rc = CFGMR3InsertNode (pCur, "VDConfig", &pVDC); RC_CHECK();
1158 for (size_t ii = 0; ii < names.size(); ++ ii)
1159 {
1160 if (values [ii])
1161 {
1162 Utf8Str name = names [ii];
1163 Utf8Str value = values [ii];
1164 rc = CFGMR3InsertString (pVDC, name, value);
1165 if ( !(name.compare("HostIPStack"))
1166 && !(value.compare("0")))
1167 fHostIP = false;
1168 }
1169 }
1170 }
1171
1172 /* Custom code: put marker to not use host IP stack to driver
1173 * configuration node. Simplifies life of DrvVD a bit. */
1174 if (!fHostIP)
1175 {
1176 rc = CFGMR3InsertInteger (pCfg, "HostIPStack", 0); RC_CHECK();
1177 }
1178
1179 /* next */
1180 pParent = pCur;
1181 parentHardDisk = hardDisk;
1182 }
1183 }
1184 H();
1185 }
1186 H();
1187
1188 /*
1189 * Network adapters
1190 */
1191#ifdef VMWARE_NET_IN_SLOT_11
1192 bool fSwapSlots3and11 = false;
1193#endif
1194 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
1195 rc = CFGMR3InsertNode(pDevices, "pcnet", &pDevPCNet); RC_CHECK();
1196#ifdef VBOX_WITH_E1000
1197 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
1198 rc = CFGMR3InsertNode(pDevices, "e1000", &pDevE1000); RC_CHECK();
1199#endif
1200 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ulInstance++)
1201 {
1202 ComPtr<INetworkAdapter> networkAdapter;
1203 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
1204 BOOL fEnabled = FALSE;
1205 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
1206 if (!fEnabled)
1207 continue;
1208
1209 /*
1210 * The virtual hardware type. Create appropriate device first.
1211 */
1212 NetworkAdapterType_T adapterType;
1213 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
1214 switch (adapterType)
1215 {
1216 case NetworkAdapterType_Am79C970A:
1217 case NetworkAdapterType_Am79C973:
1218 pDev = pDevPCNet;
1219 break;
1220#ifdef VBOX_WITH_E1000
1221 case NetworkAdapterType_I82540EM:
1222 case NetworkAdapterType_I82543GC:
1223 case NetworkAdapterType_I82545EM:
1224 pDev = pDevE1000;
1225 break;
1226#endif
1227 default:
1228 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
1229 adapterType, ulInstance));
1230 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1231 N_("Invalid network adapter type '%d' for slot '%d'"),
1232 adapterType, ulInstance);
1233 }
1234
1235 char szInstance[4]; Assert(ulInstance <= 999);
1236 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1237 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1238 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1239 /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
1240 * next 4 get 16..19. */
1241 unsigned iPciDeviceNo = 3;
1242 if (ulInstance)
1243 {
1244 if (ulInstance < 4)
1245 iPciDeviceNo = ulInstance - 1 + 8;
1246 else
1247 iPciDeviceNo = ulInstance - 4 + 16;
1248 }
1249#ifdef VMWARE_NET_IN_SLOT_11
1250 /*
1251 * Dirty hack for PCI slot compatibility with VMWare,
1252 * it assigns slot 11 to the first network controller.
1253 */
1254 if (iPciDeviceNo == 3 && adapterType == NetworkAdapterType_I82545EM)
1255 {
1256 iPciDeviceNo = 0x11;
1257 fSwapSlots3and11 = true;
1258 }
1259 else if (iPciDeviceNo == 0x11 && fSwapSlots3and11)
1260 iPciDeviceNo = 3;
1261#endif
1262 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
1263 Assert(!afPciDeviceNo[iPciDeviceNo]);
1264 afPciDeviceNo[iPciDeviceNo] = true;
1265 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1266 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1267#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
1268 if (pDev == pDevPCNet)
1269 {
1270 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", false); RC_CHECK();
1271 }
1272#endif
1273
1274 /*
1275 * The virtual hardware type. PCNet supports two types.
1276 */
1277 switch (adapterType)
1278 {
1279 case NetworkAdapterType_Am79C970A:
1280 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
1281 break;
1282 case NetworkAdapterType_Am79C973:
1283 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
1284 break;
1285 case NetworkAdapterType_I82540EM:
1286 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
1287 break;
1288 case NetworkAdapterType_I82543GC:
1289 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
1290 break;
1291 case NetworkAdapterType_I82545EM:
1292 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 2); RC_CHECK();
1293 break;
1294 }
1295
1296 /*
1297 * Get the MAC address and convert it to binary representation
1298 */
1299 Bstr macAddr;
1300 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1301 Assert(macAddr);
1302 Utf8Str macAddrUtf8 = macAddr;
1303 char *macStr = (char*)macAddrUtf8.raw();
1304 Assert(strlen(macStr) == 12);
1305 RTMAC Mac;
1306 memset(&Mac, 0, sizeof(Mac));
1307 char *pMac = (char*)&Mac;
1308 for (uint32_t i = 0; i < 6; i++)
1309 {
1310 char c1 = *macStr++ - '0';
1311 if (c1 > 9)
1312 c1 -= 7;
1313 char c2 = *macStr++ - '0';
1314 if (c2 > 9)
1315 c2 -= 7;
1316 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1317 }
1318 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1319
1320 /*
1321 * Check if the cable is supposed to be unplugged
1322 */
1323 BOOL fCableConnected;
1324 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1325 rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
1326
1327 /*
1328 * Line speed to report from custom drivers
1329 */
1330 ULONG ulLineSpeed;
1331 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1332 rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
1333
1334 /*
1335 * Attach the status driver.
1336 */
1337 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1338 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1339 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1340 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
1341
1342 /*
1343 * Enable the packet sniffer if requested.
1344 */
1345 BOOL fSniffer;
1346 hrc = networkAdapter->COMGETTER(TraceEnabled)(&fSniffer); H();
1347 if (fSniffer)
1348 {
1349 /* insert the sniffer filter driver. */
1350 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1351 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
1352 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1353 hrc = networkAdapter->COMGETTER(TraceFile)(&str); H();
1354 if (str) /* check convention for indicating default file. */
1355 {
1356 STR_CONV();
1357 rc = CFGMR3InsertString(pCfg, "File", psz); RC_CHECK();
1358 STR_FREE();
1359 }
1360 }
1361
1362
1363 NetworkAttachmentType_T networkAttachment;
1364 hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H();
1365 Bstr networkName, trunkName, trunkType;
1366 switch (networkAttachment)
1367 {
1368 case NetworkAttachmentType_Null:
1369 break;
1370
1371 case NetworkAttachmentType_NAT:
1372 {
1373 if (fSniffer)
1374 {
1375 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1376 }
1377 else
1378 {
1379 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1380 }
1381 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
1382 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1383 /* (Port forwarding goes here.) */
1384
1385 /* Configure TFTP prefix and boot filename. */
1386 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
1387 STR_CONV();
1388 if (psz && *psz)
1389 {
1390 char *pszTFTPPrefix = NULL;
1391 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
1392 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix); RC_CHECK();
1393 RTStrFree(pszTFTPPrefix);
1394 }
1395 STR_FREE();
1396 hrc = pMachine->COMGETTER(Name)(&str); H();
1397 STR_CONV();
1398 char *pszBootFile = NULL;
1399 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
1400 STR_FREE();
1401 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile); RC_CHECK();
1402 RTStrFree(pszBootFile);
1403
1404 hrc = networkAdapter->COMGETTER(NATNetwork)(&str); H();
1405 if (str)
1406 {
1407 STR_CONV();
1408 if (psz && *psz)
1409 {
1410 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1411 /* NAT uses its own DHCP implementation */
1412 //networkName = Bstr(psz);
1413 }
1414
1415 STR_FREE();
1416 }
1417 break;
1418 }
1419
1420 case NetworkAttachmentType_Bridged:
1421 {
1422 /*
1423 * Perform the attachment if required (don't return on error!)
1424 */
1425 hrc = pConsole->attachToBridgedInterface(networkAdapter);
1426 if (SUCCEEDED(hrc))
1427 {
1428#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
1429 Assert ((int)pConsole->maTapFD[ulInstance] >= 0);
1430 if ((int)pConsole->maTapFD[ulInstance] >= 0)
1431 {
1432 if (fSniffer)
1433 {
1434 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1435 }
1436 else
1437 {
1438 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1439 }
1440 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1441 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1442 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pConsole->maTapFD[ulInstance]); RC_CHECK();
1443 }
1444#elif defined(VBOX_WITH_NETFLT)
1445 /*
1446 * This is the new VBoxNetFlt+IntNet stuff.
1447 */
1448 if (fSniffer)
1449 {
1450 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1451 }
1452 else
1453 {
1454 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1455 }
1456
1457 Bstr HifName;
1458 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1459 if(FAILED(hrc))
1460 {
1461 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1462 H();
1463 }
1464
1465 Utf8Str HifNameUtf8(HifName);
1466 const char *pszHifName = HifNameUtf8.raw();
1467
1468# if defined(RT_OS_DARWIN)
1469 /* The name is on the form 'ifX: long name', chop it off at the colon. */
1470 char szTrunk[8];
1471 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
1472 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1473 if (!pszColon)
1474 {
1475 hrc = networkAdapter->Detach(); H();
1476 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1477 N_("Malformed host interface networking name '%ls'"),
1478 HifName.raw());
1479 }
1480 *pszColon = '\0';
1481 const char *pszTrunk = szTrunk;
1482
1483# elif defined(RT_OS_SOLARIS)
1484 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
1485 char szTrunk[256];
1486 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
1487 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
1488
1489 /*
1490 * Currently don't bother about malformed names here for the sake of people using
1491 * VBoxManage and setting only the NIC name from there. If there is a space we
1492 * chop it off and proceed, otherwise just use whatever we've got.
1493 */
1494 if (pszSpace)
1495 *pszSpace = '\0';
1496
1497 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
1498 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1499 if (pszColon)
1500 *pszColon = '\0';
1501
1502 const char *pszTrunk = szTrunk;
1503
1504# elif defined(RT_OS_WINDOWS)
1505 ComPtr<IHostNetworkInterface> hostInterface;
1506 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1507 if (!SUCCEEDED(rc))
1508 {
1509 AssertBreakpoint();
1510 LogRel(("NetworkAttachmentType_Bridged: FindByName failed, rc (0x%x)", rc));
1511 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1512 N_("Inexistent host networking interface, name '%ls'"),
1513 HifName.raw());
1514 }
1515
1516 HostNetworkInterfaceType_T ifType;
1517 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
1518 if(FAILED(hrc))
1519 {
1520 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
1521 H();
1522 }
1523
1524 if(ifType != HostNetworkInterfaceType_Bridged)
1525 {
1526 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1527 N_("Interface ('%ls') is not a Bridged Adapter interface"),
1528 HifName.raw());
1529 }
1530
1531 Guid hostIFGuid;
1532 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1533 if(FAILED(hrc))
1534 {
1535 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1536 H();
1537 }
1538
1539 INetCfg *pNc;
1540 ComPtr<INetCfgComponent> pAdaptorComponent;
1541 LPWSTR lpszApp;
1542 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
1543
1544 hrc = VBoxNetCfgWinQueryINetCfg( FALSE,
1545 L"VirtualBox",
1546 &pNc,
1547 &lpszApp );
1548 Assert(hrc == S_OK);
1549 if(hrc == S_OK)
1550 {
1551 /* get the adapter's INetCfgComponent*/
1552 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
1553 if(hrc != S_OK)
1554 {
1555 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1556 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
1557 H();
1558 }
1559 }
1560#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
1561 char szTrunkName[INTNET_MAX_TRUNK_NAME];
1562 char *pszTrunkName = szTrunkName;
1563 wchar_t * pswzBindName;
1564 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
1565 Assert(hrc == S_OK);
1566 if (hrc == S_OK)
1567 {
1568 int cwBindName = (int)wcslen(pswzBindName) + 1;
1569 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
1570 if(sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
1571 {
1572 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
1573 pszTrunkName += cbFullBindNamePrefix-1;
1574 if(!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
1575 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
1576 {
1577 Assert(0);
1578 DWORD err = GetLastError();
1579 hrc = HRESULT_FROM_WIN32(err);
1580 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
1581 LogRel(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x)\n", hrc, hrc));
1582 }
1583 }
1584 else
1585 {
1586 Assert(0);
1587 LogRel(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
1588 /** @todo set appropriate error code */
1589 hrc = E_FAIL;
1590 }
1591
1592 if(hrc != S_OK)
1593 {
1594 Assert(0);
1595 CoTaskMemFree(pswzBindName);
1596 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1597 H();
1598 }
1599
1600 /* we're not freeing the bind name since we'll use it later for detecting wireless*/
1601 }
1602 else
1603 {
1604 Assert(0);
1605 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1606 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
1607 H();
1608 }
1609 const char *pszTrunk = szTrunkName;
1610 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
1611
1612# elif defined(RT_OS_LINUX)
1613 /* @todo Check for malformed names. */
1614 const char *pszTrunk = pszHifName;
1615
1616# else
1617# error "PORTME (VBOX_WITH_NETFLT)"
1618# endif
1619
1620 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1621 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1622 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1623 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1624 char szNetwork[80];
1625 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1626 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1627 networkName = Bstr(szNetwork);
1628 trunkName = Bstr(pszTrunk);
1629 trunkType = Bstr(TRUNKTYPE_NETFLT);
1630
1631# if defined(RT_OS_DARWIN)
1632 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
1633 if ( strstr(pszHifName, "Wireless")
1634 || strstr(pszHifName, "AirPort" ))
1635 {
1636 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1637 }
1638# elif defined(RT_OS_LINUX)
1639 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
1640 if (iSock >= 0)
1641 {
1642 struct iwreq WRq;
1643
1644 memset(&WRq, 0, sizeof(WRq));
1645 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
1646 if (ioctl(iSock, SIOCGIWNAME, &WRq) >= 0)
1647 {
1648 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1649 Log(("Set SharedMacOnWire\n"));
1650 }
1651 else
1652 {
1653 Log(("Failed to get wireless name\n"));
1654 }
1655 close(iSock);
1656 }
1657 else
1658 {
1659 Log(("Failed to open wireless socket\n"));
1660 }
1661# elif defined(RT_OS_WINDOWS)
1662# define DEVNAME_PREFIX L"\\\\.\\"
1663 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
1664 * there is a pretty long way till there though since we need to obtain the symbolic link name
1665 * for the adapter device we are going to query given the device Guid */
1666
1667 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
1668 wchar_t FileName[MAX_PATH];
1669 wcscpy(FileName, DEVNAME_PREFIX);
1670 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
1671
1672 /* open the device */
1673 HANDLE hDevice = CreateFile(FileName,
1674 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
1675 NULL,
1676 OPEN_EXISTING,
1677 FILE_ATTRIBUTE_NORMAL,
1678 NULL);
1679 if (hDevice != INVALID_HANDLE_VALUE)
1680 {
1681 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
1682 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
1683 NDIS_PHYSICAL_MEDIUM PhMedium;
1684 DWORD cbResult;
1685 if (DeviceIoControl(hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, &Oid, sizeof(Oid), &PhMedium, sizeof(PhMedium), &cbResult, NULL))
1686 {
1687 /* that was simple, now examine PhMedium */
1688 if(PhMedium == NdisPhysicalMediumWirelessWan
1689 || PhMedium == NdisPhysicalMediumWirelessLan
1690 || PhMedium == NdisPhysicalMediumNative802_11
1691 || PhMedium == NdisPhysicalMediumBluetooth
1692 /*|| PhMedium == NdisPhysicalMediumWiMax*/
1693 )
1694 {
1695 Log(("this is a wireless adapter"));
1696 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1697 Log(("Set SharedMacOnWire\n"));
1698 }
1699 else
1700 {
1701 Log(("this is NOT a wireless adapter"));
1702 }
1703 }
1704 else
1705 {
1706 int winEr = GetLastError();
1707 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
1708 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
1709 }
1710
1711 CloseHandle(hDevice);
1712 }
1713 else
1714 {
1715 int winEr = GetLastError();
1716 LogRel(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
1717 AssertBreakpoint();
1718 }
1719
1720 CoTaskMemFree(pswzBindName);
1721
1722 pAdaptorComponent.setNull();
1723 /* release the pNc finally */
1724 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1725# else
1726 /** @todo PORTME: wireless detection */
1727# endif
1728
1729# if defined(RT_OS_SOLARIS)
1730# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
1731 /* Zone access restriction, don't allow snopping the global zone. */
1732 zoneid_t ZoneId = getzoneid();
1733 if (ZoneId != GLOBAL_ZONEID)
1734 {
1735 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
1736 }
1737# endif
1738# endif
1739
1740#elif defined(RT_OS_WINDOWS) /* not defined NetFlt */
1741 /* NOTHING TO DO HERE */
1742#elif defined(RT_OS_LINUX)
1743/// @todo aleksey: is there anything to be done here?
1744#elif defined(RT_OS_FREEBSD)
1745/** @todo FreeBSD: Check out this later (HIF networking). */
1746#else
1747# error "Port me"
1748#endif
1749 }
1750 else
1751 {
1752 switch (hrc)
1753 {
1754#ifdef RT_OS_LINUX
1755 case VERR_ACCESS_DENIED:
1756 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1757 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1758 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
1759 "change the group of that node and make yourself a member of that group. Make "
1760 "sure that these changes are permanent, especially if you are "
1761 "using udev"));
1762#endif /* RT_OS_LINUX */
1763 default:
1764 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1765 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1766 "Failed to initialize Host Interface Networking"));
1767 }
1768 }
1769 break;
1770 }
1771
1772 case NetworkAttachmentType_Internal:
1773 {
1774 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1775 if (str)
1776 {
1777 STR_CONV();
1778 if (psz && *psz)
1779 {
1780 if (fSniffer)
1781 {
1782 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1783 }
1784 else
1785 {
1786 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1787 }
1788 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1789 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1790 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1791 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone); RC_CHECK();
1792 networkName = Bstr(psz);
1793 trunkType = Bstr(TRUNKTYPE_WHATEVER);
1794 }
1795 STR_FREE();
1796 }
1797 break;
1798 }
1799
1800 case NetworkAttachmentType_HostOnly:
1801 {
1802 if (fSniffer)
1803 {
1804 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1805 }
1806 else
1807 {
1808 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1809 }
1810
1811 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1812 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1813#if defined(RT_OS_WINDOWS)
1814# ifndef VBOX_WITH_NETFLT
1815 hrc = E_NOTIMPL;
1816 LogRel(("NetworkAttachmentType_HostOnly: Not Implemented"));
1817 H();
1818# else
1819 Bstr HifName;
1820 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1821 if(FAILED(hrc))
1822 {
1823 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1824 H();
1825 }
1826
1827 Utf8Str HifNameUtf8(HifName);
1828 const char *pszHifName = HifNameUtf8.raw();
1829 ComPtr<IHostNetworkInterface> hostInterface;
1830 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1831 if (!SUCCEEDED(rc))
1832 {
1833 AssertBreakpoint();
1834 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)", rc));
1835 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1836 N_("Inexistent host networking interface, name '%ls'"),
1837 HifName.raw());
1838 }
1839
1840 HostNetworkInterfaceType_T ifType;
1841 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
1842 if(FAILED(hrc))
1843 {
1844 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
1845 H();
1846 }
1847
1848 if(ifType != HostNetworkInterfaceType_HostOnly)
1849 {
1850 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1851 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
1852 HifName.raw());
1853 }
1854
1855
1856 Guid hostIFGuid;
1857 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1858 if(FAILED(hrc))
1859 {
1860 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1861 H();
1862 }
1863
1864 INetCfg *pNc;
1865 ComPtr<INetCfgComponent> pAdaptorComponent;
1866 LPWSTR lpszApp;
1867 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
1868
1869 hrc = VBoxNetCfgWinQueryINetCfg( FALSE,
1870 L"VirtualBox",
1871 &pNc,
1872 &lpszApp );
1873 Assert(hrc == S_OK);
1874 if(hrc == S_OK)
1875 {
1876 /* get the adapter's INetCfgComponent*/
1877 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
1878 if(hrc != S_OK)
1879 {
1880 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1881 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
1882 H();
1883 }
1884 }
1885#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
1886 char szTrunkName[INTNET_MAX_TRUNK_NAME];
1887 char *pszTrunkName = szTrunkName;
1888 wchar_t * pswzBindName;
1889 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
1890 Assert(hrc == S_OK);
1891 if (hrc == S_OK)
1892 {
1893 int cwBindName = (int)wcslen(pswzBindName) + 1;
1894 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
1895 if(sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
1896 {
1897 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
1898 pszTrunkName += cbFullBindNamePrefix-1;
1899 if(!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
1900 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
1901 {
1902 Assert(0);
1903 DWORD err = GetLastError();
1904 hrc = HRESULT_FROM_WIN32(err);
1905 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
1906 LogRel(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x)\n", hrc, hrc));
1907 }
1908 }
1909 else
1910 {
1911 Assert(0);
1912 LogRel(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
1913 /** @todo set appropriate error code */
1914 hrc = E_FAIL;
1915 }
1916
1917 if(hrc != S_OK)
1918 {
1919 Assert(0);
1920 CoTaskMemFree(pswzBindName);
1921 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1922 H();
1923 }
1924 }
1925 else
1926 {
1927 Assert(0);
1928 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1929 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
1930 H();
1931 }
1932
1933
1934 CoTaskMemFree(pswzBindName);
1935
1936 pAdaptorComponent.setNull();
1937 /* release the pNc finally */
1938 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1939
1940 const char *pszTrunk = szTrunkName;
1941
1942
1943 /* TODO: set the proper Trunk and Network values, currently the driver uses the first adapter instance */
1944 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
1945 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1946 char szNetwork[80];
1947 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1948 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1949 networkName = Bstr(szNetwork);
1950 trunkName = Bstr(pszTrunk);
1951 trunkType = TRUNKTYPE_NETADP;
1952# endif /* defined VBOX_WITH_NETFLT*/
1953#elif defined(RT_OS_DARWIN)
1954 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK();
1955 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0"); RC_CHECK();
1956 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
1957 networkName = Bstr("HostInterfaceNetworking-vboxnet0");
1958 trunkName = Bstr("vboxnet0");
1959 trunkType = TRUNKTYPE_NETADP;
1960#else
1961 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK();
1962 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0"); RC_CHECK();
1963 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1964 networkName = Bstr("HostInterfaceNetworking-vboxnet0");
1965 trunkName = Bstr("vboxnet0");
1966 trunkType = TRUNKTYPE_NETFLT;
1967#endif
1968#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
1969 Bstr HifName;
1970 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1971 if(FAILED(hrc))
1972 {
1973 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1974 H();
1975 }
1976
1977 Utf8Str HifNameUtf8(HifName);
1978 const char *pszHifName = HifNameUtf8.raw();
1979 ComPtr<IHostNetworkInterface> hostInterface;
1980 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1981 if (!SUCCEEDED(rc))
1982 {
1983 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)", rc));
1984 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1985 N_("Inexistent host networking interface, name '%ls'"),
1986 HifName.raw());
1987 }
1988 Bstr tmpAddr, tmpMask;
1989 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPAddress"), tmpAddr.asOutParam());
1990 if (SUCCEEDED(hrc) && !tmpAddr.isNull())
1991 {
1992 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPNetMask"), tmpMask.asOutParam());
1993 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
1994 hrc = hostInterface->EnableStaticIpConfig(tmpAddr, tmpMask);
1995 }
1996 else
1997 hrc = hostInterface->EnableStaticIpConfig(Bstr(VBOXNET_IPV4ADDR_DEFAULT),
1998 Bstr(VBOXNET_IPV4MASK_DEFAULT));
1999
2000
2001 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPV6Address"), tmpAddr.asOutParam());
2002 if (SUCCEEDED(hrc))
2003 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPV6NetMask"), tmpMask.asOutParam());
2004 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
2005 hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
2006#endif
2007 break;
2008 }
2009
2010 default:
2011 AssertMsgFailed(("should not get here!\n"));
2012 break;
2013 }
2014
2015 if(!networkName.isNull())
2016 {
2017 /*
2018 * Until we implement service reference counters DHCP Server will be stopped
2019 * by DHCPServerRunner destructor.
2020 */
2021 ComPtr<IDHCPServer> dhcpServer;
2022 hrc = virtualBox->FindDHCPServerByNetworkName(networkName.mutableRaw(), dhcpServer.asOutParam());
2023 if(SUCCEEDED(hrc))
2024 {
2025 /* there is a DHCP server available for this network */
2026 BOOL bEnabled;
2027 hrc = dhcpServer->COMGETTER(Enabled)(&bEnabled);
2028 if(FAILED(hrc))
2029 {
2030 LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (0x%x)", hrc));
2031 H();
2032 }
2033
2034 if(bEnabled)
2035 hrc = dhcpServer->Start(networkName, trunkName, trunkType);
2036 }
2037 else
2038 {
2039 hrc = S_OK;
2040 }
2041 }
2042
2043 }
2044
2045 /*
2046 * Serial (UART) Ports
2047 */
2048 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
2049 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
2050 {
2051 ComPtr<ISerialPort> serialPort;
2052 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
2053 BOOL fEnabled = FALSE;
2054 if (serialPort)
2055 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
2056 if (!fEnabled)
2057 continue;
2058
2059 char szInstance[4]; Assert(ulInstance <= 999);
2060 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
2061
2062 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
2063 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2064
2065 ULONG ulIRQ, ulIOBase;
2066 PortMode_T HostMode;
2067 Bstr path;
2068 BOOL fServer;
2069 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
2070 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
2071 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
2072 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
2073 hrc = serialPort->COMGETTER(Server)(&fServer); H();
2074 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
2075 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
2076 if (HostMode != PortMode_Disconnected)
2077 {
2078 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2079 if (HostMode == PortMode_HostPipe)
2080 {
2081 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
2082 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
2083 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
2084 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
2085 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
2086 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
2087 }
2088 else if (HostMode == PortMode_HostDevice)
2089 {
2090 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
2091 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
2092 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
2093 }
2094 }
2095 }
2096
2097 /*
2098 * Parallel (LPT) Ports
2099 */
2100 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
2101 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
2102 {
2103 ComPtr<IParallelPort> parallelPort;
2104 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
2105 BOOL fEnabled = FALSE;
2106 if (parallelPort)
2107 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
2108 if (!fEnabled)
2109 continue;
2110
2111 char szInstance[4]; Assert(ulInstance <= 999);
2112 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
2113
2114 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
2115 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2116
2117 ULONG ulIRQ, ulIOBase;
2118 Bstr DevicePath;
2119 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
2120 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
2121 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
2122 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
2123 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
2124 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2125 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
2126 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
2127 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
2128 }
2129
2130 /*
2131 * VMM Device
2132 */
2133 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
2134 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2135 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2136 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
2137 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
2138 Assert(!afPciDeviceNo[4]);
2139 afPciDeviceNo[4] = true;
2140 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2141 Bstr hwVersion;
2142 hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
2143 if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
2144 {
2145 CFGMR3InsertInteger(pCfg, "HeapEnabled", 0); RC_CHECK();
2146 }
2147
2148 /* the VMM device's Main driver */
2149 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2150 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
2151 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2152 VMMDev *pVMMDev = pConsole->mVMMDev;
2153 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
2154
2155 /*
2156 * Attach the status driver.
2157 */
2158 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2159 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2160 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2161 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
2162 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2163 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2164
2165 /*
2166 * Audio Sniffer Device
2167 */
2168 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
2169 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2170 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2171
2172 /* the Audio Sniffer device's Main driver */
2173 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2174 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
2175 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2176 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
2177 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
2178
2179 /*
2180 * AC'97 ICH / SoundBlaster16 audio
2181 */
2182 BOOL enabled;
2183 ComPtr<IAudioAdapter> audioAdapter;
2184 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
2185 if (audioAdapter)
2186 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
2187
2188 if (enabled)
2189 {
2190 AudioControllerType_T audioController;
2191 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
2192 switch (audioController)
2193 {
2194 case AudioControllerType_AC97:
2195 {
2196 /* default: ICH AC97 */
2197 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
2198 rc = CFGMR3InsertNode(pDev, "0", &pInst);
2199 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2200 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
2201 Assert(!afPciDeviceNo[5]);
2202 afPciDeviceNo[5] = true;
2203 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2204 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2205 break;
2206 }
2207 case AudioControllerType_SB16:
2208 {
2209 /* legacy SoundBlaster16 */
2210 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
2211 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2212 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2213 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2214 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
2215 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
2216 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
2217 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
2218 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
2219 break;
2220 }
2221 }
2222
2223 /* the Audio driver */
2224 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2225 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
2226 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2227
2228 AudioDriverType_T audioDriver;
2229 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
2230 switch (audioDriver)
2231 {
2232 case AudioDriverType_Null:
2233 {
2234 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
2235 break;
2236 }
2237#ifdef RT_OS_WINDOWS
2238#ifdef VBOX_WITH_WINMM
2239 case AudioDriverType_WinMM:
2240 {
2241 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
2242 break;
2243 }
2244#endif
2245 case AudioDriverType_DirectSound:
2246 {
2247 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
2248 break;
2249 }
2250#endif /* RT_OS_WINDOWS */
2251#ifdef RT_OS_SOLARIS
2252 case AudioDriverType_SolAudio:
2253 {
2254 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
2255 break;
2256 }
2257#endif
2258#ifdef RT_OS_LINUX
2259# ifdef VBOX_WITH_ALSA
2260 case AudioDriverType_ALSA:
2261 {
2262 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
2263 break;
2264 }
2265# endif
2266# ifdef VBOX_WITH_PULSE
2267 case AudioDriverType_Pulse:
2268 {
2269 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
2270 break;
2271 }
2272# endif
2273#endif /* RT_OS_LINUX */
2274#if defined (RT_OS_LINUX) || defined (RT_OS_FREEBSD)
2275 case AudioDriverType_OSS:
2276 {
2277 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
2278 break;
2279 }
2280#endif
2281#ifdef RT_OS_DARWIN
2282 case AudioDriverType_CoreAudio:
2283 {
2284 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
2285 break;
2286 }
2287#endif
2288 }
2289 hrc = pMachine->COMGETTER(Name)(&str); H();
2290 STR_CONV();
2291 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
2292 STR_FREE();
2293 }
2294
2295 /*
2296 * The USB Controller.
2297 */
2298 ComPtr<IUSBController> USBCtlPtr;
2299 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
2300 if (USBCtlPtr)
2301 {
2302 BOOL fEnabled;
2303 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
2304 if (fEnabled)
2305 {
2306 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
2307 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2308 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2309 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
2310 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
2311 Assert(!afPciDeviceNo[6]);
2312 afPciDeviceNo[6] = true;
2313 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2314
2315 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2316 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2317 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2318
2319 /*
2320 * Attach the status driver.
2321 */
2322 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2323 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2324 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2325 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
2326 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2327 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2328
2329#ifdef VBOX_WITH_EHCI
2330 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
2331 if (fEnabled)
2332 {
2333 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
2334 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2335 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2336 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2337 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
2338 Assert(!afPciDeviceNo[11]);
2339 afPciDeviceNo[11] = true;
2340 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2341
2342 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2343 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2344 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2345
2346 /*
2347 * Attach the status driver.
2348 */
2349 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2350 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2351 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2352 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
2353 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2354 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2355 }
2356 else
2357#endif
2358 {
2359 /*
2360 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
2361 * on a per device level now.
2362 */
2363 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
2364 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
2365 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
2366 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
2367 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
2368 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
2369 // that it's documented somewhere.) Users needing it can use:
2370 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
2371 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
2372 }
2373 }
2374 }
2375
2376 /*
2377 * Clipboard
2378 */
2379 {
2380 ClipboardMode_T mode = ClipboardMode_Disabled;
2381 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
2382
2383 if (mode != ClipboardMode_Disabled)
2384 {
2385 /* Load the service */
2386 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
2387
2388 if (RT_FAILURE (rc))
2389 {
2390 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
2391 /* That is not a fatal failure. */
2392 rc = VINF_SUCCESS;
2393 }
2394 else
2395 {
2396 /* Setup the service. */
2397 VBOXHGCMSVCPARM parm;
2398
2399 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2400
2401 switch (mode)
2402 {
2403 default:
2404 case ClipboardMode_Disabled:
2405 {
2406 LogRel(("VBoxSharedClipboard mode: Off\n"));
2407 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
2408 break;
2409 }
2410 case ClipboardMode_GuestToHost:
2411 {
2412 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
2413 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
2414 break;
2415 }
2416 case ClipboardMode_HostToGuest:
2417 {
2418 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
2419 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
2420 break;
2421 }
2422 case ClipboardMode_Bidirectional:
2423 {
2424 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
2425 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
2426 break;
2427 }
2428 }
2429
2430 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
2431
2432 Log(("Set VBoxSharedClipboard mode\n"));
2433 }
2434 }
2435 }
2436
2437#ifdef VBOX_WITH_CROGL
2438/* Currently broken on Snow Leopard 64-bit */
2439# if !(defined(RT_OS_DARWIN) && defined(RT_ARCH_AMD64))
2440 /*
2441 * crOpenGL
2442 */
2443 {
2444 BOOL fEnabled = false;
2445 hrc = pMachine->COMGETTER(Accelerate3DEnabled) (&fEnabled); H();
2446
2447 if (fEnabled)
2448 {
2449 /* Load the service */
2450 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
2451 if (RT_FAILURE(rc))
2452 {
2453 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
2454 /* That is not a fatal failure. */
2455 rc = VINF_SUCCESS;
2456 }
2457 else
2458 {
2459 LogRel(("Shared crOpenGL service loaded.\n"));
2460
2461 /* Setup the service. */
2462 VBOXHGCMSVCPARM parm;
2463 parm.type = VBOX_HGCM_SVC_PARM_PTR;
2464
2465 //parm.u.pointer.addr = static_cast <IConsole *> (pData->pVMMDev->getParent());
2466 parm.u.pointer.addr = pConsole->mVMMDev->getParent()->getDisplay()->getFramebuffer();
2467 parm.u.pointer.size = sizeof(IFramebuffer *);
2468
2469 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_FRAMEBUFFER, 1, &parm);
2470 if (!RT_SUCCESS(rc))
2471 AssertMsgFailed(("SHCRGL_HOST_FN_SET_FRAMEBUFFER failed with %Rrc\n", rc));
2472 }
2473 }
2474 }
2475# endif
2476#endif
2477
2478#ifdef VBOX_WITH_GUEST_PROPS
2479 /*
2480 * Guest property service
2481 */
2482 {
2483 /* Load the service */
2484 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
2485
2486 if (RT_FAILURE (rc))
2487 {
2488 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
2489 /* That is not a fatal failure. */
2490 rc = VINF_SUCCESS;
2491 }
2492 else
2493 {
2494 /* Pull over the properties from the server. */
2495 SafeArray <BSTR> namesOut;
2496 SafeArray <BSTR> valuesOut;
2497 SafeArray <ULONG64> timestampsOut;
2498 SafeArray <BSTR> flagsOut;
2499 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
2500 ComSafeArrayAsOutParam(valuesOut),
2501 ComSafeArrayAsOutParam(timestampsOut),
2502 ComSafeArrayAsOutParam(flagsOut)); H();
2503 size_t cProps = namesOut.size();
2504 if ( valuesOut.size() != cProps
2505 || timestampsOut.size() != cProps
2506 || flagsOut.size() != cProps
2507 )
2508 rc = VERR_INVALID_PARAMETER;
2509
2510 std::vector <Utf8Str> utf8Names, utf8Values, utf8Flags;
2511 std::vector <char *> names, values, flags;
2512 std::vector <ULONG64> timestamps;
2513 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2514 if ( !VALID_PTR(namesOut[i])
2515 || !VALID_PTR(valuesOut[i])
2516 || !VALID_PTR(flagsOut[i])
2517 )
2518 rc = VERR_INVALID_POINTER;
2519 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2520 {
2521 utf8Names.push_back(Bstr(namesOut[i]));
2522 utf8Values.push_back(Bstr(valuesOut[i]));
2523 timestamps.push_back(timestampsOut[i]);
2524 utf8Flags.push_back(Bstr(flagsOut[i]));
2525 if ( utf8Names.back().isNull()
2526 || utf8Values.back().isNull()
2527 || utf8Flags.back().isNull()
2528 )
2529 throw std::bad_alloc();
2530 }
2531 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2532 {
2533 names.push_back(utf8Names[i].mutableRaw());
2534 values.push_back(utf8Values[i].mutableRaw());
2535 flags.push_back(utf8Flags[i].mutableRaw());
2536 }
2537 names.push_back(NULL);
2538 values.push_back(NULL);
2539 timestamps.push_back(0);
2540 flags.push_back(NULL);
2541
2542 /* Setup the service. */
2543 VBOXHGCMSVCPARM parms[4];
2544
2545 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
2546 parms[0].u.pointer.addr = &names.front();
2547 parms[0].u.pointer.size = 0; /* We don't actually care. */
2548 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
2549 parms[1].u.pointer.addr = &values.front();
2550 parms[1].u.pointer.size = 0; /* We don't actually care. */
2551 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
2552 parms[2].u.pointer.addr = &timestamps.front();
2553 parms[2].u.pointer.size = 0; /* We don't actually care. */
2554 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
2555 parms[3].u.pointer.addr = &flags.front();
2556 parms[3].u.pointer.size = 0; /* We don't actually care. */
2557
2558 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4, &parms[0]);
2559
2560 /* Register the host notification callback */
2561 HGCMSVCEXTHANDLE hDummy;
2562 HGCMHostRegisterServiceExtension (&hDummy, "VBoxGuestPropSvc",
2563 Console::doGuestPropNotification,
2564 pvConsole);
2565
2566 Log(("Set VBoxGuestPropSvc property store\n"));
2567 }
2568 }
2569#endif /* VBOX_WITH_GUEST_PROPS defined */
2570
2571 /*
2572 * CFGM overlay handling.
2573 *
2574 * Here we check the extra data entries for CFGM values
2575 * and create the nodes and insert the values on the fly. Existing
2576 * values will be removed and reinserted. CFGM is typed, so by default
2577 * we will guess whether it's a string or an integer (byte arrays are
2578 * not currently supported). It's possible to override this autodetection
2579 * by adding "string:", "integer:" or "bytes:" (future).
2580 *
2581 * We first perform a run on global extra data, then on the machine
2582 * extra data to support global settings with local overrides.
2583 *
2584 */
2585 /** @todo add support for removing nodes and byte blobs. */
2586 Bstr strExtraDataKey;
2587 bool fGlobalExtraData = true;
2588 for (;;)
2589 {
2590 /*
2591 * Get the next key
2592 */
2593 Bstr strNextExtraDataKey;
2594 Bstr strExtraDataValue;
2595 if (fGlobalExtraData)
2596 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2597 strExtraDataValue.asOutParam());
2598 else
2599 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2600 strExtraDataValue.asOutParam());
2601
2602 /* stop if for some reason there's nothing more to request */
2603 if (FAILED(hrc) || !strNextExtraDataKey)
2604 {
2605 /* if we're out of global keys, continue with machine, otherwise we're done */
2606 if (fGlobalExtraData)
2607 {
2608 fGlobalExtraData = false;
2609 strExtraDataKey.setNull();
2610 continue;
2611 }
2612 break;
2613 }
2614 strExtraDataKey = strNextExtraDataKey;
2615
2616 /*
2617 * We only care about keys starting with "VBoxInternal/"
2618 */
2619 Utf8Str strExtraDataKeyUtf8(strExtraDataKey);
2620 char *pszExtraDataKey = (char *)strExtraDataKeyUtf8.raw();
2621 if (strncmp(pszExtraDataKey, "VBoxInternal/", sizeof("VBoxInternal/") - 1) != 0)
2622 continue;
2623 pszExtraDataKey += sizeof("VBoxInternal/") - 1;
2624
2625 /*
2626 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2627 * Split the two and get the node, delete the value and create the node
2628 * if necessary.
2629 */
2630 PCFGMNODE pNode;
2631 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2632 if (pszCFGMValueName)
2633 {
2634 /* terminate the node and advance to the value (Utf8Str might not
2635 offically like this but wtf) */
2636 *pszCFGMValueName = '\0';
2637 pszCFGMValueName++;
2638
2639 /* does the node already exist? */
2640 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2641 if (pNode)
2642 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2643 else
2644 {
2645 /* create the node */
2646 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2647 if (RT_FAILURE(rc))
2648 {
2649 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2650 continue;
2651 }
2652 Assert(pNode);
2653 }
2654 }
2655 else
2656 {
2657 /* root value (no node path). */
2658 pNode = pRoot;
2659 pszCFGMValueName = pszExtraDataKey;
2660 pszExtraDataKey--;
2661 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2662 }
2663
2664 /*
2665 * Now let's have a look at the value.
2666 * Empty strings means that we should remove the value, which we've
2667 * already done above.
2668 */
2669 Utf8Str strCFGMValueUtf8(strExtraDataValue);
2670 const char *pszCFGMValue = strCFGMValueUtf8.raw();
2671 if ( pszCFGMValue
2672 && *pszCFGMValue)
2673 {
2674 uint64_t u64Value;
2675
2676 /* check for type prefix first. */
2677 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
2678 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
2679 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
2680 {
2681 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
2682 if (RT_SUCCESS(rc))
2683 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2684 }
2685 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
2686 rc = VERR_NOT_IMPLEMENTED;
2687 /* auto detect type. */
2688 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
2689 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2690 else
2691 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
2692 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
2693 }
2694 }
2695
2696#undef H
2697#undef RC_CHECK
2698#undef STR_FREE
2699#undef STR_CONV
2700
2701 /* Register VM state change handler */
2702 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2703 AssertRC (rc2);
2704 if (RT_SUCCESS (rc))
2705 rc = rc2;
2706
2707 /* Register VM runtime error handler */
2708 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2709 AssertRC (rc2);
2710 if (RT_SUCCESS (rc))
2711 rc = rc2;
2712
2713 /* Save the VM pointer in the machine object */
2714 pConsole->mpVM = pVM;
2715
2716 LogFlowFunc (("vrc = %Rrc\n", rc));
2717 LogFlowFuncLeave();
2718
2719 return rc;
2720}
2721
2722/* 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