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