VirtualBox

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

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

Main: repair RT_OS_LINUX=1 VBOX_WITH_NETFLT=

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