VirtualBox

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

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

OSE build fix

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

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