VirtualBox

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

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

Allow up to 8 network cards.

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