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