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