sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #ifndef CSCSIPROTOCOL_H sl@0: #define CSCSIPROTOCOL_H sl@0: sl@0: class CMassStorageFsm; sl@0: sl@0: class TSbcClientInterface; sl@0: sl@0: class RMediaChangeNotifier sl@0: { sl@0: public: sl@0: RMediaChangeNotifier(); sl@0: ~RMediaChangeNotifier(); sl@0: sl@0: void Register(const RMessage2& aMessage); sl@0: void DoNotifyL(); sl@0: void DoCancelL(); sl@0: sl@0: private: sl@0: void CompleteNotifierL(TInt); sl@0: sl@0: private: sl@0: /** Notification service */ sl@0: RMessage2 iNotifier; sl@0: /** Flag to indicate that media change notification is active */ sl@0: TBool iRegistered; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: SCSI Protocol procedures sl@0: */ sl@0: class CScsiProtocol: public CBase, public MProtocol, public MBlockTransferProtocol sl@0: { sl@0: public: sl@0: /** SCSI state */ sl@0: enum TScsiState sl@0: { sl@0: EConnected, sl@0: EDisconnected sl@0: }; sl@0: sl@0: static CScsiProtocol* NewL(TLun aLun, MTransport& aTransport); sl@0: ~CScsiProtocol(); sl@0: private: sl@0: void ConstructL(TLun aLun); sl@0: CScsiProtocol(MTransport& aTransport); sl@0: sl@0: public: sl@0: void InitialiseUnitL(); sl@0: sl@0: // Stop unit command to uninitialise the lun sl@0: void UninitialiseUnitL(); sl@0: sl@0: // Read command to read the media sl@0: void ReadL(TPos aPos, TDes8& aCopybuf, TInt aLen); sl@0: sl@0: // Write command to write to the media sl@0: void WriteL(TPos aPos, TDesC8& aCopybuf, TInt aLen); sl@0: sl@0: // ReadCapacity command to find the capacity of the media sl@0: void GetCapacityL(TCapsInfo& aCapsInfo); sl@0: sl@0: // unit testing sl@0: void CreateSbcInterfaceL(TUint32 aBlockLen, TUint32 aLastLba); sl@0: sl@0: void DoScsiReadyCheckEventL(); sl@0: sl@0: void NotifyChange(const RMessage2& aMessage); sl@0: void ForceCompleteNotifyChangeL(); sl@0: void CancelChangeNotifierL(); sl@0: void CompleteNotifyChangeL(); sl@0: void SuspendL(); sl@0: void ResumeL(); sl@0: TBool IsConnected(); sl@0: sl@0: // Supported Mass Storage commands sl@0: TInt MsInquiryL(); sl@0: TInt MsTestUnitReadyL(); sl@0: TInt MsStartStopUnitL(TBool aStart); sl@0: TInt MsPreventAllowMediaRemovalL(TBool aPrevent); sl@0: sl@0: TInt MsReadCapacityL(); sl@0: TInt MsModeSense10L(); sl@0: TInt MsModeSense6L(); sl@0: sl@0: TInt MsRequestSenseL(); sl@0: sl@0: TBool MsIsSbcSet() const; sl@0: TBool MsIsRemovableMedia() const; sl@0: const TSenseInfo& MsSenseInfo() const; sl@0: sl@0: // MBlockTransferProtocol interface sl@0: void BlockReadL(TPos aPos, TDes8& aBuf, TInt aLength); sl@0: void BlockWriteL(TPos aPos, TDesC8& aBuf, TUint aOffset, TInt aLength); sl@0: sl@0: private: sl@0: void ResetSbc(); sl@0: sl@0: void DoCheckConditionL(); sl@0: sl@0: TInt GetSystemWideSenseError(const TSenseInfo& aSenseInfo); sl@0: TInt ProcessAsCodes(const TSenseInfo& aSenseInfo); sl@0: sl@0: private: sl@0: sl@0: /** State machine for device initialisation protocol */ sl@0: CMassStorageFsm* iFsm; sl@0: sl@0: /** SCSI SPC interface methods */ sl@0: TSpcClientInterface iSpcInterface; sl@0: /** SCSI SBC interface methods */ sl@0: TSbcClientInterface* iSbcInterface; sl@0: // buffers for block manipulation (for use in iSbcInterface) sl@0: RBuf8 iHeadbuf; sl@0: RBuf8 iTailbuf; sl@0: sl@0: // Logical Unit properties sl@0: /** LU removable */ sl@0: TBool iRemovableMedia; sl@0: /** LU write protected */ sl@0: TBool iWriteProtect; sl@0: sl@0: /** Result of the last SCSI command */ sl@0: TSenseInfo iSenseInfo; sl@0: sl@0: /** State of the LUN represented by this object */ sl@0: TScsiState iState; sl@0: sl@0: /** Notifier for media changes */ sl@0: RMediaChangeNotifier iMediaChangeNotifier; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: Returns the state of the SBC interface. INQUIRY command is used to detect if sl@0: device supports SBC and initialise the SBC interface. sl@0: sl@0: @return TBool ETrue is SBC interface is initialised sl@0: */ sl@0: inline TBool CScsiProtocol::MsIsSbcSet() const sl@0: { sl@0: return iSbcInterface ? ETrue : EFalse; sl@0: } sl@0: sl@0: /** sl@0: Returns the device removable property. MODE SENSE command is used to detect if sl@0: the device is removable. sl@0: sl@0: @return TBool ETrue if device is removable sl@0: */ sl@0: inline TBool CScsiProtocol::MsIsRemovableMedia() const sl@0: { sl@0: return iRemovableMedia; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Helper to return current SenseInfo. SCSI REQUEST SENSE command sets the sense sl@0: info. The protocol will retrieve device's sense info in the event of a SCSI sl@0: command error. sl@0: sl@0: @return const TSenseInfo& sl@0: */ sl@0: inline const TSenseInfo& CScsiProtocol::MsSenseInfo() const sl@0: { sl@0: return iSenseInfo; sl@0: } sl@0: sl@0: #endif // CSCSIPROTOCOL_H