VirtualBox

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

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

Main: centralized control for extended device profiles, ACPI cleanup

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

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