os/kernelhwsrv/kerneltest/e32test/device/t_usbcsc.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/device/t_usbcsc.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,4143 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test\device\t_usbcsc.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#define __E32TEST_EXTENSION__
    1.22 +#include <e32test.h>
    1.23 +#include <e32def.h>
    1.24 +#include <e32def_private.h>
    1.25 +#include <d32usbcsc.h>
    1.26 +#include <hal.h>
    1.27 +#include "t_usblib.h"
    1.28 +#include <e32svr.h>
    1.29 +#include "u32std.h"
    1.30 +
    1.31 +//#define DEBUGVERSION
    1.32 +
    1.33 +#ifdef DEBUGVERSION
    1.34 +#define DEBUGPRINT(a) {a;}
    1.35 +#else
    1.36 +#define DEBUGPRINT(a) {}
    1.37 +#endif
    1.38 +
    1.39 +LOCAL_D RTest test(_L("T_USBCSC"));
    1.40 +
    1.41 +_LIT(KLddName, "eusbcsc");
    1.42 +_LIT(KUsbDeviceName, "Usbcsc");
    1.43 +
    1.44 +static char sym[9]="`*+@$#%!";
    1.45 +
    1.46 +// Constants to be used in Descriptor Tests
    1.47 +
    1.48 +static const TInt KUsbDesc_SizeOffset = 0;		//for SetCS EndpointDescriptor
    1.49 +static const TInt KUsbDesc_TypeOffset = 1;		//for SetCS EndpointDescriptor
    1.50 +
    1.51 +static const TInt KDevDesc_SpecOffset = 2;
    1.52 +static const TInt KDevDesc_DevClassOffset = 4;
    1.53 +static const TInt KDevDesc_DevSubClassOffset = 5;
    1.54 +static const TInt KDevDesc_DevProtocolOffset = 6;
    1.55 +static const TInt KDevDesc_Ep0SizeOffset = 7;
    1.56 +static const TInt KDevDesc_VendorIdOffset = 8;
    1.57 +static const TInt KDevDesc_ProductIdOffset = 10;
    1.58 +static const TInt KDevDesc_DevReleaseOffset = 12;
    1.59 +
    1.60 +static const TInt KConfDesc_AttribOffset = 7;
    1.61 +static const TInt KConfDesc_MaxPowerOffset = 8;
    1.62 +
    1.63 +static const TInt KIfcDesc_SettingOffset = 2;
    1.64 +static const TInt KIfcDesc_ProtocolOffset = 7;
    1.65 +
    1.66 +static const TInt KEpDesc_PacketSizeOffset = 4;
    1.67 +static const TInt KEpDesc_IntervalOffset = 6;
    1.68 +static const TInt KEpDesc_SynchAddressOffset = 8;
    1.69 +
    1.70 +//
    1.71 +const TInt KUsbcMaxBuffers = 32; // Maximum buffers per device (15 In + 15 Out + 2 for Ep0)
    1.72 +const TInt KUsbcMaxAltSetting = 5; // Maximum alternate setting an interface can have  
    1.73 +
    1.74 +static RDevUsbcScClient gPort;
    1.75 +
    1.76 +// Values to be found from device capabilities
    1.77 +static TBool gSupportsHighSpeed;
    1.78 +TInt gInterruptInEpFound = 0;
    1.79 +
    1.80 +//Command Line parameters 
    1.81 +TBool gRealHardware = EFalse;
    1.82 +TInt gVerbose = 0;
    1.83 +enum TSpecTestType {EAll=0,EBufRead,EBufWrite,EEp0, EAltSet, EInterface, ECancel, EInvalidApi, EDescriptor, /*insert new non-bil here*/ EBilRw=100, EBilEp0, EBilAlt};
    1.84 +TSpecTestType gSpecTest = EAll;
    1.85 +
    1.86 +RChunk gChunk;
    1.87 +static const TInt gBytesReceived = 128;
    1.88 +static const TInt KMaxBufSize = 1024 * 1024;				// max data buffer size: 1MB
    1.89 +
    1.90 +// Masks for EP0Setup type. (Used By BIL tests and LDD tests)
    1.91 +const TUint KDeviceToHost   = 0x80;
    1.92 +//const TUint KDirMask		= 0x80;
    1.93 +const TUint KDirBit			= 0x7;
    1.94 +
    1.95 +//const TUint KReqTypeMask	= 0x60;
    1.96 +const TUint KReqTypeBit		= 0x5;
    1.97 +
    1.98 +const TUint KRecepientMask	= 0x1F;
    1.99 +const TUint KRecepientReservedMask	= 0x1C;
   1.100 +
   1.101 +
   1.102 +//Forward Declaration
   1.103 +class TAlternateSetting;
   1.104 +class CActiveRW;
   1.105 +class TBuffer;
   1.106 +class TEndpointWrapper;
   1.107 +
   1.108 +// Stucture which holds how many in and out endpoints an alternate setting in the chunk should contain
   1.109 +struct TEndpointDescription
   1.110 +	{
   1.111 +	TInt iNumOfEp;
   1.112 +	TInt iNumOfOutEp;
   1.113 +	TInt iNumOfInEp;
   1.114 +	};
   1.115 +// This class is used for checking against the contents of the chunk after its construction
   1.116 +class TAltSetConfig
   1.117 +	{
   1.118 +public:
   1.119 +	TInt iNumOfAltSet; 
   1.120 +	TEndpointDescription iEpsDesc[KMaxEndpointsPerClient];
   1.121 +	};
   1.122 +
   1.123 +enum Tep0phase {EReady, EDataIn};
   1.124 +
   1.125 +struct Sep0SetupPacket
   1.126 +	{
   1.127 +	TUint8 iRequestType;
   1.128 +	TUint8 iRequest;
   1.129 +	TUint16 iwValue;
   1.130 +	TUint16 iwIndex;
   1.131 +	TUint16 iWlength;
   1.132 +	};
   1.133 +
   1.134 +// CActive class to monitor KeyStrokes from User (Only EKeyEscape in this test)
   1.135 +class CActiveConsole : public CActive
   1.136 +	{
   1.137 +public:
   1.138 +	CActiveConsole();
   1.139 +	~CActiveConsole();
   1.140 +	void GetCharacter();
   1.141 +
   1.142 +private:
   1.143 +	// Defined as pure virtual by CActive;
   1.144 +	// implementation provided by this class.
   1.145 +	virtual void DoCancel();
   1.146 +	// Defined as pure virtual by CActive;
   1.147 +	// implementation provided by this class,
   1.148 +	virtual void RunL();
   1.149 +	};
   1.150 +
   1.151 +//CActive class to monitor Device/AlternateSetting changes
   1.152 +class CActiveDeviceStateNotifier : public CActive
   1.153 +	{
   1.154 +public:
   1.155 +	CActiveDeviceStateNotifier();
   1.156 +	~CActiveDeviceStateNotifier();
   1.157 +	void Activate();
   1.158 +
   1.159 +private:
   1.160 +	virtual void DoCancel();
   1.161 +	virtual void RunL();
   1.162 +
   1.163 +private:
   1.164 +	TUint iDeviceState;
   1.165 +	};
   1.166 +
   1.167 +class CActiveStallNotifier : public CActive
   1.168 +	{
   1.169 +public:
   1.170 +	CActiveStallNotifier();
   1.171 +	~CActiveStallNotifier();
   1.172 +	void Activate();
   1.173 +
   1.174 +private:
   1.175 +	virtual void DoCancel();
   1.176 +	virtual void RunL();
   1.177 +
   1.178 +private:
   1.179 +	TUint iEndpointState;
   1.180 +	};
   1.181 +
   1.182 +//Class containing all alternate settings
   1.183 +class TInterface
   1.184 +	{
   1.185 +public:
   1.186 +	TInterface();
   1.187 +	~TInterface();
   1.188 +	void AddAlternateSetting(TAlternateSetting &aAlternateSetting);
   1.189 +	void SetActiveAlternateSetting(TInt aSettingNum, TBool aStartNextInAltSet = EFalse);
   1.190 +	TInt GetAltSettingChangeSequenceNum();
   1.191 +private:
   1.192 +	void IncrementAltSettingChangeSequenceNum();
   1.193 +private:
   1.194 +	TInt iAltSettingChangeSequenceNum; // To keep track of alternate setting changes, Always is one more than previous after an alternat setting change.
   1.195 +	RArray <TAlternateSetting> iAlternateSetting;
   1.196 +	};
   1.197 +
   1.198 +//Class containing all endpoints of an alternate setting 
   1.199 +class TAlternateSetting
   1.200 +	{
   1.201 +public:
   1.202 +	TAlternateSetting(TInt aAltSetNum);
   1.203 +	~TAlternateSetting();
   1.204 +	void AddEndpoint(CActiveRW &aEp); 
   1.205 +	void SetInterfaceHandle(TInterface *aInterface);
   1.206 +	TInt GetAlternateSetting();
   1.207 +	TInt GetInterfaceAltSettingChangeSequenceNum();
   1.208 +	void Activate(TBool aStartNextInAltSet = EFalse);
   1.209 +	void SetChangeRequestFlag(CActiveRW *aEp);
   1.210 +	TBool CheckFlagForAllOutEndpoints();
   1.211 +	void ChangeAlternateSetting(TInt aAltsetting);
   1.212 +private:
   1.213 +	TInt iAltSetNum;
   1.214 +	TInterface *iInterface;
   1.215 +	RArray <TEndpointWrapper> iEndpoints;
   1.216 +	};
   1.217 +
   1.218 +// CActive class represents an endpoint for reading or writing 
   1.219 +class CActiveRW : public CActive
   1.220 +	{
   1.221 +public:
   1.222 +	CActiveRW(TInt aEndpointNum, TInt aDirection, TBuffer* aBuffer);
   1.223 +	~CActiveRW();
   1.224 +	void SetAlternateSettingHandle(TAlternateSetting *aAlternateSetting);	
   1.225 +	TInt GetAlternateSettingOfEndpoint();
   1.226 +	TBool CheckFlagForAllOutEndpoints();
   1.227 +	TInt GetInterfaceAltSettingChangeSequenceNum();
   1.228 +	void CallChangeAlternateSetting(TInt aAltsetting);
   1.229 +
   1.230 +	TInt GetEndpointNumber();
   1.231 +	TInt GetDirection();
   1.232 +	
   1.233 +	void QueueRequests();	
   1.234 +	TInt StartRead();
   1.235 +	void StartWrite();
   1.236 +	void SetChangeRequestFlag(TBuffer *aBuffer);
   1.237 +
   1.238 +private:
   1.239 +	virtual void RunL();
   1.240 +	virtual void DoCancel();
   1.241 +
   1.242 +private:
   1.243 +	TInt iLogicalEndpointNum;	
   1.244 +	TInt iDirection;
   1.245 +	TAlternateSetting* iAltSetting;
   1.246 +
   1.247 +public:
   1.248 +	TBuffer* iBuffer; 
   1.249 +	};
   1.250 +
   1.251 +class TBuffer
   1.252 +	{
   1.253 +public:
   1.254 +	TBuffer(TInt aBufNum);
   1.255 +	~TBuffer();
   1.256 +	void SetEndpointHandle(CActiveRW* aEndpoint);	
   1.257 +	void SetUpHeader(); 
   1.258 +	void ProcessData();	
   1.259 +	void SendEP0Packet(TInt aLength);
   1.260 +
   1.261 +public:
   1.262 +	CActiveRW* iEndpoint; // To know which endpoint of an alternate setting it belongs to 
   1.263 +
   1.264 +	TInt iBufNum;
   1.265 +	TBool iIsHeaderSetUp;	// If already setUp 
   1.266 +	
   1.267 +	//For Ep0
   1.268 +	Sep0SetupPacket* iSetup;	
   1.269 +	Tep0phase iEp0Phase;	
   1.270 +
   1.271 +	//For Reading	
   1.272 +	TUsbcScTransferHeader* iTransfer;
   1.273 +	SUsbcScBufferHeader* iHeader;
   1.274 +	TUint iMaxBufferSize;
   1.275 +	TUint iMaxPacketSize;
   1.276 +	TUint iBase;
   1.277 +	TInt iOldTail; 
   1.278 +
   1.279 +#if _DEBUG
   1.280 +	TUint iPrevSequence;
   1.281 +	TUint iLoop;
   1.282 +#endif
   1.283 +	TInt iBytesReceived;
   1.284 +	TInt iTickCount;
   1.285 +	TUint iPrevAltSeq;
   1.286 +
   1.287 +
   1.288 +	//For Writing
   1.289 +	TUint iBufferOffset;
   1.290 +	TUint iLength;
   1.291 +	};
   1.292 +
   1.293 +class TEndpointWrapper
   1.294 +	{
   1.295 +public:
   1.296 +	CActiveRW*	iEp;
   1.297 +	TBool iSettingChangeReceived; // Flag to check if "empty packet" containing alternate setting change is received
   1.298 +	};
   1.299 +
   1.300 +
   1.301 +/* Open drivers, with a few endpoints. Check each endpoint has headers that
   1.302 +   make sense.  Getting the test program to this stage will be an
   1.303 +   achievement in itself! */
   1.304 +
   1.305 +void TestBufferConstruction(TAltSetConfig* aAltSetConfig)
   1.306 +	{
   1.307 +	TInt r;
   1.308 +	test.Next(_L("Buffer Construction"));
   1.309 +	r = gPort.RealizeInterface(gChunk);
   1.310 +	test_KErrNone(r);
   1.311 +
   1.312 +	TUsbcScChunkHeader chunkHeader(gChunk);
   1.313 +
   1.314 +	DEBUGPRINT(test.Printf(_L("iBuffers at 0x%x, iAltSettings at 0x%x\n"),chunkHeader.iBuffers, chunkHeader.iAltSettings));
   1.315 +
   1.316 +	test_Equal(gChunk.Base()+ sizeof(TUint)*2, chunkHeader.iBuffers);
   1.317 +
   1.318 +	DEBUGPRINT(test.Printf(_L("iBuffers: EP0Out: 0x%x EP0In: 0x%x\n"), chunkHeader.iBuffers->Ep0Out()->Offset(),  
   1.319 +																	chunkHeader.iBuffers->Ep0In()->Offset()));
   1.320 + 													
   1.321 +	DEBUGPRINT(test.Printf(_L("iAltSettings: Number of: %d First offset: 0x%x \n"), chunkHeader.iAltSettings->iNumOfAltSettings,  
   1.322 +																	chunkHeader.iAltSettings->iAltTableOffset[0]));
   1.323 +	
   1.324 +	test_Compare(aAltSetConfig->iNumOfAltSet, ==, chunkHeader.iAltSettings->iNumOfAltSettings);
   1.325 +
   1.326 +	TInt maxInEps = 0, maxOutEps = 0;
   1.327 +	for (int i = 0; i < chunkHeader.iAltSettings->iNumOfAltSettings; i++)
   1.328 +		{
   1.329 +		TInt inEps = 0, outEps = 0;
   1.330 +		DEBUGPRINT(test.Printf(_L("Alternate Setting %d offset: 0x%x \n"), i, chunkHeader.iAltSettings->iAltTableOffset[i]));
   1.331 +
   1.332 +		TInt8* endpoint = (TInt8*) (chunkHeader.iAltSettings->iAltTableOffset[i] + (TInt) gChunk.Base());
   1.333 +		for (int j = 1; j <= chunkHeader.GetNumberOfEndpoints(i); j++)
   1.334 +			{
   1.335 +			TUsbcScHdrEndpointRecord* endpointInf = (TUsbcScHdrEndpointRecord*) &(endpoint[j * chunkHeader.iAltSettings->iEpRecordSize]);
   1.336 +			DEBUGPRINT(test.Printf(_L("Endpoint %d owns buffer %d BufferOffset 0x%x Dir %d Type %d\n"), j, endpointInf->iBufferNo, chunkHeader.iBuffers->Buffers(endpointInf->iBufferNo)->Offset(), 
   1.337 +						endpointInf->Direction(), endpointInf->Type()));
   1.338 +			if (endpointInf->Direction() == KUsbScHdrEpDirectionOut)
   1.339 +				{
   1.340 +				outEps++;
   1.341 +				}
   1.342 +			else 
   1.343 +				{
   1.344 +				inEps++;
   1.345 +				}
   1.346 +			}
   1.347 +
   1.348 +		DEBUGPRINT(test.Printf(_L("Test if Alternate Setting %d  has %d endpoints (%d Out Endpoint(s) and %d In Endpoint(s)) \n"), i, aAltSetConfig->iEpsDesc[i].iNumOfEp,
   1.349 +				aAltSetConfig->iEpsDesc[i].iNumOfOutEp, aAltSetConfig->iEpsDesc[i].iNumOfInEp));
   1.350 +
   1.351 +		test_Compare(chunkHeader.GetNumberOfEndpoints(i), ==, aAltSetConfig->iEpsDesc[i].iNumOfEp);
   1.352 +		test_Compare(outEps, ==, aAltSetConfig->iEpsDesc[i].iNumOfOutEp);
   1.353 +		test_Compare(inEps, ==, aAltSetConfig->iEpsDesc[i].iNumOfInEp);
   1.354 +		if (outEps > maxOutEps)
   1.355 +			maxOutEps = outEps;
   1.356 +		if (inEps > maxInEps)
   1.357 +			maxInEps = inEps;
   1.358 +		}
   1.359 +	test_Compare(chunkHeader.iBuffers->NumberOfBuffers(), ==, (maxOutEps + maxInEps));
   1.360 +	}
   1.361 +
   1.362 +// Function Definitions *****
   1.363 +
   1.364 +TInt WaitUntilTimeout(TInt aTimout, TRequestStatus& aStatus)
   1.365 +{
   1.366 +	TRequestStatus timerStatus;
   1.367 +	RTimer timer;
   1.368 +	test_KErrNone(timer.CreateLocal());
   1.369 +	timer.After(timerStatus,aTimout*1000);
   1.370 +	User::WaitForRequest(timerStatus, aStatus);
   1.371 +	return (timerStatus.Int()!=KRequestPending)?KErrTimedOut:KErrNone;
   1.372 +}
   1.373 +
   1.374 +// Class CActiveConsole
   1.375 +
   1.376 +CActiveConsole::CActiveConsole()
   1.377 +	: CActive(EPriorityHigh)
   1.378 +	{
   1.379 +	CActiveScheduler::Add(this);
   1.380 +	}
   1.381 +
   1.382 +CActiveConsole::~CActiveConsole()
   1.383 +	{
   1.384 +	Cancel();
   1.385 +	}
   1.386 +
   1.387 +void CActiveConsole::GetCharacter()
   1.388 +	{
   1.389 +	test.Printf(_L("\n \n ***** Press Escape to exit ***** \n \n"));
   1.390 +
   1.391 +	test.Console()->Read(iStatus);
   1.392 +	SetActive();
   1.393 +	}
   1.394 +
   1.395 +void CActiveConsole::DoCancel()
   1.396 +	{
   1.397 +	DEBUGPRINT(test.Printf(_L("CActiveConsole::DoCancel\n")));
   1.398 +	test.Console()->ReadCancel();
   1.399 +	}
   1.400 +
   1.401 +void CActiveConsole::RunL()
   1.402 +	{
   1.403 +	DEBUGPRINT(test.Printf(_L("\n CActiveConsole::RunL\n")));
   1.404 +	if (test.Console()->KeyCode() == EKeyEscape)
   1.405 +		{
   1.406 +		test.Printf(_L("CActiveConsole: ESC key pressed -> stopping active scheduler...\n"));
   1.407 +		CActiveScheduler::Stop();
   1.408 +		return;
   1.409 +		}
   1.410 +	GetCharacter();
   1.411 +	}
   1.412 +
   1.413 +// Class CActiveDeviceStateNotifier
   1.414 +CActiveDeviceStateNotifier::CActiveDeviceStateNotifier()
   1.415 +	: CActive(EPriorityHigh)
   1.416 +	{
   1.417 +	DEBUGPRINT(test.Printf(_L("CActiveDeviceStateNotifier::CActiveDeviceStateNotifier() \n")));
   1.418 +	CActiveScheduler::Add(this);
   1.419 +	}
   1.420 +
   1.421 +CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()
   1.422 +	{
   1.423 +	DEBUGPRINT(test.Printf(_L("CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier() \n")));
   1.424 +	Cancel();
   1.425 +	}
   1.426 +
   1.427 +void CActiveDeviceStateNotifier::DoCancel()
   1.428 +	{
   1.429 +	DEBUGPRINT(test.Printf(_L("CActiveDeviceStateNotifier::DoCancel\n")));
   1.430 +	gPort.AlternateDeviceStatusNotifyCancel();
   1.431 +	}
   1.432 +
   1.433 +void CActiveDeviceStateNotifier::Activate()
   1.434 +	{
   1.435 +	gPort.AlternateDeviceStatusNotify(iStatus, iDeviceState);
   1.436 +	SetActive();
   1.437 +	}
   1.438 +
   1.439 +void CActiveDeviceStateNotifier::RunL()
   1.440 +	{
   1.441 +	DEBUGPRINT(test.Printf(_L("CActiveDeviceStateNotifier::RunL() \n")));
   1.442 +	if (!(iDeviceState & KUsbAlternateSetting))
   1.443 +		{
   1.444 +		switch (iDeviceState)
   1.445 +			{
   1.446 +		case EUsbcDeviceStateUndefined:
   1.447 +			DEBUGPRINT(test.Printf(_L("Device State notifier: Undefined \n")));
   1.448 +			break;
   1.449 +		case EUsbcDeviceStateAttached:
   1.450 +			DEBUGPRINT(test.Printf(_L("Device State notifier: Attached \n")));
   1.451 +			break;
   1.452 +		case EUsbcDeviceStatePowered:
   1.453 +			DEBUGPRINT(test.Printf(_L("Device State notifier: Powered \n")));
   1.454 +			break;
   1.455 +		case EUsbcDeviceStateDefault:
   1.456 +			DEBUGPRINT(test.Printf(_L("Device State notifier: Default \n")));
   1.457 +			break;
   1.458 +		case EUsbcDeviceStateAddress:
   1.459 +			DEBUGPRINT(test.Printf(_L("Device State notifier: Address \n")));
   1.460 +			break;
   1.461 +		case EUsbcDeviceStateConfigured:
   1.462 +			DEBUGPRINT(test.Printf(_L("Device State notifier: Configured \n")));
   1.463 +			break;
   1.464 +		case EUsbcDeviceStateSuspended:
   1.465 +			DEBUGPRINT(test.Printf(_L("Device State notifier: Suspended \n")));
   1.466 +			break;
   1.467 +		default:
   1.468 +			DEBUGPRINT(test.Printf(_L("Device State notifier: !!!! NOT RECOGNISED !!!! \n")));
   1.469 +			}
   1.470 +		}
   1.471 +	else if (iDeviceState & KUsbAlternateSetting)
   1.472 +		{
   1.473 +		test.Printf(_L("Device State notifier: Alternate interface setting has changed: now %d \n"),
   1.474 +					iDeviceState & ~KUsbAlternateSetting);
   1.475 +		}
   1.476 +	Activate();
   1.477 +	}
   1.478 +
   1.479 +
   1.480 +
   1.481 +CActiveStallNotifier::CActiveStallNotifier()
   1.482 +	: CActive(EPriorityNormal),
   1.483 +	  iEndpointState(0)
   1.484 +	{
   1.485 +	DEBUGPRINT(test.Printf(_L("CActiveStallNotifier::CActiveStallNotifier() \n")));
   1.486 +	CActiveScheduler::Add(this);
   1.487 +	}
   1.488 +
   1.489 +CActiveStallNotifier::~CActiveStallNotifier()
   1.490 +	{
   1.491 +	DEBUGPRINT(test.Printf(_L("CActiveStallNotifier::~CActiveStallNotifier() \n")));
   1.492 +	Cancel();
   1.493 +	}
   1.494 +
   1.495 +void CActiveStallNotifier::DoCancel()
   1.496 +	{
   1.497 +	DEBUGPRINT(test.Printf(_L("CActiveStallNotifier::DoCancel() \n")));
   1.498 +	gPort.EndpointStatusNotifyCancel();
   1.499 +	}
   1.500 +
   1.501 +void CActiveStallNotifier::RunL()
   1.502 +	{
   1.503 +	DEBUGPRINT(test.Printf(_L("CActiveStallNotifier::RunL() \n")));
   1.504 +	test.Printf(_L("StallNotifier Endpointstate 0x%x\n"), iEndpointState);
   1.505 +	Activate();
   1.506 +	}
   1.507 +
   1.508 +void CActiveStallNotifier::Activate()
   1.509 +	{
   1.510 +	gPort.EndpointStatusNotify(iStatus, iEndpointState);
   1.511 +	SetActive();
   1.512 +	}
   1.513 +
   1.514 +
   1.515 +
   1.516 +
   1.517 +
   1.518 +
   1.519 +
   1.520 +//Function definitions for Class TInterface
   1.521 +
   1.522 +TInterface::TInterface()
   1.523 +	:iAltSettingChangeSequenceNum(0)
   1.524 +	{ 	}
   1.525 +
   1.526 +TInterface::~TInterface()
   1.527 +	{
   1.528 +	DEBUGPRINT(test.Printf(_L("TInterface::~TInterface()\n")));
   1.529 +	iAlternateSetting.Reset();
   1.530 +	}
   1.531 +
   1.532 +void TInterface::AddAlternateSetting(TAlternateSetting &aAlternateSetting)
   1.533 +	{
   1.534 +	aAlternateSetting.SetInterfaceHandle(this);
   1.535 +	iAlternateSetting.Append(aAlternateSetting);
   1.536 +	}
   1.537 +
   1.538 +void TInterface::SetActiveAlternateSetting(TInt aSettingNum, TBool aStartNextInAltSet)
   1.539 +	{
   1.540 +	if (aStartNextInAltSet)
   1.541 +		{
   1.542 +		IncrementAltSettingChangeSequenceNum();
   1.543 +		test.Printf(_L("ALTERNATE SETTING CHANGE! Calling StartNextInAlternateSetting() \n"));
   1.544 +		TInt r = gPort.StartNextInAlternateSetting();
   1.545 +		test_Compare((r&0xFFFF), ==, aSettingNum);
   1.546 +		}
   1.547 +
   1.548 +	iAlternateSetting[aSettingNum].Activate(aStartNextInAltSet);
   1.549 +	}
   1.550 +
   1.551 +void TInterface::IncrementAltSettingChangeSequenceNum()
   1.552 +	{
   1.553 +	iAltSettingChangeSequenceNum++;
   1.554 +	}
   1.555 +TInt TInterface::GetAltSettingChangeSequenceNum()
   1.556 +	{
   1.557 +	return iAltSettingChangeSequenceNum;
   1.558 +	}
   1.559 +
   1.560 +TAlternateSetting::TAlternateSetting(TInt aAltSetNum)
   1.561 +	:iAltSetNum(aAltSetNum)
   1.562 +	{	}
   1.563 +
   1.564 +//Function definitions for Class TAlternateSetting
   1.565 +
   1.566 +TAlternateSetting::~TAlternateSetting()
   1.567 +	{
   1.568 +	DEBUGPRINT(test.Printf(_L("TAlternateSetting::~TAlternateSetting() \n")));
   1.569 +	iEndpoints.Reset();
   1.570 +	}
   1.571 +
   1.572 +void TAlternateSetting::AddEndpoint(CActiveRW &aEndpoint)
   1.573 +	{
   1.574 +	TEndpointWrapper* wrapper = new TEndpointWrapper();
   1.575 +	test_NotNull(wrapper);
   1.576 +
   1.577 +	aEndpoint.SetAlternateSettingHandle(this);
   1.578 +	
   1.579 +	wrapper->iEp = &aEndpoint;
   1.580 +	wrapper->iSettingChangeReceived = EFalse;
   1.581 +	
   1.582 +	iEndpoints.Append(*wrapper);
   1.583 +	delete wrapper;
   1.584 +	}
   1.585 +
   1.586 +void TAlternateSetting::SetInterfaceHandle(TInterface *aInterface)
   1.587 +	{
   1.588 +	iInterface = aInterface;
   1.589 +	}
   1.590 +
   1.591 +TInt TAlternateSetting::GetAlternateSetting()
   1.592 +	{
   1.593 +	return iAltSetNum;
   1.594 +	}
   1.595 +
   1.596 +TInt TAlternateSetting::GetInterfaceAltSettingChangeSequenceNum()
   1.597 +	{
   1.598 +	return iInterface->GetAltSettingChangeSequenceNum();
   1.599 +	}
   1.600 +
   1.601 +
   1.602 +void TAlternateSetting::Activate(TBool aStartNextInAltSet)
   1.603 +	{
   1.604 +	// set handle for Ep0
   1.605 +	for(TInt count = 0; count < iEndpoints.Count(); count++)
   1.606 +		{
   1.607 +		if(iEndpoints[count].iEp->GetEndpointNumber() == 0)
   1.608 +			{
   1.609 +			iEndpoints[count].iEp->SetAlternateSettingHandle(this);
   1.610 +			break;
   1.611 +			}
   1.612 +		}
   1.613 +
   1.614 +	if (gSpecTest == EAltSet)
   1.615 +		test.Printf(_L("On host side, on the Interface Tab, Change to a differnt Alternate Setting and read or write from an endpoint in the new alternate setting \n\n"));
   1.616 +
   1.617 +	if (aStartNextInAltSet)
   1.618 +		{
   1.619 +		iEndpoints[0].iSettingChangeReceived = EFalse;
   1.620 +		iEndpoints[0].iEp->QueueRequests();
   1.621 +		
   1.622 +
   1.623 +		for (TInt i = 1; i < iEndpoints.Count() ; i++)	// Not including EP0
   1.624 +			{
   1.625 +			iEndpoints[i].iEp->iBuffer->SetEndpointHandle(iEndpoints[i].iEp);
   1.626 +			iEndpoints[i].iSettingChangeReceived = EFalse;
   1.627 +			
   1.628 +			if (iEndpoints[i].iEp->iBuffer->iIsHeaderSetUp)
   1.629 +				{
   1.630 +				iEndpoints[i].iEp->QueueRequests();
   1.631 +				}
   1.632 +			else
   1.633 +				{
   1.634 +				//Set up Header as before
   1.635 +				iEndpoints[i].iEp->iBuffer->iIsHeaderSetUp = ETrue;
   1.636 +				iEndpoints[i].iEp->iBuffer->SetUpHeader();
   1.637 +				}
   1.638 +			}
   1.639 +		}
   1.640 +	else
   1.641 +		{
   1.642 +		for (TInt i = 0; i < iEndpoints.Count() ; i++)
   1.643 +			{
   1.644 +			iEndpoints[i].iEp->iBuffer->SetEndpointHandle(iEndpoints[i].iEp);
   1.645 +			iEndpoints[i].iEp->iBuffer->iIsHeaderSetUp = ETrue;
   1.646 +
   1.647 +			iEndpoints[i].iSettingChangeReceived = EFalse;
   1.648 +			iEndpoints[i].iEp->iBuffer->SetUpHeader();
   1.649 +			}
   1.650 +		}
   1.651 +	}
   1.652 +
   1.653 +void CActiveRW::QueueRequests()
   1.654 +	{
   1.655 +	DEBUGPRINT(test.Printf(_L("CActiveRW::QueueRequests() for Buffer number iBufNum %d AlternateSetting %d iDirection %d\n"),
   1.656 +												iBuffer->iBufNum, iAltSetting->GetAlternateSetting(), iDirection));
   1.657 +	if (!IsActive())
   1.658 +		{
   1.659 +		if (iDirection != KUsbScHdrEpDirectionIn)
   1.660 +			{
   1.661 +			TInt r = StartRead();
   1.662 +			if (r == KErrCompletion)
   1.663 +				RunL();
   1.664 +			else if (r == KErrNone)
   1.665 +				SetActive();
   1.666 +			}
   1.667 +		else
   1.668 +			StartWrite();
   1.669 +		}
   1.670 +	}
   1.671 +
   1.672 +void TAlternateSetting::SetChangeRequestFlag(CActiveRW *aEp)
   1.673 +	{
   1.674 +	DEBUGPRINT(test.Printf(_L("Set ChangeRequestFlag to True for Buffer Number = %d \n"), aEp->iBuffer->iBufNum));
   1.675 +
   1.676 +	TInt countOfEndpoints = iEndpoints.Count();
   1.677 +
   1.678 +	for(TInt count = 0; count < countOfEndpoints; count++)
   1.679 +		{
   1.680 +		if(iEndpoints[count].iEp->iBuffer->iBufNum == aEp->iBuffer->iBufNum)
   1.681 +			{
   1.682 +			iEndpoints[count].iSettingChangeReceived = ETrue;
   1.683 +			break;
   1.684 +			}
   1.685 +		}
   1.686 +	}
   1.687 +
   1.688 +TBool TAlternateSetting::CheckFlagForAllOutEndpoints()
   1.689 +	{
   1.690 +	// now check if we have received Alternate Setting requests for all out EPs
   1.691 +	TInt countOfEndpoints = iEndpoints.Count();
   1.692 +	TBool settingRequestReceivedForAllEps = ETrue;
   1.693 +	for(TInt count = 0; count < countOfEndpoints; count++) 
   1.694 +		{
   1.695 +		if((iEndpoints[count].iEp->GetDirection() != KUsbScHdrEpDirectionIn) && !iEndpoints[count].iSettingChangeReceived)
   1.696 +			{
   1.697 +			settingRequestReceivedForAllEps = EFalse;
   1.698 +			break;
   1.699 +			}
   1.700 +		}
   1.701 +	
   1.702 +	return settingRequestReceivedForAllEps;
   1.703 +	}
   1.704 +
   1.705 +void TAlternateSetting::ChangeAlternateSetting(TInt aAltSetting)
   1.706 +	{
   1.707 +	iInterface->SetActiveAlternateSetting(aAltSetting, ETrue);
   1.708 +	}
   1.709 +
   1.710 +//Function definitions for Class CActiveRW
   1.711 +CActiveRW::CActiveRW(TInt aEndpointNum, TInt aDirection, TBuffer* aBuffer)
   1.712 +	: CActive(EPriorityNormal),
   1.713 +		iLogicalEndpointNum(aEndpointNum),
   1.714 +		iDirection(aDirection)
   1.715 +	{
   1.716 +	CActiveScheduler::Add(this);
   1.717 +	iBuffer = aBuffer;
   1.718 +	}
   1.719 +
   1.720 +CActiveRW::~CActiveRW()
   1.721 +	{
   1.722 +	DEBUGPRINT(test.Printf(_L("CActiveRW::~CActiveRW\n")));
   1.723 +	Cancel();
   1.724 +	}
   1.725 +
   1.726 +void CActiveRW::DoCancel()
   1.727 +	{
   1.728 +	DEBUGPRINT(test.Printf(_L("CActiveRW::DoCancel for Buffer number iBufNum %d AlternateSetting %d\n"),
   1.729 +												iBuffer->iBufNum, iAltSetting->GetAlternateSetting()));
   1.730 +	if (IsActive())
   1.731 +		{
   1.732 +		if (iDirection == KUsbScHdrEpDirectionOut)
   1.733 +			gPort.ReadCancel(iBuffer->iBufNum);
   1.734 +		else if (iDirection == KUsbScHdrEpDirectionIn)
   1.735 +			gPort.WriteCancel(iBuffer->iBufNum);
   1.736 +		else 
   1.737 +			{
   1.738 +			gPort.WriteCancel(iBuffer->iBufNum);
   1.739 +			gPort.ReadCancel(iBuffer->iBufNum);
   1.740 +			}
   1.741 +		}
   1.742 +	}
   1.743 +
   1.744 +void CActiveRW::SetAlternateSettingHandle(TAlternateSetting *aAlternateSetting)
   1.745 +	{
   1.746 +	iAltSetting = aAlternateSetting;
   1.747 +	}
   1.748 +
   1.749 +TInt CActiveRW::GetAlternateSettingOfEndpoint()
   1.750 +	{
   1.751 +	return iAltSetting->GetAlternateSetting();
   1.752 +	}
   1.753 +
   1.754 +TBool CActiveRW::CheckFlagForAllOutEndpoints()
   1.755 +	{
   1.756 +	return iAltSetting->CheckFlagForAllOutEndpoints();
   1.757 +	}
   1.758 +
   1.759 +TInt CActiveRW::GetInterfaceAltSettingChangeSequenceNum()
   1.760 +	{
   1.761 +	return iAltSetting->GetInterfaceAltSettingChangeSequenceNum();
   1.762 +	}
   1.763 +
   1.764 +void CActiveRW::CallChangeAlternateSetting(TInt aAltsetting)
   1.765 +	{
   1.766 +	iAltSetting->ChangeAlternateSetting(aAltsetting);
   1.767 +	}
   1.768 +
   1.769 +void CActiveRW::SetChangeRequestFlag(TBuffer *aBuffer)
   1.770 +	{
   1.771 +	iAltSetting->SetChangeRequestFlag(this);
   1.772 +	}
   1.773 +
   1.774 +TInt CActiveRW::GetEndpointNumber()
   1.775 +	{
   1.776 +	return iLogicalEndpointNum;
   1.777 +	}
   1.778 +
   1.779 +TInt CActiveRW::GetDirection()
   1.780 +	{
   1.781 +	return iDirection;
   1.782 +	}
   1.783 +
   1.784 +//Prototypes 
   1.785 +void LoadDriver();
   1.786 +void OpenChannel();
   1.787 +void CloseChannel();
   1.788 +void UnloadDriver();
   1.789 +void TestMultipleChannels();
   1.790 +void CheckDeviceCapabilities();
   1.791 +TInt SettingOne(TInt aAltSetNo);
   1.792 +TInt SettingTwo(TInt aAltSetNo);
   1.793 +TInt SettingThreeIn(TInt aAltSetNo);
   1.794 +TInt SettingFourOut(TInt aAltSetNo);
   1.795 +TInt SettingFive(TInt aAltSetNo);
   1.796 +TInt InvalidSettingOne(TInt aAltSetNo);
   1.797 +TInt InvalidSettingTwo(TInt aAltSetNo);
   1.798 +TInt InvalidSettingThree(TInt aAltSetNo);
   1.799 +
   1.800 +void TestBufferHandling()
   1.801 +	{
   1.802 +	LoadDriver();
   1.803 +	OpenChannel();
   1.804 +
   1.805 +	TAltSetConfig *altSetConfig = new TAltSetConfig;
   1.806 +	altSetConfig->iNumOfAltSet = 1;
   1.807 +	TEndpointDescription temp = {2,1,1}; 
   1.808 +	altSetConfig->iEpsDesc[0] = temp; 
   1.809 +
   1.810 +	test_KErrNone(SettingOne(0));	
   1.811 +	if (gSpecTest==EAltSet)
   1.812 +		{
   1.813 +		test_KErrNone(SettingTwo(1));
   1.814 +		test_KErrNone(SettingThreeIn(2));	
   1.815 +		test_KErrNone(SettingFourOut(3));
   1.816 +
   1.817 +		altSetConfig->iNumOfAltSet = 4;
   1.818 +		TEndpointDescription temp1 = {5,4,1}; 
   1.819 +		TEndpointDescription temp2 = {3,0,3}; 
   1.820 +		TEndpointDescription temp3 = {3,3,0};
   1.821 +		
   1.822 +		altSetConfig->iEpsDesc[1] = temp1;	
   1.823 +		altSetConfig->iEpsDesc[2] = temp2; 
   1.824 +		altSetConfig->iEpsDesc[3] = temp3; 
   1.825 +		}
   1.826 +
   1.827 +	TInt r = gPort.RealizeInterface(gChunk);
   1.828 +	test_KErrNone(r);
   1.829 +
   1.830 +	if (gRealHardware)
   1.831 +		{
   1.832 +		TUsbcScChunkHeader chunkHeader(gChunk);
   1.833 +		
   1.834 +		test.Printf(_L("\n \n Trying hardware\nPlease start the Host side application...\n"));
   1.835 +
   1.836 +		TRequestStatus status;
   1.837 +		gPort.ReEnumerate(status);
   1.838 +		User::WaitForRequest(status);
   1.839 +
   1.840 +		TUsbcDeviceState device_state =	EUsbcDeviceStateUndefined;
   1.841 +		TInt r = gPort.DeviceStatus(device_state);
   1.842 +		if (r != KErrNone)
   1.843 +			{
   1.844 +			test.Printf(_L("Error %d on querying device state"), r);
   1.845 +			}
   1.846 +		else
   1.847 +			{
   1.848 +			DEBUGPRINT(test.Printf(_L("Current device state: %s \n"),
   1.849 +						(device_state == EUsbcDeviceStateUndefined) ? _S("Undefined") :
   1.850 +						((device_state == EUsbcDeviceStateAttached) ? _S("Attached") :
   1.851 +						 ((device_state == EUsbcDeviceStatePowered) ? _S("Powered") :
   1.852 +						  ((device_state == EUsbcDeviceStateDefault) ? _S("Default") :
   1.853 +						   ((device_state == EUsbcDeviceStateAddress) ? _S("Address") :
   1.854 +							((device_state == EUsbcDeviceStateConfigured) ? _S("Configured") :
   1.855 +							 ((device_state == EUsbcDeviceStateSuspended) ? _S("Suspended") :
   1.856 +							  _S("Unknown")))))))));
   1.857 +			}
   1.858 +
   1.859 +		CActiveScheduler* myScheduler = new (ELeave) CActiveScheduler();
   1.860 +		CActiveScheduler::Install(myScheduler);
   1.861 +
   1.862 +	__UHEAP_MARK;
   1.863 +
   1.864 +		CActiveConsole* myActiveConsole = new CActiveConsole();
   1.865 +		myActiveConsole->GetCharacter();
   1.866 +
   1.867 +		CActiveDeviceStateNotifier* myDeviceStateNotifier = new CActiveDeviceStateNotifier();
   1.868 +		myDeviceStateNotifier->Activate();
   1.869 +
   1.870 +		CActiveStallNotifier* myEndpointStateNotifier = new CActiveStallNotifier();
   1.871 +		myEndpointStateNotifier->Activate();
   1.872 +
   1.873 +		TBuffer* bufferEp0 = new TBuffer(KUsbcScEndpointZero);
   1.874 +
   1.875 +		// Keep an array of pointer of Buffers 
   1.876 +		TBuffer* bufferArray[KUsbcMaxBuffers];
   1.877 +		for(TInt i = 0; i < chunkHeader.iBuffers->NumberOfBuffers(); i++)
   1.878 +			{
   1.879 +			TBuffer* buf = new TBuffer(i);
   1.880 +			bufferArray[i] = buf;
   1.881 +			}
   1.882 +		
   1.883 +		TInterface* interface1 = new TInterface;
   1.884 +		TAlternateSetting* alternateSetting;
   1.885 +		
   1.886 +		// Keep an array of pointer of the alternate settings
   1.887 +		TAlternateSetting** altSetArray;
   1.888 +		altSetArray = new TAlternateSetting *[KUsbcMaxAltSetting]; 
   1.889 +		TInt number = 0;
   1.890 +
   1.891 +
   1.892 +		CActiveRW *endpoint0 = new CActiveRW(0,KUsbScHdrEpDirectionBiDir, bufferEp0);
   1.893 +		
   1.894 +		// Keep an array of pointer of Endpoints 
   1.895 +		CActiveRW** array;
   1.896 +		array = new CActiveRW *[KUsbcMaxEndpoints];
   1.897 +		TInt count = 0;
   1.898 +		array[count++] = endpoint0;
   1.899 +
   1.900 +		
   1.901 +		for(TInt i = 0; i < chunkHeader.iAltSettings->iNumOfAltSettings; i++)
   1.902 +			{
   1.903 +			TInt8* iEp = (TInt8*) (chunkHeader.iAltSettings->iAltTableOffset[i] + (TInt) gChunk.Base());
   1.904 +			alternateSetting = new TAlternateSetting(i);
   1.905 +			alternateSetting->AddEndpoint(*endpoint0);
   1.906 +			
   1.907 +			for (TInt epNum = 1; epNum <= chunkHeader.GetNumberOfEndpoints(i); epNum++)
   1.908 +				{
   1.909 +				TUsbcScHdrEndpointRecord* endpointInf = (TUsbcScHdrEndpointRecord*) &(iEp[epNum * chunkHeader.iAltSettings->iEpRecordSize]);
   1.910 +				DEBUGPRINT(test.Printf(_L("Endpoint %d owns buffer %d BufferOffset 0x%x Dir %d Type %d\n"), epNum, endpointInf->iBufferNo, chunkHeader.iBuffers->Buffers(endpointInf->iBufferNo)->Offset(), 
   1.911 +							endpointInf->Direction(), endpointInf->Type()));
   1.912 +				CActiveRW *EndpointRW = new CActiveRW(epNum, endpointInf->Direction(), bufferArray[endpointInf->iBufferNo]);
   1.913 +				alternateSetting->AddEndpoint(*EndpointRW);
   1.914 +				array[count++] = EndpointRW;
   1.915 +				}
   1.916 +			altSetArray[number++] = alternateSetting;
   1.917 +			interface1->AddAlternateSetting(*alternateSetting);
   1.918 +			}
   1.919 +
   1.920 +		interface1->SetActiveAlternateSetting(0);
   1.921 +		CActiveScheduler::Start();
   1.922 +//		User::After(2000000);
   1.923 +		
   1.924 +		test.Printf(_L("Cleaning Up \n"));
   1.925 +	
   1.926 +		test.Printf(_L("Delete endpoint array \n"));
   1.927 +		for(TInt i = 0;  i < count; i++)
   1.928 +			{
   1.929 +			delete array[i];
   1.930 +			}
   1.931 +		delete [] array;
   1.932 +
   1.933 +		test.Printf(_L("Delete altset array \n"));
   1.934 +		for (TInt i = 0; i < number; i++)
   1.935 +			{
   1.936 +			delete altSetArray[i];
   1.937 +			}
   1.938 +		delete [] altSetArray;
   1.939 +
   1.940 +		delete interface1;
   1.941 +	
   1.942 +		test.Printf(_L("Delete buffer array \n"));
   1.943 +		for(TInt i = 0; i < chunkHeader.iBuffers->NumberOfBuffers(); i++)
   1.944 +			{
   1.945 +			delete bufferArray[i];
   1.946 +			}
   1.947 +		test.Printf(_L("Delete buffer ep0 \n"));
   1.948 +		delete bufferEp0;
   1.949 +	
   1.950 +		delete myEndpointStateNotifier;
   1.951 +		delete myDeviceStateNotifier;
   1.952 +		delete myActiveConsole;
   1.953 +	
   1.954 +	__UHEAP_MARKEND;
   1.955 +
   1.956 +		test.Printf(_L("Uninstalling scheduler \n"));
   1.957 +
   1.958 +		CActiveScheduler::Install(NULL); // Uninstalling the scheduler
   1.959 +		delete myScheduler;			
   1.960 +		}
   1.961 +	delete altSetConfig;
   1.962 +	
   1.963 +	CloseChannel();
   1.964 +	UnloadDriver();
   1.965 +	}
   1.966 +
   1.967 +//To do Move Around Later
   1.968 +//Function definitions for Class TBuffer
   1.969 +TBuffer::TBuffer(TInt aBufNum)
   1.970 +		:iBufNum(aBufNum),
   1.971 +		 iIsHeaderSetUp(EFalse),
   1.972 +	     iSetup(NULL),		//Ep0
   1.973 +		 iTransfer(NULL),
   1.974 +		 iHeader(NULL),
   1.975 +		 iOldTail(0),
   1.976 +		 iBytesReceived(0),
   1.977 +		 iTickCount(0),
   1.978 +		 iPrevAltSeq(0)
   1.979 +	{
   1.980 +	iBase = (TUint) gChunk.Base();
   1.981 +	}
   1.982 +
   1.983 +TBuffer::~TBuffer()
   1.984 +	{ }
   1.985 +
   1.986 +void TBuffer::SetEndpointHandle(CActiveRW* aEndpoint)
   1.987 +	{
   1.988 +	iEndpoint = aEndpoint;
   1.989 +	}
   1.990 +
   1.991 +void TBuffer::SendEP0Packet(TInt aLength)
   1.992 +	{
   1.993 +	const char testString[] = "Once upon a time, there was a developer, that really did dispair. ";
   1.994 +	TUint8* data;
   1.995 +	TInt maxSize;
   1.996 +	TUsbcScChunkHeader chunkHeader(gChunk); 
   1.997 +
   1.998 +	iBufferOffset = chunkHeader.iBuffers->Ep0In()->Offset();
   1.999 +	data = (TUint8*) (((TUint) iBufferOffset  + iBase));
  1.1000 +
  1.1001 +	maxSize = chunkHeader.iBuffers->Ep0In()->Size();
  1.1002 +	test_Compare(maxSize, >= ,  aLength);
  1.1003 +
  1.1004 +	TInt strPos=0;
  1.1005 +	TInt i;
  1.1006 +	for (i=0; i<aLength; i++, strPos++)
  1.1007 +		{
  1.1008 +		if (testString[strPos]==0)
  1.1009 +			strPos=0;
  1.1010 +		data[i]=testString[strPos];
  1.1011 +		}
  1.1012 +	test.Printf(_L("Sending data....."));
  1.1013 +	// copy data into buffer TO DO
  1.1014 +	gPort.WriteData(KUsbcScEndpointZero,  iBufferOffset, aLength, 0, iEndpoint->iStatus);
  1.1015 +	User::WaitForRequest(iEndpoint->iStatus);
  1.1016 +	test_KErrNone(iEndpoint->iStatus.Int());
  1.1017 +	test.Printf(_L("Sent!\n"));
  1.1018 +	}
  1.1019 +
  1.1020 +_LIT(KUndefined,"Undefined"); _LIT(KAttached,"KAttached"); _LIT(KPowered,"KPowered"); _LIT(KDefault,"Default");
  1.1021 +_LIT(KAddress,"Address"); _LIT(KConfigured,"Configured"); _LIT(KSuspended,"Suspended"); _LIT(KOther," <?> ");
  1.1022 +const TDesC* const KStates[8] = {&KUndefined,&KAttached,&KPowered,&KDefault,&KAddress,&KConfigured,&KSuspended,&KOther};
  1.1023 +
  1.1024 +void TBuffer::SetUpHeader()
  1.1025 +	{
  1.1026 +	DEBUGPRINT(test.Printf(_L("CActiveRW::SetUpHeader() for Buffer %d belonging to Endpoint %d in Alternate Setting %d \n"), 
  1.1027 +								iBufNum, iEndpoint->GetEndpointNumber(), iEndpoint->GetAlternateSettingOfEndpoint()));
  1.1028 +	TUsbcScChunkHeader chunkHeader(gChunk);
  1.1029 +	TUsbcScHdrEndpointRecord* epInfo;
  1.1030 +
  1.1031 +#if _DEBUG
  1.1032 +	iLoop =0;
  1.1033 +#endif
  1.1034 +	iEp0Phase=EReady;
  1.1035 +	
  1.1036 +	if (iEndpoint->GetEndpointNumber() == 0)
  1.1037 +		{
  1.1038 +		if ((gSpecTest == EEp0) || (gSpecTest == EAltSet))
  1.1039 +			{
  1.1040 +			iBufNum = KUsbcScEndpointZero;
  1.1041 +			iHeader = (SUsbcScBufferHeader*) (( (TInt) chunkHeader.iBuffers->Ep0Out()->Offset()) + iBase);
  1.1042 +
  1.1043 +			// To check instance of Alternate Setting Sequence Number
  1.1044 +			iTransfer = (TUsbcScTransferHeader*) (iHeader->iTail + iBase);
  1.1045 +
  1.1046 +			iMaxBufferSize = chunkHeader.iBuffers->Ep0Out()->Size();
  1.1047 +			DEBUGPRINT(test.Printf(_L("MaxBufferSize %d \n"), iMaxBufferSize));
  1.1048 +
  1.1049 +			TUint ep0MaxPacketSize = gPort.EndpointZeroMaxPacketSizes();
  1.1050 +			DEBUGPRINT(test.Printf(_L("ep0 Max Packet Size = %d\n"), ep0MaxPacketSize));
  1.1051 +
  1.1052 +			iMaxPacketSize = (ep0MaxPacketSize == KUsbEpSize64) ? 64 :
  1.1053 +				((ep0MaxPacketSize == KUsbEpSize32) ? 32 :
  1.1054 +					((ep0MaxPacketSize == KUsbEpSize16) ? 16 :
  1.1055 +						((ep0MaxPacketSize == KUsbEpSize8) ? 8 : 0)));
  1.1056 +				
  1.1057 +			test_Compare(iMaxPacketSize,>,0);
  1.1058 +			if (gSpecTest == EEp0)
  1.1059 +				test.Printf(_L("Writing from buffer %d \n On host side, on the Class or Vendor Request Tab, send a Vendor request from an Interface on Device-to-Host or Host-to-Device(to an Interface) \n\n"), iBufNum);
  1.1060 +			iEndpoint->QueueRequests();
  1.1061 +			}
  1.1062 +		}
  1.1063 +	else
  1.1064 +		{
  1.1065 +		TInt r;
  1.1066 +		TBuf8<KUsbDescSize_Endpoint> endpointSizeDescriptor;
  1.1067 +
  1.1068 +		r = gPort.GetEndpointDescriptor(iEndpoint->GetAlternateSettingOfEndpoint(), iEndpoint->GetEndpointNumber(), endpointSizeDescriptor);
  1.1069 +		test_KErrNone(r);
  1.1070 +		iMaxPacketSize = EpSize(endpointSizeDescriptor[KEpDesc_PacketSizeOffset], endpointSizeDescriptor[KEpDesc_PacketSizeOffset+1]);
  1.1071 +		test_Compare(iMaxPacketSize,>,0);
  1.1072 +		DEBUGPRINT(test.Printf(_L("Endpoint %d Max Packet Size = %d\n"), iEndpoint->GetEndpointNumber(), iMaxPacketSize));
  1.1073 +	
  1.1074 +		if (iEndpoint->GetDirection() == KUsbScHdrEpDirectionOut)
  1.1075 +			{
  1.1076 +			if ((gSpecTest == EBufRead) || (gSpecTest == EAltSet))
  1.1077 +				{
  1.1078 +				TUsbcScBufferRecord* buff = chunkHeader.GetBuffer(iEndpoint->GetAlternateSettingOfEndpoint(), iEndpoint->GetEndpointNumber(), epInfo);
  1.1079 +				test_NotNull(buff);
  1.1080 +				iHeader = (SUsbcScBufferHeader *) (buff->Offset() + iBase);
  1.1081 +				// To check instance of Alternate Setting Sequence Number
  1.1082 +				iTransfer = (TUsbcScTransferHeader*) (iHeader->iTail + iBase);
  1.1083 + 				iMaxBufferSize = buff->Size();
  1.1084 +
  1.1085 +				if (gSpecTest == EBufRead)
  1.1086 +					test.Printf(_L("Reading from buffer %d \n On host side, on the Pipes Tab, please select endpoint %d and read from a file and send to pipe\n"), iBufNum, iEndpoint->GetEndpointNumber());
  1.1087 +				iEndpoint->QueueRequests();
  1.1088 +				}
  1.1089 +			}
  1.1090 +
  1.1091 +		if (iEndpoint->GetDirection() == KUsbScHdrEpDirectionIn)
  1.1092 +			{
  1.1093 +			if ((gSpecTest == EBufWrite) || (gSpecTest == EAltSet))
  1.1094 +				{
  1.1095 +				const char testString[] = "Hello, this is a test! Its not very exciting, but it does demonstrate if USBCSC can write to the IN endpoint.  Please dont keep reading this file, if your expecting great works of litrature, for there will be none.  To be honest, i'm not even sure why the test is going on this long with these insain ramballings.  Never mind a!  I guess at this point i think i should sum up by stateing that if you got this far, USBC probebly works to some degree.  However really you need to see if it can write this lots of times.  And i dont just mean this sentance, but the entire buffer.  For a teat i'll sing you a song. Ten green bottles, Hanging on the wall, Ten green bottles, Hanging on the wall, And if one green bottle, Should accidentally fall, There'll be nine green bottles, Hanging on the wall.   Nine green bottles, Hanging on the wall,  Nine green bottles, Hanging on the wall,  And if one green bottle, Should accidentally fall . . .  you get the idea.  Ok, I started by ramble by saying \"";
  1.1096 +
  1.1097 +				TUsbcScBufferRecord* buff = chunkHeader.GetBuffer(iEndpoint->GetAlternateSettingOfEndpoint(), iEndpoint->GetEndpointNumber(), epInfo);
  1.1098 +				iBufferOffset = buff->Offset(); 	
  1.1099 +				iLength       = buff->Size();
  1.1100 +
  1.1101 +				TUint8* buffer = (TUint8*) (iBufferOffset + iBase);
  1.1102 +
  1.1103 +				TUint i;
  1.1104 +				TInt strPos=0;
  1.1105 +				for (i=0; i<iLength; i++, strPos++)
  1.1106 +					{
  1.1107 +					if (testString[strPos]==0)
  1.1108 +						strPos=0;
  1.1109 +					buffer[i]=testString[strPos];
  1.1110 +					}
  1.1111 +				buffer[iLength-1] = '$'; 
  1.1112 +				if (gSpecTest == EBufWrite)
  1.1113 +					test.Printf(_L("Writing from buffer %d \n On host side, on the Pipes Tab, please select endpoint %d and read from pipe and write to file \n"), iBufNum, iEndpoint->GetEndpointNumber());
  1.1114 +				iEndpoint->QueueRequests();
  1.1115 +				}
  1.1116 +			}
  1.1117 +		}
  1.1118 +	}
  1.1119 +
  1.1120 +TInt CActiveRW::StartRead()
  1.1121 +	{
  1.1122 +	TInt r = gPort.ReadDataNotify(iBuffer->iBufNum,iStatus);
  1.1123 +	return r;
  1.1124 +	}
  1.1125 +
  1.1126 +void CActiveRW::StartWrite()
  1.1127 +	{
  1.1128 +	// Test if starting address is aligned
  1.1129 +	test_Compare( ((iBuffer->iBufferOffset + iBuffer->iBase) % iBuffer->iMaxPacketSize), ==, 0);
  1.1130 +	gPort.WriteData(iBuffer->iBufNum,  iBuffer->iBufferOffset, iBuffer->iLength, 0 /*flags*/ ,iStatus);
  1.1131 +	if (iStatus.Int() != KErrEof)
  1.1132 +		SetActive();
  1.1133 +	}
  1.1134 +
  1.1135 +void CActiveRW::RunL()
  1.1136 +	{
  1.1137 +	DEBUGPRINT(test.Printf(_L("CActiveRW::RunL for Buffer number iBufNum %d AlternateSetting %d iDirection %d\n"),
  1.1138 +												iBuffer->iBufNum, iAltSetting->GetAlternateSetting(), iDirection));
  1.1139 +	test_Compare(IsActive(), ==, EFalse);
  1.1140 +	if ((iLogicalEndpointNum == 0) || (iDirection == KUsbScHdrEpDirectionOut))	//RunL for ReadData
  1.1141 +		{
  1.1142 +		TInt r = 0;
  1.1143 +		do
  1.1144 +			{
  1.1145 +			iBuffer->ProcessData();
  1.1146 +			if ((iBuffer->iBytesReceived > gBytesReceived) && (iBuffer->iHeader->iHead != iBuffer->iHeader->iTail))
  1.1147 +				{
  1.1148 +				iBuffer->iBytesReceived = 0;
  1.1149 +				Deque();
  1.1150 +				CActiveScheduler::Add(this);
  1.1151 +				SetActive();
  1.1152 +				TRequestStatus *status = &iStatus;
  1.1153 +				User::RequestComplete(status, KErrNone);
  1.1154 +				return;
  1.1155 +				}
  1.1156 +		    else if ((iAltSetting->GetAlternateSetting() == iBuffer->iTransfer->iAltSetting))
  1.1157 +				{
  1.1158 +				if (!IsActive())
  1.1159 +					r = StartRead();
  1.1160 +				}
  1.1161 +			else if (iAltSetting->GetAlternateSetting() != iBuffer->iTransfer->iAltSetting)
  1.1162 +				{
  1.1163 +				return;
  1.1164 +				}	
  1.1165 +			} while (r == KErrCompletion);
  1.1166 +		if (!IsActive())
  1.1167 +			SetActive();
  1.1168 +		}
  1.1169 +	else	// RunL for WriteData
  1.1170 +		{
  1.1171 +		if (iStatus.Int() != KErrCancel)
  1.1172 +			{
  1.1173 +			test.Printf(_L("%c"), sym[iBuffer->iBufNum]);
  1.1174 +			StartWrite();
  1.1175 +			}
  1.1176 +		}
  1.1177 +	}
  1.1178 +
  1.1179 +void TBuffer::ProcessData()
  1.1180 +	{
  1.1181 +	test_Compare(iOldTail, != ,  iHeader->iTail); // Should progress every time arroud the loop.
  1.1182 +	iOldTail = iHeader->iTail;
  1.1183 +
  1.1184 +	DEBUGPRINT(test.Printf(_L("iHeader->iTail 0x%x, iHeader->iHead 0x%x \n"), iHeader->iTail, iHeader->iHead));
  1.1185 +	if (iHeader->iTail == iHeader->iHead)
  1.1186 +		{
  1.1187 +			test.Printf(_L("No data after available, but returned.  iHead 0x%x \n"),iHeader->iHead);
  1.1188 +			test(0);
  1.1189 +		}
  1.1190 +	
  1.1191 +	iTransfer = (TUsbcScTransferHeader*) (iHeader->iTail + iBase);
  1.1192 +
  1.1193 +	if (iTransfer->iBytes > 0)
  1.1194 +		{
  1.1195 +		
  1.1196 +		if (iEndpoint->GetEndpointNumber() == 0) // We have to respond to Control requests.
  1.1197 +			{
  1.1198 +			if (iEp0Phase==EDataIn)
  1.1199 +				{
  1.1200 +				iEp0Phase=EReady;
  1.1201 +				gPort.SendEp0StatusPacket();
  1.1202 +				if (iTransfer->iBytes) {test.Printf(_L("EP0 Data: "));}
  1.1203 +				for (TUint ii=0; ii<iTransfer->iBytes; ii++)
  1.1204 +					test.Printf(_L(" 0x%2x "),iTransfer->iData.b[ii]);
  1.1205 +				test.Printf(_L("\n\n"));
  1.1206 +				}
  1.1207 +			else
  1.1208 +				{
  1.1209 +				if (iTransfer->iFlags&KUsbcScStateChange)
  1.1210 +					{
  1.1211 +					TInt s = *iTransfer->iData.i;
  1.1212 +					test.Printf(_L("STATE CHANGE! %d : %S \n"),s,((s<0) || (s>7))?KStates[8]:KStates[s]);
  1.1213 +					}
  1.1214 +				else
  1.1215 +					{
  1.1216 +					iSetup = (Sep0SetupPacket* ) iTransfer->iData.b;
  1.1217 +					test.Printf(_L("EP0 Command: t %x r %x v %x i %x l %x :"), iSetup->iRequestType, iSetup->iRequest, iSetup->iwValue, iSetup->iwIndex, iSetup->iWlength);
  1.1218 +					if ((iSetup->iRequestType&KDeviceToHost))// && (iSetup->iWlength>0)) //Temp To do remove
  1.1219 +						{
  1.1220 +						test.Printf(_L("EP0 Command: Device to Host\n"));
  1.1221 +						SendEP0Packet(iSetup->iWlength);
  1.1222 +						}
  1.1223 +					else
  1.1224 +						{
  1.1225 +						test.Printf(_L("EP0 Command: Host to Device.  0x%x bytes\n"), iSetup->iWlength);
  1.1226 +						iEp0Phase=EDataIn;
  1.1227 +						}
  1.1228 +					}
  1.1229 +				} // end EP0 phase
  1.1230 +			} // iLogicalEndpointNum = 0
  1.1231 +		else // else, its not ep0
  1.1232 +			{
  1.1233 +			if ((++iTickCount)>100)
  1.1234 +				{
  1.1235 +				test.Printf(_L("%c"), sym[iBufNum]);
  1.1236 +				iTickCount=0;
  1.1237 +				}
  1.1238 +			}
  1.1239 +		} // end if data
  1.1240 +	else
  1.1241 +		{
  1.1242 +		test.Printf(_L("Empty Transfer received for buffer Num = %d  as = %d\n"), iBufNum, iTransfer->iAltSetting);
  1.1243 +		if (iPrevAltSeq  >= iTransfer->iAltSettingSeq)
  1.1244 +			{
  1.1245 +			test.Printf(_L("Empty Transfer *WAS NOT* an alt setting change!\n"));
  1.1246 +			iPrevAltSeq = iTransfer->iAltSettingSeq;
  1.1247 +			}
  1.1248 +		}
  1.1249 +
  1.1250 +		//Checking Transfer Header contents
  1.1251 +		//Checking if Alternate Setting has changed
  1.1252 +		if ((iTransfer->iBytes == 0) && (iEndpoint->GetInterfaceAltSettingChangeSequenceNum() != iTransfer->iAltSettingSeq))
  1.1253 +			{
  1.1254 +			DEBUGPRINT(test.Printf(_L("Current Alternate Setting of Endpoint = %d iTransfer->iAltSetting = %d iTransfer->iAltSettingSeq = %d \n"), 
  1.1255 +								iEndpoint->GetAlternateSettingOfEndpoint(), iTransfer->iAltSetting, iTransfer->iAltSettingSeq));
  1.1256 +			test.Printf(_L("Empty Transfer received for buffer Num = %d \n"), iBufNum);
  1.1257 +			test_Compare(iEndpoint->GetInterfaceAltSettingChangeSequenceNum(), +1== , iTransfer->iAltSettingSeq);
  1.1258 +
  1.1259 +
  1.1260 +#if _DEBUG		
  1.1261 +			// checking Sequence Numbers are in order i.e. One more than previous, Should enter this loop only the first time the buffer is ever used
  1.1262 +			if (iLoop == 0)
  1.1263 +				{
  1.1264 +				iPrevSequence = iTransfer->iSequence - 1;
  1.1265 +				iLoop++;
  1.1266 +				}
  1.1267 +			test_Compare((iTransfer->iSequence - iPrevSequence), ==, 1);
  1.1268 +			iPrevSequence = iTransfer->iSequence;
  1.1269 +#endif
  1.1270 +
  1.1271 +			iHeader->iTail = iTransfer->iNext;
  1.1272 +			iHeader->iBilTail = iTransfer->iNext;
  1.1273 +
  1.1274 +			test_Equal(iTransfer->iFlags&KUsbcScStateChange, 0)
  1.1275 +
  1.1276 +			//The following function call Sets the alternate setting change request flag to true
  1.1277 +			iEndpoint->SetChangeRequestFlag(this);
  1.1278 +
  1.1279 +			//Function checks if alternate setting change request flag for all endpoints of this Alternate Setting is set to true
  1.1280 +			TBool settingRequestReceivedForAllEps = iEndpoint->CheckFlagForAllOutEndpoints();
  1.1281 +			DEBUGPRINT(test.Printf(_L("SettingRequestReceivedForAllEps = %d \n"),settingRequestReceivedForAllEps));
  1.1282 +			if(settingRequestReceivedForAllEps)
  1.1283 +				{
  1.1284 +				// change alternative setting
  1.1285 +				test.Printf(_L("AS!\n"));
  1.1286 +				iEndpoint->CallChangeAlternateSetting(iTransfer->iAltSetting);
  1.1287 +				}
  1.1288 +			}
  1.1289 +		else
  1.1290 +			{
  1.1291 +			// Checking if Data does not overlap chunk offset of the next transfer to be extracted 
  1.1292 +			TUint startOfBuf=(TUint) &(iHeader->iBilTail) +sizeof(TUint) - (TUint)gChunk.Base();
  1.1293 +
  1.1294 +			if (iTransfer->iNext > TUint (iHeader->iTail))
  1.1295 +				{
  1.1296 +				test_Compare(&(iTransfer->iData.b[iTransfer->iBytes - 1]), <=, (TUint8*) (iBase + iTransfer->iNext));
  1.1297 +				}
  1.1298 +			else
  1.1299 +				{
  1.1300 +				test_Compare((TInt) (iTransfer->iNext), >=,   startOfBuf );
  1.1301 +				DEBUGPRINT(test.Printf(_L("Endpoint Buffer of size %d is filled. Next transfer from Start of Buffer \n"), iMaxBufferSize));
  1.1302 +				}	
  1.1303 +
  1.1304 +			//Checking that no data or information goes beyond the end address of the buffer
  1.1305 +			test_Compare(iTransfer->iNext + (TUint) iBase, <,   (TUint) iHeader + iMaxBufferSize);
  1.1306 +			test_Compare(&(iTransfer->iData.b[iTransfer->iBytes - 1]), <=, (TUint) iHeader + iMaxBufferSize);	
  1.1307 +
  1.1308 +			// Checking if data is aligned to iMaxPacketSize, except EP0 as data not DMA'd for EP0
  1.1309 +			if (iEndpoint->GetEndpointNumber() != 0) 
  1.1310 +				test_Compare(((TUint) (iTransfer->iData.b) % iMaxPacketSize), ==, 0);
  1.1311 +			
  1.1312 +#if _DEBUG		
  1.1313 +			// checking Sequence Numbers are in order i.e. One more than previous
  1.1314 +			if (iLoop == 0)
  1.1315 +				{
  1.1316 +				iPrevSequence = iTransfer->iSequence - 1;
  1.1317 +				iLoop++;
  1.1318 +
  1.1319 +				// Checking if first transfer greater than or equal to the lowest chunk offset a transfer can be 
  1.1320 +				test_Compare(iHeader->iTail, >=,  startOfBuf);
  1.1321 +				}
  1.1322 +			DEBUGPRINT(test.Printf(_L("Previous Sequence Number 0x%x Current Sequence Number 0x%x \n"), iPrevSequence, iTransfer->iSequence));
  1.1323 +			test_Compare((iTransfer->iSequence - iPrevSequence), ==, 1);
  1.1324 +			iPrevSequence = iTransfer->iSequence;
  1.1325 +#endif
  1.1326 +
  1.1327 +			if (gVerbose)
  1.1328 +				{
  1.1329 +#if _DEBUG		
  1.1330 +				//Print transfer contents
  1.1331 +				test.Printf(_L("Recieved packet Hash ID 0x%x Sequence Number 0x%x Bytes 0x%x Flags 0x%x Next 0x%x Alternate Setting Seq 0x%x  Current Alternate Setting 0x%x \n"), 
  1.1332 +				iTransfer->iHashId,iTransfer->iSequence, iTransfer->iBytes, iTransfer->iFlags, iTransfer->iNext, 
  1.1333 +				iTransfer->iAltSettingSeq, iTransfer->iAltSetting);
  1.1334 +#else
  1.1335 +				test.Printf(_L("Recieved packet Bytes 0x%x Flags 0x%x Next 0x%x Alternate Setting Seq 0x%x  Current Alternate Setting 0x%x \n"), 
  1.1336 +				iTransfer->iBytes, iTransfer->iFlags,
  1.1337 +				iTransfer->iNext, iTransfer->iAltSettingSeq, iTransfer->iAltSetting );
  1.1338 +#endif
  1.1339 +				if (gVerbose>1)
  1.1340 +					{
  1.1341 +					for (TUint ii=0; ii<iTransfer->iBytes; ii++)
  1.1342 +						{
  1.1343 +						test.Printf(_L(" %c "),iTransfer->iData.b[ii]);
  1.1344 +						}
  1.1345 +					test.Printf(_L("\n"));
  1.1346 +					}
  1.1347 +				} // if verbose
  1.1348 +
  1.1349 +			iBytesReceived += iTransfer->iBytes;
  1.1350 +			iHeader->iTail = iTransfer->iNext;
  1.1351 +			iHeader->iBilTail = iTransfer->iNext;
  1.1352 +			}	// if not alternate setting change
  1.1353 +	}
  1.1354 +
  1.1355 +static void TestCancel()
  1.1356 +{
  1.1357 +	test.Start(_L("Testing Read and Write Cancel API's \n"));
  1.1358 +	LoadDriver();
  1.1359 +	OpenChannel();
  1.1360 +
  1.1361 +	TInt r;	
  1.1362 +	r = SettingOne(0);	
  1.1363 +	test_KErrNone(r);
  1.1364 +	r = gPort.RealizeInterface(gChunk);
  1.1365 +	test_KErrNone(r);
  1.1366 +
  1.1367 +	const TInt timeOut = 5000; //5 millisec
  1.1368 +	TUsbcScChunkHeader chunkHeader(gChunk);
  1.1369 +		
  1.1370 +	TUint base = (TUint) gChunk.Base(); 
  1.1371 +	TUsbcScHdrEndpointRecord* epInfo;
  1.1372 +	TRequestStatus status;
  1.1373 +
  1.1374 +	test.Next(_L("ReadCancel Test before enumeration\n"));
  1.1375 +	
  1.1376 +	TUsbcScTransferHeader* transfer;
  1.1377 +	SUsbcScBufferHeader* header;
  1.1378 +	header = (SUsbcScBufferHeader *) (chunkHeader.GetBuffer(0, 2, epInfo)->Offset() + base);  
  1.1379 +	TInt outBuffNum = epInfo->iBufferNo;
  1.1380 +
  1.1381 +	r = gPort.ReadDataNotify(outBuffNum,status);
  1.1382 +	test_Equal(r, KErrUsbInterfaceNotReady);
  1.1383 +
  1.1384 +	test.Next(_L("WriteCancel Test before enumeration"));
  1.1385 +	TUsbcScBufferRecord* buff = chunkHeader.GetBuffer(0, 1, epInfo);
  1.1386 +	TInt inBuffNum = epInfo->iBufferNo;
  1.1387 +	TUint bufferOffset = buff->Offset();
  1.1388 +	TUint length = buff->Size();
  1.1389 +	TUint8* buffer = (TUint8*) (bufferOffset + base);
  1.1390 +
  1.1391 +	gPort.WriteData(inBuffNum,  bufferOffset, length, 1, status);
  1.1392 +	test_KErrNone(WaitUntilTimeout(timeOut, status));	
  1.1393 +	test_Equal(KErrUsbInterfaceNotReady, status.Int());
  1.1394 +
  1.1395 +	if (gRealHardware)
  1.1396 +		{		
  1.1397 +		test.Printf(_L("\n\n Trying hardware\nPlease start the Host side application...\n"));
  1.1398 +
  1.1399 +
  1.1400 +		gPort.ReEnumerate(status);
  1.1401 +		User::WaitForRequest(status);
  1.1402 +		test.Printf(_L("Enumerated status = %d\n"), status.Int());
  1.1403 +	
  1.1404 +		test.Next(_L("ReadCancel Test after enumeration\n"));
  1.1405 +		do  // Drain out all data in buffer first, then queue cancel
  1.1406 +			{
  1.1407 +			r = gPort.ReadDataNotify(outBuffNum,status);
  1.1408 +			DEBUGPRINT(test.Printf(_L("header->iTail 0x%x header->iHead 0x%x\n"), header->iTail, header->iHead));
  1.1409 +			transfer = (TUsbcScTransferHeader*) (header->iTail + base);
  1.1410 +			header->iTail = transfer->iNext;
  1.1411 +			}
  1.1412 +		while (r != KErrNone);	
  1.1413 +
  1.1414 +		gPort.ReadCancel(outBuffNum);
  1.1415 +		test_KErrNone(WaitUntilTimeout(timeOut, status));	
  1.1416 +
  1.1417 +		test_Equal(status.Int(), KErrCancel);
  1.1418 +		
  1.1419 +		test.Next(_L("WriteCancel Test after enumeration\n"));
  1.1420 +
  1.1421 +		test.Printf(_L("Generating test data %x %d\n"), buffer, inBuffNum);
  1.1422 +		for (TUint i=0; i<length; i++)
  1.1423 +			{
  1.1424 +			buffer[i]=i;
  1.1425 +			}
  1.1426 +		buffer[length-1] = '$';
  1.1427 +
  1.1428 +		gPort.WriteData(inBuffNum,  bufferOffset, length, 1, status);
  1.1429 +		gPort.WriteCancel(inBuffNum);
  1.1430 +		test_KErrNone(WaitUntilTimeout(timeOut, status));	
  1.1431 +		test_Equal(status.Int(), KErrCancel);
  1.1432 +		
  1.1433 +	}//grealhardware
  1.1434 +
  1.1435 +	CloseChannel();
  1.1436 +	UnloadDriver();
  1.1437 +
  1.1438 +	test.End();
  1.1439 +}
  1.1440 +		
  1.1441 +static void TestInvalidAPI()
  1.1442 +	{
  1.1443 +	TInt altSetNo = 0;
  1.1444 +	test.Start(_L("Test Invalid Reading and Writing API calls \n"));
  1.1445 +	LoadDriver();
  1.1446 +	OpenChannel();
  1.1447 +	TInt r = SettingTwo(altSetNo);
  1.1448 +	test_KErrNone(r);		
  1.1449 +
  1.1450 +	r = gPort.RealizeInterface(gChunk);
  1.1451 +	test_KErrNone(r);
  1.1452 +
  1.1453 +	TInt out_buf = 0;
  1.1454 +	TInt in_buf = 0; 
  1.1455 +	TInt in_ep = 0;
  1.1456 +
  1.1457 +	TUsbcScChunkHeader chunkHeader(gChunk);
  1.1458 +	
  1.1459 +	for (TInt i = 0; i < chunkHeader.iAltSettings->iNumOfAltSettings; i++)
  1.1460 +		{
  1.1461 +		TInt8* endpoint = (TInt8*) (chunkHeader.iAltSettings->iAltTableOffset[i] + (TInt) gChunk.Base());
  1.1462 +		for (TInt j = 1; j <= chunkHeader.GetNumberOfEndpoints(i); j++)
  1.1463 +			{
  1.1464 +			TUsbcScHdrEndpointRecord* endpointInf = (TUsbcScHdrEndpointRecord*) &(endpoint[j * chunkHeader.iAltSettings->iEpRecordSize]);
  1.1465 +			if (endpointInf->Direction() == KUsbScHdrEpDirectionOut)
  1.1466 +				{
  1.1467 +				out_buf = endpointInf->iBufferNo;		
  1.1468 +				}
  1.1469 +			else 
  1.1470 +				{
  1.1471 +				in_ep = j;
  1.1472 +				in_buf = endpointInf->iBufferNo;			
  1.1473 +				}
  1.1474 +			}
  1.1475 +		}
  1.1476 +	
  1.1477 +
  1.1478 +	test.Next(_L("Test invalid parameters to ReadDataNotify API \n"));
  1.1479 +	TRequestStatus status;
  1.1480 +
  1.1481 +	r = gPort.ReadDataNotify(in_buf,status);
  1.1482 +	test_Compare(r, ==, KErrNotSupported);
  1.1483 +
  1.1484 +	r = gPort.ReadDataNotify(KMaxEndpointsPerClient + 1,status);	// Any number greater than max num of ep's for an Alt set
  1.1485 +	test_Compare(r, ==, KErrArgument);
  1.1486 +
  1.1487 +	r = gPort.ReadDataNotify(-2,status);	// Negative Number 
  1.1488 +	test_Compare(r, ==, KErrArgument);
  1.1489 +
  1.1490 +	test.Next(_L("Test Invalid parameters to WriteData API \n"));
  1.1491 +
  1.1492 +	TUsbcScHdrEndpointRecord* epInfo;
  1.1493 +
  1.1494 +	TUsbcScBufferRecord* buff = chunkHeader.GetBuffer(0, in_ep, epInfo);
  1.1495 +	TUint bufferOffset = buff->Offset(); 	
  1.1496 +	TUint length = buff->Size();
  1.1497 +
  1.1498 +	// Testing with invalid buffer values
  1.1499 +	test.Printf(_L("Test Buffer Writing with invalid buffer values\n"));
  1.1500 +	gPort.WriteData(out_buf,  bufferOffset, length, 0, status);
  1.1501 +	User::WaitForRequest(status);
  1.1502 +	test_Compare(status.Int(), ==, KErrArgument);
  1.1503 +
  1.1504 +	gPort.WriteData(KMaxEndpointsPerClient + 1,  bufferOffset, length, 0, status);
  1.1505 +	User::WaitForRequest(status);
  1.1506 +	test_Compare(status.Int(), ==, KErrArgument);
  1.1507 +
  1.1508 +	gPort.WriteData(-3,  bufferOffset, length, 0,status);
  1.1509 +	User::WaitForRequest(status);
  1.1510 +	test_Compare(status.Int(), ==, KErrArgument);
  1.1511 +/*
  1.1512 +	// Unaligned argument 
  1.1513 +	test.Printf(_L("Test Buffer Writing with invalid buffer offsets\n"));
  1.1514 +	gPort.WriteData(in_buf,  bufferOffset + sizeof(TUint), length, 0,status);
  1.1515 +	User::WaitForRequest(status);
  1.1516 +	test_Compare(status.Int(), ==, KErrArgument);
  1.1517 +*/	
  1.1518 +	//Offset passed is greater than end offset
  1.1519 +	gPort.WriteData(in_buf,  (bufferOffset + length + 4), length, 0,status);
  1.1520 +	User::WaitForRequest(status);
  1.1521 +	test_Compare(status.Int(), ==, KErrArgument);
  1.1522 +
  1.1523 +	//Length greater than buffer size
  1.1524 +	gPort.WriteData(in_buf,  bufferOffset, (length + sizeof (TUint) * 3), 0,status);
  1.1525 +	User::WaitForRequest(status);
  1.1526 +	test_Compare(status.Int(), ==, KErrArgument);
  1.1527 +	
  1.1528 +	CloseChannel();
  1.1529 +	UnloadDriver();	
  1.1530 +	
  1.1531 +	test.End();
  1.1532 +	}
  1.1533 +
  1.1534 +static void TestSetInterface()
  1.1535 +	{
  1.1536 +	test.Start(_L("Test chunk's construction and clean up for various interface setting Configurations \n"));
  1.1537 +	TInt r;
  1.1538 +	TAltSetConfig *altSetConfig = new TAltSetConfig;
  1.1539 +	TInt altSetNo = 0;
  1.1540 +	__KHEAP_MARK;
  1.1541 +	//1 - This test is to see if chunk is populated correctly (Default Setting), - It is 
  1.1542 +	//2 - Test Release Interface
  1.1543 +	//3 - Test Set and Release Interface after Realize Interface 
  1.1544 +	test.Next(_L("Check if chunk is populated correctly with One Setting with two endpoints\n"));
  1.1545 +	LoadDriver();
  1.1546 +	OpenChannel();
  1.1547 +
  1.1548 +	r = SettingOne(altSetNo);
  1.1549 +	test_KErrNone(r);	
  1.1550 +	r = SettingOne(++altSetNo);
  1.1551 +	test_KErrNone(r);		
  1.1552 +	
  1.1553 +	test.Printf(_L("Release Interface %d\n"), --altSetNo);
  1.1554 +	r = gPort.ReleaseInterface(altSetNo);
  1.1555 +	test_Compare(r, !=, KErrNone);				
  1.1556 +
  1.1557 +	test.Printf(_L("Release Interface %d\n"), ++altSetNo);
  1.1558 +	r = gPort.ReleaseInterface(altSetNo);					
  1.1559 +	test_KErrNone(r);
  1.1560 +	
  1.1561 +	altSetConfig->iNumOfAltSet = 1;
  1.1562 +	TEndpointDescription temp = {2,1,1}; 
  1.1563 +	altSetConfig->iEpsDesc[0] = temp; //{2,1,1};
  1.1564 +		
  1.1565 +	TestBufferConstruction(altSetConfig); // Should have only one AltSet
  1.1566 +	
  1.1567 +	// Should not be be able to set interface once chunk realized
  1.1568 +	r = SettingOne(altSetNo); 
  1.1569 +	test_Compare(r, ==, KErrUsbAlreadyRealized);	
  1.1570 +
  1.1571 +	// Should not be allowed to release Interface once Chunk Realized
  1.1572 +	test.Printf(_L("Release Interface %d \n"), altSetNo);
  1.1573 +	r = gPort.ReleaseInterface(altSetNo);
  1.1574 +	test_Compare(r, ==, KErrUsbAlreadyRealized);	
  1.1575 +	CloseChannel();
  1.1576 +	UnloadDriver();	
  1.1577 +
  1.1578 +	//1 - Test if chunk constructed correctly with two Alternate Settings
  1.1579 +	//2 - If Realize Interface is called twice driver doesn not unload properly.
  1.1580 +	//3 - Multiple channels opened simultaneously also faults. 
  1.1581 +	test.Next(_L("Check if chunk is populated correctly with Two Settings with two endpoints each \n"));
  1.1582 +
  1.1583 +	LoadDriver();
  1.1584 +	OpenChannel();
  1.1585 +
  1.1586 +	r = SettingOne(--altSetNo);
  1.1587 +	test_KErrNone(r);
  1.1588 +
  1.1589 +	r = SettingOne(++altSetNo);
  1.1590 +	test_KErrNone(r);
  1.1591 +
  1.1592 +	altSetConfig->iNumOfAltSet = 2;
  1.1593 +	altSetConfig->iEpsDesc[0] = temp; //{2,1,1};
  1.1594 +	altSetConfig->iEpsDesc[1] = temp; //{2,1,1};
  1.1595 +
  1.1596 +	TestBufferConstruction(altSetConfig);
  1.1597 +
  1.1598 +	RChunk tmpChunk;
  1.1599 +	r = gPort.RealizeInterface(tmpChunk);			//TO do Uncomment to test Realize interface call twice
  1.1600 +	test_Equal(KErrUsbAlreadyRealized, r);
  1.1601 +
  1.1602 +	CloseChannel();
  1.1603 +	TestMultipleChannels();
  1.1604 +	UnloadDriver();			
  1.1605 +
  1.1606 +	test.Next(_L("Check if chunk is populated correctly with 2 settings, first setting with two endpoints and second with five endpoints \n")); 
  1.1607 +	LoadDriver();
  1.1608 +	OpenChannel();
  1.1609 +
  1.1610 +	altSetNo = 0;
  1.1611 +	r = SettingOne(altSetNo);
  1.1612 +	test_KErrNone(r);	
  1.1613 +	altSetNo++;
  1.1614 +	r = SettingTwo(altSetNo);
  1.1615 +	test_KErrNone(r);
  1.1616 +
  1.1617 +	altSetConfig->iNumOfAltSet = 2;
  1.1618 +	altSetConfig->iEpsDesc[0] = temp; //{2,1,1};
  1.1619 +	TEndpointDescription temp1 = {5,4,1}; 
  1.1620 +	altSetConfig->iEpsDesc[1] = temp1; //{5,4,1};
  1.1621 +
  1.1622 +	TestBufferConstruction(altSetConfig);
  1.1623 +
  1.1624 +	CloseChannel();
  1.1625 +	UnloadDriver();	
  1.1626 +
  1.1627 +
  1.1628 +	test.Next(_L("Test SetInterface with Dodgy alternate setting - Check if destructors Cleaning up properly \n")); 
  1.1629 +
  1.1630 +	LoadDriver();
  1.1631 +	OpenChannel();	
  1.1632 +
  1.1633 +	altSetNo = 0;
  1.1634 +	r = SettingOne(altSetNo);
  1.1635 +	test_KErrNone(r);	
  1.1636 +	altSetNo++;
  1.1637 +	r = InvalidSettingOne(altSetNo);
  1.1638 +	test_Compare(r, !=, KErrNone);	
  1.1639 +
  1.1640 +	altSetConfig->iNumOfAltSet = 1;
  1.1641 +	altSetConfig->iEpsDesc[0] = temp; //{2,1,1};
  1.1642 +
  1.1643 +	test.Printf(_L("Check chunk still populated with one interface\n")); 
  1.1644 +	TestBufferConstruction(altSetConfig);
  1.1645 +
  1.1646 +	CloseChannel();
  1.1647 +	UnloadDriver();		
  1.1648 +
  1.1649 +	test.Next(_L("Test SetInterface with invalid alternate setting \n")); 
  1.1650 +
  1.1651 +	LoadDriver();
  1.1652 +	OpenChannel();
  1.1653 +
  1.1654 +	altSetNo = 0;
  1.1655 +	r = SettingOne(altSetNo);
  1.1656 +	test_KErrNone(r);	
  1.1657 +	altSetNo++;
  1.1658 +	r = InvalidSettingTwo(altSetNo);
  1.1659 +	test_Compare(r, !=, KErrNone);		
  1.1660 +
  1.1661 +	test.Printf(_L("Check chunk still populated with one interface \n")); 
  1.1662 +	TestBufferConstruction(altSetConfig);
  1.1663 +
  1.1664 +	CloseChannel();
  1.1665 +	UnloadDriver();
  1.1666 +
  1.1667 +	test.Next(_L("Test SetInterface with Number of endpoints much greater than maximum per client \n")); 
  1.1668 +  	LoadDriver();
  1.1669 +	OpenChannel();
  1.1670 +	altSetNo = 0;
  1.1671 +	r = InvalidSettingThree(altSetNo);
  1.1672 +	test(r != KErrNone);
  1.1673 +
  1.1674 +	altSetConfig->iNumOfAltSet = 0;
  1.1675 +	TEndpointDescription temp2 = {0,0,0};
  1.1676 +	altSetConfig->iEpsDesc[0] = temp2; //{0,0,0};
  1.1677 +	
  1.1678 +	test.Printf(_L("Check chunk not populated with any valid data as all interfaces would be destroyed \n")); 
  1.1679 +	TestBufferConstruction(altSetConfig);
  1.1680 +
  1.1681 +	CloseChannel();
  1.1682 +	UnloadDriver();	
  1.1683 +	test.Next(_L("Test Release Interface, No interface set but call Release interface and test Chunk construction \n")); 
  1.1684 +
  1.1685 +  	LoadDriver();
  1.1686 +	OpenChannel();
  1.1687 +
  1.1688 +	r = gPort.ReleaseInterface(1);
  1.1689 +	test_KErrNone(r);
  1.1690 +
  1.1691 +	TestBufferConstruction(altSetConfig);
  1.1692 +	
  1.1693 +	CloseChannel();
  1.1694 +	UnloadDriver();			
  1.1695 +	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
  1.1696 +	__KHEAP_MARKEND;
  1.1697 +	test.Next(_L("Test Release Interface, Release all interfaces one by one \n")); 
  1.1698 +	__KHEAP_MARK;
  1.1699 +	LoadDriver();
  1.1700 +	OpenChannel();
  1.1701 +
  1.1702 +	r = SettingOne(altSetNo);
  1.1703 +	test_KErrNone(r);
  1.1704 +	r = SettingTwo(++altSetNo);
  1.1705 +	test_KErrNone(r);
  1.1706 +
  1.1707 +	gPort.ReleaseInterface(1);
  1.1708 +	test_KErrNone(r);
  1.1709 +
  1.1710 +	gPort.ReleaseInterface(0);
  1.1711 +	test_KErrNone(r);
  1.1712 +
  1.1713 +	TestBufferConstruction(altSetConfig);
  1.1714 +
  1.1715 +	CloseChannel();
  1.1716 +	UnloadDriver();			
  1.1717 +	UserSvr::HalFunction(EHalGroupKernel, EKernelHalSupervisorBarrier, (TAny*)5000, 0);
  1.1718 +	__KHEAP_MARKEND;
  1.1719 +	delete altSetConfig;	
  1.1720 +	test.End();
  1.1721 +	}
  1.1722 +
  1.1723 +//This has to be called once atleast before testing reading and writing as global variables used for checking data alignment are set in this function
  1.1724 +void CheckDeviceCapabilities()
  1.1725 +	{
  1.1726 +	// Device caps
  1.1727 +	test.Next(_L("Query USB device caps"));
  1.1728 +	TUsbDeviceCaps d_caps;
  1.1729 +	TInt r = gPort.DeviceCaps(d_caps);
  1.1730 +	test_KErrNone(r);
  1.1731 +	TInt numOfEndPoints = d_caps().iTotalEndpoints;
  1.1732 +
  1.1733 +	// Global variable - we'll need this value later.
  1.1734 +	gSupportsHighSpeed = d_caps().iHighSpeed;
  1.1735 +
  1.1736 +	test.Printf(_L("USB device capabilities:\n"));
  1.1737 +	test.Printf(_L("Number of endpoints:                %d\n"), numOfEndPoints);
  1.1738 +	test.Printf(_L("Supports Software-Connect:          %s\n"),
  1.1739 +				d_caps().iConnect ? _S("yes") : _S("no"));
  1.1740 +	test.Printf(_L("Device is Self-Powered:             %s\n"),
  1.1741 +				d_caps().iSelfPowered ? _S("yes") : _S("no"));
  1.1742 +	test.Printf(_L("Supports Remote-Wakeup:             %s\n"),
  1.1743 +				d_caps().iRemoteWakeup ? _S("yes") : _S("no"));
  1.1744 +	test.Printf(_L("Supports High-speed:                %s\n"),
  1.1745 +				gSupportsHighSpeed ? _S("yes") : _S("no"));
  1.1746 +	test.Printf(_L("Supports unpowered cable detection: %s\n"),
  1.1747 +				(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ?
  1.1748 +				_S("yes") : _S("no"));
  1.1749 +
  1.1750 +	test_Compare(numOfEndPoints, >=, 2);
  1.1751 +	test.Printf(_L("(Device has sufficient endpoints.)\n"));
  1.1752 +		
  1.1753 +	// Endpoint caps
  1.1754 +	test.Next(_L("Query USB endpoint caps"));
  1.1755 +	TUsbcEndpointData data[KUsbcMaxEndpoints];
  1.1756 +	TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
  1.1757 +	r = gPort.EndpointCaps(dataptr);
  1.1758 +	test_KErrNone(r);
  1.1759 +
  1.1760 +	test.Printf(_L("USB device endpoint capabilities:\n"));
  1.1761 +
  1.1762 +	TInt dir;
  1.1763 +	for (TInt i = 0; i < numOfEndPoints; i++)
  1.1764 +		{
  1.1765 +		const TUsbcEndpointCaps* caps = &data[i].iCaps;
  1.1766 +		dir = caps->iTypesAndDir;
  1.1767 +		test.Printf(_L("Endpoint: SizeBf= 0x%08x Type/Dir= 0x%08x"),
  1.1768 +					caps->iSizes, dir);
  1.1769 +		
  1.1770 +		if (dir&KUsbEpDirIn)
  1.1771 +			test.Printf(_L(" In "));
  1.1772 +		if (dir&KUsbEpDirOut)
  1.1773 +			test.Printf(_L(" Out"));
  1.1774 +		if (dir&KUsbEpDirBidirect)
  1.1775 +			test.Printf(_L(" Bi "));
  1.1776 +
  1.1777 +		if (dir&KUsbEpTypeControl)
  1.1778 +			{
  1.1779 +			test.Printf(_L(" Control"));
  1.1780 +			}
  1.1781 +		if (dir&KUsbEpTypeIsochronous)
  1.1782 +			{
  1.1783 +			test.Printf(_L(" Isochronus"));
  1.1784 +			}
  1.1785 +		if (dir&KUsbEpTypeBulk)
  1.1786 +			{
  1.1787 +			test.Printf(_L(" Bulk"));		
  1.1788 +			}
  1.1789 +		if (dir&KUsbEpTypeInterrupt)
  1.1790 +			{
  1.1791 +			test.Printf(_L(" Interrupt"));
  1.1792 +			}
  1.1793 +
  1.1794 +		test.Printf(_L("\n"));
  1.1795 +
  1.1796 +		if (caps->iHighBandwidth)
  1.1797 +			{
  1.1798 +			// Must be HS Int or Iso ep
  1.1799 +			test(gSupportsHighSpeed);
  1.1800 +			test(caps->iTypesAndDir & (KUsbEpTypeIsochronous | KUsbEpTypeInterrupt));
  1.1801 +			}
  1.1802 +
  1.1803 +		if ((dir&KUsbEpDirIn) && (dir&KUsbEpTypeInterrupt))
  1.1804 +			gInterruptInEpFound++;
  1.1805 +		}
  1.1806 +	}
  1.1807 +
  1.1808 +
  1.1809 +TInt SettingOne(TInt aAltSetNo)
  1.1810 +	{
  1.1811 +	test.Printf(_L("RTEST: Interigate Endpoint Capabilities (S1)\n"));
  1.1812 +	TInt r;
  1.1813 +	TUsbcScInterfaceInfoBuf ifc;
  1.1814 +	// Endpoint 0
  1.1815 +	ifc().iEndpointData[0].iType = KUsbEpTypeBulk;
  1.1816 +	ifc().iEndpointData[0].iDir = KUsbEpDirIn;
  1.1817 +	ifc().iEndpointData[0].iSize = KUsbEpSize64;	
  1.1818 +	//Endpoint 1
  1.1819 +	ifc().iEndpointData[1].iType = KUsbEpTypeBulk;
  1.1820 +	ifc().iEndpointData[1].iDir = KUsbEpDirOut;
  1.1821 +	ifc().iEndpointData[1].iSize = KUsbEpSize64;
  1.1822 +	
  1.1823 +	test.Printf(_L("RTEST: Setting up interface %d with two endpoints (s1)\n"), aAltSetNo);
  1.1824 +	_LIT16(string, "T_USBCSC Test Interface");
  1.1825 +	ifc().iString = const_cast<TDesC16*>(&string);
  1.1826 +	ifc().iTotalEndpointsUsed = 2;
  1.1827 +	ifc().iClass.iClassNum	  = 0xff;
  1.1828 +	ifc().iClass.iSubClassNum = 0xff;
  1.1829 +	ifc().iClass.iProtocolNum = 0xff;
  1.1830 +	// Tell the driver that this setting is interested in Ep0 requests:
  1.1831 +	ifc().iFeatureWord |= 0;
  1.1832 +
  1.1833 +	// Set up the interface.
  1.1834 +	 r = gPort.SetInterface(aAltSetNo, ifc);
  1.1835 +	return r;
  1.1836 +	}
  1.1837 +
  1.1838 +TInt SettingTwo(TInt aAltSetNo)
  1.1839 +	{
  1.1840 +	test.Printf(_L("RTEST: Interigate Endpoint Capabilities (S2)\n"));
  1.1841 +	TUsbcScInterfaceInfoBuf ifc;
  1.1842 +	TInt ep_found = 0; 
  1.1843 +	if (gInterruptInEpFound)
  1.1844 +		{
  1.1845 +		ifc().iEndpointData[ep_found].iType  = KUsbEpTypeInterrupt;
  1.1846 +		ifc().iEndpointData[ep_found].iDir   = KUsbEpDirIn;
  1.1847 +		if (gSupportsHighSpeed)
  1.1848 +			ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.1849 +		else
  1.1850 +			ifc().iEndpointData[ep_found].iSize  = KUsbEpSize8;
  1.1851 +		ifc().iEndpointData[ep_found].iInterval = 5;	
  1.1852 +		++ep_found;
  1.1853 +		}
  1.1854 +	else
  1.1855 +		{
  1.1856 +		ifc().iEndpointData[ep_found].iType  = KUsbEpTypeBulk;
  1.1857 +		ifc().iEndpointData[ep_found].iDir   = KUsbEpDirIn;
  1.1858 +		ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.1859 +		++ep_found;
  1.1860 +		}
  1.1861 +
  1.1862 +	do
  1.1863 +		{
  1.1864 +		ifc().iEndpointData[ep_found].iType  = KUsbEpTypeBulk;
  1.1865 +		ifc().iEndpointData[ep_found].iDir   = KUsbEpDirOut;
  1.1866 +		ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.1867 +		} while (++ep_found < 5);
  1.1868 +	
  1.1869 +	test.Printf(_L("Setting up interface %d with Five Endpoints (s2)\n"), aAltSetNo);
  1.1870 +	_LIT16(string, "T_USBSC API Test Interface");
  1.1871 +	ifc().iString = const_cast<TDesC16*>(&string);
  1.1872 +	ifc().iTotalEndpointsUsed = ep_found;
  1.1873 +	ifc().iClass.iClassNum	  = 0x08;
  1.1874 +	ifc().iClass.iSubClassNum = 0x06;
  1.1875 +	ifc().iClass.iProtocolNum = 0x50;
  1.1876 +	ifc().iFeatureWord |= 0;
  1.1877 +	TInt r = gPort.SetInterface(aAltSetNo, ifc);
  1.1878 +	return r;
  1.1879 +	}
  1.1880 +
  1.1881 +TInt SettingThreeIn(TInt aAltSetNo)
  1.1882 +	{
  1.1883 +	test.Printf(_L("RTEST: Interigate Endpoint Capabilities (S3)\n"));
  1.1884 +	TInt r;
  1.1885 +	TUsbcScInterfaceInfoBuf ifc;
  1.1886 +	TInt ep_found = 0; 
  1.1887 +	do
  1.1888 +		{
  1.1889 +		ifc().iEndpointData[ep_found].iType  = KUsbEpTypeBulk;
  1.1890 +		ifc().iEndpointData[ep_found].iDir   = KUsbEpDirIn;
  1.1891 +		ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.1892 +		} while (++ep_found < 3);
  1.1893 +	
  1.1894 +	test.Printf(_L("Setting up interface %d with three Bulk In endpoints(s3)\n"), aAltSetNo);
  1.1895 +	_LIT16(string, "T_USBCSC Test Interface");
  1.1896 +	ifc().iString = const_cast<TDesC16*>(&string);
  1.1897 +	ifc().iTotalEndpointsUsed = ep_found;
  1.1898 +	ifc().iClass.iClassNum	  = 0xff;
  1.1899 +	ifc().iClass.iSubClassNum = 0xff;
  1.1900 +	ifc().iClass.iProtocolNum = 0xff;
  1.1901 +	ifc().iFeatureWord |= 0;
  1.1902 +	// Set up the interface.
  1.1903 +	r = gPort.SetInterface(aAltSetNo, ifc);
  1.1904 + 	return r;
  1.1905 +	}
  1.1906 +
  1.1907 +TInt SettingFourOut(TInt aAltSetNo)
  1.1908 +	{
  1.1909 +	test.Printf(_L("RTEST: Interigate Endpoint Capabilities (S4)\n"));
  1.1910 +	TInt r;
  1.1911 +	TUsbcScInterfaceInfoBuf ifc;
  1.1912 +	TInt ep_found = 0; 
  1.1913 +	do
  1.1914 +		{
  1.1915 +		ifc().iEndpointData[ep_found].iType  = KUsbEpTypeBulk;
  1.1916 +		ifc().iEndpointData[ep_found].iDir   = KUsbEpDirOut;
  1.1917 +		ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.1918 +		} while (++ep_found < 3);
  1.1919 +	
  1.1920 +	test.Printf(_L("Setting up interface %d with three Bulk Out endpoints(s4)\n"), aAltSetNo);
  1.1921 +	_LIT16(string, "T_USBCSC Test Interface");
  1.1922 +	ifc().iString = const_cast<TDesC16*>(&string);
  1.1923 +	ifc().iTotalEndpointsUsed = ep_found;
  1.1924 +	ifc().iClass.iClassNum	  = 0xff;
  1.1925 +	ifc().iClass.iSubClassNum = 0xff;
  1.1926 +	ifc().iClass.iProtocolNum = 0xff;
  1.1927 +	ifc().iFeatureWord |= 0;
  1.1928 +	// Set up the interface.
  1.1929 +	r = gPort.SetInterface(aAltSetNo, ifc);
  1.1930 +	return r;
  1.1931 +	}
  1.1932 +
  1.1933 +TInt SettingFive(TInt aAltSetNo)
  1.1934 +	{
  1.1935 +	test.Printf(_L("RTEST: Interigate Endpoint Capabilities (S5)\n"));
  1.1936 +	TUsbcScInterfaceInfoBuf ifc;
  1.1937 +	TInt ep_found = 0; 
  1.1938 +	if (gInterruptInEpFound)
  1.1939 +		{
  1.1940 +		ifc().iEndpointData[ep_found].iType  = KUsbEpTypeInterrupt;
  1.1941 +		ifc().iEndpointData[ep_found].iDir   = KUsbEpDirIn;
  1.1942 +		if (gSupportsHighSpeed)
  1.1943 +			ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.1944 +		else
  1.1945 +			ifc().iEndpointData[ep_found].iSize  = KUsbEpSize8;
  1.1946 +		ifc().iEndpointData[ep_found].iInterval = 5;
  1.1947 +		ifc().iEndpointData[ep_found].iExtra    = 2;	// 2 extra bytes for Audio Class EP descriptor
  1.1948 +		++ep_found;
  1.1949 +		}
  1.1950 +	else
  1.1951 +		{
  1.1952 +		ifc().iEndpointData[ep_found].iType  = KUsbEpTypeBulk;
  1.1953 +		ifc().iEndpointData[ep_found].iDir   = KUsbEpDirIn;
  1.1954 +		ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.1955 +		ifc().iEndpointData[ep_found].iExtra    = 2;	// 2 extra bytes for Audio Class EP descriptor
  1.1956 +		++ep_found;
  1.1957 +		}
  1.1958 +
  1.1959 +	do
  1.1960 +		{
  1.1961 +		ifc().iEndpointData[ep_found].iType  = KUsbEpTypeBulk;
  1.1962 +		ifc().iEndpointData[ep_found].iDir   = KUsbEpDirOut;
  1.1963 +		ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.1964 +		} while (++ep_found < 4);
  1.1965 +	
  1.1966 +	ifc().iEndpointData[ep_found].iType  = KUsbEpTypeBulk;
  1.1967 +	ifc().iEndpointData[ep_found].iDir   = KUsbEpDirIn;
  1.1968 +	ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.1969 +	
  1.1970 +	test.Printf(_L("Setting up interface %d with Five Endpoints(s5)\n"), aAltSetNo);
  1.1971 +	_LIT16(string, "T_USBSC API Test Interface");
  1.1972 +	ifc().iString = const_cast<TDesC16*>(&string);
  1.1973 +	ifc().iTotalEndpointsUsed = ep_found;
  1.1974 +	ifc().iClass.iClassNum	  = 0x01;
  1.1975 +	ifc().iClass.iSubClassNum = 0x02;
  1.1976 +	ifc().iClass.iProtocolNum = 0x00;
  1.1977 +	ifc().iFeatureWord |= 0;
  1.1978 +	TInt r = gPort.SetInterface(aAltSetNo, ifc);
  1.1979 +	return r;
  1.1980 +	}
  1.1981 +
  1.1982 +TInt InvalidSettingOne(TInt aAltSetNo) // Invalid Interface - request more than what is available on device. 
  1.1983 +									   // This will not be a valid test on the current high speed platform as the size requested is not available 
  1.1984 +									   // and will however return with an error, not because we are requesting one more than what is available of an interrupt endpoint
  1.1985 +	{
  1.1986 +	test.Printf(_L("RTEST: Interigate Endpoint Capabilities (I1)\n"));
  1.1987 +	TUsbcScInterfaceInfoBuf ifc;
  1.1988 +	TInt interruptInEpFound = gInterruptInEpFound + 1;
  1.1989 +
  1.1990 +	if (interruptInEpFound>KMaxEndpointsPerClient)
  1.1991 +		interruptInEpFound = KMaxEndpointsPerClient;
  1.1992 +
  1.1993 +	for (TInt i = 0; i < interruptInEpFound; i++)
  1.1994 +		{
  1.1995 +		ifc().iEndpointData[i].iType = KUsbEpTypeInterrupt;
  1.1996 +		ifc().iEndpointData[i].iDir = KUsbEpDirIn;
  1.1997 +		ifc().iEndpointData[i].iSize = KUsbEpSize8;
  1.1998 +		ifc().iEndpointData[i].iInterval = 1; 
  1.1999 +		}
  1.2000 +	
  1.2001 +	test.Next(_L("RTest: Setting up Erroneous Alternate interface, Endpoints already in use (I1)"));
  1.2002 +	_LIT16(string2, "T_USBSC API Test Interface");
  1.2003 +	ifc().iString = const_cast<TDesC16*>(&string2);
  1.2004 +	ifc().iTotalEndpointsUsed = interruptInEpFound;
  1.2005 +	ifc().iClass.iClassNum	  = 0x01;
  1.2006 +	ifc().iClass.iSubClassNum = 0x02;
  1.2007 +	ifc().iClass.iProtocolNum = 0x00;
  1.2008 +	ifc().iFeatureWord |= 0;
  1.2009 +	// Set up the interface.
  1.2010 +	TInt r1 = gPort.SetInterface(aAltSetNo, ifc);
  1.2011 +	return r1;
  1.2012 +	}
  1.2013 +
  1.2014 +TInt InvalidSettingTwo(TInt aAltSetNo) //Invalid Setting by requesting an endpoint that is not available.
  1.2015 +									   //Only control endpoints are bi-directional. Request any other type which has bidirectional capability.
  1.2016 +	{
  1.2017 +	test.Printf(_L("RTEST: Interigate Endpoint Capabilities (I2)\n"));
  1.2018 +
  1.2019 +	TUsbcScInterfaceInfoBuf ifc;
  1.2020 +	// Endpoint 0
  1.2021 +	ifc().iEndpointData[0].iType = KUsbEpTypeInterrupt;
  1.2022 +	ifc().iEndpointData[0].iDir = KUsbEpDirIn;
  1.2023 +	ifc().iEndpointData[0].iSize = KUsbEpSize8;
  1.2024 +	//Endpoint 1
  1.2025 +	ifc().iEndpointData[1].iType = KUsbEpTypeInterrupt;
  1.2026 +	ifc().iEndpointData[1].iDir = KUsbEpDirBidirect;
  1.2027 +	ifc().iEndpointData[1].iSize = KUsbEpSize8;
  1.2028 +
  1.2029 +	test.Next(_L("Setting up Erroneous Alternate interface (2), Endpoint not available on device (I2)"));
  1.2030 +	_LIT16(string2, "T_USBSC API Test Interface");
  1.2031 +	ifc().iString = const_cast<TDesC16*>(&string2);
  1.2032 +	ifc().iTotalEndpointsUsed = 2;
  1.2033 +	ifc().iClass.iClassNum	  = 0x01;
  1.2034 +	ifc().iClass.iSubClassNum = 0x02;
  1.2035 +	ifc().iClass.iProtocolNum = 0x00;
  1.2036 +	ifc().iFeatureWord |= 0;
  1.2037 +	// Set up the interface.
  1.2038 +	TInt r1 = gPort.SetInterface(aAltSetNo, ifc);
  1.2039 +	return r1;
  1.2040 +	}
  1.2041 +
  1.2042 +TInt InvalidSettingThree(TInt aAltSetNo)
  1.2043 +	{
  1.2044 +	test.Printf(_L("RTEST: Interigate Endpoint Capabilities (I3)\n"));
  1.2045 +	TInt r;
  1.2046 +	TUsbcScInterfaceInfoBuf ifc;
  1.2047 +	TInt ep_found = 0; 
  1.2048 +	do
  1.2049 +		{
  1.2050 +		ifc().iEndpointData[ep_found].iType  = KUsbEpTypeBulk;
  1.2051 +		ifc().iEndpointData[ep_found].iDir   = KUsbEpDirIn;
  1.2052 +		ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.2053 +			} while (++ep_found < 3);
  1.2054 +	do
  1.2055 +		{
  1.2056 +		ifc().iEndpointData[ep_found].iType  = KUsbEpTypeBulk;
  1.2057 +		ifc().iEndpointData[ep_found].iDir   = KUsbEpDirOut;
  1.2058 +		ifc().iEndpointData[ep_found].iSize  = KUsbEpSize64;
  1.2059 +		} while (++ep_found < 5);
  1.2060 +	
  1.2061 +	test.Printf(_L("RTEST: Setting up interface %d, with invalid setting three (I3).\n"), aAltSetNo);
  1.2062 +	_LIT16(string, "T_USBCSC Test Interface");
  1.2063 +	ifc().iString = const_cast<TDesC16*>(&string);
  1.2064 +	ifc().iTotalEndpointsUsed = ep_found+1;
  1.2065 +	ifc().iClass.iClassNum	  = 0x01;
  1.2066 +	ifc().iClass.iSubClassNum = 0x02;
  1.2067 +	ifc().iClass.iProtocolNum = 0x00;
  1.2068 +	ifc().iFeatureWord |= 0;
  1.2069 +	// Set up the interface.
  1.2070 +	 r = gPort.SetInterface(aAltSetNo, ifc);
  1.2071 +	 return r;
  1.2072 +	}
  1.2073 +
  1.2074 +static void TestDeviceDescriptor()
  1.2075 +	{
  1.2076 +	test.Start(_L("Device Descriptor Manipulation"));
  1.2077 +
  1.2078 +	test.Next(_L("GetDeviceDescriptorSize()"));
  1.2079 +	TInt desc_size = 0;
  1.2080 +	gPort.GetDeviceDescriptorSize(desc_size);
  1.2081 +	test(static_cast<TUint>(desc_size) == KUsbDescSize_Device);
  1.2082 +
  1.2083 +	test.Next(_L("GetDeviceDescriptor()"));
  1.2084 +	TBuf8<KUsbDescSize_Device> descriptor;
  1.2085 +	TInt r = gPort.GetDeviceDescriptor(descriptor);
  1.2086 +	test_KErrNone(r);
  1.2087 +
  1.2088 +	test.Next(_L("SetDeviceDescriptor()"));
  1.2089 +	// Change the USB spec number to 2.00
  1.2090 +	descriptor[KDevDesc_SpecOffset]   = 0x00;
  1.2091 +	descriptor[KDevDesc_SpecOffset+1] = 0x02;
  1.2092 +	// Change the device vendor ID (VID) to 0x1234
  1.2093 +	descriptor[KDevDesc_VendorIdOffset]   = 0x22;			// little endian
  1.2094 +	descriptor[KDevDesc_VendorIdOffset+1] = 0x0E;
  1.2095 +	// Change the device product ID (PID) to 0x1111
  1.2096 +	descriptor[KDevDesc_ProductIdOffset]   = 0x11;
  1.2097 +	descriptor[KDevDesc_ProductIdOffset+1] = 0x11;
  1.2098 +	// Change the device release number to 3.05
  1.2099 +	descriptor[KDevDesc_DevReleaseOffset]   = 0x05;
  1.2100 +	descriptor[KDevDesc_DevReleaseOffset+1] = 0x03;
  1.2101 +	r = gPort.SetDeviceDescriptor(descriptor);
  1.2102 +	test_KErrNone(r);
  1.2103 +
  1.2104 +	test.Next(_L("GetDeviceDescriptor()"));
  1.2105 +	TBuf8<KUsbDescSize_Device> descriptor2;
  1.2106 +	r = gPort.GetDeviceDescriptor(descriptor2);
  1.2107 +	test_KErrNone(r);
  1.2108 +
  1.2109 +	test.Next(_L("Compare device descriptor with value set"));
  1.2110 +	r = descriptor2.Compare(descriptor);
  1.2111 +	test_KErrNone(r);
  1.2112 +
  1.2113 +	if (gSupportsHighSpeed)									
  1.2114 +		{
  1.2115 +		// HS only allows one possible packet size.
  1.2116 +		test(descriptor[KDevDesc_Ep0SizeOffset] == 64);
  1.2117 +		}	 
  1.2118 +
  1.2119 +	test.End();
  1.2120 +	}
  1.2121 +
  1.2122 +
  1.2123 +static void	TestDeviceQualifierDescriptor()
  1.2124 +	{
  1.2125 +	test.Start(_L("Device_Qualifier Descriptor Manipulation"));
  1.2126 +
  1.2127 +	if (!gSupportsHighSpeed)
  1.2128 +		{
  1.2129 +		test.Printf(_L("*** Not supported - skipping Device_Qualifier descriptor tests\n"));
  1.2130 +		test.End();
  1.2131 +		return;
  1.2132 +		}
  1.2133 +
  1.2134 +	test.Next(_L("GetDeviceQualifierDescriptor()"));
  1.2135 +	TBuf8<KUsbDescSize_DeviceQualifier> descriptor;
  1.2136 +	TInt r = gPort.GetDeviceQualifierDescriptor(descriptor);
  1.2137 +	test_KErrNone(r);
  1.2138 +
  1.2139 +	test.Next(_L("SetDeviceQualifierDescriptor()"));
  1.2140 +	// Change the USB spec number to 3.00
  1.2141 +	descriptor[KDevDesc_SpecOffset]   = 0x00;
  1.2142 +	descriptor[KDevDesc_SpecOffset+1] = 0x03;
  1.2143 +	// Change the device class, subclass and protocol codes
  1.2144 +	descriptor[KDevDesc_DevClassOffset]    = 0xA1;
  1.2145 +	descriptor[KDevDesc_DevSubClassOffset] = 0xB2;
  1.2146 +	descriptor[KDevDesc_DevProtocolOffset] = 0xC3;
  1.2147 +	r = gPort.SetDeviceQualifierDescriptor(descriptor);
  1.2148 +	test_KErrNone(r);
  1.2149 +
  1.2150 +	test.Next(_L("GetDeviceQualifierDescriptor()"));
  1.2151 +	TBuf8<KUsbDescSize_DeviceQualifier> descriptor2;
  1.2152 +	r = gPort.GetDeviceQualifierDescriptor(descriptor2);
  1.2153 +	test_KErrNone(r);
  1.2154 +
  1.2155 +	test.Next(_L("Compare Device_Qualifier desc with value set"));
  1.2156 +	r = descriptor2.Compare(descriptor);
  1.2157 +	test_KErrNone(r);
  1.2158 +
  1.2159 +	test.End();
  1.2160 +	}
  1.2161 +
  1.2162 +
  1.2163 +static void TestConfigurationDescriptor()
  1.2164 +	{
  1.2165 +	test.Start(_L("Configuration Descriptor Manipulation"));
  1.2166 +
  1.2167 +	test.Next(_L("GetConfigurationDescriptorSize()"));
  1.2168 +	TInt desc_size = 0;
  1.2169 +	gPort.GetConfigurationDescriptorSize(desc_size);
  1.2170 +	test(static_cast<TUint>(desc_size) == KUsbDescSize_Config);
  1.2171 +
  1.2172 +	test.Next(_L("GetConfigurationDescriptor()"));
  1.2173 +	TBuf8<KUsbDescSize_Config> descriptor;
  1.2174 +	TInt r = gPort.GetConfigurationDescriptor(descriptor);
  1.2175 +	test_KErrNone(r);
  1.2176 +
  1.2177 +	test.Next(_L("SetConfigurationDescriptor()"));
  1.2178 +	// Invert Remote-Wakup support
  1.2179 +	descriptor[KConfDesc_AttribOffset] = (descriptor[KConfDesc_AttribOffset] ^ KUsbDevAttr_RemoteWakeup);
  1.2180 +	// Change the reported max power to 200mA (2 * 0x64)
  1.2181 +	descriptor[KConfDesc_MaxPowerOffset] = 0x64;
  1.2182 +	r = gPort.SetConfigurationDescriptor(descriptor);
  1.2183 +	test_KErrNone(r);
  1.2184 +
  1.2185 +	test.Next(_L("GetConfigurationDescriptor()"));
  1.2186 +	TBuf8<KUsbDescSize_Config> descriptor2;
  1.2187 +	r = gPort.GetConfigurationDescriptor(descriptor2);
  1.2188 +	test_KErrNone(r);
  1.2189 +
  1.2190 +	test.Next(_L("Compare configuration desc with value set"));
  1.2191 +	r = descriptor2.Compare(descriptor);
  1.2192 +	test_KErrNone(r);
  1.2193 +
  1.2194 +	test.End();
  1.2195 +	}
  1.2196 +
  1.2197 +
  1.2198 +static void	TestOtherSpeedConfigurationDescriptor()
  1.2199 +	{
  1.2200 +	test.Start(_L("Other_Speed_Configuration Desc Manipulation"));
  1.2201 +
  1.2202 +	if (!gSupportsHighSpeed)
  1.2203 +		{
  1.2204 +		test.Printf(_L("*** Not supported - skipping Other_Speed_Configuration desc tests\n"));
  1.2205 +		test.End();
  1.2206 +		return;
  1.2207 +		}
  1.2208 +
  1.2209 +	test.Next(_L("GetOtherSpeedConfigurationDescriptor()"));
  1.2210 +	TBuf8<KUsbDescSize_OtherSpeedConfig> descriptor;
  1.2211 +	TInt r = gPort.GetOtherSpeedConfigurationDescriptor(descriptor);
  1.2212 +	test_KErrNone(r);
  1.2213 +
  1.2214 +	test.Next(_L("SetOtherSpeedConfigurationDescriptor()"));
  1.2215 +	// Invert Remote-Wakup support
  1.2216 +	descriptor[KConfDesc_AttribOffset] = (descriptor[KConfDesc_AttribOffset] ^ KUsbDevAttr_RemoteWakeup);
  1.2217 +	// Change the reported max power to 330mA (2 * 0xA5)
  1.2218 +	descriptor[KConfDesc_MaxPowerOffset] = 0xA5;
  1.2219 +	r = gPort.SetOtherSpeedConfigurationDescriptor(descriptor);
  1.2220 +	test_KErrNone(r);
  1.2221 +
  1.2222 +	test.Next(_L("GetOtherSpeedConfigurationDescriptor()"));
  1.2223 +	TBuf8<KUsbDescSize_OtherSpeedConfig> descriptor2;
  1.2224 +	r = gPort.GetOtherSpeedConfigurationDescriptor(descriptor2);
  1.2225 +	test_KErrNone(r);
  1.2226 +
  1.2227 +	test.Next(_L("Compare O_S_Config desc with value set"));
  1.2228 +	r = descriptor2.Compare(descriptor);
  1.2229 +	test_KErrNone(r);
  1.2230 +
  1.2231 +	test.End();
  1.2232 +	}
  1.2233 +
  1.2234 +
  1.2235 +static void TestInterfaceDescriptor()
  1.2236 +	{
  1.2237 +	test.Start(_L("Interface Descriptor Manipulation"));
  1.2238 +
  1.2239 +	// First the standard Interface descriptor
  1.2240 +	test.Next(_L("GetInterfaceDescriptorSize()"));
  1.2241 +	TInt desc_size = 0;
  1.2242 +	TInt r = gPort.GetInterfaceDescriptorSize(0, desc_size);
  1.2243 +	test_KErrNone(r);
  1.2244 +	test(static_cast<TUint>(desc_size) == KUsbDescSize_Interface);
  1.2245 +
  1.2246 +	test.Next(_L("GetInterfaceDescriptor()"));
  1.2247 +	TBuf8<KUsbDescSize_Interface> descriptor;
  1.2248 +	r = gPort.GetInterfaceDescriptor(0, descriptor);
  1.2249 +	test_KErrNone(r);
  1.2250 +
  1.2251 +	test.Next(_L("SetInterfaceDescriptor()"));
  1.2252 +	// Change the interface protocol to 0x78(+)
  1.2253 +	TUint8 prot = 0x78;
  1.2254 +	if (descriptor[KIfcDesc_ProtocolOffset] == prot)
  1.2255 +		prot++;
  1.2256 +	descriptor[KIfcDesc_ProtocolOffset] = prot;
  1.2257 +	r = gPort.SetInterfaceDescriptor(0, descriptor);
  1.2258 +	test_KErrNone(r);
  1.2259 +
  1.2260 +	test.Next(_L("GetInterfaceDescriptor()"));
  1.2261 +	TBuf8<KUsbDescSize_Interface> descriptor2;
  1.2262 +	r = gPort.GetInterfaceDescriptor(0, descriptor2);
  1.2263 +	test_KErrNone(r);
  1.2264 +
  1.2265 +	test.Next(_L("Compare interface descriptor with value set"));
  1.2266 +	r = descriptor2.Compare(descriptor);
  1.2267 +	test_KErrNone(r);
  1.2268 +
  1.2269 +	test.End();
  1.2270 +	}
  1.2271 +
  1.2272 +static void TestClassSpecificDescriptors()
  1.2273 +	{
  1.2274 +	test.Start(_L("Class-specific Descriptor Manipulation"));
  1.2275 +
  1.2276 +	// First a class-specific Interface descriptor
  1.2277 +	test.Next(_L("SetCSInterfaceDescriptorBlock()"));
  1.2278 +	// choose arbitrary new descriptor size
  1.2279 +	const TInt KUsbDescSize_CS_Interface = KUsbDescSize_Interface + 10;
  1.2280 +	TBuf8<KUsbDescSize_CS_Interface> cs_ifc_descriptor;
  1.2281 +	cs_ifc_descriptor.FillZ(cs_ifc_descriptor.MaxLength());
  1.2282 +	cs_ifc_descriptor[KUsbDesc_SizeOffset] = KUsbDescSize_CS_Interface;
  1.2283 +	cs_ifc_descriptor[KUsbDesc_TypeOffset] = KUsbDescType_CS_Interface;
  1.2284 +	TInt r = gPort.SetCSInterfaceDescriptorBlock(0, cs_ifc_descriptor);
  1.2285 +	test_KErrNone(r);
  1.2286 +
  1.2287 +	test.Next(_L("GetCSInterfaceDescriptorBlockSize()"));
  1.2288 +	TInt desc_size = 0;
  1.2289 +	r = gPort.GetCSInterfaceDescriptorBlockSize(0, desc_size);
  1.2290 +	test_KErrNone(r);
  1.2291 +	test(desc_size == KUsbDescSize_CS_Interface);
  1.2292 +
  1.2293 +	test.Next(_L("GetCSInterfaceDescriptorBlock()"));
  1.2294 +	TBuf8<KUsbDescSize_CS_Interface> descriptor;
  1.2295 +	r = gPort.GetCSInterfaceDescriptorBlock(0, descriptor);
  1.2296 +	test_KErrNone(r);
  1.2297 +
  1.2298 +	test.Next(_L("Compare CS ifc descriptor with value set"));
  1.2299 +	r = descriptor.Compare(cs_ifc_descriptor);
  1.2300 +	test_KErrNone(r);
  1.2301 +
  1.2302 +	// Next a class-specific Endpoint descriptor
  1.2303 +	test.Next(_L("SetCSEndpointDescriptorBlock()"));
  1.2304 +	// choose arbitrary new descriptor size
  1.2305 +	const TInt KUsbDescSize_CS_Endpoint = KUsbDescSize_Endpoint + 5;
  1.2306 +	TBuf8<KUsbDescSize_CS_Endpoint> cs_ep_descriptor;
  1.2307 +	cs_ep_descriptor.FillZ(cs_ep_descriptor.MaxLength());
  1.2308 +	cs_ep_descriptor[KUsbDesc_SizeOffset] = KUsbDescSize_CS_Endpoint;
  1.2309 +	cs_ep_descriptor[KUsbDesc_TypeOffset] = KUsbDescType_CS_Endpoint;
  1.2310 +	r = gPort.SetCSEndpointDescriptorBlock(0, 2, cs_ep_descriptor);
  1.2311 +	test_KErrNone(r);
  1.2312 +
  1.2313 +	test.Next(_L("GetCSEndpointDescriptorBlockSize()"));
  1.2314 +	r = gPort.GetCSEndpointDescriptorBlockSize(0, 2, desc_size);
  1.2315 +	test_KErrNone(r);
  1.2316 +	test(desc_size == KUsbDescSize_CS_Endpoint);
  1.2317 +
  1.2318 +	test.Next(_L("GetCSEndpointDescriptorBlock()"));
  1.2319 +	TBuf8<KUsbDescSize_CS_Endpoint> descriptor2;
  1.2320 +	r = gPort.GetCSEndpointDescriptorBlock(0, 2, descriptor2);
  1.2321 +	test_KErrNone(r);
  1.2322 +
  1.2323 +	test.Next(_L("Compare CS ep descriptor with value set"));
  1.2324 +	r = descriptor2.Compare(cs_ep_descriptor);
  1.2325 +	test_KErrNone(r);
  1.2326 +
  1.2327 +	test.End();
  1.2328 +	}	
  1.2329 +
  1.2330 +static void TestAlternateInterfaceManipulation()
  1.2331 +	{
  1.2332 +	test.Start(_L("Alternate Interface Setting Manipulation"));
  1.2333 +
  1.2334 +	if (!SupportsAlternateInterfaces())
  1.2335 +		{
  1.2336 +		test.Printf(_L("*** Not supported - skipping alternate interface settings tests\n"));
  1.2337 +		test.End();
  1.2338 +		return;
  1.2339 +		}
  1.2340 +	test_KErrNone(SettingFive(1));
  1.2341 +
  1.2342 +	TInt r;
  1.2343 +	test.Next(_L("Set alternate setting number to 8"));
  1.2344 +	TBuf8<KUsbDescSize_Interface> descriptor;
  1.2345 +	r = gPort.GetInterfaceDescriptor(1, descriptor);
  1.2346 +	test_KErrNone(r);
  1.2347 +	descriptor[KIfcDesc_SettingOffset] = 8;
  1.2348 +	r = gPort.SetInterfaceDescriptor(1, descriptor);
  1.2349 +	test(r != KErrNone);
  1.2350 +
  1.2351 +	test.Next(_L("Change ifc # in def setting whith alt ifcs"));
  1.2352 +	r = gPort.GetInterfaceDescriptor(0, descriptor);
  1.2353 +	test_KErrNone(r);
  1.2354 +	descriptor[KIfcDesc_SettingOffset] = 8;
  1.2355 +	r = gPort.SetInterfaceDescriptor(0, descriptor);
  1.2356 +	test(r != KErrNone);
  1.2357 +
  1.2358 +	test.Next(_L("Change the ifc # in default setting to 8"));
  1.2359 +	r = gPort.ReleaseInterface(1);
  1.2360 +	test_KErrNone(r);
  1.2361 +	r = gPort.SetInterfaceDescriptor(0, descriptor);
  1.2362 +	test_KErrNone(r);
  1.2363 +
  1.2364 +	test.Next(_L("Create new setting - this should also get #8"));
  1.2365 +	test_KErrNone(SettingFive(1));
  1.2366 +
  1.2367 +	r = gPort.GetInterfaceDescriptor(1, descriptor);
  1.2368 +	test_KErrNone(r);
  1.2369 +	test(descriptor[KIfcDesc_SettingOffset] == 8);
  1.2370 +
  1.2371 +	test.Next(_L("Change the ifc # in default setting to 0"));
  1.2372 +	r = gPort.ReleaseInterface(1);
  1.2373 +	test_KErrNone(r);
  1.2374 +	r = gPort.GetInterfaceDescriptor(0, descriptor);
  1.2375 +	test_KErrNone(r);
  1.2376 +	descriptor[KIfcDesc_SettingOffset] = 0;
  1.2377 +	r = gPort.SetInterfaceDescriptor(0, descriptor);
  1.2378 +	test_KErrNone(r);
  1.2379 +
  1.2380 +	test.Next(_L("Create new setting - this should also get #0"));
  1.2381 +	test_KErrNone(SettingFive(1));
  1.2382 +
  1.2383 +	r = gPort.GetInterfaceDescriptor(1, descriptor);
  1.2384 +	test_KErrNone(r);
  1.2385 +	test(descriptor[KIfcDesc_SettingOffset] == 0);
  1.2386 +
  1.2387 +	test.End();
  1.2388 +	}	
  1.2389 +
  1.2390 +static void TestEndpointDescriptor()
  1.2391 +	{
  1.2392 +	test.Start(_L("Endpoint Descriptor Manipulation"));
  1.2393 +
  1.2394 +	test.Next(_L("GetEndpointDescriptorSize(1)"));
  1.2395 +	TInt epNumber = 1;
  1.2396 +	TInt desc_size = 0;
  1.2397 +	TInt r = gPort.GetEndpointDescriptorSize(0, epNumber, desc_size);
  1.2398 +	test_KErrNone(r);
  1.2399 +	test(static_cast<TUint>(desc_size) == KUsbDescSize_Endpoint);
  1.2400 +
  1.2401 +	test.Next(_L("GetEndpointDescriptor(1)"));
  1.2402 +	TBuf8<KUsbDescSize_Endpoint> descriptor;
  1.2403 +	r = gPort.GetEndpointDescriptor(0, epNumber, descriptor);
  1.2404 +	test_KErrNone(r);
  1.2405 +
  1.2406 +	test.Next(_L("SetEndpointDescriptor(1)"));
  1.2407 +	// Change the endpoint poll interval
  1.2408 +	TUint8 ival = 0x66;
  1.2409 +	if (descriptor[KEpDesc_IntervalOffset] == ival)
  1.2410 +		ival++;
  1.2411 +	descriptor[KEpDesc_IntervalOffset] = ival;
  1.2412 +	r = gPort.SetEndpointDescriptor(0, epNumber, descriptor);
  1.2413 +	test_KErrNone(r);
  1.2414 +
  1.2415 +	test.Next(_L("GetEndpointDescriptor(1)"));
  1.2416 +	TBuf8<KUsbDescSize_Endpoint> descriptor2;
  1.2417 +	r = gPort.GetEndpointDescriptor(0, epNumber, descriptor2);
  1.2418 +	test_KErrNone(r);
  1.2419 +
  1.2420 +	test.Next(_L("Compare endpoint descriptor with value set"));
  1.2421 +	r = descriptor2.Compare(descriptor);
  1.2422 +	test_KErrNone(r);
  1.2423 +
  1.2424 +	test.End();
  1.2425 +	}	
  1.2426 +
  1.2427 +static void TestExtendedEndpointDescriptor()
  1.2428 +	{
  1.2429 +	test.Start(_L("Extended Endpoint Descriptor Manipulation"));
  1.2430 +
  1.2431 +	if (!SupportsAlternateInterfaces())
  1.2432 +		{
  1.2433 +		test.Printf(_L("*** Not supported - skipping Extended Endpoint descriptor tests\n"));
  1.2434 +		test.End();
  1.2435 +		return;
  1.2436 +		}
  1.2437 +
  1.2438 +	// Extended Endpoint Descriptor manipulation (Audio class endpoint)
  1.2439 +	test.Next(_L("GetEndpointDescriptorSize()"));
  1.2440 +	TInt epNumber = 1; // refering to first endpoint
  1.2441 +	TInt desc_size = 0;
  1.2442 +	TInt r = gPort.GetEndpointDescriptorSize(1, epNumber, desc_size);
  1.2443 +	test_KErrNone(r);
  1.2444 +	test(static_cast<TUint>(desc_size) == KUsbDescSize_AudioEndpoint);
  1.2445 +
  1.2446 +	test.Next(_L("GetEndpointDescriptor()"));
  1.2447 +	TBuf8<KUsbDescSize_AudioEndpoint> descriptor;
  1.2448 +	r = gPort.GetEndpointDescriptor(1, epNumber, descriptor);
  1.2449 +	test_KErrNone(r);
  1.2450 +
  1.2451 +	test.Next(_L("SetEndpointDescriptor()"));
  1.2452 +	// Change the Audio Endpoint bSynchAddress field
  1.2453 +	TUint8 addr = 0x85;										// bogus address
  1.2454 +	if (descriptor[KEpDesc_SynchAddressOffset] == addr)
  1.2455 +		addr++;
  1.2456 +	descriptor[KEpDesc_SynchAddressOffset] = addr;
  1.2457 +	r = gPort.SetEndpointDescriptor(1, epNumber, descriptor);
  1.2458 +	test_KErrNone(r);
  1.2459 +
  1.2460 +	test.Next(_L("GetEndpointDescriptor()"));
  1.2461 +	TBuf8<KUsbDescSize_AudioEndpoint> descriptor2;
  1.2462 +	r = gPort.GetEndpointDescriptor(1, epNumber, descriptor2);
  1.2463 +	test_KErrNone(r);
  1.2464 +
  1.2465 +	test.Next(_L("Compare endpoint descriptor with value set"));
  1.2466 +	r = descriptor2.Compare(descriptor);
  1.2467 +	test_KErrNone(r);
  1.2468 +
  1.2469 +	test.End();
  1.2470 +	}	
  1.2471 +
  1.2472 +
  1.2473 +static void TestStandardStringDescriptors()
  1.2474 +	{
  1.2475 +	test.Start(_L("String Descriptor Manipulation"));
  1.2476 +
  1.2477 +	// --- LANGID code
  1.2478 +	test.Next(_L("GetStringDescriptorLangId()"));
  1.2479 +	TUint16 rd_langid_orig;
  1.2480 +	TInt r = gPort.GetStringDescriptorLangId(rd_langid_orig);
  1.2481 +	test_KErrNone(r);
  1.2482 +	test.Printf(_L("Original LANGID code: 0x%04X\n"), rd_langid_orig);
  1.2483 +
  1.2484 +	test.Next(_L("SetStringDescriptorLangId()"));
  1.2485 +	TUint16 wr_langid = 0x0809;								// English (UK) Language ID
  1.2486 +	if (wr_langid == rd_langid_orig)
  1.2487 +		wr_langid = 0x0444;									// Tatar Language ID
  1.2488 +	r = gPort.SetStringDescriptorLangId(wr_langid);
  1.2489 +	test_KErrNone(r);
  1.2490 +
  1.2491 +	test.Next(_L("GetStringDescriptorLangId()"));
  1.2492 +	TUint16 rd_langid;
  1.2493 +	r = gPort.GetStringDescriptorLangId(rd_langid);
  1.2494 +	test_KErrNone(r);
  1.2495 +	test.Printf(_L("New LANGID code: 0x%04X\n"), rd_langid);
  1.2496 +
  1.2497 +	test.Next(_L("Compare LANGID codes"));
  1.2498 +	test(rd_langid == wr_langid);
  1.2499 +
  1.2500 +	test.Next(_L("Restore original LANGID code"));
  1.2501 +	r = gPort.SetStringDescriptorLangId(rd_langid_orig);
  1.2502 +	test_KErrNone(r);
  1.2503 +	r = gPort.GetStringDescriptorLangId(rd_langid);
  1.2504 +	test_KErrNone(r);
  1.2505 +	test(rd_langid == rd_langid_orig);
  1.2506 +
  1.2507 +	// --- Manufacturer string
  1.2508 +	test.Next(_L("GetManufacturerStringDescriptor()"));
  1.2509 +	TBuf16<KUsbStringDescStringMaxSize / 2> rd_str_orig;
  1.2510 +	r = gPort.GetManufacturerStringDescriptor(rd_str_orig);
  1.2511 +	test(r == KErrNone || r == KErrNotFound);
  1.2512 +	TBool restore_string;
  1.2513 +	if (r == KErrNone)
  1.2514 +		{
  1.2515 +		test.Printf(_L("Original Manufacturer string: \"%lS\"\n"), &rd_str_orig);
  1.2516 +		restore_string = ETrue;
  1.2517 +		}
  1.2518 +	else
  1.2519 +		{
  1.2520 +		test.Printf(_L("No Manufacturer string set\n"));
  1.2521 +		restore_string = EFalse;
  1.2522 +		}
  1.2523 +
  1.2524 +	test.Next(_L("SetManufacturerStringDescriptor()"));
  1.2525 +	_LIT16(manufacturer, "Manufacturer Which Manufactures Devices");
  1.2526 +	TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(manufacturer);
  1.2527 +	r = gPort.SetManufacturerStringDescriptor(wr_str);
  1.2528 +	test_KErrNone(r);
  1.2529 +
  1.2530 +	test.Next(_L("GetManufacturerStringDescriptor()"));
  1.2531 +	TBuf16<KUsbStringDescStringMaxSize / 2> rd_str;
  1.2532 +	r = gPort.GetManufacturerStringDescriptor(rd_str);
  1.2533 +	test_KErrNone(r);
  1.2534 +	test.Printf(_L("New Manufacturer string: \"%lS\"\n"), &rd_str);
  1.2535 +
  1.2536 +	test.Next(_L("Compare Manufacturer strings"));
  1.2537 +	r = rd_str.Compare(wr_str);
  1.2538 +	test_KErrNone(r);
  1.2539 +
  1.2540 +	test.Next(_L("SetManufacturerStringDescriptor()"));
  1.2541 +	_LIT16(manufacturer2, "Different Manufacturer Which Manufactures Different Devices");
  1.2542 +	wr_str.FillZ(wr_str.MaxLength());
  1.2543 +	wr_str = manufacturer2;
  1.2544 +	r = gPort.SetManufacturerStringDescriptor(wr_str);
  1.2545 +	test_KErrNone(r);
  1.2546 +
  1.2547 +	test.Next(_L("GetManufacturerStringDescriptor()"));
  1.2548 +	rd_str.FillZ(rd_str.MaxLength());
  1.2549 +	r = gPort.GetManufacturerStringDescriptor(rd_str);
  1.2550 +	test_KErrNone(r);
  1.2551 +	test.Printf(_L("New Manufacturer string: \"%lS\"\n"), &rd_str);
  1.2552 +
  1.2553 +	test.Next(_L("Compare Manufacturer strings"));
  1.2554 +	r = rd_str.Compare(wr_str);
  1.2555 +	test_KErrNone(r);
  1.2556 +
  1.2557 +	test.Next(_L("RemoveManufacturerStringDescriptor()"));
  1.2558 +	r = gPort.RemoveManufacturerStringDescriptor();
  1.2559 +	test_KErrNone(r);
  1.2560 +	r = gPort.GetManufacturerStringDescriptor(rd_str);
  1.2561 +	test(r == KErrNotFound);
  1.2562 +
  1.2563 +	if (restore_string)
  1.2564 +		{
  1.2565 +		test.Next(_L("Restore original string"));
  1.2566 +		r = gPort.SetManufacturerStringDescriptor(rd_str_orig);
  1.2567 +		test_KErrNone(r);
  1.2568 +		r = gPort.GetManufacturerStringDescriptor(rd_str);
  1.2569 +		test_KErrNone(r);
  1.2570 +		r = rd_str.Compare(rd_str_orig);
  1.2571 +		test_KErrNone(r);
  1.2572 +		}
  1.2573 +
  1.2574 +	// --- Product string
  1.2575 +	test.Next(_L("GetProductStringDescriptor()"));
  1.2576 +	rd_str_orig.FillZ(rd_str.MaxLength());
  1.2577 +	r = gPort.GetProductStringDescriptor(rd_str_orig);
  1.2578 +	test(r == KErrNone || r == KErrNotFound);
  1.2579 +	if (r == KErrNone)
  1.2580 +		{
  1.2581 +		test.Printf(_L("Old Product string: \"%lS\"\n"), &rd_str_orig);
  1.2582 +		restore_string = ETrue;
  1.2583 +		}
  1.2584 +	else
  1.2585 +		restore_string = EFalse;
  1.2586 +
  1.2587 +	test.Next(_L("SetProductStringDescriptor()"));
  1.2588 +	_LIT16(product, "Product That Was Produced By A Manufacturer");
  1.2589 +	wr_str.FillZ(wr_str.MaxLength());
  1.2590 +	wr_str = product;
  1.2591 +	r = gPort.SetProductStringDescriptor(wr_str);
  1.2592 +	test_KErrNone(r);
  1.2593 +
  1.2594 +	test.Next(_L("GetProductStringDescriptor()"));
  1.2595 +	rd_str.FillZ(rd_str.MaxLength());
  1.2596 +	r = gPort.GetProductStringDescriptor(rd_str);
  1.2597 +	test_KErrNone(r);
  1.2598 +	test.Printf(_L("New Product string: \"%lS\"\n"), &rd_str);
  1.2599 +
  1.2600 +	test.Next(_L("Compare Product strings"));
  1.2601 +	r = rd_str.Compare(wr_str);
  1.2602 +	test_KErrNone(r);
  1.2603 +
  1.2604 +	test.Next(_L("SetProductStringDescriptor()"));
  1.2605 +	_LIT16(product2, "Different Product That Was Produced By A Different Manufacturer");
  1.2606 +	wr_str.FillZ(wr_str.MaxLength());
  1.2607 +	wr_str = product2;
  1.2608 +	r = gPort.SetProductStringDescriptor(wr_str);
  1.2609 +	test_KErrNone(r);
  1.2610 +
  1.2611 +	test.Next(_L("GetProductStringDescriptor()"));
  1.2612 +	rd_str.FillZ(rd_str.MaxLength());
  1.2613 +	r = gPort.GetProductStringDescriptor(rd_str);
  1.2614 +	test_KErrNone(r);
  1.2615 +	test.Printf(_L("New Product string: \"%lS\"\n"), &rd_str);
  1.2616 +
  1.2617 +	test.Next(_L("Compare Product strings"));
  1.2618 +	r = rd_str.Compare(wr_str);
  1.2619 +	test_KErrNone(r);
  1.2620 +
  1.2621 +	test.Next(_L("RemoveProductStringDescriptor()"));
  1.2622 +	r = gPort.RemoveProductStringDescriptor();
  1.2623 +	test_KErrNone(r);
  1.2624 +	r = gPort.GetProductStringDescriptor(rd_str);
  1.2625 +	test(r == KErrNotFound);
  1.2626 +
  1.2627 +	if (restore_string)
  1.2628 +		{
  1.2629 +		test.Next(_L("Restore original string"));
  1.2630 +		r = gPort.SetProductStringDescriptor(rd_str_orig);
  1.2631 +		test_KErrNone(r);
  1.2632 +		r = gPort.GetProductStringDescriptor(rd_str);
  1.2633 +		test_KErrNone(r);
  1.2634 +		r = rd_str.Compare(rd_str_orig);
  1.2635 +		test_KErrNone(r);
  1.2636 +		}
  1.2637 +
  1.2638 +	// --- Serial Number string
  1.2639 +	test.Next(_L("GetSerialNumberStringDescriptor()"));
  1.2640 +	rd_str_orig.FillZ(rd_str.MaxLength());
  1.2641 +	r = gPort.GetSerialNumberStringDescriptor(rd_str_orig);
  1.2642 +	test(r == KErrNone || r == KErrNotFound);
  1.2643 +	if (r == KErrNone)
  1.2644 +		{
  1.2645 +		test.Printf(_L("Old Serial Number: \"%lS\"\n"), &rd_str_orig);
  1.2646 +		restore_string = ETrue;
  1.2647 +		}
  1.2648 +	else
  1.2649 +		restore_string = EFalse;
  1.2650 +
  1.2651 +	test.Next(_L("SetSerialNumberStringDescriptor()"));
  1.2652 +	_LIT16(serial, "000666000XYZ");
  1.2653 +	wr_str.FillZ(wr_str.MaxLength());
  1.2654 +	wr_str = serial;
  1.2655 +	r = gPort.SetSerialNumberStringDescriptor(wr_str);
  1.2656 +	test_KErrNone(r);
  1.2657 +
  1.2658 +	test.Next(_L("GetSerialNumberStringDescriptor()"));
  1.2659 +	rd_str.FillZ(rd_str.MaxLength());
  1.2660 +	r = gPort.GetSerialNumberStringDescriptor(rd_str);
  1.2661 +	test_KErrNone(r);
  1.2662 +	test.Printf(_L("New Serial Number: \"%lS\"\n"), &rd_str);
  1.2663 +
  1.2664 +	test.Next(_L("Compare Serial Number strings"));
  1.2665 +	r = rd_str.Compare(wr_str);
  1.2666 +	test_KErrNone(r);
  1.2667 +
  1.2668 +	test.Next(_L("SetSerialNumberStringDescriptor()"));
  1.2669 +	_LIT16(serial2, "Y11611193111711111Y");
  1.2670 +	wr_str.FillZ(wr_str.MaxLength());
  1.2671 +	wr_str = serial2;
  1.2672 +	r = gPort.SetSerialNumberStringDescriptor(wr_str);
  1.2673 +	test_KErrNone(r);
  1.2674 +
  1.2675 +	test.Next(_L("GetSerialNumberStringDescriptor()"));
  1.2676 +	rd_str.FillZ(rd_str.MaxLength());
  1.2677 +	r = gPort.GetSerialNumberStringDescriptor(rd_str);
  1.2678 +	test_KErrNone(r);
  1.2679 +	test.Printf(_L("New Serial Number: \"%lS\"\n"), &rd_str);
  1.2680 +
  1.2681 +	test.Next(_L("Compare Serial Number strings"));
  1.2682 +	r = rd_str.Compare(wr_str);
  1.2683 +	test_KErrNone(r);
  1.2684 +
  1.2685 +	test.Next(_L("RemoveSerialNumberStringDescriptor()"));
  1.2686 +	r = gPort.RemoveSerialNumberStringDescriptor();
  1.2687 +	test_KErrNone(r);
  1.2688 +	r = gPort.GetSerialNumberStringDescriptor(rd_str);
  1.2689 +	test(r == KErrNotFound);
  1.2690 +
  1.2691 +	if (restore_string)
  1.2692 +		{
  1.2693 +		test.Next(_L("Restore original string"));
  1.2694 +		r = gPort.SetSerialNumberStringDescriptor(rd_str_orig);
  1.2695 +		test_KErrNone(r);
  1.2696 +		r = gPort.GetSerialNumberStringDescriptor(rd_str);
  1.2697 +		test_KErrNone(r);
  1.2698 +		r = rd_str.Compare(rd_str_orig);
  1.2699 +		test_KErrNone(r);
  1.2700 +		}
  1.2701 +
  1.2702 +	// --- Configuration string
  1.2703 +	test.Next(_L("GetConfigurationStringDescriptor()"));
  1.2704 +	rd_str_orig.FillZ(rd_str.MaxLength());
  1.2705 +	r = gPort.GetConfigurationStringDescriptor(rd_str_orig);
  1.2706 +	test(r == KErrNone || r == KErrNotFound);
  1.2707 +	if (r == KErrNone)
  1.2708 +		{
  1.2709 +		test.Printf(_L("Old Configuration string: \"%lS\"\n"), &rd_str_orig);
  1.2710 +		restore_string = ETrue;
  1.2711 +		}
  1.2712 +	else
  1.2713 +		restore_string = EFalse;
  1.2714 +
  1.2715 +	test.Next(_L("SetConfigurationStringDescriptor()"));
  1.2716 +	_LIT16(config, "Relatively Simple Configuration That Is Still Useful");
  1.2717 +	wr_str.FillZ(wr_str.MaxLength());
  1.2718 +	wr_str = config;
  1.2719 +	r = gPort.SetConfigurationStringDescriptor(wr_str);
  1.2720 +	test_KErrNone(r);
  1.2721 +
  1.2722 +	test.Next(_L("GetConfigurationStringDescriptor()"));
  1.2723 +	rd_str.FillZ(rd_str.MaxLength());
  1.2724 +	r = gPort.GetConfigurationStringDescriptor(rd_str);
  1.2725 +	test_KErrNone(r);
  1.2726 +	test.Printf(_L("New Configuration string: \"%lS\"\n"), &rd_str);
  1.2727 +
  1.2728 +	test.Next(_L("Compare Configuration strings"));
  1.2729 +	r = rd_str.Compare(wr_str);
  1.2730 +	test_KErrNone(r);
  1.2731 +
  1.2732 +	test.Next(_L("SetConfigurationStringDescriptor()"));
  1.2733 +	_LIT16(config2, "Convenient Configuration That Can Be Very Confusing");
  1.2734 +	wr_str.FillZ(wr_str.MaxLength());
  1.2735 +	wr_str = config2;
  1.2736 +	r = gPort.SetConfigurationStringDescriptor(wr_str);
  1.2737 +	test_KErrNone(r);
  1.2738 +
  1.2739 +	test.Next(_L("GetConfigurationStringDescriptor()"));
  1.2740 +	rd_str.FillZ(rd_str.MaxLength());
  1.2741 +	r = gPort.GetConfigurationStringDescriptor(rd_str);
  1.2742 +	test_KErrNone(r);
  1.2743 +	test.Printf(_L("New Configuration string: \"%lS\"\n"), &rd_str);
  1.2744 +
  1.2745 +	test.Next(_L("Compare Configuration strings"));
  1.2746 +	r = rd_str.Compare(wr_str);
  1.2747 +	test_KErrNone(r);
  1.2748 +
  1.2749 +	test.Next(_L("RemoveConfigurationStringDescriptor()"));
  1.2750 +	r = gPort.RemoveConfigurationStringDescriptor();
  1.2751 +	test_KErrNone(r);
  1.2752 +	r = gPort.GetConfigurationStringDescriptor(rd_str);
  1.2753 +	test(r == KErrNotFound);
  1.2754 +
  1.2755 +	if (restore_string)
  1.2756 +		{
  1.2757 +		test.Next(_L("Restore original string"));
  1.2758 +		r = gPort.SetConfigurationStringDescriptor(rd_str_orig);
  1.2759 +		test_KErrNone(r);
  1.2760 +		r = gPort.GetConfigurationStringDescriptor(rd_str);
  1.2761 +		test_KErrNone(r);
  1.2762 +		r = rd_str.Compare(rd_str_orig);
  1.2763 +		test_KErrNone(r);
  1.2764 +		}
  1.2765 +
  1.2766 +	test.End();
  1.2767 +	}
  1.2768 +
  1.2769 +static void TestArbitraryStringDescriptors()
  1.2770 +	{
  1.2771 +	test.Start(_L("Arbitrary String Descriptor Manipulation"));
  1.2772 +
  1.2773 +	const TUint8 stridx1 = 0xEE;
  1.2774 +	const TUint8 stridx2 = 0xCC;
  1.2775 +	const TUint8 stridx3 = 0xDD;
  1.2776 +	const TUint8 stridx4 = 0xFF;
  1.2777 +
  1.2778 +	// First test string
  1.2779 +	test.Next(_L("GetStringDescriptor() 1"));
  1.2780 +	TBuf16<KUsbStringDescStringMaxSize / 2> rd_str;
  1.2781 +	TInt r = gPort.GetStringDescriptor(stridx1, rd_str);
  1.2782 +	test(r == KErrNotFound);
  1.2783 +
  1.2784 +	test.Next(_L("SetStringDescriptor() 1"));
  1.2785 +	_LIT16(string_one, "Arbitrary String Descriptor Test String 1");
  1.2786 +	TBuf16<KUsbStringDescStringMaxSize / 2> wr_str(string_one);
  1.2787 +	r = gPort.SetStringDescriptor(stridx1, wr_str);
  1.2788 +	test_KErrNone(r);
  1.2789 +
  1.2790 +	test.Next(_L("GetStringDescriptor() 1"));
  1.2791 +	r = gPort.GetStringDescriptor(stridx1, rd_str);
  1.2792 +	test_KErrNone(r);
  1.2793 +	test.Printf(_L("New test string @ idx %d: \"%lS\"\n"), stridx1, &rd_str);
  1.2794 +
  1.2795 +	test.Next(_L("Compare test strings 1"));
  1.2796 +	r = rd_str.Compare(wr_str);
  1.2797 +	test_KErrNone(r);
  1.2798 +
  1.2799 +	// Second test string
  1.2800 +	test.Next(_L("GetStringDescriptor() 2"));
  1.2801 +	rd_str.FillZ(rd_str.MaxLength());
  1.2802 +	r = gPort.GetStringDescriptor(stridx2, rd_str);
  1.2803 +	test(r == KErrNotFound);
  1.2804 +
  1.2805 +	test.Next(_L("SetStringDescriptor() 2"));
  1.2806 +	_LIT16(string_two, "Arbitrary String Descriptor Test String 2");
  1.2807 +	wr_str.FillZ(wr_str.MaxLength());
  1.2808 +	wr_str = string_two;
  1.2809 +	r = gPort.SetStringDescriptor(stridx2, wr_str);
  1.2810 +	test_KErrNone(r);
  1.2811 +
  1.2812 +	// In between we create another interface setting to see what happens
  1.2813 +	// to the existing string descriptor indices.
  1.2814 +	// (We don't have to test this on every platform -
  1.2815 +	// besides, those that don't support alt settings
  1.2816 +	// are by now very rare.)
  1.2817 +	if (SupportsAlternateInterfaces())
  1.2818 +		{
  1.2819 +		TUsbcScInterfaceInfoBuf ifc;
  1.2820 +		_LIT16(string, "T_USBAPI Bogus Test Interface (Setting 2)");
  1.2821 +		ifc().iString = const_cast<TDesC16*>(&string);
  1.2822 +		ifc().iTotalEndpointsUsed = 0;
  1.2823 +		TInt r = gPort.SetInterface(2, ifc);
  1.2824 +		test_KErrNone(r);
  1.2825 +		}
  1.2826 +
  1.2827 +	test.Next(_L("GetStringDescriptor() 2"));
  1.2828 +	r = gPort.GetStringDescriptor(stridx2, rd_str);
  1.2829 +	test_KErrNone(r);
  1.2830 +	test.Printf(_L("New test string @ idx %d: \"%lS\"\n"), stridx2, &rd_str);
  1.2831 +
  1.2832 +	test.Next(_L("Compare test strings 2"));
  1.2833 +	r = rd_str.Compare(wr_str);
  1.2834 +	test_KErrNone(r);
  1.2835 +
  1.2836 +	// Third test string
  1.2837 +	test.Next(_L("GetStringDescriptor() 3"));
  1.2838 +	rd_str.FillZ(rd_str.MaxLength());
  1.2839 +	r = gPort.GetStringDescriptor(stridx3, rd_str);
  1.2840 +	test(r == KErrNotFound);
  1.2841 +
  1.2842 +	test.Next(_L("SetStringDescriptor() 3"));
  1.2843 +	_LIT16(string_three, "Arbitrary String Descriptor Test String 3");
  1.2844 +	wr_str.FillZ(wr_str.MaxLength());
  1.2845 +	wr_str = string_three;
  1.2846 +	r = gPort.SetStringDescriptor(stridx3, wr_str);
  1.2847 +	test_KErrNone(r);
  1.2848 +
  1.2849 +	test.Next(_L("GetStringDescriptor() 3"));
  1.2850 +	r = gPort.GetStringDescriptor(stridx3, rd_str);
  1.2851 +	test_KErrNone(r);
  1.2852 +	test.Printf(_L("New test string @ idx %d: \"%lS\"\n"), stridx3, &rd_str);
  1.2853 +
  1.2854 +	test.Next(_L("Compare test strings 3"));
  1.2855 +	r = rd_str.Compare(wr_str);
  1.2856 +	test_KErrNone(r);
  1.2857 +
  1.2858 +	// Remove string descriptors
  1.2859 +	test.Next(_L("RemoveStringDescriptor() 4"));
  1.2860 +	r = gPort.RemoveStringDescriptor(stridx4);
  1.2861 +	test(r == KErrNotFound);
  1.2862 +
  1.2863 +	test.Next(_L("RemoveStringDescriptor() 3"));
  1.2864 +	r = gPort.RemoveStringDescriptor(stridx3);
  1.2865 +	test_KErrNone(r);
  1.2866 +	r = gPort.GetStringDescriptor(stridx3, rd_str);
  1.2867 +	test(r == KErrNotFound);
  1.2868 +
  1.2869 +	test.Next(_L("RemoveStringDescriptor() 2"));
  1.2870 +	r = gPort.RemoveStringDescriptor(stridx2);
  1.2871 +	test_KErrNone(r);
  1.2872 +	r = gPort.GetStringDescriptor(stridx2, rd_str);
  1.2873 +	test(r == KErrNotFound);
  1.2874 +
  1.2875 +	test.Next(_L("RemoveStringDescriptor() 1"));
  1.2876 +	r = gPort.RemoveStringDescriptor(stridx1);
  1.2877 +	test_KErrNone(r);
  1.2878 +	r = gPort.GetStringDescriptor(stridx1, rd_str);
  1.2879 +	test(r == KErrNotFound);
  1.2880 +
  1.2881 +	test.End();
  1.2882 +	}	
  1.2883 +
  1.2884 +static TEndpointState QueryEndpointState(TInt aEndpoint)
  1.2885 +	{
  1.2886 +	TEndpointState ep_state = EEndpointStateUnknown;
  1.2887 +	TInt r = gPort.EndpointStatus(aEndpoint, ep_state);
  1.2888 +	test(r == KErrNone);
  1.2889 +	test.Printf(_L("Endpoint %d state: %s\n"), aEndpoint,
  1.2890 +				(ep_state == EEndpointStateNotStalled) ? _S("Not stalled") :
  1.2891 +				((ep_state == EEndpointStateStalled) ? _S("Stalled") :
  1.2892 +				 _S("Unknown...")));
  1.2893 +	return ep_state;
  1.2894 +	}
  1.2895 +
  1.2896 +static void TestEndpointStallStatus()
  1.2897 +	{
  1.2898 +	test.Start(_L("Test Endpoint Stall Status"));
  1.2899 +
  1.2900 +	if (!SupportsEndpointStall())
  1.2901 +		{
  1.2902 +		test.Printf(_L("*** Not supported - skipping endpoint stall status tests\n"));
  1.2903 +		test.End();
  1.2904 +		return;
  1.2905 +		}
  1.2906 +
  1.2907 +	test.Next(_L("Endpoint stall status"));
  1.2908 +	TEndpointState epState = EEndpointStateUnknown;
  1.2909 +	test_Equal(EEndpointStateNotStalled, QueryEndpointState(1));
  1.2910 +	test_Equal(EEndpointStateNotStalled, QueryEndpointState(2));
  1.2911 +
  1.2912 +	test.Next(_L("Stall Ep1"));
  1.2913 +	gPort.HaltEndpoint(1);
  1.2914 +	epState = QueryEndpointState(1);
  1.2915 +	test(epState == EEndpointStateStalled);
  1.2916 +
  1.2917 +	test.Next(_L("Clear Stall Ep1"));
  1.2918 +	gPort.ClearHaltEndpoint(1);
  1.2919 +	epState = QueryEndpointState(1);
  1.2920 +	test(epState == EEndpointStateNotStalled);
  1.2921 +
  1.2922 +	test.Next(_L("Stall Ep2"));
  1.2923 +	gPort.HaltEndpoint(2);
  1.2924 +	epState = QueryEndpointState(2);
  1.2925 +	test(epState == EEndpointStateStalled);
  1.2926 +
  1.2927 +	test.Next(_L("Clear Stall Ep2"));
  1.2928 +	gPort.ClearHaltEndpoint(2);
  1.2929 +	epState = QueryEndpointState(2);
  1.2930 +	test(epState == EEndpointStateNotStalled);
  1.2931 +
  1.2932 +	test.End();
  1.2933 +	}
  1.2934 +
  1.2935 +static void TestEndpointStatusNotify()
  1.2936 +	{
  1.2937 +	test.Start(_L("Test Endpoint Status Notification"));
  1.2938 +
  1.2939 +	TRequestStatus ep_status;
  1.2940 +	TUint epStateBitmap = 0xffffffff;						// put in a nonsense value
  1.2941 +	test.Next(_L("EndpointStatusNotify()"));
  1.2942 +	gPort.EndpointStatusNotify(ep_status, epStateBitmap);
  1.2943 +	test.Next(_L("EndpointStatusNotifyCancel()"));
  1.2944 +	gPort.EndpointStatusNotifyCancel();
  1.2945 +	User::WaitForRequest(ep_status);
  1.2946 +	test(ep_status.Int() == KErrCancel);
  1.2947 +	test.Next(_L("Check endpoint state bitmap returned"));
  1.2948 +	// Our interface only uses 2 eps + ep0
  1.2949 +	const TUint usedEpBitmap = (1 << 0 | 1 << 1 | 1 << 2);
  1.2950 +	// Must not return info about non existent Eps:
  1.2951 +	test((epStateBitmap & ~usedEpBitmap) == 0);
  1.2952 +	for (TInt i = 0; i <= 2; i++)
  1.2953 +		{
  1.2954 +		if ((epStateBitmap & (1 << i)) == EEndpointStateNotStalled)
  1.2955 +			{
  1.2956 +			test.Printf(_L("EndpointStatusNotify: Ep %d NOT STALLED\n"), i);
  1.2957 +			}
  1.2958 +		else
  1.2959 +			{
  1.2960 +			test.Printf(_L("EndpointStatusNotify: Ep %d STALLED\n"), i);
  1.2961 +			}
  1.2962 +		}
  1.2963 +
  1.2964 +	test.End();
  1.2965 +	}
  1.2966 +
  1.2967 +static void TestAlternateDeviceStatusNotify()
  1.2968 +	{
  1.2969 +	test.Start(_L("Test Alternate Device Status Notification"));
  1.2970 +
  1.2971 +	TRequestStatus dev_status;
  1.2972 +	TUint deviceState = 0xffffffff;						// put in a nonsense value
  1.2973 +	test.Next(_L("AlternateDeviceStatusNotify()"));
  1.2974 +	gPort.AlternateDeviceStatusNotify(dev_status, deviceState);
  1.2975 +	test.Next(_L("AlternateDeviceStatusNotifyCancel()"));
  1.2976 +	gPort.AlternateDeviceStatusNotifyCancel();
  1.2977 +	User::WaitForRequest(dev_status);
  1.2978 +	test(dev_status == KErrCancel || dev_status == KErrNone);
  1.2979 +	if (deviceState & KUsbAlternateSetting)
  1.2980 +		{
  1.2981 +		TUint setting = (deviceState & ~KUsbAlternateSetting);
  1.2982 +		test.Printf(_L("Alternate setting change to setting %d - unexpected"), setting);
  1.2983 +		test(EFalse);
  1.2984 +		}
  1.2985 +	else
  1.2986 +		{
  1.2987 +		switch (deviceState)
  1.2988 +			{
  1.2989 +		case EUsbcDeviceStateUndefined:
  1.2990 +			test.Printf(_L("TestAlternateDeviceStatusNotify: Undefined state\n"));
  1.2991 +			break;
  1.2992 +		case EUsbcDeviceStateAttached:
  1.2993 +			test.Printf(_L("TestAlternateDeviceStatusNotify: Attached state\n"));
  1.2994 +			break;
  1.2995 +		case EUsbcDeviceStatePowered:
  1.2996 +			test.Printf(_L("TestAlternateDeviceStatusNotify: Powered state\n"));
  1.2997 +			break;
  1.2998 +		case EUsbcDeviceStateDefault:
  1.2999 +			test.Printf(_L("TestAlternateDeviceStatusNotify: Default state\n"));
  1.3000 +			break;
  1.3001 +		case EUsbcDeviceStateAddress:
  1.3002 +			test.Printf(_L("TestAlternateDeviceStatusNotify: Address state\n"));
  1.3003 +			break;
  1.3004 +		case EUsbcDeviceStateConfigured:
  1.3005 +			test.Printf(_L("TestAlternateDeviceStatusNotify: Configured state\n"));
  1.3006 +			break;
  1.3007 +		case EUsbcDeviceStateSuspended:
  1.3008 +			test.Printf(_L("TestAlternateDeviceStatusNotify: Suspended state\n"));
  1.3009 +			break;
  1.3010 +		case EUsbcNoState:
  1.3011 +			test.Printf(_L("TestAlternateDeviceStatusNotify: State buffering error\n"));
  1.3012 +			test(EFalse);
  1.3013 +			break;
  1.3014 +		default:
  1.3015 +			test.Printf(_L("TestAlternateDeviceStatusNotify: Unknown state\n"));
  1.3016 +			test(EFalse);
  1.3017 +			}
  1.3018 +		}
  1.3019 +	test.End();
  1.3020 +	}	
  1.3021 +
  1.3022 +static void TestDeviceControl()
  1.3023 +	{
  1.3024 +	test.Start(_L("Test Device Control"));
  1.3025 +
  1.3026 +	test.Next(_L("SetDeviceControl()"));
  1.3027 +	TInt r = gPort.SetDeviceControl();
  1.3028 +	test_KErrNone(r);
  1.3029 +	test.Next(_L("ReleaseDeviceControl()"));
  1.3030 +	r = gPort.ReleaseDeviceControl();
  1.3031 +	test_KErrNone(r);
  1.3032 +
  1.3033 +	test.End();
  1.3034 +	}
  1.3035 +
  1.3036 +static void TestDescriptorManipulation()
  1.3037 +	{
  1.3038 +	test.Start(_L("Test USB Descriptor Manipulation"));
  1.3039 +	
  1.3040 +	LoadDriver();
  1.3041 +	OpenChannel();
  1.3042 +	test_KErrNone(SettingOne(0));
  1.3043 +
  1.3044 +	TestDeviceControl();
  1.3045 +	
  1.3046 +	TestAlternateDeviceStatusNotify();
  1.3047 +
  1.3048 +	TestDeviceDescriptor();
  1.3049 +
  1.3050 +	TestDeviceQualifierDescriptor();
  1.3051 +
  1.3052 +	TestConfigurationDescriptor();
  1.3053 +
  1.3054 +	TestOtherSpeedConfigurationDescriptor();
  1.3055 +
  1.3056 +	TestInterfaceDescriptor();
  1.3057 +
  1.3058 +	TestEndpointDescriptor();
  1.3059 +
  1.3060 +	TestClassSpecificDescriptors();
  1.3061 +
  1.3062 +	TestStandardStringDescriptors();	
  1.3063 +
  1.3064 +	TestAlternateInterfaceManipulation();
  1.3065 +
  1.3066 +	TestExtendedEndpointDescriptor();
  1.3067 +
  1.3068 +	TestArbitraryStringDescriptors();
  1.3069 +	
  1.3070 +	TestEndpointStallStatus();
  1.3071 +
  1.3072 +	TestEndpointStatusNotify();
  1.3073 +
  1.3074 +	CloseChannel();
  1.3075 +	UnloadDriver();
  1.3076 +
  1.3077 +	test.End();
  1.3078 +	}
  1.3079 +
  1.3080 +void LoadDriver()
  1.3081 +	{
  1.3082 +	test.Next(_L("Load USB LDD"));
  1.3083 +	TInt r = User::LoadLogicalDevice(KLddName);
  1.3084 +	test_Value(r, r == KErrNone || r == KErrAlreadyExists);  
  1.3085 +	}	
  1.3086 +
  1.3087 +void OpenChannel()
  1.3088 +	{
  1.3089 +	test.Next(_L("Open Channel"));
  1.3090 +
  1.3091 +	TInt r = gPort.Open(0);
  1.3092 +	test_KErrNone(r);
  1.3093 +	}
  1.3094 +
  1.3095 +void TestMultipleChannels()
  1.3096 +	{
  1.3097 +	RDevUsbcScClient lPort1;
  1.3098 +	test.Next(_L("Open local USB channel 1"));
  1.3099 +	TInt r = lPort1.Open(0);
  1.3100 +	test_KErrNone(r);
  1.3101 +
  1.3102 +	RDevUsbcScClient lPort2;
  1.3103 +	test.Next(_L("Open local USB channel 2"));
  1.3104 +	r = lPort2.Open(0);
  1.3105 +	test_KErrNone(r);
  1.3106 +
  1.3107 +	test.Next(_L("Close USB Channel 1"));
  1.3108 +	lPort1.Close();
  1.3109 +
  1.3110 +	RDevUsbcScClient lPort3;
  1.3111 +	test.Next(_L("Open local USB channel 3"));
  1.3112 +	r = lPort3.Open(0);
  1.3113 +	test_KErrNone(r);
  1.3114 +
  1.3115 +	test.Next(_L("Close USB Channel 2"));
  1.3116 +	lPort2.Close();
  1.3117 +
  1.3118 +	test.Next(_L("Close USB Channel 3"));
  1.3119 +	lPort3.Close();
  1.3120 +	}
  1.3121 +
  1.3122 +void CloseChannel()
  1.3123 +	{
  1.3124 +	test.Next(_L("Close Chunk Handle"));
  1.3125 +	gChunk.Close();
  1.3126 +
  1.3127 +	test.Next(_L("Close USB Channel"));
  1.3128 +	gPort.Close();
  1.3129 +	}
  1.3130 +
  1.3131 +void UnloadDriver()
  1.3132 +	{
  1.3133 +	// This delay isnt technically needed - its here for test reasons only!
  1.3134 +	// By waiting, we can see if we get a KErrNone, meaning we know the chunk went away.
  1.3135 +	// In a real life case - some other client might be using the chunk for a while,
  1.3136 +	// but this wouldnt matter, it just means we get a diffrent error code.
  1.3137 +	
  1.3138 +	test.Next(_L("Free USB LDD"));
  1.3139 +	User::After(100000);
  1.3140 +	TInt r = User::FreeLogicalDevice(KUsbDeviceName);
  1.3141 +	test_KErrNone(r);
  1.3142 +	}
  1.3143 +
  1.3144 +void SetupBulkInterfaces(TUint aInterfaceNo,TUint nReadEps, TUint nWriteEps)
  1.3145 +	{
  1.3146 +	test.Printf(_L("SetupBulkInterfaces: %d, %d, %d\n"),aInterfaceNo,nReadEps,nWriteEps);
  1.3147 +	TUsbcScInterfaceInfoBuf ifc;
  1.3148 +	TUint i;
  1.3149 +	for(i=0; i<nWriteEps;i++)
  1.3150 +		{
  1.3151 +		ifc().iEndpointData[i].iType = KUsbEpTypeBulk;
  1.3152 +		ifc().iEndpointData[i].iDir  = KUsbEpDirIn;
  1.3153 +		ifc().iEndpointData[i].iSize = KUsbEpSize64;
  1.3154 +		}
  1.3155 +
  1.3156 +	while(i < (nReadEps + nWriteEps))
  1.3157 +		{
  1.3158 +		ifc().iEndpointData[i].iType = KUsbEpTypeBulk;
  1.3159 +		ifc().iEndpointData[i].iDir  = KUsbEpDirOut;
  1.3160 +		ifc().iEndpointData[i].iSize = KUsbEpSize64;
  1.3161 +		i++;
  1.3162 +		}
  1.3163 +
  1.3164 +	_LIT16(string, "T_USBAPI Test Interface");
  1.3165 +	ifc().iString = const_cast<TDesC16*>(&string);
  1.3166 +	ifc().iTotalEndpointsUsed = nReadEps + nWriteEps;
  1.3167 +	ifc().iClass.iClassNum	  = 0xff;
  1.3168 +	ifc().iClass.iSubClassNum = 0xff;
  1.3169 +	ifc().iClass.iProtocolNum = 0xff;
  1.3170 +	TInt r = gPort.SetInterface(aInterfaceNo, ifc);
  1.3171 +	test_KErrNone(r);
  1.3172 +	}
  1.3173 +
  1.3174 +void PrintBILTestOptions()
  1.3175 +	{
  1.3176 +	test.Printf(_L("Select an option\n"));
  1.3177 +	test.Printf(_L("1.Test BIL API\n"));	//unimplemented
  1.3178 +	test.Printf(_L("2.Test BIL Read Write\n"));
  1.3179 +	test.Printf(_L("3.Test EP0 using BIL API's\n"));
  1.3180 +	test.Printf(_L("4.Test AlternateSetting Change BIL API's\n"));	//unimplemented	
  1.3181 +	test.Printf(_L("5.Run All\n"));
  1.3182 +	test.Printf(_L("6.Quit\n"));
  1.3183 +	}
  1.3184 +
  1.3185 +void PrintWriteOptions()
  1.3186 +	{
  1.3187 +	test.Printf(_L("Select an option\n"));
  1.3188 +	test.Printf(_L("1.Test single buffer write\n"));
  1.3189 +	test.Printf(_L("2.Test double buffer write\n"));
  1.3190 +	test.Printf(_L("3.Test multiple queing write\n"));
  1.3191 +	}
  1.3192 +
  1.3193 +
  1.3194 +_LIT(KLitHostToDev,"Host to Device");
  1.3195 +_LIT(KLitDevToHost,"Device to Host");
  1.3196 +const TDesC* const KLitDirections[2] = {&KLitHostToDev, &KLitDevToHost};
  1.3197 +
  1.3198 +_LIT(KLitStandard, "standard");
  1.3199 +_LIT(KLitClass, "class");
  1.3200 +_LIT(KLitVendor, "vendor");
  1.3201 +_LIT(KLitUnkown, "unknown");
  1.3202 +const TDesC* const KLitType[4] = {&KLitStandard, &KLitClass, &KLitVendor, &KLitUnkown};
  1.3203 +
  1.3204 +_LIT(KLitDevice, "Device");
  1.3205 +_LIT(KLitInterface, "Interface");
  1.3206 +_LIT(KLitEndpoint, "Endpoint");
  1.3207 +_LIT(KLitOther, "Other");
  1.3208 +const TDesC* const KLitDest[4] = {&KLitDevice, &KLitInterface, &KLitEndpoint, &KLitOther};
  1.3209 +
  1.3210 +
  1.3211 +void PrintSetupPkt(Sep0SetupPacket* setup)
  1.3212 +	{
  1.3213 +
  1.3214 +	if(setup != NULL)
  1.3215 +		{
  1.3216 +		test.Printf(_L("EP0 command:\n"));
  1.3217 +		test.Printf(_L("Direction: %S, "),KLitDirections[(setup->iRequestType>>KDirBit) & 0x1]);
  1.3218 +		test.Printf(_L("Request type: %S, "), KLitType[((setup->iRequestType>>KReqTypeBit) & 0x3)]);
  1.3219 +
  1.3220 +		if (setup->iRequestType & KRecepientReservedMask)
  1.3221 +			test.Printf(_L("Recepient: Unknown (0x%x), "), setup->iRequestType & KRecepientMask);
  1.3222 +		else
  1.3223 +			test.Printf(_L("Recepient: %S\n"), KLitDest[(setup->iRequestType & KRecepientMask)]);
  1.3224 +
  1.3225 +		test.Printf(_L("bRequest:0x%x, "),setup->iRequest);
  1.3226 +		test.Printf(_L("wValue:0x%x, "),setup->iwValue);
  1.3227 +		test.Printf(_L("wIndex:0x%x, "),setup->iwIndex);
  1.3228 +		test.Printf(_L("wLength:0x%x\n"),setup->iWlength);
  1.3229 +		}
  1.3230 +	}
  1.3231 +
  1.3232 +void WriteDataToBuffer(TAny* aBufferStartAddr,TUint aLength,TDes8& aWriteBuf)
  1.3233 +	{
  1.3234 +	TUint8 * scBufferAddr = (TUint8*) aBufferStartAddr; 
  1.3235 +	TUint i;
  1.3236 +	//create the write buffer
  1.3237 +	for(i=0;i<aLength;i++)
  1.3238 +		{
  1.3239 +		aWriteBuf.Append(i);			//data is duplicated here in writebuffer and sc location, cant think of anyth better at the moment;
  1.3240 +		*(scBufferAddr) = i;
  1.3241 +		//test.Printf(_L("Addr:0x%x, data[i]:%d "),scBufferAddr,*(scBufferAddr));
  1.3242 +		scBufferAddr += 1;
  1.3243 +		}	
  1.3244 +	}
  1.3245 +void BILWrite(TDes8& aWriteBuf)
  1.3246 +	{
  1.3247 +	TInt ret = KErrNone;
  1.3248 +	test.Printf(_L("TestBILWrite\n"));
  1.3249 +	TEndpointBuffer epBuf;
  1.3250 +	const TUint KWriteEp = 1;
  1.3251 +	TRequestStatus status;
  1.3252 +	TRequestStatus status1,status2;
  1.3253 +	TUint length;
  1.3254 +	TAny* buffer;
  1.3255 +
  1.3256 +	//Open endpoint
  1.3257 +	test_KErrNone(gPort.OpenEndpoint(epBuf,KWriteEp));
  1.3258 +	test_KErrNone(epBuf.GetInBufferRange(buffer, length));
  1.3259 +
  1.3260 +	char ch='0';
  1.3261 +	do{
  1.3262 +		PrintWriteOptions();
  1.3263 +		ch = test.Getch();
  1.3264 +		switch(ch)
  1.3265 +			{
  1.3266 +			case '1':
  1.3267 +				//case 1: Write a buffer fulll of data to USBIO demo app: Total data written- 1xBuffersize
  1.3268 +				test.Printf(_L("Length to be written: %d\n"),length);
  1.3269 +				WriteDataToBuffer(buffer,length,aWriteBuf);
  1.3270 +				//need to check allignment
  1.3271 +				test.Printf(_L("Data ready to be written out, Start 'read to file' on an IN endpoint onthe  USBIO demo application then press a key when ready to proceed\n"));
  1.3272 +				test.Getch();
  1.3273 +				test_KErrNone(epBuf.WriteBuffer(buffer,length,ETrue,status));
  1.3274 +				//Note-Till here is common for all options and can be put in a common place. Repeating the code for the sake of better understanding
  1.3275 +				User::WaitForRequest(status);
  1.3276 +				if(gVerbose)
  1.3277 +					test.Printf(_L("Write status %d\n"),status.Int());
  1.3278 +				test_KErrNone(status.Int());
  1.3279 +				test.Printf(_L("Total bytes written:%d\n"),aWriteBuf.Length());
  1.3280 +				test.Printf(_L("Stop writing at the USBIO demo dialog window, Press a key to continue##\n"));
  1.3281 +				test.Getch();
  1.3282 +				break;
  1.3283 +
  1.3284 +			case '2':
  1.3285 +				//case 2: Write a buffer fulll of data to USBIO demo app wait until it is written out, write a second buffer full of data: Total data written- 2xBuffersize
  1.3286 +				WriteDataToBuffer(buffer,length,aWriteBuf);
  1.3287 +				test.Printf(_L("Data ready to be written out, Start the write mode on USBIO demo application and press a key when ready to proceed\n"));
  1.3288 +				test.Getch();
  1.3289 +				ret = epBuf.WriteBuffer(buffer,length,EFalse,status);
  1.3290 +				test_KErrNone(ret);
  1.3291 +				User::WaitForRequest(status);
  1.3292 +				test_KErrNone(status.Int());
  1.3293 +
  1.3294 +				WriteDataToBuffer(buffer,length,aWriteBuf);
  1.3295 +				ret = epBuf.WriteBuffer(buffer,length,ETrue,status);
  1.3296 +				test_KErrNone(ret);
  1.3297 +				User::WaitForRequest(status);
  1.3298 +				test_KErrNone(status.Int());
  1.3299 +
  1.3300 +				test.Printf(_L("Total bytes written:%d\n"),aWriteBuf.Length());
  1.3301 +				test.Printf(_L("Stop writing at the USBIO demo dialog window,Press a key to continue\n"));
  1.3302 +				test.Getch();
  1.3303 +				break;
  1.3304 +
  1.3305 +			case '3':	
  1.3306 +				//case 3: Write maxpacketsize (64 bytes) of data to USBIO demo app, queue remianing data in buffer (full buffer length-maxpacket size), wait for results: Total data written- 1xBuffersize
  1.3307 +				WriteDataToBuffer(buffer,64,aWriteBuf);
  1.3308 +				test.Printf(_L("Data ready to be written out, Start the write mode on USBIO demo application and press a key when ready to proceed\n"));
  1.3309 +				test.Getch();
  1.3310 +
  1.3311 +				ret = epBuf.WriteBuffer(buffer,64,EFalse,status1);
  1.3312 +				test_KErrNone(ret);
  1.3313 +
  1.3314 +				WriteDataToBuffer((TUint8*)buffer+64,length-64,aWriteBuf);
  1.3315 +				ret = epBuf.WriteBuffer((TUint8*)buffer+64,length-64,ETrue,status2);
  1.3316 +				test_KErrNone(ret);
  1.3317 +
  1.3318 +				User::WaitForRequest(status1);
  1.3319 +				test_KErrNone(status1.Int());
  1.3320 +				User::WaitForRequest(status2);
  1.3321 +				test_KErrNone(status2.Int());
  1.3322 +				
  1.3323 +				test.Printf(_L("Total bytes written: %d\n"),aWriteBuf.Length());
  1.3324 +				test.Printf(_L("Stop writing at the USBIO demo dialog window,Press a key to continue\n"));
  1.3325 +				test.Getch();
  1.3326 +				break;
  1.3327 +				
  1.3328 +			default:
  1.3329 +				ch='R'; //repeat
  1.3330 +				break;
  1.3331 +			}
  1.3332 +		}while(ch == 'R');
  1.3333 +
  1.3334 +	epBuf.Close();
  1.3335 +
  1.3336 +	}
  1.3337 +
  1.3338 +
  1.3339 +void BILRead(TDes8& aReadBuf)
  1.3340 +	{
  1.3341 +	test.Printf(_L("TestBILRead\n"));
  1.3342 +	TEndpointBuffer epBuf;
  1.3343 +	const TUint KReadEp = 2;
  1.3344 +	TRequestStatus status;
  1.3345 +	
  1.3346 +	//Open endpoint
  1.3347 +	gPort.OpenEndpoint(epBuf,KReadEp);
  1.3348 +	test.Printf(_L("Open endpoint results for read endpoint\n"));
  1.3349 +
  1.3350 +	//call GetBuffer, loop as long as EoF is not received
  1.3351 +	TAny *readBuf;
  1.3352 +	TUint aSize;
  1.3353 +	TBool aZlp;		
  1.3354 +
  1.3355 +	do
  1.3356 +		{
  1.3357 +		aSize = 0;
  1.3358 +		aZlp = EFalse;
  1.3359 +		TInt ret = KErrGeneral;
  1.3360 +		ret = epBuf.GetBuffer(readBuf,aSize,aZlp,status);
  1.3361 +		if(gVerbose)
  1.3362 +			test.Printf(_L("Getbuffer call returned %d, aSize: %d, aZlp: %d\n"),ret, aSize,aZlp);
  1.3363 +		
  1.3364 +		if(ret == KErrCompletion)
  1.3365 +			{
  1.3366 +			//add the data to read buffer
  1.3367 +			TUint8 *buffer = (TUint8 *)readBuf;
  1.3368 +			aReadBuf.Append(&buffer[0],aSize);
  1.3369 +			}
  1.3370 +		else
  1.3371 +			{
  1.3372 +			test_KErrNone(ret);
  1.3373 +			test.Printf(_L("Waiting for Data, Data read so far: %d\n"),aReadBuf.Length());
  1.3374 +			User::WaitForRequest(status);
  1.3375 +			}
  1.3376 +		}
  1.3377 +	while(!aZlp);
  1.3378 +
  1.3379 +	epBuf.Close();
  1.3380 +	}
  1.3381 +
  1.3382 +TBool CompareBuffs(TDes8& aReadBuf, TDes8& aWriteBuf)
  1.3383 +	{
  1.3384 +	TInt wrLength = aWriteBuf.Length();
  1.3385 +	TInt rdLength = aReadBuf.Length();
  1.3386 +	if(wrLength != rdLength)
  1.3387 +		{
  1.3388 +		test.Printf(_L("Error: Disparity between length of data written and read back!"));
  1.3389 +		return EFalse;
  1.3390 +		}
  1.3391 +	for(TInt i=0; i < wrLength; i++)
  1.3392 +		{
  1.3393 +		if (aReadBuf[i] != aWriteBuf[i])
  1.3394 +			{
  1.3395 +			test.Printf(_L("Error: for i = %d:"), i);
  1.3396 +			test.Printf(_L("aReadBuf: %d != aWriteBuf: %d"),
  1.3397 +								aReadBuf[i], aWriteBuf[i]);
  1.3398 +			return EFalse;
  1.3399 +			}
  1.3400 +		}
  1.3401 +	return ETrue;
  1.3402 +	}
  1.3403 +
  1.3404 +
  1.3405 +/**
  1.3406 +Test Read/write using BIL api's
  1.3407 +-Sends data to PC application
  1.3408 +-Reads data back (the host side should send back the data which was read in the previous step)
  1.3409 +-Compare the data read to that written, verify they match.
  1.3410 +*/
  1.3411 +TBuf8<KMaxBufSize> iWriteBuf;
  1.3412 +TBuf8<KMaxBufSize> iReadBuf;
  1.3413 +void TestBILReadWrite()
  1.3414 +	{
  1.3415 +	TRequestStatus status;
  1.3416 +
  1.3417 +	test.Next(_L("TestBILReadWrite"));
  1.3418 +	test.Printf(_L("Open global USB channel"));
  1.3419 +	TInt r = gPort.Open(0);
  1.3420 +	test_KErrNone(r);
  1.3421 +	//Test for a simple interface with 2 endpoints
  1.3422 +	test.Printf(_L("Set up interface\n"));
  1.3423 +	SetupBulkInterfaces(0,1,1);
  1.3424 +	RChunk *tChunk = &gChunk;
  1.3425 +	test.Printf(_L("Finalize Interface\n"));
  1.3426 +	gPort.FinalizeInterface(tChunk);
  1.3427 +
  1.3428 +	if(gRealHardware)
  1.3429 +		{
  1.3430 +		test.Printf(_L("Please Start the USBIO demo application on the host side \n"));
  1.3431 +		gPort.ReEnumerate(status);
  1.3432 +		User::WaitForRequest(status);
  1.3433 +		test.Printf(_L("Enumerated. status = %d\n"), status.Int());
  1.3434 +		test.Printf(_L("The following test attempts to write data to the host application. USBIO demo application is used on the PC side.\
  1.3435 +						Using USBIO demo app, user should capture data to a file. When prompted, use USBIO application to send the recorded file back to device.\
  1.3436 +						The device side application will compare the data and show the result\n"));
  1.3437 +		test.Printf(_L("Test Write using BIL apis\n"));
  1.3438 +		BILWrite(iWriteBuf);
  1.3439 +	
  1.3440 +		test.Printf(_L("Test Read using BIL api's\n"));
  1.3441 +		BILRead(iReadBuf);
  1.3442 +
  1.3443 +		test.Printf(_L("Compare Read and Write buffers\n"));
  1.3444 +		TBool ret = CompareBuffs(iReadBuf, iWriteBuf);
  1.3445 +		if(!ret)
  1.3446 +			{
  1.3447 +			test.Printf(_L("!!warning- compare buffers found discrepancies!\n"));
  1.3448 +			}
  1.3449 +		}
  1.3450 +	gChunk.Close();
  1.3451 +	test.Printf(_L("Close global USB channel\n"));
  1.3452 +	gPort.Close();
  1.3453 +	}
  1.3454 +
  1.3455 +//At present, test only tests that multiple intefaces can be set up.
  1.3456 +void TestBILAlternateSettingChange()
  1.3457 +	{
  1.3458 +	TRequestStatus status;
  1.3459 +
  1.3460 +	test.Next(_L("BIL Alternate Setting Change"));
  1.3461 +	test.Printf(_L("Open global USB channel"));
  1.3462 +	TInt r = gPort.Open(0);
  1.3463 +	test_KErrNone(r);
  1.3464 +	//Test for a simple interface with 2 endpoints
  1.3465 +	test.Printf(_L("Set up interface 0\n"));
  1.3466 +	SetupBulkInterfaces(0,1,1);
  1.3467 +	test.Printf(_L("Set up interface 1\n"));
  1.3468 +	SetupBulkInterfaces(1,1,1);
  1.3469 +	RChunk *tChunk = &gChunk;
  1.3470 +	test.Printf(_L("Finalize Interface\n"));
  1.3471 +	gPort.FinalizeInterface(tChunk);
  1.3472 +
  1.3473 +	if(gRealHardware)
  1.3474 +		{
  1.3475 +		gPort.ReEnumerate(status);
  1.3476 +		User::WaitForRequest(status);
  1.3477 +		test.Printf(_L("Enumerated. status = %d\n"), status.Int());
  1.3478 +		}
  1.3479 +	gChunk.Close();
  1.3480 +	test.Printf(_L("Close global USB channel\n"));
  1.3481 +	gPort.Close();
  1.3482 +	}
  1.3483 +
  1.3484 +/**
  1.3485 +Test EP0 Read/write using BIL api's
  1.3486 +-Waits until a setup packet is received from host. Decodes the packet once it is received
  1.3487 +-If data is expected from host, read the data and print it out
  1.3488 +-If data is to be sent to host, write the data to host.
  1.3489 +-Manual verification that data is received correctly
  1.3490 +*/
  1.3491 +void TestBILEp0()
  1.3492 +	{
  1.3493 +	test.Next(_L("Endpoint Zero"));
  1.3494 +
  1.3495 +	TRequestStatus status;
  1.3496 +	TRequestStatus keyStatus;
  1.3497 +
  1.3498 +	test_KErrNone(gPort.Open(0));
  1.3499 +	//Test for a simple interface with 2 endpoints
  1.3500 +	SetupBulkInterfaces(0,1,1);
  1.3501 +	RChunk *tChunk = &gChunk;
  1.3502 +	test_KErrNone(gPort.FinalizeInterface(tChunk));
  1.3503 +
  1.3504 +	if(gRealHardware)
  1.3505 +		{
  1.3506 +		test.Printf(_L("With USBIO, open and configure the device, then send then and then recieve at lest 4 class/vendor requests to interface 0\n"));
  1.3507 +
  1.3508 +		TBool passed=EFalse;
  1.3509 +		TBool error=EFalse;
  1.3510 +		gPort.ReEnumerate(status);
  1.3511 +		User::WaitForRequest(status);
  1.3512 +		test_KErrNone(status.Int());
  1.3513 +		TEndpointBuffer epBuf;
  1.3514 +		const TUint KEp0Endpoint = 0;
  1.3515 +		//TRequestStatus status;
  1.3516 +		
  1.3517 +		//Open endpoint
  1.3518 +		test_KErrNone(gPort.OpenEndpoint(epBuf,KEp0Endpoint));
  1.3519 +		//call readdatanotify
  1.3520 +		
  1.3521 +		Sep0SetupPacket* setup;
  1.3522 +		TUint8 *readBuf;
  1.3523 +		TUint aSize;
  1.3524 +		TBool aZlp;	
  1.3525 +		aSize = 0;
  1.3526 +		aZlp = EFalse;
  1.3527 +		TInt ret = KErrGeneral;
  1.3528 +		TInt phase=0;
  1.3529 +		keyStatus=KErrNone;
  1.3530 +
  1.3531 +		TUint dataLength=0;
  1.3532 +		TBool reqNeeded=ETrue;
  1.3533 +
  1.3534 +		TInt goodReads=0;
  1.3535 +		TInt goodWrites=0;
  1.3536 +		TInt goodStateChange=0;
  1.3537 +
  1.3538 +		while (ETrue)
  1.3539 +			{
  1.3540 +			if (keyStatus.Int()!=KRequestPending)
  1.3541 +				{
  1.3542 +				if (test.Console()->KeyCode() == EKeyEscape)
  1.3543 +					break;
  1.3544 +				else
  1.3545 +					test.Printf(_L("Press escape to end EP0 testing\n"));	
  1.3546 +
  1.3547 +				test.Console()->Read(keyStatus);
  1.3548 +				}
  1.3549 +
  1.3550 +			if (reqNeeded)
  1.3551 +				{
  1.3552 +				ret = epBuf.GetBuffer((TAny*&)readBuf,aSize,aZlp,status);
  1.3553 +				if(gVerbose)
  1.3554 +					test.Printf(_L("Getbuffer returned %d, aSize: %d, aZlp: %d\n"),ret, aSize,aZlp);
  1.3555 +				}
  1.3556 +
  1.3557 +			if (ret==KErrNone)
  1.3558 +				{
  1.3559 +				User::WaitForRequest(status, keyStatus);
  1.3560 +				TInt r = status.Int();
  1.3561 +				test_Value(r, (r==KErrNone) || (r==KRequestPending));
  1.3562 +				if (r!=KRequestPending)  // Dealing with keys in the same loop, does confuse things.
  1.3563 +					ret=KErrCompletion;
  1.3564 +				}
  1.3565 +			else if (ret==TEndpointBuffer::KStateChange)
  1.3566 +				{
  1.3567 +				TInt state = *((TInt*) readBuf);
  1.3568 +				test.Printf(_L("Status Change:! %d : %S \n"),state,((state<0) || (state>7))?KStates[8]:KStates[state]);
  1.3569 +				test_Equal(aSize, 4);
  1.3570 +				goodStateChange++;
  1.3571 +				}
  1.3572 +			else
  1.3573 +				{
  1.3574 +				test_Equal(ret, KErrCompletion);
  1.3575 +				reqNeeded = ETrue;
  1.3576 +				if (phase==0) //Header
  1.3577 +					{
  1.3578 +					if (aSize!=8)
  1.3579 +						{
  1.3580 +						test.Printf(_L("Error: Malformed control packet of size %d.\n"),aSize);
  1.3581 +						error = ETrue;
  1.3582 +						}
  1.3583 +					else
  1.3584 +						{
  1.3585 +						setup = (Sep0SetupPacket* ) readBuf;
  1.3586 +						PrintSetupPkt(setup);
  1.3587 +					
  1.3588 +						if (setup->iRequestType&KDeviceToHost)
  1.3589 +							{
  1.3590 +							// Send data
  1.3591 +							test.Printf(_L("Sending %d bytes of data value increasing from 0x0 in 1 step. Verify data is received at the host\n"),setup->iWlength);
  1.3592 +							TUint8 *ep0Buffer; // = (TUint8 *)epBuf.Ep0In()BufferStart;
  1.3593 +							TUint ep0Length;
  1.3594 +							epBuf.GetInBufferRange(((TAny*&)ep0Buffer),ep0Length);
  1.3595 +							TUint8 *ep0Data = ep0Buffer;
  1.3596 +							for(TUint8 i=0;i< setup->iWlength;i++)
  1.3597 +								{
  1.3598 +								*(ep0Data++) = i;
  1.3599 +								}
  1.3600 +							test_KErrNone(epBuf.WriteBuffer(ep0Buffer,setup->iWlength,ETrue,status));
  1.3601 +							User::WaitForRequest(status);
  1.3602 +							test_KErrNone(status.Int());
  1.3603 +							goodWrites++;
  1.3604 +							}
  1.3605 +						else
  1.3606 +							{
  1.3607 +							dataLength = setup->iWlength;
  1.3608 +							if (dataLength)
  1.3609 +								{
  1.3610 +								phase=1;
  1.3611 +								iReadBuf.Zero();
  1.3612 +								}
  1.3613 +							else
  1.3614 +								{
  1.3615 +								gPort.SendEp0StatusPacket();
  1.3616 +								test.Printf(_L("No Data.\n"));
  1.3617 +								}
  1.3618 +							} // end HostToDevice type
  1.3619 +						} //packet Correct length
  1.3620 +					}
  1.3621 +				else  // DataPhase
  1.3622 +					{
  1.3623 +					dataLength -= aSize;
  1.3624 +					iReadBuf.Append(&readBuf[0],aSize);
  1.3625 +					if (!dataLength)
  1.3626 +						phase=0;
  1.3627 +
  1.3628 +					if (aZlp && dataLength)
  1.3629 +						{
  1.3630 +						test.Printf(_L("\nError: ZLP received before enough data is read out!\nFailing Test!\n"));
  1.3631 +						error=ETrue;
  1.3632 +						phase=0;
  1.3633 +						}
  1.3634 +
  1.3635 +					if (!phase)
  1.3636 +						{
  1.3637 +						gPort.SendEp0StatusPacket();
  1.3638 +						//Print read out values
  1.3639 +						test.Printf(_L("Data Read:"));
  1.3640 +						for(TInt i=0; i < iReadBuf.Length(); i++)
  1.3641 +							{
  1.3642 +							test.Printf(_L("0x%x "),iReadBuf[i]);
  1.3643 +							}
  1.3644 +						test.Printf(_L("\n"));
  1.3645 +						goodReads++;
  1.3646 +						}
  1.3647 +
  1.3648 +					} // end DataPhase
  1.3649 +				}
  1.3650 +			
  1.3651 +			} // end while
  1.3652 +		epBuf.Close();
  1.3653 +
  1.3654 +		if ((goodWrites>3) && (goodReads>3) && (goodStateChange>6))
  1.3655 +			passed=ETrue;
  1.3656 +
  1.3657 +		if ((!passed) || (error))
  1.3658 +			{
  1.3659 +			if (!error)
  1.3660 +				test.Printf(_L("\nInsifishant reads/writes where seen to work, to pass test.\n"));
  1.3661 +								
  1.3662 +			test.Printf(_L("\n ***************\n"));
  1.3663 +			test.Printf(_L(" * FAILED TEST *\n"));
  1.3664 +			test.Printf(_L(" ***************\n\nKey to Continue."));
  1.3665 +			}
  1.3666 +		else
  1.3667 +			{
  1.3668 +			test.Printf(_L("\nIf the USBIO demo application responded as expected, then this can be called a passed test.\n\nKey to Continue.\n"));		
  1.3669 +			}
  1.3670 +
  1.3671 +		//Note- A disturbing fact! If host aborts data transmission and send a new setup packet, the userside is clueless as to what it's reading is
  1.3672 +		//		data/setup data.  
  1.3673 +			test.Getch();
  1.3674 +		} // end if-real-hardware
  1.3675 +	gChunk.Close();
  1.3676 +	test.Printf(_L("Close global USB channel\n"));
  1.3677 +	gPort.Close();
  1.3678 +	} // end funcion
  1.3679 +
  1.3680 +
  1.3681 +
  1.3682 +void TestBIL()
  1.3683 +	{
  1.3684 +	TInt r;
  1.3685 +	test.Start(_L("BIL unit tests"));
  1.3686 +	test.Next(_L("Load driver"));	
  1.3687 +	r = User::LoadLogicalDevice(KLddName);
  1.3688 +	test_Value(r, r == KErrNone || r == KErrAlreadyExists);  
  1.3689 +/* ----------------------------------------------------------------------------
  1.3690 +@SYMTestCaseID		PBASE-USB-SC-1225
  1.3691 +@SYMTestCaseDesc	BIL Testing: Functionality tests
  1.3692 +@SYMPREQ			PREQ1846
  1.3693 +@SYMTestPriority	
  1.3694 +@SYMTestActions
  1.3695 +	The test has 3 components- write content to USBIO demo application, read back the contents written and compare the written and read data to do data validation.
  1.3696 +	The test attempts to do 3 types of write
  1.3697 +		1)  A full buffer write- Buffer is filled with data and written to host. The user should initiate the host side application to accept the incoming data and write it to a file.  
  1.3698 +		2)  A double buffer write- Data equivalent to twice the buffer size is written to host side. The test waits until 1 full buffer of data is written out, and then writes another full buffer of data. 
  1.3699 +			The user should initiate the host side application to accept the incoming data and write to a file 
  1.3700 +		3)  A split buffer write- A full buffer of data is split into two portions and written to the buffer in quick succession. 
  1.3701 +			The test waits for the status of both write operations after queuing the writes.
  1.3702 +	In each of the above cases, the sent data is written to a file by the USBIO demo application. User then sends back the file written to the device. 
  1.3703 +	The test application reads in the file sent by the host application and compares it to written data which was saved during the write stage. 
  1.3704 +	If the read data is same as written data, test succeeds. 
  1.3705 +@SYMTestExpectedResults
  1.3706 +	The test should read the same data as was sent. It should be able to handle all the 3 types of writes.
  1.3707 +*/
  1.3708 +	if ((gSpecTest==EBilRw) || (gSpecTest==EAll))
  1.3709 +		TestBILReadWrite();
  1.3710 +/* ----------------------------------------------------------------------------
  1.3711 +@SYMTestCaseID		PBASE-USB-SC-1226
  1.3712 +@SYMTestCaseDesc	BIL testing: EP0 Read/write
  1.3713 +@SYMPREQ			PREQ1846
  1.3714 +@SYMTestPriority	
  1.3715 +@SYMTestActions
  1.3716 +	The USBIO host application can be used to send a class/vendor request on EP0. 
  1.3717 +	The test application should wait for an EP0 setup packet. Once a setup packet is received, the test application decodes the contents of the setup packet. 
  1.3718 +	If there is data to be received from host, BIL read routines should read the data in and send a status packet back to the host. 
  1.3719 +	If data is to be sent back to the host, ensure that data is received correctly at host
  1.3720 +@SYMTestExpectedResults
  1.3721 +	Ensure setup packet is received correctly and data is received at host/device end correctly
  1.3722 +*/
  1.3723 +	if ((gSpecTest==EBilEp0) || (gSpecTest==EAll))
  1.3724 +		TestBILEp0();
  1.3725 +
  1.3726 +	if ((gSpecTest==EBilAlt) || (gSpecTest==EAll))
  1.3727 +		TestBILAlternateSettingChange();
  1.3728 +
  1.3729 +	test.Next(_L("Unload driver"));
  1.3730 +	r = User::FreeLogicalDevice(KUsbDeviceName);
  1.3731 +	test_Value(r,(r==KErrNone) || (r==KErrInUse));
  1.3732 +	test.End();
  1.3733 +	}
  1.3734 +
  1.3735 +/* Where the testing starts */
  1.3736 +void StartTests(void)
  1.3737 +	{
  1.3738 +	switch (gSpecTest)
  1.3739 +	{
  1.3740 +/* ----------------------------------------------------------------------------
  1.3741 +@SYMTestCaseID		PBASE-USB-SC-1218
  1.3742 +@SYMTestCaseDesc	Buffer Handling: Reads
  1.3743 +@SYMPREQ			PREQ1846
  1.3744 +@SYMTestPriority	
  1.3745 +@SYMTestActions
  1.3746 +	1.	Queue read on OUT endpoint i.e. Call ReadDataNotify API.
  1.3747 +		Each time the transfer header is checked for the following
  1.3748 +		a) Tail pointer of previous transfer not the same as the current Tail pointer
  1.3749 +		b) Sequence Number of every transfer is always one more than previous
  1.3750 +		c) First transfer offset greater than start offset of buffer header. Transfer Offset when it wraps around to the beginning of the buffer is also greater than start offset of buffer header.
  1.3751 +		d) Data does not overlap chunk offset of the next transfer to be extracted
  1.3752 +		e) No data or metadata goes beyond the end address of the buffer
  1.3753 +		f) Data is aligned to MaxPacketSize of the endpoint
  1.3754 +@SYMTestExpectedResults
  1.3755 +	1.	If data is present API returns immediately with KErrCompletion else KErrNone. If data ready, user side walks the chunk. 
  1.3756 +		Queues another read till no data present when the API will return KErrNone. 
  1.3757 +*/
  1.3758 +	case EBufRead:	// Test Reading from an endpoint
  1.3759 +		{
  1.3760 +		test.Start(_L("PBASE-USB-SC-1218 Reading from an endpoint. On host side, select an OUT endpoint and send data from a file\n"));
  1.3761 +		TestBufferHandling();
  1.3762 +		test.End();
  1.3763 +		break;
  1.3764 +		}
  1.3765 +/* ----------------------------------------------------------------------------
  1.3766 +@SYMTestCaseID		PBASE-USB-SC-1219
  1.3767 +@SYMTestCaseDesc	Buffer Handling: Writes
  1.3768 +@SYMPREQ			PREQ1846
  1.3769 +@SYMTestPriority	
  1.3770 +@SYMTestActions
  1.3771 +	1.	Queue Write on an IN endpoint i.e. Call WriteData API. The buffer offset is checked to see if it is aligned to MaxPacketSize of endpoint.
  1.3772 +@SYMTestExpectedResults
  1.3773 +	1.	Chunk is populated with correct number of buffers and alternate settings with correct number and type of endpoints.
  1.3774 +*/
  1.3775 +	case EBufWrite: // Test Writing to an endpoint
  1.3776 +		{
  1.3777 +		test.Start(_L("PBASE-USB-SC-1219 Writing to an endpoint. On host side, select an IN endpoint and write to a file\n"));
  1.3778 +		TestBufferHandling();
  1.3779 +		test.End();
  1.3780 +		break;
  1.3781 +		}
  1.3782 +/* ----------------------------------------------------------------------------
  1.3783 +@SYMTestCaseID		PBASE-USB-SC-1220
  1.3784 +@SYMTestCaseDesc	Endpoint 0: Read, Write and Status Changes
  1.3785 +@SYMPREQ			PREQ1846
  1.3786 +@SYMTestPriority	
  1.3787 +@SYMTestActions
  1.3788 +	1.	If the setup packet contains a command to send data from Host to Device, Queue read on EP0 endpoint i.e. Call ReadDataNotify API.
  1.3789 +		Each time the transfer header is checked for the following
  1.3790 +			a) Tail pointer of previous transfer not the same as the current Tail pointer
  1.3791 +			b) Sequence Number of every transfer is always one more than previous
  1.3792 +			c) First transfer offset greater than start offset of buffer header. Transfer Offset when it wraps around to the beginning of the buffer is also greater than start offset of buffer header.
  1.3793 +			d) Data does not overlap chunk offset of the next transfer to be extracted
  1.3794 +			e) No data or metadata goes beyond the end address of the buffer
  1.3795 +			f) Test for successful reading of odd number of bytes as data.
  1.3796 +	2.	If the setup packet contains a command to send data from device to host, Queue Write on an EP0 endpoint i.e. Call WriteData API.
  1.3797 +	3.	On unplugging and plugging back the USB cable, check that state change packets can be sent to user side.
  1.3798 +@SYMTestExpectedResults
  1.3799 +	1.	If data is present API returns immediately with KErrCompletion else KErrNone. If data ready, user side walks the chunk. Queues another read till no data present when the API will return KErrNone. 
  1.3800 +	2.	Data is successfully written out of the buffer
  1.3801 +	3.	State change packets corresponding to the event that caused it are seen on user side
  1.3802 +
  1.3803 +*/
  1.3804 +	case EEp0: // Test Ep0
  1.3805 +		{
  1.3806 +		test.Start(_L("PBASE-USB-SC-1220 Reading from and Writing to EP0. On host side, send a Vendor Request to interface from Host to Device or Device to Host\n"));
  1.3807 +		TestBufferHandling();
  1.3808 +		test.End();
  1.3809 +		break;
  1.3810 +		}
  1.3811 +/* ----------------------------------------------------------------------------
  1.3812 +@SYMTestCaseID		PBASE-USB-SC-1221
  1.3813 +@SYMTestCaseDesc	Alternate Setting Changes
  1.3814 +@SYMPREQ			PREQ1846
  1.3815 +@SYMTestPriority	
  1.3816 +@SYMTestActions
  1.3817 +	1.	Set up an interface with 2 or more alternate settings. Read/Write from the default setting (0). Switch to another alternate setting. Read/Write from the new alternate setting (1/2/3). Switch back to the default setting. Read/Write from the default setting (0).
  1.3818 +		Each time alternate setting is changed, ensure that for every OUT endpoint
  1.3819 +		a) The transfer header's alternate setting member contains the current alternate setting
  1.3820 +		b) The transfer header's alternate setting change sequence member in incremented
  1.3821 +		c) An empty transfer header containing the new alternate setting and alternate setting change sequence numbers.
  1.3822 +		d) EP0 OUT endpoint gets an empty transfer header containing the new alternate setting and alternate setting change sequence numbers.
  1.3823 +@SYMTestExpectedResults
  1.3824 +	1.	On Alternate setting change, all buffers corresponding to the OUT endpoints and EP0 OUT buffer receive a transfer with the new alternate setting number, new alternate setting change sequence number.
  1.3825 +		The device is able to read and write though the endpoints corresponding to the new alternate setting.
  1.3826 +*/
  1.3827 +	case EAltSet: // AlternateSetting
  1.3828 +		{
  1.3829 +		test.Start(_L("PBASE-USB-SC-1221 Alternate Setting Change \n"));
  1.3830 +		TestBufferHandling();
  1.3831 +		test.End();
  1.3832 +		break;
  1.3833 +		}
  1.3834 +/* ----------------------------------------------------------------------------
  1.3835 +@SYMTestCaseID		PBASE-USB-SC-1217
  1.3836 +@SYMTestCaseDesc	Buffer Construction
  1.3837 +@SYMPREQ			PREQ1846
  1.3838 +@SYMTestPriority	
  1.3839 +@SYMTestActions
  1.3840 +	1.	Set up different number of interfaces. Check if chunk is populated correctly for various setting configurations set using SetInterface and RealizeInterface API
  1.3841 +	2.	Positive and Negative tests using Release Interface
  1.3842 +@SYMTestExpectedResults
  1.3843 +	1.	Chunk is populated with correct number of buffers and alternate settings with correct number and type of endpoints.
  1.3844 +	2.	Destructors clean up 
  1.3845 +*/
  1.3846 +	case EInterface:
  1.3847 +		{
  1.3848 +		test.Start(_L("PBASE-USB-SC-1217 SetInterface Test\n"));
  1.3849 +		TestSetInterface();
  1.3850 +		test.End();
  1.3851 +		break;
  1.3852 +		}
  1.3853 +/* ----------------------------------------------------------------------------
  1.3854 +@SYMTestCaseID		PBASE-USB-SC-1222
  1.3855 +@SYMTestCaseDesc	Cancel Notifications
  1.3856 +@SYMPREQ			PREQ1846
  1.3857 +@SYMTestPriority	
  1.3858 +@SYMTestActions
  1.3859 +	Before Enumeration (negative tests)
  1.3860 +		1.	Queue a notification for read. 
  1.3861 +		2.	Queue  ReadCancel
  1.3862 +		3.	Queue  WriteData
  1.3863 +		4.	Queue WriteCancel
  1.3864 +	After Enumeration (Positive Tests)
  1.3865 +		5.	Queue a read notification and drain out the buffer of any data. Cancel the read.
  1.3866 +		6.	Queue WriteData and cancel it with WriteCancel
  1.3867 +@SYMTestExpectedResults
  1.3868 +		1.	Notification should immediately return with KErrNone as device is not configured
  1.3869 +		2.	API should almost immediately return with status as KErrCancel, panic otherwise
  1.3870 +		3.	API should immediately return with KErrNone as device is not configured
  1.3871 +		4.	API should almost immediately return with status as KErrCancel, panic otherwise
  1.3872 +		5.	API should almost immediately return with status as KErrCancel, panic otherwise
  1.3873 +		6.	Cancelling the request should return with KErrCancel, panic otherwise
  1.3874 +*/
  1.3875 +	case ECancel:
  1.3876 +		{
  1.3877 +		test.Start(_L("PBASE-USB-SC-1222 Cancel Notifications Test \n"));
  1.3878 +		TestCancel();
  1.3879 +		test.End();
  1.3880 +		break;
  1.3881 +		}
  1.3882 +/* ----------------------------------------------------------------------------
  1.3883 +@SYMTestCaseID		PBASE-USB-SC-1223
  1.3884 +@SYMTestCaseDesc	Invalid API Tests
  1.3885 +@SYMPREQ			PREQ1846
  1.3886 +@SYMTestPriority	
  1.3887 +@SYMTestActions
  1.3888 +	1.	Call ReadDataNotify with invalid buffer numbers
  1.3889 +		a.	Buffer does not exist.
  1.3890 +		b.	Negative buffer Number
  1.3891 +		c.	Buffer number corresponding to an IN endpoint
  1.3892 +	2.	Test API with invalid parameters
  1.3893 +		a.	Pass invalid buffer numbers to WriteData. Negative buffer numbers, buffer does not exist, buffer corresponding to an OUT endpoint.
  1.3894 +		b.	Pass invalid buffer offsets to WriteData i.e. unaligned offset or an offset beyond end of buffer. 
  1.3895 +		c.	Pass invalid lenghts to WriteData i.e. length greater than the maximum size of buffer.
  1.3896 +@SYMTestExpectedResults
  1.3897 +	1.	a.	API returns with KErrArgument.
  1.3898 +		b.	API returns with KErrArgument.
  1.3899 +		c.	API returns with KErrNotSupported.
  1.3900 +	2.	a.	Return with KErrArgument each case
  1.3901 +		b.	Return with KErrArgument each case
  1.3902 +		c.	Return with KErrArgument
  1.3903 +*/
  1.3904 +	case EInvalidApi:
  1.3905 +		{
  1.3906 +		test.Start(_L("PBASE-USB-SC-1223 Invalid Api Tests \n"));
  1.3907 +		TestInvalidAPI();
  1.3908 +		test.End();
  1.3909 +		break;
  1.3910 +		}
  1.3911 +/* ----------------------------------------------------------------------------
  1.3912 +@SYMTestCaseID		PBASE-USB-SC-1224
  1.3913 +@SYMTestCaseDesc	Descriptor Tests
  1.3914 +@SYMPREQ			PREQ1846
  1.3915 +@SYMTestPriority	
  1.3916 +@SYMTestActions
  1.3917 +	1.	Test descriptor manipulation: validate the device, deviceQualifier, configuration, interface, endpoint, class specific, alternate interface, endpoint and string descriptor manipulation.
  1.3918 +	2.	Test HaltEndpoint and ClearHaltEndpoint correctly result in endpoint status being reported as stalled/not stalled.
  1.3919 +@SYMTestExpectedResults
  1.3920 +	1.	All entries should match.
  1.3921 +	2.	All entries should match.
  1.3922 +*/
  1.3923 +	case EDescriptor:
  1.3924 +		{
  1.3925 +		test.Start(_L("PBASE-USB-SC-1224 Descriptor Tests \n"));
  1.3926 +		TestDescriptorManipulation();
  1.3927 +		test.End();
  1.3928 +		break;
  1.3929 +		}
  1.3930 +	default:
  1.3931 +		if (gSpecTest>=EBilRw)
  1.3932 +			TestBIL();
  1.3933 +		else
  1.3934 +			test.Printf(_L("No such option \n"));
  1.3935 +	}
  1.3936 +
  1.3937 +
  1.3938 +	}
  1.3939 +
  1.3940 +void ProcessCommandLineOptions(void)
  1.3941 +	{
  1.3942 +	//ToDo: to put back in
  1.3943 +	// Open Driver and Check Device Capabilities - PowerUpUDC NOT Working 
  1.3944 +	LoadDriver();
  1.3945 +	OpenChannel();
  1.3946 +	CheckDeviceCapabilities();
  1.3947 +	test_KErrNone(SettingOne(0));
  1.3948 +	TInt r;
  1.3949 +	r = gPort.RealizeInterface(gChunk);
  1.3950 +	test_KErrNone(r);
  1.3951 +
  1.3952 +	TInt ifc_no = -1;
  1.3953 +	r = gPort.GetAlternateSetting(ifc_no);
  1.3954 +	test_Equal(KErrUsbDeviceNotConfigured, r);	
  1.3955 +
  1.3956 +	// Check for OTG support as if OTG is supported, client stack is disabled
  1.3957 +	TBuf8<KUsbDescSize_Otg> otg_desc;
  1.3958 +	r = gPort.GetOtgDescriptor(otg_desc);
  1.3959 +	test(r == KErrNotSupported || r == KErrNone);
  1.3960 +	TInt supportsOtg = (r != KErrNotSupported) ? ETrue : EFalse;
  1.3961 +
  1.3962 +	// We turn on UDC here explicitly. This is done only once and just to test the API as such
  1.3963 +	test.Next(_L("Powering up UDC"));
  1.3964 +	r = gPort.PowerUpUdc();
  1.3965 +
  1.3966 +	if (!supportsOtg)
  1.3967 +		{
  1.3968 +		test_KErrNone(r);
  1.3969 +		}
  1.3970 +	else
  1.3971 +		{
  1.3972 +		test((r == KErrNone) || (r == KErrNotReady));
  1.3973 +		}
  1.3974 +
  1.3975 +	CloseChannel();
  1.3976 +	UnloadDriver();
  1.3977 +	if (gSpecTest == EAll)
  1.3978 +		{
  1.3979 +		for (TInt i = 1; i <= 7; i++)
  1.3980 +			{
  1.3981 +			gSpecTest = (TSpecTestType) i;
  1.3982 +			StartTests();
  1.3983 +			}
  1.3984 +		for (TInt i = 100; i <= 102; i++)
  1.3985 +			{
  1.3986 +			gSpecTest = (TSpecTestType) i;
  1.3987 +			StartTests();
  1.3988 +			}
  1.3989 +
  1.3990 +		}
  1.3991 +	else
  1.3992 +		{
  1.3993 +		StartTests();
  1.3994 +		}
  1.3995 +	}
  1.3996 +
  1.3997 + 
  1.3998 +
  1.3999 +// -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  1.4000 +
  1.4001 +//
  1.4002 +// ParseCommandLine reads the arguments and sets globals accordingly.
  1.4003 +//
  1.4004 +
  1.4005 +TInt ParseCommandLine()
  1.4006 +	{
  1.4007 +	TBuf<32> args;
  1.4008 +	User::CommandLine(args);
  1.4009 +	TLex lex(args);
  1.4010 +	TInt err=KErrNone;
  1.4011 +	FOREVER
  1.4012 +		{
  1.4013 +		TPtrC token=lex.NextToken();
  1.4014 +		TPtrC subtoken(_L(""));
  1.4015 +
  1.4016 +		if(token.Length()!=0)
  1.4017 +			{
  1.4018 +			if ((token==_L("help")) || (token==_L("-h")) || (token==_L("/h")) || (token==_L("-?")) || (token==_L("/?")))
  1.4019 +				{
  1.4020 +				test.Printf(_L("\nThis tests the Shared chunk version of the USBC driver.  It focuses on the elements specific to this driver and should be used in conjuntion with other USBC tests in order to validate the driver.\n\n"));
  1.4021 +				test.Printf(_L("\n -h : Help.\n -r : test on Real hardware\n -v : Verbose\n -V : Very verbose\n-t <test> : Run a specific test.\n"));   
  1.4022 +				test.Printf(_L("\nAvailable tests:  buf_read, buf_write, ep0, altset, interface, cancel, api, descriptor, bil_rw, bil_ep0, bil_alt\n"));
  1.4023 +				err=KErrCancel;
  1.4024 +				}
  1.4025 +			else
  1.4026 +				if (token==_L("-r"))
  1.4027 +					gRealHardware = ETrue;
  1.4028 +			else
  1.4029 +				if (token==_L("-v"))
  1.4030 +					gVerbose = 1;
  1.4031 +			else
  1.4032 +				if (token==_L("-V"))
  1.4033 +					gVerbose = 2;
  1.4034 +			else
  1.4035 +				if (token==_L("-t"))
  1.4036 +					{
  1.4037 +					subtoken.Set(lex.NextToken());
  1.4038 +
  1.4039 +					if(subtoken.Length()!=0)
  1.4040 +						{
  1.4041 +						if (subtoken==_L("buf_read"))
  1.4042 +								{
  1.4043 +								gSpecTest=EBufRead;
  1.4044 +								gRealHardware = ETrue;
  1.4045 +								}
  1.4046 +						else if (subtoken==_L("buf_write"))
  1.4047 +								{
  1.4048 +								gSpecTest=EBufWrite;
  1.4049 +								gRealHardware = ETrue;
  1.4050 +								}
  1.4051 +						else if (subtoken==_L("ep0"))
  1.4052 +								{
  1.4053 +								gSpecTest=EEp0;
  1.4054 +								gRealHardware = ETrue;
  1.4055 +								}
  1.4056 +						else if (subtoken==_L("descriptor"))
  1.4057 +								gSpecTest=EDescriptor;
  1.4058 +						else if (subtoken==_L("interface"))
  1.4059 +								gSpecTest=EInterface;
  1.4060 +						else if (subtoken==_L("cancel"))
  1.4061 +								gSpecTest=ECancel;
  1.4062 +						else if (subtoken==_L("api"))
  1.4063 +								gSpecTest=EInvalidApi;
  1.4064 +						else if (subtoken==_L("bil_rw"))
  1.4065 +								{
  1.4066 +								gSpecTest=EBilRw;
  1.4067 +								gRealHardware = ETrue;
  1.4068 +								}
  1.4069 +						else if (subtoken==_L("bil_ep0"))
  1.4070 +								{
  1.4071 +								gSpecTest=EBilEp0;
  1.4072 +								gRealHardware = ETrue;
  1.4073 +								}
  1.4074 +						else if (subtoken==_L("bil_alt"))
  1.4075 +								{
  1.4076 +								gSpecTest=EBilAlt;
  1.4077 +								gRealHardware = ETrue;
  1.4078 +								}
  1.4079 +						else if (subtoken==_L("altset"))
  1.4080 +								{
  1.4081 +								gRealHardware = ETrue;
  1.4082 +								gSpecTest=EAltSet;
  1.4083 +								}
  1.4084 +						else
  1.4085 +							{
  1.4086 +							err=KErrArgument;
  1.4087 +							}
  1.4088 +
  1.4089 +						}
  1.4090 +					else
  1.4091 +						{
  1.4092 +						subtoken.Set(_L("<NOTHING>"));
  1.4093 +						err = KErrArgument;
  1.4094 +						}
  1.4095 +					} // endif -t
  1.4096 +			else
  1.4097 +				{
  1.4098 +				err = KErrArgument;
  1.4099 +				} // endif token 
  1.4100 +			}
  1.4101 +		else
  1.4102 +			break;
  1.4103 +		
  1.4104 +		if (err!=KErrNone)
  1.4105 +			{
  1.4106 +			if (err==KErrArgument)
  1.4107 +				test.Printf(_L("\nUnknown argument '%S%s%S'\n"), &token, (subtoken.Length()==0)?"":" ", &subtoken);
  1.4108 +			test.Printf(_L("\nUsage:  t_usbcsc [-hrvVt]\n\n"));
  1.4109 +			test.Getch();
  1.4110 +			return err;
  1.4111 +			}
  1.4112 +		}
  1.4113 +	return KErrNone;
  1.4114 +	}
  1.4115 +
  1.4116 +GLDEF_C TInt E32Main()
  1.4117 +	{
  1.4118 +	test.Title();
  1.4119 +	__UHEAP_MARK;
  1.4120 +	if (ParseCommandLine())
  1.4121 +		return KErrNone;
  1.4122 +	
  1.4123 +	test.Start(_L("USB client 'Shared Chunk' driver Tests"));
  1.4124 +
  1.4125 +	TInt muid = 0;
  1.4126 +	TInt r = HAL::Get(HAL::EMachineUid, muid);
  1.4127 +	if (r != KErrNone)
  1.4128 +		{
  1.4129 +		test.Printf(_L("Unable to get Platform ID. Skipping tests\n"));
  1.4130 +		return KErrNone;
  1.4131 +		}
  1.4132 +	if (SupportsUsb() && (muid != HAL::EMachineUid_Lubbock))
  1.4133 +		{
  1.4134 +		ProcessCommandLineOptions();
  1.4135 +		}
  1.4136 +	else
  1.4137 +		{
  1.4138 +		test.Printf(_L("USB is not supported on this platform.  Skipping test\n"));
  1.4139 +		}
  1.4140 +	
  1.4141 +   	test.End();
  1.4142 +	__UHEAP_MARKEND;
  1.4143 +
  1.4144 +	return KErrNone;  
  1.4145 +	}
  1.4146 +