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