msc handle more test, passed Command Self Test compliant

This commit is contained in:
hathach 2021-08-29 12:06:10 +07:00
parent ad21b69277
commit ee18cc42f2

View File

@ -373,7 +373,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
// 6.7 The 13 Cases: case 2 (Hn < Di), case 3 (Hn < Do), case 10 (Ho <> Di) -> phase error // 6.7 The 13 Cases: case 2 (Hn < Di), case 3 (Hn < Do), case 10 (Ho <> Di) -> phase error
if ( rdwr10_get_blocksize(p_cbw) == 0 || !is_data_in(p_cbw->dir) ) if ( rdwr10_get_blocksize(p_cbw) == 0 || !is_data_in(p_cbw->dir) )
{ {
TU_LOG(MSC_DEBUG, " SCSI ase 2 (Hn < Di), case 3 (Hn < Do), case 10 (Ho <> Di)\r\n"); TU_LOG(MSC_DEBUG, " SCSI case 2 (Hn < Di), case 3 (Hn < Do), case 10 (Ho <> Di)\r\n");
fail_scsi_op(rhport, p_msc, MSC_CSW_STATUS_PHASE_ERROR); fail_scsi_op(rhport, p_msc, MSC_CSW_STATUS_PHASE_ERROR);
}else }else
{ {
@ -386,7 +386,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
// 6.7 The 13 Cases: case 2 (Hn < Do), case 3 (Hn < Do), case 8 (Hi <> Do) -> phase error // 6.7 The 13 Cases: case 2 (Hn < Do), case 3 (Hn < Do), case 8 (Hi <> Do) -> phase error
if ( rdwr10_get_blocksize(p_cbw) == 0 || is_data_in(p_cbw->dir) ) if ( rdwr10_get_blocksize(p_cbw) == 0 || is_data_in(p_cbw->dir) )
{ {
TU_LOG(MSC_DEBUG, " SCSI ase 2 (Hn < Di), case 3 (Hn < Do), case 8 (Hi <> Do)\r\n"); TU_LOG(MSC_DEBUG, " SCSI case 2 (Hn < Di), case 3 (Hn < Do), case 8 (Hi <> Do)\r\n");
fail_scsi_op(rhport, p_msc, MSC_CSW_STATUS_PHASE_ERROR); fail_scsi_op(rhport, p_msc, MSC_CSW_STATUS_PHASE_ERROR);
}else }else
{ {
@ -400,11 +400,16 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
// 2. IN & Zero: Process if is built-in, else Invoke app callback. Skip DATA if zero length // 2. IN & Zero: Process if is built-in, else Invoke app callback. Skip DATA if zero length
if ( (p_cbw->total_bytes > 0 ) && !is_data_in(p_cbw->dir) ) if ( (p_cbw->total_bytes > 0 ) && !is_data_in(p_cbw->dir) )
{ {
// Didn't check for case 9 (Ho > Dn), which requires examining scsi command first if (p_cbw->total_bytes > sizeof(_mscd_buf))
// but it is OK to just receive data then responded with failed status {
TU_LOG(MSC_DEBUG, " SCSI reject non READ10/WRITE10 with large data\r\n");
// Prepare for Data stage fail_scsi_op(rhport, p_msc, MSC_CSW_STATUS_FAILED);
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) ); }else
{
// Didn't check for case 9 (Ho > Dn), which requires examining scsi command first
// but it is OK to just receive data then responded with failed status
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
}
}else }else
{ {
// First process if it is a built-in commands // First process if it is a built-in commands
@ -483,11 +488,12 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
if ( cb_result < 0 ) if ( cb_result < 0 )
{ {
p_csw->status = MSC_CSW_STATUS_FAILED; // unsupported command
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation TU_LOG(MSC_DEBUG, " SCSI unsupported command\r\n");
fail_scsi_op(rhport, p_msc, MSC_CSW_STATUS_FAILED);
}else }else
{ {
p_csw->status = MSC_CSW_STATUS_PASSED; // TODO haven't implement this scenario any further yet
} }
} }
@ -500,7 +506,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
} }
else else
{ {
// No command take more than one transfer yet -> unlikely error // This scenario with command that take more than one transfer is already rejected at Command stage
TU_BREAKPOINT(); TU_BREAKPOINT();
} }
} }