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