VirtualBox

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

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

VMM: correct report cores count, also expose more CPUID leaves by default

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette