VirtualBox

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

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

NetworkAttachment: shifted the configuration to a new function configNetwork().

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