VirtualBox

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

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

Comment updates

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