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