First public contribution.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
17 // This contains implementation for CT_RDevUsbcClientData class
23 #include "T_RDevUsbcClientData.h"
28 //LITs to identify the commands
29 _LIT(KCmdNewL, "NewL");
30 _LIT(KCmdUtilityLoadLogicalDevice, "LoadLogicalDevice");
31 _LIT(KCmdOpen, "Open");
32 _LIT(KCmdDeviceCaps, "DeviceCaps");
33 _LIT(KCmdUtilitySetEndPoint, "SetEndPoint");
34 _LIT(KCmdEndpointCaps, "EndpointCaps");
35 _LIT(KCmdSetInterface, "SetInterface");
36 _LIT(KCmdGetDeviceDescriptorSize, "GetDeviceDescriptorSize");
37 _LIT(KCmdGetDeviceDescriptor, "GetDeviceDescriptor");
38 _LIT(KCmdSetDeviceDescriptor, "SetDeviceDescriptor");
39 _LIT(KCmdDestructor, "~");
44 //LITs to read from the ini file
46 _LIT(KDirection, "direction");
47 _LIT(KBufferingMask, "bandwidthBufferingMask");
48 _LIT(KSupportsConnect, "supportsConnect");
49 _LIT(KSupportsSelfPowered, "supportsSelfPowered");
50 _LIT(KSupportsRemoteWakeup, "supportsRemoteWakeup");
51 _LIT(KUSBVersionLow, "USBVersionLow");
52 _LIT(KUSBVersionHigh, "USBVersionHigh");
53 _LIT(KVendorIDLow, "VendorIDLow");
54 _LIT(KVendorIDHigh, "VendorIDHigh");
55 _LIT(KProductIDLow, "ProductIDLow");
56 _LIT(KProductIDHigh, "ProductIDHigh");
57 _LIT(KReleaseNumberLow, "ReleaseNumberLow");
58 _LIT(KReleaseNumberHigh, "ReleaseNumberHigh");
59 _LIT(KDriver, "driver");
60 _LIT(KEXPECTED, "expected");
64 _LIT16(interfaceName, "USB interface");
68 _LIT(KResourceDMA, "ResourceDMA");
69 _LIT(KResourceDoubleBuffering, "ResourceDoubleBuffering");
71 const CDataWrapperBase::TEnumEntryTable CT_RDevUsbcClientData::iEUsbcEndpointResource[] =
73 { KResourceDMA, EUsbcEndpointResourceDMA }, // Requests the use of DMA =0
74 { KResourceDoubleBuffering, EUsbcEndpointResourceDoubleBuffering }, //Requests the use of double FIFO buffering = 1
78 * Two phase constructor
80 * @leave system wide error
82 CT_RDevUsbcClientData* CT_RDevUsbcClientData::NewL()
84 CT_RDevUsbcClientData* ret=new (ELeave) CT_RDevUsbcClientData();
85 CleanupStack::PushL(ret);
87 CleanupStack::Pop(ret);
92 * Protected constructor. First phase construction
94 CT_RDevUsbcClientData::CT_RDevUsbcClientData()
99 iConfiguredEndpoints(0),
102 iActiveCallback(NULL),
104 iBuffer_verify(NULL),
105 iDeviceDescriptorSize(0)
111 * Second phase construction
120 * @leave system wide error
122 void CT_RDevUsbcClientData::ConstructL()
124 iActiveCallback = CActiveCallback::NewL(*this);
130 CT_RDevUsbcClientData::~CT_RDevUsbcClientData()
132 // Empty arrays and delete objects
138 delete iActiveCallback;
139 iActiveCallback = NULL;
144 * RunL is called when an asynchronous call has completed
146 * @param aActive - a pointer to an active object
147 * @param aIndex - Index of the asynchronous call
150 void CT_RDevUsbcClientData::RunL(CActive* aActive, TInt aIndex)
152 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::RunL"));
153 DecOutstanding(); // One of the async calls has completed
154 TBool straySignal = EFalse;
156 if(aActive == iActiveCallback)
158 INFO_PRINTF1(_L("Asynchronous task has completed. RunL called"));
162 ERR_PRINTF1(_L("Stray RunL signal"));
163 SetBlockResult(EFail);
169 TInt err = aActive->iStatus.Int();
170 if( err != KErrNone )
172 ERR_PRINTF2(_L("RunL Error %d"), err);
173 SetAsyncError( aIndex, err );
177 INFO_PRINTF1(_L("RunL completed successfully"));
180 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::RunL"));
185 * Return a pointer to the object that the data wraps
187 * @return pointer to the object that the data wraps
189 TAny* CT_RDevUsbcClientData::GetObject()
195 * Returns the wrapper.
197 * @return pointer to the Wrapper class
203 * Process a command read from the ini file
205 * @param aCommand The command to process
206 * @param aSection The section in the ini containing data for the command
207 * @param aAsyncErrorIndex Command index for async calls to return errors to
208 * @return ETrue if the command is processed
209 * @leave System wide error
211 TBool CT_RDevUsbcClientData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
215 if(aCommand == KCmdNewL )
219 else if(aCommand == KCmdUtilityLoadLogicalDevice)
221 DoCmdUtilityLoadLogicalDevice(aSection);
223 else if(aCommand == KCmdOpen)
227 else if(aCommand == KCmdDeviceCaps)
229 DoCmdDeviceCaps(aSection);
231 else if(aCommand == KCmdGetDeviceDescriptorSize)
233 DoCmdGetDeviceDescriptorSize(aSection);
235 else if(aCommand == KCmdGetDeviceDescriptor)
237 DoCmdGetDeviceDescriptor(aSection);
239 else if(aCommand == KCmdSetDeviceDescriptor)
241 DoCmdSetDeviceDescriptor(aSection);
243 else if(aCommand == KCmdUtilitySetEndPoint)
245 DoCmdUtilitySetEndPointL(aSection);
247 else if(aCommand == KCmdEndpointCaps)
251 else if(aCommand == KCmdSetInterface)
253 DoCmdSetInterface(aSection);
255 else if(aCommand == KCmdDestructor)
261 ERR_PRINTF1(_L("Unknown command"));
271 * Creante an object of RDevUsbcClient
273 void CT_RDevUsbcClientData::DoCmdNewL()
275 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdNewL"));
277 iChannel = new (ELeave) RDevUsbcClient();
278 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdNewL"));
281 * Loads Logical Device for USB.
283 void CT_RDevUsbcClientData::DoCmdUtilityLoadLogicalDevice(const TTEFSectionName& aSection)
285 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdUtilityLoadLogicalDevice"));
286 TInt error(KErrNone);
287 TBool dataOk = ETrue;
290 if(!GetStringFromConfig(aSection, KDriver, lddName))
292 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), & KDriver);
293 SetBlockResult(EFail);
299 INFO_PRINTF2(_L("Driver: %S"), & value);
300 error = User::LoadLogicalDevice(value);
302 if(error == KErrAlreadyExists)
304 INFO_PRINTF2(_L("USB - Logical device driver loaded with %d, error will be changed to KErrNone"), error);
307 if(error != KErrNone)
309 ERR_PRINTF2(_L("USB - Could not load logical device driver. Error %d"), error);
313 INFO_PRINTF2(_L("USB - Logical device driver loaded with %d"), error);
317 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdUtilityLoadLogicalDevice"));
321 * Opens a USB channel
323 void CT_RDevUsbcClientData::DoCmdOpen()
325 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdOpen"));
326 // Open USB driver channel
327 TInt error = iChannel->Open(USB::KUSBChannelOpenParameter);
329 if (error != KErrNone)
331 ERR_PRINTF2(_L("ERROR %d when opening channel"), error);
335 INFO_PRINTF2(_L("Channel open returns: %d "), error);
339 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdOpen"));
343 * Reads device capabilities and verifies them
344 * @param aSection The section in the ini containing data for the command
346 void CT_RDevUsbcClientData::DoCmdDeviceCaps(const TTEFSectionName& aSection)
348 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdDeviceCaps"));
349 TBool supportsConnect;
350 TBool dataOk = ETrue;
351 if(!GetBoolFromConfig(aSection, KSupportsConnect, supportsConnect))
353 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSupportsConnect);
354 SetBlockResult(EFail);
358 TBool supportsSelfPowered;
359 if(!GetBoolFromConfig(aSection, KSupportsSelfPowered, supportsSelfPowered))
361 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSupportsSelfPowered);
362 SetBlockResult(EFail);
366 TBool supportsRemoteWakeup;
367 if(!GetBoolFromConfig(aSection, KSupportsRemoteWakeup, supportsRemoteWakeup))
369 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KSupportsRemoteWakeup);
370 SetBlockResult(EFail);
375 TInt error = iChannel->DeviceCaps(iCaps);
376 if (error != KErrNone)
378 ERR_PRINTF2(_L("Failed to read device caps [%d]"), error);
383 // Check that reported device capabilities are what they should be
384 INFO_PRINTF2(_L("Device supports %d endpoints"), iCaps().iTotalEndpoints );
385 INFO_PRINTF2(_L("Device supports Software-Connect: %s"), iCaps().iConnect ? _S("yes") : _S("no"));
386 if(!iCaps().iConnect && supportsConnect)
388 ERR_PRINTF1(_L("Device supports Software-Connect feature IS NOT SUPPORTED"));
389 SetBlockResult(EFail);
392 INFO_PRINTF2(_L("Device is Self-Powered: %s"), iCaps().iSelfPowered ? _S("yes") : _S("no"));
393 if(!iCaps().iSelfPowered && supportsSelfPowered)
395 ERR_PRINTF1(_L("Device is Self-Powered feature IS NOT SUPPORTED"));
396 SetBlockResult(EFail);
399 INFO_PRINTF2(_L("Device supports Remote-Wakeup: %s"),iCaps().iRemoteWakeup ? _S("yes") : _S("no"));
400 if(!iCaps().iRemoteWakeup && supportsRemoteWakeup)
402 ERR_PRINTF1(_L("Device supports Remote-Wakeup feature IS NOT SUPPORTED"));
403 SetBlockResult(EFail);
407 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdDeviceCaps"));
411 * Reads device endpoint capabilities and prints them
413 void CT_RDevUsbcClientData::DoCmdEndpointCaps()
415 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdEndpointCaps"));
416 TPtr8 endpointData(reinterpret_cast<TUint8*>(iEndpointData), sizeof(iEndpointData), sizeof(iEndpointData));
417 TInt error = iChannel->EndpointCaps(endpointData);
419 if (error != KErrNone)
421 ERR_PRINTF2(_L("Failed to read endpoint caps [%d]"), error);
426 INFO_PRINTF1(_L("User endpoint capabilities:"));
427 for (TInt i = 0; i < iCaps().iTotalEndpoints; i++)
429 const TUsbcEndpointCaps* caps = &iEndpointData[i].iCaps;
430 INFO_PRINTF4(_L("Endpoint %02d: MaxPackeSize=%s TypeDirM = 0x%08x "),
432 (caps->iSizes & KUsbEpSizeCont ) ? _S("Continuous") :
433 ((caps->iSizes & KUsbEpSize8) ? _S("8 bytes") :
434 ((caps->iSizes & KUsbEpSize16) ? _S("16 bytes") :
435 ((caps->iSizes & KUsbEpSize32) ? _S("32 bytes") :
436 ((caps->iSizes & KUsbEpSize64) ? _S("64 bytes") :
437 ((caps->iSizes & KUsbEpSize128) ? _S("128 bytes") :
438 ((caps->iSizes & KUsbEpSize256) ? _S("256 bytes") :
439 ((caps->iSizes & KUsbEpSize512) ? _S("512 bytes") :
440 ((caps->iSizes & KUsbEpSize1023) ? _S("1023 bytes") :
441 ((caps->iSizes & KUsbEpSize1024) ? _S("1024 bytes") :
442 _S("Unknown")))))))))),
446 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdEndpointCaps"));
451 * Inits USB Device Descriptors - Get the device descriptor size
454 void CT_RDevUsbcClientData::DoCmdGetDeviceDescriptorSize(const TTEFSectionName& aSection)
456 // Read the size of the descriptors and create buffer to store them.
457 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdGetDeviceDescriptorSize"));
459 if(!GetIntFromConfig(aSection, KEXPECTED, expected))
461 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KEXPECTED);
462 SetBlockResult(EFail);
466 iDeviceDescriptorSize = 0;
467 INFO_PRINTF1(_L("Initializing device descriptors"));
468 INFO_PRINTF1(_L("void CT_RDevUsbcClientData::GetDeviceDescriptorSize() BEGIN"));
469 iChannel->GetDeviceDescriptorSize(iDeviceDescriptorSize);
471 if(expected != iDeviceDescriptorSize)
473 ERR_PRINTF3(_L("Expected size != actual size, expected = %d, actual = %d "),expected, iDeviceDescriptorSize);
474 SetBlockResult(EFail);
477 // initialize buffer which used to verify.
480 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdGetDeviceDescriptorSize"));
484 * Inits USB Device Descriptors - Get device descriptor
487 void CT_RDevUsbcClientData::DoCmdGetDeviceDescriptor(const TTEFSectionName& aSection)
489 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdGetDeviceDescriptor"));
491 //initialize descriptor buffer.
492 TRAPD(error, iBuffer = HBufC8::NewL(iDeviceDescriptorSize));
493 if(error != KErrNone || !iBuffer)
495 ERR_PRINTF2(_L("Failed to initialize device descriptor [%d]"),error);
498 TRAPD(error2, iBuffer_verify = HBufC8::NewL(iDeviceDescriptorSize));
499 if(error2 != KErrNone || !iBuffer_verify)
501 ERR_PRINTF2(_L("Failed to initialize device descriptor [%d]"),error2);
506 TPtr8 devDescrPtr = iBuffer->Des();
507 // Read the current descriptors.
508 err = iChannel->GetDeviceDescriptor(devDescrPtr);
511 ERR_PRINTF2(_L("Failed to get the device descriptor [%d]"),err);
515 // Read descriptors from ini and compare.
517 TBool dataOk = ETrue;
518 if(!GetIntFromConfig(aSection, KUSBVersionLow, USBVersionLow))
520 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KUSBVersionLow);
521 SetBlockResult(EFail);
525 if(!GetIntFromConfig(aSection, KUSBVersionHigh, USBVersionHigh))
527 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KUSBVersionHigh);
528 SetBlockResult(EFail);
532 if(!GetIntFromConfig(aSection, KVendorIDLow, VendorIDLow))
534 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVendorIDLow);
535 SetBlockResult(EFail);
539 if(!GetIntFromConfig(aSection, KVendorIDHigh, VendorIDHigh))
541 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVendorIDHigh);
542 SetBlockResult(EFail);
545 // product ID for test device
547 if(!GetIntFromConfig(aSection, KProductIDLow, ProductIDLow))
549 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KProductIDLow);
550 SetBlockResult(EFail);
554 if(!GetIntFromConfig(aSection, KProductIDHigh, ProductIDHigh))
556 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KProductIDHigh);
557 SetBlockResult(EFail);
561 TInt ReleaseNumberLow;
562 if(!GetIntFromConfig(aSection, KReleaseNumberLow, ReleaseNumberLow))
564 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KReleaseNumberLow);
565 SetBlockResult(EFail);
568 TInt ReleaseNumberHigh;
569 if(!GetIntFromConfig(aSection, KReleaseNumberHigh, ReleaseNumberHigh))
571 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KReleaseNumberHigh);
572 SetBlockResult(EFail);
575 // Device descriptor data is presented in bytes (Little endian)
576 // defined in the .ini file
577 // The following presents numeric values device uses to introduce
578 // herself to USB host in enumeration process
581 TPtr8 devDescrPtr_verify = iBuffer_verify->Des();
582 err = iChannel->GetDeviceDescriptor(devDescrPtr_verify);
585 ERR_PRINTF2(_L("Failed to get the device descriptor [%d]"),err);
589 devDescrPtr_verify[USB::KSpecOffset] = USBVersionLow;
590 devDescrPtr_verify[USB::KSpecOffset + 1] = USBVersionHigh;
592 devDescrPtr_verify[USB::KVendorOffset] = VendorIDLow;
593 devDescrPtr_verify[USB::KVendorOffset + 1] = VendorIDHigh;
595 // product ID for test device
596 devDescrPtr_verify[USB::KProductIDOffset] = ProductIDLow;
597 devDescrPtr_verify[USB::KProductIDOffset + 1] = ProductIDHigh;
599 // Set release number
600 devDescrPtr_verify[USB::KReleaseOffset] = ReleaseNumberLow;
601 devDescrPtr_verify[USB::KReleaseOffset + 1] = ReleaseNumberHigh;
603 if(devDescrPtr != devDescrPtr_verify)
605 ERR_PRINTF1(_L("Expected DeviceDescriptor is not the same as actual. "));
606 SetBlockResult(EFail);
612 delete iBuffer_verify;
613 iBuffer_verify = NULL;
615 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdGetDeviceDescriptor"));
619 * Inits USB Device Descriptors - Set device descriptor
620 * @param aSection - The section in the ini containing data for the command
622 void CT_RDevUsbcClientData::DoCmdSetDeviceDescriptor(const TTEFSectionName& aSection)
625 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdSetDeviceDescriptor"));
627 iDeviceDescriptorSize = 0;
628 INFO_PRINTF1(_L("Initializing device descriptors"));
629 iChannel->GetDeviceDescriptorSize(iDeviceDescriptorSize);
630 INFO_PRINTF2(_L("Device descriptor size = %d"), iDeviceDescriptorSize);
632 //initialize descriptor buffer.
633 TRAPD(err, iBuffer = HBufC8::NewL(iDeviceDescriptorSize));
634 if(err != KErrNone || !iBuffer)
636 ERR_PRINTF2(_L("Failed to initialize device descriptor [%d]"),err);
642 TBool dataOk = ETrue;
643 if(!GetIntFromConfig(aSection, KUSBVersionLow, USBVersionLow))
645 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KUSBVersionLow);
646 SetBlockResult(EFail);
650 if(!GetIntFromConfig(aSection, KUSBVersionHigh, USBVersionHigh))
652 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KUSBVersionHigh);
653 SetBlockResult(EFail);
658 if(!GetIntFromConfig(aSection, KVendorIDLow, VendorIDLow))
660 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVendorIDLow);
661 SetBlockResult(EFail);
665 if(!GetIntFromConfig(aSection, KVendorIDHigh, VendorIDHigh))
667 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KVendorIDHigh);
668 SetBlockResult(EFail);
671 // product ID for test device
673 if(!GetIntFromConfig(aSection, KProductIDLow, ProductIDLow))
675 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KProductIDLow);
676 SetBlockResult(EFail);
680 if(!GetIntFromConfig(aSection, KProductIDHigh, ProductIDHigh))
682 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KProductIDHigh);
683 SetBlockResult(EFail);
687 TInt ReleaseNumberLow;
688 if(!GetIntFromConfig(aSection, KReleaseNumberLow, ReleaseNumberLow))
690 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KReleaseNumberLow);
691 SetBlockResult(EFail);
694 TInt ReleaseNumberHigh;
695 if(!GetIntFromConfig(aSection, KReleaseNumberHigh, ReleaseNumberHigh))
697 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KReleaseNumberHigh);
698 SetBlockResult(EFail);
701 // Device descriptor data is presented in bytes (Little endian)
702 // defined in the .ini file
703 // The following presents numeric values device uses to introduce
704 // herself to USB host in enumeration process
707 TPtr8 devDescrPtr = iBuffer->Des();
708 devDescrPtr.FillZ(devDescrPtr.MaxLength());
711 devDescrPtr[USB::KSpecOffset] = USBVersionLow;
712 devDescrPtr[USB::KSpecOffset + 1] = USBVersionHigh;
714 devDescrPtr[USB::KVendorOffset] = VendorIDLow;
715 devDescrPtr[USB::KVendorOffset + 1] = VendorIDHigh;
717 // product ID for test device
718 devDescrPtr[USB::KProductIDOffset] = ProductIDLow;
719 devDescrPtr[USB::KProductIDOffset + 1] = ProductIDHigh;
721 // Set release number
722 devDescrPtr[USB::KReleaseOffset] = ReleaseNumberLow;
723 devDescrPtr[USB::KReleaseOffset + 1] = ReleaseNumberHigh;
725 INFO_PRINTF1(_L("Setting device descriptors"));
726 // Store the descriptors.
727 error = iChannel->SetDeviceDescriptor(devDescrPtr);
728 if (error != KErrNone)
730 ERR_PRINTF2(_L("Failed to set the device descriptor [%d]"),error);
740 INFO_PRINTF1(_L("Device descriptors set"));
742 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdSetDeviceDescriptor"));
747 * @param aSection - The section in the ini containing data for the command
750 void CT_RDevUsbcClientData::DoCmdUtilitySetEndPointL(const TTEFSectionName& aSection)
752 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdUtilitySetEndPointL"));
754 TBool dataOk = ETrue;
755 if(!GetStringFromConfig(aSection, KMode, mode))
757 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KMode);
758 SetBlockResult(EFail);
762 if(!GetStringFromConfig(aSection, KDirection, direction))
764 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KDirection);
765 SetBlockResult(EFail);
770 TInt error(KErrNone);
771 if(mode == USB::KEPBulk)
773 INFO_PRINTF1(_L("Selected mode is KEPBulk"));
774 if(direction == USB::KEPIn)
776 error = SetEndpoint(KUsbEpTypeBulk, KUsbEpDirIn);
777 if (error != KErrNone)
779 ERR_PRINTF2(_L("Failed to set end point direction to KEPIn with error [%d]"), error);
780 SetBlockResult(EFail);
783 else if(direction == USB::KEPOut)
785 error = SetEndpoint(KUsbEpTypeBulk, KUsbEpDirOut);
786 if (error != KErrNone)
788 ERR_PRINTF2(_L("Failed to set end point direction to KEPOut with error [%d]"), error);
789 SetBlockResult(EFail);
794 ERR_PRINTF2(_L("USB - INCORRECT direction %S"), direction.AllocL());
795 SetBlockResult(EFail);
798 else if(mode == USB::KEPInterrupt)
800 INFO_PRINTF1(_L("Selected mode is KEPInterrupt"));
801 if(direction == USB::KEPIn)
803 error = SetEndpoint(KUsbEpTypeInterrupt, KUsbEpDirIn);
804 if (error != KErrNone)
806 ERR_PRINTF2(_L("Failed to set end point direction to KEPIn with error [%d]"), error);
807 SetBlockResult(EFail);
810 else if(direction == USB::KEPOut)
812 error = SetEndpoint(KUsbEpTypeInterrupt, KUsbEpDirOut);
813 if (error != KErrNone)
815 ERR_PRINTF2(_L("Failed to set end point direction to KEPOut with error [%d]"), error);
816 SetBlockResult(EFail);
821 ERR_PRINTF2(_L("USB - INCORRECT direction %S"), direction.AllocL());
822 SetBlockResult(EFail);
827 ERR_PRINTF2(_L("USB - Mode not supported %S"), mode.AllocL());
828 SetBlockResult(EFail);
831 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdUtilitySetEndPointL"));
836 * Sets a new endpoint for interface handled by this channel
837 * @param aEndpointType - USB endpoint type
838 * @param aEndpointDirection - USB endpoint direction
840 TInt CT_RDevUsbcClientData::SetEndpoint(TUint aEndpointType, TUint aEndpointDirection)
842 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::SetEndpoint"));
843 if(iConfiguredEndpoints == KMaxEndpointsPerClient)
845 ERR_PRINTF2(_L("Maximum number of endpoints [%d] for clients reached "), KMaxEndpointsPerClient);
846 SetBlockResult(EFail);
850 // search for the endpoints that match the settings user has given.
851 for (TInt i = 0; i < iCaps().iTotalEndpoints; ++i)
853 const TUsbcEndpointCaps* caps = &iEndpointData[i].iCaps;
854 const TInt maximumPacketSize = caps->MaxPacketSize();
856 // Check if endpoint in question matches with parameters we want to use for configuring an endpoint
857 if ( (caps->iTypesAndDir & (aEndpointType | aEndpointDirection)) == (aEndpointType | aEndpointDirection) )
859 INFO_PRINTF3(_L("Configuring %s endpoint with direction %s"),
860 (aEndpointType == KUsbEpTypeControl) ? _S("Control") :
861 ((aEndpointType == KUsbEpTypeIsochronous) ? _S("Isochronous") :
862 ((aEndpointType == KUsbEpTypeBulk) ? _S("Bulk") :
863 ((aEndpointType == KUsbEpTypeInterrupt) ? _S("Interrupt") :
865 (aEndpointDirection == KUsbEpDirIn) ? _S("In") :
866 ((aEndpointDirection == KUsbEpDirOut) ? _S("Out") :
867 ((aEndpointDirection == KUsbEpDirBidirect) ? _S("Bidirectional") :
871 iInterface().iEndpointData[iConfiguredEndpoints].iType = aEndpointType;
872 iInterface().iEndpointData[iConfiguredEndpoints].iDir = aEndpointDirection;
873 iInterface().iEndpointData[iConfiguredEndpoints].iSize = maximumPacketSize;
874 iTxMaxPacketSize = maximumPacketSize;
876 iConfiguredEndpoints++;
882 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::SetEndpoint"));
889 * Sets interface with endpoints configured with CT_RDevUsbcClientData::SetEndpoint
890 * Note that endpoints must be set before calling this method
892 * @param aBandwithwidthBufferingMask TInt contains IN and OUT bandwidth buffering masks combined
893 * using binary OR operation
894 * NOTE: IT IS TEST CASE SCRIPTERS RESPONSIBILITY TO CHECK VALID (or invalid for negative cases) MASKS
896 void CT_RDevUsbcClientData::DoCmdSetInterface(const TTEFSectionName& aSection)
898 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdSetInterface"));
899 TInt bandwidthBufferingMask;
900 TBool dataOk = ETrue;
901 if(!GetIntFromConfig(aSection, KBufferingMask, bandwidthBufferingMask))
903 ERR_PRINTF2(_L("Error in getting parameter %S from INI file"), &KBufferingMask);
904 SetBlockResult(EFail);
909 INFO_PRINTF2(_L("bandwidthBufferingMask %d"), bandwidthBufferingMask);
910 INFO_PRINTF2(_L("Configuring the interface settings with %d endpoints"), iConfiguredEndpoints);
912 if( iConfiguredEndpoints == 0 )
914 ERR_PRINTF1(_L("No endpoints have been set! Set endpoints before configuring interface"));
915 SetBlockResult(EFail);
919 HBufC16* allocatedName = 0;
920 TRAPD(error, allocatedName = interfaceName().AllocL());
921 if (error != KErrNone)
923 ERR_PRINTF2(_L("AllocL failed [%d]"), error);
924 SetBlockResult(EFail);
928 iInterface().iString = allocatedName;
929 iInterface().iTotalEndpointsUsed = iConfiguredEndpoints;
930 iInterface().iClass.iClassNum = 0xff;
931 iInterface().iClass.iSubClassNum = 0xff;
932 iInterface().iClass.iProtocolNum = 0xff;
933 INFO_PRINTF2(_L("Using bandwidth buffering mask 0x%08x"), bandwidthBufferingMask);
935 error = iChannel->SetInterface(0, iInterface, bandwidthBufferingMask);
937 delete allocatedName;
938 allocatedName = NULL;
940 if (error != KErrNone)
942 ERR_PRINTF2(_L("Failed to set the interface [%d]"), error);
945 INFO_PRINTF2(_L("SetInterface returns [%d]"), error);
949 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdSetInterface"));
956 * Tell test class to stop waiting
957 * @param result from callback
959 void CT_RDevUsbcClientData::Signal(TInt aResult)
961 INFO_PRINTF2(_L("Signal %d"),aResult);
969 void CT_RDevUsbcClientData::DoCmdDestructor()
971 INFO_PRINTF1(_L("*START*CT_RDevUsbcClientData::DoCmdDestructor"));
973 INFO_PRINTF1(_L("*END*CT_RDevUsbcClientData::DoCmdDestructor"));
976 void CT_RDevUsbcClientData::DestroyData()