VirtualBox

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

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

ConsoleImpl2.cpp: r=bird: Who is gonna catch that std:bad_alloc() thow?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 128.1 KB
Line 
1/* $Id: ConsoleImpl2.cpp 21378 2009-07-08 01:17:51Z 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 BOOL fShowCpu = fExtProfile;
664 /* Always show the CPU leafs when we have multiple VCPUs or when the IO-APIC is enabled.
665 * The Windows SMP kernel needs a CPU leaf or else its idle loop will burn cpu cycles; the
666 * intelppm driver refuses to register an idle state handler.
667 */
668 if ((cCpus > 1) || fIOAPIC)
669 fShowCpu = true;
670
671 rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); RC_CHECK();
672 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
673 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
674 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
675 rc = CFGMR3InsertInteger(pCfg, "RamSize", cbRam); RC_CHECK();
676 rc = CFGMR3InsertInteger(pCfg, "RamHoleSize", cbRamHole); RC_CHECK();
677 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
678
679 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
680 rc = CFGMR3InsertInteger(pCfg, "FdcEnabled", fFdcEnabled); RC_CHECK();
681#ifdef VBOX_WITH_HPET
682 rc = CFGMR3InsertInteger(pCfg, "HpetEnabled", fHpetEnabled); RC_CHECK();
683#endif
684#ifdef VBOX_WITH_SMC
685 rc = CFGMR3InsertInteger(pCfg, "SmcEnabled", fSmcEnabled); RC_CHECK();
686#endif
687 rc = CFGMR3InsertInteger(pCfg, "ShowRtc", fExtProfile); RC_CHECK();
688
689 rc = CFGMR3InsertInteger(pCfg, "ShowCpu", fShowCpu); RC_CHECK();
690 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
691 Assert(!afPciDeviceNo[7]);
692 afPciDeviceNo[7] = true;
693 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
694
695 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
696 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
697 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
698 }
699
700 /*
701 * i8254 Programmable Interval Timer And Dummy Speaker
702 */
703 rc = CFGMR3InsertNode(pDevices, "i8254", &pDev); RC_CHECK();
704 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
705 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
706#ifdef DEBUG
707 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
708#endif
709
710 /*
711 * i8259 Programmable Interrupt Controller.
712 */
713 rc = CFGMR3InsertNode(pDevices, "i8259", &pDev); RC_CHECK();
714 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
715 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
716 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
717
718 /*
719 * Advanced Programmable Interrupt Controller.
720 * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
721 * thus only single insert
722 */
723 rc = CFGMR3InsertNode(pDevices, "apic", &pDev); RC_CHECK();
724 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
725 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
726 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
727 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
728 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
729
730 if (fIOAPIC)
731 {
732 /*
733 * I/O Advanced Programmable Interrupt Controller.
734 */
735 rc = CFGMR3InsertNode(pDevices, "ioapic", &pDev); RC_CHECK();
736 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
737 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
738 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
739 }
740
741 /*
742 * RTC MC146818.
743 */
744 rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); RC_CHECK();
745 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
746 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
747
748 /*
749 * VGA.
750 */
751 rc = CFGMR3InsertNode(pDevices, "vga", &pDev); RC_CHECK();
752 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
753 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
754 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 2); RC_CHECK();
755 Assert(!afPciDeviceNo[2]);
756 afPciDeviceNo[2] = true;
757 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
758 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
759 ULONG cVRamMBs;
760 hrc = pMachine->COMGETTER(VRAMSize)(&cVRamMBs); H();
761 rc = CFGMR3InsertInteger(pCfg, "VRamSize", cVRamMBs * _1M); RC_CHECK();
762#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
763 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", fHWVirtExEnabled); RC_CHECK();
764#endif
765
766 /*
767 * BIOS logo
768 */
769 BOOL fFadeIn;
770 hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
771 rc = CFGMR3InsertInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0); RC_CHECK();
772 BOOL fFadeOut;
773 hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
774 rc = CFGMR3InsertInteger(pCfg, "FadeOut", fFadeOut ? 1: 0); RC_CHECK();
775 ULONG logoDisplayTime;
776 hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
777 rc = CFGMR3InsertInteger(pCfg, "LogoTime", logoDisplayTime); RC_CHECK();
778 Bstr logoImagePath;
779 hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
780 rc = CFGMR3InsertString(pCfg, "LogoFile", logoImagePath ? Utf8Str(logoImagePath) : ""); RC_CHECK();
781
782 /*
783 * Boot menu
784 */
785 BIOSBootMenuMode_T bootMenuMode;
786 int value;
787 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
788 switch (bootMenuMode)
789 {
790 case BIOSBootMenuMode_Disabled:
791 value = 0;
792 break;
793 case BIOSBootMenuMode_MenuOnly:
794 value = 1;
795 break;
796 default:
797 value = 2;
798 }
799 rc = CFGMR3InsertInteger(pCfg, "ShowBootMenu", value); RC_CHECK();
800
801 /* Custom VESA mode list */
802 unsigned cModes = 0;
803 for (unsigned iMode = 1; iMode <= 16; iMode++)
804 {
805 char szExtraDataKey[sizeof("CustomVideoModeXX")];
806 RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%d", iMode);
807 hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), &str); H();
808 if (!str || !*str)
809 break;
810 STR_CONV();
811 rc = CFGMR3InsertString(pCfg, szExtraDataKey, psz);
812 STR_FREE();
813 cModes++;
814 }
815 rc = CFGMR3InsertInteger(pCfg, "CustomVideoModes", cModes);
816
817 /* VESA height reduction */
818 ULONG ulHeightReduction;
819 IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
820 if (pFramebuffer)
821 {
822 hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
823 }
824 else
825 {
826 /* If framebuffer is not available, there is no height reduction. */
827 ulHeightReduction = 0;
828 }
829 rc = CFGMR3InsertInteger(pCfg, "HeightReduction", ulHeightReduction); RC_CHECK();
830
831 /* Attach the display. */
832 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
833 rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay"); RC_CHECK();
834 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
835 Display *pDisplay = pConsole->mDisplay;
836 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pDisplay); RC_CHECK();
837
838 /*
839 * Storage controllers.
840 */
841 com::SafeIfaceArray<IStorageController> ctrls;
842 hrc = pMachine->
843 COMGETTER(StorageControllers) (ComSafeArrayAsOutParam (ctrls)); H();
844
845 for (size_t i = 0; i < ctrls.size(); ++ i)
846 {
847 PCFGMNODE pCtlInst = NULL; /* /Devices/<name>/0/ */
848 StorageControllerType_T enmCtrlType;
849 StorageBus_T enmBus;
850 bool fSCSI = false;
851 BSTR controllerName;
852
853 rc = ctrls[i]->COMGETTER(ControllerType)(&enmCtrlType); H();
854 rc = ctrls[i]->COMGETTER(Bus)(&enmBus); H();
855 rc = ctrls[i]->COMGETTER(Name)(&controllerName); H();
856
857 switch(enmCtrlType)
858 {
859 case StorageControllerType_LsiLogic:
860 {
861 rc = CFGMR3InsertNode(pDevices, "lsilogicscsi", &pDev); RC_CHECK();
862 rc = CFGMR3InsertNode(pDev, "0", &pCtlInst); RC_CHECK();
863 rc = CFGMR3InsertInteger(pCtlInst, "Trusted", 1); RC_CHECK();
864 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 20); RC_CHECK();
865 Assert(!afPciDeviceNo[20]);
866 afPciDeviceNo[20] = true;
867 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
868 rc = CFGMR3InsertNode(pCtlInst, "Config", &pCfg); RC_CHECK();
869 fSCSI = true;
870
871 /* Attach the status driver */
872 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
873 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
874 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
875 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSCSILeds[0]); RC_CHECK();
876 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
877 rc = CFGMR3InsertInteger(pCfg, "Last", 15); RC_CHECK();
878 break;
879 }
880 case StorageControllerType_BusLogic:
881 {
882 rc = CFGMR3InsertNode(pDevices, "buslogic", &pDev); RC_CHECK();
883 rc = CFGMR3InsertNode(pDev, "0", &pCtlInst); RC_CHECK();
884 rc = CFGMR3InsertInteger(pCtlInst, "Trusted", 1); RC_CHECK();
885 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 21); RC_CHECK();
886 Assert(!afPciDeviceNo[21]);
887 afPciDeviceNo[21] = true;
888 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
889 rc = CFGMR3InsertNode(pCtlInst, "Config", &pCfg); RC_CHECK();
890 fSCSI = true;
891
892 /* Attach the status driver */
893 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
894 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
895 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
896 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSCSILeds[0]); RC_CHECK();
897 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
898 rc = CFGMR3InsertInteger(pCfg, "Last", 15); RC_CHECK();
899 break;
900 }
901 case StorageControllerType_IntelAhci:
902 {
903 rc = CFGMR3InsertNode(pDevices, "ahci", &pDev); RC_CHECK();
904 rc = CFGMR3InsertNode(pDev, "0", &pCtlInst); RC_CHECK();
905 rc = CFGMR3InsertInteger(pCtlInst, "Trusted", 1); RC_CHECK();
906 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 13); RC_CHECK();
907 Assert(!afPciDeviceNo[13]);
908 afPciDeviceNo[13] = true;
909 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
910 rc = CFGMR3InsertNode(pCtlInst, "Config", &pCfg); RC_CHECK();
911
912 ULONG cPorts = 0;
913 hrc = ctrls[i]->COMGETTER(PortCount)(&cPorts); H();
914 rc = CFGMR3InsertInteger(pCfg, "PortCount", cPorts); RC_CHECK();
915
916 /* Needed configuration values for the bios. */
917 if (pBiosCfg)
918 {
919 rc = CFGMR3InsertString(pBiosCfg, "SataHardDiskDevice", "ahci"); RC_CHECK();
920 }
921
922 for (uint32_t j = 0; j < 4; j++)
923 {
924 static const char *s_apszConfig[4] =
925 { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
926 static const char *s_apszBiosConfig[4] =
927 { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
928
929 LONG lPortNumber = -1;
930 hrc = ctrls[i]->GetIDEEmulationPort(j, &lPortNumber); H();
931 rc = CFGMR3InsertInteger(pCfg, s_apszConfig[j], lPortNumber); RC_CHECK();
932 if (pBiosCfg)
933 {
934 rc = CFGMR3InsertInteger(pBiosCfg, s_apszBiosConfig[j], lPortNumber); RC_CHECK();
935 }
936 }
937
938 /* Attach the status driver */
939 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
940 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
941 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
942 AssertRelease(cPorts <= RT_ELEMENTS(pConsole->mapSATALeds));
943 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSATALeds[0]); RC_CHECK();
944 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
945 rc = CFGMR3InsertInteger(pCfg, "Last", cPorts - 1); RC_CHECK();
946 break;
947 }
948 case StorageControllerType_PIIX3:
949 case StorageControllerType_PIIX4:
950 case StorageControllerType_ICH6:
951 {
952 /*
953 * IDE (update this when the main interface changes)
954 */
955 rc = CFGMR3InsertNode(pDevices, "piix3ide", &pDev); /* piix3 */ RC_CHECK();
956 rc = CFGMR3InsertNode(pDev, "0", &pCtlInst); RC_CHECK();
957 rc = CFGMR3InsertInteger(pCtlInst, "Trusted", 1); /* boolean */ RC_CHECK();
958 rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 1); RC_CHECK();
959 Assert(!afPciDeviceNo[1]);
960 afPciDeviceNo[1] = true;
961 rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 1); RC_CHECK();
962 rc = CFGMR3InsertNode(pCtlInst, "Config", &pCfg); RC_CHECK();
963 rc = CFGMR3InsertString(pCfg, "Type", controllerString(enmCtrlType)); RC_CHECK();
964
965 /* Attach the status driver */
966 rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
967 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
968 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
969 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapIDELeds[0]);RC_CHECK();
970 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
971 rc = CFGMR3InsertInteger(pCfg, "Last", 3); RC_CHECK();
972
973 /*
974 * Attach the CD/DVD driver now
975 */
976 ComPtr<IDVDDrive> dvdDrive;
977 hrc = pMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam()); H();
978 if (dvdDrive)
979 {
980 // ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
981 rc = CFGMR3InsertNode(pCtlInst, "LUN#2", &pLunL0); RC_CHECK();
982 ComPtr<IHostDVDDrive> hostDvdDrive;
983 hrc = dvdDrive->GetHostDrive(hostDvdDrive.asOutParam()); H();
984 if (hostDvdDrive)
985 {
986 pConsole->meDVDState = DriveState_HostDriveCaptured;
987 rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
988 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
989 hrc = hostDvdDrive->COMGETTER(Name)(&str); H();
990 STR_CONV();
991 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
992 STR_FREE();
993 BOOL fPassthrough;
994 hrc = dvdDrive->COMGETTER(Passthrough)(&fPassthrough); H();
995 rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough); RC_CHECK();
996 }
997 else
998 {
999 pConsole->meDVDState = DriveState_NotMounted;
1000 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
1001 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1002 rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
1003 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
1004
1005 ComPtr<IDVDImage> dvdImage;
1006 hrc = dvdDrive->GetImage(dvdImage.asOutParam()); H();
1007 if (dvdImage)
1008 {
1009 pConsole->meDVDState = DriveState_ImageMounted;
1010 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1011 rc = CFGMR3InsertString(pLunL1, "Driver", "MediaISO"); RC_CHECK();
1012 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
1013 hrc = dvdImage->COMGETTER(Location)(&str); H();
1014 STR_CONV();
1015 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
1016 STR_FREE();
1017 }
1018 }
1019 }
1020 break;
1021 }
1022 default:
1023 AssertMsgFailed (("invalid storage controller type: "
1024 "%d\n", enmCtrlType));
1025 return VERR_GENERAL_FAILURE;
1026 }
1027
1028 /* At the moment we only support one controller per type. So the instance id is always 0. */
1029 rc = ctrls[i]->COMSETTER(Instance)(0); H();
1030
1031 /* Attach the hard disks. */
1032 com::SafeIfaceArray<IHardDiskAttachment> atts;
1033 hrc = pMachine->
1034 GetHardDiskAttachmentsOfController (controllerName,
1035 ComSafeArrayAsOutParam (atts)); H();
1036
1037 for (size_t j = 0; j < atts.size(); ++ j)
1038 {
1039 ComPtr<IHardDisk> hardDisk;
1040 hrc = atts [j]->COMGETTER(HardDisk) (hardDisk.asOutParam()); H();
1041 LONG lDev;
1042 hrc = atts [j]->COMGETTER(Device) (&lDev); H();
1043 LONG lPort;
1044 hrc = atts [j]->COMGETTER(Port) (&lPort); H();
1045
1046 int iLUN = 0;
1047
1048 switch (enmBus)
1049 {
1050 case StorageBus_IDE:
1051 {
1052 if (lPort >= 2 || lPort < 0)
1053 {
1054 AssertMsgFailed (("invalid controller channel number: "
1055 "%d\n", lPort));
1056 return VERR_GENERAL_FAILURE;
1057 }
1058
1059 if (lDev >= 2 || lDev < 0)
1060 {
1061 AssertMsgFailed (("invalid controller device number: "
1062 "%d\n", lDev));
1063 return VERR_GENERAL_FAILURE;
1064 }
1065
1066 iLUN = 2 * lPort + lDev;
1067 break;
1068 }
1069 case StorageBus_SATA:
1070 case StorageBus_SCSI:
1071 {
1072 iLUN = lPort;
1073 break;
1074 }
1075 default:
1076 {
1077 AssertMsgFailed (("invalid storage bus type: "
1078 "%d\n", enmBus));
1079 return VERR_GENERAL_FAILURE;
1080 }
1081 }
1082
1083 char szLUN[16];
1084 RTStrPrintf (szLUN, sizeof(szLUN), "LUN#%d", iLUN);
1085
1086 rc = CFGMR3InsertNode (pCtlInst, szLUN, &pLunL0); RC_CHECK();
1087 /* SCSI has a another driver between device and block. */
1088 if (fSCSI)
1089 {
1090 rc = CFGMR3InsertString (pLunL0, "Driver", "SCSI"); RC_CHECK();
1091 rc = CFGMR3InsertNode (pLunL0, "Config", &pCfg); RC_CHECK();
1092
1093 rc = CFGMR3InsertNode (pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1094 }
1095 rc = CFGMR3InsertString (pLunL0, "Driver", "Block"); RC_CHECK();
1096 rc = CFGMR3InsertNode (pLunL0, "Config", &pCfg); RC_CHECK();
1097 rc = CFGMR3InsertString (pCfg, "Type", "HardDisk"); RC_CHECK();
1098 rc = CFGMR3InsertInteger (pCfg, "Mountable", 0); RC_CHECK();
1099
1100 rc = CFGMR3InsertNode (pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1101 rc = CFGMR3InsertString (pLunL1, "Driver", "VD"); RC_CHECK();
1102 rc = CFGMR3InsertNode (pLunL1, "Config", &pCfg); RC_CHECK();
1103
1104 hrc = hardDisk->COMGETTER(Location) (bstr.asOutParam()); H();
1105 rc = CFGMR3InsertString (pCfg, "Path", Utf8Str (bstr)); RC_CHECK();
1106
1107 hrc = hardDisk->COMGETTER(Format) (bstr.asOutParam()); H();
1108 rc = CFGMR3InsertString (pCfg, "Format", Utf8Str (bstr)); RC_CHECK();
1109
1110 /* Pass all custom parameters. */
1111 bool fHostIP = true;
1112 SafeArray <BSTR> names;
1113 SafeArray <BSTR> values;
1114 hrc = hardDisk->GetProperties (NULL,
1115 ComSafeArrayAsOutParam (names),
1116 ComSafeArrayAsOutParam (values)); H();
1117
1118 if (names.size() != 0)
1119 {
1120 PCFGMNODE pVDC;
1121 rc = CFGMR3InsertNode (pCfg, "VDConfig", &pVDC); RC_CHECK();
1122 for (size_t ii = 0; ii < names.size(); ++ ii)
1123 {
1124 if (values[ii] && *values[ii])
1125 {
1126 Utf8Str name = names [ii];
1127 Utf8Str value = values [ii];
1128 rc = CFGMR3InsertString (pVDC, name, value);
1129 if ( !(name.compare("HostIPStack"))
1130 && !(value.compare("0")))
1131 fHostIP = false;
1132 }
1133 }
1134 }
1135
1136 /* Create an inversed tree of parents. */
1137 ComPtr<IHardDisk> parentHardDisk = hardDisk;
1138 for (PCFGMNODE pParent = pCfg;;)
1139 {
1140 hrc = parentHardDisk->
1141 COMGETTER(Parent) (hardDisk.asOutParam()); H();
1142 if (hardDisk.isNull())
1143 break;
1144
1145 PCFGMNODE pCur;
1146 rc = CFGMR3InsertNode (pParent, "Parent", &pCur); RC_CHECK();
1147 hrc = hardDisk->COMGETTER(Location) (bstr.asOutParam()); H();
1148 rc = CFGMR3InsertString (pCur, "Path", Utf8Str (bstr)); RC_CHECK();
1149
1150 hrc = hardDisk->COMGETTER(Format) (bstr.asOutParam()); H();
1151 rc = CFGMR3InsertString (pCur, "Format", Utf8Str (bstr)); RC_CHECK();
1152
1153 /* Pass all custom parameters. */
1154 SafeArray <BSTR> names;
1155 SafeArray <BSTR> values;
1156 hrc = hardDisk->GetProperties (NULL,
1157 ComSafeArrayAsOutParam (names),
1158 ComSafeArrayAsOutParam (values));H();
1159
1160 if (names.size() != 0)
1161 {
1162 PCFGMNODE pVDC;
1163 rc = CFGMR3InsertNode (pCur, "VDConfig", &pVDC); RC_CHECK();
1164 for (size_t ii = 0; ii < names.size(); ++ ii)
1165 {
1166 if (values [ii])
1167 {
1168 Utf8Str name = names [ii];
1169 Utf8Str value = values [ii];
1170 rc = CFGMR3InsertString (pVDC, name, value);
1171 if ( !(name.compare("HostIPStack"))
1172 && !(value.compare("0")))
1173 fHostIP = false;
1174 }
1175 }
1176 }
1177
1178 /* Custom code: put marker to not use host IP stack to driver
1179 * configuration node. Simplifies life of DrvVD a bit. */
1180 if (!fHostIP)
1181 {
1182 rc = CFGMR3InsertInteger (pCfg, "HostIPStack", 0); RC_CHECK();
1183 }
1184
1185 /* next */
1186 pParent = pCur;
1187 parentHardDisk = hardDisk;
1188 }
1189 }
1190 H();
1191 }
1192 H();
1193
1194 /*
1195 * Network adapters
1196 */
1197#ifdef VMWARE_NET_IN_SLOT_11
1198 bool fSwapSlots3and11 = false;
1199#endif
1200 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
1201 rc = CFGMR3InsertNode(pDevices, "pcnet", &pDevPCNet); RC_CHECK();
1202#ifdef VBOX_WITH_E1000
1203 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
1204 rc = CFGMR3InsertNode(pDevices, "e1000", &pDevE1000); RC_CHECK();
1205#endif
1206 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ulInstance++)
1207 {
1208 ComPtr<INetworkAdapter> networkAdapter;
1209 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
1210 BOOL fEnabled = FALSE;
1211 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
1212 if (!fEnabled)
1213 continue;
1214
1215 /*
1216 * The virtual hardware type. Create appropriate device first.
1217 */
1218 const char *pszAdapterName = "pcnet";
1219 NetworkAdapterType_T adapterType;
1220 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
1221 switch (adapterType)
1222 {
1223 case NetworkAdapterType_Am79C970A:
1224 case NetworkAdapterType_Am79C973:
1225 pDev = pDevPCNet;
1226 break;
1227#ifdef VBOX_WITH_E1000
1228 case NetworkAdapterType_I82540EM:
1229 case NetworkAdapterType_I82543GC:
1230 case NetworkAdapterType_I82545EM:
1231 pDev = pDevE1000;
1232 pszAdapterName = "e1000";
1233 break;
1234#endif
1235 default:
1236 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
1237 adapterType, ulInstance));
1238 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1239 N_("Invalid network adapter type '%d' for slot '%d'"),
1240 adapterType, ulInstance);
1241 }
1242
1243 char szInstance[4]; Assert(ulInstance <= 999);
1244 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1245 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1246 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1247 /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
1248 * next 4 get 16..19. */
1249 unsigned iPciDeviceNo = 3;
1250 if (ulInstance)
1251 {
1252 if (ulInstance < 4)
1253 iPciDeviceNo = ulInstance - 1 + 8;
1254 else
1255 iPciDeviceNo = ulInstance - 4 + 16;
1256 }
1257#ifdef VMWARE_NET_IN_SLOT_11
1258 /*
1259 * Dirty hack for PCI slot compatibility with VMWare,
1260 * it assigns slot 11 to the first network controller.
1261 */
1262 if (iPciDeviceNo == 3 && adapterType == NetworkAdapterType_I82545EM)
1263 {
1264 iPciDeviceNo = 0x11;
1265 fSwapSlots3and11 = true;
1266 }
1267 else if (iPciDeviceNo == 0x11 && fSwapSlots3and11)
1268 iPciDeviceNo = 3;
1269#endif
1270 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
1271 Assert(!afPciDeviceNo[iPciDeviceNo]);
1272 afPciDeviceNo[iPciDeviceNo] = true;
1273 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1274 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1275#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
1276 if (pDev == pDevPCNet)
1277 {
1278 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", false); RC_CHECK();
1279 }
1280#endif
1281
1282 /*
1283 * The virtual hardware type. PCNet supports two types.
1284 */
1285 switch (adapterType)
1286 {
1287 case NetworkAdapterType_Am79C970A:
1288 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
1289 break;
1290 case NetworkAdapterType_Am79C973:
1291 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
1292 break;
1293 case NetworkAdapterType_I82540EM:
1294 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
1295 break;
1296 case NetworkAdapterType_I82543GC:
1297 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
1298 break;
1299 case NetworkAdapterType_I82545EM:
1300 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 2); RC_CHECK();
1301 break;
1302 }
1303
1304 /*
1305 * Get the MAC address and convert it to binary representation
1306 */
1307 Bstr macAddr;
1308 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1309 Assert(macAddr);
1310 Utf8Str macAddrUtf8 = macAddr;
1311 char *macStr = (char*)macAddrUtf8.raw();
1312 Assert(strlen(macStr) == 12);
1313 RTMAC Mac;
1314 memset(&Mac, 0, sizeof(Mac));
1315 char *pMac = (char*)&Mac;
1316 for (uint32_t i = 0; i < 6; i++)
1317 {
1318 char c1 = *macStr++ - '0';
1319 if (c1 > 9)
1320 c1 -= 7;
1321 char c2 = *macStr++ - '0';
1322 if (c2 > 9)
1323 c2 -= 7;
1324 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1325 }
1326 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1327
1328 /*
1329 * Check if the cable is supposed to be unplugged
1330 */
1331 BOOL fCableConnected;
1332 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1333 rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
1334
1335 /*
1336 * Line speed to report from custom drivers
1337 */
1338 ULONG ulLineSpeed;
1339 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1340 rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
1341
1342 /*
1343 * Attach the status driver.
1344 */
1345 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1346 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1347 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1348 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
1349
1350 /*
1351 * Configure the network card now
1352 */
1353
1354 rc = configNetwork(pConsole, pszAdapterName, ulInstance, 0, networkAdapter, pCfg, pLunL0, pInst, false);
1355 RC_CHECK();
1356 }
1357
1358 /*
1359 * Serial (UART) Ports
1360 */
1361 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1362 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1363 {
1364 ComPtr<ISerialPort> serialPort;
1365 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1366 BOOL fEnabled = FALSE;
1367 if (serialPort)
1368 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1369 if (!fEnabled)
1370 continue;
1371
1372 char szInstance[4]; Assert(ulInstance <= 999);
1373 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1374
1375 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1376 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1377
1378 ULONG ulIRQ, ulIOBase;
1379 PortMode_T HostMode;
1380 Bstr path;
1381 BOOL fServer;
1382 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1383 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1384 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1385 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1386 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1387 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1388 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1389 if (HostMode != PortMode_Disconnected)
1390 {
1391 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1392 if (HostMode == PortMode_HostPipe)
1393 {
1394 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1395 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1396 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1397 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1398 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1399 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1400 }
1401 else if (HostMode == PortMode_HostDevice)
1402 {
1403 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1404 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1405 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1406 }
1407 else if (HostMode == PortMode_RawFile)
1408 {
1409 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1410 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1411 rc = CFGMR3InsertString(pLunL1, "Driver", "RawFile"); RC_CHECK();
1412 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1413 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1414 }
1415 }
1416 }
1417
1418 /*
1419 * Parallel (LPT) Ports
1420 */
1421 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1422 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1423 {
1424 ComPtr<IParallelPort> parallelPort;
1425 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1426 BOOL fEnabled = FALSE;
1427 if (parallelPort)
1428 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1429 if (!fEnabled)
1430 continue;
1431
1432 char szInstance[4]; Assert(ulInstance <= 999);
1433 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1434
1435 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1436 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1437
1438 ULONG ulIRQ, ulIOBase;
1439 Bstr DevicePath;
1440 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1441 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1442 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1443 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1444 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1445 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1446 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1447 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1448 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1449 }
1450
1451 /*
1452 * VMM Device
1453 */
1454 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1455 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1456 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1457 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1458 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1459 Assert(!afPciDeviceNo[4]);
1460 afPciDeviceNo[4] = true;
1461 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1462 Bstr hwVersion;
1463 hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
1464 if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
1465 {
1466 CFGMR3InsertInteger(pCfg, "HeapEnabled", 0); RC_CHECK();
1467 }
1468
1469 /* the VMM device's Main driver */
1470 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1471 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1472 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1473 VMMDev *pVMMDev = pConsole->mVMMDev;
1474 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1475
1476 /*
1477 * Attach the status driver.
1478 */
1479 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1480 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1481 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1482 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1483 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1484 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1485
1486 /*
1487 * Audio Sniffer Device
1488 */
1489 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1490 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1491 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1492
1493 /* the Audio Sniffer device's Main driver */
1494 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1495 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1496 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1497 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1498 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1499
1500 /*
1501 * AC'97 ICH / SoundBlaster16 audio
1502 */
1503 BOOL enabled;
1504 ComPtr<IAudioAdapter> audioAdapter;
1505 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1506 if (audioAdapter)
1507 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1508
1509 if (enabled)
1510 {
1511 AudioControllerType_T audioController;
1512 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
1513 switch (audioController)
1514 {
1515 case AudioControllerType_AC97:
1516 {
1517 /* default: ICH AC97 */
1518 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
1519 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1520 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1521 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1522 Assert(!afPciDeviceNo[5]);
1523 afPciDeviceNo[5] = true;
1524 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1525 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1526 break;
1527 }
1528 case AudioControllerType_SB16:
1529 {
1530 /* legacy SoundBlaster16 */
1531 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
1532 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1533 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1534 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1535 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
1536 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
1537 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
1538 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
1539 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
1540 break;
1541 }
1542 }
1543
1544 /* the Audio driver */
1545 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1546 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1547 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1548
1549 AudioDriverType_T audioDriver;
1550 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1551 switch (audioDriver)
1552 {
1553 case AudioDriverType_Null:
1554 {
1555 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1556 break;
1557 }
1558#ifdef RT_OS_WINDOWS
1559#ifdef VBOX_WITH_WINMM
1560 case AudioDriverType_WinMM:
1561 {
1562 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1563 break;
1564 }
1565#endif
1566 case AudioDriverType_DirectSound:
1567 {
1568 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
1569 break;
1570 }
1571#endif /* RT_OS_WINDOWS */
1572#ifdef RT_OS_SOLARIS
1573 case AudioDriverType_SolAudio:
1574 {
1575 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
1576 break;
1577 }
1578#endif
1579#ifdef RT_OS_LINUX
1580# ifdef VBOX_WITH_ALSA
1581 case AudioDriverType_ALSA:
1582 {
1583 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
1584 break;
1585 }
1586# endif
1587# ifdef VBOX_WITH_PULSE
1588 case AudioDriverType_Pulse:
1589 {
1590 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
1591 break;
1592 }
1593# endif
1594#endif /* RT_OS_LINUX */
1595#if defined (RT_OS_LINUX) || defined (RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
1596 case AudioDriverType_OSS:
1597 {
1598 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
1599 break;
1600 }
1601#endif
1602#ifdef RT_OS_DARWIN
1603 case AudioDriverType_CoreAudio:
1604 {
1605 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1606 break;
1607 }
1608#endif
1609 }
1610 hrc = pMachine->COMGETTER(Name)(&str); H();
1611 STR_CONV();
1612 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
1613 STR_FREE();
1614 }
1615
1616 /*
1617 * The USB Controller.
1618 */
1619 ComPtr<IUSBController> USBCtlPtr;
1620 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1621 if (USBCtlPtr)
1622 {
1623 BOOL fEnabled;
1624 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1625 if (fEnabled)
1626 {
1627 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
1628 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1629 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1630 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1631 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
1632 Assert(!afPciDeviceNo[6]);
1633 afPciDeviceNo[6] = true;
1634 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1635
1636 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1637 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1638 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1639
1640 /*
1641 * Attach the status driver.
1642 */
1643 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1644 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1645 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1646 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
1647 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1648 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1649
1650#ifdef VBOX_WITH_EHCI
1651 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
1652 if (fEnabled)
1653 {
1654 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
1655 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1656 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1657 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1658 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
1659 Assert(!afPciDeviceNo[11]);
1660 afPciDeviceNo[11] = true;
1661 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1662
1663 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1664 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1665 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1666
1667 /*
1668 * Attach the status driver.
1669 */
1670 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1671 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1672 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1673 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
1674 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1675 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1676 }
1677 else
1678#endif
1679 {
1680 /*
1681 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
1682 * on a per device level now.
1683 */
1684 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
1685 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
1686 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
1687 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
1688 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
1689 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
1690 // that it's documented somewhere.) Users needing it can use:
1691 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
1692 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
1693 }
1694 }
1695 }
1696
1697 /*
1698 * Clipboard
1699 */
1700 {
1701 ClipboardMode_T mode = ClipboardMode_Disabled;
1702 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
1703
1704 if (mode != ClipboardMode_Disabled)
1705 {
1706 /* Load the service */
1707 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
1708
1709 if (RT_FAILURE (rc))
1710 {
1711 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
1712 /* That is not a fatal failure. */
1713 rc = VINF_SUCCESS;
1714 }
1715 else
1716 {
1717 /* Setup the service. */
1718 VBOXHGCMSVCPARM parm;
1719
1720 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
1721
1722 switch (mode)
1723 {
1724 default:
1725 case ClipboardMode_Disabled:
1726 {
1727 LogRel(("VBoxSharedClipboard mode: Off\n"));
1728 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
1729 break;
1730 }
1731 case ClipboardMode_GuestToHost:
1732 {
1733 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
1734 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
1735 break;
1736 }
1737 case ClipboardMode_HostToGuest:
1738 {
1739 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
1740 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
1741 break;
1742 }
1743 case ClipboardMode_Bidirectional:
1744 {
1745 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
1746 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
1747 break;
1748 }
1749 }
1750
1751 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
1752
1753 Log(("Set VBoxSharedClipboard mode\n"));
1754 }
1755 }
1756 }
1757
1758#ifdef VBOX_WITH_CROGL
1759/* Currently broken on Snow Leopard 64-bit */
1760# if !(defined(RT_OS_DARWIN) && defined(RT_ARCH_AMD64))
1761 /*
1762 * crOpenGL
1763 */
1764 {
1765 BOOL fEnabled = false;
1766 hrc = pMachine->COMGETTER(Accelerate3DEnabled) (&fEnabled); H();
1767
1768 if (fEnabled)
1769 {
1770 /* Load the service */
1771 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
1772 if (RT_FAILURE(rc))
1773 {
1774 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
1775 /* That is not a fatal failure. */
1776 rc = VINF_SUCCESS;
1777 }
1778 else
1779 {
1780 LogRel(("Shared crOpenGL service loaded.\n"));
1781
1782 /* Setup the service. */
1783 VBOXHGCMSVCPARM parm;
1784 parm.type = VBOX_HGCM_SVC_PARM_PTR;
1785
1786 //parm.u.pointer.addr = static_cast <IConsole *> (pData->pVMMDev->getParent());
1787 parm.u.pointer.addr = pConsole->mVMMDev->getParent()->getDisplay()->getFramebuffer();
1788 parm.u.pointer.size = sizeof(IFramebuffer *);
1789
1790 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_FRAMEBUFFER, 1, &parm);
1791 if (!RT_SUCCESS(rc))
1792 AssertMsgFailed(("SHCRGL_HOST_FN_SET_FRAMEBUFFER failed with %Rrc\n", rc));
1793 }
1794 }
1795 }
1796# endif
1797#endif
1798
1799#ifdef VBOX_WITH_GUEST_PROPS
1800 /*
1801 * Guest property service
1802 */
1803 {
1804 /* Load the service */
1805 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
1806
1807 if (RT_FAILURE (rc))
1808 {
1809 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
1810 /* That is not a fatal failure. */
1811 rc = VINF_SUCCESS;
1812 }
1813 else
1814 {
1815 /* Pull over the properties from the server. */
1816 SafeArray<BSTR> namesOut;
1817 SafeArray<BSTR> valuesOut;
1818 SafeArray<ULONG64> timestampsOut;
1819 SafeArray<BSTR> flagsOut;
1820 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
1821 ComSafeArrayAsOutParam(valuesOut),
1822 ComSafeArrayAsOutParam(timestampsOut),
1823 ComSafeArrayAsOutParam(flagsOut)); H();
1824 size_t cProps = namesOut.size();
1825 if ( valuesOut.size() != cProps
1826 || timestampsOut.size() != cProps
1827 || flagsOut.size() != cProps
1828 )
1829 rc = VERR_INVALID_PARAMETER;
1830
1831 std::vector<Utf8Str> utf8Names, utf8Values, utf8Flags;
1832 std::vector<char *> names, values, flags;
1833 std::vector<ULONG64> timestamps;
1834 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
1835 if ( !VALID_PTR(namesOut[i])
1836 || !VALID_PTR(valuesOut[i])
1837 || !VALID_PTR(flagsOut[i])
1838 )
1839 rc = VERR_INVALID_POINTER;
1840 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
1841 {
1842 utf8Names.push_back(Bstr(namesOut[i]));
1843 utf8Values.push_back(Bstr(valuesOut[i]));
1844 timestamps.push_back(timestampsOut[i]);
1845 utf8Flags.push_back(Bstr(flagsOut[i]));
1846#if 0 /** @todo r=bird: Who is gonna catch this? Why does it trigger now? */
1847 if ( utf8Names.back().isNull()
1848 || utf8Values.back().isNull()
1849 || utf8Flags.back().isNull()
1850 )
1851 throw std::bad_alloc();
1852#endif
1853 }
1854 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
1855 {
1856 names.push_back(utf8Names[i].mutableRaw());
1857 values.push_back(utf8Values[i].mutableRaw());
1858 flags.push_back(utf8Flags[i].mutableRaw());
1859 }
1860 names.push_back(NULL);
1861 values.push_back(NULL);
1862 timestamps.push_back(0);
1863 flags.push_back(NULL);
1864
1865 /* Setup the service. */
1866 VBOXHGCMSVCPARM parms[4];
1867
1868 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
1869 parms[0].u.pointer.addr = &names.front();
1870 parms[0].u.pointer.size = 0; /* We don't actually care. */
1871 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
1872 parms[1].u.pointer.addr = &values.front();
1873 parms[1].u.pointer.size = 0; /* We don't actually care. */
1874 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
1875 parms[2].u.pointer.addr = &timestamps.front();
1876 parms[2].u.pointer.size = 0; /* We don't actually care. */
1877 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
1878 parms[3].u.pointer.addr = &flags.front();
1879 parms[3].u.pointer.size = 0; /* We don't actually care. */
1880
1881 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4, &parms[0]);
1882
1883 /* Register the host notification callback */
1884 HGCMSVCEXTHANDLE hDummy;
1885 HGCMHostRegisterServiceExtension (&hDummy, "VBoxGuestPropSvc",
1886 Console::doGuestPropNotification,
1887 pvConsole);
1888
1889 Log(("Set VBoxGuestPropSvc property store\n"));
1890 }
1891 }
1892#endif /* VBOX_WITH_GUEST_PROPS defined */
1893
1894 /*
1895 * CFGM overlay handling.
1896 *
1897 * Here we check the extra data entries for CFGM values
1898 * and create the nodes and insert the values on the fly. Existing
1899 * values will be removed and reinserted. CFGM is typed, so by default
1900 * we will guess whether it's a string or an integer (byte arrays are
1901 * not currently supported). It's possible to override this autodetection
1902 * by adding "string:", "integer:" or "bytes:" (future).
1903 *
1904 * We first perform a run on global extra data, then on the machine
1905 * extra data to support global settings with local overrides.
1906 *
1907 */
1908 /** @todo add support for removing nodes and byte blobs. */
1909 Bstr strExtraDataKey;
1910 bool fGlobalExtraData = true;
1911 for (;;)
1912 {
1913 /*
1914 * Get the next key
1915 */
1916 Bstr strNextExtraDataKey;
1917 Bstr strExtraDataValue;
1918 if (fGlobalExtraData)
1919 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1920 strExtraDataValue.asOutParam());
1921 else
1922 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
1923 strExtraDataValue.asOutParam());
1924
1925 /* stop if for some reason there's nothing more to request */
1926 if (FAILED(hrc) || strNextExtraDataKey.isEmpty())
1927 {
1928 /* if we're out of global keys, continue with machine, otherwise we're done */
1929 if (fGlobalExtraData)
1930 {
1931 fGlobalExtraData = false;
1932 strExtraDataKey.setNull();
1933 continue;
1934 }
1935 break;
1936 }
1937 strExtraDataKey = strNextExtraDataKey;
1938
1939 /*
1940 * We only care about keys starting with "VBoxInternal/"
1941 */
1942 Utf8Str strExtraDataKeyUtf8(strExtraDataKey);
1943 char *pszExtraDataKey = (char *)strExtraDataKeyUtf8.raw();
1944 if (strncmp(pszExtraDataKey, "VBoxInternal/", sizeof("VBoxInternal/") - 1) != 0)
1945 continue;
1946 pszExtraDataKey += sizeof("VBoxInternal/") - 1;
1947
1948 /*
1949 * The key will be in the format "Node1/Node2/Value" or simply "Value".
1950 * Split the two and get the node, delete the value and create the node
1951 * if necessary.
1952 */
1953 PCFGMNODE pNode;
1954 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
1955 if (pszCFGMValueName)
1956 {
1957 /* terminate the node and advance to the value (Utf8Str might not
1958 offically like this but wtf) */
1959 *pszCFGMValueName = '\0';
1960 pszCFGMValueName++;
1961
1962 /* does the node already exist? */
1963 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
1964 if (pNode)
1965 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1966 else
1967 {
1968 /* create the node */
1969 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
1970 if (RT_FAILURE(rc))
1971 {
1972 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
1973 continue;
1974 }
1975 Assert(pNode);
1976 }
1977 }
1978 else
1979 {
1980 /* root value (no node path). */
1981 pNode = pRoot;
1982 pszCFGMValueName = pszExtraDataKey;
1983 pszExtraDataKey--;
1984 CFGMR3RemoveValue(pNode, pszCFGMValueName);
1985 }
1986
1987 /*
1988 * Now let's have a look at the value.
1989 * Empty strings means that we should remove the value, which we've
1990 * already done above.
1991 */
1992 Utf8Str strCFGMValueUtf8(strExtraDataValue);
1993 const char *pszCFGMValue = strCFGMValueUtf8.raw();
1994 if ( pszCFGMValue
1995 && *pszCFGMValue)
1996 {
1997 uint64_t u64Value;
1998
1999 /* check for type prefix first. */
2000 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
2001 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
2002 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
2003 {
2004 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
2005 if (RT_SUCCESS(rc))
2006 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2007 }
2008 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
2009 rc = VERR_NOT_IMPLEMENTED;
2010 /* auto detect type. */
2011 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
2012 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2013 else
2014 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
2015 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
2016 }
2017 }
2018
2019#undef H
2020#undef RC_CHECK
2021#undef STR_FREE
2022#undef STR_CONV
2023
2024 /* Register VM state change handler */
2025 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2026 AssertRC (rc2);
2027 if (RT_SUCCESS (rc))
2028 rc = rc2;
2029
2030 /* Register VM runtime error handler */
2031 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2032 AssertRC (rc2);
2033 if (RT_SUCCESS (rc))
2034 rc = rc2;
2035
2036 /* Save the VM pointer in the machine object */
2037 pConsole->mpVM = pVM;
2038
2039 LogFlowFunc (("vrc = %Rrc\n", rc));
2040 LogFlowFuncLeave();
2041
2042 return rc;
2043}
2044
2045
2046/**
2047 * Construct the Network configuration tree
2048 *
2049 * @returns VBox status code.
2050 *
2051 * @param pThis Pointer to the Console object.
2052 * @param pszDevice The PDM device name.
2053 * @param uInstance The PDM device instance.
2054 * @param uLun The PDM LUN number of the drive.
2055 * @param aNetworkAdapter The network adapter whose attachment needs to be changed
2056 *
2057 * @note Locks the Console object for writing.
2058 */
2059DECLCALLBACK(int) Console::configNetwork(Console *pThis, const char *pszDevice,
2060 unsigned uInstance, unsigned uLun,
2061 INetworkAdapter *aNetworkAdapter,
2062 PCFGMNODE pCfg, PCFGMNODE pLunL0,
2063 PCFGMNODE pInst, bool attachDetach)
2064{
2065 int rc = VINF_SUCCESS;
2066 int rcRet = VINF_SUCCESS;
2067
2068 AutoCaller autoCaller (pThis);
2069 AssertComRCReturn (autoCaller.rc(), VERR_ACCESS_DENIED);
2070
2071 /*
2072 * Locking the object before doing VMR3* calls is quite safe here, since
2073 * we're on EMT. Write lock is necessary because we indirectly modify the
2074 * meAttachmentType member.
2075 */
2076 AutoWriteLock alock (pThis);
2077
2078 PVM pVM = pThis->mpVM;
2079
2080#define STR_CONV() do { rc = RTUtf16ToUtf8(str, &psz); RC_CHECK(); } while (0)
2081#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } if (psz) { RTStrFree(psz); psz = NULL; } } while (0)
2082#define RC_CHECK() do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc)); return rc; } } while (0)
2083#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); return VERR_GENERAL_FAILURE; } } while (0)
2084 do
2085 {
2086 HRESULT hrc;
2087 ComPtr <IMachine> pMachine = pThis->machine();
2088
2089 ComPtr<IVirtualBox> virtualBox;
2090 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam());
2091 H();
2092
2093 ComPtr<IHost> host;
2094 hrc = virtualBox->COMGETTER(Host)(host.asOutParam());
2095 H();
2096
2097 BSTR str = NULL;
2098 char *psz = NULL;
2099
2100 /*
2101 * Detach the device train for the current network attachment.
2102 */
2103
2104 if (attachDetach)
2105 {
2106 rc = PDMR3DeviceDetach (pVM, pszDevice, uInstance, uLun, PDMDEVATT_FLAGS_NOT_HOT_PLUG);
2107 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
2108 rc = VINF_SUCCESS;
2109 AssertRC (rc);
2110
2111 /* nuke anything which might have been left behind. */
2112 CFGMR3RemoveNode (CFGMR3GetChildF (pInst, "LUN#%d", uLun));
2113 }
2114
2115 /*
2116 * Enable the packet sniffer if requested.
2117 */
2118 BOOL fSniffer;
2119 hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer);
2120 H();
2121 if (fSniffer)
2122 {
2123 /* insert the sniffer filter driver. */
2124 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2125 RC_CHECK();
2126 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer");
2127 RC_CHECK();
2128 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2129 RC_CHECK();
2130 hrc = aNetworkAdapter->COMGETTER(TraceFile)(&str);
2131 H();
2132 if (str) /* check convention for indicating default file. */
2133 {
2134 STR_CONV();
2135 rc = CFGMR3InsertString(pCfg, "File", psz);
2136 RC_CHECK();
2137 STR_FREE();
2138 }
2139 }
2140
2141 Bstr networkName, trunkName, trunkType;
2142 NetworkAttachmentType_T eAttachmentType;
2143 hrc = aNetworkAdapter->COMGETTER(AttachmentType)(&eAttachmentType);
2144 H();
2145 switch (eAttachmentType)
2146 {
2147 case NetworkAttachmentType_Null:
2148 break;
2149
2150 case NetworkAttachmentType_NAT:
2151 {
2152 if (fSniffer)
2153 {
2154 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2155 RC_CHECK();
2156 }
2157 else
2158 {
2159 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2160 RC_CHECK();
2161 }
2162
2163 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT");
2164 RC_CHECK();
2165
2166 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2167 RC_CHECK();
2168
2169 /* Configure TFTP prefix and boot filename. */
2170 hrc = virtualBox->COMGETTER(HomeFolder)(&str);
2171 H();
2172 STR_CONV();
2173 if (psz && *psz)
2174 {
2175 char *pszTFTPPrefix = NULL;
2176 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
2177 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix);
2178 RC_CHECK();
2179 RTStrFree(pszTFTPPrefix);
2180 }
2181 STR_FREE();
2182 hrc = pMachine->COMGETTER(Name)(&str);
2183 H();
2184 STR_CONV();
2185 char *pszBootFile = NULL;
2186 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
2187 STR_FREE();
2188 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile);
2189 RC_CHECK();
2190 RTStrFree(pszBootFile);
2191
2192 hrc = aNetworkAdapter->COMGETTER(NATNetwork)(&str);
2193 H();
2194 if (str)
2195 {
2196 STR_CONV();
2197 if (psz && *psz)
2198 {
2199 rc = CFGMR3InsertString(pCfg, "Network", psz);
2200 RC_CHECK();
2201 /* NAT uses its own DHCP implementation */
2202 //networkName = Bstr(psz);
2203 }
2204
2205 STR_FREE();
2206 }
2207 break;
2208 }
2209
2210 case NetworkAttachmentType_Bridged:
2211 {
2212#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
2213 Assert ((int)pThis->maTapFD[uInstance] >= 0);
2214 if ((int)pThis->maTapFD[uInstance] >= 0)
2215 {
2216 if (fSniffer)
2217 {
2218 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2219 RC_CHECK();
2220 }
2221 else
2222 {
2223 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2224 RC_CHECK();
2225 }
2226 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface");
2227 RC_CHECK();
2228 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2229 RC_CHECK();
2230 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pThis->maTapFD[uInstance]);
2231 RC_CHECK();
2232 }
2233#elif defined(VBOX_WITH_NETFLT)
2234 /*
2235 * This is the new VBoxNetFlt+IntNet stuff.
2236 */
2237 if (fSniffer)
2238 {
2239 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2240 RC_CHECK();
2241 }
2242 else
2243 {
2244 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2245 RC_CHECK();
2246 }
2247
2248 Bstr HifName;
2249 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
2250 if(FAILED(hrc))
2251 {
2252 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
2253 H();
2254 }
2255
2256 Utf8Str HifNameUtf8(HifName);
2257 const char *pszHifName = HifNameUtf8.raw();
2258
2259# if defined(RT_OS_DARWIN)
2260 /* The name is on the form 'ifX: long name', chop it off at the colon. */
2261 char szTrunk[8];
2262 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
2263 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
2264 if (!pszColon)
2265 {
2266 hrc = aNetworkAdapter->Detach();
2267 H();
2268 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2269 N_("Malformed host interface networking name '%ls'"),
2270 HifName.raw());
2271 }
2272 *pszColon = '\0';
2273 const char *pszTrunk = szTrunk;
2274
2275# elif defined(RT_OS_SOLARIS)
2276 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
2277 char szTrunk[256];
2278 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
2279 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
2280
2281 /*
2282 * Currently don't bother about malformed names here for the sake of people using
2283 * VBoxManage and setting only the NIC name from there. If there is a space we
2284 * chop it off and proceed, otherwise just use whatever we've got.
2285 */
2286 if (pszSpace)
2287 *pszSpace = '\0';
2288
2289 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
2290 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
2291 if (pszColon)
2292 *pszColon = '\0';
2293
2294 const char *pszTrunk = szTrunk;
2295
2296# elif defined(RT_OS_WINDOWS)
2297 ComPtr<IHostNetworkInterface> hostInterface;
2298 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
2299 if (!SUCCEEDED(rc))
2300 {
2301 AssertBreakpoint();
2302 LogRel(("NetworkAttachmentType_Bridged: FindByName failed, rc (0x%x)", rc));
2303 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2304 N_("Inexistent host networking interface, name '%ls'"),
2305 HifName.raw());
2306 }
2307
2308 HostNetworkInterfaceType_T ifType;
2309 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
2310 if(FAILED(hrc))
2311 {
2312 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
2313 H();
2314 }
2315
2316 if(ifType != HostNetworkInterfaceType_Bridged)
2317 {
2318 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2319 N_("Interface ('%ls') is not a Bridged Adapter interface"),
2320 HifName.raw());
2321 }
2322
2323 Bstr hostIFGuid_;
2324 hrc = hostInterface->COMGETTER(Id)(hostIFGuid_.asOutParam());
2325 if(FAILED(hrc))
2326 {
2327 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
2328 H();
2329 }
2330 Guid hostIFGuid(hostIFGuid_);
2331
2332 INetCfg *pNc;
2333 ComPtr<INetCfgComponent> pAdaptorComponent;
2334 LPWSTR lpszApp;
2335 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
2336
2337 hrc = VBoxNetCfgWinQueryINetCfg( FALSE,
2338 L"VirtualBox",
2339 &pNc,
2340 &lpszApp );
2341 Assert(hrc == S_OK);
2342 if(hrc == S_OK)
2343 {
2344 /* get the adapter's INetCfgComponent*/
2345 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
2346 if(hrc != S_OK)
2347 {
2348 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2349 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2350 H();
2351 }
2352 }
2353#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
2354 char szTrunkName[INTNET_MAX_TRUNK_NAME];
2355 char *pszTrunkName = szTrunkName;
2356 wchar_t * pswzBindName;
2357 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
2358 Assert(hrc == S_OK);
2359 if (hrc == S_OK)
2360 {
2361 int cwBindName = (int)wcslen(pswzBindName) + 1;
2362 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
2363 if(sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
2364 {
2365 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
2366 pszTrunkName += cbFullBindNamePrefix-1;
2367 if(!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
2368 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
2369 {
2370 Assert(0);
2371 DWORD err = GetLastError();
2372 hrc = HRESULT_FROM_WIN32(err);
2373 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
2374 LogRel(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x)\n", hrc, hrc));
2375 }
2376 }
2377 else
2378 {
2379 Assert(0);
2380 LogRel(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
2381 /** @todo set appropriate error code */
2382 hrc = E_FAIL;
2383 }
2384
2385 if(hrc != S_OK)
2386 {
2387 Assert(0);
2388 CoTaskMemFree(pswzBindName);
2389 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2390 H();
2391 }
2392
2393 /* we're not freeing the bind name since we'll use it later for detecting wireless*/
2394 }
2395 else
2396 {
2397 Assert(0);
2398 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2399 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2400 H();
2401 }
2402 const char *pszTrunk = szTrunkName;
2403 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
2404
2405# elif defined(RT_OS_LINUX)
2406 /* @todo Check for malformed names. */
2407 const char *pszTrunk = pszHifName;
2408
2409# else
2410# error "PORTME (VBOX_WITH_NETFLT)"
2411# endif
2412
2413 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet");
2414 RC_CHECK();
2415 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2416 RC_CHECK();
2417 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk);
2418 RC_CHECK();
2419 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
2420 RC_CHECK();
2421 char szNetwork[80];
2422 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
2423 rc = CFGMR3InsertString(pCfg, "Network", szNetwork);
2424 RC_CHECK();
2425 networkName = Bstr(szNetwork);
2426 trunkName = Bstr(pszTrunk);
2427 trunkType = Bstr(TRUNKTYPE_NETFLT);
2428
2429# if defined(RT_OS_DARWIN)
2430 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
2431 if ( strstr(pszHifName, "Wireless")
2432 || strstr(pszHifName, "AirPort" ))
2433 {
2434 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
2435 RC_CHECK();
2436 }
2437# elif defined(RT_OS_LINUX)
2438 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
2439 if (iSock >= 0)
2440 {
2441 struct iwreq WRq;
2442
2443 memset(&WRq, 0, sizeof(WRq));
2444 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
2445 if (ioctl(iSock, SIOCGIWNAME, &WRq) >= 0)
2446 {
2447 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
2448 RC_CHECK();
2449 Log(("Set SharedMacOnWire\n"));
2450 }
2451 else
2452 {
2453 Log(("Failed to get wireless name\n"));
2454 }
2455 close(iSock);
2456 }
2457 else
2458 {
2459 Log(("Failed to open wireless socket\n"));
2460 }
2461# elif defined(RT_OS_WINDOWS)
2462# define DEVNAME_PREFIX L"\\\\.\\"
2463 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
2464 * there is a pretty long way till there though since we need to obtain the symbolic link name
2465 * for the adapter device we are going to query given the device Guid */
2466
2467
2468 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
2469
2470 wchar_t FileName[MAX_PATH];
2471 wcscpy(FileName, DEVNAME_PREFIX);
2472 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
2473
2474 /* open the device */
2475 HANDLE hDevice = CreateFile(FileName,
2476 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
2477 NULL,
2478 OPEN_EXISTING,
2479 FILE_ATTRIBUTE_NORMAL,
2480 NULL);
2481
2482 if (hDevice != INVALID_HANDLE_VALUE)
2483 {
2484 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
2485 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
2486 NDIS_PHYSICAL_MEDIUM PhMedium;
2487 DWORD cbResult;
2488 if (DeviceIoControl(hDevice,
2489 IOCTL_NDIS_QUERY_GLOBAL_STATS,
2490 &Oid,
2491 sizeof(Oid),
2492 &PhMedium,
2493 sizeof(PhMedium),
2494 &cbResult,
2495 NULL))
2496 {
2497 /* that was simple, now examine PhMedium */
2498 if ( PhMedium == NdisPhysicalMediumWirelessWan
2499 || PhMedium == NdisPhysicalMediumWirelessLan
2500 || PhMedium == NdisPhysicalMediumNative802_11
2501 || PhMedium == NdisPhysicalMediumBluetooth)
2502 {
2503 Log(("this is a wireless adapter"));
2504 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
2505 RC_CHECK();
2506 Log(("Set SharedMacOnWire\n"));
2507 }
2508 else
2509 {
2510 Log(("this is NOT a wireless adapter"));
2511 }
2512 }
2513 else
2514 {
2515 int winEr = GetLastError();
2516 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
2517 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
2518 }
2519
2520 CloseHandle(hDevice);
2521 }
2522 else
2523 {
2524 int winEr = GetLastError();
2525 LogRel(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
2526 AssertBreakpoint();
2527 }
2528
2529 CoTaskMemFree(pswzBindName);
2530
2531 pAdaptorComponent.setNull();
2532 /* release the pNc finally */
2533 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2534# else
2535 /** @todo PORTME: wireless detection */
2536# endif
2537
2538# if defined(RT_OS_SOLARIS)
2539# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
2540 /* Zone access restriction, don't allow snopping the global zone. */
2541 zoneid_t ZoneId = getzoneid();
2542 if (ZoneId != GLOBAL_ZONEID)
2543 {
2544 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
2545 }
2546# endif
2547# endif
2548
2549#elif defined(RT_OS_WINDOWS) /* not defined NetFlt */
2550 /* NOTHING TO DO HERE */
2551#elif defined(RT_OS_LINUX)
2552/// @todo aleksey: is there anything to be done here?
2553#elif defined(RT_OS_FREEBSD)
2554/** @todo FreeBSD: Check out this later (HIF networking). */
2555#else
2556# error "Port me"
2557#endif
2558 break;
2559 }
2560
2561 case NetworkAttachmentType_Internal:
2562 {
2563 hrc = aNetworkAdapter->COMGETTER(InternalNetwork)(&str);
2564 H();
2565 if (str)
2566 {
2567 STR_CONV();
2568 if (psz && *psz)
2569 {
2570 if (fSniffer)
2571 {
2572 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2573 RC_CHECK();
2574 }
2575 else
2576 {
2577 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2578 RC_CHECK();
2579 }
2580 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet");
2581 RC_CHECK();
2582 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2583 RC_CHECK();
2584 rc = CFGMR3InsertString(pCfg, "Network", psz);
2585 RC_CHECK();
2586 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone);
2587 RC_CHECK();
2588 networkName = Bstr(psz);
2589 trunkType = Bstr(TRUNKTYPE_WHATEVER);
2590 }
2591 STR_FREE();
2592 }
2593 break;
2594 }
2595
2596 case NetworkAttachmentType_HostOnly:
2597 {
2598 if (fSniffer)
2599 {
2600 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
2601 RC_CHECK();
2602 }
2603 else
2604 {
2605 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
2606 RC_CHECK();
2607 }
2608
2609 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet");
2610 RC_CHECK();
2611 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg);
2612 RC_CHECK();
2613#if defined(RT_OS_WINDOWS)
2614# ifndef VBOX_WITH_NETFLT
2615 hrc = E_NOTIMPL;
2616 LogRel(("NetworkAttachmentType_HostOnly: Not Implemented"));
2617 H();
2618# else
2619 Bstr HifName;
2620 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
2621 if(FAILED(hrc))
2622 {
2623 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
2624 H();
2625 }
2626
2627 Utf8Str HifNameUtf8(HifName);
2628 const char *pszHifName = HifNameUtf8.raw();
2629 ComPtr<IHostNetworkInterface> hostInterface;
2630 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
2631 if (!SUCCEEDED(rc))
2632 {
2633 AssertBreakpoint();
2634 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)", rc));
2635 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2636 N_("Inexistent host networking interface, name '%ls'"),
2637 HifName.raw());
2638 }
2639
2640 HostNetworkInterfaceType_T ifType;
2641 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
2642 if(FAILED(hrc))
2643 {
2644 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
2645 H();
2646 }
2647
2648 if(ifType != HostNetworkInterfaceType_HostOnly)
2649 {
2650 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2651 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
2652 HifName.raw());
2653 }
2654
2655
2656 Bstr hostIFGuid_;
2657 hrc = hostInterface->COMGETTER(Id)(hostIFGuid_.asOutParam());
2658 if(FAILED(hrc))
2659 {
2660 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)", hrc));
2661 H();
2662 }
2663 Guid hostIFGuid(hostIFGuid_);
2664
2665 INetCfg *pNc;
2666 ComPtr<INetCfgComponent> pAdaptorComponent;
2667 LPWSTR lpszApp;
2668 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
2669
2670 hrc = VBoxNetCfgWinQueryINetCfg(FALSE,
2671 L"VirtualBox",
2672 &pNc,
2673 &lpszApp);
2674 Assert(hrc == S_OK);
2675 if(hrc == S_OK)
2676 {
2677 /* get the adapter's INetCfgComponent*/
2678 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
2679 if(hrc != S_OK)
2680 {
2681 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2682 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2683 H();
2684 }
2685 }
2686#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
2687 char szTrunkName[INTNET_MAX_TRUNK_NAME];
2688 char *pszTrunkName = szTrunkName;
2689 wchar_t * pswzBindName;
2690 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
2691 Assert(hrc == S_OK);
2692 if (hrc == S_OK)
2693 {
2694 int cwBindName = (int)wcslen(pswzBindName) + 1;
2695 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
2696 if(sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
2697 {
2698 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
2699 pszTrunkName += cbFullBindNamePrefix-1;
2700 if(!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
2701 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
2702 {
2703 Assert(0);
2704 DWORD err = GetLastError();
2705 hrc = HRESULT_FROM_WIN32(err);
2706 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
2707 LogRel(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x)\n", hrc, hrc));
2708 }
2709 }
2710 else
2711 {
2712 Assert(0);
2713 LogRel(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
2714 /** @todo set appropriate error code */
2715 hrc = E_FAIL;
2716 }
2717
2718 if(hrc != S_OK)
2719 {
2720 Assert(0);
2721 CoTaskMemFree(pswzBindName);
2722 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2723 H();
2724 }
2725 }
2726 else
2727 {
2728 Assert(0);
2729 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2730 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2731 H();
2732 }
2733
2734
2735 CoTaskMemFree(pswzBindName);
2736
2737 pAdaptorComponent.setNull();
2738 /* release the pNc finally */
2739 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
2740
2741 const char *pszTrunk = szTrunkName;
2742
2743
2744 /* TODO: set the proper Trunk and Network values, currently the driver uses the first adapter instance */
2745 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp);
2746 RC_CHECK();
2747 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk);
2748 RC_CHECK();
2749 char szNetwork[80];
2750 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
2751 rc = CFGMR3InsertString(pCfg, "Network", szNetwork);
2752 RC_CHECK();
2753 networkName = Bstr(szNetwork);
2754 trunkName = Bstr(pszTrunk);
2755 trunkType = TRUNKTYPE_NETADP;
2756# endif /* defined VBOX_WITH_NETFLT*/
2757#elif defined(RT_OS_DARWIN)
2758 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0");
2759 RC_CHECK();
2760 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0");
2761 RC_CHECK();
2762 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp);
2763 RC_CHECK();
2764 networkName = Bstr("HostInterfaceNetworking-vboxnet0");
2765 trunkName = Bstr("vboxnet0");
2766 trunkType = TRUNKTYPE_NETADP;
2767#else
2768 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0");
2769 RC_CHECK();
2770 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0");
2771 RC_CHECK();
2772 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
2773 RC_CHECK();
2774 networkName = Bstr("HostInterfaceNetworking-vboxnet0");
2775 trunkName = Bstr("vboxnet0");
2776 trunkType = TRUNKTYPE_NETFLT;
2777#endif
2778#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
2779 Bstr HifName;
2780 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
2781 if(FAILED(hrc))
2782 {
2783 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
2784 H();
2785 }
2786
2787 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface): ", hrc));
2788 Utf8Str HifNameUtf8(HifName);
2789 const char *pszHifName = HifNameUtf8.raw();
2790 ComPtr<IHostNetworkInterface> hostInterface;
2791 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
2792 if (!SUCCEEDED(rc))
2793 {
2794 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)", rc));
2795 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2796 N_("Inexistent host networking interface, name '%ls'"),
2797 HifName.raw());
2798 }
2799 Bstr tmpAddr, tmpMask;
2800 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPAddress"), tmpAddr.asOutParam());
2801 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
2802 {
2803 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPNetMask"), tmpMask.asOutParam());
2804 if (SUCCEEDED(hrc) && !tmpMask.isEmpty())
2805 hrc = hostInterface->EnableStaticIpConfig(tmpAddr, tmpMask);
2806 else
2807 hrc = hostInterface->EnableStaticIpConfig(tmpAddr,
2808 Bstr(VBOXNET_IPV4MASK_DEFAULT));
2809 }
2810 else
2811 hrc = hostInterface->EnableStaticIpConfig(Bstr(VBOXNET_IPV4ADDR_DEFAULT),
2812 Bstr(VBOXNET_IPV4MASK_DEFAULT));
2813
2814
2815 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPV6Address"), tmpAddr.asOutParam());
2816 if (SUCCEEDED(hrc))
2817 hrc = virtualBox->GetExtraData(Bstr("HostOnly/vboxnet0/IPV6NetMask"), tmpMask.asOutParam());
2818 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty() && !tmpMask.isEmpty())
2819 hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
2820#endif
2821 break;
2822 }
2823
2824 default:
2825 AssertMsgFailed(("should not get here!\n"));
2826 break;
2827 }
2828
2829 /*
2830 * Attempt to attach the driver.
2831 */
2832 switch (eAttachmentType)
2833 {
2834 case NetworkAttachmentType_Null:
2835 break;
2836
2837 case NetworkAttachmentType_Bridged:
2838 case NetworkAttachmentType_Internal:
2839 case NetworkAttachmentType_HostOnly:
2840 case NetworkAttachmentType_NAT:
2841 {
2842 if (SUCCEEDED(hrc) && SUCCEEDED(rc))
2843 {
2844 if (attachDetach)
2845 {
2846 rc = PDMR3DeviceAttach (pVM, pszDevice, uInstance, uLun, NULL, PDMDEVATT_FLAGS_NOT_HOT_PLUG);
2847 AssertRC (rc);
2848 }
2849
2850 {
2851 /** @todo r=pritesh: get the dhcp server name from the
2852 * previous network configuration and then stop the server
2853 * else it may conflict with the dhcp server running with
2854 * the current attachment type
2855 */
2856 /* Stop the hostonly DHCP Server */
2857 }
2858
2859 if(!networkName.isNull())
2860 {
2861 /*
2862 * Until we implement service reference counters DHCP Server will be stopped
2863 * by DHCPServerRunner destructor.
2864 */
2865 ComPtr<IDHCPServer> dhcpServer;
2866 hrc = virtualBox->FindDHCPServerByNetworkName(networkName.mutableRaw(), dhcpServer.asOutParam());
2867 if(SUCCEEDED(hrc))
2868 {
2869 /* there is a DHCP server available for this network */
2870 BOOL bEnabled;
2871 hrc = dhcpServer->COMGETTER(Enabled)(&bEnabled);
2872 if(FAILED(hrc))
2873 {
2874 LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (0x%x)", hrc));
2875 H();
2876 }
2877
2878 if(bEnabled)
2879 hrc = dhcpServer->Start(networkName, trunkName, trunkType);
2880 }
2881 else
2882 {
2883 hrc = S_OK;
2884 }
2885 }
2886 }
2887
2888 break;
2889 }
2890
2891 default:
2892 AssertMsgFailed(("should not get here!\n"));
2893 break;
2894 }
2895
2896 meAttachmentType[uInstance] = eAttachmentType;
2897 }
2898 while (0);
2899
2900#undef STR_FREE
2901#undef STR_CONV
2902#undef H
2903#undef RC_CHECK
2904
2905 return rcRet;
2906}
2907
2908/* 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