VirtualBox

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

Last change on this file since 17077 was 17077, checked in by vboxsync, 16 years ago

pass IDE controller type as string in config

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 108.7 KB
Line 
1/* $Id: ConsoleImpl2.cpp 17077 2009-02-24 16:58:15Z 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
6 * finds problematic to optimize so we can disable optimizations
7 * and later, perhaps, find a real solution for it.
8 */
9
10/*
11 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
12 *
13 * This file is part of VirtualBox Open Source Edition (OSE), as
14 * available from http://www.virtualbox.org. This file is free software;
15 * you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License (GPL) as published by the Free Software
17 * Foundation, in version 2 as it comes in the "COPYING" file of the
18 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
22 * Clara, CA 95054 USA or visit http://www.sun.com if you need
23 * additional information or have any questions.
24 */
25
26/*******************************************************************************
27* Header Files *
28*******************************************************************************/
29#include "ConsoleImpl.h"
30#include "DisplayImpl.h"
31#include "VMMDev.h"
32
33// generated header
34#include "SchemaDefs.h"
35
36#include "Logging.h"
37
38#include <iprt/string.h>
39#include <iprt/path.h>
40#include <iprt/dir.h>
41#include <iprt/param.h>
42
43#include <VBox/vmapi.h>
44#include <VBox/err.h>
45#include <VBox/version.h>
46#include <VBox/HostServices/VBoxClipboardSvc.h>
47#ifdef VBOX_WITH_CROGL
48#include <VBox/HostServices/VBoxCrOpenGLSvc.h>
49#endif
50#ifdef VBOX_WITH_GUEST_PROPS
51# include <VBox/HostServices/GuestPropertySvc.h>
52# include <VBox/com/defs.h>
53# include <VBox/com/array.h>
54# include <hgcm/HGCM.h> /** @todo it should be possible to register a service
55 * extension using a VMMDev callback. */
56# include <vector>
57#endif /* VBOX_WITH_GUEST_PROPS */
58#include <VBox/intnet.h>
59
60#include <VBox/com/string.h>
61#include <VBox/com/array.h>
62
63#if defined(RT_OS_SOLARIS) && defined(VBOX_WITH_NETFLT)
64# include <zone.h>
65#endif
66
67#if defined(RT_OS_LINUX) && defined(VBOX_WITH_NETFLT)
68# include <unistd.h>
69# include <sys/ioctl.h>
70# include <sys/socket.h>
71# include <linux/types.h>
72# include <linux/if.h>
73# include <linux/wireless.h>
74#endif
75
76#if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
77# include <VBox/WinNetConfig.h>
78# include <Ntddndis.h>
79# include <devguid.h>
80#endif
81
82/**
83 * Translate IDEControllerType_T to string representation.
84 */
85const char* controllerString(IDEControllerType_T enmType)
86{
87 switch (enmType)
88 {
89 case IDEControllerType_PIIX3:
90 return "PIIX3";
91 case IDEControllerType_PIIX4:
92 return "PIIX4";
93 case IDEControllerType_ICH6:
94 return "ICH6";
95 default:
96 return "Unknown";
97 }
98}
99/*
100 * VC++ 8 / amd64 has some serious trouble with this function.
101 * As a temporary measure, we'll drop global optimizations.
102 */
103#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
104# pragma optimize("g", off)
105#endif
106
107/**
108 * Construct the VM configuration tree (CFGM).
109 *
110 * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
111 * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
112 * is done here.
113 *
114 * @param pVM VM handle.
115 * @param pvConsole Pointer to the VMPowerUpTask object.
116 * @return VBox status code.
117 *
118 * @note Locks the Console object for writing.
119 */
120DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
121{
122 LogFlowFuncEnter();
123 /* Note: hardcoded assumption about number of slots; see rom bios */
124 bool afPciDeviceNo[32] = {false};
125
126#if !defined (VBOX_WITH_XPCOM)
127 {
128 /* initialize COM */
129 HRESULT hrc = CoInitializeEx(NULL,
130 COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
131 COINIT_SPEED_OVER_MEMORY);
132 LogFlow (("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
133 AssertComRCReturn (hrc, VERR_GENERAL_FAILURE);
134 }
135#endif
136
137 AssertReturn (pvConsole, VERR_GENERAL_FAILURE);
138 ComObjPtr <Console> pConsole = static_cast <Console *> (pvConsole);
139
140 AutoCaller autoCaller (pConsole);
141 AssertComRCReturn (autoCaller.rc(), VERR_ACCESS_DENIED);
142
143 /* lock the console because we widely use internal fields and methods */
144 AutoWriteLock alock (pConsole);
145
146 ComPtr <IMachine> pMachine = pConsole->machine();
147
148 int rc;
149 HRESULT hrc;
150 char *psz = NULL;
151 BSTR str = NULL;
152
153 Bstr bstr; /* use this bstr when calling COM methods instead
154 of str as it manages memory! */
155
156#define STR_CONV() do { rc = RTUtf16ToUtf8(str, &psz); RC_CHECK(); } while (0)
157#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } if (psz) { RTStrFree(psz); psz = NULL; } } while (0)
158#define RC_CHECK() do { if (RT_FAILURE(rc)) { AssertMsgFailed(("rc=%Rrc\n", rc)); STR_FREE(); return rc; } } while (0)
159#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
160
161 /*
162 * Get necessary objects and frequently used parameters.
163 */
164 ComPtr<IVirtualBox> virtualBox;
165 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
166
167 ComPtr<IHost> host;
168 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
169
170 ComPtr <ISystemProperties> systemProperties;
171 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
172
173 ComPtr<IBIOSSettings> biosSettings;
174 hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
175
176 Guid uuid;
177 hrc = pMachine->COMGETTER(Id)(uuid.asOutParam()); H();
178 PCRTUUID pUuid = uuid.raw();
179
180 ULONG cRamMBs;
181 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
182
183 ULONG cCpus = 1;
184#ifdef VBOX_WITH_SMP_GUESTS
185 hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
186#endif
187
188 /*
189 * Get root node first.
190 * This is the only node in the tree.
191 */
192 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
193 Assert(pRoot);
194
195 /*
196 * Set the root (and VMM) level values.
197 */
198 hrc = pMachine->COMGETTER(Name)(&str); H();
199 STR_CONV();
200 rc = CFGMR3InsertString(pRoot, "Name", psz); RC_CHECK();
201 STR_FREE();
202 rc = CFGMR3InsertBytes(pRoot, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
203 rc = CFGMR3InsertInteger(pRoot, "RamSize", cRamMBs * _1M); RC_CHECK();
204 rc = CFGMR3InsertInteger(pRoot, "NumCPUs", cCpus); RC_CHECK();
205 rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10); RC_CHECK();
206 rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1); /* boolean */ RC_CHECK();
207 rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1); /* boolean */ RC_CHECK();
208 /** @todo Config: RawR0, PATMEnabled and CASMEnabled needs attention later. */
209 rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1); /* boolean */ RC_CHECK();
210 rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1); /* boolean */ RC_CHECK();
211
212 /* hardware virtualization extensions */
213 TSBool_T hwVirtExEnabled;
214 BOOL fHWVirtExEnabled;
215 hrc = pMachine->COMGETTER(HWVirtExEnabled)(&hwVirtExEnabled); H();
216 if (hwVirtExEnabled == TSBool_Default)
217 {
218 /* check the default value */
219 hrc = systemProperties->COMGETTER(HWVirtExEnabled)(&fHWVirtExEnabled); H();
220 }
221 else
222 fHWVirtExEnabled = (hwVirtExEnabled == TSBool_True);
223#ifdef RT_OS_DARWIN
224 rc = CFGMR3InsertInteger(pRoot, "HwVirtExtForced", fHWVirtExEnabled); RC_CHECK();
225#else
226 rc = CFGMR3InsertInteger(pRoot, "HwVirtExtForced", 0); RC_CHECK();
227#endif
228
229 PCFGMNODE pHWVirtExt;
230 rc = CFGMR3InsertNode(pRoot, "HWVirtExt", &pHWVirtExt); RC_CHECK();
231 if (fHWVirtExEnabled)
232 {
233 rc = CFGMR3InsertInteger(pHWVirtExt, "Enabled", 1); RC_CHECK();
234
235 /* Indicate whether 64-bit guests are supported or not. */
236 /** @todo This is currently only forced off on 32-bit hosts only because it
237 * makes a lof of difference there (REM and Solaris performance).
238 */
239
240 Bstr osTypeId;
241 hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
242
243 ComPtr <IGuestOSType> guestOSType;
244 hrc = virtualBox->GetGuestOSType(osTypeId, guestOSType.asOutParam()); H();
245
246 BOOL fSupportsLongMode = false;
247 hrc = host->GetProcessorFeature(ProcessorFeature_LongMode,
248 &fSupportsLongMode); H();
249 BOOL fIs64BitGuest = false;
250 hrc = guestOSType->COMGETTER(Is64Bit)(&fIs64BitGuest); H();
251
252 if (fSupportsLongMode && fIs64BitGuest)
253 {
254 rc = CFGMR3InsertInteger(pHWVirtExt, "64bitEnabled", 1); RC_CHECK();
255#if ARCH_BITS == 32 /* The recompiler must use load VBoxREM64 (32-bit host only). */
256 PCFGMNODE pREM;
257 rc = CFGMR3InsertNode(pRoot, "REM", &pREM); RC_CHECK();
258 rc = CFGMR3InsertInteger(pREM, "64bitEnabled", 1); RC_CHECK();
259#endif
260 }
261#if ARCH_BITS == 32 /* 32-bit guests only. */
262 else
263 {
264 rc = CFGMR3InsertInteger(pHWVirtExt, "64bitEnabled", 0); RC_CHECK();
265 }
266#endif
267 }
268
269 /* Nested paging (VT-x/AMD-V) */
270 BOOL fEnableNestedPaging = false;
271 hrc = pMachine->COMGETTER(HWVirtExNestedPagingEnabled)(&fEnableNestedPaging); H();
272 rc = CFGMR3InsertInteger(pRoot, "EnableNestedPaging", fEnableNestedPaging); RC_CHECK();
273
274 /* VPID (VT-x) */
275 BOOL fEnableVPID = false;
276 hrc = pMachine->COMGETTER(HWVirtExVPIDEnabled)(&fEnableVPID); H();
277 rc = CFGMR3InsertInteger(pRoot, "EnableVPID", fEnableVPID); RC_CHECK();
278
279 /* Physical Address Extension (PAE) */
280 BOOL fEnablePAE = false;
281 hrc = pMachine->COMGETTER(PAEEnabled)(&fEnablePAE); H();
282 rc = CFGMR3InsertInteger(pRoot, "EnablePAE", fEnablePAE); RC_CHECK();
283
284 BOOL fIOAPIC;
285 hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
286
287 BOOL fPXEDebug;
288 hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
289
290 /*
291 * Virtual IDE controller type.
292 */
293 IDEControllerType_T controllerType;
294 hrc = biosSettings->COMGETTER(IDEControllerType)(&controllerType); H();
295
296 /*
297 * PDM config.
298 * Load drivers in VBoxC.[so|dll]
299 */
300 PCFGMNODE pPDM;
301 PCFGMNODE pDrivers;
302 PCFGMNODE pMod;
303 rc = CFGMR3InsertNode(pRoot, "PDM", &pPDM); RC_CHECK();
304 rc = CFGMR3InsertNode(pPDM, "Drivers", &pDrivers); RC_CHECK();
305 rc = CFGMR3InsertNode(pDrivers, "VBoxC", &pMod); RC_CHECK();
306#ifdef VBOX_WITH_XPCOM
307 // VBoxC is located in the components subdirectory
308 char szPathVBoxC[RTPATH_MAX];
309 rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
310 strcat(szPathVBoxC, "/components/VBoxC");
311 rc = CFGMR3InsertString(pMod, "Path", szPathVBoxC); RC_CHECK();
312#else
313 rc = CFGMR3InsertString(pMod, "Path", "VBoxC"); RC_CHECK();
314#endif
315
316 /*
317 * Devices
318 */
319 PCFGMNODE pDevices = NULL; /* /Devices */
320 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
321 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
322 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
323 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
324 PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
325 PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
326 PCFGMNODE pIdeInst = NULL; /* /Devices/piix3ide/0/ */
327 PCFGMNODE pSataInst = NULL; /* /Devices/ahci/0/ */
328 PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
329
330 rc = CFGMR3InsertNode(pRoot, "Devices", &pDevices); RC_CHECK();
331
332 /*
333 * PC Arch.
334 */
335 rc = CFGMR3InsertNode(pDevices, "pcarch", &pDev); RC_CHECK();
336 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
337 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
338 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
339
340 BOOL fEfiEnabled;
341 /** @todo: implement appropriate getter */
342#ifdef VBOX_WITH_EFI
343 fEfiEnabled = true;
344#else
345 fEfiEnabled = false;
346#endif
347
348 if (fEfiEnabled)
349 {
350 rc = CFGMR3InsertNode(pDevices, "efi", &pDev); RC_CHECK();
351 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
352 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
353 }
354
355 /*
356 * PC Bios.
357 */
358 if (!fEfiEnabled)
359 {
360 rc = CFGMR3InsertNode(pDevices, "pcbios", &pDev); RC_CHECK();
361 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
362 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
363 rc = CFGMR3InsertNode(pInst, "Config", &pBiosCfg); RC_CHECK();
364 rc = CFGMR3InsertInteger(pBiosCfg, "RamSize", cRamMBs * _1M); RC_CHECK();
365 rc = CFGMR3InsertInteger(pBiosCfg, "NumCPUs", cCpus); RC_CHECK();
366 rc = CFGMR3InsertString(pBiosCfg, "HardDiskDevice", "piix3ide"); RC_CHECK();
367 rc = CFGMR3InsertString(pBiosCfg, "FloppyDevice", "i82078"); RC_CHECK();
368 rc = CFGMR3InsertInteger(pBiosCfg, "IOAPIC", fIOAPIC); RC_CHECK();
369 rc = CFGMR3InsertInteger(pBiosCfg, "PXEDebug", fPXEDebug); RC_CHECK();
370 rc = CFGMR3InsertBytes(pBiosCfg, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
371
372 DeviceType_T bootDevice;
373 if (SchemaDefs::MaxBootPosition > 9)
374 {
375 AssertMsgFailed (("Too many boot devices %d\n",
376 SchemaDefs::MaxBootPosition));
377 return VERR_INVALID_PARAMETER;
378 }
379
380 for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; pos ++)
381 {
382 hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
383
384 char szParamName[] = "BootDeviceX";
385 szParamName[sizeof (szParamName) - 2] = ((char (pos - 1)) + '0');
386
387 const char *pszBootDevice;
388 switch (bootDevice)
389 {
390 case DeviceType_Null:
391 pszBootDevice = "NONE";
392 break;
393 case DeviceType_HardDisk:
394 pszBootDevice = "IDE";
395 break;
396 case DeviceType_DVD:
397 pszBootDevice = "DVD";
398 break;
399 case DeviceType_Floppy:
400 pszBootDevice = "FLOPPY";
401 break;
402 case DeviceType_Network:
403 pszBootDevice = "LAN";
404 break;
405 default:
406 AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
407 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
408 N_("Invalid boot device '%d'"), bootDevice);
409 }
410 rc = CFGMR3InsertString(pBiosCfg, szParamName, pszBootDevice); RC_CHECK();
411 }
412 }
413
414 /*
415 * The time offset
416 */
417 LONG64 timeOffset;
418 hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
419 PCFGMNODE pTMNode;
420 rc = CFGMR3InsertNode(pRoot, "TM", &pTMNode); RC_CHECK();
421 rc = CFGMR3InsertInteger(pTMNode, "UTCOffset", timeOffset * 1000000); RC_CHECK();
422
423 /*
424 * DMA
425 */
426 rc = CFGMR3InsertNode(pDevices, "8237A", &pDev); RC_CHECK();
427 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
428 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
429
430 /*
431 * PCI buses.
432 */
433 rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */ RC_CHECK();
434 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
435 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
436 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
437 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
438
439#if 0 /* enable this to test PCI bridging */
440 rc = CFGMR3InsertNode(pDevices, "pcibridge", &pDev); RC_CHECK();
441 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
442 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
443 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
444 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 14); RC_CHECK();
445 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
446 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 0);/* -> pci[0] */ RC_CHECK();
447
448 rc = CFGMR3InsertNode(pDev, "1", &pInst); RC_CHECK();
449 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
450 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
451 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 1); RC_CHECK();
452 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
453 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
454
455 rc = CFGMR3InsertNode(pDev, "2", &pInst); RC_CHECK();
456 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
457 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
458 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 3); RC_CHECK();
459 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
460 rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
461#endif
462
463 /*
464 * High Precision Event Timer (HPET)
465 */
466 BOOL fHpetEnabled;
467 /** @todo: implement appropriate getter */
468#ifdef VBOX_WITH_HPET
469 fHpetEnabled = true;
470#else
471 fHpetEnabled = false;
472#endif
473
474 if (fHpetEnabled)
475 {
476 rc = CFGMR3InsertNode(pDevices, "hpet", &pDev); RC_CHECK();
477 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
478 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
479 }
480
481 /*
482 * System Management Controller (SMC)
483 */
484 BOOL fSmcEnabled;
485 /** @todo: implement appropriate getter */
486#ifdef VBOX_WITH_SMC
487 fSmcEnabled = true;
488#else
489 fSmcEnabled = false;
490#endif
491 if (fSmcEnabled)
492 {
493 rc = CFGMR3InsertNode(pDevices, "smc", &pDev); RC_CHECK();
494 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
495 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
496 }
497
498 /*
499 * Low Pin Count (LPC) bus
500 */
501 BOOL fLpcEnabled;
502 /** @todo: implement appropriate getter */
503#ifdef VBOX_WITH_LPC
504 fLpcEnabled = true;
505#else
506 fLpcEnabled = false;
507#endif
508
509 if (fLpcEnabled)
510 {
511 rc = CFGMR3InsertNode(pDevices, "lpc", &pDev); RC_CHECK();
512 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
513 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
514 }
515
516 /*
517 * PS/2 keyboard & mouse.
518 */
519 rc = CFGMR3InsertNode(pDevices, "pckbd", &pDev); RC_CHECK();
520 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
521 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
522 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
523
524 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
525 rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); RC_CHECK();
526 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
527 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); RC_CHECK();
528
529 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
530 rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard"); RC_CHECK();
531 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
532 Keyboard *pKeyboard = pConsole->mKeyboard;
533 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pKeyboard); RC_CHECK();
534
535 rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL0); RC_CHECK();
536 rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); RC_CHECK();
537 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
538 rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); RC_CHECK();
539
540 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
541 rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse"); RC_CHECK();
542 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
543 Mouse *pMouse = pConsole->mMouse;
544 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse); RC_CHECK();
545
546 /*
547 * i82078 Floppy drive controller
548 */
549 ComPtr<IFloppyDrive> floppyDrive;
550 hrc = pMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam()); H();
551 BOOL fFdcEnabled;
552 hrc = floppyDrive->COMGETTER(Enabled)(&fFdcEnabled); H();
553 if (fFdcEnabled)
554 {
555 rc = CFGMR3InsertNode(pDevices, "i82078", &pDev); RC_CHECK();
556 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
557 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); RC_CHECK();
558 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
559 rc = CFGMR3InsertInteger(pCfg, "IRQ", 6); RC_CHECK();
560 rc = CFGMR3InsertInteger(pCfg, "DMA", 2); RC_CHECK();
561 rc = CFGMR3InsertInteger(pCfg, "MemMapped", 0 ); RC_CHECK();
562 rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x3f0); RC_CHECK();
563
564 /* Attach the status driver */
565 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
566 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
567 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
568 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapFDLeds[0]); RC_CHECK();
569 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
570 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
571
572 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
573
574 ComPtr<IFloppyImage> floppyImage;
575 hrc = floppyDrive->GetImage(floppyImage.asOutParam()); H();
576 if (floppyImage)
577 {
578 pConsole->meFloppyState = DriveState_ImageMounted;
579 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
580 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
581 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
582 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
583
584 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
585 rc = CFGMR3InsertString(pLunL1, "Driver", "RawImage"); RC_CHECK();
586 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
587 hrc = floppyImage->COMGETTER(Location)(&str); H();
588 STR_CONV();
589 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
590 STR_FREE();
591 }
592 else
593 {
594 ComPtr<IHostFloppyDrive> hostFloppyDrive;
595 hrc = floppyDrive->GetHostDrive(hostFloppyDrive.asOutParam()); H();
596 if (hostFloppyDrive)
597 {
598 pConsole->meFloppyState = DriveState_HostDriveCaptured;
599 rc = CFGMR3InsertString(pLunL0, "Driver", "HostFloppy"); RC_CHECK();
600 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
601 hrc = hostFloppyDrive->COMGETTER(Name)(&str); H();
602 STR_CONV();
603 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
604 STR_FREE();
605 }
606 else
607 {
608 pConsole->meFloppyState = DriveState_NotMounted;
609 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
610 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
611 rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
612 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
613 }
614 }
615 }
616
617 /*
618 * ACPI
619 */
620 BOOL fACPI;
621 hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
622 if (fACPI)
623 {
624 rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); RC_CHECK();
625 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
626 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
627 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
628 rc = CFGMR3InsertInteger(pCfg, "RamSize", cRamMBs * _1M); RC_CHECK();
629 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
630
631 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
632 rc = CFGMR3InsertInteger(pCfg, "FdcEnabled", fFdcEnabled); RC_CHECK();
633#ifdef VBOX_WITH_HPET
634 rc = CFGMR3InsertInteger(pCfg, "HpetEnabled", fHpetEnabled); RC_CHECK();
635#endif
636#ifdef VBOX_WITH_SMC
637 rc = CFGMR3InsertInteger(pCfg, "SmcEnabled", fSmcEnabled); RC_CHECK();
638#endif
639 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
640 Assert(!afPciDeviceNo[7]);
641 afPciDeviceNo[7] = true;
642 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
643
644 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
645 rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
646 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
647 }
648
649 /*
650 * i8254 Programmable Interval Timer And Dummy Speaker
651 */
652 rc = CFGMR3InsertNode(pDevices, "i8254", &pDev); RC_CHECK();
653 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
654 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
655#ifdef DEBUG
656 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
657#endif
658
659 /*
660 * i8259 Programmable Interrupt Controller.
661 */
662 rc = CFGMR3InsertNode(pDevices, "i8259", &pDev); RC_CHECK();
663 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
664 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
665 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
666
667 /*
668 * Advanced Programmable Interrupt Controller.
669 * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
670 * thus only single insert
671 */
672 rc = CFGMR3InsertNode(pDevices, "apic", &pDev); RC_CHECK();
673 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
674 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
675 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
676 rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
677 rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
678
679 /* SMP: @todo: IOAPIC may be required for SMP configs */
680 if (fIOAPIC)
681 {
682 /*
683 * I/O Advanced Programmable Interrupt Controller.
684 */
685 rc = CFGMR3InsertNode(pDevices, "ioapic", &pDev); RC_CHECK();
686 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
687 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
688 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
689 }
690
691 /*
692 * RTC MC146818.
693 */
694 rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); RC_CHECK();
695 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
696 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
697
698 /*
699 * VGA.
700 */
701 rc = CFGMR3InsertNode(pDevices, "vga", &pDev); RC_CHECK();
702 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
703 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
704 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 2); RC_CHECK();
705 Assert(!afPciDeviceNo[2]);
706 afPciDeviceNo[2] = true;
707 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
708 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
709 hrc = pMachine->COMGETTER(VRAMSize)(&cRamMBs); H();
710 rc = CFGMR3InsertInteger(pCfg, "VRamSize", cRamMBs * _1M); RC_CHECK();
711#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
712 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", fHWVirtExEnabled); RC_CHECK();
713#endif
714
715 /*
716 * BIOS logo
717 */
718 BOOL fFadeIn;
719 hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
720 rc = CFGMR3InsertInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0); RC_CHECK();
721 BOOL fFadeOut;
722 hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
723 rc = CFGMR3InsertInteger(pCfg, "FadeOut", fFadeOut ? 1: 0); RC_CHECK();
724 ULONG logoDisplayTime;
725 hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
726 rc = CFGMR3InsertInteger(pCfg, "LogoTime", logoDisplayTime); RC_CHECK();
727 Bstr logoImagePath;
728 hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
729 rc = CFGMR3InsertString(pCfg, "LogoFile", logoImagePath ? Utf8Str(logoImagePath) : ""); RC_CHECK();
730
731 /*
732 * Boot menu
733 */
734 BIOSBootMenuMode_T bootMenuMode;
735 int value;
736 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
737 switch (bootMenuMode)
738 {
739 case BIOSBootMenuMode_Disabled:
740 value = 0;
741 break;
742 case BIOSBootMenuMode_MenuOnly:
743 value = 1;
744 break;
745 default:
746 value = 2;
747 }
748 rc = CFGMR3InsertInteger(pCfg, "ShowBootMenu", value); RC_CHECK();
749
750 /* Custom VESA mode list */
751 unsigned cModes = 0;
752 for (unsigned iMode = 1; iMode <= 16; iMode++)
753 {
754 char szExtraDataKey[sizeof("CustomVideoModeXX")];
755 RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%d", iMode);
756 hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), &str); H();
757 if (!str || !*str)
758 break;
759 STR_CONV();
760 rc = CFGMR3InsertString(pCfg, szExtraDataKey, psz);
761 STR_FREE();
762 cModes++;
763 }
764 rc = CFGMR3InsertInteger(pCfg, "CustomVideoModes", cModes);
765
766 /* VESA height reduction */
767 ULONG ulHeightReduction;
768 IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
769 if (pFramebuffer)
770 {
771 hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
772 }
773 else
774 {
775 /* If framebuffer is not available, there is no height reduction. */
776 ulHeightReduction = 0;
777 }
778 rc = CFGMR3InsertInteger(pCfg, "HeightReduction", ulHeightReduction); RC_CHECK();
779
780 /* Attach the display. */
781 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
782 rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay"); RC_CHECK();
783 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
784 Display *pDisplay = pConsole->mDisplay;
785 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pDisplay); RC_CHECK();
786
787 /*
788 * IDE (update this when the main interface changes)
789 */
790 rc = CFGMR3InsertNode(pDevices, "piix3ide", &pDev); /* piix3 */ RC_CHECK();
791 rc = CFGMR3InsertNode(pDev, "0", &pIdeInst); RC_CHECK();
792 rc = CFGMR3InsertInteger(pIdeInst, "Trusted", 1); /* boolean */ RC_CHECK();
793 rc = CFGMR3InsertInteger(pIdeInst, "PCIDeviceNo", 1); RC_CHECK();
794 Assert(!afPciDeviceNo[1]);
795 afPciDeviceNo[1] = true;
796 rc = CFGMR3InsertInteger(pIdeInst, "PCIFunctionNo", 1); RC_CHECK();
797 rc = CFGMR3InsertNode(pIdeInst, "Config", &pCfg); RC_CHECK();
798 rc = CFGMR3InsertString(pCfg, "Type", controllerString(controllerType)); RC_CHECK();
799
800 /* Attach the status driver */
801 rc = CFGMR3InsertNode(pIdeInst, "LUN#999", &pLunL0); RC_CHECK();
802 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
803 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
804 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapIDELeds[0]);RC_CHECK();
805 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
806 rc = CFGMR3InsertInteger(pCfg, "Last", 3); RC_CHECK();
807
808 /*
809 * SATA controller
810 */
811 ComPtr<ISATAController> sataController;
812 hrc = pMachine->COMGETTER(SATAController)(sataController.asOutParam());
813 BOOL enabled = FALSE;
814
815 if (sataController)
816 {
817 hrc = sataController->COMGETTER(Enabled)(&enabled); H();
818
819 if (enabled)
820 {
821 rc = CFGMR3InsertNode(pDevices, "ahci", &pDev); RC_CHECK();
822 rc = CFGMR3InsertNode(pDev, "0", &pSataInst); RC_CHECK();
823 rc = CFGMR3InsertInteger(pSataInst, "Trusted", 1); RC_CHECK();
824 rc = CFGMR3InsertInteger(pSataInst, "PCIDeviceNo", 13); RC_CHECK();
825 Assert(!afPciDeviceNo[13]);
826 afPciDeviceNo[13] = true;
827 rc = CFGMR3InsertInteger(pSataInst, "PCIFunctionNo", 0); RC_CHECK();
828 rc = CFGMR3InsertNode(pSataInst, "Config", &pCfg); RC_CHECK();
829
830 ULONG cPorts = 0;
831 hrc = sataController->COMGETTER(PortCount)(&cPorts); H();
832 rc = CFGMR3InsertInteger(pCfg, "PortCount", cPorts); RC_CHECK();
833
834 /* Needed configuration values for the bios. */
835 rc = CFGMR3InsertString(pBiosCfg, "SataHardDiskDevice", "ahci"); RC_CHECK();
836
837 for (uint32_t i = 0; i < 4; i++)
838 {
839 static const char *s_apszConfig[4] =
840 { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
841 static const char *s_apszBiosConfig[4] =
842 { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
843
844 LONG lPortNumber = -1;
845 hrc = sataController->GetIDEEmulationPort(i, &lPortNumber); H();
846 rc = CFGMR3InsertInteger(pCfg, s_apszConfig[i], lPortNumber); RC_CHECK();
847 rc = CFGMR3InsertInteger(pBiosCfg, s_apszBiosConfig[i], lPortNumber); RC_CHECK();
848 }
849
850 /* Attach the status driver */
851 rc = CFGMR3InsertNode(pSataInst,"LUN#999", &pLunL0); RC_CHECK();
852 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
853 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
854 AssertRelease(cPorts <= RT_ELEMENTS(pConsole->mapSATALeds));
855 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSATALeds[0]); RC_CHECK();
856 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
857 rc = CFGMR3InsertInteger(pCfg, "Last", cPorts - 1); RC_CHECK();
858 }
859 }
860
861 /* Attach the hard disks */
862 {
863 com::SafeIfaceArray<IHardDiskAttachment> atts;
864 hrc = pMachine->
865 COMGETTER(HardDiskAttachments) (ComSafeArrayAsOutParam (atts)); H();
866
867 for (size_t i = 0; i < atts.size(); ++ i)
868 {
869 ComPtr<IHardDisk> hardDisk;
870 hrc = atts [i]->COMGETTER(HardDisk) (hardDisk.asOutParam()); H();
871 StorageBus_T enmBus;
872 hrc = atts [i]->COMGETTER(Bus) (&enmBus); H();
873 LONG lDev;
874 hrc = atts [i]->COMGETTER(Device) (&lDev); H();
875 LONG lChannel;
876 hrc = atts [i]->COMGETTER(Channel) (&lChannel); H();
877
878 PCFGMNODE pHardDiskCtl = NULL;
879 int iLUN = 0;
880
881 switch (enmBus)
882 {
883 case StorageBus_IDE:
884 {
885 if (lChannel >= 2 || lChannel < 0)
886 {
887 AssertMsgFailed (("invalid controller channel number: "
888 "%d\n", lChannel));
889 return VERR_GENERAL_FAILURE;
890 }
891
892 if (lDev >= 2 || lDev < 0)
893 {
894 AssertMsgFailed (("invalid controller device number: "
895 "%d\n", lDev));
896 return VERR_GENERAL_FAILURE;
897 }
898
899 iLUN = 2 * lChannel + lDev;
900 pHardDiskCtl = pIdeInst;
901
902 break;
903 }
904 case StorageBus_SATA:
905 {
906 iLUN = lChannel;
907 pHardDiskCtl = enabled ? pSataInst : NULL;
908 break;
909 }
910 default:
911 {
912 AssertMsgFailed (("invalid disk controller type: "
913 "%d\n", enmBus));
914 return VERR_GENERAL_FAILURE;
915 }
916 }
917
918 /* Can be NULL if SATA controller is not enabled and current hard
919 * disk is attached to SATA controller. */
920 if (pHardDiskCtl == NULL)
921 continue;
922
923 char szLUN[16];
924 RTStrPrintf (szLUN, sizeof(szLUN), "LUN#%d", iLUN);
925
926 rc = CFGMR3InsertNode (pHardDiskCtl, szLUN, &pLunL0); RC_CHECK();
927 rc = CFGMR3InsertString (pLunL0, "Driver", "Block"); RC_CHECK();
928 rc = CFGMR3InsertNode (pLunL0, "Config", &pCfg); RC_CHECK();
929 rc = CFGMR3InsertString (pCfg, "Type", "HardDisk"); RC_CHECK();
930 rc = CFGMR3InsertInteger (pCfg, "Mountable", 0); RC_CHECK();
931
932 rc = CFGMR3InsertNode (pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
933 rc = CFGMR3InsertString (pLunL1, "Driver", "VD"); RC_CHECK();
934 rc = CFGMR3InsertNode (pLunL1, "Config", &pCfg); RC_CHECK();
935
936 hrc = hardDisk->COMGETTER(Location) (bstr.asOutParam()); H();
937 rc = CFGMR3InsertString (pCfg, "Path", Utf8Str (bstr)); RC_CHECK();
938
939 hrc = hardDisk->COMGETTER(Format) (bstr.asOutParam()); H();
940 rc = CFGMR3InsertString (pCfg, "Format", Utf8Str (bstr)); RC_CHECK();
941
942#if defined(VBOX_WITH_PDM_ASYNC_COMPLETION)
943 if (bstr == L"VMDK")
944 {
945 /* Create cfgm nodes for async transport driver because VMDK is
946 * currently the only one which may support async I/O. This has
947 * to be made generic based on the capabiliy flags when the new
948 * HardDisk interface is merged.
949 */
950 rc = CFGMR3InsertNode (pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
951 rc = CFGMR3InsertString (pLunL2, "Driver", "TransportAsync"); RC_CHECK();
952 /* The async transport driver has no config options yet. */
953 }
954#endif
955 /* Pass all custom parameters. */
956 bool fHostIP = true;
957 SafeArray <BSTR> names;
958 SafeArray <BSTR> values;
959 hrc = hardDisk->GetProperties (NULL,
960 ComSafeArrayAsOutParam (names),
961 ComSafeArrayAsOutParam (values)); H();
962
963 if (names.size() != 0)
964 {
965 PCFGMNODE pVDC;
966 rc = CFGMR3InsertNode (pCfg, "VDConfig", &pVDC); RC_CHECK();
967 for (size_t i = 0; i < names.size(); ++ i)
968 {
969 if (values [i])
970 {
971 Utf8Str name = names [i];
972 Utf8Str value = values [i];
973 rc = CFGMR3InsertString (pVDC, name, value);
974 if ( !(name.compare("HostIPStack"))
975 && !(value.compare("0")))
976 fHostIP = false;
977 }
978 }
979 }
980
981 /* Create an inversed tree of parents. */
982 ComPtr<IHardDisk> parentHardDisk = hardDisk;
983 for (PCFGMNODE pParent = pCfg;;)
984 {
985 hrc = parentHardDisk->
986 COMGETTER(Parent) (hardDisk.asOutParam()); H();
987 if (hardDisk.isNull())
988 break;
989
990 PCFGMNODE pCur;
991 rc = CFGMR3InsertNode (pParent, "Parent", &pCur); RC_CHECK();
992 hrc = hardDisk->COMGETTER(Location) (bstr.asOutParam()); H();
993 rc = CFGMR3InsertString (pCur, "Path", Utf8Str (bstr)); RC_CHECK();
994
995 hrc = hardDisk->COMGETTER(Format) (bstr.asOutParam()); H();
996 rc = CFGMR3InsertString (pCur, "Format", Utf8Str (bstr)); RC_CHECK();
997
998 /* Pass all custom parameters. */
999 SafeArray <BSTR> names;
1000 SafeArray <BSTR> values;
1001 hrc = hardDisk->GetProperties (NULL,
1002 ComSafeArrayAsOutParam (names),
1003 ComSafeArrayAsOutParam (values));H();
1004
1005 if (names.size() != 0)
1006 {
1007 PCFGMNODE pVDC;
1008 rc = CFGMR3InsertNode (pCur, "VDConfig", &pVDC); RC_CHECK();
1009 for (size_t i = 0; i < names.size(); ++ i)
1010 {
1011 if (values [i])
1012 {
1013 Utf8Str name = names [i];
1014 Utf8Str value = values [i];
1015 rc = CFGMR3InsertString (pVDC, name, value);
1016 if ( !(name.compare("HostIPStack"))
1017 && !(value.compare("0")))
1018 fHostIP = false;
1019 }
1020 }
1021 }
1022
1023 /* Custom code: put marker to not use host IP stack to driver
1024 * configuration node. Simplifies life of DrvVD a bit. */
1025 if (!fHostIP)
1026 {
1027 rc = CFGMR3InsertInteger (pCfg, "HostIPStack", 0); RC_CHECK();
1028 }
1029
1030 /* next */
1031 pParent = pCur;
1032 parentHardDisk = hardDisk;
1033 }
1034 }
1035 }
1036 H();
1037
1038 ComPtr<IDVDDrive> dvdDrive;
1039 hrc = pMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam()); H();
1040 if (dvdDrive)
1041 {
1042 // ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
1043 rc = CFGMR3InsertNode(pIdeInst, "LUN#2", &pLunL0); RC_CHECK();
1044 ComPtr<IHostDVDDrive> hostDvdDrive;
1045 hrc = dvdDrive->GetHostDrive(hostDvdDrive.asOutParam()); H();
1046 if (hostDvdDrive)
1047 {
1048 pConsole->meDVDState = DriveState_HostDriveCaptured;
1049 rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
1050 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1051 hrc = hostDvdDrive->COMGETTER(Name)(&str); H();
1052 STR_CONV();
1053 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
1054 STR_FREE();
1055 BOOL fPassthrough;
1056 hrc = dvdDrive->COMGETTER(Passthrough)(&fPassthrough); H();
1057 rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough); RC_CHECK();
1058 }
1059 else
1060 {
1061 pConsole->meDVDState = DriveState_NotMounted;
1062 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
1063 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1064 rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
1065 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
1066
1067 ComPtr<IDVDImage> dvdImage;
1068 hrc = dvdDrive->GetImage(dvdImage.asOutParam()); H();
1069 if (dvdImage)
1070 {
1071 pConsole->meDVDState = DriveState_ImageMounted;
1072 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1073 rc = CFGMR3InsertString(pLunL1, "Driver", "MediaISO"); RC_CHECK();
1074 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
1075 hrc = dvdImage->COMGETTER(Location)(&str); H();
1076 STR_CONV();
1077 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
1078 STR_FREE();
1079 }
1080 }
1081 }
1082
1083 /*
1084 * Network adapters
1085 */
1086 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
1087 rc = CFGMR3InsertNode(pDevices, "pcnet", &pDevPCNet); RC_CHECK();
1088#ifdef VBOX_WITH_E1000
1089 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
1090 rc = CFGMR3InsertNode(pDevices, "e1000", &pDevE1000); RC_CHECK();
1091#endif
1092 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ulInstance++)
1093 {
1094 ComPtr<INetworkAdapter> networkAdapter;
1095 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
1096 BOOL fEnabled = FALSE;
1097 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
1098 if (!fEnabled)
1099 continue;
1100
1101 /*
1102 * The virtual hardware type. Create appropriate device first.
1103 */
1104 NetworkAdapterType_T adapterType;
1105 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
1106 switch (adapterType)
1107 {
1108 case NetworkAdapterType_Am79C970A:
1109 case NetworkAdapterType_Am79C973:
1110 pDev = pDevPCNet;
1111 break;
1112#ifdef VBOX_WITH_E1000
1113 case NetworkAdapterType_I82540EM:
1114 case NetworkAdapterType_I82543GC:
1115 pDev = pDevE1000;
1116 break;
1117#endif
1118 default:
1119 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
1120 adapterType, ulInstance));
1121 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1122 N_("Invalid network adapter type '%d' for slot '%d'"),
1123 adapterType, ulInstance);
1124 }
1125
1126 char szInstance[4]; Assert(ulInstance <= 999);
1127 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1128 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1129 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1130 /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
1131 * next 4 get 16..19. */
1132 unsigned iPciDeviceNo = 3;
1133 if (ulInstance)
1134 {
1135 if (ulInstance < 4)
1136 iPciDeviceNo = ulInstance - 1 + 8;
1137 else
1138 iPciDeviceNo = ulInstance - 4 + 16;
1139 }
1140 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
1141 Assert(!afPciDeviceNo[iPciDeviceNo]);
1142 afPciDeviceNo[iPciDeviceNo] = true;
1143 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1144 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1145#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
1146 if (pDev == pDevPCNet)
1147 {
1148 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", false); RC_CHECK();
1149 }
1150#endif
1151
1152 /*
1153 * The virtual hardware type. PCNet supports two types.
1154 */
1155 switch (adapterType)
1156 {
1157 case NetworkAdapterType_Am79C970A:
1158 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
1159 break;
1160 case NetworkAdapterType_Am79C973:
1161 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
1162 break;
1163 case NetworkAdapterType_I82540EM:
1164 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
1165 break;
1166 case NetworkAdapterType_I82543GC:
1167 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
1168 break;
1169 }
1170
1171 /*
1172 * Get the MAC address and convert it to binary representation
1173 */
1174 Bstr macAddr;
1175 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1176 Assert(macAddr);
1177 Utf8Str macAddrUtf8 = macAddr;
1178 char *macStr = (char*)macAddrUtf8.raw();
1179 Assert(strlen(macStr) == 12);
1180 RTMAC Mac;
1181 memset(&Mac, 0, sizeof(Mac));
1182 char *pMac = (char*)&Mac;
1183 for (uint32_t i = 0; i < 6; i++)
1184 {
1185 char c1 = *macStr++ - '0';
1186 if (c1 > 9)
1187 c1 -= 7;
1188 char c2 = *macStr++ - '0';
1189 if (c2 > 9)
1190 c2 -= 7;
1191 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1192 }
1193 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1194
1195 /*
1196 * Check if the cable is supposed to be unplugged
1197 */
1198 BOOL fCableConnected;
1199 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1200 rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
1201
1202 /*
1203 * Line speed to report from custom drivers
1204 */
1205 ULONG ulLineSpeed;
1206 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1207 rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
1208
1209 /*
1210 * Attach the status driver.
1211 */
1212 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1213 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1214 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1215 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
1216
1217 /*
1218 * Enable the packet sniffer if requested.
1219 */
1220 BOOL fSniffer;
1221 hrc = networkAdapter->COMGETTER(TraceEnabled)(&fSniffer); H();
1222 if (fSniffer)
1223 {
1224 /* insert the sniffer filter driver. */
1225 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1226 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
1227 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1228 hrc = networkAdapter->COMGETTER(TraceFile)(&str); H();
1229 if (str) /* check convention for indicating default file. */
1230 {
1231 STR_CONV();
1232 rc = CFGMR3InsertString(pCfg, "File", psz); RC_CHECK();
1233 STR_FREE();
1234 }
1235 }
1236
1237 NetworkAttachmentType_T networkAttachment;
1238 hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H();
1239 switch (networkAttachment)
1240 {
1241 case NetworkAttachmentType_Null:
1242 break;
1243
1244 case NetworkAttachmentType_NAT:
1245 {
1246 if (fSniffer)
1247 {
1248 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1249 }
1250 else
1251 {
1252 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1253 }
1254 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
1255 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1256 /* (Port forwarding goes here.) */
1257
1258 /* Configure TFTP prefix and boot filename. */
1259 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
1260 STR_CONV();
1261 if (psz && *psz)
1262 {
1263 char *pszTFTPPrefix = NULL;
1264 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
1265 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix); RC_CHECK();
1266 RTStrFree(pszTFTPPrefix);
1267 }
1268 STR_FREE();
1269 hrc = pMachine->COMGETTER(Name)(&str); H();
1270 STR_CONV();
1271 char *pszBootFile = NULL;
1272 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
1273 STR_FREE();
1274 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile); RC_CHECK();
1275 RTStrFree(pszBootFile);
1276
1277 hrc = networkAdapter->COMGETTER(NATNetwork)(&str); H();
1278 if (str)
1279 {
1280 STR_CONV();
1281 if (psz && *psz)
1282 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1283 STR_FREE();
1284 }
1285 break;
1286 }
1287
1288 case NetworkAttachmentType_HostInterface:
1289 {
1290 /*
1291 * Perform the attachment if required (don't return on error!)
1292 */
1293 hrc = pConsole->attachToHostInterface(networkAdapter);
1294 if (SUCCEEDED(hrc))
1295 {
1296#if defined(VBOX_WITH_NETFLT)
1297 /*
1298 * This is the new VBoxNetFlt+IntNet stuff.
1299 */
1300 if (fSniffer)
1301 {
1302 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1303 }
1304 else
1305 {
1306 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1307 }
1308
1309 Bstr HifName;
1310 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1311 if(FAILED(hrc))
1312 {
1313 LogRel(("NetworkAttachmentType_HostInterface: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1314 H();
1315 }
1316
1317 Utf8Str HifNameUtf8(HifName);
1318 const char *pszHifName = HifNameUtf8.raw();
1319
1320# if defined(RT_OS_DARWIN)
1321 /* The name is on the form 'ifX: long name', chop it off at the colon. */
1322 char szTrunk[8];
1323 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
1324 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1325 if (!pszColon)
1326 {
1327 hrc = networkAdapter->Detach(); H();
1328 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1329 N_("Malformed host interface networking name '%ls'"),
1330 HifName.raw());
1331 }
1332 *pszColon = '\0';
1333 const char *pszTrunk = szTrunk;
1334
1335# elif defined(RT_OS_SOLARIS)
1336 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
1337 char szTrunk[256];
1338 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
1339 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
1340
1341 /*
1342 * Currently don't bother about malformed names here for the sake of people using
1343 * VBoxManage and setting only the NIC name from there. If there is a space we
1344 * chop it off and proceed, otherwise just use whatever we've got.
1345 */
1346 if (pszSpace)
1347 *pszSpace = '\0';
1348
1349 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
1350 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1351 if (pszColon)
1352 *pszColon = '\0';
1353
1354 const char *pszTrunk = szTrunk;
1355
1356# elif defined(RT_OS_WINDOWS)
1357 ComPtr<IHostNetworkInterface> hostInterface;
1358 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1359 if (!SUCCEEDED(rc))
1360 {
1361 AssertBreakpoint();
1362 LogRel(("NetworkAttachmentType_HostInterface: FindByName failed, rc (0x%x)", rc));
1363 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1364 N_("Inexistent host networking interface, name '%ls'"),
1365 HifName.raw());
1366 }
1367
1368 BOOL real;
1369 hrc = hostInterface->COMGETTER(Real)(&real);
1370 if(FAILED(hrc))
1371 {
1372 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Real) failed, hrc (0x%x)", hrc));
1373 H();
1374 }
1375
1376 if(!real)
1377 {
1378 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Real) failed, hrc (0x%x)", hrc));
1379 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1380 N_("Interface ('%ls') is a Host Adapter interface"),
1381 HifName.raw());
1382 }
1383
1384 Guid hostIFGuid;
1385 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1386 if(FAILED(hrc))
1387 {
1388 LogRel(("NetworkAttachmentType_HostInterface: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1389 H();
1390 }
1391 char szDriverGUID[RTUUID_STR_LENGTH];
1392 strcpy(szDriverGUID , hostIFGuid.toString().raw());
1393 const char *pszTrunk = szDriverGUID;
1394# elif defined(RT_OS_LINUX)
1395 /* @todo Check for malformed names. */
1396 const char *pszTrunk = pszHifName;
1397
1398# else
1399# error "PORTME (VBOX_WITH_NETFLT)"
1400# endif
1401
1402 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1403 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1404 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1405 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1406 char szNetwork[80];
1407 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1408 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1409
1410# if defined(RT_OS_DARWIN)
1411 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
1412 if ( strstr(pszHifName, "Wireless")
1413 || strstr(pszHifName, "AirPort" ))
1414 {
1415 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1416 }
1417# elif defined(RT_OS_LINUX)
1418 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
1419 if (iSock >= 0)
1420 {
1421 struct iwreq WRq;
1422
1423 memset(&WRq, 0, sizeof(WRq));
1424 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
1425 if (ioctl(iSock, SIOCGIWNAME, &WRq) >= 0)
1426 {
1427 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1428 Log(("Set SharedMacOnWire\n"));
1429 }
1430 else
1431 {
1432 Log(("Failed to get wireless name\n"));
1433 }
1434 close(iSock);
1435 }
1436 else
1437 {
1438 Log(("Failed to open wireless socket\n"));
1439 }
1440# elif defined(RT_OS_WINDOWS)
1441# define DEVNAME_PREFIX L"\\\\.\\"
1442 INetCfg *pNc;
1443 LPWSTR lpszApp;
1444 HRESULT hr;
1445 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
1446
1447 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
1448 * there is a pretty long way till there though since we need to obtain the symbolic link name
1449 * for the adapter device we are going to query given the device Guid */
1450 hr = VBoxNetCfgWinQueryINetCfg( FALSE,
1451 L"VirtualBox",
1452 &pNc,
1453 &lpszApp );
1454 Assert(hr == S_OK);
1455 if(hr == S_OK)
1456 {
1457 /* get the adapter's INetCfgComponent*/
1458 INetCfgComponent *pAdaptorComponent;
1459 hr = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), &pAdaptorComponent);
1460 Assert(hr == S_OK);
1461 if(hr == S_OK)
1462 {
1463 /* now get the bind name */
1464 LPWSTR pName;
1465 hr = pAdaptorComponent->GetBindName(&pName);
1466 Assert(hr == S_OK);
1467 if(hr == S_OK)
1468 {
1469 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
1470 wchar_t FileName[MAX_PATH];
1471 wcscpy(FileName, DEVNAME_PREFIX);
1472 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pName);
1473
1474 /* open the device */
1475 HANDLE hDevice = CreateFile(FileName,
1476 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
1477 NULL,
1478 OPEN_EXISTING,
1479 FILE_ATTRIBUTE_NORMAL,
1480 NULL);
1481 if (hDevice != INVALID_HANDLE_VALUE)
1482 {
1483 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
1484 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
1485 NDIS_PHYSICAL_MEDIUM PhMedium;
1486 DWORD cbResult;
1487 if (DeviceIoControl(hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, &Oid, sizeof(Oid), &PhMedium, sizeof(PhMedium), &cbResult, NULL))
1488 {
1489 /* that was simple, now examine PhMedium */
1490 if(PhMedium == NdisPhysicalMediumWirelessWan
1491 || PhMedium == NdisPhysicalMediumWirelessLan
1492 || PhMedium == NdisPhysicalMediumNative802_11
1493 || PhMedium == NdisPhysicalMediumBluetooth
1494 /*|| PhMedium == NdisPhysicalMediumWiMax*/
1495 )
1496 {
1497 Log(("this is a wireles adapter"));
1498 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1499 Log(("Set SharedMacOnWire\n"));
1500 }
1501 else
1502 {
1503 Log(("this is NOT a wireles adapter"));
1504 }
1505 }
1506 else
1507 {
1508 int winEr = GetLastError();
1509 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
1510 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
1511 }
1512
1513 CloseHandle(hDevice);
1514 }
1515 else
1516 {
1517 int winEr = GetLastError();
1518 LogRel(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
1519 AssertBreakpoint();
1520 }
1521 CoTaskMemFree(pName);
1522 }
1523 VBoxNetCfgWinReleaseRef(pAdaptorComponent);
1524 }
1525 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1526 }
1527# else
1528 /** @todo PORTME: wireless detection */
1529# endif
1530
1531# if defined(RT_OS_SOLARIS)
1532# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
1533 /* Zone access restriction, don't allow snopping the global zone. */
1534 zoneid_t ZoneId = getzoneid();
1535 if (ZoneId != GLOBAL_ZONEID)
1536 {
1537 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
1538 }
1539# endif
1540# endif
1541
1542#elif defined(RT_OS_WINDOWS)
1543 if (fSniffer)
1544 {
1545 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1546 }
1547 else
1548 {
1549 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1550 }
1551 Bstr hostInterfaceName;
1552 hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
1553 ComPtr<IHostNetworkInterface> hostInterface;
1554 rc = host->FindHostNetworkInterfaceByName(hostInterfaceName, hostInterface.asOutParam());
1555 if (!SUCCEEDED(rc))
1556 {
1557 AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
1558 hrc = networkAdapter->Detach(); H();
1559 }
1560 else
1561 {
1562# ifndef VBOX_WITH_NETFLT
1563 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1564 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1565 rc = CFGMR3InsertString(pCfg, "HostInterfaceName", Utf8Str(hostInterfaceName)); RC_CHECK();
1566# else
1567 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1568 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1569 rc = CFGMR3InsertString(pCfg, "Trunk", Utf8Str(hostInterfaceName)); RC_CHECK();
1570 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1571# endif
1572 Guid hostIFGuid;
1573 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1574 char szDriverGUID[256] = {0};
1575 /* add curly brackets */
1576 szDriverGUID[0] = '{';
1577 strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
1578 strcat(szDriverGUID, "}");
1579 rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
1580 }
1581#elif defined(RT_OS_LINUX)
1582/// @todo aleksey: is there anything to be done here?
1583#elif defined(RT_OS_FREEBSD)
1584/** @todo FreeBSD: Check out this later (HIF networking). */
1585#else
1586# error "Port me"
1587#endif
1588 }
1589 else
1590 {
1591 switch (hrc)
1592 {
1593#ifdef RT_OS_LINUX
1594 case VERR_ACCESS_DENIED:
1595 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1596 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1597 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
1598 "change the group of that node and make yourself a member of that group. Make "
1599 "sure that these changes are permanent, especially if you are "
1600 "using udev"));
1601#endif /* RT_OS_LINUX */
1602 default:
1603 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1604 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1605 "Failed to initialize Host Interface Networking"));
1606 }
1607 }
1608 break;
1609 }
1610
1611 case NetworkAttachmentType_Internal:
1612 {
1613 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1614 if (str)
1615 {
1616 STR_CONV();
1617 if (psz && *psz)
1618 {
1619 if (fSniffer)
1620 {
1621 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1622 }
1623 else
1624 {
1625 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1626 }
1627 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1628 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1629 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1630 }
1631 STR_FREE();
1632 }
1633 break;
1634 }
1635
1636 case NetworkAttachmentType_HostOnly:
1637 {
1638 if (fSniffer)
1639 {
1640 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1641 }
1642 else
1643 {
1644 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1645 }
1646
1647 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1648 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1649#if defined(RT_OS_WINDOWS)
1650 Bstr HifName;
1651 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1652 if(FAILED(hrc))
1653 {
1654 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1655 H();
1656 }
1657
1658 Utf8Str HifNameUtf8(HifName);
1659 const char *pszHifName = HifNameUtf8.raw();
1660 ComPtr<IHostNetworkInterface> hostInterface;
1661 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1662 if (!SUCCEEDED(rc))
1663 {
1664 AssertBreakpoint();
1665 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)", rc));
1666 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1667 N_("Inexistent host networking interface, name '%ls'"),
1668 HifName.raw());
1669 }
1670
1671 BOOL real;
1672 hrc = hostInterface->COMGETTER(Real)(&real);
1673 if(FAILED(hrc))
1674 {
1675 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Real) failed, hrc (0x%x)", hrc));
1676 H();
1677 }
1678
1679 if(real)
1680 {
1681 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Real) failed, hrc (0x%x)", hrc));
1682 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1683 N_("Interface ('%ls') is not a Host Adapter interface"),
1684 HifName.raw());
1685 }
1686
1687 Guid hostIFGuid;
1688 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1689 if(FAILED(hrc))
1690 {
1691 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1692 H();
1693 }
1694 char szDriverGUID[RTUUID_STR_LENGTH];
1695 strcpy(szDriverGUID , hostIFGuid.toString().raw());
1696 const char *pszTrunk = szDriverGUID;
1697
1698 /* TODO: set the proper Trunk and Network values, currently the driver uses the first adapter instance */
1699 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
1700 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1701 char szNetwork[80];
1702 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1703 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1704#elif defined(RT_OS_DARWIN)
1705 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK();
1706 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0"); RC_CHECK();
1707 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
1708#else
1709 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK();
1710 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0"); RC_CHECK();
1711 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1712#endif
1713 break;
1714 }
1715
1716 default:
1717 AssertMsgFailed(("should not get here!\n"));
1718 break;
1719 }
1720 }
1721
1722 /*
1723 * Serial (UART) Ports
1724 */
1725 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1726 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1727 {
1728 ComPtr<ISerialPort> serialPort;
1729 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1730 BOOL fEnabled = FALSE;
1731 if (serialPort)
1732 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1733 if (!fEnabled)
1734 continue;
1735
1736 char szInstance[4]; Assert(ulInstance <= 999);
1737 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1738
1739 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1740 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1741
1742 ULONG ulIRQ, ulIOBase;
1743 PortMode_T HostMode;
1744 Bstr path;
1745 BOOL fServer;
1746 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1747 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1748 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1749 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1750 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1751 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1752 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1753 if (HostMode != PortMode_Disconnected)
1754 {
1755 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1756 if (HostMode == PortMode_HostPipe)
1757 {
1758 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1759 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1760 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1761 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1762 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1763 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1764 }
1765 else if (HostMode == PortMode_HostDevice)
1766 {
1767 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1768 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1769 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1770 }
1771 }
1772 }
1773
1774 /*
1775 * Parallel (LPT) Ports
1776 */
1777 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1778 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1779 {
1780 ComPtr<IParallelPort> parallelPort;
1781 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1782 BOOL fEnabled = FALSE;
1783 if (parallelPort)
1784 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1785 if (!fEnabled)
1786 continue;
1787
1788 char szInstance[4]; Assert(ulInstance <= 999);
1789 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1790
1791 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1792 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1793
1794 ULONG ulIRQ, ulIOBase;
1795 Bstr DevicePath;
1796 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1797 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1798 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1799 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1800 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1801 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1802 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1803 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1804 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1805 }
1806
1807 /*
1808 * VMM Device
1809 */
1810 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1811 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1812 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1813 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1814 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1815 Assert(!afPciDeviceNo[4]);
1816 afPciDeviceNo[4] = true;
1817 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1818 Bstr hwVersion;
1819 hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
1820 if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
1821 {
1822 CFGMR3InsertInteger(pCfg, "HeapEnabled", 0); RC_CHECK();
1823 }
1824
1825 /* the VMM device's Main driver */
1826 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1827 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1828 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1829 VMMDev *pVMMDev = pConsole->mVMMDev;
1830 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1831
1832 /*
1833 * Attach the status driver.
1834 */
1835 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1836 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1837 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1838 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1839 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1840 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1841
1842 /*
1843 * Audio Sniffer Device
1844 */
1845 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1846 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1847 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1848
1849 /* the Audio Sniffer device's Main driver */
1850 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1851 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1852 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1853 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1854 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1855
1856 /*
1857 * AC'97 ICH / SoundBlaster16 audio
1858 */
1859 ComPtr<IAudioAdapter> audioAdapter;
1860 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1861 if (audioAdapter)
1862 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1863
1864 if (enabled)
1865 {
1866 AudioControllerType_T audioController;
1867 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
1868 switch (audioController)
1869 {
1870 case AudioControllerType_AC97:
1871 {
1872 /* default: ICH AC97 */
1873 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
1874 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1875 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1876 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1877 Assert(!afPciDeviceNo[5]);
1878 afPciDeviceNo[5] = true;
1879 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1880 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1881 break;
1882 }
1883 case AudioControllerType_SB16:
1884 {
1885 /* legacy SoundBlaster16 */
1886 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
1887 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1888 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1889 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1890 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
1891 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
1892 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
1893 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
1894 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
1895 break;
1896 }
1897 }
1898
1899 /* the Audio driver */
1900 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1901 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1902 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1903
1904 AudioDriverType_T audioDriver;
1905 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1906 switch (audioDriver)
1907 {
1908 case AudioDriverType_Null:
1909 {
1910 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1911 break;
1912 }
1913#ifdef RT_OS_WINDOWS
1914#ifdef VBOX_WITH_WINMM
1915 case AudioDriverType_WinMM:
1916 {
1917 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1918 break;
1919 }
1920#endif
1921 case AudioDriverType_DirectSound:
1922 {
1923 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
1924 break;
1925 }
1926#endif /* RT_OS_WINDOWS */
1927#ifdef RT_OS_SOLARIS
1928 case AudioDriverType_SolAudio:
1929 {
1930 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
1931 break;
1932 }
1933#endif
1934#ifdef RT_OS_LINUX
1935 case AudioDriverType_OSS:
1936 {
1937 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
1938 break;
1939 }
1940# ifdef VBOX_WITH_ALSA
1941 case AudioDriverType_ALSA:
1942 {
1943 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
1944 break;
1945 }
1946# endif
1947# ifdef VBOX_WITH_PULSE
1948 case AudioDriverType_Pulse:
1949 {
1950 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
1951 break;
1952 }
1953# endif
1954#endif /* RT_OS_LINUX */
1955#ifdef RT_OS_DARWIN
1956 case AudioDriverType_CoreAudio:
1957 {
1958 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1959 break;
1960 }
1961#endif
1962 }
1963 hrc = pMachine->COMGETTER(Name)(&str); H();
1964 STR_CONV();
1965 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
1966 STR_FREE();
1967 }
1968
1969 /*
1970 * The USB Controller.
1971 */
1972 ComPtr<IUSBController> USBCtlPtr;
1973 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1974 if (USBCtlPtr)
1975 {
1976 BOOL fEnabled;
1977 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1978 if (fEnabled)
1979 {
1980 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
1981 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1982 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1983 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1984 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
1985 Assert(!afPciDeviceNo[6]);
1986 afPciDeviceNo[6] = true;
1987 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1988
1989 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1990 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
1991 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1992
1993 /*
1994 * Attach the status driver.
1995 */
1996 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1997 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1998 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1999 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
2000 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2001 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2002
2003#ifdef VBOX_WITH_EHCI
2004 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
2005 if (fEnabled)
2006 {
2007 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
2008 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2009 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2010 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2011 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
2012 Assert(!afPciDeviceNo[11]);
2013 afPciDeviceNo[11] = true;
2014 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2015
2016 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2017 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2018 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2019
2020 /*
2021 * Attach the status driver.
2022 */
2023 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2024 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2025 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2026 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
2027 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2028 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2029 }
2030 else
2031#endif
2032 {
2033 /*
2034 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
2035 * on a per device level now.
2036 */
2037 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
2038 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
2039 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
2040 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
2041 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
2042 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
2043 // that it's documented somewhere.) Users needing it can use:
2044 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
2045 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
2046 }
2047 }
2048 }
2049
2050 /*
2051 * Clipboard
2052 */
2053 {
2054 ClipboardMode_T mode = ClipboardMode_Disabled;
2055 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
2056
2057 if (mode != ClipboardMode_Disabled)
2058 {
2059 /* Load the service */
2060 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
2061
2062 if (RT_FAILURE (rc))
2063 {
2064 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
2065 /* That is not a fatal failure. */
2066 rc = VINF_SUCCESS;
2067 }
2068 else
2069 {
2070 /* Setup the service. */
2071 VBOXHGCMSVCPARM parm;
2072
2073 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2074
2075 switch (mode)
2076 {
2077 default:
2078 case ClipboardMode_Disabled:
2079 {
2080 LogRel(("VBoxSharedClipboard mode: Off\n"));
2081 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
2082 break;
2083 }
2084 case ClipboardMode_GuestToHost:
2085 {
2086 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
2087 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
2088 break;
2089 }
2090 case ClipboardMode_HostToGuest:
2091 {
2092 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
2093 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
2094 break;
2095 }
2096 case ClipboardMode_Bidirectional:
2097 {
2098 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
2099 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
2100 break;
2101 }
2102 }
2103
2104 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
2105
2106 Log(("Set VBoxSharedClipboard mode\n"));
2107 }
2108 }
2109 }
2110
2111#ifdef VBOX_WITH_CROGL
2112 /*
2113 * crOpenGL
2114 */
2115 {
2116 BOOL fEnabled = false;
2117 hrc = pMachine->COMGETTER(Accelerate3DEnabled) (&fEnabled); H();
2118
2119 if (fEnabled)
2120 {
2121 /* Load the service */
2122 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
2123 if (RT_FAILURE(rc))
2124 {
2125 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
2126 /* That is not a fatal failure. */
2127 rc = VINF_SUCCESS;
2128 }
2129 else
2130 {
2131 LogRel(("Shared crOpenGL service loaded.\n"));
2132
2133 /* Setup the service. */
2134 VBOXHGCMSVCPARM parm;
2135 parm.type = VBOX_HGCM_SVC_PARM_PTR;
2136
2137 //parm.u.pointer.addr = static_cast <IConsole *> (pData->pVMMDev->getParent());
2138 parm.u.pointer.addr = pConsole->mVMMDev->getParent()->getDisplay()->getFramebuffer();
2139 parm.u.pointer.size = sizeof(IFramebuffer *);
2140
2141 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_FRAMEBUFFER, 1, &parm);
2142 if (!RT_SUCCESS(rc))
2143 AssertMsgFailed(("SHCRGL_HOST_FN_SET_FRAMEBUFFER failed with %Rrc\n", rc));
2144 }
2145 }
2146 }
2147#endif
2148
2149#ifdef VBOX_WITH_GUEST_PROPS
2150 /*
2151 * Guest property service
2152 */
2153 {
2154 /* Load the service */
2155 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
2156
2157 if (RT_FAILURE (rc))
2158 {
2159 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
2160 /* That is not a fatal failure. */
2161 rc = VINF_SUCCESS;
2162 }
2163 else
2164 {
2165 /* Pull over the properties from the server. */
2166 SafeArray <BSTR> namesOut;
2167 SafeArray <BSTR> valuesOut;
2168 SafeArray <ULONG64> timestampsOut;
2169 SafeArray <BSTR> flagsOut;
2170 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
2171 ComSafeArrayAsOutParam(valuesOut),
2172 ComSafeArrayAsOutParam(timestampsOut),
2173 ComSafeArrayAsOutParam(flagsOut)); H();
2174 size_t cProps = namesOut.size();
2175 if ( valuesOut.size() != cProps
2176 || timestampsOut.size() != cProps
2177 || flagsOut.size() != cProps
2178 )
2179 rc = VERR_INVALID_PARAMETER;
2180
2181 std::vector <Utf8Str> utf8Names, utf8Values, utf8Flags;
2182 std::vector <char *> names, values, flags;
2183 std::vector <ULONG64> timestamps;
2184 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2185 if ( !VALID_PTR(namesOut[i])
2186 || !VALID_PTR(valuesOut[i])
2187 || !VALID_PTR(flagsOut[i])
2188 )
2189 rc = VERR_INVALID_POINTER;
2190 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2191 {
2192 utf8Names.push_back(Bstr(namesOut[i]));
2193 utf8Values.push_back(Bstr(valuesOut[i]));
2194 timestamps.push_back(timestampsOut[i]);
2195 utf8Flags.push_back(Bstr(flagsOut[i]));
2196 if ( utf8Names.back().isNull()
2197 || utf8Values.back().isNull()
2198 || utf8Flags.back().isNull()
2199 )
2200 throw std::bad_alloc();
2201 }
2202 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2203 {
2204 names.push_back(utf8Names[i].mutableRaw());
2205 values.push_back(utf8Values[i].mutableRaw());
2206 flags.push_back(utf8Flags[i].mutableRaw());
2207 }
2208 names.push_back(NULL);
2209 values.push_back(NULL);
2210 timestamps.push_back(0);
2211 flags.push_back(NULL);
2212
2213 /* Setup the service. */
2214 VBOXHGCMSVCPARM parms[4];
2215
2216 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
2217 parms[0].u.pointer.addr = &names.front();
2218 parms[0].u.pointer.size = 0; /* We don't actually care. */
2219 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
2220 parms[1].u.pointer.addr = &values.front();
2221 parms[1].u.pointer.size = 0; /* We don't actually care. */
2222 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
2223 parms[2].u.pointer.addr = &timestamps.front();
2224 parms[2].u.pointer.size = 0; /* We don't actually care. */
2225 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
2226 parms[3].u.pointer.addr = &flags.front();
2227 parms[3].u.pointer.size = 0; /* We don't actually care. */
2228
2229 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4, &parms[0]);
2230
2231 /* Register the host notification callback */
2232 HGCMSVCEXTHANDLE hDummy;
2233 HGCMHostRegisterServiceExtension (&hDummy, "VBoxGuestPropSvc",
2234 Console::doGuestPropNotification,
2235 pvConsole);
2236
2237 Log(("Set VBoxGuestPropSvc property store\n"));
2238 }
2239 }
2240#endif /* VBOX_WITH_GUEST_PROPS defined */
2241
2242 /*
2243 * CFGM overlay handling.
2244 *
2245 * Here we check the extra data entries for CFGM values
2246 * and create the nodes and insert the values on the fly. Existing
2247 * values will be removed and reinserted. CFGM is typed, so by default
2248 * we will guess whether it's a string or an integer (byte arrays are
2249 * not currently supported). It's possible to override this autodetection
2250 * by adding "string:", "integer:" or "bytes:" (future).
2251 *
2252 * We first perform a run on global extra data, then on the machine
2253 * extra data to support global settings with local overrides.
2254 *
2255 */
2256 /** @todo add support for removing nodes and byte blobs. */
2257 Bstr strExtraDataKey;
2258 bool fGlobalExtraData = true;
2259 for (;;)
2260 {
2261 /*
2262 * Get the next key
2263 */
2264 Bstr strNextExtraDataKey;
2265 Bstr strExtraDataValue;
2266 if (fGlobalExtraData)
2267 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2268 strExtraDataValue.asOutParam());
2269 else
2270 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2271 strExtraDataValue.asOutParam());
2272
2273 /* stop if for some reason there's nothing more to request */
2274 if (FAILED(hrc) || !strNextExtraDataKey)
2275 {
2276 /* if we're out of global keys, continue with machine, otherwise we're done */
2277 if (fGlobalExtraData)
2278 {
2279 fGlobalExtraData = false;
2280 strExtraDataKey.setNull();
2281 continue;
2282 }
2283 break;
2284 }
2285 strExtraDataKey = strNextExtraDataKey;
2286
2287 /*
2288 * We only care about keys starting with "VBoxInternal/"
2289 */
2290 Utf8Str strExtraDataKeyUtf8(strExtraDataKey);
2291 char *pszExtraDataKey = (char *)strExtraDataKeyUtf8.raw();
2292 if (strncmp(pszExtraDataKey, "VBoxInternal/", sizeof("VBoxInternal/") - 1) != 0)
2293 continue;
2294 pszExtraDataKey += sizeof("VBoxInternal/") - 1;
2295
2296 /*
2297 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2298 * Split the two and get the node, delete the value and create the node
2299 * if necessary.
2300 */
2301 PCFGMNODE pNode;
2302 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2303 if (pszCFGMValueName)
2304 {
2305 /* terminate the node and advance to the value (Utf8Str might not
2306 offically like this but wtf) */
2307 *pszCFGMValueName = '\0';
2308 pszCFGMValueName++;
2309
2310 /* does the node already exist? */
2311 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2312 if (pNode)
2313 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2314 else
2315 {
2316 /* create the node */
2317 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2318 if (RT_FAILURE(rc))
2319 {
2320 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2321 continue;
2322 }
2323 Assert(pNode);
2324 }
2325 }
2326 else
2327 {
2328 /* root value (no node path). */
2329 pNode = pRoot;
2330 pszCFGMValueName = pszExtraDataKey;
2331 pszExtraDataKey--;
2332 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2333 }
2334
2335 /*
2336 * Now let's have a look at the value.
2337 * Empty strings means that we should remove the value, which we've
2338 * already done above.
2339 */
2340 Utf8Str strCFGMValueUtf8(strExtraDataValue);
2341 const char *pszCFGMValue = strCFGMValueUtf8.raw();
2342 if ( pszCFGMValue
2343 && *pszCFGMValue)
2344 {
2345 uint64_t u64Value;
2346
2347 /* check for type prefix first. */
2348 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
2349 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
2350 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
2351 {
2352 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
2353 if (RT_SUCCESS(rc))
2354 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2355 }
2356 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
2357 rc = VERR_NOT_IMPLEMENTED;
2358 /* auto detect type. */
2359 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
2360 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2361 else
2362 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
2363 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
2364 }
2365 }
2366
2367#undef H
2368#undef RC_CHECK
2369#undef STR_FREE
2370#undef STR_CONV
2371
2372 /* Register VM state change handler */
2373 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2374 AssertRC (rc2);
2375 if (RT_SUCCESS (rc))
2376 rc = rc2;
2377
2378 /* Register VM runtime error handler */
2379 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2380 AssertRC (rc2);
2381 if (RT_SUCCESS (rc))
2382 rc = rc2;
2383
2384 /* Save the VM pointer in the machine object */
2385 pConsole->mpVM = pVM;
2386
2387 LogFlowFunc (("vrc = %Rrc\n", rc));
2388 LogFlowFuncLeave();
2389
2390 return rc;
2391}
2392/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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