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