Author Topic: MSD "bulk only" device returns CSW already in data phase  (Read 6333 times)

erdmann

  • Member
  • ***
  • Posts: 43
MSD "bulk only" device returns CSW already in data phase
« on: June 14, 2015, 04:56:49 am »
I have a "bulk only" MSD device which is a "virtual CD-ROM". When I do an SCSI "READ TOC" command and specifying a length of 512 bytes, that device apparently does not return any data. Instead it already returns the CSW in the data phase !

I then used USBpcap to find out what happens under Windows. Windows issues about 20 SCSI "TEST UNIT READY" commands, issues a couple of other commands (that fail as they seem to be unimplemented) and then eventually does the SCSI "READ TOC" specifying a length of 804 (?) bytes which apparently succeeds.

So what am I doing wrong ? And how can it happen that a "bulk only" device returns the CSW already in the data phase even when there are 0 bytes to transfer in the data phase (should lead to a zero length packet) ? That kind of confuses the state logic.

It does turn out that for that device I have to call "TEST UNIT READY" about 5 times for it to finally return without error/return with device ready (I always do a "REQUEST_SENSE" command after the "TEST UNIT READY" command to get further info in case of error).
The need for multiple "TEST UNIT READY" commands seems absurd to me as there are no moveable parts that would need time to react or such.

This is all so odd.


Lars

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: MSD "bulk only" device returns CSW already in data phase
« Reply #1 on: June 14, 2015, 08:39:48 pm »
For curiosity's sake, I would try a READ TOC for 804 bytes.

Check bCSWStatus.

erdmann

  • Member
  • ***
  • Posts: 43
Re: MSD "bulk only" device returns CSW already in data phase
« Reply #2 on: June 18, 2015, 07:13:51 am »
1) I tried 804 bytes but it did not make a difference compared to 512 bytes.
2) bCSWStatus contained 0 ("good" status). Then I looked at bCSWDataResidue. And there it was, it contained 512 bytes (when I asked to return 512 bytes). Therefore, the CSW as such was OK and coherent.

Effectively, under Windows, much less than 804 bytes (and also 512 bytes) was returned so 512 byte buffer should also be ok.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: MSD "bulk only" device returns CSW already in data phase
« Reply #3 on: June 18, 2015, 10:18:26 pm »
Thanks for reporting what you found!

Tsuneo

  • Frequent Contributor
  • ****
  • Posts: 145
Re: MSD "bulk only" device returns CSW already in data phase
« Reply #4 on: June 21, 2015, 10:29:59 am »
Quote
I have a "bulk only" MSD device which is a "virtual CD-ROM". When I do an SCSI "READ TOC" command and specifying a length of 512 bytes, that device apparently does not return any data.

Windows ... eventually does the SCSI "READ TOC" specifying a length of 804 (?) bytes which apparently succeeds.

You have to be aware of MSF and FORMAT fields of the READ TOC command block.

There are four types of this command, identified by these parameters
1) MSF:0, FORMAT:0
2) MSF:0, FORMAT:1
3) MSF:1, FORMAT:0
4) MSF:1, FORMAT:2 (format field is assigned to MSb 2bits of Control byte - legacy form)
The return data blocks are slightly different each other.

- Windows and Linux ask 1),2),3)
- MacOSX retrieves 1),4)

As of the details of this command, refer to SCSI MMC-6 (mmc6r02g.pdf)

In this post, I wrote on the implementation of READ TOC emulation on Device side.
http://www.keil.com/forum/58452/usb-msc-class-and-cd-rom-subclass/

Tsuneo