os/boardsupport/haitest/bspsvs/suite/e32/src/T_RDevUsbcClientData.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
/*
sl@0
     2
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
// This contains implementation for CT_RDevUsbcClientData class
sl@0
    18
sl@0
    19
sl@0
    20
sl@0
    21
#include <f32file.h>
sl@0
    22
#include <d32usbc.h>
sl@0
    23
#include "T_RDevUsbcClientData.h" 
sl@0
    24
sl@0
    25
sl@0
    26
sl@0
    27
/*@{*/
sl@0
    28
//LITs to identify the commands
sl@0
    29
_LIT(KCmdNewL,									"NewL");
sl@0
    30
_LIT(KCmdUtilityLoadLogicalDevice, 				"LoadLogicalDevice");
sl@0
    31
_LIT(KCmdOpen, 					    			"Open");
sl@0
    32
_LIT(KCmdDeviceCaps,							"DeviceCaps");
sl@0
    33
_LIT(KCmdUtilitySetEndPoint, 					"SetEndPoint");
sl@0
    34
_LIT(KCmdEndpointCaps,							"EndpointCaps");
sl@0
    35
_LIT(KCmdSetInterface, 							"SetInterface");
sl@0
    36
_LIT(KCmdGetDeviceDescriptorSize,				"GetDeviceDescriptorSize");
sl@0
    37
_LIT(KCmdGetDeviceDescriptor,					"GetDeviceDescriptor");
sl@0
    38
_LIT(KCmdSetDeviceDescriptor,					"SetDeviceDescriptor");
sl@0
    39
_LIT(KCmdDestructor,							"~");
sl@0
    40
/*@}*/
sl@0
    41
sl@0
    42
sl@0
    43
/*@{*/
sl@0
    44
//LITs to read from the ini file
sl@0
    45
_LIT(KMode, 									"mode");
sl@0
    46
_LIT(KDirection, 								"direction");
sl@0
    47
_LIT(KBufferingMask, 							"bandwidthBufferingMask");
sl@0
    48
_LIT(KSupportsConnect,							"supportsConnect");
sl@0
    49
_LIT(KSupportsSelfPowered, 						"supportsSelfPowered");
sl@0
    50
_LIT(KSupportsRemoteWakeup, 					"supportsRemoteWakeup");
sl@0
    51
_LIT(KUSBVersionLow, 							"USBVersionLow");
sl@0
    52
_LIT(KUSBVersionHigh,							"USBVersionHigh");
sl@0
    53
_LIT(KVendorIDLow, 								"VendorIDLow");
sl@0
    54
_LIT(KVendorIDHigh, 							"VendorIDHigh");
sl@0
    55
_LIT(KProductIDLow, 							"ProductIDLow");
sl@0
    56
_LIT(KProductIDHigh, 							"ProductIDHigh");
sl@0
    57
_LIT(KReleaseNumberLow, 						"ReleaseNumberLow");
sl@0
    58
_LIT(KReleaseNumberHigh, 						"ReleaseNumberHigh");
sl@0
    59
_LIT(KDriver, 									"driver");
sl@0
    60
_LIT(KEXPECTED, 								"expected");
sl@0
    61
/*@}*/
sl@0
    62
sl@0
    63
/*@{*/
sl@0
    64
_LIT16(interfaceName, "USB interface");
sl@0
    65
/*@}*/
sl@0
    66
sl@0
    67
/*@{*/
sl@0
    68
_LIT(KResourceDMA, 							"ResourceDMA");
sl@0
    69
_LIT(KResourceDoubleBuffering,				"ResourceDoubleBuffering");
sl@0
    70
/*@}*/
sl@0
    71
const CDataWrapperBase::TEnumEntryTable CT_RDevUsbcClientData::iEUsbcEndpointResource[] = 
sl@0
    72
	{ 
sl@0
    73
	{ KResourceDMA,					EUsbcEndpointResourceDMA },		// Requests the use of DMA =0
sl@0
    74
	{ KResourceDoubleBuffering,		EUsbcEndpointResourceDoubleBuffering },	//Requests the use of double FIFO buffering = 1	
sl@0
    75
	};
sl@0
    76
sl@0
    77
/**
sl@0
    78
 * Two phase constructor
sl@0
    79
 *
sl@0
    80
 * @leave	system wide error
sl@0
    81
 */
sl@0
    82
CT_RDevUsbcClientData* CT_RDevUsbcClientData::NewL()
sl@0
    83
	{
sl@0
    84
	CT_RDevUsbcClientData*	ret=new (ELeave) CT_RDevUsbcClientData();
sl@0
    85
	CleanupStack::PushL(ret);
sl@0
    86
	ret->ConstructL();
sl@0
    87
	CleanupStack::Pop(ret);
sl@0
    88
	return ret;
sl@0
    89
	}
sl@0
    90
sl@0
    91
/**
sl@0
    92
 * Protected constructor. First phase construction
sl@0
    93
 */
sl@0
    94
CT_RDevUsbcClientData::CT_RDevUsbcClientData()
sl@0
    95
	:
sl@0
    96
	iChannel(NULL),
sl@0
    97
	iInterface(NULL),
sl@0
    98
	iEndpointData(),
sl@0
    99
	iConfiguredEndpoints(0),
sl@0
   100
	iTxMaxPacketSize(0),
sl@0
   101
	iCaps(),
sl@0
   102
	iActiveCallback(NULL),
sl@0
   103
	iBuffer(NULL),
sl@0
   104
    iBuffer_verify(NULL),
sl@0
   105
    iDeviceDescriptorSize(0)
sl@0
   106
	{
sl@0
   107
	
sl@0
   108
	}
sl@0
   109
sl@0
   110
/**
sl@0
   111
 * Second phase construction
sl@0
   112
 *
sl@0
   113
 * @internalComponent
sl@0
   114
 *
sl@0
   115
 * @return	N/A
sl@0
   116
 *
sl@0
   117
 * @pre		None
sl@0
   118
 * @post	None
sl@0
   119
 *
sl@0
   120
 * @leave	system wide error
sl@0
   121
 */
sl@0
   122
void CT_RDevUsbcClientData::ConstructL()
sl@0
   123
	{
sl@0
   124
	iActiveCallback = CActiveCallback::NewL(*this);	
sl@0
   125
	}
sl@0
   126
sl@0
   127
/**
sl@0
   128
 * Public destructor
sl@0
   129
 */
sl@0
   130
CT_RDevUsbcClientData::~CT_RDevUsbcClientData()
sl@0
   131
	{		
sl@0
   132
	// Empty arrays and delete objects
sl@0
   133
sl@0
   134
	DestroyData();
sl@0
   135
sl@0
   136
	if (iActiveCallback)
sl@0
   137
		{
sl@0
   138
		delete iActiveCallback;
sl@0
   139
		iActiveCallback = NULL;
sl@0
   140
		}
sl@0
   141
	}
sl@0
   142
sl@0
   143
/**
sl@0
   144
 *  RunL is called when an asynchronous call has completed
sl@0
   145
 * 
sl@0
   146
 *  @param aActive - a pointer to an active object
sl@0
   147
 *  @param aIndex - Index of the asynchronous call
sl@0
   148
 * 
sl@0
   149
 */
sl@0
   150
void CT_RDevUsbcClientData::RunL(CActive* aActive, TInt aIndex)
sl@0
   151
	{
sl@0
   152
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::RunL"));
sl@0
   153
	DecOutstanding(); // One of the async calls has completed 
sl@0
   154
	TBool straySignal = EFalse; 
sl@0
   155
		  
sl@0
   156
	if(aActive == iActiveCallback)
sl@0
   157
		{
sl@0
   158
		INFO_PRINTF1(_L("Asynchronous task has completed. RunL  called"));
sl@0
   159
		}		
sl@0
   160
	else
sl@0
   161
		{ 
sl@0
   162
		ERR_PRINTF1(_L("Stray RunL signal"));
sl@0
   163
		SetBlockResult(EFail);
sl@0
   164
		straySignal = ETrue;		
sl@0
   165
		}
sl@0
   166
	
sl@0
   167
	if( !straySignal ) 
sl@0
   168
		{ 
sl@0
   169
		TInt err = aActive->iStatus.Int(); 
sl@0
   170
		if( err != KErrNone ) 
sl@0
   171
			{ 
sl@0
   172
			ERR_PRINTF2(_L("RunL Error %d"), err); 
sl@0
   173
			SetAsyncError( aIndex, err );		
sl@0
   174
			} 
sl@0
   175
		else
sl@0
   176
			{ 
sl@0
   177
			INFO_PRINTF1(_L("RunL  completed successfully"));
sl@0
   178
			}
sl@0
   179
		}
sl@0
   180
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::RunL"));
sl@0
   181
	}
sl@0
   182
sl@0
   183
sl@0
   184
/**
sl@0
   185
 * Return a pointer to the object that the data wraps
sl@0
   186
 *
sl@0
   187
 * @return	pointer to the object that the data wraps
sl@0
   188
 */
sl@0
   189
TAny* CT_RDevUsbcClientData::GetObject()
sl@0
   190
	{
sl@0
   191
	return iChannel;
sl@0
   192
	}
sl@0
   193
sl@0
   194
/**
sl@0
   195
 * Returns the wrapper.
sl@0
   196
 * 
sl@0
   197
 * @return pointer to the Wrapper class
sl@0
   198
 */
sl@0
   199
sl@0
   200
sl@0
   201
sl@0
   202
/**
sl@0
   203
 * Process a command read from the ini file
sl@0
   204
 *
sl@0
   205
 * @param aCommand			The command to process
sl@0
   206
 * @param aSection			The section in the ini containing data for the command
sl@0
   207
 * @param aAsyncErrorIndex	Command index for async calls to return errors to
sl@0
   208
 * @return					ETrue if the command is processed
sl@0
   209
 * @leave					System wide error
sl@0
   210
 */
sl@0
   211
TBool CT_RDevUsbcClientData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
sl@0
   212
	{
sl@0
   213
	TBool ret=ETrue;
sl@0
   214
		
sl@0
   215
	if(aCommand == KCmdNewL )
sl@0
   216
		{
sl@0
   217
		DoCmdNewL();
sl@0
   218
		}
sl@0
   219
	else if(aCommand == KCmdUtilityLoadLogicalDevice)
sl@0
   220
		{
sl@0
   221
		DoCmdUtilityLoadLogicalDevice(aSection);
sl@0
   222
		}
sl@0
   223
	else if(aCommand == KCmdOpen)
sl@0
   224
		{
sl@0
   225
		DoCmdOpen();
sl@0
   226
		}
sl@0
   227
	else if(aCommand == KCmdDeviceCaps)
sl@0
   228
		{
sl@0
   229
		DoCmdDeviceCaps(aSection);
sl@0
   230
		}	
sl@0
   231
	else if(aCommand == KCmdGetDeviceDescriptorSize)
sl@0
   232
		{
sl@0
   233
		DoCmdGetDeviceDescriptorSize(aSection);
sl@0
   234
		}
sl@0
   235
	else if(aCommand == KCmdGetDeviceDescriptor)
sl@0
   236
		{
sl@0
   237
		DoCmdGetDeviceDescriptor(aSection);
sl@0
   238
		}
sl@0
   239
	else if(aCommand == KCmdSetDeviceDescriptor)
sl@0
   240
		{
sl@0
   241
		DoCmdSetDeviceDescriptor(aSection);
sl@0
   242
		}
sl@0
   243
	else if(aCommand == KCmdUtilitySetEndPoint)
sl@0
   244
		{
sl@0
   245
		DoCmdUtilitySetEndPointL(aSection);
sl@0
   246
		}	
sl@0
   247
	else if(aCommand == KCmdEndpointCaps)
sl@0
   248
		{
sl@0
   249
		DoCmdEndpointCaps();
sl@0
   250
		}
sl@0
   251
	else if(aCommand == KCmdSetInterface)
sl@0
   252
		{
sl@0
   253
		DoCmdSetInterface(aSection);
sl@0
   254
		}	
sl@0
   255
	else if(aCommand == KCmdDestructor)
sl@0
   256
		{
sl@0
   257
		DoCmdDestructor();
sl@0
   258
		}
sl@0
   259
	else
sl@0
   260
		{
sl@0
   261
		ERR_PRINTF1(_L("Unknown command"));
sl@0
   262
		ret = EFalse;
sl@0
   263
		}
sl@0
   264
	
sl@0
   265
	return ret;
sl@0
   266
	}
sl@0
   267
sl@0
   268
sl@0
   269
sl@0
   270
/**
sl@0
   271
 * Creante an object of RDevUsbcClient
sl@0
   272
 */
sl@0
   273
void  CT_RDevUsbcClientData::DoCmdNewL()
sl@0
   274
	{
sl@0
   275
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdNewL"));
sl@0
   276
	DestroyData();
sl@0
   277
	iChannel = new (ELeave) RDevUsbcClient();
sl@0
   278
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdNewL"));
sl@0
   279
	}
sl@0
   280
/**
sl@0
   281
 * Loads Logical Device for USB.
sl@0
   282
 */
sl@0
   283
void CT_RDevUsbcClientData::DoCmdUtilityLoadLogicalDevice(const TTEFSectionName& aSection)
sl@0
   284
	{
sl@0
   285
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdUtilityLoadLogicalDevice"));
sl@0
   286
	TInt error(KErrNone);
sl@0
   287
	TBool dataOk = ETrue;
sl@0
   288
	TPtrC lddName;
sl@0
   289
	TBufC<9> value;	
sl@0
   290
	if(!GetStringFromConfig(aSection, KDriver, lddName))
sl@0
   291
		{
sl@0
   292
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), & KDriver);
sl@0
   293
		SetBlockResult(EFail);
sl@0
   294
		dataOk = EFalse;
sl@0
   295
		}	
sl@0
   296
	if(dataOk)
sl@0
   297
		{	
sl@0
   298
		value = lddName;		
sl@0
   299
		INFO_PRINTF2(_L("Driver: %S"), & value);
sl@0
   300
		error = User::LoadLogicalDevice(value);		
sl@0
   301
		
sl@0
   302
		if(error == KErrAlreadyExists)
sl@0
   303
			{
sl@0
   304
			INFO_PRINTF2(_L("USB - Logical device driver loaded with %d, error will be changed to KErrNone"), error);
sl@0
   305
			error = KErrNone;
sl@0
   306
			}
sl@0
   307
		if(error != KErrNone)
sl@0
   308
			{
sl@0
   309
			ERR_PRINTF2(_L("USB - Could not load logical device driver. Error %d"), error);
sl@0
   310
			}
sl@0
   311
		else
sl@0
   312
			{
sl@0
   313
			INFO_PRINTF2(_L("USB - Logical device driver loaded with %d"), error);
sl@0
   314
			}	
sl@0
   315
		SetError(error);
sl@0
   316
		}		
sl@0
   317
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdUtilityLoadLogicalDevice"));
sl@0
   318
	}
sl@0
   319
sl@0
   320
/**
sl@0
   321
 * Opens a USB channel 
sl@0
   322
 */
sl@0
   323
void CT_RDevUsbcClientData::DoCmdOpen()
sl@0
   324
	{
sl@0
   325
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdOpen"));
sl@0
   326
	// Open USB driver channel
sl@0
   327
	TInt error = iChannel->Open(USB::KUSBChannelOpenParameter);
sl@0
   328
sl@0
   329
	if (error != KErrNone)
sl@0
   330
		{
sl@0
   331
		ERR_PRINTF2(_L("ERROR %d when opening channel"), error);
sl@0
   332
		}
sl@0
   333
	else
sl@0
   334
		{
sl@0
   335
		INFO_PRINTF2(_L("Channel open returns: %d "), error);
sl@0
   336
		}
sl@0
   337
sl@0
   338
	SetError(error);
sl@0
   339
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdOpen"));
sl@0
   340
	}
sl@0
   341
sl@0
   342
/**
sl@0
   343
 * Reads device capabilities and verifies them
sl@0
   344
 * @param aSection		The section in the ini containing data for the command
sl@0
   345
 */
sl@0
   346
void CT_RDevUsbcClientData::DoCmdDeviceCaps(const TTEFSectionName& aSection)
sl@0
   347
	{
sl@0
   348
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdDeviceCaps"));
sl@0
   349
	TBool supportsConnect;
sl@0
   350
	TBool dataOk = ETrue;
sl@0
   351
	if(!GetBoolFromConfig(aSection, KSupportsConnect, supportsConnect))
sl@0
   352
		{
sl@0
   353
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSupportsConnect);
sl@0
   354
		SetBlockResult(EFail);
sl@0
   355
		dataOk = EFalse;
sl@0
   356
		}
sl@0
   357
	
sl@0
   358
	TBool supportsSelfPowered;
sl@0
   359
	if(!GetBoolFromConfig(aSection, KSupportsSelfPowered, supportsSelfPowered))
sl@0
   360
		{
sl@0
   361
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSupportsSelfPowered);
sl@0
   362
		SetBlockResult(EFail);
sl@0
   363
		dataOk = EFalse;
sl@0
   364
		}
sl@0
   365
	
sl@0
   366
	TBool supportsRemoteWakeup;
sl@0
   367
	if(!GetBoolFromConfig(aSection, KSupportsRemoteWakeup, supportsRemoteWakeup))
sl@0
   368
		{
sl@0
   369
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSupportsRemoteWakeup);
sl@0
   370
		SetBlockResult(EFail);
sl@0
   371
		dataOk = EFalse;
sl@0
   372
		}
sl@0
   373
	if(dataOk)
sl@0
   374
		{
sl@0
   375
		TInt error = iChannel->DeviceCaps(iCaps);
sl@0
   376
		if (error != KErrNone)
sl@0
   377
			{
sl@0
   378
			ERR_PRINTF2(_L("Failed to read device caps [%d]"), error);
sl@0
   379
			SetError(error);
sl@0
   380
			}
sl@0
   381
		else
sl@0
   382
			{
sl@0
   383
			// Check that reported device capabilities are what they should be
sl@0
   384
			INFO_PRINTF2(_L("Device supports %d endpoints"), iCaps().iTotalEndpoints );
sl@0
   385
			INFO_PRINTF2(_L("Device supports Software-Connect: %s"), iCaps().iConnect ? _S("yes") : _S("no"));
sl@0
   386
			if(!iCaps().iConnect && supportsConnect)
sl@0
   387
				{
sl@0
   388
				ERR_PRINTF1(_L("Device supports Software-Connect feature IS NOT SUPPORTED"));
sl@0
   389
				SetBlockResult(EFail);
sl@0
   390
				}
sl@0
   391
sl@0
   392
			INFO_PRINTF2(_L("Device is Self-Powered: %s"), iCaps().iSelfPowered ? _S("yes") : _S("no"));
sl@0
   393
			if(!iCaps().iSelfPowered && supportsSelfPowered)
sl@0
   394
				{
sl@0
   395
				ERR_PRINTF1(_L("Device is Self-Powered feature IS NOT SUPPORTED"));
sl@0
   396
				SetBlockResult(EFail);
sl@0
   397
				}
sl@0
   398
sl@0
   399
			INFO_PRINTF2(_L("Device supports Remote-Wakeup:	%s"),iCaps().iRemoteWakeup ? _S("yes") : _S("no"));
sl@0
   400
			if(!iCaps().iRemoteWakeup && supportsRemoteWakeup)
sl@0
   401
				{
sl@0
   402
				ERR_PRINTF1(_L("Device supports Remote-Wakeup feature IS NOT SUPPORTED"));
sl@0
   403
				SetBlockResult(EFail);
sl@0
   404
				}
sl@0
   405
			}		
sl@0
   406
		}
sl@0
   407
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdDeviceCaps"));
sl@0
   408
	}
sl@0
   409
sl@0
   410
/**
sl@0
   411
 * Reads device endpoint capabilities and prints them
sl@0
   412
 */
sl@0
   413
void CT_RDevUsbcClientData::DoCmdEndpointCaps()
sl@0
   414
	{
sl@0
   415
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdEndpointCaps"));
sl@0
   416
	TPtr8 endpointData(reinterpret_cast<TUint8*>(iEndpointData), sizeof(iEndpointData), sizeof(iEndpointData));
sl@0
   417
	TInt error = iChannel->EndpointCaps(endpointData);
sl@0
   418
sl@0
   419
	if (error != KErrNone)
sl@0
   420
		{
sl@0
   421
		ERR_PRINTF2(_L("Failed to read endpoint caps [%d]"), error);
sl@0
   422
		SetError(error);
sl@0
   423
		}
sl@0
   424
	else
sl@0
   425
		{
sl@0
   426
		INFO_PRINTF1(_L("User endpoint capabilities:"));
sl@0
   427
		for (TInt i = 0; i < iCaps().iTotalEndpoints; i++)
sl@0
   428
			{
sl@0
   429
			const TUsbcEndpointCaps* caps = &iEndpointData[i].iCaps;
sl@0
   430
			INFO_PRINTF4(_L("Endpoint %02d: MaxPackeSize=%s TypeDirM = 0x%08x "),
sl@0
   431
						i + 1,
sl@0
   432
						(caps->iSizes & KUsbEpSizeCont ) ? _S("Continuous") :
sl@0
   433
						((caps->iSizes & KUsbEpSize8) ? _S("8 bytes") :
sl@0
   434
						((caps->iSizes & KUsbEpSize16) ? _S("16 bytes") :
sl@0
   435
						((caps->iSizes & KUsbEpSize32) ? _S("32 bytes") :
sl@0
   436
						((caps->iSizes & KUsbEpSize64) ? _S("64 bytes") :
sl@0
   437
						((caps->iSizes & KUsbEpSize128) ? _S("128 bytes") :
sl@0
   438
						((caps->iSizes & KUsbEpSize256) ? _S("256 bytes") :
sl@0
   439
						((caps->iSizes & KUsbEpSize512) ? _S("512 bytes") :
sl@0
   440
						((caps->iSizes & KUsbEpSize1023) ? _S("1023 bytes") :
sl@0
   441
						((caps->iSizes & KUsbEpSize1024) ? _S("1024 bytes") :
sl@0
   442
						_S("Unknown")))))))))),
sl@0
   443
						caps->iTypesAndDir);
sl@0
   444
			}
sl@0
   445
		}
sl@0
   446
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdEndpointCaps"));
sl@0
   447
	}
sl@0
   448
sl@0
   449
sl@0
   450
/*
sl@0
   451
 * Inits USB Device Descriptors - Get the device descriptor size
sl@0
   452
 */
sl@0
   453
sl@0
   454
void CT_RDevUsbcClientData::DoCmdGetDeviceDescriptorSize(const TTEFSectionName& aSection)
sl@0
   455
	{	
sl@0
   456
	// Read the size of the descriptors and create buffer to store them.
sl@0
   457
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdGetDeviceDescriptorSize"));
sl@0
   458
    TInt expected;
sl@0
   459
    if(!GetIntFromConfig(aSection, KEXPECTED, expected))
sl@0
   460
		{
sl@0
   461
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KEXPECTED);
sl@0
   462
		SetBlockResult(EFail);
sl@0
   463
		}
sl@0
   464
    else
sl@0
   465
        {
sl@0
   466
        iDeviceDescriptorSize = 0;
sl@0
   467
    	INFO_PRINTF1(_L("Initializing device descriptors"));
sl@0
   468
        INFO_PRINTF1(_L("void CT_RDevUsbcClientData::GetDeviceDescriptorSize() BEGIN"));
sl@0
   469
    	iChannel->GetDeviceDescriptorSize(iDeviceDescriptorSize);	
sl@0
   470
        
sl@0
   471
        if(expected != iDeviceDescriptorSize)
sl@0
   472
            {
sl@0
   473
            ERR_PRINTF3(_L("Expected size != actual size, expected = %d, actual = %d "),expected, iDeviceDescriptorSize);
sl@0
   474
            SetBlockResult(EFail);
sl@0
   475
            }
sl@0
   476
        }
sl@0
   477
        // initialize buffer which used to verify.
sl@0
   478
        
sl@0
   479
            
sl@0
   480
    INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdGetDeviceDescriptorSize"));
sl@0
   481
	}
sl@0
   482
sl@0
   483
/**
sl@0
   484
 * Inits USB Device Descriptors - Get device descriptor
sl@0
   485
 */
sl@0
   486
sl@0
   487
void CT_RDevUsbcClientData::DoCmdGetDeviceDescriptor(const TTEFSectionName& aSection)
sl@0
   488
	{
sl@0
   489
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdGetDeviceDescriptor"));
sl@0
   490
    
sl@0
   491
    //initialize descriptor buffer.
sl@0
   492
    TRAPD(error, iBuffer = HBufC8::NewL(iDeviceDescriptorSize));
sl@0
   493
    if(error != KErrNone || !iBuffer)
sl@0
   494
    	{
sl@0
   495
    	ERR_PRINTF2(_L("Failed to initialize device descriptor [%d]"),error);
sl@0
   496
    	SetError(error);
sl@0
   497
    	}
sl@0
   498
    TRAPD(error2, iBuffer_verify = HBufC8::NewL(iDeviceDescriptorSize));
sl@0
   499
    if(error2 != KErrNone || !iBuffer_verify)
sl@0
   500
    	{
sl@0
   501
    	ERR_PRINTF2(_L("Failed to initialize device descriptor [%d]"),error2);
sl@0
   502
    	SetError(error2);
sl@0
   503
    	}  
sl@0
   504
    
sl@0
   505
	TInt err;	
sl@0
   506
	TPtr8 devDescrPtr = iBuffer->Des();
sl@0
   507
	// Read the current descriptors.	
sl@0
   508
	err = iChannel->GetDeviceDescriptor(devDescrPtr);
sl@0
   509
	if (err != KErrNone)
sl@0
   510
		{
sl@0
   511
		ERR_PRINTF2(_L("Failed to get the device descriptor [%d]"),err);
sl@0
   512
		SetError(err);
sl@0
   513
		}   
sl@0
   514
        
sl@0
   515
    // Read descriptors from ini and compare.
sl@0
   516
    TInt USBVersionLow;
sl@0
   517
	TBool dataOk = ETrue;
sl@0
   518
	if(!GetIntFromConfig(aSection, KUSBVersionLow, USBVersionLow))
sl@0
   519
		{
sl@0
   520
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KUSBVersionLow);
sl@0
   521
		SetBlockResult(EFail);
sl@0
   522
		dataOk = EFalse;
sl@0
   523
		}
sl@0
   524
	TInt USBVersionHigh;
sl@0
   525
	if(!GetIntFromConfig(aSection, KUSBVersionHigh, USBVersionHigh))
sl@0
   526
		{
sl@0
   527
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KUSBVersionHigh);
sl@0
   528
		SetBlockResult(EFail);
sl@0
   529
		dataOk = EFalse;
sl@0
   530
		}
sl@0
   531
	TInt VendorIDLow;
sl@0
   532
	if(!GetIntFromConfig(aSection, KVendorIDLow, VendorIDLow))
sl@0
   533
		{
sl@0
   534
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVendorIDLow);
sl@0
   535
		SetBlockResult(EFail);
sl@0
   536
		dataOk = EFalse;
sl@0
   537
		}
sl@0
   538
	TInt VendorIDHigh;
sl@0
   539
	if(!GetIntFromConfig(aSection, KVendorIDHigh, VendorIDHigh))
sl@0
   540
		{
sl@0
   541
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVendorIDHigh);
sl@0
   542
		SetBlockResult(EFail);
sl@0
   543
		dataOk = EFalse;
sl@0
   544
		}
sl@0
   545
	// product ID for test device
sl@0
   546
	TInt ProductIDLow;
sl@0
   547
	if(!GetIntFromConfig(aSection, KProductIDLow, ProductIDLow))
sl@0
   548
		{
sl@0
   549
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KProductIDLow);
sl@0
   550
		SetBlockResult(EFail);
sl@0
   551
		dataOk = EFalse;
sl@0
   552
		}
sl@0
   553
	TInt ProductIDHigh;
sl@0
   554
	if(!GetIntFromConfig(aSection, KProductIDHigh, ProductIDHigh))
sl@0
   555
		{
sl@0
   556
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KProductIDHigh);
sl@0
   557
		SetBlockResult(EFail);
sl@0
   558
		dataOk = EFalse;
sl@0
   559
		}
sl@0
   560
	// release number
sl@0
   561
	TInt ReleaseNumberLow;
sl@0
   562
	if(!GetIntFromConfig(aSection, KReleaseNumberLow, ReleaseNumberLow))
sl@0
   563
		{
sl@0
   564
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KReleaseNumberLow);
sl@0
   565
		SetBlockResult(EFail);
sl@0
   566
		dataOk = EFalse;
sl@0
   567
		}
sl@0
   568
	TInt ReleaseNumberHigh;
sl@0
   569
	if(!GetIntFromConfig(aSection, KReleaseNumberHigh, ReleaseNumberHigh))
sl@0
   570
		{
sl@0
   571
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KReleaseNumberHigh);
sl@0
   572
		SetBlockResult(EFail);
sl@0
   573
		dataOk = EFalse;
sl@0
   574
		}			
sl@0
   575
	// Device descriptor data is presented in bytes (Little endian)
sl@0
   576
	// defined in the .ini file
sl@0
   577
	// The following presents numeric values device uses to introduce
sl@0
   578
	// herself to USB host in enumeration process
sl@0
   579
	if(dataOk)
sl@0
   580
		{
sl@0
   581
		TPtr8 devDescrPtr_verify = iBuffer_verify->Des();
sl@0
   582
		err = iChannel->GetDeviceDescriptor(devDescrPtr_verify);
sl@0
   583
		if (err != KErrNone)
sl@0
   584
			{
sl@0
   585
			ERR_PRINTF2(_L("Failed to get the device descriptor [%d]"),err);
sl@0
   586
			SetError(err);
sl@0
   587
			}   
sl@0
   588
		// USB version
sl@0
   589
		devDescrPtr_verify[USB::KSpecOffset] = USBVersionLow;
sl@0
   590
		devDescrPtr_verify[USB::KSpecOffset + 1] = USBVersionHigh;
sl@0
   591
sl@0
   592
		devDescrPtr_verify[USB::KVendorOffset] = VendorIDLow;
sl@0
   593
		devDescrPtr_verify[USB::KVendorOffset + 1] = VendorIDHigh;
sl@0
   594
sl@0
   595
		// product ID for test device
sl@0
   596
		devDescrPtr_verify[USB::KProductIDOffset] = ProductIDLow;
sl@0
   597
		devDescrPtr_verify[USB::KProductIDOffset + 1] = ProductIDHigh;
sl@0
   598
sl@0
   599
		// Set release number
sl@0
   600
		devDescrPtr_verify[USB::KReleaseOffset] = ReleaseNumberLow;
sl@0
   601
		devDescrPtr_verify[USB::KReleaseOffset + 1] = ReleaseNumberHigh;
sl@0
   602
sl@0
   603
        if(devDescrPtr != devDescrPtr_verify)
sl@0
   604
            {
sl@0
   605
            ERR_PRINTF1(_L("Expected DeviceDescriptor is not the same as actual. "));
sl@0
   606
            SetBlockResult(EFail);
sl@0
   607
            }
sl@0
   608
		}	
sl@0
   609
        
sl@0
   610
        delete iBuffer;
sl@0
   611
		iBuffer = NULL;
sl@0
   612
        delete iBuffer_verify;
sl@0
   613
		iBuffer_verify = NULL;
sl@0
   614
sl@0
   615
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdGetDeviceDescriptor"));
sl@0
   616
	}
sl@0
   617
sl@0
   618
/**
sl@0
   619
 * Inits USB Device Descriptors - Set device descriptor
sl@0
   620
 * @param aSection - The section in the ini containing data for the command
sl@0
   621
 */
sl@0
   622
void CT_RDevUsbcClientData::DoCmdSetDeviceDescriptor(const TTEFSectionName& aSection)
sl@0
   623
	{
sl@0
   624
	// USB version
sl@0
   625
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdSetDeviceDescriptor"));
sl@0
   626
    
sl@0
   627
    iDeviceDescriptorSize = 0;
sl@0
   628
    INFO_PRINTF1(_L("Initializing device descriptors"));
sl@0
   629
    iChannel->GetDeviceDescriptorSize(iDeviceDescriptorSize);	
sl@0
   630
    INFO_PRINTF2(_L("Device descriptor size = %d"), iDeviceDescriptorSize);
sl@0
   631
    
sl@0
   632
    //initialize descriptor buffer.
sl@0
   633
    TRAPD(err, iBuffer = HBufC8::NewL(iDeviceDescriptorSize));
sl@0
   634
    if(err != KErrNone || !iBuffer)
sl@0
   635
    	{
sl@0
   636
    	ERR_PRINTF2(_L("Failed to initialize device descriptor [%d]"),err);
sl@0
   637
    	SetError(err);
sl@0
   638
    	}
sl@0
   639
    
sl@0
   640
	TInt error;
sl@0
   641
	TInt USBVersionLow;
sl@0
   642
	TBool dataOk = ETrue;
sl@0
   643
	if(!GetIntFromConfig(aSection, KUSBVersionLow, USBVersionLow))
sl@0
   644
		{
sl@0
   645
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KUSBVersionLow);
sl@0
   646
		SetBlockResult(EFail);
sl@0
   647
		dataOk = EFalse;
sl@0
   648
		}
sl@0
   649
	TInt USBVersionHigh;
sl@0
   650
	if(!GetIntFromConfig(aSection, KUSBVersionHigh, USBVersionHigh))
sl@0
   651
		{
sl@0
   652
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KUSBVersionHigh);
sl@0
   653
		SetBlockResult(EFail);
sl@0
   654
		dataOk = EFalse;
sl@0
   655
		}
sl@0
   656
sl@0
   657
	TInt VendorIDLow;
sl@0
   658
	if(!GetIntFromConfig(aSection, KVendorIDLow, VendorIDLow))
sl@0
   659
		{
sl@0
   660
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVendorIDLow);
sl@0
   661
		SetBlockResult(EFail);
sl@0
   662
		dataOk = EFalse;
sl@0
   663
		}
sl@0
   664
	TInt VendorIDHigh;
sl@0
   665
	if(!GetIntFromConfig(aSection, KVendorIDHigh, VendorIDHigh))
sl@0
   666
		{
sl@0
   667
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVendorIDHigh);
sl@0
   668
		SetBlockResult(EFail);
sl@0
   669
		dataOk = EFalse;
sl@0
   670
		}
sl@0
   671
	// product ID for test device
sl@0
   672
	TInt ProductIDLow;
sl@0
   673
	if(!GetIntFromConfig(aSection, KProductIDLow, ProductIDLow))
sl@0
   674
		{
sl@0
   675
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KProductIDLow);
sl@0
   676
		SetBlockResult(EFail);
sl@0
   677
		dataOk = EFalse;
sl@0
   678
		}
sl@0
   679
	TInt ProductIDHigh;
sl@0
   680
	if(!GetIntFromConfig(aSection, KProductIDHigh, ProductIDHigh))
sl@0
   681
		{
sl@0
   682
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KProductIDHigh);
sl@0
   683
		SetBlockResult(EFail);
sl@0
   684
		dataOk = EFalse;
sl@0
   685
		}
sl@0
   686
	// release number
sl@0
   687
	TInt ReleaseNumberLow;
sl@0
   688
	if(!GetIntFromConfig(aSection, KReleaseNumberLow, ReleaseNumberLow))
sl@0
   689
		{
sl@0
   690
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KReleaseNumberLow);
sl@0
   691
		SetBlockResult(EFail);
sl@0
   692
		dataOk = EFalse;
sl@0
   693
		}
sl@0
   694
	TInt ReleaseNumberHigh;
sl@0
   695
	if(!GetIntFromConfig(aSection, KReleaseNumberHigh, ReleaseNumberHigh))
sl@0
   696
		{
sl@0
   697
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KReleaseNumberHigh);
sl@0
   698
		SetBlockResult(EFail);
sl@0
   699
		dataOk = EFalse;
sl@0
   700
		}			
sl@0
   701
	// Device descriptor data is presented in bytes (Little endian)
sl@0
   702
	// defined in the .ini file
sl@0
   703
	// The following presents numeric values device uses to introduce
sl@0
   704
	// herself to USB host in enumeration process
sl@0
   705
	if(dataOk)
sl@0
   706
		{
sl@0
   707
		TPtr8 devDescrPtr = iBuffer->Des();
sl@0
   708
		devDescrPtr.FillZ(devDescrPtr.MaxLength());
sl@0
   709
sl@0
   710
		// USB version
sl@0
   711
		devDescrPtr[USB::KSpecOffset] = USBVersionLow;
sl@0
   712
		devDescrPtr[USB::KSpecOffset + 1] = USBVersionHigh;
sl@0
   713
sl@0
   714
		devDescrPtr[USB::KVendorOffset] = VendorIDLow;
sl@0
   715
		devDescrPtr[USB::KVendorOffset + 1] = VendorIDHigh;
sl@0
   716
sl@0
   717
		// product ID for test device
sl@0
   718
		devDescrPtr[USB::KProductIDOffset] = ProductIDLow;
sl@0
   719
		devDescrPtr[USB::KProductIDOffset + 1] = ProductIDHigh;
sl@0
   720
sl@0
   721
		// Set release number
sl@0
   722
		devDescrPtr[USB::KReleaseOffset] = ReleaseNumberLow;
sl@0
   723
		devDescrPtr[USB::KReleaseOffset + 1] = ReleaseNumberHigh;
sl@0
   724
sl@0
   725
		INFO_PRINTF1(_L("Setting device descriptors"));
sl@0
   726
		// Store the descriptors.
sl@0
   727
		error = iChannel->SetDeviceDescriptor(devDescrPtr);
sl@0
   728
		if (error != KErrNone)
sl@0
   729
			{
sl@0
   730
			ERR_PRINTF2(_L("Failed to set the device descriptor [%d]"),error);
sl@0
   731
			delete iBuffer;
sl@0
   732
			SetError(error);
sl@0
   733
			}
sl@0
   734
		else
sl@0
   735
			{
sl@0
   736
			delete iBuffer;
sl@0
   737
			iBuffer = NULL;
sl@0
   738
			}
sl@0
   739
		
sl@0
   740
		INFO_PRINTF1(_L("Device descriptors set"));
sl@0
   741
		}	
sl@0
   742
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdSetDeviceDescriptor"));
sl@0
   743
	}
sl@0
   744
sl@0
   745
/**
sl@0
   746
 * Sets USB EndPoints
sl@0
   747
 * @param aSection - The section in the ini containing data for the command
sl@0
   748
 */
sl@0
   749
sl@0
   750
void CT_RDevUsbcClientData::DoCmdUtilitySetEndPointL(const TTEFSectionName& aSection)
sl@0
   751
	{
sl@0
   752
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdUtilitySetEndPointL"));
sl@0
   753
	TPtrC16 mode;
sl@0
   754
	TBool dataOk = ETrue;
sl@0
   755
	if(!GetStringFromConfig(aSection, KMode, mode))
sl@0
   756
		{
sl@0
   757
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KMode);
sl@0
   758
		SetBlockResult(EFail);
sl@0
   759
		dataOk = EFalse;
sl@0
   760
		}
sl@0
   761
	TPtrC16 direction;
sl@0
   762
	if(!GetStringFromConfig(aSection, KDirection, direction))
sl@0
   763
		{
sl@0
   764
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDirection);
sl@0
   765
		SetBlockResult(EFail);
sl@0
   766
		dataOk = EFalse;
sl@0
   767
		}
sl@0
   768
	if(dataOk)
sl@0
   769
		{
sl@0
   770
		TInt error(KErrNone);	
sl@0
   771
		if(mode == USB::KEPBulk)
sl@0
   772
			{
sl@0
   773
			INFO_PRINTF1(_L("Selected mode is KEPBulk"));
sl@0
   774
			if(direction == USB::KEPIn)
sl@0
   775
				{
sl@0
   776
				error = SetEndpoint(KUsbEpTypeBulk, KUsbEpDirIn);
sl@0
   777
				if (error != KErrNone)
sl@0
   778
					{
sl@0
   779
					ERR_PRINTF2(_L("Failed to set end point direction to KEPIn with error [%d]"), error);
sl@0
   780
					SetBlockResult(EFail);					
sl@0
   781
					}
sl@0
   782
				}
sl@0
   783
			else if(direction == USB::KEPOut)
sl@0
   784
				{
sl@0
   785
				error = SetEndpoint(KUsbEpTypeBulk, KUsbEpDirOut);
sl@0
   786
				if (error != KErrNone)
sl@0
   787
					{
sl@0
   788
					ERR_PRINTF2(_L("Failed to set end point direction to KEPOut with error [%d]"), error);
sl@0
   789
					SetBlockResult(EFail);
sl@0
   790
					}
sl@0
   791
				}
sl@0
   792
			else
sl@0
   793
				{
sl@0
   794
				ERR_PRINTF2(_L("USB - INCORRECT direction %S"), direction.AllocL());
sl@0
   795
				SetBlockResult(EFail);
sl@0
   796
				}
sl@0
   797
			}
sl@0
   798
		else if(mode == USB::KEPInterrupt)
sl@0
   799
			{
sl@0
   800
			INFO_PRINTF1(_L("Selected mode is KEPInterrupt"));
sl@0
   801
			if(direction == USB::KEPIn)
sl@0
   802
				{
sl@0
   803
				error = SetEndpoint(KUsbEpTypeInterrupt, KUsbEpDirIn);
sl@0
   804
				if (error != KErrNone)
sl@0
   805
					{
sl@0
   806
					ERR_PRINTF2(_L("Failed to set end point direction to KEPIn with error [%d]"), error);
sl@0
   807
					SetBlockResult(EFail);
sl@0
   808
					}
sl@0
   809
				}
sl@0
   810
			else if(direction == USB::KEPOut)
sl@0
   811
				{
sl@0
   812
				error = SetEndpoint(KUsbEpTypeInterrupt, KUsbEpDirOut);
sl@0
   813
				if (error != KErrNone)
sl@0
   814
					{
sl@0
   815
					ERR_PRINTF2(_L("Failed to set end point direction to KEPOut with error [%d]"), error);
sl@0
   816
					SetBlockResult(EFail);
sl@0
   817
					}
sl@0
   818
				}
sl@0
   819
			else
sl@0
   820
				{
sl@0
   821
				ERR_PRINTF2(_L("USB - INCORRECT direction %S"), direction.AllocL());
sl@0
   822
				SetBlockResult(EFail);
sl@0
   823
				}
sl@0
   824
			}
sl@0
   825
		else
sl@0
   826
			{
sl@0
   827
			ERR_PRINTF2(_L("USB - Mode not supported %S"), mode.AllocL());
sl@0
   828
			SetBlockResult(EFail);
sl@0
   829
			}
sl@0
   830
		}			
sl@0
   831
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdUtilitySetEndPointL"));
sl@0
   832
	}
sl@0
   833
sl@0
   834
sl@0
   835
/**
sl@0
   836
 * Sets a new endpoint for interface handled by this channel
sl@0
   837
 * @param aEndpointType - USB endpoint type
sl@0
   838
 * @param aEndpointDirection - USB endpoint direction	
sl@0
   839
 */
sl@0
   840
TInt CT_RDevUsbcClientData::SetEndpoint(TUint aEndpointType, TUint aEndpointDirection)
sl@0
   841
	{
sl@0
   842
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::SetEndpoint"));
sl@0
   843
	if(iConfiguredEndpoints == KMaxEndpointsPerClient)
sl@0
   844
		{
sl@0
   845
		ERR_PRINTF2(_L("Maximum number of endpoints [%d] for clients reached "), KMaxEndpointsPerClient);
sl@0
   846
		SetBlockResult(EFail);
sl@0
   847
		return KErrArgument;
sl@0
   848
		}
sl@0
   849
sl@0
   850
	// search for the endpoints that match the settings user has given.
sl@0
   851
	for (TInt i = 0; i < iCaps().iTotalEndpoints; ++i)
sl@0
   852
		{
sl@0
   853
		const TUsbcEndpointCaps* caps = &iEndpointData[i].iCaps;
sl@0
   854
		const TInt maximumPacketSize = caps->MaxPacketSize();
sl@0
   855
sl@0
   856
		// Check if endpoint in question matches with parameters we want to use for configuring an endpoint
sl@0
   857
		if ( (caps->iTypesAndDir & (aEndpointType | aEndpointDirection)) == (aEndpointType | aEndpointDirection) )
sl@0
   858
			{
sl@0
   859
			INFO_PRINTF3(_L("Configuring %s endpoint with direction %s"),
sl@0
   860
				(aEndpointType == KUsbEpTypeControl) ? _S("Control") :
sl@0
   861
				((aEndpointType == KUsbEpTypeIsochronous) ? _S("Isochronous") :
sl@0
   862
				((aEndpointType == KUsbEpTypeBulk) ? _S("Bulk") :
sl@0
   863
				((aEndpointType == KUsbEpTypeInterrupt) ? _S("Interrupt") :
sl@0
   864
				_S("Unknown")))),
sl@0
   865
				(aEndpointDirection == KUsbEpDirIn) ? _S("In") :
sl@0
   866
				((aEndpointDirection == KUsbEpDirOut) ? _S("Out") :
sl@0
   867
				((aEndpointDirection == KUsbEpDirBidirect) ? _S("Bidirectional") :
sl@0
   868
				_S("Unknown")))
sl@0
   869
				);
sl@0
   870
sl@0
   871
			iInterface().iEndpointData[iConfiguredEndpoints].iType = aEndpointType;
sl@0
   872
			iInterface().iEndpointData[iConfiguredEndpoints].iDir = aEndpointDirection;
sl@0
   873
			iInterface().iEndpointData[iConfiguredEndpoints].iSize = maximumPacketSize;
sl@0
   874
			iTxMaxPacketSize = maximumPacketSize;
sl@0
   875
sl@0
   876
			iConfiguredEndpoints++;
sl@0
   877
sl@0
   878
			break;
sl@0
   879
			}
sl@0
   880
		}
sl@0
   881
sl@0
   882
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::SetEndpoint"));
sl@0
   883
	return KErrNone;
sl@0
   884
	}
sl@0
   885
sl@0
   886
sl@0
   887
sl@0
   888
/**
sl@0
   889
 * Sets interface with endpoints configured with CT_RDevUsbcClientData::SetEndpoint
sl@0
   890
 * Note that endpoints must be set before calling this method
sl@0
   891
 * 
sl@0
   892
 * @param aBandwithwidthBufferingMask TInt contains IN and OUT bandwidth buffering masks combined 
sl@0
   893
 *									 using binary OR operation
sl@0
   894
 *			NOTE: IT IS TEST CASE SCRIPTERS RESPONSIBILITY TO CHECK VALID (or invalid for negative cases) MASKS
sl@0
   895
 */
sl@0
   896
void CT_RDevUsbcClientData::DoCmdSetInterface(const TTEFSectionName& aSection)
sl@0
   897
	{
sl@0
   898
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdSetInterface"));
sl@0
   899
	TInt bandwidthBufferingMask;
sl@0
   900
	TBool dataOk = ETrue;
sl@0
   901
	if(!GetIntFromConfig(aSection, KBufferingMask, bandwidthBufferingMask))
sl@0
   902
		{
sl@0
   903
		ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KBufferingMask);
sl@0
   904
		SetBlockResult(EFail);
sl@0
   905
		dataOk = EFalse;
sl@0
   906
		}
sl@0
   907
	if(dataOk)
sl@0
   908
		{
sl@0
   909
		INFO_PRINTF2(_L("bandwidthBufferingMask %d"), bandwidthBufferingMask);
sl@0
   910
		INFO_PRINTF2(_L("Configuring the interface settings with %d endpoints"), iConfiguredEndpoints);
sl@0
   911
sl@0
   912
		if( iConfiguredEndpoints == 0 )
sl@0
   913
			{
sl@0
   914
			ERR_PRINTF1(_L("No endpoints have been set! Set endpoints before configuring interface"));
sl@0
   915
			SetBlockResult(EFail);
sl@0
   916
			}
sl@0
   917
		else
sl@0
   918
			{
sl@0
   919
			HBufC16* allocatedName = 0;
sl@0
   920
			TRAPD(error, allocatedName = interfaceName().AllocL());
sl@0
   921
		    if (error != KErrNone)
sl@0
   922
		        {
sl@0
   923
		        ERR_PRINTF2(_L("AllocL failed [%d]"), error);
sl@0
   924
		        SetBlockResult(EFail);
sl@0
   925
		        }
sl@0
   926
		    else
sl@0
   927
		    	{
sl@0
   928
		    	iInterface().iString = allocatedName;
sl@0
   929
				iInterface().iTotalEndpointsUsed = iConfiguredEndpoints;
sl@0
   930
				iInterface().iClass.iClassNum = 0xff;
sl@0
   931
				iInterface().iClass.iSubClassNum = 0xff;
sl@0
   932
				iInterface().iClass.iProtocolNum = 0xff;
sl@0
   933
				INFO_PRINTF2(_L("Using bandwidth buffering mask 0x%08x"), bandwidthBufferingMask);
sl@0
   934
sl@0
   935
				error = iChannel->SetInterface(0, iInterface, bandwidthBufferingMask);
sl@0
   936
sl@0
   937
				delete allocatedName;
sl@0
   938
				allocatedName = NULL;
sl@0
   939
				
sl@0
   940
				if (error != KErrNone)
sl@0
   941
					{
sl@0
   942
					ERR_PRINTF2(_L("Failed to set the interface [%d]"), error);
sl@0
   943
					SetError(error);
sl@0
   944
					}
sl@0
   945
				INFO_PRINTF2(_L("SetInterface returns [%d]"), error);
sl@0
   946
		    	}			
sl@0
   947
			}	    
sl@0
   948
		}
sl@0
   949
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdSetInterface"));
sl@0
   950
	}
sl@0
   951
sl@0
   952
sl@0
   953
sl@0
   954
sl@0
   955
/**
sl@0
   956
 * Tell test class to stop waiting 
sl@0
   957
 * @param result from callback
sl@0
   958
 */
sl@0
   959
void CT_RDevUsbcClientData::Signal(TInt aResult)
sl@0
   960
	{
sl@0
   961
	INFO_PRINTF2(_L("Signal %d"),aResult);
sl@0
   962
	}
sl@0
   963
sl@0
   964
sl@0
   965
/**
sl@0
   966
 * Destroyer
sl@0
   967
 */
sl@0
   968
sl@0
   969
void  CT_RDevUsbcClientData::DoCmdDestructor()
sl@0
   970
	{
sl@0
   971
	INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdDestructor"));
sl@0
   972
	DestroyData();
sl@0
   973
	INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdDestructor"));
sl@0
   974
	}
sl@0
   975
sl@0
   976
void CT_RDevUsbcClientData::DestroyData()
sl@0
   977
	{
sl@0
   978
	if(iChannel)
sl@0
   979
		{
sl@0
   980
		iChannel->Close();
sl@0
   981
		delete iChannel;
sl@0
   982
		iChannel = NULL;
sl@0
   983
		}
sl@0
   984
	}