VirtualBox

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

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

Main: Added ExtPackManager to Console and implemented the Console and VirtualBox hooks.

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

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