Update copyrights for 2021.
[pub/lufa.git] / Demos / Device / ClassDriver / MassStorageKeyboard / Lib / SCSI.c
index 83719bf..7bf74a0 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2011.
+     Copyright (C) Dean Camera, 2021.
 
   dean [at] fourwalledcubicle [dot] com
            www.lufa-lib.org
 */
 
 /*
-  Copyright 2011  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2021  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
@@ -18,7 +18,7 @@
   advertising or publicity pertaining to distribution of the
   software without specific, written prior permission.
 
-  The author disclaim all warranties with regard to this
+  The author disclaims all warranties with regard to this
   software, including all implied warranties of merchantability
   and fitness.  In no event shall the author be liable for any
   special, indirect or consequential damages or any damages
@@ -41,7 +41,7 @@
 /** Structure to hold the SCSI response data to a SCSI INQUIRY command. This gives information about the device's
  *  features and capabilities.
  */
-SCSI_Inquiry_Response_t InquiryData =
+static const SCSI_Inquiry_Response_t InquiryData =
        {
                .DeviceType          = DEVICE_TYPE_BLOCK,
                .PeripheralQualifier = 0,
@@ -73,7 +73,7 @@ SCSI_Inquiry_Response_t InquiryData =
 /** Structure to hold the sense data for the last issued SCSI command, which is returned to the host after a SCSI REQUEST SENSE
  *  command is issued. This gives information on exactly why the last command failed to complete.
  */
-SCSI_Request_Sense_Response_t SenseData =
+static SCSI_Request_Sense_Response_t SenseData =
        {
                .ResponseCode        = 0x70,
                .AdditionalLength    = 0x0A,
@@ -86,7 +86,7 @@ SCSI_Request_Sense_Response_t SenseData =
  *
  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with
  *
- *  \return Boolean true if the command completed successfully, false otherwise
+ *  \return Boolean \c true if the command completed successfully, \c false otherwise
  */
 bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
@@ -116,6 +116,7 @@ bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
                case SCSI_CMD_MODE_SENSE_6:
                        CommandSuccess = SCSI_Command_ModeSense_6(MSInterfaceInfo);
                        break;
+               case SCSI_CMD_START_STOP_UNIT:
                case SCSI_CMD_TEST_UNIT_READY:
                case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
                case SCSI_CMD_VERIFY_10:
@@ -149,13 +150,12 @@ bool SCSI_DecodeSCSICommand(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
  *
  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with
  *
- *  \return Boolean true if the command completed successfully, false otherwise.
+ *  \return Boolean \c true if the command completed successfully, \c false otherwise.
  */
 static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
        uint16_t AllocationLength  = SwapEndian_16(*(uint16_t*)&MSInterfaceInfo->State.CommandBlock.SCSICommandData[3]);
-       uint16_t BytesTransferred  = (AllocationLength < sizeof(InquiryData))? AllocationLength :
-                                                                              sizeof(InquiryData);
+       uint16_t BytesTransferred  = MIN(AllocationLength, sizeof(InquiryData));
 
        /* Only the standard INQUIRY data is supported, check if any optional INQUIRY bits set */
        if ((MSInterfaceInfo->State.CommandBlock.SCSICommandData[1] & ((1 << 0) | (1 << 1))) ||
@@ -188,12 +188,12 @@ static bool SCSI_Command_Inquiry(USB_ClassInfo_MS_Device_t* const MSInterfaceInf
  *
  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with
  *
- *  \return Boolean true if the command completed successfully, false otherwise.
+ *  \return Boolean \c true if the command completed successfully, \c false otherwise.
  */
 static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
        uint8_t  AllocationLength = MSInterfaceInfo->State.CommandBlock.SCSICommandData[4];
-       uint8_t  BytesTransferred = (AllocationLength < sizeof(SenseData))? AllocationLength : sizeof(SenseData);
+       uint8_t  BytesTransferred = MIN(AllocationLength, sizeof(SenseData));
 
        Endpoint_Write_Stream_LE(&SenseData, BytesTransferred, NULL);
        Endpoint_Null_Stream((AllocationLength - BytesTransferred), NULL);
@@ -210,7 +210,7 @@ static bool SCSI_Command_Request_Sense(USB_ClassInfo_MS_Device_t* const MSInterf
  *
  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with
  *
- *  \return Boolean true if the command completed successfully, false otherwise.
+ *  \return Boolean \c true if the command completed successfully, \c false otherwise.
  */
 static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
@@ -233,7 +233,7 @@ static bool SCSI_Command_Read_Capacity_10(USB_ClassInfo_MS_Device_t* const MSInt
  *
  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with
  *
- *  \return Boolean true if the command completed successfully, false otherwise.
+ *  \return Boolean \c true if the command completed successfully, \c false otherwise.
  */
 static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
@@ -272,7 +272,7 @@ static bool SCSI_Command_Send_Diagnostic(USB_ClassInfo_MS_Device_t* const MSInte
  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with
  *  \param[in] IsDataRead  Indicates if the command is a READ (10) command or WRITE (10) command (DATA_READ or DATA_WRITE)
  *
- *  \return Boolean true if the command completed successfully, false otherwise.
+ *  \return Boolean \c true if the command completed successfully, \c false otherwise.
  */
 static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo,
                                       const bool IsDataRead)
@@ -288,7 +288,7 @@ static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfa
                               SCSI_ASENSE_WRITE_PROTECTED,
                               SCSI_ASENSEQ_NO_QUALIFIER);
 
-               return false;           
+               return false;
        }
 
        /* Load in the 32-bit block address (SCSI uses big-endian, so have to reverse the byte order) */
@@ -330,15 +330,15 @@ static bool SCSI_Command_ReadWrite_10(USB_ClassInfo_MS_Device_t* const MSInterfa
  *
  *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with
  *
- *  \return Boolean true if the command completed successfully, false otherwise.
+ *  \return Boolean \c true if the command completed successfully, \c false otherwise.
  */
 static bool SCSI_Command_ModeSense_6(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
 {
        /* Send an empty header response with the Write Protect flag status */
-       Endpoint_Write_Byte(0x00);
-       Endpoint_Write_Byte(0x00);
-       Endpoint_Write_Byte(DISK_READ_ONLY ? 0x80 : 0x00);
-       Endpoint_Write_Byte(0x00);
+       Endpoint_Write_8(0x00);
+       Endpoint_Write_8(0x00);
+       Endpoint_Write_8(DISK_READ_ONLY ? 0x80 : 0x00);
+       Endpoint_Write_8(0x00);
        Endpoint_ClearIN();
 
        /* Update the bytes transferred counter and succeed the command */
@@ -346,3 +346,4 @@ static bool SCSI_Command_ModeSense_6(USB_ClassInfo_MS_Device_t* const MSInterfac
 
        return true;
 }
+