VirtualBox

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

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

Added large page property.

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