VirtualBox

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

最後變更 在這個檔案從26646是 26609,由 vboxsync 提交於 15 年 前

Main, shared f/w: changed DMI passthrough defaults

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

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