VirtualBox

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

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

ExtPack: Fixes to IExtPack (QueryInterface can't be used for getting stuff from the ext pack, designed the plug-in interfaces). Bugfixes making 'VBoxManage list extpack' work when building with VBOX_WITH_EXTPACK_PUEL=1.

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