userlibandfileserver/fileserver/shostmassstorage/server/protocol/include/cscsiprotocol.h
changeset 0 a41df078684a
child 31 56f325a607ea
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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 #ifndef CSCSIPROTOCOL_H
       
    22 #define CSCSIPROTOCOL_H
       
    23 
       
    24 class CMassStorageFsm;
       
    25 
       
    26 class TSbcClientInterface;
       
    27 
       
    28 class RMediaChangeNotifier
       
    29     {
       
    30 public:
       
    31     RMediaChangeNotifier();
       
    32     ~RMediaChangeNotifier();
       
    33 
       
    34 	void Register(const RMessage2& aMessage);
       
    35     void DoNotifyL();
       
    36     void DoCancelL();
       
    37 
       
    38 private:
       
    39 	void CompleteNotifierL(TInt);
       
    40 
       
    41 private:
       
    42     /** Notification service */
       
    43 	RMessage2 iNotifier;
       
    44     /** Flag to indicate that media change notification is active */
       
    45 	TBool iRegistered;
       
    46     };
       
    47 
       
    48 
       
    49 /**
       
    50 SCSI Protocol procedures
       
    51 */
       
    52 class CScsiProtocol: public CBase, public MProtocol, public MBlockTransferProtocol
       
    53     {
       
    54 public:
       
    55    /** SCSI state */
       
    56    enum TScsiState
       
    57         {
       
    58         EConnected,
       
    59         EDisconnected
       
    60         };
       
    61 
       
    62     static CScsiProtocol* NewL(TLun aLun, MTransport& aTransport);
       
    63 	~CScsiProtocol();
       
    64 private:
       
    65     void ConstructL(TLun aLun);
       
    66 	CScsiProtocol(MTransport& aTransport);
       
    67 
       
    68 public:
       
    69     void InitialiseUnitL();
       
    70 
       
    71     // Stop unit command to uninitialise the lun
       
    72     void UninitialiseUnitL();
       
    73 
       
    74     // Read command to read the media
       
    75     void ReadL(TPos aPos, TDes8& aCopybuf, TInt aLen);
       
    76 
       
    77     // Write command to write to the media
       
    78     void WriteL(TPos aPos, TDesC8& aCopybuf, TInt aLen);
       
    79 
       
    80     // ReadCapacity command to find the capacity of the media
       
    81     void GetCapacityL(TCapsInfo& aCapsInfo);
       
    82 
       
    83     // unit testing
       
    84     void CreateSbcInterfaceL(TUint32 aBlockLen, TUint32 aLastLba);
       
    85 
       
    86 	void DoScsiReadyCheckEventL();
       
    87 
       
    88 	void NotifyChange(const RMessage2& aMessage);
       
    89     void ForceCompleteNotifyChangeL();
       
    90     void CancelChangeNotifierL();
       
    91 	void CompleteNotifyChangeL();
       
    92 	void SuspendL();
       
    93 	void ResumeL();
       
    94     TBool IsConnected();
       
    95 
       
    96     // Supported Mass Storage commands
       
    97     TInt MsInquiryL();
       
    98     TInt MsTestUnitReadyL();
       
    99     TInt MsStartStopUnitL(TBool aStart);
       
   100     TInt MsPreventAllowMediaRemovalL(TBool aPrevent);
       
   101 
       
   102     TInt MsReadCapacityL();
       
   103     TInt MsModeSense10L();
       
   104     TInt MsModeSense6L();
       
   105 
       
   106     TInt MsRequestSenseL();
       
   107 
       
   108     TBool MsIsSbcSet() const;
       
   109     TBool MsIsRemovableMedia() const;
       
   110     const TSenseInfo& MsSenseInfo() const;
       
   111 
       
   112     // MBlockTransferProtocol interface
       
   113     void BlockReadL(TPos aPos, TDes8& aBuf, TInt aLength);
       
   114     void BlockWriteL(TPos aPos, TDesC8& aBuf, TUint aOffset, TInt aLength);
       
   115 
       
   116 private:
       
   117     void ResetSbc();
       
   118 
       
   119     void DoCheckConditionL();
       
   120 
       
   121 	TInt GetSystemWideSenseError(const TSenseInfo& aSenseInfo);
       
   122 	TInt ProcessAsCodes(const TSenseInfo& aSenseInfo);
       
   123 
       
   124 private:
       
   125 
       
   126     /** State machine for device initialisation protocol */
       
   127     CMassStorageFsm* iFsm;
       
   128 
       
   129     /** SCSI SPC interface methods */
       
   130     TSpcClientInterface iSpcInterface;
       
   131     /** SCSI SBC interface methods */
       
   132     TSbcClientInterface* iSbcInterface;
       
   133 
       
   134     // Logical Unit properties
       
   135     /** LU removable */
       
   136     TBool iRemovableMedia;
       
   137     /** LU write protected */
       
   138     TBool iWriteProtect;
       
   139 
       
   140     /** Result of the last SCSI command */
       
   141     TSenseInfo iSenseInfo;
       
   142 
       
   143     /** State of the LUN represented by this object */
       
   144 	TScsiState iState;
       
   145 
       
   146     /** Notifier for media changes */
       
   147     RMediaChangeNotifier iMediaChangeNotifier;
       
   148     };
       
   149 
       
   150 
       
   151 /**
       
   152 Returns the state of the SBC interface. INQUIRY command is used to detect if
       
   153 device supports SBC and initialise the SBC interface.
       
   154 
       
   155 @return TBool ETrue is SBC interface is initialised
       
   156 */
       
   157 inline TBool CScsiProtocol::MsIsSbcSet() const
       
   158     {
       
   159     return iSbcInterface ? ETrue : EFalse;
       
   160     }
       
   161 
       
   162 /**
       
   163 Returns the device removable property. MODE SENSE command is used to detect if
       
   164 the device is removable.
       
   165 
       
   166 @return TBool ETrue if device is removable
       
   167 */
       
   168 inline TBool CScsiProtocol::MsIsRemovableMedia() const
       
   169     {
       
   170     return iRemovableMedia;
       
   171     }
       
   172 
       
   173 
       
   174 /**
       
   175 Helper to return current SenseInfo. SCSI REQUEST SENSE command sets the sense
       
   176 info. The protocol will retrieve device's sense info in the event of a SCSI
       
   177 command error.
       
   178 
       
   179 @return const TSenseInfo&
       
   180 */
       
   181 inline const TSenseInfo& CScsiProtocol::MsSenseInfo() const
       
   182     {
       
   183     return iSenseInfo;
       
   184     }
       
   185 
       
   186 #endif // CSCSIPROTOCOL_H