VirtualBox

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

Last change on this file since 21945 was 21916, checked in by vboxsync, 15 years ago

Main/GuestProperties: create guest properties for the VBox version and SVN revision at startup time

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

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