1 | /* $Id: ConsoleImpl2.cpp 12911 2008-10-02 09:40:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Console COM Class implementation
|
---|
4 | *
|
---|
5 | * @remark We've split out the code that the 64-bit VC++ v8 compiler
|
---|
6 | * finds problematic to optimize so we can disable optimizations
|
---|
7 | * and later, perhaps, find a real solution for it.
|
---|
8 | */
|
---|
9 |
|
---|
10 | /*
|
---|
11 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
12 | *
|
---|
13 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
14 | * available from http://www.virtualbox.org. This file is free software;
|
---|
15 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
16 | * General Public License (GPL) as published by the Free Software
|
---|
17 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
18 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
19 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
20 | *
|
---|
21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
22 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
23 | * additional information or have any questions.
|
---|
24 | */
|
---|
25 |
|
---|
26 | /*******************************************************************************
|
---|
27 | * Header Files *
|
---|
28 | *******************************************************************************/
|
---|
29 | #include "ConsoleImpl.h"
|
---|
30 | #include "DisplayImpl.h"
|
---|
31 | #include "VMMDev.h"
|
---|
32 |
|
---|
33 | // generated header
|
---|
34 | #include "SchemaDefs.h"
|
---|
35 |
|
---|
36 | #include "Logging.h"
|
---|
37 |
|
---|
38 | #include <iprt/string.h>
|
---|
39 | #include <iprt/path.h>
|
---|
40 | #include <iprt/dir.h>
|
---|
41 | #include <iprt/param.h>
|
---|
42 |
|
---|
43 | #include <VBox/vmapi.h>
|
---|
44 | #include <VBox/err.h>
|
---|
45 | #include <VBox/version.h>
|
---|
46 | #include <VBox/HostServices/VBoxClipboardSvc.h>
|
---|
47 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
48 | # include <VBox/HostServices/GuestPropertySvc.h>
|
---|
49 | # include <VBox/com/defs.h>
|
---|
50 | # include <VBox/com/array.h>
|
---|
51 | #endif /* VBOX_WITH_GUEST_PROPS */
|
---|
52 | #include <VBox/intnet.h>
|
---|
53 |
|
---|
54 |
|
---|
55 | /*
|
---|
56 | * VC++ 8 / amd64 has some serious trouble with this function.
|
---|
57 | * As a temporary measure, we'll drop global optimizations.
|
---|
58 | */
|
---|
59 | #if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
|
---|
60 | # pragma optimize("g", off)
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Construct the VM configuration tree (CFGM).
|
---|
65 | *
|
---|
66 | * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
|
---|
67 | * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
|
---|
68 | * is done here.
|
---|
69 | *
|
---|
70 | * @param pVM VM handle.
|
---|
71 | * @param pvConsole Pointer to the VMPowerUpTask object.
|
---|
72 | * @return VBox status code.
|
---|
73 | *
|
---|
74 | * @note Locks the Console object for writing.
|
---|
75 | */
|
---|
76 | DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
|
---|
77 | {
|
---|
78 | LogFlowFuncEnter();
|
---|
79 | /* Note: hardcoded assumption about number of slots; see rom bios */
|
---|
80 | bool afPciDeviceNo[15] = {false};
|
---|
81 |
|
---|
82 | #if !defined (VBOX_WITH_XPCOM)
|
---|
83 | {
|
---|
84 | /* initialize COM */
|
---|
85 | HRESULT hrc = CoInitializeEx(NULL,
|
---|
86 | COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE |
|
---|
87 | COINIT_SPEED_OVER_MEMORY);
|
---|
88 | LogFlow (("Console::configConstructor(): CoInitializeEx()=%08X\n", hrc));
|
---|
89 | AssertComRCReturn (hrc, VERR_GENERAL_FAILURE);
|
---|
90 | }
|
---|
91 | #endif
|
---|
92 |
|
---|
93 | AssertReturn (pvConsole, VERR_GENERAL_FAILURE);
|
---|
94 | ComObjPtr <Console> pConsole = static_cast <Console *> (pvConsole);
|
---|
95 |
|
---|
96 | AutoCaller autoCaller (pConsole);
|
---|
97 | AssertComRCReturn (autoCaller.rc(), VERR_ACCESS_DENIED);
|
---|
98 |
|
---|
99 | /* lock the console because we widely use internal fields and methods */
|
---|
100 | AutoWriteLock alock (pConsole);
|
---|
101 |
|
---|
102 | ComPtr <IMachine> pMachine = pConsole->machine();
|
---|
103 |
|
---|
104 | int rc;
|
---|
105 | HRESULT hrc;
|
---|
106 | char *psz = NULL;
|
---|
107 | BSTR str = NULL;
|
---|
108 |
|
---|
109 | #define STR_CONV() do { rc = RTUtf16ToUtf8(str, &psz); RC_CHECK(); } while (0)
|
---|
110 | #define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } if (psz) { RTStrFree(psz); psz = NULL; } } while (0)
|
---|
111 | #define RC_CHECK() do { if (VBOX_FAILURE(rc)) { AssertMsgFailed(("rc=%Vrc\n", rc)); STR_FREE(); return rc; } } while (0)
|
---|
112 | #define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
|
---|
113 |
|
---|
114 | /*
|
---|
115 | * Get necessary objects and frequently used parameters.
|
---|
116 | */
|
---|
117 | ComPtr<IVirtualBox> virtualBox;
|
---|
118 | hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
|
---|
119 |
|
---|
120 | ComPtr<IHost> host;
|
---|
121 | hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
|
---|
122 |
|
---|
123 | ComPtr <ISystemProperties> systemProperties;
|
---|
124 | hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
|
---|
125 |
|
---|
126 | ComPtr<IBIOSSettings> biosSettings;
|
---|
127 | hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
|
---|
128 |
|
---|
129 | Guid uuid;
|
---|
130 | hrc = pMachine->COMGETTER(Id)(uuid.asOutParam()); H();
|
---|
131 | PCRTUUID pUuid = uuid.raw();
|
---|
132 |
|
---|
133 | ULONG cRamMBs;
|
---|
134 | hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
|
---|
135 |
|
---|
136 | #ifdef VBOX_WITH_SMP_GUESTS
|
---|
137 | /* @todo nike: Testing code, should use actual getter when ready */
|
---|
138 | uint16_t cCpus = 2;
|
---|
139 | #else
|
---|
140 | uint16_t cCpus = 1;
|
---|
141 | #endif
|
---|
142 |
|
---|
143 | /*
|
---|
144 | * Get root node first.
|
---|
145 | * This is the only node in the tree.
|
---|
146 | */
|
---|
147 | PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
|
---|
148 | Assert(pRoot);
|
---|
149 |
|
---|
150 | /*
|
---|
151 | * Set the root level values.
|
---|
152 | */
|
---|
153 | hrc = pMachine->COMGETTER(Name)(&str); H();
|
---|
154 | STR_CONV();
|
---|
155 | rc = CFGMR3InsertString(pRoot, "Name", psz); RC_CHECK();
|
---|
156 | STR_FREE();
|
---|
157 | rc = CFGMR3InsertBytes(pRoot, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
|
---|
158 | rc = CFGMR3InsertInteger(pRoot, "RamSize", cRamMBs * _1M); RC_CHECK();
|
---|
159 | rc = CFGMR3InsertInteger(pRoot, "NumCPUs", cCpus); RC_CHECK();
|
---|
160 | rc = CFGMR3InsertInteger(pRoot, "TimerMillies", 10); RC_CHECK();
|
---|
161 | rc = CFGMR3InsertInteger(pRoot, "RawR3Enabled", 1); /* boolean */ RC_CHECK();
|
---|
162 | rc = CFGMR3InsertInteger(pRoot, "RawR0Enabled", 1); /* boolean */ RC_CHECK();
|
---|
163 | /** @todo Config: RawR0, PATMEnabled and CASMEnabled needs attention later. */
|
---|
164 | rc = CFGMR3InsertInteger(pRoot, "PATMEnabled", 1); /* boolean */ RC_CHECK();
|
---|
165 | rc = CFGMR3InsertInteger(pRoot, "CSAMEnabled", 1); /* boolean */ RC_CHECK();
|
---|
166 |
|
---|
167 | /* hardware virtualization extensions */
|
---|
168 | TSBool_T hwVirtExEnabled;
|
---|
169 | BOOL fHWVirtExEnabled;
|
---|
170 | hrc = pMachine->COMGETTER(HWVirtExEnabled)(&hwVirtExEnabled); H();
|
---|
171 | if (hwVirtExEnabled == TSBool_Default)
|
---|
172 | {
|
---|
173 | /* check the default value */
|
---|
174 | hrc = systemProperties->COMGETTER(HWVirtExEnabled)(&fHWVirtExEnabled); H();
|
---|
175 | }
|
---|
176 | else
|
---|
177 | fHWVirtExEnabled = (hwVirtExEnabled == TSBool_True);
|
---|
178 | #ifndef RT_OS_DARWIN /** @todo Implement HWVirtExt on darwin. See #1865. */
|
---|
179 | if (fHWVirtExEnabled)
|
---|
180 | {
|
---|
181 | PCFGMNODE pHWVirtExt;
|
---|
182 | rc = CFGMR3InsertNode(pRoot, "HWVirtExt", &pHWVirtExt); RC_CHECK();
|
---|
183 | rc = CFGMR3InsertInteger(pHWVirtExt, "Enabled", 1); RC_CHECK();
|
---|
184 | }
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | /* Nested paging (VT-x/AMD-V) */
|
---|
188 | BOOL fEnableNestedPaging = false;
|
---|
189 | hrc = pMachine->COMGETTER(HWVirtExNestedPagingEnabled)(&fEnableNestedPaging); H();
|
---|
190 | rc = CFGMR3InsertInteger(pRoot, "EnableNestedPaging", fEnableNestedPaging); RC_CHECK();
|
---|
191 |
|
---|
192 | /* Physical Address Extension (PAE) */
|
---|
193 | BOOL fEnablePAE = false;
|
---|
194 | hrc = pMachine->COMGETTER(PAEEnabled)(&fEnablePAE); H();
|
---|
195 | rc = CFGMR3InsertInteger(pRoot, "EnablePAE", fEnablePAE); RC_CHECK();
|
---|
196 |
|
---|
197 | BOOL fIOAPIC;
|
---|
198 | hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
|
---|
199 |
|
---|
200 | BOOL fPXEDebug;
|
---|
201 | hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
|
---|
202 |
|
---|
203 | /*
|
---|
204 | * Virtual IDE controller type.
|
---|
205 | */
|
---|
206 | IDEControllerType_T controllerType;
|
---|
207 | BOOL fPIIX4;
|
---|
208 | hrc = biosSettings->COMGETTER(IDEControllerType)(&controllerType); H();
|
---|
209 | switch (controllerType)
|
---|
210 | {
|
---|
211 | case IDEControllerType_PIIX3:
|
---|
212 | fPIIX4 = FALSE;
|
---|
213 | break;
|
---|
214 | case IDEControllerType_PIIX4:
|
---|
215 | fPIIX4 = TRUE;
|
---|
216 | break;
|
---|
217 | default:
|
---|
218 | AssertMsgFailed(("Invalid IDE controller type '%d'", controllerType));
|
---|
219 | return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
|
---|
220 | N_("Invalid IDE controller type '%d'"), controllerType);
|
---|
221 | }
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * PDM config.
|
---|
225 | * Load drivers in VBoxC.[so|dll]
|
---|
226 | */
|
---|
227 | PCFGMNODE pPDM;
|
---|
228 | PCFGMNODE pDrivers;
|
---|
229 | PCFGMNODE pMod;
|
---|
230 | rc = CFGMR3InsertNode(pRoot, "PDM", &pPDM); RC_CHECK();
|
---|
231 | rc = CFGMR3InsertNode(pPDM, "Drivers", &pDrivers); RC_CHECK();
|
---|
232 | rc = CFGMR3InsertNode(pDrivers, "VBoxC", &pMod); RC_CHECK();
|
---|
233 | #ifdef VBOX_WITH_XPCOM
|
---|
234 | // VBoxC is located in the components subdirectory
|
---|
235 | char szPathVBoxC[RTPATH_MAX];
|
---|
236 | rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
|
---|
237 | strcat(szPathVBoxC, "/components/VBoxC");
|
---|
238 | rc = CFGMR3InsertString(pMod, "Path", szPathVBoxC); RC_CHECK();
|
---|
239 | #else
|
---|
240 | rc = CFGMR3InsertString(pMod, "Path", "VBoxC"); RC_CHECK();
|
---|
241 | #endif
|
---|
242 |
|
---|
243 | /*
|
---|
244 | * Devices
|
---|
245 | */
|
---|
246 | PCFGMNODE pDevices = NULL; /* /Devices */
|
---|
247 | PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
|
---|
248 | PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
|
---|
249 | PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
|
---|
250 | PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
|
---|
251 | PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
|
---|
252 | PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
|
---|
253 | PCFGMNODE pIdeInst = NULL; /* /Devices/piix3ide/0/ */
|
---|
254 | PCFGMNODE pSataInst = NULL; /* /Devices/ahci/0/ */
|
---|
255 | PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
|
---|
256 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
257 | PCFGMNODE pGuestProps = NULL; /* /GuestProps */
|
---|
258 | PCFGMNODE pValues = NULL; /* /GuestProps/Values */
|
---|
259 | PCFGMNODE pTimestamps = NULL; /* /GuestProps/Timestamps */
|
---|
260 | PCFGMNODE pFlags = NULL; /* /GuestProps/Flags */
|
---|
261 | #endif /* VBOX_WITH_GUEST_PROPS defined */
|
---|
262 |
|
---|
263 | rc = CFGMR3InsertNode(pRoot, "Devices", &pDevices); RC_CHECK();
|
---|
264 |
|
---|
265 | /*
|
---|
266 | * PC Arch.
|
---|
267 | */
|
---|
268 | rc = CFGMR3InsertNode(pDevices, "pcarch", &pDev); RC_CHECK();
|
---|
269 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
270 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
271 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
272 |
|
---|
273 | /*
|
---|
274 | * PC Bios.
|
---|
275 | */
|
---|
276 | rc = CFGMR3InsertNode(pDevices, "pcbios", &pDev); RC_CHECK();
|
---|
277 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
278 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
279 | rc = CFGMR3InsertNode(pInst, "Config", &pBiosCfg); RC_CHECK();
|
---|
280 | rc = CFGMR3InsertInteger(pBiosCfg, "RamSize", cRamMBs * _1M); RC_CHECK();
|
---|
281 | rc = CFGMR3InsertInteger(pBiosCfg, "NumCPUs", cCpus); RC_CHECK();
|
---|
282 | rc = CFGMR3InsertString(pBiosCfg, "HardDiskDevice", "piix3ide"); RC_CHECK();
|
---|
283 | rc = CFGMR3InsertString(pBiosCfg, "FloppyDevice", "i82078"); RC_CHECK();
|
---|
284 | rc = CFGMR3InsertInteger(pBiosCfg, "IOAPIC", fIOAPIC); RC_CHECK();
|
---|
285 | rc = CFGMR3InsertInteger(pBiosCfg, "PXEDebug", fPXEDebug); RC_CHECK();
|
---|
286 | rc = CFGMR3InsertBytes(pBiosCfg, "UUID", pUuid, sizeof(*pUuid)); RC_CHECK();
|
---|
287 |
|
---|
288 | DeviceType_T bootDevice;
|
---|
289 | if (SchemaDefs::MaxBootPosition > 9)
|
---|
290 | {
|
---|
291 | AssertMsgFailed (("Too many boot devices %d\n",
|
---|
292 | SchemaDefs::MaxBootPosition));
|
---|
293 | return VERR_INVALID_PARAMETER;
|
---|
294 | }
|
---|
295 |
|
---|
296 | for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; pos ++)
|
---|
297 | {
|
---|
298 | hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
|
---|
299 |
|
---|
300 | char szParamName[] = "BootDeviceX";
|
---|
301 | szParamName[sizeof (szParamName) - 2] = ((char (pos - 1)) + '0');
|
---|
302 |
|
---|
303 | const char *pszBootDevice;
|
---|
304 | switch (bootDevice)
|
---|
305 | {
|
---|
306 | case DeviceType_Null:
|
---|
307 | pszBootDevice = "NONE";
|
---|
308 | break;
|
---|
309 | case DeviceType_HardDisk:
|
---|
310 | pszBootDevice = "IDE";
|
---|
311 | break;
|
---|
312 | case DeviceType_DVD:
|
---|
313 | pszBootDevice = "DVD";
|
---|
314 | break;
|
---|
315 | case DeviceType_Floppy:
|
---|
316 | pszBootDevice = "FLOPPY";
|
---|
317 | break;
|
---|
318 | case DeviceType_Network:
|
---|
319 | pszBootDevice = "LAN";
|
---|
320 | break;
|
---|
321 | default:
|
---|
322 | AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
|
---|
323 | return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
|
---|
324 | N_("Invalid boot device '%d'"), bootDevice);
|
---|
325 | }
|
---|
326 | rc = CFGMR3InsertString(pBiosCfg, szParamName, pszBootDevice); RC_CHECK();
|
---|
327 | }
|
---|
328 |
|
---|
329 | /*
|
---|
330 | * The time offset
|
---|
331 | */
|
---|
332 | LONG64 timeOffset;
|
---|
333 | hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
|
---|
334 | PCFGMNODE pTMNode;
|
---|
335 | rc = CFGMR3InsertNode(pRoot, "TM", &pTMNode); RC_CHECK();
|
---|
336 | rc = CFGMR3InsertInteger(pTMNode, "UTCOffset", timeOffset * 1000000); RC_CHECK();
|
---|
337 |
|
---|
338 | /*
|
---|
339 | * DMA
|
---|
340 | */
|
---|
341 | rc = CFGMR3InsertNode(pDevices, "8237A", &pDev); RC_CHECK();
|
---|
342 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
343 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
344 |
|
---|
345 | /*
|
---|
346 | * PCI bus.
|
---|
347 | */
|
---|
348 | rc = CFGMR3InsertNode(pDevices, "pci", &pDev); /* piix3 */ RC_CHECK();
|
---|
349 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
350 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
351 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
352 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
|
---|
353 |
|
---|
354 | /*
|
---|
355 | * PS/2 keyboard & mouse.
|
---|
356 | */
|
---|
357 | rc = CFGMR3InsertNode(pDevices, "pckbd", &pDev); RC_CHECK();
|
---|
358 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
359 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
360 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
361 |
|
---|
362 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
363 | rc = CFGMR3InsertString(pLunL0, "Driver", "KeyboardQueue"); RC_CHECK();
|
---|
364 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
365 | rc = CFGMR3InsertInteger(pCfg, "QueueSize", 64); RC_CHECK();
|
---|
366 |
|
---|
367 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
368 | rc = CFGMR3InsertString(pLunL1, "Driver", "MainKeyboard"); RC_CHECK();
|
---|
369 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
370 | Keyboard *pKeyboard = pConsole->mKeyboard;
|
---|
371 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pKeyboard); RC_CHECK();
|
---|
372 |
|
---|
373 | rc = CFGMR3InsertNode(pInst, "LUN#1", &pLunL0); RC_CHECK();
|
---|
374 | rc = CFGMR3InsertString(pLunL0, "Driver", "MouseQueue"); RC_CHECK();
|
---|
375 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
376 | rc = CFGMR3InsertInteger(pCfg, "QueueSize", 128); RC_CHECK();
|
---|
377 |
|
---|
378 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
379 | rc = CFGMR3InsertString(pLunL1, "Driver", "MainMouse"); RC_CHECK();
|
---|
380 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
381 | Mouse *pMouse = pConsole->mMouse;
|
---|
382 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pMouse); RC_CHECK();
|
---|
383 |
|
---|
384 | /*
|
---|
385 | * i82078 Floppy drive controller
|
---|
386 | */
|
---|
387 | ComPtr<IFloppyDrive> floppyDrive;
|
---|
388 | hrc = pMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam()); H();
|
---|
389 | BOOL fFdcEnabled;
|
---|
390 | hrc = floppyDrive->COMGETTER(Enabled)(&fFdcEnabled); H();
|
---|
391 | if (fFdcEnabled)
|
---|
392 | {
|
---|
393 | rc = CFGMR3InsertNode(pDevices, "i82078", &pDev); RC_CHECK();
|
---|
394 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
395 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); RC_CHECK();
|
---|
396 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
397 | rc = CFGMR3InsertInteger(pCfg, "IRQ", 6); RC_CHECK();
|
---|
398 | rc = CFGMR3InsertInteger(pCfg, "DMA", 2); RC_CHECK();
|
---|
399 | rc = CFGMR3InsertInteger(pCfg, "MemMapped", 0 ); RC_CHECK();
|
---|
400 | rc = CFGMR3InsertInteger(pCfg, "IOBase", 0x3f0); RC_CHECK();
|
---|
401 |
|
---|
402 | /* Attach the status driver */
|
---|
403 | rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
404 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
405 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
406 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapFDLeds[0]); RC_CHECK();
|
---|
407 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
408 | rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
|
---|
409 |
|
---|
410 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
411 |
|
---|
412 | ComPtr<IFloppyImage> floppyImage;
|
---|
413 | hrc = floppyDrive->GetImage(floppyImage.asOutParam()); H();
|
---|
414 | if (floppyImage)
|
---|
415 | {
|
---|
416 | pConsole->meFloppyState = DriveState_ImageMounted;
|
---|
417 | rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
|
---|
418 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
419 | rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
|
---|
420 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
|
---|
421 |
|
---|
422 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
423 | rc = CFGMR3InsertString(pLunL1, "Driver", "RawImage"); RC_CHECK();
|
---|
424 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
425 | hrc = floppyImage->COMGETTER(FilePath)(&str); H();
|
---|
426 | STR_CONV();
|
---|
427 | rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
|
---|
428 | STR_FREE();
|
---|
429 | }
|
---|
430 | else
|
---|
431 | {
|
---|
432 | ComPtr<IHostFloppyDrive> hostFloppyDrive;
|
---|
433 | hrc = floppyDrive->GetHostDrive(hostFloppyDrive.asOutParam()); H();
|
---|
434 | if (hostFloppyDrive)
|
---|
435 | {
|
---|
436 | pConsole->meFloppyState = DriveState_HostDriveCaptured;
|
---|
437 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostFloppy"); RC_CHECK();
|
---|
438 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
439 | hrc = hostFloppyDrive->COMGETTER(Name)(&str); H();
|
---|
440 | STR_CONV();
|
---|
441 | rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
|
---|
442 | STR_FREE();
|
---|
443 | }
|
---|
444 | else
|
---|
445 | {
|
---|
446 | pConsole->meFloppyState = DriveState_NotMounted;
|
---|
447 | rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
|
---|
448 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
449 | rc = CFGMR3InsertString(pCfg, "Type", "Floppy 1.44"); RC_CHECK();
|
---|
450 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
|
---|
451 | }
|
---|
452 | }
|
---|
453 | }
|
---|
454 |
|
---|
455 | /*
|
---|
456 | * ACPI
|
---|
457 | */
|
---|
458 | BOOL fACPI;
|
---|
459 | hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
|
---|
460 | if (fACPI)
|
---|
461 | {
|
---|
462 | rc = CFGMR3InsertNode(pDevices, "acpi", &pDev); RC_CHECK();
|
---|
463 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
464 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
465 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
466 | rc = CFGMR3InsertInteger(pCfg, "RamSize", cRamMBs * _1M); RC_CHECK();
|
---|
467 | rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
|
---|
468 |
|
---|
469 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
|
---|
470 | rc = CFGMR3InsertInteger(pCfg, "FdcEnabled", fFdcEnabled); RC_CHECK();
|
---|
471 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 7); RC_CHECK();
|
---|
472 | Assert(!afPciDeviceNo[7]);
|
---|
473 | afPciDeviceNo[7] = true;
|
---|
474 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
475 |
|
---|
476 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
477 | rc = CFGMR3InsertString(pLunL0, "Driver", "ACPIHost"); RC_CHECK();
|
---|
478 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
479 | }
|
---|
480 |
|
---|
481 | /*
|
---|
482 | * i8254 Programmable Interval Timer And Dummy Speaker
|
---|
483 | */
|
---|
484 | rc = CFGMR3InsertNode(pDevices, "i8254", &pDev); RC_CHECK();
|
---|
485 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
486 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
487 | #ifdef DEBUG
|
---|
488 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
489 | #endif
|
---|
490 |
|
---|
491 | /*
|
---|
492 | * i8259 Programmable Interrupt Controller.
|
---|
493 | */
|
---|
494 | rc = CFGMR3InsertNode(pDevices, "i8259", &pDev); RC_CHECK();
|
---|
495 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
496 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
497 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
498 |
|
---|
499 | /*
|
---|
500 | * Advanced Programmable Interrupt Controller.
|
---|
501 | * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
|
---|
502 | * thus only single insert
|
---|
503 | */
|
---|
504 | rc = CFGMR3InsertNode(pDevices, "apic", &pDev); RC_CHECK();
|
---|
505 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
506 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
507 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
508 | rc = CFGMR3InsertInteger(pCfg, "IOAPIC", fIOAPIC); RC_CHECK();
|
---|
509 | rc = CFGMR3InsertInteger(pCfg, "NumCPUs", cCpus); RC_CHECK();
|
---|
510 |
|
---|
511 | /* SMP: @todo: IOAPIC may be required for SMP configs */
|
---|
512 | if (fIOAPIC)
|
---|
513 | {
|
---|
514 | /*
|
---|
515 | * I/O Advanced Programmable Interrupt Controller.
|
---|
516 | */
|
---|
517 | rc = CFGMR3InsertNode(pDevices, "ioapic", &pDev); RC_CHECK();
|
---|
518 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
519 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
520 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
521 | }
|
---|
522 |
|
---|
523 | /*
|
---|
524 | * RTC MC146818.
|
---|
525 | */
|
---|
526 | rc = CFGMR3InsertNode(pDevices, "mc146818", &pDev); RC_CHECK();
|
---|
527 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
528 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
529 |
|
---|
530 | /*
|
---|
531 | * VGA.
|
---|
532 | */
|
---|
533 | rc = CFGMR3InsertNode(pDevices, "vga", &pDev); RC_CHECK();
|
---|
534 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
535 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
536 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 2); RC_CHECK();
|
---|
537 | Assert(!afPciDeviceNo[2]);
|
---|
538 | afPciDeviceNo[2] = true;
|
---|
539 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
540 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
541 | hrc = pMachine->COMGETTER(VRAMSize)(&cRamMBs); H();
|
---|
542 | rc = CFGMR3InsertInteger(pCfg, "VRamSize", cRamMBs * _1M); RC_CHECK();
|
---|
543 |
|
---|
544 | /*
|
---|
545 | * BIOS logo
|
---|
546 | */
|
---|
547 | BOOL fFadeIn;
|
---|
548 | hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
|
---|
549 | rc = CFGMR3InsertInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0); RC_CHECK();
|
---|
550 | BOOL fFadeOut;
|
---|
551 | hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
|
---|
552 | rc = CFGMR3InsertInteger(pCfg, "FadeOut", fFadeOut ? 1: 0); RC_CHECK();
|
---|
553 | ULONG logoDisplayTime;
|
---|
554 | hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
|
---|
555 | rc = CFGMR3InsertInteger(pCfg, "LogoTime", logoDisplayTime); RC_CHECK();
|
---|
556 | Bstr logoImagePath;
|
---|
557 | hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
|
---|
558 | rc = CFGMR3InsertString(pCfg, "LogoFile", logoImagePath ? Utf8Str(logoImagePath) : ""); RC_CHECK();
|
---|
559 |
|
---|
560 | /*
|
---|
561 | * Boot menu
|
---|
562 | */
|
---|
563 | BIOSBootMenuMode_T bootMenuMode;
|
---|
564 | int value;
|
---|
565 | biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
|
---|
566 | switch (bootMenuMode)
|
---|
567 | {
|
---|
568 | case BIOSBootMenuMode_Disabled:
|
---|
569 | value = 0;
|
---|
570 | break;
|
---|
571 | case BIOSBootMenuMode_MenuOnly:
|
---|
572 | value = 1;
|
---|
573 | break;
|
---|
574 | default:
|
---|
575 | value = 2;
|
---|
576 | }
|
---|
577 | rc = CFGMR3InsertInteger(pCfg, "ShowBootMenu", value); RC_CHECK();
|
---|
578 |
|
---|
579 | /* Custom VESA mode list */
|
---|
580 | unsigned cModes = 0;
|
---|
581 | for (unsigned iMode = 1; iMode <= 16; iMode++)
|
---|
582 | {
|
---|
583 | char szExtraDataKey[sizeof("CustomVideoModeXX")];
|
---|
584 | RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%d", iMode);
|
---|
585 | hrc = pMachine->GetExtraData(Bstr(szExtraDataKey), &str); H();
|
---|
586 | if (!str || !*str)
|
---|
587 | break;
|
---|
588 | STR_CONV();
|
---|
589 | rc = CFGMR3InsertString(pCfg, szExtraDataKey, psz);
|
---|
590 | STR_FREE();
|
---|
591 | cModes++;
|
---|
592 | }
|
---|
593 | rc = CFGMR3InsertInteger(pCfg, "CustomVideoModes", cModes);
|
---|
594 |
|
---|
595 | /* VESA height reduction */
|
---|
596 | ULONG ulHeightReduction;
|
---|
597 | IFramebuffer *pFramebuffer = pConsole->getDisplay()->getFramebuffer();
|
---|
598 | if (pFramebuffer)
|
---|
599 | {
|
---|
600 | hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
|
---|
601 | }
|
---|
602 | else
|
---|
603 | {
|
---|
604 | /* If framebuffer is not available, there is no height reduction. */
|
---|
605 | ulHeightReduction = 0;
|
---|
606 | }
|
---|
607 | rc = CFGMR3InsertInteger(pCfg, "HeightReduction", ulHeightReduction); RC_CHECK();
|
---|
608 |
|
---|
609 | /* Attach the display. */
|
---|
610 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
611 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainDisplay"); RC_CHECK();
|
---|
612 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
613 | Display *pDisplay = pConsole->mDisplay;
|
---|
614 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pDisplay); RC_CHECK();
|
---|
615 |
|
---|
616 | /*
|
---|
617 | * IDE (update this when the main interface changes)
|
---|
618 | */
|
---|
619 | rc = CFGMR3InsertNode(pDevices, "piix3ide", &pDev); /* piix3 */ RC_CHECK();
|
---|
620 | rc = CFGMR3InsertNode(pDev, "0", &pIdeInst); RC_CHECK();
|
---|
621 | rc = CFGMR3InsertInteger(pIdeInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
622 | rc = CFGMR3InsertInteger(pIdeInst, "PCIDeviceNo", 1); RC_CHECK();
|
---|
623 | Assert(!afPciDeviceNo[1]);
|
---|
624 | afPciDeviceNo[1] = true;
|
---|
625 | rc = CFGMR3InsertInteger(pIdeInst, "PCIFunctionNo", 1); RC_CHECK();
|
---|
626 | rc = CFGMR3InsertNode(pIdeInst, "Config", &pCfg); RC_CHECK();
|
---|
627 | rc = CFGMR3InsertInteger(pCfg, "PIIX4", fPIIX4); /* boolean */ RC_CHECK();
|
---|
628 |
|
---|
629 | /* Attach the status driver */
|
---|
630 | rc = CFGMR3InsertNode(pIdeInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
631 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
632 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
633 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapIDELeds[0]);RC_CHECK();
|
---|
634 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
635 | rc = CFGMR3InsertInteger(pCfg, "Last", 3); RC_CHECK();
|
---|
636 |
|
---|
637 | /*
|
---|
638 | * SATA controller
|
---|
639 | */
|
---|
640 | ComPtr<ISATAController> sataController;
|
---|
641 | hrc = pMachine->COMGETTER(SATAController)(sataController.asOutParam());
|
---|
642 | BOOL enabled = FALSE;
|
---|
643 |
|
---|
644 | if (sataController)
|
---|
645 | {
|
---|
646 | hrc = sataController->COMGETTER(Enabled)(&enabled); H();
|
---|
647 |
|
---|
648 | if (enabled)
|
---|
649 | {
|
---|
650 | rc = CFGMR3InsertNode(pDevices, "ahci", &pDev); RC_CHECK();
|
---|
651 | rc = CFGMR3InsertNode(pDev, "0", &pSataInst); RC_CHECK();
|
---|
652 | rc = CFGMR3InsertInteger(pSataInst, "Trusted", 1); RC_CHECK();
|
---|
653 | rc = CFGMR3InsertInteger(pSataInst, "PCIDeviceNo", 13); RC_CHECK();
|
---|
654 | Assert(!afPciDeviceNo[13]);
|
---|
655 | afPciDeviceNo[13] = true;
|
---|
656 | rc = CFGMR3InsertInteger(pSataInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
657 | rc = CFGMR3InsertNode(pSataInst, "Config", &pCfg); RC_CHECK();
|
---|
658 |
|
---|
659 | ULONG cPorts = 0;
|
---|
660 | hrc = sataController->COMGETTER(PortCount)(&cPorts); H();
|
---|
661 | rc = CFGMR3InsertInteger(pCfg, "PortCount", cPorts); RC_CHECK();
|
---|
662 |
|
---|
663 | /* Needed configuration values for the bios. */
|
---|
664 | rc = CFGMR3InsertString(pBiosCfg, "SataHardDiskDevice", "ahci"); RC_CHECK();
|
---|
665 |
|
---|
666 | for (uint32_t i = 0; i < 4; i++)
|
---|
667 | {
|
---|
668 | static const char *s_apszConfig[4] =
|
---|
669 | { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
|
---|
670 | static const char *s_apszBiosConfig[4] =
|
---|
671 | { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
|
---|
672 |
|
---|
673 | LONG lPortNumber = -1;
|
---|
674 | hrc = sataController->GetIDEEmulationPort(i, &lPortNumber); H();
|
---|
675 | rc = CFGMR3InsertInteger(pCfg, s_apszConfig[i], lPortNumber); RC_CHECK();
|
---|
676 | rc = CFGMR3InsertInteger(pBiosCfg, s_apszBiosConfig[i], lPortNumber); RC_CHECK();
|
---|
677 | }
|
---|
678 |
|
---|
679 | /* Attach the status driver */
|
---|
680 | rc = CFGMR3InsertNode(pSataInst,"LUN#999", &pLunL0); RC_CHECK();
|
---|
681 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
682 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
683 | AssertRelease(cPorts <= RT_ELEMENTS(pConsole->mapSATALeds));
|
---|
684 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSATALeds[0]); RC_CHECK();
|
---|
685 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
686 | rc = CFGMR3InsertInteger(pCfg, "Last", cPorts - 1); RC_CHECK();
|
---|
687 | }
|
---|
688 | }
|
---|
689 |
|
---|
690 | /* Attach the harddisks */
|
---|
691 | ComPtr<IHardDiskAttachmentCollection> hdaColl;
|
---|
692 | hrc = pMachine->COMGETTER(HardDiskAttachments)(hdaColl.asOutParam()); H();
|
---|
693 | ComPtr<IHardDiskAttachmentEnumerator> hdaEnum;
|
---|
694 | hrc = hdaColl->Enumerate(hdaEnum.asOutParam()); H();
|
---|
695 |
|
---|
696 | BOOL fMore = FALSE;
|
---|
697 | while ( SUCCEEDED(hrc = hdaEnum->HasMore(&fMore))
|
---|
698 | && fMore)
|
---|
699 | {
|
---|
700 | PCFGMNODE pHardDiskCtl;
|
---|
701 | ComPtr<IHardDiskAttachment> hda;
|
---|
702 | hrc = hdaEnum->GetNext(hda.asOutParam()); H();
|
---|
703 | ComPtr<IHardDisk> hardDisk;
|
---|
704 | hrc = hda->COMGETTER(HardDisk)(hardDisk.asOutParam()); H();
|
---|
705 | StorageBus_T enmBus;
|
---|
706 | hrc = hda->COMGETTER(Bus)(&enmBus); H();
|
---|
707 | LONG lDev;
|
---|
708 | hrc = hda->COMGETTER(Device)(&lDev); H();
|
---|
709 | LONG lChannel;
|
---|
710 | hrc = hda->COMGETTER(Channel)(&lChannel); H();
|
---|
711 |
|
---|
712 | int iLUN;
|
---|
713 | switch (enmBus)
|
---|
714 | {
|
---|
715 | case StorageBus_IDE:
|
---|
716 | {
|
---|
717 | if (lChannel >= 2 || lChannel < 0)
|
---|
718 | {
|
---|
719 | AssertMsgFailed(("invalid controller channel number: %d\n", lChannel));
|
---|
720 | return VERR_GENERAL_FAILURE;
|
---|
721 | }
|
---|
722 |
|
---|
723 | if (lDev >= 2 || lDev < 0)
|
---|
724 | {
|
---|
725 | AssertMsgFailed(("invalid controller device number: %d\n", lDev));
|
---|
726 | return VERR_GENERAL_FAILURE;
|
---|
727 | }
|
---|
728 | iLUN = 2*lChannel + lDev;
|
---|
729 | pHardDiskCtl = pIdeInst;
|
---|
730 | }
|
---|
731 | break;
|
---|
732 | case StorageBus_SATA:
|
---|
733 | iLUN = lChannel;
|
---|
734 | pHardDiskCtl = enabled ? pSataInst : NULL;
|
---|
735 | break;
|
---|
736 | default:
|
---|
737 | AssertMsgFailed(("invalid disk controller type: %d\n", enmBus));
|
---|
738 | return VERR_GENERAL_FAILURE;
|
---|
739 | }
|
---|
740 |
|
---|
741 | /* Can be NULL if SATA controller is not enabled and current hard disk is attached to SATA controller. */
|
---|
742 | if (pHardDiskCtl)
|
---|
743 | {
|
---|
744 | char szLUN[16];
|
---|
745 | RTStrPrintf(szLUN, sizeof(szLUN), "LUN#%d", iLUN);
|
---|
746 | rc = CFGMR3InsertNode(pHardDiskCtl, szLUN, &pLunL0); RC_CHECK();
|
---|
747 | rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
|
---|
748 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
749 | rc = CFGMR3InsertString(pCfg, "Type", "HardDisk"); RC_CHECK();
|
---|
750 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 0); RC_CHECK();
|
---|
751 |
|
---|
752 | HardDiskStorageType_T hddType;
|
---|
753 | hardDisk->COMGETTER(StorageType)(&hddType);
|
---|
754 | if (hddType == HardDiskStorageType_VirtualDiskImage)
|
---|
755 | {
|
---|
756 | ComPtr<IVirtualDiskImage> vdiDisk = hardDisk;
|
---|
757 | AssertBreakStmt (!vdiDisk.isNull(), hrc = E_FAIL);
|
---|
758 |
|
---|
759 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
760 | rc = CFGMR3InsertString(pLunL1, "Driver", "VBoxHDD"); RC_CHECK();
|
---|
761 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
762 | hrc = vdiDisk->COMGETTER(FilePath)(&str); H();
|
---|
763 | STR_CONV();
|
---|
764 | rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
|
---|
765 | STR_FREE();
|
---|
766 |
|
---|
767 | /* Create an inversed tree of parents. */
|
---|
768 | ComPtr<IHardDisk> parentHardDisk = hardDisk;
|
---|
769 | for (PCFGMNODE pParent = pCfg;;)
|
---|
770 | {
|
---|
771 | ComPtr<IHardDisk> curHardDisk;
|
---|
772 | hrc = parentHardDisk->COMGETTER(Parent)(curHardDisk.asOutParam()); H();
|
---|
773 | if (!curHardDisk)
|
---|
774 | break;
|
---|
775 |
|
---|
776 | vdiDisk = curHardDisk;
|
---|
777 | AssertBreakStmt (!vdiDisk.isNull(), hrc = E_FAIL);
|
---|
778 |
|
---|
779 | PCFGMNODE pCur;
|
---|
780 | rc = CFGMR3InsertNode(pParent, "Parent", &pCur); RC_CHECK();
|
---|
781 | hrc = vdiDisk->COMGETTER(FilePath)(&str); H();
|
---|
782 | STR_CONV();
|
---|
783 | rc = CFGMR3InsertString(pCur, "Path", psz); RC_CHECK();
|
---|
784 | STR_FREE();
|
---|
785 | rc = CFGMR3InsertInteger(pCur, "ReadOnly", 1); RC_CHECK();
|
---|
786 |
|
---|
787 | /* next */
|
---|
788 | pParent = pCur;
|
---|
789 | parentHardDisk = curHardDisk;
|
---|
790 | }
|
---|
791 | }
|
---|
792 | else if (hddType == HardDiskStorageType_ISCSIHardDisk)
|
---|
793 | {
|
---|
794 | ComPtr<IISCSIHardDisk> iSCSIDisk = hardDisk;
|
---|
795 | AssertBreakStmt (!iSCSIDisk.isNull(), hrc = E_FAIL);
|
---|
796 |
|
---|
797 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
798 | rc = CFGMR3InsertString(pLunL1, "Driver", "iSCSI"); RC_CHECK();
|
---|
799 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
800 |
|
---|
801 | /* Set up the iSCSI initiator driver configuration. */
|
---|
802 | hrc = iSCSIDisk->COMGETTER(Target)(&str); H();
|
---|
803 | STR_CONV();
|
---|
804 | rc = CFGMR3InsertString(pCfg, "TargetName", psz); RC_CHECK();
|
---|
805 | STR_FREE();
|
---|
806 |
|
---|
807 | ULONG64 lun;
|
---|
808 | hrc = iSCSIDisk->COMGETTER(Lun)(&lun); H();
|
---|
809 | rc = CFGMR3InsertInteger(pCfg, "LUN", lun); RC_CHECK();
|
---|
810 |
|
---|
811 | hrc = iSCSIDisk->COMGETTER(Server)(&str); H();
|
---|
812 | STR_CONV();
|
---|
813 | USHORT port;
|
---|
814 | hrc = iSCSIDisk->COMGETTER(Port)(&port); H();
|
---|
815 | if (port != 0)
|
---|
816 | {
|
---|
817 | char *pszTN;
|
---|
818 | RTStrAPrintf(&pszTN, "%s:%u", psz, port);
|
---|
819 | rc = CFGMR3InsertString(pCfg, "TargetAddress", pszTN); RC_CHECK();
|
---|
820 | RTStrFree(pszTN);
|
---|
821 | }
|
---|
822 | else
|
---|
823 | {
|
---|
824 | rc = CFGMR3InsertString(pCfg, "TargetAddress", psz); RC_CHECK();
|
---|
825 | }
|
---|
826 | STR_FREE();
|
---|
827 |
|
---|
828 | hrc = iSCSIDisk->COMGETTER(UserName)(&str); H();
|
---|
829 | if (str)
|
---|
830 | {
|
---|
831 | STR_CONV();
|
---|
832 | rc = CFGMR3InsertString(pCfg, "InitiatorUsername", psz); RC_CHECK();
|
---|
833 | STR_FREE();
|
---|
834 | }
|
---|
835 |
|
---|
836 | hrc = iSCSIDisk->COMGETTER(Password)(&str); H();
|
---|
837 | if (str)
|
---|
838 | {
|
---|
839 | STR_CONV();
|
---|
840 | rc = CFGMR3InsertString(pCfg, "InitiatorSecret", psz); RC_CHECK();
|
---|
841 | STR_FREE();
|
---|
842 | }
|
---|
843 |
|
---|
844 | // @todo currently there is no target username config.
|
---|
845 | //rc = CFGMR3InsertString(pCfg, "TargetUsername", ""); RC_CHECK();
|
---|
846 |
|
---|
847 | // @todo currently there is no target password config.
|
---|
848 | //rc = CFGMR3InsertString(pCfg, "TargetSecret", ""); RC_CHECK();
|
---|
849 |
|
---|
850 | /* The iSCSI initiator needs an attached iSCSI transport driver. */
|
---|
851 | rc = CFGMR3InsertNode(pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
|
---|
852 | rc = CFGMR3InsertString(pLunL2, "Driver", "iSCSITCP"); RC_CHECK();
|
---|
853 | /* Currently the transport driver has no config options. */
|
---|
854 | }
|
---|
855 | else if (hddType == HardDiskStorageType_VMDKImage)
|
---|
856 | {
|
---|
857 | ComPtr<IVMDKImage> vmdkDisk = hardDisk;
|
---|
858 | AssertBreakStmt (!vmdkDisk.isNull(), hrc = E_FAIL);
|
---|
859 |
|
---|
860 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
861 | #if 1 /* Enable new VD container code (and new VMDK), as the bugs are fixed. */
|
---|
862 | rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
|
---|
863 | #else
|
---|
864 | rc = CFGMR3InsertString(pLunL1, "Driver", "VmdkHDD"); RC_CHECK();
|
---|
865 | #endif
|
---|
866 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
867 | hrc = vmdkDisk->COMGETTER(FilePath)(&str); H();
|
---|
868 | STR_CONV();
|
---|
869 | rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
|
---|
870 | STR_FREE();
|
---|
871 | rc = CFGMR3InsertString(pCfg, "Format", "VMDK"); RC_CHECK();
|
---|
872 |
|
---|
873 | #if defined(VBOX_WITH_PDM_ASYNC_COMPLETION)
|
---|
874 | /*
|
---|
875 | * Create cfgm nodes for async transport driver because VMDK is currently the only
|
---|
876 | * one which may support async I/O. This has to be made generic based on the capabiliy flags
|
---|
877 | * when the new HardDisk interface is merged.
|
---|
878 | */
|
---|
879 | rc = CFGMR3InsertNode(pLunL1, "AttachedDriver", &pLunL2); RC_CHECK();
|
---|
880 | rc = CFGMR3InsertString(pLunL2, "Driver", "TransportAsync"); RC_CHECK();
|
---|
881 | /* The async transport driver has no config options yet. */
|
---|
882 | #endif
|
---|
883 | }
|
---|
884 | else if (hddType == HardDiskStorageType_CustomHardDisk)
|
---|
885 | {
|
---|
886 | ComPtr<ICustomHardDisk> customHardDisk = hardDisk;
|
---|
887 | AssertBreakStmt (!customHardDisk.isNull(), hrc = E_FAIL);
|
---|
888 |
|
---|
889 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
890 | rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
|
---|
891 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
892 | hrc = customHardDisk->COMGETTER(Location)(&str); H();
|
---|
893 | STR_CONV();
|
---|
894 | rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
|
---|
895 | STR_FREE();
|
---|
896 | hrc = customHardDisk->COMGETTER(Format)(&str); H();
|
---|
897 | STR_CONV();
|
---|
898 | rc = CFGMR3InsertString(pCfg, "Format", psz); RC_CHECK();
|
---|
899 | STR_FREE();
|
---|
900 | }
|
---|
901 | else if (hddType == HardDiskStorageType_VHDImage)
|
---|
902 | {
|
---|
903 | ComPtr<IVHDImage> vhdDisk = hardDisk;
|
---|
904 | AssertBreakStmt (!vhdDisk.isNull(), hrc = E_FAIL);
|
---|
905 |
|
---|
906 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
907 | rc = CFGMR3InsertString(pLunL1, "Driver", "VD"); RC_CHECK();
|
---|
908 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
909 | hrc = vhdDisk->COMGETTER(FilePath)(&str); H();
|
---|
910 | STR_CONV();
|
---|
911 | rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
|
---|
912 | rc = CFGMR3InsertString(pCfg, "Format", "VHD"); RC_CHECK();
|
---|
913 | STR_FREE();
|
---|
914 | }
|
---|
915 | else
|
---|
916 | AssertFailed();
|
---|
917 | }
|
---|
918 | }
|
---|
919 | H();
|
---|
920 |
|
---|
921 | ComPtr<IDVDDrive> dvdDrive;
|
---|
922 | hrc = pMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam()); H();
|
---|
923 | if (dvdDrive)
|
---|
924 | {
|
---|
925 | // ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
|
---|
926 | rc = CFGMR3InsertNode(pIdeInst, "LUN#2", &pLunL0); RC_CHECK();
|
---|
927 | ComPtr<IHostDVDDrive> hostDvdDrive;
|
---|
928 | hrc = dvdDrive->GetHostDrive(hostDvdDrive.asOutParam()); H();
|
---|
929 | if (hostDvdDrive)
|
---|
930 | {
|
---|
931 | pConsole->meDVDState = DriveState_HostDriveCaptured;
|
---|
932 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostDVD"); RC_CHECK();
|
---|
933 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
934 | hrc = hostDvdDrive->COMGETTER(Name)(&str); H();
|
---|
935 | STR_CONV();
|
---|
936 | rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
|
---|
937 | STR_FREE();
|
---|
938 | BOOL fPassthrough;
|
---|
939 | hrc = dvdDrive->COMGETTER(Passthrough)(&fPassthrough); H();
|
---|
940 | rc = CFGMR3InsertInteger(pCfg, "Passthrough", !!fPassthrough); RC_CHECK();
|
---|
941 | }
|
---|
942 | else
|
---|
943 | {
|
---|
944 | pConsole->meDVDState = DriveState_NotMounted;
|
---|
945 | rc = CFGMR3InsertString(pLunL0, "Driver", "Block"); RC_CHECK();
|
---|
946 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
947 | rc = CFGMR3InsertString(pCfg, "Type", "DVD"); RC_CHECK();
|
---|
948 | rc = CFGMR3InsertInteger(pCfg, "Mountable", 1); RC_CHECK();
|
---|
949 |
|
---|
950 | ComPtr<IDVDImage> dvdImage;
|
---|
951 | hrc = dvdDrive->GetImage(dvdImage.asOutParam()); H();
|
---|
952 | if (dvdImage)
|
---|
953 | {
|
---|
954 | pConsole->meDVDState = DriveState_ImageMounted;
|
---|
955 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
956 | rc = CFGMR3InsertString(pLunL1, "Driver", "MediaISO"); RC_CHECK();
|
---|
957 | rc = CFGMR3InsertNode(pLunL1, "Config", &pCfg); RC_CHECK();
|
---|
958 | hrc = dvdImage->COMGETTER(FilePath)(&str); H();
|
---|
959 | STR_CONV();
|
---|
960 | rc = CFGMR3InsertString(pCfg, "Path", psz); RC_CHECK();
|
---|
961 | STR_FREE();
|
---|
962 | }
|
---|
963 | }
|
---|
964 | }
|
---|
965 |
|
---|
966 | /*
|
---|
967 | * Network adapters
|
---|
968 | */
|
---|
969 | PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
|
---|
970 | rc = CFGMR3InsertNode(pDevices, "pcnet", &pDevPCNet); RC_CHECK();
|
---|
971 | #ifdef VBOX_WITH_E1000
|
---|
972 | PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
|
---|
973 | rc = CFGMR3InsertNode(pDevices, "e1000", &pDevE1000); RC_CHECK();
|
---|
974 | #endif
|
---|
975 | for (ULONG ulInstance = 0; ulInstance < SchemaDefs::NetworkAdapterCount; ulInstance++)
|
---|
976 | {
|
---|
977 | ComPtr<INetworkAdapter> networkAdapter;
|
---|
978 | hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
|
---|
979 | BOOL fEnabled = FALSE;
|
---|
980 | hrc = networkAdapter->COMGETTER(Enabled)(&fEnabled); H();
|
---|
981 | if (!fEnabled)
|
---|
982 | continue;
|
---|
983 |
|
---|
984 | /*
|
---|
985 | * The virtual hardware type. Create appropriate device first.
|
---|
986 | */
|
---|
987 | NetworkAdapterType_T adapterType;
|
---|
988 | hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
|
---|
989 | switch (adapterType)
|
---|
990 | {
|
---|
991 | case NetworkAdapterType_Am79C970A:
|
---|
992 | case NetworkAdapterType_Am79C973:
|
---|
993 | pDev = pDevPCNet;
|
---|
994 | break;
|
---|
995 | #ifdef VBOX_WITH_E1000
|
---|
996 | case NetworkAdapterType_I82540EM:
|
---|
997 | case NetworkAdapterType_I82543GC:
|
---|
998 | pDev = pDevE1000;
|
---|
999 | break;
|
---|
1000 | #endif
|
---|
1001 | default:
|
---|
1002 | AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
|
---|
1003 | adapterType, ulInstance));
|
---|
1004 | return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
|
---|
1005 | N_("Invalid network adapter type '%d' for slot '%d'"),
|
---|
1006 | adapterType, ulInstance);
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 | char szInstance[4]; Assert(ulInstance <= 999);
|
---|
1010 | RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
|
---|
1011 | rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
|
---|
1012 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
1013 | /* the first network card gets the PCI ID 3, the next 3 gets 8..10. */
|
---|
1014 | const unsigned iPciDeviceNo = !ulInstance ? 3 : ulInstance - 1 + 8;
|
---|
1015 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", iPciDeviceNo); RC_CHECK();
|
---|
1016 | Assert(!afPciDeviceNo[iPciDeviceNo]);
|
---|
1017 | afPciDeviceNo[iPciDeviceNo] = true;
|
---|
1018 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1019 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1020 |
|
---|
1021 | /*
|
---|
1022 | * The virtual hardware type. PCNet supports two types.
|
---|
1023 | */
|
---|
1024 | switch (adapterType)
|
---|
1025 | {
|
---|
1026 | case NetworkAdapterType_Am79C970A:
|
---|
1027 | rc = CFGMR3InsertInteger(pCfg, "Am79C973", 0); RC_CHECK();
|
---|
1028 | break;
|
---|
1029 | case NetworkAdapterType_Am79C973:
|
---|
1030 | rc = CFGMR3InsertInteger(pCfg, "Am79C973", 1); RC_CHECK();
|
---|
1031 | break;
|
---|
1032 | case NetworkAdapterType_I82540EM:
|
---|
1033 | rc = CFGMR3InsertInteger(pCfg, "AdapterType", 0); RC_CHECK();
|
---|
1034 | break;
|
---|
1035 | case NetworkAdapterType_I82543GC:
|
---|
1036 | rc = CFGMR3InsertInteger(pCfg, "AdapterType", 1); RC_CHECK();
|
---|
1037 | break;
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | /*
|
---|
1041 | * Get the MAC address and convert it to binary representation
|
---|
1042 | */
|
---|
1043 | Bstr macAddr;
|
---|
1044 | hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
|
---|
1045 | Assert(macAddr);
|
---|
1046 | Utf8Str macAddrUtf8 = macAddr;
|
---|
1047 | char *macStr = (char*)macAddrUtf8.raw();
|
---|
1048 | Assert(strlen(macStr) == 12);
|
---|
1049 | RTMAC Mac;
|
---|
1050 | memset(&Mac, 0, sizeof(Mac));
|
---|
1051 | char *pMac = (char*)&Mac;
|
---|
1052 | for (uint32_t i = 0; i < 6; i++)
|
---|
1053 | {
|
---|
1054 | char c1 = *macStr++ - '0';
|
---|
1055 | if (c1 > 9)
|
---|
1056 | c1 -= 7;
|
---|
1057 | char c2 = *macStr++ - '0';
|
---|
1058 | if (c2 > 9)
|
---|
1059 | c2 -= 7;
|
---|
1060 | *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
|
---|
1061 | }
|
---|
1062 | rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
|
---|
1063 |
|
---|
1064 | /*
|
---|
1065 | * Check if the cable is supposed to be unplugged
|
---|
1066 | */
|
---|
1067 | BOOL fCableConnected;
|
---|
1068 | hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
|
---|
1069 | rc = CFGMR3InsertInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0); RC_CHECK();
|
---|
1070 |
|
---|
1071 | /*
|
---|
1072 | * Line speed to report from custom drivers
|
---|
1073 | */
|
---|
1074 | ULONG ulLineSpeed;
|
---|
1075 | hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
|
---|
1076 | rc = CFGMR3InsertInteger(pCfg, "LineSpeed", ulLineSpeed); RC_CHECK();
|
---|
1077 |
|
---|
1078 | /*
|
---|
1079 | * Attach the status driver.
|
---|
1080 | */
|
---|
1081 | rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1082 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1083 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1084 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
|
---|
1085 |
|
---|
1086 | /*
|
---|
1087 | * Enable the packet sniffer if requested.
|
---|
1088 | */
|
---|
1089 | BOOL fSniffer;
|
---|
1090 | hrc = networkAdapter->COMGETTER(TraceEnabled)(&fSniffer); H();
|
---|
1091 | if (fSniffer)
|
---|
1092 | {
|
---|
1093 | /* insert the sniffer filter driver. */
|
---|
1094 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1095 | rc = CFGMR3InsertString(pLunL0, "Driver", "NetSniffer"); RC_CHECK();
|
---|
1096 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1097 | hrc = networkAdapter->COMGETTER(TraceFile)(&str); H();
|
---|
1098 | if (str) /* check convention for indicating default file. */
|
---|
1099 | {
|
---|
1100 | STR_CONV();
|
---|
1101 | rc = CFGMR3InsertString(pCfg, "File", psz); RC_CHECK();
|
---|
1102 | STR_FREE();
|
---|
1103 | }
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 | NetworkAttachmentType_T networkAttachment;
|
---|
1107 | hrc = networkAdapter->COMGETTER(AttachmentType)(&networkAttachment); H();
|
---|
1108 | switch (networkAttachment)
|
---|
1109 | {
|
---|
1110 | case NetworkAttachmentType_Null:
|
---|
1111 | break;
|
---|
1112 |
|
---|
1113 | case NetworkAttachmentType_NAT:
|
---|
1114 | {
|
---|
1115 | if (fSniffer)
|
---|
1116 | {
|
---|
1117 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
|
---|
1118 | }
|
---|
1119 | else
|
---|
1120 | {
|
---|
1121 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1122 | }
|
---|
1123 | rc = CFGMR3InsertString(pLunL0, "Driver", "NAT"); RC_CHECK();
|
---|
1124 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1125 | /* (Port forwarding goes here.) */
|
---|
1126 |
|
---|
1127 | /* Configure TFTP prefix and boot filename. */
|
---|
1128 | hrc = virtualBox->COMGETTER(HomeFolder)(&str); H();
|
---|
1129 | STR_CONV();
|
---|
1130 | if (psz && *psz)
|
---|
1131 | {
|
---|
1132 | char *pszTFTPPrefix = NULL;
|
---|
1133 | RTStrAPrintf(&pszTFTPPrefix, "%s%c%s", psz, RTPATH_DELIMITER, "TFTP");
|
---|
1134 | rc = CFGMR3InsertString(pCfg, "TFTPPrefix", pszTFTPPrefix); RC_CHECK();
|
---|
1135 | RTStrFree(pszTFTPPrefix);
|
---|
1136 | }
|
---|
1137 | STR_FREE();
|
---|
1138 | hrc = pMachine->COMGETTER(Name)(&str); H();
|
---|
1139 | STR_CONV();
|
---|
1140 | char *pszBootFile = NULL;
|
---|
1141 | RTStrAPrintf(&pszBootFile, "%s.pxe", psz);
|
---|
1142 | STR_FREE();
|
---|
1143 | rc = CFGMR3InsertString(pCfg, "BootFile", pszBootFile); RC_CHECK();
|
---|
1144 | RTStrFree(pszBootFile);
|
---|
1145 |
|
---|
1146 | hrc = networkAdapter->COMGETTER(NATNetwork)(&str); H();
|
---|
1147 | if (str)
|
---|
1148 | {
|
---|
1149 | STR_CONV();
|
---|
1150 | if (psz && *psz)
|
---|
1151 | rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
|
---|
1152 | STR_FREE();
|
---|
1153 | }
|
---|
1154 | break;
|
---|
1155 | }
|
---|
1156 |
|
---|
1157 | case NetworkAttachmentType_HostInterface:
|
---|
1158 | {
|
---|
1159 | /*
|
---|
1160 | * Perform the attachment if required (don't return on error!)
|
---|
1161 | */
|
---|
1162 | hrc = pConsole->attachToHostInterface(networkAdapter);
|
---|
1163 | if (SUCCEEDED(hrc))
|
---|
1164 | {
|
---|
1165 | #ifdef VBOX_WITH_UNIXY_TAP_NETWORKING
|
---|
1166 | Assert ((int)pConsole->maTapFD[ulInstance] >= 0);
|
---|
1167 | if ((int)pConsole->maTapFD[ulInstance] >= 0)
|
---|
1168 | {
|
---|
1169 | if (fSniffer)
|
---|
1170 | {
|
---|
1171 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
|
---|
1172 | }
|
---|
1173 | else
|
---|
1174 | {
|
---|
1175 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1176 | }
|
---|
1177 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
|
---|
1178 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1179 | # if defined(RT_OS_SOLARIS)
|
---|
1180 | /* Device name/number is required for Solaris as we need it for TAP PPA. */
|
---|
1181 | Bstr tapDeviceName;
|
---|
1182 | networkAdapter->COMGETTER(HostInterface)(tapDeviceName.asOutParam());
|
---|
1183 | if (!tapDeviceName.isEmpty())
|
---|
1184 | rc = CFGMR3InsertString(pCfg, "Device", Utf8Str(tapDeviceName)); RC_CHECK();
|
---|
1185 |
|
---|
1186 | /* TAP setup application/script */
|
---|
1187 | Bstr tapSetupApp;
|
---|
1188 | networkAdapter->COMGETTER(TAPSetupApplication)(tapSetupApp.asOutParam());
|
---|
1189 | if (!tapSetupApp.isEmpty())
|
---|
1190 | rc = CFGMR3InsertString(pCfg, "TAPSetupApplication", Utf8Str(tapSetupApp)); RC_CHECK();
|
---|
1191 |
|
---|
1192 | /* TAP terminate application/script */
|
---|
1193 | Bstr tapTerminateApp;
|
---|
1194 | networkAdapter->COMGETTER(TAPTerminateApplication)(tapTerminateApp.asOutParam());
|
---|
1195 | if (!tapTerminateApp.isEmpty())
|
---|
1196 | rc = CFGMR3InsertString(pCfg, "TAPTerminateApplication", Utf8Str(tapTerminateApp)); RC_CHECK();
|
---|
1197 |
|
---|
1198 | /* "FileHandle" must NOT be inserted here, it is done in DrvTAP.cpp */
|
---|
1199 |
|
---|
1200 | # ifdef VBOX_WITH_CROSSBOW
|
---|
1201 | /* Crossbow: needs the MAC address for setting up TAP. */
|
---|
1202 | rc = CFGMR3InsertBytes(pCfg, "MAC", &Mac, sizeof(Mac)); RC_CHECK();
|
---|
1203 | # endif
|
---|
1204 | # else
|
---|
1205 | rc = CFGMR3InsertInteger(pCfg, "FileHandle", pConsole->maTapFD[ulInstance]); RC_CHECK();
|
---|
1206 | # endif
|
---|
1207 | }
|
---|
1208 |
|
---|
1209 | #elif defined(VBOX_WITH_NETFLT) && !defined(RT_OS_WINDOWS) /** @todo merge in the windows stuff too */
|
---|
1210 | /*
|
---|
1211 | * This is the new VBoxNetFlt+IntNet stuff.
|
---|
1212 | */
|
---|
1213 | if (fSniffer)
|
---|
1214 | {
|
---|
1215 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
|
---|
1216 | }
|
---|
1217 | else
|
---|
1218 | {
|
---|
1219 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1220 | }
|
---|
1221 |
|
---|
1222 | Bstr HifName;
|
---|
1223 | hrc = networkAdapter->COMGETTER(HostInterface)(HifName.asOutParam()); H();
|
---|
1224 | Utf8Str HifNameUtf8(HifName);
|
---|
1225 | const char *pszHifName = HifNameUtf8.raw();
|
---|
1226 |
|
---|
1227 | # if defined(RT_OS_DARWIN)
|
---|
1228 | /* The name is on the form 'ifX: long name', chop it off at the colon. */
|
---|
1229 | char szTrunk[8];
|
---|
1230 | strncpy(szTrunk, pszHifName, sizeof(szTrunk));
|
---|
1231 | char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
|
---|
1232 | if (!pszColon)
|
---|
1233 | {
|
---|
1234 | hrc = networkAdapter->Detach(); H();
|
---|
1235 | return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
|
---|
1236 | N_("Malformed host interface networking name '%ls'"),
|
---|
1237 | HifName.raw());
|
---|
1238 | }
|
---|
1239 | *pszColon = '\0';
|
---|
1240 | const char *pszTrunk = szTrunk;
|
---|
1241 |
|
---|
1242 | # elif defined(RT_OS_SOLARIS)
|
---|
1243 | /* The name is on the form format 'ifX - long name, chop it off at space. */
|
---|
1244 | char szTrunk[8];
|
---|
1245 | strncpy(szTrunk, pszHifName, sizeof(szTrunk));
|
---|
1246 | char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
|
---|
1247 |
|
---|
1248 | /*
|
---|
1249 | * Currently don't bother about malformed names here for the sake of people using
|
---|
1250 | * VBoxManage and setting only the NIC name from there. If there is a space we
|
---|
1251 | * chop it off and proceed, otherwise just use whatever we've got.
|
---|
1252 | */
|
---|
1253 | if (pszSpace)
|
---|
1254 | *pszSpace = '\0';
|
---|
1255 | const char *pszTrunk = szTrunk;
|
---|
1256 | # else
|
---|
1257 | # error "PORTME (VBOX_WITH_NETFLT)"
|
---|
1258 | # endif
|
---|
1259 |
|
---|
1260 | rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
|
---|
1261 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1262 | rc = CFGMR3InsertString(pCfg, "Trunk", pszTrunk); RC_CHECK();
|
---|
1263 | rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
|
---|
1264 | char szNetwork[80];
|
---|
1265 | RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s\n", pszHifName);
|
---|
1266 | rc = CFGMR3InsertString(pCfg, "Network", szNetwork); RC_CHECK();
|
---|
1267 |
|
---|
1268 | # if defined(RT_OS_DARWIN)
|
---|
1269 | /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
|
---|
1270 | if ( strstr(pszHifName, "Wireless")
|
---|
1271 | || strstr(pszHifName, "AirPort" ))
|
---|
1272 | {
|
---|
1273 | rc = CFGMR3InsertInteger(pCfg, "SharedMacOnWire", true); RC_CHECK();
|
---|
1274 | }
|
---|
1275 | # else
|
---|
1276 | /** @todo PORTME: wireless detection */
|
---|
1277 | # endif
|
---|
1278 |
|
---|
1279 | #elif defined(RT_OS_WINDOWS)
|
---|
1280 | if (fSniffer)
|
---|
1281 | {
|
---|
1282 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
|
---|
1283 | }
|
---|
1284 | else
|
---|
1285 | {
|
---|
1286 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1287 | }
|
---|
1288 | Bstr hostInterfaceName;
|
---|
1289 | hrc = networkAdapter->COMGETTER(HostInterface)(hostInterfaceName.asOutParam()); H();
|
---|
1290 | ComPtr<IHostNetworkInterfaceCollection> coll;
|
---|
1291 | hrc = host->COMGETTER(NetworkInterfaces)(coll.asOutParam()); H();
|
---|
1292 | ComPtr<IHostNetworkInterface> hostInterface;
|
---|
1293 | rc = coll->FindByName(hostInterfaceName, hostInterface.asOutParam());
|
---|
1294 | if (!SUCCEEDED(rc))
|
---|
1295 | {
|
---|
1296 | AssertMsgFailed(("Cannot get GUID for host interface '%ls'\n", hostInterfaceName));
|
---|
1297 | hrc = networkAdapter->Detach(); H();
|
---|
1298 | }
|
---|
1299 | else
|
---|
1300 | {
|
---|
1301 | # ifndef VBOX_WITH_NETFLT
|
---|
1302 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostInterface"); RC_CHECK();
|
---|
1303 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1304 | rc = CFGMR3InsertString(pCfg, "HostInterfaceName", Utf8Str(hostInterfaceName)); RC_CHECK();
|
---|
1305 | # else
|
---|
1306 | rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
|
---|
1307 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1308 | rc = CFGMR3InsertString(pCfg, "Trunk", Utf8Str(hostInterfaceName)); RC_CHECK();
|
---|
1309 | rc = CFGMR3InsertInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt); RC_CHECK();
|
---|
1310 | # endif
|
---|
1311 | Guid hostIFGuid;
|
---|
1312 | hrc = hostInterface->COMGETTER(Id)(hostIFGuid.asOutParam()); H();
|
---|
1313 | char szDriverGUID[256] = {0};
|
---|
1314 | /* add curly brackets */
|
---|
1315 | szDriverGUID[0] = '{';
|
---|
1316 | strcpy(szDriverGUID + 1, hostIFGuid.toString().raw());
|
---|
1317 | strcat(szDriverGUID, "}");
|
---|
1318 | rc = CFGMR3InsertBytes(pCfg, "GUID", szDriverGUID, sizeof(szDriverGUID)); RC_CHECK();
|
---|
1319 | }
|
---|
1320 | #else
|
---|
1321 | # error "Port me"
|
---|
1322 | #endif
|
---|
1323 | }
|
---|
1324 | else
|
---|
1325 | {
|
---|
1326 | switch (hrc)
|
---|
1327 | {
|
---|
1328 | #ifdef RT_OS_LINUX
|
---|
1329 | case VERR_ACCESS_DENIED:
|
---|
1330 | return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
|
---|
1331 | "Failed to open '/dev/net/tun' for read/write access. Please check the "
|
---|
1332 | "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
|
---|
1333 | "change the group of that node and make yourself a member of that group. Make "
|
---|
1334 | "sure that these changes are permanent, especially if you are "
|
---|
1335 | "using udev"));
|
---|
1336 | #endif /* RT_OS_LINUX */
|
---|
1337 | default:
|
---|
1338 | AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
|
---|
1339 | return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
|
---|
1340 | "Failed to initialize Host Interface Networking"));
|
---|
1341 | }
|
---|
1342 | }
|
---|
1343 | break;
|
---|
1344 | }
|
---|
1345 |
|
---|
1346 | case NetworkAttachmentType_Internal:
|
---|
1347 | {
|
---|
1348 | hrc = networkAdapter->COMGETTER(InternalNetwork)(&str); H();
|
---|
1349 | if (str)
|
---|
1350 | {
|
---|
1351 | STR_CONV();
|
---|
1352 | if (psz && *psz)
|
---|
1353 | {
|
---|
1354 | if (fSniffer)
|
---|
1355 | {
|
---|
1356 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL0); RC_CHECK();
|
---|
1357 | }
|
---|
1358 | else
|
---|
1359 | {
|
---|
1360 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1361 | }
|
---|
1362 | rc = CFGMR3InsertString(pLunL0, "Driver", "IntNet"); RC_CHECK();
|
---|
1363 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1364 | rc = CFGMR3InsertString(pCfg, "Network", psz); RC_CHECK();
|
---|
1365 | }
|
---|
1366 | STR_FREE();
|
---|
1367 | }
|
---|
1368 | break;
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | default:
|
---|
1372 | AssertMsgFailed(("should not get here!\n"));
|
---|
1373 | break;
|
---|
1374 | }
|
---|
1375 | }
|
---|
1376 |
|
---|
1377 | /*
|
---|
1378 | * Serial (UART) Ports
|
---|
1379 | */
|
---|
1380 | rc = CFGMR3InsertNode(pDevices, "serial", &pDev); RC_CHECK();
|
---|
1381 | for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ulInstance++)
|
---|
1382 | {
|
---|
1383 | ComPtr<ISerialPort> serialPort;
|
---|
1384 | hrc = pMachine->GetSerialPort (ulInstance, serialPort.asOutParam()); H();
|
---|
1385 | BOOL fEnabled = FALSE;
|
---|
1386 | if (serialPort)
|
---|
1387 | hrc = serialPort->COMGETTER(Enabled)(&fEnabled); H();
|
---|
1388 | if (!fEnabled)
|
---|
1389 | continue;
|
---|
1390 |
|
---|
1391 | char szInstance[4]; Assert(ulInstance <= 999);
|
---|
1392 | RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
|
---|
1393 |
|
---|
1394 | rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
|
---|
1395 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1396 |
|
---|
1397 | ULONG ulIRQ, ulIOBase;
|
---|
1398 | PortMode_T HostMode;
|
---|
1399 | Bstr path;
|
---|
1400 | BOOL fServer;
|
---|
1401 | hrc = serialPort->COMGETTER(HostMode)(&HostMode); H();
|
---|
1402 | hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
|
---|
1403 | hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
|
---|
1404 | hrc = serialPort->COMGETTER(Path)(path.asOutParam()); H();
|
---|
1405 | hrc = serialPort->COMGETTER(Server)(&fServer); H();
|
---|
1406 | rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
|
---|
1407 | rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
|
---|
1408 | if (HostMode != PortMode_Disconnected)
|
---|
1409 | {
|
---|
1410 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1411 | if (HostMode == PortMode_HostPipe)
|
---|
1412 | {
|
---|
1413 | rc = CFGMR3InsertString(pLunL0, "Driver", "Char"); RC_CHECK();
|
---|
1414 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
1415 | rc = CFGMR3InsertString(pLunL1, "Driver", "NamedPipe"); RC_CHECK();
|
---|
1416 | rc = CFGMR3InsertNode(pLunL1, "Config", &pLunL2); RC_CHECK();
|
---|
1417 | rc = CFGMR3InsertString(pLunL2, "Location", Utf8Str(path)); RC_CHECK();
|
---|
1418 | rc = CFGMR3InsertInteger(pLunL2, "IsServer", fServer); RC_CHECK();
|
---|
1419 | }
|
---|
1420 | else if (HostMode == PortMode_HostDevice)
|
---|
1421 | {
|
---|
1422 | rc = CFGMR3InsertString(pLunL0, "Driver", "Host Serial"); RC_CHECK();
|
---|
1423 | rc = CFGMR3InsertNode(pLunL0, "Config", &pLunL1); RC_CHECK();
|
---|
1424 | rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(path)); RC_CHECK();
|
---|
1425 | }
|
---|
1426 | }
|
---|
1427 | }
|
---|
1428 |
|
---|
1429 | /*
|
---|
1430 | * Parallel (LPT) Ports
|
---|
1431 | */
|
---|
1432 | rc = CFGMR3InsertNode(pDevices, "parallel", &pDev); RC_CHECK();
|
---|
1433 | for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ulInstance++)
|
---|
1434 | {
|
---|
1435 | ComPtr<IParallelPort> parallelPort;
|
---|
1436 | hrc = pMachine->GetParallelPort (ulInstance, parallelPort.asOutParam()); H();
|
---|
1437 | BOOL fEnabled = FALSE;
|
---|
1438 | if (parallelPort)
|
---|
1439 | hrc = parallelPort->COMGETTER(Enabled)(&fEnabled); H();
|
---|
1440 | if (!fEnabled)
|
---|
1441 | continue;
|
---|
1442 |
|
---|
1443 | char szInstance[4]; Assert(ulInstance <= 999);
|
---|
1444 | RTStrPrintf(szInstance, sizeof(szInstance), "%lu", ulInstance);
|
---|
1445 |
|
---|
1446 | rc = CFGMR3InsertNode(pDev, szInstance, &pInst); RC_CHECK();
|
---|
1447 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1448 |
|
---|
1449 | ULONG ulIRQ, ulIOBase;
|
---|
1450 | Bstr DevicePath;
|
---|
1451 | hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
|
---|
1452 | hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
|
---|
1453 | hrc = parallelPort->COMGETTER(Path)(DevicePath.asOutParam()); H();
|
---|
1454 | rc = CFGMR3InsertInteger(pCfg, "IRQ", ulIRQ); RC_CHECK();
|
---|
1455 | rc = CFGMR3InsertInteger(pCfg, "IOBase", ulIOBase); RC_CHECK();
|
---|
1456 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1457 | rc = CFGMR3InsertString(pLunL0, "Driver", "HostParallel"); RC_CHECK();
|
---|
1458 | rc = CFGMR3InsertNode(pLunL0, "AttachedDriver", &pLunL1); RC_CHECK();
|
---|
1459 | rc = CFGMR3InsertString(pLunL1, "DevicePath", Utf8Str(DevicePath)); RC_CHECK();
|
---|
1460 | }
|
---|
1461 |
|
---|
1462 | /*
|
---|
1463 | * VMM Device
|
---|
1464 | */
|
---|
1465 | rc = CFGMR3InsertNode(pDevices, "VMMDev", &pDev); RC_CHECK();
|
---|
1466 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1467 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1468 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
1469 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 4); RC_CHECK();
|
---|
1470 | Assert(!afPciDeviceNo[4]);
|
---|
1471 | afPciDeviceNo[4] = true;
|
---|
1472 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1473 |
|
---|
1474 | /* the VMM device's Main driver */
|
---|
1475 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1476 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainVMMDev"); RC_CHECK();
|
---|
1477 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1478 | VMMDev *pVMMDev = pConsole->mVMMDev;
|
---|
1479 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pVMMDev); RC_CHECK();
|
---|
1480 |
|
---|
1481 | /*
|
---|
1482 | * Attach the status driver.
|
---|
1483 | */
|
---|
1484 | rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1485 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1486 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1487 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapSharedFolderLed); RC_CHECK();
|
---|
1488 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1489 | rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
|
---|
1490 |
|
---|
1491 | /*
|
---|
1492 | * Audio Sniffer Device
|
---|
1493 | */
|
---|
1494 | rc = CFGMR3InsertNode(pDevices, "AudioSniffer", &pDev); RC_CHECK();
|
---|
1495 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1496 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1497 |
|
---|
1498 | /* the Audio Sniffer device's Main driver */
|
---|
1499 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1500 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainAudioSniffer"); RC_CHECK();
|
---|
1501 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1502 | AudioSniffer *pAudioSniffer = pConsole->mAudioSniffer;
|
---|
1503 | rc = CFGMR3InsertInteger(pCfg, "Object", (uintptr_t)pAudioSniffer); RC_CHECK();
|
---|
1504 |
|
---|
1505 | /*
|
---|
1506 | * AC'97 ICH / SoundBlaster16 audio
|
---|
1507 | */
|
---|
1508 | ComPtr<IAudioAdapter> audioAdapter;
|
---|
1509 | hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
|
---|
1510 | if (audioAdapter)
|
---|
1511 | hrc = audioAdapter->COMGETTER(Enabled)(&enabled); H();
|
---|
1512 |
|
---|
1513 | if (enabled)
|
---|
1514 | {
|
---|
1515 | AudioControllerType_T audioController;
|
---|
1516 | hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
|
---|
1517 | switch (audioController)
|
---|
1518 | {
|
---|
1519 | case AudioControllerType_AC97:
|
---|
1520 | {
|
---|
1521 | /* default: ICH AC97 */
|
---|
1522 | rc = CFGMR3InsertNode(pDevices, "ichac97", &pDev); RC_CHECK();
|
---|
1523 | rc = CFGMR3InsertNode(pDev, "0", &pInst);
|
---|
1524 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
1525 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 5); RC_CHECK();
|
---|
1526 | Assert(!afPciDeviceNo[5]);
|
---|
1527 | afPciDeviceNo[5] = true;
|
---|
1528 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1529 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1530 | break;
|
---|
1531 | }
|
---|
1532 | case AudioControllerType_SB16:
|
---|
1533 | {
|
---|
1534 | /* legacy SoundBlaster16 */
|
---|
1535 | rc = CFGMR3InsertNode(pDevices, "sb16", &pDev); RC_CHECK();
|
---|
1536 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1537 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
1538 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1539 | rc = CFGMR3InsertInteger(pCfg, "IRQ", 5); RC_CHECK();
|
---|
1540 | rc = CFGMR3InsertInteger(pCfg, "DMA", 1); RC_CHECK();
|
---|
1541 | rc = CFGMR3InsertInteger(pCfg, "DMA16", 5); RC_CHECK();
|
---|
1542 | rc = CFGMR3InsertInteger(pCfg, "Port", 0x220); RC_CHECK();
|
---|
1543 | rc = CFGMR3InsertInteger(pCfg, "Version", 0x0405); RC_CHECK();
|
---|
1544 | break;
|
---|
1545 | }
|
---|
1546 | }
|
---|
1547 |
|
---|
1548 | /* the Audio driver */
|
---|
1549 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1550 | rc = CFGMR3InsertString(pLunL0, "Driver", "AUDIO"); RC_CHECK();
|
---|
1551 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1552 |
|
---|
1553 | AudioDriverType_T audioDriver;
|
---|
1554 | hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
|
---|
1555 | switch (audioDriver)
|
---|
1556 | {
|
---|
1557 | case AudioDriverType_Null:
|
---|
1558 | {
|
---|
1559 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "null"); RC_CHECK();
|
---|
1560 | break;
|
---|
1561 | }
|
---|
1562 | #ifdef RT_OS_WINDOWS
|
---|
1563 | #ifdef VBOX_WITH_WINMM
|
---|
1564 | case AudioDriverType_WinMM:
|
---|
1565 | {
|
---|
1566 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "winmm"); RC_CHECK();
|
---|
1567 | break;
|
---|
1568 | }
|
---|
1569 | #endif
|
---|
1570 | case AudioDriverType_DirectSound:
|
---|
1571 | {
|
---|
1572 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "dsound"); RC_CHECK();
|
---|
1573 | break;
|
---|
1574 | }
|
---|
1575 | #endif /* RT_OS_WINDOWS */
|
---|
1576 | #ifdef RT_OS_SOLARIS
|
---|
1577 | case AudioDriverType_SolAudio:
|
---|
1578 | {
|
---|
1579 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "solaudio"); RC_CHECK();
|
---|
1580 | break;
|
---|
1581 | }
|
---|
1582 | #endif
|
---|
1583 | #ifdef RT_OS_LINUX
|
---|
1584 | case AudioDriverType_OSS:
|
---|
1585 | {
|
---|
1586 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "oss"); RC_CHECK();
|
---|
1587 | break;
|
---|
1588 | }
|
---|
1589 | # ifdef VBOX_WITH_ALSA
|
---|
1590 | case AudioDriverType_ALSA:
|
---|
1591 | {
|
---|
1592 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "alsa"); RC_CHECK();
|
---|
1593 | break;
|
---|
1594 | }
|
---|
1595 | # endif
|
---|
1596 | # ifdef VBOX_WITH_PULSE
|
---|
1597 | case AudioDriverType_Pulse:
|
---|
1598 | {
|
---|
1599 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "pulse"); RC_CHECK();
|
---|
1600 | break;
|
---|
1601 | }
|
---|
1602 | # endif
|
---|
1603 | #endif /* RT_OS_LINUX */
|
---|
1604 | #ifdef RT_OS_DARWIN
|
---|
1605 | case AudioDriverType_CoreAudio:
|
---|
1606 | {
|
---|
1607 | rc = CFGMR3InsertString(pCfg, "AudioDriver", "coreaudio"); RC_CHECK();
|
---|
1608 | break;
|
---|
1609 | }
|
---|
1610 | #endif
|
---|
1611 | }
|
---|
1612 | hrc = pMachine->COMGETTER(Name)(&str); H();
|
---|
1613 | STR_CONV();
|
---|
1614 | rc = CFGMR3InsertString(pCfg, "StreamName", psz); RC_CHECK();
|
---|
1615 | STR_FREE();
|
---|
1616 | }
|
---|
1617 |
|
---|
1618 | /*
|
---|
1619 | * The USB Controller.
|
---|
1620 | */
|
---|
1621 | ComPtr<IUSBController> USBCtlPtr;
|
---|
1622 | hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
|
---|
1623 | if (USBCtlPtr)
|
---|
1624 | {
|
---|
1625 | BOOL fEnabled;
|
---|
1626 | hrc = USBCtlPtr->COMGETTER(Enabled)(&fEnabled); H();
|
---|
1627 | if (fEnabled)
|
---|
1628 | {
|
---|
1629 | rc = CFGMR3InsertNode(pDevices, "usb-ohci", &pDev); RC_CHECK();
|
---|
1630 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1631 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1632 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
1633 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 6); RC_CHECK();
|
---|
1634 | Assert(!afPciDeviceNo[6]);
|
---|
1635 | afPciDeviceNo[6] = true;
|
---|
1636 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1637 |
|
---|
1638 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1639 | rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
|
---|
1640 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1641 |
|
---|
1642 | /*
|
---|
1643 | * Attach the status driver.
|
---|
1644 | */
|
---|
1645 | rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1646 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1647 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1648 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[0]);RC_CHECK();
|
---|
1649 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1650 | rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
|
---|
1651 |
|
---|
1652 | #ifdef VBOX_WITH_EHCI
|
---|
1653 | hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEnabled); H();
|
---|
1654 | if (fEnabled)
|
---|
1655 | {
|
---|
1656 | rc = CFGMR3InsertNode(pDevices, "usb-ehci", &pDev); RC_CHECK();
|
---|
1657 | rc = CFGMR3InsertNode(pDev, "0", &pInst); RC_CHECK();
|
---|
1658 | rc = CFGMR3InsertNode(pInst, "Config", &pCfg); RC_CHECK();
|
---|
1659 | rc = CFGMR3InsertInteger(pInst, "Trusted", 1); /* boolean */ RC_CHECK();
|
---|
1660 | rc = CFGMR3InsertInteger(pInst, "PCIDeviceNo", 11); RC_CHECK();
|
---|
1661 | Assert(!afPciDeviceNo[11]);
|
---|
1662 | afPciDeviceNo[11] = true;
|
---|
1663 | rc = CFGMR3InsertInteger(pInst, "PCIFunctionNo", 0); RC_CHECK();
|
---|
1664 |
|
---|
1665 | rc = CFGMR3InsertNode(pInst, "LUN#0", &pLunL0); RC_CHECK();
|
---|
1666 | rc = CFGMR3InsertString(pLunL0, "Driver", "VUSBRootHub"); RC_CHECK();
|
---|
1667 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1668 |
|
---|
1669 | /*
|
---|
1670 | * Attach the status driver.
|
---|
1671 | */
|
---|
1672 | rc = CFGMR3InsertNode(pInst, "LUN#999", &pLunL0); RC_CHECK();
|
---|
1673 | rc = CFGMR3InsertString(pLunL0, "Driver", "MainStatus"); RC_CHECK();
|
---|
1674 | rc = CFGMR3InsertNode(pLunL0, "Config", &pCfg); RC_CHECK();
|
---|
1675 | rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapUSBLed[1]);RC_CHECK();
|
---|
1676 | rc = CFGMR3InsertInteger(pCfg, "First", 0); RC_CHECK();
|
---|
1677 | rc = CFGMR3InsertInteger(pCfg, "Last", 0); RC_CHECK();
|
---|
1678 | }
|
---|
1679 | else
|
---|
1680 | #endif
|
---|
1681 | {
|
---|
1682 | /*
|
---|
1683 | * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
|
---|
1684 | * on a per device level now.
|
---|
1685 | */
|
---|
1686 | rc = CFGMR3InsertNode(pRoot, "USB", &pCfg); RC_CHECK();
|
---|
1687 | rc = CFGMR3InsertNode(pCfg, "USBProxy", &pCfg); RC_CHECK();
|
---|
1688 | rc = CFGMR3InsertNode(pCfg, "GlobalConfig", &pCfg); RC_CHECK();
|
---|
1689 | // This globally enables the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
|
---|
1690 | //rc = CFGMR3InsertInteger(pCfg, "Force11Device", true); RC_CHECK();
|
---|
1691 | // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
|
---|
1692 | // that it's documented somewhere.) Users needing it can use:
|
---|
1693 | // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
|
---|
1694 | //rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
|
---|
1695 | }
|
---|
1696 | }
|
---|
1697 | }
|
---|
1698 |
|
---|
1699 | /*
|
---|
1700 | * Clipboard
|
---|
1701 | */
|
---|
1702 | {
|
---|
1703 | ClipboardMode_T mode = ClipboardMode_Disabled;
|
---|
1704 | hrc = pMachine->COMGETTER(ClipboardMode) (&mode); H();
|
---|
1705 |
|
---|
1706 | if (mode != ClipboardMode_Disabled)
|
---|
1707 | {
|
---|
1708 | /* Load the service */
|
---|
1709 | rc = pConsole->mVMMDev->hgcmLoadService ("VBoxSharedClipboard", "VBoxSharedClipboard");
|
---|
1710 |
|
---|
1711 | if (VBOX_FAILURE (rc))
|
---|
1712 | {
|
---|
1713 | LogRel(("VBoxSharedClipboard is not available. rc = %Vrc\n", rc));
|
---|
1714 | /* That is not a fatal failure. */
|
---|
1715 | rc = VINF_SUCCESS;
|
---|
1716 | }
|
---|
1717 | else
|
---|
1718 | {
|
---|
1719 | /* Setup the service. */
|
---|
1720 | VBOXHGCMSVCPARM parm;
|
---|
1721 |
|
---|
1722 | parm.type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
1723 |
|
---|
1724 | switch (mode)
|
---|
1725 | {
|
---|
1726 | default:
|
---|
1727 | case ClipboardMode_Disabled:
|
---|
1728 | {
|
---|
1729 | LogRel(("VBoxSharedClipboard mode: Off\n"));
|
---|
1730 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
|
---|
1731 | break;
|
---|
1732 | }
|
---|
1733 | case ClipboardMode_GuestToHost:
|
---|
1734 | {
|
---|
1735 | LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
|
---|
1736 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
|
---|
1737 | break;
|
---|
1738 | }
|
---|
1739 | case ClipboardMode_HostToGuest:
|
---|
1740 | {
|
---|
1741 | LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
|
---|
1742 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
|
---|
1743 | break;
|
---|
1744 | }
|
---|
1745 | case ClipboardMode_Bidirectional:
|
---|
1746 | {
|
---|
1747 | LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
|
---|
1748 | parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
|
---|
1749 | break;
|
---|
1750 | }
|
---|
1751 | }
|
---|
1752 |
|
---|
1753 | pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
|
---|
1754 |
|
---|
1755 | Log(("Set VBoxSharedClipboard mode\n"));
|
---|
1756 | }
|
---|
1757 | }
|
---|
1758 | }
|
---|
1759 | #ifdef VBOX_WITH_GUEST_PROPS
|
---|
1760 | /*
|
---|
1761 | * Shared information services
|
---|
1762 | */
|
---|
1763 | {
|
---|
1764 | /* Load the service */
|
---|
1765 | rc = pConsole->mVMMDev->hgcmLoadService ("VBoxGuestPropSvc", "VBoxGuestPropSvc");
|
---|
1766 |
|
---|
1767 | if (VBOX_FAILURE (rc))
|
---|
1768 | {
|
---|
1769 | LogRel(("VBoxGuestPropSvc is not available. rc = %Vrc\n", rc));
|
---|
1770 | /* That is not a fatal failure. */
|
---|
1771 | rc = VINF_SUCCESS;
|
---|
1772 | }
|
---|
1773 | else
|
---|
1774 | {
|
---|
1775 | rc = CFGMR3InsertNode(pRoot, "GuestProps", &pGuestProps); RC_CHECK();
|
---|
1776 | rc = CFGMR3InsertNode(pGuestProps, "Values", &pValues); RC_CHECK();
|
---|
1777 | rc = CFGMR3InsertNode(pGuestProps, "Timestamps", &pTimestamps); RC_CHECK();
|
---|
1778 | rc = CFGMR3InsertNode(pGuestProps, "Flags", &pFlags); RC_CHECK();
|
---|
1779 |
|
---|
1780 | /* Pull over the properties from the server. */
|
---|
1781 | SafeArray <BSTR> names;
|
---|
1782 | SafeArray <BSTR> values;
|
---|
1783 | SafeArray <ULONG64> timestamps;
|
---|
1784 | SafeArray <BSTR> flags;
|
---|
1785 | hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(names),
|
---|
1786 | ComSafeArrayAsOutParam(values),
|
---|
1787 | ComSafeArrayAsOutParam(timestamps),
|
---|
1788 | ComSafeArrayAsOutParam(flags)); H();
|
---|
1789 | size_t cProps = names.size();
|
---|
1790 | for (size_t i = 0; i < cProps; ++i)
|
---|
1791 | {
|
---|
1792 | rc = CFGMR3InsertString(pValues, Utf8Str(names[i]).raw(), Utf8Str(values[i]).raw()); RC_CHECK();
|
---|
1793 | rc = CFGMR3InsertInteger(pTimestamps, Utf8Str(names[i]).raw(), timestamps[i]); RC_CHECK();
|
---|
1794 | rc = CFGMR3InsertString(pFlags, Utf8Str(names[i]).raw(), Utf8Str(flags[i]).raw()); RC_CHECK();
|
---|
1795 | }
|
---|
1796 |
|
---|
1797 | /* Setup the service. */
|
---|
1798 | VBOXHGCMSVCPARM parms[3];
|
---|
1799 |
|
---|
1800 | parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
1801 | parms[0].u.pointer.addr = pValues;
|
---|
1802 | parms[0].u.pointer.size = sizeof(pValues); /* We don't actually care. */
|
---|
1803 | parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
1804 | parms[1].u.pointer.addr = pTimestamps;
|
---|
1805 | parms[1].u.pointer.size = sizeof(pTimestamps);
|
---|
1806 | parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
1807 | parms[2].u.pointer.addr = pFlags;
|
---|
1808 | parms[2].u.pointer.size = sizeof(pFlags);
|
---|
1809 |
|
---|
1810 | pConsole->mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", guestProp::SET_CFGM_NODE, 3, &parms[0]);
|
---|
1811 |
|
---|
1812 | Log(("Set VBoxGuestPropSvc property store\n"));
|
---|
1813 | }
|
---|
1814 | }
|
---|
1815 | #endif /* VBOX_WITH_GUEST_PROPS defined */
|
---|
1816 |
|
---|
1817 | /*
|
---|
1818 | * CFGM overlay handling.
|
---|
1819 | *
|
---|
1820 | * Here we check the extra data entries for CFGM values
|
---|
1821 | * and create the nodes and insert the values on the fly. Existing
|
---|
1822 | * values will be removed and reinserted. If a value is a valid number,
|
---|
1823 | * it will be inserted as a number, otherwise as a string.
|
---|
1824 | *
|
---|
1825 | * We first perform a run on global extra data, then on the machine
|
---|
1826 | * extra data to support global settings with local overrides.
|
---|
1827 | *
|
---|
1828 | */
|
---|
1829 | Bstr strExtraDataKey;
|
---|
1830 | bool fGlobalExtraData = true;
|
---|
1831 | for (;;)
|
---|
1832 | {
|
---|
1833 | Bstr strNextExtraDataKey;
|
---|
1834 | Bstr strExtraDataValue;
|
---|
1835 |
|
---|
1836 | /* get the next key */
|
---|
1837 | if (fGlobalExtraData)
|
---|
1838 | hrc = virtualBox->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
|
---|
1839 | strExtraDataValue.asOutParam());
|
---|
1840 | else
|
---|
1841 | hrc = pMachine->GetNextExtraDataKey(strExtraDataKey, strNextExtraDataKey.asOutParam(),
|
---|
1842 | strExtraDataValue.asOutParam());
|
---|
1843 |
|
---|
1844 | /* stop if for some reason there's nothing more to request */
|
---|
1845 | if (FAILED(hrc) || !strNextExtraDataKey)
|
---|
1846 | {
|
---|
1847 | /* if we're out of global keys, continue with machine, otherwise we're done */
|
---|
1848 | if (fGlobalExtraData)
|
---|
1849 | {
|
---|
1850 | fGlobalExtraData = false;
|
---|
1851 | strExtraDataKey.setNull();
|
---|
1852 | continue;
|
---|
1853 | }
|
---|
1854 | break;
|
---|
1855 | }
|
---|
1856 |
|
---|
1857 | strExtraDataKey = strNextExtraDataKey;
|
---|
1858 | Utf8Str strExtraDataKeyUtf8 = Utf8Str(strExtraDataKey);
|
---|
1859 |
|
---|
1860 | /* we only care about keys starting with "VBoxInternal/" */
|
---|
1861 | if (strncmp(strExtraDataKeyUtf8.raw(), "VBoxInternal/", 13) != 0)
|
---|
1862 | continue;
|
---|
1863 | char *pszExtraDataKey = (char*)strExtraDataKeyUtf8.raw() + 13;
|
---|
1864 |
|
---|
1865 | /* the key will be in the format "Node1/Node2/Value" or simply "Value". */
|
---|
1866 | PCFGMNODE pNode;
|
---|
1867 | char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
|
---|
1868 | if (pszCFGMValueName)
|
---|
1869 | {
|
---|
1870 | /* terminate the node and advance to the value */
|
---|
1871 | *pszCFGMValueName = '\0';
|
---|
1872 | pszCFGMValueName++;
|
---|
1873 |
|
---|
1874 | /* does the node already exist? */
|
---|
1875 | pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
|
---|
1876 | if (pNode)
|
---|
1877 | {
|
---|
1878 | /* the value might already exist, remove it to be safe */
|
---|
1879 | CFGMR3RemoveValue(pNode, pszCFGMValueName);
|
---|
1880 | }
|
---|
1881 | else
|
---|
1882 | {
|
---|
1883 | /* create the node */
|
---|
1884 | rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
|
---|
1885 | AssertMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
|
---|
1886 | if (VBOX_FAILURE(rc) || !pNode)
|
---|
1887 | continue;
|
---|
1888 | }
|
---|
1889 | }
|
---|
1890 | else
|
---|
1891 | {
|
---|
1892 | pNode = pRoot;
|
---|
1893 | pszCFGMValueName = pszExtraDataKey;
|
---|
1894 | pszExtraDataKey--;
|
---|
1895 |
|
---|
1896 | /* the value might already exist, remove it to be safe */
|
---|
1897 | CFGMR3RemoveValue(pNode, pszCFGMValueName);
|
---|
1898 | }
|
---|
1899 |
|
---|
1900 | /* now let's have a look at the value */
|
---|
1901 | Utf8Str strCFGMValueUtf8 = Utf8Str(strExtraDataValue);
|
---|
1902 | const char *pszCFGMValue = strCFGMValueUtf8.raw();
|
---|
1903 | /* empty value means remove value which we've already done */
|
---|
1904 | if (pszCFGMValue && *pszCFGMValue)
|
---|
1905 | {
|
---|
1906 | /* if it's a valid number, we'll insert it as such, otherwise string */
|
---|
1907 | uint64_t u64Value;
|
---|
1908 | char *pszNext = NULL;
|
---|
1909 | if ( RTStrToUInt64Ex(pszCFGMValue, &pszNext, 0, &u64Value) == VINF_SUCCESS
|
---|
1910 | && (!pszNext || *pszNext == '\0') /* check if the _whole_ string is a valid number */
|
---|
1911 | )
|
---|
1912 | {
|
---|
1913 | rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
|
---|
1914 | }
|
---|
1915 | else
|
---|
1916 | {
|
---|
1917 | rc = CFGMR3InsertString(pNode, pszCFGMValueName, pszCFGMValue);
|
---|
1918 | }
|
---|
1919 | AssertMsgRC(rc, ("failed to insert CFGM value '%s' to key '%s'\n", pszCFGMValue, pszExtraDataKey));
|
---|
1920 | }
|
---|
1921 | }
|
---|
1922 |
|
---|
1923 | #undef H
|
---|
1924 | #undef RC_CHECK
|
---|
1925 | #undef STR_FREE
|
---|
1926 | #undef STR_CONV
|
---|
1927 |
|
---|
1928 | /* Register VM state change handler */
|
---|
1929 | int rc2 = VMR3AtStateRegister (pVM, Console::vmstateChangeCallback, pConsole);
|
---|
1930 | AssertRC (rc2);
|
---|
1931 | if (VBOX_SUCCESS (rc))
|
---|
1932 | rc = rc2;
|
---|
1933 |
|
---|
1934 | /* Register VM runtime error handler */
|
---|
1935 | rc2 = VMR3AtRuntimeErrorRegister (pVM, Console::setVMRuntimeErrorCallback, pConsole);
|
---|
1936 | AssertRC (rc2);
|
---|
1937 | if (VBOX_SUCCESS (rc))
|
---|
1938 | rc = rc2;
|
---|
1939 |
|
---|
1940 | /* Save the VM pointer in the machine object */
|
---|
1941 | pConsole->mpVM = pVM;
|
---|
1942 |
|
---|
1943 | LogFlowFunc (("vrc = %Vrc\n", rc));
|
---|
1944 | LogFlowFuncLeave();
|
---|
1945 |
|
---|
1946 | return rc;
|
---|
1947 | }
|
---|
1948 |
|
---|
1949 |
|
---|