VirtualBox

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

Last change on this file since 22214 was 22214, checked in by vboxsync, 15 years ago

Main: documentation.

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