os/kernelhwsrv/kerneltest/e32test/usbho/t_otgdi/src/otgroot.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// @internalComponent
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32std.h>
sl@0
    19
#include <e32std_private.h>
sl@0
    20
#include <u32std.h> 	// unicode builds
sl@0
    21
#include <e32base.h>
sl@0
    22
#include <e32base_private.h>
sl@0
    23
#include <e32cons.h>
sl@0
    24
#include <e32Test.h>	// RTest header
sl@0
    25
#include <e32def.h>
sl@0
    26
#include <e32def_private.h>
sl@0
    27
#include <d32otgdi.h>		// OTGDI header
sl@0
    28
#include <d32usbc.h>		// USBCC header
sl@0
    29
#include "otgroot.h"
sl@0
    30
#include "testcaseroot.h"
sl@0
    31
sl@0
    32
RUsbOtgDriver  oUsbOtgDriver;
sl@0
    33
RDevUsbcClient oUsbcClient;
sl@0
    34
sl@0
    35
sl@0
    36
//=====================================================================================
sl@0
    37
	
sl@0
    38
/*	this class wraps all OTGDI calls as well to simplify 
sl@0
    39
	 calling and normalising object access. - it has no base-class hence we can use multiple-inheritance
sl@0
    40
	 */	
sl@0
    41
	COtgRoot::COtgRoot()
sl@0
    42
	{
sl@0
    43
	iOptActive = EFalse;
sl@0
    44
	SetLoaded(EFalse);	
sl@0
    45
	}
sl@0
    46
	
sl@0
    47
	
sl@0
    48
/** otgLoadLdd
sl@0
    49
*/
sl@0
    50
TInt COtgRoot::otgLoadLdd()
sl@0
    51
	{
sl@0
    52
	
sl@0
    53
	LOG_FUNC
sl@0
    54
	LOG_VERBOSE2(_L("Load driver: %S\n"), &KOTGDeviceInterfaceDriverName);
sl@0
    55
sl@0
    56
	if (!LddLoaded())
sl@0
    57
		{
sl@0
    58
sl@0
    59
	 	// load ldd device drivers (load otg only, it will load the needed stuff for us)
sl@0
    60
		TInt err(User::LoadLogicalDevice(KOTGDeviceInterfaceDriverName));
sl@0
    61
		if ( (err != KErrNone) && (err != KErrAlreadyExists) )
sl@0
    62
			{
sl@0
    63
			test.Printf(_L("<Error %d> Unable to load driver: %S\n"), err, &KOTGDeviceInterfaceDriverName);
sl@0
    64
			SetLoaded(EFalse);
sl@0
    65
			return(err);
sl@0
    66
			}
sl@0
    67
		else
sl@0
    68
			{
sl@0
    69
			LOG_VERBOSE2(_L("Loaded driver: '%S' OK\n"), &KOTGDeviceInterfaceDriverName);
sl@0
    70
			SetLoaded(ETrue);
sl@0
    71
			}
sl@0
    72
		
sl@0
    73
		}
sl@0
    74
		return(KErrNone);
sl@0
    75
	}
sl@0
    76
sl@0
    77
sl@0
    78
/** otgOpen
sl@0
    79
*/
sl@0
    80
TInt COtgRoot::otgOpen()
sl@0
    81
	{
sl@0
    82
	LOG_FUNC
sl@0
    83
	
sl@0
    84
	LOG_VERBOSE2(_L("Opening session... loaded = %d\n"), LddLoaded());
sl@0
    85
sl@0
    86
	TInt err(oUsbOtgDriver.Open());
sl@0
    87
	if (err != KErrNone)
sl@0
    88
		{
sl@0
    89
		test.Printf(_L("<Error %d> Unable to open a channel to USB OTG driver\n"),err);
sl@0
    90
		return(err);
sl@0
    91
		}
sl@0
    92
	else
sl@0
    93
		{
sl@0
    94
		LOG_VERBOSE1(_L("Open channel OK\n"));
sl@0
    95
		}
sl@0
    96
		
sl@0
    97
	return(KErrNone);	
sl@0
    98
	}
sl@0
    99
sl@0
   100
sl@0
   101
/** otgClose
sl@0
   102
*/
sl@0
   103
void COtgRoot::otgClose()
sl@0
   104
	{
sl@0
   105
	LOG_FUNC
sl@0
   106
	
sl@0
   107
	test.Printf(_L("Closing session... loaded = %d\n"), LddLoaded());
sl@0
   108
	oUsbOtgDriver.Close();
sl@0
   109
	}
sl@0
   110
sl@0
   111
sl@0
   112
/* otgActivateOptTestMode
sl@0
   113
 */ 
sl@0
   114
TInt COtgRoot::otgActivateOptTestMode()
sl@0
   115
	{
sl@0
   116
	LOG_FUNC
sl@0
   117
sl@0
   118
	TInt err = oUsbOtgDriver.ActivateOptTestMode();
sl@0
   119
sl@0
   120
	return(err);
sl@0
   121
	}
sl@0
   122
sl@0
   123
sl@0
   124
/** otgStartStacks
sl@0
   125
*/
sl@0
   126
TInt COtgRoot::otgStartStacks()
sl@0
   127
	{
sl@0
   128
	LOG_FUNC
sl@0
   129
sl@0
   130
	TInt err(oUsbOtgDriver.StartStacks());
sl@0
   131
	if (err != KErrNone)
sl@0
   132
		{
sl@0
   133
sl@0
   134
		LOG_FUNCERROR(err)
sl@0
   135
sl@0
   136
		}
sl@0
   137
	return(err);
sl@0
   138
	
sl@0
   139
	}
sl@0
   140
sl@0
   141
sl@0
   142
/** otgStopStacks
sl@0
   143
*/ 
sl@0
   144
void COtgRoot::otgStopStacks()
sl@0
   145
	{
sl@0
   146
	LOG_FUNC
sl@0
   147
	
sl@0
   148
	oUsbOtgDriver.StopStacks();
sl@0
   149
	}
sl@0
   150
sl@0
   151
sl@0
   152
/** otgUnloadLdd
sl@0
   153
*/
sl@0
   154
void COtgRoot::otgUnloadLdd()
sl@0
   155
	{
sl@0
   156
sl@0
   157
	// code to unload the OTG ldd driver
sl@0
   158
	TInt err (User::FreeLogicalDevice(KOTGDeviceInterfaceDriverName));
sl@0
   159
	if (err != KErrNone)
sl@0
   160
		{
sl@0
   161
		LOG_FUNCERROR(err)
sl@0
   162
		}
sl@0
   163
sl@0
   164
	SetLoaded(EFalse);
sl@0
   165
	}
sl@0
   166
sl@0
   167
sl@0
   168
/** otgQueueOtgEventRequest
sl@0
   169
*/
sl@0
   170
void COtgRoot::otgQueueOtgEventRequest(RUsbOtgDriver::TOtgEvent& aEvent, TRequestStatus &aStatus)
sl@0
   171
	{
sl@0
   172
	//LOG_FUNC	
sl@0
   173
	LOG_VERBOSE2(_L("Queue an Event Request %08X.\n"), (TInt)(&aStatus));
sl@0
   174
sl@0
   175
	oUsbOtgDriver.QueueOtgEventRequest(aEvent, aStatus);
sl@0
   176
	
sl@0
   177
	}
sl@0
   178
	
sl@0
   179
sl@0
   180
/** otgCancelOtgEventRequest
sl@0
   181
*/	
sl@0
   182
void COtgRoot::otgCancelOtgEventRequest()
sl@0
   183
	{
sl@0
   184
	LOG_VERBOSE1(_L("Cancel Event Request.\n"));
sl@0
   185
	oUsbOtgDriver.CancelOtgEventRequest();
sl@0
   186
	}
sl@0
   187
    
sl@0
   188
    
sl@0
   189
/** otgQueueOtgMessageRequest
sl@0
   190
*/
sl@0
   191
void COtgRoot::otgQueueOtgMessageRequest(RUsbOtgDriver::TOtgMessage& aMessage, TRequestStatus &aStatus)
sl@0
   192
	{
sl@0
   193
	//LOG_FUNC	
sl@0
   194
	LOG_VERBOSE2(_L("Queue a Message Request %08X.\n"), (TInt)(&aStatus));
sl@0
   195
sl@0
   196
	//LOG_VERBOSE1(_L("Queue a Message Request.\n"));
sl@0
   197
	oUsbOtgDriver.QueueOtgMessageRequest(aMessage, aStatus);
sl@0
   198
		
sl@0
   199
	}
sl@0
   200
	
sl@0
   201
sl@0
   202
/** otgCancelOtgMessageRequest
sl@0
   203
*/	
sl@0
   204
void COtgRoot::otgCancelOtgMessageRequest()
sl@0
   205
	{
sl@0
   206
	LOG_VERBOSE1(_L("Cancel Message Request.\n"));
sl@0
   207
	oUsbOtgDriver.CancelOtgMessageRequest();
sl@0
   208
	}    
sl@0
   209
    
sl@0
   210
void COtgRoot::otgQueuePeripheralStateRequest(TUint& aPeripheralState, TRequestStatus& aStatus)
sl@0
   211
	{
sl@0
   212
	LOG_VERBOSE1(_L("Queue Peripheral State Request.\n"));
sl@0
   213
	oUsbcClient.AlternateDeviceStatusNotify(aStatus, aPeripheralState);
sl@0
   214
	}
sl@0
   215
sl@0
   216
void COtgRoot::otgCancelPeripheralStateRequest()
sl@0
   217
	{
sl@0
   218
	LOG_VERBOSE1(_L("Cancel Peripheral State Request.\n"));
sl@0
   219
	oUsbcClient.AlternateDeviceStatusNotifyCancel();	
sl@0
   220
	}
sl@0
   221
sl@0
   222
void COtgRoot::otgQueueAConnectionIdleRequest(RUsbOtgDriver::TOtgConnection& aAConnectionIdle, TRequestStatus& aStatus)
sl@0
   223
	{
sl@0
   224
	LOG_VERBOSE1(_L("Queue A Connection Idle Request.\n"));
sl@0
   225
	oUsbOtgDriver.QueueOtgConnectionNotification(aAConnectionIdle, aStatus);
sl@0
   226
	}
sl@0
   227
sl@0
   228
void COtgRoot::otgCancelAConnectionIdleRequest()
sl@0
   229
	{
sl@0
   230
	LOG_VERBOSE1(_L("Cancel A Connection Idle Request.\n"));
sl@0
   231
	oUsbOtgDriver.CancelOtgConnectionNotification();
sl@0
   232
	}
sl@0
   233
sl@0
   234
sl@0
   235
/** otgQueueOtgStateRequest
sl@0
   236
*/
sl@0
   237
void COtgRoot::otgQueueOtgStateRequest(RUsbOtgDriver::TOtgState& aState, TRequestStatus &aStatus)
sl@0
   238
	{
sl@0
   239
	//LOG_FUNC	
sl@0
   240
	LOG_VERBOSE2(_L("Queue a State Request %08X.\n"), (TInt)(&aStatus));
sl@0
   241
sl@0
   242
	oUsbOtgDriver.QueueOtgStateRequest(aState, aStatus);
sl@0
   243
	
sl@0
   244
	}
sl@0
   245
	
sl@0
   246
sl@0
   247
/** otgCancelOtgStateRequest
sl@0
   248
*/	
sl@0
   249
void COtgRoot::otgCancelOtgStateRequest()
sl@0
   250
	{
sl@0
   251
	LOG_VERBOSE1(_L("Cancel State Request.\n"));
sl@0
   252
	oUsbOtgDriver.CancelOtgStateRequest();
sl@0
   253
	}
sl@0
   254
sl@0
   255
    
sl@0
   256
/** otgBusRequest
sl@0
   257
raise VBus (in reality this must only happen when a 'A' is present... and when not present it starts HNP)
sl@0
   258
*/
sl@0
   259
TInt COtgRoot::otgBusRequest()
sl@0
   260
	{
sl@0
   261
	LOG_FUNC
sl@0
   262
	
sl@0
   263
	TInt err(0);
sl@0
   264
	err = oUsbOtgDriver.BusRequest();
sl@0
   265
	if (err != KErrNone)
sl@0
   266
		{
sl@0
   267
		LOG_FUNCERROR(err)
sl@0
   268
		}
sl@0
   269
	return(err);
sl@0
   270
	}
sl@0
   271
	
sl@0
   272
sl@0
   273
/* call when SRP has been recieved, based on our HNP Enable setting, this will allow HNP. The 
sl@0
   274
 * A-device may choose to call BusRequest directly, which will result in a 'short-circuit' role-swap.
sl@0
   275
 */
sl@0
   276
TInt COtgRoot::otgBusRespondSRP()
sl@0
   277
	{
sl@0
   278
	LOG_FUNC
sl@0
   279
	TInt err(0);
sl@0
   280
		err = oUsbOtgDriver.BusRespondSrp();
sl@0
   281
		if (err != KErrNone)
sl@0
   282
			{
sl@0
   283
			LOG_FUNCERROR(err)
sl@0
   284
			}
sl@0
   285
		return(err);
sl@0
   286
	}
sl@0
   287
sl@0
   288
	
sl@0
   289
/** Drop VBus (A-host)
sl@0
   290
*/	
sl@0
   291
TInt COtgRoot::otgBusDrop()
sl@0
   292
	{
sl@0
   293
	LOG_FUNC
sl@0
   294
	TInt err(0);
sl@0
   295
	err = oUsbOtgDriver.BusDrop();
sl@0
   296
	if (err != KErrNone)
sl@0
   297
		{
sl@0
   298
		LOG_FUNCERROR(err)
sl@0
   299
		}
sl@0
   300
	return(err);
sl@0
   301
	}
sl@0
   302
sl@0
   303
/** otgBusClearError
sl@0
   304
*/
sl@0
   305
TInt COtgRoot::otgBusClearError()
sl@0
   306
	{
sl@0
   307
	LOG_FUNC
sl@0
   308
	
sl@0
   309
	TInt err(0);
sl@0
   310
	err = oUsbOtgDriver.BusClearError();
sl@0
   311
	if (err != KErrNone)
sl@0
   312
		{
sl@0
   313
		LOG_FUNCERROR(err)
sl@0
   314
		}
sl@0
   315
	return(err);
sl@0
   316
	}
sl@0
   317
	
sl@0
   318
sl@0
   319
	
sl@0
   320
void COtgRoot::otgQueueOtgIdPinNotification(RUsbOtgDriver::TOtgIdPin& aPin, TRequestStatus& aStatus)
sl@0
   321
	{
sl@0
   322
	LOG_FUNC
sl@0
   323
	oUsbOtgDriver.QueueOtgIdPinNotification(aPin, aStatus);	// the kernel driver populates aPin...
sl@0
   324
	}
sl@0
   325
sl@0
   326
	
sl@0
   327
void COtgRoot::otgCancelOtgIdPinNotification()
sl@0
   328
	{
sl@0
   329
	LOG_FUNC
sl@0
   330
	oUsbOtgDriver.CancelOtgIdPinNotification();
sl@0
   331
	}
sl@0
   332
sl@0
   333
sl@0
   334
void COtgRoot::otgQueueOtgVbusNotification(RUsbOtgDriver::TOtgVbus& aVbus, 
sl@0
   335
                                                TRequestStatus& aStatus
sl@0
   336
                                               )
sl@0
   337
	{
sl@0
   338
	LOG_FUNC
sl@0
   339
	oUsbOtgDriver.QueueOtgVbusNotification(aVbus, aStatus);
sl@0
   340
	}
sl@0
   341
	
sl@0
   342
	
sl@0
   343
void COtgRoot::otgCancelOtgVbusNotification()
sl@0
   344
	{
sl@0
   345
	LOG_FUNC
sl@0
   346
	oUsbOtgDriver.CancelOtgVbusNotification();
sl@0
   347
	}
sl@0
   348
sl@0
   349
sl@0
   350
TBool COtgRoot::otgIdPinPresent()
sl@0
   351
	{
sl@0
   352
	LOG_FUNC
sl@0
   353
	TRequestStatus aStatus;
sl@0
   354
	RUsbOtgDriver::TOtgIdPin aPin;
sl@0
   355
	oUsbOtgDriver.QueueOtgIdPinNotification(aPin, aStatus);	// the kernel driver populates aPin...
sl@0
   356
	LOG_VERBOSE2(_L("(sync) ID_PIN=%d\n"), iOTGIdPin);
sl@0
   357
	
sl@0
   358
	oUsbOtgDriver.CancelOtgIdPinNotification();
sl@0
   359
	// swallow the event
sl@0
   360
	User::WaitForRequest(aStatus);
sl@0
   361
	
sl@0
   362
	if (RUsbOtgDriver::EIdPinAPlug == aPin)			// at this stage, the aPin value is known
sl@0
   363
		{
sl@0
   364
		return(ETrue);
sl@0
   365
		}
sl@0
   366
	return(EFalse);
sl@0
   367
	}
sl@0
   368
	
sl@0
   369
	
sl@0
   370
TBool COtgRoot::otgVbusPresent()
sl@0
   371
	{
sl@0
   372
	LOG_FUNC
sl@0
   373
	TRequestStatus aStatus;
sl@0
   374
 	RUsbOtgDriver::TOtgVbus aVBus;
sl@0
   375
	oUsbOtgDriver.QueueOtgVbusNotification(aVBus, aStatus);	// the kernel driver populates aPin in a kernel thread...
sl@0
   376
	oUsbOtgDriver.CancelOtgVbusNotification();
sl@0
   377
	// swallow the event
sl@0
   378
	User::WaitForRequest(aStatus);
sl@0
   379
sl@0
   380
	if (RUsbOtgDriver::EVbusHigh == aVBus)			// by this stage, the aVBus value is known
sl@0
   381
		{
sl@0
   382
		return(ETrue);
sl@0
   383
		}
sl@0
   384
	return(EFalse);
sl@0
   385
	}
sl@0
   386
sl@0
   387
sl@0
   388
TBool COtgRoot::iLoadedLdd = EFalse;
sl@0
   389
TBool COtgRoot::iFdfActorActive = EFalse;
sl@0
   390
RProcess COtgRoot::iFdfActorProcess;
sl@0
   391
sl@0
   392
/** static */
sl@0
   393
TBool& COtgRoot::LddLoaded()
sl@0
   394
	{ 
sl@0
   395
	return(iLoadedLdd);
sl@0
   396
	}
sl@0
   397
sl@0
   398
sl@0
   399
/** static */
sl@0
   400
TBool COtgRoot::SetLoaded(TBool aState) 
sl@0
   401
	{ 
sl@0
   402
	iLoadedLdd = aState; 
sl@0
   403
	return(LddLoaded());
sl@0
   404
	}
sl@0
   405
sl@0
   406
/** static */
sl@0
   407
void COtgRoot::OtgEventString( RUsbOtgDriver::TOtgEvent aEvent, TBuf<MAX_DSTRLEN> &aDescription)
sl@0
   408
	{
sl@0
   409
sl@0
   410
	switch( aEvent )
sl@0
   411
		{
sl@0
   412
		case RUsbOtgDriver::EEventAPlugInserted:		aDescription= _L("A Plug Inserted");break;
sl@0
   413
		case RUsbOtgDriver::EEventAPlugRemoved:			aDescription= _L("A Plug Removed");	break;
sl@0
   414
		case RUsbOtgDriver::EEventVbusRaised:			aDescription= _L("VBUS Raised");	break;
sl@0
   415
		case RUsbOtgDriver::EEventVbusDropped:			aDescription= _L("VBUS Dropped");	break;
sl@0
   416
		case RUsbOtgDriver::EEventSrpReceived:			aDescription= _L("SRP Received");	break;
sl@0
   417
		case RUsbOtgDriver::EEventSrpInitiated:			aDescription= _L("SRP Initiated");	break;
sl@0
   418
		case RUsbOtgDriver::EEventHnpEnabled:			aDescription= _L("HNP Enabled");	break;
sl@0
   419
		case RUsbOtgDriver::EEventHnpDisabled:			aDescription= _L("HNP Disabled");	break;
sl@0
   420
		case RUsbOtgDriver::EEventRoleChangedToHost:	aDescription= _L("Role->Host");		break;
sl@0
   421
		case RUsbOtgDriver::EEventRoleChangedToDevice:	aDescription= _L("Role->Device");	break;
sl@0
   422
		case RUsbOtgDriver::EEventRoleChangedToIdle:	aDescription= _L("Role->Idle");		break;
sl@0
   423
		
sl@0
   424
		case RUsbOtgDriver::EEventHnpSupported : 		aDescription= _L("HNP Supported");		break;
sl@0
   425
		case RUsbOtgDriver::EEventHnpAltSupported:		aDescription= _L("Alt-HNP Supp.");		break;
sl@0
   426
		case RUsbOtgDriver::EEventBusConnectionBusy:	aDescription= _L("Connection Busy");	break;
sl@0
   427
		case RUsbOtgDriver::EEventBusConnectionIdle:	aDescription= _L("Connection Idle");	break;
sl@0
   428
		default:										aDescription= _L("Unknown");		break;
sl@0
   429
		}
sl@0
   430
	}
sl@0
   431
sl@0
   432
/** static */
sl@0
   433
void COtgRoot::OtgStateString( RUsbOtgDriver::TOtgState aState, TBuf<MAX_DSTRLEN> &aDescription)
sl@0
   434
	{
sl@0
   435
sl@0
   436
	switch( aState )
sl@0
   437
		{
sl@0
   438
		case RUsbOtgDriver::EStateReset:		aDescription= _L("Reset");			break;
sl@0
   439
		case RUsbOtgDriver::EStateAIdle:		aDescription= _L("A-Idle");			break;
sl@0
   440
		case RUsbOtgDriver::EStateAHost:		aDescription= _L("A-Host");			break;
sl@0
   441
		case RUsbOtgDriver::EStateAPeripheral:	aDescription= _L("A-Peripheral");	break;
sl@0
   442
		case RUsbOtgDriver::EStateAVbusError:   aDescription= _L("A-VBus Error");	break;
sl@0
   443
		case RUsbOtgDriver::EStateBIdle:		aDescription= _L("B-Idle");			break;
sl@0
   444
		case RUsbOtgDriver::EStateBPeripheral:	aDescription= _L("B-Peripheral");	break;
sl@0
   445
		case RUsbOtgDriver::EStateBHost:		aDescription= _L("B-Host");			break;
sl@0
   446
		default:								aDescription= _L("Unknown");		break;
sl@0
   447
		}
sl@0
   448
	}
sl@0
   449
sl@0
   450
/** static */
sl@0
   451
void COtgRoot::OtgMessageString( RUsbOtgDriver::TOtgMessage aMessage, TBuf<MAX_DSTRLEN> &aDescription)
sl@0
   452
	{
sl@0
   453
sl@0
   454
	switch( aMessage )
sl@0
   455
		{
sl@0
   456
		case RUsbOtgDriver::EEventQueueOverflow:			aDescription = _L("Event Queue Overflow");		break;
sl@0
   457
		case RUsbOtgDriver::EStateQueueOverflow:			aDescription = _L("State Queue Overflow");		break;
sl@0
   458
		case RUsbOtgDriver::EMessageQueueOverflow:			aDescription = _L("Message Queue Overflow");	break;
sl@0
   459
		case RUsbOtgDriver::EMessageBadState:				aDescription = _L("Bad State");					break;
sl@0
   460
		case RUsbOtgDriver::EMessageStackNotStarted:		aDescription = _L("Stack Not Started");			break;
sl@0
   461
		case RUsbOtgDriver::EMessageVbusAlreadyRaised:		aDescription = _L("Vbus Already Raised");		break;
sl@0
   462
		case RUsbOtgDriver::EMessageSrpForbidden:			aDescription = _L("SRP Forbidden");				break;
sl@0
   463
		case RUsbOtgDriver::EMessageBusControlProblem:		aDescription = _L("Bus Control Problem");		break;
sl@0
   464
		case RUsbOtgDriver::EMessageVbusError:				aDescription = _L("Vbus Error");				break;
sl@0
   465
		case RUsbOtgDriver::EMessageSrpTimeout:				aDescription = _L("SRP Timeout");				break;
sl@0
   466
		case RUsbOtgDriver::EMessageSrpActive:				aDescription = _L("SRP In Use");				break;
sl@0
   467
		// PREQ 1305 messages
sl@0
   468
		case RUsbOtgDriver::EMessageSrpNotPermitted:		aDescription = _L("Srp Not Permitted"); break;
sl@0
   469
		case RUsbOtgDriver::EMessageHnpNotPermitted:		aDescription = _L("Hnp Not Permitted"); break;
sl@0
   470
		case RUsbOtgDriver::EMessageHnpNotEnabled:			aDescription = _L("Hnp Not Enabled"); break;
sl@0
   471
		case RUsbOtgDriver::EMessageHnpNotSuspended: 			aDescription = _L("HNP not possible, not suspended"); break;
sl@0
   472
		case RUsbOtgDriver::EMessageVbusPowerUpNotPermitted:	aDescription = _L("Vbus PowerUp Not Permitted"); break;
sl@0
   473
		case RUsbOtgDriver::EMessageVbusPowerUpError:			aDescription = _L("Vbus PowerUp Error"); break;
sl@0
   474
		case RUsbOtgDriver::EMessageVbusPowerDownNotPermitted:	aDescription = _L("Vbus PowerDown Not Permitted"); break;
sl@0
   475
		case RUsbOtgDriver::EMessageVbusClearErrorNotPermitted:	aDescription = _L("Vbus ClearError Not Permitted"); break;
sl@0
   476
		case RUsbOtgDriver::EMessageHnpNotResponding:		aDescription = _L("Not reposnding to HNP");
sl@0
   477
		case RUsbOtgDriver::EMessageHnpBusDrop:				aDescription = _L("VBUS drop during HNP");
sl@0
   478
		default:												aDescription = _L("Unknown");					break;
sl@0
   479
		}
sl@0
   480
	}
sl@0
   481
sl@0
   482
void COtgRoot::PeripheralStateString( TUint aPeripheralState, TBuf<MAX_DSTRLEN> &aDescription)
sl@0
   483
	{
sl@0
   484
	if(aPeripheralState & KUsbAlternateSetting)
sl@0
   485
		{
sl@0
   486
		aDescription = _L("Interface Alternate Setting Change");
sl@0
   487
		}
sl@0
   488
	else
sl@0
   489
		{
sl@0
   490
		switch( aPeripheralState )
sl@0
   491
			{
sl@0
   492
			case EUsbcDeviceStateUndefined:		aDescription = _L("Undefined");			break;
sl@0
   493
			case EUsbcDeviceStateAttached:		aDescription = _L("Attached");			break;
sl@0
   494
			case EUsbcDeviceStatePowered:		aDescription = _L("Powered");			break;
sl@0
   495
			case EUsbcDeviceStateDefault:		aDescription = _L("Default");			break;
sl@0
   496
			case EUsbcDeviceStateAddress:		aDescription = _L("Addressed");			break;
sl@0
   497
			case EUsbcDeviceStateConfigured:	aDescription = _L("Configured");		break;
sl@0
   498
			case EUsbcDeviceStateSuspended:		aDescription = _L("Suspended");			break;
sl@0
   499
			case EUsbcNoState:					aDescription = _L("NoState!");			break;
sl@0
   500
			default:							aDescription = _L("Unknown");			break;
sl@0
   501
			}
sl@0
   502
		}
sl@0
   503
	}
sl@0
   504
	
sl@0
   505
void COtgRoot::AConnectionIdleString(RUsbOtgDriver::TOtgConnection aAConnectionIdle, TBuf<MAX_DSTRLEN> &aDescription)
sl@0
   506
	{
sl@0
   507
	switch( aAConnectionIdle )
sl@0
   508
		{
sl@0
   509
		case RUsbOtgDriver::EConnectionBusy:		aDescription = _L("Busy");			break;
sl@0
   510
		case RUsbOtgDriver::EConnectionIdle:		aDescription = _L("Idle");			break;
sl@0
   511
		case RUsbOtgDriver::EConnectionUnknown:		aDescription = _L("Unknown");		break;
sl@0
   512
		default:									aDescription = _L("Not recognised");break;
sl@0
   513
		}
sl@0
   514
	}
sl@0
   515
sl@0
   516
TInt COtgRoot::otgActivateFdfActor()
sl@0
   517
	{
sl@0
   518
	if(iFdfActorActive)
sl@0
   519
		{
sl@0
   520
		RDebug::Print(_L("FdfActor already exists!"));
sl@0
   521
		return KErrAlreadyExists;
sl@0
   522
		}
sl@0
   523
		
sl@0
   524
	const TUid KFdfSvrUid={0x10282B48};
sl@0
   525
	const TUidType fdfActorUid(KNullUid, KNullUid, KFdfSvrUid);
sl@0
   526
sl@0
   527
	RDebug::Print(_L("About to activate FDF Actor"));
sl@0
   528
sl@0
   529
//	RProcess fdfActorProcess;
sl@0
   530
	TInt err = iFdfActorProcess.Create(_L("t_otgdi_fdfactor.exe"), KNullDesC, fdfActorUid);
sl@0
   531
	
sl@0
   532
	if (err != KErrNone)
sl@0
   533
		{
sl@0
   534
		RDebug::Print(_L("Failed to create FDF Actor, err=%d"),err);
sl@0
   535
		iFdfActorProcess.Close();
sl@0
   536
		return err;
sl@0
   537
		}
sl@0
   538
sl@0
   539
	TRequestStatus stat;
sl@0
   540
	iFdfActorProcess.Rendezvous(stat);
sl@0
   541
	
sl@0
   542
	if (stat!=KRequestPending)
sl@0
   543
		{
sl@0
   544
		RDebug::Print(_L("Failed to commence rendezvous, err=%d"),stat.Int());
sl@0
   545
		iFdfActorProcess.Kill(0);		// abort startup
sl@0
   546
		iFdfActorProcess.Close();
sl@0
   547
		return stat.Int();
sl@0
   548
		}
sl@0
   549
	else
sl@0
   550
		{
sl@0
   551
		iFdfActorProcess.Resume();	// logon OK - start the server
sl@0
   552
		}
sl@0
   553
sl@0
   554
	User::WaitForRequest(stat);		// wait for start or death
sl@0
   555
	if(stat.Int()!=KErrNone)
sl@0
   556
		{
sl@0
   557
		//	Wasn't KErrNone, which means that the FDFActor didn't successfully
sl@0
   558
		//	start up. We shouldn't proceed with the test we're in.
sl@0
   559
		RDebug::Print(_L("Failed to activate FDF Actor, err=%d"),stat.Int());
sl@0
   560
		iFdfActorProcess.Close();
sl@0
   561
		return stat.Int();
sl@0
   562
		}
sl@0
   563
	
sl@0
   564
	//	We rendezvoused(?) with the FDFActor OK, so it is going to suspend
sl@0
   565
	//	any devices it sees being attached, and will shut itself down
sl@0
   566
	//	when this process signals its Rendezvous (at the end of the test)...
sl@0
   567
	RDebug::Print(_L("Activated FDF Actor"));
sl@0
   568
	iFdfActorActive = ETrue;
sl@0
   569
sl@0
   570
	return KErrNone;
sl@0
   571
	}
sl@0
   572
sl@0
   573
void COtgRoot::otgDeactivateFdfActor()
sl@0
   574
	{
sl@0
   575
	if(!iFdfActorActive)
sl@0
   576
		{
sl@0
   577
		RDebug::Print(_L("FdfActor is not running!"));
sl@0
   578
		return;
sl@0
   579
		}
sl@0
   580
sl@0
   581
	//	If iFdfActorActive is set, the FDF Actor should be waiting to
sl@0
   582
	//	rendezvous with us before it shuts down...
sl@0
   583
	//	First of all, logon to wait for it to close down properly
sl@0
   584
	TRequestStatus waitForCloseStat;
sl@0
   585
	iFdfActorProcess.Logon(waitForCloseStat);
sl@0
   586
	
sl@0
   587
	//	Now, trigger the FDF Actor to close down
sl@0
   588
sl@0
   589
	RProcess::Rendezvous(KErrNone);
sl@0
   590
	
sl@0
   591
	//	...and wait for it to go away.
sl@0
   592
	User::WaitForRequest(waitForCloseStat);
sl@0
   593
	test.Printf(_L("T_OTGDI confirms FDF Actor has gone away %d\n"), waitForCloseStat.Int());
sl@0
   594
	
sl@0
   595
	//	Now close our handle, and record that the process is no more...
sl@0
   596
	iFdfActorProcess.Close();
sl@0
   597
	iFdfActorActive = EFalse;
sl@0
   598
	}
sl@0
   599
	
sl@0
   600
/** Commonly used step to unload the USB Client Driver
sl@0
   601
* @return ETrue if the ldd unloaded sucessfully
sl@0
   602
*/
sl@0
   603
TBool COtgRoot::StepUnloadClient()
sl@0
   604
	{
sl@0
   605
	test.Printf(_L("Unload USBCC Client\n"));
sl@0
   606
sl@0
   607
	TInt err;
sl@0
   608
sl@0
   609
	// Close the Client
sl@0
   610
sl@0
   611
	test.Printf(_L("..Close\n"));
sl@0
   612
	oUsbcClient.Close();
sl@0
   613
sl@0
   614
	// Unload the LDD - note the name is *not* the same as for loading
sl@0
   615
sl@0
   616
	test.Printf(_L("..Unload\n"));
sl@0
   617
	err = User::FreeLogicalDevice( KUsbDeviceName );
sl@0
   618
	if (err != KErrNone)
sl@0
   619
		{
sl@0
   620
		AssertionFailed2(KErrAbort, _L("Client Unload Fail "), err);
sl@0
   621
		return (EFalse);
sl@0
   622
		}
sl@0
   623
sl@0
   624
sl@0
   625
	return(ETrue);
sl@0
   626
	}
sl@0
   627
sl@0
   628
sl@0
   629
/** Commonly used step to load the USB Client Driver and set up
sl@0
   630
 *	a 'useful' default device descriptor set
sl@0
   631
 * @return ETrue if the ldd loaded sucessfully
sl@0
   632
 */
sl@0
   633
TBool COtgRoot::StepLoadClient(TUint16 aPID, 
sl@0
   634
								TBool aEnableHNP/*=ETrue*/, 
sl@0
   635
								TBool aEnableSRP/*=ETrue*/)
sl@0
   636
	{
sl@0
   637
	test.Printf(_L("Load USBCC Client 0x%04x\n"),aPID);
sl@0
   638
sl@0
   639
	TInt err;
sl@0
   640
sl@0
   641
	// The incoming PID is expected to have a form of 0x0TTT or 0xFTTT
sl@0
   642
	// where 'TTT' is the test number: if the lead is 0xF000 we now 
sl@0
   643
	// overlay an 'A' or a 'B' depending on the default role
sl@0
   644
	
sl@0
   645
	if (   ( ( aPID & 0xF000 ) != 0xF000 )
sl@0
   646
		&& ( ( aPID & 0xF000 ) != 0x0000 )
sl@0
   647
	   )
sl@0
   648
		{
sl@0
   649
		AssertionFailed(KErrAbort, _L("Bad default PID"));
sl@0
   650
		}
sl@0
   651
		
sl@0
   652
	if ( aPID & 0xF000 )
sl@0
   653
		{
sl@0
   654
		aPID &= 0x0FFF;
sl@0
   655
		
sl@0
   656
		if ( gTestRoleMaster )
sl@0
   657
			{
sl@0
   658
			// this is the 'B' device
sl@0
   659
			aPID |= 0xB000;
sl@0
   660
			}
sl@0
   661
		else
sl@0
   662
			{
sl@0
   663
			// this is the 'A' device
sl@0
   664
			aPID |= 0xA000;
sl@0
   665
			}
sl@0
   666
		}
sl@0
   667
	
sl@0
   668
	// Load the LDD - note the name is *not* the same as for unload
sl@0
   669
sl@0
   670
	test.Printf(_L("..Load LDD\n"));
sl@0
   671
	err = User::LoadLogicalDevice( KUsbcLddFileName );
sl@0
   672
	if ((err != KErrNone) && (err !=KErrAlreadyExists))
sl@0
   673
		{
sl@0
   674
		AssertionFailed2(KErrAbort, _L("Client Load Fail "), err);
sl@0
   675
		return (EFalse);
sl@0
   676
		}
sl@0
   677
sl@0
   678
	// Open the Client
sl@0
   679
sl@0
   680
	test.Printf(_L("..Open LDD\n"));
sl@0
   681
	err = oUsbcClient.Open(0);
sl@0
   682
	if (err != KErrNone)
sl@0
   683
		{
sl@0
   684
		AssertionFailed2(KErrAbort, _L("Client Open Fail "), err);
sl@0
   685
		return (EFalse);
sl@0
   686
		}
sl@0
   687
sl@0
   688
	// Set up descriptors
sl@0
   689
	
sl@0
   690
	test.Printf(_L("..Setup Descriptors\n"));
sl@0
   691
sl@0
   692
	// the OTG descriptor
sl@0
   693
	TBuf8<KUsbDescSize_Otg> theOtgDescriptor;
sl@0
   694
	err = oUsbcClient.GetOtgDescriptor(theOtgDescriptor);
sl@0
   695
	if (err != KErrNone)
sl@0
   696
		{
sl@0
   697
		AssertionFailed2(KErrAbort, _L("OTG GetDes Fail "), err);
sl@0
   698
		return (EFalse);
sl@0
   699
		}
sl@0
   700
	// modify OTG descriptor based on parameters passed
sl@0
   701
	if (aEnableHNP)
sl@0
   702
		aEnableSRP=ETrue;	// Keep the device Legal according to OTG spec 6.4.2
sl@0
   703
	/*Attribute Fields
sl@0
   704
	  D7…2: Reserved (reset to zero)
sl@0
   705
	  D1: HNP support
sl@0
   706
	  D0: SRP support*/
sl@0
   707
	TUint8 aByte = theOtgDescriptor[2];
sl@0
   708
		aByte &= (~0x03);
sl@0
   709
		aByte |= (aEnableSRP? 1 : 0); 
sl@0
   710
		aByte |= (aEnableHNP? 2 : 0); 
sl@0
   711
	test.Printf(_L("..Change OTG 0x%02X->0x%02X\n"), theOtgDescriptor[2], aByte);
sl@0
   712
	theOtgDescriptor[2] = aByte;
sl@0
   713
	
sl@0
   714
	err = oUsbcClient.SetOtgDescriptor(theOtgDescriptor);
sl@0
   715
	if (err != KErrNone)
sl@0
   716
		{
sl@0
   717
		AssertionFailed2(KErrAbort, _L("OTG SetDes Fail "), err);
sl@0
   718
		return (EFalse);
sl@0
   719
		}
sl@0
   720
	
sl@0
   721
	//
sl@0
   722
sl@0
   723
	TUsbDeviceCaps d_caps;
sl@0
   724
	err = oUsbcClient.DeviceCaps(d_caps);
sl@0
   725
	TBool softwareConnect;
sl@0
   726
sl@0
   727
	if (err != KErrNone)
sl@0
   728
		{
sl@0
   729
		AssertionFailed2(KErrAbort, _L("Client DevCaps Fail "), err);
sl@0
   730
		return (EFalse);
sl@0
   731
		}
sl@0
   732
sl@0
   733
	const TInt n = d_caps().iTotalEndpoints;
sl@0
   734
sl@0
   735
	softwareConnect = d_caps().iConnect;
sl@0
   736
	test.Printf(_L("..SoftwareConnect = %d\n"),softwareConnect);
sl@0
   737
sl@0
   738
	if (n < 2)
sl@0
   739
		{
sl@0
   740
		AssertionFailed2(KErrAbort, _L("Client Endpoints Fail "), err);
sl@0
   741
		return (EFalse);
sl@0
   742
		}
sl@0
   743
sl@0
   744
	// Endpoints
sl@0
   745
	TUsbcEndpointData data[KUsbcMaxEndpoints];
sl@0
   746
	TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
sl@0
   747
	err = oUsbcClient.EndpointCaps(dataptr);
sl@0
   748
	if (err != KErrNone)
sl@0
   749
		{
sl@0
   750
		AssertionFailed2(KErrAbort, _L("Client EpCaps Fail "), err);
sl@0
   751
		return (EFalse);
sl@0
   752
		}
sl@0
   753
sl@0
   754
	// Set up the active interface
sl@0
   755
	TUsbcInterfaceInfoBuf ifc;
sl@0
   756
	TInt ep_found = 0;
sl@0
   757
	TBool foundBulkIN = EFalse;
sl@0
   758
	TBool foundBulkOUT = EFalse;
sl@0
   759
	for (TInt i = 0; i < n; i++)
sl@0
   760
		{
sl@0
   761
		const TUsbcEndpointCaps* const caps = &data[i].iCaps;
sl@0
   762
		const TInt mps = caps->MaxPacketSize();
sl@0
   763
		if (!foundBulkIN &&
sl@0
   764
			(caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirIn)) ==
sl@0
   765
			(KUsbEpTypeBulk | KUsbEpDirIn))
sl@0
   766
			{
sl@0
   767
			if (!(mps == 64 || mps == 512))
sl@0
   768
				{
sl@0
   769
				}
sl@0
   770
			// EEndpoint1 is going to be our Tx (IN) endpoint
sl@0
   771
			ifc().iEndpointData[0].iType = KUsbEpTypeBulk;
sl@0
   772
			ifc().iEndpointData[0].iDir	 = KUsbEpDirIn;
sl@0
   773
			ifc().iEndpointData[0].iSize = mps;
sl@0
   774
			foundBulkIN = ETrue;
sl@0
   775
			if (++ep_found == 2)
sl@0
   776
				break;
sl@0
   777
			}
sl@0
   778
		else if (!foundBulkOUT &&
sl@0
   779
			(caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirOut)) ==
sl@0
   780
			(KUsbEpTypeBulk | KUsbEpDirOut))
sl@0
   781
			{
sl@0
   782
			if (!(mps == 64 || mps == 512))
sl@0
   783
				{
sl@0
   784
				}
sl@0
   785
			// EEndpoint2 is going to be our Rx (OUT) endpoint
sl@0
   786
			ifc().iEndpointData[1].iType = KUsbEpTypeBulk;
sl@0
   787
			ifc().iEndpointData[1].iDir	 = KUsbEpDirOut;
sl@0
   788
			ifc().iEndpointData[1].iSize = mps;
sl@0
   789
			foundBulkOUT = ETrue;
sl@0
   790
			if (++ep_found == 2)
sl@0
   791
				break;
sl@0
   792
			}
sl@0
   793
		}
sl@0
   794
	if (ep_found != 2)
sl@0
   795
		{
sl@0
   796
		AssertionFailed2(KErrAbort, _L("Client EpFound Fail "), err);
sl@0
   797
		return (EFalse);
sl@0
   798
		}
sl@0
   799
sl@0
   800
	_LIT16(ifcname, "T_OTGDI Test Interface (Default Setting 0)");
sl@0
   801
	ifc().iString = const_cast<TDesC16*>(&ifcname);
sl@0
   802
	ifc().iTotalEndpointsUsed = 2;
sl@0
   803
	ifc().iClass.iClassNum	  = 0xff;						// vendor-specific
sl@0
   804
	ifc().iClass.iSubClassNum = 0xff;						// vendor-specific
sl@0
   805
	ifc().iClass.iProtocolNum = 0xff;						// vendor-specific
sl@0
   806
sl@0
   807
	err = oUsbcClient.SetInterface(0, ifc, (EUsbcBandwidthOUTDefault | EUsbcBandwidthINDefault));
sl@0
   808
sl@0
   809
	if( err != KErrNone )
sl@0
   810
		{
sl@0
   811
		AssertionFailed2(KErrAbort, _L("Client SetInt Fail "), err);
sl@0
   812
		return (EFalse);
sl@0
   813
		}
sl@0
   814
	
sl@0
   815
	// Set the revised PID
sl@0
   816
	
sl@0
   817
	TBuf8<KUsbDescSize_Device> theDeviceDescriptor;
sl@0
   818
	err = oUsbcClient.GetDeviceDescriptor(theDeviceDescriptor);
sl@0
   819
	if (err != KErrNone)
sl@0
   820
		{
sl@0
   821
		AssertionFailed2(KErrAbort, _L("Client GetDes Fail "), err);
sl@0
   822
		return (EFalse);
sl@0
   823
		}
sl@0
   824
sl@0
   825
	TUint16 oldPID = ( theDeviceDescriptor[10] )
sl@0
   826
		           + ( theDeviceDescriptor[11] << 8 );
sl@0
   827
sl@0
   828
	theDeviceDescriptor[10] = ( aPID & 0x00FF );
sl@0
   829
	theDeviceDescriptor[11] = ( aPID & 0xFF00 ) >> 8;
sl@0
   830
sl@0
   831
	test.Printf(_L("..Change PID 0x%04X->0x%04X\n"), oldPID, aPID);
sl@0
   832
sl@0
   833
	err = oUsbcClient.SetDeviceDescriptor(theDeviceDescriptor);
sl@0
   834
	if (err != KErrNone)
sl@0
   835
		{
sl@0
   836
		AssertionFailed2(KErrAbort, _L("Client SetDes Fail "), err);
sl@0
   837
		return (EFalse);
sl@0
   838
		}
sl@0
   839
sl@0
   840
sl@0
   841
	// Power Up UDC - KErrNotReady is expected
sl@0
   842
sl@0
   843
	test.Printf(_L("..Power Up UDC\n"));
sl@0
   844
sl@0
   845
	err = oUsbcClient.PowerUpUdc();
sl@0
   846
	if( err != KErrNotReady )
sl@0
   847
		{
sl@0
   848
		AssertionFailed2(KErrAbort, _L("PowerUp UDC Fail "), err);
sl@0
   849
		return (EFalse);
sl@0
   850
		}
sl@0
   851
sl@0
   852
	// Connect to Host
sl@0
   853
sl@0
   854
	test.Printf(_L("..Connect to Host\n"));
sl@0
   855
sl@0
   856
	err = oUsbcClient.DeviceConnectToHost();
sl@0
   857
	if( err != KErrNone )
sl@0
   858
		{
sl@0
   859
		AssertionFailed2(KErrAbort, _L("Host Connect Fail "), err);
sl@0
   860
		return (EFalse);
sl@0
   861
		}
sl@0
   862
sl@0
   863
	// Default no-problem return
sl@0
   864
sl@0
   865
	return(ETrue);
sl@0
   866
	}
sl@0
   867
sl@0
   868
sl@0
   869
/** Commonly used steps to control D+ connect/disconnect
sl@0
   870
 *  the device to/from the host
sl@0
   871
 */
sl@0
   872
TBool COtgRoot::StepDisconnect()
sl@0
   873
	{
sl@0
   874
	test.Printf(_L("Disconnect from Host\n"));
sl@0
   875
sl@0
   876
	TInt err;
sl@0
   877
	
sl@0
   878
	err = oUsbcClient.DeviceDisconnectFromHost();
sl@0
   879
	if( err != KErrNone )
sl@0
   880
		{
sl@0
   881
		AssertionFailed2(KErrAbort, _L("Host Disconnect Fail "), err);
sl@0
   882
		return (EFalse);
sl@0
   883
		}
sl@0
   884
sl@0
   885
	// Default no-problem return
sl@0
   886
sl@0
   887
	return(ETrue);
sl@0
   888
	}
sl@0
   889
sl@0
   890
TBool COtgRoot::StepConnect()
sl@0
   891
	{
sl@0
   892
	test.Printf(_L("Connect to Host\n"));
sl@0
   893
sl@0
   894
	TInt err;
sl@0
   895
	
sl@0
   896
	err = oUsbcClient.DeviceConnectToHost();
sl@0
   897
	if( err != KErrNone )
sl@0
   898
		{
sl@0
   899
		AssertionFailed2(KErrAbort, _L("Host Connect Fail "), err);
sl@0
   900
		return (EFalse);
sl@0
   901
		}
sl@0
   902
sl@0
   903
	// Default no-problem return
sl@0
   904
sl@0
   905
	return(ETrue);
sl@0
   906
	}
sl@0
   907
sl@0
   908
sl@0
   909
/** Commonly used step to load the USB Client Driver and set up
sl@0
   910
 *	a High-Speed electrical test VID/PID pair
sl@0
   911
 * @return ETrue if the ldd loaded sucessfully
sl@0
   912
 */
sl@0
   913
TBool COtgRoot::StepChangeVidPid(TUint16 aVID, TUint16 aPID)
sl@0
   914
sl@0
   915
	{
sl@0
   916
	test.Printf(_L("Load USBCC HS Test Client 0x%04x/0x%04x\n"),aVID,aPID);
sl@0
   917
sl@0
   918
	TInt err;
sl@0
   919
sl@0
   920
	// Set the revised VID/PID pair
sl@0
   921
	
sl@0
   922
	TBuf8<KUsbDescSize_Device> theDeviceDescriptor;
sl@0
   923
	err = oUsbcClient.GetDeviceDescriptor(theDeviceDescriptor);
sl@0
   924
	if (err != KErrNone)
sl@0
   925
		{
sl@0
   926
		AssertionFailed2(KErrAbort, _L("Client GetDes Fail "), err);
sl@0
   927
		return (EFalse);
sl@0
   928
		}
sl@0
   929
sl@0
   930
	TUint16 oldVID = ( theDeviceDescriptor[8] )
sl@0
   931
		           + ( theDeviceDescriptor[9] << 8 );
sl@0
   932
sl@0
   933
	theDeviceDescriptor[8] = ( aVID & 0x00FF );
sl@0
   934
	theDeviceDescriptor[9] = ( aVID & 0xFF00 ) >> 8;
sl@0
   935
sl@0
   936
	test.Printf(_L("..Change VID 0x%04X->0x%04X\n"), oldVID, aVID);
sl@0
   937
sl@0
   938
	TUint16 oldPID = ( theDeviceDescriptor[10] )
sl@0
   939
		           + ( theDeviceDescriptor[11] << 8 );
sl@0
   940
sl@0
   941
	theDeviceDescriptor[10] = ( aPID & 0x00FF );
sl@0
   942
	theDeviceDescriptor[11] = ( aPID & 0xFF00 ) >> 8;
sl@0
   943
sl@0
   944
	test.Printf(_L("..Change PID 0x%04X->0x%04X\n"), oldPID, aPID);
sl@0
   945
sl@0
   946
	err = oUsbcClient.SetDeviceDescriptor(theDeviceDescriptor);
sl@0
   947
	if (err != KErrNone)
sl@0
   948
		{
sl@0
   949
		AssertionFailed2(KErrAbort, _L("Client SetDes Fail "), err);
sl@0
   950
		return (EFalse);
sl@0
   951
		}
sl@0
   952
sl@0
   953
	// Default no-problem return
sl@0
   954
sl@0
   955
	return(ETrue);
sl@0
   956
	}
sl@0
   957
sl@0
   958
sl@0
   959
/** Commonly used step to set a flag that will cause the
sl@0
   960
    OPT test mode to be activated when the stacks are
sl@0
   961
	started 
sl@0
   962
*/
sl@0
   963
void COtgRoot::StepSetOptActive() 
sl@0
   964
	{ 
sl@0
   965
	iOptActive = ETrue;
sl@0
   966
	}
sl@0
   967
sl@0
   968
sl@0
   969
/** Commonly used step to unload the ldd and shut it down
sl@0
   970
*@return ETrue if the ldd unloaded sucessfully
sl@0
   971
*/
sl@0
   972
TBool COtgRoot::StepUnloadLDD()
sl@0
   973
	{ 
sl@0
   974
	test.Printf(_L("Unload otg LDD (implicit Stop() + Close()) \n"));
sl@0
   975
	
sl@0
   976
	LOG_VERBOSE1(_L("  Stop OTG+Host Stack\n"));
sl@0
   977
	otgStopStacks();
sl@0
   978
	otgClose();
sl@0
   979
	
sl@0
   980
	LOG_VERBOSE1(_L("  Unload\n"));
sl@0
   981
	otgUnloadLdd();
sl@0
   982
	
sl@0
   983
	iOptActive = EFalse; // retain the OTGDI behavour to clears this flag when client shuts 
sl@0
   984
	if (LddLoaded())
sl@0
   985
		return(EFalse);
sl@0
   986
	return(ETrue);
sl@0
   987
	}
sl@0
   988
	
sl@0
   989
sl@0
   990
/** StepLoadLDD - utility method : load the LDD, open it and init the stacks
sl@0
   991
 a commonly used test step */
sl@0
   992
TBool COtgRoot::StepLoadLDD()
sl@0
   993
	{
sl@0
   994
	TInt err;	
sl@0
   995
sl@0
   996
	LOG_VERBOSE1(_L("Load otg LDD\n"));
sl@0
   997
	err = otgLoadLdd();
sl@0
   998
	if (err != KErrNone)
sl@0
   999
		{
sl@0
  1000
		AssertionFailed2(KErrAbort, _L("Loading LDD failed "), err);
sl@0
  1001
		return (EFalse);
sl@0
  1002
		}
sl@0
  1003
		
sl@0
  1004
	LOG_VERBOSE1(_L("Open the LDD session\n"));
sl@0
  1005
	err = otgOpen();
sl@0
  1006
	if (err != KErrNone)
sl@0
  1007
		{
sl@0
  1008
		AssertionFailed2(KErrAbort, _L("Open LDD session failed "), err);
sl@0
  1009
		return (EFalse);
sl@0
  1010
		}
sl@0
  1011
sl@0
  1012
	if ( iOptActive )
sl@0
  1013
		{
sl@0
  1014
		test.Printf(_L("Activate OPT Test Mode\n"));
sl@0
  1015
		err = otgActivateOptTestMode();
sl@0
  1016
		if (err != KErrNone)
sl@0
  1017
			{
sl@0
  1018
			AssertionFailed2(KErrAbort, _L("OPT Activate failed "), err);
sl@0
  1019
			return (EFalse);
sl@0
  1020
			}	
sl@0
  1021
		}
sl@0
  1022
sl@0
  1023
	test.Printf(_L("Start OTG+Host Stack\n"));
sl@0
  1024
	err = otgStartStacks();
sl@0
  1025
	if (err != KErrNone)
sl@0
  1026
		{
sl@0
  1027
		AssertionFailed2(KErrAbort, _L("Start stack failed "), err);
sl@0
  1028
		return (EFalse);
sl@0
  1029
		}	
sl@0
  1030
		
sl@0
  1031
	//	DS - Temporarily adding .1 second delay in here to beat the race
sl@0
  1032
	//	condition to be fixed as part of third part USB HOST/OTG stack issue 60761
sl@0
  1033
	User::After(100000);
sl@0
  1034
		
sl@0
  1035
	return(ETrue);
sl@0
  1036
	}
sl@0
  1037
sl@0
  1038
void COtgRoot::SetMaxPowerToL(TUint16 aVal)
sl@0
  1039
	{
sl@0
  1040
sl@0
  1041
	TBuf8<KUsbDescSize_Config> buf;
sl@0
  1042
	
sl@0
  1043
	oUsbcClient.GetConfigurationDescriptor(buf);
sl@0
  1044
	
sl@0
  1045
	aVal %= 500;
sl@0
  1046
	
sl@0
  1047
	buf[8] = (TUint8)(aVal / 2);
sl@0
  1048
	
sl@0
  1049
	oUsbcClient.SetConfigurationDescriptor(buf);
sl@0
  1050
	
sl@0
  1051
	}
sl@0
  1052
sl@0
  1053
void COtgRoot::GetMaxPower(TUint16& aVal)
sl@0
  1054
	{
sl@0
  1055
	TBuf8<KUsbDescSize_Config> buf;
sl@0
  1056
	
sl@0
  1057
	oUsbcClient.GetConfigurationDescriptor(buf);
sl@0
  1058
	
sl@0
  1059
	aVal = buf[8] * 2;
sl@0
  1060
	}
sl@0
  1061
sl@0
  1062