Regarding status_unsuccessful+IoCalldriver+UsbBuildVendorRequest

Z

zyx

Hi,
I am working on adding support of DFU to the exixting usb function
driver.My driver goes to DFU mode now.
If I give a getstatus request to the device.It is giving me
status_unsuccessful.
After it calls the IoCallDriver it returns c0000001 error code.
I am not sure why it is coming.I am executing the same piece of code 2
times.one before resetting the device.ie once the device exposes its
normal descriptor I gave detach request to it.The same piece of code is
executed again after the device changes its mode(ie, to DFU).and now it
gives me status_unsuccessful.
The piece of code that I am executing is given below
NTSTATUS SendDFUCommand(PDEVICE_OBJECT fdo,USHORT direction,UCHAR
request,
USHORT value,USHORT index,PVOID data,ULONG *length)
{
PAGED_CODE();
NTSTATUS status;
PURB urb;
PIRP irp;
KEVENT event;
IO_STATUS_BLOCK iostatus;

/* TODO: Remove after testing */
KdPrint((DRIVERNAME " - Inside SendDFUCommand\n"));

PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fdo->DeviceExtension;
urb = (PURB) ExAllocatePool(NonPagedPool,sizeof(struct
_URB_CONTROL_VENDOR_OR_CLASS_REQUEST));
UsbBuildVendorRequest(
urb,
URB_FUNCTION_CLASS_INTERFACE,
sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST),
direction?USBD_TRANSFER_DIRECTION_IN : USBD_TRANSFER_DIRECTION_OUT,
0,request,
value,index,
data,NULL,*length,
0
);
KdPrint((DRIVERNAME " - DFU_Request %X \n", request));
KdPrint((DRIVERNAME " - Timeout milliseconds %X \n", value));
KdPrint((DRIVERNAME " - DFU Interface %X \n", index));
KdPrint((DRIVERNAME " - Data send or received %X \n", data));
KdPrint((DRIVERNAME " - Total length of data %X \n", *length));

KeInitializeEvent(&event, NotificationEvent, FALSE);
KdPrint((DRIVERNAME " - iostatus %X \n", &iostatus));
irp = IoBuildDeviceIoControlRequest(
IOCTL_INTERNAL_USB_SUBMIT_URB,
pdx->LowerDeviceObject,
NULL, 0, NULL, 0, TRUE, &event, &iostatus);
if (!irp)
{
KdPrint((DRIVERNAME " - Unable to allocate IRP for sending
URB\n"));
return STATUS_INSUFFICIENT_RESOURCES;
}

KdPrint((DRIVERNAME " - IoBuildDeviceIoControlRequest %X \n",
iostatus.Status));
KdPrint((DRIVERNAME " - IRP Pointer %X \n", irp));

PIO_STACK_LOCATION stack = IoGetNextIrpStackLocation(irp);
stack->Parameters.Others.Argument1 = (PVOID)urb;
stack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
stack->Parameters.DeviceIoControl.IoControlCode =
IOCTL_INTERNAL_USB_SUBMIT_URB;

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

KdPrint((DRIVERNAME " - After IoCallDriver %X \n", status));
if(status == STATUS_PENDING)
{
status = KeWaitForSingleObject(
&event,
Executive,
KernelMode,
FALSE,
NULL
);
KdPrint((DRIVERNAME " - Before Assigning status %X \n", status));
KdPrint((DRIVERNAME " - IoBuildDeviceIoControlRequest %X \n",
iostatus.Status));
status = iostatus.Status;
}
*length = urb->UrbBulkOrInterruptTransfer.TransferBufferLength;
KdPrint((DRIVERNAME " - status length %X \n", *length));
KdPrint((DRIVERNAME " - data %X \n", data));
ExFreePool (urb);
KdPrint((DRIVERNAME " - IoBuildDeviceIoControlRequest %X \n",
status));
return status;
}
This is the sample code I got from net,csr application note .I am using
the same code.
Help me find out the prblem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top