X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/eb2e883fd35b5332a7425488105a7adb500ce3fe..a032d77d0e8009a3ef7e1666f144cde6f08f800e:/LUFA/Drivers/USB/Class/Host/MassStorageClassHost.c?ds=sidebyside diff --git a/LUFA/Drivers/USB/Class/Host/MassStorageClassHost.c b/LUFA/Drivers/USB/Class/Host/MassStorageClassHost.c index 96550cc3f..f145881fd 100644 --- a/LUFA/Drivers/USB/Class/Host/MassStorageClassHost.c +++ b/LUFA/Drivers/USB/Class/Host/MassStorageClassHost.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2011. + Copyright (C) Dean Camera, 2012. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ /* - Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -78,45 +78,19 @@ uint8_t MS_Host_ConfigurePipes(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, DataOUTEndpoint = EndpointData; } - for (uint8_t PipeNum = 1; PipeNum < PIPE_TOTAL_PIPES; PipeNum++) - { - uint16_t Size; - uint8_t Type; - uint8_t Token; - uint8_t EndpointAddress; - bool DoubleBanked; - - if (PipeNum == MSInterfaceInfo->Config.DataINPipeNumber) - { - Size = le16_to_cpu(DataINEndpoint->EndpointSize); - EndpointAddress = DataINEndpoint->EndpointAddress; - Token = PIPE_TOKEN_IN; - Type = EP_TYPE_BULK; - DoubleBanked = MSInterfaceInfo->Config.DataINPipeDoubleBank; - - MSInterfaceInfo->State.DataINPipeSize = DataINEndpoint->EndpointSize; - } - else if (PipeNum == MSInterfaceInfo->Config.DataOUTPipeNumber) - { - Size = le16_to_cpu(DataOUTEndpoint->EndpointSize); - EndpointAddress = DataOUTEndpoint->EndpointAddress; - Token = PIPE_TOKEN_OUT; - Type = EP_TYPE_BULK; - DoubleBanked = MSInterfaceInfo->Config.DataOUTPipeDoubleBank; - - MSInterfaceInfo->State.DataOUTPipeSize = DataOUTEndpoint->EndpointSize; - } - else - { - continue; - } - - if (!(Pipe_ConfigurePipe(PipeNum, Type, Token, EndpointAddress, Size, - DoubleBanked ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE))) - { - return MS_ENUMERROR_PipeConfigurationFailed; - } - } + MSInterfaceInfo->Config.DataINPipe.Size = le16_to_cpu(DataINEndpoint->EndpointSize); + MSInterfaceInfo->Config.DataINPipe.EndpointAddress = DataINEndpoint->EndpointAddress; + MSInterfaceInfo->Config.DataINPipe.Type = EP_TYPE_BULK; + + MSInterfaceInfo->Config.DataOUTPipe.Size = le16_to_cpu(DataOUTEndpoint->EndpointSize); + MSInterfaceInfo->Config.DataOUTPipe.EndpointAddress = DataOUTEndpoint->EndpointAddress; + MSInterfaceInfo->Config.DataOUTPipe.Type = EP_TYPE_BULK; + + if (!(Pipe_ConfigurePipeTable(&MSInterfaceInfo->Config.DataINPipe, 1))) + return false; + + if (!(Pipe_ConfigurePipeTable(&MSInterfaceInfo->Config.DataOUTPipe, 1))) + return false; MSInterfaceInfo->State.InterfaceNumber = MassStorageInterface->InterfaceNumber; MSInterfaceInfo->State.IsActive = true; @@ -178,26 +152,33 @@ static uint8_t MS_Host_SendCommand(USB_ClassInfo_MS_Host_t* const MSInterfaceInf SCSICommandBlock->Signature = CPU_TO_LE32(MS_CBW_SIGNATURE); SCSICommandBlock->Tag = cpu_to_le32(MSInterfaceInfo->State.TransactionTag); - Pipe_SelectPipe(MSInterfaceInfo->Config.DataOUTPipeNumber); + Pipe_SelectPipe(MSInterfaceInfo->Config.DataOUTPipe.Address); Pipe_Unfreeze(); if ((ErrorCode = Pipe_Write_Stream_LE(SCSICommandBlock, sizeof(MS_CommandBlockWrapper_t), NULL)) != PIPE_RWSTREAM_NoError) - return ErrorCode; + { + return ErrorCode; + } Pipe_ClearOUT(); Pipe_WaitUntilReady(); Pipe_Freeze(); - if ((BufferPtr != NULL) && - ((ErrorCode = MS_Host_SendReceiveData(MSInterfaceInfo, SCSICommandBlock, (void*)BufferPtr)) != PIPE_RWSTREAM_NoError)) + if (BufferPtr != NULL) { - Pipe_Freeze(); - return ErrorCode; + ErrorCode = MS_Host_SendReceiveData(MSInterfaceInfo, SCSICommandBlock, (void*)BufferPtr); + + if ((ErrorCode != PIPE_RWSTREAM_NoError) && (ErrorCode != PIPE_RWSTREAM_PipeStalled)) + { + Pipe_Freeze(); + return ErrorCode; + } } - return ErrorCode; + MS_CommandStatusWrapper_t SCSIStatusBlock; + return MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSIStatusBlock); } static uint8_t MS_Host_WaitForDataReceived(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo) @@ -205,7 +186,7 @@ static uint8_t MS_Host_WaitForDataReceived(USB_ClassInfo_MS_Host_t* const MSInte uint16_t TimeoutMSRem = MS_COMMAND_DATA_TIMEOUT_MS; uint16_t PreviousFrameNumber = USB_Host_GetFrameNumber(); - Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipeNumber); + Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipe.Address); Pipe_Unfreeze(); while (!(Pipe_IsINReceived())) @@ -221,7 +202,7 @@ static uint8_t MS_Host_WaitForDataReceived(USB_ClassInfo_MS_Host_t* const MSInte } Pipe_Freeze(); - Pipe_SelectPipe(MSInterfaceInfo->Config.DataOUTPipeNumber); + Pipe_SelectPipe(MSInterfaceInfo->Config.DataOUTPipe.Address); Pipe_Unfreeze(); if (Pipe_IsStalled()) @@ -231,7 +212,7 @@ static uint8_t MS_Host_WaitForDataReceived(USB_ClassInfo_MS_Host_t* const MSInte } Pipe_Freeze(); - Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipeNumber); + Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipe.Address); Pipe_Unfreeze(); if (Pipe_IsStalled()) @@ -244,10 +225,10 @@ static uint8_t MS_Host_WaitForDataReceived(USB_ClassInfo_MS_Host_t* const MSInte return PIPE_RWSTREAM_DeviceDisconnected; }; - Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipeNumber); + Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipe.Address); Pipe_Freeze(); - Pipe_SelectPipe(MSInterfaceInfo->Config.DataOUTPipeNumber); + Pipe_SelectPipe(MSInterfaceInfo->Config.DataOUTPipe.Address); Pipe_Freeze(); return PIPE_RWSTREAM_NoError; @@ -268,7 +249,7 @@ static uint8_t MS_Host_SendReceiveData(USB_ClassInfo_MS_Host_t* const MSInterfac return ErrorCode; } - Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipeNumber); + Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipe.Address); Pipe_Unfreeze(); if ((ErrorCode = Pipe_Read_Stream_LE(BufferPtr, BytesRem, NULL)) != PIPE_RWSTREAM_NoError) @@ -278,7 +259,7 @@ static uint8_t MS_Host_SendReceiveData(USB_ClassInfo_MS_Host_t* const MSInterfac } else { - Pipe_SelectPipe(MSInterfaceInfo->Config.DataOUTPipeNumber); + Pipe_SelectPipe(MSInterfaceInfo->Config.DataOUTPipe.Address); Pipe_Unfreeze(); if ((ErrorCode = Pipe_Write_Stream_LE(BufferPtr, BytesRem, NULL)) != PIPE_RWSTREAM_NoError) @@ -306,7 +287,7 @@ static uint8_t MS_Host_GetReturnedStatus(USB_ClassInfo_MS_Host_t* const MSInterf if ((ErrorCode = MS_Host_WaitForDataReceived(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError) return ErrorCode; - Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipeNumber); + Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipe.Address); Pipe_Unfreeze(); if ((ErrorCode = Pipe_Read_Stream_LE(SCSICommandStatus, sizeof(MS_CommandStatusWrapper_t), @@ -341,13 +322,13 @@ uint8_t MS_Host_ResetMSInterface(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo) if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful) return ErrorCode; - - Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipeNumber); - + + Pipe_SelectPipe(MSInterfaceInfo->Config.DataINPipe.Address); + if ((ErrorCode = USB_Host_ClearEndpointStall(Pipe_GetBoundEndpointAddress())) != HOST_SENDCONTROL_Successful) return ErrorCode; - Pipe_SelectPipe(MSInterfaceInfo->Config.DataOUTPipeNumber); + Pipe_SelectPipe(MSInterfaceInfo->Config.DataOUTPipe.Address); if ((ErrorCode = USB_Host_ClearEndpointStall(Pipe_GetBoundEndpointAddress())) != HOST_SENDCONTROL_Successful) return ErrorCode; @@ -358,7 +339,7 @@ uint8_t MS_Host_ResetMSInterface(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo) uint8_t MS_Host_GetMaxLUN(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, uint8_t* const MaxLUNIndex) { - uint8_t ErrorCode = HOST_SENDCONTROL_Successful; + uint8_t ErrorCode; USB_ControlRequest = (USB_Request_Header_t) { @@ -387,8 +368,6 @@ uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive)) return HOST_SENDCONTROL_DeviceDisconnected; - uint8_t ErrorCode; - MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t) { .DataTransferLength = CPU_TO_LE32(sizeof(SCSI_Inquiry_Response_t)), @@ -406,15 +385,7 @@ uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, } }; - MS_CommandStatusWrapper_t SCSICommandStatus; - - if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, InquiryData)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - return PIPE_RWSTREAM_NoError; + return MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, InquiryData); } uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, @@ -423,8 +394,6 @@ uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive)) return HOST_SENDCONTROL_DeviceDisconnected; - uint8_t ErrorCode; - MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t) { .DataTransferLength = CPU_TO_LE32(0), @@ -442,15 +411,7 @@ uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, } }; - MS_CommandStatusWrapper_t SCSICommandStatus; - - if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, NULL)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - return PIPE_RWSTREAM_NoError; + return MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, NULL); } uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, @@ -483,17 +444,12 @@ uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* const MSInterfaceInf } }; - MS_CommandStatusWrapper_t SCSICommandStatus; - if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, DeviceCapacity)) != PIPE_RWSTREAM_NoError) return ErrorCode; DeviceCapacity->Blocks = BE32_TO_CPU(DeviceCapacity->Blocks); DeviceCapacity->BlockSize = BE32_TO_CPU(DeviceCapacity->BlockSize); - if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - return PIPE_RWSTREAM_NoError; } @@ -504,8 +460,6 @@ uint8_t MS_Host_RequestSense(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive)) return HOST_SENDCONTROL_DeviceDisconnected; - uint8_t ErrorCode; - MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t) { .DataTransferLength = CPU_TO_LE32(sizeof(SCSI_Request_Sense_Response_t)), @@ -523,15 +477,7 @@ uint8_t MS_Host_RequestSense(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, } }; - MS_CommandStatusWrapper_t SCSICommandStatus; - - if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, SenseData)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - return PIPE_RWSTREAM_NoError; + return MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, SenseData); } uint8_t MS_Host_PreventAllowMediumRemoval(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, @@ -541,8 +487,6 @@ uint8_t MS_Host_PreventAllowMediumRemoval(USB_ClassInfo_MS_Host_t* const MSInter if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive)) return HOST_SENDCONTROL_DeviceDisconnected; - uint8_t ErrorCode; - MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t) { .DataTransferLength = CPU_TO_LE32(0), @@ -560,15 +504,7 @@ uint8_t MS_Host_PreventAllowMediumRemoval(USB_ClassInfo_MS_Host_t* const MSInter } }; - MS_CommandStatusWrapper_t SCSICommandStatus; - - if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, NULL)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - return PIPE_RWSTREAM_NoError; + return MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, NULL); } uint8_t MS_Host_ReadDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, @@ -581,8 +517,6 @@ uint8_t MS_Host_ReadDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive)) return HOST_SENDCONTROL_DeviceDisconnected; - uint8_t ErrorCode; - MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t) { .DataTransferLength = cpu_to_le32((uint32_t)Blocks * BlockSize), @@ -604,15 +538,7 @@ uint8_t MS_Host_ReadDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, } }; - MS_CommandStatusWrapper_t SCSICommandStatus; - - if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, BlockBuffer)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - return PIPE_RWSTREAM_NoError; + return MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, BlockBuffer); } uint8_t MS_Host_WriteDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo, @@ -625,8 +551,6 @@ uint8_t MS_Host_WriteDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.IsActive)) return HOST_SENDCONTROL_DeviceDisconnected; - uint8_t ErrorCode; - MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t) { .DataTransferLength = cpu_to_le32((uint32_t)Blocks * BlockSize), @@ -648,15 +572,7 @@ uint8_t MS_Host_WriteDeviceBlocks(USB_ClassInfo_MS_Host_t* const MSInterfaceInfo } }; - MS_CommandStatusWrapper_t SCSICommandStatus; - - if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, BlockBuffer)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError) - return ErrorCode; - - return PIPE_RWSTREAM_NoError; + return MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock, BlockBuffer); } #endif