1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/bsp/mmc/ldd/src/mmclddstack.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,371 @@
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 +#include <kernel.h>
1.23 +#include <mmc.h>
1.24 +#include <locmedia.h>
1.25 +
1.26 +#include "mmcldd.h"
1.27 +#include "d_mmcsdif.h"
1.28 +
1.29 +/**
1.30 + * Do a kernel side control for DMMCStack
1.31 + *
1.32 + * @param TInt aFunction - Request Function ID
1.33 + * @param TAny* a1 - Given parameter
1.34 + * @param TAny* a2 - Given parameter
1.35 + *
1.36 + * @return TInt the error code
1.37 + *
1.38 + * @leave N/A
1.39 + */
1.40 +TInt DLddMmcCntrlInterface::StackDoControl(TInt aFunction, TAny* a1, TAny* a2)
1.41 + {
1.42 + MMCSDLOG3(
1.43 + "DLddMmcCntrlInterface::StackDoControl aFunction(%d) \
1.44 + TTCFunctionId(aFunction).FunctionId()(%d)",
1.45 + aFunction, TTCFunctionId(aFunction).FunctionId());
1.46 + TInt ret = KErrNone;
1.47 +
1.48 + if (!iStack)
1.49 + {
1.50 + MMCSDLOG("DLddMmcCntrlInterface::StackDoControl - iStack is NULL");
1.51 + return KErrGeneral;
1.52 + }
1.53 + else if (!iClient)
1.54 + {
1.55 + MMCSDLOG("DLddMmcCntrlInterface::StackDoControl - iClient is NULL");
1.56 + return KErrGeneral;
1.57 + }
1.58 +
1.59 + switch (TTCFunctionId(aFunction).FunctionId())
1.60 + {
1.61 + case RMMCSDTestControllerInterface::EStack:
1.62 + {
1.63 + MMCSDLOG("case RMMCSDTestControllerInterface::EStack");
1.64 + ret = Kern::ThreadRawWrite(iClient, a1, &iStack, sizeof(iStack));
1.65 + }
1.66 + break;
1.67 + case RMMCSDTestControllerInterface::EStackAdjustPartialRead:
1.68 + {
1.69 + if (!iCard)
1.70 + {
1.71 + MMCSDLOG("RMMCSDTestControllerInterface::EStackAdjustPartialRead NULL card\n");
1.72 + return KErrNotReady;
1.73 + }
1.74 +
1.75 + TPartialReadData partialReadData;
1.76 + Kern::ThreadRawRead(iClient, a1, &partialReadData,
1.77 + sizeof(partialReadData));
1.78 + iStack->AdjustPartialRead(iCard, partialReadData.iStart,
1.79 + partialReadData.iEnd,
1.80 + (TUint32*)&(partialReadData.iPhysStart),
1.81 + (TUint32*)&(partialReadData.iPhysEnd));
1.82 + ret = Kern::ThreadRawWrite(iClient, a1, &partialReadData,
1.83 + sizeof(partialReadData));
1.84 + }
1.85 + break;
1.86 + case RMMCSDTestControllerInterface::EStackAllocSession:
1.87 + {
1.88 + // just a simple test to check p1 call of DMMCStack::AllocSession
1.89 + // the session is tested further within the DLddAsyncRequest class
1.90 + // which each uses their own session (allocated from DMMCStack::AllocSession)
1.91 + MMCSDLOG("pre AllocSession");
1.92 + DMMCSession* session = iStack->AllocSession(TMMCCallBack());
1.93 + MMCSDLOG2("post AllocSession session = %x", session);
1.94 + delete session;
1.95 + }
1.96 + break;
1.97 + case RMMCSDTestControllerInterface::EStackBufferInfo:
1.98 + {
1.99 + MMCSDLOG("RMMCSDTestControllerInterface::EStackBufferInfo");
1.100 + TBufferInfo bufInfo;
1.101 + iStack->BufferInfo(bufInfo.iBuf, bufInfo.iBufLen,
1.102 + bufInfo.iMinorBufLen);
1.103 + Kern::ThreadRawWrite(iClient, a1, &bufInfo, sizeof(bufInfo));
1.104 + }
1.105 + break;
1.106 + case RMMCSDTestControllerInterface::EStackGetBufferInfo:
1.107 + {
1.108 + MMCSDLOG("RMMCSDTestControllerInterface::EStackGetBufferInfo");
1.109 + TBufferInfo bufInfo;
1.110 + iStack->GetBufferInfo(&bufInfo.iBuf, &bufInfo.iBufLen);
1.111 + Kern::ThreadRawWrite(iClient, a1, &bufInfo, sizeof(bufInfo));
1.112 + }
1.113 + break;
1.114 +
1.115 + case RMMCSDTestControllerInterface::EStackCardP:
1.116 + {
1.117 + TCardPtr cardPtr;
1.118 + ret = Kern::ThreadRawRead(iClient, a1, &cardPtr, sizeof(cardPtr));
1.119 + if( ret == KErrNone )
1.120 + {
1.121 + MMCSDLOG("Calling RMMCSDTestControllerInterface::EStackCardP");
1.122 + MMCSDLOG2("cardNumber=%d", cardPtr.iCardNumber);
1.123 + iCard = iStack->CardP(cardPtr.iCardNumber);
1.124 + MMCSDLOG2("cardPtr=%x", iCard);
1.125 + cardPtr.iCardPtr = iCard;
1.126 + ret = Kern::ThreadRawWrite(iClient, a1, &cardPtr, sizeof(cardPtr));
1.127 + }
1.128 + }
1.129 + break;
1.130 +
1.131 + case RMMCSDTestControllerInterface::EStackDemandPagingInfo:
1.132 + {
1.133 + DMMCStack::TDemandPagingInfo dpInfo;
1.134 + ret = iStack->DemandPagingInfo(dpInfo);
1.135 +
1.136 + if (ret == KErrNone)
1.137 + {
1.138 + TTCDemandPagingInfo info;
1.139 + info.iDriveCount = dpInfo.iDriveCount;
1.140 + info.iNumPages = dpInfo.iNumPages;
1.141 + info.iPagingDriveList = dpInfo.iPagingDriveList;
1.142 + info.iPagingType = dpInfo.iPagingType;
1.143 + info.iReadShift = dpInfo.iReadShift;
1.144 + info.iWriteProtected = dpInfo.iWriteProtected;
1.145 + ret = Kern::ThreadRawWrite(iClient, a1, &info, sizeof(info));
1.146 + }
1.147 + else
1.148 + {
1.149 + MMCSDLOG2(
1.150 + "RMMCSDTestControllerInterface::EStackDemandPagingInfo err(%d)",
1.151 + ret);
1.152 + }
1.153 + }
1.154 + break;
1.155 +
1.156 + case RMMCSDTestControllerInterface::EStackEffectiveModes:
1.157 + {
1.158 + TUint32 rval = iStack->EffectiveModes(iStackConfig);
1.159 + ret = Kern::ThreadRawWrite(iClient, a1, &rval, sizeof(rval));
1.160 + }
1.161 + break;
1.162 +
1.163 + case RMMCSDTestControllerInterface::EStackHasCardsPresent:
1.164 + {
1.165 + TBool cardsPresent = iStack->HasCardsPresent();
1.166 + ret = Kern::ThreadRawWrite(iClient, a1, &cardsPresent,
1.167 + sizeof(cardsPresent));
1.168 + }
1.169 + break;
1.170 + case RMMCSDTestControllerInterface::EStackHasSessionsQueued:
1.171 + {
1.172 + TBool sessionsQueued = iStack->HasSessionsQueued();
1.173 + ret = Kern::ThreadRawWrite(iClient, a1, &sessionsQueued,
1.174 + sizeof(sessionsQueued));
1.175 + }
1.176 + break;
1.177 + case RMMCSDTestControllerInterface::EStackInit:
1.178 + ret = iStack->Init();
1.179 + break;
1.180 + case RMMCSDTestControllerInterface::EStackInitStackInProgress:
1.181 + {
1.182 + TBool inProgress = iStack->InitStackInProgress();
1.183 + ret = Kern::ThreadRawWrite(iClient, a1, &inProgress,
1.184 + sizeof(inProgress));
1.185 + }
1.186 + break;
1.187 + case RMMCSDTestControllerInterface::EStackMMCSocket:
1.188 + {
1.189 + MMCSDLOG("case RMMCSDTestControllerInterface::EStackMMCSocket");
1.190 + DMMCSocket* socketPtr = iStack->MMCSocket();
1.191 + MMCSDLOG3("Socket Ptr (%x) &socketPtr(%x)", socketPtr,
1.192 + &socketPtr);
1.193 + ret = Kern::ThreadRawWrite(iClient, a1, &socketPtr,
1.194 + sizeof(socketPtr));
1.195 + }
1.196 + break;
1.197 + case RMMCSDTestControllerInterface::EStackMachineInfo:
1.198 + {
1.199 + TMMCMachineInfo mi;
1.200 + iStack->MachineInfo(mi);
1.201 + TMachineInfo machineInfo(mi);
1.202 + ret = Kern::ThreadRawWrite(iClient, a1, &machineInfo, sizeof(machineInfo));
1.203 + }
1.204 + break;
1.205 + case RMMCSDTestControllerInterface::EStackMaxCardsInStack:
1.206 + {
1.207 + TUint maxCards = iStack->MaxCardsInStack();
1.208 + ret = Kern::ThreadRawWrite(iClient, a1, &maxCards, sizeof(maxCards));
1.209 + }
1.210 + break;
1.211 + case RMMCSDTestControllerInterface::EStackReadPasswordStore:
1.212 + {
1.213 + TMMCPasswordStore* pps = iStack->PasswordStore();
1.214 + TStackPasswordStoreData pwdStoreData;
1.215 + pwdStoreData.iPwdStorePtr = pps;
1.216 + if (pps)
1.217 + {
1.218 + TBuf8<KPasswordStoreCIDLength + KMmcPwdLen> formattedPassword;
1.219 + ret = pps->ReadPasswordData(formattedPassword);
1.220 + MMCSDLOG2("RMMCSDTestControllerInterface::EStackReadPasswordStore formattedPassword=%S", &formattedPassword);
1.221 +
1.222 + if (ret == KErrNone)
1.223 + {
1.224 + pwdStoreData.SetFormattedPassword(formattedPassword);
1.225 + ret = Kern::ThreadRawWrite(iClient, a1, &pwdStoreData, sizeof(pwdStoreData));
1.226 + }
1.227 + }
1.228 + else
1.229 + {
1.230 + MMCSDLOG("RMMCSDTestControllerInterface::EStackReadPasswordStore invalid pps");
1.231 + ret = KErrGeneral;
1.232 + }
1.233 +
1.234 + MMCSDLOG3("RMMCSDTestControllerInterface::EStackReadPasswordStore #1 ret(%d) pwdStoreData.iPassword(%S)",
1.235 + ret, &pwdStoreData.iPassword);
1.236 + }
1.237 + break;
1.238 + case RMMCSDTestControllerInterface::EStackWritePasswordStore:
1.239 + {
1.240 + TStackPasswordStoreData pwdStoreData;
1.241 + ret = Kern::ThreadRawRead(iClient, a1, &pwdStoreData, sizeof(pwdStoreData));
1.242 + TMMCPasswordStore* pps = iStack->PasswordStore();
1.243 + pwdStoreData.iPwdStorePtr = pps;
1.244 + if (pps)
1.245 + {
1.246 + TBuf8<KPasswordStoreCIDLength + KMmcPwdLen> formattedPassword;
1.247 + if (pwdStoreData.CreateFormattedPassword(formattedPassword, iCard->CID()))
1.248 + {
1.249 + MMCSDLOG2("RMMCSDTestControllerInterface::EStackWritePasswordStore formattedPassword=%S", &formattedPassword);
1.250 + ret = pps->WritePasswordData(formattedPassword);
1.251 + }
1.252 + else
1.253 + {
1.254 + MMCSDLOG("RMMCSDTestControllerInterface::EStackWritePasswordStore - CreateFormattedPassword() failed");
1.255 + ret = KErrGeneral;
1.256 + }
1.257 + }
1.258 + else
1.259 + {
1.260 + MMCSDLOG("RMMCSDTestControllerInterface::EStackWritePasswordStore invalid pps");
1.261 + ret = KErrGeneral;
1.262 + }
1.263 + MMCSDLOG3(
1.264 + "RMMCSDTestControllerInterface::EStackWritePasswordStore ret(%d) pwdStoreData.iPassword(%S)",
1.265 + ret, &pwdStoreData.iPassword);
1.266 + }
1.267 + break;
1.268 +
1.269 + case RMMCSDTestControllerInterface::EStackProgramPeriodInMs:
1.270 + {
1.271 + TInt periodMs = iStack->ProgramPeriodInMilliSeconds();
1.272 + ret
1.273 + = Kern::ThreadRawWrite(iClient, a1, &periodMs,
1.274 + sizeof(periodMs));
1.275 + }
1.276 + break;
1.277 +
1.278 + case RMMCSDTestControllerInterface::EStackStop:
1.279 + {
1.280 + if (!iCard)
1.281 + {
1.282 + MMCSDLOG("RMMCSDTestControllerInterface::EStackStop NULL card\n");
1.283 + return KErrNotReady;
1.284 + }
1.285 +
1.286 + ret = iStack->Stop(iCard);
1.287 + }
1.288 + break;
1.289 +
1.290 + case RMMCSDTestControllerInterface::EStackReportPowerUp:
1.291 + iStack->ReportPowerUp();
1.292 + break;
1.293 +
1.294 + case RMMCSDTestControllerInterface::EStackReportPowerDown:
1.295 + iStack->ReportPowerDown();
1.296 + break;
1.297 +
1.298 + case RMMCSDTestControllerInterface::EStackConfigureEffectiveModes:
1.299 + if (!a1)
1.300 + {
1.301 + return KErrArgument;
1.302 + }
1.303 + ret = StackConfigureEffectiveModes((TInt) a1, a2);
1.304 + break;
1.305 +
1.306 + default:
1.307 + ret = KErrNotFound;
1.308 + break;
1.309 + }
1.310 + return ret;
1.311 + }
1.312 +
1.313 +/**
1.314 + * Configure the Effectivemodes parameter for all TMMCStackConfig functions
1.315 + *
1.316 + * @param TInt aEffectiveModesFunctionId - Effective Modes Function ID
1.317 + * @param TAny* aParam - Given Effective Modes Function parameter
1.318 + *
1.319 + * @return TInt the error code
1.320 + *
1.321 + * @leave N/A
1.322 + */
1.323 +TInt DLddMmcCntrlInterface::StackConfigureEffectiveModes(
1.324 + TInt aEffectiveModesFunctionId, TAny* aParam)
1.325 + {
1.326 + // used to handle requests to configure the iStackConfig (Effectivemodes)
1.327 + // parameter for all TMMCStackConfig functions is max 32 bit value so passes in as value aParam
1.328 +
1.329 + TInt r = KErrNone; // all functions return void
1.330 + switch ((RMMCSDTestControllerInterface::TEffectiveModesFunctionId) aEffectiveModesFunctionId)
1.331 + {
1.332 + case RMMCSDTestControllerInterface::EStackEffectiveModesRemoveMode:
1.333 + iStackConfig.RemoveMode((TUint32)aParam);
1.334 + break;
1.335 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetBusClockInKhz:
1.336 + iStackConfig.SetBusClockInKhz((TUint)aParam);
1.337 + break;
1.338 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetBusyTimeOutInMcs:
1.339 + iStackConfig.SetBusyTimeOutInMcs((TUint)aParam);
1.340 + break;
1.341 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetCRCRetries:
1.342 + iStackConfig.SetCRCRetries((TUint)aParam);
1.343 + break;
1.344 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetDataTimeOutInMcs:
1.345 + iStackConfig.SetDataTimeOutInMcs((TUint)aParam);
1.346 + break;
1.347 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetMode:
1.348 + iStackConfig.SetMode((TUint32)aParam);
1.349 + break;
1.350 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetOpCondBusyTimeout:
1.351 + iStackConfig.SetOpCondBusyTimeout((TUint16)((TInt)aParam));
1.352 + break;
1.353 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetPollAttempts:
1.354 + iStackConfig.SetPollAttempts((TUint)aParam);
1.355 + break;
1.356 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetResponseTimeOutInTicks:
1.357 + iStackConfig.SetResponseTimeOutInTicks((TUint)aParam);
1.358 + break;
1.359 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetTicksClockIn:
1.360 + iStackConfig.SetTicksClockIn((TUint)aParam);
1.361 + break;
1.362 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetTicksClockOut:
1.363 + iStackConfig.SetTicksClockOut((TUint)aParam);
1.364 + break;
1.365 + case RMMCSDTestControllerInterface::EStackEffectiveModesSetTimeOutRetries:
1.366 + iStackConfig.SetTimeOutRetries((TUint)aParam);
1.367 + break;
1.368 + default:
1.369 + r = KErrNotFound;
1.370 + break;
1.371 + };
1.372 + return r;
1.373 + }
1.374 +