os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/server/protocol/include/cscsiprotocol.h
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 #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     // buffers for block manipulation (for use in iSbcInterface)
   134     RBuf8 iHeadbuf;
   135 	RBuf8 iTailbuf;    		
   136 
   137     // Logical Unit properties
   138     /** LU removable */
   139     TBool iRemovableMedia;
   140     /** LU write protected */
   141     TBool iWriteProtect;
   142 
   143     /** Result of the last SCSI command */
   144     TSenseInfo iSenseInfo;
   145 
   146     /** State of the LUN represented by this object */
   147 	TScsiState iState;
   148 
   149     /** Notifier for media changes */
   150     RMediaChangeNotifier iMediaChangeNotifier;
   151     };
   152 
   153 
   154 /**
   155 Returns the state of the SBC interface. INQUIRY command is used to detect if
   156 device supports SBC and initialise the SBC interface.
   157 
   158 @return TBool ETrue is SBC interface is initialised
   159 */
   160 inline TBool CScsiProtocol::MsIsSbcSet() const
   161     {
   162     return iSbcInterface ? ETrue : EFalse;
   163     }
   164 
   165 /**
   166 Returns the device removable property. MODE SENSE command is used to detect if
   167 the device is removable.
   168 
   169 @return TBool ETrue if device is removable
   170 */
   171 inline TBool CScsiProtocol::MsIsRemovableMedia() const
   172     {
   173     return iRemovableMedia;
   174     }
   175 
   176 
   177 /**
   178 Helper to return current SenseInfo. SCSI REQUEST SENSE command sets the sense
   179 info. The protocol will retrieve device's sense info in the event of a SCSI
   180 command error.
   181 
   182 @return const TSenseInfo&
   183 */
   184 inline const TSenseInfo& CScsiProtocol::MsSenseInfo() const
   185     {
   186     return iSenseInfo;
   187     }
   188 
   189 #endif // CSCSIPROTOCOL_H