VBoxNetFltMp-win.c revision c7b017ddd4d5b39bd9343f12e47db5777c98b6f3
/* $Id$ */
/** @file
* VBoxNetFlt - Network Filter Driver (Host), Windows Specific Code. Miniport edge of ndis filter driver
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*
* Based in part on Microsoft DDK sample code for Ndis Intermediate Miniport passthru driver sample.
* Copyright (c) 1993-1999, Microsoft Corporation
*/
#include "VBoxNetFltCommon-win.h"
#ifdef VBOX_NETFLT_ONDEMAND_BIND
# error "unsupported (VBOX_NETFLT_ONDEMAND_BIND)"
#else
/** driver handle */
/** Ndis wrapper handle */
static NDIS_HANDLE g_hNdisWrapperHandle;
/** device handle for ioctl interface this is not used currently and should be removed soon */
/** device object used for ioctl interface this is not used currently and should be removed soon */
/** ioctl device ref count */
static LONG g_cControlDeviceRefs = 0;
/** true if control device needs to be dereferenced before destroying */
static bool g_bControlDeviceReferenced = false;
enum _DEVICE_STATE
{
/** create operation in progress */
/** delete operation in progress */
/*
* miniport
*/
typedef struct {
/*
* makes our device object usable/accessible for non-privileged users
*/
{
/*obtain the handle first*/
OBJ_KERNEL_HANDLE /* ULONG Attributes */,
NULL /*HANDLE RootDirectory*/,
NULL /*PSECURITY_DESCRIPTOR SecurityDescriptor */
);
WRITE_DAC /*ACCESS_MASK DesiredAccess - we want to change the ACL */,
&ObjAttr /*POBJECT_ATTRIBUTES */,
&IoStatus /*PIO_STATUS_BLOCK */,
0 /*ULONG ShareAccess*/,
0 /*ULONG OpenOptions*/
);
if(Status == STATUS_SUCCESS)
{
/* create and set security descriptor */
if(Status == STATUS_SUCCESS)
{
if(Status != STATUS_SUCCESS)
{
}
}
else
{
}
{
if(Tmp != STATUS_SUCCESS)
{
}
}
}
else
{
}
return Status;
}
/**
* Register an ioctl interface - a device object to be used for this
* purpose is created by NDIS when we call NdisMRegisterDevice.
*
* This routine is called whenever a new miniport instance is
* initialized. However, we only create one global device object,
* when the first miniport instance is initialized. This routine
* handles potential race conditions with vboxNetFltWinPtDeregisterDevice via
* the g_eControlDeviceState and g_cControlDeviceRefs variables.
*
* NOTE: do not call this from DriverEntry; it will prevent the driver
* from being unloaded (e.g. on uninstall).
*
* @return NDIS_STATUS_SUCCESS if we successfully register a device object. */
static NDIS_STATUS
)
{
LogFlow(("==>vboxNetFltWinPtRegisterDevice\n"));
if (1 == g_cControlDeviceRefs)
{
/* Another thread could be running vboxNetFltWinPtDeregisterDevice on
* behalf of another miniport instance. If so, wait for
* it to exit. */
while (g_eControlDeviceState != PS_DEVICE_STATE_READY)
{
NdisMSleep(1);
}
/* Create a device object and register our dispatch handlers */
&DispatchTable[0],
);
if(Status == NDIS_STATUS_SUCCESS)
{
/* NdisMRegisterDevice does not offers us the ability to set security attributes */
/* need to do this "manualy" for the device to be accessible by the non-privileged users */
if(Status != STATUS_SUCCESS)
{
LogRel(("Failed to set security attributes for netflt control device, status (0x%x), ignoring\n", Status));
/* ignore the failure */
}
Status = ObReferenceObjectByPointer(g_pControlDeviceObject, FILE_READ_DATA, *IoFileObjectType, KernelMode);
if(Status == NDIS_STATUS_SUCCESS)
{
g_bControlDeviceReferenced = true;
}
else
{
/* ignore the failure */
g_bControlDeviceReferenced = false;
}
}
}
return (Status);
}
/**
* Deregister the ioctl interface. This is called whenever a miniport
* instance is halted. When the last miniport instance is halted, we
* request NDIS to delete the device object
*
* @return NDIS_STATUS_SUCCESS if everything worked ok
* */
static NDIS_STATUS
)
{
LogFlow(("==>NetFltDeregisterDevice\n"));
Assert(g_cControlDeviceRefs > 0);
if (0 == g_cControlDeviceRefs)
{
/* All miniport instances have been halted. Deregister
* the control device. */
/* Block vboxNetFltWinPtRegisterDevice() while we release the control
* device lock and deregister the device. */
if (g_hNdisDeviceHandle != NULL)
{
{
g_bControlDeviceReferenced = false;
}
}
}
return Status;
}
#ifndef VBOXNETADP
/**
* This is the initialize handler which gets called as a result of
* the BindAdapter handler calling NdisIMInitializeDeviceInstanceEx.
* The context parameter which we pass there is the adapter structure
* which we retrieve here.
*
* @param OpenErrorStatus Not used by us.
* @param SelectedMediumIndex Place-holder for what media we are using
* @param MediumArray Array of ndis media passed down to us to pick from
* @param MediumArraySize Size of the array
* @param MiniportAdapterHandle The handle NDIS uses to refer to us
* @param WrapperConfigurationContext For use by NdisOpenConfiguration
* @return NDIS_STATUS_SUCCESS unless something goes wrong
* */
static NDIS_STATUS vboxNetFltWinMpInitialize(
)
{
UINT i;
do
{
/*
* Start off by retrieving our adapter context and storing
* the Miniport handle in it.
*/
/* the MP state should be already set to kVBoxNetDevOpState_Initializing, just a paranoya
* in case NDIS for some reason calls us in some unregular way */
/*
* Usually we export the medium type of the adapter below as our
* virtual miniport's medium type. However if the adapter below us
* is a WAN device, then we claim to be of medium type 802.3.
*/
if (Medium == NdisMediumWan)
{
}
for (i = 0; i < MediumArraySize; i++)
{
if (MediumArray[i] == Medium)
{
*SelectedMediumIndex = i;
break;
}
}
if (i == MediumArraySize)
{
break;
}
/*
* Set the attributes now. NDIS_ATTRIBUTE_DESERIALIZE enables us
* to make up-calls to NDIS without having to call NdisIMSwitchToMiniport
* or NdisIMQueueCallBack. This also forces us to protect our data using
* spinlocks where appropriate. Also in this case NDIS does not queue
* packets on our behalf. Since this is a very simple pass-thru
* miniport, we do not have a need to protect anything. However in
* a general case there will be a need to use per-adapter spin-locks
* for the packet queues at the very least.
*/
0, /* CheckForHangTimeInSeconds */
(NDIS_INTERFACE_TYPE)0);
/*
* Initialize LastIndicatedStatus to be NDIS_STATUS_MEDIA_CONNECT
*/
/*
* Initialize the power states for both the lower binding (PTDeviceState)
* and our miniport edge to Powered On.
*/
}
while (FALSE);
/*
* If we had received an UnbindAdapter notification on the underlying
* adapter, we would have blocked that thread waiting for the IM Init
* process to complete. Wake up any such thread.
*/
if(Status != NDIS_STATUS_SUCCESS)
{
}
return Status;
}
/**
* process the packet send in a "passthru" mode
*/
static NDIS_STATUS
)
{
if (fStatus == NDIS_STATUS_SUCCESS)
{
#if !defined(VBOX_LOOPBACK_USEFLAGS) /* || defined(DEBUG_NETFLT_PACKETS) */
/* no need for the loop enqueue & check in a passthru mode , ndis will do everything for us */
#endif
if (fStatus != NDIS_STATUS_PENDING)
{
#ifndef WIN9X
#endif
}
}
return fStatus;
}
#else /* defined VBOXNETADP */
{
int cPPUsage;
/*
* Set the flag that the miniport below is unbinding, so the request handlers will
* fail any request comming later
*/
/* check packet pool is empty */
/* for debugging only, ignore the err in release */
// pAdapt->hMiniportHandle = NULL;
return NDIS_STATUS_SUCCESS;
}
static NDIS_STATUS vboxNetFltWinMpReadApplyConfig(PADAPT pAdapt, NDIS_HANDLE hMiniportAdapter, NDIS_HANDLE hWrapperConfigurationContext)
{
//
// Open the registry for this adapter to read advanced
// configuration parameters stored by the INF file.
//
&Status,
if(Status == NDIS_STATUS_SUCCESS)
{
do
{
int rc;
&strMAC,
// Assert(Status == NDIS_STATUS_SUCCESS);
if(Status == NDIS_STATUS_SUCCESS)
{
if(RT_SUCCESS(rc))
{
break;
}
}
if(RT_SUCCESS(rc))
{
&strMAC,
¶m);
if(Status != NDIS_STATUS_SUCCESS)
{
/* ignore the failure */
}
}
}while(0);
}
else
{
}
return NDIS_STATUS_SUCCESS;
}
DECLHIDDEN(NDIS_STATUS) vboxNetFltWinMpDoInitialization(PADAPT pAdapt, NDIS_HANDLE hMiniportAdapter, NDIS_HANDLE hWrapperConfigurationContext)
{
0, /* CheckForHangTimeInSeconds */
NdisInterfaceInternal/*(NDIS_INTERFACE_TYPE)0*/);
/*
* Initialize the power states for both the lower binding (PTDeviceState)
* and our miniport edge to Powered On.
*/
// *OpenErrorStatus = Status;
return Status;
}
/**
* This is the initialize handler which gets called as a result of
* the BindAdapter handler calling NdisIMInitializeDeviceInstanceEx.
* The context parameter which we pass there is the adapter structure
* which we retrieve here.
*
* @param OpenErrorStatus Not used by us.
* @param SelectedMediumIndex Place-holder for what media we are using
* @param MediumArray Array of ndis media passed down to us to pick from
* @param MediumArraySize Size of the array
* @param MiniportAdapterHandle The handle NDIS uses to refer to us
* @param WrapperConfigurationContext For use by NdisOpenConfiguration
* @return NDIS_STATUS_SUCCESS unless something goes wrong
* */
static NDIS_STATUS vboxNetFltWinMpInitialize(
)
{
UINT i;
if (Medium == NdisMediumWan)
{
}
for (i = 0; i < MediumArraySize; i++)
{
if (MediumArray[i] == Medium)
{
*SelectedMediumIndex = i;
break;
}
}
if (i != MediumArraySize)
{
#define KEY_PREFIX L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Class\\"
&pPdo,
&pFdo,
NULL, //Next Device Object
NULL,
NULL);
&cbBuf);
if(Status == STATUS_SUCCESS)
{
if(Status == STATUS_SUCCESS)
{
// UCHAR valBuf[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + RTUUID_STR_LENGTH*2 + 10];
// ULONG cLength = sizeof(valBuf);
#define NAME_PREFIX L"\\DEVICE\\"
sizeof(Buf),
&cbBuf);
if(Status == STATUS_SUCCESS)
{
{
if(Status == STATUS_SUCCESS)
{
Status = vboxNetFltWinPtInitBind(&pAdapt, MiniportAdapterHandle, &RtlStr, WrapperConfigurationContext);
if(Status == STATUS_SUCCESS)
{
#if 0
0);
#endif
}
else
{
}
}
}
else
{
}
}
}
}
}
else
{
}
if(Status != NDIS_STATUS_SUCCESS)
{
}
/* TODO: */
return Status;
}
#endif
/**
* Send Packet Array handler. Either this or our SendPacket handler is called
* based on which one is enabled in our Miniport Characteristics.
*
* @param MiniportAdapterContext Pointer to our adapter
* @param PacketArray Set of packets to send
* @param NumberOfPackets Self-explanatory
* @return none */
static VOID
)
{
UINT i;
bool bNetFltActive;
{
if(bNetFltActive)
{
cPassThruRefs = 0;
}
else
{
cNetFltRefs = 0;
}
for (i = 0; i < cNumberOfPackets; i++)
{
pPacket = pPacketArray[i];
if(!cNetFltRefs
|| (fStatus = vboxNetFltWinQuEnqueuePacket(pNetFlt, pPacket, PACKET_SRC_HOST)) != NDIS_STATUS_SUCCESS)
{
#ifndef VBOXNETADP
#else
if(!cNetFltRefs)
{
# ifdef VBOXNETADP_REPORT_DISCONNECTED
# else
# endif
}
#endif
if (fStatus != NDIS_STATUS_PENDING)
{
fStatus);
}
else
{
cAdaptRefs--;
}
}
else
{
cAdaptRefs--;
cNetFltRefs--;
}
}
if(cNetFltRefs)
{
}
else if(cPassThruRefs)
{
}
if(cAdaptRefs)
{
}
}
else
{
Assert(0);
if(h)
{
for (i = 0; i < cNumberOfPackets; i++)
{
pPacket = pPacketArray[i];
}
}
}
}
#ifndef VBOXNETADP
/**
* Entry point called by NDIS to query for the value of the specified OID.
* Typical processing is to forward the query down to the underlying miniport.
*
* The following OIDs are filtered here:
* OID_PNP_QUERY_POWER - return success right here
* OID_GEN_SUPPORTED_GUIDS - do not forward, otherwise we will show up
* multiple instances of private GUIDs supported by the underlying miniport.
* OID_PNP_CAPABILITIES - we do send this down to the lower miniport, but
* the values returned are postprocessed before we complete this request;
* see vboxNetFltWinPtRequestComplete.
*
* NOTE on OID_TCP_TASK_OFFLOAD - if this IM driver modifies the contents
* of data it passes through such that a lower miniport may not be able
* to perform TCP task offload, then it should not forward this OID down,
* but fail it here with the status NDIS_STATUS_NOT_SUPPORTED. This is to
* avoid performing incorrect transformations on data.
*
* If our miniport edge (upper edge) is at a low-power state, fail the request.
* If our protocol edge (lower edge) has been notified of a low-power state,
* we pend this request until the miniport below has been set to D0. Since
* requests to miniports are serialized always, at most a single request will
* be pended.
*
* @param MiniportAdapterContext Pointer to the adapter structure
* @param Oid Oid for this query
* @param InformationBuffer Buffer for information
* @param InformationBufferLength Size of this buffer
* @param BytesWritten Specifies how much info is written
* @param BytesNeeded In case the buffer is smaller than what we need, tell them how much is needed
* @return Return code from the NdisRequest below.
* */
static NDIS_STATUS
)
{
do
{
if (Oid == OID_PNP_QUERY_POWER)
{
/*
* Do not forward this.
*/
break;
}
if (Oid == OID_GEN_SUPPORTED_GUIDS)
{
/*
* Do not forward this, otherwise we will end up with multiple
* instances of private GUIDs that the underlying miniport
* supports.
*/
break;
}
if (Oid == OID_TCP_TASK_OFFLOAD)
{
/* we want to receive packets with checksums calculated
* since we are passing them to IntNet
*/
break;
}
/*
* If the miniport below is unbinding, just fail any request
*/
if (vboxNetFltWinGetOpState(&pAdapt->PTState) > kVBoxNetDevOpState_Initialized) /* protocol unbind in progress */
{
break;
}
/*
* All other queries are failed, if the miniport is not at D0,
*/
{
break;
}
/*
* If the miniport below is binding, fail the request
*/
{
break;
}
/*
* If the Protocol device state is OFF, mark this request as being
* pended. We queue this until the device state is back to D0.
*/
{
break;
}
/*
* This is in the process of powering down the system, always fail the request
*/
{
break;
}
{
bool fNetFltActive;
if(fNetFltActive)
{
/* netflt is active, simply return the cached value */
break;
}
else if(fAdaptActive)
{
/* we're cleaning it in RequestComplete */
}
}
/*
* default case, most requests will be passed to the miniport below
*/
if (Status != NDIS_STATUS_PENDING)
{
}
} while (FALSE);
return(Status);
}
/**
* Postprocess a request for OID_PNP_CAPABILITIES that was forwarded
* down to the underlying miniport, and has been completed by it.
*
* @param pAdapt - Pointer to the adapter structure
* @param pStatus - Place to return final status
* @return None. */
)
{
if (pAdapt->Request.DATA.QUERY_INFORMATION.InformationBufferLength >= sizeof(NDIS_PNP_CAPABILITIES))
{
pPNPCapabilities = (PNDIS_PNP_CAPABILITIES)(pAdapt->Request.DATA.QUERY_INFORMATION.InformationBuffer);
/*
* The following fields must be overwritten by an IM driver.
*/
*pAdapt->BytesNeeded = 0;
}
else
{
}
}
#endif /* ifndef VBOXNETADP*/
/**
* This routine does all the procssing for a request with a SetPower Oid
* The miniport shoud accept the Set Power and transition to the new state
*
* The Set Power should not be passed to the miniport below
*
* If the IM miniport is going into a low power state, then there is no guarantee if it will ever
* be asked go back to D0, before getting halted. No requests should be pended or queued.
*
* @param pNdisStatus - Status of the operation
* @param pAdapt - The Adapter structure
* @param InformationBuffer - The New DeviceState
* @param InformationBufferLength
* @param BytesRead - No of bytes read
* @param BytesNeeded - No of bytes needed
* @return Status - NDIS_STATUS_SUCCESS if all the wait events succeed. */
static VOID
)
{
do
{
/*
* Check for invalid length
*/
if (InformationBufferLength < sizeof(NDIS_DEVICE_POWER_STATE))
{
break;
}
/*
* Check for invalid device state
*/
if ((vboxNetFltWinGetPowerState(&pAdapt->MPState) > NdisDeviceStateD0) && (NewDeviceState != NdisDeviceStateD0))
{
/*
* If the miniport is in a non-D0 state, the miniport can only receive a Set Power to D0
*/
Assert (!(vboxNetFltWinGetPowerState(&pAdapt->MPState) > NdisDeviceStateD0) && (NewDeviceState != NdisDeviceStateD0));
break;
}
#ifndef VBOXNETADP
/*
* Is the miniport transitioning from an On (D0) state to an Low Power State (>D0)
* If so, then set the bStandingBy Flag - (Block all incoming requests)
*/
if (vboxNetFltWinGetPowerState(&pAdapt->MPState) == NdisDeviceStateD0 && NewDeviceState > NdisDeviceStateD0)
{
}
/*
* If the miniport is transitioning from a low power state to ON (D0), then clear the bStandingBy flag
* All incoming requests will be pended until the physical miniport turns ON.
*/
if (vboxNetFltWinGetPowerState(&pAdapt->MPState) > NdisDeviceStateD0 && NewDeviceState == NdisDeviceStateD0)
{
}
#endif
/*
* Now update the state in the pAdapt structure;
*/
#ifndef VBOXNETADP
if(NewDeviceState != NdisDeviceStateD0)
{
true ); /* just return */
}
#endif
} while (FALSE);
if (*pNdisStatus == NDIS_STATUS_SUCCESS)
{
#ifndef VBOXNETADP
/*
* The miniport resume from low power state
*/
{
/*
* If we need to indicate the media connect state
*/
{
0);
}
}
else
{
/*
* Initialize LatestUnIndicatedStatus
*/
}
#endif
*BytesRead = sizeof(NDIS_DEVICE_POWER_STATE);
*BytesNeeded = 0;
}
else
{
*BytesRead = 0;
*BytesNeeded = sizeof (NDIS_DEVICE_POWER_STATE);
}
}
#ifndef VBOXNETADP
/**
* Miniport SetInfo handler.
*
* In the case of OID_PNP_SET_POWER, record the power state and return the OID.
* Do not pass below
* If the device is suspended, do not block the SET_POWER_OID
* as it is used to reactivate the NetFlt miniport
*
* PM- If the MP is not ON (DeviceState > D0) return immediately (except for 'query power' and 'set power')
* If MP is ON, but the PT is not at D0, then queue the queue the request for later processing
*
* Requests to miniports are always serialized
*
* @param MiniportAdapterContext Pointer to the adapter structure
* @param Oid Oid for this query
* @param InformationBuffer Buffer for information
* @param InformationBufferLength Size of this buffer
* @param BytesRead Specifies how much info is read
* @param BytesNeeded In case the buffer is smaller than what we need, tell them how much is needed
* @return Return code from the NdisRequest below. */
static NDIS_STATUS
)
{
do
{
/*
* The Set Power should not be sent to the miniport below the NetFlt, but is handled internally
*/
if (Oid == OID_PNP_SET_POWER)
{
break;
}
/*
* If the miniport below is unbinding, fail the request
*/
{
break;
}
/*
* All other Set Information requests are failed, if the miniport is
* not at D0 or is transitioning to a device state greater than D0.
*/
{
break;
}
/* Set up the Request and return the result */
/*
* If the miniport below is unbinding, fail the request
*/
{
break;
}
/*
* If the device below is at a low power state, we cannot send it the
* request now, and must pend it.
*/
{
break;
}
/*
* This is in the process of powering down the system, always fail the request
*/
{
break;
}
{
/* need to disable cleaning promiscuous here ?? */
bool fNetFltActive;
if(fNetFltActive)
{
/* netflt is active, update the cached value */
/* TODO: in case we are are not in promiscuous now, we are issuing a request.
* what should we do in case of a failure?
* i.e. should we update the fUpperProtocolSetFilter in completion routine in this case? etc. */
pAdapt->bUpperProtSetFilterInitialized = true;
{
/* we'll do dereferencing in request complete */
}
else
{
break;
}
}
else if(fAdaptActive)
{
/* dereference on completion */
}
}
/*
* Forward the request to the device below.
*/
if (Status != NDIS_STATUS_PENDING)
{
}
} while (FALSE);
return(Status);
}
#else
static NDIS_OID g_vboxNetFltWinMpSupportedOids[] =
{
#ifndef INTERFACE_WITH_NDISPROT
,
# if 0
,
# endif
#endif
};
static NDIS_STATUS
/*++
Routine Description:
Entry point called by NDIS to query for the value of the specified OID.
MiniportQueryInformation runs at IRQL = DISPATCH_LEVEL.
Arguments:
MiniportAdapterContext Pointer to the adapter structure
Oid Oid for this query
InformationBuffer Buffer for information
InformationBufferLength Size of this buffer
BytesWritten Specifies how much info is written
BytesNeeded In case the buffer is smaller than
what we need, tell them how much is needed
Return Value:
Return code from the NdisRequest below.
Notes: Read "Minimizing Miniport Driver Initialization Time" in the DDK
for more info on how to handle certain OIDs that affect the init of
a miniport.
--*/
{
// Initialize the result
*BytesWritten = 0;
*BytesNeeded = 0;
switch(Oid)
{
case OID_GEN_SUPPORTED_LIST:
//
// The OID_GEN_SUPPORTED_LIST OID specifies an array of OIDs
// for objects that the underlying driver or its NIC supports.
// Objects include general, media-specific, and implementation-
// specific objects. NDIS forwards a subset of the returned
// list to protocols that make this query. That is, NDIS filters
// any supported statistics OIDs out of the list because
// protocols never make statistics queries.
//
ulInfoLen = sizeof(g_vboxNetFltWinMpSupportedOids);
break;
case OID_GEN_HARDWARE_STATUS:
//
// Specify the current hardware status of the underlying NIC as
// one of the following NDIS_HARDWARE_STATUS-type values.
//
ulInfoLen = sizeof(NDIS_HARDWARE_STATUS);
break;
case OID_GEN_MEDIA_SUPPORTED:
//
// Specify the media types that the NIC can support but not
// necessarily the media types that the NIC currently uses.
// fallthrough:
case OID_GEN_MEDIA_IN_USE:
//
// Specifiy a complete list of the media types that the NIC
// currently uses.
//
ulInfoLen = sizeof(NDIS_MEDIUM);
break;
//
// If the miniport driver indicates received data by calling
// NdisXxxIndicateReceive, it should respond to OID_GEN_MAXIMUM_LOOKAHEAD
// with the maximum number of bytes the NIC can provide as
// lookahead data. If that value is different from the size of the
// lookahead buffer supported by bound protocols, NDIS will call
// MiniportSetInformation to set the size of the lookahead buffer
// provided by the miniport driver to the minimum of the miniport
// driver and protocol(s) values. If the driver always indicates
// up full packets with NdisMIndicateReceivePacket, it should
// set this value to the maximum total packet size, which
// excludes the header.
// Upper-layer drivers examine lookahead data to determine whether
// a packet that is associated with the lookahead data is intended
// for one or more of their clients. If the underlying driver
// supports multipacket receive indications, bound protocols are
// given full net packets on every indication. Consequently,
// this value is identical to that returned for
// OID_GEN_RECEIVE_BLOCK_SIZE.
//
break;
//
// Specifiy the maximum network packet size, in bytes, that the
// NIC supports excluding the header. A NIC driver that emulates
// another medium type for binding to a transport must ensure that
// the maximum frame size for a protocol-supplied net packet does
// not exceed the size limitations for the true network medium.
//
break;
//
// Specify the maximum total packet length, in bytes, the NIC
// supports including the header. A protocol driver might use
// this returned length as a gauge to determine the maximum
// size packet that a NIC driver could forward to the
// protocol driver. The miniport driver must never indicate
// up to the bound protocol driver packets received over the
// network that are longer than the packet size specified by
// OID_GEN_MAXIMUM_TOTAL_SIZE.
//
//
// The OID_GEN_TRANSMIT_BLOCK_SIZE OID specifies the minimum
// number of bytes that a single net packet occupies in the
// transmit buffer space of the NIC. For example, a NIC that
// has a transmit space divided into 256-byte pieces would have
// a transmit block size of 256 bytes. To calculate the total
// transmit buffer space on such a NIC, its driver multiplies
// the number of transmit buffers on the NIC by its transmit
// block size. In our case, the transmit block size is
// identical to its maximum packet size.
//
// The OID_GEN_RECEIVE_BLOCK_SIZE OID specifies the amount of
// storage, in bytes, that a single packet occupies in the receive
// buffer space of the NIC.
//
break;
case OID_GEN_MAC_OPTIONS:
//
// Specify a bitmask that defines optional properties of the NIC.
// This miniport indicates receive with NdisMIndicateReceivePacket
// function. It has no MiniportTransferData function. Such a driver
// should set this NDIS_MAC_OPTION_TRANSFERS_NOT_PEND flag.
//
// NDIS_MAC_OPTION_NO_LOOPBACK tells NDIS that NIC has no internal
// loopback support so NDIS will manage loopbacks on behalf of
// this driver.
//
// NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA tells the protocol that
// our receive buffer is not on a device-specific card. If
// NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA is not set, multi-buffer
// indications are copied to a single flat buffer.
//
break;
case OID_GEN_LINK_SPEED:
//
// Specify the maximum speed of the NIC in kbps.
// The unit of measurement is 100 bps
//
break;
//
// Specify the amount of memory, in bytes, on the NIC that
// is available for buffering transmit data. A protocol can
// use this OID as a guide for sizing the amount of transmit
// data per send.
//
break;
//
// Specify the amount of memory on the NIC that is available
// for buffering receive data. A protocol driver can use this
// OID as a guide for advertising its receive window after it
// establishes sessions with remote nodes.
//
break;
case OID_GEN_VENDOR_ID:
//
// Specify a three-byte IEEE-registered vendor code, followed
// by a single byte that the vendor assigns to identify a
// particular NIC. The IEEE code uniquely identifies the vendor
// and is the same as the three bytes appearing at the beginning
// of the NIC hardware address. Vendors without an IEEE-registered
// code should use the value 0xFFFFFF.
//
break;
//
// Specify a zero-terminated string describing the NIC vendor.
//
pInfo = VendorDesc;
ulInfoLen = sizeof(VendorDesc);
break;
//
// Specify the vendor-assigned version number of the NIC driver.
// The low-order half of the return value specifies the minor
// version; the high-order half specifies the major version.
//
break;
case OID_GEN_DRIVER_VERSION:
//
// Specify the NDIS version in use by the NIC driver. The high
// byte is the major version number; the low byte is the minor
// version number.
//
break;
//
// If a miniport driver registers a MiniportSendPackets function,
// MiniportQueryInformation will be called with the
// OID_GEN_MAXIMUM_SEND_PACKETS request. The miniport driver must
// respond with the maximum number of packets it is prepared to
// handle on a single send request. The miniport driver should
// pick a maximum that minimizes the number of packets that it
// has to queue internally because it has no resources
// (its device is full). A miniport driver for a bus-master DMA
// NIC should attempt to pick a value that keeps its NIC filled
// under anticipated loads.
//
break;
//
// Return the connection status of the NIC on the network as one
// of the following system-defined values: NdisMediaStateConnected
// or NdisMediaStateDisconnected.
//
{
bool bNetFltActive;
if(bActive && bNetFltActive)
{
}
else
{
}
if(bActive)
{
}
if(bNetFltActive)
{
}
else
{
}
}
#else
#endif
break;
//
// Specifiy the types of net packets such as directed, broadcast
// multicast, for which a protocol receives indications from a
// NIC driver. After NIC is initialized, a protocol driver
// can send a set OID_GEN_CURRENT_PACKET_FILTER to a non-zero value,
// thereby enabling the miniport driver to indicate receive packets
// to that protocol.
//
ulInfo = (
);
break;
case OID_PNP_CAPABILITIES:
//
// Return the wake-up capabilities of its NIC. If you return
// NDIS_STATUS_NOT_SUPPORTED, NDIS considers the miniport driver
// to be not Power management aware and doesn't send any power
// or wake-up related queries such as
// OID_PNP_SET_POWER, OID_PNP_QUERY_POWER,
// OID_PNP_ADD_WAKE_UP_PATTERN, OID_PNP_REMOVE_WAKE_UP_PATTERN,
// OID_PNP_ENABLE_WAKE_UP. Here, we are expecting the driver below
// us to do the right thing.
//
ulInfoLen = sizeof (NDIS_PNP_CAPABILITIES);
break;
case OID_PNP_QUERY_POWER:
break;
//
// Following 4 OIDs are for querying Ethernet Operational
// Characteristics.
//
//
// Return the MAC address of the NIC burnt in the hardware.
//
{
}
break;
//
// Return the MAC address the NIC is currently programmed to
// use. Note that this address could be different from the
// permananent address as the user can override using
// registry. Read NdisReadNetworkAddress doc for more info.
//
{
}
break;
//
// The maximum number of multicast addresses the NIC driver
// can manage. This list is global for all protocols bound
// to (or above) the NIC. Consequently, a protocol can receive
// NDIS_STATUS_MULTICAST_FULL from the NIC driver when
// attempting to set the multicast address list, even if
// the number of elements in the given list is less than
// the number originally returned for this query.
//
break;
case OID_802_3_MAC_OPTIONS:
//
// A protocol can use this OID to determine features supported
// by the underlying driver such as NDIS_802_3_MAC_OPTION_PRIORITY.
// Return zero indicating that it supports no options.
//
ulInfo = 0;
break;
//
// Following list consists of both general and Ethernet
// specific statistical OIDs.
//
case OID_GEN_XMIT_OK:
if (InformationBufferLength >= sizeof(ULONG64) ||
InformationBufferLength == 0)
{
}
else
{
}
// We should always report that 8 bytes are required to keep ndistest happy
*BytesNeeded = sizeof(ULONG64);
break;
case OID_GEN_RCV_OK:
if (InformationBufferLength >= sizeof(ULONG64) ||
InformationBufferLength == 0)
{
}
else
{
}
// We should always report that 8 bytes are required to keep ndistest happy
*BytesNeeded = sizeof(ULONG64);
break;
case OID_GEN_XMIT_ERROR:
break;
case OID_GEN_RCV_ERROR:
break;
case OID_GEN_RCV_NO_BUFFER:
ulInfo = 0;
break;
case OID_GEN_RCV_CRC_ERROR:
ulInfo = 0;
break;
break;
ulInfo = 0;
break;
ulInfo = 0;
break;
ulInfo = 0;
break;
case OID_802_3_XMIT_DEFERRED:
ulInfo = 0;
break;
ulInfo = 0;
break;
case OID_802_3_RCV_OVERRUN:
ulInfo = 0;
break;
case OID_802_3_XMIT_UNDERRUN:
ulInfo = 0;
break;
ulInfo = 0;
break;
ulInfo = 0;
break;
ulInfo = 0;
break;
default:
break;
}
if(Status == NDIS_STATUS_SUCCESS)
{
if(ulInfoLen <= InformationBufferLength)
{
// Copy result into InformationBuffer
if(ulInfoLen)
{
}
}
else
{
// too short
*BytesNeeded = ulInfoLen;
}
}
LogFlow(("<== vboxNetFltWinMpQueryInformation Status = 0x%08x\n",
Status));
return(Status);
}
)
/*++
Routine Description:
This routine will set up the adapter for a specified multicast
address list.
Arguments:
IN PMP_ADAPTER Adapter - Pointer to adapter block
InformationBuffer - Buffer for information
InformationBufferLength Size of this buffer
pBytesRead Specifies how much info is read
BytesNeeded In case the buffer is smaller than
Return Value:
NDIS_STATUS
--*/
{
#if 0
#endif
LogFlow(("==> vboxNetFltWinMpSetMulticastList\n"));
//
// Initialize.
//
*pBytesNeeded = 0;
do
{
{
break;
}
{
break;
}
#if 0
//
// Protect the list update with a lock if it can be updated by
// another thread simultaneously.
//
#endif
}
while (FALSE);
//
// Program the hardware to add suport for these muticast addresses
//
LogFlow(("<== vboxNetFltWinMpSetMulticastList\n"));
return(Status);
}
static NDIS_STATUS
/*++
Routine Description:
This is the handler for an OID set operation.
MiniportSetInformation runs at IRQL = DISPATCH_LEVEL.
Arguments:
MiniportAdapterContext Pointer to the adapter structure
Oid Oid for this query
InformationBuffer Buffer for information
InformationBufferLength Size of this buffer
BytesRead Specifies how much info is read
BytesNeeded In case the buffer is smaller than what
we need, tell them how much is needed
Return Value:
Return code from the NdisRequest below.
--*/
{
*BytesRead = 0;
*BytesNeeded = 0;
switch(Oid)
{
case OID_802_3_MULTICAST_LIST:
//
// Set the multicast address list on the NIC for packet reception.
// The NIC driver can set a limit on the number of multicast
// addresses bound protocol drivers can enable simultaneously.
// NDIS returns NDIS_STATUS_MULTICAST_FULL if a protocol driver
// exceeds this limit or if it specifies an invalid multicast
// address.
//
break;
//
// Program the hardware to indicate the packets
// of certain filter types.
//
if(InformationBufferLength != sizeof(ULONG))
{
*BytesNeeded = sizeof(ULONG);
break;
}
break;
//
// A protocol driver can set a suggested value for the number
// of bytes to be used in its binding; however, the underlying
// NIC driver is never required to limit its indications to
// the value set.
//
if(InformationBufferLength != sizeof(ULONG)){
*BytesNeeded = sizeof(ULONG);
break;
}
break;
case OID_PNP_SET_POWER:
//
// This OID notifies a miniport driver that its NIC will be
// transitioning to the device power state specified in the
// InformationBuffer. The miniport driver must always return
// NDIS_STATUS_SUCCESS to an OID_PNP_SET_POWER request. An
// OID_PNP_SET_POWER request may or may not be preceded by an
// OID_PNP_QUERY_POWER request.
//
if (InformationBufferLength != sizeof(NDIS_DEVICE_POWER_STATE ))
{
break;
}
vboxNetFltWinMpProcessSetPowerOid(&Status, pAdapt, InformationBuffer, InformationBufferLength, BytesRead, BytesNeeded);
break;
/*
case OID_PNP_ADD_WAKE_UP_PATTERN:
//
// This OID is sent by a protocol driver to a miniport driver to
// specify a wake-up pattern. The wake-up pattern, along with its mask,
// is described by an NDIS_PM_PACKET_PATTERN structure.
//
pPmPattern = (PNDIS_PM_PACKET_PATTERN) InformationBuffer;
if (InformationBufferLength < sizeof(NDIS_PM_PACKET_PATTERN))
{
Status = NDIS_STATUS_BUFFER_TOO_SHORT;
*BytesNeeded = sizeof(NDIS_PM_PACKET_PATTERN);
break;
}
if (InformationBufferLength < pPmPattern->PatternOffset + pPmPattern->PatternSize)
{
Status = NDIS_STATUS_BUFFER_TOO_SHORT;
*BytesNeeded = pPmPattern->PatternOffset + pPmPattern->PatternSize;
break;
}
*BytesRead = pPmPattern->PatternOffset + pPmPattern->PatternSize;
Status = NDIS_STATUS_SUCCESS;
bForwardRequest = TRUE;
break;
case OID_PNP_REMOVE_WAKE_UP_PATTERN:
//
// This OID requests the miniport driver to delete a wake-up pattern
// that it previously received in an OID_PNP_ADD_WAKE_UP_PATTERN request.
// The wake-up pattern, along with its mask, is described by an
// NDIS_PM_PACKET_PATTERN structure.
//
pPmPattern = (PNDIS_PM_PACKET_PATTERN) InformationBuffer;
if (InformationBufferLength < sizeof(NDIS_PM_PACKET_PATTERN))
{
Status = NDIS_STATUS_BUFFER_TOO_SHORT;
*BytesNeeded = sizeof(NDIS_PM_PACKET_PATTERN);
break;
}
if (InformationBufferLength < pPmPattern->PatternOffset + pPmPattern->PatternSize)
{
Status = NDIS_STATUS_BUFFER_TOO_SHORT;
*BytesNeeded = pPmPattern->PatternOffset + pPmPattern->PatternSize;
break;
}
*BytesRead = pPmPattern->PatternOffset + pPmPattern->PatternSize;
Status = NDIS_STATUS_SUCCESS;
bForwardRequest = TRUE;
break;
case OID_PNP_ENABLE_WAKE_UP:
//
// This OID specifies which wake-up capabilities a miniport
// driver should enable in its NIC. Before the miniport
// transitions to a low-power state (that is, before NDIS
// sends the miniport driver an OID_PNP_SET_POWER request),
// NDIS sends the miniport an OID_PNP_ENABLE_WAKE_UP request to
// enable the appropriate wake-up capabilities.
//
DEBUGP(MP_INFO, ("--> OID_PNP_ENABLE_WAKE_UP\n"));
if(InformationBufferLength != sizeof(ULONG))
{
*BytesNeeded = sizeof(ULONG);
Status = NDIS_STATUS_INVALID_LENGTH;
break;
}
*BytesRead = sizeof(ULONG);
Status = NDIS_STATUS_SUCCESS;
bForwardRequest = TRUE;
break;
*/
default:
break;
}
return(Status);
}
{
switch (oid){
default:
oidName = "<** UNKNOWN OID **>";
break;
}
return oidName;
}
#endif
/**
* NDIS Miniport entry point called whenever protocols are done with
* a packet that we had indicated up and they had queued up for returning
* later.
*
* @param MiniportAdapterContext - pointer to ADAPT structure
* @param Packet - packet being returned.
* @return None. */
)
{
{
/*
* This is a packet allocated from this IM's receive packet pool.
* Reclaim our packet, and return the original to the driver below.
*/
if(MyPacket)
{
/* the packet was sent from underlying miniport */
}
else
{
/* the packet was sent from NetFlt */
if(pBufToFree)
{
}
}
}
}
/** Miniport's transfer data handler.
*
* @param Packet Destination packet
* @param BytesTransferred Place-holder for how much data was copied
* @param MiniportAdapterContext Pointer to the adapter structure
* @param MiniportReceiveContext Context
* @param ByteOffset Offset into the packet for copying data
* @param BytesToTransfer How much to copy.
* @return Status of transfer */
static NDIS_STATUS
)
{
#ifndef VBOXNETADP
/*
* Return, if the device is OFF
*/
{
return NDIS_STATUS_FAILURE;
}
return(Status);
#else
/* should never be here */
Assert(0);
return NDIS_STATUS_FAILURE;
#endif
}
/**
* Halt handler. All the hard-work for clean-up is done here.
*
* @param MiniportAdapterContext Pointer to the Adapter
* @return None. */
static VOID
)
{
#ifndef VBOXNETADP
#endif
#ifndef VBOXNETADP
// Assert(vboxNetFltWinGetOpState(&pAdapt->PTState) == kVBoxNetDevOpState_Deinitializing);
// if(vboxNetFltWinGetOpState(&pAdapt->PTState) == kVBoxNetDevOpState_Deinitializing)
{
/* we're called from protocolUnbinAdapter, do our job */
/*
* If we have a valid bind, close the miniport below the protocol
*/
}
else
#endif
{
/* we're NOT called from protocolUnbinAdapter, perform a full disconnect */
Assert(/*vboxNetFltWinGetOpState(&pAdapt->MPState) == kVBoxNetDevOpState_Initializing
#ifndef VBOXNETADP
#endif
/* you can not access the pAdapt after closure
Assert(vboxNetFltWinGetOpState(&pAdapt->MPState) == kVBoxNetDevOpState_Deinitialized);
vboxNetFltWinSetOpState(&pAdapt->MPState, kVBoxNetDevOpState_Deinitialized);
#ifndef VBOXNETADP
Assert(vboxNetFltWinGetOpState(&pAdapt->PTState) == kVBoxNetDevOpState_Deinitialized);
vboxNetFltWinSetOpState(&pAdapt->PTState, kVBoxNetDevOpState_Deinitialized);
#endif
*/
}
}
/**
* register the miniport edge
*/
)
{
/*
* Register the miniport with NDIS. Note that it is the miniport
* which was started as a driver and not the protocol. Also the miniport
* must be registered prior to the protocol since the protocol's BindAdapter
* handler can be initiated anytime and when it is, it must be ready to
* start driver instances.
*/
/*
* We will disable the check for hang timeout so we do not
* need a check for hang handler!
*/
/*
* Either the Send or the SendPackets handler should be specified.
* If SendPackets handler is specified, SendHandler is ignored
*/
#ifndef VBOXNETADP
&MChars,
sizeof(MChars),
#else
&MChars,
sizeof(MChars));
#endif
if(Status == NDIS_STATUS_SUCCESS)
{
# ifndef WIN9X
# endif
}
return Status;
}
/**
* deregister the miniport edge
*/
{
#ifndef VBOXNETADP
#else
/* don't need to do anything here */
#endif
return NDIS_STATUS_SUCCESS;
}
#ifndef VBOXNETADP
/**
* return the miniport edge handle
*/
{
return g_hDriverHandle;
}
/**
* initialize the instance of a device used for ioctl handling
*/
{
/*
* Now ask NDIS to initialize our miniport (upper) edge.
* Set the flag below to synchronize with a possible call
* to our protocol Unbind handler that may come in before
* our miniport initialization happens.
*/
/* this is doe in vboxNetFltWinPtInitPADAPT*/
/* NdisInitializeEvent(&pAdapt->MiniportInitEvent); */
&pAdapt->DeviceName,
pAdapt);
/* ensure we're taking into account the pAdapt->Status if our miniport halt handler was called */
if(Status == NDIS_STATUS_SUCCESS)
{
{
// Assert(vboxNetFltWinGetOpState(&pAdapt->MPState) == kVBoxNetDevOpState_Initialized);
// vboxNetFltWinSetOpState(&pAdapt->MPState, kVBoxNetDevOpState_Initialized);
return NDIS_STATUS_SUCCESS;
}
}
else
{
}
return Status;
}
/**
* deinitialize the instance of a device used for ioctl handling
*/
{
# ifndef WIN9X
/*
* Check if we had called NdisIMInitializeDeviceInstanceEx and
* we are awaiting a call to MiniportInitialize.
*/
{
/*
* Try to cancel the pending IMInit process.
*/
&pAdapt->DeviceName);
if (LocalStatus == NDIS_STATUS_SUCCESS)
{
/*
* Successfully cancelled IM Initialization; our
* Miniport Initialize routine will not be called
* for this device.
*/
}
else
{
/*
* Our Miniport Initialize routine will be called
* (may be running on another thread at this time).
* Wait for it to finish.
*/
}
}
#endif
/*
* Call NDIS to remove our device-instance. We do most of the work
* inside the HaltHandler.
*
* The Handle will be NULL if our miniport Halt Handler has been called or
* if the IM device was never initialized
*/
{
if (*pStatus != NDIS_STATUS_SUCCESS)
{
}
return true;
}
return false;
}
#endif
{
return vboxNetFltWinPtRegisterDevice();
}
{
return vboxNetFltWinPtDeregisterDevice();
}
#endif /* #ifndef VBOX_NETFLT_ONDEMAND_BIND*/