State information for class drivers is now zeroed out during enumeration (both in...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Common / MassStorage.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /** \ingroup Group_USBClassMS
32 * @{
33 */
34
35 #ifndef _MS_CLASS_COMMON_H_
36 #define _MS_CLASS_COMMON_H_
37
38 /* Includes: */
39 #include "../../USB.h"
40
41 #include <string.h>
42
43 /* Enable C linkage for C++ Compilers: */
44 #if defined(__cplusplus)
45 extern "C" {
46 #endif
47
48 /* Macros: */
49 /** Mass Storage Class specific request to reset the Mass Storage interface, ready for the next command. */
50 #define REQ_MassStorageReset 0xFF
51
52 /** Mass Storage Class specific request to retrieve the total number of Logical Units (drives) in the SCSI device. */
53 #define REQ_GetMaxLUN 0xFE
54
55 /** Magic signature for a Command Block Wrapper used in the Mass Storage Bulk-Only transport protocol. */
56 #define MS_CBW_SIGNATURE 0x43425355UL
57
58 /** Magic signature for a Command Status Wrapper used in the Mass Storage Bulk-Only transport protocol. */
59 #define MS_CSW_SIGNATURE 0x53425355UL
60
61 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from host-to-device. */
62 #define MS_COMMAND_DIR_DATA_OUT (0 << 7)
63
64 /** Mask for a Command Block Wrapper's flags attribute to specify a command with data sent from device-to-host. */
65 #define MS_COMMAND_DIR_DATA_IN (1 << 7)
66
67 /* Type defines: */
68 /** Type define for a Command Block Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
69 typedef struct
70 {
71 uint32_t Signature; /**< Command block signature, must be CBW_SIGNATURE to indicate a valid Command Block */
72 uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */
73 uint32_t DataTransferLength; /** Length of the optional data portion of the issued command, in bytes */
74 uint8_t Flags; /**< Command block flags, indicating command data direction */
75 uint8_t LUN; /**< Logical Unit number this command is issued to */
76 uint8_t SCSICommandLength; /**< Length of the issued SCSI command within the SCSI command data array */
77 uint8_t SCSICommandData[16]; /**< Issued SCSI command in the Command Block */
78 } MS_CommandBlockWrapper_t;
79
80 /** Type define for a Command Status Wrapper, used in the Mass Storage Bulk-Only Transport protocol. */
81 typedef struct
82 {
83 uint32_t Signature; /**< Status block signature, must be CSW_SIGNATURE to indicate a valid Command Status */
84 uint32_t Tag; /**< Unique command ID value, to associate a command block wrapper with its command status wrapper */
85 uint32_t DataTransferResidue; /**< Number of bytes of data not processed in the SCSI command */
86 uint8_t Status; /**< Status code of the issued command - a value from the MassStorage_CommandStatusCodes_t enum */
87 } MS_CommandStatusWrapper_t;
88
89 /* Enums: */
90 /** Enum for the possible command status wrapper return status codes. */
91 enum MassStorage_CommandStatusCodes_t
92 {
93 SCSI_Command_Pass = 0, /**< Command completed with no error */
94 SCSI_Command_Fail = 1, /**< Command failed to complete - host may check the exact error via a SCSI REQUEST SENSE command */
95 SCSI_Phase_Error = 2 /**< Command failed due to being invalid in the current phase */
96 };
97
98 /* Disable C linkage for C++ Compilers: */
99 #if defined(__cplusplus)
100 }
101 #endif
102
103 #endif
104
105 /** @} */