VirtualBox

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

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

DHCP server/win: make it work again; NetFlt,Adp/win: IDC init polling

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

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