usbmgmt/usbmgr/host/functiondrivers/ms/msfdc/src/msfdc.cpp
branchRCL_3
changeset 16 012cc2ee6408
parent 15 f92a4f87e424
equal deleted inserted replaced
15:f92a4f87e424 16:012cc2ee6408
     1 /*
     1 /*
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-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".
    24 #include "utils.h"
    24 #include "utils.h"
    25 #include <d32usbc.h>
    25 #include <d32usbc.h>
    26 #include <usbhost/internal/fdcpluginobserver.h>
    26 #include <usbhost/internal/fdcpluginobserver.h>
    27 #include <d32usbdi.h>
    27 #include <d32usbdi.h>
    28 #include <d32usbdescriptors.h>
    28 #include <d32usbdescriptors.h>
    29 #include "OstTraceDefinitions.h"
    29 
    30 #ifdef OST_TRACE_COMPILER_IN_USE
    30 #ifdef __FLOG_ACTIVE
    31 #include "msfdcTraces.h"
    31 _LIT8(KLogComponent, "MsFdc");
    32 #endif
    32 #endif
    33 
       
    34 
       
    35 /**
    33 /**
    36   NewL function of CMsFdc, allocate the memory that needed for instantiating this object.
    34   NewL function of CMsFdc, allocate the memory that needed for instantiating this object.
    37  
    35  
    38   @param	aObserver   this is a pointer to the Observer object(FDF), MsFdc will get
    36   @param	aObserver   this is a pointer to the Observer object(FDF), MsFdc will get
    39                        informations from FDF.
    37                        informations from FDF.
    40   @return	A pointer to this CMsFdc object
    38   @return	A pointer to this CMsFdc object
    41  */
    39  */
    42 CMsFdc* CMsFdc::NewL(MFdcPluginObserver& aObserver)
    40 CMsFdc* CMsFdc::NewL(MFdcPluginObserver& aObserver)
    43 	{
    41 	{
    44 	OstTraceFunctionEntry0( CMSFDC_NEWL_ENTRY );
    42 	LOG_STATIC_FUNC_ENTRY
    45 	
    43 
    46 	CMsFdc* self = new(ELeave) CMsFdc(aObserver);
    44 	CMsFdc* self = new(ELeave) CMsFdc(aObserver);
    47 	CleanupStack::PushL(self);
    45 	CleanupStack::PushL(self);
    48 	self->ConstructL();
    46 	self->ConstructL();
    49 	CleanupStack::Pop(self);
    47 	CleanupStack::Pop(self);
    50 	OstTraceFunctionExit0( CMSFDC_NEWL_EXIT );
       
    51 	return self;
    48 	return self;
    52 	} 
    49 	} 
    53 
    50 
    54 /**
    51 /**
    55   Destructor of CMsFdc.
    52   Destructor of CMsFdc.
    56  */
    53  */
    57 CMsFdc::~CMsFdc()
    54 CMsFdc::~CMsFdc()
    58 	{
    55 	{
    59 	OstTraceFunctionEntry0( CMSFDC_CMSFDC_DES_ENTRY );
    56 	LOG_FUNC
       
    57 	
    60 	iMsmmSession.Disconnect();
    58 	iMsmmSession.Disconnect();
    61 	OstTrace0( TRACE_NORMAL, CMSFDC_CMSFDC, "Disconnected to MSMM OK" );
    59 	LOGTEXT(_L("Disconnected to MSMM OK"));
    62 
    60 #ifdef __FLOG_ACTIVE
    63 	OstTraceFunctionExit0( CMSFDC_CMSFDC_DES_EXIT );
    61 	CUsbLog::Close();
       
    62 #endif
    64 	}
    63 	}
    65 /**
    64 /**
    66   Constructor of CMsFdc.
    65   Constructor of CMsFdc.
    67  */
    66  */
    68 CMsFdc::CMsFdc(MFdcPluginObserver& aObserver)
    67 CMsFdc::CMsFdc(MFdcPluginObserver& aObserver)
    72 /**
    71 /**
    73   The Second phase construction of CMsFdc.
    72   The Second phase construction of CMsFdc.
    74  */
    73  */
    75 void CMsFdc::ConstructL()
    74 void CMsFdc::ConstructL()
    76 	{
    75 	{
    77 	OstTraceFunctionEntry0( CMSFDC_CONSTRUCTL_ENTRY );
    76 
       
    77 #ifdef __FLOG_ACTIVE
       
    78 	CUsbLog::Connect();
       
    79 #endif
       
    80 	LOG_FUNC
    78 	
    81 	
    79 	//Set up the connection with mount manager
    82 	//Set up the connection with mount manager
    80 	TInt error = iMsmmSession.Connect();
    83 	TInt error = iMsmmSession.Connect();
    81 	if ( error )
    84 	if ( error )
    82 		{
    85 		{
    83         OstTrace1( TRACE_NORMAL, CMSFDC_CONSTRUCTL, 
    86 		LOGTEXT2(_L("Failed to connect to MSMM %d"),error);
    84                 "Failed to connect to MSMM %d",error );
    87 		User::Leave(error);
    85         User::Leave(error);
    88 		}
    86 		}
    89 	else
    87 	else
    90 		{
    88 		{
    91 		LOGTEXT(_L("Connected to MSMM OK"));
    89         OstTrace0( TRACE_NORMAL, CMSFDC_CONSTRUCTL_DUP1, 
    92 		}
    90                 "Connected to MSMM OK" );
       
    91  		}
       
    92 	OstTraceFunctionExit0( CMSFDC_CONSTRUCTL_EXIT );
       
    93 	}
    93 	}
    94 /**
    94 /**
    95   Get called when FDF is trying to load the driver for Mass Storage Device. 
    95   Get called when FDF is trying to load the driver for Mass Storage Device. 
    96  
    96  
    97   @param	aDevice  	 				Device ID allocated by FDF for the newly inserted device
    97   @param	aDevice  	 				Device ID allocated by FDF for the newly inserted device
   104 TInt CMsFdc::Mfi1NewFunction(TUint aDeviceId,
   104 TInt CMsFdc::Mfi1NewFunction(TUint aDeviceId,
   105 		const TArray<TUint>& aInterfaces,
   105 		const TArray<TUint>& aInterfaces,
   106 		const TUsbDeviceDescriptor& aDeviceDescriptor,
   106 		const TUsbDeviceDescriptor& aDeviceDescriptor,
   107 		const TUsbConfigurationDescriptor& aConfigurationDescriptor)
   107 		const TUsbConfigurationDescriptor& aConfigurationDescriptor)
   108 	{
   108 	{
   109 	OstTraceFunctionEntry0( CMSFDC_MFI1NEWFUNCTION_ENTRY );
   109 	LOG_FUNC // this is the evidence that the message got through.
   110 	 
   110 	LOGTEXT2(_L8("\t***** Mass Storage FD notified of device (ID %d) attachment!"), aDeviceId);
   111 	// this is the evidence that the message got through.
   111 	
   112 	OstTrace1( TRACE_NORMAL, CMSFDC_MFI1NEWFUNCTION, 
       
   113 	        "***** Mass Storage FD notified of device (ID %d) attachment!", aDeviceId );	
       
   114 
   112 
   115 	// Mass Storage FDC only claims one interface.
   113 	// Mass Storage FDC only claims one interface.
   116 	OstTrace1( TRACE_NORMAL, CMSFDC_MFI1NEWFUNCTION_DUP1, 
   114 	LOGTEXT2(_L8("\t***** Mass Storage FD interface to request token is %d"), aInterfaces[0]);
   117 	            "***** Mass Storage FD interface to request token is %d", aInterfaces[0] );    
       
   118 	TUint32 token = Observer().TokenForInterface(aInterfaces[0]);
   115 	TUint32 token = Observer().TokenForInterface(aInterfaces[0]);
   119 	OstTrace1( TRACE_NORMAL, CMSFDC_MFI1NEWFUNCTION_DUP2, 
   116 	LOGTEXT2(_L8("\t***** Mass Storage FD tokenInterface  %d"), token);
   120 	        "***** Mass Storage FD tokenInterface  %d", token );
       
   121 	if (token == 0)
   117 	if (token == 0)
   122 		{
   118 		{
   123         OstTrace0( TRACE_ERROR, CMSFDC_MFI1NEWFUNCTION_DUP3, 
   119 		LOGTEXT(_L8("\t***** Mass Storage FDC device containing this function is removed."));
   124 	            "***** Mass Storage FDC device containing this function is removed." );
       
   125 		OstTraceFunctionExit0( CMSFDC_MFI1NEWFUNCTION_EXIT );
       
   126 		return KErrGeneral;
   120 		return KErrGeneral;
   127 		}
   121 		}
   128 
   122 
   129 	//Get the languages that is supported by this device.
   123 	//Get the languages that is supported by this device.
   130 	TUint defaultlangid = 0;
   124 	TUint defaultlangid = 0;
   131 	TRAPD(error, GetDefaultLanguageL(aDeviceId, defaultlangid));
   125 	TRAPD(error, GetDefaultLanguageL(aDeviceId, defaultlangid));
   132 
   126 
   133 	if (error)
   127 	if (error)
   134 		{
   128 		{
   135         OstTrace0( TRACE_ERROR, CMSFDC_MFI1NEWFUNCTION_DUP4, 
   129 		LOGTEXT(_L8("\t***** Mass Storage FDC getting language array failed"));
   136 	                "***** Mass Storage FDC getting language array failed" );
       
   137 		OstTraceFunctionExit0( CMSFDC_MFI1NEWFUNCTION_EXIT_DUP1 );
       
   138 		return error;
   130 		return error;
   139 		}
   131 		}
   140 	
   132 	
   141 	TUSBMSDeviceDescription* data = NULL;
   133 	TUSBMSDeviceDescription* data = NULL;
   142 	TRAP(error, data = new (ELeave) TUSBMSDeviceDescription);
   134 	TRAP(error, data = new (ELeave) TUSBMSDeviceDescription);
   143 	if (error)
   135 	if (error)
   144 		{
   136 		{
   145         OstTrace0( TRACE_ERROR, CMSFDC_MFI1NEWFUNCTION_DUP5, 
   137 		LOGTEXT(_L8("\t***** Mass Storage FDC Memory allocation Failed"));		
   146 	                    "***** Mass Storage FDC Memory allocation Failed" );
       
   147 		OstTraceFunctionExit0( CMSFDC_MFI1NEWFUNCTION_EXIT_DUP2 );
       
   148 		return error;
   138 		return error;
   149 		}
   139 		}
   150 
   140 
   151 	//Get Serial number from string descriptor
   141 	//Get Serial number from string descriptor
   152 	error = Observer().GetSerialNumberStringDescriptor(aDeviceId, defaultlangid, 
   142 	error = Observer().GetSerialNumberStringDescriptor(aDeviceId, defaultlangid, 
   153 			data->iSerialNumber);
   143 			data->iSerialNumber);
   154 	
   144 	
   155 	if (error)
   145 	if (error)
   156 		{
   146 		{
   157         OstTrace0( TRACE_ERROR, CMSFDC_MFI1NEWFUNCTION_DUP6, 
   147 		LOGTEXT(_L8("\t***** Mass Storage FDC getting Serial Number failed"));
   158                     "***** Mass Storage FDC getting Serial Number Failed" );
   148 		delete data;
   159 		delete data;
   149 		return error;
   160 		OstTraceFunctionExit0( CMSFDC_MFI1NEWFUNCTION_EXIT_DUP3 );
   150 		}
   161 		return error;
   151 	else
   162 		}
   152 		{
   163 	else
   153 		LOGTEXT2(_L("\t***** Mass Storage FDC Serial String is %S"), &data->iSerialNumber);
   164 		{
   154 		}
   165         OstTraceExt1( TRACE_ERROR, CMSFDC_MFI1NEWFUNCTION_DUP7, 
       
   166 	                    "***** Mass Storage FDC Serial String is %S", data->iSerialNumber );
       
   167 	    }
       
   168 	//Get Product string descriptor
   155 	//Get Product string descriptor
   169 	error = Observer().GetProductStringDescriptor(aDeviceId, defaultlangid, data->iProductString);
   156 	error = Observer().GetProductStringDescriptor(aDeviceId, defaultlangid, data->iProductString);
   170 	
   157 	
   171 
   158 
   172 	if (error)
   159 	if (error)
   173 		{
   160 		{
   174         OstTrace0( TRACE_ERROR, CMSFDC_MFI1NEWFUNCTION_DUP8, 
   161 		LOGTEXT(_L8("\t***** Mass Storage FDC getting Product string failed"));
   175 	                    "***** Mass Storage FDC getting Product string Failed" );
   162 		delete data;
   176 	    delete data;
   163 		return error;
   177 		OstTraceFunctionExit0( CMSFDC_MFI1NEWFUNCTION_EXIT_DUP4 );
   164 		}
   178 		return error;
   165 	else
   179 		}
   166 		{
   180 	else
   167 		LOGTEXT2(_L("\t***** Mass Storage FDC Product String is %S"), &data->iProductString);
   181 		{
       
   182         OstTraceExt1( TRACE_NORMAL, CMSFDC_MFI1NEWFUNCTION_DUP9, 
       
   183 	                        "***** Mass Storage FDC Product String is %S", data->iProductString );
       
   184 		}
   168 		}
   185 
   169 
   186 	//Get Manufacturer string descriptor
   170 	//Get Manufacturer string descriptor
   187 	error = Observer().GetManufacturerStringDescriptor(aDeviceId, defaultlangid, 
   171 	error = Observer().GetManufacturerStringDescriptor(aDeviceId, defaultlangid, 
   188 			data->iManufacturerString);
   172 			data->iManufacturerString);
   189 	
   173 	
   190 	if (error)
   174 	if (error)
   191 		{
   175 		{
   192         OstTrace0( TRACE_ERROR, CMSFDC_MFI1NEWFUNCTION_DUP10, 
   176 		LOGTEXT(_L8("\t***** Mass Storage FDC getting Manufacturer string failed"));
   193                     "***** Mass Storage FDC getting Manufacturer string Failed" );
   177 		delete data;
   194 		delete data;
   178 		return error;
   195 		OstTraceFunctionExit0( CMSFDC_MFI1NEWFUNCTION_EXIT_DUP5 );
   179 		}
   196 		return error;
   180 	else
   197 		}
   181 		{
   198 	else
   182 		LOGTEXT2(_L("\t***** Mass Storage FDC Manufacturer String is %S"), 
   199 		{
   183 				&data->iManufacturerString);		
   200         OstTraceExt1( TRACE_NORMAL, CMSFDC_MFI1NEWFUNCTION_DUP11, 
       
   201 	                            "***** Mass Storage FDC Manufacturer String is %S", data->iManufacturerString );
       
   202 		}	
   184 		}	
   203 	
   185 	
   204 	/************************Remote Wakeup Attribute acquiring***********************/
   186 	/************************Remote Wakeup Attribute acquiring***********************/
   205 	TUint8 attr = aConfigurationDescriptor.Attributes();
   187 	TUint8 attr = aConfigurationDescriptor.Attributes();
   206 
   188 
   208 	RUsbInterface interface_ep0;
   190 	RUsbInterface interface_ep0;
   209     TUsbInterfaceDescriptor ifDescriptor;
   191     TUsbInterfaceDescriptor ifDescriptor;
   210     error = interface_ep0.Open(token);
   192     error = interface_ep0.Open(token);
   211     if (error)
   193     if (error)
   212     	{
   194     	{
   213         OstTrace0( TRACE_ERROR, CMSFDC_MFI1NEWFUNCTION_DUP12, 
   195 		LOGTEXT(_L8("\t***** Mass Storage FDC Open interface handle failed"));
   214                         "***** Mass Storage FDC Open interface handle Failed" );
   196 		delete data;
   215     	delete data;
       
   216 		OstTraceFunctionExit0( CMSFDC_MFI1NEWFUNCTION_EXIT_DUP6 );
       
   217 		return error;
   197 		return error;
   218     	}
   198     	}
   219     else
   199     else
   220     	{
   200     	{
   221         OstTrace0( TRACE_NORMAL, CMSFDC_MFI1NEWFUNCTION_DUP13, 
   201 		LOGTEXT(_L8("\t***** Mass Storage FDC Open interface handle OK"));
   222                          "***** Mass Storage FDC Open interface handle OK" );
       
   223     	}
   202     	}
   224 
   203 
   225     error = interface_ep0.GetInterfaceDescriptor(ifDescriptor);
   204     error = interface_ep0.GetInterfaceDescriptor(ifDescriptor);
   226 	interface_ep0.Close();
       
   227     if (error)
   205     if (error)
   228     	{
   206     	{
   229         OstTrace0( TRACE_ERROR, CMSFDC_MFI1NEWFUNCTION_DUP14, 
   207 		LOGTEXT(_L8("\t***** Mass Storage FDC get interface descriptor failed"));
   230                         "***** Mass Storage FDC get interface descriptor Failed" );
   208 		interface_ep0.Close();
   231 		delete data;
   209 		delete data;
   232 		OstTraceFunctionExit0( CMSFDC_MFI1NEWFUNCTION_EXIT_DUP7 );
       
   233 		return error;
   210 		return error;
   234     	}
   211     	}
   235     else
   212     else
   236     	{
   213     	{
   237         OstTrace0( TRACE_NORMAL, CMSFDC_MFI1NEWFUNCTION_DUP15, 
   214 		LOGTEXT(_L8("\t***** Mass Storage FDC get interface descriptor OK"));
   238                          "***** Mass Storage FDC get interface descriptor OK" );
       
   239     	}
   215     	}
   240 	
   216 	
   241 	/*********************************************************************************/
   217 	/*********************************************************************************/
   242 	
   218 	
   243 	//Send informations to Mass Storage Mount Manager
   219 	//Send informations to Mass Storage Mount Manager
   259 	//This OTG information may need to be changed when OTG descriptor becomes available.
   235 	//This OTG information may need to be changed when OTG descriptor becomes available.
   260 	data->iOtgInformation        = aDeviceDescriptor.DeviceBcd();
   236 	data->iOtgInformation        = aDeviceDescriptor.DeviceBcd();
   261 	
   237 	
   262 	error = iMsmmSession.AddFunction(*data, aInterfaces[0], token);
   238 	error = iMsmmSession.AddFunction(*data, aInterfaces[0], token);
   263 	
   239 	
       
   240 	interface_ep0.Close();
   264 	delete data;
   241 	delete data;
   265 	OstTraceFunctionExit0( CMSFDC_MFI1NEWFUNCTION_EXIT_DUP8 );
       
   266 	return error;
   242 	return error;
   267 	}
   243 	}
   268 /**
   244 /**
   269   Get called when FDF unload the function controller of the removed device.
   245   Get called when FDF unload the function controller of the removed device.
   270  
   246  
   271   @param	aDeviceId	The device ID that indicates that which device's been removed.
   247   @param	aDeviceId	The device ID that indicates that which device's been removed.
   272  */
   248  */
   273 void CMsFdc::Mfi1DeviceDetached(TUint aDeviceId)
   249 void CMsFdc::Mfi1DeviceDetached(TUint aDeviceId)
   274 	{
   250 	{
   275 	OstTraceFunctionEntry0( CMSFDC_MFI1DEVICEDETACHED_ENTRY );
   251 	LOG_FUNC // this is the evidence that the message got through.
   276     // this is the evidence that the message got through.
   252 	LOGTEXT2(_L8("\t***** Mass Storage FD notified of device (ID %d) detachment!"), aDeviceId);
   277 	OstTrace1( TRACE_NORMAL, CMSFDC_MFI1DEVICEDETACHED, 
       
   278 	        "***** Mass Storage FD notified of device (ID %d) detachment!", aDeviceId );
       
   279 	iMsmmSession.RemoveDevice(aDeviceId);
   253 	iMsmmSession.RemoveDevice(aDeviceId);
   280 
   254 
   281 	OstTraceFunctionExit0( CMSFDC_MFI1DEVICEDETACHED_EXIT );
       
   282 	}
   255 	}
   283 
   256 
   284 /**
   257 /**
   285   Convert the pointer of this CMsFdc object to a pointer to TAny
   258   Convert the pointer of this CMsFdc object to a pointer to TAny
   286  
   259  
   287   @param	aUid	A UID that indicate the interface that is needed..
   260   @param	aUid	A UID that indicate the interface that is needed..
   288   @return	this pointer if aUid equals to the interface uid of CMsFdc or otherwise NULL.
   261   @return	this pointer if aUid equals to the interface uid of CMsFdc or otherwise NULL.
   289  */
   262  */
   290 TAny* CMsFdc::GetInterface(TUid aUid)
   263 TAny* CMsFdc::GetInterface(TUid aUid)
   291 	{
   264 	{
   292 	OstTraceFunctionEntry0( CMSFDC_GETINTERFACE_ENTRY );
   265 	LOG_LINE
   293 	OstTrace1( TRACE_NORMAL, CMSFDC_GETINTERFACE, "aUid = 0x%08x", aUid.iUid );
   266 	LOG_FUNC;
   294 	
   267 	LOGTEXT2(_L8("\taUid = 0x%08x"), aUid);
       
   268 
   295 	TAny* ret = NULL;
   269 	TAny* ret = NULL;
   296 	if ( aUid == TUid::Uid(KFdcInterfaceV1) )
   270 	if ( aUid == TUid::Uid(KFdcInterfaceV1) )
   297 		{
   271 		{
   298 		ret = reinterpret_cast<TAny*>(
   272 		ret = reinterpret_cast<TAny*>(
   299 			static_cast<MFdcInterfaceV1*>(this)
   273 			static_cast<MFdcInterfaceV1*>(this)
   300 			);
   274 			);
   301 		}
   275 		}
   302 	OstTrace1( TRACE_NORMAL, CMSFDC_GETINTERFACE_DUP1, 
   276 
   303         "ret = [0x%08x]", ret );
   277 	LOGTEXT2(_L8("\tret = [0x%08x]"), ret);
   304 	OstTraceFunctionExit0( CMSFDC_GETINTERFACE_EXIT );
       
   305 	return ret;
   278 	return ret;
   306 	}
   279 	}
   307 /**
   280 /**
   308   Get the default language ID that is supported by this Mass Storage device.
   281   Get the default language ID that is supported by this Mass Storage device.
   309  
   282