os/boardsupport/haitest/bspsvs/suite/bsp/mmc/ldd/src/mmclddsocket.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 DMMCSocket
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::SocketDoControl(TInt aFunction, TAny* a1, TAny* a2)
sl@0
    38
	{
sl@0
    39
	TInt ret=KErrNone;
sl@0
    40
	
sl@0
    41
	if (!iSocket)
sl@0
    42
		{
sl@0
    43
  		MMCSDLOG("DLddMmcCntrlInterface::SocketDoControl - iSocket is NULL");		
sl@0
    44
		return KErrGeneral;
sl@0
    45
		}
sl@0
    46
	else if (!iClient)
sl@0
    47
		{
sl@0
    48
  		MMCSDLOG("DLddMmcCntrlInterface::SocketDoControl - iClient is NULL");		
sl@0
    49
		return KErrGeneral;
sl@0
    50
		}
sl@0
    51
sl@0
    52
	switch (TTCFunctionId(aFunction).FunctionId())
sl@0
    53
		{
sl@0
    54
      	case RMMCSDTestControllerInterface::ESocket:
sl@0
    55
      		{
sl@0
    56
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocket");
sl@0
    57
			ret = Kern::ThreadRawWrite(iClient, a1, &iSocket, sizeof(iSocket)); 		
sl@0
    58
      		}
sl@0
    59
	  		break;
sl@0
    60
	  		
sl@0
    61
      	case RMMCSDTestControllerInterface::ESocketAdjustPartialRead:
sl@0
    62
      		{      		
sl@0
    63
      		TPartialReadData partialReadData;
sl@0
    64
    		ret = Kern::ThreadRawRead(iClient, a1, &partialReadData, sizeof(partialReadData));	
sl@0
    65
			if( ret == KErrNone )
sl@0
    66
				{    				    			    		
sl@0
    67
		  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketAdjustPartialRead");
sl@0
    68
	      		MMCSDLOG3("start=%d, end=%d", partialReadData.iStart, partialReadData.iEnd);
sl@0
    69
		  		MMCSDLOG2("cardPtr=%x", iCard);
sl@0
    70
	    		iSocket->AdjustPartialRead(iCard, partialReadData.iStart, partialReadData.iEnd
sl@0
    71
	    									, (TUint32*)&(partialReadData.iPhysStart)
sl@0
    72
	    									, (TUint32*)&(partialReadData.iPhysEnd));
sl@0
    73
	    		ret = Kern::ThreadRawWrite(iClient, a1, &partialReadData, sizeof(partialReadData));
sl@0
    74
				}
sl@0
    75
      		}
sl@0
    76
      		break;
sl@0
    77
      	
sl@0
    78
      	case RMMCSDTestControllerInterface::ESocketCardIsPresent:
sl@0
    79
      		{      		
sl@0
    80
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketCardIsPresent");
sl@0
    81
    		TBool cardPresent = iSocket->CardIsPresent();	    		
sl@0
    82
    		ret = Kern::ThreadRawWrite(iClient, a1, &cardPresent, sizeof(cardPresent));
sl@0
    83
      		}
sl@0
    84
      		break;
sl@0
    85
      		
sl@0
    86
      	case RMMCSDTestControllerInterface::ESocketGetBufferInfo:
sl@0
    87
      		{	
sl@0
    88
			TBufferInfo bufInfo;
sl@0
    89
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketGetBufferInfo");
sl@0
    90
	  		iSocket->GetBufferInfo(&bufInfo.iBuf, &bufInfo.iBufLen);
sl@0
    91
			ret = Kern::ThreadRawWrite(iClient, a1, &bufInfo, sizeof(bufInfo));
sl@0
    92
      		}
sl@0
    93
      		break;
sl@0
    94
sl@0
    95
	  	case RMMCSDTestControllerInterface::ESocketInit:
sl@0
    96
	  		{
sl@0
    97
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketInit");
sl@0
    98
	  		ret = iSocket->Init();
sl@0
    99
	  		}
sl@0
   100
	  		break;
sl@0
   101
	  		
sl@0
   102
	  	case RMMCSDTestControllerInterface::ESocketInitiatePowerUpSequence:
sl@0
   103
	  		{
sl@0
   104
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketInitiatePowerUpSequence");
sl@0
   105
	  		iSocket->InitiatePowerUpSequence();
sl@0
   106
	  		}
sl@0
   107
	  		break;
sl@0
   108
  		
sl@0
   109
      	case RMMCSDTestControllerInterface::ESocketMachineInfo:
sl@0
   110
      		{
sl@0
   111
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketMachineInfo");
sl@0
   112
      		TMachineInfo machineInfo(iSocket->MachineInfo());
sl@0
   113
      		ret = Kern::ThreadRawWrite(iClient, a1, &machineInfo, sizeof(machineInfo));	
sl@0
   114
      		}
sl@0
   115
  			break;	  		
sl@0
   116
sl@0
   117
      	case RMMCSDTestControllerInterface::ESocketPrepareStore:
sl@0
   118
      		{	
sl@0
   119
      		TPasswordPrepareStoreData pwdData;     		
sl@0
   120
      		ret = Kern::ThreadRawRead(iClient, a1, &pwdData, sizeof(pwdData));	 
sl@0
   121
			if( ret == KErrNone )
sl@0
   122
				{
sl@0
   123
		  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketPrepareStore");
sl@0
   124
	      		MMCSDLOG5("bus=%d, func=%d, newPassword=%S, oldPassword=%S"
sl@0
   125
	      				, pwdData.iBus, pwdData.iFunc, &pwdData.iNewPassword, &pwdData.iOldPassword);      		
sl@0
   126
	      		TLocalDrivePasswordData ld;
sl@0
   127
	      		if( pwdData.iNewPassword == _L("NULL") )
sl@0
   128
	      			{
sl@0
   129
		      		ld.iNewPasswd = NULL;
sl@0
   130
			  		MMCSDLOG("Using iNewPasswd=NULL");
sl@0
   131
	      			}
sl@0
   132
	      		else
sl@0
   133
	      			{
sl@0
   134
	      			ld.iNewPasswd = &pwdData.iNewPassword;
sl@0
   135
	      			}
sl@0
   136
	      		if( pwdData.iOldPassword == _L("NULL") )
sl@0
   137
	      			{
sl@0
   138
		      		ld.iOldPasswd = NULL;
sl@0
   139
			  		MMCSDLOG("Using iOldPasswd=NULL");
sl@0
   140
	      			}
sl@0
   141
	      		else
sl@0
   142
	      			{
sl@0
   143
	      			ld.iOldPasswd = &pwdData.iOldPassword;
sl@0
   144
	      			}
sl@0
   145
	      		ret = iSocket->PrepareStore(pwdData.iBus, pwdData.iFunc, ld);     
sl@0
   146
				}
sl@0
   147
      		}
sl@0
   148
      		break;
sl@0
   149
sl@0
   150
      	case RMMCSDTestControllerInterface::ESocketReset1:
sl@0
   151
      		{
sl@0
   152
  			MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketReset1");
sl@0
   153
			iSocket->Reset1();
sl@0
   154
      		}
sl@0
   155
	  		break;
sl@0
   156
	  		
sl@0
   157
	  	case RMMCSDTestControllerInterface::ESocketReset2:
sl@0
   158
	  		{
sl@0
   159
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketReset2");
sl@0
   160
	  		iSocket->Reset2();
sl@0
   161
	  		}
sl@0
   162
	  		break;
sl@0
   163
	  		
sl@0
   164
	  	case RMMCSDTestControllerInterface::ESocketResetInactivity:
sl@0
   165
	  		{
sl@0
   166
	  		TInt busNumber;
sl@0
   167
     		ret = Kern::ThreadRawRead(iClient, a1, &busNumber, sizeof(busNumber));     		
sl@0
   168
			if( ret == KErrNone )
sl@0
   169
				{
sl@0
   170
		  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketResetInactivity");
sl@0
   171
		  		MMCSDLOG2("busNumber=%d", busNumber);
sl@0
   172
	     		iSocket->ResetInactivity(busNumber); 
sl@0
   173
				}
sl@0
   174
	  		}
sl@0
   175
	  		break;
sl@0
   176
sl@0
   177
      	case RMMCSDTestControllerInterface::ESocketStack:
sl@0
   178
      		{
sl@0
   179
      		TStackPtr stackPtr;     		
sl@0
   180
      		ret = Kern::ThreadRawRead(iClient, a1, &stackPtr, sizeof(stackPtr));	 
sl@0
   181
			if( ret == KErrNone )
sl@0
   182
				{
sl@0
   183
		  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketStack");
sl@0
   184
		  		MMCSDLOG2("busNumber=%d", stackPtr.iBus);
sl@0
   185
				stackPtr.iStackPtr = iSocket->Stack(stackPtr.iBus);
sl@0
   186
				ret = Kern::ThreadRawWrite(iClient, a1, &stackPtr, sizeof(stackPtr));
sl@0
   187
				}
sl@0
   188
      		}
sl@0
   189
	  		break;
sl@0
   190
sl@0
   191
      	case RMMCSDTestControllerInterface::ESocketiState_Get:
sl@0
   192
	  		{
sl@0
   193
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketiState_Get");
sl@0
   194
	  		MMCSDLOG2("iState=%d", iSocket->iState);
sl@0
   195
			ret = Kern::ThreadRawWrite(iClient, a1, &iSocket->iState, sizeof(iSocket->iState));
sl@0
   196
	  		}
sl@0
   197
	  		break;
sl@0
   198
	  		
sl@0
   199
		case RMMCSDTestControllerInterface::ESocketiStandby_Get:
sl@0
   200
	        {
sl@0
   201
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketiStandby_Get");
sl@0
   202
       	    MMCSDLOG2("iStandby=%d", &iSocket->iStandby);
sl@0
   203
       	    ret = Kern::ThreadRawWrite(iClient, a1, &iSocket->iStandby, sizeof(iSocket->iStandby));
sl@0
   204
            }
sl@0
   205
            break;
sl@0
   206
            
sl@0
   207
		case RMMCSDTestControllerInterface::ESocketiType_Get:
sl@0
   208
	        {
sl@0
   209
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketiType_Get");
sl@0
   210
       	    MMCSDLOG2("iType=%d", &iSocket->iType);
sl@0
   211
       	    ret = Kern::ThreadRawWrite(iClient, a1, &iSocket->iType, sizeof(iSocket->iType));
sl@0
   212
            }
sl@0
   213
            break;
sl@0
   214
            
sl@0
   215
      	case RMMCSDTestControllerInterface::ESocketiDoorOpened_Get:
sl@0
   216
        	{
sl@0
   217
	  		MMCSDLOG("Calling RMMCSDTestControllerInterface::ESocketiDoorOpened_Get");
sl@0
   218
       	    MMCSDLOG2("iDoorOpened=%d", &iSocket->iDoorOpened);
sl@0
   219
       	    ret = Kern::ThreadRawWrite(iClient, a1, &iSocket->iDoorOpened, sizeof(iSocket->iDoorOpened));
sl@0
   220
			}
sl@0
   221
        	break;
sl@0
   222
	  			  		
sl@0
   223
        default:
sl@0
   224
           	ret=KErrNotFound;
sl@0
   225
			break;
sl@0
   226
		}
sl@0
   227
	return(ret);
sl@0
   228
	}
sl@0
   229
sl@0
   230
/**
sl@0
   231
 * Do a kernel side request for DMMCSocket
sl@0
   232
 *
sl@0
   233
 * @param TRequestStatus* aStatus - Request Status
sl@0
   234
 * @param TAny* a1 - Given parameter
sl@0
   235
 * @param TAny* a2 - Given parameter
sl@0
   236
 * @param TInt aCommand - Request Function ID
sl@0
   237
 *
sl@0
   238
 * @return TInt the error code
sl@0
   239
 *
sl@0
   240
 * @leave N/A
sl@0
   241
 */
sl@0
   242
TInt DLddMmcCntrlInterface::SocketDoRequest(TRequestStatus* aStatus, TAny* a1, TAny *a2, TInt aCommand)
sl@0
   243
	{
sl@0
   244
	MMCSDLOG2("~~~ SocketDoRequest called iAsyncFunction(%x)", aCommand);
sl@0
   245
sl@0
   246
	if (!iSocket)
sl@0
   247
		{
sl@0
   248
  		MMCSDLOG("DLddMmcCntrlInterface::SocketDoRequest - iSocket is NULL");		
sl@0
   249
		return KErrGeneral;
sl@0
   250
		}
sl@0
   251
sl@0
   252
	TInt ret = KErrNone;
sl@0
   253
	switch (TTCFunctionId(aCommand).FunctionId())
sl@0
   254
		// iAsyncFunction initialized in DoRequest
sl@0
   255
		{
sl@0
   256
		case RMMCSDTestControllerInterface::ESocketPowerUp:
sl@0
   257
			{
sl@0
   258
			MMCSDLOG("Performing RMMCSDTestControllerInterface::ESocketPowerUp");
sl@0
   259
			
sl@0
   260
#ifdef __DEBUG
sl@0
   261
			MMCSDLOG("RMMCSDTestControllerInterface::ESocketPowerUp - Not available in debug build");
sl@0
   262
			ret = KErrNotSupported;
sl@0
   263
#else
sl@0
   264
			ret = iSocket->PowerUp();
sl@0
   265
#endif
sl@0
   266
sl@0
   267
			if ( (ret == KErrNone) || (ret == KErrCompletion) )
sl@0
   268
				{
sl@0
   269
				CreateAsyncBusEventRequest( DLddMmcCntrlInterface::EMMcSocketPowerUp, aStatus, iUnit);
sl@0
   270
				}
sl@0
   271
			else
sl@0
   272
				{
sl@0
   273
				Kern::RequestComplete(iClient, aStatus, ret);
sl@0
   274
				}
sl@0
   275
			}
sl@0
   276
			break;
sl@0
   277
		default:
sl@0
   278
			break;
sl@0
   279
		}
sl@0
   280
	return ret;
sl@0
   281
	}