阅读:1508回复:4
各位高手,40分求一份passthru与上层应用程序通讯的代码
如题,谢谢。
|
|
最新喜欢:xiaoji... |
沙发#
发布于:2003-11-18 09:10
NDIS_STATUS
PtRegisterDevice(VOID) { NDIS_STATUS Status = NDIS_STATUS_SUCCESS; UNICODE_STRING DeviceName; UNICODE_STRING DeviceLinkUnicodeString; PDRIVER_DISPATCH DispatchTable[IRP_MJ_MAXIMUM_FUNCTION+1]; 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); NdisZeroMemory(DispatchTable, (IRP_MJ_MAXIMUM_FUNCTION+1) * sizeof(PDRIVER_DISPATCH)); // BEGIN_PTUSERIO DispatchTable[IRP_MJ_CREATE] = DevOpen; DispatchTable[IRP_MJ_CLEANUP] = DevCleanup; DispatchTable[IRP_MJ_CLOSE] = DevClose; DispatchTable[IRP_MJ_DEVICE_CONTROL] = DevIoControl; // END_PTUSERIO NdisInitUnicodeString(&DeviceName, NTDEVICE_STRING); NdisInitUnicodeString(&DeviceLinkUnicodeString, LINKNAME_STRING); // // Create a device object and register our dispatch handlers // Status = NdisMRegisterDevice( PGPnetDriver.NdisWrapperHandle, &DeviceName, &DeviceLinkUnicodeString, &DispatchTable[0], &ControlDeviceObject, &PGPnetDriver.NdisDeviceHandle ); NdisAcquireSpinLock(&GlobalLock); ControlDeviceState = PS_DEVICE_STATE_READY; } NdisReleaseSpinLock(&GlobalLock); DBGPRINT((\"<==PtRegisterDevice: %x\\n\", Status)); return (Status); } NTSTATUS DevIoControl( IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp ) { 先把分给我,我就把这个函数的实现部分给你,哈哈;) } |
|
|
板凳#
发布于:2003-11-19 09:52
好吧!
^_^! 不过你有没有 用事件通知下层的代码? 如果有的话,麻烦给个代码! 谢谢! 接分 |
|
地板#
发布于:2003-11-22 20:40
NTSTATUS
DevIoControl( IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp ) { PIO_STACK_LOCATION pIrpSp; NTSTATUS NtStatus = STATUS_SUCCESS; ULONG BytesReturned = 0; ULONG FunctionCode; PUCHAR ioBuffer = NULL; ULONG inputBufferLength; ULONG outputBufferLength; UNREFERENCED_PARAMETER(pDeviceObject); pIrpSp = IoGetCurrentIrpStackLocation(pIrp); ioBuffer = pIrp->AssociatedIrp.SystemBuffer; inputBufferLength = pIrpSp->Parameters.DeviceIoControl.InputBufferLength; outputBufferLength = pIrpSp->Parameters.DeviceIoControl.OutputBufferLength; FunctionCode = pIrpSp->Parameters.DeviceIoControl.IoControlCode; DBGPRINT((\"==>Pt DevIoControl: Context %p\\n\", (pIrpSp->FileObject)->FsContext )); switch (FunctionCode) { case IOCTL_PTUSERIO_ENUMERATE: return( DevEnumerateBindings( pDeviceObject, pIrp ) // 需要自己实现 ); case IOCTL_PTUSERIO_OPEN_ADAPTER: return( DevOpenAdapter( pDeviceObject, pIrp, FALSE // 需要自己实现 ) ); case IOCTL_PTUSERIO_QUERY_INFORMATION: return( DevQueryInformation( pDeviceObject, pIrp, FALSE // 需要自己实现 ) ); case IOCTL_PTUSERIO_SET_INFORMATION: default: NtStatus = STATUS_NOT_SUPPORTED; break; } if (NtStatus != STATUS_PENDING) { pIrp->IoStatus.Information = BytesReturned; pIrp->IoStatus.Status = NtStatus; IoCompleteRequest(pIrp, IO_NO_INCREMENT); } DBGPRINT((\"<== Pt DevIoControl\\n\")); return NtStatus; } #define FSCTL_PTUSERIO_BASE FILE_DEVICE_NETWORK #define _PTUSERIO_CTL_CODE(_Function, _Method, _Access) \\ CTL_CODE(FSCTL_PTUSERIO_BASE, _Function, _Method, _Access) #define IOCTL_PTUSERIO_ENUMERATE \\ _PTUSERIO_CTL_CODE(0x201, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) #define IOCTL_PTUSERIO_OPEN_ADAPTER \\ _PTUSERIO_CTL_CODE(0x202, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) #define IOCTL_PTUSERIO_QUERY_INFORMATION \\ _PTUSERIO_CTL_CODE(0x203, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) #define IOCTL_PTUSERIO_SET_INFORMATION \\ _PTUSERIO_CTL_CODE(0x204, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) |
|
|
地下室#
发布于:2003-11-29 16:13
楼上的,你的代码不是很全啊!
你只给出了deviceIoControl的代码! 其他的函数的代码没有啊! 其实我到不是非要这些代码,主要是想知道这些代码和普通驱动的关于这些函数代码的异同。 另外我按照你的方法,上层调用CreateFile时总是返回空句柄啊! 具体是这样写的: hDevice=CreateFile(\"\\\\\\\\.\\\\Filter\" , GENERIC_READ | GENERIC_WRITE, 0, // share mode none NULL, // no security OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); // no template 在驱动中定义的符号连接是\\\\DosDevices\\\\Filter 怎么回事,高手看看啊!谢谢 |
|