VirtualBox

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

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

Main/ConsoleImpl2: fixed crash when accessing pConsole's mpVM as it was not yet.

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