kerneltest/e32test/usbho/t_usbdi/src/TestDeviceBase.cpp
changeset 259 57b9594f5772
parent 0 a41df078684a
child 257 3e88ff8f41d5
child 269 d57b86b1867a
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    23 #include "softwareconnecttimer.h"
    23 #include "softwareconnecttimer.h"
    24 #include "wakeuptimer.h"
    24 #include "wakeuptimer.h"
    25 #include "controltransferrequests.h"
    25 #include "controltransferrequests.h"
    26 #include "testinterfacebase.h"
    26 #include "testinterfacebase.h"
    27 #include "PBASE-T_USBDI-0486.h"
    27 #include "PBASE-T_USBDI-0486.h"
       
    28 #include "OstTraceDefinitions.h"
       
    29 #ifdef OST_TRACE_COMPILER_IN_USE
       
    30 #include "TestDeviceBaseTraces.h"
       
    31 #endif
    28 #include <e32property.h>
    32 #include <e32property.h>
    29 
    33 
    30 namespace NUnitTesting_USBDI
    34 namespace NUnitTesting_USBDI
    31 	{
    35 	{
    32 
    36 
    35 	iCurrentState(EUsbcDeviceStateUndefined), 
    39 	iCurrentState(EUsbcDeviceStateUndefined), 
    36 	iDeviceEp0(NULL), 
    40 	iDeviceEp0(NULL), 
    37 	iConnectTimer(NULL), iWakeupTimer(NULL),
    41 	iConnectTimer(NULL), iWakeupTimer(NULL),
    38 	iAuxBuffer(NULL)
    42 	iAuxBuffer(NULL)
    39 	{
    43 	{
       
    44 	OstTraceFunctionEntry1( RUSBTESTDEVICE_RUSBTESTDEVICE_ENTRY, this );
       
    45 	OstTraceFunctionExit1( RUSBTESTDEVICE_RUSBTESTDEVICE_EXIT, this );
    40 	}
    46 	}
    41 	
    47 	
    42 RUsbTestDevice::RUsbTestDevice(CBaseTestCase* aTestCase)
    48 RUsbTestDevice::RUsbTestDevice(CBaseTestCase* aTestCase)
    43 : 	iStateWatcher(NULL), 
    49 : 	iStateWatcher(NULL), 
    44 	iCurrentState(EUsbcDeviceStateUndefined), 
    50 	iCurrentState(EUsbcDeviceStateUndefined), 
    45 	iDeviceEp0(NULL), 
    51 	iDeviceEp0(NULL), 
    46 	iConnectTimer(NULL), iWakeupTimer(NULL),
    52 	iConnectTimer(NULL), iWakeupTimer(NULL),
    47 	iAuxBuffer(NULL)
    53 	iAuxBuffer(NULL)
    48 	{
    54 	{
    49 	LOG_FUNC	
    55 	OstTraceFunctionEntryExt( RUSBTESTDEVICE_RUSBTESTDEVICE_ENTRY_DUP01, this );
    50 	iTestCase = aTestCase;
    56 	iTestCase = aTestCase;
    51 	RDebug::Printf("iTestCase = %d", iTestCase);
    57 	OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_RUSBTESTDEVICE, "iTestCase = %d", iTestCase);
       
    58 	OstTraceFunctionExit1( RUSBTESTDEVICE_RUSBTESTDEVICE_EXIT_DUP01, this );
    52 	}
    59 	}
    53 		
    60 		
    54 void RUsbTestDevice::ResetState()
    61 void RUsbTestDevice::ResetState()
    55 	{
    62 	{
       
    63 	OstTraceFunctionEntry1( RUSBTESTDEVICE_RESETSTATE_ENTRY, this );
    56 	iCurrentState = EUsbcDeviceStateUndefined;
    64 	iCurrentState = EUsbcDeviceStateUndefined;
       
    65 	OstTraceFunctionExit1( RUSBTESTDEVICE_RESETSTATE_EXIT, this );
    57 	}
    66 	}
    58 
    67 
    59 RUsbTestDevice::~RUsbTestDevice()
    68 RUsbTestDevice::~RUsbTestDevice()
    60 	{
    69 	{
    61 	LOG_FUNC
    70 	OstTraceFunctionEntry1( RUSBTESTDEVICE_RUSBTESTDEVICE_ENTRY_DUP02, this );
    62 	
    71 	
       
    72 	OstTraceFunctionExit1( RUSBTESTDEVICE_RUSBTESTDEVICE_EXIT_DUP02, this );
    63 	}
    73 	}
    64 	
    74 	
    65 void RUsbTestDevice::Close()
    75 void RUsbTestDevice::Close()
    66 	{
    76 	{
    67 	LOG_FUNC
    77 OstTraceFunctionEntry1( RUSBTESTDEVICE_CLOSE_ENTRY, this );
    68 
    78 
    69 	delete iWakeupTimer;
    79 	delete iWakeupTimer;
    70 	delete iConnectTimer;
    80 	delete iConnectTimer;
    71 	delete iDeviceEp0;
    81 	delete iDeviceEp0;
    72 	delete iStateWatcher;
    82 	delete iStateWatcher;
    83         static const TInt KWordOfDeathKey = 0x01066601;
    93         static const TInt KWordOfDeathKey = 0x01066601;
    84         static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
    94         static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
    85         TInt r = RProperty::Define(KWordOfDeathCat, KWordOfDeathKey, RProperty::EInt,KAllowAllPolicy, KAllowAllPolicy, 0);
    95         TInt r = RProperty::Define(KWordOfDeathCat, KWordOfDeathKey, RProperty::EInt,KAllowAllPolicy, KAllowAllPolicy, 0);
    86         if(r != KErrNone)
    96         if(r != KErrNone)
    87             {
    97             {
    88             RDebug::Print(_L("Could not create the WordOfDeath P&S   (%d)"), r);
    98             OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_CLOSE, "Could not create the WordOfDeath P&S   (%d)", r);
    89             }
    99             }
    90 		RDebug::Printf("killing t_usbhost_usbman.exe");
   100 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_CLOSE_DUP01, "killing t_usbhost_usbman.exe");
    91         RProperty::Set(KWordOfDeathCat, KWordOfDeathKey, KErrAbort);   // Send the word of death
   101         RProperty::Set(KWordOfDeathCat, KWordOfDeathKey, KErrAbort);   // Send the word of death
    92         User::After(1000000); //allow time for t_usbhost_usbman.exe to clean up
   102         User::After(1000000); //allow time for t_usbhost_usbman.exe to clean up
    93 		}
   103 		}
       
   104 	OstTraceFunctionExit1( RUSBTESTDEVICE_CLOSE_EXIT, this );
    94 	}
   105 	}
    95 
   106 
    96 
   107 
    97 void RUsbTestDevice::SubscribeToReports(TRequestStatus& aObserverStatus)
   108 void RUsbTestDevice::SubscribeToReports(TRequestStatus& aObserverStatus)
    98 	{
   109 	{
    99 	LOG_FUNC
   110 	OstTraceFunctionEntryExt( RUSBTESTDEVICE_SUBSCRIBETOREPORTS_ENTRY, this );
   100 	
   111 	
   101 	// Signal the request as pending
   112 	// Signal the request as pending
   102 	
   113 	
   103 	iObserverStatus = &aObserverStatus;
   114 	iObserverStatus = &aObserverStatus;
   104 	*iObserverStatus = KRequestPending;
   115 	*iObserverStatus = KRequestPending;
       
   116 	OstTraceFunctionExit1( RUSBTESTDEVICE_SUBSCRIBETOREPORTS_EXIT, this );
   105 	}
   117 	}
   106 
   118 
   107 
   119 
   108 void RUsbTestDevice::CancelSubscriptionToReports()
   120 void RUsbTestDevice::CancelSubscriptionToReports()
   109 	{
   121 	{
   110 	LOG_FUNC
   122 	OstTraceFunctionEntry1( RUSBTESTDEVICE_CANCELSUBSCRIPTIONTOREPORTS_ENTRY, this );
   111 	
   123 	
   112 	// Signal the request as cancelled
   124 	// Signal the request as cancelled
   113 	User::RequestComplete(iObserverStatus,KErrCancel);
   125 	User::RequestComplete(iObserverStatus,KErrCancel);
       
   126 	OstTraceFunctionExit1( RUSBTESTDEVICE_CANCELSUBSCRIPTIONTOREPORTS_EXIT, this );
   114 	}
   127 	}
   115 	
   128 	
   116 		
   129 		
   117 void RUsbTestDevice::OpenL()
   130 void RUsbTestDevice::OpenL()
   118 	{
   131 	{
   119 	LOG_FUNC	
   132 	OstTraceFunctionEntry1( RUSBTESTDEVICE_OPENL_ENTRY, this );
   120 	TInt err = KErrNone;
   133 	TInt err = KErrNone;
   121 	
   134 	
   122 	RDebug::Printf("starting t_usbhost_usbman.exe");
   135 	OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_OPENL, "starting t_usbhost_usbman.exe");
   123 	TInt r = iOtgUsbMan.Create(_L("t_usbhost_usbman.exe"), _L("client"));
   136 	TInt r = iOtgUsbMan.Create(_L("t_usbhost_usbman.exe"), _L("client"));
   124 	gtest(r == KErrNone);
   137 	gtest(r == KErrNone);
   125 	iOtgUsbMan.Resume();	
   138 	iOtgUsbMan.Resume();	
   126 	
   139 	
   127 	User::After(1500000);
   140 	User::After(1500000);
   128 	
   141 	
   129 	// Open channel to driver
   142 	// Open channel to driver
   130 	err = iClientDriver.Open(0);
   143 	err = iClientDriver.Open(0);
   131 	if(err != KErrNone)
   144 	if(err != KErrNone)
   132 		{
   145 		{
   133 		RDebug::Printf("<Error %d> Unable to open a channel to USB client driver",err);
   146 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP01, "<Error %d> Unable to open a channel to USB client driver",err);
   134 		User::Leave(err);
   147 		User::Leave(err);
   135 		}
   148 		}
   136 	
   149 	
   137 	// Hide bus from host while interfaces are being set up
   150 	// Hide bus from host while interfaces are being set up
   138 	err = iClientDriver.DeviceDisconnectFromHost();
   151 	err = iClientDriver.DeviceDisconnectFromHost();
   139 	if(err != KErrNone)
   152 	if(err != KErrNone)
   140 		{
   153 		{
   141 		RDebug::Printf("<Error %d> unable to disconnect device from host",err);
   154 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP02, "<Error %d> unable to disconnect device from host",err);
   142 		User::Leave(err);
   155 		User::Leave(err);
   143 		}
   156 		}
   144 	
   157 	
   145 	// Create the client usb state watcher
   158 	// Create the client usb state watcher
   146 	iStateWatcher = CUsbClientStateWatcher::NewL(iClientDriver,*this);
   159 	iStateWatcher = CUsbClientStateWatcher::NewL(iClientDriver,*this);
   154 	// Create the timer for remote wakeup events
   167 	// Create the timer for remote wakeup events
   155 	iWakeupTimer = CRemoteWakeupTimer::NewL(*this);
   168 	iWakeupTimer = CRemoteWakeupTimer::NewL(*this);
   156 	_LIT8(KYes, "yes");
   169 	_LIT8(KYes, "yes");
   157 	_LIT8(KNo, "no");
   170 	_LIT8(KNo, "no");
   158 	User::LeaveIfError(iClientDriver.DeviceCaps(iDeviceCaps));
   171 	User::LeaveIfError(iClientDriver.DeviceCaps(iDeviceCaps));
   159  	RDebug::Printf("------ USB device capabilities -------");
   172  	OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP03, "------ USB device capabilities -------");
   160 	RDebug::Printf("Number of endpoints:                %d",iDeviceCaps().iTotalEndpoints);	
   173 	OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP04, "Number of endpoints:                %d",iDeviceCaps().iTotalEndpoints);	
   161 	RDebug::Printf("Supports Software-Connect:          %S",iDeviceCaps().iConnect ? &KYes() : &KNo());
   174 	OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP05, "Supports Software-Connect:          %s",iDeviceCaps().iConnect ? KYes() : KNo());
   162 	RDebug::Printf("Device is Self-Powered:             %S",iDeviceCaps().iSelfPowered ? &KYes() : &KNo());
   175 	OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP06, "Device is Self-Powered:             %S",iDeviceCaps().iSelfPowered ? KYes() : KNo());
   163 	RDebug::Printf("Supports Remote-Wakeup:             %S",iDeviceCaps().iRemoteWakeup ? &KYes() : &KNo());
   176 	OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP07, "Supports Remote-Wakeup:             %S",iDeviceCaps().iRemoteWakeup ? KYes() : KNo());
   164 	RDebug::Printf("Supports High-speed:                %S",iDeviceCaps().iHighSpeed ? &KYes() : &KNo());
   177 	OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP08, "Supports High-speed:                %S",iDeviceCaps().iHighSpeed ? KYes() : KNo());
   165 	RDebug::Printf("Supports unpowered cable detection: %S",(iDeviceCaps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ? &KYes() : &KNo());
   178 	OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP09, "Supports unpowered cable detection: %S",(iDeviceCaps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ? KYes() : KNo());
   166 	RDebug::Printf("--------------------------------------");
   179 	OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP10, "--------------------------------------");
   167 	
   180 	
       
   181 	OstTraceFunctionExit1( RUSBTESTDEVICE_OPENL_EXIT, this );
   168 	}
   182 	}
   169 
   183 
   170 
   184 
   171 TInt RUsbTestDevice::SetClassCode(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol)
   185 TInt RUsbTestDevice::SetClassCode(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol)
   172 	{
   186 	{
   173 	LOG_FUNC
   187     OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETCLASSCODE_ENTRY, this );
   174 
   188 
   175 	// Get Device descriptor
   189 	// Get Device descriptor
   176 	TBuf8<KUsbDescSize_Device> deviceDescriptor;
   190 	TBuf8<KUsbDescSize_Device> deviceDescriptor;
   177 	TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
   191 	TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
   178 	if(err != KErrNone)
   192 	if(err != KErrNone)
   179 		{
   193 		{
   180 		RDebug::Printf("<Error %d> Unable to obtain device descriptor",err);
   194 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETCLASSCODE, "<Error %d> Unable to obtain device descriptor",err);
   181 		}
   195 		}
   182 	else
   196 	else
   183 		{
   197 		{
   184 		deviceDescriptor[KDevDescOffset_bDeviceClass] = aClassCode;
   198 		deviceDescriptor[KDevDescOffset_bDeviceClass] = aClassCode;
   185 		deviceDescriptor[KDevDescOffset_bDeviceSubClass] = aSubClassCode;
   199 		deviceDescriptor[KDevDescOffset_bDeviceSubClass] = aSubClassCode;
   186 		deviceDescriptor[KDevDescOffset_bDeviceProtocol] = aDeviceProtocol;	
   200 		deviceDescriptor[KDevDescOffset_bDeviceProtocol] = aDeviceProtocol;	
   187 		
   201 		
   188 		err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
   202 		err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
   189 		if(err != KErrNone)
   203 		if(err != KErrNone)
   190 			{
   204 			{
   191 			RDebug::Printf("<Error %d> Unable to set the device dsecriptor",err);
   205 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETCLASSCODE_DUP01, "<Error %d> Unable to set the device dsecriptor",err);
   192 			}
   206 			}
   193 		}
   207 		}
       
   208 	OstTraceFunctionExitExt( RUSBTESTDEVICE_SETCLASSCODE_EXIT, this, err );
   194 	return err;
   209 	return err;
   195 	}
   210 	}
   196 
   211 
   197 
   212 
   198 TInt RUsbTestDevice::SetUsbSpecification(TUint16 aSpecification)
   213 TInt RUsbTestDevice::SetUsbSpecification(TUint16 aSpecification)
   199 	{
   214 	{
   200 	LOG_FUNC
   215     OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETUSBSPECIFICATION_ENTRY, this );
   201 
   216 
   202 	// Get Device descriptor
   217 	// Get Device descriptor
   203 	TBuf8<KUsbDescSize_Device> deviceDescriptor;
   218 	TBuf8<KUsbDescSize_Device> deviceDescriptor;
   204 	TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
   219 	TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
   205 	if(err != KErrNone)
   220 	if(err != KErrNone)
   206 		{
   221 		{
   207 		RDebug::Printf("<Error %d> Unable to obtain device descriptor",err);
   222 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETUSBSPECIFICATION, "<Error %d> Unable to obtain device descriptor",err);
   208 		}
   223 		}
   209 	else
   224 	else
   210 		{
   225 		{
   211 		// Set bcdUSB
   226 		// Set bcdUSB
   212 		TUint8* p = reinterpret_cast<TUint8*>(&aSpecification);
   227 		TUint8* p = reinterpret_cast<TUint8*>(&aSpecification);
   219 		deviceDescriptor[KDevDescOffset_bNumConfigurations] = 0x01;
   234 		deviceDescriptor[KDevDescOffset_bNumConfigurations] = 0x01;
   220 		
   235 		
   221 		err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
   236 		err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
   222 		if(err != KErrNone)
   237 		if(err != KErrNone)
   223 			{
   238 			{
   224 			RDebug::Printf("<Error %d> Unable to set the device dsecriptor",err);
   239 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETUSBSPECIFICATION_DUP01, "<Error %d> Unable to set the device dsecriptor",err);
   225 			}
   240 			}
   226 		}
   241 		}
       
   242 	OstTraceFunctionExitExt( RUSBTESTDEVICE_SETUSBSPECIFICATION_EXIT, this, err );
   227 	return err;
   243 	return err;
   228 	}
   244 	}
   229 
   245 
   230 
   246 
   231 TInt RUsbTestDevice::SetVendor(TUint16 aVendorId)
   247 TInt RUsbTestDevice::SetVendor(TUint16 aVendorId)
   232 	{
   248 	{
   233 	LOG_FUNC
   249     OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETVENDOR_ENTRY, this );
   234 
   250 
   235 	// Get Device descriptor
   251 	// Get Device descriptor
   236 	TBuf8<KUsbDescSize_Device> deviceDescriptor;
   252 	TBuf8<KUsbDescSize_Device> deviceDescriptor;
   237 	TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
   253 	TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
   238 	if(err != KErrNone)
   254 	if(err != KErrNone)
   239 		{
   255 		{
   240 		RDebug::Printf("<Error %d> Unable to obtain device descriptor",err);
   256 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETVENDOR, "<Error %d> Unable to obtain device descriptor",err);
   241 		}
   257 		}
   242 	else
   258 	else
   243 		{
   259 		{
   244 		// Set VID
   260 		// Set VID
   245 		TUint8* p = reinterpret_cast<TUint8*>(&aVendorId);
   261 		TUint8* p = reinterpret_cast<TUint8*>(&aVendorId);
   247 		deviceDescriptor[KDevDescOffset_idVendor+1] = *(p+1);
   263 		deviceDescriptor[KDevDescOffset_idVendor+1] = *(p+1);
   248 		
   264 		
   249 		err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
   265 		err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
   250 		if(err != KErrNone)
   266 		if(err != KErrNone)
   251 			{
   267 			{
   252 			RDebug::Printf("<Error %d> Unable to set the device descriptor",err);
   268 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETVENDOR_DUP01, "<Error %d> Unable to set the device descriptor",err);
   253 			}
   269 			}
   254 		}
   270 		}
       
   271 	OstTraceFunctionExitExt( RUSBTESTDEVICE_SETVENDOR_EXIT, this, err );
   255 	return err;
   272 	return err;
   256 	}
   273 	}
   257 
   274 
   258 
   275 
   259 TInt RUsbTestDevice::SetProduct(TUint16 aProductId,const TDesC16& aProductString,
   276 TInt RUsbTestDevice::SetProduct(TUint16 aProductId,const TDesC16& aProductString,
   260 				const TDesC16& aManufacturerString,const TDesC16& aSerialNumberString)
   277 				const TDesC16& aManufacturerString,const TDesC16& aSerialNumberString)
   261 	{
   278 	{
   262 	LOG_FUNC
   279     OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETPRODUCT_ENTRY, this );
   263 
   280 
   264 	// Get Device descriptor
   281 	// Get Device descriptor
   265 	TBuf8<KUsbDescSize_Device> deviceDescriptor;
   282 	TBuf8<KUsbDescSize_Device> deviceDescriptor;
   266 	TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
   283 	TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
   267 	if(err != KErrNone)
   284 	if(err != KErrNone)
   268 		{
   285 		{
   269 		RDebug::Printf("<Error %d> Unable to obtain device descriptor",err);
   286 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT, "<Error %d> Unable to obtain device descriptor",err);
   270 		}
   287 		}
   271 	else
   288 	else
   272 		{
   289 		{
   273 		// Set PID
   290 		// Set PID
   274 		TUint8* p = reinterpret_cast<TUint8*>(&aProductId);
   291 		TUint8* p = reinterpret_cast<TUint8*>(&aProductId);
   276 		deviceDescriptor[KDevDescOffset_idProduct+1] = *(p+1);
   293 		deviceDescriptor[KDevDescOffset_idProduct+1] = *(p+1);
   277 		
   294 		
   278 		err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
   295 		err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
   279 		if(err != KErrNone)
   296 		if(err != KErrNone)
   280 			{
   297 			{
   281 			RDebug::Printf("<Error %d> Unable to set the device dsecriptor",err);
   298 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP01, "<Error %d> Unable to set the device dsecriptor",err);
       
   299 			OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT, this, err );
   282 			return err;
   300 			return err;
   283 			}
   301 			}
   284 		
   302 		
   285 		RDebug::Printf("Product Identity set");
   303 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP02, "Product Identity set");
   286 	
   304 	
   287 		// Product string
   305 		// Product string
   288 		err = iClientDriver.SetProductStringDescriptor(aProductString);
   306 		err = iClientDriver.SetProductStringDescriptor(aProductString);
   289 		if(err != KErrNone)
   307 		if(err != KErrNone)
   290 			{
   308 			{
   291 			RDebug::Printf("<Error %d> Unable to set product string descriptor",err);
   309 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP03, "<Error %d> Unable to set product string descriptor",err);
       
   310 			OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT_DUP01, this, err );
   292 			return err;
   311 			return err;
   293 			}
   312 			}
   294 
   313 
   295 		// Manufacturer string
   314 		// Manufacturer string
   296 		err = iClientDriver.SetManufacturerStringDescriptor(aManufacturerString);
   315 		err = iClientDriver.SetManufacturerStringDescriptor(aManufacturerString);
   297 		if(err != KErrNone)
   316 		if(err != KErrNone)
   298 			{
   317 			{
   299 			RDebug::Printf("<Error %d> Unable to set the manufacturer string descriptor",err);
   318 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP04, "<Error %d> Unable to set the manufacturer string descriptor",err);
       
   319 			OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT_DUP02, this, err );
   300 			return err;
   320 			return err;
   301 			}
   321 			}
   302 	
   322 	
   303 		// Serial number string
   323 		// Serial number string
   304 		err = iClientDriver.SetSerialNumberStringDescriptor(aSerialNumberString);
   324 		err = iClientDriver.SetSerialNumberStringDescriptor(aSerialNumberString);
   305 		if(err != KErrNone)
   325 		if(err != KErrNone)
   306 			{
   326 			{
   307 			RDebug::Printf("<Error %d> Unable to set the serial number string descriptor",err);
   327 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP05, "<Error %d> Unable to set the serial number string descriptor",err);
       
   328 			OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT_DUP03, this, err );
   308 			return err;
   329 			return err;
   309 			}
   330 			}
   310 		}
   331 		}
       
   332 	OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT_DUP04, this, KErrNone );
   311 	return KErrNone;
   333 	return KErrNone;
   312 	}
   334 	}
   313 
   335 
   314 
   336 
   315 TInt RUsbTestDevice::SetConfigurationString(const TDesC16& aConfigString)
   337 TInt RUsbTestDevice::SetConfigurationString(const TDesC16& aConfigString)
   316 	{
   338 	{
   317 	LOG_FUNC
   339     OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETCONFIGURATIONSTRING_ENTRY, this );
   318 
   340 
   319 	TInt err(iClientDriver.SetConfigurationStringDescriptor(aConfigString));
   341 	TInt err(iClientDriver.SetConfigurationStringDescriptor(aConfigString));
   320 	if(err != KErrNone)
   342 	if(err != KErrNone)
   321 		{
   343 		{
   322 		RDebug::Printf("<Error %d> Unable to set configuration string descriptor",err);
   344 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETCONFIGURATIONSTRING, "<Error %d> Unable to set configuration string descriptor",err);
   323 		}
   345 		}
       
   346 	OstTraceFunctionExitExt( RUSBTESTDEVICE_SETCONFIGURATIONSTRING_EXIT, this, err );
   324 	return err;
   347 	return err;
   325 	}
   348 	}
   326 
   349 
   327 
   350 
   328 void RUsbTestDevice::AddInterface(CInterfaceBase* aInterface)
   351 void RUsbTestDevice::AddInterface(CInterfaceBase* aInterface)
   329 	{
   352 	{
   330 	LOG_FUNC
   353 	OstTraceFunctionEntryExt( RUSBTESTDEVICE_ADDINTERFACE_ENTRY, this );
   331 		
   354 		
   332 	// Add the interface to the device
   355 	// Add the interface to the device
   333 	TInt err = iInterfaces.Append(aInterface);
   356 	TInt err = iInterfaces.Append(aInterface);
   334 	
   357 	
   335 	if(err != KErrNone)
   358 	if(err != KErrNone)
   336 		{
   359 		{
   337 		RDebug::Printf("<Error %d> Unable to add interface",err);
   360 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_ADDINTERFACE, "<Error %d> Unable to add interface",err);
   338 		return ReportError(err);
   361 		return ReportError(err);
   339 		}
   362 		}
       
   363 	OstTraceFunctionExit1( RUSBTESTDEVICE_ADDINTERFACE_EXIT, this );
   340 	}
   364 	}
   341 
   365 
   342 
   366 
   343 CInterfaceBase& RUsbTestDevice::Interface(TInt aIndex)
   367 CInterfaceBase& RUsbTestDevice::Interface(TInt aIndex)
   344 	{
   368 	{
       
   369 	OstTraceFunctionEntryExt( RUSBTESTDEVICE_INTERFACE_ENTRY, this );
       
   370 	OstTraceFunctionExit1( RUSBTESTDEVICE_INTERFACE_EXIT, this );
   345 	return *iInterfaces[aIndex];
   371 	return *iInterfaces[aIndex];
   346 	}
   372 	}
   347 
   373 
   348 
   374 
   349 void RUsbTestDevice::SoftwareConnect()
   375 void RUsbTestDevice::SoftwareConnect()
   350 	{
   376 	{
   351 	LOG_FUNC
   377 	OstTraceFunctionEntry1( RUSBTESTDEVICE_SOFTWARECONNECT_ENTRY, this );
   352 	TInt err(iClientDriver.PowerUpUdc());
   378 	TInt err(iClientDriver.PowerUpUdc());
   353 	if((err != KErrNone) && (err != KErrNotReady))
   379 	if((err != KErrNone) && (err != KErrNotReady))
   354 		{
   380 		{
   355 		RDebug::Printf("<Error %d> Power Up Udc",err);
   381 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWARECONNECT, "<Error %d> Power Up Udc",err);
   356 		ReportError(err);
   382 		ReportError(err);
   357 		}
   383 		}
   358 		
   384 		
   359 	if(iDeviceCaps().iConnect) 
   385 	if(iDeviceCaps().iConnect) 
   360 		{
   386 		{
   361 		err = iClientDriver.DeviceConnectToHost();
   387 		err = iClientDriver.DeviceConnectToHost();
   362 		if(err != KErrNone)
   388 		if(err != KErrNone)
   363 			{
   389 			{
   364 			RDebug::Printf("<Error %d> Unable to connect to the host",err);
   390 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWARECONNECT_DUP01, "<Error %d> Unable to connect to the host",err);
   365 			ReportError(err);
   391 			ReportError(err);
   366 			}
   392 			}
   367 		}
   393 		}
   368 	else
   394 	else
   369 		{
   395 		{
   370 		RDebug::Printf("Please connect device to Host");
   396 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWARECONNECT_DUP02, "Please connect device to Host");
   371 		}	
   397 		}	
       
   398 	OstTraceFunctionExit1( RUSBTESTDEVICE_SOFTWARECONNECT_EXIT, this );
   372 	}   	
   399 	}   	
   373 	 
   400 	 
   374 void RUsbTestDevice::SoftwareDisconnect()
   401 void RUsbTestDevice::SoftwareDisconnect()
   375 	{
   402 	{
   376 	LOG_FUNC
   403 	OstTraceFunctionEntry1( RUSBTESTDEVICE_SOFTWAREDISCONNECT_ENTRY, this );
   377 	
   404 	
   378 	if(iDeviceCaps().iConnect) 
   405 	if(iDeviceCaps().iConnect) 
   379 		{
   406 		{
   380 		TInt err(iClientDriver.DeviceDisconnectFromHost());
   407 		TInt err(iClientDriver.DeviceDisconnectFromHost());
   381 		if(err != KErrNone)
   408 		if(err != KErrNone)
   382 			{
   409 			{
   383 			RDebug::Printf("<Error %d> Unable to disconnect from the host",err);
   410 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWAREDISCONNECT, "<Error %d> Unable to disconnect from the host",err);
   384 			ReportError(err);
   411 			ReportError(err);
   385 			}
   412 			}
   386 		}
   413 		}
   387 	else
   414 	else
   388 		{
   415 		{
   389 		RDebug::Printf("Please disconnect device from Host");
   416 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWAREDISCONNECT_DUP01, "Please disconnect device from Host");
   390 		}
   417 		}
   391 		
   418 		
       
   419 	OstTraceFunctionExit1( RUSBTESTDEVICE_SOFTWAREDISCONNECT_EXIT, this );
   392 	}       
   420 	}       
   393 
   421 
   394 
   422 
   395 void RUsbTestDevice::RemoteWakeup()
   423 void RUsbTestDevice::RemoteWakeup()
   396 	{
   424 	{
   397 	LOG_FUNC
   425 	OstTraceFunctionEntry1( RUSBTESTDEVICE_REMOTEWAKEUP_ENTRY, this );
   398 	if(iDeviceCaps().iConnect) 
   426 	if(iDeviceCaps().iConnect) 
   399 		{
   427 		{
   400 		TInt err(iClientDriver.SignalRemoteWakeup());
   428 		TInt err(iClientDriver.SignalRemoteWakeup());
   401 		if(err != KErrNone)
   429 		if(err != KErrNone)
   402 			{
   430 			{
   403 			RDebug::Printf("<Error %d> Unable to perform a remote wakeup",err);
   431 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_REMOTEWAKEUP, "<Error %d> Unable to perform a remote wakeup",err);
   404 			ReportError(err);
   432 			ReportError(err);
   405 			}
   433 			}
   406 		}
   434 		}
   407 	else
   435 	else
   408 		{
   436 		{
   409 		RDebug::Printf("remote wakeup not supported");
   437 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_REMOTEWAKEUP_DUP01, "remote wakeup not supported");
   410 		}
   438 		}
       
   439 	OstTraceFunctionExit1( RUSBTESTDEVICE_REMOTEWAKEUP_EXIT, this );
   411 	}
   440 	}
   412 
   441 
   413 
   442 
   414 TInt RUsbTestDevice::ProcessRequestL(TUint8 aRequest,TUint16 aValue,TUint16 aIndex,
   443 TInt RUsbTestDevice::ProcessRequestL(TUint8 aRequest,TUint16 aValue,TUint16 aIndex,
   415 	TUint16 aDataReqLength,const TDesC8& aPayload)
   444 	TUint16 aDataReqLength,const TDesC8& aPayload)
   416 	{
   445 	{
   417 	LOG_FUNC
   446 	OstTraceFunctionEntryExt( RUSBTESTDEVICE_PROCESSREQUESTL_ENTRY, this );
   418 	
   447 	
   419 	if(aRequest == KVendorEmptyRequest)
   448 	if(aRequest == KVendorEmptyRequest)
   420 		{
   449 		{
   421 		// Handle an empty request (i.e. do nothing)
   450 		// Handle an empty request (i.e. do nothing)
   422 		
   451 		
   429 		AcknowledgeRequestReceived();
   458 		AcknowledgeRequestReceived();
   430 		iConnectTimer->SoftwareReConnect(aValue);
   459 		iConnectTimer->SoftwareReConnect(aValue);
   431 		}
   460 		}
   432 	else if(aRequest == KVendorDisconnectDeviceAThenConnectDeviceCRequest)
   461 	else if(aRequest == KVendorDisconnectDeviceAThenConnectDeviceCRequest)
   433 		{
   462 		{
   434 		RDebug::Printf("**aRequest == KVendorDisconnectDeviceAThenConnectDeviceCRequest, this = 0x%08x", this);
   463 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL, "**aRequest == KVendorDisconnectDeviceAThenConnectDeviceCRequest, this = 0x%08x", this);
   435 		// Handle a reconnect requests from the host		
   464 		// Handle a reconnect requests from the host		
   436 		AcknowledgeRequestReceived();			
   465 		AcknowledgeRequestReceived();			
   437 		
   466 		
   438 		SoftwareDisconnect();	
   467 		SoftwareDisconnect();	
   439 		User::After(1000000);
   468 		User::After(1000000);
   443 		
   472 		
   444 		User::After(3000000);
   473 		User::After(3000000);
   445 		iTestCaseT_USBDI_0486->TestDeviceC()->OpenL(KTestDeviceC_SN);		
   474 		iTestCaseT_USBDI_0486->TestDeviceC()->OpenL(KTestDeviceC_SN);		
   446 		// Connect the device to the host	
   475 		// Connect the device to the host	
   447 		iTestCaseT_USBDI_0486->TestDeviceC()->SoftwareConnect();
   476 		iTestCaseT_USBDI_0486->TestDeviceC()->SoftwareConnect();
       
   477 		OstTraceFunctionExitExt( RUSBTESTDEVICE_PROCESSREQUESTL_EXIT, this, KErrAbort );
   448 		return KErrAbort;
   478 		return KErrAbort;
   449 		}
   479 		}
   450 	else if(aRequest == KVendorDisconnectDeviceCThenConnectDeviceARequest)
   480 	else if(aRequest == KVendorDisconnectDeviceCThenConnectDeviceARequest)
   451 		{
   481 		{
   452 		RDebug::Printf("**aRequest == KVendorDisconnectDeviceCThenConnectDeviceARequest, this = 0x%08x", this);
   482 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP01, "**aRequest == KVendorDisconnectDeviceCThenConnectDeviceARequest, this = 0x%08x", this);
   453 		// Handle a reconnect requests from the host		
   483 		// Handle a reconnect requests from the host		
   454 		AcknowledgeRequestReceived();		
   484 		AcknowledgeRequestReceived();		
   455 		 
   485 		 
   456 		SoftwareDisconnect();	
   486 		SoftwareDisconnect();	
   457 		User::After(1000000); 
   487 		User::After(1000000); 
   466 		iTestCaseT_USBDI_0486->HandleDeviceDConnection();
   496 		iTestCaseT_USBDI_0486->HandleDeviceDConnection();
   467 		iTestCaseT_USBDI_0486->TestDeviceD()->OpenL(iTestCaseT_USBDI_0486->TestCaseId());	
   497 		iTestCaseT_USBDI_0486->TestDeviceD()->OpenL(iTestCaseT_USBDI_0486->TestCaseId());	
   468 		
   498 		
   469 		// Connect the device to the host	
   499 		// Connect the device to the host	
   470 		iTestCaseT_USBDI_0486->TestDeviceD()->SoftwareConnect();	
   500 		iTestCaseT_USBDI_0486->TestDeviceD()->SoftwareConnect();	
       
   501 		OstTraceFunctionExitExt( RUSBTESTDEVICE_PROCESSREQUESTL_EXIT_DUP01, this, KErrAbort );
   471 		return KErrAbort;
   502 		return KErrAbort;
   472 		}		
   503 		}		
   473 	else if(aRequest == KVendorTestCasePassed)
   504 	else if(aRequest == KVendorTestCasePassed)
   474 		{ 
   505 		{ 
   475 		// Test case has completed successfully 
   506 		// Test case has completed successfully 
   485 		
   516 		
   486 		AcknowledgeRequestReceived();
   517 		AcknowledgeRequestReceived();
   487 		
   518 		
   488 		HBufC16* msg = HBufC16::NewL(aPayload.Length());
   519 		HBufC16* msg = HBufC16::NewL(aPayload.Length());
   489 		msg->Des().Copy(aPayload);
   520 		msg->Des().Copy(aPayload);
   490 		RDebug::Printf("<Host> Test case failed: %S",msg);
   521 		OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP02, "<Host> Test case failed: %S",*msg);
   491 		delete msg;
   522 		delete msg;
   492 		msg = 0;
   523 		msg = 0;
   493 		ReportError(-aValue);
   524 		ReportError(-aValue);
   494 		}
   525 		}
   495 	else if(aRequest == KVendorRemoteWakeupRequest)
   526 	else if(aRequest == KVendorRemoteWakeupRequest)
   502 	else if(aRequest == KVendorPutPayloadRequest)
   533 	else if(aRequest == KVendorPutPayloadRequest)
   503 		{
   534 		{
   504 		// Handle a payload request from the host
   535 		// Handle a payload request from the host
   505 
   536 
   506 		AcknowledgeRequestReceived();
   537 		AcknowledgeRequestReceived();
   507 		RDebug::Printf("Put payload");
   538 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP03, "Put payload");
   508 		if(aPayload.Compare(_L8("DEADBEEF")) != 0)
   539 		if(aPayload.Compare(_L8("DEADBEEF")) != 0)
   509 			{
   540 			{
   510 			RDebug::Printf("<Error %d> Payload not as expected",KErrCorrupt);
   541 			OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP04, "<Error %d> Payload not as expected",KErrCorrupt);
   511 			ReportError(KErrCorrupt);
   542 			ReportError(KErrCorrupt);
   512 			}
   543 			}
   513 		}
   544 		}
   514 	else if(aRequest == KVendorGetPayloadRequest)
   545 	else if(aRequest == KVendorGetPayloadRequest)
   515 		{
   546 		{
   516 		// Handle a payload request to the host
   547 		// Handle a payload request to the host
   517 
   548 
   518 		RDebug::Printf("Get payload");
   549 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP05, "Get payload");
   519 		__ASSERT_DEBUG(iAuxBuffer, User::Panic(_L("Trying to write non-allocated buffer"), KErrGeneral));
   550 		__ASSERT_DEBUG(iAuxBuffer, User::Panic(_L("Trying to write non-allocated buffer"), KErrGeneral));
   520 		RDebug::Printf("iAuxBuffer = ....");
   551 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP06, "iAuxBuffer = ....");
   521 		RDebug::RawPrint(*iAuxBuffer);
   552         OstTraceData(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP56, "", iAuxBuffer->Ptr(), iAuxBuffer->Length());
   522 		RDebug::Printf("\n");
   553 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP07, "\n");
   523 		
   554 		
   524 		//Perform synchronous write to EP0
   555 		//Perform synchronous write to EP0
   525 		//This allows the subsequent 'Read' request to
   556 		//This allows the subsequent 'Read' request to
   526 		//take place
   557 		//take place
   527 		TInt ret = iDeviceEp0->SendDataSynchronous(*iAuxBuffer);
   558 		TInt ret = iDeviceEp0->SendDataSynchronous(*iAuxBuffer);
   528 		RDebug::Printf("Write (from device callback) executed with error %d", ret);
   559 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP08, "Write (from device callback) executed with error %d", ret);
   529 		}
   560 		}
   530 	else if(aRequest == KVendorUnrespondRequest)
   561 	else if(aRequest == KVendorUnrespondRequest)
   531 		{
   562 		{
   532 		// Do not acknowledge this request
   563 		// Do not acknowledge this request
   533 		
   564 		
   534 		RDebug::Printf("Unrespond request: continually NAK the host");
   565 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP09, "Unrespond request: continually NAK the host");
   535 		}
   566 		}
   536 	else if(aRequest == KVendorStallRequest)
   567 	else if(aRequest == KVendorStallRequest)
   537 		{
   568 		{
   538 		// Stall the specified endpoint
   569 		// Stall the specified endpoint
   539 		
   570 		
   540 		AcknowledgeRequestReceived();
   571 		AcknowledgeRequestReceived();
   541 		RDebug::Printf("Stalling endpoint %d",aValue);
   572 		OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP10, "Stalling endpoint %d",aValue);
   542 						
   573 						
   543 		}
   574 		}
   544 	else
   575 	else
   545 		{
   576 		{
   546 		// Maybe forward to derived classes
   577 		// Maybe forward to derived classes
   547 		}
   578 		}
       
   579 	OstTraceFunctionExitExt( RUSBTESTDEVICE_PROCESSREQUESTL_EXIT_DUP02, this, KErrNone );
   548 	return KErrNone;
   580 	return KErrNone;
   549 	}
   581 	}
   550 
   582 
   551 
   583 
   552 void RUsbTestDevice::StateChangeL(TUsbcDeviceState aNewState,TInt aChangeCompletionCode)
   584 void RUsbTestDevice::StateChangeL(TUsbcDeviceState aNewState,TInt aChangeCompletionCode)
   553 	{
   585 	{
   554 	LOG_FUNC
   586 	OstTraceFunctionEntryExt( RUSBTESTDEVICE_STATECHANGEL_ENTRY, this );
   555 	
   587 	
   556 	RDebug::Printf("Client state change to %d err=%d",aNewState,aChangeCompletionCode);
   588 	OstTraceExt2(TRACE_NORMAL, RUSBTESTDEVICE_STATECHANGEL, "Client state change to %d err=%d",aNewState,aChangeCompletionCode);
   557 	
   589 	
   558 	// Notify the test case of failed state change notification
   590 	// Notify the test case of failed state change notification
   559 	
   591 	
   560 	if(aChangeCompletionCode != KErrNone)
   592 	if(aChangeCompletionCode != KErrNone)
   561 		{
   593 		{
   575 		else
   607 		else
   576 			{
   608 			{
   577 			// The is a state change from EUsbcDeviceStateConfigured to aNewState
   609 			// The is a state change from EUsbcDeviceStateConfigured to aNewState
   578 			// so stop reading from control ep0
   610 			// so stop reading from control ep0
   579 			
   611 			
   580 			RDebug::Printf("Ignoring control ep0");
   612 			OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_STATECHANGEL_DUP01, "Ignoring control ep0");
   581 			
   613 			
   582 			// Stop reading ep0 directed requests
   614 			// Stop reading ep0 directed requests
   583 			
   615 			
   584 			StopEp0Reading();
   616 			StopEp0Reading();
   585 			
   617 			
   595 		if(aNewState == EUsbcDeviceStateConfigured)
   627 		if(aNewState == EUsbcDeviceStateConfigured)
   596 			{
   628 			{
   597 			// Device has now been placed into a fully configured state by the host
   629 			// Device has now been placed into a fully configured state by the host
   598 			// so start reading from control ep0
   630 			// so start reading from control ep0
   599 			
   631 			
   600 			RDebug::Printf("Reading from control ep0");
   632 			OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_STATECHANGEL_DUP02, "Reading from control ep0");
   601 			
   633 			
   602 			// Start reading ep0 directed requests
   634 			// Start reading ep0 directed requests
   603 			
   635 			
   604 			StartEp0Reading();
   636 			StartEp0Reading();
   605 			
   637 			
   616 		}
   648 		}
   617 				
   649 				
   618 	// Forward the state change notification to derived classes
   650 	// Forward the state change notification to derived classes
   619 	
   651 	
   620 	OnStateChangeL(aNewState);
   652 	OnStateChangeL(aNewState);
       
   653 	OstTraceFunctionExit1( RUSBTESTDEVICE_STATECHANGEL_EXIT, this );
   621 	}
   654 	}
   622 	
   655 	
   623 
   656 
   624 void RUsbTestDevice::StartEp0Reading()
   657 void RUsbTestDevice::StartEp0Reading()
   625 	{
   658 	{
   626 	LOG_FUNC
   659     OstTraceFunctionEntry1( RUSBTESTDEVICE_STARTEP0READING_ENTRY, this );
   627 
   660 
   628 	// Start reading device directed ep0 requests
   661 	// Start reading device directed ep0 requests
   629 	
   662 	
   630 	TInt err(iDeviceEp0->Start());
   663 	TInt err(iDeviceEp0->Start());
   631 	if(err != KErrNone)
   664 	if(err != KErrNone)
   638 	TInt interfaceCount(iInterfaces.Count());
   671 	TInt interfaceCount(iInterfaces.Count());
   639 	for(TInt i=0; i<interfaceCount; i++)
   672 	for(TInt i=0; i<interfaceCount; i++)
   640 		{
   673 		{
   641 		iInterfaces[i]->StartEp0Reading();
   674 		iInterfaces[i]->StartEp0Reading();
   642 		}
   675 		}
       
   676 	OstTraceFunctionExit1( RUSBTESTDEVICE_STARTEP0READING_EXIT, this );
   643 	}
   677 	}
   644 
   678 
   645 
   679 
   646 void RUsbTestDevice::StopEp0Reading()
   680 void RUsbTestDevice::StopEp0Reading()
   647 	{
   681 	{
   648 	LOG_FUNC
   682     OstTraceFunctionEntry1( RUSBTESTDEVICE_STOPEP0READING_ENTRY, this );
   649 
   683 
   650 	// Stop reading interface directed requests
   684 	// Stop reading interface directed requests
   651 	
   685 	
   652 	TInt interfaceCount(iInterfaces.Count());
   686 	TInt interfaceCount(iInterfaces.Count());
   653 	for(TInt i=0; i<interfaceCount; i++)
   687 	for(TInt i=0; i<interfaceCount; i++)
   660 	TInt err(iDeviceEp0->Stop());
   694 	TInt err(iDeviceEp0->Stop());
   661 	if(err != KErrNone)
   695 	if(err != KErrNone)
   662 		{
   696 		{
   663 		return ReportError(err);
   697 		return ReportError(err);
   664 		}
   698 		}
       
   699 	OstTraceFunctionExit1( RUSBTESTDEVICE_STOPEP0READING_EXIT, this );
   665 	}
   700 	}
   666 
   701 
   667 
   702 
   668 void RUsbTestDevice::AcknowledgeRequestReceived()
   703 void RUsbTestDevice::AcknowledgeRequestReceived()
   669 	{
   704 	{
   670 	LOG_FUNC
   705 	OstTraceFunctionEntry1( RUSBTESTDEVICE_ACKNOWLEDGEREQUESTRECEIVED_ENTRY, this );
   671 	
   706 	
   672 	TInt err(iDeviceEp0->Reader().Acknowledge());
   707 	TInt err(iDeviceEp0->Reader().Acknowledge());
   673 	RDebug::Printf("err = %d",err);
   708 	OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_ACKNOWLEDGEREQUESTRECEIVED, "err = %d",err);
   674 	if(err != KErrNone)
   709 	if(err != KErrNone)
   675 		{
   710 		{
   676 		ReportError(err);
   711 		ReportError(err);
   677 		}
   712 		}
       
   713 	OstTraceFunctionExit1( RUSBTESTDEVICE_ACKNOWLEDGEREQUESTRECEIVED_EXIT, this );
   678 	}
   714 	}
   679 
   715 
   680 
   716 
   681 
   717 
   682 void RUsbTestDevice::ReportError(TInt aCompletionCode)
   718 void RUsbTestDevice::ReportError(TInt aCompletionCode)
   683 	{
   719 	{
   684 	LOG_FUNC
   720 	OstTraceFunctionEntryExt( RUSBTESTDEVICE_REPORTERROR_ENTRY, this );
   685 	RDebug::Printf("err or aCompletionCode = %d, observer status = %d, KRequestPending = %d",
   721 	OstTraceExt3(TRACE_NORMAL, RUSBTESTDEVICE_REPORTERROR, "err or aCompletionCode = %d, observer status = %d, KRequestPending = %d",
   686 			aCompletionCode, iObserverStatus->Int(), KRequestPending);
   722 			aCompletionCode, iObserverStatus->Int(), KRequestPending);
   687 	if(*iObserverStatus == KRequestPending)
   723 	if(*iObserverStatus == KRequestPending)
   688 		{
   724 		{
   689 		RDebug::Printf("In complete request");
   725 		OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_REPORTERROR_DUP01, "In complete request");
   690 		User::RequestComplete(iObserverStatus,aCompletionCode);
   726 		User::RequestComplete(iObserverStatus,aCompletionCode);
   691 		}
   727 		}
   692 	}
   728 	OstTraceFunctionExit1( RUSBTESTDEVICE_REPORTERROR_EXIT, this );
   693 	
   729 	}
   694 
   730 	
   695 	}
   731 
   696 	
   732 	}
       
   733