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;
}
//---------------------------------------------------------------------//
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;
}
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...
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:
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;
}
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.
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;
}
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;
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.
You can set ExecutionLevel to Passive, it can solve.