usbmgmt/usbmgr/host/fdf/production/server/src/fdf.cpp
branchRCL_3
changeset 15 f92a4f87e424
parent 8 863facfed77d
child 16 012cc2ee6408
equal deleted inserted replaced
14:d3e8e7d462dd 15:f92a4f87e424
     1 /*
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007-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".
    23 #include "fdf.h"
    23 #include "fdf.h"
    24 #include <usb/usblogger.h>
    24 #include <usb/usblogger.h>
    25 #include "utils.h"
    25 #include "utils.h"
    26 #include <usbhost/internal/fdcplugin.hrh>
    26 #include <usbhost/internal/fdcplugin.hrh>
    27 #include "eventqueue.h"
    27 #include "eventqueue.h"
    28 
    28 #include "OstTraceDefinitions.h"
    29 #ifdef __FLOG_ACTIVE
    29 #ifdef OST_TRACE_COMPILER_IN_USE
    30 _LIT8(KLogComponent, "fdf      ");
    30 #include "fdfTraces.h"
    31 #endif
    31 #endif
       
    32 
    32 
    33 
    33 _LIT(KDriverUsbhubLddFileName,"usbhubdriver");
    34 _LIT(KDriverUsbhubLddFileName,"usbhubdriver");
    34 _LIT(KDriverUsbdiLddFileName,"usbdi");
    35 _LIT(KDriverUsbdiLddFileName,"usbdi");
    35 
    36 
    36 PANICCATEGORY("fdf");
    37 _LIT(KPanicCategory, "fdf");
    37 
    38 
    38 const TUint KVendorSpecificDeviceClassValue = 0xFF;
    39 const TUint KVendorSpecificDeviceClassValue = 0xFF;
    39 const TUint KVendorSpecificInterfaceClassValue = 0xFF;
    40 const TUint KVendorSpecificInterfaceClassValue = 0xFF;
    40 const TUint KMaxSearchKeyLength = 64; 
    41 const TUint KMaxSearchKeyLength = 64; 
    41 
    42 
    42 // Factory function for TInterfaceInfo objects.
    43 // Factory function for TInterfaceInfo objects.
    43 CFdf::TInterfaceInfo* CFdf::TInterfaceInfo::NewL(RPointerArray<CFdf::TInterfaceInfo>& aInterfaces)
    44 CFdf::TInterfaceInfo* CFdf::TInterfaceInfo::NewL(RPointerArray<CFdf::TInterfaceInfo>& aInterfaces)
    44 	{
    45 	{
    45 	LOG_STATIC_FUNC_ENTRY
    46     OstTraceFunctionEntry0( CFDF_TINTERFACEINFO_NEWL_ENTRY );
    46 
    47 
    47 	TInterfaceInfo* self = new(ELeave) TInterfaceInfo;
    48 	TInterfaceInfo* self = new(ELeave) TInterfaceInfo;
    48 	CleanupStack::PushL(self);
    49 	CleanupStack::PushL(self);
    49 	aInterfaces.AppendL(self);
    50 	aInterfaces.AppendL(self);
    50 	CLEANUPSTACK_POP1(self);
    51 	CLEANUPSTACK_POP1(self);
       
    52 	OstTraceFunctionExit0( CFDF_TINTERFACEINFO_NEWL_EXIT );
    51 	return self;
    53 	return self;
    52 	}
    54 	}
    53 
    55 
    54 
    56 
    55 CFdf* CFdf::NewL()
    57 CFdf* CFdf::NewL()
    56 	{
    58 	{
    57 	LOG_STATIC_FUNC_ENTRY
    59     OstTraceFunctionEntry0( CFDF_NEWL_ENTRY );
    58 
    60 
    59 	CFdf* self = new(ELeave) CFdf;
    61 	CFdf* self = new(ELeave) CFdf;
    60 	CleanupStack::PushL(self);
    62 	CleanupStack::PushL(self);
    61 	self->ConstructL();
    63 	self->ConstructL();
    62 	CLEANUPSTACK_POP1(self);
    64 	CLEANUPSTACK_POP1(self);
       
    65 	OstTraceFunctionExit0( CFDF_NEWL_EXIT );
    63 	return self;
    66 	return self;
    64 	}
    67 	}
    65 
    68 
    66 CFdf::CFdf()
    69 CFdf::CFdf()
    67 :	iDevices(_FOFF(CDeviceProxy, iLink)),
    70 :	iDevices(_FOFF(CDeviceProxy, iLink)),
    68 	iFunctionDrivers(_FOFF(CFdcProxy, iLink))
    71 	iFunctionDrivers(_FOFF(CFdcProxy, iLink))
    69 	{
    72 	{
    70 	LOG_FUNC
    73     OstTraceFunctionEntry0( CFDF_CFDF_CONS_ENTRY );
    71 	}
    74 	}
    72 
    75 
    73 void CFdf::ConstructL()
    76 void CFdf::ConstructL()
    74 	{
    77 	{
    75 	LOG_FUNC
    78 	OstTraceFunctionEntry0( CFDF_CONSTRUCTL_ENTRY );
    76 
    79 	
    77 #ifndef __OVER_DUMMYUSBDI__
    80 #ifndef __OVER_DUMMYUSBDI__
    78 	// If we're using the DummyUSBDI we don't need the real USBDI.
    81 	// If we're using the DummyUSBDI we don't need the real USBDI.
    79 	TInt err = User::LoadLogicalDevice(KDriverUsbhubLddFileName);
    82 	TInt err = User::LoadLogicalDevice(KDriverUsbhubLddFileName);
    80 	if ( err != KErrAlreadyExists )
    83 	if ( err != KErrAlreadyExists )
    81 		{
    84 		{
    82 		LEAVEIFERRORL(err);
    85         LEAVEIFERRORL(err,OstTrace1( TRACE_NORMAL, CFDF_CONSTRUCTL, "Error when loading KDriverUsbhubLddFileName OVER DUMMYUSBDI; err=%d", err ););
    83 		}
    86 		}
    84 #endif // __OVER_DUMMYUSBDI__
    87 #endif // __OVER_DUMMYUSBDI__
    85 
    88 
    86 	LEAVEIFERRORL(iHubDriver.Open());
    89 	TInt errDr=iHubDriver.Open();
       
    90 	LEAVEIFERRORL(errDr,OstTrace1( TRACE_NORMAL, CFDF_CONSTRUCTL_DUP1, "Error when open iHubDriver; errDr=%d", errDr ););
    87 
    91 
    88 #ifdef __OVER_DUMMYUSBDI__
    92 #ifdef __OVER_DUMMYUSBDI__
    89 	LEAVEIFERRORL(iHubDriver.StartHost());
    93 	//LEAVEIFERRORL(iHubDriver.StartHost());
       
    94 	TInt errHo=iHubDriver.StartHost();
       
    95 	LEAVEIFERRORL(errHo,OstTrace1( TRACE_NORMAL, CFDF_CONSTRUCTL_DUP2, "Fail in iHubDriver.StartHost in dummy; errHo=%d", errHo ););
       
    96 
    90 #endif
    97 #endif
    91 
    98 
    92 	iActiveWaitForBusEvent = CActiveWaitForBusEvent::NewL(iHubDriver, iBusEvent, *this);
    99 	iActiveWaitForBusEvent = CActiveWaitForBusEvent::NewL(iHubDriver, iBusEvent, *this);
    93 	iActiveWaitForBusEvent->Wait();	
   100 	iActiveWaitForBusEvent->Wait();	
    94 		
   101 		
    96 	
   103 	
    97 	iActiveWaitForEComEvent = CActiveWaitForEComEvent::NewL(*this);
   104 	iActiveWaitForEComEvent = CActiveWaitForEComEvent::NewL(*this);
    98 	iActiveWaitForEComEvent->Wait();
   105 	iActiveWaitForEComEvent->Wait();
    99 	
   106 	
   100 	iEventQueue = CEventQueue::NewL(*this);
   107 	iEventQueue = CEventQueue::NewL(*this);
       
   108 	OstTraceFunctionExit0( CFDF_CONSTRUCTL_EXIT );
   101 	}
   109 	}
   102 
   110 
   103 void CFdf::CreateFunctionDriverProxiesL()
   111 void CFdf::CreateFunctionDriverProxiesL()
   104 	{
   112 	{
   105 
   113     OstTraceFunctionEntry0( CFDF_CREATEFUNCTIONDRIVERPROXIESL_ENTRY );
   106 	LOG_FUNC
       
   107 	REComSession::ListImplementationsL(TUid::Uid(KFdcEcomInterfaceUid), iImplInfoArray);
   114 	REComSession::ListImplementationsL(TUid::Uid(KFdcEcomInterfaceUid), iImplInfoArray);
   108 	const TUint count = iImplInfoArray.Count();
   115 	const TUint count = iImplInfoArray.Count();
   109 	LOGTEXT2(_L8("\tiImplInfoArray.Count() upon FDF creation  = %d"), count);
   116 	OstTrace1( TRACE_NORMAL, CFDF_CREATEFUNCTIONDRIVERPROXIESL, "\tiImplInfoArray.Count() upon FDF creation  = %d", count );
   110 #ifdef __FLOG_ACTIVE
   117 #ifdef _DEBUG
   111 	if ( count == 0 )
   118 	if ( count == 0 )
   112 		{
   119 		{
   113 		LOGTEXT(_L8("\tTHERE ARE NO FUNCTION DRIVERS PRESENT IN THE SYSTEM"));
   120         OstTrace0( TRACE_NORMAL, CFDF_CREATEFUNCTIONDRIVERPROXIESL_DUP1, "\tTHERE ARE NO FUNCTION DRIVERS PRESENT IN THE SYSTEM" );
   114 		}
   121         }
   115 	else
   122 	else
   116 		{
   123 		{
   117 		for (TInt kk = 0; kk < count; ++kk)
   124 		for (TInt32 kk = 0; kk < count; ++kk)
   118 			LOGTEXT3(_L8("\t\tFDC implementation Index:%d UID: 0x%08x"), kk, iImplInfoArray[kk]->ImplementationUid());				
   125 			OstTraceExt2( TRACE_NORMAL, CFDF_CREATEFUNCTIONDRIVERPROXIESL_DUP2,
       
   126 			        "FDC implementation UID: 0x%08x Index:%d ", 
       
   127 			        iImplInfoArray[kk]->ImplementationUid().iUid, kk);
       
   128 			
   119 		}
   129 		}
   120 #endif
   130 #endif
   121 
   131 
   122    	for ( TUint i = 0 ; i < count ; ++i )
   132    	for ( TUint i = 0 ; i < count ; ++i )
   123    		{
   133    		{
   129    		if (proxy->RomBased())
   139    		if (proxy->RomBased())
   130    			iFunctionDrivers.AddFirst(*proxy);
   140    			iFunctionDrivers.AddFirst(*proxy);
   131    		else
   141    		else
   132    			iFunctionDrivers.AddLast(*proxy);
   142    			iFunctionDrivers.AddLast(*proxy);
   133    		}
   143    		}
       
   144 	OstTraceFunctionExit0( CFDF_CREATEFUNCTIONDRIVERPROXIESL_EXIT );
   134 	}
   145 	}
   135 
   146 
   136 CFdf::~CFdf()
   147 CFdf::~CFdf()
   137 	{
   148 	{
   138 	LOG_FUNC
   149     OstTraceFunctionEntry0( CFDF_CFDF_DES_ENTRY );
   139 
   150 
   140 	// Mimic the detachment of each attached device.
   151 	// Mimic the detachment of each attached device.
   141 	TSglQueIter<CDeviceProxy> deviceIter(iDevices);
   152 	TSglQueIter<CDeviceProxy> deviceIter(iDevices);
   142 	deviceIter.SetToFirst();
   153 	deviceIter.SetToFirst();
   143 	CDeviceProxy* device;
   154 	CDeviceProxy* device;
   144 	while ( ( device = deviceIter++ ) != NULL )
   155 	while ( ( device = deviceIter++ ) != NULL )
   145 		{
   156 		{
   146 		const TUint deviceId = device->DeviceId();
   157 		const TUint deviceId = device->DeviceId();
   147 		LOGTEXT2(_L8("\tmimicking detachment of device with id %d"), device);
   158 		OstTrace1( TRACE_NORMAL, CFDF_CFDF, "mimicking detachment of device with id %d", device );
   148 		TellFdcsOfDeviceDetachment(deviceId);
   159 		TellFdcsOfDeviceDetachment(deviceId);
   149 		iDevices.Remove(*device);
   160 		iDevices.Remove(*device);
   150 		delete device;
   161 		delete device;
   151 		}
   162 		}
   152 
   163 
   172 	iHubDriver.Close();
   183 	iHubDriver.Close();
   173 
   184 
   174 #ifndef __OVER_DUMMYUSBDI__
   185 #ifndef __OVER_DUMMYUSBDI__
   175 	//If we're using the DummyUSBDI the real USBDI isn't loaded.
   186 	//If we're using the DummyUSBDI the real USBDI isn't loaded.
   176 	TInt err = User::FreeLogicalDevice(KDriverUsbhubLddFileName);
   187 	TInt err = User::FreeLogicalDevice(KDriverUsbhubLddFileName);
   177 	LOGTEXT2(_L8("\tFreeLogicalDevice( usbhubdriver ) returned %d"), err);
   188 	OstTrace1( TRACE_NORMAL, CFDF_CFDF_DUP1, "FreeLogicalDevice( usbhubdriver ) returned %d", err );
   178 	
       
   179 	err = User::FreeLogicalDevice(KDriverUsbdiLddFileName);
   189 	err = User::FreeLogicalDevice(KDriverUsbdiLddFileName);
   180 	LOGTEXT2(_L8("\tFreeLogicalDevice( usbdi ) returned %d"), err);
   190 	OstTrace1( TRACE_NORMAL, CFDF_CFDF_DUP2, "FreeLogicalDevice( usbdi ) returned %d", err );
   181 #endif // __OVER_DUMMYUSBDI__
   191 #endif // __OVER_DUMMYUSBDI__
   182 	
   192 	
   183 	delete iEventQueue;
   193 	delete iEventQueue;
   184 
   194 
   185 	// This is a worthwhile check to do at this point. If we ever don't clean
   195 	// This is a worthwhile check to do at this point. If we ever don't clean
   186 	// up iInterfaces at the *right* time, then this will be easier to debug
   196 	// up iInterfaces at the *right* time, then this will be easier to debug
   187 	// than a memory leak.
   197 	// than a memory leak.
   188 	ASSERT_DEBUG(iInterfaces.Count() == 0);
   198 	if(!(iInterfaces.Count() == 0))
       
   199 	    {
       
   200         OstTrace1( TRACE_FATAL, CFDF_CFDF_DUP3, "Memory leak from interface;Interface remains %d", iInterfaces.Count() );
       
   201         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   202 	    }
   189 
   203 
   190 	iImplInfoArray.ResetAndDestroy();
   204 	iImplInfoArray.ResetAndDestroy();
   191 	REComSession::FinalClose();
   205 	REComSession::FinalClose();
       
   206 	OstTraceFunctionExit0( CFDF_CFDF_DES_EXIT );
   192 	}
   207 	}
   193 
   208 
   194 void CFdf::EnableDriverLoading()
   209 void CFdf::EnableDriverLoading()
   195 	{
   210 	{
   196 	LOG_FUNC
   211     OstTraceFunctionEntry0( CFDF_ENABLEDRIVERLOADING_ENTRY );
   197 
       
   198 	iDriverLoadingEnabled = ETrue;
   212 	iDriverLoadingEnabled = ETrue;
   199 	}
   213 	}
   200 
   214 
   201 void CFdf::DisableDriverLoading()
   215 void CFdf::DisableDriverLoading()
   202 	{
   216 	{
   203 	LOG_FUNC
   217 	OstTraceFunctionEntry0( CFDF_DISABLEDRIVERLOADING_ENTRY );
   204 
       
   205 	iDriverLoadingEnabled = EFalse;
   218 	iDriverLoadingEnabled = EFalse;
   206 	}
   219 	}
   207 
   220 
   208 void CFdf::SetSession(CFdfSession* aSession)
   221 void CFdf::SetSession(CFdfSession* aSession)
   209 	{
   222 	{
   210 	LOG_FUNC
   223 	OstTraceFunctionEntry0( CFDF_SETSESSION_ENTRY );
   211 	LOGTEXT2(_L8("\taSession = 0x%08x"), aSession);
   224 	OstTrace1( TRACE_NORMAL, CFDF_SETSESSION, "aSession = 0x%08x", aSession );
   212 
       
   213 	iSession = aSession;
   225 	iSession = aSession;
   214 	}
   226 	}
   215 
   227 
   216 CFdfSession* CFdf::Session()
   228 CFdfSession* CFdf::Session()
   217 	{
   229 	{
   218 	return iSession;
   230 	return iSession;
   219 	}
   231 	}
   220 
   232 
   221 TBool CFdf::GetDeviceEvent(TDeviceEvent& aEvent)
   233 TBool CFdf::GetDeviceEvent(TDeviceEvent& aEvent)
   222 	{
   234 	{
   223 	LOG_FUNC
   235 	OstTraceFunctionEntry0( CFDF_GETDEVICEEVENT_ENTRY );
   224 
   236 	if(!iEventQueue)
   225 	ASSERT_DEBUG(iEventQueue);
   237 	    {
       
   238         OstTrace0( TRACE_FATAL, CFDF_GETDEVICEEVENT, "iEventQueue is empty" );
       
   239         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   240 	    }
       
   241 
   226 	return iEventQueue->GetDeviceEvent(aEvent);
   242 	return iEventQueue->GetDeviceEvent(aEvent);
   227 	}
   243 	}
   228 
   244 
   229 TBool CFdf::GetDevmonEvent(TInt& aEvent)
   245 TBool CFdf::GetDevmonEvent(TInt& aEvent)
   230 	{
   246 	{
   231 	LOG_FUNC
   247 	OstTraceFunctionEntry0( CFDF_GETDEVMONEVENT_ENTRY );
   232 
   248 	
   233 	ASSERT_DEBUG(iEventQueue);
   249 	if(!iEventQueue)
       
   250 	    {
       
   251         OstTrace0( TRACE_FATAL, CFDF_GETDEVMONEVENT, "iEventQueue is empty" );
       
   252         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   253 	    }
       
   254 
       
   255 	
   234 	return iEventQueue->GetDevmonEvent(aEvent);
   256 	return iEventQueue->GetDevmonEvent(aEvent);
   235 	}
   257 	}
   236 	
   258 	
   237 	
   259 	
   238 // An ECom plugin has been installed or removed
   260 // An ECom plugin has been installed or removed
   244 	
   266 	
   245 	}
   267 	}
   246 
   268 
   247 void CFdf::HandleEComEventReceivedL()
   269 void CFdf::HandleEComEventReceivedL()
   248 	{
   270 	{
   249 	LOG_FUNC
   271 	OstTraceFunctionEntry0( CFDF_HANDLEECOMEVENTRECEIVEDL_ENTRY );
   250 	
   272 
   251 	// There is no way to filter ecom notification to only receive ones we are interested in, also there is no way
   273 	// There is no way to filter ecom notification to only receive ones we are interested in, also there is no way
   252 	// to query ecom as to what has changed. Hence there is no option but to call ListImplementations().
   274 	// to query ecom as to what has changed. Hence there is no option but to call ListImplementations().
   253 	iImplInfoArray.ResetAndDestroy();		
   275 	iImplInfoArray.ResetAndDestroy();		
   254 			
   276 			
   255 	REComSession::ListImplementationsL(TUid::Uid(KFdcEcomInterfaceUid), iImplInfoArray);	
   277 	REComSession::ListImplementationsL(TUid::Uid(KFdcEcomInterfaceUid), iImplInfoArray);	
   256 	TUint implementationsCount = iImplInfoArray.Count();
   278 	TUint implementationsCount = iImplInfoArray.Count();
   257 	LOGTEXT2(_L8("\tiImplInfoArray.Count() after ECom notification= %d"), implementationsCount);
   279 	OstTrace1( TRACE_NORMAL, CFDF_HANDLEECOMEVENTRECEIVEDL, "iImplInfoArray.Count() after ECom notification= %d", implementationsCount );
   258 	
   280 	
   259 #ifdef __FLOG_ACTIVE
       
   260 	if ( implementationsCount == 0 )
   281 	if ( implementationsCount == 0 )
   261 		{
   282 		{
   262 		LOGTEXT(_L8("\tTHERE ARE NO FUNCTION DRIVERS PRESENT IN THE SYSTEM"));
   283         OstTrace0( TRACE_NORMAL, CFDF_HANDLEECOMEVENTRECEIVEDL_DUP1, "THERE ARE NO FUNCTION DRIVERS PRESENT IN THE SYSTEM" );
   263 		}
   284  		}
   264 		
   285 		
   265 	TSglQueIter<CFdcProxy> proxiesIterDebug(iFunctionDrivers);
   286 	TSglQueIter<CFdcProxy> proxiesIterDebug(iFunctionDrivers);
   266 	CFdcProxy* fdcDebug = NULL;		
   287 	CFdcProxy* fdcDebug = NULL;		
   267 	while ( ( fdcDebug = proxiesIterDebug++ ) != NULL )
   288 	while ( ( fdcDebug = proxiesIterDebug++ ) != NULL )
   268 		{
   289 		{
   269 		TUid fdcUid = fdcDebug->ImplUid();
   290 		TUid fdcUid = fdcDebug->ImplUid();
   270 		LOGTEXT2(_L8("\t\tOld FDC Proxy implementation UID: 0x%08x"), fdcUid.iUid);
   291 		OstTrace1( TRACE_NORMAL, CFDF_HANDLEECOMEVENTRECEIVEDL_DUP2, "Old FDC Proxy implementation UID: 0x%08x", fdcUid.iUid );
   271 		TInt fdcVersion = fdcDebug->Version();
   292 		TInt fdcVersion = fdcDebug->Version();
   272 		LOGTEXT2(_L8("\t\tFDC Proxy version UID: %d"), fdcVersion);
   293 		OstTrace1( TRACE_NORMAL, CFDF_HANDLEECOMEVENTRECEIVEDL_DUP3, "FDC Proxy version UID: %d", fdcVersion );
   273 		}		
   294 		}
   274 	LOGTEXT(_L8("\t\t------------------------------------------------------------------"));
   295 	OstTrace0( TRACE_NORMAL, CFDF_HANDLEECOMEVENTRECEIVEDL_DUP4, "------------------------------------------------------------------" );
       
   296 
   275 	for (TInt kk = 0; kk < implementationsCount; ++kk)
   297 	for (TInt kk = 0; kk < implementationsCount; ++kk)
   276 		{
   298 		{
   277 		TUid fdcUid2 = iImplInfoArray[kk]->ImplementationUid();
   299 		TUid fdcUid2 = iImplInfoArray[kk]->ImplementationUid();
   278 		LOGTEXT2(_L8("\t\tNew FDC Proxy implementation UID: 0x%08x"), fdcUid2.iUid);
   300 		OstTrace1( TRACE_NORMAL, CFDF_HANDLEECOMEVENTRECEIVEDL_DUP5, "New FDC Proxy implementation UID: 0x%08x", fdcUid2.iUid );
   279 		TInt fdcVersion2 = iImplInfoArray[kk]->Version();
   301 		TInt fdcVersion2 = iImplInfoArray[kk]->Version();
   280 		LOGTEXT2(_L8("\t\tFDC Proxy version UID: %d"), fdcVersion2);					
   302 		OstTrace1( TRACE_NORMAL, CFDF_HANDLEECOMEVENTRECEIVEDL_DUP6, "FDC Proxy version UID: %d", fdcVersion2 );
   281 		}
   303 		}
   282 #endif
       
   283 
   304 
   284 	// See if any relevant FDCs (or upgrades) have been installed or uninstalled:	
   305 	// See if any relevant FDCs (or upgrades) have been installed or uninstalled:	
   285 	
   306 	
   286 	// For each FD in the proxy list compare the uid and version with each FD returned by ECom looking
   307 	// For each FD in the proxy list compare the uid and version with each FD returned by ECom looking
   287 	// for the removal, upgrade or downgrade of an existing FD 	
   308 	// for the removal, upgrade or downgrade of an existing FD 	
   377 				iFunctionDrivers.AddFirst(*proxy);
   398 				iFunctionDrivers.AddFirst(*proxy);
   378 			else
   399 			else
   379 				iFunctionDrivers.AddLast(*proxy);			
   400 				iFunctionDrivers.AddLast(*proxy);			
   380 			}
   401 			}
   381 		}
   402 		}
       
   403 	OstTraceFunctionExit0( CFDF_HANDLEECOMEVENTRECEIVEDL_EXIT );
   382 	}
   404 	}
   383 
   405 
   384 // A bus event has occurred.
   406 // A bus event has occurred.
   385 void CFdf::MbeoBusEvent()
   407 void CFdf::MbeoBusEvent()
   386 	{
   408 	{
   387 	LOG_FUNC
   409     OstTraceFunctionEntry0( CFDF_MBEOBUSEVENT_ENTRY );
   388 	LOGTEXT2(_L8("\tiBusEvent.iEventType = %d"), iBusEvent.iEventType);
   410     OstTrace1( TRACE_NORMAL, CFDF_MBEOBUSEVENT, "iBusEvent.iEventType = %d", iBusEvent.iEventType );
   389 	LOGTEXT2(_L8("\tiBusEvent.iError = %d"), iBusEvent.iError);
   411     OstTrace1( TRACE_NORMAL, CFDF_MBEOBUSEVENT_DUP1, "iBusEvent.iError = %d", iBusEvent.iError );
   390 	LOGTEXT2(_L8("\tiBusEvent.iDeviceHandle = %d"), iBusEvent.iDeviceHandle);
   412     OstTrace1( TRACE_NORMAL, CFDF_MBEOBUSEVENT_DUP2, "iBusEvent.iDeviceHandle = %d", iBusEvent.iDeviceHandle );
   391 
   413 
   392 	switch ( iBusEvent.iEventType )
   414 	switch ( iBusEvent.iEventType )
   393 		{
   415 		{
   394 		case RUsbHubDriver::TBusEvent::EDeviceAttached:
   416 		case RUsbHubDriver::TBusEvent::EDeviceAttached:
   395 			if ( !iBusEvent.iError )
   417 			if ( !iBusEvent.iError )
   398 				HandleDeviceAttachment(iBusEvent.iDeviceHandle);
   420 				HandleDeviceAttachment(iBusEvent.iDeviceHandle);
   399 				}
   421 				}
   400 			else
   422 			else
   401 				{
   423 				{
   402 				// It was an attachment failure. Simply tell the event queue.
   424 				// It was an attachment failure. Simply tell the event queue.
   403 				ASSERT_DEBUG(iEventQueue);
   425 				if(!iEventQueue)
       
   426 				    {
       
   427                     OstTrace0( TRACE_FATAL, CFDF_MBEOBUSEVENT_DUP3, "Empty iEventQueue" );
       
   428                     __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   429 				    }
   404 				iEventQueue->AttachmentFailure(iBusEvent.iError);
   430 				iEventQueue->AttachmentFailure(iBusEvent.iError);
   405 				}
   431 				}
   406 			break;
   432 			break;
   407 	
   433 	
   408 		case RUsbHubDriver::TBusEvent::EDeviceRemoved:
   434 		case RUsbHubDriver::TBusEvent::EDeviceRemoved:
   409 			// Device detachments are always 'KErrNone'. If the device was
   435 			// Device detachments are always 'KErrNone'. If the device was
   410 			// pseudo-detached due to an overcurrent condition (for instance) then
   436 			// pseudo-detached due to an overcurrent condition (for instance) then
   411 			// the overcurrent condition is indicated through the devmon API (i.e.
   437 			// the overcurrent condition is indicated through the devmon API (i.e.
   412 			// EDevMonEvent) and the detachment is still 'KErrNone'.
   438 			// EDevMonEvent) and the detachment is still 'KErrNone'.
   413 			ASSERT_DEBUG(iBusEvent.iError == KErrNone);
   439 			if(!(iBusEvent.iError == KErrNone))
       
   440 			    {
       
   441                 OstTrace0( TRACE_NORMAL, CFDF_MBEOBUSEVENT_DUP4, "iBusEvent error" );
       
   442                 __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   443 			    }
       
   444 
   414 			HandleDeviceDetachment(iBusEvent.iDeviceHandle);
   445 			HandleDeviceDetachment(iBusEvent.iDeviceHandle);
   415 			break;
   446 			break;
   416 	
   447 	
   417 		case RUsbHubDriver::TBusEvent::EDevMonEvent:
   448 		case RUsbHubDriver::TBusEvent::EDevMonEvent:
   418 			HandleDevmonEvent(iBusEvent.iError);
   449 			HandleDevmonEvent(iBusEvent.iError);
   425 
   456 
   426 	// Only re-post the notification when we've finished examining the
   457 	// Only re-post the notification when we've finished examining the
   427 	// TBusEvent from the previous completion. (Otherwise it might get
   458 	// TBusEvent from the previous completion. (Otherwise it might get
   428 	// overwritten.)
   459 	// overwritten.)
   429 	iActiveWaitForBusEvent->Wait();
   460 	iActiveWaitForBusEvent->Wait();
       
   461 	OstTraceFunctionExit0( CFDF_MBEOBUSEVENT_EXIT );
   430 	}
   462 	}
   431 
   463 
   432 // This is the central handler for device attachment.
   464 // This is the central handler for device attachment.
   433 // We deal with device attachments in two phases.
   465 // We deal with device attachments in two phases.
   434 // The first phase is confusingly called device attachment.
   466 // The first phase is confusingly called device attachment.
   435 // The second phase is driver loading.
   467 // The second phase is driver loading.
   436 void CFdf::HandleDeviceAttachment(TUint aDeviceId)
   468 void CFdf::HandleDeviceAttachment(TUint aDeviceId)
   437 	{
   469 	{
   438 	LOG_FUNC
   470     OstTraceFunctionEntry0( CFDF_HANDLEDEVICEATTACHMENT_ENTRY );
   439 	// This is filled in by HandleDeviceAttachmentL on success.
   471 	// This is filled in by HandleDeviceAttachmentL on success.
   440 	CDeviceProxy* device;
   472 	CDeviceProxy* device;
   441 	TRAPD(err, HandleDeviceAttachmentL(aDeviceId, device));
   473 	TRAPD(err, HandleDeviceAttachmentL(aDeviceId, device));
   442 	if ( err )
   474 	if ( err )
   443 		{
   475 		{
   444 		LOGTEXT2(_L8("\terr = %d"), err);
   476         OstTrace1( TRACE_NORMAL, CFDF_HANDLEDEVICEATTACHMENT, "err = %d", err );
   445 		// There was an attachment failure, so we just increment the count of
   477 		// There was an attachment failure, so we just increment the count of
   446 		// attachment failures.
   478 		// attachment failures.
   447 		ASSERT_DEBUG(iEventQueue);
   479 		if(!iEventQueue)
       
   480 		    {
       
   481             OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEATTACHMENT_DUP1, "Empty iEventQueue" );
       
   482             __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   483 		    }
       
   484 
   448 		iEventQueue->AttachmentFailure(err);
   485 		iEventQueue->AttachmentFailure(err);
   449 		// If we failed the attachment phase, we can't try to load drivers for
   486 		// If we failed the attachment phase, we can't try to load drivers for
   450 		// the device.
   487 		// the device.
   451 
   488 
   452 		}
   489 		}
   454 		{
   491 		{
   455 		// This function always moves the 'driver loading' event from the
   492 		// This function always moves the 'driver loading' event from the
   456 		// device proxy created by HandleDeviceAttachmentL to the event queue.
   493 		// device proxy created by HandleDeviceAttachmentL to the event queue.
   457 		// This event object is always populated with the correct status and
   494 		// This event object is always populated with the correct status and
   458 		// error.
   495 		// error.
   459 		ASSERT_DEBUG(device);
   496 		if(!device)
       
   497 		    {
       
   498             OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEATTACHMENT_DUP2, "Empty device" );
       
   499             __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   500 		    }
       
   501 
   460 		DoDriverLoading(*device);
   502 		DoDriverLoading(*device);
   461 		}
   503 		}
   462 
   504 
   463 	// Finally, clean up the collection of information on the device's
   505 	// Finally, clean up the collection of information on the device's
   464 	// interfaces which was populated (maybe only partly) in
   506 	// interfaces which was populated (maybe only partly) in
   465 	// HandleDeviceAttachmentL.
   507 	// HandleDeviceAttachmentL.
   466 	iCurrentDevice = NULL;
   508 	iCurrentDevice = NULL;
   467 	iInterfaces.ResetAndDestroy();
   509 	iInterfaces.ResetAndDestroy();
       
   510 	OstTraceFunctionExit0( CFDF_HANDLEDEVICEATTACHMENT_EXIT );
   468 	}
   511 	}
   469 
   512 
   470 // This does the 'device attachment' phase of the new device attachment only.
   513 // This does the 'device attachment' phase of the new device attachment only.
   471 void CFdf::HandleDeviceAttachmentL(TUint aDeviceId, CDeviceProxy*& aDevice)
   514 void CFdf::HandleDeviceAttachmentL(TUint aDeviceId, CDeviceProxy*& aDevice)
   472 	{
   515 	{
   473 	LOG_FUNC
   516 	OstTraceFunctionEntry0( CFDF_HANDLEDEVICEATTACHMENTL_ENTRY );
   474 
       
   475 	// Create the device proxy
   517 	// Create the device proxy
   476 	aDevice = CDeviceProxy::NewL(iHubDriver, aDeviceId);
   518 	aDevice = CDeviceProxy::NewL(iHubDriver, aDeviceId);
   477 	CleanupStack::PushL(aDevice);
   519 	CleanupStack::PushL(aDevice);
   478 	iCurrentDevice = aDevice;
   520 	iCurrentDevice = aDevice;
   479 	// Get necessary descriptors (for this phase)
   521 	// Get necessary descriptors (for this phase)
   480 	LEAVEIFERRORL(aDevice->GetDeviceDescriptor(iDD));
   522 	TInt err=aDevice->GetDeviceDescriptor(iDD);
   481 	LOGTEXT2(_L8("\tiDD.USBBcd = 0x%04x"), iDD.USBBcd());
   523 	if (err<0)
   482 	LOGTEXT2(_L8("\tiDD.DeviceClass = 0x%02x"), iDD.DeviceClass());
   524 	    {
   483 	LOGTEXT2(_L8("\tiDD.DeviceSubClass = 0x%02x"), iDD.DeviceSubClass());
   525         OstTrace1( TRACE_NORMAL, CFDF_HANDLEDEVICEATTACHMENTL, "GetDeviceDescriptor error=%d", err );
   484 	LOGTEXT2(_L8("\tiDD.DeviceProtocol = 0x%02x"), iDD.DeviceProtocol());
   526         User::Leave(err);
   485 	LOGTEXT2(_L8("\tiDD.MaxPacketSize0 = %d"), iDD.MaxPacketSize0());
   527 	    }
   486 	LOGTEXT2(_L8("\tiDD.VendorId = 0x%04x"), iDD.VendorId());
   528 
   487 	LOGTEXT2(_L8("\tiDD.ProductId = 0x%04x"), iDD.ProductId());
   529 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP1, "iDD.USBBcd = 0x%04x", iDD.USBBcd() );
   488 	LOGTEXT2(_L8("\tiDD.DeviceBcd = 0x%04x"), iDD.DeviceBcd());
   530 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP2, "iDD.DeviceClass = 0x%02x", iDD.DeviceClass() );
   489 	LOGTEXT2(_L8("\tiDD.ManufacturerIndex = %d"), iDD.ManufacturerIndex());
   531 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP3, "iDD.DeviceSubClass = 0x%02x", iDD.DeviceSubClass() );
   490 	LOGTEXT2(_L8("\tiDD.ProductIndex = %d"), iDD.ProductIndex());
   532 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP4, "iDD.DeviceProtocol = 0x%02x", iDD.DeviceProtocol() );
   491 	LOGTEXT2(_L8("\tiDD.SerialNumberIndex = %d"), iDD.SerialNumberIndex());
   533 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP5, "iDD.MaxPacketSize0 = %d", iDD.MaxPacketSize0() );
   492 	LOGTEXT2(_L8("\tiDD.NumConfigurations = %d"), iDD.NumConfigurations());
   534 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP6, "iDD.VendorId = 0x%04x", iDD.VendorId() );
   493 	LEAVEIFERRORL(aDevice->GetConfigurationDescriptor(iCD));
   535 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP7, "iDD.ProductId = 0x%04x", iDD.ProductId() );
   494 	LOGTEXT2(_L8("\tiCD.TotalLength = %d"), iCD.TotalLength());
   536 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP8, "iDD.DeviceBcd = 0x%04x", iDD.DeviceBcd() );
   495 	LOGTEXT2(_L8("\tiCD.NumInterfaces = %d"), iCD.NumInterfaces());
   537 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP9, "iDD.ManufacturerIndex = %d", iDD.ManufacturerIndex() );
   496 	LOGTEXT2(_L8("\tiCD.ConfigurationValue = %d"), iCD.ConfigurationValue());
   538 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP10, "iDD.ProductIndex = %d", iDD.ProductIndex() );
   497 	LOGTEXT2(_L8("\tiCD.ConfigurationIndex = %d"), iCD.ConfigurationIndex());
   539 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP11, "iDD.SerialNumberIndex = %d", iDD.SerialNumberIndex() );
   498 	LOGTEXT2(_L8("\tiCD.Attributes = %d"), iCD.Attributes());
   540 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP12, "iDD.NumConfigurations = %d", iDD.NumConfigurations() );
   499 	LOGTEXT2(_L8("\tiCD.MaxPower = %d"), iCD.MaxPower());
   541 	err=aDevice->GetConfigurationDescriptor(iCD);
   500 
   542 	if(err<0)
       
   543 	    {
       
   544         OstTrace1( TRACE_NORMAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP13, "GetConfigurationDescriptor error=%d", err);
       
   545 	    User::Leave(err);
       
   546 	    }
       
   547 
       
   548 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP14, "iCD.TotalLength = %d", iCD.TotalLength() );
       
   549 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP15, "iCD.NumInterfaces = %d", iCD.NumInterfaces() );
       
   550 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP16, "iCD.ConfigurationValue = %d", iCD.ConfigurationValue() );
       
   551 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP17, "iCD.ConfigurationIndex = %d", iCD.ConfigurationIndex() );
       
   552 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP18, "iCD.Attributes = %d", iCD.Attributes() );
       
   553 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP19, "iCD.MaxPower = %d", iCD.MaxPower() );
       
   554 	        
   501 	const TUint8 numberOfInterfaces = iCD.NumInterfaces();
   555 	const TUint8 numberOfInterfaces = iCD.NumInterfaces();
   502 	LOGTEXT2(_L8("\tnumberOfInterfaces (field in config descriptor) = %d)"), numberOfInterfaces);
   556 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP20, "numberOfInterfaces (field in config descriptor) = %d)", numberOfInterfaces );
   503 	if ( numberOfInterfaces == 0 )
   557 	if ( numberOfInterfaces == 0 )
   504 		{
   558 		{
   505 		LEAVEL(KErrUsbConfigurationHasNoInterfaces);
   559 	    OstTrace0( TRACE_NORMAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP21, "Error: Usb Configuration Has No Interfaces");
       
   560 	    User::Leave(KErrUsbConfigurationHasNoInterfaces);
   506 		}
   561 		}
   507 
   562 
   508 	// Walk the configuration bundle. Collect information on each interface
   563 	// Walk the configuration bundle. Collect information on each interface
   509 	// (its number, class, subclass and protocol). This populates iInterfaces.
   564 	// (its number, class, subclass and protocol). This populates iInterfaces.
   510 	ASSERT_DEBUG(iInterfaces.Count() == 0);
   565 	if(!(iInterfaces.Count() == 0))
   511 	ASSERT_ALWAYS(iCurrentDevice);
   566 	    {
       
   567         OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP22, "Error: Usb Configuration Has No Interfaces");
       
   568         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   569 	    }
       
   570 
       
   571 	if(!iCurrentDevice)
       
   572 	    {
       
   573         OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP23, "Empty iCurrentDevice");
       
   574         User::Panic(KPanicCategory,__LINE__);
       
   575 	    }
       
   576 
   512 	ParseL(iCD);
   577 	ParseL(iCD);
   513 
   578 
   514 	// Log iInterfaces.
   579 	// Log iInterfaces.
   515 	const TUint interfaceCount = iInterfaces.Count();
   580 	const TUint interfaceCount = iInterfaces.Count();
   516 	LOGTEXT2(_L8("\tinterfaceCount (parsed from bundle) = %d"), interfaceCount);
   581 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP24, "interfaceCount (parsed from bundle) = %d", interfaceCount );
   517 #ifdef __FLOG_ACTIVE
   582 #ifdef _DEBUG
   518 	LOGTEXT(_L8("\tLogging iInterfaces:"));
   583 	OstTrace0( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP25, "Logging iInterfaces:");
   519 	for ( TUint ii = 0 ; ii < interfaceCount ; ++ii )
   584 	for ( TUint ii = 0 ; ii < interfaceCount ; ++ii )
   520 		{
   585 		{
   521 		const TInterfaceInfo* ifInfo = iInterfaces[ii];
   586 		const TInterfaceInfo* ifInfo = iInterfaces[ii];
   522 		ASSERT_DEBUG(ifInfo);
   587 		if(!ifInfo)
   523 		LOGTEXT6(_L8("\t\tiInterfaces[%d]: number %d, interface class 0x%02x subclass 0x%02x protocol 0x%02x"),
   588 		    {
       
   589             OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP26, "Empty ifInfo");
       
   590             __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   591 		    }
       
   592 		
       
   593 		OstTraceExt5(TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP27, "\t\tiInterfaces[%d]: number %d, interface class 0x%02x subclass 0x%02x protocol 0x%02x",
   524 			ii,
   594 			ii,
   525 			ifInfo->iNumber,
   595 			ifInfo->iNumber,
   526 			ifInfo->iClass,
   596 			ifInfo->iClass,
   527 			ifInfo->iSubclass,
   597 			ifInfo->iSubclass,
   528 			ifInfo->iProtocol
   598 			ifInfo->iProtocol
   529 			);
   599 			);
   530 		}
   600 		}
   531 #endif
   601 #endif
   532 
   602 	
   533 	// Check that the config's NumInterfaces is the same as the actual number
   603 	// Check that the config's NumInterfaces is the same as the actual number
   534 	// of interface descriptors we found. We rely on this later on.
   604 	// of interface descriptors we found. We rely on this later on.
   535 	if ( numberOfInterfaces != interfaceCount )
   605 	if ( numberOfInterfaces != interfaceCount )
   536 		{
   606 		{
   537 		LEAVEL(KErrUsbInterfaceCountMismatch);
   607         OstTrace0( TRACE_NORMAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP28, "KErrUsbInterfaceCountMismatch");
       
   608 		User::Leave(KErrUsbInterfaceCountMismatch);
   538 		}
   609 		}
   539 
   610 
   540 	// Check that each interface number in iInterfaces is unique.
   611 	// Check that each interface number in iInterfaces is unique.
   541 	if ( interfaceCount > 1 )
   612 	if ( interfaceCount > 1 )
   542 		{
   613 		{
   543 		for ( TUint ii = 0 ; ii < interfaceCount ; ++ii )
   614 		for ( TUint ii = 0 ; ii < interfaceCount ; ++ii )
   544 			{
   615 			{
   545 			const TInterfaceInfo* lhs = iInterfaces[ii];
   616 			const TInterfaceInfo* lhs = iInterfaces[ii];
   546 			ASSERT_DEBUG(lhs);
   617 			if(!lhs)
       
   618 			    {
       
   619                 OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP29, "Empty lhs");
       
   620                 __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   621 			    }
       
   622 
   547 			for ( TUint jj = ii+1 ; jj < interfaceCount ; ++jj )
   623 			for ( TUint jj = ii+1 ; jj < interfaceCount ; ++jj )
   548 				{
   624 				{
   549 				const TInterfaceInfo* rhs = iInterfaces[jj];
   625 				const TInterfaceInfo* rhs = iInterfaces[jj];
   550 				ASSERT_DEBUG(rhs);
   626 				if(!rhs)
       
   627 				    {
       
   628                     OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP30, "Empty rhs");
       
   629                     __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   630 				    }
       
   631 
   551 				if ( lhs->iNumber == rhs->iNumber )
   632 				if ( lhs->iNumber == rhs->iNumber )
   552 					{
   633 					{
   553 					LEAVEL(KErrUsbDuplicateInterfaceNumbers);
   634                     OstTrace1( TRACE_NORMAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP31, "KErrUsbDuplicateInterfaceNumbers; iNumber=%d", lhs->iNumber);
       
   635 					User::Leave(KErrUsbDuplicateInterfaceNumbers);
   554 					}
   636 					}
   555 				}
   637 				}
   556 			}
   638 			}
   557 		}
   639 		}
   558 
   640 
   562 	if (iDevices.IsEmpty())
   644 	if (iDevices.IsEmpty())
   563 		{
   645 		{
   564 		TInt err = User::LoadLogicalDevice(KDriverUsbdiLddFileName);
   646 		TInt err = User::LoadLogicalDevice(KDriverUsbdiLddFileName);
   565 		if ( err != KErrAlreadyExists )
   647 		if ( err != KErrAlreadyExists )
   566 			{
   648 			{
   567 			LEAVEIFERRORL(err);
   649 			LEAVEIFERRORL(err,OstTrace1( TRACE_NORMAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP32, "Load Logical Device error; error=%d", err););
   568 			}
   650 			}
   569 		}
   651 		}
   570 #endif // __OVER_DUMMYUSBDI__
   652 #endif // __OVER_DUMMYUSBDI__
   571 	
   653 	
   572 	// Now we know we've succeeded with a device attachment, remove the device
   654 	// Now we know we've succeeded with a device attachment, remove the device
   573 	// proxy from the cleanup stack and put it on the TSglQue.
   655 	// proxy from the cleanup stack and put it on the TSglQue.
   574 	CLEANUPSTACK_POP1(aDevice);
   656 	CLEANUPSTACK_POP1(aDevice);
   575 	iDevices.AddLast(*aDevice);
   657 	iDevices.AddLast(*aDevice);
   576 	// Also put an event on the event queue.
   658 	// Also put an event on the event queue.
   577 	TDeviceEvent* const attachmentEvent = aDevice->GetAttachmentEventObject();
   659 	TDeviceEvent* const attachmentEvent = aDevice->GetAttachmentEventObject();
   578 	ASSERT_DEBUG(attachmentEvent);
   660 	
       
   661 	if(!attachmentEvent)
       
   662 	    {
       
   663         OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP33, "Empty attachmentEvent");
       
   664         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   665 	    }
       
   666 
   579 	attachmentEvent->iInfo.iVid = iDD.VendorId();
   667 	attachmentEvent->iInfo.iVid = iDD.VendorId();
   580 	attachmentEvent->iInfo.iPid = iDD.ProductId();
   668 	attachmentEvent->iInfo.iPid = iDD.ProductId();
   581 	attachmentEvent->iInfo.iError = KErrNone;
   669 	attachmentEvent->iInfo.iError = KErrNone;
   582 	ASSERT_DEBUG(iEventQueue);
   670 	if(!iEventQueue)
       
   671 	    {
       
   672         OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEATTACHMENTL_DUP34, "Empty iEventQueue");
       
   673         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   674 	    }
       
   675 
   583 	iEventQueue->AddDeviceEvent(*attachmentEvent);
   676 	iEventQueue->AddDeviceEvent(*attachmentEvent);
   584 	LOGTEXT2(_L8("***USB HOST STACK: SUCCESSFUL ATTACHMENT OF DEVICE (id %d)"), aDeviceId);
   677 	OstTrace1( TRACE_DUMP, CFDF_HANDLEDEVICEATTACHMENTL_DUP35, "***USB HOST STACK: SUCCESSFUL ATTACHMENT OF DEVICE (id %d)", aDeviceId );
       
   678 	
       
   679 	OstTraceFunctionExit0( CFDF_HANDLEDEVICEATTACHMENTL_EXIT );
   585 	}
   680 	}
   586 
   681 
   587 void CFdf::DoDriverLoading(CDeviceProxy& aDevice)
   682 void CFdf::DoDriverLoading(CDeviceProxy& aDevice)
   588 	{
   683 	{
   589 	LOG_FUNC
   684     OstTraceFunctionEntry0( CFDF_DODRIVERLOADING_ENTRY );
   590 
       
   591 	// Leaving or returning from DoDriverLoadingL is the trigger to put the
   685 	// Leaving or returning from DoDriverLoadingL is the trigger to put the
   592 	// 'driver loading' event object on the event queue. It must already have
   686 	// 'driver loading' event object on the event queue. It must already have
   593 	// been populated correctly (the actual error code it left with doesn't
   687 	// been populated correctly (the actual error code it left with doesn't
   594 	// feed into the driver loading event).
   688 	// feed into the driver loading event).
   595 	TRAP_IGNORE(DoDriverLoadingL(aDevice));
   689 	TRAP_IGNORE(DoDriverLoadingL(aDevice));
   596 	
   690 	
   597 	TDeviceEvent* const driverLoadingEvent = aDevice.GetDriverLoadingEventObject();
   691 	TDeviceEvent* const driverLoadingEvent = aDevice.GetDriverLoadingEventObject();
   598 	ASSERT_DEBUG(driverLoadingEvent);
   692 	if(!driverLoadingEvent)
       
   693 	    {
       
   694         OstTrace0( TRACE_FATAL, CFDF_DODRIVERLOADING, "Empty driverLoadingEvent" );
       
   695         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   696 	    }
       
   697 
   599 	// The driver loading event object says whether driver loading succeeded
   698 	// The driver loading event object says whether driver loading succeeded
   600 	// (all interfaces were claimed without error), partly succeeded (not all
   699 	// (all interfaces were claimed without error), partly succeeded (not all
   601 	// interfaces were claimed without error), or failed (no interfaces were
   700 	// interfaces were claimed without error), or failed (no interfaces were
   602 	// claimed without error). This information is intended for USBMAN so it
   701 	// claimed without error). This information is intended for USBMAN so it
   603 	// can tell the user, but we also use it now to suspend the device if
   702 	// can tell the user, but we also use it now to suspend the device if
   606 		{
   705 		{
   607 		// We can't do anything with error here. Suspending the device is for
   706 		// We can't do anything with error here. Suspending the device is for
   608 		// power-saving reasons and is not critical.
   707 		// power-saving reasons and is not critical.
   609 		(void)aDevice.Suspend();
   708 		(void)aDevice.Suspend();
   610 		}
   709 		}
   611 	ASSERT_DEBUG(iEventQueue);
   710 	if(!iEventQueue)
       
   711 	    {
       
   712         OstTrace0( TRACE_FATAL, CFDF_DODRIVERLOADING_DUP1, "Empty iEventQueue" );
       
   713         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   714 	    }
       
   715 
   612 	iEventQueue->AddDeviceEvent(*driverLoadingEvent);
   716 	iEventQueue->AddDeviceEvent(*driverLoadingEvent);
       
   717 	OstTraceFunctionExit0( CFDF_DODRIVERLOADING_EXIT );
   613 	}
   718 	}
   614 
   719 
   615 
   720 
   616 void CFdf::DoDriverLoadingL(CDeviceProxy& aDevice)
   721 void CFdf::DoDriverLoadingL(CDeviceProxy& aDevice)
   617 	{
   722 	{
   618 	LOG_FUNC
   723     OstTraceFunctionEntry0( CFDF_DODRIVERLOADINGL_ENTRY );
   619 
       
   620 	// Check whether driver loading is enabled.
   724 	// Check whether driver loading is enabled.
   621 	if ( !iDriverLoadingEnabled )
   725 	if ( !iDriverLoadingEnabled )
   622 		{
   726 		{
   623 		// Complete driver load failure scenario.
   727 		// Complete driver load failure scenario.
   624 		aDevice.SetDriverLoadingEventData(EDriverLoadFailure, KErrUsbDriverLoadingDisabled);
   728 		aDevice.SetDriverLoadingEventData(EDriverLoadFailure, KErrUsbDriverLoadingDisabled);
   625 		LEAVEL(KErrGeneral);
   729 		
   626 	}
   730 		OstTrace1( TRACE_NORMAL, CFDF_DODRIVERLOADINGL, "Leave with error %d", KErrGeneral );
       
   731 		User::Leave(KErrGeneral);
       
   732 		}
   627 
   733 
   628 
   734 
   629 	// Set this member up so that when the FDC calls TokenForInterface we call
   735 	// Set this member up so that when the FDC calls TokenForInterface we call
   630 	// the right proxy object.
   736 	// the right proxy object.
   631 
   737 
   647 	// in the new attached device. Once we finished the device level searching of FDC and we couldn't find any, we
   753 	// in the new attached device. Once we finished the device level searching of FDC and we couldn't find any, we
   648 	// break down the loading process
   754 	// break down the loading process
   649 	if (aDevice.HasIADFlag() && !functionDriverFound)
   755 	if (aDevice.HasIADFlag() && !functionDriverFound)
   650 		{
   756 		{
   651 		aDevice.SetDriverLoadingEventData(EDriverLoadFailure, KErrUsbUnsupportedDevice);
   757 		aDevice.SetDriverLoadingEventData(EDriverLoadFailure, KErrUsbUnsupportedDevice);
   652 		LEAVEL(KErrGeneral);		
   758 		OstTrace0( TRACE_NORMAL, CFDF_DODRIVERLOADINGL_DUP1, "Leave with function Driver not Found" );
       
   759 		User::Leave(KErrGeneral);
   653 		}
   760 		}
   654 	// If a device FD is found then it is supposed to claim all the interfaces, if it didn't then report
   761 	// If a device FD is found then it is supposed to claim all the interfaces, if it didn't then report
   655 	// a partial success but don't offer unclaimed interfaces to any other FD.
   762 	// a partial success but don't offer unclaimed interfaces to any other FD.
   656 	const TUint interfaceCount = iInterfaces.Count();
   763 	const TUint interfaceCount = iInterfaces.Count();
   657 
   764 
   665 	// (a) are there any unclaimed interfaces remaining?
   772 	// (a) are there any unclaimed interfaces remaining?
   666 	// (b) what's in collectedErr?
   773 	// (b) what's in collectedErr?
   667 	// Whether all interfaces were taken, some, or none, collectedErr may have
   774 	// Whether all interfaces were taken, some, or none, collectedErr may have
   668 	// an error in it or KErrNone. We use specific error codes in some cases.			
   775 	// an error in it or KErrNone. We use specific error codes in some cases.			
   669 	TUint unclaimedInterfaces = UnclaimedInterfaceCount();
   776 	TUint unclaimedInterfaces = UnclaimedInterfaceCount();
   670 	LOGTEXT2(_L8("\tunclaimedInterfaces = %d"), unclaimedInterfaces);
   777 	OstTrace1( TRACE_DUMP, CFDF_DODRIVERLOADINGL_DUP2, "unclaimedInterfaces = %d", unclaimedInterfaces );
   671 	LOGTEXT2(_L8("\tanySuccess = %d"), anySuccess);
   778 	OstTrace1( TRACE_DUMP, CFDF_DODRIVERLOADINGL_DUP3, "anySuccess = %d", anySuccess );
   672 	LOGTEXT2(_L8("\tcollectedErr = %d"), collectedErr);
   779 	OstTrace1( TRACE_DUMP, CFDF_DODRIVERLOADINGL_DUP4, "collectedErr = %d", collectedErr );
   673 	ASSERT_DEBUG(unclaimedInterfaces <= interfaceCount);
   780 	if(!(unclaimedInterfaces <= interfaceCount))
       
   781 	    {
       
   782         OstTrace0( TRACE_FATAL, CFDF_DODRIVERLOADINGL_DUP5, "interface Count error" );
       
   783         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   784 	    }
       
   785 
   674 
   786 
   675 	if(iDeviceDetachedTooEarly)
   787 	if(iDeviceDetachedTooEarly)
   676 		{
   788 		{
   677 		LOGTEXT(_L8("\tDevice has been detached too early!"));
   789         OstTrace0( TRACE_NORMAL, CFDF_DODRIVERLOADINGL_DUP6, "Device has been detached too early!" );
   678 		iDeviceDetachedTooEarly = EFalse;
   790 		iDeviceDetachedTooEarly = EFalse;
   679 		// the choice of having the status to be EDriverLoadPartialSuccess
   791 		// the choice of having the status to be EDriverLoadPartialSuccess
   680 		// was not to clash with trying to suspend the device because
   792 		// was not to clash with trying to suspend the device because
   681 		// of a total failure to load the FD.(because device is detached)
   793 		// of a total failure to load the FD.(because device is detached)
   682 		// even though that a FDC has been created
   794 		// even though that a FDC has been created
   688 	else
   800 	else
   689 		{
   801 		{
   690 		SetFailureStatus(unclaimedInterfaces, interfaceCount, anySuccess, collectedErr, aDevice);
   802 		SetFailureStatus(unclaimedInterfaces, interfaceCount, anySuccess, collectedErr, aDevice);
   691 		}// iDeviceDetachedTooEarly
   803 		}// iDeviceDetachedTooEarly
   692 
   804 
       
   805 	OstTraceFunctionExit0( CFDF_DODRIVERLOADINGL_EXIT );
   693 	}
   806 	}
   694 
   807 
   695 // Recursive function, originally called with the configuration descriptor.
   808 // Recursive function, originally called with the configuration descriptor.
   696 // Builds up information on the interface descriptors in the configuration
   809 // Builds up information on the interface descriptors in the configuration
   697 // bundle.
   810 // bundle.
   698 void CFdf::ParseL(TUsbGenericDescriptor& aDesc)
   811 void CFdf::ParseL(TUsbGenericDescriptor& aDesc)
   699 	{
   812 	{
   700 	LOG_FUNC
   813     OstTraceFunctionEntry0( CFDF_PARSEL_ENTRY );
   701 	LOGTEXT2(_L8("\t&aDesc = 0x%08x"), &aDesc);
   814     OstTrace1( TRACE_DUMP, CFDF_PARSEL, "&aDesc = 0x%08x", &aDesc );
   702 	LOGTEXT2(_L8("\taDesc.ibDescriptorType = %d"), aDesc.ibDescriptorType);
   815     OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP1, "aDesc.ibDescriptorType = %d", aDesc.ibDescriptorType );
   703 	LOGTEXT2(_L8("\taDesc.iFirstChild = 0x%08x"), aDesc.iFirstChild);
   816     OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP2, "aDesc.iFirstChild = 0x%08x", aDesc.iFirstChild );
   704 	LOGTEXT2(_L8("\taDesc.iNextPeer = 0x%08x"), aDesc.iNextPeer);
   817     OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP3, "aDesc.iNextPeer = 0x%08x", aDesc.iNextPeer );
   705 
   818     
   706 	if ( aDesc.ibDescriptorType == EInterface )
   819     if ( aDesc.ibDescriptorType == EInterface )
   707 		{
   820 		{
   708 		// Add interface information to collection, but only if it's alternate
   821 		// Add interface information to collection, but only if it's alternate
   709 		// setting 0.
   822 		// setting 0.
   710 		const TUsbInterfaceDescriptor& ifDesc = static_cast<TUsbInterfaceDescriptor&>(aDesc);
   823 		const TUsbInterfaceDescriptor& ifDesc = static_cast<TUsbInterfaceDescriptor&>(aDesc);
   711 		if ( ifDesc.AlternateSetting() == 0 ) // hard-coded '0' means the default (initial configuration) setting
   824 		if ( ifDesc.AlternateSetting() == 0 ) // hard-coded '0' means the default (initial configuration) setting
   712 			{
   825 			{
   713 			LOGTEXT2(_L8("\tifDesc.InterfaceNumber = %d"), ifDesc.InterfaceNumber());
   826             OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP4, "ifDesc.InterfaceNumber = %d", ifDesc.InterfaceNumber() );
   714 			LOGTEXT2(_L8("\tifDesc.NumEndpoints = %d"), ifDesc.NumEndpoints());
   827             OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP5, "ifDesc.NumEndpoints = %d", ifDesc.NumEndpoints() );
   715 			LOGTEXT2(_L8("\tifDesc.InterfaceClass = 0x%02x"), ifDesc.InterfaceClass());
   828             OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP6, "ifDesc.InterfaceClass = 0x%02x", ifDesc.InterfaceClass() );
   716 			LOGTEXT2(_L8("\tifDesc.InterfaceSubClass = 0x%02x"), ifDesc.InterfaceSubClass());
   829             OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP7, "ifDesc.InterfaceSubClass = 0x%02x", ifDesc.InterfaceSubClass() );
   717 			LOGTEXT2(_L8("\tifDesc.InterfaceProtocol = 0x%02x"), ifDesc.InterfaceProtocol());
   830             OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP8, "ifDesc.InterfaceProtocol = 0x%02x", ifDesc.InterfaceProtocol() );
   718 			LOGTEXT2(_L8("\tifDesc.Interface = %d"), ifDesc.Interface());
   831             OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP9, "ifDesc.Interface = %d", ifDesc.Interface() );
   719 
   832             
   720 			TInterfaceInfo* ifInfo = TInterfaceInfo::NewL(iInterfaces);
   833 			TInterfaceInfo* ifInfo = TInterfaceInfo::NewL(iInterfaces);
   721 			ifInfo->iNumber = ifDesc.InterfaceNumber();
   834 			ifInfo->iNumber = ifDesc.InterfaceNumber();
   722 			ifInfo->iClass = ifDesc.InterfaceClass();
   835 			ifInfo->iClass = ifDesc.InterfaceClass();
   723 			ifInfo->iSubclass = ifDesc.InterfaceSubClass();
   836 			ifInfo->iSubclass = ifDesc.InterfaceSubClass();
   724 			ifInfo->iProtocol = ifDesc.InterfaceProtocol();
   837 			ifInfo->iProtocol = ifDesc.InterfaceProtocol();
   733 		}
   846 		}
   734 	else if (aDesc.ibDescriptorType == EOTG)
   847 	else if (aDesc.ibDescriptorType == EOTG)
   735 		{
   848 		{
   736 		// OTG descriptor found
   849 		// OTG descriptor found
   737 		const TUsbOTGDescriptor& otgDesc = static_cast<TUsbOTGDescriptor&>(aDesc);
   850 		const TUsbOTGDescriptor& otgDesc = static_cast<TUsbOTGDescriptor&>(aDesc);
   738 
   851 		OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP10, "otgDesc.Attributes = %d", otgDesc.Attributes() );
   739 		LOGTEXT2(_L8("\totgDesc.Attributes = %b"), otgDesc.Attributes());
   852 		OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP11, "otgDesc.HNPSupported = %d", otgDesc.HNPSupported() );
   740 		LOGTEXT2(_L8("\totgDesc.HNPSupported = %d"), otgDesc.HNPSupported());
   853 		OstTrace1( TRACE_DUMP, CFDF_PARSEL_DUP12, "otgDesc.SRPSupported = %d", otgDesc.SRPSupported() );
   741 		LOGTEXT2(_L8("\totgDesc.SRPSupported = %d"), otgDesc.SRPSupported());
       
   742 		
   854 		
   743 		iCurrentDevice->SetOtgDescriptorL(otgDesc);
   855 		iCurrentDevice->SetOtgDescriptorL(otgDesc);
   744 		}
   856 		}
   745 
   857 
   746 	TUsbGenericDescriptor* const firstChild = aDesc.iFirstChild;
   858 	TUsbGenericDescriptor* const firstChild = aDesc.iFirstChild;
   752 	TUsbGenericDescriptor* const nextPeer = aDesc.iNextPeer;
   864 	TUsbGenericDescriptor* const nextPeer = aDesc.iNextPeer;
   753 	if ( nextPeer )
   865 	if ( nextPeer )
   754 		{
   866 		{
   755 		ParseL(*nextPeer);
   867 		ParseL(*nextPeer);
   756 		}
   868 		}
       
   869 	OstTraceFunctionExit0( CFDF_PARSEL_EXIT );
   757 	}
   870 	}
   758 
   871 
   759 // Method that uses only one array to hold the unclaimed interface numbers.
   872 // Method that uses only one array to hold the unclaimed interface numbers.
   760 void CFdf::FindDriversForInterfacesUsingSpecificKeyL(CDeviceProxy& aDevice,
   873 void CFdf::FindDriversForInterfacesUsingSpecificKeyL(CDeviceProxy& aDevice,
   761 													TInt& aCollectedErr,
   874 													TInt& aCollectedErr,
   762 													TBool& aAnySuccess,			
   875 													TBool& aAnySuccess,			
   763 													RArray<TUint>& aInterfacesNumberArray, 
   876 													RArray<TUint>& aInterfacesNumberArray, 
   764 													TInterfaceSearchKeys aKey)	
   877 													TInterfaceSearchKeys aKey)	
   765 	{
   878 	{
   766 	LOG_FUNC
   879     OstTraceFunctionEntry0( CFDF_FINDDRIVERSFORINTERFACESUSINGSPECIFICKEYL_ENTRY );
   767 
   880  
   768 	const TUint interfaceCount = iInterfaces.Count();
   881 	const TUint interfaceCount = iInterfaces.Count();
   769 	for ( TUint ii = 0 ; ii < interfaceCount ; ++ii )
   882 	for ( TUint ii = 0 ; ii < interfaceCount ; ++ii )
   770 		{
   883 		{
   771 		TInterfaceInfo* ifInfo = iInterfaces[ii];		
   884 		TInterfaceInfo* ifInfo = iInterfaces[ii];		
   772 		ASSERT_DEBUG(ifInfo);
   885 		if(!ifInfo)
       
   886 		    {
       
   887             OstTrace0( TRACE_FATAL, CFDF_FINDDRIVERSFORINTERFACESUSINGSPECIFICKEYL, "Empty ifInfo" );
       
   888             __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
   889 		    }
   773 		
   890 		
   774 		if ((ifInfo->iClaimed) ||
   891 		if ((ifInfo->iClaimed) ||
   775 			(aKey == EVendorInterfacesubclassInterfaceprotocol && ifInfo->iClass != KVendorSpecificInterfaceClassValue)||	
   892 			(aKey == EVendorInterfacesubclassInterfaceprotocol && ifInfo->iClass != KVendorSpecificInterfaceClassValue)||	
   776 			(aKey == EVendorInterfacesubclass && ifInfo->iClass != KVendorSpecificInterfaceClassValue) ||
   893 			(aKey == EVendorInterfacesubclass && ifInfo->iClass != KVendorSpecificInterfaceClassValue) ||
   777 			(aKey == EInterfaceclassInterfacesubclassInterfaceprotocol && ifInfo->iClass == KVendorSpecificInterfaceClassValue) ||
   894 			(aKey == EInterfaceclassInterfacesubclassInterfaceprotocol && ifInfo->iClass == KVendorSpecificInterfaceClassValue) ||
   783 			}
   900 			}
   784 		
   901 		
   785 
   902 
   786 		TBuf8<KMaxSearchKeyLength> searchKey;
   903 		TBuf8<KMaxSearchKeyLength> searchKey;
   787 		FormatInterfaceSearchKey(searchKey, aKey, *ifInfo);
   904 		FormatInterfaceSearchKey(searchKey, aKey, *ifInfo);
   788 
   905 		OstTraceExt1( TRACE_NORMAL, CFDF_FINDDRIVERSFORINTERFACESUSINGSPECIFICKEYL_DUP1, "searchKey = \"%S\"", searchKey );
   789 		LOGTEXT2(_L8("\tsearchKey = \"%S\""), &searchKey);
       
   790 		// RArray<TUint>* array = &aInterfacesNumberArray;
   906 		// RArray<TUint>* array = &aInterfacesNumberArray;
   791 
   907 
   792 		FindDriverForInterfaceUsingSpecificKey(aDevice, aCollectedErr, aAnySuccess, aInterfacesNumberArray, searchKey);
   908 		FindDriverForInterfaceUsingSpecificKey(aDevice, aCollectedErr, aAnySuccess, aInterfacesNumberArray, searchKey);
   793 
   909 
   794 		// Putting ii+1 as the starting offset is to remove the interface on which
   910 		// Putting ii+1 as the starting offset is to remove the interface on which
   795 		// the searching have been done.		
   911 		// the searching have been done.		
   796 		RebuildUnClaimedInterfacesArrayL(aDevice, aInterfacesNumberArray, ii+1);
   912 		RebuildUnClaimedInterfacesArrayL(aDevice, aInterfacesNumberArray, ii+1);
   797 		}
   913 		}
       
   914 	OstTraceFunctionExit0( CFDF_FINDDRIVERSFORINTERFACESUSINGSPECIFICKEYL_EXIT );
   798 	}
   915 	}
   799 
   916 
   800 
   917 
   801 
   918 
   802 // Called for one interface, to find a Function Driver on the basis of a
   919 // Called for one interface, to find a Function Driver on the basis of a
   806 								   TInt& aCollectedErr,
   923 								   TInt& aCollectedErr,
   807 								   TBool& aAnySuccess,
   924 								   TBool& aAnySuccess,
   808 								   RArray<TUint>& aInterfacesGivenToFdc,
   925 								   RArray<TUint>& aInterfacesGivenToFdc,
   809 								   const TDesC8& aSearchKey)
   926 								   const TDesC8& aSearchKey)
   810 	{
   927 	{
   811 
   928     OstTraceFunctionEntry0( CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY_ENTRY );
   812 	LOG_FUNC
   929 	OstTraceExt1( TRACE_NORMAL, CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY, "aSearchKey = \"%S\"", aSearchKey );
   813 	LOGTEXT2(_L8("\taSearchKey = \"%S\""), &aSearchKey);
       
   814 
   930 
   815 	// Find an FDC matching this search key.
   931 	// Find an FDC matching this search key.
   816 	TSglQueIter<CFdcProxy> iter(iFunctionDrivers);
   932 	TSglQueIter<CFdcProxy> iter(iFunctionDrivers);
   817 	iter.SetToFirst();
   933 	iter.SetToFirst();
   818 	CFdcProxy* fdc;
   934 	CFdcProxy* fdc;
   819 
   935 
   820 	while ( ( fdc = iter++ ) != NULL )
   936 	while ( ( fdc = iter++ ) != NULL )
   821 		{
   937 		{
   822 		LOGTEXT2(_L8("\tFDC's default_data field = \"%S\""), &fdc->DefaultDataField());
   938         OstTraceExt1( TRACE_NORMAL, CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY_DUP1, "FDC's default_data field = \"%S\"", fdc->DefaultDataField() );
       
   939 
   823 #ifdef _DEBUG
   940 #ifdef _DEBUG
   824 	// having these two together in the debug window is helpful for interactive debugging
   941 	// having these two together in the debug window is helpful for interactive debugging
   825 	TBuf8<KMaxSearchKeyLength > fd_key;
   942 	TBuf8<KMaxSearchKeyLength > fd_key;
   826 	fd_key.Append(fdc->DefaultDataField().Ptr(), fdc->DefaultDataField().Length() > KMaxSearchKeyLength ? KMaxSearchKeyLength : fdc->DefaultDataField().Length());
   943 	fd_key.Append(fdc->DefaultDataField().Ptr(), fdc->DefaultDataField().Length() > KMaxSearchKeyLength ? KMaxSearchKeyLength : fdc->DefaultDataField().Length());
   827 	TBuf8<KMaxSearchKeyLength > searchKey;
   944 	TBuf8<KMaxSearchKeyLength > searchKey;
   844 			// suitable FDC we found so fa.
   961 			// suitable FDC we found so fa.
   845 			if (!aDevice.MultipleDriversFlag() && FindMultipleFDs(aSearchKey, iter))
   962 			if (!aDevice.MultipleDriversFlag() && FindMultipleFDs(aSearchKey, iter))
   846 				{
   963 				{
   847 				aDevice.SetMultipleDriversFlag();
   964 				aDevice.SetMultipleDriversFlag();
   848 				}
   965 				}
   849 			
   966 			OstTrace1( TRACE_NORMAL, CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY_DUP2, "found matching FDC (0x%08x)", fdc );
   850 			LOGTEXT2(_L8("\tfound matching FDC (0x%08x)"), fdc);
   967 
   851 #ifdef __FLOG_ACTIVE
       
   852 			const TUint count = aInterfacesGivenToFdc.Count();
   968 			const TUint count = aInterfacesGivenToFdc.Count();
   853 			LOGTEXT2(_L8("\tlogging aInterfacesGivenToFdc (interfaces being offered to the FDC): count = %d"), count);
   969 			OstTrace1( TRACE_NORMAL, CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY_DUP3, "logging aInterfacesGivenToFdc (interfaces being offered to the FDC): count = %d", count );
   854 			for ( TUint ii = 0 ; ii < count ; ++ii )
   970 			for ( TUint ii = 0 ; ii < count ; ++ii )
   855 				{
   971 				{
   856 				LOGTEXT3(_L8("\t\tindex %d: interface number %d"), ii, aInterfacesGivenToFdc[ii]);
   972                 OstTraceExt2( TRACE_NORMAL, CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY_DUP4, 
   857 				}
   973                         "index %u: interface number %u", 
   858 #endif
   974                         ii, aInterfacesGivenToFdc[ii] );
       
   975 			    }
   859 			TInt err = fdc->NewFunction(aDevice.DeviceId(), aInterfacesGivenToFdc, iDD, iCD);
   976 			TInt err = fdc->NewFunction(aDevice.DeviceId(), aInterfacesGivenToFdc, iDD, iCD);
   860 			LOGTEXT2(_L8("\tNewFunction returned %d"), err);
   977 			OstTrace1( TRACE_NORMAL, CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY_DUP5, "NewFunction returned %d", err );
       
   978 			            
   861 			// To correctly determine whether the driver load for the whole
   979 			// To correctly determine whether the driver load for the whole
   862 			// configuration was a complete failure, a partial success or a
   980 			// configuration was a complete failure, a partial success or a
   863 			// complete success, we need to collect any non-KErrNone error
   981 			// complete success, we need to collect any non-KErrNone error
   864 			// from this, and whether any handovers worked at all.
   982 			// from this, and whether any handovers worked at all.
   865 			if ( err == KErrNone )
   983 			if ( err == KErrNone )
   866 				{
   984 				{
   867 #ifdef __FLOG_ACTIVE
   985                 OstTraceExt2(TRACE_NORMAL, CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY_DUP6, 
   868 				LOGTEXT3(_L8("***USB HOST STACK: THE FOLLOWING INTERFACES OF DEVICE %d WERE SUCCESSFULLY PASSED TO FUNCTION DRIVER WITH IMPL UID 0x%08x"),
   986                         "***USB HOST STACK: THE FOLLOWING INTERFACES OF DEVICE %u WERE SUCCESSFULLY PASSED TO FUNCTION DRIVER WITH IMPL UID 0x%08x",
   869 					aDevice.DeviceId(), fdc->ImplUid());
   987 					(TInt32) aDevice.DeviceId(), fdc->ImplUid().iUid);
   870 				// We want to log each interface that's in
   988 				// We want to log each interface that's in
   871 				// aInterfacesGivenToFdc AND is marked claimed in iInterfaces.
   989 				// aInterfacesGivenToFdc AND is marked claimed in iInterfaces.
   872 				for ( TUint ii = 0 ; ii < aInterfacesGivenToFdc.Count() ; ++ii )
   990 				for ( TUint ii = 0 ; ii < aInterfacesGivenToFdc.Count() ; ++ii )
   873 					{
   991 					{
   874 					const TUint ifNum = aInterfacesGivenToFdc[ii];
   992 					const TUint ifNum = aInterfacesGivenToFdc[ii];
   875 					for ( TUint jj = 0 ; jj < iInterfaces.Count() ; ++jj )
   993 					for ( TUint jj = 0 ; jj < iInterfaces.Count() ; ++jj )
   876 						{
   994 						{
   877 						const TInterfaceInfo* ifInfo = iInterfaces[jj];
   995 						const TInterfaceInfo* ifInfo = iInterfaces[jj];
   878 						ASSERT_DEBUG(ifInfo);
   996 						
       
   997 						if(!ifInfo)
       
   998 						    {
       
   999                             OstTrace0( TRACE_FATAL, CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY_DUP7, "Empty ifInfo" );
       
  1000                             __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
  1001 						    }
   879 						if (	ifNum == ifInfo->iNumber
  1002 						if (	ifNum == ifInfo->iNumber
   880 							&&	ifInfo->iClaimed
  1003 							&&	ifInfo->iClaimed
   881 							)
  1004 							)
   882 							{
  1005 							{
   883 							LOGTEXT2(_L8("***USB HOST STACK: bInterfaceNumber %d"), ifNum);
  1006                             OstTrace1( TRACE_NORMAL, CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY_DUP8, "***USB HOST STACK: bInterfaceNumber %d", ifNum );
   884 							}
  1007 							}
   885 						}
  1008 						}
   886 					}
  1009 					}
   887 #endif
       
   888 				aAnySuccess = ETrue;
  1010 				aAnySuccess = ETrue;
   889 				}
  1011 				}
   890 			else
  1012 			else
   891 				{
  1013 				{
   892 				aCollectedErr = err;
  1014 				aCollectedErr = err;
   893 				}
  1015 				}
   894 			// We found a matching FDC for this interface- no need to look for more.
  1016 			// We found a matching FDC for this interface- no need to look for more.
   895 			break;
  1017 			break;
   896 			}
  1018 			}
   897 		}
  1019 		}
       
  1020 	OstTraceFunctionExit0( CFDF_FINDDRIVERFORINTERFACEUSINGSPECIFICKEY_EXIT );
   898 	}
  1021 	}
   899 
  1022 
   900 void CFdf::HandleDeviceDetachment(TUint aDeviceId)
  1023 void CFdf::HandleDeviceDetachment(TUint aDeviceId)
   901 	{
  1024 	{
   902 	LOG_FUNC
  1025     OstTraceFunctionEntry0( CFDF_HANDLEDEVICEDETACHMENT_ENTRY );
   903 	LOGTEXT2(_L8("\taDeviceId = %d"), aDeviceId);
  1026     OstTrace1( TRACE_NORMAL, CFDF_HANDLEDEVICEDETACHMENT, "aDeviceId = %d", aDeviceId );
   904 
       
   905 
  1027 
   906 #ifdef _DEBUG
  1028 #ifdef _DEBUG
   907 	TBool found = EFalse;
  1029 	TBool found = EFalse;
   908 #endif
  1030 #endif
   909 	// Find the relevant device proxy. If there isn't one, just drop the
  1031 	// Find the relevant device proxy. If there isn't one, just drop the
   917 		if ( device->DeviceId() == aDeviceId )
  1039 		if ( device->DeviceId() == aDeviceId )
   918 			{
  1040 			{
   919 #ifdef _DEBUG
  1041 #ifdef _DEBUG
   920 			found = ETrue;
  1042 			found = ETrue;
   921 #endif
  1043 #endif
   922 			LOGTEXT(_L8("\tfound matching device proxy"));
  1044 			OstTrace0( TRACE_NORMAL, CFDF_HANDLEDEVICEDETACHMENT_DUP1, "found matching device proxy" );
   923 
  1045 			
   924 			iDevices.Remove(*device);
  1046 			iDevices.Remove(*device);
   925 			// Before destroying the device proxy, take the detachment event
  1047 			// Before destroying the device proxy, take the detachment event
   926 			// stored in it for the event queue.
  1048 			// stored in it for the event queue.
   927 			TDeviceEvent* const detachmentEvent = device->GetDetachmentEventObject();
  1049 			TDeviceEvent* const detachmentEvent = device->GetDetachmentEventObject();
   928 			ASSERT_DEBUG(detachmentEvent);
  1050 			if(!detachmentEvent)
   929 			ASSERT_DEBUG(iEventQueue);
  1051 			    {
       
  1052                 OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEDETACHMENT_DUP2, "Empty detachmentEvent" );
       
  1053                 __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
  1054 			    }
       
  1055 			if(!iEventQueue)
       
  1056 			    {
       
  1057                 OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVICEDETACHMENT_DUP3, "Empty iEventQueue" );
       
  1058                 __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
  1059 			    }
   930 			iEventQueue->AddDeviceEvent(*detachmentEvent);
  1060 			iEventQueue->AddDeviceEvent(*detachmentEvent);
   931 			LOGTEXT2(_L8("***USB HOST STACK: DETACHMENT OF DEVICE (id %d)"), aDeviceId);
  1061 			OstTrace1( TRACE_NORMAL, CFDF_HANDLEDEVICEDETACHMENT_DUP4, "***USB HOST STACK: DETACHMENT OF DEVICE (id %d)", aDeviceId );
   932 			delete device;
  1062 			delete device;
   933 
  1063 
   934 			TellFdcsOfDeviceDetachment(aDeviceId);
  1064 			TellFdcsOfDeviceDetachment(aDeviceId);
   935 			
  1065 			
   936 #ifndef __OVER_DUMMYUSBDI__
  1066 #ifndef __OVER_DUMMYUSBDI__
   937 			// If we're using the DummyUSBDI the real USBDI isn't loaded.
  1067 			// If we're using the DummyUSBDI the real USBDI isn't loaded.
   938 			// Unload USBDI when attached devices goes from 1 to 0
  1068 			// Unload USBDI when attached devices goes from 1 to 0
   939 			if (iDevices.IsEmpty())
  1069 			if (iDevices.IsEmpty())
   940 				{
  1070 				{
   941 				TInt err = User::FreeLogicalDevice(KDriverUsbdiLddFileName);
  1071 				TInt err = User::FreeLogicalDevice(KDriverUsbdiLddFileName);
   942 				LOGTEXT2(_L8("\tFreeLogicalDevice( usbdi ) returned %d"), err);
  1072 				OstTrace1( TRACE_NORMAL, CFDF_HANDLEDEVICEDETACHMENT_DUP5, "FreeLogicalDevice( usbdi ) returned %d", err );
   943 				}
  1073 				}
   944 #endif // __OVER_DUMMYUSBDI__
  1074 #endif // __OVER_DUMMYUSBDI__
   945 			
  1075 			
   946 			break;
  1076 			break;
   947 			}
  1077 			}
   948 		}
  1078 		}
   949 
  1079 
   950 #ifdef _DEBUG
  1080 #ifdef _DEBUG
   951 	if ( !found )
  1081 	if ( !found )
   952 		{
  1082 		{
   953 		LOGTEXT(_L8("\tno matching device proxy found"));
  1083         OstTrace0( TRACE_NORMAL, CFDF_HANDLEDEVICEDETACHMENT_DUP6, "no matching device proxy found" );
   954 		}
  1084 		}
   955 #endif
  1085 #endif
       
  1086 	
       
  1087 	OstTraceFunctionExit0( CFDF_HANDLEDEVICEDETACHMENT_EXIT );
   956 	}
  1088 	}
   957 
  1089 
   958 void CFdf::HandleDevmonEvent(TInt aEvent)
  1090 void CFdf::HandleDevmonEvent(TInt aEvent)
   959 	{
  1091 	{
   960 	LOG_FUNC
  1092 	OstTraceFunctionEntry0( CFDF_HANDLEDEVMONEVENT_ENTRY );
   961 	LOGTEXT2(_L8("\taEvent = %d"), aEvent);
  1093 	OstTrace1( TRACE_NORMAL, CFDF_HANDLEDEVMONEVENT, "aEvent = %d", aEvent );
   962 
  1094 
   963 	ASSERT_DEBUG(iEventQueue);
  1095 	if(!iEventQueue)
       
  1096 	    {
       
  1097         OstTrace0( TRACE_FATAL, CFDF_HANDLEDEVMONEVENT_DUP1, "Empty iEventQueue" );
       
  1098         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
  1099 	    }
   964 	iEventQueue->AddDevmonEvent(aEvent);
  1100 	iEventQueue->AddDevmonEvent(aEvent);
       
  1101 	OstTraceFunctionExit0( CFDF_HANDLEDEVMONEVENT_EXIT );
   965 	}
  1102 	}
   966 
  1103 
   967 void CFdf::TellFdcsOfDeviceDetachment(TUint aDeviceId)
  1104 void CFdf::TellFdcsOfDeviceDetachment(TUint aDeviceId)
   968 	{
  1105 	{
   969 	LOG_FUNC
  1106 	OstTraceFunctionEntry0( CFDF_TELLFDCSOFDEVICEDETACHMENT_ENTRY );
   970 	LOGTEXT2(_L8("\taDeviceId = %d"), aDeviceId);
  1107 	OstTrace1( TRACE_NORMAL, CFDF_TELLFDCSOFDEVICEDETACHMENT, "aDeviceId = %d", aDeviceId );
   971 
  1108 	
   972 	TSglQueIter<CFdcProxy> iter(iFunctionDrivers);
  1109 	TSglQueIter<CFdcProxy> iter(iFunctionDrivers);
   973 	iter.SetToFirst();
  1110 	iter.SetToFirst();
   974 	CFdcProxy* fdc;
  1111 	CFdcProxy* fdc;
   975 	while ( ( fdc = iter++ ) != NULL )
  1112 	while ( ( fdc = iter++ ) != NULL )
   976 		{
  1113 		{
   980 			iFunctionDrivers.Remove(*fdc);
  1117 			iFunctionDrivers.Remove(*fdc);
   981 			delete fdc;
  1118 			delete fdc;
   982 			}
  1119 			}
   983 		}			
  1120 		}			
   984 		
  1121 		
       
  1122 	OstTraceFunctionExit0( CFDF_TELLFDCSOFDEVICEDETACHMENT_EXIT );
   985 	}
  1123 	}
   986 
  1124 
   987 TUint32 CFdf::TokenForInterface(TUint8 aInterface)
  1125 TUint32 CFdf::TokenForInterface(TUint8 aInterface)
   988 	{
  1126 	{
   989 	LOG_FUNC
  1127 	OstTraceFunctionEntry0( CFDF_TOKENFORINTERFACE_ENTRY );
   990 	LOGTEXT2(_L8("\taInterface = %d"), aInterface);
  1128 	OstTrace1( TRACE_NORMAL, CFDF_TOKENFORINTERFACE, "aInterface = %d", aInterface );
       
  1129 	
   991 	TUint32 token = 0;
  1130 	TUint32 token = 0;
   992 
  1131 
   993 	// Check that the interface was in the array given to the FD and mark it
  1132 	// Check that the interface was in the array given to the FD and mark it
   994 	// as claimed.
  1133 	// as claimed.
   995 	TBool found = EFalse;
  1134 	TBool found = EFalse;
   996 	const TUint interfaceCount = iInterfaces.Count();
  1135 	const TUint interfaceCount = iInterfaces.Count();
   997 	for ( TUint ii = 0 ; ii < interfaceCount ; ++ii )
  1136 	for ( TUint ii = 0 ; ii < interfaceCount ; ++ii )
   998 		{
  1137 		{
   999 		TInterfaceInfo* ifInfo = iInterfaces[ii];
  1138 		TInterfaceInfo* ifInfo = iInterfaces[ii];
  1000 		ASSERT_DEBUG(ifInfo);
  1139 		if(!ifInfo)
       
  1140 		    {
       
  1141             OstTrace0( TRACE_FATAL, CFDF_TOKENFORINTERFACE_DUP1, "Empty ifInfo" );
       
  1142             __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
  1143 		    }
  1001 		if ( ifInfo->iNumber == aInterface )
  1144 		if ( ifInfo->iNumber == aInterface )
  1002 			{
  1145 			{
  1003 			found = ETrue;
  1146 			found = ETrue;
  1004 			// The FDC tried to claim an interface that was already claimed.
  1147 			// The FDC tried to claim an interface that was already claimed.
  1005 			ASSERT_ALWAYS(!ifInfo->iClaimed);
  1148 			if(ifInfo->iClaimed)
       
  1149 			    {
       
  1150                 OstTrace0( TRACE_FATAL, CFDF_TOKENFORINTERFACE_DUP2, "iClaimed error" );
       
  1151                 User::Panic(KPanicCategory,__LINE__);
       
  1152 			    }
  1006 			ifInfo->iClaimed = ETrue;
  1153 			ifInfo->iClaimed = ETrue;
  1007 			break;
  1154 			break;
  1008 			}
  1155 			}
  1009 		}
  1156 		}
  1010 	// Could not find interface in the interface array- the FDC tried to claim
  1157 	// Could not find interface in the interface array- the FDC tried to claim
  1011 	// an interface it had not been offered.
  1158 	// an interface it had not been offered.
  1012 	ASSERT_ALWAYS(found);
  1159 	if(!found)
  1013 
  1160 	    {
  1014 	ASSERT_DEBUG(iCurrentDevice);
  1161         OstTrace0( TRACE_FATAL, CFDF_TOKENFORINTERFACE_DUP3, "not found" );
       
  1162         User::Panic(KPanicCategory,__LINE__);
       
  1163 	    }
       
  1164 
       
  1165 	if(!iCurrentDevice)
       
  1166 	    {
       
  1167         OstTrace0( TRACE_FATAL, CFDF_TOKENFORINTERFACE_DUP4, "Empty iCurrentDevice" );
       
  1168         __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
  1169 	    }
  1015 
  1170 
  1016 	// GetTokenForInterface will return error in the following cases:
  1171 	// GetTokenForInterface will return error in the following cases:
  1017 	// 1/ KErrBadHandle: invalid device handle (the CDeviceProxy asserts that
  1172 	// 1/ KErrBadHandle: invalid device handle (the CDeviceProxy asserts that
  1018 	// the handle is valid) because the device has been detached while processing
  1173 	// the handle is valid) because the device has been detached while processing
  1019 	// may be due to too much current or cable has been removed
  1174 	// may be due to too much current or cable has been removed
  1037 
  1192 
  1038 		case KErrNone: // Fall through and do nothing
  1193 		case KErrNone: // Fall through and do nothing
  1039 			break;
  1194 			break;
  1040 
  1195 
  1041 		default:
  1196 		default:
  1042 			LOGTEXT3(_L8("\tUnexpected error %d when requesting token for aInterface %d"),err,aInterface);
  1197 			OstTraceExt2( TRACE_FATAL, CFDF_TOKENFORINTERFACE_DUP5, "Unexpected error %d when requesting token for aInterface %d",err,aInterface);
  1043 			ASSERT_ALWAYS(0);
  1198 			User::Panic(KPanicCategory,__LINE__);
  1044 			break;
  1199 			break;
  1045 		}
  1200 		}
  1046 
  1201 
  1047 	LOGTEXT3(_L8("\tToken for interface %d is = %d"),aInterface, token);
  1202 	OstTraceExt2( TRACE_NORMAL, CFDF_TOKENFORINTERFACE_DUP6, 
  1048 
  1203 	        "Token for interface %hhu is = %u",aInterface, token);
       
  1204 	
       
  1205 	OstTraceFunctionExit0( CFDF_TOKENFORINTERFACE_EXIT );
  1049 	return token;
  1206 	return token;
  1050 	}
  1207 	}
  1051 
  1208 
  1052 CDeviceProxy* CFdf::DeviceProxyL(TUint aDeviceId) const
  1209 CDeviceProxy* CFdf::DeviceProxyL(TUint aDeviceId) const
  1053 	{
  1210 	{
  1054 	LOG_FUNC
  1211 	OstTraceFunctionEntry0( CFDF_DEVICEPROXYL_ENTRY );
  1055 	LOGTEXT2(_L8("\taDeviceId = %d"), aDeviceId);
  1212 	OstTrace1( TRACE_NORMAL, CFDF_DEVICEPROXYL, "aDeviceId = %d", aDeviceId );
  1056 
  1213 	
  1057 	TSglQueIter<CDeviceProxy> iter(const_cast<CFdf*>(this)->iDevices);
  1214 	TSglQueIter<CDeviceProxy> iter(const_cast<CFdf*>(this)->iDevices);
  1058 	iter.SetToFirst();
  1215 	iter.SetToFirst();
  1059 	CDeviceProxy* device = NULL;
  1216 	CDeviceProxy* device = NULL;
  1060 	while ( ( device = iter++ ) != NULL )
  1217 	while ( ( device = iter++ ) != NULL )
  1061 		{
  1218 		{
  1062 		if ( device->DeviceId() == aDeviceId )
  1219 		if ( device->DeviceId() == aDeviceId )
  1063 			{
  1220 			{
  1064 			LOGTEXT2(_L8("\tdevice = 0x%08x"), device);
  1221             OstTrace1( TRACE_NORMAL, CFDF_DEVICEPROXYL_DUP1, "device = 0x%08x", device );
       
  1222 			OstTraceFunctionExit0( CFDF_DEVICEPROXYL_EXIT );
  1065 			return device;
  1223 			return device;
  1066 			}
  1224 			}
  1067 		}
  1225 		}
  1068 	LEAVEL(KErrNotFound);
  1226 	OstTrace0( TRACE_NORMAL, CFDF_DEVICEPROXYL_DUP2, "KErrNotFound");
       
  1227 	User::Leave(KErrNotFound);
       
  1228 	OstTraceFunctionExit0( CFDF_DEVICEPROXYL_EXIT_DUP1 );
  1069 	return NULL; // avoid warning
  1229 	return NULL; // avoid warning
  1070 	}
  1230 	}
  1071 
  1231 
  1072 const RArray<TUint>& CFdf::GetSupportedLanguagesL(TUint aDeviceId) const
  1232 const RArray<TUint>& CFdf::GetSupportedLanguagesL(TUint aDeviceId) const
  1073 	{
  1233 	{
  1074 	LOG_FUNC
  1234 	OstTraceFunctionEntry0( CFDF_GETSUPPORTEDLANGUAGESL_ENTRY );
  1075 	LOGTEXT2(_L8("\taDeviceId = %d"), aDeviceId);
  1235 	OstTrace1( TRACE_NORMAL, CFDF_GETSUPPORTEDLANGUAGESL, "aDeviceId = %d", aDeviceId );
  1076 
  1236 	
  1077 	CDeviceProxy* deviceProxy = DeviceProxyL(aDeviceId);
  1237 	CDeviceProxy* deviceProxy = DeviceProxyL(aDeviceId);
  1078 	return deviceProxy->GetSupportedLanguages();
  1238 	return deviceProxy->GetSupportedLanguages();
  1079 	}
  1239 	}
  1080 
  1240 
  1081 void CFdf::GetManufacturerStringDescriptorL(TUint aDeviceId, TUint32 aLangId, TName& aString) const
  1241 void CFdf::GetManufacturerStringDescriptorL(TUint aDeviceId, TUint32 aLangId, TName& aString) const
  1082 	{
  1242 	{
  1083 	LOG_FUNC
  1243 	OstTraceFunctionEntry0( CFDF_GETMANUFACTURERSTRINGDESCRIPTORL_ENTRY );
  1084 	LOGTEXT3(_L8("\taDeviceId = %d, aLangId = 0x%04x"), aDeviceId, aLangId);
  1244 	OstTraceExt2( TRACE_NORMAL, CFDF_GETMANUFACTURERSTRINGDESCRIPTORL, 
  1085 
  1245 	        "aDeviceId = %u, aLangId = 0x%08x", (TUint32)aDeviceId, aLangId );
       
  1246 		
  1086 	CDeviceProxy* deviceProxy = DeviceProxyL(aDeviceId);
  1247 	CDeviceProxy* deviceProxy = DeviceProxyL(aDeviceId);
  1087 	deviceProxy->GetManufacturerStringDescriptorL(aLangId, aString);
  1248 	deviceProxy->GetManufacturerStringDescriptorL(aLangId, aString);
  1088 	LOGTEXT2(_L("\taString = \"%S\""), &aString);
  1249 	OstTraceExt1( TRACE_NORMAL, CFDF_GETMANUFACTURERSTRINGDESCRIPTORL_DUP1, "aString = \"%S\"", aString );
       
  1250 	OstTraceFunctionExit0( CFDF_GETMANUFACTURERSTRINGDESCRIPTORL_EXIT );
  1089 	}
  1251 	}
  1090 
  1252 
  1091 void CFdf::GetProductStringDescriptorL(TUint aDeviceId, TUint32 aLangId, TName& aString) const
  1253 void CFdf::GetProductStringDescriptorL(TUint aDeviceId, TUint32 aLangId, TName& aString) const
  1092 	{
  1254 	{
  1093 	LOG_FUNC
  1255 	OstTraceFunctionEntry0( CFDF_GETPRODUCTSTRINGDESCRIPTORL_ENTRY );
  1094 	LOGTEXT3(_L8("\taDeviceId = %d, aLangId = 0x%04x"), aDeviceId, aLangId);
  1256 	OstTraceExt2( TRACE_NORMAL, CFDF_GETPRODUCTSTRINGDESCRIPTORL, 
       
  1257 	        "aDeviceId = %u, aLangId = 0x%04x", (TUint32)aDeviceId, aLangId );
  1095 
  1258 
  1096 	CDeviceProxy* deviceProxy = DeviceProxyL(aDeviceId);
  1259 	CDeviceProxy* deviceProxy = DeviceProxyL(aDeviceId);
  1097 	deviceProxy->GetProductStringDescriptorL(aLangId, aString);
  1260 	deviceProxy->GetProductStringDescriptorL(aLangId, aString);
  1098 	LOGTEXT2(_L("\taString = \"%S\""), &aString);
  1261 	OstTraceExt1( TRACE_NORMAL, CFDF_GETPRODUCTSTRINGDESCRIPTORL_DUP1, "aString = \"%S\"", aString );
       
  1262 	OstTraceFunctionExit0( CFDF_GETPRODUCTSTRINGDESCRIPTORL_EXIT );
  1099 	}
  1263 	}
  1100 
  1264 
  1101 void CFdf::GetOtgDeviceDescriptorL(TInt aDeviceId, TOtgDescriptor& aDescriptor) const
  1265 void CFdf::GetOtgDeviceDescriptorL(TInt aDeviceId, TOtgDescriptor& aDescriptor) const
  1102 	{
  1266 	{
  1103 	LOG_FUNC
  1267 	OstTraceFunctionEntry0( CFDF_GETOTGDEVICEDESCRIPTORL_ENTRY );
  1104 	
  1268 	
  1105 	DeviceProxyL(aDeviceId)->GetOtgDescriptorL(aDescriptor);
  1269 	DeviceProxyL(aDeviceId)->GetOtgDescriptorL(aDescriptor);
       
  1270 	OstTraceFunctionExit0( CFDF_GETOTGDEVICEDESCRIPTORL_EXIT );
  1106 	}
  1271 	}
  1107 
  1272 
  1108 void CFdf::GetSerialNumberStringDescriptorL(TUint aDeviceId, TUint32 aLangId, TName& aString) const
  1273 void CFdf::GetSerialNumberStringDescriptorL(TUint aDeviceId, TUint32 aLangId, TName& aString) const
  1109 	{
  1274 	{
  1110 	LOG_FUNC
  1275 	OstTraceFunctionEntry0( CFDF_GETSERIALNUMBERSTRINGDESCRIPTORL_ENTRY );
  1111 	LOGTEXT3(_L8("\taDeviceId = %d, aLangId = 0x%04x"), aDeviceId, aLangId);
  1276 	OstTraceExt2( TRACE_NORMAL, CFDF_GETSERIALNUMBERSTRINGDESCRIPTORL, 
       
  1277 	        "aDeviceId = %u, aLangId = 0x%08x", (TUint32)aDeviceId, aLangId );
  1112 
  1278 
  1113 	CDeviceProxy* deviceProxy = DeviceProxyL(aDeviceId);
  1279 	CDeviceProxy* deviceProxy = DeviceProxyL(aDeviceId);
  1114 	deviceProxy->GetSerialNumberStringDescriptorL(aLangId, aString);
  1280 	deviceProxy->GetSerialNumberStringDescriptorL(aLangId, aString);
  1115 	LOGTEXT2(_L("\taString = \"%S\""), &aString);
  1281 	OstTraceExt1( TRACE_NORMAL, CFDF_GETSERIALNUMBERSTRINGDESCRIPTORL_DUP1, "aString = \"%S\"", aString );
       
  1282 	OstTraceFunctionExit0( CFDF_GETSERIALNUMBERSTRINGDESCRIPTORL_EXIT );
  1116 	}
  1283 	}
  1117 
  1284 
  1118 void CFdf::SearchForInterfaceFunctionDriversL(CDeviceProxy& aDevice, TBool& aAnySuccess, TInt& aCollectedErr)
  1285 void CFdf::SearchForInterfaceFunctionDriversL(CDeviceProxy& aDevice, TBool& aAnySuccess, TInt& aCollectedErr)
  1119 	{
  1286 	{
  1120 	RArray<TUint> interfacesNumberArray;	
  1287 	RArray<TUint> interfacesNumberArray;	
  1121 	CleanupClosePushL(interfacesNumberArray);
  1288 	CleanupClosePushL(interfacesNumberArray);
  1122 
       
  1123 
       
  1124 	
  1289 	
  1125 	for ( TUint ii = 0 ; ii < iInterfaces.Count() ; ++ii )
  1290 	for ( TUint ii = 0 ; ii < iInterfaces.Count() ; ++ii )
  1126 		{
  1291 		{
  1127 		// At this point we have NOT done any interface level searching yet,
  1292 		// At this point we have NOT done any interface level searching yet,
  1128 		// and all interfaces should in the Unclaimed status,
  1293 		// and all interfaces should in the Unclaimed status,
  1170 void CFdf::AppendInterfaceNumberToArrayL(CDeviceProxy& aDevice, RArray<TUint>& aArray, TUint aInterfaceNo) const
  1335 void CFdf::AppendInterfaceNumberToArrayL(CDeviceProxy& aDevice, RArray<TUint>& aArray, TUint aInterfaceNo) const
  1171 	{
  1336 	{
  1172 	TInt err = aArray.Append(aInterfaceNo);
  1337 	TInt err = aArray.Append(aInterfaceNo);
  1173 	if ( err )
  1338 	if ( err )
  1174 		{
  1339 		{
  1175 		aDevice.SetDriverLoadingEventData(EDriverLoadFailure, err);
  1340 		aDevice.SetDriverLoadingEventData(EDriverLoadFailure, err);	
  1176 		LEAVEL(err);
  1341 		OstTrace1( TRACE_NORMAL, CFDF_APPENDINTERFACENUMBERTOARRAYL, "Leave with error: %d", err );
       
  1342 		User::Leave(err);
  1177 		}
  1343 		}
  1178 	}
  1344 	}
  1179 	
  1345 	
  1180 
  1346 
  1181 
  1347 
  1213 		CFdcProxy* fdc;
  1379 		CFdcProxy* fdc;
  1214 		while ( ( fdc = iter++ ) != NULL)
  1380 		while ( ( fdc = iter++ ) != NULL)
  1215 			{
  1381 			{
  1216 			if (fdc->MarkedForDeletion())
  1382 			if (fdc->MarkedForDeletion())
  1217 				continue;
  1383 				continue;
  1218 			LOGTEXT2(_L8("\tFDC's default_data field = \"%S\""), &fdc->DefaultDataField());
  1384 			OstTraceExt1( TRACE_NORMAL, CFDF_SEARCHFORADEVICEFUNCTIONDRIVERL, "FDC's default_data field = \"%S\"", fdc->DefaultDataField());
  1219 #ifdef _DEBUG
  1385 			
  1220 	// having these two together in the debug window is helpful for interactive debugging
  1386 	// having these two together in the debug window is helpful for interactive debugging
  1221 	TBuf8<KMaxSearchKeyLength> fd_key;
  1387 	TBuf8<KMaxSearchKeyLength> fd_key;
  1222 	fd_key.Append(fdc->DefaultDataField().Ptr(), fdc->DefaultDataField().Length() > KMaxSearchKeyLength ? KMaxSearchKeyLength : fdc->DefaultDataField().Length());	
  1388 	fd_key.Append(fdc->DefaultDataField().Ptr(), fdc->DefaultDataField().Length() > KMaxSearchKeyLength ? KMaxSearchKeyLength : fdc->DefaultDataField().Length());	
  1223 	TBuf8<KMaxSearchKeyLength> search_key;
  1389 	TBuf8<KMaxSearchKeyLength> search_key;
  1224 	search_key.Append(searchKeyString.Ptr(), searchKeyString.Length() > KMaxSearchKeyLength ? KMaxSearchKeyLength : searchKeyString.Length());
  1390 	search_key.Append(searchKeyString.Ptr(), searchKeyString.Length() > KMaxSearchKeyLength ? KMaxSearchKeyLength : searchKeyString.Length());
  1225 	TInt version = fdc->Version();
  1391 	TInt version = fdc->Version();
  1226 #endif
  1392 
  1227 			if (searchKeyString.CompareF(fdc->DefaultDataField()) == 0)
  1393 			if (searchKeyString.CompareF(fdc->DefaultDataField()) == 0)
  1228 				{
  1394 				{
  1229 				
  1395 				
  1230 				// If there is more than one matching FD then if all of them are in RAM we simply choose the first one we find.
  1396 				// If there is more than one matching FD then if all of them are in RAM we simply choose the first one we find.
  1231 				// (Similarly if they are all in ROM we choose the first one although this situation should not arise as a device
  1397 				// (Similarly if they are all in ROM we choose the first one although this situation should not arise as a device
  1239 					{
  1405 					{
  1240 					aDevice.SetMultipleDriversFlag();
  1406 					aDevice.SetMultipleDriversFlag();
  1241 					}
  1407 					}
  1242 				
  1408 				
  1243 				foundFdc = ETrue;
  1409 				foundFdc = ETrue;
  1244 				LOGTEXT2(_L8("\tfound matching FDC (0x%08x)"), fdc);
  1410 				OstTrace1( TRACE_NORMAL, CFDF_SEARCHFORADEVICEFUNCTIONDRIVERL_DUP1, "found matching FDC (0x%08x)", fdc );
  1245 				TInt err = fdc->NewFunction(aDevice.DeviceId(), interfaces, iDD, iCD);
  1411 				TInt err = fdc->NewFunction(aDevice.DeviceId(), interfaces, iDD, iCD);
  1246 				LOGTEXT2(_L8("\tNewFunction returned %d"), err);
  1412 				OstTrace1( TRACE_NORMAL, CFDF_SEARCHFORADEVICEFUNCTIONDRIVERL_DUP2, "NewFunction returned %d", err);
  1247 				// To correctly determine whether the driver load for the whole
  1413 				// To correctly determine whether the driver load for the whole
  1248 				// configuration was a complete failure, a partial success or a
  1414 				// configuration was a complete failure, a partial success or a
  1249 				// complete success, we need to collect any non-KErrNone error
  1415 				// complete success, we need to collect any non-KErrNone error
  1250 				// from this, and whether any handovers worked at all.
  1416 				// from this, and whether any handovers worked at all.
  1251 				if ( err == KErrNone )
  1417 				if ( err == KErrNone )
  1289 //
  1455 //
  1290 // Format the string aSearchKey according to aSearchKeys to search for Device Functions drivers
  1456 // Format the string aSearchKey according to aSearchKeys to search for Device Functions drivers
  1291 //
  1457 //
  1292 void CFdf::FormatDeviceSearchKey(TDes8& aSearchKey, TDeviceSearchKeys aDeviceSearchKeys)
  1458 void CFdf::FormatDeviceSearchKey(TDes8& aSearchKey, TDeviceSearchKeys aDeviceSearchKeys)
  1293 	{
  1459 	{
  1294 	LOG_FUNC
  1460 	OstTraceFunctionEntry0( CFDF_FORMATDEVICESEARCHKEY_ENTRY );
       
  1461 	
  1295 	switch (aDeviceSearchKeys)
  1462 	switch (aDeviceSearchKeys)
  1296 		{
  1463 		{
  1297 		case EVendorProductDevice:
  1464 		case EVendorProductDevice:
  1298 			{
  1465 			{
  1299 			_LIT8(KTemplateV_P_D, "V0x%04xP0x%04xD0x%04x");
  1466 			_LIT8(KTemplateV_P_D, "V0x%04xP0x%04xD0x%04x");
  1329 			_LIT8(KTemplateDC_DSC, "DC0x%02xDSC0x%02x");
  1496 			_LIT8(KTemplateDC_DSC, "DC0x%02xDSC0x%02x");
  1330 			aSearchKey.Format(KTemplateDC_DSC(), iDD.DeviceClass(), iDD.DeviceSubClass());
  1497 			aSearchKey.Format(KTemplateDC_DSC(), iDD.DeviceClass(), iDD.DeviceSubClass());
  1331 			break;
  1498 			break;
  1332 			}
  1499 			}
  1333 		default:
  1500 		default:
  1334 			{
  1501 			{	
  1335 			ASSERT_DEBUG(EFalse);
  1502 			OstTrace1( TRACE_FATAL, CFDF_FORMATDEVICESEARCHKEY, "Invalid aDeviceSearchKeys=%d", aDeviceSearchKeys );
       
  1503 			__ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
  1336 			}		
  1504 			}		
  1337 		}
  1505 		}
  1338 		
  1506 	OstTraceExt1( TRACE_NORMAL, CFDF_FORMATDEVICESEARCHKEY_DUP1, "aSearchKey = \"%s\"", aSearchKey );
  1339 	LOGTEXT2(_L8("\taSearchKey = \"%S\""), &aSearchKey);		
  1507 	OstTraceFunctionExit0( CFDF_FORMATDEVICESEARCHKEY_EXIT );
  1340 	}
  1508 	}
  1341 	
  1509 	
  1342 	
  1510 	
  1343 	
  1511 	
  1344 	
  1512 	
  1346 //
  1514 //
  1347 // Format the string aSearchKey according to aSearchKeys to search for Interface Functions drivers
  1515 // Format the string aSearchKey according to aSearchKeys to search for Interface Functions drivers
  1348 //	
  1516 //	
  1349 void CFdf::FormatInterfaceSearchKey(TDes8& aSearchKey, TInterfaceSearchKeys aSearchKeys, const TInterfaceInfo& aIfInfo)
  1517 void CFdf::FormatInterfaceSearchKey(TDes8& aSearchKey, TInterfaceSearchKeys aSearchKeys, const TInterfaceInfo& aIfInfo)
  1350 	{
  1518 	{
  1351 	LOG_FUNC
  1519 	OstTraceFunctionEntry0( CFDF_FORMATINTERFACESEARCHKEY_ENTRY );
       
  1520 	
  1352 	switch (aSearchKeys)
  1521 	switch (aSearchKeys)
  1353 		{
  1522 		{
  1354 		case EVendorProductDeviceConfigurationvalueInterfacenumber:
  1523 		case EVendorProductDeviceConfigurationvalueInterfacenumber:
  1355 			{
  1524 			{
  1356 			_LIT8(KTemplateV_P_D_CV_IN, "V0x%04xP0x%04xD0x%04xCV0x%02xIN0x%02x");		
  1525 			_LIT8(KTemplateV_P_D_CV_IN, "V0x%04xP0x%04xD0x%04xCV0x%02xIN0x%02x");		
  1387 			aSearchKey.Format(KTemplateIC_ISC(), aIfInfo.iClass, aIfInfo.iSubclass);
  1556 			aSearchKey.Format(KTemplateIC_ISC(), aIfInfo.iClass, aIfInfo.iSubclass);
  1388 			break;
  1557 			break;
  1389 			}
  1558 			}
  1390 		default:
  1559 		default:
  1391 			{
  1560 			{
  1392 			ASSERT_DEBUG(EFalse);
  1561 			OstTrace1( TRACE_FATAL, CFDF_FORMATINTERFACESEARCHKEY, "Invalid aSearchKeys=%d", aSearchKeys );
  1393 			}
  1562 			__ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
  1394 		}
  1563 			}
  1395 	LOGTEXT2(_L8("\taSearchKey = \"%S\""), &aSearchKey);		
  1564 		}
       
  1565 	OstTraceExt1( TRACE_NORMAL, CFDF_FORMATINTERFACESEARCHKEY_DUP1, "aSearchKey = \"%s\"", aSearchKey );
       
  1566 	OstTraceFunctionExit0( CFDF_FORMATINTERFACESEARCHKEY_EXIT );
  1396 	}
  1567 	}
  1397 
  1568 
  1398 
  1569 
  1399 TUint CFdf::UnclaimedInterfaceCount() const
  1570 TUint CFdf::UnclaimedInterfaceCount() const
  1400 	{
  1571 	{
  1401 	LOG_FUNC	
  1572 	OstTraceFunctionEntry0( CFDF_UNCLAIMEDINTERFACECOUNT_ENTRY );
       
  1573 		
  1402 	TUint unclaimedInterfaces = 0;
  1574 	TUint unclaimedInterfaces = 0;
  1403 	for ( TUint ii = 0 ; ii < iInterfaces.Count() ; ++ii )
  1575 	for ( TUint ii = 0 ; ii < iInterfaces.Count() ; ++ii )
  1404 		{
  1576 		{
  1405 		TInterfaceInfo* ifInfo = iInterfaces[ii];
  1577 		TInterfaceInfo* ifInfo = iInterfaces[ii];
  1406 		ASSERT_DEBUG(ifInfo);
  1578 		
       
  1579 		if(!ifInfo)
       
  1580 		    {
       
  1581             OstTrace0( TRACE_FATAL, CFDF_UNCLAIMEDINTERFACECOUNT, "Empty ifInfo" );
       
  1582             __ASSERT_DEBUG(EFalse,User::Panic(KPanicCategory,__LINE__));
       
  1583 		    }
  1407 		if ( !ifInfo->iClaimed )
  1584 		if ( !ifInfo->iClaimed )
  1408 			{
  1585 			{
  1409 			LOGTEXT2(_L8("\tunclaimed interface: ifInfo->iNumber = %d"), ifInfo->iNumber);
  1586             OstTrace1( TRACE_NORMAL, CFDF_UNCLAIMEDINTERFACECOUNT_DUP1, "unclaimed interface: ifInfo->iNumber = %d", ifInfo->iNumber );
  1410 			++unclaimedInterfaces;
  1587 			++unclaimedInterfaces;
  1411 			}
  1588 			}
  1412 		}
  1589 		}
  1413 	LOGTEXT2(_L("\tunclaimedInterfaces = \"%d\""), unclaimedInterfaces);			
  1590 	OstTrace1( TRACE_NORMAL, CFDF_UNCLAIMEDINTERFACECOUNT_DUP2, "unclaimedInterfaces = \"%d\"", unclaimedInterfaces );
       
  1591 	OstTraceFunctionExit0( CFDF_UNCLAIMEDINTERFACECOUNT_EXIT );
  1414 	return unclaimedInterfaces;
  1592 	return unclaimedInterfaces;
  1415 	}
  1593 	}
  1416 	
  1594 	
  1417 	
  1595 	
  1418 void CFdf::SetFailureStatus(TInt aUnclaimedInterfaces, TInt aInterfaceCount, TBool aAnySuccess, TBool aCollectedErr, CDeviceProxy& aDevice)
  1596 void CFdf::SetFailureStatus(TInt aUnclaimedInterfaces, TInt aInterfaceCount, TBool aAnySuccess, TBool aCollectedErr, CDeviceProxy& aDevice)