VirtualBox

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

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

Main/HardDisk2Impl: copy zero terminator too. Also deal correctly with NULL values on VM start in ConsoleImpl.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette