AnsweredAssumed Answered

USB MSC library bug?

Question asked by karlen on Jan 13, 2014
Does anyone got USB MSC library working?  At least one suspicious place:
File: usbd_msc_scsi.c
(...)
static int8_t SCSI_Verify10(uint8_t lun , uint8_t *params){
  if ((params[1]& 0x02) == 0x02)
  {
    SCSI_SenseCode (lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
    return -1; /* Error, Verify Mode Not supported*/
  }
 
  if(SCSI_CheckAddressRange(lun, SCSI_blk_addr, SCSI_blk_len) < 0)
  {
    return -1; /* error */      
  }
  MSC_BOT_DataLen = 0;
  return 0;
}

/**
* @brief  SCSI_CheckAddressRange
*         Check address range
* @param  lun: Logical unit number
* @param  blk_offset: first block address
* @param  blk_nbr: number of block to be processed
* @retval status
*/
static int8_t SCSI_CheckAddressRange (uint8_t lun , uint32_t blk_offset , uint16_t blk_nbr)
{
 
  if ((blk_offset + blk_nbr) > SCSI_blk_nbr )  ///!!!!!!!!  <<< WHAT is here?
  {
    SCSI_SenseCode(lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE);
    return -1;
  }
  return 0;
}
(...)
The first function "SCSI_Verify10" calls the later one "SCSI_CheckAddressRange" which adds memory address in bytes to number of blocks (typical 1 block = 512 bytes) and compares to  maximum number of blocks?

May be it should be: if ((blk_offset / SCSI_blk_size + blk_nbr) > SCSI_blk_nbr )

Somebody got this example working?  "SCSI_CheckAddressRange" function is also used in some other SCSI processings...


Addition:

After closer look it seems that "SCSI_Verify10" is totally wrong (should be similar to Write10).  Fixing it "SCSI_CheckAddressRange" could be left as is.

Anyone from ST could confirm that? 

Outcomes