3      Copyright (C) Dean Camera, 2009. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, and distribute this software 
  13   and its documentation for any purpose and without fee is hereby 
  14   granted, provided that the above copyright notice appear in all 
  15   copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting 
  17   documentation, and that the name of the author not be used in 
  18   advertising or publicity pertaining to distribution of the 
  19   software without specific, written prior permission. 
  21   The author disclaim all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  31 /** \ingroup Group_USBClassMS 
  32  *  @defgroup Group_USBClassMSCommon  Common Class Definitions 
  34  *  \section Module Description 
  35  *  Constants, Types and Enum definitions that are common to both Device and Host modes for the USB 
  41 #ifndef _MS_CLASS_COMMON_H_ 
  42 #define _MS_CLASS_COMMON_H_ 
  45                 #include "../../USB.h" 
  49         /* Enable C linkage for C++ Compilers: */ 
  50                 #if defined(__cplusplus) 
  55                 /** Mass Storage Class specific request to reset the Mass Storage interface, ready for the next command. */ 
  56                 #define REQ_MassStorageReset       0xFF 
  58                 /** Mass Storage Class specific request to retrieve the total number of Logical Units (drives) in the SCSI device. */ 
  59                 #define REQ_GetMaxLUN              0xFE 
  61                 /** Magic signature for a Command Block Wrapper used in the Mass Storage Bulk-Only transport protocol. */ 
  62                 #define MS_CBW_SIGNATURE           0x43425355UL 
  64                 /** Magic signature for a Command Status Wrapper used in the Mass Storage Bulk-Only transport protocol. */ 
  65                 #define MS_CSW_SIGNATURE           0x53425355UL 
  67                 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from host-to-device. */ 
  68                 #define MS_COMMAND_DIR_DATA_OUT    (0 << 7) 
  70                 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from device-to-host. */ 
  71                 #define MS_COMMAND_DIR_DATA_IN     (1 << 7) 
  73                 /** SCSI Command Code for an INQUIRY command. */ 
  74                 #define SCSI_CMD_INQUIRY                               0x12 
  76                 /** SCSI Command Code for a REQUEST SENSE command. */ 
  77                 #define SCSI_CMD_REQUEST_SENSE                         0x03 
  79                 /** SCSI Command Code for a TEST UNIT READY command. */ 
  80                 #define SCSI_CMD_TEST_UNIT_READY                       0x00 
  82                 /** SCSI Command Code for a READ CAPACITY (10) command. */ 
  83                 #define SCSI_CMD_READ_CAPACITY_10                      0x25 
  85                 /** SCSI Command Code for a SEND DIAGNOSTIC command. */ 
  86                 #define SCSI_CMD_SEND_DIAGNOSTIC                       0x1D 
  88                 /** SCSI Command Code for a PREVENT ALLOW MEDIUM REMOVAL command. */ 
  89                 #define SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL          0x1E 
  91                 /** SCSI Command Code for a WRITE (10) command. */ 
  92                 #define SCSI_CMD_WRITE_10                              0x2A 
  94                 /** SCSI Command Code for a READ (10) command. */ 
  95                 #define SCSI_CMD_READ_10                               0x28 
  97                 /** SCSI Command Code for a WRITE (6) command. */ 
  98                 #define SCSI_CMD_WRITE_6                               0x0A 
 100                 /** SCSI Command Code for a READ (6) command. */ 
 101                 #define SCSI_CMD_READ_6                                0x08 
 103                 /** SCSI Command Code for a VERIFY (10) command. */ 
 104                 #define SCSI_CMD_VERIFY_10                             0x2F 
 106                 /** SCSI Command Code for a MODE SENSE (6) command. */ 
 107                 #define SCSI_CMD_MODE_SENSE_6                          0x1A 
 109                 /** SCSI Command Code for a MODE SENSE (10) command. */ 
 110                 #define SCSI_CMD_MODE_SENSE_10                         0x5A 
 112                 /** SCSI Sense Code to indicate no error has ocurred. */ 
 113                 #define SCSI_SENSE_KEY_GOOD                            0x00 
 115                 /** SCSI Sense Code to indicate that the device has recovered from an error. */ 
 116                 #define SCSI_SENSE_KEY_RECOVERED_ERROR                 0x01 
 118                 /** SCSI Sense Code to indicate that the device is not ready for a new command. */ 
 119                 #define SCSI_SENSE_KEY_NOT_READY                       0x02 
 121                 /** SCSI Sense Code to indicate an error whilst accessing the medium. */ 
 122                 #define SCSI_SENSE_KEY_MEDIUM_ERROR                    0x03 
 124                 /** SCSI Sense Code to indicate a hardware has ocurred. */ 
 125                 #define SCSI_SENSE_KEY_HARDWARE_ERROR                  0x04 
 127                 /** SCSI Sense Code to indicate that an illegal request has been issued. */ 
 128                 #define SCSI_SENSE_KEY_ILLEGAL_REQUEST                 0x05 
 130                 /** SCSI Sense Code to indicate that the unit requires attention from the host to indicate 
 131                  *  a reset event, medium removal or other condition. 
 133                 #define SCSI_SENSE_KEY_UNIT_ATTENTION                  0x06 
 135                 /** SCSI Sense Code to indicate that a write attempt on a protected block has been made. */ 
 136                 #define SCSI_SENSE_KEY_DATA_PROTECT                    0x07 
 138                 /** SCSI Sense Code to indicate an error while trying to write to a write-once medium. */ 
 139                 #define SCSI_SENSE_KEY_BLANK_CHECK                     0x08 
 141                 /** SCSI Sense Code to indicate a vendor specific error has ocurred. */ 
 142                 #define SCSI_SENSE_KEY_VENDOR_SPECIFIC                 0x09 
 144                 /** SCSI Sense Code to indicate that an EXTENDED COPY command has aborted due to an error. */ 
 145                 #define SCSI_SENSE_KEY_COPY_ABORTED                    0x0A 
 147                 /** SCSI Sense Code to indicate that the device has aborted the issued command. */ 
 148                 #define SCSI_SENSE_KEY_ABORTED_COMMAND                 0x0B 
 150                 /** SCSI Sense Code to indicate an attempt to write past the end of a partition has been made. */ 
 151                 #define SCSI_SENSE_KEY_VOLUME_OVERFLOW                 0x0D 
 153                 /** SCSI Sense Code to indicate that the source data did not match the data read from the medium. */ 
 154                 #define SCSI_SENSE_KEY_MISCOMPARE                      0x0E 
 156                 /** SCSI Additional Sense Code to indicate no additional sense information is available. */ 
 157                 #define SCSI_ASENSE_NO_ADDITIONAL_INFORMATION          0x00 
 159                 /** SCSI Additional Sense Code to indicate that the logical unit (LUN) addressed is not ready. */ 
 160                 #define SCSI_ASENSE_LOGICAL_UNIT_NOT_READY             0x04 
 162                 /** SCSI Additional Sense Code to indicate an invalid field was encountered while processing the issued command. */ 
 163                 #define SCSI_ASENSE_INVALID_FIELD_IN_CDB               0x24 
 165                 /** SCSI Additional Sense Code to indicate that an attemp to write to a protected area was made. */ 
 166                 #define SCSI_ASENSE_WRITE_PROTECTED                    0x27 
 168                 /** SCSI Additional Sense Code to indicate an error whilst formatting the device medium. */ 
 169                 #define SCSI_ASENSE_FORMAT_ERROR                       0x31 
 171                 /** SCSI Additional Sense Code to indicate an invalid command was issued. */ 
 172                 #define SCSI_ASENSE_INVALID_COMMAND                    0x20 
 174                 /** SCSI Additional Sense Code to indicate a write to a block out outside of the medium's range was issued. */ 
 175                 #define SCSI_ASENSE_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE 0x21 
 177                 /** SCSI Additional Sense Code to indicate that no removable medium is inserted into the device. */ 
 178                 #define SCSI_ASENSE_MEDIUM_NOT_PRESENT                 0x3A 
 180                 /** SCSI Additional Sense Qualifier Code to indicate no additional sense qualifier information is available. */ 
 181                 #define SCSI_ASENSEQ_NO_QUALIFIER                      0x00 
 183                 /** SCSI Additional Sense Qualifier Code to indicate that a medium format command failed to complete. */ 
 184                 #define SCSI_ASENSEQ_FORMAT_COMMAND_FAILED             0x01 
 186                 /** SCSI Additional Sense Qualifier Code to indicate that an initializing command must be issued before the issued 
 187                  *  command can be executed. 
 189                 #define SCSI_ASENSEQ_INITIALIZING_COMMAND_REQUIRED     0x02 
 191                 /** SCSI Additional Sense Qualifier Code to indicate that an operation is currently in progress. */ 
 192                 #define SCSI_ASENSEQ_OPERATION_IN_PROGRESS             0x07 
 195                 /** Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */ 
 198                         uint32_t Signature
; /**< Command block signature, must be CBW_SIGNATURE to indicate a valid Command Block */ 
 199                         uint32_t Tag
; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */ 
 200                         uint32_t DataTransferLength
; /** Length of the optional data portion of the issued command, in bytes */ 
 201                         uint8_t  Flags
; /**< Command block flags, indicating command data direction */ 
 202                         uint8_t  LUN
; /**< Logical Unit number this command is issued to */ 
 203                         uint8_t  SCSICommandLength
; /**< Length of the issued SCSI command within the SCSI command data array */ 
 204                         uint8_t  SCSICommandData
[16]; /**< Issued SCSI command in the Command Block */ 
 205                 } MS_CommandBlockWrapper_t
; 
 207                 /** Type define for a Command Status Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */ 
 210                         uint32_t Signature
; /**< Status block signature, must be CSW_SIGNATURE to indicate a valid Command Status */ 
 211                         uint32_t Tag
; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */ 
 212                         uint32_t DataTransferResidue
; /**< Number of bytes of data not processed in the SCSI command */ 
 213                         uint8_t  Status
; /**< Status code of the issued command - a value from the MassStorage_CommandStatusCodes_t enum */ 
 214                 } MS_CommandStatusWrapper_t
; 
 217                 /** Enum for the possible command status wrapper return status codes. */ 
 218                 enum MassStorage_CommandStatusCodes_t
 
 220                         SCSI_Command_Pass 
= 0, /**< Command completed with no error */ 
 221                         SCSI_Command_Fail 
= 1, /**< Command failed to complete - host may check the exact error via a SCSI REQUEST SENSE command */ 
 222                         SCSI_Phase_Error  
= 2  /**< Command failed due to being invalid in the current phase */ 
 225         /* Disable C linkage for C++ Compilers: */ 
 226                 #if defined(__cplusplus)