VirtualBox

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

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

NetworkAttachment: Allow changing the attachment between NONE/NAT/HIF/host-only/.. dynamically #3573

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