usbmgmt/usbmgr/device/classdrivers/acm/classimplementation/ecacm/src/CdcControlInterface.cpp
branchRCL_3
changeset 15 f92a4f87e424
parent 0 c9bc50fca66e
child 16 012cc2ee6408
equal deleted inserted replaced
14:d3e8e7d462dd 15:f92a4f87e424
     1 /*
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2010 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".
    23 #include "CdcControlInterfaceReader.h"
    23 #include "CdcControlInterfaceReader.h"
    24 #include "ClassDescriptor.h"
    24 #include "ClassDescriptor.h"
    25 #include "CdcAcmClass.h"
    25 #include "CdcAcmClass.h"
    26 #include "AcmPanic.h"
    26 #include "AcmPanic.h"
    27 #include "AcmUtils.h"
    27 #include "AcmUtils.h"
    28 #include <usb/usblogger.h>
    28 #include "OstTraceDefinitions.h"
    29 
    29 #ifdef OST_TRACE_COMPILER_IN_USE
    30 #ifdef __FLOG_ACTIVE
    30 #include "CdcControlInterfaceTraces.h"
    31 _LIT8(KLogComponent, "ECACM");
       
    32 #endif
    31 #endif
       
    32 
    33 
    33 
    34 CCdcControlInterface::CCdcControlInterface(const TUint8 aProtocolNum, const TDesC16& aIfcName)
    34 CCdcControlInterface::CCdcControlInterface(const TUint8 aProtocolNum, const TDesC16& aIfcName)
    35 /**
    35 /**
    36  * Constructor using interface name.
    36  * Constructor using interface name.
    37  * @param aProtocolNum Contains the Table 17 protocol number.
    37  * @param aProtocolNum Contains the Table 17 protocol number.
    39  */
    39  */
    40  :	CCdcInterfaceBase(aIfcName), 
    40  :	CCdcInterfaceBase(aIfcName), 
    41 	iSerialState(0xFFFF),
    41 	iSerialState(0xFFFF),
    42 	iProtocolNum(aProtocolNum)
    42 	iProtocolNum(aProtocolNum)
    43 	{
    43 	{
       
    44 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACE_CCDCCONTROLINTERFACE_CONS_ENTRY );
       
    45 	OstTraceFunctionExit0( CCDCCONTROLINTERFACE_CCDCCONTROLINTERFACE_CONS_EXIT );
    44 	}
    46 	}
    45 
    47 
    46 CCdcControlInterface* CCdcControlInterface::NewL(CCdcAcmClass& aParent, const TUint8 aProtocolNum, const TDesC16& aIfcName)
    48 CCdcControlInterface* CCdcControlInterface::NewL(CCdcAcmClass& aParent, const TUint8 aProtocolNum, const TDesC16& aIfcName)
    47 /**
    49 /**
    48  * Create a new CCDCCommClass object and construct it using interface name
    50  * Create a new CCDCCommClass object and construct it using interface name
    52  * @param aProtocolNum contains the Table 17 protocol number.
    54  * @param aProtocolNum contains the Table 17 protocol number.
    53  * @param aIfcName Contains the interface name
    55  * @param aIfcName Contains the interface name
    54  * @return A pointer to the new object
    56  * @return A pointer to the new object
    55  */
    57  */
    56 	{
    58 	{
    57 	LOG_STATIC_FUNC_ENTRY
    59 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACE_NEWL_ENTRY );
    58 
    60 	OstTraceExt1( TRACE_NORMAL, CCDCCONTROLINTERFACE_NEWL, "CCdcControlInterface::NewL;\tControl Ifc Name = %S", aIfcName );
    59 	LOGTEXT2(_L("\tControl Ifc Name = %S"), &aIfcName);
       
    60 
    61 
    61 	CCdcControlInterface* self = new(ELeave) CCdcControlInterface(aProtocolNum, aIfcName);
    62 	CCdcControlInterface* self = new(ELeave) CCdcControlInterface(aProtocolNum, aIfcName);
    62 	CleanupStack::PushL(self);
    63 	CleanupStack::PushL(self);
    63 	self->ConstructL(aParent);
    64 	self->ConstructL(aParent);
    64 	CLEANUPSTACK_POP(self);
    65 	CLEANUPSTACK_POP(self);
       
    66 	OstTraceFunctionExit0( CCDCCONTROLINTERFACE_NEWL_EXIT );
    65 	return self;
    67 	return self;
    66 	}
    68 	}
    67 
    69 
    68 void CCdcControlInterface::ConstructL(CCdcAcmClass& aParent)
    70 void CCdcControlInterface::ConstructL(CCdcAcmClass& aParent)
    69 /**
    71 /**
    71  * This call registers the object with the USB device driver
    73  * This call registers the object with the USB device driver
    72  *
    74  *
    73  * @param aParent The ACM class.
    75  * @param aParent The ACM class.
    74  */
    76  */
    75 	{
    77 	{
       
    78 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACE_CONSTRUCTL_ENTRY );
       
    79 	
    76 	BaseConstructL();
    80 	BaseConstructL();
    77 
    81 
    78 	iReader  = CCdcControlInterfaceReader::NewL(aParent, iLdd);
    82 	iReader  = CCdcControlInterfaceReader::NewL(aParent, iLdd);
    79 
    83 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_CONSTRUCTL, "CCdcControlInterface::ConstructL;iProtocolNum=%d", (TInt)iProtocolNum );
    80 	LOGTEXT2(_L8("\tcreated CdcControlInterface iProtocolNum = %d"), iProtocolNum);
    84 	OstTraceFunctionExit0( CCDCCONTROLINTERFACE_CONSTRUCTL_EXIT );
    81 	}
    85 	}
    82 
    86 
    83 TInt CCdcControlInterface::SetUpInterface()
    87 TInt CCdcControlInterface::SetUpInterface()
    84 /**
    88 /**
    85  * Set up the interface for use. This involves finding a "Interrupt IN" 
    89  * Set up the interface for use. This involves finding a "Interrupt IN" 
    86  * endpoint and, if found, configuring the interface.
    90  * endpoint and, if found, configuring the interface.
    87  */
    91  */
    88 	{
    92 	{
    89 	LOGTEXT(_L8(">>CCdcControlInterface::SetUpInterface"));
    93 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACE_SETUPINTERFACE_ENTRY );
    90 
    94 
    91 	TUsbDeviceCaps dCaps;
    95 	TUsbDeviceCaps dCaps;
    92 	TInt ret = iLdd.DeviceCaps(dCaps);
    96 	TInt ret = iLdd.DeviceCaps(dCaps);
    93 	LOGTEXT(_L8("\tchecking result of DeviceCaps"));
    97 	OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPINTERFACE, "CCdcControlInterface::SetUpInterface;\tchecking result of DeviceCaps" );
    94 	if ( ret )
    98 	if ( ret )
    95 		{
    99 		{
    96 		LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret);
   100 		OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPINTERFACE_DUP1, "CCdcControlInterface::SetUpInterface;ret=%d", ret );
       
   101 		OstTraceFunctionExit0( CCDCCONTROLINTERFACE_SETUPINTERFACE_EXIT );
    97 		return ret;
   102 		return ret;
    98 		}
   103 		}
    99 
   104 
   100 	const TUint KRequiredNumberOfEndpoints = 1; // in addition to endpoint 0.
   105 	const TUint KRequiredNumberOfEndpoints = 1; // in addition to endpoint 0.
   101 
   106 
   102 	const TUint totalEndpoints = static_cast<TUint>(dCaps().iTotalEndpoints);
   107 	const TUint totalEndpoints = static_cast<TUint>(dCaps().iTotalEndpoints);
   103 	LOGTEXT2(_L8("\tiTotalEndpoints = %d"), totalEndpoints);
   108 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPINTERFACE_DUP2, 
       
   109 			"CCdcControlInterface::SetUpInterface;totalEndpoints=%d", (TInt)totalEndpoints );
       
   110 
   104 	if ( totalEndpoints < KRequiredNumberOfEndpoints )
   111 	if ( totalEndpoints < KRequiredNumberOfEndpoints )
   105 		{
   112 		{
   106 		LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), 
   113 		OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPINTERFACE_DUP3, 
   107 			KErrGeneral);
   114 				"CCdcControlInterface::SetUpInterface;ret=%d", KErrGeneral );
       
   115 		OstTraceFunctionExit0( CCDCCONTROLINTERFACE_SETUPINTERFACE_EXIT_DUP1 );
   108 		return KErrGeneral;
   116 		return KErrGeneral;
   109 		}
   117 		}
   110 	
   118 	
   111 	// Endpoints
   119 	// Endpoints
   112 	TUsbcEndpointData data[KUsbcMaxEndpoints];
   120 	TUsbcEndpointData data[KUsbcMaxEndpoints];
   113 	TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
   121 	TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
   114 	ret = iLdd.EndpointCaps(dataptr);
   122 	ret = iLdd.EndpointCaps(dataptr);
   115 	LOGTEXT(_L8("\tchecking result of EndpointCaps"));
   123 	OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPINTERFACE_DUP4, 
       
   124 			"CCdcControlInterface::SetUpInterface;\tchecking result of EndpointCaps" );
       
   125 
   116 	if ( ret )
   126 	if ( ret )
   117 		{
   127 		{
   118 		LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret);
   128 		OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPINTERFACE_DUP5, "CCdcControlInterface::SetUpInterface;ret=%d", ret );
       
   129 		OstTraceFunctionExit0( CCDCCONTROLINTERFACE_SETUPINTERFACE_EXIT_DUP2 );
   119 		return ret;
   130 		return ret;
   120 		}
   131 		}
   121 
   132 
   122 	// Set the active interface
   133 	// Set the active interface
   123 	TUsbcInterfaceInfoBuf ifc;
   134 	TUsbcInterfaceInfoBuf ifc;
   124 	TBool epFound = EFalse;
   135 	TBool epFound = EFalse;
   125 	for ( TUint i = 0 ; i < totalEndpoints ; i++ )
   136 	for ( TUint i = 0 ; i < totalEndpoints ; i++ )
   126 		{
   137 		{
   127 		const TUsbcEndpointCaps* caps = &data[i].iCaps;
   138 		const TUsbcEndpointCaps* caps = &data[i].iCaps;
   128 		__ASSERT_DEBUG(caps, 
   139 		if (!caps)
   129 			_USB_PANIC(KAcmPanicCat, EPanicInternalError));
   140 			{
       
   141 			OstTraceExt1( TRACE_FATAL, CCDCCONTROLINTERFACE_SETUPINTERFACE_DUP6, "CCdcControlInterface::SetUpInterface;caps=%p", caps );
       
   142 			__ASSERT_DEBUG( EFalse, User::Panic(KAcmPanicCat, EPanicInternalError) );
       
   143 			}
   130 
   144 
   131 		if (data[i].iInUse)
   145 		if (data[i].iInUse)
   132 			{
   146 			{
   133 			continue;
   147 			continue;
   134 			}
   148 			}
   150 			ifc().iEndpointData[0].iInterval = KPollInterval; 
   164 			ifc().iEndpointData[0].iInterval = KPollInterval; 
   151 			epFound = ETrue;
   165 			epFound = ETrue;
   152 			break;
   166 			break;
   153 			}
   167 			}
   154 		}
   168 		}
   155 	LOGTEXT(_L8("\tchecking epFound"));
   169 	
       
   170 	
       
   171 	OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPINTERFACE_DUP8, "CCdcControlInterface::SetUpInterface;\tchecking epFound" );
   156 	if ( !epFound )
   172 	if ( !epFound )
   157 		{
   173 		{
   158 		LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), 
   174 		OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPINTERFACE_DUP9, "CCdcControlInterface::SetUpInterface;ret=%d", KErrGeneral );
   159 			KErrGeneral);
   175 		OstTraceFunctionExit0( CCDCCONTROLINTERFACE_SETUPINTERFACE_EXIT_DUP3 );
   160 		return KErrGeneral;
   176 		return KErrGeneral;
   161 		}
   177 		}
   162 
   178 
   163 	ifc().iString = &iIfcName;
   179 	ifc().iString = &iIfcName;
   164 	ifc().iTotalEndpointsUsed = KRequiredNumberOfEndpoints;
   180 	ifc().iTotalEndpointsUsed = KRequiredNumberOfEndpoints;
   165 	// Codes taken from USBCDC 1.1.
   181 	// Codes taken from USBCDC 1.1.
   166 	ifc().iClass.iClassNum	  = 0x02; // Table 15- Communication Interface Class
   182 	ifc().iClass.iClassNum	  = 0x02; // Table 15- Communication Interface Class
   167 	ifc().iClass.iSubClassNum = 0x02; // Table 16- Abstract Control Model
   183 	ifc().iClass.iSubClassNum = 0x02; // Table 16- Abstract Control Model
   168 	ifc().iClass.iProtocolNum = iProtocolNum; // Table 17
   184 	ifc().iClass.iProtocolNum = iProtocolNum; // Table 17
   169 
   185 
   170 	LOGTEXT(_L8("\tabout to call SetInterface"));
   186 	OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPINTERFACE_DUP10, 
       
   187 			"CCdcControlInterface::SetUpInterface;\tabout to call SetInterface" );
   171 	// Zero effectively indicates that alternate interfaces are not used.
   188 	// Zero effectively indicates that alternate interfaces are not used.
   172 	ret = iLdd.SetInterface(0, ifc);
   189 	ret = iLdd.SetInterface(0, ifc);
   173 
   190 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPINTERFACE_DUP11, "CCdcControlInterface::SetUpInterface;ret=%d", ret );
   174 	LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret);
   191 	OstTraceFunctionExit0( CCDCCONTROLINTERFACE_SETUPINTERFACE_EXIT_DUP4 );
   175 	return ret;
   192 	return ret;
   176 	}
   193 	}
   177 
   194 
   178 TInt CCdcControlInterface::SetupClassSpecificDescriptor(
   195 TInt CCdcControlInterface::SetupClassSpecificDescriptor(
   179 							TUint8 aDataInterfaceNumber)
   196 							TUint8 aDataInterfaceNumber)
   182  *
   199  *
   183  * @param aDataInterfaceNumber The interface number of the data class
   200  * @param aDataInterfaceNumber The interface number of the data class
   184  * @return Error.
   201  * @return Error.
   185  */
   202  */
   186 	{
   203 	{
   187 	LOG_FUNC
   204 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACE_SETUPCLASSSPECIFICDESCRIPTOR_ENTRY );
   188 	LOGTEXT2(_L8("\taDataInterfaceNumber = %d"), aDataInterfaceNumber);
   205 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPCLASSSPECIFICDESCRIPTOR, 
       
   206 			"CCdcControlInterface::SetupClassSpecificDescriptor;aDataInterfaceNumber=%d", (TInt)aDataInterfaceNumber );
   189 
   207 
   190 	TInt res;
   208 	TInt res;
   191 
   209 
   192 	TUsbCsClassDescriptor descriptor;
   210 	TUsbCsClassDescriptor descriptor;
   193 
   211 
   227 
   245 
   228 #endif
   246 #endif
   229 
   247 
   230 	if ( res )
   248 	if ( res )
   231 		{
   249 		{
   232 		LOGTEXT2(_L8("\t***GetInterfaceNumber=%d"), res);
   250 		OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPCLASSSPECIFICDESCRIPTOR_DUP1, 
       
   251 				"CCdcControlInterface::SetupClassSpecificDescriptor;\t***GetInterfaceNumber=%d", res );
       
   252 		OstTraceFunctionExit0( CCDCCONTROLINTERFACE_SETUPCLASSSPECIFICDESCRIPTOR_EXIT );
   233 		return res;
   253 		return res;
   234 		}
   254 		}
   235 
   255 
   236 	LOGTEXT(_L8("\tabout to call SetCSInterfaceDescriptorBlock"));
   256 	OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPCLASSSPECIFICDESCRIPTOR_DUP2, 
       
   257 			"CCdcControlInterface::SetupClassSpecificDescriptor;\tabout to call SetCSInterfaceDescriptorBlock" );
       
   258 	
   237 	res = iLdd.SetCSInterfaceDescriptorBlock(0, descriptor.Des());
   259 	res = iLdd.SetCSInterfaceDescriptorBlock(0, descriptor.Des());
   238 	if ( res )
   260 	if ( res )
   239 		{
   261 		{
   240 		LOGTEXT2(_L8("\t***SetCSInterfaceDescriptorBlock=%d"), res);
   262 		OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SETUPCLASSSPECIFICDESCRIPTOR_DUP3, 
       
   263 				"CCdcControlInterface::SetupClassSpecificDescriptor;\t***SetCSInterfaceDescriptorBlock=%d", res );
       
   264 		
       
   265 		OstTraceFunctionExit0( CCDCCONTROLINTERFACE_SETUPCLASSSPECIFICDESCRIPTOR_EXIT_DUP1 );
   241 		return res;
   266 		return res;
   242 		}
   267 		}
   243 
   268 
       
   269 	OstTraceFunctionExit0( CCDCCONTROLINTERFACE_SETUPCLASSSPECIFICDESCRIPTOR_EXIT_DUP2 );
   244 	return KErrNone;
   270 	return KErrNone;
   245 	}
   271 	}
   246 
   272 
   247 CCdcControlInterface::~CCdcControlInterface()
   273 CCdcControlInterface::~CCdcControlInterface()
   248 /**
   274 /**
   249  * Destructor
   275  * Destructor
   250  */
   276  */
   251 	{
   277 	{
   252 	LOG_FUNC
   278 	OstTraceFunctionEntry0( DUP1_CCDCCONTROLINTERFACE_CCDCCONTROLINTERFACE_ENTRY );
   253 
       
   254 	delete iReader;
   279 	delete iReader;
       
   280 	OstTraceFunctionExit0( DUP1_CCDCCONTROLINTERFACE_CCDCCONTROLINTERFACE_EXIT );
   255 	}
   281 	}
   256 
   282 
   257 /**
   283 /**
   258  * Special data object used to send a NETWORK_CONNECTION notification
   284  * Special data object used to send a NETWORK_CONNECTION notification
   259  * up to the (USB) Host, using whatever size is available on the
   285  * up to the (USB) Host, using whatever size is available on the
   281  * This function packs the TUSBNotificationSerialState class into a 
   307  * This function packs the TUSBNotificationSerialState class into a 
   282  * byte buffer with the correct byte alignment for transmission on 
   308  * byte buffer with the correct byte alignment for transmission on 
   283  * the little-endian USB bus.
   309  * the little-endian USB bus.
   284  */
   310  */
   285 	{
   311 	{
       
   312 	OstTraceFunctionEntry0( TUSBNOTIFICATIONNETWORKCONNECTION_PACKBUFFER_ENTRY );
       
   313 	
   286 	iBuffer.SetLength(KUSBNotificationNetworkConnectionSize);
   314 	iBuffer.SetLength(KUSBNotificationNetworkConnectionSize);
   287 
   315 
   288 	iBuffer[0] = bmRequestType;
   316 	iBuffer[0] = bmRequestType;
   289 	iBuffer[1] = bNotification;
   317 	iBuffer[1] = bNotification;
   290 	iBuffer[2] = static_cast<TUint8>( wValue	& 0x00ff);
   318 	iBuffer[2] = static_cast<TUint8>( wValue	& 0x00ff);
   292 	iBuffer[4] = static_cast<TUint8>( wIndex	& 0x00ff);
   320 	iBuffer[4] = static_cast<TUint8>( wIndex	& 0x00ff);
   293 	iBuffer[5] = static_cast<TUint8>((wIndex	& 0xff00) >> 8);
   321 	iBuffer[5] = static_cast<TUint8>((wIndex	& 0xff00) >> 8);
   294 	iBuffer[6] = static_cast<TUint8>( wLength & 0x00ff);
   322 	iBuffer[6] = static_cast<TUint8>( wLength & 0x00ff);
   295 	iBuffer[7] = static_cast<TUint8>((wLength & 0xff00) >> 8);
   323 	iBuffer[7] = static_cast<TUint8>((wLength & 0xff00) >> 8);
   296 
   324 
       
   325 	OstTraceFunctionExit0( TUSBNOTIFICATIONNETWORKCONNECTION_PACKBUFFER_EXIT );
   297 	return iBuffer;
   326 	return iBuffer;
   298 	}
   327 	}
   299 
   328 
   300 TInt CCdcControlInterface::SendNetworkConnection(TBool aValue)
   329 TInt CCdcControlInterface::SendNetworkConnection(TBool aValue)
   301 /**
   330 /**
   307  *
   336  *
   308  * @param aValue	ETrue if Network Connected
   337  * @param aValue	ETrue if Network Connected
   309  * @return Error.
   338  * @return Error.
   310  */
   339  */
   311 	{
   340 	{
   312 	LOGTEXT2(_L8(">>CCdcControlInterface::SendNetworkConnection aValue=%d"), 
   341 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACE_SENDNETWORKCONNECTION_ENTRY );
   313 		aValue);
   342 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SENDNETWORKCONNECTION, 
       
   343 			"CCdcControlInterface::SendNetworkConnection;aValue=%d", (TInt)aValue );
   314 
   344 
   315 	// form the message and prime it down to the interrupt handler
   345 	// form the message and prime it down to the interrupt handler
   316 	// (that is 'interrupt' in the USB sense)
   346 	// (that is 'interrupt' in the USB sense)
   317 
   347 
   318 	// Note that this does not need to be aware of endian-ness, this
   348 	// Note that this does not need to be aware of endian-ness, this
   327 
   357 
   328 	TInt ret = WriteData(EEndpoint1, 
   358 	TInt ret = WriteData(EEndpoint1, 
   329 		notification.PackBuffer(), 
   359 		notification.PackBuffer(), 
   330 		notification.PackBuffer().Length());
   360 		notification.PackBuffer().Length());
   331 
   361 
   332 	LOGTEXT2(_L8("<<CCdcControlInterface::SendNetworkConnection ret=%d"), ret);
   362 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SENDNETWORKCONNECTION_DUP1, 
       
   363 			"CCdcControlInterface::SendNetworkConnection;ret=%d", ret );
       
   364 	OstTraceFunctionExit0( CCDCCONTROLINTERFACE_SENDNETWORKCONNECTION_EXIT );
   333 	return ret;
   365 	return ret;
   334 	}
   366 	}
   335 
   367 
   336 /**
   368 /**
   337  * Special data object used to send a SERIAL_STATE notification
   369  * Special data object used to send a SERIAL_STATE notification
   361  * This function packs the TUSBNotificationSerialState class into a 
   393  * This function packs the TUSBNotificationSerialState class into a 
   362  * byte buffer with the correct byte alignment for transmission on 
   394  * byte buffer with the correct byte alignment for transmission on 
   363  * the little-endian USB bus.
   395  * the little-endian USB bus.
   364  */
   396  */
   365 	{
   397 	{
       
   398 	OstTraceFunctionEntry0( TUSBNOTIFICATIONSERIALSTATE_PACKBUFFER_ENTRY );
       
   399 	
   366 	iBuffer.SetLength(KUSBNotificationSerialStateSize);
   400 	iBuffer.SetLength(KUSBNotificationSerialStateSize);
   367 
   401 
   368 	iBuffer[0] = bmRequestType;
   402 	iBuffer[0] = bmRequestType;
   369 	iBuffer[1] = bNotification;
   403 	iBuffer[1] = bNotification;
   370 	iBuffer[2] = static_cast<TUint8>( wValue	& 0x00ff);
   404 	iBuffer[2] = static_cast<TUint8>( wValue	& 0x00ff);
   374 	iBuffer[6] = static_cast<TUint8>( wLength & 0x00ff);
   408 	iBuffer[6] = static_cast<TUint8>( wLength & 0x00ff);
   375 	iBuffer[7] = static_cast<TUint8>((wLength & 0xff00) >> 8);
   409 	iBuffer[7] = static_cast<TUint8>((wLength & 0xff00) >> 8);
   376 	iBuffer[8] = static_cast<TUint8>( wData & 0x00ff);
   410 	iBuffer[8] = static_cast<TUint8>( wData & 0x00ff);
   377 	iBuffer[9] = static_cast<TUint8>((wData & 0xff00) >> 8);
   411 	iBuffer[9] = static_cast<TUint8>((wData & 0xff00) >> 8);
   378 
   412 
       
   413 	OstTraceFunctionExit0( TUSBNOTIFICATIONSERIALSTATE_PACKBUFFER_EXIT );
   379 	return iBuffer;
   414 	return iBuffer;
   380 	}
   415 	}
   381 
   416 
   382 TInt CCdcControlInterface::SendSerialState(TBool aOverRun, 
   417 TInt CCdcControlInterface::SendSerialState(TBool aOverRun, 
   383 									 TBool aParity, 
   418 									 TBool aParity, 
   397  * @param aTxCarrier True if the transmit carrier is present
   432  * @param aTxCarrier True if the transmit carrier is present
   398  * @param aRxCarrier True if the receive carrier is present
   433  * @param aRxCarrier True if the receive carrier is present
   399  * @return Error.
   434  * @return Error.
   400  */
   435  */
   401 	{
   436 	{
   402 	LOG_FUNC
   437 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACE_SENDSERIALSTATE_ENTRY );
   403 	LOGTEXT2(_L8("\taOverRun=%d"), aOverRun);
   438 	
   404 	LOGTEXT2(_L8("\taParity=%d"), aParity);
   439 	OstTrace1( TRACE_DUMP, CCDCCONTROLINTERFACE_SENDSERIALSTATE, 
   405 	LOGTEXT2(_L8("\taFraming=%d"), aFraming);
   440 			"CCdcControlInterface::SendSerialState;aOverRun=%d", (TInt)aOverRun );
   406 	LOGTEXT2(_L8("\taRing=%d"), aRing);
   441 	OstTrace1( TRACE_DUMP, CCDCCONTROLINTERFACE_SENDSERIALSTATE_DUP1, 
   407 	LOGTEXT2(_L8("\taBreak=%d"), aBreak);
   442 			"CCdcControlInterface::SendSerialState;aParity=%d", (TInt)aParity );
   408 	LOGTEXT2(_L8("\taTxCarrier=%d"), aTxCarrier);
   443 	OstTrace1( TRACE_DUMP, CCDCCONTROLINTERFACE_SENDSERIALSTATE_DUP2, 
   409 	LOGTEXT2(_L8("\taRxCarrier=%d"), aRxCarrier);
   444 			"CCdcControlInterface::SendSerialState;aFraming=%d", (TInt)aFraming );
       
   445 	OstTrace1( TRACE_DUMP, CCDCCONTROLINTERFACE_SENDSERIALSTATE_DUP3, 
       
   446 			"CCdcControlInterface::SendSerialState;aRing=%d", (TInt)aRing );
       
   447 	OstTrace1( TRACE_DUMP, CCDCCONTROLINTERFACE_SENDSERIALSTATE_DUP4, 
       
   448 			"CCdcControlInterface::SendSerialState;aBreak=%d", (TInt)aBreak );
       
   449 	OstTrace1( TRACE_DUMP, CCDCCONTROLINTERFACE_SENDSERIALSTATE_DUP5, 
       
   450 			"CCdcControlInterface::SendSerialState;aTxCarrier=%d", (TInt)aTxCarrier );
       
   451 	OstTrace1( TRACE_DUMP, CCDCCONTROLINTERFACE_SENDSERIALSTATE_DUP6, 
       
   452 			"CCdcControlInterface::SendSerialState;aRxCarrier=%d", (TInt)aRxCarrier );
   410 
   453 
   411 	// First work out what might need to be sent by assembling the bits into 
   454 	// First work out what might need to be sent by assembling the bits into 
   412 	// the correct places. See CDC spec table 69 (UART state bitmap values).
   455 	// the correct places. See CDC spec table 69 (UART state bitmap values).
   413 	TUint16 data = static_cast<TUint16>
   456 	TUint16 data = static_cast<TUint16>
   414 					(
   457 					(
   424 	// now check to see if this has created a different state than
   467 	// now check to see if this has created a different state than
   425 	// last time it was sent, if it is the same, don't bother to
   468 	// last time it was sent, if it is the same, don't bother to
   426 	// send it off.
   469 	// send it off.
   427 	if ( data == iSerialState )
   470 	if ( data == iSerialState )
   428 		{
   471 		{
   429 		LOGTEXT(_L8("\tdata == iSerialState"));
   472 		OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACE_SENDSERIALSTATE_DUP7, 
       
   473 				"CCdcControlInterface::SendSerialState;\tdata == iSerialState" );
       
   474 		OstTraceFunctionExit0( CCDCCONTROLINTERFACE_SENDSERIALSTATE_EXIT );
   430 		return KErrNone;
   475 		return KErrNone;
   431 		}
   476 		}
   432 
   477 
   433 	// state is different, store local to the class object ready for
   478 	// state is different, store local to the class object ready for
   434 	// testing next time through
   479 	// testing next time through
   449 	notification.wData		   = data;
   494 	notification.wData		   = data;
   450 
   495 
   451 	TInt ret = WriteData(	EEndpoint1, 
   496 	TInt ret = WriteData(	EEndpoint1, 
   452 							notification.PackBuffer(), 
   497 							notification.PackBuffer(), 
   453 							notification.PackBuffer().Length());
   498 							notification.PackBuffer().Length());
   454 	LOGTEXT2(_L8("\tWriteData = %d"), ret);
   499 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_SENDSERIALSTATE_DUP8, "CCdcControlInterface::SendSerialState;ret=%d", ret );
   455 
   500 	OstTraceFunctionExit0( DUP1_CCDCCONTROLINTERFACE_SENDSERIALSTATE_EXIT );
   456 	return ret;
   501 	return ret;
   457 	}
   502 	}
   458 
   503 
   459 TInt CCdcControlInterface::WriteData(TEndpointNumber aEndPoint, 
   504 TInt CCdcControlInterface::WriteData(TEndpointNumber aEndPoint, 
   460 							   TDes8& aDes, 
   505 							   TDes8& aDes, 
   465  * @param aEndPoint
   510  * @param aEndPoint
   466  * @param aDes
   511  * @param aDes
   467  * @param aLength
   512  * @param aLength
   468  */
   513  */
   469 	{
   514 	{
   470 	LOG_FUNC
   515 	OstTraceFunctionEntry0( CCDCCONTROLINTERFACE_WRITEDATA_ENTRY );
   471 	LOGTEXT2(_L8("\taEndpoint=%d"), aEndPoint);
   516 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_WRITEDATA, "CCdcControlInterface::WriteData;aEndPoint=%d", (TInt)aEndPoint );
   472 
   517 
   473 	TInt ret;
   518 	TInt ret;
   474 	RTimer timer;
   519 	RTimer timer;
   475 	ret = timer.CreateLocal();
   520 	ret = timer.CreateLocal();
   476 	if ( ret )
   521 	if ( ret )
   477 		{
   522 		{
   478 		LOGTEXT2(_L8("\ttimer.CreateLocal = %d- returning"), ret);
   523 		OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_WRITEDATA_DUP1, 
       
   524 				"CCdcControlInterface::WriteData;\ttimer.CreateLocal = %d- returning", ret );
       
   525 		
       
   526 		OstTraceFunctionExit0( CCDCCONTROLINTERFACE_WRITEDATA_EXIT );
   479 		return ret;
   527 		return ret;
   480 		}
   528 		}
   481 	TRequestStatus status;
   529 	TRequestStatus status;
   482 	TRequestStatus timerStatus;
   530 	TRequestStatus timerStatus;
   483 	LOGTEXT(_L8("\tAttempting to write data to control interface"));
   531 	OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACE_WRITEDATA_DUP2, 
       
   532 			"CCdcControlInterface::WriteData;\tAttempting to write data to control interface" );
       
   533 
   484 	iLdd.Write(status, aEndPoint, aDes, aLength);
   534 	iLdd.Write(status, aEndPoint, aDes, aLength);
   485 	timer.After(timerStatus, KWriteDataTimeout);
   535 	timer.After(timerStatus, KWriteDataTimeout);
   486 	User::WaitForRequest(status, timerStatus);
   536 	User::WaitForRequest(status, timerStatus);
   487 	if ( timerStatus != KRequestPending )
   537 	if ( timerStatus != KRequestPending )
   488 		{
   538 		{
   489 		// Timeout occurred, silently ignore error condition.
   539 		// Timeout occurred, silently ignore error condition.
   490 		// Assuming that the line has been disconnected
   540 		// Assuming that the line has been disconnected
   491 		LOGTEXT(_L8("CCdcControlInterface::WriteData() - Timeout occurred"));
   541 		OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACE_WRITEDATA_DUP3, 
       
   542 				"CCdcControlInterface::WriteData;CCdcControlInterface::WriteData() - Timeout occurred" );
       
   543 		
   492 		iLdd.WriteCancel(aEndPoint);
   544 		iLdd.WriteCancel(aEndPoint);
   493 		User::WaitForRequest(status);
   545 		User::WaitForRequest(status);
   494 		ret = timerStatus.Int();
   546 		ret = timerStatus.Int();
   495 		}
   547 		}
   496 	else
   548 	else
   497 		{
   549 		{
   498 		LOGTEXT(_L8("CCdcControlInterface::WriteData() - Write completed"));
   550 		OstTrace0( TRACE_NORMAL, CCDCCONTROLINTERFACE_WRITEDATA_DUP4, 
       
   551 				"CCdcControlInterface::WriteData;CCdcControlInterface::WriteData() - Write completed" );
       
   552 		
   499 		timer.Cancel();
   553 		timer.Cancel();
   500 		User::WaitForRequest(timerStatus);
   554 		User::WaitForRequest(timerStatus);
   501 		ret = status.Int();
   555 		ret = status.Int();
   502 		}
   556 		}
   503 
   557 
   504 	LOGTEXT2(_L8("\treturning %d"), ret);
   558 	OstTrace1( TRACE_NORMAL, CCDCCONTROLINTERFACE_WRITEDATA_DUP5, "CCdcControlInterface::WriteData;ret=%d", ret );
       
   559 	OstTraceFunctionExit0( CCDCCONTROLINTERFACE_WRITEDATA_EXIT_DUP1 );
   505 	return ret;
   560 	return ret;
   506 	}
   561 	}
   507 
   562 
   508 //
   563 //
   509 // End of file
   564 // End of file