每次读到的都不一样。怎么会这样啊。ddk下的。其他地方都没有改,就在FilterDispatchPnp中添加一段代码来获得设备描述符。但是问题如标题。每次运行
DebugPrint出来的idVendor, idProduct,bcdDevice的值老是变化的。
具体代码如下
NTSTATUS
FilterDispatchPnp (
__in PDEVICE_OBJECT DeviceObject,
__in PIRP Irp
)
/*++
Routine Description:
The plug and play dispatch routines.
Most of these the driver will completely ignore.
In all cases it must pass on the IRP to the lower driver.
Arguments:
DeviceObject - pointer to a device object.
Irp - pointer to an I/O Request Packet.
Return Value:
NT status code
--*/
{
PDEVICE_EXTENSION deviceExtension;
PIO_STACK_LOCATION irpStack;
NTSTATUS status;
KEVENT event;
PURB pUrb = NULL;
PUSB_DEVICE_DESCRIPTOR deviceDescriptor = NULL;
ULONG dwSize;
NTSTATUS Status = STATUS_SUCCESS;
LARGE_INTEGER RunTime;
KEVENT Event;
IO_STATUS_BLOCK IoStatus;
PIO_STACK_LOCATION NextStack;
PIRP newIrp;
USHORT myidVendor;
PAGED_CODE();
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
irpStack = IoGetCurrentIrpStackLocation(Irp);
//DbgPrint(("FilterDO %s IRP:0x%p \n",
// PnPMinorFunctionString(irpStack->MinorFunction), Irp));
status = IoAcquireRemoveLock (&deviceExtension->RemoveLock, Irp);
if (!NT_SUCCESS (status)) {
Irp->IoStatus.Status = status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return status;
}
//////////////////////////////////////////////////////////////
// Added by me
pUrb = (PURB)ExAllocatePool(NonPagedPool, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
if(pUrb)
{
//DbgPrint("URB OK\n");
dwSize = sizeof(USB_DEVICE_DESCRIPTOR);
deviceDescriptor = (PUSB_DEVICE_DESCRIPTOR)ExAllocatePool(NonPagedPool, dwSize);
if(deviceDescriptor)
{
//DbgPrint("DeviceDescriptor OK\n");
UsbBuildGetDescriptorRequest(pUrb,
(USHORT)sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
USB_DEVICE_DESCRIPTOR_TYPE,
0,
0,
deviceDescriptor,
NULL,
dwSize,
NULL);
RunTime.QuadPart = -2000 * 10;
KeInitializeEvent(&Event, NotificationEvent, FALSE);
newIrp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_SUBMIT_URB,
DeviceObject,
NULL,
0,
NULL,
0,
TRUE,
&Event,
&IoStatus);
NextStack = IoGetNextIrpStackLocation(newIrp);
NextStack->Parameters.Others.Argument1 = pUrb;
//DbgPrint("Before Call\n");
Status = IoCallDriver(DeviceObject, newIrp);
if(Status == STATUS_PENDING)
{
DbgPrint("Pending\n");
Status = KeWaitForSingleObject(
&Event,
Suspended,
KernelMode,
FALSE,
&RunTime);
if(Status == STATUS_TIMEOUT)
{
DbgPrint("Cancel\n");
Status = STATUS_UNSUCCESSFUL;
IoCancelIrp(newIrp);
KeWaitForSingleObject(
&Event,
Suspended,
KernelMode,
FALSE,
NULL);
}
}
DbgPrint(" idVendor: %d, bcdDevice:%d, idProduct:%d\n", deviceDescriptor->idVendor,deviceDescriptor->bcdDevice,deviceDescriptor->idProduct);
DbgPrint(" bDeviceClass: %d,bDeviceSubClass:%d\n",deviceDescriptor->bDeviceClass,deviceDescriptor->bDeviceSubClass);
myidVendor = deviceDescriptor->idVendor;
}
ExFreePool(deviceDescriptor);
}
else
{
Status = STATUS_NO_MEMORY;
}
ExFreePool(pUrb);
}
else
{
Status = STATUS_NO_MEMORY;
}
DbgPrint("Return\n");
// End of addition
///////////////////////////////////////////////////////////////////////////
switch (irpStack->MinorFunction) {
case IRP_MN_START_DEVICE:
这个是ddk vista 6000版本的一个toast例子中的,我只是改写filter.c中的这段想获得设备描述符。
全国第一家虚拟主机:支持伪静态.有利于提高排名!!!
15G全能空间年付500元/月付70元 可免费试用
5GB 独立WEB空间、5GB 企业邮箱空间、5GB MSSQL数据库
IIS连接数据 500 个、500GB/月流量、共享日志文件空间
企业邮箱功能
赠送5GB 超大企业邮箱,500个Email企业邮箱用户
自动回复、自动转发、POP3、SMTP收发信、SMTP发信认证
邮件过滤、邮件拒收、邮件夹管理、邮件域管理、定制邮件数
数据库功能
支持5GB MSSQL数据库空间,5个用户数据库、Access
主机功能支持
采用安全稳定的Win2003 .net2.0 架构
支持ASP、PHP、ASP.NET、PERL等脚本、支持自定义CGI
全面支持.net2.0版本,独立的Application应用池,
支持SSI(Shtml),支持FrontPage扩展
可免费自行绑定5个域名、500个解析、500个子域名
详情咨询021-51695858 QQ:678500
官方网站 www.abcnic.com
ADD:上海市浦东新区金桥浙桥路289号建银大厦A座703-704
晕啊,我提问的帖怎么被人灌水啊。真是无语。各位兄弟请帮助啊。不吝赐教,非常感激了。