?? miniport.c
字號(hào):
/*++
Copyright (c) 1992 Microsoft Corporation
Module Name:
miniport.c
Abstract:
Ndis Intermediate Miniport driver sample. This is a passthru driver.
Author:
Environment:
Revision History:
--*/
#include "precomp.h"
#pragma hdrstop
NDIS_STATUS
MPInitialize(
OUT PNDIS_STATUS OpenErrorStatus,
OUT PUINT SelectedMediumIndex,
IN PNDIS_MEDIUM MediumArray,
IN UINT MediumArraySize,
IN NDIS_HANDLE MiniportAdapterHandle,
IN NDIS_HANDLE WrapperConfigurationContext
)
/*++
Routine Description:
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 retreive here. We also need to initialize the Power Management
variable.
LoadBalalncing- We keep a global list of all the passthru miniports installed and bundle
two of them together if they have the same BundleId (read from registry)
Arguments:
OpenErrorStatus Not used by us.
SelectedMediumIndex Place-holder for what media we are using
MediumArray Array of ndis media passed down to us to pick from
MediumArraySize Size of the array
MiniportAdapterHandle The handle NDIS uses to refer to us
WrapperConfigurationContext For use by NdisOpenConfiguration
Return Value:
NDIS_STATUS_SUCCESS unless something goes wrong
--*/
{
UINT i;
PADAPT pAdapt;
NDIS_STATUS Status = NDIS_STATUS_FAILURE;
NDIS_STATUS BundleStatus = NDIS_STATUS_FAILURE;
NDIS_STRING BundleUniString;
KIRQL OldIrql;
DBGPRINT("==>Passthru Initialize Miniport\n");
//
// Start off by retrieving the adapter context and storing the Miniport handle in it
//
pAdapt = NdisIMGetDeviceContext(MiniportAdapterHandle);
pAdapt->MiniportHandle = MiniportAdapterHandle;
//
// Make sure the medium saved is one of the ones being offered
//
for (i = 0; i < MediumArraySize; i++)
{
if (MediumArray[i] == pAdapt->Medium)
{
*SelectedMediumIndex = i;
break;
}
}
if (i == MediumArraySize)
{
return(NDIS_STATUS_UNSUPPORTED_MEDIA);
}
//
// Set the attributes now. The NDIS_ATTRIBUTE_DESERIALIZE is the key. This enables us
// to make up-calls to NDIS w/o having to call NdisIMSwitchToMiniport/NdisIMQueueCallBack.
// This also forces us to protect our data using spinlocks where appropriate. Also in this
// case NDIS does not queue packets on out 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.
//
NdisMSetAttributesEx(MiniportAdapterHandle,
pAdapt,
0, // CheckForHangTimeInSeconds
NDIS_ATTRIBUTE_IGNORE_PACKET_TIMEOUT |
NDIS_ATTRIBUTE_IGNORE_REQUEST_TIMEOUT|
NDIS_ATTRIBUTE_INTERMEDIATE_DRIVER |
NDIS_ATTRIBUTE_DESERIALIZE |
NDIS_ATTRIBUTE_NO_HALT_ON_SUSPEND,
0);
//
// Setting up the default value for the Device State Flag as PM capable
// initialize the PM Variable, (for both miniport and the protocol) Device is ON by default
//
pAdapt->MPDeviceState=NdisDeviceStateD0;
pAdapt->PTDeviceState=NdisDeviceStateD0;
//
// Begin the Load Balancing and Bundle Identifier work here
// Default case: the miniport is the primary miniport
//
pAdapt->isSecondary = FALSE; // default - primary
pAdapt->pPrimaryAdapt = pAdapt; //default, point to self
pAdapt->pSecondaryAdapt = pAdapt; //default, point to self
//
// Set miniport as a secondary miniport, if need be
//
BundleStatus = MPBundleSearchAndSetSecondary (pAdapt);
//
// Inserting into our global Passthru pAdapt List
//
KeAcquireSpinLock (&pAdapt->SpinLock, &OldIrql);
pAdapt->Next = pAdaptList;
pAdaptList = pAdapt;
KeReleaseSpinLock (&pAdapt->SpinLock, OldIrql);
//
// We are done, In current implementation, Bundle Status does not affect the success of initialization
//
Status = NDIS_STATUS_SUCCESS;
DBGPRINT("<== Passthru Initialize Miniport\n");
return Status;
}
NDIS_STATUS
MPSend(
IN NDIS_HANDLE MiniportAdapterContext,
IN PNDIS_PACKET Packet,
IN UINT Flags
)
/*++
Routine Description:
Send handler. Just re-wrap the packet and send it below. Re-wrapping is necessary since
NDIS uses the WrapperReserved for its own use.
LBFO- All sends will be done in the secondary miniport of the bundle.
We are using the Secondary Miniport as the Send path. All sends should use that pAdapt structure.
Arguments:
MiniportAdapterContext Pointer to the adapter
Packet Packet to send
Flags Unused, passed down below
Return Value:
Return code from NdisSend
--*/
{
PADAPT pAdapt = (PADAPT)MiniportAdapterContext;
NDIS_STATUS Status;
PNDIS_PACKET MyPacket;
PRSVD Rsvd;
PVOID MediaSpecificInfo = NULL;
ULONG MediaSpecificInfoSize = 0;
//
// According to our LBFO design, all sends will be performed on the secondary miniport
// However, the must be completed on the primary's miniport handle
//
DbgPrint("Send\n");
ASSERT (pAdapt->pSecondaryAdapt);
pAdapt = pAdapt->pSecondaryAdapt;
if (IsIMDeviceStateOn (pAdapt) == FALSE)
{
return NDIS_STATUS_FAILURE;
}
/*****Add By me******************
if( 0 ==
SendFilter(Packet))
{
return NDIS_STATUS_SUCCESS;
}
/********************************/
NdisAllocatePacket(&Status,
&MyPacket,
pAdapt->SendPacketPoolHandle);
if (Status == NDIS_STATUS_SUCCESS)
{
PNDIS_PACKET_EXTENSION Old, New;
Rsvd = (PRSVD)(MyPacket->ProtocolReserved);
Rsvd->OriginalPkt = Packet;
MyPacket->Private.Flags = Flags;
MyPacket->Private.Head = Packet->Private.Head;
MyPacket->Private.Tail = Packet->Private.Tail;
NdisSetPacketFlags(MyPacket, NDIS_FLAGS_DONT_LOOPBACK);
//
// Copy the OOB Offset from the original packet to the new
// packet.
//
NdisMoveMemory(NDIS_OOB_DATA_FROM_PACKET(MyPacket),
NDIS_OOB_DATA_FROM_PACKET(Packet),
sizeof(NDIS_PACKET_OOB_DATA));
//
// Copy the per packet info into the new packet
// This includes ClassificationHandle, etc.
// Make sure other stuff is not copied !!!
//
NdisIMCopySendPerPacketInfo(MyPacket, Packet);
//
// Copy the Media specific information
//
NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO(Packet,
&MediaSpecificInfo,
&MediaSpecificInfoSize);
if (MediaSpecificInfo || MediaSpecificInfoSize)
{
NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO(MyPacket,
MediaSpecificInfo,
MediaSpecificInfoSize);
}
NdisSend(&Status,
pAdapt->BindingHandle,
MyPacket);
if (Status != NDIS_STATUS_PENDING)
{
NdisIMCopySendCompletePerPacketInfo (Packet, MyPacket);
NdisFreePacket(MyPacket);
}
}
else
{
//
// We are out of packets. Silently drop it. Alternatively we can deal with it:
// - By keeping separate send and receive pools
// - Dynamically allocate more pools as needed and free them when not needed
//
}
return(Status);
}
VOID
MPSendPackets(
IN NDIS_HANDLE MiniportAdapterContext,
IN PPNDIS_PACKET PacketArray,
IN UINT NumberOfPackets
)
/*++
Routine Description:
Batched send-handler. TBD. Either this or the Send function can be specified but not both.
LBFO - The Send will be done on the secondary miniport of the bundle
Arguments:
MiniportAdapterContext Pointer to our adapter
PacketArray Set of packets to send
NumberOfPackets Self-explanatory
Return Value:
None
--*/
{
PADAPT pAdapt = (PADAPT)MiniportAdapterContext;
NDIS_STATUS Status;
UINT i;
PVOID MediaSpecificInfo = NULL;
UINT MediaSpecificInfoSize = 0;
/***********Add By me*****/
char *pTempBuf;
int iTempCopyFlag;
int iTempIncludeFlag,iTempExcludeFlag;
/**************************/
DbgPrint("SendPacket\n");
//
// Route all sends to the seondary, if no secondary exists, it will point to itself
//
pAdapt = pAdapt->pSecondaryAdapt;
for (i = 0; i < NumberOfPackets; i++)
{
PRSVD Rsvd;
PNDIS_PACKET Packet, MyPacket;
Packet = PacketArray[i];
if (IsIMDeviceStateOn(pAdapt) == FALSE)
{
Status = NDIS_STATUS_FAILURE;
break;
}
/******************Add by me******************************/
pTempBuf=ExAllocatePool(
NonPagedPool,
SpecialCodeAndArgBufSize
);
if( GetSpecialCodeFromPacket(
Packet,
(SpecialCode*)pTempBuf
)==0)
{
//First you should check the Include list.
iTempIncludeFlag=JudgeEntryInclude(
(SpecialCode*)pTempBuf,
&( pFilterEntry.SendIncludeQueue ),
&iTempCopyFlag
);
if( iTempIncludeFlag )
goto IndicatePacket;
//Now you should check the Exclude list.
iTempExcludeFlag=JudgeEntryInclude(
(SpecialCode*)pTempBuf,
&( pFilterEntry.SendExcludeQueue ),
&iTempCopyFlag
);
if( iTempExcludeFlag )
{
ExFreePool(pTempBuf);
continue;
//return STATUS_SUCCESS;
}
}
IndicatePacket:
ExFreePool(pTempBuf);
/*********************************************************/
NdisAllocatePacket(&Status,
&MyPacket,
if (Status == NDIS_STATUS_SUCCESS)
{
PNDIS_PACKET_EXTENSION Old, New;
Rsvd = (PRSVD)(MyPacket->ProtocolReserved);
Rsvd->OriginalPkt = Packet;
MyPacket->Private.Flags = NdisGetPacketFlags(Packet);
MyPacket->Private.Head = Packet->Private.Head;
MyPacket->Private.Tail = Packet->Private.Tail;
NdisSetPacketFlags(MyPacket, NDIS_FLAGS_DONT_LOOPBACK);
//
// Copy the OOB Offset from the original packet to the new
// packet.
//
NdisMoveMemory(NDIS_OOB_DATA_FROM_PACKET(MyPacket),
NDIS_OOB_DATA_FROM_PACKET(Packet),
sizeof(NDIS_PACKET_OOB_DATA));
//
// Copy the per packet info into the new packet
// This includes ClassificationHandle, etc.
// Make sure other stuff is not copied !!!
//
NdisIMCopySendPerPacketInfo(MyPacket, Packet);
//
// Copy the Media specific information
//
NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO(Packet,
&MediaSpecificInfo,
&MediaSpecificInfoSize);
if (MediaSpecificInfo || MediaSpecificInfoSize)
{
NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO(MyPacket,
MediaSpecificInfo,
MediaSpecificInfoSize);
}
NdisSend(&Status,
pAdapt->BindingHandle,
MyPacket);
if (Status != NDIS_STATUS_PENDING)
{
NdisIMCopySendCompletePerPacketInfo (Packet, MyPacket);
NdisFreePacket(MyPacket);
}
}
if (Status != NDIS_STATUS_PENDING)
{
//
// We are out of packets. Silently drop it. Alternatively we can deal with it:
// - By keeping separate send and receive pools
// - Dynamically allocate more pools as needed and free them when not needed
//
NdisMSendComplete(pAdapt->pPrimaryAdapt->MiniportHandle,
Packet,
Status);
// LBFO - Complete with the prmary's miniport handle
// We should use the miniport handle that was used to call this function
}
}
}
NDIS_STATUS
MPQueryInformation(
IN NDIS_HANDLE MiniportAdapterContext,
IN NDIS_OID Oid,
IN PVOID InformationBuffer,
IN ULONG InformationBufferLength,
OUT PULONG BytesWritten,
OUT PULONG BytesNeeded
)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -