|
我参考U盘驱动的代码,想构造一个URB,但是没有获取到设备描述符。
代码如下,大家给看看是什么错误
typedef struct tagDEVICE_EXTENSION {
PDEVICE_OBJECT DeviceObject; // device object this extension belongs to
PDEVICE_OBJECT LowerDeviceObject; // next lower driver in same stack
PDEVICE_OBJECT Pdo; // the PDO
IO_REMOVE_LOCK RemoveLock;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
NTSTATUS
ReadandSelectDescriptors( IN PDEVICE_OBJECT DeviceObject )
{
KdPrint(("ReadandSelectDescriptors begin\n"));
PURB urb;
ULONG siz;
NTSTATUS ntStatus;
PUSB_DEVICE_DESCRIPTOR deviceDescriptor;
urb = NULL;
deviceDescriptor = NULL;
//Read the device descriptor
urb = (PURB)ExAllocatePool(NonPagedPool, sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST));
if(urb)
{
siz = sizeof(USB_DEVICE_DESCRIPTOR);
deviceDescriptor = (PUSB_DEVICE_DESCRIPTOR)ExAllocatePool(NonPagedPool, siz);
if(deviceDescriptor) //注意看一下
{
UsbBuildGetDescriptorRequest(
urb,
(USHORT) sizeof(struct _URB_CONTROL_DESCRIPTOR_REQUEST),
USB_DEVICE_DESCRIPTOR_TYPE,
0,
0,
deviceDescriptor,
NULL,
siz,
NULL);
ntStatus = CallUSBD(DeviceObject, urb);
if(NT_SUCCESS(ntStatus))
{
ASSERT(deviceDescriptor->bNumConfigurations);
//ntStatus = ConfigureDevice(DeviceObject);
KdPrint(("get deviceDescriptor success!"));
}
ExFreePool(urb);
ExFreePool(deviceDescriptor);
}
else
{
ExFreePool(urb);
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
}
else
{
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
}
return ntStatus;
}
NTSTATUS
CallUSBD(
IN PDEVICE_OBJECT DeviceObject,
IN PURB Urb
)
{
PIRP irp;
KEVENT event;
NTSTATUS ntStatus;
IO_STATUS_BLOCK ioStatus;
PIO_STACK_LOCATION nextStack;
PDEVICE_EXTENSION pdx;
irp = NULL;
pdx = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
//KeInitializeEvent(&event, NotificationEvent, FALSE);
irp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_SUBMIT_URB,
pdx->LowerDeviceObject,
NULL,
0,
NULL,
0,
TRUE,
&event,
&ioStatus);
if(!irp)
{
KdPrint(("IoBuildDeviceIoControlRequest failed\n"));
return STATUS_INSUFFICIENT_RESOURCES;
}
nextStack = IoGetNextIrpStackLocation(irp);
ASSERT(nextStack != NULL);
nextStack->Parameters.Others.Argument1 = Urb;
// IoSetCompletionRoutine(irp, (PIO_COMPLETION_ROUTINE) GetDescriptorCompletionRoutine,
// (PVOID) pdx, TRUE, TRUE, TRUE);
ntStatus = IoCallDriver(pdx->LowerDeviceObject, irp);
if(ntStatus == STATUS_PENDING)
{
//KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
ntStatus = ioStatus.Status;
}
return ntStatus;
} |
|