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