|
1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 // |
|
16 |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 |
|
22 SCSI Protocol layer for USB Mass Storage |
|
23 */ |
|
24 |
|
25 #ifndef SCSIPROT_H |
|
26 #define SCSIPROT_H |
|
27 |
|
28 |
|
29 // Header files |
|
30 #include "filesystemimage.h" |
|
31 #include "protocol.h" |
|
32 #include "mscfilecontroller.h" |
|
33 #include "usbmscfileshared.h" |
|
34 |
|
35 // Define MSDC_MULTITHREADED to use Mass Storage multi-threaded (Double-buffering) disk read/writes. |
|
36 // smassstorage_db.mmp defines this macro. |
|
37 |
|
38 |
|
39 // Display time taken to write data to disk |
|
40 //#define MEASURE_AND_DISPLAY_WRITE_TIME |
|
41 // Display time taken to read data from disk |
|
42 //#define MEASURE_AND_DISPLAY_READ_TIME |
|
43 |
|
44 |
|
45 // Maximum size for SCSI Read10 Write10 and Verify10 commands |
|
46 // Windows requests size of 64K whereas MAC requests size of 128K |
|
47 static const TUint32 KMaxBufSize = 128 * 1024; |
|
48 |
|
49 // Write to media when data is available |
|
50 static const TUint32 KDefaultMediaWriteSize = 4 * 1024; |
|
51 |
|
52 // Use in the HS case a write size of 64KB |
|
53 static const TUint32 KHsMediaWriteSize = 64 * 1024; |
|
54 |
|
55 |
|
56 /** |
|
57 Sense Info |
|
58 */ |
|
59 class TSenseInfo |
|
60 { |
|
61 public: |
|
62 // Spec: SCSI Primary Commands 3 (SPC-3) |
|
63 // Section 4.5.6 Sense key and sense code defintions |
|
64 // Table 27 - Sense key descriptions |
|
65 enum TSenseCode |
|
66 { |
|
67 ENoSense = 0, |
|
68 ERecoveredError = 1, |
|
69 ENotReady = 2, |
|
70 EMediumError = 3, |
|
71 EHardwareError = 4, |
|
72 EIllegalRequest = 5, |
|
73 EUnitAttention = 6, |
|
74 EDataProtection = 7, |
|
75 EBlankCheck = 8, |
|
76 EVendorSpecific = 9, |
|
77 ECopyAborted = 10, |
|
78 EAbortedCommand = 11, |
|
79 EDataOverflow = 13, |
|
80 EMisCompare = 14 |
|
81 }; |
|
82 |
|
83 // Table 28 - ASC and ASQ assignments |
|
84 enum TAdditionalCode |
|
85 { |
|
86 EAscNull = 0x00, |
|
87 EAscLogicalUnitNotReady = 0x04, |
|
88 EAscLogicalUnitDoesNotRespondToSelection = 0x05, |
|
89 EInvalidCmdCode = 0x20, |
|
90 ELbaOutOfRange = 0x21, |
|
91 EInvalidFieldInCdb = 0x24, |
|
92 ELuNotSupported = 0x25, |
|
93 EWriteProtected = 0x27, |
|
94 ENotReadyToReadyChange = 0x28, |
|
95 EMediaNotPresent = 0x3A, |
|
96 EInsufficientRes = 0x55 |
|
97 }; |
|
98 |
|
99 enum TAdditionalSenseCodeQualifier |
|
100 { |
|
101 EAscqNull = 0x00, |
|
102 EAscqLogicalUnitIsInProcessOfBecomingReady = 0x01 |
|
103 }; |
|
104 |
|
105 public: |
|
106 TSenseInfo(); |
|
107 |
|
108 void SetSense(TSenseCode aSenseCode); |
|
109 |
|
110 void SetSense(TSenseCode aSenseCode, |
|
111 TAdditionalCode aAdditional); |
|
112 |
|
113 void SetSense(TSenseCode aSenseCode, |
|
114 TAdditionalCode aAdditional, |
|
115 TAdditionalSenseCodeQualifier aQualifier); |
|
116 |
|
117 TBool SenseOk(); |
|
118 |
|
119 public: |
|
120 TUint8 iSenseCode; |
|
121 TUint8 iAdditional; |
|
122 TUint8 iQualifier; |
|
123 }; |
|
124 |
|
125 |
|
126 /** |
|
127 Returns EFalse if a sense code has been set. |
|
128 Note that ENoSense indicates that there is no specific sense key infotmation |
|
129 to be reported and the command was successful. |
|
130 */ |
|
131 inline TBool TSenseInfo::SenseOk() |
|
132 { |
|
133 return (iSenseCode == ENoSense); |
|
134 } |
|
135 |
|
136 |
|
137 const TUint KModeSenseCommandLength = 4; |
|
138 const TUint KReadCapacityCommandLength = 8; |
|
139 const TUint KReadFormatCapacitiesCommandLength = 12; |
|
140 const TUint KRequestSenseCommandLength = 18; |
|
141 const TUint KInquiryCommandLength = 36; |
|
142 |
|
143 const TUint KCommandBufferLength = KInquiryCommandLength; |
|
144 |
|
145 |
|
146 /** |
|
147 The CScsiProtocol is responsible for interpreting the data received from the Transpor layer |
|
148 and where appropriate routing specific requests through to the appropriate drive unit. |
|
149 |
|
150 @internalTechnology |
|
151 */ |
|
152 class CScsiProtocol : public CBase, public MProtocolBase |
|
153 { |
|
154 public: |
|
155 enum TCommand |
|
156 { |
|
157 ETestUnitReady = 0x00, |
|
158 ERequestSense = 0x03, |
|
159 EInquiry = 0x12, |
|
160 EModeSense = 0x1A, |
|
161 EStartStopUnit = 0x1B, |
|
162 EPreventMediaRemoval = 0x1E, |
|
163 EReadFormatCapacities = 0x23, // not supported for CD-ROM |
|
164 EReadCapacity = 0x25, |
|
165 ERead10 = 0x28, |
|
166 EWrite10 = 0x2A, // not supported for CD-ROM |
|
167 EVerify10 = 0x2f, // not supported for CD-ROM |
|
168 EReadTOC = 0x43, |
|
169 EGetConfiguration = 0x46, |
|
170 EModeSense10 = 0x5A, |
|
171 ERead12 = 0xA8, |
|
172 EUndefinedCommand = 0xFF |
|
173 }; |
|
174 |
|
175 |
|
176 public: |
|
177 |
|
178 static CScsiProtocol* NewL(CMscFileController& aController); |
|
179 void RegisterTransport(MTransportBase* aTransport); |
|
180 void ReportHighSpeedDevice(); |
|
181 TBool DecodePacket(TPtrC8& aData, TUint aLun); |
|
182 TInt ReadComplete(TInt aError); |
|
183 TInt SetScsiParameters(TMassStorageConfig aConfig); |
|
184 TInt Cancel(); |
|
185 ~CScsiProtocol(); |
|
186 |
|
187 private: |
|
188 CScsiProtocol(CMscFileController& aController); |
|
189 void ConstructL(); |
|
190 CFileSystemImage* GetCheckFs(TUint aLun); |
|
191 TBool HandleUnitReady(TUint aLun); |
|
192 TBool HandleRequestSense(TPtrC8& aData); |
|
193 TBool HandleInquiry(TPtrC8& aData, TUint aLun); |
|
194 TBool HandleStartStopUnit(TPtrC8& aData, TUint aLun); |
|
195 TBool HandlePreventMediaRemoval(TPtrC8& aData, TUint aLun); |
|
196 TBool HandleReadCapacity(TPtrC8& aData, TUint aLun); |
|
197 TBool HandleRead10(TPtrC8& aData, TUint aLun); |
|
198 TBool HandleRead12(TPtrC8& aData, TUint aLun); |
|
199 TBool HandleModeSense(TPtrC8& aData, TUint aLun); |
|
200 TBool HandleModeSense10(TPtrC8& aData, TUint aLun); |
|
201 TBool HandleReadTOC(TPtrC8& aData, TUint aLun); |
|
202 TBool HandleGetConfiguration(TPtrC8& aData, TUint aLun); |
|
203 |
|
204 private: |
|
205 /** Configuration data for INQUIRY command*/ |
|
206 TMassStorageConfig iConfig; |
|
207 |
|
208 /** reference to the Drive Manager */ |
|
209 CMscFileController& iController; |
|
210 |
|
211 /** pointer to the transport level */ |
|
212 MTransportBase* iTransport; |
|
213 |
|
214 /** Sense Info */ |
|
215 TSenseInfo iSenseInfo; |
|
216 |
|
217 /** General buffer for read/write operations */ |
|
218 TBuf8<KMaxBufSize> iCommandBuf; |
|
219 |
|
220 /** StartL offset (in bytes) for Write/Verify */ |
|
221 TInt64 iOffset; |
|
222 |
|
223 /** Last command for SetupRead (Write or Verify) */ |
|
224 TUint8 iLastCommand; |
|
225 |
|
226 /** LUN for SetupRead */ |
|
227 TUint iLastLun; |
|
228 |
|
229 #ifdef SIMDISK |
|
230 CArrayFixFlat<TUint8>* iSimDisk; |
|
231 #endif |
|
232 |
|
233 /** The number of bytes remaining to be read from the host for write operations */ |
|
234 TUint32 iBytesRemain; |
|
235 |
|
236 /** Write to the media when this amount of data is available */ |
|
237 TUint32 iMediaWriteSize; |
|
238 |
|
239 }; |
|
240 |
|
241 #endif // SCSIPROT_H |