usbmgmt/usbmgr/usbman/client/SRC/RUsb.cpp
branchRCL_3
changeset 16 012cc2ee6408
parent 15 f92a4f87e424
equal deleted inserted replaced
15:f92a4f87e424 16:012cc2ee6408
     1 /*
     1 /*
     2 * Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2003-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".
    17 
    17 
    18 #include <e32uid.h>
    18 #include <e32uid.h>
    19 #include <usbman.h>
    19 #include <usbman.h>
    20 #include <usb.h>
    20 #include <usb.h>
    21 #include <e32base.h>
    21 #include <e32base.h>
       
    22 #include "rusb.h"
       
    23 #include <usb/usblogger.h>
       
    24 
       
    25 #ifdef __FLOG_ACTIVE
       
    26 _LIT8(KLogComponent, "USBMAN");
       
    27 #endif
    22 
    28 
    23 #ifdef __USBMAN_NO_PROCESSES__
    29 #ifdef __USBMAN_NO_PROCESSES__
    24 #include <e32math.h>
    30 #include <e32math.h>
    25 #endif
       
    26 
       
    27 #include <usb/usblogger.h>
       
    28 
       
    29 #include "rusb.h"
       
    30 
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "RUsbTraces.h"
       
    34 #endif
    31 #endif
    35 
    32 
    36 
    33 
    37 static TInt StartServer()
    34 static TInt StartServer()
    38 //
    35 //
   110 	// from KErrNone
   107 	// from KErrNone
   111 	err = (server.ExitType() == EExitPanic) ? KErrServerTerminated : stat.Int();
   108 	err = (server.ExitType() == EExitPanic) ? KErrServerTerminated : stat.Int();
   112 
   109 
   113 	server.Close();
   110 	server.Close();
   114 	
   111 	
   115 	OstTrace1( TRACE_NORMAL, RUSB_STARTSERVER, "::StartServer;USB server started successfully: err=%d", err );
   112 	LOGTEXT2(_L8("USB server started successfully: err = %d\n"),err);
   116 	
       
   117 
   113 
   118 	return err;
   114 	return err;
   119 	}
   115 	}
   120 
   116 
   121 
   117 
   123 
   119 
   124 EXPORT_C RUsb::RUsb() 
   120 EXPORT_C RUsb::RUsb() 
   125 	: iDeviceStatePkg(0), iServiceStatePkg(0), iMessagePkg(0), 
   121 	: iDeviceStatePkg(0), iServiceStatePkg(0), iMessagePkg(0), 
   126 	  iHostPkg(TDeviceEventInformation())
   122 	  iHostPkg(TDeviceEventInformation())
   127 	{
   123 	{
   128 	OstTraceFunctionEntry0( RUSB_RUSB_CONS_ENTRY );
   124 	LOG_LINE
   129 	OstTraceFunctionExit0( RUSB_RUSB_CONS_EXIT );
   125 	LOG_FUNC
   130 	}
   126 	}
   131 
   127 
   132 EXPORT_C RUsb::~RUsb()
   128 EXPORT_C RUsb::~RUsb()
   133 	{
   129 	{
   134     OstTraceFunctionEntry0( RUSB_RUSB_DES_ENTRY );
   130 	LOG_LINE
   135 	OstTraceFunctionExit0( RUSB_RUSB_DES_EXIT );
   131 	LOG_FUNC
   136 	}
   132 	}
   137 
   133 
   138 EXPORT_C TVersion RUsb::Version() const
   134 EXPORT_C TVersion RUsb::Version() const
   139 	{
   135 	{
   140 	return(TVersion(KUsbSrvMajorVersionNumber,KUsbSrvMinorVersionNumber,KUsbSrvBuildVersionNumber));
   136 	return(TVersion(KUsbSrvMajorVersionNumber,KUsbSrvMinorVersionNumber,KUsbSrvBuildVersionNumber));
   141 	}
   137 	}
   142 
   138 
   143 EXPORT_C TInt RUsb::Connect()
   139 EXPORT_C TInt RUsb::Connect()
   144 	{
   140 	{
   145 	OstTraceFunctionEntry0( RUSB_CONNECT_ENTRY );
   141 	LOG_LINE
       
   142 	LOG_FUNC
       
   143 
   146 	TInt retry = 2;
   144 	TInt retry = 2;
   147 	
   145 	
   148 	FOREVER
   146 	FOREVER
   149 		{
   147 		{
   150 		// Create the session to UsbSrv with 10 asynchronous message slots
   148 		// Create the session to UsbSrv with 10 asynchronous message slots
   151 		TInt err = CreateSession(KUsbServerName, Version(), 10);
   149 		TInt err = CreateSession(KUsbServerName, Version(), 10);
   152 
   150 
   153 		if ((err != KErrNotFound) && (err != KErrServerTerminated))
   151 		if ((err != KErrNotFound) && (err != KErrServerTerminated))
   154 			{
   152 			{
   155 			OstTraceFunctionExit0( RUSB_CONNECT_EXIT );
       
   156 			return err;
   153 			return err;
   157 			}
   154 			}
   158 
   155 
   159 		if (--retry == 0)
   156 		if (--retry == 0)
   160 			{
   157 			{
   161 			OstTraceFunctionExit0( RUSB_CONNECT_EXIT_DUP1 );
       
   162 			return err;
   158 			return err;
   163 			}
   159 			}
   164 
   160 
   165 		err = StartServer();
   161 		err = StartServer();
   166 
   162 
   167 		if ((err != KErrNone) && (err != KErrAlreadyExists))
   163 		if ((err != KErrNone) && (err != KErrAlreadyExists))
   168 			{
   164 			{
   169 			OstTraceFunctionExit0( RUSB_CONNECT_EXIT_DUP2 );
       
   170 			return err;
   165 			return err;
   171 			}
   166 			}
   172 		}
   167 		}
   173 	}
   168 	}
   174 
   169 
   175 EXPORT_C void RUsb::Start(TRequestStatus& aStatus)
   170 EXPORT_C void RUsb::Start(TRequestStatus& aStatus)
   176 	{
   171 	{
   177 	OstTraceFunctionEntry0( RUSB_START_ENTRY );
   172 	LOG_LINE
   178 	
   173 	LOG_FUNC
       
   174 
   179 	SendReceive(EUsbStart, aStatus);
   175 	SendReceive(EUsbStart, aStatus);
   180 	OstTraceFunctionExit0( RUSB_START_EXIT );
       
   181 	}
   176 	}
   182 
   177 
   183 EXPORT_C void RUsb::StartCancel()
   178 EXPORT_C void RUsb::StartCancel()
   184 	{
   179 	{
   185 	OstTraceFunctionEntry0( RUSB_STARTCANCEL_ENTRY );
   180 	LOG_LINE
       
   181 	LOG_FUNC
       
   182 
   186 	SendReceive(EUsbStartCancel);
   183 	SendReceive(EUsbStartCancel);
   187 	OstTraceFunctionExit0( RUSB_STARTCANCEL_EXIT );
       
   188 	}
   184 	}
   189 
   185 
   190 EXPORT_C void RUsb::Stop()
   186 EXPORT_C void RUsb::Stop()
   191 	{
   187 	{
   192 	OstTraceFunctionEntry0( RUSB_STOP_ENTRY );
   188 	LOG_LINE
       
   189 	LOG_FUNC
       
   190 
   193 	SendReceive(EUsbStop);
   191 	SendReceive(EUsbStop);
   194 	OstTraceFunctionExit0( RUSB_STOP_EXIT );
       
   195 	}
   192 	}
   196 
   193 
   197 EXPORT_C void RUsb::Stop(TRequestStatus& aStatus)
   194 EXPORT_C void RUsb::Stop(TRequestStatus& aStatus)
   198 	{
   195 	{
   199 	OstTraceFunctionEntry0( RUSB_STOP_TREQUESTSTATUS_ENTRY );
   196 	LOG_LINE
       
   197 	LOG_FUNC
       
   198 
   200 	SendReceive(EUsbStop, aStatus);
   199 	SendReceive(EUsbStop, aStatus);
   201 	OstTraceFunctionExit0( RUSB_STOP_TREQUESTSTATUS_EXIT );
       
   202 	}
   200 	}
   203 
   201 
   204 EXPORT_C void RUsb::StopCancel()
   202 EXPORT_C void RUsb::StopCancel()
   205 	{
   203 	{
   206 	OstTraceFunctionEntry0( RUSB_STOPCANCEL_ENTRY );
   204 	LOG_LINE
       
   205 	LOG_FUNC
       
   206 
   207 	SendReceive(EUsbStopCancel);
   207 	SendReceive(EUsbStopCancel);
   208 	OstTraceFunctionExit0( RUSB_STOPCANCEL_EXIT );
       
   209 	}
   208 	}
   210 
   209 
   211 EXPORT_C TInt RUsb::GetServiceState(TUsbServiceState& aState)
   210 EXPORT_C TInt RUsb::GetServiceState(TUsbServiceState& aState)
   212 	{
   211 	{
   213 	OstTraceFunctionEntry0( RUSB_GETSERVICESTATE_ENTRY );
   212 	LOG_LINE
       
   213 	LOG_FUNC
       
   214 
   214 	TPckg<TUint32> pkg(aState);
   215 	TPckg<TUint32> pkg(aState);
   215 	TInt ret=SendReceive(EUsbGetCurrentState, TIpcArgs(&pkg));
   216 	TInt ret=SendReceive(EUsbGetCurrentState, TIpcArgs(&pkg));
   216 	aState=(TUsbServiceState)pkg();
   217 	aState=(TUsbServiceState)pkg();
   217 	OstTraceFunctionExit0( RUSB_GETSERVICESTATE_EXIT );
       
   218 	return ret;
   218 	return ret;
   219 	}
   219 	}
   220 
   220 
   221 EXPORT_C TInt RUsb::GetCurrentState(TUsbServiceState& aState)
   221 EXPORT_C TInt RUsb::GetCurrentState(TUsbServiceState& aState)
   222 	{
   222 	{
   223 	OstTraceFunctionEntry0( RUSB_GETCURRENTSTATE_ENTRY );
   223 	LOG_LINE
       
   224 	LOG_FUNC
       
   225 
   224 	return GetServiceState(aState);
   226 	return GetServiceState(aState);
   225 	}
   227 	}
   226 
   228 
   227 EXPORT_C void RUsb::ServiceStateNotification(TUsbServiceState& aState,
   229 EXPORT_C void RUsb::ServiceStateNotification(TUsbServiceState& aState,
   228 	TRequestStatus& aStatus)
   230 	TRequestStatus& aStatus)
   229 	{
   231 	{
   230 	OstTraceFunctionEntry0( RUSB_SERVICESTATENOTIFICATION_ENTRY );
   232 	LOG_LINE
       
   233 	LOG_FUNC
   231 
   234 
   232 	iServiceStatePkg.Set((TUint8*)&aState, sizeof(TUint32), sizeof(TUint32));
   235 	iServiceStatePkg.Set((TUint8*)&aState, sizeof(TUint32), sizeof(TUint32));
   233 
   236 
   234 	SendReceive(EUsbRegisterServiceObserver, TIpcArgs(&iServiceStatePkg), aStatus);
   237 	SendReceive(EUsbRegisterServiceObserver, TIpcArgs(&iServiceStatePkg), aStatus);
   235 	OstTraceFunctionExit0( RUSB_SERVICESTATENOTIFICATION_EXIT );
       
   236 	}
   238 	}
   237 
   239 
   238 EXPORT_C void RUsb::ServiceStateNotificationCancel()
   240 EXPORT_C void RUsb::ServiceStateNotificationCancel()
   239 	{
   241 	{
   240 	OstTraceFunctionEntry0( RUSB_SERVICESTATENOTIFICATIONCANCEL_ENTRY );
   242 	LOG_LINE
       
   243 	LOG_FUNC
       
   244 
   241 	SendReceive(EUsbCancelServiceObserver);
   245 	SendReceive(EUsbCancelServiceObserver);
   242 	OstTraceFunctionExit0( RUSB_SERVICESTATENOTIFICATIONCANCEL_EXIT );
       
   243 	}
   246 	}
   244 
   247 
   245 EXPORT_C TInt RUsb::GetDeviceState(TUsbDeviceState& aState)
   248 EXPORT_C TInt RUsb::GetDeviceState(TUsbDeviceState& aState)
   246 	{
   249 	{
   247 	OstTraceFunctionEntry0( RUSB_GETDEVICESTATE_ENTRY );
   250 	LOG_LINE
       
   251 	LOG_FUNC
       
   252 
   248 	TPckg<TUint32> pkg(aState);
   253 	TPckg<TUint32> pkg(aState);
   249 	TInt ret=SendReceive(EUsbGetCurrentDeviceState, TIpcArgs(&pkg));
   254 	TInt ret=SendReceive(EUsbGetCurrentDeviceState, TIpcArgs(&pkg));
   250 	aState=(TUsbDeviceState)pkg();
   255 	aState=(TUsbDeviceState)pkg();
   251 	OstTraceFunctionExit0( RUSB_GETDEVICESTATE_EXIT );
       
   252 	return ret;
   256 	return ret;
   253 	}
   257 	}
   254 
   258 
   255 EXPORT_C void RUsb::DeviceStateNotification(TUint aEventMask, TUsbDeviceState& aState,
   259 EXPORT_C void RUsb::DeviceStateNotification(TUint aEventMask, TUsbDeviceState& aState,
   256 											TRequestStatus& aStatus)
   260 											TRequestStatus& aStatus)
   257 	{
   261 	{
   258 	OstTraceFunctionEntry0( RUSB_DEVICESTATENOTIFICATION_ENTRY );
   262 	LOG_LINE
       
   263 	LOG_FUNC
       
   264 
   259 	iDeviceStatePkg.Set((TUint8*)&aState, sizeof(TUint32), sizeof(TUint32));
   265 	iDeviceStatePkg.Set((TUint8*)&aState, sizeof(TUint32), sizeof(TUint32));
   260 
   266 
   261 	SendReceive(EUsbRegisterObserver, TIpcArgs(aEventMask, &iDeviceStatePkg), aStatus);
   267 	SendReceive(EUsbRegisterObserver, TIpcArgs(aEventMask, &iDeviceStatePkg), aStatus);
   262 	OstTraceFunctionExit0( RUSB_DEVICESTATENOTIFICATION_EXIT );
       
   263 	}
   268 	}
   264 
   269 
   265 EXPORT_C void RUsb::DeviceStateNotificationCancel()
   270 EXPORT_C void RUsb::DeviceStateNotificationCancel()
   266 	{
   271 	{
   267 	OstTraceFunctionEntry0( RUSB_DEVICESTATENOTIFICATIONCANCEL_ENTRY );
   272 	LOG_LINE
       
   273 	LOG_FUNC
       
   274 
   268 	SendReceive(EUsbCancelObserver);
   275 	SendReceive(EUsbCancelObserver);
   269 	OstTraceFunctionExit0( RUSB_DEVICESTATENOTIFICATIONCANCEL_EXIT );
       
   270 	}
   276 	}
   271 
   277 
   272 EXPORT_C void RUsb::StateNotification(TUint aEventMask, TUsbDeviceState& aState, TRequestStatus& aStatus)
   278 EXPORT_C void RUsb::StateNotification(TUint aEventMask, TUsbDeviceState& aState, TRequestStatus& aStatus)
   273 	{
   279 	{
   274 	OstTraceFunctionEntry0( RUSB_STATENOTIFICATION_ENTRY );
   280 	LOG_LINE
       
   281 	LOG_FUNC
       
   282 
   275 	DeviceStateNotification(aEventMask, aState, aStatus);
   283 	DeviceStateNotification(aEventMask, aState, aStatus);
   276 	OstTraceFunctionExit0( RUSB_STATENOTIFICATION_EXIT );
       
   277 	}
   284 	}
   278 
   285 
   279 EXPORT_C void RUsb::StateNotificationCancel()
   286 EXPORT_C void RUsb::StateNotificationCancel()
   280 	{
   287 	{
   281 	OstTraceFunctionEntry0( RUSB_STATENOTIFICATIONCANCEL_ENTRY );
   288 	LOG_LINE
       
   289 	LOG_FUNC
       
   290 
   282 	DeviceStateNotificationCancel();
   291 	DeviceStateNotificationCancel();
   283 	OstTraceFunctionExit0( RUSB_STATENOTIFICATIONCANCEL_EXIT );
       
   284 	}
   292 	}
   285 	
   293 	
   286 EXPORT_C void RUsb::TryStart(TInt aPersonalityId, TRequestStatus& aStatus)
   294 EXPORT_C void RUsb::TryStart(TInt aPersonalityId, TRequestStatus& aStatus)
   287 	{
   295 	{
   288 	OstTraceFunctionEntry0( RUSB_TRYSTART_ENTRY );
   296 	LOG_LINE
       
   297 	LOG_FUNC
   289 
   298 
   290 	TIpcArgs ipcArgs(aPersonalityId);
   299 	TIpcArgs ipcArgs(aPersonalityId);
   291 	SendReceive(EUsbTryStart, ipcArgs, aStatus);
   300 	SendReceive(EUsbTryStart, ipcArgs, aStatus);
   292 	OstTraceFunctionExit0( RUSB_TRYSTART_EXIT );
       
   293 	}
   301 	}
   294 
   302 
   295 EXPORT_C void RUsb::TryStop(TRequestStatus& aStatus)
   303 EXPORT_C void RUsb::TryStop(TRequestStatus& aStatus)
   296 	{
   304 	{
   297 	OstTraceFunctionEntry0( RUSB_TRYSTOP_ENTRY );
   305 	LOG_LINE
       
   306 	LOG_FUNC
       
   307 
   298 	SendReceive(EUsbTryStop, aStatus);
   308 	SendReceive(EUsbTryStop, aStatus);
   299 	OstTraceFunctionExit0( RUSB_TRYSTOP_EXIT );
       
   300 	}
   309 	}
   301 	
   310 	
   302 EXPORT_C TInt RUsb::CancelInterest(TUsbReqType aMessageId)
   311 EXPORT_C TInt RUsb::CancelInterest(TUsbReqType aMessageId)
   303 	{
   312 	{
   304 	OstTraceFunctionEntry0( RUSB_CANCELINTEREST_ENTRY );
   313 	LOG_LINE
       
   314 	LOG_FUNC
   305 
   315 
   306 	TInt messageId;
   316 	TInt messageId;
   307 	switch (aMessageId)
   317 	switch (aMessageId)
   308 		{
   318 		{
   309 	case EStart:
   319 	case EStart:
   326 	return SendReceive(EUsbCancelInterest, ipcArgs);
   336 	return SendReceive(EUsbCancelInterest, ipcArgs);
   327 	}
   337 	}
   328 
   338 
   329 EXPORT_C TInt RUsb::GetDescription(TInt aPersonalityId, HBufC*& aLocalizedPersonalityDescriptor)
   339 EXPORT_C TInt RUsb::GetDescription(TInt aPersonalityId, HBufC*& aLocalizedPersonalityDescriptor)
   330 	{
   340 	{
   331 	OstTraceFunctionEntry0( RUSB_GETDESCRIPTION_ENTRY );
   341 	LOG_LINE
       
   342 	LOG_FUNC
       
   343 
   332 	TInt ret = KErrNone;
   344 	TInt ret = KErrNone;
   333 	// caller is responsible for freeing up memory allocatd for aLocalizedPersonalityDescriptor
   345 	// caller is responsible for freeing up memory allocatd for aLocalizedPersonalityDescriptor
   334 	TRAP(ret, aLocalizedPersonalityDescriptor = HBufC::NewL(KUsbStringDescStringMaxSize));
   346 	TRAP(ret, aLocalizedPersonalityDescriptor = HBufC::NewL(KUsbStringDescStringMaxSize));
   335 	if (ret == KErrNone)
   347 	if (ret == KErrNone)
   336 		{
   348 		{
   343 		{
   355 		{
   344 		// just in case caller tries to free the memory before checking the return code
   356 		// just in case caller tries to free the memory before checking the return code
   345 		aLocalizedPersonalityDescriptor = NULL;
   357 		aLocalizedPersonalityDescriptor = NULL;
   346 		}
   358 		}
   347 
   359 
   348 	OstTraceFunctionExit0( RUSB_GETDESCRIPTION_EXIT );
       
   349 	return ret;	
   360 	return ret;	
   350 	}
   361 	}
   351 	
   362 	
   352 EXPORT_C TInt RUsb::GetCurrentPersonalityId(TInt& aPersonalityId)
   363 EXPORT_C TInt RUsb::GetCurrentPersonalityId(TInt& aPersonalityId)
   353 	{
   364 	{
   354 	OstTraceFunctionEntry0( RUSB_GETCURRENTPERSONALITYID_ENTRY );
   365 	LOG_LINE
       
   366 	LOG_FUNC
   355 
   367 
   356 	TPckg<TInt> pkg0(aPersonalityId);
   368 	TPckg<TInt> pkg0(aPersonalityId);
   357 	TInt ret = SendReceive(EUsbGetCurrentPersonalityId, TIpcArgs(&pkg0));
   369 	TInt ret = SendReceive(EUsbGetCurrentPersonalityId, TIpcArgs(&pkg0));
   358 	aPersonalityId = static_cast<TInt>(pkg0());
   370 	aPersonalityId = static_cast<TInt>(pkg0());
   359 	OstTraceFunctionExit0( RUSB_GETCURRENTPERSONALITYID_EXIT );
       
   360 	return ret;	
   371 	return ret;	
   361 	}
   372 	}
   362 
   373 
   363 EXPORT_C TInt RUsb::GetSupportedClasses(TInt aPersonalityId, RArray<TUid>& aClassUids)
   374 EXPORT_C TInt RUsb::GetSupportedClasses(TInt aPersonalityId, RArray<TUid>& aClassUids)
   364 	{
   375 	{
   365 	OstTraceFunctionEntry0( RUSB_GETSUPPORTEDCLASSES_ENTRY );
   376 	LOG_LINE
       
   377 	LOG_FUNC
       
   378 
   366 	TInt ret = KErrNone;
   379 	TInt ret = KErrNone;
   367 	HBufC8* buf = NULL;
   380 	HBufC8* buf = NULL;
   368 	// +1 for the actual count of personality ids
   381 	// +1 for the actual count of personality ids
   369 	TRAP(ret, buf = HBufC8::NewL((KUsbMaxSupportedClasses + 1)*sizeof (TInt32)));
   382 	TRAP(ret, buf = HBufC8::NewL((KUsbMaxSupportedClasses + 1)*sizeof (TInt32)));
   370 	if (ret != KErrNone)
   383 	if (ret != KErrNone)
   371 		{
   384 		{
   372 		OstTraceFunctionExit0( RUSB_GETSUPPORTEDCLASSES_EXIT );
       
   373 		return ret;
   385 		return ret;
   374 		}
   386 		}
   375 
   387 
   376 	TPtr8 ptr8 = buf->Des();
   388 	TPtr8 ptr8 = buf->Des();
   377 	ret = SendReceive(EUsbGetSupportedClasses, TIpcArgs(aPersonalityId, &ptr8));
   389 	ret = SendReceive(EUsbGetSupportedClasses, TIpcArgs(aPersonalityId, &ptr8));
   380 		{
   392 		{
   381 		const TInt32* recvedIds = reinterpret_cast<const TInt32*>(buf->Ptr());
   393 		const TInt32* recvedIds = reinterpret_cast<const TInt32*>(buf->Ptr());
   382 		if (!recvedIds)
   394 		if (!recvedIds)
   383 			{
   395 			{
   384 			delete buf;
   396 			delete buf;
   385 			OstTraceFunctionExit0( RUSB_GETSUPPORTEDCLASSES_EXIT_DUP1 );
       
   386 			return KErrCorrupt;
   397 			return KErrCorrupt;
   387 			}
   398 			}
   388 			
   399 			
   389 		TInt arraySize = *recvedIds++;
   400 		TInt arraySize = *recvedIds++;
   390 		// Copy received supported class ids to aClassUids
   401 		// Copy received supported class ids to aClassUids
   419 				}
   430 				}
   420 			}
   431 			}
   421 		}
   432 		}
   422 		
   433 		
   423 	delete buf;
   434 	delete buf;
   424 	OstTraceFunctionExit0( RUSB_GETSUPPORTEDCLASSES_EXIT_DUP2 );
       
   425 	return ret;
   435 	return ret;
   426 	}
   436 	}
   427 	
   437 	
   428 EXPORT_C TInt RUsb::ClassSupported(TInt aPersonalityId, TUid aClassUid, TBool& aSupported)
   438 EXPORT_C TInt RUsb::ClassSupported(TInt aPersonalityId, TUid aClassUid, TBool& aSupported)
   429 	{
   439 	{
   430 	OstTraceFunctionEntry0( RUSB_CLASSSUPPORTED_ENTRY );
   440 	LOG_LINE
       
   441 	LOG_FUNC
   431 
   442 
   432 	TPckg<TInt32>  	pkg2(aSupported);
   443 	TPckg<TInt32>  	pkg2(aSupported);
   433 	TIpcArgs ipcArgs(aPersonalityId, aClassUid.iUid, &pkg2);
   444 	TIpcArgs ipcArgs(aPersonalityId, aClassUid.iUid, &pkg2);
   434 	
   445 	
   435 	TInt ret = SendReceive(EUsbClassSupported, ipcArgs);
   446 	TInt ret = SendReceive(EUsbClassSupported, ipcArgs);
   437 	if (ret == KErrNone)
   448 	if (ret == KErrNone)
   438 		{
   449 		{
   439 		aSupported = static_cast<TBool>(pkg2());		
   450 		aSupported = static_cast<TBool>(pkg2());		
   440 		}
   451 		}
   441 		
   452 		
   442 	OstTraceFunctionExit0( RUSB_CLASSSUPPORTED_EXIT );
       
   443 	return ret;
   453 	return ret;
   444 	}
   454 	}
   445 	
   455 	
   446 EXPORT_C TInt RUsb::GetPersonalityIds(RArray<TInt>& aPersonalityIds)
   456 EXPORT_C TInt RUsb::GetPersonalityIds(RArray<TInt>& aPersonalityIds)
   447 	{
   457 	{
   448 	OstTraceFunctionEntry0( RUSB_GETPERSONALITYIDS_ENTRY );
   458 	LOG_LINE
       
   459 	LOG_FUNC
       
   460 
   449 	TInt ret = KErrNone;
   461 	TInt ret = KErrNone;
   450 	HBufC8* buf = NULL;
   462 	HBufC8* buf = NULL;
   451 	// +1 for the actual count of personality ids
   463 	// +1 for the actual count of personality ids
   452 	TRAP(ret, buf = HBufC8::NewL((KUsbMaxSupportedPersonalities + 1)*sizeof (TInt)));
   464 	TRAP(ret, buf = HBufC8::NewL((KUsbMaxSupportedPersonalities + 1)*sizeof (TInt)));
   453 	if (ret != KErrNone)
   465 	if (ret != KErrNone)
   454 		{
   466 		{
   455 		OstTraceFunctionExit0( RUSB_GETPERSONALITYIDS_EXIT );
       
   456 		return ret;
   467 		return ret;
   457 		}
   468 		}
   458 
   469 
   459 	TPtr8 ptr8 = buf->Des();
   470 	TPtr8 ptr8 = buf->Des();
   460 	ret = SendReceive(EUsbGetPersonalityIds, TIpcArgs(&ptr8));
   471 	ret = SendReceive(EUsbGetPersonalityIds, TIpcArgs(&ptr8));
   463 		{
   474 		{
   464 		const TInt* recvedIds = reinterpret_cast<const TInt*>(buf->Ptr());
   475 		const TInt* recvedIds = reinterpret_cast<const TInt*>(buf->Ptr());
   465 		if (!recvedIds)
   476 		if (!recvedIds)
   466 			{
   477 			{
   467 			delete buf;
   478 			delete buf;
   468 			OstTraceFunctionExit0( RUSB_GETPERSONALITYIDS_EXIT_DUP1 );
       
   469 			return KErrCorrupt;
   479 			return KErrCorrupt;
   470 			}
   480 			}
   471 			
   481 			
   472 		TInt arraySize = *recvedIds++;
   482 		TInt arraySize = *recvedIds++;
   473 		// Copy received personality ids to aPersonalityIds
   483 		// Copy received personality ids to aPersonalityIds
   503 				}
   513 				}
   504 			}
   514 			}
   505 		}
   515 		}
   506 		
   516 		
   507 	delete buf;
   517 	delete buf;
   508 	OstTraceFunctionExit0( RUSB_GETPERSONALITYIDS_EXIT_DUP2 );
       
   509 	return ret;
   518 	return ret;
   510 	}
   519 	}
   511 	
   520 	
   512 EXPORT_C TInt RUsb::__DbgMarkHeap()
   521 EXPORT_C TInt RUsb::__DbgMarkHeap()
   513 	{
   522 	{
   556     return KErrNone;
   565     return KErrNone;
   557 #endif
   566 #endif
   558 	}
   567 	}
   559 
   568 
   560 EXPORT_C void panic()
   569 EXPORT_C void panic()
   561     { 
   570 	{
   562     OstTrace1( TRACE_FATAL, RUSB_PANIC, "::panic;Panic reason=%d", EUsbPanicRemovedExport );
   571 	_USB_PANIC(KUsbCliPncCat, EUsbPanicRemovedExport);
   563     User::Panic(KUsbCliPncCat, EUsbPanicRemovedExport);
       
   564 	}
   572 	}
   565 
   573 
   566 EXPORT_C TInt RUsb::SetCtlSessionMode(TBool aValue)
   574 EXPORT_C TInt RUsb::SetCtlSessionMode(TBool aValue)
   567 	{
   575 	{
   568 	OstTraceFunctionEntry0( RUSB_SETCTLSESSIONMODE_ENTRY );
   576 	LOG_LINE
       
   577 	LOG_FUNC
   569 
   578 
   570 	TPckg<TBool> pkg(aValue);
   579 	TPckg<TBool> pkg(aValue);
   571 	return SendReceive(EUsbSetCtlSessionMode, TIpcArgs(&pkg));
   580 	return SendReceive(EUsbSetCtlSessionMode, TIpcArgs(&pkg));
   572 	}
   581 	}
   573 
   582 
   574 EXPORT_C TInt RUsb::BusRequest()
   583 EXPORT_C TInt RUsb::BusRequest()
   575 	{
   584 	{
   576 	OstTraceFunctionEntry0( RUSB_BUSREQUEST_ENTRY );
   585 	LOG_LINE
       
   586 	LOG_FUNC
   577 
   587 
   578 	return SendReceive(EUsbBusRequest);
   588 	return SendReceive(EUsbBusRequest);
   579 	}
   589 	}
   580 
   590 
   581 EXPORT_C TInt RUsb::BusRespondSrp()
   591 EXPORT_C TInt RUsb::BusRespondSrp()
   582 	{
   592 	{
   583 	OstTraceFunctionEntry0( RUSB_BUSRESPONDSRP_ENTRY );
   593 	LOG_LINE
       
   594 	LOG_FUNC
   584 
   595 
   585 	return SendReceive(EUsbBusRespondSrp);
   596 	return SendReceive(EUsbBusRespondSrp);
   586 	}
   597 	}
   587 
   598 
   588 EXPORT_C TInt RUsb::BusClearError()
   599 EXPORT_C TInt RUsb::BusClearError()
   589 	{
   600 	{
   590 	OstTraceFunctionEntry0( RUSB_BUSCLEARERROR_ENTRY );
   601 	LOG_LINE
       
   602 	LOG_FUNC
       
   603 
   591 	return SendReceive(EUsbBusClearError);
   604 	return SendReceive(EUsbBusClearError);
   592 	}
   605 	}
   593 
   606 
   594 
   607 
   595 EXPORT_C TInt RUsb::BusDrop()
   608 EXPORT_C TInt RUsb::BusDrop()
   596 	{
   609 	{
   597 	OstTraceFunctionEntry0( RUSB_BUSDROP_ENTRY );
   610 	LOG_LINE
       
   611 	LOG_FUNC
       
   612 
   598 	return SendReceive(EUsbBusDrop);
   613 	return SendReceive(EUsbBusDrop);
   599 	}
   614 	}
   600 
   615 
   601 EXPORT_C void RUsb::MessageNotification(TRequestStatus& aStatus, TInt& aMessage)
   616 EXPORT_C void RUsb::MessageNotification(TRequestStatus& aStatus, TInt& aMessage)
   602 	{
   617 	{
   603 	OstTraceFunctionEntry0( RUSB_MESSAGENOTIFICATION_ENTRY );
   618 	LOG_LINE
       
   619 	LOG_FUNC
       
   620 
   604 	iMessagePkg.Set((TUint8*)&aMessage, sizeof(TInt), sizeof(TInt));
   621 	iMessagePkg.Set((TUint8*)&aMessage, sizeof(TInt), sizeof(TInt));
   605 
   622 
   606 	SendReceive(EUsbRegisterMessageObserver, TIpcArgs(&iMessagePkg), aStatus);
   623 	SendReceive(EUsbRegisterMessageObserver, TIpcArgs(&iMessagePkg), aStatus);
   607 	OstTraceFunctionExit0( RUSB_MESSAGENOTIFICATION_EXIT );
       
   608 	}
   624 	}
   609 
   625 
   610 EXPORT_C void RUsb::MessageNotificationCancel()
   626 EXPORT_C void RUsb::MessageNotificationCancel()
   611 	{
   627 	{
   612 	OstTraceFunctionEntry0( RUSB_MESSAGENOTIFICATIONCANCEL_ENTRY );
   628 	LOG_LINE
       
   629 	LOG_FUNC
       
   630 
   613 	SendReceive(EUsbCancelMessageObserver);
   631 	SendReceive(EUsbCancelMessageObserver);
   614 	OstTraceFunctionExit0( RUSB_MESSAGENOTIFICATIONCANCEL_EXIT );
       
   615 	}
   632 	}
   616 
   633 
   617 EXPORT_C void RUsb::HostEventNotification(TRequestStatus& aStatus,
   634 EXPORT_C void RUsb::HostEventNotification(TRequestStatus& aStatus,
   618 										  TDeviceEventInformation& aDeviceInformation)
   635 										  TDeviceEventInformation& aDeviceInformation)
   619 	{
   636 	{
   620 	OstTraceFunctionEntry0( RUSB_HOSTEVENTNOTIFICATION_ENTRY );
   637 	LOG_LINE
       
   638 	LOG_FUNC
   621 
   639 
   622 	iHostPkg.Set((TUint8*)&aDeviceInformation, sizeof(TDeviceEventInformation), sizeof(TDeviceEventInformation));
   640 	iHostPkg.Set((TUint8*)&aDeviceInformation, sizeof(TDeviceEventInformation), sizeof(TDeviceEventInformation));
   623 
   641 
   624 	SendReceive(EUsbRegisterHostObserver, TIpcArgs(&iHostPkg), aStatus);
   642 	SendReceive(EUsbRegisterHostObserver, TIpcArgs(&iHostPkg), aStatus);
   625 	OstTraceFunctionExit0( RUSB_HOSTEVENTNOTIFICATION_EXIT );
       
   626 	}
   643 	}
   627 	
   644 	
   628 EXPORT_C void RUsb::HostEventNotificationCancel()
   645 EXPORT_C void RUsb::HostEventNotificationCancel()
   629 	{
   646 	{
   630 	OstTraceFunctionEntry0( RUSB_HOSTEVENTNOTIFICATIONCANCEL_ENTRY );
   647 	LOG_LINE
       
   648 	LOG_FUNC
       
   649 
   631 	SendReceive(EUsbCancelHostObserver);
   650 	SendReceive(EUsbCancelHostObserver);
   632 	OstTraceFunctionExit0( RUSB_HOSTEVENTNOTIFICATIONCANCEL_EXIT );
       
   633 	}
   651 	}
   634 
   652 
   635 EXPORT_C TInt RUsb::EnableFunctionDriverLoading()
   653 EXPORT_C TInt RUsb::EnableFunctionDriverLoading()
   636 	{
   654 	{
   637 	OstTraceFunctionEntry0( RUSB_ENABLEFUNCTIONDRIVERLOADING_ENTRY );
   655 	LOG_LINE
       
   656 	LOG_FUNC
   638 
   657 
   639 	return SendReceive(EUsbEnableFunctionDriverLoading);
   658 	return SendReceive(EUsbEnableFunctionDriverLoading);
   640 	}
   659 	}
   641 
   660 
   642 EXPORT_C void RUsb::DisableFunctionDriverLoading()
   661 EXPORT_C void RUsb::DisableFunctionDriverLoading()
   643 	{
   662 	{
   644 	OstTraceFunctionEntry0( RUSB_DISABLEFUNCTIONDRIVERLOADING_ENTRY );
   663 	LOG_LINE
       
   664 	LOG_FUNC
       
   665 
   645 	SendReceive(EUsbDisableFunctionDriverLoading);
   666 	SendReceive(EUsbDisableFunctionDriverLoading);
   646 	OstTraceFunctionExit0( RUSB_DISABLEFUNCTIONDRIVERLOADING_EXIT );
       
   647 	}
   667 	}
   648 
   668 
   649 EXPORT_C TInt RUsb::GetSupportedLanguages(TUint aDeviceId, RArray<TUint>& aLangIds)
   669 EXPORT_C TInt RUsb::GetSupportedLanguages(TUint aDeviceId, RArray<TUint>& aLangIds)
   650 	{
   670 	{
   651 	OstTraceFunctionEntry0( RUSB_GETSUPPORTEDLANGUAGES_ENTRY );
   671 	LOG_LINE
       
   672 	LOG_FUNC
   652 
   673 
   653 	aLangIds.Reset();
   674 	aLangIds.Reset();
   654 
   675 
   655 	TInt ret = KErrNone;
   676 	TInt ret = KErrNone;
   656 	HBufC8* buf = NULL;
   677 	HBufC8* buf = NULL;
   657 	// +1 for the actual count of language ids
   678 	// +1 for the actual count of language ids
   658 	TRAP(ret, buf = HBufC8::NewL((KUsbMaxSupportedLanguageIds + 1)*sizeof (TUint)));
   679 	TRAP(ret, buf = HBufC8::NewL((KUsbMaxSupportedLanguageIds + 1)*sizeof (TUint)));
   659 	if (ret != KErrNone)
   680 	if (ret != KErrNone)
   660 		{
   681 		{
   661 		OstTraceFunctionExit0( RUSB_GETSUPPORTEDLANGUAGES_EXIT );
       
   662 		return ret;
   682 		return ret;
   663 		}
   683 		}
   664 
   684 
   665 	TPtr8 ptr8 = buf->Des();
   685 	TPtr8 ptr8 = buf->Des();
   666 	ret = SendReceive(EUsbGetSupportedLanguages, TIpcArgs(aDeviceId, &ptr8));
   686 	ret = SendReceive(EUsbGetSupportedLanguages, TIpcArgs(aDeviceId, &ptr8));
   669 		{
   689 		{
   670 		const TUint* recvedIds = reinterpret_cast<const TUint*>(buf->Ptr());
   690 		const TUint* recvedIds = reinterpret_cast<const TUint*>(buf->Ptr());
   671 		if (!recvedIds)
   691 		if (!recvedIds)
   672 			{
   692 			{
   673 			delete buf;
   693 			delete buf;
   674 			OstTraceFunctionExit0( RUSB_GETSUPPORTEDLANGUAGES_EXIT_DUP1 );
       
   675 			return KErrCorrupt;
   694 			return KErrCorrupt;
   676 			}
   695 			}
   677 			
   696 			
   678 		TInt arraySize = *recvedIds++;
   697 		TInt arraySize = *recvedIds++;
   679 		// Copy received language ids to aLangIds
   698 		// Copy received language ids to aLangIds
   687 				}
   706 				}
   688 			}
   707 			}
   689 		}
   708 		}
   690 		
   709 		
   691 	delete buf;	
   710 	delete buf;	
   692 	OstTraceFunctionExit0( RUSB_GETSUPPORTEDLANGUAGES_EXIT_DUP2 );
       
   693 	return ret;
   711 	return ret;
   694 	}
   712 	}
   695 	
   713 	
   696 EXPORT_C TInt RUsb::GetManufacturerStringDescriptor(TUint aDeviceId, TUint aLangId, TName& aString)
   714 EXPORT_C TInt RUsb::GetManufacturerStringDescriptor(TUint aDeviceId, TUint aLangId, TName& aString)
   697 	{
   715 	{
   698 	OstTraceFunctionEntry0( RUSB_GETMANUFACTURERSTRINGDESCRIPTOR_ENTRY );
   716 	LOG_LINE
       
   717 	LOG_FUNC
   699 
   718 
   700 	return SendReceive(EUsbGetManufacturerStringDescriptor, TIpcArgs(aDeviceId, aLangId, &aString));
   719 	return SendReceive(EUsbGetManufacturerStringDescriptor, TIpcArgs(aDeviceId, aLangId, &aString));
   701 	}
   720 	}
   702 
   721 
   703 EXPORT_C TInt RUsb::GetProductStringDescriptor(TUint aDeviceId, TUint aLangId, TName& aString)
   722 EXPORT_C TInt RUsb::GetProductStringDescriptor(TUint aDeviceId, TUint aLangId, TName& aString)
   704 	{
   723 	{
   705 	OstTraceFunctionEntry0( RUSB_GETPRODUCTSTRINGDESCRIPTOR_ENTRY );
   724 	LOG_LINE
       
   725 	LOG_FUNC
       
   726 
   706 	return SendReceive(EUsbGetProductStringDescriptor, TIpcArgs(aDeviceId, aLangId, &aString));
   727 	return SendReceive(EUsbGetProductStringDescriptor, TIpcArgs(aDeviceId, aLangId, &aString));
   707 	}
   728 	}
   708 
   729 
   709 EXPORT_C TInt RUsb::GetOtgDescriptor(TUint aDeviceId, TOtgDescriptor& aDescriptor)
   730 EXPORT_C TInt RUsb::GetOtgDescriptor(TUint aDeviceId, TOtgDescriptor& aDescriptor)
   710 	{
   731 	{
   711 	OstTraceFunctionEntry0( RUSB_GETOTGDESCRIPTOR_ENTRY );
   732 	LOG_LINE
       
   733 	LOG_FUNC
       
   734 		
   712 	TPckg<TOtgDescriptor> otgDescPkg(aDescriptor);
   735 	TPckg<TOtgDescriptor> otgDescPkg(aDescriptor);
   713 	
   736 	
   714 	TIpcArgs args;
   737 	TIpcArgs args;
   715 	args.Set(0, aDeviceId);
   738 	args.Set(0, aDeviceId);
   716 	args.Set(1, &otgDescPkg);
   739 	args.Set(1, &otgDescPkg);
   719 	}
   742 	}
   720 
   743 
   721 
   744 
   722 EXPORT_C TInt RUsb::RequestSession()
   745 EXPORT_C TInt RUsb::RequestSession()
   723 	{
   746 	{
   724 	OstTraceFunctionEntry0( RUSB_REQUESTSESSION_ENTRY );
   747 	LOG_LINE
       
   748 	LOG_FUNC
   725 
   749 
   726 	return SendReceive(EUsbRequestSession);
   750 	return SendReceive(EUsbRequestSession);
   727 	}
   751 	}
   728 
   752 
   729 EXPORT_C TInt RUsb::GetDetailedDescription(TInt /*aPersonalityId*/, HBufC*& /*aLocalizedPersonalityDescriptor*/)
   753 EXPORT_C TInt RUsb::GetDetailedDescription(TInt aPersonalityId, HBufC*& aLocalizedPersonalityDescriptor)
   730 	{
   754 	{
   731 	OstTraceFunctionEntry0( RUSB_GETDETAILEDDESCRIPTION_ENTRY );
   755 	LOG_LINE
   732 	//This API has been deprecated
   756 	LOG_FUNC
   733 	OstTraceFunctionExit0( RUSB_GETDETAILEDDESCRIPTION_EXIT );
   757 
   734 	return KErrNotSupported; 
   758  	TInt ret = KErrNone;
       
   759 	// caller is responsible for freeing up memory allocated for aLocalizedPersonalityDescriptor
       
   760 	TRAP(ret, aLocalizedPersonalityDescriptor = HBufC::NewL(KUsbStringDescStringMaxSize));
       
   761 	if (ret == KErrNone)
       
   762 		{
       
   763 		TPtr ptr = aLocalizedPersonalityDescriptor->Des();
       
   764 		TIpcArgs ipcArgs(0, &ptr);
       
   765 		ipcArgs.Set(0, aPersonalityId);
       
   766 		ret = SendReceive(EUsbGetDetailedDescription, ipcArgs);
       
   767 		}
       
   768 	else
       
   769 		{
       
   770 		// just in case caller tries to free the memory before checking the return code
       
   771 		aLocalizedPersonalityDescriptor = NULL;
       
   772 		}
       
   773 
       
   774 	return ret; 
   735 	}
   775 	}
   736 
   776 
   737 EXPORT_C TInt RUsb::GetPersonalityProperty(TInt aPersonalityId, TUint32& aProperty)
   777 EXPORT_C TInt RUsb::GetPersonalityProperty(TInt aPersonalityId, TUint32& aProperty)
   738 	{
   778 	{
   739 	OstTraceFunctionEntry0( RUSB_GETPERSONALITYPROPERTY_ENTRY );
   779 	LOG_LINE
       
   780 	LOG_FUNC
   740 
   781 
   741 	TPckg<TUint32> pkg(aProperty);
   782 	TPckg<TUint32> pkg(aProperty);
   742 	TInt ret = SendReceive(EUsbGetPersonalityProperty, TIpcArgs(aPersonalityId, &pkg));
   783 	TInt ret = SendReceive(EUsbGetPersonalityProperty, TIpcArgs(aPersonalityId, &pkg));
   743 	if (ret == KErrNone)
   784 	if (ret == KErrNone)
   744 		{
   785 		{
   745 		aProperty = static_cast<TUint32>(pkg());
   786 		aProperty = static_cast<TUint32>(pkg());
   746 		}
   787 		}
   747 	OstTraceFunctionExit0( RUSB_GETPERSONALITYPROPERTY_EXIT );
       
   748 	return ret;	
   788 	return ret;	
   749 	}
   789 	}
   750 
   790