kerneltest/e32test/usbho/t_otgdi/src/otgroot.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".
    26 #include <e32def_private.h>
    26 #include <e32def_private.h>
    27 #include <d32otgdi.h>		// OTGDI header
    27 #include <d32otgdi.h>		// OTGDI header
    28 #include <d32usbc.h>		// USBCC header
    28 #include <d32usbc.h>		// USBCC header
    29 #include "otgroot.h"
    29 #include "otgroot.h"
    30 #include "testcaseroot.h"
    30 #include "testcaseroot.h"
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "otgrootTraces.h"
       
    34 #endif
       
    35 
    31 
    36 RUsbOtgDriver  oUsbOtgDriver;
    32 RUsbOtgDriver  oUsbOtgDriver;
    37 RDevUsbcClient oUsbcClient;
    33 RDevUsbcClient oUsbcClient;
    38 
    34 
    39 
    35 
    52 /** otgLoadLdd
    48 /** otgLoadLdd
    53 */
    49 */
    54 TInt COtgRoot::otgLoadLdd()
    50 TInt COtgRoot::otgLoadLdd()
    55 	{
    51 	{
    56 	
    52 	
    57 	if(gVerboseOutput)
    53 	LOG_FUNC
    58 	    {
       
    59 	    OstTraceFunctionEntry0(COTGROOT_OTGLOADLDD);
       
    60 	    }
       
    61 	LOG_VERBOSE2(_L("Load driver: %S\n"), &KOTGDeviceInterfaceDriverName);
    54 	LOG_VERBOSE2(_L("Load driver: %S\n"), &KOTGDeviceInterfaceDriverName);
    62 	if(gVerboseOutput)
       
    63 	    {
       
    64 	    OstTraceExt1(TRACE_VERBOSE, COTGROOT_OTGLOADLDD_DUP01, "Load driver: %S\n", KOTGDeviceInterfaceDriverName);
       
    65 	    }
       
    66 
    55 
    67 	if (!LddLoaded())
    56 	if (!LddLoaded())
    68 		{
    57 		{
    69 
    58 
    70 	 	// load ldd device drivers (load otg only, it will load the needed stuff for us)
    59 	 	// load ldd device drivers (load otg only, it will load the needed stuff for us)
    71 		TInt err(User::LoadLogicalDevice(KOTGDeviceInterfaceDriverName));
    60 		TInt err(User::LoadLogicalDevice(KOTGDeviceInterfaceDriverName));
    72 		if ( (err != KErrNone) && (err != KErrAlreadyExists) )
    61 		if ( (err != KErrNone) && (err != KErrAlreadyExists) )
    73 			{
    62 			{
    74 			test.Printf(_L("<Error %d> Unable to load driver: %S\n"), err, &KOTGDeviceInterfaceDriverName);
    63 			test.Printf(_L("<Error %d> Unable to load driver: %S\n"), err, &KOTGDeviceInterfaceDriverName);
    75 			OstTraceExt2(TRACE_NORMAL, COTGROOT_OTGLOADLDD_DUP02, "<Error %d> Unable to load driver: %S\n", err, KOTGDeviceInterfaceDriverName);
       
    76 			SetLoaded(EFalse);
    64 			SetLoaded(EFalse);
    77 			return(err);
    65 			return(err);
    78 			}
    66 			}
    79 		else
    67 		else
    80 			{
    68 			{
    81 			LOG_VERBOSE2(_L("Loaded driver: '%S' OK\n"), &KOTGDeviceInterfaceDriverName);
    69 			LOG_VERBOSE2(_L("Loaded driver: '%S' OK\n"), &KOTGDeviceInterfaceDriverName);
    82 			if(gVerboseOutput)
       
    83 			    {
       
    84 			    OstTraceExt1(TRACE_VERBOSE, COTGROOT_OTGLOADLDD_DUP03, "Loaded driver: '%S' OK\n", KOTGDeviceInterfaceDriverName);
       
    85 			    }
       
    86 			SetLoaded(ETrue);
    70 			SetLoaded(ETrue);
    87 			}
    71 			}
    88 		
    72 		
    89 		}
    73 		}
    90 		return(KErrNone);
    74 		return(KErrNone);
    93 
    77 
    94 /** otgOpen
    78 /** otgOpen
    95 */
    79 */
    96 TInt COtgRoot::otgOpen()
    80 TInt COtgRoot::otgOpen()
    97 	{
    81 	{
    98 	if(gVerboseOutput)
    82 	LOG_FUNC
    99 	    {
       
   100 	    OstTraceFunctionEntry0(COTGROOT_OTGOPEN);
       
   101 	    }
       
   102 	
    83 	
   103 	LOG_VERBOSE2(_L("Opening session... loaded = %d\n"), LddLoaded());
    84 	LOG_VERBOSE2(_L("Opening session... loaded = %d\n"), LddLoaded());
   104 	if(gVerboseOutput)
       
   105 	    {
       
   106 	    OstTrace1(TRACE_VERBOSE, COTGROOT_OTGOPEN_DUP01, "Opening session... loaded = %d\n", LddLoaded());
       
   107 	    }
       
   108 
    85 
   109 	TInt err(oUsbOtgDriver.Open());
    86 	TInt err(oUsbOtgDriver.Open());
   110 	if (err != KErrNone)
    87 	if (err != KErrNone)
   111 		{
    88 		{
   112 		test.Printf(_L("<Error %d> Unable to open a channel to USB OTG driver\n"),err);
    89 		test.Printf(_L("<Error %d> Unable to open a channel to USB OTG driver\n"),err);
   113 		OstTrace1(TRACE_NORMAL, COTGROOT_OTGOPEN_DUP02, "<Error %d> Unable to open a channel to USB OTG driver\n",err);
       
   114 		return(err);
    90 		return(err);
   115 		}
    91 		}
   116 	else
    92 	else
   117 		{
    93 		{
   118 		LOG_VERBOSE1(_L("Open channel OK\n"));
    94 		LOG_VERBOSE1(_L("Open channel OK\n"));
   119 		if(gVerboseOutput)
       
   120 		    {
       
   121 		    OstTrace0(TRACE_VERBOSE, COTGROOT_OTGOPEN_DUP03, "Open channel OK\n");
       
   122 		    }
       
   123 		}
    95 		}
   124 		
    96 		
   125 	return(KErrNone);	
    97 	return(KErrNone);	
   126 	}
    98 	}
   127 
    99 
   128 
   100 
   129 /** otgClose
   101 /** otgClose
   130 */
   102 */
   131 void COtgRoot::otgClose()
   103 void COtgRoot::otgClose()
   132 	{
   104 	{
   133 	if(gVerboseOutput)
   105 	LOG_FUNC
   134 	    {
       
   135 	    OstTraceFunctionEntry0(COTGROOT_OTGCLOSE);
       
   136 	    }
       
   137 	
   106 	
   138 	test.Printf(_L("Closing session... loaded = %d\n"), LddLoaded());
   107 	test.Printf(_L("Closing session... loaded = %d\n"), LddLoaded());
   139 	OstTrace1(TRACE_NORMAL, COTGROOT_OTGCLOSE_DUP01, "Closing session... loaded = %d\n", LddLoaded());
       
   140 	oUsbOtgDriver.Close();
   108 	oUsbOtgDriver.Close();
   141 	}
   109 	}
   142 
   110 
   143 
   111 
   144 /* otgActivateOptTestMode
   112 /* otgActivateOptTestMode
   145  */ 
   113  */ 
   146 TInt COtgRoot::otgActivateOptTestMode()
   114 TInt COtgRoot::otgActivateOptTestMode()
   147 	{
   115 	{
   148 	if(gVerboseOutput)
   116 	LOG_FUNC
   149 	    {
       
   150 	    OstTraceFunctionEntry0(COTGROOT_OTGACTIVATEOPTTESTMODE);
       
   151 	    }
       
   152 
   117 
   153 	TInt err = oUsbOtgDriver.ActivateOptTestMode();
   118 	TInt err = oUsbOtgDriver.ActivateOptTestMode();
   154 
   119 
   155 	return(err);
   120 	return(err);
   156 	}
   121 	}
   158 
   123 
   159 /** otgStartStacks
   124 /** otgStartStacks
   160 */
   125 */
   161 TInt COtgRoot::otgStartStacks()
   126 TInt COtgRoot::otgStartStacks()
   162 	{
   127 	{
   163 	if(gVerboseOutput)
   128 	LOG_FUNC
   164 	    {
       
   165 	    OstTraceFunctionEntry0(COTGROOT_OTGSTARTSTACKS);
       
   166 	    }
       
   167 
   129 
   168 	TInt err(oUsbOtgDriver.StartStacks());
   130 	TInt err(oUsbOtgDriver.StartStacks());
   169 	if (err != KErrNone)
   131 	if (err != KErrNone)
   170 		{
   132 		{
   171 
   133 
   172 		OstTrace1(TRACE_WARNING, COTGROOT_OTGSTARTSTACKS_DUP01, "[WARNING failed %d]", err);
   134 		LOG_FUNCERROR(err)
   173 
   135 
   174 		}
   136 		}
   175 	return(err);
   137 	return(err);
   176 	
   138 	
   177 	}
   139 	}
   179 
   141 
   180 /** otgStopStacks
   142 /** otgStopStacks
   181 */ 
   143 */ 
   182 void COtgRoot::otgStopStacks()
   144 void COtgRoot::otgStopStacks()
   183 	{
   145 	{
   184 	if(gVerboseOutput)
   146 	LOG_FUNC
   185 	    {
       
   186 	    OstTraceFunctionEntry0(COTGROOT_OTGSTOPSTACKS);
       
   187 	    }
       
   188 	
   147 	
   189 	oUsbOtgDriver.StopStacks();
   148 	oUsbOtgDriver.StopStacks();
   190 	}
   149 	}
   191 
   150 
   192 
   151 
   197 
   156 
   198 	// code to unload the OTG ldd driver
   157 	// code to unload the OTG ldd driver
   199 	TInt err (User::FreeLogicalDevice(KOTGDeviceInterfaceDriverName));
   158 	TInt err (User::FreeLogicalDevice(KOTGDeviceInterfaceDriverName));
   200 	if (err != KErrNone)
   159 	if (err != KErrNone)
   201 		{
   160 		{
   202 		OstTrace1(TRACE_WARNING, COTGROOT_OTGUNLOADLDD, "[WARNING failed %d]", err);
   161 		LOG_FUNCERROR(err)
   203 		}
   162 		}
   204 
   163 
   205 	SetLoaded(EFalse);
   164 	SetLoaded(EFalse);
   206 	}
   165 	}
   207 
   166 
   208 
   167 
   209 /** otgQueueOtgEventRequest
   168 /** otgQueueOtgEventRequest
   210 */
   169 */
   211 void COtgRoot::otgQueueOtgEventRequest(RUsbOtgDriver::TOtgEvent& aEvent, TRequestStatus &aStatus)
   170 void COtgRoot::otgQueueOtgEventRequest(RUsbOtgDriver::TOtgEvent& aEvent, TRequestStatus &aStatus)
   212 	{
   171 	{
       
   172 	//LOG_FUNC	
   213 	LOG_VERBOSE2(_L("Queue an Event Request %08X.\n"), (TInt)(&aStatus));
   173 	LOG_VERBOSE2(_L("Queue an Event Request %08X.\n"), (TInt)(&aStatus));
   214 	if(gVerboseOutput)
       
   215 	    {
       
   216 	    OstTrace1(TRACE_VERBOSE, COTGROOT_OTGQUEUEOTGEVENTREQUEST_DUP01, "Queue an Event Request %08X.\n", (TInt)(&aStatus));
       
   217 	    }
       
   218 
   174 
   219 	oUsbOtgDriver.QueueOtgEventRequest(aEvent, aStatus);
   175 	oUsbOtgDriver.QueueOtgEventRequest(aEvent, aStatus);
   220 	
   176 	
   221 	}
   177 	}
   222 	
   178 	
   224 /** otgCancelOtgEventRequest
   180 /** otgCancelOtgEventRequest
   225 */	
   181 */	
   226 void COtgRoot::otgCancelOtgEventRequest()
   182 void COtgRoot::otgCancelOtgEventRequest()
   227 	{
   183 	{
   228 	LOG_VERBOSE1(_L("Cancel Event Request.\n"));
   184 	LOG_VERBOSE1(_L("Cancel Event Request.\n"));
   229 	if(gVerboseOutput)
       
   230 	    {
       
   231 	    OstTrace0(TRACE_VERBOSE, COTGROOT_OTGCANCELOTGEVENTREQUEST, "Cancel Event Request.\n");
       
   232 	    }
       
   233 	oUsbOtgDriver.CancelOtgEventRequest();
   185 	oUsbOtgDriver.CancelOtgEventRequest();
   234 	}
   186 	}
   235     
   187     
   236     
   188     
   237 /** otgQueueOtgMessageRequest
   189 /** otgQueueOtgMessageRequest
   238 */
   190 */
   239 void COtgRoot::otgQueueOtgMessageRequest(RUsbOtgDriver::TOtgMessage& aMessage, TRequestStatus &aStatus)
   191 void COtgRoot::otgQueueOtgMessageRequest(RUsbOtgDriver::TOtgMessage& aMessage, TRequestStatus &aStatus)
   240 	{
   192 	{
   241 
   193 	//LOG_FUNC	
   242 	LOG_VERBOSE2(_L("Queue a Message Request %08X.\n"), (TInt)(&aStatus));
   194 	LOG_VERBOSE2(_L("Queue a Message Request %08X.\n"), (TInt)(&aStatus));
   243 	if(gVerboseOutput)
   195 
   244 	    {
   196 	//LOG_VERBOSE1(_L("Queue a Message Request.\n"));
   245 	    OstTrace1(TRACE_VERBOSE, COTGROOT_OTGQUEUEOTGMESSAGEREQUEST_DUP01, "Queue a Message Request %08X.\n", (TInt)(&aStatus));
       
   246 	    }
       
   247 
       
   248 	oUsbOtgDriver.QueueOtgMessageRequest(aMessage, aStatus);
   197 	oUsbOtgDriver.QueueOtgMessageRequest(aMessage, aStatus);
   249 		
   198 		
   250 	}
   199 	}
   251 	
   200 	
   252 
   201 
   253 /** otgCancelOtgMessageRequest
   202 /** otgCancelOtgMessageRequest
   254 */	
   203 */	
   255 void COtgRoot::otgCancelOtgMessageRequest()
   204 void COtgRoot::otgCancelOtgMessageRequest()
   256 	{
   205 	{
   257 	LOG_VERBOSE1(_L("Cancel Message Request.\n"));
   206 	LOG_VERBOSE1(_L("Cancel Message Request.\n"));
   258 	if(gVerboseOutput)
       
   259 	    {
       
   260 	    OstTrace0(TRACE_VERBOSE, COTGROOT_OTGCANCELOTGMESSAGEREQUEST, "Cancel Message Request.\n");
       
   261 	    }
       
   262 	oUsbOtgDriver.CancelOtgMessageRequest();
   207 	oUsbOtgDriver.CancelOtgMessageRequest();
   263 	}    
   208 	}    
   264     
   209     
   265 void COtgRoot::otgQueuePeripheralStateRequest(TUint& aPeripheralState, TRequestStatus& aStatus)
   210 void COtgRoot::otgQueuePeripheralStateRequest(TUint& aPeripheralState, TRequestStatus& aStatus)
   266 	{
   211 	{
   267 	LOG_VERBOSE1(_L("Queue Peripheral State Request.\n"));
   212 	LOG_VERBOSE1(_L("Queue Peripheral State Request.\n"));
   268 	if(gVerboseOutput)
       
   269 	    {
       
   270 	    OstTrace0(TRACE_VERBOSE, COTGROOT_OTGQUEUEPERIPHERALSTATEREQUEST, "Queue Peripheral State Request.\n");
       
   271 	    }
       
   272 	oUsbcClient.AlternateDeviceStatusNotify(aStatus, aPeripheralState);
   213 	oUsbcClient.AlternateDeviceStatusNotify(aStatus, aPeripheralState);
   273 	}
   214 	}
   274 
   215 
   275 void COtgRoot::otgCancelPeripheralStateRequest()
   216 void COtgRoot::otgCancelPeripheralStateRequest()
   276 	{
   217 	{
   277 	LOG_VERBOSE1(_L("Cancel Peripheral State Request.\n"));
   218 	LOG_VERBOSE1(_L("Cancel Peripheral State Request.\n"));
   278 	if(gVerboseOutput)
       
   279 	    {
       
   280 	    OstTrace0(TRACE_VERBOSE, COTGROOT_OTGCANCELPERIPHERALSTATEREQUEST, "Cancel Peripheral State Request.\n");
       
   281 	    }
       
   282 	oUsbcClient.AlternateDeviceStatusNotifyCancel();	
   219 	oUsbcClient.AlternateDeviceStatusNotifyCancel();	
   283 	}
   220 	}
   284 
   221 
   285 void COtgRoot::otgQueueAConnectionIdleRequest(RUsbOtgDriver::TOtgConnection& aAConnectionIdle, TRequestStatus& aStatus)
   222 void COtgRoot::otgQueueAConnectionIdleRequest(RUsbOtgDriver::TOtgConnection& aAConnectionIdle, TRequestStatus& aStatus)
   286 	{
   223 	{
   287 	LOG_VERBOSE1(_L("Queue A Connection Idle Request.\n"));
   224 	LOG_VERBOSE1(_L("Queue A Connection Idle Request.\n"));
   288 	if(gVerboseOutput)
       
   289 	    {
       
   290 	    OstTrace0(TRACE_VERBOSE, COTGROOT_OTGQUEUEACONNECTIONIDLEREQUEST, "Queue A Connection Idle Request.\n");
       
   291 	    }
       
   292 	oUsbOtgDriver.QueueOtgConnectionNotification(aAConnectionIdle, aStatus);
   225 	oUsbOtgDriver.QueueOtgConnectionNotification(aAConnectionIdle, aStatus);
   293 	}
   226 	}
   294 
   227 
   295 void COtgRoot::otgCancelAConnectionIdleRequest()
   228 void COtgRoot::otgCancelAConnectionIdleRequest()
   296 	{
   229 	{
   297 	LOG_VERBOSE1(_L("Cancel A Connection Idle Request.\n"));
   230 	LOG_VERBOSE1(_L("Cancel A Connection Idle Request.\n"));
   298 	if(gVerboseOutput)
       
   299 	    {
       
   300 	    OstTrace0(TRACE_VERBOSE, COTGROOT_OTGCANCELACONNECTIONIDLEREQUEST, "Cancel A Connection Idle Request.\n");
       
   301 	    }
       
   302 	oUsbOtgDriver.CancelOtgConnectionNotification();
   231 	oUsbOtgDriver.CancelOtgConnectionNotification();
   303 	}
   232 	}
   304 
   233 
   305 
   234 
   306 /** otgQueueOtgStateRequest
   235 /** otgQueueOtgStateRequest
   307 */
   236 */
   308 void COtgRoot::otgQueueOtgStateRequest(RUsbOtgDriver::TOtgState& aState, TRequestStatus &aStatus)
   237 void COtgRoot::otgQueueOtgStateRequest(RUsbOtgDriver::TOtgState& aState, TRequestStatus &aStatus)
   309 	{
   238 	{
       
   239 	//LOG_FUNC	
   310 	LOG_VERBOSE2(_L("Queue a State Request %08X.\n"), (TInt)(&aStatus));
   240 	LOG_VERBOSE2(_L("Queue a State Request %08X.\n"), (TInt)(&aStatus));
   311 	if(gVerboseOutput)
       
   312 	    {
       
   313 	    OstTrace1(TRACE_VERBOSE, COTGROOT_OTGQUEUEOTGSTATEREQUEST_DUP01, "Queue a State Request %08X.\n", (TInt)(&aStatus));
       
   314 	    }
       
   315 
   241 
   316 	oUsbOtgDriver.QueueOtgStateRequest(aState, aStatus);
   242 	oUsbOtgDriver.QueueOtgStateRequest(aState, aStatus);
   317 	
   243 	
   318 	}
   244 	}
   319 	
   245 	
   321 /** otgCancelOtgStateRequest
   247 /** otgCancelOtgStateRequest
   322 */	
   248 */	
   323 void COtgRoot::otgCancelOtgStateRequest()
   249 void COtgRoot::otgCancelOtgStateRequest()
   324 	{
   250 	{
   325 	LOG_VERBOSE1(_L("Cancel State Request.\n"));
   251 	LOG_VERBOSE1(_L("Cancel State Request.\n"));
   326 	if(gVerboseOutput)
       
   327 	    {
       
   328 	    OstTrace0(TRACE_VERBOSE, COTGROOT_OTGCANCELOTGSTATEREQUEST, "Cancel State Request.\n");
       
   329 	    }
       
   330 	oUsbOtgDriver.CancelOtgStateRequest();
   252 	oUsbOtgDriver.CancelOtgStateRequest();
   331 	}
   253 	}
   332 
   254 
   333     
   255     
   334 /** otgBusRequest
   256 /** otgBusRequest
   335 raise VBus (in reality this must only happen when a 'A' is present... and when not present it starts HNP)
   257 raise VBus (in reality this must only happen when a 'A' is present... and when not present it starts HNP)
   336 */
   258 */
   337 TInt COtgRoot::otgBusRequest()
   259 TInt COtgRoot::otgBusRequest()
   338 	{
   260 	{
   339 	if(gVerboseOutput)
   261 	LOG_FUNC
   340 	    {
       
   341 	    OstTraceFunctionEntry0(COTGROOT_OTGBUSREQUEST);
       
   342 	    }
       
   343 	
   262 	
   344 	TInt err(0);
   263 	TInt err(0);
   345 	err = oUsbOtgDriver.BusRequest();
   264 	err = oUsbOtgDriver.BusRequest();
   346 	if (err != KErrNone)
   265 	if (err != KErrNone)
   347 		{
   266 		{
   348 		OstTrace1(TRACE_WARNING, COTGROOT_OTGBUSREQUEST_DUP01, "[WARNING failed %d]", err);
   267 		LOG_FUNCERROR(err)
   349 		}
   268 		}
   350 	return(err);
   269 	return(err);
   351 	}
   270 	}
   352 	
   271 	
   353 
   272 
   354 /* call when SRP has been recieved, based on our HNP Enable setting, this will allow HNP. The 
   273 /* call when SRP has been recieved, based on our HNP Enable setting, this will allow HNP. The 
   355  * A-device may choose to call BusRequest directly, which will result in a 'short-circuit' role-swap.
   274  * A-device may choose to call BusRequest directly, which will result in a 'short-circuit' role-swap.
   356  */
   275  */
   357 TInt COtgRoot::otgBusRespondSRP()
   276 TInt COtgRoot::otgBusRespondSRP()
   358 	{
   277 	{
   359 	if(gVerboseOutput)
   278 	LOG_FUNC
   360 	    {
       
   361 	    OstTraceFunctionEntry0(COTGROOT_OTGBUSRESPONDSRP);
       
   362 	    }
       
   363 	TInt err(0);
   279 	TInt err(0);
   364 		err = oUsbOtgDriver.BusRespondSrp();
   280 		err = oUsbOtgDriver.BusRespondSrp();
   365 		if (err != KErrNone)
   281 		if (err != KErrNone)
   366 			{
   282 			{
   367 			OstTrace1(TRACE_WARNING, COTGROOT_OTGBUSRESPONDSRP_DUP01, "[WARNING failed %d]", err);
   283 			LOG_FUNCERROR(err)
   368 			}
   284 			}
   369 		return(err);
   285 		return(err);
   370 	}
   286 	}
   371 
   287 
   372 	
   288 	
   373 /** Drop VBus (A-host)
   289 /** Drop VBus (A-host)
   374 */	
   290 */	
   375 TInt COtgRoot::otgBusDrop()
   291 TInt COtgRoot::otgBusDrop()
   376 	{
   292 	{
   377 	if(gVerboseOutput)
   293 	LOG_FUNC
   378 	    {
       
   379 	    OstTraceFunctionEntry0(COTGROOT_OTGBUSDROP);
       
   380 	    }
       
   381 	TInt err(0);
   294 	TInt err(0);
   382 	err = oUsbOtgDriver.BusDrop();
   295 	err = oUsbOtgDriver.BusDrop();
   383 	if (err != KErrNone)
   296 	if (err != KErrNone)
   384 		{
   297 		{
   385 		OstTrace1(TRACE_WARNING, COTGROOT_OTGBUSDROP_DUP01, "[WARNING failed %d]", err);
   298 		LOG_FUNCERROR(err)
   386 		}
   299 		}
   387 	return(err);
   300 	return(err);
   388 	}
   301 	}
   389 
   302 
   390 /** otgBusClearError
   303 /** otgBusClearError
   391 */
   304 */
   392 TInt COtgRoot::otgBusClearError()
   305 TInt COtgRoot::otgBusClearError()
   393 	{
   306 	{
   394 	if(gVerboseOutput)
   307 	LOG_FUNC
   395 	    {
       
   396 	    OstTraceFunctionEntry0(COTGROOT_OTGBUSCLEARERROR);
       
   397 	    }
       
   398 	
   308 	
   399 	TInt err(0);
   309 	TInt err(0);
   400 	err = oUsbOtgDriver.BusClearError();
   310 	err = oUsbOtgDriver.BusClearError();
   401 	if (err != KErrNone)
   311 	if (err != KErrNone)
   402 		{
   312 		{
   403 		OstTrace1(TRACE_WARNING, COTGROOT_OTGBUSCLEARERROR_DUP01, "[WARNING failed %d]", err);
   313 		LOG_FUNCERROR(err)
   404 		}
   314 		}
   405 	return(err);
   315 	return(err);
   406 	}
   316 	}
   407 	
   317 	
   408 
   318 
   409 	
   319 	
   410 void COtgRoot::otgQueueOtgIdPinNotification(RUsbOtgDriver::TOtgIdPin& aPin, TRequestStatus& aStatus)
   320 void COtgRoot::otgQueueOtgIdPinNotification(RUsbOtgDriver::TOtgIdPin& aPin, TRequestStatus& aStatus)
   411 	{
   321 	{
   412 	if(gVerboseOutput)
   322 	LOG_FUNC
   413 	    {
       
   414 	    OstTraceFunctionEntry0(COTGROOT_OTGQUEUEOTGIDPINNOTIFICATION);
       
   415 	    }
       
   416 	oUsbOtgDriver.QueueOtgIdPinNotification(aPin, aStatus);	// the kernel driver populates aPin...
   323 	oUsbOtgDriver.QueueOtgIdPinNotification(aPin, aStatus);	// the kernel driver populates aPin...
   417 	}
   324 	}
   418 
   325 
   419 	
   326 	
   420 void COtgRoot::otgCancelOtgIdPinNotification()
   327 void COtgRoot::otgCancelOtgIdPinNotification()
   421 	{
   328 	{
   422 	if(gVerboseOutput)
   329 	LOG_FUNC
   423 	    {
       
   424 	    OstTraceFunctionEntry0(COTGROOT_OTGCANCELOTGIDPINNOTIFICATION);
       
   425 	    }
       
   426 	oUsbOtgDriver.CancelOtgIdPinNotification();
   330 	oUsbOtgDriver.CancelOtgIdPinNotification();
   427 	}
   331 	}
   428 
   332 
   429 
   333 
   430 void COtgRoot::otgQueueOtgVbusNotification(RUsbOtgDriver::TOtgVbus& aVbus, 
   334 void COtgRoot::otgQueueOtgVbusNotification(RUsbOtgDriver::TOtgVbus& aVbus, 
   431                                                 TRequestStatus& aStatus
   335                                                 TRequestStatus& aStatus
   432                                                )
   336                                                )
   433 	{
   337 	{
   434 	if(gVerboseOutput)
   338 	LOG_FUNC
   435 	    {
       
   436 	    OstTraceFunctionEntry0(COTGROOT_OTGQUEUEOTGVBUSNOTIFICATION);
       
   437 	    }
       
   438 	oUsbOtgDriver.QueueOtgVbusNotification(aVbus, aStatus);
   339 	oUsbOtgDriver.QueueOtgVbusNotification(aVbus, aStatus);
   439 	}
   340 	}
   440 	
   341 	
   441 	
   342 	
   442 void COtgRoot::otgCancelOtgVbusNotification()
   343 void COtgRoot::otgCancelOtgVbusNotification()
   443 	{
   344 	{
   444 	if(gVerboseOutput)
   345 	LOG_FUNC
   445 	    {
       
   446 	    OstTraceFunctionEntry0(COTGROOT_OTGCANCELOTGVBUSNOTIFICATION);
       
   447 	    }
       
   448 	oUsbOtgDriver.CancelOtgVbusNotification();
   346 	oUsbOtgDriver.CancelOtgVbusNotification();
   449 	}
   347 	}
   450 
   348 
   451 
   349 
   452 TBool COtgRoot::otgIdPinPresent()
   350 TBool COtgRoot::otgIdPinPresent()
   453 	{
   351 	{
   454 	if(gVerboseOutput)
   352 	LOG_FUNC
   455 	    {
       
   456 	    OstTraceFunctionEntry0(COTGROOT_OTGIDPINPRESENT);
       
   457 	    }
       
   458 	TRequestStatus aStatus;
   353 	TRequestStatus aStatus;
   459 	RUsbOtgDriver::TOtgIdPin aPin;
   354 	RUsbOtgDriver::TOtgIdPin aPin;
   460 	oUsbOtgDriver.QueueOtgIdPinNotification(aPin, aStatus);	// the kernel driver populates aPin...
   355 	oUsbOtgDriver.QueueOtgIdPinNotification(aPin, aStatus);	// the kernel driver populates aPin...
   461 	LOG_VERBOSE2(_L("(sync) ID_PIN=%d\n"), iOTGIdPin);
   356 	LOG_VERBOSE2(_L("(sync) ID_PIN=%d\n"), iOTGIdPin);
   462 	if(gVerboseOutput)
       
   463 	    {
       
   464 	    OstTrace1(TRACE_VERBOSE, COTGROOT_OTGIDPINPRESENT_DUP01, "(sync) ID_PIN=%d\n", iOTGIdPin);
       
   465 	    }
       
   466 	
   357 	
   467 	oUsbOtgDriver.CancelOtgIdPinNotification();
   358 	oUsbOtgDriver.CancelOtgIdPinNotification();
   468 	// swallow the event
   359 	// swallow the event
   469 	User::WaitForRequest(aStatus);
   360 	User::WaitForRequest(aStatus);
   470 	
   361 	
   476 	}
   367 	}
   477 	
   368 	
   478 	
   369 	
   479 TBool COtgRoot::otgVbusPresent()
   370 TBool COtgRoot::otgVbusPresent()
   480 	{
   371 	{
   481 	if(gVerboseOutput)
   372 	LOG_FUNC
   482 	    {
       
   483 	    OstTraceFunctionEntry0(COTGROOT_OTGVBUSPRESENT);
       
   484 	    }
       
   485 	TRequestStatus aStatus;
   373 	TRequestStatus aStatus;
   486  	RUsbOtgDriver::TOtgVbus aVBus;
   374  	RUsbOtgDriver::TOtgVbus aVBus;
   487 	oUsbOtgDriver.QueueOtgVbusNotification(aVBus, aStatus);	// the kernel driver populates aPin in a kernel thread...
   375 	oUsbOtgDriver.QueueOtgVbusNotification(aVBus, aStatus);	// the kernel driver populates aPin in a kernel thread...
   488 	oUsbOtgDriver.CancelOtgVbusNotification();
   376 	oUsbOtgDriver.CancelOtgVbusNotification();
   489 	// swallow the event
   377 	// swallow the event
   627 
   515 
   628 TInt COtgRoot::otgActivateFdfActor()
   516 TInt COtgRoot::otgActivateFdfActor()
   629 	{
   517 	{
   630 	if(iFdfActorActive)
   518 	if(iFdfActorActive)
   631 		{
   519 		{
   632 		OstTrace0(TRACE_NORMAL, COTGROOT_OTGACTIVATEFDFACTOR, "FdfActor already exists!");
   520 		RDebug::Print(_L("FdfActor already exists!"));
   633 		return KErrAlreadyExists;
   521 		return KErrAlreadyExists;
   634 		}
   522 		}
   635 		
   523 		
   636 	const TUid KFdfSvrUid={0x10282B48};
   524 	const TUid KFdfSvrUid={0x10282B48};
   637 	const TUidType fdfActorUid(KNullUid, KNullUid, KFdfSvrUid);
   525 	const TUidType fdfActorUid(KNullUid, KNullUid, KFdfSvrUid);
   638 
   526 
   639 	OstTrace0(TRACE_NORMAL, COTGROOT_OTGACTIVATEFDFACTOR_DUP01, "About to activate FDF Actor");
   527 	RDebug::Print(_L("About to activate FDF Actor"));
   640 
   528 
   641 //	RProcess fdfActorProcess;
   529 //	RProcess fdfActorProcess;
   642 	TInt err = iFdfActorProcess.Create(_L("t_otgdi_fdfactor.exe"), KNullDesC, fdfActorUid);
   530 	TInt err = iFdfActorProcess.Create(_L("t_otgdi_fdfactor.exe"), KNullDesC, fdfActorUid);
   643 	
   531 	
   644 	if (err != KErrNone)
   532 	if (err != KErrNone)
   645 		{
   533 		{
   646 		OstTrace1(TRACE_NORMAL, COTGROOT_OTGACTIVATEFDFACTOR_DUP02, "Failed to create FDF Actor, err=%d",err);
   534 		RDebug::Print(_L("Failed to create FDF Actor, err=%d"),err);
   647 		iFdfActorProcess.Close();
   535 		iFdfActorProcess.Close();
   648 		return err;
   536 		return err;
   649 		}
   537 		}
   650 
   538 
   651 	TRequestStatus stat;
   539 	TRequestStatus stat;
   652 	iFdfActorProcess.Rendezvous(stat);
   540 	iFdfActorProcess.Rendezvous(stat);
   653 	
   541 	
   654 	if (stat!=KRequestPending)
   542 	if (stat!=KRequestPending)
   655 		{
   543 		{
   656 		OstTrace1(TRACE_NORMAL, COTGROOT_OTGACTIVATEFDFACTOR_DUP03, "Failed to commence rendezvous, err=%d",stat.Int());
   544 		RDebug::Print(_L("Failed to commence rendezvous, err=%d"),stat.Int());
   657 		iFdfActorProcess.Kill(0);		// abort startup
   545 		iFdfActorProcess.Kill(0);		// abort startup
   658 		iFdfActorProcess.Close();
   546 		iFdfActorProcess.Close();
   659 		return stat.Int();
   547 		return stat.Int();
   660 		}
   548 		}
   661 	else
   549 	else
   666 	User::WaitForRequest(stat);		// wait for start or death
   554 	User::WaitForRequest(stat);		// wait for start or death
   667 	if(stat.Int()!=KErrNone)
   555 	if(stat.Int()!=KErrNone)
   668 		{
   556 		{
   669 		//	Wasn't KErrNone, which means that the FDFActor didn't successfully
   557 		//	Wasn't KErrNone, which means that the FDFActor didn't successfully
   670 		//	start up. We shouldn't proceed with the test we're in.
   558 		//	start up. We shouldn't proceed with the test we're in.
   671 		OstTrace1(TRACE_NORMAL, COTGROOT_OTGACTIVATEFDFACTOR_DUP04, "Failed to activate FDF Actor, err=%d",stat.Int());
   559 		RDebug::Print(_L("Failed to activate FDF Actor, err=%d"),stat.Int());
   672 		iFdfActorProcess.Close();
   560 		iFdfActorProcess.Close();
   673 		return stat.Int();
   561 		return stat.Int();
   674 		}
   562 		}
   675 	
   563 	
   676 	//	We rendezvoused(?) with the FDFActor OK, so it is going to suspend
   564 	//	We rendezvoused(?) with the FDFActor OK, so it is going to suspend
   677 	//	any devices it sees being attached, and will shut itself down
   565 	//	any devices it sees being attached, and will shut itself down
   678 	//	when this process signals its Rendezvous (at the end of the test)...
   566 	//	when this process signals its Rendezvous (at the end of the test)...
   679 	OstTrace0(TRACE_NORMAL, COTGROOT_OTGACTIVATEFDFACTOR_DUP05, "Activated FDF Actor");
   567 	RDebug::Print(_L("Activated FDF Actor"));
   680 	iFdfActorActive = ETrue;
   568 	iFdfActorActive = ETrue;
   681 
   569 
   682 	return KErrNone;
   570 	return KErrNone;
   683 	}
   571 	}
   684 
   572 
   685 void COtgRoot::otgDeactivateFdfActor()
   573 void COtgRoot::otgDeactivateFdfActor()
   686 	{
   574 	{
   687 	if(!iFdfActorActive)
   575 	if(!iFdfActorActive)
   688 		{
   576 		{
   689 		OstTrace0(TRACE_NORMAL, COTGROOT_OTGDEACTIVATEFDFACTOR, "FdfActor is not running!");
   577 		RDebug::Print(_L("FdfActor is not running!"));
   690 		return;
   578 		return;
   691 		}
   579 		}
   692 
   580 
   693 	//	If iFdfActorActive is set, the FDF Actor should be waiting to
   581 	//	If iFdfActorActive is set, the FDF Actor should be waiting to
   694 	//	rendezvous with us before it shuts down...
   582 	//	rendezvous with us before it shuts down...
   701 	RProcess::Rendezvous(KErrNone);
   589 	RProcess::Rendezvous(KErrNone);
   702 	
   590 	
   703 	//	...and wait for it to go away.
   591 	//	...and wait for it to go away.
   704 	User::WaitForRequest(waitForCloseStat);
   592 	User::WaitForRequest(waitForCloseStat);
   705 	test.Printf(_L("T_OTGDI confirms FDF Actor has gone away %d\n"), waitForCloseStat.Int());
   593 	test.Printf(_L("T_OTGDI confirms FDF Actor has gone away %d\n"), waitForCloseStat.Int());
   706 	OstTrace1(TRACE_NORMAL, COTGROOT_OTGDEACTIVATEFDFACTOR_DUP01, "T_OTGDI confirms FDF Actor has gone away %d\n", waitForCloseStat.Int());
       
   707 	
   594 	
   708 	//	Now close our handle, and record that the process is no more...
   595 	//	Now close our handle, and record that the process is no more...
   709 	iFdfActorProcess.Close();
   596 	iFdfActorProcess.Close();
   710 	iFdfActorActive = EFalse;
   597 	iFdfActorActive = EFalse;
   711 	}
   598 	}
   714 * @return ETrue if the ldd unloaded sucessfully
   601 * @return ETrue if the ldd unloaded sucessfully
   715 */
   602 */
   716 TBool COtgRoot::StepUnloadClient()
   603 TBool COtgRoot::StepUnloadClient()
   717 	{
   604 	{
   718 	test.Printf(_L("Unload USBCC Client\n"));
   605 	test.Printf(_L("Unload USBCC Client\n"));
   719 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPUNLOADCLIENT, "Unload USBCC Client\n");
       
   720 
   606 
   721 	TInt err;
   607 	TInt err;
   722 
   608 
   723 	// Close the Client
   609 	// Close the Client
   724 
   610 
   725 	test.Printf(_L("..Close\n"));
   611 	test.Printf(_L("..Close\n"));
   726 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPUNLOADCLIENT_DUP01, "..Close\n");
       
   727 	oUsbcClient.Close();
   612 	oUsbcClient.Close();
   728 
   613 
   729 	// Unload the LDD - note the name is *not* the same as for loading
   614 	// Unload the LDD - note the name is *not* the same as for loading
   730 
   615 
   731 	test.Printf(_L("..Unload\n"));
   616 	test.Printf(_L("..Unload\n"));
   732 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPUNLOADCLIENT_DUP02, "..Unload\n");
       
   733 	err = User::FreeLogicalDevice( KUsbDeviceName );
   617 	err = User::FreeLogicalDevice( KUsbDeviceName );
   734 	if (err != KErrNone)
   618 	if (err != KErrNone)
   735 		{
   619 		{
   736 		AssertionFailed2(KErrAbort, _L("Client Unload Fail "), err);
   620 		AssertionFailed2(KErrAbort, _L("Client Unload Fail "), err);
   737 		return (EFalse);
   621 		return (EFalse);
   749 TBool COtgRoot::StepLoadClient(TUint16 aPID, 
   633 TBool COtgRoot::StepLoadClient(TUint16 aPID, 
   750 								TBool aEnableHNP/*=ETrue*/, 
   634 								TBool aEnableHNP/*=ETrue*/, 
   751 								TBool aEnableSRP/*=ETrue*/)
   635 								TBool aEnableSRP/*=ETrue*/)
   752 	{
   636 	{
   753 	test.Printf(_L("Load USBCC Client 0x%04x\n"),aPID);
   637 	test.Printf(_L("Load USBCC Client 0x%04x\n"),aPID);
   754 	OstTrace1(TRACE_NORMAL, COTGROOT_STEPLOADCLIENT, "Load USBCC Client 0x%04x\n",aPID);
       
   755 
   638 
   756 	TInt err;
   639 	TInt err;
   757 
   640 
   758 	// The incoming PID is expected to have a form of 0x0TTT or 0xFTTT
   641 	// The incoming PID is expected to have a form of 0x0TTT or 0xFTTT
   759 	// where 'TTT' is the test number: if the lead is 0xF000 we now 
   642 	// where 'TTT' is the test number: if the lead is 0xF000 we now 
   783 		}
   666 		}
   784 	
   667 	
   785 	// Load the LDD - note the name is *not* the same as for unload
   668 	// Load the LDD - note the name is *not* the same as for unload
   786 
   669 
   787 	test.Printf(_L("..Load LDD\n"));
   670 	test.Printf(_L("..Load LDD\n"));
   788 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPLOADCLIENT_DUP01, "..Load LDD\n");
       
   789 	err = User::LoadLogicalDevice( KUsbcLddFileName );
   671 	err = User::LoadLogicalDevice( KUsbcLddFileName );
   790 	if ((err != KErrNone) && (err !=KErrAlreadyExists))
   672 	if ((err != KErrNone) && (err !=KErrAlreadyExists))
   791 		{
   673 		{
   792 		AssertionFailed2(KErrAbort, _L("Client Load Fail "), err);
   674 		AssertionFailed2(KErrAbort, _L("Client Load Fail "), err);
   793 		return (EFalse);
   675 		return (EFalse);
   794 		}
   676 		}
   795 
   677 
   796 	// Open the Client
   678 	// Open the Client
   797 
   679 
   798 	test.Printf(_L("..Open LDD\n"));
   680 	test.Printf(_L("..Open LDD\n"));
   799 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPLOADCLIENT_DUP02, "..Open LDD\n");
       
   800 	err = oUsbcClient.Open(0);
   681 	err = oUsbcClient.Open(0);
   801 	if (err != KErrNone)
   682 	if (err != KErrNone)
   802 		{
   683 		{
   803 		AssertionFailed2(KErrAbort, _L("Client Open Fail "), err);
   684 		AssertionFailed2(KErrAbort, _L("Client Open Fail "), err);
   804 		return (EFalse);
   685 		return (EFalse);
   805 		}
   686 		}
   806 
   687 
   807 	// Set up descriptors
   688 	// Set up descriptors
   808 	
   689 	
   809 	test.Printf(_L("..Setup Descriptors\n"));
   690 	test.Printf(_L("..Setup Descriptors\n"));
   810 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPLOADCLIENT_DUP03, "..Setup Descriptors\n");
       
   811 
   691 
   812 	// the OTG descriptor
   692 	// the OTG descriptor
   813 	TBuf8<KUsbDescSize_Otg> theOtgDescriptor;
   693 	TBuf8<KUsbDescSize_Otg> theOtgDescriptor;
   814 	err = oUsbcClient.GetOtgDescriptor(theOtgDescriptor);
   694 	err = oUsbcClient.GetOtgDescriptor(theOtgDescriptor);
   815 	if (err != KErrNone)
   695 	if (err != KErrNone)
   827 	TUint8 aByte = theOtgDescriptor[2];
   707 	TUint8 aByte = theOtgDescriptor[2];
   828 		aByte &= (~0x03);
   708 		aByte &= (~0x03);
   829 		aByte |= (aEnableSRP? 1 : 0); 
   709 		aByte |= (aEnableSRP? 1 : 0); 
   830 		aByte |= (aEnableHNP? 2 : 0); 
   710 		aByte |= (aEnableHNP? 2 : 0); 
   831 	test.Printf(_L("..Change OTG 0x%02X->0x%02X\n"), theOtgDescriptor[2], aByte);
   711 	test.Printf(_L("..Change OTG 0x%02X->0x%02X\n"), theOtgDescriptor[2], aByte);
   832 	OstTraceExt2(TRACE_NORMAL, COTGROOT_STEPLOADCLIENT_DUP04, "..Change OTG 0x%02X->0x%02X\n", (TUint32)theOtgDescriptor[2], (TUint32)aByte);
       
   833 	theOtgDescriptor[2] = aByte;
   712 	theOtgDescriptor[2] = aByte;
   834 	
   713 	
   835 	err = oUsbcClient.SetOtgDescriptor(theOtgDescriptor);
   714 	err = oUsbcClient.SetOtgDescriptor(theOtgDescriptor);
   836 	if (err != KErrNone)
   715 	if (err != KErrNone)
   837 		{
   716 		{
   853 
   732 
   854 	const TInt n = d_caps().iTotalEndpoints;
   733 	const TInt n = d_caps().iTotalEndpoints;
   855 
   734 
   856 	softwareConnect = d_caps().iConnect;
   735 	softwareConnect = d_caps().iConnect;
   857 	test.Printf(_L("..SoftwareConnect = %d\n"),softwareConnect);
   736 	test.Printf(_L("..SoftwareConnect = %d\n"),softwareConnect);
   858 	OstTrace1(TRACE_NORMAL, COTGROOT_STEPLOADCLIENT_DUP05, "..SoftwareConnect = %d\n",softwareConnect);
       
   859 
   737 
   860 	if (n < 2)
   738 	if (n < 2)
   861 		{
   739 		{
   862 		AssertionFailed2(KErrAbort, _L("Client Endpoints Fail "), err);
   740 		AssertionFailed2(KErrAbort, _L("Client Endpoints Fail "), err);
   863 		return (EFalse);
   741 		return (EFalse);
   949 
   827 
   950 	theDeviceDescriptor[10] = ( aPID & 0x00FF );
   828 	theDeviceDescriptor[10] = ( aPID & 0x00FF );
   951 	theDeviceDescriptor[11] = ( aPID & 0xFF00 ) >> 8;
   829 	theDeviceDescriptor[11] = ( aPID & 0xFF00 ) >> 8;
   952 
   830 
   953 	test.Printf(_L("..Change PID 0x%04X->0x%04X\n"), oldPID, aPID);
   831 	test.Printf(_L("..Change PID 0x%04X->0x%04X\n"), oldPID, aPID);
   954 	OstTraceExt2(TRACE_NORMAL, COTGROOT_STEPLOADCLIENT_DUP06, "..Change PID 0x%04X->0x%04X\n", (TUint32)oldPID, (TUint32)aPID);
       
   955 
   832 
   956 	err = oUsbcClient.SetDeviceDescriptor(theDeviceDescriptor);
   833 	err = oUsbcClient.SetDeviceDescriptor(theDeviceDescriptor);
   957 	if (err != KErrNone)
   834 	if (err != KErrNone)
   958 		{
   835 		{
   959 		AssertionFailed2(KErrAbort, _L("Client SetDes Fail "), err);
   836 		AssertionFailed2(KErrAbort, _L("Client SetDes Fail "), err);
   962 
   839 
   963 
   840 
   964 	// Power Up UDC - KErrNotReady is expected
   841 	// Power Up UDC - KErrNotReady is expected
   965 
   842 
   966 	test.Printf(_L("..Power Up UDC\n"));
   843 	test.Printf(_L("..Power Up UDC\n"));
   967 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPLOADCLIENT_DUP07, "..Power Up UDC\n");
       
   968 
   844 
   969 	err = oUsbcClient.PowerUpUdc();
   845 	err = oUsbcClient.PowerUpUdc();
   970 	if( err != KErrNotReady )
   846 	if( err != KErrNotReady )
   971 		{
   847 		{
   972 		AssertionFailed2(KErrAbort, _L("PowerUp UDC Fail "), err);
   848 		AssertionFailed2(KErrAbort, _L("PowerUp UDC Fail "), err);
   974 		}
   850 		}
   975 
   851 
   976 	// Connect to Host
   852 	// Connect to Host
   977 
   853 
   978 	test.Printf(_L("..Connect to Host\n"));
   854 	test.Printf(_L("..Connect to Host\n"));
   979 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPLOADCLIENT_DUP08, "..Connect to Host\n");
       
   980 
   855 
   981 	err = oUsbcClient.DeviceConnectToHost();
   856 	err = oUsbcClient.DeviceConnectToHost();
   982 	if( err != KErrNone )
   857 	if( err != KErrNone )
   983 		{
   858 		{
   984 		AssertionFailed2(KErrAbort, _L("Host Connect Fail "), err);
   859 		AssertionFailed2(KErrAbort, _L("Host Connect Fail "), err);
   995  *  the device to/from the host
   870  *  the device to/from the host
   996  */
   871  */
   997 TBool COtgRoot::StepDisconnect()
   872 TBool COtgRoot::StepDisconnect()
   998 	{
   873 	{
   999 	test.Printf(_L("Disconnect from Host\n"));
   874 	test.Printf(_L("Disconnect from Host\n"));
  1000 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPDISCONNECT, "Disconnect from Host\n");
       
  1001 
   875 
  1002 	TInt err;
   876 	TInt err;
  1003 	
   877 	
  1004 	err = oUsbcClient.DeviceDisconnectFromHost();
   878 	err = oUsbcClient.DeviceDisconnectFromHost();
  1005 	if( err != KErrNone )
   879 	if( err != KErrNone )
  1014 	}
   888 	}
  1015 
   889 
  1016 TBool COtgRoot::StepConnect()
   890 TBool COtgRoot::StepConnect()
  1017 	{
   891 	{
  1018 	test.Printf(_L("Connect to Host\n"));
   892 	test.Printf(_L("Connect to Host\n"));
  1019 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPCONNECT, "Connect to Host\n");
       
  1020 
   893 
  1021 	TInt err;
   894 	TInt err;
  1022 	
   895 	
  1023 	err = oUsbcClient.DeviceConnectToHost();
   896 	err = oUsbcClient.DeviceConnectToHost();
  1024 	if( err != KErrNone )
   897 	if( err != KErrNone )
  1039  */
   912  */
  1040 TBool COtgRoot::StepChangeVidPid(TUint16 aVID, TUint16 aPID)
   913 TBool COtgRoot::StepChangeVidPid(TUint16 aVID, TUint16 aPID)
  1041 
   914 
  1042 	{
   915 	{
  1043 	test.Printf(_L("Load USBCC HS Test Client 0x%04x/0x%04x\n"),aVID,aPID);
   916 	test.Printf(_L("Load USBCC HS Test Client 0x%04x/0x%04x\n"),aVID,aPID);
  1044 	OstTraceExt2(TRACE_NORMAL, COTGROOT_STEPCHANGEVIDPID, "Load USBCC HS Test Client 0x%04x/0x%04x\n",(TUint32)aVID,(TUint32)aPID);
       
  1045 
   917 
  1046 	TInt err;
   918 	TInt err;
  1047 
   919 
  1048 	// Set the revised VID/PID pair
   920 	// Set the revised VID/PID pair
  1049 	
   921 	
  1060 
   932 
  1061 	theDeviceDescriptor[8] = ( aVID & 0x00FF );
   933 	theDeviceDescriptor[8] = ( aVID & 0x00FF );
  1062 	theDeviceDescriptor[9] = ( aVID & 0xFF00 ) >> 8;
   934 	theDeviceDescriptor[9] = ( aVID & 0xFF00 ) >> 8;
  1063 
   935 
  1064 	test.Printf(_L("..Change VID 0x%04X->0x%04X\n"), oldVID, aVID);
   936 	test.Printf(_L("..Change VID 0x%04X->0x%04X\n"), oldVID, aVID);
  1065 	OstTraceExt2(TRACE_NORMAL, COTGROOT_STEPCHANGEVIDPID_DUP01, "..Change VID 0x%04X->0x%04X\n", (TUint32)oldVID, (TUint32)aVID);
       
  1066 
   937 
  1067 	TUint16 oldPID = ( theDeviceDescriptor[10] )
   938 	TUint16 oldPID = ( theDeviceDescriptor[10] )
  1068 		           + ( theDeviceDescriptor[11] << 8 );
   939 		           + ( theDeviceDescriptor[11] << 8 );
  1069 
   940 
  1070 	theDeviceDescriptor[10] = ( aPID & 0x00FF );
   941 	theDeviceDescriptor[10] = ( aPID & 0x00FF );
  1071 	theDeviceDescriptor[11] = ( aPID & 0xFF00 ) >> 8;
   942 	theDeviceDescriptor[11] = ( aPID & 0xFF00 ) >> 8;
  1072 
   943 
  1073 	test.Printf(_L("..Change PID 0x%04X->0x%04X\n"), oldPID, aPID);
   944 	test.Printf(_L("..Change PID 0x%04X->0x%04X\n"), oldPID, aPID);
  1074 	OstTraceExt2(TRACE_NORMAL, COTGROOT_STEPCHANGEVIDPID_DUP02, "..Change PID 0x%04X->0x%04X\n", (TUint32)oldPID, (TUint32)aPID);
       
  1075 
   945 
  1076 	err = oUsbcClient.SetDeviceDescriptor(theDeviceDescriptor);
   946 	err = oUsbcClient.SetDeviceDescriptor(theDeviceDescriptor);
  1077 	if (err != KErrNone)
   947 	if (err != KErrNone)
  1078 		{
   948 		{
  1079 		AssertionFailed2(KErrAbort, _L("Client SetDes Fail "), err);
   949 		AssertionFailed2(KErrAbort, _L("Client SetDes Fail "), err);
  1100 *@return ETrue if the ldd unloaded sucessfully
   970 *@return ETrue if the ldd unloaded sucessfully
  1101 */
   971 */
  1102 TBool COtgRoot::StepUnloadLDD()
   972 TBool COtgRoot::StepUnloadLDD()
  1103 	{ 
   973 	{ 
  1104 	test.Printf(_L("Unload otg LDD (implicit Stop() + Close()) \n"));
   974 	test.Printf(_L("Unload otg LDD (implicit Stop() + Close()) \n"));
  1105 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPUNLOADLDD, "Unload otg LDD (implicit Stop(+ Close()) \n");
       
  1106 	
   975 	
  1107 	LOG_VERBOSE1(_L("  Stop OTG+Host Stack\n"));
   976 	LOG_VERBOSE1(_L("  Stop OTG+Host Stack\n"));
  1108 	if(gVerboseOutput)
       
  1109 	    {
       
  1110 	    OstTrace0(TRACE_VERBOSE, COTGROOT_STEPUNLOADLDD_DUP01, "  Stop OTG+Host Stack\n");
       
  1111 	    }
       
  1112 	otgStopStacks();
   977 	otgStopStacks();
  1113 	otgClose();
   978 	otgClose();
  1114 	
   979 	
  1115 	LOG_VERBOSE1(_L("  Unload\n"));
   980 	LOG_VERBOSE1(_L("  Unload\n"));
  1116 	if(gVerboseOutput)
       
  1117 	    {
       
  1118 	    OstTrace0(TRACE_VERBOSE, COTGROOT_STEPUNLOADLDD_DUP02, "  Unload\n");
       
  1119 	    }
       
  1120 	otgUnloadLdd();
   981 	otgUnloadLdd();
  1121 	
   982 	
  1122 	iOptActive = EFalse; // retain the OTGDI behavour to clears this flag when client shuts 
   983 	iOptActive = EFalse; // retain the OTGDI behavour to clears this flag when client shuts 
  1123 	if (LddLoaded())
   984 	if (LddLoaded())
  1124 		return(EFalse);
   985 		return(EFalse);
  1131 TBool COtgRoot::StepLoadLDD()
   992 TBool COtgRoot::StepLoadLDD()
  1132 	{
   993 	{
  1133 	TInt err;	
   994 	TInt err;	
  1134 
   995 
  1135 	LOG_VERBOSE1(_L("Load otg LDD\n"));
   996 	LOG_VERBOSE1(_L("Load otg LDD\n"));
  1136 	if(gVerboseOutput)
       
  1137 	    {
       
  1138 	    OstTrace0(TRACE_VERBOSE, COTGROOT_STEPLOADLDD, "Load otg LDD\n");
       
  1139 	    }
       
  1140 	err = otgLoadLdd();
   997 	err = otgLoadLdd();
  1141 	if (err != KErrNone)
   998 	if (err != KErrNone)
  1142 		{
   999 		{
  1143 		AssertionFailed2(KErrAbort, _L("Loading LDD failed "), err);
  1000 		AssertionFailed2(KErrAbort, _L("Loading LDD failed "), err);
  1144 		return (EFalse);
  1001 		return (EFalse);
  1145 		}
  1002 		}
  1146 		
  1003 		
  1147 	LOG_VERBOSE1(_L("Open the LDD session\n"));
  1004 	LOG_VERBOSE1(_L("Open the LDD session\n"));
  1148 	if(gVerboseOutput)
       
  1149 	    {
       
  1150 	    OstTrace0(TRACE_VERBOSE, COTGROOT_STEPLOADLDD_DUP01, "Open the LDD session\n");
       
  1151 	    }
       
  1152 	err = otgOpen();
  1005 	err = otgOpen();
  1153 	if (err != KErrNone)
  1006 	if (err != KErrNone)
  1154 		{
  1007 		{
  1155 		AssertionFailed2(KErrAbort, _L("Open LDD session failed "), err);
  1008 		AssertionFailed2(KErrAbort, _L("Open LDD session failed "), err);
  1156 		return (EFalse);
  1009 		return (EFalse);
  1157 		}
  1010 		}
  1158 
  1011 
  1159 	if ( iOptActive )
  1012 	if ( iOptActive )
  1160 		{
  1013 		{
  1161 		test.Printf(_L("Activate OPT Test Mode\n"));
  1014 		test.Printf(_L("Activate OPT Test Mode\n"));
  1162 		OstTrace0(TRACE_NORMAL, COTGROOT_STEPLOADLDD_DUP02, "Activate OPT Test Mode\n");
       
  1163 		err = otgActivateOptTestMode();
  1015 		err = otgActivateOptTestMode();
  1164 		if (err != KErrNone)
  1016 		if (err != KErrNone)
  1165 			{
  1017 			{
  1166 			AssertionFailed2(KErrAbort, _L("OPT Activate failed "), err);
  1018 			AssertionFailed2(KErrAbort, _L("OPT Activate failed "), err);
  1167 			return (EFalse);
  1019 			return (EFalse);
  1168 			}	
  1020 			}	
  1169 		}
  1021 		}
  1170 
  1022 
  1171 	test.Printf(_L("Start OTG+Host Stack\n"));
  1023 	test.Printf(_L("Start OTG+Host Stack\n"));
  1172 	OstTrace0(TRACE_NORMAL, COTGROOT_STEPLOADLDD_DUP03, "Start OTG+Host Stack\n");
       
  1173 	err = otgStartStacks();
  1024 	err = otgStartStacks();
  1174 	if (err != KErrNone)
  1025 	if (err != KErrNone)
  1175 		{
  1026 		{
  1176 		AssertionFailed2(KErrAbort, _L("Start stack failed "), err);
  1027 		AssertionFailed2(KErrAbort, _L("Start stack failed "), err);
  1177 		return (EFalse);
  1028 		return (EFalse);