VirtualBox

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

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

ConsoleImpl2.cpp: param info

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 129.1 KB
Line 
1/* $Id: ConsoleImpl2.cpp 22048 2009-08-07 08:05:49Z 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 Bstr osTypeId;
215 hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
216
217 /*
218 * Get root node first.
219 * This is the only node in the tree.
220 */
221 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
222 Assert(pRoot);
223
224 /*
225 * Set the root (and VMM) level values.
226 */
227 hrc = pMachine->COMGETTER(Name)(&str); H();
228 STR_CONV();
229 rc = CFGMR3InsertString(pRoot, "Name", psz); RC_CHECK();
230 STR_FREE();
231 rc = CFGMR3InsertBytes(pRoot, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
232 rc = CFGMR3InsertInteger(pRoot, "RamSize", cbRam); RC_CHECK();
233 rc = CFGMR3InsertInteger(pRoot, "RamHoleSize", cbRamHole); RC_CHECK();
234 rc = CFGMR3InsertInteger(pRoot, "NumCPUs", cCpus); RC_CHECK();
235 rc = CFGMR3InsertString (pRoot, "OSType", Utf8Str(osTypeId)); RC_CHECK();
236 rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10); RC_CHECK();
237 rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1); /* boolean */ RC_CHECK();
238 rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1); /* boolean */ RC_CHECK();
239 /** @todo Config: RawR0, PATMEnabled and CASMEnabled needs attention later. */
240 rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1); /* boolean */ RC_CHECK();
241 rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1); /* boolean */ RC_CHECK();
242
243 if (osTypeId == "WindowsNT4")
244 {
245 /*
246 * We must limit CPUID count for Windows NT 4,
247 * as otherwise it stops with 0x3e error
248 * (MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED).
249 */
250 LogRel(("Limiting CPUID leaf count for NT4 guests\n"));
251 rc = CFGMR3InsertInteger(pRoot, "NT4LeafLimit", true); RC_CHECK();
252 }
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 * @param pCfg Configuration node for the device
2084 * @param pLunL0 To store the pointer to the LUN#0.
2085 * @param pInst The instance CFGM node
2086 * @param attachDetach To determine if the network attachment should be attached/detached
2087 * after/before configuration.
2088 *
2089 * @note Locks the Console object for writing.
2090 */
2091DECLCALLBACK(int) Console::configNetwork(Console *pThis, const char *pszDevice,
2092 unsigned uInstance, unsigned uLun,
2093 INetworkAdapter *aNetworkAdapter,
2094 PCFGMNODE pCfg, PCFGMNODE pLunL0,
2095 PCFGMNODE pInst, bool attachDetach)
2096{
2097 int rc = VINF_SUCCESS;
2098 int rcRet = VINF_SUCCESS;
2099
2100 AutoCaller autoCaller(pThis);
2101 AssertComRCReturn (autoCaller.rc(), VERR_ACCESS_DENIED);
2102
2103 /*
2104 * Locking the object before doing VMR3* calls is quite safe here, since
2105 * we're on EMT. Write lock is necessary because we indirectly modify the
2106 * meAttachmentType member.
2107 */
2108 AutoWriteLock alock(pThis);
2109
2110 PVM pVM = pThis->mpVM;
2111
2112#define STR_CONV() do { rc = RTUtf16ToUtf8(str, &psz); RC_CHECK(); } while (0)
2113#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } if (psz) { RTStrFree(psz); psz = NULL; } } while (0)
2114#define RC_CHECK() do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc)); return rc; } } while (0)
2115#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); return VERR_GENERAL_FAILURE; } } while (0)
2116 do
2117 {
2118 HRESULT hrc;
2119 ComPtr<IMachine> pMachine = pThis->machine();
2120
2121 ComPtr<IVirtualBox> virtualBox;
2122 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam());
2123 H();
2124
2125 ComPtr<IHost> host;
2126 hrc = virtualBox->COMGETTER(Host)(host.asOutParam());
2127 H();
2128
2129 BSTR str = NULL;
2130 char *psz = NULL;
2131
2132 /*
2133 * Detach the device train for the current network attachment.
2134 */
2135
2136 if (attachDetach)
2137 {
2138 rc = PDMR3DeviceDetach (pVM, pszDevice, uInstance, uLun, PDMDEVATT_FLAGS_NOT_HOT_PLUG);
2139 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
2140 rc = VINF_SUCCESS;
2141 AssertRC (rc);
2142
2143 /* nuke anything which might have been left behind. */
2144 CFGMR3RemoveNode (CFGMR3GetChildF (pInst, "LUN#%d", uLun));
2145 }
2146
2147 /*
2148 * Enable the packet sniffer if requested.
2149 */
2150 BOOL fSniffer;
2151 hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer);
2152 H();
2153 if (fSniffer)
2154 {
2155 /* insert the sniffer filter driver. */
2156 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2157 RC_CHECK();
2158 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer");
2159 RC_CHECK();
2160 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2161 RC_CHECK();
2162 hrc = aNetworkAdapter->COMGETTER(TraceFile)(&str);
2163 H();
2164 if (str) /* check convention for indicating default file. */
2165 {
2166 STR_CONV();
2167 rc = CFGMR3InsertString(pCfg, "File", psz);
2168 RC_CHECK();
2169 STR_FREE();
2170 }
2171 }
2172
2173 Bstr networkName, trunkName, trunkType;
2174 NetworkAttachmentType_T eAttachmentType;
2175 hrc = aNetworkAdapter->COMGETTER(AttachmentType)(&eAttachmentType);
2176 H();
2177 switch (eAttachmentType)
2178 {
2179 case NetworkAttachmentType_Null:
2180 break;
2181
2182 case NetworkAttachmentType_NAT:
2183 {
2184 if (fSniffer)
2185 {
2186 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2187 RC_CHECK();
2188 }
2189 else
2190 {
2191 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2192 RC_CHECK();
2193 }
2194
2195 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT");
2196 RC_CHECK();
2197
2198 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2199 RC_CHECK();
2200
2201 /* Configure TFTP prefix and boot filename. */
2202 hrc = virtualBox->COMGETTER(HomeFolder)(&str);
2203 H();
2204 STR_CONV();
2205 if (psz && *psz)
2206 {
2207 char *pszTFTPPrefix = NULL;
2208 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
2209 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix);
2210 RC_CHECK();
2211 RTStrFree(pszTFTPPrefix);
2212 }
2213 STR_FREE();
2214 hrc = pMachine->COMGETTER(Name)(&str);
2215 H();
2216 STR_CONV();
2217 char *pszBootFile = NULL;
2218 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
2219 STR_FREE();
2220 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile);
2221 RC_CHECK();
2222 RTStrFree(pszBootFile);
2223
2224 hrc = aNetworkAdapter->COMGETTER(NATNetwork)(&str);
2225 H();
2226 if (str)
2227 {
2228 STR_CONV();
2229 if (psz && *psz)
2230 {
2231 rc = CFGMR3InsertString(pCfg, "Network", psz);
2232 RC_CHECK();
2233 /* NAT uses its own DHCP implementation */
2234 //networkName = Bstr(psz);
2235 }
2236
2237 STR_FREE();
2238 }
2239 break;
2240 }
2241
2242 case NetworkAttachmentType_Bridged:
2243 {
2244#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
2245 Assert ((int)pThis->maTapFD[uInstance] >= 0);
2246 if ((int)pThis->maTapFD[uInstance] >= 0)
2247 {
2248 if (fSniffer)
2249 {
2250 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2251 RC_CHECK();
2252 }
2253 else
2254 {
2255 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2256 RC_CHECK();
2257 }
2258 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface");
2259 RC_CHECK();
2260 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2261 RC_CHECK();
2262 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pThis->maTapFD[uInstance]);
2263 RC_CHECK();
2264 }
2265#elif defined(VBOX_WITH_NETFLT)
2266 /*
2267 * This is the new VBoxNetFlt+IntNet stuff.
2268 */
2269 if (fSniffer)
2270 {
2271 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2272 RC_CHECK();
2273 }
2274 else
2275 {
2276 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2277 RC_CHECK();
2278 }
2279
2280 Bstr HifName;
2281 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
2282 if(FAILED(hrc))
2283 {
2284 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
2285 H();
2286 }
2287
2288 Utf8Str HifNameUtf8(HifName);
2289 const char *pszHifName = HifNameUtf8.raw();
2290
2291# if defined(RT_OS_DARWIN)
2292 /* The name is on the form 'ifX: long name', chop it off at the colon. */
2293 char szTrunk[8];
2294 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
2295 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
2296 if (!pszColon)
2297 {
2298 hrc = aNetworkAdapter->Detach();
2299 H();
2300 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2301 N_("Malformed host interface networking name '%ls'"),
2302 HifName.raw());
2303 }
2304 *pszColon = '\0';
2305 const char *pszTrunk = szTrunk;
2306
2307# elif defined(RT_OS_SOLARIS)
2308 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
2309 char szTrunk[256];
2310 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
2311 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
2312
2313 /*
2314 * Currently don't bother about malformed names here for the sake of people using
2315 * VBoxManage and setting only the NIC name from there. If there is a space we
2316 * chop it off and proceed, otherwise just use whatever we've got.
2317 */
2318 if (pszSpace)
2319 *pszSpace = '\0';
2320
2321 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
2322 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
2323 if (pszColon)
2324 *pszColon = '\0';
2325
2326 const char *pszTrunk = szTrunk;
2327
2328# elif defined(RT_OS_WINDOWS)
2329 ComPtr<IHostNetworkInterface> hostInterface;
2330 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
2331 if (!SUCCEEDED(rc))
2332 {
2333 AssertBreakpoint();
2334 LogRel(("NetworkAttachmentType_Bridged: FindByName failed, rc (0x%x)", rc));
2335 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2336 N_("Inexistent host networking interface, name '%ls'"),
2337 HifName.raw());
2338 }
2339
2340 HostNetworkInterfaceType_T ifType;
2341 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
2342 if(FAILED(hrc))
2343 {
2344 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
2345 H();
2346 }
2347
2348 if(ifType != HostNetworkInterfaceType_Bridged)
2349 {
2350 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2351 N_("Interface ('%ls') is not a Bridged Adapter interface"),
2352 HifName.raw());
2353 }
2354
2355 Bstr hostIFGuid_;
2356 hrc = hostInterface->COMGETTER(Id)(hostIFGuid_.asOutParam());
2357 if(FAILED(hrc))
2358 {
2359 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
2360 H();
2361 }
2362 Guid hostIFGuid(hostIFGuid_);
2363
2364 INetCfg *pNc;
2365 ComPtr<INetCfgComponent> pAdaptorComponent;
2366 LPWSTR lpszApp;
2367 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
2368
2369 hrc = VBoxNetCfgWinQueryINetCfg( FALSE,
2370 L"VirtualBox",
2371 &pNc,
2372 &lpszApp );
2373 Assert(hrc == S_OK);
2374 if(hrc == S_OK)
2375 {
2376 /* get the adapter's INetCfgComponent*/
2377 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
2378 if(hrc != S_OK)
2379 {
2380 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2381 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2382 H();
2383 }
2384 }
2385#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
2386 char szTrunkName[INTNET_MAX_TRUNK_NAME];
2387 char *pszTrunkName = szTrunkName;
2388 wchar_t * pswzBindName;
2389 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
2390 Assert(hrc == S_OK);
2391 if (hrc == S_OK)
2392 {
2393 int cwBindName = (int)wcslen(pswzBindName) + 1;
2394 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
2395 if(sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
2396 {
2397 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
2398 pszTrunkName += cbFullBindNamePrefix-1;
2399 if(!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
2400 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
2401 {
2402 Assert(0);
2403 DWORD err = GetLastError();
2404 hrc = HRESULT_FROM_WIN32(err);
2405 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
2406 LogRel(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x)\n", hrc, hrc));
2407 }
2408 }
2409 else
2410 {
2411 Assert(0);
2412 LogRel(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
2413 /** @todo set appropriate error code */
2414 hrc = E_FAIL;
2415 }
2416
2417 if(hrc != S_OK)
2418 {
2419 Assert(0);
2420 CoTaskMemFree(pswzBindName);
2421 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2422 H();
2423 }
2424
2425 /* we're not freeing the bind name since we'll use it later for detecting wireless*/
2426 }
2427 else
2428 {
2429 Assert(0);
2430 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2431 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2432 H();
2433 }
2434 const char *pszTrunk = szTrunkName;
2435 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
2436
2437# elif defined(RT_OS_LINUX)
2438 /* @todo Check for malformed names. */
2439 const char *pszTrunk = pszHifName;
2440
2441# else
2442# error "PORTME (VBOX_WITH_NETFLT)"
2443# endif
2444
2445 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet");
2446 RC_CHECK();
2447 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2448 RC_CHECK();
2449 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk);
2450 RC_CHECK();
2451 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
2452 RC_CHECK();
2453 char szNetwork[80];
2454 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
2455 rc = CFGMR3InsertString(pCfg, "Network", szNetwork);
2456 RC_CHECK();
2457 networkName = Bstr(szNetwork);
2458 trunkName = Bstr(pszTrunk);
2459 trunkType = Bstr(TRUNKTYPE_NETFLT);
2460
2461# if defined(RT_OS_DARWIN)
2462 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
2463 if ( strstr(pszHifName, "Wireless")
2464 || strstr(pszHifName, "AirPort" ))
2465 {
2466 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
2467 RC_CHECK();
2468 }
2469# elif defined(RT_OS_LINUX)
2470 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
2471 if (iSock >= 0)
2472 {
2473 struct iwreq WRq;
2474
2475 memset(&WRq, 0, sizeof(WRq));
2476 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
2477 if (ioctl(iSock, SIOCGIWNAME, &WRq) >= 0)
2478 {
2479 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
2480 RC_CHECK();
2481 Log(("Set SharedMacOnWire\n"));
2482 }
2483 else
2484 {
2485 Log(("Failed to get wireless name\n"));
2486 }
2487 close(iSock);
2488 }
2489 else
2490 {
2491 Log(("Failed to open wireless socket\n"));
2492 }
2493# elif defined(RT_OS_WINDOWS)
2494# define DEVNAME_PREFIX L"\\\\.\\"
2495 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
2496 * there is a pretty long way till there though since we need to obtain the symbolic link name
2497 * for the adapter device we are going to query given the device Guid */
2498
2499
2500 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
2501
2502 wchar_t FileName[MAX_PATH];
2503 wcscpy(FileName, DEVNAME_PREFIX);
2504 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
2505
2506 /* open the device */
2507 HANDLE hDevice = CreateFile(FileName,
2508 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
2509 NULL,
2510 OPEN_EXISTING,
2511 FILE_ATTRIBUTE_NORMAL,
2512 NULL);
2513
2514 if (hDevice != INVALID_HANDLE_VALUE)
2515 {
2516 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
2517 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
2518 NDIS_PHYSICAL_MEDIUM PhMedium;
2519 DWORD cbResult;
2520 if (DeviceIoControl(hDevice,
2521 IOCTL_NDIS_QUERY_GLOBAL_STATS,
2522 &Oid,
2523 sizeof(Oid),
2524 &PhMedium,
2525 sizeof(PhMedium),
2526 &cbResult,
2527 NULL))
2528 {
2529 /* that was simple, now examine PhMedium */
2530 if ( PhMedium == NdisPhysicalMediumWirelessWan
2531 || PhMedium == NdisPhysicalMediumWirelessLan
2532 || PhMedium == NdisPhysicalMediumNative802_11
2533 || PhMedium == NdisPhysicalMediumBluetooth)
2534 {
2535 Log(("this is a wireless adapter"));
2536 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
2537 RC_CHECK();
2538 Log(("Set SharedMacOnWire\n"));
2539 }
2540 else
2541 {
2542 Log(("this is NOT a wireless adapter"));
2543 }
2544 }
2545 else
2546 {
2547 int winEr = GetLastError();
2548 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
2549 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
2550 }
2551
2552 CloseHandle(hDevice);
2553 }
2554 else
2555 {
2556 int winEr = GetLastError();
2557 LogRel(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
2558 AssertBreakpoint();
2559 }
2560
2561 CoTaskMemFree(pswzBindName);
2562
2563 pAdaptorComponent.setNull();
2564 /* release the pNc finally */
2565 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2566# else
2567 /** @todo PORTME: wireless detection */
2568# endif
2569
2570# if defined(RT_OS_SOLARIS)
2571# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
2572 /* Zone access restriction, don't allow snopping the global zone. */
2573 zoneid_t ZoneId = getzoneid();
2574 if (ZoneId != GLOBAL_ZONEID)
2575 {
2576 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
2577 }
2578# endif
2579# endif
2580
2581#elif defined(RT_OS_WINDOWS) /* not defined NetFlt */
2582 /* NOTHING TO DO HERE */
2583#elif defined(RT_OS_LINUX)
2584/// @todo aleksey: is there anything to be done here?
2585#elif defined(RT_OS_FREEBSD)
2586/** @todo FreeBSD: Check out this later (HIF networking). */
2587#else
2588# error "Port me"
2589#endif
2590 break;
2591 }
2592
2593 case NetworkAttachmentType_Internal:
2594 {
2595 hrc = aNetworkAdapter->COMGETTER(InternalNetwork)(&str);
2596 H();
2597 if (str)
2598 {
2599 STR_CONV();
2600 if (psz && *psz)
2601 {
2602 if (fSniffer)
2603 {
2604 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2605 RC_CHECK();
2606 }
2607 else
2608 {
2609 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2610 RC_CHECK();
2611 }
2612 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet");
2613 RC_CHECK();
2614 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2615 RC_CHECK();
2616 rc = CFGMR3InsertString(pCfg, "Network", psz);
2617 RC_CHECK();
2618 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone);
2619 RC_CHECK();
2620 networkName = Bstr(psz);
2621 trunkType = Bstr(TRUNKTYPE_WHATEVER);
2622 }
2623 STR_FREE();
2624 }
2625 break;
2626 }
2627
2628 case NetworkAttachmentType_HostOnly:
2629 {
2630 if (fSniffer)
2631 {
2632 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2633 RC_CHECK();
2634 }
2635 else
2636 {
2637 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2638 RC_CHECK();
2639 }
2640
2641 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet");
2642 RC_CHECK();
2643 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2644 RC_CHECK();
2645
2646 Bstr HifName;
2647 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
2648 if(FAILED(hrc))
2649 {
2650 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)\n", hrc));
2651 H();
2652 }
2653
2654 Utf8Str HifNameUtf8(HifName);
2655 const char *pszHifName = HifNameUtf8.raw();
2656 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface): %s\n", pszHifName));
2657 ComPtr<IHostNetworkInterface> hostInterface;
2658 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
2659 if (!SUCCEEDED(rc))
2660 {
2661 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)\n", rc));
2662 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2663 N_("Inexistent host networking interface, name '%ls'"),
2664 HifName.raw());
2665 }
2666
2667 char szNetwork[80];
2668 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
2669
2670#if defined(RT_OS_WINDOWS)
2671# ifndef VBOX_WITH_NETFLT
2672 hrc = E_NOTIMPL;
2673 LogRel(("NetworkAttachmentType_HostOnly: Not Implemented\n"));
2674 H();
2675# else /* defined VBOX_WITH_NETFLT*/
2676
2677 HostNetworkInterfaceType_T ifType;
2678 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
2679 if(FAILED(hrc))
2680 {
2681 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)\n", hrc));
2682 H();
2683 }
2684
2685 if(ifType != HostNetworkInterfaceType_HostOnly)
2686 {
2687 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2688 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
2689 HifName.raw());
2690 }
2691
2692 Bstr hostIFGuid_;
2693 hrc = hostInterface->COMGETTER(Id)(hostIFGuid_.asOutParam());
2694 if(FAILED(hrc))
2695 {
2696 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)\n", hrc));
2697 H();
2698 }
2699 Guid hostIFGuid(hostIFGuid_);
2700
2701 INetCfg *pNc;
2702 ComPtr<INetCfgComponent> pAdaptorComponent;
2703 LPWSTR lpszApp;
2704 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
2705
2706 hrc = VBoxNetCfgWinQueryINetCfg(FALSE,
2707 L"VirtualBox",
2708 &pNc,
2709 &lpszApp);
2710 Assert(hrc == S_OK);
2711 if(hrc == S_OK)
2712 {
2713 /* get the adapter's INetCfgComponent*/
2714 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
2715 if(hrc != S_OK)
2716 {
2717 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2718 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)\n", hrc));
2719 H();
2720 }
2721 }
2722#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
2723 char szTrunkName[INTNET_MAX_TRUNK_NAME];
2724 char *pszTrunkName = szTrunkName;
2725 wchar_t * pswzBindName;
2726 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
2727 Assert(hrc == S_OK);
2728 if (hrc == S_OK)
2729 {
2730 int cwBindName = (int)wcslen(pswzBindName) + 1;
2731 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
2732 if(sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
2733 {
2734 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
2735 pszTrunkName += cbFullBindNamePrefix-1;
2736 if(!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
2737 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
2738 {
2739 Assert(0);
2740 DWORD err = GetLastError();
2741 hrc = HRESULT_FROM_WIN32(err);
2742 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
2743 LogRel(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x)\n", hrc, hrc));
2744 }
2745 }
2746 else
2747 {
2748 Assert(0);
2749 LogRel(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
2750 /** @todo set appropriate error code */
2751 hrc = E_FAIL;
2752 }
2753
2754 if(hrc != S_OK)
2755 {
2756 Assert(0);
2757 CoTaskMemFree(pswzBindName);
2758 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2759 H();
2760 }
2761 }
2762 else
2763 {
2764 Assert(0);
2765 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2766 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)\n", hrc));
2767 H();
2768 }
2769
2770
2771 CoTaskMemFree(pswzBindName);
2772
2773 pAdaptorComponent.setNull();
2774 /* release the pNc finally */
2775 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2776
2777 const char *pszTrunk = szTrunkName;
2778
2779
2780 /* TODO: set the proper Trunk and Network values, currently the driver uses the first adapter instance */
2781 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp);
2782 RC_CHECK();
2783 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk);
2784 RC_CHECK();
2785 rc = CFGMR3InsertString(pCfg, "Network", szNetwork);
2786 RC_CHECK();
2787 networkName = Bstr(szNetwork);
2788 trunkName = Bstr(pszTrunk);
2789 trunkType = TRUNKTYPE_NETADP;
2790# endif /* defined VBOX_WITH_NETFLT*/
2791#elif defined(RT_OS_DARWIN)
2792 rc = CFGMR3InsertString(pCfg, "Trunk", pszHifName);
2793 RC_CHECK();
2794 rc = CFGMR3InsertString(pCfg, "Network", szNetwork);
2795 RC_CHECK();
2796 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp);
2797 RC_CHECK();
2798 networkName = Bstr(szNetwork);
2799 trunkName = Bstr(pszHifName);
2800 trunkType = TRUNKTYPE_NETADP;
2801#else
2802 rc = CFGMR3InsertString(pCfg, "Trunk", pszHifName);
2803 RC_CHECK();
2804 rc = CFGMR3InsertString(pCfg, "Network", szNetwork);
2805 RC_CHECK();
2806 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
2807 RC_CHECK();
2808 networkName = Bstr(szNetwork);
2809 trunkName = Bstr(pszHifName);
2810 trunkType = TRUNKTYPE_NETFLT;
2811#endif
2812#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
2813
2814 Bstr tmpAddr, tmpMask;
2815
2816 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPAddress", pszHifName), tmpAddr.asOutParam());
2817 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
2818 {
2819 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPNetMask", pszHifName), tmpMask.asOutParam());
2820 if (SUCCEEDED(hrc) && !tmpMask.isEmpty())
2821 hrc = hostInterface->EnableStaticIpConfig(BstrFmt("HostOnly/%s/IPAddress", pszHifName),
2822 BstrFmt("HostOnly/%s/IPNetMask", pszHifName));
2823 else
2824 hrc = hostInterface->EnableStaticIpConfig(BstrFmt("HostOnly/%s/IPAddress", pszHifName),
2825 Bstr(VBOXNET_IPV4MASK_DEFAULT));
2826 }
2827 else
2828 hrc = hostInterface->EnableStaticIpConfig(Bstr(VBOXNET_IPV4ADDR_DEFAULT),
2829 Bstr(VBOXNET_IPV4MASK_DEFAULT));
2830
2831 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6Address", pszHifName), tmpAddr.asOutParam());
2832 if (SUCCEEDED(hrc))
2833 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6NetMask", pszHifName), tmpMask.asOutParam());
2834 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty() && !tmpMask.isEmpty())
2835 hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
2836#endif
2837 break;
2838 }
2839
2840 default:
2841 AssertMsgFailed(("should not get here!\n"));
2842 break;
2843 }
2844
2845 /*
2846 * Attempt to attach the driver.
2847 */
2848 switch (eAttachmentType)
2849 {
2850 case NetworkAttachmentType_Null:
2851 break;
2852
2853 case NetworkAttachmentType_Bridged:
2854 case NetworkAttachmentType_Internal:
2855 case NetworkAttachmentType_HostOnly:
2856 case NetworkAttachmentType_NAT:
2857 {
2858 if (SUCCEEDED(hrc) && SUCCEEDED(rc))
2859 {
2860 if (attachDetach)
2861 {
2862 rc = PDMR3DeviceAttach (pVM, pszDevice, uInstance, uLun, NULL, PDMDEVATT_FLAGS_NOT_HOT_PLUG);
2863 AssertRC (rc);
2864 }
2865
2866 {
2867 /** @todo r=pritesh: get the dhcp server name from the
2868 * previous network configuration and then stop the server
2869 * else it may conflict with the dhcp server running with
2870 * the current attachment type
2871 */
2872 /* Stop the hostonly DHCP Server */
2873 }
2874
2875 if(!networkName.isNull())
2876 {
2877 /*
2878 * Until we implement service reference counters DHCP Server will be stopped
2879 * by DHCPServerRunner destructor.
2880 */
2881 ComPtr<IDHCPServer> dhcpServer;
2882 hrc = virtualBox->FindDHCPServerByNetworkName(networkName.mutableRaw(), dhcpServer.asOutParam());
2883 if(SUCCEEDED(hrc))
2884 {
2885 /* there is a DHCP server available for this network */
2886 BOOL bEnabled;
2887 hrc = dhcpServer->COMGETTER(Enabled)(&bEnabled);
2888 if(FAILED(hrc))
2889 {
2890 LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (0x%x)", hrc));
2891 H();
2892 }
2893
2894 if(bEnabled)
2895 hrc = dhcpServer->Start(networkName, trunkName, trunkType);
2896 }
2897 else
2898 {
2899 hrc = S_OK;
2900 }
2901 }
2902 }
2903
2904 break;
2905 }
2906
2907 default:
2908 AssertMsgFailed(("should not get here!\n"));
2909 break;
2910 }
2911
2912 meAttachmentType[uInstance] = eAttachmentType;
2913 }
2914 while (0);
2915
2916#undef STR_FREE
2917#undef STR_CONV
2918#undef H
2919#undef RC_CHECK
2920
2921 return rcRet;
2922}
2923
2924/* 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