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