NetworkAdapterImpl.cpp revision 9abd802d84a98ae8602297346ec3b3290423bbab
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * VirtualBox COM class implementation
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Copyright (C) 2006-2007 innotek GmbH
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * available from http://www.virtualbox.org. This file is free software;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * General Public License (GPL) as published by the Free Software
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync// constructor / destructor
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync////////////////////////////////////////////////////////////////////////////////
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync// public initializer/uninitializer for internal purposes only
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync////////////////////////////////////////////////////////////////////////////////
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Initializes the network adapter object.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aParent Handle of the parent object.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncHRESULT NetworkAdapter::init (Machine *aParent, ULONG aSlot)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync LogFlowThisFunc (("aParent=%p, aSlot=%d\n", aParent, aSlot));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync ComAssertRet (aSlot < SchemaDefs::NetworkAdapterCount, E_INVALIDARG);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Enclose the state transition NotReady->InInit->Ready */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* mPeer is left null */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* initialize data */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* default to Am79C973 */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* generate the MAC address early to guarantee it is the same both after
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * changing some other property (i.e. after mData.backup()) and after the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * subsequent mData.rollback(). */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Confirm a successful initialization */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Initializes the network adapter object given another network adapter object
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * (a kind of copy constructor). This object shares data with
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * the object passed as an argument.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @note This object must be destroyed before the original object
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * it shares data with is destroyed.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @note Locks @a aThat object for reading.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncHRESULT NetworkAdapter::init (Machine *aParent, NetworkAdapter *aThat)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Enclose the state transition NotReady->InInit->Ready */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Confirm a successful initialization */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Initializes the guest object given another guest object
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * (a kind of copy constructor). This object makes a private copy of data
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * of the original object passed as an argument.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @note Locks @a aThat object for reading.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncHRESULT NetworkAdapter::initCopy (Machine *aParent, NetworkAdapter *aThat)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Enclose the state transition NotReady->InInit->Ready */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* mPeer is left null */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Confirm a successful initialization */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Uninitializes the instance and sets the ready flag to FALSE.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Called either from FinalRelease() or by the parent when it gets destroyed.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Enclose the state transition Ready->InUninit->NotReady */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync// INetworkAdapter properties
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync////////////////////////////////////////////////////////////////////////////////
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(AdapterType) (NetworkAdapterType_T *aAdapterType)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMSETTER(AdapterType) (NetworkAdapterType_T aAdapterType)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the machine needs to be mutable */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Machine::AutoMutableStateDependency adep (mParent);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* make sure the value is allowed */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* leave the lock before informing callbacks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(Slot) (ULONG *aSlot)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(Enabled) (BOOL *aEnabled)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMSETTER(Enabled) (BOOL aEnabled)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the machine needs to be mutable */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Machine::AutoMutableStateDependency adep (mParent);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* leave the lock before informing callbacks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(MACAddress)(BSTR *aMACAddress)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMSETTER(MACAddress)(INPTR BSTR aMACAddress)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the machine needs to be mutable */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Machine::AutoMutableStateDependency adep (mParent);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Are we supposed to generate a MAC?
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Verify given MAC address
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync while ((i < 13) && macAddressStr && *macAddressStr && (rc == S_OK))
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* canonicalize hex digits to capital letters */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** @todo the runtime lacks an ascii lower/upper conv */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* we only accept capital letters */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync rc = setError(E_INVALIDARG, tr("Invalid MAC address format"));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the second digit must have even value for unicast addresses */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if ((i == 1) && (!!(c & 1) == (c >= '0' && c <= '9')))
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync rc = setError(E_INVALIDARG, tr("Invalid MAC address format"));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* we must have parsed exactly 12 characters */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (i != 12)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync rc = setError(E_INVALIDARG, tr("Invalid MAC address format"));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* leave the lock before informing callbacks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(AttachmentType)(
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(HostInterface)(BSTR *aHostInterface)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMSETTER(HostInterface)(INPTR BSTR aHostInterface)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** @todo Validate input string length. r=dmik: do it in XML schema?*/
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync // we don't allow null strings for the host interface on Win32
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync // (because the @name attribute of <HostInerface> must be always present,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync // but can be empty).
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync // empty strings are not allowed as path names
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the machine needs to be mutable */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Machine::AutoMutableStateDependency adep (mParent);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* leave the lock before informing callbacks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(TAPFileDescriptor)(LONG *aTAPFileDescriptor)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMSETTER(TAPFileDescriptor)(LONG aTAPFileDescriptor)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Validate input.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (tapFD != NIL_RTFILE && (LONG)tapFD != aTAPFileDescriptor)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync AssertMsgFailed(("Invalid file descriptor: %ld.\n", aTAPFileDescriptor));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync tr ("Invalid file descriptor: %ld"), aTAPFileDescriptor);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the machine needs to be mutable */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Machine::AutoMutableStateDependency adep (mParent);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* leave the lock before informing callbacks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(TAPSetupApplication) (
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* we don't have to be in TAP mode to support this call */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync mData->mTAPSetupApplication.cloneTo (aTAPSetupApplication);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMSETTER(TAPSetupApplication) (
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* empty strings are not allowed as path names */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (aTAPSetupApplication && !(*aTAPSetupApplication))
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the machine needs to be mutable */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Machine::AutoMutableStateDependency adep (mParent);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (mData->mTAPSetupApplication != aTAPSetupApplication)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync mData->mTAPSetupApplication = aTAPSetupApplication;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* leave the lock before informing callbacks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(TAPTerminateApplication) (
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* we don't have to be in TAP mode to support this call */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync mData->mTAPTerminateApplication.cloneTo(aTAPTerminateApplication);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMSETTER(TAPTerminateApplication) (
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* empty strings are not allowed as path names */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (aTAPTerminateApplication && !(*aTAPTerminateApplication))
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the machine needs to be mutable */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Machine::AutoMutableStateDependency adep (mParent);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (mData->mTAPTerminateApplication != aTAPTerminateApplication)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync mData->mTAPTerminateApplication = aTAPTerminateApplication;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* leave the lock before informing callbacks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#endif /* VBOX_WITH_UNIXY_TAP_NETWORKING */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(InternalNetwork) (BSTR *aInternalNetwork)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* we don't allow null strings */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync mData->mInternalNetwork.cloneTo (aInternalNetwork);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMSETTER(InternalNetwork) (INPTR BSTR aInternalNetwork)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the machine needs to be mutable */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Machine::AutoMutableStateDependency adep (mParent);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* if an empty string is to be set, internal networking must be turned off */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync && (mData->mAttachmentType = NetworkAttachmentType_Internal))
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return setError (E_FAIL, tr ("Empty internal network name is not valid"));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* leave the lock before informing callbacks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(CableConnected) (BOOL *aConnected)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMSETTER(CableConnected) (BOOL aConnected)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the machine needs to be mutable */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Machine::AutoMutableStateDependency adep (mParent);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* leave the lock before informing callbacks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(LineSpeed) (ULONG *aSpeed)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMSETTER(LineSpeed) (ULONG aSpeed)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* the machine needs to be mutable */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Machine::AutoMutableStateDependency adep (mParent);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* leave the lock before informing callbacks */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP NetworkAdapter::COMGETTER(TraceEnabled) (BOOL *aEnabled)
return S_OK;
return S_OK;
if (!aTraceFile)
return E_POINTER;
return S_OK;
return S_OK;
detach();
return S_OK;
detach();
return S_OK;
detach();
return S_OK;
detach();
return S_OK;
using namespace settings;
E_FAIL);
#ifdef RT_OS_WINDOWS
return S_OK;
using namespace settings;
E_FAIL);
#ifdef RT_OS_WINDOWS
return S_OK;
bool changed = false;
return changed;
if (mPeer)
#ifdef RT_OS_WINDOWS