VirtualBox

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

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

Main, PCI: uniform PCI slots management, please watch/report regressions

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