VirtualBox

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

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

typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 163.9 KB
Line 
1/* $Id: ConsoleImpl2.cpp 28489 2010-04-19 18:06:52Z 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 if (fExtProfile)
2250 {
2251 BootNic aNic = llBootNics.front();
2252 uint32_t u32NicPciAddr = (aNic.mPciDev << 16) | aNic.mPciFn;
2253 rc = CFGMR3InsertInteger(pCfg, "NicPciAddress", u32NicPciAddr); RC_CHECK();
2254 }
2255 rc = CFGMR3InsertInteger(pCfg, "ShowCpu", fShowCpu); RC_CHECK();
2256 rc = CFGMR3InsertInteger(pCfg, "CpuHotPlug", fCpuHotPlug); RC_CHECK();
2257 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
2258 Assert(!afPciDeviceNo[7]);
2259 afPciDeviceNo[7] = true;
2260 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2261
2262 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2263 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
2264 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2265
2266 /* Attach the dummy CPU drivers */
2267 for (ULONG iCpuCurr = 1; iCpuCurr < cCpus; iCpuCurr++)
2268 {
2269 BOOL fCpuAttached = true;
2270
2271 if (fCpuHotPlug)
2272 {
2273 hrc = pMachine->GetCPUStatus(iCpuCurr, &fCpuAttached); H();
2274 }
2275
2276 if (fCpuAttached)
2277 {
2278 rc = CFGMR3InsertNodeF(pInst, &pLunL0, "LUN#%u", iCpuCurr); RC_CHECK();
2279 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPICpu"); RC_CHECK();
2280 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2281 }
2282 }
2283 }
2284
2285
2286 /*
2287 * CFGM overlay handling.
2288 *
2289 * Here we check the extra data entries for CFGM values
2290 * and create the nodes and insert the values on the fly. Existing
2291 * values will be removed and reinserted. CFGM is typed, so by default
2292 * we will guess whether it's a string or an integer (byte arrays are
2293 * not currently supported). It's possible to override this autodetection
2294 * by adding "string:", "integer:" or "bytes:" (future).
2295 *
2296 * We first perform a run on global extra data, then on the machine
2297 * extra data to support global settings with local overrides.
2298 *
2299 */
2300 /** @todo add support for removing nodes and byte blobs. */
2301 SafeArray<BSTR> aGlobalExtraDataKeys;
2302 SafeArray<BSTR> aMachineExtraDataKeys;
2303 /*
2304 * Get the next key
2305 */
2306 if (FAILED(hrc = virtualBox->GetExtraDataKeys(ComSafeArrayAsOutParam(aGlobalExtraDataKeys))))
2307 AssertMsgFailed(("VirtualBox::GetExtraDataKeys failed with %Rrc\n", hrc));
2308
2309 // remember the no. of global values so we can call the correct method below
2310 size_t cGlobalValues = aGlobalExtraDataKeys.size();
2311
2312 if (FAILED(hrc = pMachine->GetExtraDataKeys(ComSafeArrayAsOutParam(aMachineExtraDataKeys))))
2313 AssertMsgFailed(("IMachine::GetExtraDataKeys failed with %Rrc\n", hrc));
2314
2315 // build a combined list from global keys...
2316 std::list<Utf8Str> llExtraDataKeys;
2317
2318 for (size_t i = 0; i < aGlobalExtraDataKeys.size(); ++i)
2319 llExtraDataKeys.push_back(Utf8Str(aGlobalExtraDataKeys[i]));
2320 // ... and machine keys
2321 for (size_t i = 0; i < aMachineExtraDataKeys.size(); ++i)
2322 llExtraDataKeys.push_back(Utf8Str(aMachineExtraDataKeys[i]));
2323
2324 size_t i2 = 0;
2325 for (std::list<Utf8Str>::const_iterator it = llExtraDataKeys.begin();
2326 it != llExtraDataKeys.end();
2327 ++it, ++i2)
2328 {
2329 const Utf8Str &strKey = *it;
2330
2331 /*
2332 * We only care about keys starting with "VBoxInternal/" (skip "G:" or "M:")
2333 */
2334 if (!strKey.startsWith("VBoxInternal/"))
2335 continue;
2336
2337 const char *pszExtraDataKey = strKey.raw() + sizeof("VBoxInternal/") - 1;
2338
2339 // get the value
2340 Bstr strExtraDataValue;
2341 if (i2 < cGlobalValues)
2342 // this is still one of the global values:
2343 hrc = virtualBox->GetExtraData(Bstr(strKey), strExtraDataValue.asOutParam());
2344 else
2345 hrc = pMachine->GetExtraData(Bstr(strKey), strExtraDataValue.asOutParam());
2346 if (FAILED(hrc))
2347 LogRel(("Warning: Cannot get extra data key %s, rc = %Rrc\n", strKey.raw(), hrc));
2348
2349 /*
2350 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2351 * Split the two and get the node, delete the value and create the node
2352 * if necessary.
2353 */
2354 PCFGMNODE pNode;
2355 const char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2356 if (pszCFGMValueName)
2357 {
2358 /* terminate the node and advance to the value (Utf8Str might not
2359 offically like this but wtf) */
2360 *(char*)pszCFGMValueName = '\0';
2361 ++pszCFGMValueName;
2362
2363 /* does the node already exist? */
2364 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2365 if (pNode)
2366 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2367 else
2368 {
2369 /* create the node */
2370 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2371 if (RT_FAILURE(rc))
2372 {
2373 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2374 continue;
2375 }
2376 Assert(pNode);
2377 }
2378 }
2379 else
2380 {
2381 /* root value (no node path). */
2382 pNode = pRoot;
2383 pszCFGMValueName = pszExtraDataKey;
2384 pszExtraDataKey--;
2385 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2386 }
2387
2388 /*
2389 * Now let's have a look at the value.
2390 * Empty strings means that we should remove the value, which we've
2391 * already done above.
2392 */
2393 Utf8Str strCFGMValueUtf8(strExtraDataValue);
2394 const char *pszCFGMValue = strCFGMValueUtf8.raw();
2395 if ( pszCFGMValue
2396 && *pszCFGMValue)
2397 {
2398 uint64_t u64Value;
2399
2400 /* check for type prefix first. */
2401 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
2402 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
2403 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
2404 {
2405 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
2406 if (RT_SUCCESS(rc))
2407 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2408 }
2409 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
2410 rc = VERR_NOT_IMPLEMENTED;
2411 /* auto detect type. */
2412 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
2413 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2414 else
2415 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
2416 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
2417 }
2418 }
2419
2420#undef STR_FREE
2421#undef H
2422#undef RC_CHECK
2423
2424 /* Register VM state change handler */
2425 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2426 AssertRC(rc2);
2427 if (RT_SUCCESS(rc))
2428 rc = rc2;
2429
2430 /* Register VM runtime error handler */
2431 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2432 AssertRC(rc2);
2433 if (RT_SUCCESS(rc))
2434 rc = rc2;
2435
2436 LogFlowFunc (("vrc = %Rrc\n", rc));
2437 LogFlowFuncLeave();
2438
2439 return rc;
2440}
2441
2442/**
2443 * Ellipsis to va_list wrapper for calling setVMRuntimeErrorCallback.
2444 */
2445/*static*/ void Console::setVMRuntimeErrorCallbackF(PVM pVM, void *pvConsole, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
2446{
2447 va_list va;
2448 va_start(va, pszFormat);
2449 setVMRuntimeErrorCallback(pVM, pvConsole, fFlags, pszErrorId, pszFormat, va);
2450 va_end(va);
2451}
2452
2453/**
2454 * Construct the Network configuration tree
2455 *
2456 * @returns VBox status code.
2457 *
2458 * @param pThis Pointer to the Console object.
2459 * @param pszDevice The PDM device name.
2460 * @param uInstance The PDM device instance.
2461 * @param uLun The PDM LUN number of the drive.
2462 * @param aNetworkAdapter The network adapter whose attachment needs to be changed
2463 * @param pCfg Configuration node for the device
2464 * @param pLunL0 To store the pointer to the LUN#0.
2465 * @param pInst The instance CFGM node
2466 * @param fAttachDetach To determine if the network attachment should
2467 * be attached/detached after/before
2468 * configuration.
2469 *
2470 * @note Locks the Console object for writing.
2471 */
2472/*static*/ int Console::configNetwork(Console *pThis, const char *pszDevice,
2473 unsigned uInstance, unsigned uLun,
2474 INetworkAdapter *aNetworkAdapter,
2475 PCFGMNODE pCfg, PCFGMNODE pLunL0,
2476 PCFGMNODE pInst, bool fAttachDetach)
2477{
2478 int rc = VINF_SUCCESS;
2479
2480 AutoCaller autoCaller(pThis);
2481 AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
2482
2483 /*
2484 * Locking the object before doing VMR3* calls is quite safe here, since
2485 * we're on EMT. Write lock is necessary because we indirectly modify the
2486 * meAttachmentType member.
2487 */
2488 AutoWriteLock alock(pThis COMMA_LOCKVAL_SRC_POS);
2489
2490 PVM pVM = pThis->mpVM;
2491 BSTR str = NULL;
2492
2493#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } } while (0)
2494#define RC_CHECK() do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc)); STR_FREE(); return rc; } } while (0)
2495#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%Rhrc\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
2496
2497 HRESULT hrc;
2498 ComPtr<IMachine> pMachine = pThis->machine();
2499
2500 ComPtr<IVirtualBox> virtualBox;
2501 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam());
2502 H();
2503
2504 ComPtr<IHost> host;
2505 hrc = virtualBox->COMGETTER(Host)(host.asOutParam());
2506 H();
2507
2508 BOOL fSniffer;
2509 hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer);
2510 H();
2511
2512 if (fAttachDetach && fSniffer)
2513 {
2514 const char *pszNetDriver = "IntNet";
2515 if (pThis->meAttachmentType[uInstance] == NetworkAttachmentType_NAT)
2516 pszNetDriver = "NAT";
2517#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
2518 if (pThis->meAttachmentType[uInstance] == NetworkAttachmentType_Bridged)
2519 pszNetDriver = "HostInterface";
2520#endif
2521
2522 rc = PDMR3DriverDetach(pVM, pszDevice, uInstance, uLun, pszNetDriver, 0, 0 /*fFlags*/);
2523 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
2524 rc = VINF_SUCCESS;
2525 AssertLogRelRCReturn(rc, rc);
2526
2527 pLunL0 = CFGMR3GetChildF(pInst, "LUN#%u", uLun);
2528 PCFGMNODE pLunAD = CFGMR3GetChildF(pLunL0, "AttachedDriver");
2529 if (pLunAD)
2530 {
2531 CFGMR3RemoveNode(pLunAD);
2532 }
2533 else
2534 {
2535 CFGMR3RemoveNode(pLunL0);
2536 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2537 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
2538 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2539 hrc = aNetworkAdapter->COMGETTER(TraceFile)(&str); H();
2540 if (str) /* check convention for indicating default file. */
2541 {
2542 rc = CFGMR3InsertStringW(pCfg, "File", str); RC_CHECK();
2543 }
2544 STR_FREE();
2545 }
2546 }
2547 else if (fAttachDetach && !fSniffer)
2548 {
2549 rc = PDMR3DeviceDetach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/);
2550 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
2551 rc = VINF_SUCCESS;
2552 AssertLogRelRCReturn(rc, rc);
2553
2554 /* nuke anything which might have been left behind. */
2555 CFGMR3RemoveNode(CFGMR3GetChildF(pInst, "LUN#%u", uLun));
2556 }
2557 else if (!fAttachDetach && fSniffer)
2558 {
2559 /* insert the sniffer filter driver. */
2560 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2561 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
2562 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2563 hrc = aNetworkAdapter->COMGETTER(TraceFile)(&str); H();
2564 if (str) /* check convention for indicating default file. */
2565 {
2566 rc = CFGMR3InsertStringW(pCfg, "File", str); RC_CHECK();
2567 }
2568 STR_FREE();
2569 }
2570
2571 Bstr networkName, trunkName, trunkType;
2572 NetworkAttachmentType_T eAttachmentType;
2573 hrc = aNetworkAdapter->COMGETTER(AttachmentType)(&eAttachmentType); H();
2574 switch (eAttachmentType)
2575 {
2576 case NetworkAttachmentType_Null:
2577 break;
2578
2579 case NetworkAttachmentType_NAT:
2580 {
2581 ComPtr<INATEngine> natDriver;
2582 hrc = aNetworkAdapter->COMGETTER(NatDriver)(natDriver.asOutParam()); H();
2583 if (fSniffer)
2584 {
2585 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
2586 }
2587 else
2588 {
2589 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2590 }
2591 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
2592 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2593
2594 /* Configure TFTP prefix and boot filename. */
2595 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
2596 if (str && *str)
2597 {
2598 rc = CFGMR3InsertStringF(pCfg, "TFTPPrefix", "%ls%c%s", str, RTPATH_DELIMITER, "TFTP"); RC_CHECK();
2599 }
2600 STR_FREE();
2601 hrc = pMachine->COMGETTER(Name)(&str); H();
2602 rc = CFGMR3InsertStringF(pCfg, "BootFile", "%ls.pxe", str); RC_CHECK();
2603 STR_FREE();
2604
2605 hrc = natDriver->COMGETTER(Network)(&str); H();
2606 if (str)
2607 {
2608 rc = CFGMR3InsertStringW(pCfg, "Network", str); RC_CHECK();
2609 }
2610 else
2611 {
2612 ULONG uSlot;
2613 hrc = aNetworkAdapter->COMGETTER(Slot)(&uSlot); H();
2614 rc = CFGMR3InsertStringF(pCfg, "Network", "10.0.%d.0/24", uSlot+2); RC_CHECK();
2615 }
2616 STR_FREE();
2617 hrc = natDriver->COMGETTER(HostIP)(&str); H();
2618 if (str)
2619 {
2620 rc = CFGMR3InsertStringW(pCfg, "BindIP", str); RC_CHECK();
2621 }
2622 STR_FREE();
2623 ULONG mtu = 0;
2624 ULONG sockSnd = 0;
2625 ULONG sockRcv = 0;
2626 ULONG tcpSnd = 0;
2627 ULONG tcpRcv = 0;
2628 hrc = natDriver->GetNetworkSettings(&mtu, &sockSnd, &sockRcv, &tcpSnd, &tcpRcv); H();
2629 if (mtu)
2630 {
2631 rc = CFGMR3InsertInteger(pCfg, "SlirpMTU", mtu); RC_CHECK();
2632 }
2633 if (sockRcv)
2634 {
2635 rc = CFGMR3InsertInteger(pCfg, "SockRcv", sockRcv); RC_CHECK();
2636 }
2637 if (sockSnd)
2638 {
2639 rc = CFGMR3InsertInteger(pCfg, "SockSnd", sockSnd); RC_CHECK();
2640 }
2641 if (tcpRcv)
2642 {
2643 rc = CFGMR3InsertInteger(pCfg, "TcpRcv", tcpRcv); RC_CHECK();
2644 }
2645 if (tcpSnd)
2646 {
2647 rc = CFGMR3InsertInteger(pCfg, "TcpSnd", tcpSnd); RC_CHECK();
2648 }
2649 STR_FREE();
2650 hrc = natDriver->COMGETTER(TftpPrefix)(&str); H();
2651 if (str)
2652 {
2653 rc = CFGMR3RemoveValue(pCfg, "TFTPPrefix"); RC_CHECK();
2654 rc = CFGMR3InsertStringW(pCfg, "TFTPPrefix", str); RC_CHECK();
2655 }
2656 STR_FREE();
2657 hrc = natDriver->COMGETTER(TftpBootFile)(&str); H();
2658 if (str)
2659 {
2660 rc = CFGMR3RemoveValue(pCfg, "BootFile"); RC_CHECK();
2661 rc = CFGMR3InsertStringW(pCfg, "BootFile", str); RC_CHECK();
2662 }
2663 STR_FREE();
2664 hrc = natDriver->COMGETTER(TftpNextServer)(&str); H();
2665 if (str)
2666 {
2667 rc = CFGMR3InsertStringW(pCfg, "NextServer", str); RC_CHECK();
2668 }
2669 BOOL fDnsFlag;
2670 hrc = natDriver->COMGETTER(DnsPassDomain)(&fDnsFlag); H();
2671 rc = CFGMR3InsertInteger(pCfg, "PassDomain", fDnsFlag); RC_CHECK();
2672 hrc = natDriver->COMGETTER(DnsProxy)(&fDnsFlag); H();
2673 rc = CFGMR3InsertInteger(pCfg, "DNSProxy", fDnsFlag); RC_CHECK();
2674 hrc = natDriver->COMGETTER(DnsUseHostResolver)(&fDnsFlag); H();
2675 rc = CFGMR3InsertInteger(pCfg, "UseHostResolver", fDnsFlag); RC_CHECK();
2676 /* port-forwarding */
2677 SafeArray<BSTR> pfs;
2678 hrc = natDriver->COMGETTER(Redirects)(ComSafeArrayAsOutParam(pfs)); H();
2679 PCFGMNODE pPF = NULL; /* /Devices/Dev/.../Config/PF#0/ */
2680 for (unsigned int i = 0; i < pfs.size(); ++i)
2681 {
2682 uint16_t port = 0;
2683 BSTR r = pfs[i];
2684 Utf8Str utf = Utf8Str(r);
2685 Utf8Str strName;
2686 Utf8Str strProto;
2687 Utf8Str strHostPort;
2688 Utf8Str strHostIP;
2689 Utf8Str strGuestPort;
2690 Utf8Str strGuestIP;
2691 size_t pos, ppos;
2692 pos = ppos = 0;
2693 #define ITERATE_TO_NEXT_TERM(res, str, pos, ppos) \
2694 do { \
2695 pos = str.find(",", ppos); \
2696 if (pos == Utf8Str::npos) \
2697 { \
2698 Log(( #res " extracting from %s is failed\n", str.raw())); \
2699 continue; \
2700 } \
2701 res = str.substr(ppos, pos - ppos); \
2702 Log2((#res " %s pos:%d, ppos:%d\n", res.raw(), pos, ppos)); \
2703 ppos = pos + 1; \
2704 }while (0)
2705 ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos);
2706 ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos);
2707 ITERATE_TO_NEXT_TERM(strHostIP, utf, pos, ppos);
2708 ITERATE_TO_NEXT_TERM(strHostPort, utf, pos, ppos);
2709 ITERATE_TO_NEXT_TERM(strGuestIP, utf, pos, ppos);
2710 strGuestPort = utf.substr(ppos, utf.length() - ppos);
2711 #undef ITERATE_TO_NEXT_TERM
2712
2713 uint32_t proto = strProto.toUInt32();
2714 bool fValid = true;
2715 switch (proto)
2716 {
2717 case NATProtocol_UDP:
2718 strProto = "UDP";
2719 break;
2720 case NATProtocol_TCP:
2721 strProto = "TCP";
2722 break;
2723 default:
2724 fValid = false;
2725 }
2726 /* continue with next rule if no valid proto was passed */
2727 if (!fValid)
2728 continue;
2729
2730 rc = CFGMR3InsertNode(pCfg, strName.raw(), &pPF); RC_CHECK();
2731 rc = CFGMR3InsertString(pPF, "Protocol", strProto.raw()); RC_CHECK();
2732
2733 if (!strHostIP.isEmpty())
2734 {
2735 rc = CFGMR3InsertString(pPF, "BindIP", strHostIP.raw()); RC_CHECK();
2736 }
2737
2738 if (!strGuestIP.isEmpty())
2739 {
2740 rc = CFGMR3InsertString(pPF, "GuestIP", strGuestIP.raw()); RC_CHECK();
2741 }
2742
2743 port = RTStrToUInt16(strHostPort.raw());
2744 if (port)
2745 {
2746 rc = CFGMR3InsertInteger(pPF, "HostPort", port); RC_CHECK();
2747 }
2748
2749 port = RTStrToUInt16(strGuestPort.raw());
2750 if (port)
2751 {
2752 rc = CFGMR3InsertInteger(pPF, "GuestPort", port); RC_CHECK();
2753 }
2754 }
2755 break;
2756 }
2757
2758 case NetworkAttachmentType_Bridged:
2759 {
2760#if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT)
2761 hrc = pThis->attachToTapInterface(aNetworkAdapter);
2762 if (FAILED(hrc))
2763 {
2764 switch (hrc)
2765 {
2766 case VERR_ACCESS_DENIED:
2767 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2768 "Failed to open '/dev/net/tun' for read/write access. Please check the "
2769 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
2770 "change the group of that node and make yourself a member of that group. Make "
2771 "sure that these changes are permanent, especially if you are "
2772 "using udev"));
2773 default:
2774 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
2775 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2776 "Failed to initialize Host Interface Networking"));
2777 }
2778 }
2779
2780 Assert((int)pThis->maTapFD[uInstance] >= 0);
2781 if ((int)pThis->maTapFD[uInstance] >= 0)
2782 {
2783 if (fSniffer)
2784 {
2785 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
2786 }
2787 else
2788 {
2789 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2790 }
2791 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
2792 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2793 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pThis->maTapFD[uInstance]); RC_CHECK();
2794 }
2795
2796#elif defined(VBOX_WITH_NETFLT)
2797 /*
2798 * This is the new VBoxNetFlt+IntNet stuff.
2799 */
2800 if (fSniffer)
2801 {
2802 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
2803 }
2804 else
2805 {
2806 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2807 }
2808
2809 Bstr HifName;
2810 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
2811 if (FAILED(hrc))
2812 {
2813 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
2814 H();
2815 }
2816
2817 Utf8Str HifNameUtf8(HifName);
2818 const char *pszHifName = HifNameUtf8.raw();
2819
2820# if defined(RT_OS_DARWIN)
2821 /* The name is on the form 'ifX: long name', chop it off at the colon. */
2822 char szTrunk[8];
2823 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
2824 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
2825 if (!pszColon)
2826 {
2827 /*
2828 * Dynamic changing of attachment causes an attempt to configure
2829 * network with invalid host adapter (as it is must be changed before
2830 * the attachment), calling Detach here will cause a deadlock.
2831 * See #4750.
2832 * hrc = aNetworkAdapter->Detach(); H();
2833 */
2834 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2835 N_("Malformed host interface networking name '%ls'"),
2836 HifName.raw());
2837 }
2838 *pszColon = '\0';
2839 const char *pszTrunk = szTrunk;
2840
2841# elif defined(RT_OS_SOLARIS)
2842 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
2843 char szTrunk[256];
2844 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
2845 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
2846
2847 /*
2848 * Currently don't bother about malformed names here for the sake of people using
2849 * VBoxManage and setting only the NIC name from there. If there is a space we
2850 * chop it off and proceed, otherwise just use whatever we've got.
2851 */
2852 if (pszSpace)
2853 *pszSpace = '\0';
2854
2855 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
2856 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
2857 if (pszColon)
2858 *pszColon = '\0';
2859
2860 const char *pszTrunk = szTrunk;
2861
2862# elif defined(RT_OS_WINDOWS)
2863 ComPtr<IHostNetworkInterface> hostInterface;
2864 hrc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
2865 if (!SUCCEEDED(hrc))
2866 {
2867 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: FindByName failed, rc=%Rhrc (0x%x)", hrc, hrc));
2868 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2869 N_("Inexistent host networking interface, name '%ls'"),
2870 HifName.raw());
2871 }
2872
2873 HostNetworkInterfaceType_T eIfType;
2874 hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
2875 if (FAILED(hrc))
2876 {
2877 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
2878 H();
2879 }
2880
2881 if (eIfType != HostNetworkInterfaceType_Bridged)
2882 {
2883 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
2884 N_("Interface ('%ls') is not a Bridged Adapter interface"),
2885 HifName.raw());
2886 }
2887
2888 hrc = hostInterface->COMGETTER(Id)(&str);
2889 if (FAILED(hrc))
2890 {
2891 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
2892 H();
2893 }
2894 Guid hostIFGuid(str);
2895 STR_FREE();
2896
2897 INetCfg *pNc;
2898 ComPtr<INetCfgComponent> pAdaptorComponent;
2899 LPWSTR pszApp;
2900 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
2901
2902 hrc = VBoxNetCfgWinQueryINetCfg(FALSE /*fGetWriteLock*/,
2903 L"VirtualBox",
2904 &pNc,
2905 &pszApp);
2906 Assert(hrc == S_OK);
2907 if (hrc == S_OK)
2908 {
2909 /* get the adapter's INetCfgComponent*/
2910 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
2911 if (hrc != S_OK)
2912 {
2913 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2914 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2915 H();
2916 }
2917 }
2918#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
2919 char szTrunkName[INTNET_MAX_TRUNK_NAME];
2920 char *pszTrunkName = szTrunkName;
2921 wchar_t * pswzBindName;
2922 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
2923 Assert(hrc == S_OK);
2924 if (hrc == S_OK)
2925 {
2926 int cwBindName = (int)wcslen(pswzBindName) + 1;
2927 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
2928 if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
2929 {
2930 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
2931 pszTrunkName += cbFullBindNamePrefix-1;
2932 if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
2933 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
2934 {
2935 DWORD err = GetLastError();
2936 hrc = HRESULT_FROM_WIN32(err);
2937 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
2938 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
2939 }
2940 }
2941 else
2942 {
2943 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
2944 /** @todo set appropriate error code */
2945 hrc = E_FAIL;
2946 }
2947
2948 if (hrc != S_OK)
2949 {
2950 AssertFailed();
2951 CoTaskMemFree(pswzBindName);
2952 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2953 H();
2954 }
2955
2956 /* we're not freeing the bind name since we'll use it later for detecting wireless*/
2957 }
2958 else
2959 {
2960 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
2961 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
2962 H();
2963 }
2964 const char *pszTrunk = szTrunkName;
2965 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
2966
2967# elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
2968# if defined(RT_OS_FREEBSD)
2969 /*
2970 * If we bridge to a tap interface open it the `old' direct way.
2971 * This works and performs better than bridging a physical
2972 * interface via the current FreeBSD vboxnetflt implementation.
2973 */
2974 if (!strncmp(pszHifName, "tap", sizeof "tap" - 1)) {
2975 hrc = pThis->attachToTapInterface(aNetworkAdapter);
2976 if (FAILED(hrc))
2977 {
2978 switch (hrc)
2979 {
2980 case VERR_ACCESS_DENIED:
2981 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2982 "Failed to open '/dev/%s' for read/write access. Please check the "
2983 "permissions of that node, and that the net.link.tap.user_open "
2984 "sysctl is set. Either run 'chmod 0666 /dev/%s' or "
2985 "change the group of that node to vboxusers and make yourself "
2986 "a member of that group. Make sure that these changes are permanent."), pszHifName, pszHifName);
2987 default:
2988 AssertMsgFailed(("Could not attach to tap interface! Bad!\n"));
2989 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
2990 "Failed to initialize Host Interface Networking"));
2991 }
2992 }
2993
2994 Assert((int)pThis->maTapFD[uInstance] >= 0);
2995 if ((int)pThis->maTapFD[uInstance] >= 0)
2996 {
2997 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
2998 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2999 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pThis->maTapFD[uInstance]); RC_CHECK();
3000 }
3001 break;
3002 }
3003# endif
3004 /** @todo Check for malformed names. */
3005 const char *pszTrunk = pszHifName;
3006
3007 /* Issue a warning if the interface is down */
3008 {
3009 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
3010 if (iSock >= 0)
3011 {
3012 struct ifreq Req;
3013
3014 memset(&Req, 0, sizeof(Req));
3015 strncpy(Req.ifr_name, pszHifName, sizeof(Req.ifr_name) - 1);
3016 if (ioctl(iSock, SIOCGIFFLAGS, &Req) >= 0)
3017 if ((Req.ifr_flags & IFF_UP) == 0)
3018 {
3019 setVMRuntimeErrorCallbackF(pVM, pThis, 0, "BridgedInterfaceDown", "Bridged interface %s is down. Guest will not be able to use this interface", pszHifName);
3020 }
3021
3022 close(iSock);
3023 }
3024 }
3025
3026# else
3027# error "PORTME (VBOX_WITH_NETFLT)"
3028# endif
3029
3030 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
3031 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
3032 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
3033 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
3034 RC_CHECK();
3035 char szNetwork[INTNET_MAX_NETWORK_NAME];
3036 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
3037 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
3038 networkName = Bstr(szNetwork);
3039 trunkName = Bstr(pszTrunk);
3040 trunkType = Bstr(TRUNKTYPE_NETFLT);
3041
3042# if defined(RT_OS_DARWIN)
3043 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
3044 if ( strstr(pszHifName, "Wireless")
3045 || strstr(pszHifName, "AirPort" ))
3046 {
3047 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
3048 }
3049# elif defined(RT_OS_LINUX)
3050 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
3051 if (iSock >= 0)
3052 {
3053 struct iwreq WRq;
3054
3055 memset(&WRq, 0, sizeof(WRq));
3056 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
3057 bool fSharedMacOnWire = ioctl(iSock, SIOCGIWNAME, &WRq) >= 0;
3058 close(iSock);
3059 if (fSharedMacOnWire)
3060 {
3061 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
3062 RC_CHECK();
3063 Log(("Set SharedMacOnWire\n"));
3064 }
3065 else
3066 Log(("Failed to get wireless name\n"));
3067 }
3068 else
3069 Log(("Failed to open wireless socket\n"));
3070# elif defined(RT_OS_FREEBSD)
3071 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
3072 if (iSock >= 0)
3073 {
3074 struct ieee80211req WReq;
3075 uint8_t abData[32];
3076
3077 memset(&WReq, 0, sizeof(WReq));
3078 strncpy(WReq.i_name, pszHifName, sizeof(WReq.i_name));
3079 WReq.i_type = IEEE80211_IOC_SSID;
3080 WReq.i_val = -1;
3081 WReq.i_data = abData;
3082 WReq.i_len = sizeof(abData);
3083
3084 bool fSharedMacOnWire = ioctl(iSock, SIOCG80211, &WReq) >= 0;
3085 close(iSock);
3086 if (fSharedMacOnWire)
3087 {
3088 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
3089 RC_CHECK();
3090 Log(("Set SharedMacOnWire\n"));
3091 }
3092 else
3093 Log(("Failed to get wireless name\n"));
3094 }
3095 else
3096 Log(("Failed to open wireless socket\n"));
3097# elif defined(RT_OS_WINDOWS)
3098# define DEVNAME_PREFIX L"\\\\.\\"
3099 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
3100 * there is a pretty long way till there though since we need to obtain the symbolic link name
3101 * for the adapter device we are going to query given the device Guid */
3102
3103
3104 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
3105
3106 wchar_t FileName[MAX_PATH];
3107 wcscpy(FileName, DEVNAME_PREFIX);
3108 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
3109
3110 /* open the device */
3111 HANDLE hDevice = CreateFile(FileName,
3112 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
3113 NULL,
3114 OPEN_EXISTING,
3115 FILE_ATTRIBUTE_NORMAL,
3116 NULL);
3117
3118 if (hDevice != INVALID_HANDLE_VALUE)
3119 {
3120 bool fSharedMacOnWire = false;
3121
3122 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
3123 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
3124 NDIS_PHYSICAL_MEDIUM PhMedium;
3125 DWORD cbResult;
3126 if (DeviceIoControl(hDevice,
3127 IOCTL_NDIS_QUERY_GLOBAL_STATS,
3128 &Oid,
3129 sizeof(Oid),
3130 &PhMedium,
3131 sizeof(PhMedium),
3132 &cbResult,
3133 NULL))
3134 {
3135 /* that was simple, now examine PhMedium */
3136 if ( PhMedium == NdisPhysicalMediumWirelessWan
3137 || PhMedium == NdisPhysicalMediumWirelessLan
3138 || PhMedium == NdisPhysicalMediumNative802_11
3139 || PhMedium == NdisPhysicalMediumBluetooth)
3140 fSharedMacOnWire = true;
3141 }
3142 else
3143 {
3144 int winEr = GetLastError();
3145 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
3146 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
3147 }
3148 CloseHandle(hDevice);
3149
3150 if (fSharedMacOnWire)
3151 {
3152 Log(("this is a wireless adapter"));
3153 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
3154 Log(("Set SharedMacOnWire\n"));
3155 }
3156 else
3157 Log(("this is NOT a wireless adapter"));
3158 }
3159 else
3160 {
3161 int winEr = GetLastError();
3162 AssertLogRelMsgFailed(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
3163 }
3164
3165 CoTaskMemFree(pswzBindName);
3166
3167 pAdaptorComponent.setNull();
3168 /* release the pNc finally */
3169 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3170# else
3171 /** @todo PORTME: wireless detection */
3172# endif
3173
3174# if defined(RT_OS_SOLARIS)
3175# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
3176 /* Zone access restriction, don't allow snopping the global zone. */
3177 zoneid_t ZoneId = getzoneid();
3178 if (ZoneId != GLOBAL_ZONEID)
3179 {
3180 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
3181 }
3182# endif
3183# endif
3184
3185#elif defined(RT_OS_WINDOWS) /* not defined NetFlt */
3186 /* NOTHING TO DO HERE */
3187#elif defined(RT_OS_LINUX)
3188/// @todo aleksey: is there anything to be done here?
3189#elif defined(RT_OS_FREEBSD)
3190/** @todo FreeBSD: Check out this later (HIF networking). */
3191#else
3192# error "Port me"
3193#endif
3194 break;
3195 }
3196
3197 case NetworkAttachmentType_Internal:
3198 {
3199 hrc = aNetworkAdapter->COMGETTER(InternalNetwork)(&str); H();
3200 if (str && *str)
3201 {
3202 if (fSniffer)
3203 {
3204 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
3205 RC_CHECK();
3206 }
3207 else
3208 {
3209 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
3210 RC_CHECK();
3211 }
3212 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
3213 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
3214 rc = CFGMR3InsertStringW(pCfg, "Network", str); RC_CHECK();
3215 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone); RC_CHECK();
3216 networkName = str;
3217 trunkType = Bstr(TRUNKTYPE_WHATEVER);
3218 }
3219 STR_FREE();
3220 break;
3221 }
3222
3223 case NetworkAttachmentType_HostOnly:
3224 {
3225 if (fSniffer)
3226 {
3227 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
3228 RC_CHECK();
3229 }
3230 else
3231 {
3232 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
3233 RC_CHECK();
3234 }
3235
3236 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
3237 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
3238
3239 Bstr HifName;
3240 hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
3241 if (FAILED(hrc))
3242 {
3243 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)\n", hrc));
3244 H();
3245 }
3246
3247 Utf8Str HifNameUtf8(HifName);
3248 const char *pszHifName = HifNameUtf8.raw();
3249 ComPtr<IHostNetworkInterface> hostInterface;
3250 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
3251 if (!SUCCEEDED(rc))
3252 {
3253 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)\n", rc));
3254 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
3255 N_("Inexistent host networking interface, name '%ls'"),
3256 HifName.raw());
3257 }
3258
3259 char szNetwork[INTNET_MAX_NETWORK_NAME];
3260 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
3261
3262#if defined(RT_OS_WINDOWS)
3263# ifndef VBOX_WITH_NETFLT
3264 hrc = E_NOTIMPL;
3265 LogRel(("NetworkAttachmentType_HostOnly: Not Implemented\n"));
3266 H();
3267# else /* defined VBOX_WITH_NETFLT*/
3268 /** @todo r=bird: Put this in a function. */
3269
3270 HostNetworkInterfaceType_T eIfType;
3271 hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
3272 if (FAILED(hrc))
3273 {
3274 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)\n", hrc));
3275 H();
3276 }
3277
3278 if (eIfType != HostNetworkInterfaceType_HostOnly)
3279 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
3280 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
3281 HifName.raw());
3282
3283 hrc = hostInterface->COMGETTER(Id)(&str);
3284 if (FAILED(hrc))
3285 {
3286 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)\n", hrc));
3287 H();
3288 }
3289 Guid hostIFGuid(str);
3290 STR_FREE();
3291
3292 INetCfg *pNc;
3293 ComPtr<INetCfgComponent> pAdaptorComponent;
3294 LPWSTR pszApp;
3295 rc = VERR_INTNET_FLT_IF_NOT_FOUND;
3296
3297 hrc = VBoxNetCfgWinQueryINetCfg(FALSE,
3298 L"VirtualBox",
3299 &pNc,
3300 &pszApp);
3301 Assert(hrc == S_OK);
3302 if (hrc == S_OK)
3303 {
3304 /* get the adapter's INetCfgComponent*/
3305 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
3306 if (hrc != S_OK)
3307 {
3308 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3309 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
3310 H();
3311 }
3312 }
3313#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
3314 char szTrunkName[INTNET_MAX_TRUNK_NAME];
3315 char *pszTrunkName = szTrunkName;
3316 wchar_t * pswzBindName;
3317 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
3318 Assert(hrc == S_OK);
3319 if (hrc == S_OK)
3320 {
3321 int cwBindName = (int)wcslen(pswzBindName) + 1;
3322 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
3323 if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
3324 {
3325 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
3326 pszTrunkName += cbFullBindNamePrefix-1;
3327 if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
3328 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
3329 {
3330 DWORD err = GetLastError();
3331 hrc = HRESULT_FROM_WIN32(err);
3332 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
3333 }
3334 }
3335 else
3336 {
3337 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
3338 /** @todo set appropriate error code */
3339 hrc = E_FAIL;
3340 }
3341
3342 if (hrc != S_OK)
3343 {
3344 AssertFailed();
3345 CoTaskMemFree(pswzBindName);
3346 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3347 H();
3348 }
3349 }
3350 else
3351 {
3352 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3353 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
3354 H();
3355 }
3356
3357
3358 CoTaskMemFree(pswzBindName);
3359
3360 pAdaptorComponent.setNull();
3361 /* release the pNc finally */
3362 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
3363
3364 const char *pszTrunk = szTrunkName;
3365
3366 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
3367 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
3368 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
3369 networkName = Bstr(szNetwork);
3370 trunkName = Bstr(pszTrunk);
3371 trunkType = TRUNKTYPE_NETADP;
3372# endif /* defined VBOX_WITH_NETFLT*/
3373#elif defined(RT_OS_DARWIN)
3374 rc = CFGMR3InsertString(pCfg, "Trunk", pszHifName); RC_CHECK();
3375 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
3376 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
3377 networkName = Bstr(szNetwork);
3378 trunkName = Bstr(pszHifName);
3379 trunkType = TRUNKTYPE_NETADP;
3380#else
3381 rc = CFGMR3InsertString(pCfg, "Trunk", pszHifName); RC_CHECK();
3382 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
3383 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
3384 networkName = Bstr(szNetwork);
3385 trunkName = Bstr(pszHifName);
3386 trunkType = TRUNKTYPE_NETFLT;
3387#endif
3388#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
3389
3390 Bstr tmpAddr, tmpMask;
3391
3392 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPAddress", pszHifName), tmpAddr.asOutParam());
3393 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
3394 {
3395 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPNetMask", pszHifName), tmpMask.asOutParam());
3396 if (SUCCEEDED(hrc) && !tmpMask.isEmpty())
3397 hrc = hostInterface->EnableStaticIpConfig(tmpAddr, tmpMask);
3398 else
3399 hrc = hostInterface->EnableStaticIpConfig(tmpAddr,
3400 Bstr(VBOXNET_IPV4MASK_DEFAULT));
3401 }
3402 else
3403 {
3404 /* Grab the IP number from the 'vboxnetX' instance number (see netif.h) */
3405 hrc = hostInterface->EnableStaticIpConfig(getDefaultIPv4Address(Bstr(pszHifName)),
3406 Bstr(VBOXNET_IPV4MASK_DEFAULT));
3407 }
3408
3409 ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
3410
3411 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6Address", pszHifName), tmpAddr.asOutParam());
3412 if (SUCCEEDED(hrc))
3413 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6NetMask", pszHifName), tmpMask.asOutParam());
3414 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty() && !tmpMask.isEmpty())
3415 {
3416 hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
3417 ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
3418 }
3419#endif
3420 break;
3421 }
3422
3423#if defined(VBOX_WITH_VDE)
3424 case NetworkAttachmentType_VDE:
3425 {
3426 hrc = aNetworkAdapter->COMGETTER(VDENetwork)(&str); H();
3427 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
3428 rc = CFGMR3InsertString(pLunL0, "Driver", "VDE"); RC_CHECK();
3429 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
3430 if (str && *str)
3431 {
3432 rc = CFGMR3InsertStringW(pCfg, "Network", str); RC_CHECK();
3433 networkName = str;
3434 }
3435 STR_FREE();
3436 break;
3437 }
3438#endif
3439
3440 default:
3441 AssertMsgFailed(("should not get here!\n"));
3442 break;
3443 }
3444
3445 /*
3446 * Attempt to attach the driver.
3447 */
3448 switch (eAttachmentType)
3449 {
3450 case NetworkAttachmentType_Null:
3451 break;
3452
3453 case NetworkAttachmentType_Bridged:
3454 case NetworkAttachmentType_Internal:
3455 case NetworkAttachmentType_HostOnly:
3456 case NetworkAttachmentType_NAT:
3457#if defined(VBOX_WITH_VDE)
3458 case NetworkAttachmentType_VDE:
3459#endif
3460 {
3461 if (SUCCEEDED(hrc) && SUCCEEDED(rc))
3462 {
3463 if (fAttachDetach)
3464 {
3465 rc = PDMR3DriverAttach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /* ppBase */);
3466 //AssertRC(rc);
3467 }
3468
3469 {
3470 /** @todo pritesh: get the dhcp server name from the
3471 * previous network configuration and then stop the server
3472 * else it may conflict with the dhcp server running with
3473 * the current attachment type
3474 */
3475 /* Stop the hostonly DHCP Server */
3476 }
3477
3478 if (!networkName.isEmpty())
3479 {
3480 /*
3481 * Until we implement service reference counters DHCP Server will be stopped
3482 * by DHCPServerRunner destructor.
3483 */
3484 ComPtr<IDHCPServer> dhcpServer;
3485 hrc = virtualBox->FindDHCPServerByNetworkName(networkName, dhcpServer.asOutParam());
3486 if (SUCCEEDED(hrc))
3487 {
3488 /* there is a DHCP server available for this network */
3489 BOOL fEnabled;
3490 hrc = dhcpServer->COMGETTER(Enabled)(&fEnabled);
3491 if (FAILED(hrc))
3492 {
3493 LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (%Rhrc)", hrc));
3494 H();
3495 }
3496
3497 if (fEnabled)
3498 hrc = dhcpServer->Start(networkName, trunkName, trunkType);
3499 }
3500 else
3501 hrc = S_OK;
3502 }
3503 }
3504
3505 break;
3506 }
3507
3508 default:
3509 AssertMsgFailed(("should not get here!\n"));
3510 break;
3511 }
3512
3513 pThis->meAttachmentType[uInstance] = eAttachmentType;
3514
3515#undef STR_FREE
3516#undef H
3517#undef RC_CHECK
3518
3519 return VINF_SUCCESS;
3520}
3521
3522#ifdef VBOX_WITH_GUEST_PROPS
3523/**
3524 * Set an array of guest properties
3525 */
3526static void configSetProperties(VMMDev * const pVMMDev, void *names,
3527 void *values, void *timestamps, void *flags)
3528{
3529 VBOXHGCMSVCPARM parms[4];
3530
3531 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
3532 parms[0].u.pointer.addr = names;
3533 parms[0].u.pointer.size = 0; /* We don't actually care. */
3534 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
3535 parms[1].u.pointer.addr = values;
3536 parms[1].u.pointer.size = 0; /* We don't actually care. */
3537 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
3538 parms[2].u.pointer.addr = timestamps;
3539 parms[2].u.pointer.size = 0; /* We don't actually care. */
3540 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
3541 parms[3].u.pointer.addr = flags;
3542 parms[3].u.pointer.size = 0; /* We don't actually care. */
3543
3544 pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4,
3545 &parms[0]);
3546}
3547
3548/**
3549 * Set a single guest property
3550 */
3551static void configSetProperty(VMMDev * const pVMMDev, const char *pszName,
3552 const char *pszValue, const char *pszFlags)
3553{
3554 VBOXHGCMSVCPARM parms[4];
3555
3556 AssertPtrReturnVoid(pszName);
3557 AssertPtrReturnVoid(pszValue);
3558 AssertPtrReturnVoid(pszFlags);
3559 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
3560 parms[0].u.pointer.addr = (void *)pszName;
3561 parms[0].u.pointer.size = strlen(pszName) + 1;
3562 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
3563 parms[1].u.pointer.addr = (void *)pszValue;
3564 parms[1].u.pointer.size = strlen(pszValue) + 1;
3565 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
3566 parms[2].u.pointer.addr = (void *)pszFlags;
3567 parms[2].u.pointer.size = strlen(pszFlags) + 1;
3568 pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3,
3569 &parms[0]);
3570}
3571
3572/**
3573 * Set the global flags value by calling the service
3574 * @returns the status returned by the call to the service
3575 *
3576 * @param pTable the service instance handle
3577 * @param eFlags the flags to set
3578 */
3579int configSetGlobalPropertyFlags(VMMDev * const pVMMDev,
3580 guestProp::ePropFlags eFlags)
3581{
3582 VBOXHGCMSVCPARM paParm;
3583 paParm.setUInt32(eFlags);
3584 int rc = pVMMDev->hgcmHostCall ("VBoxGuestPropSvc",
3585 guestProp::SET_GLOBAL_FLAGS_HOST, 1,
3586 &paParm);
3587 if (RT_FAILURE(rc))
3588 {
3589 char szFlags[guestProp::MAX_FLAGS_LEN];
3590 if (RT_FAILURE(writeFlags(eFlags, szFlags)))
3591 Log(("Failed to set the global flags.\n"));
3592 else
3593 Log(("Failed to set the global flags \"%s\".\n", szFlags));
3594 }
3595 return rc;
3596}
3597#endif /* VBOX_WITH_GUEST_PROPS */
3598
3599/**
3600 * Set up the Guest Property service, populate it with properties read from
3601 * the machine XML and set a couple of initial properties.
3602 */
3603/* static */ int Console::configGuestProperties(void *pvConsole)
3604{
3605#ifdef VBOX_WITH_GUEST_PROPS
3606 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
3607 ComObjPtr<Console> pConsole = static_cast <Console *> (pvConsole);
3608
3609 /* Load the service */
3610 int rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
3611
3612 if (RT_FAILURE(rc))
3613 {
3614 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
3615 /* That is not a fatal failure. */
3616 rc = VINF_SUCCESS;
3617 }
3618 else
3619 {
3620 /*
3621 * Initialize built-in properties that can be changed and saved.
3622 *
3623 * These are typically transient properties that the guest cannot
3624 * change.
3625 */
3626
3627 /* Sysprep execution by VBoxService. */
3628 configSetProperty(pConsole->mVMMDev,
3629 "/VirtualBox/HostGuest/SysprepExec", "",
3630 "TRANSIENT, RDONLYGUEST");
3631 configSetProperty(pConsole->mVMMDev,
3632 "/VirtualBox/HostGuest/SysprepArgs", "",
3633 "TRANSIENT, RDONLYGUEST");
3634
3635 /*
3636 * Pull over the properties from the server.
3637 */
3638 SafeArray<BSTR> namesOut;
3639 SafeArray<BSTR> valuesOut;
3640 SafeArray<ULONG64> timestampsOut;
3641 SafeArray<BSTR> flagsOut;
3642 HRESULT hrc;
3643 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
3644 ComSafeArrayAsOutParam(valuesOut),
3645 ComSafeArrayAsOutParam(timestampsOut),
3646 ComSafeArrayAsOutParam(flagsOut));
3647 AssertMsgReturn(SUCCEEDED(hrc), ("hrc=%Rrc\n", hrc), VERR_GENERAL_FAILURE);
3648 size_t cProps = namesOut.size();
3649 size_t cAlloc = cProps + 1;
3650 if ( valuesOut.size() != cProps
3651 || timestampsOut.size() != cProps
3652 || flagsOut.size() != cProps
3653 )
3654 AssertFailedReturn(VERR_INVALID_PARAMETER);
3655
3656 char **papszNames, **papszValues, **papszFlags;
3657 char szEmpty[] = "";
3658 ULONG64 *pau64Timestamps;
3659 papszNames = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
3660 papszValues = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
3661 pau64Timestamps = (ULONG64 *)RTMemTmpAllocZ(sizeof(ULONG64) * cAlloc);
3662 papszFlags = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
3663 if (papszNames && papszValues && pau64Timestamps && papszFlags)
3664 {
3665 for (unsigned i = 0; RT_SUCCESS(rc) && i < cProps; ++i)
3666 {
3667 AssertPtrReturn(namesOut[i], VERR_INVALID_PARAMETER);
3668 rc = RTUtf16ToUtf8(namesOut[i], &papszNames[i]);
3669 if (RT_FAILURE(rc))
3670 break;
3671 if (valuesOut[i])
3672 rc = RTUtf16ToUtf8(valuesOut[i], &papszValues[i]);
3673 else
3674 papszValues[i] = szEmpty;
3675 if (RT_FAILURE(rc))
3676 break;
3677 pau64Timestamps[i] = timestampsOut[i];
3678 if (flagsOut[i])
3679 rc = RTUtf16ToUtf8(flagsOut[i], &papszFlags[i]);
3680 else
3681 papszFlags[i] = szEmpty;
3682 }
3683 if (RT_SUCCESS(rc))
3684 configSetProperties(pConsole->mVMMDev,
3685 (void *)papszNames,
3686 (void *)papszValues,
3687 (void *)pau64Timestamps,
3688 (void *)papszFlags);
3689 for (unsigned i = 0; i < cProps; ++i)
3690 {
3691 RTStrFree(papszNames[i]);
3692 if (valuesOut[i])
3693 RTStrFree(papszValues[i]);
3694 if (flagsOut[i])
3695 RTStrFree(papszFlags[i]);
3696 }
3697 }
3698 else
3699 rc = VERR_NO_MEMORY;
3700 RTMemTmpFree(papszNames);
3701 RTMemTmpFree(papszValues);
3702 RTMemTmpFree(pau64Timestamps);
3703 RTMemTmpFree(papszFlags);
3704 AssertRCReturn(rc, rc);
3705
3706 /*
3707 * These properties have to be set before pulling over the properties
3708 * from the machine XML, to ensure that properties saved in the XML
3709 * will override them.
3710 */
3711 /* Set the VBox version string as a guest property */
3712 configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxVer",
3713 VBOX_VERSION_STRING, "TRANSIENT, RDONLYGUEST");
3714 /* Set the VBox SVN revision as a guest property */
3715 configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxRev",
3716 RTBldCfgRevisionStr(), "TRANSIENT, RDONLYGUEST");
3717
3718 /*
3719 * Register the host notification callback
3720 */
3721 HGCMSVCEXTHANDLE hDummy;
3722 HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestPropSvc",
3723 Console::doGuestPropNotification,
3724 pvConsole);
3725
3726#ifdef VBOX_WITH_GUEST_PROPS_RDONLY_GUEST
3727 rc = configSetGlobalPropertyFlags(pConsole->mVMMDev,
3728 guestProp::RDONLYGUEST);
3729 AssertRCReturn(rc, rc);
3730#endif
3731
3732 Log(("Set VBoxGuestPropSvc property store\n"));
3733 }
3734 return VINF_SUCCESS;
3735#else /* !VBOX_WITH_GUEST_PROPS */
3736 return VERR_NOT_SUPPORTED;
3737#endif /* !VBOX_WITH_GUEST_PROPS */
3738}
3739
3740/**
3741 * Set up the Guest Control service.
3742 */
3743/* static */ int Console::configGuestControl(void *pvConsole)
3744{
3745#ifdef VBOX_WITH_GUEST_CONTROL
3746 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
3747 ComObjPtr<Console> pConsole = static_cast <Console *> (pvConsole);
3748
3749 /* Load the service */
3750 int rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestControlSvc", "VBoxGuestControlSvc");
3751
3752 if (RT_FAILURE(rc))
3753 {
3754 LogRel(("VBoxGuestControlSvc is not available. rc = %Rrc\n", rc));
3755 /* That is not a fatal failure. */
3756 rc = VINF_SUCCESS;
3757 }
3758 else
3759 {
3760 HGCMSVCEXTHANDLE hDummy;
3761 rc = HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestControlSvc",
3762 &Guest::doGuestCtrlNotification,
3763 pConsole->getGuest());
3764 if (RT_FAILURE(rc))
3765 Log(("Cannot register VBoxGuestControlSvc extension!\n"));
3766 else
3767 Log(("VBoxGuestControlSvc loaded\n"));
3768 }
3769
3770 return rc;
3771#else /* !VBOX_WITH_GUEST_CONTROL */
3772 return VERR_NOT_SUPPORTED;
3773#endif /* !VBOX_WITH_GUEST_CONTROL */
3774}
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