mtptransports/mtpptpiptransport/ptpipplugin/src/cptpipconnection.cpp
changeset 49 c20dd21d1eb4
parent 17 aabe5387f5ce
child 54 4dc88a4ac6f4
equal deleted inserted replaced
41:2c19c7cf5550 49:c20dd21d1eb4
    25 // MTP includes
    25 // MTP includes
    26 #include <mtp/mtpprotocolconstants.h>
    26 #include <mtp/mtpprotocolconstants.h>
    27 #include <mtp/tmtptyperesponse.h>
    27 #include <mtp/tmtptyperesponse.h>
    28 
    28 
    29 // Plugin includes
    29 // Plugin includes
       
    30 #include "mtpdebug.h"
    30 #include "cptpipcommandhandler.h"
    31 #include "cptpipcommandhandler.h"
    31 #include "cptpipeventhandler.h"
    32 #include "cptpipeventhandler.h"
    32 #include "cptpipconnection.h"
    33 #include "cptpipconnection.h"
    33 #include "ptpipsocketpublish.h" 
    34 #include "ptpipsocketpublish.h"
       
    35 #include "OstTraceDefinitions.h"
       
    36 #ifdef OST_TRACE_COMPILER_IN_USE
       
    37 #include "cptpipconnectionTraces.h"
       
    38 #endif
       
    39  
    34 
    40 
    35 // File type constants.
    41 // File type constants.
    36 const TInt KMTPNullChunkSize(0x00020000); // 100KB
    42 const TInt KMTPNullChunkSize(0x00020000); // 100KB
    37 const TUint32 KPTPIPDataHeaderSize = 12;  // Size of len, type and tran id. 
    43 const TUint32 KPTPIPDataHeaderSize = 12;  // Size of len, type and tran id. 
    38 __FLOG_STMT(_LIT8(KComponent,"PTPIPConnection");)
       
    39 #define UNUSED_VAR(a) (a) = (a)
    44 #define UNUSED_VAR(a) (a) = (a)
    40 
    45 
    41 /**
    46 /**
    42  PTPIP device class connection factory method.
    47  PTPIP device class connection factory method.
    43  @param aConnectionMgr The MTP connection manager interface.
    48  @param aConnectionMgr The MTP connection manager interface.
    44  @return A pointer to an PTPIP device class connection. Ownership IS transfered.
    49  @return A pointer to an PTPIP device class connection. Ownership IS transfered.
    45  @leave One of the system wide error codes, if a processing failure occurs.
    50  @leave One of the system wide error codes, if a processing failure occurs.
    46  */
    51  */
    47 CPTPIPConnection* CPTPIPConnection::NewL(MMTPConnectionMgr& aConnectionMgr )
    52 CPTPIPConnection* CPTPIPConnection::NewL(MMTPConnectionMgr& aConnectionMgr )
    48 	{
    53 	{
       
    54 	OstTraceFunctionEntry0( CPTPIPCONNECTION_NEWL_ENTRY );
    49 	CPTPIPConnection* self = new(ELeave) CPTPIPConnection(aConnectionMgr);
    55 	CPTPIPConnection* self = new(ELeave) CPTPIPConnection(aConnectionMgr);
    50 	CleanupStack::PushL (self );
    56 	CleanupStack::PushL (self );
    51 	self->ConstructL ( );
    57 	self->ConstructL ( );
    52 	CleanupStack::Pop (self );
    58 	CleanupStack::Pop (self );
       
    59 	OstTraceFunctionExit0( CPTPIPCONNECTION_NEWL_EXIT );
    53 	return self;
    60 	return self;
    54 	}
    61 	}
    55 
    62 
    56 /**
    63 /**
    57  Destructor
    64  Destructor
    58  */
    65  */
    59 CPTPIPConnection::~CPTPIPConnection( )
    66 CPTPIPConnection::~CPTPIPConnection( )
    60 	{
    67 	{
    61 	__FLOG(_L8("Destructor - Entry"));
    68 	OstTraceFunctionEntry0( CPTPIPCONNECTION_CPTPIPCONNECTION_ENTRY );
    62 	StopConnection ( );
    69 	StopConnection ( );
    63 
    70 
    64 	// Delete all the handlers which will close the sockets.
    71 	// Delete all the handlers which will close the sockets.
    65 	delete iCommandHandler;
    72 	delete iCommandHandler;
    66 	delete iEventHandler;
    73 	delete iEventHandler;
    73            {
    80            {
    74            iProtocolLayer->Unbind(*this);
    81            iProtocolLayer->Unbind(*this);
    75            }
    82            }
    76 	
    83 	
    77 	iNullBuffer.Close();
    84 	iNullBuffer.Close();
    78 
    85 	OstTraceFunctionExit0( CPTPIPCONNECTION_CPTPIPCONNECTION_EXIT );
    79 	__FLOG(_L8("Destructor - Exit"));
       
    80 	__FLOG_CLOSE;
       
    81 	}
    86 	}
    82 
    87 
    83 /**
    88 /**
    84  Second phase constructor
    89  Second phase constructor
    85  @leave One of the system wide error codes, if a processing failure occurs.
    90  @leave One of the system wide error codes, if a processing failure occurs.
    86  */
    91  */
    87 void CPTPIPConnection::ConstructL( )
    92 void CPTPIPConnection::ConstructL( )
    88 	{
    93 	{
    89 	__FLOG_OPEN(KMTPSubsystem, KComponent);
    94 	OstTraceFunctionEntry0( CPTPIPCONNECTION_CONSTRUCTL_ENTRY );
    90 	__FLOG(_L8("ConstructL - Entry"));
       
    91 
    95 
    92 	// Construct the Command and event handlers
    96 	// Construct the Command and event handlers
    93 	iCommandHandler = CPTPIPCommandHandler::NewL (*this );
    97 	iCommandHandler = CPTPIPCommandHandler::NewL (*this );
    94 	iEventHandler = CPTPIPEventHandler::NewL (*this );
    98 	iEventHandler = CPTPIPEventHandler::NewL (*this );
    95 
    99 
   101 	TransferSocketsL();
   105 	TransferSocketsL();
   102 
   106 
   103 	SetConnectionState (EInitialising );
   107 	SetConnectionState (EInitialising );
   104 	CompleteSelf (KErrNone );
   108 	CompleteSelf (KErrNone );
   105 
   109 
   106 	__FLOG(_L8("ConstructL - Exit"));
   110 	OstTraceFunctionExit0( CPTPIPCONNECTION_CONSTRUCTL_EXIT );
   107 	}
   111 	}
   108 
   112 
   109 /**
   113 /**
   110  Constructor
   114  Constructor
   111  */
   115  */
   112 CPTPIPConnection::CPTPIPConnection(MMTPConnectionMgr& aConnectionMgr ) :
   116 CPTPIPConnection::CPTPIPConnection(MMTPConnectionMgr& aConnectionMgr ) :
   113 									CActive(EPriorityStandard), 
   117 									CActive(EPriorityStandard), 
   114 									iConnectionMgr(&aConnectionMgr)
   118 									iConnectionMgr(&aConnectionMgr)
   115 	{
   119 	{
       
   120 	OstTraceFunctionEntry0( DUP1_CPTPIPCONNECTION_CPTPIPCONNECTION_ENTRY );
   116 	CActiveScheduler::Add (this );
   121 	CActiveScheduler::Add (this );
       
   122 	OstTraceFunctionExit0( DUP1_CPTPIPCONNECTION_CPTPIPCONNECTION_EXIT );
   117 	}
   123 	}
   118 
   124 
   119 //
   125 //
   120 // MMTPTransportConnection functions
   126 // MMTPTransportConnection functions
   121 //
   127 //
   125  @param aProtocol - The connectionProtocol provides the SPI or the observer
   131  @param aProtocol - The connectionProtocol provides the SPI or the observer
   126  for the communication to happen from the transport to the framework. 
   132  for the communication to happen from the transport to the framework. 
   127  */
   133  */
   128 void CPTPIPConnection::BindL(MMTPConnectionProtocol& aProtocol )
   134 void CPTPIPConnection::BindL(MMTPConnectionProtocol& aProtocol )
   129 	{
   135 	{
   130 	__FLOG(_L8("BindL - Entry"));
   136 	OstTraceFunctionEntry0( CPTPIPCONNECTION_BINDL_ENTRY );
   131 	iProtocolLayer = &aProtocol;
   137 	iProtocolLayer = &aProtocol;
   132 	__FLOG(_L8("BindL - Exit"));
   138 	OstTraceFunctionExit0( CPTPIPCONNECTION_BINDL_EXIT );
   133 	}
   139 	}
   134 
   140 
   135 /**
   141 /**
   136  Returns the protocol layer.
   142  Returns the protocol layer.
   137  @return The SPI or the observer protocol layer
   143  @return The SPI or the observer protocol layer
   138  */
   144  */
   139 MMTPConnectionProtocol& CPTPIPConnection::BoundProtocolLayer( )
   145 MMTPConnectionProtocol& CPTPIPConnection::BoundProtocolLayer( )
   140 	{
   146 	{
   141 	__FLOG(_L8("BoundProtocolLayer - Entry"));
   147 	OstTraceFunctionEntry0( CPTPIPCONNECTION_BOUNDPROTOCOLLAYER_ENTRY );
   142 	__ASSERT_ALWAYS(iProtocolLayer, Panic(EPTPIPBadState));
   148 	__ASSERT_ALWAYS(iProtocolLayer, Panic(EPTPIPBadState));
   143 	__FLOG(_L8("BoundProtocolLayer - Exit"));
   149 	OstTraceFunctionExit0( CPTPIPCONNECTION_BOUNDPROTOCOLLAYER_EXIT );
   144 	return *iProtocolLayer;
   150 	return *iProtocolLayer;
   145 	}
   151 	}
   146 
   152 
   147 /**
   153 /**
   148  Close the connection, stop all data transfer activity and and wait for the host 
   154  Close the connection, stop all data transfer activity and and wait for the host 
   149  to issue a Device Reset Request.
   155  to issue a Device Reset Request.
   150  */
   156  */
   151 void CPTPIPConnection::CloseConnection( )
   157 void CPTPIPConnection::CloseConnection( )
   152 	{
   158 	{
   153 	__FLOG(_L8("CloseConnection - Entry"));
   159 	OstTraceFunctionEntry0( CPTPIPCONNECTION_CLOSECONNECTION_ENTRY );
   154 	StopConnection ( );
   160 	StopConnection ( );
   155 	__FLOG(_L8("CloseConnection - Exit"));
   161 	OstTraceFunctionExit0( CPTPIPCONNECTION_CLOSECONNECTION_EXIT );
   156 	}
   162 	}
   157 
   163 
   158 /**
   164 /**
   159  A transaction is one set of request, data transfer and response phases. 
   165  A transaction is one set of request, data transfer and response phases. 
   160  The fw calls this to mark the end of an MTP transaction. 
   166  The fw calls this to mark the end of an MTP transaction. 
   161  */
   167  */
   162 void CPTPIPConnection::TransactionCompleteL(const TMTPTypeRequest& /*aRequest*/)
   168 void CPTPIPConnection::TransactionCompleteL(const TMTPTypeRequest& /*aRequest*/)
   163 	{
   169 	{
   164 	__FLOG(_L8("TransactionCompleteL - Entry"));
   170 	OstTraceFunctionEntry0( CPTPIPCONNECTION_TRANSACTIONCOMPLETEL_ENTRY );
   165 	__FLOG(_L8("******** Transaction Complete **************"));
   171 	OstTrace0( TRACE_NORMAL, CPTPIPCONNECTION_TRANSACTIONCOMPLETEL, "******** Transaction Complete **************" );
       
   172 
   166 	SetTransactionPhase (EIdlePhase );
   173 	SetTransactionPhase (EIdlePhase );
   167 
   174 
   168 	// Clear the cancel flag.
   175 	// Clear the cancel flag.
   169 	iCancelOnCommandState = ECancelNotReceived;
   176 	iCancelOnCommandState = ECancelNotReceived;
   170 	iCancelOnEventState = ECancelNotReceived;
   177 	iCancelOnEventState = ECancelNotReceived;
   171 
   178 
   172 	// Again start listening for the command request. 
   179 	// Again start listening for the command request. 
   173 	InitiateCommandRequestPhaseL( );
   180 	InitiateCommandRequestPhaseL( );
   174 
   181 
   175 	__FLOG(_L8("TransactionCompleteL - Exit"));
   182 	OstTraceFunctionExit0( CPTPIPCONNECTION_TRANSACTIONCOMPLETEL_EXIT );
   176 	}
   183 	}
   177 
   184 
   178 /**
   185 /**
   179  Called by the fw to indicate that protocol layer is not using this transport anymore 
   186  Called by the fw to indicate that protocol layer is not using this transport anymore 
   180  and so we will not have any callback/SPI funtions to the fw any more
   187  and so we will not have any callback/SPI funtions to the fw any more
   181  */
   188  */
   182 void CPTPIPConnection::Unbind(MMTPConnectionProtocol& /*aProtocol*/)
   189 void CPTPIPConnection::Unbind(MMTPConnectionProtocol& /*aProtocol*/)
   183 	{
   190 	{
   184 	__FLOG(_L8("Unbind - Entry"));
   191 	OstTraceFunctionEntry0( CPTPIPCONNECTION_UNBIND_ENTRY );
   185 	__ASSERT_DEBUG(iProtocolLayer, Panic(EPTPIPBadState));
   192 	__ASSERT_DEBUG(iProtocolLayer, Panic(EPTPIPBadState));
   186 	// Protocol will no longer be bound to the transport
   193 	// Protocol will no longer be bound to the transport
   187 	iProtocolLayer = NULL;
   194 	iProtocolLayer = NULL;
   188 	__FLOG(_L8("Unbind - Exit"));
   195 	OstTraceFunctionExit0( CPTPIPCONNECTION_UNBIND_EXIT );
   189 	}
   196 	}
   190 
   197 
   191 /**
   198 /**
   192  Not used
   199  Not used
   193  */
   200  */
   194 TAny* CPTPIPConnection::GetExtendedInterface(TUid /*aInterfaceUid*/)
   201 TAny* CPTPIPConnection::GetExtendedInterface(TUid /*aInterfaceUid*/)
   195 	{
   202 	{
       
   203 	OstTraceFunctionEntry0( CPTPIPCONNECTION_GETEXTENDEDINTERFACE_ENTRY );
       
   204 	OstTraceFunctionExit0( CPTPIPCONNECTION_GETEXTENDEDINTERFACE_EXIT );
   196 	return NULL;
   205 	return NULL;
   197 	}
   206 	}
   198 
   207 
   199 /*
   208 /*
   200  * return PTPIP transport implementation UID
   209  * return PTPIP transport implementation UID
   201  */
   210  */
   202 TUint CPTPIPConnection::GetImplementationUid()
   211 TUint CPTPIPConnection::GetImplementationUid()
   203     {
   212     {
       
   213     OstTraceFunctionEntry0( CPTPIPCONNECTION_GETIMPLEMENTATIONUID_ENTRY );
       
   214     OstTraceFunctionExit0( CPTPIPCONNECTION_GETIMPLEMENTATIONUID_EXIT );
   204     return KMTPPTPIPTransportImplementationUid;
   215     return KMTPPTPIPTransportImplementationUid;
   205     }
   216     }
   206 
   217 
   207 //
   218 //
   208 // Active Object functions
   219 // Active Object functions
   211 /**
   222 /**
   212  Used to cancel the outstanding requests, and reset internal states as appropriate. 
   223  Used to cancel the outstanding requests, and reset internal states as appropriate. 
   213  */
   224  */
   214 void CPTPIPConnection::DoCancel( )
   225 void CPTPIPConnection::DoCancel( )
   215 	{
   226 	{
   216 	__FLOG(_L8("DoCancel - Entry"));
   227 	OstTraceFunctionEntry0( CPTPIPCONNECTION_DOCANCEL_ENTRY );
   217 
   228 
   218 	iCommandHandler->Cancel( );
   229 	iCommandHandler->Cancel( );
   219 	iEventHandler->Cancel( );
   230 	iEventHandler->Cancel( );
   220 
   231 
   221 	SetConnectionState(ECancelled );
   232 	SetConnectionState(ECancelled );
   222 
   233 
   223 	__FLOG(_L8("DoCancel - Exit"));
   234 	OstTraceFunctionExit0( CPTPIPCONNECTION_DOCANCEL_EXIT );
   224 	}
   235 	}
   225 
   236 
   226 /**
   237 /**
   227 The connection behaves as an active object during the PTPIP connection establishment phase.
   238 The connection behaves as an active object during the PTPIP connection establishment phase.
   228 Subsequently, it behaves as a normal object whose functions are invoked by the MTP framework
   239 Subsequently, it behaves as a normal object whose functions are invoked by the MTP framework
   230 
   241 
   231 Thus the runl is not hit after the initial connection establishment. 
   242 Thus the runl is not hit after the initial connection establishment. 
   232  */
   243  */
   233 void CPTPIPConnection::RunL( )
   244 void CPTPIPConnection::RunL( )
   234 	{
   245 	{
   235 	__FLOG(_L8("RunL - Entry"));
   246 	OstTraceFunctionEntry0( CPTPIPCONNECTION_RUNL_ENTRY );
   236 	__FLOG_VA((_L8("Current State is %d, and status is %d"), iState, iStatus.Int()));
   247 	OstTraceExt2( TRACE_NORMAL, CPTPIPCONNECTION_RUNL, "Current State is %d, and status is %d", iState, iStatus.Int() );
       
   248 	
   237 
   249 
   238 	if(iStatus != KErrNone )
   250 	if(iStatus != KErrNone )
   239 		{
   251 		{
   240 		CloseConnection( );
   252 		CloseConnection( );
   241 		}
   253 		}
   261 			InitiateEventRequestPhaseL( );
   273 			InitiateEventRequestPhaseL( );
   262 			InitiateCommandRequestPhaseL( );
   274 			InitiateCommandRequestPhaseL( );
   263 			break;
   275 			break;
   264 
   276 
   265 		default:
   277 		default:
   266 			__FLOG(_L8("PTPIP ERROR: Invalid  connection state"));
   278 			OstTrace0( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_RUNL, "PTPIP ERROR: Invalid  connection state" );
       
   279 			
   267 			Panic(EPTPIPBadState );
   280 			Panic(EPTPIPBadState );
   268 			break;
   281 			break;
   269 		}
   282 		}
   270 		}
   283 		}
   271 
   284 
   272 	__FLOG(_L8("RunL - Exit"));
   285 	OstTraceFunctionExit0( CPTPIPCONNECTION_RUNL_EXIT );
   273 	}
   286 	}
   274 
   287 
   275 /**
   288 /**
   276  Called when an error occurs in the RunL 
   289  Called when an error occurs in the RunL 
   277  */
   290  */
   278 #ifdef __FLOG_ACTIVE
       
   279 TInt CPTPIPConnection::RunError(TInt aError )
   291 TInt CPTPIPConnection::RunError(TInt aError )
   280 #else
   292 	{
   281 TInt CPTPIPConnection::RunError(TInt /*aError*/ )
   293 	OstTraceFunctionEntry0( CPTPIPCONNECTION_RUNERROR_ENTRY );
   282 #endif
   294 	
   283 	{
   295 	OstTrace1( TRACE_NORMAL, CPTPIPCONNECTION_RUNERROR, "PTPIP ERROR: Error received is %d", aError );
   284 	__FLOG(_L8("RunError - Entry"));
   296 	
   285 	__FLOG_VA((_L8("PTPIP ERROR: Error received is %d"), aError));
       
   286 
   297 
   287 	// Cancel all the outstanding requests.
   298 	// Cancel all the outstanding requests.
   288 	Cancel( );
   299 	Cancel( );
   289 
   300 
   290 	// Stop the connection, if necessary.
   301 	// Stop the connection, if necessary.
   291 	StopConnection( );
   302 	StopConnection( );
   292 
   303 
   293 	__FLOG(_L8("RunError - Exit"));
   304 	OstTraceFunctionExit0( CPTPIPCONNECTION_RUNERROR_EXIT );
   294 	return KErrNone;
   305 	return KErrNone;
   295 	}
   306 	}
   296 
   307 
   297 //
   308 //
   298 // Receive data functions
   309 // Receive data functions
   303  This will invoke the command handler 
   314  This will invoke the command handler 
   304  to listen on the socket and get the data into the buffers passed. 
   315  to listen on the socket and get the data into the buffers passed. 
   305  */
   316  */
   306 void CPTPIPConnection::InitiateCommandRequestPhaseL( )
   317 void CPTPIPConnection::InitiateCommandRequestPhaseL( )
   307 	{
   318 	{
   308 	__FLOG(_L8("InitiateCommandRequestPhaseL - Entry"));
   319 	OstTraceFunctionEntry0( CPTPIPCONNECTION_INITIATECOMMANDREQUESTPHASEL_ENTRY );
   309 	__FLOG(_L8("******** Phase 1 - Request **************"));
   320 	OstTrace0( TRACE_NORMAL, CPTPIPCONNECTION_INITIATECOMMANDREQUESTPHASEL, "******** Phase 1 - Request **************" );
       
   321 	
   310 	// Set current state to request phase
   322 	// Set current state to request phase
   311 	SetTransactionPhase(ERequestPhase );
   323 	SetTransactionPhase(ERequestPhase );
   312 
   324 
   313 	// The PTPIP data buffer is a member of connection.  
   325 	// The PTPIP data buffer is a member of connection.  
   314 	// Since we are expecting a request now, set the payload to request type
   326 	// Since we are expecting a request now, set the payload to request type
   316 	iPTPIPCommandContainer->SetPayloadL(&iPTPIPRequestPayload );
   328 	iPTPIPCommandContainer->SetPayloadL(&iPTPIPRequestPayload );
   317 
   329 
   318 	// Call the CommandHandler to get the request in the container
   330 	// Call the CommandHandler to get the request in the container
   319 	iCommandHandler->ReceiveCommandRequestL(*iPTPIPCommandContainer );
   331 	iCommandHandler->ReceiveCommandRequestL(*iPTPIPCommandContainer );
   320 
   332 
   321 	__FLOG(_L8("InitiateCommandRequestPhaseL - Exit"));
   333 	OstTraceFunctionExit0( CPTPIPCONNECTION_INITIATECOMMANDREQUESTPHASEL_EXIT );
   322 	}
   334 	}
   323 
   335 
   324 /** 
   336 /** 
   325  Called to indicate completion of receive of data started by InitiateCommandRequestPhaseL.
   337  Called to indicate completion of receive of data started by InitiateCommandRequestPhaseL.
   326  There is no point in reporting the error up to the f/w since no transaction has started.
   338  There is no point in reporting the error up to the f/w since no transaction has started.
   327  USB does nothing at this stage. In PTP , the connection is closed.
   339  USB does nothing at this stage. In PTP , the connection is closed.
   328  @param aError - The error if any, received from socket.
   340  @param aError - The error if any, received from socket.
   329  */
   341  */
   330 void CPTPIPConnection::ReceiveCommandCompleteL(TInt aError )
   342 void CPTPIPConnection::ReceiveCommandCompleteL(TInt aError )
   331 	{
   343 	{
   332 	__FLOG(_L8("ReceiveCommandCompleteL - Entry"));
   344 	OstTraceFunctionEntry0( CPTPIPCONNECTION_RECEIVECOMMANDCOMPLETEL_ENTRY );
   333 
   345 
   334 	if(KErrNone != aError )
   346 	if(KErrNone != aError )
   335 		{
   347 		{
   336 		__FLOG_VA((_L8("PTPIP Error: Received error=%d in request phase, closing  connection"), aError));
   348 		OstTrace1( TRACE_NORMAL, CPTPIPCONNECTION_RECEIVECOMMANDCOMPLETEL, "PTPIP Error: Received error=%d in request phase, closing  connection", aError );
       
   349 		
   337 		CloseConnection( );
   350 		CloseConnection( );
   338 		}
   351 		}
   339 	else if(ValidateTransactionPhase(ERequestPhase ) )
   352 	else if(ValidateTransactionPhase(ERequestPhase ) )
   340 		{
   353 		{
   341 		// Request block received.
   354 		// Request block received.
   342 		TPTPIPTypeRequestPayload* pRequest = static_cast<TPTPIPTypeRequestPayload*>(iPTPIPCommandContainer->Payload());
   355 		TPTPIPTypeRequestPayload* pRequest = static_cast<TPTPIPTypeRequestPayload*>(iPTPIPCommandContainer->Payload());
   343 
   356 
   344 		TUint16 op(pRequest->Uint16(TPTPIPTypeRequestPayload::EOpCode ));
   357 		TUint16 op(pRequest->Uint16(TPTPIPTypeRequestPayload::EOpCode ));
   345 		TUint32	tran(pRequest->Uint32(TPTPIPTypeRequestPayload::ETransactionId ));
   358 		TUint32	tran(pRequest->Uint32(TPTPIPTypeRequestPayload::ETransactionId ));
   346 		TUint32 sessionId = KMTPSessionNone;
   359 		TUint32 sessionId = KMTPSessionNone;
   347 		__FLOG_VA((_L8("Command block received with op = 0x%04X ,transId = %d"), op, tran));
   360 		OstTraceExt2( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_RECEIVECOMMANDCOMPLETEL, "Command block received with op = 0x%04X ,transId = %d", static_cast<TUint32>(op), tran );
   348 
   361 		
   349 		// Reset the iMTPRequest.
   362 		// Reset the iMTPRequest.
   350 		iMTPRequest.Reset( );
   363 		iMTPRequest.Reset( );
   351 
   364 
   352 		// Setup the MTP request dataset buffer. Set Operation Code and TransactionID
   365 		// Setup the MTP request dataset buffer. Set Operation Code and TransactionID
   353 		iMTPRequest.SetUint16(TMTPTypeRequest::ERequestOperationCode, op );
   366 		iMTPRequest.SetUint16(TMTPTypeRequest::ERequestOperationCode, op );
   354 		iMTPRequest.SetUint32(TMTPTypeRequest::ERequestTransactionID, tran );
   367 		iMTPRequest.SetUint32(TMTPTypeRequest::ERequestTransactionID, tran );
   355 
   368 
   356 		// Set SessionID.
   369 		// Set SessionID.
   357 		if(op == EMTPOpCodeOpenSession )
   370 		if(op == EMTPOpCodeOpenSession )
   358 			{
   371 			{
   359 			__FLOG(_L8("Processing OpenSession request"));
   372 			OstTrace0( TRACE_NORMAL, DUP2_CPTPIPCONNECTION_RECEIVECOMMANDCOMPLETEL, "Processing OpenSession request" );
       
   373 			
   360 			}
   374 			}
   361 		else if(op == EMTPOpCodeCloseSession || op == EMTPOpCodeResetDevice )
   375 		else if(op == EMTPOpCodeCloseSession || op == EMTPOpCodeResetDevice )
   362 			{
   376 			{
   363 			__FLOG(_L8("Processing CloseSession or the ResetDevice request"));
   377 			OstTrace0( TRACE_NORMAL, DUP3_CPTPIPCONNECTION_RECEIVECOMMANDCOMPLETEL, "Processing CloseSession or the ResetDevice request" );
       
   378 			
   364 			// Force CloseSession requests to be processed outside an active session. 
   379 			// Force CloseSession requests to be processed outside an active session. 
   365 			// ResetDevice currently behaves the same way as CloseSession. 
   380 			// ResetDevice currently behaves the same way as CloseSession. 
   366 			iMTPRequest.SetUint32(TMTPTypeRequest::ERequestParameter1,
   381 			iMTPRequest.SetUint32(TMTPTypeRequest::ERequestParameter1,
   367 					iMTPSessionId );
   382 					iMTPSessionId );
   368 			}
   383 			}
   369 		else
   384 		else
   370 			{
   385 			{
   371 			sessionId = iMTPSessionId;
   386 			sessionId = iMTPSessionId;
   372 			__FLOG_VA((_L8("Processing general request on session %d"), sessionId));
   387 			OstTrace1( TRACE_NORMAL, DUP4_CPTPIPCONNECTION_RECEIVECOMMANDCOMPLETEL, "Processing general request on session %d", sessionId );
       
   388 			
   373 			}
   389 			}
   374 		
   390 		
   375 		iMTPRequest.SetUint32(TMTPTypeRequest::ERequestSessionID,sessionId );
   391 		iMTPRequest.SetUint32(TMTPTypeRequest::ERequestSessionID,sessionId );
   376 
   392 
   377 		// Set Parameter 1 .. Parameter 5.
   393 		// Set Parameter 1 .. Parameter 5.
   381 		// Notify the protocol layer.
   397 		// Notify the protocol layer.
   382 		
   398 		
   383 		BoundProtocolLayer().ReceivedRequestL(iMTPRequest );
   399 		BoundProtocolLayer().ReceivedRequestL(iMTPRequest );
   384 
   400 
   385 		}
   401 		}
   386 	__FLOG(_L8("ReceiveCommandCompleteL - Exit"));
   402 	OstTraceFunctionExit0( CPTPIPCONNECTION_RECEIVECOMMANDCOMPLETEL_EXIT );
   387 	}
   403 	}
   388 
   404 
   389 /**
   405 /**
   390  Called to get data over the command channel,( in turn its called by f/ws ReceiveData)
   406  Called to get data over the command channel,( in turn its called by f/ws ReceiveData)
   391  @param aData - The buffer provided by the F/w in which to receive data.
   407  @param aData - The buffer provided by the F/w in which to receive data.
   392  */
   408  */
   393 void CPTPIPConnection::ReceiveCommandDataL(MMTPType& aData )
   409 void CPTPIPConnection::ReceiveCommandDataL(MMTPType& aData )
   394 	{
   410 	{
   395 	__FLOG(_L8("ReceiveCommandDataL - Entry"));
   411 	OstTraceFunctionEntry0( CPTPIPCONNECTION_RECEIVECOMMANDDATAL_ENTRY );
   396 
   412 
   397 	iRecvData = 0;
   413 	iRecvData = 0;
   398 	iTotalRecvData = 0;
   414 	iTotalRecvData = 0;
   399 	
   415 	
   400 	// First we will receive a PTPIP start data packet which is stored in the commandContainer
   416 	// First we will receive a PTPIP start data packet which is stored in the commandContainer
   403 	// The mtp buffer is passed from the framework and will be passed on as the payload.
   419 	// The mtp buffer is passed from the framework and will be passed on as the payload.
   404 	// in the next ptpip data packet.
   420 	// in the next ptpip data packet.
   405 	iPTPIPDataContainer->SetPayloadL(&aData );
   421 	iPTPIPDataContainer->SetPayloadL(&aData );
   406 	iCommandHandler->ReceiveCommandDataL(*iPTPIPCommandContainer );
   422 	iCommandHandler->ReceiveCommandDataL(*iPTPIPCommandContainer );
   407 
   423 
   408 	__FLOG(_L8("ReceiveCommandDataL - Exit"));
   424 	OstTraceFunctionExit0( CPTPIPCONNECTION_RECEIVECOMMANDDATAL_EXIT );
   409 	}
   425 	}
   410 
   426 
   411 /**
   427 /**
   412  Called to indicate completion of receive of data started by ReceiveCommandDataL.
   428  Called to indicate completion of receive of data started by ReceiveCommandDataL.
   413  Any errors received are sent back up to the framework. 
   429  Any errors received are sent back up to the framework. 
   414  */
   430  */
   415 void CPTPIPConnection::ReceiveCommandDataCompleteL(TInt aError )
   431 void CPTPIPConnection::ReceiveCommandDataCompleteL(TInt aError )
   416 	{
   432 	{
   417 	__FLOG(_L8("ReceiveCommandDataCompleteL - Entry"));
   433 	OstTraceFunctionEntry0( CPTPIPCONNECTION_RECEIVECOMMANDDATACOMPLETEL_ENTRY );
   418 	if(ValidateTransactionPhase(EDataIToRPhase ) )
   434 	if(ValidateTransactionPhase(EDataIToRPhase ) )
   419 		{
   435 		{
   420 		// Data block received, notify the protocol layer.
   436 		// Data block received, notify the protocol layer.
   421 		iPTPIPDataContainer->SetUint32L(CPTPIPDataContainer::EPacketType, 0 );
   437 		iPTPIPDataContainer->SetUint32L(CPTPIPDataContainer::EPacketType, 0 );
   422 		BoundProtocolLayer().ReceiveDataCompleteL(aError, *iPTPIPDataContainer->Payload(), iMTPRequest );
   438 		BoundProtocolLayer().ReceiveDataCompleteL(aError, *iPTPIPDataContainer->Payload(), iMTPRequest );
   423 		}
   439 		}
   424 	__FLOG(_L8("ReceiveCommandDataCompleteL - Exit"));
   440 	OstTraceFunctionExit0( CPTPIPCONNECTION_RECEIVECOMMANDDATACOMPLETEL_EXIT );
   425 	}
   441 	}
   426 
   442 
   427 /**
   443 /**
   428  Called by the command handler to indicate completion of receive on the command channel.
   444  Called by the command handler to indicate completion of receive on the command channel.
   429  Now check whether it was commands or data completion and call the appropriate function. 
   445  Now check whether it was commands or data completion and call the appropriate function. 
   430  */
   446  */
   431 
   447 
   432 void CPTPIPConnection::ReceiveCommandChannelCompleteL(TInt aError, MMTPType& /*aSource*/)
   448 void CPTPIPConnection::ReceiveCommandChannelCompleteL(TInt aError, MMTPType& /*aSource*/)
   433 	{
   449 	{
   434 	__FLOG(_L8("ReceiveCommandChannelCompleteL - Entry"));
   450 	OstTraceFunctionEntry0( CPTPIPCONNECTION_RECEIVECOMMANDCHANNELCOMPLETEL_ENTRY );
   435 	__FLOG(_L8("******** Receiving 1 ptpip packet on command/data channel complete **************"));
   451 	OstTrace0( TRACE_NORMAL, CPTPIPCONNECTION_RECEIVECOMMANDCHANNELCOMPLETEL, "******** Receiving 1 ptpip packet on command/data channel complete **************" );
       
   452 	
   436 	HandleTCPError(aError );
   453 	HandleTCPError(aError );
   437 	TUint32	typeCommand = iPTPIPCommandContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   454 	TUint32	typeCommand = iPTPIPCommandContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   438 	TUint32	typeData = iPTPIPDataContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   455 	TUint32	typeData = iPTPIPDataContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   439 	__FLOG_VA((_L8("type on the command buffer is %d and type on the data buffer is %d"), typeCommand, typeData ) );
   456 	OstTraceExt2( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_RECEIVECOMMANDCHANNELCOMPLETEL, "type on the command buffer is %d and type on the data buffer is %d", typeCommand, typeData );
       
   457 	
   440 
   458 
   441 
   459 
   442 	switch (typeCommand)
   460 	switch (typeCommand)
   443 	{
   461 	{
   444 	case EPTPIPPacketTypeOperationRequest:
   462 	case EPTPIPPacketTypeOperationRequest:
   452 			}
   470 			}
   453 		else
   471 		else
   454 			{
   472 			{
   455 			// Save the total data expected. 
   473 			// Save the total data expected. 
   456 			iTotalRecvData =(static_cast<TPTPIPTypeStartDataPayload*>(iPTPIPCommandContainer->Payload()))->Uint64(TPTPIPTypeStartDataPayload::ETotalSize );
   474 			iTotalRecvData =(static_cast<TPTPIPTypeStartDataPayload*>(iPTPIPCommandContainer->Payload()))->Uint64(TPTPIPTypeStartDataPayload::ETotalSize );
   457 			__FLOG_VA((_L8("Total data to receive in data phase is %ld"), iTotalRecvData));						
   475 			OstTrace1( TRACE_NORMAL, DUP2_CPTPIPCONNECTION_RECEIVECOMMANDCHANNELCOMPLETEL, "Total data to receive in data phase is %ld", iTotalRecvData );
       
   476 			
   458 			
   477 			
   459 			//reset the command container 
   478 			//reset the command container 
   460 			iPTPIPCommandContainer->SetUint32L(CPTPIPGenericContainer::EPacketType, 0 );
   479 			iPTPIPCommandContainer->SetUint32L(CPTPIPGenericContainer::EPacketType, 0 );
   461 			iCommandHandler->ReceiveCommandDataL(*iPTPIPDataContainer );
   480 			iCommandHandler->ReceiveCommandDataL(*iPTPIPDataContainer );
   462 			}
   481 			}
   487 			{
   506 			{
   488 			iCommandHandler->iUseOffset = ETrue;	
   507 			iCommandHandler->iUseOffset = ETrue;	
   489 				
   508 				
   490 			}
   509 			}
   491 			
   510 			
   492 			
   511 			OstTrace1( TRACE_NORMAL, DUP3_CPTPIPCONNECTION_RECEIVECOMMANDCHANNELCOMPLETEL, "Data received so far in data phase is %ld", iRecvData );
   493 			__FLOG_VA((_L8("Data received so far in data phase is %ld"), iRecvData));
   512 			
   494 			if(iRecvData <= iTotalRecvData )
   513 			if(iRecvData <= iTotalRecvData )
   495 				{
   514 				{
   496 				iCommandHandler->ReceiveCommandDataL(*iPTPIPDataContainer );
   515 				iCommandHandler->ReceiveCommandDataL(*iPTPIPDataContainer );
   497 				}
   516 				}
   498 			else
   517 			else
   499 				{
   518 				{
   500 				__FLOG_VA((_L8("PTPIP ERROR: The data received so far= %ld is more than expected data = %ld "), iRecvData, iTotalRecvData));
   519                 TBuf<8> recvData;
       
   520                 recvData.Num( iRecvData, EDecimal );
       
   521                 TBuf<8> totalRecvData;
       
   522                 totalRecvData.Num( iTotalRecvData, EDecimal );
       
   523 				OstTraceExt2( TRACE_NORMAL, DUP5_CPTPIPCONNECTION_RECEIVECOMMANDCHANNELCOMPLETEL, "PTPIP ERROR: The data received so far= %S is more than expected data = %S",
       
   524 				        recvData, totalRecvData );
       
   525 				
   501 				CloseConnection( );
   526 				CloseConnection( );
   502 				}			
   527 				}			
   503 			break;
   528 			break;
   504 		
   529 		
   505 		case EPTPIPPacketTypeEndData:
   530 		case EPTPIPPacketTypeEndData:
   506 			iRecvData += iPTPIPDataContainer->Uint32L(CPTPIPDataContainer::EPacketLength );
   531 			iRecvData += iPTPIPDataContainer->Uint32L(CPTPIPDataContainer::EPacketLength );
   507 			iRecvData -= KPTPIPDataHeaderSize; // The header size is not included in the total size sent. 
   532 			iRecvData -= KPTPIPDataHeaderSize; // The header size is not included in the total size sent. 
   508 			
   533 			
   509 			iCommandHandler->iUseOffset = EFalse;
   534 			iCommandHandler->iUseOffset = EFalse;
   510 			
   535 			
   511 			__FLOG_VA((_L8("Data received so far in data phase is %ld"), iRecvData));
   536 			OstTrace1( TRACE_NORMAL, DUP6_CPTPIPCONNECTION_RECEIVECOMMANDCHANNELCOMPLETEL, "Data received so far in data phase is %ld", iRecvData );
       
   537 			
   512 			if(iTotalRecvData == iRecvData )
   538 			if(iTotalRecvData == iRecvData )
   513 				{
   539 				{
   514 				ReceiveCommandDataCompleteL(aError );
   540 				ReceiveCommandDataCompleteL(aError );
   515 				}
   541 				}
   516 			else
   542 			else
   517 				{
   543 				{
   518 				__FLOG_VA((_L8("PTPIP ERROR: The data received so far= %ld is not equal to expected data = %ld "), iRecvData, iTotalRecvData));
   544                 TBuf<8> recvData;
       
   545                 recvData.Num( iRecvData, EDecimal );
       
   546                 TBuf<8> totalRecvData;
       
   547                 totalRecvData.Num( iTotalRecvData, EDecimal );
       
   548 				OstTraceExt2( TRACE_NORMAL, DUP4_CPTPIPCONNECTION_RECEIVECOMMANDCHANNELCOMPLETEL, "PTPIP ERROR: The data received so far= %S is not equal to expected data = %S", recvData, totalRecvData );
       
   549 				
   519 				CloseConnection( );
   550 				CloseConnection( );
   520 				}
   551 				}
   521 			break;
   552 			break;
   522 		
   553 		
   523 		case EPTPIPPacketTypeCancel:
   554 		case EPTPIPPacketTypeCancel:
   528 			HandleCommandCancelL(transId);
   559 			HandleCommandCancelL(transId);
   529 			}
   560 			}
   530 			break;
   561 			break;
   531 		
   562 		
   532 		default:
   563 		default:
   533 			__FLOG_VA((_L8("PTPIP ERROR: Unexpected type received,  data container = %d, command container =%d "), typeData, typeCommand));
   564 			OstTraceExt2( TRACE_NORMAL, DUP7_CPTPIPCONNECTION_RECEIVECOMMANDCHANNELCOMPLETEL, "PTPIP ERROR: Unexpected type received,  data container = %d, command container =%d ", typeData, typeCommand );
   534 			CloseConnection( );
   565 			CloseConnection( );
   535 			break;
   566 			break;
   536 		} // switch data
   567 		} // switch data
   537 	} // switch command
   568 	} // switch command
   538 
   569 
   539 	__FLOG(_L8("ReceiveCommandChannelCompleteL - Exit"));
   570 	OstTraceFunctionExit0( CPTPIPCONNECTION_RECEIVECOMMANDCHANNELCOMPLETEL_EXIT );
   540 	}
   571 	}
   541 
   572 
   542 /**
   573 /**
   543  Called by MTP fw to get data from the transport.
   574  Called by MTP fw to get data from the transport.
   544  */
   575  */
   545 void CPTPIPConnection::ReceiveDataL(MMTPType& aData, const TMTPTypeRequest& /*aRequest*/)
   576 void CPTPIPConnection::ReceiveDataL(MMTPType& aData, const TMTPTypeRequest& /*aRequest*/)
   546 	{
   577 	{
   547 	__FLOG(_L8("ReceiveDataL - Entry"));
   578 	OstTraceFunctionEntry0( CPTPIPCONNECTION_RECEIVEDATAL_ENTRY );
   548 	__FLOG(_L8("******** Phase 2 - Data I to R **************"));
   579 	OstTrace0( TRACE_NORMAL, CPTPIPCONNECTION_RECEIVEDATAL, "******** Phase 2 - Data I to R **************" );
       
   580 	
   549 	SetTransactionPhase(EDataIToRPhase );
   581 	SetTransactionPhase(EDataIToRPhase );
   550 	ReceiveCommandDataL(aData );
   582 	ReceiveCommandDataL(aData );
   551 	__FLOG(_L8("ReceiveDataL - Exit"));
   583 	OstTraceFunctionExit0( CPTPIPCONNECTION_RECEIVEDATAL_EXIT );
   552 	}
   584 	}
   553 
   585 
   554 /**
   586 /**
   555  Called by MTP fw to cancel the receiving data.
   587  Called by MTP fw to cancel the receiving data.
   556  */
   588  */
   557 void CPTPIPConnection::ReceiveDataCancelL(const TMTPTypeRequest& /*aRequest*/)
   589 void CPTPIPConnection::ReceiveDataCancelL(const TMTPTypeRequest& /*aRequest*/)
   558 	{
   590 	{
   559 	__FLOG(_L8("ReceiveDataCancelL - Entry"));
   591 	OstTraceFunctionEntry0( CPTPIPCONNECTION_RECEIVEDATACANCELL_ENTRY );
   560 
   592 
   561 	iCommandHandler->CancelReceiveL(KErrCancel );
   593 	iCommandHandler->CancelReceiveL(KErrCancel );
   562 	__FLOG(_L8("ReceiveDataCancelL - Exit"));
   594 	OstTraceFunctionExit0( CPTPIPCONNECTION_RECEIVEDATACANCELL_EXIT );
   563 	}
   595 	}
   564 
   596 
   565 /**
   597 /**
   566  This will invoke the event handler to listen on the socket and get the events 
   598  This will invoke the event handler to listen on the socket and get the events 
   567  into the buffers passed. 
   599  into the buffers passed. 
   568  */
   600  */
   569 void CPTPIPConnection::InitiateEventRequestPhaseL( )
   601 void CPTPIPConnection::InitiateEventRequestPhaseL( )
   570 	{
   602 	{
   571 	__FLOG(_L8("InitiateEventRequestPhaseL - Entry"));
   603 	OstTraceFunctionEntry0( CPTPIPCONNECTION_INITIATEEVENTREQUESTPHASEL_ENTRY );
   572 
   604 
   573 	// Initialise the PTP buffers to get the data. 
   605 	// Initialise the PTP buffers to get the data. 
   574 	iPTPIPEventPayload.Reset( );
   606 	iPTPIPEventPayload.Reset( );
   575 	iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketType, NULL );
   607 	iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketType, NULL );
   576 	iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketLength,	NULL );
   608 	iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketLength,	NULL );
   577 	iPTPIPEventContainer->SetPayloadL(&iPTPIPEventPayload );
   609 	iPTPIPEventContainer->SetPayloadL(&iPTPIPEventPayload );
   578 
   610 
   579 	// Call the EventHandler
   611 	// Call the EventHandler
   580 	iEventHandler->ReceiveEventL(*iPTPIPEventContainer );
   612 	iEventHandler->ReceiveEventL(*iPTPIPEventContainer );
   581 	__FLOG(_L8("InitiateEventRequestPhaseL - Exit"));
   613 	OstTraceFunctionExit0( CPTPIPCONNECTION_INITIATEEVENTREQUESTPHASEL_EXIT );
   582 	}
   614 	}
   583 
   615 
   584 /**
   616 /**
   585  Signals the completion of receving an event. 
   617  Signals the completion of receving an event. 
   586  */
   618  */
   587 void CPTPIPConnection::ReceiveEventCompleteL(TInt aError, MMTPType& /*aSource*/)
   619 void CPTPIPConnection::ReceiveEventCompleteL(TInt aError, MMTPType& /*aSource*/)
   588 	{
   620 	{
   589 	__FLOG(_L8("ReceiveEventCompleteL - Entry"));
   621 	OstTraceFunctionEntry0( CPTPIPCONNECTION_RECEIVEEVENTCOMPLETEL_ENTRY );
   590 
   622 
   591 	TUint32	type = iPTPIPEventContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   623 	TUint32	type = iPTPIPEventContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   592 	__FLOG_VA((_L8("Error value is %d and type is %d"), aError, type));
   624 	OstTraceExt2( TRACE_NORMAL, CPTPIPCONNECTION_RECEIVEEVENTCOMPLETEL, "Error value is %d and type is %d", static_cast<TInt32>(aError), static_cast<TInt32>(type));
       
   625 	
   593 
   626 
   594 	if(KErrNone != aError )
   627 	if(KErrNone != aError )
   595 		{
   628 		{
   596 		__FLOG_VA((_L8("PTPIP Error: Received error=%d in request phase, closing  connection"), aError));
   629 		OstTrace1( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_RECEIVEEVENTCOMPLETEL, "PTPIP Error: Received error=%d in request phase, closing  connection", aError );
       
   630 		
   597 		CloseConnection( );
   631 		CloseConnection( );
   598 		}
   632 		}
   599 	else
   633 	else
   600 		{
   634 		{
   601 		// For a probe request, we just send a probe response and don't notify the MTP f/w. 
   635 		// For a probe request, we just send a probe response and don't notify the MTP f/w. 
   602 		if( type == EPTPIPPacketTypeProbeRequest )
   636 		if( type == EPTPIPPacketTypeProbeRequest )
   603 			{
   637 			{
   604 			__FLOG(_L8("Received a probe request, sending back a probe response"));
   638 			OstTrace0( TRACE_NORMAL, DUP2_CPTPIPCONNECTION_RECEIVEEVENTCOMPLETEL, "Received a probe request, sending back a probe response" );
       
   639 			
   605 			// Send the response, 
   640 			// Send the response, 
   606 			iPTPIPEventContainer->SetPayloadL(NULL );
   641 			iPTPIPEventContainer->SetPayloadL(NULL );
   607 			iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketLength, iPTPIPEventContainer->Size( ) );
   642 			iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketLength, iPTPIPEventContainer->Size( ) );
   608 			iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketType, EPTPIPPacketTypeProbeResponse );
   643 			iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketType, EPTPIPPacketTypeProbeResponse );
   609 
   644 
   618 		else if(type == EPTPIPPacketTypeEvent )
   653 		else if(type == EPTPIPPacketTypeEvent )
   619 			{
   654 			{
   620 			// Request block received.
   655 			// Request block received.
   621 			TPTPIPTypeResponsePayload* pEvent = static_cast<TPTPIPTypeResponsePayload*>(iPTPIPEventContainer->Payload());
   656 			TPTPIPTypeResponsePayload* pEvent = static_cast<TPTPIPTypeResponsePayload*>(iPTPIPEventContainer->Payload());
   622 			TUint16	op(pEvent->Uint16(TPTPIPTypeResponsePayload::EResponseCode ));
   657 			TUint16	op(pEvent->Uint16(TPTPIPTypeResponsePayload::EResponseCode ));
   623 			__FLOG_VA((_L8("Event block 0x%04X received"), op));
   658 			OstTrace1( TRACE_NORMAL, DUP3_CPTPIPCONNECTION_RECEIVEEVENTCOMPLETEL, "Event block 0x%04X received", op );
       
   659 			
       
   660 			
   624 
   661 
   625 			// Reset the iMTPRequest.
   662 			// Reset the iMTPRequest.
   626 			iMTPEvent.Reset( );
   663 			iMTPEvent.Reset( );
   627 
   664 
   628 			// Setup the MTP request dataset buffer. Set Operation Code and TransactionID
   665 			// Setup the MTP request dataset buffer. Set Operation Code and TransactionID
   638 			InitiateEventRequestPhaseL( );
   675 			InitiateEventRequestPhaseL( );
   639 			}
   676 			}
   640 		// If unexpected data is received , its ignored in the release mode. 
   677 		// If unexpected data is received , its ignored in the release mode. 
   641 		else
   678 		else
   642 			{
   679 			{
   643 			__FLOG(_L8("PTPIP ERROR : Unknown event type received, ignoring it."));
   680 			OstTrace0( TRACE_NORMAL, DUP4_CPTPIPCONNECTION_RECEIVEEVENTCOMPLETEL, "PTPIP ERROR : Unknown event type received, ignoring it." );
       
   681 			
   644 			__ASSERT_DEBUG(type, Panic(EPTPIPBadState));
   682 			__ASSERT_DEBUG(type, Panic(EPTPIPBadState));
   645 			}
   683 			}
   646 		}
   684 		}
   647 	__FLOG(_L8("ReceiveEventCompleteL - Exit"));
   685 	OstTraceFunctionExit0( CPTPIPCONNECTION_RECEIVEEVENTCOMPLETEL_EXIT );
   648 	}
   686 	}
   649 
   687 
   650 //
   688 //
   651 // Send data functions
   689 // Send data functions
   652 //
   690 //
   654  Called by the MTP f/w to send the response to the initiator.
   692  Called by the MTP f/w to send the response to the initiator.
   655  Also called from this connection itself to send the cancel response. 
   693  Also called from this connection itself to send the cancel response. 
   656  */
   694  */
   657 void CPTPIPConnection::SendResponseL(const TMTPTypeResponse& aResponse,	const TMTPTypeRequest& aRequest )
   695 void CPTPIPConnection::SendResponseL(const TMTPTypeResponse& aResponse,	const TMTPTypeRequest& aRequest )
   658 	{
   696 	{
   659 	__FLOG(_L8("SendResponseL - Entry"));
   697 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDRESPONSEL_ENTRY );
   660 
   698 
   661 	// Update the transaction state.
   699 	// Update the transaction state.
   662 	SetTransactionPhase(EResponsePhase );
   700 	SetTransactionPhase(EResponsePhase );
   663 	__FLOG(_L8("******** Phase 3 - Response **************"));
   701 	OstTrace0( TRACE_NORMAL, CPTPIPCONNECTION_SENDRESPONSEL, "******** Phase 3 - Response **************" );
       
   702 	
   664 	
   703 	
   665 	if(iCancelOnCommandState  )
   704 	if(iCancelOnCommandState  )
   666 		{
   705 		{
   667 		__FLOG(_L8("Cancel has been received from initiator, so send own response"));
   706 		OstTrace0( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_SENDRESPONSEL, "Cancel has been received from initiator, so send own response" );
   668 		
   707 		
   669 		SendCancelResponseL(aRequest.Uint32(TMTPTypeRequest::ERequestTransactionID ));
   708 		SendCancelResponseL(aRequest.Uint32(TMTPTypeRequest::ERequestTransactionID ));
   670 		}
   709 		}
   671 	else
   710 	else
   672 		{
   711 		{
   673 		TUint16	opCode(aRequest.Uint16(TMTPTypeRequest::ERequestOperationCode ));
   712 		TUint16	opCode(aRequest.Uint16(TMTPTypeRequest::ERequestOperationCode ));
   674 		TUint16 rspCode(aResponse.Uint16(TMTPTypeResponse::EResponseCode ));
   713 		TUint16 rspCode(aResponse.Uint16(TMTPTypeResponse::EResponseCode ));
   675 		__FLOG_VA((_L8("ResponseCode = 0x%04X, Operation Code = 0x%04X"), rspCode, opCode));
   714 		OstTraceExt2( TRACE_NORMAL, DUP2_CPTPIPCONNECTION_SENDRESPONSEL, "ResponseCode = 0x%04X, Operation Code = 0x%04X", rspCode, opCode );
       
   715 		
   676 
   716 
   677 		if((opCode == EMTPOpCodeOpenSession) &&(rspCode == EMTPRespCodeOK) )
   717 		if((opCode == EMTPOpCodeOpenSession) &&(rspCode == EMTPRespCodeOK) )
   678 			{
   718 			{
   679 			// An session has been opened. Record the active SessionID.
   719 			// An session has been opened. Record the active SessionID.
   680 			iMTPSessionId = aRequest.Uint32(TMTPTypeRequest::ERequestParameter1 );
   720 			iMTPSessionId = aRequest.Uint32(TMTPTypeRequest::ERequestParameter1 );
   681 			__FLOG_VA((_L8("Processing OpenSession response, SessionID = %d"), iMTPSessionId));
   721 			OstTrace1( TRACE_NORMAL, DUP3_CPTPIPCONNECTION_SENDRESPONSEL, "Processing OpenSession response, SessionID = %d", iMTPSessionId );
       
   722 			
   682 			}
   723 			}
   683 		else if(((opCode == EMTPOpCodeCloseSession) ||
   724 		else if(((opCode == EMTPOpCodeCloseSession) ||
   684 				(opCode == EMTPOpCodeResetDevice))&&(rspCode == EMTPRespCodeOK) )
   725 				(opCode == EMTPOpCodeResetDevice))&&(rspCode == EMTPRespCodeOK) )
   685 			{
   726 			{
   686 			// An session has been closed. Clear the active SessionID.        
   727 			// An session has been closed. Clear the active SessionID.        
   687 			__FLOG_VA((_L8("Processing CloseSession or ResetDevice response, SessionID = %d"), iMTPSessionId));
   728 			OstTrace1( TRACE_NORMAL, DUP4_CPTPIPCONNECTION_SENDRESPONSEL, "Processing CloseSession or ResetDevice response, SessionID = %d", iMTPSessionId );
       
   729 			
   688 			iMTPSessionId = KMTPSessionNone;
   730 			iMTPSessionId = KMTPSessionNone;
   689 			}
   731 			}
   690 
   732 
   691 		//Setup the parameter block payload dataset. Note that since this is a 
   733 		//Setup the parameter block payload dataset. Note that since this is a 
   692 		//variable length dataset, it must first be reset.
   734 		//variable length dataset, it must first be reset.
   705 		iPTPIPCommandContainer->SetPayloadL(const_cast<TPTPIPTypeResponsePayload*>(&iPTPIPResponsePayload) );
   747 		iPTPIPCommandContainer->SetPayloadL(const_cast<TPTPIPTypeResponsePayload*>(&iPTPIPResponsePayload) );
   706 		iPTPIPCommandContainer->SetUint32L(	CPTPIPGenericContainer::EPacketLength, static_cast<TUint32>(iPTPIPCommandContainer->Size()) );
   748 		iPTPIPCommandContainer->SetUint32L(	CPTPIPGenericContainer::EPacketLength, static_cast<TUint32>(iPTPIPCommandContainer->Size()) );
   707 		iPTPIPCommandContainer->SetUint32L(	CPTPIPGenericContainer::EPacketType, EPTPIPPacketTypeOperationResponse );
   749 		iPTPIPCommandContainer->SetUint32L(	CPTPIPGenericContainer::EPacketType, EPTPIPPacketTypeOperationResponse );
   708 
   750 
   709 		// Initiate the command send sequence.
   751 		// Initiate the command send sequence.
   710 		__FLOG_VA((_L8("Sending response 0x%04X(%d bytes)"),
   752 		OstTraceExt2( TRACE_NORMAL, DUP5_CPTPIPCONNECTION_SENDRESPONSEL, "Sending response 0x%04X(%d bytes)",
   711 						iPTPIPResponsePayload.Uint16(TPTPIPTypeResponsePayload::EResponseCode),
   753 		        static_cast<TUint32>(iPTPIPResponsePayload.Uint16(TPTPIPTypeResponsePayload::EResponseCode)),
   712 						iPTPIPCommandContainer->Uint32L(CPTPIPGenericContainer::EPacketLength)));
   754 		        iPTPIPCommandContainer->Uint32L(CPTPIPGenericContainer::EPacketLength));
       
   755 		
   713 		iCommandHandler->SendCommandL(*iPTPIPCommandContainer );
   756 		iCommandHandler->SendCommandL(*iPTPIPCommandContainer );
   714 		}
   757 		}
   715 
   758 
   716 	__FLOG(_L8("SendResponseL - Exit"));
   759 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDRESPONSEL_EXIT );
   717 	}
   760 	}
   718 
   761 
   719 /**
   762 /**
   720  Send response complete
   763  Send response complete
   721  */
   764  */
   722 void CPTPIPConnection::SendCommandCompleteL(TInt aError )
   765 void CPTPIPConnection::SendCommandCompleteL(TInt aError )
   723 	{
   766 	{
   724 
   767     OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDCOMMANDCOMPLETEL_ENTRY );
   725 	__FLOG(_L8("SendCommandCompleteL - Entry"));
   768 
   726 
   769 
   727 	if(ValidateTransactionPhase(EResponsePhase ) )
   770 	if(ValidateTransactionPhase(EResponsePhase ) )
   728 		{
   771 		{
   729 		BoundProtocolLayer().SendResponseCompleteL( aError,
   772 		BoundProtocolLayer().SendResponseCompleteL( aError,
   730 		                                            *static_cast<TMTPTypeResponse*>(iPTPIPCommandContainer->Payload()), 
   773 		                                            *static_cast<TMTPTypeResponse*>(iPTPIPCommandContainer->Payload()), 
   731 		                                            iMTPRequest );
   774 		                                            iMTPRequest );
   732 		}
   775 		}
   733 	__FLOG(_L8("SendCommandCompleteL - Exit"));
   776 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDCOMMANDCOMPLETEL_EXIT );
   734 	}
   777 	}
   735 
   778 
   736 /**
   779 /**
   737  Send data complete
   780  Send data complete
   738  */
   781  */
   739 void CPTPIPConnection::SendCommandDataCompleteL(TInt aError )
   782 void CPTPIPConnection::SendCommandDataCompleteL(TInt aError )
   740 	{
   783 	{
   741 	__FLOG(_L8("SendCommandDataCompleteL - Entry"));
   784 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDCOMMANDDATACOMPLETEL_ENTRY );
   742 
   785 
   743 	if(ValidateTransactionPhase(EDataRToIPhase ) )
   786 	if(ValidateTransactionPhase(EDataRToIPhase ) )
   744 		{
   787 		{
   745 		BoundProtocolLayer().SendDataCompleteL(aError, *iPTPIPDataContainer->Payload(), iMTPRequest );
   788 		BoundProtocolLayer().SendDataCompleteL(aError, *iPTPIPDataContainer->Payload(), iMTPRequest );
   746 		}
   789 		}
   747 	SetConnectionState(EDataSendFinished);
   790 	SetConnectionState(EDataSendFinished);
   748 	iPTPIPDataContainer->SetPayloadL(NULL );
   791 	iPTPIPDataContainer->SetPayloadL(NULL );
   749 
   792 
   750 	__FLOG(_L8("SendCommandDataCompleteL - Exit"));
   793 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDCOMMANDDATACOMPLETEL_EXIT );
   751 	}
   794 	}
   752 
   795 
   753 /**
   796 /**
   754  Called by the command handler to indicate completion of send on the command channel.
   797  Called by the command handler to indicate completion of send on the command channel.
   755  Now check whether it was commands or data completion and call the appropriate function. 
   798  Now check whether it was commands or data completion and call the appropriate function. 
   756  */
   799  */
   757 void CPTPIPConnection::SendCommandChannelCompleteL(TInt aError, const MMTPType& /*aSource*/)
   800 void CPTPIPConnection::SendCommandChannelCompleteL(TInt aError, const MMTPType& /*aSource*/)
   758 	{
   801 	{
   759 	__FLOG(_L8("SendCommandChannelCompleteL - Entry"));
   802 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDCOMMANDCHANNELCOMPLETEL_ENTRY );
   760 
   803 
   761 	// Now see whether we have completed getting data or commands, and call the appropriate function.
   804 	// Now see whether we have completed getting data or commands, and call the appropriate function.
   762 	TUint typeCommand = iPTPIPCommandContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   805 	TUint typeCommand = iPTPIPCommandContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   763 	TUint typeData = iPTPIPDataContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   806 	TUint typeData = iPTPIPDataContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   764 	__FLOG_VA((_L8("type on the command buffer is %d and type on the data buffer is %d"), typeCommand, typeData ) );
   807 	OstTraceExt2( TRACE_NORMAL, CPTPIPCONNECTION_SENDCOMMANDCHANNELCOMPLETEL, "type on the command buffer is %d and type on the data buffer is %d", typeCommand, typeData );
       
   808 	
   765 	
   809 	
   766 	
   810 	
   767 	// if we have received a cancel on the event channel then terminate the current sending
   811 	// if we have received a cancel on the event channel then terminate the current sending
   768 	// and handle the receiving and sending of cancel on the channel.
   812 	// and handle the receiving and sending of cancel on the channel.
   769 	if (iCancelOnEventState && !iCancelOnCommandState)
   813 	if (iCancelOnEventState && !iCancelOnCommandState)
   804 			}
   848 			}
   805 
   849 
   806 	// Any other type indicates a programming error, and a panic is raised. 
   850 	// Any other type indicates a programming error, and a panic is raised. 
   807 	else
   851 	else
   808 		{
   852 		{
   809 		__FLOG_VA((_L8("PTPIP ERROR: Unexpected type in sent data, type = = %d, command =%d "), typeData, typeCommand));
   853 		OstTraceExt2( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_SENDCOMMANDCHANNELCOMPLETEL, "PTPIP ERROR: Unexpected type in sent data, type = = %d, command =%d", typeData, typeCommand );
       
   854 		
   810 		Panic(EPTPIPBadState );
   855 		Panic(EPTPIPBadState );
   811 		}
   856 		}
   812 
   857 
   813 	__FLOG(_L8("SendCommandChannelCompleteL - Exit"));
   858 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDCOMMANDCHANNELCOMPLETEL_EXIT );
   814 	}
   859 	}
   815 
   860 
   816 /**
   861 /**
   817  Called by the MTP fw to send the data by the transport via the sockets
   862  Called by the MTP fw to send the data by the transport via the sockets
   818  */
   863  */
   819 void CPTPIPConnection::SendDataL(const MMTPType& aData,	const TMTPTypeRequest& aRequest )
   864 void CPTPIPConnection::SendDataL(const MMTPType& aData,	const TMTPTypeRequest& aRequest )
   820 	{
   865 	{
   821 	__FLOG(_L8("SendDataL - Entry"));
   866 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDDATAL_ENTRY );
   822 
   867 
   823 	__FLOG(_L8("******** Phase 2 - Data R to I **************"));
   868 	OstTrace0( TRACE_NORMAL, CPTPIPCONNECTION_SENDDATAL, "******** Phase 2 - Data R to I **************" );
       
   869 	
   824 	SetTransactionPhase(EDataRToIPhase );
   870 	SetTransactionPhase(EDataRToIPhase );
   825 	SetConnectionState(EDataSendInProgress );
   871 	SetConnectionState(EDataSendInProgress );
   826 
   872 
   827 	// Save the actual data in the dataContainer
   873 	// Save the actual data in the dataContainer
   828 	iPTPIPDataContainer->SetPayloadL(const_cast<MMTPType*>(&aData) );
   874 	iPTPIPDataContainer->SetPayloadL(const_cast<MMTPType*>(&aData) );
   843 	// First send the start data packet, once this is complete, it will invoke the 
   889 	// First send the start data packet, once this is complete, it will invoke the 
   844 	// SendCommandChannelCompleteL, where we will check the state and send the 
   890 	// SendCommandChannelCompleteL, where we will check the state and send the 
   845 	// actual data in the next packet, which has been saved in the dataContainer. 
   891 	// actual data in the next packet, which has been saved in the dataContainer. 
   846 	SendStartDataPacketL( );
   892 	SendStartDataPacketL( );
   847 
   893 
   848 	__FLOG(_L8("SendDataL - Exit"));
   894 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDDATAL_EXIT );
   849 	}
   895 	}
   850 
   896 
   851 /**
   897 /**
   852  The data will be sent in 2 ptpip operations. 
   898  The data will be sent in 2 ptpip operations. 
   853  first the start data ptpip packet will be sent. This has the totalk size and transaction. 
   899  first the start data ptpip packet will be sent. This has the totalk size and transaction. 
   854  next the actual data packet will be sent, with the end data ptp ip header.
   900  next the actual data packet will be sent, with the end data ptp ip header.
   855  */
   901  */
   856 void CPTPIPConnection::SendStartDataPacketL( )
   902 void CPTPIPConnection::SendStartDataPacketL( )
   857 	{
   903 	{
   858 	__FLOG(_L8("SendStartDataPacketL - Entry"));
   904 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDSTARTDATAPACKETL_ENTRY );
   859 
   905 
   860 	SetConnectionState(EDataSendInProgress );
   906 	SetConnectionState(EDataSendInProgress );
   861 	iCommandHandler->SendCommandL(*iPTPIPCommandContainer );
   907 	iCommandHandler->SendCommandL(*iPTPIPCommandContainer );
   862 	__FLOG(_L8("SendStartDataPacketL - Exit"));
   908 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDSTARTDATAPACKETL_EXIT );
   863 	}
   909 	}
   864 
   910 
   865 /**
   911 /**
   866  Send the actual data, which has come from the MTP framework 
   912  Send the actual data, which has come from the MTP framework 
   867  */
   913  */
   868 void CPTPIPConnection::SendDataPacketL( )
   914 void CPTPIPConnection::SendDataPacketL( )
   869 	{
   915 	{
   870 	__FLOG(_L8("SendDataPacketL - Entry"));
   916 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDDATAPACKETL_ENTRY );
   871 	
   917 	
   872 	MMTPType* payLoad = iPTPIPDataContainer->Payload();
   918 	MMTPType* payLoad = iPTPIPDataContainer->Payload();
   873 	
   919 	
   874 	TPtr8 headerChunk(NULL, 0);
   920 	TPtr8 headerChunk(NULL, 0);
   875 	TBool hasTransportHeader = payLoad->ReserveTransportHeader(KPTPIPDataHeaderSize, headerChunk);
   921 	TBool hasTransportHeader = payLoad->ReserveTransportHeader(KPTPIPDataHeaderSize, headerChunk);
   894 	    
   940 	    
   895 	    SetConnectionState(EDataSendInProgress );
   941 	    SetConnectionState(EDataSendInProgress );
   896 	    iCommandHandler->SendCommandDataL(*iPTPIPDataContainer,	iPTPIPDataContainer->Uint32L(TMTPTypeRequest::ERequestTransactionID ) );
   942 	    iCommandHandler->SendCommandDataL(*iPTPIPDataContainer,	iPTPIPDataContainer->Uint32L(TMTPTypeRequest::ERequestTransactionID ) );
   897 	    }
   943 	    }
   898 
   944 
   899 	__FLOG(_L8("SendDataPacketL - Exit"));
   945 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDDATAPACKETL_EXIT );
   900 	}
   946 	}
   901 
   947 
   902 /**
   948 /**
   903  Called by the fw to cancel the sending of data
   949  Called by the fw to cancel the sending of data
   904  */
   950  */
   905 void CPTPIPConnection::SendDataCancelL(const TMTPTypeRequest& /*aRequest*/)
   951 void CPTPIPConnection::SendDataCancelL(const TMTPTypeRequest& /*aRequest*/)
   906 	{
   952 	{
   907 	__FLOG(_L8("SendDataCancelL - Entry"));
   953 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDDATACANCELL_ENTRY );
   908 	iCommandHandler->CancelSendL(KErrCancel );
   954 	iCommandHandler->CancelSendL(KErrCancel );
   909 	__FLOG(_L8("SendDataCancelL - Exit"));
   955 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDDATACANCELL_EXIT );
   910 	}
   956 	}
   911 
   957 
   912 /**
   958 /**
   913  Called by the fw to send an event. 
   959  Called by the fw to send an event. 
   914  */
   960  */
   915 void CPTPIPConnection::SendEventL(const TMTPTypeEvent& aEvent )
   961 void CPTPIPConnection::SendEventL(const TMTPTypeEvent& aEvent )
   916 	{
   962 	{
   917 	__FLOG(_L8("SendEventL - Entry"));
   963 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDEVENTL_ENTRY );
   918 
   964 
   919     // Reset the event.
   965     // Reset the event.
   920     iMTPEvent.Reset(); 
   966     iMTPEvent.Reset(); 
   921     MMTPType::CopyL(aEvent, iMTPEvent);
   967     MMTPType::CopyL(aEvent, iMTPEvent);
   922     
   968     
   923 	TUint16 opCode(aEvent.Uint16(TMTPTypeEvent::EEventCode ));
   969 	TUint16 opCode(aEvent.Uint16(TMTPTypeEvent::EEventCode ));
   924 	TUint32 tran(aEvent.Uint32(TMTPTypeEvent::EEventTransactionID ));
   970 	TUint32 tran(aEvent.Uint32(TMTPTypeEvent::EEventTransactionID ));
   925 	__FLOG_VA((_L8(" Sending event with Operation Code = 0x%04X and tran id = %d"), opCode, tran ));
   971 	OstTraceExt2( TRACE_NORMAL, CPTPIPCONNECTION_SENDEVENTL, "Sending event with Operation Code = 0x%04X and tran id = %d", static_cast<TUint32>(opCode), tran );
       
   972 	
   926 
   973 
   927 	TBool isNullParamValid = EFalse;
   974 	TBool isNullParamValid = EFalse;
   928 	TUint numberOfNullParam = 0;
   975 	TUint numberOfNullParam = 0;
   929 
   976 
   930 	iPTPIPEventPayload.CopyIn(aEvent, 
   977 	iPTPIPEventPayload.CopyIn(aEvent, 
   939 	iPTPIPEventContainer->SetPayloadL(const_cast<TPTPIPTypeResponsePayload*>(&iPTPIPEventPayload) );
   986 	iPTPIPEventContainer->SetPayloadL(const_cast<TPTPIPTypeResponsePayload*>(&iPTPIPEventPayload) );
   940 	iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketLength,	static_cast<TUint32>(iPTPIPEventContainer->Size()) );
   987 	iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketLength,	static_cast<TUint32>(iPTPIPEventContainer->Size()) );
   941 	iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketType, EPTPIPPacketTypeEvent );
   988 	iPTPIPEventContainer->SetUint32L(CPTPIPGenericContainer::EPacketType, EPTPIPPacketTypeEvent );
   942 
   989 
   943 	// Initiate the event send sequence.
   990 	// Initiate the event send sequence.
   944 	__FLOG_VA((_L8("Sending response 0x%04X(%d bytes)"),
   991 	OstTraceExt2( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_SENDEVENTL, "Sending response 0x%04X(%d bytes)",
   945 					iPTPIPEventPayload.Uint16(TPTPIPTypeResponsePayload::EResponseCode),
   992 	        static_cast<TUint32>(iPTPIPEventPayload.Uint16(TPTPIPTypeResponsePayload::EResponseCode)),
   946 					iPTPIPEventContainer->Uint32L(CPTPIPGenericContainer::EPacketLength)));
   993 	        iPTPIPEventContainer->Uint32L(CPTPIPGenericContainer::EPacketLength));
       
   994 	
   947 
   995 
   948 	iEventHandler->SendEventL(*iPTPIPEventContainer );
   996 	iEventHandler->SendEventL(*iPTPIPEventContainer );
   949 	__FLOG(_L8("SendEventL - Exit"));
   997 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDEVENTL_EXIT );
   950 	}
   998 	}
   951 
   999 
   952 /**
  1000 /**
   953  Marks the completion of the asynchronous send event. 
  1001  Marks the completion of the asynchronous send event. 
   954  */
  1002  */
   955 void CPTPIPConnection::SendEventCompleteL(TInt aError, const MMTPType& /*aSource*/)
  1003 void CPTPIPConnection::SendEventCompleteL(TInt aError, const MMTPType& /*aSource*/)
   956 	{
  1004 	{
   957 	__FLOG(_L8("SendEventCompleteL - Entry"));
  1005 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDEVENTCOMPLETEL_ENTRY );
   958 	TUint type = iPTPIPEventContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
  1006 	TUint type = iPTPIPEventContainer->Uint32L(CPTPIPGenericContainer::EPacketType );
   959 
  1007 
   960 	// Notify the fw that event was sent. 
  1008 	// Notify the fw that event was sent. 
   961 	if(type == EPTPIPPacketTypeEvent )
  1009 	if(type == EPTPIPPacketTypeEvent )
   962 		{
  1010 		{
   967 #ifdef _DEBUG
  1015 #ifdef _DEBUG
   968 	//In case we sent a probe response, we dont' need to notify the fw.
  1016 	//In case we sent a probe response, we dont' need to notify the fw.
   969 	else
  1017 	else
   970 		if(type == EPTPIPPacketTypeProbeResponse )
  1018 		if(type == EPTPIPPacketTypeProbeResponse )
   971 			{
  1019 			{
   972 			__FLOG(_L8("Probe response was sent successfully"));
  1020 			OstTrace0( TRACE_NORMAL, CPTPIPCONNECTION_SENDEVENTCOMPLETEL, "Probe response was sent successfully" );
   973 			}
  1021 			}
   974 		else
  1022 		else
   975 			{
  1023 			{
   976 			// If unexpected data was sent , it is ignored in the release mode. 
  1024 			// If unexpected data was sent , it is ignored in the release mode. 
   977 			__FLOG(_L8("PTPIP ERROR: An invalid send event completion signalled"));
  1025 			OstTrace0( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_SENDEVENTCOMPLETEL, "PTPIP ERROR: An invalid send event completion signalled" );
       
  1026 			
   978 			__ASSERT_DEBUG(type, Panic(EPTPIPBadState));
  1027 			__ASSERT_DEBUG(type, Panic(EPTPIPBadState));
   979 			}
  1028 			}
   980 #endif
  1029 #endif
   981 	
  1030 	
   982 	// Restart listening for events
  1031 	// Restart listening for events
   983 	InitiateEventRequestPhaseL( );
  1032 	InitiateEventRequestPhaseL( );
   984 	__FLOG(_L8("SendEventCompleteL - Exit"));
  1033 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDEVENTCOMPLETEL_EXIT );
   985 	}
  1034 	}
   986 
  1035 
   987 //
  1036 //
   988 // Cancel handling functions
  1037 // Cancel handling functions
   989 //
  1038 //
   993  or after the cancel on the command channle, and it can also come 
  1042  or after the cancel on the command channle, and it can also come 
   994  in any of the MTP transaction states ( request, response, data)
  1043  in any of the MTP transaction states ( request, response, data)
   995  */
  1044  */
   996 void CPTPIPConnection::HandleEventCancelL( )
  1045 void CPTPIPConnection::HandleEventCancelL( )
   997 	{
  1046 	{
   998 	__FLOG(_L8("HandleEventCancelL - Entry"));
  1047 	OstTraceFunctionEntry0( CPTPIPCONNECTION_HANDLEEVENTCANCELL_ENTRY );
   999 	__FLOG_VA((_L8("iCancelOnCommandState = 0x%04X, and  iCancelOnEventState = 0x%04X"), iCancelOnCommandState, iCancelOnEventState));
  1048 	OstTraceExt2( TRACE_NORMAL, CPTPIPCONNECTION_HANDLEEVENTCANCELL, "iCancelOnCommandState = 0x%04X, and  iCancelOnEventState = 0x%04X", iCancelOnCommandState, iCancelOnEventState );
       
  1049 	
  1000 
  1050 
  1001 	// Check whether the cancel has already been received on the command channel. 
  1051 	// Check whether the cancel has already been received on the command channel. 
  1002 	// If so then we can simply ignore this on the event channel. 
  1052 	// If so then we can simply ignore this on the event channel. 
  1003 	switch(iCancelOnCommandState )
  1053 	switch(iCancelOnCommandState )
  1004 		{
  1054 		{
  1039 					break;
  1089 					break;
  1040 
  1090 
  1041 				case EResponsePhase:
  1091 				case EResponsePhase:
  1042 				case ERequestPhase:
  1092 				case ERequestPhase:
  1043 				default:
  1093 				default:
  1044 					__FLOG(_L8(" Cancel received on event channel during a non data phase, ignoring, as this will be handled when its received on command channel."));
  1094 					OstTrace0( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_HANDLEEVENTCANCELL, "Cancel received on event channel during a non data phase, ignoring, as this will be handled when its received on command channel." );
       
  1095 					
  1045 					iCancelOnEventState = ECancelEvtHandled;
  1096 					iCancelOnEventState = ECancelEvtHandled;
  1046 					break;
  1097 					break;
  1047 				}// end of switch for transaction phase.
  1098 				}// end of switch for transaction phase.
  1048 
  1099 
  1049 			break;
  1100 			break;
  1050 		default:
  1101 		default:
  1051 			break;
  1102 			break;
  1052 		}
  1103 		}
  1053 	__FLOG(_L8("HandleEventCancelL - Exit"));
  1104 	OstTraceFunctionExit0( CPTPIPCONNECTION_HANDLEEVENTCANCELL_EXIT );
  1054 	}
  1105 	}
  1055 
  1106 
  1056 /** 
  1107 /** 
  1057  Handle the cancel on the command channel. This can come before 
  1108  Handle the cancel on the command channel. This can come before 
  1058  or after the cancel on the event channel, and it can also come 
  1109  or after the cancel on the event channel, and it can also come 
  1059  in any of the MTP transaction states ( request, response, data)
  1110  in any of the MTP transaction states ( request, response, data)
  1060  */
  1111  */
  1061 void CPTPIPConnection::HandleCommandCancelL(TUint32 aTransId )
  1112 void CPTPIPConnection::HandleCommandCancelL(TUint32 aTransId )
  1062 	{
  1113 	{
  1063 	__FLOG(_L8("HandleCommandCancelL - Entry"));
  1114 	OstTraceFunctionEntry0( CPTPIPCONNECTION_HANDLECOMMANDCANCELL_ENTRY );
  1064 
  1115 
  1065 	switch(iTransactionState )
  1116 	switch(iTransactionState )
  1066 		{
  1117 		{
  1067 		case ERequestPhase:
  1118 		case ERequestPhase:
  1068 			__FLOG(_L8(" Cancel received during the request phase before the request packet, ignoring."));
  1119 			OstTrace0( TRACE_NORMAL, CPTPIPCONNECTION_HANDLECOMMANDCANCELL, "Cancel received during the request phase before the request packet, ignoring." );
       
  1120 			
  1069 			iCancelOnCommandState = ECancelCmdHandled;
  1121 			iCancelOnCommandState = ECancelCmdHandled;
  1070 			if (iCancelOnEventState == ECancelNotReceived)
  1122 			if (iCancelOnEventState == ECancelNotReceived)
  1071 				{
  1123 				{
  1072 				// Wait for it to be received on event
  1124 				// Wait for it to be received on event
  1073 				__FLOG(_L8("Awaiting cancel on the event channel."));
  1125 				OstTrace0( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_HANDLECOMMANDCANCELL, "Awaiting cancel on the event channel." );
  1074 				}
  1126 				}
  1075 			else
  1127 			else
  1076 				{
  1128 				{
  1077 				HandleCommandCancelCompleteL();
  1129 				HandleCommandCancelCompleteL();
  1078 				}			
  1130 				}			
  1094 		case EResponsePhase:
  1146 		case EResponsePhase:
  1095 			iCancelOnCommandState = ECancelCmdHandled;
  1147 			iCancelOnCommandState = ECancelCmdHandled;
  1096 			if (iCancelOnEventState == ECancelNotReceived)
  1148 			if (iCancelOnEventState == ECancelNotReceived)
  1097 				{
  1149 				{
  1098 				// Wait for it to be received on event
  1150 				// Wait for it to be received on event
  1099 				__FLOG(_L8("Awaiting cancel on the event channel."));
  1151 				OstTrace0( TRACE_NORMAL, DUP2_CPTPIPCONNECTION_HANDLECOMMANDCANCELL, "Awaiting cancel on the event channel." );
  1100 				}
  1152 				}
  1101 			else
  1153 			else
  1102 				{
  1154 				{
  1103 				HandleCommandCancelCompleteL();
  1155 				HandleCommandCancelCompleteL();
  1104 				}
  1156 				}
  1105 			
  1157 			
  1106 			break;
  1158 			break;
  1107 		}// switch
  1159 		}// switch
  1108 
  1160 
  1109 	__FLOG(_L8("HandleCommandCancelL - Exit"));
  1161 	OstTraceFunctionExit0( CPTPIPCONNECTION_HANDLECOMMANDCANCELL_EXIT );
  1110 	}
  1162 	}
  1111 	
  1163 	
  1112 	
  1164 	
  1113 void CPTPIPConnection::HandleCancelDuringSendL()
  1165 void CPTPIPConnection::HandleCancelDuringSendL()
  1114 	{
  1166 	{
  1115 	__FLOG(_L8("HandleCancelDuringSendL - Entry"));	
  1167 	OstTraceFunctionEntry0( CPTPIPCONNECTION_HANDLECANCELDURINGSENDL_ENTRY );
  1116 	iCommandHandler->Cancel( );
  1168 	iCommandHandler->Cancel( );
  1117 	// Now start listening for the cancel on command channel.
  1169 	// Now start listening for the cancel on command channel.
  1118 	iPTPIPDataContainer->SetUint32L(CPTPIPDataContainer::EPacketType, 0 );
  1170 	iPTPIPDataContainer->SetUint32L(CPTPIPDataContainer::EPacketType, 0 );
  1119 	iPTPIPCommandContainer->SetUint32L(	CPTPIPGenericContainer::EPacketType, 0 );
  1171 	iPTPIPCommandContainer->SetUint32L(	CPTPIPGenericContainer::EPacketType, 0 );
  1120 	iPTPIPCommandCancelPayload.Set(0 );
  1172 	iPTPIPCommandCancelPayload.Set(0 );
  1121 	iPTPIPCommandContainer->SetPayloadL(&iPTPIPCommandCancelPayload );
  1173 	iPTPIPCommandContainer->SetPayloadL(&iPTPIPCommandCancelPayload );
  1122 	iCommandHandler->ReceiveCommandRequestL(*iPTPIPCommandContainer );	
  1174 	iCommandHandler->ReceiveCommandRequestL(*iPTPIPCommandContainer );	
  1123 	__FLOG(_L8("HandleCancelDuringSendL - Exit"));
  1175 	OstTraceFunctionExit0( CPTPIPCONNECTION_HANDLECANCELDURINGSENDL_EXIT );
  1124 	}
  1176 	}
  1125 
  1177 
  1126 /**
  1178 /**
  1127  Called when the reponse to the cancel has been sent to the initiator
  1179  Called when the reponse to the cancel has been sent to the initiator
  1128  */
  1180  */
  1129 void CPTPIPConnection::HandleCommandCancelCompleteL( )
  1181 void CPTPIPConnection::HandleCommandCancelCompleteL( )
  1130 	{
  1182 	{
  1131 	__FLOG(_L8("HandleCommandCancelCompleteL - Entry"));	
  1183 	OstTraceFunctionEntry0( CPTPIPCONNECTION_HANDLECOMMANDCANCELCOMPLETEL_ENTRY );	
  1132 	//now cancel handling is complete.
  1184 	//now cancel handling is complete.
  1133 
  1185 
  1134 	if((ECancelCmdHandled == iCancelOnCommandState) &&(ECancelEvtHandled == iCancelOnEventState) )
  1186 	if((ECancelCmdHandled == iCancelOnCommandState) &&(ECancelEvtHandled == iCancelOnEventState) )
  1135 		{
  1187 		{
  1136 		__FLOG(_L8("Completed handling cancel on both channels. "));
  1188 		OstTrace0( TRACE_NORMAL, CPTPIPCONNECTION_HANDLECOMMANDCANCELCOMPLETEL, "Completed handling cancel on both channels." );
       
  1189 		
  1137 		// Cancel has already been received and handled on the command channel
  1190 		// Cancel has already been received and handled on the command channel
  1138 		// ignore the cancel on event channel and reset the state to none, 
  1191 		// ignore the cancel on event channel and reset the state to none, 
  1139 		// and start listening for the next transaction.
  1192 		// and start listening for the next transaction.
  1140 		iCancelOnCommandState = ECancelNotReceived;
  1193 		iCancelOnCommandState = ECancelNotReceived;
  1141 		iCancelOnEventState = ECancelNotReceived;
  1194 		iCancelOnEventState = ECancelNotReceived;
  1143 		InitiateEventRequestPhaseL();
  1196 		InitiateEventRequestPhaseL();
  1144 		}
  1197 		}
  1145 	// if the cancel has not been received yet on event, we wait for it. 
  1198 	// if the cancel has not been received yet on event, we wait for it. 
  1146 	else if(ECancelEvtHandled != iCancelOnEventState )
  1199 	else if(ECancelEvtHandled != iCancelOnEventState )
  1147 		{
  1200 		{
  1148 		__FLOG(_L8("Waiting for the cancel on the event channel. "));
  1201 		OstTrace0( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_HANDLECOMMANDCANCELCOMPLETEL, "Waiting for the cancel on the event channel. " );
  1149 		}
  1202 		
  1150 	__FLOG(_L8("HandleCommandCancelCompleteL - Exit"));
  1203 		}
       
  1204 	OstTraceFunctionExit0( CPTPIPCONNECTION_HANDLECOMMANDCANCELCOMPLETEL_EXIT );
  1151 	}
  1205 	}
  1152 
  1206 
  1153 /**
  1207 /**
  1154  Inform the MTP framework that a cancel has been received. 
  1208  Inform the MTP framework that a cancel has been received. 
  1155  */
  1209  */
  1156 void CPTPIPConnection::SendCancelToFrameworkL(TUint32 aTransId )
  1210 void CPTPIPConnection::SendCancelToFrameworkL(TUint32 aTransId )
  1157 	{
  1211 	{
  1158 	__FLOG(_L8("SendCancelToFramework - Entry"));
  1212 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDCANCELTOFRAMEWORKL_ENTRY );
  1159 
  1213 
  1160 	// Setup the MTP request dataset buffer. Set Operation Code and TransactionID
  1214 	// Setup the MTP request dataset buffer. Set Operation Code and TransactionID
  1161 	iMTPEvent.Reset( );
  1215 	iMTPEvent.Reset( );
  1162 	iMTPEvent.SetUint16(TMTPTypeEvent::EEventCode,	EMTPEventCodeCancelTransaction );
  1216 	iMTPEvent.SetUint16(TMTPTypeEvent::EEventCode,	EMTPEventCodeCancelTransaction );
  1163 	iMTPEvent.SetUint32(TMTPTypeEvent::EEventSessionID, iMTPSessionId );
  1217 	iMTPEvent.SetUint32(TMTPTypeEvent::EEventSessionID, iMTPSessionId );
  1164 	iMTPEvent.SetUint32(TMTPTypeEvent::EEventTransactionID, aTransId );
  1218 	iMTPEvent.SetUint32(TMTPTypeEvent::EEventTransactionID, aTransId );
  1165 
  1219 
  1166 	BoundProtocolLayer().ReceivedEventL(iMTPEvent );
  1220 	BoundProtocolLayer().ReceivedEventL(iMTPEvent );
  1167 	__FLOG(_L8("SendCancelToFramework - Exit"));
  1221 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDCANCELTOFRAMEWORKL_EXIT );
  1168 	}
  1222 	}
  1169 
  1223 
  1170 /**
  1224 /**
  1171  Send the response to the cancel event. 
  1225  Send the response to the cancel event. 
  1172  */
  1226  */
  1173 void CPTPIPConnection::SendCancelResponseL(TUint32 aTransId )
  1227 void CPTPIPConnection::SendCancelResponseL(TUint32 aTransId )
  1174 	{
  1228 	{
  1175 	__FLOG(_L8("SendCancelResponse - Entry"));
  1229 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDCANCELRESPONSEL_ENTRY );
  1176 	iPTPIPResponsePayload.Reset( );
  1230 	iPTPIPResponsePayload.Reset( );
  1177 	iPTPIPResponsePayload.SetUint16(TPTPIPTypeResponsePayload::EResponseCode, EMTPRespCodeTransactionCancelled );
  1231 	iPTPIPResponsePayload.SetUint16(TPTPIPTypeResponsePayload::EResponseCode, EMTPRespCodeTransactionCancelled );
  1178 	iPTPIPResponsePayload.SetUint32(TPTPIPTypeResponsePayload::ETransactionId, aTransId );
  1232 	iPTPIPResponsePayload.SetUint32(TPTPIPTypeResponsePayload::ETransactionId, aTransId );
  1179 
  1233 
  1180 	// Setup the command container.
  1234 	// Setup the command container.
  1181 	iPTPIPCommandContainer->SetPayloadL(const_cast<TPTPIPTypeResponsePayload*>(&iPTPIPResponsePayload) );
  1235 	iPTPIPCommandContainer->SetPayloadL(const_cast<TPTPIPTypeResponsePayload*>(&iPTPIPResponsePayload) );
  1182 	iPTPIPCommandContainer->SetUint32L(CPTPIPGenericContainer::EPacketLength, static_cast<TUint32>(iPTPIPCommandContainer->Size()) );
  1236 	iPTPIPCommandContainer->SetUint32L(CPTPIPGenericContainer::EPacketLength, static_cast<TUint32>(iPTPIPCommandContainer->Size()) );
  1183 	iPTPIPCommandContainer->SetUint32L(CPTPIPGenericContainer::EPacketType,	EPTPIPPacketTypeOperationResponse );
  1237 	iPTPIPCommandContainer->SetUint32L(CPTPIPGenericContainer::EPacketType,	EPTPIPPacketTypeOperationResponse );
  1184 
  1238 
  1185 	// Initiate the command send sequence.
  1239 	// Initiate the command send sequence.
  1186 	__FLOG_VA((_L8("Sending response 0x%04X(%d bytes)"),
  1240 	OstTraceExt2( TRACE_NORMAL, CPTPIPCONNECTION_SENDCANCELRESPONSEL, "Sending response 0x%04X(%d bytes)", 
  1187 					iPTPIPResponsePayload.Uint16(TPTPIPTypeResponsePayload::EResponseCode),
  1241                 static_cast<TUint32>(iPTPIPResponsePayload.Uint16(TPTPIPTypeResponsePayload::EResponseCode)),
  1188 					iPTPIPCommandContainer->Uint32L(CPTPIPGenericContainer::EPacketLength)));
  1242                 iPTPIPCommandContainer->Uint32L(CPTPIPGenericContainer::EPacketLength));
       
  1243 	
  1189 	iCommandHandler->SendCommandL(*iPTPIPCommandContainer );
  1244 	iCommandHandler->SendCommandL(*iPTPIPCommandContainer );
  1190 	__FLOG(_L8("SendCancelResponse - Exit"));
  1245 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDCANCELRESPONSEL_EXIT );
  1191 	}
  1246 	}
  1192 
  1247 
  1193 /**
  1248 /**
  1194  * If the cancel packet is received on the event channel first
  1249  * If the cancel packet is received on the event channel first
  1195  * and we are in the DataItoR phase, we have to continue reading and ignoreing the 
  1250  * and we are in the DataItoR phase, we have to continue reading and ignoreing the 
  1196  * data packets sent by the initiator, into dummy buffers until the cancel packet is received. 
  1251  * data packets sent by the initiator, into dummy buffers until the cancel packet is received. 
  1197  */
  1252  */
  1198 void CPTPIPConnection::SetNULLPacketL()
  1253 void CPTPIPConnection::SetNULLPacketL()
  1199 	{
  1254 	{
  1200 	__FLOG(_L8("SetNULLPacketL - Entry"));
  1255 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SETNULLPACKETL_ENTRY );
  1201     // Setup the bulk container and initiate the bulk data receive sequence.
  1256     // Setup the bulk container and initiate the bulk data receive sequence.
  1202     iNullBuffer.Close();
  1257     iNullBuffer.Close();
  1203     iNullBuffer.CreateL(KMTPNullChunkSize);
  1258     iNullBuffer.CreateL(KMTPNullChunkSize);
  1204     iNullBuffer.SetLength(KMTPNullChunkSize);
  1259     iNullBuffer.SetLength(KMTPNullChunkSize);
  1205     iNull.SetBuffer(iNullBuffer);
  1260     iNull.SetBuffer(iNullBuffer);
  1206 	iPTPIPDataContainer->SetPayloadL(&iNull);
  1261 	iPTPIPDataContainer->SetPayloadL(&iNull);
  1207 	__FLOG(_L8("SetNULLPacketL - Exit"));
  1262 	OstTraceFunctionExit0( CPTPIPCONNECTION_SETNULLPACKETL_EXIT );
  1208 	}
  1263 	}
  1209 
  1264 
  1210 //
  1265 //
  1211 // Getters , Setters and other helper functions
  1266 // Getters , Setters and other helper functions
  1212 //
  1267 //
  1218  property names, then a leave occurs. 
  1273  property names, then a leave occurs. 
  1219  Also in case opening or transferring the socket fails, a leave is generated. 
  1274  Also in case opening or transferring the socket fails, a leave is generated. 
  1220  */
  1275  */
  1221 void CPTPIPConnection::TransferSocketsL( )
  1276 void CPTPIPConnection::TransferSocketsL( )
  1222 	{
  1277 	{
  1223 
  1278 OstTraceFunctionEntry0( CPTPIPCONNECTION_TRANSFERSOCKETSL_ENTRY );
  1224 	__FLOG(_L8("TransferSocketsL - Entry"));
  1279 
  1225 
  1280 
  1226 	TName evtsockname, cmdsockname;
  1281 	TName evtsockname, cmdsockname;
  1227 	TUid propertyUid=iConnectionMgr->ClientSId();
  1282 	TUid propertyUid=iConnectionMgr->ClientSId();
  1228 	User::LeaveIfError(RProperty::Get(propertyUid, ECommandSocketName,	cmdsockname ));
  1283 	TInt err = RProperty::Get(propertyUid, ECommandSocketName, cmdsockname );
  1229 	User::LeaveIfError(RProperty::Get(propertyUid, EEventSocketName, evtsockname ));
  1284 	LEAVEIFERROR(err, 
       
  1285 	                        OstTrace1( TRACE_ERROR, DUP1_CPTPIPCONNECTION_TRANSFERSOCKETSL, "error code is %d", err ));
       
  1286 
       
  1287 	err = RProperty::Get(propertyUid, EEventSocketName, evtsockname );
       
  1288 	LEAVEIFERROR(err, 
       
  1289 	                        OstTrace1( TRACE_ERROR, DUP2_CPTPIPCONNECTION_TRANSFERSOCKETSL, "error code is %d", err ));
  1230 
  1290 
  1231 	RSocketServ serversocket;
  1291 	RSocketServ serversocket;
  1232 	TInt err=serversocket.Connect( );
  1292 	err=serversocket.Connect( );
  1233 	__FLOG_VA((_L8("Connected to socketServer with %d code"), err) );
  1293 	OstTrace1( TRACE_NORMAL, CPTPIPCONNECTION_TRANSFERSOCKETSL, "Connected to socketServer with %d code", err );
       
  1294 	
  1234 	
  1295 	
  1235 	if (KErrNone == err)
  1296 	if (KErrNone == err)
  1236 		{			
  1297 		{			
  1237 		User::LeaveIfError(iCommandHandler->Socket().Open(serversocket ));
  1298 		err = iCommandHandler->Socket().Open(serversocket );
  1238 		User::LeaveIfError(iEventHandler->Socket().Open(serversocket ));
  1299 		LEAVEIFERROR(err, 
  1239 	
  1300 		        OstTrace1( TRACE_ERROR, DUP3_CPTPIPCONNECTION_TRANSFERSOCKETSL, "error code is %d", err ));
  1240 		User::LeaveIfError(err=iCommandHandler->Socket().Transfer(serversocket, cmdsockname ));
  1301 		err = iEventHandler->Socket().Open(serversocket );
  1241 		User::LeaveIfError(err=iEventHandler->Socket().Transfer(serversocket, evtsockname ));
  1302 	    LEAVEIFERROR(err, 
       
  1303 	            OstTrace1( TRACE_ERROR, DUP4_CPTPIPCONNECTION_TRANSFERSOCKETSL, "error code is %d", err ));
       
  1304 	    err=iCommandHandler->Socket().Transfer(serversocket, cmdsockname );
       
  1305 	    LEAVEIFERROR(err, 
       
  1306 	            OstTrace1( TRACE_ERROR, DUP5_CPTPIPCONNECTION_TRANSFERSOCKETSL, "error code is %d", err ));
       
  1307 	    err=iEventHandler->Socket().Transfer(serversocket, evtsockname );
       
  1308 	    LEAVEIFERROR(err, 
       
  1309 	            OstTrace1( TRACE_ERROR, DUP6_CPTPIPCONNECTION_TRANSFERSOCKETSL, "error code is %d", err ));
  1242 		}
  1310 		}
  1243 	
  1311 	
  1244 	iCommandHandler->SetSocketOptions();
  1312 	iCommandHandler->SetSocketOptions();
  1245 	iEventHandler->SetSocketOptions();
  1313 	iEventHandler->SetSocketOptions();
  1246 
  1314 
  1247 	__FLOG(_L8("TransferSocketsL - Exit"));
  1315 	OstTraceFunctionExit0( CPTPIPCONNECTION_TRANSFERSOCKETSL_EXIT );
  1248 	}
  1316 	}
  1249 
  1317 
  1250 
  1318 
  1251 /**
  1319 /**
  1252  Connection establishment has 4 steps, the first 3 are completed by the controller process:
  1320  Connection establishment has 4 steps, the first 3 are completed by the controller process:
  1261  the mtp process. This is done after the the framework has loaded, the sockets have
  1329  the mtp process. This is done after the the framework has loaded, the sockets have
  1262  been transferred to this process and the transport is up. 
  1330  been transferred to this process and the transport is up. 
  1263  */
  1331  */
  1264 void CPTPIPConnection::SendInitAckL( )
  1332 void CPTPIPConnection::SendInitAckL( )
  1265 	{
  1333 	{
  1266 
  1334 OstTraceFunctionEntry0( CPTPIPCONNECTION_SENDINITACKL_ENTRY );
  1267 	__FLOG(_L8("SendInitAckL - Entry"));
       
  1268 
  1335 
  1269 	iPTPIPEventContainer->SetPayloadL(NULL );
  1336 	iPTPIPEventContainer->SetPayloadL(NULL );
  1270 	iPTPIPEventContainer->SetUint32L(TPTPIPInitEvtAck::ELength,	iPTPIPEventContainer->Size( ) );
  1337 	iPTPIPEventContainer->SetUint32L(TPTPIPInitEvtAck::ELength,	iPTPIPEventContainer->Size( ) );
  1271 	iPTPIPEventContainer->SetUint32L(TPTPIPInitEvtAck::EType, EPTPIPPacketTypeEventAck );
  1338 	iPTPIPEventContainer->SetUint32L(TPTPIPInitEvtAck::EType, EPTPIPPacketTypeEventAck );
  1272 
  1339 
  1273 	// Send the packet
  1340 	// Send the packet
  1274 	iEventHandler->SendInitAck(iPTPIPEventContainer );
  1341 	iEventHandler->SendInitAck(iPTPIPEventContainer );
  1275 
  1342 
  1276 	__FLOG(_L8("SendInitAckL - Exit"));
  1343 	OstTraceFunctionExit0( CPTPIPCONNECTION_SENDINITACKL_EXIT );
  1277 	}
  1344 	}
  1278 
  1345 
  1279 /**
  1346 /**
  1280  Stop the connection. 
  1347  Stop the connection. 
  1281 
  1348 
  1285  Also inform the fw that connection is closed. 
  1352  Also inform the fw that connection is closed. 
  1286 
  1353 
  1287  */
  1354  */
  1288 void CPTPIPConnection::StopConnection( )
  1355 void CPTPIPConnection::StopConnection( )
  1289 	{
  1356 	{
  1290 	__FLOG(_L8("StopConnection - Entry"));
  1357 	OstTraceFunctionEntry0( CPTPIPCONNECTION_STOPCONNECTION_ENTRY );
  1291 
  1358 
  1292 	if(ConnectionOpen( ) )
  1359 	if(ConnectionOpen( ) )
  1293 		{
  1360 		{
  1294 		__FLOG(_L8("Stopping socket handlers"));
  1361 		OstTrace0( TRACE_NORMAL, CPTPIPCONNECTION_STOPCONNECTION, "Stopping socket handlers" );
       
  1362 		
  1295 		iEventHandler->Cancel( );
  1363 		iEventHandler->Cancel( );
  1296 		iCommandHandler->Cancel( );
  1364 		iCommandHandler->Cancel( );
  1297 		if(iTransactionState == EDataIToRPhase )
  1365 		if(iTransactionState == EDataIToRPhase )
  1298 			{
  1366 			{
  1299 			__FLOG(_L8("Aborting active I to R data phase"));
  1367 			OstTrace0( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_STOPCONNECTION, "Aborting active I to R data phase" );
       
  1368 			
  1300 			TRAPD(err, BoundProtocolLayer().ReceiveDataCompleteL(KErrAbort, *iPTPIPDataContainer->Payload(), iMTPRequest));
  1369 			TRAPD(err, BoundProtocolLayer().ReceiveDataCompleteL(KErrAbort, *iPTPIPDataContainer->Payload(), iMTPRequest));
  1301 			UNUSED_VAR(err);
  1370 			UNUSED_VAR(err);
  1302 			}
  1371 			}
  1303 		else
  1372 		else
  1304 			if(iTransactionState == EDataRToIPhase )
  1373 			if(iTransactionState == EDataRToIPhase )
  1305 				{
  1374 				{
  1306 				__FLOG(_L8("Aborting active R to I data phase"));
  1375 				OstTrace0( TRACE_NORMAL, DUP2_CPTPIPCONNECTION_STOPCONNECTION, "Aborting active R to I data phase" );
       
  1376 				
  1307 				TRAPD(err, BoundProtocolLayer().SendDataCompleteL(KErrAbort, *iPTPIPDataContainer->Payload(), iMTPRequest))	;
  1377 				TRAPD(err, BoundProtocolLayer().SendDataCompleteL(KErrAbort, *iPTPIPDataContainer->Payload(), iMTPRequest))	;
  1308 				UNUSED_VAR(err);
  1378 				UNUSED_VAR(err);
  1309 				}
  1379 				}
  1310 
  1380 		OstTrace0( TRACE_NORMAL, DUP3_CPTPIPCONNECTION_STOPCONNECTION, "Notifying protocol layer connection closed" );
  1311 		__FLOG(_L8("Notifying protocol layer connection closed"));
  1381 		
  1312 		iConnectionMgr->ConnectionClosed(*this );
  1382 		iConnectionMgr->ConnectionClosed(*this );
  1313 		SetTransactionPhase(EUndefined );
  1383 		SetTransactionPhase(EUndefined );
  1314 		SetConnectionState(EIdle );
  1384 		SetConnectionState(EIdle );
  1315 		}
  1385 		}
  1316 
  1386 	OstTraceFunctionExit0( CPTPIPCONNECTION_STOPCONNECTION_EXIT );
  1317 	__FLOG(_L8("StopConnection - Exit"));
       
  1318 	}
  1387 	}
  1319 
  1388 
  1320 /**
  1389 /**
  1321  * Invoked by the SocketHandler when there is an error.
  1390  * Invoked by the SocketHandler when there is an error.
  1322  */
  1391  */
  1323 #ifdef __FLOG_ACTIVE
       
  1324 void CPTPIPConnection::HandleError(TInt aError)
  1392 void CPTPIPConnection::HandleError(TInt aError)
  1325 #else
  1393 	{
  1326 void CPTPIPConnection::HandleError(TInt /*aError*/)
  1394 	OstTraceFunctionEntry0( CPTPIPCONNECTION_HANDLEERROR_ENTRY );
  1327 #endif
  1395 	OstTrace1( TRACE_NORMAL, CPTPIPCONNECTION_HANDLEERROR, "SocketHandler received an error=%d, stopping connection.", aError );
  1328 	{
  1396 	
  1329 	__FLOG_VA((_L8("SocketHandler received an error=%d, stopping connection.)"),aError));
       
  1330 	StopConnection();
  1397 	StopConnection();
       
  1398 	OstTraceFunctionExit0( CPTPIPCONNECTION_HANDLEERROR_EXIT );
  1331 	}
  1399 	}
  1332 
  1400 
  1333 /**
  1401 /**
  1334  Used to trigger the RunL, by first setting itself to active and 
  1402  Used to trigger the RunL, by first setting itself to active and 
  1335  then simulating a fake asynchronous service provider which will complete us 
  1403  then simulating a fake asynchronous service provider which will complete us 
  1336  with a completion code.
  1404  with a completion code.
  1337  */
  1405  */
  1338 void CPTPIPConnection::CompleteSelf(TInt aCompletionCode )
  1406 void CPTPIPConnection::CompleteSelf(TInt aCompletionCode )
  1339 	{
  1407 	{
       
  1408 	OstTraceFunctionEntry0( CPTPIPCONNECTION_COMPLETESELF_ENTRY );
  1340 	// Setting ourselves active to wait to be done by ASP.
  1409 	// Setting ourselves active to wait to be done by ASP.
  1341 	SetActive( );
  1410 	SetActive( );
  1342 
  1411 
  1343 	// Simulating a fake ASP which completes us.
  1412 	// Simulating a fake ASP which completes us.
  1344 	TRequestStatus* stat = &iStatus;
  1413 	TRequestStatus* stat = &iStatus;
  1345 	User::RequestComplete(stat, aCompletionCode );
  1414 	User::RequestComplete(stat, aCompletionCode );
       
  1415 	OstTraceFunctionExit0( CPTPIPCONNECTION_COMPLETESELF_EXIT );
  1346 	}
  1416 	}
  1347 
  1417 
  1348 /**
  1418 /**
  1349  Setter for transaction phase(request, dataItoR, dataRtoI, or response)
  1419  Setter for transaction phase(request, dataItoR, dataRtoI, or response)
  1350  */
  1420  */
  1351 void CPTPIPConnection::SetTransactionPhase(TMTPTransactionPhase aPhase )
  1421 void CPTPIPConnection::SetTransactionPhase(TMTPTransactionPhase aPhase )
  1352 	{
  1422 	{
  1353 	__FLOG(_L8("SetTransactionPhase - Entry"));
  1423 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SETTRANSACTIONPHASE_ENTRY );
  1354 	iTransactionState = aPhase;
  1424 	iTransactionState = aPhase;
  1355 	__FLOG_VA((_L8("Transaction Phase set to 0x%08X"), iTransactionState));
  1425 	OstTrace1( TRACE_NORMAL, CPTPIPCONNECTION_SETTRANSACTIONPHASE, "Transaction Phase set to 0x%08X", iTransactionState );
  1356 	__FLOG(_L8("SetTransactionPhase - Exit"));
  1426 	
       
  1427 	OstTraceFunctionExit0( CPTPIPCONNECTION_SETTRANSACTIONPHASE_EXIT );
  1357 	}
  1428 	}
  1358 
  1429 
  1359 /**
  1430 /**
  1360  Setter for connection state,( initialising, send data, etc)
  1431  Setter for connection state,( initialising, send data, etc)
  1361  */
  1432  */
  1362 void CPTPIPConnection::SetConnectionState(TConnectionState aState )
  1433 void CPTPIPConnection::SetConnectionState(TConnectionState aState )
  1363 	{
  1434 	{
  1364 	__FLOG(_L8("SetConnectionState - Entry"));
  1435 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SETCONNECTIONSTATE_ENTRY );
  1365 	iState = aState;
  1436 	iState = aState;
  1366 	__FLOG_VA((_L8("Connection state set to 0x%08X"), iState));
  1437 	OstTrace1( TRACE_NORMAL, CPTPIPCONNECTION_SETCONNECTIONSTATE, "Connection state set to 0x%08X", iState );
  1367 	__FLOG(_L8("SetConnectionState - Exit"));
  1438 	
       
  1439 	OstTraceFunctionExit0( CPTPIPCONNECTION_SETCONNECTIONSTATE_EXIT );
  1368 	}
  1440 	}
  1369 
  1441 
  1370 /**
  1442 /**
  1371  Getter 
  1443  Getter 
  1372  */
  1444  */
  1373 TBool CPTPIPConnection::ConnectionOpen( ) const
  1445 TBool CPTPIPConnection::ConnectionOpen( ) const
  1374 	{
  1446 	{
       
  1447 	OstTraceFunctionEntry0( CPTPIPCONNECTION_CONNECTIONOPEN_ENTRY );
       
  1448 	OstTraceFunctionExit0( CPTPIPCONNECTION_CONNECTIONOPEN_EXIT );
  1375 	return((iState >= EInitialising) && (iState <= EDataSendFinished));
  1449 	return((iState >= EInitialising) && (iState <= EDataSendFinished));
  1376 	}
  1450 	}
  1377 
  1451 
  1378 /**
  1452 /**
  1379  Getter for the command container, 
  1453  Getter for the command container, 
  1380  */
  1454  */
  1381 CPTPIPGenericContainer* CPTPIPConnection::CommandContainer( )
  1455 CPTPIPGenericContainer* CPTPIPConnection::CommandContainer( )
  1382 	{
  1456 	{
       
  1457 	OstTraceFunctionEntry0( CPTPIPCONNECTION_COMMANDCONTAINER_ENTRY );
       
  1458 	OstTraceFunctionExit0( CPTPIPCONNECTION_COMMANDCONTAINER_EXIT );
  1383 	return iPTPIPCommandContainer;
  1459 	return iPTPIPCommandContainer;
  1384 	}
  1460 	}
  1385 
  1461 
  1386 /**
  1462 /**
  1387  Getter for the event container
  1463  Getter for the event container
  1388  */
  1464  */
  1389 CPTPIPGenericContainer* CPTPIPConnection::EventContainer( )
  1465 CPTPIPGenericContainer* CPTPIPConnection::EventContainer( )
  1390 	{
  1466 	{
       
  1467 	OstTraceFunctionEntry0( CPTPIPCONNECTION_EVENTCONTAINER_ENTRY );
       
  1468 	OstTraceFunctionExit0( CPTPIPCONNECTION_EVENTCONTAINER_EXIT );
  1391 	return iPTPIPEventContainer;
  1469 	return iPTPIPEventContainer;
  1392 	}
  1470 	}
  1393 
  1471 
  1394 /**
  1472 /**
  1395  Getter for the data container
  1473  Getter for the data container
  1396  */
  1474  */
  1397 CPTPIPDataContainer* CPTPIPConnection::DataContainer( )
  1475 CPTPIPDataContainer* CPTPIPConnection::DataContainer( )
  1398 	{
  1476 	{
       
  1477 	OstTraceFunctionEntry0( CPTPIPCONNECTION_DATACONTAINER_ENTRY );
       
  1478 	OstTraceFunctionExit0( CPTPIPCONNECTION_DATACONTAINER_EXIT );
  1399 	return iPTPIPDataContainer;
  1479 	return iPTPIPDataContainer;
  1400 	}
  1480 	}
  1401 
  1481 
  1402 /**
  1482 /**
  1403  Getter for the transaction phase: request, dataItoR, dataRtoI or response
  1483  Getter for the transaction phase: request, dataItoR, dataRtoI or response
  1404  */
  1484  */
  1405 TMTPTransactionPhase CPTPIPConnection::TransactionPhase( ) const
  1485 TMTPTransactionPhase CPTPIPConnection::TransactionPhase( ) const
  1406 	{
  1486 	{
       
  1487 	OstTraceFunctionEntry0( CPTPIPCONNECTION_TRANSACTIONPHASE_ENTRY );
       
  1488 	OstTraceFunctionExit0( CPTPIPCONNECTION_TRANSACTIONPHASE_EXIT );
  1407 	return iTransactionState;
  1489 	return iTransactionState;
  1408 	}
  1490 	}
  1409 
  1491 
  1410 /**
  1492 /**
  1411  Takes the 4 bytes from the chunk(iReceiveChunkData) and return 
  1493  Takes the 4 bytes from the chunk(iReceiveChunkData) and return 
  1415  the value 0 ( undefined) is returned
  1497  the value 0 ( undefined) is returned
  1416 
  1498 
  1417  */
  1499  */
  1418 TUint32 CPTPIPConnection::ValidateAndSetCommandPayloadL( )
  1500 TUint32 CPTPIPConnection::ValidateAndSetCommandPayloadL( )
  1419 	{
  1501 	{
  1420 	__FLOG(_L8("ValidateAndSetCommandPayload - Entry"));
  1502 	OstTraceFunctionEntry0( CPTPIPCONNECTION_VALIDATEANDSETCOMMANDPAYLOADL_ENTRY );
  1421 
  1503 
  1422 	TUint32 containerType = CommandContainer()->Uint32L(CPTPIPGenericContainer::EPacketType );
  1504 	TUint32 containerType = CommandContainer()->Uint32L(CPTPIPGenericContainer::EPacketType );
  1423 	
  1505 	
  1424 	__FLOG_VA((_L8("PTP packet type  = %d, adjust payload accordingly"), containerType));
  1506 	OstTrace1( TRACE_NORMAL, CPTPIPCONNECTION_VALIDATEANDSETCOMMANDPAYLOADL, "PTP packet type  = %d, adjust payload accordingly", containerType );
       
  1507 	
  1425 
  1508 
  1426 	switch(containerType )
  1509 	switch(containerType )
  1427 		{
  1510 		{
  1428 		case EPTPIPPacketTypeOperationRequest:
  1511 		case EPTPIPPacketTypeOperationRequest:
  1429 			if (!ValidateTransactionPhase(ERequestPhase ))
  1512 			if (!ValidateTransactionPhase(ERequestPhase ))
  1430 				{
  1513 				{
  1431 				__FLOG(_L8("PTPIP ERROR: Request data unexpected in this phase, setting type to undefined"));
  1514 				OstTrace0( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_VALIDATEANDSETCOMMANDPAYLOADL, "PTPIP ERROR: Request data unexpected in this phase, setting type to undefined" );
       
  1515 				
  1432 				containerType = EPTPIPPacketTypeUndefined;
  1516 				containerType = EPTPIPPacketTypeUndefined;
  1433 				}
  1517 				}
  1434 			// Nothing to do , the payload is already set.  In case this is unexpected, 
  1518 			// Nothing to do , the payload is already set.  In case this is unexpected, 
  1435 			//then the validate function will close the connection. 
  1519 			//then the validate function will close the connection. 
  1436 			break;
  1520 			break;
  1437 
  1521 
  1438 		case EPTPIPPacketTypeStartData:
  1522 		case EPTPIPPacketTypeStartData:
  1439 			if (!ValidateTransactionPhase(EDataIToRPhase ))
  1523 			if (!ValidateTransactionPhase(EDataIToRPhase ))
  1440 				{
  1524 				{
  1441 				__FLOG(_L8("PTPIP ERROR: Start data unexpected in this phase, setting type to undefined"));
  1525 				OstTrace0( TRACE_NORMAL, DUP2_CPTPIPCONNECTION_VALIDATEANDSETCOMMANDPAYLOADL, "PTPIP ERROR: Start data unexpected in this phase, setting type to undefined" );
       
  1526 				
  1442 				containerType = EPTPIPPacketTypeUndefined;
  1527 				containerType = EPTPIPPacketTypeUndefined;
  1443 				}
  1528 				}
  1444 			// Nothing to do , the payload is already set.  In case this is unexpected, 
  1529 			// Nothing to do , the payload is already set.  In case this is unexpected, 
  1445 			//then the validate function will close the connection. 
  1530 			//then the validate function will close the connection. 
  1446 			break;
  1531 			break;
  1458 				CommandContainer()->SetPayloadL(&iPTPIPCommandCancelPayload );
  1543 				CommandContainer()->SetPayloadL(&iPTPIPCommandCancelPayload );
  1459 				}
  1544 				}
  1460 			break;
  1545 			break;
  1461 			
  1546 			
  1462 		case EPTPIPPacketTypeOperationResponse:
  1547 		case EPTPIPPacketTypeOperationResponse:
  1463 			__FLOG(_L8("PTPIP ERROR: Response not expected from the initiator, setting type to undefined"));
  1548 			OstTrace0( TRACE_NORMAL, DUP3_CPTPIPCONNECTION_VALIDATEANDSETCOMMANDPAYLOADL, "PTPIP ERROR: Response not expected from the initiator, setting type to undefined" );
       
  1549 			
  1464 			containerType = EPTPIPPacketTypeUndefined;			
  1550 			containerType = EPTPIPPacketTypeUndefined;			
  1465 			// As per the protocol, the initiator cannot send a response, 
  1551 			// As per the protocol, the initiator cannot send a response, 
  1466 			// only the responder( here device)  will create a response, 
  1552 			// only the responder( here device)  will create a response, 
  1467 			// if this is recieved it is an erro
  1553 			// if this is recieved it is an erro
  1468 			break;
  1554 			break;
  1469 			
  1555 			
  1470 
  1556 
  1471 		default:
  1557 		default:
  1472 			__FLOG_VA((_L8("PTPIP ERROR: Invalid packet type received %d )"), containerType));
  1558 			OstTrace1( TRACE_NORMAL, DUP4_CPTPIPCONNECTION_VALIDATEANDSETCOMMANDPAYLOADL, "PTPIP ERROR: Invalid packet type received %d", containerType );
       
  1559 			
  1473 			containerType = EPTPIPPacketTypeUndefined;
  1560 			containerType = EPTPIPPacketTypeUndefined;
  1474 			break;
  1561 			break;
  1475 		}
  1562 		}
  1476 
  1563 
  1477 	__FLOG(_L8("ValidateAndSetCommandPayload - Exit"));
  1564 	OstTraceFunctionExit0( CPTPIPCONNECTION_VALIDATEANDSETCOMMANDPAYLOADL_EXIT );
  1478 	return containerType;
  1565 	return containerType;
  1479 	}
  1566 	}
  1480 
  1567 
  1481 /**
  1568 /**
  1482  Takes the 4 bytes from the chunk(iReceiveChunkData) and return 
  1569  Takes the 4 bytes from the chunk(iReceiveChunkData) and return 
  1486  the value 0 ( undefined) is returned
  1573  the value 0 ( undefined) is returned
  1487 
  1574 
  1488  */
  1575  */
  1489 TUint32 CPTPIPConnection::ValidateDataPacketL( )
  1576 TUint32 CPTPIPConnection::ValidateDataPacketL( )
  1490 	{
  1577 	{
  1491 	__FLOG(_L8("ValidateDataPacketL - Entry"));
  1578 	OstTraceFunctionEntry0( CPTPIPCONNECTION_VALIDATEDATAPACKETL_ENTRY );
  1492 
  1579 
  1493 	TUint32 containerType = DataContainer()->Uint32L(CPTPIPDataContainer::EPacketType );
  1580 	TUint32 containerType = DataContainer()->Uint32L(CPTPIPDataContainer::EPacketType );
  1494 	__FLOG_VA((_L8("PTP data packet type  = %d, "), containerType));
  1581 	OstTrace1( TRACE_NORMAL, CPTPIPCONNECTION_VALIDATEDATAPACKETL, "PTP data packet type  = %d", containerType );
       
  1582 	
  1495 
  1583 
  1496 	switch(containerType )
  1584 	switch(containerType )
  1497 		{
  1585 		{
  1498 		case EPTPIPPacketTypeData:
  1586 		case EPTPIPPacketTypeData:
  1499 		case EPTPIPPacketTypeEndData:
  1587 		case EPTPIPPacketTypeEndData:
  1500 			if (!ValidateTransactionPhase(EDataIToRPhase ))
  1588 			if (!ValidateTransactionPhase(EDataIToRPhase ))
  1501 				{
  1589 				{
  1502 				__FLOG(_L8("PTPIP ERROR: Receiving data unexpected in this phase, setting type to undefined"));
  1590 				OstTrace0( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_VALIDATEDATAPACKETL, "PTPIP ERROR: Receiving data unexpected in this phase, setting type to undefined" );
       
  1591 				
  1503 				containerType = EPTPIPPacketTypeUndefined;
  1592 				containerType = EPTPIPPacketTypeUndefined;
  1504 				}
  1593 				}
  1505 			break;
  1594 			break;
  1506 
  1595 
  1507 		default:
  1596 		default:
  1508 			__FLOG_VA((_L8("PTPIP ERROR: Unexpected or Invalid packet type received while expecting data packet%d )"), containerType));
  1597 			OstTrace1( TRACE_NORMAL, DUP2_CPTPIPCONNECTION_VALIDATEDATAPACKETL, "PTPIP ERROR: Unexpected or Invalid packet type received while expecting data packet%d ", containerType );
       
  1598 			
  1509 			containerType = EPTPIPPacketTypeUndefined;
  1599 			containerType = EPTPIPPacketTypeUndefined;
  1510 			break;
  1600 			break;
  1511 		}
  1601 		}
  1512 
  1602 
  1513 	__FLOG(_L8("ValidateDataPacket - Exit"));
  1603 	OstTraceFunctionExit0( CPTPIPCONNECTION_VALIDATEDATAPACKETL_EXIT );
  1514 	return containerType;
  1604 	return containerType;
  1515 	}
  1605 	}
  1516 
  1606 
  1517 /**
  1607 /**
  1518  Takes the 4 bytes from the chunk(iReceiveChunkData) and return 
  1608  Takes the 4 bytes from the chunk(iReceiveChunkData) and return 
  1522  the value 0 ( undefined) is returned
  1612  the value 0 ( undefined) is returned
  1523 
  1613 
  1524  */
  1614  */
  1525 TUint32 CPTPIPConnection::ValidateAndSetEventPayloadL( )
  1615 TUint32 CPTPIPConnection::ValidateAndSetEventPayloadL( )
  1526 	{
  1616 	{
  1527 	__FLOG(_L8("ValidateAndSetEventPayload - Entry"));
  1617 	OstTraceFunctionEntry0( CPTPIPCONNECTION_VALIDATEANDSETEVENTPAYLOADL_ENTRY );
  1528 
  1618 
  1529 	TUint32 containerType = EventContainer()->Uint32L(CPTPIPGenericContainer::EPacketType );
  1619 	TUint32 containerType = EventContainer()->Uint32L(CPTPIPGenericContainer::EPacketType );
  1530 	__FLOG_VA((_L8("PTP event packet type  = %d, adjust payload accordingly"), containerType));
  1620 	OstTrace1( TRACE_NORMAL, CPTPIPCONNECTION_VALIDATEANDSETEVENTPAYLOADL, "PTP event packet type  = %d, adjust payload accordingly", containerType );
       
  1621 	
  1531 
  1622 
  1532 	switch(containerType )
  1623 	switch(containerType )
  1533 		{
  1624 		{
  1534 		case EPTPIPPacketTypeProbeRequest:
  1625 		case EPTPIPPacketTypeProbeRequest:
  1535 			EventContainer()->SetPayloadL(NULL );
  1626 			EventContainer()->SetPayloadL(NULL );
  1542 		case EPTPIPPacketTypeEvent:
  1633 		case EPTPIPPacketTypeEvent:
  1543 			EventContainer()->SetPayloadL(&iPTPIPEventPayload );
  1634 			EventContainer()->SetPayloadL(&iPTPIPEventPayload );
  1544 			break;
  1635 			break;
  1545 
  1636 
  1546 		default:
  1637 		default:
  1547 			__FLOG_VA((_L8("PTPIP ERROR: Invalid packet type received %d )"), containerType));
  1638 			OstTrace1( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_VALIDATEANDSETEVENTPAYLOADL, "PTPIP ERROR: Invalid packet type received %d", containerType );
       
  1639 			
  1548 			containerType = EPTPIPPacketTypeUndefined;
  1640 			containerType = EPTPIPPacketTypeUndefined;
  1549 			break;
  1641 			break;
  1550 		}
  1642 		}
  1551 
  1643 
  1552 	__FLOG(_L8("ValidateAndSetEventPayload - Exit"));
  1644 	OstTraceFunctionExit0( CPTPIPCONNECTION_VALIDATEANDSETEVENTPAYLOADL_EXIT );
  1553 	return containerType;
  1645 	return containerType;
  1554 	}
  1646 	}
  1555 
  1647 
  1556 /**
  1648 /**
  1557  Processes bulk transfer request transaction state checking. If the transaction 
  1649  Processes bulk transfer request transaction state checking. If the transaction 
  1560  EFalse.
  1652  EFalse.
  1561  */
  1653  */
  1562 TBool CPTPIPConnection::ValidateTransactionPhase(
  1654 TBool CPTPIPConnection::ValidateTransactionPhase(
  1563 		TMTPTransactionPhase aExpectedTransactionState )
  1655 		TMTPTransactionPhase aExpectedTransactionState )
  1564 	{
  1656 	{
  1565 	__FLOG(_L8("ValidateTransactionPhase - Entry"));
  1657 	OstTraceFunctionEntry0( CPTPIPCONNECTION_VALIDATETRANSACTIONPHASE_ENTRY );
  1566 	__FLOG_VA((_L8("transaction state = %d"), iTransactionState));
  1658 	OstTrace1( TRACE_NORMAL, CPTPIPCONNECTION_VALIDATETRANSACTIONPHASE, "transaction state = %d", iTransactionState );
       
  1659 	
  1567 	TBool valid(iTransactionState == aExpectedTransactionState);
  1660 	TBool valid(iTransactionState == aExpectedTransactionState);
  1568 	if(!valid )
  1661 	if(!valid )
  1569 		{
  1662 		{
  1570 		// Invalid transaction state, close the connection.
  1663 		// Invalid transaction state, close the connection.
  1571 		__FLOG_VA((_L8("PTPIP ERROR: invalid transaction state, current = %d, expected = %d"), iTransactionState, aExpectedTransactionState));
  1664 		OstTraceExt2( TRACE_NORMAL, DUP1_CPTPIPCONNECTION_VALIDATETRANSACTIONPHASE, "PTPIP ERROR: invalid transaction state, current = %d, expected = %d", iTransactionState, aExpectedTransactionState );
       
  1665 		
  1572 		CloseConnection( );
  1666 		CloseConnection( );
  1573 		}
  1667 		}
  1574 	__FLOG(_L8("ValidateTransactionPhase - Exit"));
  1668 	OstTraceFunctionExit0( CPTPIPCONNECTION_VALIDATETRANSACTIONPHASE_EXIT );
  1575 	return valid;
  1669 	return valid;
  1576 	}
  1670 	}
  1577 
  1671 
  1578 /**
  1672 /**
  1579  Convert the TCP errors, the disconnect should be reported as an abort, 
  1673  Convert the TCP errors, the disconnect should be reported as an abort, 
  1580  since that is what the MTP frameword expects.
  1674  since that is what the MTP frameword expects.
  1581  */
  1675  */
  1582 TBool CPTPIPConnection::HandleTCPError(TInt& aError )
  1676 TBool CPTPIPConnection::HandleTCPError(TInt& aError )
  1583 	{
  1677 	{
  1584 	__FLOG(_L8("TCPErrorHandled - Entry"));
  1678 	OstTraceFunctionEntry0( CPTPIPCONNECTION_HANDLETCPERROR_ENTRY );
  1585 	TInt ret(EFalse);
  1679 	TInt ret(EFalse);
  1586 	if(aError == KErrDisconnected || aError == KErrEof)
  1680 	if(aError == KErrDisconnected || aError == KErrEof)
  1587 		{
  1681 		{
  1588 		aError = KErrAbort;
  1682 		aError = KErrAbort;
  1589 		CloseConnection( );
  1683 		CloseConnection( );
  1590 		ret = ETrue;
  1684 		ret = ETrue;
  1591 		}
  1685 		}
  1592 	__FLOG(_L8("TCPErrorHandled - Exit"));
  1686 	OstTraceFunctionExit0( CPTPIPCONNECTION_HANDLETCPERROR_EXIT );
  1593 	return ret;
  1687 	return ret;
  1594 	}
  1688 	}
  1595 
  1689 
  1596 void CPTPIPConnection::SetDataTypeInDataContainerL(TPTPIPPacketTypeCode aType )
  1690 void CPTPIPConnection::SetDataTypeInDataContainerL(TPTPIPPacketTypeCode aType )
  1597 	{
  1691 	{
       
  1692 	OstTraceFunctionEntry0( CPTPIPCONNECTION_SETDATATYPEINDATACONTAINERL_ENTRY );
  1598 	iPTPIPDataContainer->SetUint32L(CPTPIPDataContainer::EPacketType, aType );
  1693 	iPTPIPDataContainer->SetUint32L(CPTPIPDataContainer::EPacketType, aType );
  1599 	}
  1694 	OstTraceFunctionExit0( CPTPIPCONNECTION_SETDATATYPEINDATACONTAINERL_EXIT );
  1600 
  1695 	}
  1601 
  1696 
  1602 
  1697 
       
  1698