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