1 | /* $Id: ConsoleImpl2.cpp 29564 2010-05-17 15:19:33Z 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 Oracle Corporation
|
---|
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 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #include "ConsoleImpl.h"
|
---|
27 | #include "DisplayImpl.h"
|
---|
28 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
29 | # include "GuestImpl.h"
|
---|
30 | #endif
|
---|
31 | #include "VMMDev.h"
|
---|
32 | #include "Global.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/ctype.h>
|
---|
42 | #include <iprt/dir.h>
|
---|
43 | #include <iprt/file.h>
|
---|
44 | #include <iprt/param.h>
|
---|
45 | #include <iprt/path.h>
|
---|
46 | #include <iprt/string.h>
|
---|
47 | #include <iprt/system.h>
|
---|
48 | #if 0 /* enable to play with lots of memory. */
|
---|
49 | # include <iprt/env.h>
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | #include <VBox/vmapi.h>
|
---|
53 | #include <VBox/err.h>
|
---|
54 | #include <VBox/param.h>
|
---|
55 | #include <VBox/pdmapi.h> /* For PDMR3DriverAttach/PDMR3DriverDetach */
|
---|
56 | #include <VBox/version.h>
|
---|
57 | #include <VBox/HostServices/VBoxClipboardSvc.h>
|
---|
58 | #ifdef VBOX_WITH_CROGL
|
---|
59 | # include <VBox/HostServices/VBoxCrOpenGLSvc.h>
|
---|
60 | #endif
|
---|
61 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
62 | # include <VBox/HostServices/GuestPropertySvc.h>
|
---|
63 | # include <VBox/com/defs.h>
|
---|
64 | # include <VBox/com/array.h>
|
---|
65 | # include <hgcm/HGCM.h> /** @todo it should be possible to register a service
|
---|
66 | * extension using a VMMDev callback. */
|
---|
67 | # include <vector>
|
---|
68 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
69 | #include <VBox/intnet.h>
|
---|
70 |
|
---|
71 | #include <VBox/com/com.h>
|
---|
72 | #include <VBox/com/string.h>
|
---|
73 | #include <VBox/com/array.h>
|
---|
74 |
|
---|
75 | #ifdef VBOX_WITH_NETFLT
|
---|
76 | # if defined(RT_OS_SOLARIS)
|
---|
77 | # include <zone.h>
|
---|
78 | # elif defined(RT_OS_LINUX)
|
---|
79 | # include <unistd.h>
|
---|
80 | # include <sys/ioctl.h>
|
---|
81 | # include <sys/socket.h>
|
---|
82 | # include <linux/types.h>
|
---|
83 | # include <linux/if.h>
|
---|
84 | # include <linux/wireless.h>
|
---|
85 | # elif defined(RT_OS_FREEBSD)
|
---|
86 | # include <unistd.h>
|
---|
87 | # include <sys/types.h>
|
---|
88 | # include <sys/ioctl.h>
|
---|
89 | # include <sys/socket.h>
|
---|
90 | # include <net/if.h>
|
---|
91 | # include <net80211/ieee80211_ioctl.h>
|
---|
92 | # endif
|
---|
93 | # if defined(RT_OS_WINDOWS)
|
---|
94 | # include <VBox/WinNetConfig.h>
|
---|
95 | # include <Ntddndis.h>
|
---|
96 | # include <devguid.h>
|
---|
97 | # else
|
---|
98 | # include <HostNetworkInterfaceImpl.h>
|
---|
99 | # include <netif.h>
|
---|
100 | # include <stdlib.h>
|
---|
101 | # endif
|
---|
102 | #endif /* VBOX_WITH_NETFLT */
|
---|
103 |
|
---|
104 | #include "DHCPServerRunner.h"
|
---|
105 |
|
---|
106 | #if defined(RT_OS_DARWIN)
|
---|
107 |
|
---|
108 | # include "IOKit/IOKitLib.h"
|
---|
109 |
|
---|
110 | static int DarwinSmcKey(char *pabKey, uint32_t cbKey)
|
---|
111 | {
|
---|
112 | /*
|
---|
113 | * Method as described in Amit Singh's article:
|
---|
114 | * http://osxbook.com/book/bonus/chapter7/tpmdrmmyth/
|
---|
115 | */
|
---|
116 | typedef struct
|
---|
117 | {
|
---|
118 | uint32_t key;
|
---|
119 | uint8_t pad0[22];
|
---|
120 | uint32_t datasize;
|
---|
121 | uint8_t pad1[10];
|
---|
122 | uint8_t cmd;
|
---|
123 | uint32_t pad2;
|
---|
124 | uint8_t data[32];
|
---|
125 | } AppleSMCBuffer;
|
---|
126 |
|
---|
127 | AssertReturn(cbKey >= 65, VERR_INTERNAL_ERROR);
|
---|
128 |
|
---|
129 | io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
|
---|
130 | IOServiceMatching("AppleSMC"));
|
---|
131 | if (!service)
|
---|
132 | return VERR_NOT_FOUND;
|
---|
133 |
|
---|
134 | io_connect_t port = (io_connect_t)0;
|
---|
135 | kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
|
---|
136 | IOObjectRelease(service);
|
---|
137 |
|
---|
138 | if (kr != kIOReturnSuccess)
|
---|
139 | return RTErrConvertFromDarwin(kr);
|
---|
140 |
|
---|
141 | AppleSMCBuffer inputStruct = { 0, {0}, 32, {0}, 5, };
|
---|
142 | AppleSMCBuffer outputStruct;
|
---|
143 | size_t cbOutputStruct = sizeof(outputStruct);
|
---|
144 |
|
---|
145 | for (int i = 0; i < 2; i++)
|
---|
146 | {
|
---|
147 | inputStruct.key = (uint32_t)((i == 0) ? 'OSK0' : 'OSK1');
|
---|
148 | kr = IOConnectCallStructMethod((mach_port_t)port,
|
---|
149 | (uint32_t)2,
|
---|
150 | (const void *)&inputStruct,
|
---|
151 | sizeof(inputStruct),
|
---|
152 | (void *)&outputStruct,
|
---|
153 | &cbOutputStruct);
|
---|
154 | if (kr != kIOReturnSuccess)
|
---|
155 | {
|
---|
156 | IOServiceClose(port);
|
---|
157 | return RTErrConvertFromDarwin(kr);
|
---|
158 | }
|
---|
159 |
|
---|
160 | for (int j = 0; j < 32; j++)
|
---|
161 | pabKey[j + i*32] = outputStruct.data[j];
|
---|
162 | }
|
---|
163 |
|
---|
164 | IOServiceClose(port);
|
---|
165 |
|
---|
166 | pabKey[64] = 0;
|
---|
167 |
|
---|
168 | return VINF_SUCCESS;
|
---|
169 | }
|
---|
170 |
|
---|
171 | #endif /* RT_OS_DARWIN */
|
---|
172 |
|
---|
173 | /* Darwin compile cludge */
|
---|
174 | #undef PVM
|
---|
175 |
|
---|
176 | /* Comment out the following line to remove VMWare compatibility hack. */
|
---|
177 | #define VMWARE_NET_IN_SLOT_11
|
---|
178 |
|
---|
179 | /**
|
---|
180 | * Translate IDE StorageControllerType_T to string representation.
|
---|
181 | */
|
---|
182 | const char* controllerString(StorageControllerType_T enmType)
|
---|
183 | {
|
---|
184 | switch (enmType)
|
---|
185 | {
|
---|
186 | case StorageControllerType_PIIX3:
|
---|
187 | return "PIIX3";
|
---|
188 | case StorageControllerType_PIIX4:
|
---|
189 | return "PIIX4";
|
---|
190 | case StorageControllerType_ICH6:
|
---|
191 | return "ICH6";
|
---|
192 | default:
|
---|
193 | return "Unknown";
|
---|
194 | }
|
---|
195 | }
|
---|
196 |
|
---|
197 | /**
|
---|
198 | * Simple class for storing network boot information.
|
---|
199 | */
|
---|
200 | struct BootNic
|
---|
201 | {
|
---|
202 | ULONG mInstance;
|
---|
203 | unsigned mPciDev;
|
---|
204 | unsigned mPciFn;
|
---|
205 | ULONG mBootPrio;
|
---|
206 | bool operator < (const BootNic &rhs) const
|
---|
207 | {
|
---|
208 | ULONG lval = mBootPrio - 1; /* 0 will wrap around and get the lowest priority. */
|
---|
209 | ULONG rval = rhs.mBootPrio - 1;
|
---|
210 | return lval < rval; /* Zero compares as highest number (lowest prio). */
|
---|
211 | }
|
---|
212 | };
|
---|
213 |
|
---|
214 | /*
|
---|
215 | * VC++ 8 / amd64 has some serious trouble with this function.
|
---|
216 | * As a temporary measure, we'll drop global optimizations.
|
---|
217 | */
|
---|
218 | #if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
|
---|
219 | # pragma optimize("g", off)
|
---|
220 | #endif
|
---|
221 |
|
---|
222 | static int findEfiRom(IVirtualBox* vbox, FirmwareType_T aFirmwareType, Utf8Str& aEfiRomFile)
|
---|
223 | {
|
---|
224 | int rc;
|
---|
225 | BOOL fPresent = FALSE;
|
---|
226 | Bstr aFilePath, empty;
|
---|
227 |
|
---|
228 | rc = vbox->CheckFirmwarePresent(aFirmwareType, empty,
|
---|
229 | empty.asOutParam(), aFilePath.asOutParam(), &fPresent);
|
---|
230 | if (RT_FAILURE(rc))
|
---|
231 | AssertComRCReturn(rc, VERR_FILE_NOT_FOUND);
|
---|
232 |
|
---|
233 | if (!fPresent)
|
---|
234 | return VERR_FILE_NOT_FOUND;
|
---|
235 |
|
---|
236 | aEfiRomFile = Utf8Str(aFilePath);
|
---|
237 |
|
---|
238 | return S_OK;
|
---|
239 | }
|
---|
240 |
|
---|
241 | static int getSmcDeviceKey(IMachine *pMachine, BSTR *aKey, bool *pfGetKeyFromRealSMC)
|
---|
242 | {
|
---|
243 | *pfGetKeyFromRealSMC = false;
|
---|
244 |
|
---|
245 | /*
|
---|
246 | * The extra data takes precedence (if non-zero).
|
---|
247 | */
|
---|
248 | HRESULT hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/SmcDeviceKey"), aKey);
|
---|
249 | if (FAILED(hrc))
|
---|
250 | return Global::vboxStatusCodeFromCOM(hrc);
|
---|
251 | if ( SUCCEEDED(hrc)
|
---|
252 | && *aKey
|
---|
253 | && **aKey)
|
---|
254 | return VINF_SUCCESS;
|
---|
255 |
|
---|
256 | #ifdef RT_OS_DARWIN
|
---|
257 | /*
|
---|
258 | * Query it here and now.
|
---|
259 | */
|
---|
260 | char abKeyBuf[65];
|
---|
261 | int rc = DarwinSmcKey(abKeyBuf, sizeof(abKeyBuf));
|
---|
262 | if (SUCCEEDED(rc))
|
---|
263 | {
|
---|
264 | Bstr(abKeyBuf).detachTo(aKey);
|
---|
265 | return rc;
|
---|
266 | }
|
---|
267 | LogRel(("Warning: DarwinSmcKey failed with rc=%Rrc!\n", rc));
|
---|
268 |
|
---|
269 | #else
|
---|
270 | /*
|
---|
271 | * Is it apple hardware in bootcamp?
|
---|
272 | */
|
---|
273 | /** @todo implement + test RTSYSDMISTR_MANUFACTURER on all hosts.
|
---|
274 | * Currently falling back on the product name. */
|
---|
275 | char szManufacturer[256];
|
---|
276 | szManufacturer[0] = '\0';
|
---|
277 | RTSystemQueryDmiString(RTSYSDMISTR_MANUFACTURER, szManufacturer, sizeof(szManufacturer));
|
---|
278 | if (szManufacturer[0] != '\0')
|
---|
279 | {
|
---|
280 | if ( !strcmp(szManufacturer, "Apple Computer, Inc.")
|
---|
281 | || !strcmp(szManufacturer, "Apple Inc.")
|
---|
282 | )
|
---|
283 | *pfGetKeyFromRealSMC = true;
|
---|
284 | }
|
---|
285 | else
|
---|
286 | {
|
---|
287 | char szProdName[256];
|
---|
288 | szProdName[0] = '\0';
|
---|
289 | RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szProdName, sizeof(szProdName));
|
---|
290 | if ( ( !strncmp(szProdName, "Mac", 3)
|
---|
291 | || !strncmp(szProdName, "iMac", 4)
|
---|
292 | || !strncmp(szProdName, "iMac", 4)
|
---|
293 | || !strncmp(szProdName, "Xserve", 6)
|
---|
294 | )
|
---|
295 | && !strchr(szProdName, ' ') /* no spaces */
|
---|
296 | && RT_C_IS_DIGIT(szProdName[strlen(szProdName) - 1]) /* version number */
|
---|
297 | )
|
---|
298 | *pfGetKeyFromRealSMC = true;
|
---|
299 | }
|
---|
300 |
|
---|
301 | int rc = VINF_SUCCESS;
|
---|
302 | #endif
|
---|
303 |
|
---|
304 | return rc;
|
---|
305 | }
|
---|
306 |
|
---|
307 | /**
|
---|
308 | * Construct the VM configuration tree (CFGM).
|
---|
309 | *
|
---|
310 | * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
|
---|
311 | * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
|
---|
312 | * is done here.
|
---|
313 | *
|
---|
314 | * @param pVM VM handle.
|
---|
315 | * @param pvConsole Pointer to the VMPowerUpTask object.
|
---|
316 | * @return VBox status code.
|
---|
317 | *
|
---|
318 | * @note Locks the Console object for writing.
|
---|
319 | */
|
---|
320 | DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
|
---|
321 | {
|
---|
322 | LogFlowFuncEnter();
|
---|
323 | /* Note: hardcoded assumption about number of slots; see rom bios */
|
---|
324 | bool afPciDeviceNo[32] = {false};
|
---|
325 | bool fFdcEnabled = false;
|
---|
326 | BOOL fIs64BitGuest = false;
|
---|
327 |
|
---|
328 | #if !defined(VBOX_WITH_XPCOM)
|
---|
329 | {
|
---|
330 | /* initialize COM */
|
---|
331 | HRESULT hrc = CoInitializeEx(NULL,
|
---|
332 | COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
|
---|
333 | COINIT_SPEED_OVER_MEMORY);
|
---|
334 | LogFlow(("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
|
---|
335 | AssertComRCReturn(hrc, VERR_GENERAL_FAILURE);
|
---|
336 | }
|
---|
337 | #endif
|
---|
338 |
|
---|
339 | AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
|
---|
340 | ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
|
---|
341 |
|
---|
342 | AutoCaller autoCaller(pConsole);
|
---|
343 | AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
|
---|
344 |
|
---|
345 | /* lock the console because we widely use internal fields and methods */
|
---|
346 | AutoWriteLock alock(pConsole COMMA_LOCKVAL_SRC_POS);
|
---|
347 |
|
---|
348 | /* Save the VM pointer in the machine object */
|
---|
349 | pConsole->mpVM = pVM;
|
---|
350 |
|
---|
351 | ComPtr<IMachine> pMachine = pConsole->machine();
|
---|
352 |
|
---|
353 | int rc;
|
---|
354 | HRESULT hrc;
|
---|
355 | Bstr bstr;
|
---|
356 |
|
---|
357 | #define RC_CHECK() AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc)
|
---|
358 | #define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
|
---|
359 |
|
---|
360 | /*
|
---|
361 | * Get necessary objects and frequently used parameters.
|
---|
362 | */
|
---|
363 | ComPtr<IVirtualBox> virtualBox;
|
---|
364 | hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
|
---|
365 |
|
---|
366 | ComPtr<IHost> host;
|
---|
367 | hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
|
---|
368 |
|
---|
369 | ComPtr<ISystemProperties> systemProperties;
|
---|
370 | hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
|
---|
371 |
|
---|
372 | ComPtr<IBIOSSettings> biosSettings;
|
---|
373 | hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
|
---|
374 |
|
---|
375 | hrc = pMachine->COMGETTER(HardwareUUID)(bstr.asOutParam()); H();
|
---|
376 | RTUUID HardwareUuid;
|
---|
377 | rc = RTUuidFromUtf16(&HardwareUuid, bstr.raw()); RC_CHECK();
|
---|
378 |
|
---|
379 | ULONG cRamMBs;
|
---|
380 | hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
|
---|
381 | #if 0 /* enable to play with lots of memory. */
|
---|
382 | if (RTEnvExist("VBOX_RAM_SIZE"))
|
---|
383 | cRamMBs = RTStrToUInt64(RTEnvGet("VBOX_RAM_SIZE"));
|
---|
384 | #endif
|
---|
385 | uint64_t const cbRam = cRamMBs * (uint64_t)_1M;
|
---|
386 | uint32_t const cbRamHole = MM_RAM_HOLE_SIZE_DEFAULT;
|
---|
387 |
|
---|
388 | ULONG cCpus = 1;
|
---|
389 | hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
|
---|
390 |
|
---|
391 | Bstr osTypeId;
|
---|
392 | hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
|
---|
393 |
|
---|
394 | BOOL fIOAPIC;
|
---|
395 | hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
|
---|
396 |
|
---|
397 | ComPtr<IGuestOSType> guestOSType;
|
---|
398 | hrc = virtualBox->GetGuestOSType(osTypeId, guestOSType.asOutParam()); H();
|
---|
399 |
|
---|
400 | Bstr guestTypeFamilyId;
|
---|
401 | hrc = guestOSType->COMGETTER(FamilyId)(guestTypeFamilyId.asOutParam()); H();
|
---|
402 | BOOL fOsXGuest = guestTypeFamilyId == Bstr("MacOS");
|
---|
403 |
|
---|
404 | /*
|
---|
405 | * Get root node first.
|
---|
406 | * This is the only node in the tree.
|
---|
407 | */
|
---|
408 | PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
|
---|
409 | Assert(pRoot);
|
---|
410 |
|
---|
411 | /*
|
---|
412 | * Set the root (and VMM) level values.
|
---|
413 | */
|
---|
414 | hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
|
---|
415 | rc = CFGMR3InsertStringW(pRoot, "Name", bstr.raw()); RC_CHECK();
|
---|
416 | rc = CFGMR3InsertBytes(pRoot, "UUID", &HardwareUuid, sizeof(HardwareUuid)); RC_CHECK();
|
---|
417 | rc = CFGMR3InsertInteger(pRoot, "RamSize", cbRam); RC_CHECK();
|
---|
418 | rc = CFGMR3InsertInteger(pRoot, "RamHoleSize", cbRamHole); RC_CHECK();
|
---|
419 | rc = CFGMR3InsertInteger(pRoot, "NumCPUs", cCpus); RC_CHECK();
|
---|
420 | rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10); RC_CHECK();
|
---|
421 | #ifdef VBOX_WITH_RAW_MODE
|
---|
422 | rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1); /* boolean */ RC_CHECK();
|
---|
423 | rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1); /* boolean */ RC_CHECK();
|
---|
424 | /** @todo Config: RawR0, PATMEnabled and CSAMEnabled needs attention later. */
|
---|
425 | rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1); /* boolean */ RC_CHECK();
|
---|
426 | rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1); /* boolean */ RC_CHECK();
|
---|
427 | #endif
|
---|
428 |
|
---|
429 | /* cpuid leaf overrides. */
|
---|
430 | static uint32_t const s_auCpuIdRanges[] =
|
---|
431 | {
|
---|
432 | UINT32_C(0x00000000), UINT32_C(0x0000000a),
|
---|
433 | UINT32_C(0x80000000), UINT32_C(0x8000000a)
|
---|
434 | };
|
---|
435 | for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
|
---|
436 | for (uint32_t uLeaf = s_auCpuIdRanges[i]; uLeaf < s_auCpuIdRanges[i + 1]; uLeaf++)
|
---|
437 | {
|
---|
438 | ULONG ulEax, ulEbx, ulEcx, ulEdx;
|
---|
439 | hrc = pMachine->GetCPUIDLeaf(uLeaf, &ulEax, &ulEbx, &ulEcx, &ulEdx);
|
---|
440 | if (SUCCEEDED(hrc))
|
---|
441 | {
|
---|
442 | PCFGMNODE pLeaf;
|
---|
443 | rc = CFGMR3InsertNodeF(pRoot, &pLeaf, "CPUM/HostCPUID/%RX32", uLeaf); RC_CHECK();
|
---|
444 |
|
---|
445 | rc = CFGMR3InsertInteger(pLeaf, "eax", ulEax); RC_CHECK();
|
---|
446 | rc = CFGMR3InsertInteger(pLeaf, "ebx", ulEbx); RC_CHECK();
|
---|
447 | rc = CFGMR3InsertInteger(pLeaf, "ecx", ulEcx); RC_CHECK();
|
---|
448 | rc = CFGMR3InsertInteger(pLeaf, "edx", ulEdx); RC_CHECK();
|
---|
449 | }
|
---|
450 | else if (hrc != E_INVALIDARG) H();
|
---|
451 | }
|
---|
452 |
|
---|
453 | if (osTypeId == "WindowsNT4")
|
---|
454 | {
|
---|
455 | /*
|
---|
456 | * We must limit CPUID count for Windows NT 4, as otherwise it stops
|
---|
457 | * with error 0x3e (MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED).
|
---|
458 | */
|
---|
459 | LogRel(("Limiting CPUID leaf count for NT4 guests\n"));
|
---|
460 | PCFGMNODE pCPUM;
|
---|
461 | rc = CFGMR3InsertNode(pRoot, "CPUM", &pCPUM); RC_CHECK();
|
---|
462 | rc = CFGMR3InsertInteger(pCPUM, "NT4LeafLimit", true); RC_CHECK();
|
---|
463 | }
|
---|
464 |
|
---|
465 | if (fOsXGuest)
|
---|
466 | {
|
---|
467 | /*
|
---|
468 | * Expose extended MWAIT features to Mac OS X guests.
|
---|
469 | */
|
---|
470 | LogRel(("Using MWAIT extensions\n"));
|
---|
471 | PCFGMNODE pCPUM;
|
---|
472 | rc = CFGMR3InsertNode(pRoot, "CPUM", &pCPUM); RC_CHECK();
|
---|
473 | rc = CFGMR3InsertInteger(pCPUM, "MWaitExtensions", true); RC_CHECK();
|
---|
474 | }
|
---|
475 |
|
---|
476 | /* hardware virtualization extensions */
|
---|
477 | BOOL fHWVirtExEnabled;
|
---|
478 | BOOL fHwVirtExtForced;
|
---|
479 | #ifdef VBOX_WITH_RAW_MODE
|
---|
480 | hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Enabled, &fHWVirtExEnabled); H();
|
---|
481 | if (cCpus > 1) /** @todo SMP: This isn't nice, but things won't work on mac otherwise. */
|
---|
482 | fHWVirtExEnabled = TRUE;
|
---|
483 | # ifdef RT_OS_DARWIN
|
---|
484 | fHwVirtExtForced = fHWVirtExEnabled;
|
---|
485 | # else
|
---|
486 | /* - With more than 4GB PGM will use different RAMRANGE sizes for raw
|
---|
487 | mode and hv mode to optimize lookup times.
|
---|
488 | - With more than one virtual CPU, raw-mode isn't a fallback option. */
|
---|
489 | fHwVirtExtForced = fHWVirtExEnabled
|
---|
490 | && ( cbRam > (_4G - cbRamHole)
|
---|
491 | || cCpus > 1);
|
---|
492 | # endif
|
---|
493 | #else /* !VBOX_WITH_RAW_MODE */
|
---|
494 | fHWVirtExEnabled = fHwVirtExtForced = TRUE;
|
---|
495 | #endif /* !VBOX_WITH_RAW_MODE */
|
---|
496 | rc = CFGMR3InsertInteger(pRoot, "HwVirtExtForced", fHwVirtExtForced); RC_CHECK();
|
---|
497 |
|
---|
498 | PCFGMNODE pHWVirtExt;
|
---|
499 | rc = CFGMR3InsertNode(pRoot, "HWVirtExt", &pHWVirtExt); RC_CHECK();
|
---|
500 | if (fHWVirtExEnabled)
|
---|
501 | {
|
---|
502 | rc = CFGMR3InsertInteger(pHWVirtExt, "Enabled", 1); RC_CHECK();
|
---|
503 |
|
---|
504 | /* Indicate whether 64-bit guests are supported or not. */
|
---|
505 | /** @todo This is currently only forced off on 32-bit hosts only because it
|
---|
506 | * makes a lof of difference there (REM and Solaris performance).
|
---|
507 | */
|
---|
508 | BOOL fSupportsLongMode = false;
|
---|
509 | hrc = host->GetProcessorFeature(ProcessorFeature_LongMode,
|
---|
510 | &fSupportsLongMode); H();
|
---|
511 | hrc = guestOSType->COMGETTER(Is64Bit)(&fIs64BitGuest); H();
|
---|
512 |
|
---|
513 | if (fSupportsLongMode && fIs64BitGuest)
|
---|
514 | {
|
---|
515 | rc = CFGMR3InsertInteger(pHWVirtExt, "64bitEnabled", 1); RC_CHECK();
|
---|
516 | #if ARCH_BITS == 32 /* The recompiler must use VBoxREM64 (32-bit host only). */
|
---|
517 | PCFGMNODE pREM;
|
---|
518 | rc = CFGMR3InsertNode(pRoot, "REM", &pREM); RC_CHECK();
|
---|
519 | rc = CFGMR3InsertInteger(pREM, "64bitEnabled", 1); RC_CHECK();
|
---|
520 | #endif
|
---|
521 | }
|
---|
522 | #if ARCH_BITS == 32 /* 32-bit guests only. */
|
---|
523 | else
|
---|
524 | {
|
---|
525 | rc = CFGMR3InsertInteger(pHWVirtExt, "64bitEnabled", 0); RC_CHECK();
|
---|
526 | }
|
---|
527 | #endif
|
---|
528 |
|
---|
529 | /** @todo Not exactly pretty to check strings; VBOXOSTYPE would be better, but that requires quite a bit of API change in Main. */
|
---|
530 | if ( !fIs64BitGuest
|
---|
531 | && fIOAPIC
|
---|
532 | && ( osTypeId == "WindowsNT4"
|
---|
533 | || osTypeId == "Windows2000"
|
---|
534 | || osTypeId == "WindowsXP"
|
---|
535 | || osTypeId == "Windows2003"))
|
---|
536 | {
|
---|
537 | /* Only allow TPR patching for NT, Win2k, XP and Windows Server 2003. (32 bits mode)
|
---|
538 | * We may want to consider adding more guest OSes (Solaris) later on.
|
---|
539 | */
|
---|
540 | rc = CFGMR3InsertInteger(pHWVirtExt, "TPRPatchingEnabled", 1); RC_CHECK();
|
---|
541 | }
|
---|
542 | }
|
---|
543 |
|
---|
544 | /* HWVirtEx exclusive mode */
|
---|
545 | BOOL fHWVirtExExclusive = true;
|
---|
546 | hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Exclusive, &fHWVirtExExclusive); H();
|
---|
547 | rc = CFGMR3InsertInteger(pHWVirtExt, "Exclusive", fHWVirtExExclusive); RC_CHECK();
|
---|
548 |
|
---|
549 | /* Nested paging (VT-x/AMD-V) */
|
---|
550 | BOOL fEnableNestedPaging = false;
|
---|
551 | hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &fEnableNestedPaging); H();
|
---|
552 | rc = CFGMR3InsertInteger(pHWVirtExt, "EnableNestedPaging", fEnableNestedPaging); RC_CHECK();
|
---|
553 |
|
---|
554 | /* Large pages; requires nested paging */
|
---|
555 | BOOL fEnableLargePages = false;
|
---|
556 | hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_LargePages, &fEnableLargePages); H();
|
---|
557 | rc = CFGMR3InsertInteger(pHWVirtExt, "EnableLargePages", fEnableLargePages); RC_CHECK();
|
---|
558 |
|
---|
559 | /* VPID (VT-x) */
|
---|
560 | BOOL fEnableVPID = false;
|
---|
561 | hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &fEnableVPID); H();
|
---|
562 | rc = CFGMR3InsertInteger(pHWVirtExt, "EnableVPID", fEnableVPID); RC_CHECK();
|
---|
563 |
|
---|
564 | /* Physical Address Extension (PAE) */
|
---|
565 | BOOL fEnablePAE = false;
|
---|
566 | hrc = pMachine->GetCPUProperty(CPUPropertyType_PAE, &fEnablePAE); H();
|
---|
567 | rc = CFGMR3InsertInteger(pRoot, "EnablePAE", fEnablePAE); RC_CHECK();
|
---|
568 |
|
---|
569 | /* Synthetic CPU */
|
---|
570 | BOOL fSyntheticCpu = false;
|
---|
571 | hrc = pMachine->GetCPUProperty(CPUPropertyType_Synthetic, &fSyntheticCpu); H();
|
---|
572 | rc = CFGMR3InsertInteger(pRoot, "SyntheticCpu", fSyntheticCpu); RC_CHECK();
|
---|
573 |
|
---|
574 | BOOL fPXEDebug;
|
---|
575 | hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
|
---|
576 |
|
---|
577 | /*
|
---|
578 | * PDM config.
|
---|
579 | * Load drivers in VBoxC.[so|dll]
|
---|
580 | */
|
---|
581 | PCFGMNODE pPDM;
|
---|
582 | PCFGMNODE pDrivers;
|
---|
583 | PCFGMNODE pMod;
|
---|
584 | rc = CFGMR3InsertNode(pRoot, "PDM", &pPDM); RC_CHECK();
|
---|
585 | rc = CFGMR3InsertNode(pPDM, "Drivers", &pDrivers); RC_CHECK();
|
---|
586 | rc = CFGMR3InsertNode(pDrivers, "VBoxC", &pMod); RC_CHECK();
|
---|
587 | #ifdef VBOX_WITH_XPCOM
|
---|
588 | // VBoxC is located in the components subdirectory
|
---|
589 | char szPathVBoxC[RTPATH_MAX];
|
---|
590 | rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
|
---|
591 | strcat(szPathVBoxC, "/components/VBoxC");
|
---|
592 | rc = CFGMR3InsertString(pMod, "Path", szPathVBoxC); RC_CHECK();
|
---|
593 | #else
|
---|
594 | rc = CFGMR3InsertString(pMod, "Path", "VBoxC"); RC_CHECK();
|
---|
595 | #endif
|
---|
596 |
|
---|
597 | /*
|
---|
598 | * I/O settings (cach, max bandwidth, ...).
|
---|
599 | */
|
---|
600 | PCFGMNODE pPDMAc;
|
---|
601 | PCFGMNODE pPDMAcFile;
|
---|
602 | rc = CFGMR3InsertNode(pPDM, "AsyncCompletion", &pPDMAc); RC_CHECK();
|
---|
603 | rc = CFGMR3InsertNode(pPDMAc, "File", &pPDMAcFile); RC_CHECK();
|
---|
604 |
|
---|
605 | /* Builtin I/O cache */
|
---|
606 | BOOL fIoCache = true;
|
---|
607 | hrc = pMachine->COMGETTER(IoCacheEnabled)(&fIoCache); H();
|
---|
608 | rc = CFGMR3InsertInteger(pPDMAcFile, "CacheEnabled", fIoCache); RC_CHECK();
|
---|
609 |
|
---|
610 | /* I/O cache size */
|
---|
611 | ULONG ioCacheSize = 5;
|
---|
612 | hrc = pMachine->COMGETTER(IoCacheSize)(&ioCacheSize); H();
|
---|
613 | rc = CFGMR3InsertInteger(pPDMAcFile, "CacheSize", ioCacheSize * _1M); RC_CHECK();
|
---|
614 |
|
---|
615 | /* Maximum I/O bandwidth */
|
---|
616 | ULONG ioBandwidthMax = 0;
|
---|
617 | hrc = pMachine->COMGETTER(IoBandwidthMax)(&ioBandwidthMax); H();
|
---|
618 | if (ioBandwidthMax != 0)
|
---|
619 | {
|
---|
620 | rc = CFGMR3InsertInteger(pPDMAcFile, "VMTransferPerSecMax", ioBandwidthMax * _1M); RC_CHECK();
|
---|
621 | }
|
---|
622 |
|
---|
623 | /*
|
---|
624 | * Devices
|
---|
625 | */
|
---|
626 | PCFGMNODE pDevices = NULL; /* /Devices */
|
---|
627 | PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
|
---|
628 | PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
|
---|
629 | PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
|
---|
630 | PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
|
---|
631 | PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
|
---|
632 | PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
|
---|
633 | PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
|
---|
634 | PCFGMNODE pNetBootCfg = NULL; /* /Devices/pcbios/0/Config/NetBoot/ */
|
---|
635 |
|
---|
636 | rc = CFGMR3InsertNode(pRoot, "Devices", &pDevices); RC_CHECK();
|
---|
637 |
|
---|
638 | /*
|
---|
639 | * PC Arch.
|
---|
640 | */
|
---|
641 | rc = CFGMR3InsertNode(pDevices, "pcarch", &pDev); RC_CHECK();
|
---|
642 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
643 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
644 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
645 |
|
---|
646 | /*
|
---|
647 | * The time offset
|
---|
648 | */
|
---|
649 | LONG64 timeOffset;
|
---|
650 | hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
|
---|
651 | PCFGMNODE pTMNode;
|
---|
652 | rc = CFGMR3InsertNode(pRoot, "TM", &pTMNode); RC_CHECK();
|
---|
653 | rc = CFGMR3InsertInteger(pTMNode, "UTCOffset", timeOffset * 1000000); RC_CHECK();
|
---|
654 |
|
---|
655 | /*
|
---|
656 | * DMA
|
---|
657 | */
|
---|
658 | rc = CFGMR3InsertNode(pDevices, "8237A", &pDev); RC_CHECK();
|
---|
659 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
660 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
661 |
|
---|
662 | /*
|
---|
663 | * PCI buses.
|
---|
664 | */
|
---|
665 | rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */ RC_CHECK();
|
---|
666 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
667 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
668 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
669 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
|
---|
670 |
|
---|
671 | #if 0 /* enable this to test PCI bridging */
|
---|
672 | rc = CFGMR3InsertNode(pDevices, "pcibridge", &pDev); RC_CHECK();
|
---|
673 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
674 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
675 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
676 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 14); RC_CHECK();
|
---|
677 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
678 | rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 0);/* -> pci[0] */ RC_CHECK();
|
---|
679 |
|
---|
680 | rc = CFGMR3InsertNode(pDev, "1", &pInst); RC_CHECK();
|
---|
681 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
682 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
683 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 1); RC_CHECK();
|
---|
684 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
685 | rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
|
---|
686 |
|
---|
687 | rc = CFGMR3InsertNode(pDev, "2", &pInst); RC_CHECK();
|
---|
688 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
689 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
690 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 3); RC_CHECK();
|
---|
691 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
692 | rc = CFGMR3InsertInteger(pInst, "PCIBusNo", 1);/* ->pcibridge[0] */ RC_CHECK();
|
---|
693 | #endif
|
---|
694 |
|
---|
695 | /*
|
---|
696 | * Enable 3 following devices: HPET, SMC, LPC on MacOS X guests
|
---|
697 | */
|
---|
698 | /*
|
---|
699 | * High Precision Event Timer (HPET)
|
---|
700 | */
|
---|
701 | BOOL fHpetEnabled;
|
---|
702 | #ifdef VBOX_WITH_HPET
|
---|
703 | /* Other guests may wish to use HPET too, but MacOS X not functional without it */
|
---|
704 | hrc = pMachine->COMGETTER(HpetEnabled)(&fHpetEnabled); H();
|
---|
705 | /* so always enable HPET in extended profile */
|
---|
706 | fHpetEnabled |= fOsXGuest;
|
---|
707 | #else
|
---|
708 | fHpetEnabled = false;
|
---|
709 | #endif
|
---|
710 | if (fHpetEnabled)
|
---|
711 | {
|
---|
712 | rc = CFGMR3InsertNode(pDevices, "hpet", &pDev); RC_CHECK();
|
---|
713 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
714 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
715 | }
|
---|
716 |
|
---|
717 | /*
|
---|
718 | * System Management Controller (SMC)
|
---|
719 | */
|
---|
720 | BOOL fSmcEnabled;
|
---|
721 | #ifdef VBOX_WITH_SMC
|
---|
722 | fSmcEnabled = fOsXGuest;
|
---|
723 | #else
|
---|
724 | fSmcEnabled = false;
|
---|
725 | #endif
|
---|
726 | if (fSmcEnabled)
|
---|
727 | {
|
---|
728 | rc = CFGMR3InsertNode(pDevices, "smc", &pDev); RC_CHECK();
|
---|
729 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
730 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
731 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
732 | bool fGetKeyFromRealSMC;
|
---|
733 | Bstr bstrKey;
|
---|
734 | rc = getSmcDeviceKey(pMachine, bstrKey.asOutParam(), &fGetKeyFromRealSMC); RC_CHECK();
|
---|
735 | rc = CFGMR3InsertString(pCfg, "DeviceKey", Utf8Str(bstrKey).raw()); RC_CHECK();
|
---|
736 | rc = CFGMR3InsertInteger(pCfg, "GetKeyFromRealSMC", fGetKeyFromRealSMC); RC_CHECK();
|
---|
737 | }
|
---|
738 |
|
---|
739 | /*
|
---|
740 | * Low Pin Count (LPC) bus
|
---|
741 | */
|
---|
742 | BOOL fLpcEnabled;
|
---|
743 | /** @todo: implement appropriate getter */
|
---|
744 | #ifdef VBOX_WITH_LPC
|
---|
745 | fLpcEnabled = fOsXGuest;
|
---|
746 | #else
|
---|
747 | fLpcEnabled = false;
|
---|
748 | #endif
|
---|
749 | if (fLpcEnabled)
|
---|
750 | {
|
---|
751 | rc = CFGMR3InsertNode(pDevices, "lpc", &pDev); RC_CHECK();
|
---|
752 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
753 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
754 | }
|
---|
755 |
|
---|
756 | /*
|
---|
757 | * PS/2 keyboard & mouse.
|
---|
758 | */
|
---|
759 | rc = CFGMR3InsertNode(pDevices, "pckbd", &pDev); RC_CHECK();
|
---|
760 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
761 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
762 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
763 |
|
---|
764 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
765 | rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); RC_CHECK();
|
---|
766 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
767 | rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); RC_CHECK();
|
---|
768 |
|
---|
769 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
770 | rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard"); RC_CHECK();
|
---|
771 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
772 | Keyboard *pKeyboard = pConsole->mKeyboard;
|
---|
773 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pKeyboard); RC_CHECK();
|
---|
774 |
|
---|
775 | rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL0); RC_CHECK();
|
---|
776 | rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); RC_CHECK();
|
---|
777 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
778 | rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); RC_CHECK();
|
---|
779 |
|
---|
780 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
781 | rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse"); RC_CHECK();
|
---|
782 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
783 | Mouse *pMouse = pConsole->mMouse;
|
---|
784 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse); RC_CHECK();
|
---|
785 |
|
---|
786 | /*
|
---|
787 | * i8254 Programmable Interval Timer And Dummy Speaker
|
---|
788 | */
|
---|
789 | rc = CFGMR3InsertNode(pDevices, "i8254", &pDev); RC_CHECK();
|
---|
790 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
791 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
792 | #ifdef DEBUG
|
---|
793 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
794 | #endif
|
---|
795 |
|
---|
796 | /*
|
---|
797 | * i8259 Programmable Interrupt Controller.
|
---|
798 | */
|
---|
799 | rc = CFGMR3InsertNode(pDevices, "i8259", &pDev); RC_CHECK();
|
---|
800 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
801 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
802 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
803 |
|
---|
804 | /*
|
---|
805 | * Advanced Programmable Interrupt Controller.
|
---|
806 | * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
|
---|
807 | * thus only single insert
|
---|
808 | */
|
---|
809 | rc = CFGMR3InsertNode(pDevices, "apic", &pDev); RC_CHECK();
|
---|
810 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
811 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
812 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
813 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
|
---|
814 | rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
|
---|
815 |
|
---|
816 | if (fIOAPIC)
|
---|
817 | {
|
---|
818 | /*
|
---|
819 | * I/O Advanced Programmable Interrupt Controller.
|
---|
820 | */
|
---|
821 | rc = CFGMR3InsertNode(pDevices, "ioapic", &pDev); RC_CHECK();
|
---|
822 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
823 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
824 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
825 | }
|
---|
826 |
|
---|
827 | /*
|
---|
828 | * RTC MC146818.
|
---|
829 | */
|
---|
830 | rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); RC_CHECK();
|
---|
831 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
832 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
833 | BOOL fRTCUseUTC;
|
---|
834 | hrc = pMachine->COMGETTER(RTCUseUTC)(&fRTCUseUTC); H();
|
---|
835 | rc = CFGMR3InsertInteger(pCfg, "UseUTC", fRTCUseUTC ? 1 : 0); RC_CHECK();
|
---|
836 |
|
---|
837 | /*
|
---|
838 | * VGA.
|
---|
839 | */
|
---|
840 | rc = CFGMR3InsertNode(pDevices, "vga", &pDev); RC_CHECK();
|
---|
841 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
842 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
843 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 2); RC_CHECK();
|
---|
844 | Assert(!afPciDeviceNo[2]);
|
---|
845 | afPciDeviceNo[2] = true;
|
---|
846 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
847 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
848 | ULONG cVRamMBs;
|
---|
849 | hrc = pMachine->COMGETTER(VRAMSize)(&cVRamMBs); H();
|
---|
850 | rc = CFGMR3InsertInteger(pCfg, "VRamSize", cVRamMBs * _1M); RC_CHECK();
|
---|
851 | ULONG cMonitorCount;
|
---|
852 | hrc = pMachine->COMGETTER(MonitorCount)(&cMonitorCount); H();
|
---|
853 | rc = CFGMR3InsertInteger(pCfg, "MonitorCount", cMonitorCount); RC_CHECK();
|
---|
854 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
855 | rc = CFGMR3InsertInteger(pCfg, "R0Enabled", fHWVirtExEnabled); RC_CHECK();
|
---|
856 | #endif
|
---|
857 |
|
---|
858 | /*
|
---|
859 | * BIOS logo
|
---|
860 | */
|
---|
861 | BOOL fFadeIn;
|
---|
862 | hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
|
---|
863 | rc = CFGMR3InsertInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0); RC_CHECK();
|
---|
864 | BOOL fFadeOut;
|
---|
865 | hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
|
---|
866 | rc = CFGMR3InsertInteger(pCfg, "FadeOut", fFadeOut ? 1: 0); RC_CHECK();
|
---|
867 | ULONG logoDisplayTime;
|
---|
868 | hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
|
---|
869 | rc = CFGMR3InsertInteger(pCfg, "LogoTime", logoDisplayTime); RC_CHECK();
|
---|
870 | Bstr logoImagePath;
|
---|
871 | hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
|
---|
872 | rc = CFGMR3InsertString(pCfg, "LogoFile", logoImagePath ? Utf8Str(logoImagePath).c_str() : ""); RC_CHECK();
|
---|
873 |
|
---|
874 | /*
|
---|
875 | * Boot menu
|
---|
876 | */
|
---|
877 | BIOSBootMenuMode_T eBootMenuMode;
|
---|
878 | int iShowBootMenu;
|
---|
879 | biosSettings->COMGETTER(BootMenuMode)(&eBootMenuMode);
|
---|
880 | switch (eBootMenuMode)
|
---|
881 | {
|
---|
882 | case BIOSBootMenuMode_Disabled: iShowBootMenu = 0; break;
|
---|
883 | case BIOSBootMenuMode_MenuOnly: iShowBootMenu = 1; break;
|
---|
884 | default: iShowBootMenu = 2; break;
|
---|
885 | }
|
---|
886 | rc = CFGMR3InsertInteger(pCfg, "ShowBootMenu", iShowBootMenu); RC_CHECK();
|
---|
887 |
|
---|
888 | /* Custom VESA mode list */
|
---|
889 | unsigned cModes = 0;
|
---|
890 | for (unsigned iMode = 1; iMode <= 16; ++iMode)
|
---|
891 | {
|
---|
892 | char szExtraDataKey[sizeof("CustomVideoModeXX")];
|
---|
893 | RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%u", iMode);
|
---|
894 | hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), bstr.asOutParam()); H();
|
---|
895 | if (bstr.isEmpty())
|
---|
896 | break;
|
---|
897 | rc = CFGMR3InsertStringW(pCfg, szExtraDataKey, bstr.raw()); RC_CHECK();
|
---|
898 | ++cModes;
|
---|
899 | }
|
---|
900 | rc = CFGMR3InsertInteger(pCfg, "CustomVideoModes", cModes); RC_CHECK();
|
---|
901 |
|
---|
902 | /* VESA height reduction */
|
---|
903 | ULONG ulHeightReduction;
|
---|
904 | IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
|
---|
905 | if (pFramebuffer)
|
---|
906 | {
|
---|
907 | hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
|
---|
908 | }
|
---|
909 | else
|
---|
910 | {
|
---|
911 | /* If framebuffer is not available, there is no height reduction. */
|
---|
912 | ulHeightReduction = 0;
|
---|
913 | }
|
---|
914 | rc = CFGMR3InsertInteger(pCfg, "HeightReduction", ulHeightReduction); RC_CHECK();
|
---|
915 |
|
---|
916 | /* Attach the display. */
|
---|
917 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
918 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay"); RC_CHECK();
|
---|
919 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
920 | Display *pDisplay = pConsole->mDisplay;
|
---|
921 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pDisplay); RC_CHECK();
|
---|
922 |
|
---|
923 |
|
---|
924 | /*
|
---|
925 | * Firmware.
|
---|
926 | */
|
---|
927 | FirmwareType_T eFwType = FirmwareType_BIOS;
|
---|
928 | hrc = pMachine->COMGETTER(FirmwareType)(&eFwType); H();
|
---|
929 |
|
---|
930 | #ifdef VBOX_WITH_EFI
|
---|
931 | BOOL fEfiEnabled = (eFwType >= FirmwareType_EFI) && (eFwType <= FirmwareType_EFIDUAL);
|
---|
932 | #else
|
---|
933 | BOOL fEfiEnabled = false;
|
---|
934 | #endif
|
---|
935 | if (!fEfiEnabled)
|
---|
936 | {
|
---|
937 | /*
|
---|
938 | * PC Bios.
|
---|
939 | */
|
---|
940 | rc = CFGMR3InsertNode(pDevices, "pcbios", &pDev); RC_CHECK();
|
---|
941 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
942 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
943 | rc = CFGMR3InsertNode(pInst, "Config", &pBiosCfg); RC_CHECK();
|
---|
944 | rc = CFGMR3InsertInteger(pBiosCfg, "RamSize", cbRam); RC_CHECK();
|
---|
945 | rc = CFGMR3InsertInteger(pBiosCfg, "RamHoleSize", cbRamHole); RC_CHECK();
|
---|
946 | rc = CFGMR3InsertInteger(pBiosCfg, "NumCPUs", cCpus); RC_CHECK();
|
---|
947 | rc = CFGMR3InsertString(pBiosCfg, "HardDiskDevice", "piix3ide"); RC_CHECK();
|
---|
948 | rc = CFGMR3InsertString(pBiosCfg, "FloppyDevice", "i82078"); RC_CHECK();
|
---|
949 | rc = CFGMR3InsertInteger(pBiosCfg, "IOAPIC", fIOAPIC); RC_CHECK();
|
---|
950 | rc = CFGMR3InsertInteger(pBiosCfg, "PXEDebug", fPXEDebug); RC_CHECK();
|
---|
951 | rc = CFGMR3InsertBytes(pBiosCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));RC_CHECK();
|
---|
952 | rc = CFGMR3InsertNode(pBiosCfg, "NetBoot", &pNetBootCfg); RC_CHECK();
|
---|
953 |
|
---|
954 | DeviceType_T bootDevice;
|
---|
955 | if (SchemaDefs::MaxBootPosition > 9)
|
---|
956 | {
|
---|
957 | AssertMsgFailed(("Too many boot devices %d\n",
|
---|
958 | SchemaDefs::MaxBootPosition));
|
---|
959 | return VERR_INVALID_PARAMETER;
|
---|
960 | }
|
---|
961 |
|
---|
962 | for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; ++pos)
|
---|
963 | {
|
---|
964 | hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
|
---|
965 |
|
---|
966 | char szParamName[] = "BootDeviceX";
|
---|
967 | szParamName[sizeof(szParamName) - 2] = ((char (pos - 1)) + '0');
|
---|
968 |
|
---|
969 | const char *pszBootDevice;
|
---|
970 | switch (bootDevice)
|
---|
971 | {
|
---|
972 | case DeviceType_Null:
|
---|
973 | pszBootDevice = "NONE";
|
---|
974 | break;
|
---|
975 | case DeviceType_HardDisk:
|
---|
976 | pszBootDevice = "IDE";
|
---|
977 | break;
|
---|
978 | case DeviceType_DVD:
|
---|
979 | pszBootDevice = "DVD";
|
---|
980 | break;
|
---|
981 | case DeviceType_Floppy:
|
---|
982 | pszBootDevice = "FLOPPY";
|
---|
983 | break;
|
---|
984 | case DeviceType_Network:
|
---|
985 | pszBootDevice = "LAN";
|
---|
986 | break;
|
---|
987 | default:
|
---|
988 | AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
|
---|
989 | return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
|
---|
990 | N_("Invalid boot device '%d'"), bootDevice);
|
---|
991 | }
|
---|
992 | rc = CFGMR3InsertString(pBiosCfg, szParamName, pszBootDevice); RC_CHECK();
|
---|
993 | }
|
---|
994 | }
|
---|
995 | else
|
---|
996 | {
|
---|
997 | Utf8Str efiRomFile;
|
---|
998 |
|
---|
999 | /* Autodetect firmware type, basing on guest type */
|
---|
1000 | if (eFwType == FirmwareType_EFI)
|
---|
1001 | {
|
---|
1002 | eFwType =
|
---|
1003 | fIs64BitGuest ?
|
---|
1004 | (FirmwareType_T)FirmwareType_EFI64
|
---|
1005 | :
|
---|
1006 | (FirmwareType_T)FirmwareType_EFI32;
|
---|
1007 | }
|
---|
1008 | bool f64BitEntry = eFwType == FirmwareType_EFI64;
|
---|
1009 |
|
---|
1010 | rc = findEfiRom(virtualBox, eFwType, efiRomFile); RC_CHECK();
|
---|
1011 |
|
---|
1012 | /* Get boot args */
|
---|
1013 | Bstr bootArgs;
|
---|
1014 | hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiBootArgs"), bootArgs.asOutParam()); H();
|
---|
1015 |
|
---|
1016 | /* Get device props */
|
---|
1017 | Bstr deviceProps;
|
---|
1018 | hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiDeviceProps"), deviceProps.asOutParam()); H();
|
---|
1019 | /* Get GOP mode settings */
|
---|
1020 | uint32_t u32GopMode = UINT32_MAX;
|
---|
1021 | hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiGopMode"), bstr.asOutParam()); H();
|
---|
1022 | if (!bstr.isEmpty())
|
---|
1023 | u32GopMode = Utf8Str(bstr).toUInt32();
|
---|
1024 |
|
---|
1025 | /* UGA mode settings */
|
---|
1026 | uint32_t u32UgaHorisontal = 0;
|
---|
1027 | hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaHorizontalResolution"), bstr.asOutParam()); H();
|
---|
1028 | if (!bstr.isEmpty())
|
---|
1029 | u32UgaHorisontal = Utf8Str(bstr).toUInt32();
|
---|
1030 |
|
---|
1031 | uint32_t u32UgaVertical = 0;
|
---|
1032 | hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaVerticalResolution"), bstr.asOutParam()); H();
|
---|
1033 | if (!bstr.isEmpty())
|
---|
1034 | u32UgaVertical = Utf8Str(bstr).toUInt32();
|
---|
1035 |
|
---|
1036 | /*
|
---|
1037 | * EFI subtree.
|
---|
1038 | */
|
---|
1039 | rc = CFGMR3InsertNode(pDevices, "efi", &pDev); RC_CHECK();
|
---|
1040 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1041 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
1042 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1043 | rc = CFGMR3InsertInteger(pCfg, "RamSize", cbRam); RC_CHECK();
|
---|
1044 | rc = CFGMR3InsertInteger(pCfg, "RamHoleSize", cbRamHole); RC_CHECK();
|
---|
1045 | rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
|
---|
1046 | rc = CFGMR3InsertString(pCfg, "EfiRom", efiRomFile.raw()); RC_CHECK();
|
---|
1047 | rc = CFGMR3InsertString(pCfg, "BootArgs", Utf8Str(bootArgs).raw()); RC_CHECK();
|
---|
1048 | rc = CFGMR3InsertString(pCfg, "DeviceProps", Utf8Str(deviceProps).raw());RC_CHECK();
|
---|
1049 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
|
---|
1050 | rc = CFGMR3InsertBytes(pCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid)); RC_CHECK();
|
---|
1051 | rc = CFGMR3InsertInteger(pCfg, "64BitEntry", f64BitEntry); /* boolean */ RC_CHECK();
|
---|
1052 | rc = CFGMR3InsertInteger(pCfg, "GopMode", u32GopMode); RC_CHECK();
|
---|
1053 | rc = CFGMR3InsertInteger(pCfg, "UgaHorizontalResolution", u32UgaHorisontal); RC_CHECK();
|
---|
1054 | rc = CFGMR3InsertInteger(pCfg, "UgaVerticalResolution", u32UgaVertical); RC_CHECK();
|
---|
1055 |
|
---|
1056 | /* For OS X guests we'll force passing host's DMI info to the guest */
|
---|
1057 | if (fOsXGuest)
|
---|
1058 | {
|
---|
1059 | rc = CFGMR3InsertInteger(pCfg, "DmiUseHostInfo", 1); RC_CHECK();
|
---|
1060 | rc = CFGMR3InsertInteger(pCfg, "DmiExposeMemoryTable", 1); RC_CHECK();
|
---|
1061 | }
|
---|
1062 | }
|
---|
1063 |
|
---|
1064 | /*
|
---|
1065 | * Storage controllers.
|
---|
1066 | */
|
---|
1067 | com::SafeIfaceArray<IStorageController> ctrls;
|
---|
1068 | PCFGMNODE aCtrlNodes[StorageControllerType_LsiLogicSas + 1] = {};
|
---|
1069 | hrc = pMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(ctrls)); H();
|
---|
1070 |
|
---|
1071 | for (size_t i = 0; i < ctrls.size(); ++i)
|
---|
1072 | {
|
---|
1073 | DeviceType_T *paLedDevType = NULL;
|
---|
1074 |
|
---|
1075 | StorageControllerType_T enmCtrlType;
|
---|
1076 | rc = ctrls[i]->COMGETTER(ControllerType)(&enmCtrlType); H();
|
---|
1077 | AssertRelease((unsigned)enmCtrlType < RT_ELEMENTS(aCtrlNodes));
|
---|
1078 |
|
---|
1079 | StorageBus_T enmBus;
|
---|
1080 | rc = ctrls[i]->COMGETTER(Bus)(&enmBus); H();
|
---|
1081 |
|
---|
1082 | Bstr controllerName;
|
---|
1083 | rc = ctrls[i]->COMGETTER(Name)(controllerName.asOutParam()); H();
|
---|
1084 |
|
---|
1085 | ULONG ulInstance = 999;
|
---|
1086 | rc = ctrls[i]->COMGETTER(Instance)(&ulInstance); H();
|
---|
1087 |
|
---|
1088 | BOOL fUseHostIOCache;
|
---|
1089 | rc = ctrls[i]->COMGETTER(UseHostIOCache)(&fUseHostIOCache); H();
|
---|
1090 |
|
---|
1091 | /* /Devices/<ctrldev>/ */
|
---|
1092 | const char *pszCtrlDev = pConsole->convertControllerTypeToDev(enmCtrlType);
|
---|
1093 | pDev = aCtrlNodes[enmCtrlType];
|
---|
1094 | if (!pDev)
|
---|
1095 | {
|
---|
1096 | rc = CFGMR3InsertNode(pDevices, pszCtrlDev, &pDev); RC_CHECK();
|
---|
1097 | aCtrlNodes[enmCtrlType] = pDev; /* IDE variants are handled in the switch */
|
---|
1098 | }
|
---|
1099 |
|
---|
1100 | /* /Devices/<ctrldev>/<instance>/ */
|
---|
1101 | PCFGMNODE pCtlInst = NULL;
|
---|
1102 | rc = CFGMR3InsertNodeF(pDev, &pCtlInst, "%u", ulInstance); RC_CHECK();
|
---|
1103 |
|
---|
1104 | /* Device config: /Devices/<ctrldev>/<instance>/<values> & /ditto/Config/<values> */
|
---|
1105 | rc = CFGMR3InsertInteger(pCtlInst, "Trusted", 1); RC_CHECK();
|
---|
1106 | rc = CFGMR3InsertNode(pCtlInst, "Config", &pCfg); RC_CHECK();
|
---|
1107 |
|
---|
1108 | switch (enmCtrlType)
|
---|
1109 | {
|
---|
1110 | case StorageControllerType_LsiLogic:
|
---|
1111 | {
|
---|
1112 | rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 20); RC_CHECK();
|
---|
1113 | Assert(!afPciDeviceNo[20]);
|
---|
1114 | afPciDeviceNo[20] = true;
|
---|
1115 | rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1116 |
|
---|
1117 | /* Attach the status driver */
|
---|
1118 | rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1119 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1120 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1121 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedScsi]); RC_CHECK();
|
---|
1122 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1123 | Assert(cLedScsi >= 16);
|
---|
1124 | rc = CFGMR3InsertInteger(pCfg, "Last", 15); RC_CHECK();
|
---|
1125 | paLedDevType = &pConsole->maStorageDevType[iLedScsi];
|
---|
1126 | break;
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | case StorageControllerType_BusLogic:
|
---|
1130 | {
|
---|
1131 | rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 21); RC_CHECK();
|
---|
1132 | Assert(!afPciDeviceNo[21]);
|
---|
1133 | afPciDeviceNo[21] = true;
|
---|
1134 | rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1135 |
|
---|
1136 | /* Attach the status driver */
|
---|
1137 | rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1138 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1139 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1140 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedScsi]); RC_CHECK();
|
---|
1141 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1142 | Assert(cLedScsi >= 16);
|
---|
1143 | rc = CFGMR3InsertInteger(pCfg, "Last", 15); RC_CHECK();
|
---|
1144 | paLedDevType = &pConsole->maStorageDevType[iLedScsi];
|
---|
1145 | break;
|
---|
1146 | }
|
---|
1147 |
|
---|
1148 | case StorageControllerType_IntelAhci:
|
---|
1149 | {
|
---|
1150 | rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 13); RC_CHECK();
|
---|
1151 | Assert(!afPciDeviceNo[13]);
|
---|
1152 | afPciDeviceNo[13] = true;
|
---|
1153 | rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1154 |
|
---|
1155 | ULONG cPorts = 0;
|
---|
1156 | hrc = ctrls[i]->COMGETTER(PortCount)(&cPorts); H();
|
---|
1157 | rc = CFGMR3InsertInteger(pCfg, "PortCount", cPorts); RC_CHECK();
|
---|
1158 |
|
---|
1159 | /* Needed configuration values for the bios. */
|
---|
1160 | if (pBiosCfg)
|
---|
1161 | {
|
---|
1162 | rc = CFGMR3InsertString(pBiosCfg, "SataHardDiskDevice", "ahci"); RC_CHECK();
|
---|
1163 | }
|
---|
1164 |
|
---|
1165 | for (uint32_t j = 0; j < 4; ++j)
|
---|
1166 | {
|
---|
1167 | static const char * const s_apszConfig[4] =
|
---|
1168 | { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
|
---|
1169 | static const char * const s_apszBiosConfig[4] =
|
---|
1170 | { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
|
---|
1171 |
|
---|
1172 | LONG lPortNumber = -1;
|
---|
1173 | hrc = ctrls[i]->GetIDEEmulationPort(j, &lPortNumber); H();
|
---|
1174 | rc = CFGMR3InsertInteger(pCfg, s_apszConfig[j], lPortNumber); RC_CHECK();
|
---|
1175 | if (pBiosCfg)
|
---|
1176 | {
|
---|
1177 | rc = CFGMR3InsertInteger(pBiosCfg, s_apszBiosConfig[j], lPortNumber); RC_CHECK();
|
---|
1178 | }
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 | /* Attach the status driver */
|
---|
1182 | rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1183 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1184 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1185 | AssertRelease(cPorts <= cLedSata);
|
---|
1186 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedSata]); RC_CHECK();
|
---|
1187 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1188 | rc = CFGMR3InsertInteger(pCfg, "Last", cPorts - 1); RC_CHECK();
|
---|
1189 | paLedDevType = &pConsole->maStorageDevType[iLedSata];
|
---|
1190 | break;
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | case StorageControllerType_PIIX3:
|
---|
1194 | case StorageControllerType_PIIX4:
|
---|
1195 | case StorageControllerType_ICH6:
|
---|
1196 | {
|
---|
1197 | /*
|
---|
1198 | * IDE (update this when the main interface changes)
|
---|
1199 | */
|
---|
1200 | rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 1); RC_CHECK();
|
---|
1201 | Assert(!afPciDeviceNo[1]);
|
---|
1202 | afPciDeviceNo[1] = true;
|
---|
1203 | rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 1); RC_CHECK();
|
---|
1204 | rc = CFGMR3InsertString(pCfg, "Type", controllerString(enmCtrlType)); RC_CHECK();
|
---|
1205 |
|
---|
1206 | /* Attach the status driver */
|
---|
1207 | rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1208 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1209 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1210 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedIde]); RC_CHECK();
|
---|
1211 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1212 | Assert(cLedIde >= 4);
|
---|
1213 | rc = CFGMR3InsertInteger(pCfg, "Last", 3); RC_CHECK();
|
---|
1214 | paLedDevType = &pConsole->maStorageDevType[iLedIde];
|
---|
1215 |
|
---|
1216 | /* IDE flavors */
|
---|
1217 | aCtrlNodes[StorageControllerType_PIIX3] = pDev;
|
---|
1218 | aCtrlNodes[StorageControllerType_PIIX4] = pDev;
|
---|
1219 | aCtrlNodes[StorageControllerType_ICH6] = pDev;
|
---|
1220 | break;
|
---|
1221 | }
|
---|
1222 |
|
---|
1223 | case StorageControllerType_I82078:
|
---|
1224 | {
|
---|
1225 | /*
|
---|
1226 | * i82078 Floppy drive controller
|
---|
1227 | */
|
---|
1228 | fFdcEnabled = true;
|
---|
1229 | rc = CFGMR3InsertInteger(pCfg, "IRQ", 6); RC_CHECK();
|
---|
1230 | rc = CFGMR3InsertInteger(pCfg, "DMA", 2); RC_CHECK();
|
---|
1231 | rc = CFGMR3InsertInteger(pCfg, "MemMapped", 0 ); RC_CHECK();
|
---|
1232 | rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x3f0); RC_CHECK();
|
---|
1233 |
|
---|
1234 | /* Attach the status driver */
|
---|
1235 | rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1236 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1237 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1238 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedFloppy]); RC_CHECK();
|
---|
1239 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1240 | Assert(cLedFloppy >= 1);
|
---|
1241 | rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
|
---|
1242 | paLedDevType = &pConsole->maStorageDevType[iLedFloppy];
|
---|
1243 | break;
|
---|
1244 | }
|
---|
1245 |
|
---|
1246 | case StorageControllerType_LsiLogicSas:
|
---|
1247 | {
|
---|
1248 | rc = CFGMR3InsertInteger(pCtlInst, "PCIDeviceNo", 22); RC_CHECK();
|
---|
1249 | Assert(!afPciDeviceNo[22]);
|
---|
1250 | afPciDeviceNo[22] = true;
|
---|
1251 | rc = CFGMR3InsertInteger(pCtlInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1252 |
|
---|
1253 | rc = CFGMR3InsertString(pCfg, "ControllerType", "SAS1068"); RC_CHECK();
|
---|
1254 |
|
---|
1255 | /* Attach the status driver */
|
---|
1256 | rc = CFGMR3InsertNode(pCtlInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1257 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1258 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1259 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapStorageLeds[iLedSas]); RC_CHECK();
|
---|
1260 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1261 | Assert(cLedSas >= 8);
|
---|
1262 | rc = CFGMR3InsertInteger(pCfg, "Last", 7); RC_CHECK();
|
---|
1263 | paLedDevType = &pConsole->maStorageDevType[iLedSas];
|
---|
1264 | break;
|
---|
1265 | }
|
---|
1266 |
|
---|
1267 | default:
|
---|
1268 | AssertMsgFailedReturn(("invalid storage controller type: %d\n", enmCtrlType), VERR_GENERAL_FAILURE);
|
---|
1269 | }
|
---|
1270 |
|
---|
1271 | /* Attach the media to the storage controllers. */
|
---|
1272 | com::SafeIfaceArray<IMediumAttachment> atts;
|
---|
1273 | hrc = pMachine->GetMediumAttachmentsOfController(controllerName,
|
---|
1274 | ComSafeArrayAsOutParam(atts)); H();
|
---|
1275 |
|
---|
1276 | for (size_t j = 0; j < atts.size(); ++j)
|
---|
1277 | {
|
---|
1278 | rc = pConsole->configMediumAttachment(pCtlInst,
|
---|
1279 | pszCtrlDev,
|
---|
1280 | ulInstance,
|
---|
1281 | enmBus,
|
---|
1282 | fUseHostIOCache,
|
---|
1283 | false /* fSetupMerge */,
|
---|
1284 | 0 /* uMergeSource */,
|
---|
1285 | 0 /* uMergeTarget */,
|
---|
1286 | atts[j],
|
---|
1287 | pConsole->mMachineState,
|
---|
1288 | NULL /* phrc */,
|
---|
1289 | false /* fAttachDetach */,
|
---|
1290 | false /* fForceUnmount */,
|
---|
1291 | NULL /* pVM */,
|
---|
1292 | paLedDevType); RC_CHECK();
|
---|
1293 | }
|
---|
1294 | H();
|
---|
1295 | }
|
---|
1296 | H();
|
---|
1297 |
|
---|
1298 | /*
|
---|
1299 | * Network adapters
|
---|
1300 | */
|
---|
1301 | #ifdef VMWARE_NET_IN_SLOT_11
|
---|
1302 | bool fSwapSlots3and11 = false;
|
---|
1303 | #endif
|
---|
1304 | PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
|
---|
1305 | rc = CFGMR3InsertNode(pDevices, "pcnet", &pDevPCNet); RC_CHECK();
|
---|
1306 | #ifdef VBOX_WITH_E1000
|
---|
1307 | PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
|
---|
1308 | rc = CFGMR3InsertNode(pDevices, "e1000", &pDevE1000); RC_CHECK();
|
---|
1309 | #endif
|
---|
1310 | #ifdef VBOX_WITH_VIRTIO
|
---|
1311 | PCFGMNODE pDevVirtioNet = NULL; /* Virtio network devices */
|
---|
1312 | rc = CFGMR3InsertNode(pDevices, "virtio-net", &pDevVirtioNet); RC_CHECK();
|
---|
1313 | #endif /* VBOX_WITH_VIRTIO */
|
---|
1314 | std::list<BootNic> llBootNics;
|
---|
1315 | for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ++ulInstance)
|
---|
1316 | {
|
---|
1317 | ComPtr<INetworkAdapter> networkAdapter;
|
---|
1318 | hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
|
---|
1319 | BOOL fEnabled = FALSE;
|
---|
1320 | hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
|
---|
1321 | if (!fEnabled)
|
---|
1322 | continue;
|
---|
1323 |
|
---|
1324 | /*
|
---|
1325 | * The virtual hardware type. Create appropriate device first.
|
---|
1326 | */
|
---|
1327 | const char *pszAdapterName = "pcnet";
|
---|
1328 | NetworkAdapterType_T adapterType;
|
---|
1329 | hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
|
---|
1330 | switch (adapterType)
|
---|
1331 | {
|
---|
1332 | case NetworkAdapterType_Am79C970A:
|
---|
1333 | case NetworkAdapterType_Am79C973:
|
---|
1334 | pDev = pDevPCNet;
|
---|
1335 | break;
|
---|
1336 | #ifdef VBOX_WITH_E1000
|
---|
1337 | case NetworkAdapterType_I82540EM:
|
---|
1338 | case NetworkAdapterType_I82543GC:
|
---|
1339 | case NetworkAdapterType_I82545EM:
|
---|
1340 | pDev = pDevE1000;
|
---|
1341 | pszAdapterName = "e1000";
|
---|
1342 | break;
|
---|
1343 | #endif
|
---|
1344 | #ifdef VBOX_WITH_VIRTIO
|
---|
1345 | case NetworkAdapterType_Virtio:
|
---|
1346 | pDev = pDevVirtioNet;
|
---|
1347 | pszAdapterName = "virtio-net";
|
---|
1348 | break;
|
---|
1349 | #endif /* VBOX_WITH_VIRTIO */
|
---|
1350 | default:
|
---|
1351 | AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
|
---|
1352 | adapterType, ulInstance));
|
---|
1353 | return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
|
---|
1354 | N_("Invalid network adapter type '%d' for slot '%d'"),
|
---|
1355 | adapterType, ulInstance);
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | rc = CFGMR3InsertNodeF(pDev, &pInst, "%u", ulInstance); RC_CHECK();
|
---|
1359 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
1360 | /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
|
---|
1361 | * next 4 get 16..19. */
|
---|
1362 | unsigned iPciDeviceNo = 3;
|
---|
1363 | if (ulInstance)
|
---|
1364 | {
|
---|
1365 | if (ulInstance < 4)
|
---|
1366 | iPciDeviceNo = ulInstance - 1 + 8;
|
---|
1367 | else
|
---|
1368 | iPciDeviceNo = ulInstance - 4 + 16;
|
---|
1369 | }
|
---|
1370 | #ifdef VMWARE_NET_IN_SLOT_11
|
---|
1371 | /*
|
---|
1372 | * Dirty hack for PCI slot compatibility with VMWare,
|
---|
1373 | * it assigns slot 11 to the first network controller.
|
---|
1374 | */
|
---|
1375 | if (iPciDeviceNo == 3 && adapterType == NetworkAdapterType_I82545EM)
|
---|
1376 | {
|
---|
1377 | iPciDeviceNo = 0x11;
|
---|
1378 | fSwapSlots3and11 = true;
|
---|
1379 | }
|
---|
1380 | else if (iPciDeviceNo == 0x11 && fSwapSlots3and11)
|
---|
1381 | iPciDeviceNo = 3;
|
---|
1382 | #endif
|
---|
1383 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
|
---|
1384 | Assert(!afPciDeviceNo[iPciDeviceNo]);
|
---|
1385 | afPciDeviceNo[iPciDeviceNo] = true;
|
---|
1386 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1387 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1388 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */
|
---|
1389 | if (pDev == pDevPCNet)
|
---|
1390 | {
|
---|
1391 | rc = CFGMR3InsertInteger(pCfg, "R0Enabled", false); RC_CHECK();
|
---|
1392 | }
|
---|
1393 | #endif
|
---|
1394 | /*
|
---|
1395 | * Collect information needed for network booting and add it to the list.
|
---|
1396 | */
|
---|
1397 | BootNic nic;
|
---|
1398 |
|
---|
1399 | nic.mInstance = ulInstance;
|
---|
1400 | nic.mPciDev = iPciDeviceNo;
|
---|
1401 | nic.mPciFn = 0;
|
---|
1402 |
|
---|
1403 | hrc = networkAdapter->COMGETTER(BootPriority)(&nic.mBootPrio); H();
|
---|
1404 |
|
---|
1405 | llBootNics.push_back(nic);
|
---|
1406 |
|
---|
1407 | /*
|
---|
1408 | * The virtual hardware type. PCNet supports two types.
|
---|
1409 | */
|
---|
1410 | switch (adapterType)
|
---|
1411 | {
|
---|
1412 | case NetworkAdapterType_Am79C970A:
|
---|
1413 | rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
|
---|
1414 | break;
|
---|
1415 | case NetworkAdapterType_Am79C973:
|
---|
1416 | rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
|
---|
1417 | break;
|
---|
1418 | case NetworkAdapterType_I82540EM:
|
---|
1419 | rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
|
---|
1420 | break;
|
---|
1421 | case NetworkAdapterType_I82543GC:
|
---|
1422 | rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
|
---|
1423 | break;
|
---|
1424 | case NetworkAdapterType_I82545EM:
|
---|
1425 | rc = CFGMR3InsertInteger(pCfg, "AdapterType", 2); RC_CHECK();
|
---|
1426 | break;
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | /*
|
---|
1430 | * Get the MAC address and convert it to binary representation
|
---|
1431 | */
|
---|
1432 | Bstr macAddr;
|
---|
1433 | hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
|
---|
1434 | Assert(macAddr);
|
---|
1435 | Utf8Str macAddrUtf8 = macAddr;
|
---|
1436 | char *macStr = (char*)macAddrUtf8.raw();
|
---|
1437 | Assert(strlen(macStr) == 12);
|
---|
1438 | RTMAC Mac;
|
---|
1439 | memset(&Mac, 0, sizeof(Mac));
|
---|
1440 | char *pMac = (char*)&Mac;
|
---|
1441 | for (uint32_t i = 0; i < 6; ++i)
|
---|
1442 | {
|
---|
1443 | char c1 = *macStr++ - '0';
|
---|
1444 | if (c1 > 9)
|
---|
1445 | c1 -= 7;
|
---|
1446 | char c2 = *macStr++ - '0';
|
---|
1447 | if (c2 > 9)
|
---|
1448 | c2 -= 7;
|
---|
1449 | *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
|
---|
1450 | }
|
---|
1451 | rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
|
---|
1452 |
|
---|
1453 | /*
|
---|
1454 | * Check if the cable is supposed to be unplugged
|
---|
1455 | */
|
---|
1456 | BOOL fCableConnected;
|
---|
1457 | hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
|
---|
1458 | rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
|
---|
1459 |
|
---|
1460 | /*
|
---|
1461 | * Line speed to report from custom drivers
|
---|
1462 | */
|
---|
1463 | ULONG ulLineSpeed;
|
---|
1464 | hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
|
---|
1465 | rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
|
---|
1466 |
|
---|
1467 | /*
|
---|
1468 | * Attach the status driver.
|
---|
1469 | */
|
---|
1470 | rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1471 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1472 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1473 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
|
---|
1474 |
|
---|
1475 | /*
|
---|
1476 | * Configure the network card now
|
---|
1477 | */
|
---|
1478 | rc = pConsole->configNetwork(pszAdapterName, ulInstance, 0,
|
---|
1479 | networkAdapter, pCfg, pLunL0, pInst,
|
---|
1480 | false /*fAttachDetach*/); RC_CHECK();
|
---|
1481 | }
|
---|
1482 |
|
---|
1483 | /*
|
---|
1484 | * Build network boot information and transfer it to the BIOS.
|
---|
1485 | */
|
---|
1486 | if (pNetBootCfg && !llBootNics.empty()) /* NetBoot node doesn't exist for EFI! */
|
---|
1487 | {
|
---|
1488 | llBootNics.sort(); /* Sort the list by boot priority. */
|
---|
1489 |
|
---|
1490 | char achBootIdx[] = "0";
|
---|
1491 | unsigned uBootIdx = 0;
|
---|
1492 |
|
---|
1493 | for (std::list<BootNic>::iterator it = llBootNics.begin(); it != llBootNics.end(); ++it)
|
---|
1494 | {
|
---|
1495 | /* A NIC with priority 0 is only used if it's first in the list. */
|
---|
1496 | if (it->mBootPrio == 0 && uBootIdx != 0)
|
---|
1497 | break;
|
---|
1498 |
|
---|
1499 | PCFGMNODE pNetBtDevCfg;
|
---|
1500 | achBootIdx[0] = '0' + uBootIdx++; /* Boot device order. */
|
---|
1501 | rc = CFGMR3InsertNode(pNetBootCfg, achBootIdx, &pNetBtDevCfg); RC_CHECK();
|
---|
1502 | rc = CFGMR3InsertInteger(pNetBtDevCfg, "NIC", it->mInstance); RC_CHECK();
|
---|
1503 | rc = CFGMR3InsertInteger(pNetBtDevCfg, "PCIDeviceNo", it->mPciDev); RC_CHECK();
|
---|
1504 | rc = CFGMR3InsertInteger(pNetBtDevCfg, "PCIFunctionNo", it->mPciFn); RC_CHECK();
|
---|
1505 | }
|
---|
1506 | }
|
---|
1507 |
|
---|
1508 | /*
|
---|
1509 | * Serial (UART) Ports
|
---|
1510 | */
|
---|
1511 | rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
|
---|
1512 | for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ++ulInstance)
|
---|
1513 | {
|
---|
1514 | ComPtr<ISerialPort> serialPort;
|
---|
1515 | hrc = pMachine->GetSerialPort(ulInstance, serialPort.asOutParam()); H();
|
---|
1516 | BOOL fEnabled = FALSE;
|
---|
1517 | if (serialPort)
|
---|
1518 | hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
|
---|
1519 | if (!fEnabled)
|
---|
1520 | continue;
|
---|
1521 |
|
---|
1522 | rc = CFGMR3InsertNodeF(pDev, &pInst, "%u", ulInstance); RC_CHECK();
|
---|
1523 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1524 |
|
---|
1525 | ULONG ulIRQ;
|
---|
1526 | hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
|
---|
1527 | rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
|
---|
1528 | ULONG ulIOBase;
|
---|
1529 | hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
|
---|
1530 | rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
|
---|
1531 | BOOL fServer;
|
---|
1532 | hrc = serialPort->COMGETTER(Server)(&fServer); H();
|
---|
1533 | hrc = serialPort->COMGETTER(Path)(bstr.asOutParam()); H();
|
---|
1534 | PortMode_T eHostMode;
|
---|
1535 | hrc = serialPort->COMGETTER(HostMode)(&eHostMode); H();
|
---|
1536 | if (eHostMode != PortMode_Disconnected)
|
---|
1537 | {
|
---|
1538 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1539 | if (eHostMode == PortMode_HostPipe)
|
---|
1540 | {
|
---|
1541 | rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
|
---|
1542 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
1543 | rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
|
---|
1544 | rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
|
---|
1545 | rc = CFGMR3InsertStringW(pLunL2, "Location", bstr.raw()); RC_CHECK();
|
---|
1546 | rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
|
---|
1547 | }
|
---|
1548 | else if (eHostMode == PortMode_HostDevice)
|
---|
1549 | {
|
---|
1550 | rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
|
---|
1551 | rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
|
---|
1552 | rc = CFGMR3InsertStringW(pLunL1, "DevicePath", bstr.raw()); RC_CHECK();
|
---|
1553 | }
|
---|
1554 | else if (eHostMode == PortMode_RawFile)
|
---|
1555 | {
|
---|
1556 | rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
|
---|
1557 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
1558 | rc = CFGMR3InsertString(pLunL1, "Driver", "RawFile"); RC_CHECK();
|
---|
1559 | rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
|
---|
1560 | rc = CFGMR3InsertStringW(pLunL2, "Location", bstr.raw()); RC_CHECK();
|
---|
1561 | }
|
---|
1562 | }
|
---|
1563 | }
|
---|
1564 |
|
---|
1565 | /*
|
---|
1566 | * Parallel (LPT) Ports
|
---|
1567 | */
|
---|
1568 | rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
|
---|
1569 | for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ++ulInstance)
|
---|
1570 | {
|
---|
1571 | ComPtr<IParallelPort> parallelPort;
|
---|
1572 | hrc = pMachine->GetParallelPort(ulInstance, parallelPort.asOutParam()); H();
|
---|
1573 | BOOL fEnabled = FALSE;
|
---|
1574 | if (parallelPort)
|
---|
1575 | {
|
---|
1576 | hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
|
---|
1577 | }
|
---|
1578 | if (!fEnabled)
|
---|
1579 | continue;
|
---|
1580 |
|
---|
1581 | rc = CFGMR3InsertNodeF(pDev, &pInst, "%u", ulInstance); RC_CHECK();
|
---|
1582 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1583 |
|
---|
1584 | ULONG ulIRQ;
|
---|
1585 | hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
|
---|
1586 | rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
|
---|
1587 | ULONG ulIOBase;
|
---|
1588 | hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
|
---|
1589 | rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
|
---|
1590 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1591 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
|
---|
1592 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
1593 | hrc = parallelPort->COMGETTER(Path)(bstr.asOutParam()); H();
|
---|
1594 | rc = CFGMR3InsertStringW(pLunL1, "DevicePath", bstr.raw()); RC_CHECK();
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 | /*
|
---|
1598 | * VMM Device
|
---|
1599 | */
|
---|
1600 | rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
|
---|
1601 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1602 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1603 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
1604 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
|
---|
1605 | Assert(!afPciDeviceNo[4]);
|
---|
1606 | afPciDeviceNo[4] = true;
|
---|
1607 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1608 | Bstr hwVersion;
|
---|
1609 | hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
|
---|
1610 | if (hwVersion.compare(Bstr("1")) == 0) /* <= 2.0.x */
|
---|
1611 | {
|
---|
1612 | CFGMR3InsertInteger(pCfg, "HeapEnabled", 0); RC_CHECK();
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 | /* the VMM device's Main driver */
|
---|
1616 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1617 | rc = CFGMR3InsertString(pLunL0, "Driver", "HGCM"); RC_CHECK();
|
---|
1618 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1619 | VMMDev *pVMMDev = pConsole->mVMMDev;
|
---|
1620 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
|
---|
1621 |
|
---|
1622 | /*
|
---|
1623 | * Attach the status driver.
|
---|
1624 | */
|
---|
1625 | rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1626 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1627 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1628 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
|
---|
1629 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1630 | rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
|
---|
1631 |
|
---|
1632 | /*
|
---|
1633 | * Audio Sniffer Device
|
---|
1634 | */
|
---|
1635 | rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
|
---|
1636 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1637 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1638 |
|
---|
1639 | /* the Audio Sniffer device's Main driver */
|
---|
1640 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1641 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
|
---|
1642 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1643 | AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
|
---|
1644 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
|
---|
1645 |
|
---|
1646 | /*
|
---|
1647 | * AC'97 ICH / SoundBlaster16 audio
|
---|
1648 | */
|
---|
1649 | BOOL enabled;
|
---|
1650 | ComPtr<IAudioAdapter> audioAdapter;
|
---|
1651 | hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
|
---|
1652 | if (audioAdapter)
|
---|
1653 | hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
|
---|
1654 |
|
---|
1655 | if (enabled)
|
---|
1656 | {
|
---|
1657 | AudioControllerType_T audioController;
|
---|
1658 | hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
|
---|
1659 | switch (audioController)
|
---|
1660 | {
|
---|
1661 | case AudioControllerType_AC97:
|
---|
1662 | {
|
---|
1663 | /* default: ICH AC97 */
|
---|
1664 | rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
|
---|
1665 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
1666 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
|
---|
1667 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
|
---|
1668 | Assert(!afPciDeviceNo[5]);
|
---|
1669 | afPciDeviceNo[5] = true;
|
---|
1670 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1671 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1672 | break;
|
---|
1673 | }
|
---|
1674 | case AudioControllerType_SB16:
|
---|
1675 | {
|
---|
1676 | /* legacy SoundBlaster16 */
|
---|
1677 | rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
|
---|
1678 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1679 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
|
---|
1680 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1681 | rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
|
---|
1682 | rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
|
---|
1683 | rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
|
---|
1684 | rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
|
---|
1685 | rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
|
---|
1686 | break;
|
---|
1687 | }
|
---|
1688 | }
|
---|
1689 |
|
---|
1690 | /* the Audio driver */
|
---|
1691 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1692 | rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
|
---|
1693 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1694 |
|
---|
1695 | AudioDriverType_T audioDriver;
|
---|
1696 | hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
|
---|
1697 | switch (audioDriver)
|
---|
1698 | {
|
---|
1699 | case AudioDriverType_Null:
|
---|
1700 | {
|
---|
1701 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
|
---|
1702 | break;
|
---|
1703 | }
|
---|
1704 | #ifdef RT_OS_WINDOWS
|
---|
1705 | #ifdef VBOX_WITH_WINMM
|
---|
1706 | case AudioDriverType_WinMM:
|
---|
1707 | {
|
---|
1708 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
|
---|
1709 | break;
|
---|
1710 | }
|
---|
1711 | #endif
|
---|
1712 | case AudioDriverType_DirectSound:
|
---|
1713 | {
|
---|
1714 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
|
---|
1715 | break;
|
---|
1716 | }
|
---|
1717 | #endif /* RT_OS_WINDOWS */
|
---|
1718 | #ifdef RT_OS_SOLARIS
|
---|
1719 | case AudioDriverType_SolAudio:
|
---|
1720 | {
|
---|
1721 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
|
---|
1722 | break;
|
---|
1723 | }
|
---|
1724 | #endif
|
---|
1725 | #ifdef RT_OS_LINUX
|
---|
1726 | # ifdef VBOX_WITH_ALSA
|
---|
1727 | case AudioDriverType_ALSA:
|
---|
1728 | {
|
---|
1729 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
|
---|
1730 | break;
|
---|
1731 | }
|
---|
1732 | # endif
|
---|
1733 | # ifdef VBOX_WITH_PULSE
|
---|
1734 | case AudioDriverType_Pulse:
|
---|
1735 | {
|
---|
1736 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
|
---|
1737 | break;
|
---|
1738 | }
|
---|
1739 | # endif
|
---|
1740 | #endif /* RT_OS_LINUX */
|
---|
1741 | #if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
|
---|
1742 | case AudioDriverType_OSS:
|
---|
1743 | {
|
---|
1744 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
|
---|
1745 | break;
|
---|
1746 | }
|
---|
1747 | #endif
|
---|
1748 | #ifdef RT_OS_FREEBSD
|
---|
1749 | # ifdef VBOX_WITH_PULSE
|
---|
1750 | case AudioDriverType_Pulse:
|
---|
1751 | {
|
---|
1752 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
|
---|
1753 | break;
|
---|
1754 | }
|
---|
1755 | # endif
|
---|
1756 | #endif
|
---|
1757 | #ifdef RT_OS_DARWIN
|
---|
1758 | case AudioDriverType_CoreAudio:
|
---|
1759 | {
|
---|
1760 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
|
---|
1761 | break;
|
---|
1762 | }
|
---|
1763 | #endif
|
---|
1764 | }
|
---|
1765 | hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
|
---|
1766 | rc = CFGMR3InsertStringW(pCfg, "StreamName", bstr.raw()); RC_CHECK();
|
---|
1767 | }
|
---|
1768 |
|
---|
1769 | /*
|
---|
1770 | * The USB Controller.
|
---|
1771 | */
|
---|
1772 | ComPtr<IUSBController> USBCtlPtr;
|
---|
1773 | hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
|
---|
1774 | if (USBCtlPtr)
|
---|
1775 | {
|
---|
1776 | BOOL fOhciEnabled;
|
---|
1777 | hrc = USBCtlPtr->COMGETTER(Enabled)(&fOhciEnabled); H();
|
---|
1778 | if (fOhciEnabled)
|
---|
1779 | {
|
---|
1780 | rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
|
---|
1781 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1782 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1783 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
1784 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
|
---|
1785 | Assert(!afPciDeviceNo[6]);
|
---|
1786 | afPciDeviceNo[6] = true;
|
---|
1787 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1788 |
|
---|
1789 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1790 | rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
|
---|
1791 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1792 |
|
---|
1793 | /*
|
---|
1794 | * Attach the status driver.
|
---|
1795 | */
|
---|
1796 | rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1797 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1798 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1799 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
|
---|
1800 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1801 | rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
|
---|
1802 |
|
---|
1803 | #ifdef VBOX_WITH_EHCI
|
---|
1804 | BOOL fEhciEnabled;
|
---|
1805 | hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEhciEnabled); H();
|
---|
1806 | if (fEhciEnabled)
|
---|
1807 | {
|
---|
1808 | rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
|
---|
1809 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1810 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1811 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* bool */ RC_CHECK();
|
---|
1812 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
|
---|
1813 | Assert(!afPciDeviceNo[11]);
|
---|
1814 | afPciDeviceNo[11] = true;
|
---|
1815 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1816 |
|
---|
1817 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1818 | rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
|
---|
1819 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1820 |
|
---|
1821 | /*
|
---|
1822 | * Attach the status driver.
|
---|
1823 | */
|
---|
1824 | rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1825 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1826 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1827 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
|
---|
1828 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1829 | rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
|
---|
1830 | }
|
---|
1831 | #endif
|
---|
1832 |
|
---|
1833 | /*
|
---|
1834 | * Virtual USB Devices.
|
---|
1835 | */
|
---|
1836 | PCFGMNODE pUsbDevices = NULL;
|
---|
1837 | rc = CFGMR3InsertNode(pRoot, "USB", &pUsbDevices); RC_CHECK();
|
---|
1838 |
|
---|
1839 | #ifdef VBOX_WITH_USB
|
---|
1840 | {
|
---|
1841 | /*
|
---|
1842 | * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
|
---|
1843 | * on a per device level now.
|
---|
1844 | */
|
---|
1845 | rc = CFGMR3InsertNode(pUsbDevices, "USBProxy", &pCfg); RC_CHECK();
|
---|
1846 | rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
|
---|
1847 | // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
|
---|
1848 | //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
|
---|
1849 | // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
|
---|
1850 | // that it's documented somewhere.) Users needing it can use:
|
---|
1851 | // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
|
---|
1852 | //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
|
---|
1853 | }
|
---|
1854 | #endif
|
---|
1855 |
|
---|
1856 | # if 0 /* Virtual MSD*/
|
---|
1857 |
|
---|
1858 | rc = CFGMR3InsertNode(pUsbDevices, "Msd", &pDev); RC_CHECK();
|
---|
1859 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1860 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1861 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1862 |
|
---|
1863 | rc = CFGMR3InsertString(pLunL0, "Driver", "SCSI"); RC_CHECK();
|
---|
1864 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1865 |
|
---|
1866 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
1867 | rc = CFGMR3InsertString(pLunL1, "Driver", "Block"); RC_CHECK();
|
---|
1868 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
1869 | rc = CFGMR3InsertString(pCfg, "Type", "HardDisk"); RC_CHECK();
|
---|
1870 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 0); RC_CHECK();
|
---|
1871 |
|
---|
1872 | rc = CFGMR3InsertNode(pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
|
---|
1873 | rc = CFGMR3InsertString(pLunL2, "Driver", "VD"); RC_CHECK();
|
---|
1874 | rc = CFGMR3InsertNode(pLunL2, "Config", &pCfg); RC_CHECK();
|
---|
1875 | rc = CFGMR3InsertString(pCfg, "Path", "/Volumes/DataHFS/bird/VDIs/linux.vdi"); RC_CHECK();
|
---|
1876 | rc = CFGMR3InsertString(pCfg, "Format", "VDI"); RC_CHECK();
|
---|
1877 | # endif
|
---|
1878 |
|
---|
1879 | /* Virtual USB Mouse/Tablet */
|
---|
1880 | PointingHidType_T aPointingHid;
|
---|
1881 | hrc = pMachine->COMGETTER(PointingHidType)(&aPointingHid); H();
|
---|
1882 | if (aPointingHid == PointingHidType_USBMouse || aPointingHid == PointingHidType_USBTablet)
|
---|
1883 | {
|
---|
1884 | rc = CFGMR3InsertNode(pUsbDevices, "HidMouse", &pDev); RC_CHECK();
|
---|
1885 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1886 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1887 |
|
---|
1888 | if (aPointingHid == PointingHidType_USBTablet)
|
---|
1889 | {
|
---|
1890 | rc = CFGMR3InsertInteger(pCfg, "Absolute", 1); RC_CHECK();
|
---|
1891 | }
|
---|
1892 | else
|
---|
1893 | {
|
---|
1894 | rc = CFGMR3InsertInteger(pCfg, "Absolute", 0); RC_CHECK();
|
---|
1895 | }
|
---|
1896 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1897 | rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); RC_CHECK();
|
---|
1898 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1899 | rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); RC_CHECK();
|
---|
1900 |
|
---|
1901 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
1902 | rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse"); RC_CHECK();
|
---|
1903 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
1904 | pMouse = pConsole->mMouse;
|
---|
1905 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse); RC_CHECK();
|
---|
1906 | }
|
---|
1907 |
|
---|
1908 | /* Virtual USB Keyboard */
|
---|
1909 | KeyboardHidType_T aKbdHid;
|
---|
1910 | hrc = pMachine->COMGETTER(KeyboardHidType)(&aKbdHid); H();
|
---|
1911 | if (aKbdHid == KeyboardHidType_USBKeyboard)
|
---|
1912 | {
|
---|
1913 | rc = CFGMR3InsertNode(pUsbDevices, "HidKeyboard", &pDev); RC_CHECK();
|
---|
1914 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1915 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1916 |
|
---|
1917 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1918 | rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); RC_CHECK();
|
---|
1919 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1920 | rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); RC_CHECK();
|
---|
1921 |
|
---|
1922 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
1923 | rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard"); RC_CHECK();
|
---|
1924 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
1925 | pKeyboard = pConsole->mKeyboard;
|
---|
1926 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pKeyboard); RC_CHECK();
|
---|
1927 | }
|
---|
1928 | }
|
---|
1929 | }
|
---|
1930 |
|
---|
1931 | /*
|
---|
1932 | * Clipboard
|
---|
1933 | */
|
---|
1934 | {
|
---|
1935 | ClipboardMode_T mode = ClipboardMode_Disabled;
|
---|
1936 | hrc = pMachine->COMGETTER(ClipboardMode)(&mode); H();
|
---|
1937 |
|
---|
1938 | if (mode != ClipboardMode_Disabled)
|
---|
1939 | {
|
---|
1940 | /* Load the service */
|
---|
1941 | rc = pConsole->mVMMDev->hgcmLoadService("VBoxSharedClipboard", "VBoxSharedClipboard");
|
---|
1942 |
|
---|
1943 | if (RT_FAILURE(rc))
|
---|
1944 | {
|
---|
1945 | LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
|
---|
1946 | /* That is not a fatal failure. */
|
---|
1947 | rc = VINF_SUCCESS;
|
---|
1948 | }
|
---|
1949 | else
|
---|
1950 | {
|
---|
1951 | /* Setup the service. */
|
---|
1952 | VBOXHGCMSVCPARM parm;
|
---|
1953 |
|
---|
1954 | parm.type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
1955 |
|
---|
1956 | switch (mode)
|
---|
1957 | {
|
---|
1958 | default:
|
---|
1959 | case ClipboardMode_Disabled:
|
---|
1960 | {
|
---|
1961 | LogRel(("VBoxSharedClipboard mode: Off\n"));
|
---|
1962 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
|
---|
1963 | break;
|
---|
1964 | }
|
---|
1965 | case ClipboardMode_GuestToHost:
|
---|
1966 | {
|
---|
1967 | LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
|
---|
1968 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
|
---|
1969 | break;
|
---|
1970 | }
|
---|
1971 | case ClipboardMode_HostToGuest:
|
---|
1972 | {
|
---|
1973 | LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
|
---|
1974 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
|
---|
1975 | break;
|
---|
1976 | }
|
---|
1977 | case ClipboardMode_Bidirectional:
|
---|
1978 | {
|
---|
1979 | LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
|
---|
1980 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
|
---|
1981 | break;
|
---|
1982 | }
|
---|
1983 | }
|
---|
1984 |
|
---|
1985 | pConsole->mVMMDev->hgcmHostCall("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
|
---|
1986 |
|
---|
1987 | Log(("Set VBoxSharedClipboard mode\n"));
|
---|
1988 | }
|
---|
1989 | }
|
---|
1990 | }
|
---|
1991 |
|
---|
1992 | #ifdef VBOX_WITH_CROGL
|
---|
1993 | /*
|
---|
1994 | * crOpenGL
|
---|
1995 | */
|
---|
1996 | {
|
---|
1997 | BOOL fEnabled = false;
|
---|
1998 | hrc = pMachine->COMGETTER(Accelerate3DEnabled)(&fEnabled); H();
|
---|
1999 |
|
---|
2000 | if (fEnabled)
|
---|
2001 | {
|
---|
2002 | /* Load the service */
|
---|
2003 | rc = pConsole->mVMMDev->hgcmLoadService("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
|
---|
2004 | if (RT_FAILURE(rc))
|
---|
2005 | {
|
---|
2006 | LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
|
---|
2007 | /* That is not a fatal failure. */
|
---|
2008 | rc = VINF_SUCCESS;
|
---|
2009 | }
|
---|
2010 | else
|
---|
2011 | {
|
---|
2012 | LogRel(("Shared crOpenGL service loaded.\n"));
|
---|
2013 |
|
---|
2014 | /* Setup the service. */
|
---|
2015 | VBOXHGCMSVCPARM parm;
|
---|
2016 | parm.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2017 |
|
---|
2018 | parm.u.pointer.addr = (IConsole*) (Console*) pConsole;
|
---|
2019 | parm.u.pointer.size = sizeof(IConsole *);
|
---|
2020 |
|
---|
2021 | rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_CONSOLE,
|
---|
2022 | SHCRGL_CPARMS_SET_CONSOLE, &parm);
|
---|
2023 | if (!RT_SUCCESS(rc))
|
---|
2024 | AssertMsgFailed(("SHCRGL_HOST_FN_SET_CONSOLE failed with %Rrc\n", rc));
|
---|
2025 |
|
---|
2026 | parm.u.pointer.addr = pVM;
|
---|
2027 | parm.u.pointer.size = sizeof(pVM);
|
---|
2028 | rc = pConsole->mVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VM,
|
---|
2029 | SHCRGL_CPARMS_SET_VM, &parm);
|
---|
2030 | if (!RT_SUCCESS(rc))
|
---|
2031 | AssertMsgFailed(("SHCRGL_HOST_FN_SET_VM failed with %Rrc\n", rc));
|
---|
2032 | }
|
---|
2033 |
|
---|
2034 | }
|
---|
2035 | }
|
---|
2036 | #endif
|
---|
2037 |
|
---|
2038 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
2039 | /*
|
---|
2040 | * Guest property service
|
---|
2041 | */
|
---|
2042 |
|
---|
2043 | rc = configGuestProperties(pConsole);
|
---|
2044 | #endif /* VBOX_WITH_GUEST_PROPS defined */
|
---|
2045 |
|
---|
2046 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
2047 | /*
|
---|
2048 | * Guest control service
|
---|
2049 | */
|
---|
2050 |
|
---|
2051 | rc = configGuestControl(pConsole);
|
---|
2052 | #endif /* VBOX_WITH_GUEST_CONTROL defined */
|
---|
2053 |
|
---|
2054 | /*
|
---|
2055 | * ACPI
|
---|
2056 | */
|
---|
2057 | BOOL fACPI;
|
---|
2058 | hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
|
---|
2059 | if (fACPI)
|
---|
2060 | {
|
---|
2061 | BOOL fCpuHotPlug = false;
|
---|
2062 | BOOL fShowCpu = fOsXGuest;
|
---|
2063 | /* Always show the CPU leafs when we have multiple VCPUs or when the IO-APIC is enabled.
|
---|
2064 | * The Windows SMP kernel needs a CPU leaf or else its idle loop will burn cpu cycles; the
|
---|
2065 | * intelppm driver refuses to register an idle state handler.
|
---|
2066 | */
|
---|
2067 | if ((cCpus > 1) || fIOAPIC)
|
---|
2068 | fShowCpu = true;
|
---|
2069 |
|
---|
2070 | hrc = pMachine->COMGETTER(CPUHotPlugEnabled)(&fCpuHotPlug); H();
|
---|
2071 |
|
---|
2072 | rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); RC_CHECK();
|
---|
2073 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
2074 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
2075 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
2076 | rc = CFGMR3InsertInteger(pCfg, "RamSize", cbRam); RC_CHECK();
|
---|
2077 | rc = CFGMR3InsertInteger(pCfg, "RamHoleSize", cbRamHole); RC_CHECK();
|
---|
2078 | rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
|
---|
2079 |
|
---|
2080 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
|
---|
2081 | rc = CFGMR3InsertInteger(pCfg, "FdcEnabled", fFdcEnabled); RC_CHECK();
|
---|
2082 | rc = CFGMR3InsertInteger(pCfg, "HpetEnabled", fHpetEnabled); RC_CHECK();
|
---|
2083 | rc = CFGMR3InsertInteger(pCfg, "SmcEnabled", fSmcEnabled); RC_CHECK();
|
---|
2084 | rc = CFGMR3InsertInteger(pCfg, "ShowRtc", fOsXGuest); RC_CHECK();
|
---|
2085 | if (fOsXGuest && !llBootNics.empty())
|
---|
2086 | {
|
---|
2087 | BootNic aNic = llBootNics.front();
|
---|
2088 | uint32_t u32NicPciAddr = (aNic.mPciDev << 16) | aNic.mPciFn;
|
---|
2089 | rc = CFGMR3InsertInteger(pCfg, "NicPciAddress", u32NicPciAddr); RC_CHECK();
|
---|
2090 | }
|
---|
2091 | rc = CFGMR3InsertInteger(pCfg, "ShowCpu", fShowCpu); RC_CHECK();
|
---|
2092 | rc = CFGMR3InsertInteger(pCfg, "CpuHotPlug", fCpuHotPlug); RC_CHECK();
|
---|
2093 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
|
---|
2094 | Assert(!afPciDeviceNo[7]);
|
---|
2095 | afPciDeviceNo[7] = true;
|
---|
2096 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
2097 |
|
---|
2098 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
2099 | rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
|
---|
2100 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
2101 |
|
---|
2102 | /* Attach the dummy CPU drivers */
|
---|
2103 | for (ULONG iCpuCurr = 1; iCpuCurr < cCpus; iCpuCurr++)
|
---|
2104 | {
|
---|
2105 | BOOL fCpuAttached = true;
|
---|
2106 |
|
---|
2107 | if (fCpuHotPlug)
|
---|
2108 | {
|
---|
2109 | hrc = pMachine->GetCPUStatus(iCpuCurr, &fCpuAttached); H();
|
---|
2110 | }
|
---|
2111 |
|
---|
2112 | if (fCpuAttached)
|
---|
2113 | {
|
---|
2114 | rc = CFGMR3InsertNodeF(pInst, &pLunL0, "LUN#%u", iCpuCurr); RC_CHECK();
|
---|
2115 | rc = CFGMR3InsertString(pLunL0, "Driver", "ACPICpu"); RC_CHECK();
|
---|
2116 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
2117 | }
|
---|
2118 | }
|
---|
2119 | }
|
---|
2120 |
|
---|
2121 |
|
---|
2122 | /*
|
---|
2123 | * CFGM overlay handling.
|
---|
2124 | *
|
---|
2125 | * Here we check the extra data entries for CFGM values
|
---|
2126 | * and create the nodes and insert the values on the fly. Existing
|
---|
2127 | * values will be removed and reinserted. CFGM is typed, so by default
|
---|
2128 | * we will guess whether it's a string or an integer (byte arrays are
|
---|
2129 | * not currently supported). It's possible to override this autodetection
|
---|
2130 | * by adding "string:", "integer:" or "bytes:" (future).
|
---|
2131 | *
|
---|
2132 | * We first perform a run on global extra data, then on the machine
|
---|
2133 | * extra data to support global settings with local overrides.
|
---|
2134 | *
|
---|
2135 | */
|
---|
2136 | /** @todo add support for removing nodes and byte blobs. */
|
---|
2137 | SafeArray<BSTR> aGlobalExtraDataKeys;
|
---|
2138 | SafeArray<BSTR> aMachineExtraDataKeys;
|
---|
2139 | /*
|
---|
2140 | * Get the next key
|
---|
2141 | */
|
---|
2142 | if (FAILED(hrc = virtualBox->GetExtraDataKeys(ComSafeArrayAsOutParam(aGlobalExtraDataKeys))))
|
---|
2143 | AssertMsgFailed(("VirtualBox::GetExtraDataKeys failed with %Rrc\n", hrc));
|
---|
2144 |
|
---|
2145 | // remember the no. of global values so we can call the correct method below
|
---|
2146 | size_t cGlobalValues = aGlobalExtraDataKeys.size();
|
---|
2147 |
|
---|
2148 | if (FAILED(hrc = pMachine->GetExtraDataKeys(ComSafeArrayAsOutParam(aMachineExtraDataKeys))))
|
---|
2149 | AssertMsgFailed(("IMachine::GetExtraDataKeys failed with %Rrc\n", hrc));
|
---|
2150 |
|
---|
2151 | // build a combined list from global keys...
|
---|
2152 | std::list<Utf8Str> llExtraDataKeys;
|
---|
2153 |
|
---|
2154 | for (size_t i = 0; i < aGlobalExtraDataKeys.size(); ++i)
|
---|
2155 | llExtraDataKeys.push_back(Utf8Str(aGlobalExtraDataKeys[i]));
|
---|
2156 | // ... and machine keys
|
---|
2157 | for (size_t i = 0; i < aMachineExtraDataKeys.size(); ++i)
|
---|
2158 | llExtraDataKeys.push_back(Utf8Str(aMachineExtraDataKeys[i]));
|
---|
2159 |
|
---|
2160 | size_t i2 = 0;
|
---|
2161 | for (std::list<Utf8Str>::const_iterator it = llExtraDataKeys.begin();
|
---|
2162 | it != llExtraDataKeys.end();
|
---|
2163 | ++it, ++i2)
|
---|
2164 | {
|
---|
2165 | const Utf8Str &strKey = *it;
|
---|
2166 |
|
---|
2167 | /*
|
---|
2168 | * We only care about keys starting with "VBoxInternal/" (skip "G:" or "M:")
|
---|
2169 | */
|
---|
2170 | if (!strKey.startsWith("VBoxInternal/"))
|
---|
2171 | continue;
|
---|
2172 |
|
---|
2173 | const char *pszExtraDataKey = strKey.raw() + sizeof("VBoxInternal/") - 1;
|
---|
2174 |
|
---|
2175 | // get the value
|
---|
2176 | Bstr strExtraDataValue;
|
---|
2177 | if (i2 < cGlobalValues)
|
---|
2178 | // this is still one of the global values:
|
---|
2179 | hrc = virtualBox->GetExtraData(Bstr(strKey), strExtraDataValue.asOutParam());
|
---|
2180 | else
|
---|
2181 | hrc = pMachine->GetExtraData(Bstr(strKey), strExtraDataValue.asOutParam());
|
---|
2182 | if (FAILED(hrc))
|
---|
2183 | LogRel(("Warning: Cannot get extra data key %s, rc = %Rrc\n", strKey.raw(), hrc));
|
---|
2184 |
|
---|
2185 | /*
|
---|
2186 | * The key will be in the format "Node1/Node2/Value" or simply "Value".
|
---|
2187 | * Split the two and get the node, delete the value and create the node
|
---|
2188 | * if necessary.
|
---|
2189 | */
|
---|
2190 | PCFGMNODE pNode;
|
---|
2191 | const char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
|
---|
2192 | if (pszCFGMValueName)
|
---|
2193 | {
|
---|
2194 | /* terminate the node and advance to the value (Utf8Str might not
|
---|
2195 | offically like this but wtf) */
|
---|
2196 | *(char*)pszCFGMValueName = '\0';
|
---|
2197 | ++pszCFGMValueName;
|
---|
2198 |
|
---|
2199 | /* does the node already exist? */
|
---|
2200 | pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
|
---|
2201 | if (pNode)
|
---|
2202 | CFGMR3RemoveValue(pNode, pszCFGMValueName);
|
---|
2203 | else
|
---|
2204 | {
|
---|
2205 | /* create the node */
|
---|
2206 | rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
|
---|
2207 | if (RT_FAILURE(rc))
|
---|
2208 | {
|
---|
2209 | AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
|
---|
2210 | continue;
|
---|
2211 | }
|
---|
2212 | Assert(pNode);
|
---|
2213 | }
|
---|
2214 | }
|
---|
2215 | else
|
---|
2216 | {
|
---|
2217 | /* root value (no node path). */
|
---|
2218 | pNode = pRoot;
|
---|
2219 | pszCFGMValueName = pszExtraDataKey;
|
---|
2220 | pszExtraDataKey--;
|
---|
2221 | CFGMR3RemoveValue(pNode, pszCFGMValueName);
|
---|
2222 | }
|
---|
2223 |
|
---|
2224 | /*
|
---|
2225 | * Now let's have a look at the value.
|
---|
2226 | * Empty strings means that we should remove the value, which we've
|
---|
2227 | * already done above.
|
---|
2228 | */
|
---|
2229 | Utf8Str strCFGMValueUtf8(strExtraDataValue);
|
---|
2230 | const char *pszCFGMValue = strCFGMValueUtf8.raw();
|
---|
2231 | if ( pszCFGMValue
|
---|
2232 | && *pszCFGMValue)
|
---|
2233 | {
|
---|
2234 | uint64_t u64Value;
|
---|
2235 |
|
---|
2236 | /* check for type prefix first. */
|
---|
2237 | if (!strncmp(pszCFGMValue, "string:", sizeof("string:") - 1))
|
---|
2238 | rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue + sizeof("string:") - 1);
|
---|
2239 | else if (!strncmp(pszCFGMValue, "integer:", sizeof("integer:") - 1))
|
---|
2240 | {
|
---|
2241 | rc = RTStrToUInt64Full(pszCFGMValue + sizeof("integer:") - 1, 0, &u64Value);
|
---|
2242 | if (RT_SUCCESS(rc))
|
---|
2243 | rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
|
---|
2244 | }
|
---|
2245 | else if (!strncmp(pszCFGMValue, "bytes:", sizeof("bytes:") - 1))
|
---|
2246 | rc = VERR_NOT_IMPLEMENTED;
|
---|
2247 | /* auto detect type. */
|
---|
2248 | else if (RT_SUCCESS(RTStrToUInt64Full(pszCFGMValue, 0, &u64Value)))
|
---|
2249 | rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
|
---|
2250 | else
|
---|
2251 | rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
|
---|
2252 | AssertLogRelMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
|
---|
2253 | }
|
---|
2254 | }
|
---|
2255 |
|
---|
2256 | #undef H
|
---|
2257 | #undef RC_CHECK
|
---|
2258 |
|
---|
2259 | /* Register VM state change handler */
|
---|
2260 | int rc2 = VMR3AtStateRegister(pVM, Console::vmstateChangeCallback, pConsole);
|
---|
2261 | AssertRC(rc2);
|
---|
2262 | if (RT_SUCCESS(rc))
|
---|
2263 | rc = rc2;
|
---|
2264 |
|
---|
2265 | /* Register VM runtime error handler */
|
---|
2266 | rc2 = VMR3AtRuntimeErrorRegister(pVM, Console::setVMRuntimeErrorCallback, pConsole);
|
---|
2267 | AssertRC(rc2);
|
---|
2268 | if (RT_SUCCESS(rc))
|
---|
2269 | rc = rc2;
|
---|
2270 |
|
---|
2271 | LogFlowFunc(("vrc = %Rrc\n", rc));
|
---|
2272 | LogFlowFuncLeave();
|
---|
2273 |
|
---|
2274 | return rc;
|
---|
2275 | }
|
---|
2276 |
|
---|
2277 | /**
|
---|
2278 | * Ellipsis to va_list wrapper for calling setVMRuntimeErrorCallback.
|
---|
2279 | */
|
---|
2280 | /*static*/ void Console::setVMRuntimeErrorCallbackF(PVM pVM, void *pvConsole, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
|
---|
2281 | {
|
---|
2282 | va_list va;
|
---|
2283 | va_start(va, pszFormat);
|
---|
2284 | setVMRuntimeErrorCallback(pVM, pvConsole, fFlags, pszErrorId, pszFormat, va);
|
---|
2285 | va_end(va);
|
---|
2286 | }
|
---|
2287 |
|
---|
2288 | int Console::configMediumAttachment(PCFGMNODE pCtlInst,
|
---|
2289 | const char *pcszDevice,
|
---|
2290 | unsigned uInstance,
|
---|
2291 | StorageBus_T enmBus,
|
---|
2292 | bool fUseHostIOCache,
|
---|
2293 | bool fSetupMerge,
|
---|
2294 | unsigned uMergeSource,
|
---|
2295 | unsigned uMergeTarget,
|
---|
2296 | IMediumAttachment *pMediumAtt,
|
---|
2297 | MachineState_T aMachineState,
|
---|
2298 | HRESULT *phrc,
|
---|
2299 | bool fAttachDetach,
|
---|
2300 | bool fForceUnmount,
|
---|
2301 | PVM pVM,
|
---|
2302 | DeviceType_T *paLedDevType)
|
---|
2303 | {
|
---|
2304 | int rc = VINF_SUCCESS;
|
---|
2305 | HRESULT hrc;
|
---|
2306 | Bstr bstr;
|
---|
2307 |
|
---|
2308 | #define RC_CHECK() AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc)
|
---|
2309 | #define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
|
---|
2310 |
|
---|
2311 | LONG lDev;
|
---|
2312 | hrc = pMediumAtt->COMGETTER(Device)(&lDev); H();
|
---|
2313 | LONG lPort;
|
---|
2314 | hrc = pMediumAtt->COMGETTER(Port)(&lPort); H();
|
---|
2315 | DeviceType_T lType;
|
---|
2316 | hrc = pMediumAtt->COMGETTER(Type)(&lType); H();
|
---|
2317 |
|
---|
2318 | unsigned uLUN;
|
---|
2319 | PCFGMNODE pLunL0 = NULL;
|
---|
2320 | PCFGMNODE pCfg = NULL;
|
---|
2321 | hrc = Console::convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN); H();
|
---|
2322 |
|
---|
2323 | /* First check if the LUN already exists. */
|
---|
2324 | pLunL0 = CFGMR3GetChildF(pCtlInst, "LUN#%u", uLUN);
|
---|
2325 | if (pLunL0)
|
---|
2326 | {
|
---|
2327 | if (fAttachDetach)
|
---|
2328 | {
|
---|
2329 | if (lType != DeviceType_HardDisk)
|
---|
2330 | {
|
---|
2331 | /* Unmount existing media only for floppy and DVD drives. */
|
---|
2332 | PPDMIBASE pBase;
|
---|
2333 | rc = PDMR3QueryLun(pVM, pcszDevice, uInstance, uLUN, &pBase);
|
---|
2334 | if (RT_FAILURE(rc))
|
---|
2335 | {
|
---|
2336 | if (rc == VERR_PDM_LUN_NOT_FOUND || rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
|
---|
2337 | rc = VINF_SUCCESS;
|
---|
2338 | AssertRC(rc);
|
---|
2339 | }
|
---|
2340 | else
|
---|
2341 | {
|
---|
2342 | PPDMIMOUNT pIMount = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMOUNT);
|
---|
2343 | AssertReturn(pIMount, VERR_INVALID_POINTER);
|
---|
2344 |
|
---|
2345 | /* Unmount the media. */
|
---|
2346 | rc = pIMount->pfnUnmount(pIMount, fForceUnmount);
|
---|
2347 | if (rc == VERR_PDM_MEDIA_NOT_MOUNTED)
|
---|
2348 | rc = VINF_SUCCESS;
|
---|
2349 | }
|
---|
2350 | }
|
---|
2351 |
|
---|
2352 | rc = PDMR3DeviceDetach(pVM, pcszDevice, 0, uLUN, PDM_TACH_FLAGS_NOT_HOT_PLUG);
|
---|
2353 | if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
|
---|
2354 | rc = VINF_SUCCESS;
|
---|
2355 | RC_CHECK();
|
---|
2356 |
|
---|
2357 | CFGMR3RemoveNode(pLunL0);
|
---|
2358 | }
|
---|
2359 | else
|
---|
2360 | AssertFailedReturn(VERR_INTERNAL_ERROR);
|
---|
2361 | }
|
---|
2362 |
|
---|
2363 | rc = CFGMR3InsertNodeF(pCtlInst, &pLunL0, "LUN#%u", uLUN); RC_CHECK();
|
---|
2364 |
|
---|
2365 | /* SCSI has a another driver between device and block. */
|
---|
2366 | if (enmBus == StorageBus_SCSI || enmBus == StorageBus_SAS)
|
---|
2367 | {
|
---|
2368 | rc = CFGMR3InsertString(pLunL0, "Driver", "SCSI"); RC_CHECK();
|
---|
2369 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
2370 |
|
---|
2371 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
|
---|
2372 | }
|
---|
2373 |
|
---|
2374 | ComPtr<IMedium> pMedium;
|
---|
2375 | hrc = pMediumAtt->COMGETTER(Medium)(pMedium.asOutParam()); H();
|
---|
2376 | BOOL fPassthrough;
|
---|
2377 | hrc = pMediumAtt->COMGETTER(Passthrough)(&fPassthrough); H();
|
---|
2378 | rc = configMedium(pLunL0,
|
---|
2379 | !!fPassthrough,
|
---|
2380 | lType,
|
---|
2381 | fUseHostIOCache,
|
---|
2382 | fSetupMerge,
|
---|
2383 | uMergeSource,
|
---|
2384 | uMergeTarget,
|
---|
2385 | pMedium,
|
---|
2386 | aMachineState,
|
---|
2387 | phrc); RC_CHECK();
|
---|
2388 |
|
---|
2389 | if (fAttachDetach)
|
---|
2390 | {
|
---|
2391 | /* Attach the new driver. */
|
---|
2392 | rc = PDMR3DeviceAttach(pVM, pcszDevice, 0, uLUN,
|
---|
2393 | PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/); RC_CHECK();
|
---|
2394 |
|
---|
2395 | /* There is no need to handle removable medium mounting, as we
|
---|
2396 | * unconditionally replace everthing including the block driver level.
|
---|
2397 | * This means the new medium will be picked up automatically. */
|
---|
2398 | }
|
---|
2399 |
|
---|
2400 | if (paLedDevType)
|
---|
2401 | paLedDevType[uLUN] = lType;
|
---|
2402 |
|
---|
2403 | #undef H
|
---|
2404 | #undef RC_CHECK
|
---|
2405 |
|
---|
2406 | return VINF_SUCCESS;;
|
---|
2407 | }
|
---|
2408 |
|
---|
2409 | int Console::configMedium(PCFGMNODE pLunL0,
|
---|
2410 | bool fPassthrough,
|
---|
2411 | DeviceType_T enmType,
|
---|
2412 | bool fUseHostIOCache,
|
---|
2413 | bool fSetupMerge,
|
---|
2414 | unsigned uMergeSource,
|
---|
2415 | unsigned uMergeTarget,
|
---|
2416 | IMedium *pMedium,
|
---|
2417 | MachineState_T aMachineState,
|
---|
2418 | HRESULT *phrc)
|
---|
2419 | {
|
---|
2420 | int rc = VINF_SUCCESS;
|
---|
2421 | HRESULT hrc;
|
---|
2422 | Bstr bstr;
|
---|
2423 |
|
---|
2424 | #define RC_CHECK() AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc)
|
---|
2425 | #define H() AssertMsgReturnStmt(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), if (phrc) *phrc = hrc, VERR_GENERAL_FAILURE)
|
---|
2426 |
|
---|
2427 | PCFGMNODE pLunL1 = NULL;
|
---|
2428 | PCFGMNODE pCfg = NULL;
|
---|
2429 |
|
---|
2430 | BOOL fHostDrive = FALSE;
|
---|
2431 | if (pMedium)
|
---|
2432 | {
|
---|
2433 | hrc = pMedium->COMGETTER(HostDrive)(&fHostDrive); H();
|
---|
2434 | }
|
---|
2435 |
|
---|
2436 | if (fHostDrive)
|
---|
2437 | {
|
---|
2438 | Assert(pMedium);
|
---|
2439 | if (enmType == DeviceType_DVD)
|
---|
2440 | {
|
---|
2441 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
|
---|
2442 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
2443 |
|
---|
2444 | hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
|
---|
2445 | rc = CFGMR3InsertStringW(pCfg, "Path", bstr.raw()); RC_CHECK();
|
---|
2446 |
|
---|
2447 | rc = CFGMR3InsertInteger(pCfg, "Passthrough", fPassthrough); RC_CHECK();
|
---|
2448 | }
|
---|
2449 | else if (enmType == DeviceType_Floppy)
|
---|
2450 | {
|
---|
2451 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostFloppy"); RC_CHECK();
|
---|
2452 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
2453 |
|
---|
2454 | hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
|
---|
2455 | rc = CFGMR3InsertStringW(pCfg, "Path", bstr.raw()); RC_CHECK();
|
---|
2456 | }
|
---|
2457 | }
|
---|
2458 | else
|
---|
2459 | {
|
---|
2460 | rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
|
---|
2461 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
2462 | switch (enmType)
|
---|
2463 | {
|
---|
2464 | case DeviceType_DVD:
|
---|
2465 | rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
|
---|
2466 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
|
---|
2467 | break;
|
---|
2468 | case DeviceType_Floppy:
|
---|
2469 | rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
|
---|
2470 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
|
---|
2471 | break;
|
---|
2472 | case DeviceType_HardDisk:
|
---|
2473 | default:
|
---|
2474 | rc = CFGMR3InsertString(pCfg, "Type", "HardDisk"); RC_CHECK();
|
---|
2475 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 0); RC_CHECK();
|
---|
2476 | }
|
---|
2477 |
|
---|
2478 | if ( pMedium
|
---|
2479 | && ( enmType == DeviceType_DVD
|
---|
2480 | || enmType == DeviceType_Floppy
|
---|
2481 | ))
|
---|
2482 | {
|
---|
2483 | // if this medium represents an ISO image and this image is inaccessible,
|
---|
2484 | // the ignore it instead of causing a failure; this can happen when we
|
---|
2485 | // restore a VM state and the ISO has disappeared, e.g. because the Guest
|
---|
2486 | // Additions were mounted and the user upgraded VirtualBox. Previously
|
---|
2487 | // we failed on startup, but that's not good because the only way out then
|
---|
2488 | // would be to discard the VM state...
|
---|
2489 | MediumState_T mediumState;
|
---|
2490 | rc = pMedium->RefreshState(&mediumState);
|
---|
2491 | RC_CHECK();
|
---|
2492 | if (mediumState == MediumState_Inaccessible)
|
---|
2493 | {
|
---|
2494 | Bstr loc;
|
---|
2495 | rc = pMedium->COMGETTER(Location)(loc.asOutParam());
|
---|
2496 | if (FAILED(rc)) return rc;
|
---|
2497 |
|
---|
2498 | setVMRuntimeErrorCallbackF(mpVM,
|
---|
2499 | this,
|
---|
2500 | 0,
|
---|
2501 | "DvdOrFloppyImageInaccessible",
|
---|
2502 | "The image file '%ls' is inaccessible and is being ignored. Please select a different image file for the virtual %s drive.",
|
---|
2503 | loc.raw(),
|
---|
2504 | (enmType == DeviceType_DVD) ? "DVD" : "floppy");
|
---|
2505 | pMedium = NULL;
|
---|
2506 | }
|
---|
2507 | }
|
---|
2508 |
|
---|
2509 | if (pMedium)
|
---|
2510 | {
|
---|
2511 | /* Start with length of parent chain, as the list is reversed */
|
---|
2512 | unsigned uImage = 0;
|
---|
2513 | IMedium *pTmp = pMedium;
|
---|
2514 | while (pTmp)
|
---|
2515 | {
|
---|
2516 | uImage++;
|
---|
2517 | hrc = pTmp->COMGETTER(Parent)(&pTmp); H();
|
---|
2518 | }
|
---|
2519 | /* Index of last image */
|
---|
2520 | uImage--;
|
---|
2521 |
|
---|
2522 | #if 0 /* Enable for I/O debugging */
|
---|
2523 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
|
---|
2524 | rc = CFGMR3InsertString(pLunL0, "Driver", "DiskIntegrity"); RC_CHECK();
|
---|
2525 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
2526 | rc = CFGMR3InsertInteger(pCfg, "CheckConsistency", 0); RC_CHECK();
|
---|
2527 | rc = CFGMR3InsertInteger(pCfg, "CheckDoubleCompletions", 1); RC_CHECK();
|
---|
2528 | #endif
|
---|
2529 |
|
---|
2530 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
2531 | rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
|
---|
2532 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
2533 |
|
---|
2534 | hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
|
---|
2535 | rc = CFGMR3InsertStringW(pCfg, "Path", bstr.raw()); RC_CHECK();
|
---|
2536 |
|
---|
2537 | hrc = pMedium->COMGETTER(Format)(bstr.asOutParam()); H();
|
---|
2538 | rc = CFGMR3InsertStringW(pCfg, "Format", bstr.raw()); RC_CHECK();
|
---|
2539 |
|
---|
2540 | /* DVDs are always readonly */
|
---|
2541 | if (enmType == DeviceType_DVD)
|
---|
2542 | {
|
---|
2543 | rc = CFGMR3InsertInteger(pCfg, "ReadOnly", 1); RC_CHECK();
|
---|
2544 | }
|
---|
2545 |
|
---|
2546 | /* Start without exclusive write access to the images. */
|
---|
2547 | /** @todo Live Migration: I don't quite like this, we risk screwing up when
|
---|
2548 | * we're resuming the VM if some 3rd dude have any of the VDIs open
|
---|
2549 | * with write sharing denied. However, if the two VMs are sharing a
|
---|
2550 | * image it really is necessary....
|
---|
2551 | *
|
---|
2552 | * So, on the "lock-media" command, the target teleporter should also
|
---|
2553 | * make DrvVD undo TempReadOnly. It gets interesting if we fail after
|
---|
2554 | * that. Grumble. */
|
---|
2555 | else if (aMachineState == MachineState_TeleportingIn)
|
---|
2556 | {
|
---|
2557 | rc = CFGMR3InsertInteger(pCfg, "TempReadOnly", 1); RC_CHECK();
|
---|
2558 | }
|
---|
2559 |
|
---|
2560 | if (!fUseHostIOCache)
|
---|
2561 | {
|
---|
2562 | rc = CFGMR3InsertInteger(pCfg, "UseNewIo", 1); RC_CHECK();
|
---|
2563 | }
|
---|
2564 |
|
---|
2565 | if (fSetupMerge)
|
---|
2566 | {
|
---|
2567 | rc = CFGMR3InsertInteger(pCfg, "SetupMerge", 1); RC_CHECK();
|
---|
2568 | if (uImage == uMergeSource)
|
---|
2569 | {
|
---|
2570 | rc = CFGMR3InsertInteger(pCfg, "MergeSource", 1); RC_CHECK();
|
---|
2571 | }
|
---|
2572 | else if (uImage == uMergeTarget)
|
---|
2573 | {
|
---|
2574 | rc = CFGMR3InsertInteger(pCfg, "MergeTarget", 1); RC_CHECK();
|
---|
2575 | }
|
---|
2576 | }
|
---|
2577 |
|
---|
2578 | /* Pass all custom parameters. */
|
---|
2579 | bool fHostIP = true;
|
---|
2580 | SafeArray<BSTR> names;
|
---|
2581 | SafeArray<BSTR> values;
|
---|
2582 | hrc = pMedium->GetProperties(NULL,
|
---|
2583 | ComSafeArrayAsOutParam(names),
|
---|
2584 | ComSafeArrayAsOutParam(values)); H();
|
---|
2585 |
|
---|
2586 | if (names.size() != 0)
|
---|
2587 | {
|
---|
2588 | PCFGMNODE pVDC;
|
---|
2589 | rc = CFGMR3InsertNode(pCfg, "VDConfig", &pVDC); RC_CHECK();
|
---|
2590 | for (size_t ii = 0; ii < names.size(); ++ii)
|
---|
2591 | {
|
---|
2592 | if (values[ii] && *values[ii])
|
---|
2593 | {
|
---|
2594 | Utf8Str name = names[ii];
|
---|
2595 | Utf8Str value = values[ii];
|
---|
2596 | rc = CFGMR3InsertString(pVDC, name.c_str(), value.c_str()); RC_CHECK();
|
---|
2597 | if ( name.compare("HostIPStack") == 0
|
---|
2598 | && value.compare("0") == 0)
|
---|
2599 | fHostIP = false;
|
---|
2600 | }
|
---|
2601 | }
|
---|
2602 | }
|
---|
2603 |
|
---|
2604 | /* Create an inversed list of parents. */
|
---|
2605 | uImage--;
|
---|
2606 | IMedium *pParentMedium = pMedium;
|
---|
2607 | for (PCFGMNODE pParent = pCfg;; uImage--)
|
---|
2608 | {
|
---|
2609 | hrc = pParentMedium->COMGETTER(Parent)(&pMedium); H();
|
---|
2610 | if (!pMedium)
|
---|
2611 | break;
|
---|
2612 |
|
---|
2613 | PCFGMNODE pCur;
|
---|
2614 | rc = CFGMR3InsertNode(pParent, "Parent", &pCur); RC_CHECK();
|
---|
2615 | hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
|
---|
2616 | rc = CFGMR3InsertStringW(pCur, "Path", bstr.raw()); RC_CHECK();
|
---|
2617 |
|
---|
2618 | hrc = pMedium->COMGETTER(Format)(bstr.asOutParam()); H();
|
---|
2619 | rc = CFGMR3InsertStringW(pCur, "Format", bstr.raw()); RC_CHECK();
|
---|
2620 |
|
---|
2621 | if (fSetupMerge)
|
---|
2622 | {
|
---|
2623 | if (uImage == uMergeSource)
|
---|
2624 | {
|
---|
2625 | rc = CFGMR3InsertInteger(pCur, "MergeSource", 1); RC_CHECK();
|
---|
2626 | }
|
---|
2627 | else if (uImage == uMergeTarget)
|
---|
2628 | {
|
---|
2629 | rc = CFGMR3InsertInteger(pCur, "MergeTarget", 1); RC_CHECK();
|
---|
2630 | }
|
---|
2631 | }
|
---|
2632 |
|
---|
2633 | /* Pass all custom parameters. */
|
---|
2634 | SafeArray<BSTR> aNames;
|
---|
2635 | SafeArray<BSTR> aValues;
|
---|
2636 | hrc = pMedium->GetProperties(NULL,
|
---|
2637 | ComSafeArrayAsOutParam(aNames),
|
---|
2638 | ComSafeArrayAsOutParam(aValues)); H();
|
---|
2639 |
|
---|
2640 | if (aNames.size() != 0)
|
---|
2641 | {
|
---|
2642 | PCFGMNODE pVDC;
|
---|
2643 | rc = CFGMR3InsertNode(pCur, "VDConfig", &pVDC); RC_CHECK();
|
---|
2644 | for (size_t ii = 0; ii < aNames.size(); ++ii)
|
---|
2645 | {
|
---|
2646 | if (aValues[ii] && *aValues[ii])
|
---|
2647 | {
|
---|
2648 | Utf8Str name = aNames[ii];
|
---|
2649 | Utf8Str value = aValues[ii];
|
---|
2650 | rc = CFGMR3InsertString(pVDC, name.c_str(), value.c_str()); RC_CHECK();
|
---|
2651 | if ( name.compare("HostIPStack") == 0
|
---|
2652 | && value.compare("0") == 0)
|
---|
2653 | fHostIP = false;
|
---|
2654 | }
|
---|
2655 | }
|
---|
2656 | }
|
---|
2657 |
|
---|
2658 | /* Custom code: put marker to not use host IP stack to driver
|
---|
2659 | * configuration node. Simplifies life of DrvVD a bit. */
|
---|
2660 | if (!fHostIP)
|
---|
2661 | {
|
---|
2662 | rc = CFGMR3InsertInteger(pCfg, "HostIPStack", 0); RC_CHECK();
|
---|
2663 | }
|
---|
2664 |
|
---|
2665 | /* next */
|
---|
2666 | pParent = pCur;
|
---|
2667 | pParentMedium = pMedium;
|
---|
2668 | }
|
---|
2669 | }
|
---|
2670 | }
|
---|
2671 |
|
---|
2672 | #undef H
|
---|
2673 | #undef RC_CHECK
|
---|
2674 |
|
---|
2675 | return VINF_SUCCESS;
|
---|
2676 | }
|
---|
2677 |
|
---|
2678 | /**
|
---|
2679 | * Construct the Network configuration tree
|
---|
2680 | *
|
---|
2681 | * @returns VBox status code.
|
---|
2682 | *
|
---|
2683 | * @param pszDevice The PDM device name.
|
---|
2684 | * @param uInstance The PDM device instance.
|
---|
2685 | * @param uLun The PDM LUN number of the drive.
|
---|
2686 | * @param aNetworkAdapter The network adapter whose attachment needs to be changed
|
---|
2687 | * @param pCfg Configuration node for the device
|
---|
2688 | * @param pLunL0 To store the pointer to the LUN#0.
|
---|
2689 | * @param pInst The instance CFGM node
|
---|
2690 | * @param fAttachDetach To determine if the network attachment should
|
---|
2691 | * be attached/detached after/before
|
---|
2692 | * configuration.
|
---|
2693 | *
|
---|
2694 | * @note Locks this object for writing.
|
---|
2695 | */
|
---|
2696 | int Console::configNetwork(const char *pszDevice, unsigned uInstance,
|
---|
2697 | unsigned uLun, INetworkAdapter *aNetworkAdapter,
|
---|
2698 | PCFGMNODE pCfg, PCFGMNODE pLunL0, PCFGMNODE pInst,
|
---|
2699 | bool fAttachDetach)
|
---|
2700 | {
|
---|
2701 | AutoCaller autoCaller(this);
|
---|
2702 | AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
|
---|
2703 |
|
---|
2704 | int rc = VINF_SUCCESS;
|
---|
2705 | HRESULT hrc;
|
---|
2706 | Bstr bstr;
|
---|
2707 |
|
---|
2708 | #define RC_CHECK() AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc)
|
---|
2709 | #define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
|
---|
2710 |
|
---|
2711 | /*
|
---|
2712 | * Locking the object before doing VMR3* calls is quite safe here, since
|
---|
2713 | * we're on EMT. Write lock is necessary because we indirectly modify the
|
---|
2714 | * meAttachmentType member.
|
---|
2715 | */
|
---|
2716 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
2717 |
|
---|
2718 | PVM pVM = mpVM;
|
---|
2719 |
|
---|
2720 | ComPtr<IMachine> pMachine = machine();
|
---|
2721 |
|
---|
2722 | ComPtr<IVirtualBox> virtualBox;
|
---|
2723 | hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam());
|
---|
2724 | H();
|
---|
2725 |
|
---|
2726 | ComPtr<IHost> host;
|
---|
2727 | hrc = virtualBox->COMGETTER(Host)(host.asOutParam());
|
---|
2728 | H();
|
---|
2729 |
|
---|
2730 | BOOL fSniffer;
|
---|
2731 | hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer);
|
---|
2732 | H();
|
---|
2733 |
|
---|
2734 | if (fAttachDetach && fSniffer)
|
---|
2735 | {
|
---|
2736 | const char *pszNetDriver = "IntNet";
|
---|
2737 | if (meAttachmentType[uInstance] == NetworkAttachmentType_NAT)
|
---|
2738 | pszNetDriver = "NAT";
|
---|
2739 | #if !defined(VBOX_WITH_NETFLT) && defined(RT_OS_LINUX)
|
---|
2740 | if (meAttachmentType[uInstance] == NetworkAttachmentType_Bridged)
|
---|
2741 | pszNetDriver = "HostInterface";
|
---|
2742 | #endif
|
---|
2743 |
|
---|
2744 | rc = PDMR3DriverDetach(pVM, pszDevice, uInstance, uLun, pszNetDriver, 0, 0 /*fFlags*/);
|
---|
2745 | if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
|
---|
2746 | rc = VINF_SUCCESS;
|
---|
2747 | AssertLogRelRCReturn(rc, rc);
|
---|
2748 |
|
---|
2749 | pLunL0 = CFGMR3GetChildF(pInst, "LUN#%u", uLun);
|
---|
2750 | PCFGMNODE pLunAD = CFGMR3GetChildF(pLunL0, "AttachedDriver");
|
---|
2751 | if (pLunAD)
|
---|
2752 | {
|
---|
2753 | CFGMR3RemoveNode(pLunAD);
|
---|
2754 | }
|
---|
2755 | else
|
---|
2756 | {
|
---|
2757 | CFGMR3RemoveNode(pLunL0);
|
---|
2758 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
2759 | rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
|
---|
2760 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
2761 | hrc = aNetworkAdapter->COMGETTER(TraceFile)(bstr.asOutParam()); H();
|
---|
2762 | if (!bstr.isEmpty()) /* check convention for indicating default file. */
|
---|
2763 | {
|
---|
2764 | rc = CFGMR3InsertStringW(pCfg, "File", bstr.raw()); RC_CHECK();
|
---|
2765 | }
|
---|
2766 | }
|
---|
2767 | }
|
---|
2768 | else if (fAttachDetach && !fSniffer)
|
---|
2769 | {
|
---|
2770 | rc = PDMR3DeviceDetach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/);
|
---|
2771 | if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
|
---|
2772 | rc = VINF_SUCCESS;
|
---|
2773 | AssertLogRelRCReturn(rc, rc);
|
---|
2774 |
|
---|
2775 | /* nuke anything which might have been left behind. */
|
---|
2776 | CFGMR3RemoveNode(CFGMR3GetChildF(pInst, "LUN#%u", uLun));
|
---|
2777 | }
|
---|
2778 | else if (!fAttachDetach && fSniffer)
|
---|
2779 | {
|
---|
2780 | /* insert the sniffer filter driver. */
|
---|
2781 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
2782 | rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
|
---|
2783 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
2784 | hrc = aNetworkAdapter->COMGETTER(TraceFile)(bstr.asOutParam()); H();
|
---|
2785 | if (!bstr.isEmpty()) /* check convention for indicating default file. */
|
---|
2786 | {
|
---|
2787 | rc = CFGMR3InsertStringW(pCfg, "File", bstr.raw()); RC_CHECK();
|
---|
2788 | }
|
---|
2789 | }
|
---|
2790 |
|
---|
2791 | Bstr networkName, trunkName, trunkType;
|
---|
2792 | NetworkAttachmentType_T eAttachmentType;
|
---|
2793 | hrc = aNetworkAdapter->COMGETTER(AttachmentType)(&eAttachmentType); H();
|
---|
2794 | switch (eAttachmentType)
|
---|
2795 | {
|
---|
2796 | case NetworkAttachmentType_Null:
|
---|
2797 | break;
|
---|
2798 |
|
---|
2799 | case NetworkAttachmentType_NAT:
|
---|
2800 | {
|
---|
2801 | ComPtr<INATEngine> natDriver;
|
---|
2802 | hrc = aNetworkAdapter->COMGETTER(NatDriver)(natDriver.asOutParam()); H();
|
---|
2803 | if (fSniffer)
|
---|
2804 | {
|
---|
2805 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
|
---|
2806 | }
|
---|
2807 | else
|
---|
2808 | {
|
---|
2809 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
2810 | }
|
---|
2811 | rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
|
---|
2812 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
2813 |
|
---|
2814 | /* Configure TFTP prefix and boot filename. */
|
---|
2815 | hrc = virtualBox->COMGETTER(HomeFolder)(bstr.asOutParam()); H();
|
---|
2816 | if (!bstr.isEmpty())
|
---|
2817 | {
|
---|
2818 | rc = CFGMR3InsertStringF(pCfg, "TFTPPrefix", "%ls%c%s", bstr.raw(), RTPATH_DELIMITER, "TFTP"); RC_CHECK();
|
---|
2819 | }
|
---|
2820 | hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
|
---|
2821 | rc = CFGMR3InsertStringF(pCfg, "BootFile", "%ls.pxe", bstr.raw()); RC_CHECK();
|
---|
2822 |
|
---|
2823 | hrc = natDriver->COMGETTER(Network)(bstr.asOutParam()); H();
|
---|
2824 | if (!bstr.isEmpty())
|
---|
2825 | {
|
---|
2826 | rc = CFGMR3InsertStringW(pCfg, "Network", bstr.raw()); RC_CHECK();
|
---|
2827 | }
|
---|
2828 | else
|
---|
2829 | {
|
---|
2830 | ULONG uSlot;
|
---|
2831 | hrc = aNetworkAdapter->COMGETTER(Slot)(&uSlot); H();
|
---|
2832 | rc = CFGMR3InsertStringF(pCfg, "Network", "10.0.%d.0/24", uSlot+2); RC_CHECK();
|
---|
2833 | }
|
---|
2834 | hrc = natDriver->COMGETTER(HostIP)(bstr.asOutParam()); H();
|
---|
2835 | if (!bstr.isEmpty())
|
---|
2836 | {
|
---|
2837 | rc = CFGMR3InsertStringW(pCfg, "BindIP", bstr.raw()); RC_CHECK();
|
---|
2838 | }
|
---|
2839 | ULONG mtu = 0;
|
---|
2840 | ULONG sockSnd = 0;
|
---|
2841 | ULONG sockRcv = 0;
|
---|
2842 | ULONG tcpSnd = 0;
|
---|
2843 | ULONG tcpRcv = 0;
|
---|
2844 | hrc = natDriver->GetNetworkSettings(&mtu, &sockSnd, &sockRcv, &tcpSnd, &tcpRcv); H();
|
---|
2845 | if (mtu)
|
---|
2846 | {
|
---|
2847 | rc = CFGMR3InsertInteger(pCfg, "SlirpMTU", mtu); RC_CHECK();
|
---|
2848 | }
|
---|
2849 | if (sockRcv)
|
---|
2850 | {
|
---|
2851 | rc = CFGMR3InsertInteger(pCfg, "SockRcv", sockRcv); RC_CHECK();
|
---|
2852 | }
|
---|
2853 | if (sockSnd)
|
---|
2854 | {
|
---|
2855 | rc = CFGMR3InsertInteger(pCfg, "SockSnd", sockSnd); RC_CHECK();
|
---|
2856 | }
|
---|
2857 | if (tcpRcv)
|
---|
2858 | {
|
---|
2859 | rc = CFGMR3InsertInteger(pCfg, "TcpRcv", tcpRcv); RC_CHECK();
|
---|
2860 | }
|
---|
2861 | if (tcpSnd)
|
---|
2862 | {
|
---|
2863 | rc = CFGMR3InsertInteger(pCfg, "TcpSnd", tcpSnd); RC_CHECK();
|
---|
2864 | }
|
---|
2865 | hrc = natDriver->COMGETTER(TftpPrefix)(bstr.asOutParam()); H();
|
---|
2866 | if (!bstr.isEmpty())
|
---|
2867 | {
|
---|
2868 | rc = CFGMR3RemoveValue(pCfg, "TFTPPrefix"); RC_CHECK();
|
---|
2869 | rc = CFGMR3InsertStringW(pCfg, "TFTPPrefix", bstr); RC_CHECK();
|
---|
2870 | }
|
---|
2871 | hrc = natDriver->COMGETTER(TftpBootFile)(bstr.asOutParam()); H();
|
---|
2872 | if (!bstr.isEmpty())
|
---|
2873 | {
|
---|
2874 | rc = CFGMR3RemoveValue(pCfg, "BootFile"); RC_CHECK();
|
---|
2875 | rc = CFGMR3InsertStringW(pCfg, "BootFile", bstr); RC_CHECK();
|
---|
2876 | }
|
---|
2877 | hrc = natDriver->COMGETTER(TftpNextServer)(bstr.asOutParam()); H();
|
---|
2878 | if (!bstr.isEmpty())
|
---|
2879 | {
|
---|
2880 | rc = CFGMR3InsertStringW(pCfg, "NextServer", bstr); RC_CHECK();
|
---|
2881 | }
|
---|
2882 | BOOL fDnsFlag;
|
---|
2883 | hrc = natDriver->COMGETTER(DnsPassDomain)(&fDnsFlag); H();
|
---|
2884 | rc = CFGMR3InsertInteger(pCfg, "PassDomain", fDnsFlag); RC_CHECK();
|
---|
2885 | hrc = natDriver->COMGETTER(DnsProxy)(&fDnsFlag); H();
|
---|
2886 | rc = CFGMR3InsertInteger(pCfg, "DNSProxy", fDnsFlag); RC_CHECK();
|
---|
2887 | hrc = natDriver->COMGETTER(DnsUseHostResolver)(&fDnsFlag); H();
|
---|
2888 | rc = CFGMR3InsertInteger(pCfg, "UseHostResolver", fDnsFlag); RC_CHECK();
|
---|
2889 |
|
---|
2890 | ULONG aliasMode;
|
---|
2891 | hrc = natDriver->COMGETTER(AliasMode)(&aliasMode); H();
|
---|
2892 | rc = CFGMR3InsertInteger(pCfg, "AliasMode", aliasMode); RC_CHECK();
|
---|
2893 |
|
---|
2894 | /* port-forwarding */
|
---|
2895 | SafeArray<BSTR> pfs;
|
---|
2896 | hrc = natDriver->COMGETTER(Redirects)(ComSafeArrayAsOutParam(pfs)); H();
|
---|
2897 | PCFGMNODE pPF = NULL; /* /Devices/Dev/.../Config/PF#0/ */
|
---|
2898 | for (unsigned int i = 0; i < pfs.size(); ++i)
|
---|
2899 | {
|
---|
2900 | uint16_t port = 0;
|
---|
2901 | BSTR r = pfs[i];
|
---|
2902 | Utf8Str utf = Utf8Str(r);
|
---|
2903 | Utf8Str strName;
|
---|
2904 | Utf8Str strProto;
|
---|
2905 | Utf8Str strHostPort;
|
---|
2906 | Utf8Str strHostIP;
|
---|
2907 | Utf8Str strGuestPort;
|
---|
2908 | Utf8Str strGuestIP;
|
---|
2909 | size_t pos, ppos;
|
---|
2910 | pos = ppos = 0;
|
---|
2911 | #define ITERATE_TO_NEXT_TERM(res, str, pos, ppos) \
|
---|
2912 | do { \
|
---|
2913 | pos = str.find(",", ppos); \
|
---|
2914 | if (pos == Utf8Str::npos) \
|
---|
2915 | { \
|
---|
2916 | Log(( #res " extracting from %s is failed\n", str.raw())); \
|
---|
2917 | continue; \
|
---|
2918 | } \
|
---|
2919 | res = str.substr(ppos, pos - ppos); \
|
---|
2920 | Log2((#res " %s pos:%d, ppos:%d\n", res.raw(), pos, ppos)); \
|
---|
2921 | ppos = pos + 1; \
|
---|
2922 | } while (0)
|
---|
2923 | ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos);
|
---|
2924 | ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos);
|
---|
2925 | ITERATE_TO_NEXT_TERM(strHostIP, utf, pos, ppos);
|
---|
2926 | ITERATE_TO_NEXT_TERM(strHostPort, utf, pos, ppos);
|
---|
2927 | ITERATE_TO_NEXT_TERM(strGuestIP, utf, pos, ppos);
|
---|
2928 | strGuestPort = utf.substr(ppos, utf.length() - ppos);
|
---|
2929 | #undef ITERATE_TO_NEXT_TERM
|
---|
2930 |
|
---|
2931 | uint32_t proto = strProto.toUInt32();
|
---|
2932 | bool fValid = true;
|
---|
2933 | switch (proto)
|
---|
2934 | {
|
---|
2935 | case NATProtocol_UDP:
|
---|
2936 | strProto = "UDP";
|
---|
2937 | break;
|
---|
2938 | case NATProtocol_TCP:
|
---|
2939 | strProto = "TCP";
|
---|
2940 | break;
|
---|
2941 | default:
|
---|
2942 | fValid = false;
|
---|
2943 | }
|
---|
2944 | /* continue with next rule if no valid proto was passed */
|
---|
2945 | if (!fValid)
|
---|
2946 | continue;
|
---|
2947 |
|
---|
2948 | rc = CFGMR3InsertNode(pCfg, strName.raw(), &pPF); RC_CHECK();
|
---|
2949 | rc = CFGMR3InsertString(pPF, "Protocol", strProto.raw()); RC_CHECK();
|
---|
2950 |
|
---|
2951 | if (!strHostIP.isEmpty())
|
---|
2952 | {
|
---|
2953 | rc = CFGMR3InsertString(pPF, "BindIP", strHostIP.raw()); RC_CHECK();
|
---|
2954 | }
|
---|
2955 |
|
---|
2956 | if (!strGuestIP.isEmpty())
|
---|
2957 | {
|
---|
2958 | rc = CFGMR3InsertString(pPF, "GuestIP", strGuestIP.raw()); RC_CHECK();
|
---|
2959 | }
|
---|
2960 |
|
---|
2961 | port = RTStrToUInt16(strHostPort.raw());
|
---|
2962 | if (port)
|
---|
2963 | {
|
---|
2964 | rc = CFGMR3InsertInteger(pPF, "HostPort", port); RC_CHECK();
|
---|
2965 | }
|
---|
2966 |
|
---|
2967 | port = RTStrToUInt16(strGuestPort.raw());
|
---|
2968 | if (port)
|
---|
2969 | {
|
---|
2970 | rc = CFGMR3InsertInteger(pPF, "GuestPort", port); RC_CHECK();
|
---|
2971 | }
|
---|
2972 | }
|
---|
2973 | break;
|
---|
2974 | }
|
---|
2975 |
|
---|
2976 | case NetworkAttachmentType_Bridged:
|
---|
2977 | {
|
---|
2978 | #if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT)
|
---|
2979 | hrc = attachToTapInterface(aNetworkAdapter);
|
---|
2980 | if (FAILED(hrc))
|
---|
2981 | {
|
---|
2982 | switch (hrc)
|
---|
2983 | {
|
---|
2984 | case VERR_ACCESS_DENIED:
|
---|
2985 | return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
|
---|
2986 | "Failed to open '/dev/net/tun' for read/write access. Please check the "
|
---|
2987 | "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
|
---|
2988 | "change the group of that node and make yourself a member of that group. Make "
|
---|
2989 | "sure that these changes are permanent, especially if you are "
|
---|
2990 | "using udev"));
|
---|
2991 | default:
|
---|
2992 | AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
|
---|
2993 | return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
|
---|
2994 | "Failed to initialize Host Interface Networking"));
|
---|
2995 | }
|
---|
2996 | }
|
---|
2997 |
|
---|
2998 | Assert((int)maTapFD[uInstance] >= 0);
|
---|
2999 | if ((int)maTapFD[uInstance] >= 0)
|
---|
3000 | {
|
---|
3001 | if (fSniffer)
|
---|
3002 | {
|
---|
3003 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
|
---|
3004 | }
|
---|
3005 | else
|
---|
3006 | {
|
---|
3007 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
3008 | }
|
---|
3009 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
|
---|
3010 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
3011 | rc = CFGMR3InsertInteger(pCfg, "FileHandle", maTapFD[uInstance]); RC_CHECK();
|
---|
3012 | }
|
---|
3013 |
|
---|
3014 | #elif defined(VBOX_WITH_NETFLT)
|
---|
3015 | /*
|
---|
3016 | * This is the new VBoxNetFlt+IntNet stuff.
|
---|
3017 | */
|
---|
3018 | if (fSniffer)
|
---|
3019 | {
|
---|
3020 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
|
---|
3021 | }
|
---|
3022 | else
|
---|
3023 | {
|
---|
3024 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
3025 | }
|
---|
3026 |
|
---|
3027 | Bstr HifName;
|
---|
3028 | hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
|
---|
3029 | if (FAILED(hrc))
|
---|
3030 | {
|
---|
3031 | LogRel(("NetworkAttachmentType_Bridged: COMGETTER(HostInterface) failed, hrc (0x%x)", hrc));
|
---|
3032 | H();
|
---|
3033 | }
|
---|
3034 |
|
---|
3035 | Utf8Str HifNameUtf8(HifName);
|
---|
3036 | const char *pszHifName = HifNameUtf8.raw();
|
---|
3037 |
|
---|
3038 | # if defined(RT_OS_DARWIN)
|
---|
3039 | /* The name is on the form 'ifX: long name', chop it off at the colon. */
|
---|
3040 | char szTrunk[8];
|
---|
3041 | strncpy(szTrunk, pszHifName, sizeof(szTrunk));
|
---|
3042 | char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
|
---|
3043 | if (!pszColon)
|
---|
3044 | {
|
---|
3045 | /*
|
---|
3046 | * Dynamic changing of attachment causes an attempt to configure
|
---|
3047 | * network with invalid host adapter (as it is must be changed before
|
---|
3048 | * the attachment), calling Detach here will cause a deadlock.
|
---|
3049 | * See #4750.
|
---|
3050 | * hrc = aNetworkAdapter->Detach(); H();
|
---|
3051 | */
|
---|
3052 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
3053 | N_("Malformed host interface networking name '%ls'"),
|
---|
3054 | HifName.raw());
|
---|
3055 | }
|
---|
3056 | *pszColon = '\0';
|
---|
3057 | const char *pszTrunk = szTrunk;
|
---|
3058 |
|
---|
3059 | # elif defined(RT_OS_SOLARIS)
|
---|
3060 | /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
|
---|
3061 | char szTrunk[256];
|
---|
3062 | strlcpy(szTrunk, pszHifName, sizeof(szTrunk));
|
---|
3063 | char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
|
---|
3064 |
|
---|
3065 | /*
|
---|
3066 | * Currently don't bother about malformed names here for the sake of people using
|
---|
3067 | * VBoxManage and setting only the NIC name from there. If there is a space we
|
---|
3068 | * chop it off and proceed, otherwise just use whatever we've got.
|
---|
3069 | */
|
---|
3070 | if (pszSpace)
|
---|
3071 | *pszSpace = '\0';
|
---|
3072 |
|
---|
3073 | /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
|
---|
3074 | char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
|
---|
3075 | if (pszColon)
|
---|
3076 | *pszColon = '\0';
|
---|
3077 |
|
---|
3078 | const char *pszTrunk = szTrunk;
|
---|
3079 |
|
---|
3080 | # elif defined(RT_OS_WINDOWS)
|
---|
3081 | ComPtr<IHostNetworkInterface> hostInterface;
|
---|
3082 | hrc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
|
---|
3083 | if (!SUCCEEDED(hrc))
|
---|
3084 | {
|
---|
3085 | AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: FindByName failed, rc=%Rhrc (0x%x)", hrc, hrc));
|
---|
3086 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
3087 | N_("Inexistent host networking interface, name '%ls'"),
|
---|
3088 | HifName.raw());
|
---|
3089 | }
|
---|
3090 |
|
---|
3091 | HostNetworkInterfaceType_T eIfType;
|
---|
3092 | hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
|
---|
3093 | if (FAILED(hrc))
|
---|
3094 | {
|
---|
3095 | LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
|
---|
3096 | H();
|
---|
3097 | }
|
---|
3098 |
|
---|
3099 | if (eIfType != HostNetworkInterfaceType_Bridged)
|
---|
3100 | {
|
---|
3101 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
3102 | N_("Interface ('%ls') is not a Bridged Adapter interface"),
|
---|
3103 | HifName.raw());
|
---|
3104 | }
|
---|
3105 |
|
---|
3106 | hrc = hostInterface->COMGETTER(Id)(bstr.asOutParam());
|
---|
3107 | if (FAILED(hrc))
|
---|
3108 | {
|
---|
3109 | LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
|
---|
3110 | H();
|
---|
3111 | }
|
---|
3112 | Guid hostIFGuid(bstr);
|
---|
3113 |
|
---|
3114 | INetCfg *pNc;
|
---|
3115 | ComPtr<INetCfgComponent> pAdaptorComponent;
|
---|
3116 | LPWSTR pszApp;
|
---|
3117 | int rc = VERR_INTNET_FLT_IF_NOT_FOUND;
|
---|
3118 |
|
---|
3119 | hrc = VBoxNetCfgWinQueryINetCfg(FALSE /*fGetWriteLock*/,
|
---|
3120 | L"VirtualBox",
|
---|
3121 | &pNc,
|
---|
3122 | &pszApp);
|
---|
3123 | Assert(hrc == S_OK);
|
---|
3124 | if (hrc == S_OK)
|
---|
3125 | {
|
---|
3126 | /* get the adapter's INetCfgComponent*/
|
---|
3127 | hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
|
---|
3128 | if (hrc != S_OK)
|
---|
3129 | {
|
---|
3130 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3131 | LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
|
---|
3132 | H();
|
---|
3133 | }
|
---|
3134 | }
|
---|
3135 | #define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
|
---|
3136 | char szTrunkName[INTNET_MAX_TRUNK_NAME];
|
---|
3137 | char *pszTrunkName = szTrunkName;
|
---|
3138 | wchar_t * pswzBindName;
|
---|
3139 | hrc = pAdaptorComponent->GetBindName(&pswzBindName);
|
---|
3140 | Assert(hrc == S_OK);
|
---|
3141 | if (hrc == S_OK)
|
---|
3142 | {
|
---|
3143 | int cwBindName = (int)wcslen(pswzBindName) + 1;
|
---|
3144 | int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
|
---|
3145 | if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
|
---|
3146 | {
|
---|
3147 | strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
|
---|
3148 | pszTrunkName += cbFullBindNamePrefix-1;
|
---|
3149 | if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
|
---|
3150 | sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
|
---|
3151 | {
|
---|
3152 | DWORD err = GetLastError();
|
---|
3153 | hrc = HRESULT_FROM_WIN32(err);
|
---|
3154 | AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
|
---|
3155 | AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
|
---|
3156 | }
|
---|
3157 | }
|
---|
3158 | else
|
---|
3159 | {
|
---|
3160 | AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
|
---|
3161 | /** @todo set appropriate error code */
|
---|
3162 | hrc = E_FAIL;
|
---|
3163 | }
|
---|
3164 |
|
---|
3165 | if (hrc != S_OK)
|
---|
3166 | {
|
---|
3167 | AssertFailed();
|
---|
3168 | CoTaskMemFree(pswzBindName);
|
---|
3169 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3170 | H();
|
---|
3171 | }
|
---|
3172 |
|
---|
3173 | /* we're not freeing the bind name since we'll use it later for detecting wireless*/
|
---|
3174 | }
|
---|
3175 | else
|
---|
3176 | {
|
---|
3177 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3178 | AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
|
---|
3179 | H();
|
---|
3180 | }
|
---|
3181 | const char *pszTrunk = szTrunkName;
|
---|
3182 | /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
|
---|
3183 |
|
---|
3184 | # elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
|
---|
3185 | # if defined(RT_OS_FREEBSD)
|
---|
3186 | /*
|
---|
3187 | * If we bridge to a tap interface open it the `old' direct way.
|
---|
3188 | * This works and performs better than bridging a physical
|
---|
3189 | * interface via the current FreeBSD vboxnetflt implementation.
|
---|
3190 | */
|
---|
3191 | if (!strncmp(pszHifName, "tap", sizeof "tap" - 1)) {
|
---|
3192 | hrc = attachToTapInterface(aNetworkAdapter);
|
---|
3193 | if (FAILED(hrc))
|
---|
3194 | {
|
---|
3195 | switch (hrc)
|
---|
3196 | {
|
---|
3197 | case VERR_ACCESS_DENIED:
|
---|
3198 | return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
|
---|
3199 | "Failed to open '/dev/%s' for read/write access. Please check the "
|
---|
3200 | "permissions of that node, and that the net.link.tap.user_open "
|
---|
3201 | "sysctl is set. Either run 'chmod 0666 /dev/%s' or "
|
---|
3202 | "change the group of that node to vboxusers and make yourself "
|
---|
3203 | "a member of that group. Make sure that these changes are permanent."), pszHifName, pszHifName);
|
---|
3204 | default:
|
---|
3205 | AssertMsgFailed(("Could not attach to tap interface! Bad!\n"));
|
---|
3206 | return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
|
---|
3207 | "Failed to initialize Host Interface Networking"));
|
---|
3208 | }
|
---|
3209 | }
|
---|
3210 |
|
---|
3211 | Assert((int)maTapFD[uInstance] >= 0);
|
---|
3212 | if ((int)maTapFD[uInstance] >= 0)
|
---|
3213 | {
|
---|
3214 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
|
---|
3215 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
3216 | rc = CFGMR3InsertInteger(pCfg, "FileHandle", maTapFD[uInstance]); RC_CHECK();
|
---|
3217 | }
|
---|
3218 | break;
|
---|
3219 | }
|
---|
3220 | # endif
|
---|
3221 | /** @todo Check for malformed names. */
|
---|
3222 | const char *pszTrunk = pszHifName;
|
---|
3223 |
|
---|
3224 | /* Issue a warning if the interface is down */
|
---|
3225 | {
|
---|
3226 | int iSock = socket(AF_INET, SOCK_DGRAM, 0);
|
---|
3227 | if (iSock >= 0)
|
---|
3228 | {
|
---|
3229 | struct ifreq Req;
|
---|
3230 |
|
---|
3231 | memset(&Req, 0, sizeof(Req));
|
---|
3232 | strncpy(Req.ifr_name, pszHifName, sizeof(Req.ifr_name) - 1);
|
---|
3233 | if (ioctl(iSock, SIOCGIFFLAGS, &Req) >= 0)
|
---|
3234 | if ((Req.ifr_flags & IFF_UP) == 0)
|
---|
3235 | {
|
---|
3236 | setVMRuntimeErrorCallbackF(pVM, this, 0, "BridgedInterfaceDown", "Bridged interface %s is down. Guest will not be able to use this interface", pszHifName);
|
---|
3237 | }
|
---|
3238 |
|
---|
3239 | close(iSock);
|
---|
3240 | }
|
---|
3241 | }
|
---|
3242 |
|
---|
3243 | # else
|
---|
3244 | # error "PORTME (VBOX_WITH_NETFLT)"
|
---|
3245 | # endif
|
---|
3246 |
|
---|
3247 | rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
|
---|
3248 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
3249 | rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
|
---|
3250 | rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
|
---|
3251 | RC_CHECK();
|
---|
3252 | char szNetwork[INTNET_MAX_NETWORK_NAME];
|
---|
3253 | RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
|
---|
3254 | rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
|
---|
3255 | networkName = Bstr(szNetwork);
|
---|
3256 | trunkName = Bstr(pszTrunk);
|
---|
3257 | trunkType = Bstr(TRUNKTYPE_NETFLT);
|
---|
3258 |
|
---|
3259 | # if defined(RT_OS_DARWIN)
|
---|
3260 | /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
|
---|
3261 | if ( strstr(pszHifName, "Wireless")
|
---|
3262 | || strstr(pszHifName, "AirPort" ))
|
---|
3263 | {
|
---|
3264 | rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
|
---|
3265 | }
|
---|
3266 | # elif defined(RT_OS_LINUX)
|
---|
3267 | int iSock = socket(AF_INET, SOCK_DGRAM, 0);
|
---|
3268 | if (iSock >= 0)
|
---|
3269 | {
|
---|
3270 | struct iwreq WRq;
|
---|
3271 |
|
---|
3272 | memset(&WRq, 0, sizeof(WRq));
|
---|
3273 | strncpy(WRq.ifr_name, pszHifName, IFNAMSIZ);
|
---|
3274 | bool fSharedMacOnWire = ioctl(iSock, SIOCGIWNAME, &WRq) >= 0;
|
---|
3275 | close(iSock);
|
---|
3276 | if (fSharedMacOnWire)
|
---|
3277 | {
|
---|
3278 | rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
|
---|
3279 | RC_CHECK();
|
---|
3280 | Log(("Set SharedMacOnWire\n"));
|
---|
3281 | }
|
---|
3282 | else
|
---|
3283 | Log(("Failed to get wireless name\n"));
|
---|
3284 | }
|
---|
3285 | else
|
---|
3286 | Log(("Failed to open wireless socket\n"));
|
---|
3287 | # elif defined(RT_OS_FREEBSD)
|
---|
3288 | int iSock = socket(AF_INET, SOCK_DGRAM, 0);
|
---|
3289 | if (iSock >= 0)
|
---|
3290 | {
|
---|
3291 | struct ieee80211req WReq;
|
---|
3292 | uint8_t abData[32];
|
---|
3293 |
|
---|
3294 | memset(&WReq, 0, sizeof(WReq));
|
---|
3295 | strncpy(WReq.i_name, pszHifName, sizeof(WReq.i_name));
|
---|
3296 | WReq.i_type = IEEE80211_IOC_SSID;
|
---|
3297 | WReq.i_val = -1;
|
---|
3298 | WReq.i_data = abData;
|
---|
3299 | WReq.i_len = sizeof(abData);
|
---|
3300 |
|
---|
3301 | bool fSharedMacOnWire = ioctl(iSock, SIOCG80211, &WReq) >= 0;
|
---|
3302 | close(iSock);
|
---|
3303 | if (fSharedMacOnWire)
|
---|
3304 | {
|
---|
3305 | rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true);
|
---|
3306 | RC_CHECK();
|
---|
3307 | Log(("Set SharedMacOnWire\n"));
|
---|
3308 | }
|
---|
3309 | else
|
---|
3310 | Log(("Failed to get wireless name\n"));
|
---|
3311 | }
|
---|
3312 | else
|
---|
3313 | Log(("Failed to open wireless socket\n"));
|
---|
3314 | # elif defined(RT_OS_WINDOWS)
|
---|
3315 | # define DEVNAME_PREFIX L"\\\\.\\"
|
---|
3316 | /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
|
---|
3317 | * there is a pretty long way till there though since we need to obtain the symbolic link name
|
---|
3318 | * for the adapter device we are going to query given the device Guid */
|
---|
3319 |
|
---|
3320 |
|
---|
3321 | /* prepend the "\\\\.\\" to the bind name to obtain the link name */
|
---|
3322 |
|
---|
3323 | wchar_t FileName[MAX_PATH];
|
---|
3324 | wcscpy(FileName, DEVNAME_PREFIX);
|
---|
3325 | wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
|
---|
3326 |
|
---|
3327 | /* open the device */
|
---|
3328 | HANDLE hDevice = CreateFile(FileName,
|
---|
3329 | GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
---|
3330 | NULL,
|
---|
3331 | OPEN_EXISTING,
|
---|
3332 | FILE_ATTRIBUTE_NORMAL,
|
---|
3333 | NULL);
|
---|
3334 |
|
---|
3335 | if (hDevice != INVALID_HANDLE_VALUE)
|
---|
3336 | {
|
---|
3337 | bool fSharedMacOnWire = false;
|
---|
3338 |
|
---|
3339 | /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
|
---|
3340 | DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
|
---|
3341 | NDIS_PHYSICAL_MEDIUM PhMedium;
|
---|
3342 | DWORD cbResult;
|
---|
3343 | if (DeviceIoControl(hDevice,
|
---|
3344 | IOCTL_NDIS_QUERY_GLOBAL_STATS,
|
---|
3345 | &Oid,
|
---|
3346 | sizeof(Oid),
|
---|
3347 | &PhMedium,
|
---|
3348 | sizeof(PhMedium),
|
---|
3349 | &cbResult,
|
---|
3350 | NULL))
|
---|
3351 | {
|
---|
3352 | /* that was simple, now examine PhMedium */
|
---|
3353 | if ( PhMedium == NdisPhysicalMediumWirelessWan
|
---|
3354 | || PhMedium == NdisPhysicalMediumWirelessLan
|
---|
3355 | || PhMedium == NdisPhysicalMediumNative802_11
|
---|
3356 | || PhMedium == NdisPhysicalMediumBluetooth)
|
---|
3357 | fSharedMacOnWire = true;
|
---|
3358 | }
|
---|
3359 | else
|
---|
3360 | {
|
---|
3361 | int winEr = GetLastError();
|
---|
3362 | LogRel(("Console::configConstructor: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
|
---|
3363 | Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
|
---|
3364 | }
|
---|
3365 | CloseHandle(hDevice);
|
---|
3366 |
|
---|
3367 | if (fSharedMacOnWire)
|
---|
3368 | {
|
---|
3369 | Log(("this is a wireless adapter"));
|
---|
3370 | rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
|
---|
3371 | Log(("Set SharedMacOnWire\n"));
|
---|
3372 | }
|
---|
3373 | else
|
---|
3374 | Log(("this is NOT a wireless adapter"));
|
---|
3375 | }
|
---|
3376 | else
|
---|
3377 | {
|
---|
3378 | int winEr = GetLastError();
|
---|
3379 | AssertLogRelMsgFailed(("Console::configConstructor: CreateFile failed, err (0x%x), ignoring\n", winEr));
|
---|
3380 | }
|
---|
3381 |
|
---|
3382 | CoTaskMemFree(pswzBindName);
|
---|
3383 |
|
---|
3384 | pAdaptorComponent.setNull();
|
---|
3385 | /* release the pNc finally */
|
---|
3386 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3387 | # else
|
---|
3388 | /** @todo PORTME: wireless detection */
|
---|
3389 | # endif
|
---|
3390 |
|
---|
3391 | # if defined(RT_OS_SOLARIS)
|
---|
3392 | # if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
|
---|
3393 | /* Zone access restriction, don't allow snopping the global zone. */
|
---|
3394 | zoneid_t ZoneId = getzoneid();
|
---|
3395 | if (ZoneId != GLOBAL_ZONEID)
|
---|
3396 | {
|
---|
3397 | rc = CFGMR3InsertInteger(pCfg, "IgnoreAllPromisc", true); RC_CHECK();
|
---|
3398 | }
|
---|
3399 | # endif
|
---|
3400 | # endif
|
---|
3401 |
|
---|
3402 | #elif defined(RT_OS_WINDOWS) /* not defined NetFlt */
|
---|
3403 | /* NOTHING TO DO HERE */
|
---|
3404 | #elif defined(RT_OS_LINUX)
|
---|
3405 | /// @todo aleksey: is there anything to be done here?
|
---|
3406 | #elif defined(RT_OS_FREEBSD)
|
---|
3407 | /** @todo FreeBSD: Check out this later (HIF networking). */
|
---|
3408 | #else
|
---|
3409 | # error "Port me"
|
---|
3410 | #endif
|
---|
3411 | break;
|
---|
3412 | }
|
---|
3413 |
|
---|
3414 | case NetworkAttachmentType_Internal:
|
---|
3415 | {
|
---|
3416 | hrc = aNetworkAdapter->COMGETTER(InternalNetwork)(bstr.asOutParam()); H();
|
---|
3417 | if (!bstr.isEmpty())
|
---|
3418 | {
|
---|
3419 | if (fSniffer)
|
---|
3420 | {
|
---|
3421 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
|
---|
3422 | RC_CHECK();
|
---|
3423 | }
|
---|
3424 | else
|
---|
3425 | {
|
---|
3426 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
|
---|
3427 | RC_CHECK();
|
---|
3428 | }
|
---|
3429 | rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
|
---|
3430 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
3431 | rc = CFGMR3InsertStringW(pCfg, "Network", bstr); RC_CHECK();
|
---|
3432 | rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone); RC_CHECK();
|
---|
3433 | networkName = bstr;
|
---|
3434 | trunkType = Bstr(TRUNKTYPE_WHATEVER);
|
---|
3435 | }
|
---|
3436 | break;
|
---|
3437 | }
|
---|
3438 |
|
---|
3439 | case NetworkAttachmentType_HostOnly:
|
---|
3440 | {
|
---|
3441 | if (fSniffer)
|
---|
3442 | {
|
---|
3443 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0);
|
---|
3444 | RC_CHECK();
|
---|
3445 | }
|
---|
3446 | else
|
---|
3447 | {
|
---|
3448 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0);
|
---|
3449 | RC_CHECK();
|
---|
3450 | }
|
---|
3451 |
|
---|
3452 | rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
|
---|
3453 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
3454 |
|
---|
3455 | Bstr HifName;
|
---|
3456 | hrc = aNetworkAdapter->COMGETTER(HostInterface)(HifName.asOutParam());
|
---|
3457 | if (FAILED(hrc))
|
---|
3458 | {
|
---|
3459 | LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostInterface) failed, hrc (0x%x)\n", hrc));
|
---|
3460 | H();
|
---|
3461 | }
|
---|
3462 |
|
---|
3463 | Utf8Str HifNameUtf8(HifName);
|
---|
3464 | const char *pszHifName = HifNameUtf8.raw();
|
---|
3465 | ComPtr<IHostNetworkInterface> hostInterface;
|
---|
3466 | rc = host->FindHostNetworkInterfaceByName(HifName, hostInterface.asOutParam());
|
---|
3467 | if (!SUCCEEDED(rc))
|
---|
3468 | {
|
---|
3469 | LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)\n", rc));
|
---|
3470 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
3471 | N_("Inexistent host networking interface, name '%ls'"),
|
---|
3472 | HifName.raw());
|
---|
3473 | }
|
---|
3474 |
|
---|
3475 | char szNetwork[INTNET_MAX_NETWORK_NAME];
|
---|
3476 | RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHifName);
|
---|
3477 |
|
---|
3478 | #if defined(RT_OS_WINDOWS)
|
---|
3479 | # ifndef VBOX_WITH_NETFLT
|
---|
3480 | hrc = E_NOTIMPL;
|
---|
3481 | LogRel(("NetworkAttachmentType_HostOnly: Not Implemented\n"));
|
---|
3482 | H();
|
---|
3483 | # else /* defined VBOX_WITH_NETFLT*/
|
---|
3484 | /** @todo r=bird: Put this in a function. */
|
---|
3485 |
|
---|
3486 | HostNetworkInterfaceType_T eIfType;
|
---|
3487 | hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
|
---|
3488 | if (FAILED(hrc))
|
---|
3489 | {
|
---|
3490 | LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)\n", hrc));
|
---|
3491 | H();
|
---|
3492 | }
|
---|
3493 |
|
---|
3494 | if (eIfType != HostNetworkInterfaceType_HostOnly)
|
---|
3495 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
3496 | N_("Interface ('%ls') is not a Host-Only Adapter interface"),
|
---|
3497 | HifName.raw());
|
---|
3498 |
|
---|
3499 | hrc = hostInterface->COMGETTER(Id)(bstr.asOutParam());
|
---|
3500 | if (FAILED(hrc))
|
---|
3501 | {
|
---|
3502 | LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)\n", hrc));
|
---|
3503 | H();
|
---|
3504 | }
|
---|
3505 | Guid hostIFGuid(bstr);
|
---|
3506 |
|
---|
3507 | INetCfg *pNc;
|
---|
3508 | ComPtr<INetCfgComponent> pAdaptorComponent;
|
---|
3509 | LPWSTR pszApp;
|
---|
3510 | rc = VERR_INTNET_FLT_IF_NOT_FOUND;
|
---|
3511 |
|
---|
3512 | hrc = VBoxNetCfgWinQueryINetCfg(FALSE,
|
---|
3513 | L"VirtualBox",
|
---|
3514 | &pNc,
|
---|
3515 | &pszApp);
|
---|
3516 | Assert(hrc == S_OK);
|
---|
3517 | if (hrc == S_OK)
|
---|
3518 | {
|
---|
3519 | /* get the adapter's INetCfgComponent*/
|
---|
3520 | hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.ptr(), pAdaptorComponent.asOutParam());
|
---|
3521 | if (hrc != S_OK)
|
---|
3522 | {
|
---|
3523 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3524 | LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
|
---|
3525 | H();
|
---|
3526 | }
|
---|
3527 | }
|
---|
3528 | #define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
|
---|
3529 | char szTrunkName[INTNET_MAX_TRUNK_NAME];
|
---|
3530 | char *pszTrunkName = szTrunkName;
|
---|
3531 | wchar_t * pswzBindName;
|
---|
3532 | hrc = pAdaptorComponent->GetBindName(&pswzBindName);
|
---|
3533 | Assert(hrc == S_OK);
|
---|
3534 | if (hrc == S_OK)
|
---|
3535 | {
|
---|
3536 | int cwBindName = (int)wcslen(pswzBindName) + 1;
|
---|
3537 | int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
|
---|
3538 | if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
|
---|
3539 | {
|
---|
3540 | strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
|
---|
3541 | pszTrunkName += cbFullBindNamePrefix-1;
|
---|
3542 | if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
|
---|
3543 | sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
|
---|
3544 | {
|
---|
3545 | DWORD err = GetLastError();
|
---|
3546 | hrc = HRESULT_FROM_WIN32(err);
|
---|
3547 | AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
|
---|
3548 | }
|
---|
3549 | }
|
---|
3550 | else
|
---|
3551 | {
|
---|
3552 | AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
|
---|
3553 | /** @todo set appropriate error code */
|
---|
3554 | hrc = E_FAIL;
|
---|
3555 | }
|
---|
3556 |
|
---|
3557 | if (hrc != S_OK)
|
---|
3558 | {
|
---|
3559 | AssertFailed();
|
---|
3560 | CoTaskMemFree(pswzBindName);
|
---|
3561 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3562 | H();
|
---|
3563 | }
|
---|
3564 | }
|
---|
3565 | else
|
---|
3566 | {
|
---|
3567 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3568 | AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
|
---|
3569 | H();
|
---|
3570 | }
|
---|
3571 |
|
---|
3572 |
|
---|
3573 | CoTaskMemFree(pswzBindName);
|
---|
3574 |
|
---|
3575 | pAdaptorComponent.setNull();
|
---|
3576 | /* release the pNc finally */
|
---|
3577 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
|
---|
3578 |
|
---|
3579 | const char *pszTrunk = szTrunkName;
|
---|
3580 |
|
---|
3581 | rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
|
---|
3582 | rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
|
---|
3583 | rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
|
---|
3584 | networkName = Bstr(szNetwork);
|
---|
3585 | trunkName = Bstr(pszTrunk);
|
---|
3586 | trunkType = TRUNKTYPE_NETADP;
|
---|
3587 | # endif /* defined VBOX_WITH_NETFLT*/
|
---|
3588 | #elif defined(RT_OS_DARWIN)
|
---|
3589 | rc = CFGMR3InsertString(pCfg, "Trunk", pszHifName); RC_CHECK();
|
---|
3590 | rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
|
---|
3591 | rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp); RC_CHECK();
|
---|
3592 | networkName = Bstr(szNetwork);
|
---|
3593 | trunkName = Bstr(pszHifName);
|
---|
3594 | trunkType = TRUNKTYPE_NETADP;
|
---|
3595 | #else
|
---|
3596 | rc = CFGMR3InsertString(pCfg, "Trunk", pszHifName); RC_CHECK();
|
---|
3597 | rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
|
---|
3598 | rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
|
---|
3599 | networkName = Bstr(szNetwork);
|
---|
3600 | trunkName = Bstr(pszHifName);
|
---|
3601 | trunkType = TRUNKTYPE_NETFLT;
|
---|
3602 | #endif
|
---|
3603 | #if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
|
---|
3604 |
|
---|
3605 | Bstr tmpAddr, tmpMask;
|
---|
3606 |
|
---|
3607 | hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPAddress", pszHifName), tmpAddr.asOutParam());
|
---|
3608 | if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
|
---|
3609 | {
|
---|
3610 | hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPNetMask", pszHifName), tmpMask.asOutParam());
|
---|
3611 | if (SUCCEEDED(hrc) && !tmpMask.isEmpty())
|
---|
3612 | hrc = hostInterface->EnableStaticIpConfig(tmpAddr, tmpMask);
|
---|
3613 | else
|
---|
3614 | hrc = hostInterface->EnableStaticIpConfig(tmpAddr,
|
---|
3615 | Bstr(VBOXNET_IPV4MASK_DEFAULT));
|
---|
3616 | }
|
---|
3617 | else
|
---|
3618 | {
|
---|
3619 | /* Grab the IP number from the 'vboxnetX' instance number (see netif.h) */
|
---|
3620 | hrc = hostInterface->EnableStaticIpConfig(getDefaultIPv4Address(Bstr(pszHifName)),
|
---|
3621 | Bstr(VBOXNET_IPV4MASK_DEFAULT));
|
---|
3622 | }
|
---|
3623 |
|
---|
3624 | ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
|
---|
3625 |
|
---|
3626 | hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6Address", pszHifName), tmpAddr.asOutParam());
|
---|
3627 | if (SUCCEEDED(hrc))
|
---|
3628 | hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6NetMask", pszHifName), tmpMask.asOutParam());
|
---|
3629 | if (SUCCEEDED(hrc) && !tmpAddr.isEmpty() && !tmpMask.isEmpty())
|
---|
3630 | {
|
---|
3631 | hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr, Utf8Str(tmpMask).toUInt32());
|
---|
3632 | ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
|
---|
3633 | }
|
---|
3634 | #endif
|
---|
3635 | break;
|
---|
3636 | }
|
---|
3637 |
|
---|
3638 | #if defined(VBOX_WITH_VDE)
|
---|
3639 | case NetworkAttachmentType_VDE:
|
---|
3640 | {
|
---|
3641 | hrc = aNetworkAdapter->COMGETTER(VDENetwork)(bstr.asOutParam()); H();
|
---|
3642 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
3643 | rc = CFGMR3InsertString(pLunL0, "Driver", "VDE"); RC_CHECK();
|
---|
3644 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
3645 | if (!bstr.isEmpty())
|
---|
3646 | {
|
---|
3647 | rc = CFGMR3InsertStringW(pCfg, "Network", bstr); RC_CHECK();
|
---|
3648 | networkName = bstr;
|
---|
3649 | }
|
---|
3650 | break;
|
---|
3651 | }
|
---|
3652 | #endif
|
---|
3653 |
|
---|
3654 | default:
|
---|
3655 | AssertMsgFailed(("should not get here!\n"));
|
---|
3656 | break;
|
---|
3657 | }
|
---|
3658 |
|
---|
3659 | /*
|
---|
3660 | * Attempt to attach the driver.
|
---|
3661 | */
|
---|
3662 | switch (eAttachmentType)
|
---|
3663 | {
|
---|
3664 | case NetworkAttachmentType_Null:
|
---|
3665 | break;
|
---|
3666 |
|
---|
3667 | case NetworkAttachmentType_Bridged:
|
---|
3668 | case NetworkAttachmentType_Internal:
|
---|
3669 | case NetworkAttachmentType_HostOnly:
|
---|
3670 | case NetworkAttachmentType_NAT:
|
---|
3671 | #if defined(VBOX_WITH_VDE)
|
---|
3672 | case NetworkAttachmentType_VDE:
|
---|
3673 | #endif
|
---|
3674 | {
|
---|
3675 | if (SUCCEEDED(hrc) && SUCCEEDED(rc))
|
---|
3676 | {
|
---|
3677 | if (fAttachDetach)
|
---|
3678 | {
|
---|
3679 | rc = PDMR3DriverAttach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /* ppBase */);
|
---|
3680 | //AssertRC(rc);
|
---|
3681 | }
|
---|
3682 |
|
---|
3683 | {
|
---|
3684 | /** @todo pritesh: get the dhcp server name from the
|
---|
3685 | * previous network configuration and then stop the server
|
---|
3686 | * else it may conflict with the dhcp server running with
|
---|
3687 | * the current attachment type
|
---|
3688 | */
|
---|
3689 | /* Stop the hostonly DHCP Server */
|
---|
3690 | }
|
---|
3691 |
|
---|
3692 | if (!networkName.isEmpty())
|
---|
3693 | {
|
---|
3694 | /*
|
---|
3695 | * Until we implement service reference counters DHCP Server will be stopped
|
---|
3696 | * by DHCPServerRunner destructor.
|
---|
3697 | */
|
---|
3698 | ComPtr<IDHCPServer> dhcpServer;
|
---|
3699 | hrc = virtualBox->FindDHCPServerByNetworkName(networkName, dhcpServer.asOutParam());
|
---|
3700 | if (SUCCEEDED(hrc))
|
---|
3701 | {
|
---|
3702 | /* there is a DHCP server available for this network */
|
---|
3703 | BOOL fEnabled;
|
---|
3704 | hrc = dhcpServer->COMGETTER(Enabled)(&fEnabled);
|
---|
3705 | if (FAILED(hrc))
|
---|
3706 | {
|
---|
3707 | LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (%Rhrc)", hrc));
|
---|
3708 | H();
|
---|
3709 | }
|
---|
3710 |
|
---|
3711 | if (fEnabled)
|
---|
3712 | hrc = dhcpServer->Start(networkName, trunkName, trunkType);
|
---|
3713 | }
|
---|
3714 | else
|
---|
3715 | hrc = S_OK;
|
---|
3716 | }
|
---|
3717 | }
|
---|
3718 |
|
---|
3719 | break;
|
---|
3720 | }
|
---|
3721 |
|
---|
3722 | default:
|
---|
3723 | AssertMsgFailed(("should not get here!\n"));
|
---|
3724 | break;
|
---|
3725 | }
|
---|
3726 |
|
---|
3727 | meAttachmentType[uInstance] = eAttachmentType;
|
---|
3728 |
|
---|
3729 | #undef H
|
---|
3730 | #undef RC_CHECK
|
---|
3731 |
|
---|
3732 | return VINF_SUCCESS;
|
---|
3733 | }
|
---|
3734 |
|
---|
3735 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
3736 | /**
|
---|
3737 | * Set an array of guest properties
|
---|
3738 | */
|
---|
3739 | static void configSetProperties(VMMDev * const pVMMDev, void *names,
|
---|
3740 | void *values, void *timestamps, void *flags)
|
---|
3741 | {
|
---|
3742 | VBOXHGCMSVCPARM parms[4];
|
---|
3743 |
|
---|
3744 | parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3745 | parms[0].u.pointer.addr = names;
|
---|
3746 | parms[0].u.pointer.size = 0; /* We don't actually care. */
|
---|
3747 | parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3748 | parms[1].u.pointer.addr = values;
|
---|
3749 | parms[1].u.pointer.size = 0; /* We don't actually care. */
|
---|
3750 | parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3751 | parms[2].u.pointer.addr = timestamps;
|
---|
3752 | parms[2].u.pointer.size = 0; /* We don't actually care. */
|
---|
3753 | parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3754 | parms[3].u.pointer.addr = flags;
|
---|
3755 | parms[3].u.pointer.size = 0; /* We don't actually care. */
|
---|
3756 |
|
---|
3757 | pVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_PROPS_HOST, 4,
|
---|
3758 | &parms[0]);
|
---|
3759 | }
|
---|
3760 |
|
---|
3761 | /**
|
---|
3762 | * Set a single guest property
|
---|
3763 | */
|
---|
3764 | static void configSetProperty(VMMDev * const pVMMDev, const char *pszName,
|
---|
3765 | const char *pszValue, const char *pszFlags)
|
---|
3766 | {
|
---|
3767 | VBOXHGCMSVCPARM parms[4];
|
---|
3768 |
|
---|
3769 | AssertPtrReturnVoid(pszName);
|
---|
3770 | AssertPtrReturnVoid(pszValue);
|
---|
3771 | AssertPtrReturnVoid(pszFlags);
|
---|
3772 | parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3773 | parms[0].u.pointer.addr = (void *)pszName;
|
---|
3774 | parms[0].u.pointer.size = strlen(pszName) + 1;
|
---|
3775 | parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3776 | parms[1].u.pointer.addr = (void *)pszValue;
|
---|
3777 | parms[1].u.pointer.size = strlen(pszValue) + 1;
|
---|
3778 | parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3779 | parms[2].u.pointer.addr = (void *)pszFlags;
|
---|
3780 | parms[2].u.pointer.size = strlen(pszFlags) + 1;
|
---|
3781 | pVMMDev->hgcmHostCall("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3,
|
---|
3782 | &parms[0]);
|
---|
3783 | }
|
---|
3784 |
|
---|
3785 | /**
|
---|
3786 | * Set the global flags value by calling the service
|
---|
3787 | * @returns the status returned by the call to the service
|
---|
3788 | *
|
---|
3789 | * @param pTable the service instance handle
|
---|
3790 | * @param eFlags the flags to set
|
---|
3791 | */
|
---|
3792 | int configSetGlobalPropertyFlags(VMMDev * const pVMMDev,
|
---|
3793 | guestProp::ePropFlags eFlags)
|
---|
3794 | {
|
---|
3795 | VBOXHGCMSVCPARM paParm;
|
---|
3796 | paParm.setUInt32(eFlags);
|
---|
3797 | int rc = pVMMDev->hgcmHostCall("VBoxGuestPropSvc",
|
---|
3798 | guestProp::SET_GLOBAL_FLAGS_HOST, 1,
|
---|
3799 | &paParm);
|
---|
3800 | if (RT_FAILURE(rc))
|
---|
3801 | {
|
---|
3802 | char szFlags[guestProp::MAX_FLAGS_LEN];
|
---|
3803 | if (RT_FAILURE(writeFlags(eFlags, szFlags)))
|
---|
3804 | Log(("Failed to set the global flags.\n"));
|
---|
3805 | else
|
---|
3806 | Log(("Failed to set the global flags \"%s\".\n", szFlags));
|
---|
3807 | }
|
---|
3808 | return rc;
|
---|
3809 | }
|
---|
3810 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
3811 |
|
---|
3812 | /**
|
---|
3813 | * Set up the Guest Property service, populate it with properties read from
|
---|
3814 | * the machine XML and set a couple of initial properties.
|
---|
3815 | */
|
---|
3816 | /* static */ int Console::configGuestProperties(void *pvConsole)
|
---|
3817 | {
|
---|
3818 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
3819 | AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
|
---|
3820 | ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
|
---|
3821 |
|
---|
3822 | /* Load the service */
|
---|
3823 | int rc = pConsole->mVMMDev->hgcmLoadService("VBoxGuestPropSvc", "VBoxGuestPropSvc");
|
---|
3824 |
|
---|
3825 | if (RT_FAILURE(rc))
|
---|
3826 | {
|
---|
3827 | LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
|
---|
3828 | /* That is not a fatal failure. */
|
---|
3829 | rc = VINF_SUCCESS;
|
---|
3830 | }
|
---|
3831 | else
|
---|
3832 | {
|
---|
3833 | /*
|
---|
3834 | * Initialize built-in properties that can be changed and saved.
|
---|
3835 | *
|
---|
3836 | * These are typically transient properties that the guest cannot
|
---|
3837 | * change.
|
---|
3838 | */
|
---|
3839 |
|
---|
3840 | /* Sysprep execution by VBoxService. */
|
---|
3841 | configSetProperty(pConsole->mVMMDev,
|
---|
3842 | "/VirtualBox/HostGuest/SysprepExec", "",
|
---|
3843 | "TRANSIENT, RDONLYGUEST");
|
---|
3844 | configSetProperty(pConsole->mVMMDev,
|
---|
3845 | "/VirtualBox/HostGuest/SysprepArgs", "",
|
---|
3846 | "TRANSIENT, RDONLYGUEST");
|
---|
3847 |
|
---|
3848 | /*
|
---|
3849 | * Pull over the properties from the server.
|
---|
3850 | */
|
---|
3851 | SafeArray<BSTR> namesOut;
|
---|
3852 | SafeArray<BSTR> valuesOut;
|
---|
3853 | SafeArray<ULONG64> timestampsOut;
|
---|
3854 | SafeArray<BSTR> flagsOut;
|
---|
3855 | HRESULT hrc;
|
---|
3856 | hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
|
---|
3857 | ComSafeArrayAsOutParam(valuesOut),
|
---|
3858 | ComSafeArrayAsOutParam(timestampsOut),
|
---|
3859 | ComSafeArrayAsOutParam(flagsOut));
|
---|
3860 | AssertMsgReturn(SUCCEEDED(hrc), ("hrc=%Rrc\n", hrc), VERR_GENERAL_FAILURE);
|
---|
3861 | size_t cProps = namesOut.size();
|
---|
3862 | size_t cAlloc = cProps + 1;
|
---|
3863 | if ( valuesOut.size() != cProps
|
---|
3864 | || timestampsOut.size() != cProps
|
---|
3865 | || flagsOut.size() != cProps
|
---|
3866 | )
|
---|
3867 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
3868 |
|
---|
3869 | char **papszNames, **papszValues, **papszFlags;
|
---|
3870 | char szEmpty[] = "";
|
---|
3871 | ULONG64 *pau64Timestamps;
|
---|
3872 | papszNames = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
|
---|
3873 | papszValues = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
|
---|
3874 | pau64Timestamps = (ULONG64 *)RTMemTmpAllocZ(sizeof(ULONG64) * cAlloc);
|
---|
3875 | papszFlags = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
|
---|
3876 | if (papszNames && papszValues && pau64Timestamps && papszFlags)
|
---|
3877 | {
|
---|
3878 | for (unsigned i = 0; RT_SUCCESS(rc) && i < cProps; ++i)
|
---|
3879 | {
|
---|
3880 | AssertPtrReturn(namesOut[i], VERR_INVALID_PARAMETER);
|
---|
3881 | rc = RTUtf16ToUtf8(namesOut[i], &papszNames[i]);
|
---|
3882 | if (RT_FAILURE(rc))
|
---|
3883 | break;
|
---|
3884 | if (valuesOut[i])
|
---|
3885 | rc = RTUtf16ToUtf8(valuesOut[i], &papszValues[i]);
|
---|
3886 | else
|
---|
3887 | papszValues[i] = szEmpty;
|
---|
3888 | if (RT_FAILURE(rc))
|
---|
3889 | break;
|
---|
3890 | pau64Timestamps[i] = timestampsOut[i];
|
---|
3891 | if (flagsOut[i])
|
---|
3892 | rc = RTUtf16ToUtf8(flagsOut[i], &papszFlags[i]);
|
---|
3893 | else
|
---|
3894 | papszFlags[i] = szEmpty;
|
---|
3895 | }
|
---|
3896 | if (RT_SUCCESS(rc))
|
---|
3897 | configSetProperties(pConsole->mVMMDev,
|
---|
3898 | (void *)papszNames,
|
---|
3899 | (void *)papszValues,
|
---|
3900 | (void *)pau64Timestamps,
|
---|
3901 | (void *)papszFlags);
|
---|
3902 | for (unsigned i = 0; i < cProps; ++i)
|
---|
3903 | {
|
---|
3904 | RTStrFree(papszNames[i]);
|
---|
3905 | if (valuesOut[i])
|
---|
3906 | RTStrFree(papszValues[i]);
|
---|
3907 | if (flagsOut[i])
|
---|
3908 | RTStrFree(papszFlags[i]);
|
---|
3909 | }
|
---|
3910 | }
|
---|
3911 | else
|
---|
3912 | rc = VERR_NO_MEMORY;
|
---|
3913 | RTMemTmpFree(papszNames);
|
---|
3914 | RTMemTmpFree(papszValues);
|
---|
3915 | RTMemTmpFree(pau64Timestamps);
|
---|
3916 | RTMemTmpFree(papszFlags);
|
---|
3917 | AssertRCReturn(rc, rc);
|
---|
3918 |
|
---|
3919 | /*
|
---|
3920 | * These properties have to be set before pulling over the properties
|
---|
3921 | * from the machine XML, to ensure that properties saved in the XML
|
---|
3922 | * will override them.
|
---|
3923 | */
|
---|
3924 | /* Set the VBox version string as a guest property */
|
---|
3925 | configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxVer",
|
---|
3926 | VBOX_VERSION_STRING, "TRANSIENT, RDONLYGUEST");
|
---|
3927 | /* Set the VBox SVN revision as a guest property */
|
---|
3928 | configSetProperty(pConsole->mVMMDev, "/VirtualBox/HostInfo/VBoxRev",
|
---|
3929 | RTBldCfgRevisionStr(), "TRANSIENT, RDONLYGUEST");
|
---|
3930 |
|
---|
3931 | /*
|
---|
3932 | * Register the host notification callback
|
---|
3933 | */
|
---|
3934 | HGCMSVCEXTHANDLE hDummy;
|
---|
3935 | HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestPropSvc",
|
---|
3936 | Console::doGuestPropNotification,
|
---|
3937 | pvConsole);
|
---|
3938 |
|
---|
3939 | #ifdef VBOX_WITH_GUEST_PROPS_RDONLY_GUEST
|
---|
3940 | rc = configSetGlobalPropertyFlags(pConsole->mVMMDev,
|
---|
3941 | guestProp::RDONLYGUEST);
|
---|
3942 | AssertRCReturn(rc, rc);
|
---|
3943 | #endif
|
---|
3944 |
|
---|
3945 | Log(("Set VBoxGuestPropSvc property store\n"));
|
---|
3946 | }
|
---|
3947 | return VINF_SUCCESS;
|
---|
3948 | #else /* !VBOX_WITH_GUEST_PROPS */
|
---|
3949 | return VERR_NOT_SUPPORTED;
|
---|
3950 | #endif /* !VBOX_WITH_GUEST_PROPS */
|
---|
3951 | }
|
---|
3952 |
|
---|
3953 | /**
|
---|
3954 | * Set up the Guest Control service.
|
---|
3955 | */
|
---|
3956 | /* static */ int Console::configGuestControl(void *pvConsole)
|
---|
3957 | {
|
---|
3958 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
3959 | AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
|
---|
3960 | ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
|
---|
3961 |
|
---|
3962 | /* Load the service */
|
---|
3963 | int rc = pConsole->mVMMDev->hgcmLoadService("VBoxGuestControlSvc", "VBoxGuestControlSvc");
|
---|
3964 |
|
---|
3965 | if (RT_FAILURE(rc))
|
---|
3966 | {
|
---|
3967 | LogRel(("VBoxGuestControlSvc is not available. rc = %Rrc\n", rc));
|
---|
3968 | /* That is not a fatal failure. */
|
---|
3969 | rc = VINF_SUCCESS;
|
---|
3970 | }
|
---|
3971 | else
|
---|
3972 | {
|
---|
3973 | HGCMSVCEXTHANDLE hDummy;
|
---|
3974 | rc = HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestControlSvc",
|
---|
3975 | &Guest::doGuestCtrlNotification,
|
---|
3976 | pConsole->getGuest());
|
---|
3977 | if (RT_FAILURE(rc))
|
---|
3978 | Log(("Cannot register VBoxGuestControlSvc extension!\n"));
|
---|
3979 | else
|
---|
3980 | Log(("VBoxGuestControlSvc loaded\n"));
|
---|
3981 | }
|
---|
3982 |
|
---|
3983 | return rc;
|
---|
3984 | #else /* !VBOX_WITH_GUEST_CONTROL */
|
---|
3985 | return VERR_NOT_SUPPORTED;
|
---|
3986 | #endif /* !VBOX_WITH_GUEST_CONTROL */
|
---|
3987 | }
|
---|