Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why can't send Urb to the underlaying device?

87 views
Skip to first unread message

bluestar

unread,
Sep 22, 2008, 5:54:14 AM9/22/08
to
I took the sample code: kmdf\usbsamp to modify it.
I tried to add the receive IOCTL_SCSI_PASS_THROUGH command in
EvtDeviceIoControl
callback function.

I transfer the SCSI_PASS_THROUGH structure to CBW(USB 2.0 spec)
structure and
use WdfUsbTargetPipeSendUrbSynchronously to send to the underlaying
device, but
after run WdfUsbTargetPipeSendUrbSynchronously , WinDbg always break
with message:
"WARNING: This break is not a step/trace completion. The last command
has been
cleared to prevent accidental continuation of this unrelated event.
Check the event,
location and thread before resuming. Break instruction exception -
code 80000003
(first chance)"

My code for transfering and send is below.
What's wrong with my source code? and How to send successfully?

I tried many method to do, but always failed.

Please help me.
Thanks for your kindly help.

//----------------------------------------------------------------------------------------------------------------//
pDeviceContext = GetDeviceContext(WdfIoQueueGetDevice(Queue));
status = WdfRequestRetrieveInputBuffer(Request, InputBufferLength,
&INBuffer, &INLength);
if (!NT_SUCCESS(status)) {
*((PULONG)BytesReadOrWritten) = 0;
goto Exit;
}
pSCSI_CMD_Buf = (PSCSI_PASS_THROUGH_WITH_BUFFERS)INBuffer;
CBW.uldCBWSignature = 0x43425355;
CBW.uldCBWTag = 0x0F;
CBW.uldCBWDataTransferLength = pSCSI_CMD_Buf->spt.DataTransferLength;
if(pSCSI_CMD_Buf->spt.DataIn == SCSI_IOCTL_DATA_IN )
CBW.ucbmCBWFlags = CBW_DATA_IN_FORM_DEVICE;
else if (pSCSI_CMD_Buf->spt.DataIn == SCSI_IOCTL_DATA_OUT )
CBW.ucbmCBWFlags = CBW_DATA_OUT_TO_DEVICE;
else
CBW.ucbmCBWFlags = CBW_DATA_OUT_TO_DEVICE;
CBW.ucbCBWLUN = pSCSI_CMD_Buf->spt.Lun;
CBW.ucbCBWCBLength = MAX_CDB_LENGTH;
RtlCopyMemory(&CBW.ucCBWCB, pSCSI_CMD_Buf->spt.Cdb,
CBW.ucbCBWCBLength);

WDF_REQUEST_SEND_OPTIONS_INIT(&objOptions,
(WDF_REQUEST_SEND_OPTION_TIMEOUT|
WDF_REQUEST_SEND_OPTION_SYNCHRONOUS) );
WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&objOptions,
WDF_REL_TIMEOUT_IN_SEC(pSCSI_CMD_Buf->spt.TimeOutValue) );
Urb.UrbHeader.Function = URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER;
Urb.UrbHeader.Length = sizeof(struct
_URB_BULK_OR_INTERRUPT_TRANSFER);
Urb.UrbBulkOrInterruptTransfer.PipeHandle = pDeviceContext-
>BulkOUTPipe;
Urb.UrbBulkOrInterruptTransfer.TransferFlags =
(pSCSI_CMD_Buf->spt.DataIn == SCSI_IOCTL_DATA_IN)?
(USBD_TRANSFER_DIRECTION_IN|USBD_SHORT_TRANSFER_OK):0;
Urb.UrbBulkOrInterruptTransfer.TransferBufferLength = 31;
Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL = NULL;
Urb.UrbBulkOrInterruptTransfer.TransferBuffer = (PVOID)&CBW;
Urb.UrbBulkOrInterruptTransfer.UrbLink = NULL;
//WDF_OBJECT_ATTRIBUTES_INIT(&objectAttribs);
//objectAttribs.ParentObject = pDeviceContext->OUTRequest;
//status = WdfMemoryCreatePreallocated(&objectAttribs,
// (PVOID)pSCSI_CMD_Buf-
>ucDataBuf,
// SPTWB_DATA_LENGTH,
// &reqMemory);
//if(!NT_SUCCESS(status)){
// PLTraceEvents(TRACE_LEVEL_CRITICAL, DBG_WRITE,
"WdfMemoryCreatePreallocated failed\n");
// goto Exit;
//}
//status = WdfUsbTargetPipeSendUrbSynchronously(
// pDeviceContext-
>BulkOUTPipe,
// pDeviceContext-
>OUTRequest,
// &objOptions,
// &Urb
// );
status = WdfUsbTargetDeviceSendUrbSynchronously(
pDeviceContext-
>WdfUsbTargetDevice,
NULL,
&objOptions,
&Urb
);
if (!NT_SUCCESS(status)) {
PLTraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTL,
"WdfIoTargetSendIoctlSynchronously failed 0x%x\n", status);
*((PULONG)BytesReadOrWritten) = 0;
}

bluestar

unread,
Sep 22, 2008, 8:17:13 AM9/22/08
to
I tried another method to send, but it still failed.


//---------------------------------------------------------------------//
VOID
EvtIoDeviceControl(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t OutputBufferLength,
IN size_t InputBufferLength,
IN ULONG IoControlCode
)
{
WDFDEVICE device;
NTSTATUS status;
PDEVICE_CONTEXT pDevContext;
ULONG length = 0;
UNREFERENCED_PARAMETER(OutputBufferLength);
UNREFERENCED_PARAMETER(InputBufferLength);
pDevContext = GetDeviceContext(WdfIoQueueGetDevice(Queue));
switch(IoControlCode) {
case IOCTL_SCSI_PASS_THROUGH:
//All pass-through requests must be synchronous
WdfSpinLockAcquire(pDevContext->IoctlSpinLockHnd);
status = UsbIoctlProcedure(Queue, Request, OutputBufferLength,
InputBufferLength, IoControlCode, &length);
WdfSpinLockRelease(pDevContext->IoctlSpinLockHnd);
break;
default :
status = STATUS_INVALID_DEVICE_REQUEST;
break;
}
WdfRequestCompleteWithInformation(Request, status, length);
return;
}

NTSTATUS
UsbIoctlProcedure(
IN WDFQUEUE Queue,
IN WDFREQUEST Request,
IN size_t OutputBufferLength,
IN size_t InputBufferLength,
IN ULONG IoctlControlCode,
OUT PULONG BytesReadOrWritten
)
{
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_CONTEXT pDeviceContext;
WDF_MEMORY_DESCRIPTOR inputDesc, outputDesc;
size_t INLength, OUTLength;
PVOID INBuffer = 0, OUTBuffer = 0;
PSCSI_PASS_THROUGH_WITH_BUFFERS pSCSI_CMD_Buf;
CMD_BLOCK_WRAPPER CBW;
WDF_REQUEST_SEND_OPTIONS objOptions;
URB Urb;

WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&outputDesc,
(PVOID)&CBW,
31);
status = WdfUsbTargetPipeWriteSynchronously(pDeviceContext-
>BulkOUTPipe,
NULL,
&objOptions,
&outputDesc,
BytesReadOrWritten);


if (!NT_SUCCESS(status)) {
PLTraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTL,
"WdfIoTargetSendIoctlSynchronously failed 0x%x\n", status);
*((PULONG)BytesReadOrWritten) = 0;
}

Exit:
if (!NT_SUCCESS(status)) {
status = WdfRequestGetStatus(Request);
}
return status;
}

Doron Holan [MSFT]

unread,
Sep 22, 2008, 2:01:35 PM9/22/08
to
you cannot send synchronous IO while holding a spinlock. you can only send
sync io while @ passive_level, acquiring a spin lock moves you to
dispatch_level

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"bluestar" <bluest...@gmail.com> wrote in message
news:492af65c-51d3-4361...@g17g2000prg.googlegroups.com...

bluestar

unread,
Sep 23, 2008, 8:47:39 AM9/23/08
to
Dear Sir:

I am very appreciated your correction.
It is ok that I pass my code to the device.
VERY THANKS.


On 9月23日, 上午2時01分, "Doron Holan [MSFT]" <dor...@online.microsoft.com>
wrote:

bluestar

unread,
Sep 24, 2008, 3:48:08 AM9/24/08
to
Dear Sir:

I am very appreciated that your help.

I already sent to the device successfully.
But I found some confusions and please you
help me again.

My Device is USB FullSpeed, and I also
(USB_DEVICE_DESCRIPTOR.bcdUSB=0x0110)
check the devices by connection into 1.X
controller in Device-Manager(Intel Chip).

If I plug-in my device through USB-Analyzer
or USBHub, I can send below code successfully.

PC -> Analyzer / USB-Hub(2.0) -> Device (successfully)

And another method also can work well, if
I change USB 2.0 Controller to FullSpeed in
BIOS.

If I don't change to FullSpeed in BIOS and
plug-in the device into PC directly, status
is STATUS_IO_TIMEOUT((NTSTATUS)0xC00000B5L),
not NT_SUCCESS.

My Code is the same for 3 experiments.
What's matter with this condition?
Do I need to set something for this condition in driver?

//--------------------------------------------------//


WDF_REQUEST_SEND_OPTIONS_INIT(&objOptions,
(WDF_REQUEST_SEND_OPTION_TIMEOUT|
WDF_REQUEST_SEND_OPTION_SYNCHRONOUS) );
WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&objOptions,
WDF_REL_TIMEOUT_IN_SEC(pSCSI_CMD_Buf->spt.TimeOutValue) );

==> AP set time-out is 2 seconds and I follow this value

//send CBW


WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&outputDesc,
(PVOID)&CBW,
31);
status = WdfUsbTargetPipeWriteSynchronously(pDeviceContext-
>BulkOUTPipe,
NULL,
&objOptions,
&outputDesc,

pReturn);


if (!NT_SUCCESS(status)) {
PLTraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTL,
"WdfIoTargetSendIoctlSynchronously failed 0x%x\n", status);
*((PULONG)BytesReadOrWritten) = 0;

goto Exit;
}

bluestar

unread,
Oct 2, 2008, 2:56:40 AM10/2/08
to
Dear Sir:

I already sent to the device successfully.

But I found compatibility for functions:
WdfUsbTargetPipeWriteSynchronously and
WdfUsbTargetPipeReadSynchronously.

I tried to plug my device into MB with
SB:ICH5, AMD SB600 and nForce560 and I
found it doesn't throw anything to my
device when I run WdfUsbTargetPipeWrite-
Synchronously and WdfUsbTargetPipeRead-
Synchronously,the returned value is
STATUS_IO_TIMEOUT except ICHx.Even ICHx
chipset, the commands don't always work
successfully.

Is it compatibility issue for my device
and SB? Is there any method to workaround
to fix this condition?

Thanks for your kindly suggestion

ps: I modified KMDF\usbsamp to send
command to my device.

bluestar

unread,
Oct 2, 2008, 9:56:10 AM10/2/08
to
Dear Sir:

I found if I don't plug other USB devices(keyboard, mouse),
only
my device, it has a chance to send successfully.

Should I need to add something?

By the way, When I run my testing AP to send commands, it
is ok for XP, but it will crash for Vista. Where do I need to take
care?

Thanks for your suggestion.

//----------------------------------------------------------------------------------------//


WDF_REQUEST_SEND_OPTIONS_INIT(&objOptions,
(WDF_REQUEST_SEND_OPTION_TIMEOUT|
WDF_REQUEST_SEND_OPTION_SYNCHRONOUS) );
WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&objOptions,

WDF_REL_TIMEOUT_IN_SEC(ullTimeOut) );
//send CBW


WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&outputDesc,
(PVOID)&CBW,
31);
status = WdfUsbTargetPipeWriteSynchronously(pDeviceContext-
>BulkOUTPipe,
NULL,
&objOptions,
&outputDesc,

&nReturn);


if (!NT_SUCCESS(status)) {
PLTraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTL,
"WdfIoTargetSendIoctlSynchronously failed 0x%x\n", status);
*((PULONG)BytesReadOrWritten) = 0;

goto Exit;
}

bluestar

unread,
Oct 3, 2008, 12:01:01 AM10/3/08
to
Dear Sir:

I run the Below code and work successfully in XP,
but it failed in Vista, and WinDbg will show:


"WARNING: This break is not a step/trace completion.
The last command has been cleared to prevent
accidental continuation of this unrelated event.
Check the event, location and thread before resuming.
Break instruction exception - code 80000003 (first chance)
"

What happens for this condition?
Where is my failure with my code?

//-------------------------------------------------------------------------­---------------//


WDF_REQUEST_SEND_OPTIONS_INIT(&objOptions,
(WDF_REQUEST_SEND_OPTION_TIMEOUT|
WDF_REQUEST_SEND_OPTION_SYNCHRONOUS) );
WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&objOptions,

WDF_REL_TIMEOUT_IN_SEC(ullTimeOut) );
//send CBW


WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&outputDesc,
(PVOID)&CBW,
31);
status = WdfUsbTargetPipeWriteSynchronously(pDeviceContext-
>BulkOUTPipe,
NULL,
&objOptions,
&outputDesc,

&nReturn); ====> Error
Message


if (!NT_SUCCESS(status)) {
PLTraceEvents(TRACE_LEVEL_ERROR, DBG_IOCTL,
"WdfIoTargetSendIoctlSynchronously failed 0x%x\n", status);
*((PULONG)BytesReadOrWritten) = 0;

goto Exit;

Tim Roberts

unread,
Oct 4, 2008, 9:28:33 PM10/4/08
to
bluestar <bluest...@gmail.com> wrote:
>
> I run the Below code and work successfully in XP,
>but it failed in Vista, and WinDbg will show:
>"WARNING: This break is not a step/trace completion.
>The last command has been cleared to prevent
>accidental continuation of this unrelated event.
>Check the event, location and thread before resuming.
>Break instruction exception - code 80000003 (first chance)
>"
> What happens for this condition?
> Where is my failure with my code?

You seem to have hit an assert. Assuming it is coming from WDF, the
!wdflogdump should be able to tell you what asserted.

http://www.microsoft.com/whdc/Driver/tips/KMDF_IfrLog.mspx
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

zhangfei

unread,
Oct 27, 2008, 4:11:27 AM10/27/08
to
Any suggestion will be appreciated. Thanks in advance.


bluestar

unread,
Nov 11, 2008, 4:18:08 AM11/11/08
to
On 10月27日, 下午4時11分, "zhangfei" <fzh...@atheros.com> wrote:
> Any suggestion will be appreciated. Thanks in advance.

You can set ExecutionLevel to Passive, it can solve.

0 new messages