VirtualBox

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

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

E1000: Added support for 82545EM (MT Server)

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