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