os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/server/protocol/include/cscsiprotocol.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/server/protocol/include/cscsiprotocol.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,189 @@
     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 +#ifndef CSCSIPROTOCOL_H
    1.25 +#define CSCSIPROTOCOL_H
    1.26 +
    1.27 +class CMassStorageFsm;
    1.28 +
    1.29 +class TSbcClientInterface;
    1.30 +
    1.31 +class RMediaChangeNotifier
    1.32 +    {
    1.33 +public:
    1.34 +    RMediaChangeNotifier();
    1.35 +    ~RMediaChangeNotifier();
    1.36 +
    1.37 +	void Register(const RMessage2& aMessage);
    1.38 +    void DoNotifyL();
    1.39 +    void DoCancelL();
    1.40 +
    1.41 +private:
    1.42 +	void CompleteNotifierL(TInt);
    1.43 +
    1.44 +private:
    1.45 +    /** Notification service */
    1.46 +	RMessage2 iNotifier;
    1.47 +    /** Flag to indicate that media change notification is active */
    1.48 +	TBool iRegistered;
    1.49 +    };
    1.50 +
    1.51 +
    1.52 +/**
    1.53 +SCSI Protocol procedures
    1.54 +*/
    1.55 +class CScsiProtocol: public CBase, public MProtocol, public MBlockTransferProtocol
    1.56 +    {
    1.57 +public:
    1.58 +   /** SCSI state */
    1.59 +   enum TScsiState
    1.60 +        {
    1.61 +        EConnected,
    1.62 +        EDisconnected
    1.63 +        };
    1.64 +
    1.65 +    static CScsiProtocol* NewL(TLun aLun, MTransport& aTransport);
    1.66 +	~CScsiProtocol();
    1.67 +private:
    1.68 +    void ConstructL(TLun aLun);
    1.69 +	CScsiProtocol(MTransport& aTransport);
    1.70 +
    1.71 +public:
    1.72 +    void InitialiseUnitL();
    1.73 +
    1.74 +    // Stop unit command to uninitialise the lun
    1.75 +    void UninitialiseUnitL();
    1.76 +
    1.77 +    // Read command to read the media
    1.78 +    void ReadL(TPos aPos, TDes8& aCopybuf, TInt aLen);
    1.79 +
    1.80 +    // Write command to write to the media
    1.81 +    void WriteL(TPos aPos, TDesC8& aCopybuf, TInt aLen);
    1.82 +
    1.83 +    // ReadCapacity command to find the capacity of the media
    1.84 +    void GetCapacityL(TCapsInfo& aCapsInfo);
    1.85 +
    1.86 +    // unit testing
    1.87 +    void CreateSbcInterfaceL(TUint32 aBlockLen, TUint32 aLastLba);
    1.88 +
    1.89 +	void DoScsiReadyCheckEventL();
    1.90 +
    1.91 +	void NotifyChange(const RMessage2& aMessage);
    1.92 +    void ForceCompleteNotifyChangeL();
    1.93 +    void CancelChangeNotifierL();
    1.94 +	void CompleteNotifyChangeL();
    1.95 +	void SuspendL();
    1.96 +	void ResumeL();
    1.97 +    TBool IsConnected();
    1.98 +
    1.99 +    // Supported Mass Storage commands
   1.100 +    TInt MsInquiryL();
   1.101 +    TInt MsTestUnitReadyL();
   1.102 +    TInt MsStartStopUnitL(TBool aStart);
   1.103 +    TInt MsPreventAllowMediaRemovalL(TBool aPrevent);
   1.104 +
   1.105 +    TInt MsReadCapacityL();
   1.106 +    TInt MsModeSense10L();
   1.107 +    TInt MsModeSense6L();
   1.108 +
   1.109 +    TInt MsRequestSenseL();
   1.110 +
   1.111 +    TBool MsIsSbcSet() const;
   1.112 +    TBool MsIsRemovableMedia() const;
   1.113 +    const TSenseInfo& MsSenseInfo() const;
   1.114 +
   1.115 +    // MBlockTransferProtocol interface
   1.116 +    void BlockReadL(TPos aPos, TDes8& aBuf, TInt aLength);
   1.117 +    void BlockWriteL(TPos aPos, TDesC8& aBuf, TUint aOffset, TInt aLength);
   1.118 +
   1.119 +private:
   1.120 +    void ResetSbc();
   1.121 +
   1.122 +    void DoCheckConditionL();
   1.123 +
   1.124 +	TInt GetSystemWideSenseError(const TSenseInfo& aSenseInfo);
   1.125 +	TInt ProcessAsCodes(const TSenseInfo& aSenseInfo);
   1.126 +
   1.127 +private:
   1.128 +
   1.129 +    /** State machine for device initialisation protocol */
   1.130 +    CMassStorageFsm* iFsm;
   1.131 +
   1.132 +    /** SCSI SPC interface methods */
   1.133 +    TSpcClientInterface iSpcInterface;
   1.134 +    /** SCSI SBC interface methods */
   1.135 +    TSbcClientInterface* iSbcInterface;
   1.136 +    // buffers for block manipulation (for use in iSbcInterface)
   1.137 +    RBuf8 iHeadbuf;
   1.138 +	RBuf8 iTailbuf;    		
   1.139 +
   1.140 +    // Logical Unit properties
   1.141 +    /** LU removable */
   1.142 +    TBool iRemovableMedia;
   1.143 +    /** LU write protected */
   1.144 +    TBool iWriteProtect;
   1.145 +
   1.146 +    /** Result of the last SCSI command */
   1.147 +    TSenseInfo iSenseInfo;
   1.148 +
   1.149 +    /** State of the LUN represented by this object */
   1.150 +	TScsiState iState;
   1.151 +
   1.152 +    /** Notifier for media changes */
   1.153 +    RMediaChangeNotifier iMediaChangeNotifier;
   1.154 +    };
   1.155 +
   1.156 +
   1.157 +/**
   1.158 +Returns the state of the SBC interface. INQUIRY command is used to detect if
   1.159 +device supports SBC and initialise the SBC interface.
   1.160 +
   1.161 +@return TBool ETrue is SBC interface is initialised
   1.162 +*/
   1.163 +inline TBool CScsiProtocol::MsIsSbcSet() const
   1.164 +    {
   1.165 +    return iSbcInterface ? ETrue : EFalse;
   1.166 +    }
   1.167 +
   1.168 +/**
   1.169 +Returns the device removable property. MODE SENSE command is used to detect if
   1.170 +the device is removable.
   1.171 +
   1.172 +@return TBool ETrue if device is removable
   1.173 +*/
   1.174 +inline TBool CScsiProtocol::MsIsRemovableMedia() const
   1.175 +    {
   1.176 +    return iRemovableMedia;
   1.177 +    }
   1.178 +
   1.179 +
   1.180 +/**
   1.181 +Helper to return current SenseInfo. SCSI REQUEST SENSE command sets the sense
   1.182 +info. The protocol will retrieve device's sense info in the event of a SCSI
   1.183 +command error.
   1.184 +
   1.185 +@return const TSenseInfo&
   1.186 +*/
   1.187 +inline const TSenseInfo& CScsiProtocol::MsSenseInfo() const
   1.188 +    {
   1.189 +    return iSenseInfo;
   1.190 +    }
   1.191 +
   1.192 +#endif // CSCSIPROTOCOL_H