First public contribution.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #ifdef __KERNEL_MODE__
21 #include "MmcTestUtils.h"
24 * Convert kernel Card object to user side object
26 * @param const TMMCard& aCard - The card object
32 void TMMCCardInfo::SetCardInfo(const TMMCard& aCard)
34 iIsReady = aCard.IsPresent();
35 iIsLocked = aCard.IsLocked();
36 TCID* cid=(TCID*)&(aCard.CID());
42 const TCSD& csd = aCard.CSD();
47 iRCA = TUint16(aCard.RCA());
48 iMediaType = (TMmcMediaType)aCard.MediaType();
49 iCardSizeInBytes = aCard.DeviceSize64();
50 iMaxReadBlLen = aCard.MaxReadBlLen();
51 iReadBlLen = csd.ReadBlockLength();
52 iWriteBlLen = csd.WriteBlockLength();
53 iReadBlPartial = csd.ReadBlPartial();
54 iWriteBlPartial = csd.WriteBlPartial();
55 iReadBlkMisalign = csd.ReadBlkMisalign();
56 iWriteBlkMisalign = csd.WriteBlkMisalign();
57 iReadCurrentInMilliAmps = csd.MaxReadCurrentInMilliamps();
58 iWriteCurrentInMilliAmps = csd.MaxWriteCurrentInMilliamps();
59 iSpecVers = csd.SpecVers();
62 iTransferSpeed = csd.TranSpeed();
63 iCommandRegister = csd.CCC();
64 iHighCapacity = aCard.IsHighCapacity();
65 iFlags = aCard.iFlags;
69 * Convert kernel Machine Info object to user side object
71 * @param const TMMCMachineInfo& aMachineInfo - The Machine Info object
77 TMachineInfo::TMachineInfo(const TMMCMachineInfo& aMachineInfo)
79 iTotalSockets = aMachineInfo.iTotalSockets;
80 iTotalMediaChanges = aMachineInfo.iTotalMediaChanges;
81 iTotalPrimarySupplies = aMachineInfo.iTotalPrimarySupplies;
82 iSPIMode = aMachineInfo.iSPIMode & 0x1;
83 iBaseBusNumber = aMachineInfo.iBaseBusNumber;
85 if( aMachineInfo.iFlags & TMMCMachineInfo::ESupportsSPIMode )
87 iSupportsSPIMode = ETrue;
91 iSupportsSPIMode = EFalse;
93 if( aMachineInfo.iFlags & TMMCMachineInfo::ESupportsDoubleBuffering )
95 iSupportsDoubleBuffering = ETrue;
99 iSupportsDoubleBuffering = EFalse;
101 if( aMachineInfo.iFlags & TMMCMachineInfo::ESupportsR7 )
107 iSupportsR7 = EFalse;
109 if( aMachineInfo.iFlags & TMMCMachineInfo::EDma8BitAddressing )
111 iDma8BitAddressing = ETrue;
115 iDma8BitAddressing = EFalse;
117 if( aMachineInfo.iFlags & TMMCMachineInfo::EDma16BitAddressing )
119 iDma16BitAddressing = ETrue;
123 iDma16BitAddressing = EFalse;
125 if( aMachineInfo.iFlags & TMMCMachineInfo::EDma32BitAddressing )
127 iDma32BitAddressing = ETrue;
131 iDma32BitAddressing = EFalse;
133 if( aMachineInfo.iFlags & TMMCMachineInfo::EDma64BitAddressing )
135 iDma64BitAddressing = ETrue;
139 iDma64BitAddressing = EFalse;
141 if( aMachineInfo.iFlags & TMMCMachineInfo::ESupportsDMA )
143 iSupportsDMA = ETrue;
147 iSupportsDMA = EFalse;
149 if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_256K )
151 iMaxTransferLength_256K = ETrue;
155 iMaxTransferLength_256K = EFalse;
157 if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_512K )
159 iMaxTransferLength_512K = ETrue;
163 iMaxTransferLength_512K = EFalse;
165 if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_1M )
167 iMaxTransferLength_1M = ETrue;
171 iMaxTransferLength_1M = EFalse;
173 if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_2M )
175 iMaxTransferLength_2M = ETrue;
179 iMaxTransferLength_2M = EFalse;
181 if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_4M )
183 iMaxTransferLength_4M = ETrue;
187 iMaxTransferLength_4M = EFalse;
189 if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_8M )
191 iMaxTransferLength_8M = ETrue;
195 iMaxTransferLength_8M = EFalse;
197 if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_16M )
199 iMaxTransferLength_16M = ETrue;
203 iMaxTransferLength_16M = EFalse;
208 * Convert kernel CSD object to user side object
210 * @param const TCSD& aCSD - The CSD object
216 TCSDInfo::TCSDInfo(const TCSD& aCSD)
218 iCSDStructure = aCSD.CSDStructure();
219 iSpecVers = aCSD.SpecVers();
220 iReserved120 = aCSD.Reserved120();
223 iTranSpeed = aCSD.TranSpeed();
225 iReadBlLen = aCSD.ReadBlLen();
226 iReadBlPartial = aCSD.ReadBlPartial();
227 iWriteBlkMisalign = aCSD.WriteBlkMisalign();
228 iReadBlkMisalign = aCSD.ReadBlkMisalign();
229 iDSRImp = aCSD.DSRImp();
230 iReserved74 = aCSD.Reserved74();
231 iCSize = aCSD.CSize();
232 iVDDRCurrMin = aCSD.VDDRCurrMin();
233 iVDDRCurrMax = aCSD.VDDRCurrMax();
234 iVDDWCurrMin = aCSD.VDDWCurrMin();
235 iVDDWCurrMax = aCSD.VDDWCurrMax();
236 iCSizeMult = aCSD.CSizeMult();
237 iEraseGrpSize = aCSD.EraseGrpSize();
238 iEraseGrpMult = aCSD.EraseGrpMult();
239 iWPGrpSize = aCSD.WPGrpSize();
240 iWPGrpEnable = aCSD.WPGrpEnable();
241 iDefaultECC = aCSD.DefaultECC();
242 iR2WFactor = aCSD.R2WFactor();
243 iWriteBlLen = aCSD.WriteBlLen();
244 iWriteBlPartial = aCSD.WriteBlPartial();
245 iReserved16 = aCSD.Reserved16();
246 iFileFormatGrp = aCSD.FileFormatGrp();
248 iPermWriteProtect = aCSD.PermWriteProtect();
249 iTmpWriteProtect = aCSD.TmpWriteProtect();
250 iFileFormat = aCSD.FileFormat();
253 iDeviceSize = aCSD.DeviceSize();
254 iReadBlockLength = aCSD.ReadBlockLength();
255 iWriteBlockLength = aCSD.WriteBlockLength();
256 iEraseSectorSize = aCSD.EraseSectorSize();
257 iEraseGroupSize = aCSD.EraseGroupSize();
258 iMinReadCurrentInMilliamps = aCSD.MinReadCurrentInMilliamps();
259 iMinWriteCurrentInMilliamps = aCSD.MinWriteCurrentInMilliamps();
260 iMaxReadCurrentInMilliamps = aCSD.MaxReadCurrentInMilliamps();
261 iMaxWriteCurrentInMilliamps = aCSD.MaxWriteCurrentInMilliamps();
262 iMaxTranSpeedInKilohertz = aCSD.MaxTranSpeedInKilohertz();
264 // Convert Kernel side TMMCMediaTypeEnum to User side TMMCMediaTypeEnumInfo
265 switch (aCSD.MediaType())
268 iMediaType = EMultiMediaROM;
271 case EMultiMediaFlash:
272 iMediaType = EMultiMediaFlash;
276 iMediaType = EMultiMediaIO;
279 case EMultiMediaOther:
280 iMediaType = EMultiMediaOther;
284 iMediaType = EMultiMediaNotSupported;
290 * Convert kernel Extended CSD object to user side object
292 * @param const TExtendedCSD& aExtendedCSD - The Extended CSD object
298 TExtendedCSDInfo::TExtendedCSDInfo(const TExtendedCSD& aExtendedCSD)
300 iSupportedCmdSet = aExtendedCSD.SupportedCmdSet();
301 iSectorCount = aExtendedCSD.SectorCount();
302 iMinPerfWrite8Bit52Mhz = aExtendedCSD.MinPerfWrite8Bit52Mhz();
303 iMinPerfRead8Bit52Mhz = aExtendedCSD.MinPerfRead8Bit52Mhz();
304 iMinPerfWrite8Bit26Mhz_4Bit52Mhz = aExtendedCSD.MinPerfWrite8Bit26Mhz_4Bit52Mhz();
305 iMinPerfRead8Bit26Mhz_4Bit52Mhz = aExtendedCSD.MinPerfRead8Bit26Mhz_4Bit52Mhz();
306 iMinPerfWrite4Bit26Mhz = aExtendedCSD.MinPerfWrite4Bit26Mhz();
307 iMinPerfRead4Bit26Mhz = aExtendedCSD.MinPerfRead4Bit26Mhz();
308 iPowerClass26Mhz360V = aExtendedCSD.PowerClass26Mhz360V();
309 iPowerClass52Mhz360V = aExtendedCSD.PowerClass52Mhz360V();
310 iPowerClass26Mhz195V = aExtendedCSD.PowerClass26Mhz195V();
311 iPowerClass52Mhz195V = aExtendedCSD.PowerClass52Mhz195V();
312 iCardType = aExtendedCSD.CardType();
313 iCSDStructureVer = aExtendedCSD.CSDStructureVer();
314 iExtendedCSDRev = aExtendedCSD.ExtendedCSDRev();
315 iCmdSet = aExtendedCSD.CmdSet();
316 iCmdSetRev = aExtendedCSD.CmdSetRev();
317 iPowerClass = aExtendedCSD.PowerClass();
318 iHighSpeedTiming = aExtendedCSD.HighSpeedTiming();
322 * Create a formatted password from CID to write to Password Store
324 * @param TDes8 &aFormattedPassword - The buffer to hold the formatted password
325 * @param const TCID& aCID - The CID
331 TBool TStackPasswordStoreData::CreateFormattedPassword(TDes8 &aFormattedPassword, const TCID& aCID)
333 TBool success = EFalse;
334 if (aFormattedPassword.MaxLength() >= KMMCCIDLength)
336 aFormattedPassword.Zero();
337 aFormattedPassword.SetLength(KMMCCIDLength);
338 aCID.Copy(&aFormattedPassword[0]);
339 TUint8 lenBuf[sizeof(TInt32)]; // TInt32, big endian
340 TMMC::BigEndian4Bytes(lenBuf, TInt32(iPassword.Length()));
341 aFormattedPassword.Append(&lenBuf[0], sizeof(TInt32));
342 aFormattedPassword.Append(iPassword);
349 * Extract the password string from a formatted password
351 * @param TDes8 &aFormattedPassword - The formatted password
357 void TStackPasswordStoreData::SetFormattedPassword(const TDesC8 &aFormattedPassword)
359 iPassword.Copy(&aFormattedPassword[KPasswordStoreCIDLength], aFormattedPassword.Length()-KPasswordStoreCIDLength);
364 #error compiling kernel side only src file on user side