VirtualBox

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

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

networking API renaming

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 109.6 KB
Line 
1/* $Id: ConsoleImpl2.cpp 17275 2009-03-03 13:28:12Z 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 if (pBiosCfg)
836 {
837 rc = CFGMR3InsertString(pBiosCfg, "SataHardDiskDevice", "ahci"); RC_CHECK();
838 }
839
840 for (uint32_t i = 0; i < 4; i++)
841 {
842 static const char *s_apszConfig[4] =
843 { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
844 static const char *s_apszBiosConfig[4] =
845 { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
846
847 LONG lPortNumber = -1;
848 hrc = sataController->GetIDEEmulationPort(i, &lPortNumber); H();
849 rc = CFGMR3InsertInteger(pCfg, s_apszConfig[i], lPortNumber); RC_CHECK();
850 if (pBiosCfg)
851 {
852 rc = CFGMR3InsertInteger(pBiosCfg, s_apszBiosConfig[i], lPortNumber); RC_CHECK();
853 }
854 }
855
856 /* Attach the status driver */
857 rc = CFGMR3InsertNode(pSataInst,"LUN#999", &pLunL0); RC_CHECK();
858 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
859 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
860 AssertRelease(cPorts <= RT_ELEMENTS(pConsole->mapSATALeds));
861 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSATALeds[0]); RC_CHECK();
862 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
863 rc = CFGMR3InsertInteger(pCfg, "Last", cPorts - 1); RC_CHECK();
864 }
865 }
866
867 /* Attach the hard disks */
868 {
869 com::SafeIfaceArray<IHardDiskAttachment> atts;
870 hrc = pMachine->
871 COMGETTER(HardDiskAttachments) (ComSafeArrayAsOutParam (atts)); H();
872
873 for (size_t i = 0; i < atts.size(); ++ i)
874 {
875 ComPtr<IHardDisk> hardDisk;
876 hrc = atts [i]->COMGETTER(HardDisk) (hardDisk.asOutParam()); H();
877 StorageBus_T enmBus;
878 hrc = atts [i]->COMGETTER(Bus) (&enmBus); H();
879 LONG lDev;
880 hrc = atts [i]->COMGETTER(Device) (&lDev); H();
881 LONG lChannel;
882 hrc = atts [i]->COMGETTER(Channel) (&lChannel); H();
883
884 PCFGMNODE pHardDiskCtl = NULL;
885 int iLUN = 0;
886
887 switch (enmBus)
888 {
889 case StorageBus_IDE:
890 {
891 if (lChannel >= 2 || lChannel < 0)
892 {
893 AssertMsgFailed (("invalid controller channel number: "
894 "%d\n", lChannel));
895 return VERR_GENERAL_FAILURE;
896 }
897
898 if (lDev >= 2 || lDev < 0)
899 {
900 AssertMsgFailed (("invalid controller device number: "
901 "%d\n", lDev));
902 return VERR_GENERAL_FAILURE;
903 }
904
905 iLUN = 2 * lChannel + lDev;
906 pHardDiskCtl = pIdeInst;
907
908 break;
909 }
910 case StorageBus_SATA:
911 {
912 iLUN = lChannel;
913 pHardDiskCtl = enabled ? pSataInst : NULL;
914 break;
915 }
916 default:
917 {
918 AssertMsgFailed (("invalid disk controller type: "
919 "%d\n", enmBus));
920 return VERR_GENERAL_FAILURE;
921 }
922 }
923
924 /* Can be NULL if SATA controller is not enabled and current hard
925 * disk is attached to SATA controller. */
926 if (pHardDiskCtl == NULL)
927 continue;
928
929 char szLUN[16];
930 RTStrPrintf (szLUN, sizeof(szLUN), "LUN#%d", iLUN);
931
932 rc = CFGMR3InsertNode (pHardDiskCtl, szLUN, &pLunL0); RC_CHECK();
933 rc = CFGMR3InsertString (pLunL0, "Driver", "Block"); RC_CHECK();
934 rc = CFGMR3InsertNode (pLunL0, "Config", &pCfg); RC_CHECK();
935 rc = CFGMR3InsertString (pCfg, "Type", "HardDisk"); RC_CHECK();
936 rc = CFGMR3InsertInteger (pCfg, "Mountable", 0); RC_CHECK();
937
938 rc = CFGMR3InsertNode (pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
939 rc = CFGMR3InsertString (pLunL1, "Driver", "VD"); RC_CHECK();
940 rc = CFGMR3InsertNode (pLunL1, "Config", &pCfg); RC_CHECK();
941
942 hrc = hardDisk->COMGETTER(Location) (bstr.asOutParam()); H();
943 rc = CFGMR3InsertString (pCfg, "Path", Utf8Str (bstr)); RC_CHECK();
944
945 hrc = hardDisk->COMGETTER(Format) (bstr.asOutParam()); H();
946 rc = CFGMR3InsertString (pCfg, "Format", Utf8Str (bstr)); RC_CHECK();
947
948#if defined(VBOX_WITH_PDM_ASYNC_COMPLETION)
949 if (bstr == L"VMDK")
950 {
951 /* Create cfgm nodes for async transport driver because VMDK is
952 * currently the only one which may support async I/O. This has
953 * to be made generic based on the capabiliy flags when the new
954 * HardDisk interface is merged.
955 */
956 rc = CFGMR3InsertNode (pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
957 rc = CFGMR3InsertString (pLunL2, "Driver", "TransportAsync"); RC_CHECK();
958 /* The async transport driver has no config options yet. */
959 }
960#endif
961 /* Pass all custom parameters. */
962 bool fHostIP = true;
963 SafeArray <BSTR> names;
964 SafeArray <BSTR> values;
965 hrc = hardDisk->GetProperties (NULL,
966 ComSafeArrayAsOutParam (names),
967 ComSafeArrayAsOutParam (values)); H();
968
969 if (names.size() != 0)
970 {
971 PCFGMNODE pVDC;
972 rc = CFGMR3InsertNode (pCfg, "VDConfig", &pVDC); RC_CHECK();
973 for (size_t i = 0; i < names.size(); ++ i)
974 {
975 if (values [i])
976 {
977 Utf8Str name = names [i];
978 Utf8Str value = values [i];
979 rc = CFGMR3InsertString (pVDC, name, value);
980 if ( !(name.compare("HostIPStack"))
981 && !(value.compare("0")))
982 fHostIP = false;
983 }
984 }
985 }
986
987 /* Create an inversed tree of parents. */
988 ComPtr<IHardDisk> parentHardDisk = hardDisk;
989 for (PCFGMNODE pParent = pCfg;;)
990 {
991 hrc = parentHardDisk->
992 COMGETTER(Parent) (hardDisk.asOutParam()); H();
993 if (hardDisk.isNull())
994 break;
995
996 PCFGMNODE pCur;
997 rc = CFGMR3InsertNode (pParent, "Parent", &pCur); RC_CHECK();
998 hrc = hardDisk->COMGETTER(Location) (bstr.asOutParam()); H();
999 rc = CFGMR3InsertString (pCur, "Path", Utf8Str (bstr)); RC_CHECK();
1000
1001 hrc = hardDisk->COMGETTER(Format) (bstr.asOutParam()); H();
1002 rc = CFGMR3InsertString (pCur, "Format", Utf8Str (bstr)); RC_CHECK();
1003
1004 /* Pass all custom parameters. */
1005 SafeArray <BSTR> names;
1006 SafeArray <BSTR> values;
1007 hrc = hardDisk->GetProperties (NULL,
1008 ComSafeArrayAsOutParam (names),
1009 ComSafeArrayAsOutParam (values));H();
1010
1011 if (names.size() != 0)
1012 {
1013 PCFGMNODE pVDC;
1014 rc = CFGMR3InsertNode (pCur, "VDConfig", &pVDC); RC_CHECK();
1015 for (size_t i = 0; i < names.size(); ++ i)
1016 {
1017 if (values [i])
1018 {
1019 Utf8Str name = names [i];
1020 Utf8Str value = values [i];
1021 rc = CFGMR3InsertString (pVDC, name, value);
1022 if ( !(name.compare("HostIPStack"))
1023 && !(value.compare("0")))
1024 fHostIP = false;
1025 }
1026 }
1027 }
1028
1029 /* Custom code: put marker to not use host IP stack to driver
1030 * configuration node. Simplifies life of DrvVD a bit. */
1031 if (!fHostIP)
1032 {
1033 rc = CFGMR3InsertInteger (pCfg, "HostIPStack", 0); RC_CHECK();
1034 }
1035
1036 /* next */
1037 pParent = pCur;
1038 parentHardDisk = hardDisk;
1039 }
1040 }
1041 }
1042 H();
1043
1044 ComPtr<IDVDDrive> dvdDrive;
1045 hrc = pMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam()); H();
1046 if (dvdDrive)
1047 {
1048 // ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
1049 rc = CFGMR3InsertNode(pIdeInst, "LUN#2", &pLunL0); RC_CHECK();
1050 ComPtr<IHostDVDDrive> hostDvdDrive;
1051 hrc = dvdDrive->GetHostDrive(hostDvdDrive.asOutParam()); H();
1052 if (hostDvdDrive)
1053 {
1054 pConsole->meDVDState = DriveState_HostDriveCaptured;
1055 rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
1056 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1057 hrc = hostDvdDrive->COMGETTER(Name)(&str); H();
1058 STR_CONV();
1059 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
1060 STR_FREE();
1061 BOOL fPassthrough;
1062 hrc = dvdDrive->COMGETTER(Passthrough)(&fPassthrough); H();
1063 rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough); RC_CHECK();
1064 }
1065 else
1066 {
1067 pConsole->meDVDState = DriveState_NotMounted;
1068 rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
1069 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1070 rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
1071 rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
1072
1073 ComPtr<IDVDImage> dvdImage;
1074 hrc = dvdDrive->GetImage(dvdImage.asOutParam()); H();
1075 if (dvdImage)
1076 {
1077 pConsole->meDVDState = DriveState_ImageMounted;
1078 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1079 rc = CFGMR3InsertString(pLunL1, "Driver", "MediaISO"); RC_CHECK();
1080 rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
1081 hrc = dvdImage->COMGETTER(Location)(&str); H();
1082 STR_CONV();
1083 rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
1084 STR_FREE();
1085 }
1086 }
1087 }
1088
1089 /*
1090 * Network adapters
1091 */
1092 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
1093 rc = CFGMR3InsertNode(pDevices, "pcnet", &pDevPCNet); RC_CHECK();
1094#ifdef VBOX_WITH_E1000
1095 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
1096 rc = CFGMR3InsertNode(pDevices, "e1000", &pDevE1000); RC_CHECK();
1097#endif
1098 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ulInstance++)
1099 {
1100 ComPtr<INetworkAdapter> networkAdapter;
1101 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
1102 BOOL fEnabled = FALSE;
1103 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
1104 if (!fEnabled)
1105 continue;
1106
1107 /*
1108 * The virtual hardware type. Create appropriate device first.
1109 */
1110 NetworkAdapterType_T adapterType;
1111 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
1112 switch (adapterType)
1113 {
1114 case NetworkAdapterType_Am79C970A:
1115 case NetworkAdapterType_Am79C973:
1116 pDev = pDevPCNet;
1117 break;
1118#ifdef VBOX_WITH_E1000
1119 case NetworkAdapterType_I82540EM:
1120 case NetworkAdapterType_I82543GC:
1121 pDev = pDevE1000;
1122 break;
1123#endif
1124 default:
1125 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
1126 adapterType, ulInstance));
1127 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1128 N_("Invalid network adapter type '%d' for slot '%d'"),
1129 adapterType, ulInstance);
1130 }
1131
1132 char szInstance[4]; Assert(ulInstance <= 999);
1133 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1134 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1135 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1136 /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
1137 * next 4 get 16..19. */
1138 unsigned iPciDeviceNo = 3;
1139 if (ulInstance)
1140 {
1141 if (ulInstance < 4)
1142 iPciDeviceNo = ulInstance - 1 + 8;
1143 else
1144 iPciDeviceNo = ulInstance - 4 + 16;
1145 }
1146 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
1147 Assert(!afPciDeviceNo[iPciDeviceNo]);
1148 afPciDeviceNo[iPciDeviceNo] = true;
1149 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1150 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1151#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
1152 if (pDev == pDevPCNet)
1153 {
1154 rc = CFGMR3InsertInteger(pCfg, "R0Enabled", false); RC_CHECK();
1155 }
1156#endif
1157
1158 /*
1159 * The virtual hardware type. PCNet supports two types.
1160 */
1161 switch (adapterType)
1162 {
1163 case NetworkAdapterType_Am79C970A:
1164 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
1165 break;
1166 case NetworkAdapterType_Am79C973:
1167 rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
1168 break;
1169 case NetworkAdapterType_I82540EM:
1170 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
1171 break;
1172 case NetworkAdapterType_I82543GC:
1173 rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
1174 break;
1175 }
1176
1177 /*
1178 * Get the MAC address and convert it to binary representation
1179 */
1180 Bstr macAddr;
1181 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1182 Assert(macAddr);
1183 Utf8Str macAddrUtf8 = macAddr;
1184 char *macStr = (char*)macAddrUtf8.raw();
1185 Assert(strlen(macStr) == 12);
1186 RTMAC Mac;
1187 memset(&Mac, 0, sizeof(Mac));
1188 char *pMac = (char*)&Mac;
1189 for (uint32_t i = 0; i < 6; i++)
1190 {
1191 char c1 = *macStr++ - '0';
1192 if (c1 > 9)
1193 c1 -= 7;
1194 char c2 = *macStr++ - '0';
1195 if (c2 > 9)
1196 c2 -= 7;
1197 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1198 }
1199 rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
1200
1201 /*
1202 * Check if the cable is supposed to be unplugged
1203 */
1204 BOOL fCableConnected;
1205 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1206 rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
1207
1208 /*
1209 * Line speed to report from custom drivers
1210 */
1211 ULONG ulLineSpeed;
1212 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1213 rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
1214
1215 /*
1216 * Attach the status driver.
1217 */
1218 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1219 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1220 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1221 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
1222
1223 /*
1224 * Enable the packet sniffer if requested.
1225 */
1226 BOOL fSniffer;
1227 hrc = networkAdapter->COMGETTER(TraceEnabled)(&fSniffer); H();
1228 if (fSniffer)
1229 {
1230 /* insert the sniffer filter driver. */
1231 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1232 rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
1233 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1234 hrc = networkAdapter->COMGETTER(TraceFile)(&str); H();
1235 if (str) /* check convention for indicating default file. */
1236 {
1237 STR_CONV();
1238 rc = CFGMR3InsertString(pCfg, "File", psz); RC_CHECK();
1239 STR_FREE();
1240 }
1241 }
1242
1243 NetworkAttachmentType_T networkAttachment;
1244 hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H();
1245 switch (networkAttachment)
1246 {
1247 case NetworkAttachmentType_Null:
1248 break;
1249
1250 case NetworkAttachmentType_NAT:
1251 {
1252 if (fSniffer)
1253 {
1254 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1255 }
1256 else
1257 {
1258 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1259 }
1260 rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
1261 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1262 /* (Port forwarding goes here.) */
1263
1264 /* Configure TFTP prefix and boot filename. */
1265 hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
1266 STR_CONV();
1267 if (psz && *psz)
1268 {
1269 char *pszTFTPPrefix = NULL;
1270 RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
1271 rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix); RC_CHECK();
1272 RTStrFree(pszTFTPPrefix);
1273 }
1274 STR_FREE();
1275 hrc = pMachine->COMGETTER(Name)(&str); H();
1276 STR_CONV();
1277 char *pszBootFile = NULL;
1278 RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
1279 STR_FREE();
1280 rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile); RC_CHECK();
1281 RTStrFree(pszBootFile);
1282
1283 hrc = networkAdapter->COMGETTER(NATNetwork)(&str); H();
1284 if (str)
1285 {
1286 STR_CONV();
1287 if (psz && *psz)
1288 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1289 STR_FREE();
1290 }
1291 break;
1292 }
1293
1294 case NetworkAttachmentType_Bridged:
1295 {
1296 /*
1297 * Perform the attachment if required (don't return on error!)
1298 */
1299 hrc = pConsole->attachToBridgedInterface(networkAdapter);
1300 if (SUCCEEDED(hrc))
1301 {
1302#if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
1303 Assert ((int)pConsole->maTapFD[ulInstance] >= 0);
1304 if ((int)pConsole->maTapFD[ulInstance] >= 0)
1305 {
1306 if (fSniffer)
1307 {
1308 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1309 }
1310 else
1311 {
1312 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1313 }
1314 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1315 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1316 rc = CFGMR3InsertInteger(pCfg, "FileHandle", pConsole->maTapFD[ulInstance]); RC_CHECK();
1317 }
1318#elif defined(VBOX_WITH_NETFLT)
1319 /*
1320 * This is the new VBoxNetFlt+IntNet stuff.
1321 */
1322 if (fSniffer)
1323 {
1324 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1325 }
1326 else
1327 {
1328 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1329 }
1330
1331 Bstr HifName;
1332 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1333 if(FAILED(hrc))
1334 {
1335 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1336 H();
1337 }
1338
1339 Utf8Str HifNameUtf8(HifName);
1340 const char *pszHifName = HifNameUtf8.raw();
1341
1342# if defined(RT_OS_DARWIN)
1343 /* The name is on the form 'ifX: long name', chop it off at the colon. */
1344 char szTrunk[8];
1345 strncpy(szTrunk, pszHifName, sizeof(szTrunk));
1346 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1347 if (!pszColon)
1348 {
1349 hrc = networkAdapter->Detach(); H();
1350 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1351 N_("Malformed host interface networking name '%ls'"),
1352 HifName.raw());
1353 }
1354 *pszColon = '\0';
1355 const char *pszTrunk = szTrunk;
1356
1357# elif defined(RT_OS_SOLARIS)
1358 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
1359 char szTrunk[256];
1360 strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
1361 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
1362
1363 /*
1364 * Currently don't bother about malformed names here for the sake of people using
1365 * VBoxManage and setting only the NIC name from there. If there is a space we
1366 * chop it off and proceed, otherwise just use whatever we've got.
1367 */
1368 if (pszSpace)
1369 *pszSpace = '\0';
1370
1371 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
1372 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
1373 if (pszColon)
1374 *pszColon = '\0';
1375
1376 const char *pszTrunk = szTrunk;
1377
1378# elif defined(RT_OS_WINDOWS)
1379 ComPtr<IHostNetworkInterface> hostInterface;
1380 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1381 if (!SUCCEEDED(rc))
1382 {
1383 AssertBreakpoint();
1384 LogRel(("NetworkAttachmentType_Bridged: FindByName failed, rc (0x%x)", rc));
1385 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1386 N_("Inexistent host networking interface, name '%ls'"),
1387 HifName.raw());
1388 }
1389
1390 HostNetworkInterfaceType_T ifType;
1391 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
1392 if(FAILED(hrc))
1393 {
1394 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
1395 H();
1396 }
1397
1398 if(ifType != HostNetworkInterfaceType_Bridged)
1399 {
1400 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1401 N_("Interface ('%ls') is not a Bridged Adapter interface"),
1402 HifName.raw());
1403 }
1404
1405 Guid hostIFGuid;
1406 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1407 if(FAILED(hrc))
1408 {
1409 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1410 H();
1411 }
1412 char szDriverGUID[RTUUID_STR_LENGTH];
1413 strcpy(szDriverGUID , hostIFGuid.toString().raw());
1414 const char *pszTrunk = szDriverGUID;
1415# elif defined(RT_OS_LINUX)
1416 /* @todo Check for malformed names. */
1417 const char *pszTrunk = pszHifName;
1418
1419# else
1420# error "PORTME (VBOX_WITH_NETFLT)"
1421# endif
1422
1423 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1424 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1425 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1426 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1427 char szNetwork[80];
1428 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1429 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1430
1431# if defined(RT_OS_DARWIN)
1432 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
1433 if ( strstr(pszHifName, "Wireless")
1434 || strstr(pszHifName, "AirPort" ))
1435 {
1436 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1437 }
1438# elif defined(RT_OS_LINUX)
1439 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
1440 if (iSock >= 0)
1441 {
1442 struct iwreq WRq;
1443
1444 memset(&WRq, 0, sizeof(WRq));
1445 strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
1446 if (ioctl(iSock, SIOCGIWNAME, &WRq) >= 0)
1447 {
1448 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1449 Log(("Set SharedMacOnWire\n"));
1450 }
1451 else
1452 {
1453 Log(("Failed to get wireless name\n"));
1454 }
1455 close(iSock);
1456 }
1457 else
1458 {
1459 Log(("Failed to open wireless socket\n"));
1460 }
1461# elif defined(RT_OS_WINDOWS)
1462# define DEVNAME_PREFIX L"\\\\.\\"
1463 INetCfg *pNc;
1464 LPWSTR lpszApp;
1465 HRESULT hr;
1466 int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
1467
1468 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
1469 * there is a pretty long way till there though since we need to obtain the symbolic link name
1470 * for the adapter device we are going to query given the device Guid */
1471 hr = VBoxNetCfgWinQueryINetCfg( FALSE,
1472 L"VirtualBox",
1473 &pNc,
1474 &lpszApp );
1475 Assert(hr == S_OK);
1476 if(hr == S_OK)
1477 {
1478 /* get the adapter's INetCfgComponent*/
1479 INetCfgComponent *pAdaptorComponent;
1480 hr = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), &pAdaptorComponent);
1481 Assert(hr == S_OK);
1482 if(hr == S_OK)
1483 {
1484 /* now get the bind name */
1485 LPWSTR pName;
1486 hr = pAdaptorComponent->GetBindName(&pName);
1487 Assert(hr == S_OK);
1488 if(hr == S_OK)
1489 {
1490 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
1491 wchar_t FileName[MAX_PATH];
1492 wcscpy(FileName, DEVNAME_PREFIX);
1493 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pName);
1494
1495 /* open the device */
1496 HANDLE hDevice = CreateFile(FileName,
1497 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
1498 NULL,
1499 OPEN_EXISTING,
1500 FILE_ATTRIBUTE_NORMAL,
1501 NULL);
1502 if (hDevice != INVALID_HANDLE_VALUE)
1503 {
1504 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
1505 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
1506 NDIS_PHYSICAL_MEDIUM PhMedium;
1507 DWORD cbResult;
1508 if (DeviceIoControl(hDevice, IOCTL_NDIS_QUERY_GLOBAL_STATS, &Oid, sizeof(Oid), &PhMedium, sizeof(PhMedium), &cbResult, NULL))
1509 {
1510 /* that was simple, now examine PhMedium */
1511 if(PhMedium == NdisPhysicalMediumWirelessWan
1512 || PhMedium == NdisPhysicalMediumWirelessLan
1513 || PhMedium == NdisPhysicalMediumNative802_11
1514 || PhMedium == NdisPhysicalMediumBluetooth
1515 /*|| PhMedium == NdisPhysicalMediumWiMax*/
1516 )
1517 {
1518 Log(("this is a wireles adapter"));
1519 rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
1520 Log(("Set SharedMacOnWire\n"));
1521 }
1522 else
1523 {
1524 Log(("this is NOT a wireles adapter"));
1525 }
1526 }
1527 else
1528 {
1529 int winEr = GetLastError();
1530 LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
1531 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
1532 }
1533
1534 CloseHandle(hDevice);
1535 }
1536 else
1537 {
1538 int winEr = GetLastError();
1539 LogRel(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
1540 AssertBreakpoint();
1541 }
1542 CoTaskMemFree(pName);
1543 }
1544 VBoxNetCfgWinReleaseRef(pAdaptorComponent);
1545 }
1546 VBoxNetCfgWinReleaseINetCfg( pNc, FALSE );
1547 }
1548# else
1549 /** @todo PORTME: wireless detection */
1550# endif
1551
1552# if defined(RT_OS_SOLARIS)
1553# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
1554 /* Zone access restriction, don't allow snopping the global zone. */
1555 zoneid_t ZoneId = getzoneid();
1556 if (ZoneId != GLOBAL_ZONEID)
1557 {
1558 rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
1559 }
1560# endif
1561# endif
1562
1563#elif defined(RT_OS_WINDOWS)
1564 if (fSniffer)
1565 {
1566 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1567 }
1568 else
1569 {
1570 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1571 }
1572 Bstr hostInterfaceName;
1573 hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
1574 ComPtr<IHostNetworkInterface> hostInterface;
1575 rc = host->FindHostNetworkInterfaceByName(hostInterfaceName, hostInterface.asOutParam());
1576 if (!SUCCEEDED(rc))
1577 {
1578 AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
1579 hrc = networkAdapter->Detach(); H();
1580 }
1581 else
1582 {
1583# ifndef VBOX_WITH_NETFLT
1584 rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
1585 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1586 rc = CFGMR3InsertString(pCfg, "HostInterfaceName", Utf8Str(hostInterfaceName)); RC_CHECK();
1587# else
1588 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1589 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1590 rc = CFGMR3InsertString(pCfg, "Trunk", Utf8Str(hostInterfaceName)); RC_CHECK();
1591 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1592# endif
1593 Guid hostIFGuid;
1594 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
1595 char szDriverGUID[256] = {0};
1596 /* add curly brackets */
1597 szDriverGUID[0] = '{';
1598 strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
1599 strcat(szDriverGUID, "}");
1600 rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
1601 }
1602#elif defined(RT_OS_LINUX)
1603/// @todo aleksey: is there anything to be done here?
1604#elif defined(RT_OS_FREEBSD)
1605/** @todo FreeBSD: Check out this later (HIF networking). */
1606#else
1607# error "Port me"
1608#endif
1609 }
1610 else
1611 {
1612 switch (hrc)
1613 {
1614#ifdef RT_OS_LINUX
1615 case VERR_ACCESS_DENIED:
1616 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1617 "Failed to open '/dev/net/tun' for read/write access. Please check the "
1618 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
1619 "change the group of that node and make yourself a member of that group. Make "
1620 "sure that these changes are permanent, especially if you are "
1621 "using udev"));
1622#endif /* RT_OS_LINUX */
1623 default:
1624 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
1625 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
1626 "Failed to initialize Host Interface Networking"));
1627 }
1628 }
1629 break;
1630 }
1631
1632 case NetworkAttachmentType_Internal:
1633 {
1634 hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
1635 if (str)
1636 {
1637 STR_CONV();
1638 if (psz && *psz)
1639 {
1640 if (fSniffer)
1641 {
1642 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1643 }
1644 else
1645 {
1646 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1647 }
1648 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1649 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1650 rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
1651 }
1652 STR_FREE();
1653 }
1654 break;
1655 }
1656
1657 case NetworkAttachmentType_HostOnly:
1658 {
1659 if (fSniffer)
1660 {
1661 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
1662 }
1663 else
1664 {
1665 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1666 }
1667
1668 rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
1669 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1670#if defined(RT_OS_WINDOWS)
1671 Bstr HifName;
1672 hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
1673 if(FAILED(hrc))
1674 {
1675 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
1676 H();
1677 }
1678
1679 Utf8Str HifNameUtf8(HifName);
1680 const char *pszHifName = HifNameUtf8.raw();
1681 ComPtr<IHostNetworkInterface> hostInterface;
1682 rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
1683 if (!SUCCEEDED(rc))
1684 {
1685 AssertBreakpoint();
1686 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)", rc));
1687 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1688 N_("Inexistent host networking interface, name '%ls'"),
1689 HifName.raw());
1690 }
1691
1692 HostNetworkInterfaceType_T ifType;
1693 hrc = hostInterface->COMGETTER(InterfaceType)(&ifType);
1694 if(FAILED(hrc))
1695 {
1696 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
1697 H();
1698 }
1699
1700 if(ifType != HostNetworkInterfaceType_HostOnly)
1701 {
1702 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
1703 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
1704 HifName.raw());
1705 }
1706
1707
1708 Guid hostIFGuid;
1709 hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam());
1710 if(FAILED(hrc))
1711 {
1712 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)", hrc));
1713 H();
1714 }
1715 char szDriverGUID[RTUUID_STR_LENGTH];
1716 strcpy(szDriverGUID , hostIFGuid.toString().raw());
1717 const char *pszTrunk = szDriverGUID;
1718
1719 /* TODO: set the proper Trunk and Network values, currently the driver uses the first adapter instance */
1720 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
1721 rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
1722 char szNetwork[80];
1723 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
1724 rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
1725#elif defined(RT_OS_DARWIN)
1726 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK();
1727 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0"); RC_CHECK();
1728 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
1729#else
1730 rc = CFGMR3InsertString(pCfg, "Trunk", "vboxnet0"); RC_CHECK();
1731 rc = CFGMR3InsertString(pCfg, "Network", "HostInterfaceNetworking-vboxnet0"); RC_CHECK();
1732 rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
1733#endif
1734 break;
1735 }
1736
1737 default:
1738 AssertMsgFailed(("should not get here!\n"));
1739 break;
1740 }
1741 }
1742
1743 /*
1744 * Serial (UART) Ports
1745 */
1746 rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
1747 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
1748 {
1749 ComPtr<ISerialPort> serialPort;
1750 hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
1751 BOOL fEnabled = FALSE;
1752 if (serialPort)
1753 hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
1754 if (!fEnabled)
1755 continue;
1756
1757 char szInstance[4]; Assert(ulInstance <= 999);
1758 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1759
1760 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1761 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1762
1763 ULONG ulIRQ, ulIOBase;
1764 PortMode_T HostMode;
1765 Bstr path;
1766 BOOL fServer;
1767 hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
1768 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1769 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1770 hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
1771 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1772 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1773 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1774 if (HostMode != PortMode_Disconnected)
1775 {
1776 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1777 if (HostMode == PortMode_HostPipe)
1778 {
1779 rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
1780 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1781 rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
1782 rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
1783 rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
1784 rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
1785 }
1786 else if (HostMode == PortMode_HostDevice)
1787 {
1788 rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
1789 rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
1790 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
1791 }
1792 }
1793 }
1794
1795 /*
1796 * Parallel (LPT) Ports
1797 */
1798 rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
1799 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
1800 {
1801 ComPtr<IParallelPort> parallelPort;
1802 hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
1803 BOOL fEnabled = FALSE;
1804 if (parallelPort)
1805 hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
1806 if (!fEnabled)
1807 continue;
1808
1809 char szInstance[4]; Assert(ulInstance <= 999);
1810 RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
1811
1812 rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
1813 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1814
1815 ULONG ulIRQ, ulIOBase;
1816 Bstr DevicePath;
1817 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
1818 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
1819 hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
1820 rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
1821 rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
1822 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1823 rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
1824 rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
1825 rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
1826 }
1827
1828 /*
1829 * VMM Device
1830 */
1831 rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
1832 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1833 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1834 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
1835 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
1836 Assert(!afPciDeviceNo[4]);
1837 afPciDeviceNo[4] = true;
1838 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1839 Bstr hwVersion;
1840 hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
1841 if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
1842 {
1843 CFGMR3InsertInteger(pCfg, "HeapEnabled", 0); RC_CHECK();
1844 }
1845
1846 /* the VMM device's Main driver */
1847 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1848 rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
1849 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1850 VMMDev *pVMMDev = pConsole->mVMMDev;
1851 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
1852
1853 /*
1854 * Attach the status driver.
1855 */
1856 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
1857 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
1858 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1859 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
1860 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
1861 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
1862
1863 /*
1864 * Audio Sniffer Device
1865 */
1866 rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
1867 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1868 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1869
1870 /* the Audio Sniffer device's Main driver */
1871 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1872 rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
1873 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1874 AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
1875 rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
1876
1877 /*
1878 * AC'97 ICH / SoundBlaster16 audio
1879 */
1880 ComPtr<IAudioAdapter> audioAdapter;
1881 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
1882 if (audioAdapter)
1883 hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
1884
1885 if (enabled)
1886 {
1887 AudioControllerType_T audioController;
1888 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
1889 switch (audioController)
1890 {
1891 case AudioControllerType_AC97:
1892 {
1893 /* default: ICH AC97 */
1894 rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
1895 rc = CFGMR3InsertNode(pDev, "0", &pInst);
1896 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1897 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
1898 Assert(!afPciDeviceNo[5]);
1899 afPciDeviceNo[5] = true;
1900 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
1901 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1902 break;
1903 }
1904 case AudioControllerType_SB16:
1905 {
1906 /* legacy SoundBlaster16 */
1907 rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
1908 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
1909 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
1910 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
1911 rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
1912 rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
1913 rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
1914 rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
1915 rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
1916 break;
1917 }
1918 }
1919
1920 /* the Audio driver */
1921 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
1922 rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
1923 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
1924
1925 AudioDriverType_T audioDriver;
1926 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
1927 switch (audioDriver)
1928 {
1929 case AudioDriverType_Null:
1930 {
1931 rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
1932 break;
1933 }
1934#ifdef RT_OS_WINDOWS
1935#ifdef VBOX_WITH_WINMM
1936 case AudioDriverType_WinMM:
1937 {
1938 rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
1939 break;
1940 }
1941#endif
1942 case AudioDriverType_DirectSound:
1943 {
1944 rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
1945 break;
1946 }
1947#endif /* RT_OS_WINDOWS */
1948#ifdef RT_OS_SOLARIS
1949 case AudioDriverType_SolAudio:
1950 {
1951 rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
1952 break;
1953 }
1954#endif
1955#ifdef RT_OS_LINUX
1956 case AudioDriverType_OSS:
1957 {
1958 rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
1959 break;
1960 }
1961# ifdef VBOX_WITH_ALSA
1962 case AudioDriverType_ALSA:
1963 {
1964 rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
1965 break;
1966 }
1967# endif
1968# ifdef VBOX_WITH_PULSE
1969 case AudioDriverType_Pulse:
1970 {
1971 rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
1972 break;
1973 }
1974# endif
1975#endif /* RT_OS_LINUX */
1976#ifdef RT_OS_DARWIN
1977 case AudioDriverType_CoreAudio:
1978 {
1979 rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
1980 break;
1981 }
1982#endif
1983 }
1984 hrc = pMachine->COMGETTER(Name)(&str); H();
1985 STR_CONV();
1986 rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
1987 STR_FREE();
1988 }
1989
1990 /*
1991 * The USB Controller.
1992 */
1993 ComPtr<IUSBController> USBCtlPtr;
1994 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
1995 if (USBCtlPtr)
1996 {
1997 BOOL fEnabled;
1998 hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
1999 if (fEnabled)
2000 {
2001 rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
2002 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2003 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2004 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
2005 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
2006 Assert(!afPciDeviceNo[6]);
2007 afPciDeviceNo[6] = true;
2008 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2009
2010 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2011 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2012 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2013
2014 /*
2015 * Attach the status driver.
2016 */
2017 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2018 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2019 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2020 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
2021 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2022 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2023
2024#ifdef VBOX_WITH_EHCI
2025 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
2026 if (fEnabled)
2027 {
2028 rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
2029 rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
2030 rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
2031 rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
2032 rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
2033 Assert(!afPciDeviceNo[11]);
2034 afPciDeviceNo[11] = true;
2035 rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
2036
2037 rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
2038 rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
2039 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2040
2041 /*
2042 * Attach the status driver.
2043 */
2044 rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
2045 rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
2046 rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
2047 rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
2048 rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
2049 rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
2050 }
2051 else
2052#endif
2053 {
2054 /*
2055 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
2056 * on a per device level now.
2057 */
2058 rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
2059 rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
2060 rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
2061 // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
2062 //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
2063 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
2064 // that it's documented somewhere.) Users needing it can use:
2065 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
2066 //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
2067 }
2068 }
2069 }
2070
2071 /*
2072 * Clipboard
2073 */
2074 {
2075 ClipboardMode_T mode = ClipboardMode_Disabled;
2076 hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
2077
2078 if (mode != ClipboardMode_Disabled)
2079 {
2080 /* Load the service */
2081 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
2082
2083 if (RT_FAILURE (rc))
2084 {
2085 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
2086 /* That is not a fatal failure. */
2087 rc = VINF_SUCCESS;
2088 }
2089 else
2090 {
2091 /* Setup the service. */
2092 VBOXHGCMSVCPARM parm;
2093
2094 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2095
2096 switch (mode)
2097 {
2098 default:
2099 case ClipboardMode_Disabled:
2100 {
2101 LogRel(("VBoxSharedClipboard mode: Off\n"));
2102 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
2103 break;
2104 }
2105 case ClipboardMode_GuestToHost:
2106 {
2107 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
2108 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
2109 break;
2110 }
2111 case ClipboardMode_HostToGuest:
2112 {
2113 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
2114 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
2115 break;
2116 }
2117 case ClipboardMode_Bidirectional:
2118 {
2119 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
2120 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
2121 break;
2122 }
2123 }
2124
2125 pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
2126
2127 Log(("Set VBoxSharedClipboard mode\n"));
2128 }
2129 }
2130 }
2131
2132#ifdef VBOX_WITH_CROGL
2133 /*
2134 * crOpenGL
2135 */
2136 {
2137 BOOL fEnabled = false;
2138 hrc = pMachine->COMGETTER(Accelerate3DEnabled) (&fEnabled); H();
2139
2140 if (fEnabled)
2141 {
2142 /* Load the service */
2143 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
2144 if (RT_FAILURE(rc))
2145 {
2146 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
2147 /* That is not a fatal failure. */
2148 rc = VINF_SUCCESS;
2149 }
2150 else
2151 {
2152 LogRel(("Shared crOpenGL service loaded.\n"));
2153
2154 /* Setup the service. */
2155 VBOXHGCMSVCPARM parm;
2156 parm.type = VBOX_HGCM_SVC_PARM_PTR;
2157
2158 //parm.u.pointer.addr = static_cast <IConsole *> (pData->pVMMDev->getParent());
2159 parm.u.pointer.addr = pConsole->mVMMDev->getParent()->getDisplay()->getFramebuffer();
2160 parm.u.pointer.size = sizeof(IFramebuffer *);
2161
2162 rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_FRAMEBUFFER, 1, &parm);
2163 if (!RT_SUCCESS(rc))
2164 AssertMsgFailed(("SHCRGL_HOST_FN_SET_FRAMEBUFFER failed with %Rrc\n", rc));
2165 }
2166 }
2167 }
2168#endif
2169
2170#ifdef VBOX_WITH_GUEST_PROPS
2171 /*
2172 * Guest property service
2173 */
2174 {
2175 /* Load the service */
2176 rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
2177
2178 if (RT_FAILURE (rc))
2179 {
2180 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
2181 /* That is not a fatal failure. */
2182 rc = VINF_SUCCESS;
2183 }
2184 else
2185 {
2186 /* Pull over the properties from the server. */
2187 SafeArray <BSTR> namesOut;
2188 SafeArray <BSTR> valuesOut;
2189 SafeArray <ULONG64> timestampsOut;
2190 SafeArray <BSTR> flagsOut;
2191 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
2192 ComSafeArrayAsOutParam(valuesOut),
2193 ComSafeArrayAsOutParam(timestampsOut),
2194 ComSafeArrayAsOutParam(flagsOut)); H();
2195 size_t cProps = namesOut.size();
2196 if ( valuesOut.size() != cProps
2197 || timestampsOut.size() != cProps
2198 || flagsOut.size() != cProps
2199 )
2200 rc = VERR_INVALID_PARAMETER;
2201
2202 std::vector <Utf8Str> utf8Names, utf8Values, utf8Flags;
2203 std::vector <char *> names, values, flags;
2204 std::vector <ULONG64> timestamps;
2205 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2206 if ( !VALID_PTR(namesOut[i])
2207 || !VALID_PTR(valuesOut[i])
2208 || !VALID_PTR(flagsOut[i])
2209 )
2210 rc = VERR_INVALID_POINTER;
2211 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2212 {
2213 utf8Names.push_back(Bstr(namesOut[i]));
2214 utf8Values.push_back(Bstr(valuesOut[i]));
2215 timestamps.push_back(timestampsOut[i]);
2216 utf8Flags.push_back(Bstr(flagsOut[i]));
2217 if ( utf8Names.back().isNull()
2218 || utf8Values.back().isNull()
2219 || utf8Flags.back().isNull()
2220 )
2221 throw std::bad_alloc();
2222 }
2223 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i)
2224 {
2225 names.push_back(utf8Names[i].mutableRaw());
2226 values.push_back(utf8Values[i].mutableRaw());
2227 flags.push_back(utf8Flags[i].mutableRaw());
2228 }
2229 names.push_back(NULL);
2230 values.push_back(NULL);
2231 timestamps.push_back(0);
2232 flags.push_back(NULL);
2233
2234 /* Setup the service. */
2235 VBOXHGCMSVCPARM parms[4];
2236
2237 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
2238 parms[0].u.pointer.addr = &names.front();
2239 parms[0].u.pointer.size = 0; /* We don't actually care. */
2240 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
2241 parms[1].u.pointer.addr = &values.front();
2242 parms[1].u.pointer.size = 0; /* We don't actually care. */
2243 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
2244 parms[2].u.pointer.addr = &timestamps.front();
2245 parms[2].u.pointer.size = 0; /* We don't actually care. */
2246 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
2247 parms[3].u.pointer.addr = &flags.front();
2248 parms[3].u.pointer.size = 0; /* We don't actually care. */
2249
2250 pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4, &parms[0]);
2251
2252 /* Register the host notification callback */
2253 HGCMSVCEXTHANDLE hDummy;
2254 HGCMHostRegisterServiceExtension (&hDummy, "VBoxGuestPropSvc",
2255 Console::doGuestPropNotification,
2256 pvConsole);
2257
2258 Log(("Set VBoxGuestPropSvc property store\n"));
2259 }
2260 }
2261#endif /* VBOX_WITH_GUEST_PROPS defined */
2262
2263 /*
2264 * CFGM overlay handling.
2265 *
2266 * Here we check the extra data entries for CFGM values
2267 * and create the nodes and insert the values on the fly. Existing
2268 * values will be removed and reinserted. CFGM is typed, so by default
2269 * we will guess whether it's a string or an integer (byte arrays are
2270 * not currently supported). It's possible to override this autodetection
2271 * by adding "string:", "integer:" or "bytes:" (future).
2272 *
2273 * We first perform a run on global extra data, then on the machine
2274 * extra data to support global settings with local overrides.
2275 *
2276 */
2277 /** @todo add support for removing nodes and byte blobs. */
2278 Bstr strExtraDataKey;
2279 bool fGlobalExtraData = true;
2280 for (;;)
2281 {
2282 /*
2283 * Get the next key
2284 */
2285 Bstr strNextExtraDataKey;
2286 Bstr strExtraDataValue;
2287 if (fGlobalExtraData)
2288 hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2289 strExtraDataValue.asOutParam());
2290 else
2291 hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
2292 strExtraDataValue.asOutParam());
2293
2294 /* stop if for some reason there's nothing more to request */
2295 if (FAILED(hrc) || !strNextExtraDataKey)
2296 {
2297 /* if we're out of global keys, continue with machine, otherwise we're done */
2298 if (fGlobalExtraData)
2299 {
2300 fGlobalExtraData = false;
2301 strExtraDataKey.setNull();
2302 continue;
2303 }
2304 break;
2305 }
2306 strExtraDataKey = strNextExtraDataKey;
2307
2308 /*
2309 * We only care about keys starting with "VBoxInternal/"
2310 */
2311 Utf8Str strExtraDataKeyUtf8(strExtraDataKey);
2312 char *pszExtraDataKey = (char *)strExtraDataKeyUtf8.raw();
2313 if (strncmp(pszExtraDataKey, "VBoxInternal/", sizeof("VBoxInternal/") - 1) != 0)
2314 continue;
2315 pszExtraDataKey += sizeof("VBoxInternal/") - 1;
2316
2317 /*
2318 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2319 * Split the two and get the node, delete the value and create the node
2320 * if necessary.
2321 */
2322 PCFGMNODE pNode;
2323 char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2324 if (pszCFGMValueName)
2325 {
2326 /* terminate the node and advance to the value (Utf8Str might not
2327 offically like this but wtf) */
2328 *pszCFGMValueName = '\0';
2329 pszCFGMValueName++;
2330
2331 /* does the node already exist? */
2332 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2333 if (pNode)
2334 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2335 else
2336 {
2337 /* create the node */
2338 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2339 if (RT_FAILURE(rc))
2340 {
2341 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2342 continue;
2343 }
2344 Assert(pNode);
2345 }
2346 }
2347 else
2348 {
2349 /* root value (no node path). */
2350 pNode = pRoot;
2351 pszCFGMValueName = pszExtraDataKey;
2352 pszExtraDataKey--;
2353 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2354 }
2355
2356 /*
2357 * Now let's have a look at the value.
2358 * Empty strings means that we should remove the value, which we've
2359 * already done above.
2360 */
2361 Utf8Str strCFGMValueUtf8(strExtraDataValue);
2362 const char *pszCFGMValue = strCFGMValueUtf8.raw();
2363 if ( pszCFGMValue
2364 && *pszCFGMValue)
2365 {
2366 uint64_t u64Value;
2367
2368 /* check for type prefix first. */
2369 if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
2370 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
2371 else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
2372 {
2373 rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
2374 if (RT_SUCCESS(rc))
2375 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2376 }
2377 else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
2378 rc = VERR_NOT_IMPLEMENTED;
2379 /* auto detect type. */
2380 else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
2381 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2382 else
2383 rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
2384 AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
2385 }
2386 }
2387
2388#undef H
2389#undef RC_CHECK
2390#undef STR_FREE
2391#undef STR_CONV
2392
2393 /* Register VM state change handler */
2394 int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
2395 AssertRC (rc2);
2396 if (RT_SUCCESS (rc))
2397 rc = rc2;
2398
2399 /* Register VM runtime error handler */
2400 rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
2401 AssertRC (rc2);
2402 if (RT_SUCCESS (rc))
2403 rc = rc2;
2404
2405 /* Save the VM pointer in the machine object */
2406 pConsole->mpVM = pVM;
2407
2408 LogFlowFunc (("vrc = %Rrc\n", rc));
2409 LogFlowFuncLeave();
2410
2411 return rc;
2412}
2413/* 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