VirtualBox

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

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

RTC is _not_ enabled by default

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