VirtualBox

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

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

Move the TPR patching decision logic to Main.

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