VirtualBox

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

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

*: spelling fixes, thanks Timeless!

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