VirtualBox

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

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

ConsoleImpl2: removed debug output

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