mirror of
https://github.com/STMicroelectronics/stm32-mw-usb-device.git
synced 2026-02-08 20:18:07 -05:00
Release v2.11.4
This commit is contained in:
@@ -92,6 +92,8 @@ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_Read12(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_ReportLuns(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params);
|
||||
static int8_t SCSI_ReceiveDiagnosticResults(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);
|
||||
|
||||
@@ -190,9 +192,16 @@ int8_t SCSI_ProcessCmd(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *cmd)
|
||||
ret = SCSI_Verify10(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_REPORT_LUNS:
|
||||
ret = SCSI_ReportLuns(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
case SCSI_RECEIVE_DIAGNOSTIC_RESULTS:
|
||||
ret = SCSI_ReceiveDiagnosticResults(pdev, lun, cmd);
|
||||
break;
|
||||
|
||||
default:
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_CDB);
|
||||
hmsc->bot_status = USBD_BOT_STATUS_ERROR;
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
@@ -283,7 +292,7 @@ static int8_t SCSI_Inquiry(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
||||
else /* Request Not supported */
|
||||
{
|
||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST,
|
||||
INVALID_FIELED_IN_COMMAND);
|
||||
INVALID_FIELD_IN_COMMAND);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -319,14 +328,15 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
UNUSED(params);
|
||||
int8_t ret;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &hmsc->scsi_blk_nbr,
|
||||
&hmsc->scsi_blk_size);
|
||||
ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &p_scsi_blk->nbr,
|
||||
&p_scsi_blk->size);
|
||||
|
||||
if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED))
|
||||
{
|
||||
@@ -334,20 +344,19 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
return -1;
|
||||
}
|
||||
|
||||
hmsc->bot_data[0] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 24);
|
||||
hmsc->bot_data[1] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 16);
|
||||
hmsc->bot_data[2] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 8);
|
||||
hmsc->bot_data[3] = (uint8_t)(hmsc->scsi_blk_nbr - 1U);
|
||||
hmsc->bot_data[0] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 24);
|
||||
hmsc->bot_data[1] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 16);
|
||||
hmsc->bot_data[2] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 8);
|
||||
hmsc->bot_data[3] = (uint8_t)(p_scsi_blk->nbr - 1U);
|
||||
|
||||
hmsc->bot_data[4] = (uint8_t)(hmsc->scsi_blk_size >> 24);
|
||||
hmsc->bot_data[5] = (uint8_t)(hmsc->scsi_blk_size >> 16);
|
||||
hmsc->bot_data[6] = (uint8_t)(hmsc->scsi_blk_size >> 8);
|
||||
hmsc->bot_data[7] = (uint8_t)(hmsc->scsi_blk_size);
|
||||
hmsc->bot_data[4] = (uint8_t)(p_scsi_blk->size >> 24);
|
||||
hmsc->bot_data[5] = (uint8_t)(p_scsi_blk->size >> 16);
|
||||
hmsc->bot_data[6] = (uint8_t)(p_scsi_blk->size >> 8);
|
||||
hmsc->bot_data[7] = (uint8_t)(p_scsi_blk->size);
|
||||
|
||||
hmsc->bot_data_length = 8U;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -364,14 +373,15 @@ static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
uint32_t idx;
|
||||
int8_t ret;
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &hmsc->scsi_blk_nbr,
|
||||
&hmsc->scsi_blk_size);
|
||||
ret = ((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->GetCapacity(lun, &p_scsi_blk->nbr,
|
||||
&p_scsi_blk->size);
|
||||
|
||||
if ((ret != 0) || (hmsc->scsi_medium_state == SCSI_MEDIUM_EJECTED))
|
||||
{
|
||||
@@ -389,15 +399,15 @@ static int8_t SCSI_ReadCapacity16(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
hmsc->bot_data[idx] = 0U;
|
||||
}
|
||||
|
||||
hmsc->bot_data[4] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 24);
|
||||
hmsc->bot_data[5] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 16);
|
||||
hmsc->bot_data[6] = (uint8_t)((hmsc->scsi_blk_nbr - 1U) >> 8);
|
||||
hmsc->bot_data[7] = (uint8_t)(hmsc->scsi_blk_nbr - 1U);
|
||||
hmsc->bot_data[4] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 24);
|
||||
hmsc->bot_data[5] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 16);
|
||||
hmsc->bot_data[6] = (uint8_t)((p_scsi_blk->nbr - 1U) >> 8);
|
||||
hmsc->bot_data[7] = (uint8_t)(p_scsi_blk->nbr - 1U);
|
||||
|
||||
hmsc->bot_data[8] = (uint8_t)(hmsc->scsi_blk_size >> 24);
|
||||
hmsc->bot_data[9] = (uint8_t)(hmsc->scsi_blk_size >> 16);
|
||||
hmsc->bot_data[10] = (uint8_t)(hmsc->scsi_blk_size >> 8);
|
||||
hmsc->bot_data[11] = (uint8_t)(hmsc->scsi_blk_size);
|
||||
hmsc->bot_data[8] = (uint8_t)(p_scsi_blk->size >> 24);
|
||||
hmsc->bot_data[9] = (uint8_t)(p_scsi_blk->size >> 16);
|
||||
hmsc->bot_data[10] = (uint8_t)(p_scsi_blk->size >> 8);
|
||||
hmsc->bot_data[11] = (uint8_t)(p_scsi_blk->size);
|
||||
|
||||
hmsc->bot_data_length = ((uint32_t)params[10] << 24) |
|
||||
((uint32_t)params[11] << 16) |
|
||||
@@ -480,7 +490,11 @@ static int8_t SCSI_ModeSense6(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *pa
|
||||
/* Check If media is write-protected */
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0)
|
||||
{
|
||||
MSC_Mode_Sense6_data[2] |= 0x80U;
|
||||
MSC_Mode_Sense6_data[2] |= (0x1U << 7); /* Set the WP (write protection) bit */
|
||||
}
|
||||
else
|
||||
{
|
||||
MSC_Mode_Sense10_data[2] &= ~(0x1U << 7); /* Clear the WP (write protection) bit */
|
||||
}
|
||||
|
||||
if (params[4] <= len)
|
||||
@@ -515,7 +529,11 @@ static int8_t SCSI_ModeSense10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *p
|
||||
/* Check If media is write-protected */
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->IsWriteProtected(lun) != 0)
|
||||
{
|
||||
MSC_Mode_Sense10_data[3] |= 0x80U;
|
||||
MSC_Mode_Sense10_data[3] |= (0x1U << 7); /* Set the WP (write protection) bit */
|
||||
}
|
||||
else
|
||||
{
|
||||
MSC_Mode_Sense10_data[3] &= ~(0x1U << 7); /* Clear the WP (write protection) bit */
|
||||
}
|
||||
|
||||
if (params[8] <= len)
|
||||
@@ -635,7 +653,7 @@ static int8_t SCSI_StartStopUnit(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t
|
||||
|
||||
if ((hmsc->scsi_medium_state == SCSI_MEDIUM_LOCKED) && ((params[4] & 0x3U) == 2U))
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELD_IN_COMMAND);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -704,6 +722,7 @@ static int8_t SCSI_AllowPreventRemovable(USBD_HandleTypeDef *pdev, uint8_t lun,
|
||||
static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
@@ -732,21 +751,20 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
||||
return -1;
|
||||
}
|
||||
|
||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
p_scsi_blk->addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
|
||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) | (uint32_t)params[8];
|
||||
p_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, p_scsi_blk->addr, p_scsi_blk->len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
|
||||
/* cases 4,5 : Hi <> Dn */
|
||||
if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size))
|
||||
if (hmsc->cbw.dDataLength != (p_scsi_blk->len * p_scsi_blk->size))
|
||||
{
|
||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
||||
return -1;
|
||||
@@ -770,6 +788,7 @@ static int8_t SCSI_Read10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
||||
static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
@@ -797,24 +816,23 @@ static int8_t SCSI_Read12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params
|
||||
return -1;
|
||||
}
|
||||
|
||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
p_scsi_blk->addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
|
||||
hmsc->scsi_blk_len = ((uint32_t)params[6] << 24) |
|
||||
((uint32_t)params[7] << 16) |
|
||||
((uint32_t)params[8] << 8) |
|
||||
(uint32_t)params[9];
|
||||
p_scsi_blk->len = ((uint32_t)params[6] << 24) |
|
||||
((uint32_t)params[7] << 16) |
|
||||
((uint32_t)params[8] << 8) |
|
||||
(uint32_t)params[9];
|
||||
|
||||
if (SCSI_CheckAddressRange(pdev, lun, hmsc->scsi_blk_addr,
|
||||
hmsc->scsi_blk_len) < 0)
|
||||
if (SCSI_CheckAddressRange(pdev, lun, p_scsi_blk->addr, p_scsi_blk->len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
|
||||
/* cases 4,5 : Hi <> Dn */
|
||||
if (hmsc->cbw.dDataLength != (hmsc->scsi_blk_len * hmsc->scsi_blk_size))
|
||||
if (hmsc->cbw.dDataLength != (p_scsi_blk->len * p_scsi_blk->size))
|
||||
{
|
||||
SCSI_SenseCode(pdev, hmsc->cbw.bLUN, ILLEGAL_REQUEST, INVALID_CDB);
|
||||
return -1;
|
||||
@@ -838,6 +856,7 @@ static int8_t SCSI_Read12(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->pClassDataCmsit[pdev->classId];
|
||||
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||
uint32_t len;
|
||||
|
||||
if (hmsc == NULL)
|
||||
@@ -879,22 +898,21 @@ static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
||||
return -1;
|
||||
}
|
||||
|
||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
p_scsi_blk->addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
|
||||
hmsc->scsi_blk_len = ((uint32_t)params[7] << 8) |
|
||||
(uint32_t)params[8];
|
||||
p_scsi_blk->len = ((uint32_t)params[7] << 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, p_scsi_blk->addr, p_scsi_blk->len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
|
||||
len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||
len = p_scsi_blk->len * p_scsi_blk->size;
|
||||
|
||||
/* cases 3,11,13 : Hn,Ho <> D0 */
|
||||
if (hmsc->cbw.dDataLength != len)
|
||||
@@ -928,6 +946,7 @@ static int8_t SCSI_Write10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
||||
static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||
uint32_t len;
|
||||
|
||||
if (hmsc == NULL)
|
||||
@@ -970,24 +989,23 @@ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
||||
return -1;
|
||||
}
|
||||
|
||||
hmsc->scsi_blk_addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
p_scsi_blk->addr = ((uint32_t)params[2] << 24) |
|
||||
((uint32_t)params[3] << 16) |
|
||||
((uint32_t)params[4] << 8) |
|
||||
(uint32_t)params[5];
|
||||
|
||||
hmsc->scsi_blk_len = ((uint32_t)params[6] << 24) |
|
||||
((uint32_t)params[7] << 16) |
|
||||
((uint32_t)params[8] << 8) |
|
||||
(uint32_t)params[9];
|
||||
p_scsi_blk->len = ((uint32_t)params[6] << 24) |
|
||||
((uint32_t)params[7] << 16) |
|
||||
((uint32_t)params[8] << 8) |
|
||||
(uint32_t)params[9];
|
||||
|
||||
/* 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, p_scsi_blk->addr, p_scsi_blk->len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
|
||||
len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||
len = p_scsi_blk->len * p_scsi_blk->size;
|
||||
|
||||
/* cases 3,11,13 : Hn,Ho <> D0 */
|
||||
if (hmsc->cbw.dDataLength != len)
|
||||
@@ -1021,6 +1039,7 @@ static int8_t SCSI_Write12(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *param
|
||||
static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
@@ -1029,11 +1048,11 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *para
|
||||
|
||||
if ((params[1] & 0x02U) == 0x02U)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELED_IN_COMMAND);
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, INVALID_FIELD_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, p_scsi_blk->addr, p_scsi_blk->len) < 0)
|
||||
{
|
||||
return -1; /* error */
|
||||
}
|
||||
@@ -1043,6 +1062,90 @@ static int8_t SCSI_Verify10(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *para
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SCSI_ReportLuns12
|
||||
* Process ReportLuns command
|
||||
* @retval status
|
||||
*/
|
||||
static int8_t SCSI_ReportLuns(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc;
|
||||
uint32_t lun_list_length;
|
||||
uint32_t total_length;
|
||||
uint8_t lun_idx;
|
||||
|
||||
UNUSED(lun);
|
||||
UNUSED(params);
|
||||
|
||||
/* Define the report LUNs buffer Each LUN entry is 8 bytes */
|
||||
static uint8_t lun_report[8U * (MSC_BOT_MAX_LUN + 1U)];
|
||||
|
||||
hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Initialize the report LUNs buffer */
|
||||
(void)USBD_memset(lun_report, 0, sizeof(lun_report));
|
||||
|
||||
/* Set the LUN list length in the first 4 bytes */
|
||||
lun_list_length = 8U * (hmsc->max_lun + 1U);
|
||||
lun_report[0] = (uint8_t)(lun_list_length >> 24);
|
||||
lun_report[1] = (uint8_t)(lun_list_length >> 16);
|
||||
lun_report[2] = (uint8_t)(lun_list_length >> 8);
|
||||
lun_report[3] = (uint8_t)(lun_list_length & 0xFFU);
|
||||
|
||||
/* Update the LUN list */
|
||||
for (lun_idx = 0U; lun_idx <= hmsc->max_lun; lun_idx++)
|
||||
{
|
||||
/* LUN identifier is placed at the second byte of each 8-byte entry */
|
||||
lun_report[(8U * (lun_idx + 1U)) + 1U] = lun_idx;
|
||||
}
|
||||
|
||||
/* Calculate the total length of the report LUNs buffer */
|
||||
total_length = lun_list_length + 8U;
|
||||
|
||||
/* Update the BOT data with the report LUNs buffer */
|
||||
(void)SCSI_UpdateBotData(hmsc, lun_report, (uint16_t)total_length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SCSI_ReceiveDiagnosticResults
|
||||
* Process SCSI_Receive Diagnostic Results command
|
||||
* @param lun: Logical unit number
|
||||
* @param params: Command parameters
|
||||
* @retval status
|
||||
*/
|
||||
static int8_t SCSI_ReceiveDiagnosticResults(USBD_HandleTypeDef *pdev, uint8_t lun, uint8_t *params)
|
||||
{
|
||||
UNUSED(lun);
|
||||
USBD_MSC_BOT_HandleTypeDef *hmsc = (USBD_MSC_BOT_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
|
||||
uint16_t allocation_length;
|
||||
|
||||
/* Extract the allocation length from the CDB */
|
||||
allocation_length = (((uint16_t)params[3] << 8) | (uint16_t)params[4]);
|
||||
|
||||
if (allocation_length == 0U)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Ensure the allocation length does not exceed the diagnostic data length */
|
||||
if (allocation_length > DIAGNOSTIC_DATA_LEN)
|
||||
{
|
||||
allocation_length = DIAGNOSTIC_DATA_LEN;
|
||||
}
|
||||
|
||||
/* Send the diagnostic data to the host */
|
||||
(void)SCSI_UpdateBotData(hmsc, MSC_Diagnostic_Data, allocation_length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SCSI_CheckAddressRange
|
||||
* Check address range
|
||||
@@ -1055,13 +1158,14 @@ 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->pClassDataCmsit[pdev->classId];
|
||||
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||
|
||||
if (hmsc == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((blk_offset + blk_nbr) > hmsc->scsi_blk_nbr)
|
||||
if ((blk_offset + blk_nbr) > p_scsi_blk->nbr)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, ILLEGAL_REQUEST, ADDRESS_OUT_OF_RANGE);
|
||||
return -1;
|
||||
@@ -1079,6 +1183,7 @@ static int8_t SCSI_CheckAddressRange(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->pClassDataCmsit[pdev->classId];
|
||||
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||
uint32_t len;
|
||||
|
||||
if (hmsc == NULL)
|
||||
@@ -1086,7 +1191,7 @@ static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||
len = p_scsi_blk->len * p_scsi_blk->size;
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
@@ -1096,8 +1201,8 @@ static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
len = MIN(len, MSC_MEDIA_PACKET);
|
||||
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Read(lun, hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
p_scsi_blk->addr,
|
||||
(len / p_scsi_blk->size)) < 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, UNRECOVERED_READ_ERROR);
|
||||
return -1;
|
||||
@@ -1105,13 +1210,13 @@ static int8_t SCSI_ProcessRead(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
|
||||
(void)USBD_LL_Transmit(pdev, MSCInEpAdd, hmsc->bot_data, len);
|
||||
|
||||
hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size);
|
||||
hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size);
|
||||
p_scsi_blk->addr += (len / p_scsi_blk->size);
|
||||
p_scsi_blk->len -= (len / p_scsi_blk->size);
|
||||
|
||||
/* case 6 : Hi = Di */
|
||||
hmsc->csw.dDataResidue -= len;
|
||||
|
||||
if (hmsc->scsi_blk_len == 0U)
|
||||
if (p_scsi_blk->len == 0U)
|
||||
{
|
||||
hmsc->bot_state = USBD_BOT_LAST_DATA_IN;
|
||||
}
|
||||
@@ -1128,6 +1233,7 @@ static int8_t SCSI_ProcessRead(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->pClassDataCmsit[pdev->classId];
|
||||
USBD_MSC_BOT_LUN_TypeDef *p_scsi_blk = &hmsc->scsi_blk[lun];
|
||||
uint32_t len;
|
||||
|
||||
if (hmsc == NULL)
|
||||
@@ -1135,7 +1241,7 @@ static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = hmsc->scsi_blk_len * hmsc->scsi_blk_size;
|
||||
len = p_scsi_blk->len * p_scsi_blk->size;
|
||||
|
||||
#ifdef USE_USBD_COMPOSITE
|
||||
/* Get the Endpoints addresses allocated for this class instance */
|
||||
@@ -1144,27 +1250,26 @@ static int8_t SCSI_ProcessWrite(USBD_HandleTypeDef *pdev, uint8_t lun)
|
||||
|
||||
len = MIN(len, MSC_MEDIA_PACKET);
|
||||
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Write(lun, hmsc->bot_data,
|
||||
hmsc->scsi_blk_addr,
|
||||
(len / hmsc->scsi_blk_size)) < 0)
|
||||
if (((USBD_StorageTypeDef *)pdev->pUserData[pdev->classId])->Write(lun, hmsc->bot_data, p_scsi_blk->addr,
|
||||
(len / p_scsi_blk->size)) < 0)
|
||||
{
|
||||
SCSI_SenseCode(pdev, lun, HARDWARE_ERROR, WRITE_FAULT);
|
||||
return -1;
|
||||
}
|
||||
|
||||
hmsc->scsi_blk_addr += (len / hmsc->scsi_blk_size);
|
||||
hmsc->scsi_blk_len -= (len / hmsc->scsi_blk_size);
|
||||
p_scsi_blk->addr += (len / p_scsi_blk->size);
|
||||
p_scsi_blk->len -= (len / p_scsi_blk->size);
|
||||
|
||||
/* case 12 : Ho = Do */
|
||||
hmsc->csw.dDataResidue -= len;
|
||||
|
||||
if (hmsc->scsi_blk_len == 0U)
|
||||
if (p_scsi_blk->len == 0U)
|
||||
{
|
||||
MSC_BOT_SendCSW(pdev, USBD_CSW_CMD_PASSED);
|
||||
}
|
||||
else
|
||||
{
|
||||
len = MIN((hmsc->scsi_blk_len * hmsc->scsi_blk_size), MSC_MEDIA_PACKET);
|
||||
len = MIN((p_scsi_blk->len * p_scsi_blk->size), MSC_MEDIA_PACKET);
|
||||
|
||||
/* Prepare EP to Receive next packet */
|
||||
(void)USBD_LL_PrepareReceive(pdev, MSCOutEpAdd, hmsc->bot_data, len);
|
||||
|
||||
Reference in New Issue
Block a user