VirtualBox

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

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

SSM,VMM,Devices,Main,VBoxBFE: Live snapshot/migration SSM API adjustments.

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