mirror of
https://github.com/STMicroelectronics/stm32-mw-usb-device.git
synced 2026-02-08 20:18:07 -05:00
Release v2.5.3
This commit is contained in:
@@ -12,16 +12,16 @@
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* http://www.st.com/SLA0044
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
- "stm32xxxxx_{eval}{discovery}{adafruit}_sd.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_msc_bot.h"
|
||||
@@ -78,22 +78,22 @@
|
||||
/** @defgroup MSC_SCSI_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params);
|
||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params);
|
||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
uint32_t blk_offset, uint32_t blk_nbr);
|
||||
static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
uint32_t blk_offset, uint32_t blk_nbr);
|
||||
|
||||
static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun);
|
||||
static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun);
|
||||
static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun);
|
||||
static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -116,57 +116,58 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd)
|
||||
{
|
||||
switch (cmd[0])
|
||||
{
|
||||
case SCSI_TEST_UNIT_READY:
|
||||
SCSI_TestUnitReady(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_TEST_UNIT_READY:
|
||||
SCSI_TestUnitReady(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_REQUEST_SENSE:
|
||||
SCSI_RequestSense (pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_INQUIRY:
|
||||
SCSI_Inquiry(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_REQUEST_SENSE:
|
||||
SCSI_RequestSense(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_INQUIRY:
|
||||
SCSI_Inquiry(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_START_STOP_UNIT:
|
||||
SCSI_StartStopUnit(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_START_STOP_UNIT:
|
||||
SCSI_StartStopUnit(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_ALLOW_MEDIUM_REMOVAL:
|
||||
SCSI_StartStopUnit(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_ALLOW_MEDIUM_REMOVAL:
|
||||
SCSI_StartStopUnit(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_MODE_SENSE6:
|
||||
SCSI_ModeSense6 (pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_MODE_SENSE6:
|
||||
SCSI_ModeSense6(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_MODE_SENSE10:
|
||||
SCSI_ModeSense10 (pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_MODE_SENSE10:
|
||||
SCSI_ModeSense10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_READ_FORMAT_CAPACITIES:
|
||||
SCSI_ReadFormatCapacity(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_READ_FORMAT_CAPACITIES:
|
||||
SCSI_ReadFormatCapacity(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_READ_CAPACITY10:
|
||||
SCSI_ReadCapacity10(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_READ_CAPACITY10:
|
||||
SCSI_ReadCapacity10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_READ10:
|
||||
SCSI_Read10(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_READ10:
|
||||
SCSI_Read10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_WRITE10:
|
||||
SCSI_Write10(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_WRITE10:
|
||||
SCSI_Write10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_VERIFY10:
|
||||
SCSI_Verify10(pdev, lun, cmd);
|
||||
break;
|
||||
case SCSI_VERIFY10:
|
||||
SCSI_Verify10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
default:
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB);
|
||||
return -1;
|
||||
default:
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -180,7 +181,7 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd)
|
||||
*/
|
||||
static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
/* case 9 : Hi > D0 */
|
||||
if (hmsc->cbw.dDataLength != 0U)
|
||||
@@ -190,7 +191,7 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
hmsc->bot_state = USBD_BOT_NO_DATA;
|
||||
@@ -211,9 +212,9 @@ static int8_t SCSI_TestUnitReady(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
*/
|
||||
static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
uint8_t* pPage;
|
||||
uint8_t *pPage;
|
||||
uint16_t len;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if (params[1] & 0x01U)/*Evpd is set*/
|
||||
{
|
||||
@@ -228,7 +229,7 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *par
|
||||
}
|
||||
else
|
||||
{
|
||||
pPage = (uint8_t *)(void *)&((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN];
|
||||
pPage = (uint8_t *)(void *) & ((USBD_StorageTypeDef *)pdev->pUserData)->pInquiry[lun * STANDARD_INQUIRY_DATA_LEN];
|
||||
len = (uint16_t)pPage[4] + 5U;
|
||||
|
||||
if (params[4] <= len)
|
||||
@@ -256,9 +257,9 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *par
|
||||
*/
|
||||
static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
@@ -289,18 +290,18 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_
|
||||
*/
|
||||
static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
uint16_t blk_size;
|
||||
uint32_t blk_nbr;
|
||||
uint16_t i;
|
||||
|
||||
for(i = 0U; i < 12U ; i++)
|
||||
for (i = 0U; i < 12U ; i++)
|
||||
{
|
||||
hmsc->bot_data[i] = 0U;
|
||||
}
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &blk_nbr, &blk_size) != 0U)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &blk_nbr, &blk_size) != 0U)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
@@ -329,9 +330,9 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef *pdev, uint8_t lun, ui
|
||||
* @param params: Command parameters
|
||||
* @retval status
|
||||
*/
|
||||
static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
uint16_t len = 8U;
|
||||
hmsc->bot_data_length = len;
|
||||
|
||||
@@ -350,10 +351,10 @@ static int8_t SCSI_ModeSense6 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *
|
||||
* @param params: Command parameters
|
||||
* @retval status
|
||||
*/
|
||||
static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
uint16_t len = 8U;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hmsc->bot_data_length = len;
|
||||
|
||||
@@ -374,20 +375,21 @@ static int8_t SCSI_ModeSense10 (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
static int8_t SCSI_RequestSense(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
uint8_t i;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
for(i = 0U ;i < REQUEST_SENSE_DATA_LEN; i++)
|
||||
for (i = 0U ; i < REQUEST_SENSE_DATA_LEN; i++)
|
||||
{
|
||||
hmsc->bot_data[i] = 0U;
|
||||
}
|
||||
|
||||
hmsc->bot_data[0] = 0x70U;
|
||||
hmsc->bot_data[7] = REQUEST_SENSE_DATA_LEN - 6U;
|
||||
hmsc->bot_data[0] = 0x70U;
|
||||
hmsc->bot_data[7] = REQUEST_SENSE_DATA_LEN - 6U;
|
||||
|
||||
if((hmsc->scsi_sense_head != hmsc->scsi_sense_tail)) {
|
||||
if ((hmsc->scsi_sense_head != hmsc->scsi_sense_tail))
|
||||
{
|
||||
|
||||
hmsc->bot_data[2] = hmsc->scsi_sense[hmsc->scsi_sense_head].Skey;
|
||||
hmsc->bot_data[12] = hmsc->scsi_sense[hmsc->scsi_sense_head].w.b.ASCQ;
|
||||
@@ -419,7 +421,7 @@ static int8_t SCSI_RequestSense (USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
*/
|
||||
void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_t ASC)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
|
||||
hmsc->scsi_sense[hmsc->scsi_sense_tail].Skey = sKey;
|
||||
hmsc->scsi_sense[hmsc->scsi_sense_tail].w.ASC = ASC << 8;
|
||||
@@ -438,7 +440,7 @@ void SCSI_SenseCode(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t sKey, uint8_
|
||||
*/
|
||||
static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
hmsc->bot_data_length = 0U;
|
||||
return 0;
|
||||
}
|
||||
@@ -452,9 +454,9 @@ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
*/
|
||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if(hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
||||
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
||||
{
|
||||
/* case 10 : Ho <> Di */
|
||||
if ((hmsc->cbw.bmFlags & 0x80U) != 0x80U)
|
||||
@@ -463,7 +465,7 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, MEDIUM_NOT_PRESENT);
|
||||
return -1;
|
||||
@@ -472,12 +474,12 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
(uint32_t)params[5];
|
||||
|
||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8];
|
||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8];
|
||||
|
||||
if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
@@ -504,9 +506,9 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params)
|
||||
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;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
uint32_t len;
|
||||
|
||||
if (hmsc->bot_state == USBD_BOT_IDLE) /* Idle */
|
||||
@@ -519,14 +521,14 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
||||
}
|
||||
|
||||
/* Check whether Media is ready */
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->IsReady(lun) != 0)
|
||||
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)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->IsWriteProtected(lun) != 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, NOT_READY, WRITE_PROTECTED);
|
||||
return -1;
|
||||
@@ -535,14 +537,14 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
(uint32_t)params[5];
|
||||
|
||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) |
|
||||
(uint32_t)params[8];
|
||||
(uint32_t)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)
|
||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
@@ -560,7 +562,7 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
||||
|
||||
/* Prepare EP to receive first data packet */
|
||||
hmsc->bot_state = USBD_BOT_DATA_OUT;
|
||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
||||
}
|
||||
else /* Write Process ongoing */
|
||||
{
|
||||
@@ -578,18 +580,18 @@ static int8_t SCSI_Write10 (USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *params)
|
||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if ((params[1]& 0x02U) == 0x02U)
|
||||
if ((params[1] & 0x02U) == 0x02U)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
return -1; /* Error, Verify Mode Not supported*/
|
||||
}
|
||||
|
||||
if(SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
@@ -605,10 +607,10 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun , uint8_t *pa
|
||||
* @param blk_nbr: number of block to be processed
|
||||
* @retval status
|
||||
*/
|
||||
static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
uint32_t blk_offset, uint32_t blk_nbr)
|
||||
static int8_t SCSI_CheckAddressRange(USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
uint32_t blk_offset, uint32_t blk_nbr)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr)
|
||||
{
|
||||
@@ -624,23 +626,23 @@ static int8_t SCSI_CheckAddressRange (USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
* @param lun: Logical unit number
|
||||
* @retval status
|
||||
*/
|
||||
static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*)pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassData;
|
||||
uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||
|
||||
len = MIN(len, MSC_MEDIA_PACKET);
|
||||
|
||||
if( ((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun,
|
||||
hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->Read(lun,
|
||||
hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
USBD_LL_Transmit (pdev, MSC_EPIN_ADDR, hmsc->bot_data, len);
|
||||
USBD_LL_Transmit(pdev, MSC_EPIN_ADDR, hmsc->bot_data, len);
|
||||
|
||||
hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size);
|
||||
hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size);
|
||||
@@ -662,16 +664,16 @@ static int8_t SCSI_ProcessRead (USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef*) pdev->pClassData;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *) pdev->pClassData;
|
||||
uint32_t len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||
|
||||
len = MIN(len, MSC_MEDIA_PACKET);
|
||||
|
||||
if(((USBD_StorageTypeDef *)pdev->pUserData)->Write(lun, hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData)->Write(lun, hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, WRITE_FAULT);
|
||||
|
||||
@@ -686,13 +688,13 @@ static int8_t SCSI_ProcessWrite (USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
|
||||
if (hmsc->scsi_blk_len == 0U)
|
||||
{
|
||||
MSC_BOT_SendCSW (pdev, USBD_CSW_CMD_PASSED);
|
||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = MIN((hmsc->scsi_blk_len * hmsc->scsi_blk_size), MSC_MEDIA_PACKET);
|
||||
/* Prepare EP to Receive next packet */
|
||||
USBD_LL_PrepareReceive (pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
||||
USBD_LL_PrepareReceive(pdev, MSC_EPOUT_ADDR, hmsc->bot_data, len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user