VirtualBox

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

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

Pass boot NIC PCI dev/fn separately to DevPcBios. Easier to understand and modify.

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