kernel/eka/drivers/usbcc/ps_usbc.cpp
changeset 253 d37db4dcc88d
parent 90 947f0dc9f7a8
child 269 d57b86b1867a
equal deleted inserted replaced
252:0a40b8675b23 253:d37db4dcc88d
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    21  @file ps_usbc.cpp
    21  @file ps_usbc.cpp
    22  @internalTechnology
    22  @internalTechnology
    23 */
    23 */
    24 
    24 
    25 #include <drivers/usbc.h>
    25 #include <drivers/usbc.h>
       
    26 #include "OstTraceDefinitions.h"
       
    27 #ifdef OST_TRACE_COMPILER_IN_USE
       
    28 #include "ps_usbcTraces.h"
       
    29 #endif
       
    30 
    26 
    31 
    27 
    32 
    28 /**
    33 /**
    29 	TUsbcInterfaceSet and TUsbcInterface
    34 	TUsbcInterfaceSet and TUsbcInterface
    30 	====================================
    35 	====================================
   116 
   121 
   117 	It's not exported because it is virtual.
   122 	It's not exported because it is virtual.
   118 */
   123 */
   119 DUsbClientController::~DUsbClientController()
   124 DUsbClientController::~DUsbClientController()
   120 	{
   125 	{
   121 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::~DUsbClientController()"));
   126 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DUSBCLIENTCONTROLLER_DES, "DUsbClientController::~DUsbClientController()" );
       
   127 	
   122 	if (iPowerHandler)
   128 	if (iPowerHandler)
   123 		{
   129 		{
   124 		iPowerHandler->Remove();
   130 		iPowerHandler->Remove();
   125 		delete iPowerHandler;
   131 		delete iPowerHandler;
   126 		}
   132 		}
   127 	// ResetAndDestroy() will call for every array element the destructor of the pointed-to object,
   133 	// ResetAndDestroy() will call for every array element the destructor of the pointed-to object,
   128 	// before deleting the element itself, and closing the array.
   134 	// before deleting the element itself, and closing the array.
   129 	iConfigs.ResetAndDestroy();
   135 	iConfigs.ResetAndDestroy();
   130 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::~DUsbClientController(): Done."));
   136 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DUSBCLIENTCONTROLLER_DES_DUP1, "DUsbClientController::~DUsbClientController(): Done." );
   131 	}
   137 	}
   132 
   138 
   133 
   139 
   134 /** To be called by the OTG/Host stack in an OTG setup to disable USB device
   140 /** To be called by the OTG/Host stack in an OTG setup to disable USB device
   135 	functionality.
   141 	functionality.
   145 	applications on the user-side (including the USB Manager) about a USB
   151 	applications on the user-side (including the USB Manager) about a USB
   146 	device state change event, a transition to the "Undefined" state.
   152 	device state change event, a transition to the "Undefined" state.
   147 */
   153 */
   148 EXPORT_C void DUsbClientController::DisableClientStack()
   154 EXPORT_C void DUsbClientController::DisableClientStack()
   149 	{
   155 	{
   150 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DisableClientStack()"));
   156 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DISABLECLIENTSTACK, "DUsbClientController::DisableClientStack()" );
   151 	if (!iStackIsActive)
   157 	if (!iStackIsActive)
   152 		{
   158 		{
   153 		__KTRACE_OPT(KUSB, Kern::Printf("  Already disabled - returning"));
   159 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DISABLECLIENTSTACK_DUP1, "  Already disabled - returning" );
   154 		return;
   160 		return;
   155 		}
   161 		}
   156 	iOtgClientConnect = EFalse;
   162 	iOtgClientConnect = EFalse;
   157 	TInt r = EvaluateOtgConnectFlags();					 // will disconnect UDC
   163 	TInt r = EvaluateOtgConnectFlags();					 // will disconnect UDC
   158 	if (r != KErrNone)
   164 	if (r != KErrNone)
   159 		{
   165 		{
   160 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: EvaluateOtgConnectFlags() failed: %d", r));
   166 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DISABLECLIENTSTACK_DUP2, "  Error: EvaluateOtgConnectFlags() failed: %d", r );
   161 		}
   167 		}
   162 
   168 
   163 	// Reset OTG features, leave attributes as is (just as in USB Reset case)
   169 	// Reset OTG features, leave attributes as is (just as in USB Reset case)
   164 	// (OTG spec 1.3 sections 6.5.x all say "... on a bus reset or at the end
   170 	// (OTG spec 1.3 sections 6.5.x all say "... on a bus reset or at the end
   165 	//  of a session." VBus drop is the end of a session.)
   171 	//  of a session." VBus drop is the end of a session.)
   203 	is calling this function during the transition to the A_PERIPHERAL state,
   209 	is calling this function during the transition to the A_PERIPHERAL state,
   204 	i.e. when acting as an A-device.
   210 	i.e. when acting as an A-device.
   205 */
   211 */
   206 EXPORT_C void DUsbClientController::EnableClientStack()
   212 EXPORT_C void DUsbClientController::EnableClientStack()
   207 	{
   213 	{
   208 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EnableClientStack()"));
   214 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK, "DUsbClientController::EnableClientStack()" );
   209 	if (iStackIsActive)
   215 	if (iStackIsActive)
   210 		{
   216 		{
   211 		__KTRACE_OPT(KUSB, Kern::Printf("  Already enabled - returning"));
   217 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK_DUP1, "  Already enabled - returning" );
   212 		return;
   218 		return;
   213 		}
   219 		}
   214 	iStackIsActive = ETrue;
   220 	iStackIsActive = ETrue;
   215 	// If the UDC is still off, we switch it on here.
   221 	// If the UDC is still off, we switch it on here.
   216 	TInt r = ActivateHardwareController();
   222 	TInt r = ActivateHardwareController();
   217 	if (r != KErrNone)
   223 	if (r != KErrNone)
   218 		{
   224 		{
   219 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: ActivateHardwareController() failed: %d", r));
   225 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK_DUP2, "  Error: ActivateHardwareController() failed: %d", r);
   220 		}
   226 		}
   221 	iOtgClientConnect = ETrue;
   227 	iOtgClientConnect = ETrue;
   222 	r = EvaluateOtgConnectFlags();							// may connect UDC
   228 	r = EvaluateOtgConnectFlags();							// may connect UDC
   223 	if (r != KErrNone)
   229 	if (r != KErrNone)
   224 		{
   230 		{
   225 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: EvaluateOtgConnectFlags() failed: %d", r));
   231 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENABLECLIENTSTACK_DUP3, "  Error: EvaluateOtgConnectFlags() failed: %d", r);
   226 		}
   232 		}
   227 	}
   233 	}
   228 
   234 
   229 
   235 
   230 /** Called by LDD to see if controller is usable.
   236 /** Called by LDD to see if controller is usable.
   231 
   237 
   232 	@return ETrue if controller is in normal state, EFalse if it is disabled.
   238 	@return ETrue if controller is in normal state, EFalse if it is disabled.
   233 */
   239 */
   234 EXPORT_C TBool DUsbClientController::IsActive()
   240 EXPORT_C TBool DUsbClientController::IsActive()
   235 	{
   241 	{
   236 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::IsActive()"));
   242 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ISACTIVE, "DUsbClientController::IsActive()" );
   237 	return iStackIsActive;
   243 	return iStackIsActive;
   238 	}
   244 	}
   239 
   245 
   240 
   246 
   241 /** Called by LDD to register client callbacks.
   247 /** Called by LDD to register client callbacks.
   242 
   248 
   243 	@return KErrNone if successful, KErrAlreadyExists callback exists.
   249 	@return KErrNone if successful, KErrAlreadyExists callback exists.
   244 */
   250 */
   245 EXPORT_C TInt DUsbClientController::RegisterClientCallback(TUsbcClientCallback& aCallback)
   251 EXPORT_C TInt DUsbClientController::RegisterClientCallback(TUsbcClientCallback& aCallback)
   246 	{
   252 	{
   247 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RegisterClientCallback()"));
   253 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERCLIENTCALLBACK, "DUsbClientController::RegisterClientCallback()" );
   248 	if (iClientCallbacks.Elements() == KUsbcMaxListLength)
   254 	if (iClientCallbacks.Elements() == KUsbcMaxListLength)
   249 		{
   255 		{
   250 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Maximum list length reached: %d",
   256 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERCLIENTCALLBACK_DUP1, "  Error: Maximum list length reached: %d",
   251 										  KUsbcMaxListLength));
   257                                           KUsbcMaxListLength);
       
   258 
   252 		return KErrGeneral;
   259 		return KErrGeneral;
   253 		}
   260 		}
   254 	TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks);
   261 	TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks);
   255 	TUsbcClientCallback* p;
   262 	TUsbcClientCallback* p;
   256 	while ((p = iter++) != NULL)
   263 	while ((p = iter++) != NULL)
   257 		if (p == &aCallback)
   264 		if (p == &aCallback)
   258 			{
   265 			{
   259 			__KTRACE_OPT(KUSB, Kern::Printf("	 Error: ClientCallback @ 0x%x already registered", &aCallback));
   266 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REGISTERCLIENTCALLBACK_DUP2, "    Error: ClientCallback @ 0x%x already registered", &aCallback);
   260 			return KErrAlreadyExists;
   267 			return KErrAlreadyExists;
   261 			}
   268 			}
   262 	iClientCallbacks.AddLast(aCallback);
   269 	iClientCallbacks.AddLast(aCallback);
   263 	return KErrNone;
   270 	return KErrNone;
   264 	}
   271 	}
   272 
   279 
   273 	@return A pointer to the USB client controller object.
   280 	@return A pointer to the USB client controller object.
   274 */
   281 */
   275 EXPORT_C DUsbClientController* DUsbClientController::UsbcControllerPointer(TInt aUdc)
   282 EXPORT_C DUsbClientController* DUsbClientController::UsbcControllerPointer(TInt aUdc)
   276 	{
   283 	{
   277 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::UsbcControllerPointer()"));
   284 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_USBCCONTROLLERPOINTER, "DUsbClientController::UsbcControllerPointer()" );
   278 	if (aUdc < 0 || aUdc > 1)
   285 	if (aUdc < 0 || aUdc > 1)
   279 		{
   286 		{
   280 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: aUdc out of range (%d)", aUdc));
   287 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_USBCCONTROLLERPOINTER_DUP1, "  Error: aUdc out of range (%d)", aUdc);
   281 		return NULL;
   288 		return NULL;
   282 		}
   289 		}
   283 	return UsbClientController[aUdc];
   290 	return UsbClientController[aUdc];
   284 	}
   291 	}
   285 
   292 
   295 	TUsbcEndpointData elements; there are TUsbDeviceCaps::iTotalEndpoints elements in the array;
   302 	TUsbcEndpointData elements; there are TUsbDeviceCaps::iTotalEndpoints elements in the array;
   296 	call DeviceCaps() to get the number of elements required.
   303 	call DeviceCaps() to get the number of elements required.
   297 */
   304 */
   298 EXPORT_C void DUsbClientController::EndpointCaps(const DBase* aClientId, TDes8& aCapsBuf) const
   305 EXPORT_C void DUsbClientController::EndpointCaps(const DBase* aClientId, TDes8& aCapsBuf) const
   299 	{
   306 	{
   300 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EndpointCaps()"));
   307 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENDPOINTCAPS, "DUsbClientController::EndpointCaps()" );
   301 	// Here we do not simply call DUsbClientController::DeviceEndpointCaps(),
   308 	// Here we do not simply call DUsbClientController::DeviceEndpointCaps(),
   302 	// because that function fills an array which comprises of _all_ endpoints,
   309 	// because that function fills an array which comprises of _all_ endpoints,
   303 	// whereas this function omits ep0 and all unusable endpoints.
   310 	// whereas this function omits ep0 and all unusable endpoints.
   304 	// Apart from that, we have to fill an array of TUsbcEndpointData, not TUsbcEndpointCaps.
   311 	// Apart from that, we have to fill an array of TUsbcEndpointData, not TUsbcEndpointCaps.
   305 	TUsbcEndpointData data[KUsbcMaxEndpoints];
   312 	TUsbcEndpointData data[KUsbcMaxEndpoints];
   306 	const TInt ifcset_num = ClientId2InterfaceNumber(aClientId);
   313 	const TInt ifcset_num = ClientId2InterfaceNumber(aClientId);
   307 	for (TInt i = 2, j = 0; i < iDeviceTotalEndpoints; ++i)
   314 	for (TInt i = 2, j = 0; i < iDeviceTotalEndpoints; ++i)
   308 		{
   315 		{
   309 		__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::Caps: RealEndpoint #%d", i));
   316 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTCAPS_DUP1, "DUsbClientController::Caps: RealEndpoint #%d", i);
   310 		if (iRealEndpoints[i].iCaps.iTypesAndDir != KUsbEpNotAvailable)
   317 		if (iRealEndpoints[i].iCaps.iTypesAndDir != KUsbEpNotAvailable)
   311 			{
   318 			{
   312 			__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::Caps: --> UsableEndpoint #%d", j));
   319 		    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTCAPS_DUP2, "DUsbClientController::Caps: --> UsableEndpoint #%d", j);
   313 			data[j].iCaps = iRealEndpoints[i].iCaps;
   320 			data[j].iCaps = iRealEndpoints[i].iCaps;
   314 			if (ifcset_num < 0)
   321 			if (ifcset_num < 0)
   315 				{
   322 				{
   316 				// If this LDD doesn't own an interface, but the Ep points to one,
   323 				// If this LDD doesn't own an interface, but the Ep points to one,
   317 				// then that must be the interface of a different LDD. Hence the Ep
   324 				// then that must be the interface of a different LDD. Hence the Ep
   352 	@param aCapsBuf A reference to a descriptor buffer which, on return, contains
   359 	@param aCapsBuf A reference to a descriptor buffer which, on return, contains
   353 	a TUsbDeviceCaps structure.
   360 	a TUsbDeviceCaps structure.
   354 */
   361 */
   355 EXPORT_C void DUsbClientController::DeviceCaps(const DBase* aClientId, TDes8& aCapsBuf) const
   362 EXPORT_C void DUsbClientController::DeviceCaps(const DBase* aClientId, TDes8& aCapsBuf) const
   356 	{
   363 	{
   357 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeviceCaps()"));
   364 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICECAPS, "DUsbClientController::DeviceCaps()" );
   358 	TUsbDeviceCaps caps;
   365 	TUsbDeviceCaps caps;
   359 	caps().iTotalEndpoints = iDeviceUsableEndpoints;		// not DeviceTotalEndpoints()!
   366 	caps().iTotalEndpoints = iDeviceUsableEndpoints;		// not DeviceTotalEndpoints()!
   360 	caps().iConnect = SoftConnectCaps();
   367 	caps().iConnect = SoftConnectCaps();
   361 	caps().iSelfPowered = iSelfPowered;
   368 	caps().iSelfPowered = iSelfPowered;
   362 	caps().iRemoteWakeup = iRemoteWakeup;
   369 	caps().iRemoteWakeup = iRemoteWakeup;
   433 												 TInt aInterfaceNum, TUsbcClassInfo& aClass,
   440 												 TInt aInterfaceNum, TUsbcClassInfo& aClass,
   434 												 TDesC8* aString, TInt aTotalEndpointsUsed,
   441 												 TDesC8* aString, TInt aTotalEndpointsUsed,
   435 												 const TUsbcEndpointInfoArray aEndpointData,
   442 												 const TUsbcEndpointInfoArray aEndpointData,
   436 												 TInt aRealEpNumbers[], TUint32 aFeatureWord)
   443 												 TInt aRealEpNumbers[], TUint32 aFeatureWord)
   437 	{
   444 	{
   438 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetInterface()"));
   445 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETINTERFACE, "DUsbClientController::SetInterface()" );
   439 	if (aInterfaceNum != 0)
   446 	if (aInterfaceNum != 0)
   440 		{
   447 		{
   441 		__KTRACE_OPT(KUSB, Kern::Printf("  alternate interface setting request: #%d", aInterfaceNum));
   448 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP1, "  alternate interface setting request: #%d", aInterfaceNum);
       
   449 
   442 		}
   450 		}
   443 #ifndef USB_SUPPORTS_CONTROLENDPOINTS
   451 #ifndef USB_SUPPORTS_CONTROLENDPOINTS
   444 	for (TInt i = 0; i < aTotalEndpointsUsed; ++i)
   452 	for (TInt i = 0; i < aTotalEndpointsUsed; ++i)
   445 		{
   453 		{
   446 		if (aEndpointData[i].iType == KUsbEpTypeControl)
   454 		if (aEndpointData[i].iType == KUsbEpTypeControl)
   447 			{
   455 			{
   448 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: control endpoints not supported"));
   456 		    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP2, "  Error: control endpoints not supported");
   449 			return KErrNotSupported;
   457 			return KErrNotSupported;
   450 			}
   458 			}
   451 		}
   459 		}
   452 #endif
   460 #endif
   453 	// Check for endpoint availability & check those endpoint's capabilities
   461 	// Check for endpoint availability & check those endpoint's capabilities
   454 	const TInt ifcset_num = ClientId2InterfaceNumber(aClientId);
   462 	const TInt ifcset_num = ClientId2InterfaceNumber(aClientId);
   455 	// The passed-in ifcset_num may be -1 now, but that's intended.
   463 	// The passed-in ifcset_num may be -1 now, but that's intended.
   456 	if (!CheckEpAvailability(aTotalEndpointsUsed, aEndpointData, ifcset_num))
   464 	if (!CheckEpAvailability(aTotalEndpointsUsed, aEndpointData, ifcset_num))
   457 		{
   465 		{
   458 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: endpoints not (all) available"));
   466 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP3, "  Error: endpoints not (all) available");
   459 		return KErrInUse;
   467 		return KErrInUse;
   460 		}
   468 		}
   461 	// Create & setup new interface
   469 	// Create & setup new interface
   462 	TUsbcInterface* ifc = CreateInterface(aClientId, aInterfaceNum, aFeatureWord);
   470 	TUsbcInterface* ifc = CreateInterface(aClientId, aInterfaceNum, aFeatureWord);
   463 	if (ifc == NULL)
   471 	if (ifc == NULL)
   464 		{
   472 		{
   465 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: ifc == NULL"));
   473 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP4, "  Error: ifc == NULL");
   466 		return KErrGeneral;
   474 		return KErrGeneral;
   467 		}
   475 		}
   468 	// Create logical endpoints
   476 	// Create logical endpoints
   469 	TInt r = CreateEndpoints(ifc, aTotalEndpointsUsed, aEndpointData, aRealEpNumbers);
   477 	TInt r = CreateEndpoints(ifc, aTotalEndpointsUsed, aEndpointData, aRealEpNumbers);
   470 	if (r != KErrNone)
   478 	if (r != KErrNone)
   471 		{
   479 		{
   472 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: CreateEndpoints() != KErrNone"));
   480 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACE_DUP5, "  Error: CreateEndpoints() != KErrNone");
   473 		DeleteInterface(ifc->iInterfaceSet->iInterfaceNumber, aInterfaceNum);
   481 		DeleteInterface(ifc->iInterfaceSet->iInterfaceNumber, aInterfaceNum);
   474 		return r;
   482 		return r;
   475 		}
   483 		}
   476 	// Create & setup interface, string, and endpoint descriptors
   484 	// Create & setup interface, string, and endpoint descriptors
   477 	r = SetupIfcDescriptor(ifc, aClass, aThread, aString, aEndpointData);
   485 	r = SetupIfcDescriptor(ifc, aClass, aThread, aString, aEndpointData);
   494 	invalid interface setting number is specified (not existing or existing but too small), KErrNone if
   502 	invalid interface setting number is specified (not existing or existing but too small), KErrNone if
   495 	interface successfully released or if this client doesn't own any interface.
   503 	interface successfully released or if this client doesn't own any interface.
   496 */
   504 */
   497 EXPORT_C TInt DUsbClientController::ReleaseInterface(const DBase* aClientId, TInt aInterfaceNum)
   505 EXPORT_C TInt DUsbClientController::ReleaseInterface(const DBase* aClientId, TInt aInterfaceNum)
   498 	{
   506 	{
   499 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ReleaseInterface(..., %d)", aInterfaceNum));
   507 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE, "DUsbClientController::ReleaseInterface(..., %d)", aInterfaceNum);
       
   508 	
   500 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
   509 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
   501 	if (ifcset < 0)
   510 	if (ifcset < 0)
   502 		{
   511 		{
   503 		__KTRACE_OPT(KUSB, Kern::Printf(" interface not found")); // no error
   512 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP1, " interface not found");
   504 		return KErrNone;
   513 		return KErrNone;
   505 		}
   514 		}
   506 	TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset);
   515 	TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset);
   507 	if (!ifcset_ptr)
   516 	if (!ifcset_ptr)
   508 		{
   517 		{
   509 		__KTRACE_OPT(KUSB, Kern::Printf(" Error: interface number %d doesn't exist", ifcset));
   518 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP2, "Error: interface number %d doesn't exist", ifcset);
   510 		return KErrNotFound;
   519 		return KErrNotFound;
   511 		}
   520 		}
   512 	const TInt setting_count = ifcset_ptr->iInterfaces.Count();
   521 	const TInt setting_count = ifcset_ptr->iInterfaces.Count();
   513 	if ((setting_count - 1) != aInterfaceNum)
   522 	if ((setting_count - 1) != aInterfaceNum)
   514 		{
   523 		{
   515 		__KTRACE_OPT(KUSB,
   524 	    OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP3, "> Error: interface settings must be released in descending order:\n\r"
   516 					 Kern::Printf(" > Error: interface settings must be released in descending order:\n\r"
   525                                   "   %d setting(s) exist, #%d was requested to be released.\n\r"
   517 								  "   %d setting(s) exist, #%d was requested to be released.\n\r"
   526                                   "   (#%d has to be released first)",
   518 								  "   (#%d has to be released first)",
   527                                   setting_count, aInterfaceNum, setting_count - 1);
   519 								  setting_count, aInterfaceNum, setting_count - 1));
       
   520 		return KErrArgument;
   528 		return KErrArgument;
   521 		}
   529 		}
   522 	// Tear down current setting (invalidate configured state)
   530 	// Tear down current setting (invalidate configured state)
   523 	__KTRACE_OPT(KUSB, Kern::Printf(" > tearing down InterfaceSet %d", ifcset));
   531 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP4, " > tearing down InterfaceSet %d", ifcset);
   524 	// Cancel all transfers on the current setting of this interface and deconfigure all its endpoints.
   532 	// Cancel all transfers on the current setting of this interface and deconfigure all its endpoints.
   525 	InterfaceSetTeardown(ifcset_ptr);
   533 	InterfaceSetTeardown(ifcset_ptr);
   526 	// 'Setting 0' means: delete all existing settings.
   534 	// 'Setting 0' means: delete all existing settings.
   527 	if (aInterfaceNum == 0)
   535 	if (aInterfaceNum == 0)
   528 		{
   536 		{
   569 		NextDeviceState(EUsbcDeviceStateAddress);
   577 		NextDeviceState(EUsbcDeviceStateAddress);
   570 		}
   578 		}
   571 	// If it was the last interface(set)...
   579 	// If it was the last interface(set)...
   572 	if (iConfigs[0]->iInterfaceSets.Count() == 0)
   580 	if (iConfigs[0]->iInterfaceSets.Count() == 0)
   573 		{
   581 		{
   574 		__KTRACE_OPT(KUSB, Kern::Printf("  No ifc left -> turning off UDC"));
   582 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEINTERFACE_DUP5, "  No ifc left -> turning off UDC");
   575 		// First disconnect the device from the bus
   583 		// First disconnect the device from the bus
   576 		UsbDisconnect();
   584 		UsbDisconnect();
   577 		DeActivateHardwareController();
   585 		DeActivateHardwareController();
   578 		// (this also disables endpoint zero; we cannot have a USB device w/o interface, see 9.6.3)
   586 		// (this also disables endpoint zero; we cannot have a USB device w/o interface, see 9.6.3)
   579 		}
   587 		}
   586 
   594 
   587 	This only works if the PSL supports it, i.e. if SoftConnectCaps() returns ETrue.
   595 	This only works if the PSL supports it, i.e. if SoftConnectCaps() returns ETrue.
   588 */
   596 */
   589 EXPORT_C TInt DUsbClientController::ReEnumerate()
   597 EXPORT_C TInt DUsbClientController::ReEnumerate()
   590 	{
   598 	{
   591 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ReEnumerate()"));
   599 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REENUMERATE, "DUsbClientController::ReEnumerate()" );
   592 	// If, in an OTG setup, the client stack is disabled, there's no point in
   600 	// If, in an OTG setup, the client stack is disabled, there's no point in
   593 	// trying to reenumerate the device. In fact, we then don't even want to
   601 	// trying to reenumerate the device. In fact, we then don't even want to
   594 	// turn on the UDC via ActivateHardwareController().
   602 	// turn on the UDC via ActivateHardwareController().
   595 	if (!iStackIsActive)
   603 	if (!iStackIsActive)
   596 		{
   604 		{
   597 		__KTRACE_OPT(KUSB, Kern::Printf("  Client stack disabled -> returning here"));
   605 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REENUMERATE_DUP1, " Client stack disabled -> returning here" );
   598 		return KErrNotReady;
   606 		return KErrNotReady;
   599 		}
   607 		}
   600 	// We probably don't check here whether SoftConnectCaps() is ETrue, and
   608 	// We probably don't check here whether SoftConnectCaps() is ETrue, and
   601 	// return if not, because we might still want to execute
   609 	// return if not, because we might still want to execute
   602 	// ActivateHardwareController(). UsbConnect() and UsbDisconnect() should be
   610 	// ActivateHardwareController(). UsbConnect() and UsbDisconnect() should be
   603 	// no-ops if not supported by the PSL.
   611 	// no-ops if not supported by the PSL.
   604 	if (iConfigs[0]->iInterfaceSets.Count() == 0)
   612 	if (iConfigs[0]->iInterfaceSets.Count() == 0)
   605 		{
   613 		{
   606 		__KTRACE_OPT(KUSB, Kern::Printf("  > No interface registered -> no need to re-enumerate"));
   614 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REENUMERATE_DUP2, "  > No interface registered -> no need to re-enumerate" );
   607 		return KErrNone;;
   615 		return KErrNone;;
   608 		}
   616 		}
   609 	if (!iHardwareActivated)
   617 	if (!iHardwareActivated)
   610 		{
   618 		{
   611 		// If the UDC is still off, we switch it on here.
   619 		// If the UDC is still off, we switch it on here.
   612 		const TInt r = ActivateHardwareController();
   620 		const TInt r = ActivateHardwareController();
   613 		if (r != KErrNone)
   621 		if (r != KErrNone)
   614 				{
   622 				{
   615 				__KTRACE_OPT(KPANIC, Kern::Printf("  Error: ActivateHardwareController() failed: %d", r));
   623 		        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REENUMERATE_DUP3, "  Error: ActivateHardwareController() failed: %d", r);
   616 				return r;
   624 				return r;
   617 				}
   625 				}
   618 		// Finally connect the device to the bus
   626 		// Finally connect the device to the bus
   619 		UsbConnect();
   627 		UsbConnect();
   620 		}
   628 		}
   636 	interfaces have been registered yet, KErrHardwareNotAvailable if UDC
   644 	interfaces have been registered yet, KErrHardwareNotAvailable if UDC
   637 	couldn't be activated.
   645 	couldn't be activated.
   638 */
   646 */
   639 EXPORT_C TInt DUsbClientController::PowerUpUdc()
   647 EXPORT_C TInt DUsbClientController::PowerUpUdc()
   640 	{
   648 	{
   641 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerUpUdc()"));
   649 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERUPUDC, "DUsbClientController::PowerUpUdc()" );
   642 	// If, in an OTG setup, the client stack is disabled, we mustn't turn on
   650 	// If, in an OTG setup, the client stack is disabled, we mustn't turn on
   643 	// the UDC via ActivateHardwareController() as that would already configure
   651 	// the UDC via ActivateHardwareController() as that would already configure
   644 	// Ep0.
   652 	// Ep0.
   645 	if (!iStackIsActive)
   653 	if (!iStackIsActive)
   646 		{
   654 		{
   647 		__KTRACE_OPT(KUSB, Kern::Printf("  Client stack disabled -> returning here"));
   655 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERUPUDC_DUP1, "  Client stack disabled -> returning here" );
   648 		return KErrNotReady;
   656 		return KErrNotReady;
   649 		}
   657 		}
   650 	if (iConfigs[0]->iInterfaceSets.Count() == 0)
   658 	if (iConfigs[0]->iInterfaceSets.Count() == 0)
   651 		{
   659 		{
   652 		__KTRACE_OPT(KUSB, Kern::Printf("  > No interface registered -> won't power up UDC"));
   660 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERUPUDC_DUP2, "   > No interface registered -> won't power up UDC" );
   653 		return KErrNotReady;
   661 		return KErrNotReady;
   654 		}
   662 		}
   655 	// If the UDC is still off, we switch it on here.
   663 	// If the UDC is still off, we switch it on here.
   656 	const TInt r = ActivateHardwareController();
   664 	const TInt r = ActivateHardwareController();
   657 	if (r != KErrNone)
   665 	if (r != KErrNone)
   658 		{
   666 		{
   659 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: ActivateHardwareController() failed: %d", r));
   667 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_POWERUPUDC_DUP3, "  Error: ActivateHardwareController() failed: %d", r);
   660 		}
   668 		}
   661 	return r;
   669 	return r;
   662 	}
   670 	}
   663 
   671 
   664 
   672 
   668 
   676 
   669 	@return KErrNone if UDC successfully connected, KErrGeneral if there was an error.
   677 	@return KErrNone if UDC successfully connected, KErrGeneral if there was an error.
   670 */
   678 */
   671 EXPORT_C TInt DUsbClientController::UsbConnect()
   679 EXPORT_C TInt DUsbClientController::UsbConnect()
   672 	{
   680 	{
   673 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::UsbConnect()"));
   681     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_USBCONNECT, "DUsbClientController::UsbConnect()" );
   674 #ifdef USB_OTG_CLIENT
   682 #ifdef USB_OTG_CLIENT
   675 	iClientSupportReady = ETrue;
   683 	iClientSupportReady = ETrue;
   676 	const TInt r = EvaluateOtgConnectFlags();
   684 	const TInt r = EvaluateOtgConnectFlags();
   677     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
   685     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
   678 	if (iUsbResetDeferred) // implies (iOtgHnpHandledByHw == ETrue)
   686 	if (iUsbResetDeferred) // implies (iOtgHnpHandledByHw == ETrue)
   679 		{
   687 		{
   680 		__KTRACE_OPT(KUSB, Kern::Printf("  Resetting USB Reset 'defer' flag"));
   688 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_USBCONNECT_DUP1, "  Resetting USB Reset 'defer' flag" );
   681 		iUsbResetDeferred = EFalse;
   689 		iUsbResetDeferred = EFalse;
   682 		(void) ProcessResetEvent(EFalse);
   690 		(void) ProcessResetEvent(EFalse);
   683 		}
   691 		}
   684     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   692     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   685 #else
   693 #else
   695 
   703 
   696 	@return KErrNone if UDC successfully disconnected, KErrGeneral if there was an error.
   704 	@return KErrNone if UDC successfully disconnected, KErrGeneral if there was an error.
   697 */
   705 */
   698 EXPORT_C TInt DUsbClientController::UsbDisconnect()
   706 EXPORT_C TInt DUsbClientController::UsbDisconnect()
   699 	{
   707 	{
   700 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::UsbDisconnect()"));
   708     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_USBDISCONNECT, "DUsbClientController::UsbDisconnect()" );   
   701 #ifdef USB_OTG_CLIENT
   709 #ifdef USB_OTG_CLIENT
   702 	iClientSupportReady = EFalse;
   710 	iClientSupportReady = EFalse;
   703 	const TInt r = EvaluateOtgConnectFlags();
   711 	const TInt r = EvaluateOtgConnectFlags();
   704 #else
   712 #else
   705 	const TInt r = UdcDisconnect();
   713 	const TInt r = UdcDisconnect();
   731 	@return KErrNone if callback successfully registered, KErrGeneral if this callback is already registered
   739 	@return KErrNone if callback successfully registered, KErrGeneral if this callback is already registered
   732 	(it won't be registered twice).
   740 	(it won't be registered twice).
   733 */
   741 */
   734 EXPORT_C TInt DUsbClientController::RegisterForStatusChange(TUsbcStatusCallback& aCallback)
   742 EXPORT_C TInt DUsbClientController::RegisterForStatusChange(TUsbcStatusCallback& aCallback)
   735 	{
   743 	{
   736 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RegisterForStatusChange()"));
   744 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERFORSTATUSCHANGE, "DUsbClientController::RegisterForStatusChange()" );
   737 	if (iStatusCallbacks.Elements() == KUsbcMaxListLength)
   745 	if (iStatusCallbacks.Elements() == KUsbcMaxListLength)
   738 		{
   746 		{
   739 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Maximum list length reached: %d",
   747 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERFORSTATUSCHANGE_DUP1, "  Error: Maximum list length reached: %d",
   740 										  KUsbcMaxListLength));
   748                                           KUsbcMaxListLength);
   741 		return KErrGeneral;
   749 		return KErrGeneral;
   742 		}
   750 		}
   743 	if (IsInTheStatusList(aCallback))
   751 	if (IsInTheStatusList(aCallback))
   744 		{
   752 		{
   745 		__KTRACE_OPT(KUSB, Kern::Printf("  Error: StatusCallback @ 0x%x already registered", &aCallback));
   753 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REGISTERFORSTATUSCHANGE_DUP2, "  Error: StatusCallback @ 0x%x already registered", &aCallback);
   746 		return KErrGeneral;
   754 		return KErrGeneral;
   747 		}
   755 		}
   748     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
   756     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
   749 	iStatusCallbacks.AddLast(aCallback);
   757 	iStatusCallbacks.AddLast(aCallback);
   750     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   758     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   759 
   767 
   760 	@return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found.
   768 	@return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found.
   761 */
   769 */
   762 EXPORT_C TInt DUsbClientController::DeRegisterForStatusChange(const DBase* aClientId)
   770 EXPORT_C TInt DUsbClientController::DeRegisterForStatusChange(const DBase* aClientId)
   763 	{
   771 	{
   764 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeRegisterForStatusChange()"));
   772 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERFORSTATUSCHANGE, "DUsbClientController::DeRegisterForStatusChange()" );
   765 	__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__));
   773 	__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__));
   766     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
   774     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
   767 	TSglQueIter<TUsbcStatusCallback> iter(iStatusCallbacks);
   775 	TSglQueIter<TUsbcStatusCallback> iter(iStatusCallbacks);
   768 	TUsbcStatusCallback* p;
   776 	TUsbcStatusCallback* p;
   769 	while ((p = iter++) != NULL)
   777 	while ((p = iter++) != NULL)
   770 		{
   778 		{
   771 		if (p->Owner() == aClientId)
   779 		if (p->Owner() == aClientId)
   772 			{
   780 			{
   773 			__KTRACE_OPT(KUSB, Kern::Printf("  removing StatusCallback @ 0x%x", p));
   781 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORSTATUSCHANGE_DUP1, "  removing StatusCallback @ 0x%x", p);
   774 			iStatusCallbacks.Remove(*p);
   782 			iStatusCallbacks.Remove(*p);
   775 		    __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   783 		    __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   776 			return KErrNone;
   784 			return KErrNone;
   777 			}
   785 			}
   778 		}
   786 		}
   779 	__KTRACE_OPT(KUSB, Kern::Printf("  client not found"));
   787     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORSTATUSCHANGE_DUP2, "  client not found");
   780     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   788     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   781 	return KErrNotFound;
   789 	return KErrNotFound;
   782 	}
   790 	}
   783 
   791 
   784 
   792 
   797 	@return KErrNone if callback successfully registered, KErrGeneral if this callback is already registered
   805 	@return KErrNone if callback successfully registered, KErrGeneral if this callback is already registered
   798 	(it won't be registered twice).
   806 	(it won't be registered twice).
   799 */
   807 */
   800 EXPORT_C TInt DUsbClientController::RegisterForEndpointStatusChange(TUsbcEndpointStatusCallback& aCallback)
   808 EXPORT_C TInt DUsbClientController::RegisterForEndpointStatusChange(TUsbcEndpointStatusCallback& aCallback)
   801 	{
   809 	{
   802 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RegisterForEndpointStatusChange()"));
   810 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERFORENDPOINTSTATUSCHANGE, "DUsbClientController::RegisterForEndpointStatusChange()" );
   803 	if (iEpStatusCallbacks.Elements() == KUsbcMaxListLength)
   811 	if (iEpStatusCallbacks.Elements() == KUsbcMaxListLength)
   804 		{
   812 		{
   805 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Maximum list length reached: %d",
   813 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERFORENDPOINTSTATUSCHANGE_DUP1, "  Error: Maximum list length reached: %d",
   806 										  KUsbcMaxListLength));
   814                                           KUsbcMaxListLength);
       
   815 
   807 		return KErrGeneral;
   816 		return KErrGeneral;
   808 		}
   817 		}
   809 	if (IsInTheEpStatusList(aCallback))
   818 	if (IsInTheEpStatusList(aCallback))
   810 		{
   819 		{
   811 		__KTRACE_OPT(KUSB, Kern::Printf("  Error: EpStatusCallback @ 0x%x already registered", &aCallback));
   820 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REGISTERFORENDPOINTSTATUSCHANGE_DUP2, "  Error: EpStatusCallback @ 0x%x already registered", &aCallback);
   812 		return KErrGeneral;
   821 		return KErrGeneral;
   813 		}
   822 		}
   814     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
   823     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
   815 	iEpStatusCallbacks.AddLast(aCallback);
   824 	iEpStatusCallbacks.AddLast(aCallback);
   816     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   825     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   825 
   834 
   826 	@return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found.
   835 	@return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found.
   827 */
   836 */
   828 EXPORT_C TInt DUsbClientController::DeRegisterForEndpointStatusChange(const DBase* aClientId)
   837 EXPORT_C TInt DUsbClientController::DeRegisterForEndpointStatusChange(const DBase* aClientId)
   829 	{
   838 	{
   830 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeRegisterForEndpointStatusChange()"));
   839 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERFORENDPOINTSTATUSCHANGE, "DUsbClientController::DeRegisterForEndpointStatusChange()" );
   831 	__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__));
   840 	__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__));
   832     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
   841     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
   833 	TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks);
   842 	TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks);
   834 	TUsbcEndpointStatusCallback* p;
   843 	TUsbcEndpointStatusCallback* p;
   835 	while ((p = iter++) != NULL)
   844 	while ((p = iter++) != NULL)
   836 		{
   845 		{
   837 		if (p->Owner() == aClientId)
   846 		if (p->Owner() == aClientId)
   838 			{
   847 			{
   839 			__KTRACE_OPT(KUSB, Kern::Printf("  removing EpStatusCallback @ 0x%x", p));
   848 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORENDPOINTSTATUSCHANGE_DUP1, "  removing EpStatusCallback @ 0x%x", p);
   840 			iEpStatusCallbacks.Remove(*p);
   849 			iEpStatusCallbacks.Remove(*p);
   841 		    __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   850 		    __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   842 			return KErrNone;
   851 			return KErrNone;
   843 			}
   852 			}
   844 		}
   853 		}
   845 	__KTRACE_OPT(KUSB, Kern::Printf("  client not found"));
   854     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFORENDPOINTSTATUSCHANGE_DUP2, "  client not found");
   846     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   855     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
   847 	return KErrNotFound;
   856 	return KErrNotFound;
   848 	}
   857 	}
   849 
   858 
   850 
   859 
   856 	@return KErrNotFound if an interface for this client couldn't be found, KErrNone if setting value was
   865 	@return KErrNotFound if an interface for this client couldn't be found, KErrNone if setting value was
   857 	successfully written.
   866 	successfully written.
   858 */
   867 */
   859 EXPORT_C TInt DUsbClientController::GetInterfaceNumber(const DBase* aClientId, TInt& aInterfaceNum) const
   868 EXPORT_C TInt DUsbClientController::GetInterfaceNumber(const DBase* aClientId, TInt& aInterfaceNum) const
   860 	{
   869 	{
   861 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetInterfaceNumber()"));
   870 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETINTERFACENUMBER, "DUsbClientController::GetInterfaceNumber()" );
       
   871 	
   862 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
   872 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
   863 	if (ifcset < 0)
   873 	if (ifcset < 0)
   864 		{
   874 		{
   865 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error (ifc < 0)"));
   875 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETINTERFACENUMBER_DUP1, "  Error (ifc < 0)");
   866 		return KErrNotFound;
   876 		return KErrNotFound;
   867 		}
   877 		}
   868 	const TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset);
   878 	const TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset);
   869 	if (!ifcset_ptr)
   879 	if (!ifcset_ptr)
   870 		{
   880 		{
   871 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: interface number %d doesn't exist", ifcset));
   881 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETINTERFACENUMBER_DUP2, "  Error: interface number %d doesn't exist", ifcset);
   872 		return KErrNotFound;
   882 		return KErrNotFound;
   873 		}
   883 		}
   874 	aInterfaceNum = ifcset_ptr->iCurrentInterface;
   884 	aInterfaceNum = ifcset_ptr->iCurrentInterface;
   875 	return KErrNone;
   885 	return KErrNone;
   876 	}
   886 	}
   891 
   901 
   892 	@return KErrNone.
   902 	@return KErrNone.
   893 */
   903 */
   894 EXPORT_C TInt DUsbClientController::DeRegisterClient(const DBase* aClientId)
   904 EXPORT_C TInt DUsbClientController::DeRegisterClient(const DBase* aClientId)
   895 	{
   905 	{
   896 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeRegisterClient(0x%x)", aClientId));
   906 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERCLIENT, "DUsbClientController::DeRegisterClient(0x%x)", aClientId);
       
   907 	
   897 	// Cancel all device state notification requests
   908 	// Cancel all device state notification requests
   898 	DeRegisterForStatusChange(aClientId);
   909 	DeRegisterForStatusChange(aClientId);
   899 	// Cancel all endpoint state notification requests
   910 	// Cancel all endpoint state notification requests
   900 	DeRegisterForEndpointStatusChange(aClientId);
   911 	DeRegisterForEndpointStatusChange(aClientId);
   901 	DeRegisterForOtgFeatureChange(aClientId);
   912 	DeRegisterForOtgFeatureChange(aClientId);
   903 	// Delete the interface including all its alternate settings which might exist.
   914 	// Delete the interface including all its alternate settings which might exist.
   904 	// (If we release the default setting (0), all alternate settings are deleted as well.)
   915 	// (If we release the default setting (0), all alternate settings are deleted as well.)
   905 	const TInt r = ReleaseInterface(aClientId, 0);
   916 	const TInt r = ReleaseInterface(aClientId, 0);
   906 	// Cancel all remaining (if any) read/write requests
   917 	// Cancel all remaining (if any) read/write requests
   907 	DeleteRequestCallbacks(aClientId);
   918 	DeleteRequestCallbacks(aClientId);
   908 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeRegisterClient: Done."));
   919 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERCLIENT_DUP1, "DUsbClientController::DeRegisterClient: Done.");
   909 	return r;
   920 	return r;
   910 	}
   921 	}
   911 
   922 
   912 
   923 
   913 /** Returns the currently used Ep0 max packet size.
   924 /** Returns the currently used Ep0 max packet size.
   917 EXPORT_C TInt DUsbClientController::Ep0PacketSize() const
   928 EXPORT_C TInt DUsbClientController::Ep0PacketSize() const
   918 	{
   929 	{
   919 	const TUsbcLogicalEndpoint* const ep = iRealEndpoints[0].iLEndpoint;
   930 	const TUsbcLogicalEndpoint* const ep = iRealEndpoints[0].iLEndpoint;
   920 	if (iHighSpeed)
   931 	if (iHighSpeed)
   921 		{
   932 		{
   922 		__KTRACE_OPT(KUSB, Kern::Printf("  Ep0 size = %d (HS)", ep->iEpSize_Hs));
   933 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0PACKETSIZE, "  Ep0 size = %d (HS)", ep->iEpSize_Hs);
       
   934 		
   923 		return ep->iEpSize_Hs;
   935 		return ep->iEpSize_Hs;
   924 		}
   936 		}
   925 	else
   937 	else
   926 		{
   938 		{
   927 		__KTRACE_OPT(KUSB, Kern::Printf("  Ep0 size = %d (FS)", ep->iEpSize_Fs));
   939 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0PACKETSIZE_DUP1, "  Ep0 size = %d (FS)", ep->iEpSize_Fs);
   928 		return ep->iEpSize_Fs;
   940 		return ep->iEpSize_Fs;
   929 		}
   941 		}
   930 	}
   942 	}
   931 
   943 
   932 
   944 
   936 
   948 
   937 	@return KErrNone if endpoint zero successfully stalled, KErrGeneral otherwise.
   949 	@return KErrNone if endpoint zero successfully stalled, KErrGeneral otherwise.
   938 */
   950 */
   939 EXPORT_C TInt DUsbClientController::Ep0Stall(const DBase* aClientId)
   951 EXPORT_C TInt DUsbClientController::Ep0Stall(const DBase* aClientId)
   940 	{
   952 	{
   941 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::Ep0Stall()"));
   953 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_EP0STALL, "DUsbClientController::Ep0Stall()" );
   942 	if (aClientId == iEp0ClientId)
   954 	if (aClientId == iEp0ClientId)
   943 		{
   955 		{
   944 		ResetEp0DataOutVars();
   956 		ResetEp0DataOutVars();
   945 		}
   957 		}
   946 	const TInt err = StallEndpoint(KEp0_Out);
   958 	const TInt err = StallEndpoint(KEp0_Out);
   957 
   969 
   958 	@param aClientId A pointer to the LDD wishing to send the status packet (not used at present).
   970 	@param aClientId A pointer to the LDD wishing to send the status packet (not used at present).
   959 */
   971 */
   960 EXPORT_C void DUsbClientController::SendEp0StatusPacket(const DBase* /* aClientId */)
   972 EXPORT_C void DUsbClientController::SendEp0StatusPacket(const DBase* /* aClientId */)
   961 	{
   973 	{
   962 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SendEp0StatusPacket()"));
   974 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SENDEP0STATUSPACKET, "DUsbClientController::SendEp0StatusPacket()" );
   963 	SendEp0ZeroByteStatusPacket();
   975 	SendEp0ZeroByteStatusPacket();
   964 	}
   976 	}
   965 
   977 
   966 
   978 
   967 /** Returns the current USB device state.
   979 /** Returns the current USB device state.
   972 	@return The current USB device state, or EUsbcDeviceStateUndefined if the UDC doesn't allow device state
   984 	@return The current USB device state, or EUsbcDeviceStateUndefined if the UDC doesn't allow device state
   973 	tracking (PSL's DeviceStateChangeCaps() returns EFalse).
   985 	tracking (PSL's DeviceStateChangeCaps() returns EFalse).
   974 */
   986 */
   975 EXPORT_C TUsbcDeviceState DUsbClientController::GetDeviceStatus() const
   987 EXPORT_C TUsbcDeviceState DUsbClientController::GetDeviceStatus() const
   976 	{
   988 	{
   977 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetDeviceStatus()"));
   989 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETDEVICESTATUS, "DUsbClientController::GetDeviceStatus()" );
   978 	return iDeviceState;
   990 	return iDeviceState;
   979 	}
   991 	}
   980 
   992 
   981 
   993 
   982 /** Returns the state of an endpoint.
   994 /** Returns the state of an endpoint.
   989 
  1001 
   990 	@return The current endpoint state, or EEndpointStateUnknown if the endpoint couldn't be found.
  1002 	@return The current endpoint state, or EEndpointStateUnknown if the endpoint couldn't be found.
   991 */
  1003 */
   992 EXPORT_C TEndpointState DUsbClientController::GetEndpointStatus(const DBase* aClientId, TInt aEndpointNum) const
  1004 EXPORT_C TEndpointState DUsbClientController::GetEndpointStatus(const DBase* aClientId, TInt aEndpointNum) const
   993 	{
  1005 	{
   994 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetEndpointStatus()"));
  1006 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETENDPOINTSTATUS, "DUsbClientController::GetEndpointStatus()" );
   995 	return EndpointStallStatus(aEndpointNum) ?
  1007 	return EndpointStallStatus(aEndpointNum) ?
   996 		EEndpointStateStalled :
  1008 		EEndpointStateStalled :
   997 		EEndpointStateNotStalled;
  1009 		EEndpointStateNotStalled;
   998 	}
  1010 	}
   999 
  1011 
  1006 	(but it won't be registered twice), KErrNotFound if the endpoint couldn't be found, KErrArgument if
  1018 	(but it won't be registered twice), KErrNotFound if the endpoint couldn't be found, KErrArgument if
  1007 	endpoint number invalid (PSL), KErrGeneral if something else goes wrong.
  1019 	endpoint number invalid (PSL), KErrGeneral if something else goes wrong.
  1008 */
  1020 */
  1009 EXPORT_C TInt DUsbClientController::SetupReadBuffer(TUsbcRequestCallback& aCallback)
  1021 EXPORT_C TInt DUsbClientController::SetupReadBuffer(TUsbcRequestCallback& aCallback)
  1010 	{
  1022 	{
  1011 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetupReadBuffer()"));
  1023 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETUPREADBUFFER, "DUsbClientController::SetupReadBuffer()" );
  1012 	const TInt ep = aCallback.iRealEpNum;
  1024 	const TInt ep = aCallback.iRealEpNum;
  1013 	__KTRACE_OPT(KUSB, Kern::Printf("  logical ep: #%d", aCallback.iEndpointNum));
  1025 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP1, "  logical ep: #%d", aCallback.iEndpointNum);
  1014 	__KTRACE_OPT(KUSB, Kern::Printf("  real ep:    #%d", ep));
  1026 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP2, "  real ep:    #%d", ep);
  1015 	TInt err = KErrGeneral;
  1027 	TInt err = KErrGeneral;
  1016 	if (ep != 0)
  1028 	if (ep != 0)
  1017 		{
  1029 		{
  1018 		if (iRequestCallbacks[ep])
  1030 		if (iRequestCallbacks[ep])
  1019 			{
  1031 			{
  1020 			__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: RequestCallback already registered for that ep"));
  1032 			OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP3, "  Warning: RequestCallback already registered for that ep");
  1021 			if (iRequestCallbacks[ep] == &aCallback)
  1033 			if (iRequestCallbacks[ep] == &aCallback)
  1022 				{
  1034 				{
  1023 				__KTRACE_OPT(KPANIC, Kern::Printf("  (this same RequestCallback @ 0x%x)", &aCallback));
  1035 	            OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP4, "  (this same RequestCallback @ 0x%x)", &aCallback);
  1024 				}
  1036 				}
  1025 			else
  1037 			else
  1026 				{
  1038 				{
  1027 				__KTRACE_OPT(KPANIC, Kern::Printf("  (a different RequestCallback @ 0x%x)", &aCallback));
  1039                 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP5, "  (a different RequestCallback @ 0x%x)", &aCallback);
  1028 				}
  1040 				}
  1029 			return KErrNone;
  1041 			return KErrNone;
  1030 			}
  1042 			}
  1031 		// This may seem awkward:
  1043 		// This may seem awkward:
  1032 		// First we add a callback, and then, in case of an error, we remove it again.
  1044 		// First we add a callback, and then, in case of an error, we remove it again.
  1033 		// However this is necessary because the transfer request might complete (through
  1045 		// However this is necessary because the transfer request might complete (through
  1034 		// an ISR) _before_ the SetupEndpointRead function returns. Since we don't know the
  1046 		// an ISR) _before_ the SetupEndpointRead function returns. Since we don't know the
  1035 		// outcome, we have to provide the callback before making the setup call.
  1047 		// outcome, we have to provide the callback before making the setup call.
  1036 		//
  1048 		//
  1037 		__KTRACE_OPT(KUSB, Kern::Printf("  adding RequestCallback[%d] @ 0x%x", ep, &aCallback));
  1049         OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP6, "  adding RequestCallback[%d] @ 0x%x", ep, (TUint)&aCallback);
  1038 		iRequestCallbacks[ep] = &aCallback;
  1050 		iRequestCallbacks[ep] = &aCallback;
  1039 		if ((err = SetupEndpointRead(ep, aCallback)) != KErrNone)
  1051 		if ((err = SetupEndpointRead(ep, aCallback)) != KErrNone)
  1040 			{
  1052 			{
  1041 			__KTRACE_OPT(KPANIC, Kern::Printf("  removing RequestCallback @ 0x%x (due to error)",
  1053 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP7, "  removing RequestCallback @ 0x%x (due to error)",
  1042 											  &aCallback));
  1054                                               &aCallback);
  1043 			iRequestCallbacks[ep] = NULL;
  1055 			iRequestCallbacks[ep] = NULL;
  1044 			}
  1056 			}
  1045 		}
  1057 		}
  1046 	else													// (ep == 0)
  1058 	else													// (ep == 0)
  1047 		{
  1059 		{
  1048 		if (iEp0ReadRequestCallbacks.Elements() == KUsbcMaxListLength)
  1060 		if (iEp0ReadRequestCallbacks.Elements() == KUsbcMaxListLength)
  1049 			{
  1061 			{
  1050 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Maximum list length reached: %d",
  1062 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP8, "  Error: Maximum list length reached: %d",
  1051 											  KUsbcMaxListLength));
  1063                                               KUsbcMaxListLength);
  1052 			return KErrGeneral;
  1064 			return KErrGeneral;
  1053 			}
  1065 			}
  1054 		if (IsInTheRequestList(aCallback))
  1066 		if (IsInTheRequestList(aCallback))
  1055 			{
  1067 			{
  1056 			__KTRACE_OPT(KUSB, Kern::Printf("  RequestCallback @ 0x%x already registered", &aCallback));
  1068 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP9, "   RequestCallback @ 0x%x already registered", &aCallback);
  1057 			return KErrNone;
  1069 			return KErrNone;
  1058 			}
  1070 			}
  1059 		// Ep0 reads don't need to be prepared - there's always one pending
  1071 		// Ep0 reads don't need to be prepared - there's always one pending
  1060 		__KTRACE_OPT(KUSB, Kern::Printf("  adding RequestCallback @ 0x%x (ep0)", &aCallback));
  1072         OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP10, "  adding RequestCallback @ 0x%x (ep0)", &aCallback);
  1061 	    const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  1073 	    const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  1062 		iEp0ReadRequestCallbacks.AddLast(aCallback);
  1074 		iEp0ReadRequestCallbacks.AddLast(aCallback);
  1063         __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  1075         __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  1064 		err = KErrNone;
  1076 		err = KErrNone;
  1065 		if (iEp0_RxExtraData)
  1077 		if (iEp0_RxExtraData)
  1066 			{
  1078 			{
  1067 			__KTRACE_OPT(KUSB, Kern::Printf("  iEp0_RxExtraData: trying again..."));
  1079 	        OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP11, "  iEp0_RxExtraData: trying again...");
  1068 			const TBool rx_data = iEp0DataReceiving;
  1080 			const TBool rx_data = iEp0DataReceiving;
  1069 		    const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  1081 		    const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  1070 			err = ProcessEp0ReceiveDone(iEp0_RxExtraCount);
  1082 			err = ProcessEp0ReceiveDone(iEp0_RxExtraCount);
  1071 	        __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  1083 	        __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  1072 			if (err == KErrNone)
  1084 			if (err == KErrNone)
  1080 					}
  1092 					}
  1081 				else
  1093 				else
  1082 					{
  1094 					{
  1083 					Ep0ReadSetupPktProceed();
  1095 					Ep0ReadSetupPktProceed();
  1084 					}
  1096 					}
  1085 				__KTRACE_OPT(KUSB, Kern::Printf("  :-)"));
  1097 	            OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP12, "  :-)");
  1086 				}
  1098 				}
  1087 			else
  1099 			else
  1088 				{
  1100 				{
  1089 				__KTRACE_OPT(KPANIC, Kern::Printf("  Error: :-("));
  1101                 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPREADBUFFER_DUP13, "  Error: :-(");
  1090 				err = KErrGeneral;
  1102 				err = KErrGeneral;
  1091 				}
  1103 				}
  1092 			return err;
  1104 			return err;
  1093 			}
  1105 			}
  1094 		}
  1106 		}
  1104 	(but it won't be registered twice), KErrNotFound if the endpoint couldn't be found, KErrArgument if
  1116 	(but it won't be registered twice), KErrNotFound if the endpoint couldn't be found, KErrArgument if
  1105 	endpoint number invalid (PSL), KErrGeneral if something else goes wrong.
  1117 	endpoint number invalid (PSL), KErrGeneral if something else goes wrong.
  1106 */
  1118 */
  1107 EXPORT_C TInt DUsbClientController::SetupWriteBuffer(TUsbcRequestCallback& aCallback)
  1119 EXPORT_C TInt DUsbClientController::SetupWriteBuffer(TUsbcRequestCallback& aCallback)
  1108 	{
  1120 	{
  1109 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetupWriteBuffer()"));
  1121 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER, "DUsbClientController::SetupWriteBuffer()" );
  1110 	TInt ep = aCallback.iRealEpNum;
  1122 	TInt ep = aCallback.iRealEpNum;
  1111 	__KTRACE_OPT(KUSB, Kern::Printf("  logical ep: #%d", aCallback.iEndpointNum));
  1123 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP1, "  logical ep: #%d", aCallback.iEndpointNum);
  1112 	__KTRACE_OPT(KUSB, Kern::Printf("  real ep:	   #%d", ep));
  1124 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP2, "  real ep:    #%d", ep);
       
  1125 
  1113 	if (iRequestCallbacks[ep])
  1126 	if (iRequestCallbacks[ep])
  1114 		{
  1127 		{
  1115 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: RequestCallback already registered for that ep"));
  1128 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP3, "  Warning: RequestCallback already registered for that ep");
  1116 		if (iRequestCallbacks[ep] == &aCallback)
  1129 		if (iRequestCallbacks[ep] == &aCallback)
  1117 			{
  1130 			{
  1118 			__KTRACE_OPT(KPANIC, Kern::Printf("  (this same RequestCallback @ 0x%x)", &aCallback));
  1131 		    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP4, "  (this same RequestCallback @ 0x%x)", &aCallback);
  1119 			return KErrNone;
  1132 			return KErrNone;
  1120 			}
  1133 			}
  1121 		else
  1134 		else
  1122 			{
  1135 			{
  1123 			__KTRACE_OPT(KPANIC, Kern::Printf("  (a different RequestCallback @ 0x%x - poss. error)",
  1136 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP5, "  (a different RequestCallback @ 0x%x - poss. error)",
  1124 											  &aCallback));
  1137                                               &aCallback);
  1125 			return KErrGeneral;
  1138 			return KErrGeneral;
  1126 			}
  1139 			}
  1127 		}
  1140 		}
  1128 	if (ep == 0)
  1141 	if (ep == 0)
  1129 		{
  1142 		{
  1130 		if (iEp0_TxNonStdCount)
  1143 		if (iEp0_TxNonStdCount)
  1131 			{
  1144 			{
  1132 			if (iEp0_TxNonStdCount > aCallback.iLength)
  1145 			if (iEp0_TxNonStdCount > aCallback.iLength)
  1133 				{
  1146 				{
  1134 				__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Ep0 is sending less data than requested"));
  1147 				OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP6, "  Warning: Ep0 is sending less data than requested");
  1135 				if ((aCallback.iLength % iEp0MaxPacketSize == 0) && !aCallback.iZlpReqd)
  1148 				if ((aCallback.iLength % iEp0MaxPacketSize == 0) && !aCallback.iZlpReqd)
  1136 					{
  1149 					{
  1137 					__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Zlp should probably be requested"));
  1150 		            OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP7, "  Warning: Zlp should probably be requested");
  1138 					}
  1151 					}
  1139 				}
  1152 				}
  1140 			else if (iEp0_TxNonStdCount < aCallback.iLength)
  1153 			else if (iEp0_TxNonStdCount < aCallback.iLength)
  1141 				{
  1154 				{
  1142 				__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Ep0 is sending more data than requested"));
  1155                 OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP8, "  Warning: Ep0 is sending more data than requested");
  1143 				}
  1156 				}
  1144 			iEp0_TxNonStdCount = 0;
  1157 			iEp0_TxNonStdCount = 0;
  1145 			}
  1158 			}
  1146 		// Ep0 IN needs to be adjusted: the LDD uses 0 for both Ep0 directions.
  1159 		// Ep0 IN needs to be adjusted: the LDD uses 0 for both Ep0 directions.
  1147 		ep = KEp0_Tx;
  1160 		ep = KEp0_Tx;
  1149 	// This may seem awkward:
  1162 	// This may seem awkward:
  1150 	// First we add a callback, and then, in case of an error, we remove it again.
  1163 	// First we add a callback, and then, in case of an error, we remove it again.
  1151 	// However this is necessary because the transfer request might complete (through
  1164 	// However this is necessary because the transfer request might complete (through
  1152 	// an ISR) _before_ the SetupEndpointWrite function returns. Since we don't know the
  1165 	// an ISR) _before_ the SetupEndpointWrite function returns. Since we don't know the
  1153 	// outcome, we have to provide the callback before making the setup call.
  1166 	// outcome, we have to provide the callback before making the setup call.
  1154 	//
  1167     OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP9, "  adding RequestCallback[%d] @ 0x%x", ep, (TUint)&aCallback);
  1155 	__KTRACE_OPT(KUSB, Kern::Printf("  adding RequestCallback[%d] @ 0x%x", ep, &aCallback));
       
  1156 	iRequestCallbacks[ep] = &aCallback;
  1168 	iRequestCallbacks[ep] = &aCallback;
  1157 	if (ep == KEp0_Tx)
  1169 	if (ep == KEp0_Tx)
  1158 		{
  1170 		{
  1159 		iEp0ClientDataTransmitting = ETrue;			 // this must be set before calling SetupEndpointZeroWrite
  1171 		iEp0ClientDataTransmitting = ETrue;			 // this must be set before calling SetupEndpointZeroWrite
  1160 		if (SetupEndpointZeroWrite(aCallback.iBufferStart, aCallback.iLength, aCallback.iZlpReqd) != KErrNone)
  1172 		if (SetupEndpointZeroWrite(aCallback.iBufferStart, aCallback.iLength, aCallback.iZlpReqd) != KErrNone)
  1161 			{
  1173 			{
  1162 			__KTRACE_OPT(KPANIC, Kern::Printf("  removing RequestCallback @ 0x%x (due to error)", &aCallback));
  1174 		    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP10, "  removing RequestCallback @ 0x%x (due to error)", &aCallback);
  1163 			iRequestCallbacks[ep] = NULL;
  1175 			iRequestCallbacks[ep] = NULL;
  1164 			iEp0ClientDataTransmitting = EFalse;
  1176 			iEp0ClientDataTransmitting = EFalse;
  1165 			}
  1177 			}
  1166 		}
  1178 		}
  1167 	else if (SetupEndpointWrite(ep, aCallback) != KErrNone)
  1179 	else if (SetupEndpointWrite(ep, aCallback) != KErrNone)
  1168 		{
  1180 		{
  1169 		__KTRACE_OPT(KPANIC, Kern::Printf("  removing RequestCallback @ 0x%x (due to error)", &aCallback));
  1181         OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPWRITEBUFFER_DUP11, "  removing RequestCallback @ 0x%x (due to error)", &aCallback);
  1170 		iRequestCallbacks[ep] = NULL;
  1182 		iRequestCallbacks[ep] = NULL;
  1171 		}
  1183 		}
  1172 	return KErrNone;
  1184 	return KErrNone;
  1173 	}
  1185 	}
  1174 
  1186 
  1181 	@param aClientId A pointer to the LDD owning the interface which contains the endpoint.
  1193 	@param aClientId A pointer to the LDD owning the interface which contains the endpoint.
  1182 	@param aRealEndpoint The number of the endpoint for which the transfer request is to be cancelled.
  1194 	@param aRealEndpoint The number of the endpoint for which the transfer request is to be cancelled.
  1183 */
  1195 */
  1184 EXPORT_C void DUsbClientController::CancelReadBuffer(const DBase* aClientId, TInt aRealEndpoint)
  1196 EXPORT_C void DUsbClientController::CancelReadBuffer(const DBase* aClientId, TInt aRealEndpoint)
  1185 	{
  1197 	{
  1186 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CancelReadBuffer(%d)", aRealEndpoint));
  1198 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CANCELREADBUFFER, "DUsbClientController::CancelReadBuffer(%d)", aRealEndpoint);
       
  1199 	
  1187 	if (aRealEndpoint < 0)
  1200 	if (aRealEndpoint < 0)
  1188 		{
  1201 		{
  1189 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: ep # < 0: %d", aRealEndpoint));
  1202 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CANCELREADBUFFER_DUP1, "  Error: ep # < 0: %d", aRealEndpoint);
  1190 		return;
  1203 		return;
  1191 		}
  1204 		}
  1192 	// Note that we here don't cancel Ep0 read requests at the PSL level!
  1205 	// Note that we here don't cancel Ep0 read requests at the PSL level!
  1193 	if (aRealEndpoint > 0)
  1206 	if (aRealEndpoint > 0)
  1194 		{
  1207 		{
  1207 	@param aClientId A pointer to the LDD owning the interface which contains the endpoint.
  1220 	@param aClientId A pointer to the LDD owning the interface which contains the endpoint.
  1208 	@param aRealEndpoint The number of the endpoint for which the transfer request is to be cancelled.
  1221 	@param aRealEndpoint The number of the endpoint for which the transfer request is to be cancelled.
  1209 */
  1222 */
  1210 EXPORT_C void DUsbClientController::CancelWriteBuffer(const DBase* aClientId, TInt aRealEndpoint)
  1223 EXPORT_C void DUsbClientController::CancelWriteBuffer(const DBase* aClientId, TInt aRealEndpoint)
  1211 	{
  1224 	{
  1212 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CancelWriteBuffer(%d)", aRealEndpoint));
  1225 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CANCELWRITEBUFFER, "DUsbClientController::CancelWriteBuffer(%d)", aRealEndpoint);
       
  1226 	
  1213 	if (aRealEndpoint < 0)
  1227 	if (aRealEndpoint < 0)
  1214 		{
  1228 		{
  1215 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: ep # < 0: %d", aRealEndpoint));
  1229 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CANCELWRITEBUFFER_DUP1, "  Error: ep # < 0: %d", aRealEndpoint);
  1216 		return;
  1230 		return;
  1217 		}
  1231 		}
  1218 	if (aRealEndpoint == 0)
  1232 	if (aRealEndpoint == 0)
  1219 		{
  1233 		{
  1220 		// Ep0 IN needs to be adjusted: the LDD uses 0 for both Ep0 directions.
  1234 		// Ep0 IN needs to be adjusted: the LDD uses 0 for both Ep0 directions.
  1238 	@return KErrNotFound if endpoint couldn't be found (includes Ep0), KErrNone if endpoint successfully
  1252 	@return KErrNotFound if endpoint couldn't be found (includes Ep0), KErrNone if endpoint successfully
  1239 	stalled, KErrGeneral otherwise.
  1253 	stalled, KErrGeneral otherwise.
  1240 */
  1254 */
  1241 EXPORT_C TInt DUsbClientController::HaltEndpoint(const DBase* aClientId, TInt aEndpointNum)
  1255 EXPORT_C TInt DUsbClientController::HaltEndpoint(const DBase* aClientId, TInt aEndpointNum)
  1242 	{
  1256 	{
  1243 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::HaltEndpoint(%d)", aEndpointNum));
  1257 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_HALTENDPOINT, "DUsbClientController::HaltEndpoint(%d)", aEndpointNum);
       
  1258 	
  1244 	const TInt r = StallEndpoint(aEndpointNum);
  1259 	const TInt r = StallEndpoint(aEndpointNum);
  1245 	if (r == KErrNone)
  1260 	if (r == KErrNone)
  1246 		{
  1261 		{
  1247 		iRealEndpoints[aEndpointNum].iHalt = ETrue;
  1262 		iRealEndpoints[aEndpointNum].iHalt = ETrue;
  1248 		}
  1263 		}
  1262 	@return KErrNotFound if endpoint couldn't be found (includes Ep0), KErrNone if endpoint successfully
  1277 	@return KErrNotFound if endpoint couldn't be found (includes Ep0), KErrNone if endpoint successfully
  1263 	stalled, KErrGeneral otherwise.
  1278 	stalled, KErrGeneral otherwise.
  1264 */
  1279 */
  1265 EXPORT_C TInt DUsbClientController::ClearHaltEndpoint(const DBase* aClientId, TInt aEndpointNum)
  1280 EXPORT_C TInt DUsbClientController::ClearHaltEndpoint(const DBase* aClientId, TInt aEndpointNum)
  1266 	{
  1281 	{
  1267 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ClearHaltEndpoint(%d)", aEndpointNum));
  1282 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CLEARHALTENDPOINT, "DUsbClientController::ClearHaltEndpoint(%d)", aEndpointNum);
  1268 	const TInt r = ClearStallEndpoint(aEndpointNum);
  1283 	const TInt r = ClearStallEndpoint(aEndpointNum);
  1269 	if (r == KErrNone)
  1284 	if (r == KErrNone)
  1270 		{
  1285 		{
  1271 		iRealEndpoints[aEndpointNum].iHalt = EFalse;
  1286 		iRealEndpoints[aEndpointNum].iHalt = EFalse;
  1272 		}
  1287 		}
  1289 	@return KErrNone if device control successfully claimed or if this LDD already owns it, KErrGeneral if
  1304 	@return KErrNone if device control successfully claimed or if this LDD already owns it, KErrGeneral if
  1290 	device control already owned by a different client.
  1305 	device control already owned by a different client.
  1291 */
  1306 */
  1292 EXPORT_C TInt DUsbClientController::SetDeviceControl(const DBase* aClientId)
  1307 EXPORT_C TInt DUsbClientController::SetDeviceControl(const DBase* aClientId)
  1293 	{
  1308 	{
  1294 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetDeviceControl()"));
  1309 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETDEVICECONTROL, "DUsbClientController::SetDeviceControl()" );
  1295 	if (iEp0DeviceControl)
  1310 	if (iEp0DeviceControl)
  1296 		{
  1311 		{
  1297 		if (iEp0DeviceControl == aClientId)
  1312 		if (iEp0DeviceControl == aClientId)
  1298 			{
  1313 			{
  1299 			__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Device Control already owned by this client"));
  1314 			OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETDEVICECONTROL_DUP1, "  Warning: Device Control already owned by this client" );
  1300 			return KErrNone;
  1315 			return KErrNone;
  1301 			}
  1316 			}
  1302 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Device Control already claimed by a different client"));
  1317         OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETDEVICECONTROL_DUP2, "  Error: Device Control already claimed by a different client");
  1303 		return KErrGeneral;
  1318 		return KErrGeneral;
  1304 		}
  1319 		}
  1305 	iEp0DeviceControl = aClientId;
  1320 	iEp0DeviceControl = aClientId;
  1306 	return KErrNone;
  1321 	return KErrNone;
  1307 	}
  1322 	}
  1316 	@return KErrNone if device control successfully released, KErrGeneral if device control owned by a
  1331 	@return KErrNone if device control successfully released, KErrGeneral if device control owned by a
  1317 	different client or by no client at all.
  1332 	different client or by no client at all.
  1318 */
  1333 */
  1319 EXPORT_C TInt DUsbClientController::ReleaseDeviceControl(const DBase* aClientId)
  1334 EXPORT_C TInt DUsbClientController::ReleaseDeviceControl(const DBase* aClientId)
  1320 	{
  1335 	{
  1321 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ReleaseDeviceControl()"));
  1336 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_RELEASEDEVICECONTROL, "DUsbClientController::ReleaseDeviceControl()" );
  1322 	if (iEp0DeviceControl)
  1337 	if (iEp0DeviceControl)
  1323 		{
  1338 		{
  1324 		if (iEp0DeviceControl == aClientId)
  1339 		if (iEp0DeviceControl == aClientId)
  1325 			{
  1340 			{
  1326 			__KTRACE_OPT(KUSB, Kern::Printf("  Releasing Device Control"));
  1341 			OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RELEASEDEVICECONTROL_DUP1, "  Releasing Device Control" );
  1327 			iEp0DeviceControl = NULL;
  1342 			iEp0DeviceControl = NULL;
  1328 			return KErrNone;
  1343 			return KErrNone;
  1329 			}
  1344 			}
  1330 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Device Control owned by a different client"));
  1345         OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_RELEASEDEVICECONTROL_DUP2, "  Error: Device Control owned by a different client" );
  1331 		}
  1346 		}
  1332 	else
  1347 	else
  1333 		{
  1348 		{
  1334 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Device Control not owned by any client"));
  1349         OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_RELEASEDEVICECONTROL_DUP3, "  Error: Device Control not owned by any client" );
  1335 		}
  1350 		}
  1336 	return KErrGeneral;
  1351 	return KErrGeneral;
  1337 	}
  1352 	}
  1338 
  1353 
  1339 
  1354 
  1344 
  1359 
  1345 	@return All available (configurable) max packet sizes for Ep0.
  1360 	@return All available (configurable) max packet sizes for Ep0.
  1346 */
  1361 */
  1347 EXPORT_C TUint DUsbClientController::EndpointZeroMaxPacketSizes() const
  1362 EXPORT_C TUint DUsbClientController::EndpointZeroMaxPacketSizes() const
  1348 	{
  1363 	{
  1349 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EndpointZeroMaxPacketSizes()"));
  1364 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENDPOINTZEROMAXPACKETSIZES, "DUsbClientController::EndpointZeroMaxPacketSizes()" );
  1350 	return iRealEndpoints[0].iCaps.iSizes;
  1365 	return iRealEndpoints[0].iCaps.iSizes;
  1351 	}
  1366 	}
  1352 
  1367 
  1353 
  1368 
  1354 /** Sets (configures) the max packet size for Ep0.
  1369 /** Sets (configures) the max packet size for Ep0.
  1360 	@return KErrNotSupported if invalid size specified, KErrNone if new max packet size successfully set or
  1375 	@return KErrNotSupported if invalid size specified, KErrNone if new max packet size successfully set or
  1361 	requested size was already set.
  1376 	requested size was already set.
  1362 */
  1377 */
  1363 EXPORT_C TInt DUsbClientController::SetEndpointZeroMaxPacketSize(TInt aMaxPacketSize)
  1378 EXPORT_C TInt DUsbClientController::SetEndpointZeroMaxPacketSize(TInt aMaxPacketSize)
  1364 	{
  1379 	{
  1365 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetEndpointZeroMaxPacketSize(%d)",
  1380 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETENDPOINTZEROMAXPACKETSIZE, "DUsbClientController::SetEndpointZeroMaxPacketSize(%d)",
  1366 									aMaxPacketSize));
  1381                                     aMaxPacketSize);
       
  1382 	
  1367 
  1383 
  1368 	if (DeviceHighSpeedCaps())
  1384 	if (DeviceHighSpeedCaps())
  1369 		{
  1385 		{
  1370 		// We're not going to mess with this on a HS device.
  1386 		// We're not going to mess with this on a HS device.
  1371 		return KErrNone;
  1387 		return KErrNone;
  1372 		}
  1388 		}
  1373 
  1389 
  1374 	if (!(iRealEndpoints[0].iCaps.iSizes & PacketSize2Mask(aMaxPacketSize)))
  1390 	if (!(iRealEndpoints[0].iCaps.iSizes & PacketSize2Mask(aMaxPacketSize)))
  1375 		{
  1391 		{
  1376 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: invalid size"));
  1392 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETENDPOINTZEROMAXPACKETSIZE_DUP1, "  Error: invalid size");
  1377 		return KErrNotSupported;
  1393 		return KErrNotSupported;
  1378 		}
  1394 		}
  1379 	if (iRealEndpoints[0].iLEndpoint->iEpSize_Fs == aMaxPacketSize)
  1395 	if (iRealEndpoints[0].iLEndpoint->iEpSize_Fs == aMaxPacketSize)
  1380 		{
  1396 		{
  1381 		__KTRACE_OPT(KUSB, Kern::Printf("  this packet size already set -> returning"));
  1397 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETENDPOINTZEROMAXPACKETSIZE_DUP2, "  this packet size already set -> returning");
  1382 		return KErrNone;
  1398 		return KErrNone;
  1383 		}
  1399 		}
  1384 	const TUsbcLogicalEndpoint* const ep0_0 = iRealEndpoints[0].iLEndpoint;
  1400 	const TUsbcLogicalEndpoint* const ep0_0 = iRealEndpoints[0].iLEndpoint;
  1385 	const TUsbcLogicalEndpoint* const ep0_1 = iRealEndpoints[1].iLEndpoint;
  1401 	const TUsbcLogicalEndpoint* const ep0_1 = iRealEndpoints[1].iLEndpoint;
  1386 	const_cast<TUsbcLogicalEndpoint*>(ep0_0)->iEpSize_Fs = aMaxPacketSize;
  1402 	const_cast<TUsbcLogicalEndpoint*>(ep0_0)->iEpSize_Fs = aMaxPacketSize;
  1413 	@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target
  1429 	@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target
  1414 	buffer.
  1430 	buffer.
  1415 */
  1431 */
  1416 EXPORT_C TInt DUsbClientController::GetDeviceDescriptor(DThread* aThread, TDes8& aDeviceDescriptor)
  1432 EXPORT_C TInt DUsbClientController::GetDeviceDescriptor(DThread* aThread, TDes8& aDeviceDescriptor)
  1417 	{
  1433 	{
  1418 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetDeviceDescriptor()"));
  1434 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETDEVICEDESCRIPTOR, "DUsbClientController::GetDeviceDescriptor()" );
  1419 	return iDescriptors.GetDeviceDescriptorTC(aThread, aDeviceDescriptor);
  1435 	return iDescriptors.GetDeviceDescriptorTC(aThread, aDeviceDescriptor);
  1420 	}
  1436 	}
  1421 
  1437 
  1422 
  1438 
  1423 /** Sets a new USB Device descriptor.
  1439 /** Sets a new USB Device descriptor.
  1429 	@return The return value of the thread read operation, Kern::ThreadRead(), when reading from the source
  1445 	@return The return value of the thread read operation, Kern::ThreadRead(), when reading from the source
  1430 	buffer in case of a failure, KErrNone if the new descriptor was successfully set.
  1446 	buffer in case of a failure, KErrNone if the new descriptor was successfully set.
  1431 */
  1447 */
  1432 EXPORT_C TInt DUsbClientController::SetDeviceDescriptor(DThread* aThread, const TDes8& aDeviceDescriptor)
  1448 EXPORT_C TInt DUsbClientController::SetDeviceDescriptor(DThread* aThread, const TDes8& aDeviceDescriptor)
  1433 	{
  1449 	{
  1434 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetDeviceDescriptor()"));
  1450 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETDEVICEDESCRIPTOR, "DUsbClientController::SetDeviceDescriptor()" );
  1435 	return iDescriptors.SetDeviceDescriptorTC(aThread, aDeviceDescriptor);
  1451 	return iDescriptors.SetDeviceDescriptorTC(aThread, aDeviceDescriptor);
  1436 	}
  1452 	}
  1437 
  1453 
  1438 
  1454 
  1439 /** Returns the current USB Device descriptor size.
  1455 /** Returns the current USB Device descriptor size.
  1445 	@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target
  1461 	@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target
  1446 	buffer.
  1462 	buffer.
  1447 */
  1463 */
  1448 EXPORT_C TInt DUsbClientController::GetDeviceDescriptorSize(DThread* aThread, TDes8& aSize)
  1464 EXPORT_C TInt DUsbClientController::GetDeviceDescriptorSize(DThread* aThread, TDes8& aSize)
  1449 	{
  1465 	{
  1450 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetDeviceDescriptorSize()"));
  1466 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETDEVICEDESCRIPTORSIZE, "DUsbClientController::GetDeviceDescriptorSize()" );
  1451 	// We do not really enquire here....
  1467 	// We do not really enquire here....
  1452 	const TPtrC8 size(reinterpret_cast<const TUint8*>(&KUsbDescSize_Device), sizeof(KUsbDescSize_Device));
  1468 	const TPtrC8 size(reinterpret_cast<const TUint8*>(&KUsbDescSize_Device), sizeof(KUsbDescSize_Device));
  1453 	return Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  1469 	return Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  1454 	}
  1470 	}
  1455 
  1471 
  1463 	@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target
  1479 	@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target
  1464 	buffer.
  1480 	buffer.
  1465 */
  1481 */
  1466 EXPORT_C TInt DUsbClientController::GetConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor)
  1482 EXPORT_C TInt DUsbClientController::GetConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor)
  1467 	{
  1483 	{
  1468 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetConfigurationDescriptor()"));
  1484 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETCONFIGURATIONDESCRIPTOR, "DUsbClientController::GetConfigurationDescriptor()" );
  1469 	return iDescriptors.GetConfigurationDescriptorTC(aThread, aConfigurationDescriptor);
  1485 	return iDescriptors.GetConfigurationDescriptorTC(aThread, aConfigurationDescriptor);
  1470 	}
  1486 	}
  1471 
  1487 
  1472 
  1488 
  1473 /** Sets a new USB configuration descriptor.
  1489 /** Sets a new USB configuration descriptor.
  1480 	buffer in case of a failure, KErrNone if the new descriptor was successfully set.
  1496 	buffer in case of a failure, KErrNone if the new descriptor was successfully set.
  1481 */
  1497 */
  1482 EXPORT_C TInt DUsbClientController::SetConfigurationDescriptor(DThread* aThread,
  1498 EXPORT_C TInt DUsbClientController::SetConfigurationDescriptor(DThread* aThread,
  1483 															   const TDes8& aConfigurationDescriptor)
  1499 															   const TDes8& aConfigurationDescriptor)
  1484 	{
  1500 	{
  1485 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetConfigurationDescriptor()"));
  1501 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETCONFIGURATIONDESCRIPTOR, "DUsbClientController::SetConfigurationDescriptor()" );
  1486 	return iDescriptors.SetConfigurationDescriptorTC(aThread, aConfigurationDescriptor);
  1502 	return iDescriptors.SetConfigurationDescriptorTC(aThread, aConfigurationDescriptor);
  1487 	}
  1503 	}
  1488 
  1504 
  1489 
  1505 
  1490 /** Returns the current USB configuration descriptor size.
  1506 /** Returns the current USB configuration descriptor size.
  1496 	@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target
  1512 	@return The return value of the thread write operation, Kern::ThreadWrite(), when writing to the target
  1497 	buffer.
  1513 	buffer.
  1498 */
  1514 */
  1499 EXPORT_C TInt DUsbClientController::GetConfigurationDescriptorSize(DThread* aThread, TDes8& aSize)
  1515 EXPORT_C TInt DUsbClientController::GetConfigurationDescriptorSize(DThread* aThread, TDes8& aSize)
  1500 	{
  1516 	{
  1501 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetConfigurationDescriptorSize()"));
  1517 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETCONFIGURATIONDESCRIPTORSIZE, "DUsbClientController::GetConfigurationDescriptorSize()" );
  1502 	// We do not really enquire here....
  1518 	// We do not really enquire here....
  1503 	const TPtrC8 size(reinterpret_cast<const TUint8*>(&KUsbDescSize_Config), sizeof(KUsbDescSize_Config));
  1519 	const TPtrC8 size(reinterpret_cast<const TUint8*>(&KUsbDescSize_Config), sizeof(KUsbDescSize_Config));
  1504 	return Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  1520 	return Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  1505 	}
  1521 	}
  1506 
  1522 
  1514 	@return KErrNotSupported or the return value of the thread write operation, Kern::ThreadDesWrite(),
  1530 	@return KErrNotSupported or the return value of the thread write operation, Kern::ThreadDesWrite(),
  1515 	when writing to the target buffer.
  1531 	when writing to the target buffer.
  1516 */
  1532 */
  1517 EXPORT_C TInt DUsbClientController::GetOtgDescriptor(DThread* aThread, TDes8& aOtgDesc) const
  1533 EXPORT_C TInt DUsbClientController::GetOtgDescriptor(DThread* aThread, TDes8& aOtgDesc) const
  1518 	{
  1534 	{
  1519 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetOtgDescriptor()"));
  1535 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETOTGDESCRIPTOR, "DUsbClientController::GetOtgDescriptor()" );
  1520 	if (!iOtgSupport)
  1536 	if (!iOtgSupport)
  1521 		{
  1537 		{
  1522 		return KErrNotSupported;
  1538 		return KErrNotSupported;
  1523 		}
  1539 		}
  1524 	return iDescriptors.GetOtgDescriptorTC(aThread, aOtgDesc);
  1540 	return iDescriptors.GetOtgDescriptorTC(aThread, aOtgDesc);
  1532 
  1548 
  1533 	@return KErrNotSupported or the return value of the thread read operation, Kern::ThreadDesRead().
  1549 	@return KErrNotSupported or the return value of the thread read operation, Kern::ThreadDesRead().
  1534 */
  1550 */
  1535 EXPORT_C TInt DUsbClientController::SetOtgDescriptor(DThread* aThread, const TDesC8& aOtgDesc)
  1551 EXPORT_C TInt DUsbClientController::SetOtgDescriptor(DThread* aThread, const TDesC8& aOtgDesc)
  1536 	{
  1552 	{
  1537 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetOtgDescriptor()"));
  1553 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR, "DUsbClientController::SetOtgDescriptor()" );
  1538 	if (!iOtgSupport)
  1554 	if (!iOtgSupport)
  1539 		{
  1555 		{
  1540 		return KErrNotSupported;
  1556 		return KErrNotSupported;
  1541 		}
  1557 		}
  1542 	TBuf8<KUsbDescSize_Otg> otg;
  1558 	TBuf8<KUsbDescSize_Otg> otg;
  1546 		return r;
  1562 		return r;
  1547 		}
  1563 		}
  1548 	// Check descriptor validity
  1564 	// Check descriptor validity
  1549 	if (otg[0] != KUsbDescSize_Otg || otg[1] != KUsbDescType_Otg || otg[2] > 3)
  1565 	if (otg[0] != KUsbDescSize_Otg || otg[1] != KUsbDescType_Otg || otg[2] > 3)
  1550 		{
  1566 		{
  1551 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid OTG descriptor"));
  1567 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP1, "  Error: Invalid OTG descriptor" );
  1552 		return KErrGeneral;
  1568 		return KErrGeneral;
  1553 		}
  1569 		}
  1554 	__KTRACE_OPT(KUSB, Kern::Printf("  iOtgFuncMap before: 0x%x", iOtgFuncMap));
  1570     OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP2, "  iOtgFuncMap before: 0x%x", iOtgFuncMap);
  1555 	// Update value in controller as well
  1571 	// Update value in controller as well
  1556 	const TUint8 hnp = otg[2] & KUsbOtgAttr_HnpSupp;
  1572 	const TUint8 hnp = otg[2] & KUsbOtgAttr_HnpSupp;
  1557 	const TUint8 srp = otg[2] & KUsbOtgAttr_SrpSupp;
  1573 	const TUint8 srp = otg[2] & KUsbOtgAttr_SrpSupp;
  1558 	if (hnp && !srp)
  1574 	if (hnp && !srp)
  1559 		{
  1575 		{
  1560 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Invalid OTG attribute combination (HNP && !SRP"));
  1576 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP3, " Warning: Invalid OTG attribute combination (HNP && !SRP");
  1561 		}
  1577 		}
  1562 	if (hnp && !(iOtgFuncMap & KUsbOtgAttr_HnpSupp))
  1578 	if (hnp && !(iOtgFuncMap & KUsbOtgAttr_HnpSupp))
  1563 		{
  1579 		{
  1564 		__KTRACE_OPT(KUSB, Kern::Printf("  Setting attribute KUsbOtgAttr_HnpSupp"));
  1580 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP4, "   Setting attribute KUsbOtgAttr_HnpSupp");
  1565 		iOtgFuncMap |= KUsbOtgAttr_HnpSupp;
  1581 		iOtgFuncMap |= KUsbOtgAttr_HnpSupp;
  1566 		}
  1582 		}
  1567 	else if (!hnp && (iOtgFuncMap & KUsbOtgAttr_HnpSupp))
  1583 	else if (!hnp && (iOtgFuncMap & KUsbOtgAttr_HnpSupp))
  1568 		{
  1584 		{
  1569 		__KTRACE_OPT(KUSB, Kern::Printf("  Removing attribute KUsbOtgAttr_HnpSupp"));
  1585 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP5, "  Removing attribute KUsbOtgAttr_HnpSupp");
  1570 		iOtgFuncMap &= ~KUsbOtgAttr_HnpSupp;
  1586 		iOtgFuncMap &= ~KUsbOtgAttr_HnpSupp;
  1571 		}
  1587 		}
  1572 	if (srp && !(iOtgFuncMap & KUsbOtgAttr_SrpSupp))
  1588 	if (srp && !(iOtgFuncMap & KUsbOtgAttr_SrpSupp))
  1573 		{
  1589 		{
  1574 		__KTRACE_OPT(KUSB, Kern::Printf("  Setting attribute KUsbOtgAttr_SrpSupp"));
  1590 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP6, "  Setting attribute KUsbOtgAttr_SrpSupp");
  1575 		iOtgFuncMap |= KUsbOtgAttr_SrpSupp;
  1591 		iOtgFuncMap |= KUsbOtgAttr_SrpSupp;
  1576 		}
  1592 		}
  1577 	else if (!srp && (iOtgFuncMap & KUsbOtgAttr_SrpSupp))
  1593 	else if (!srp && (iOtgFuncMap & KUsbOtgAttr_SrpSupp))
  1578 		{
  1594 		{
  1579 		__KTRACE_OPT(KUSB, Kern::Printf("  Removing attribute KUsbOtgAttr_SrpSupp"));
  1595 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP7, "  Removing attribute KUsbOtgAttr_SrpSupp");
  1580 		iOtgFuncMap &= ~KUsbOtgAttr_SrpSupp;
  1596 		iOtgFuncMap &= ~KUsbOtgAttr_SrpSupp;
  1581 		}
  1597 		}
  1582 	__KTRACE_OPT(KUSB, Kern::Printf("  iOtgFuncMap after:  0x%x", iOtgFuncMap));
  1598     OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETOTGDESCRIPTOR_DUP8, "  iOtgFuncMap after:  0x%x", iOtgFuncMap);
  1583 	return iDescriptors.SetOtgDescriptor(otg);
  1599 	return iDescriptors.SetOtgDescriptor(otg);
  1584 	}
  1600 	}
  1585 
  1601 
  1586 
  1602 
  1587 /** Returns current OTG features of USB device.
  1603 /** Returns current OTG features of USB device.
  1591 
  1607 
  1592 	@return KErrNotSupported or the return value of the thread write operation, Kern::ThreadDesWrite().
  1608 	@return KErrNotSupported or the return value of the thread write operation, Kern::ThreadDesWrite().
  1593 */
  1609 */
  1594 EXPORT_C TInt DUsbClientController::GetOtgFeatures(DThread* aThread, TDes8& aFeatures) const
  1610 EXPORT_C TInt DUsbClientController::GetOtgFeatures(DThread* aThread, TDes8& aFeatures) const
  1595 	{
  1611 	{
  1596 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetOtgFeatures()"));
  1612 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETOTGFEATURES, "DUsbClientController::GetOtgFeatures()" );
  1597 	if (!iOtgSupport)
  1613 	if (!iOtgSupport)
  1598 		{
  1614 		{
  1599 		return KErrNotSupported;
  1615 		return KErrNotSupported;
  1600 		}
  1616 		}
  1601 	TBuf8<1> features(1);
  1617 	TBuf8<1> features(1);
  1610 	@param aFeatures The reference to which the current features should be set at.
  1626 	@param aFeatures The reference to which the current features should be set at.
  1611 	@return KErrNone if successful, KErrNotSupported if OTG is unavailable.
  1627 	@return KErrNone if successful, KErrNotSupported if OTG is unavailable.
  1612 */
  1628 */
  1613 EXPORT_C TInt DUsbClientController::GetCurrentOtgFeatures(TUint8& aFeatures) const
  1629 EXPORT_C TInt DUsbClientController::GetCurrentOtgFeatures(TUint8& aFeatures) const
  1614 	{
  1630 	{
  1615 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetCurrentOtgFeatures()"));
  1631 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETCURRENTOTGFEATURES, "DUsbClientController::GetCurrentOtgFeatures()" );
  1616 	if (!iOtgSupport)
  1632 	if (!iOtgSupport)
  1617 		{
  1633 		{
  1618 		return KErrNotSupported;
  1634 		return KErrNotSupported;
  1619 		}
  1635 		}
  1620 	aFeatures = iOtgFuncMap & 0x1C;
  1636 	aFeatures = iOtgFuncMap & 0x1C;
  1631 
  1647 
  1632 	@return KErrNone if successful, KErrAlreadyExists if aCallback is already in the queue.
  1648 	@return KErrNone if successful, KErrAlreadyExists if aCallback is already in the queue.
  1633 */
  1649 */
  1634 EXPORT_C TInt DUsbClientController::RegisterForOtgFeatureChange(TUsbcOtgFeatureCallback& aCallback)
  1650 EXPORT_C TInt DUsbClientController::RegisterForOtgFeatureChange(TUsbcOtgFeatureCallback& aCallback)
  1635 	{
  1651 	{
  1636 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RegisterForOtgFeatureChange()"));
  1652 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERFOROTGFEATURECHANGE, "DUsbClientController::RegisterForOtgFeatureChange()" );
  1637 	if (iOtgCallbacks.Elements() == KUsbcMaxListLength)
  1653 	if (iOtgCallbacks.Elements() == KUsbcMaxListLength)
  1638 		{
  1654 		{
  1639 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Maximum list length reached: %d",
  1655 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERFOROTGFEATURECHANGE_DUP1, "  Error: Maximum list length reached: %d",
  1640 										  KUsbcMaxListLength));
  1656                                           KUsbcMaxListLength);
  1641 		return KErrGeneral;
  1657 		return KErrGeneral;
  1642 		}
  1658 		}
  1643 	if (IsInTheOtgFeatureList(aCallback))
  1659 	if (IsInTheOtgFeatureList(aCallback))
  1644 		{
  1660 		{
  1645 		__KTRACE_OPT(KUSB, Kern::Printf("  Error: OtgFeatureCallback @ 0x%x already registered", &aCallback));
  1661 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REGISTERFOROTGFEATURECHANGE_DUP2, "  Error: OtgFeatureCallback @ 0x%x already registered", &aCallback);
  1646 		return KErrAlreadyExists;
  1662 		return KErrAlreadyExists;
  1647 		}
  1663 		}
  1648     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  1664     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  1649 	iOtgCallbacks.AddLast(aCallback);
  1665 	iOtgCallbacks.AddLast(aCallback);
  1650     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  1666     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  1659 
  1675 
  1660 	@return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found.
  1676 	@return KErrNone if callback successfully unregistered, KErrNotFound if the callback couldn't be found.
  1661 */
  1677 */
  1662 EXPORT_C TInt DUsbClientController::DeRegisterForOtgFeatureChange(const DBase* aClientId)
  1678 EXPORT_C TInt DUsbClientController::DeRegisterForOtgFeatureChange(const DBase* aClientId)
  1663 	{
  1679 	{
  1664 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeRegisterForOtgFeatureChange()"));
  1680 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERFOROTGFEATURECHANGE, "DUsbClientController::DeRegisterForOtgFeatureChange()" );
  1665 	__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__));
  1681 	__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__));
  1666     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  1682     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  1667 	TSglQueIter<TUsbcOtgFeatureCallback> iter(iOtgCallbacks);
  1683 	TSglQueIter<TUsbcOtgFeatureCallback> iter(iOtgCallbacks);
  1668 	TUsbcOtgFeatureCallback* p;
  1684 	TUsbcOtgFeatureCallback* p;
  1669 	while ((p = iter++) != NULL)
  1685 	while ((p = iter++) != NULL)
  1670 		{
  1686 		{
  1671 		if (!aClientId || p->Owner() == aClientId)
  1687 		if (!aClientId || p->Owner() == aClientId)
  1672 			{
  1688 			{
  1673 			__KTRACE_OPT(KUSB, Kern::Printf("  removing OtgFeatureCallback @ 0x%x", p));
  1689 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFOROTGFEATURECHANGE_DUP1, "  removing OtgFeatureCallback @ 0x%x", p);
  1674 			iOtgCallbacks.Remove(*p);
  1690 			iOtgCallbacks.Remove(*p);
  1675             __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  1691             __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  1676 			return KErrNone;
  1692 			return KErrNone;
  1677 			}
  1693 			}
  1678 		}
  1694 		}
  1679 	__KTRACE_OPT(KUSB, Kern::Printf("  client not found"));
  1695     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERFOROTGFEATURECHANGE_DUP2, "  client not found");
  1680     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  1696     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  1681 	return KErrNotFound;
  1697 	return KErrNotFound;
  1682 	}
  1698 	}
  1683 
  1699 
  1684 
  1700 
  1694 	write operation, Kern::ThreadWrite(), when writing to the target buffer.
  1710 	write operation, Kern::ThreadWrite(), when writing to the target buffer.
  1695 */
  1711 */
  1696 EXPORT_C TInt DUsbClientController::GetInterfaceDescriptor(DThread* aThread, const DBase* aClientId,
  1712 EXPORT_C TInt DUsbClientController::GetInterfaceDescriptor(DThread* aThread, const DBase* aClientId,
  1697 														   TInt aSettingNum, TDes8& aInterfaceDescriptor)
  1713 														   TInt aSettingNum, TDes8& aInterfaceDescriptor)
  1698 	{
  1714 	{
  1699 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetInterfaceDescriptor(x, 0x%08x, %d, y)",
  1715 	OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETINTERFACEDESCRIPTOR, "DUsbClientController::GetInterfaceDescriptor(x, 0x%08x, %d, y)",
  1700 									aClientId, aSettingNum));
  1716                                     (TUint)aClientId, aSettingNum);
       
  1717 	
  1701 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1718 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1702 	if (ifcset < 0)
  1719 	if (ifcset < 0)
  1703 		{
  1720 		{
  1704 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  1721 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETINTERFACEDESCRIPTOR_DUP1, "  Error: Interface not found from client ID");
  1705 		return KErrNotFound;
  1722 		return KErrNotFound;
  1706 		}
  1723 		}
  1707 	return iDescriptors.GetInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum);
  1724 	return iDescriptors.GetInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum);
  1708 	}
  1725 	}
  1709 
  1726 
  1729 	if the new descriptor was successfully set.
  1746 	if the new descriptor was successfully set.
  1730 */
  1747 */
  1731 EXPORT_C TInt DUsbClientController::SetInterfaceDescriptor(DThread* aThread, const DBase* aClientId,
  1748 EXPORT_C TInt DUsbClientController::SetInterfaceDescriptor(DThread* aThread, const DBase* aClientId,
  1732 														   TInt aSettingNum, const TDes8& aInterfaceDescriptor)
  1749 														   TInt aSettingNum, const TDes8& aInterfaceDescriptor)
  1733 	{
  1750 	{
  1734 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetInterfaceDescriptor(x, 0x%08x, %d, y)",
  1751 	OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR, "DUsbClientController::SetInterfaceDescriptor(x, 0x%08x, %d, y)",
  1735 									aClientId, aSettingNum));
  1752                                     (TUint)aClientId, aSettingNum);
  1736 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1753 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1737 	if (ifcset < 0)
  1754 	if (ifcset < 0)
  1738 		{
  1755 		{
  1739 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  1756 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP1, "  Error: Interface not found from client ID");
  1740 		return KErrNotFound;
  1757 		return KErrNotFound;
  1741 		}
  1758 		}
  1742 	TBuf8<KUsbDescSize_Interface> new_ifc;
  1759 	TBuf8<KUsbDescSize_Interface> new_ifc;
  1743 	TInt r = Kern::ThreadDesRead(aThread, &aInterfaceDescriptor, new_ifc, 0);
  1760 	TInt r = Kern::ThreadDesRead(aThread, &aInterfaceDescriptor, new_ifc, 0);
  1744 	if (r != KErrNone)
  1761 	if (r != KErrNone)
  1745 		{
  1762 		{
  1746 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Copying interface descriptor buffer failed (%d)", r));
  1763 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP2, "  Error: Copying interface descriptor buffer failed (%d)", r);
  1747 		return r;
  1764 		return r;
  1748 		}
  1765 		}
  1749 	const TInt ifcset_new = new_ifc[2];
  1766 	const TInt ifcset_new = new_ifc[2];
  1750 	const TBool ifc_num_changes = (ifcset != ifcset_new);
  1767 	const TBool ifc_num_changes = (ifcset != ifcset_new);
  1751 	TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset);
  1768 	TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset);
  1752 	if (!ifcset_ptr)
  1769 	if (!ifcset_ptr)
  1753 		{
  1770 		{
  1754 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: interface number %d doesn't exist", ifcset));
  1771 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP3, "  Error: interface number %d doesn't exist", ifcset);
  1755 		return KErrNotFound;
  1772 		return KErrNotFound;
  1756 		}
  1773 		}
  1757 	if (ifc_num_changes)
  1774 	if (ifc_num_changes)
  1758 		{
  1775 		{
  1759 		// If the user wants to change the interface number, we need to do some sanity checks:
  1776 		// If the user wants to change the interface number, we need to do some sanity checks:
  1760 		if (InterfaceExists(ifcset_new))
  1777 		if (InterfaceExists(ifcset_new))
  1761 			{
  1778 			{
  1762 			// Obviously we cannot accept a number that is already used by another interface.
  1779 			// Obviously we cannot accept a number that is already used by another interface.
  1763 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: interface number %d already in use", ifcset_new));
  1780 		    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP4, "  Error: interface number %d already in use", ifcset_new);
  1764 			return KErrArgument;
  1781 			return KErrArgument;
  1765 			}
  1782 			}
  1766 		if (ifcset_ptr->iInterfaces.Count() > 1)
  1783 		if (ifcset_ptr->iInterfaces.Count() > 1)
  1767 			{
  1784 			{
  1768 			// We allow the interface number to be changed only when it's the only setting.
  1785 			// We allow the interface number to be changed only when it's the only setting.
  1769 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: interface has more than one alternate setting"));
  1786 	        OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP5, "  Error: interface has more than one alternate setting");
  1770 			return KErrArgument;
  1787 			return KErrArgument;
  1771 			}
  1788 			}
  1772 		if (aSettingNum != 0)
  1789 		if (aSettingNum != 0)
  1773 			{
  1790 			{
  1774 			// We allow the interface number to be changed only when it's the default setting.
  1791 			// We allow the interface number to be changed only when it's the default setting.
  1775 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: interface number can only be changed for setting 0"));
  1792 	        OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP6, " Error: interface number can only be changed for setting 0");
  1776 			return KErrArgument;
  1793 			return KErrArgument;
  1777 			}
  1794 			}
  1778 		}
  1795 		}
  1779 	if ((r = iDescriptors.SetInterfaceDescriptor(new_ifc, ifcset, aSettingNum)) != KErrNone)
  1796 	if ((r = iDescriptors.SetInterfaceDescriptor(new_ifc, ifcset, aSettingNum)) != KErrNone)
  1780 		{
  1797 		{
  1781 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: iDescriptors.SetInterfaceDescriptorfailed"));
  1798         OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP7, "  Error: iDescriptors.SetInterfaceDescriptorfailed");
  1782 		return r;
  1799 		return r;
  1783 		}
  1800 		}
  1784 	if (ifc_num_changes)
  1801 	if (ifc_num_changes)
  1785 		{
  1802 		{
  1786 		// Alright then, let's do it...
  1803 		// Alright then, let's do it...
  1787 		__KTRACE_OPT(KUSB, Kern::Printf("  about to change interface number from %d to %d",
  1804 		OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETINTERFACEDESCRIPTOR_DUP8, "  about to change interface number from %d to %d",
  1788 										ifcset, ifcset_new));
  1805                                         ifcset, ifcset_new);
  1789 		ifcset_ptr->iInterfaceNumber = ifcset_new;
  1806 		ifcset_ptr->iInterfaceNumber = ifcset_new;
  1790 		}
  1807 		}
  1791 	return KErrNone;
  1808 	return KErrNone;
  1792 	}
  1809 	}
  1793 
  1810 
  1804 	write operation, Kern::ThreadWrite(), when writing to the target buffer.
  1821 	write operation, Kern::ThreadWrite(), when writing to the target buffer.
  1805 */
  1822 */
  1806 EXPORT_C TInt DUsbClientController::GetInterfaceDescriptorSize(DThread* aThread, const DBase* aClientId,
  1823 EXPORT_C TInt DUsbClientController::GetInterfaceDescriptorSize(DThread* aThread, const DBase* aClientId,
  1807 															   TInt /*aSettingNum*/, TDes8& aSize)
  1824 															   TInt /*aSettingNum*/, TDes8& aSize)
  1808 	{
  1825 	{
  1809 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetInterfaceDescriptorSize()"));
  1826 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETINTERFACEDESCRIPTORSIZE, "DUsbClientController::GetInterfaceDescriptorSize()" );
  1810 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1827 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1811 	if (ifcset < 0)
  1828 	if (ifcset < 0)
  1812 		{
  1829 		{
  1813 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  1830 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETINTERFACEDESCRIPTORSIZE_DUP1, "  Error: Interface not found from client ID" );
  1814 		return KErrNotFound;
  1831 		return KErrNotFound;
  1815 		}
  1832 		}
  1816 	// Actually, we do not really enquire here....
  1833 	// Actually, we do not really enquire here....
  1817 	const TPtrC8 size(reinterpret_cast<const TUint8*>(&KUsbDescSize_Interface), sizeof(KUsbDescSize_Interface));
  1834 	const TPtrC8 size(reinterpret_cast<const TUint8*>(&KUsbDescSize_Interface), sizeof(KUsbDescSize_Interface));
  1818 	Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  1835 	Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  1835 */
  1852 */
  1836 EXPORT_C TInt DUsbClientController::GetEndpointDescriptor(DThread* aThread, const DBase* aClientId,
  1853 EXPORT_C TInt DUsbClientController::GetEndpointDescriptor(DThread* aThread, const DBase* aClientId,
  1837 														  TInt aSettingNum, TInt aEndpointNum,
  1854 														  TInt aSettingNum, TInt aEndpointNum,
  1838 														  TDes8& aEndpointDescriptor)
  1855 														  TDes8& aEndpointDescriptor)
  1839 	{
  1856 	{
  1840 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetEndpointDescriptor(x, 0x%08x, %d, %d, y)",
  1857 	OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTOR, "DUsbClientController::GetEndpointDescriptor(x, 0x%08x, %d, %d, y)",
  1841 									aClientId, aSettingNum, aEndpointNum));
  1858                                     (TUint)aClientId, aSettingNum, aEndpointNum);
  1842 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1859 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1843 	if (ifcset < 0)
  1860 	if (ifcset < 0)
  1844 		{
  1861 		{
  1845 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  1862 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTOR_DUP1, "  Error: Interface not found from client ID");
  1846 		return KErrNotFound;
  1863 		return KErrNotFound;
  1847 		}
  1864 		}
  1848 	return iDescriptors.GetEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset,
  1865 	return iDescriptors.GetEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset,
  1849 												aSettingNum, EpIdx2Addr(aEndpointNum));
  1866 												aSettingNum, EpIdx2Addr(aEndpointNum));
  1850 	}
  1867 	}
  1866 */
  1883 */
  1867 EXPORT_C TInt DUsbClientController::SetEndpointDescriptor(DThread* aThread, const DBase* aClientId,
  1884 EXPORT_C TInt DUsbClientController::SetEndpointDescriptor(DThread* aThread, const DBase* aClientId,
  1868 														  TInt aSettingNum, TInt aEndpointNum,
  1885 														  TInt aSettingNum, TInt aEndpointNum,
  1869 														  const TDes8& aEndpointDescriptor)
  1886 														  const TDes8& aEndpointDescriptor)
  1870 	{
  1887 	{
  1871 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetEndpointDescriptor(x, 0x%08x, %d, %d, y)",
  1888 	OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETENDPOINTDESCRIPTOR, "DUsbClientController::SetEndpointDescriptor(x, 0x%08x, %d, %d, y)",
  1872 									aClientId, aSettingNum, aEndpointNum));
  1889                                     (TUint)aClientId, aSettingNum, aEndpointNum);
  1873 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1890 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1874 	if (ifcset < 0)
  1891 	if (ifcset < 0)
  1875 		{
  1892 		{
  1876 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  1893 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETENDPOINTDESCRIPTOR_DUP1, "  Error: Interface not found from client ID");
  1877 		return KErrNotFound;
  1894 		return KErrNotFound;
  1878 		}
  1895 		}
  1879 	return iDescriptors.SetEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset,
  1896 	return iDescriptors.SetEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset,
  1880 												aSettingNum, EpIdx2Addr(aEndpointNum));
  1897 												aSettingNum, EpIdx2Addr(aEndpointNum));
  1881 	}
  1898 	}
  1896 */
  1913 */
  1897 EXPORT_C TInt DUsbClientController::GetEndpointDescriptorSize(DThread* aThread, const DBase* aClientId,
  1914 EXPORT_C TInt DUsbClientController::GetEndpointDescriptorSize(DThread* aThread, const DBase* aClientId,
  1898 															  TInt aSettingNum, TInt aEndpointNum,
  1915 															  TInt aSettingNum, TInt aEndpointNum,
  1899 															  TDes8& aSize)
  1916 															  TDes8& aSize)
  1900 	{
  1917 	{
  1901 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetEndpointDescriptorSize(x, 0x%08x, %d, %d, y)",
  1918 	OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTORSIZE, "DUsbClientController::GetEndpointDescriptorSize(x, 0x%08x, %d, %d, y)",
  1902 									aClientId, aSettingNum, aEndpointNum));
  1919                                     (TUint)aClientId, aSettingNum, aEndpointNum);
  1903 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1920 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  1904 	if (ifcset < 0)
  1921 	if (ifcset < 0)
  1905 		{
  1922 		{
  1906 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  1923 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTORSIZE_DUP1, "D  Error: Interface not found from client ID");
  1907 		return KErrNotFound;
  1924 		return KErrNotFound;
  1908 		}
  1925 		}
  1909 	TInt s;
  1926 	TInt s;
  1910 	TInt r = iDescriptors.GetEndpointDescriptorSize(ifcset, aSettingNum,
  1927 	TInt r = iDescriptors.GetEndpointDescriptorSize(ifcset, aSettingNum,
  1911 													EpIdx2Addr(aEndpointNum), s);
  1928 													EpIdx2Addr(aEndpointNum), s);
  1914 		TPtrC8 size(reinterpret_cast<const TUint8*>(&s), sizeof(s));
  1931 		TPtrC8 size(reinterpret_cast<const TUint8*>(&s), sizeof(s));
  1915 		r = Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  1932 		r = Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  1916 		}
  1933 		}
  1917 	else
  1934 	else
  1918 		{
  1935 		{
  1919 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: endpoint descriptor not found"));
  1936 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETENDPOINTDESCRIPTORSIZE_DUP2, "  Error: endpoint descriptor not found");
  1920 		}
  1937 		}
  1921 	return r;
  1938 	return r;
  1922 	}
  1939 	}
  1923 
  1940 
  1924 
  1941 
  1934 	write operation, Kern::ThreadWrite(), when writing to the target buffer.
  1951 	write operation, Kern::ThreadWrite(), when writing to the target buffer.
  1935 */
  1952 */
  1936 EXPORT_C TInt DUsbClientController::GetDeviceQualifierDescriptor(DThread* aThread,
  1953 EXPORT_C TInt DUsbClientController::GetDeviceQualifierDescriptor(DThread* aThread,
  1937 																 TDes8& aDeviceQualifierDescriptor)
  1954 																 TDes8& aDeviceQualifierDescriptor)
  1938 	{
  1955 	{
  1939 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetDeviceQualifierDescriptor()"));
  1956 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETDEVICEQUALIFIERDESCRIPTOR, "DUsbClientController::GetDeviceQualifierDescriptor()" );
  1940 	return iDescriptors.GetDeviceQualifierDescriptorTC(aThread, aDeviceQualifierDescriptor);
  1957 	return iDescriptors.GetDeviceQualifierDescriptorTC(aThread, aDeviceQualifierDescriptor);
  1941 	}
  1958 	}
  1942 
  1959 
  1943 
  1960 
  1944 /** Sets a new Device_Qualifier descriptor. On a USB device which doesn't support high-speed
  1961 /** Sets a new Device_Qualifier descriptor. On a USB device which doesn't support high-speed
  1954 	the new descriptor was successfully set.
  1971 	the new descriptor was successfully set.
  1955 */
  1972 */
  1956 EXPORT_C TInt DUsbClientController::SetDeviceQualifierDescriptor(DThread* aThread,
  1973 EXPORT_C TInt DUsbClientController::SetDeviceQualifierDescriptor(DThread* aThread,
  1957 																 const TDes8& aDeviceQualifierDescriptor)
  1974 																 const TDes8& aDeviceQualifierDescriptor)
  1958 	{
  1975 	{
  1959 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetDeviceQualifierDescriptor()"));
  1976 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETDEVICEQUALIFIERDESCRIPTOR, "DUsbClientController::SetDeviceQualifierDescriptor()" );
  1960 	return iDescriptors.SetDeviceQualifierDescriptorTC(aThread, aDeviceQualifierDescriptor);
  1977 	return iDescriptors.SetDeviceQualifierDescriptorTC(aThread, aDeviceQualifierDescriptor);
  1961 	}
  1978 	}
  1962 
  1979 
  1963 
  1980 
  1964 /** Returns the current Other_Speed_Configuration descriptor. On a USB device which doesn't support high-speed
  1981 /** Returns the current Other_Speed_Configuration descriptor. On a USB device which doesn't support high-speed
  1973 	write operation, Kern::ThreadWrite(), when writing to the target buffer.
  1990 	write operation, Kern::ThreadWrite(), when writing to the target buffer.
  1974 */
  1991 */
  1975 EXPORT_C TInt DUsbClientController::GetOtherSpeedConfigurationDescriptor(DThread* aThread,
  1992 EXPORT_C TInt DUsbClientController::GetOtherSpeedConfigurationDescriptor(DThread* aThread,
  1976 																		 TDes8& aConfigurationDescriptor)
  1993 																		 TDes8& aConfigurationDescriptor)
  1977 	{
  1994 	{
  1978 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetOtherSpeedConfigurationDescriptor()"));
  1995 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETOTHERSPEEDCONFIGURATIONDESCRIPTOR, "DUsbClientController::GetOtherSpeedConfigurationDescriptor()" );
  1979 	return iDescriptors.GetOtherSpeedConfigurationDescriptorTC(aThread, aConfigurationDescriptor);
  1996 	return iDescriptors.GetOtherSpeedConfigurationDescriptorTC(aThread, aConfigurationDescriptor);
  1980 	}
  1997 	}
  1981 
  1998 
  1982 
  1999 
  1983 /** Sets a new Other_Speed_Configuration descriptor. On a USB device which doesn't support high-speed
  2000 /** Sets a new Other_Speed_Configuration descriptor. On a USB device which doesn't support high-speed
  1993 	the new descriptor was successfully set.
  2010 	the new descriptor was successfully set.
  1994 */
  2011 */
  1995 EXPORT_C TInt DUsbClientController::SetOtherSpeedConfigurationDescriptor(DThread* aThread,
  2012 EXPORT_C TInt DUsbClientController::SetOtherSpeedConfigurationDescriptor(DThread* aThread,
  1996 																		 const TDes8& aConfigurationDescriptor)
  2013 																		 const TDes8& aConfigurationDescriptor)
  1997 	{
  2014 	{
  1998 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetOtherSpeedConfigurationDescriptor()"));
  2015 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETOTHERSPEEDCONFIGURATIONDESCRIPTOR, "DUsbClientController::SetOtherSpeedConfigurationDescriptor()" );
  1999 	return iDescriptors.SetOtherSpeedConfigurationDescriptorTC(aThread, aConfigurationDescriptor);
  2016 	return iDescriptors.SetOtherSpeedConfigurationDescriptorTC(aThread, aConfigurationDescriptor);
  2000 	}
  2017 	}
  2001 
  2018 
  2002 
  2019 
  2003 /** Returns a block of all available non-standard (class-specific) interface descriptors for a specific
  2020 /** Returns a block of all available non-standard (class-specific) interface descriptors for a specific
  2014 */
  2031 */
  2015 EXPORT_C TInt DUsbClientController::GetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId,
  2032 EXPORT_C TInt DUsbClientController::GetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId,
  2016 																  TInt aSettingNum,
  2033 																  TInt aSettingNum,
  2017 																  TDes8& aInterfaceDescriptor)
  2034 																  TDes8& aInterfaceDescriptor)
  2018 	{
  2035 	{
  2019 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetCSInterfaceDescriptorBlock(x, 0x%08x, %d, y)",
  2036 	OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETCSINTERFACEDESCRIPTORBLOCK, "DUsbClientController::GetCSInterfaceDescriptorBlock(x, 0x%08x, %d, y)",
  2020 									aClientId, aSettingNum));
  2037                                     (TUint)aClientId, aSettingNum);
  2021 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2038 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2022 	if (ifcset < 0)
  2039 	if (ifcset < 0)
  2023 		{
  2040 		{
  2024 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  2041 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSINTERFACEDESCRIPTORBLOCK_DUP1, "D  Error: Interface not found from client ID");
  2025 		return KErrNotFound;
  2042 		return KErrNotFound;
  2026 		}
  2043 		}
  2027 	return iDescriptors.GetCSInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum);
  2044 	return iDescriptors.GetCSInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum);
  2028 	}
  2045 	}
  2029 
  2046 
  2046 */
  2063 */
  2047 EXPORT_C TInt DUsbClientController::SetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId,
  2064 EXPORT_C TInt DUsbClientController::SetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId,
  2048 																  TInt aSettingNum,
  2065 																  TInt aSettingNum,
  2049 																  const TDes8& aInterfaceDescriptor, TInt aSize)
  2066 																  const TDes8& aInterfaceDescriptor, TInt aSize)
  2050 	{
  2067 	{
  2051 	__KTRACE_OPT(KUSB,
  2068 	OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCSINTERFACEDESCRIPTORBLOCK, "DUsbClientController::SetCSInterfaceDescriptorBlock(x, 0x%08x, %d, y, %d)",
  2052 				 Kern::Printf("DUsbClientController::SetCSInterfaceDescriptorBlock(x, 0x%08x, %d, y, %d)",
  2069                               (TUint)aClientId, aSettingNum, aSize);
  2053 							  aClientId, aSettingNum, aSize));
       
  2054 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2070 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2055 	if (ifcset < 0)
  2071 	if (ifcset < 0)
  2056 		{
  2072 		{
  2057 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  2073 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSINTERFACEDESCRIPTORBLOCK_DUP1, "  Error: Interface not found from client ID");
  2058 		return KErrNotFound;
  2074 		return KErrNotFound;
  2059 		}
  2075 		}
  2060 	if (aSize < 2)
  2076 	if (aSize < 2)
  2061 		{
  2077 		{
  2062 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: aSize < 2 (%d)", aSize));
  2078 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSINTERFACEDESCRIPTORBLOCK_DUP2, "  Error: aSize < 2 (%d)", aSize);
  2063 		return KErrArgument;
  2079 		return KErrArgument;
  2064 		}
  2080 		}
  2065 	return iDescriptors.SetCSInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum, aSize);
  2081 	return iDescriptors.SetCSInterfaceDescriptorTC(aThread, aInterfaceDescriptor, ifcset, aSettingNum, aSize);
  2066 	}
  2082 	}
  2067 
  2083 
  2079 	write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2095 	write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2080 */
  2096 */
  2081 EXPORT_C TInt DUsbClientController::GetCSInterfaceDescriptorBlockSize(DThread* aThread, const DBase* aClientId,
  2097 EXPORT_C TInt DUsbClientController::GetCSInterfaceDescriptorBlockSize(DThread* aThread, const DBase* aClientId,
  2082 																	  TInt aSettingNum, TDes8& aSize)
  2098 																	  TInt aSettingNum, TDes8& aSize)
  2083 	{
  2099 	{
  2084 	__KTRACE_OPT(KUSB,
  2100 	OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETCSINTERFACEDESCRIPTORBLOCKSIZE, "DUsbClientController::GetCSInterfaceDescriptorBlockSize(x, 0x%08x, %d, y)",
  2085 				 Kern::Printf("DUsbClientController::GetCSInterfaceDescriptorBlockSize(x, 0x%08x, %d, y)",
  2101                               (TUint)aClientId, aSettingNum);
  2086 							  aClientId, aSettingNum));
       
  2087 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2102 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2088 	if (ifcset < 0)
  2103 	if (ifcset < 0)
  2089 		{
  2104 		{
  2090 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  2105 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSINTERFACEDESCRIPTORBLOCKSIZE_DUP1, "  Error: Interface not found from client ID");
  2091 		return KErrNotFound;
  2106 		return KErrNotFound;
  2092 		}
  2107 		}
  2093 	TInt s;
  2108 	TInt s;
  2094 	const TInt r = iDescriptors.GetCSInterfaceDescriptorSize(ifcset, aSettingNum, s);
  2109 	const TInt r = iDescriptors.GetCSInterfaceDescriptorSize(ifcset, aSettingNum, s);
  2095 	if (r == KErrNone)
  2110 	if (r == KErrNone)
  2097 		const TPtrC8 size(reinterpret_cast<const TUint8*>(&s), sizeof(s));
  2112 		const TPtrC8 size(reinterpret_cast<const TUint8*>(&s), sizeof(s));
  2098 		Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  2113 		Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  2099 		}
  2114 		}
  2100 	else
  2115 	else
  2101 		{
  2116 		{
  2102 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: cs interface descriptor not found"));
  2117 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSINTERFACEDESCRIPTORBLOCKSIZE_DUP2, "  Error: cs interface descriptor not found");
  2103 		}
  2118 		}
  2104 	return r;
  2119 	return r;
  2105 	}
  2120 	}
  2106 
  2121 
  2107 
  2122 
  2120 */
  2135 */
  2121 EXPORT_C TInt DUsbClientController::GetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId,
  2136 EXPORT_C TInt DUsbClientController::GetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId,
  2122 																 TInt aSettingNum, TInt aEndpointNum,
  2137 																 TInt aSettingNum, TInt aEndpointNum,
  2123 																 TDes8& aEndpointDescriptor)
  2138 																 TDes8& aEndpointDescriptor)
  2124 	{
  2139 	{
  2125 	__KTRACE_OPT(KUSB,
  2140 	OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCK, "DUsbClientController::GetCSEndpointDescriptorBlock(x, 0x%08x, %d, %d, y)",
  2126 				 Kern::Printf("DUsbClientController::GetCSEndpointDescriptorBlock(x, 0x%08x, %d, %d, y)",
  2141                               (TUint)aClientId, aSettingNum, aEndpointNum);
  2127 							  aClientId, aSettingNum, aEndpointNum));
       
  2128 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2142 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2129 	if (ifcset < 0)
  2143 	if (ifcset < 0)
  2130 		{
  2144 		{
  2131 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  2145 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCK_DUP1, "  Error: Interface not found from client ID");
  2132 		return KErrNotFound;
  2146 		return KErrNotFound;
  2133 		}
  2147 		}
  2134 	return iDescriptors.GetCSEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset,
  2148 	return iDescriptors.GetCSEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset,
  2135 												  aSettingNum, EpIdx2Addr(aEndpointNum));
  2149 												  aSettingNum, EpIdx2Addr(aEndpointNum));
  2136 	}
  2150 	}
  2155 */
  2169 */
  2156 EXPORT_C TInt DUsbClientController::SetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId,
  2170 EXPORT_C TInt DUsbClientController::SetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId,
  2157 																 TInt aSettingNum, TInt aEndpointNum,
  2171 																 TInt aSettingNum, TInt aEndpointNum,
  2158 																 const TDes8& aEndpointDescriptor, TInt aSize)
  2172 																 const TDes8& aEndpointDescriptor, TInt aSize)
  2159 	{
  2173 	{
  2160 	__KTRACE_OPT(KUSB,
  2174 	OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCSENDPOINTDESCRIPTORBLOCK, "DUsbClientController::SetCSEndpointDescriptorBlock(x, 0x%08x, %d, %d, y)",
  2161 				 Kern::Printf("DUsbClientController::SetCSEndpointDescriptorBlock(x, 0x%08x, %d, %d, y)",
  2175                               (TUint)aClientId, aSettingNum, aEndpointNum);
  2162 							  aClientId, aSettingNum, aEndpointNum));
       
  2163 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2176 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2164 	if (ifcset < 0)
  2177 	if (ifcset < 0)
  2165 		{
  2178 		{
  2166 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  2179 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSENDPOINTDESCRIPTORBLOCK_DUP1, "  Error: Interface not found from client ID");
  2167 		return KErrNotFound;
  2180 		return KErrNotFound;
  2168 		}
  2181 		}
  2169 	if (aSize < 2)
  2182 	if (aSize < 2)
  2170 		{
  2183 		{
  2171 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: aSize < 2 (%d)", aSize));
  2184 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETCSENDPOINTDESCRIPTORBLOCK_DUP2, "  Error: aSize < 2 (%d)", aSize);
  2172 		return KErrArgument;
  2185 		return KErrArgument;
  2173 		}
  2186 		}
  2174 	return iDescriptors.SetCSEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset,
  2187 	return iDescriptors.SetCSEndpointDescriptorTC(aThread, aEndpointDescriptor, ifcset,
  2175 												  aSettingNum, EpIdx2Addr(aEndpointNum), aSize);
  2188 												  aSettingNum, EpIdx2Addr(aEndpointNum), aSize);
  2176 	}
  2189 	}
  2191 */
  2204 */
  2192 EXPORT_C TInt DUsbClientController::GetCSEndpointDescriptorBlockSize(DThread* aThread, const DBase* aClientId,
  2205 EXPORT_C TInt DUsbClientController::GetCSEndpointDescriptorBlockSize(DThread* aThread, const DBase* aClientId,
  2193 																	 TInt aSettingNum, TInt aEndpointNum,
  2206 																	 TInt aSettingNum, TInt aEndpointNum,
  2194 																	 TDes8& aSize)
  2207 																	 TDes8& aSize)
  2195 	{
  2208 	{
  2196 	__KTRACE_OPT(KUSB,
  2209 	OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCKSIZE, "DUsbClientController::GetCSEndpointDescriptorBlockSize(x, 0x%08x, %d, %d, y)",
  2197 				 Kern::Printf("DUsbClientController::GetCSEndpointDescriptorBlockSize(x, 0x%08x, %d, %d, y)",
  2210                               (TUint)aClientId, aSettingNum, aEndpointNum);
  2198 							  aClientId, aSettingNum, aEndpointNum));
       
  2199 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2211 	const TInt ifcset = ClientId2InterfaceNumber(aClientId);
  2200 	if (ifcset < 0)
  2212 	if (ifcset < 0)
  2201 		{
  2213 		{
  2202 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface not found from client ID"));
  2214 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCKSIZE_DUP1, "  Error: Interface not found from client ID");
  2203 		return KErrNotFound;
  2215 		return KErrNotFound;
  2204 		}
  2216 		}
  2205 	TInt s;
  2217 	TInt s;
  2206 	const TInt r = iDescriptors.GetCSEndpointDescriptorSize(ifcset, aSettingNum,
  2218 	const TInt r = iDescriptors.GetCSEndpointDescriptorSize(ifcset, aSettingNum,
  2207 															EpIdx2Addr(aEndpointNum), s);
  2219 															EpIdx2Addr(aEndpointNum), s);
  2210 		const TPtrC8 size(reinterpret_cast<const TUint8*>(&s), sizeof(s));
  2222 		const TPtrC8 size(reinterpret_cast<const TUint8*>(&s), sizeof(s));
  2211 		Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  2223 		Kern::ThreadDesWrite(aThread, &aSize, size, 0);
  2212 		}
  2224 		}
  2213 	else
  2225 	else
  2214 		{
  2226 		{
  2215 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: cs endpoint descriptor not found"));
  2227 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_GETCSENDPOINTDESCRIPTORBLOCKSIZE_DUP2, "  Error: cs endpoint descriptor not found");
  2216 		}
  2228 		}
  2217 	return r;
  2229 	return r;
  2218 	}
  2230 	}
  2219 
  2231 
  2220 
  2232 
  2227 	@return The return value of the thread write operation, Kern::ThreadDesWrite(),
  2239 	@return The return value of the thread write operation, Kern::ThreadDesWrite(),
  2228 	when writing to the target buffer.
  2240 	when writing to the target buffer.
  2229 */
  2241 */
  2230 EXPORT_C TInt DUsbClientController::GetStringDescriptorLangId(DThread* aThread, TDes8& aLangId)
  2242 EXPORT_C TInt DUsbClientController::GetStringDescriptorLangId(DThread* aThread, TDes8& aLangId)
  2231 	{
  2243 	{
  2232 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetStringDescriptorLangId()"));
  2244 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETSTRINGDESCRIPTORLANGID, "DUsbClientController::GetStringDescriptorLangId()" );
  2233 	return iDescriptors.GetStringDescriptorLangIdTC(aThread, aLangId);
  2245 	return iDescriptors.GetStringDescriptorLangIdTC(aThread, aLangId);
  2234 	}
  2246 	}
  2235 
  2247 
  2236 
  2248 
  2237 /** Sets the string descriptor language ID (LANGID) code.
  2249 /** Sets the string descriptor language ID (LANGID) code.
  2240 
  2252 
  2241 	@return KErrNone.
  2253 	@return KErrNone.
  2242 */
  2254 */
  2243 EXPORT_C TInt DUsbClientController::SetStringDescriptorLangId(TUint16 aLangId)
  2255 EXPORT_C TInt DUsbClientController::SetStringDescriptorLangId(TUint16 aLangId)
  2244 	{
  2256 	{
  2245 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetStringDescriptorLangId()"));
  2257 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETSTRINGDESCRIPTORLANGID, "DUsbClientController::SetStringDescriptorLangId()" );
  2246 	return iDescriptors.SetStringDescriptorLangId(aLangId);
  2258 	return iDescriptors.SetStringDescriptorLangId(aLangId);
  2247 	}
  2259 	}
  2248 
  2260 
  2249 
  2261 
  2250 /** Returns the currently set Manufacturer string (which is referenced by the iManufacturer field in the device
  2262 /** Returns the currently set Manufacturer string (which is referenced by the iManufacturer field in the device
  2260 	@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return
  2272 	@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return
  2261 	value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2273 	value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2262 */
  2274 */
  2263 EXPORT_C TInt DUsbClientController::GetManufacturerStringDescriptor(DThread* aThread, TDes8& aString)
  2275 EXPORT_C TInt DUsbClientController::GetManufacturerStringDescriptor(DThread* aThread, TDes8& aString)
  2264 	{
  2276 	{
  2265 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetManufacturerStringDescriptor()"));
  2277 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETMANUFACTURERSTRINGDESCRIPTOR, "DUsbClientController::GetManufacturerStringDescriptor()" );
  2266 	return iDescriptors.GetManufacturerStringDescriptorTC(aThread, aString);
  2278 	return iDescriptors.GetManufacturerStringDescriptorTC(aThread, aString);
  2267 	}
  2279 	}
  2268 
  2280 
  2269 
  2281 
  2270 /** Sets a new Manufacturer string in the Manufacturer string descriptor (which is referenced by the
  2282 /** Sets a new Manufacturer string in the Manufacturer string descriptor (which is referenced by the
  2281 	return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong,
  2293 	return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong,
  2282 	KErrNone if new string descriptor successfully set.
  2294 	KErrNone if new string descriptor successfully set.
  2283 */
  2295 */
  2284 EXPORT_C TInt DUsbClientController::SetManufacturerStringDescriptor(DThread* aThread, const TDes8& aString)
  2296 EXPORT_C TInt DUsbClientController::SetManufacturerStringDescriptor(DThread* aThread, const TDes8& aString)
  2285 	{
  2297 	{
  2286 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetManufacturerStringDescriptor()"));
  2298 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETMANUFACTURERSTRINGDESCRIPTOR, "DUsbClientController::SetManufacturerStringDescriptor()" );
  2287 	return iDescriptors.SetManufacturerStringDescriptorTC(aThread, aString);
  2299 	return iDescriptors.SetManufacturerStringDescriptorTC(aThread, aString);
  2288 	}
  2300 	}
  2289 
  2301 
  2290 
  2302 
  2291 /** Removes (deletes) the Manufacturer string descriptor (which is referenced by the
  2303 /** Removes (deletes) the Manufacturer string descriptor (which is referenced by the
  2293 
  2305 
  2294 	@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found
  2306 	@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found
  2295 */
  2307 */
  2296 EXPORT_C TInt DUsbClientController::RemoveManufacturerStringDescriptor()
  2308 EXPORT_C TInt DUsbClientController::RemoveManufacturerStringDescriptor()
  2297 	{
  2309 	{
  2298 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RemoveManufacturerStringDescriptor()"));
  2310 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REMOVEMANUFACTURERSTRINGDESCRIPTOR, "DUsbClientController::RemoveManufacturerStringDescriptor()" );
  2299 	return iDescriptors.RemoveManufacturerStringDescriptor();
  2311 	return iDescriptors.RemoveManufacturerStringDescriptor();
  2300 	}
  2312 	}
  2301 
  2313 
  2302 
  2314 
  2303 /** Returns the currently set Product string (which is referenced by the iProduct field in the device
  2315 /** Returns the currently set Product string (which is referenced by the iProduct field in the device
  2313 	@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return
  2325 	@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return
  2314 	value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2326 	value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2315 */
  2327 */
  2316 EXPORT_C TInt DUsbClientController::GetProductStringDescriptor(DThread* aThread, TDes8& aString)
  2328 EXPORT_C TInt DUsbClientController::GetProductStringDescriptor(DThread* aThread, TDes8& aString)
  2317 	{
  2329 	{
  2318 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetProductStringDescriptor()"));
  2330 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETPRODUCTSTRINGDESCRIPTOR, "DUsbClientController::GetProductStringDescriptor()" );
  2319 	return iDescriptors.GetProductStringDescriptorTC(aThread, aString);
  2331 	return iDescriptors.GetProductStringDescriptorTC(aThread, aString);
  2320 	}
  2332 	}
  2321 
  2333 
  2322 
  2334 
  2323 /** Sets a new Product string in the Product string descriptor (which is referenced by the iProduct field in
  2335 /** Sets a new Product string in the Product string descriptor (which is referenced by the iProduct field in
  2334 	return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong,
  2346 	return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong,
  2335 	KErrNone if new string descriptor successfully set.
  2347 	KErrNone if new string descriptor successfully set.
  2336 */
  2348 */
  2337 EXPORT_C TInt DUsbClientController::SetProductStringDescriptor(DThread* aThread, const TDes8& aString)
  2349 EXPORT_C TInt DUsbClientController::SetProductStringDescriptor(DThread* aThread, const TDes8& aString)
  2338 	{
  2350 	{
  2339 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetProductStringDescriptor()"));
  2351 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETPRODUCTSTRINGDESCRIPTOR, "DUsbClientController::SetProductStringDescriptor()" );
  2340 	return iDescriptors.SetProductStringDescriptorTC(aThread, aString);
  2352 	return iDescriptors.SetProductStringDescriptorTC(aThread, aString);
  2341 	}
  2353 	}
  2342 
  2354 
  2343 
  2355 
  2344 /** Removes (deletes) the Product string descriptor (which is referenced by the
  2356 /** Removes (deletes) the Product string descriptor (which is referenced by the
  2346 
  2358 
  2347 	@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found
  2359 	@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found
  2348 */
  2360 */
  2349 EXPORT_C TInt DUsbClientController::RemoveProductStringDescriptor()
  2361 EXPORT_C TInt DUsbClientController::RemoveProductStringDescriptor()
  2350 	{
  2362 	{
  2351 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RemoveProductStringDescriptor()"));
  2363 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REMOVEPRODUCTSTRINGDESCRIPTOR, "DUsbClientController::RemoveProductStringDescriptor()" );
  2352 	return iDescriptors.RemoveProductStringDescriptor();
  2364 	return iDescriptors.RemoveProductStringDescriptor();
  2353 	}
  2365 	}
  2354 
  2366 
  2355 
  2367 
  2356 /** Returns the currently set SerialNumber string (which is referenced by the iSerialNumber field in the device
  2368 /** Returns the currently set SerialNumber string (which is referenced by the iSerialNumber field in the device
  2366 	@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return
  2378 	@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return
  2367 	value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2379 	value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2368 */
  2380 */
  2369 EXPORT_C TInt DUsbClientController::GetSerialNumberStringDescriptor(DThread* aThread, TDes8& aString)
  2381 EXPORT_C TInt DUsbClientController::GetSerialNumberStringDescriptor(DThread* aThread, TDes8& aString)
  2370 	{
  2382 	{
  2371 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetSerialNumberStringDescriptor()"));
  2383 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETSERIALNUMBERSTRINGDESCRIPTOR, "DUsbClientController::GetSerialNumberStringDescriptor()" );
  2372 	return iDescriptors.GetSerialNumberStringDescriptorTC(aThread, aString);
  2384 	return iDescriptors.GetSerialNumberStringDescriptorTC(aThread, aString);
  2373 	}
  2385 	}
  2374 
  2386 
  2375 
  2387 
  2376 /** Sets a new SerialNumber string in the SerialNumber string descriptor (which is referenced by the
  2388 /** Sets a new SerialNumber string in the SerialNumber string descriptor (which is referenced by the
  2387 	return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong,
  2399 	return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong,
  2388 	KErrNone if new string descriptor successfully set.
  2400 	KErrNone if new string descriptor successfully set.
  2389 */
  2401 */
  2390 EXPORT_C TInt DUsbClientController::SetSerialNumberStringDescriptor(DThread* aThread, const TDes8& aString)
  2402 EXPORT_C TInt DUsbClientController::SetSerialNumberStringDescriptor(DThread* aThread, const TDes8& aString)
  2391 	{
  2403 	{
  2392 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetSerialNumberStringDescriptor()"));
  2404 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETSERIALNUMBERSTRINGDESCRIPTOR, "DUsbClientController::SetSerialNumberStringDescriptor()" );
  2393 	return iDescriptors.SetSerialNumberStringDescriptorTC(aThread, aString);
  2405 	return iDescriptors.SetSerialNumberStringDescriptorTC(aThread, aString);
  2394 	}
  2406 	}
  2395 
  2407 
  2396 
  2408 
  2397 /** Removes (deletes) the Serial Number string descriptor (which is referenced by the
  2409 /** Removes (deletes) the Serial Number string descriptor (which is referenced by the
  2399 
  2411 
  2400 	@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found
  2412 	@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found
  2401 */
  2413 */
  2402 EXPORT_C TInt DUsbClientController::RemoveSerialNumberStringDescriptor()
  2414 EXPORT_C TInt DUsbClientController::RemoveSerialNumberStringDescriptor()
  2403 	{
  2415 	{
  2404 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RemoveSerialNumberStringDescriptor()"));
  2416 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REMOVESERIALNUMBERSTRINGDESCRIPTOR, "DUsbClientController::RemoveSerialNumberStringDescriptor()" );
  2405 	return iDescriptors.RemoveSerialNumberStringDescriptor();
  2417 	return iDescriptors.RemoveSerialNumberStringDescriptor();
  2406 	}
  2418 	}
  2407 
  2419 
  2408 
  2420 
  2409 /** Returns the currently set Configuration string (which is referenced by the iConfiguration field in the
  2421 /** Returns the currently set Configuration string (which is referenced by the iConfiguration field in the
  2419 	@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return
  2431 	@return KErrNotFound if the string descriptor couldn't be found (PIL internal error), otherwise the return
  2420 	value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2432 	value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2421 */
  2433 */
  2422 EXPORT_C TInt DUsbClientController::GetConfigurationStringDescriptor(DThread* aThread, TDes8& aString)
  2434 EXPORT_C TInt DUsbClientController::GetConfigurationStringDescriptor(DThread* aThread, TDes8& aString)
  2423 	{
  2435 	{
  2424 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetConfigurationStringDescriptor()"));
  2436 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_GETCONFIGURATIONSTRINGDESCRIPTOR, "DUsbClientController::GetConfigurationStringDescriptor()" );
  2425 	return iDescriptors.GetConfigurationStringDescriptorTC(aThread, aString);
  2437 	return iDescriptors.GetConfigurationStringDescriptorTC(aThread, aString);
  2426 	}
  2438 	}
  2427 
  2439 
  2428 
  2440 
  2429 /** Sets a new Configuration string in the Configuration string descriptor (which is referenced by the
  2441 /** Sets a new Configuration string in the Configuration string descriptor (which is referenced by the
  2440 	return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong,
  2452 	return value of the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong,
  2441 	KErrNone if new string descriptor successfully set.
  2453 	KErrNone if new string descriptor successfully set.
  2442 */
  2454 */
  2443 EXPORT_C TInt DUsbClientController::SetConfigurationStringDescriptor(DThread* aThread, const TDes8& aString)
  2455 EXPORT_C TInt DUsbClientController::SetConfigurationStringDescriptor(DThread* aThread, const TDes8& aString)
  2444 	{
  2456 	{
  2445 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetConfigurationStringDescriptor()"));
  2457 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETCONFIGURATIONSTRINGDESCRIPTOR, "DUsbClientController::SetConfigurationStringDescriptor()" );
  2446 	return iDescriptors.SetConfigurationStringDescriptorTC(aThread, aString);
  2458 	return iDescriptors.SetConfigurationStringDescriptorTC(aThread, aString);
  2447 	}
  2459 	}
  2448 
  2460 
  2449 
  2461 
  2450 /** Removes (deletes) the Configuration string descriptor (which is referenced by the
  2462 /** Removes (deletes) the Configuration string descriptor (which is referenced by the
  2452 
  2464 
  2453 	@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found.
  2465 	@return KErrNone if successful, KErrNotFound if the string descriptor couldn't be found.
  2454 */
  2466 */
  2455 EXPORT_C TInt DUsbClientController::RemoveConfigurationStringDescriptor()
  2467 EXPORT_C TInt DUsbClientController::RemoveConfigurationStringDescriptor()
  2456 	{
  2468 	{
  2457 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RemoveConfigurationStringDescriptor()"));
  2469 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REMOVECONFIGURATIONSTRINGDESCRIPTOR, "DUsbClientController::RemoveConfigurationStringDescriptor()" );
  2458 	return iDescriptors.RemoveConfigurationStringDescriptor();
  2470 	return iDescriptors.RemoveConfigurationStringDescriptor();
  2459 	}
  2471 	}
  2460 
  2472 
  2461 
  2473 
  2462 /** Copies the string descriptor at the specified index in the string descriptor array into
  2474 /** Copies the string descriptor at the specified index in the string descriptor array into
  2470 	@return KErrNone if successful, KErrNotFound if no string descriptor exists at the specified index, or the
  2482 	@return KErrNone if successful, KErrNotFound if no string descriptor exists at the specified index, or the
  2471 	return value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2483 	return value of the thread write operation, Kern::ThreadWrite(), when writing to the target buffer.
  2472 */
  2484 */
  2473 EXPORT_C TInt DUsbClientController::GetStringDescriptor(DThread* aThread, TUint8 aIndex, TDes8& aString)
  2485 EXPORT_C TInt DUsbClientController::GetStringDescriptor(DThread* aThread, TUint8 aIndex, TDes8& aString)
  2474 	{
  2486 	{
  2475 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::GetStringDescriptor(%d)", aIndex));
  2487 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_GETSTRINGDESCRIPTOR, "DUsbClientController::GetStringDescriptor(%d)", aIndex);
       
  2488 	
  2476 	return iDescriptors.GetStringDescriptorTC(aThread, aIndex, aString);
  2489 	return iDescriptors.GetStringDescriptorTC(aThread, aIndex, aString);
  2477 	}
  2490 	}
  2478 
  2491 
  2479 
  2492 
  2480 /** Sets the aString argument to be a string descriptor at the specified index in the string
  2493 /** Sets the aString argument to be a string descriptor at the specified index in the string
  2489 	to store the new string (an existing descriptor at that index will be preserved), or the return value of
  2502 	to store the new string (an existing descriptor at that index will be preserved), or the return value of
  2490 	the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong.
  2503 	the thread read operation, Kern::ThreadRead(), if reading from the source buffer goes wrong.
  2491 */
  2504 */
  2492 EXPORT_C TInt DUsbClientController::SetStringDescriptor(DThread* aThread, TUint8 aIndex, const TDes8& aString)
  2505 EXPORT_C TInt DUsbClientController::SetStringDescriptor(DThread* aThread, TUint8 aIndex, const TDes8& aString)
  2493 	{
  2506 	{
  2494 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetStringDescriptor(%d)", aIndex));
  2507 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETSTRINGDESCRIPTOR, "DUsbClientController::SetStringDescriptor(%d)", aIndex);
       
  2508 	
  2495 	return iDescriptors.SetStringDescriptorTC(aThread, aIndex, aString);
  2509 	return iDescriptors.SetStringDescriptorTC(aThread, aIndex, aString);
  2496 	}
  2510 	}
  2497 
  2511 
  2498 
  2512 
  2499 /** Removes (deletes) the string descriptor at the specified index in the string descriptor array.
  2513 /** Removes (deletes) the string descriptor at the specified index in the string descriptor array.
  2502 
  2516 
  2503 	@return KErrNone if successful, KErrNotFound if no string descriptor exists at the specified index.
  2517 	@return KErrNone if successful, KErrNotFound if no string descriptor exists at the specified index.
  2504 */
  2518 */
  2505 EXPORT_C TInt DUsbClientController::RemoveStringDescriptor(TUint8 aIndex)
  2519 EXPORT_C TInt DUsbClientController::RemoveStringDescriptor(TUint8 aIndex)
  2506 	{
  2520 	{
  2507 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RemoveStringDescriptor(%d)", aIndex));
  2521 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_REMOVESTRINGDESCRIPTOR, "DUsbClientController::RemoveStringDescriptor(%d)", aIndex);
       
  2522 	
  2508 	return iDescriptors.RemoveStringDescriptor(aIndex);
  2523 	return iDescriptors.RemoveStringDescriptor(aIndex);
  2509 	}
  2524 	}
  2510 
  2525 
  2511 
  2526 
  2512 /** Allocates an endpoint resource.
  2527 /** Allocates an endpoint resource.
  2523 	cannot be allocated. KErrArgument if the endpoint number is invalid.
  2538 	cannot be allocated. KErrArgument if the endpoint number is invalid.
  2524 */
  2539 */
  2525 EXPORT_C TInt DUsbClientController::AllocateEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum,
  2540 EXPORT_C TInt DUsbClientController::AllocateEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum,
  2526 															 TUsbcEndpointResource aResource)
  2541 															 TUsbcEndpointResource aResource)
  2527 	{
  2542 	{
  2528 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::AllocateEndpointResource()"));
  2543 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ALLOCATEENDPOINTRESOURCE, "DUsbClientController::AllocateEndpointResource()" );
  2529 	return AllocateEndpointResource(aEndpointNum, aResource);
  2544 	return AllocateEndpointResource(aEndpointNum, aResource);
  2530 	}
  2545 	}
  2531 
  2546 
  2532 
  2547 
  2533 /** Deallocates (frees) an endpoint resource.
  2548 /** Deallocates (frees) an endpoint resource.
  2542 	does not support the resource requested. KErrArgument if the endpoint number is invalid.
  2557 	does not support the resource requested. KErrArgument if the endpoint number is invalid.
  2543 */
  2558 */
  2544 EXPORT_C TInt DUsbClientController::DeAllocateEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum,
  2559 EXPORT_C TInt DUsbClientController::DeAllocateEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum,
  2545 															   TUsbcEndpointResource aResource)
  2560 															   TUsbcEndpointResource aResource)
  2546 	{
  2561 	{
  2547 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeAllocateEndpointResource()"));
  2562 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEALLOCATEENDPOINTRESOURCE, "DUsbClientController::DeAllocateEndpointResource()" );
  2548 	return DeAllocateEndpointResource(aEndpointNum, aResource);
  2563 	return DeAllocateEndpointResource(aEndpointNum, aResource);
  2549 	}
  2564 	}
  2550 
  2565 
  2551 
  2566 
  2552 /** Queries the use of and endpoint resource.
  2567 /** Queries the use of and endpoint resource.
  2562 	during the execution of the function.
  2577 	during the execution of the function.
  2563 */
  2578 */
  2564 EXPORT_C TBool DUsbClientController::QueryEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum,
  2579 EXPORT_C TBool DUsbClientController::QueryEndpointResource(const DBase* /*aClientId*/, TInt aEndpointNum,
  2565 														   TUsbcEndpointResource aResource)
  2580 														   TUsbcEndpointResource aResource)
  2566 	{
  2581 	{
  2567 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::QueryEndpointResource()"));
  2582 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_QUERYENDPOINTRESOURCE, "DUsbClientController::QueryEndpointResource()" );
  2568 	return QueryEndpointResource(aEndpointNum, aResource);
  2583 	return QueryEndpointResource(aEndpointNum, aResource);
  2569 	}
  2584 	}
  2570 
  2585 
  2571 
  2586 
  2572 EXPORT_C TInt DUsbClientController::EndpointPacketSize(const DBase* aClientId, TInt aEndpointNum)
  2587 EXPORT_C TInt DUsbClientController::EndpointPacketSize(const DBase* aClientId, TInt aEndpointNum)
  2573 	{
  2588 	{
  2574 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EndpointPacketSize(0x%08x, %d)",
  2589 	OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE, "DUsbClientController::EndpointPacketSize(0x%08x, %d)",
  2575 									aClientId, aEndpointNum));
  2590                                     (TUint)aClientId, aEndpointNum);
  2576 
       
  2577 	const TUsbcInterfaceSet* const ifcset_ptr = ClientId2InterfacePointer(aClientId);
  2591 	const TUsbcInterfaceSet* const ifcset_ptr = ClientId2InterfacePointer(aClientId);
  2578 	if (!ifcset_ptr)
  2592 	if (!ifcset_ptr)
  2579 		{
  2593 		{
  2580 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: interface or clientid not found"));
  2594 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP1, "  Error: interface or clientid not found");
  2581 		return -1;
  2595 		return -1;
  2582 		}
  2596 		}
  2583 	const TUsbcInterface* const ifc_ptr = ifcset_ptr->iInterfaces[ifcset_ptr->iCurrentInterface];
  2597 	const TUsbcInterface* const ifc_ptr = ifcset_ptr->iInterfaces[ifcset_ptr->iCurrentInterface];
  2584 	const RPointerArray<TUsbcLogicalEndpoint>& ep_array = ifc_ptr->iEndpoints;
  2598 	const RPointerArray<TUsbcLogicalEndpoint>& ep_array = ifc_ptr->iEndpoints;
  2585 	const TInt n = ep_array.Count();
  2599 	const TInt n = ep_array.Count();
  2586 	for (TInt i = 0; i < n; i++)
  2600 	for (TInt i = 0; i < n; i++)
  2587 		{
  2601 		{
  2588 		const TUsbcLogicalEndpoint* const ep = ep_array[i];
  2602 		const TUsbcLogicalEndpoint* const ep = ep_array[i];
  2589 		if (EpAddr2Idx(ep->iPEndpoint->iEndpointAddr) == static_cast<TUint>(aEndpointNum))
  2603 		if (EpAddr2Idx(ep->iPEndpoint->iEndpointAddr) == static_cast<TUint>(aEndpointNum))
  2590 			{
  2604 			{
  2591 			__KTRACE_OPT(KUSB, Kern::Printf("  Endpoint packet sizes: FS = %d  HS = %d",
  2605 		    OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP2, "  Endpoint packet sizes: FS = %d  HS = %d",
  2592 											ep->iEpSize_Fs, ep->iEpSize_Hs));
  2606                                             ep->iEpSize_Fs, ep->iEpSize_Hs);
  2593 			const TInt size = iHighSpeed ? ep->iEpSize_Hs : ep->iEpSize_Fs;
  2607 			const TInt size = iHighSpeed ? ep->iEpSize_Hs : ep->iEpSize_Fs;
  2594 			__KTRACE_OPT(KUSB, Kern::Printf("  Returning %d", size));
  2608 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP3, "  Returning %d", size);
  2595 			return size;
  2609 			return size;
  2596 			}
  2610 			}
  2597 		}
  2611 		}
  2598 	__KTRACE_OPT(KPANIC, Kern::Printf("  Error: endpoint not found"));
  2612     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ENDPOINTPACKETSIZE_DUP4, "  Error: endpoint not found");
  2599 	return -1;
  2613 	return -1;
  2600 	}
  2614 	}
  2601 
  2615 
  2602 
  2616 
  2603 //
  2617 //
  2604 // === USB Controller member function implementations - LDD API (public) ===========================
  2618 // === USB Controller member function implementations - LDD API (public) ===========================
  2605 //
  2619 //
  2606 
  2620 
  2607 EXPORT_C TBool DUsbClientController::CurrentlyUsingHighSpeed()
  2621 EXPORT_C TBool DUsbClientController::CurrentlyUsingHighSpeed()
  2608 	{
  2622 	{
  2609 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CurrentlyUsingHighSpeed()"));
  2623 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CURRENTLYUSINGHIGHSPEED, "DUsbClientController::CurrentlyUsingHighSpeed()" );
  2610 	return EFalse;
  2624 	return EFalse;
  2611 	}
  2625 	}
  2612 
  2626 
  2613 
  2627 
  2614 //
  2628 //
  2624 
  2638 
  2625 	@publishedPartner @released
  2639 	@publishedPartner @released
  2626 */
  2640 */
  2627 DUsbClientController* DUsbClientController::RegisterUdc(TInt aUdc)
  2641 DUsbClientController* DUsbClientController::RegisterUdc(TInt aUdc)
  2628 	{
  2642 	{
  2629 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RegisterUdc()"));
  2643 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_REGISTERUDC, "DUsbClientController::RegisterUdc()" );
  2630 	if (aUdc < 0 || aUdc > (KUsbcMaxUdcs - 1))
  2644 	if (aUdc < 0 || aUdc > (KUsbcMaxUdcs - 1))
  2631 		{
  2645 		{
  2632 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: aUdc out of range (%d)", aUdc));
  2646 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_REGISTERUDC_DUP1, "  Error: aUdc out of range (%d)", aUdc);
  2633 		return NULL;
  2647 		return NULL;
  2634 		}
  2648 		}
  2635 	return UsbClientController[aUdc] = this;
  2649 	return UsbClientController[aUdc] = this;
  2636 	}
  2650 	}
  2637 
  2651 
  2710 												TUsbcStringDescriptor* aProduct,
  2724 												TUsbcStringDescriptor* aProduct,
  2711 												TUsbcStringDescriptor* aSerialNum,
  2725 												TUsbcStringDescriptor* aSerialNum,
  2712 												TUsbcStringDescriptor* aConfig,
  2726 												TUsbcStringDescriptor* aConfig,
  2713                                                 TUsbcOtgDescriptor* aOtgDesc)
  2727                                                 TUsbcOtgDescriptor* aOtgDesc)
  2714 	{
  2728 	{
  2715 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::InitialiseBaseClass()"));
  2729 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS, "DUsbClientController::InitialiseBaseClass()" );
  2716 	// We don't want the host to see us (at least not yet):
  2730 	// We don't want the host to see us (at least not yet):
  2717 	UsbDisconnect();
  2731 	UsbDisconnect();
  2718 
  2732 
  2719 	// Initialise USB descriptor pool
  2733 	// Initialise USB descriptor pool
  2720 	if (iDescriptors.Init(aDeviceDesc, aConfigDesc, aLangId, aManufacturer, aProduct,
  2734 	if (iDescriptors.Init(aDeviceDesc, aConfigDesc, aLangId, aManufacturer, aProduct,
  2721 						  aSerialNum, aConfig, aOtgDesc) !=	KErrNone)
  2735 						  aSerialNum, aConfig, aOtgDesc) !=	KErrNone)
  2722 		{
  2736 		{
  2723 		__KTRACE_OPT(KUSB, Kern::Printf("  Error: Descriptor initialization failed"));
  2737 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP1, "  Error: Descriptor initialization failed");
  2724 		return EFalse;
  2738 		return EFalse;
  2725 		}
  2739 		}
  2726 
  2740 
  2727 	if (aOtgDesc)
  2741 	if (aOtgDesc)
  2728 		{
  2742 		{
  2759 	TUsbcEndpointInfo info(KUsbEpTypeControl, KUsbEpDirOut, 0);
  2773 	TUsbcEndpointInfo info(KUsbEpTypeControl, KUsbEpDirOut, 0);
  2760 	TUsbcLogicalEndpoint* ep = NULL;
  2774 	TUsbcLogicalEndpoint* ep = NULL;
  2761 
  2775 
  2762 	// Initialise the array of physical endpoints
  2776 	// Initialise the array of physical endpoints
  2763 	iDeviceTotalEndpoints = DeviceTotalEndpoints();
  2777 	iDeviceTotalEndpoints = DeviceTotalEndpoints();
  2764 	__KTRACE_OPT(KUSB, Kern::Printf("  DeviceTotalEndpoints: %d", iDeviceTotalEndpoints));
  2778     OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP2, "  DeviceTotalEndpoints: %d", iDeviceTotalEndpoints);
  2765 	// KUsbcMaxEndpoints doesn't include ep 0
  2779 	// KUsbcMaxEndpoints doesn't include ep 0
  2766 	if ((iDeviceTotalEndpoints > (KUsbcMaxEndpoints + 2)) ||
  2780 	if ((iDeviceTotalEndpoints > (KUsbcMaxEndpoints + 2)) ||
  2767 		((iDeviceTotalEndpoints * sizeof(TUsbcPhysicalEndpoint)) > sizeof(iRealEndpoints)))
  2781 		((iDeviceTotalEndpoints * sizeof(TUsbcPhysicalEndpoint)) > sizeof(iRealEndpoints)))
  2768 		{
  2782 		{
  2769 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: too many endpoints! (change KUsbcMaxEndpoints: %d)",
  2783 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP3, "  Error: too many endpoints! (change KUsbcMaxEndpoints: %d)",
  2770 										  KUsbcMaxEndpoints));
  2784                                           KUsbcMaxEndpoints);
  2771 		goto exit_1;
  2785 		goto exit_1;
  2772 		}
  2786 		}
  2773 	caps = DeviceEndpointCaps();
  2787 	caps = DeviceEndpointCaps();
  2774 	for (TInt i = 0; i < iDeviceTotalEndpoints; ++i)
  2788 	for (TInt i = 0; i < iDeviceTotalEndpoints; ++i)
  2775 		{
  2789 		{
  2776 		iRealEndpoints[i].iEndpointAddr = EpIdx2Addr(i);
  2790 		iRealEndpoints[i].iEndpointAddr = EpIdx2Addr(i);
  2777 		__KTRACE_OPT(KUSB, Kern::Printf("  Caps[%02d] - iTypes: 0x%08x iSizes: 0x%08x",
  2791 		OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP4, "  Caps[%02d] - iTypes: 0x%08x iSizes: 0x%08x",
  2778 										i, caps[i].iTypesAndDir, caps[i].iSizes));
  2792                                         i, caps[i].iTypesAndDir, caps[i].iSizes);
  2779 		iRealEndpoints[i].iCaps = caps[i];
  2793 		iRealEndpoints[i].iCaps = caps[i];
  2780 		iRealEndpoints[i].iCaps.iReserved[0] = 0;
  2794 		iRealEndpoints[i].iCaps.iReserved[0] = 0;
  2781 		iRealEndpoints[i].iCaps.iReserved[1] = 0;
  2795 		iRealEndpoints[i].iCaps.iReserved[1] = 0;
  2782 		if ((i > 1) && (caps[i].iTypesAndDir != KUsbEpNotAvailable))
  2796 		if ((i > 1) && (caps[i].iTypesAndDir != KUsbEpNotAvailable))
  2783 			{
  2797 			{
  2784 			__KTRACE_OPT(KUSB, Kern::Printf("  --> UsableEndpoint: #%d", i));
  2798 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP5, "  --> UsableEndpoint: #%d", i);
  2785 			iDeviceUsableEndpoints++;
  2799 			iDeviceUsableEndpoints++;
  2786 			}
  2800 			}
  2787 		}
  2801 		}
  2788 
  2802 
  2789 	// Initialise Ep0 structures (logical endpoints are numbered 1..KMaxEndpointsPerClient,
  2803 	// Initialise Ep0 structures (logical endpoints are numbered 1..KMaxEndpointsPerClient,
  2790 	// and virtual 0 is real 0):
  2804 	// and virtual 0 is real 0):
  2791 	// -- Ep0 OUT
  2805 	// -- Ep0 OUT
  2792 	iEp0MaxPacketSize = caps[0].MaxPacketSize();
  2806 	iEp0MaxPacketSize = caps[0].MaxPacketSize();
  2793 	__KTRACE_OPT(KUSB, Kern::Printf("  using Ep0 maxpacketsize of %d bytes", iEp0MaxPacketSize));
  2807     OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP6, "  using Ep0 maxpacketsize of %d bytes", iEp0MaxPacketSize);
  2794 	info.iSize = iEp0MaxPacketSize;
  2808 	info.iSize = iEp0MaxPacketSize;
  2795 	ep = new TUsbcLogicalEndpoint(this, 0, info, NULL, &iRealEndpoints[KEp0_Out]);
  2809 	ep = new TUsbcLogicalEndpoint(this, 0, info, NULL, &iRealEndpoints[KEp0_Out]);
  2796 	if (!ep)
  2810 	if (!ep)
  2797 		{
  2811 		{
  2798 		goto exit_1;
  2812 		goto exit_1;
  2799 		}
  2813 		}
  2800 	__KTRACE_OPT(KUSB, Kern::Printf("  creating ep: mapping real ep %d --> logical ep 0", KEp0_Out));
  2814     OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP7, "  creating ep: mapping real ep %d --> logical ep 0", KEp0_Out);
  2801 	iRealEndpoints[KEp0_Out].iLEndpoint = ep;
  2815 	iRealEndpoints[KEp0_Out].iLEndpoint = ep;
  2802 	// -- Ep0 IN
  2816 	// -- Ep0 IN
  2803 	info.iDir = KUsbEpDirIn;
  2817 	info.iDir = KUsbEpDirIn;
  2804 	ep = new TUsbcLogicalEndpoint(this, 0, info, NULL, &iRealEndpoints[KEp0_In]);
  2818 	ep = new TUsbcLogicalEndpoint(this, 0, info, NULL, &iRealEndpoints[KEp0_In]);
  2805 	if (!ep)
  2819 	if (!ep)
  2806 		{
  2820 		{
  2807 		goto exit_2;
  2821 		goto exit_2;
  2808 		}
  2822 		}
  2809 	__KTRACE_OPT(KUSB, Kern::Printf("  creating ep: mapping real ep %d --> logical ep 0", KEp0_In));
  2823     OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP8, "  creating ep: mapping real ep %d --> logical ep 0", KEp0_In);
  2810 	iRealEndpoints[KEp0_In].iLEndpoint = ep;
  2824 	iRealEndpoints[KEp0_In].iLEndpoint = ep;
  2811 
  2825 
  2812 	// Create the power handler
  2826 	// Create the power handler
  2813 	iPowerHandler = new DUsbcPowerHandler(this);
  2827 	iPowerHandler = new DUsbcPowerHandler(this);
  2814 	if (!iPowerHandler)
  2828 	if (!iPowerHandler)
  2822 	if (!iTrackDeviceState)
  2836 	if (!iTrackDeviceState)
  2823 		{
  2837 		{
  2824 		// There shouldn't really be any PSL that doesn't support Device State
  2838 		// There shouldn't really be any PSL that doesn't support Device State
  2825 		// tracking, but we cannot simply enforce it as we have to preserve
  2839 		// tracking, but we cannot simply enforce it as we have to preserve
  2826 		// backwards compatibility.
  2840 		// backwards compatibility.
  2827 		__KTRACE_OPT(KUSB, Kern::Printf("  Warning: USB Device State tracking not supported by PSL"));
  2841 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_INITIALISEBASECLASS_DUP9, "  Warning: USB Device State tracking not supported by PSL");
  2828 		}
  2842 		}
  2829 
  2843 
  2830 	return ETrue;
  2844 	return ETrue;
  2831 
  2845 
  2832  exit_3:
  2846  exit_3:
  2899 	  iUsbResetDeferred(EFalse),
  2913 	  iUsbResetDeferred(EFalse),
  2900 	  iEnablePullUpOnDPlus(NULL),
  2914 	  iEnablePullUpOnDPlus(NULL),
  2901 	  iDisablePullUpOnDPlus(NULL),
  2915 	  iDisablePullUpOnDPlus(NULL),
  2902 	  iOtgContext(NULL)
  2916 	  iOtgContext(NULL)
  2903 	{
  2917 	{
  2904 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DUsbClientController()"));
  2918     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DUSBCLIENTCONTROLLER_CONS, "DUsbClientController::DUsbClientController()" );
  2905 
  2919 
  2906 #ifndef SEPARATE_USB_DFC_QUEUE
  2920 #ifndef SEPARATE_USB_DFC_QUEUE
  2907 	iPowerUpDfc.SetDfcQ(Kern::DfcQue0());
  2921 	iPowerUpDfc.SetDfcQ(Kern::DfcQue0());
  2908   	iPowerDownDfc.SetDfcQ(Kern::DfcQue0());
  2922   	iPowerDownDfc.SetDfcQ(Kern::DfcQue0());
  2909 #endif // SEPARATE_USB_DFC_QUEUE
  2923 #endif // SEPARATE_USB_DFC_QUEUE
  2925 
  2939 
  2926 	@publishedPartner @released
  2940 	@publishedPartner @released
  2927 */
  2941 */
  2928 TInt DUsbClientController::DeviceEventNotification(TUsbcDeviceEvent anEvent)
  2942 TInt DUsbClientController::DeviceEventNotification(TUsbcDeviceEvent anEvent)
  2929 	{
  2943 	{
  2930 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeviceEventNotification()"));
  2944     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICEEVENTNOTIFICATION, "DUsbClientController::DeviceEventNotification()" );
  2931 
  2945 
  2932 	// This function may be called by the PSL from within an ISR -- so we have
  2946 	// This function may be called by the PSL from within an ISR -- so we have
  2933 	// to take care what we do here (and also in all functions that get called
  2947 	// to take care what we do here (and also in all functions that get called
  2934 	// from here).
  2948 	// from here).
  2935 
  2949 
  2959 
  2973 
  2960 	@publishedPartner @released
  2974 	@publishedPartner @released
  2961 */
  2975 */
  2962 void DUsbClientController::EndpointRequestComplete(TUsbcRequestCallback* aCallback)
  2976 void DUsbClientController::EndpointRequestComplete(TUsbcRequestCallback* aCallback)
  2963 	{
  2977 	{
  2964 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EndpointRequestComplete(%p)", aCallback));
  2978 	OstTraceDefExt1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENDPOINTREQUESTCOMPLETE, "DUsbClientController::EndpointRequestComplete(%p)", aCallback);
  2965 
  2979 	
  2966 	// This function may be called by the PSL from within an ISR -- so we have
  2980 	// This function may be called by the PSL from within an ISR -- so we have
  2967 	// to take care what we do here (and also in all functions that get called
  2981 	// to take care what we do here (and also in all functions that get called
  2968 	// from here).
  2982 	// from here).
  2969 
  2983 
  2970 	// We don't test aCallback for NULL here (and therefore risk a crash)
  2984 	// We don't test aCallback for NULL here (and therefore risk a crash)
  2993 */
  3007 */
  2994 void DUsbClientController::HandleHnpRequest(TInt aHnpState)
  3008 void DUsbClientController::HandleHnpRequest(TInt aHnpState)
  2995 // This function is called by the PSL from within an ISR -- so we have to take care what we do here
  3009 // This function is called by the PSL from within an ISR -- so we have to take care what we do here
  2996 // (and also in all functions that get called from here).
  3010 // (and also in all functions that get called from here).
  2997 	{
  3011 	{
  2998 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::HandleHnpRequest(%d)", aHnpState));
  3012 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_HANDLEHNPREQUEST, "DUsbClientController::HandleHnpRequest(%d)", aHnpState);
       
  3013 	
  2999 
  3014 
  3000 	if (!iOtgSupport)
  3015 	if (!iOtgSupport)
  3001 		{
  3016 		{
  3002 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Request only supported on a OTG device"));
  3017 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_HANDLEHNPREQUEST_DUP1, "  Error: Request only supported on a OTG device");
  3003 		return;
  3018 		return;
  3004 		}
  3019 		}
  3005 	if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp))
  3020 	if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp))
  3006 		{
  3021 		{
  3007 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Request only valid if OTG device supports HNP"));
  3022 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_HANDLEHNPREQUEST_DUP2, "  Error: Request only valid if OTG device supports HNP");
  3008 		return;
  3023 		return;
  3009 		}
  3024 		}
  3010 	//	(case KUsbFeature_B_HnpEnable:)
  3025 	//	(case KUsbFeature_B_HnpEnable:)
  3011 	if (aHnpState & 0x04)
  3026 	if (aHnpState & 0x04)
  3012 		{
  3027 		{
  3042 
  3057 
  3043 	@publishedPartner @released
  3058 	@publishedPartner @released
  3044 */
  3059 */
  3045 TInt DUsbClientController::Ep0RequestComplete(TInt aRealEndpoint, TInt aCount, TInt aError)
  3060 TInt DUsbClientController::Ep0RequestComplete(TInt aRealEndpoint, TInt aCount, TInt aError)
  3046 	{
  3061 	{
  3047 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::Ep0RequestComplete(%d)", aRealEndpoint));
  3062 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE, "DUsbClientController::Ep0RequestComplete(%d)", aRealEndpoint);
  3048 
  3063 	
  3049 	// This function may be called by the PSL from within an ISR -- so we have
  3064 	// This function may be called by the PSL from within an ISR -- so we have
  3050 	// to take care what we do here (and also in all functions that get called
  3065 	// to take care what we do here (and also in all functions that get called
  3051 	// from here).
  3066 	// from here).
  3052 
  3067 
  3053 	__ASSERT_DEBUG((aRealEndpoint < 2), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3068 	__ASSERT_DEBUG((aRealEndpoint < 2), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3054 	if (aError != KErrNone && aError != KErrPrematureEnd)
  3069 	if (aError != KErrNone && aError != KErrPrematureEnd)
  3055 		{
  3070 		{
  3056 		__KTRACE_OPT(KUSB, Kern::Printf(" Error: Ep0 request failed (code %d). "
  3071 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP1, " Error: Ep0 request failed (code %d). "
  3057 										"Setting up new Read request.", aError));
  3072                                         "Setting up new Read request.", aError);
       
  3073 
  3058 		if (aRealEndpoint == KEp0_Rx)
  3074 		if (aRealEndpoint == KEp0_Rx)
  3059 			{
  3075 			{
  3060 			__KTRACE_OPT(KUSB, Kern::Printf(" (RX request failed)"));
  3076 			OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP2, " (RX request failed)");
  3061 			StallEndpoint(KEp0_Out);
  3077 			StallEndpoint(KEp0_Out);
  3062 			}
  3078 			}
  3063 		else
  3079 		else
  3064 			{
  3080 			{
  3065 			__KTRACE_OPT(KUSB, Kern::Printf(" (TX request failed)"));
  3081 	        OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP3, " (TX request failed)");
  3066 			iEp0WritePending = EFalse;
  3082 			iEp0WritePending = EFalse;
  3067 			StallEndpoint(KEp0_In);
  3083 			StallEndpoint(KEp0_In);
  3068 			}
  3084 			}
  3069 		// our only remedy: set up a new read request
  3085 		// our only remedy: set up a new read request
  3070 		SetupEndpointZeroRead();
  3086 		SetupEndpointZeroRead();
  3088 		}
  3104 		}
  3089 	if (iEp0WritePending == EFalse)
  3105 	if (iEp0WritePending == EFalse)
  3090 		{
  3106 		{
  3091 		// we're done & no write request has been set up.
  3107 		// we're done & no write request has been set up.
  3092 		// so: setup an Ep0 read again
  3108 		// so: setup an Ep0 read again
  3093 		__KTRACE_OPT(KUSB, Kern::Printf(" Setting up new Ep0 read request."));
  3109         OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EP0REQUESTCOMPLETE_DUP4, " Setting up new Ep0 read request.");
  3094 		SetupEndpointZeroRead();
  3110 		SetupEndpointZeroRead();
  3095 		}
  3111 		}
  3096 	return r;
  3112 	return r;
  3097 	}
  3113 	}
  3098 
  3114 
  3101 
  3117 
  3102 	@publishedPartner @released
  3118 	@publishedPartner @released
  3103 */
  3119 */
  3104 void DUsbClientController::MoveToAddressState()
  3120 void DUsbClientController::MoveToAddressState()
  3105 	{
  3121 	{
  3106 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::MoveToAddressState()"));
  3122     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_MOVETOADDRESSSTATE, "DUsbClientController::MoveToAddressState()" );
  3107 
  3123 
  3108 	// This function may be called by the PSL from within an ISR -- so we have
  3124 	// This function may be called by the PSL from within an ISR -- so we have
  3109 	// to take care what we do here (and also in all functions that get called
  3125 	// to take care what we do here (and also in all functions that get called
  3110 	// from here).
  3126 	// from here).
  3111 
  3127 
  3122 
  3138 
  3123 	@publishedPartner @released
  3139 	@publishedPartner @released
  3124 */
  3140 */
  3125 void DUsbClientController::SetCurrent(TInt aCurrent)
  3141 void DUsbClientController::SetCurrent(TInt aCurrent)
  3126 	{
  3142 	{
  3127 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetCurrent(%d)", aCurrent));
  3143 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_SETCURRENT, "DUsbClientController::SetCurrent(%d)", aCurrent);
  3128 
  3144 	
  3129 	// Not much for the moment... (What should we do here?)
  3145 	// Not much for the moment... (What should we do here?)
  3130 	return;
  3146 	return;
  3131 	}
  3147 	}
  3132 
  3148 
  3133 
  3149 
  3135 // === Platform Specific Layer (PSL) - private/virtual =============================================
  3151 // === Platform Specific Layer (PSL) - private/virtual =============================================
  3136 //
  3152 //
  3137 
  3153 
  3138 TInt DUsbClientController::OpenDmaChannel(TInt aRealEndpoint)
  3154 TInt DUsbClientController::OpenDmaChannel(TInt aRealEndpoint)
  3139 	{
  3155 	{
  3140 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::OpenDmaChannel(%d)", aRealEndpoint));
  3156 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_OPENDMACHANNEL, "DUsbClientController::OpenDmaChannel(%d)", aRealEndpoint);
       
  3157 	
  3141 	return KErrNone;
  3158 	return KErrNone;
  3142 	}
  3159 	}
  3143 
  3160 
  3144 
  3161 
  3145 void DUsbClientController::CloseDmaChannel(TInt aRealEndpoint)
  3162 void DUsbClientController::CloseDmaChannel(TInt aRealEndpoint)
  3146 	{
  3163 	{
  3147 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CloseDmaChannel(%d)", aRealEndpoint));
  3164 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CLOSEDMACHANNEL, "DUsbClientController::CloseDmaChannel(%d)", aRealEndpoint);
  3148 	}
  3165 	}
  3149 
  3166 
  3150 
  3167 
  3151 TBool DUsbClientController::CableDetectWithoutPowerCaps() const
  3168 TBool DUsbClientController::CableDetectWithoutPowerCaps() const
  3152 	{
  3169 	{
  3153 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CableDetectWithoutPowerCaps()"));
  3170 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CABLEDETECTWITHOUTPOWERCAPS, "DUsbClientController::CableDetectWithoutPowerCaps()" );
  3154 	// Should be overridden in PSL if applicable.
  3171 	// Should be overridden in PSL if applicable.
  3155 	return EFalse;
  3172 	return EFalse;
  3156 	}
  3173 	}
  3157 
  3174 
  3158 
  3175 
  3159 TBool DUsbClientController::DeviceHighSpeedCaps() const
  3176 TBool DUsbClientController::DeviceHighSpeedCaps() const
  3160 	{
  3177 	{
  3161 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeviceHighSpeedCaps()"));
  3178 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICEHIGHSPEEDCAPS, "DUsbClientController::DeviceHighSpeedCaps()" );
  3162 	// Should be overridden in PSL if applicable.
  3179 	// Should be overridden in PSL if applicable.
  3163 	return EFalse;
  3180 	return EFalse;
  3164 	}
  3181 	}
  3165 
  3182 
  3166 
  3183 
  3167 TBool DUsbClientController::DeviceResourceAllocV2Caps() const
  3184 TBool DUsbClientController::DeviceResourceAllocV2Caps() const
  3168 	{
  3185 	{
  3169 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeviceResourceAllocV2Caps()"));
  3186 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICERESOURCEALLOCV2CAPS, "DUsbClientController::DeviceResourceAllocV2Caps()" );
  3170 	// Should be overridden in PSL if applicable.
  3187 	// Should be overridden in PSL if applicable.
  3171 	return EFalse;
  3188 	return EFalse;
  3172 	}
  3189 	}
  3173 
  3190 
  3174 
  3191 
  3175 TBool DUsbClientController::DeviceHnpHandledByHardwareCaps() const
  3192 TBool DUsbClientController::DeviceHnpHandledByHardwareCaps() const
  3176 	{
  3193 	{
  3177 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeviceHnpHandledByHardwareCaps()"));
  3194 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEVICEHNPHANDLEDBYHARDWARECAPS, "DUsbClientController::DeviceHnpHandledByHardwareCaps()" );
  3178 	// Should be overridden in PSL if applicable.
  3195 	// Should be overridden in PSL if applicable.
  3179 	return EFalse;
  3196 	return EFalse;
  3180 	}
  3197 	}
  3181 
  3198 
  3182 
  3199 
  3183 TInt DUsbClientController::EnterTestMode(TInt aTestSelector)
  3200 TInt DUsbClientController::EnterTestMode(TInt aTestSelector)
  3184 	{
  3201 	{
  3185 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EnterTestMode(%d)", aTestSelector));
  3202 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ENTERTESTMODE, "DUsbClientController::EnterTestMode(%d)", aTestSelector);
       
  3203 	
  3186 	// Should be overridden in PSL if applicable.
  3204 	// Should be overridden in PSL if applicable.
  3187 	return KErrNotSupported;
  3205 	return KErrNotSupported;
  3188 	}
  3206 	}
  3189 
  3207 
  3190 
  3208 
  3191 TBool DUsbClientController::PowerDownWhenActive() const
  3209 TBool DUsbClientController::PowerDownWhenActive() const
  3192 	{
  3210 	{
  3193  	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerDownWhenActive()"));
  3211  	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERDOWNWHENACTIVE, "DUsbClientController::PowerDownWhenActive()" );
  3194  	return EFalse;
  3212  	return EFalse;
  3195 	}
  3213 	}
  3196 
  3214 
  3197 
  3215 
  3198 TInt DUsbClientController::PowerDown()
  3216 TInt DUsbClientController::PowerDown()
  3199 	{
  3217 	{
  3200  	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerDown()"));
  3218  	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERDOWN, "DUsbClientController::PowerDown()" );
  3201  	return KErrNone;
  3219  	return KErrNone;
  3202 	}
  3220 	}
  3203 
  3221 
  3204 
  3222 
  3205 TInt DUsbClientController::PowerUp()
  3223 TInt DUsbClientController::PowerUp()
  3206 	{
  3224 	{
  3207  	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerUp()"));
  3225  	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERUP, "DUsbClientController::PowerUp()" );
  3208  	return KErrNone;
  3226  	return KErrNone;
  3209 	}
  3227 	}
  3210 
  3228 
  3211 
  3229 
  3212 TInt DUsbClientController::OtgEnableUdc()
  3230 TInt DUsbClientController::OtgEnableUdc()
  3213 	{
  3231 	{
  3214  	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::OtgEnableUdc()"));
  3232  	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_OTGENABLEUDC, "DUsbClientController::OtgEnableUdc()" );
  3215  	return KErrNone;
  3233  	return KErrNone;
  3216 	}
  3234 	}
  3217 
  3235 
  3218 
  3236 
  3219 TInt DUsbClientController::OtgDisableUdc()
  3237 TInt DUsbClientController::OtgDisableUdc()
  3220    	{
  3238    	{
  3221  	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::OtgDisableUdc()"));
  3239  	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_OTGDISABLEUDC, "DUsbClientController::OtgDisableUdc()" );
  3222  	return KErrNone;
  3240  	return KErrNone;
  3223 	}
  3241 	}
  3224 
  3242 
  3225 
  3243 
  3226 //
  3244 //
  3227 // === USB Controller member function implementations - Internal utility functions (private) =======
  3245 // === USB Controller member function implementations - Internal utility functions (private) =======
  3228 //
  3246 //
  3229 
  3247 
  3230 TInt DUsbClientController::DeRegisterClientCallback(const DBase* aClientId)
  3248 TInt DUsbClientController::DeRegisterClientCallback(const DBase* aClientId)
  3231     {
  3249     {
  3232 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeRegisterClientCallback()"));
  3250 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEREGISTERCLIENTCALLBACK, "DUsbClientController::DeRegisterClientCallback()" );
  3233 	__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3251 	__ASSERT_DEBUG((aClientId != NULL), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3234 	TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks);
  3252 	TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks);
  3235 	TUsbcClientCallback* p;
  3253 	TUsbcClientCallback* p;
  3236 	while ((p = iter++) != NULL)
  3254 	while ((p = iter++) != NULL)
  3237 		if (p->Owner() == aClientId)
  3255 		if (p->Owner() == aClientId)
  3238 			{
  3256 			{
  3239 			__KTRACE_OPT(KUSB, Kern::Printf("  removing ClientCallback @ 0x%x", p));
  3257 			 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERCLIENTCALLBACK_DUP1, "  removing ClientCallback @ 0x%x", p);
  3240 			iClientCallbacks.Remove(*p);
  3258 			iClientCallbacks.Remove(*p);
  3241 			return KErrNone;
  3259 			return KErrNone;
  3242 			}
  3260 			}
  3243 	__KTRACE_OPT(KUSB, Kern::Printf("  Client not found"));
  3261     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEREGISTERCLIENTCALLBACK_DUP2, "  Client not found");
  3244 	return KErrNotFound;
  3262 	return KErrNotFound;
  3245     }
  3263     }
  3246 
  3264 
  3247 
  3265 
  3248 TBool DUsbClientController::CheckEpAvailability(TInt aEndpointsUsed,
  3266 TBool DUsbClientController::CheckEpAvailability(TInt aEndpointsUsed,
  3249 												const TUsbcEndpointInfoArray& aEndpointData,
  3267 												const TUsbcEndpointInfoArray& aEndpointData,
  3250 												TInt aIfcNumber) const
  3268 												TInt aIfcNumber) const
  3251 	{
  3269 	{
  3252 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CheckEpAvailability()"));
  3270 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY, "DUsbClientController::CheckEpAvailability()" );
  3253 	if (aEndpointsUsed > KMaxEndpointsPerClient)
  3271 	if (aEndpointsUsed > KMaxEndpointsPerClient)
  3254 		{
  3272 		{
  3255 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: too many endpoints claimed (%d)", aEndpointsUsed));
  3273 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP1, "  Error: too many endpoints claimed (%d)", aEndpointsUsed);
  3256 		return EFalse;
  3274 		return EFalse;
  3257 		}
  3275 		}
  3258 	TBool reserve[KUsbcEpArraySize]; // iDeviceTotalEndpoints can be equal to 32
  3276 	TBool reserve[KUsbcEpArraySize]; // iDeviceTotalEndpoints can be equal to 32
  3259 	memset(reserve, EFalse, sizeof(reserve));				// reset the array
  3277 	memset(reserve, EFalse, sizeof(reserve));				// reset the array
  3260 	for (TInt i = 0; i < aEndpointsUsed; ++i)
  3278 	for (TInt i = 0; i < aEndpointsUsed; ++i)
  3261 		{
  3279 		{
  3262 		__KTRACE_OPT(KUSB, Kern::Printf("  checking for (user) endpoint #%d availability...", i + 1));
  3280 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP2, "  checking for (user) endpoint #%d availability...", i + 1);
  3263 		TInt j = 2;
  3281 		TInt j = 2;
  3264 		while (j < iDeviceTotalEndpoints)
  3282 		while (j < iDeviceTotalEndpoints)
  3265 			{
  3283 			{
  3266 			if ((iRealEndpoints[j].EndpointSuitable(&aEndpointData[i], aIfcNumber)) &&
  3284 			if ((iRealEndpoints[j].EndpointSuitable(&aEndpointData[i], aIfcNumber)) &&
  3267 				(reserve[j] == EFalse))
  3285 				(reserve[j] == EFalse))
  3268 				{
  3286 				{
  3269 				__KTRACE_OPT(KUSB, Kern::Printf("  ---> found suitable endpoint: RealEndpoint #%d", j));
  3287 		        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP3, "  ---> found suitable endpoint: RealEndpoint #%d", j);
  3270 				reserve[j] = ETrue;							// found one: mark this ep as reserved
  3288 				reserve[j] = ETrue;							// found one: mark this ep as reserved
  3271 				break;
  3289 				break;
  3272 				}
  3290 				}
  3273 			__KTRACE_OPT(KUSB, Kern::Printf("  -> endpoint not suitable: RealEndpoint #%d", j));
  3291             OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CHECKEPAVAILABILITY_DUP4, "  -> endpoint not suitable: RealEndpoint #%d", j);
  3274 			j++;
  3292 			j++;
  3275 			}
  3293 			}
  3276 		if (j == iDeviceTotalEndpoints)
  3294 		if (j == iDeviceTotalEndpoints)
  3277 			{
  3295 			{
  3278 			return EFalse;
  3296 			return EFalse;
  3285 TUsbcInterface* DUsbClientController::CreateInterface(const DBase* aClientId, TInt aIfc, TUint32 aFeatureWord)
  3303 TUsbcInterface* DUsbClientController::CreateInterface(const DBase* aClientId, TInt aIfc, TUint32 aFeatureWord)
  3286 // We know that 9.2.3 says: "Interfaces are numbered from zero to one less than the number of
  3304 // We know that 9.2.3 says: "Interfaces are numbered from zero to one less than the number of
  3287 // concurrent interfaces supported by the configuration."  But since we permit the user to
  3305 // concurrent interfaces supported by the configuration."  But since we permit the user to
  3288 // change interface numbers, we can neither assume nor enforce anything about them here.
  3306 // change interface numbers, we can neither assume nor enforce anything about them here.
  3289 	{
  3307 	{
  3290 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CreateInterface(x, aIfc=%d)", aIfc));
  3308 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE, "DUsbClientController::CreateInterface(x, aIfc=%d)", aIfc);
       
  3309 	
  3291 	TUsbcInterfaceSet* ifcset_ptr = NULL;
  3310 	TUsbcInterfaceSet* ifcset_ptr = NULL;
  3292 	TInt ifcset = ClientId2InterfaceNumber(aClientId);
  3311 	TInt ifcset = ClientId2InterfaceNumber(aClientId);
  3293 	TBool new_ifc;
  3312 	TBool new_ifc;
  3294 	if (ifcset < 0)
  3313 	if (ifcset < 0)
  3295 		{
  3314 		{
  3296 		// New interface(set), so we need to find a number for it.
  3315 		// New interface(set), so we need to find a number for it.
  3297 		new_ifc = ETrue;
  3316 		new_ifc = ETrue;
  3298 		const TInt num_ifcsets = iConfigs[0]->iInterfaceSets.Count();
  3317 		const TInt num_ifcsets = iConfigs[0]->iInterfaceSets.Count();
  3299 		if (num_ifcsets == 255)
  3318 		if (num_ifcsets == 255)
  3300 			{
  3319 			{
  3301 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Too many interfaces already exist: 255"));
  3320 			OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP1, "  Error: Too many interfaces already exist: 255");
  3302 			return NULL;
  3321 			return NULL;
  3303 			}
  3322 			}
  3304 		// Find the smallest interface number that has not yet been used.
  3323 		// Find the smallest interface number that has not yet been used.
  3305 		for (ifcset = 0; ifcset < 256; ++ifcset)
  3324 		for (ifcset = 0; ifcset < 256; ++ifcset)
  3306 			{
  3325 			{
  3307 			TBool n_used = EFalse;
  3326 			TBool n_used = EFalse;
  3308 			for (TInt i = 0; i < num_ifcsets; ++i)
  3327 			for (TInt i = 0; i < num_ifcsets; ++i)
  3309 				{
  3328 				{
  3310 				if ((iConfigs[0]->iInterfaceSets[i]->iInterfaceNumber) == ifcset)
  3329 				if ((iConfigs[0]->iInterfaceSets[i]->iInterfaceNumber) == ifcset)
  3311 					{
  3330 					{
  3312 					__KTRACE_OPT(KUSB, Kern::Printf("  interface number %d already used", ifcset));
  3331 			        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP2, "  interface number %d already used", ifcset);
  3313 					n_used = ETrue;
  3332 					n_used = ETrue;
  3314 					break;
  3333 					break;
  3315 					}
  3334 					}
  3316 				}
  3335 				}
  3317 			if (!n_used)
  3336 			if (!n_used)
  3319 				break;
  3338 				break;
  3320 				}
  3339 				}
  3321 			}
  3340 			}
  3322 		if (ifcset == 256)
  3341 		if (ifcset == 256)
  3323 			{
  3342 			{
  3324 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no available interface number found"));
  3343             OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP3, "  Error: no available interface number found");
  3325 			return NULL;
  3344 			return NULL;
  3326 			}
  3345 			}
  3327 		// append the ifcset
  3346 		// append the ifcset
  3328 		__KTRACE_OPT(KUSB, Kern::Printf("  creating new InterfaceSet %d first", ifcset));
  3347         OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP4, "  creating new InterfaceSet %d first", ifcset);
  3329 		if (aIfc != 0)
  3348 		if (aIfc != 0)
  3330 			{
  3349 			{
  3331 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: invalid interface setting number (1): %d", aIfc));
  3350 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP5, "  Error: invalid interface setting number (1): %d", aIfc);
  3332 			return NULL;
  3351 			return NULL;
  3333 			}
  3352 			}
  3334 		if ((ifcset_ptr = new TUsbcInterfaceSet(aClientId, ifcset)) == NULL)
  3353 		if ((ifcset_ptr = new TUsbcInterfaceSet(aClientId, ifcset)) == NULL)
  3335 			{
  3354 			{
  3336 			__KTRACE_OPT(KPANIC,
  3355 			OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP6, "  Error: new TUsbcInterfaceSet(aClientId, ifcset_num) failed");
  3337 						 Kern::Printf("  Error: new TUsbcInterfaceSet(aClientId, ifcset_num) failed"));
       
  3338 			return NULL;
  3356 			return NULL;
  3339 			}
  3357 			}
  3340 		iConfigs[0]->iInterfaceSets.Append(ifcset_ptr);
  3358 		iConfigs[0]->iInterfaceSets.Append(ifcset_ptr);
  3341 		}
  3359 		}
  3342 	else /* if (ifcset_num >= 0) */
  3360 	else /* if (ifcset_num >= 0) */
  3343 		{
  3361 		{
  3344 		// use an existent ifcset
  3362 		// use an existent ifcset
  3345 		new_ifc = EFalse;
  3363 		new_ifc = EFalse;
  3346 		__KTRACE_OPT(KUSB, Kern::Printf("  using existing InterfaceSet %d", ifcset));
  3364         OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP7, "  using existing InterfaceSet %d", ifcset);
  3347 		ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset);
  3365 		ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset);
  3348 		if (aIfc != ifcset_ptr->iInterfaces.Count())
  3366 		if (aIfc != ifcset_ptr->iInterfaces.Count())
  3349 			{
  3367 			{
  3350 			// 9.2.3: "Alternate settings range from zero to one less than the number of alternate
  3368 			// 9.2.3: "Alternate settings range from zero to one less than the number of alternate
  3351 			// settings for a specific interface." (Thus we can here only append a setting.)
  3369 			// settings for a specific interface." (Thus we can here only append a setting.)
  3352 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: invalid interface setting number (2): %d", aIfc));
  3370 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP8, "  Error: invalid interface setting number (2): %d", aIfc);
  3353 			return NULL;
  3371 			return NULL;
  3354 			}
  3372 			}
  3355 		// Check whether the existing interface belongs indeed to this client
  3373 		// Check whether the existing interface belongs indeed to this client
  3356 		if (ifcset_ptr->iClientId != aClientId)
  3374 		if (ifcset_ptr->iClientId != aClientId)
  3357 			{
  3375 			{
  3358 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: iClientId (%p) != aClientId (%p)",
  3376 	        OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP9, "  Error: iClientId (%p) != aClientId (%p)",
  3359 											  ifcset_ptr->iClientId, aClientId));
  3377                                               ifcset_ptr->iClientId, aClientId);
  3360 			return NULL;
  3378 			return NULL;
  3361 			}
  3379 			}
  3362 		}
  3380 		}
  3363 	const TBool no_ep0_requests = aFeatureWord & KUsbcInterfaceInfo_NoEp0RequestsPlease;
  3381 	const TBool no_ep0_requests = aFeatureWord & KUsbcInterfaceInfo_NoEp0RequestsPlease;
  3364 	TUsbcInterface* const ifc_ptr = new TUsbcInterface(ifcset_ptr, aIfc, no_ep0_requests);
  3382 	TUsbcInterface* const ifc_ptr = new TUsbcInterface(ifcset_ptr, aIfc, no_ep0_requests);
  3365 	if (!ifc_ptr)
  3383 	if (!ifc_ptr)
  3366 		{
  3384 		{
  3367 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: new TUsbcInterface(ifcset, aIfc) failed"));
  3385 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEINTERFACE_DUP10, "  Error: new TUsbcInterface(ifcset, aIfc) failed");
  3368 		if (new_ifc)
  3386 		if (new_ifc)
  3369 			{
  3387 			{
  3370 			DeleteInterfaceSet(ifcset);
  3388 			DeleteInterfaceSet(ifcset);
  3371 			}
  3389 			}
  3372 		return NULL;
  3390 		return NULL;
  3385 
  3403 
  3386 TInt DUsbClientController::CreateEndpoints(TUsbcInterface* aIfc, TInt aEndpointsUsed,
  3404 TInt DUsbClientController::CreateEndpoints(TUsbcInterface* aIfc, TInt aEndpointsUsed,
  3387 										   const TUsbcEndpointInfoArray& aEndpointData,
  3405 										   const TUsbcEndpointInfoArray& aEndpointData,
  3388 										   TInt aRealEpNumbers[])
  3406 										   TInt aRealEpNumbers[])
  3389 	{
  3407 	{
  3390 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CreateEndpoints()"));
  3408 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CREATEENDPOINTS, "DUsbClientController::CreateEndpoints()" );
  3391 	const TInt ifc_num = aIfc->iInterfaceSet->iInterfaceNumber;
  3409 	const TInt ifc_num = aIfc->iInterfaceSet->iInterfaceNumber;
  3392 	const TInt start_ep = 2;
  3410 	const TInt start_ep = 2;
  3393 	for (TInt i = 0; i < aEndpointsUsed; ++i)
  3411 	for (TInt i = 0; i < aEndpointsUsed; ++i)
  3394 		{
  3412 		{
  3395 		for (TInt j = start_ep; j < iDeviceTotalEndpoints; ++j)
  3413 		for (TInt j = start_ep; j < iDeviceTotalEndpoints; ++j)
  3399 				// Logical endpoints are numbered 1..KMaxEndpointsPerClient (virtual 0 is real 0 and 1)
  3417 				// Logical endpoints are numbered 1..KMaxEndpointsPerClient (virtual 0 is real 0 and 1)
  3400 				TUsbcLogicalEndpoint* const ep = new TUsbcLogicalEndpoint(this, i + 1, aEndpointData[i],
  3418 				TUsbcLogicalEndpoint* const ep = new TUsbcLogicalEndpoint(this, i + 1, aEndpointData[i],
  3401 																		  aIfc, &iRealEndpoints[j]);
  3419 																		  aIfc, &iRealEndpoints[j]);
  3402 				if (!ep)
  3420 				if (!ep)
  3403 					{
  3421 					{
  3404 					__KTRACE_OPT(KPANIC, Kern::Printf("  Error: new TUsbcLogicalEndpoint() failed"));
  3422 					OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP1, "  Error: new TUsbcLogicalEndpoint() failed");
  3405 					aIfc->iEndpoints.ResetAndDestroy();
  3423 					aIfc->iEndpoints.ResetAndDestroy();
  3406 					RESET_SETTINGRESERVE;
  3424 					RESET_SETTINGRESERVE;
  3407 					return KErrNoMemory;
  3425 					return KErrNoMemory;
  3408 					}
  3426 					}
  3409 				aIfc->iEndpoints.Append(ep);
  3427 				aIfc->iEndpoints.Append(ep);
  3411 				if (aIfc->iSettingCode == 0)
  3429 				if (aIfc->iSettingCode == 0)
  3412 					{
  3430 					{
  3413 					// For details see last paragraph of 5.7.3 "Interrupt Transfer Packet Size Constraints".
  3431 					// For details see last paragraph of 5.7.3 "Interrupt Transfer Packet Size Constraints".
  3414 					if ((ep->iInfo.iType == KUsbEpTypeInterrupt) && (ep->iEpSize_Hs > 64))
  3432 					if ((ep->iInfo.iType == KUsbEpTypeInterrupt) && (ep->iEpSize_Hs > 64))
  3415 						{
  3433 						{
  3416 						__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: INT ep HS size = %d on default ifc setting",
  3434 		                OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP2, "  Warning: INT ep HS size = %d on default ifc setting",
  3417 														  ep->iEpSize_Hs));
  3435                                                           ep->iEpSize_Hs);
  3418 						__KTRACE_OPT(KPANIC, Kern::Printf("           (should be <= 64)"));
  3436 		                OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP3, "           (should be <= 64)");
  3419 						}
  3437 						}
  3420 					// For details see last paragraph of 5.6.3 "Isochronous Transfer Packet Size Constraints".
  3438 					// For details see last paragraph of 5.6.3 "Isochronous Transfer Packet Size Constraints".
  3421 					else if ((ep->iInfo.iType == KUsbEpTypeIsochronous) && (ep->iInfo.iSize > 0))
  3439 					else if ((ep->iInfo.iType == KUsbEpTypeIsochronous) && (ep->iInfo.iSize > 0))
  3422 						{
  3440 						{
  3423 						__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: ISO ep size = %d on default ifc setting",
  3441 						OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP4, " Warning: ISO ep size = %d on default ifc setting",
  3424 														  ep->iInfo.iSize));
  3442                                                           ep->iInfo.iSize);
  3425 						__KTRACE_OPT(KPANIC, Kern::Printf("           (should be zero or ep non-existent)"));
  3443 						OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP5, "           (should be zero or ep non-existent)");
  3426 						}
  3444 						}
  3427 					}
  3445 					}
  3428 				// If the endpoint doesn't support DMA (now or never) the next operation
  3446 				// If the endpoint doesn't support DMA (now or never) the next operation
  3429 				// will be a successful no-op.
  3447 				// will be a successful no-op.
  3430 				const TInt r = OpenDmaChannel(j);
  3448 				const TInt r = OpenDmaChannel(j);
  3431 				if (r != KErrNone)
  3449 				if (r != KErrNone)
  3432 					{
  3450 					{
  3433 					__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Opening of DMA channel failed"));
  3451                     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP6, "  Error: Opening of DMA channel failed");
  3434 					aIfc->iEndpoints.ResetAndDestroy();
  3452 					aIfc->iEndpoints.ResetAndDestroy();
  3435 					RESET_SETTINGRESERVE;
  3453 					RESET_SETTINGRESERVE;
  3436 					return r;
  3454 					return r;
  3437 					}
  3455 					}
  3438 				__KTRACE_OPT(KUSB, Kern::Printf("  creating ep: mapping real ep %d -> logical ep %d",
  3456 				OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP7, "  creating ep: mapping real ep %d -> logical ep %d",
  3439 												j, i + 1));
  3457                                                 j, i + 1);
  3440 				iRealEndpoints[j].iIfcNumber = &aIfc->iInterfaceSet->iInterfaceNumber;
  3458 				iRealEndpoints[j].iIfcNumber = &aIfc->iInterfaceSet->iInterfaceNumber;
  3441 				iRealEndpoints[j].iSettingReserve = ETrue;
  3459 				iRealEndpoints[j].iSettingReserve = ETrue;
  3442 				__KTRACE_OPT(KUSB,
  3460 				OstTraceDefExt4(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP8, "  ep->iInfo: iType=0x%x iDir=0x%x iSize=%d iInterval=%d",
  3443 							 Kern::Printf("  ep->iInfo: iType=0x%x iDir=0x%x iSize=%d iInterval=%d",
  3461                                           ep->iInfo.iType, ep->iInfo.iDir, ep->iInfo.iSize,
  3444 										  ep->iInfo.iType, ep->iInfo.iDir, ep->iInfo.iSize,
  3462                                           ep->iInfo.iInterval);
  3445 										  ep->iInfo.iInterval));
  3463 				OstTraceDefExt3(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP9, "  ep->iInfo: iInterval_Hs=%d iTransactions=%d iExtra=%d",
  3446 				__KTRACE_OPT(KUSB,
  3464                                           ep->iInfo.iInterval_Hs, ep->iInfo.iTransactions,
  3447 							 Kern::Printf("  ep->iInfo: iInterval_Hs=%d iTransactions=%d iExtra=%d",
  3465                                           ep->iInfo.iExtra);
  3448 										  ep->iInfo.iInterval_Hs, ep->iInfo.iTransactions,
       
  3449 										  ep->iInfo.iExtra));
       
  3450 				// Store real endpoint numbers:
  3466 				// Store real endpoint numbers:
  3451 				// array[x] holds the number for logical ep x.
  3467 				// array[x] holds the number for logical ep x.
  3452 				aRealEpNumbers[i + 1] = j;
  3468 				aRealEpNumbers[i + 1] = j;
  3453 				break;
  3469 				break;
  3454 				}
  3470 				}
  3455 			}
  3471 			}
  3456 		}
  3472 		}
  3457 	aRealEpNumbers[0] = 0;								// ep0: 0.
  3473 	aRealEpNumbers[0] = 0;								// ep0: 0.
  3458 	__KTRACE_OPT(KUSB,{
  3474 	OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP10, "  Endpoint Mapping for Interface %d / Setting %d:", ifc_num, aIfc->iSettingCode); 
  3459 		Kern::Printf("  Endpoint Mapping for Interface %d / Setting %d:", ifc_num, aIfc->iSettingCode);
  3475 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP11, "Logical  | Real");
  3460 		Kern::Printf("Logical  | Real");
  3476 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP12, "Endpoint | Endpoint");
  3461 		Kern::Printf("Endpoint | Endpoint");
  3477     for (TInt ep = 0; ep <= aEndpointsUsed; ++ep)
  3462 		for (TInt ep = 0; ep <= aEndpointsUsed; ++ep) Kern::Printf("   %2d       %3d",ep, aRealEpNumbers[ep]);
  3478         OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CREATEENDPOINTS_DUP13, "   %2d       %3d",ep, aRealEpNumbers[ep]);
  3463 		});
  3479 
  3464 	RESET_SETTINGRESERVE;
  3480 	RESET_SETTINGRESERVE;
  3465 	return KErrNone;
  3481 	return KErrNone;
  3466 	}
  3482 	}
  3467 
  3483 
  3468 
  3484 
  3469 TInt DUsbClientController::SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass, DThread* aThread,
  3485 TInt DUsbClientController::SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass, DThread* aThread,
  3470 											  TDesC8* aString, const TUsbcEndpointInfoArray& aEndpointData)
  3486 											  TDesC8* aString, const TUsbcEndpointInfoArray& aEndpointData)
  3471 	{
  3487 	{
  3472 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetupIfcDescriptor()"));
  3488     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR, "DUsbClientController::SetupIfcDescriptor()" );
  3473 
  3489 
  3474 	// Interface descriptor
  3490 	// Interface descriptor
  3475 	TUsbcDescriptorBase* d = TUsbcInterfaceDescriptor::New(aIfc->iInterfaceSet->iInterfaceNumber,
  3491 	TUsbcDescriptorBase* d = TUsbcInterfaceDescriptor::New(aIfc->iInterfaceSet->iInterfaceNumber,
  3476 														   aIfc->iSettingCode,
  3492 														   aIfc->iSettingCode,
  3477 														   aIfc->iEndpoints.Count(),
  3493 														   aIfc->iEndpoints.Count(),
  3478 														   aClass);
  3494 														   aClass);
  3479 	if (!d)
  3495 	if (!d)
  3480 		{
  3496 		{
  3481 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Memory allocation for ifc desc failed."));
  3497 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP1, "  Error: Memory allocation for ifc desc failed." );
  3482 		return KErrNoMemory;
  3498 		return KErrNoMemory;
  3483 		}
  3499 		}
  3484 	iDescriptors.InsertDescriptor(d);
  3500 	iDescriptors.InsertDescriptor(d);
  3485 
  3501 
  3486 	// Interface string descriptor
  3502 	// Interface string descriptor
  3488 		{
  3504 		{
  3489 		// we don't know the length of the string, so we have to allocate memory dynamically
  3505 		// we don't know the length of the string, so we have to allocate memory dynamically
  3490 		TUint strlen = Kern::ThreadGetDesLength(aThread, aString);
  3506 		TUint strlen = Kern::ThreadGetDesLength(aThread, aString);
  3491 		if (strlen > KUsbStringDescStringMaxSize)
  3507 		if (strlen > KUsbStringDescStringMaxSize)
  3492 			{
  3508 			{
  3493 			__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: $ descriptor too long - string will be truncated"));
  3509 		    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP2, "  Warning: $ descriptor too long - string will be truncated" );
  3494 			strlen = KUsbStringDescStringMaxSize;
  3510 			strlen = KUsbStringDescStringMaxSize;
  3495 			}
  3511 			}
  3496 		HBuf8* const stringbuf = HBuf8::New(strlen);
  3512 		HBuf8* const stringbuf = HBuf8::New(strlen);
  3497 		if (!stringbuf)
  3513 		if (!stringbuf)
  3498 			{
  3514 			{
  3499 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Memory allocation for ifc $ desc string failed."));
  3515 	        OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP3, "  Error: Memory allocation for ifc $ desc string failed." );
  3500 			iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber,
  3516 			iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber,
  3501 											 aIfc->iSettingCode);
  3517 											 aIfc->iSettingCode);
  3502 			return KErrNoMemory;
  3518 			return KErrNoMemory;
  3503 			}
  3519 			}
  3504 		stringbuf->SetMax();
  3520 		stringbuf->SetMax();
  3505 		// the aString points to data that lives in user memory, so we have to copy it:
  3521 		// the aString points to data that lives in user memory, so we have to copy it:
  3506 		TInt r = Kern::ThreadDesRead(aThread, aString, *stringbuf, 0);
  3522 		TInt r = Kern::ThreadDesRead(aThread, aString, *stringbuf, 0);
  3507 		if (r != KErrNone)
  3523 		if (r != KErrNone)
  3508 			{
  3524 			{
  3509 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Thread read error"));
  3525 	         OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP4, "  Error: Thread read error" );
  3510 			iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber,
  3526 			iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber,
  3511 											 aIfc->iSettingCode);
  3527 											 aIfc->iSettingCode);
  3512 			delete stringbuf;
  3528 			delete stringbuf;
  3513 			return r;
  3529 			return r;
  3514 			}
  3530 			}
  3515 		TUsbcStringDescriptor* const sd = TUsbcStringDescriptor::New(*stringbuf);
  3531 		TUsbcStringDescriptor* const sd = TUsbcStringDescriptor::New(*stringbuf);
  3516 		if (!sd)
  3532 		if (!sd)
  3517 			{
  3533 			{
  3518 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Memory allocation for ifc $ desc failed."));
  3534 	        OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP5, "  Error: Memory allocation for ifc $ desc failed." );
  3519 			iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber,
  3535 			iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber,
  3520 											 aIfc->iSettingCode);
  3536 											 aIfc->iSettingCode);
  3521 			delete stringbuf;
  3537 			delete stringbuf;
  3522 			return KErrNoMemory;
  3538 			return KErrNoMemory;
  3523 			}
  3539 			}
  3537 			{
  3553 			{
  3538 			// if a non-standard endpoint descriptor is requested...
  3554 			// if a non-standard endpoint descriptor is requested...
  3539 			if (aEndpointData[i].iExtra != 2)
  3555 			if (aEndpointData[i].iExtra != 2)
  3540 				{
  3556 				{
  3541 				// ...then it must be a Audio Class endpoint descriptor. Else...
  3557 				// ...then it must be a Audio Class endpoint descriptor. Else...
  3542 				__KTRACE_OPT(KPANIC, Kern::Printf("  Error: EP desc extension > 2 bytes (%d)",
  3558 				OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP6, "  Error: EP desc extension > 2 bytes (%d)",
  3543 												  aEndpointData[i].iExtra));
  3559                                                   aEndpointData[i].iExtra);
  3544 				iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber,
  3560 				iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber,
  3545 												 aIfc->iSettingCode);
  3561 												 aIfc->iSettingCode);
  3546 				return KErrArgument;
  3562 				return KErrArgument;
  3547 				}
  3563 				}
  3548 			d = TUsbcAudioEndpointDescriptor::New(aIfc->iEndpoints[i]->iPEndpoint->iEndpointAddr,
  3564 			d = TUsbcAudioEndpointDescriptor::New(aIfc->iEndpoints[i]->iPEndpoint->iEndpointAddr,
  3553 			d = TUsbcEndpointDescriptor::New(aIfc->iEndpoints[i]->iPEndpoint->iEndpointAddr,
  3569 			d = TUsbcEndpointDescriptor::New(aIfc->iEndpoints[i]->iPEndpoint->iEndpointAddr,
  3554 											 aEndpointData[i]);
  3570 											 aEndpointData[i]);
  3555 			}
  3571 			}
  3556 		if (!d)
  3572 		if (!d)
  3557 			{
  3573 			{
  3558 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Memory allocation for ep desc #%d failed.", i));
  3574 			OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_SETUPIFCDESCRIPTOR_DUP7, "  Error: Memory allocation for ep desc #%d failed.", i);
  3559 			iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber,
  3575 			iDescriptors.DeleteIfcDescriptor(aIfc->iInterfaceSet->iInterfaceNumber,
  3560 											 aIfc->iSettingCode);
  3576 											 aIfc->iSettingCode);
  3561 			return KErrNoMemory;
  3577 			return KErrNoMemory;
  3562 			}
  3578 			}
  3563 		iDescriptors.InsertDescriptor(d);
  3579 		iDescriptors.InsertDescriptor(d);
  3619 	}
  3635 	}
  3620 
  3636 
  3621 
  3637 
  3622 TInt DUsbClientController::ActivateHardwareController()
  3638 TInt DUsbClientController::ActivateHardwareController()
  3623 	{
  3639 	{
  3624 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ActivateHardwareController()"));
  3640 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ACTIVATEHARDWARECONTROLLER, "DUsbClientController::ActivateHardwareController()" );
  3625 	if (iHardwareActivated)
  3641 	if (iHardwareActivated)
  3626 		{
  3642 		{
  3627 		__KTRACE_OPT(KUSB, Kern::Printf("  already active -> returning"));
  3643 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ACTIVATEHARDWARECONTROLLER_DUP1, "  already active -> returning" );
  3628 		return KErrNone;
  3644 		return KErrNone;
  3629 		}
  3645 		}
  3630 	// Initialise HW
  3646 	// Initialise HW
  3631 	TInt r = StartUdc();
  3647 	TInt r = StartUdc();
  3632 	if (r != KErrNone)
  3648 	if (r != KErrNone)
  3633 		{
  3649 		{
  3634 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: StartUdc() failed"));
  3650 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ACTIVATEHARDWARECONTROLLER_DUP2, "  Error: StartUdc() failed" );
  3635 		return KErrHardwareNotAvailable;
  3651 		return KErrHardwareNotAvailable;
  3636 		}
  3652 		}
  3637 	r = OtgEnableUdc();							   // turn on UDC (OTG flavour)
  3653 	r = OtgEnableUdc();							   // turn on UDC (OTG flavour)
  3638 	if (r != KErrNone)
  3654 	if (r != KErrNone)
  3639 		{
  3655 		{
  3640 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: OtgEnableUdc() failed: %d", r));
  3656 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_ACTIVATEHARDWARECONTROLLER_DUP3, "  Error: OtgEnableUdc() failed: %d", r);
  3641 		}
  3657 		}
  3642 	iHardwareActivated = ETrue;
  3658 	iHardwareActivated = ETrue;
  3643 
  3659 
  3644 	// Configure & enable endpoint zero
  3660 	// Configure & enable endpoint zero
  3645 	const TUsbcLogicalEndpoint* const ep0_0 = iRealEndpoints[0].iLEndpoint;
  3661 	const TUsbcLogicalEndpoint* const ep0_0 = iRealEndpoints[0].iLEndpoint;
  3656 		}
  3672 		}
  3657 	ConfigureEndpoint(0, ep0_0->iInfo);
  3673 	ConfigureEndpoint(0, ep0_0->iInfo);
  3658 	ConfigureEndpoint(1, ep0_1->iInfo);
  3674 	ConfigureEndpoint(1, ep0_1->iInfo);
  3659 	iEp0MaxPacketSize = ep0_0->iInfo.iSize;
  3675 	iEp0MaxPacketSize = ep0_0->iInfo.iSize;
  3660 
  3676 
  3661 	__KTRACE_OPT(KUSB, Kern::Printf("  Controller activated."));
  3677     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_ACTIVATEHARDWARECONTROLLER_DUP4, "  Controller activated.");
  3662 	if (UsbConnectionStatus())
  3678 	if (UsbConnectionStatus())
  3663 		{
  3679 		{
  3664 		if (iDeviceState == EUsbcDeviceStateUndefined)
  3680 		if (iDeviceState == EUsbcDeviceStateUndefined)
  3665 			{
  3681 			{
  3666 			NextDeviceState(EUsbcDeviceStateAttached);
  3682 			NextDeviceState(EUsbcDeviceStateAttached);
  3671 	}
  3687 	}
  3672 
  3688 
  3673 
  3689 
  3674 void DUsbClientController::DeActivateHardwareController()
  3690 void DUsbClientController::DeActivateHardwareController()
  3675 	{
  3691 	{
  3676 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeActivateHardwareController()"));
  3692 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER, "DUsbClientController::DeActivateHardwareController()" );
  3677 	if (!iHardwareActivated)
  3693 	if (!iHardwareActivated)
  3678 		{
  3694 		{
  3679 		__KTRACE_OPT(KUSB, Kern::Printf("  not active -> returning"));
  3695 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER_DUP1, "  not active -> returning" );
  3680 		return;
  3696 		return;
  3681 		}
  3697 		}
  3682 	// Deconfigure & disable endpoint zero
  3698 	// Deconfigure & disable endpoint zero
  3683 	DeConfigureEndpoint(KEp0_Out);
  3699 	DeConfigureEndpoint(KEp0_Out);
  3684 	DeConfigureEndpoint(KEp0_In);
  3700 	DeConfigureEndpoint(KEp0_In);
  3685 	// Stop HW
  3701 	// Stop HW
  3686 	TInt r = OtgDisableUdc();					  // turn off UDC (OTG flavour)
  3702 	TInt r = OtgDisableUdc();					  // turn off UDC (OTG flavour)
  3687 	if (r != KErrNone)
  3703 	if (r != KErrNone)
  3688 		{
  3704 		{
  3689 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: OtgDisableUdc() failed: %d", r));
  3705 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER_DUP2, "  Error: OtgDisableUdc() failed: %d", r);
  3690 		}
  3706 		}
  3691 	StopUdc();
  3707 	StopUdc();
  3692 	iHardwareActivated = EFalse;
  3708 	iHardwareActivated = EFalse;
  3693 	__KTRACE_OPT(KUSB, Kern::Printf("  Controller deactivated."));
  3709     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DEACTIVATEHARDWARECONTROLLER_DUP3, "  Controller deactivated.");
  3694 	if (UsbConnectionStatus())
  3710 	if (UsbConnectionStatus())
  3695 		{
  3711 		{
  3696 		NextDeviceState(EUsbcDeviceStateAttached);
  3712 		NextDeviceState(EUsbcDeviceStateAttached);
  3697 		}
  3713 		}
  3698 	return;
  3714 	return;
  3699 	}
  3715 	}
  3700 
  3716 
  3701 
  3717 
  3702 void DUsbClientController::DeleteInterfaceSet(TInt aIfcSet)
  3718 void DUsbClientController::DeleteInterfaceSet(TInt aIfcSet)
  3703 	{
  3719 	{
  3704 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeleteInterfaceSet(%d)", aIfcSet));
  3720 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEINTERFACESET, "DUsbClientController::DeleteInterfaceSet(%d)", aIfcSet);
       
  3721 	
  3705 	TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(aIfcSet);
  3722 	TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(aIfcSet);
  3706 	if (!ifcset_ptr)
  3723 	if (!ifcset_ptr)
  3707 		{
  3724 		{
  3708 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: invalid interface number: %d", aIfcSet));
  3725 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DELETEINTERFACESET_DUP1, "  Error: invalid interface number: %d", aIfcSet);
  3709 		return;
  3726 		return;
  3710 		}
  3727 		}
  3711 	const TInt idx = iConfigs[0]->iInterfaceSets.Find(ifcset_ptr);
  3728 	const TInt idx = iConfigs[0]->iInterfaceSets.Find(ifcset_ptr);
  3712 	if (idx == KErrNotFound)
  3729 	if (idx == KErrNotFound)
  3713 		{
  3730 		{
  3714 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: interface not found in array"));
  3731 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DELETEINTERFACESET_DUP2, "  Error: interface not found in array");
  3715 		return;
  3732 		return;
  3716 		}
  3733 		}
  3717 	//Add this mutex to protect the interface set data structure
  3734 	//Add this mutex to protect the interface set data structure
  3718 	if (NKern::CurrentContext() == EThread)
  3735 	if (NKern::CurrentContext() == EThread)
  3719 	    {
  3736 	    {
  3729 	}
  3746 	}
  3730 
  3747 
  3731 
  3748 
  3732 void DUsbClientController::DeleteInterface(TInt aIfcSet, TInt aIfc)
  3749 void DUsbClientController::DeleteInterface(TInt aIfcSet, TInt aIfc)
  3733 	{
  3750 	{
  3734 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeleteInterface(%d, %d)", aIfcSet, aIfc));
  3751 	OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEINTERFACE, "DUsbClientController::DeleteInterface(%d, %d)", aIfcSet, aIfc);
       
  3752 	
  3735 	TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(aIfcSet);
  3753 	TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(aIfcSet);
  3736 	if (!ifcset_ptr)
  3754 	if (!ifcset_ptr)
  3737 		{
  3755 		{
  3738 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: invalid interface number: %d", aIfcSet));
  3756 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DELETEINTERFACE_DUP1, " Error: invalid interface number: %d", aIfcSet);
  3739 		return;
  3757 		return;
  3740 		}
  3758 		}
  3741 	if (ifcset_ptr->iInterfaces.Count() <= aIfc)
  3759 	if (ifcset_ptr->iInterfaces.Count() <= aIfc)
  3742 		{
  3760 		{
  3743 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: invalid interface setting: %d", aIfc));
  3761 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_DELETEINTERFACE_DUP2, "  Error: invalid interface setting: %d", aIfc);
  3744 		return;
  3762 		return;
  3745 		}
  3763 		}
  3746 	//Add this mutex to protect the interface set data structure
  3764 	//Add this mutex to protect the interface set data structure
  3747 	if (NKern::CurrentContext() == EThread)
  3765 	if (NKern::CurrentContext() == EThread)
  3748 	    {
  3766 	    {
  3752 	// Always first remove, then delete (see ~TUsbcLogicalEndpoint() for the reason why)
  3770 	// Always first remove, then delete (see ~TUsbcLogicalEndpoint() for the reason why)
  3753 	ifcset_ptr->iInterfaces.Remove(aIfc);
  3771 	ifcset_ptr->iInterfaces.Remove(aIfc);
  3754 
  3772 
  3755 	if (aIfc == ifcset_ptr->iCurrentInterface)
  3773 	if (aIfc == ifcset_ptr->iCurrentInterface)
  3756 		{
  3774 		{
  3757 		__KTRACE_OPT(KUSB, Kern::Printf(" > Warning: deleting current interface setting"));
  3775 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEINTERFACE_DUP3, " > Warning: deleting current interface setting");
  3758 		ifcset_ptr->iCurrentInterface = 0;
  3776 		ifcset_ptr->iCurrentInterface = 0;
  3759 		}
  3777 		}
  3760 	if (NKern::CurrentContext() == EThread)
  3778 	if (NKern::CurrentContext() == EThread)
  3761 	    {
  3779 	    {
  3762         NKern::FMSignal(&iMutex);
  3780         NKern::FMSignal(&iMutex);
  3765 	}
  3783 	}
  3766 
  3784 
  3767 
  3785 
  3768 void DUsbClientController::CancelTransferRequests(TInt aRealEndpoint)
  3786 void DUsbClientController::CancelTransferRequests(TInt aRealEndpoint)
  3769 	{
  3787 	{
  3770 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CancelTransferRequests(aRealEndpoint=%d)",
  3788 	OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_CANCELTRANSFERREQUESTS, "DUsbClientController::CancelTransferRequests(aRealEndpoint=%d)",
  3771 									aRealEndpoint));
  3789                                     aRealEndpoint);
       
  3790 	
  3772 	const DBase* const clientId = PEndpoint2ClientId(aRealEndpoint);
  3791 	const DBase* const clientId = PEndpoint2ClientId(aRealEndpoint);
  3773 	if (EpIdx2Addr(aRealEndpoint) & KUsbEpAddress_In)
  3792 	if (EpIdx2Addr(aRealEndpoint) & KUsbEpAddress_In)
  3774 		{
  3793 		{
  3775 		CancelWriteBuffer(clientId, aRealEndpoint);
  3794 		CancelWriteBuffer(clientId, aRealEndpoint);
  3776 		}
  3795 		}
  3782 
  3801 
  3783 
  3802 
  3784 void DUsbClientController::DeleteRequestCallback(const DBase* aClientId, TInt aEndpointNum,
  3803 void DUsbClientController::DeleteRequestCallback(const DBase* aClientId, TInt aEndpointNum,
  3785 												 TTransferDirection aTransferDir)
  3804 												 TTransferDirection aTransferDir)
  3786 	{
  3805 	{
  3787 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeleteRequestCallback()"));
  3806 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACK, "DUsbClientController::DeleteRequestCallback()" );
  3788 	// Ep0 OUT
  3807 	// Ep0 OUT
  3789 	if (aEndpointNum == 0)
  3808 	if (aEndpointNum == 0)
  3790 		{
  3809 		{
  3791 	    const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  3810 	    const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  3792 		TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks);
  3811 		TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks);
  3795 			{
  3814 			{
  3796 			if (p->Owner() == aClientId)
  3815 			if (p->Owner() == aClientId)
  3797 				{
  3816 				{
  3798 				__ASSERT_DEBUG((p->iRealEpNum == 0), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3817 				__ASSERT_DEBUG((p->iRealEpNum == 0), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3799 				__ASSERT_DEBUG((p->iTransferDir == EControllerRead), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3818 				__ASSERT_DEBUG((p->iTransferDir == EControllerRead), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3800 				__KTRACE_OPT(KUSB, Kern::Printf("  removing RequestCallback @ 0x%x (ep0)", p));
  3819 			    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACK_DUP1, "  removing RequestCallback @ 0x%x (ep0)", p);
  3801 				iEp0ReadRequestCallbacks.Remove(*p);
  3820 				iEp0ReadRequestCallbacks.Remove(*p);
  3802 				}
  3821 				}
  3803 			}
  3822 			}
  3804         __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  3823         __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  3805 		return;
  3824 		return;
  3808 	TUsbcRequestCallback* const p = iRequestCallbacks[aEndpointNum];
  3827 	TUsbcRequestCallback* const p = iRequestCallbacks[aEndpointNum];
  3809 	if (p)
  3828 	if (p)
  3810 		{
  3829 		{
  3811  		__ASSERT_DEBUG((p->Owner() == aClientId), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3830  		__ASSERT_DEBUG((p->Owner() == aClientId), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3812 		__ASSERT_DEBUG((p->iTransferDir == aTransferDir), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3831 		__ASSERT_DEBUG((p->iTransferDir == aTransferDir), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3813 		__KTRACE_OPT(KUSB, Kern::Printf("  removing RequestCallback @ 0x%x", p));
  3832         OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACK_DUP2, "  removing RequestCallback @ 0x%x", p);
  3814 		iRequestCallbacks[aEndpointNum] = NULL;
  3833 		iRequestCallbacks[aEndpointNum] = NULL;
  3815 		}
  3834 		}
  3816 	}
  3835 	}
  3817 
  3836 
  3818 
  3837 
  3819 void DUsbClientController::DeleteRequestCallbacks(const DBase* aClientId)
  3838 void DUsbClientController::DeleteRequestCallbacks(const DBase* aClientId)
  3820 	{
  3839 	{
  3821 	// aClientId being NULL means: delete all requests for *all* clients.
  3840 	// aClientId being NULL means: delete all requests for *all* clients.
  3822 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DeleteRequestCallbacks()"));
  3841 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACKS, "DUsbClientController::DeleteRequestCallbacks()" );
  3823 	// Ep0 OUT
  3842 	// Ep0 OUT
  3824     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  3843     const TInt irq = __SPIN_LOCK_IRQSAVE(iUsbLock);
  3825 	TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks);
  3844 	TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks);
  3826 	TUsbcRequestCallback* p;
  3845 	TUsbcRequestCallback* p;
  3827 	while ((p = iter++) != NULL)
  3846 	while ((p = iter++) != NULL)
  3828 		{
  3847 		{
  3829 		if (!aClientId || p->Owner() == aClientId)
  3848 		if (!aClientId || p->Owner() == aClientId)
  3830 			{
  3849 			{
  3831 			__KTRACE_OPT(KUSB, Kern::Printf("  removing RequestCallback @ 0x%x (ep0)", p));
  3850 			 OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACKS_DUP1, "  removing RequestCallback @ 0x%x (ep0)", p);
  3832 			iEp0ReadRequestCallbacks.Remove(*p);
  3851 			iEp0ReadRequestCallbacks.Remove(*p);
  3833 			}
  3852 			}
  3834 		}
  3853 		}
  3835     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  3854     __SPIN_UNLOCK_IRQRESTORE(iUsbLock, irq);
  3836 	// Other endpoints
  3855 	// Other endpoints
  3837 	for (TInt i = 1; i < KUsbcEpArraySize; i++)
  3856 	for (TInt i = 1; i < KUsbcEpArraySize; i++)
  3838 		{
  3857 		{
  3839 		TUsbcRequestCallback* const p = iRequestCallbacks[i];
  3858 		TUsbcRequestCallback* const p = iRequestCallbacks[i];
  3840 		if (p && (!aClientId || p->Owner() == aClientId))
  3859 		if (p && (!aClientId || p->Owner() == aClientId))
  3841 			{
  3860 			{
  3842 			__KTRACE_OPT(KUSB, Kern::Printf("  removing RequestCallback @ 0x%x", p));
  3861 	        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_DELETEREQUESTCALLBACKS_DUP2, "  removing RequestCallback @ 0x%x", p);
  3843 			iRequestCallbacks[i] = NULL;
  3862 			iRequestCallbacks[i] = NULL;
  3844 			}
  3863 			}
  3845 		}
  3864 		}
  3846 	}
  3865 	}
  3847 
  3866 
  3848 
  3867 
  3849 void DUsbClientController::StatusNotify(TUsbcDeviceState aState, const DBase* aClientId)
  3868 void DUsbClientController::StatusNotify(TUsbcDeviceState aState, const DBase* aClientId)
  3850 	{
  3869 	{
  3851 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::StatusNotify()"));
  3870     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_STATUSNOTIFY, "DUsbClientController::StatusNotify()" );
  3852 
  3871 
  3853 	// This function may be called by the PSL (via chapter9.cpp) from within an
  3872 	// This function may be called by the PSL (via chapter9.cpp) from within an
  3854 	// ISR -- so we have to take care what we do here (and also in all
  3873 	// ISR -- so we have to take care what we do here (and also in all
  3855 	// functions that get called from here).
  3874 	// functions that get called from here).
  3856 
  3875 
  3858 	TUsbcStatusCallback* p;
  3877 	TUsbcStatusCallback* p;
  3859 	while ((p = iter++) != NULL)
  3878 	while ((p = iter++) != NULL)
  3860 		{
  3879 		{
  3861 		if (!aClientId || aClientId == p->Owner())
  3880 		if (!aClientId || aClientId == p->Owner())
  3862 			{
  3881 			{
  3863 			__KTRACE_OPT(KUSB, Kern::Printf("  notifying LDD @ 0x%x about %d", p->Owner(), aState));
  3882 		    OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_STATUSNOTIFY_DUP1, "  notifying LDD @ 0x%x about %d", (TUint)p->Owner(), (TUint)aState);
  3864 			p->SetState(aState);
  3883 			p->SetState(aState);
  3865 			p->DoCallback();
  3884 			p->DoCallback();
  3866 			}
  3885 			}
  3867 		}
  3886 		}
  3868 	}
  3887 	}
  3869 
  3888 
  3870 
  3889 
  3871 void DUsbClientController::EpStatusNotify(TInt aRealEndpoint)
  3890 void DUsbClientController::EpStatusNotify(TInt aRealEndpoint)
  3872 	{
  3891 	{
  3873 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EpStatusNotify()"));
  3892     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY, "DUsbClientController::EpStatusNotify()" );
  3874 
  3893 
  3875 	// This function may be called by the PSL (via chapter9.cpp) from within an
  3894 	// This function may be called by the PSL (via chapter9.cpp) from within an
  3876 	// ISR -- so we have to take care what we do here (and also in all
  3895 	// ISR -- so we have to take care what we do here (and also in all
  3877 	// functions that get called from here).
  3896 	// functions that get called from here).
  3878 
  3897 
  3879 	const DBase* const client_id = PEndpoint2ClientId(aRealEndpoint);
  3898 	const DBase* const client_id = PEndpoint2ClientId(aRealEndpoint);
  3880 	if (!client_id)
  3899 	if (!client_id)
  3881 		{
  3900 		{
  3882 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Client not found for real ep %d", aRealEndpoint));
  3901 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP1, "  Error: Client not found for real ep %d", aRealEndpoint);
  3883 		return;
  3902 		return;
  3884 		}
  3903 		}
  3885 	// Check if there is a notification request queued for that client (if not, we can return here).
  3904 	// Check if there is a notification request queued for that client (if not, we can return here).
  3886 	TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks);
  3905 	TSglQueIter<TUsbcEndpointStatusCallback> iter(iEpStatusCallbacks);
  3887 	TUsbcEndpointStatusCallback* p;
  3906 	TUsbcEndpointStatusCallback* p;
  3892 			break;
  3911 			break;
  3893 			}
  3912 			}
  3894 		}
  3913 		}
  3895 	if (!p)
  3914 	if (!p)
  3896 		{
  3915 		{
  3897 		__KTRACE_OPT(KUSB, Kern::Printf("  No notification request for that client, returning"));
  3916 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP2, "  No notification request for that client, returning");
  3898 		return;
  3917 		return;
  3899 		}
  3918 		}
  3900 	const TInt ifcset = ClientId2InterfaceNumber(client_id);
  3919 	const TInt ifcset = ClientId2InterfaceNumber(client_id);
  3901 	if (ifcset < 0)
  3920 	if (ifcset < 0)
  3902 		{
  3921 		{
  3903 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Ifcset not found for clientid %d", client_id));
  3922 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP3, "  Error: Ifcset not found for clientid %d", client_id);
  3904 		return;
  3923 		return;
  3905 		}
  3924 		}
  3906 	const TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset);
  3925 	const TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(ifcset);
  3907 	if (!ifcset_ptr)
  3926 	if (!ifcset_ptr)
  3908 		{
  3927 		{
  3909 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Ifcset pointer not found for ifcset %d", ifcset));
  3928 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP4, "  Error: Ifcset pointer not found for ifcset %d", ifcset);
  3910 		return;
  3929 		return;
  3911 		}
  3930 		}
  3912 	const TUsbcInterface* const ifc_ptr = ifcset_ptr->CurrentInterface();
  3931 	const TUsbcInterface* const ifc_ptr = ifcset_ptr->CurrentInterface();
  3913 	if (!ifc_ptr)
  3932 	if (!ifc_ptr)
  3914 		{
  3933 		{
  3915 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Current ifc pointer not found for ifcset %d", ifcset));
  3934 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP5, "  Error: Current ifc pointer not found for ifcset %d", ifcset);
  3916 		return;
  3935 		return;
  3917 		}
  3936 		}
  3918 	TUint state = 0;
  3937 	TUint state = 0;
  3919 	const TInt eps = ifc_ptr->iEndpoints.Count();
  3938 	const TInt eps = ifc_ptr->iEndpoints.Count();
  3920 	for (TInt i = 0; i < eps; i++)
  3939 	for (TInt i = 0; i < eps; i++)
  3921 		{
  3940 		{
  3922 		const TUsbcLogicalEndpoint* const ep_ptr = ifc_ptr->iEndpoints[i];
  3941 		const TUsbcLogicalEndpoint* const ep_ptr = ifc_ptr->iEndpoints[i];
  3923 		__KTRACE_OPT(KUSB, Kern::Printf("  checking logical ep #%d for stall state...",
  3942 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP6, "  checking logical ep #%d for stall state...",
  3924 										ep_ptr->iLEndpointNum));
  3943                                         ep_ptr->iLEndpointNum);
  3925 		if (ep_ptr->iPEndpoint->iHalt)
  3944 		if (ep_ptr->iPEndpoint->iHalt)
  3926 			{
  3945 			{
  3927 			__KTRACE_OPT(KUSB, Kern::Printf("  -- stalled"));
  3946 			OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP7, "  -- stalled");
  3928 			// set the bit n to 1, where n is the logical endpoint number minus one
  3947 			// set the bit n to 1, where n is the logical endpoint number minus one
  3929 			state |= (1 << (ep_ptr->iLEndpointNum - 1));
  3948 			state |= (1 << (ep_ptr->iLEndpointNum - 1));
  3930 			}
  3949 			}
  3931 		else
  3950 		else
  3932 			{
  3951 			{
  3933 			__KTRACE_OPT(KUSB, Kern::Printf("  -- not stalled"));
  3952 	        OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP8, "  -- not stalled");
  3934 			}
  3953 			}
  3935 		}
  3954 		}
  3936 	__KTRACE_OPT(KUSB, Kern::Printf(" passing ep state 0x%x on to LDD @ 0x%x", state, client_id));
  3955     OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EPSTATUSNOTIFY_DUP9, " passing ep state 0x%x on to LDD @ 0x%x", (TUint)state, (TUint)client_id);
  3937 	p->SetState(state);
  3956 	p->SetState(state);
  3938 	p->DoCallback();
  3957 	p->DoCallback();
  3939 	}
  3958 	}
  3940 
  3959 
  3941 
  3960 
  3942 void DUsbClientController::OtgFeaturesNotify()
  3961 void DUsbClientController::OtgFeaturesNotify()
  3943 	{
  3962 	{
  3944 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::OtgFeaturesNotify()"));
  3963     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_OTGFEATURESNOTIFY, "DUsbClientController::OtgFeaturesNotify()" );
  3945 
  3964 
  3946 	// This function may be called from the PSL (via PIL's chapter9.cpp) from
  3965 	// This function may be called from the PSL (via PIL's chapter9.cpp) from
  3947 	// within an ISR -- so we have to take care what we do here (and also in
  3966 	// within an ISR -- so we have to take care what we do here (and also in
  3948 	// all functions that get called from here).
  3967 	// all functions that get called from here).
  3949 
  3968 
  3957 	}
  3976 	}
  3958 
  3977 
  3959 
  3978 
  3960 void DUsbClientController::RunClientCallbacks()
  3979 void DUsbClientController::RunClientCallbacks()
  3961 	{
  3980 	{
  3962 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::RunClientCallbacks()"));
  3981 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_RUNCLIENTCALLBACKS, "DUsbClientController::RunClientCallbacks()" );
  3963 	TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks);
  3982 	TSglQueIter<TUsbcClientCallback> iter(iClientCallbacks);
  3964 	TUsbcClientCallback* p;
  3983 	TUsbcClientCallback* p;
  3965 	while ((p = iter++) != NULL)
  3984 	while ((p = iter++) != NULL)
  3966 		{
  3985 		{
  3967 		__KTRACE_OPT(KUSB, Kern::Printf("Callback 0x%x", p));
  3986 		OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_RUNCLIENTCALLBACKS_DUP1, "Callback 0x%x", p);
  3968 		p->DoCallback();
  3987 		p->DoCallback();
  3969 		}
  3988 		}
  3970 	}
  3989 	}
  3971 
  3990 
  3972 
  3991 
  3973 void DUsbClientController::ProcessDataTransferDone(TUsbcRequestCallback& aRcb)
  3992 void DUsbClientController::ProcessDataTransferDone(TUsbcRequestCallback& aRcb)
  3974 	{
  3993 	{
  3975 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessDataTransferDone()"));
  3994 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSDATATRANSFERDONE, "DUsbClientController::ProcessDataTransferDone()" );
  3976 	// This piece can only be called in thread context from ProcessEp0DataReceived() /
  3995 	// This piece can only be called in thread context from ProcessEp0DataReceived() /
  3977 	// ProcessEp0SetupReceived() via the call to ProcessEp0ReceiveDone() in
  3996 	// ProcessEp0SetupReceived() via the call to ProcessEp0ReceiveDone() in
  3978 	// SetupReadBuffer(), which is guarded by an interrupt lock.
  3997 	// SetupReadBuffer(), which is guarded by an interrupt lock.
  3979 	TInt ep = aRcb.iRealEpNum;
  3998 	TInt ep = aRcb.iRealEpNum;
  3980 	if (ep == 0)
  3999 	if (ep == 0)
  3991 			}
  4010 			}
  3992 		}
  4011 		}
  3993 	if (ep > 0)												// not 'else'!
  4012 	if (ep > 0)												// not 'else'!
  3994 		{
  4013 		{
  3995 		__ASSERT_DEBUG((iRequestCallbacks[ep] == &aRcb), Kern::Fault(KUsbPILPanicCat, __LINE__));
  4014 		__ASSERT_DEBUG((iRequestCallbacks[ep] == &aRcb), Kern::Fault(KUsbPILPanicCat, __LINE__));
  3996 		__KTRACE_OPT(KUSB, Kern::Printf(" > removing RequestCallback[%d] @ 0x%x", ep, &aRcb));
  4015 		OstTraceDefExt2(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSDATATRANSFERDONE_DUP1, " > removing RequestCallback[%d] @ 0x%x", ep, (TUint)&aRcb);
  3997 		iRequestCallbacks[ep] = NULL;
  4016 		iRequestCallbacks[ep] = NULL;
  3998 		}
  4017 		}
  3999 	aRcb.DoCallback();
  4018 	aRcb.DoCallback();
  4000 	}
  4019 	}
  4001 
  4020 
  4002 
  4021 
  4003 void DUsbClientController::NextDeviceState(TUsbcDeviceState aNextState)
  4022 void DUsbClientController::NextDeviceState(TUsbcDeviceState aNextState)
  4004 	{
  4023 	{
  4005 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::NextDeviceState()"));
  4024     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE, "DUsbClientController::NextDeviceState()" );
       
  4025     
  4006 #ifdef _DEBUG
  4026 #ifdef _DEBUG
       
  4027 #ifdef OST_TRACE_COMPILER_IN_USE
  4007 	const char* const states[] = {"Undefined", "Attached", "Powered", "Default",
  4028 	const char* const states[] = {"Undefined", "Attached", "Powered", "Default",
  4008 								  "Address", "Configured", "Suspended"};
  4029 								  "Address", "Configured", "Suspended"};
       
  4030 #endif
  4009 	if ((aNextState >= EUsbcDeviceStateUndefined) &&
  4031 	if ((aNextState >= EUsbcDeviceStateUndefined) &&
  4010 		(aNextState <= EUsbcDeviceStateSuspended))
  4032 		(aNextState <= EUsbcDeviceStateSuspended))
  4011 		{
  4033 		{
  4012 		__KTRACE_OPT(KUSB, Kern::Printf("  next device state: %s", states[aNextState]));
  4034 	    OstTraceDefExt1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP1, "  next device state: %s", states[aNextState]);
  4013 		}
  4035 		}
  4014 	else
  4036 	else
  4015 		{
  4037 		{
  4016 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Unknown next device state: %d", aNextState));
  4038 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP2, "  Error: Unknown next device state: %d", aNextState);
  4017 		}
  4039 		}
  4018 	// Print a warning when an invalid state transition is detected
  4040 	// Print a warning when an invalid state transition is detected
  4019 	// 'Undefined' is not a state that is mentioned in the USB spec, but
  4041 	// 'Undefined' is not a state that is mentioned in the USB spec, but
  4020 	// that's what we're in once the cable gets pulled (for instance).
  4042 	// that's what we're in once the cable gets pulled (for instance).
  4021 	switch (iDeviceState)
  4043 	switch (iDeviceState)
  4074 			(aNextState != EUsbcDeviceStateAddress) &&
  4096 			(aNextState != EUsbcDeviceStateAddress) &&
  4075 			(aNextState != EUsbcDeviceStateConfigured))
  4097 			(aNextState != EUsbcDeviceStateConfigured))
  4076 			break;
  4098 			break;
  4077 		goto OK;
  4099 		goto OK;
  4078 	default:
  4100 	default:
  4079 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Unknown current device state: %d", iDeviceState));
  4101 	    OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP3, "  Error: Unknown current device state: %d", iDeviceState);
  4080 		goto OK;
  4102 		goto OK;
  4081 		}
  4103 		}
  4082 	// KUSB only (instead of KPANIC) so as not to worry people too much where
  4104 	// KUSB only (instead of KPANIC) so as not to worry people too much where
  4083 	// a particular h/w regularly enforces invalid (but harmless) transitions
  4105 	// a particular h/w regularly enforces invalid (but harmless) transitions
  4084 	__KTRACE_OPT(KUSB, Kern::Printf("  Warning: Invalid next state from %s", states[iDeviceState]));
  4106     OstTraceDefExt1(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_NEXTDEVICESTATE_DUP4, "  Warning: Invalid next state from %s", states[iDeviceState]);
  4085 OK:
  4107 OK:
  4086 #endif // _DEBUG
  4108 #endif // _DEBUG
  4087 
  4109 
  4088 	iDeviceState = aNextState;
  4110 	iDeviceState = aNextState;
  4089 	StatusNotify(iDeviceState);
  4111 	StatusNotify(iDeviceState);
  4090 	}
  4112 	}
  4091 
  4113 
  4092 
  4114 
  4093 TInt DUsbClientController::ProcessSuspendEvent()
  4115 TInt DUsbClientController::ProcessSuspendEvent()
  4094 	{
  4116 	{
  4095 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSuspendEvent()"));
  4117 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSSUSPENDEVENT, "DUsbClientController::ProcessSuspendEvent()" );
  4096 	// A suspend interrupt has been received and needs attention.
  4118 	// A suspend interrupt has been received and needs attention.
  4097 	iDeviceStateB4Suspend = iDeviceState;
  4119 	iDeviceStateB4Suspend = iDeviceState;
  4098 	// We have to move to the Suspend state immediately (in case it's a genuine Suspend)
  4120 	// We have to move to the Suspend state immediately (in case it's a genuine Suspend)
  4099 	// because 7.1.7.6 says: "The device must actually be suspended, [...] after no more
  4121 	// because 7.1.7.6 says: "The device must actually be suspended, [...] after no more
  4100 	// than 10ms of bus inactivity [...]." Assuming we got the interrupt 3ms after the
  4122 	// than 10ms of bus inactivity [...]." Assuming we got the interrupt 3ms after the
  4114 //
  4136 //
  4115 // ISR (from CableStatusTimerCallback)
  4137 // ISR (from CableStatusTimerCallback)
  4116 //
  4138 //
  4117 TInt DUsbClientController::ProcessSuspendEventProceed()
  4139 TInt DUsbClientController::ProcessSuspendEventProceed()
  4118 	{
  4140 	{
  4119 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSuspendEventProceed()"));
  4141 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSSUSPENDEVENTPROCEED, "DUsbClientController::ProcessSuspendEventProceed()" );
  4120 	if (!UsbConnectionStatus())
  4142 	if (!UsbConnectionStatus())
  4121 		{
  4143 		{
  4122 		// If we are no longer connected to the bus, we go into Undefined state (from Suspend).
  4144 		// If we are no longer connected to the bus, we go into Undefined state (from Suspend).
  4123 		__KTRACE_OPT(KUSB, Kern::Printf(" > USB cable detached"));
  4145 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSSUSPENDEVENTPROCEED_DUP1, " > USB cable detached" );
  4124 		NextDeviceState(EUsbcDeviceStateUndefined);
  4146 		NextDeviceState(EUsbcDeviceStateUndefined);
  4125 		}
  4147 		}
  4126 	return KErrNone;
  4148 	return KErrNone;
  4127 	}
  4149 	}
  4128 
  4150 
  4129 
  4151 
  4130 TInt DUsbClientController::ProcessResumeEvent()
  4152 TInt DUsbClientController::ProcessResumeEvent()
  4131 	{
  4153 	{
  4132 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessResumeEvent()"));
  4154 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSRESUMEEVENT, "DUsbClientController::ProcessResumeEvent()" );
  4133 	iCableStatusTimer.Cancel();
  4155 	iCableStatusTimer.Cancel();
  4134 	if (iDeviceState == EUsbcDeviceStateSuspended)
  4156 	if (iDeviceState == EUsbcDeviceStateSuspended)
  4135 		{
  4157 		{
  4136 		NextDeviceState(iDeviceStateB4Suspend);
  4158 		NextDeviceState(iDeviceStateB4Suspend);
  4137 		}
  4159 		}
  4140 	}
  4162 	}
  4141 
  4163 
  4142 
  4164 
  4143 TInt DUsbClientController::ProcessResetEvent(TBool aPslUpcall)
  4165 TInt DUsbClientController::ProcessResetEvent(TBool aPslUpcall)
  4144 	{
  4166 	{
  4145 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessResetEvent()"));
  4167     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT, "DUsbClientController::ProcessResetEvent()" );
  4146 
  4168 
  4147 	if (aPslUpcall)
  4169 	if (aPslUpcall)
  4148 		{
  4170 		{
  4149 		// Call back into PSL if we're coming from there.
  4171 		// Call back into PSL if we're coming from there.
  4150 		// Also, do it always, even when PIL processing will be deferred.
  4172 		// Also, do it always, even when PIL processing will be deferred.
  4151 		Reset();
  4173 		Reset();
  4152 		}
  4174 		}
  4153 
       
  4154 #ifdef USB_OTG_CLIENT
  4175 #ifdef USB_OTG_CLIENT
  4155 	if (iUsbResetDeferred) // implies (iOtgHnpHandledByHw == ETrue)
  4176 	if (iUsbResetDeferred) // implies (iOtgHnpHandledByHw == ETrue)
  4156 		{
  4177 		{
  4157 		__KTRACE_OPT(KUSB, Kern::Printf("  User-side (still) not ready -> returning"));
  4178 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP1, "  User-side (still) not ready -> returning" );
  4158 		return KErrNone;
  4179 		return KErrNone;
  4159 		}
  4180 		}
  4160 	else if (iOtgHnpHandledByHw && !iClientSupportReady)
  4181 	else if (iOtgHnpHandledByHw && !iClientSupportReady)
  4161 		{
  4182 		{
  4162 		// Wait with the PIL Reset processing until user-side is ready
  4183 		// Wait with the PIL Reset processing until user-side is ready
  4163 		__KTRACE_OPT(KUSB, Kern::Printf("  User-side not ready -> deferring"));
  4184 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP2, "  User-side not ready -> deferring" );
  4164 		iUsbResetDeferred = ETrue;
  4185 		iUsbResetDeferred = ETrue;
  4165 		return KErrNone;
  4186 		return KErrNone;
  4166 		}
  4187 		}
  4167 #endif // USB_OTG_CLIENT
  4188 #endif // USB_OTG_CLIENT
  4168 
  4189 
  4193 	// Check whether there's a speed change
  4214 	// Check whether there's a speed change
  4194 	const TBool was_hs = iHighSpeed;
  4215 	const TBool was_hs = iHighSpeed;
  4195 	iHighSpeed = CurrentlyUsingHighSpeed();
  4216 	iHighSpeed = CurrentlyUsingHighSpeed();
  4196 	if (!was_hs && iHighSpeed)
  4217 	if (!was_hs && iHighSpeed)
  4197 		{
  4218 		{
  4198 		__KTRACE_OPT(KUSB, Kern::Printf("  Moving to High-speed"));
  4219 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP3, "  Moving to High-speed" );
  4199 		EnterHighSpeed();
  4220 		EnterHighSpeed();
  4200 		}
  4221 		}
  4201 	else if (was_hs && !iHighSpeed)
  4222 	else if (was_hs && !iHighSpeed)
  4202 		{
  4223 		{
  4203 		__KTRACE_OPT(KUSB, Kern::Printf("  Moving to Full-speed"));
  4224 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP4, "  Moving to Full-speed" );
  4204 		EnterFullSpeed();
  4225 		EnterFullSpeed();
  4205 		}
  4226 		}
  4206 
  4227 
  4207 	// Setup initial Ep0 read (SetupEndpointZeroRead never called from thread)
  4228 	// Setup initial Ep0 read (SetupEndpointZeroRead never called from thread)
  4208 	if (SetupEndpointZeroRead() != KErrNone)
  4229 	if (SetupEndpointZeroRead() != KErrNone)
  4209 		{
  4230 		{
  4210 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: while setting up Ep0 read"));
  4231 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSRESETEVENT_DUP5, "  Error: while setting up Ep0 read" );
  4211 		return KErrGeneral;
  4232 		return KErrGeneral;
  4212 		}
  4233 		}
  4213 
  4234 
  4214 	return KErrNone;
  4235 	return KErrNone;
  4215 	}
  4236 	}
  4216 
  4237 
  4217 
  4238 
  4218 TInt DUsbClientController::ProcessCableInsertEvent()
  4239 TInt DUsbClientController::ProcessCableInsertEvent()
  4219 	{
  4240 	{
  4220 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessCableInsertEvent()"));
  4241     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSCABLEINSERTEVENT, "DUsbClientController::ProcessCableInsertEvent()" );
       
  4242     
  4221 #ifdef USB_OTG_CLIENT
  4243 #ifdef USB_OTG_CLIENT
  4222 	__KTRACE_OPT(KPANIC, Kern::Printf("  Error: EUsbEventCableInsert shouldn't be sent by an OTG Client PSL"));
  4244     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSCABLEINSERTEVENT_DUP1, "  Error: EUsbEventCableInsert shouldn't be sent by an OTG Client PSL" );
  4223 	return KErrArgument;
  4245 	return KErrArgument;
  4224 #else
  4246 #else
  4225 	NextDeviceState(EUsbcDeviceStateAttached);
  4247 	NextDeviceState(EUsbcDeviceStateAttached);
  4226 	if (iHardwareActivated)
  4248 	if (iHardwareActivated)
  4227 		{
  4249 		{
  4232 	}
  4254 	}
  4233 
  4255 
  4234 
  4256 
  4235 TInt DUsbClientController::ProcessCableRemoveEvent()
  4257 TInt DUsbClientController::ProcessCableRemoveEvent()
  4236 	{
  4258 	{
  4237 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessCableRemoveEvent()"));
  4259     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_PROCESSCABLEREMOVEEVENT, "DUsbClientController::ProcessCableRemoveEvent()" );
  4238 #ifdef USB_OTG_CLIENT
  4260 #ifdef USB_OTG_CLIENT
  4239 	__KTRACE_OPT(KPANIC, Kern::Printf("  Error: EUsbEventCableRemoved shouldn't be sent by an OTG Client PSL"));
  4261     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_PROCESSCABLEREMOVEEVENT_DUP1, "  Error: EUsbEventCableRemoved shouldn't be sent by an OTG Client PSL" );
  4240 	return KErrArgument;
  4262 	return KErrArgument;
  4241 #else
  4263 #else
  4242 	// Tear down the current configuration (if any)
  4264 	// Tear down the current configuration (if any)
  4243 	ChangeConfiguration(0);
  4265 	ChangeConfiguration(0);
  4244 	NextDeviceState(EUsbcDeviceStateUndefined);
  4266 	NextDeviceState(EUsbcDeviceStateUndefined);
  4247 	}
  4269 	}
  4248 
  4270 
  4249 
  4271 
  4250 void DUsbClientController::EnterFullSpeed()
  4272 void DUsbClientController::EnterFullSpeed()
  4251 	{
  4273 	{
  4252 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EnterFullSpeed()"));
  4274 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENTERFULLSPEED, "DUsbClientController::EnterFullSpeed()" );
  4253 	iDescriptors.UpdateDescriptorsFs();
  4275 	iDescriptors.UpdateDescriptorsFs();
  4254 	}
  4276 	}
  4255 
  4277 
  4256 
  4278 
  4257 void DUsbClientController::EnterHighSpeed()
  4279 void DUsbClientController::EnterHighSpeed()
  4258 	{
  4280 	{
  4259 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EnterHighSpeed()"));
  4281 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_ENTERHIGHSPEED, "DUsbClientController::EnterHighSpeed()" );
  4260 	iDescriptors.UpdateDescriptorsHs();
  4282 	iDescriptors.UpdateDescriptorsHs();
  4261 	}
  4283 	}
  4262 
  4284 
  4263 
  4285 
  4264 //
  4286 //
  4265 // Called whenever either iOtgClientConnect or iClientSupportReady changes value.
  4287 // Called whenever either iOtgClientConnect or iClientSupportReady changes value.
  4266 //
  4288 //
  4267 TInt DUsbClientController::EvaluateOtgConnectFlags()
  4289 TInt DUsbClientController::EvaluateOtgConnectFlags()
  4268 	{
  4290 	{
  4269 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EvaluateOtgConnectFlags()"));
  4291     OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS, "DUsbClientController::EvaluateOtgConnectFlags()" );
  4270 
  4292 
  4271 	TInt r = KErrNone;
  4293 	TInt r = KErrNone;
  4272 
  4294 
  4273 	// Check to see if the current flag states result in a change to the
  4295 	// Check to see if the current flag states result in a change to the
  4274 	// need to activate the DPLUS pull-up
  4296 	// need to activate the DPLUS pull-up
  4279 		enableDPlus = (iOtgClientConnect && iClientSupportReady);
  4301 		enableDPlus = (iOtgClientConnect && iClientSupportReady);
  4280 		}
  4302 		}
  4281 	else
  4303 	else
  4282 		{
  4304 		{
  4283 		// certain h/w: handles HNP connect/disconnect automatically
  4305 		// certain h/w: handles HNP connect/disconnect automatically
  4284 		__KTRACE_OPT(KUSB, Kern::Printf("  HNP-handling h/w: only considering user-side readiness"));
  4306 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP1, "  HNP-handling h/w: only considering user-side readiness" );
  4285 		enableDPlus = iClientSupportReady;
  4307 		enableDPlus = iClientSupportReady;
  4286 		}
  4308 		}
  4287 
  4309 
  4288 	if (enableDPlus == iDPlusEnabled)
  4310 	if (enableDPlus == iDPlusEnabled)
  4289 		{
  4311 		{
  4291 		}
  4313 		}
  4292 
  4314 
  4293 	// There has been a changed requirement that must be serviced...
  4315 	// There has been a changed requirement that must be serviced...
  4294 	if (enableDPlus)
  4316 	if (enableDPlus)
  4295 		{
  4317 		{
  4296 		__KTRACE_OPT(KUSB, Kern::Printf("  calling (*iEnablePullUpOnDPlus)()"));
  4318 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP2, "  calling (*iEnablePullUpOnDPlus)()" );
  4297 		if (iEnablePullUpOnDPlus != NULL)
  4319 		if (iEnablePullUpOnDPlus != NULL)
  4298 			{
  4320 			{
  4299 			iDPlusEnabled = enableDPlus;
  4321 			iDPlusEnabled = enableDPlus;
  4300 			// First we move to Suspend state to trigger a state change
  4322 			// First we move to Suspend state to trigger a state change
  4301 			// notification in any case, even if no cable and/or host are
  4323 			// notification in any case, even if no cable and/or host are
  4319 				NextDeviceState(iDeviceState);
  4341 				NextDeviceState(iDeviceState);
  4320 				}
  4342 				}
  4321 			r = (*iEnablePullUpOnDPlus)(iOtgContext);
  4343 			r = (*iEnablePullUpOnDPlus)(iOtgContext);
  4322 			if (r != KErrNone)
  4344 			if (r != KErrNone)
  4323 				{
  4345 				{
  4324 				__KTRACE_OPT(KPANIC, Kern::Printf("  Error: iEnablePullUpOnDPlus() = %d", r));
  4346 		        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP3, "  Error: iEnablePullUpOnDPlus() = %d", r);
  4325 				}
  4347 				}
  4326 			}
  4348 			}
  4327 		else
  4349 		else
  4328 			{
  4350 			{
  4329 			__KTRACE_OPT(KUSB, Kern::Printf("  Warning: iEnablePullUpOnDPlus pointer not ready"));
  4351             OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP4, "  Warning: iEnablePullUpOnDPlus pointer not ready");
  4330 			// We cannot enforce the presence of the pointer (via an ASSERT)
  4352 			// We cannot enforce the presence of the pointer (via an ASSERT)
  4331 			// since it might only be available at a later point.
  4353 			// since it might only be available at a later point.
  4332 			// We shouldn't return an error at this point either, since the
  4354 			// We shouldn't return an error at this point either, since the
  4333 			// problem will be a systematic one.
  4355 			// problem will be a systematic one.
  4334 			}
  4356 			}
  4335 		}
  4357 		}
  4336 	else
  4358 	else
  4337 		{
  4359 		{
  4338 		__KTRACE_OPT(KUSB, Kern::Printf("  calling (*iDisablePullUpOnDPlus)()"));
  4360         OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP5, "  calling (*iDisablePullUpOnDPlus)()");
  4339 		if (iDisablePullUpOnDPlus != NULL)
  4361 		if (iDisablePullUpOnDPlus != NULL)
  4340 			{
  4362 			{
  4341 			iDPlusEnabled = enableDPlus;
  4363 			iDPlusEnabled = enableDPlus;
  4342 			r = (*iDisablePullUpOnDPlus)(iOtgContext);
  4364 			r = (*iDisablePullUpOnDPlus)(iOtgContext);
  4343 			if (r != KErrNone)
  4365 			if (r != KErrNone)
  4344 				{
  4366 				{
  4345 				__KTRACE_OPT(KPANIC, Kern::Printf("  Error: iDisablePullUpOnDPlus() = %d", r));
  4367 		        OstTraceDef1(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP6, "  Error: iDisablePullUpOnDPlus() = %d", r);
  4346 				}
  4368 				}
  4347 			}
  4369 			}
  4348 		else
  4370 		else
  4349 			{
  4371 			{
  4350 			__KTRACE_OPT(KUSB, Kern::Printf("  Warning: iDisablePullUpOnDPlus pointer not ready"));
  4372             OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_EVALUATEOTGCONNECTFLAGS_DUP7, "  Warning: iDisablePullUpOnDPlus pointer not ready");
  4351 			// We cannot enforce the presence of the pointer (via an ASSERT)
  4373 			// We cannot enforce the presence of the pointer (via an ASSERT)
  4352 			// since it might only be available at a later point.
  4374 			// since it might only be available at a later point.
  4353 			// We shouldn't return an error at this point either, since the
  4375 			// We shouldn't return an error at this point either, since the
  4354 			// problem will be a systematic one.
  4376 			// problem will be a systematic one.
  4355 			}
  4377 			}
  4361 //
  4383 //
  4362 // DFC (static)
  4384 // DFC (static)
  4363 //
  4385 //
  4364 void DUsbClientController::ReconnectTimerCallback(TAny *aPtr)
  4386 void DUsbClientController::ReconnectTimerCallback(TAny *aPtr)
  4365 	{
  4387 	{
  4366 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ReconnectTimerCallback()"));
  4388 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_RECONNECTTIMERCALLBACK, "DUsbClientController::ReconnectTimerCallback()" );
  4367 	if (!aPtr)
  4389 	if (!aPtr)
  4368 		{
  4390 		{
  4369 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: !aPtr"));
  4391 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_RECONNECTTIMERCALLBACK_DUP1, "  Error: !aPtr");
  4370 		return;
  4392 		return;
  4371 		}
  4393 		}
  4372 	DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr);
  4394 	DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr);
  4373 	ptr->UsbConnect();
  4395 	ptr->UsbConnect();
  4374 	}
  4396 	}
  4377 //
  4399 //
  4378 // ISR (static)
  4400 // ISR (static)
  4379 //
  4401 //
  4380 void DUsbClientController::CableStatusTimerCallback(TAny *aPtr)
  4402 void DUsbClientController::CableStatusTimerCallback(TAny *aPtr)
  4381 	{
  4403 	{
  4382 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::CableStatusTimerCallback()"));
  4404 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_CABLESTATUSTIMERCALLBACK, "DUsbClientController::CableStatusTimerCallback()" );
  4383 	if (!aPtr)
  4405 	if (!aPtr)
  4384 		{
  4406 		{
  4385 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: !aPtr"));
  4407 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_CABLESTATUSTIMERCALLBACK_DUP1, "  Error: !aPtr" );
  4386 		return;
  4408 		return;
  4387 		}
  4409 		}
  4388 	DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr);
  4410 	DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr);
  4389 	ptr->ProcessSuspendEventProceed();
  4411 	ptr->ProcessSuspendEventProceed();
  4390 	}
  4412 	}
  4393 //
  4415 //
  4394 // static
  4416 // static
  4395 //
  4417 //
  4396 void DUsbClientController::PowerUpDfc(TAny* aPtr)
  4418 void DUsbClientController::PowerUpDfc(TAny* aPtr)
  4397 	{
  4419 	{
  4398 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerUpDfc"));
  4420 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERUPDFC, "DUsbClientController::PowerUpDfc" );
  4399 	if (!aPtr)
  4421 	if (!aPtr)
  4400 		{
  4422 		{
  4401 		__KTRACE_OPT(KPANIC, Kern::Printf("	 Error: !aPtr"));
  4423 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_POWERUPDFC_DUP1, "   Error: !aPtr" );
  4402 		return;
  4424 		return;
  4403 		}
  4425 		}
  4404 	DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr);
  4426 	DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr);
  4405 	__PM_ASSERT(ptr->iStandby);
  4427 	__PM_ASSERT(ptr->iStandby);
  4406 	(void) ptr->PowerUp();
  4428 	(void) ptr->PowerUp();
  4412 //
  4434 //
  4413 // static
  4435 // static
  4414 //
  4436 //
  4415 void DUsbClientController::PowerDownDfc(TAny* aPtr)
  4437 void DUsbClientController::PowerDownDfc(TAny* aPtr)
  4416 	{
  4438 	{
  4417 	__KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::PowerDownDfc"));
  4439 	OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FLOW, DUSBCLIENTCONTROLLER_POWERDOWNDFC, "DUsbClientController::PowerDownDfc" );
  4418 	if (!aPtr)
  4440 	if (!aPtr)
  4419 		{
  4441 		{
  4420 		__KTRACE_OPT(KPANIC, Kern::Printf("	 Error: !aPtr"));
  4442 		OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP1, "    Error: !aPtr" );
  4421 		return;
  4443 		return;
  4422 		}
  4444 		}
  4423 	DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr);
  4445 	DUsbClientController* const ptr = static_cast<DUsbClientController*>(aPtr);
  4424 	__PM_ASSERT(!ptr->iStandby);
  4446 	__PM_ASSERT(!ptr->iStandby);
  4425 	ptr->iStandby = ETrue;
  4447 	ptr->iStandby = ETrue;
  4426 	// We might not want to power down when the UDC is active:
  4448 	// We might not want to power down when the UDC is active:
  4427 	if (!ptr->iHardwareActivated || ptr->PowerDownWhenActive())
  4449 	if (!ptr->iHardwareActivated || ptr->PowerDownWhenActive())
  4428 		{
  4450 		{
  4429 		(void) ptr->PowerDown();
  4451 		(void) ptr->PowerDown();
  4430 		__KTRACE_OPT(KUSB, Kern::Printf("Calling PowerHandler->PowerDownDone()"));
  4452 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP2, "Calling PowerHandler->PowerDownDone()" );
  4431 		ptr->iPowerHandler->PowerDownDone();
  4453 		ptr->iPowerHandler->PowerDownDone();
  4432 		}
  4454 		}
  4433 	else
  4455 	else
  4434 		{
  4456 		{
  4435 		__KTRACE_OPT(KUSB, Kern::Printf("Not calling PowerHandler->PowerDownDone()"));
  4457 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP3, "Not calling PowerHandler->PowerDownDone()" );
  4436 		__KTRACE_OPT(KUSB, Kern::Printf("  because UDC is active."));
  4458 	    OstTraceDef0(OST_TRACE_CATEGORY_RND, TRACE_NORMAL, DUSBCLIENTCONTROLLER_POWERDOWNDFC_DUP4, "  because UDC is active." );
  4437 		}
  4459 		}
  4438 	}
  4460 	}
  4439 
  4461 
  4440 
  4462 
  4441 // -EOF-
  4463 // -EOF-