1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/bsp/mmc/ldd/src/MMcKernelTestUtils.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,366 @@
1.4 +/*
1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#ifdef __KERNEL_MODE__
1.23 +
1.24 +#include "MmcTestUtils.h"
1.25 +
1.26 +/**
1.27 + * Convert kernel Card object to user side object
1.28 + *
1.29 + * @param const TMMCard& aCard - The card object
1.30 + *
1.31 + * @return N/A
1.32 + *
1.33 + * @leave N/A
1.34 + */
1.35 +void TMMCCardInfo::SetCardInfo(const TMMCard& aCard)
1.36 + {
1.37 + iIsReady = aCard.IsPresent();
1.38 + iIsLocked = aCard.IsLocked();
1.39 + TCID* cid=(TCID*)&(aCard.CID());
1.40 + TInt i;
1.41 + for (i=0;i<16;i++)
1.42 + {
1.43 + iCID[i] = cid->At(i);
1.44 + }
1.45 + const TCSD& csd = aCard.CSD();
1.46 + for (i=0;i<16;i++)
1.47 + {
1.48 + iCSD[i] = csd.At(i);
1.49 + }
1.50 + iRCA = TUint16(aCard.RCA());
1.51 + iMediaType = (TMmcMediaType)aCard.MediaType();
1.52 + iCardSizeInBytes = aCard.DeviceSize64();
1.53 + iMaxReadBlLen = aCard.MaxReadBlLen();
1.54 + iReadBlLen = csd.ReadBlockLength();
1.55 + iWriteBlLen = csd.WriteBlockLength();
1.56 + iReadBlPartial = csd.ReadBlPartial();
1.57 + iWriteBlPartial = csd.WriteBlPartial();
1.58 + iReadBlkMisalign = csd.ReadBlkMisalign();
1.59 + iWriteBlkMisalign = csd.WriteBlkMisalign();
1.60 + iReadCurrentInMilliAmps = csd.MaxReadCurrentInMilliamps();
1.61 + iWriteCurrentInMilliAmps = csd.MaxWriteCurrentInMilliamps();
1.62 + iSpecVers = csd.SpecVers();
1.63 + iTAAC = csd.TAAC();
1.64 + iNSAC = csd.NSAC();
1.65 + iTransferSpeed = csd.TranSpeed();
1.66 + iCommandRegister = csd.CCC();
1.67 + iHighCapacity = aCard.IsHighCapacity();
1.68 + iFlags = aCard.iFlags;
1.69 + }
1.70 +
1.71 +/**
1.72 + * Convert kernel Machine Info object to user side object
1.73 + *
1.74 + * @param const TMMCMachineInfo& aMachineInfo - The Machine Info object
1.75 + *
1.76 + * @return N/A
1.77 + *
1.78 + * @leave N/A
1.79 + */
1.80 +TMachineInfo::TMachineInfo(const TMMCMachineInfo& aMachineInfo)
1.81 + {
1.82 + iTotalSockets = aMachineInfo.iTotalSockets;
1.83 + iTotalMediaChanges = aMachineInfo.iTotalMediaChanges;
1.84 + iTotalPrimarySupplies = aMachineInfo.iTotalPrimarySupplies;
1.85 + iSPIMode = aMachineInfo.iSPIMode & 0x1;
1.86 + iBaseBusNumber = aMachineInfo.iBaseBusNumber;
1.87 +
1.88 + if( aMachineInfo.iFlags & TMMCMachineInfo::ESupportsSPIMode )
1.89 + {
1.90 + iSupportsSPIMode = ETrue;
1.91 + }
1.92 + else
1.93 + {
1.94 + iSupportsSPIMode = EFalse;
1.95 + }
1.96 + if( aMachineInfo.iFlags & TMMCMachineInfo::ESupportsDoubleBuffering )
1.97 + {
1.98 + iSupportsDoubleBuffering = ETrue;
1.99 + }
1.100 + else
1.101 + {
1.102 + iSupportsDoubleBuffering = EFalse;
1.103 + }
1.104 + if( aMachineInfo.iFlags & TMMCMachineInfo::ESupportsR7 )
1.105 + {
1.106 + iSupportsR7 = ETrue;
1.107 + }
1.108 + else
1.109 + {
1.110 + iSupportsR7 = EFalse;
1.111 + }
1.112 + if( aMachineInfo.iFlags & TMMCMachineInfo::EDma8BitAddressing )
1.113 + {
1.114 + iDma8BitAddressing = ETrue;
1.115 + }
1.116 + else
1.117 + {
1.118 + iDma8BitAddressing = EFalse;
1.119 + }
1.120 + if( aMachineInfo.iFlags & TMMCMachineInfo::EDma16BitAddressing )
1.121 + {
1.122 + iDma16BitAddressing = ETrue;
1.123 + }
1.124 + else
1.125 + {
1.126 + iDma16BitAddressing = EFalse;
1.127 + }
1.128 + if( aMachineInfo.iFlags & TMMCMachineInfo::EDma32BitAddressing )
1.129 + {
1.130 + iDma32BitAddressing = ETrue;
1.131 + }
1.132 + else
1.133 + {
1.134 + iDma32BitAddressing = EFalse;
1.135 + }
1.136 + if( aMachineInfo.iFlags & TMMCMachineInfo::EDma64BitAddressing )
1.137 + {
1.138 + iDma64BitAddressing = ETrue;
1.139 + }
1.140 + else
1.141 + {
1.142 + iDma64BitAddressing = EFalse;
1.143 + }
1.144 + if( aMachineInfo.iFlags & TMMCMachineInfo::ESupportsDMA )
1.145 + {
1.146 + iSupportsDMA = ETrue;
1.147 + }
1.148 + else
1.149 + {
1.150 + iSupportsDMA = EFalse;
1.151 + }
1.152 + if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_256K )
1.153 + {
1.154 + iMaxTransferLength_256K = ETrue;
1.155 + }
1.156 + else
1.157 + {
1.158 + iMaxTransferLength_256K = EFalse;
1.159 + }
1.160 + if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_512K )
1.161 + {
1.162 + iMaxTransferLength_512K = ETrue;
1.163 + }
1.164 + else
1.165 + {
1.166 + iMaxTransferLength_512K = EFalse;
1.167 + }
1.168 + if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_1M )
1.169 + {
1.170 + iMaxTransferLength_1M = ETrue;
1.171 + }
1.172 + else
1.173 + {
1.174 + iMaxTransferLength_1M = EFalse;
1.175 + }
1.176 + if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_2M )
1.177 + {
1.178 + iMaxTransferLength_2M = ETrue;
1.179 + }
1.180 + else
1.181 + {
1.182 + iMaxTransferLength_2M = EFalse;
1.183 + }
1.184 + if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_4M )
1.185 + {
1.186 + iMaxTransferLength_4M = ETrue;
1.187 + }
1.188 + else
1.189 + {
1.190 + iMaxTransferLength_4M = EFalse;
1.191 + }
1.192 + if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_8M )
1.193 + {
1.194 + iMaxTransferLength_8M = ETrue;
1.195 + }
1.196 + else
1.197 + {
1.198 + iMaxTransferLength_8M = EFalse;
1.199 + }
1.200 + if( aMachineInfo.iFlags & TMMCMachineInfo::EMaxTransferLength_16M )
1.201 + {
1.202 + iMaxTransferLength_16M = ETrue;
1.203 + }
1.204 + else
1.205 + {
1.206 + iMaxTransferLength_16M = EFalse;
1.207 + }
1.208 + }
1.209 +
1.210 +/**
1.211 + * Convert kernel CSD object to user side object
1.212 + *
1.213 + * @param const TCSD& aCSD - The CSD object
1.214 + *
1.215 + * @return N/A
1.216 + *
1.217 + * @leave N/A
1.218 + */
1.219 +TCSDInfo::TCSDInfo(const TCSD& aCSD)
1.220 + {
1.221 + iCSDStructure = aCSD.CSDStructure();
1.222 + iSpecVers = aCSD.SpecVers();
1.223 + iReserved120 = aCSD.Reserved120();
1.224 + iTAAC = aCSD.TAAC();
1.225 + iNSAC = aCSD.NSAC();
1.226 + iTranSpeed = aCSD.TranSpeed();
1.227 + iCCC = aCSD.CCC();
1.228 + iReadBlLen = aCSD.ReadBlLen();
1.229 + iReadBlPartial = aCSD.ReadBlPartial();
1.230 + iWriteBlkMisalign = aCSD.WriteBlkMisalign();
1.231 + iReadBlkMisalign = aCSD.ReadBlkMisalign();
1.232 + iDSRImp = aCSD.DSRImp();
1.233 + iReserved74 = aCSD.Reserved74();
1.234 + iCSize = aCSD.CSize();
1.235 + iVDDRCurrMin = aCSD.VDDRCurrMin();
1.236 + iVDDRCurrMax = aCSD.VDDRCurrMax();
1.237 + iVDDWCurrMin = aCSD.VDDWCurrMin();
1.238 + iVDDWCurrMax = aCSD.VDDWCurrMax();
1.239 + iCSizeMult = aCSD.CSizeMult();
1.240 + iEraseGrpSize = aCSD.EraseGrpSize();
1.241 + iEraseGrpMult = aCSD.EraseGrpMult();
1.242 + iWPGrpSize = aCSD.WPGrpSize();
1.243 + iWPGrpEnable = aCSD.WPGrpEnable();
1.244 + iDefaultECC = aCSD.DefaultECC();
1.245 + iR2WFactor = aCSD.R2WFactor();
1.246 + iWriteBlLen = aCSD.WriteBlLen();
1.247 + iWriteBlPartial = aCSD.WriteBlPartial();
1.248 + iReserved16 = aCSD.Reserved16();
1.249 + iFileFormatGrp = aCSD.FileFormatGrp();
1.250 + iCopy = aCSD.Copy();
1.251 + iPermWriteProtect = aCSD.PermWriteProtect();
1.252 + iTmpWriteProtect = aCSD.TmpWriteProtect();
1.253 + iFileFormat = aCSD.FileFormat();
1.254 + iECC = aCSD.ECC();
1.255 + iCRC = aCSD.CRC();
1.256 + iDeviceSize = aCSD.DeviceSize();
1.257 + iReadBlockLength = aCSD.ReadBlockLength();
1.258 + iWriteBlockLength = aCSD.WriteBlockLength();
1.259 + iEraseSectorSize = aCSD.EraseSectorSize();
1.260 + iEraseGroupSize = aCSD.EraseGroupSize();
1.261 + iMinReadCurrentInMilliamps = aCSD.MinReadCurrentInMilliamps();
1.262 + iMinWriteCurrentInMilliamps = aCSD.MinWriteCurrentInMilliamps();
1.263 + iMaxReadCurrentInMilliamps = aCSD.MaxReadCurrentInMilliamps();
1.264 + iMaxWriteCurrentInMilliamps = aCSD.MaxWriteCurrentInMilliamps();
1.265 + iMaxTranSpeedInKilohertz = aCSD.MaxTranSpeedInKilohertz();
1.266 +
1.267 + // Convert Kernel side TMMCMediaTypeEnum to User side TMMCMediaTypeEnumInfo
1.268 + switch (aCSD.MediaType())
1.269 + {
1.270 + case EMultiMediaROM:
1.271 + iMediaType = EMultiMediaROM;
1.272 + break;
1.273 +
1.274 + case EMultiMediaFlash:
1.275 + iMediaType = EMultiMediaFlash;
1.276 + break;
1.277 +
1.278 + case EMultiMediaIO:
1.279 + iMediaType = EMultiMediaIO;
1.280 + break;
1.281 +
1.282 + case EMultiMediaOther:
1.283 + iMediaType = EMultiMediaOther;
1.284 + break;
1.285 +
1.286 + default:
1.287 + iMediaType = EMultiMediaNotSupported;
1.288 + break;
1.289 + }
1.290 + }
1.291 +
1.292 +/**
1.293 + * Convert kernel Extended CSD object to user side object
1.294 + *
1.295 + * @param const TExtendedCSD& aExtendedCSD - The Extended CSD object
1.296 + *
1.297 + * @return N/A
1.298 + *
1.299 + * @leave N/A
1.300 + */
1.301 +TExtendedCSDInfo::TExtendedCSDInfo(const TExtendedCSD& aExtendedCSD)
1.302 + {
1.303 + iSupportedCmdSet = aExtendedCSD.SupportedCmdSet();
1.304 + iSectorCount = aExtendedCSD.SectorCount();
1.305 + iMinPerfWrite8Bit52Mhz = aExtendedCSD.MinPerfWrite8Bit52Mhz();
1.306 + iMinPerfRead8Bit52Mhz = aExtendedCSD.MinPerfRead8Bit52Mhz();
1.307 + iMinPerfWrite8Bit26Mhz_4Bit52Mhz = aExtendedCSD.MinPerfWrite8Bit26Mhz_4Bit52Mhz();
1.308 + iMinPerfRead8Bit26Mhz_4Bit52Mhz = aExtendedCSD.MinPerfRead8Bit26Mhz_4Bit52Mhz();
1.309 + iMinPerfWrite4Bit26Mhz = aExtendedCSD.MinPerfWrite4Bit26Mhz();
1.310 + iMinPerfRead4Bit26Mhz = aExtendedCSD.MinPerfRead4Bit26Mhz();
1.311 + iPowerClass26Mhz360V = aExtendedCSD.PowerClass26Mhz360V();
1.312 + iPowerClass52Mhz360V = aExtendedCSD.PowerClass52Mhz360V();
1.313 + iPowerClass26Mhz195V = aExtendedCSD.PowerClass26Mhz195V();
1.314 + iPowerClass52Mhz195V = aExtendedCSD.PowerClass52Mhz195V();
1.315 + iCardType = aExtendedCSD.CardType();
1.316 + iCSDStructureVer = aExtendedCSD.CSDStructureVer();
1.317 + iExtendedCSDRev = aExtendedCSD.ExtendedCSDRev();
1.318 + iCmdSet = aExtendedCSD.CmdSet();
1.319 + iCmdSetRev = aExtendedCSD.CmdSetRev();
1.320 + iPowerClass = aExtendedCSD.PowerClass();
1.321 + iHighSpeedTiming = aExtendedCSD.HighSpeedTiming();
1.322 + }
1.323 +
1.324 +/**
1.325 + * Create a formatted password from CID to write to Password Store
1.326 + *
1.327 + * @param TDes8 &aFormattedPassword - The buffer to hold the formatted password
1.328 + * @param const TCID& aCID - The CID
1.329 + *
1.330 + * @return N/A
1.331 + *
1.332 + * @leave N/A
1.333 + */
1.334 +TBool TStackPasswordStoreData::CreateFormattedPassword(TDes8 &aFormattedPassword, const TCID& aCID)
1.335 + {
1.336 + TBool success = EFalse;
1.337 + if (aFormattedPassword.MaxLength() >= KMMCCIDLength)
1.338 + {
1.339 + aFormattedPassword.Zero();
1.340 + aFormattedPassword.SetLength(KMMCCIDLength);
1.341 + aCID.Copy(&aFormattedPassword[0]);
1.342 + TUint8 lenBuf[sizeof(TInt32)]; // TInt32, big endian
1.343 + TMMC::BigEndian4Bytes(lenBuf, TInt32(iPassword.Length()));
1.344 + aFormattedPassword.Append(&lenBuf[0], sizeof(TInt32));
1.345 + aFormattedPassword.Append(iPassword);
1.346 + success = ETrue;
1.347 + }
1.348 + return success;
1.349 + }
1.350 +
1.351 +/**
1.352 + * Extract the password string from a formatted password
1.353 + *
1.354 + * @param TDes8 &aFormattedPassword - The formatted password
1.355 + *
1.356 + * @return N/A
1.357 + *
1.358 + * @leave N/A
1.359 + */
1.360 +void TStackPasswordStoreData::SetFormattedPassword(const TDesC8 &aFormattedPassword)
1.361 + {
1.362 + iPassword.Copy(&aFormattedPassword[KPasswordStoreCIDLength], aFormattedPassword.Length()-KPasswordStoreCIDLength);
1.363 + }
1.364 +
1.365 +#else
1.366 +
1.367 +#error compiling kernel side only src file on user side
1.368 +
1.369 +#endif