wengyu100
驱动牛犊
驱动牛犊
  • 注册日期2003-10-10
  • 最后登录2006-10-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1530回复:6

80求两段源码!

楼主#
更多 发布于:2003-12-11 15:20
最近在学passthru与应用层通讯
所以求:
1、xp的passthru(听说有通讯)
2。老胡的源码 (有NdisMregisteDevice的那段源码,最好完整点,有应用层的,没有也不强求)
谢谢
wxl_50685330
论坛版主
论坛版主
  • 注册日期2002-11-19
  • 最后登录2018-09-25
  • 粉丝0
  • 关注0
  • 积分1000分
  • 威望521点
  • 贡献值0点
  • 好评度419点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-12-11 16:01
ndis里面创建设备可以给你一个参考,测试过,工作正常
#include \"prexsim.h\"
#pragma hdrstop


//UNICODE_STRING symLinkName;

/*――――――――――――――――――――――――――――――――――――――
用NDIS_INIT_FUNCTION宏标识DriverEntry函数只运行一次
*/
#pragma NDIS_INIT_FUNCTION(DriverEntry)

//////
#define LINKNAME_STRING L\"\\\\DosDevices\\\\xpassthru\"
#define NTDEVICE_STRING L\"\\\\Device\\\\xpassthru\"
NDIS_HANDLE NdisDeviceHandle = NULL;
PDEVICE_OBJECT ControlDeviceObject = NULL;
enum _DEVICE_STATE
{
PS_DEVICE_STATE_READY = 0, // ready for create/delete
PS_DEVICE_STATE_CREATING, // create operation in progress
PS_DEVICE_STATE_DELETING // delete operation in progress
} ControlDeviceState = PS_DEVICE_STATE_READY;
NDIS_SPIN_LOCK GlobalLock;//, mypacketlock;
LONG            MiniportCount = 0;

//////

NDIS_PHYSICAL_ADDRESS HighestAcceptableMax \\
= NDIS_PHYSICAL_ADDRESS_CONST(-1, -1);
NDIS_HANDLE ProtHandle = NULL;
NDIS_HANDLE DriverHandle = NULL;
NDIS_MEDIUM MediumArray[3] =
{
NdisMedium802_3, // Ethernet
NdisMedium802_5, // Token-ring
NdisMediumFddi // Fddi
};
PADAPT pAdaptList = NULL;
NDIS_HANDLE WrapperHandle = NULL;

NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
NDIS_STATUS Status;
PNDIS_CONFIGURATION_PARAMETER Param;
 
DBGPRINT(\"==> DriverEntry...\\n\");
NdisAllocateSpinLock(&GlobalLock);
// NdisAllocateSpinLock(&mypacketlock);

NdisInitializeEvent(& FULLEVENT);
NdisInitializeEvent(& EMPTYEVENT);
NdisResetEvent(&FULLEVENT);
NdisResetEvent(&EMPTYEVENT);


NdisMInitializeWrapper(&WrapperHandle, DriverObject, RegistryPath, NULL);

Status = MPRegisterAsMiniport(DriverObject, RegistryPath);
ASSERT(Status == NDIS_STATUS_SUCCESS);

NdisMRegisterUnloadHandler(WrapperHandle, PtUnload);

Status = PtRegisterAsProtocol(DriverObject, RegistryPath);
ASSERT(Status == NDIS_STATUS_SUCCESS);

NdisIMAssociateMiniport(DriverHandle, ProtHandle);
DBGPRINT(\"<== NdisIMAssociateMiniport.\\n\");

// RtlInitUnicodeString(&symLinkName, L\"\\\\??\\\\IpsecCard\");


return(Status);
}


NDIS_STATUS
PtRegisterDevice(
VOID
)
/*++

Routine Description:

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 PtDeregisterDevice via
the ControlDeviceState and MiniportCount variables.

NOTE: do not call this from DriverEntry; it will prevent the driver
from being unloaded (e.g. on uninstall).

Arguments:

None

Return Value:

NDIS_STATUS_SUCCESS if we successfully register a device object.

--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
UNICODE_STRING DeviceName;
UNICODE_STRING DeviceLinkUnicodeString;
PDRIVER_DISPATCH DispatchTable[IRP_MJ_MAXIMUM_FUNCTION];
UINT i;

DBGPRINT((\"==>PtRegisterDevice\\n\"));

NdisAcquireSpinLock(&GlobalLock);

++MiniportCount;

if (1 == MiniportCount)
    {
ASSERT(ControlDeviceState != PS_DEVICE_STATE_CREATING);

//
// Another thread could be running PtDeregisterDevice on
// behalf of another miniport instance. If so, wait for
// it to exit.
//
while (ControlDeviceState != PS_DEVICE_STATE_READY)
{
NdisReleaseSpinLock(&GlobalLock);
NdisMSleep(1);
NdisAcquireSpinLock(&GlobalLock);
}

ControlDeviceState = PS_DEVICE_STATE_CREATING;

NdisReleaseSpinLock(&GlobalLock);

for (i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++)
{
   DispatchTable = PtDispatch;
}

NdisInitUnicodeString(&DeviceName, NTDEVICE_STRING);
NdisInitUnicodeString(&DeviceLinkUnicodeString, LINKNAME_STRING);

//
// Create a device object and register our dispatch handlers
//

Status = NdisMRegisterDevice(
                    WrapperHandle,
                    &DeviceName,
                    &DeviceLinkUnicodeString,
                    &DispatchTable[0],
                    &ControlDeviceObject,
                    &NdisDeviceHandle
                    );

NdisAcquireSpinLock(&GlobalLock);

ControlDeviceState = PS_DEVICE_STATE_READY;
}

NdisReleaseSpinLock(&GlobalLock);

DbgPrint(\"<==PtRegisterDevice: %x\\n\", Status);

return (Status);
}


NTSTATUS
PtDispatch(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:

Process IRPs sent to this device.

Arguments:

DeviceObject - pointer to a device object
Irp  - pointer to an I/O Request Packet

Return Value:

NTSTATUS - STATUS_SUCCESS always - change this when adding
real code to handle ioctls.

--*/
{
PIO_STACK_LOCATION  irpStack;
NTSTATUS        status = STATUS_SUCCESS;
ULONG ControlCode;
ULONG InputLength, OutputLength;
typedef struct _MESSAGE{
UINT32   type                 ;
UINT32   len                  ;
ULONG   data[64]   ;
}MESSAGE;
MESSAGE message ;

OBJECT_HANDLE_INFORMATION objHandleInfo;

DBGPRINT((\"==>Pt Dispatch\\n\"));
irpStack = IoGetCurrentIrpStackLocation(Irp);
  
switch (irpStack->MajorFunction)
{
case IRP_MJ_CREATE:
break;
case IRP_MJ_CLOSE:
break;        
case IRP_MJ_DEVICE_CONTROL:
//
// Add code here to handle ioctl commands sent to passthru.
//
//////////////////////////////////////////////////////////////////////////////////////////

// 得到DeviceIoControl传来的控制码
ControlCode = irpStack->Parameters.DeviceIoControl.IoControlCode;

switch (ControlCode)
{
case  IO_GET_NDIS_DATA:
DbgPrint(\"Data for upper needed :mybuffer full empty:%x %x %x \\n\", MyBuffer, &FULLEVENT, &EMPTYEVENT);
message.type = 61;
message.len = 3*sizeof(ULONG);
message.data[0] = (ULONG)MyBuffer;
message.data[1] = (ULONG)&FULLEVENT;
message.data[2] = (ULONG)&EMPTYEVENT;
DbgPrint(\"message.data[0] message.data[1] message.data[2]:%x %x %x\\n\", message.data[0], message.data[1], message.data[2]);
NdisMoveMemory((Irp->AssociatedIrp.SystemBuffer), &message, message.len+8);
Irp->IoStatus.Information = message.len+8;
break;
case IO_START_CAPTURE:
DbgPrint(\"Start Capture packet:\\n\");
START_CAPTURE_FLAG = TRUE;
break;
case IO_END_CAPTURE:
DbgPrint(\"End Capture packet:\\n\");
START_CAPTURE_FLAG = FALSE;
break;
default:
break;
}

////////////////////////////////////////////////////////////
break;        
default:
break;
}

Irp->IoStatus.Status = status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);

DBGPRINT((\"<== Pt Dispatch\\n\"));

return status;

}
NDIS_STATUS
PtDeregisterDevice(
VOID
)
/*++

Routine Description:

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

Arguments:

NdisDeviceHandle - Handle returned by NdisMRegisterDevice

Return Value:

NDIS_STATUS_SUCCESS if everything worked ok

--*/
{
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;

DBGPRINT((\"==>PassthruDeregisterDevice\\n\"));

NdisAcquireSpinLock(&GlobalLock);

ASSERT(MiniportCount > 0);

--MiniportCount;

if (0 == MiniportCount)
{
//
// All miniport instances have been halted. Deregister
// the control device.
//

ASSERT(ControlDeviceState == PS_DEVICE_STATE_READY);

//
// Block PtRegisterDevice() while we release the control
// device lock and deregister the device.
//
ControlDeviceState = PS_DEVICE_STATE_DELETING;

NdisReleaseSpinLock(&GlobalLock);

if (NdisDeviceHandle != NULL)
{
Status = NdisMDeregisterDevice(NdisDeviceHandle);
NdisDeviceHandle = NULL;
}

NdisAcquireSpinLock(&GlobalLock);
ControlDeviceState = PS_DEVICE_STATE_READY;
}

NdisReleaseSpinLock(&GlobalLock);

DbgPrint(\"<== PassthruDeregisterDevice: %x\\n\", Status);
return Status;

}
VOID
PtUnloadProtocol(
VOID
)
{
NDIS_STATUS Status;

if (ProtHandle != NULL)
{
NdisDeregisterProtocol(&Status, ProtHandle);
ProtHandle = NULL;
}

DBGPRINT((\"PtUnloadProtocol: done!\\n\"));
}
根据地的兄弟们,团结就是力量
fanxf
驱动牛犊
驱动牛犊
  • 注册日期2002-12-20
  • 最后登录2006-03-14
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-12-11 21:01
在国外的网站上有源码,好像是www.pcsua.com上的wd3
arthurtu
驱动巨牛
驱动巨牛
  • 注册日期2001-11-08
  • 最后登录2020-12-19
  • 粉丝0
  • 关注0
  • 积分26分
  • 威望161点
  • 贡献值0点
  • 好评度35点
  • 原创分0分
  • 专家分0分
  • 社区居民
地板#
发布于:2003-12-11 22:59
1、xp的ddk就带了。
2、antpower以前帖过,很旧的帖子也有,应该可以搜到。
wengyu100
驱动牛犊
驱动牛犊
  • 注册日期2003-10-10
  • 最后登录2006-10-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2003-12-13 14:39
arthurtu
你老哥说的我都知道
但是我还想要源码
真的需要

请各位老大帮帮我
都是一些现成的东西,我弄不到手
cc_file
驱动牛犊
驱动牛犊
  • 注册日期2003-05-12
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2003-12-13 14:45
xp passthru
附件名称/大小 下载次数 最后更新
2003-12-13_xppassthru.rar (93KB)  6
我站在人群中,笑容如阳光般的灿烂,但是你可知道,我心底的忧伤...
wengyu100
驱动牛犊
驱动牛犊
  • 注册日期2003-10-10
  • 最后登录2006-10-21
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2003-12-14 09:54
cc_file
老兄,还是你够爽快
给40分

还有一段代码
大家能不能给个调试过的?
万分感谢!
游客

返回顶部