Thanks Tim for analyzing the WinDbg output of my driver. I have attached the code below. I went through the code again and again to understand if there are any issues here i am clueless now.
NTSTATUS SendUrb(WDFDEVICE Device)
{
WDF_OBJECT_ATTRIBUTES woa;
WDFREQUEST Request;
WDFIOTARGET target;
NTSTATUS status;
WDFMEMORY memory;
PURB Urb;
PUCHAR buffer = NULL;
WDF_OBJECT_ATTRIBUTES_INIT(&woa);
//Create request oject
target = WdfDeviceGetIoTarget(Device);
status = WdfRequestCreate(
WDF_NO_OBJECT_ATTRIBUTES, target, &Request);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, “URb Req Create Failed”);
return status;
}
woa.ParentObject = Request;
status = WdfMemoryCreate(WDF_NO_OBJECT_ATTRIBUTES,
NonPagedPool,
0,
sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST)+50,//sizeof(XRB),
&memory,
(PVOID*)&Urb);
if (!NT_SUCCESS(status)) {
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, “Urb Mem Create failed”);
return status;
}
buffer = ExAllocatePoolWithTag(NonPagedPoolNx, 50, ‘durb’);
//Initialize buffer with random data
if (buffer != NULL)
{
for (int i = 0; i < 50; i++)
buffer[i] = 0xaa;
}
// [?Format the URB?]
UsbBuildVendorRequest(Urb,
URB_FUNCTION_CLASS_INTERFACE,
sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST),
USBD_TRANSFER_DIRECTION_OUT,
0,
0,//RequestCode,
0,
0xABCD,
buffer,//(Urb+1),//TransferBuffer,
NULL,
50,//TransferBufferLength,
0);
// Parameters.Others.Argument3 is used by the IOCTL value
status = WdfIoTargetFormatRequestForInternalIoctlOthers(
WdfDeviceGetIoTarget(Device),
Request,
IOCTL_INTERNAL_USB_SUBMIT_URB,
memory, NULL, // Parameters.Others.Argument1
WDF_NO_HANDLE, NULL, // Parameters.Others.Argument2
WDF_NO_HANDLE, NULL // Parameters.Others.Argument4
);
if (NT_SUCCESS(status)) {
WdfRequestSetCompletionRoutine(Request, UrbCompletionRoutine, NULL);
WDF_REQUEST_SEND_OPTIONS_INIT(&options,
WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET);
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, “Urb send WdfDeviceGetIoTarget=0x%llx”,(unsigned __int64)target);
// send async
if (WdfRequestSend(Request,
WdfDeviceGetIoTarget(Device),
&options) == FALSE) {
status = WdfRequestGetStatus(Request);
// send failed
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, “Urb send failed Status=0x%x”, status);
WdfObjectDelete(memory);
}
else {
status = STATUS_PENDING;
}
}
if (!NT_SUCCESS(status)) {
WdfObjectDelete(memory);
}
return status;
}
Thanks,
Patil