// Process SCSI WRITE10 command // input: // pdev - pointer to the USB device handle // lun - logical unit number // params - pointer to the buffer with command parameters static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData; if (hmsc->bot_state == USBD_BOT_IDLE) { // case 8 : Hi <> Do if (hmsc->cbw.bmFlags & 0x80) { SCSI_SenseCode(pdev,hmsc->cbw.bLUN,ILLEGAL_REQUEST,INVALID_CDB); return -1; } // Check whether media is ready if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0) { SCSI_SenseCode(pdev,lun,NOT_READY,MEDIUM_NOT_PRESENT); return -1; } // Check if media is write-protected if (((USBD_StorageTypeDef *)pdev->pUserData)->IsWriteProtected(lun) != 0) { SCSI_SenseCode(pdev,lun,NOT_READY,WRITE_PROTECTED); return -1; } hmsc->scsi_blk_addr = (params[2] << 24) | (params[3] << 16) | (params[4] << 8) | params[5]; hmsc->scsi_blk_len = (params[7] << 8) | params[8]; // Check if LBA address is in the right range if (SCSI_CheckAddressRange(pdev,lun,hmsc->scsi_blk_addr,hmsc->scsi_blk_len) < 0) return -1; hmsc->scsi_blk_addr *= hmsc->scsi_blk_size; hmsc->scsi_blk_len *= hmsc->scsi_blk_size; // cases 3,11,13 : Hn,Ho <> D0 if (hmsc->cbw.dDataLength != hmsc->scsi_blk_len) { SCSI_SenseCode(pdev,hmsc->cbw.bLUN,ILLEGAL_REQUEST,INVALID_CDB); return -1; } // Prepare endpoint to receive first data packet hmsc->bot_state = USBD_BOT_DATA_OUT; USBD_LL_PrepareReceive(pdev,MSC_EPOUT_ADDR,hmsc->bot_data,MIN(hmsc->scsi_blk_len,MSC_MEDIA_PACKET)); } else { // Write Process ongoing return SCSI_ProcessWrite(pdev,lun); } return 0; }
static int8_t SCSI_Write10 (uint8_t lun , uint8_t *params) { if (MSC_BOT_State == BOT_IDLE) /* Idle */ { /* case 8 : Hi <> Do */ if ((MSC_BOT_cbw.bmFlags & 0x80) == 0x80) { SCSI_SenseCode(MSC_BOT_cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } /* Check whether Media is ready */ if(USBD_STORAGE_fops->IsReady(lun) !=0 ) { SCSI_SenseCode(lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; } /* Check If media is write-protected */ if(USBD_STORAGE_fops->IsWriteProtected(lun) !=0 ) { SCSI_SenseCode(lun, NOT_READY, WRITE_PROTECTED); return -1; } SCSI_blk_addr = (params[2] << 24) | \ (params[3] << 16) | \ (params[4] << 8) | \ params[5]; SCSI_blk_len = (params[7] << 8) | \ params[8]; /* check if LBA address is in the right range */ if(SCSI_CheckAddressRange(lun, SCSI_blk_addr, SCSI_blk_len) < 0) { return -1; /* error */ } SCSI_blk_addr *= SCSI_blk_size; SCSI_blk_len *= SCSI_blk_size; /* cases 3,11,13 : Hn,Ho <> D0 */ if (MSC_BOT_cbw.dDataLength != SCSI_blk_len) { SCSI_SenseCode(MSC_BOT_cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } /* Prepare EP to receive first data packet */ MSC_BOT_State = BOT_DATA_OUT; DCD_EP_PrepareRx (cdev, MSC_OUT_EP, MSC_BOT_Data, MIN (SCSI_blk_len, MSC_MEDIA_PACKET)); } else /* Write Process ongoing */ { return SCSI_ProcessWrite(lun); } return 0; }
static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params) { USBD_MSC_BOT_HandleTypeDef *hmsc = pdev->pClassData; if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */ { /* case 8 : Hi <> Do */ if ((hmsc->cbw.bmFlags & 0x80) == 0x80) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } /* Check whether Media is ready */ if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) !=0 ) { SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT); return -1; } /* Check If media is write-protected */ if(((USBD_StorageTypeDef *)pdev->pUserData)->IsWriteProtected(lun) !=0 ) { SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED); return -1; } hmsc->scsi_blk_addr_in_blks = (params[2] << 24) | \ (params[3] << 16) | \ (params[4] << 8) | \ params[5]; hmsc->scsi_blk_len = (params[7] << 8) | \ params[8]; /* check if LBA address is in the right range */ if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr_in_blks, hmsc->scsi_blk_len) < 0) { return -1; /* error */ } hmsc->scsi_blk_len *= hmsc->scsi_blk_size; /* cases 3,11,13 : Hn,Ho <> D0 */ if (hmsc->cbw.dDataLength != hmsc->scsi_blk_len) { SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB); return -1; } /* Prepare EP to receive first data packet */ hmsc->bot_state = USBD_BOT_DATA_OUT; USBD_LL_PrepareReceive (pdev, MSC_OUT_EP, hmsc->bot_data, MIN (hmsc->scsi_blk_len, MSC_MEDIA_PACKET)); } else /* Write Process ongoing */ { return SCSI_ProcessWrite(pdev, lun); } return 0; }