VirtualBox

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

Last change on this file since 28286 was 28286, checked in by vboxsync, 15 years ago

Guest Control: Update (introducing contexts for callbacks).

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