lejianz
驱动中牛
驱动中牛
  • 注册日期2003-03-05
  • 最后登录2023-11-15
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望145点
  • 贡献值0点
  • 好评度116点
  • 原创分0分
  • 专家分0分
  • 社区居民
阅读:2844回复:7

如何在HID Minidriver里发URB读报告数据

楼主#
更多 发布于:2004-09-07 16:49
现在做一个HID Minidriver,在它的IOCTL_HID_READ_REPORT响应例程中,我要发出一个URB,这是一个中断传输,我象往常一样构造一个URB,然后CallUsbdi,但在这个函数中,在以下部分遇到问题:
   ntStatus = IoCallDriver(pdx->LowerDeviceObject,irp);
    if (ntStatus == STATUS_PENDING) {
KeWaitForSingleObject(&event,Suspended,KernelMode,FALSE,NULL);
ntStatus=ioStatus.Status;
}
蓝屏告诉我:
a wait operation, attach process or yield was attempted from a DPC routine.
Softice也告诉我:
ATTEMPTED_SWITCH_FROM_DPC, ERROR:08

后来,我把它改成一个完成例程的方式:

IoSetCompletionRoutine(irp,
(PIO_COMPLETION_ROUTINE)UsbInterruptReadCompletion,
urb,
TRUE,
TRUE,
TRUE
);

…….
IoMarkIrpPending(irp);

ntStatus = IoCallDriver(pdx->LowerDeviceObject, irp);

…….
return STATUS_PENDING;


现在它不会出现以上的问题,但读数据时,根本读不出来数据,不知道为什么。
 根据Walter Only的建议:

? If your device is a nonstandard USB device, you can perhaps submit a single URB to derive data from which you can compose a structured report. You can piggyback the URB on the IOCTL_HID_READ_REPORT request if your device’s raw report is no bigger than the report HIDCLASS is expecting. In this case, your dispatch routine will presumably allocate memory for the URB from nonpaged memory, install a completion routine, and forward the IRP down the PnP stack to the USB bus driver. Your completion routine will free the URB, reformat the report data and set IoStatus.Information equal to the size of the reformatted report, and return STATUS_SUCCESS to allow the IRP to complete.
? In still other situations, you may need to pend the IOCTL_HID_READ_REPORT request while you perform one or more I/O operations to fetch raw data from your device, which you then reformat into the desired report packet. With this design, you have the usual issues associated with caching a pointer to the IOCTL_HID_READ_REPORT request in a cancel-safe way and with cancelling whatever subsidiary IRPs you create.

我不管采用哪种方式,都不能得到数据,固件应该没问题,如果当作一个USB设备来读,可以读到数据。
不知有哪位大侠曾有过相似的经历或知道怎么做,请不吝赐教。

一起交流,共同提高!
lejianz
驱动中牛
驱动中牛
  • 注册日期2003-03-05
  • 最后登录2023-11-15
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望145点
  • 贡献值0点
  • 好评度116点
  • 原创分0分
  • 专家分0分
  • 社区居民
沙发#
发布于:2004-09-09 15:17
难道真得没有大侠知道吗?
现在看来,出现蓝屏的原因是知道了,因为在这里,不能出现线程阻塞的,因此只能用异步IRP来解决这个问题。但不知为什么,在IOCALLDRIVER之后,返回STATUS_PENDING,而在我的完成例程里,能返回STATUS_SUCCESS,在这之后,系统不再发出IOCTL_HID_READ_REPORT。
我应该如何在HID MINIDRIVER中出URB读USB的设备数据?
请大侠现身。
一起交流,共同提高!
lejianz
驱动中牛
驱动中牛
  • 注册日期2003-03-05
  • 最后登录2023-11-15
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望145点
  • 贡献值0点
  • 好评度116点
  • 原创分0分
  • 专家分0分
  • 社区居民
板凳#
发布于:2004-09-10 08:52
现在能有数据读过来了,但读的数据不对,继续调试中,还望DX能给给予关注。
一起交流,共同提高!
lejianz
驱动中牛
驱动中牛
  • 注册日期2003-03-05
  • 最后登录2023-11-15
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望145点
  • 贡献值0点
  • 好评度116点
  • 原创分0分
  • 专家分0分
  • 社区居民
地板#
发布于:2004-09-13 19:52
还是有问题,看来只有用WORKITEM降低IRQL来处理问题。
有知道的大侠请指点。
一起交流,共同提高!
lejianz
驱动中牛
驱动中牛
  • 注册日期2003-03-05
  • 最后登录2023-11-15
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望145点
  • 贡献值0点
  • 好评度116点
  • 原创分0分
  • 专家分0分
  • 社区居民
地下室#
发布于:2004-09-15 10:54
终于可以读来正确的数据,但新问题又来了。在读来10多帧数据后(不一定)重新启动OS,用SOFTICE调试,说是分页错误。这有可能是哪里的原因呢?
一起交流,共同提高!
lejianz
驱动中牛
驱动中牛
  • 注册日期2003-03-05
  • 最后登录2023-11-15
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望145点
  • 贡献值0点
  • 好评度116点
  • 原创分0分
  • 专家分0分
  • 社区居民
5楼#
发布于:2004-09-15 15:19
我把调试信息贴上来,它说存取地址不正确:

MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit
MsMini - Usb Interrupt Read complete routine ntStatus 0
MsMini - IOCTL_HID_READ_REPORT
MsMini - Usb Interrupt Read Entry
MsMini - Usb Interrupt Read ntStatus 103
MsMini - Usb Interrupt Read Exit

*** Fatal System Error: 0x0000000a
                       (0x00000000,0x00000002,0x00000001,0x804F5544)

Break instruction exception - code 80000003 (first chance)

A fatal system error has occurred.
Debugger entered on first try; Bugcheck callbacks have not been invoked.

A fatal system error has occurred.

Connected to Windows XP 2600 x86 compatible target, ptr64 FALSE
Loading Kernel Symbols
................................................Unable to add module at ffffffff
Missing image name, possible corrupt data.
.Unable to add module at 00000000
Unable to read KLDR_DATA_TABLE_ENTRY at 48706950 - NTSTATUS 0xC0000001

Loading unloaded module list
...........
*******************************************************************************
*                                                                             *
*                        Bugcheck Analysis                                    *
*                                                                             *
*******************************************************************************

Use !analyze -v to get detailed debugging information.

BugCheck A, {0, 2, 1, 804f5544}

Probably caused by : sr.sys ( sr!SrSetInformation+177 )

Followup: MachineOwner
---------

nt!RtlpBreakWithStatusInstruction:
805103fa cc               int     3
kd> !analyze -v
*******************************************************************************
*                                                                             *
*                        Bugcheck Analysis                                    *
*                                                                             *
*******************************************************************************

IRQL_NOT_LESS_OR_EQUAL (a)
An attempt was made to access a pageable (or completely invalid) address at an
interrupt request level (IRQL) that is too high.  This is usually
caused by drivers using improper addresses.
If a kernel debugger is available get the stack backtrace.
Arguments:
Arg1: 00000000, memory referenced
Arg2: 00000002, IRQL
Arg3: 00000001, value 0 = read operation, 1 = write operation
Arg4: 804f5544, address which referenced memory

Debugging Details:
------------------


WRITE_ADDRESS:  00000000

CURRENT_IRQL:  2

FAULTING_IP:
nt!CcAllocateInitializeBcb+81
804f5544 8902             mov     [edx],eax

DEFAULT_BUCKET_ID:  DRIVER_FAULT

BUGCHECK_STR:  0xA

LAST_CONTROL_TRANSFER:  from 805258ca to 805103fa

STACK_TEXT:  
fa2df574 805258ca 00000003 fa2df8a4 00000000 nt!RtlpBreakWithStatusInstruction
fa2df5c0 80526160 00000003 00000000 804f5544 nt!KiBugCheckDebugBreak+0x19
fa2df98c 805266db 0000000a 00000000 00000002 nt!KeBugCheck2+0x46d
fa2df9ac 804dce53 0000000a 00000000 00000002 nt!KeBugCheckEx+0x19
fa2df9ac 804f5544 0000000a 00000000 00000002 nt!KiTrap0E+0x2ad
fa2dfa44 804f5660 ff4edc18 ffb7abf0 fa2dfa70 nt!CcAllocateInitializeBcb+0x81
fa2dfad0 805891a7 ff986448 fa2dfb24 00000020 nt!CcPinFileData+0x1d2
fa2dfb44 f9dd6bc4 ff986448 fa2dfb70 00000020 nt!CcPinRead+0xc4
fa2dfb78 f9dd91e5 ffbdfeb0 e1a51008 00003020 Fastfat!FatReadDirectoryFile+0x88
fa2dfba0 f9dd937c ffbdfeb0 e12dbcf0 fa2dfbd0 Fastfat!FatGetDirentFromFcbOrDcb+0x25
fa2dfbfc f9dd9028 ffbdfeb0 ff062008 ff061a70 Fastfat!FatSetEndOfFileInfo+0x104
fa2dfc50 f9dd90bf ffbdfeb0 ff062008 ff062008 Fastfat!FatCommonSetInformation+0x231
fa2dfc94 804eca36 8128cc38 ff062008 ff062198 Fastfat!FatFsdSetInformation+0x65
fa2dfca4 f9e02101 ff061a70 812e1030 00000000 nt!IopfCallDriver+0x31
fa2dfcb8 804eca36 8128c0d8 ff062008 8128c020 sr!SrSetInformation+0x177
fa2dfcc8 804f4106 00000000 ff0615e0 000019d6 nt!IopfCallDriver+0x31
fa2dfcfc 804f384d ff061a70 fa2dfd24 80548290 nt!CcSetValidData+0xa6
fa2dfd34 804ee99d 813192c0 8054eda0 8131e020 nt!CcWriteBehind+0x206
fa2dfd74 804ed629 813192c0 00000000 8131e020 nt!CcWorkerThread+0x116
fa2dfdac 8057c73a 813192c0 00000000 00000000 nt!ExpWorkerThread+0xfe
fa2dfddc 805124c1 804ed556 00000000 00000000 nt!PspSystemThreadStartup+0x34
00000000 00000000 00000000 00000000 00000000 nt!KiThreadStartup+0x16


FOLLOWUP_IP:
sr!SrSetInformation+177
f9e02101 5f               pop     edi

FOLLOWUP_NAME:  MachineOwner

SYMBOL_NAME:  sr!SrSetInformation+177

MODULE_NAME:  sr

IMAGE_NAME:  sr.sys

DEBUG_FLR_IMAGE_TIMESTAMP:  3d6dd8b4

STACK_COMMAND:  kb

BUCKET_ID:  0xA_W_sr!SrSetInformation+177

Followup: MachineOwner
---------

有大侠能提示吗?
一起交流,共同提高!
lejianz
驱动中牛
驱动中牛
  • 注册日期2003-03-05
  • 最后登录2023-11-15
  • 粉丝0
  • 关注0
  • 积分8分
  • 威望145点
  • 贡献值0点
  • 好评度116点
  • 原创分0分
  • 专家分0分
  • 社区居民
6楼#
发布于:2004-09-16 11:39
上面的问题终于解决了,主要还是参数写得不对。现在可以正确读来数据。接下来是数据处理。
怪了,这些天没有大侠来说上一二句,真是郁闷。给我的感觉是孤单只影,在黑暗中摸索。
唉,只有慢慢来....
一起交流,共同提高!
kuangyang
驱动牛犊
驱动牛犊
  • 注册日期2008-08-10
  • 最后登录2009-06-12
  • 粉丝0
  • 关注0
  • 积分24分
  • 威望109点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2009-02-26 21:33
楼主能不能请你告诉我你的邮箱?我能请教你一些问题嘛?我遇到类似的问题!谢谢
csukuangyang@163.com
游客

返回顶部