VirtualBox

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

Last change on this file since 30177 was 30177, checked in by vboxsync, 14 years ago

Same for memory balloon

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

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