X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/071e02c6b6b4837fa9cf0b6d4c749994e02638d7..5f57785404e671f136f8c7e325922076d16fee30:/Demos/Device/LowLevel/MassStorage/Lib/SCSI.c diff --git a/Demos/Device/LowLevel/MassStorage/Lib/SCSI.c b/Demos/Device/LowLevel/MassStorage/Lib/SCSI.c index 10e6bc4a7..d718e7eea 100644 --- a/Demos/Device/LowLevel/MassStorage/Lib/SCSI.c +++ b/Demos/Device/LowLevel/MassStorage/Lib/SCSI.c @@ -136,8 +136,7 @@ bool SCSI_DecodeSCSICommand(void) */ static void SCSI_Command_Inquiry(void) { - uint16_t AllocationLength = (((uint16_t)CommandBlock.SCSICommandData[3] << 8) | - CommandBlock.SCSICommandData[4]); + uint16_t AllocationLength = SwapEndian_16(*(uint16_t*)&CommandBlock.SCSICommandData[3]); uint16_t BytesTransferred = (AllocationLength < sizeof(InquiryData))? AllocationLength : sizeof(InquiryData); @@ -159,7 +158,7 @@ static void SCSI_Command_Inquiry(void) uint8_t PadBytes[AllocationLength - BytesTransferred]; /* Pad out remaining bytes with 0x00 */ - Endpoint_Write_Stream_LE(&PadBytes, (AllocationLength - BytesTransferred), StreamCallback_AbortOnMassStoreReset); + Endpoint_Write_Stream_LE(&PadBytes, sizeof(PadBytes), StreamCallback_AbortOnMassStoreReset); /* Finalize the stream transfer to send the last packet */ Endpoint_ClearIN(); @@ -182,7 +181,7 @@ static void SCSI_Command_Request_Sense(void) uint8_t PadBytes[AllocationLength - BytesTransferred]; /* Pad out remaining bytes with 0x00 */ - Endpoint_Write_Stream_LE(&PadBytes, (AllocationLength - BytesTransferred), StreamCallback_AbortOnMassStoreReset); + Endpoint_Write_Stream_LE(&PadBytes, sizeof(PadBytes), StreamCallback_AbortOnMassStoreReset); /* Finalize the stream transfer to send the last packet */ Endpoint_ClearIN(); @@ -253,19 +252,9 @@ static void SCSI_Command_Send_Diagnostic(void) */ static void SCSI_Command_ReadWrite_10(const bool IsDataRead) { - uint32_t BlockAddress; - uint16_t TotalBlocks; - - /* Load in the 32-bit block address (SCSI uses big-endian, so have to do it byte-by-byte) */ - ((uint8_t*)&BlockAddress)[3] = CommandBlock.SCSICommandData[2]; - ((uint8_t*)&BlockAddress)[2] = CommandBlock.SCSICommandData[3]; - ((uint8_t*)&BlockAddress)[1] = CommandBlock.SCSICommandData[4]; - ((uint8_t*)&BlockAddress)[0] = CommandBlock.SCSICommandData[5]; - - /* Load in the 16-bit total blocks (SCSI uses big-endian, so have to do it byte-by-byte) */ - ((uint8_t*)&TotalBlocks)[1] = CommandBlock.SCSICommandData[7]; - ((uint8_t*)&TotalBlocks)[0] = CommandBlock.SCSICommandData[8]; - + uint32_t BlockAddress = SwapEndian_32(*(uint32_t*)&CommandBlock.SCSICommandData[2]); + uint16_t TotalBlocks = SwapEndian_16(*(uint16_t*)&CommandBlock.SCSICommandData[7]); + /* Check if the block address is outside the maximum allowable value for the LUN */ if (BlockAddress >= LUN_MEDIA_BLOCKS) {