usbmgmt/usbmgr/device/classdrivers/acm/classimplementation/ecacm/src/CdcControlInterfaceReader.cpp
branchRCL_3
changeset 43 012cc2ee6408
parent 42 f92a4f87e424
equal deleted inserted replaced
42:f92a4f87e424 43:012cc2ee6408
     1 /*
     1 /*
     2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    20 #include "CdcControlInterfaceReader.h"
    20 #include "CdcControlInterfaceReader.h"
    21 #include "AcmPanic.h"
    21 #include "AcmPanic.h"
    22 #include "AcmUtils.h"
    22 #include "AcmUtils.h"
    23 #include "CdcControlInterfaceRequestHandler.h"
    23 #include "CdcControlInterfaceRequestHandler.h"
    24 #include "AcmConstants.h"
    24 #include "AcmConstants.h"
    25 #include "OstTraceDefinitions.h"
    25 #include <usb/usblogger.h>
    26 #ifdef OST_TRACE_COMPILER_IN_USE
    26 
    27 #include "CdcControlInterfaceReaderTraces.h"
    27 #ifdef __FLOG_ACTIVE
       
    28 _LIT8(KLogComponent, "ECACM");
    28 #endif
    29 #endif
    29 
       
    30 
    30 
    31 CCdcControlInterfaceReader::CCdcControlInterfaceReader(
    31 CCdcControlInterfaceReader::CCdcControlInterfaceReader(
    32 				MCdcCommsClassRequestHandler& aParent, 
    32 				MCdcCommsClassRequestHandler& aParent, 
    33 				RDevUsbcClient& aLdd)
    33 				RDevUsbcClient& aLdd)
    34 :	CActive(KEcacmAOPriority),
    34 :	CActive(KEcacmAOPriority),
    39  *
    39  *
    40  * @param aParent	Observer (ACM port)
    40  * @param aParent	Observer (ACM port)
    41  * @param aLdd		The USB LDD handle to be used.
    41  * @param aLdd		The USB LDD handle to be used.
    42  */
    42  */
    43 	{
    43 	{
    44 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_CCDCCONTROLINTERFACEREADER_CONS_ENTRY );
       
    45 	CActiveScheduler::Add(this);
    44 	CActiveScheduler::Add(this);
    46 	ReadMessageHeader();
    45 	ReadMessageHeader();
    47 	OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_CCDCCONTROLINTERFACEREADER_CONS_EXIT );
       
    48 	}
    46 	}
    49 
    47 
    50 CCdcControlInterfaceReader::~CCdcControlInterfaceReader()
    48 CCdcControlInterfaceReader::~CCdcControlInterfaceReader()
    51 /**
    49 /**
    52  * Destructor
    50  * Destructor
    53  */
    51  */
    54 	{
    52 	{
    55 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_CCDCCONTROLINTERFACEREADER_DES_ENTRY );
    53 	LOG_FUNC
       
    54 
    56 	Cancel(); //Call CActive::Cancel()	 
    55 	Cancel(); //Call CActive::Cancel()	 
    57 	OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_CCDCCONTROLINTERFACEREADER_DES_EXIT );
       
    58 	}
    56 	}
    59 
    57 
    60 CCdcControlInterfaceReader* CCdcControlInterfaceReader::NewL(
    58 CCdcControlInterfaceReader* CCdcControlInterfaceReader::NewL(
    61 	MCdcCommsClassRequestHandler& aParent, 
    59 	MCdcCommsClassRequestHandler& aParent, 
    62 	RDevUsbcClient& aLdd)
    60 	RDevUsbcClient& aLdd)
    65  *
    63  *
    66  * @param aParent	Observer (ACM port)
    64  * @param aParent	Observer (ACM port)
    67  * @param aLdd		The USB LDD handle to be used.
    65  * @param aLdd		The USB LDD handle to be used.
    68  */
    66  */
    69 	{
    67 	{
    70 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_NEWL_ENTRY );
    68 	LOG_STATIC_FUNC_ENTRY
       
    69 
    71 	CCdcControlInterfaceReader* self = new(ELeave) CCdcControlInterfaceReader(
    70 	CCdcControlInterfaceReader* self = new(ELeave) CCdcControlInterfaceReader(
    72 		aParent, 
    71 		aParent, 
    73 		aLdd);
    72 		aLdd);
    74 	OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_NEWL_EXIT );
       
    75 	return self;
    73 	return self;
    76 	}
    74 	}
    77 
    75 
    78 void CCdcControlInterfaceReader::RunL()
    76 void CCdcControlInterfaceReader::RunL()
    79 /**
    77 /**
    80  * This function will be called when a read completes.
    78  * This function will be called when a read completes.
    81  */
    79  */
    82 	{
    80 	{
    83 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_RUNL_ENTRY );
    81 	LOGTEXT2(_L8(">>CCdcControlInterfaceReader::RunL iStatus=%d"), iStatus.Int());
    84 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_RUNL, "CCdcControlInterfaceReader::RunL;iStatus=%d", iStatus.Int() );
       
    85 	HandleReadCompletion(iStatus.Int());
    82 	HandleReadCompletion(iStatus.Int());
    86 	OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_RUNL_EXIT );
    83 	LOGTEXT(_L8("<<CCdcControlInterfaceReader::RunL"));
    87 	}
    84 	}
    88 
    85 
    89 void CCdcControlInterfaceReader::DoCancel()
    86 void CCdcControlInterfaceReader::DoCancel()
    90 /**
    87 /**
    91  * Cancel an outstanding read.
    88  * Cancel an outstanding read.
    92  */
    89  */
    93 	{
    90 	{
    94 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_DOCANCEL_ENTRY );
    91 	LOG_FUNC
    95 	iLdd.ReadCancel(EEndpoint0);
    92 	iLdd.ReadCancel(EEndpoint0);
    96 	OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_DOCANCEL_EXIT );
       
    97 	}
    93 	}
    98 
    94 
    99 void CCdcControlInterfaceReader::HandleReadCompletion(TInt aError)
    95 void CCdcControlInterfaceReader::HandleReadCompletion(TInt aError)
   100 /**
    96 /**
   101  * This will be called when a new packet has been received.
    97  * This will be called when a new packet has been received.
   105  * packets have been received before decoding.
   101  * packets have been received before decoding.
   106  *
   102  *
   107  * @param aError Error
   103  * @param aError Error
   108  */
   104  */
   109 	{
   105 	{
   110 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_ENTRY );
   106 	LOGTEXT2(_L8(">>CCdcControlInterfaceReader::HandleReadCompletion "
   111 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION, 
   107 		"aError=%d"), aError);
   112 			"CCdcControlInterfaceReader::HandleReadCompletion;aError=%d", aError );
       
   113 
   108 
   114 	if ( aError )
   109 	if ( aError )
   115 		{
   110 		{
   116 		ReadMessageHeader();		
   111 		ReadMessageHeader();			  
   117 		OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_DUP1, 
   112 		LOGTEXT(_L8("<<CCdcControlInterfaceReader::HandleReadCompletion"));
   118 				"CCdcControlInterfaceReader::HandleReadCompletion" );
       
   119 		OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_EXIT );
       
   120 		return;
   113 		return;
   121 		}
   114 		}
   122 
   115 
   123 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_DUP2, 
   116 	LOGTEXT2(_L8("\tcompleted with iState=%d"),iState);
   124 			"CCdcControlInterfaceReader::HandleReadCompletion;iState=%d", (TInt)iState );
       
   125 
       
   126 	switch ( iState)
   117 	switch ( iState)
   127 		{
   118 		{
   128 	case EWaitingForHeader:
   119 	case EWaitingForHeader:
   129 		{
   120 		{
   130 		DecodeMessageHeader();
   121 		DecodeMessageHeader();
   137 		}
   128 		}
   138 		break;
   129 		break;
   139 
   130 
   140 	default:
   131 	default:
   141 		{
   132 		{
   142 		OstTrace1( TRACE_FATAL, CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_DUP3, 
   133 		_USB_PANIC(KAcmPanicCat, EPanicIllegalState);
   143 					"CCdcControlInterfaceReader::HandleReadCompletion;iState=%d", (TInt)iState );
   134 		}
   144 		User::Panic(KAcmPanicCat, EPanicIllegalState);
   135 		break;
   145 		}
   136 		}
   146 		break;
   137 
   147 		}
   138 	LOGTEXT(_L8("<<CCdcControlInterfaceReader::HandleReadCompletion"));
   148 
       
   149 	OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_HANDLEREADCOMPLETION_EXIT_DUP1 );
       
   150 	}
   139 	}
   151 
   140 
   152 void CCdcControlInterfaceReader::DecodeMessageHeader()
   141 void CCdcControlInterfaceReader::DecodeMessageHeader()
   153 /**
   142 /**
   154  * This function decodes a message header. It determines whether the host 
   143  * This function decodes a message header. It determines whether the host 
   155  * requires some data in response and dispatches the request appropriately.
   144  * requires some data in response and dispatches the request appropriately.
   156  */
   145  */
   157 	{
   146 	{
   158 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEHEADER_ENTRY );
   147 	LOG_FUNC
       
   148 
   159 	if ( TUsbRequestHdr::Decode(iMessageHeader, iRequestHeader) != KErrNone )
   149 	if ( TUsbRequestHdr::Decode(iMessageHeader, iRequestHeader) != KErrNone )
   160 		{
   150 		{
   161 		OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEHEADER, 
   151 		LOGTEXT(_L8("\t- Unable to decode request header!"));
   162 				"CCdcControlInterfaceReader::DecodeMessageHeader;\t- Unable to decode request header!" );
       
   163 		
       
   164 		// Stall bus- unknown message. If this fails, there's nothing we can 
   152 		// Stall bus- unknown message. If this fails, there's nothing we can 
   165 		// do.
   153 		// do.
   166 		static_cast<void>(iLdd.EndpointZeroRequestError()); 
   154 		static_cast<void>(iLdd.EndpointZeroRequestError()); 
   167 		ReadMessageHeader();
   155 		ReadMessageHeader();
   168 		OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEHEADER_EXIT );
       
   169 		return;
   156 		return;
   170 		}
   157 		}
   171 
   158 
   172 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEHEADER_DUP1, 
   159 	LOGTEXT2(_L8("\t- New read! Request 0x%x"), iRequestHeader.iRequest);
   173 			"CCdcControlInterfaceReader::DecodeMessageHeader;\t- New read! Request %d", (TInt)iRequestHeader.iRequest );
   160 
   174 	
       
   175 	if ( iRequestHeader.IsDataResponseRequired() )
   161 	if ( iRequestHeader.IsDataResponseRequired() )
   176 		{
   162 		{
   177 		DecodeMessageDataWithResponseRequired();
   163 		DecodeMessageDataWithResponseRequired();
   178 		}
   164 		}
   179 	else if ( iRequestHeader.iLength == 0 )
   165 	else if ( iRequestHeader.iLength == 0 )
   183 		}
   169 		}
   184 	else
   170 	else
   185 		{
   171 		{
   186 		ReadMessageData(iRequestHeader.iLength);
   172 		ReadMessageData(iRequestHeader.iLength);
   187 		}
   173 		}
   188 	OstTraceFunctionExit0( DUP1_CCDCCONTROLINTERFACEREADER_DECODEMESSAGEHEADER_EXIT );
       
   189 	}
   174 	}
   190 
   175 
   191 void CCdcControlInterfaceReader::DecodeMessageDataWithResponseRequired()
   176 void CCdcControlInterfaceReader::DecodeMessageDataWithResponseRequired()
   192 /**
   177 /**
   193  * Decode a message which requires data to be sent to the host in response.
   178  * Decode a message which requires data to be sent to the host in response.
   194  */
   179  */
   195 	{
   180 	{
   196 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATAWITHRESPONSEREQUIRED_ENTRY );
   181 	LOG_FUNC
   197 	OstTraceExt1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATAWITHRESPONSEREQUIRED, 
   182 
   198 			"CCdcControlInterfaceReader::DecodeMessageDataWithResponseRequired;\t- New read! Request=%hhx", iRequestHeader.iRequest );
   183 	LOGTEXT2(_L8("\t- New read! Request 0x%x"), iRequestHeader.iRequest);
   199 	
       
   200 	TBuf8<KAcmControlReadBufferLength> returnBuffer;
   184 	TBuf8<KAcmControlReadBufferLength> returnBuffer;
       
   185 
   201 	switch ( iRequestHeader.iRequest )
   186 	switch ( iRequestHeader.iRequest )
   202 		{
   187 		{
   203 	case KGetEncapsulated:
   188 	case KGetEncapsulated:
   204 		{
   189 		{
   205 		if ( iParent.HandleGetEncapResponse(returnBuffer) == KErrNone )
   190 		if ( iParent.HandleGetEncapResponse(returnBuffer) == KErrNone )
   261 		}
   246 		}
   262 		break;
   247 		break;
   263 
   248 
   264 	default:
   249 	default:
   265 		{
   250 		{
   266 		OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATAWITHRESPONSEREQUIRED_DUP1, 
   251 		LOGTEXT2(_L8("\t- request number not recognised (%d)"),
   267 				"CCdcControlInterfaceReader::DecodeMessageDataWithResponseRequired;\t- request number not recognised (%d)", 
   252 			iRequestHeader.iRequest);
   268 				(TInt)(iRequestHeader.iRequest) );
       
   269 		
       
   270 		// Stall bus- unknown message. If this fails, there's nothing we can 
   253 		// Stall bus- unknown message. If this fails, there's nothing we can 
   271 		// do.
   254 		// do.
   272 		static_cast<void>(iLdd.EndpointZeroRequestError()); 
   255 		static_cast<void>(iLdd.EndpointZeroRequestError()); 
   273 		}
   256 		}
   274 		break;
   257 		break;
   275 		}
   258 		}
   276 
   259 
   277 	ReadMessageHeader();
   260 	ReadMessageHeader();
   278 	OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATAWITHRESPONSEREQUIRED_EXIT );
       
   279 	}
   261 	}
   280 
   262 
   281 void CCdcControlInterfaceReader::DecodeMessageData()
   263 void CCdcControlInterfaceReader::DecodeMessageData()
   282 /**
   264 /**
   283  * Decode a message that does not require any data to be sent to the host in 
   265  * Decode a message that does not require any data to be sent to the host in 
   284  * response. In all the requests here, the completion of the class-specific 
   266  * response. In all the requests here, the completion of the class-specific 
   285  * function is ack'ed by sending an endpoint zero status packet. The request 
   267  * function is ack'ed by sending an endpoint zero status packet. The request 
   286  * can be nack'ed by signalling an endpoint zero request error.
   268  * can be nack'ed by signalling an endpoint zero request error.
   287  */
   269  */
   288 	{
   270 	{
   289 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA_ENTRY );
   271 	LOG_FUNC
       
   272 
   290 	if ( iMessageData.Length() != iRequestHeader.iLength )
   273 	if ( iMessageData.Length() != iRequestHeader.iLength )
   291 		{
   274 		{
   292 		OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA, 
   275 		LOGTEXT(_L8("\t- Data length is incorrect"));
   293 				"CCdcControlInterfaceReader::DecodeMessageData;\t- Data length is incorrect" );
       
   294 		
       
   295 		ReadMessageHeader();
   276 		ReadMessageHeader();
   296 		OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA_EXIT );
       
   297 		return;
   277 		return;
   298 		}
   278 		}
   299 
   279 
   300 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA_DUP1, 
   280 	LOGTEXT2(_L8("\tNew read! Request %d"), iRequestHeader.iRequest);
   301 			"CCdcControlInterfaceReader::DecodeMessageData;\tNew read! Request %d", (TInt)(iRequestHeader.iRequest) );
   281 
   302 	
       
   303 	switch ( iRequestHeader.iRequest )
   282 	switch ( iRequestHeader.iRequest )
   304 		{
   283 		{
   305 	case KSendEncapsulated:
   284 	case KSendEncapsulated:
   306 		if(iParent.HandleSendEncapCommand(iMessageData) == KErrNone)
   285 		if(iParent.HandleSendEncapCommand(iMessageData) == KErrNone)
   307 			{
   286 			{
   385 			// can do.
   364 			// can do.
   386 			static_cast<void>(iLdd.EndpointZeroRequestError()); 
   365 			static_cast<void>(iLdd.EndpointZeroRequestError()); 
   387 			}
   366 			}
   388 		break;
   367 		break;
   389 	default:
   368 	default:
   390 		OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA_DUP2, 
   369 		LOGTEXT2(_L8("\t***request number not recognised (%d)"),
   391 				"CCdcControlInterfaceReader::DecodeMessageData;\t***request number not recognised (%d)", (TInt)(iRequestHeader.iRequest) );
   370 			iRequestHeader.iRequest);
   392 		
       
   393 		// Stall bus- unknown message. If this fails, there's nothing we can 
   371 		// Stall bus- unknown message. If this fails, there's nothing we can 
   394 		// do.
   372 		// do.
   395 		static_cast<void>(iLdd.EndpointZeroRequestError()); 
   373 		static_cast<void>(iLdd.EndpointZeroRequestError()); 
   396 		break;
   374 		break;
   397 		}
   375 		}
   398 
   376 
   399 	ReadMessageHeader();
   377 	ReadMessageHeader();
   400 	OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_DECODEMESSAGEDATA_EXIT_DUP1 );
       
   401 	}
   378 	}
   402 
   379 
   403 void CCdcControlInterfaceReader::ReadMessageHeader()
   380 void CCdcControlInterfaceReader::ReadMessageHeader()
   404 /**
   381 /**
   405  * Post a read request and set the state to indicate that we're waiting for a 
   382  * Post a read request and set the state to indicate that we're waiting for a 
   406  * message header.
   383  * message header.
   407  */
   384  */
   408 	{
   385 	{
   409 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_READMESSAGEHEADER_ENTRY );
   386 	LOG_FUNC
       
   387 
   410 	iState = EWaitingForHeader;
   388 	iState = EWaitingForHeader;
       
   389 
   411 	iLdd.ReadPacket(iStatus, EEndpoint0, iMessageHeader, KUsbRequestHdrSize);
   390 	iLdd.ReadPacket(iStatus, EEndpoint0, iMessageHeader, KUsbRequestHdrSize);
   412 	SetActive();
   391 	SetActive();
   413 	OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_READMESSAGEHEADER_EXIT );
       
   414 	}
   392 	}
   415 
   393 
   416 void CCdcControlInterfaceReader::ReadMessageData(TUint aLength)
   394 void CCdcControlInterfaceReader::ReadMessageData(TUint aLength)
   417 /**
   395 /**
   418  * Post a read request and set the state to indicate that we're waiting for 
   396  * Post a read request and set the state to indicate that we're waiting for 
   419  * some message data.
   397  * some message data.
   420  *
   398  *
   421  * @param aLength Length of data to read.
   399  * @param aLength Length of data to read.
   422  */
   400  */
   423 	{
   401 	{
   424 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACEREADER_READMESSAGEDATA_ENTRY );
   402 	LOG_FUNC
   425 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACEREADER_READMESSAGEDATA, 
   403 
   426 			"CCdcControlInterfaceReader::ReadMessageData;\tqueuing read, length = %d", (TInt)aLength );
   404 	LOGTEXT2(_L8("\tqueuing read, length = %d"),aLength);
   427 
   405 
   428 	iState = EWaitingForData;
   406 	iState = EWaitingForData;
       
   407 
   429 	iLdd.Read(iStatus, EEndpoint0, iMessageData, static_cast<TInt>(aLength));
   408 	iLdd.Read(iStatus, EEndpoint0, iMessageData, static_cast<TInt>(aLength));
   430 	SetActive();
   409 	SetActive();
   431 	OstTraceFunctionExit0( CCDCCONTROLINTERFACEREADER_READMESSAGEDATA_EXIT );
       
   432 	}
   410 	}
   433 
   411 
   434 //
   412 //
   435 // End of file
   413 // End of file