title: Android SCSI USB communication issues
body: <p>This is not a question about code as much as correct SCSI procedures.</p>
  <p>I'm using an open source Android USB library which works fine, but I'm trying to solve some issues with a device I'm having.</p>
  <p>When a device is connected the library goes through all its LUNs and calls the following SCSI functions to initialize each one:</p>
  <ol>
  <li><code>INQUIRY</code></li>
  <li><code>TEST UNIT READY</code></li>
  <li><code>READ CAPACITY</code></li>
  </ol>
  <p>This works fine on most devices but on my device there is an issue. The device is an SD card reader with two LUNs. One is empty and this results in <code>TEST UNIT READY</code> reporting an error when called. <code>REQUEST SENSE</code> is then called which reports it as <code>MEDIUM NOT PRESENT</code> which is logical and handled by throwing an exception and thereby stopping before <code>READ CAPACITY</code> is reached.</p>
  <p>The second LUN with an SD card in it also reports an error in <code>TEST UNIT READY</code>; <code>NOT READY TO READY CHANGE, MEDIUM MAY HAVE CHANGED</code> (Sense code 06h, ASC 28h, ASCQ 00h). I think it essentially means &quot;card inserted&quot;. My question is what to do at this point to continue initializing the LUN?</p>
  <p>I have tried:</p>
  <ul>
  <li>Calling <code>TEST UNIT READY</code> again - results in the exact same error reappearing in <code>TEST UNIT READY</code> each time</li>
  <li>Retrying the entire init procedure starting with a new <code>INQUIRY</code> - same result as above</li>
  <li>Reading the error and continuing with <code>READ CAPACITY</code> - results in the receiving <code>UsbDeviceConnection.bulkTransfer()</code> for <code>READ CAPACITY</code> to return -1.</li>
  </ul>
  <p>My conclusion is that either something is wrong with this reader (which seems unlikely) or I'm not handling the further communication with the device correctly after this type of SENSE result is returned. I've been looking through all documentation I can find on google but can't find anything that can help me with this particular issue. I assume some kind of reset or something has to be done? Some way to acknowledge that the medium has changed?</p>
  <p>More observations:</p>
  <ul>
  <li>The issue seems to arise only in a certain SD card reader, and only with a certain SD card. Using another SD card in the reader works and using the first SD card in another reader also works.</li>
  <li>When the USB device is initially opened <code>UsbDeviceConnection.claimInterface(interface, true)</code> is called. When this takes very long time (1-2 minutes) the issue always arises, but if it has the more normal almost instantaneous delay then the issue doesn't arise.</li>
  </ul>
  <p>This leads me to conclude that either this particular SD card and reader doesn't like each other very much, or there is some issue in claimInterface with this particular SD card reader.</p>