VirtualBox

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

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

OSE/win burn fix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 124.8 KB
Line 
1/* $Id: ConsoleImpl2.cpp 18405 2009-03-27 15:23:11Z 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 pDev = pDevE1000;
1206 break;
1207#endif
1208 default:
1209 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
1210 adapterType, ulInstance));
1211 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1212 N_("Invalid network adapter type '%d' for slot '%d'"),
1213 adapterType, ulInstance);
1214 }
1215
1216 char szInstance[4]; Assert(ulInstance <= 999);
1217 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1218 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1219 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1220 /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
1221 * next 4 get 16..19. */
1222 unsigned iPciDeviceNo = 3;
1223 if (ulInstance)
1224 {
1225 if (ulInstance < 4)
1226 iPciDeviceNo = ulInstance - 1 + 8;
1227 else
1228 iPciDeviceNo = ulInstance - 4 + 16;
1229 }
1230 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
1231 Assert(!afPciDeviceNo[iPciDeviceNo]);
1232 afPciDeviceNo[iPciDeviceNo] = true;
1233 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1234 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1235#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
1236 if (pDev == pDevPCNet)
1237 {
1238 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", false); RC_CHECK();
1239 }
1240#endif
1241
1242 /*
1243 * The virtual hardware type. PCNet supports two types.
1244 */
1245 switch (adapterType)
1246 {
1247 case NetworkAdapterType_Am79C970A:
1248 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
1249 break;
1250 case NetworkAdapterType_Am79C973:
1251 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
1252 break;
1253 case NetworkAdapterType_I82540EM:
1254 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
1255 break;
1256 case NetworkAdapterType_I82543GC:
1257 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
1258 break;
1259 }
1260
1261 /*
1262 * Get the MAC address and convert it to binary representation
1263 */
1264 Bstr macAddr;
1265 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1266 Assert(macAddr);
1267 Utf8Str macAddrUtf8 = macAddr;
1268 char *macStr = (char*)macAddrUtf8.raw();
1269 Assert(strlen(macStr) == 12);
1270 RTMAC Mac;
1271 memset(&Mac, 0, sizeof(Mac));
1272 char *pMac = (char*)&Mac;
1273 for (uint32_t i = 0; i < 6; i++)
1274 {
1275 char c1 = *macStr++ - '0';
1276 if (c1 > 9)
1277 c1 -= 7;
1278 char c2 = *macStr++ - '0';
1279 if (c2 > 9)
1280 c2 -= 7;
1281 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1282 }
1283 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1284
1285 /*
1286 * Check if the cable is supposed to be unplugged
1287 */
1288 BOOL fCableConnected;
1289 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1290 rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
1291
1292 /*
1293 * Line speed to report from custom drivers
1294 */
1295 ULONG ulLineSpeed;
1296 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1297 rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
1298
1299 /*
1300 * Attach the status driver.
1301 */
1302 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1303 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1304 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1305 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
1306
1307 /*
1308 * Enable the packet sniffer if requested.
1309 */
1310 BOOL fSniffer;
1311 hrc = networkAdapter->COMGETTER(TraceEnabled)(&fSniffer); H();
1312 if (fSniffer)
1313 {
1314 /* insert the sniffer filter driver. */
1315 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1316 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
1317 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1318 hrc = networkAdapter->COMGETTER(TraceFile)(&str); H();
1319 if (str) /* check convention for indicating default file. */
1320 {
1321 STR_CONV();
1322 rc = CFGMR3InsertString(pCfg, "File", psz); RC_CHECK();
1323 STR_FREE();
1324 }
1325 }
1326
1327
1328 NetworkAttachmentType_T networkAttachment;
1329 hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H();
1330 Bstr networkName, trunkName, trunkType;
1331 switch (networkAttachment)
1332 {
1333 case NetworkAttachmentType_Null:
1334 break;
1335
1336 case NetworkAttachmentType_NAT:
1337 {
1338 if (fSniffer)
1339 {
1340 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1341 }
1342 else
1343 {
1344 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1345 }
1346 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
1347 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1348 /* (Port forwarding goes here.) */
1349
1350 /* Configure TFTP prefix and boot filename. */
1351 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
1352 STR_CONV();
1353 if (psz && *psz)
1354 {
1355 char *pszTFTPPrefix = NULL;
1356 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
1357 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix); RC_CHECK();
1358 RTStrFree(pszTFTPPrefix);
1359 }
1360 STR_FREE();
1361 hrc = pMachine->COMGETTER(Name)(&str); H();
1362 STR_CONV();
1363 char *pszBootFile = NULL;
1364 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
1365 STR_FREE();
1366 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile); RC_CHECK();
1367 RTStrFree(pszBootFile);
1368
1369 hrc = networkAdapter->COMGETTER(NATNetwork)(&str); H();
1370 if (str)
1371 {
1372 STR_CONV();
1373 if (psz && *psz)
1374 {
1375 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1376 /* NAT uses its own DHCP implementation */
1377 //networkName = Bstr(psz);
1378 }
1379
1380 STR_FREE();
1381 }
1382 break;
1383 }
1384
1385 case NetworkAttachmentType_Bridged:
1386 {
1387 /*
1388 * Perform the attachment if required (don't return on error!)
1389 */
1390 hrc = pConsole->attachToBridgedInterface(networkAdapter);
1391 if (SUCCEEDED(hrc))
1392 {
1393#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
1394 Assert ((int)pConsole->maTapFD[ulInstance] >= 0);
1395 if ((int)pConsole->maTapFD[ulInstance] >= 0)
1396 {
1397 if (fSniffer)
1398 {
1399 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1400 }
1401 else
1402 {
1403 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1404 }
1405 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1406 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1407 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pConsole->maTapFD[ulInstance]); RC_CHECK();
1408 }
1409#elif defined(VBOX_WITH_NETFLT)
1410 /*
1411 * This is the new VBoxNetFlt+IntNet stuff.
1412 */
1413 if (fSniffer)
1414 {
1415 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1416 }
1417 else
1418 {
1419 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1420 }
1421
1422 Bstr HifName;
1423 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1424 if(FAILED(hrc))
1425 {
1426 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1427 H();
1428 }
1429
1430 Utf8Str HifNameUtf8(HifName);
1431 const char *pszHifName = HifNameUtf8.raw();
1432
1433# if defined(RT_OS_DARWIN)
1434 /* The name is on the form 'ifX: long name', chop it off at the colon. */
1435 char szTrunk[8];
1436 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
1437 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1438 if (!pszColon)
1439 {
1440 hrc = networkAdapter->Detach(); H();
1441 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1442 N_("Malformed host interface networking name '%ls'"),
1443 HifName.raw());
1444 }
1445 *pszColon = '\0';
1446 const char *pszTrunk = szTrunk;
1447
1448# elif defined(RT_OS_SOLARIS)
1449 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
1450 char szTrunk[256];
1451 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
1452 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
1453
1454 /*
1455 * Currently don't bother about malformed names here for the sake of people using
1456 * VBoxManage and setting only the NIC name from there. If there is a space we
1457 * chop it off and proceed, otherwise just use whatever we've got.
1458 */
1459 if (pszSpace)
1460 *pszSpace = '\0';
1461
1462 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
1463 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1464 if (pszColon)
1465 *pszColon = '\0';
1466
1467 const char *pszTrunk = szTrunk;
1468
1469# elif defined(RT_OS_WINDOWS)
1470 ComPtr<IHostNetworkInterface> hostInterface;
1471 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1472 if (!SUCCEEDED(rc))
1473 {
1474 AssertBreakpoint();
1475 LogRel(("NetworkAttachmentType_Bridged: FindByName failed, rc (0x%x)", rc));
1476 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1477 N_("Inexistent host networking interface, name '%ls'"),
1478 HifName.raw());
1479 }
1480
1481 HostNetworkInterfaceType_T ifType;
1482 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
1483 if(FAILED(hrc))
1484 {
1485 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
1486 H();
1487 }
1488
1489 if(ifType != HostNetworkInterfaceType_Bridged)
1490 {
1491 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1492 N_("Interface ('%ls') is not a Bridged Adapter interface"),
1493 HifName.raw());
1494 }
1495
1496 Guid hostIFGuid;
1497 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1498 if(FAILED(hrc))
1499 {
1500 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1501 H();
1502 }
1503
1504 INetCfg *pNc;
1505 ComPtr<INetCfgComponent> pAdaptorComponent;
1506 LPWSTR lpszApp;
1507 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
1508
1509 hrc = VBoxNetCfgWinQueryINetCfg( FALSE,
1510 L"VirtualBox",
1511 &pNc,
1512 &lpszApp );
1513 Assert(hrc == S_OK);
1514 if(hrc == S_OK)
1515 {
1516 /* get the adapter's INetCfgComponent*/
1517 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
1518 if(hrc != S_OK)
1519 {
1520 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1521 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
1522 H();
1523 }
1524 }
1525#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
1526 char szTrunkName[INTNET_MAX_TRUNK_NAME];
1527 char *pszTrunkName = szTrunkName;
1528 wchar_t * pswzBindName;
1529 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
1530 Assert(hrc == S_OK);
1531 if (hrc == S_OK)
1532 {
1533 int cwBindName = (int)wcslen(pswzBindName) + 1;
1534 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
1535 if(sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
1536 {
1537 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
1538 pszTrunkName += cbFullBindNamePrefix-1;
1539 if(!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
1540 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
1541 {
1542 Assert(0);
1543 DWORD err = GetLastError();
1544 hrc = HRESULT_FROM_WIN32(err);
1545 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
1546 LogRel(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x)\n", hrc, hrc));
1547 }
1548 }
1549 else
1550 {
1551 Assert(0);
1552 LogRel(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
1553 /** @todo set appropriate error code */
1554 hrc = E_FAIL;
1555 }
1556
1557 if(hrc != S_OK)
1558 {
1559 Assert(0);
1560 CoTaskMemFree(pswzBindName);
1561 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1562 H();
1563 }
1564
1565 /* we're not freeing the bind name since we'll use it later for detecting wireless*/
1566 }
1567 else
1568 {
1569 Assert(0);
1570 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1571 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
1572 H();
1573 }
1574 const char *pszTrunk = szTrunkName;
1575 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
1576
1577# elif defined(RT_OS_LINUX)
1578 /* @todo Check for malformed names. */
1579 const char *pszTrunk = pszHifName;
1580
1581# else
1582# error "PORTME (VBOX_WITH_NETFLT)"
1583# endif
1584
1585 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1586 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1587 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1588 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1589 char szNetwork[80];
1590 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1591 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1592 networkName = Bstr(szNetwork);
1593 trunkName = Bstr(pszTrunk);
1594 trunkType = Bstr(TRUNKTYPE_NETFLT);
1595
1596# if defined(RT_OS_DARWIN)
1597 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
1598 if ( strstr(pszHifName, "Wireless")
1599 || strstr(pszHifName, "AirPort" ))
1600 {
1601 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1602 }
1603# elif defined(RT_OS_LINUX)
1604 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
1605 if (iSock >= 0)
1606 {
1607 struct iwreq WRq;
1608
1609 memset(&WRq, 0, sizeof(WRq));
1610 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
1611 if (ioctl(iSock, SIOCGIWNAME, &WRq) >= 0)
1612 {
1613 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1614 Log(("Set SharedMacOnWire\n"));
1615 }
1616 else
1617 {
1618 Log(("Failed to get wireless name\n"));
1619 }
1620 close(iSock);
1621 }
1622 else
1623 {
1624 Log(("Failed to open wireless socket\n"));
1625 }
1626# elif defined(RT_OS_WINDOWS)
1627# define DEVNAME_PREFIX L"\\\\.\\"
1628 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
1629 * there is a pretty long way till there though since we need to obtain the symbolic link name
1630 * for the adapter device we are going to query given the device Guid */
1631
1632 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
1633 wchar_t FileName[MAX_PATH];
1634 wcscpy(FileName, DEVNAME_PREFIX);
1635 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
1636
1637 /* open the device */
1638 HANDLE hDevice = CreateFile(FileName,
1639 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
1640 NULL,
1641 OPEN_EXISTING,
1642 FILE_ATTRIBUTE_NORMAL,
1643 NULL);
1644 if (hDevice != INVALID_HANDLE_VALUE)
1645 {
1646 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
1647 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
1648 NDIS_PHYSICAL_MEDIUM PhMedium;
1649 DWORD cbResult;
1650 if (DeviceIoControl(hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, &Oid, sizeof(Oid), &PhMedium, sizeof(PhMedium), &cbResult, NULL))
1651 {
1652 /* that was simple, now examine PhMedium */
1653 if(PhMedium == NdisPhysicalMediumWirelessWan
1654 || PhMedium == NdisPhysicalMediumWirelessLan
1655 || PhMedium == NdisPhysicalMediumNative802_11
1656 || PhMedium == NdisPhysicalMediumBluetooth
1657 /*|| PhMedium == NdisPhysicalMediumWiMax*/
1658 )
1659 {
1660 Log(("this is a wireless adapter"));
1661 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1662 Log(("Set SharedMacOnWire\n"));
1663 }
1664 else
1665 {
1666 Log(("this is NOT a wireless adapter"));
1667 }
1668 }
1669 else
1670 {
1671 int winEr = GetLastError();
1672 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
1673 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
1674 }
1675
1676 CloseHandle(hDevice);
1677 }
1678 else
1679 {
1680 int winEr = GetLastError();
1681 LogRel(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
1682 AssertBreakpoint();
1683 }
1684
1685 CoTaskMemFree(pswzBindName);
1686
1687 pAdaptorComponent.setNull();
1688 /* release the pNc finally */
1689 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1690# else
1691 /** @todo PORTME: wireless detection */
1692# endif
1693
1694# if defined(RT_OS_SOLARIS)
1695# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
1696 /* Zone access restriction, don't allow snopping the global zone. */
1697 zoneid_t ZoneId = getzoneid();
1698 if (ZoneId != GLOBAL_ZONEID)
1699 {
1700 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
1701 }
1702# endif
1703# endif
1704
1705#elif defined(RT_OS_WINDOWS)
1706 if (fSniffer)
1707 {
1708 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1709 }
1710 else
1711 {
1712 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1713 }
1714 Bstr hostInterfaceName;
1715 hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
1716 ComPtr<IHostNetworkInterface> hostInterface;
1717 rc = host->FindHostNetworkInterfaceByName(hostInterfaceName, hostInterface.asOutParam());
1718 if (!SUCCEEDED(rc))
1719 {
1720 AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
1721 hrc = networkAdapter->Detach(); H();
1722 }
1723 else
1724 {
1725# ifdef VBOX_WITH_NETFLT
1726 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1727 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1728 rc = CFGMR3InsertString(pCfg, "Trunk", Utf8Str(hostInterfaceName)); RC_CHECK();
1729 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1730# endif
1731 Guid hostIFGuid;
1732 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1733 char szDriverGUID[256] = {0};
1734 /* add curly brackets */
1735 szDriverGUID[0] = '{';
1736 strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
1737 strcat(szDriverGUID, "}");
1738 rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
1739 }
1740#elif defined(RT_OS_LINUX)
1741/// @todo aleksey: is there anything to be done here?
1742#elif defined(RT_OS_FREEBSD)
1743/** @todo FreeBSD: Check out this later (HIF networking). */
1744#else
1745# error "Port me"
1746#endif
1747 }
1748 else
1749 {
1750 switch (hrc)
1751 {
1752#ifdef RT_OS_LINUX
1753 case VERR_ACCESS_DENIED:
1754 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1755 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1756 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
1757 "change the group of that node and make yourself a member of that group. Make "
1758 "sure that these changes are permanent, especially if you are "
1759 "using udev"));
1760#endif /* RT_OS_LINUX */
1761 default:
1762 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1763 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1764 "Failed to initialize Host Interface Networking"));
1765 }
1766 }
1767 break;
1768 }
1769
1770 case NetworkAttachmentType_Internal:
1771 {
1772 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1773 if (str)
1774 {
1775 STR_CONV();
1776 if (psz && *psz)
1777 {
1778 if (fSniffer)
1779 {
1780 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1781 }
1782 else
1783 {
1784 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1785 }
1786 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1787 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1788 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1789 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone); RC_CHECK();
1790 networkName = Bstr(psz);
1791 trunkType = Bstr(TRUNKTYPE_WHATEVER);
1792 }
1793 STR_FREE();
1794 }
1795 break;
1796 }
1797
1798 case NetworkAttachmentType_HostOnly:
1799 {
1800 if (fSniffer)
1801 {
1802 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1803 }
1804 else
1805 {
1806 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1807 }
1808
1809 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1810 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1811#if defined(RT_OS_WINDOWS)
1812# ifndef VBOX_WITH_NETFLT
1813 hrc = E_NOTIMPL;
1814 LogRel(("NetworkAttachmentType_HostOnly: Not Implemented"));
1815 H();
1816# else
1817 Bstr HifName;
1818 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1819 if(FAILED(hrc))
1820 {
1821 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1822 H();
1823 }
1824
1825 Utf8Str HifNameUtf8(HifName);
1826 const char *pszHifName = HifNameUtf8.raw();
1827 ComPtr<IHostNetworkInterface> hostInterface;
1828 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1829 if (!SUCCEEDED(rc))
1830 {
1831 AssertBreakpoint();
1832 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)", rc));
1833 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1834 N_("Inexistent host networking interface, name '%ls'"),
1835 HifName.raw());
1836 }
1837
1838 HostNetworkInterfaceType_T ifType;
1839 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
1840 if(FAILED(hrc))
1841 {
1842 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
1843 H();
1844 }
1845
1846 if(ifType != HostNetworkInterfaceType_HostOnly)
1847 {
1848 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1849 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
1850 HifName.raw());
1851 }
1852
1853
1854 Guid hostIFGuid;
1855 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1856 if(FAILED(hrc))
1857 {
1858 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1859 H();
1860 }
1861
1862 INetCfg *pNc;
1863 ComPtr<INetCfgComponent> pAdaptorComponent;
1864 LPWSTR lpszApp;
1865 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
1866
1867 hrc = VBoxNetCfgWinQueryINetCfg( FALSE,
1868 L"VirtualBox",
1869 &pNc,
1870 &lpszApp );
1871 Assert(hrc == S_OK);
1872 if(hrc == S_OK)
1873 {
1874 /* get the adapter's INetCfgComponent*/
1875 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
1876 if(hrc != S_OK)
1877 {
1878 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1879 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
1880 H();
1881 }
1882 }
1883#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
1884 char szTrunkName[INTNET_MAX_TRUNK_NAME];
1885 char *pszTrunkName = szTrunkName;
1886 wchar_t * pswzBindName;
1887 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
1888 Assert(hrc == S_OK);
1889 if (hrc == S_OK)
1890 {
1891 int cwBindName = (int)wcslen(pswzBindName) + 1;
1892 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
1893 if(sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
1894 {
1895 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
1896 pszTrunkName += cbFullBindNamePrefix-1;
1897 if(!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
1898 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
1899 {
1900 Assert(0);
1901 DWORD err = GetLastError();
1902 hrc = HRESULT_FROM_WIN32(err);
1903 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
1904 LogRel(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x)\n", hrc, hrc));
1905 }
1906 }
1907 else
1908 {
1909 Assert(0);
1910 LogRel(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
1911 /** @todo set appropriate error code */
1912 hrc = E_FAIL;
1913 }
1914
1915 if(hrc != S_OK)
1916 {
1917 Assert(0);
1918 CoTaskMemFree(pswzBindName);
1919 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1920 H();
1921 }
1922 }
1923 else
1924 {
1925 Assert(0);
1926 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1927 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
1928 H();
1929 }
1930
1931
1932 CoTaskMemFree(pswzBindName);
1933
1934 pAdaptorComponent.setNull();
1935 /* release the pNc finally */
1936 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1937
1938 const char *pszTrunk = szTrunkName;
1939
1940
1941 /* TODO: set the proper Trunk and Network values, currently the driver uses the first adapter instance */
1942 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
1943 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1944 char szNetwork[80];
1945 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1946 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1947 networkName = Bstr(szNetwork);
1948 trunkName = Bstr(pszTrunk);
1949 trunkType = TRUNKTYPE_NETADP;
1950# endif /* definedd VBOX_WITH_NETFLT*/
1951#elif defined(RT_OS_DARWIN)
1952 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK();
1953 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0"); RC_CHECK();
1954 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
1955 networkName = Bstr("HostInterfaceNetworking-vboxnet0");
1956 trunkName = Bstr("vboxnet0");
1957 trunkType = TRUNKTYPE_NETADP;
1958#else
1959 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK();
1960 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0"); RC_CHECK();
1961 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1962 networkName = Bstr("HostInterfaceNetworking-vboxnet0");
1963 trunkName = Bstr("vboxnet0");
1964 trunkType = TRUNKTYPE_NETFLT;
1965#endif
1966#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
1967 Bstr HifName;
1968 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1969 if(FAILED(hrc))
1970 {
1971 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1972 H();
1973 }
1974
1975 Utf8Str HifNameUtf8(HifName);
1976 const char *pszHifName = HifNameUtf8.raw();
1977 ComPtr<IHostNetworkInterface> hostInterface;
1978 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1979 if (!SUCCEEDED(rc))
1980 {
1981 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)", rc));
1982 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1983 N_("Inexistent host networking interface, name '%ls'"),
1984 HifName.raw());
1985 }
1986 Bstr tmpAddr, tmpMask;
1987 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPAddress"), tmpAddr.asOutParam());
1988 if (SUCCEEDED(hrc) && !tmpAddr.isNull())
1989 {
1990 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPNetMask"), tmpMask.asOutParam());
1991 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
1992 hrc = hostInterface->EnableStaticIpConfig(tmpAddr, tmpMask);
1993 }
1994 else
1995 hrc = hostInterface->EnableStaticIpConfig(Bstr(VBOXNET_IPV4ADDR_DEFAULT),
1996 Bstr(VBOXNET_IPV4MASK_DEFAULT));
1997
1998
1999 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPV6Address"), tmpAddr.asOutParam());
2000 if (SUCCEEDED(hrc))
2001 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPV6NetMask"), tmpMask.asOutParam());
2002 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
2003 hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
2004#endif
2005 break;
2006 }
2007
2008 default:
2009 AssertMsgFailed(("should not get here!\n"));
2010 break;
2011 }
2012
2013 if(!networkName.isNull())
2014 {
2015 /*
2016 * Until we implement service reference counters DHCP Server will be stopped
2017 * by DHCPServerRunner destructor.
2018 */
2019 ComPtr<IDHCPServer> dhcpServer;
2020 hrc = virtualBox->FindDHCPServerByNetworkName(networkName.mutableRaw(), dhcpServer.asOutParam());
2021 if(SUCCEEDED(hrc))
2022 {
2023 /* there is a DHCP server available for this network */
2024 BOOL bEnabled;
2025 hrc = dhcpServer->COMGETTER(Enabled)(&bEnabled);
2026 if(FAILED(hrc))
2027 {
2028 LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (0x%x)", hrc));
2029 H();
2030 }
2031
2032 if(bEnabled)
2033 hrc = dhcpServer->Start(networkName, trunkName, trunkType);
2034 }
2035 else
2036 {
2037 hrc = S_OK;
2038 }
2039 }
2040
2041 }
2042
2043 /*
2044 * Serial (UART) Ports
2045 */
2046 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
2047 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
2048 {
2049 ComPtr<ISerialPort> serialPort;
2050 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
2051 BOOL fEnabled = FALSE;
2052 if (serialPort)
2053 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
2054 if (!fEnabled)
2055 continue;
2056
2057 char szInstance[4]; Assert(ulInstance <= 999);
2058 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
2059
2060 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
2061 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2062
2063 ULONG ulIRQ, ulIOBase;
2064 PortMode_T HostMode;
2065 Bstr path;
2066 BOOL fServer;
2067 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
2068 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
2069 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
2070 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
2071 hrc = serialPort->COMGETTER(Server)(&fServer); H();
2072 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
2073 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
2074 if (HostMode != PortMode_Disconnected)
2075 {
2076 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2077 if (HostMode == PortMode_HostPipe)
2078 {
2079 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
2080 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
2081 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
2082 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
2083 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
2084 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
2085 }
2086 else if (HostMode == PortMode_HostDevice)
2087 {
2088 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
2089 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
2090 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
2091 }
2092 }
2093 }
2094
2095 /*
2096 * Parallel (LPT) Ports
2097 */
2098 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
2099 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
2100 {
2101 ComPtr<IParallelPort> parallelPort;
2102 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
2103 BOOL fEnabled = FALSE;
2104 if (parallelPort)
2105 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
2106 if (!fEnabled)
2107 continue;
2108
2109 char szInstance[4]; Assert(ulInstance <= 999);
2110 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
2111
2112 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
2113 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2114
2115 ULONG ulIRQ, ulIOBase;
2116 Bstr DevicePath;
2117 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
2118 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
2119 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
2120 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
2121 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
2122 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2123 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
2124 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
2125 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
2126 }
2127
2128 /*
2129 * VMM Device
2130 */
2131 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
2132 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2133 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2134 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
2135 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
2136 Assert(!afPciDeviceNo[4]);
2137 afPciDeviceNo[4] = true;
2138 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2139 Bstr hwVersion;
2140 hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
2141 if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
2142 {
2143 CFGMR3InsertInteger(pCfg, "HeapEnabled", 0); RC_CHECK();
2144 }
2145
2146 /* the VMM device's Main driver */
2147 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2148 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
2149 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2150 VMMDev *pVMMDev = pConsole->mVMMDev;
2151 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
2152
2153 /*
2154 * Attach the status driver.
2155 */
2156 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2157 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2158 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2159 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
2160 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2161 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2162
2163 /*
2164 * Audio Sniffer Device
2165 */
2166 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
2167 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2168 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2169
2170 /* the Audio Sniffer device's Main driver */
2171 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2172 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
2173 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2174 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
2175 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
2176
2177 /*
2178 * AC'97 ICH / SoundBlaster16 audio
2179 */
2180 BOOL enabled;
2181 ComPtr<IAudioAdapter> audioAdapter;
2182 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
2183 if (audioAdapter)
2184 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
2185
2186 if (enabled)
2187 {
2188 AudioControllerType_T audioController;
2189 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
2190 switch (audioController)
2191 {
2192 case AudioControllerType_AC97:
2193 {
2194 /* default: ICH AC97 */
2195 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
2196 rc = CFGMR3InsertNode(pDev, "0", &pInst);
2197 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2198 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
2199 Assert(!afPciDeviceNo[5]);
2200 afPciDeviceNo[5] = true;
2201 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2202 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2203 break;
2204 }
2205 case AudioControllerType_SB16:
2206 {
2207 /* legacy SoundBlaster16 */
2208 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
2209 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2210 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2211 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2212 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
2213 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
2214 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
2215 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
2216 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
2217 break;
2218 }
2219 }
2220
2221 /* the Audio driver */
2222 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2223 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
2224 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2225
2226 AudioDriverType_T audioDriver;
2227 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
2228 switch (audioDriver)
2229 {
2230 case AudioDriverType_Null:
2231 {
2232 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
2233 break;
2234 }
2235#ifdef RT_OS_WINDOWS
2236#ifdef VBOX_WITH_WINMM
2237 case AudioDriverType_WinMM:
2238 {
2239 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
2240 break;
2241 }
2242#endif
2243 case AudioDriverType_DirectSound:
2244 {
2245 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
2246 break;
2247 }
2248#endif /* RT_OS_WINDOWS */
2249#ifdef RT_OS_SOLARIS
2250 case AudioDriverType_SolAudio:
2251 {
2252 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
2253 break;
2254 }
2255#endif
2256#ifdef RT_OS_LINUX
2257 case AudioDriverType_OSS:
2258 {
2259 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
2260 break;
2261 }
2262# ifdef VBOX_WITH_ALSA
2263 case AudioDriverType_ALSA:
2264 {
2265 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
2266 break;
2267 }
2268# endif
2269# ifdef VBOX_WITH_PULSE
2270 case AudioDriverType_Pulse:
2271 {
2272 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
2273 break;
2274 }
2275# endif
2276#endif /* RT_OS_LINUX */
2277#ifdef RT_OS_DARWIN
2278 case AudioDriverType_CoreAudio:
2279 {
2280 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
2281 break;
2282 }
2283#endif
2284 }
2285 hrc = pMachine->COMGETTER(Name)(&str); H();
2286 STR_CONV();
2287 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
2288 STR_FREE();
2289 }
2290
2291 /*
2292 * The USB Controller.
2293 */
2294 ComPtr<IUSBController> USBCtlPtr;
2295 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
2296 if (USBCtlPtr)
2297 {
2298 BOOL fEnabled;
2299 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
2300 if (fEnabled)
2301 {
2302 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
2303 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2304 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2305 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
2306 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
2307 Assert(!afPciDeviceNo[6]);
2308 afPciDeviceNo[6] = true;
2309 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2310
2311 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2312 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2313 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2314
2315 /*
2316 * Attach the status driver.
2317 */
2318 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2319 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2320 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2321 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
2322 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2323 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2324
2325#ifdef VBOX_WITH_EHCI
2326 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
2327 if (fEnabled)
2328 {
2329 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
2330 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2331 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2332 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2333 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
2334 Assert(!afPciDeviceNo[11]);
2335 afPciDeviceNo[11] = true;
2336 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2337
2338 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2339 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2340 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2341
2342 /*
2343 * Attach the status driver.
2344 */
2345 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2346 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2347 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2348 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
2349 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2350 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2351 }
2352 else
2353#endif
2354 {
2355 /*
2356 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
2357 * on a per device level now.
2358 */
2359 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
2360 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
2361 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
2362 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
2363 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
2364 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
2365 // that it's documented somewhere.) Users needing it can use:
2366 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
2367 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
2368 }
2369 }
2370 }
2371
2372 /*
2373 * Clipboard
2374 */
2375 {
2376 ClipboardMode_T mode = ClipboardMode_Disabled;
2377 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
2378
2379 if (mode != ClipboardMode_Disabled)
2380 {
2381 /* Load the service */
2382 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
2383
2384 if (RT_FAILURE (rc))
2385 {
2386 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
2387 /* That is not a fatal failure. */
2388 rc = VINF_SUCCESS;
2389 }
2390 else
2391 {
2392 /* Setup the service. */
2393 VBOXHGCMSVCPARM parm;
2394
2395 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2396
2397 switch (mode)
2398 {
2399 default:
2400 case ClipboardMode_Disabled:
2401 {
2402 LogRel(("VBoxSharedClipboard mode: Off\n"));
2403 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
2404 break;
2405 }
2406 case ClipboardMode_GuestToHost:
2407 {
2408 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
2409 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
2410 break;
2411 }
2412 case ClipboardMode_HostToGuest:
2413 {
2414 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
2415 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
2416 break;
2417 }
2418 case ClipboardMode_Bidirectional:
2419 {
2420 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
2421 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
2422 break;
2423 }
2424 }
2425
2426 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
2427
2428 Log(("Set VBoxSharedClipboard mode\n"));
2429 }
2430 }
2431 }
2432
2433#ifdef VBOX_WITH_CROGL
2434/* Currently broken on Snow Leopard 64-bit */
2435# if !(defined(RT_OS_DARWIN) && defined(RT_ARCH_AMD64))
2436 /*
2437 * crOpenGL
2438 */
2439 {
2440 BOOL fEnabled = false;
2441 hrc = pMachine->COMGETTER(Accelerate3DEnabled) (&fEnabled); H();
2442
2443 if (fEnabled)
2444 {
2445 /* Load the service */
2446 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
2447 if (RT_FAILURE(rc))
2448 {
2449 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
2450 /* That is not a fatal failure. */
2451 rc = VINF_SUCCESS;
2452 }
2453 else
2454 {
2455 LogRel(("Shared crOpenGL service loaded.\n"));
2456
2457 /* Setup the service. */
2458 VBOXHGCMSVCPARM parm;
2459 parm.type = VBOX_HGCM_SVC_PARM_PTR;
2460
2461 //parm.u.pointer.addr = static_cast <IConsole *> (pData->pVMMDev->getParent());
2462 parm.u.pointer.addr = pConsole->mVMMDev->getParent()->getDisplay()->getFramebuffer();
2463 parm.u.pointer.size = sizeof(IFramebuffer *);
2464
2465 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_FRAMEBUFFER, 1, &parm);
2466 if (!RT_SUCCESS(rc))
2467 AssertMsgFailed(("SHCRGL_HOST_FN_SET_FRAMEBUFFER failed with %Rrc\n", rc));
2468 }
2469 }
2470 }
2471# endif
2472#endif
2473
2474#ifdef VBOX_WITH_GUEST_PROPS
2475 /*
2476 * Guest property service
2477 */
2478 {
2479 /* Load the service */
2480 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
2481
2482 if (RT_FAILURE (rc))
2483 {
2484 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
2485 /* That is not a fatal failure. */
2486 rc = VINF_SUCCESS;
2487 }
2488 else
2489 {
2490 /* Pull over the properties from the server. */
2491 SafeArray <BSTR> namesOut;
2492 SafeArray <BSTR> valuesOut;
2493 SafeArray <ULONG64> timestampsOut;
2494 SafeArray <BSTR> flagsOut;
2495 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
2496 ComSafeArrayAsOutParam(valuesOut),
2497 ComSafeArrayAsOutParam(timestampsOut),
2498 ComSafeArrayAsOutParam(flagsOut)); H();
2499 size_t cProps = namesOut.size();
2500 if ( valuesOut.size() != cProps
2501 || timestampsOut.size() != cProps
2502 || flagsOut.size() != cProps
2503 )
2504 rc = VERR_INVALID_PARAMETER;
2505
2506 std::vector <Utf8Str> utf8Names, utf8Values, utf8Flags;
2507 std::vector <char *> names, values, flags;
2508 std::vector <ULONG64> timestamps;
2509 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2510 if ( !VALID_PTR(namesOut[i])
2511 || !VALID_PTR(valuesOut[i])
2512 || !VALID_PTR(flagsOut[i])
2513 )
2514 rc = VERR_INVALID_POINTER;
2515 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2516 {
2517 utf8Names.push_back(Bstr(namesOut[i]));
2518 utf8Values.push_back(Bstr(valuesOut[i]));
2519 timestamps.push_back(timestampsOut[i]);
2520 utf8Flags.push_back(Bstr(flagsOut[i]));
2521 if ( utf8Names.back().isNull()
2522 || utf8Values.back().isNull()
2523 || utf8Flags.back().isNull()
2524 )
2525 throw std::bad_alloc();
2526 }
2527 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2528 {
2529 names.push_back(utf8Names[i].mutableRaw());
2530 values.push_back(utf8Values[i].mutableRaw());
2531 flags.push_back(utf8Flags[i].mutableRaw());
2532 }
2533 names.push_back(NULL);
2534 values.push_back(NULL);
2535 timestamps.push_back(0);
2536 flags.push_back(NULL);
2537
2538 /* Setup the service. */
2539 VBOXHGCMSVCPARM parms[4];
2540
2541 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
2542 parms[0].u.pointer.addr = &names.front();
2543 parms[0].u.pointer.size = 0; /* We don't actually care. */
2544 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
2545 parms[1].u.pointer.addr = &values.front();
2546 parms[1].u.pointer.size = 0; /* We don't actually care. */
2547 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
2548 parms[2].u.pointer.addr = &timestamps.front();
2549 parms[2].u.pointer.size = 0; /* We don't actually care. */
2550 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
2551 parms[3].u.pointer.addr = &flags.front();
2552 parms[3].u.pointer.size = 0; /* We don't actually care. */
2553
2554 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4, &parms[0]);
2555
2556 /* Register the host notification callback */
2557 HGCMSVCEXTHANDLE hDummy;
2558 HGCMHostRegisterServiceExtension (&hDummy, "VBoxGuestPropSvc",
2559 Console::doGuestPropNotification,
2560 pvConsole);
2561
2562 Log(("Set VBoxGuestPropSvc property store\n"));
2563 }
2564 }
2565#endif /* VBOX_WITH_GUEST_PROPS defined */
2566
2567 /*
2568 * CFGM overlay handling.
2569 *
2570 * Here we check the extra data entries for CFGM values
2571 * and create the nodes and insert the values on the fly. Existing
2572 * values will be removed and reinserted. CFGM is typed, so by default
2573 * we will guess whether it's a string or an integer (byte arrays are
2574 * not currently supported). It's possible to override this autodetection
2575 * by adding "string:", "integer:" or "bytes:" (future).
2576 *
2577 * We first perform a run on global extra data, then on the machine
2578 * extra data to support global settings with local overrides.
2579 *
2580 */
2581 /** @todo add support for removing nodes and byte blobs. */
2582 Bstr strExtraDataKey;
2583 bool fGlobalExtraData = true;
2584 for (;;)
2585 {
2586 /*
2587 * Get the next key
2588 */
2589 Bstr strNextExtraDataKey;
2590 Bstr strExtraDataValue;
2591 if (fGlobalExtraData)
2592 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2593 strExtraDataValue.asOutParam());
2594 else
2595 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2596 strExtraDataValue.asOutParam());
2597
2598 /* stop if for some reason there's nothing more to request */
2599 if (FAILED(hrc) || !strNextExtraDataKey)
2600 {
2601 /* if we're out of global keys, continue with machine, otherwise we're done */
2602 if (fGlobalExtraData)
2603 {
2604 fGlobalExtraData = false;
2605 strExtraDataKey.setNull();
2606 continue;
2607 }
2608 break;
2609 }
2610 strExtraDataKey = strNextExtraDataKey;
2611
2612 /*
2613 * We only care about keys starting with "VBoxInternal/"
2614 */
2615 Utf8Str strExtraDataKeyUtf8(strExtraDataKey);
2616 char *pszExtraDataKey = (char *)strExtraDataKeyUtf8.raw();
2617 if (strncmp(pszExtraDataKey, "VBoxInternal/", sizeof("VBoxInternal/") - 1) != 0)
2618 continue;
2619 pszExtraDataKey += sizeof("VBoxInternal/") - 1;
2620
2621 /*
2622 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2623 * Split the two and get the node, delete the value and create the node
2624 * if necessary.
2625 */
2626 PCFGMNODE pNode;
2627 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2628 if (pszCFGMValueName)
2629 {
2630 /* terminate the node and advance to the value (Utf8Str might not
2631 offically like this but wtf) */
2632 *pszCFGMValueName = '\0';
2633 pszCFGMValueName++;
2634
2635 /* does the node already exist? */
2636 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2637 if (pNode)
2638 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2639 else
2640 {
2641 /* create the node */
2642 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2643 if (RT_FAILURE(rc))
2644 {
2645 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2646 continue;
2647 }
2648 Assert(pNode);
2649 }
2650 }
2651 else
2652 {
2653 /* root value (no node path). */
2654 pNode = pRoot;
2655 pszCFGMValueName = pszExtraDataKey;
2656 pszExtraDataKey--;
2657 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2658 }
2659
2660 /*
2661 * Now let's have a look at the value.
2662 * Empty strings means that we should remove the value, which we've
2663 * already done above.
2664 */
2665 Utf8Str strCFGMValueUtf8(strExtraDataValue);
2666 const char *pszCFGMValue = strCFGMValueUtf8.raw();
2667 if ( pszCFGMValue
2668 && *pszCFGMValue)
2669 {
2670 uint64_t u64Value;
2671
2672 /* check for type prefix first. */
2673 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
2674 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
2675 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
2676 {
2677 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
2678 if (RT_SUCCESS(rc))
2679 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2680 }
2681 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
2682 rc = VERR_NOT_IMPLEMENTED;
2683 /* auto detect type. */
2684 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
2685 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2686 else
2687 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
2688 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
2689 }
2690 }
2691
2692#undef H
2693#undef RC_CHECK
2694#undef STR_FREE
2695#undef STR_CONV
2696
2697 /* Register VM state change handler */
2698 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2699 AssertRC (rc2);
2700 if (RT_SUCCESS (rc))
2701 rc = rc2;
2702
2703 /* Register VM runtime error handler */
2704 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2705 AssertRC (rc2);
2706 if (RT_SUCCESS (rc))
2707 rc = rc2;
2708
2709 /* Save the VM pointer in the machine object */
2710 pConsole->mpVM = pVM;
2711
2712 LogFlowFunc (("vrc = %Rrc\n", rc));
2713 LogFlowFuncLeave();
2714
2715 return rc;
2716}
2717/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use