First public contribution.
1 // Copyright (c) 2007-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.
19 #include <e32std_private.h>
20 #include <u32std.h> // unicode builds
22 #include <e32base_private.h>
24 #include <e32Test.h> // RTest header
26 #include <e32def_private.h>
27 #include <d32otgdi.h> // OTGDI header
28 #include <d32usbc.h> // USBCC header
30 #include "testcaseroot.h"
32 RUsbOtgDriver oUsbOtgDriver;
33 RDevUsbcClient oUsbcClient;
36 //=====================================================================================
38 /* this class wraps all OTGDI calls as well to simplify
39 calling and normalising object access. - it has no base-class hence we can use multiple-inheritance
50 TInt COtgRoot::otgLoadLdd()
54 LOG_VERBOSE2(_L("Load driver: %S\n"), &KOTGDeviceInterfaceDriverName);
59 // load ldd device drivers (load otg only, it will load the needed stuff for us)
60 TInt err(User::LoadLogicalDevice(KOTGDeviceInterfaceDriverName));
61 if ( (err != KErrNone) && (err != KErrAlreadyExists) )
63 test.Printf(_L("<Error %d> Unable to load driver: %S\n"), err, &KOTGDeviceInterfaceDriverName);
69 LOG_VERBOSE2(_L("Loaded driver: '%S' OK\n"), &KOTGDeviceInterfaceDriverName);
80 TInt COtgRoot::otgOpen()
84 LOG_VERBOSE2(_L("Opening session... loaded = %d\n"), LddLoaded());
86 TInt err(oUsbOtgDriver.Open());
89 test.Printf(_L("<Error %d> Unable to open a channel to USB OTG driver\n"),err);
94 LOG_VERBOSE1(_L("Open channel OK\n"));
103 void COtgRoot::otgClose()
107 test.Printf(_L("Closing session... loaded = %d\n"), LddLoaded());
108 oUsbOtgDriver.Close();
112 /* otgActivateOptTestMode
114 TInt COtgRoot::otgActivateOptTestMode()
118 TInt err = oUsbOtgDriver.ActivateOptTestMode();
126 TInt COtgRoot::otgStartStacks()
130 TInt err(oUsbOtgDriver.StartStacks());
144 void COtgRoot::otgStopStacks()
148 oUsbOtgDriver.StopStacks();
154 void COtgRoot::otgUnloadLdd()
157 // code to unload the OTG ldd driver
158 TInt err (User::FreeLogicalDevice(KOTGDeviceInterfaceDriverName));
168 /** otgQueueOtgEventRequest
170 void COtgRoot::otgQueueOtgEventRequest(RUsbOtgDriver::TOtgEvent& aEvent, TRequestStatus &aStatus)
173 LOG_VERBOSE2(_L("Queue an Event Request %08X.\n"), (TInt)(&aStatus));
175 oUsbOtgDriver.QueueOtgEventRequest(aEvent, aStatus);
180 /** otgCancelOtgEventRequest
182 void COtgRoot::otgCancelOtgEventRequest()
184 LOG_VERBOSE1(_L("Cancel Event Request.\n"));
185 oUsbOtgDriver.CancelOtgEventRequest();
189 /** otgQueueOtgMessageRequest
191 void COtgRoot::otgQueueOtgMessageRequest(RUsbOtgDriver::TOtgMessage& aMessage, TRequestStatus &aStatus)
194 LOG_VERBOSE2(_L("Queue a Message Request %08X.\n"), (TInt)(&aStatus));
196 //LOG_VERBOSE1(_L("Queue a Message Request.\n"));
197 oUsbOtgDriver.QueueOtgMessageRequest(aMessage, aStatus);
202 /** otgCancelOtgMessageRequest
204 void COtgRoot::otgCancelOtgMessageRequest()
206 LOG_VERBOSE1(_L("Cancel Message Request.\n"));
207 oUsbOtgDriver.CancelOtgMessageRequest();
210 void COtgRoot::otgQueuePeripheralStateRequest(TUint& aPeripheralState, TRequestStatus& aStatus)
212 LOG_VERBOSE1(_L("Queue Peripheral State Request.\n"));
213 oUsbcClient.AlternateDeviceStatusNotify(aStatus, aPeripheralState);
216 void COtgRoot::otgCancelPeripheralStateRequest()
218 LOG_VERBOSE1(_L("Cancel Peripheral State Request.\n"));
219 oUsbcClient.AlternateDeviceStatusNotifyCancel();
222 void COtgRoot::otgQueueAConnectionIdleRequest(RUsbOtgDriver::TOtgConnection& aAConnectionIdle, TRequestStatus& aStatus)
224 LOG_VERBOSE1(_L("Queue A Connection Idle Request.\n"));
225 oUsbOtgDriver.QueueOtgConnectionNotification(aAConnectionIdle, aStatus);
228 void COtgRoot::otgCancelAConnectionIdleRequest()
230 LOG_VERBOSE1(_L("Cancel A Connection Idle Request.\n"));
231 oUsbOtgDriver.CancelOtgConnectionNotification();
235 /** otgQueueOtgStateRequest
237 void COtgRoot::otgQueueOtgStateRequest(RUsbOtgDriver::TOtgState& aState, TRequestStatus &aStatus)
240 LOG_VERBOSE2(_L("Queue a State Request %08X.\n"), (TInt)(&aStatus));
242 oUsbOtgDriver.QueueOtgStateRequest(aState, aStatus);
247 /** otgCancelOtgStateRequest
249 void COtgRoot::otgCancelOtgStateRequest()
251 LOG_VERBOSE1(_L("Cancel State Request.\n"));
252 oUsbOtgDriver.CancelOtgStateRequest();
257 raise VBus (in reality this must only happen when a 'A' is present... and when not present it starts HNP)
259 TInt COtgRoot::otgBusRequest()
264 err = oUsbOtgDriver.BusRequest();
273 /* call when SRP has been recieved, based on our HNP Enable setting, this will allow HNP. The
274 * A-device may choose to call BusRequest directly, which will result in a 'short-circuit' role-swap.
276 TInt COtgRoot::otgBusRespondSRP()
280 err = oUsbOtgDriver.BusRespondSrp();
289 /** Drop VBus (A-host)
291 TInt COtgRoot::otgBusDrop()
295 err = oUsbOtgDriver.BusDrop();
305 TInt COtgRoot::otgBusClearError()
310 err = oUsbOtgDriver.BusClearError();
320 void COtgRoot::otgQueueOtgIdPinNotification(RUsbOtgDriver::TOtgIdPin& aPin, TRequestStatus& aStatus)
323 oUsbOtgDriver.QueueOtgIdPinNotification(aPin, aStatus); // the kernel driver populates aPin...
327 void COtgRoot::otgCancelOtgIdPinNotification()
330 oUsbOtgDriver.CancelOtgIdPinNotification();
334 void COtgRoot::otgQueueOtgVbusNotification(RUsbOtgDriver::TOtgVbus& aVbus,
335 TRequestStatus& aStatus
339 oUsbOtgDriver.QueueOtgVbusNotification(aVbus, aStatus);
343 void COtgRoot::otgCancelOtgVbusNotification()
346 oUsbOtgDriver.CancelOtgVbusNotification();
350 TBool COtgRoot::otgIdPinPresent()
353 TRequestStatus aStatus;
354 RUsbOtgDriver::TOtgIdPin aPin;
355 oUsbOtgDriver.QueueOtgIdPinNotification(aPin, aStatus); // the kernel driver populates aPin...
356 LOG_VERBOSE2(_L("(sync) ID_PIN=%d\n"), iOTGIdPin);
358 oUsbOtgDriver.CancelOtgIdPinNotification();
360 User::WaitForRequest(aStatus);
362 if (RUsbOtgDriver::EIdPinAPlug == aPin) // at this stage, the aPin value is known
370 TBool COtgRoot::otgVbusPresent()
373 TRequestStatus aStatus;
374 RUsbOtgDriver::TOtgVbus aVBus;
375 oUsbOtgDriver.QueueOtgVbusNotification(aVBus, aStatus); // the kernel driver populates aPin in a kernel thread...
376 oUsbOtgDriver.CancelOtgVbusNotification();
378 User::WaitForRequest(aStatus);
380 if (RUsbOtgDriver::EVbusHigh == aVBus) // by this stage, the aVBus value is known
388 TBool COtgRoot::iLoadedLdd = EFalse;
389 TBool COtgRoot::iFdfActorActive = EFalse;
390 RProcess COtgRoot::iFdfActorProcess;
393 TBool& COtgRoot::LddLoaded()
400 TBool COtgRoot::SetLoaded(TBool aState)
407 void COtgRoot::OtgEventString( RUsbOtgDriver::TOtgEvent aEvent, TBuf<MAX_DSTRLEN> &aDescription)
412 case RUsbOtgDriver::EEventAPlugInserted: aDescription= _L("A Plug Inserted");break;
413 case RUsbOtgDriver::EEventAPlugRemoved: aDescription= _L("A Plug Removed"); break;
414 case RUsbOtgDriver::EEventVbusRaised: aDescription= _L("VBUS Raised"); break;
415 case RUsbOtgDriver::EEventVbusDropped: aDescription= _L("VBUS Dropped"); break;
416 case RUsbOtgDriver::EEventSrpReceived: aDescription= _L("SRP Received"); break;
417 case RUsbOtgDriver::EEventSrpInitiated: aDescription= _L("SRP Initiated"); break;
418 case RUsbOtgDriver::EEventHnpEnabled: aDescription= _L("HNP Enabled"); break;
419 case RUsbOtgDriver::EEventHnpDisabled: aDescription= _L("HNP Disabled"); break;
420 case RUsbOtgDriver::EEventRoleChangedToHost: aDescription= _L("Role->Host"); break;
421 case RUsbOtgDriver::EEventRoleChangedToDevice: aDescription= _L("Role->Device"); break;
422 case RUsbOtgDriver::EEventRoleChangedToIdle: aDescription= _L("Role->Idle"); break;
424 case RUsbOtgDriver::EEventHnpSupported : aDescription= _L("HNP Supported"); break;
425 case RUsbOtgDriver::EEventHnpAltSupported: aDescription= _L("Alt-HNP Supp."); break;
426 case RUsbOtgDriver::EEventBusConnectionBusy: aDescription= _L("Connection Busy"); break;
427 case RUsbOtgDriver::EEventBusConnectionIdle: aDescription= _L("Connection Idle"); break;
428 default: aDescription= _L("Unknown"); break;
433 void COtgRoot::OtgStateString( RUsbOtgDriver::TOtgState aState, TBuf<MAX_DSTRLEN> &aDescription)
438 case RUsbOtgDriver::EStateReset: aDescription= _L("Reset"); break;
439 case RUsbOtgDriver::EStateAIdle: aDescription= _L("A-Idle"); break;
440 case RUsbOtgDriver::EStateAHost: aDescription= _L("A-Host"); break;
441 case RUsbOtgDriver::EStateAPeripheral: aDescription= _L("A-Peripheral"); break;
442 case RUsbOtgDriver::EStateAVbusError: aDescription= _L("A-VBus Error"); break;
443 case RUsbOtgDriver::EStateBIdle: aDescription= _L("B-Idle"); break;
444 case RUsbOtgDriver::EStateBPeripheral: aDescription= _L("B-Peripheral"); break;
445 case RUsbOtgDriver::EStateBHost: aDescription= _L("B-Host"); break;
446 default: aDescription= _L("Unknown"); break;
451 void COtgRoot::OtgMessageString( RUsbOtgDriver::TOtgMessage aMessage, TBuf<MAX_DSTRLEN> &aDescription)
456 case RUsbOtgDriver::EEventQueueOverflow: aDescription = _L("Event Queue Overflow"); break;
457 case RUsbOtgDriver::EStateQueueOverflow: aDescription = _L("State Queue Overflow"); break;
458 case RUsbOtgDriver::EMessageQueueOverflow: aDescription = _L("Message Queue Overflow"); break;
459 case RUsbOtgDriver::EMessageBadState: aDescription = _L("Bad State"); break;
460 case RUsbOtgDriver::EMessageStackNotStarted: aDescription = _L("Stack Not Started"); break;
461 case RUsbOtgDriver::EMessageVbusAlreadyRaised: aDescription = _L("Vbus Already Raised"); break;
462 case RUsbOtgDriver::EMessageSrpForbidden: aDescription = _L("SRP Forbidden"); break;
463 case RUsbOtgDriver::EMessageBusControlProblem: aDescription = _L("Bus Control Problem"); break;
464 case RUsbOtgDriver::EMessageVbusError: aDescription = _L("Vbus Error"); break;
465 case RUsbOtgDriver::EMessageSrpTimeout: aDescription = _L("SRP Timeout"); break;
466 case RUsbOtgDriver::EMessageSrpActive: aDescription = _L("SRP In Use"); break;
467 // PREQ 1305 messages
468 case RUsbOtgDriver::EMessageSrpNotPermitted: aDescription = _L("Srp Not Permitted"); break;
469 case RUsbOtgDriver::EMessageHnpNotPermitted: aDescription = _L("Hnp Not Permitted"); break;
470 case RUsbOtgDriver::EMessageHnpNotEnabled: aDescription = _L("Hnp Not Enabled"); break;
471 case RUsbOtgDriver::EMessageHnpNotSuspended: aDescription = _L("HNP not possible, not suspended"); break;
472 case RUsbOtgDriver::EMessageVbusPowerUpNotPermitted: aDescription = _L("Vbus PowerUp Not Permitted"); break;
473 case RUsbOtgDriver::EMessageVbusPowerUpError: aDescription = _L("Vbus PowerUp Error"); break;
474 case RUsbOtgDriver::EMessageVbusPowerDownNotPermitted: aDescription = _L("Vbus PowerDown Not Permitted"); break;
475 case RUsbOtgDriver::EMessageVbusClearErrorNotPermitted: aDescription = _L("Vbus ClearError Not Permitted"); break;
476 case RUsbOtgDriver::EMessageHnpNotResponding: aDescription = _L("Not reposnding to HNP");
477 case RUsbOtgDriver::EMessageHnpBusDrop: aDescription = _L("VBUS drop during HNP");
478 default: aDescription = _L("Unknown"); break;
482 void COtgRoot::PeripheralStateString( TUint aPeripheralState, TBuf<MAX_DSTRLEN> &aDescription)
484 if(aPeripheralState & KUsbAlternateSetting)
486 aDescription = _L("Interface Alternate Setting Change");
490 switch( aPeripheralState )
492 case EUsbcDeviceStateUndefined: aDescription = _L("Undefined"); break;
493 case EUsbcDeviceStateAttached: aDescription = _L("Attached"); break;
494 case EUsbcDeviceStatePowered: aDescription = _L("Powered"); break;
495 case EUsbcDeviceStateDefault: aDescription = _L("Default"); break;
496 case EUsbcDeviceStateAddress: aDescription = _L("Addressed"); break;
497 case EUsbcDeviceStateConfigured: aDescription = _L("Configured"); break;
498 case EUsbcDeviceStateSuspended: aDescription = _L("Suspended"); break;
499 case EUsbcNoState: aDescription = _L("NoState!"); break;
500 default: aDescription = _L("Unknown"); break;
505 void COtgRoot::AConnectionIdleString(RUsbOtgDriver::TOtgConnection aAConnectionIdle, TBuf<MAX_DSTRLEN> &aDescription)
507 switch( aAConnectionIdle )
509 case RUsbOtgDriver::EConnectionBusy: aDescription = _L("Busy"); break;
510 case RUsbOtgDriver::EConnectionIdle: aDescription = _L("Idle"); break;
511 case RUsbOtgDriver::EConnectionUnknown: aDescription = _L("Unknown"); break;
512 default: aDescription = _L("Not recognised");break;
516 TInt COtgRoot::otgActivateFdfActor()
520 RDebug::Print(_L("FdfActor already exists!"));
521 return KErrAlreadyExists;
524 const TUid KFdfSvrUid={0x10282B48};
525 const TUidType fdfActorUid(KNullUid, KNullUid, KFdfSvrUid);
527 RDebug::Print(_L("About to activate FDF Actor"));
529 // RProcess fdfActorProcess;
530 TInt err = iFdfActorProcess.Create(_L("t_otgdi_fdfactor.exe"), KNullDesC, fdfActorUid);
534 RDebug::Print(_L("Failed to create FDF Actor, err=%d"),err);
535 iFdfActorProcess.Close();
540 iFdfActorProcess.Rendezvous(stat);
542 if (stat!=KRequestPending)
544 RDebug::Print(_L("Failed to commence rendezvous, err=%d"),stat.Int());
545 iFdfActorProcess.Kill(0); // abort startup
546 iFdfActorProcess.Close();
551 iFdfActorProcess.Resume(); // logon OK - start the server
554 User::WaitForRequest(stat); // wait for start or death
555 if(stat.Int()!=KErrNone)
557 // Wasn't KErrNone, which means that the FDFActor didn't successfully
558 // start up. We shouldn't proceed with the test we're in.
559 RDebug::Print(_L("Failed to activate FDF Actor, err=%d"),stat.Int());
560 iFdfActorProcess.Close();
564 // We rendezvoused(?) with the FDFActor OK, so it is going to suspend
565 // any devices it sees being attached, and will shut itself down
566 // when this process signals its Rendezvous (at the end of the test)...
567 RDebug::Print(_L("Activated FDF Actor"));
568 iFdfActorActive = ETrue;
573 void COtgRoot::otgDeactivateFdfActor()
577 RDebug::Print(_L("FdfActor is not running!"));
581 // If iFdfActorActive is set, the FDF Actor should be waiting to
582 // rendezvous with us before it shuts down...
583 // First of all, logon to wait for it to close down properly
584 TRequestStatus waitForCloseStat;
585 iFdfActorProcess.Logon(waitForCloseStat);
587 // Now, trigger the FDF Actor to close down
589 RProcess::Rendezvous(KErrNone);
591 // ...and wait for it to go away.
592 User::WaitForRequest(waitForCloseStat);
593 test.Printf(_L("T_OTGDI confirms FDF Actor has gone away %d\n"), waitForCloseStat.Int());
595 // Now close our handle, and record that the process is no more...
596 iFdfActorProcess.Close();
597 iFdfActorActive = EFalse;
600 /** Commonly used step to unload the USB Client Driver
601 * @return ETrue if the ldd unloaded sucessfully
603 TBool COtgRoot::StepUnloadClient()
605 test.Printf(_L("Unload USBCC Client\n"));
611 test.Printf(_L("..Close\n"));
614 // Unload the LDD - note the name is *not* the same as for loading
616 test.Printf(_L("..Unload\n"));
617 err = User::FreeLogicalDevice( KUsbDeviceName );
620 AssertionFailed2(KErrAbort, _L("Client Unload Fail "), err);
629 /** Commonly used step to load the USB Client Driver and set up
630 * a 'useful' default device descriptor set
631 * @return ETrue if the ldd loaded sucessfully
633 TBool COtgRoot::StepLoadClient(TUint16 aPID,
634 TBool aEnableHNP/*=ETrue*/,
635 TBool aEnableSRP/*=ETrue*/)
637 test.Printf(_L("Load USBCC Client 0x%04x\n"),aPID);
641 // The incoming PID is expected to have a form of 0x0TTT or 0xFTTT
642 // where 'TTT' is the test number: if the lead is 0xF000 we now
643 // overlay an 'A' or a 'B' depending on the default role
645 if ( ( ( aPID & 0xF000 ) != 0xF000 )
646 && ( ( aPID & 0xF000 ) != 0x0000 )
649 AssertionFailed(KErrAbort, _L("Bad default PID"));
656 if ( gTestRoleMaster )
658 // this is the 'B' device
663 // this is the 'A' device
668 // Load the LDD - note the name is *not* the same as for unload
670 test.Printf(_L("..Load LDD\n"));
671 err = User::LoadLogicalDevice( KUsbcLddFileName );
672 if ((err != KErrNone) && (err !=KErrAlreadyExists))
674 AssertionFailed2(KErrAbort, _L("Client Load Fail "), err);
680 test.Printf(_L("..Open LDD\n"));
681 err = oUsbcClient.Open(0);
684 AssertionFailed2(KErrAbort, _L("Client Open Fail "), err);
688 // Set up descriptors
690 test.Printf(_L("..Setup Descriptors\n"));
692 // the OTG descriptor
693 TBuf8<KUsbDescSize_Otg> theOtgDescriptor;
694 err = oUsbcClient.GetOtgDescriptor(theOtgDescriptor);
697 AssertionFailed2(KErrAbort, _L("OTG GetDes Fail "), err);
700 // modify OTG descriptor based on parameters passed
702 aEnableSRP=ETrue; // Keep the device Legal according to OTG spec 6.4.2
704 D7…2: Reserved (reset to zero)
707 TUint8 aByte = theOtgDescriptor[2];
709 aByte |= (aEnableSRP? 1 : 0);
710 aByte |= (aEnableHNP? 2 : 0);
711 test.Printf(_L("..Change OTG 0x%02X->0x%02X\n"), theOtgDescriptor[2], aByte);
712 theOtgDescriptor[2] = aByte;
714 err = oUsbcClient.SetOtgDescriptor(theOtgDescriptor);
717 AssertionFailed2(KErrAbort, _L("OTG SetDes Fail "), err);
723 TUsbDeviceCaps d_caps;
724 err = oUsbcClient.DeviceCaps(d_caps);
725 TBool softwareConnect;
729 AssertionFailed2(KErrAbort, _L("Client DevCaps Fail "), err);
733 const TInt n = d_caps().iTotalEndpoints;
735 softwareConnect = d_caps().iConnect;
736 test.Printf(_L("..SoftwareConnect = %d\n"),softwareConnect);
740 AssertionFailed2(KErrAbort, _L("Client Endpoints Fail "), err);
745 TUsbcEndpointData data[KUsbcMaxEndpoints];
746 TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
747 err = oUsbcClient.EndpointCaps(dataptr);
750 AssertionFailed2(KErrAbort, _L("Client EpCaps Fail "), err);
754 // Set up the active interface
755 TUsbcInterfaceInfoBuf ifc;
757 TBool foundBulkIN = EFalse;
758 TBool foundBulkOUT = EFalse;
759 for (TInt i = 0; i < n; i++)
761 const TUsbcEndpointCaps* const caps = &data[i].iCaps;
762 const TInt mps = caps->MaxPacketSize();
764 (caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirIn)) ==
765 (KUsbEpTypeBulk | KUsbEpDirIn))
767 if (!(mps == 64 || mps == 512))
770 // EEndpoint1 is going to be our Tx (IN) endpoint
771 ifc().iEndpointData[0].iType = KUsbEpTypeBulk;
772 ifc().iEndpointData[0].iDir = KUsbEpDirIn;
773 ifc().iEndpointData[0].iSize = mps;
778 else if (!foundBulkOUT &&
779 (caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirOut)) ==
780 (KUsbEpTypeBulk | KUsbEpDirOut))
782 if (!(mps == 64 || mps == 512))
785 // EEndpoint2 is going to be our Rx (OUT) endpoint
786 ifc().iEndpointData[1].iType = KUsbEpTypeBulk;
787 ifc().iEndpointData[1].iDir = KUsbEpDirOut;
788 ifc().iEndpointData[1].iSize = mps;
789 foundBulkOUT = ETrue;
796 AssertionFailed2(KErrAbort, _L("Client EpFound Fail "), err);
800 _LIT16(ifcname, "T_OTGDI Test Interface (Default Setting 0)");
801 ifc().iString = const_cast<TDesC16*>(&ifcname);
802 ifc().iTotalEndpointsUsed = 2;
803 ifc().iClass.iClassNum = 0xff; // vendor-specific
804 ifc().iClass.iSubClassNum = 0xff; // vendor-specific
805 ifc().iClass.iProtocolNum = 0xff; // vendor-specific
807 err = oUsbcClient.SetInterface(0, ifc, (EUsbcBandwidthOUTDefault | EUsbcBandwidthINDefault));
809 if( err != KErrNone )
811 AssertionFailed2(KErrAbort, _L("Client SetInt Fail "), err);
815 // Set the revised PID
817 TBuf8<KUsbDescSize_Device> theDeviceDescriptor;
818 err = oUsbcClient.GetDeviceDescriptor(theDeviceDescriptor);
821 AssertionFailed2(KErrAbort, _L("Client GetDes Fail "), err);
825 TUint16 oldPID = ( theDeviceDescriptor[10] )
826 + ( theDeviceDescriptor[11] << 8 );
828 theDeviceDescriptor[10] = ( aPID & 0x00FF );
829 theDeviceDescriptor[11] = ( aPID & 0xFF00 ) >> 8;
831 test.Printf(_L("..Change PID 0x%04X->0x%04X\n"), oldPID, aPID);
833 err = oUsbcClient.SetDeviceDescriptor(theDeviceDescriptor);
836 AssertionFailed2(KErrAbort, _L("Client SetDes Fail "), err);
841 // Power Up UDC - KErrNotReady is expected
843 test.Printf(_L("..Power Up UDC\n"));
845 err = oUsbcClient.PowerUpUdc();
846 if( err != KErrNotReady )
848 AssertionFailed2(KErrAbort, _L("PowerUp UDC Fail "), err);
854 test.Printf(_L("..Connect to Host\n"));
856 err = oUsbcClient.DeviceConnectToHost();
857 if( err != KErrNone )
859 AssertionFailed2(KErrAbort, _L("Host Connect Fail "), err);
863 // Default no-problem return
869 /** Commonly used steps to control D+ connect/disconnect
870 * the device to/from the host
872 TBool COtgRoot::StepDisconnect()
874 test.Printf(_L("Disconnect from Host\n"));
878 err = oUsbcClient.DeviceDisconnectFromHost();
879 if( err != KErrNone )
881 AssertionFailed2(KErrAbort, _L("Host Disconnect Fail "), err);
885 // Default no-problem return
890 TBool COtgRoot::StepConnect()
892 test.Printf(_L("Connect to Host\n"));
896 err = oUsbcClient.DeviceConnectToHost();
897 if( err != KErrNone )
899 AssertionFailed2(KErrAbort, _L("Host Connect Fail "), err);
903 // Default no-problem return
909 /** Commonly used step to load the USB Client Driver and set up
910 * a High-Speed electrical test VID/PID pair
911 * @return ETrue if the ldd loaded sucessfully
913 TBool COtgRoot::StepChangeVidPid(TUint16 aVID, TUint16 aPID)
916 test.Printf(_L("Load USBCC HS Test Client 0x%04x/0x%04x\n"),aVID,aPID);
920 // Set the revised VID/PID pair
922 TBuf8<KUsbDescSize_Device> theDeviceDescriptor;
923 err = oUsbcClient.GetDeviceDescriptor(theDeviceDescriptor);
926 AssertionFailed2(KErrAbort, _L("Client GetDes Fail "), err);
930 TUint16 oldVID = ( theDeviceDescriptor[8] )
931 + ( theDeviceDescriptor[9] << 8 );
933 theDeviceDescriptor[8] = ( aVID & 0x00FF );
934 theDeviceDescriptor[9] = ( aVID & 0xFF00 ) >> 8;
936 test.Printf(_L("..Change VID 0x%04X->0x%04X\n"), oldVID, aVID);
938 TUint16 oldPID = ( theDeviceDescriptor[10] )
939 + ( theDeviceDescriptor[11] << 8 );
941 theDeviceDescriptor[10] = ( aPID & 0x00FF );
942 theDeviceDescriptor[11] = ( aPID & 0xFF00 ) >> 8;
944 test.Printf(_L("..Change PID 0x%04X->0x%04X\n"), oldPID, aPID);
946 err = oUsbcClient.SetDeviceDescriptor(theDeviceDescriptor);
949 AssertionFailed2(KErrAbort, _L("Client SetDes Fail "), err);
953 // Default no-problem return
959 /** Commonly used step to set a flag that will cause the
960 OPT test mode to be activated when the stacks are
963 void COtgRoot::StepSetOptActive()
969 /** Commonly used step to unload the ldd and shut it down
970 *@return ETrue if the ldd unloaded sucessfully
972 TBool COtgRoot::StepUnloadLDD()
974 test.Printf(_L("Unload otg LDD (implicit Stop() + Close()) \n"));
976 LOG_VERBOSE1(_L(" Stop OTG+Host Stack\n"));
980 LOG_VERBOSE1(_L(" Unload\n"));
983 iOptActive = EFalse; // retain the OTGDI behavour to clears this flag when client shuts
990 /** StepLoadLDD - utility method : load the LDD, open it and init the stacks
991 a commonly used test step */
992 TBool COtgRoot::StepLoadLDD()
996 LOG_VERBOSE1(_L("Load otg LDD\n"));
1000 AssertionFailed2(KErrAbort, _L("Loading LDD failed "), err);
1004 LOG_VERBOSE1(_L("Open the LDD session\n"));
1006 if (err != KErrNone)
1008 AssertionFailed2(KErrAbort, _L("Open LDD session failed "), err);
1014 test.Printf(_L("Activate OPT Test Mode\n"));
1015 err = otgActivateOptTestMode();
1016 if (err != KErrNone)
1018 AssertionFailed2(KErrAbort, _L("OPT Activate failed "), err);
1023 test.Printf(_L("Start OTG+Host Stack\n"));
1024 err = otgStartStacks();
1025 if (err != KErrNone)
1027 AssertionFailed2(KErrAbort, _L("Start stack failed "), err);
1031 // DS - Temporarily adding .1 second delay in here to beat the race
1032 // condition to be fixed as part of third part USB HOST/OTG stack issue 60761
1033 User::After(100000);
1038 void COtgRoot::SetMaxPowerToL(TUint16 aVal)
1041 TBuf8<KUsbDescSize_Config> buf;
1043 oUsbcClient.GetConfigurationDescriptor(buf);
1047 buf[8] = (TUint8)(aVal / 2);
1049 oUsbcClient.SetConfigurationDescriptor(buf);
1053 void COtgRoot::GetMaxPower(TUint16& aVal)
1055 TBuf8<KUsbDescSize_Config> buf;
1057 oUsbcClient.GetConfigurationDescriptor(buf);