First public contribution.
1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test/usb/t_usb_device/src/activecontrol.cpp
15 // USB Test Program T_USB_DEVICE, functional part.
16 // Device-side part, to work against T_USB_HOST running on the host.
22 #include "usblib.h" // Helpers
24 #include "activecontrol.h"
28 void StartMassStorage(RDEVCLIENT* aPort);
29 void StopMassStorage(RDEVCLIENT* aPort);
39 ETestDisconnect = 0x60,
40 ETestMassStorage = 0x70,
41 ETestIdleCounter = 0x80,
45 extern TBool gVerbose;
47 extern TBool gTempTest;
48 extern TBool gStopOnFail;
49 extern TBool gAltSettingOnNotify;
50 extern TInt gSoakCount;
51 extern CActiveRW* gRW[KMaxConcurrentTests]; // the USB read/write active object
52 extern IFConfigPtr gInterfaceConfig [128] [KMaxInterfaceSettings];
53 extern TInt gActiveTestCount;
58 TInt firstBulkOutEndpoint = -1;
60 _LIT(KTestIdleCounterChunkName, "TestIdleCounter");
61 _LIT(KTestIdleCounterPanic, "IdleCounter");
63 enum TTestIdleCounterPanic
65 ETestIdleCounterWrongCommand
68 enum TTestIdleCounterCommand
70 ETestIdleCounterDoNothing,
71 ETestIdleCounterReset,
75 struct TTestIdleCounter
77 volatile TInt64 iCounter;
78 volatile TTestIdleCounterCommand iCommand;
81 TInt IdleCounterThread(TAny*)
85 RThread().SetPriority(EPriorityAbsoluteVeryLow);
88 r = chunk.CreateGlobal(KTestIdleCounterChunkName,
89 sizeof(struct TTestIdleCounter),
90 sizeof(struct TTestIdleCounter) + 1);
93 struct TTestIdleCounter* counter = (struct TTestIdleCounter*) chunk.Base();
94 counter->iCounter = 0;
95 counter->iCommand = ETestIdleCounterDoNothing;
99 TInt command = counter->iCommand;
100 if (command == ETestIdleCounterReset)
102 counter->iCounter = 0;
103 counter->iCommand = ETestIdleCounterDoNothing;
105 else if (command == ETestIdleCounterClose)
109 else if (command != ETestIdleCounterDoNothing)
111 RThread().Panic(KTestIdleCounterPanic, ETestIdleCounterWrongCommand);
123 // --- class CActiveControl ---------------------------------------------------------
126 CActiveControl::CActiveControl(CConsoleBase* aConsole, TDes * aConfigFile, TDes * aScriptFile)
127 : CActive(EPriorityNormal),
129 iSoftwareConnect(EFalse),
131 iConfigFileName(aConfigFile),
132 iScriptFileName(aScriptFile),
137 CActiveControl* CActiveControl::NewLC(CConsoleBase* aConsole, TDes * aConfigFile, TDes * aScriptFile)
139 CActiveControl* self = new (ELeave) CActiveControl(aConsole, aConfigFile, aScriptFile);
140 CleanupStack::PushL(self);
146 CActiveControl* CActiveControl::NewL(CConsoleBase* aConsole, TDes * aConfigFile, TDes * aScriptFile)
148 CActiveControl* self = NewLC(aConsole, aConfigFile, aScriptFile);
154 void CActiveControl::ConstructL()
156 CActiveScheduler::Add(this);
159 User::LeaveIfError(iFs.Connect());
161 test.Start (_L("Configuration"));
163 test_Compare(iConfigFileName->Length(),!=,0);
165 iTimer.CreateLocal();
166 iPending = EPendingNone;
168 test.Next (_L("Open configuration file"));
169 // set the session path to use the ROM if no drive specified
170 r=iFs.SetSessionPath(_L("Z:\\test\\"));
173 r = iConfigFile.Open(iFs, * iConfigFileName, EFileShareReadersOnly | EFileStreamText | EFileRead);
175 TUSB_VERBOSE_PRINT1("Configuration file %s Opened successfully", iConfigFileName->PtrZ());
177 test.Next (_L("Process configuration file"));
178 test(ProcessConfigFile (iConfigFile,iConsole,&iLddPtr));
182 test.Next (_L("LDD in configuration file"));
183 test_NotNull(iLddPtr);
185 LDDConfigPtr lddPtr = iLddPtr;
187 while (lddPtr != NULL)
189 // Load logical driver (LDD)
190 // (There's no physical driver (PDD) with USB: it's a kernel extension DLL which
191 // was already loaded at boot time.)
192 test.Next (_L("Loading USB LDD"));
193 TUSB_VERBOSE_PRINT1("Loading USB LDD ",lddPtr->iName.PtrZ());
194 r = User::LoadLogicalDevice(lddPtr->iName);
195 test(r == KErrNone || r == KErrAlreadyExists);
197 IFConfigPtr ifPtr = lddPtr->iIFPtr;
199 test.Next (_L("Opening Channels"));
200 for (TInt portNumber = nextPort; portNumber < nextPort+lddPtr->iNumChannels; portNumber++)
202 test_Compare(lddPtr->iNumChannels,>,0);
205 r = iPort[portNumber].Open(0);
207 TUSB_VERBOSE_PRINT("Successfully opened USB port");
209 // Query the USB device/Setup the USB interface
210 if (portNumber == nextPort)
212 // Change some descriptors to contain suitable values
213 SetupDescriptors(lddPtr, &iPort[portNumber]);
218 QueryUsbClientL(lddPtr, &iPort[portNumber]);
223 IFConfigPtr defaultIfPtr = ifPtr;
224 SetupInterface(&ifPtr,portNumber);
227 RChunk *tChunk = &gChunk;
228 test_KErrNone(iPort[portNumber].FinalizeInterface(tChunk));
231 // allocate endpoint DMA and double buffering for all endpoints on default interface
232 for (TUint8 i = 1; i <= defaultIfPtr->iInfoPtr->iTotalEndpointsUsed; i++)
234 defaultIfPtr->iEpDMA[i-1] ? AllocateEndpointDMA(&iPort[portNumber],(TENDPOINTNUMBER)i) : DeAllocateEndpointDMA(&iPort[portNumber],(TENDPOINTNUMBER)i);
236 defaultIfPtr->iEpDoubleBuff[i-1] ? AllocateDoubleBuffering(&iPort[portNumber],(TENDPOINTNUMBER)i) : DeAllocateDoubleBuffering(&iPort[portNumber],(TENDPOINTNUMBER)i);
242 iTotalChannels += lddPtr->iNumChannels;
243 nextPort += lddPtr->iNumChannels;
244 lddPtr = lddPtr->iPtrNext;
247 TUSB_VERBOSE_PRINT("All Interfaces and Alternate Settings successfully set up");
249 test.Next (_L("Start Idle Counter Thread"));
250 r = iIdleCounterThread.Create(_L("IdleCounter"), IdleCounterThread, KDefaultStackSize, KMinHeapSize, KMinHeapSize, NULL);
252 iIdleCounterThread.Resume();
253 // Allow some time for low-priority counter process
254 User::After(100000); // 0.1 second
255 r = iIdleCounterChunk.OpenGlobal(KTestIdleCounterChunkName, EFalse);
257 iIdleCounter = (struct TTestIdleCounter*) iIdleCounterChunk.Base();
258 test_NotNull(iIdleCounter);
259 // Allow some time for low-priority counter process
260 User::After(100000); // 0.1 second
261 TInt64 val1 = iIdleCounter->iCounter;
262 User::After(1000000); // 1 second
263 TInt64 val2 = iIdleCounter->iCounter;
264 TUSB_PRINT1("Idle Counter when test inactive: %Ldinc/ms", (val2 - val1) / 1000);
266 test.Next (_L("Enumeration..."));
270 TUSB_VERBOSE_PRINT("Device successfully re-enumerated\n");
273 if (iLddPtr->iHighSpeed && !gSkip)
275 test.Next (_L("High Speed"));
279 test.Next (_L("Create Notifiers"));
280 for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
283 // Create device state active object
284 iDeviceStateNotifier[portNumber] = CActiveDeviceStateNotifier::NewL(iConsole, &iPort[portNumber], portNumber);
285 test_NotNull(iDeviceStateNotifier[portNumber]);
286 iDeviceStateNotifier[portNumber]->Activate();
287 TUSB_VERBOSE_PRINT("Created device state notifier");
289 // Create endpoint stall status active object
290 iStallNotifier[portNumber] = CActiveStallNotifier::NewL(iConsole, &iPort[portNumber]);
291 test_NotNull(iStallNotifier[portNumber]);
292 iStallNotifier[portNumber]->Activate();
293 TUSB_VERBOSE_PRINT("Created stall notifier");
295 TestInvalidSetInterface (&iPort[portNumber],iNumInterfaceSettings[portNumber]);
296 TestInvalidReleaseInterface (&iPort[portNumber],iNumInterfaceSettings[portNumber]);
300 test.Next (_L("Endpoint Zero Max Packet Sizes"));
301 TUint ep0Size = iPort[0].EndpointZeroMaxPacketSizes();
324 test_Compare(iEp0PacketSize,>,0);
326 test.Next (_L("Set Device Control"));
327 r = iPort[0].SetDeviceControl();
331 r = iPort[0].OpenEndpoint(iEp0Buf,0);
339 void CActiveControl::ReConnect()
343 test.Start (_L("Reconnecting USB"));
344 LDDConfigPtr lddPtr = iLddPtr;
346 while (lddPtr != NULL)
348 IFConfigPtr ifPtr = lddPtr->iIFPtr;
350 test.Next (_L("Opening Channels"));
351 for (TInt portNumber = nextPort; portNumber < nextPort+lddPtr->iNumChannels; portNumber++)
354 r = iPort[portNumber].Open(0);
356 TUSB_VERBOSE_PRINT("Successfully opened USB port");
358 // Query the USB device/Setup the USB interface
359 if (portNumber == nextPort)
361 // Change some descriptors to contain suitable values
362 SetupDescriptors(lddPtr, &iPort[portNumber]);
365 IFConfigPtr defaultIfPtr = ifPtr;
366 SetupInterface(&ifPtr,portNumber);
369 RChunk *tChunk = &gChunk;
370 test_KErrNone(iPort[portNumber].FinalizeInterface(tChunk));
373 // allocate endpoint DMA and double buffering for all endpoints on default interface
374 for (TUint8 i = 1; i <= defaultIfPtr->iInfoPtr->iTotalEndpointsUsed; i++)
376 defaultIfPtr->iEpDMA[i-1] ? AllocateEndpointDMA(&iPort[portNumber],(TENDPOINTNUMBER)i) : DeAllocateEndpointDMA(&iPort[portNumber],(TENDPOINTNUMBER)i);
378 defaultIfPtr->iEpDoubleBuff[i-1] ? AllocateDoubleBuffering(&iPort[portNumber],(TENDPOINTNUMBER)i) : DeAllocateDoubleBuffering(&iPort[portNumber],(TENDPOINTNUMBER)i);
383 nextPort += lddPtr->iNumChannels;
384 lddPtr = lddPtr->iPtrNext;
387 TUSB_VERBOSE_PRINT("All Interfaces and Alternate Settings successfully set up");
389 test.Next (_L("Enumeration..."));
393 TUSB_VERBOSE_PRINT("Device successfully re-enumerated\n");
395 for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
397 // Create device state active object
398 iDeviceStateNotifier[portNumber] = CActiveDeviceStateNotifier::NewL(iConsole, &iPort[portNumber], portNumber);
399 test_NotNull(iDeviceStateNotifier[portNumber]);
400 iDeviceStateNotifier[portNumber]->Activate();
401 TUSB_VERBOSE_PRINT("Created device state notifier");
403 // Create endpoint stall status active object
404 iStallNotifier[portNumber] = CActiveStallNotifier::NewL(iConsole, &iPort[portNumber]);
405 test_NotNull(iStallNotifier[portNumber]);
406 iStallNotifier[portNumber]->Activate();
407 TUSB_VERBOSE_PRINT("Created stall notifier");
411 test.Next (_L("Set Device Control"));
412 r = iPort[portNumber].SetDeviceControl();
416 r = iPort[portNumber].OpenEndpoint(iEp0Buf,0);
426 void CActiveControl::SetupInterface(IFConfigPtr* aIfPtr, TInt aPortNumber)
428 test.Start (_L("Setup Interface"));
430 // first of all set the default interface
431 TUSB_PRINT2 ("Set Default Interface with %d endpoints bandwidth 0x%x",(*aIfPtr)->iInfoPtr->iTotalEndpointsUsed,(*aIfPtr)->iBandwidthIn | (*aIfPtr)->iBandwidthOut);
433 TUsbcScInterfaceInfoBuf ifc = *((*aIfPtr)->iInfoPtr);
434 TInt r = iPort[aPortNumber].SetInterface(0, ifc);
436 TUsbcInterfaceInfoBuf ifc = *((*aIfPtr)->iInfoPtr);
437 TInt r = iPort[aPortNumber].SetInterface(0, ifc, (*aIfPtr)->iBandwidthIn | (*aIfPtr)->iBandwidthOut);
441 TBuf8<KUsbDescSize_Interface> ifDescriptor;
442 r = iPort[aPortNumber].GetInterfaceDescriptor(0, ifDescriptor);
445 // Check the interface descriptor
446 test(ifDescriptor[KIfcDesc_SettingOffset] == 0 && ifDescriptor[KIfcDesc_NumEndpointsOffset] == (*aIfPtr)->iInfoPtr->iTotalEndpointsUsed &&
447 ifDescriptor[KIfcDesc_ClassOffset] == (*aIfPtr)->iInfoPtr->iClass.iClassNum &&
448 ifDescriptor[KIfcDesc_SubClassOffset] == (*aIfPtr)->iInfoPtr->iClass.iSubClassNum &&
449 ifDescriptor[KIfcDesc_ProtocolOffset] == (*aIfPtr)->iInfoPtr->iClass.iProtocolNum);
451 if ((*aIfPtr)->iNumber != 0 && ifDescriptor[KIfcDesc_NumberOffset] != (*aIfPtr)->iNumber)
453 ifDescriptor[KIfcDesc_NumberOffset] = (*aIfPtr)->iNumber;
454 r = iPort[aPortNumber].SetInterfaceDescriptor(0, ifDescriptor);
459 (*aIfPtr)->iNumber = ifDescriptor[KIfcDesc_NumberOffset];
461 TUint8 interfaceNumber = (*aIfPtr)->iNumber;
462 TUSB_PRINT1 ("Interface Number %d",interfaceNumber);
464 // Check all endpoint descriptors
465 TBuf8<KUsbDescSize_AudioEndpoint> epDescriptor;
466 for (TUint i = 0; i < (*aIfPtr)->iInfoPtr->iTotalEndpointsUsed; i++)
470 TestEndpointDescriptor (&iPort[aPortNumber],0,i+1,(*aIfPtr)->iInfoPtr->iEndpointData[i]);
474 if (firstBulkOutEndpoint < 0 && ((*aIfPtr)->iInfoPtr->iEndpointData[i].iDir & KUsbEpDirOut) &&
475 (*aIfPtr)->iInfoPtr->iEndpointData[i].iType == KUsbEpTypeBulk)
477 firstBulkOutEndpoint = i+1;
481 TUSB_PRINT1 ("Interface number is %d",interfaceNumber);
482 (*aIfPtr)->iPortNumber = aPortNumber;
483 gInterfaceConfig [interfaceNumber] [0] = *aIfPtr;
485 TInt alternateNumber = 1;
486 // check for any alternatate interfaces and set any that are found
487 * aIfPtr = (*aIfPtr)->iPtrNext;
488 if (* aIfPtr != NULL)
490 test(SupportsAlternateInterfaces());
492 IFConfigPtr ifPtr = *aIfPtr;
493 while (ifPtr != NULL)
495 if (ifPtr->iAlternateSetting)
497 ifc = *(ifPtr->iInfoPtr);
499 TUSB_PRINT2 ("Set Alternate Interface Setting %d with %d endpoints",alternateNumber,ifPtr->iInfoPtr->iTotalEndpointsUsed);
500 r = iPort[aPortNumber].SetInterface(alternateNumber, ifc);
502 TUSB_PRINT3 ("Set Alternate Interface Setting %d with %d endpoints bandwidth 0x%x",alternateNumber,ifPtr->iInfoPtr->iTotalEndpointsUsed,ifPtr->iBandwidthIn | iLddPtr->iIFPtr->iBandwidthOut);
503 r = iPort[aPortNumber].SetInterface(alternateNumber, ifc, ifPtr->iBandwidthIn | iLddPtr->iIFPtr->iBandwidthOut);
507 r = iPort[aPortNumber].GetInterfaceDescriptor(alternateNumber, ifDescriptor);
510 // Check the interface descriptor
511 test(ifDescriptor[KIfcDesc_SettingOffset] == alternateNumber && ifDescriptor[KIfcDesc_NumEndpointsOffset] == (*aIfPtr)->iInfoPtr->iTotalEndpointsUsed &&
512 ifDescriptor[KIfcDesc_ClassOffset] == (*aIfPtr)->iInfoPtr->iClass.iClassNum &&
513 ifDescriptor[KIfcDesc_SubClassOffset] == (*aIfPtr)->iInfoPtr->iClass.iSubClassNum &&
514 ifDescriptor[KIfcDesc_ProtocolOffset] == (*aIfPtr)->iInfoPtr->iClass.iProtocolNum);
516 // Check all endpoint descriptors
517 for (TUint i = 0; i < ifPtr->iInfoPtr->iTotalEndpointsUsed; i++)
520 r = iPort[aPortNumber].GetEndpointDescriptorSize(alternateNumber, i+1, desc_size);
522 test_Equal(KUsbDescSize_Endpoint + (*aIfPtr)->iInfoPtr->iEndpointData[i].iExtra,static_cast<TUint>(desc_size));
524 r = iPort[aPortNumber].GetEndpointDescriptor(alternateNumber, i+1, epDescriptor);
527 test((((*aIfPtr)->iInfoPtr->iEndpointData[i].iDir & KUsbEpDirIn) && (epDescriptor[KEpDesc_AddressOffset] & 0x80) ||
528 !((*aIfPtr)->iInfoPtr->iEndpointData[i].iDir & KUsbEpDirIn) && !(epDescriptor[KEpDesc_AddressOffset] & 0x80)) &&
529 EpTypeMask2Value((*aIfPtr)->iInfoPtr->iEndpointData[i].iType) == (TUint)(epDescriptor[KEpDesc_AttributesOffset] & 0x03) &&
530 (*aIfPtr)->iInfoPtr->iEndpointData[i].iInterval == epDescriptor[KEpDesc_IntervalOffset]);
533 if (!gSkip && (*aIfPtr)->iInfoPtr->iEndpointData[i].iExtra)
535 test.Next(_L("Extended Endpoint Descriptor Manipulation"));
536 TUint8 addr = 0x85; // bogus address
537 if (epDescriptor[KEpDesc_SynchAddressOffset] == addr)
539 epDescriptor[KEpDesc_SynchAddressOffset] = addr;
540 r = iPort[aPortNumber].SetEndpointDescriptor(alternateNumber, i+1, epDescriptor);
543 TBuf8<KUsbDescSize_AudioEndpoint> descriptor2;
544 r = iPort[aPortNumber].GetEndpointDescriptor(alternateNumber, i+1, descriptor2);
547 test.Next(_L("Compare endpoint descriptor with value set"));
548 r = descriptor2.Compare(epDescriptor);
554 // if no error move on to the next interface
555 ifPtr->iPortNumber = aPortNumber;
556 ifPtr->iNumber = interfaceNumber;
557 gInterfaceConfig [interfaceNumber] [alternateNumber] = ifPtr;
560 ifPtr = ifPtr->iPtrNext;
569 iNumInterfaceSettings[aPortNumber] = alternateNumber;
572 TestInvalidSetInterface (&iPort[aPortNumber],iNumInterfaceSettings[aPortNumber]);
573 TestInvalidReleaseInterface (&iPort[aPortNumber],iNumInterfaceSettings[aPortNumber]);
575 TestDescriptorManipulation(iLddPtr->iHighSpeed,&iPort[aPortNumber],alternateNumber);
576 TestOtgExtensions(&iPort[aPortNumber]);
577 TestEndpoint0MaxPacketSizes(&iPort[aPortNumber]);
584 CActiveControl::~CActiveControl()
586 TUSB_PRINT("CActiveControl::~CActiveControl()");
593 while (iLddPtr->iIFPtr)
595 IFConfigPtr* ifPtrPtr = & iLddPtr->iIFPtr;
596 while ((*ifPtrPtr)->iPtrNext)
598 ifPtrPtr = &(*ifPtrPtr)->iPtrNext;
600 delete (*ifPtrPtr)->iInfoPtr->iString;
601 delete (*ifPtrPtr)->iInfoPtr;
608 LDDConfigPtr* lddPtrPtr = &iLddPtr;
609 while ((*lddPtrPtr)->iPtrNext)
611 lddPtrPtr = &(*lddPtrPtr)->iPtrNext;
613 delete (*lddPtrPtr)->iManufacturer;
614 delete (*lddPtrPtr)->iProduct;
615 delete (*lddPtrPtr)->iSerialNumber;
623 void CActiveControl::DoCancel()
625 TUSB_VERBOSE_PRINT("CActiveControl::DoCancel()");
626 iConsole->ReadCancel();
629 void CActiveControl::SetMSFinished(TBool aState)
633 if (iPending != EPendingEject)
635 iPending = EPendingEject;
636 iTimer.After(iStatus,KMSFinishedDelay);
645 if (iPending == EPendingEject)
647 iPending = EPendingCancel;
653 void CActiveControl::RequestEp0ControlPacket()
655 TUSB_VERBOSE_PRINT("CActiveControl::RequestEp0ControlPacket()");
656 // A request is issued to read a packet for endpoint 0
657 __ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 660));
662 r = iEp0Buf.GetBuffer (iEp0Packet,iEp0Size,iEp0Zlp,iStatus);
663 TUSB_VERBOSE_PRINT4("Get Buffer Return code %d Status %d PacketPtr 0x%x Size %d", r, iStatus.Int(),iEp0Packet,iEp0Size);
664 test_Value(r, (r == KErrNone) || (r == KErrCompletion) || (r == TEndpointBuffer::KStateChange) || (r == KErrAlternateSettingChanged));
665 if (r == KErrCompletion)
667 // ignore anything except a setup packet
668 if ((TInt)iEp0Size == KSetupPacketSize)
670 iEp0SetUpPacket.Copy((TUint8 *)iEp0Packet,iEp0Size);
671 r = ProcessEp0ControlPacket();
678 iPending = EPendingEp0Read;
683 while ((r == KErrCompletion) || (r == TEndpointBuffer::KStateChange) || (r == KErrAlternateSettingChanged));
685 iPort[0].ReadPacket(iStatus,EEndpoint0, iEp0SetUpPacket,KSetupPacketSize);
686 iPending = EPendingEp0Read;
691 void CActiveControl::RunL()
695 TUSB_VERBOSE_PRINT("CActiveControl::RunL()");
702 case EPendingEp0Read :
703 iPending = EPendingNone;
704 if (iStatus != KErrNone)
706 TUSB_PRINT1("ActiveControl::Error %d in Ep0 Read Packet", iStatus.Int());
710 // for shared chunks this means that data is available in the buffer
711 // but the data has yet to be transferred to a local buffer
712 RequestEp0ControlPacket();
714 if (ProcessEp0ControlPacket() == KErrCompletion)
715 RequestEp0ControlPacket();
720 iPending = EPendingNone;
721 if (iStatus != KErrNone)
723 TUSB_PRINT1("ActiveControl::Error %d in Connection Timer Delay", iStatus.Int());
726 r = iPort[0].DeviceConnectToHost();
731 RequestEp0ControlPacket();
735 iPending = EPendingNone;
736 if (iStatus != KErrNone)
738 TUSB_PRINT1("ActiveControl::Error %d in Eject Timer Delay", iStatus.Int());
741 StopMassStorage(&iPort[0]);
747 RequestEp0ControlPacket();
750 case EPendingCancel :
751 iPending = EPendingNone;
752 if (iStatus != KErrNone && iStatus != KErrCancel)
754 TUSB_PRINT1("ActiveControl::Error %d in Eject Timer Delay", iStatus.Int());
761 TInt CActiveControl::ProcessEp0ControlPacket()
763 TUint16 value = *reinterpret_cast<TUint16*>(&iEp0SetUpPacket[KUsb_Ep0wValueOffset]);
764 TUint16 index = *reinterpret_cast<TUint16*>(&iEp0SetUpPacket[KUsb_Ep0wIndexOffset]);
765 TUint16 length= *reinterpret_cast<TUint16*>(&iEp0SetUpPacket[KUsb_Ep0wLengthOffset]);
766 TUSB_VERBOSE_PRINT3("ProcessEp0ControlPacket length 0x%x value 0x%x index 0x%x",length,value,index);
767 TRequestStatus ep0Status;
768 TUint8 host_ver_major;
769 TUint8 host_ver_minor;
770 TUint8 host_ver_micro;
771 TUint8 usbio_ver_major;
772 TUint8 usbio_ver_minor;
774 TBuf8<KMaxControlPacketSize> ep0DataPacket;
777 TBool firstSettingThread = (index & KFirstSettingThreadMask) ? ETrue : EFalse;
778 TBool lastSettingThread = (index & KLastSettingThreadMask) ? ETrue : EFalse;
779 index &= ~(KFirstSettingThreadMask | KLastSettingThreadMask);
780 CActiveRW* pActiveRW;
784 if (((iEp0SetUpPacket[KUsb_Ep0RequestTypeOffset] & KUsbRequestType_DestMask) == KUsbRequestType_DestDevice) &&
785 ((iEp0SetUpPacket[KUsb_Ep0RequestTypeOffset] & KUsbRequestType_TypeMask) == KUsbRequestType_TypeClass))
787 TUSB_VERBOSE_PRINT("Received Device Directed setup packet");
788 if ((iEp0SetUpPacket[KUsb_Ep0RequestTypeOffset] & KUsbRequestType_DirMask) == KUsbRequestType_DirToDev)
790 iEp0DataBuffer.SetLength(0);
791 while (iEp0DataBuffer.Length() < length)
793 TUSB_VERBOSE_PRINT("Reading Ep0 data packet");
795 r = iEp0Buf.GetBuffer (iEp0Packet,iEp0Size,iEp0Zlp,ep0Status);
796 test_Value(r, r == KErrNone || r == KErrCompletion || (r == KErrAlternateSettingChanged));
797 while (r == KErrNone)
799 TUSB_VERBOSE_PRINT("Waiting for Ep0 data packet");
800 User::WaitForRequest(ep0Status);
801 test_KErrNone(ep0Status.Int());
802 r = iEp0Buf.GetBuffer (iEp0Packet,iEp0Size,iEp0Zlp,ep0Status);
803 test_Value(r, r == KErrNone || r == KErrCompletion || (r == KErrAlternateSettingChanged));
805 TUSB_VERBOSE_PRINT1("Ep0 data packet - size %d",iEp0Size);
806 iEp0DataBuffer.Append((TUint8 *)iEp0Packet,iEp0Size);
808 TUint16 packetLength = Min(length-iEp0DataBuffer.Length(),iEp0PacketSize);
809 iPort[0].ReadPacket(ep0Status, EEndpoint0, ep0DataPacket, packetLength);
810 User::WaitForRequest(ep0Status);
811 if (ep0Status == KErrNone)
813 iEp0DataBuffer.Append(ep0DataPacket);
817 TUSB_PRINT1("ActiveControl::Error %d in Ep0 Read Data Packet", ep0Status.Int());
823 TUSB_VERBOSE_PRINT4("Setup ToDevice Type %d length %d value %d index %d",iEp0SetUpPacket[KUsb_Ep0RequestOffset],length,value,index);
825 switch (iEp0SetUpPacket[KUsb_Ep0RequestOffset])
828 // send this now as the port will be disconnected
830 r = iPort[0].SendEp0StatusPacket();
833 if (value && firstBulkOutEndpoint > 0)
838 for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
840 // base class cancel -> calls our DoCancel
841 delete iDeviceStateNotifier[portNumber];
842 delete iStallNotifier[portNumber];
845 r = iPort[portNumber].RemoveStringDescriptor(stridx1);
848 TUSB_PRINT1("Error %d on string removal", r);
850 r = iPort[portNumber].RemoveStringDescriptor(stridx2);
853 TUSB_PRINT1("Error %d on string removal", r);
856 TUSB_VERBOSE_PRINT1 ("Closing USB channel number %d",portNumber);
857 iPort[portNumber].Close(); // close USB channel
859 TUSB_VERBOSE_PRINT("Closing Idle Counter Thread");
860 iIdleCounter->iCommand = ETestIdleCounterClose;
861 iIdleCounterChunk.Close();
862 // Allow time for low-priority thread to close
864 iIdleCounterThread.Close();
866 CActiveScheduler::Stop();
870 TUSB_PRINT("Receiving t_usb_host version");
871 host_ver_major = iEp0DataBuffer[0];
872 host_ver_minor = iEp0DataBuffer[1];
873 host_ver_micro = iEp0DataBuffer[2];
874 usbio_ver_major = iEp0DataBuffer[3];
875 usbio_ver_minor = iEp0DataBuffer[4];
876 TUSB_PRINT5("Host-side: t_usb_host v%d.%d.%d USBIO v%d.%d\n",
877 host_ver_major, host_ver_minor, host_ver_micro,
878 usbio_ver_major, usbio_ver_minor);
879 if (host_ver_major < KHostVersionMajor)
881 TUSB_PRINT1("t_usb_host version not sufficient (need at least v%d.x.x)\n",KHostVersionMajor);
885 // Just using '<' instead of the seemingly absurd '<= && !==' doesn't work without
886 // GCC compiler warning because Kxxx can also be zero (in which case there's no '<').
887 else if ((host_ver_minor <= KHostVersionMinor) &&
888 !(host_ver_minor == KHostVersionMinor))
890 TUSB_PRINT2("t_usb_host version not sufficient (need at least v%d.%d.x)\n",
891 KHostVersionMajor, KHostVersionMinor);
895 // Just using '<' instead of the seemingly absurd '<= && !==' doesn't work without
896 // GCC compiler warning because Kxxx can also be zero (in which case there's no '<').
897 else if ((host_ver_micro <= KHostVersionMicro) &&
898 !(host_ver_micro == KHostVersionMicro))
900 TUSB_PRINT3("USBRFLCT version not sufficient (need at least v%d.%d.%d)\n",
901 KHostVersionMajor, KHostVersionMinor, KHostVersionMicro);
908 tpPtr = (TestParamPtr)(&iEp0DataBuffer[0]);
909 TUSB_VERBOSE_PRINT4("Test Params - interface %d repeat %d settingRepeat %d beforeIndex %d",tpPtr->interfaceNumber,tpPtr->repeat,tpPtr->settingRepeat,tpPtr->beforeIndex);
910 if (index >= KMaxConcurrentTests)
912 TUSB_PRINT2("Test index %d is greater than maximum allowed (%d) concurrent tests",index,KMaxConcurrentTests);
916 // Create Reader/Writer active object
917 pActiveRW = CActiveRW::NewL(iConsole, &iPort[gInterfaceConfig[tpPtr->interfaceNumber][tpPtr->alternateSetting]->iPortNumber], iFs, index, lastSettingThread);
920 TUSB_PRINT("Failed to create reader/writer");
924 TUSB_VERBOSE_PRINT("Created reader/writer");
925 pActiveRW->SetTestParams(tpPtr);
929 test.Start (_L("Xml"));
933 test.Start (_L("Loop"));
934 pActiveRW->SetTransferMode(ELoop);
935 gAltSettingOnNotify = ETrue;
936 if (tpPtr->settingRepeat && !firstSettingThread)
938 pActiveRW->Suspend(ESuspend);
942 pActiveRW->StartOrSuspend();
947 test.Start (_L("Compare"));
948 pActiveRW->SetTransferMode(ELoopComp);
949 gAltSettingOnNotify = ETrue;
950 if (tpPtr->settingRepeat && !firstSettingThread)
952 pActiveRW->Suspend(ESuspend);
956 pActiveRW->StartOrSuspend();
961 test.Start (_L("Stream"));
962 if (tpPtr->outPipe > KMaxEndpointsPerClient)
964 pActiveRW->SetTransferMode(ETransmitOnly);
965 gAltSettingOnNotify = ETrue;
966 if (tpPtr->settingRepeat && !firstSettingThread)
968 pActiveRW->Suspend(ESuspend);
972 pActiveRW->StartOrSuspend();
977 pActiveRW->SetTransferMode(EReceiveOnly);
978 gAltSettingOnNotify = ETrue;
979 if (tpPtr->settingRepeat && !firstSettingThread)
981 pActiveRW->Suspend(ESuspend);
985 pActiveRW->StartOrSuspend();
991 test.Start (_L("File"));
992 // send this now as the file setup takes a long time
994 r = iPort[0].SendEp0StatusPacket();
996 if (tpPtr->outPipe > KMaxEndpointsPerClient)
998 pActiveRW->SetTransferMode(ETransmitOnly);
999 TInt maxFileSize = tpPtr->maxSize * tpPtr->repeat;
1000 pActiveRW->ReadFromDisk((TChar)tpPtr->minSize,maxFileSize);
1001 gAltSettingOnNotify = ETrue;
1002 if (tpPtr->settingRepeat && !firstSettingThread)
1004 pActiveRW->Suspend(ESuspend);
1008 pActiveRW->StartOrSuspend();
1013 pActiveRW->SetTransferMode(EReceiveOnly);
1014 pActiveRW->WriteToDisk((TChar)tpPtr->minSize);
1015 gAltSettingOnNotify = ETrue;
1016 if (tpPtr->settingRepeat && !firstSettingThread)
1018 pActiveRW->Suspend(ESuspend);
1022 pActiveRW->StartOrSuspend();
1028 TUSB_PRINT1("Invalid test value %X",value);
1032 gRW[index] = pActiveRW;
1036 TUSB_VERBOSE_PRINT2 ("Test index %d complete - value %d",index,value);
1037 // if failure, send this first to prevent panic corrupting EP0
1040 sendStatus = EFalse;
1041 r = iPort[0].SendEp0StatusPacket();
1043 if (index < KMaxConcurrentTests)
1045 if (gRW[index] != NULL)
1047 gRW[index]->TestComplete (value);
1051 if (index == KHostErrorIndex)
1055 TUSB_PRINT("Host Test Fail");
1060 TUSB_PRINT2("Invalid test index %d for result %d",index,value);
1073 test.Start (_L("Connect"));
1074 sendStatus = EFalse;
1075 r = iPort[0].SendEp0StatusPacket();
1076 if (iSoftwareConnect)
1078 r = iPort[0].DeviceDisconnectFromHost();
1081 TUint32 waitTime = (TUint32)value * 1000;
1084 waitTime = 5000; // default to 5 milliseconds
1086 iTimer.After(iStatus,waitTime);
1087 iPending = EPendingTimer;
1093 iConsole->Printf(_L("This device does not support software\n"));
1094 iConsole->Printf(_L("disconnect/reconnect\n"));
1095 iConsole->Printf(_L("Please physically unplug and replug\n"));
1096 iConsole->Printf(_L("the USB cable NOW... "));
1101 case ETestDisconnect :
1102 test.Start (_L("Disconnect"));
1103 // send this now as the port will be disconnected
1104 sendStatus = EFalse;
1105 r = iPort[0].SendEp0StatusPacket();
1106 if (iSoftwareConnect)
1108 r = iPort[0].DeviceDisconnectFromHost();
1113 iConsole->Printf(_L("This device does not support software\n"));
1114 iConsole->Printf(_L("disconnect/reconnect\n"));
1115 iConsole->Printf(_L("Please physically unplug and replug\n"));
1116 iConsole->Printf(_L("the USB cable NOW... "));
1122 case ETestMassStorage :
1123 test.Start (_L("Select Mass Storage"));
1125 // send this now as the port will be disconnected
1126 sendStatus = EFalse;
1127 r = iPort[0].SendEp0StatusPacket();
1130 for (TInt portNumber = 0; portNumber < iTotalChannels; portNumber++)
1132 delete iDeviceStateNotifier[portNumber];
1133 delete iStallNotifier[portNumber];
1134 if (portNumber == 0)
1136 r = iPort[portNumber].RemoveStringDescriptor(stridx1);
1139 TUSB_PRINT1("Error %d on string removal", r);
1141 r = iPort[portNumber].RemoveStringDescriptor(stridx2);
1144 TUSB_PRINT1("Error %d on string removal", r);
1147 TUSB_VERBOSE_PRINT1 ("Closing USB channel number %d",portNumber);
1148 iPort[portNumber].Close(); // close USB channel
1151 r = iPort[0].Open(0);
1153 TUSB_VERBOSE_PRINT("Successfully opened USB port");
1155 SetupDescriptors(iLddPtr, &iPort[0],value);
1156 StartMassStorage(&iPort[0]);
1158 test.Next (_L("Enumeration..."));
1168 r = iPort[0].SendEp0StatusPacket();
1171 TUSB_PRINT1("ActiveControl::Error %d in Ep0 Send Status Packet", r);
1179 if ((iEp0SetUpPacket[KUsb_Ep0RequestOffset] == EVersion) && length > 0)
1181 TUSB_PRINT4("Sending t_usb_device version: %d.%d.%d length %d \n", KDeviceVersionMajor, KDeviceVersionMinor, KDeviceVersionMicro, length);
1186 iEp0Buf.GetInBufferRange(((TAny*&)ep0Buffer),ep0Length);
1188 ep0BufPtr = ep0Buffer;
1189 *(ep0Buffer++) = KDeviceVersionMajor;
1190 *(ep0Buffer++) = KDeviceVersionMinor;
1191 *(ep0Buffer++) = KDeviceVersionMicro;
1193 if (iConfigFileName->Length())
1195 for(TUint8 j=0; j < iConfigFileName->Length() && i < length; j++)
1198 *(ep0Buffer++) = (*iConfigFileName)[j];
1201 if (iScriptFileName->Length())
1203 for(TUint8 j=0; j < iScriptFileName->Length() && i < length; j++)
1206 *(ep0Buffer++) = (*iScriptFileName)[j];
1210 r = iEp0Buf.WriteBuffer(ep0BufPtr,length,FALSE,ep0Status);
1213 iEp0DataBuffer.FillZ(length);
1214 iEp0DataBuffer[0] = KDeviceVersionMajor;
1215 iEp0DataBuffer[1] = KDeviceVersionMinor;
1216 iEp0DataBuffer[2] = KDeviceVersionMicro;
1217 iEp0DataBuffer.SetLength(3);
1218 iEp0DataBuffer.Append (*iConfigFileName);
1219 iEp0DataBuffer.Append (*iScriptFileName);
1220 iEp0DataBuffer.SetLength(length);
1221 iPort[0].Write(ep0Status, EEndpoint0, iEp0DataBuffer, length);
1223 User::WaitForRequest(ep0Status);
1224 test_KErrNone(ep0Status.Int());
1226 else if ((iEp0SetUpPacket[KUsb_Ep0RequestOffset] == ETestIdleCounter) && length >= sizeof(TInt64))
1228 // for a non zero request value if any tests still active send zero otherwise the counter value
1229 TInt64 val = (value == 0 || gActiveTestCount == 0) ? iIdleCounter->iCounter : 0;
1231 TUSB_PRINT1("Sending counter value %Ld\n", val);
1236 iEp0Buf.GetInBufferRange(((TAny*&)ep0Buffer),ep0Length);
1238 *((TInt64*) ep0Buffer) = val;
1240 r = iEp0Buf.WriteBuffer(ep0Buffer,length,FALSE,ep0Status);
1244 iEp0DataBuffer.FillZ(length);
1245 *((TInt64*) iEp0DataBuffer.Ptr()) = val;
1246 iEp0DataBuffer.SetLength(sizeof(TInt64));
1247 iPort[0].Write(ep0Status, EEndpoint0, iEp0DataBuffer, length);
1250 User::WaitForRequest(ep0Status);
1251 test_KErrNone(ep0Status.Int());
1254 if (iEp0SetUpPacket[KUsb_Ep0RequestOffset] != EStop && iEp0SetUpPacket[KUsb_Ep0RequestOffset] != ETestConnect &&
1255 iEp0SetUpPacket[KUsb_Ep0RequestOffset] != ETestMassStorage)
1257 return KErrCompletion;
1262 TUSB_PRINT1("Error : Incorrect SetUp Packet Request Type %X", iEp0SetUpPacket[0]);
1270 void CActiveControl::PrintHostLog()
1272 TRequestStatus status = 0;
1273 wchar_t lineBuf[128];
1276 TUSB_VERBOSE_PRINT("Reading Host log file\n");
1280 TEndpointBuffer scReadBuf;
1284 TBool readZlp = EFalse;
1286 r = iPort->OpenEndpoint(scReadBuf,firstBulkOutEndpoint);
1290 r = scReadBuf.GetBuffer (scReadData,readSize,readZlp,status);
1291 // The following line can be reinstated once the shared chunk failure is fixed
1292 // that prevents the readZlp flag from being set
1293 // test_Value(r, (r == KErrNone) || (r == KErrCompletion) || (r == KErrEof));
1294 if (r == KErrCompletion)
1296 TUSB_VERBOSE_PRINT1("Host log file %d bytes read\n",readSize);
1297 scCharPtr = (TUint8 *)scReadData;
1298 // Print the host log file
1299 for (TUint i = 0; i < readSize; i++)
1301 if (* scCharPtr == '\r')
1303 lineBuf[j++] = '\0';
1304 RDebug::Print (_L("%s"),lineBuf);
1309 if (* scCharPtr != '\n')
1311 lineBuf[j++] = * scCharPtr;
1319 User::WaitForRequest(status);
1320 test_KErrNone(status.Int());
1323 while (r >= KErrNone && !readZlp);
1325 TPtr8 readBuf((TUint8 *)User::Alloc(KHostLogFileSize),KHostLogFileSize,KHostLogFileSize);
1326 iPort[0].ReadUntilShort(status, (TEndpointNumber)firstBulkOutEndpoint, readBuf);
1327 User::WaitForRequest(status);
1328 test_KErrNone(status.Int());
1329 TUSB_VERBOSE_PRINT1("Host log file %d bytes read\n",readBuf.Length());
1330 for (TUint i = 0; i < readBuf.Length(); i++)
1332 if (readBuf[i] == '\r')
1334 lineBuf[j++] = '\0';
1335 RDebug::Print (_L("%s"),lineBuf);
1340 if (readBuf[i] != '\n')
1342 lineBuf[j++] = readBuf[i];
1346 User::Free ((TAny *)readBuf.Ptr());
1350 void CActiveControl::QueryUsbClientL(LDDConfigPtr aLddPtr, RDEVCLIENT* aPort)
1352 // Get device/endpoint capabilities
1354 // A TPckg, or TPckBuf was not used in the following, because
1356 // TPckgBuf<TUsbcEndpointData[KUsbcMaxEndpoints]> databuf;
1358 // doesn't work. Also,
1360 // TUsbcEndpointData data[KUsbcMaxEndpoints];
1361 // TPckgBuf<TUsbcEndpointData[KUsbcMaxEndpoints]> databuf(data);
1363 // doesn't work. Also,
1365 // TUsbcEndpointData data[KUsbcMaxEndpoints];
1366 // TPckgBuf<TUsbcEndpointData[]> databuf(data);
1369 // So we seem to have to stick to the ugly cast below.
1371 // TUsbcEndpointData data[KUsbcMaxEndpoints];
1372 // TPtr8 databuf(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
1376 // === Device Descriptor
1378 test.Start(_L("Query device and Endpoint Capabilities"));
1381 TUsbDeviceCaps d_caps;
1382 TInt r = aPort->DeviceCaps(d_caps);
1385 const TInt n = d_caps().iTotalEndpoints;
1387 TUSB_PRINT("### USB device capabilities:");
1388 TUSB_PRINT1("Number of endpoints: %d", n);
1389 TUSB_PRINT1("Supports Software-Connect: %s",
1390 d_caps().iConnect ? _S("yes") : _S("no"));
1391 TUSB_PRINT1("Device is Self-Powered: %s",
1392 d_caps().iSelfPowered ? _S("yes") : _S("no"));
1393 TUSB_PRINT1("Supports Remote-Wakeup: %s",
1394 d_caps().iRemoteWakeup ? _S("yes") : _S("no"));
1395 TUSB_PRINT1("Supports High-speed: %s",
1396 d_caps().iHighSpeed ? _S("yes") : _S("no"));
1397 TUSB_PRINT1("Supports unpowered cable detection: %s\n",
1398 (d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ?
1399 _S("yes") : _S("no"));
1402 iSoftwareConnect = d_caps().iConnect; // we need to remember this
1403 test_Equal(aLddPtr->iSoftConnect,iSoftwareConnect);
1405 // only check capabilities if set; therefore allowing them to be disabled
1406 if (aLddPtr->iSelfPower)
1408 test(d_caps().iSelfPowered);
1411 // only check capabilities if set; therefore allowing them to be disabled
1412 if (aLddPtr->iRemoteWakeup)
1414 test(d_caps().iRemoteWakeup);
1417 test_Equal(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower,aLddPtr->iFeatures);
1419 // only check capability if set; therefore allowing it to be disabled
1420 if (aLddPtr->iHighSpeed)
1422 test(d_caps().iHighSpeed);
1425 test_Equal(aLddPtr->iNumEndpoints,n);
1428 TUsbcEndpointData data[KUsbcMaxEndpoints];
1429 TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
1430 r = aPort->EndpointCaps(dataptr);
1433 TUSB_PRINT("### USB device endpoint capabilities:");
1434 for (TInt i = 0; i < n; i++)
1436 const TUsbcEndpointCaps* caps = &data[i].iCaps;
1439 TBuf<40> sizeStr(_S("unknown"));
1440 if (caps->iSizes == KUsbEpNotAvailable)
1442 sizeStr = _S("Not Available");
1446 sizeStr.SetLength(0);
1447 if (caps->iSizes & KUsbEpSizeCont)
1448 sizeStr.Append(_S(" Continuous"),11);
1449 if (caps->iSizes & KUsbEpSize8)
1450 sizeStr.Append(_S(" 8"),2);
1451 if (caps->iSizes & KUsbEpSize16)
1452 sizeStr.Append(_S(" 16"),3);
1453 if (caps->iSizes & KUsbEpSize32)
1454 sizeStr.Append(_S(" 32"),3);
1455 if (caps->iSizes & KUsbEpSize64)
1456 sizeStr.Append(_S(" 64"),3);
1457 if (caps->iSizes & KUsbEpSize128)
1458 sizeStr.Append(_S(" 128"),4);
1459 if (caps->iSizes & KUsbEpSize256)
1460 sizeStr.Append(_S(" 256"),4);
1461 if (caps->iSizes & KUsbEpSize512)
1462 sizeStr.Append(_S(" 512"),4);
1463 if (caps->iSizes & KUsbEpSize1023)
1464 sizeStr.Append(_S(" 1023"),5);
1465 if (caps->iSizes & KUsbEpSize1024)
1466 sizeStr.Append(_S(" 1024"),5);
1469 TBuf<40> typeStr(_S("unknown"));
1470 if (caps->iTypesAndDir == KUsbEpNotAvailable)
1471 typeStr = _S("Not Available");
1472 if (caps->iTypesAndDir & (KUsbEpTypeControl | KUsbEpTypeBulk | KUsbEpTypeInterrupt | KUsbEpTypeIsochronous))
1474 typeStr.SetLength(0);
1475 if (caps->iTypesAndDir & KUsbEpTypeBulk)
1476 typeStr.Append(_S("Control "),8);
1477 if (caps->iTypesAndDir & KUsbEpTypeBulk)
1478 typeStr.Append(_S("Bulk "),5);
1479 if (caps->iTypesAndDir & KUsbEpTypeInterrupt)
1480 typeStr.Append(_S("Interrupt "),10);
1481 if (caps->iTypesAndDir & KUsbEpTypeIsochronous)
1482 typeStr.Append(_S("Isochronous"),11);
1485 TBuf<20> directionStr(_S("unknown"));
1487 if (caps->iTypesAndDir & KUsbEpDirIn)
1488 directionStr = _S("In");
1489 if (caps->iTypesAndDir & KUsbEpDirOut)
1490 directionStr = _S("Out");
1491 if (caps->iTypesAndDir & KUsbEpDirBidirect)
1492 directionStr = _S("Both");
1494 TUSB_PRINT4("Endpoint:%d Sizes =%s Type = %s - %s",
1495 i+1,sizeStr.PtrZ(), typeStr.PtrZ(), directionStr.PtrZ());
1504 void CActiveControl::AllocateEndpointDMA(RDEVCLIENT* aPort,TENDPOINTNUMBER aEndpoint)
1508 TInt r = aPort->AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDMA);
1510 RDebug::Print(_L("DMA allocation on endpoint %d: KErrNone"), aEndpoint);
1511 else if (r == KErrInUse)
1512 RDebug::Print(_L("DMA allocation on endpoint %d: KErrInUse"), aEndpoint);
1513 else if (r == KErrNotSupported)
1514 RDebug::Print(_L("DMA allocation on endpoint %d: KErrNotSupported"), aEndpoint);
1516 RDebug::Print(_L("DMA allocation on endpoint %d: unexpected return value %d"),
1519 res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
1521 res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
1524 TUSB_PRINT2("DMA on endpoint %d %s\n",
1525 aEndpoint, res ? _S("allocated") : _S("not allocated"));
1527 if ((r == KErrNone) && !res)
1528 RDebug::Print(_L("(Allocation success but negative query result: contradiction!)\n"));
1529 else if ((r != KErrNone) && res)
1530 RDebug::Print(_L("(Allocation failure but positive query result: contradiction!)\n"));
1534 void CActiveControl::DeAllocateEndpointDMA(RDEVCLIENT* aPort,TENDPOINTNUMBER aEndpoint)
1537 TInt r = aPort->DeAllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDMA);
1539 RDebug::Print(_L("DMA deallocation on endpoint %d: KErrNone"), aEndpoint);
1540 else if (r == KErrNotSupported)
1541 RDebug::Print(_L("DMA deallocation on endpoint %d: KErrNotSupported"), aEndpoint);
1543 RDebug::Print(_L("DMA deallocation on endpoint %d: unexpected return value %d"),
1546 res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
1548 res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
1551 TUSB_PRINT2("DMA on endpoint %d %s\n",
1552 aEndpoint, res ? _S("allocated") : _S("not allocated"));
1556 void CActiveControl::AllocateDoubleBuffering(RDEVCLIENT* aPort,TENDPOINTNUMBER aEndpoint)
1559 TInt r = aPort->AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
1561 RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrNone"), aEndpoint);
1562 else if (r == KErrInUse)
1563 RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrInUse"), aEndpoint);
1564 else if (r == KErrNotSupported)
1565 RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrNotSupported"), aEndpoint);
1567 RDebug::Print(_L("Double Buffering allocation on endpoint %d: unexpected return value %d"),
1569 res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
1570 TUSB_PRINT2("Double Buffering on endpoint %d %s\n",
1571 aEndpoint, res ? _S("allocated") : _S("not allocated"));
1573 if ((r == KErrNone) && !res)
1574 RDebug::Print(_L("(Allocation success but negative query result: contradiction!)\n"));
1575 else if ((r != KErrNone) && res)
1576 RDebug::Print(_L("(Allocation failure but positive query result: contradiction!)\n"));
1580 void CActiveControl::DeAllocateDoubleBuffering(RDEVCLIENT* aPort,TENDPOINTNUMBER aEndpoint)
1582 TInt r = aPort->DeAllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
1584 RDebug::Print(_L("Double Buffering deallocation on endpoint %d: KErrNone"), aEndpoint);
1585 else if (r == KErrNotSupported)
1586 RDebug::Print(_L("Double Buffering deallocation on endpoint %d: KErrNotSupported"), aEndpoint);
1588 RDebug::Print(_L("Double Buffering deallocation on endpoint %d: unexpected return value %d"),
1590 TBool res = aPort->QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
1591 TUSB_PRINT2("Double Buffering on endpoint %d %s\n",
1592 aEndpoint, res ? _S("allocated") : _S("not allocated"));
1597 TInt CActiveControl::ReEnumerate()
1599 TRequestStatus enum_status;
1600 iPort[0].ReEnumerate(enum_status);
1601 if (!iSoftwareConnect)
1603 iConsole->Printf(_L("This device does not support software\n"));
1604 iConsole->Printf(_L("disconnect/reconnect\n"));
1605 iConsole->Printf(_L("Please physically unplug and replug\n"));
1606 iConsole->Printf(_L("the USB cable NOW... "));
1608 iConsole->Printf(_L("\n>>> Start the t_usb_win program on the host <<<\n"));
1609 User::WaitForRequest(enum_status);
1610 if (enum_status != KErrNone)
1612 TUSB_PRINT1("Error: Re-enumeration status = %d", enum_status.Int());
1615 TUsbcDeviceState device_state = EUsbcDeviceStateUndefined;
1616 TInt r = iPort[0].DeviceStatus(device_state);
1619 TUSB_PRINT1("Error %d on querying device state", r);
1623 TUSB_PRINT1("Current device state: %s",
1624 (device_state == EUsbcDeviceStateUndefined) ? _S("Undefined") :
1625 ((device_state == EUsbcDeviceStateAttached) ? _S("Attached") :
1626 ((device_state == EUsbcDeviceStatePowered) ? _S("Powered") :
1627 ((device_state == EUsbcDeviceStateDefault) ? _S("Default") :
1628 ((device_state == EUsbcDeviceStateAddress) ? _S("Address") :
1629 ((device_state == EUsbcDeviceStateConfigured) ? _S("Configured") :
1630 ((device_state == EUsbcDeviceStateSuspended) ? _S("Suspended") :
1631 _S("Unknown"))))))));
1634 // Check the speed of the established physical USB connection
1635 iHighSpeed = iPort[0].CurrentlyUsingHighSpeed();
1638 TUSB_PRINT("---> USB High-speed Testing\n");
1642 TUSB_PRINT("---> USB Full-speed Testing\n");