VirtualBox

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

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

crOpenGL-OSX: Enable OpenGL for the Cocoa port again.

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