VirtualBox

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

Last change on this file since 19276 was 19239, checked in by vboxsync, 16 years ago

Main: support for using VBox from Python on Windows (still certain limitation apply, such as enum visibility)

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