//////////////////////////////////////////////////////////////////////
// filterAdap.cpp: implementation of the filterAdapter class.
//
// Generated by Network Driver Wizard on Friday, February 06, 2004
//
#include "filterBind.h"
#include "filterAdap.h"
//////////////////////////////////////////////////////////////////////
// Constructor
filterAdapter::filterAdapter()
{
// TODO: initialize your private data members
// Do NOT call any NDIS functions in here. Defer to Initialize()
}
//////////////////////////////////////////////////////////////////////
// Destructor
filterAdapter::~filterAdapter()
{
// TODO: deallocate all the resources allocated in constructor/Initialize()
//
}
////////////////////////////////////////////////////////////////////
// NDIS callback handlers
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// filterAdapter::OnInitialize
// 当一个虚拟NIC被创建时,调用此成员函数。此时已经完成对底层物理NIC的邦定
// 大部分工作系统已经完成,用户可以在此检查媒介类型,以可以设置私有成员变量
//参数:
// Medium
// Reference to the KNdisMedium object which has a medium type
// selected for the underlying binding by the real NIC
// Config
// Reference to miniport's KNdisConfig object used to query various
// configuration parameters
//
// Return
// NDIS_STATUS_SUCCESS Proceed with the creation of the filter
// NDIS_STATUS_XXXXXXX Error. The framework rolls back and fails the
// miniport initialization.
// IRQL:
// PASSIVE_LEVEL
// Return Mode:
// Synchronous
//
NDIS_STATUS filterAdapter::OnInitialize
(const KNdisMedium& Medium, KNdisConfig& Config)
{
TRACE("filterAdapter::OnInitialize(): %s at %ws\n", Medium.Text(), GetBoundDeviceName());
//注册
KNdisBundle::Register(this, GetBundle());
UNREFERENCED_PARAMETER(Config);
return NDIS_STATUS_SUCCESS;
}
////////////////////////////////////////////////////////////////////
// filterAdapter::OnHalt
//
// Either virtual NIC or underlying binding is being destroyed by NDIS
// Not much can we do here.
//
VOID filterAdapter::OnHalt()
{
TRACE("filterAdapter::OnHalt()\n");
// 撤销邦定
KNdisBundle::Deregister(this, GetBundle());
// TODO: deinit private members
}
////////////////////////////////////////////////////////////////////
// filterAdapter::OnSend
//
// 处理发送网络封包.这里过滤驱动对输出的网络封包进行处理 ,
// 过滤驱动检查协议封包,如果需要则对其进行更改,或者丢弃。处理工程是
// 先对原始封包进行拷贝,然后分析拷贝对其处理后返回。如果需要处理多个封包,
// 需要拥有封包池,并且指定完成列程OnSendComplete()指针
// Parameters:
// Original - NDIS提供的原始封包
// Repackaged - 驱动程序对原始封包进行处理后的封包
//
// OnSend() is returned:
// NDIS_STATUS_SUCCESS Requests the framework to forward the
// Repackaged packet down the binding
// NDIS_STATUS_NOT_ACCEPTED Send nothing. Release resources and Return NDIS_STATUS_SUCCESS to NDIS
// NDIS_STATUS_PENDING Do nothing, Recycle nothing. Return NDIS_STATUS_PENDING to NDIS
// NDIS_STATUS_XXX ramework after
NDIS_STATUS filterAdapter::OnSend
(const KNdisPacket& Original, KNdisPacket& Repackaged)
{
TRACE("filterAdapter::OnSend() %u bytes\n", Original.QueryTotalLength());
TRACE("对封包进行发送过滤");
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
//拷贝封包 对Repackaged封包进行处理
//此处我们不作处理,屏蔽一切发送的封包
// Repackaged.CloneDown(Original);
KNdisFilterAdapter* pSecondary = GetBundleAdapter(1);
if (pSecondary == NULL) // no bundle: just forward down
return NDIS_STATUS_SUCCESS;
Status = pSecondary->ForwardDown(Repackaged, this);
if (Status == NDIS_STATUS_SUCCESS)
return NDIS_STATUS_NOT_ACCEPTED;
return Status;
}
////////////////////////////////////////////////////////////////////
// filterAdapter::OnReceive
// 底层封包接受,这里对来自NIC的封包进行过滤。过滤驱动在此对封包进行处理。
// 可以检查来自NIC的封包,对其进行拷贝 更改 或者 丢弃。驱动程序提供一个新
// 的,经过处理的封传递给目标通讯协议。如果过滤驱动需要一系列封包,需要建立
// 一个封包池用来保存封包
//
//
// 参数:
// Original - 通过NIC的封包对象
// Repackaged - 改变后的封包对象
// 返回值:返回值决定着驱动程序后继的行为,其返回值如下:
//
// NDIS_STATUS_SUCCESS 成功返回,驱动将新的封包传递个对应的协议
// NDIS_STATUS_NOT_ACCEPTED 驱动程序释放资源并向NDIS返回 NDIS_STATUS_SUCCESS
// NDIS_STATUS_XXX 什么也没有做 ,直接返回
NDIS_STATUS filterAdapter::OnReceive
(const KNdisPacket& Original, KNdisPacket& Repackaged)
{
TRACE("filterAdapter::OnReceive() %u bytes\n", Original.QueryTotalLength());
TRACE("在此处对封包进行接受过滤");
// TODO: 对封包的进行过滤, 比如
// HEADER* Content = (HEADER*) Original.QueryFirstBuffer();
// . . .
// 拷贝封包,对其进行处理
// 此处我们对接受到封包全部过滤
//Repackaged.CloneUp(Original);
// LBFO Support:
// This *sample* demonstrates an implementation of a balance loading scenario.
// Although the receives can be coming from all bundled adapters, we should use
// only primary one to indicate the packet to NDIS
KNdisFilterAdapter* pPrimary = (GetBundle()) ? GetBundleAdapter(0) : NULL;
if (pPrimary) { // bundle available
// Use the primary adapter to pass the packet up to NDIS.
// Note we pass 'this' as "originating" instance pointer. It will be
// used for proper recycling of packet descriptors by the framework
pPrimary->ForwardUp(Repackaged, this);
// Note the special return code we use to tell the framework do NOT forward
// the packet up over the normal binding but rather just recycle it
return NDIS_STATUS_NOT_ACCEPTED;
}
else
return NDIS_STATUS_SUCCESS;
}
///////////////////////////////////////////////////////////////////////
// filterAdapter::OnReceive (partial)
//
// Parameters:
// PacketToAccept - Non-initialized packet descriptor
// HeaderBuffer - Header pointer
// HeaderBufferSize - Header size being indicated
// LookAheadBuffer - Lookahead buffer pointer
// LookaheadBufferSize - Lookahead size being indicated
// PacketSize - Total packet size (not including the header)
// Returns:
// The return value determines the behaviour of the framework after
// OnReceive() is returned:
// NDIS_STATUS_SUCCESS Requests the framework to forward the
// Repackaged packet up to the protocols
// NDIS_STATUS_NOT_ACCEPTED Forward nothing. Release resources and Return NDIS_STATUS_SUCCESS to NDIS
// NDIS_STATUS_XXX Do nothing. Retutn this status to NDIS.
// Comments:
//
NDIS_STATUS filterAdapter::OnReceive(IN OUT KNdisPartialPacket& PacketToAccept,
IN PVOID HeaderBuffer, IN UINT HeaderBufferSize,
IN PVOID LookAheadBuffer, IN UINT LookaheadBufferSize,
IN UINT PacketSize)
{
TRACE("filterAdapter::OnReceive() Partial %u/%u%/%u bytes\n",
HeaderBufferSize, LookaheadBufferSize, PacketSize);
UNREFERENCED_PARAMETER(PacketToAccept);
// LBFO Support:
// This *sample* demonstrates an implementation of a balance loading scenario.
// Although the receives can be coming from all bundled adapters, we should use
// only primary one to indicate the data to NDIS
KNdisFilterAdapter* pPrimary = (GetBundle()) ? GetBundleAdapter(0) : NULL;
if (pPrimary) { // bundle available
// Use the primary adapter to pass the indication up to NDIS.
// Note we pass the original lower miniport context to later
// restore it for TransferData
pPrimary->ForwardUp(PacketToAccept.MacReceiveContext(),
HeaderBuffer, HeaderBufferSize,
LookAheadBuffer, LookaheadBufferSize, PacketSize,
this);
// Note the special return code we use to tell the framework do NOT forward
// the indica
- 1
- 2
- 3
前往页