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