os/boardsupport/haitest/bspsvs/suite/bsp/mmc/ldd/src/mmclddstack.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 *
    16 */
    17 
    18 
    19 #include <kernel.h>
    20 #include <mmc.h>
    21 #include <locmedia.h>
    22 
    23 #include "mmcldd.h"
    24 #include "d_mmcsdif.h"
    25 
    26 /**
    27  * Do a kernel side control for DMMCStack
    28  *
    29  * @param TInt aFunction - Request Function ID
    30  * @param TAny* a1 - Given parameter
    31  * @param TAny* a2 - Given parameter
    32  *
    33  * @return TInt the error code
    34  *
    35  * @leave N/A
    36  */
    37 TInt DLddMmcCntrlInterface::StackDoControl(TInt aFunction, TAny* a1, TAny* a2)
    38 	{
    39 	MMCSDLOG3(
    40 			"DLddMmcCntrlInterface::StackDoControl aFunction(%d) \
    41 			TTCFunctionId(aFunction).FunctionId()(%d)",
    42 			aFunction, TTCFunctionId(aFunction).FunctionId());
    43 	TInt ret = KErrNone;
    44 	
    45 	if (!iStack)
    46 		{
    47   		MMCSDLOG("DLddMmcCntrlInterface::StackDoControl - iStack is NULL");		
    48 		return KErrGeneral;
    49 		}
    50 	else if (!iClient)
    51 		{
    52   		MMCSDLOG("DLddMmcCntrlInterface::StackDoControl - iClient is NULL");		
    53 		return KErrGeneral;
    54 		}
    55 
    56 	switch (TTCFunctionId(aFunction).FunctionId())
    57 		{
    58 		case RMMCSDTestControllerInterface::EStack:
    59 			{
    60 			MMCSDLOG("case RMMCSDTestControllerInterface::EStack");
    61 			ret = Kern::ThreadRawWrite(iClient, a1, &iStack, sizeof(iStack));
    62 			}
    63 			break;
    64 		case RMMCSDTestControllerInterface::EStackAdjustPartialRead:
    65 			{
    66 			if (!iCard)
    67 				{
    68 				MMCSDLOG("RMMCSDTestControllerInterface::EStackAdjustPartialRead NULL card\n");
    69 				return KErrNotReady;
    70 				}
    71 
    72 			TPartialReadData partialReadData;
    73 			Kern::ThreadRawRead(iClient, a1, &partialReadData,
    74 					sizeof(partialReadData));
    75 			iStack->AdjustPartialRead(iCard, partialReadData.iStart,
    76 					partialReadData.iEnd,
    77 					(TUint32*)&(partialReadData.iPhysStart),
    78 					(TUint32*)&(partialReadData.iPhysEnd));
    79 			ret = Kern::ThreadRawWrite(iClient, a1, &partialReadData,
    80 					sizeof(partialReadData));
    81 			}
    82 			break;
    83 		case RMMCSDTestControllerInterface::EStackAllocSession:
    84 			{
    85 			// just a simple test to check p1 call of DMMCStack::AllocSession
    86 			// the session is tested further within the DLddAsyncRequest class
    87 			// which each uses their own session (allocated from DMMCStack::AllocSession)			
    88 			MMCSDLOG("pre AllocSession");
    89 			DMMCSession* session = iStack->AllocSession(TMMCCallBack());
    90 			MMCSDLOG2("post AllocSession session = %x", session);
    91 			delete session;
    92 			}
    93 			break;
    94 		case RMMCSDTestControllerInterface::EStackBufferInfo:
    95 			{
    96 			MMCSDLOG("RMMCSDTestControllerInterface::EStackBufferInfo");
    97 			TBufferInfo bufInfo;
    98 			iStack->BufferInfo(bufInfo.iBuf, bufInfo.iBufLen,
    99 					bufInfo.iMinorBufLen);
   100 			Kern::ThreadRawWrite(iClient, a1, &bufInfo, sizeof(bufInfo));
   101 			}
   102 			break;
   103 		case RMMCSDTestControllerInterface::EStackGetBufferInfo:
   104 			{
   105 			MMCSDLOG("RMMCSDTestControllerInterface::EStackGetBufferInfo");
   106 			TBufferInfo bufInfo;
   107 			iStack->GetBufferInfo(&bufInfo.iBuf, &bufInfo.iBufLen);
   108 			Kern::ThreadRawWrite(iClient, a1, &bufInfo, sizeof(bufInfo));
   109 			}
   110 			break;
   111 
   112 		case RMMCSDTestControllerInterface::EStackCardP:
   113 			{
   114      		TCardPtr cardPtr;     		
   115       		ret = Kern::ThreadRawRead(iClient, a1, &cardPtr, sizeof(cardPtr));	 
   116 			if( ret == KErrNone )
   117 				{
   118 		  		MMCSDLOG("Calling RMMCSDTestControllerInterface::EStackCardP");
   119 		  		MMCSDLOG2("cardNumber=%d", cardPtr.iCardNumber);
   120 		  		iCard = iStack->CardP(cardPtr.iCardNumber);
   121 		  		MMCSDLOG2("cardPtr=%x", iCard);
   122 		  		cardPtr.iCardPtr = iCard;
   123 				ret = Kern::ThreadRawWrite(iClient, a1, &cardPtr, sizeof(cardPtr));
   124 				}
   125 			}
   126 			break;
   127 
   128 		case RMMCSDTestControllerInterface::EStackDemandPagingInfo:
   129 			{
   130 			DMMCStack::TDemandPagingInfo dpInfo;
   131 			ret = iStack->DemandPagingInfo(dpInfo);
   132 
   133 			if (ret == KErrNone)
   134 				{
   135 				TTCDemandPagingInfo info;
   136 				info.iDriveCount = dpInfo.iDriveCount;
   137 				info.iNumPages = dpInfo.iNumPages;
   138 				info.iPagingDriveList = dpInfo.iPagingDriveList;
   139 				info.iPagingType = dpInfo.iPagingType;
   140 				info.iReadShift = dpInfo.iReadShift;
   141 				info.iWriteProtected = dpInfo.iWriteProtected;
   142 				ret = Kern::ThreadRawWrite(iClient, a1, &info, sizeof(info));
   143 				}
   144 			else
   145 				{
   146 				MMCSDLOG2(
   147 						"RMMCSDTestControllerInterface::EStackDemandPagingInfo err(%d)",
   148 						ret);
   149 				}
   150 			}
   151 			break;
   152 
   153 		case RMMCSDTestControllerInterface::EStackEffectiveModes:
   154 			{
   155 			TUint32 rval = iStack->EffectiveModes(iStackConfig);
   156 			ret = Kern::ThreadRawWrite(iClient, a1, &rval, sizeof(rval));
   157 			}
   158 			break;
   159 
   160 		case RMMCSDTestControllerInterface::EStackHasCardsPresent:
   161 			{
   162 			TBool cardsPresent = iStack->HasCardsPresent();
   163 			ret = Kern::ThreadRawWrite(iClient, a1, &cardsPresent,
   164 					sizeof(cardsPresent));
   165 			}
   166 			break;
   167 		case RMMCSDTestControllerInterface::EStackHasSessionsQueued:
   168 			{
   169 			TBool sessionsQueued = iStack->HasSessionsQueued();
   170 			ret = Kern::ThreadRawWrite(iClient, a1, &sessionsQueued,
   171 					sizeof(sessionsQueued));
   172 			}
   173 			break;
   174 		case RMMCSDTestControllerInterface::EStackInit:
   175 			ret = iStack->Init();
   176 			break;
   177 		case RMMCSDTestControllerInterface::EStackInitStackInProgress:
   178 			{
   179 			TBool inProgress = iStack->InitStackInProgress();
   180 			ret = Kern::ThreadRawWrite(iClient, a1, &inProgress,
   181 					sizeof(inProgress));
   182 			}
   183 			break;
   184 		case RMMCSDTestControllerInterface::EStackMMCSocket:
   185 			{
   186 			MMCSDLOG("case RMMCSDTestControllerInterface::EStackMMCSocket");
   187 			DMMCSocket* socketPtr = iStack->MMCSocket();
   188 			MMCSDLOG3("Socket Ptr (%x)   &socketPtr(%x)", socketPtr,
   189 					&socketPtr);
   190 			ret = Kern::ThreadRawWrite(iClient, a1, &socketPtr,
   191 					sizeof(socketPtr));
   192 			}
   193 			break;
   194 		case RMMCSDTestControllerInterface::EStackMachineInfo:
   195 			{
   196 			TMMCMachineInfo mi;
   197 			iStack->MachineInfo(mi);
   198 			TMachineInfo machineInfo(mi);
   199 			ret = Kern::ThreadRawWrite(iClient, a1, &machineInfo, sizeof(machineInfo));
   200 			}
   201 			break;
   202 		case RMMCSDTestControllerInterface::EStackMaxCardsInStack:
   203 			{
   204 			TUint maxCards = iStack->MaxCardsInStack();
   205 			ret = Kern::ThreadRawWrite(iClient, a1, &maxCards, sizeof(maxCards));
   206 			}
   207 			break;
   208 		case RMMCSDTestControllerInterface::EStackReadPasswordStore:
   209 			{
   210 			TMMCPasswordStore* pps = iStack->PasswordStore();
   211 			TStackPasswordStoreData pwdStoreData;
   212 			pwdStoreData.iPwdStorePtr = pps;
   213 			if (pps)
   214 				{
   215 				TBuf8<KPasswordStoreCIDLength + KMmcPwdLen> formattedPassword;
   216 				ret = pps->ReadPasswordData(formattedPassword);
   217 				MMCSDLOG2("RMMCSDTestControllerInterface::EStackReadPasswordStore formattedPassword=%S", &formattedPassword);
   218 				
   219 				if (ret == KErrNone)
   220 					{
   221 					pwdStoreData.SetFormattedPassword(formattedPassword);
   222 					ret = Kern::ThreadRawWrite(iClient, a1, &pwdStoreData, sizeof(pwdStoreData));
   223 					}
   224 				}
   225 			else
   226 				{
   227 				MMCSDLOG("RMMCSDTestControllerInterface::EStackReadPasswordStore invalid pps");
   228 				ret = KErrGeneral;
   229 				}
   230 
   231 			MMCSDLOG3("RMMCSDTestControllerInterface::EStackReadPasswordStore #1 ret(%d) pwdStoreData.iPassword(%S)",
   232 						ret, &pwdStoreData.iPassword);
   233 			}
   234 			break;
   235 		case RMMCSDTestControllerInterface::EStackWritePasswordStore:
   236 			{
   237 			TStackPasswordStoreData pwdStoreData;
   238 			ret = Kern::ThreadRawRead(iClient, a1, &pwdStoreData, sizeof(pwdStoreData));
   239 			TMMCPasswordStore* pps = iStack->PasswordStore();
   240 			pwdStoreData.iPwdStorePtr = pps;
   241 			if (pps)
   242 				{
   243 				TBuf8<KPasswordStoreCIDLength + KMmcPwdLen> formattedPassword;
   244 				if (pwdStoreData.CreateFormattedPassword(formattedPassword, iCard->CID()))
   245 					{
   246 					MMCSDLOG2("RMMCSDTestControllerInterface::EStackWritePasswordStore formattedPassword=%S", &formattedPassword);
   247 					ret = pps->WritePasswordData(formattedPassword);				
   248 					}
   249 				else
   250 					{
   251 					MMCSDLOG("RMMCSDTestControllerInterface::EStackWritePasswordStore - CreateFormattedPassword() failed");
   252 					ret = KErrGeneral;
   253 					}
   254 				}
   255 			else
   256 				{
   257 				MMCSDLOG("RMMCSDTestControllerInterface::EStackWritePasswordStore invalid pps");
   258 				ret = KErrGeneral;
   259 				}
   260 			MMCSDLOG3(
   261 					"RMMCSDTestControllerInterface::EStackWritePasswordStore ret(%d) pwdStoreData.iPassword(%S)",
   262 					ret, &pwdStoreData.iPassword);
   263 			}
   264 			break;
   265 			
   266 		case RMMCSDTestControllerInterface::EStackProgramPeriodInMs:
   267 			{
   268 			TInt periodMs = iStack->ProgramPeriodInMilliSeconds();
   269 			ret
   270 					= Kern::ThreadRawWrite(iClient, a1, &periodMs,
   271 							sizeof(periodMs));
   272 			}
   273 			break;
   274 
   275 		case RMMCSDTestControllerInterface::EStackStop:
   276 			{
   277 			if (!iCard)
   278 				{
   279 				MMCSDLOG("RMMCSDTestControllerInterface::EStackStop NULL card\n");
   280 				return KErrNotReady;
   281 				}
   282 
   283 			ret = iStack->Stop(iCard);
   284 			}
   285 			break;
   286 
   287 		case RMMCSDTestControllerInterface::EStackReportPowerUp:
   288 			iStack->ReportPowerUp();
   289 			break;
   290 			
   291 		case RMMCSDTestControllerInterface::EStackReportPowerDown:
   292 			iStack->ReportPowerDown();
   293 			break;
   294 			
   295 		case RMMCSDTestControllerInterface::EStackConfigureEffectiveModes:
   296 			if (!a1)
   297 				{
   298 				return KErrArgument;
   299 				}
   300 			ret = StackConfigureEffectiveModes((TInt) a1, a2);
   301 			break;
   302 
   303 		default:
   304 			ret = KErrNotFound;
   305 			break;
   306 		}
   307 	return ret;
   308 	}
   309 
   310 /**
   311  * Configure the Effectivemodes parameter for all TMMCStackConfig functions
   312  *
   313  * @param TInt aEffectiveModesFunctionId - Effective Modes Function ID
   314  * @param TAny* aParam - Given Effective Modes Function parameter
   315  *
   316  * @return TInt the error code
   317  *
   318  * @leave N/A
   319  */
   320 TInt DLddMmcCntrlInterface::StackConfigureEffectiveModes(
   321 		TInt aEffectiveModesFunctionId, TAny* aParam)
   322 	{
   323 	// used to handle requests to configure the iStackConfig (Effectivemodes)
   324 	// parameter for all TMMCStackConfig functions is max 32 bit value so passes in as value aParam
   325 
   326 	TInt r = KErrNone; // all functions return void	
   327 	switch ((RMMCSDTestControllerInterface::TEffectiveModesFunctionId) aEffectiveModesFunctionId)
   328 		{
   329 		case RMMCSDTestControllerInterface::EStackEffectiveModesRemoveMode:
   330 			iStackConfig.RemoveMode((TUint32)aParam);
   331 			break;
   332 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetBusClockInKhz:
   333 			iStackConfig.SetBusClockInKhz((TUint)aParam);
   334 			break;
   335 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetBusyTimeOutInMcs:
   336 			iStackConfig.SetBusyTimeOutInMcs((TUint)aParam);
   337 			break;
   338 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetCRCRetries:
   339 			iStackConfig.SetCRCRetries((TUint)aParam);
   340 			break;
   341 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetDataTimeOutInMcs:
   342 			iStackConfig.SetDataTimeOutInMcs((TUint)aParam);
   343 			break;
   344 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetMode:
   345 			iStackConfig.SetMode((TUint32)aParam);
   346 			break;
   347 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetOpCondBusyTimeout:
   348 			iStackConfig.SetOpCondBusyTimeout((TUint16)((TInt)aParam));
   349 			break;
   350 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetPollAttempts:
   351 			iStackConfig.SetPollAttempts((TUint)aParam);
   352 			break;
   353 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetResponseTimeOutInTicks:
   354 			iStackConfig.SetResponseTimeOutInTicks((TUint)aParam);
   355 			break;
   356 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetTicksClockIn:
   357 			iStackConfig.SetTicksClockIn((TUint)aParam);
   358 			break;
   359 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetTicksClockOut:
   360 			iStackConfig.SetTicksClockOut((TUint)aParam);
   361 			break;
   362 		case RMMCSDTestControllerInterface::EStackEffectiveModesSetTimeOutRetries:
   363 			iStackConfig.SetTimeOutRetries((TUint)aParam);
   364 			break;
   365 		default:
   366 			r = KErrNotFound;
   367 			break;
   368 		};
   369 	return r;
   370 	}
   371