os/kernelhwsrv/kerneltest/e32test/usb/t_usb_device/src/activerw.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2000-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
// e32test/usb/t_usb_device/src/activerw.cpp
sl@0
    15
// USB Test Program T_USB_DEVICE, functional part.
sl@0
    16
// Device-side part, to work against T_USB_HOST running on the host.
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
#include "general.h"									// CActiveControl, CActiveRW
sl@0
    21
#include "config.h"
sl@0
    22
#include "activerw.h"
sl@0
    23
#include "activetimer.h" 
sl@0
    24
#include "usblib.h"										// Helpers
sl@0
    25
sl@0
    26
_LIT(KFileName, "\\T_USBFILE.BIN");
sl@0
    27
sl@0
    28
extern RTest test;
sl@0
    29
extern TBool gVerbose;
sl@0
    30
extern TBool gSkip;
sl@0
    31
extern TBool gStopOnFail;
sl@0
    32
extern TBool gAltSettingOnNotify;
sl@0
    33
extern TInt8 gSettingNumber [128];
sl@0
    34
extern TInt gSoakCount;
sl@0
    35
extern CActiveRW* gRW[KMaxConcurrentTests];				// the USB read/write active object
sl@0
    36
extern IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings];
sl@0
    37
extern TInt gActiveTestCount;
sl@0
    38
sl@0
    39
static TInt gYieldRepeat = 0;
sl@0
    40
static const TInt KYieldRepeat = 100;
sl@0
    41
sl@0
    42
//
sl@0
    43
// --- class CActiveRW ---------------------------------------------------------
sl@0
    44
//
sl@0
    45
sl@0
    46
CActiveRW::CActiveRW(CConsoleBase* aConsole, RDEVCLIENT* aPort, RFs aFs, TUint16 aIndex, TBool aLastSetting)
sl@0
    47
	: CActive(EPriorityNormal),
sl@0
    48
		#ifndef USB_SC
sl@0
    49
		iWriteBuf((TUint8 *)NULL,0,0),		// temporary initialisation
sl@0
    50
		iReadBuf((TUint8 *)NULL,0,0),		// temporary initialisation	
sl@0
    51
	  	#endif
sl@0
    52
	  iConsole(aConsole),
sl@0
    53
	  iPort(aPort),
sl@0
    54
	  iBufSz(0),
sl@0
    55
	  iMaxPktSz(0),
sl@0
    56
	  iCurrentXfer(ETxferNone),
sl@0
    57
	  iXferMode(::ENone),
sl@0
    58
	  iDoStop(EFalse),
sl@0
    59
	  iPktNum(0),
sl@0
    60
	  iFs(aFs),
sl@0
    61
	  iRepeat(0),
sl@0
    62
	  iComplete(EFalse),
sl@0
    63
	  iResult(EFalse),
sl@0
    64
	  iIndex (aIndex),
sl@0
    65
	  iLastSetting (aLastSetting)
sl@0
    66
	{
sl@0
    67
	gActiveTestCount++;
sl@0
    68
	TUSB_VERBOSE_PRINT("CActiveRW::CActiveRW()");
sl@0
    69
	}
sl@0
    70
sl@0
    71
sl@0
    72
CActiveRW* CActiveRW::NewL(CConsoleBase* aConsole, RDEVCLIENT* aPort, RFs aFs, TUint16 aIndex, TBool aLastSetting)
sl@0
    73
	{
sl@0
    74
	TUSB_VERBOSE_APRINT("CActiveRW::NewL()");
sl@0
    75
sl@0
    76
	CActiveRW* self = new (ELeave) CActiveRW(aConsole, aPort, aFs, aIndex, aLastSetting);
sl@0
    77
	CleanupStack::PushL(self);
sl@0
    78
	self->ConstructL();
sl@0
    79
	CActiveScheduler::Add(self);
sl@0
    80
	CleanupStack::Pop();									// self
sl@0
    81
	return self;
sl@0
    82
	}
sl@0
    83
sl@0
    84
sl@0
    85
void CActiveRW::ConstructL()
sl@0
    86
	{
sl@0
    87
	TUSB_VERBOSE_PRINT("CActiveRW::ConstructL()");
sl@0
    88
sl@0
    89
	// Create read timeout timer active object (but don't activate it yet)
sl@0
    90
	iTimeoutTimer = CActiveTimer::NewL(iConsole, iPort);
sl@0
    91
	if (!iTimeoutTimer)
sl@0
    92
		{
sl@0
    93
		TUSB_PRINT("Failed to create timeout timer");
sl@0
    94
		}
sl@0
    95
	}
sl@0
    96
sl@0
    97
sl@0
    98
CActiveRW::~CActiveRW()
sl@0
    99
	{
sl@0
   100
	TUSB_VERBOSE_PRINT("CActiveRW::~CActiveRW()");
sl@0
   101
	Cancel();												// base class
sl@0
   102
	delete iTimeoutTimer;
sl@0
   103
	#ifdef USB_SC
sl@0
   104
	if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
sl@0
   105
		{
sl@0
   106
		iSCReadBuf.Close();
sl@0
   107
		}
sl@0
   108
	if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
sl@0
   109
		{
sl@0
   110
		iSCWriteBuf.Close();
sl@0
   111
		}
sl@0
   112
	#else
sl@0
   113
	User::Free((TAny *)iReadBuf.Ptr());
sl@0
   114
	User::Free((TAny *)iWriteBuf.Ptr());
sl@0
   115
	#endif
sl@0
   116
	iFile.Close();
sl@0
   117
	gRW[iIndex] = NULL;
sl@0
   118
	gActiveTestCount--;
sl@0
   119
	}
sl@0
   120
sl@0
   121
sl@0
   122
void CActiveRW::SetTestParams(TestParamPtr aTpPtr)
sl@0
   123
	{
sl@0
   124
	iBufSz = aTpPtr->minSize;
sl@0
   125
	iPktNum = aTpPtr->packetNumber;
sl@0
   126
	
sl@0
   127
	iTestParams = *aTpPtr;
sl@0
   128
sl@0
   129
	gYieldRepeat = ((iTestParams.settingRepeat != 0) || (iIndex == 0))? 0 : KYieldRepeat;
sl@0
   130
sl@0
   131
	if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
sl@0
   132
		{
sl@0
   133
		#ifndef USB_SC
sl@0
   134
		TAny * newBuffer = User::Alloc(aTpPtr->maxSize);
sl@0
   135
		if (newBuffer == NULL)
sl@0
   136
			{
sl@0
   137
			TUSB_PRINT ("Failure to allocate heap memory");
sl@0
   138
			test(EFalse);
sl@0
   139
			}
sl@0
   140
		iReadBuf.Set((TUint8 *)newBuffer,0,(TInt)aTpPtr->maxSize);
sl@0
   141
		#endif
sl@0
   142
		TBuf8<KUsbDescSize_Endpoint> descriptor;
sl@0
   143
		TUSB_VERBOSE_PRINT2 ("GetEndpointDescriptor Alt Setting %d Endpoint %d",iTestParams.alternateSetting, iTestParams.outPipe);
sl@0
   144
		TInt r = iPort->GetEndpointDescriptor(iTestParams.alternateSetting, (TENDPOINTNUMBER)iTestParams.outPipe, descriptor);
sl@0
   145
		if ((TUint)r != iReadSize)
sl@0
   146
			{
sl@0
   147
			TUSB_PRINT("Failed to get endpoint descriptor");
sl@0
   148
			test(EFalse);
sl@0
   149
			return;
sl@0
   150
			}
sl@0
   151
sl@0
   152
		iMaxPktSz = EpSize(descriptor[KEpDesc_PacketSizeOffset],descriptor[KEpDesc_PacketSizeOffset+1]);		
sl@0
   153
		TUSB_VERBOSE_PRINT5 ("Out Endpoint 0x%x attributes 0x%x interface %d setting %d max packet size %d",
sl@0
   154
			descriptor[KEpDesc_AddressOffset],descriptor[KEpDesc_AttributesOffset],iTestParams.interfaceNumber,iTestParams.alternateSetting,iMaxPktSz);
sl@0
   155
		if (!gSkip && iMaxPktSz != (TUint)gInterfaceConfig[iTestParams.interfaceNumber][iTestParams.alternateSetting]->iInfoPtr->iEndpointData[iTestParams.outPipe-1].iSize)
sl@0
   156
			{
sl@0
   157
			TUSB_PRINT4("Error - Interface %d Setting %d Endpoint %d Max Packet Size %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iMaxPktSz);
sl@0
   158
			test(EFalse);
sl@0
   159
			return;
sl@0
   160
			}
sl@0
   161
		}
sl@0
   162
	if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
sl@0
   163
		{
sl@0
   164
		#ifndef USB_SC
sl@0
   165
		TAny * newBuffer = User::Alloc(aTpPtr->maxSize);
sl@0
   166
		if (newBuffer == NULL)
sl@0
   167
			{
sl@0
   168
			TUSB_PRINT ("Failure to allocate heap memory");
sl@0
   169
			test(EFalse);
sl@0
   170
			}
sl@0
   171
		iWriteBuf.Set((TUint8 *)newBuffer,0,(TInt)aTpPtr->maxSize);
sl@0
   172
		#endif
sl@0
   173
		TBuf8<KUsbDescSize_Endpoint> descriptor;
sl@0
   174
		TUSB_VERBOSE_PRINT2 ("GetEndpointDescriptor Alt Setting %d Endpoint %d",iTestParams.alternateSetting, iTestParams.inPipe);
sl@0
   175
		TInt r = iPort->GetEndpointDescriptor(iTestParams.alternateSetting, (TENDPOINTNUMBER)iTestParams.inPipe, descriptor);
sl@0
   176
		if (r != KErrNone)
sl@0
   177
			{
sl@0
   178
			TUSB_PRINT("Failed to get endpoint descriptor");
sl@0
   179
			test(EFalse);
sl@0
   180
			return;
sl@0
   181
			}
sl@0
   182
sl@0
   183
		TInt maxPktSz = EpSize(descriptor[KEpDesc_PacketSizeOffset],descriptor[KEpDesc_PacketSizeOffset+1]);		
sl@0
   184
		TUSB_VERBOSE_PRINT5 ("In Endpoint 0x%x attributes 0x%x interface %d setting %d max packet size %d",
sl@0
   185
			descriptor[KEpDesc_AddressOffset],descriptor[KEpDesc_AttributesOffset],iTestParams.interfaceNumber,iTestParams.alternateSetting,maxPktSz);
sl@0
   186
		if (!gSkip && maxPktSz != gInterfaceConfig[iTestParams.interfaceNumber][iTestParams.alternateSetting]->iInfoPtr->iEndpointData[iTestParams.inPipe-1].iSize)
sl@0
   187
			{
sl@0
   188
			TUSB_PRINT4("Error - Interface %d Setting %d Endpoint %d Max Packet Size %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe,maxPktSz);
sl@0
   189
			test(EFalse);
sl@0
   190
			return;
sl@0
   191
			}
sl@0
   192
		}
sl@0
   193
		
sl@0
   194
	}
sl@0
   195
sl@0
   196
sl@0
   197
void CActiveRW::SetTransferMode(TXferMode aMode)
sl@0
   198
	{
sl@0
   199
	iXferMode = aMode;
sl@0
   200
	if (aMode == EReceiveOnly || aMode == ETransmitOnly)
sl@0
   201
		{
sl@0
   202
		// For streaming transfers we do this only once.
sl@0
   203
		iBufSz = iTestParams.maxSize;
sl@0
   204
		}
sl@0
   205
	}
sl@0
   206
sl@0
   207
void CActiveRW::Suspend(TXferType aType)
sl@0
   208
	{
sl@0
   209
	if (aType == ESuspend)
sl@0
   210
		TUSB_VERBOSE_PRINT1("Index %d Suspend",iIndex);
sl@0
   211
	if (aType == EAltSetting)
sl@0
   212
		TUSB_VERBOSE_PRINT3("Index %d Suspend for Alternate Setting - interface %d setting %d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);	
sl@0
   213
	iStatus = KRequestPending;
sl@0
   214
	iCurrentXfer = aType;
sl@0
   215
	if (!IsActive())
sl@0
   216
		{
sl@0
   217
		SetActive();
sl@0
   218
		}
sl@0
   219
	}
sl@0
   220
sl@0
   221
void CActiveRW::Resume()
sl@0
   222
	{	
sl@0
   223
	TUSB_VERBOSE_PRINT3("Index %d Resume interface %d setting %d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);
sl@0
   224
	TRequestStatus* status = &iStatus;
sl@0
   225
	User::RequestComplete(status,KErrNone);
sl@0
   226
	if (!IsActive())
sl@0
   227
		{
sl@0
   228
		SetActive();
sl@0
   229
		}
sl@0
   230
	}
sl@0
   231
sl@0
   232
void CActiveRW::Yield()
sl@0
   233
	{
sl@0
   234
	TUSB_VERBOSE_PRINT1("Index %d Scheduler Yield",iIndex);
sl@0
   235
	// removes the active object from the scheduler queue then adds it back in again
sl@0
   236
	Deque();	
sl@0
   237
	CActiveScheduler::Add(this);
sl@0
   238
	}
sl@0
   239
sl@0
   240
void CActiveRW::ResumeAltSetting(TUint aAltSetting)
sl@0
   241
	{
sl@0
   242
	if (iCurrentXfer == EAltSetting && iTestParams.alternateSetting == aAltSetting)
sl@0
   243
		{
sl@0
   244
		Resume();
sl@0
   245
		}
sl@0
   246
	}
sl@0
   247
sl@0
   248
void CActiveRW::StartOrSuspend()
sl@0
   249
	{
sl@0
   250
	TInt altSetting;
sl@0
   251
	
sl@0
   252
	iPort->GetAlternateSetting (altSetting);
sl@0
   253
	if (iTestParams.alternateSetting != altSetting)
sl@0
   254
		{
sl@0
   255
		Suspend(EAltSetting);
sl@0
   256
		}
sl@0
   257
	else
sl@0
   258
		{
sl@0
   259
		#ifdef USB_SC
sl@0
   260
		TInt r;
sl@0
   261
		if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
sl@0
   262
			{
sl@0
   263
			gSettingNumber[iTestParams.interfaceNumber] = iTestParams.alternateSetting;
sl@0
   264
			r = iPort->StartNextOutAlternateSetting(ETrue);
sl@0
   265
			TUSB_VERBOSE_PRINT1("StartNextOutAlternateSetting retValue %d",r);
sl@0
   266
			test_Value(r, (r >= KErrNone) || (r == KErrNotReady)   || (r == KErrGeneral));
sl@0
   267
			}
sl@0
   268
		TUSB_VERBOSE_PRINT4 ("CActiveRW::StartOrSuspend() interface %d setting %d Out %d In %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iTestParams.inPipe);
sl@0
   269
		if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
sl@0
   270
			{
sl@0
   271
			r = iPort->OpenEndpoint(iSCReadBuf,iTestParams.outPipe);
sl@0
   272
			test_KErrNone(r);
sl@0
   273
			}
sl@0
   274
		if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
sl@0
   275
			{
sl@0
   276
			r = iPort->OpenEndpoint(iSCWriteBuf,iTestParams.inPipe);
sl@0
   277
			test_KErrNone(r);
sl@0
   278
			}
sl@0
   279
		#endif
sl@0
   280
		if (iXferMode == EReceiveOnly)
sl@0
   281
			{
sl@0
   282
			// read data and process any available
sl@0
   283
			iReadSize = ReadData();
sl@0
   284
			if (iReadSize != 0)
sl@0
   285
				{
sl@0
   286
				ProcessReadXfer();
sl@0
   287
				}
sl@0
   288
			}
sl@0
   289
		else
sl@0
   290
			{
sl@0
   291
			SendData();										// or we send data
sl@0
   292
			if (iXferMode == ETransmitOnly)
sl@0
   293
				{
sl@0
   294
				iPktNum++;				
sl@0
   295
				iRepeat++;		
sl@0
   296
				}
sl@0
   297
			}	
sl@0
   298
		}
sl@0
   299
	}
sl@0
   300
sl@0
   301
void CActiveRW::RunL()
sl@0
   302
	{
sl@0
   303
	#ifdef USB_SC
sl@0
   304
	TInt r = 0;
sl@0
   305
	#else
sl@0
   306
	TInt altSetting;	
sl@0
   307
	#endif
sl@0
   308
	
sl@0
   309
	TUSB_VERBOSE_PRINT("CActiveRW::RunL()");
sl@0
   310
sl@0
   311
	if ((iStatus != KErrNone) && (iStatus != KErrEof))
sl@0
   312
		{
sl@0
   313
		TUSB_PRINT1("Error %d in RunL", iStatus.Int());
sl@0
   314
		}
sl@0
   315
	if (iDoStop)
sl@0
   316
		{
sl@0
   317
		TUSB_PRINT("Stopped");
sl@0
   318
		iDoStop = EFalse;
sl@0
   319
		return;
sl@0
   320
		}
sl@0
   321
	switch (iCurrentXfer)
sl@0
   322
		{
sl@0
   323
	case EWaitSetting:
sl@0
   324
		#ifdef USB_SC
sl@0
   325
		if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
sl@0
   326
			{
sl@0
   327
			r = iSCReadBuf.Close();
sl@0
   328
			test_KErrNone(r);
sl@0
   329
			}
sl@0
   330
		if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
sl@0
   331
			{
sl@0
   332
			r = iSCWriteBuf.Close();
sl@0
   333
			test_KErrNone(r);
sl@0
   334
			}
sl@0
   335
		#endif
sl@0
   336
		if (iTestParams.settingRepeat  && ((iRepeat < iTestParams.repeat) || !iLastSetting))
sl@0
   337
			{
sl@0
   338
			gRW[iTestParams.afterIndex]->Resume();			
sl@0
   339
			}
sl@0
   340
		Suspend(ESuspend);	
sl@0
   341
		break;
sl@0
   342
			
sl@0
   343
	case ESuspend:
sl@0
   344
		#ifdef USB_SC
sl@0
   345
		TUSB_VERBOSE_PRINT3("Index %d Resumed interface %d setting test=%d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting);	
sl@0
   346
		if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
sl@0
   347
			{
sl@0
   348
			r = iPort->StartNextOutAlternateSetting(ETrue);
sl@0
   349
			TUSB_VERBOSE_PRINT1("StartNextOutAlternateSetting retValue %d",r);
sl@0
   350
			test_Value(r, (r >= KErrNone) || (r == KErrNotReady)  || (r == KErrGeneral));
sl@0
   351
			if (r != KErrNotReady)
sl@0
   352
				{
sl@0
   353
				gSettingNumber[iTestParams.interfaceNumber] = r;
sl@0
   354
				}
sl@0
   355
			if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
sl@0
   356
				{
sl@0
   357
				Suspend(EAltSetting);
sl@0
   358
				break;
sl@0
   359
				}
sl@0
   360
			}
sl@0
   361
		#else
sl@0
   362
		iPort->GetAlternateSetting (altSetting);
sl@0
   363
		TUSB_VERBOSE_PRINT4("Index %d Resumed interface %d setting test=%d actual=%d",iIndex,iTestParams.interfaceNumber,iTestParams.alternateSetting,altSetting);	
sl@0
   364
		if (gAltSettingOnNotify)
sl@0
   365
			{
sl@0
   366
			if (iTestParams.alternateSetting != altSetting)
sl@0
   367
				{
sl@0
   368
				Suspend(EAltSetting);
sl@0
   369
				break;
sl@0
   370
				}
sl@0
   371
			}
sl@0
   372
		#endif
sl@0
   373
			
sl@0
   374
		// If alternate setting is ok drops through to EAltSetting to start next read or write
sl@0
   375
		iCurrentXfer = EAltSetting;
sl@0
   376
			
sl@0
   377
	case EAltSetting:
sl@0
   378
		#ifdef USB_SC
sl@0
   379
		if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
sl@0
   380
			{
sl@0
   381
			r = iPort->StartNextOutAlternateSetting(ETrue);
sl@0
   382
			TUSB_VERBOSE_PRINT1("StartNextOutAlternateSetting retValue %d",r);
sl@0
   383
			test_Value(r, (r >= KErrNone) || (r == KErrNotReady)   || (r == KErrGeneral));
sl@0
   384
			if (r != KErrNotReady)
sl@0
   385
				{
sl@0
   386
				gSettingNumber[iTestParams.interfaceNumber] = r;
sl@0
   387
				}
sl@0
   388
			if (iTestParams.alternateSetting != gSettingNumber[iTestParams.interfaceNumber])
sl@0
   389
				{
sl@0
   390
				Suspend(EAltSetting);
sl@0
   391
				break;
sl@0
   392
				}
sl@0
   393
			}
sl@0
   394
		TUSB_VERBOSE_PRINT4 ("CActiveRW::Runl() EAltSetting interface %d setting %d Out %d In %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe,iTestParams.inPipe);
sl@0
   395
		if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
sl@0
   396
			{
sl@0
   397
			r = iPort->OpenEndpoint(iSCReadBuf,iTestParams.outPipe);
sl@0
   398
			test_KErrNone(r);
sl@0
   399
			}
sl@0
   400
		if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
sl@0
   401
			{
sl@0
   402
			r = iPort->OpenEndpoint(iSCWriteBuf,iTestParams.inPipe);
sl@0
   403
			test_KErrNone(r);
sl@0
   404
			}
sl@0
   405
		#endif
sl@0
   406
		if (iXferMode == EReceiveOnly)
sl@0
   407
			{
sl@0
   408
			// read data and process any available
sl@0
   409
			iReadSize = ReadData();
sl@0
   410
			if (iReadSize != 0)
sl@0
   411
				{
sl@0
   412
				ProcessReadXfer();
sl@0
   413
				}		
sl@0
   414
			}
sl@0
   415
		else
sl@0
   416
			{
sl@0
   417
			SendData();										// or we send data
sl@0
   418
			if (iXferMode == ETransmitOnly)
sl@0
   419
				{
sl@0
   420
				iPktNum++;				
sl@0
   421
				iRepeat++;		
sl@0
   422
				}
sl@0
   423
			}
sl@0
   424
		break;
sl@0
   425
sl@0
   426
	case EWriteXfer:
sl@0
   427
		ProcessWriteXfer();
sl@0
   428
		break;
sl@0
   429
		
sl@0
   430
	case EReadXfer:
sl@0
   431
		#ifdef USB_SC
sl@0
   432
		iReadSize = ReadData();
sl@0
   433
		if (iReadSize != 0)
sl@0
   434
			{
sl@0
   435
			ProcessReadXfer();
sl@0
   436
			}
sl@0
   437
		#else
sl@0
   438
		iReadSize = iReadBuf.Length();
sl@0
   439
		ProcessReadXfer();
sl@0
   440
		#endif
sl@0
   441
		break;
sl@0
   442
		
sl@0
   443
	default:
sl@0
   444
		TUSB_PRINT("Oops. (Shouldn't end up here...)");
sl@0
   445
		break;
sl@0
   446
		}
sl@0
   447
	return;
sl@0
   448
	}
sl@0
   449
sl@0
   450
void CActiveRW::ProcessWriteXfer()
sl@0
   451
	{
sl@0
   452
	if (iXferMode == ETransmitOnly)
sl@0
   453
		{
sl@0
   454
		if (iTestParams.settingRepeat && iRepeat)
sl@0
   455
			{	
sl@0
   456
			if (((iRepeat % iTestParams.settingRepeat) == 0) || (iRepeat >= iTestParams.repeat))
sl@0
   457
				{
sl@0
   458
				if ((iRepeat < iTestParams.repeat) || !iLastSetting)
sl@0
   459
					{
sl@0
   460
					#ifdef USB_SC
sl@0
   461
					if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
sl@0
   462
						{
sl@0
   463
						test_KErrNone(iSCWriteBuf.Close());
sl@0
   464
						}
sl@0
   465
					#endif
sl@0
   466
					gRW[iTestParams.afterIndex]->Resume();			
sl@0
   467
					}
sl@0
   468
				if (iRepeat < iTestParams.repeat)
sl@0
   469
					{
sl@0
   470
					Suspend(ESuspend);	
sl@0
   471
					return;					
sl@0
   472
					}
sl@0
   473
				}
sl@0
   474
			}
sl@0
   475
sl@0
   476
		if ((iTestParams.repeat == 0) || (iRepeat < iTestParams.repeat))
sl@0
   477
			{
sl@0
   478
			// Yield the scheduler to ensure other activeObjects can run
sl@0
   479
			if (iRepeat && gYieldRepeat)
sl@0
   480
				{
sl@0
   481
				if ((iRepeat % gYieldRepeat) == 0)
sl@0
   482
					{
sl@0
   483
					Yield();
sl@0
   484
					}
sl@0
   485
				}
sl@0
   486
			SendData();							// next we send data			
sl@0
   487
			iPktNum++;				
sl@0
   488
			iRepeat++;
sl@0
   489
			}
sl@0
   490
		else
sl@0
   491
			{
sl@0
   492
			TestComplete(ETrue);
sl@0
   493
			}
sl@0
   494
		}
sl@0
   495
	else
sl@0
   496
		{
sl@0
   497
		// read data and process any available
sl@0
   498
		iReadSize = ReadData();
sl@0
   499
		if (iReadSize != 0)
sl@0
   500
			{
sl@0
   501
			ProcessReadXfer();
sl@0
   502
			}
sl@0
   503
		}
sl@0
   504
sl@0
   505
	return;
sl@0
   506
	}
sl@0
   507
sl@0
   508
void CActiveRW::ProcessReadXfer()
sl@0
   509
	{
sl@0
   510
	if ((iReadOffset + iReadSize) > iBufSz)
sl@0
   511
		{
sl@0
   512
		TUSB_PRINT2("*** rcv'd too much data: 0x%x (expected: 0x%x)", iReadOffset + iReadSize, iBufSz);
sl@0
   513
		test(EFalse);
sl@0
   514
		}
sl@0
   515
sl@0
   516
	if (iXferMode == EReceiveOnly)
sl@0
   517
		{
sl@0
   518
		if (iReadOffset == 0)
sl@0
   519
			{
sl@0
   520
			#ifdef USB_SC
sl@0
   521
			const TUint32 num = *reinterpret_cast<const TUint32*>(iSCReadData);
sl@0
   522
			#else
sl@0
   523
			const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr());
sl@0
   524
			#endif	
sl@0
   525
			if (num != iPktNum)
sl@0
   526
				{
sl@0
   527
				TUSB_PRINT3("*** Repeat %d rcv'd wrong pkt number: 0x%x (expected: 0x%x)", iRepeat, num, iPktNum);
sl@0
   528
				iPktNum = num;
sl@0
   529
				test(EFalse);
sl@0
   530
				}
sl@0
   531
			}
sl@0
   532
		if (iDiskAccessEnabled)
sl@0
   533
			{
sl@0
   534
			// Write out to disk previous completed Read
sl@0
   535
			#ifdef USB_SC
sl@0
   536
			TPtr8 readBuf((TUint8 *)iSCReadData,iReadSize,iReadSize);
sl@0
   537
			WriteBufferToDisk(readBuf, iReadSize);
sl@0
   538
			#else	
sl@0
   539
			TUSB_VERBOSE_PRINT2("Max Buffer Size = %d (iReadBuf.Size(): %d)", iTestParams.maxSize, iReadBuf.Size());
sl@0
   540
			WriteBufferToDisk(iReadBuf, iTestParams.maxSize);
sl@0
   541
			#endif
sl@0
   542
			}		
sl@0
   543
		iReadOffset += iReadSize;
sl@0
   544
		if (iReadOffset >= iBufSz)
sl@0
   545
			{
sl@0
   546
			iReadOffset = 0;			
sl@0
   547
			}
sl@0
   548
		else
sl@0
   549
			{
sl@0
   550
			#ifdef USB_SC
sl@0
   551
			iReadSize = ReadData();
sl@0
   552
			if (iReadSize)
sl@0
   553
				{
sl@0
   554
				ProcessReadXfer();
sl@0
   555
				}
sl@0
   556
			#endif
sl@0
   557
			return;
sl@0
   558
			}
sl@0
   559
		iPktNum++;
sl@0
   560
		iRepeat++;
sl@0
   561
		iReadSize = 0;
sl@0
   562
		if (iTestParams.settingRepeat)
sl@0
   563
			{	
sl@0
   564
			if (((iRepeat % iTestParams.settingRepeat) == 0) || (iRepeat >= iTestParams.repeat))
sl@0
   565
				{
sl@0
   566
				#ifdef USB_SC
sl@0
   567
				if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
sl@0
   568
					{
sl@0
   569
					test_KErrNone(iSCReadBuf.Close());
sl@0
   570
					}
sl@0
   571
				#endif
sl@0
   572
				if ((iRepeat < iTestParams.repeat) || !iLastSetting)
sl@0
   573
					{
sl@0
   574
					gRW[iTestParams.afterIndex]->Resume();			
sl@0
   575
					}
sl@0
   576
				if (iRepeat < iTestParams.repeat)
sl@0
   577
					{
sl@0
   578
					Suspend(ESuspend);	
sl@0
   579
					return;					
sl@0
   580
					}
sl@0
   581
				}
sl@0
   582
			}
sl@0
   583
		if ((iTestParams.repeat == 0) || (iRepeat < iTestParams.repeat))
sl@0
   584
			{
sl@0
   585
			// Yield the scheduler to ensure other activeObjects can run
sl@0
   586
			if (iRepeat && gYieldRepeat)
sl@0
   587
				{
sl@0
   588
				if ((iRepeat % gYieldRepeat) == 0)
sl@0
   589
					{
sl@0
   590
					Yield();
sl@0
   591
					}
sl@0
   592
				}
sl@0
   593
			#ifdef USB_SC
sl@0
   594
			TRequestStatus* status = &iStatus;
sl@0
   595
			User::RequestComplete(status,KErrNone);
sl@0
   596
			if (!IsActive())
sl@0
   597
				{
sl@0
   598
				SetActive();
sl@0
   599
				}	
sl@0
   600
			#else
sl@0
   601
			iReadSize = ReadData();			
sl@0
   602
			#endif
sl@0
   603
			}
sl@0
   604
		else
sl@0
   605
			{
sl@0
   606
			TestComplete(ETrue);
sl@0
   607
			}
sl@0
   608
		}
sl@0
   609
	else
sl@0
   610
		{
sl@0
   611
		if (iXferMode == ELoopComp)
sl@0
   612
			{
sl@0
   613
			test(CompareBuffers());
sl@0
   614
			}
sl@0
   615
		else if (iBufSz > 3)
sl@0
   616
			{
sl@0
   617
			if (iReadOffset == 0)
sl@0
   618
				{
sl@0
   619
				#ifdef USB_SC
sl@0
   620
				const TUint32 num = *reinterpret_cast<const TUint32*>(iSCReadData);
sl@0
   621
				#else
sl@0
   622
				const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr());
sl@0
   623
				#endif
sl@0
   624
				if (num != iPktNum)
sl@0
   625
					{
sl@0
   626
					TUSB_PRINT2("*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum);
sl@0
   627
					}
sl@0
   628
				}
sl@0
   629
			}
sl@0
   630
		iReadOffset += iReadSize;
sl@0
   631
		if (iReadOffset >= iBufSz)
sl@0
   632
			{
sl@0
   633
			iReadOffset = 0;			
sl@0
   634
			}
sl@0
   635
		else
sl@0
   636
			{
sl@0
   637
			iReadSize = ReadData();
sl@0
   638
			if (iReadSize)
sl@0
   639
				{
sl@0
   640
				ProcessReadXfer();
sl@0
   641
				}
sl@0
   642
			return;
sl@0
   643
			}
sl@0
   644
		if ((TUint)iBufSz == iTestParams.maxSize)
sl@0
   645
			{
sl@0
   646
			iBufSz = iTestParams.minSize;
sl@0
   647
			}
sl@0
   648
		else
sl@0
   649
			{
sl@0
   650
			iBufSz++;
sl@0
   651
			}
sl@0
   652
		iPktNum++;
sl@0
   653
		iRepeat++;
sl@0
   654
		iReadSize = 0;
sl@0
   655
		if (iTestParams.settingRepeat)
sl@0
   656
			{	
sl@0
   657
			if (((iRepeat % iTestParams.settingRepeat) == 0) || (iRepeat >= iTestParams.repeat))
sl@0
   658
				{
sl@0
   659
				if (iRepeat < iTestParams.repeat)
sl@0
   660
					{
sl@0
   661
					SendWaitSetting();
sl@0
   662
					return;					
sl@0
   663
					}
sl@0
   664
				else
sl@0
   665
					{
sl@0
   666
					#ifdef USB_SC
sl@0
   667
					if ((TENDPOINTNUMBER)iTestParams.outPipe <= KMaxEndpointsPerClient)
sl@0
   668
						{
sl@0
   669
						test_KErrNone(iSCReadBuf.Close());
sl@0
   670
						}
sl@0
   671
					if ((TENDPOINTNUMBER)iTestParams.inPipe <= KMaxEndpointsPerClient)
sl@0
   672
						{
sl@0
   673
						test_KErrNone(iSCWriteBuf.Close());
sl@0
   674
						}
sl@0
   675
					#endif	
sl@0
   676
					if (!iLastSetting)
sl@0
   677
						{
sl@0
   678
						gRW[iTestParams.afterIndex]->Resume();			
sl@0
   679
						}
sl@0
   680
					}
sl@0
   681
				}
sl@0
   682
			}
sl@0
   683
			
sl@0
   684
		if ((iTestParams.repeat == 0) || (iRepeat < iTestParams.repeat))
sl@0
   685
			{
sl@0
   686
			// Yield the scheduler to ensure other activeObjects can run
sl@0
   687
			if (iRepeat && gYieldRepeat)
sl@0
   688
				{
sl@0
   689
				if ((iRepeat % gYieldRepeat) == 0)
sl@0
   690
					{
sl@0
   691
					Yield();
sl@0
   692
					}
sl@0
   693
				}
sl@0
   694
			SendData();				
sl@0
   695
			}
sl@0
   696
		else
sl@0
   697
			{
sl@0
   698
			TestComplete(ETrue);
sl@0
   699
			}	
sl@0
   700
		}
sl@0
   701
sl@0
   702
	return;
sl@0
   703
	}
sl@0
   704
sl@0
   705
void CActiveRW::SendWaitSetting()
sl@0
   706
	{
sl@0
   707
	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 662));
sl@0
   708
	#ifdef	USB_SC
sl@0
   709
	TAny* inBuffer;
sl@0
   710
	TUint inBufLength;
sl@0
   711
	test_KErrNone(iSCWriteBuf.GetInBufferRange(inBuffer, inBufLength));
sl@0
   712
	test_KErrNone(iSCWriteBuf.WriteBuffer(inBuffer,KWaitSettingSize,FALSE,iStatus));
sl@0
   713
	#else
sl@0
   714
	iWriteBuf.SetLength(KWaitSettingSize);
sl@0
   715
	iPort->Write(iStatus, (TENDPOINTNUMBER)iTestParams.inPipe, iWriteBuf, KWaitSettingSize);
sl@0
   716
	#endif
sl@0
   717
	iCurrentXfer = EWaitSetting;
sl@0
   718
	if (!IsActive())
sl@0
   719
		{
sl@0
   720
		SetActive();
sl@0
   721
		}
sl@0
   722
	}
sl@0
   723
sl@0
   724
	
sl@0
   725
void CActiveRW::SendData()
sl@0
   726
	{
sl@0
   727
	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 663));
sl@0
   728
	#ifdef	USB_SC
sl@0
   729
	TUint8* inBuffer;
sl@0
   730
	TUint inBufLength;
sl@0
   731
	test_KErrNone(iSCWriteBuf.GetInBufferRange((TAny*&)inBuffer, inBufLength));
sl@0
   732
	if (iDiskAccessEnabled)
sl@0
   733
		{
sl@0
   734
		TPtr8 writeBuf((TUint8 *)inBuffer,iBufSz,iBufSz);
sl@0
   735
		ReadBufferFromDisk(writeBuf, iBufSz);
sl@0
   736
		}
sl@0
   737
	if (iBufSz > 3)
sl@0
   738
		*reinterpret_cast<TUint32*>(inBuffer) = iPktNum;
sl@0
   739
	
sl@0
   740
	if (iXferMode == ELoopComp)
sl@0
   741
		{
sl@0
   742
		for (TUint i = 4; i < iBufSz; i++)
sl@0
   743
			{
sl@0
   744
			*(inBuffer+i) = static_cast<TUint8>((iPktNum+i) & 0x000000ff);
sl@0
   745
			}
sl@0
   746
		}
sl@0
   747
	TUSB_VERBOSE_PRINT3("SendData interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe);
sl@0
   748
	iCurrentXfer = EWriteXfer;
sl@0
   749
	TInt r = iSCWriteBuf.WriteBuffer(inBuffer, iBufSz, FALSE, iStatus);
sl@0
   750
	test_KErrNone(r);
sl@0
   751
	#else
sl@0
   752
	if (iDiskAccessEnabled)
sl@0
   753
		{
sl@0
   754
		ReadBufferFromDisk(iWriteBuf, iBufSz);
sl@0
   755
		}
sl@0
   756
	iWriteBuf.SetLength(iBufSz);
sl@0
   757
	if (iBufSz > 3)
sl@0
   758
		*reinterpret_cast<TUint32*>(const_cast<TUint8*>(iWriteBuf.Ptr())) = iPktNum;
sl@0
   759
	if (iXferMode == ELoopComp)
sl@0
   760
		{
sl@0
   761
		for (TUint i = 4; i < iBufSz; i++)
sl@0
   762
			{
sl@0
   763
			iWriteBuf[i] = static_cast<TUint8>((iPktNum+i) & 0x000000ff);
sl@0
   764
			}
sl@0
   765
		}
sl@0
   766
sl@0
   767
	TUSB_VERBOSE_PRINT3("SendData interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.inPipe);
sl@0
   768
	iCurrentXfer = EWriteXfer;
sl@0
   769
	iPort->Write(iStatus, (TENDPOINTNUMBER)iTestParams.inPipe, iWriteBuf, iBufSz);
sl@0
   770
	#endif
sl@0
   771
	if (!IsActive())
sl@0
   772
		{
sl@0
   773
		SetActive();
sl@0
   774
		}
sl@0
   775
	}
sl@0
   776
sl@0
   777
TInt CActiveRW::WriteToDisk(TChar aDriveLetter)
sl@0
   778
	{
sl@0
   779
	iDiskAccessEnabled = ETrue;
sl@0
   780
	TInt r = KErrNone;
sl@0
   781
sl@0
   782
	iFileName.Format(_L("%c:"), aDriveLetter.operator TUint());
sl@0
   783
	iFileName.Append(KFileName);
sl@0
   784
	TUSB_PRINT1("\nFilename = %S", &iFileName);
sl@0
   785
sl@0
   786
	// open the record file
sl@0
   787
	r = iFile.Replace(iFs, iFileName, EFileWrite);
sl@0
   788
	iFileOffset = 0;
sl@0
   789
	if (r != KErrNone)
sl@0
   790
		{
sl@0
   791
		TUSB_PRINT1("RFile::Replace() returned %d", r);
sl@0
   792
		iDiskAccessEnabled = EFalse;
sl@0
   793
		return r;
sl@0
   794
		}
sl@0
   795
		
sl@0
   796
	return r;
sl@0
   797
	}
sl@0
   798
sl@0
   799
sl@0
   800
TInt CActiveRW::ReadFromDisk(TChar aDriveLetter, TInt aMaxFileSize)
sl@0
   801
	{
sl@0
   802
	iDiskAccessEnabled = ETrue;
sl@0
   803
	TInt r = KErrNone;
sl@0
   804
sl@0
   805
	iFileName.Format(_L("%c:"), aDriveLetter.operator TUint());
sl@0
   806
	iFileName.Append(KFileName);
sl@0
   807
	TUSB_PRINT1("\nFilename = %S", &iFileName);
sl@0
   808
	TUSB_PRINT1("File size: %d", aMaxFileSize);
sl@0
   809
sl@0
   810
	// First create the file & fill it
sl@0
   811
	r = iFile.Replace(iFs, iFileName, EFileWrite);
sl@0
   812
	if (r != KErrNone)
sl@0
   813
		{
sl@0
   814
		TUSB_PRINT1("RFile::Replace() returned %d", r);
sl@0
   815
		iDiskAccessEnabled = EFalse;
sl@0
   816
		return r;
sl@0
   817
		}
sl@0
   818
	const TInt KBufferSize = 4 * 1024;
sl@0
   819
	TBuf8<KBufferSize> buffer;
sl@0
   820
	buffer.SetLength(KBufferSize);
sl@0
   821
	for (TInt n = 0; n < KBufferSize; n++)
sl@0
   822
		{
sl@0
   823
		buffer[n] = static_cast<TUint8>(n & 0x000000ff);
sl@0
   824
		}
sl@0
   825
	TUSB_PRINT("Writing data to file (this may take some minutes...)");
sl@0
   826
	for (TInt n = 0; n < aMaxFileSize; n += KBufferSize)
sl@0
   827
		{
sl@0
   828
		r = iFile.Write(buffer, KBufferSize);
sl@0
   829
		if (r != KErrNone)
sl@0
   830
			{
sl@0
   831
			TUSB_PRINT1("RFile::Write() returned %d (disk full?)", r);
sl@0
   832
			iFile.Close();
sl@0
   833
			iDiskAccessEnabled = EFalse;
sl@0
   834
			return r;
sl@0
   835
			}
sl@0
   836
		}
sl@0
   837
	TUSB_PRINT("Done.");
sl@0
   838
	iFile.Close();
sl@0
   839
	// Now open the file for reading
sl@0
   840
	r = iFile.Open(iFs, iFileName, EFileRead);
sl@0
   841
	if (r != KErrNone)
sl@0
   842
		{
sl@0
   843
		TUSB_PRINT1("RFile::Open() returned %d", r);
sl@0
   844
		iDiskAccessEnabled = EFalse;
sl@0
   845
		return r;
sl@0
   846
		}
sl@0
   847
	iFileOffset = 0;
sl@0
   848
sl@0
   849
	return r;
sl@0
   850
	}
sl@0
   851
sl@0
   852
sl@0
   853
void CActiveRW::WriteBufferToDisk(TDes8& aBuffer, TInt aLen)
sl@0
   854
	{
sl@0
   855
	TUSB_VERBOSE_PRINT1("CActiveRW::WriteBufferToDisk(), len = %d", aLen);
sl@0
   856
	TInt r = iFile.Write(aBuffer, aLen);
sl@0
   857
	if (r != KErrNone)
sl@0
   858
		{
sl@0
   859
		TUSB_PRINT2("Error writing to %S (%d)", &iFileName, r);
sl@0
   860
		iDiskAccessEnabled = EFalse;
sl@0
   861
		return;
sl@0
   862
		}
sl@0
   863
	iFileOffset += aLen;
sl@0
   864
	}
sl@0
   865
sl@0
   866
sl@0
   867
void CActiveRW::ReadBufferFromDisk(TDes8& aBuffer, TInt aLen)
sl@0
   868
	{
sl@0
   869
	const TInt r = iFile.Read(aBuffer, aLen);
sl@0
   870
	if (r != KErrNone)
sl@0
   871
		{
sl@0
   872
		TUSB_PRINT2("Error reading from %S (%d)", &iFileName, r);
sl@0
   873
		iDiskAccessEnabled = EFalse;
sl@0
   874
		return;
sl@0
   875
		}
sl@0
   876
	TInt readLen = aBuffer.Length();
sl@0
   877
	TUSB_VERBOSE_PRINT1("CActiveRW::ReadBufferFromDisk(), len = %d\n", readLen);
sl@0
   878
	if (readLen < aLen)
sl@0
   879
		{
sl@0
   880
		TUSB_PRINT3("Only %d bytes of %d read from file %S)",
sl@0
   881
					readLen, aLen, &iFileName);
sl@0
   882
		iDiskAccessEnabled = EFalse;
sl@0
   883
		return;
sl@0
   884
		}
sl@0
   885
	iFileOffset += aLen;
sl@0
   886
	}
sl@0
   887
sl@0
   888
sl@0
   889
TUint CActiveRW::ReadData()
sl@0
   890
	{
sl@0
   891
	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 664));
sl@0
   892
	iCurrentXfer = EReadXfer;
sl@0
   893
	#ifdef	USB_SC
sl@0
   894
	TUint readSize = 0;			// note that this returns zero when asynchronous read is pending 
sl@0
   895
	TInt r = 0;
sl@0
   896
	do
sl@0
   897
		{
sl@0
   898
		r = iSCReadBuf.GetBuffer (iSCReadData,readSize,iReadZlp,iStatus);
sl@0
   899
		test_Value(r, (r == KErrNone) || (r == KErrCompletion) || (r == KErrEof));
sl@0
   900
		TUSB_VERBOSE_PRINT4("Get Buffer Return code %d Status %d DataPtr 0x%x Size %d", r, iStatus.Int(),iSCReadData,readSize);	
sl@0
   901
		}
sl@0
   902
	while ((r == KErrCompletion && readSize == 0) || (r == KErrEof));
sl@0
   903
	if (r == KErrCompletion)
sl@0
   904
		{
sl@0
   905
		return readSize;
sl@0
   906
		}
sl@0
   907
	else
sl@0
   908
		{
sl@0
   909
		if (!IsActive())
sl@0
   910
			{
sl@0
   911
			SetActive();
sl@0
   912
			}
sl@0
   913
		return 0;
sl@0
   914
		}
sl@0
   915
	#else
sl@0
   916
	iReadBuf.SetLength (0);
sl@0
   917
	if (iBufSz <= iMaxPktSz)
sl@0
   918
		{
sl@0
   919
		// Testing the packet version of Read()
sl@0
   920
		TUSB_VERBOSE_PRINT3("ReadData (single packet) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
sl@0
   921
		iPort->ReadPacket(iStatus, (TENDPOINTNUMBER)iTestParams.outPipe, iReadBuf, iBufSz);
sl@0
   922
		}
sl@0
   923
	else if ((TUint)iBufSz == iTestParams.maxSize)
sl@0
   924
		{
sl@0
   925
		// Testing the two-parameter version
sl@0
   926
		TUSB_VERBOSE_PRINT3("ReadData (w/o length) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
sl@0
   927
		iPort->Read(iStatus, (TENDPOINTNUMBER)iTestParams.outPipe, iReadBuf);
sl@0
   928
		}
sl@0
   929
	else
sl@0
   930
		{
sl@0
   931
		// otherwise, we use the universal default version
sl@0
   932
		// Testing the three-parameter version
sl@0
   933
		TUSB_VERBOSE_PRINT3("ReadData (normal) interface %d setting %d endpoint %d",iTestParams.interfaceNumber,iTestParams.alternateSetting,iTestParams.outPipe);
sl@0
   934
		iPort->Read(iStatus, (TENDPOINTNUMBER)iTestParams.outPipe, iReadBuf, iBufSz);
sl@0
   935
		}
sl@0
   936
	if (!IsActive())
sl@0
   937
		{
sl@0
   938
		SetActive();
sl@0
   939
		}
sl@0
   940
	return 0;
sl@0
   941
	#endif
sl@0
   942
	}
sl@0
   943
sl@0
   944
sl@0
   945
void CActiveRW::Stop()
sl@0
   946
	{
sl@0
   947
	if (!IsActive())
sl@0
   948
		{
sl@0
   949
		TUSB_PRINT("CActiveRW::Stop(): Not active");
sl@0
   950
		return;
sl@0
   951
		}
sl@0
   952
	TUSB_PRINT("Cancelling outstanding transfer requests\n");
sl@0
   953
	iBufSz = 0;
sl@0
   954
	iPktNum = 0;
sl@0
   955
	iDoStop = ETrue;
sl@0
   956
	iCurrentXfer = ETxferNone;
sl@0
   957
	Cancel();
sl@0
   958
	}
sl@0
   959
sl@0
   960
sl@0
   961
void CActiveRW::DoCancel()
sl@0
   962
	{
sl@0
   963
	TUSB_VERBOSE_PRINT("CActiveRW::DoCancel()");
sl@0
   964
	// Canceling the transfer requests can be done explicitly
sl@0
   965
	// for every transfer...
sl@0
   966
	iPort->WriteCancel((TENDPOINTNUMBER)iTestParams.inPipe);
sl@0
   967
	iPort->ReadCancel((TENDPOINTNUMBER)iTestParams.outPipe);
sl@0
   968
	// or like this:
sl@0
   969
	// iPort->EndpointTransferCancel(~0);	
sl@0
   970
	}
sl@0
   971
sl@0
   972
sl@0
   973
TBool CActiveRW::CompareBuffers()
sl@0
   974
	{
sl@0
   975
	TUSB_VERBOSE_PRINT2("CActiveRW::CompareBuffers() ReadOffset %d ReadSize %d",iReadOffset,iReadSize);
sl@0
   976
	#ifdef USB_SC
sl@0
   977
	TUint8 *readPtr = reinterpret_cast<TUint8*>(iSCReadData);
sl@0
   978
	TUint8* writePtr;
sl@0
   979
	TUint inBufLength;
sl@0
   980
	test_KErrNone(iSCWriteBuf.GetInBufferRange((TAny*&)writePtr, inBufLength));
sl@0
   981
	writePtr += iReadOffset;
sl@0
   982
	#endif
sl@0
   983
	for (TUint i = 0; i < iReadSize; i++)
sl@0
   984
		{
sl@0
   985
		#ifdef USB_SC
sl@0
   986
		if (*readPtr != *writePtr)
sl@0
   987
			{
sl@0
   988
			TUSB_PRINT3 ("*** Error while comparing tx & rx buffers packet 0x%x length %d index %d",iPktNum, iReadSize,i + iReadOffset); 
sl@0
   989
			TUSB_PRINT2 ("*** Read byte 0x%x Write byte 0x%x",*readPtr,*writePtr); 
sl@0
   990
			return EFalse;
sl@0
   991
			}
sl@0
   992
		readPtr++;
sl@0
   993
		writePtr++;
sl@0
   994
		#else
sl@0
   995
		if (iReadBuf[i] != iWriteBuf[i + iReadOffset])
sl@0
   996
			{
sl@0
   997
			TUSB_PRINT3 ("*** Error while comparing tx & rx buffers packet 0x%x length %d index %d",iPktNum, iReadSize,i + iReadOffset); 
sl@0
   998
			TUSB_PRINT5 ("WriteBuf Start 0x%x 0x%x 0x%x 0x%x 0x%x",
sl@0
   999
				iWriteBuf[i], iWriteBuf[i+1], iWriteBuf[i+2], iWriteBuf[i+3], iWriteBuf[i+4]); 
sl@0
  1000
			TUSB_PRINT5 ("ReadBuf Start 0x%x 0x%x 0x%x 0x%x 0x%x",
sl@0
  1001
				iReadBuf[i], iReadBuf[i+1], iReadBuf[i+2], iReadBuf[i+3], iReadBuf[i+4]);
sl@0
  1002
			if (iReadSize >= 10)
sl@0
  1003
				{
sl@0
  1004
				TUSB_PRINT5 ("WriteBuf End 0x%x 0x%x 0x%x 0x%x 0x%x",
sl@0
  1005
					iWriteBuf[iReadSize-5], iWriteBuf[iReadSize-4], iWriteBuf[iReadSize-3], iWriteBuf[iReadSize-2], iWriteBuf[iReadSize-1]); 
sl@0
  1006
				TUSB_PRINT5 ("ReadBuf End 0x%x 0x%x 0x%x 0x%x 0x%x",
sl@0
  1007
					iReadBuf[iReadSize-5], iReadBuf[iReadSize-4], iReadBuf[iReadSize-3], iReadBuf[iReadSize-2], iReadBuf[iReadSize-1]); 
sl@0
  1008
				}
sl@0
  1009
			return EFalse;
sl@0
  1010
			}
sl@0
  1011
		#endif
sl@0
  1012
		}
sl@0
  1013
	return ETrue;
sl@0
  1014
	}
sl@0
  1015
sl@0
  1016
void CActiveRW::TestComplete(TBool aResult)
sl@0
  1017
	{
sl@0
  1018
	TUSB_VERBOSE_PRINT("CActiveRW::TestComplete()");
sl@0
  1019
sl@0
  1020
	iResult = aResult;
sl@0
  1021
	
sl@0
  1022
	if (iComplete || !iResult || iTestParams.repeat == 0)
sl@0
  1023
		{
sl@0
  1024
		test(iResult);
sl@0
  1025
		test.End();
sl@0
  1026
		gRW[iIndex] = NULL;
sl@0
  1027
		delete this;
sl@0
  1028
		}
sl@0
  1029
	else
sl@0
  1030
		{
sl@0
  1031
		iComplete = ETrue;
sl@0
  1032
		}
sl@0
  1033
	}
sl@0
  1034
sl@0
  1035
// -eof-