usbmgmt/usbmgrtest/t_usbmanager_suite/Stub3CC/src/Stub3CC.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".
    20 
    20 
    21 /**
    21 /**
    22  @file
    22  @file
    23 */
    23 */
    24 
    24 
       
    25 #include "Stub3CC.h"
    25 #include <usb_std.h>
    26 #include <usb_std.h>
    26 #include <es_ini.h>
    27 #include <es_ini.h>
    27 #include <d32usbc.h>
    28 #include <d32usbc.h>
    28 #include "Stub3CC.h"
    29 #include <usb/usblogger.h>
    29 
    30 
    30 #ifdef __FLOG_ACTIVE
    31 #ifdef __FLOG_ACTIVE
    31 _LIT8(KLogComponent, "STUB3CC");
    32 _LIT8(KLogComponent, "STUB3CC");
    32 #endif
    33 #endif
    33 
    34 
    34 
    35 
    35 #include "usbmaninternalconstants.h"
    36 #include "usbmaninternalconstants.h"
    36 #include "OstTraceDefinitions.h"
       
    37 #ifdef OST_TRACE_COMPILER_IN_USE
       
    38 #include "Stub3CCTraces.h"
       
    39 #endif
       
    40 
       
    41  
    37  
    42 
    38 
    43 // Panic category 
    39 // Panic category 
    44 _LIT( Kstub3CcPanicCategory, "Usbstub3Cc" );
    40 _LIT( Kstub3CcPanicCategory, "Usbstub3Cc" );
    45 
    41 
   164  *
   160  *
   165  * @param aStatus The caller's request status, filled in with an error code
   161  * @param aStatus The caller's request status, filled in with an error code
   166  */
   162  */
   167 void CUsbstub3ClassController::Start(TRequestStatus& aStatus)
   163 void CUsbstub3ClassController::Start(TRequestStatus& aStatus)
   168 	{
   164 	{
   169     OstTraceFunctionEntry0( CUSBSTUB3CLASSCONTROLLER_START_ENTRY );
   165 	LOG_FUNC
   170     
   166 
   171 	aStatus = KRequestPending;
   167 	aStatus = KRequestPending;
   172 	iReportStatus = &aStatus;
   168 	iReportStatus = &aStatus;
   173 	//If we are already started then just complete the request.
   169 	//If we are already started then just complete the request.
   174 	if (iState == EUsbServiceStarted)
   170 	if (iState == EUsbServiceStarted)
   175 		{
   171 		{
   176 		User::RequestComplete(iReportStatus, KErrNone);
   172 		User::RequestComplete(iReportStatus, KErrNone);
   177 		OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_START_EXIT );
       
   178 		return;
   173 		return;
   179 		}
   174 		}
   180 
   175 
   181 	if (iFailToStart)
   176 	if (iFailToStart)
   182 		{
   177 		{
   183 		User::RequestComplete(iReportStatus, KErrGeneral);
   178 		User::RequestComplete(iReportStatus, KErrGeneral);
   184 		OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_START_EXIT_DUP1 );
       
   185 		return;
   179 		return;
   186 		}
   180 		}
   187 	
   181 	
   188 	iState = EUsbServiceStarting;
   182 	iState = EUsbServiceStarting;
   189 	
   183 	
   190 #ifndef __WINS__	
   184 #ifndef __WINS__	
   191 	TInt ret = iLdd.Open(0);
   185 	TInt ret = iLdd.Open(0);
   192 	OstTrace1( TRACE_NORMAL, CUSBSTUB3CLASSCONTROLLER_START, _L8("Open LDD, ret=%d"), ret );
   186 	LOGTEXT2(_L8("Open LDD, ret=%d"), ret);
   193 	
       
   194 	ret = SetUpInterface();
   187 	ret = SetUpInterface();
   195 	OstTrace1( TRACE_NORMAL, CUSBSTUB3CLASSCONTROLLER_START_DUP1, 
   188 	LOGTEXT2(_L8("SetUpInterface(), ret=%d"), ret);
   196 	        _L8("SetUpInterface(), ret=%d"), ret );
       
   197 	
       
   198 #endif	
   189 #endif	
   199 
   190 
   200 
   191 
   201 	iTimer.After(iStatus, iStartDelay*1000);  //convert from usec to msec
   192 	iTimer.After(iStatus, iStartDelay*1000);  //convert from usec to msec
   202 	SetActive();
   193 	SetActive();
   203 	OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_START_EXIT_DUP2 );
       
   204 	}
   194 	}
   205 
   195 
   206 /**
   196 /**
   207  * Called by UsbMan when it wants to stop the USB stub3 class.
   197  * Called by UsbMan when it wants to stop the USB stub3 class.
   208  *
   198  *
   209  * @param aStatus The caller's request status: always set to KErrNone
   199  * @param aStatus The caller's request status: always set to KErrNone
   210  */
   200  */
   211 void CUsbstub3ClassController::Stop(TRequestStatus& aStatus)
   201 void CUsbstub3ClassController::Stop(TRequestStatus& aStatus)
   212 	{
   202 	{
   213 	OstTraceFunctionEntry0( CUSBSTUB3CLASSCONTROLLER_STOP_ENTRY );
   203 	LOG_FUNC
   214 	
   204 
   215 	aStatus = KRequestPending;
   205 	aStatus = KRequestPending;
   216 	iReportStatus = &aStatus;
   206 	iReportStatus = &aStatus;
   217 	//If we are already idle then just complete the request.
   207 	//If we are already idle then just complete the request.
   218 	if (iState == EUsbServiceIdle)
   208 	if (iState == EUsbServiceIdle)
   219 		{
   209 		{
   220 		User::RequestComplete(iReportStatus, KErrNone);
   210 		User::RequestComplete(iReportStatus, KErrNone);
   221 		OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_STOP_EXIT );
       
   222 		return;
   211 		return;
   223 		}
   212 		}
   224 
   213 
   225 	if (iFailToStop)
   214 	if (iFailToStop)
   226 		{
   215 		{
   227 		User::RequestComplete(iReportStatus, KErrGeneral);
   216 		User::RequestComplete(iReportStatus, KErrGeneral);
   228 		OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_STOP_EXIT_DUP1 );
       
   229 		return;
   217 		return;
   230 		}
   218 		}
   231 
   219 
   232 	iState = EUsbServiceStopping;
   220 	iState = EUsbServiceStopping;
   233 
   221 
   236 #endif
   224 #endif
   237 
   225 
   238 	
   226 	
   239 	iTimer.After(iStatus, iStopDelay*1000);  //convert from usec to msec
   227 	iTimer.After(iStatus, iStopDelay*1000);  //convert from usec to msec
   240 	SetActive();
   228 	SetActive();
   241 	OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_STOP_EXIT_DUP2 );
       
   242 	}
   229 	}
   243 
   230 
   244 /**
   231 /**
   245  * Gets information about the descriptor which this class provides.
   232  * Gets information about the descriptor which this class provides.
   246  *
   233  *
   247  * @param aDescriptorInfo Descriptor info structure filled in by this function
   234  * @param aDescriptorInfo Descriptor info structure filled in by this function
   248  */
   235  */
   249 void CUsbstub3ClassController::GetDescriptorInfo(TUsbDescriptor& aDescriptorInfo) const
   236 void CUsbstub3ClassController::GetDescriptorInfo(TUsbDescriptor& aDescriptorInfo) const
   250 	{
   237 	{
   251     OstTraceFunctionEntry0( CUSBSTUB3CLASSCONTROLLER_GETDESCRIPTORINFO_ENTRY );
   238 	LOG_FUNC
   252     
   239 
   253 	aDescriptorInfo.iLength = Kstub3DescriptorLength;
   240 	aDescriptorInfo.iLength = Kstub3DescriptorLength;
   254 	aDescriptorInfo.iNumInterfaces = Kstub3NumberOfInterfacesPerstub3Function;
   241 	aDescriptorInfo.iNumInterfaces = Kstub3NumberOfInterfacesPerstub3Function;
   255 	
       
   256 	OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_GETDESCRIPTORINFO_EXIT );
       
   257 	}
   242 	}
   258 
   243 
   259 
   244 
   260 /**
   245 /**
   261  * Standard active object RunL. 
   246  * Standard active object RunL. 
   262  */
   247  */
   263 void CUsbstub3ClassController::RunL()
   248 void CUsbstub3ClassController::RunL()
   264 	{
   249 	{
   265     OstTraceFunctionEntry0( CUSBSTUB3CLASSCONTROLLER_RUNL_ENTRY );
   250 	LOG_FUNC
   266     
   251 
   267     if(iStatus != KErrNone)
   252 	__ASSERT_DEBUG( iStatus == KErrNone, _USB_PANIC(Kstub3CcPanicCategory, EPanicUnexpectedStatus) );
   268         {
       
   269             OstTrace1( TRACE_FATAL, CUSBSTUB3CLASSCONTROLLER_RUNL, 
       
   270                     "CUsbstub3ClassController::RunL panic with error %d", EPanicUnexpectedStatus );
       
   271             __ASSERT_DEBUG(EFalse,User::Panic(Kstub3CcPanicCategory,EPanicUnexpectedStatus));
       
   272         }
       
   273 	switch (iState)
   253 	switch (iState)
   274 		{
   254 		{
   275 		case EUsbServiceStarting:
   255 		case EUsbServiceStarting:
   276 			iState = EUsbServiceStarted;
   256 			iState = EUsbServiceStarted;
   277 			break;
   257 			break;
   278 		case EUsbServiceStopping:
   258 		case EUsbServiceStopping:
   279 			iState = EUsbServiceIdle;
   259 			iState = EUsbServiceIdle;
   280 			break;
   260 			break;
   281 		default:	
   261 		default:	
   282 		    OstTrace1( TRACE_FATAL, CUSBSTUB3CLASSCONTROLLER_RUNL_DUP1, 
   262 			_USB_PANIC(Kstub3CcPanicCategory, EPanicUnexpectedState);
   283 		             "CUsbstub3ClassController::RunL panic with error %d", EPanicUnexpectedStatus );
       
   284 		    User::Panic(Kstub3CcPanicCategory,EPanicUnexpectedStatus);
       
   285 		}
   263 		}
   286 	*iReportStatus = KErrNone;	
   264 	*iReportStatus = KErrNone;	
   287 	User::RequestComplete(iReportStatus, iStatus.Int());	
   265 	User::RequestComplete(iReportStatus, iStatus.Int());	
   288 	OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_RUNL_EXIT );
       
   289 	}
   266 	}
   290 
   267 
   291 /**
   268 /**
   292  * Standard active object cancellation function. Never called because this
   269  * Standard active object cancellation function. Never called because this
   293  * class has no asynchronous requests.
   270  * class has no asynchronous requests.
   305 			iState = EUsbServiceIdle;
   282 			iState = EUsbServiceIdle;
   306 			break;
   283 			break;
   307 		case EUsbServiceStopping:
   284 		case EUsbServiceStopping:
   308 			iState = EUsbServiceStarted;
   285 			iState = EUsbServiceStarted;
   309 			break;
   286 			break;
   310 		default:
   287 		default:	
   311 		    OstTrace1( TRACE_FATAL, CUSBSTUB3CLASSCONTROLLER_DOCANCEL, 
   288 			_USB_PANIC(Kstub3CcPanicCategory, EPanicUnexpectedState);
   312 		            "CUsbstub3ClassController::DoCancel panic with error %d", EPanicUnexpectedStatus );
       
   313 		    User::Panic(Kstub3CcPanicCategory,EPanicUnexpectedStatus);
       
   314 	}
   289 	}
   315 	*iReportStatus = KErrNone;		
   290 	*iReportStatus = KErrNone;		
   316 	User::RequestComplete(iReportStatus, KErrCancel);	
   291 	User::RequestComplete(iReportStatus, KErrCancel);	
   317 	}
   292 	}
   318 
   293 
   323  * @param aError The error code (unused)
   298  * @param aError The error code (unused)
   324  * @return Always KErrNone to avoid an active scheduler panic
   299  * @return Always KErrNone to avoid an active scheduler panic
   325  */
   300  */
   326 TInt CUsbstub3ClassController::RunError(TInt /*aError*/)
   301 TInt CUsbstub3ClassController::RunError(TInt /*aError*/)
   327 	{
   302 	{
   328     OstTrace1( TRACE_FATAL, CUSBSTUB3CLASSCONTROLLER_RUNERROR, 
   303 	__ASSERT_DEBUG( EFalse, _USB_PANIC(Kstub3CcPanicCategory, EUnusedFunction) );
   329              "CUsbstub3ClassController::RunError panic with error %d", EUnusedFunction );
       
   330     __ASSERT_DEBUG(EFalse,User::Panic(Kstub3CcPanicCategory,EUnusedFunction));
       
   331 	return KErrNone;
   304 	return KErrNone;
   332 	}
   305 	}
   333 
   306 
   334 TInt CUsbstub3ClassController::SetUpInterface()
   307 TInt CUsbstub3ClassController::SetUpInterface()
   335 /**
   308 /**
   336  * Set up the interface for use. This involves finding a "Interrupt IN" 
   309  * Set up the interface for use. This involves finding a "Interrupt IN" 
   337  * endpoint and, if found, configuring the interface.
   310  * endpoint and, if found, configuring the interface.
   338  */
   311  */
   339 	{
   312 	{
   340     OstTraceFunctionEntry0( CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_ENTRY );
   313 	LOG_FUNC
   341     
   314 
   342 	TUsbDeviceCaps dCaps;
   315 	TUsbDeviceCaps dCaps;
   343 	TInt ret = iLdd.DeviceCaps(dCaps);
   316 	TInt ret = iLdd.DeviceCaps(dCaps);
   344 	OstTrace0( TRACE_NORMAL, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE,
   317 	LOGTEXT(_L8("\tchecking result of DeviceCaps"));
   345 	        _L8("\tchecking result of DeviceCaps"));
       
   346 	
       
   347 	if ( ret )
   318 	if ( ret )
   348 		{
   319 		{
   349         OstTrace1( TRACE_ERROR, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_DUP1, 
   320 		LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret);
   350                 _L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret );
       
   351         
       
   352 		OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_EXIT );
       
   353 		return ret;
   321 		return ret;
   354 		}
   322 		}
   355 
   323 
   356 	const TUint KRequiredNumberOfEndpoints = 1; // in addition to endpoint 0.
   324 	const TUint KRequiredNumberOfEndpoints = 1; // in addition to endpoint 0.
   357 
   325 
   358 	const TUint totalEndpoints = static_cast<TUint>(dCaps().iTotalEndpoints);
   326 	const TUint totalEndpoints = static_cast<TUint>(dCaps().iTotalEndpoints);
   359 	OstTrace1( TRACE_NORMAL, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_DUP2, 
   327 	LOGTEXT2(_L8("\tiTotalEndpoints = %d"), totalEndpoints);
   360 	        _L8("\tiTotalEndpoints = %d"), totalEndpoints );
       
   361 	
       
   362 	if ( totalEndpoints < KRequiredNumberOfEndpoints )
   328 	if ( totalEndpoints < KRequiredNumberOfEndpoints )
   363 		{
   329 		{
   364         OstTrace1( TRACE_ERROR, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_DUP3, 
   330 		LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), 
   365                 _L8("<<CCdcControlInterface::SetUpInterface ret=%d"), KErrGeneral );
   331 			KErrGeneral);
   366         
       
   367 		OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_EXIT_DUP1 );
       
   368 		return KErrGeneral;
   332 		return KErrGeneral;
   369 		}
   333 		}
   370 	
   334 	
   371 	// Endpoints
   335 	// Endpoints
   372 	TUsbcEndpointData data[KUsbcMaxEndpoints];
   336 	TUsbcEndpointData data[KUsbcMaxEndpoints];
   373 	TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
   337 	TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
   374 	ret = iLdd.EndpointCaps(dataptr);
   338 	ret = iLdd.EndpointCaps(dataptr);
   375 	OstTrace0( TRACE_NORMAL, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_DUP4,
   339 	LOGTEXT(_L8("\tchecking result of EndpointCaps"));
   376 	        _L8("\tchecking result of EndpointCaps"));
       
   377 	
       
   378 	if ( ret )
   340 	if ( ret )
   379 		{
   341 		{
   380         OstTrace1( TRACE_ERROR, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_DUP5, 
   342 		LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret);
   381                 _L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret );
       
   382         
       
   383 		OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_EXIT_DUP2 );
       
   384 		return ret;
   343 		return ret;
   385 		}
   344 		}
   386 
   345 
   387 	// Set the active interface
   346 	// Set the active interface
   388 	TUsbcInterfaceInfoBuf ifc;
   347 	TUsbcInterfaceInfoBuf ifc;
   389 	TBool epFound = EFalse;
   348 	TBool epFound = EFalse;
   390 	for ( TUint i = 0 ; i < totalEndpoints ; i++ )
   349 	for ( TUint i = 0 ; i < totalEndpoints ; i++ )
   391 		{
   350 		{
   392 		const TUsbcEndpointCaps* caps = &data[i].iCaps;
   351 		const TUsbcEndpointCaps* caps = &data[i].iCaps;
   393 		if(!caps)
   352 		__ASSERT_DEBUG(caps,_USB_PANIC(Kstub3CcPanicCategory, EPanicUnexpectedStatus));
   394 		    {
       
   395                 OstTrace1( TRACE_FATAL, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_DUP6, 
       
   396                         "CUsbstub3ClassController::SetUpInterface panic with error %d", 
       
   397                         EPanicUnexpectedStatus );
       
   398                 __ASSERT_DEBUG(EFalse,User::Panic(Kstub3CcPanicCategory,EPanicUnexpectedStatus));
       
   399 		    }
       
   400 
   353 
   401 		if (data[i].iInUse)
   354 		if (data[i].iInUse)
   402 			{
   355 			{
   403 			continue;
   356 			continue;
   404 			}
   357 			}
   420 			ifc().iEndpointData[0].iInterval = KPollInterval; 
   373 			ifc().iEndpointData[0].iInterval = KPollInterval; 
   421 			epFound = ETrue;
   374 			epFound = ETrue;
   422 			break;
   375 			break;
   423 			}
   376 			}
   424 		}
   377 		}
   425 	OstTrace0( TRACE_NORMAL, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_DUP7, _L8("\tchecking epFound"));
   378 	LOGTEXT(_L8("\tchecking epFound"));
   426 	
       
   427 	if ( !epFound )
   379 	if ( !epFound )
   428 		{
   380 		{
   429         OstTrace1( TRACE_ERROR, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_DUP8, 
   381 		LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), 
   430                 _L8("<<CCdcControlInterface::SetUpInterface ret=%d"), KErrGeneral);
   382 			KErrGeneral);
   431         
       
   432 		OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_EXIT_DUP3 );
       
   433 		return KErrGeneral;
   383 		return KErrGeneral;
   434 		}
   384 		}
   435 
   385 
   436 	TName ifcName(KIfcName);
   386 	TName ifcName(KIfcName);
   437 	ifc().iString = &ifcName;
   387 	ifc().iString = &ifcName;
   439 	// Codes taken from USBCDC 1.1.
   389 	// Codes taken from USBCDC 1.1.
   440 	ifc().iClass.iClassNum	  = 0x02; // Table 15- Communication Interface Class
   390 	ifc().iClass.iClassNum	  = 0x02; // Table 15- Communication Interface Class
   441 	ifc().iClass.iSubClassNum = 0x02; // Table 16- Abstract Control Model
   391 	ifc().iClass.iSubClassNum = 0x02; // Table 16- Abstract Control Model
   442 	ifc().iClass.iProtocolNum = 0x01; // Table 17- Hayes compatible
   392 	ifc().iClass.iProtocolNum = 0x01; // Table 17- Hayes compatible
   443 
   393 
   444 	OstTrace0( TRACE_NORMAL, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_DUP9,
   394 	LOGTEXT(_L8("\tabout to call SetInterface"));
   445 	        _L8("\tabout to call SetInterface"));
       
   446 	
       
   447 	// Zero effectively indicates that alternate interfaces are not used.
   395 	// Zero effectively indicates that alternate interfaces are not used.
   448 	ret = iLdd.SetInterface(0, ifc);
   396 	ret = iLdd.SetInterface(0, ifc);
   449 
   397 
   450 	OstTrace1( TRACE_NORMAL, CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_DUP10, 
   398 	LOGTEXT2(_L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret);
   451 	        _L8("<<CCdcControlInterface::SetUpInterface ret=%d"), ret );
       
   452 	
       
   453 	OstTraceFunctionExit0( CUSBSTUB3CLASSCONTROLLER_SETUPINTERFACE_EXIT_DUP4 );
       
   454 	return ret;
   399 	return ret;
   455 	}
   400 	}
   456 
   401 
   457 //
   402 //
   458 // End of file
   403 // End of file