linux日志idProduct,获得的设备描述符的idVendor, idProduct,bcdDevice的值老是变化的。...

获得的设备描述符的idVendor, idProduct,bcdDevice的值老是变化的。

[复制链接]

每次读到的都不一样。怎么会这样啊。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:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值