HostImpl.cpp revision b3a78fd7f3993672fca6c18b994557f473ec0ab9
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * VirtualBox COM class implementation: Host
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * Copyright (C) 2006-2009 Sun Microsystems, Inc.
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * available from http://www.virtualbox.org. This file is free software;
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * you can redistribute it and/or modify it under the terms of the GNU
f48d0356a138aa21ced9ef2fae1c1d29beeee52bvboxsync * General Public License (GPL) as published by the Free Software
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f48d0356a138aa21ced9ef2fae1c1d29beeee52bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * additional information or have any questions.
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync// # include <sys/types.h>
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync// # include <sys/stat.h>
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync// # include <unistd.h>
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync// # include <fcntl.h>
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync// # include <mntent.h>
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync/* bird: This is a hack to work around conflicts between these linux kernel headers
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * and the GLIBC tcpip headers. They have different declarations of the 4
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync * standard byte order functions. */
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync// # define _LINUX_BYTEORDER_GENERIC_H
d6432128cdbae4c7b328246b2c60d693972d6656vboxsync// # include <linux/cdrom.h>
#ifdef RT_OS_SOLARIS
# include <fcntl.h>
# include <unistd.h>
# include <stropts.h>
# include <errno.h>
# include <limits.h>
# include <stdio.h>
# ifdef VBOX_SOLARIS_NSL_RESOLVED
# include <libdevinfo.h>
# ifdef VBOX_USE_LIBHAL
# include "vbox-libhal.h"
# include "solaris/DynLoadLibSolaris.h"
#ifdef RT_OS_WINDOWS
# define _WIN32_DCOM
# include <windows.h>
# include <shellapi.h>
# define INITGUID
# include <guiddef.h>
# include <devguid.h>
# include <objbase.h>
# include <setupapi.h>
# include <shlobj.h>
# include <cfgmgr32.h>
#include "HostImpl.h"
#include "HostDVDDriveImpl.h"
#include "HostFloppyDriveImpl.h"
#include "HostNetworkInterfaceImpl.h"
#ifdef VBOX_WITH_USB
# include "HostUSBDeviceImpl.h"
# include "USBDeviceFilterImpl.h"
# include "USBProxyService.h"
#include "VirtualBoxImpl.h"
#include "MachineImpl.h"
#include "Logging.h"
#ifdef RT_OS_DARWIN
#ifdef RT_OS_SOLARIS
#ifdef VBOX_WITH_HOSTNETIF_API
#include "netif.h"
#include <stdio.h>
#include <algorithm>
return S_OK;
if (isReady())
uninit();
// public initializer/uninitializer for internal purposes only
#ifdef VBOX_WITH_USB
# if defined (RT_OS_DARWIN)
#ifdef VBOX_WITH_RESOURCE_USAGE_API
#if defined (RT_OS_WINDOWS)
fVTxAMDVSupported = false;
fLongModeSupported = false;
fPAESupported = false;
if (ASMHasCpuId())
fVTxAMDVSupported = true;
fVTxAMDVSupported = true;
setReady(true);
return S_OK;
#ifdef VBOX_WITH_RESOURCE_USAGE_API
#ifdef VBOX_WITH_USB
delete mUSBProxyService;
delete mHostPowerService;
#ifdef VBOX_WITH_USB
CHECK_READY();
#if defined(RT_OS_WINDOWS)
driveName[0] = *p;
delete[] hostDrives;
# ifdef VBOX_USE_LIBHAL
char *cdromDrive;
while (cdromDrive)
while (cur)
return rc;
CHECK_READY();
#ifdef RT_OS_WINDOWS
driveName[0] = *p;
delete[] hostDrives;
return rc;
#ifdef RT_OS_WINDOWS
bool ret = false;
status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, KEY_READ, &hNetcard);
status = RegQueryValueExA(hNetCardGUID, "NetCfgInstanceId", NULL, &dwKeyType, (LPBYTE)szNetCfgInstanceId, &len);
szNetProductName[0] = 0;
status = RegQueryValueExA(hNetCardGUID, "ProductName", NULL, &dwKeyType, (LPBYTE)szNetProductName, &len);
szNetProviderName[0] = 0;
status = RegQueryValueExA(hNetCardGUID, "ProviderName", NULL, &dwKeyType, (LPBYTE)szNetProviderName, &len);
ret = true;
return ret;
#ifdef RT_OS_SOLARIS
static void vboxSolarisAddHostIface(char *pszIface, int Instance, PCRTMAC pMac, void *pvHostNetworkInterfaceList)
std::list<ComObjPtr <HostNetworkInterface> > *pList = (std::list<ComObjPtr <HostNetworkInterface> > *)pvHostNetworkInterfaceList;
if (pMac)
static boolean_t vboxSolarisAddLinkHostIface(const char *pszIface, void *pvHostNetworkInterfaceList)
if (pszColon)
int cbInstance = 0;
cbInstance++;
pszEnd--;
return _B_FALSE;
static bool vboxSolarisSortNICList(const ComObjPtr <HostNetworkInterface> Iface1, const ComObjPtr <HostNetworkInterface> Iface2)
static bool vboxSolarisSameNIC(const ComObjPtr <HostNetworkInterface> Iface1, const ComObjPtr <HostNetworkInterface> Iface2)
# ifdef VBOX_SOLARIS_NSL_RESOLVED
static int vboxSolarisAddPhysHostIface(di_node_t Node, di_minor_t Minor, void *pvHostNetworkInterfaceList)
return DI_WALK_CONTINUE;
return DI_WALK_CONTINUE;
return DI_WALK_CONTINUE;
static int vboxNetWinAddComponent(std::list <ComObjPtr <HostNetworkInterface> > * pPist, INetCfgComponent * pncc)
Assert(0);
return rc;
STDMETHODIMP Host::COMGETTER(NetworkInterfaces) (ComSafeArrayOut (IHostNetworkInterface *, aNetworkInterfaces))
return E_POINTER;
CHECK_READY();
#ifdef VBOX_WITH_HOSTNETIF_API
if (rc)
# if defined(RT_OS_DARWIN)
while (pEtherNICs)
if (SUCCEEDED(IfObj->init(Bstr(pEtherNICs->szName), Guid(pEtherNICs->Uuid), HostNetworkInterfaceType_Bridged)))
# ifdef VBOX_SOLARIS_NSL_RESOLVED
if (VBoxSolarisLibDlpiFound())
if (Sock > 0)
if (!rc)
if (!rc)
if (!rc)
if (!rc)
# ifndef VBOX_WITH_NETFLT
&pNc,
&lpszApp );
#ifdef VBOX_NETFLT_ONDEMAND_BIND
/* for the protocol-based approach for now we just get all miniports the MS_TCPIP protocol binds to */
# ifndef VBOX_WITH_HARDENING
if(uComponentStatus == 0)
if (sock >= 0)
return S_OK;
#ifdef VBOX_WITH_USB
CHECK_READY();
#ifdef VBOX_WITH_USB
CHECK_READY();
return rc;
CHECK_READY();
return S_OK;
CHECK_READY();
return S_OK;
CHECK_READY();
return S_OK;
CHECK_READY();
CHECK_READY();
switch (aFeature)
case ProcessorFeature_PAE:
return S_OK;
CHECK_READY();
if (!hal)
return E_FAIL;
delete hal;
return rc;
CHECK_READY();
if (!hal)
return E_FAIL;
delete hal;
return rc;
CHECK_READY();
CHECK_READY();
CHECK_READY();
return S_OK;
#ifdef RT_OS_WINDOWS
return FALSE;
CHECK_READY();
d (new NetworkInterfaceHelperClientData());
static_cast <void *> (d.get()),
progress);
d.release();
return rc;
CHECK_READY();
d (new NetworkInterfaceHelperClientData());
static_cast <void *> (d.get()),
progress);
d.release();
return rc;
#ifdef VBOX_WITH_USB
CHECK_READY();
return S_OK;
#ifdef VBOX_WITH_USB
CHECK_READY();
if (!filter)
#ifdef VBOX_WITH_USB
CHECK_READY();
using namespace settings;
CHECK_READY();
#ifdef VBOX_WITH_USB
action);
return rc;
using namespace settings;
CHECK_READY();
#ifdef VBOX_WITH_USB
++ it;
return S_OK;
#ifdef VBOX_WITH_USB
CHECK_READY();
if (aActiveChanged)
return S_OK;
void Host::getUSBFilters(Host::USBDeviceFilterList *aGlobalFilters, VirtualBox::SessionMachineVector *aMachines)
bool halSuccess = false;
if (!gLibHalCheckPresence())
if (dbusConnection != 0)
if (halContext != 0)
int numDevices;
if (halDevices != 0)
halSuccess = true;
for (int i = 0; i < numDevices; i++)
#ifdef RT_OS_SOLARIS
if (devNode != 0)
if (product == 0)
LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n",
if (vendor != 0)
if (product != 0)
#ifndef RT_OS_SOLARIS
LogRel(("Host::COMGETTER(DVDDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n",
LogRel(("Host::COMGETTER(DVDDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(DVDDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(DVDDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(DVDDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
return halSuccess;
bool halSuccess = false;
if (!gLibHalCheckPresence())
if (dbusConnection != 0)
if (halContext != 0)
int numDevices;
if (halDevices != 0)
halSuccess = true;
for (int i = 0; i < numDevices; i++)
if (driveType != 0)
if (devNode != 0)
if (product == 0)
LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"info.product\" for device %s. dbus error: %s (%s)\n",
if (vendor != 0)
if (product != 0)
// LogRel(("Host::COMGETTER(FloppyDrives): failed to validate the block device %s as a floppy drive\n"));
LogRel(("Host::COMGETTER(FloppyDrives): failed to get property \"block.device\" for device %s. dbus error: %s (%s)\n",
LogRel(("Host::COMGETTER(FloppyDrives): failed to get devices with capability \"storage.cdrom\". dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(FloppyDrives): failed to shutdown the libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(FloppyDrives): failed to initialise libhal context. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
LogRel(("Host::COMGETTER(FloppyDrives): failed to connect to dbus. dbus error: %s (%s)\n", dbusError.name, dbusError.message));
return halSuccess;
#if defined(RT_OS_SOLARIS)
#ifdef RT_OS_LINUX
if (mtab)
char *mnt_type;
char *mnt_dev;
char *tmp;
if (tmp)
if (mnt_type)
if (tmp)
if (tmp)
if (mnt_dev)
if (tmp)
if (mntFile)
bool retValue = false;
if (!deviceNode)
if (isCDROM)
int fileHandle;
if (fileHandle >= 0)
#ifdef RT_OS_LINUX
retValue = true;
retValue = true;
return retValue;
#ifdef VBOX_WITH_USB
CHECK_READY();
#ifdef RT_OS_LINUX
# ifdef VBOX_WITH_DBUS
tr ("The USB Proxy Service could not be started, because neither the USB file system (usbfs) nor the hardware information service (hal) is available")
tr ("The USB Proxy Service could not be started, because the USB file system (usbfs) is not available")
return S_OK;
#ifdef RT_OS_WINDOWS
/* The original source of the VBoxTAP adapter creation/destruction code has the following copyright */
return E_INVALIDARG;
&pidl);
if (pShellFolder)
return hr;
return E_FAIL;
return E_FAIL;
return E_FAIL;
return status;
return S_OK;
#ifdef VBOX_WITH_NETFLT
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
while (TRUE)
if (!ret)
index++;
sizeof (detailBuf),
NULL))
TCHAR * t;
index ++;
if (!found)
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (ok)
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
KEY_READ);
GetLastError()));
if (destroyList)
return vrc;
SetErrBreak ((
SetErrBreak ((
SetErrBreak ((
if (hkeyConnection)
if (hkeyNetwork)
while (TRUE)
if (!ok)
index++;
NULL,
NULL,
&size);
if (!ok)
index++;
NULL,
size,
NULL);
if (!ok)
index++;
index++;
if (deviceHwid)
if (found)
index++;
GetLastError()));
if (!ok)
GetLastError()));
if (!ok)
GetLastError()));
return vrc;
return S_OK;
switch (d->msgCode)
bool endLoop = false;
while (!endLoop)
switch (reply)
endLoop = true;
endLoop = true;
endLoop = true;
bool endLoop = false;
while (!endLoop)
switch (reply)
endLoop = true;
endLoop = true;
endLoop = true;
if (aVrc)
return rc;
switch (aMsgCode)
return vrc;
#ifdef VBOX_WITH_RESOURCE_USAGE_API
STDMETHODIMP Host::FindHostNetworkInterfaceByName(IN_BSTR name, IHostNetworkInterface **networkInterface)
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
if (!name)
return E_INVALIDARG;
if (!networkInterface)
return E_POINTER;
return E_FAIL;
Bstr n;
if (n == name)
if (!found)
STDMETHODIMP Host::FindHostNetworkInterfaceById(IN_GUID id, IHostNetworkInterface **networkInterface)
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
return E_INVALIDARG;
if (!networkInterface)
return E_POINTER;
return E_FAIL;
Guid g;
if (!found)
STDMETHODIMP Host::FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_T type, ComSafeArrayOut (IHostNetworkInterface *, aNetworkInterfaces))
return hr;
return hr;
if(t == type)
return S_OK;