author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:47:38 +0300 | |
changeset 102 | ef2a444a7410 |
parent 90 | 947f0dc9f7a8 |
child 97 | 41f0cfe18c80 |
permissions | -rw-r--r-- |
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
1 |
// Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 2 |
// All rights reserved. |
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "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 |
@file |
|
18 |
@internalTechnology |
|
19 |
*/ |
|
20 |
||
21 |
#include <e32base.h> |
|
22 |
||
23 |
#include "debug.h" |
|
24 |
#include "msdebug.h" |
|
25 |
#include "msctypes.h" |
|
26 |
#include "shared.h" |
|
27 |
#include "msgservice.h" |
|
28 |
||
29 |
#include "mtransport.h" |
|
30 |
#include "mprotocol.h" |
|
31 |
#include "tscsiclientreq.h" |
|
32 |
#include "tscsiprimarycmds.h" |
|
33 |
#include "tscsiblockcmds.h" |
|
34 |
||
35 |
#include "mblocktransferprotocol.h" |
|
36 |
#include "tblocktransfer.h" |
|
37 |
||
38 |
#include "tsbcclientinterface.h" |
|
39 |
#include "tspcclientinterface.h" |
|
40 |
#include "cmassstoragefsm.h" |
|
41 |
#include "cscsiprotocol.h" |
|
42 |
||
43 |
#include "usbmshostpanic.h" |
|
44 |
||
45 |
||
46 |
/** |
|
47 |
Create the CScsiProtocol object. |
|
48 |
||
49 |
@param aLun The LUN for the device represented by this object |
|
50 |
@param aTransport The transport interface |
|
51 |
@param aStatusPollingInterval The polling interval |
|
52 |
@return CScsiProtocol* A reference to the |
|
53 |
*/ |
|
54 |
CScsiProtocol* CScsiProtocol::NewL(TLun aLun, MTransport& aTransport) |
|
55 |
{ |
|
56 |
__MSFNSLOG |
|
57 |
CScsiProtocol* r = new (ELeave) CScsiProtocol(aTransport); |
|
58 |
||
59 |
CleanupStack::PushL(r); |
|
60 |
r->ConstructL(aLun); |
|
61 |
CleanupStack::Pop(); |
|
62 |
return r; |
|
63 |
} |
|
64 |
||
65 |
void CScsiProtocol::ConstructL(TLun aLun) |
|
66 |
{ |
|
67 |
__MSFNLOG |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
68 |
// iState = EEntry; |
0 | 69 |
iFsm = CMassStorageFsm::NewL(*this); |
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
const TInt blockLength = 0x200; |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
iHeadbuf.CreateL(blockLength); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
iTailbuf.CreateL(blockLength); |
0 | 75 |
} |
76 |
||
77 |
||
78 |
CScsiProtocol::CScsiProtocol(MTransport& aTransport) |
|
79 |
: iSpcInterface(aTransport), |
|
80 |
iSbcInterface(NULL) |
|
81 |
{ |
|
82 |
__MSFNLOG |
|
83 |
} |
|
84 |
||
85 |
||
86 |
CScsiProtocol::~CScsiProtocol() |
|
87 |
{ |
|
88 |
__MSFNLOG |
|
89 |
delete iFsm; |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
iHeadbuf.Close(); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
iTailbuf.Close(); |
0 | 92 |
delete iSbcInterface; |
93 |
} |
|
94 |
||
95 |
||
96 |
void CScsiProtocol::InitialiseUnitL() |
|
97 |
{ |
|
98 |
__MSFNLOG |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
99 |
iState = EDisconnected; |
0 | 100 |
|
101 |
// A device may take time to mount the media. If the device fails attempt to |
|
102 |
// retry the connection for a number of seconds |
|
103 |
TInt retryCounter = 20; |
|
104 |
do |
|
105 |
{ |
|
106 |
retryCounter--; |
|
107 |
iFsm->ConnectLogicalUnitL(); |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
108 |
if (iFsm->IsConnected()) |
0 | 109 |
{ |
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
110 |
iState = EConnected; |
0 | 111 |
break; |
112 |
} |
|
113 |
User::After(1000 * 200); // 200 mS |
|
114 |
} |
|
115 |
while (retryCounter); |
|
116 |
} |
|
117 |
||
118 |
||
119 |
void CScsiProtocol::UninitialiseUnitL() |
|
120 |
{ |
|
121 |
__MSFNLOG |
|
122 |
iFsm->DisconnectLogicalUnitL(); |
|
123 |
} |
|
124 |
||
125 |
TBool CScsiProtocol::IsConnected() |
|
126 |
{ |
|
127 |
__MSFNLOG |
|
128 |
return (iState == EConnected)? ETrue : EFalse; |
|
129 |
} |
|
130 |
||
131 |
void CScsiProtocol::ReadL(TPos aPos, |
|
132 |
TDes8& aBuf, |
|
133 |
TInt aLength) |
|
134 |
{ |
|
135 |
__MSFNLOG |
|
136 |
if(!IsConnected()) |
|
137 |
User::Leave(KErrNotReady); |
|
138 |
iSbcInterface->iBlockTransfer.ReadL(*this, aPos, aLength, aBuf); |
|
139 |
} |
|
140 |
||
141 |
||
142 |
void CScsiProtocol::BlockReadL(TPos aPos, TDes8& aCopybuf, TInt aLen) |
|
143 |
{ |
|
144 |
__MSFNLOG |
|
145 |
__ASSERT_DEBUG(aPos % iSbcInterface->iBlockTransfer.BlockLength() == 0, |
|
146 |
User::Panic(KUsbMsHostPanicCat, EBlockDevice)); |
|
147 |
||
148 |
const TInt blockLen = iSbcInterface->iBlockTransfer.BlockLength(); |
|
149 |
TInt len = aLen; |
|
150 |
||
151 |
TInt64 lba = aPos / static_cast<TInt64>(blockLen); |
|
152 |
||
153 |
if (I64HIGH(lba)) |
|
154 |
{ |
|
155 |
User::LeaveIfError(KErrOverflow); |
|
156 |
} |
|
157 |
||
158 |
TInt err = iSbcInterface->Read10L(I64LOW(lba), aCopybuf, len); |
|
159 |
if (err) |
|
160 |
{ |
|
161 |
__SCSIPRINT1(_L("READ(10) Err=%d"), err); |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
162 |
User::LeaveIfError(DoCheckConditionL()); |
0 | 163 |
} |
164 |
||
165 |
// handle residue |
|
166 |
while (len != aLen) |
|
167 |
{ |
|
168 |
__SCSIPRINT2(_L("SCSI Read Residue 0x%x bytes read (0x%x)"), len, aLen); |
|
169 |
__SCSIPRINT2(_L("Pos=0x%lx Len=0x%x"), aPos, aLen); |
|
170 |
||
171 |
// read next block |
|
172 |
||
173 |
// full blocks read in bytes |
|
174 |
TInt bytesRead = len/blockLen * blockLen; |
|
175 |
aPos += bytesRead; |
|
176 |
aLen -= bytesRead; |
|
177 |
len = aLen; |
|
178 |
||
179 |
__SCSIPRINT3(_L("New Pos=0x%lx Len=0x%x (bytes read = %x)"), |
|
180 |
aPos, aLen, bytesRead); |
|
181 |
||
182 |
aCopybuf.SetLength(bytesRead); |
|
183 |
||
184 |
// read rest of the block |
|
185 |
TInt err = iSbcInterface->Read10L(aPos/blockLen, aCopybuf, len); |
|
186 |
if (err) |
|
187 |
{ |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
188 |
User::LeaveIfError(DoCheckConditionL()); |
0 | 189 |
} |
190 |
} |
|
191 |
} |
|
192 |
||
193 |
||
194 |
void CScsiProtocol::WriteL(TPos aPosition, |
|
195 |
TDesC8& aBuf, |
|
196 |
TInt aLength) |
|
197 |
{ |
|
198 |
__MSFNLOG |
|
199 |
if(!IsConnected()) |
|
200 |
User::Leave(KErrNotReady); |
|
201 |
iSbcInterface->iBlockTransfer.WriteL(*this, aPosition, aLength, aBuf); |
|
202 |
} |
|
203 |
||
204 |
||
205 |
void CScsiProtocol::BlockWriteL(TPos aPos, TDesC8& aCopybuf, TUint aOffset, TInt aLen) |
|
206 |
{ |
|
207 |
__MSFNLOG |
|
208 |
__ASSERT_DEBUG(aPos % iSbcInterface->iBlockTransfer.BlockLength() == 0, |
|
209 |
User::Panic(KUsbMsHostPanicCat, EBlockDevice)); |
|
210 |
const TInt blockLen = iSbcInterface->iBlockTransfer.BlockLength(); |
|
211 |
TInt len = aLen; |
|
212 |
TInt err = iSbcInterface->Write10L(aPos/blockLen, aCopybuf, aOffset, len); |
|
213 |
if (err) |
|
214 |
{ |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
215 |
User::LeaveIfError(DoCheckConditionL()); |
0 | 216 |
} |
217 |
||
218 |
while (len != aLen) |
|
219 |
{ |
|
220 |
// handle residue |
|
221 |
__SCSIPRINT2(_L("SCSI Write Residue 0x%x bytes read (0x%x)"), len, aLen); |
|
222 |
__SCSIPRINT2(_L("Pos=0x%lx Len=0x%x"), aPos, aLen); |
|
223 |
||
224 |
// write next block |
|
225 |
||
226 |
// full blocks written in bytes |
|
227 |
TInt bytesWritten = len/blockLen * blockLen; |
|
228 |
aPos += bytesWritten; |
|
229 |
aLen -= bytesWritten; |
|
230 |
len = aLen; |
|
231 |
__SCSIPRINT2(_L("New Pos=0x%lx Len=0x%x"), aPos, aLen); |
|
232 |
||
233 |
TPtrC8 buf = aCopybuf.Mid(bytesWritten); |
|
234 |
||
235 |
// write rest of the block |
|
236 |
TInt err = iSbcInterface->Write10L(aPos/blockLen, buf, aOffset, len); |
|
237 |
if (err) |
|
238 |
{ |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
239 |
User::LeaveIfError(DoCheckConditionL()); |
0 | 240 |
} |
241 |
} |
|
242 |
} |
|
243 |
||
244 |
||
245 |
void CScsiProtocol::GetCapacityL(TCapsInfo& aCapsInfo) |
|
246 |
{ |
|
247 |
__MSFNLOG |
|
248 |
if (!IsConnected()) |
|
249 |
{ |
|
250 |
DoScsiReadyCheckEventL(); |
|
251 |
} |
|
252 |
||
253 |
TLba lastLba; |
|
254 |
TUint32 blockLength; |
|
255 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
256 |
// Retry ReadCapacity10L if stalled |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
257 |
TInt stallCounter = 4; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
258 |
TInt err = KErrNone; |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
259 |
do |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
260 |
{ |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
261 |
err = iSbcInterface->ReadCapacity10L(lastLba, blockLength); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
262 |
} while (err == KErrCommandStalled && stallCounter-- > 0); |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
263 |
|
0 | 264 |
if (err) |
265 |
{ |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
266 |
// DoCheckConditionL clears sense error |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
267 |
// Media not present will return KErrNotReady so leave here |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
268 |
User::LeaveIfError(DoCheckConditionL()); |
0 | 269 |
} |
270 |
||
271 |
// update iWriteProtect |
|
272 |
err = MsModeSense10L(); |
|
273 |
if (err) |
|
274 |
{ |
|
275 |
if (err == KErrCommandFailed) |
|
276 |
{ |
|
277 |
// Clear sense error |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
278 |
err = DoCheckConditionL(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
279 |
// ignore error if unsupported |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
280 |
if (err != KErrUnknown) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
281 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
282 |
User::LeaveIfError(err); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
283 |
} |
0 | 284 |
} |
285 |
||
286 |
err = MsModeSense6L(); |
|
287 |
if (err == KErrCommandFailed) |
|
288 |
{ |
|
289 |
// Clear sense error |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
290 |
err = DoCheckConditionL(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
291 |
// ignore error if unsupported |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
292 |
if (err != KErrUnknown) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
293 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
294 |
User::LeaveIfError(err); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
295 |
} |
0 | 296 |
} |
297 |
} |
|
298 |
||
299 |
aCapsInfo.iNumberOfBlocks = lastLba + 1; |
|
300 |
aCapsInfo.iBlockLength = blockLength; |
|
301 |
aCapsInfo.iWriteProtect = iWriteProtect; |
|
302 |
||
303 |
__SCSIPRINT3(_L("numBlock = x%x , blockLength = %x wp = %d"), |
|
304 |
lastLba + 1, blockLength, iWriteProtect); |
|
305 |
} |
|
306 |
||
307 |
||
308 |
/** |
|
309 |
Perform SCSI INQUIRY command. The function leaves if the device response is not |
|
310 |
compliant with the protocol standard. |
|
311 |
||
312 |
@return TInt KErrNone if successful otherwise KErrCommandFailed to indicate a |
|
313 |
device status error |
|
314 |
*/ |
|
315 |
TInt CScsiProtocol::MsInquiryL() |
|
316 |
{ |
|
317 |
__MSFNLOG |
|
318 |
ResetSbc(); |
|
319 |
||
320 |
/** |
|
321 |
INQUIRY |
|
322 |
*/ |
|
323 |
||
324 |
/** |
|
325 |
SPC states |
|
326 |
- the INQUIRY data should be returned even though the device server is not |
|
327 |
ready for other commands. |
|
328 |
||
329 |
- If the standard INQUIRY data changes for any reason, the device server |
|
330 |
shall generate a unit attention condition |
|
331 |
*/ |
|
332 |
TPeripheralInfo info; |
|
333 |
TInt err = iSpcInterface.InquiryL(info); |
|
334 |
if (err) |
|
335 |
{ |
|
336 |
// KErrCommandFailed |
|
337 |
return err; |
|
338 |
} |
|
339 |
||
340 |
// print reponse |
|
341 |
__TESTREPORT1(_L("RMB = %d"), info.iRemovable); |
|
342 |
__TESTREPORT2(_L("PERIPHERAL DEVICE TYPE = %d PQ = %d"), |
|
343 |
info.iPeripheralDeviceType, |
|
344 |
info.iPeripheralQualifier); |
|
345 |
__TESTREPORT1(_L("VERSION = %d"), info.iVersion); |
|
346 |
__TESTREPORT1(_L("RESPONSE DATA FORMAT = %d"), info.iResponseDataFormat); |
|
347 |
__TESTREPORT3(_L("VENDOR ID %S PRODUCT ID %S REV %S"), |
|
348 |
&info.iIdentification.iVendorId, |
|
349 |
&info.iIdentification.iProductId, |
|
350 |
&info.iIdentification.iProductRev); |
|
351 |
||
352 |
if (info.iPeripheralQualifier != 0 && info.iPeripheralQualifier != 1) |
|
353 |
{ |
|
354 |
__HOSTPRINT(_L("Peripheral Qualifier[Unknown device type]\n")) |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
355 |
return KErrUnknown; |
0 | 356 |
} |
357 |
||
358 |
if (info.iPeripheralDeviceType != 0) |
|
359 |
{ |
|
360 |
__HOSTPRINT(_L("Peripheral Device Type[Unsupported device type]\n")) |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
361 |
return KErrUnknown; |
0 | 362 |
} |
363 |
||
364 |
iRemovableMedia = info.iRemovable; |
|
365 |
||
366 |
// SCSI Block device |
|
367 |
iSbcInterface = new (ELeave) TSbcClientInterface(iSpcInterface.Transport()); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
iSbcInterface->InitBuffers(&iHeadbuf, &iTailbuf); |
0 | 369 |
|
370 |
return KErrNone; |
|
371 |
} |
|
372 |
||
373 |
||
374 |
/** |
|
375 |
Perform SCSI TEST UNIT READY command. The function leaves if the device response |
|
376 |
is not compliant with the protocol standard. |
|
377 |
||
378 |
@return TInt KErrNone if successful or otherwise KErrCommandFailed to indicate a |
|
379 |
device status error |
|
380 |
*/ |
|
381 |
TInt CScsiProtocol::MsTestUnitReadyL() |
|
382 |
{ |
|
383 |
__MSFNLOG |
|
384 |
/* TestUnitReady */ |
|
385 |
return iSpcInterface.TestUnitReadyL(); |
|
386 |
} |
|
387 |
||
388 |
||
389 |
/** |
|
390 |
Perform SCSI READ CAPACITY (10) command. The function leaves if the device |
|
391 |
response is not compliant with the protocol standard. |
|
392 |
||
393 |
Before a block device can be read or written the media's capacity (LAST LBA and |
|
394 |
BLOCK SIZE) must be obtained. This function is used to initialise TBlockTransfer |
|
395 |
with the capacity parameters via TSbcInterface::ReadCapcaityL(). |
|
396 |
||
397 |
@return TInt KErrNone if successful, KErrCommandFailed to indicate a |
|
398 |
device status error, KErrCommandStalled to indicate a device stall |
|
399 |
*/ |
|
400 |
TInt CScsiProtocol::MsReadCapacityL() |
|
401 |
{ |
|
402 |
__MSFNLOG |
|
403 |
// READ CAPACITY |
|
404 |
TUint32 blockSize; |
|
405 |
TUint32 lastLba; |
|
406 |
TInt err = iSbcInterface->ReadCapacity10L(lastLba, blockSize); |
|
407 |
||
408 |
__TESTREPORT2(_L("CAPACITY: Block Size=0x%x Last LBA=0x%x"), blockSize, lastLba); |
|
409 |
return err; |
|
410 |
} |
|
411 |
||
412 |
||
413 |
/** |
|
414 |
Perform MODE SENSE (10) command. The function leaves if the device response is |
|
415 |
not compliant with the protocol standard. |
|
416 |
||
417 |
@return TInt KErrNone if successful, KErrCommandFailed to indicate a |
|
418 |
device status error, KErrCommandStalled to indicate a device stall |
|
419 |
*/ |
|
420 |
TInt CScsiProtocol::MsModeSense10L() |
|
421 |
{ |
|
422 |
__MSFNLOG |
|
423 |
TBool writeProtected; |
|
424 |
TInt err = iSbcInterface->ModeSense10L(TSbcClientInterface::EReturnAllModePages, writeProtected); |
|
425 |
||
426 |
if (!err) |
|
427 |
{ |
|
428 |
iWriteProtect = writeProtected; |
|
429 |
} |
|
430 |
return err; |
|
431 |
} |
|
432 |
||
433 |
||
434 |
/** |
|
435 |
Perform SCSI MODE SENSE (6) command. The function leaves if the device response |
|
436 |
is not compliant with the protocol standard. |
|
437 |
||
438 |
@return TInt KErrNone if successful, KErrCommandFailed to indicate a |
|
439 |
device status error, KErrCommandStalled to indicate a device stall |
|
440 |
*/ |
|
441 |
TInt CScsiProtocol::MsModeSense6L() |
|
442 |
{ |
|
443 |
__MSFNLOG |
|
444 |
TBool writeProtected; |
|
445 |
TInt err = iSbcInterface->ModeSense6L(TSbcClientInterface::EReturnAllModePages, writeProtected); |
|
446 |
||
447 |
if (!err) |
|
448 |
{ |
|
449 |
iWriteProtect = writeProtected; |
|
450 |
} |
|
451 |
return err; |
|
452 |
} |
|
453 |
||
454 |
||
455 |
/** |
|
456 |
Perform SCSI START STOP UNIT command. The function leaves if the device response |
|
457 |
is not compliant with the protocol standard. |
|
458 |
||
459 |
@return TInt KErrNone if successful otherwise KErrCommandFailed to indicate a |
|
460 |
device status error |
|
461 |
*/ |
|
462 |
TInt CScsiProtocol::MsStartStopUnitL(TBool aStart) |
|
463 |
{ |
|
464 |
__MSFNLOG |
|
465 |
return iSbcInterface->StartStopUnitL(aStart); |
|
466 |
} |
|
467 |
||
468 |
||
469 |
/** |
|
470 |
Perform SCSI PREVENT ALLOW MEDIA REMOVAL command. The function leaves if the |
|
471 |
device response is not compliant with the protocol standard. |
|
472 |
||
473 |
@return TInt KErrNone if successful otherwise KErrCommandFailed to indicate a |
|
474 |
device status error |
|
475 |
*/ |
|
476 |
TInt CScsiProtocol::MsPreventAllowMediaRemovalL(TBool aPrevent) |
|
477 |
{ |
|
478 |
__MSFNLOG |
|
479 |
return iSpcInterface.PreventAllowMediumRemovalL(aPrevent); |
|
480 |
} |
|
481 |
||
482 |
||
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
483 |
TInt CScsiProtocol::DoCheckConditionL() |
0 | 484 |
{ |
485 |
__MSFNLOG |
|
486 |
User::LeaveIfError(MsRequestSenseL()); |
|
487 |
||
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
488 |
TInt err; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
489 |
|
0 | 490 |
// Check if init is needed |
491 |
if (iSenseInfo.iSenseCode == TSenseInfo::ENotReady && |
|
492 |
iSenseInfo.iAdditional == TSenseInfo::EAscLogicalUnitNotReady && |
|
493 |
iSenseInfo.iQualifier == TSenseInfo::EAscqInitializingCommandRequired) |
|
494 |
{ |
|
495 |
// start unit |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
496 |
err = iSbcInterface->StartStopUnitL(ETrue); |
0 | 497 |
if (err) |
498 |
{ |
|
499 |
User::LeaveIfError(MsRequestSenseL()); |
|
500 |
} |
|
501 |
} |
|
502 |
||
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
503 |
err = GetSystemWideSenseError(iSenseInfo); |
0 | 504 |
|
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
505 |
TScsiState nextState = iState; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
506 |
if (err == KErrDisconnected) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
507 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
508 |
nextState = EDisconnected; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
509 |
} |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
510 |
else if (err == KErrNotReady) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
511 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
512 |
nextState = EMediaNotPresent; |
0 | 513 |
} |
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
514 |
else |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
515 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
516 |
// no state change; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
517 |
} |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
518 |
|
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
519 |
if (nextState != iState) |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
520 |
{ |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
521 |
iMediaChangeNotifier.DoNotifyL(); |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
522 |
iState = nextState; |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
523 |
} |
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
524 |
|
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
525 |
return err; |
0 | 526 |
} |
527 |
||
528 |
||
529 |
/** |
|
530 |
Map SCSI sense error to a system wide error code |
|
531 |
KErrNotReady could happen due to any of the following reasons: |
|
532 |
1. Lun is in the process of becoming ready |
|
533 |
2. Initialising command is required |
|
534 |
3. Lun is not ready to process the command - meaning it is still handling |
|
535 |
the previous command |
|
536 |
||
537 |
KErrUnknown could happen due to any of the following reasons: |
|
538 |
1. Mass storage device does not respond to the selected logical unit, other |
|
539 |
than the locial unit not ready scenario 2. The command sent was not |
|
540 |
recognized or contains a invalid code 3. Invialid field in the command block |
|
541 |
4. The requested logical unit is not supported |
|
542 |
5. The mass storage device cnosists of insufficient resource |
|
543 |
6. Hardware error |
|
544 |
7. Blank check |
|
545 |
8. Vendor specific error |
|
546 |
9. Any illegal request (we assume the commands sent by MSC should be |
|
547 |
supported by the device, if not then the illegal request is said to be of |
|
548 |
unknown system wide error for Symbian. 10. Miscompare - we do not support |
|
549 |
the compare operation/command so this error should not happen |
|
550 |
||
551 |
KErrAccessDenied could happen due to any of the following reasons: |
|
552 |
1. Data protection error happened |
|
553 |
2. Media was write protected |
|
554 |
3. Media was not present |
|
555 |
||
556 |
KErrOverflow could happen due to any of the following reasons: |
|
557 |
1. Data over flow occured |
|
558 |
2. The requested LBA is out of range |
|
559 |
||
560 |
KErrAbort could happen due to any of the following reasons: |
|
561 |
1. A copy operation is aborted. |
|
562 |
2. The command is aborted |
|
563 |
||
564 |
KErrCorrupt could happen due to any of the following reasons: |
|
565 |
1. The underlying media was having errors |
|
566 |
||
567 |
KErrDisconnected could happen due to any of the following reasons: |
|
568 |
1. The media was changed/removed - While this error is happening the file |
|
569 |
extension will be notified setting the iChanged flag |
|
570 |
*/ |
|
571 |
TInt CScsiProtocol::GetSystemWideSenseError(const TSenseInfo& aSenseInfo) |
|
572 |
{ |
|
573 |
__MSFNLOG |
|
574 |
TInt ret = KErrNone; |
|
575 |
TInt additionalError = KErrNone; |
|
576 |
||
577 |
switch(aSenseInfo.iSenseCode) |
|
578 |
{ |
|
579 |
case TSenseInfo::ENoSense: |
|
580 |
case TSenseInfo::ERecoveredError: |
|
581 |
ret = KErrNone; |
|
582 |
break; |
|
583 |
case TSenseInfo::ENotReady: |
|
584 |
ret = KErrNotReady; |
|
585 |
additionalError = ProcessAsCodes(aSenseInfo); |
|
586 |
if (additionalError != KErrNone) |
|
587 |
{ |
|
588 |
ret = additionalError; |
|
589 |
} |
|
590 |
break; |
|
591 |
case TSenseInfo::EMediumError: |
|
592 |
ret = KErrCorrupt; |
|
593 |
additionalError = ProcessAsCodes(aSenseInfo); |
|
594 |
if (additionalError != KErrNone) |
|
595 |
{ |
|
596 |
ret = additionalError; |
|
597 |
} |
|
598 |
break; |
|
599 |
case TSenseInfo::EUnitAttention: |
|
600 |
ret = KErrDisconnected; |
|
601 |
break; |
|
602 |
case TSenseInfo::EDataProtection: |
|
603 |
ret = KErrAccessDenied; |
|
604 |
break; |
|
605 |
case TSenseInfo::EIllegalRequest: |
|
606 |
case TSenseInfo::EHardwareError: |
|
607 |
case TSenseInfo::EBlankCheck: |
|
608 |
case TSenseInfo::EVendorSpecific: |
|
609 |
case TSenseInfo::EMisCompare: |
|
610 |
ret = KErrUnknown; |
|
611 |
break; |
|
612 |
case TSenseInfo::ECopyAborted: |
|
613 |
case TSenseInfo::EAbortedCommand: |
|
614 |
ret = KErrAbort; |
|
615 |
break; |
|
616 |
case TSenseInfo::EDataOverflow: |
|
617 |
ret = KErrOverflow; |
|
618 |
break; |
|
619 |
default: |
|
620 |
ret = KErrUnknown; |
|
621 |
break; |
|
622 |
} |
|
623 |
||
624 |
return ret; |
|
625 |
} |
|
626 |
||
627 |
||
628 |
TInt CScsiProtocol::ProcessAsCodes(const TSenseInfo& aSenseInfo) |
|
629 |
{ |
|
630 |
__MSFNLOG |
|
631 |
TInt ret = KErrNone; |
|
632 |
||
633 |
switch(aSenseInfo.iAdditional) |
|
634 |
{ |
|
635 |
case TSenseInfo::EAscLogicalUnitNotReady: |
|
636 |
case TSenseInfo::EMediaNotPresent: |
|
637 |
ret = KErrNotReady; |
|
638 |
break; |
|
639 |
||
640 |
case TSenseInfo::ELbaOutOfRange: |
|
641 |
ret = KErrOverflow; |
|
642 |
break; |
|
643 |
||
644 |
case TSenseInfo::EWriteProtected: |
|
645 |
ret = KErrAccessDenied; |
|
646 |
break; |
|
647 |
||
648 |
case TSenseInfo::ENotReadyToReadyChange: |
|
649 |
ret = KErrNone; |
|
650 |
break; |
|
651 |
||
652 |
case TSenseInfo::EAscLogicalUnitDoesNotRespondToSelection: |
|
653 |
case TSenseInfo::EInvalidCmdCode: |
|
654 |
case TSenseInfo::EInvalidFieldInCdb: |
|
655 |
case TSenseInfo::ELuNotSupported: |
|
656 |
case TSenseInfo::EInsufficientRes: |
|
657 |
ret = KErrUnknown; |
|
658 |
break; |
|
659 |
default: |
|
660 |
ret = KErrNone; |
|
661 |
break; |
|
662 |
} |
|
663 |
return ret; |
|
664 |
} |
|
665 |
||
666 |
||
667 |
/** |
|
668 |
Perform SCSI REQUEST SENSE command. The function leaves if the device response |
|
669 |
is not compliant with the protocol standard. |
|
670 |
||
671 |
@return TInt KErrNone if successful otherwise KErrCommandFailed to indicate a |
|
672 |
device status error |
|
673 |
*/ |
|
674 |
TInt CScsiProtocol::MsRequestSenseL() |
|
675 |
{ |
|
676 |
__MSFNLOG |
|
677 |
return iSpcInterface.RequestSenseL(iSenseInfo) ? KErrCommandFailed : KErrNone; |
|
678 |
} |
|
679 |
||
680 |
||
681 |
void CScsiProtocol::CreateSbcInterfaceL(TUint32 aBlockLen, TUint32 aLastLba) |
|
682 |
{ |
|
683 |
__MSFNLOG |
|
684 |
// SCSI Block device |
|
685 |
ASSERT(iSbcInterface == NULL); |
|
686 |
iSbcInterface = new (ELeave) TSbcClientInterface(iSpcInterface.Transport()); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
687 |
iSbcInterface->InitBuffers(&iHeadbuf, &iTailbuf); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
688 |
iSbcInterface->SetCapacityL(aBlockLen, aLastLba); |
0 | 689 |
} |
690 |
||
691 |
||
692 |
void CScsiProtocol::ResetSbc() |
|
693 |
{ |
|
694 |
__MSFNLOG |
|
695 |
if (iSbcInterface) |
|
696 |
{ |
|
697 |
delete iSbcInterface; |
|
698 |
iSbcInterface = NULL; |
|
699 |
} |
|
700 |
} |
|
701 |
||
702 |
||
703 |
void CScsiProtocol::NotifyChange(const RMessage2& aMessage) |
|
704 |
{ |
|
705 |
__MSFNLOG |
|
706 |
iMediaChangeNotifier.Register(aMessage); |
|
707 |
} |
|
708 |
||
709 |
||
710 |
void CScsiProtocol::ForceCompleteNotifyChangeL() |
|
711 |
{ |
|
712 |
__MSFNLOG |
|
713 |
iMediaChangeNotifier.DoNotifyL(); |
|
714 |
} |
|
715 |
||
716 |
||
717 |
void CScsiProtocol::CancelChangeNotifierL() |
|
718 |
{ |
|
719 |
__MSFNLOG |
|
720 |
iMediaChangeNotifier.DoCancelL(); |
|
721 |
} |
|
722 |
||
723 |
||
724 |
void CScsiProtocol::SuspendL() |
|
725 |
{ |
|
726 |
__MSFNLOG |
|
727 |
if (iFsm->StartStopUnitRequired()) |
|
728 |
{ |
|
729 |
iSbcInterface->StartStopUnitL(EFalse); |
|
730 |
} |
|
731 |
} |
|
732 |
||
733 |
void CScsiProtocol::ResumeL() |
|
734 |
{ |
|
735 |
__MSFNLOG |
|
736 |
if (iFsm->StartStopUnitRequired()) |
|
737 |
{ |
|
738 |
iSbcInterface->StartStopUnitL(ETrue); |
|
739 |
} |
|
740 |
} |
|
741 |
||
742 |
||
743 |
void CScsiProtocol::DoScsiReadyCheckEventL() |
|
744 |
{ |
|
745 |
__MSFNLOG |
|
746 |
TInt err = KErrNone; |
|
747 |
||
102
ef2a444a7410
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
748 |
if(iFsm->IsRemovableMedia() || iState != EConnected) |
0 | 749 |
{ |
750 |
iFsm->SetStatusCheck(); |
|
751 |
TRAP(err, iFsm->ConnectLogicalUnitL()); |
|
752 |
iFsm->ClearStatusCheck(); |
|
753 |
||
754 |
User::LeaveIfError(err); |
|
755 |
err = iFsm->IsConnected() ? KErrNone : KErrNotReady; |
|
756 |
} |
|
757 |
||
758 |
if (iState == EConnected) |
|
759 |
{ |
|
760 |
if (err != KErrNone) |
|
761 |
{ |
|
762 |
iState = EDisconnected; |
|
763 |
__SCSIPRINT(_L("** Disconnected Notification **")); |
|
764 |
iMediaChangeNotifier.DoNotifyL(); |
|
765 |
} |
|
766 |
} |
|
767 |
else |
|
768 |
{ |
|
769 |
if (err == KErrNone) |
|
770 |
{ |
|
771 |
iState = EConnected; |
|
772 |
__SCSIPRINT(_L("** Connected Notification **")); |
|
773 |
iMediaChangeNotifier.DoNotifyL(); |
|
774 |
} |
|
775 |
} |
|
776 |
} |
|
777 |
||
778 |
||
779 |
RMediaChangeNotifier::RMediaChangeNotifier() |
|
780 |
: iRegistered(EFalse) |
|
781 |
{ |
|
782 |
__MSFNSLOG |
|
783 |
} |
|
784 |
||
785 |
||
786 |
RMediaChangeNotifier::~RMediaChangeNotifier() |
|
787 |
{ |
|
788 |
__MSFNSLOG |
|
789 |
if (iRegistered) |
|
790 |
iNotifier.Complete(KErrDisconnected); |
|
791 |
} |
|
792 |
||
793 |
/** |
|
794 |
Initialise notifier to enable media change notfications. |
|
795 |
||
796 |
@param aMessage The message to commplete the notification |
|
797 |
*/ |
|
798 |
void RMediaChangeNotifier::Register(const RMessage2& aMessage) |
|
799 |
{ |
|
800 |
__MSFNLOG |
|
801 |
iRegistered = ETrue; |
|
802 |
iNotifier = aMessage; |
|
803 |
} |
|
804 |
||
805 |
||
806 |
void RMediaChangeNotifier::DoNotifyL() |
|
807 |
{ |
|
808 |
__MSFNLOG |
|
809 |
CompleteNotifierL(KErrNone); |
|
810 |
} |
|
811 |
||
812 |
void RMediaChangeNotifier::DoCancelL() |
|
813 |
{ |
|
814 |
__MSFNLOG |
|
815 |
CompleteNotifierL(KErrCancel); |
|
816 |
} |
|
817 |
||
818 |
void RMediaChangeNotifier::CompleteNotifierL(TInt aReason) |
|
819 |
{ |
|
820 |
__MSFNLOG |
|
821 |
if (iRegistered) |
|
822 |
{ |
|
823 |
TBool mediaChanged = ETrue; |
|
824 |
TPtrC8 pStatus((TUint8*)&mediaChanged,sizeof(TBool)); |
|
825 |
iNotifier.WriteL(0,pStatus); |
|
826 |
iNotifier.Complete(aReason); |
|
827 |
iRegistered = EFalse; |
|
828 |
} |
|
829 |
} |