mtptransports/mtpptpiptransport/ptpipcontroller/src/cptpipcontroller.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "cptpipcontroller.h"	// Cptpipcontroller	
       
    17 
       
    18 #include <mtp/tmtptypeuint128.h>
       
    19 #include "ptpipsocketpublish.h"
       
    20 #include <in_sock.h>
       
    21 #include "ptpipprotocolconstants.h"
       
    22 
       
    23 
       
    24  
       
    25 _LIT_SECURITY_POLICY_PASS(KAllowReadAll);
       
    26 _LIT_SECURITY_POLICY_C1(KProcPolicy,ECapability_None);
       
    27 __FLOG_STMT(_LIT8(KComponent,"PTPIPController");)
       
    28 
       
    29 
       
    30 #define PTPIP_INIT_COMMAND_REQUEST	1
       
    31 #define PTPIP_INIT_COMMAND_ACK		2
       
    32 #define PTPIP_INIT_EVENT_REQUEST	3
       
    33 #define PTPIP_INIT_FAIL				5
       
    34 #define PTPIP_FIXED_CONNECTION_ID	1
       
    35 #define PTPIP_PRPTOCOL_VERSION		0x00000001
       
    36 
       
    37 
       
    38 enum TPTPIPControllerPanicReasons
       
    39     {
       
    40     EPanicTransportNotStarted     = 0,
       
    41     };
       
    42 
       
    43 
       
    44 EXPORT_C CPTPIPController* CPTPIPController::NewLC()
       
    45 	{
       
    46 	CPTPIPController* self = new (ELeave) CPTPIPController;
       
    47 	CleanupStack::PushL(self);
       
    48 	self->ConstructL();
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 /*
       
    53  Factory Method
       
    54 */
       
    55 EXPORT_C CPTPIPController* CPTPIPController::NewL()
       
    56 	{
       
    57 	CPTPIPController* self = CPTPIPController::NewLC();
       
    58 	CleanupStack::Pop(1);
       
    59 	return self;
       
    60 	}
       
    61 
       
    62 
       
    63 CPTPIPController::CPTPIPController():
       
    64 		CActive(EPriorityStandard),iDeviceGUID()
       
    65 	{
       
    66 	iCtrlState=EIdle;
       
    67 	iTransportId=TUid::Uid(KMTPPTPIPTransportImplementationUid);
       
    68 	iCounter=0;
       
    69 	CActiveScheduler::Add(this);
       
    70 	}
       
    71 
       
    72 /*
       
    73 Creates two PTPIP SocketHandlers and handles the sockets to 
       
    74 PTPIP SocketHandler & loads the Filter plugin.
       
    75 */
       
    76 void CPTPIPController::ConstructL()
       
    77 	{
       
    78    	 __FLOG_OPEN(KMTPSubsystem, KComponent);	 
       
    79 	 iCmdHandler = CPTPIPSocketHandler::NewL();
       
    80 	 iEvtHandler = CPTPIPSocketHandler::NewL();
       
    81 	 iFilter=CPTPIPHostFilterInterface::NewL();
       
    82 	 iInitCmdAck   = CPTPIPInitCmdAck::NewL(); 
       
    83 	 iTimer=CPTPIPTimer::NewL(*this);	 
       
    84 	 	
       
    85 	TParameter param=EDeviceFriendlyName;
       
    86 	
       
    87 	iIsConnectedToMTP = EFalse;
       
    88 	iDeviceGUID.Set(0,0);
       
    89 	const TUint32 KUidMTPRepositoryValue(0x10282FCC);
       
    90 	const TUid KUidMTPRepository = {KUidMTPRepositoryValue};
       
    91 	iRepository = CRepository::NewL(KUidMTPRepository);		
       
    92 	iDeviceFriendlyName = HBufC16::NewL(100);
       
    93 	TPtr16 name = iDeviceFriendlyName->Des();	
       
    94 	TInt result=iRepository->Get(param,name);		
       
    95 	}
       
    96 
       
    97 /*
       
    98 Destructor
       
    99 */
       
   100 EXPORT_C CPTPIPController::~CPTPIPController()
       
   101 	{
       
   102 	delete iCmdHandler;
       
   103    	delete iEvtHandler;
       
   104    	delete iFilter; 
       
   105    	delete iTimer;
       
   106    	delete iDeviceFriendlyName;  
       
   107 	delete iRepository;
       
   108 	delete iInitCmdReq;
       
   109 	delete iInitCmdAck;
       
   110    	iMTP.Close();
       
   111 	iIsConnectedToMTP = EFalse;
       
   112 	iProperty.Close();
       
   113 	iConnectionState.Close();
       
   114    	__FLOG_CLOSE;
       
   115 	}
       
   116 
       
   117 
       
   118 
       
   119 EXPORT_C RSocket& CPTPIPController::NewSocketL()
       
   120 	{
       
   121 	iCounter++;
       
   122 	if(iCounter==1)
       
   123 	return iCmdHandler->Socket();
       
   124 	else if(iCounter==2)
       
   125 	return iEvtHandler->Socket();
       
   126 	else
       
   127 	return iDummySocket;
       
   128 	//Issue :If Newsocket is called 4 time then we are going to give 
       
   129 	 //the same socket that we have given him third time.
       
   130 	
       
   131 	}
       
   132 TInt  CPTPIPController::CheckMTPConnection()
       
   133 {
       
   134 	TInt error = KErrNone;
       
   135 	if(iIsConnectedToMTP == EFalse)
       
   136 		{
       
   137 		error = iMTP.Connect();	
       
   138 		}	
       
   139 	if(error ==KErrNone) 
       
   140 		{
       
   141 		iIsConnectedToMTP = ETrue;		
       
   142 		error = iMTP.IsAvailable(iTransportId);
       
   143 		}
       
   144     return error;
       
   145 }
       
   146 /*
       
   147 Validates the socket connection based on the current value of iCtrlState
       
   148 @return ETrue on succes EFalse on failure*/
       
   149 TBool CPTPIPController::Validate()
       
   150 	{
       
   151 	if(iCtrlState==EIdle || iCtrlState==EInitEvtAwaited)
       
   152 	return ETrue;
       
   153 	else 
       
   154 	return EFalse;
       
   155 	}
       
   156 
       
   157 
       
   158 /*Saves the CommandSocket and EventSocket;The respective SocketHandlers are given the sockets
       
   159 and Calls itself on a CompleteSelf()
       
   160  @param aSocket Pointer to socket
       
   161  @param TRequestStatus of the caller i.e., CPTPIPAgent
       
   162 */ 
       
   163 EXPORT_C void CPTPIPController::SocketAccepted(TRequestStatus& aStatus)
       
   164 	{
       
   165    	iCallerStatus=&aStatus;
       
   166    	aStatus=KRequestPending;    	   		
       
   167 	TBool result=Validate();
       
   168 	if(result==EFalse)
       
   169 		{
       
   170 		User::RequestComplete(iCallerStatus,KErrServerBusy);
       
   171 		return;
       
   172 		}
       
   173 	
       
   174     if(iCtrlState==EInitEvtAwaited)  
       
   175     	{ // we are not gracefully rejecting a new PTPIP connection from other  host
       
   176     	  // as of now just socket closed.
       
   177         if(CompareHost(iEvtHandler->Socket())==EFalse)
       
   178         	{       
       
   179         	User::RequestComplete(iCallerStatus,KErrServerBusy);	
       
   180         	return;
       
   181  			}
       
   182     	}
       
   183 	if(iCtrlState==EPTPIPConnected)  
       
   184     	{ 
       
   185          /*if(CompareHost(iDummySocket->Socket())==EFalse)
       
   186           *	User::RequestComplete(status,KErrServerBusy);	
       
   187           *	Note : As of now this check is not required because 
       
   188           * call to Validate(0) will fail. 	
       
   189          */
       
   190  		}
       
   191 	 			
       
   192 	/*
       
   193 	Check whether PTPIPController is in a state of accepting new socket connections
       
   194 	*/
       
   195 	if (iCtrlState == EIdle)
       
   196       	{      
       
   197       	iCtrlState = EInitCommandAwaited;
       
   198       	}       
       
   199     else if (iCtrlState == EInitEvtAwaited)
       
   200       	{        
       
   201        	iCtrlState = EInitEvtAwaited;
       
   202       	}
       
   203       	
       
   204       Schedule();        
       
   205 	}
       
   206 	
       
   207 	
       
   208 /*
       
   209 Compares whether the second connection request is from the same remote host
       
   210 @param returns ETrue if the second request comes from the same host
       
   211 */	
       
   212 TBool CPTPIPController::CompareHost(RSocket& aSocket)
       
   213 	{
       
   214      
       
   215 	TInetAddr  thisaddr, newAddr;
       
   216      
       
   217     iCmdHandler->Socket().RemoteName(thisaddr);     
       
   218 	aSocket.RemoteName(newAddr);	
       
   219     if(newAddr.Address() == thisaddr.Address())
       
   220     	{
       
   221 		return ETrue;
       
   222     	}
       
   223     else
       
   224     	{
       
   225    	 	return EFalse;
       
   226     	}
       
   227 
       
   228 	}		
       
   229 			
       
   230 /**
       
   231 Schedules the next request phase or event.
       
   232 */
       
   233 void CPTPIPController::Schedule()
       
   234 	{	 
       
   235  	iStatus = KRequestPending; 
       
   236  	TRequestStatus* status(&iStatus);  
       
   237     SetActive();
       
   238     User::RequestComplete(status, KErrNone);	 
       
   239 	}
       
   240 
       
   241 /*
       
   242  Defines the two socket names to be published
       
   243  @return one of the system wide error codes on failure
       
   244 */
       
   245 TInt  CPTPIPController::PublishSocketNamePair()
       
   246 	{
       
   247 	TName iCommandSocketSysName,iEventSocketSysName;			  
       
   248    	iCmdHandler->Socket().Name(iCommandSocketSysName);
       
   249    	iEvtHandler->Socket().Name(iEventSocketSysName);
       
   250 	
       
   251 	
       
   252 	
       
   253 	/******************Define command socket system name************************/		
       
   254 	RProcess serverprocess;
       
   255 	
       
   256 	const TUid KPropertyUid= serverprocess.Identity();		
       
   257    
       
   258     TInt error=iProperty.Define(KPropertyUid,ECommandSocketName,RProperty::EText,KAllowReadAll,KAllowReadAll);
       
   259    
       
   260     error=iProperty.Attach(KPropertyUid,ECommandSocketName);
       
   261    
       
   262 	error=RProperty::Set(KPropertyUid,ECommandSocketName,iCommandSocketSysName);    
       
   263 
       
   264 	/*****************Define event socket system name***********************/		
       
   265 	
       
   266 	error=iProperty.Define(KPropertyUid,EEventSocketName,RProperty::EText,KAllowReadAll,KAllowReadAll);
       
   267 	
       
   268 	error=iProperty.Attach(KPropertyUid,EEventSocketName);
       
   269 	
       
   270     error=RProperty::Set(KPropertyUid,EEventSocketName,iEventSocketSysName);  
       
   271 	
       
   272 	return error;
       
   273 	}
       
   274 	
       
   275 
       
   276 /*Makes the sockets Transfer enabled
       
   277  @return one of the system wide error codes on failure
       
   278  */
       
   279 TInt CPTPIPController::EnableSocketTransfer()
       
   280 	{
       
   281 	TInt err;
       
   282 	err = iCmdHandler->Socket().SetOpt(KSOEnableTransfer, KSOLSocket,KProcPolicy().Package());	
       
   283 	
       
   284 	if(err != KErrNone) return err;
       
   285 	
       
   286 	err = iEvtHandler->Socket().SetOpt(KSOEnableTransfer, KSOLSocket,KProcPolicy().Package());
       
   287 	
       
   288 	 return err;
       
   289 	}	
       
   290 
       
   291 /*
       
   292 Sets the obtained DeviceGUID as the current DeviceGUID
       
   293 @param TDesC8& aDeviceGUID
       
   294 @return TInt KErrArgument if DeviceGUID is invalid or KErrNone
       
   295 */
       
   296 EXPORT_C TInt CPTPIPController::SetDeviceGUID(TDesC8& aDeviceGUID)
       
   297 	{	     
       
   298     TInt size = aDeviceGUID.Size();
       
   299     if (size != 16) return KErrArgument;
       
   300 	TMTPTypeUint128  guid(aDeviceGUID);	
       
   301 	iDeviceGUID = guid;	
       
   302 	return KErrNone;
       
   303 	}
       
   304 
       
   305 /*
       
   306 Sets the obtained DeviceFriendlyName
       
   307 @param TDesC16* aDeviceGUID
       
   308 */    
       
   309 EXPORT_C void CPTPIPController::SetDeviceFriendlyName(TDesC16* aDeviceFreindlyName)
       
   310 	{
       
   311 	delete iDeviceFriendlyName;
       
   312 	
       
   313 	TRAPD(err, iDeviceFriendlyName=aDeviceFreindlyName->AllocL());
       
   314 	
       
   315 	if(err != KErrNone)
       
   316 		{
       
   317 		 __FLOG_VA((_L8("CPTPIPController::SetDeviceFriendlyName ERROR = %d\n"), err));	
       
   318 		}
       
   319 	
       
   320 	}
       
   321 	
       
   322 
       
   323 void CPTPIPController::Reset()
       
   324 	{
       
   325 	iCmdHandler->Socket().Close();
       
   326 	iEvtHandler->Socket().Close();
       
   327 	if(iIsConnectedToMTP)
       
   328 	{
       
   329 	TInt stopStatus=iMTP.StopTransport(iTransportId);
       
   330 	if (KErrNone != stopStatus)
       
   331 	{
       
   332 	 __FLOG_VA((_L8("CPTPIPController::Reset ERROR = %d\n"), stopStatus));	
       
   333 	}	
       
   334 		
       
   335 	}
       
   336 				
       
   337 	iMTP.Close();
       
   338 	iProperty.Close();
       
   339 	iConnectionState.Close();
       
   340 	iCounter=0;
       
   341 	iIsConnectedToMTP = EFalse;	
       
   342 	iCtrlState = EIdle;	
       
   343 	iCmdHandler->State()=EReadState;
       
   344 	iEvtHandler->State()=EReadState;
       
   345 	}
       
   346 
       
   347 EXPORT_C void CPTPIPController::StopTransport()
       
   348 	{
       
   349 	Reset();
       
   350 	}
       
   351 
       
   352 
       
   353 
       
   354 void CPTPIPController:: CheckAndHandleErrorL(TInt  aError)
       
   355 	{		
       
   356 	if(aError != KErrNone)
       
   357 		{
       
   358 		Reset();							
       
   359 		__FLOG_VA((_L8("PTPIP Controller CheckAndHandleErrorL, Error = %d"), aError));	
       
   360 		User::Leave(aError);
       
   361 		}
       
   362 	}
       
   363 	
       
   364 void CPTPIPController:: CheckInitFailL(TInt aError)	
       
   365 	{
       
   366 	
       
   367 	TInitFailReason reason = EInitFailUnSpecified;
       
   368 		
       
   369 	// we send Init fail packet to Initiator on command channel
       
   370 	// even after InitEvent is received.
       
   371 	if(aError!=KErrNone && (iCtrlState==EInitCommandRead|| iCtrlState==EInitEventRead))
       
   372 		{
       
   373 		if(aError == KErrAccessDenied)
       
   374 			{
       
   375 			reason = EInitFailRejected;
       
   376 			}
       
   377 		BuildInitFailL(reason);  				 				 				 		
       
   378 		iCtrlState= EWaitForInitFail;
       
   379 		if(iCmdHandler->State()==EWriteState)
       
   380 		iCmdHandler->WriteToSocket(iInitFailed,iStatus);		
       
   381 		else
       
   382 		iEvtHandler->WriteToSocket(iInitFailed,iStatus);	
       
   383 		StartTimer(30);
       
   384 		__FLOG_VA((_L8("PTPIP Controller Error, Error = %d"), aError));
       
   385 		User::Leave(aError);					
       
   386 		}	
       
   387 	}	
       
   388 
       
   389 /*
       
   390 Cause a Time-Out event to occur
       
   391 */
       
   392 EXPORT_C void CPTPIPController::OnTimeOut()
       
   393 	{
       
   394 	TRequestStatus* status(&iStatus);
       
   395 	User::RequestComplete(status,KErrTimedOut);
       
   396 	}
       
   397 	
       
   398 void CPTPIPController::StartTimer(TInt aSecond)	
       
   399 	{	
       
   400 		iTimer->IssueRequest(aSecond);
       
   401 		iStatus = KRequestPending;	
       
   402 		SetActive(); 	
       
   403 	}
       
   404 	
       
   405 void CPTPIPController::RunL()
       
   406 	{
       
   407 	
       
   408 	TInt StatusError=iStatus.Int();
       
   409 		
       
   410 	if(iCmdHandler->IsActive() || iEvtHandler->IsActive())	
       
   411 	{		
       
   412 	if(iCmdHandler->IsActive())
       
   413 	iCmdHandler->Cancel();
       
   414 	if(iEvtHandler->IsActive())
       
   415 	iEvtHandler->Cancel();
       
   416 	
       
   417 	}
       
   418 	else if(iTimer->IsActive())
       
   419 	{	
       
   420 	iTimer->Cancel();	
       
   421 	}
       
   422 
       
   423     TPtrC8 hostGUID;
       
   424 	TInt error;
       
   425  	 switch(iCtrlState)
       
   426   	{
       
   427   		case EIdle:
       
   428   			 break;
       
   429 
       
   430    		case EInitCommandAwaited :    		   			
       
   431    		   				
       
   432    				iInitCmdReq   = CPTPIPInitCmdRequest::NewL();  
       
   433    											
       
   434      			iCmdHandler->ReadFromSocket(*iInitCmdReq,iStatus);        			  							
       
   435  				iCtrlState=EInitCommandRead;
       
   436  												 										
       
   437 				StartTimer(30);
       
   438   				break;
       
   439  
       
   440   		case EInitCommandRead:
       
   441   				CheckAndHandleErrorL(StatusError);
       
   442   				
       
   443 
       
   444   				error = ParseInitPacketL();  				
       
   445   				CheckInitFailL(error);
       
   446   				
       
   447   				// Need special error number for MTP not available 
       
   448   				// so that licensee can understand it.
       
   449   				if(iMTP.IsProcessRunning() != KErrNotFound )
       
   450 	  				{
       
   451 					error = CheckMTPConnection();
       
   452 	                CheckInitFailL(error);  					
       
   453 	  				}
       
   454 
       
   455   				//coverity[unchecked_value]
       
   456                 iHostGUID.FirstReadChunk(hostGUID);               
       
   457                 
       
   458                 iFilter->Accept(*iHostFriendlyName,hostGUID,iStatus);               
       
   459                 iCtrlState=EFilterConsentAwaited;                
       
   460                 StartTimer(30);                
       
   461   				break;
       
   462  
       
   463  		 case EFilterConsentAwaited:  		  		 	
       
   464  		 			 	 		  		 	
       
   465                 // Please wriet in function in m class that filter must send KErrAccessDenied
       
   466  		 		CheckInitFailL(StatusError );
       
   467  				//give error code for rejection.
       
   468  				BuildInitAckL();  				 							
       
   469  				iCtrlState = EWaitForInitCommandAck; 				
       
   470  				iCmdHandler->WriteToSocket(*iInitCmdAck,iStatus); 				 				
       
   471  				StartTimer(30); 				
       
   472 				break;
       
   473 				
       
   474  		case EWaitForInitFail : 
       
   475  		       // Do not call any other leaving function here 		                 
       
   476  		       // because RunError is going to ignore it.
       
   477  		       
       
   478  		       // Error code is wrong if this happens due to local error.
       
   479                 CheckAndHandleErrorL(KErrAccessDenied);                                
       
   480                 break;
       
   481 				
       
   482  		case EWaitForInitCommandAck :  
       
   483                 CheckAndHandleErrorL(StatusError);                
       
   484 				iCtrlState = EInitEvtAwaited;				
       
   485   				User::RequestComplete(iCallerStatus,KErrNone); 
       
   486 				break;
       
   487 				   				  	
       
   488  
       
   489   		case EInitEvtAwaited:
       
   490   		   				 	  			  		   		   				 				  								
       
   491   				iEvtHandler->ReadFromSocket(iInitEvtReq,iStatus);
       
   492   				iCtrlState=EInitEventRead;  				
       
   493   				StartTimer(30);  			
       
   494   				break;
       
   495  
       
   496   		case EInitEventRead:    			 			
       
   497  					 				
       
   498                	CheckInitFailL(StatusError);
       
   499   				error = ParseEvtPacket();
       
   500   				CheckInitFailL(error);
       
   501   				               	
       
   502 				error = EnableSocketTransfer();
       
   503 				CheckInitFailL(error);
       
   504 				
       
   505   				error = PublishSocketNamePair();
       
   506   				CheckInitFailL(error);
       
   507   				
       
   508   				error = CheckMTPConnection();                             
       
   509                 CheckInitFailL(error); 
       
   510   				error = iMTP.StartTransport(iTransportId);
       
   511   	  			CheckAndHandleErrorL(error);
       
   512   	  				
       
   513   				/************Subscribe to the state of plugin********/  				
       
   514   				TInt connState;
       
   515   				error = iConnectionState.Attach(KMTPPublishConnStateCat,EMTPConnStateKey);
       
   516   				CheckAndHandleErrorL(error);
       
   517   				error = iConnectionState.Get(KMTPPublishConnStateCat,EMTPConnStateKey,connState);   				
       
   518   				CheckAndHandleErrorL(error);
       
   519                	iConnectionState.Subscribe(iStatus);                	            	              	               	
       
   520                	iCtrlState = EPTPIPConnected;               	
       
   521                	SetActive();               
       
   522                	break;
       
   523                 
       
   524                
       
   525   		case EPTPIPConnected:  	
       
   526   			{
       
   527 			error=iConnectionState.Get(connState);  				
       
   528 			if((error!=KErrNone) || (connState==EDisconnectedFromHost))
       
   529   				{  					
       
   530   				Reset();						
       
   531 				User::RequestComplete(iCallerStatus,KErrNone);				
       
   532   				}
       
   533   			else
       
   534 	  			{
       
   535 				iConnectionState.Subscribe(iStatus);
       
   536 	 		    SetActive();
       
   537 	  			}
       
   538 			break;
       
   539   			}  				
       
   540   		default :
       
   541 	  		{
       
   542 	  		break;  			
       
   543 	  		}
       
   544 
       
   545   	} 
       
   546  	
       
   547 	}
       
   548 
       
   549 /*
       
   550 Over-ridden to return KErrNone by checking the state of PTPIP Controller
       
   551 */
       
   552 TInt CPTPIPController::RunError(TInt aErr)	
       
   553 	{			
       
   554    		if(iCtrlState != EWaitForInitFail)
       
   555    		{ 
       
   556    		User::RequestComplete(iCallerStatus,aErr);   			
       
   557 		iCtrlState = EIdle;
       
   558 		iCmdHandler->State()=EReadState;
       
   559 		iEvtHandler->State()=EReadState;
       
   560 		iCounter=0;		
       
   561 		iMTP.Close();		
       
   562 		iIsConnectedToMTP = EFalse; 			   	
       
   563    		}
       
   564    		//Return KErrNone back to RunL()
       
   565    		return KErrNone;
       
   566 	}
       
   567 	
       
   568 
       
   569 
       
   570 
       
   571 void CPTPIPController::DoCancel()
       
   572 	{
       
   573 
       
   574 	}
       
   575 	
       
   576 TInt CPTPIPController::ParseInitPacketL()
       
   577 {
       
   578 		TUint32 length(iInitCmdReq->Uint32L(CPTPIPInitCmdRequest::ELength));
       
   579 		TUint32 type(iInitCmdReq->Uint32L(CPTPIPInitCmdRequest::EPktType));
       
   580 		if(type != PTPIP_INIT_COMMAND_REQUEST) 
       
   581 			{
       
   582 			return KErrBadHandle;	
       
   583 			}
       
   584 		
       
   585 		iInitCmdReq->GetL(CPTPIPInitCmdRequest::EInitiatorGUID,iHostGUID);
       
   586 
       
   587 
       
   588 		TDesC& name = iInitCmdReq->HostFriendlyName();
       
   589 		iHostFriendlyName = &name;
       
   590 		TUint32 version(iInitCmdReq->Uint32L(CPTPIPInitCmdRequest::EVersion));
       
   591 		return KErrNone;
       
   592 }
       
   593 
       
   594 TInt CPTPIPController::ParseEvtPacket()
       
   595 {
       
   596 		TUint32 length(iInitEvtReq.Uint32(TPTPIPInitEvtRequest::ELength));
       
   597 		TUint32 type(iInitEvtReq.Uint32(TPTPIPInitEvtRequest::EType));	
       
   598 		if(type != PTPIP_INIT_EVENT_REQUEST) return KErrBadHandle;
       
   599 		TUint32 conNumber(iInitEvtReq.Uint32(TPTPIPInitEvtRequest::EconNumber));	
       
   600 		if(conNumber !=PTPIP_FIXED_CONNECTION_ID)
       
   601 			{ 
       
   602 			// We are supporting only one connection,So connection Id is fixed.
       
   603 			return KErrBadHandle;
       
   604 			}
       
   605 
       
   606 		return KErrNone;
       
   607 }
       
   608 void CPTPIPController::BuildInitAckL()
       
   609 {	
       
   610 	iInitCmdAck->SetUint32L(CPTPIPInitCmdAck::EPktType,PTPIP_INIT_COMMAND_ACK);
       
   611 	// We are supporting only one connection,So connection Id is fixed
       
   612 	iInitCmdAck->SetUint32L(CPTPIPInitCmdAck::EConNumber,PTPIP_FIXED_CONNECTION_ID);
       
   613 
       
   614 	iInitCmdAck->SetL(CPTPIPInitCmdAck::EResponderGUID,iDeviceGUID);
       
   615 
       
   616 	iInitCmdAck->SetDeviceFriendlyName(*iDeviceFriendlyName);
       
   617 	iInitCmdAck->SetUint32L(CPTPIPInitCmdAck::EVersion,PTPIP_PRPTOCOL_VERSION);
       
   618 	TUint64 size =  iInitCmdAck->Size();
       
   619 	iInitCmdAck->SetUint32L(CPTPIPInitCmdAck::ELength,(TUint32)size);	
       
   620 }
       
   621 
       
   622 void CPTPIPController::BuildInitFailL(TInitFailReason aReason)
       
   623 {	
       
   624 	iInitFailed.SetUint32(TPTPIPInitFailed::ELength,iInitFailed.Size());
       
   625 	iInitFailed.SetUint32(TPTPIPInitFailed::EType,PTPIP_INIT_FAIL);
       
   626 	iInitFailed.SetUint32(TPTPIPInitFailed::EReason,aReason);		
       
   627 }
       
   628 
       
   629 TBool E32Dll()
       
   630 {
       
   631 	return ETrue;
       
   632 }
       
   633 
       
   634 
       
   635