/********************************************************************
Copyright (C) 2005
File Name: DriverEntry.cpp
Created Date: 2005-06-23
Author: XuWenTao
Version: 1.0
Last Version Date:
Version Date:
*******************************************************************/
#include "inc.h"
#include "head.h"
//#include "initguid.h"
//#include "guid.h"
#define DEVICE_NAME L"\\Device\\FirstIM"
#define SYMBOLIC_LINK_NAME L"\\DosDevices\\FirstIM"
#define ETH_TYPE 0x0008 //IP관0x0008 ARP관0x0608 RARP관0x3580 0x8e88
#define NUIO_8021P_TAG_TYPE 0x0081
//
VOID DriverUnload(IN PDRIVER_OBJECT fdo);
NTSTATUS DispatchCreate(IN PDEVICE_OBJECT fdo,IN PIRP Irp);
NTSTATUS DispatchClose(IN PDEVICE_OBJECT fdo,IN PIRP Irp);
NTSTATUS DispatchRead(IN PDEVICE_OBJECT fdo,IN PIRP Irp);
NTSTATUS DispatchWrite(IN PDEVICE_OBJECT fdo,IN PIRP Irp);
NTSTATUS DispatchDeviceControl(IN PDEVICE_OBJECT fdo,IN PIRP Irp);
void ReleaseNode(PACKETNODE *node);
void ProtocolBindAdapter(OUT PNDIS_STATUS Status,IN NDIS_HANDLE BindContext,IN PNDIS_STRING DeviceName,
IN PVOID SystemSpecific1,
IN PVOID SystemSpecific2
)
/*++
Routine Description:
Protocol Bind Handler entry point called when NDIS wants us
to bind to an adapter. We go ahead and set up a binding.
An OPEN_CONTEXT structure is allocated to keep state about
this binding.
Arguments:
pStatus - place to return bind status
BindContext - handle to use with NdisCompleteBindAdapter
DeviceName - adapter to bind to
SystemSpecific1 - used to access protocol-specific registry key for this binding
SystemSpecific2 - unused
Return Value:
None
--*/
{
DbgPrint("ProtocolBindAdapter start\n");
NDIS_HANDLE ConfigHandle = NULL;
PNDIS_CONFIGURATION_PARAMETER Param;
NDIS_STRING DeviceStr = NDIS_STRING_CONST("UpperBindings");
PADAPT pAdapt = NULL;
NDIS_STATUS Sts;
UINT MediumIndex;
ULONG TotalSize;
PNDIS_CONFIGURATION_PARAMETER BundleParam;
NDIS_STRING BundleStr = NDIS_STRING_CONST("BundleId");
NDIS_STATUS BundleStatus;
do
{
// Access the configuration section for our binding-specific parameters.
NdisOpenProtocolConfiguration(Status,&ConfigHandle,(PNDIS_STRING)SystemSpecific1);
if (*Status != NDIS_STATUS_SUCCESS)
{
break;
}
// Read the "UpperBindings" reserved key that contains a list
// of device names representing our miniport instances corresponding
// to this lower binding. Since this is a 1:1 IM driver, this key
// contains exactly one name.
//
// If we want to implement a N:1 mux driver (N adapter instances
// over a single lower binding), then UpperBindings will be a
// MULTI_SZ containing a list of device names - we would loop through
// this list, calling NdisIMInitializeDeviceInstanceEx once for
// each name in it.
NdisReadConfiguration(Status,&Param,ConfigHandle,&DeviceStr,NdisParameterString);
if (*Status != NDIS_STATUS_SUCCESS)
{
break;
}
// Allocate memory for the Adapter structure. This represents both the
// protocol context as well as the adapter structure when the miniport
// is initialized.
//
// In addition to the base structure, allocate space for the device
// instance string.
//
TotalSize = sizeof(ADAPT) + Param->ParameterData.StringData.MaximumLength;
NdisAllocateMemoryWithTag((PVOID *)&pAdapt, TotalSize, TAG);
if (pAdapt == NULL)
{
*Status = NDIS_STATUS_RESOURCES;
break;
}
//
// Initialize the adapter structure. We copy in the IM device
// name as well, because we may need to use it in a call to
// NdisIMCancelInitializeDeviceInstance. The string returned
// by NdisReadConfiguration is active (i.e. available) only
// for the duration of this call to our BindAdapter handler.
//
NdisZeroMemory(pAdapt, TotalSize);
pAdapt->DeviceName.MaximumLength = Param->ParameterData.StringData.MaximumLength;
pAdapt->DeviceName.Length = Param->ParameterData.StringData.Length;
pAdapt->DeviceName.Buffer = (PWCHAR)((ULONG_PTR)pAdapt + sizeof(ADAPT));
NdisMoveMemory(pAdapt->DeviceName.Buffer,
Param->ParameterData.StringData.Buffer,
Param->ParameterData.StringData.MaximumLength);
DbgPrint("DeviceName(UpperBindings) is %ws\n",pAdapt->DeviceName.Buffer);
DbgPrint("DeviceName is %ws\n",DeviceName->Buffer);
NdisInitializeEvent(&pAdapt->Event);
//
// 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 (see also NDIS 5.1 packet stacking).
//
NdisAllocatePacketPoolEx(Status,
&pAdapt->SendPacketPoolHandle,
MIN_PACKET_POOL_SIZE,
MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE,
sizeof(SEND_RSVD));
if (*Status != NDIS_STATUS_SUCCESS)
{
break;
}
//
// Allocate a packet pool for receives. We need this to indicate receives.
// Same consideration as sends (see also NDIS 5.1 packet stacking).
//
NdisAllocatePacketPoolEx(Status,
&pAdapt->RecvPacketPoolHandle,
MIN_PACKET_POOL_SIZE,
MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE,
PROTOCOL_RESERVED_SIZE_IN_PACKET);
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;
NdisResetEvent(&pAdapt->Event);
}
if (*Status != NDIS_STATUS_SUCCESS)
{
break;
}
pAdapt->Medium = MediumArray[MediumIndex];
//
// 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.
//
pAdapt->MiniportInitPending = TRUE;
NdisInitializeEvent(&pAdapt->MiniportInitEvent);
*Status = NdisIMInitializeDeviceInstanceEx(DriverHandle,&pAdapt->DeviceName,pAdapt);
if (*Status != NDIS_STATUS_SUCCESS)
{
break;
}
} while(FALSE);
//
// Close the configuration handle now - see comments above with
// the call to NdisIMInitializeDeviceInstanceEx.
//
if (ConfigHandle != NULL)
{
NdisCloseConfiguration(ConfigHandle);
}
if (*Status != NDIS_STATUS_SUCCESS)
{
if (pAdapt != NULL)
{
if (pAdapt->BindingHandle != NULL)
{
NDIS_STATUS LocalStatus;
// Close the binding we opened above.
NdisCloseAdapter(&LocalStatus, pAdapt->BindingHandle);
pAdapt->BindingHandle = NULL;
if (LocalStatus == NDIS_STATUS_PENDING)
{
NdisWaitEvent(&pAdapt->Event, 0);
LocalStatus = pAdapt->Status;
NdisResetEvent(&pAdapt->Event);
}
}
if (pAdapt->SendPacketPoolHandle != NULL)
{
NdisFreePacketPool(pAdapt->SendPacketPoolHandle);
}
if (pAdapt->RecvPacketPoolHandle != NULL)
{
NdisFreePacketPool(pAdapt->RecvPacketPoolHandle);
}
NdisFreeMemory(pAdapt, sizeof(ADAPT), 0);
pAdapt = NULL;
}
}
}
void ProtocolOpenAdapterComplete(IN NDIS_HANDLE ProtocolBindingContext,IN NDIS_STATUS Status,IN NDIS_STATUS OpenErrorCode)
{
PADAPT pAdapt =(PADAPT)ProtocolBindingContext;
pAdapt->Status = Status;
NdisSetEvent(&pAdapt->Event);
}
void ProtocolCloseAdapterComplete(IN NDIS_HANDLE ProtocolBindingContext,IN NDIS_STATUS Status)
{
PADAPT pAdapt =(PADAPT)ProtocolBindingContext;
pAdapt->Status = Status;
NdisSetE
没有合适的资源?快使用搜索试试~ 我知道了~
驱动开发例子c++1111
共20个文件
inf:4个
h:2个
log:1个
需积分: 0 21 下载量 153 浏览量
2008-10-06
20:05:29
上传
评论
收藏 104KB RAR 举报
温馨提示
驱动 开发 例子,c语言的写的例子。驱动 开发 例子,c语言的写的例子。
资源详情
资源评论
资源推荐
收起资源包目录
FirstIM.rar (20个子文件)
sources 509B
head.h 5KB
DriverEntry.cpp 80KB
obj
i386
_objects.mac 241B
netsf_m.inf 2KB
objfre
i386
netsf_m.inf 2KB
FirstIM.pdb 115KB
driverentry.obj 107KB
FirstIM.sys 10KB
FirstIM.sym 5KB
FirstIM.map 11KB
netsf.inf 6KB
inc.h 567B
vssver.scc 208B
FirstIM.vcproj 4KB
makefile 244B
MakeDrvr.bat 436B
free
BuildLog.htm 2KB
buildfre.log 2KB
netsf.inf 6KB
共 20 条
- 1
pzou9330
- 粉丝: 0
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0