VirtualBox

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

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

Store PCI bus/dev/fn of first NIC in CFGM and propagate the data to CMOS.

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

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