VirtualBox

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

Last change on this file since 19379 was 19379, checked in by vboxsync, 16 years ago

ConsoleImpl2.cpp: force hardware virtualization mode if cCpus > 1. Required for darwin at least.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette