Hi All,
I have a problem formatting and sending an Irp with Urb. I have an usb
upper function filter driver and inside my custom IOCTL handler I call
UsbBuildSelectConfigurationRequest to format an Urb and then I call
SendAwaitUrb to sumbit the Urb. However, IoCallDriver inside
SendAwaitUrb is returning STATUS_INVALID_DEVICE_REQUEST 0xc0000010.
I must be wrong somewere in the code below, because as we all know the
SendWaitUrb and the other code from W.Oney's book is a great source to
learn and practicise.
I have checked the chain Fido->Fdo->Pdo, it's ok, I believe
UsbBuildSelectConfigurationRequest with NULL formats a proper setup
packet... but still I am stuck and could not go ahead.
Please take a look at the code below and let me know what do you think.
Best regards,
Dim
switch (irpStack->MajorFunction) {
case IRP_MJ_CREATE:
DebugPrint(("Create \n"));
break;
case IRP_MJ_CLOSE:
DebugPrint(("Close \n"));
break;
case IRP_MJ_CLEANUP:
DebugPrint(("Cleanup \n"));
break;
case IRP_MJ_DEVICE_CONTROL:
;
switch (irpStack->Parameters.DeviceIoControl.IoControlCode)
{
//Here comes our predefined custom code
case IOCTL_MY_CUSTOM:
// Create the URB
urb = (PURB)ExAllocatePool(NonPagedPool, sizeof(struct
_URB_CONTROL_VENDOR_OR_CLASS_REQUEST));
UsbBuildSelectConfigurationRequest(urb,
sizeof(struct _URB_SELECT_CONFIGURATION),
NULL);
status = SendAwaitUrb(DeviceObject, urb);
if (!NT_SUCCESS(status))
KdPrint((DRIVERNAME " - sending urb failed with status %X\n",
status));
break;
default:
status = STATUS_INVALID_PARAMETER;
break;
}
default:
break;
}
return CompleteRequest(Irp, status, 0);
}
NTSTATUS SendAwaitUrb(PDEVICE_OBJECT fdo, PURB urb)
{
// SendAwaitUrb
PIO_STACK_LOCATION stack;
IO_STATUS_BLOCK iostatus;
KEVENT event;
NTSTATUS status;
PIRP Irp;
PDEVICE_EXTENSION pdx;
PAGED_CODE();
ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
pdx = (PDEVICE_EXTENSION) fdo->DeviceExtension;
if(pdx->NextLowerDriver == NULL)
return STATUS_UNSUCCESSFUL;
KeInitializeEvent(&event, NotificationEvent, FALSE);
Irp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_USB_SUBMIT_URB,
pdx->NextLowerDriver, NULL, 0, NULL, 0, TRUE, &event, &iostatus);
if (!Irp)
{
KdPrint((DRIVERNAME " - Unable to allocate IRP for sending URB\n"));
return STATUS_INSUFFICIENT_RESOURCES;
}
stack = IoGetNextIrpStackLocation(Irp);
stack->Parameters.Others.Argument1 = (PVOID) urb;
status = IoCallDriver(pdx->NextLowerDriver, Irp);
if (status == STATUS_PENDING)
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = iostatus.Status;
}
return status;
}// SendAwaitUrb