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