VirtualBox

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

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

com/Guid: remove conversion operators to eliminate any compiler surprises. Caught one totally unexpected issue which was indirectly caused by the similar Bstr cleanup, as there still is a Bstr->Guid conversion and thus the Guid magic was triggered

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

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