os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/server/protocol/cmassstoragefsm.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/server/protocol/cmassstoragefsm.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1187 @@
1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +/**
1.20 + @file
1.21 + @internalTechnology
1.22 +*/
1.23 +
1.24 +#include <e32base.h>
1.25 +
1.26 +#include "usbmshostpanic.h"
1.27 +#include "debug.h"
1.28 +#include "msdebug.h"
1.29 +
1.30 +#include "msctypes.h"
1.31 +#include "mprotocol.h"
1.32 +#include "mblocktransferprotocol.h"
1.33 +#include "tspcclientinterface.h"
1.34 +#include "cscsiprotocol.h"
1.35 +#include "cmassstoragefsm.h"
1.36 +
1.37 +
1.38 +/**
1.39 +Constructor
1.40 +
1.41 +@param aScsiProtocol A reference to CScsiProtocol
1.42 +*/
1.43 +TMassStorage::TMassStorage(CScsiProtocol& aScsiProtocol)
1.44 +: iScsiProtocol(aScsiProtocol)
1.45 + {
1.46 + __MSFNLOG
1.47 + }
1.48 +
1.49 +
1.50 +/**
1.51 +Clear StatusCheck flag. Periodic status checking is used for removable media.
1.52 +*/
1.53 +void CMassStorageFsm::ClearStatusCheck()
1.54 +{
1.55 + __MSFNLOG
1.56 + iStatusCheck = EFalse;
1.57 +}
1.58 +
1.59 +
1.60 +/**
1.61 +Set StatusCheck flag. Periodic status checking is used for removable media.
1.62 +*/
1.63 +void CMassStorageFsm::SetStatusCheck()
1.64 +{
1.65 + __MSFNLOG
1.66 + iStatusCheck = ETrue;
1.67 +}
1.68 +
1.69 +
1.70 +/**
1.71 +Get the boolean state of StatusCheck flag.
1.72 +
1.73 +@return TBool ETrue if StatusCheck flag is set
1.74 +*/
1.75 +TBool CMassStorageFsm::IsStatusCheck() const
1.76 +{
1.77 + __MSFNSLOG
1.78 + return iStatusCheck;
1.79 +}
1.80 +
1.81 +
1.82 +/**
1.83 +Device supports SCSI BLOCK COMMANDS.
1.84 +
1.85 +@return TBool Returns ETrue if the SBC interface is initialised
1.86 +*/
1.87 +TBool TMassStorage::IsSbcSet() const
1.88 + {
1.89 + __MSFNSLOG
1.90 + return iScsiProtocol.MsIsSbcSet();
1.91 + }
1.92 +
1.93 +/**
1.94 +Device is removable media
1.95 +
1.96 +@return TBool Returns ETrue if removable
1.97 +*/
1.98 +TBool TMassStorage::IsRemovableMedia() const
1.99 + {
1.100 + __MSFNSLOG
1.101 + return iScsiProtocol.MsIsRemovableMedia();
1.102 + }
1.103 +
1.104 +/**
1.105 +Retrieve the sense info returned by a call to SenseL
1.106 +
1.107 +@return const TSenseInfo& Returns the SCSI SENSE info
1.108 +*/
1.109 +const TSenseInfo& TMassStorage::MsSenseInfo() const
1.110 + {
1.111 + __MSFNSLOG
1.112 + return iScsiProtocol.MsSenseInfo();
1.113 + }
1.114 +
1.115 +
1.116 +/** SCSI Request */
1.117 +TMassStorage::TEvent TMassStorage::InquiryL()
1.118 + {
1.119 + __MSFNLOG
1.120 + TEvent event = EEvCommandFailed;
1.121 +
1.122 + switch (iScsiProtocol.MsInquiryL())
1.123 + {
1.124 + case KErrNone:
1.125 + event = EEvCommandPassed;
1.126 + break;
1.127 + case KErrCommandFailed:
1.128 + event = EEvCommandFailed;
1.129 + break;
1.130 + case KErrNotSupported:
1.131 + __SCSIPRINT(_L("INQUIRY Command returned NOT SUPPORTED"));
1.132 + User::Leave(KErrNotSupported);
1.133 + break;
1.134 + default:
1.135 + User::Leave(KErrUnknown);
1.136 + break;
1.137 + }
1.138 + return event;
1.139 + }
1.140 +
1.141 +
1.142 +/** SCSI Request */
1.143 +TMassStorage::TEvent TMassStorage::SenseL()
1.144 + {
1.145 + __MSFNLOG
1.146 + TEvent event = EEvCommandPassed;
1.147 + switch (iScsiProtocol.MsRequestSenseL())
1.148 + {
1.149 + case KErrNone:
1.150 + break;
1.151 + case KErrCommandFailed:
1.152 + __SCSIPRINT(_L("REQUEST SENSE Command Failed"));
1.153 + User::Leave(KErrNotSupported);
1.154 + break;
1.155 + default:
1.156 + User::Leave(KErrUnknown);
1.157 + break;
1.158 + }
1.159 + return event;
1.160 + }
1.161 +
1.162 +
1.163 +/** SCSI Request */
1.164 +TMassStorage::TEvent TMassStorage::TestUnitReadyL()
1.165 + {
1.166 + __MSFNLOG
1.167 + // KErrCommandFailed indictates that device is NOT READY
1.168 + TInt err = iScsiProtocol.MsTestUnitReadyL();
1.169 + return (err == KErrNone) ? EEvCommandPassed : EEvCommandFailed;
1.170 + }
1.171 +
1.172 +
1.173 +/** SCSI Request */
1.174 +TMassStorage::TEvent TMassStorage::StartStopUnitL(TBool aStart)
1.175 + {
1.176 + __MSFNLOG
1.177 + TInt err = iScsiProtocol.MsStartStopUnitL(aStart);
1.178 + return (err == KErrNone) ? EEvCommandPassed : EEvCommandFailed;
1.179 + }
1.180 +
1.181 +
1.182 +/** SCSI Request */
1.183 +TMassStorage::TEvent TMassStorage::PreventAllowMediumRemovalL(TBool aPrevent)
1.184 + {
1.185 + __MSFNLOG
1.186 + // KErrCommandFailed indictates that device is NOT READY
1.187 + TInt err = iScsiProtocol.MsPreventAllowMediaRemovalL(aPrevent);
1.188 + return (err == KErrNone) ? EEvCommandPassed : EEvCommandFailed;
1.189 + }
1.190 +
1.191 +
1.192 +/** SCSI Request */
1.193 +TMassStorage::TEvent TMassStorage::ReadCapacityL()
1.194 + {
1.195 + __MSFNLOG
1.196 + TInt err = iScsiProtocol.MsReadCapacityL();
1.197 + return ErrToEvent(err);
1.198 + }
1.199 +
1.200 +
1.201 +/** SCSI Request */
1.202 +TMassStorage::TEvent TMassStorage::ModeSense10L()
1.203 + {
1.204 + __MSFNLOG
1.205 + TInt err = iScsiProtocol.MsModeSense10L();
1.206 + return ErrToEvent(err);
1.207 + }
1.208 +
1.209 +
1.210 +/** SCSI Request */
1.211 +TMassStorage::TEvent TMassStorage::ModeSense6L()
1.212 + {
1.213 + __MSFNLOG
1.214 + TInt err = iScsiProtocol.MsModeSense6L();
1.215 + return ErrToEvent(err);
1.216 + }
1.217 +
1.218 +
1.219 +/**
1.220 +Creates and returns a pointer to CMassStorageFsm.
1.221 +
1.222 +@param aScsiProtocol A reference to the protocol providing the interface to the
1.223 +mass storage device.
1.224 +
1.225 +@return CMassStorageFsm* A pointer to the newly created object
1.226 +*/
1.227 +CMassStorageFsm* CMassStorageFsm::NewL(CScsiProtocol& aScsiProtocol)
1.228 +{
1.229 + __MSFNSLOG
1.230 + CMassStorageFsm* r = new (ELeave) CMassStorageFsm(aScsiProtocol);
1.231 +
1.232 + CleanupStack::PushL(r);
1.233 + r->ConstructL();
1.234 + CleanupStack::Pop();
1.235 + return r;
1.236 +}
1.237 +
1.238 +void CMassStorageFsm::ConstructL()
1.239 + {
1.240 + __MSFNLOG
1.241 + TInt i = 0;
1.242 + // EInquiryState,
1.243 + iStateTable[i++] = new (ELeave) TInquiryState;
1.244 + // EInquirySenseState,
1.245 + iStateTable[i++] = new (ELeave) TInquirySenseState;
1.246 + // ENotReadyState,
1.247 + iStateTable[i++] = new (ELeave) TNotReadyState;
1.248 + // ENotReadySenseState,
1.249 + iStateTable[i++] = new (ELeave) TNotReadySenseState;
1.250 + // EStartUnitState
1.251 + iStateTable[i++] = new (ELeave) TStartUnitState;
1.252 + //EStartUnitSenseState,
1.253 + iStateTable[i++] = new (ELeave) TStartUnitSenseState;
1.254 + //EPreventAllowMediumRemovalState,
1.255 + iStateTable[i++] = new (ELeave) TPreventMediumRemovalState;
1.256 + //EPreventAllowMediumRemovalSenseState,
1.257 + iStateTable[i++] = new (ELeave) TPreventMediumRemovalSenseState;
1.258 + //EReadCapacity10State,
1.259 + iStateTable[i++] = new (ELeave) TReadCapacity10State;
1.260 + //EModeSense10State,
1.261 + iStateTable[i++] = new (ELeave) TModeSense10State;
1.262 + //EModeSense10SenseState,
1.263 + iStateTable[i++] = new (ELeave) TModeSense10SenseState;
1.264 + //EModeSense6State,
1.265 + iStateTable[i++] = new (ELeave) TModeSense6State;
1.266 + //EModeSense6SenseState,
1.267 + iStateTable[i++] = new (ELeave) TModeSense6SenseState;
1.268 + //EConnectedState,
1.269 + iStateTable[i++] = new (ELeave) TConnectedState;
1.270 + //EStatusCheck
1.271 + iStateTable[i++] = new (ELeave) TStatusCheckState;
1.272 + //EAllowMediumRemovalState,
1.273 + iStateTable[i++] = new (ELeave) TAllowMediumRemovalState;
1.274 + //EStopUnitState,
1.275 + iStateTable[i++] = new (ELeave) TStopUnitState;
1.276 + //ESenseState,
1.277 + iStateTable[i++] = new (ELeave) TSenseState;
1.278 +
1.279 +#ifdef __DEBUG
1.280 + // verify state table
1.281 + for (TInt i = 0; i < iStateTable.Count(), i++)
1.282 + {
1.283 + __ASSERT_DEBUG(i == iStateTable[i].iStateId, User::Invariant());
1.284 + }
1.285 +#endif
1.286 +
1.287 + SetState(TMassStorageState::EInquiryState);
1.288 + }
1.289 +
1.290 +
1.291 +CMassStorageFsm::CMassStorageFsm(CScsiProtocol& aScsiProtocol)
1.292 +: TMassStorage(aScsiProtocol),
1.293 + iStartStopUnitRequired(EFalse)
1.294 + {
1.295 + __MSFNLOG
1.296 + }
1.297 +
1.298 +CMassStorageFsm::~CMassStorageFsm()
1.299 + {
1.300 + __MSFNLOG
1.301 +
1.302 + for (TInt i = 0; i < iStateTable.Count(); i++)
1.303 + {
1.304 + delete iStateTable[i];
1.305 + }
1.306 + }
1.307 +
1.308 +
1.309 +TMassStorage::TEvent CMassStorageFsm::EntryL()
1.310 + {
1.311 + __MSFNLOG
1.312 +
1.313 + return iState->EntryL(*this);
1.314 + }
1.315 +
1.316 +
1.317 +/**
1.318 +Run FSM to connect device.
1.319 +
1.320 +@return TInt KErrCompletion if successful otherwise KErrNotSupported
1.321 +*/
1.322 +TInt CMassStorageFsm::ConnectLogicalUnitL()
1.323 + {
1.324 + __MSFNLOG
1.325 + TInt err = KErrNone;
1.326 + for (;;)
1.327 + {
1.328 + err = ProcessStateL();
1.329 + if (err)
1.330 + break;
1.331 + }
1.332 + return err;
1.333 + }
1.334 +
1.335 +
1.336 +/**
1.337 +Run FSM to disconnect the device.
1.338 +
1.339 +@return TInt KErrCompletion if successful otherwise KErrNotSupported
1.340 +*/
1.341 +TInt CMassStorageFsm::DisconnectLogicalUnitL()
1.342 + {
1.343 + __MSFNLOG
1.344 + TInt err = KErrNone;
1.345 + for (;;)
1.346 + {
1.347 + TInt err = ProcessStateL();
1.348 + if (err)
1.349 + break;
1.350 + }
1.351 + return err;
1.352 + }
1.353 +
1.354 +
1.355 +/**
1.356 +Return current FSM state.
1.357 +
1.358 +@return TBool ETrue if FSM state is Connected State
1.359 +*/
1.360 +TBool CMassStorageFsm::IsConnected() const
1.361 + {
1.362 + __MSFNSLOG
1.363 + return iState->iStateId == TMassStorageState::EConnectedState ? ETrue : EFalse;
1.364 + }
1.365 +
1.366 +
1.367 +TInt CMassStorageFsm::ProcessStateL()
1.368 + {
1.369 + __MSFNLOG
1.370 + TMassStorage::TEvent event = TMassStorage::EEvCommandFailed;
1.371 + TRAPD(err, event = EntryL());
1.372 + if (err == KErrNotSupported)
1.373 + {
1.374 + return KErrNotSupported;
1.375 + }
1.376 + User::LeaveIfError(err);
1.377 +
1.378 + __HOSTPRINT1(_L("FSM event=%d"), event);
1.379 + switch (event)
1.380 + {
1.381 + case TMassStorage::EEvCommandPassed:
1.382 + err = ScsiCommandPassed();
1.383 + break;
1.384 + case TMassStorage::EEvCommandFailed:
1.385 + err = ScsiCommandFailed();
1.386 + break;
1.387 + case TMassStorage::EEvCommandError:
1.388 + err = ScsiCommandError();
1.389 + break;
1.390 + default:
1.391 + User::Panic(KUsbMsHostPanicCat, EMsFsmEvent);
1.392 + break;
1.393 + }
1.394 +
1.395 + __HOSTPRINT1(_L("FSM ProcessState completed=%d"), err);
1.396 + return err;
1.397 + }
1.398 +
1.399 +
1.400 +TInt CMassStorageFsm::ScsiCommandPassed()
1.401 + {
1.402 + __MSFNLOG
1.403 + return iState->ScsiCommandPassed(*this);
1.404 + }
1.405 +
1.406 +
1.407 +TInt CMassStorageFsm::ScsiCommandFailed()
1.408 + {
1.409 + __MSFNLOG
1.410 + return iState->ScsiCommandFailed(*this);
1.411 + }
1.412 +
1.413 +
1.414 +TInt CMassStorageFsm::ScsiCommandError()
1.415 + {
1.416 + __MSFNLOG
1.417 + return iState->ScsiCommandError(*this);
1.418 + }
1.419 +
1.420 +
1.421 +/**
1.422 +Constructor
1.423 +
1.424 +@param aStateId The state id of the state implementation
1.425 +*/
1.426 +TMassStorageState::TMassStorageState(TStateId aStateId)
1.427 +: iStateId(aStateId)
1.428 + {
1.429 + __MSFNLOG
1.430 + }
1.431 +
1.432 +
1.433 +/**
1.434 + Default state does nothing. Used by states where the stalled event is not
1.435 + applicable
1.436 +
1.437 + @param aFsm
1.438 +
1.439 + @return TInt
1.440 + */
1.441 +TInt TMassStorageState::ScsiCommandError(CMassStorageFsm& /* aFsm */)
1.442 + {
1.443 + return KErrNone;
1.444 + }
1.445 +
1.446 +
1.447 +TInt TMassStorageState::SenseError(CMassStorageFsm& aFsm)
1.448 + {
1.449 + __MSFNLOG
1.450 + TInt ret = KErrNone;
1.451 + const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
1.452 +
1.453 + if (senseInfo.iSenseCode == TSenseInfo::EUnitAttention)
1.454 + {
1.455 + aFsm.SetState(TMassStorageState::EInquiryState);
1.456 + }
1.457 + else
1.458 + {
1.459 + aFsm.SetState(TMassStorageState::ENotReadyState);
1.460 + ret = KErrCompletion;
1.461 + }
1.462 + return ret;
1.463 + }
1.464 +
1.465 +
1.466 +/**
1.467 +
1.468 +*/
1.469 +TInquiryState::TInquiryState()
1.470 +: TMassStorageState(EInquiryState)
1.471 + {
1.472 + __MSFNLOG
1.473 + }
1.474 +
1.475 +
1.476 +TMassStorage::TEvent TInquiryState::EntryL(CMassStorageFsm& aFsm)
1.477 + {
1.478 + __MSFNLOG
1.479 + return aFsm.InquiryL();
1.480 + };
1.481 +
1.482 +
1.483 +TInt TInquiryState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.484 + {
1.485 + __MSFNLOG
1.486 + aFsm.SetState(ENotReadyState);
1.487 + return KErrNone;
1.488 + };
1.489 +
1.490 +
1.491 +TInt TInquiryState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.492 + {
1.493 + __MSFNLOG
1.494 + aFsm.SetState(EInquirySenseState);
1.495 + return KErrNone;
1.496 + }
1.497 +
1.498 +
1.499 +/**
1.500 +
1.501 +*/
1.502 +TInquirySenseState::TInquirySenseState()
1.503 +: TMassStorageState(EInquirySenseState)
1.504 + {
1.505 + __MSFNLOG
1.506 + }
1.507 +
1.508 +
1.509 +TMassStorage::TEvent TInquirySenseState::EntryL(CMassStorageFsm& aFsm)
1.510 + {
1.511 + __MSFNLOG
1.512 + return aFsm.SenseL();
1.513 + };
1.514 +
1.515 +
1.516 +TInt TInquirySenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.517 + {
1.518 + __MSFNLOG
1.519 + // SENSE ERROR
1.520 + aFsm.SetState(TMassStorageState::EInquiryState);
1.521 + return KErrCompletion;
1.522 + };
1.523 +
1.524 +
1.525 +TInt TInquirySenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.526 + {
1.527 + __MSFNLOG
1.528 + aFsm.SetState(TMassStorageState::EInquiryState);
1.529 + return KErrCompletion;
1.530 + }
1.531 +
1.532 +
1.533 +/**
1.534 +
1.535 +*/
1.536 +TNotReadyState::TNotReadyState()
1.537 +: TMassStorageState(ENotReadyState)
1.538 + {
1.539 + __MSFNLOG
1.540 + }
1.541 +
1.542 +
1.543 +TMassStorage::TEvent TNotReadyState::EntryL(CMassStorageFsm& aFsm)
1.544 + {
1.545 + __MSFNLOG
1.546 + return aFsm.TestUnitReadyL();
1.547 + }
1.548 +
1.549 +
1.550 +TInt TNotReadyState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.551 + {
1.552 + __MSFNLOG
1.553 + if (aFsm.IsSbcSet())
1.554 + {
1.555 + if (aFsm.IsRemovableMedia())
1.556 + aFsm.SetState(TMassStorageState::EPreventRemovalState);
1.557 + else
1.558 + aFsm.SetState(TMassStorageState::EReadCapacityState);
1.559 + }
1.560 + else
1.561 + aFsm.SetState(TMassStorageState::EInquiryState);
1.562 + return KErrNone;
1.563 + }
1.564 +
1.565 +
1.566 +TInt TNotReadyState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.567 + {
1.568 + __MSFNLOG
1.569 + aFsm.SetState(TMassStorageState::ENotReadySenseState);
1.570 + return KErrNone;
1.571 + }
1.572 +
1.573 +
1.574 +/**
1.575 +
1.576 +*/
1.577 +TNotReadySenseState::TNotReadySenseState()
1.578 +: TMassStorageState(ENotReadySenseState)
1.579 + {
1.580 + __MSFNLOG
1.581 + }
1.582 +
1.583 +
1.584 +TMassStorage::TEvent TNotReadySenseState::EntryL(CMassStorageFsm& aFsm)
1.585 + {
1.586 + __MSFNLOG
1.587 + return aFsm.SenseL();
1.588 + }
1.589 +
1.590 +
1.591 +TInt TNotReadySenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.592 + {
1.593 + __MSFNLOG
1.594 + const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
1.595 + TInt ret = KErrNone;
1.596 +
1.597 + if (senseInfo.iSenseCode == TSenseInfo::ENotReady &&
1.598 + senseInfo.iAdditional == TSenseInfo::EAscLogicalUnitNotReady &&
1.599 + senseInfo.iQualifier == TSenseInfo::EAscqInitializingCommandRequired)
1.600 + {
1.601 + aFsm.SetStartStopUnitRequired(ETrue);
1.602 + aFsm.SetState(TMassStorageState::EStartUnitState);
1.603 + }
1.604 + else
1.605 + {
1.606 + ret = TMassStorageState::SenseError(aFsm);
1.607 + }
1.608 +
1.609 + return ret;
1.610 + }
1.611 +
1.612 +
1.613 +TInt TNotReadySenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.614 + {
1.615 + __MSFNLOG
1.616 + return TMassStorageState::SenseError(aFsm);
1.617 + }
1.618 +
1.619 +
1.620 +/**
1.621 +
1.622 +*/
1.623 +TStartUnitState::TStartUnitState()
1.624 +: TMassStorageState(EPreventRemovalState)
1.625 + {
1.626 + __MSFNLOG
1.627 + }
1.628 +
1.629 +
1.630 +TMassStorage::TEvent TStartUnitState::EntryL(CMassStorageFsm& aFsm)
1.631 + {
1.632 + __MSFNLOG
1.633 + return aFsm.StartStopUnitL(ETrue);
1.634 + }
1.635 +
1.636 +
1.637 +TInt TStartUnitState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.638 + {
1.639 + __MSFNLOG
1.640 + if (aFsm.IsRemovableMedia())
1.641 + aFsm.SetState(TMassStorageState::EPreventRemovalState);
1.642 + else
1.643 + aFsm.SetState(TMassStorageState::EReadCapacityState);
1.644 + return KErrNone;
1.645 + }
1.646 +
1.647 +
1.648 +TInt TStartUnitState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.649 + {
1.650 + __MSFNLOG
1.651 + aFsm.SetState(TMassStorageState::EPreventRemovalSenseState);
1.652 + return KErrNone;
1.653 + }
1.654 +
1.655 +/**
1.656 +
1.657 +*/
1.658 +TStartUnitSenseState::TStartUnitSenseState()
1.659 +: TMassStorageState(EPreventRemovalSenseState)
1.660 + {
1.661 + __MSFNLOG
1.662 + }
1.663 +
1.664 +
1.665 +TMassStorage::TEvent TStartUnitSenseState::EntryL(CMassStorageFsm& aFsm)
1.666 + {
1.667 + __MSFNLOG
1.668 + return aFsm.SenseL();
1.669 + }
1.670 +
1.671 +
1.672 +TInt TStartUnitSenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.673 + {
1.674 + __MSFNLOG
1.675 + if (aFsm.IsRemovableMedia())
1.676 + aFsm.SetState(TMassStorageState::EPreventRemovalState);
1.677 + else
1.678 + aFsm.SetState(TMassStorageState::EReadCapacityState);
1.679 +
1.680 + return KErrNone;
1.681 + }
1.682 +
1.683 +
1.684 +TInt TStartUnitSenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.685 + {
1.686 + __MSFNLOG
1.687 + TInt ret = KErrCompletion;
1.688 + const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
1.689 +
1.690 + aFsm.SetState(TMassStorageState::EInquiryState);
1.691 + if (senseInfo.iSenseCode == TSenseInfo::EIllegalRequest)
1.692 + {
1.693 + aFsm.SetState(TMassStorageState::EReadCapacityState);
1.694 + ret = KErrNone;
1.695 + }
1.696 + else
1.697 + {
1.698 + ret = TMassStorageState::SenseError(aFsm);
1.699 + }
1.700 +
1.701 + return ret;
1.702 + }
1.703 +
1.704 +
1.705 +/**
1.706 +
1.707 +*/
1.708 +TPreventMediumRemovalState::TPreventMediumRemovalState()
1.709 +: TMassStorageState(EPreventRemovalState)
1.710 + {
1.711 + __MSFNLOG
1.712 + }
1.713 +
1.714 +
1.715 +TMassStorage::TEvent TPreventMediumRemovalState::EntryL(CMassStorageFsm& aFsm)
1.716 + {
1.717 + __MSFNLOG
1.718 + return aFsm.PreventAllowMediumRemovalL(ETrue);
1.719 + }
1.720 +
1.721 +
1.722 +TInt TPreventMediumRemovalState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.723 + {
1.724 + __MSFNLOG
1.725 + aFsm.SetState(TMassStorageState::EReadCapacityState);
1.726 + return KErrNone;
1.727 + }
1.728 +
1.729 +
1.730 +TInt TPreventMediumRemovalState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.731 + {
1.732 + __MSFNLOG
1.733 + aFsm.SetState(TMassStorageState::EPreventRemovalSenseState);
1.734 + return KErrNone;
1.735 + }
1.736 +
1.737 +/**
1.738 +
1.739 +*/
1.740 +TPreventMediumRemovalSenseState::TPreventMediumRemovalSenseState()
1.741 +: TMassStorageState(EPreventRemovalSenseState)
1.742 + {
1.743 + __MSFNLOG
1.744 + }
1.745 +
1.746 +
1.747 +TMassStorage::TEvent TPreventMediumRemovalSenseState::EntryL(CMassStorageFsm& aFsm)
1.748 + {
1.749 + __MSFNLOG
1.750 + return aFsm.SenseL();
1.751 + }
1.752 +
1.753 +
1.754 +TInt TPreventMediumRemovalSenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.755 + {
1.756 + __MSFNLOG
1.757 + aFsm.SetState(TMassStorageState::EReadCapacityState);
1.758 + return KErrNone;
1.759 + }
1.760 +
1.761 +
1.762 +
1.763 +
1.764 +TInt TPreventMediumRemovalSenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.765 + {
1.766 + __MSFNLOG
1.767 + TInt ret = KErrCompletion;
1.768 + const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
1.769 +
1.770 + if (senseInfo.iSenseCode == TSenseInfo::EIllegalRequest)
1.771 + {
1.772 + aFsm.SetState(TMassStorageState::EReadCapacityState);
1.773 + ret = KErrNone;
1.774 + }
1.775 + else
1.776 + {
1.777 + ret = TMassStorageState::SenseError(aFsm);
1.778 + }
1.779 + return ret;
1.780 + }
1.781 +
1.782 +
1.783 +/**
1.784 +
1.785 +*/
1.786 +TReadCapacity10State::TReadCapacity10State()
1.787 +: TMassStorageState(EReadCapacityState)
1.788 + {
1.789 + __MSFNLOG
1.790 + }
1.791 +
1.792 +
1.793 +TMassStorage::TEvent TReadCapacity10State::EntryL(CMassStorageFsm& aFsm)
1.794 + {
1.795 + __MSFNLOG
1.796 + return aFsm.ReadCapacityL();
1.797 + };
1.798 +
1.799 +
1.800 +TInt TReadCapacity10State::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.801 + {
1.802 + __MSFNLOG
1.803 + aFsm.SetState(EModeSense10State);
1.804 + return KErrNone;
1.805 + };
1.806 +
1.807 +
1.808 +TInt TReadCapacity10State::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.809 + {
1.810 + __MSFNLOG
1.811 + aFsm.SetState(TMassStorageState::ESenseState);
1.812 + return KErrCompletion;
1.813 + }
1.814 +
1.815 +
1.816 +TInt TReadCapacity10State::ScsiCommandError(CMassStorageFsm& aFsm)
1.817 + {
1.818 + __MSFNLOG
1.819 + aFsm.SetState(TMassStorageState::ENotReadyState);
1.820 + return KErrCompletion;
1.821 + }
1.822 +
1.823 +
1.824 +/**
1.825 +
1.826 +*/
1.827 +TModeSense10State::TModeSense10State()
1.828 +: TMassStorageState(EModeSense10State)
1.829 + {
1.830 + __MSFNLOG
1.831 + }
1.832 +
1.833 +
1.834 +TMassStorage::TEvent TModeSense10State::EntryL(CMassStorageFsm& aFsm)
1.835 + {
1.836 + __MSFNLOG
1.837 + return aFsm.ModeSense10L();
1.838 + };
1.839 +
1.840 +
1.841 +TInt TModeSense10State::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.842 + {
1.843 + __MSFNLOG
1.844 + aFsm.SetState(EConnectedState);
1.845 + return KErrCompletion;
1.846 + };
1.847 +
1.848 +
1.849 +TInt TModeSense10State::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.850 + {
1.851 + __MSFNLOG
1.852 + aFsm.SetState(EModeSense10SenseState);
1.853 + return KErrNone;
1.854 + }
1.855 +
1.856 +
1.857 +TInt TModeSense10State::ScsiCommandError(CMassStorageFsm& aFsm)
1.858 + {
1.859 + __MSFNLOG
1.860 + aFsm.SetState(EModeSense6State);
1.861 + return KErrNone;
1.862 + }
1.863 +
1.864 +/**
1.865 +
1.866 +*/
1.867 +TModeSense10SenseState::TModeSense10SenseState()
1.868 +: TMassStorageState(EModeSense10SenseState)
1.869 + {
1.870 + __MSFNLOG
1.871 + }
1.872 +
1.873 +
1.874 +TMassStorage::TEvent TModeSense10SenseState::EntryL(CMassStorageFsm& aFsm)
1.875 + {
1.876 + __MSFNLOG
1.877 + return aFsm.SenseL();
1.878 + };
1.879 +
1.880 +
1.881 +TInt TModeSense10SenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.882 + {
1.883 + __MSFNLOG
1.884 + TInt ret = KErrCompletion;
1.885 + const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
1.886 +
1.887 + aFsm.SetState(TMassStorageState::EInquiryState);
1.888 + if (senseInfo.iSenseCode == TSenseInfo::EIllegalRequest)
1.889 + {
1.890 + aFsm.SetState(TMassStorageState::EModeSense6State);
1.891 + ret = KErrNone;
1.892 + }
1.893 + else
1.894 + {
1.895 + ret = TMassStorageState::SenseError(aFsm);
1.896 + }
1.897 + return ret;
1.898 + };
1.899 +
1.900 +
1.901 +TInt TModeSense10SenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.902 + {
1.903 + __MSFNLOG
1.904 + aFsm.SetState(EInquirySenseState);
1.905 + return KErrCompletion;
1.906 + }
1.907 +
1.908 +/**
1.909 +
1.910 +*/
1.911 +TModeSense6State::TModeSense6State()
1.912 +: TMassStorageState(EModeSense6State)
1.913 + {
1.914 + __MSFNLOG
1.915 + }
1.916 +
1.917 +
1.918 +TMassStorage::TEvent TModeSense6State::EntryL(CMassStorageFsm& aFsm)
1.919 + {
1.920 + __MSFNLOG
1.921 + return aFsm.ModeSense6L();
1.922 + };
1.923 +
1.924 +
1.925 +TInt TModeSense6State::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.926 + {
1.927 + __MSFNLOG
1.928 + aFsm.SetState(EConnectedState);
1.929 + return KErrCompletion;
1.930 + };
1.931 +
1.932 +
1.933 +TInt TModeSense6State::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.934 + {
1.935 + __MSFNLOG
1.936 + aFsm.SetState(EModeSense6SenseState);
1.937 + return KErrNone;
1.938 + }
1.939 +
1.940 +
1.941 +TInt TModeSense6State::ScsiCommandError(CMassStorageFsm& aFsm)
1.942 + {
1.943 + __MSFNLOG
1.944 + // If device responds with protocol error, ignore the error and assume the
1.945 + // device is not write protected
1.946 + aFsm.SetState(EConnectedState);
1.947 + return KErrCompletion;
1.948 + }
1.949 +
1.950 +
1.951 +/**
1.952 +
1.953 +*/
1.954 +TModeSense6SenseState::TModeSense6SenseState()
1.955 +: TMassStorageState(EModeSense6SenseState)
1.956 + {
1.957 + __MSFNLOG
1.958 + }
1.959 +
1.960 +
1.961 +TMassStorage::TEvent TModeSense6SenseState::EntryL(CMassStorageFsm& aFsm)
1.962 + {
1.963 + __MSFNLOG
1.964 + return aFsm.SenseL();
1.965 + };
1.966 +
1.967 +
1.968 +TInt TModeSense6SenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.969 + {
1.970 + __MSFNLOG
1.971 + TInt ret = KErrCompletion;
1.972 + const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
1.973 +
1.974 + aFsm.SetState(TMassStorageState::EInquiryState);
1.975 + if (senseInfo.iSenseCode == TSenseInfo::EIllegalRequest)
1.976 + {
1.977 + aFsm.SetState(TMassStorageState::EConnectedState);
1.978 + }
1.979 + else
1.980 + {
1.981 + ret = TMassStorageState::SenseError(aFsm);
1.982 + }
1.983 + return ret;
1.984 + };
1.985 +
1.986 +
1.987 +TInt TModeSense6SenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.988 + {
1.989 + __MSFNLOG
1.990 + aFsm.SetState(EInquirySenseState);
1.991 + return KErrCompletion;
1.992 + }
1.993 +
1.994 +
1.995 +
1.996 +/**
1.997 +
1.998 +*/
1.999 +TConnectedState::TConnectedState()
1.1000 +: TMassStorageState(EConnectedState)
1.1001 + {
1.1002 + __MSFNLOG
1.1003 + }
1.1004 +
1.1005 +
1.1006 +TMassStorage::TEvent TConnectedState::EntryL(CMassStorageFsm& /* aFsm */)
1.1007 + {
1.1008 + __MSFNLOG
1.1009 + return TMassStorage::EEvCommandPassed;
1.1010 + };
1.1011 +
1.1012 +
1.1013 +TInt TConnectedState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.1014 + {
1.1015 + __MSFNLOG
1.1016 + TInt ret = KErrNone;
1.1017 +
1.1018 + if (aFsm.IsRemovableMedia())
1.1019 + {
1.1020 + if(aFsm.IsStatusCheck())
1.1021 + {
1.1022 + aFsm.SetState(TMassStorageState::EStatusCheckState);
1.1023 + }
1.1024 + else
1.1025 + {
1.1026 + aFsm.SetState(TMassStorageState::EAllowRemovalState);
1.1027 + }
1.1028 + }
1.1029 + else if (aFsm.StartStopUnitRequired())
1.1030 + {
1.1031 + aFsm.SetState(TMassStorageState::EStopUnitState);
1.1032 + }
1.1033 + else
1.1034 + {
1.1035 + aFsm.SetState(TMassStorageState::ENotReadyState);
1.1036 + ret = KErrCompletion;
1.1037 + }
1.1038 + return ret;
1.1039 + };
1.1040 +
1.1041 +
1.1042 +TInt TConnectedState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.1043 + {
1.1044 + __MSFNLOG
1.1045 + aFsm.SetState(TMassStorageState::EInquiryState);
1.1046 + return KErrCompletion;
1.1047 + }
1.1048 +
1.1049 +
1.1050 +/**
1.1051 +
1.1052 +*/
1.1053 +TStatusCheckState::TStatusCheckState()
1.1054 +: TMassStorageState(EStatusCheckState)
1.1055 + {
1.1056 + __MSFNLOG
1.1057 + }
1.1058 +
1.1059 +
1.1060 +TMassStorage::TEvent TStatusCheckState::EntryL(CMassStorageFsm& aFsm)
1.1061 + {
1.1062 + __MSFNLOG
1.1063 + return aFsm.TestUnitReadyL();
1.1064 + };
1.1065 +
1.1066 +
1.1067 +TInt TStatusCheckState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.1068 + {
1.1069 + __MSFNLOG
1.1070 + aFsm.SetState(EConnectedState);
1.1071 + return KErrCompletion;
1.1072 + };
1.1073 +
1.1074 +
1.1075 +TInt TStatusCheckState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.1076 + {
1.1077 + __MSFNLOG
1.1078 + aFsm.SetState(ESenseState);
1.1079 + return KErrNone;
1.1080 + }
1.1081 +
1.1082 +
1.1083 +/**
1.1084 +
1.1085 +*/
1.1086 +TAllowMediumRemovalState::TAllowMediumRemovalState()
1.1087 +: TMassStorageState(EAllowRemovalState)
1.1088 + {
1.1089 + __MSFNLOG
1.1090 + }
1.1091 +
1.1092 +
1.1093 +TMassStorage::TEvent TAllowMediumRemovalState::EntryL(CMassStorageFsm& aFsm)
1.1094 + {
1.1095 + __MSFNLOG
1.1096 + return aFsm.PreventAllowMediumRemovalL(EFalse);
1.1097 + }
1.1098 +
1.1099 +
1.1100 +TInt TAllowMediumRemovalState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.1101 + {
1.1102 + __MSFNLOG
1.1103 + TInt ret = KErrNone;
1.1104 + if (aFsm.StartStopUnitRequired())
1.1105 + {
1.1106 + aFsm.SetState(TMassStorageState::EStopUnitState);
1.1107 + }
1.1108 + else
1.1109 + {
1.1110 + aFsm.SetState(ENotReadyState);
1.1111 + ret = KErrCompletion;
1.1112 + }
1.1113 + return ret;
1.1114 + };
1.1115 +
1.1116 +
1.1117 +TInt TAllowMediumRemovalState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.1118 + {
1.1119 + __MSFNLOG
1.1120 + aFsm.SetState(TMassStorageState::EInquiryState);
1.1121 + return KErrCompletion;
1.1122 + }
1.1123 +
1.1124 +
1.1125 +/**
1.1126 +
1.1127 +*/
1.1128 +TStopUnitState::TStopUnitState()
1.1129 +: TMassStorageState(EStopUnitState)
1.1130 + {
1.1131 + __MSFNLOG
1.1132 + }
1.1133 +
1.1134 +
1.1135 +TMassStorage::TEvent TStopUnitState::EntryL(CMassStorageFsm& aFsm)
1.1136 + {
1.1137 + __MSFNLOG
1.1138 + return aFsm.StartStopUnitL(EFalse);
1.1139 + }
1.1140 +
1.1141 +
1.1142 +TInt TStopUnitState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.1143 + {
1.1144 + __MSFNLOG
1.1145 + aFsm.SetState(ENotReadyState);
1.1146 + return KErrCompletion;
1.1147 + };
1.1148 +
1.1149 +
1.1150 +TInt TStopUnitState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.1151 + {
1.1152 + __MSFNLOG
1.1153 + aFsm.SetState(TMassStorageState::EInquiryState);
1.1154 + return KErrCompletion;
1.1155 + }
1.1156 +
1.1157 +
1.1158 +/**
1.1159 +
1.1160 +*/
1.1161 +TSenseState::TSenseState()
1.1162 +: TMassStorageState(EConnectedState)
1.1163 + {
1.1164 + __MSFNLOG
1.1165 + }
1.1166 +
1.1167 +
1.1168 +TMassStorage::TEvent TSenseState::EntryL(CMassStorageFsm& aFsm)
1.1169 + {
1.1170 + __MSFNLOG
1.1171 + return aFsm.SenseL();
1.1172 + };
1.1173 +
1.1174 +
1.1175 +TInt TSenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
1.1176 + {
1.1177 + __MSFNLOG
1.1178 + aFsm.SetState(ENotReadyState);
1.1179 + return KErrCompletion;
1.1180 + };
1.1181 +
1.1182 +
1.1183 +TInt TSenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
1.1184 + {
1.1185 + __MSFNLOG
1.1186 + // This event should not happen
1.1187 + aFsm.SetState(EInquiryState);
1.1188 + return KErrCompletion;
1.1189 + }
1.1190 +