Search code examples
embeddedusbscsi

USB as a host Data Transfer problems for SCSI READ command


I am implementing USB as a host using OHCI. And using SCSI to read a mass storage device. All my control transfers run successfully. I have done all the initialization using Control Transfers however I am facing problem with Data Transfers.

I am having troubles in successfully implementing the READ command in SCSI, be it READ(6), READ(10), etc.

The following is a snapshot of the Command Block Wrapper(CBW)- enter image description here

The highlighted portion is the SCSI command.

As You can see I have requested 512 bytes- which is the size of 1 LBA for my mass storage device.

The following is what comes in the 512 byte buffer from the device- enter image description here

FYI- The buffer was initialized to 0xff These 512 bytes are not present anywhere on my mass storage device. I opened the mass storage device on HXD and checked the bytes to see that the block I received doesnt exist on my mass storage!

And the Command Status Wrapper (CSW) I got was as follows- enter image description here

Last byte in CSW is 0x01 which means the command failed. I have 3 questions 1- What could be the reason why this READ is failing? Am I supposed to run any other SCSI command before this for any reason? 2- I request for 512 bytes and I even get that but the bytes 8-11 in CSW which show residue still show a certain value a which happens to be greater than 512 (as this is little endian format). How is this possible? 3- What could the 512 bytes I receive from the device possibly be?

Any helps with this I have been stuck here for a looong time now and I dont have a USB analyzer.

Pseudo code for Data Transfers- Set the Endpoint Descriptor (ED) 1 (Indication the OUT Endpoint) Set the Transfer Descriptor (TD) 1 (Send SCSI command)

Set the BulkHead ED to ED 1 Start the descriptor processing and then stop it

Set the Endpoint Descriptor (ED) 1 (Indication the IN Endpoint) Set the Transfer Descriptor (TD) 1 (Read the 512 bytes) Set the Transfer Descriptor (TD) 2 (Read the 13 CSW bytes)

Set the BulkHead ED to ED 1 Start the descriptor processing and then stop it


Solution

  • These 512 bytes are not present anywhere on my mass storage device.

    No, this looks very much like a valid sector 0 to me.

    What you probalbly miss ist that Windows does not allow a non-admin user to look at this sector at all. HXD thus shows you the first sector of the partition, which is not sector 0. You would see this only with admin priviliges and when opening the corresponding physical disk.

    I request for 512 bytes and I even get that but the bytes 8-11 in CSW which show residue still show a certain value a which happens to be greater than 512

    No, you request 256*512 bytes. The byte order for those SCSI length fields is AFAIK big endian.