usbmgmt/usbmgr/usbman/server/SRC/CUsbDevice.cpp
changeset 26 f3a1ae528dee
parent 25 4ddb65515edd
child 29 59aa7d6e3e0f
equal deleted inserted replaced
25:4ddb65515edd 26:f3a1ae528dee
     1 /*
     1 /*
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 1997-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    19 
    19 
    20 /**
    20 /**
    21  @file
    21  @file
    22 */
    22 */
    23 
    23 
    24 #include "CUsbDevice.h"
       
    25 #include "CUsbDeviceStateWatcher.h"
       
    26 #include <cusbclasscontrolleriterator.h>
    24 #include <cusbclasscontrolleriterator.h>
    27 #include "MUsbDeviceNotify.h"
       
    28 #include "UsbSettings.h"
       
    29 #include "CUsbServer.h"
       
    30 #include <cusbclasscontrollerbase.h>
    25 #include <cusbclasscontrollerbase.h>
    31 #include <cusbclasscontrollerplugin.h>
    26 #include <cusbclasscontrollerplugin.h>
    32 #include "UsbUtils.h"
       
    33 #include <cusbmanextensionplugin.h>
    27 #include <cusbmanextensionplugin.h>
    34 
       
    35 #ifdef USE_DUMMY_CLASS_CONTROLLER
       
    36 #include "CUsbDummyClassController.h"
       
    37 #endif
       
    38 
       
    39 #include <bafl/sysutil.h>
    28 #include <bafl/sysutil.h>
    40 #include <usb/usblogger.h>
    29 #include <usb/usblogger.h>
    41 #include <e32svr.h>
    30 #include <e32svr.h>
    42 #include <e32base.h>
    31 #include <e32base.h>
    43 #include <e32std.h>
    32 #include <e32std.h>
    44 #include <usbman.rsg>
       
    45 #include <f32file.h>
    33 #include <f32file.h>
    46 #include <barsc.h>
    34 #include <barsc.h>
    47 #include <barsread.h>
    35 #include <barsread.h>
    48 #include <bautils.h>
    36 #include <bautils.h>
    49 #include <e32property.h> //Publish & Subscribe header
    37 #include <e32property.h> //Publish & Subscribe header
       
    38 #ifdef USE_DUMMY_CLASS_CONTROLLER
       
    39 #include "CUsbDummyClassController.h"
       
    40 #endif
       
    41 #include "MUsbDeviceNotify.h"
       
    42 #include "UsbSettings.h"
       
    43 #include "CUsbServer.h"
       
    44 #include "UsbUtils.h"
       
    45 #include "CUsbDevice.h"
       
    46 #include "CUsbDeviceStateWatcher.h"
    50 #include "CPersonality.h"
    47 #include "CPersonality.h"
       
    48 #include "usbmancenrepmanager.h"
       
    49 #include "usbmanprivatecrkeys.h"
    51 
    50 
    52 _LIT(KUsbLDDName, "eusbc"); //Name used in call to User::LoadLogicalDevice
    51 _LIT(KUsbLDDName, "eusbc"); //Name used in call to User::LoadLogicalDevice
    53 _LIT(KUsbLDDFreeName, "Usbc"); //Name used in call to User::FreeLogicalDevice
    52 _LIT(KUsbLDDFreeName, "Usbc"); //Name used in call to User::FreeLogicalDevice
    54 
    53 
    55 #ifdef __FLOG_ACTIVE
    54 #ifdef __FLOG_ACTIVE
   106 	iSupportedClasses.ResetAndDestroy();
   105 	iSupportedClasses.ResetAndDestroy();
   107 	iSupportedPersonalities.ResetAndDestroy();
   106 	iSupportedPersonalities.ResetAndDestroy();
   108 	iSupportedClassUids.Close();
   107 	iSupportedClassUids.Close();
   109 
   108 
   110 	iExtensionPlugins.ResetAndDestroy();
   109 	iExtensionPlugins.ResetAndDestroy();
       
   110 	
       
   111 	delete iCenRepManager;
       
   112 	
       
   113 	delete  iDeviceConfiguration.iManufacturerName;
       
   114 	delete  iDeviceConfiguration.iProductName;  
   111 
   115 
   112 	if(iEcom)
   116 	if(iEcom)
   113 		iEcom->Close();
   117 		iEcom->Close();
   114 	REComSession::FinalClose();
   118 	REComSession::FinalClose();
   115 
   119 
   163 	LOG_FUNC
   167 	LOG_FUNC
   164 	
   168 	
   165 	iEcom = &(REComSession::OpenL());
   169 	iEcom = &(REComSession::OpenL());
   166 
   170 
   167 	iUsbClassControllerIterator = new(ELeave) CUsbClassControllerIterator(iSupportedClasses);
   171 	iUsbClassControllerIterator = new(ELeave) CUsbClassControllerIterator(iSupportedClasses);
   168 
   172 	iCenRepManager = CUsbManCenRepManager::NewL(*this);
   169 #ifndef __OVER_DUMMYUSBDI__
   173 
       
   174 	iDeviceConfiguration.iManufacturerName   = HBufC::NewL(KUsbStringDescStringMaxSize);
       
   175 	iDeviceConfiguration.iProductName        = HBufC::NewL(KUsbStringDescStringMaxSize);
       
   176 #ifndef __OVER_DUMMYUSBDI__	
   170 #ifndef __WINS__
   177 #ifndef __WINS__
   171 	LOGTEXT(_L8("About to load LDD"));
   178 	LOGTEXT(_L8("About to load LDD"));
   172 	TInt err = User::LoadLogicalDevice(KUsbLDDName);
   179 	TInt err = User::LoadLogicalDevice(KUsbLDDName);
   173 
   180 
   174 	if (err != KErrNone && err != KErrAlreadyExists)
   181 	if (err != KErrNone && err != KErrAlreadyExists)
   785 	LOGTEXT2(_L8("\tDeviceSubClass is: 0x%02x"), aDeviceDescriptor.iDeviceSubClass);
   792 	LOGTEXT2(_L8("\tDeviceSubClass is: 0x%02x"), aDeviceDescriptor.iDeviceSubClass);
   786 	LOGTEXT2(_L8("\tDeviceProtocol is: 0x%02x"), aDeviceDescriptor.iDeviceProtocol);
   793 	LOGTEXT2(_L8("\tDeviceProtocol is: 0x%02x"), aDeviceDescriptor.iDeviceProtocol);
   787 	LOGTEXT2(_L8("\tiMaxPacketSize is: 0x%02x"), aDeviceDescriptor.iMaxPacketSize);
   794 	LOGTEXT2(_L8("\tiMaxPacketSize is: 0x%02x"), aDeviceDescriptor.iMaxPacketSize);
   788 	
   795 	
   789 	LOGTEXT2(_L8("\tVendorId is: 0x%04x"), aDeviceDescriptor.iIdVendor);
   796 	LOGTEXT2(_L8("\tVendorId is: 0x%04x"), aDeviceDescriptor.iIdVendor);
   790 	LOGTEXT2(_L8("\tProductId is: 0x%04x"), aDeviceDescriptor.iIdProduct);
   797 	LOGTEXT2(_L8("\tProductId is: 0x%04x"), aDeviceDescriptor.iProductId);
   791 	LOGTEXT2(_L8("\tBcdDevice is: 0x%04x"), aDeviceDescriptor.iBcdDevice);
   798 	LOGTEXT2(_L8("\tBcdDevice is: 0x%04x"), aDeviceDescriptor.iBcdDevice);
   792 
   799 
   793 	LOGTEXT2(_L8("\tiManufacturer is: 0x%04x"), aDeviceDescriptor.iManufacturer);
   800 	LOGTEXT2(_L8("\tiManufacturer is: 0x%04x"), aDeviceDescriptor.iManufacturer);
   794 	LOGTEXT2(_L8("\tiSerialNumber is: 0x%04x"), aDeviceDescriptor.iSerialNumber);
   801 	LOGTEXT2(_L8("\tiSerialNumber is: 0x%04x"), aDeviceDescriptor.iSerialNumber);
   795 	LOGTEXT2(_L8("\tiNumConfigurations is: 0x%04x"), aDeviceDescriptor.iNumConfigurations);
   802 	LOGTEXT2(_L8("\tiNumConfigurations is: 0x%04x"), aDeviceDescriptor.iNumConfigurations);
   837 		{
   844 		{
   838 		SetUsbDeviceSettingsFromPersonalityL(*deviceDescriptor);		
   845 		SetUsbDeviceSettingsFromPersonalityL(*deviceDescriptor);		
   839 		}
   846 		}
   840 	else
   847 	else
   841 		{
   848 		{
   842 	SetUsbDeviceSettingsL(*deviceDescriptor);
   849         LOGTEXT(_L8("USB configuration is not read"));
       
   850         LEAVEL(KErrNotFound);
   843 		}
   851 		}
   844 	
   852 	
   845 #ifndef __OVER_DUMMYUSBDI__
   853 #ifndef __OVER_DUMMYUSBDI__
   846 #ifndef __WINS__
   854 #ifndef __WINS__
   847 	ret = iLdd.SetDeviceDescriptor(devicePtr);
   855 	ret = iLdd.SetDeviceDescriptor(devicePtr);
   868 	{
   876 	{
   869 	aDeviceDescriptor.iDeviceClass		= KUsbDefaultDeviceClass;
   877 	aDeviceDescriptor.iDeviceClass		= KUsbDefaultDeviceClass;
   870 	aDeviceDescriptor.iDeviceSubClass	= KUsbDefaultDeviceSubClass;
   878 	aDeviceDescriptor.iDeviceSubClass	= KUsbDefaultDeviceSubClass;
   871 	aDeviceDescriptor.iDeviceProtocol	= KUsbDefaultDeviceProtocol;
   879 	aDeviceDescriptor.iDeviceProtocol	= KUsbDefaultDeviceProtocol;
   872 	aDeviceDescriptor.iIdVendor			= KUsbDefaultVendorId;
   880 	aDeviceDescriptor.iIdVendor			= KUsbDefaultVendorId;
   873 	aDeviceDescriptor.iIdProduct		= KUsbDefaultProductId;
   881 	aDeviceDescriptor.iProductId		= KUsbDefaultProductId;
   874 	}
   882 	}
   875 
   883 
   876 void CUsbDevice::SetUsbDeviceSettingsL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
   884 void CUsbDevice::SetUsbDeviceSettingsFromPersonalityL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
   877 /**
   885 /**
   878  * Configure the USB device, reading in the settings from a
   886  * Configure the USB device from the current personality.
   879  * resource file where possible.
       
   880  *
   887  *
   881  * @param aDeviceDescriptor The device descriptor for the USB device
   888  * @param aDeviceDescriptor The device descriptor for the USB device
   882  */
   889  */
   883 	{
   890 	{
   884 	LOG_FUNC
   891 	LOG_FUNC
   885 
   892 
   886 	// First, use the default values
   893 	// First, use the default values
   887 	LOGTEXT(_L8("Setting default values for the configuration"));
   894 	LOGTEXT(_L8("Setting default values for the configuration"));
   888 	SetUsbDeviceSettingsDefaultsL(aDeviceDescriptor);
   895 	SetUsbDeviceSettingsDefaultsL(aDeviceDescriptor);
   889 
   896 
   890 	// Now try to get the configuration from the resource file
   897 	// Now try to get the configuration from the current personality
   891 	RFs fs;
   898     aDeviceDescriptor.iDeviceClass          = iCurrentPersonality->DeviceClass();
   892 	LEAVEIFERRORL(fs.Connect());
   899     aDeviceDescriptor.iDeviceSubClass       = iCurrentPersonality->DeviceSubClass();
   893 	CleanupClosePushL(fs);
   900     aDeviceDescriptor.iDeviceProtocol       = iCurrentPersonality->DeviceProtocol();
   894 
   901     aDeviceDescriptor.iIdVendor             = iDeviceConfiguration.iVendorId;
   895 	RResourceFile resource;
   902     aDeviceDescriptor.iProductId            = iCurrentPersonality->ProductId();
   896 	TRAPD(err, resource.OpenL(fs, KUsbManagerResource));
   903     aDeviceDescriptor.iBcdDevice            = iCurrentPersonality->BcdDevice();
   897 	LOGTEXT2(_L8("Opened resource file with error %d"), err);
   904     aDeviceDescriptor.iNumConfigurations    = iCurrentPersonality->NumConfigurations();	
   898 
   905 	
   899 	if (err != KErrNone)
   906 
   900 		{
       
   901 		LOGTEXT(_L8("Unable to open resource file: using default settings"));
       
   902 		CleanupStack::PopAndDestroy(&fs);
       
   903 		return;
       
   904 		}
       
   905 
       
   906 	CleanupClosePushL(resource);
       
   907 
       
   908 	resource.ConfirmSignatureL(KUsbManagerResourceVersion);
       
   909 
       
   910 	HBufC8* id = resource.AllocReadLC(USB_CONFIG);
       
   911 
       
   912 	// The format of the USB resource structure is:
       
   913 	//
       
   914 	//	STRUCT usb_configuration
       
   915 	//		{
       
   916 	//		WORD	vendorId		= 0x0e22;
       
   917 	//		WORD	productId		= 0x000b;
       
   918 	//		WORD	bcdDevice		= 0x0000;
       
   919 	//		LTEXT	manufacturer	= "Symbian Ltd.";
       
   920 	//		LTEXT	product			= "Symbian OS";
       
   921 	//		}
       
   922 	//
       
   923 	// Note that the resource must be read in this order!
       
   924 	
       
   925 	TResourceReader reader;
       
   926 	reader.SetBuffer(id);
       
   927 
       
   928 	aDeviceDescriptor.iIdVendor = static_cast<TUint16>(reader.ReadUint16());
       
   929 	aDeviceDescriptor.iIdProduct = static_cast<TUint16>(reader.ReadUint16());
       
   930 	aDeviceDescriptor.iBcdDevice = static_cast<TUint16>(reader.ReadUint16());
       
   931 
       
   932 	// Try to read device and manufacturer name from new SysUtil API
       
   933 	TPtrC16 sysUtilModelName;
       
   934 	TPtrC16 sysUtilManuName;
       
   935 	
       
   936 	// This method returns ownership.
       
   937 	CDeviceTypeInformation* deviceInfo = SysUtil::GetDeviceTypeInfoL();
       
   938 	CleanupStack::PushL(deviceInfo);
       
   939 	TInt gotSysUtilModelName = deviceInfo->GetModelName(sysUtilModelName);
       
   940 	TInt gotSysUtilManuName = deviceInfo->GetManufacturerName(sysUtilManuName);
       
   941 	
       
   942 	TPtrC manufacturerString = reader.ReadTPtrC();
       
   943 	TPtrC productString = reader.ReadTPtrC();
       
   944 	
       
   945 	// If we succesfully read the manufacturer or device name from SysUtil API
       
   946 	// then set these results, otherwise use the values defined in resource file
       
   947 #ifndef __OVER_DUMMYUSBDI__
   907 #ifndef __OVER_DUMMYUSBDI__
   948 #ifndef __WINS__
   908 #ifndef __WINS__
   949 	if (gotSysUtilManuName == KErrNone)
   909 	LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(*(iDeviceConfiguration.iManufacturerName)));
   950 		{
   910 	LEAVEIFERRORL(iLdd.SetProductStringDescriptor(*(iDeviceConfiguration.iProductName)));
   951 		LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(sysUtilManuName));
   911 
   952 		}
       
   953 	else
       
   954 		{
       
   955 		LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(manufacturerString));
       
   956 		}
       
   957 
       
   958 	if (gotSysUtilModelName == KErrNone)
       
   959 		{
       
   960 		LEAVEIFERRORL(iLdd.SetProductStringDescriptor(sysUtilModelName));
       
   961 		}
       
   962 	else
       
   963 		{
       
   964 		LEAVEIFERRORL(iLdd.SetProductStringDescriptor(productString));
       
   965 		}
       
   966 		
       
   967 #endif
       
   968 #endif // __OVER_DUMMYUSBDI__
       
   969 
       
   970 #ifdef __FLOG_ACTIVE
       
   971 	PrintDescriptor(aDeviceDescriptor);	
       
   972 	TBuf8<KUsbStringDescStringMaxSize> narrowString;
       
   973 	narrowString.Copy(manufacturerString);
       
   974 	LOGTEXT2(_L8("Manufacturer is: '%S'"), &narrowString);
       
   975 	narrowString.Copy(productString);
       
   976 	LOGTEXT2(_L8("Product is: '%S'"), &narrowString);
       
   977 #endif // __FLOG_ACTIVE
       
   978 
       
   979 #ifndef __OVER_DUMMYUSBDI__
       
   980 #ifndef __WINS__	
       
   981 	//Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB
   912 	//Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB
   982 	TBuf16<KUsbStringDescStringMaxSize> serNum;
   913 	TBuf16<KUsbStringDescStringMaxSize> serNum;
   983 	TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum);
   914 	TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum);
   984 	if(r==KErrNone)
   915 	if(r==KErrNone)
   985 		{
   916 		{
  1001 
   932 
  1002 #endif
   933 #endif
  1003 #endif // __OVER_DUMMYUSBDI__
   934 #endif // __OVER_DUMMYUSBDI__
  1004 
   935 
  1005 
   936 
  1006 	CleanupStack::PopAndDestroy(4, &fs); //  deviceInfo, id, resource, fs
       
  1007 	}
       
  1008 
       
  1009 void CUsbDevice::SetUsbDeviceSettingsFromPersonalityL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor)
       
  1010 /**
       
  1011  * Configure the USB device from the current personality.
       
  1012  *
       
  1013  * @param aDeviceDescriptor The device descriptor for the USB device
       
  1014  */
       
  1015 	{
       
  1016 	LOG_FUNC
       
  1017 
       
  1018 	// First, use the default values
       
  1019 	LOGTEXT(_L8("Setting default values for the configuration"));
       
  1020 	SetUsbDeviceSettingsDefaultsL(aDeviceDescriptor);
       
  1021 
       
  1022 	// Now try to get the configuration from the current personality
       
  1023 	const CUsbDevice::TUsbDeviceDescriptor& deviceDes = iCurrentPersonality->DeviceDescriptor();
       
  1024 	aDeviceDescriptor.iDeviceClass			= deviceDes.iDeviceClass;
       
  1025 	aDeviceDescriptor.iDeviceSubClass		= deviceDes.iDeviceSubClass;
       
  1026 	aDeviceDescriptor.iDeviceProtocol		= deviceDes.iDeviceProtocol;
       
  1027 	aDeviceDescriptor.iIdVendor				= deviceDes.iIdVendor;
       
  1028 	aDeviceDescriptor.iIdProduct			= deviceDes.iIdProduct;
       
  1029 	aDeviceDescriptor.iBcdDevice			= deviceDes.iBcdDevice;
       
  1030 	aDeviceDescriptor.iSerialNumber			= deviceDes.iSerialNumber;
       
  1031 	aDeviceDescriptor.iNumConfigurations	= deviceDes.iNumConfigurations;
       
  1032 
       
  1033 #ifndef __OVER_DUMMYUSBDI__
       
  1034 #ifndef __WINS__
       
  1035 	LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(*(iCurrentPersonality->Manufacturer())));
       
  1036 	LEAVEIFERRORL(iLdd.SetProductStringDescriptor(*(iCurrentPersonality->Product())));
       
  1037 
       
  1038 	//Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB
       
  1039 	TBuf16<KUsbStringDescStringMaxSize> serNum;
       
  1040 	TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum);
       
  1041 	if(r==KErrNone)
       
  1042 		{
       
  1043 #ifdef __FLOG_ACTIVE
       
  1044 		TBuf8<KUsbStringDescStringMaxSize> narrowString;
       
  1045 		narrowString.Copy(serNum);
       
  1046 		LOGTEXT2(_L8("Setting published SerialNumber: %S"), &narrowString);
       
  1047 #endif // __FLOG_ACTIVE
       
  1048 		//USB spec doesn't give any constraints on what constitutes a valid serial number.
       
  1049 		//As long as it is a string descriptor it is valid.
       
  1050 		LEAVEIFERRORL(iLdd.SetSerialNumberStringDescriptor(serNum));	
       
  1051 		}
       
  1052 #ifdef __FLOG_ACTIVE
       
  1053 	else
       
  1054 		{
       
  1055 		LOGTEXT(_L8("SerialNumber has not been published"));	
       
  1056 		}
       
  1057 #endif // __FLOG_ACTIVE
       
  1058 
       
  1059 #endif
       
  1060 #endif // __OVER_DUMMYUSBDI__
       
  1061 
       
  1062 
       
  1063 #ifdef __FLOG_ACTIVE
   937 #ifdef __FLOG_ACTIVE
  1064 	PrintDescriptor(aDeviceDescriptor);		
   938 	PrintDescriptor(aDeviceDescriptor);		
  1065 
   939 
  1066 #ifndef __OVER_DUMMYUSBDI__
   940 #ifndef __OVER_DUMMYUSBDI__
  1067 #ifndef __WINS__
   941 #ifndef __WINS__
  1169 	LOG_FUNC
  1043 	LOG_FUNC
  1170 
  1044 
  1171 	TInt personalityCount = iSupportedPersonalities.Count();
  1045 	TInt personalityCount = iSupportedPersonalities.Count();
  1172 	for (TInt i = 0; i < personalityCount; i++)
  1046 	for (TInt i = 0; i < personalityCount; i++)
  1173 		{
  1047 		{
  1174 		const RArray<TUid>& classUids = iSupportedPersonalities[i]->SupportedClasses();
  1048 		const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iSupportedPersonalities[i]->SupportedClasses();
  1175 		TInt uidCount = classUids.Count();
  1049 		TInt uidCount = classes.Count();
  1176 		for (TInt j = 0; j < uidCount; j++)	
  1050 		for (TInt j = 0; j < uidCount; j++)	
  1177 			{
  1051 			{
  1178 			TInt ccCount = iSupportedClassUids.Count();
  1052 			TInt ccCount = iSupportedClassUids.Count();
  1179 			TInt k;
  1053 			TInt k;
       
  1054 		    LOGTEXT2(_L8("iSupportedClassUids Count = %d"),ccCount);
  1180 			for (k = 0; k < ccCount; k++)
  1055 			for (k = 0; k < ccCount; k++)
  1181 				{
  1056 				{
  1182 				if (iSupportedClassUids[k] == classUids[j])
  1057                 LOGTEXT5(_L8("iSupportedClassUids %d %x classes %d %x"), k, iSupportedClassUids[k].iUid, j, classes[j].iClassUid.iUid);
       
  1058 				if (iSupportedClassUids[k] == classes[j].iClassUid)
  1183 					{
  1059 					{
  1184 					break;
  1060 					break;
  1185 					}
  1061 					}
  1186 				}
  1062 				}
  1187 			if (k == ccCount)
  1063 			if (k == ccCount)
  1202 @param aUIDs On return array of UIDs parsed from the input string
  1078 @param aUIDs On return array of UIDs parsed from the input string
  1203 @panic EUidArrayNotEmpty if the RArray passed in is not empty
  1079 @panic EUidArrayNotEmpty if the RArray passed in is not empty
  1204 */
  1080 */
  1205 void CUsbDevice::ConvertUidsL(const TDesC& aStr, RArray<TUint>& aUidArray)	
  1081 void CUsbDevice::ConvertUidsL(const TDesC& aStr, RArray<TUint>& aUidArray)	
  1206 	{
  1082 	{
       
  1083     LOG_FUNC
  1207 	// Function assumes that aUIDs is empty
  1084 	// Function assumes that aUIDs is empty
  1208 	__ASSERT_DEBUG( aUidArray.Count() == 0, _USB_PANIC(KUsbDevicePanicCategory, EUidArrayNotEmpty) );
  1085 	__ASSERT_DEBUG( aUidArray.Count() == 0, _USB_PANIC(KUsbDevicePanicCategory, EUidArrayNotEmpty) );
  1209 
  1086 
  1210 	TLex input(aStr);
  1087 	TLex input(aStr);
  1211 
  1088 
  1226 		}
  1103 		}
  1227 	while (!input.Eos());	
  1104 	while (!input.Eos());	
  1228 	}
  1105 	}
  1229 
  1106 
  1230 void CUsbDevice::ReadPersonalitiesL()
  1107 void CUsbDevice::ReadPersonalitiesL()
  1231 /**
  1108     {    
  1232  * Reads configured personalities from the resource file
  1109     LOG_FUNC
  1233  */
  1110     TPtrC16 sysUtilModelName;
  1234 	{
  1111     TPtrC16 sysUtilManuName;
  1235 	LOG_FUNC
  1112     
  1236 	iPersonalityCfged = EFalse;
  1113     iPersonalityCfged = EFalse;
  1237 	// Now try to connect to file server
  1114     
  1238 	RFs fs;
  1115     iCenRepManager->ReadDeviceConfigurationL(iDeviceConfiguration);
  1239 	LEAVEIFERRORL(fs.Connect());
  1116     
  1240 	CleanupClosePushL(fs);
  1117     iCenRepManager->ReadPersonalitiesL(iSupportedPersonalities);
  1241 
  1118     
  1242 	TFileName resourceFileName;
  1119     //update info for SetManufacturer & SetProduct
  1243 	ResourceFileNameL(resourceFileName);
  1120     CDeviceTypeInformation* deviceInfo = SysUtil::GetDeviceTypeInfoL();
  1244 	RResourceFile resource;
  1121     CleanupStack::PushL(deviceInfo);
  1245 	TRAPD(err, resource.OpenL(fs, resourceFileName));
  1122     TInt gotSysUtilModelName = deviceInfo->GetModelName(sysUtilModelName);
  1246 	LOGTEXT2(_L8("Opened resource file with error %d"), err);
  1123     TInt gotSysUtilManuName = deviceInfo->GetManufacturerName(sysUtilManuName);
  1247 
  1124     
  1248 	if (err != KErrNone)
  1125     //To overlap info 
  1249 		{
  1126     if (gotSysUtilManuName == KErrNone)
  1250 		LOGTEXT(_L8("Unable to open resource file"));
  1127         {
  1251 		CleanupStack::PopAndDestroy(&fs);
  1128         iDeviceConfiguration.iManufacturerName->Des().Copy(sysUtilManuName); 
  1252 		return;
  1129         }
  1253 		}
  1130         
  1254 
  1131     if (gotSysUtilModelName == KErrNone)
  1255 	CleanupClosePushL(resource);
  1132         {
  1256 
  1133         iDeviceConfiguration.iProductName->Des().Copy(sysUtilModelName);
  1257 	TInt resourceVersion = resource.SignatureL();
  1134         }
  1258 	LOGTEXT2(_L8("Resource file signature is %d"), resourceVersion);
  1135     CleanupStack::PopAndDestroy(deviceInfo);
  1259 	// Check for the version is valid(EUsbManagerResourceVersionOne, EUsbManagerResourceVersionTwo
  1136     iPersonalityCfged = ETrue;
  1260 	// or EUsbManagerResourceVersionThree).
  1137     }
  1261 	if(resourceVersion > EUsbManagerResourceVersionThree)
       
  1262 		{
       
  1263 		LOGTEXT2(_L8("Version of resource file is valid (>%d)"), EUsbManagerResourceVersionThree);
       
  1264 		User::LeaveIfError(KErrNotSupported);
       
  1265 		}
       
  1266 	
       
  1267 	resource.ConfirmSignatureL(resourceVersion);
       
  1268 
       
  1269 	HBufC8* personalityBuf = 0;
       
  1270 	TRAPD(ret, personalityBuf = resource.AllocReadL(DEVICE_PERSONALITIES));
       
  1271 	// If personalities resource is not found, swallow the error and return
       
  1272 	// as no specified personalities is a valid configuration
       
  1273 	if (ret == KErrNotFound)
       
  1274 		{
       
  1275 		LOGTEXT(_L8("Personalities are not configured"));
       
  1276 		CleanupStack::PopAndDestroy(2, &fs); 
       
  1277 		return;
       
  1278 		}
       
  1279 	// Otherwise leave noisily if the AllocRead fails
       
  1280 	LEAVEIFERRORL(ret);
       
  1281 	CleanupStack::PushL(personalityBuf);
       
  1282 
       
  1283 	// The format of the USB resource structure is:
       
  1284 	//
       
  1285 	// 	STRUCT PERSONALITY
       
  1286 	//		{
       
  1287 	// 		WORD	bcdDeviceClass;
       
  1288 	// 		WORD	bcdDeviceSubClass;
       
  1289 	//		WORD 	protocol;
       
  1290 	//		WORD	numConfigurations;
       
  1291 	//		WORD 	vendorId;
       
  1292 	//		WORD 	productId;
       
  1293 	//		WORD 	bcdDevice;
       
  1294 	//		LTEXT 	manufacturer;
       
  1295 	//		LTEXT 	product;
       
  1296 	//		WORD 	id;					// personality id
       
  1297 	//		LTEXT	class_uids;	
       
  1298 	//		LTEXT 	description;		// personality description
       
  1299 	//     	LTEXT   detailedDescription;  //detailed description. This is in version 2
       
  1300 	//		LONG 	Property;
       
  1301 	//		}
       
  1302 	//
       
  1303 	// Note that the resource must be read in this order!
       
  1304 	
       
  1305 	TResourceReader reader;
       
  1306 	reader.SetBuffer(personalityBuf);
       
  1307 
       
  1308 	TUint16 personalityCount 	= static_cast<TUint16>(reader.ReadUint16());
       
  1309 	
       
  1310 	// Read the manufacturer and device name (product) here from SysUtil class
       
  1311 	TPtrC16 sysUtilModelName;
       
  1312 	TPtrC16 sysUtilManuName;
       
  1313 
       
  1314 	// This method returns ownership.
       
  1315 	CDeviceTypeInformation* deviceInfo = SysUtil::GetDeviceTypeInfoL();
       
  1316 	CleanupStack::PushL(deviceInfo);
       
  1317 	TInt gotSysUtilModelName = deviceInfo->GetModelName(sysUtilModelName);
       
  1318 	TInt gotSysUtilManuName = deviceInfo->GetManufacturerName(sysUtilManuName);
       
  1319 	
       
  1320 	for (TInt idx = 0; idx < personalityCount; idx++)
       
  1321 		{
       
  1322 		// read a personality 
       
  1323 		TUint8 	bDeviceClass 		= static_cast<TUint8>(reader.ReadUint8());
       
  1324 		TUint8 	bDeviceSubClass 	= static_cast<TUint8>(reader.ReadUint8());
       
  1325 		TUint8 	protocol 			= static_cast<TUint8>(reader.ReadUint8());
       
  1326 		TUint8 	numConfigurations	= static_cast<TUint8>(reader.ReadUint8());
       
  1327 		TUint16 vendorId			= static_cast<TUint16>(reader.ReadUint16());
       
  1328 		TUint16 productId			= static_cast<TUint16>(reader.ReadUint16());
       
  1329 		TUint16 bcdDevice			= static_cast<TUint16>(reader.ReadUint16());
       
  1330 		TPtrC	manufacturer		= reader.ReadTPtrC();
       
  1331 		TPtrC	product				= reader.ReadTPtrC();
       
  1332 		TUint16 id					= static_cast<TUint16>(reader.ReadUint16());
       
  1333 		TPtrC	uidsStr				= reader.ReadTPtrC();
       
  1334 		TPtrC 	description			= reader.ReadTPtrC();
       
  1335 		
       
  1336 		RArray<TUint> uids;
       
  1337 		CleanupClosePushL(uids);
       
  1338 		ConvertUidsL(uidsStr, uids);
       
  1339 		// creates a CPersonality object
       
  1340 		CPersonality* personality = CPersonality::NewL();
       
  1341 		CleanupStack::PushL(personality);
       
  1342 
       
  1343 		personality->SetVersion(resourceVersion);
       
  1344 		
       
  1345 		// populates personality object
       
  1346 		personality->SetId(id);
       
  1347 		        
       
  1348 		for (TInt uidIdx = 0; uidIdx < uids.Count(); uidIdx++)
       
  1349 			{
       
  1350 			LEAVEIFERRORL(personality->AddSupportedClasses(TUid::Uid(uids[uidIdx])));
       
  1351 			}
       
  1352 		
       
  1353 		// gets a handle to iDeviceDescriptor of personality
       
  1354 		CUsbDevice::TUsbDeviceDescriptor& dvceDes = personality->DeviceDescriptor();
       
  1355 		if (gotSysUtilManuName == KErrNone)
       
  1356 			{
       
  1357 			personality->SetManufacturer(&sysUtilManuName);
       
  1358 			}
       
  1359 		else
       
  1360 			{
       
  1361 			personality->SetManufacturer(&manufacturer);
       
  1362 			}
       
  1363 			
       
  1364 		if (gotSysUtilModelName == KErrNone)
       
  1365 			{
       
  1366 			personality->SetProduct(&sysUtilModelName);
       
  1367 			}
       
  1368 		else
       
  1369 			{
       
  1370 			personality->SetProduct(&product);
       
  1371 			}
       
  1372 			
       
  1373 		personality->SetDescription(&description);
       
  1374 		dvceDes.iDeviceClass = bDeviceClass;
       
  1375 		dvceDes.iDeviceSubClass = bDeviceSubClass;
       
  1376 		dvceDes.iDeviceProtocol = protocol;
       
  1377 		dvceDes.iIdVendor = vendorId;
       
  1378 		dvceDes.iIdProduct= productId;
       
  1379 		dvceDes.iBcdDevice = bcdDevice;
       
  1380 		dvceDes.iNumConfigurations = numConfigurations;
       
  1381 		
       
  1382 		//detailedDescription is only supported after EUsbManagerResourceVersionTwo
       
  1383 		if(resourceVersion >= EUsbManagerResourceVersionTwo)
       
  1384 			{
       
  1385 			TPtrC   detailedDescription = reader.ReadTPtrC();        
       
  1386 			personality->SetDetailedDescription(&detailedDescription);
       
  1387 #ifdef __FLOG_ACTIVE
       
  1388 			TBuf8<KUsbDescMaxSize_String> narrowLongBuf;
       
  1389 			narrowLongBuf.Copy(detailedDescription);
       
  1390 			LOGTEXT2(_L8("detailed description = '%S'"),        &narrowLongBuf);            
       
  1391 #endif // __FLOG_ACTIVE
       
  1392 			}
       
  1393 
       
  1394 		//Property is only supported after EUsbManagerResourceVersionThree
       
  1395 		if(resourceVersion >= EUsbManagerResourceVersionThree)
       
  1396 			{
       
  1397 			TUint32 property			= static_cast<TUint32>(reader.ReadUint32());
       
  1398 			personality->SetProperty(property);
       
  1399 #ifdef __FLOG_ACTIVE
       
  1400 		LOGTEXT2(_L8("property = %d\n"), 			property);
       
  1401 #endif // __FLOG_ACTIVE
       
  1402 			}
       
  1403 		
       
  1404 		// Append personality to iSupportedPersonalities
       
  1405 		iSupportedPersonalities.AppendL(personality);
       
  1406 		// Now pop off personality
       
  1407 		CleanupStack::Pop(personality);
       
  1408 #ifdef __FLOG_ACTIVE
       
  1409 		// Debugging
       
  1410 		LOGTEXT2(_L8("personalityCount = %d\n"), 	personalityCount);
       
  1411 		LOGTEXT2(_L8("bDeviceClass = %d\n"), 		bDeviceClass);
       
  1412 		LOGTEXT2(_L8("bDeviceSubClass = %d\n"), 	bDeviceSubClass);
       
  1413 		LOGTEXT2(_L8("protocol = %d\n"), 			protocol);
       
  1414 		LOGTEXT2(_L8("numConfigurations = %d\n"), 	numConfigurations);
       
  1415 		LOGTEXT2(_L8("vendorId = %d\n"), 			vendorId);
       
  1416 		LOGTEXT2(_L8("productId = %d\n"), 			productId);
       
  1417 		LOGTEXT2(_L8("bcdDevice = %d\n"), 			bcdDevice);
       
  1418 		TBuf8<KMaxName> narrowBuf;
       
  1419 		narrowBuf.Copy(manufacturer);
       
  1420 		LOGTEXT2(_L8("manufacturer = '%S'"), 		&narrowBuf);
       
  1421 		narrowBuf.Copy(product);
       
  1422 		LOGTEXT2(_L8("product = '%S'"), 			&narrowBuf);
       
  1423 		LOGTEXT2(_L8("id = %d\n"), 					id);
       
  1424 		LOGTEXT(_L8("ClassUids{"));
       
  1425 		for (TInt k = 0; k < uids.Count(); k++)
       
  1426 			{
       
  1427 			LOGTEXT2(_L8("%d"), uids[k]);
       
  1428 			}
       
  1429 		LOGTEXT(_L8("}"));
       
  1430 		narrowBuf.Copy(description);
       
  1431 		LOGTEXT2(_L8("description = '%S'"), 		&narrowBuf);
       
  1432 #endif // __FLOG_ACTIVE
       
  1433 		CleanupStack::PopAndDestroy(&uids);	// close uid array		
       
  1434 		}
       
  1435 		
       
  1436 	CleanupStack::PopAndDestroy(4, &fs); // deviceInfo, personalityBuf, resource, fs
       
  1437 	iPersonalityCfged = ETrue;	
       
  1438 	}
       
  1439 	
  1138 	
  1440 void CUsbDevice::SelectClassControllersL()
  1139 void CUsbDevice::SelectClassControllersL()
  1441 /**
  1140 /**
  1442  * Selects class controllers for the current personality
  1141  * Selects class controllers for the current personality
  1443  */
  1142  */
  1444 	{
  1143 	{
  1445 	LOG_FUNC
  1144 	LOG_FUNC
  1446 
  1145     const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iCurrentPersonality->SupportedClasses();
  1447 	CreateClassControllersL(iCurrentPersonality->SupportedClasses());
  1146 	RArray<TUid> classUids;
       
  1147 	CleanupClosePushL( classUids ); 
       
  1148     TInt classCount = classes.Count();
       
  1149 	for(TInt classIndex = 0; classIndex<classCount; ++classIndex)
       
  1150 	    {
       
  1151         TUid uid = classes[classIndex].iClassUid;
       
  1152         classUids.AppendL(uid);
       
  1153 	    }
       
  1154 	
       
  1155 	CreateClassControllersL(classUids);
       
  1156 	
       
  1157     CleanupStack::PopAndDestroy( &classUids );
  1448 	}
  1158 	}
  1449 #ifdef USE_DUMMY_CLASS_CONTROLLER	
  1159 #ifdef USE_DUMMY_CLASS_CONTROLLER	
  1450 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& /* aClassUids*/)
  1160 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& /* aClassUids*/)
  1451 #else 
  1161 #else 
  1452 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& aClassUids)
  1162 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& aClassUids)
  1487 	{
  1197 	{
  1488 	LOG_FUNC
  1198 	LOG_FUNC
  1489 
  1199 
  1490 	TInt smallestId = iSupportedPersonalities[0]->PersonalityId();
  1200 	TInt smallestId = iSupportedPersonalities[0]->PersonalityId();
  1491  	TInt count = iSupportedPersonalities.Count();
  1201  	TInt count = iSupportedPersonalities.Count();
  1492  	
       
  1493  	for (TInt i = 1; i < count; i++)
  1202  	for (TInt i = 1; i < count; i++)
  1494  		{
  1203  		{
  1495  		if(iSupportedPersonalities[i]->PersonalityId() < smallestId)
  1204  		if(iSupportedPersonalities[i]->PersonalityId() < smallestId)
  1496  			{
  1205  			{
  1497  			smallestId = iSupportedPersonalities[i]->PersonalityId();
  1206  			smallestId = iSupportedPersonalities[i]->PersonalityId();
  1498  			}
  1207  			}
  1499  		}
  1208  		}
  1500 
  1209     
  1501 	SetCurrentPersonalityL(smallestId);
  1210 	SetCurrentPersonalityL(smallestId);
  1502 	SelectClassControllersL();
  1211 	SelectClassControllersL();
  1503 	}
  1212 	}
  1504 
  1213 
  1505 void CUsbDevice::LoadFallbackClassControllersL()
  1214 void CUsbDevice::LoadFallbackClassControllersL()
  1514 	LOG_FUNC
  1223 	LOG_FUNC
  1515  	SetDeviceDescriptorL();
  1224  	SetDeviceDescriptorL();
  1516 	CreateClassControllersL(iSupportedClassUids);
  1225 	CreateClassControllersL(iSupportedClassUids);
  1517  	}
  1226  	}
  1518  	
  1227  	
  1519 void CUsbDevice::ResourceFileNameL(TFileName& aFileName)
       
  1520 /**
       
  1521  * Gets resource file name
       
  1522  *
       
  1523  * @param aFileName Descriptor to populate with resource file name
       
  1524  */
       
  1525  	{
       
  1526 	LOG_FUNC
       
  1527 
       
  1528 	RFs fs;
       
  1529 	LEAVEIFERRORL(fs.Connect());
       
  1530 	CleanupClosePushL(fs);
       
  1531 
       
  1532 #ifdef __WINS__
       
  1533 	// If we are running in the emulator then read the resource file from system drive.
       
  1534 	// This makes testing with different resource files easier.
       
  1535 	_LIT(KPrivatePath, ":\\Private\\101fe1db\\");
       
  1536 	aFileName.Append(RFs::GetSystemDriveChar()); //get the name of system drive
       
  1537 	aFileName.Append(KPrivatePath);
       
  1538 #else
       
  1539  	const TDriveNumber KResourceDrive = EDriveZ;
       
  1540 
       
  1541 	TDriveUnit driveUnit(KResourceDrive);
       
  1542 	TDriveName drive=driveUnit.Name();
       
  1543 	aFileName.Insert(0, drive);
       
  1544 	// append private path
       
  1545 	TPath privatePath;
       
  1546 	fs.PrivatePath(privatePath);
       
  1547 	aFileName.Append(privatePath);		
       
  1548 #endif //WINS
       
  1549 
       
  1550 	// Find the nearest match of resource file for the chosen locale
       
  1551 	aFileName.Append(_L("usbman.rsc"));
       
  1552 	BaflUtils::NearestLanguageFile(fs, aFileName); // if a match is not found, usbman.rsc will be used
       
  1553 
       
  1554 	CleanupStack::PopAndDestroy(&fs);	// fs no longer needed
       
  1555  	}
       
  1556 
       
  1557 RDevUsbcClient& CUsbDevice::MuepoDoDevUsbcClient()
  1228 RDevUsbcClient& CUsbDevice::MuepoDoDevUsbcClient()
  1558 /**
  1229 /**
  1559  * Inherited from MUsbmanExtensionPluginObserver - Function used by plugins to
  1230  * Inherited from MUsbmanExtensionPluginObserver - Function used by plugins to
  1560  * retrieve our handle to the LDD
  1231  * retrieve our handle to the LDD
  1561  *
  1232  *