sl@0: /* sl@0: * Copyright (c) 2007-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: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: @released sl@0: */ sl@0: #ifndef __CRYPTOLDD__ sl@0: #define __CRYPTOLDD__ sl@0: #include sl@0: #include sl@0: #include sl@0: #include "cryptojobs.h" sl@0: sl@0: sl@0: class DCryptoLddChannelFactory : public DLogicalDevice sl@0: { sl@0: public: sl@0: DCryptoLddChannelFactory(); sl@0: ~DCryptoLddChannelFactory(); sl@0: virtual TInt Install(); sl@0: virtual void GetCaps(TDes8& aDes) const; sl@0: virtual TInt Create(DLogicalChannelBase*& aChannel); sl@0: sl@0: // The job scheduler for the Random h/w sl@0: DCryptoJobScheduler iJSRandom; sl@0: sl@0: // The job scheduler for the AES h/w sl@0: DCryptoJobScheduler iJSAes; sl@0: }; sl@0: sl@0: class DCryptoPddChannel; sl@0: /** sl@0: Logical Channel classes for 'Crypto' sl@0: */ sl@0: sl@0: /** sl@0: DLddChanRandom sl@0: sl@0: This class just exists to keep all the LDD Chan variables for sl@0: dealing with Random requests in one place. sl@0: */ sl@0: class DCryptoLddChannel; sl@0: class DLddChanRandom : public DBase, public MCryptoJobCallbacks sl@0: { sl@0: public: sl@0: DLddChanRandom(DCryptoLddChannel &aParent); sl@0: // Cleanup must be done by DCryptoLddChannel destructor because sl@0: // by the time our destructor gets called the DCryptoLddChannel sl@0: // has already been destroyed. sl@0: sl@0: // Functions are virtual so PDD can call them via a vtable instead sl@0: // of linking directly to them. sl@0: sl@0: virtual TInt Random(TRequestStatus* aStatus,TDes8* aBuffer); sl@0: sl@0: // Callbacks for PDD sl@0: virtual TInt DataRequired(); sl@0: virtual TInt DataAvailable(); sl@0: virtual void JobComplete(TInt aResult); sl@0: sl@0: /** sl@0: Cancel a user request sl@0: */ sl@0: virtual void RandomCancel(); sl@0: private: sl@0: DCryptoLddChannel &iParent; sl@0: // Members used for processing a Random request sl@0: sl@0: TRequestStatus* iRandomStatus; // User request sl@0: TDes8* iRandomDescriptor; // User descriptor sl@0: TInt iRequestLength; sl@0: TInt iCurrentIndex; sl@0: sl@0: CryptoJobRandom *iJob; // Ptr to PDD Random job (not owned by us) sl@0: }; sl@0: sl@0: /** sl@0: DLddChanAes sl@0: sl@0: This class just exists to keep all the LDD Chan variables for sl@0: dealing with Aes requests in one place. sl@0: */ sl@0: class DCryptoLddChannel; sl@0: class DLddChanAes : public DBase, public MCryptoJobCallbacks sl@0: { sl@0: public: sl@0: DLddChanAes(DCryptoLddChannel &aParent); sl@0: // Cleanup must be done by DCryptoLddChannel destructor because sl@0: // by the time our destructor gets called the DCryptoLddChannel sl@0: // has already been destroyed. sl@0: sl@0: // Functions are virtual so PDD can call them via a vtable instead sl@0: // of linking directly to them. sl@0: sl@0: virtual TInt SetAesConfig(const TDesC8 *aConfigBuf); sl@0: virtual TInt AesWrite(TRequestStatus *aStatus, TDesC8 *aBuffer); sl@0: virtual TInt AesRead(TRequestStatus *aStatus, TDes8 *aBuffer, TUint32 aLength); sl@0: sl@0: // Callbacks for PDD sl@0: virtual TInt DataRequired(); sl@0: virtual TInt DataAvailable(); sl@0: virtual void JobComplete(TInt aResult); sl@0: sl@0: /** sl@0: Cancel a user request sl@0: */ sl@0: virtual void CancelRead(); sl@0: virtual void CancelWrite(); sl@0: private: sl@0: DCryptoLddChannel &iParent; sl@0: // Members used for processing a Aes request sl@0: sl@0: TRequestStatus *iAesWriteStatus; // User request sl@0: TDesC8 *iAesWriteDescriptor; // User descriptor sl@0: TInt iWriteRequestLength; sl@0: TInt iCurrentUserWriteIndex; sl@0: sl@0: TRequestStatus *iAesReadStatus; // User request sl@0: TDes8 *iAesReadDescriptor; // User descriptor sl@0: TInt iReadRequestLength; sl@0: TInt iOriginalUserReadDescLength; sl@0: TInt iCurrentUserReadIndex; sl@0: sl@0: TBool iEncrypt; sl@0: RCryptoDriver::TChainingMode iMode; sl@0: TInt iKeyLengthBytes; sl@0: sl@0: CryptoJobAes *iJob; // Ptr to PDD AES job (not owned by us) sl@0: }; sl@0: sl@0: sl@0: class DCryptoLddChannel : public DLogicalChannel sl@0: { sl@0: public: sl@0: DCryptoLddChannel(); sl@0: virtual ~DCryptoLddChannel(); sl@0: // Inherited from DObject sl@0: virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType); sl@0: // Inherited from DLogicalChannelBase sl@0: virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); sl@0: // Inherited from DLogicalChannel sl@0: virtual void HandleMsg(TMessageBase* aMsg); sl@0: sl@0: // Accessor for the LDD Factory sl@0: inline DCryptoLddChannelFactory *LddFactory() const; sl@0: sl@0: DLddChanRandom iLddChanRandom; sl@0: DLddChanAes iLddChanAes; sl@0: sl@0: private: sl@0: friend class DLddChanRandom; sl@0: friend class DLddChanAes; sl@0: sl@0: // Panic reasons sl@0: enum TPanic sl@0: { sl@0: ERequestAlreadyPending = 1 sl@0: }; sl@0: // Implementation for the differnt kinds of requests send through RBusLogicalChannel sl@0: TInt DoControl(TInt aFunction, TAny* a1, TAny* a2); sl@0: TInt DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2); sl@0: void DoCancel(TUint aMask); sl@0: sl@0: // Accessor for the PDD sl@0: inline DCryptoPddChannel* PddChan() const; sl@0: sl@0: // Query h/w versions sl@0: TInt GetHwVersions(TDes8* aHwVersionsBuf) const; sl@0: sl@0: // Methods for configuration sl@0: TInt GetConfig(TDes8* aConfigBuf) const; sl@0: TInt SetConfig(const TDesC8* aConfigBuf); sl@0: void CurrentConfig(RCryptoDriver::TConfig& aConfig) const; sl@0: sl@0: private: sl@0: DThread* iClient; sl@0: }; sl@0: inline DCryptoLddChannelFactory *DCryptoLddChannel::LddFactory() const sl@0: { sl@0: return static_cast(iDevice); sl@0: } sl@0: sl@0: sl@0: class DCryptoPddChannel : public DBase sl@0: { sl@0: public: sl@0: virtual TDfcQue* DfcQue() = 0; sl@0: sl@0: virtual void GetHwVersions(RCryptoDriver::THwVersions& aHwVersions) const = 0; sl@0: virtual TInt FakeDriverSetting() const = 0; sl@0: virtual TInt SetFakeDriverSetting(TInt aFakeDriverSetting) = 0; sl@0: sl@0: virtual CryptoJobRandom *GetJobRandom(TBool aAutoCreate = ETrue) = 0; sl@0: virtual CryptoJobAes *GetJobAes(TBool aAutoCreate = ETrue) = 0; sl@0: sl@0: // The LDD chan needs to be able to set this, and the Job sl@0: // implementation classes need to be able to read it, so there is sl@0: // no point in having accessor functions for it... sl@0: DCryptoLddChannel *iCryptoLddChannel; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: inline DCryptoPddChannel* DCryptoLddChannel::PddChan() const sl@0: { sl@0: return static_cast(iPdd); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: #endif