VirtualBox

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

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

Main: don't warn the user for the ext4/xfs bug if Linux >= 2.6.36-rc4 is detected (version check refined)

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