usb插拔,IRP_MN_SURPRISE_REMOVAL与IRP_MN_REMOVE_DEVICE该如何处理

zigeno 2014-08-04 03:32:06
usb插拔,IRP_MN_SURPRISE_REMOVAL与IRP_MN_REMOVE_DEVICE该如何处理


USB的URB数据循环如下:

NTSTATUS IsoStreamTransferComplete(
IN PDEVICE_OBJECT bunkfdo,
IN PIRP Irp,
IN PVOID Context
)
{
……
IoSetCompletionRoutine(Irp,
IsoStreamTransferComplete,
transferObject,
TRUE,
TRUE,
TRUE);
if (Working == pdx->DeviceState)
status = IoCallDriver(pdx->StackDeviceObject,Irp);

……
}


当USB设备意外被拔下时:
NTSTATUS USB_DispatchPnp(
IN PDEVICE_OBJECT fdo,
IN PIRP Irp
)
{
……
case IRP_MN_SURPRISE_REMOVAL:
{
KeAcquireSpinLock(&pdx->DevStateLock, &oldIrql);
SET_NEW_PNP_STATE(pdx, SurpriseRemoved);
KeReleaseSpinLock(&pdx->DevStateLock, oldIrql);

ntStatus = USB_DefaultPnpHandler(fdo, Irp);
}
break;

case IRP_MN_REMOVE_DEVICE:
{
KeAcquireSpinLock(&pdx->DevStateLock, &oldIrql);
SET_NEW_PNP_STATE(pdx, Removed);
KeReleaseSpinLock(&pdx->DevStateLock, oldIrql);

for (i = 0; i < pdx->Interface->NumberOfPipes; i++)
{
USB_AbortPipe(fdo,(USBD_PIPE_HANDLE) pdx->Interface->Pipes[i].PipeHandle);
}

UnlockDevice(fdo); // once for LockDevice at start of dispatch
UnlockDevice(fdo); // once for initialization during AddDevice

KeWaitForSingleObject(&pdx->evRemove, Executive, KernelMode, FALSE, NULL);

if (pdx->DeviceDescriptor)
{
ExFreePool(pdx->DeviceDescriptor);
}

if (pdx->Interface != NULL)
{
ExFreePool(pdx->Interface);
}

if (pdx->NeedCleanup)
{
UNICODE_STRING deviceLinkUnicodeString;

pdx->NeedCleanup = FALSE;

RtlInitUnicodeString (&deviceLinkUnicodeString,
pdx->DeviceLinkNameBuffer);

IoDeleteSymbolicLink(&deviceLinkUnicodeString);
}

IoDetachDevice(pdx->StackDeviceObject);

IoDeleteDevice (fdo);

ntStatus = USB_DefaultPnpHandler(fdo, Irp);
}
break;
……
}


运行时,拔下USB设备:
有时候PC正常运行,再次插上USB设备,设备能够恢复正常工作。
有时候PC卡死(无法响应鼠标键盘操作)

请问程序中IRP_MN_SURPRISE_REMOVAL与IRP_MN_REMOVE_DEVICE哪里处理不当?
...全文
321 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq602293601 2014-08-06
  • 打赏
  • 举报
回复
帮顶
zigeno 2014-08-04
  • 打赏
  • 举报
回复
可以自己顶一下吗?
IRPTrace2.00.002.zip ,IRP跟踪工具,支持Windows7。 IRPTrace 2.00.002, Build Date September 23, 2015 File name = README.TXT ====================================================================== CONTENTS ========= 1) IRPTrace Components 2) Release Notes 3) Known problems & limitations 4) Known bugs 5) Update to the documentation 6) List of supported I/O requests We strongly recommend that you read the following information about this release. 1) IRPTrace Components ===================== README.TXT - This file HOWTOREG.TXT - How to register IRPTrace and contact APSoft IRPTrace.EXE - Main application module IRPDRV.SYS - Driver for Windows NT/2000/XP/Server 2003 TERMINAL - Terminal log file TERMINAL.DLL - IRPTrace library UNINSDRV.DLL - IRPTrace library TSCUST.DLL - IRPTrace library IRPTRACE.CHM - Help file TIPS.TXT - 'Tip of the Day' tips GUID.INI - GUID database IRPTRACE.INI - Driver uninstallation information UNINST.ISU - Installation/uninstallation log file 2) Release Notes ================ Release 2.00.002 1. Fixed processing of IRPs at elevated IRQLs 2. Added support for Windows 10 Release (Build 10240) 3. Corrected processing of USB IOCTLs 4. Release 2.00.001 1. Added support for x64 Windows. 2. Added support for Windows Vista, 7 and 8.x. 3. Added decoding of all USB kernel-mode messages. 4. Added decoding of all CDB messages. 5. Revised Terminal tracing. 6. Revised on-line help file. 7. Revised list of known IOCTLs. 8. Revised list of known GUIDs. Release 1.00.007 1. Added support for Microsoft Windows Vista (?). 2. Redesign right panel view. 3. Fix bug with processing of Image hooks. 4. Several minor bugs were fixed. Release 1.00.006 1. A BSOD (blue screen) was fixed, which appeared o

18,124

社区成员

发帖
与我相关
我的任务
社区描述
Windows客户端使用相关问题交流社区
社区管理员
  • Windows客户端使用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧