1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usb/t_usb_device/src/activecontrol.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1648 @@
1.4 +// Copyright (c) 2000-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/usb/t_usb_device/src/activecontrol.cpp
1.18 +// USB Test Program T_USB_DEVICE, functional part.
1.19 +// Device-side part, to work against T_USB_HOST running on the host.
1.20 +//
1.21 +//
1.22 +
1.23 +
1.24 +#include "general.h"
1.25 +#include "usblib.h" // Helpers
1.26 +#include "config.h"
1.27 +#include "activecontrol.h"
1.28 +#include "apitests.h"
1.29 +#include "activerw.h"
1.30 +
1.31 +void StartMassStorage(RDEVCLIENT* aPort);
1.32 +void StopMassStorage(RDEVCLIENT* aPort);
1.33 +
1.34 +enum Ep0Requests
1.35 + {
1.36 + EStop = 0x1,
1.37 + EVersion = 0x10,
1.38 + ETestParam = 0x20,
1.39 + ETestResult = 0x30,
1.40 + ETestFail = 0x40,
1.41 + ETestConnect = 0x50,
1.42 + ETestDisconnect = 0x60,
1.43 + ETestMassStorage = 0x70,
1.44 + ETestIdleCounter = 0x80,
1.45 + };
1.46 +
1.47 +extern RTest test;
1.48 +extern TBool gVerbose;
1.49 +extern TBool gSkip;
1.50 +extern TBool gTempTest;
1.51 +extern TBool gStopOnFail;
1.52 +extern TBool gAltSettingOnNotify;
1.53 +extern TInt gSoakCount;
1.54 +extern CActiveRW* gRW[KMaxConcurrentTests]; // the USB read/write active object
1.55 +extern IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings];
1.56 +extern TInt gActiveTestCount;
1.57 +#ifdef USB_SC
1.58 +extern RChunk gChunk;
1.59 +#endif
1.60 +
1.61 +TInt firstBulkOutEndpoint = -1;
1.62 +
1.63 +_LIT(KTestIdleCounterChunkName, "TestIdleCounter");
1.64 +_LIT(KTestIdleCounterPanic, "IdleCounter");
1.65 +
1.66 +enum TTestIdleCounterPanic
1.67 + {
1.68 + ETestIdleCounterWrongCommand
1.69 + };
1.70 +
1.71 +enum TTestIdleCounterCommand
1.72 + {
1.73 + ETestIdleCounterDoNothing,
1.74 + ETestIdleCounterReset,
1.75 + ETestIdleCounterClose
1.76 + };
1.77 +
1.78 +struct TTestIdleCounter
1.79 + {
1.80 + volatile TInt64 iCounter;
1.81 + volatile TTestIdleCounterCommand iCommand;
1.82 + };
1.83 +
1.84 +TInt IdleCounterThread(TAny*)
1.85 + {
1.86 + TInt r;
1.87 + //
1.88 + RThread().SetPriority(EPriorityAbsoluteVeryLow);
1.89 + //
1.90 + RChunk chunk;
1.91 + r = chunk.CreateGlobal(KTestIdleCounterChunkName,
1.92 + sizeof(struct TTestIdleCounter),
1.93 + sizeof(struct TTestIdleCounter) + 1);
1.94 + if (r == KErrNone)
1.95 + {
1.96 + struct TTestIdleCounter* counter = (struct TTestIdleCounter*) chunk.Base();
1.97 + counter->iCounter = 0;
1.98 + counter->iCommand = ETestIdleCounterDoNothing;
1.99 + //
1.100 + FOREVER
1.101 + {
1.102 + TInt command = counter->iCommand;
1.103 + if (command == ETestIdleCounterReset)
1.104 + {
1.105 + counter->iCounter = 0;
1.106 + counter->iCommand = ETestIdleCounterDoNothing;
1.107 + }
1.108 + else if (command == ETestIdleCounterClose)
1.109 + {
1.110 + break;
1.111 + }
1.112 + else if (command != ETestIdleCounterDoNothing)
1.113 + {
1.114 + RThread().Panic(KTestIdleCounterPanic, ETestIdleCounterWrongCommand);
1.115 + }
1.116 + //
1.117 + counter->iCounter++;
1.118 + }
1.119 + //
1.120 + chunk.Close();
1.121 + }
1.122 + return r;
1.123 + }
1.124 +
1.125 +//
1.126 +// --- class CActiveControl ---------------------------------------------------------
1.127 +//
1.128 +
1.129 +CActiveControl::CActiveControl(CConsoleBase* aConsole, TDes * aConfigFile, TDes * aScriptFile)
1.130 + : CActive(EPriorityNormal),
1.131 + iConsole(aConsole),
1.132 + iSoftwareConnect(EFalse),
1.133 + iHighSpeed(EFalse),
1.134 + iConfigFileName(aConfigFile),
1.135 + iScriptFileName(aScriptFile),
1.136 + iEp0PacketSize(0)
1.137 + {}
1.138 +
1.139 +
1.140 +CActiveControl* CActiveControl::NewLC(CConsoleBase* aConsole, TDes * aConfigFile, TDes * aScriptFile)
1.141 + {
1.142 + CActiveControl* self = new (ELeave) CActiveControl(aConsole, aConfigFile, aScriptFile);
1.143 + CleanupStack::PushL(self);
1.144 + self->ConstructL();
1.145 + return self;
1.146 + }
1.147 +
1.148 +
1.149 +CActiveControl* CActiveControl::NewL(CConsoleBase* aConsole, TDes * aConfigFile, TDes * aScriptFile)
1.150 + {
1.151 + CActiveControl* self = NewLC(aConsole, aConfigFile, aScriptFile);
1.152 + CleanupStack::Pop();
1.153 + return self;
1.154 + }
1.155 +
1.156 +
1.157 +void CActiveControl::ConstructL()
1.158 + {
1.159 + CActiveScheduler::Add(this);
1.160 + TInt r;
1.161 +
1.162 + User::LeaveIfError(iFs.Connect());
1.163 +
1.164 + test.Start (_L("Configuration"));
1.165 +
1.166 + test_Compare(iConfigFileName->Length(),!=,0);
1.167 +
1.168 + iTimer.CreateLocal();
1.169 + iPending = EPendingNone;
1.170 +
1.171 + test.Next (_L("Open configuration file"));
1.172 + // set the session path to use the ROM if no drive specified
1.173 + r=iFs.SetSessionPath(_L("Z:\\test\\"));
1.174 + test_KErrNone(r);
1.175 +
1.176 + r = iConfigFile.Open(iFs, * iConfigFileName, EFileShareReadersOnly | EFileStreamText | EFileRead);
1.177 + test_KErrNone(r);
1.178 + TUSB_VERBOSE_PRINT1("Configuration file %s Opened successfully", iConfigFileName->PtrZ());
1.179 +
1.180 + test.Next (_L("Process configuration file"));
1.181 + test(ProcessConfigFile (iConfigFile,iConsole,&iLddPtr));
1.182 +
1.183 + iConfigFile.Close();
1.184 +
1.185 + test.Next (_L("LDD in configuration file"));
1.186 + test_NotNull(iLddPtr);
1.187 +
1.188 + LDDConfigPtr lddPtr = iLddPtr;
1.189 + TInt nextPort = 0;
1.190 + while (lddPtr != NULL)
1.191 + {
1.192 + // Load logical driver (LDD)
1.193 + // (There's no physical driver (PDD) with USB: it's a kernel extension DLL which
1.194 + // was already loaded at boot time.)
1.195 + test.Next (_L("Loading USB LDD"));
1.196 + TUSB_VERBOSE_PRINT1("Loading USB LDD ",lddPtr->iName.PtrZ());
1.197 + r = User::LoadLogicalDevice(lddPtr->iName);
1.198 + test(r == KErrNone || r == KErrAlreadyExists);
1.199 +
1.200 + IFConfigPtr ifPtr = lddPtr->iIFPtr;
1.201 +
1.202 + test.Next (_L("Opening Channels"));
1.203 + for (TInt portNumber = nextPort; portNumber < nextPort+lddPtr->iNumChannels; portNumber++)
1.204 + {
1.205 + test_Compare(lddPtr->iNumChannels,>,0);
1.206 +
1.207 + // Open USB channel
1.208 + r = iPort[portNumber].Open(0);
1.209 + test_KErrNone(r);
1.210 + TUSB_VERBOSE_PRINT("Successfully opened USB port");
1.211 +
1.212 + // Query the USB device/Setup the USB interface
1.213 + if (portNumber == nextPort)
1.214 + {
1.215 + // Change some descriptors to contain suitable values
1.216 + SetupDescriptors(lddPtr, &iPort[portNumber]);
1.217 + }
1.218 +
1.219 + if (portNumber == 0)
1.220 + {
1.221 + QueryUsbClientL(lddPtr, &iPort[portNumber]);
1.222 + }
1.223 +
1.224 + test_NotNull(ifPtr);
1.225 +
1.226 + IFConfigPtr defaultIfPtr = ifPtr;
1.227 + SetupInterface(&ifPtr,portNumber);
1.228 +
1.229 + #ifdef USB_SC
1.230 + RChunk *tChunk = &gChunk;
1.231 + test_KErrNone(iPort[portNumber].FinalizeInterface(tChunk));
1.232 + #endif
1.233 +
1.234 + // allocate endpoint DMA and double buffering for all endpoints on default interface
1.235 + for (TUint8 i = 1; i <= defaultIfPtr->iInfoPtr->iTotalEndpointsUsed; i++)
1.236 + {
1.237 + defaultIfPtr->iEpDMA[i-1] ? AllocateEndpointDMA(&iPort[portNumber],(TENDPOINTNUMBER)i) : DeAllocateEndpointDMA(&iPort[portNumber],(TENDPOINTNUMBER)i);
1.238 + #ifndef USB_SC
1.239 + defaultIfPtr->iEpDoubleBuff[i-1] ? AllocateDoubleBuffering(&iPort[portNumber],(TENDPOINTNUMBER)i) : DeAllocateDoubleBuffering(&iPort[portNumber],(TENDPOINTNUMBER)i);
1.240 + #endif
1.241 + }
1.242 +
1.243 + }
1.244 +
1.245 + iTotalChannels += lddPtr->iNumChannels;
1.246 + nextPort += lddPtr->iNumChannels;
1.247 + lddPtr = lddPtr->iPtrNext;
1.248 + }
1.249 +
1.250 + TUSB_VERBOSE_PRINT("All Interfaces and Alternate Settings successfully set up");
1.251 +
1.252 + test.Next (_L("Start Idle Counter Thread"));
1.253 + r = iIdleCounterThread.Create(_L("IdleCounter"), IdleCounterThread, KDefaultStackSize, KMinHeapSize, KMinHeapSize, NULL);
1.254 + test_KErrNone(r);
1.255 + iIdleCounterThread.Resume();
1.256 + // Allow some time for low-priority counter process
1.257 + User::After(100000); // 0.1 second
1.258 + r = iIdleCounterChunk.OpenGlobal(KTestIdleCounterChunkName, EFalse);
1.259 + test_KErrNone(r);
1.260 + iIdleCounter = (struct TTestIdleCounter*) iIdleCounterChunk.Base();
1.261 + test_NotNull(iIdleCounter);
1.262 + // Allow some time for low-priority counter process
1.263 + User::After(100000); // 0.1 second
1.264 + TInt64 val1 = iIdleCounter->iCounter;
1.265 + User::After(1000000); // 1 second
1.266 + TInt64 val2 = iIdleCounter->iCounter;
1.267 + TUSB_PRINT1("Idle Counter when test inactive: %Ldinc/ms", (val2 - val1) / 1000);
1.268 +
1.269 + test.Next (_L("Enumeration..."));
1.270 + r = ReEnumerate();
1.271 + test_KErrNone(r);
1.272 +
1.273 + TUSB_VERBOSE_PRINT("Device successfully re-enumerated\n");
1.274 +
1.275 +
1.276 + if (iLddPtr->iHighSpeed && !gSkip)
1.277 + {
1.278 + test.Next (_L("High Speed"));
1.279 + test(iHighSpeed);
1.280 + }
1.281 +
1.282 + test.Next (_L("Create Notifiers"));
1.283 + for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
1.284 + {
1.285 +
1.286 + // Create device state active object
1.287 + iDeviceStateNotifier[portNumber] = CActiveDeviceStateNotifier::NewL(iConsole, &iPort[portNumber], portNumber);
1.288 + test_NotNull(iDeviceStateNotifier[portNumber]);
1.289 + iDeviceStateNotifier[portNumber]->Activate();
1.290 + TUSB_VERBOSE_PRINT("Created device state notifier");
1.291 +
1.292 + // Create endpoint stall status active object
1.293 + iStallNotifier[portNumber] = CActiveStallNotifier::NewL(iConsole, &iPort[portNumber]);
1.294 + test_NotNull(iStallNotifier[portNumber]);
1.295 + iStallNotifier[portNumber]->Activate();
1.296 + TUSB_VERBOSE_PRINT("Created stall notifier");
1.297 +
1.298 + TestInvalidSetInterface (&iPort[portNumber],iNumInterfaceSettings[portNumber]);
1.299 + TestInvalidReleaseInterface (&iPort[portNumber],iNumInterfaceSettings[portNumber]);
1.300 +
1.301 + }
1.302 +
1.303 + test.Next (_L("Endpoint Zero Max Packet Sizes"));
1.304 + TUint ep0Size = iPort[0].EndpointZeroMaxPacketSizes();
1.305 + switch (ep0Size)
1.306 + {
1.307 + case KUsbEpSize8 :
1.308 + iEp0PacketSize = 8;
1.309 + break;
1.310 +
1.311 + case KUsbEpSize16 :
1.312 + iEp0PacketSize = 16;
1.313 + break;
1.314 +
1.315 + case KUsbEpSize32 :
1.316 + iEp0PacketSize = 32;
1.317 + break;
1.318 +
1.319 + case KUsbEpSize64 :
1.320 + iEp0PacketSize = 64;
1.321 + break;
1.322 +
1.323 + default:
1.324 + iEp0PacketSize = 0;
1.325 + break;
1.326 + }
1.327 + test_Compare(iEp0PacketSize,>,0);
1.328 +
1.329 + test.Next (_L("Set Device Control"));
1.330 + r = iPort[0].SetDeviceControl();
1.331 + test_KErrNone(r);
1.332 +
1.333 + #ifdef USB_SC
1.334 + r = iPort[0].OpenEndpoint(iEp0Buf,0);
1.335 + test_KErrNone(r);
1.336 + #endif
1.337 +
1.338 + test.End();
1.339 +
1.340 + }
1.341 +
1.342 +void CActiveControl::ReConnect()
1.343 + {
1.344 + TInt r;
1.345 +
1.346 + test.Start (_L("Reconnecting USB"));
1.347 + LDDConfigPtr lddPtr = iLddPtr;
1.348 + TInt nextPort = 0;
1.349 + while (lddPtr != NULL)
1.350 + {
1.351 + IFConfigPtr ifPtr = lddPtr->iIFPtr;
1.352 +
1.353 + test.Next (_L("Opening Channels"));
1.354 + for (TInt portNumber = nextPort; portNumber < nextPort+lddPtr->iNumChannels; portNumber++)
1.355 + {
1.356 + // Open USB channel
1.357 + r = iPort[portNumber].Open(0);
1.358 + test_KErrNone(r);
1.359 + TUSB_VERBOSE_PRINT("Successfully opened USB port");
1.360 +
1.361 + // Query the USB device/Setup the USB interface
1.362 + if (portNumber == nextPort)
1.363 + {
1.364 + // Change some descriptors to contain suitable values
1.365 + SetupDescriptors(lddPtr, &iPort[portNumber]);
1.366 + }
1.367 +
1.368 + IFConfigPtr defaultIfPtr = ifPtr;
1.369 + SetupInterface(&ifPtr,portNumber);
1.370 +
1.371 + #ifdef USB_SC
1.372 + RChunk *tChunk = &gChunk;
1.373 + test_KErrNone(iPort[portNumber].FinalizeInterface(tChunk));
1.374 + #endif
1.375 +
1.376 + // allocate endpoint DMA and double buffering for all endpoints on default interface
1.377 + for (TUint8 i = 1; i <= defaultIfPtr->iInfoPtr->iTotalEndpointsUsed; i++)
1.378 + {
1.379 + defaultIfPtr->iEpDMA[i-1] ? AllocateEndpointDMA(&iPort[portNumber],(TENDPOINTNUMBER)i) : DeAllocateEndpointDMA(&iPort[portNumber],(TENDPOINTNUMBER)i);
1.380 + #ifndef USB_SC
1.381 + defaultIfPtr->iEpDoubleBuff[i-1] ? AllocateDoubleBuffering(&iPort[portNumber],(TENDPOINTNUMBER)i) : DeAllocateDoubleBuffering(&iPort[portNumber],(TENDPOINTNUMBER)i);
1.382 + #endif
1.383 + }
1.384 + }
1.385 +
1.386 + nextPort += lddPtr->iNumChannels;
1.387 + lddPtr = lddPtr->iPtrNext;
1.388 + }
1.389 +
1.390 + TUSB_VERBOSE_PRINT("All Interfaces and Alternate Settings successfully set up");
1.391 +
1.392 + test.Next (_L("Enumeration..."));
1.393 + r = ReEnumerate();
1.394 + test_KErrNone(r);
1.395 +
1.396 + TUSB_VERBOSE_PRINT("Device successfully re-enumerated\n");
1.397 +
1.398 + for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
1.399 + {
1.400 + // Create device state active object
1.401 + iDeviceStateNotifier[portNumber] = CActiveDeviceStateNotifier::NewL(iConsole, &iPort[portNumber], portNumber);
1.402 + test_NotNull(iDeviceStateNotifier[portNumber]);
1.403 + iDeviceStateNotifier[portNumber]->Activate();
1.404 + TUSB_VERBOSE_PRINT("Created device state notifier");
1.405 +
1.406 + // Create endpoint stall status active object
1.407 + iStallNotifier[portNumber] = CActiveStallNotifier::NewL(iConsole, &iPort[portNumber]);
1.408 + test_NotNull(iStallNotifier[portNumber]);
1.409 + iStallNotifier[portNumber]->Activate();
1.410 + TUSB_VERBOSE_PRINT("Created stall notifier");
1.411 +
1.412 + if (portNumber == 0)
1.413 + {
1.414 + test.Next (_L("Set Device Control"));
1.415 + r = iPort[portNumber].SetDeviceControl();
1.416 + test_KErrNone(r);
1.417 +
1.418 + #ifdef USB_SC
1.419 + r = iPort[portNumber].OpenEndpoint(iEp0Buf,0);
1.420 + test_KErrNone(r);
1.421 + #endif
1.422 +
1.423 + }
1.424 + }
1.425 +
1.426 + test.End();
1.427 + }
1.428 +
1.429 +void CActiveControl::SetupInterface(IFConfigPtr* aIfPtr, TInt aPortNumber)
1.430 + {
1.431 + test.Start (_L("Setup Interface"));
1.432 +
1.433 + // first of all set the default interface
1.434 + TUSB_PRINT2 ("Set Default Interface with %d endpoints bandwidth 0x%x",(*aIfPtr)->iInfoPtr->iTotalEndpointsUsed,(*aIfPtr)->iBandwidthIn | (*aIfPtr)->iBandwidthOut);
1.435 + #ifdef USB_SC
1.436 + TUsbcScInterfaceInfoBuf ifc = *((*aIfPtr)->iInfoPtr);
1.437 + TInt r = iPort[aPortNumber].SetInterface(0, ifc);
1.438 + #else
1.439 + TUsbcInterfaceInfoBuf ifc = *((*aIfPtr)->iInfoPtr);
1.440 + TInt r = iPort[aPortNumber].SetInterface(0, ifc, (*aIfPtr)->iBandwidthIn | (*aIfPtr)->iBandwidthOut);
1.441 + #endif
1.442 + test_KErrNone(r);
1.443 +
1.444 + TBuf8<KUsbDescSize_Interface> ifDescriptor;
1.445 + r = iPort[aPortNumber].GetInterfaceDescriptor(0, ifDescriptor);
1.446 + test_KErrNone(r);
1.447 +
1.448 + // Check the interface descriptor
1.449 + test(ifDescriptor[KIfcDesc_SettingOffset] == 0 && ifDescriptor[KIfcDesc_NumEndpointsOffset] == (*aIfPtr)->iInfoPtr->iTotalEndpointsUsed &&
1.450 + ifDescriptor[KIfcDesc_ClassOffset] == (*aIfPtr)->iInfoPtr->iClass.iClassNum &&
1.451 + ifDescriptor[KIfcDesc_SubClassOffset] == (*aIfPtr)->iInfoPtr->iClass.iSubClassNum &&
1.452 + ifDescriptor[KIfcDesc_ProtocolOffset] == (*aIfPtr)->iInfoPtr->iClass.iProtocolNum);
1.453 +
1.454 + if ((*aIfPtr)->iNumber != 0 && ifDescriptor[KIfcDesc_NumberOffset] != (*aIfPtr)->iNumber)
1.455 + {
1.456 + ifDescriptor[KIfcDesc_NumberOffset] = (*aIfPtr)->iNumber;
1.457 + r = iPort[aPortNumber].SetInterfaceDescriptor(0, ifDescriptor);
1.458 + test_KErrNone(r);
1.459 + }
1.460 + else
1.461 + {
1.462 + (*aIfPtr)->iNumber = ifDescriptor[KIfcDesc_NumberOffset];
1.463 + }
1.464 + TUint8 interfaceNumber = (*aIfPtr)->iNumber;
1.465 + TUSB_PRINT1 ("Interface Number %d",interfaceNumber);
1.466 +
1.467 + // Check all endpoint descriptors
1.468 + TBuf8<KUsbDescSize_AudioEndpoint> epDescriptor;
1.469 + for (TUint i = 0; i < (*aIfPtr)->iInfoPtr->iTotalEndpointsUsed; i++)
1.470 + {
1.471 + if (!gSkip)
1.472 + {
1.473 + TestEndpointDescriptor (&iPort[aPortNumber],0,i+1,(*aIfPtr)->iInfoPtr->iEndpointData[i]);
1.474 +
1.475 + }
1.476 +
1.477 + if (firstBulkOutEndpoint < 0 && ((*aIfPtr)->iInfoPtr->iEndpointData[i].iDir & KUsbEpDirOut) &&
1.478 + (*aIfPtr)->iInfoPtr->iEndpointData[i].iType == KUsbEpTypeBulk)
1.479 + {
1.480 + firstBulkOutEndpoint = i+1;
1.481 + }
1.482 + }
1.483 +
1.484 + TUSB_PRINT1 ("Interface number is %d",interfaceNumber);
1.485 + (*aIfPtr)->iPortNumber = aPortNumber;
1.486 + gInterfaceConfig [interfaceNumber] [0] = *aIfPtr;
1.487 +
1.488 + TInt alternateNumber = 1;
1.489 + // check for any alternatate interfaces and set any that are found
1.490 + * aIfPtr = (*aIfPtr)->iPtrNext;
1.491 + if (* aIfPtr != NULL)
1.492 + {
1.493 + test(SupportsAlternateInterfaces());
1.494 +
1.495 + IFConfigPtr ifPtr = *aIfPtr;
1.496 + while (ifPtr != NULL)
1.497 + {
1.498 + if (ifPtr->iAlternateSetting)
1.499 + {
1.500 + ifc = *(ifPtr->iInfoPtr);
1.501 + #ifdef USB_SC
1.502 + TUSB_PRINT2 ("Set Alternate Interface Setting %d with %d endpoints",alternateNumber,ifPtr->iInfoPtr->iTotalEndpointsUsed);
1.503 + r = iPort[aPortNumber].SetInterface(alternateNumber, ifc);
1.504 + #else
1.505 + TUSB_PRINT3 ("Set Alternate Interface Setting %d with %d endpoints bandwidth 0x%x",alternateNumber,ifPtr->iInfoPtr->iTotalEndpointsUsed,ifPtr->iBandwidthIn | iLddPtr->iIFPtr->iBandwidthOut);
1.506 + r = iPort[aPortNumber].SetInterface(alternateNumber, ifc, ifPtr->iBandwidthIn | iLddPtr->iIFPtr->iBandwidthOut);
1.507 + #endif
1.508 + test_KErrNone(r);
1.509 +
1.510 + r = iPort[aPortNumber].GetInterfaceDescriptor(alternateNumber, ifDescriptor);
1.511 + test_KErrNone(r);
1.512 +
1.513 + // Check the interface descriptor
1.514 + test(ifDescriptor[KIfcDesc_SettingOffset] == alternateNumber && ifDescriptor[KIfcDesc_NumEndpointsOffset] == (*aIfPtr)->iInfoPtr->iTotalEndpointsUsed &&
1.515 + ifDescriptor[KIfcDesc_ClassOffset] == (*aIfPtr)->iInfoPtr->iClass.iClassNum &&
1.516 + ifDescriptor[KIfcDesc_SubClassOffset] == (*aIfPtr)->iInfoPtr->iClass.iSubClassNum &&
1.517 + ifDescriptor[KIfcDesc_ProtocolOffset] == (*aIfPtr)->iInfoPtr->iClass.iProtocolNum);
1.518 +
1.519 + // Check all endpoint descriptors
1.520 + for (TUint i = 0; i < ifPtr->iInfoPtr->iTotalEndpointsUsed; i++)
1.521 + {
1.522 + TInt desc_size;
1.523 + r = iPort[aPortNumber].GetEndpointDescriptorSize(alternateNumber, i+1, desc_size);
1.524 + test_KErrNone(r);
1.525 + test_Equal(KUsbDescSize_Endpoint + (*aIfPtr)->iInfoPtr->iEndpointData[i].iExtra,static_cast<TUint>(desc_size));
1.526 +
1.527 + r = iPort[aPortNumber].GetEndpointDescriptor(alternateNumber, i+1, epDescriptor);
1.528 + test_KErrNone(r);
1.529 +
1.530 + test((((*aIfPtr)->iInfoPtr->iEndpointData[i].iDir & KUsbEpDirIn) && (epDescriptor[KEpDesc_AddressOffset] & 0x80) ||
1.531 + !((*aIfPtr)->iInfoPtr->iEndpointData[i].iDir & KUsbEpDirIn) && !(epDescriptor[KEpDesc_AddressOffset] & 0x80)) &&
1.532 + EpTypeMask2Value((*aIfPtr)->iInfoPtr->iEndpointData[i].iType) == (TUint)(epDescriptor[KEpDesc_AttributesOffset] & 0x03) &&
1.533 + (*aIfPtr)->iInfoPtr->iEndpointData[i].iInterval == epDescriptor[KEpDesc_IntervalOffset]);
1.534 +
1.535 +
1.536 + if (!gSkip && (*aIfPtr)->iInfoPtr->iEndpointData[i].iExtra)
1.537 + {
1.538 + test.Next(_L("Extended Endpoint Descriptor Manipulation"));
1.539 + TUint8 addr = 0x85; // bogus address
1.540 + if (epDescriptor[KEpDesc_SynchAddressOffset] == addr)
1.541 + addr++;
1.542 + epDescriptor[KEpDesc_SynchAddressOffset] = addr;
1.543 + r = iPort[aPortNumber].SetEndpointDescriptor(alternateNumber, i+1, epDescriptor);
1.544 + test_KErrNone(r);
1.545 +
1.546 + TBuf8<KUsbDescSize_AudioEndpoint> descriptor2;
1.547 + r = iPort[aPortNumber].GetEndpointDescriptor(alternateNumber, i+1, descriptor2);
1.548 + test_KErrNone(r);
1.549 +
1.550 + test.Next(_L("Compare endpoint descriptor with value set"));
1.551 + r = descriptor2.Compare(epDescriptor);
1.552 + test_KErrNone(r);
1.553 + }
1.554 + }
1.555 +
1.556 +
1.557 + // if no error move on to the next interface
1.558 + ifPtr->iPortNumber = aPortNumber;
1.559 + ifPtr->iNumber = interfaceNumber;
1.560 + gInterfaceConfig [interfaceNumber] [alternateNumber] = ifPtr;
1.561 +
1.562 + alternateNumber++;
1.563 + ifPtr = ifPtr->iPtrNext;
1.564 + * aIfPtr = ifPtr;
1.565 + }
1.566 + else
1.567 + {
1.568 + ifPtr = NULL;
1.569 + }
1.570 + }
1.571 + }
1.572 + iNumInterfaceSettings[aPortNumber] = alternateNumber;
1.573 + if (!gSkip)
1.574 + {
1.575 + TestInvalidSetInterface (&iPort[aPortNumber],iNumInterfaceSettings[aPortNumber]);
1.576 + TestInvalidReleaseInterface (&iPort[aPortNumber],iNumInterfaceSettings[aPortNumber]);
1.577 +
1.578 + TestDescriptorManipulation(iLddPtr->iHighSpeed,&iPort[aPortNumber],alternateNumber);
1.579 + TestOtgExtensions(&iPort[aPortNumber]);
1.580 + TestEndpoint0MaxPacketSizes(&iPort[aPortNumber]);
1.581 + }
1.582 +
1.583 + test.End();
1.584 + }
1.585 +
1.586 +
1.587 +CActiveControl::~CActiveControl()
1.588 + {
1.589 + TUSB_PRINT("CActiveControl::~CActiveControl()");
1.590 +
1.591 + Cancel();
1.592 +
1.593 + iTimer.Close();
1.594 +
1.595 + // delete interfaces
1.596 + while (iLddPtr->iIFPtr)
1.597 + {
1.598 + IFConfigPtr* ifPtrPtr = & iLddPtr->iIFPtr;
1.599 + while ((*ifPtrPtr)->iPtrNext)
1.600 + {
1.601 + ifPtrPtr = &(*ifPtrPtr)->iPtrNext;
1.602 + }
1.603 + delete (*ifPtrPtr)->iInfoPtr->iString;
1.604 + delete (*ifPtrPtr)->iInfoPtr;
1.605 + delete (*ifPtrPtr);
1.606 + * ifPtrPtr = NULL;
1.607 + }
1.608 +
1.609 + while (iLddPtr)
1.610 + {
1.611 + LDDConfigPtr* lddPtrPtr = &iLddPtr;
1.612 + while ((*lddPtrPtr)->iPtrNext)
1.613 + {
1.614 + lddPtrPtr = &(*lddPtrPtr)->iPtrNext;
1.615 + }
1.616 + delete (*lddPtrPtr)->iManufacturer;
1.617 + delete (*lddPtrPtr)->iProduct;
1.618 + delete (*lddPtrPtr)->iSerialNumber;
1.619 + delete (*lddPtrPtr);
1.620 + * lddPtrPtr = NULL;
1.621 + }
1.622 +
1.623 + iFs.Close();
1.624 + }
1.625 +
1.626 +void CActiveControl::DoCancel()
1.627 + {
1.628 + TUSB_VERBOSE_PRINT("CActiveControl::DoCancel()");
1.629 + iConsole->ReadCancel();
1.630 + }
1.631 +
1.632 +void CActiveControl::SetMSFinished(TBool aState)
1.633 + {
1.634 + if (aState)
1.635 + {
1.636 + if (iPending != EPendingEject)
1.637 + {
1.638 + iPending = EPendingEject;
1.639 + iTimer.After(iStatus,KMSFinishedDelay);
1.640 + if (!IsActive())
1.641 + {
1.642 + SetActive();
1.643 + }
1.644 + }
1.645 + }
1.646 + else
1.647 + {
1.648 + if (iPending == EPendingEject)
1.649 + {
1.650 + iPending = EPendingCancel;
1.651 + iTimer.Cancel();
1.652 + }
1.653 + }
1.654 + }
1.655 +
1.656 +void CActiveControl::RequestEp0ControlPacket()
1.657 + {
1.658 + TUSB_VERBOSE_PRINT("CActiveControl::RequestEp0ControlPacket()");
1.659 + // A request is issued to read a packet for endpoint 0
1.660 + __ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 660));
1.661 + #ifdef USB_SC
1.662 + TInt r = 0;
1.663 + do
1.664 + {
1.665 + r = iEp0Buf.GetBuffer (iEp0Packet,iEp0Size,iEp0Zlp,iStatus);
1.666 + TUSB_VERBOSE_PRINT4("Get Buffer Return code %d Status %d PacketPtr 0x%x Size %d", r, iStatus.Int(),iEp0Packet,iEp0Size);
1.667 + test_Value(r, (r == KErrNone) || (r == KErrCompletion) || (r == TEndpointBuffer::KStateChange) || (r == KErrAlternateSettingChanged));
1.668 + if (r == KErrCompletion)
1.669 + {
1.670 + // ignore anything except a setup packet
1.671 + if ((TInt)iEp0Size == KSetupPacketSize)
1.672 + {
1.673 + iEp0SetUpPacket.Copy((TUint8 *)iEp0Packet,iEp0Size);
1.674 + r = ProcessEp0ControlPacket();
1.675 + }
1.676 + }
1.677 + else
1.678 + {
1.679 + if (r == KErrNone)
1.680 + {
1.681 + iPending = EPendingEp0Read;
1.682 + SetActive();
1.683 + }
1.684 + }
1.685 + }
1.686 + while ((r == KErrCompletion) || (r == TEndpointBuffer::KStateChange) || (r == KErrAlternateSettingChanged));
1.687 + #else
1.688 + iPort[0].ReadPacket(iStatus,EEndpoint0, iEp0SetUpPacket,KSetupPacketSize);
1.689 + iPending = EPendingEp0Read;
1.690 + SetActive();
1.691 + #endif
1.692 + }
1.693 +
1.694 +void CActiveControl::RunL()
1.695 + {
1.696 + TInt r = KErrNone;
1.697 +
1.698 + TUSB_VERBOSE_PRINT("CActiveControl::RunL()");
1.699 +
1.700 + switch (iPending)
1.701 + {
1.702 + case EPendingNone :
1.703 + break;
1.704 +
1.705 + case EPendingEp0Read :
1.706 + iPending = EPendingNone;
1.707 + if (iStatus != KErrNone)
1.708 + {
1.709 + TUSB_PRINT1("ActiveControl::Error %d in Ep0 Read Packet", iStatus.Int());
1.710 + test(EFalse);
1.711 + }
1.712 + #ifdef USB_SC
1.713 + // for shared chunks this means that data is available in the buffer
1.714 + // but the data has yet to be transferred to a local buffer
1.715 + RequestEp0ControlPacket();
1.716 + #else
1.717 + if (ProcessEp0ControlPacket() == KErrCompletion)
1.718 + RequestEp0ControlPacket();
1.719 + #endif
1.720 + break;
1.721 +
1.722 + case EPendingTimer :
1.723 + iPending = EPendingNone;
1.724 + if (iStatus != KErrNone)
1.725 + {
1.726 + TUSB_PRINT1("ActiveControl::Error %d in Connection Timer Delay", iStatus.Int());
1.727 + test(EFalse);
1.728 + }
1.729 + r = iPort[0].DeviceConnectToHost();
1.730 + test_KErrNone (r);
1.731 +
1.732 + test.End();
1.733 +
1.734 + RequestEp0ControlPacket();
1.735 + break;
1.736 +
1.737 + case EPendingEject :
1.738 + iPending = EPendingNone;
1.739 + if (iStatus != KErrNone)
1.740 + {
1.741 + TUSB_PRINT1("ActiveControl::Error %d in Eject Timer Delay", iStatus.Int());
1.742 + test(EFalse);
1.743 + }
1.744 + StopMassStorage(&iPort[0]);
1.745 + #ifdef USB_SC
1.746 + iEp0Buf.Close();
1.747 + #endif
1.748 + ReConnect();
1.749 +
1.750 + RequestEp0ControlPacket();
1.751 + break;
1.752 +
1.753 + case EPendingCancel :
1.754 + iPending = EPendingNone;
1.755 + if (iStatus != KErrNone && iStatus != KErrCancel)
1.756 + {
1.757 + TUSB_PRINT1("ActiveControl::Error %d in Eject Timer Delay", iStatus.Int());
1.758 + test(EFalse);
1.759 + }
1.760 + }
1.761 +
1.762 + }
1.763 +
1.764 +TInt CActiveControl::ProcessEp0ControlPacket()
1.765 + {
1.766 + TUint16 value = *reinterpret_cast<TUint16*>(&iEp0SetUpPacket[KUsb_Ep0wValueOffset]);
1.767 + TUint16 index = *reinterpret_cast<TUint16*>(&iEp0SetUpPacket[KUsb_Ep0wIndexOffset]);
1.768 + TUint16 length= *reinterpret_cast<TUint16*>(&iEp0SetUpPacket[KUsb_Ep0wLengthOffset]);
1.769 + TUSB_VERBOSE_PRINT3("ProcessEp0ControlPacket length 0x%x value 0x%x index 0x%x",length,value,index);
1.770 + TRequestStatus ep0Status;
1.771 + TUint8 host_ver_major;
1.772 + TUint8 host_ver_minor;
1.773 + TUint8 host_ver_micro;
1.774 + TUint8 usbio_ver_major;
1.775 + TUint8 usbio_ver_minor;
1.776 + #ifndef USB_SC
1.777 + TBuf8<KMaxControlPacketSize> ep0DataPacket;
1.778 + #endif
1.779 + TestParamPtr tpPtr;
1.780 + TBool firstSettingThread = (index & KFirstSettingThreadMask) ? ETrue : EFalse;
1.781 + TBool lastSettingThread = (index & KLastSettingThreadMask) ? ETrue : EFalse;
1.782 + index &= ~(KFirstSettingThreadMask | KLastSettingThreadMask);
1.783 + CActiveRW* pActiveRW;
1.784 + TInt r;
1.785 + TBool sendStatus;
1.786 +
1.787 + if (((iEp0SetUpPacket[KUsb_Ep0RequestTypeOffset] & KUsbRequestType_DestMask) == KUsbRequestType_DestDevice) &&
1.788 + ((iEp0SetUpPacket[KUsb_Ep0RequestTypeOffset] & KUsbRequestType_TypeMask) == KUsbRequestType_TypeClass))
1.789 + {
1.790 + TUSB_VERBOSE_PRINT("Received Device Directed setup packet");
1.791 + if ((iEp0SetUpPacket[KUsb_Ep0RequestTypeOffset] & KUsbRequestType_DirMask) == KUsbRequestType_DirToDev)
1.792 + {
1.793 + iEp0DataBuffer.SetLength(0);
1.794 + while (iEp0DataBuffer.Length() < length)
1.795 + {
1.796 + TUSB_VERBOSE_PRINT("Reading Ep0 data packet");
1.797 + #ifdef USB_SC
1.798 + r = iEp0Buf.GetBuffer (iEp0Packet,iEp0Size,iEp0Zlp,ep0Status);
1.799 + test_Value(r, r == KErrNone || r == KErrCompletion || (r == KErrAlternateSettingChanged));
1.800 + while (r == KErrNone)
1.801 + {
1.802 + TUSB_VERBOSE_PRINT("Waiting for Ep0 data packet");
1.803 + User::WaitForRequest(ep0Status);
1.804 + test_KErrNone(ep0Status.Int());
1.805 + r = iEp0Buf.GetBuffer (iEp0Packet,iEp0Size,iEp0Zlp,ep0Status);
1.806 + test_Value(r, r == KErrNone || r == KErrCompletion || (r == KErrAlternateSettingChanged));
1.807 + }
1.808 + TUSB_VERBOSE_PRINT1("Ep0 data packet - size %d",iEp0Size);
1.809 + iEp0DataBuffer.Append((TUint8 *)iEp0Packet,iEp0Size);
1.810 + #else
1.811 + TUint16 packetLength = Min(length-iEp0DataBuffer.Length(),iEp0PacketSize);
1.812 + iPort[0].ReadPacket(ep0Status, EEndpoint0, ep0DataPacket, packetLength);
1.813 + User::WaitForRequest(ep0Status);
1.814 + if (ep0Status == KErrNone)
1.815 + {
1.816 + iEp0DataBuffer.Append(ep0DataPacket);
1.817 + }
1.818 + else
1.819 + {
1.820 + TUSB_PRINT1("ActiveControl::Error %d in Ep0 Read Data Packet", ep0Status.Int());
1.821 + test(EFalse);
1.822 + return KErrNone;
1.823 + }
1.824 + #endif
1.825 + }
1.826 + TUSB_VERBOSE_PRINT4("Setup ToDevice Type %d length %d value %d index %d",iEp0SetUpPacket[KUsb_Ep0RequestOffset],length,value,index);
1.827 + sendStatus = ETrue;
1.828 + switch (iEp0SetUpPacket[KUsb_Ep0RequestOffset])
1.829 + {
1.830 + case EStop :
1.831 + // send this now as the port will be disconnected
1.832 + sendStatus = EFalse;
1.833 + r = iPort[0].SendEp0StatusPacket();
1.834 + test_KErrNone(r);
1.835 +
1.836 + if (value && firstBulkOutEndpoint > 0)
1.837 + {
1.838 + PrintHostLog();
1.839 + }
1.840 +
1.841 + for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
1.842 + {
1.843 + // base class cancel -> calls our DoCancel
1.844 + delete iDeviceStateNotifier[portNumber];
1.845 + delete iStallNotifier[portNumber];
1.846 + if (portNumber == 0)
1.847 + {
1.848 + r = iPort[portNumber].RemoveStringDescriptor(stridx1);
1.849 + if (r != KErrNone)
1.850 + {
1.851 + TUSB_PRINT1("Error %d on string removal", r);
1.852 + }
1.853 + r = iPort[portNumber].RemoveStringDescriptor(stridx2);
1.854 + if (r != KErrNone)
1.855 + {
1.856 + TUSB_PRINT1("Error %d on string removal", r);
1.857 + }
1.858 + }
1.859 + TUSB_VERBOSE_PRINT1 ("Closing USB channel number %d",portNumber);
1.860 + iPort[portNumber].Close(); // close USB channel
1.861 + }
1.862 + TUSB_VERBOSE_PRINT("Closing Idle Counter Thread");
1.863 + iIdleCounter->iCommand = ETestIdleCounterClose;
1.864 + iIdleCounterChunk.Close();
1.865 + // Allow time for low-priority thread to close
1.866 + User::After(100000);
1.867 + iIdleCounterThread.Close();
1.868 +
1.869 + CActiveScheduler::Stop();
1.870 + break;
1.871 +
1.872 + case EVersion :
1.873 + TUSB_PRINT("Receiving t_usb_host version");
1.874 + host_ver_major = iEp0DataBuffer[0];
1.875 + host_ver_minor = iEp0DataBuffer[1];
1.876 + host_ver_micro = iEp0DataBuffer[2];
1.877 + usbio_ver_major = iEp0DataBuffer[3];
1.878 + usbio_ver_minor = iEp0DataBuffer[4];
1.879 + TUSB_PRINT5("Host-side: t_usb_host v%d.%d.%d USBIO v%d.%d\n",
1.880 + host_ver_major, host_ver_minor, host_ver_micro,
1.881 + usbio_ver_major, usbio_ver_minor);
1.882 + if (host_ver_major < KHostVersionMajor)
1.883 + {
1.884 + TUSB_PRINT1("t_usb_host version not sufficient (need at least v%d.x.x)\n",KHostVersionMajor);
1.885 + User::Leave(-1);
1.886 + return KErrNone;
1.887 + }
1.888 + // Just using '<' instead of the seemingly absurd '<= && !==' doesn't work without
1.889 + // GCC compiler warning because Kxxx can also be zero (in which case there's no '<').
1.890 + else if ((host_ver_minor <= KHostVersionMinor) &&
1.891 + !(host_ver_minor == KHostVersionMinor))
1.892 + {
1.893 + TUSB_PRINT2("t_usb_host version not sufficient (need at least v%d.%d.x)\n",
1.894 + KHostVersionMajor, KHostVersionMinor);
1.895 + test(EFalse);
1.896 + return KErrNone;
1.897 + }
1.898 + // Just using '<' instead of the seemingly absurd '<= && !==' doesn't work without
1.899 + // GCC compiler warning because Kxxx can also be zero (in which case there's no '<').
1.900 + else if ((host_ver_micro <= KHostVersionMicro) &&
1.901 + !(host_ver_micro == KHostVersionMicro))
1.902 + {
1.903 + TUSB_PRINT3("USBRFLCT version not sufficient (need at least v%d.%d.%d)\n",
1.904 + KHostVersionMajor, KHostVersionMinor, KHostVersionMicro);
1.905 + test(EFalse);
1.906 + return KErrNone;
1.907 + }
1.908 + break;
1.909 +
1.910 + case ETestParam :
1.911 + tpPtr = (TestParamPtr)(&iEp0DataBuffer[0]);
1.912 + TUSB_VERBOSE_PRINT4("Test Params - interface %d repeat %d settingRepeat %d beforeIndex %d",tpPtr->interfaceNumber,tpPtr->repeat,tpPtr->settingRepeat,tpPtr->beforeIndex);
1.913 + if (index >= KMaxConcurrentTests)
1.914 + {
1.915 + TUSB_PRINT2("Test index %d is greater than maximum allowed (%d) concurrent tests",index,KMaxConcurrentTests);
1.916 + test(EFalse);
1.917 + return KErrNone;
1.918 + }
1.919 + // Create Reader/Writer active object
1.920 + pActiveRW = CActiveRW::NewL(iConsole, &iPort[gInterfaceConfig[tpPtr->interfaceNumber][tpPtr->alternateSetting]->iPortNumber], iFs, index, lastSettingThread);
1.921 + if (!pActiveRW)
1.922 + {
1.923 + TUSB_PRINT("Failed to create reader/writer");
1.924 + test(EFalse);
1.925 + return KErrNone;
1.926 + }
1.927 + TUSB_VERBOSE_PRINT("Created reader/writer");
1.928 + pActiveRW->SetTestParams(tpPtr);
1.929 + switch (value)
1.930 + {
1.931 + case 'X' :
1.932 + test.Start (_L("Xml"));
1.933 + break;
1.934 +
1.935 + case 'L' :
1.936 + test.Start (_L("Loop"));
1.937 + pActiveRW->SetTransferMode(ELoop);
1.938 + gAltSettingOnNotify = ETrue;
1.939 + if (tpPtr->settingRepeat && !firstSettingThread)
1.940 + {
1.941 + pActiveRW->Suspend(ESuspend);
1.942 + }
1.943 + else
1.944 + {
1.945 + pActiveRW->StartOrSuspend();
1.946 + }
1.947 + break;
1.948 +
1.949 + case 'C' :
1.950 + test.Start (_L("Compare"));
1.951 + pActiveRW->SetTransferMode(ELoopComp);
1.952 + gAltSettingOnNotify = ETrue;
1.953 + if (tpPtr->settingRepeat && !firstSettingThread)
1.954 + {
1.955 + pActiveRW->Suspend(ESuspend);
1.956 + }
1.957 + else
1.958 + {
1.959 + pActiveRW->StartOrSuspend();
1.960 + }
1.961 + break;
1.962 +
1.963 + case 'S' :
1.964 + test.Start (_L("Stream"));
1.965 + if (tpPtr->outPipe > KMaxEndpointsPerClient)
1.966 + {
1.967 + pActiveRW->SetTransferMode(ETransmitOnly);
1.968 + gAltSettingOnNotify = ETrue;
1.969 + if (tpPtr->settingRepeat && !firstSettingThread)
1.970 + {
1.971 + pActiveRW->Suspend(ESuspend);
1.972 + }
1.973 + else
1.974 + {
1.975 + pActiveRW->StartOrSuspend();
1.976 + }
1.977 + }
1.978 + else
1.979 + {
1.980 + pActiveRW->SetTransferMode(EReceiveOnly);
1.981 + gAltSettingOnNotify = ETrue;
1.982 + if (tpPtr->settingRepeat && !firstSettingThread)
1.983 + {
1.984 + pActiveRW->Suspend(ESuspend);
1.985 + }
1.986 + else
1.987 + {
1.988 + pActiveRW->StartOrSuspend();
1.989 + }
1.990 + }
1.991 + break;
1.992 +
1.993 + case 'F' :
1.994 + test.Start (_L("File"));
1.995 + // send this now as the file setup takes a long time
1.996 + sendStatus = EFalse;
1.997 + r = iPort[0].SendEp0StatusPacket();
1.998 + test_KErrNone(r);
1.999 + if (tpPtr->outPipe > KMaxEndpointsPerClient)
1.1000 + {
1.1001 + pActiveRW->SetTransferMode(ETransmitOnly);
1.1002 + TInt maxFileSize = tpPtr->maxSize * tpPtr->repeat;
1.1003 + pActiveRW->ReadFromDisk((TChar)tpPtr->minSize,maxFileSize);
1.1004 + gAltSettingOnNotify = ETrue;
1.1005 + if (tpPtr->settingRepeat && !firstSettingThread)
1.1006 + {
1.1007 + pActiveRW->Suspend(ESuspend);
1.1008 + }
1.1009 + else
1.1010 + {
1.1011 + pActiveRW->StartOrSuspend();
1.1012 + }
1.1013 + }
1.1014 + else
1.1015 + {
1.1016 + pActiveRW->SetTransferMode(EReceiveOnly);
1.1017 + pActiveRW->WriteToDisk((TChar)tpPtr->minSize);
1.1018 + gAltSettingOnNotify = ETrue;
1.1019 + if (tpPtr->settingRepeat && !firstSettingThread)
1.1020 + {
1.1021 + pActiveRW->Suspend(ESuspend);
1.1022 + }
1.1023 + else
1.1024 + {
1.1025 + pActiveRW->StartOrSuspend();
1.1026 + }
1.1027 + }
1.1028 + break;
1.1029 +
1.1030 + default :
1.1031 + TUSB_PRINT1("Invalid test value %X",value);
1.1032 + test(EFalse);
1.1033 + }
1.1034 +
1.1035 + gRW[index] = pActiveRW;
1.1036 + break;
1.1037 +
1.1038 + case ETestResult :
1.1039 + TUSB_VERBOSE_PRINT2 ("Test index %d complete - value %d",index,value);
1.1040 + // if failure, send this first to prevent panic corrupting EP0
1.1041 + if (!value)
1.1042 + {
1.1043 + sendStatus = EFalse;
1.1044 + r = iPort[0].SendEp0StatusPacket();
1.1045 + }
1.1046 + if (index < KMaxConcurrentTests)
1.1047 + {
1.1048 + if (gRW[index] != NULL)
1.1049 + {
1.1050 + gRW[index]->TestComplete (value);
1.1051 + break;
1.1052 + }
1.1053 + }
1.1054 + if (index == KHostErrorIndex)
1.1055 + {
1.1056 + if (!value)
1.1057 + {
1.1058 + TUSB_PRINT("Host Test Fail");
1.1059 + }
1.1060 + }
1.1061 + else
1.1062 + {
1.1063 + TUSB_PRINT2("Invalid test index %d for result %d",index,value);
1.1064 + }
1.1065 + if (!value)
1.1066 + {
1.1067 + test(EFalse);
1.1068 + }
1.1069 + break;
1.1070 +
1.1071 + case ETestFail :
1.1072 + User::Leave(-1);
1.1073 + break;
1.1074 +
1.1075 + case ETestConnect :
1.1076 + test.Start (_L("Connect"));
1.1077 + sendStatus = EFalse;
1.1078 + r = iPort[0].SendEp0StatusPacket();
1.1079 + if (iSoftwareConnect)
1.1080 + {
1.1081 + r = iPort[0].DeviceDisconnectFromHost();
1.1082 + test_KErrNone (r);
1.1083 +
1.1084 + TUint32 waitTime = (TUint32)value * 1000;
1.1085 + if (waitTime == 0)
1.1086 + {
1.1087 + waitTime = 5000; // default to 5 milliseconds
1.1088 + }
1.1089 + iTimer.After(iStatus,waitTime);
1.1090 + iPending = EPendingTimer;
1.1091 +
1.1092 + SetActive();
1.1093 + }
1.1094 + else
1.1095 + {
1.1096 + iConsole->Printf(_L("This device does not support software\n"));
1.1097 + iConsole->Printf(_L("disconnect/reconnect\n"));
1.1098 + iConsole->Printf(_L("Please physically unplug and replug\n"));
1.1099 + iConsole->Printf(_L("the USB cable NOW... "));
1.1100 + test.End ();
1.1101 + }
1.1102 + break;
1.1103 +
1.1104 + case ETestDisconnect :
1.1105 + test.Start (_L("Disconnect"));
1.1106 + // send this now as the port will be disconnected
1.1107 + sendStatus = EFalse;
1.1108 + r = iPort[0].SendEp0StatusPacket();
1.1109 + if (iSoftwareConnect)
1.1110 + {
1.1111 + r = iPort[0].DeviceDisconnectFromHost();
1.1112 + test_KErrNone (r);
1.1113 + }
1.1114 + else
1.1115 + {
1.1116 + iConsole->Printf(_L("This device does not support software\n"));
1.1117 + iConsole->Printf(_L("disconnect/reconnect\n"));
1.1118 + iConsole->Printf(_L("Please physically unplug and replug\n"));
1.1119 + iConsole->Printf(_L("the USB cable NOW... "));
1.1120 + }
1.1121 +
1.1122 + test.End ();
1.1123 + break;
1.1124 +
1.1125 + case ETestMassStorage :
1.1126 + test.Start (_L("Select Mass Storage"));
1.1127 +
1.1128 + // send this now as the port will be disconnected
1.1129 + sendStatus = EFalse;
1.1130 + r = iPort[0].SendEp0StatusPacket();
1.1131 + test_KErrNone(r);
1.1132 +
1.1133 + for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
1.1134 + {
1.1135 + delete iDeviceStateNotifier[portNumber];
1.1136 + delete iStallNotifier[portNumber];
1.1137 + if (portNumber == 0)
1.1138 + {
1.1139 + r = iPort[portNumber].RemoveStringDescriptor(stridx1);
1.1140 + if (r != KErrNone)
1.1141 + {
1.1142 + TUSB_PRINT1("Error %d on string removal", r);
1.1143 + }
1.1144 + r = iPort[portNumber].RemoveStringDescriptor(stridx2);
1.1145 + if (r != KErrNone)
1.1146 + {
1.1147 + TUSB_PRINT1("Error %d on string removal", r);
1.1148 + }
1.1149 + }
1.1150 + TUSB_VERBOSE_PRINT1 ("Closing USB channel number %d",portNumber);
1.1151 + iPort[portNumber].Close(); // close USB channel
1.1152 + }
1.1153 +
1.1154 + r = iPort[0].Open(0);
1.1155 + test_KErrNone(r);
1.1156 + TUSB_VERBOSE_PRINT("Successfully opened USB port");
1.1157 +
1.1158 + SetupDescriptors(iLddPtr, &iPort[0],value);
1.1159 + StartMassStorage(&iPort[0]);
1.1160 +
1.1161 + test.Next (_L("Enumeration..."));
1.1162 + r = ReEnumerate();
1.1163 + test_KErrNone(r);
1.1164 +
1.1165 +
1.1166 + test.End ();
1.1167 + break;
1.1168 + }
1.1169 + if (sendStatus)
1.1170 + {
1.1171 + r = iPort[0].SendEp0StatusPacket();
1.1172 + if (r != KErrNone)
1.1173 + {
1.1174 + TUSB_PRINT1("ActiveControl::Error %d in Ep0 Send Status Packet", r);
1.1175 + test(EFalse);
1.1176 + return KErrNone;
1.1177 + }
1.1178 + }
1.1179 + }
1.1180 + else
1.1181 + {
1.1182 + if ((iEp0SetUpPacket[KUsb_Ep0RequestOffset] == EVersion) && length > 0)
1.1183 + {
1.1184 + TUSB_PRINT4("Sending t_usb_device version: %d.%d.%d length %d \n", KDeviceVersionMajor, KDeviceVersionMinor, KDeviceVersionMicro, length);
1.1185 + #ifdef USB_SC
1.1186 + TUint8 *ep0Buffer;
1.1187 + TUint8 *ep0BufPtr;
1.1188 + TUint ep0Length;
1.1189 + iEp0Buf.GetInBufferRange(((TAny*&)ep0Buffer),ep0Length);
1.1190 +
1.1191 + ep0BufPtr = ep0Buffer;
1.1192 + *(ep0Buffer++) = KDeviceVersionMajor;
1.1193 + *(ep0Buffer++) = KDeviceVersionMinor;
1.1194 + *(ep0Buffer++) = KDeviceVersionMicro;
1.1195 + TUint8 i=3;
1.1196 + if (iConfigFileName->Length())
1.1197 + {
1.1198 + for(TUint8 j=0; j < iConfigFileName->Length() && i < length; j++)
1.1199 + {
1.1200 + i++;
1.1201 + *(ep0Buffer++) = (*iConfigFileName)[j];
1.1202 + }
1.1203 + }
1.1204 + if (iScriptFileName->Length())
1.1205 + {
1.1206 + for(TUint8 j=0; j < iScriptFileName->Length() && i < length; j++)
1.1207 + {
1.1208 + i++;
1.1209 + *(ep0Buffer++) = (*iScriptFileName)[j];
1.1210 + }
1.1211 + }
1.1212 + *(ep0Buffer++) = 0;
1.1213 + r = iEp0Buf.WriteBuffer(ep0BufPtr,length,FALSE,ep0Status);
1.1214 + test_KErrNone(r);
1.1215 + #else
1.1216 + iEp0DataBuffer.FillZ(length);
1.1217 + iEp0DataBuffer[0] = KDeviceVersionMajor;
1.1218 + iEp0DataBuffer[1] = KDeviceVersionMinor;
1.1219 + iEp0DataBuffer[2] = KDeviceVersionMicro;
1.1220 + iEp0DataBuffer.SetLength(3);
1.1221 + iEp0DataBuffer.Append (*iConfigFileName);
1.1222 + iEp0DataBuffer.Append (*iScriptFileName);
1.1223 + iEp0DataBuffer.SetLength(length);
1.1224 + iPort[0].Write(ep0Status, EEndpoint0, iEp0DataBuffer, length);
1.1225 + #endif
1.1226 + User::WaitForRequest(ep0Status);
1.1227 + test_KErrNone(ep0Status.Int());
1.1228 + }
1.1229 + else if ((iEp0SetUpPacket[KUsb_Ep0RequestOffset] == ETestIdleCounter) && length >= sizeof(TInt64))
1.1230 + {
1.1231 + // for a non zero request value if any tests still active send zero otherwise the counter value
1.1232 + TInt64 val = (value == 0 || gActiveTestCount == 0) ? iIdleCounter->iCounter : 0;
1.1233 +
1.1234 + TUSB_PRINT1("Sending counter value %Ld\n", val);
1.1235 + #ifdef USB_SC
1.1236 +
1.1237 + TUint8 *ep0Buffer;
1.1238 + TUint ep0Length;
1.1239 + iEp0Buf.GetInBufferRange(((TAny*&)ep0Buffer),ep0Length);
1.1240 +
1.1241 + *((TInt64*) ep0Buffer) = val;
1.1242 +
1.1243 + r = iEp0Buf.WriteBuffer(ep0Buffer,length,FALSE,ep0Status);
1.1244 + test_KErrNone(r);
1.1245 + #else
1.1246 +
1.1247 + iEp0DataBuffer.FillZ(length);
1.1248 + *((TInt64*) iEp0DataBuffer.Ptr()) = val;
1.1249 + iEp0DataBuffer.SetLength(sizeof(TInt64));
1.1250 + iPort[0].Write(ep0Status, EEndpoint0, iEp0DataBuffer, length);
1.1251 + #endif
1.1252 +
1.1253 + User::WaitForRequest(ep0Status);
1.1254 + test_KErrNone(ep0Status.Int());
1.1255 + }
1.1256 + }
1.1257 + if (iEp0SetUpPacket[KUsb_Ep0RequestOffset] != EStop && iEp0SetUpPacket[KUsb_Ep0RequestOffset] != ETestConnect &&
1.1258 + iEp0SetUpPacket[KUsb_Ep0RequestOffset] != ETestMassStorage)
1.1259 + {
1.1260 + return KErrCompletion;
1.1261 + }
1.1262 + }
1.1263 + else
1.1264 + {
1.1265 + TUSB_PRINT1("Error : Incorrect SetUp Packet Request Type %X", iEp0SetUpPacket[0]);
1.1266 + test(EFalse);
1.1267 + return KErrNone;
1.1268 + }
1.1269 +
1.1270 + return KErrNone;
1.1271 + }
1.1272 +
1.1273 +void CActiveControl::PrintHostLog()
1.1274 + {
1.1275 + TRequestStatus status = 0;
1.1276 + wchar_t lineBuf[128];
1.1277 + TUint j = 0;
1.1278 +
1.1279 + TUSB_VERBOSE_PRINT("Reading Host log file\n");
1.1280 +
1.1281 + #ifdef USB_SC
1.1282 + TInt r = 0;
1.1283 + TEndpointBuffer scReadBuf;
1.1284 + TAny * scReadData;
1.1285 + TUint8 * scCharPtr;
1.1286 + TUint readSize;
1.1287 + TBool readZlp = EFalse;
1.1288 +
1.1289 + r = iPort->OpenEndpoint(scReadBuf,firstBulkOutEndpoint);
1.1290 + test_KErrNone(r);
1.1291 + do
1.1292 + {
1.1293 + r = scReadBuf.GetBuffer (scReadData,readSize,readZlp,status);
1.1294 + // The following line can be reinstated once the shared chunk failure is fixed
1.1295 + // that prevents the readZlp flag from being set
1.1296 + // test_Value(r, (r == KErrNone) || (r == KErrCompletion) || (r == KErrEof));
1.1297 + if (r == KErrCompletion)
1.1298 + {
1.1299 + TUSB_VERBOSE_PRINT1("Host log file %d bytes read\n",readSize);
1.1300 + scCharPtr = (TUint8 *)scReadData;
1.1301 + // Print the host log file
1.1302 + for (TUint i = 0; i < readSize; i++)
1.1303 + {
1.1304 + if (* scCharPtr == '\r')
1.1305 + {
1.1306 + lineBuf[j++] = '\0';
1.1307 + RDebug::Print (_L("%s"),lineBuf);
1.1308 + j = 0;
1.1309 + }
1.1310 + else
1.1311 + {
1.1312 + if (* scCharPtr != '\n')
1.1313 + {
1.1314 + lineBuf[j++] = * scCharPtr;
1.1315 + }
1.1316 + }
1.1317 + scCharPtr++;
1.1318 + }
1.1319 + }
1.1320 + if (r == KErrNone)
1.1321 + {
1.1322 + User::WaitForRequest(status);
1.1323 + test_KErrNone(status.Int());
1.1324 + }
1.1325 + }
1.1326 + while (r >= KErrNone && !readZlp);
1.1327 + #else
1.1328 + TPtr8 readBuf((TUint8 *)User::Alloc(KHostLogFileSize),KHostLogFileSize,KHostLogFileSize);
1.1329 + iPort[0].ReadUntilShort(status, (TEndpointNumber)firstBulkOutEndpoint, readBuf);
1.1330 + User::WaitForRequest(status);
1.1331 + test_KErrNone(status.Int());
1.1332 + TUSB_VERBOSE_PRINT1("Host log file %d bytes read\n",readBuf.Length());
1.1333 + for (TUint i = 0; i < readBuf.Length(); i++)
1.1334 + {
1.1335 + if (readBuf[i] == '\r')
1.1336 + {
1.1337 + lineBuf[j++] = '\0';
1.1338 + RDebug::Print (_L("%s"),lineBuf);
1.1339 + j = 0;
1.1340 + }
1.1341 + else
1.1342 + {
1.1343 + if (readBuf[i] != '\n')
1.1344 + {
1.1345 + lineBuf[j++] = readBuf[i];
1.1346 + }
1.1347 + }
1.1348 + }
1.1349 + User::Free ((TAny *)readBuf.Ptr());
1.1350 + #endif
1.1351 + }
1.1352 +
1.1353 +void CActiveControl::QueryUsbClientL(LDDConfigPtr aLddPtr, RDEVCLIENT* aPort)
1.1354 + {
1.1355 + // Get device/endpoint capabilities
1.1356 + //
1.1357 + // A TPckg, or TPckBuf was not used in the following, because
1.1358 + //
1.1359 + // TPckgBuf<TUsbcEndpointData[KUsbcMaxEndpoints]> databuf;
1.1360 + //
1.1361 + // doesn't work. Also,
1.1362 + //
1.1363 + // TUsbcEndpointData data[KUsbcMaxEndpoints];
1.1364 + // TPckgBuf<TUsbcEndpointData[KUsbcMaxEndpoints]> databuf(data);
1.1365 + //
1.1366 + // doesn't work. Also,
1.1367 + //
1.1368 + // TUsbcEndpointData data[KUsbcMaxEndpoints];
1.1369 + // TPckgBuf<TUsbcEndpointData[]> databuf(data);
1.1370 + //
1.1371 + // doesn't work.
1.1372 + // So we seem to have to stick to the ugly cast below.
1.1373 + //
1.1374 + // TUsbcEndpointData data[KUsbcMaxEndpoints];
1.1375 + // TPtr8 databuf(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
1.1376 + //
1.1377 +
1.1378 + // Device
1.1379 + // === Device Descriptor
1.1380 +
1.1381 + test.Start(_L("Query device and Endpoint Capabilities"));
1.1382 +
1.1383 +
1.1384 + TUsbDeviceCaps d_caps;
1.1385 + TInt r = aPort->DeviceCaps(d_caps);
1.1386 + test_KErrNone(r);
1.1387 +
1.1388 + const TInt n = d_caps().iTotalEndpoints;
1.1389 +
1.1390 + TUSB_PRINT("### USB device capabilities:");
1.1391 + TUSB_PRINT1("Number of endpoints: %d", n);
1.1392 + TUSB_PRINT1("Supports Software-Connect: %s",
1.1393 + d_caps().iConnect ? _S("yes") : _S("no"));
1.1394 + TUSB_PRINT1("Device is Self-Powered: %s",
1.1395 + d_caps().iSelfPowered ? _S("yes") : _S("no"));
1.1396 + TUSB_PRINT1("Supports Remote-Wakeup: %s",
1.1397 + d_caps().iRemoteWakeup ? _S("yes") : _S("no"));
1.1398 + TUSB_PRINT1("Supports High-speed: %s",
1.1399 + d_caps().iHighSpeed ? _S("yes") : _S("no"));
1.1400 + TUSB_PRINT1("Supports unpowered cable detection: %s\n",
1.1401 + (d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ?
1.1402 + _S("yes") : _S("no"));
1.1403 + TUSB_PRINT("");
1.1404 +
1.1405 + iSoftwareConnect = d_caps().iConnect; // we need to remember this
1.1406 + test_Equal(aLddPtr->iSoftConnect,iSoftwareConnect);
1.1407 +
1.1408 + // only check capabilities if set; therefore allowing them to be disabled
1.1409 + if (aLddPtr->iSelfPower)
1.1410 + {
1.1411 + test(d_caps().iSelfPowered);
1.1412 + }
1.1413 +
1.1414 + // only check capabilities if set; therefore allowing them to be disabled
1.1415 + if (aLddPtr->iRemoteWakeup)
1.1416 + {
1.1417 + test(d_caps().iRemoteWakeup);
1.1418 + }
1.1419 +
1.1420 + test_Equal(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower,aLddPtr->iFeatures);
1.1421 +
1.1422 + // only check capability if set; therefore allowing it to be disabled
1.1423 + if (aLddPtr->iHighSpeed)
1.1424 + {
1.1425 + test(d_caps().iHighSpeed);
1.1426 + }
1.1427 +
1.1428 + test_Equal(aLddPtr->iNumEndpoints,n);
1.1429 +
1.1430 + // Endpoints
1.1431 + TUsbcEndpointData data[KUsbcMaxEndpoints];
1.1432 + TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
1.1433 + r = aPort->EndpointCaps(dataptr);
1.1434 + test_KErrNone(r);
1.1435 +
1.1436 + TUSB_PRINT("### USB device endpoint capabilities:");
1.1437 + for (TInt i = 0; i < n; i++)
1.1438 + {
1.1439 + const TUsbcEndpointCaps* caps = &data[i].iCaps;
1.1440 +
1.1441 +
1.1442 + TBuf<40> sizeStr(_S("unknown"));
1.1443 + if (caps->iSizes == KUsbEpNotAvailable)
1.1444 + {
1.1445 + sizeStr = _S("Not Available");
1.1446 + }
1.1447 + else
1.1448 + {
1.1449 + sizeStr.SetLength(0);
1.1450 + if (caps->iSizes & KUsbEpSizeCont)
1.1451 + sizeStr.Append(_S(" Continuous"),11);
1.1452 + if (caps->iSizes & KUsbEpSize8)
1.1453 + sizeStr.Append(_S(" 8"),2);
1.1454 + if (caps->iSizes & KUsbEpSize16)
1.1455 + sizeStr.Append(_S(" 16"),3);
1.1456 + if (caps->iSizes & KUsbEpSize32)
1.1457 + sizeStr.Append(_S(" 32"),3);
1.1458 + if (caps->iSizes & KUsbEpSize64)
1.1459 + sizeStr.Append(_S(" 64"),3);
1.1460 + if (caps->iSizes & KUsbEpSize128)
1.1461 + sizeStr.Append(_S(" 128"),4);
1.1462 + if (caps->iSizes & KUsbEpSize256)
1.1463 + sizeStr.Append(_S(" 256"),4);
1.1464 + if (caps->iSizes & KUsbEpSize512)
1.1465 + sizeStr.Append(_S(" 512"),4);
1.1466 + if (caps->iSizes & KUsbEpSize1023)
1.1467 + sizeStr.Append(_S(" 1023"),5);
1.1468 + if (caps->iSizes & KUsbEpSize1024)
1.1469 + sizeStr.Append(_S(" 1024"),5);
1.1470 + }
1.1471 +
1.1472 + TBuf<40> typeStr(_S("unknown"));
1.1473 + if (caps->iTypesAndDir == KUsbEpNotAvailable)
1.1474 + typeStr = _S("Not Available");
1.1475 + if (caps->iTypesAndDir & (KUsbEpTypeControl | KUsbEpTypeBulk | KUsbEpTypeInterrupt | KUsbEpTypeIsochronous))
1.1476 + {
1.1477 + typeStr.SetLength(0);
1.1478 + if (caps->iTypesAndDir & KUsbEpTypeBulk)
1.1479 + typeStr.Append(_S("Control "),8);
1.1480 + if (caps->iTypesAndDir & KUsbEpTypeBulk)
1.1481 + typeStr.Append(_S("Bulk "),5);
1.1482 + if (caps->iTypesAndDir & KUsbEpTypeInterrupt)
1.1483 + typeStr.Append(_S("Interrupt "),10);
1.1484 + if (caps->iTypesAndDir & KUsbEpTypeIsochronous)
1.1485 + typeStr.Append(_S("Isochronous"),11);
1.1486 + }
1.1487 +
1.1488 + TBuf<20> directionStr(_S("unknown"));
1.1489 +
1.1490 + if (caps->iTypesAndDir & KUsbEpDirIn)
1.1491 + directionStr = _S("In");
1.1492 + if (caps->iTypesAndDir & KUsbEpDirOut)
1.1493 + directionStr = _S("Out");
1.1494 + if (caps->iTypesAndDir & KUsbEpDirBidirect)
1.1495 + directionStr = _S("Both");
1.1496 +
1.1497 + TUSB_PRINT4("Endpoint:%d Sizes =%s Type = %s - %s",
1.1498 + i+1,sizeStr.PtrZ(), typeStr.PtrZ(), directionStr.PtrZ());
1.1499 + }
1.1500 + TUSB_PRINT("");
1.1501 +
1.1502 + test.End();
1.1503 +
1.1504 + }
1.1505 +
1.1506 +
1.1507 +void CActiveControl::AllocateEndpointDMA(RDEVCLIENT* aPort,TENDPOINTNUMBER aEndpoint)
1.1508 + {
1.1509 + TBool res = EFalse;
1.1510 +
1.1511 + TInt r = aPort->AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDMA);
1.1512 + if (r == KErrNone)
1.1513 + RDebug::Print(_L("DMA allocation on endpoint %d: KErrNone"), aEndpoint);
1.1514 + else if (r == KErrInUse)
1.1515 + RDebug::Print(_L("DMA allocation on endpoint %d: KErrInUse"), aEndpoint);
1.1516 + else if (r == KErrNotSupported)
1.1517 + RDebug::Print(_L("DMA allocation on endpoint %d: KErrNotSupported"), aEndpoint);
1.1518 + else
1.1519 + RDebug::Print(_L("DMA allocation on endpoint %d: unexpected return value %d"),
1.1520 + aEndpoint, r);
1.1521 + #ifdef USB_SC
1.1522 + res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
1.1523 + #else
1.1524 + res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
1.1525 + #endif
1.1526 +
1.1527 + TUSB_PRINT2("DMA on endpoint %d %s\n",
1.1528 + aEndpoint, res ? _S("allocated") : _S("not allocated"));
1.1529 +
1.1530 + if ((r == KErrNone) && !res)
1.1531 + RDebug::Print(_L("(Allocation success but negative query result: contradiction!)\n"));
1.1532 + else if ((r != KErrNone) && res)
1.1533 + RDebug::Print(_L("(Allocation failure but positive query result: contradiction!)\n"));
1.1534 + }
1.1535 +
1.1536 +
1.1537 +void CActiveControl::DeAllocateEndpointDMA(RDEVCLIENT* aPort,TENDPOINTNUMBER aEndpoint)
1.1538 + {
1.1539 + TBool res = FALSE;
1.1540 + TInt r = aPort->DeAllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDMA);
1.1541 + if (r == KErrNone)
1.1542 + RDebug::Print(_L("DMA deallocation on endpoint %d: KErrNone"), aEndpoint);
1.1543 + else if (r == KErrNotSupported)
1.1544 + RDebug::Print(_L("DMA deallocation on endpoint %d: KErrNotSupported"), aEndpoint);
1.1545 + else
1.1546 + RDebug::Print(_L("DMA deallocation on endpoint %d: unexpected return value %d"),
1.1547 + aEndpoint, r);
1.1548 + #ifdef USB_SC
1.1549 + res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
1.1550 + #else
1.1551 + res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
1.1552 + #endif
1.1553 +
1.1554 + TUSB_PRINT2("DMA on endpoint %d %s\n",
1.1555 + aEndpoint, res ? _S("allocated") : _S("not allocated"));
1.1556 + }
1.1557 +
1.1558 +#ifndef USB_SC
1.1559 +void CActiveControl::AllocateDoubleBuffering(RDEVCLIENT* aPort,TENDPOINTNUMBER aEndpoint)
1.1560 + {
1.1561 + TBool res = FALSE;
1.1562 + TInt r = aPort->AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
1.1563 + if (r == KErrNone)
1.1564 + RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrNone"), aEndpoint);
1.1565 + else if (r == KErrInUse)
1.1566 + RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrInUse"), aEndpoint);
1.1567 + else if (r == KErrNotSupported)
1.1568 + RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrNotSupported"), aEndpoint);
1.1569 + else
1.1570 + RDebug::Print(_L("Double Buffering allocation on endpoint %d: unexpected return value %d"),
1.1571 + aEndpoint, r);
1.1572 + res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
1.1573 + TUSB_PRINT2("Double Buffering on endpoint %d %s\n",
1.1574 + aEndpoint, res ? _S("allocated") : _S("not allocated"));
1.1575 +
1.1576 + if ((r == KErrNone) && !res)
1.1577 + RDebug::Print(_L("(Allocation success but negative query result: contradiction!)\n"));
1.1578 + else if ((r != KErrNone) && res)
1.1579 + RDebug::Print(_L("(Allocation failure but positive query result: contradiction!)\n"));
1.1580 + }
1.1581 +
1.1582 +
1.1583 +void CActiveControl::DeAllocateDoubleBuffering(RDEVCLIENT* aPort,TENDPOINTNUMBER aEndpoint)
1.1584 + {
1.1585 + TInt r = aPort->DeAllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
1.1586 + if (r == KErrNone)
1.1587 + RDebug::Print(_L("Double Buffering deallocation on endpoint %d: KErrNone"), aEndpoint);
1.1588 + else if (r == KErrNotSupported)
1.1589 + RDebug::Print(_L("Double Buffering deallocation on endpoint %d: KErrNotSupported"), aEndpoint);
1.1590 + else
1.1591 + RDebug::Print(_L("Double Buffering deallocation on endpoint %d: unexpected return value %d"),
1.1592 + aEndpoint, r);
1.1593 + TBool res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
1.1594 + TUSB_PRINT2("Double Buffering on endpoint %d %s\n",
1.1595 + aEndpoint, res ? _S("allocated") : _S("not allocated"));
1.1596 + }
1.1597 +
1.1598 +#endif
1.1599 +
1.1600 +TInt CActiveControl::ReEnumerate()
1.1601 + {
1.1602 + TRequestStatus enum_status;
1.1603 + iPort[0].ReEnumerate(enum_status);
1.1604 + if (!iSoftwareConnect)
1.1605 + {
1.1606 + iConsole->Printf(_L("This device does not support software\n"));
1.1607 + iConsole->Printf(_L("disconnect/reconnect\n"));
1.1608 + iConsole->Printf(_L("Please physically unplug and replug\n"));
1.1609 + iConsole->Printf(_L("the USB cable NOW... "));
1.1610 + }
1.1611 + iConsole->Printf(_L("\n>>> Start the t_usb_win program on the host <<<\n"));
1.1612 + User::WaitForRequest(enum_status);
1.1613 + if (enum_status != KErrNone)
1.1614 + {
1.1615 + TUSB_PRINT1("Error: Re-enumeration status = %d", enum_status.Int());
1.1616 + return KErrGeneral;
1.1617 + }
1.1618 + TUsbcDeviceState device_state = EUsbcDeviceStateUndefined;
1.1619 + TInt r = iPort[0].DeviceStatus(device_state);
1.1620 + if (r != KErrNone)
1.1621 + {
1.1622 + TUSB_PRINT1("Error %d on querying device state", r);
1.1623 + }
1.1624 + else
1.1625 + {
1.1626 + TUSB_PRINT1("Current device state: %s",
1.1627 + (device_state == EUsbcDeviceStateUndefined) ? _S("Undefined") :
1.1628 + ((device_state == EUsbcDeviceStateAttached) ? _S("Attached") :
1.1629 + ((device_state == EUsbcDeviceStatePowered) ? _S("Powered") :
1.1630 + ((device_state == EUsbcDeviceStateDefault) ? _S("Default") :
1.1631 + ((device_state == EUsbcDeviceStateAddress) ? _S("Address") :
1.1632 + ((device_state == EUsbcDeviceStateConfigured) ? _S("Configured") :
1.1633 + ((device_state == EUsbcDeviceStateSuspended) ? _S("Suspended") :
1.1634 + _S("Unknown"))))))));
1.1635 + }
1.1636 +
1.1637 + // Check the speed of the established physical USB connection
1.1638 + iHighSpeed = iPort[0].CurrentlyUsingHighSpeed();
1.1639 + if (iHighSpeed)
1.1640 + {
1.1641 + TUSB_PRINT("---> USB High-speed Testing\n");
1.1642 + }
1.1643 + else
1.1644 + {
1.1645 + TUSB_PRINT("---> USB Full-speed Testing\n");
1.1646 + }
1.1647 +
1.1648 + return KErrNone;
1.1649 + }
1.1650 +
1.1651 +// -eof-