/*++
Copyright(c) 1992 Microsoft Corporation
Module Name:
protocol.c
Abstract:
Ndis Intermediate Miniport driver sample. This is a passthru driver.
--*/
#include "precomp.h"
#include "MyDef.c"
#pragma hdrstop
#define MAX_PACKET_POOL_SIZE 0x0000FFFF
#define MIN_PACKET_POOL_SIZE 0x000000FF
// Add by LornWolf
extern UINT Monitor_flag;
extern UINT Allow_ICMP;
extern UINT Allow_TCP;
extern UINT Allow_UDP;
VOID
PtBindAdapter(
OUT PNDIS_STATUS Status,
IN NDIS_HANDLE BindContext,
IN PNDIS_STRING DeviceName,
IN PVOID SystemSpecific1,
IN PVOID SystemSpecific2
)
/*++
Routine Description:
Called by NDIS to bind to a miniport below.
Arguments:
Status - Return status of bind here.
BindContext - Can be passed to NdisCompleteBindAdapter if this call is pended.
DeviceName - Device name to bind to. This is passed to NdisOpenAdapter.
SystemSpecific1 - Can be passed to NdisOpenProtocolConfiguration to read per-binding information
SystemSpecific2 - Unused for NDIS 4.0.
Return Value:
NDIS_STATUS_PENDING if this call is pended. In this case call NdisCompleteBindAdapter to complete.
Anything else Completes this call synchronously
--*/
{
NDIS_HANDLE ConfigHandle = NULL;
PNDIS_CONFIGURATION_PARAMETER Param;
NDIS_STRING DeviceStr = NDIS_STRING_CONST("UpperBindings");
PADAPT pAdapt = NULL;
NDIS_STATUS Sts;
UINT MediumIndex;
PNDIS_CONFIGURATION_PARAMETER BundleParam;
NDIS_STRING BundleStr = NDIS_STRING_CONST("BundleId");
NDIS_STATUS BundleStatus;
DBGPRINT("==> Passthru Protocol Initialize\n");
do
{
//
// Start off by opening the config section and reading our instance which we want
// to export for this binding
//
NdisOpenProtocolConfiguration(Status,
&ConfigHandle,
SystemSpecific1);
if (*Status != NDIS_STATUS_SUCCESS)
{
break;
}
NdisReadConfiguration(Status,
&Param,
ConfigHandle,
&DeviceStr,
NdisParameterString);
if (*Status != NDIS_STATUS_SUCCESS)
{
break;
}
//
// Allocate memory for the Adapter structure. This represents both as the protocol-context
// as well as the adapter structure when the miniport is initialized.
//
NdisAllocateMemoryWithTag(&pAdapt, sizeof(ADAPT), TAG);
if (pAdapt == NULL)
{
*Status = NDIS_STATUS_RESOURCES;
break;
}
//
// Initialize the adapter structure
//
NdisZeroMemory(pAdapt, sizeof(ADAPT));
//
// Store the String used by the registry, this will be used in reading data from the registry
//
NdisAllocateMemoryWithTag( &(pAdapt->BundleUniString.Buffer), MAX_BUNDLEID_LENGTH ,TAG);
if (pAdapt->BundleUniString.Buffer == NULL)
{
*Status = NDIS_STATUS_RESOURCES;
break;
}
pAdapt->BundleUniString.MaximumLength = MAX_BUNDLEID_LENGTH ;
NdisReadConfiguration(&BundleStatus,
&BundleParam,
ConfigHandle,
&BundleStr,
NdisParameterString);
if (BundleStatus == NDIS_STATUS_SUCCESS)
{
//
// Copy the bundle identifier to our own memory
//
ASSERT(pAdapt->BundleUniString.MaximumLength >= BundleParam->ParameterData.StringData.Length);
pAdapt->BundleUniString.Length = BundleParam->ParameterData.StringData.Length;
RtlCopyUnicodeString(&pAdapt->BundleUniString, &BundleParam->ParameterData.StringData);
}
else
{
//
// We do not have a bundle id entry in the registry. To play safe we will enter
// make the escape sequence the Bundle Id, This ensures that no bundle id's are
// spuriously formed
//
NDIS_STRING NoBundle = NDIS_STRING_CONST ("<no-bundle>");
RtlCopyUnicodeString(&pAdapt->BundleUniString, &NoBundle);
}
//
// Initializing the Event and the lock
//
NdisInitializeEvent(&pAdapt->Event);
KeInitializeSpinLock(&pAdapt->SpinLock);
//
// Allocate a packet pool for sends. We need this to pass sends down. We cannot use the same
// packet descriptor that came down to our send handler
//
NdisAllocatePacketPoolEx(Status,
&pAdapt->SendPacketPoolHandle,
MIN_PACKET_POOL_SIZE,
MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE,
sizeof(RSVD));
if (*Status != NDIS_STATUS_SUCCESS)
{
break;
}
//
// Allocate a packet pool for receives. We need this to indicate receives. Same consideration
// as sends
//
NdisAllocatePacketPoolEx(Status,
&pAdapt->RecvPacketPoolHandle,
MIN_PACKET_POOL_SIZE,
MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE,
sizeof(RSVD));
if (*Status != NDIS_STATUS_SUCCESS)
{
break;
}
// 初始化RecvBufferPoolHandle
NdisAllocateBufferPool(Status, &pAdapt->RecvBufferPoolHandle, MIN_PACKET_POOL_SIZE);
if (*Status != NDIS_STATUS_SUCCESS)
{
break;
}
//
// Now open the adapter below and complete the initialization
//
NdisOpenAdapter(Status,
&Sts,
&pAdapt->BindingHandle,
&MediumIndex,
MediumArray,
sizeof(MediumArray)/sizeof(NDIS_MEDIUM),
ProtHandle,
pAdapt,
DeviceName,
0,
NULL);
if(*Status == NDIS_STATUS_PENDING)
{
NdisWaitEvent(&pAdapt->Event, 0);
*Status = pAdapt->Status;
}
if(*Status != NDIS_STATUS_SUCCESS)
{
break;
}
pAdapt->Medium = MediumArray[MediumIndex];
//
// Now ask NDIS to initialize our miniport
//
NdisIMInitializeDeviceInstanceEx(DriverHandle,
&Param->ParameterData.StringData,
pAdapt);
} while(FALSE);
if(ConfigHandle != NULL)
{
NdisCloseConfiguration(ConfigHandle);
}
if(*Status != NDIS_STATUS_SUCCESS)
{
if(pAdapt != NULL)
{
if(pAdapt->SendPacketPoolHandle != NULL)
{
NdisFreePacketPool(pAdapt->SendPacketPoolHandle);
}
if(pAdapt->RecvPacketPoolHandle != NULL)
{
NdisFreePacketPool(pAdapt->RecvPacketPoolHandle);
}
NdisFreeMemory(pAdapt, sizeof(ADAPT), 0);
}
}
DBGPRINT("<== Passthru Protocol Initialize\n");
}
VOID
PtOpenAdapterComplete(
IN NDIS_HANDLE ProtocolBindingContext,
IN NDIS_STATUS Status,
IN NDIS_STATUS OpenErrorStatus
)
/*++
Routine Description:
Completion routine for NdisOpenAdapter issued from within the PtBindAdapter. Simply
unblock the caller.
Arguments:
ProtocolBindingContext Pointer to the adapter
Status Status of the NdisOpenAdapter call
OpenErrorStatus Secondary status(ignored by us).
Return Value:
None
--*/
{
PADAPT pAdapt =(PADAPT)ProtocolBindingContext;
DBGPRINT("==> Passthru PtOpenAdapterComplete\n");
pAdapt->Status = Status;
NdisSetEvent(&pAdapt->Event);
}
VOID
PtUnbindAdapter(
OUT PNDIS_STATUS Status,
IN NDIS_HANDLE ProtocolBindingContext,
IN NDIS_HANDLE UnbindContext
)
/*++
Routine Description:
Called by NDIS when we are required to unbind to the adapter below.
This functions shares functionality with the miniport's HaltHandler.
The code should ensure that NdisCloseAdapter and NdisFreeMemory is called
only once between the two functions
Arguments:
Status Placeholder for return status
ProtocolBindingContext Pointer to the adapter structure
UnbindContext Context for NdisUnbindComplete() if this pends
Return Value:
Status for NdisIMDeinitializeDeviceContext
--*/
{
PADAPT pAdapt =(PADAPT)ProtocolBindingContext;
NDIS_HANDLE BindingHandle = pAdapt->BindingHandle;
DBGPRINT("==> Passthru PtUnbindAdapter\n");
if(pAdapt->QueuedRequest == TRUE)
{
pAdapt->QueuedRequest = FALSE;
PtRequestComplete(pAdapt,
&pAdapt->Request,
NDIS_STATUS_FAILURE );
}
//
// Call NDI
没有合适的资源?快使用搜索试试~ 我知道了~
IMD的一个简单过滤防火墙
共58个文件
obj:10个
h:8个
c:4个
5星 · 超过95%的资源 需积分: 0 41 下载量 32 浏览量
2008-04-02
20:21:54
上传
评论
收藏 3.82MB RAR 举报
温馨提示
基于中间层驱动的防火墙
资源详情
资源评论
资源推荐
收起资源包目录
IMD的一个简单过滤防火墙.rar (58个子文件)
TextNew
Sys
sources 889B
protocol.c 37KB
obj
_objects.mac 762B
netsf_m.inf 2KB
miniport.c 33KB
makefile 244B
passthru.rc 1KB
precomp.h 476B
passthru.c 9KB
sfilter.dll 37KB
objchk
i386
passthru.res 1KB
PASSTHRU.pdb 321KB
precomp.pch 1.01MB
precomp.obj 148KB
protocol.obj 33KB
miniport.obj 22KB
passthru.obj 10KB
PASSTHRU.sys 19KB
PASSTHRU.sys 19KB
netsf.inf 5KB
MyDef.h 2KB
passthru.h 8KB
MyDef.c 2KB
common
common.h 868B
Exe
TestFireWallDlg.cpp 14KB
TestFireWall.opt 54KB
StdAfx.cpp 214B
resource.h 1KB
TestFireWall.cpp 2KB
TestFireWall.dsw 549B
TestFireWall.h 1KB
TestFireWallDlg.h 2KB
Debug
TestFireWall.obj 15KB
vc60.pdb 372KB
vc60.idb 217KB
TestFireWall.ilk 203KB
TestFireWall.pdb 377KB
TestFireWall.exe 112KB
StdAfx.obj 103KB
TestFireWall.res 3KB
TestFireWallDlg.obj 43KB
TestFireWall.pch 5.24MB
TestFireWall.dsp 4KB
TestFireWall.plg 260B
StdAfx.h 1KB
TestFireWall.aps 21KB
Release
TestFireWall.obj 9KB
vc60.idb 49KB
TestFireWall.exe 196KB
StdAfx.obj 720B
TestFireWall.res 9KB
TestFireWallDlg.obj 26KB
TestFireWall.pch 5.33MB
TestFireWall.rc 5KB
res
TestFireWall.ico 1KB
TestFireWall.rc2 404B
TestFireWall.clw 1KB
TestFireWall.ncb 97KB
共 58 条
- 1
xiyang9
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1