VirtualBox

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

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

Main,NAT: Always pass the NAT network via CFGM. Use the network derived from the slot number as default.

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