emulator/emulatorbsp/specific/sdcard/sdcard4c/pp_cprm.h
changeset 0 cec860690d41
equal deleted inserted replaced
-1:000000000000 0:cec860690d41
       
     1 // Copyright (c) 2000-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 "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 // PP_SDC.H
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef __PP_CPRM_H__
       
    19 #define __PP_CPRM_H__
       
    20 #if defined(_UNICODE) && !defined(UNICODE)
       
    21 	#define UNICODE
       
    22 #endif
       
    23 
       
    24 #include <cprm.h>
       
    25 #include <emulator.h>
       
    26 
       
    27 GLREF_C TInt MapLastErrorEpoc();
       
    28 GLREF_C TMMCErr MapLastErrorMmc();
       
    29 
       
    30 const TInt KMediaChangeTickInterval=20000;	// Units 1uS
       
    31 
       
    32 const TInt KTotalWinsCardSlots=2;
       
    33 const TInt KTotalWinsCards=(KTotalWinsCardSlots+1); // Need 2 cards for slot 0
       
    34 
       
    35 const TUint32 KMMCWinsCardOCRValue = 0x00FFFF00;
       
    36 
       
    37 const TInt KSDMediaAreasPerCard = 2;
       
    38 const TInt KSDUserArea = 0;
       
    39 const TInt KSDProtectedArea = 1;
       
    40 
       
    41 class TWinsCardInfo
       
    42 	{
       
    43 public:
       
    44 	void GetCSD(TUint8* aResp) const;
       
    45 public:
       
    46 	TCID iCID;
       
    47 	TMediaPassword* iPWD;				// PWD_LEN calculated from PWD.
       
    48 	TBool iIsLocked;					// Could use iCurrentCardIsLocked
       
    49 	TMMCardStateEnum iState;			// Simulation of card's current state
       
    50 	HANDLE iAreaHandles[KSDMediaAreasPerCard];
       
    51 	TRCA iRCA;
       
    52 	TBool iIsSDCard;
       
    53 	TInt iBusWidth;
       
    54 	};
       
    55 
       
    56 class DWinsCPRMStack : public DCPRMStack
       
    57 	{
       
    58 public:
       
    59 	DWinsCPRMStack(TInt aBus, DMMCSocket* aSocket);
       
    60 	TInt Init();
       
    61 private:
       
    62 	virtual void MachineInfo(TMMCMachineInfo& aMachineInfo);
       
    63 public:
       
    64 	virtual void AdjustPartialRead(const TMMCard* aCard, TUint32 aStart, TUint32 aEnd, TUint32* aPhysStart, TUint32* aPhysEnd) const;
       
    65 	virtual void GetBufferInfo(TUint8** aMDBuf, TInt* aMDBufLen);
       
    66 	virtual void AddressCard(TInt aCardNumber);
       
    67 
       
    68 	enum TWinsMMCPanic
       
    69 		{
       
    70 	    EWinsMMCLidOpenIntBind=0,
       
    71 		EWinsMMCBadMachineInfo=1,
       
    72 		EWinsMMCMediaChangeTickFault = 2,
       
    73 		EWinsMMCCorruptCommand = 3,
       
    74 		EWinsMMCLockAttempt = 4,
       
    75 		EWinsMMCAPRNotSupp = 5,
       
    76 		EWinsMMCAPRRange = 6,
       
    77 		EWinsMMCAPRBoundary = 7,
       
    78 
       
    79 		EStkFFCNotSelCard = 0x010, EStkFFCNoneSel,
       
    80 		EStkFOCNotSelCard = 0x020, EStkFOCMultiSel, EStkFOCNoneSel,
       
    81 		EStkIMCBadStateCmd2 = 0x30, EStkIMCBadStateCmd3,
       
    82 			EStkICMACMD13NotSD, EStkIMCCmd6InvalidWidth
       
    83 		};
       
    84     static void Panic(TWinsMMCPanic aPanic);
       
    85 
       
    86 private:
       
    87 	// Stack service provided by ASSP layer
       
    88 	void SetBusConfigDefaults(TMMCBusConfig&, TUint aClock);
       
    89 	void InitClockOff();
       
    90 	void ASSPReset();
       
    91 	void ASSPDisengage();
       
    92 	void DoPowerDown();
       
    93 	// State Machine functions implemented in ASSP layer
       
    94 	TMMCErr DoPowerUpSM();
       
    95 	TMMCErr InitClockOnSM();
       
    96 	TMMCErr IssueMMCCommandSM();
       
    97 	TMMCErr CIMCalculateMediaKeySM();
       
    98 	TMMCErr SetSecureCommandArgumentSM();
       
    99 
       
   100 private:
       
   101 	TInt SetupSimulatedCard(TInt aCardNum);						// init
       
   102 	TInt CreateBinFileForCard(TInt aCardNum, TInt aAreaNum, HANDLE* aHandle);
       
   103 	TInt GetTargetSlotNumber(const TRCA& anRCA);
       
   104 	TInt FindAnyCardInStack(TMMCardStateEnum aState);
       
   105 	TInt FindFirstCardInStack(TMMCardStateEnum aState);
       
   106 	TInt FindOneCardInStack(TMMCardStateEnum aState);
       
   107 private:
       
   108 	TWinsCardInfo* iCardPool[KTotalWinsCards];		// all cards
       
   109 	TWinsCardInfo* iCardInfo[KTotalWinsCardSlots];		// present cards
       
   110 	TInt iAddressedCard;
       
   111 	TBool iCMD42Failed;
       
   112 	TInt iMBWOKBlocks;
       
   113 	TUint8* iMDBuf;
       
   114 	TInt iMDBufLen;
       
   115 
       
   116 	friend class TSDCardControllerInterfaceWins;
       
   117 	friend class DWinsMMCMediaChange;
       
   118 	};
       
   119 
       
   120 class DWinsMMCMediaChange : public DMMCMediaChange
       
   121 	{
       
   122 public:
       
   123 	DWinsMMCMediaChange(TInt aMediaChangeNum);
       
   124 	virtual TInt Create();
       
   125 	virtual void ForceMediaChange();
       
   126 	virtual void DoDoorOpen();
       
   127 	virtual void DoDoorClosed();
       
   128 	virtual TMediaState MediaState();
       
   129 protected:
       
   130     void DoorOpenService();
       
   131 private:
       
   132 	static TInt MediaChangeDfc(TAny *aPtr);
       
   133 	static void Tick(TAny *aPtr);
       
   134 	void TickService();
       
   135 	void Enable();
       
   136 	void Disable();
       
   137 	static void MediaChangeCallBack(TAny *aPtr);
       
   138 	inline void SetStackP(DWinsCPRMStack* aStackP) {iStackP=aStackP;}	
       
   139 private:
       
   140 	TTickLink iTickLink;
       
   141 	TInt iDoorClosedCount;
       
   142 	TBool iMediaChangeEnable;
       
   143 	TInt iMediaDoorCloseReload; 	// Units: In theory-20ms, Actual-100ms  
       
   144 	DWinsCPRMStack* iStackP;
       
   145 	friend class DWinsCPRMStack;
       
   146 	};
       
   147 
       
   148 class DWinsMMCPsu : public DMMCPsu 
       
   149     {
       
   150 public:
       
   151     DWinsMMCPsu(TInt aVccNum, TInt aMcId);
       
   152     virtual void Init();
       
   153 	virtual void DoSetState(TPBusPsuState aState);
       
   154 	virtual TInt VoltageInMilliVolts();
       
   155 private:
       
   156 	virtual void DoCheckVoltage();
       
   157     virtual void PsuInfo(TPBusPsuInfo &anInfo);
       
   158     };
       
   159 
       
   160 
       
   161 #endif	// #ifndef __PP_CPRM_H__