aboutsummaryrefslogtreecommitdiffstats
path: root/LUFA/Drivers
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2009-08-26 08:20:55 +0000
committerDean Camera <dean@fourwalledcubicle.com>2009-08-26 08:20:55 +0000
commit559ca2ba046e47faa54f0845339f0385a5cfbb26 (patch)
tree774fb6a1eb6edcbeb20fea8b09136ecfebe0363d /LUFA/Drivers
parenta765f717273728139966f97c634ccffe52d218df (diff)
downloadlufa-559ca2ba046e47faa54f0845339f0385a5cfbb26.tar.gz
lufa-559ca2ba046e47faa54f0845339f0385a5cfbb26.tar.bz2
lufa-559ca2ba046e47faa54f0845339f0385a5cfbb26.zip
Added MS_Host_TestUnitReady() and MS_Host_ReadDeviceCapacity() to the host mode Mass Storage Class driver.
Diffstat (limited to 'LUFA/Drivers')
-rw-r--r--LUFA/Drivers/USB/Class/Host/MassStorage.c135
-rw-r--r--LUFA/Drivers/USB/Class/Host/MassStorage.h15
2 files changed, 137 insertions, 13 deletions
diff --git a/LUFA/Drivers/USB/Class/Host/MassStorage.c b/LUFA/Drivers/USB/Class/Host/MassStorage.c
index 1610e422a..4c23e8153 100644
--- a/LUFA/Drivers/USB/Class/Host/MassStorage.c
+++ b/LUFA/Drivers/USB/Class/Host/MassStorage.c
@@ -328,41 +328,154 @@ uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t
.SCSICommandData =
{
SCSI_CMD_INQUIRY,
- 0x00, // Reserved
- 0x00, // Reserved
- 0x00, // Reserved
+ 0x00, // Reserved
+ 0x00, // Reserved
+ 0x00, // Reserved
sizeof(SCSI_Inquiry_Response_t), // Allocation Length
- 0x00 // Unused (control)
+ 0x00 // Unused (control)
}
};
- MassStore_SendCommand(MSInterfaceInfo, &SCSICommandBlock);
-
- if ((ErrorCode = MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError)
+ if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock)) != PIPE_RWSTREAM_NoError)
+ {
+ Pipe_Freeze();
+ return ErrorCode;
+ }
+
+ if ((ErrorCode = MS_Host_WaitForDataReceived(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError)
{
Pipe_Freeze();
return ErrorCode;
}
- if ((ErrorCode = MassStore_SendReceiveData(MSInterfaceInfo, (uint8_t*)InquiryPtr)) != PIPE_RWSTREAM_NoError)
+ if ((ErrorCode = MS_Host_SendReceiveData(MSInterfaceInfo, &SCSICommandBlock, InquiryData)) != PIPE_RWSTREAM_NoError)
{
Pipe_Freeze();
return ErrorCode;
}
- if ((ErrorCode = MassStore_GetReturnedStatus(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError)
+ MS_CommandStatusWrapper_t SCSICommandStatus;
+ if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)
{
Pipe_Freeze();
return ErrorCode;
}
+ if (SCSICommandStatus.Status != SCSI_Command_Pass)
+ ErrorCode = MS_ERROR_LOGICAL_CMD_FAILED;
+
return ErrorCode;
}
-uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, bool* DeviceReady);
+uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex)
+{
+ if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.Active))
+ return HOST_SENDCONTROL_DeviceDisconnect;
+
+ uint8_t ErrorCode = PIPE_RWSTREAM_NoError;
+
+ MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
+ {
+ .Signature = CBW_SIGNATURE,
+ .Tag = MSInterfaceInfo->State.TransactionTag,
+ .DataTransferLength = 0,
+ .Flags = COMMAND_DIRECTION_DATA_IN,
+ .LUN = LUNIndex,
+ .SCSICommandLength = 6,
+ .SCSICommandData =
+ {
+ SCSI_CMD_TEST_UNIT_READY,
+ 0x00, // Reserved
+ 0x00, // Reserved
+ 0x00, // Reserved
+ 0x00, // Reserved
+ 0x00 // Unused (control)
+ }
+ };
+
+ if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock)) != PIPE_RWSTREAM_NoError)
+ {
+ Pipe_Freeze();
+ return ErrorCode;
+ }
+
+ MS_CommandStatusWrapper_t SCSICommandStatus;
+ if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)
+ {
+ Pipe_Freeze();
+ return ErrorCode;
+ }
+
+ if (SCSICommandStatus.Status != SCSI_Command_Pass)
+ ErrorCode = MS_ERROR_LOGICAL_CMD_FAILED;
+
+ return ErrorCode;
+}
uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,
- SCSI_Capacity_t* DeviceCapacity);
+ SCSI_Capacity_t* DeviceCapacity)
+{
+ if ((USB_HostState != HOST_STATE_Configured) || !(MSInterfaceInfo->State.Active))
+ return HOST_SENDCONTROL_DeviceDisconnect;
+
+ uint8_t ErrorCode = PIPE_RWSTREAM_NoError;
+
+ MS_CommandBlockWrapper_t SCSICommandBlock = (MS_CommandBlockWrapper_t)
+ {
+ .Signature = CBW_SIGNATURE,
+ .Tag = MSInterfaceInfo->State.TransactionTag,
+ .DataTransferLength = sizeof(SCSI_Capacity_t),
+ .Flags = COMMAND_DIRECTION_DATA_IN,
+ .LUN = LUNIndex,
+ .SCSICommandLength = 10,
+ .SCSICommandData =
+ {
+ SCSI_CMD_READ_CAPACITY_10,
+ 0x00, // Reserved
+ 0x00, // MSB of Logical block address
+ 0x00,
+ 0x00,
+ 0x00, // LSB of Logical block address
+ 0x00, // Reserved
+ 0x00, // Reserved
+ 0x00, // Partial Medium Indicator
+ 0x00 // Unused (control)
+ }
+ };
+
+ if ((ErrorCode = MS_Host_SendCommand(MSInterfaceInfo, &SCSICommandBlock)) != PIPE_RWSTREAM_NoError)
+ {
+ Pipe_Freeze();
+ return ErrorCode;
+ }
+
+ if ((ErrorCode = MS_Host_WaitForDataReceived(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError)
+ {
+ Pipe_Freeze();
+ return ErrorCode;
+ }
+
+ if ((ErrorCode = MS_Host_SendReceiveData(MSInterfaceInfo, &SCSICommandBlock, DeviceCapacity)) != PIPE_RWSTREAM_NoError)
+ {
+ Pipe_Freeze();
+ return ErrorCode;
+ }
+
+ DeviceCapacity->Blocks = SwapEndian_32(DeviceCapacity->Blocks);
+ DeviceCapacity->BlockSize = SwapEndian_32(DeviceCapacity->BlockSize);
+
+ MS_CommandStatusWrapper_t SCSICommandStatus;
+ if ((ErrorCode = MS_Host_GetReturnedStatus(MSInterfaceInfo, &SCSICommandStatus)) != PIPE_RWSTREAM_NoError)
+ {
+ Pipe_Freeze();
+ return ErrorCode;
+ }
+
+ if (SCSICommandStatus.Status != SCSI_Command_Pass)
+ ErrorCode = MS_ERROR_LOGICAL_CMD_FAILED;
+
+ return ErrorCode;
+}
uint8_t MS_Host_RequestSense(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,
SCSI_Request_Sense_Response_t* SenseData);
diff --git a/LUFA/Drivers/USB/Class/Host/MassStorage.h b/LUFA/Drivers/USB/Class/Host/MassStorage.h
index 5999fcf6d..1678aefee 100644
--- a/LUFA/Drivers/USB/Class/Host/MassStorage.h
+++ b/LUFA/Drivers/USB/Class/Host/MassStorage.h
@@ -55,6 +55,9 @@
#endif
/* Public Interface - May be used in end-application: */
+ /* Macros: */
+ #define MS_ERROR_LOGICAL_CMD_FAILED 0xC0
+
/* Type Defines: */
/** Class state structure. An instance of this structure should be made within the user application,
* and passed to each of the HID class driver functions as the HIDInterfaceInfo parameter. This
@@ -211,11 +214,19 @@
*/
uint8_t MS_Host_GetMaxLUN(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t* MaxLUNIndex) ATTR_NON_NULL_PTR_ARG(1, 2);
+ /** Retrieves the Mass Storage device's inquiry data for the specified LUN, indicating the device characteristics and
+ * properties.
+ *
+ * \param[in,out] MSInterfaceInfo Pointer to a structure containing a MS Class host configuration and state
+ * \param[in] LUNIndex LUN index within the device the command is being issued to
+ * \param[out] InquiryData Location where the read inquiry data should be stored
+ *
+ * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum or MS_ERROR_LOGICAL_CMD_FAILED
+ */
uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,
SCSI_Inquiry_Response_t* InquiryData) ATTR_NON_NULL_PTR_ARG(1, 3);
- uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,
- bool* DeviceReady) ATTR_NON_NULL_PTR_ARG(1, 3);
+ uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex) ATTR_NON_NULL_PTR_ARG(1);
uint8_t MS_Host_ReadDeviceCapacity(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex,
SCSI_Capacity_t* DeviceCapacity) ATTR_NON_NULL_PTR_ARG(1, 3);