From a765f717273728139966f97c634ccffe52d218df Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Wed, 26 Aug 2009 07:51:40 +0000 Subject: [PATCH] Add SCSICodes.h to the Class Driver Common folder, and automatically include it in both the Host and Device Mass Storage Class drivers. Delete existing version from the ClassDriver MassStorage device demo's /Lib/ folder. --- .../Device/ClassDriver/MassStorage/Lib/SCSI.h | 1 - .../MassStorageHost/MassStorageHost.c | 2 +- LUFA.pnproj | 2 +- .../Drivers/USB/Class/Common/SCSICodes.h | 0 LUFA/Drivers/USB/Class/Device/MassStorage.h | 3 +- LUFA/Drivers/USB/Class/Host/MassStorage.c | 44 ++++++++++++++++++- LUFA/Drivers/USB/Class/Host/MassStorage.h | 5 ++- 7 files changed, 50 insertions(+), 7 deletions(-) rename Demos/Device/ClassDriver/MassStorage/Lib/SCSI_Codes.h => LUFA/Drivers/USB/Class/Common/SCSICodes.h (100%) diff --git a/Demos/Device/ClassDriver/MassStorage/Lib/SCSI.h b/Demos/Device/ClassDriver/MassStorage/Lib/SCSI.h index 052f908cdd..7779cd3d7f 100644 --- a/Demos/Device/ClassDriver/MassStorage/Lib/SCSI.h +++ b/Demos/Device/ClassDriver/MassStorage/Lib/SCSI.h @@ -46,7 +46,6 @@ #include "MassStorage.h" #include "Descriptors.h" #include "DataflashManager.h" - #include "SCSI_Codes.h" /* Macros: */ /** Macro to set the current SCSI sense data to the given key, additional sense code and additional sense qualifier. This diff --git a/Demos/Host/ClassDriver/MassStorageHost/MassStorageHost.c b/Demos/Host/ClassDriver/MassStorageHost/MassStorageHost.c index 27662db753..d9fe47d3b6 100644 --- a/Demos/Host/ClassDriver/MassStorageHost/MassStorageHost.c +++ b/Demos/Host/ClassDriver/MassStorageHost/MassStorageHost.c @@ -139,7 +139,7 @@ int main(void) } SCSI_Inquiry_Response_t InquiryData; - if (MS_Host_GetInquiryData(&FlashDisk_MS_Interface, &InquiryData)) + if (MS_Host_GetInquiryData(&FlashDisk_MS_Interface, 0, &InquiryData)) { printf("Error retreiving device Inquiry data.\r\n"); LEDs_SetAllLEDs(LEDMASK_USB_ERROR); diff --git a/LUFA.pnproj b/LUFA.pnproj index 14cb60fde0..41ae591efe 100644 --- a/LUFA.pnproj +++ b/LUFA.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/Demos/Device/ClassDriver/MassStorage/Lib/SCSI_Codes.h b/LUFA/Drivers/USB/Class/Common/SCSICodes.h similarity index 100% rename from Demos/Device/ClassDriver/MassStorage/Lib/SCSI_Codes.h rename to LUFA/Drivers/USB/Class/Common/SCSICodes.h diff --git a/LUFA/Drivers/USB/Class/Device/MassStorage.h b/LUFA/Drivers/USB/Class/Device/MassStorage.h index 4ab43987da..1c232b8299 100644 --- a/LUFA/Drivers/USB/Class/Device/MassStorage.h +++ b/LUFA/Drivers/USB/Class/Device/MassStorage.h @@ -47,7 +47,8 @@ /* Includes: */ #include "../../USB.h" #include "../Common/MassStorage.h" - + #include "../Common/SCSICodes.h" + #include /* Enable C linkage for C++ Compilers: */ diff --git a/LUFA/Drivers/USB/Class/Host/MassStorage.c b/LUFA/Drivers/USB/Class/Host/MassStorage.c index a0b34610cd..1610e422aa 100644 --- a/LUFA/Drivers/USB/Class/Host/MassStorage.c +++ b/LUFA/Drivers/USB/Class/Host/MassStorage.c @@ -310,11 +310,53 @@ uint8_t MS_Host_GetMaxLUN(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t* Max return ErrorCode; } -uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, SCSI_Inquiry_Response_t* InquiryData) +uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, SCSI_Inquiry_Response_t* InquiryData) { 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_Inquiry_Response_t), + .Flags = COMMAND_DIRECTION_DATA_IN, + .LUN = LUNIndex, + .SCSICommandLength = 6, + .SCSICommandData = + { + SCSI_CMD_INQUIRY, + 0x00, // Reserved + 0x00, // Reserved + 0x00, // Reserved + sizeof(SCSI_Inquiry_Response_t), // Allocation Length + 0x00 // Unused (control) + } + }; + + MassStore_SendCommand(MSInterfaceInfo, &SCSICommandBlock); + + if ((ErrorCode = MassStore_WaitForDataReceived()) != PIPE_RWSTREAM_NoError) + { + Pipe_Freeze(); + return ErrorCode; + } + if ((ErrorCode = MassStore_SendReceiveData(MSInterfaceInfo, (uint8_t*)InquiryPtr)) != PIPE_RWSTREAM_NoError) + { + Pipe_Freeze(); + return ErrorCode; + } + + if ((ErrorCode = MassStore_GetReturnedStatus(MSInterfaceInfo)) != PIPE_RWSTREAM_NoError) + { + Pipe_Freeze(); + return ErrorCode; + } + + return ErrorCode; } uint8_t MS_Host_TestUnitReady(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t LUNIndex, bool* DeviceReady); diff --git a/LUFA/Drivers/USB/Class/Host/MassStorage.h b/LUFA/Drivers/USB/Class/Host/MassStorage.h index 7ee3b88046..5999fcf6d6 100644 --- a/LUFA/Drivers/USB/Class/Host/MassStorage.h +++ b/LUFA/Drivers/USB/Class/Host/MassStorage.h @@ -47,6 +47,7 @@ /* Includes: */ #include "../../USB.h" #include "../Common/MassStorage.h" + #include "../Common/SCSICodes.h" /* Enable C linkage for C++ Compilers: */ #if defined(__cplusplus) @@ -210,8 +211,8 @@ */ uint8_t MS_Host_GetMaxLUN(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, uint8_t* MaxLUNIndex) ATTR_NON_NULL_PTR_ARG(1, 2); - uint8_t MS_Host_GetInquiryData(USB_ClassInfo_MS_Host_t* MSInterfaceInfo, - SCSI_Inquiry_Response_t* InquiryData) ATTR_NON_NULL_PTR_ARG(1, 2); + 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);