[7964] | 1 | /* $Id: HostImpl.cpp 16560 2009-02-06 18:06:04Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[7964] | 3 | * VirtualBox COM class implementation: Host
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[8155] | 7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
[1] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
[5999] | 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
[8155] | 16 | *
|
---|
| 17 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
| 18 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
| 19 | * additional information or have any questions.
|
---|
[1] | 20 | */
|
---|
| 21 |
|
---|
[9335] | 22 | #define __STDC_LIMIT_MACROS
|
---|
| 23 | #define __STDC_CONSTANT_MACROS
|
---|
| 24 |
|
---|
[3668] | 25 | #ifdef RT_OS_LINUX
|
---|
[14991] | 26 | // # include <sys/types.h>
|
---|
| 27 | // # include <sys/stat.h>
|
---|
| 28 | // # include <unistd.h>
|
---|
[9335] | 29 | # include <sys/ioctl.h>
|
---|
[14991] | 30 | // # include <fcntl.h>
|
---|
| 31 | // # include <mntent.h>
|
---|
[1] | 32 | /* bird: This is a hack to work around conflicts between these linux kernel headers
|
---|
| 33 | * and the GLIBC tcpip headers. They have different declarations of the 4
|
---|
| 34 | * standard byte order functions. */
|
---|
[14991] | 35 | // # define _LINUX_BYTEORDER_GENERIC_H
|
---|
| 36 | // # include <linux/cdrom.h>
|
---|
[9335] | 37 | # include <errno.h>
|
---|
[13938] | 38 | # include <net/if.h>
|
---|
[14283] | 39 | # include <net/if_arp.h>
|
---|
[3668] | 40 | #endif /* RT_OS_LINUX */
|
---|
[1] | 41 |
|
---|
[5186] | 42 | #ifdef RT_OS_SOLARIS
|
---|
| 43 | # include <fcntl.h>
|
---|
| 44 | # include <unistd.h>
|
---|
| 45 | # include <stropts.h>
|
---|
| 46 | # include <errno.h>
|
---|
| 47 | # include <limits.h>
|
---|
| 48 | # include <stdio.h>
|
---|
[12866] | 49 | # ifdef VBOX_SOLARIS_NSL_RESOLVED
|
---|
[12783] | 50 | # include <libdevinfo.h>
|
---|
[13426] | 51 | # endif
|
---|
| 52 | # include <net/if.h>
|
---|
| 53 | # include <sys/socket.h>
|
---|
| 54 | # include <sys/sockio.h>
|
---|
| 55 | # include <net/if_arp.h>
|
---|
| 56 | # include <net/if.h>
|
---|
[5186] | 57 | # include <sys/types.h>
|
---|
| 58 | # include <sys/stat.h>
|
---|
| 59 | # include <sys/cdio.h>
|
---|
| 60 | # include <sys/dkio.h>
|
---|
| 61 | # include <sys/mnttab.h>
|
---|
| 62 | # include <sys/mntent.h>
|
---|
[14722] | 63 | /* Dynamic loading of libhal on Solaris hosts */
|
---|
[5186] | 64 | # ifdef VBOX_USE_LIBHAL
|
---|
| 65 | # include "vbox-libhal.h"
|
---|
| 66 | extern "C" char *getfullrawname(char *);
|
---|
| 67 | # endif
|
---|
[12866] | 68 | # include "solaris/DynLoadLibSolaris.h"
|
---|
[5186] | 69 | #endif /* RT_OS_SOLARIS */
|
---|
| 70 |
|
---|
[3668] | 71 | #ifdef RT_OS_WINDOWS
|
---|
[9335] | 72 | # define _WIN32_DCOM
|
---|
| 73 | # include <windows.h>
|
---|
| 74 | # include <shellapi.h>
|
---|
| 75 | # define INITGUID
|
---|
| 76 | # include <guiddef.h>
|
---|
| 77 | # include <devguid.h>
|
---|
| 78 | # include <objbase.h>
|
---|
| 79 | # include <setupapi.h>
|
---|
| 80 | # include <shlobj.h>
|
---|
| 81 | # include <cfgmgr32.h>
|
---|
[12439] | 82 |
|
---|
[3668] | 83 | #endif /* RT_OS_WINDOWS */
|
---|
[1] | 84 |
|
---|
| 85 |
|
---|
| 86 | #include "HostImpl.h"
|
---|
| 87 | #include "HostDVDDriveImpl.h"
|
---|
| 88 | #include "HostFloppyDriveImpl.h"
|
---|
[10896] | 89 | #include "HostNetworkInterfaceImpl.h"
|
---|
[7964] | 90 | #ifdef VBOX_WITH_USB
|
---|
| 91 | # include "HostUSBDeviceImpl.h"
|
---|
| 92 | # include "USBDeviceFilterImpl.h"
|
---|
| 93 | # include "USBProxyService.h"
|
---|
| 94 | #endif
|
---|
[1] | 95 | #include "VirtualBoxImpl.h"
|
---|
| 96 | #include "MachineImpl.h"
|
---|
| 97 | #include "Logging.h"
|
---|
| 98 |
|
---|
[3668] | 99 | #ifdef RT_OS_DARWIN
|
---|
[7964] | 100 | # include "darwin/iokit.h"
|
---|
[1906] | 101 | #endif
|
---|
| 102 |
|
---|
[1] | 103 |
|
---|
[14820] | 104 | #include <iprt/asm.h>
|
---|
[1] | 105 | #include <iprt/string.h>
|
---|
[10399] | 106 | #include <iprt/mp.h>
|
---|
[1] | 107 | #include <iprt/time.h>
|
---|
| 108 | #include <iprt/param.h>
|
---|
[5107] | 109 | #include <iprt/env.h>
|
---|
[14991] | 110 | #include <iprt/mem.h>
|
---|
[5186] | 111 | #ifdef RT_OS_SOLARIS
|
---|
| 112 | # include <iprt/path.h>
|
---|
[11993] | 113 | # include <iprt/ctype.h>
|
---|
[5186] | 114 | #endif
|
---|
[15235] | 115 | #ifdef VBOX_WITH_HOSTNETIF_API
|
---|
[15372] | 116 | #include "netif.h"
|
---|
[15235] | 117 | #endif
|
---|
[1] | 118 |
|
---|
[16560] | 119 | #include <VBox/usb.h>
|
---|
| 120 | #include <VBox/x86.h>
|
---|
| 121 | #include <VBox/err.h>
|
---|
| 122 | #include <VBox/settings.h>
|
---|
| 123 |
|
---|
[13234] | 124 | #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
|
---|
[13720] | 125 | # include <VBox/WinNetConfig.h>
|
---|
[13234] | 126 | #endif /* #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT) */
|
---|
| 127 |
|
---|
[1] | 128 | #include <stdio.h>
|
---|
| 129 |
|
---|
| 130 | #include <algorithm>
|
---|
| 131 |
|
---|
[13234] | 132 |
|
---|
| 133 |
|
---|
[1] | 134 | // constructor / destructor
|
---|
| 135 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 136 |
|
---|
| 137 | HRESULT Host::FinalConstruct()
|
---|
| 138 | {
|
---|
| 139 | return S_OK;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | void Host::FinalRelease()
|
---|
| 143 | {
|
---|
| 144 | if (isReady())
|
---|
| 145 | uninit();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | // public initializer/uninitializer for internal purposes only
|
---|
| 149 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 150 |
|
---|
| 151 | /**
|
---|
| 152 | * Initializes the host object.
|
---|
| 153 | *
|
---|
[10595] | 154 | * @param aParent VirtualBox parent object.
|
---|
[1] | 155 | */
|
---|
[10595] | 156 | HRESULT Host::init (VirtualBox *aParent)
|
---|
[1] | 157 | {
|
---|
[3001] | 158 | LogFlowThisFunc (("isReady=%d\n", isReady()));
|
---|
[1] | 159 |
|
---|
[10595] | 160 | ComAssertRet (aParent, E_INVALIDARG);
|
---|
[1] | 161 |
|
---|
[8083] | 162 | AutoWriteLock alock (this);
|
---|
[14579] | 163 | ComAssertRet (!isReady(), E_FAIL);
|
---|
[1] | 164 |
|
---|
[10595] | 165 | mParent = aParent;
|
---|
[1] | 166 |
|
---|
[8744] | 167 | #ifdef VBOX_WITH_USB
|
---|
| 168 | /*
|
---|
| 169 | * Create and initialize the USB Proxy Service.
|
---|
| 170 | */
|
---|
| 171 | # if defined (RT_OS_DARWIN)
|
---|
[2587] | 172 | mUSBProxyService = new USBProxyServiceDarwin (this);
|
---|
[8744] | 173 | # elif defined (RT_OS_LINUX)
|
---|
[1] | 174 | mUSBProxyService = new USBProxyServiceLinux (this);
|
---|
[8744] | 175 | # elif defined (RT_OS_OS2)
|
---|
[5652] | 176 | mUSBProxyService = new USBProxyServiceOs2 (this);
|
---|
[13433] | 177 | # elif defined (RT_OS_SOLARIS)
|
---|
[8745] | 178 | mUSBProxyService = new USBProxyServiceSolaris (this);
|
---|
[8744] | 179 | # elif defined (RT_OS_WINDOWS)
|
---|
[8766] | 180 | mUSBProxyService = new USBProxyServiceWindows (this);
|
---|
[8745] | 181 | # else
|
---|
[1] | 182 | mUSBProxyService = new USBProxyService (this);
|
---|
[8744] | 183 | # endif
|
---|
| 184 | HRESULT hrc = mUSBProxyService->init();
|
---|
| 185 | AssertComRCReturn(hrc, hrc);
|
---|
| 186 | #endif /* VBOX_WITH_USB */
|
---|
[1] | 187 |
|
---|
[9904] | 188 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
[10595] | 189 | registerMetrics (aParent->performanceCollector());
|
---|
[9904] | 190 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
| 191 |
|
---|
[13655] | 192 | #if defined (RT_OS_WINDOWS)
|
---|
| 193 | mHostPowerService = new HostPowerServiceWin (mParent);
|
---|
[14527] | 194 | #elif defined (RT_OS_DARWIN)
|
---|
| 195 | mHostPowerService = new HostPowerServiceDarwin (mParent);
|
---|
[13655] | 196 | #else
|
---|
| 197 | mHostPowerService = new HostPowerService (mParent);
|
---|
| 198 | #endif
|
---|
[14523] | 199 |
|
---|
| 200 | /* Cache the features reported by GetProcessorFeature. */
|
---|
| 201 | fVTxAMDVSupported = false;
|
---|
| 202 | fLongModeSupported = false;
|
---|
| 203 | fPAESupported = false;
|
---|
| 204 |
|
---|
| 205 | if (ASMHasCpuId())
|
---|
| 206 | {
|
---|
| 207 | uint32_t u32FeaturesECX;
|
---|
| 208 | uint32_t u32Dummy;
|
---|
| 209 | uint32_t u32FeaturesEDX;
|
---|
| 210 | uint32_t u32VendorEBX, u32VendorECX, u32VendorEDX, u32AMDFeatureEDX, u32AMDFeatureECX;
|
---|
| 211 |
|
---|
| 212 | ASMCpuId (0, &u32Dummy, &u32VendorEBX, &u32VendorECX, &u32VendorEDX);
|
---|
| 213 | ASMCpuId (1, &u32Dummy, &u32Dummy, &u32FeaturesECX, &u32FeaturesEDX);
|
---|
| 214 | /* Query AMD features. */
|
---|
| 215 | ASMCpuId (0x80000001, &u32Dummy, &u32Dummy, &u32AMDFeatureECX, &u32AMDFeatureEDX);
|
---|
| 216 |
|
---|
| 217 | fLongModeSupported = !!(u32AMDFeatureEDX & X86_CPUID_AMD_FEATURE_EDX_LONG_MODE);
|
---|
| 218 | fPAESupported = !!(u32FeaturesEDX & X86_CPUID_FEATURE_EDX_PAE);
|
---|
| 219 |
|
---|
| 220 | if ( u32VendorEBX == X86_CPUID_VENDOR_INTEL_EBX
|
---|
| 221 | && u32VendorECX == X86_CPUID_VENDOR_INTEL_ECX
|
---|
| 222 | && u32VendorEDX == X86_CPUID_VENDOR_INTEL_EDX
|
---|
| 223 | )
|
---|
| 224 | {
|
---|
| 225 | if ( (u32FeaturesECX & X86_CPUID_FEATURE_ECX_VMX)
|
---|
| 226 | && (u32FeaturesEDX & X86_CPUID_FEATURE_EDX_MSR)
|
---|
| 227 | && (u32FeaturesEDX & X86_CPUID_FEATURE_EDX_FXSR)
|
---|
| 228 | )
|
---|
| 229 | fVTxAMDVSupported = true;
|
---|
| 230 | }
|
---|
| 231 | else
|
---|
| 232 | if ( u32VendorEBX == X86_CPUID_VENDOR_AMD_EBX
|
---|
| 233 | && u32VendorECX == X86_CPUID_VENDOR_AMD_ECX
|
---|
| 234 | && u32VendorEDX == X86_CPUID_VENDOR_AMD_EDX
|
---|
| 235 | )
|
---|
| 236 | {
|
---|
| 237 | if ( (u32AMDFeatureECX & X86_CPUID_AMD_FEATURE_ECX_SVM)
|
---|
| 238 | && (u32FeaturesEDX & X86_CPUID_FEATURE_EDX_MSR)
|
---|
| 239 | && (u32FeaturesEDX & X86_CPUID_FEATURE_EDX_FXSR)
|
---|
| 240 | )
|
---|
| 241 | fVTxAMDVSupported = true;
|
---|
| 242 | }
|
---|
| 243 | }
|
---|
| 244 |
|
---|
[1] | 245 | setReady(true);
|
---|
| 246 | return S_OK;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | /**
|
---|
| 250 | * Uninitializes the host object and sets the ready flag to FALSE.
|
---|
| 251 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
| 252 | */
|
---|
| 253 | void Host::uninit()
|
---|
| 254 | {
|
---|
[3001] | 255 | LogFlowThisFunc (("isReady=%d\n", isReady()));
|
---|
[1] | 256 |
|
---|
| 257 | AssertReturn (isReady(), (void) 0);
|
---|
| 258 |
|
---|
[10544] | 259 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
[10595] | 260 | unregisterMetrics (mParent->performanceCollector());
|
---|
[10544] | 261 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
| 262 |
|
---|
[7964] | 263 | #ifdef VBOX_WITH_USB
|
---|
[3001] | 264 | /* wait for USB proxy service to terminate before we uninit all USB
|
---|
| 265 | * devices */
|
---|
| 266 | LogFlowThisFunc (("Stopping USB proxy service...\n"));
|
---|
[1] | 267 | delete mUSBProxyService;
|
---|
[7964] | 268 | mUSBProxyService = NULL;
|
---|
[3001] | 269 | LogFlowThisFunc (("Done stopping USB proxy service.\n"));
|
---|
[7964] | 270 | #endif
|
---|
[1] | 271 |
|
---|
[13655] | 272 | delete mHostPowerService;
|
---|
| 273 |
|
---|
[3001] | 274 | /* uninit all USB device filters still referenced by clients */
|
---|
| 275 | uninitDependentChildren();
|
---|
| 276 |
|
---|
[7964] | 277 | #ifdef VBOX_WITH_USB
|
---|
[1] | 278 | mUSBDeviceFilters.clear();
|
---|
[7964] | 279 | #endif
|
---|
[1] | 280 |
|
---|
| 281 | setReady (FALSE);
|
---|
| 282 | }
|
---|
| 283 |
|
---|
| 284 | // IHost properties
|
---|
| 285 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 286 |
|
---|
| 287 | /**
|
---|
| 288 | * Returns a list of host DVD drives.
|
---|
| 289 | *
|
---|
| 290 | * @returns COM status code
|
---|
| 291 | * @param drives address of result pointer
|
---|
| 292 | */
|
---|
[14996] | 293 | STDMETHODIMP Host::COMGETTER(DVDDrives) (IHostDVDDriveCollection **aDrives)
|
---|
[1] | 294 | {
|
---|
[14996] | 295 | CheckComArgOutPointerValid(aDrives);
|
---|
[8083] | 296 | AutoWriteLock alock (this);
|
---|
[1] | 297 | CHECK_READY();
|
---|
| 298 | std::list <ComObjPtr <HostDVDDrive> > list;
|
---|
[14991] | 299 | HRESULT rc = S_OK;
|
---|
[1] | 300 |
|
---|
[3668] | 301 | #if defined(RT_OS_WINDOWS)
|
---|
[1] | 302 | int sz = GetLogicalDriveStrings(0, NULL);
|
---|
| 303 | TCHAR *hostDrives = new TCHAR[sz+1];
|
---|
| 304 | GetLogicalDriveStrings(sz, hostDrives);
|
---|
| 305 | wchar_t driveName[3] = { '?', ':', '\0' };
|
---|
| 306 | TCHAR *p = hostDrives;
|
---|
| 307 | do
|
---|
| 308 | {
|
---|
| 309 | if (GetDriveType(p) == DRIVE_CDROM)
|
---|
| 310 | {
|
---|
| 311 | driveName[0] = *p;
|
---|
| 312 | ComObjPtr <HostDVDDrive> hostDVDDriveObj;
|
---|
| 313 | hostDVDDriveObj.createObject();
|
---|
| 314 | hostDVDDriveObj->init (Bstr (driveName));
|
---|
| 315 | list.push_back (hostDVDDriveObj);
|
---|
| 316 | }
|
---|
| 317 | p += _tcslen(p) + 1;
|
---|
| 318 | }
|
---|
| 319 | while (*p);
|
---|
| 320 | delete[] hostDrives;
|
---|
[5186] | 321 |
|
---|
| 322 | #elif defined(RT_OS_SOLARIS)
|
---|
| 323 | # ifdef VBOX_USE_LIBHAL
|
---|
| 324 | if (!getDVDInfoFromHal(list))
|
---|
| 325 | # endif
|
---|
| 326 | // Not all Solaris versions ship with libhal.
|
---|
| 327 | // So use a fallback approach similar to Linux.
|
---|
| 328 | {
|
---|
| 329 | if (RTEnvGet("VBOX_CDROM"))
|
---|
| 330 | {
|
---|
| 331 | char *cdromEnv = strdup(RTEnvGet("VBOX_CDROM"));
|
---|
| 332 | char *cdromDrive;
|
---|
| 333 | cdromDrive = strtok(cdromEnv, ":"); /** @todo use strtok_r. */
|
---|
| 334 | while (cdromDrive)
|
---|
| 335 | {
|
---|
| 336 | if (validateDevice(cdromDrive, true))
|
---|
| 337 | {
|
---|
| 338 | ComObjPtr <HostDVDDrive> hostDVDDriveObj;
|
---|
| 339 | hostDVDDriveObj.createObject();
|
---|
| 340 | hostDVDDriveObj->init (Bstr (cdromDrive));
|
---|
| 341 | list.push_back (hostDVDDriveObj);
|
---|
| 342 | }
|
---|
| 343 | cdromDrive = strtok(NULL, ":");
|
---|
| 344 | }
|
---|
| 345 | free(cdromEnv);
|
---|
| 346 | }
|
---|
| 347 | else
|
---|
| 348 | {
|
---|
| 349 | // this might work on Solaris version older than Nevada.
|
---|
| 350 | if (validateDevice("/cdrom/cdrom0", true))
|
---|
| 351 | {
|
---|
| 352 | ComObjPtr <HostDVDDrive> hostDVDDriveObj;
|
---|
| 353 | hostDVDDriveObj.createObject();
|
---|
| 354 | hostDVDDriveObj->init (Bstr ("cdrom/cdrom0"));
|
---|
| 355 | list.push_back (hostDVDDriveObj);
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | // check the mounted drives
|
---|
| 359 | parseMountTable(MNTTAB, list);
|
---|
| 360 | }
|
---|
| 361 | }
|
---|
| 362 |
|
---|
[3668] | 363 | #elif defined(RT_OS_LINUX)
|
---|
[14991] | 364 | if (RT_SUCCESS (mHostDrives.updateDVDs()))
|
---|
| 365 | for (DriveInfoList::const_iterator it = mHostDrives.DVDBegin();
|
---|
[15752] | 366 | SUCCEEDED (rc) && it != mHostDrives.DVDEnd(); ++it)
|
---|
[1] | 367 | {
|
---|
[14991] | 368 | ComObjPtr<HostDVDDrive> hostDVDDriveObj;
|
---|
| 369 | Bstr device (it->mDevice.c_str());
|
---|
| 370 | Bstr udi (it->mUdi.empty() ? NULL : it->mUdi.c_str());
|
---|
| 371 | Bstr description (it->mDescription.empty() ? NULL : it->mDescription.c_str());
|
---|
| 372 | if (device.isNull() || (!it->mUdi.empty() && udi.isNull()) ||
|
---|
| 373 | (!it->mDescription.empty() && description.isNull()))
|
---|
| 374 | rc = E_OUTOFMEMORY;
|
---|
| 375 | if (SUCCEEDED (rc))
|
---|
| 376 | rc = hostDVDDriveObj.createObject();
|
---|
| 377 | if (SUCCEEDED (rc))
|
---|
| 378 | rc = hostDVDDriveObj->init (device, udi, description);
|
---|
| 379 | if (SUCCEEDED (rc))
|
---|
| 380 | list.push_back(hostDVDDriveObj);
|
---|
[1] | 381 | }
|
---|
[3668] | 382 | #elif defined(RT_OS_DARWIN)
|
---|
[1906] | 383 | PDARWINDVD cur = DarwinGetDVDDrives();
|
---|
| 384 | while (cur)
|
---|
| 385 | {
|
---|
| 386 | ComObjPtr<HostDVDDrive> hostDVDDriveObj;
|
---|
| 387 | hostDVDDriveObj.createObject();
|
---|
| 388 | hostDVDDriveObj->init(Bstr(cur->szName));
|
---|
| 389 | list.push_back(hostDVDDriveObj);
|
---|
| 390 |
|
---|
| 391 | /* next */
|
---|
| 392 | void *freeMe = cur;
|
---|
| 393 | cur = cur->pNext;
|
---|
| 394 | RTMemFree(freeMe);
|
---|
| 395 | }
|
---|
| 396 |
|
---|
[606] | 397 | #else
|
---|
| 398 | /* PORTME */
|
---|
[1] | 399 | #endif
|
---|
| 400 |
|
---|
| 401 | ComObjPtr<HostDVDDriveCollection> collection;
|
---|
| 402 | collection.createObject();
|
---|
| 403 | collection->init (list);
|
---|
[14996] | 404 | collection.queryInterfaceTo(aDrives);
|
---|
[14991] | 405 | return rc;
|
---|
[1] | 406 | }
|
---|
| 407 |
|
---|
| 408 | /**
|
---|
| 409 | * Returns a list of host floppy drives.
|
---|
| 410 | *
|
---|
| 411 | * @returns COM status code
|
---|
| 412 | * @param drives address of result pointer
|
---|
| 413 | */
|
---|
[14996] | 414 | STDMETHODIMP Host::COMGETTER(FloppyDrives) (IHostFloppyDriveCollection **aDrives)
|
---|
[1] | 415 | {
|
---|
[14996] | 416 | CheckComArgOutPointerValid(aDrives);
|
---|
[8083] | 417 | AutoWriteLock alock (this);
|
---|
[1] | 418 | CHECK_READY();
|
---|
| 419 |
|
---|
| 420 | std::list <ComObjPtr <HostFloppyDrive> > list;
|
---|
[14991] | 421 | HRESULT rc = S_OK;
|
---|
[1] | 422 |
|
---|
[3668] | 423 | #ifdef RT_OS_WINDOWS
|
---|
[1] | 424 | int sz = GetLogicalDriveStrings(0, NULL);
|
---|
| 425 | TCHAR *hostDrives = new TCHAR[sz+1];
|
---|
| 426 | GetLogicalDriveStrings(sz, hostDrives);
|
---|
| 427 | wchar_t driveName[3] = { '?', ':', '\0' };
|
---|
| 428 | TCHAR *p = hostDrives;
|
---|
| 429 | do
|
---|
| 430 | {
|
---|
| 431 | if (GetDriveType(p) == DRIVE_REMOVABLE)
|
---|
| 432 | {
|
---|
| 433 | driveName[0] = *p;
|
---|
| 434 | ComObjPtr <HostFloppyDrive> hostFloppyDriveObj;
|
---|
| 435 | hostFloppyDriveObj.createObject();
|
---|
| 436 | hostFloppyDriveObj->init (Bstr (driveName));
|
---|
| 437 | list.push_back (hostFloppyDriveObj);
|
---|
| 438 | }
|
---|
| 439 | p += _tcslen(p) + 1;
|
---|
| 440 | }
|
---|
| 441 | while (*p);
|
---|
| 442 | delete[] hostDrives;
|
---|
[3668] | 443 | #elif defined(RT_OS_LINUX)
|
---|
[14991] | 444 | if (RT_SUCCESS (mHostDrives.updateFloppies()))
|
---|
| 445 | for (DriveInfoList::const_iterator it = mHostDrives.FloppyBegin();
|
---|
[15752] | 446 | SUCCEEDED (rc) && it != mHostDrives.FloppyEnd(); ++it)
|
---|
[1] | 447 | {
|
---|
[14991] | 448 | ComObjPtr<HostFloppyDrive> hostFloppyDriveObj;
|
---|
| 449 | Bstr device (it->mDevice.c_str());
|
---|
| 450 | Bstr udi (it->mUdi.empty() ? NULL : it->mUdi.c_str());
|
---|
| 451 | Bstr description (it->mDescription.empty() ? NULL : it->mDescription.c_str());
|
---|
| 452 | if (device.isNull() || (!it->mUdi.empty() && udi.isNull()) ||
|
---|
| 453 | (!it->mDescription.empty() && description.isNull()))
|
---|
| 454 | rc = E_OUTOFMEMORY;
|
---|
| 455 | if (SUCCEEDED (rc))
|
---|
| 456 | rc = hostFloppyDriveObj.createObject();
|
---|
| 457 | if (SUCCEEDED (rc))
|
---|
| 458 | rc = hostFloppyDriveObj->init (device, udi, description);
|
---|
| 459 | if (SUCCEEDED (rc))
|
---|
| 460 | list.push_back(hostFloppyDriveObj);
|
---|
[1] | 461 | }
|
---|
[606] | 462 | #else
|
---|
| 463 | /* PORTME */
|
---|
[1] | 464 | #endif
|
---|
| 465 |
|
---|
| 466 | ComObjPtr<HostFloppyDriveCollection> collection;
|
---|
| 467 | collection.createObject();
|
---|
| 468 | collection->init (list);
|
---|
[14996] | 469 | collection.queryInterfaceTo(aDrives);
|
---|
[14991] | 470 | return rc;
|
---|
[1] | 471 | }
|
---|
| 472 |
|
---|
[3668] | 473 | #ifdef RT_OS_WINDOWS
|
---|
[10896] | 474 | /**
|
---|
| 475 | * Windows helper function for Host::COMGETTER(NetworkInterfaces).
|
---|
| 476 | *
|
---|
| 477 | * @returns true / false.
|
---|
| 478 | *
|
---|
| 479 | * @param guid The GUID.
|
---|
| 480 | */
|
---|
[1] | 481 | static bool IsTAPDevice(const char *guid)
|
---|
| 482 | {
|
---|
| 483 | HKEY hNetcard;
|
---|
| 484 | LONG status;
|
---|
| 485 | DWORD len;
|
---|
| 486 | int i = 0;
|
---|
| 487 | bool ret = false;
|
---|
| 488 |
|
---|
| 489 | status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ, &hNetcard);
|
---|
| 490 | if (status != ERROR_SUCCESS)
|
---|
| 491 | return false;
|
---|
| 492 |
|
---|
[10896] | 493 | for (;;)
|
---|
[1] | 494 | {
|
---|
| 495 | char szEnumName[256];
|
---|
| 496 | char szNetCfgInstanceId[256];
|
---|
| 497 | DWORD dwKeyType;
|
---|
| 498 | HKEY hNetCardGUID;
|
---|
| 499 |
|
---|
| 500 | len = sizeof(szEnumName);
|
---|
| 501 | status = RegEnumKeyExA(hNetcard, i, szEnumName, &len, NULL, NULL, NULL, NULL);
|
---|
| 502 | if (status != ERROR_SUCCESS)
|
---|
| 503 | break;
|
---|
| 504 |
|
---|
| 505 | status = RegOpenKeyExA(hNetcard, szEnumName, 0, KEY_READ, &hNetCardGUID);
|
---|
| 506 | if (status == ERROR_SUCCESS)
|
---|
| 507 | {
|
---|
[10896] | 508 | len = sizeof(szNetCfgInstanceId);
|
---|
[1] | 509 | status = RegQueryValueExA(hNetCardGUID, "NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &len);
|
---|
| 510 | if (status == ERROR_SUCCESS && dwKeyType == REG_SZ)
|
---|
| 511 | {
|
---|
| 512 | char szNetProductName[256];
|
---|
| 513 | char szNetProviderName[256];
|
---|
| 514 |
|
---|
| 515 | szNetProductName[0] = 0;
|
---|
| 516 | len = sizeof(szNetProductName);
|
---|
| 517 | status = RegQueryValueExA(hNetCardGUID, "ProductName", NULL, &dwKeyType, (LPBYTE)szNetProductName, &len);
|
---|
| 518 |
|
---|
| 519 | szNetProviderName[0] = 0;
|
---|
| 520 | len = sizeof(szNetProviderName);
|
---|
| 521 | status = RegQueryValueExA(hNetCardGUID, "ProviderName", NULL, &dwKeyType, (LPBYTE)szNetProviderName, &len);
|
---|
| 522 |
|
---|
| 523 | if ( !strcmp(szNetCfgInstanceId, guid)
|
---|
| 524 | && !strcmp(szNetProductName, "VirtualBox TAP Adapter")
|
---|
[14953] | 525 | && ( (!strcmp(szNetProviderName, "innotek GmbH"))
|
---|
| 526 | || (!strcmp(szNetProviderName, "Sun Microsystems, Inc."))))
|
---|
[1] | 527 | {
|
---|
| 528 | ret = true;
|
---|
| 529 | RegCloseKey(hNetCardGUID);
|
---|
| 530 | break;
|
---|
| 531 | }
|
---|
| 532 | }
|
---|
| 533 | RegCloseKey(hNetCardGUID);
|
---|
| 534 | }
|
---|
| 535 | ++i;
|
---|
| 536 | }
|
---|
| 537 |
|
---|
[10896] | 538 | RegCloseKey(hNetcard);
|
---|
[1] | 539 | return ret;
|
---|
| 540 | }
|
---|
[10896] | 541 | #endif /* RT_OS_WINDOWS */
|
---|
[1] | 542 |
|
---|
[12783] | 543 | #ifdef RT_OS_SOLARIS
|
---|
[12866] | 544 | static void vboxSolarisAddHostIface(char *pszIface, int Instance, PCRTMAC pMac, void *pvHostNetworkInterfaceList)
|
---|
[12783] | 545 | {
|
---|
[12866] | 546 | std::list<ComObjPtr <HostNetworkInterface> > *pList = (std::list<ComObjPtr <HostNetworkInterface> > *)pvHostNetworkInterfaceList;
|
---|
| 547 | Assert(pList);
|
---|
[12783] | 548 |
|
---|
| 549 | typedef std::map <std::string, std::string> NICMap;
|
---|
| 550 | typedef std::pair <std::string, std::string> NICPair;
|
---|
| 551 | static NICMap SolarisNICMap;
|
---|
| 552 | if (SolarisNICMap.empty())
|
---|
| 553 | {
|
---|
| 554 | SolarisNICMap.insert(NICPair("afe", "ADMtek Centaur/Comet Fast Ethernet"));
|
---|
| 555 | SolarisNICMap.insert(NICPair("aggr", "Link Aggregation Interface"));
|
---|
| 556 | SolarisNICMap.insert(NICPair("bge", "Broadcom BCM57xx Gigabit Ethernet"));
|
---|
| 557 | SolarisNICMap.insert(NICPair("ce", "Cassini Gigabit Ethernet"));
|
---|
| 558 | SolarisNICMap.insert(NICPair("chxge", "Chelsio Ethernet"));
|
---|
| 559 | SolarisNICMap.insert(NICPair("dmfe", "Davicom Fast Ethernet"));
|
---|
| 560 | SolarisNICMap.insert(NICPair("dnet", "DEC 21040/41 21140 Ethernet"));
|
---|
| 561 | SolarisNICMap.insert(NICPair("e1000", "Intel PRO/1000 Gigabit Ethernet"));
|
---|
| 562 | SolarisNICMap.insert(NICPair("e1000g", "Intel PRO/1000 Gigabit Ethernet"));
|
---|
| 563 | SolarisNICMap.insert(NICPair("elx", "3COM EtherLink III Ethernet"));
|
---|
| 564 | SolarisNICMap.insert(NICPair("elxl", "3COM Ethernet"));
|
---|
| 565 | SolarisNICMap.insert(NICPair("eri", "eri Fast Ethernet"));
|
---|
| 566 | SolarisNICMap.insert(NICPair("ge", "GEM Gigabit Ethernet"));
|
---|
| 567 | SolarisNICMap.insert(NICPair("hme", "SUNW,hme Fast-Ethernet"));
|
---|
| 568 | SolarisNICMap.insert(NICPair("ipge", "PCI-E Gigabit Ethernet"));
|
---|
| 569 | SolarisNICMap.insert(NICPair("iprb", "Intel 82557/58/59 Ethernet"));
|
---|
| 570 | SolarisNICMap.insert(NICPair("mxfe", "Macronix 98715 Fast Ethernet"));
|
---|
| 571 | SolarisNICMap.insert(NICPair("nge", "Nvidia Gigabit Ethernet"));
|
---|
| 572 | SolarisNICMap.insert(NICPair("pcelx", "3COM EtherLink III PCMCIA Ethernet"));
|
---|
| 573 | SolarisNICMap.insert(NICPair("pcn", "AMD PCnet Ethernet"));
|
---|
| 574 | SolarisNICMap.insert(NICPair("qfe", "SUNW,qfe Quad Fast-Ethernet"));
|
---|
| 575 | SolarisNICMap.insert(NICPair("rge", "Realtek Gigabit Ethernet"));
|
---|
| 576 | SolarisNICMap.insert(NICPair("rtls", "Realtek 8139 Fast Ethernet"));
|
---|
| 577 | SolarisNICMap.insert(NICPair("skge", "SksKonnect Gigabit Ethernet"));
|
---|
| 578 | SolarisNICMap.insert(NICPair("spwr", "SMC EtherPower II 10/100 (9432) Ethernet"));
|
---|
| 579 | SolarisNICMap.insert(NICPair("vnic", "Virtual Network Interface Ethernet"));
|
---|
| 580 | SolarisNICMap.insert(NICPair("xge", "Neterior Xframe Gigabit Ethernet"));
|
---|
| 581 | SolarisNICMap.insert(NICPair("xge", "Neterior Xframe 10Gigabit Ethernet"));
|
---|
| 582 | }
|
---|
| 583 |
|
---|
| 584 | /*
|
---|
| 585 | * Try picking up description from our NIC map.
|
---|
| 586 | */
|
---|
[12785] | 587 | char szNICInstance[128];
|
---|
| 588 | RTStrPrintf(szNICInstance, sizeof(szNICInstance), "%s%d", pszIface, Instance);
|
---|
[12783] | 589 | char szNICDesc[256];
|
---|
| 590 | std::string Description = SolarisNICMap[pszIface];
|
---|
| 591 | if (Description != "")
|
---|
[12785] | 592 | RTStrPrintf(szNICDesc, sizeof(szNICDesc), "%s - %s", szNICInstance, Description.c_str());
|
---|
[12783] | 593 | else
|
---|
[12785] | 594 | RTStrPrintf(szNICDesc, sizeof(szNICDesc), "%s - Ethernet", szNICInstance);
|
---|
[12783] | 595 |
|
---|
| 596 | /*
|
---|
| 597 | * Construct UUID with interface name and the MAC address if available.
|
---|
| 598 | */
|
---|
| 599 | RTUUID Uuid;
|
---|
| 600 | RTUuidClear(&Uuid);
|
---|
[12785] | 601 | memcpy(&Uuid, szNICInstance, RT_MIN(strlen(szNICInstance), sizeof(Uuid)));
|
---|
[12783] | 602 | Uuid.Gen.u8ClockSeqHiAndReserved = (Uuid.Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80;
|
---|
| 603 | Uuid.Gen.u16TimeHiAndVersion = (Uuid.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
|
---|
| 604 | if (pMac)
|
---|
| 605 | {
|
---|
| 606 | Uuid.Gen.au8Node[0] = pMac->au8[0];
|
---|
| 607 | Uuid.Gen.au8Node[1] = pMac->au8[1];
|
---|
| 608 | Uuid.Gen.au8Node[2] = pMac->au8[2];
|
---|
| 609 | Uuid.Gen.au8Node[3] = pMac->au8[3];
|
---|
| 610 | Uuid.Gen.au8Node[4] = pMac->au8[4];
|
---|
| 611 | Uuid.Gen.au8Node[5] = pMac->au8[5];
|
---|
| 612 | }
|
---|
| 613 |
|
---|
| 614 | ComObjPtr<HostNetworkInterface> IfObj;
|
---|
| 615 | IfObj.createObject();
|
---|
| 616 | if (SUCCEEDED(IfObj->init(Bstr(szNICDesc), Guid(Uuid))))
|
---|
| 617 | pList->push_back(IfObj);
|
---|
| 618 | }
|
---|
| 619 |
|
---|
[12866] | 620 | static boolean_t vboxSolarisAddLinkHostIface(const char *pszIface, void *pvHostNetworkInterfaceList)
|
---|
[12783] | 621 | {
|
---|
[12866] | 622 | /*
|
---|
[13426] | 623 | * Clip off the zone instance number from the interface name (if any).
|
---|
[12866] | 624 | */
|
---|
[13426] | 625 | char szIfaceName[128];
|
---|
| 626 | strcpy(szIfaceName, pszIface);
|
---|
| 627 | char *pszColon = (char *)memchr(szIfaceName, ':', sizeof(szIfaceName));
|
---|
| 628 | if (pszColon)
|
---|
| 629 | *pszColon = '\0';
|
---|
| 630 |
|
---|
| 631 | /*
|
---|
| 632 | * Get the instance number from the interface name, then clip it off.
|
---|
| 633 | */
|
---|
[12866] | 634 | int cbInstance = 0;
|
---|
[13426] | 635 | int cbIface = strlen(szIfaceName);
|
---|
[12866] | 636 | const char *pszEnd = pszIface + cbIface - 1;
|
---|
| 637 | for (int i = 0; i < cbIface - 1; i++)
|
---|
| 638 | {
|
---|
| 639 | if (!RT_C_IS_DIGIT(*pszEnd))
|
---|
| 640 | break;
|
---|
| 641 | cbInstance++;
|
---|
| 642 | pszEnd--;
|
---|
| 643 | }
|
---|
| 644 |
|
---|
[13426] | 645 | int Instance = atoi(pszEnd + 1);
|
---|
| 646 | strncpy(szIfaceName, pszIface, cbIface - cbInstance);
|
---|
| 647 | szIfaceName[cbIface - cbInstance] = '\0';
|
---|
| 648 |
|
---|
[12866] | 649 | /*
|
---|
| 650 | * Add the interface.
|
---|
| 651 | */
|
---|
| 652 | vboxSolarisAddHostIface(szIfaceName, Instance, NULL, pvHostNetworkInterfaceList);
|
---|
| 653 |
|
---|
| 654 | /*
|
---|
| 655 | * Continue walking...
|
---|
| 656 | */
|
---|
| 657 | return _B_FALSE;
|
---|
| 658 | }
|
---|
| 659 |
|
---|
[13426] | 660 | static bool vboxSolarisSortNICList(const ComObjPtr <HostNetworkInterface> Iface1, const ComObjPtr <HostNetworkInterface> Iface2)
|
---|
| 661 | {
|
---|
| 662 | Bstr Iface1Str;
|
---|
| 663 | (*Iface1).COMGETTER(Name) (Iface1Str.asOutParam());
|
---|
| 664 |
|
---|
| 665 | Bstr Iface2Str;
|
---|
| 666 | (*Iface2).COMGETTER(Name) (Iface2Str.asOutParam());
|
---|
| 667 |
|
---|
[13544] | 668 | return Iface1Str < Iface2Str;
|
---|
[13426] | 669 | }
|
---|
| 670 |
|
---|
| 671 | static bool vboxSolarisSameNIC(const ComObjPtr <HostNetworkInterface> Iface1, const ComObjPtr <HostNetworkInterface> Iface2)
|
---|
| 672 | {
|
---|
| 673 | Bstr Iface1Str;
|
---|
| 674 | (*Iface1).COMGETTER(Name) (Iface1Str.asOutParam());
|
---|
| 675 |
|
---|
| 676 | Bstr Iface2Str;
|
---|
| 677 | (*Iface2).COMGETTER(Name) (Iface2Str.asOutParam());
|
---|
| 678 |
|
---|
| 679 | return (Iface1Str == Iface2Str);
|
---|
| 680 | }
|
---|
| 681 |
|
---|
[12866] | 682 | # ifdef VBOX_SOLARIS_NSL_RESOLVED
|
---|
| 683 | static int vboxSolarisAddPhysHostIface(di_node_t Node, di_minor_t Minor, void *pvHostNetworkInterfaceList)
|
---|
| 684 | {
|
---|
[14942] | 685 | /*
|
---|
| 686 | * Skip aggregations.
|
---|
| 687 | */
|
---|
| 688 | if (!strcmp(di_driver_name(Node), "aggr"))
|
---|
| 689 | return DI_WALK_CONTINUE;
|
---|
[12783] | 690 |
|
---|
[14942] | 691 | /*
|
---|
| 692 | * Skip softmacs.
|
---|
| 693 | */
|
---|
| 694 | if (!strcmp(di_driver_name(Node), "softmac"))
|
---|
| 695 | return DI_WALK_CONTINUE;
|
---|
[12783] | 696 |
|
---|
[12866] | 697 | vboxSolarisAddHostIface(di_driver_name(Node), di_instance(Node), NULL, pvHostNetworkInterfaceList);
|
---|
[14942] | 698 | return DI_WALK_CONTINUE;
|
---|
[12783] | 699 | }
|
---|
[13426] | 700 | # endif /* VBOX_SOLARIS_NSL_RESOLVED */
|
---|
[12953] | 701 |
|
---|
[12783] | 702 | #endif
|
---|
| 703 |
|
---|
[13234] | 704 | #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
|
---|
| 705 | # define VBOX_APP_NAME L"VirtualBox"
|
---|
| 706 |
|
---|
| 707 | static int vboxNetWinAddComponent(std::list <ComObjPtr <HostNetworkInterface> > * pPist, INetCfgComponent * pncc)
|
---|
| 708 | {
|
---|
| 709 | LPWSTR lpszName;
|
---|
[13286] | 710 | GUID IfGuid;
|
---|
[13234] | 711 | HRESULT hr;
|
---|
| 712 | int rc = VERR_GENERAL_FAILURE;
|
---|
| 713 |
|
---|
| 714 | hr = pncc->GetDisplayName( &lpszName );
|
---|
[13286] | 715 | Assert(hr == S_OK);
|
---|
[13234] | 716 | if(hr == S_OK)
|
---|
| 717 | {
|
---|
| 718 | size_t cUnicodeName = wcslen(lpszName) + 1;
|
---|
[13286] | 719 | size_t uniLen = (cUnicodeName * 2 + sizeof (OLECHAR) - 1) / sizeof (OLECHAR);
|
---|
| 720 | Bstr name (uniLen + 1 /* extra zero */);
|
---|
| 721 | wcscpy((wchar_t *) name.mutableRaw(), lpszName);
|
---|
| 722 |
|
---|
[14996] | 723 | hr = pncc->GetInstanceGuid(&IfGuid);
|
---|
| 724 | Assert(hr == S_OK);
|
---|
| 725 | if (hr == S_OK)
|
---|
| 726 | {
|
---|
| 727 | /* create a new object and add it to the list */
|
---|
| 728 | ComObjPtr <HostNetworkInterface> iface;
|
---|
| 729 | iface.createObject();
|
---|
| 730 | /* remove the curly bracket at the end */
|
---|
| 731 | if (SUCCEEDED (iface->init (name, Guid (IfGuid))))
|
---|
| 732 | {
|
---|
| 733 | pPist->push_back (iface);
|
---|
| 734 | rc = VINF_SUCCESS;
|
---|
| 735 | }
|
---|
| 736 | else
|
---|
| 737 | {
|
---|
| 738 | Assert(0);
|
---|
| 739 | }
|
---|
| 740 | }
|
---|
[13234] | 741 | CoTaskMemFree(lpszName);
|
---|
| 742 | }
|
---|
| 743 |
|
---|
| 744 | return rc;
|
---|
| 745 | }
|
---|
| 746 |
|
---|
| 747 | #endif /* #if defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT) */
|
---|
| 748 |
|
---|
[1] | 749 | /**
|
---|
| 750 | * Returns a list of host network interfaces.
|
---|
| 751 | *
|
---|
| 752 | * @returns COM status code
|
---|
| 753 | * @param drives address of result pointer
|
---|
| 754 | */
|
---|
[15570] | 755 | STDMETHODIMP Host::COMGETTER(NetworkInterfaces) (ComSafeArrayOut (IHostNetworkInterface *, aNetworkInterfaces))
|
---|
[1] | 756 | {
|
---|
[11849] | 757 | #if defined(RT_OS_WINDOWS) || defined(VBOX_WITH_NETFLT) /*|| defined(RT_OS_OS2)*/
|
---|
[15570] | 758 | if (ComSafeArrayOutIsNull (aNetworkInterfaces))
|
---|
[1] | 759 | return E_POINTER;
|
---|
[15570] | 760 |
|
---|
[8083] | 761 | AutoWriteLock alock (this);
|
---|
[1] | 762 | CHECK_READY();
|
---|
| 763 |
|
---|
| 764 | std::list <ComObjPtr <HostNetworkInterface> > list;
|
---|
| 765 |
|
---|
[15235] | 766 | #ifdef VBOX_WITH_HOSTNETIF_API
|
---|
[15442] | 767 | int rc = NetIfList(list);
|
---|
| 768 | if (rc)
|
---|
[15235] | 769 | {
|
---|
[15442] | 770 | Log(("Failed to get host network interface list with rc=%Vrc\n", rc));
|
---|
[15235] | 771 | }
|
---|
| 772 | #else
|
---|
[10896] | 773 | # if defined(RT_OS_DARWIN)
|
---|
| 774 | PDARWINETHERNIC pEtherNICs = DarwinGetEthernetControllers();
|
---|
| 775 | while (pEtherNICs)
|
---|
| 776 | {
|
---|
| 777 | ComObjPtr<HostNetworkInterface> IfObj;
|
---|
| 778 | IfObj.createObject();
|
---|
| 779 | if (SUCCEEDED(IfObj->init(Bstr(pEtherNICs->szName), Guid(pEtherNICs->Uuid))))
|
---|
| 780 | list.push_back(IfObj);
|
---|
| 781 |
|
---|
| 782 | /* next, free current */
|
---|
| 783 | void *pvFree = pEtherNICs;
|
---|
| 784 | pEtherNICs = pEtherNICs->pNext;
|
---|
| 785 | RTMemFree(pvFree);
|
---|
| 786 | }
|
---|
| 787 |
|
---|
[11828] | 788 | # elif defined(RT_OS_SOLARIS)
|
---|
[11827] | 789 |
|
---|
[13426] | 790 | # ifdef VBOX_SOLARIS_NSL_RESOLVED
|
---|
[12866] | 791 |
|
---|
[12783] | 792 | /*
|
---|
| 793 | * Use libdevinfo for determining all physical interfaces.
|
---|
| 794 | */
|
---|
| 795 | di_node_t Root;
|
---|
| 796 | Root = di_init("/", DINFOCACHE);
|
---|
| 797 | if (Root != DI_NODE_NIL)
|
---|
[11994] | 798 | {
|
---|
[12783] | 799 | di_walk_minor(Root, DDI_NT_NET, 0, &list, vboxSolarisAddPhysHostIface);
|
---|
[14942] | 800 | di_fini(Root);
|
---|
[11994] | 801 | }
|
---|
[12866] | 802 |
|
---|
| 803 | /*
|
---|
| 804 | * Use libdlpi for determining all DLPI interfaces.
|
---|
| 805 | */
|
---|
| 806 | if (VBoxSolarisLibDlpiFound())
|
---|
| 807 | g_pfnLibDlpiWalk(vboxSolarisAddLinkHostIface, &list, 0);
|
---|
| 808 |
|
---|
[13426] | 809 | # endif /* VBOX_SOLARIS_NSL_RESOLVED */
|
---|
[12953] | 810 |
|
---|
[12783] | 811 | /*
|
---|
| 812 | * This gets only the list of all plumbed logical interfaces.
|
---|
[13426] | 813 | * This is needed for zones which cannot access the device tree
|
---|
| 814 | * and in this case we just let them use the list of plumbed interfaces
|
---|
| 815 | * on the zone.
|
---|
[12783] | 816 | */
|
---|
[11846] | 817 | int Sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
|
---|
| 818 | if (Sock > 0)
|
---|
[11827] | 819 | {
|
---|
[11846] | 820 | struct lifnum IfNum;
|
---|
| 821 | memset(&IfNum, 0, sizeof(IfNum));
|
---|
| 822 | IfNum.lifn_family = AF_INET;
|
---|
| 823 | int rc = ioctl(Sock, SIOCGLIFNUM, &IfNum);
|
---|
| 824 | if (!rc)
|
---|
[11827] | 825 | {
|
---|
[11846] | 826 | struct lifreq Ifaces[24];
|
---|
| 827 | struct lifconf IfConfig;
|
---|
| 828 | memset(&IfConfig, 0, sizeof(IfConfig));
|
---|
| 829 | IfConfig.lifc_family = AF_INET;
|
---|
| 830 | IfConfig.lifc_len = sizeof(Ifaces);
|
---|
| 831 | IfConfig.lifc_buf = (caddr_t)&(Ifaces[0]);
|
---|
| 832 | rc = ioctl(Sock, SIOCGLIFCONF, &IfConfig);
|
---|
| 833 | if (!rc)
|
---|
[11827] | 834 | {
|
---|
[11846] | 835 | for (int i = 0; i < IfNum.lifn_count; i++)
|
---|
[11827] | 836 | {
|
---|
[11868] | 837 | /*
|
---|
| 838 | * Skip loopback interfaces.
|
---|
| 839 | */
|
---|
| 840 | if (!strncmp(Ifaces[i].lifr_name, "lo", 2))
|
---|
| 841 | continue;
|
---|
| 842 |
|
---|
[13426] | 843 | #if 0
|
---|
[11846] | 844 | rc = ioctl(Sock, SIOCGLIFADDR, &(Ifaces[i]));
|
---|
| 845 | if (!rc)
|
---|
| 846 | {
|
---|
[11868] | 847 | RTMAC Mac;
|
---|
[11846] | 848 | struct arpreq ArpReq;
|
---|
| 849 | memcpy(&ArpReq.arp_pa, &Ifaces[i].lifr_addr, sizeof(struct sockaddr_in));
|
---|
[11868] | 850 |
|
---|
| 851 | /*
|
---|
| 852 | * We might fail if the interface has not been assigned an IP address.
|
---|
| 853 | * That doesn't matter; as long as it's plumbed we can pick it up.
|
---|
| 854 | * But, if it has not acquired an IP address we cannot obtain it's MAC
|
---|
| 855 | * address this way, so we just use all zeros there.
|
---|
| 856 | */
|
---|
[11846] | 857 | rc = ioctl(Sock, SIOCGARP, &ArpReq);
|
---|
| 858 | if (!rc)
|
---|
| 859 | memcpy(&Mac, ArpReq.arp_ha.sa_data, sizeof(RTMAC));
|
---|
[11868] | 860 | else
|
---|
| 861 | memset(&Mac, 0, sizeof(Mac));
|
---|
[11827] | 862 |
|
---|
[11993] | 863 | char szNICDesc[LIFNAMSIZ + 256];
|
---|
[11868] | 864 | char *pszIface = Ifaces[i].lifr_name;
|
---|
[11993] | 865 | strcpy(szNICDesc, pszIface);
|
---|
[13234] | 866 |
|
---|
[12866] | 867 | vboxSolarisAddLinkHostIface(pszIface, &list);
|
---|
[11846] | 868 | }
|
---|
[13426] | 869 | #endif
|
---|
| 870 |
|
---|
| 871 | char *pszIface = Ifaces[i].lifr_name;
|
---|
| 872 | vboxSolarisAddLinkHostIface(pszIface, &list);
|
---|
[11827] | 873 | }
|
---|
| 874 | }
|
---|
| 875 | }
|
---|
[11846] | 876 | close(Sock);
|
---|
[11827] | 877 | }
|
---|
| 878 |
|
---|
[13426] | 879 | /*
|
---|
| 880 | * Weed out duplicates caused by dlpi_walk inconsistencies across Nevadas.
|
---|
| 881 | */
|
---|
| 882 | list.sort(vboxSolarisSortNICList);
|
---|
| 883 | list.unique(vboxSolarisSameNIC);
|
---|
| 884 |
|
---|
[10896] | 885 | # elif defined RT_OS_WINDOWS
|
---|
[13234] | 886 | # ifndef VBOX_WITH_NETFLT
|
---|
[2434] | 887 | static const char *NetworkKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\"
|
---|
| 888 | "{4D36E972-E325-11CE-BFC1-08002BE10318}";
|
---|
[1] | 889 | HKEY hCtrlNet;
|
---|
| 890 | LONG status;
|
---|
| 891 | DWORD len;
|
---|
[2434] | 892 | status = RegOpenKeyExA (HKEY_LOCAL_MACHINE, NetworkKey, 0, KEY_READ, &hCtrlNet);
|
---|
[1] | 893 | if (status != ERROR_SUCCESS)
|
---|
[2434] | 894 | return setError (E_FAIL, tr("Could not open registry key \"%s\""), NetworkKey);
|
---|
[1] | 895 |
|
---|
[2434] | 896 | for (int i = 0;; ++ i)
|
---|
[1] | 897 | {
|
---|
[2434] | 898 | char szNetworkGUID [256];
|
---|
[1] | 899 | HKEY hConnection;
|
---|
[2434] | 900 | char szNetworkConnection [256];
|
---|
[1] | 901 |
|
---|
| 902 | len = sizeof (szNetworkGUID);
|
---|
[2434] | 903 | status = RegEnumKeyExA (hCtrlNet, i, szNetworkGUID, &len, NULL, NULL, NULL, NULL);
|
---|
[1] | 904 | if (status != ERROR_SUCCESS)
|
---|
| 905 | break;
|
---|
| 906 |
|
---|
[2434] | 907 | if (!IsTAPDevice(szNetworkGUID))
|
---|
| 908 | continue;
|
---|
| 909 |
|
---|
| 910 | RTStrPrintf (szNetworkConnection, sizeof (szNetworkConnection),
|
---|
| 911 | "%s\\Connection", szNetworkGUID);
|
---|
| 912 | status = RegOpenKeyExA (hCtrlNet, szNetworkConnection, 0, KEY_READ, &hConnection);
|
---|
[1] | 913 | if (status == ERROR_SUCCESS)
|
---|
| 914 | {
|
---|
| 915 | DWORD dwKeyType;
|
---|
[2434] | 916 | status = RegQueryValueExW (hConnection, TEXT("Name"), NULL,
|
---|
| 917 | &dwKeyType, NULL, &len);
|
---|
[1] | 918 | if (status == ERROR_SUCCESS && dwKeyType == REG_SZ)
|
---|
| 919 | {
|
---|
[2434] | 920 | size_t uniLen = (len + sizeof (OLECHAR) - 1) / sizeof (OLECHAR);
|
---|
| 921 | Bstr name (uniLen + 1 /* extra zero */);
|
---|
| 922 | status = RegQueryValueExW (hConnection, TEXT("Name"), NULL,
|
---|
| 923 | &dwKeyType, (LPBYTE) name.mutableRaw(), &len);
|
---|
| 924 | if (status == ERROR_SUCCESS)
|
---|
[1] | 925 | {
|
---|
[14990] | 926 | LogFunc(("Connection name %ls\n", name.mutableRaw()));
|
---|
[2434] | 927 | /* put a trailing zero, just in case (see MSDN) */
|
---|
| 928 | name.mutableRaw() [uniLen] = 0;
|
---|
[1] | 929 | /* create a new object and add it to the list */
|
---|
[2434] | 930 | ComObjPtr <HostNetworkInterface> iface;
|
---|
| 931 | iface.createObject();
|
---|
[1] | 932 | /* remove the curly bracket at the end */
|
---|
[2434] | 933 | szNetworkGUID [strlen(szNetworkGUID) - 1] = '\0';
|
---|
| 934 | if (SUCCEEDED (iface->init (name, Guid (szNetworkGUID + 1))))
|
---|
| 935 | list.push_back (iface);
|
---|
[1] | 936 | }
|
---|
| 937 | }
|
---|
| 938 | RegCloseKey (hConnection);
|
---|
| 939 | }
|
---|
| 940 | }
|
---|
| 941 | RegCloseKey (hCtrlNet);
|
---|
[13234] | 942 | # else /* # if defined VBOX_WITH_NETFLT */
|
---|
| 943 | INetCfg *pNc;
|
---|
| 944 | INetCfgComponent *pMpNcc;
|
---|
| 945 | INetCfgComponent *pTcpIpNcc;
|
---|
| 946 | LPWSTR lpszApp;
|
---|
| 947 | HRESULT hr;
|
---|
| 948 | IEnumNetCfgBindingPath *pEnumBp;
|
---|
| 949 | INetCfgBindingPath *pBp;
|
---|
| 950 | IEnumNetCfgBindingInterface *pEnumBi;
|
---|
| 951 | INetCfgBindingInterface *pBi;
|
---|
| 952 |
|
---|
| 953 | /* we are using the INetCfg API for getting the list of miniports */
|
---|
[13854] | 954 | hr = VBoxNetCfgWinQueryINetCfg( FALSE,
|
---|
[13234] | 955 | VBOX_APP_NAME,
|
---|
| 956 | &pNc,
|
---|
| 957 | &lpszApp );
|
---|
[13286] | 958 | Assert(hr == S_OK);
|
---|
[13234] | 959 | if(hr == S_OK)
|
---|
| 960 | {
|
---|
[13544] | 961 | #ifdef VBOX_NETFLT_ONDEMAND_BIND
|
---|
| 962 | /* for the protocol-based approach for now we just get all miniports the MS_TCPIP protocol binds to */
|
---|
[13234] | 963 | hr = pNc->FindComponent(L"MS_TCPIP", &pTcpIpNcc);
|
---|
[13544] | 964 | #else
|
---|
| 965 | /* for the filter-based approach we get all miniports our filter (sun_VBoxNetFlt)is bound to */
|
---|
| 966 | hr = pNc->FindComponent(L"sun_VBoxNetFlt", &pTcpIpNcc);
|
---|
[14271] | 967 | # ifndef VBOX_WITH_HARDENING
|
---|
| 968 | if(hr != S_OK)
|
---|
| 969 | {
|
---|
| 970 | /* TODO: try to install the netflt from here */
|
---|
| 971 | }
|
---|
| 972 | # endif
|
---|
| 973 |
|
---|
[13544] | 974 | #endif
|
---|
| 975 |
|
---|
[13234] | 976 | if(hr == S_OK)
|
---|
| 977 | {
|
---|
[13854] | 978 | hr = VBoxNetCfgWinGetBindingPathEnum(pTcpIpNcc, EBP_BELOW, &pEnumBp);
|
---|
[13286] | 979 | Assert(hr == S_OK);
|
---|
[13234] | 980 | if ( hr == S_OK )
|
---|
| 981 | {
|
---|
[13854] | 982 | hr = VBoxNetCfgWinGetFirstBindingPath(pEnumBp, &pBp);
|
---|
[13286] | 983 | Assert(hr == S_OK || hr == S_FALSE);
|
---|
[13234] | 984 | while( hr == S_OK )
|
---|
| 985 | {
|
---|
[14685] | 986 | /* S_OK == enabled, S_FALSE == disabled */
|
---|
| 987 | if(pBp->IsEnabled() == S_OK)
|
---|
[13234] | 988 | {
|
---|
[14685] | 989 | hr = VBoxNetCfgWinGetBindingInterfaceEnum(pBp, &pEnumBi);
|
---|
[13286] | 990 | Assert(hr == S_OK);
|
---|
[14685] | 991 | if ( hr == S_OK )
|
---|
[13234] | 992 | {
|
---|
[14685] | 993 | hr = VBoxNetCfgWinGetFirstBindingInterface(pEnumBi, &pBi);
|
---|
[13286] | 994 | Assert(hr == S_OK);
|
---|
[14685] | 995 | while(hr == S_OK)
|
---|
[13234] | 996 | {
|
---|
[14685] | 997 | hr = pBi->GetLowerComponent( &pMpNcc );
|
---|
| 998 | Assert(hr == S_OK);
|
---|
| 999 | if(hr == S_OK)
|
---|
| 1000 | {
|
---|
[15752] | 1001 | ULONG uComponentStatus;
|
---|
| 1002 | hr = pMpNcc->GetDeviceStatus(&uComponentStatus);
|
---|
| 1003 | Assert(hr == S_OK);
|
---|
| 1004 | if(hr == S_OK)
|
---|
| 1005 | {
|
---|
| 1006 | if(uComponentStatus == 0)
|
---|
| 1007 | {
|
---|
| 1008 | vboxNetWinAddComponent(&list, pMpNcc);
|
---|
| 1009 | }
|
---|
| 1010 | }
|
---|
[14685] | 1011 | VBoxNetCfgWinReleaseRef( pMpNcc );
|
---|
| 1012 | }
|
---|
| 1013 | VBoxNetCfgWinReleaseRef(pBi);
|
---|
| 1014 |
|
---|
| 1015 | hr = VBoxNetCfgWinGetNextBindingInterface(pEnumBi, &pBi);
|
---|
[13234] | 1016 | }
|
---|
[14685] | 1017 | VBoxNetCfgWinReleaseRef(pEnumBi);
|
---|
[13234] | 1018 | }
|
---|
| 1019 | }
|
---|
[13854] | 1020 | VBoxNetCfgWinReleaseRef(pBp);
|
---|
[13234] | 1021 |
|
---|
[13854] | 1022 | hr = VBoxNetCfgWinGetNextBindingPath(pEnumBp, &pBp);
|
---|
[13234] | 1023 | }
|
---|
[13854] | 1024 | VBoxNetCfgWinReleaseRef(pEnumBp);
|
---|
[13234] | 1025 | }
|
---|
[13854] | 1026 | VBoxNetCfgWinReleaseRef(pTcpIpNcc);
|
---|
[13234] | 1027 | }
|
---|
[14271] | 1028 | else
|
---|
| 1029 | {
|
---|
| 1030 | LogRel(("failed to get the sun_VBoxNetFlt component, error (0x%x)", hr));
|
---|
| 1031 | }
|
---|
| 1032 |
|
---|
[13854] | 1033 | VBoxNetCfgWinReleaseINetCfg(pNc, FALSE);
|
---|
[13234] | 1034 | }
|
---|
| 1035 | # endif /* # if defined VBOX_WITH_NETFLT */
|
---|
| 1036 |
|
---|
| 1037 |
|
---|
[13938] | 1038 | # elif defined RT_OS_LINUX
|
---|
| 1039 | int sock = socket(AF_INET, SOCK_DGRAM, 0);
|
---|
| 1040 | if (sock >= 0)
|
---|
| 1041 | {
|
---|
| 1042 | char pBuffer[2048];
|
---|
| 1043 | struct ifconf ifConf;
|
---|
| 1044 | ifConf.ifc_len = sizeof(pBuffer);
|
---|
| 1045 | ifConf.ifc_buf = pBuffer;
|
---|
| 1046 | if (ioctl(sock, SIOCGIFCONF, &ifConf) >= 0)
|
---|
| 1047 | {
|
---|
[14076] | 1048 | for (struct ifreq *pReq = ifConf.ifc_req; (char*)pReq < pBuffer + ifConf.ifc_len; pReq++)
|
---|
[13938] | 1049 | {
|
---|
[14283] | 1050 | if (ioctl(sock, SIOCGIFHWADDR, pReq) >= 0)
|
---|
| 1051 | {
|
---|
| 1052 | if (pReq->ifr_hwaddr.sa_family == ARPHRD_ETHER)
|
---|
| 1053 | {
|
---|
| 1054 | RTUUID uuid;
|
---|
| 1055 | Assert(sizeof(uuid) <= sizeof(*pReq));
|
---|
| 1056 | memcpy(&uuid, pReq, sizeof(uuid));
|
---|
[1] | 1057 |
|
---|
[14283] | 1058 | ComObjPtr<HostNetworkInterface> IfObj;
|
---|
| 1059 | IfObj.createObject();
|
---|
| 1060 | if (SUCCEEDED(IfObj->init(Bstr(pReq->ifr_name), Guid(uuid))))
|
---|
| 1061 | list.push_back(IfObj);
|
---|
| 1062 | }
|
---|
| 1063 | }
|
---|
[13938] | 1064 | }
|
---|
| 1065 | }
|
---|
| 1066 | close(sock);
|
---|
| 1067 | }
|
---|
| 1068 | # endif /* RT_OS_LINUX */
|
---|
[15235] | 1069 | #endif
|
---|
[15570] | 1070 | SafeIfaceArray <IHostNetworkInterface> networkInterfaces (list);
|
---|
| 1071 | networkInterfaces.detachTo (ComSafeArrayOutArg (aNetworkInterfaces));
|
---|
| 1072 |
|
---|
[1] | 1073 | return S_OK;
|
---|
[10896] | 1074 |
|
---|
| 1075 | #else
|
---|
| 1076 | /* Not implemented / supported on this platform. */
|
---|
[14715] | 1077 | ReturnComNotImplemented();
|
---|
[10896] | 1078 | #endif
|
---|
[1] | 1079 | }
|
---|
| 1080 |
|
---|
| 1081 | STDMETHODIMP Host::COMGETTER(USBDevices)(IHostUSBDeviceCollection **aUSBDevices)
|
---|
| 1082 | {
|
---|
[815] | 1083 | #ifdef VBOX_WITH_USB
|
---|
[14972] | 1084 | CheckComArgOutPointerValid(aUSBDevices);
|
---|
[1] | 1085 |
|
---|
[8083] | 1086 | AutoWriteLock alock (this);
|
---|
[1] | 1087 | CHECK_READY();
|
---|
| 1088 |
|
---|
[6965] | 1089 | MultiResult rc = checkUSBProxyService();
|
---|
[815] | 1090 | CheckComRCReturnRC (rc);
|
---|
| 1091 |
|
---|
[8666] | 1092 | return mUSBProxyService->getDeviceCollection (aUSBDevices);
|
---|
[6965] | 1093 |
|
---|
[815] | 1094 | #else
|
---|
| 1095 | /* Note: The GUI depends on this method returning E_NOTIMPL with no
|
---|
| 1096 | * extended error info to indicate that USB is simply not available
|
---|
[14996] | 1097 | * (w/o treating it as a failure), for example, as in OSE. */
|
---|
[14715] | 1098 | ReturnComNotImplemented();
|
---|
[815] | 1099 | #endif
|
---|
[1] | 1100 | }
|
---|
| 1101 |
|
---|
[6965] | 1102 | STDMETHODIMP Host::COMGETTER(USBDeviceFilters) (IHostUSBDeviceFilterCollection **aUSBDeviceFilters)
|
---|
[1] | 1103 | {
|
---|
[815] | 1104 | #ifdef VBOX_WITH_USB
|
---|
[14972] | 1105 | CheckComArgOutPointerValid(aUSBDeviceFilters);
|
---|
[1] | 1106 |
|
---|
[8083] | 1107 | AutoWriteLock alock (this);
|
---|
[1] | 1108 | CHECK_READY();
|
---|
| 1109 |
|
---|
[6965] | 1110 | MultiResult rc = checkUSBProxyService();
|
---|
[815] | 1111 | CheckComRCReturnRC (rc);
|
---|
| 1112 |
|
---|
[1] | 1113 | ComObjPtr <HostUSBDeviceFilterCollection> collection;
|
---|
| 1114 | collection.createObject();
|
---|
| 1115 | collection->init (mUSBDeviceFilters);
|
---|
| 1116 | collection.queryInterfaceTo (aUSBDeviceFilters);
|
---|
[6965] | 1117 |
|
---|
| 1118 | return rc;
|
---|
[815] | 1119 | #else
|
---|
| 1120 | /* Note: The GUI depends on this method returning E_NOTIMPL with no
|
---|
| 1121 | * extended error info to indicate that USB is simply not available
|
---|
[14996] | 1122 | * (w/o treating it as a failure), for example, as in OSE. */
|
---|
[14715] | 1123 | ReturnComNotImplemented();
|
---|
[815] | 1124 | #endif
|
---|
[1] | 1125 | }
|
---|
| 1126 |
|
---|
| 1127 | /**
|
---|
| 1128 | * Returns the number of installed logical processors
|
---|
| 1129 | *
|
---|
| 1130 | * @returns COM status code
|
---|
| 1131 | * @param count address of result variable
|
---|
| 1132 | */
|
---|
[14996] | 1133 | STDMETHODIMP Host::COMGETTER(ProcessorCount)(ULONG *aCount)
|
---|
[1] | 1134 | {
|
---|
[14996] | 1135 | CheckComArgOutPointerValid(aCount);
|
---|
[8083] | 1136 | AutoWriteLock alock (this);
|
---|
[1] | 1137 | CHECK_READY();
|
---|
[14996] | 1138 | *aCount = RTMpGetPresentCount();
|
---|
[1] | 1139 | return S_OK;
|
---|
| 1140 | }
|
---|
| 1141 |
|
---|
| 1142 | /**
|
---|
[11258] | 1143 | * Returns the number of online logical processors
|
---|
| 1144 | *
|
---|
| 1145 | * @returns COM status code
|
---|
| 1146 | * @param count address of result variable
|
---|
| 1147 | */
|
---|
[14996] | 1148 | STDMETHODIMP Host::COMGETTER(ProcessorOnlineCount)(ULONG *aCount)
|
---|
[11258] | 1149 | {
|
---|
[14996] | 1150 | CheckComArgOutPointerValid(aCount);
|
---|
[11258] | 1151 | AutoWriteLock alock (this);
|
---|
| 1152 | CHECK_READY();
|
---|
[14996] | 1153 | *aCount = RTMpGetOnlineCount();
|
---|
[11258] | 1154 | return S_OK;
|
---|
| 1155 | }
|
---|
| 1156 |
|
---|
| 1157 | /**
|
---|
[10399] | 1158 | * Returns the (approximate) maximum speed of the given host CPU in MHz
|
---|
[1] | 1159 | *
|
---|
| 1160 | * @returns COM status code
|
---|
[10399] | 1161 | * @param cpu id to get info for.
|
---|
[14996] | 1162 | * @param speed address of result variable, speed is 0 if unknown or aCpuId is invalid.
|
---|
[1] | 1163 | */
|
---|
[14996] | 1164 | STDMETHODIMP Host::GetProcessorSpeed(ULONG aCpuId, ULONG *aSpeed)
|
---|
[1] | 1165 | {
|
---|
[14996] | 1166 | CheckComArgOutPointerValid(aSpeed);
|
---|
[8083] | 1167 | AutoWriteLock alock (this);
|
---|
[1] | 1168 | CHECK_READY();
|
---|
[14996] | 1169 | *aSpeed = RTMpGetMaxFrequency(aCpuId);
|
---|
[1] | 1170 | return S_OK;
|
---|
| 1171 | }
|
---|
| 1172 | /**
|
---|
| 1173 | * Returns a description string for the host CPU
|
---|
| 1174 | *
|
---|
| 1175 | * @returns COM status code
|
---|
[10399] | 1176 | * @param cpu id to get info for.
|
---|
[14996] | 1177 | * @param description address of result variable, NULL if known or aCpuId is invalid.
|
---|
[1] | 1178 | */
|
---|
[14996] | 1179 | STDMETHODIMP Host::GetProcessorDescription(ULONG aCpuId, BSTR *aDescription)
|
---|
[1] | 1180 | {
|
---|
[14996] | 1181 | CheckComArgOutPointerValid(aDescription);
|
---|
[8083] | 1182 | AutoWriteLock alock (this);
|
---|
[1] | 1183 | CHECK_READY();
|
---|
| 1184 | /** @todo */
|
---|
[14715] | 1185 | ReturnComNotImplemented();
|
---|
[1] | 1186 | }
|
---|
| 1187 |
|
---|
[14521] | 1188 | /**
|
---|
| 1189 | * Returns whether a host processor feature is supported or not
|
---|
| 1190 | *
|
---|
| 1191 | * @returns COM status code
|
---|
| 1192 | * @param Feature to query.
|
---|
| 1193 | * @param address of supported bool result variable
|
---|
| 1194 | */
|
---|
[14996] | 1195 | STDMETHODIMP Host::GetProcessorFeature(ProcessorFeature_T aFeature, BOOL *aSupported)
|
---|
[14521] | 1196 | {
|
---|
[14996] | 1197 | CheckComArgOutPointerValid(aSupported);
|
---|
[14521] | 1198 | AutoWriteLock alock (this);
|
---|
| 1199 | CHECK_READY();
|
---|
[1] | 1200 |
|
---|
[14996] | 1201 | switch (aFeature)
|
---|
[14521] | 1202 | {
|
---|
| 1203 | case ProcessorFeature_HWVirtEx:
|
---|
[14996] | 1204 | *aSupported = fVTxAMDVSupported;
|
---|
[14521] | 1205 | break;
|
---|
| 1206 |
|
---|
| 1207 | case ProcessorFeature_PAE:
|
---|
[14996] | 1208 | *aSupported = fPAESupported;
|
---|
[14521] | 1209 | break;
|
---|
| 1210 |
|
---|
| 1211 | case ProcessorFeature_LongMode:
|
---|
[14996] | 1212 | *aSupported = fLongModeSupported;
|
---|
[14521] | 1213 | break;
|
---|
| 1214 |
|
---|
| 1215 | default:
|
---|
[14715] | 1216 | ReturnComNotImplemented();
|
---|
[14521] | 1217 | }
|
---|
| 1218 | return S_OK;
|
---|
| 1219 | }
|
---|
| 1220 |
|
---|
[1] | 1221 | /**
|
---|
| 1222 | * Returns the amount of installed system memory in megabytes
|
---|
| 1223 | *
|
---|
| 1224 | * @returns COM status code
|
---|
| 1225 | * @param size address of result variable
|
---|
| 1226 | */
|
---|
[14996] | 1227 | STDMETHODIMP Host::COMGETTER(MemorySize)(ULONG *aSize)
|
---|
[1] | 1228 | {
|
---|
[14996] | 1229 | CheckComArgOutPointerValid(aSize);
|
---|
[8083] | 1230 | AutoWriteLock alock (this);
|
---|
[1] | 1231 | CHECK_READY();
|
---|
[14335] | 1232 | /* @todo This is an ugly hack. There must be a function in IPRT for that. */
|
---|
| 1233 | pm::CollectorHAL *hal = pm::createHAL();
|
---|
| 1234 | if (!hal)
|
---|
[15455] | 1235 | return E_FAIL;
|
---|
[14335] | 1236 | ULONG tmp;
|
---|
[14996] | 1237 | int rc = hal->getHostMemoryUsage(aSize, &tmp, &tmp);
|
---|
| 1238 | *aSize /= 1024;
|
---|
[14335] | 1239 | delete hal;
|
---|
| 1240 | return rc;
|
---|
[1] | 1241 | }
|
---|
| 1242 |
|
---|
| 1243 | /**
|
---|
| 1244 | * Returns the current system memory free space in megabytes
|
---|
| 1245 | *
|
---|
| 1246 | * @returns COM status code
|
---|
| 1247 | * @param available address of result variable
|
---|
| 1248 | */
|
---|
[14996] | 1249 | STDMETHODIMP Host::COMGETTER(MemoryAvailable)(ULONG *aAvailable)
|
---|
[1] | 1250 | {
|
---|
[14996] | 1251 | CheckComArgOutPointerValid(aAvailable);
|
---|
[8083] | 1252 | AutoWriteLock alock (this);
|
---|
[1] | 1253 | CHECK_READY();
|
---|
[14335] | 1254 | /* @todo This is an ugly hack. There must be a function in IPRT for that. */
|
---|
| 1255 | pm::CollectorHAL *hal = pm::createHAL();
|
---|
| 1256 | if (!hal)
|
---|
[15455] | 1257 | return E_FAIL;
|
---|
[14335] | 1258 | ULONG tmp;
|
---|
[14996] | 1259 | int rc = hal->getHostMemoryUsage(&tmp, &tmp, aAvailable);
|
---|
| 1260 | *aAvailable /= 1024;
|
---|
[14335] | 1261 | delete hal;
|
---|
| 1262 | return rc;
|
---|
[1] | 1263 | }
|
---|
| 1264 |
|
---|
| 1265 | /**
|
---|
| 1266 | * Returns the name string of the host operating system
|
---|
| 1267 | *
|
---|
| 1268 | * @returns COM status code
|
---|
| 1269 | * @param os address of result variable
|
---|
| 1270 | */
|
---|
[14996] | 1271 | STDMETHODIMP Host::COMGETTER(OperatingSystem)(BSTR *aOs)
|
---|
[1] | 1272 | {
|
---|
[14996] | 1273 | CheckComArgOutPointerValid(aOs);
|
---|
[8083] | 1274 | AutoWriteLock alock (this);
|
---|
[1] | 1275 | CHECK_READY();
|
---|
| 1276 | /** @todo */
|
---|
[14715] | 1277 | ReturnComNotImplemented();
|
---|
[1] | 1278 | }
|
---|
| 1279 |
|
---|
| 1280 | /**
|
---|
| 1281 | * Returns the version string of the host operating system
|
---|
| 1282 | *
|
---|
| 1283 | * @returns COM status code
|
---|
| 1284 | * @param os address of result variable
|
---|
| 1285 | */
|
---|
[14996] | 1286 | STDMETHODIMP Host::COMGETTER(OSVersion)(BSTR *aVersion)
|
---|
[1] | 1287 | {
|
---|
[14996] | 1288 | CheckComArgOutPointerValid(aVersion);
|
---|
[8083] | 1289 | AutoWriteLock alock (this);
|
---|
[1] | 1290 | CHECK_READY();
|
---|
| 1291 | /** @todo */
|
---|
[14715] | 1292 | ReturnComNotImplemented();
|
---|
[1] | 1293 | }
|
---|
| 1294 |
|
---|
| 1295 | /**
|
---|
| 1296 | * Returns the current host time in milliseconds since 1970-01-01 UTC.
|
---|
| 1297 | *
|
---|
| 1298 | * @returns COM status code
|
---|
| 1299 | * @param time address of result variable
|
---|
| 1300 | */
|
---|
| 1301 | STDMETHODIMP Host::COMGETTER(UTCTime)(LONG64 *aUTCTime)
|
---|
| 1302 | {
|
---|
[14972] | 1303 | CheckComArgOutPointerValid(aUTCTime);
|
---|
[8083] | 1304 | AutoWriteLock alock (this);
|
---|
[1] | 1305 | CHECK_READY();
|
---|
| 1306 | RTTIMESPEC now;
|
---|
| 1307 | *aUTCTime = RTTimeSpecGetMilli(RTTimeNow(&now));
|
---|
| 1308 | return S_OK;
|
---|
| 1309 | }
|
---|
| 1310 |
|
---|
| 1311 | // IHost methods
|
---|
| 1312 | ////////////////////////////////////////////////////////////////////////////////
|
---|
| 1313 |
|
---|
[3668] | 1314 | #ifdef RT_OS_WINDOWS
|
---|
[15686] | 1315 | /** @todo REMOVE. OBSOLETE NOW. */
|
---|
[1135] | 1316 | /**
|
---|
| 1317 | * Returns TRUE if the Windows version is 6.0 or greater (i.e. it's Vista and
|
---|
| 1318 | * later OSes) and it has the UAC (User Account Control) feature enabled.
|
---|
| 1319 | */
|
---|
| 1320 | static BOOL IsUACEnabled()
|
---|
| 1321 | {
|
---|
| 1322 | LONG rc = 0;
|
---|
| 1323 |
|
---|
| 1324 | OSVERSIONINFOEX info;
|
---|
| 1325 | ZeroMemory (&info, sizeof (OSVERSIONINFOEX));
|
---|
| 1326 | info.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
|
---|
| 1327 | rc = GetVersionEx ((OSVERSIONINFO *) &info);
|
---|
| 1328 | AssertReturn (rc != 0, FALSE);
|
---|
| 1329 |
|
---|
| 1330 | LogFlowFunc (("dwMajorVersion=%d, dwMinorVersion=%d\n",
|
---|
| 1331 | info.dwMajorVersion, info.dwMinorVersion));
|
---|
| 1332 |
|
---|
| 1333 | /* we are interested only in Vista (and newer versions...). In all
|
---|
| 1334 | * earlier versions UAC is not present. */
|
---|
| 1335 | if (info.dwMajorVersion < 6)
|
---|
| 1336 | return FALSE;
|
---|
| 1337 |
|
---|
| 1338 | /* the default EnableLUA value is 1 (Enabled) */
|
---|
| 1339 | DWORD dwEnableLUA = 1;
|
---|
| 1340 |
|
---|
| 1341 | HKEY hKey;
|
---|
| 1342 | rc = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
|
---|
| 1343 | "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",
|
---|
| 1344 | 0, KEY_QUERY_VALUE, &hKey);
|
---|
| 1345 |
|
---|
| 1346 | Assert (rc == ERROR_SUCCESS || rc == ERROR_PATH_NOT_FOUND);
|
---|
| 1347 | if (rc == ERROR_SUCCESS)
|
---|
| 1348 | {
|
---|
| 1349 |
|
---|
| 1350 | DWORD cbEnableLUA = sizeof (dwEnableLUA);
|
---|
| 1351 | rc = RegQueryValueExA (hKey, "EnableLUA", NULL, NULL,
|
---|
[1139] | 1352 | (LPBYTE) &dwEnableLUA, &cbEnableLUA);
|
---|
[1135] | 1353 |
|
---|
| 1354 | RegCloseKey (hKey);
|
---|
| 1355 |
|
---|
| 1356 | Assert (rc == ERROR_SUCCESS || rc == ERROR_FILE_NOT_FOUND);
|
---|
| 1357 | }
|
---|
| 1358 |
|
---|
| 1359 | LogFlowFunc (("rc=%d, dwEnableLUA=%d\n", rc, dwEnableLUA));
|
---|
| 1360 |
|
---|
| 1361 | return dwEnableLUA == 1;
|
---|
| 1362 | }
|
---|
| 1363 |
|
---|
[1] | 1364 | struct NetworkInterfaceHelperClientData
|
---|
| 1365 | {
|
---|
| 1366 | SVCHlpMsg::Code msgCode;
|
---|
| 1367 | /* for SVCHlpMsg::CreateHostNetworkInterface */
|
---|
| 1368 | Bstr name;
|
---|
| 1369 | ComObjPtr <HostNetworkInterface> iface;
|
---|
| 1370 | /* for SVCHlpMsg::RemoveHostNetworkInterface */
|
---|
| 1371 | Guid guid;
|
---|
| 1372 | };
|
---|
| 1373 |
|
---|
| 1374 | STDMETHODIMP
|
---|
[15051] | 1375 | Host::CreateHostNetworkInterface (IN_BSTR aName,
|
---|
[1] | 1376 | IHostNetworkInterface **aHostNetworkInterface,
|
---|
| 1377 | IProgress **aProgress)
|
---|
| 1378 | {
|
---|
[14972] | 1379 | CheckComArgNotNull(aName);
|
---|
| 1380 | CheckComArgOutPointerValid(aHostNetworkInterface);
|
---|
| 1381 | CheckComArgOutPointerValid(aProgress);
|
---|
[1] | 1382 |
|
---|
[8083] | 1383 | AutoWriteLock alock (this);
|
---|
[1] | 1384 | CHECK_READY();
|
---|
| 1385 |
|
---|
| 1386 | HRESULT rc = S_OK;
|
---|
| 1387 |
|
---|
| 1388 | /* first check whether an interface with the given name already exists */
|
---|
| 1389 | {
|
---|
[16207] | 1390 | ComPtr <IHostNetworkInterface> iface;
|
---|
| 1391 | if (SUCCEEDED (FindHostNetworkInterfaceByName (aName, iface.asOutParam())))
|
---|
| 1392 | return setError (E_INVALIDARG,
|
---|
| 1393 | tr ("Host network interface '%ls' already exists"), aName);
|
---|
[1] | 1394 | }
|
---|
| 1395 |
|
---|
| 1396 | /* create a progress object */
|
---|
| 1397 | ComObjPtr <Progress> progress;
|
---|
| 1398 | progress.createObject();
|
---|
[6367] | 1399 | rc = progress->init (mParent, static_cast <IHost *> (this),
|
---|
[1] | 1400 | Bstr (tr ("Creating host network interface")),
|
---|
| 1401 | FALSE /* aCancelable */);
|
---|
| 1402 | CheckComRCReturnRC (rc);
|
---|
| 1403 | progress.queryInterfaceTo (aProgress);
|
---|
| 1404 |
|
---|
| 1405 | /* create a new uninitialized host interface object */
|
---|
| 1406 | ComObjPtr <HostNetworkInterface> iface;
|
---|
| 1407 | iface.createObject();
|
---|
| 1408 | iface.queryInterfaceTo (aHostNetworkInterface);
|
---|
| 1409 |
|
---|
| 1410 | /* create the networkInterfaceHelperClient() argument */
|
---|
| 1411 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
[606] | 1412 | d (new NetworkInterfaceHelperClientData());
|
---|
[1] | 1413 | AssertReturn (d.get(), E_OUTOFMEMORY);
|
---|
[606] | 1414 |
|
---|
[1] | 1415 | d->msgCode = SVCHlpMsg::CreateHostNetworkInterface;
|
---|
| 1416 | d->name = aName;
|
---|
| 1417 | d->iface = iface;
|
---|
| 1418 |
|
---|
| 1419 | rc = mParent->startSVCHelperClient (
|
---|
[1135] | 1420 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
[1] | 1421 | networkInterfaceHelperClient,
|
---|
| 1422 | static_cast <void *> (d.get()),
|
---|
| 1423 | progress);
|
---|
[606] | 1424 |
|
---|
[1] | 1425 | if (SUCCEEDED (rc))
|
---|
| 1426 | {
|
---|
| 1427 | /* d is now owned by networkInterfaceHelperClient(), so release it */
|
---|
| 1428 | d.release();
|
---|
| 1429 | }
|
---|
| 1430 |
|
---|
| 1431 | return rc;
|
---|
| 1432 | }
|
---|
| 1433 |
|
---|
| 1434 | STDMETHODIMP
|
---|
[15051] | 1435 | Host::RemoveHostNetworkInterface (IN_GUID aId,
|
---|
[1] | 1436 | IHostNetworkInterface **aHostNetworkInterface,
|
---|
| 1437 | IProgress **aProgress)
|
---|
| 1438 | {
|
---|
[14972] | 1439 | CheckComArgOutPointerValid(aHostNetworkInterface);
|
---|
| 1440 | CheckComArgOutPointerValid(aProgress);
|
---|
[1] | 1441 |
|
---|
[8083] | 1442 | AutoWriteLock alock (this);
|
---|
[1] | 1443 | CHECK_READY();
|
---|
| 1444 |
|
---|
| 1445 | HRESULT rc = S_OK;
|
---|
| 1446 |
|
---|
| 1447 | /* first check whether an interface with the given name already exists */
|
---|
| 1448 | {
|
---|
| 1449 | ComPtr <IHostNetworkInterface> iface;
|
---|
[16207] | 1450 | if (FAILED (FindHostNetworkInterfaceById (aId, iface.asOutParam())))
|
---|
[14996] | 1451 | return setError (VBOX_E_OBJECT_NOT_FOUND,
|
---|
[13842] | 1452 | tr ("Host network interface with UUID {%RTuuid} does not exist"),
|
---|
[1] | 1453 | Guid (aId).raw());
|
---|
| 1454 |
|
---|
| 1455 | /* return the object to be removed to the caller */
|
---|
| 1456 | iface.queryInterfaceTo (aHostNetworkInterface);
|
---|
| 1457 | }
|
---|
| 1458 |
|
---|
| 1459 | /* create a progress object */
|
---|
| 1460 | ComObjPtr <Progress> progress;
|
---|
| 1461 | progress.createObject();
|
---|
[6367] | 1462 | rc = progress->init (mParent, static_cast <IHost *> (this),
|
---|
[1] | 1463 | Bstr (tr ("Removing host network interface")),
|
---|
| 1464 | FALSE /* aCancelable */);
|
---|
| 1465 | CheckComRCReturnRC (rc);
|
---|
| 1466 | progress.queryInterfaceTo (aProgress);
|
---|
| 1467 |
|
---|
| 1468 | /* create the networkInterfaceHelperClient() argument */
|
---|
| 1469 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
[606] | 1470 | d (new NetworkInterfaceHelperClientData());
|
---|
[1] | 1471 | AssertReturn (d.get(), E_OUTOFMEMORY);
|
---|
[606] | 1472 |
|
---|
[1] | 1473 | d->msgCode = SVCHlpMsg::RemoveHostNetworkInterface;
|
---|
| 1474 | d->guid = aId;
|
---|
| 1475 |
|
---|
| 1476 | rc = mParent->startSVCHelperClient (
|
---|
[1135] | 1477 | IsUACEnabled() == TRUE /* aPrivileged */,
|
---|
[1] | 1478 | networkInterfaceHelperClient,
|
---|
| 1479 | static_cast <void *> (d.get()),
|
---|
| 1480 | progress);
|
---|
[606] | 1481 |
|
---|
[1] | 1482 | if (SUCCEEDED (rc))
|
---|
| 1483 | {
|
---|
| 1484 | /* d is now owned by networkInterfaceHelperClient(), so release it */
|
---|
| 1485 | d.release();
|
---|
| 1486 | }
|
---|
| 1487 |
|
---|
| 1488 | return rc;
|
---|
| 1489 | }
|
---|
| 1490 |
|
---|
[3668] | 1491 | #endif /* RT_OS_WINDOWS */
|
---|
[1] | 1492 |
|
---|
[15051] | 1493 | STDMETHODIMP Host::CreateUSBDeviceFilter (IN_BSTR aName, IHostUSBDeviceFilter **aFilter)
|
---|
[1] | 1494 | {
|
---|
[815] | 1495 | #ifdef VBOX_WITH_USB
|
---|
[14938] | 1496 | CheckComArgStrNotEmptyOrNull(aName);
|
---|
[14972] | 1497 | CheckComArgOutPointerValid(aFilter);
|
---|
[1] | 1498 |
|
---|
[8083] | 1499 | AutoWriteLock alock (this);
|
---|
[1] | 1500 | CHECK_READY();
|
---|
| 1501 |
|
---|
| 1502 | ComObjPtr <HostUSBDeviceFilter> filter;
|
---|
| 1503 | filter.createObject();
|
---|
[6965] | 1504 | HRESULT rc = filter->init (this, aName);
|
---|
[1] | 1505 | ComAssertComRCRet (rc, rc);
|
---|
| 1506 | rc = filter.queryInterfaceTo (aFilter);
|
---|
| 1507 | AssertComRCReturn (rc, rc);
|
---|
| 1508 | return S_OK;
|
---|
[815] | 1509 | #else
|
---|
| 1510 | /* Note: The GUI depends on this method returning E_NOTIMPL with no
|
---|
| 1511 | * extended error info to indicate that USB is simply not available
|
---|
[14996] | 1512 | * (w/o treating it as a failure), for example, as in OSE. */
|
---|
[14715] | 1513 | ReturnComNotImplemented();
|
---|
[815] | 1514 | #endif
|
---|
[1] | 1515 | }
|
---|
| 1516 |
|
---|
| 1517 | STDMETHODIMP Host::InsertUSBDeviceFilter (ULONG aPosition, IHostUSBDeviceFilter *aFilter)
|
---|
| 1518 | {
|
---|
[815] | 1519 | #ifdef VBOX_WITH_USB
|
---|
[14972] | 1520 | CheckComArgNotNull(aFilter);
|
---|
[1] | 1521 |
|
---|
[8725] | 1522 | /* Note: HostUSBDeviceFilter and USBProxyService also uses this lock. */
|
---|
[8083] | 1523 | AutoWriteLock alock (this);
|
---|
[1] | 1524 | CHECK_READY();
|
---|
| 1525 |
|
---|
[6965] | 1526 | MultiResult rc = checkUSBProxyService();
|
---|
[815] | 1527 | CheckComRCReturnRC (rc);
|
---|
| 1528 |
|
---|
[1] | 1529 | ComObjPtr <HostUSBDeviceFilter> filter = getDependentChild (aFilter);
|
---|
| 1530 | if (!filter)
|
---|
[14996] | 1531 | return setError (VBOX_E_INVALID_OBJECT_STATE,
|
---|
[1] | 1532 | tr ("The given USB device filter is not created within "
|
---|
| 1533 | "this VirtualBox instance"));
|
---|
| 1534 |
|
---|
| 1535 | if (filter->mInList)
|
---|
| 1536 | return setError (E_INVALIDARG,
|
---|
| 1537 | tr ("The given USB device filter is already in the list"));
|
---|
| 1538 |
|
---|
[815] | 1539 | /* iterate to the position... */
|
---|
[1] | 1540 | USBDeviceFilterList::iterator it = mUSBDeviceFilters.begin();
|
---|
| 1541 | std::advance (it, aPosition);
|
---|
[815] | 1542 | /* ...and insert */
|
---|
[1] | 1543 | mUSBDeviceFilters.insert (it, filter);
|
---|
| 1544 | filter->mInList = true;
|
---|
| 1545 |
|
---|
[815] | 1546 | /* notify the proxy (only when the filter is active) */
|
---|
[6965] | 1547 | if (mUSBProxyService->isActive() && filter->data().mActive)
|
---|
[1] | 1548 | {
|
---|
| 1549 | ComAssertRet (filter->id() == NULL, E_FAIL);
|
---|
[3758] | 1550 | filter->id() = mUSBProxyService->insertFilter (&filter->data().mUSBFilter);
|
---|
[1] | 1551 | }
|
---|
| 1552 |
|
---|
[815] | 1553 | /* save the global settings */
|
---|
[1] | 1554 | alock.unlock();
|
---|
[6965] | 1555 | return rc = mParent->saveSettings();
|
---|
[815] | 1556 | #else
|
---|
| 1557 | /* Note: The GUI depends on this method returning E_NOTIMPL with no
|
---|
| 1558 | * extended error info to indicate that USB is simply not available
|
---|
[14996] | 1559 | * (w/o treating it as a failure), for example, as in OSE. */
|
---|
[14715] | 1560 | ReturnComNotImplemented();
|
---|
[815] | 1561 | #endif
|
---|
[1] | 1562 | }
|
---|
| 1563 |
|
---|
| 1564 | STDMETHODIMP Host::RemoveUSBDeviceFilter (ULONG aPosition, IHostUSBDeviceFilter **aFilter)
|
---|
| 1565 | {
|
---|
[815] | 1566 | #ifdef VBOX_WITH_USB
|
---|
[14972] | 1567 | CheckComArgOutPointerValid(aFilter);
|
---|
[1] | 1568 |
|
---|
[8725] | 1569 | /* Note: HostUSBDeviceFilter and USBProxyService also uses this lock. */
|
---|
[8083] | 1570 | AutoWriteLock alock (this);
|
---|
[1] | 1571 | CHECK_READY();
|
---|
| 1572 |
|
---|
[6965] | 1573 | MultiResult rc = checkUSBProxyService();
|
---|
[815] | 1574 | CheckComRCReturnRC (rc);
|
---|
| 1575 |
|
---|
[1] | 1576 | if (!mUSBDeviceFilters.size())
|
---|
| 1577 | return setError (E_INVALIDARG,
|
---|
| 1578 | tr ("The USB device filter list is empty"));
|
---|
| 1579 |
|
---|
| 1580 | if (aPosition >= mUSBDeviceFilters.size())
|
---|
| 1581 | return setError (E_INVALIDARG,
|
---|
| 1582 | tr ("Invalid position: %lu (must be in range [0, %lu])"),
|
---|
| 1583 | aPosition, mUSBDeviceFilters.size() - 1);
|
---|
| 1584 |
|
---|
| 1585 | ComObjPtr <HostUSBDeviceFilter> filter;
|
---|
| 1586 | {
|
---|
[815] | 1587 | /* iterate to the position... */
|
---|
[1] | 1588 | USBDeviceFilterList::iterator it = mUSBDeviceFilters.begin();
|
---|
| 1589 | std::advance (it, aPosition);
|
---|
[815] | 1590 | /* ...get an element from there... */
|
---|
[1] | 1591 | filter = *it;
|
---|
[815] | 1592 | /* ...and remove */
|
---|
[1] | 1593 | filter->mInList = false;
|
---|
| 1594 | mUSBDeviceFilters.erase (it);
|
---|
| 1595 | }
|
---|
| 1596 |
|
---|
| 1597 | filter.queryInterfaceTo (aFilter);
|
---|
| 1598 |
|
---|
[815] | 1599 | /* notify the proxy (only when the filter is active) */
|
---|
[6965] | 1600 | if (mUSBProxyService->isActive() && filter->data().mActive)
|
---|
[1] | 1601 | {
|
---|
| 1602 | ComAssertRet (filter->id() != NULL, E_FAIL);
|
---|
| 1603 | mUSBProxyService->removeFilter (filter->id());
|
---|
| 1604 | filter->id() = NULL;
|
---|
| 1605 | }
|
---|
| 1606 |
|
---|
[815] | 1607 | /* save the global settings */
|
---|
[1] | 1608 | alock.unlock();
|
---|
[6965] | 1609 | return rc = mParent->saveSettings();
|
---|
[815] | 1610 | #else
|
---|
| 1611 | /* Note: The GUI depends on this method returning E_NOTIMPL with no
|
---|
| 1612 | * extended error info to indicate that USB is simply not available
|
---|
[14996] | 1613 | * (w/o treating it as a failure), for example, as in OSE. */
|
---|
[14715] | 1614 | ReturnComNotImplemented();
|
---|
[815] | 1615 | #endif
|
---|
[1] | 1616 | }
|
---|
| 1617 |
|
---|
| 1618 | // public methods only for internal purposes
|
---|
| 1619 | ////////////////////////////////////////////////////////////////////////////////
|
---|
| 1620 |
|
---|
[6076] | 1621 | HRESULT Host::loadSettings (const settings::Key &aGlobal)
|
---|
[1] | 1622 | {
|
---|
[6076] | 1623 | using namespace settings;
|
---|
| 1624 |
|
---|
[8083] | 1625 | AutoWriteLock alock (this);
|
---|
[1] | 1626 | CHECK_READY();
|
---|
| 1627 |
|
---|
[6076] | 1628 | AssertReturn (!aGlobal.isNull(), E_FAIL);
|
---|
[1] | 1629 |
|
---|
| 1630 | HRESULT rc = S_OK;
|
---|
| 1631 |
|
---|
[7964] | 1632 | #ifdef VBOX_WITH_USB
|
---|
[6076] | 1633 | Key::List filters = aGlobal.key ("USBDeviceFilters").keys ("DeviceFilter");
|
---|
| 1634 | for (Key::List::const_iterator it = filters.begin();
|
---|
| 1635 | it != filters.end(); ++ it)
|
---|
[1] | 1636 | {
|
---|
[6076] | 1637 | Bstr name = (*it).stringValue ("name");
|
---|
| 1638 | bool active = (*it).value <bool> ("active");
|
---|
[1] | 1639 |
|
---|
[7466] | 1640 | Bstr vendorId = (*it).stringValue ("vendorId");
|
---|
| 1641 | Bstr productId = (*it).stringValue ("productId");
|
---|
[6076] | 1642 | Bstr revision = (*it).stringValue ("revision");
|
---|
| 1643 | Bstr manufacturer = (*it).stringValue ("manufacturer");
|
---|
| 1644 | Bstr product = (*it).stringValue ("product");
|
---|
[7466] | 1645 | Bstr serialNumber = (*it).stringValue ("serialNumber");
|
---|
[6076] | 1646 | Bstr port = (*it).stringValue ("port");
|
---|
[1] | 1647 |
|
---|
| 1648 | USBDeviceFilterAction_T action;
|
---|
[7207] | 1649 | action = USBDeviceFilterAction_Ignore;
|
---|
[6076] | 1650 | const char *actionStr = (*it).stringValue ("action");
|
---|
| 1651 | if (strcmp (actionStr, "Ignore") == 0)
|
---|
[7207] | 1652 | action = USBDeviceFilterAction_Ignore;
|
---|
[1] | 1653 | else
|
---|
[6076] | 1654 | if (strcmp (actionStr, "Hold") == 0)
|
---|
[7207] | 1655 | action = USBDeviceFilterAction_Hold;
|
---|
[1] | 1656 | else
|
---|
[6076] | 1657 | AssertMsgFailed (("Invalid action: '%s'\n", actionStr));
|
---|
[1] | 1658 |
|
---|
| 1659 | ComObjPtr <HostUSBDeviceFilter> filterObj;
|
---|
| 1660 | filterObj.createObject();
|
---|
| 1661 | rc = filterObj->init (this,
|
---|
| 1662 | name, active, vendorId, productId, revision,
|
---|
| 1663 | manufacturer, product, serialNumber, port,
|
---|
| 1664 | action);
|
---|
[6076] | 1665 | /* error info is set by init() when appropriate */
|
---|
| 1666 | CheckComRCBreakRC (rc);
|
---|
| 1667 |
|
---|
| 1668 | mUSBDeviceFilters.push_back (filterObj);
|
---|
| 1669 | filterObj->mInList = true;
|
---|
| 1670 |
|
---|
| 1671 | /* notify the proxy (only when the filter is active) */
|
---|
| 1672 | if (filterObj->data().mActive)
|
---|
[1] | 1673 | {
|
---|
[6076] | 1674 | HostUSBDeviceFilter *flt = filterObj; /* resolve ambiguity */
|
---|
| 1675 | flt->id() = mUSBProxyService->insertFilter (&filterObj->data().mUSBFilter);
|
---|
[1] | 1676 | }
|
---|
| 1677 | }
|
---|
[7964] | 1678 | #endif /* VBOX_WITH_USB */
|
---|
[1] | 1679 |
|
---|
| 1680 | return rc;
|
---|
| 1681 | }
|
---|
| 1682 |
|
---|
[6076] | 1683 | HRESULT Host::saveSettings (settings::Key &aGlobal)
|
---|
[1] | 1684 | {
|
---|
[6076] | 1685 | using namespace settings;
|
---|
| 1686 |
|
---|
[8083] | 1687 | AutoWriteLock alock (this);
|
---|
[1] | 1688 | CHECK_READY();
|
---|
| 1689 |
|
---|
[6076] | 1690 | ComAssertRet (!aGlobal.isNull(), E_FAIL);
|
---|
[1] | 1691 |
|
---|
[7964] | 1692 | #ifdef VBOX_WITH_USB
|
---|
[6076] | 1693 | /* first, delete the entry */
|
---|
| 1694 | Key filters = aGlobal.findKey ("USBDeviceFilters");
|
---|
| 1695 | if (!filters.isNull())
|
---|
| 1696 | filters.zap();
|
---|
| 1697 | /* then, recreate it */
|
---|
| 1698 | filters = aGlobal.createKey ("USBDeviceFilters");
|
---|
[1] | 1699 |
|
---|
| 1700 | USBDeviceFilterList::const_iterator it = mUSBDeviceFilters.begin();
|
---|
| 1701 | while (it != mUSBDeviceFilters.end())
|
---|
| 1702 | {
|
---|
[8083] | 1703 | AutoWriteLock filterLock (*it);
|
---|
[1] | 1704 | const HostUSBDeviceFilter::Data &data = (*it)->data();
|
---|
| 1705 |
|
---|
[6076] | 1706 | Key filter = filters.appendKey ("DeviceFilter");
|
---|
[1] | 1707 |
|
---|
[6076] | 1708 | filter.setValue <Bstr> ("name", data.mName);
|
---|
| 1709 | filter.setValue <bool> ("active", !!data.mActive);
|
---|
[1] | 1710 |
|
---|
[6076] | 1711 | /* all are optional */
|
---|
[3756] | 1712 | Bstr str;
|
---|
| 1713 | (*it)->COMGETTER (VendorId) (str.asOutParam());
|
---|
| 1714 | if (!str.isNull())
|
---|
[7466] | 1715 | filter.setValue <Bstr> ("vendorId", str);
|
---|
[3756] | 1716 |
|
---|
| 1717 | (*it)->COMGETTER (ProductId) (str.asOutParam());
|
---|
| 1718 | if (!str.isNull())
|
---|
[7466] | 1719 | filter.setValue <Bstr> ("productId", str);
|
---|
[3756] | 1720 |
|
---|
| 1721 | (*it)->COMGETTER (Revision) (str.asOutParam());
|
---|
| 1722 | if (!str.isNull())
|
---|
[6076] | 1723 | filter.setValue <Bstr> ("revision", str);
|
---|
[3756] | 1724 |
|
---|
| 1725 | (*it)->COMGETTER (Manufacturer) (str.asOutParam());
|
---|
| 1726 | if (!str.isNull())
|
---|
[6076] | 1727 | filter.setValue <Bstr> ("manufacturer", str);
|
---|
[3756] | 1728 |
|
---|
| 1729 | (*it)->COMGETTER (Product) (str.asOutParam());
|
---|
| 1730 | if (!str.isNull())
|
---|
[6076] | 1731 | filter.setValue <Bstr> ("product", str);
|
---|
[3756] | 1732 |
|
---|
| 1733 | (*it)->COMGETTER (SerialNumber) (str.asOutParam());
|
---|
| 1734 | if (!str.isNull())
|
---|
[7466] | 1735 | filter.setValue <Bstr> ("serialNumber", str);
|
---|
[3756] | 1736 |
|
---|
| 1737 | (*it)->COMGETTER (Port) (str.asOutParam());
|
---|
| 1738 | if (!str.isNull())
|
---|
[6076] | 1739 | filter.setValue <Bstr> ("port", str);
|
---|
[3756] | 1740 |
|
---|
[6076] | 1741 | /* action is mandatory */
|
---|
[7847] | 1742 | USBDeviceFilterAction_T action = USBDeviceFilterAction_Null;
|
---|
[3756] | 1743 | (*it)->COMGETTER (Action) (&action);
|
---|
[7207] | 1744 | if (action == USBDeviceFilterAction_Ignore)
|
---|
[6076] | 1745 | filter.setStringValue ("action", "Ignore");
|
---|
[7207] | 1746 | else if (action == USBDeviceFilterAction_Hold)
|
---|
[6076] | 1747 | filter.setStringValue ("action", "Hold");
|
---|
[3756] | 1748 | else
|
---|
| 1749 | AssertMsgFailed (("Invalid action: %d\n", action));
|
---|
[6076] | 1750 |
|
---|
[1] | 1751 | ++ it;
|
---|
| 1752 | }
|
---|
[7964] | 1753 | #endif /* VBOX_WITH_USB */
|
---|
[1] | 1754 |
|
---|
| 1755 | return S_OK;
|
---|
| 1756 | }
|
---|
| 1757 |
|
---|
[7964] | 1758 | #ifdef VBOX_WITH_USB
|
---|
[1] | 1759 | /**
|
---|
[7964] | 1760 | * Called by setter methods of all USB device filters.
|
---|
| 1761 | */
|
---|
| 1762 | HRESULT Host::onUSBDeviceFilterChange (HostUSBDeviceFilter *aFilter,
|
---|
| 1763 | BOOL aActiveChanged /* = FALSE */)
|
---|
| 1764 | {
|
---|
[8083] | 1765 | AutoWriteLock alock (this);
|
---|
[7964] | 1766 | CHECK_READY();
|
---|
| 1767 |
|
---|
| 1768 | if (aFilter->mInList)
|
---|
| 1769 | {
|
---|
| 1770 | if (aActiveChanged)
|
---|
| 1771 | {
|
---|
| 1772 | // insert/remove the filter from the proxy
|
---|
| 1773 | if (aFilter->data().mActive)
|
---|
| 1774 | {
|
---|
| 1775 | ComAssertRet (aFilter->id() == NULL, E_FAIL);
|
---|
| 1776 | aFilter->id() = mUSBProxyService->insertFilter (&aFilter->data().mUSBFilter);
|
---|
| 1777 | }
|
---|
| 1778 | else
|
---|
| 1779 | {
|
---|
| 1780 | ComAssertRet (aFilter->id() != NULL, E_FAIL);
|
---|
| 1781 | mUSBProxyService->removeFilter (aFilter->id());
|
---|
| 1782 | aFilter->id() = NULL;
|
---|
| 1783 | }
|
---|
| 1784 | }
|
---|
| 1785 | else
|
---|
| 1786 | {
|
---|
| 1787 | if (aFilter->data().mActive)
|
---|
| 1788 | {
|
---|
| 1789 | // update the filter in the proxy
|
---|
| 1790 | ComAssertRet (aFilter->id() != NULL, E_FAIL);
|
---|
| 1791 | mUSBProxyService->removeFilter (aFilter->id());
|
---|
| 1792 | aFilter->id() = mUSBProxyService->insertFilter (&aFilter->data().mUSBFilter);
|
---|
| 1793 | }
|
---|
| 1794 | }
|
---|
| 1795 |
|
---|
| 1796 | // save the global settings... yeah, on every single filter property change
|
---|
| 1797 | alock.unlock();
|
---|
| 1798 | return mParent->saveSettings();
|
---|
| 1799 | }
|
---|
| 1800 |
|
---|
| 1801 | return S_OK;
|
---|
| 1802 | }
|
---|
| 1803 |
|
---|
[8744] | 1804 |
|
---|
| 1805 | /**
|
---|
| 1806 | * Interface for obtaining a copy of the USBDeviceFilterList,
|
---|
| 1807 | * used by the USBProxyService.
|
---|
| 1808 | *
|
---|
| 1809 | * @param aGlobalFilters Where to put the global filter list copy.
|
---|
| 1810 | * @param aMachines Where to put the machine vector.
|
---|
| 1811 | */
|
---|
| 1812 | void Host::getUSBFilters(Host::USBDeviceFilterList *aGlobalFilters, VirtualBox::SessionMachineVector *aMachines)
|
---|
| 1813 | {
|
---|
| 1814 | AutoWriteLock alock (this);
|
---|
| 1815 |
|
---|
| 1816 | mParent->getOpenedMachines (*aMachines);
|
---|
| 1817 | *aGlobalFilters = mUSBDeviceFilters;
|
---|
| 1818 | }
|
---|
| 1819 |
|
---|
| 1820 | #endif /* VBOX_WITH_USB */
|
---|
| 1821 |
|
---|
[1] | 1822 | // private methods
|
---|
| 1823 | ////////////////////////////////////////////////////////////////////////////////
|
---|
| 1824 |
|
---|
[14991] | 1825 | #if defined(RT_OS_SOLARIS) && defined(VBOX_USE_LIBHAL)
|
---|
[14725] | 1826 | /* Solaris hosts, loading libhal at runtime */
|
---|
[14722] | 1827 |
|
---|
| 1828 | /**
|
---|
| 1829 | * Helper function to query the hal subsystem for information about DVD drives attached to the
|
---|
| 1830 | * system.
|
---|
| 1831 | *
|
---|
| 1832 | * @returns true if information was successfully obtained, false otherwise
|
---|
| 1833 | * @retval list drives found will be attached to this list
|
---|
| 1834 | */
|
---|
| 1835 | bool Host::getDVDInfoFromHal(std::list <ComObjPtr <HostDVDDrive> > &list)
|
---|
| 1836 | {
|
---|
[2917] | 1837 | bool halSuccess = false;
|
---|
| 1838 | DBusError dbusError;
|
---|
[3950] | 1839 | if (!gLibHalCheckPresence())
|
---|
[3934] | 1840 | return false;
|
---|
[3950] | 1841 | gDBusErrorInit (&dbusError);
|
---|
| 1842 | DBusConnection *dbusConnection = gDBusBusGet(DBUS_BUS_SYSTEM, &dbusError);
|
---|
[2917] | 1843 | if (dbusConnection != 0)
|
---|
| 1844 | {
|
---|
[3950] | 1845 | LibHalContext *halContext = gLibHalCtxNew();
|
---|
[2917] | 1846 | if (halContext != 0)
|
---|
| 1847 | {
|
---|
[3950] | 1848 | if (gLibHalCtxSetDBusConnection (halContext, dbusConnection))
|
---|
[2917] | 1849 | {
|
---|
[3950] | 1850 | if (gLibHalCtxInit(halContext, &dbusError))
|
---|
[2917] | 1851 | {
|
---|
| 1852 | int numDevices;
|
---|
[5368] | 1853 | char **halDevices = gLibHalFindDeviceStringMatch(halContext,
|
---|
| 1854 | "storage.drive_type", "cdrom",
|
---|
| 1855 | &numDevices, &dbusError);
|
---|
[2917] | 1856 | if (halDevices != 0)
|
---|
| 1857 | {
|
---|
[2957] | 1858 | /* Hal is installed and working, so if no devices are reported, assume
|
---|
| 1859 | that there are none. */
|
---|
| 1860 | halSuccess = true;
|
---|
[2917] | 1861 | for (int i = 0; i < numDevices; i++)
|
---|
| 1862 | {
|
---|
[3950] | 1863 | char *devNode = gLibHalDeviceGetPropertyString(halContext,
|
---|
[2917] | 1864 | halDevices[i], "block.device", &dbusError);
|
---|
[5186] | 1865 | #ifdef RT_OS_SOLARIS
|
---|
[5212] | 1866 | /* The CD/DVD ioctls work only for raw device nodes. */
|
---|
[5217] | 1867 | char *tmp = getfullrawname(devNode);
|
---|
[5212] | 1868 | gLibHalFreeString(devNode);
|
---|
| 1869 | devNode = tmp;
|
---|
[5186] | 1870 | #endif
|
---|
[2917] | 1871 | if (devNode != 0)
|
---|
| 1872 | {
|
---|
[5368] | 1873 | // if (validateDevice(devNode, true))
|
---|
| 1874 | // {
|
---|
[2929] | 1875 | Utf8Str description;
|
---|
[2917] | 1876 | char *vendor, *product;
|
---|
[2957] | 1877 | /* We do not check the error here, as this field may
|
---|
| 1878 | not even exist. */
|
---|
[3950] | 1879 | vendor = gLibHalDeviceGetPropertyString(halContext,
|
---|
[2957] | 1880 | halDevices[i], "info.vendor", 0);
|
---|
[3950] | 1881 | product = gLibHalDeviceGetPropertyString(halContext,
|
---|
[2917] | 1882 | halDevices[i], "info.product", &dbusError);
|
---|
[2929] | 1883 | if ((product != 0 && product[0] != 0))
|
---|
[2917] | 1884 | {
|
---|
[2957] | 1885 | if ((vendor != 0) && (vendor[0] != 0))
|
---|
[2917] | 1886 | {
|
---|
[2929] | 1887 | description = Utf8StrFmt ("%s %s",
|
---|
| 1888 | vendor, product);
|
---|
[2917] | 1889 | }
|
---|
| 1890 | else
|
---|
| 1891 | {
|
---|
[2929] | 1892 | description = product;
|
---|
[2917] | 1893 | }
|
---|
| 1894 | ComObjPtr <HostDVDDrive> hostDVDDriveObj;
|
---|
| 1895 | hostDVDDriveObj.createObject();
|
---|
[2957] | 1896 | hostDVDDriveObj->init (Bstr (devNode),
|
---|
| 1897 | Bstr (halDevices[i]),
|
---|
| 1898 | Bstr (description));
|
---|
[2917] | 1899 | list.push_back (hostDVDDriveObj);
|
---|
| 1900 | }
|
---|
| 1901 | else
|
---|
| 1902 | {
|
---|
[2957] | 1903 | if (product == 0)
|
---|
| 1904 | {
|
---|
| 1905 | LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n",
|
---|
| 1906 | halDevices[i], dbusError.name, dbusError.message));
|
---|
[3950] | 1907 | gDBusErrorFree(&dbusError);
|
---|
[2957] | 1908 | }
|
---|
[2917] | 1909 | ComObjPtr <HostDVDDrive> hostDVDDriveObj;
|
---|
| 1910 | hostDVDDriveObj.createObject();
|
---|
[2957] | 1911 | hostDVDDriveObj->init (Bstr (devNode),
|
---|
| 1912 | Bstr (halDevices[i]));
|
---|
[2917] | 1913 | list.push_back (hostDVDDriveObj);
|
---|
| 1914 | }
|
---|
[2957] | 1915 | if (vendor != 0)
|
---|
| 1916 | {
|
---|
[3950] | 1917 | gLibHalFreeString(vendor);
|
---|
[2957] | 1918 | }
|
---|
| 1919 | if (product != 0)
|
---|
| 1920 | {
|
---|
[3950] | 1921 | gLibHalFreeString(product);
|
---|
[2957] | 1922 | }
|
---|
[5368] | 1923 | // }
|
---|
| 1924 | // else
|
---|
| 1925 | // {
|
---|
| 1926 | // LogRel(("Host::COMGETTER(DVDDrives): failed to validate the block device %s as a DVD drive\n"));
|
---|
| 1927 | // }
|
---|
[5186] | 1928 | #ifndef RT_OS_SOLARIS
|
---|
[3950] | 1929 | gLibHalFreeString(devNode);
|
---|
[5186] | 1930 | #else
|
---|
| 1931 | free(devNode);
|
---|
| 1932 | #endif
|
---|
[2917] | 1933 | }
|
---|
| 1934 | else
|
---|
| 1935 | {
|
---|
| 1936 | LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n",
|
---|
| 1937 | halDevices[i], dbusError.name, dbusError.message));
|
---|
[3950] | 1938 | gDBusErrorFree(&dbusError);
|
---|
[2917] | 1939 | }
|
---|
| 1940 | }
|
---|
[3950] | 1941 | gLibHalFreeStringArray(halDevices);
|
---|
[2917] | 1942 | }
|
---|
| 1943 | else
|
---|
| 1944 | {
|
---|
| 1945 | LogRel(("Host::COMGETTER(DVDDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message));
|
---|
[3950] | 1946 | gDBusErrorFree(&dbusError);
|
---|
[2917] | 1947 | }
|
---|
[3950] | 1948 | if (!gLibHalCtxShutdown(halContext, &dbusError)) /* what now? */
|
---|
[2917] | 1949 | {
|
---|
| 1950 | LogRel(("Host::COMGETTER(DVDDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
|
---|
[3950] | 1951 | gDBusErrorFree(&dbusError);
|
---|
[2917] | 1952 | }
|
---|
| 1953 | }
|
---|
| 1954 | else
|
---|
| 1955 | {
|
---|
| 1956 | LogRel(("Host::COMGETTER(DVDDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
|
---|
[3950] | 1957 | gDBusErrorFree(&dbusError);
|
---|
[2917] | 1958 | }
|
---|
[3950] | 1959 | gLibHalCtxFree(halContext);
|
---|
[2917] | 1960 | }
|
---|
| 1961 | else
|
---|
| 1962 | {
|
---|
| 1963 | LogRel(("Host::COMGETTER(DVDDrives): failed to set libhal connection to dbus.\n"));
|
---|
| 1964 | }
|
---|
| 1965 | }
|
---|
| 1966 | else
|
---|
| 1967 | {
|
---|
| 1968 | LogRel(("Host::COMGETTER(DVDDrives): failed to get a libhal context - out of memory?\n"));
|
---|
| 1969 | }
|
---|
[3950] | 1970 | gDBusConnectionUnref(dbusConnection);
|
---|
[2917] | 1971 | }
|
---|
| 1972 | else
|
---|
| 1973 | {
|
---|
| 1974 | LogRel(("Host::COMGETTER(DVDDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
|
---|
[3950] | 1975 | gDBusErrorFree(&dbusError);
|
---|
[2917] | 1976 | }
|
---|
| 1977 | return halSuccess;
|
---|
| 1978 | }
|
---|
[2957] | 1979 |
|
---|
| 1980 |
|
---|
| 1981 | /**
|
---|
| 1982 | * Helper function to query the hal subsystem for information about floppy drives attached to the
|
---|
| 1983 | * system.
|
---|
| 1984 | *
|
---|
| 1985 | * @returns true if information was successfully obtained, false otherwise
|
---|
| 1986 | * @retval list drives found will be attached to this list
|
---|
| 1987 | */
|
---|
| 1988 | bool Host::getFloppyInfoFromHal(std::list <ComObjPtr <HostFloppyDrive> > &list)
|
---|
| 1989 | {
|
---|
| 1990 | bool halSuccess = false;
|
---|
| 1991 | DBusError dbusError;
|
---|
[3950] | 1992 | if (!gLibHalCheckPresence())
|
---|
[3934] | 1993 | return false;
|
---|
[3950] | 1994 | gDBusErrorInit (&dbusError);
|
---|
| 1995 | DBusConnection *dbusConnection = gDBusBusGet(DBUS_BUS_SYSTEM, &dbusError);
|
---|
[2957] | 1996 | if (dbusConnection != 0)
|
---|
| 1997 | {
|
---|
[3950] | 1998 | LibHalContext *halContext = gLibHalCtxNew();
|
---|
[2957] | 1999 | if (halContext != 0)
|
---|
| 2000 | {
|
---|
[3950] | 2001 | if (gLibHalCtxSetDBusConnection (halContext, dbusConnection))
|
---|
[2957] | 2002 | {
|
---|
[3950] | 2003 | if (gLibHalCtxInit(halContext, &dbusError))
|
---|
[2957] | 2004 | {
|
---|
| 2005 | int numDevices;
|
---|
[5368] | 2006 | char **halDevices = gLibHalFindDeviceStringMatch(halContext,
|
---|
| 2007 | "storage.drive_type", "floppy",
|
---|
| 2008 | &numDevices, &dbusError);
|
---|
[2957] | 2009 | if (halDevices != 0)
|
---|
| 2010 | {
|
---|
| 2011 | /* Hal is installed and working, so if no devices are reported, assume
|
---|
| 2012 | that there are none. */
|
---|
| 2013 | halSuccess = true;
|
---|
| 2014 | for (int i = 0; i < numDevices; i++)
|
---|
| 2015 | {
|
---|
[3950] | 2016 | char *driveType = gLibHalDeviceGetPropertyString(halContext,
|
---|
[2957] | 2017 | halDevices[i], "storage.drive_type", 0);
|
---|
| 2018 | if (driveType != 0)
|
---|
| 2019 | {
|
---|
| 2020 | if (strcmp(driveType, "floppy") != 0)
|
---|
| 2021 | {
|
---|
[3950] | 2022 | gLibHalFreeString(driveType);
|
---|
[2957] | 2023 | continue;
|
---|
| 2024 | }
|
---|
[3950] | 2025 | gLibHalFreeString(driveType);
|
---|
[2957] | 2026 | }
|
---|
| 2027 | else
|
---|
| 2028 | {
|
---|
| 2029 | /* An error occurred. The attribute "storage.drive_type"
|
---|
| 2030 | probably didn't exist. */
|
---|
| 2031 | continue;
|
---|
| 2032 | }
|
---|
[3950] | 2033 | char *devNode = gLibHalDeviceGetPropertyString(halContext,
|
---|
[2957] | 2034 | halDevices[i], "block.device", &dbusError);
|
---|
| 2035 | if (devNode != 0)
|
---|
| 2036 | {
|
---|
[5368] | 2037 | // if (validateDevice(devNode, false))
|
---|
| 2038 | // {
|
---|
[2957] | 2039 | Utf8Str description;
|
---|
| 2040 | char *vendor, *product;
|
---|
| 2041 | /* We do not check the error here, as this field may
|
---|
| 2042 | not even exist. */
|
---|
[3950] | 2043 | vendor = gLibHalDeviceGetPropertyString(halContext,
|
---|
[2957] | 2044 | halDevices[i], "info.vendor", 0);
|
---|
[3950] | 2045 | product = gLibHalDeviceGetPropertyString(halContext,
|
---|
[2957] | 2046 | halDevices[i], "info.product", &dbusError);
|
---|
| 2047 | if ((product != 0) && (product[0] != 0))
|
---|
| 2048 | {
|
---|
| 2049 | if ((vendor != 0) && (vendor[0] != 0))
|
---|
| 2050 | {
|
---|
| 2051 | description = Utf8StrFmt ("%s %s",
|
---|
| 2052 | vendor, product);
|
---|
| 2053 | }
|
---|
| 2054 | else
|
---|
| 2055 | {
|
---|
| 2056 | description = product;
|
---|
| 2057 | }
|
---|
| 2058 | ComObjPtr <HostFloppyDrive> hostFloppyDrive;
|
---|
| 2059 | hostFloppyDrive.createObject();
|
---|
| 2060 | hostFloppyDrive->init (Bstr (devNode),
|
---|
| 2061 | Bstr (halDevices[i]),
|
---|
| 2062 | Bstr (description));
|
---|
| 2063 | list.push_back (hostFloppyDrive);
|
---|
| 2064 | }
|
---|
| 2065 | else
|
---|
| 2066 | {
|
---|
| 2067 | if (product == 0)
|
---|
| 2068 | {
|
---|
| 2069 | LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n",
|
---|
| 2070 | halDevices[i], dbusError.name, dbusError.message));
|
---|
[3950] | 2071 | gDBusErrorFree(&dbusError);
|
---|
[2957] | 2072 | }
|
---|
| 2073 | ComObjPtr <HostFloppyDrive> hostFloppyDrive;
|
---|
| 2074 | hostFloppyDrive.createObject();
|
---|
| 2075 | hostFloppyDrive->init (Bstr (devNode),
|
---|
| 2076 | Bstr (halDevices[i]));
|
---|
| 2077 | list.push_back (hostFloppyDrive);
|
---|
| 2078 | }
|
---|
| 2079 | if (vendor != 0)
|
---|
| 2080 | {
|
---|
[3950] | 2081 | gLibHalFreeString(vendor);
|
---|
[2957] | 2082 | }
|
---|
| 2083 | if (product != 0)
|
---|
| 2084 | {
|
---|
[3950] | 2085 | gLibHalFreeString(product);
|
---|
[2957] | 2086 | }
|
---|
[5368] | 2087 | // }
|
---|
| 2088 | // else
|
---|
| 2089 | // {
|
---|
| 2090 | // LogRel(("Host::COMGETTER(FloppyDrives): failed to validate the block device %s as a floppy drive\n"));
|
---|
| 2091 | // }
|
---|
[3950] | 2092 | gLibHalFreeString(devNode);
|
---|
[2957] | 2093 | }
|
---|
| 2094 | else
|
---|
| 2095 | {
|
---|
| 2096 | LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n",
|
---|
| 2097 | halDevices[i], dbusError.name, dbusError.message));
|
---|
[3950] | 2098 | gDBusErrorFree(&dbusError);
|
---|
[2957] | 2099 | }
|
---|
| 2100 | }
|
---|
[3950] | 2101 | gLibHalFreeStringArray(halDevices);
|
---|
[2957] | 2102 | }
|
---|
| 2103 | else
|
---|
| 2104 | {
|
---|
| 2105 | LogRel(("Host::COMGETTER(FloppyDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message));
|
---|
[3950] | 2106 | gDBusErrorFree(&dbusError);
|
---|
[2957] | 2107 | }
|
---|
[3950] | 2108 | if (!gLibHalCtxShutdown(halContext, &dbusError)) /* what now? */
|
---|
[2957] | 2109 | {
|
---|
| 2110 | LogRel(("Host::COMGETTER(FloppyDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
|
---|
[3950] | 2111 | gDBusErrorFree(&dbusError);
|
---|
[2957] | 2112 | }
|
---|
| 2113 | }
|
---|
| 2114 | else
|
---|
| 2115 | {
|
---|
| 2116 | LogRel(("Host::COMGETTER(FloppyDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
|
---|
[3950] | 2117 | gDBusErrorFree(&dbusError);
|
---|
[2957] | 2118 | }
|
---|
[3950] | 2119 | gLibHalCtxFree(halContext);
|
---|
[2957] | 2120 | }
|
---|
| 2121 | else
|
---|
| 2122 | {
|
---|
| 2123 | LogRel(("Host::COMGETTER(FloppyDrives): failed to set libhal connection to dbus.\n"));
|
---|
| 2124 | }
|
---|
| 2125 | }
|
---|
| 2126 | else
|
---|
| 2127 | {
|
---|
| 2128 | LogRel(("Host::COMGETTER(FloppyDrives): failed to get a libhal context - out of memory?\n"));
|
---|
| 2129 | }
|
---|
[3950] | 2130 | gDBusConnectionUnref(dbusConnection);
|
---|
[2957] | 2131 | }
|
---|
| 2132 | else
|
---|
| 2133 | {
|
---|
| 2134 | LogRel(("Host::COMGETTER(FloppyDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
|
---|
[3950] | 2135 | gDBusErrorFree(&dbusError);
|
---|
[2957] | 2136 | }
|
---|
| 2137 | return halSuccess;
|
---|
| 2138 | }
|
---|
[14991] | 2139 | #endif /* RT_OS_SOLARIS and VBOX_USE_HAL */
|
---|
[2917] | 2140 |
|
---|
[14991] | 2141 | #if defined(RT_OS_SOLARIS)
|
---|
[14725] | 2142 |
|
---|
[2917] | 2143 | /**
|
---|
[1] | 2144 | * Helper function to parse the given mount file and add found entries
|
---|
| 2145 | */
|
---|
| 2146 | void Host::parseMountTable(char *mountTable, std::list <ComObjPtr <HostDVDDrive> > &list)
|
---|
| 2147 | {
|
---|
[5186] | 2148 | #ifdef RT_OS_LINUX
|
---|
[1] | 2149 | FILE *mtab = setmntent(mountTable, "r");
|
---|
| 2150 | if (mtab)
|
---|
| 2151 | {
|
---|
| 2152 | struct mntent *mntent;
|
---|
| 2153 | char *mnt_type;
|
---|
| 2154 | char *mnt_dev;
|
---|
| 2155 | char *tmp;
|
---|
| 2156 | while ((mntent = getmntent(mtab)))
|
---|
| 2157 | {
|
---|
| 2158 | mnt_type = (char*)malloc(strlen(mntent->mnt_type) + 1);
|
---|
| 2159 | mnt_dev = (char*)malloc(strlen(mntent->mnt_fsname) + 1);
|
---|
| 2160 | strcpy(mnt_type, mntent->mnt_type);
|
---|
| 2161 | strcpy(mnt_dev, mntent->mnt_fsname);
|
---|
| 2162 | // supermount fs case
|
---|
| 2163 | if (strcmp(mnt_type, "supermount") == 0)
|
---|
| 2164 | {
|
---|
| 2165 | tmp = strstr(mntent->mnt_opts, "fs=");
|
---|
| 2166 | if (tmp)
|
---|
| 2167 | {
|
---|
| 2168 | free(mnt_type);
|
---|
| 2169 | mnt_type = strdup(tmp + strlen("fs="));
|
---|
| 2170 | if (mnt_type)
|
---|
| 2171 | {
|
---|
| 2172 | tmp = strchr(mnt_type, ',');
|
---|
| 2173 | if (tmp)
|
---|
| 2174 | *tmp = '\0';
|
---|
| 2175 | }
|
---|
| 2176 | }
|
---|
| 2177 | tmp = strstr(mntent->mnt_opts, "dev=");
|
---|
| 2178 | if (tmp)
|
---|
| 2179 | {
|
---|
| 2180 | free(mnt_dev);
|
---|
| 2181 | mnt_dev = strdup(tmp + strlen("dev="));
|
---|
| 2182 | if (mnt_dev)
|
---|
| 2183 | {
|
---|
| 2184 | tmp = strchr(mnt_dev, ',');
|
---|
| 2185 | if (tmp)
|
---|
| 2186 | *tmp = '\0';
|
---|
| 2187 | }
|
---|
| 2188 | }
|
---|
| 2189 | }
|
---|
[4395] | 2190 | // use strstr here to cover things fs types like "udf,iso9660"
|
---|
| 2191 | if (strstr(mnt_type, "iso9660") == 0)
|
---|
[1] | 2192 | {
|
---|
| 2193 | /** @todo check whether we've already got the drive in our list! */
|
---|
| 2194 | if (validateDevice(mnt_dev, true))
|
---|
| 2195 | {
|
---|
| 2196 | ComObjPtr <HostDVDDrive> hostDVDDriveObj;
|
---|
| 2197 | hostDVDDriveObj.createObject();
|
---|
| 2198 | hostDVDDriveObj->init (Bstr (mnt_dev));
|
---|
| 2199 | list.push_back (hostDVDDriveObj);
|
---|
| 2200 | }
|
---|
| 2201 | }
|
---|
| 2202 | free(mnt_dev);
|
---|
| 2203 | free(mnt_type);
|
---|
| 2204 | }
|
---|
| 2205 | endmntent(mtab);
|
---|
| 2206 | }
|
---|
[5186] | 2207 | #else // RT_OS_SOLARIS
|
---|
| 2208 | FILE *mntFile = fopen(mountTable, "r");
|
---|
| 2209 | if (mntFile)
|
---|
| 2210 | {
|
---|
| 2211 | struct mnttab mntTab;
|
---|
| 2212 | while (getmntent(mntFile, &mntTab) == 0)
|
---|
| 2213 | {
|
---|
| 2214 | char *mountName = strdup(mntTab.mnt_special);
|
---|
| 2215 | char *mountPoint = strdup(mntTab.mnt_mountp);
|
---|
| 2216 | char *mountFSType = strdup(mntTab.mnt_fstype);
|
---|
| 2217 |
|
---|
| 2218 | // skip devices we are not interested in
|
---|
| 2219 | if ((*mountName && mountName[0] == '/') && // skip 'fake' devices (like -hosts, proc, fd, swap)
|
---|
| 2220 | (*mountFSType && (strcmp(mountFSType, "devfs") != 0 && // skip devfs (i.e. /devices)
|
---|
| 2221 | strcmp(mountFSType, "dev") != 0 && // skip dev (i.e. /dev)
|
---|
| 2222 | strcmp(mountFSType, "lofs") != 0)) && // skip loop-back file-system (lofs)
|
---|
| 2223 | (*mountPoint && strcmp(mountPoint, "/") != 0)) // skip point '/' (Can CD/DVD be mounted at '/' ???)
|
---|
| 2224 | {
|
---|
| 2225 | char *rawDevName = getfullrawname(mountName);
|
---|
| 2226 | if (validateDevice(rawDevName, true))
|
---|
| 2227 | {
|
---|
| 2228 | ComObjPtr <HostDVDDrive> hostDVDDriveObj;
|
---|
| 2229 | hostDVDDriveObj.createObject();
|
---|
| 2230 | hostDVDDriveObj->init (Bstr (rawDevName));
|
---|
| 2231 | list.push_back (hostDVDDriveObj);
|
---|
| 2232 | }
|
---|
| 2233 | free(rawDevName);
|
---|
| 2234 | }
|
---|
| 2235 |
|
---|
| 2236 | free(mountName);
|
---|
| 2237 | free(mountPoint);
|
---|
| 2238 | free(mountFSType);
|
---|
| 2239 | }
|
---|
| 2240 |
|
---|
| 2241 | fclose(mntFile);
|
---|
| 2242 | }
|
---|
| 2243 | #endif
|
---|
[1] | 2244 | }
|
---|
| 2245 |
|
---|
| 2246 | /**
|
---|
| 2247 | * Helper function to check whether the given device node is a valid drive
|
---|
| 2248 | */
|
---|
[2333] | 2249 | bool Host::validateDevice(const char *deviceNode, bool isCDROM)
|
---|
[1] | 2250 | {
|
---|
| 2251 | struct stat statInfo;
|
---|
| 2252 | bool retValue = false;
|
---|
| 2253 |
|
---|
| 2254 | // sanity check
|
---|
| 2255 | if (!deviceNode)
|
---|
| 2256 | {
|
---|
| 2257 | return false;
|
---|
| 2258 | }
|
---|
| 2259 |
|
---|
| 2260 | // first a simple stat() call
|
---|
| 2261 | if (stat(deviceNode, &statInfo) < 0)
|
---|
| 2262 | {
|
---|
| 2263 | return false;
|
---|
| 2264 | } else
|
---|
| 2265 | {
|
---|
| 2266 | if (isCDROM)
|
---|
| 2267 | {
|
---|
| 2268 | if (S_ISCHR(statInfo.st_mode) || S_ISBLK(statInfo.st_mode))
|
---|
| 2269 | {
|
---|
| 2270 | int fileHandle;
|
---|
| 2271 | // now try to open the device
|
---|
[259] | 2272 | fileHandle = open(deviceNode, O_RDONLY | O_NONBLOCK, 0);
|
---|
[1] | 2273 | if (fileHandle >= 0)
|
---|
| 2274 | {
|
---|
| 2275 | cdrom_subchnl cdChannelInfo;
|
---|
[1762] | 2276 | cdChannelInfo.cdsc_format = CDROM_MSF;
|
---|
[1] | 2277 | // this call will finally reveal the whole truth
|
---|
[5186] | 2278 | #ifdef RT_OS_LINUX
|
---|
[1] | 2279 | if ((ioctl(fileHandle, CDROMSUBCHNL, &cdChannelInfo) == 0) ||
|
---|
| 2280 | (errno == EIO) || (errno == ENOENT) ||
|
---|
| 2281 | (errno == EINVAL) || (errno == ENOMEDIUM))
|
---|
[5186] | 2282 | #else
|
---|
| 2283 | if ((ioctl(fileHandle, CDROMSUBCHNL, &cdChannelInfo) == 0) ||
|
---|
| 2284 | (errno == EIO) || (errno == ENOENT) ||
|
---|
| 2285 | (errno == EINVAL))
|
---|
| 2286 | #endif
|
---|
[1] | 2287 | {
|
---|
| 2288 | retValue = true;
|
---|
| 2289 | }
|
---|
| 2290 | close(fileHandle);
|
---|
| 2291 | }
|
---|
| 2292 | }
|
---|
| 2293 | } else
|
---|
| 2294 | {
|
---|
| 2295 | // floppy case
|
---|
| 2296 | if (S_ISCHR(statInfo.st_mode) || S_ISBLK(statInfo.st_mode))
|
---|
| 2297 | {
|
---|
| 2298 | /// @todo do some more testing, maybe a nice IOCTL!
|
---|
| 2299 | retValue = true;
|
---|
| 2300 | }
|
---|
| 2301 | }
|
---|
| 2302 | }
|
---|
| 2303 | return retValue;
|
---|
| 2304 | }
|
---|
[14991] | 2305 | #endif // RT_OS_SOLARIS
|
---|
[1] | 2306 |
|
---|
[7964] | 2307 | #ifdef VBOX_WITH_USB
|
---|
[1] | 2308 | /**
|
---|
[815] | 2309 | * Checks for the presense and status of the USB Proxy Service.
|
---|
[16261] | 2310 | * Returns S_OK when the Proxy is present and OK, VBOX_E_HOST_ERROR (as a
|
---|
| 2311 | * warning) if the proxy service is not available due to the way the host is
|
---|
| 2312 | * configured (at present, that means that usbfs and hal/DBus are not
|
---|
| 2313 | * available on a Linux host) or E_FAIL and a corresponding error message
|
---|
| 2314 | * otherwise. Intended to be used by methods that rely on the Proxy Service
|
---|
| 2315 | * availability.
|
---|
[815] | 2316 | *
|
---|
[6965] | 2317 | * @note This method may return a warning result code. It is recommended to use
|
---|
| 2318 | * MultiError to store the return value.
|
---|
| 2319 | *
|
---|
[815] | 2320 | * @note Locks this object for reading.
|
---|
| 2321 | */
|
---|
| 2322 | HRESULT Host::checkUSBProxyService()
|
---|
| 2323 | {
|
---|
[8083] | 2324 | AutoWriteLock alock (this);
|
---|
[815] | 2325 | CHECK_READY();
|
---|
| 2326 |
|
---|
| 2327 | AssertReturn (mUSBProxyService, E_FAIL);
|
---|
[7104] | 2328 | if (!mUSBProxyService->isActive())
|
---|
[815] | 2329 | {
|
---|
| 2330 | /* disable the USB controller completely to avoid assertions if the
|
---|
| 2331 | * USB proxy service could not start. */
|
---|
| 2332 |
|
---|
| 2333 | if (mUSBProxyService->getLastError() == VERR_FILE_NOT_FOUND)
|
---|
[6965] | 2334 | return setWarning (E_FAIL,
|
---|
[13837] | 2335 | tr ("Could not load the Host USB Proxy Service (%Rrc). "
|
---|
[15869] | 2336 | "The service might not be installed on the host computer"),
|
---|
[815] | 2337 | mUSBProxyService->getLastError());
|
---|
[7104] | 2338 | if (mUSBProxyService->getLastError() == VINF_SUCCESS)
|
---|
[16258] | 2339 | #ifdef RT_OS_LINUX
|
---|
| 2340 | return setWarning (VBOX_E_HOST_ERROR,
|
---|
| 2341 | # ifdef VBOX_WITH_DBUS
|
---|
| 2342 | tr ("The USB Proxy Service could not be started, because neither the USB file system (usbfs) nor the hardware information service (hal) is available")
|
---|
| 2343 | # else
|
---|
| 2344 | tr ("The USB Proxy Service could not be started, because the USB file system (usbfs) is not available")
|
---|
| 2345 | # endif
|
---|
[16289] | 2346 | );
|
---|
| 2347 | #else /* !RT_OS_LINUX */
|
---|
[6965] | 2348 | return setWarning (E_FAIL,
|
---|
[7104] | 2349 | tr ("The USB Proxy Service has not yet been ported to this host"));
|
---|
[16289] | 2350 | #endif /* !RT_OS_LINUX */
|
---|
[7104] | 2351 | return setWarning (E_FAIL,
|
---|
[13837] | 2352 | tr ("Could not load the Host USB Proxy service (%Rrc)"),
|
---|
[7104] | 2353 | mUSBProxyService->getLastError());
|
---|
[815] | 2354 | }
|
---|
| 2355 |
|
---|
| 2356 | return S_OK;
|
---|
| 2357 | }
|
---|
[8744] | 2358 | #endif /* VBOX_WITH_USB */
|
---|
[815] | 2359 |
|
---|
[3668] | 2360 | #ifdef RT_OS_WINDOWS
|
---|
[1] | 2361 |
|
---|
| 2362 | /* The original source of the VBoxTAP adapter creation/destruction code has the following copyright */
|
---|
| 2363 | /*
|
---|
| 2364 | Copyright 2004 by the Massachusetts Institute of Technology
|
---|
| 2365 |
|
---|
| 2366 | All rights reserved.
|
---|
| 2367 |
|
---|
| 2368 | Permission to use, copy, modify, and distribute this software and its
|
---|
| 2369 | documentation for any purpose and without fee is hereby granted,
|
---|
| 2370 | provided that the above copyright notice appear in all copies and that
|
---|
| 2371 | both that copyright notice and this permission notice appear in
|
---|
| 2372 | supporting documentation, and that the name of the Massachusetts
|
---|
| 2373 | Institute of Technology (M.I.T.) not be used in advertising or publicity
|
---|
| 2374 | pertaining to distribution of the software without specific, written
|
---|
| 2375 | prior permission.
|
---|
| 2376 |
|
---|
| 2377 | M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
---|
| 2378 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
---|
| 2379 | M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
---|
| 2380 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
---|
| 2381 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
---|
| 2382 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
---|
| 2383 | SOFTWARE.
|
---|
| 2384 | */
|
---|
| 2385 |
|
---|
| 2386 |
|
---|
| 2387 | #define NETSHELL_LIBRARY _T("netshell.dll")
|
---|
| 2388 |
|
---|
| 2389 | /**
|
---|
| 2390 | * Use the IShellFolder API to rename the connection.
|
---|
| 2391 | */
|
---|
| 2392 | static HRESULT rename_shellfolder (PCWSTR wGuid, PCWSTR wNewName)
|
---|
| 2393 | {
|
---|
| 2394 | /* This is the GUID for the network connections folder. It is constant.
|
---|
| 2395 | * {7007ACC7-3202-11D1-AAD2-00805FC1270E} */
|
---|
| 2396 | const GUID CLSID_NetworkConnections = {
|
---|
| 2397 | 0x7007ACC7, 0x3202, 0x11D1, {
|
---|
| 2398 | 0xAA, 0xD2, 0x00, 0x80, 0x5F, 0xC1, 0x27, 0x0E
|
---|
| 2399 | }
|
---|
| 2400 | };
|
---|
| 2401 |
|
---|
| 2402 | LPITEMIDLIST pidl = NULL;
|
---|
| 2403 | IShellFolder *pShellFolder = NULL;
|
---|
| 2404 | HRESULT hr;
|
---|
| 2405 |
|
---|
| 2406 | /* Build the display name in the form "::{GUID}". */
|
---|
| 2407 | if (wcslen (wGuid) >= MAX_PATH)
|
---|
| 2408 | return E_INVALIDARG;
|
---|
| 2409 | WCHAR szAdapterGuid[MAX_PATH + 2] = {0};
|
---|
| 2410 | swprintf (szAdapterGuid, L"::%ls", wGuid);
|
---|
| 2411 |
|
---|
| 2412 | /* Create an instance of the network connections folder. */
|
---|
| 2413 | hr = CoCreateInstance (CLSID_NetworkConnections, NULL,
|
---|
| 2414 | CLSCTX_INPROC_SERVER, IID_IShellFolder,
|
---|
| 2415 | reinterpret_cast <LPVOID *> (&pShellFolder));
|
---|
| 2416 | /* Parse the display name. */
|
---|
| 2417 | if (SUCCEEDED (hr))
|
---|
| 2418 | {
|
---|
| 2419 | hr = pShellFolder->ParseDisplayName (NULL, NULL, szAdapterGuid, NULL,
|
---|
| 2420 | &pidl, NULL);
|
---|
| 2421 | }
|
---|
| 2422 | if (SUCCEEDED (hr))
|
---|
| 2423 | {
|
---|
| 2424 | hr = pShellFolder->SetNameOf (NULL, pidl, wNewName, SHGDN_NORMAL,
|
---|
| 2425 | &pidl);
|
---|
| 2426 | }
|
---|
| 2427 |
|
---|
| 2428 | CoTaskMemFree (pidl);
|
---|
| 2429 |
|
---|
| 2430 | if (pShellFolder)
|
---|
| 2431 | pShellFolder->Release();
|
---|
| 2432 |
|
---|
| 2433 | return hr;
|
---|
| 2434 | }
|
---|
| 2435 |
|
---|
| 2436 | extern "C" HRESULT RenameConnection (PCWSTR GuidString, PCWSTR NewName)
|
---|
| 2437 | {
|
---|
| 2438 | typedef HRESULT (WINAPI *lpHrRenameConnection) (const GUID *, PCWSTR);
|
---|
| 2439 | lpHrRenameConnection RenameConnectionFunc = NULL;
|
---|
| 2440 | HRESULT status;
|
---|
| 2441 |
|
---|
| 2442 | /* First try the IShellFolder interface, which was unimplemented
|
---|
| 2443 | * for the network connections folder before XP. */
|
---|
| 2444 | status = rename_shellfolder (GuidString, NewName);
|
---|
| 2445 | if (status == E_NOTIMPL)
|
---|
| 2446 | {
|
---|
| 2447 | /** @todo that code doesn't seem to work! */
|
---|
| 2448 | /* The IShellFolder interface is not implemented on this platform.
|
---|
| 2449 | * Try the (undocumented) HrRenameConnection API in the netshell
|
---|
| 2450 | * library. */
|
---|
| 2451 | CLSID clsid;
|
---|
| 2452 | HINSTANCE hNetShell;
|
---|
| 2453 | status = CLSIDFromString ((LPOLESTR) GuidString, &clsid);
|
---|
| 2454 | if (FAILED(status))
|
---|
| 2455 | return E_FAIL;
|
---|
| 2456 | hNetShell = LoadLibrary (NETSHELL_LIBRARY);
|
---|
| 2457 | if (hNetShell == NULL)
|
---|
| 2458 | return E_FAIL;
|
---|
| 2459 | RenameConnectionFunc =
|
---|
| 2460 | (lpHrRenameConnection) GetProcAddress (hNetShell,
|
---|
| 2461 | "HrRenameConnection");
|
---|
| 2462 | if (RenameConnectionFunc == NULL)
|
---|
| 2463 | {
|
---|
| 2464 | FreeLibrary (hNetShell);
|
---|
| 2465 | return E_FAIL;
|
---|
| 2466 | }
|
---|
| 2467 | status = RenameConnectionFunc (&clsid, NewName);
|
---|
| 2468 | FreeLibrary (hNetShell);
|
---|
| 2469 | }
|
---|
| 2470 | if (FAILED (status))
|
---|
| 2471 | return status;
|
---|
| 2472 |
|
---|
| 2473 | return S_OK;
|
---|
| 2474 | }
|
---|
| 2475 |
|
---|
| 2476 | #define DRIVERHWID _T("vboxtap")
|
---|
| 2477 |
|
---|
| 2478 | #define SetErrBreak(strAndArgs) \
|
---|
| 2479 | if (1) { \
|
---|
| 2480 | aErrMsg = Utf8StrFmt strAndArgs; vrc = VERR_GENERAL_FAILURE; break; \
|
---|
| 2481 | } else do {} while (0)
|
---|
| 2482 |
|
---|
| 2483 | /* static */
|
---|
| 2484 | int Host::createNetworkInterface (SVCHlpClient *aClient,
|
---|
| 2485 | const Utf8Str &aName,
|
---|
| 2486 | Guid &aGUID, Utf8Str &aErrMsg)
|
---|
| 2487 | {
|
---|
| 2488 | LogFlowFuncEnter();
|
---|
| 2489 | LogFlowFunc (("Network connection name = '%s'\n", aName.raw()));
|
---|
| 2490 |
|
---|
[606] | 2491 | AssertReturn (aClient, VERR_INVALID_POINTER);
|
---|
| 2492 | AssertReturn (!aName.isNull(), VERR_INVALID_PARAMETER);
|
---|
[1] | 2493 |
|
---|
| 2494 | int vrc = VINF_SUCCESS;
|
---|
| 2495 |
|
---|
| 2496 | HDEVINFO hDeviceInfo = INVALID_HANDLE_VALUE;
|
---|
| 2497 | SP_DEVINFO_DATA DeviceInfoData;
|
---|
| 2498 | DWORD ret = 0;
|
---|
| 2499 | BOOL found = FALSE;
|
---|
| 2500 | BOOL registered = FALSE;
|
---|
| 2501 | BOOL destroyList = FALSE;
|
---|
| 2502 | TCHAR pCfgGuidString [50];
|
---|
| 2503 |
|
---|
| 2504 | do
|
---|
| 2505 | {
|
---|
| 2506 | BOOL ok;
|
---|
| 2507 | GUID netGuid;
|
---|
| 2508 | SP_DRVINFO_DATA DriverInfoData;
|
---|
| 2509 | SP_DEVINSTALL_PARAMS DeviceInstallParams;
|
---|
| 2510 | TCHAR className [MAX_PATH];
|
---|
| 2511 | DWORD index = 0;
|
---|
| 2512 | PSP_DRVINFO_DETAIL_DATA pDriverInfoDetail;
|
---|
| 2513 | /* for our purposes, 2k buffer is more
|
---|
| 2514 | * than enough to obtain the hardware ID
|
---|
[606] | 2515 | * of the VBoxTAP driver. */
|
---|
[1] | 2516 | DWORD detailBuf [2048];
|
---|
[606] | 2517 |
|
---|
[1] | 2518 | HKEY hkey = NULL;
|
---|
| 2519 | DWORD cbSize;
|
---|
| 2520 | DWORD dwValueType;
|
---|
[606] | 2521 |
|
---|
[1] | 2522 | /* initialize the structure size */
|
---|
| 2523 | DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
|
---|
| 2524 | DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
|
---|
[606] | 2525 |
|
---|
[1] | 2526 | /* copy the net class GUID */
|
---|
| 2527 | memcpy(&netGuid, &GUID_DEVCLASS_NET, sizeof(GUID_DEVCLASS_NET));
|
---|
[606] | 2528 |
|
---|
[1] | 2529 | /* create an empty device info set associated with the net class GUID */
|
---|
| 2530 | hDeviceInfo = SetupDiCreateDeviceInfoList (&netGuid, NULL);
|
---|
| 2531 | if (hDeviceInfo == INVALID_HANDLE_VALUE)
|
---|
| 2532 | SetErrBreak (("SetupDiCreateDeviceInfoList failed (0x%08X)",
|
---|
| 2533 | GetLastError()));
|
---|
| 2534 |
|
---|
| 2535 | /* get the class name from GUID */
|
---|
| 2536 | ok = SetupDiClassNameFromGuid (&netGuid, className, MAX_PATH, NULL);
|
---|
| 2537 | if (!ok)
|
---|
| 2538 | SetErrBreak (("SetupDiClassNameFromGuid failed (0x%08X)",
|
---|
| 2539 | GetLastError()));
|
---|
| 2540 |
|
---|
| 2541 | /* create a device info element and add the new device instance
|
---|
| 2542 | * key to registry */
|
---|
| 2543 | ok = SetupDiCreateDeviceInfo (hDeviceInfo, className, &netGuid, NULL, NULL,
|
---|
| 2544 | DICD_GENERATE_ID, &DeviceInfoData);
|
---|
| 2545 | if (!ok)
|
---|
| 2546 | SetErrBreak (("SetupDiCreateDeviceInfo failed (0x%08X)",
|
---|
| 2547 | GetLastError()));
|
---|
| 2548 |
|
---|
| 2549 | /* select the newly created device info to be the currently
|
---|
| 2550 | selected member */
|
---|
| 2551 | ok = SetupDiSetSelectedDevice (hDeviceInfo, &DeviceInfoData);
|
---|
| 2552 | if (!ok)
|
---|
| 2553 | SetErrBreak (("SetupDiSetSelectedDevice failed (0x%08X)",
|
---|
| 2554 | GetLastError()));
|
---|
| 2555 |
|
---|
| 2556 | /* build a list of class drivers */
|
---|
| 2557 | ok = SetupDiBuildDriverInfoList (hDeviceInfo, &DeviceInfoData,
|
---|
| 2558 | SPDIT_CLASSDRIVER);
|
---|
| 2559 | if (!ok)
|
---|
| 2560 | SetErrBreak (("SetupDiBuildDriverInfoList failed (0x%08X)",
|
---|
| 2561 | GetLastError()));
|
---|
[606] | 2562 |
|
---|
[1] | 2563 | destroyList = TRUE;
|
---|
| 2564 |
|
---|
| 2565 | /* enumerate the driver info list */
|
---|
| 2566 | while (TRUE)
|
---|
| 2567 | {
|
---|
| 2568 | BOOL ret;
|
---|
[606] | 2569 |
|
---|
[1] | 2570 | ret = SetupDiEnumDriverInfo (hDeviceInfo, &DeviceInfoData,
|
---|
| 2571 | SPDIT_CLASSDRIVER, index, &DriverInfoData);
|
---|
[606] | 2572 |
|
---|
[1] | 2573 | /* if the function failed and GetLastError() returned
|
---|
| 2574 | * ERROR_NO_MORE_ITEMS, then we have reached the end of the
|
---|
| 2575 | * list. Othewise there was something wrong with this
|
---|
| 2576 | * particular driver. */
|
---|
| 2577 | if (!ret)
|
---|
| 2578 | {
|
---|
| 2579 | if(GetLastError() == ERROR_NO_MORE_ITEMS)
|
---|
| 2580 | break;
|
---|
| 2581 | else
|
---|
| 2582 | {
|
---|
| 2583 | index++;
|
---|
| 2584 | continue;
|
---|
| 2585 | }
|
---|
| 2586 | }
|
---|
[606] | 2587 |
|
---|
[1] | 2588 | pDriverInfoDetail = (PSP_DRVINFO_DETAIL_DATA) detailBuf;
|
---|
| 2589 | pDriverInfoDetail->cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
|
---|
[606] | 2590 |
|
---|
[1] | 2591 | /* if we successfully find the hardware ID and it turns out to
|
---|
| 2592 | * be the one for the loopback driver, then we are done. */
|
---|
| 2593 | if (SetupDiGetDriverInfoDetail (hDeviceInfo,
|
---|
| 2594 | &DeviceInfoData,
|
---|
| 2595 | &DriverInfoData,
|
---|
| 2596 | pDriverInfoDetail,
|
---|
| 2597 | sizeof (detailBuf),
|
---|
| 2598 | NULL))
|
---|
| 2599 | {
|
---|
| 2600 | TCHAR * t;
|
---|
[606] | 2601 |
|
---|
[1] | 2602 | /* pDriverInfoDetail->HardwareID is a MULTISZ string. Go through the
|
---|
| 2603 | * whole list and see if there is a match somewhere. */
|
---|
| 2604 | t = pDriverInfoDetail->HardwareID;
|
---|
| 2605 | while (t && *t && t < (TCHAR *) &detailBuf [sizeof(detailBuf) / sizeof (detailBuf[0])])
|
---|
| 2606 | {
|
---|
| 2607 | if (!_tcsicmp(t, DRIVERHWID))
|
---|
| 2608 | break;
|
---|
[606] | 2609 |
|
---|
[1] | 2610 | t += _tcslen(t) + 1;
|
---|
| 2611 | }
|
---|
[606] | 2612 |
|
---|
[1] | 2613 | if (t && *t && t < (TCHAR *) &detailBuf [sizeof(detailBuf) / sizeof (detailBuf[0])])
|
---|
| 2614 | {
|
---|
| 2615 | found = TRUE;
|
---|
| 2616 | break;
|
---|
| 2617 | }
|
---|
| 2618 | }
|
---|
[606] | 2619 |
|
---|
[1] | 2620 | index ++;
|
---|
| 2621 | }
|
---|
| 2622 |
|
---|
| 2623 | if (!found)
|
---|
| 2624 | SetErrBreak ((tr ("Could not find Host Interface Networking driver! "
|
---|
| 2625 | "Please reinstall")));
|
---|
| 2626 |
|
---|
| 2627 | /* set the loopback driver to be the currently selected */
|
---|
| 2628 | ok = SetupDiSetSelectedDriver (hDeviceInfo, &DeviceInfoData,
|
---|
| 2629 | &DriverInfoData);
|
---|
| 2630 | if (!ok)
|
---|
| 2631 | SetErrBreak (("SetupDiSetSelectedDriver failed (0x%08X)",
|
---|
| 2632 | GetLastError()));
|
---|
[606] | 2633 |
|
---|
[1] | 2634 | /* register the phantom device to prepare for install */
|
---|
| 2635 | ok = SetupDiCallClassInstaller (DIF_REGISTERDEVICE, hDeviceInfo,
|
---|
| 2636 | &DeviceInfoData);
|
---|
| 2637 | if (!ok)
|
---|
| 2638 | SetErrBreak (("SetupDiCallClassInstaller failed (0x%08X)",
|
---|
| 2639 | GetLastError()));
|
---|
[606] | 2640 |
|
---|
[1] | 2641 | /* registered, but remove if errors occur in the following code */
|
---|
| 2642 | registered = TRUE;
|
---|
[606] | 2643 |
|
---|
[1] | 2644 | /* ask the installer if we can install the device */
|
---|
| 2645 | ok = SetupDiCallClassInstaller (DIF_ALLOW_INSTALL, hDeviceInfo,
|
---|
| 2646 | &DeviceInfoData);
|
---|
| 2647 | if (!ok)
|
---|
| 2648 | {
|
---|
| 2649 | if (GetLastError() != ERROR_DI_DO_DEFAULT)
|
---|
| 2650 | SetErrBreak (("SetupDiCallClassInstaller (DIF_ALLOW_INSTALL) failed (0x%08X)",
|
---|
| 2651 | GetLastError()));
|
---|
| 2652 | /* that's fine */
|
---|
| 2653 | }
|
---|
| 2654 |
|
---|
| 2655 | /* install the files first */
|
---|
| 2656 | ok = SetupDiCallClassInstaller (DIF_INSTALLDEVICEFILES, hDeviceInfo,
|
---|
| 2657 | &DeviceInfoData);
|
---|
| 2658 | if (!ok)
|
---|
| 2659 | SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLDEVICEFILES) failed (0x%08X)",
|
---|
| 2660 | GetLastError()));
|
---|
[606] | 2661 |
|
---|
[1] | 2662 | /* get the device install parameters and disable filecopy */
|
---|
| 2663 | DeviceInstallParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS);
|
---|
| 2664 | ok = SetupDiGetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,
|
---|
| 2665 | &DeviceInstallParams);
|
---|
| 2666 | if (ok)
|
---|
| 2667 | {
|
---|
| 2668 | DeviceInstallParams.Flags |= DI_NOFILECOPY;
|
---|
| 2669 | ok = SetupDiSetDeviceInstallParams (hDeviceInfo, &DeviceInfoData,
|
---|
| 2670 | &DeviceInstallParams);
|
---|
| 2671 | if (!ok)
|
---|
| 2672 | SetErrBreak (("SetupDiSetDeviceInstallParams failed (0x%08X)",
|
---|
| 2673 | GetLastError()));
|
---|
| 2674 | }
|
---|
| 2675 |
|
---|
| 2676 | /*
|
---|
| 2677 | * Register any device-specific co-installers for this device,
|
---|
| 2678 | */
|
---|
[606] | 2679 |
|
---|
[1] | 2680 | ok = SetupDiCallClassInstaller (DIF_REGISTER_COINSTALLERS,
|
---|
| 2681 | hDeviceInfo,
|
---|
| 2682 | &DeviceInfoData);
|
---|
| 2683 | if (!ok)
|
---|
| 2684 | SetErrBreak (("SetupDiCallClassInstaller (DIF_REGISTER_COINSTALLERS) failed (0x%08X)",
|
---|
| 2685 | GetLastError()));
|
---|
[606] | 2686 |
|
---|
[1] | 2687 | /*
|
---|
| 2688 | * install any installer-specified interfaces.
|
---|
| 2689 | * and then do the real install
|
---|
| 2690 | */
|
---|
| 2691 | ok = SetupDiCallClassInstaller (DIF_INSTALLINTERFACES,
|
---|
| 2692 | hDeviceInfo,
|
---|
| 2693 | &DeviceInfoData);
|
---|
| 2694 | if (!ok)
|
---|
| 2695 | SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLINTERFACES) failed (0x%08X)",
|
---|
| 2696 | GetLastError()));
|
---|
[606] | 2697 |
|
---|
[1] | 2698 | ok = SetupDiCallClassInstaller (DIF_INSTALLDEVICE,
|
---|
| 2699 | hDeviceInfo,
|
---|
| 2700 | &DeviceInfoData);
|
---|
| 2701 | if (!ok)
|
---|
| 2702 | SetErrBreak (("SetupDiCallClassInstaller (DIF_INSTALLDEVICE) failed (0x%08X)",
|
---|
| 2703 | GetLastError()));
|
---|
| 2704 |
|
---|
| 2705 | /* Figure out NetCfgInstanceId */
|
---|
| 2706 | hkey = SetupDiOpenDevRegKey (hDeviceInfo,
|
---|
| 2707 | &DeviceInfoData,
|
---|
| 2708 | DICS_FLAG_GLOBAL,
|
---|
| 2709 | 0,
|
---|
| 2710 | DIREG_DRV,
|
---|
| 2711 | KEY_READ);
|
---|
| 2712 | if (hkey == INVALID_HANDLE_VALUE)
|
---|
| 2713 | SetErrBreak (("SetupDiOpenDevRegKey failed (0x%08X)",
|
---|
| 2714 | GetLastError()));
|
---|
[606] | 2715 |
|
---|
[1] | 2716 | cbSize = sizeof (pCfgGuidString);
|
---|
| 2717 | DWORD ret;
|
---|
| 2718 | ret = RegQueryValueEx (hkey, _T ("NetCfgInstanceId"), NULL,
|
---|
| 2719 | &dwValueType, (LPBYTE) pCfgGuidString, &cbSize);
|
---|
| 2720 | RegCloseKey (hkey);
|
---|
[606] | 2721 |
|
---|
[1] | 2722 | ret = RenameConnection (pCfgGuidString, Bstr (aName));
|
---|
| 2723 | if (FAILED (ret))
|
---|
| 2724 | SetErrBreak (("Failed to set interface name (ret=0x%08X, "
|
---|
| 2725 | "pCfgGuidString='%ls', cbSize=%d)",
|
---|
| 2726 | ret, pCfgGuidString, cbSize));
|
---|
| 2727 | }
|
---|
| 2728 | while (0);
|
---|
[606] | 2729 |
|
---|
[1] | 2730 | /*
|
---|
| 2731 | * cleanup
|
---|
| 2732 | */
|
---|
| 2733 |
|
---|
| 2734 | if (hDeviceInfo != INVALID_HANDLE_VALUE)
|
---|
| 2735 | {
|
---|
| 2736 | /* an error has occured, but the device is registered, we must remove it */
|
---|
| 2737 | if (ret != 0 && registered)
|
---|
| 2738 | SetupDiCallClassInstaller (DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
|
---|
[606] | 2739 |
|
---|
[1] | 2740 | found = SetupDiDeleteDeviceInfo (hDeviceInfo, &DeviceInfoData);
|
---|
[606] | 2741 |
|
---|
[1] | 2742 | /* destroy the driver info list */
|
---|
| 2743 | if (destroyList)
|
---|
| 2744 | SetupDiDestroyDriverInfoList (hDeviceInfo, &DeviceInfoData,
|
---|
| 2745 | SPDIT_CLASSDRIVER);
|
---|
| 2746 | /* clean up the device info set */
|
---|
| 2747 | SetupDiDestroyDeviceInfoList (hDeviceInfo);
|
---|
| 2748 | }
|
---|
| 2749 |
|
---|
| 2750 | /* return the network connection GUID on success */
|
---|
[13835] | 2751 | if (RT_SUCCESS (vrc))
|
---|
[1] | 2752 | {
|
---|
| 2753 | /* remove the curly bracket at the end */
|
---|
| 2754 | pCfgGuidString [_tcslen (pCfgGuidString) - 1] = '\0';
|
---|
| 2755 | LogFlowFunc (("Network connection GUID string = {%ls}\n", pCfgGuidString + 1));
|
---|
| 2756 |
|
---|
| 2757 | aGUID = Guid (Utf8Str (pCfgGuidString + 1));
|
---|
[13842] | 2758 | LogFlowFunc (("Network connection GUID = {%RTuuid}\n", aGUID.raw()));
|
---|
[1] | 2759 | Assert (!aGUID.isEmpty());
|
---|
| 2760 | }
|
---|
| 2761 |
|
---|
[13837] | 2762 | LogFlowFunc (("vrc=%Rrc\n", vrc));
|
---|
[1] | 2763 | LogFlowFuncLeave();
|
---|
| 2764 | return vrc;
|
---|
| 2765 | }
|
---|
| 2766 |
|
---|
| 2767 | /* static */
|
---|
| 2768 | int Host::removeNetworkInterface (SVCHlpClient *aClient,
|
---|
| 2769 | const Guid &aGUID,
|
---|
| 2770 | Utf8Str &aErrMsg)
|
---|
| 2771 | {
|
---|
| 2772 | LogFlowFuncEnter();
|
---|
[13842] | 2773 | LogFlowFunc (("Network connection GUID = {%RTuuid}\n", aGUID.raw()));
|
---|
[1] | 2774 |
|
---|
[606] | 2775 | AssertReturn (aClient, VERR_INVALID_POINTER);
|
---|
| 2776 | AssertReturn (!aGUID.isEmpty(), VERR_INVALID_PARAMETER);
|
---|
[1] | 2777 |
|
---|
| 2778 | int vrc = VINF_SUCCESS;
|
---|
| 2779 |
|
---|
| 2780 | do
|
---|
| 2781 | {
|
---|
| 2782 | TCHAR lszPnPInstanceId [512] = {0};
|
---|
| 2783 |
|
---|
| 2784 | /* We have to find the device instance ID through a registry search */
|
---|
| 2785 |
|
---|
| 2786 | HKEY hkeyNetwork = 0;
|
---|
| 2787 | HKEY hkeyConnection = 0;
|
---|
| 2788 |
|
---|
| 2789 | do
|
---|
| 2790 | {
|
---|
| 2791 | char strRegLocation [256];
|
---|
| 2792 | sprintf (strRegLocation,
|
---|
| 2793 | "SYSTEM\\CurrentControlSet\\Control\\Network\\"
|
---|
| 2794 | "{4D36E972-E325-11CE-BFC1-08002BE10318}\\{%s}",
|
---|
| 2795 | aGUID.toString().raw());
|
---|
| 2796 | LONG status;
|
---|
| 2797 | status = RegOpenKeyExA (HKEY_LOCAL_MACHINE, strRegLocation, 0,
|
---|
| 2798 | KEY_READ, &hkeyNetwork);
|
---|
| 2799 | if ((status != ERROR_SUCCESS) || !hkeyNetwork)
|
---|
| 2800 | SetErrBreak ((
|
---|
| 2801 | tr ("Host interface network is not found in registry (%s) [1]"),
|
---|
| 2802 | strRegLocation));
|
---|
[606] | 2803 |
|
---|
[1] | 2804 | status = RegOpenKeyExA (hkeyNetwork, "Connection", 0,
|
---|
| 2805 | KEY_READ, &hkeyConnection);
|
---|
| 2806 | if ((status != ERROR_SUCCESS) || !hkeyConnection)
|
---|
| 2807 | SetErrBreak ((
|
---|
| 2808 | tr ("Host interface network is not found in registry (%s) [2]"),
|
---|
| 2809 | strRegLocation));
|
---|
[606] | 2810 |
|
---|
[1] | 2811 | DWORD len = sizeof (lszPnPInstanceId);
|
---|
| 2812 | DWORD dwKeyType;
|
---|
| 2813 | status = RegQueryValueExW (hkeyConnection, L"PnPInstanceID", NULL,
|
---|
| 2814 | &dwKeyType, (LPBYTE) lszPnPInstanceId, &len);
|
---|
| 2815 | if ((status != ERROR_SUCCESS) || (dwKeyType != REG_SZ))
|
---|
| 2816 | SetErrBreak ((
|
---|
| 2817 | tr ("Host interface network is not found in registry (%s) [3]"),
|
---|
| 2818 | strRegLocation));
|
---|
| 2819 | }
|
---|
| 2820 | while (0);
|
---|
| 2821 |
|
---|
| 2822 | if (hkeyConnection)
|
---|
| 2823 | RegCloseKey (hkeyConnection);
|
---|
| 2824 | if (hkeyNetwork)
|
---|
| 2825 | RegCloseKey (hkeyNetwork);
|
---|
| 2826 |
|
---|
[13835] | 2827 | if (RT_FAILURE (vrc))
|
---|
[1] | 2828 | break;
|
---|
| 2829 |
|
---|
| 2830 | /*
|
---|
| 2831 | * Now we are going to enumerate all network devices and
|
---|
| 2832 | * wait until we encounter the right device instance ID
|
---|
| 2833 | */
|
---|
| 2834 |
|
---|
| 2835 | HDEVINFO hDeviceInfo = INVALID_HANDLE_VALUE;
|
---|
[606] | 2836 |
|
---|
[1] | 2837 | do
|
---|
| 2838 | {
|
---|
| 2839 | BOOL ok;
|
---|
| 2840 | DWORD ret = 0;
|
---|
| 2841 | GUID netGuid;
|
---|
| 2842 | SP_DEVINFO_DATA DeviceInfoData;
|
---|
| 2843 | DWORD index = 0;
|
---|
| 2844 | BOOL found = FALSE;
|
---|
| 2845 | DWORD size = 0;
|
---|
[606] | 2846 |
|
---|
[1] | 2847 | /* initialize the structure size */
|
---|
| 2848 | DeviceInfoData.cbSize = sizeof (SP_DEVINFO_DATA);
|
---|
[606] | 2849 |
|
---|
[1] | 2850 | /* copy the net class GUID */
|
---|
| 2851 | memcpy (&netGuid, &GUID_DEVCLASS_NET, sizeof (GUID_DEVCLASS_NET));
|
---|
[606] | 2852 |
|
---|
[1] | 2853 | /* return a device info set contains all installed devices of the Net class */
|
---|
| 2854 | hDeviceInfo = SetupDiGetClassDevs (&netGuid, NULL, NULL, DIGCF_PRESENT);
|
---|
[606] | 2855 |
|
---|
[1] | 2856 | if (hDeviceInfo == INVALID_HANDLE_VALUE)
|
---|
| 2857 | SetErrBreak (("SetupDiGetClassDevs failed (0x%08X)", GetLastError()));
|
---|
[606] | 2858 |
|
---|
[1] | 2859 | /* enumerate the driver info list */
|
---|
| 2860 | while (TRUE)
|
---|
| 2861 | {
|
---|
| 2862 | TCHAR *deviceHwid;
|
---|
[606] | 2863 |
|
---|
[1] | 2864 | ok = SetupDiEnumDeviceInfo (hDeviceInfo, index, &DeviceInfoData);
|
---|
[606] | 2865 |
|
---|
[1] | 2866 | if (!ok)
|
---|
| 2867 | {
|
---|
| 2868 | if (GetLastError() == ERROR_NO_MORE_ITEMS)
|
---|
| 2869 | break;
|
---|
| 2870 | else
|
---|
| 2871 | {
|
---|
| 2872 | index++;
|
---|
| 2873 | continue;
|
---|
| 2874 | }
|
---|
| 2875 | }
|
---|
[606] | 2876 |
|
---|
[1] | 2877 | /* try to get the hardware ID registry property */
|
---|
| 2878 | ok = SetupDiGetDeviceRegistryProperty (hDeviceInfo,
|
---|
| 2879 | &DeviceInfoData,
|
---|
| 2880 | SPDRP_HARDWAREID,
|
---|
| 2881 | NULL,
|
---|
| 2882 | NULL,
|
---|
| 2883 | 0,
|
---|
| 2884 | &size);
|
---|
| 2885 | if (!ok)
|
---|
| 2886 | {
|
---|
| 2887 | if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
---|
| 2888 | {
|
---|
| 2889 | index++;
|
---|
| 2890 | continue;
|
---|
| 2891 | }
|
---|
[606] | 2892 |
|
---|
[1] | 2893 | deviceHwid = (TCHAR *) malloc (size);
|
---|
| 2894 | ok = SetupDiGetDeviceRegistryProperty (hDeviceInfo,
|
---|
| 2895 | &DeviceInfoData,
|
---|
| 2896 | SPDRP_HARDWAREID,
|
---|
| 2897 | NULL,
|
---|
| 2898 | (PBYTE)deviceHwid,
|
---|
| 2899 | size,
|
---|
| 2900 | NULL);
|
---|
| 2901 | if (!ok)
|
---|
| 2902 | {
|
---|
| 2903 | free (deviceHwid);
|
---|
| 2904 | deviceHwid = NULL;
|
---|
| 2905 | index++;
|
---|
| 2906 | continue;
|
---|
| 2907 | }
|
---|
| 2908 | }
|
---|
| 2909 | else
|
---|
| 2910 | {
|
---|
| 2911 | /* something is wrong. This shouldn't have worked with a NULL buffer */
|
---|
| 2912 | index++;
|
---|
| 2913 | continue;
|
---|
| 2914 | }
|
---|
[606] | 2915 |
|
---|
[1] | 2916 | for (TCHAR *t = deviceHwid;
|
---|
| 2917 | t && *t && t < &deviceHwid[size / sizeof(TCHAR)];
|
---|
| 2918 | t += _tcslen (t) + 1)
|
---|
| 2919 | {
|
---|
| 2920 | if (!_tcsicmp (DRIVERHWID, t))
|
---|
| 2921 | {
|
---|
| 2922 | /* get the device instance ID */
|
---|
| 2923 | TCHAR devID [MAX_DEVICE_ID_LEN];
|
---|
| 2924 | if (CM_Get_Device_ID(DeviceInfoData.DevInst,
|
---|
| 2925 | devID, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS)
|
---|
| 2926 | {
|
---|
| 2927 | /* compare to what we determined before */
|
---|
| 2928 | if (wcscmp(devID, lszPnPInstanceId) == 0)
|
---|
| 2929 | {
|
---|
| 2930 | found = TRUE;
|
---|
| 2931 | break;
|
---|
| 2932 | }
|
---|
| 2933 | }
|
---|
| 2934 | }
|
---|
| 2935 | }
|
---|
[606] | 2936 |
|
---|
[1] | 2937 | if (deviceHwid)
|
---|
| 2938 | {
|
---|
| 2939 | free (deviceHwid);
|
---|
| 2940 | deviceHwid = NULL;
|
---|
| 2941 | }
|
---|
[606] | 2942 |
|
---|
[1] | 2943 | if (found)
|
---|
| 2944 | break;
|
---|
[606] | 2945 |
|
---|
[1] | 2946 | index++;
|
---|
| 2947 | }
|
---|
[606] | 2948 |
|
---|
[1] | 2949 | if (found == FALSE)
|
---|
| 2950 | SetErrBreak ((tr ("Host Interface Network driver not found (0x%08X)"),
|
---|
| 2951 | GetLastError()));
|
---|
[606] | 2952 |
|
---|
[1] | 2953 | ok = SetupDiSetSelectedDevice (hDeviceInfo, &DeviceInfoData);
|
---|
| 2954 | if (!ok)
|
---|
| 2955 | SetErrBreak (("SetupDiSetSelectedDevice failed (0x%08X)",
|
---|
| 2956 | GetLastError()));
|
---|
[606] | 2957 |
|
---|
[1] | 2958 | ok = SetupDiCallClassInstaller (DIF_REMOVE, hDeviceInfo, &DeviceInfoData);
|
---|
| 2959 | if (!ok)
|
---|
| 2960 | SetErrBreak (("SetupDiCallClassInstaller (DIF_REMOVE) failed (0x%08X)",
|
---|
| 2961 | GetLastError()));
|
---|
| 2962 | }
|
---|
| 2963 | while (0);
|
---|
| 2964 |
|
---|
| 2965 | /* clean up the device info set */
|
---|
| 2966 | if (hDeviceInfo != INVALID_HANDLE_VALUE)
|
---|
| 2967 | SetupDiDestroyDeviceInfoList (hDeviceInfo);
|
---|
| 2968 |
|
---|
[13835] | 2969 | if (RT_FAILURE (vrc))
|
---|
[1] | 2970 | break;
|
---|
| 2971 | }
|
---|
| 2972 | while (0);
|
---|
| 2973 |
|
---|
[13837] | 2974 | LogFlowFunc (("vrc=%Rrc\n", vrc));
|
---|
[1] | 2975 | LogFlowFuncLeave();
|
---|
| 2976 | return vrc;
|
---|
| 2977 | }
|
---|
| 2978 |
|
---|
| 2979 | #undef SetErrBreak
|
---|
| 2980 |
|
---|
| 2981 | /* static */
|
---|
| 2982 | HRESULT Host::networkInterfaceHelperClient (SVCHlpClient *aClient,
|
---|
| 2983 | Progress *aProgress,
|
---|
| 2984 | void *aUser, int *aVrc)
|
---|
| 2985 | {
|
---|
| 2986 | LogFlowFuncEnter();
|
---|
| 2987 | LogFlowFunc (("aClient={%p}, aProgress={%p}, aUser={%p}\n",
|
---|
| 2988 | aClient, aProgress, aUser));
|
---|
| 2989 |
|
---|
| 2990 | AssertReturn ((aClient == NULL && aProgress == NULL && aVrc == NULL) ||
|
---|
| 2991 | (aClient != NULL && aProgress != NULL && aVrc != NULL),
|
---|
[606] | 2992 | E_POINTER);
|
---|
[1] | 2993 | AssertReturn (aUser, E_POINTER);
|
---|
| 2994 |
|
---|
| 2995 | std::auto_ptr <NetworkInterfaceHelperClientData>
|
---|
| 2996 | d (static_cast <NetworkInterfaceHelperClientData *> (aUser));
|
---|
[606] | 2997 |
|
---|
[1] | 2998 | if (aClient == NULL)
|
---|
| 2999 | {
|
---|
| 3000 | /* "cleanup only" mode, just return (it will free aUser) */
|
---|
| 3001 | return S_OK;
|
---|
| 3002 | }
|
---|
| 3003 |
|
---|
| 3004 | HRESULT rc = S_OK;
|
---|
| 3005 | int vrc = VINF_SUCCESS;
|
---|
| 3006 |
|
---|
| 3007 | switch (d->msgCode)
|
---|
| 3008 | {
|
---|
| 3009 | case SVCHlpMsg::CreateHostNetworkInterface:
|
---|
| 3010 | {
|
---|
| 3011 | LogFlowFunc (("CreateHostNetworkInterface:\n"));
|
---|
| 3012 | LogFlowFunc (("Network connection name = '%ls'\n", d->name.raw()));
|
---|
| 3013 |
|
---|
| 3014 | /* write message and parameters */
|
---|
| 3015 | vrc = aClient->write (d->msgCode);
|
---|
[13835] | 3016 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3017 | vrc = aClient->write (Utf8Str (d->name));
|
---|
[13835] | 3018 | if (RT_FAILURE (vrc)) break;
|
---|
[606] | 3019 |
|
---|
[1] | 3020 | /* wait for a reply */
|
---|
| 3021 | bool endLoop = false;
|
---|
| 3022 | while (!endLoop)
|
---|
| 3023 | {
|
---|
| 3024 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
| 3025 |
|
---|
| 3026 | vrc = aClient->read (reply);
|
---|
[13835] | 3027 | if (RT_FAILURE (vrc)) break;
|
---|
[606] | 3028 |
|
---|
[1] | 3029 | switch (reply)
|
---|
| 3030 | {
|
---|
| 3031 | case SVCHlpMsg::CreateHostNetworkInterface_OK:
|
---|
| 3032 | {
|
---|
| 3033 | /* read the GUID */
|
---|
| 3034 | Guid guid;
|
---|
| 3035 | vrc = aClient->read (guid);
|
---|
[13835] | 3036 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3037 |
|
---|
[13842] | 3038 | LogFlowFunc (("Network connection GUID = {%RTuuid}\n", guid.raw()));
|
---|
[1] | 3039 |
|
---|
| 3040 | /* initialize the object returned to the caller by
|
---|
| 3041 | * CreateHostNetworkInterface() */
|
---|
| 3042 | rc = d->iface->init (d->name, guid);
|
---|
| 3043 | endLoop = true;
|
---|
| 3044 | break;
|
---|
| 3045 | }
|
---|
| 3046 | case SVCHlpMsg::Error:
|
---|
| 3047 | {
|
---|
| 3048 | /* read the error message */
|
---|
| 3049 | Utf8Str errMsg;
|
---|
| 3050 | vrc = aClient->read (errMsg);
|
---|
[13835] | 3051 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3052 |
|
---|
| 3053 | rc = setError (E_FAIL, errMsg);
|
---|
| 3054 | endLoop = true;
|
---|
| 3055 | break;
|
---|
| 3056 | }
|
---|
| 3057 | default:
|
---|
| 3058 | {
|
---|
| 3059 | endLoop = true;
|
---|
| 3060 | ComAssertMsgFailedBreak ((
|
---|
| 3061 | "Invalid message code %d (%08lX)\n",
|
---|
| 3062 | reply, reply),
|
---|
| 3063 | rc = E_FAIL);
|
---|
| 3064 | }
|
---|
| 3065 | }
|
---|
| 3066 | }
|
---|
[606] | 3067 |
|
---|
[1] | 3068 | break;
|
---|
| 3069 | }
|
---|
| 3070 | case SVCHlpMsg::RemoveHostNetworkInterface:
|
---|
| 3071 | {
|
---|
| 3072 | LogFlowFunc (("RemoveHostNetworkInterface:\n"));
|
---|
[13842] | 3073 | LogFlowFunc (("Network connection GUID = {%RTuuid}\n", d->guid.raw()));
|
---|
[1] | 3074 |
|
---|
| 3075 | /* write message and parameters */
|
---|
| 3076 | vrc = aClient->write (d->msgCode);
|
---|
[13835] | 3077 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3078 | vrc = aClient->write (d->guid);
|
---|
[13835] | 3079 | if (RT_FAILURE (vrc)) break;
|
---|
[606] | 3080 |
|
---|
[1] | 3081 | /* wait for a reply */
|
---|
| 3082 | bool endLoop = false;
|
---|
| 3083 | while (!endLoop)
|
---|
| 3084 | {
|
---|
| 3085 | SVCHlpMsg::Code reply = SVCHlpMsg::Null;
|
---|
| 3086 |
|
---|
| 3087 | vrc = aClient->read (reply);
|
---|
[13835] | 3088 | if (RT_FAILURE (vrc)) break;
|
---|
[606] | 3089 |
|
---|
[1] | 3090 | switch (reply)
|
---|
| 3091 | {
|
---|
| 3092 | case SVCHlpMsg::OK:
|
---|
| 3093 | {
|
---|
| 3094 | /* no parameters */
|
---|
| 3095 | rc = S_OK;
|
---|
| 3096 | endLoop = true;
|
---|
| 3097 | break;
|
---|
| 3098 | }
|
---|
| 3099 | case SVCHlpMsg::Error:
|
---|
| 3100 | {
|
---|
| 3101 | /* read the error message */
|
---|
| 3102 | Utf8Str errMsg;
|
---|
| 3103 | vrc = aClient->read (errMsg);
|
---|
[13835] | 3104 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3105 |
|
---|
| 3106 | rc = setError (E_FAIL, errMsg);
|
---|
| 3107 | endLoop = true;
|
---|
| 3108 | break;
|
---|
| 3109 | }
|
---|
| 3110 | default:
|
---|
| 3111 | {
|
---|
| 3112 | endLoop = true;
|
---|
| 3113 | ComAssertMsgFailedBreak ((
|
---|
| 3114 | "Invalid message code %d (%08lX)\n",
|
---|
| 3115 | reply, reply),
|
---|
| 3116 | rc = E_FAIL);
|
---|
| 3117 | }
|
---|
| 3118 | }
|
---|
| 3119 | }
|
---|
[606] | 3120 |
|
---|
[1] | 3121 | break;
|
---|
| 3122 | }
|
---|
| 3123 | default:
|
---|
| 3124 | ComAssertMsgFailedBreak ((
|
---|
| 3125 | "Invalid message code %d (%08lX)\n",
|
---|
| 3126 | d->msgCode, d->msgCode),
|
---|
| 3127 | rc = E_FAIL);
|
---|
| 3128 | }
|
---|
| 3129 |
|
---|
| 3130 | if (aVrc)
|
---|
| 3131 | *aVrc = vrc;
|
---|
| 3132 |
|
---|
[13837] | 3133 | LogFlowFunc (("rc=0x%08X, vrc=%Rrc\n", rc, vrc));
|
---|
[1] | 3134 | LogFlowFuncLeave();
|
---|
| 3135 | return rc;
|
---|
| 3136 | }
|
---|
| 3137 |
|
---|
| 3138 | /* static */
|
---|
| 3139 | int Host::networkInterfaceHelperServer (SVCHlpClient *aClient,
|
---|
| 3140 | SVCHlpMsg::Code aMsgCode)
|
---|
| 3141 | {
|
---|
| 3142 | LogFlowFuncEnter();
|
---|
| 3143 | LogFlowFunc (("aClient={%p}, aMsgCode=%d\n", aClient, aMsgCode));
|
---|
| 3144 |
|
---|
| 3145 | AssertReturn (aClient, VERR_INVALID_POINTER);
|
---|
| 3146 |
|
---|
| 3147 | int vrc = VINF_SUCCESS;
|
---|
| 3148 |
|
---|
| 3149 | switch (aMsgCode)
|
---|
| 3150 | {
|
---|
| 3151 | case SVCHlpMsg::CreateHostNetworkInterface:
|
---|
| 3152 | {
|
---|
| 3153 | LogFlowFunc (("CreateHostNetworkInterface:\n"));
|
---|
| 3154 |
|
---|
| 3155 | Utf8Str name;
|
---|
| 3156 | vrc = aClient->read (name);
|
---|
[13835] | 3157 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3158 |
|
---|
| 3159 | Guid guid;
|
---|
| 3160 | Utf8Str errMsg;
|
---|
[606] | 3161 | vrc = createNetworkInterface (aClient, name, guid, errMsg);
|
---|
[1] | 3162 |
|
---|
[13835] | 3163 | if (RT_SUCCESS (vrc))
|
---|
[1] | 3164 | {
|
---|
| 3165 | /* write success followed by GUID */
|
---|
| 3166 | vrc = aClient->write (SVCHlpMsg::CreateHostNetworkInterface_OK);
|
---|
[13835] | 3167 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3168 | vrc = aClient->write (guid);
|
---|
[13835] | 3169 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3170 | }
|
---|
| 3171 | else
|
---|
| 3172 | {
|
---|
| 3173 | /* write failure followed by error message */
|
---|
| 3174 | if (errMsg.isEmpty())
|
---|
[13837] | 3175 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
[1] | 3176 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
[13835] | 3177 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3178 | vrc = aClient->write (errMsg);
|
---|
[13835] | 3179 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3180 | }
|
---|
| 3181 |
|
---|
| 3182 | break;
|
---|
| 3183 | }
|
---|
| 3184 | case SVCHlpMsg::RemoveHostNetworkInterface:
|
---|
| 3185 | {
|
---|
| 3186 | LogFlowFunc (("RemoveHostNetworkInterface:\n"));
|
---|
| 3187 |
|
---|
| 3188 | Guid guid;
|
---|
| 3189 | vrc = aClient->read (guid);
|
---|
[13835] | 3190 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3191 |
|
---|
| 3192 | Utf8Str errMsg;
|
---|
[606] | 3193 | vrc = removeNetworkInterface (aClient, guid, errMsg);
|
---|
[1] | 3194 |
|
---|
[13835] | 3195 | if (RT_SUCCESS (vrc))
|
---|
[1] | 3196 | {
|
---|
| 3197 | /* write parameter-less success */
|
---|
| 3198 | vrc = aClient->write (SVCHlpMsg::OK);
|
---|
[13835] | 3199 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3200 | }
|
---|
| 3201 | else
|
---|
| 3202 | {
|
---|
| 3203 | /* write failure followed by error message */
|
---|
| 3204 | if (errMsg.isEmpty())
|
---|
[13837] | 3205 | errMsg = Utf8StrFmt ("Unspecified error (%Rrc)", vrc);
|
---|
[1] | 3206 | vrc = aClient->write (SVCHlpMsg::Error);
|
---|
[13835] | 3207 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3208 | vrc = aClient->write (errMsg);
|
---|
[13835] | 3209 | if (RT_FAILURE (vrc)) break;
|
---|
[1] | 3210 | }
|
---|
| 3211 |
|
---|
| 3212 | break;
|
---|
| 3213 | }
|
---|
| 3214 | default:
|
---|
[8566] | 3215 | AssertMsgFailedBreakStmt (
|
---|
| 3216 | ("Invalid message code %d (%08lX)\n", aMsgCode, aMsgCode),
|
---|
[1] | 3217 | VERR_GENERAL_FAILURE);
|
---|
| 3218 | }
|
---|
| 3219 |
|
---|
[13837] | 3220 | LogFlowFunc (("vrc=%Rrc\n", vrc));
|
---|
[1] | 3221 | LogFlowFuncLeave();
|
---|
| 3222 | return vrc;
|
---|
| 3223 | }
|
---|
| 3224 |
|
---|
[3668] | 3225 | #endif /* RT_OS_WINDOWS */
|
---|
[1] | 3226 |
|
---|
[9937] | 3227 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
[10595] | 3228 | void Host::registerMetrics (PerformanceCollector *aCollector)
|
---|
[9937] | 3229 | {
|
---|
[12400] | 3230 | pm::CollectorHAL *hal = aCollector->getHAL();
|
---|
[10595] | 3231 | /* Create sub metrics */
|
---|
[11583] | 3232 | pm::SubMetric *cpuLoadUser = new pm::SubMetric ("CPU/Load/User",
|
---|
| 3233 | "Percentage of processor time spent in user mode.");
|
---|
| 3234 | pm::SubMetric *cpuLoadKernel = new pm::SubMetric ("CPU/Load/Kernel",
|
---|
| 3235 | "Percentage of processor time spent in kernel mode.");
|
---|
| 3236 | pm::SubMetric *cpuLoadIdle = new pm::SubMetric ("CPU/Load/Idle",
|
---|
| 3237 | "Percentage of processor time spent idling.");
|
---|
| 3238 | pm::SubMetric *cpuMhzSM = new pm::SubMetric ("CPU/MHz",
|
---|
| 3239 | "Average of current frequency of all processors.");
|
---|
| 3240 | pm::SubMetric *ramUsageTotal = new pm::SubMetric ("RAM/Usage/Total",
|
---|
| 3241 | "Total physical memory installed.");
|
---|
| 3242 | pm::SubMetric *ramUsageUsed = new pm::SubMetric ("RAM/Usage/Used",
|
---|
| 3243 | "Physical memory currently occupied.");
|
---|
| 3244 | pm::SubMetric *ramUsageFree = new pm::SubMetric ("RAM/Usage/Free",
|
---|
| 3245 | "Physical memory currently available to applications.");
|
---|
[10595] | 3246 | /* Create and register base metrics */
|
---|
[10544] | 3247 | IUnknown *objptr;
|
---|
[10595] | 3248 | ComObjPtr <Host> tmp = this;
|
---|
| 3249 | tmp.queryInterfaceTo (&objptr);
|
---|
[12400] | 3250 | pm::BaseMetric *cpuLoad = new pm::HostCpuLoadRaw (hal, objptr, cpuLoadUser, cpuLoadKernel,
|
---|
[10595] | 3251 | cpuLoadIdle);
|
---|
| 3252 | aCollector->registerBaseMetric (cpuLoad);
|
---|
[12400] | 3253 | pm::BaseMetric *cpuMhz = new pm::HostCpuMhz (hal, objptr, cpuMhzSM);
|
---|
[11467] | 3254 | aCollector->registerBaseMetric (cpuMhz);
|
---|
[12400] | 3255 | pm::BaseMetric *ramUsage = new pm::HostRamUsage (hal, objptr, ramUsageTotal, ramUsageUsed,
|
---|
[10753] | 3256 | ramUsageFree);
|
---|
[10713] | 3257 | aCollector->registerBaseMetric (ramUsage);
|
---|
| 3258 |
|
---|
[10595] | 3259 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser, 0));
|
---|
| 3260 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser,
|
---|
| 3261 | new pm::AggregateAvg()));
|
---|
| 3262 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser,
|
---|
| 3263 | new pm::AggregateMin()));
|
---|
| 3264 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadUser,
|
---|
| 3265 | new pm::AggregateMax()));
|
---|
[10713] | 3266 |
|
---|
[10595] | 3267 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel, 0));
|
---|
| 3268 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel,
|
---|
| 3269 | new pm::AggregateAvg()));
|
---|
| 3270 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel,
|
---|
| 3271 | new pm::AggregateMin()));
|
---|
| 3272 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadKernel,
|
---|
| 3273 | new pm::AggregateMax()));
|
---|
[10713] | 3274 |
|
---|
[10595] | 3275 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle, 0));
|
---|
| 3276 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle,
|
---|
| 3277 | new pm::AggregateAvg()));
|
---|
| 3278 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle,
|
---|
| 3279 | new pm::AggregateMin()));
|
---|
| 3280 | aCollector->registerMetric (new pm::Metric(cpuLoad, cpuLoadIdle,
|
---|
| 3281 | new pm::AggregateMax()));
|
---|
[10713] | 3282 |
|
---|
[11467] | 3283 | aCollector->registerMetric (new pm::Metric(cpuMhz, cpuMhzSM, 0));
|
---|
| 3284 | aCollector->registerMetric (new pm::Metric(cpuMhz, cpuMhzSM,
|
---|
| 3285 | new pm::AggregateAvg()));
|
---|
| 3286 | aCollector->registerMetric (new pm::Metric(cpuMhz, cpuMhzSM,
|
---|
| 3287 | new pm::AggregateMin()));
|
---|
| 3288 | aCollector->registerMetric (new pm::Metric(cpuMhz, cpuMhzSM,
|
---|
| 3289 | new pm::AggregateMax()));
|
---|
| 3290 |
|
---|
[10713] | 3291 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal, 0));
|
---|
| 3292 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal,
|
---|
| 3293 | new pm::AggregateAvg()));
|
---|
| 3294 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal,
|
---|
| 3295 | new pm::AggregateMin()));
|
---|
| 3296 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageTotal,
|
---|
| 3297 | new pm::AggregateMax()));
|
---|
| 3298 |
|
---|
| 3299 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed, 0));
|
---|
| 3300 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed,
|
---|
| 3301 | new pm::AggregateAvg()));
|
---|
| 3302 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed,
|
---|
| 3303 | new pm::AggregateMin()));
|
---|
| 3304 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageUsed,
|
---|
| 3305 | new pm::AggregateMax()));
|
---|
| 3306 |
|
---|
| 3307 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree, 0));
|
---|
| 3308 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree,
|
---|
| 3309 | new pm::AggregateAvg()));
|
---|
| 3310 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree,
|
---|
| 3311 | new pm::AggregateMin()));
|
---|
| 3312 | aCollector->registerMetric (new pm::Metric(ramUsage, ramUsageFree,
|
---|
| 3313 | new pm::AggregateMax()));
|
---|
[10544] | 3314 | };
|
---|
[9937] | 3315 |
|
---|
[10595] | 3316 | void Host::unregisterMetrics (PerformanceCollector *aCollector)
|
---|
[9937] | 3317 | {
|
---|
[10595] | 3318 | aCollector->unregisterMetricsFor (this);
|
---|
| 3319 | aCollector->unregisterBaseMetricsFor (this);
|
---|
[10544] | 3320 | };
|
---|
[9937] | 3321 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
[16198] | 3322 |
|
---|
[16289] | 3323 | STDMETHODIMP Host::FindHostNetworkInterfaceByName(IN_BSTR name, IHostNetworkInterface **networkInterface)
|
---|
| 3324 | {
|
---|
[16198] | 3325 | #ifndef VBOX_WITH_HOSTNETIF_API
|
---|
| 3326 | return E_NOTIMPL;
|
---|
| 3327 | #else
|
---|
[16289] | 3328 | if (!name)
|
---|
| 3329 | return E_INVALIDARG;
|
---|
| 3330 | if (!networkInterface)
|
---|
| 3331 | return E_POINTER;
|
---|
| 3332 |
|
---|
| 3333 | *networkInterface = NULL;
|
---|
[16198] | 3334 | ComObjPtr <HostNetworkInterface> found;
|
---|
| 3335 | std::list <ComObjPtr <HostNetworkInterface> > list;
|
---|
| 3336 | int rc = NetIfList(list);
|
---|
| 3337 | if (RT_FAILURE(rc))
|
---|
| 3338 | {
|
---|
| 3339 | Log(("Failed to get host network interface list with rc=%Vrc\n", rc));
|
---|
| 3340 | return E_FAIL;
|
---|
| 3341 | }
|
---|
| 3342 | std::list <ComObjPtr <HostNetworkInterface> >::iterator it;
|
---|
| 3343 | for (it = list.begin(); it != list.end(); ++it)
|
---|
| 3344 | {
|
---|
| 3345 | Bstr n;
|
---|
| 3346 | (*it)->COMGETTER(Name) (n.asOutParam());
|
---|
| 3347 | if (n == name)
|
---|
| 3348 | found = *it;
|
---|
| 3349 | }
|
---|
| 3350 |
|
---|
[16289] | 3351 | if (!found)
|
---|
| 3352 | return setError (E_INVALIDARG, HostNetworkInterface::tr (
|
---|
| 3353 | "The host network interface with the given name could not be found"));
|
---|
| 3354 |
|
---|
| 3355 | return found.queryInterfaceTo (networkInterface);
|
---|
[16198] | 3356 | #endif
|
---|
[16289] | 3357 | }
|
---|
| 3358 |
|
---|
| 3359 | STDMETHODIMP Host::FindHostNetworkInterfaceById(IN_GUID id, IHostNetworkInterface **networkInterface)
|
---|
| 3360 | {
|
---|
[16198] | 3361 | #ifndef VBOX_WITH_HOSTNETIF_API
|
---|
| 3362 | return E_NOTIMPL;
|
---|
| 3363 | #else
|
---|
[16289] | 3364 | if (Guid(id).isEmpty())
|
---|
| 3365 | return E_INVALIDARG;
|
---|
| 3366 | if (!networkInterface)
|
---|
| 3367 | return E_POINTER;
|
---|
| 3368 |
|
---|
| 3369 | *networkInterface = NULL;
|
---|
[16198] | 3370 | ComObjPtr <HostNetworkInterface> found;
|
---|
| 3371 | std::list <ComObjPtr <HostNetworkInterface> > list;
|
---|
| 3372 | int rc = NetIfList(list);
|
---|
| 3373 | if (RT_FAILURE(rc))
|
---|
| 3374 | {
|
---|
| 3375 | Log(("Failed to get host network interface list with rc=%Vrc\n", rc));
|
---|
| 3376 | return E_FAIL;
|
---|
| 3377 | }
|
---|
| 3378 | std::list <ComObjPtr <HostNetworkInterface> >::iterator it;
|
---|
| 3379 | for (it = list.begin(); it != list.end(); ++it)
|
---|
[16289] | 3380 | {
|
---|
| 3381 | Guid g;
|
---|
| 3382 | (*it)->COMGETTER(Id) (g.asOutParam());
|
---|
| 3383 | if (g == Guid(id))
|
---|
| 3384 | found = *it;
|
---|
| 3385 | }
|
---|
| 3386 |
|
---|
| 3387 | if (!found)
|
---|
| 3388 | return setError (E_INVALIDARG, HostNetworkInterface::tr (
|
---|
| 3389 | "The host network interface with the given GUID could not be found"));
|
---|
| 3390 |
|
---|
| 3391 | return found.queryInterfaceTo (networkInterface);
|
---|
[16198] | 3392 | #endif
|
---|
[16289] | 3393 | }
|
---|
| 3394 |
|
---|
[14772] | 3395 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|