VirtualBox

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

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

VMM,ConsoleImpl2: Moved NT4LeafLimit down into /CPUM and documented it. Cleanup.

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