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