author | hgs |
Tue, 02 Nov 2010 15:29:23 +0000 | |
changeset 300 | 1d28c8722707 |
parent 286 | 48e57fb1237e |
permissions | -rw-r--r-- |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 2004-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 |
||
286 | 16 |
#include <e32std.h> |
17 |
#include "mtransport.h" |
|
18 |
#include "mprotocol.h" |
|
0 | 19 |
#include "scsiprot.h" |
286 | 20 |
#ifdef MSDC_MULTITHREADED |
0 | 21 |
#include "rwdrivethread.h" |
22 |
#endif // MSDC_MULTITHREADED |
|
286 | 23 |
|
24 |
#include "OstTraceDefinitions.h" |
|
25 |
#ifdef OST_TRACE_COMPILER_IN_USE |
|
26 |
#include "scsiprotTraces.h" |
|
27 |
#endif |
|
0 | 28 |
|
29 |
// Helper macros |
|
30 |
#define LBA(x) static_cast<TUint32>((x[3] << 24) | (x[4] << 16) | (x[5] << 8) | x[6]) |
|
31 |
#define LEN(x) static_cast<TUint16>((x[8] << 8) | x[9]) |
|
32 |
||
33 |
||
286 | 34 |
static const TUint32 KDefaultBlockSize = 0x200; //default block size for FAT |
0 | 35 |
|
286 | 36 |
static const TUint KUndefinedLun = 0xFFFF; |
0 | 37 |
|
286 | 38 |
static const TUint8 KAllPages = 0x3F; |
0 | 39 |
|
286 | 40 |
static const TUint8 KChangeableValues = 0x1; |
41 |
static const TUint8 KDefaultValues = 0x2; |
|
0 | 42 |
|
43 |
/** |
|
44 |
Default constructor for TSenseInfo |
|
45 |
*/ |
|
46 |
TSenseInfo::TSenseInfo() |
|
286 | 47 |
: iSenseCode(ENoSense), |
48 |
iAdditional(EAscNull), |
|
49 |
iQualifier(EAscqNull) |
|
50 |
{} |
|
0 | 51 |
|
52 |
||
53 |
/** |
|
54 |
Set sense with no additional info. |
|
55 |
||
56 |
@param aSenseCode sense key |
|
57 |
*/ |
|
58 |
void TSenseInfo::SetSense(TSenseCode aSenseCode) |
|
286 | 59 |
{ |
60 |
iSenseCode = static_cast<TUint8>(aSenseCode); |
|
61 |
iAdditional = EAscNull; |
|
62 |
iQualifier = EAscqNull; |
|
63 |
OstTraceExt3(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_SETSENSE1, " SENSE CODE %d ASC %d ASC %d", iSenseCode, iAdditional, iQualifier); |
|
64 |
} |
|
0 | 65 |
|
66 |
||
67 |
/** |
|
68 |
Set sense with additional info. |
|
69 |
||
70 |
@param aSenseCode sense key |
|
286 | 71 |
@param aAdditional additional sense code (ASC) |
0 | 72 |
*/ |
73 |
void TSenseInfo::SetSense(TSenseCode aSenseCode, TAdditionalCode aAdditional) |
|
74 |
||
286 | 75 |
{ |
76 |
iSenseCode = static_cast<TUint8>(aSenseCode); |
|
77 |
iAdditional = static_cast<TUint8>(aAdditional); |
|
78 |
iQualifier = EAscqNull; |
|
79 |
OstTraceExt3(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_SETSENSE2, " SENSE CODE %d ASC %d ASC %d", iSenseCode, iAdditional, iQualifier); |
|
80 |
} |
|
0 | 81 |
|
82 |
||
83 |
/** |
|
84 |
Set sense with additional info and qualifier. |
|
85 |
||
286 | 86 |
@param aSenseCode sense key |
87 |
@param aAdditional additional sense code (ASC) |
|
0 | 88 |
@param aQualifier additional sense code qualifier (ASCQ) |
89 |
*/ |
|
90 |
void TSenseInfo::SetSense(TSenseCode aSenseCode, |
|
286 | 91 |
TAdditionalCode aAdditional, |
92 |
TAdditionalSenseCodeQualifier aQualifier) |
|
93 |
{ |
|
94 |
iSenseCode = static_cast<TUint8>(aSenseCode); |
|
95 |
iAdditional = static_cast<TUint8>(aAdditional); |
|
96 |
iQualifier = static_cast<TUint8>(aQualifier); |
|
97 |
OstTraceExt3(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_SETSENSE3, " SENSE CODE %d ASC %d ASC %d", iSenseCode, iAdditional, iQualifier); |
|
98 |
} |
|
0 | 99 |
|
100 |
||
101 |
//----------------------------------------------- |
|
102 |
||
103 |
/** |
|
104 |
Creates the CScsiProtocol object. Called during controller initialisation. |
|
105 |
||
106 |
@param aDriveManager reference to the drive manager object |
|
107 |
*/ |
|
108 |
CScsiProtocol* CScsiProtocol::NewL(CDriveManager& aDriveManager) |
|
286 | 109 |
{ |
110 |
CScsiProtocol* self = new (ELeave) CScsiProtocol(aDriveManager); |
|
111 |
CleanupStack::PushL(self); |
|
112 |
self->ConstructL(); |
|
113 |
CleanupStack::Pop(); |
|
114 |
return self; |
|
115 |
} |
|
0 | 116 |
|
117 |
/** |
|
118 |
c'tor |
|
119 |
||
120 |
@param aDriveManager reference to the drive manager object |
|
121 |
*/ |
|
122 |
CScsiProtocol::CScsiProtocol(CDriveManager& aDriveManager): |
|
286 | 123 |
iDriveManager(aDriveManager), |
124 |
iLastCommand(EUndefinedCommand), |
|
125 |
iLastLun(KUndefinedLun), |
|
126 |
iMediaWriteSize(KDefaultMediaWriteSize) |
|
127 |
{ |
|
0 | 128 |
#ifdef USB_TRANSFER_PUBLISHER |
286 | 129 |
iWriteTransferPublisher = CUsbWriteTransferPublisher::NewL(iBytesWritten); |
130 |
iReadTransferPublisher = CUsbReadTransferPublisher::NewL(iBytesRead); |
|
0 | 131 |
|
286 | 132 |
for (TUint i = 0; i < KUsbMsMaxDrives; i++) |
133 |
{ |
|
134 |
iBytesRead[i] = 0; |
|
135 |
iBytesWritten[i] = 0; |
|
136 |
} |
|
0 | 137 |
#else |
286 | 138 |
iWriteTransferPublisher = CDriveWriteTransferPublisher::NewL(aDriveManager.iDrives); |
139 |
iReadTransferPublisher = CDriveReadTransferPublisher::NewL(aDriveManager.iDrives); |
|
0 | 140 |
#endif |
286 | 141 |
} |
0 | 142 |
|
143 |
||
144 |
CScsiProtocol::~CScsiProtocol() |
|
286 | 145 |
{ |
0 | 146 |
#ifdef MSDC_MULTITHREADED |
286 | 147 |
OstTrace0(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_DES, "Deleting Drive Threads"); |
148 |
delete iWriteDriveThread; |
|
149 |
delete iReadDriveThread; |
|
0 | 150 |
#endif // MSDC_MULTITHREADED |
151 |
||
286 | 152 |
delete iWriteTransferPublisher; |
153 |
delete iReadTransferPublisher; |
|
154 |
} |
|
0 | 155 |
|
156 |
||
157 |
void CScsiProtocol::ConstructL() |
|
286 | 158 |
{ |
0 | 159 |
#ifdef MSDC_MULTITHREADED |
286 | 160 |
OstTrace0(TRACE_SMASSSTORAGE, _CSCSIPROTOCOL, "Creating Drive Threads"); |
161 |
iWriteDriveThread = CWriteDriveThread::NewL(); |
|
162 |
iReadDriveThread = CReadDriveThread::NewL(); |
|
0 | 163 |
#endif // MSDC_MULTITHREADED |
286 | 164 |
} |
0 | 165 |
|
166 |
||
167 |
/** |
|
168 |
Associates the transport with the protocol. Called during initialisation of the controller. |
|
169 |
||
170 |
@param aTransport pointer to the transport object |
|
171 |
*/ |
|
172 |
void CScsiProtocol::RegisterTransport(MTransportBase* aTransport) |
|
286 | 173 |
{ |
174 |
iTransport = aTransport; |
|
175 |
} |
|
0 | 176 |
|
177 |
||
178 |
/** |
|
179 |
Called by the Transport when it detects that the USB device is either running |
|
180 |
at High Speed or is at least capable of HS operation. The Protocol can use this |
|
181 |
information (for instance) to select the optimal write block size to use. |
|
182 |
||
183 |
This function is preferably called before actual MS data transfer operation |
|
184 |
starts, and usually only once. |
|
185 |
||
186 |
*/ |
|
187 |
void CScsiProtocol::ReportHighSpeedDevice() |
|
286 | 188 |
{ |
189 |
iMediaWriteSize = KHsMediaWriteSize; |
|
190 |
OstTrace1(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_REPORTHIGHSPEEDDEVICE, |
|
191 |
"HS Device reported: SCSI will use 0x%x bytes disk write size", iMediaWriteSize); |
|
192 |
} |
|
0 | 193 |
|
194 |
||
195 |
TInt CScsiProtocol::SetScsiParameters(TMassStorageConfig aConfig) |
|
286 | 196 |
{ |
197 |
iConfig = aConfig; |
|
198 |
return KErrNone; |
|
199 |
} |
|
0 | 200 |
|
201 |
#ifdef MSDC_MULTITHREADED |
|
202 |
||
203 |
void CScsiProtocol::ProcessWriteComplete (TUint8* aAddress, TAny* aPtr) |
|
286 | 204 |
{ |
205 |
((CScsiProtocol*)aPtr)->iTransport->ProcessReadData(aAddress); |
|
206 |
} |
|
0 | 207 |
|
208 |
void CScsiProtocol::InitializeBufferPointers(TPtr8& aDes1, TPtr8& aDes2) // Todo Change name later - InitializeReadBufferSomething |
|
286 | 209 |
{ |
210 |
iReadDriveThread->iThreadContext->iBuffer.SetUpReadBuf(aDes1, aDes2); |
|
211 |
} |
|
0 | 212 |
#endif |
213 |
||
214 |
/** |
|
215 |
Called by the transport layer when a packet is available for decoding. |
|
216 |
If an error occurs, the sense code is updated and EFalse is returned. |
|
217 |
||
218 |
@param aData |
|
219 |
||
220 |
@return ETrue if command was decoded and executed successfully |
|
221 |
*/ |
|
222 |
TBool CScsiProtocol::DecodePacket(TPtrC8& aData, TUint aLun) |
|
286 | 223 |
{ |
224 |
TUint command = aData[1]; |
|
0 | 225 |
|
286 | 226 |
if (command != ERequestSense) |
227 |
{ |
|
228 |
iSenseInfo.SetSense(TSenseInfo::ENoSense); |
|
229 |
} |
|
0 | 230 |
|
286 | 231 |
OstTraceExt2(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_DECODEPACKET, "Command=0x%x LUN=%d", command, aLun); |
232 |
switch (command) |
|
233 |
{ |
|
234 |
case ETestUnitReady: |
|
235 |
HandleUnitReady(aLun); |
|
236 |
break; |
|
0 | 237 |
|
286 | 238 |
case ERequestSense: |
239 |
HandleRequestSense(aData); |
|
240 |
break; |
|
0 | 241 |
|
286 | 242 |
case EInquiry: |
243 |
HandleInquiry(aData, aLun); |
|
244 |
break; |
|
0 | 245 |
|
286 | 246 |
case EModeSense6: |
247 |
HandleModeSense6(aData, aLun); |
|
248 |
break; |
|
0 | 249 |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
case EModeSense10: |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
HandleModeSense10(aData, aLun); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
break; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
|
286 | 254 |
case EStartStopUnit: |
255 |
HandleStartStopUnit(aData, aLun); |
|
256 |
break; |
|
0 | 257 |
|
286 | 258 |
case EPreventMediaRemoval: |
259 |
HandlePreventMediaRemoval(aData, aLun); |
|
260 |
break; |
|
0 | 261 |
|
286 | 262 |
case EReadCapacity: |
263 |
HandleReadCapacity(aData, aLun); |
|
264 |
break; |
|
0 | 265 |
|
286 | 266 |
case ERead10: |
267 |
HandleRead10(aData, aLun); |
|
268 |
break; |
|
0 | 269 |
|
286 | 270 |
case EWrite10: |
271 |
HandleWrite10(aData,aLun); |
|
272 |
break; |
|
0 | 273 |
|
286 | 274 |
case EVerify10: |
275 |
HandleVerify10(aData, aLun); |
|
276 |
break; |
|
0 | 277 |
|
286 | 278 |
case EReadFormatCapacities: |
279 |
HandleReadFormatCapacities(aLun); |
|
280 |
break; |
|
0 | 281 |
|
286 | 282 |
default: |
283 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::EInvalidCmdCode); |
|
284 |
} |
|
285 |
return(iSenseInfo.SenseOk()); |
|
286 |
} |
|
0 | 287 |
|
288 |
||
289 |
/** |
|
290 |
Checks if drive ready |
|
291 |
||
286 | 292 |
@param aLun Logic unit number |
0 | 293 |
@return pointer to drive correspondent to LUN if drive mounted and ready, NULL otherwise |
294 |
*/ |
|
295 |
CMassStorageDrive* CScsiProtocol::GetCheckDrive(TUint aLun) |
|
286 | 296 |
{ |
297 |
TInt err=KErrNone; |
|
0 | 298 |
|
299 |
#ifdef MSDC_MULTITHREADED |
|
286 | 300 |
// check for deferred errors |
301 |
if (iWriteDriveThread->DeferredError()) |
|
302 |
{ |
|
303 |
iWriteDriveThread->ClearDeferredError(); |
|
304 |
iDeferredSenseInfo.SetSense(TSenseInfo::EMediumError); |
|
305 |
return NULL; |
|
306 |
} |
|
0 | 307 |
|
308 |
#endif |
|
309 |
||
286 | 310 |
CMassStorageDrive* drive= iDriveManager.Drive(aLun, err); |
0 | 311 |
|
286 | 312 |
if (err !=KErrNone || drive == NULL) |
313 |
{ |
|
314 |
OstTrace0(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_GETCHECKDRIVE1, "No drive available"); |
|
315 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::ELuNotSupported); |
|
316 |
return NULL; |
|
317 |
} |
|
0 | 318 |
|
286 | 319 |
CMassStorageDrive::TMountState mountState = drive->MountState(); |
0 | 320 |
|
286 | 321 |
if (mountState == CMassStorageDrive::EDisconnected || mountState == CMassStorageDrive::EConnecting) |
322 |
{ |
|
323 |
OstTrace0(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_GETCHECKDRIVE2, "Drive disconnected"); |
|
324 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, |
|
325 |
TSenseInfo::EMediaNotPresent); |
|
326 |
return NULL; |
|
327 |
} |
|
0 | 328 |
|
286 | 329 |
CMassStorageDrive::TDriveState state = drive->CheckDriveState(); |
330 |
if (state == CMassStorageDrive::EMediaNotPresent || state == CMassStorageDrive::ELocked) |
|
331 |
{ |
|
332 |
OstTrace1(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_GETCHECKDRIVE3, "Media not present or locked. state =0x%X", state); |
|
333 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, TSenseInfo::EMediaNotPresent); |
|
334 |
return NULL; |
|
335 |
} |
|
0 | 336 |
|
286 | 337 |
if (drive->IsMediaChanged(ETrue)) //reset "media changed" status |
338 |
{ |
|
339 |
OstTrace0(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_GETCHECKDRIVE4, "Media was changed"); |
|
340 |
// SAM-2 Section 5.9.5 Unit Attention Condition |
|
341 |
iSenseInfo.SetSense(TSenseInfo::EUnitAttention, TSenseInfo::ENotReadyToReadyChange); |
|
342 |
iDriveManager.Connect(aLun); //publish event to USB app |
|
343 |
return NULL; |
|
344 |
} |
|
0 | 345 |
|
286 | 346 |
if (mountState == CMassStorageDrive::EDisconnecting) |
347 |
{ |
|
348 |
OstTrace0(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_GETCHECKDRIVE5, "Drive disconnecting"); |
|
349 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, |
|
350 |
TSenseInfo::EMediaNotPresent); |
|
351 |
return NULL; |
|
352 |
} |
|
0 | 353 |
|
286 | 354 |
return drive; |
355 |
} |
|
0 | 356 |
|
357 |
||
358 |
/** |
|
359 |
Command Parser for the UNIT READY command (0x00) |
|
360 |
||
286 | 361 |
@param aLun Logic unit number |
362 |
@return ETrue if successful, |
|
0 | 363 |
*/ |
364 |
TBool CScsiProtocol::HandleUnitReady(TUint aLun) |
|
286 | 365 |
{ |
366 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_TESTUNITREADY, ">>> TEST UNIT READY"); |
|
0 | 367 |
#ifdef MSDC_MULTITHREADED |
286 | 368 |
iWriteDriveThread->WaitForWriteEmpty(); |
0 | 369 |
#endif |
286 | 370 |
return GetCheckDrive(aLun) ? (TBool)ETrue : (TBool)EFalse; |
371 |
} |
|
0 | 372 |
|
373 |
||
374 |
/** |
|
375 |
Command Parser for the REQUEST SENSE command (0x03) |
|
376 |
||
286 | 377 |
@return ETrue if successful, |
0 | 378 |
*/ |
379 |
TBool CScsiProtocol::HandleRequestSense(TPtrC8& aData) |
|
286 | 380 |
{ |
381 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_REQUESTSENSE, ">>> REQUEST SENSE"); |
|
382 |
TUint length = aData[5]; |
|
383 |
OstTrace1(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_REQUESTSENSE1, " length = %d", length); |
|
0 | 384 |
|
286 | 385 |
TPtr8 writeBuf(NULL, 0); |
386 |
iTransport->GetCommandBufPtr(writeBuf, KRequestSenseCommandLength); |
|
387 |
writeBuf.FillZ(KRequestSenseCommandLength); |
|
388 |
||
389 |
TSenseInfo* senseInfo; |
|
0 | 390 |
#ifdef MSDC_MULTITHREADED |
286 | 391 |
if (!iDeferredSenseInfo.SenseOk()) |
392 |
{ |
|
393 |
writeBuf[00] = 0x71; //(deferred errors) |
|
394 |
senseInfo = &iDeferredSenseInfo; |
|
395 |
} |
|
396 |
else |
|
397 |
{ |
|
398 |
writeBuf[00] = 0x70; //(current errors) |
|
399 |
senseInfo = &iSenseInfo; |
|
400 |
} |
|
0 | 401 |
#else |
286 | 402 |
senseInfo = &iSenseInfo; |
403 |
writeBuf[00] = 0x70; //(current errors) |
|
0 | 404 |
#endif |
405 |
||
286 | 406 |
writeBuf[02] = static_cast<TUint8>(senseInfo->iSenseCode & 0x0F); |
0 | 407 |
|
286 | 408 |
writeBuf[12] = senseInfo->iAdditional; |
409 |
writeBuf[13] = senseInfo->iQualifier; |
|
410 |
if (length<18 && length >=8) |
|
411 |
{ |
|
412 |
writeBuf.SetLength(length); //length of response code data |
|
413 |
writeBuf[07] = TUint8(length - 8); //additional sence length |
|
414 |
} |
|
415 |
else if (length >= KRequestSenseCommandLength) |
|
416 |
{ |
|
417 |
writeBuf[07] = KRequestSenseCommandLength - 8; // we have max 18 byte to send |
|
418 |
} |
|
0 | 419 |
|
286 | 420 |
OstTraceExt4(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_REQUESTSENSE2, |
421 |
" Response=0x%x Sense=0x%x, Additional=0x%x, Qualifier=0x%x", |
|
422 |
(TUint)writeBuf[0], (TUint)writeBuf[02], (TUint)writeBuf[12], (TUint)writeBuf[13]); |
|
0 | 423 |
|
286 | 424 |
TPtrC8 writeBuf1 = writeBuf.Left(length); |
0 | 425 |
|
286 | 426 |
iTransport->SetupWriteData(writeBuf1); |
427 |
||
428 |
// clear the sense info |
|
429 |
iSenseInfo.SetSense(TSenseInfo::ENoSense); |
|
0 | 430 |
|
431 |
#ifdef MSDC_MULTITHREADED |
|
286 | 432 |
iDeferredSenseInfo.SetSense(TSenseInfo::ENoSense); |
0 | 433 |
#endif |
434 |
||
286 | 435 |
return ETrue; |
436 |
} |
|
0 | 437 |
|
438 |
||
439 |
/** |
|
440 |
Command Parser for the INQUIRY command (0x12) |
|
441 |
||
286 | 442 |
@param aLun Logic unit number |
443 |
@return ETrue if successful, |
|
0 | 444 |
*/ |
445 |
TBool CScsiProtocol::HandleInquiry(TPtrC8& aData, TUint aLun ) |
|
286 | 446 |
{ |
447 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_INQUIRY, ">>> INQUIRY"); |
|
448 |
TBool cmdDt = aData[2] & 0x2; |
|
449 |
TBool evpd = aData[2] & 0x1; |
|
450 |
TUint8 page = aData[3]; |
|
451 |
if (cmdDt || evpd || page || aLun >= KUsbMsMaxDrives) |
|
452 |
{ |
|
453 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::EInvalidFieldInCdb); |
|
454 |
return EFalse; |
|
455 |
} |
|
0 | 456 |
|
286 | 457 |
TPtr8 writeBuf(NULL, 0); |
458 |
iTransport->GetCommandBufPtr(writeBuf, KInquiryCommandLength); |
|
459 |
writeBuf.FillZ(KInquiryCommandLength); |
|
0 | 460 |
|
286 | 461 |
writeBuf[1] = 0x80; // MSB: RMB : Removable |
462 |
writeBuf[3] = 0x02; // AERC, TrmTsk, NormACA, Response Data Format |
|
463 |
writeBuf[4] = 0x1F; // Additional Length |
|
0 | 464 |
|
286 | 465 |
TPtr8 vendorId(&writeBuf[8], 8, 8); // Vendor ID (Vendor Specific/Logged by T10) |
466 |
vendorId.Fill(' ', 8); |
|
467 |
vendorId.Copy(iConfig.iVendorId); |
|
0 | 468 |
|
286 | 469 |
TPtr8 productId(&writeBuf[16], 16, 16); // Product ID (Vendor Specific) |
470 |
productId.Fill(' ', 16); |
|
471 |
productId.Copy(iConfig.iProductId); |
|
0 | 472 |
|
286 | 473 |
TPtr8 productRev(&writeBuf[32], 4, 4); // Product Revision Level (Vendor Specific) |
474 |
productRev.Fill(' ', 4); |
|
475 |
productRev.Copy(iConfig.iProductRev); |
|
476 |
||
477 |
OstTraceData(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_INQUIRY1, "Vendor ID %s", vendorId.Ptr(), vendorId.Length()); |
|
478 |
OstTraceData(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_INQUIRY2, "Product ID %s", productId.Ptr(), productId.Length()); |
|
479 |
OstTraceData(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_INQUIRY3, "Product Rev %s", productRev.Ptr(), productRev.Length()); |
|
0 | 480 |
|
481 |
TUint length = aData[5]; |
|
482 |
||
286 | 483 |
TPtrC8 writeBuf1 = writeBuf.Left(length); |
484 |
iTransport->SetupWriteData(writeBuf1); |
|
0 | 485 |
|
286 | 486 |
iSenseInfo.SetSense(TSenseInfo::ENoSense); |
487 |
return ETrue; |
|
488 |
} |
|
0 | 489 |
|
490 |
||
491 |
/** |
|
492 |
Command Parser for the START STOP UNIT command (0x1B) |
|
286 | 493 |
|
0 | 494 |
@param aData command data (started form position 1) |
286 | 495 |
@param aLun Logic unit number |
0 | 496 |
@return ETrue if successful, TFalse otherwise |
497 |
*/ |
|
498 |
TBool CScsiProtocol::HandleStartStopUnit(TPtrC8& aData, TUint aLun) |
|
286 | 499 |
{ |
500 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_STARTSTOPUNIT, ">>> START STOP UNIT"); |
|
501 |
const TUint8 KStartMask = 0x01; |
|
502 |
const TUint8 KImmedMask = 0x01; |
|
503 |
const TUint8 KLoejMask = 0x02; |
|
0 | 504 |
|
286 | 505 |
TBool immed = aData[2] & KImmedMask ? (TBool)ETrue : (TBool)EFalse; |
506 |
TBool start = aData[5] & KStartMask ? (TBool)ETrue : (TBool)EFalse; |
|
507 |
TBool loej = aData[5] & KLoejMask ? (TBool)ETrue : (TBool)EFalse; |
|
0 | 508 |
|
286 | 509 |
OstTrace1(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_STARTSTOPUNIT1, " IMMED = %d", immed); |
510 |
OstTrace1(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_STARTSTOPUNIT2, " START = %d", start); |
|
511 |
OstTrace1(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_STARTSTOPUNIT3, " LOEJ = %d", loej); |
|
0 | 512 |
|
286 | 513 |
TInt err(KErrNone); |
514 |
if (loej) |
|
515 |
{ |
|
516 |
if(start) //Start unit |
|
517 |
{ |
|
518 |
err = iDriveManager.Connect(aLun); |
|
0 | 519 |
|
520 |
#ifdef USB_TRANSFER_PUBLISHER |
|
286 | 521 |
iBytesRead[aLun] = 0; |
522 |
iBytesWritten[aLun] = 0; |
|
0 | 523 |
#endif |
286 | 524 |
// publish the initial values |
525 |
iWriteTransferPublisher->DoPublishDataTransferredEvent(); |
|
526 |
iReadTransferPublisher->DoPublishDataTransferredEvent(); |
|
527 |
} |
|
528 |
else //Stop unit |
|
529 |
{ |
|
530 |
iDriveManager.SetCritical(aLun, EFalse); |
|
531 |
err = iDriveManager.Disconnect(aLun); |
|
532 |
} |
|
533 |
} |
|
0 | 534 |
|
286 | 535 |
if (err !=KErrNone) //actually we have error here only if the LUN is incorrect |
536 |
{ |
|
537 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::ELuNotSupported); |
|
538 |
return EFalse; |
|
539 |
} |
|
540 |
if (immed) |
|
541 |
{ |
|
542 |
return ETrue; |
|
543 |
} |
|
0 | 544 |
|
286 | 545 |
CMassStorageDrive* drive= iDriveManager.Drive(aLun, err); |
0 | 546 |
|
286 | 547 |
if (err !=KErrNone || drive == NULL) |
548 |
{ |
|
549 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::ELuNotSupported); |
|
550 |
return EFalse; |
|
551 |
} |
|
0 | 552 |
|
286 | 553 |
TInt timeLeft (20); // 1 sec timeout |
554 |
CMassStorageDrive::TMountState mountState; |
|
0 | 555 |
|
286 | 556 |
do |
557 |
{ |
|
558 |
User::After(1000 * 50); // 50 mSec |
|
559 |
--timeLeft; |
|
560 |
mountState = drive->MountState(); |
|
0 | 561 |
|
286 | 562 |
if ((!start && mountState != CMassStorageDrive::EConnected) |
563 |
|| |
|
564 |
(start && |
|
565 |
(mountState == CMassStorageDrive::EDisconnecting || |
|
566 |
mountState == CMassStorageDrive::EConnected)) |
|
567 |
) |
|
568 |
{ |
|
569 |
return ETrue; |
|
570 |
} |
|
571 |
} while (timeLeft>0); |
|
0 | 572 |
|
286 | 573 |
//timeout happend |
574 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, |
|
575 |
TSenseInfo::EAscLogicalUnitDoesNotRespondToSelection); |
|
576 |
return EFalse; |
|
577 |
} |
|
0 | 578 |
|
579 |
||
580 |
/** |
|
581 |
Command Parser for the PREVENT/ALLOW MEDIA REMOVAL command (0x1E) |
|
582 |
||
583 |
@param aData command data (started form position 1) |
|
286 | 584 |
@param aLun Logic unit number |
0 | 585 |
@return ETrue if successful. |
586 |
*/ |
|
587 |
TBool CScsiProtocol::HandlePreventMediaRemoval(TPtrC8& aData, TUint aLun) |
|
286 | 588 |
{ |
589 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_PREVENTMEDIAREMOVAL, ">>> PREVENT MEDIA REMOVAL"); |
|
590 |
CMassStorageDrive* drive=GetCheckDrive(aLun); |
|
0 | 591 |
|
286 | 592 |
if (drive == NULL) |
593 |
{ |
|
594 |
return EFalse; |
|
595 |
} |
|
0 | 596 |
|
286 | 597 |
TInt prevent = aData[5] & 0x01; |
598 |
OstTrace1(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_PREVENTMEDIAREMOVAL1, " prevent = %d", prevent); |
|
599 |
iDriveManager.SetCritical(aLun, prevent); |
|
600 |
return ETrue; |
|
601 |
} |
|
0 | 602 |
|
603 |
||
604 |
/** Cancel active state, Invoked by transnport when it stops */ |
|
605 |
TInt CScsiProtocol::Cancel() |
|
286 | 606 |
{ |
607 |
iDriveManager.SetCritical(CDriveManager::KAllLuns, EFalse); |
|
608 |
return KErrNone; |
|
609 |
} |
|
0 | 610 |
|
611 |
||
612 |
TBool CScsiProtocol::HandleReadFormatCapacities(TUint aLun) |
|
613 |
/** |
|
614 |
* Command Parser for the READ FORMAT CAPACITIES command (0x23) |
|
615 |
* |
|
616 |
* @return ETrue if successful, else a standard Symbian OS error code. |
|
617 |
*/ |
|
286 | 618 |
{ |
619 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_READFORMATCAPACITIES, ">>> READ FORMAT CAPACITIES"); |
|
620 |
CMassStorageDrive* drive=GetCheckDrive(aLun); |
|
0 | 621 |
|
286 | 622 |
if (drive == NULL) |
623 |
{ |
|
624 |
return EFalse; |
|
625 |
} |
|
0 | 626 |
|
286 | 627 |
TLocalDriveCapsV4 driveInfo; |
0 | 628 |
|
286 | 629 |
TInt err = drive->Caps(driveInfo); |
0 | 630 |
|
286 | 631 |
if(err != KErrNone) |
632 |
{ |
|
633 |
OstTrace1(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_HANDLEREADFORMATCAPACITIES, "Can't obtain drive Caps. Err=%d", err); |
|
634 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, TSenseInfo::EMediaNotPresent); |
|
635 |
return EFalse; |
|
636 |
} |
|
0 | 637 |
|
286 | 638 |
TInt64 driveBlocks = (driveInfo.iDriveAtt & KDriveAttLogicallyRemovable) ? driveInfo.iSize : driveInfo.MediaSizeInBytes(); |
639 |
driveBlocks /= MAKE_TINT64(0, KDefaultBlockSize); |
|
0 | 640 |
|
286 | 641 |
TPtr8 writeBuf(NULL, 0); |
642 |
iTransport->GetCommandBufPtr(writeBuf, KReadFormatCapacitiesCommandLength); |
|
643 |
writeBuf.FillZ(KReadFormatCapacitiesCommandLength); |
|
0 | 644 |
|
286 | 645 |
writeBuf[3] = 0x08; // Capacity List Length |
0 | 646 |
|
286 | 647 |
TUint32 numBlocks = I64LOW(driveBlocks); |
0 | 648 |
|
286 | 649 |
writeBuf[4] = static_cast<TUint8>((numBlocks & 0xFF000000) >> 24); // Number of blocks |
650 |
writeBuf[5] = static_cast<TUint8>((numBlocks & 0x00FF0000) >> 16); // |
|
651 |
writeBuf[6] = static_cast<TUint8>((numBlocks & 0x0000FF00) >> 8); // |
|
652 |
writeBuf[7] = static_cast<TUint8>((numBlocks & 0x000000FF)); // |
|
0 | 653 |
|
286 | 654 |
writeBuf[8] = 0x02; // Formatted size |
0 | 655 |
|
286 | 656 |
writeBuf[9] = 0x00; // 512 Byte Blocks |
657 |
writeBuf[10] = 0x02; // |
|
658 |
writeBuf[11] = 0x00; // |
|
0 | 659 |
|
286 | 660 |
TPtrC8 writeBuf1 = writeBuf; |
0 | 661 |
|
286 | 662 |
iTransport->SetupWriteData(writeBuf1); |
0 | 663 |
|
286 | 664 |
return ETrue; |
665 |
} |
|
0 | 666 |
|
667 |
||
668 |
/** |
|
669 |
Command Parser for the READ CAPACITY(10) command (0x25) |
|
670 |
||
671 |
@param aData command data (started form position 1) |
|
286 | 672 |
@param aLun Logic unit number |
0 | 673 |
@return ETrue if successful. |
674 |
*/ |
|
675 |
TBool CScsiProtocol::HandleReadCapacity(TPtrC8& aData, TUint aLun) |
|
286 | 676 |
{ |
677 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_READCAPACITY, ">>> READ CAPACITY"); |
|
678 |
CMassStorageDrive* drive=GetCheckDrive(aLun); |
|
0 | 679 |
|
286 | 680 |
if (drive == NULL) |
681 |
{ |
|
682 |
return EFalse; |
|
683 |
} |
|
0 | 684 |
|
286 | 685 |
TInt pmi = aData[9] & 0x01; |
686 |
TInt lba = aData[3] | aData[4] | aData[5] | aData[6]; |
|
0 | 687 |
|
286 | 688 |
if (pmi || lba) //do not support partial medium indicator |
689 |
{ |
|
690 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::EInvalidFieldInCdb); |
|
691 |
return EFalse; |
|
692 |
} |
|
0 | 693 |
|
286 | 694 |
TLocalDriveCapsV4 driveInfo; |
0 | 695 |
|
286 | 696 |
TInt err = drive->Caps(driveInfo); |
0 | 697 |
|
286 | 698 |
if(err != KErrNone) |
699 |
{ |
|
700 |
OstTrace1(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_HANDLEREADCAPACITY1, "ERROR: Can't obtain drive Caps Err=%d", err); |
|
701 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, TSenseInfo::EMediaNotPresent); |
|
702 |
return EFalse; |
|
703 |
} |
|
0 | 704 |
|
286 | 705 |
TInt64 driveBlocks = 0; |
706 |
if (driveInfo.iDriveAtt & KDriveAttLogicallyRemovable) |
|
707 |
{ |
|
708 |
// Partition Access only |
|
709 |
driveBlocks = driveInfo.iSize / MAKE_TINT64(0, KDefaultBlockSize); |
|
710 |
} |
|
711 |
else |
|
712 |
{ |
|
713 |
// whole Media Access |
|
714 |
driveBlocks = driveInfo.MediaSizeInBytes() / MAKE_TINT64(0, KDefaultBlockSize) - 1; |
|
715 |
} |
|
0 | 716 |
|
717 |
||
286 | 718 |
TPtr8 writeBuf(NULL, 0); |
719 |
iTransport->GetCommandBufPtr(writeBuf, KReadCapacityCommandLength); |
|
720 |
writeBuf.FillZ(KReadCapacityCommandLength); |
|
721 |
||
722 |
if (I64HIGH(driveBlocks) == 0) |
|
723 |
{ |
|
724 |
TUint32 numBlocks = I64LOW(driveBlocks); |
|
0 | 725 |
|
286 | 726 |
OstTraceExt2(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_HANDLEREADCAPACITY2, |
727 |
" Block size=0x%x, NumBlocks=0x%x", |
|
728 |
KDefaultBlockSize, numBlocks); |
|
729 |
writeBuf[0] = static_cast<TUint8>((numBlocks & 0xFF000000) >> 24); // Number of blocks |
|
730 |
writeBuf[1] = static_cast<TUint8>((numBlocks & 0x00FF0000) >> 16); |
|
731 |
writeBuf[2] = static_cast<TUint8>((numBlocks & 0x0000FF00) >> 8); |
|
732 |
writeBuf[3] = static_cast<TUint8>((numBlocks & 0x000000FF)); |
|
733 |
} |
|
734 |
else |
|
735 |
{ |
|
736 |
writeBuf[0] = writeBuf[1] = writeBuf[2] = writeBuf[3] = 0xFF; // indicate that size more then )0xFFFFFFFF |
|
737 |
} |
|
0 | 738 |
|
286 | 739 |
writeBuf[4] = static_cast<TUint8>((KDefaultBlockSize & 0xFF000000) >> 24); // Block Size |
740 |
writeBuf[5] = static_cast<TUint8>((KDefaultBlockSize & 0x00FF0000) >> 16); |
|
741 |
writeBuf[6] = static_cast<TUint8>((KDefaultBlockSize & 0x0000FF00) >> 8); |
|
742 |
writeBuf[7] = static_cast<TUint8>((KDefaultBlockSize & 0x000000FF)); |
|
0 | 743 |
|
286 | 744 |
TPtrC8 writeBuf1 = writeBuf; |
745 |
iTransport->SetupWriteData(writeBuf1); |
|
0 | 746 |
|
286 | 747 |
return KErrNone; |
748 |
} |
|
0 | 749 |
|
750 |
||
751 |
/** |
|
752 |
Command Parser for the READ10 command (0x28) |
|
753 |
||
754 |
@param aData command data (started form position 1) |
|
755 |
@param aLun Logic unit number |
|
756 |
@return ETrue if successful. |
|
757 |
*/ |
|
758 |
TBool CScsiProtocol::HandleRead10(TPtrC8& aData, TUint aLun) |
|
286 | 759 |
{ |
760 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_READ10, ">>> READ(10)"); |
|
761 |
CMassStorageDrive* drive = GetCheckDrive(aLun); |
|
762 |
if (drive == NULL) |
|
763 |
{ |
|
764 |
return EFalse; |
|
765 |
} |
|
766 |
TInt rdProtect = aData[2] >> 5; |
|
767 |
if (rdProtect) |
|
768 |
{ |
|
769 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::EInvalidFieldInCdb); |
|
770 |
return EFalse; |
|
771 |
} |
|
0 | 772 |
|
286 | 773 |
const TUint32 lba = LBA(aData); |
774 |
const TUint32 len = LEN(aData); |
|
0 | 775 |
|
286 | 776 |
OstTraceExt2(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_HANDLEREAD10_1, |
777 |
" LBA = 0x%x Transfer Len = 0x%x", lba, len); |
|
0 | 778 |
|
286 | 779 |
if (!len) |
780 |
{ |
|
781 |
return ETrue; // do nothing - this is not an error |
|
782 |
} |
|
0 | 783 |
|
286 | 784 |
TLocalDriveCapsV4 driveInfo; |
785 |
TInt err = drive->Caps(driveInfo); |
|
786 |
if (err != KErrNone) |
|
787 |
{ |
|
788 |
OstTrace1(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_HANDLEREAD10_2, "Can't obtain drive Caps. Err=%d", err); |
|
789 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, TSenseInfo::EMediaNotPresent); |
|
790 |
return EFalse; |
|
791 |
} |
|
0 | 792 |
|
286 | 793 |
const TInt64 bOffset = MAKE_TINT64(0, lba) * KDefaultBlockSize; |
794 |
const TInt bLength = len * KDefaultBlockSize; |
|
795 |
const TInt64 theEnd = bOffset + MAKE_TINT64(0, bLength); |
|
796 |
const TInt64 mediaSize = (driveInfo.iDriveAtt & KDriveAttLogicallyRemovable) ? driveInfo.iSize : driveInfo.MediaSizeInBytes() ; |
|
797 |
||
798 |
if (theEnd > mediaSize) //check if media big enough for this request |
|
799 |
{ |
|
800 |
OstTrace0(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_HANDLEREAD10_3, "ERROR: Requested size is out of media range"); |
|
801 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::ELbaOutOfRange); |
|
802 |
return EFalse; |
|
803 |
} |
|
0 | 804 |
|
805 |
#ifdef MSDC_MULTITHREADED |
|
286 | 806 |
iWriteDriveThread->WaitForWriteEmpty(); |
0 | 807 |
|
286 | 808 |
// check if our buffer can hold requested data |
809 |
if (iReadDriveThread->iThreadContext->MaxBufferLength() < bLength) |
|
810 |
{ |
|
811 |
OstTrace0(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_HANDLEREAD10_4, "ERROR: Buffer too small"); |
|
812 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::EInvalidFieldInCdb); |
|
813 |
return EFalse; |
|
814 |
} |
|
0 | 815 |
|
816 |
// Optimisation note : If the host is reading from sectors it just wrote to, |
|
817 |
// then we have to force a cache-miss so that the real data is read from the |
|
286 | 818 |
// drive. It would be possible to service the read from the write buffers, |
819 |
// but as the host is probably trying to verify the write data, we don't do |
|
820 |
// that for now. |
|
821 |
if (!iReadDriveThread->ReadDriveData(drive, bOffset, bLength, iWriteDriveThread->IsRecentlyWritten(bOffset,bLength))) |
|
822 |
{ |
|
823 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, TSenseInfo::EMediaNotPresent); |
|
824 |
return EFalse; |
|
825 |
} |
|
0 | 826 |
|
286 | 827 |
iWriteDriveThread->SetCommandWrite10(EFalse); |
828 |
TBlockDesc* &desc = iReadDriveThread->iThreadContext->iBuffer.iDescReadPtr; |
|
829 |
TPtrC8 writeBuf1 = desc->iBuf; |
|
0 | 830 |
#else |
286 | 831 |
|
832 |
TPtr8 writeBuf(NULL, 0); |
|
833 |
iTransport->GetReadDataBufPtr(writeBuf); |
|
834 |
// check if our buffer can hold requested data |
|
835 |
if (writeBuf.MaxLength() < bLength) |
|
836 |
{ |
|
837 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::EInvalidFieldInCdb); |
|
838 |
return EFalse; |
|
839 |
} |
|
0 | 840 |
|
286 | 841 |
err = drive->Read(bOffset, bLength, writeBuf, drive->IsWholeMediaAccess()); |
0 | 842 |
|
286 | 843 |
if (err != KErrNone) |
844 |
{ |
|
845 |
OstTrace1(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_HANDLEREAD10_5, "ERROR: Read failed err=%d", err); |
|
846 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, TSenseInfo::EMediaNotPresent); |
|
847 |
return EFalse; |
|
848 |
} |
|
0 | 849 |
|
286 | 850 |
TPtrC8 writeBuf1 = writeBuf; |
0 | 851 |
#endif // MSDC_MULTITHREADED |
852 |
#ifdef USB_TRANSFER_PUBLISHER |
|
286 | 853 |
iBytesRead[aLun] += writeBuf1.Length(); |
0 | 854 |
#endif |
286 | 855 |
iReadTransferPublisher->StartTimer(); |
0 | 856 |
|
286 | 857 |
// Set up data write to the host |
858 |
iTransport->SetupWriteData(writeBuf1); |
|
0 | 859 |
|
286 | 860 |
return ETrue; |
861 |
} |
|
0 | 862 |
|
863 |
||
864 |
/** |
|
865 |
Command Parser for the WRITE(10) command (0x2A) |
|
866 |
||
867 |
@param aData command data (started form position 1) |
|
868 |
@param aLun Logic unit number |
|
869 |
@return ETrue if successful. |
|
870 |
*/ |
|
871 |
TBool CScsiProtocol::HandleWrite10(TPtrC8& aData, TUint aLun) |
|
286 | 872 |
{ |
873 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_WRITE10, ">>> WRITE(10)"); |
|
874 |
CMassStorageDrive* drive = GetCheckDrive(aLun); |
|
875 |
if (drive == NULL) |
|
876 |
{ |
|
877 |
return EFalse; |
|
878 |
} |
|
879 |
TInt wrProtect = aData[2] >> 5; |
|
880 |
if (wrProtect) |
|
881 |
{ |
|
882 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::EInvalidFieldInCdb); |
|
883 |
return EFalse; |
|
884 |
} |
|
0 | 885 |
|
286 | 886 |
const TUint32 lba = LBA(aData); |
887 |
const TUint32 len = LEN(aData); |
|
888 |
OstTraceExt2(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_HANDLEWRITE10_1, "LBA = 0x%x, Transfer Len = 0x%x", lba, len); |
|
889 |
if (!len) |
|
890 |
{ |
|
891 |
return ETrue; // do nothing - this is not an error |
|
892 |
} |
|
0 | 893 |
|
286 | 894 |
TLocalDriveCapsV4 driveInfo; |
895 |
TInt err = drive->Caps(driveInfo); |
|
896 |
if (err != KErrNone) |
|
897 |
{ |
|
898 |
OstTrace1(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_WRITE10_2, "ERROR: Can't obtain drive Caps Err=%d", err); |
|
899 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, TSenseInfo::EMediaNotPresent); |
|
900 |
return EFalse; |
|
901 |
} |
|
902 |
if (driveInfo.iMediaAtt & KMediaAttWriteProtected || |
|
903 |
driveInfo.iMediaAtt & KMediaAttLocked) |
|
904 |
{ |
|
905 |
iSenseInfo.SetSense(TSenseInfo::EDataProtection, TSenseInfo::EWriteProtected); |
|
906 |
return EFalse; |
|
907 |
} |
|
0 | 908 |
|
286 | 909 |
const TInt64 bOffset = MAKE_TINT64(0, lba) * KDefaultBlockSize; |
910 |
iBytesRemain = len * KDefaultBlockSize; |
|
911 |
const TInt64 theEnd = bOffset + MAKE_TINT64(0, iBytesRemain); |
|
912 |
const TInt64 mediaSize = (driveInfo.iDriveAtt & KDriveAttLogicallyRemovable) ? driveInfo.iSize : driveInfo.MediaSizeInBytes() ; |
|
0 | 913 |
|
286 | 914 |
if (theEnd > mediaSize) //check if media big enough for this request |
915 |
{ |
|
916 |
OstTrace0(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_HANDLEWRITE10_3, "Requested size is out of media range"); |
|
917 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::ELbaOutOfRange); |
|
918 |
return EFalse; |
|
919 |
} |
|
0 | 920 |
|
921 |
#ifdef MSDC_MULTITHREADED |
|
286 | 922 |
iWriteDriveThread->SetCommandWrite10(ETrue); |
0 | 923 |
#endif |
924 |
||
286 | 925 |
// Set up the first request for data from the host - either |
926 |
// KMaxBufSize or the entire transfer length, whichever is smallest. |
|
927 |
TUint thisLength = (iBytesRemain > KMaxBufSize) ? KMaxBufSize : iBytesRemain; |
|
928 |
thisLength = (thisLength > iMediaWriteSize) ? iMediaWriteSize : thisLength; |
|
0 | 929 |
|
286 | 930 |
iOffset = bOffset; |
931 |
iLastCommand = EWrite10; |
|
932 |
iLastLun = aLun; |
|
0 | 933 |
|
286 | 934 |
iWriteTransferPublisher->StartTimer(); |
935 |
iTransport->SetupReadData(thisLength); |
|
0 | 936 |
|
286 | 937 |
return ETrue; |
938 |
} |
|
0 | 939 |
|
940 |
||
941 |
/** |
|
942 |
Command Parser for the VERIFY(10) command (0x2F) |
|
943 |
||
944 |
@param aData command data (started form position 1) |
|
945 |
@param aLun Logic unit number |
|
946 |
@return ETrue if successful. |
|
947 |
*/ |
|
948 |
TBool CScsiProtocol::HandleVerify10(TPtrC8& aData, TUint aLun) |
|
286 | 949 |
{ |
950 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_VERIFY10, ">>> VERIFY(10)"); |
|
951 |
CMassStorageDrive* drive = GetCheckDrive(aLun); |
|
952 |
if (drive == NULL) |
|
953 |
{ |
|
954 |
return EFalse; |
|
955 |
} |
|
0 | 956 |
|
286 | 957 |
TInt vrProtect = aData[2] >> 5; |
958 |
if (vrProtect) |
|
959 |
{ |
|
960 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::EInvalidFieldInCdb); |
|
961 |
return EFalse; |
|
962 |
} |
|
0 | 963 |
|
286 | 964 |
const TUint32 lba = LBA(aData); |
965 |
const TUint32 len = LEN(aData); |
|
966 |
OstTraceExt2(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_VERIFY10_1, "VERIFY(10) : LBA = 0x%x Transfer Len = 0x%x", lba, len); |
|
0 | 967 |
|
286 | 968 |
TInt bytChk = aData[2] & 0x02; |
969 |
if (!len) |
|
970 |
{ |
|
971 |
return ETrue; // do nothing - this is not an error |
|
972 |
} |
|
0 | 973 |
|
286 | 974 |
TLocalDriveCapsV4 driveInfo; |
975 |
TInt err = drive->Caps(driveInfo); |
|
976 |
if (err != KErrNone) |
|
977 |
{ |
|
978 |
OstTrace1(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_VERIFY10_2, "ERROR: Can't obtain drive Caps Err=%d", err); |
|
979 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, TSenseInfo::EMediaNotPresent); |
|
980 |
return EFalse; |
|
981 |
} |
|
0 | 982 |
|
286 | 983 |
const TInt64 bOffset = MAKE_TINT64(0, lba) * KDefaultBlockSize; |
984 |
const TInt bLength = len * KDefaultBlockSize; |
|
985 |
const TInt64 theEnd = bOffset + MAKE_TINT64(0, bLength); |
|
986 |
const TInt64 mediaSize = (driveInfo.iDriveAtt & KDriveAttLogicallyRemovable) ? driveInfo.iSize : driveInfo.MediaSizeInBytes() ; |
|
0 | 987 |
|
286 | 988 |
// check if media big enough for this request |
989 |
if (theEnd > mediaSize) |
|
990 |
{ |
|
991 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::ELbaOutOfRange); |
|
992 |
return EFalse; |
|
993 |
} |
|
0 | 994 |
|
286 | 995 |
// check if our buffer can hold requested data |
0 | 996 |
#ifdef MSDC_MULTITHREADED |
286 | 997 |
if (iWriteDriveThread->iThreadContext->MaxBufferLength() < bLength) |
0 | 998 |
#else |
286 | 999 |
TPtr8 writeBuf(NULL, 0); |
1000 |
iTransport->GetReadDataBufPtr(writeBuf); |
|
1001 |
if (writeBuf.MaxLength() < bLength) |
|
0 | 1002 |
#endif |
286 | 1003 |
{ |
1004 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest, TSenseInfo::EInvalidFieldInCdb); |
|
1005 |
return EFalse; |
|
1006 |
} |
|
0 | 1007 |
|
286 | 1008 |
if (!bytChk) |
1009 |
{ |
|
1010 |
// BYTCHK==0 : Perform a medium verification with no data comparison and not transfer any data from the application client data-out buffer. |
|
1011 |
// The device should attempt to read from the specified locations |
|
0 | 1012 |
#ifdef MSDC_MULTITHREADED |
286 | 1013 |
TPtr8 writeBuf = iWriteDriveThread->iThreadContext->GetReadBuffer(bLength); |
0 | 1014 |
#else |
286 | 1015 |
writeBuf.SetLength(bLength); |
0 | 1016 |
#endif |
286 | 1017 |
err = drive->Read(bOffset, bLength, writeBuf, drive->IsWholeMediaAccess()); |
1018 |
if (err != KErrNone) |
|
1019 |
{ |
|
1020 |
iSenseInfo.SetSense(TSenseInfo::EMisCompare); |
|
1021 |
return EFalse; |
|
1022 |
} |
|
1023 |
return ETrue; |
|
1024 |
} |
|
0 | 1025 |
|
286 | 1026 |
// BYTCHK==1 : perform a byte-by-byte comparison of user data read from the medium & user data transferred from the application client data-out buffer. |
1027 |
// The host sends data in the data-transport phase, and the device should verify that the received data matches what is stored in the device. |
|
0 | 1028 |
|
286 | 1029 |
iOffset = bOffset; |
1030 |
iLastCommand = EVerify10; |
|
1031 |
iLastLun = aLun; |
|
0 | 1032 |
|
286 | 1033 |
iTransport->SetupReadData(bLength); |
0 | 1034 |
|
286 | 1035 |
return ETrue; |
1036 |
} |
|
0 | 1037 |
|
1038 |
||
1039 |
/** |
|
1040 |
Called by the transport when the requested data has been read or an error has |
|
1041 |
occurred during the read. |
|
1042 |
||
1043 |
@param aError Indicate if an error occurs during reading data by transport. |
|
1044 |
@return KErrAbort if command processing is complete but has failed, |
|
1045 |
KErrCompletion if sufficient data is available in the buffer to process |
|
1046 |
the transfer immediately, KErrNotReady if insufficient data is |
|
1047 |
available in the buffer so the transport should wait for it to arrive, |
|
1048 |
KErrNone if command processing is complete and was successful. |
|
1049 |
*/ |
|
1050 |
TInt CScsiProtocol::ReadComplete(TInt aError) |
|
286 | 1051 |
{ |
1052 |
OstTrace1(TRACE_SMASSSTORAGE_MEDIA, CSCSIPROTOCOL_READCOMPLETE0, "ReadComplete = 0x%X", aError); |
|
1053 |
const TInt64 bOffset = iOffset; |
|
1054 |
TUint8 lastCommand = iLastCommand; |
|
1055 |
TUint lastLun = iLastLun; |
|
0 | 1056 |
|
286 | 1057 |
iOffset = 0; |
1058 |
iLastCommand = EUndefinedCommand; |
|
1059 |
iLastLun = KUndefinedLun; |
|
0 | 1060 |
|
286 | 1061 |
// OstTrace1(TRACE_SMASSSTORAGE_MEDIA, CSCSIPROTOCOL_READCOMPLETE1, "lastCommand = d", lastCommand); |
0 | 1062 |
|
286 | 1063 |
if (aError != KErrNone || |
1064 |
lastCommand == EUndefinedCommand || |
|
1065 |
lastLun == KUndefinedLun) |
|
1066 |
{ |
|
1067 |
iSenseInfo.SetSense(TSenseInfo::EAbortedCommand); |
|
1068 |
return KErrAbort; |
|
1069 |
} |
|
0 | 1070 |
|
286 | 1071 |
CMassStorageDrive* drive = GetCheckDrive(lastLun); |
1072 |
if (drive == NULL) |
|
1073 |
{ |
|
1074 |
return KErrAbort; |
|
1075 |
} |
|
0 | 1076 |
|
286 | 1077 |
if (lastCommand == EWrite10) |
1078 |
{ |
|
1079 |
TPtrC8 writeBuf(NULL, 0); |
|
1080 |
iTransport->GetWriteDataBufPtr(writeBuf); |
|
1081 |
||
0 | 1082 |
#ifdef USB_TRANSFER_PUBLISHER |
286 | 1083 |
iBytesWritten[lastLun] += writeBuf.Length(); |
0 | 1084 |
#endif |
1085 |
||
1086 |
#ifdef MSDC_MULTITHREADED |
|
286 | 1087 |
TInt err = iWriteDriveThread->WriteDriveData(drive, bOffset, writeBuf, ProcessWriteComplete, this); |
1088 |
||
1089 |
if (err != KErrNone) |
|
1090 |
{ |
|
1091 |
iDeferredSenseInfo.SetSense(TSenseInfo::EMediumError); |
|
1092 |
} |
|
0 | 1093 |
|
286 | 1094 |
TUint thisLength = iWriteDriveThread->WriteBufferLength(); |
1095 |
#else |
|
1096 |
OstTrace1(TRACE_SMASSSTORAGE_MEDIA, CSCSIPROTOCOL_READCOMPLETE2, "SCSI: writing 0x%x bytes", writeBuf.Length()); |
|
1097 |
TInt err = drive->Write(bOffset, writeBuf, drive->IsWholeMediaAccess()); |
|
1098 |
if (err != KErrNone) |
|
1099 |
{ |
|
1100 |
OstTrace1(TRACE_SMASSSTORAGE_MEDIA, CSCSIPROTOCOL_READCOMPLETE3, "Error after write = 0x%x", err); |
|
1101 |
iSenseInfo.SetSense(TSenseInfo::EAbortedCommand); |
|
1102 |
return KErrAbort; |
|
1103 |
} |
|
0 | 1104 |
|
286 | 1105 |
TUint thisLength = writeBuf.Length(); |
1106 |
#endif // MSDC_MULTITHREADED |
|
1107 |
iOffset = bOffset + MAKE_TINT64(0, thisLength); |
|
1108 |
iBytesRemain -= thisLength; |
|
1109 |
if ((TInt)iBytesRemain > 0) |
|
1110 |
{ |
|
1111 |
// More data is expected - set up another request to read from the host |
|
1112 |
iLastCommand = EWrite10; |
|
1113 |
iLastLun = lastLun; |
|
1114 |
||
1115 |
TUint minLength = (iBytesRemain < iMediaWriteSize) ? iBytesRemain : iMediaWriteSize; |
|
1116 |
TUint bytesAvail = iTransport->BytesAvailable() & ~(KDefaultBlockSize-1); |
|
1117 |
||
1118 |
TBool wait = EFalse; |
|
1119 |
thisLength = bytesAvail ? bytesAvail : minLength; |
|
1120 |
if (thisLength < minLength) |
|
1121 |
{ |
|
1122 |
// Not enough data is available at the transport to satisfy the request, |
|
1123 |
// so return KErrNotReady to indicate that the transport should wait. |
|
1124 |
thisLength = minLength; |
|
1125 |
wait = ETrue; |
|
1126 |
} |
|
0 | 1127 |
|
286 | 1128 |
thisLength = (thisLength > KMaxBufSize) ? KMaxBufSize : thisLength; |
1129 |
||
1130 |
iTransport->SetupReadData(thisLength); |
|
0 | 1131 |
|
286 | 1132 |
return wait ? KErrNotReady : KErrCompletion; |
1133 |
} |
|
1134 |
} |
|
1135 |
else if (lastCommand == EVerify10) |
|
1136 |
{ |
|
1137 |
HBufC8* hostData = NULL; |
|
1138 |
TPtrC8 writeBuf(NULL, 0); |
|
1139 |
iTransport->GetWriteDataBufPtr(writeBuf); |
|
1140 |
#ifdef MSDC_MULTITHREADED |
|
1141 |
TRAPD(err, hostData = HBufC8::NewL(writeBuf.Length())); |
|
1142 |
#else |
|
1143 |
TRAPD(err, hostData = HBufC8::NewL(writeBuf.Length())); |
|
0 | 1144 |
#endif |
286 | 1145 |
if (err != KErrNone || hostData == NULL) |
1146 |
{ |
|
1147 |
iSenseInfo.SetSense(TSenseInfo::EAbortedCommand, TSenseInfo::EInsufficientRes); |
|
1148 |
return KErrAbort; |
|
1149 |
} |
|
0 | 1150 |
|
286 | 1151 |
#ifdef MSDC_MULTITHREADED |
1152 |
// copy the data |
|
1153 |
*hostData = writeBuf; |
|
1154 |
TPtr8 readBuf = iWriteDriveThread->iThreadContext->GetReadBuffer(); |
|
1155 |
err = drive->Read(bOffset, writeBuf.Length(), readBuf, drive->IsWholeMediaAccess()); |
|
1156 |
if (err == KErrNone) |
|
1157 |
{ |
|
1158 |
err = (hostData->Compare(readBuf) == 0) ? KErrNone : KErrCorrupt; |
|
1159 |
} |
|
1160 |
#else |
|
1161 |
*hostData = writeBuf; |
|
1162 |
TPtr8 readBuf((TUint8*) writeBuf.Ptr(), writeBuf.Length()); |
|
1163 |
err = drive->Read(bOffset, writeBuf.Length(), readBuf, drive->IsWholeMediaAccess()); |
|
1164 |
if (err == KErrNone) |
|
1165 |
{ |
|
1166 |
err = (hostData->Compare(readBuf) == 0) ? KErrNone : KErrCorrupt; |
|
1167 |
} |
|
0 | 1168 |
#endif |
1169 |
||
286 | 1170 |
if (err != KErrNone) |
1171 |
{ |
|
1172 |
iSenseInfo.SetSense(TSenseInfo::EMisCompare); |
|
1173 |
} |
|
0 | 1174 |
|
286 | 1175 |
delete hostData; |
1176 |
} |
|
1177 |
else // unknown command |
|
1178 |
{ |
|
1179 |
iSenseInfo.SetSense(TSenseInfo::EAbortedCommand); |
|
1180 |
} |
|
1181 |
return iSenseInfo.SenseOk() ? KErrNone : KErrAbort; |
|
1182 |
} |
|
0 | 1183 |
|
1184 |
||
1185 |
/** |
|
1186 |
Command Parser for the MODE SENSE(06) command (0x1A) |
|
1187 |
||
1188 |
@return ETrue if successful. |
|
1189 |
*/ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1190 |
TBool CScsiProtocol::HandleModeSense6(TPtrC8& aData, TUint aLun) |
286 | 1191 |
{ |
1192 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_MODESENSE6, ">>> MODESENSE(06)"); |
|
1193 |
TInt pageCode = aData[3] & 0x3F; |
|
1194 |
TUint8 pageControl= static_cast<TUint8>(aData[3] >>6); |
|
0 | 1195 |
|
286 | 1196 |
if (pageCode != KAllPages || pageControl == KChangeableValues) |
1197 |
{ |
|
1198 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest,TSenseInfo::EInvalidFieldInCdb); |
|
1199 |
return EFalse; |
|
1200 |
} |
|
0 | 1201 |
|
286 | 1202 |
// reserve 4 bytes for Length, Media type, Device-specific parameter and Block descriptor length |
1203 |
TPtr8 writeBuf(NULL, 0); |
|
1204 |
iTransport->GetCommandBufPtr(writeBuf, KModeSense6CommandLength); |
|
1205 |
writeBuf.FillZ(KModeSense6CommandLength); |
|
0 | 1206 |
|
286 | 1207 |
if (pageControl != KDefaultValues) |
1208 |
{ |
|
1209 |
//check if drive write protected |
|
1210 |
CMassStorageDrive* drive=GetCheckDrive(aLun); |
|
1211 |
if (drive == NULL) |
|
1212 |
{ |
|
1213 |
OstTrace0(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_HANDLEMODESENSE6_1, "drive == null"); |
|
1214 |
return EFalse; |
|
1215 |
} |
|
0 | 1216 |
|
286 | 1217 |
TLocalDriveCapsV4 driveInfo; |
1218 |
TInt err = drive->Caps(driveInfo); |
|
1219 |
if (err != KErrNone) |
|
1220 |
{ |
|
1221 |
OstTrace1(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_MODESENSE6_2, "ERROR: Can't obtain drive Caps Err=%d", err); |
|
1222 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, TSenseInfo::EMediaNotPresent); |
|
1223 |
return EFalse ; |
|
1224 |
} |
|
0 | 1225 |
|
286 | 1226 |
if (driveInfo.iMediaAtt & KMediaAttWriteProtected) |
1227 |
{ |
|
1228 |
writeBuf[2] = 1<<7; // set SWP bit at the Device Specific parameters |
|
1229 |
} |
|
1230 |
} |
|
0 | 1231 |
|
286 | 1232 |
writeBuf[0]=3; //Sending only Mode parameter header |
0 | 1233 |
|
286 | 1234 |
TPtrC8 writeBuf1 = writeBuf; |
0 | 1235 |
|
286 | 1236 |
iTransport->SetupWriteData(writeBuf1); |
0 | 1237 |
|
286 | 1238 |
return (iSenseInfo.SenseOk()); |
1239 |
} |
|
0 | 1240 |
|
1241 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1242 |
/** |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1243 |
Command Parser for the MODE SENSE(10) command (0x5A) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1244 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1245 |
@return ETrue if successful. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1246 |
*/ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1247 |
TBool CScsiProtocol::HandleModeSense10(TPtrC8& aData, TUint aLun) |
286 | 1248 |
{ |
1249 |
OstTrace0(TRACE_SMASSSTORAGE_SCSI, CSCSIPROTOCOL_MODESENSE10, ">>> MODESENSE(10)"); |
|
1250 |
TInt pageCode = aData[3] & 0x3F; |
|
1251 |
TUint8 pageControl= static_cast<TUint8>(aData[3] >>6); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1252 |
|
286 | 1253 |
if (pageCode != KAllPages || pageControl == KChangeableValues) |
1254 |
{ |
|
1255 |
iSenseInfo.SetSense(TSenseInfo::EIllegalRequest,TSenseInfo::EInvalidFieldInCdb); |
|
1256 |
return EFalse; |
|
1257 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1258 |
|
286 | 1259 |
// reserve 8 bytes for Length, Media type, Device-specific parameter and Block descriptor length |
1260 |
TPtr8 writeBuf(NULL, 0); |
|
1261 |
iTransport->GetCommandBufPtr(writeBuf, KModeSense10CommandLength); |
|
1262 |
writeBuf.FillZ(KModeSense10CommandLength); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1263 |
|
286 | 1264 |
if (pageControl != KDefaultValues) |
1265 |
{ |
|
1266 |
//check if drive write protected |
|
1267 |
CMassStorageDrive* drive=GetCheckDrive(aLun); |
|
1268 |
if (drive == NULL) |
|
1269 |
{ |
|
1270 |
OstTrace0(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_HANDLEMODESENSE10_1, "drive == null"); |
|
1271 |
return EFalse; |
|
1272 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1273 |
|
286 | 1274 |
TLocalDriveCapsV4 driveInfo; |
1275 |
TInt err = drive->Caps(driveInfo); |
|
1276 |
if (err != KErrNone) |
|
1277 |
{ |
|
1278 |
OstTrace1(TRACE_SMASSSTORAGE, CSCSIPROTOCOL_MODESENSE10_1, "ERROR: Can't obtain drive Caps Err=%d", err); |
|
1279 |
iSenseInfo.SetSense(TSenseInfo::ENotReady, TSenseInfo::EMediaNotPresent); |
|
1280 |
return EFalse ; |
|
1281 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1282 |
|
286 | 1283 |
if (driveInfo.iMediaAtt & KMediaAttWriteProtected) |
1284 |
{ |
|
1285 |
writeBuf[3] = 1<<7; // set SWP bit at the Device Specific parameters |
|
1286 |
} |
|
1287 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1288 |
|
286 | 1289 |
writeBuf[1]=6; //Sending only Mode parameter header |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1290 |
|
286 | 1291 |
TPtrC8 writeBuf1 = writeBuf; |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1292 |
|
286 | 1293 |
iTransport->SetupWriteData(writeBuf1); |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1294 |
|
286 | 1295 |
return (iSenseInfo.SenseOk()); |
1296 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1297 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1298 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1299 |