os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/server/protocol/cmassstoragefsm.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @internalTechnology
    19 */
    20 
    21 #include <e32base.h>
    22 
    23 #include "usbmshostpanic.h"
    24 #include "debug.h"
    25 #include "msdebug.h"
    26 
    27 #include "msctypes.h"
    28 #include "mprotocol.h"
    29 #include "mblocktransferprotocol.h"
    30 #include "tspcclientinterface.h"
    31 #include "cscsiprotocol.h"
    32 #include "cmassstoragefsm.h"
    33 
    34 
    35 /**
    36 Constructor
    37 
    38 @param aScsiProtocol A reference to CScsiProtocol
    39 */
    40 TMassStorage::TMassStorage(CScsiProtocol& aScsiProtocol)
    41 :   iScsiProtocol(aScsiProtocol)
    42     {
    43 	__MSFNLOG
    44     }
    45 
    46 
    47 /**
    48 Clear StatusCheck flag. Periodic status checking is used for removable media.
    49 */
    50 void CMassStorageFsm::ClearStatusCheck()
    51 {
    52 	__MSFNLOG
    53 	iStatusCheck = EFalse;
    54 }
    55 
    56 
    57 /**
    58 Set StatusCheck flag. Periodic status checking is used for removable media.
    59 */
    60 void CMassStorageFsm::SetStatusCheck()
    61 {
    62 	__MSFNLOG
    63 	iStatusCheck = ETrue;
    64 }
    65 
    66 
    67 /**
    68 Get the boolean state of StatusCheck flag.
    69 
    70 @return TBool ETrue if StatusCheck flag is set
    71 */
    72 TBool CMassStorageFsm::IsStatusCheck() const
    73 {
    74 	__MSFNSLOG
    75 	return iStatusCheck;
    76 }
    77 
    78 
    79 /**
    80 Device supports SCSI BLOCK COMMANDS.
    81 
    82 @return TBool Returns ETrue if the SBC interface is initialised
    83 */
    84 TBool TMassStorage::IsSbcSet() const
    85     {
    86 	__MSFNSLOG
    87     return iScsiProtocol.MsIsSbcSet();
    88     }
    89 
    90 /**
    91 Device is removable media
    92 
    93 @return TBool Returns ETrue if removable
    94 */
    95 TBool TMassStorage::IsRemovableMedia() const
    96     {
    97 	__MSFNSLOG
    98     return iScsiProtocol.MsIsRemovableMedia();
    99     }
   100 
   101 /**
   102 Retrieve the sense info returned by a call to SenseL
   103 
   104 @return const TSenseInfo& Returns the SCSI SENSE info
   105 */
   106 const TSenseInfo& TMassStorage::MsSenseInfo() const
   107     {
   108 	__MSFNSLOG
   109     return iScsiProtocol.MsSenseInfo();
   110     }
   111 
   112 
   113 /** SCSI Request */
   114 TMassStorage::TEvent TMassStorage::InquiryL()
   115     {
   116 	__MSFNLOG
   117     TEvent event = EEvCommandFailed;
   118 
   119     switch (iScsiProtocol.MsInquiryL())
   120         {
   121     case KErrNone:
   122         event = EEvCommandPassed;
   123         break;
   124     case KErrCommandFailed:
   125         event = EEvCommandFailed;
   126         break;
   127     case KErrNotSupported:
   128         __SCSIPRINT(_L("INQUIRY Command returned NOT SUPPORTED"));
   129         User::Leave(KErrNotSupported);
   130         break;
   131     default:
   132         User::Leave(KErrUnknown);
   133         break;
   134         }
   135     return event;
   136     }
   137 
   138 
   139 /** SCSI Request */
   140 TMassStorage::TEvent TMassStorage::SenseL()
   141     {
   142 	__MSFNLOG
   143     TEvent event = EEvCommandPassed;
   144     switch (iScsiProtocol.MsRequestSenseL())
   145         {
   146     case KErrNone:
   147         break;
   148     case KErrCommandFailed:
   149         __SCSIPRINT(_L("REQUEST SENSE Command Failed"));
   150         User::Leave(KErrNotSupported);
   151         break;
   152     default:
   153         User::Leave(KErrUnknown);
   154         break;
   155         }
   156     return event;
   157     }
   158 
   159 
   160 /** SCSI Request */
   161 TMassStorage::TEvent TMassStorage::TestUnitReadyL()
   162     {
   163 	__MSFNLOG
   164     // KErrCommandFailed indictates that device is NOT READY
   165     TInt err = iScsiProtocol.MsTestUnitReadyL();
   166     return (err == KErrNone) ? EEvCommandPassed : EEvCommandFailed;
   167     }
   168 
   169 
   170 /** SCSI Request */
   171 TMassStorage::TEvent TMassStorage::StartStopUnitL(TBool aStart)
   172     {
   173 	__MSFNLOG
   174     TInt err = iScsiProtocol.MsStartStopUnitL(aStart);
   175     return (err == KErrNone) ? EEvCommandPassed : EEvCommandFailed;
   176     }
   177 
   178 
   179 /** SCSI Request */
   180 TMassStorage::TEvent TMassStorage::PreventAllowMediumRemovalL(TBool aPrevent)
   181     {
   182 	__MSFNLOG
   183     // KErrCommandFailed indictates that device is NOT READY
   184     TInt err = iScsiProtocol.MsPreventAllowMediaRemovalL(aPrevent);
   185     return (err == KErrNone) ? EEvCommandPassed : EEvCommandFailed;
   186     }
   187 
   188 
   189 /** SCSI Request */
   190 TMassStorage::TEvent TMassStorage::ReadCapacityL()
   191     {
   192 	__MSFNLOG
   193     TInt err = iScsiProtocol.MsReadCapacityL();
   194     return ErrToEvent(err);
   195     }
   196 
   197 
   198 /** SCSI Request */
   199 TMassStorage::TEvent TMassStorage::ModeSense10L()
   200     {
   201 	__MSFNLOG
   202     TInt err = iScsiProtocol.MsModeSense10L();
   203     return ErrToEvent(err);
   204     }
   205 
   206 
   207 /** SCSI Request */
   208 TMassStorage::TEvent TMassStorage::ModeSense6L()
   209     {
   210 	__MSFNLOG
   211     TInt err = iScsiProtocol.MsModeSense6L();
   212     return ErrToEvent(err);
   213     }
   214 
   215 
   216 /**
   217 Creates and returns a pointer to CMassStorageFsm.
   218 
   219 @param aScsiProtocol A reference to the protocol providing the interface to the
   220 mass storage device.
   221 
   222 @return CMassStorageFsm* A pointer to the newly created object
   223 */
   224 CMassStorageFsm* CMassStorageFsm::NewL(CScsiProtocol& aScsiProtocol)
   225 {
   226 	__MSFNSLOG
   227 	CMassStorageFsm* r = new (ELeave) CMassStorageFsm(aScsiProtocol);
   228 
   229 	CleanupStack::PushL(r);
   230 	r->ConstructL();
   231 	CleanupStack::Pop();
   232 	return r;
   233 }
   234 
   235 void CMassStorageFsm::ConstructL()
   236     {
   237 	__MSFNLOG
   238     TInt i = 0;
   239     // EInquiryState,
   240     iStateTable[i++] = new (ELeave) TInquiryState;
   241     // EInquirySenseState,
   242     iStateTable[i++] = new (ELeave) TInquirySenseState;
   243     // ENotReadyState,
   244     iStateTable[i++] = new (ELeave) TNotReadyState;
   245     // ENotReadySenseState,
   246     iStateTable[i++] = new (ELeave) TNotReadySenseState;
   247     // EStartUnitState
   248     iStateTable[i++] = new (ELeave) TStartUnitState;
   249     //EStartUnitSenseState,
   250     iStateTable[i++] = new (ELeave) TStartUnitSenseState;
   251     //EPreventAllowMediumRemovalState,
   252     iStateTable[i++] = new (ELeave) TPreventMediumRemovalState;
   253     //EPreventAllowMediumRemovalSenseState,
   254     iStateTable[i++] = new (ELeave) TPreventMediumRemovalSenseState;
   255     //EReadCapacity10State,
   256     iStateTable[i++] = new (ELeave) TReadCapacity10State;
   257     //EModeSense10State,
   258     iStateTable[i++] = new (ELeave) TModeSense10State;
   259     //EModeSense10SenseState,
   260     iStateTable[i++] = new (ELeave) TModeSense10SenseState;
   261     //EModeSense6State,
   262     iStateTable[i++] = new (ELeave) TModeSense6State;
   263     //EModeSense6SenseState,
   264     iStateTable[i++] = new (ELeave) TModeSense6SenseState;
   265     //EConnectedState,
   266     iStateTable[i++] = new (ELeave) TConnectedState;
   267     //EStatusCheck
   268     iStateTable[i++] = new (ELeave) TStatusCheckState;
   269     //EAllowMediumRemovalState,
   270     iStateTable[i++] = new (ELeave) TAllowMediumRemovalState;
   271     //EStopUnitState,
   272     iStateTable[i++] = new (ELeave) TStopUnitState;
   273     //ESenseState,
   274     iStateTable[i++] = new (ELeave) TSenseState;
   275 
   276 #ifdef __DEBUG
   277     // verify state table
   278     for (TInt i = 0; i < iStateTable.Count(), i++)
   279         {
   280         __ASSERT_DEBUG(i == iStateTable[i].iStateId, User::Invariant());
   281         }
   282 #endif
   283 
   284     SetState(TMassStorageState::EInquiryState);
   285     }
   286 
   287 
   288 CMassStorageFsm::CMassStorageFsm(CScsiProtocol& aScsiProtocol)
   289 :   TMassStorage(aScsiProtocol),
   290     iStartStopUnitRequired(EFalse)
   291     {
   292 	__MSFNLOG
   293     }
   294 
   295 CMassStorageFsm::~CMassStorageFsm()
   296     {
   297 	__MSFNLOG
   298 
   299     for (TInt i = 0; i < iStateTable.Count(); i++)
   300         {
   301         delete iStateTable[i];
   302         }
   303     }
   304 
   305 
   306 TMassStorage::TEvent CMassStorageFsm::EntryL()
   307     {
   308 	__MSFNLOG
   309 
   310     return iState->EntryL(*this);
   311     }
   312 
   313 
   314 /**
   315 Run FSM to connect device.
   316 
   317 @return TInt KErrCompletion if successful otherwise KErrNotSupported
   318 */
   319 TInt CMassStorageFsm::ConnectLogicalUnitL()
   320     {
   321 	__MSFNLOG
   322     TInt err = KErrNone;
   323     for (;;)
   324          {
   325          err = ProcessStateL();
   326          if (err)
   327              break;
   328          }
   329     return err;
   330     }
   331 
   332 
   333 /**
   334 Run FSM to disconnect the device.
   335 
   336 @return TInt KErrCompletion if successful otherwise KErrNotSupported
   337 */
   338 TInt CMassStorageFsm::DisconnectLogicalUnitL()
   339     {
   340 	__MSFNLOG
   341     TInt err = KErrNone;
   342     for (;;)
   343          {
   344          TInt err = ProcessStateL();
   345          if (err)
   346              break;
   347          }
   348     return err;
   349     }
   350 
   351 
   352 /**
   353 Return current FSM state.
   354 
   355 @return TBool ETrue if FSM state is Connected State
   356 */
   357 TBool CMassStorageFsm::IsConnected() const
   358     {
   359 	__MSFNSLOG
   360     return iState->iStateId == TMassStorageState::EConnectedState ? ETrue : EFalse;
   361     }
   362 
   363 
   364 TInt CMassStorageFsm::ProcessStateL()
   365     {
   366 	__MSFNLOG
   367     TMassStorage::TEvent event = TMassStorage::EEvCommandFailed;
   368     TRAPD(err,  event = EntryL());
   369     if (err == KErrNotSupported)
   370         {
   371         return KErrNotSupported;
   372         }
   373     User::LeaveIfError(err);
   374 
   375     __HOSTPRINT1(_L("FSM event=%d"), event);
   376     switch (event)
   377         {
   378     case TMassStorage::EEvCommandPassed:
   379         err = ScsiCommandPassed();
   380         break;
   381     case TMassStorage::EEvCommandFailed:
   382         err = ScsiCommandFailed();
   383         break;
   384     case TMassStorage::EEvCommandError:
   385         err = ScsiCommandError();
   386         break;
   387     default:
   388         User::Panic(KUsbMsHostPanicCat, EMsFsmEvent);
   389         break;
   390         }
   391 
   392     __HOSTPRINT1(_L("FSM ProcessState completed=%d"), err);
   393     return err;
   394     }
   395 
   396 
   397 TInt CMassStorageFsm::ScsiCommandPassed()
   398     {
   399 	__MSFNLOG
   400     return iState->ScsiCommandPassed(*this);
   401     }
   402 
   403 
   404 TInt CMassStorageFsm::ScsiCommandFailed()
   405     {
   406 	__MSFNLOG
   407     return iState->ScsiCommandFailed(*this);
   408     }
   409 
   410 
   411 TInt CMassStorageFsm::ScsiCommandError()
   412     {
   413 	__MSFNLOG
   414     return iState->ScsiCommandError(*this);
   415     }
   416 
   417 
   418 /**
   419 Constructor
   420 
   421 @param aStateId The state id of the state implementation
   422 */
   423 TMassStorageState::TMassStorageState(TStateId aStateId)
   424 :   iStateId(aStateId)
   425     {
   426 	__MSFNLOG
   427     }
   428 
   429 
   430 /** 
   431    Default state does nothing. Used by states where the stalled event is not 
   432    applicable 
   433    
   434    @param aFsm
   435    
   436    @return TInt
   437  */
   438 TInt TMassStorageState::ScsiCommandError(CMassStorageFsm& /* aFsm */)
   439     {
   440     return KErrNone;
   441     }
   442 
   443 
   444 TInt TMassStorageState::SenseError(CMassStorageFsm& aFsm)
   445     {
   446 	__MSFNLOG
   447     TInt ret = KErrNone;
   448     const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
   449 
   450     if (senseInfo.iSenseCode == TSenseInfo::EUnitAttention)
   451         {
   452         aFsm.SetState(TMassStorageState::EInquiryState);
   453         }
   454     else
   455         {
   456         aFsm.SetState(TMassStorageState::ENotReadyState);
   457         ret = KErrCompletion;
   458         }
   459     return ret;
   460     }
   461 
   462 
   463 /**
   464 
   465 */
   466 TInquiryState::TInquiryState()
   467 :   TMassStorageState(EInquiryState)
   468     {
   469 	__MSFNLOG
   470     }
   471 
   472 
   473 TMassStorage::TEvent TInquiryState::EntryL(CMassStorageFsm& aFsm)
   474     {
   475 	__MSFNLOG
   476     return aFsm.InquiryL();
   477     };
   478 
   479 
   480 TInt TInquiryState::ScsiCommandPassed(CMassStorageFsm& aFsm)
   481     {
   482 	__MSFNLOG
   483     aFsm.SetState(ENotReadyState);
   484     return KErrNone;
   485     };
   486 
   487 
   488 TInt TInquiryState::ScsiCommandFailed(CMassStorageFsm& aFsm)
   489     {
   490 	__MSFNLOG
   491     aFsm.SetState(EInquirySenseState);
   492     return KErrNone;
   493     }
   494 
   495 
   496 /**
   497 
   498 */
   499 TInquirySenseState::TInquirySenseState()
   500 :   TMassStorageState(EInquirySenseState)
   501     {
   502 	__MSFNLOG
   503     }
   504 
   505 
   506 TMassStorage::TEvent TInquirySenseState::EntryL(CMassStorageFsm& aFsm)
   507     {
   508 	__MSFNLOG
   509     return aFsm.SenseL();
   510     };
   511 
   512 
   513 TInt TInquirySenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
   514     {
   515 	__MSFNLOG
   516     // SENSE ERROR
   517     aFsm.SetState(TMassStorageState::EInquiryState);
   518     return KErrCompletion;
   519     };
   520 
   521 
   522 TInt TInquirySenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
   523     {
   524 	__MSFNLOG
   525     aFsm.SetState(TMassStorageState::EInquiryState);
   526     return KErrCompletion;
   527     }
   528 
   529 
   530 /**
   531 
   532 */
   533 TNotReadyState::TNotReadyState()
   534 :   TMassStorageState(ENotReadyState)
   535     {
   536 	__MSFNLOG
   537     }
   538 
   539 
   540 TMassStorage::TEvent TNotReadyState::EntryL(CMassStorageFsm& aFsm)
   541     {
   542 	__MSFNLOG
   543     return aFsm.TestUnitReadyL();
   544     }
   545 
   546 
   547 TInt TNotReadyState::ScsiCommandPassed(CMassStorageFsm& aFsm)
   548     {
   549 	__MSFNLOG
   550     if (aFsm.IsSbcSet())
   551         {
   552         if (aFsm.IsRemovableMedia())
   553             aFsm.SetState(TMassStorageState::EPreventRemovalState);
   554         else
   555             aFsm.SetState(TMassStorageState::EReadCapacityState);
   556         }
   557     else
   558         aFsm.SetState(TMassStorageState::EInquiryState);
   559     return KErrNone;
   560     }
   561 
   562 
   563 TInt TNotReadyState::ScsiCommandFailed(CMassStorageFsm& aFsm)
   564     {
   565 	__MSFNLOG
   566     aFsm.SetState(TMassStorageState::ENotReadySenseState);
   567     return KErrNone;
   568     }
   569 
   570 
   571 /**
   572 
   573 */
   574 TNotReadySenseState::TNotReadySenseState()
   575 :   TMassStorageState(ENotReadySenseState)
   576     {
   577 	__MSFNLOG
   578     }
   579 
   580 
   581 TMassStorage::TEvent TNotReadySenseState::EntryL(CMassStorageFsm& aFsm)
   582     {
   583 	__MSFNLOG
   584     return aFsm.SenseL();
   585     }
   586 
   587 
   588 TInt TNotReadySenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
   589     {
   590 	__MSFNLOG
   591     const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
   592     TInt ret = KErrNone;
   593 
   594     if (senseInfo.iSenseCode == TSenseInfo::ENotReady &&
   595         senseInfo.iAdditional == TSenseInfo::EAscLogicalUnitNotReady &&
   596         senseInfo.iQualifier == TSenseInfo::EAscqInitializingCommandRequired)
   597         {
   598         aFsm.SetStartStopUnitRequired(ETrue);
   599         aFsm.SetState(TMassStorageState::EStartUnitState);
   600         }
   601     else
   602         {
   603         ret = TMassStorageState::SenseError(aFsm);
   604         }
   605 
   606     return ret;
   607     }
   608 
   609 
   610 TInt TNotReadySenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
   611     {
   612 	__MSFNLOG
   613     return TMassStorageState::SenseError(aFsm);
   614     }
   615 
   616 
   617 /**
   618 
   619 */
   620 TStartUnitState::TStartUnitState()
   621 :   TMassStorageState(EPreventRemovalState)
   622     {
   623 	__MSFNLOG
   624     }
   625 
   626 
   627 TMassStorage::TEvent TStartUnitState::EntryL(CMassStorageFsm& aFsm)
   628     {
   629 	__MSFNLOG
   630     return aFsm.StartStopUnitL(ETrue);
   631     }
   632 
   633 
   634 TInt TStartUnitState::ScsiCommandPassed(CMassStorageFsm& aFsm)
   635     {
   636 	__MSFNLOG
   637     if (aFsm.IsRemovableMedia())
   638         aFsm.SetState(TMassStorageState::EPreventRemovalState);
   639     else
   640         aFsm.SetState(TMassStorageState::EReadCapacityState);
   641     return KErrNone;
   642     }
   643 
   644 
   645 TInt TStartUnitState::ScsiCommandFailed(CMassStorageFsm& aFsm)
   646     {
   647 	__MSFNLOG
   648     aFsm.SetState(TMassStorageState::EPreventRemovalSenseState);
   649     return KErrNone;
   650     }
   651 
   652 /**
   653 
   654 */
   655 TStartUnitSenseState::TStartUnitSenseState()
   656 :   TMassStorageState(EPreventRemovalSenseState)
   657     {
   658 	__MSFNLOG
   659     }
   660 
   661 
   662 TMassStorage::TEvent TStartUnitSenseState::EntryL(CMassStorageFsm& aFsm)
   663     {
   664 	__MSFNLOG
   665     return aFsm.SenseL();
   666     }
   667 
   668 
   669 TInt TStartUnitSenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
   670     {
   671 	__MSFNLOG
   672     if (aFsm.IsRemovableMedia())
   673         aFsm.SetState(TMassStorageState::EPreventRemovalState);
   674     else
   675         aFsm.SetState(TMassStorageState::EReadCapacityState);
   676 
   677     return KErrNone;
   678     }
   679 
   680 
   681 TInt TStartUnitSenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
   682     {
   683 	__MSFNLOG
   684     TInt ret = KErrCompletion;
   685     const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
   686 
   687     aFsm.SetState(TMassStorageState::EInquiryState);
   688     if (senseInfo.iSenseCode == TSenseInfo::EIllegalRequest)
   689         {
   690         aFsm.SetState(TMassStorageState::EReadCapacityState);
   691         ret = KErrNone;
   692         }
   693     else
   694         {
   695         ret = TMassStorageState::SenseError(aFsm);
   696         }
   697 
   698     return ret;
   699     }
   700 
   701 
   702 /**
   703 
   704 */
   705 TPreventMediumRemovalState::TPreventMediumRemovalState()
   706 :   TMassStorageState(EPreventRemovalState)
   707     {
   708 	__MSFNLOG
   709     }
   710 
   711 
   712 TMassStorage::TEvent TPreventMediumRemovalState::EntryL(CMassStorageFsm& aFsm)
   713     {
   714 	__MSFNLOG
   715     return aFsm.PreventAllowMediumRemovalL(ETrue);
   716     }
   717 
   718 
   719 TInt TPreventMediumRemovalState::ScsiCommandPassed(CMassStorageFsm& aFsm)
   720     {
   721 	__MSFNLOG
   722     aFsm.SetState(TMassStorageState::EReadCapacityState);
   723     return KErrNone;
   724     }
   725 
   726 
   727 TInt TPreventMediumRemovalState::ScsiCommandFailed(CMassStorageFsm& aFsm)
   728     {
   729 	__MSFNLOG
   730     aFsm.SetState(TMassStorageState::EPreventRemovalSenseState);
   731     return KErrNone;
   732     }
   733 
   734 /**
   735 
   736 */
   737 TPreventMediumRemovalSenseState::TPreventMediumRemovalSenseState()
   738 :   TMassStorageState(EPreventRemovalSenseState)
   739     {
   740 	__MSFNLOG
   741     }
   742 
   743 
   744 TMassStorage::TEvent TPreventMediumRemovalSenseState::EntryL(CMassStorageFsm& aFsm)
   745     {
   746 	__MSFNLOG
   747     return aFsm.SenseL();
   748     }
   749 
   750 
   751 TInt TPreventMediumRemovalSenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
   752     {
   753 	__MSFNLOG
   754     aFsm.SetState(TMassStorageState::EReadCapacityState);
   755     return KErrNone;
   756     }
   757 
   758 
   759 
   760 
   761 TInt TPreventMediumRemovalSenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
   762     {
   763 	__MSFNLOG
   764     TInt ret = KErrCompletion;
   765     const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
   766 
   767     if (senseInfo.iSenseCode == TSenseInfo::EIllegalRequest)
   768         {
   769         aFsm.SetState(TMassStorageState::EReadCapacityState);
   770         ret = KErrNone;
   771         }
   772     else
   773         {
   774         ret = TMassStorageState::SenseError(aFsm);
   775         }
   776     return ret;
   777     }
   778 
   779 
   780 /**
   781 
   782 */
   783 TReadCapacity10State::TReadCapacity10State()
   784 :   TMassStorageState(EReadCapacityState)
   785     {
   786 	__MSFNLOG
   787     }
   788 
   789 
   790 TMassStorage::TEvent TReadCapacity10State::EntryL(CMassStorageFsm& aFsm)
   791     {
   792 	__MSFNLOG
   793     return aFsm.ReadCapacityL();
   794     };
   795 
   796 
   797 TInt TReadCapacity10State::ScsiCommandPassed(CMassStorageFsm& aFsm)
   798     {
   799 	__MSFNLOG
   800     aFsm.SetState(EModeSense10State);
   801     return KErrNone;
   802     };
   803 
   804 
   805 TInt TReadCapacity10State::ScsiCommandFailed(CMassStorageFsm& aFsm)
   806     {
   807 	__MSFNLOG
   808     aFsm.SetState(TMassStorageState::ESenseState);
   809     return KErrCompletion;
   810     }
   811 
   812 
   813 TInt TReadCapacity10State::ScsiCommandError(CMassStorageFsm& aFsm)
   814     {
   815 	__MSFNLOG
   816     aFsm.SetState(TMassStorageState::ENotReadyState);
   817     return KErrCompletion;
   818     }
   819 
   820 
   821 /**
   822 
   823 */
   824 TModeSense10State::TModeSense10State()
   825 :   TMassStorageState(EModeSense10State)
   826     {
   827 	__MSFNLOG
   828     }
   829 
   830 
   831 TMassStorage::TEvent TModeSense10State::EntryL(CMassStorageFsm& aFsm)
   832     {
   833 	__MSFNLOG
   834     return aFsm.ModeSense10L();
   835     };
   836 
   837 
   838 TInt TModeSense10State::ScsiCommandPassed(CMassStorageFsm& aFsm)
   839     {
   840 	__MSFNLOG
   841     aFsm.SetState(EConnectedState);
   842     return KErrCompletion;
   843     };
   844 
   845 
   846 TInt TModeSense10State::ScsiCommandFailed(CMassStorageFsm& aFsm)
   847     {
   848 	__MSFNLOG
   849     aFsm.SetState(EModeSense10SenseState);
   850     return KErrNone;
   851     }
   852 
   853 
   854 TInt TModeSense10State::ScsiCommandError(CMassStorageFsm& aFsm)
   855     {
   856 	__MSFNLOG
   857     aFsm.SetState(EModeSense6State);
   858     return KErrNone;
   859     }
   860 
   861 /**
   862 
   863 */
   864 TModeSense10SenseState::TModeSense10SenseState()
   865 :   TMassStorageState(EModeSense10SenseState)
   866     {
   867 	__MSFNLOG
   868     }
   869 
   870 
   871 TMassStorage::TEvent TModeSense10SenseState::EntryL(CMassStorageFsm& aFsm)
   872     {
   873 	__MSFNLOG
   874     return aFsm.SenseL();
   875     };
   876 
   877 
   878 TInt TModeSense10SenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
   879     {
   880 	__MSFNLOG
   881     TInt ret = KErrCompletion;
   882     const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
   883 
   884     aFsm.SetState(TMassStorageState::EInquiryState);
   885     if (senseInfo.iSenseCode == TSenseInfo::EIllegalRequest)
   886         {
   887         aFsm.SetState(TMassStorageState::EModeSense6State);
   888         ret = KErrNone;
   889         }
   890     else
   891         {
   892         ret = TMassStorageState::SenseError(aFsm);
   893         }
   894     return ret;
   895     };
   896 
   897 
   898 TInt TModeSense10SenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
   899     {
   900 	__MSFNLOG
   901     aFsm.SetState(EInquirySenseState);
   902     return KErrCompletion;
   903     }
   904 
   905 /**
   906 
   907 */
   908 TModeSense6State::TModeSense6State()
   909 :   TMassStorageState(EModeSense6State)
   910     {
   911 	__MSFNLOG
   912     }
   913 
   914 
   915 TMassStorage::TEvent TModeSense6State::EntryL(CMassStorageFsm& aFsm)
   916     {
   917 	__MSFNLOG
   918     return aFsm.ModeSense6L();
   919     };
   920 
   921 
   922 TInt TModeSense6State::ScsiCommandPassed(CMassStorageFsm& aFsm)
   923     {
   924 	__MSFNLOG
   925     aFsm.SetState(EConnectedState);
   926     return KErrCompletion;
   927     };
   928 
   929 
   930 TInt TModeSense6State::ScsiCommandFailed(CMassStorageFsm& aFsm)
   931     {
   932 	__MSFNLOG
   933     aFsm.SetState(EModeSense6SenseState);
   934     return KErrNone;
   935     }
   936 
   937 
   938 TInt TModeSense6State::ScsiCommandError(CMassStorageFsm& aFsm)
   939     {
   940 	__MSFNLOG
   941     // If device responds with protocol error, ignore the error and assume the
   942     // device is not write protected
   943     aFsm.SetState(EConnectedState);
   944     return KErrCompletion;
   945     }
   946 
   947 
   948 /**
   949 
   950 */
   951 TModeSense6SenseState::TModeSense6SenseState()
   952 :   TMassStorageState(EModeSense6SenseState)
   953     {
   954 	__MSFNLOG
   955     }
   956 
   957 
   958 TMassStorage::TEvent TModeSense6SenseState::EntryL(CMassStorageFsm& aFsm)
   959     {
   960 	__MSFNLOG
   961     return aFsm.SenseL();
   962     };
   963 
   964 
   965 TInt TModeSense6SenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
   966     {
   967 	__MSFNLOG
   968     TInt ret = KErrCompletion;
   969     const TSenseInfo& senseInfo = aFsm.MsSenseInfo();
   970 
   971     aFsm.SetState(TMassStorageState::EInquiryState);
   972     if (senseInfo.iSenseCode == TSenseInfo::EIllegalRequest)
   973         {
   974         aFsm.SetState(TMassStorageState::EConnectedState);
   975         }
   976     else
   977         {
   978         ret = TMassStorageState::SenseError(aFsm);
   979         }
   980     return ret;
   981     };
   982 
   983 
   984 TInt TModeSense6SenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
   985     {
   986 	__MSFNLOG
   987     aFsm.SetState(EInquirySenseState);
   988     return KErrCompletion;
   989     }
   990 
   991 
   992 
   993 /**
   994 
   995 */
   996 TConnectedState::TConnectedState()
   997 :   TMassStorageState(EConnectedState)
   998     {
   999 	__MSFNLOG
  1000     }
  1001 
  1002 
  1003 TMassStorage::TEvent TConnectedState::EntryL(CMassStorageFsm& /* aFsm */)
  1004     {
  1005 	__MSFNLOG
  1006     return TMassStorage::EEvCommandPassed;
  1007     };
  1008 
  1009 
  1010 TInt TConnectedState::ScsiCommandPassed(CMassStorageFsm& aFsm)
  1011     {
  1012 	__MSFNLOG
  1013     TInt ret = KErrNone;
  1014 
  1015     if (aFsm.IsRemovableMedia())
  1016         {
  1017 		if(aFsm.IsStatusCheck())
  1018 			{
  1019 			aFsm.SetState(TMassStorageState::EStatusCheckState);
  1020 			}
  1021 		else
  1022             {
  1023             aFsm.SetState(TMassStorageState::EAllowRemovalState);
  1024             }
  1025         }
  1026     else if (aFsm.StartStopUnitRequired())
  1027         {
  1028         aFsm.SetState(TMassStorageState::EStopUnitState);
  1029         }
  1030     else
  1031         {
  1032 		aFsm.SetState(TMassStorageState::ENotReadyState);
  1033 		ret = KErrCompletion;
  1034         }
  1035     return ret;
  1036     };
  1037 
  1038 
  1039 TInt TConnectedState::ScsiCommandFailed(CMassStorageFsm& aFsm)
  1040     {
  1041 	__MSFNLOG
  1042     aFsm.SetState(TMassStorageState::EInquiryState);
  1043     return KErrCompletion;
  1044     }
  1045 
  1046 
  1047 /**
  1048 
  1049 */
  1050 TStatusCheckState::TStatusCheckState()
  1051 :   TMassStorageState(EStatusCheckState)
  1052     {
  1053 	__MSFNLOG
  1054     }
  1055 
  1056 
  1057 TMassStorage::TEvent TStatusCheckState::EntryL(CMassStorageFsm& aFsm)
  1058     {
  1059 	__MSFNLOG
  1060     return aFsm.TestUnitReadyL();
  1061     };
  1062 
  1063 
  1064 TInt TStatusCheckState::ScsiCommandPassed(CMassStorageFsm& aFsm)
  1065     {
  1066 	__MSFNLOG
  1067     aFsm.SetState(EConnectedState);
  1068     return KErrCompletion;
  1069     };
  1070 
  1071 
  1072 TInt TStatusCheckState::ScsiCommandFailed(CMassStorageFsm& aFsm)
  1073     {
  1074 	__MSFNLOG
  1075 	aFsm.SetState(ESenseState);
  1076     return KErrNone;
  1077     }
  1078 
  1079 
  1080 /**
  1081 
  1082 */
  1083 TAllowMediumRemovalState::TAllowMediumRemovalState()
  1084 :   TMassStorageState(EAllowRemovalState)
  1085     {
  1086 	__MSFNLOG
  1087     }
  1088 
  1089 
  1090 TMassStorage::TEvent TAllowMediumRemovalState::EntryL(CMassStorageFsm& aFsm)
  1091     {
  1092 	__MSFNLOG
  1093     return aFsm.PreventAllowMediumRemovalL(EFalse);
  1094     }
  1095 
  1096 
  1097 TInt TAllowMediumRemovalState::ScsiCommandPassed(CMassStorageFsm& aFsm)
  1098     {
  1099 	__MSFNLOG
  1100     TInt ret = KErrNone;
  1101     if (aFsm.StartStopUnitRequired())
  1102         {
  1103         aFsm.SetState(TMassStorageState::EStopUnitState);
  1104         }
  1105     else
  1106         {
  1107         aFsm.SetState(ENotReadyState);
  1108         ret = KErrCompletion;
  1109         }
  1110     return ret;
  1111     };
  1112 
  1113 
  1114 TInt TAllowMediumRemovalState::ScsiCommandFailed(CMassStorageFsm& aFsm)
  1115     {
  1116 	__MSFNLOG
  1117     aFsm.SetState(TMassStorageState::EInquiryState);
  1118     return KErrCompletion;
  1119     }
  1120 
  1121 
  1122 /**
  1123 
  1124 */
  1125 TStopUnitState::TStopUnitState()
  1126 :   TMassStorageState(EStopUnitState)
  1127     {
  1128 	__MSFNLOG
  1129     }
  1130 
  1131 
  1132 TMassStorage::TEvent TStopUnitState::EntryL(CMassStorageFsm& aFsm)
  1133     {
  1134 	__MSFNLOG
  1135     return aFsm.StartStopUnitL(EFalse);
  1136     }
  1137 
  1138 
  1139 TInt TStopUnitState::ScsiCommandPassed(CMassStorageFsm& aFsm)
  1140     {
  1141 	__MSFNLOG
  1142     aFsm.SetState(ENotReadyState);
  1143     return KErrCompletion;
  1144     };
  1145 
  1146 
  1147 TInt TStopUnitState::ScsiCommandFailed(CMassStorageFsm& aFsm)
  1148     {
  1149 	__MSFNLOG
  1150     aFsm.SetState(TMassStorageState::EInquiryState);
  1151     return KErrCompletion;
  1152     }
  1153 
  1154 
  1155 /**
  1156 
  1157 */
  1158 TSenseState::TSenseState()
  1159 :   TMassStorageState(EConnectedState)
  1160     {
  1161 	__MSFNLOG
  1162     }
  1163 
  1164 
  1165 TMassStorage::TEvent TSenseState::EntryL(CMassStorageFsm& aFsm)
  1166     {
  1167 	__MSFNLOG
  1168     return aFsm.SenseL();
  1169     };
  1170 
  1171 
  1172 TInt TSenseState::ScsiCommandPassed(CMassStorageFsm& aFsm)
  1173     {
  1174 	__MSFNLOG
  1175     aFsm.SetState(ENotReadyState);
  1176     return KErrCompletion;
  1177     };
  1178 
  1179 
  1180 TInt TSenseState::ScsiCommandFailed(CMassStorageFsm& aFsm)
  1181     {
  1182 	__MSFNLOG
  1183     // This event should not happen
  1184     aFsm.SetState(EInquiryState);
  1185     return KErrCompletion;
  1186     }
  1187