kernel/eka/drivers/usbcc/descriptors.cpp
changeset 253 d37db4dcc88d
parent 189 a5496987b1da
child 257 3e88ff8f41d5
child 273 6a75fa55495f
equal deleted inserted replaced
252:0a40b8675b23 253:d37db4dcc88d
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    22  @internalTechnology
    22  @internalTechnology
    23 */
    23 */
    24 
    24 
    25 #include <kernel/kern_priv.h>
    25 #include <kernel/kern_priv.h>
    26 #include <drivers/usbc.h>
    26 #include <drivers/usbc.h>
       
    27 #include "OstTraceDefinitions.h"
       
    28 #ifdef OST_TRACE_COMPILER_IN_USE
       
    29 #include "descriptorsTraces.h"
       
    30 #endif
       
    31 
    27 
    32 
    28 
    33 
    29 // Debug Support
    34 // Debug Support
    30 static const char KUsbPanicCat[] = "USB PIL";
    35 static const char KUsbPanicCat[] = "USB PIL";
    31 
    36 
    37 #ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
    42 #ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
    38 	iIndex(0),
    43 	iIndex(0),
    39 #endif
    44 #endif
    40 	iBufPtr(NULL, 0)
    45 	iBufPtr(NULL, 0)
    41 	{
    46 	{
    42 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorBase::TUsbcDescriptorBase()"));
    47 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORBASE_TUSBCDESCRIPTORBASE_CONS,
       
    48 	        "TUsbcDescriptorBase::TUsbcDescriptorBase()" );
    43 	}
    49 	}
    44 
    50 
    45 
    51 
    46 TUsbcDescriptorBase::~TUsbcDescriptorBase()
    52 TUsbcDescriptorBase::~TUsbcDescriptorBase()
    47 	{
    53 	{
    48 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorBase::~TUsbcDescriptorBase()"));
    54     OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORBASE_TUSBCDESCRIPTORBASE_DES,
       
    55 	        "TUsbcDescriptorBase::~TUsbcDescriptorBase()" );
    49 	}
    56 	}
    50 
    57 
    51 
    58 
    52 void TUsbcDescriptorBase::SetByte(TInt aPosition, TUint8 aValue)
    59 void TUsbcDescriptorBase::SetByte(TInt aPosition, TUint8 aValue)
    53 	{
    60 	{
   144 // --- TUsbcDeviceDescriptor
   151 // --- TUsbcDeviceDescriptor
   145 
   152 
   146 TUsbcDeviceDescriptor::TUsbcDeviceDescriptor()
   153 TUsbcDeviceDescriptor::TUsbcDeviceDescriptor()
   147 	: iBuf()
   154 	: iBuf()
   148 	{
   155 	{
   149 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDeviceDescriptor::TUsbcDeviceDescriptor()"));
   156 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDEVICEDESCRIPTOR_TUSBCDEVICEDESCRIPTOR_CONS, 
       
   157 	        "TUsbcDeviceDescriptor::TUsbcDeviceDescriptor()" );
   150 	}
   158 	}
   151 
   159 
   152 
   160 
   153 TUsbcDeviceDescriptor* TUsbcDeviceDescriptor::New(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
   161 TUsbcDeviceDescriptor* TUsbcDeviceDescriptor::New(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
   154 												  TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
   162 												  TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
   155 												  TUint16 aVendorId, TUint16 aProductId,
   163 												  TUint16 aVendorId, TUint16 aProductId,
   156 												  TUint16 aDeviceRelease, TUint8 aNumConfigurations)
   164 												  TUint16 aDeviceRelease, TUint8 aNumConfigurations)
   157 	{
   165 	{
   158 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDeviceDescriptor::New()"));
   166 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDEVICEDESCRIPTOR_NEW, 
       
   167 	        "TUsbcDeviceDescriptor::New()" );
   159 	TUsbcDeviceDescriptor* self = new TUsbcDeviceDescriptor();
   168 	TUsbcDeviceDescriptor* self = new TUsbcDeviceDescriptor();
   160 	if (self)
   169 	if (self)
   161 		{
   170 		{
   162 		if (self->Construct(aDeviceClass, aDeviceSubClass, aDeviceProtocol, aMaxPacketSize0, aVendorId,
   171 		if (self->Construct(aDeviceClass, aDeviceSubClass, aDeviceProtocol, aMaxPacketSize0, aVendorId,
   163 							aProductId, aDeviceRelease, aNumConfigurations) != KErrNone)
   172 							aProductId, aDeviceRelease, aNumConfigurations) != KErrNone)
   172 
   181 
   173 TInt TUsbcDeviceDescriptor::Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol,
   182 TInt TUsbcDeviceDescriptor::Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass, TUint8 aDeviceProtocol,
   174 									  TUint8 aMaxPacketSize0, TUint16 aVendorId, TUint16 aProductId,
   183 									  TUint8 aMaxPacketSize0, TUint16 aVendorId, TUint16 aProductId,
   175 									  TUint16 aDeviceRelease, TUint8 aNumConfigurations)
   184 									  TUint16 aDeviceRelease, TUint8 aNumConfigurations)
   176 	{
   185 	{
   177 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDeviceDescriptor::Construct()"));
   186 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDEVICEDESCRIPTOR_CONSTRUCT,
       
   187 	        "TUsbcDeviceDescriptor::Construct()" );
   178 	iBuf.SetMax();
   188 	iBuf.SetMax();
   179 	SetBufferPointer(iBuf);
   189 	SetBufferPointer(iBuf);
   180 	iBuf[0] = iBuf.Size();									// bLength
   190 	iBuf[0] = iBuf.Size();									// bLength
   181 	iBuf[1] = KUsbDescType_Device;							// bDescriptorType
   191 	iBuf[1] = KUsbDescType_Device;							// bDescriptorType
   182 	SetWord(2, KUsbcUsbVersion);							// bcdUSB
   192 	SetWord(2, KUsbcUsbVersion);							// bcdUSB
   196 	}
   206 	}
   197 
   207 
   198 
   208 
   199 void TUsbcDeviceDescriptor::UpdateFs()
   209 void TUsbcDeviceDescriptor::UpdateFs()
   200 	{
   210 	{
   201 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDeviceDescriptor::UpdateFs()"));
   211 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDEVICEDESCRIPTOR_UPDATEFS, 
       
   212 	        "TUsbcDeviceDescriptor::UpdateFs()" );
   202 	SetByte(7, iEp0Size_Fs);								// bMaxPacketSize0
   213 	SetByte(7, iEp0Size_Fs);								// bMaxPacketSize0
   203 	}
   214 	}
   204 
   215 
   205 
   216 
   206 void TUsbcDeviceDescriptor::UpdateHs()
   217 void TUsbcDeviceDescriptor::UpdateHs()
   207 	{
   218 	{
   208 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDeviceDescriptor::UpdateHs()"));
   219 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDEVICEDESCRIPTOR_UPDATEHS,
       
   220 	        "TUsbcDeviceDescriptor::UpdateHs()" );
   209 	SetByte(7, 64);											// bMaxPacketSize0
   221 	SetByte(7, 64);											// bMaxPacketSize0
   210 	}
   222 	}
   211 
   223 
   212 
   224 
   213 // --- TUsbcDeviceQualifierDescriptor
   225 // --- TUsbcDeviceQualifierDescriptor
   214 
   226 
   215 TUsbcDeviceQualifierDescriptor::TUsbcDeviceQualifierDescriptor()
   227 TUsbcDeviceQualifierDescriptor::TUsbcDeviceQualifierDescriptor()
   216 	: iBuf()
   228 	: iBuf()
   217 	{
   229 	{
   218 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDeviceDescriptor::TUsbcDeviceQualifierDescriptor()"));
   230 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDEVICEQUALIFIERDESCRIPTOR_TUSBCDEVICEQUALIFIERDESCRIPTOR_CONS,
       
   231 	        "TUsbcDeviceQualifierDescriptor::TUsbcDeviceQualifierDescriptor()" );
   219 	}
   232 	}
   220 
   233 
   221 
   234 
   222 TUsbcDeviceQualifierDescriptor* TUsbcDeviceQualifierDescriptor::New(TUint8 aDeviceClass,
   235 TUsbcDeviceQualifierDescriptor* TUsbcDeviceQualifierDescriptor::New(TUint8 aDeviceClass,
   223 																	TUint8 aDeviceSubClass,
   236 																	TUint8 aDeviceSubClass,
   224 																	TUint8 aDeviceProtocol,
   237 																	TUint8 aDeviceProtocol,
   225 																	TUint8 aMaxPacketSize0,
   238 																	TUint8 aMaxPacketSize0,
   226 																	TUint8 aNumConfigurations,
   239 																	TUint8 aNumConfigurations,
   227 																	TUint8 aReserved)
   240 																	TUint8 aReserved)
   228 	{
   241 	{
   229 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDeviceQualifierDescriptor::New()"));
   242 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDEVICEQUALIFIERDESCRIPTOR_NEW, 
       
   243 	        "TUsbcDeviceQualifierDescriptor::New()" );
   230 	TUsbcDeviceQualifierDescriptor* self = new TUsbcDeviceQualifierDescriptor();
   244 	TUsbcDeviceQualifierDescriptor* self = new TUsbcDeviceQualifierDescriptor();
   231 	if (self)
   245 	if (self)
   232 		{
   246 		{
   233 		if (self->Construct(aDeviceClass, aDeviceSubClass, aDeviceProtocol, aMaxPacketSize0,
   247 		if (self->Construct(aDeviceClass, aDeviceSubClass, aDeviceProtocol, aMaxPacketSize0,
   234 							aNumConfigurations, aReserved) != KErrNone)
   248 							aNumConfigurations, aReserved) != KErrNone)
   243 
   257 
   244 TInt TUsbcDeviceQualifierDescriptor::Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
   258 TInt TUsbcDeviceQualifierDescriptor::Construct(TUint8 aDeviceClass, TUint8 aDeviceSubClass,
   245 											   TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
   259 											   TUint8 aDeviceProtocol, TUint8 aMaxPacketSize0,
   246 											   TUint8 aNumConfigurations, TUint8 aReserved)
   260 											   TUint8 aNumConfigurations, TUint8 aReserved)
   247 	{
   261 	{
   248 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDeviceQualifierDescriptor::Construct()"));
   262 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDEVICEQUALIFIERDESCRIPTOR_CONSTRUCT,
       
   263 	        "TUsbcDeviceQualifierDescriptor::Construct()" );
   249 	iBuf.SetMax();
   264 	iBuf.SetMax();
   250 	SetBufferPointer(iBuf);
   265 	SetBufferPointer(iBuf);
   251 	iBuf[0] = iBuf.Size();									// bLength
   266 	iBuf[0] = iBuf.Size();									// bLength
   252 	iBuf[1] = KUsbDescType_DeviceQualifier;					// bDescriptorType
   267 	iBuf[1] = KUsbDescType_DeviceQualifier;					// bDescriptorType
   253 	SetWord(2, KUsbcUsbVersion);							// bcdUSB
   268 	SetWord(2, KUsbcUsbVersion);							// bcdUSB
   263 	}
   278 	}
   264 
   279 
   265 
   280 
   266 void TUsbcDeviceQualifierDescriptor::UpdateFs()
   281 void TUsbcDeviceQualifierDescriptor::UpdateFs()
   267 	{
   282 	{
   268 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDeviceQualifierDescriptor::UpdateFs()"));
   283 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDEVICEQUALIFIERDESCRIPTOR_UPDATEFS,
       
   284 	        "TUsbcDeviceQualifierDescriptor::UpdateFs()" );
   269 	// Here we do exactly the opposite of what's done in the Device descriptor (as this one's
   285 	// Here we do exactly the opposite of what's done in the Device descriptor (as this one's
   270 	// documenting the 'other than the current speed').
   286 	// documenting the 'other than the current speed').
   271 	SetByte(7, 64);											// bMaxPacketSize0
   287 	SetByte(7, 64);											// bMaxPacketSize0
   272 	}
   288 	}
   273 
   289 
   274 
   290 
   275 void TUsbcDeviceQualifierDescriptor::UpdateHs()
   291 void TUsbcDeviceQualifierDescriptor::UpdateHs()
   276 	{
   292 	{
   277 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDeviceQualifierDescriptor::UpdateHs()"));
   293 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDEVICEQUALIFIERDESCRIPTOR_UPDATEHS,
       
   294 	        "TUsbcDeviceQualifierDescriptor::UpdateHs()" );
   278 	// Here we do exactly the opposite of what's done in the Device descriptor (as this one's
   295 	// Here we do exactly the opposite of what's done in the Device descriptor (as this one's
   279 	// documenting the 'other than the current speed').
   296 	// documenting the 'other than the current speed').
   280 	SetByte(7, iEp0Size_Fs);								// bMaxPacketSize0
   297 	SetByte(7, iEp0Size_Fs);								// bMaxPacketSize0
   281 	}
   298 	}
   282 
   299 
   284 // --- TUsbcConfigDescriptor
   301 // --- TUsbcConfigDescriptor
   285 
   302 
   286 TUsbcConfigDescriptor::TUsbcConfigDescriptor()
   303 TUsbcConfigDescriptor::TUsbcConfigDescriptor()
   287 	: iBuf()
   304 	: iBuf()
   288 	{
   305 	{
   289 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcConfigDescriptor::TUsbcConfigDescriptor()"));
   306 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCCONFIGDESCRIPTOR_TUSBCCONFIGDESCRIPTOR_CONS,
       
   307 	        "TUsbcConfigDescriptor::TUsbcConfigDescriptor()" );
   290 	}
   308 	}
   291 
   309 
   292 
   310 
   293 TUsbcConfigDescriptor* TUsbcConfigDescriptor::New(TUint8 aConfigurationValue, TBool aSelfPowered,
   311 TUsbcConfigDescriptor* TUsbcConfigDescriptor::New(TUint8 aConfigurationValue, TBool aSelfPowered,
   294 												  TBool aRemoteWakeup, TUint16 aMaxPower)
   312 												  TBool aRemoteWakeup, TUint16 aMaxPower)
   295 	{
   313 	{
   296 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcConfigDescriptor::New()"));
   314 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCCONFIGDESCRIPTOR_NEW,
       
   315 	        "TUsbcConfigDescriptor::New()" );
   297 	TUsbcConfigDescriptor* self = new TUsbcConfigDescriptor();
   316 	TUsbcConfigDescriptor* self = new TUsbcConfigDescriptor();
   298 	if (self)
   317 	if (self)
   299 		{
   318 		{
   300 		if (self->Construct(aConfigurationValue, aSelfPowered, aRemoteWakeup, aMaxPower) != KErrNone)
   319 		if (self->Construct(aConfigurationValue, aSelfPowered, aRemoteWakeup, aMaxPower) != KErrNone)
   301 			{
   320 			{
   308 
   327 
   309 
   328 
   310 TInt TUsbcConfigDescriptor::Construct(TUint8 aConfigurationValue, TBool aSelfPowered,
   329 TInt TUsbcConfigDescriptor::Construct(TUint8 aConfigurationValue, TBool aSelfPowered,
   311 									   TBool aRemoteWakeup, TUint16 aMaxPower)
   330 									   TBool aRemoteWakeup, TUint16 aMaxPower)
   312 	{
   331 	{
   313 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcConfigDescriptor::Construct()"));
   332 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCCONFIGDESCRIPTOR_CONSTRUCT,
       
   333 	        "TUsbcConfigDescriptor::Construct()" );
   314 	iBuf.SetMax();
   334 	iBuf.SetMax();
   315 	SetBufferPointer(iBuf);
   335 	SetBufferPointer(iBuf);
   316 	iBuf[0] = iBuf.Size();									// bLength
   336 	iBuf[0] = iBuf.Size();									// bLength
   317 	iBuf[1] = KUsbDescType_Config;							// bDescriptorType
   337 	iBuf[1] = KUsbDescType_Config;							// bDescriptorType
   318 	SetWord(2, KUsbDescSize_Config);						// wTotalLength
   338 	SetWord(2, KUsbDescSize_Config);						// wTotalLength
   321 	iBuf[6] = 0;											// iConfiguration
   341 	iBuf[6] = 0;											// iConfiguration
   322 	iBuf[7] = 0x80 |
   342 	iBuf[7] = 0x80 |
   323 		(aSelfPowered ? KUsbDevAttr_SelfPowered : 0) |
   343 		(aSelfPowered ? KUsbDevAttr_SelfPowered : 0) |
   324 		(aRemoteWakeup ? KUsbDevAttr_RemoteWakeup : 0);		// bmAttributes (bit 7 always 1)
   344 		(aRemoteWakeup ? KUsbDevAttr_RemoteWakeup : 0);		// bmAttributes (bit 7 always 1)
   325 	if (aMaxPower > 510)
   345 	if (aMaxPower > 510)
   326 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid value for bMaxPower: %d", aMaxPower));
   346 		OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, DUP1_TUSBCCONFIGDESCRIPTOR_CONSTRUCT_DUP1,
       
   347 		        "  Error: Invalid value for bMaxPower: %d", aMaxPower );
   327 	iBuf[8] = aMaxPower / 2;								// bMaxPower (2mA units!)
   348 	iBuf[8] = aMaxPower / 2;								// bMaxPower (2mA units!)
   328 	return KErrNone;
   349 	return KErrNone;
   329 	}
   350 	}
   330 
   351 
   331 
   352 
   332 // --- TUsbcInterfaceDescriptor
   353 // --- TUsbcInterfaceDescriptor
   333 
   354 
   334 TUsbcInterfaceDescriptor::TUsbcInterfaceDescriptor()
   355 TUsbcInterfaceDescriptor::TUsbcInterfaceDescriptor()
   335 	: iBuf()
   356 	: iBuf()
   336 	{
   357 	{
   337 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcInterfaceDescriptor::TUsbcInterfaceDescriptor()"));
   358 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCINTERFACEDESCRIPTOR_TUSBCINTERFACEDESCRIPTOR_CONS,
       
   359 	        "TUsbcInterfaceDescriptor::TUsbcInterfaceDescriptor()" );
   338 	}
   360 	}
   339 
   361 
   340 
   362 
   341 TUsbcInterfaceDescriptor* TUsbcInterfaceDescriptor::New(TUint8 aInterfaceNumber, TUint8 aAlternateSetting,
   363 TUsbcInterfaceDescriptor* TUsbcInterfaceDescriptor::New(TUint8 aInterfaceNumber, TUint8 aAlternateSetting,
   342 														TInt aNumEndpoints, const TUsbcClassInfo& aClassInfo)
   364 														TInt aNumEndpoints, const TUsbcClassInfo& aClassInfo)
   343 	{
   365 	{
   344 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcInterfaceDescriptor::New()"));
   366 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCINTERFACEDESCRIPTOR_NEW,
       
   367 	        "TUsbcInterfaceDescriptor::New()" );
   345 	TUsbcInterfaceDescriptor* self = new TUsbcInterfaceDescriptor();
   368 	TUsbcInterfaceDescriptor* self = new TUsbcInterfaceDescriptor();
   346 	if (self)
   369 	if (self)
   347 		{
   370 		{
   348 		if (self->Construct(aInterfaceNumber, aAlternateSetting, aNumEndpoints, aClassInfo) != KErrNone)
   371 		if (self->Construct(aInterfaceNumber, aAlternateSetting, aNumEndpoints, aClassInfo) != KErrNone)
   349 			{
   372 			{
   356 
   379 
   357 
   380 
   358 TInt TUsbcInterfaceDescriptor::Construct(TUint8 aInterfaceNumber, TUint8 aAlternateSetting,
   381 TInt TUsbcInterfaceDescriptor::Construct(TUint8 aInterfaceNumber, TUint8 aAlternateSetting,
   359 										 TInt aNumEndpoints, const TUsbcClassInfo& aClassInfo)
   382 										 TInt aNumEndpoints, const TUsbcClassInfo& aClassInfo)
   360 	{
   383 	{
   361 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcInterfaceDescriptor::Construct()"));
   384 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCINTERFACEDESCRIPTOR_CONSTRUCT,
       
   385 	        "TUsbcInterfaceDescriptor::Construct()" );
   362 	iBuf.SetMax();
   386 	iBuf.SetMax();
   363 	SetBufferPointer(iBuf);
   387 	SetBufferPointer(iBuf);
   364 	iBuf[0] = iBuf.Size();									// bLength
   388 	iBuf[0] = iBuf.Size();									// bLength
   365 	iBuf[1] = KUsbDescType_Interface;						// bDescriptorType
   389 	iBuf[1] = KUsbDescType_Interface;						// bDescriptorType
   366 	iBuf[2] = aInterfaceNumber;								// bInterfaceNumber
   390 	iBuf[2] = aInterfaceNumber;								// bInterfaceNumber
   376 
   400 
   377 // --- TUsbcEndpointDescriptorBase
   401 // --- TUsbcEndpointDescriptorBase
   378 
   402 
   379 TUsbcEndpointDescriptorBase::TUsbcEndpointDescriptorBase()
   403 TUsbcEndpointDescriptorBase::TUsbcEndpointDescriptorBase()
   380 	{
   404 	{
   381 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcEndpointDescriptorBase::TUsbcEndpointDescriptorBase()"));
   405 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCENDPOINTDESCRIPTORBASE_TUSBCENDPOINTDESCRIPTORBASE_CONS,
       
   406 	        "TUsbcEndpointDescriptorBase::TUsbcEndpointDescriptorBase()" );
   382 	}
   407 	}
   383 
   408 
   384 
   409 
   385 TInt TUsbcEndpointDescriptorBase::Construct(const TUsbcEndpointInfo& aEpInfo)
   410 TInt TUsbcEndpointDescriptorBase::Construct(const TUsbcEndpointInfo& aEpInfo)
   386 	{
   411 	{
   387 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcEndpointDescriptorBase::Construct()"));
   412 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCENDPOINTDESCRIPTORBASE_CONSTRUCT,
       
   413 	        "TUsbcEndpointDescriptorBase::Construct()" );
   388 	//  Adjust FS/HS endpoint sizes
   414 	//  Adjust FS/HS endpoint sizes
   389 	if (aEpInfo.AdjustEpSizes(iEpSize_Fs, iEpSize_Hs) != KErrNone)
   415 	if (aEpInfo.AdjustEpSizes(iEpSize_Fs, iEpSize_Hs) != KErrNone)
   390 		{
   416 		{
   391 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Unknown endpoint type: %d", aEpInfo.iType));
   417 		OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCENDPOINTDESCRIPTORBASE_CONSTRUCT_DUP1,
   392 		}
   418 		        "  Error: Unknown endpoint type: %d", aEpInfo.iType );
   393 	__KTRACE_OPT(KUSB, Kern::Printf("  Now set: iEpSize_Fs=%d iEpSize_Hs=%d (aEpInfo.iSize=%d)",
   419 		}
   394 									iEpSize_Fs, iEpSize_Hs, aEpInfo.iSize));
   420 	OstTraceDefExt3( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCENDPOINTDESCRIPTORBASE_CONSTRUCT_DUP2,
       
   421 	        "  Now set: iEpSize_Fs=%d iEpSize_Hs=%d (aEpInfo.iSize=%d)",
       
   422 	        iEpSize_Fs, iEpSize_Hs, aEpInfo.iSize );
   395 
   423 
   396 	//  Adjust HS endpoint size for additional transactions
   424 	//  Adjust HS endpoint size for additional transactions
   397 	if ((aEpInfo.iType == KUsbEpTypeIsochronous) || (aEpInfo.iType == KUsbEpTypeInterrupt))
   425 	if ((aEpInfo.iType == KUsbEpTypeIsochronous) || (aEpInfo.iType == KUsbEpTypeInterrupt))
   398 		{
   426 		{
   399 		if ((aEpInfo.iTransactions > 0) && (aEpInfo.iTransactions < 3))
   427 		if ((aEpInfo.iTransactions > 0) && (aEpInfo.iTransactions < 3))
   400 			{
   428 			{
   401 			// Bits 12..11 specify the number of additional transactions per microframe
   429 			// Bits 12..11 specify the number of additional transactions per microframe
   402 			iEpSize_Hs |= (aEpInfo.iTransactions << 12);
   430 			iEpSize_Hs |= (aEpInfo.iTransactions << 12);
   403 			__KTRACE_OPT(KUSB, Kern::Printf("  Adjusted for add. transact.: iEpSize_Hs=0x%02x "
   431 			 OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCENDPOINTDESCRIPTORBASE_CONSTRUCT_DUP3,
   404 											"(aEpInfo.iTransactions=%d)",
   432 			         "  Adjusted for add. transact.: iEpSize_Hs=0x%02x (aEpInfo.iTransactions=%d)",
   405 											iEpSize_Hs, aEpInfo.iTransactions));
   433 			         iEpSize_Hs, aEpInfo.iTransactions );
       
   434 
   406 			}
   435 			}
   407 		else if (aEpInfo.iTransactions != 0)
   436 		else if (aEpInfo.iTransactions != 0)
   408 			{
   437 			{
   409 			__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Invalid iTransactions value: %d (ignored)",
   438             OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCENDPOINTDESCRIPTORBASE_CONSTRUCT_DUP4,
   410 											  aEpInfo.iTransactions));
   439                     "  Warning: Invalid iTransactions value: %d (ignored)", aEpInfo.iTransactions );
       
   440 
   411 			}
   441 			}
   412 		}
   442 		}
   413 
   443 
   414 	//  Adjust HS polling interval
   444 	//  Adjust HS polling interval
   415 	TUsbcEndpointInfo info(aEpInfo);						// create local writeable copy
   445 	TUsbcEndpointInfo info(aEpInfo);						// create local writeable copy
   416 	if (info.AdjustPollInterval() != KErrNone)
   446 	if (info.AdjustPollInterval() != KErrNone)
   417 		{
   447 		{
   418 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Unknown ep type (%d) or invalid interval value (%d)",
   448         OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCENDPOINTDESCRIPTORBASE_CONSTRUCT_DUP5,
   419 										  info.iType, info.iInterval));
   449                 "  Error: Unknown ep type (%d) or invalid interval value (%d)", info.iType, info.iInterval );
   420 		}
   450 		}
   421 	iInterval_Fs = info.iInterval;
   451 	iInterval_Fs = info.iInterval;
   422 	iInterval_Hs = info.iInterval_Hs;
   452 	iInterval_Hs = info.iInterval_Hs;
   423 	__KTRACE_OPT(KUSB, Kern::Printf("  Now set: iInterval_Fs=%d iInterval_Hs=%d",
   453     OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCENDPOINTDESCRIPTORBASE_CONSTRUCT_DUP6,
   424 									iInterval_Fs, iInterval_Hs));
   454             "  Now set: iInterval_Fs=%d iInterval_Hs=%d", iInterval_Fs, iInterval_Hs );
       
   455 
   425 	return KErrNone;
   456 	return KErrNone;
   426 	}
   457 	}
   427 
   458 
   428 
   459 
   429 void TUsbcEndpointDescriptorBase::UpdateFs()
   460 void TUsbcEndpointDescriptorBase::UpdateFs()
   430 	{
   461 	{
   431 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcEndpointDescriptorBase::UpdateFs()"));
   462 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCENDPOINTDESCRIPTORBASE_UPDATEFS,
       
   463 	        "TUsbcEndpointDescriptorBase::UpdateFs" );
   432 	// (TUsbcEndpointDescriptorBase's FS/HS endpoint sizes and interval values got
   464 	// (TUsbcEndpointDescriptorBase's FS/HS endpoint sizes and interval values got
   433 	//  adjusted in its Construct() method.)
   465 	//  adjusted in its Construct() method.)
   434 	SetWord(4, iEpSize_Fs);									// wMaxPacketSize
   466 	SetWord(4, iEpSize_Fs);									// wMaxPacketSize
   435 	SetByte(6, iInterval_Fs);								// bInterval
   467 	SetByte(6, iInterval_Fs);								// bInterval
   436 	}
   468 	}
   437 
   469 
   438 
   470 
   439 void TUsbcEndpointDescriptorBase::UpdateHs()
   471 void TUsbcEndpointDescriptorBase::UpdateHs()
   440 	{
   472 	{
   441 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcEndpointDescriptorBase::UpdateHs()"));
   473 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCENDPOINTDESCRIPTORBASE_UPDATEHS,
       
   474 	        "TUsbcEndpointDescriptorBase::UpdateHs()" );
   442 	// (TUsbcEndpointDescriptorBase's FS/HS endpoint sizes and interval values get
   475 	// (TUsbcEndpointDescriptorBase's FS/HS endpoint sizes and interval values get
   443 	//  adjusted in its Construct() method.)
   476 	//  adjusted in its Construct() method.)
   444 	SetWord(4, iEpSize_Hs);									// wMaxPacketSize
   477 	SetWord(4, iEpSize_Hs);									// wMaxPacketSize
   445 	SetByte(6, iInterval_Hs);								// bInterval
   478 	SetByte(6, iInterval_Hs);								// bInterval
   446 	}
   479 	}
   449 // --- TUsbcEndpointDescriptor
   482 // --- TUsbcEndpointDescriptor
   450 
   483 
   451 TUsbcEndpointDescriptor::TUsbcEndpointDescriptor()
   484 TUsbcEndpointDescriptor::TUsbcEndpointDescriptor()
   452 	: iBuf()
   485 	: iBuf()
   453 	{
   486 	{
   454 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcEndpointDescriptor::TUsbcEndpointDescriptor()"));
   487 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCENDPOINTDESCRIPTOR_TUSBCENDPOINTDESCRIPTOR_CONS,
       
   488 	        "TUsbcEndpointDescriptor::TUsbcEndpointDescriptor()" );
   455 	}
   489 	}
   456 
   490 
   457 
   491 
   458 TUsbcEndpointDescriptor* TUsbcEndpointDescriptor::New(TUint8 aEndpointAddress,
   492 TUsbcEndpointDescriptor* TUsbcEndpointDescriptor::New(TUint8 aEndpointAddress,
   459 													  const TUsbcEndpointInfo& aEpInfo)
   493 													  const TUsbcEndpointInfo& aEpInfo)
   460 	{
   494 	{
   461 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcEndpointDescriptor::New()"));
   495 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCENDPOINTDESCRIPTOR_NEW,
       
   496 	        "TUsbcEndpointDescriptor::New()" );
   462 	TUsbcEndpointDescriptor* self = new TUsbcEndpointDescriptor();
   497 	TUsbcEndpointDescriptor* self = new TUsbcEndpointDescriptor();
   463 	if (self)
   498 	if (self)
   464 		{
   499 		{
   465 		if (self->Construct(aEndpointAddress, aEpInfo) != KErrNone)
   500 		if (self->Construct(aEndpointAddress, aEpInfo) != KErrNone)
   466 			{
   501 			{
   472 	}
   507 	}
   473 
   508 
   474 
   509 
   475 TInt TUsbcEndpointDescriptor::Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo)
   510 TInt TUsbcEndpointDescriptor::Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo)
   476 	{
   511 	{
   477 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcEndpointDescriptor::Construct()"));
   512 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCENDPOINTDESCRIPTOR_CONSTRUCT,
       
   513 	        "TUsbcEndpointDescriptor::Construct()" );
   478 	(void) TUsbcEndpointDescriptorBase::Construct(aEpInfo);	// Init Base class
   514 	(void) TUsbcEndpointDescriptorBase::Construct(aEpInfo);	// Init Base class
   479 	iBuf.SetMax();
   515 	iBuf.SetMax();
   480 	SetBufferPointer(iBuf);
   516 	SetBufferPointer(iBuf);
   481 	iBuf[0] = iBuf.Size();									// bLength
   517 	iBuf[0] = iBuf.Size();									// bLength
   482 	iBuf[1] = KUsbDescType_Endpoint;						// bDescriptorType
   518 	iBuf[1] = KUsbDescType_Endpoint;						// bDescriptorType
   491 // --- TUsbcAudioEndpointDescriptor
   527 // --- TUsbcAudioEndpointDescriptor
   492 
   528 
   493 TUsbcAudioEndpointDescriptor::TUsbcAudioEndpointDescriptor()
   529 TUsbcAudioEndpointDescriptor::TUsbcAudioEndpointDescriptor()
   494 	: iBuf()
   530 	: iBuf()
   495 	{
   531 	{
   496 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcAudioEndpointDescriptor::TUsbcAudioEndpointDescriptor()"));
   532 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCAUDIOENDPOINTDESCRIPTOR_TUSBCAUDIOENDPOINTDESCRIPTOR_CONS,
       
   533 	        "TUsbcAudioEndpointDescriptor::TUsbcAudioEndpointDescriptor()" );
   497 	}
   534 	}
   498 
   535 
   499 
   536 
   500 TUsbcAudioEndpointDescriptor* TUsbcAudioEndpointDescriptor::New(TUint8 aEndpointAddress,
   537 TUsbcAudioEndpointDescriptor* TUsbcAudioEndpointDescriptor::New(TUint8 aEndpointAddress,
   501 																const TUsbcEndpointInfo& aEpInfo)
   538 																const TUsbcEndpointInfo& aEpInfo)
   502 	{
   539 	{
   503 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcAudioEndpointDescriptor::New()"));
   540 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCAUDIOENDPOINTDESCRIPTOR_NEW,
       
   541 	        "TUsbcAudioEndpointDescriptor::New()" );
   504 	TUsbcAudioEndpointDescriptor* self = new TUsbcAudioEndpointDescriptor();
   542 	TUsbcAudioEndpointDescriptor* self = new TUsbcAudioEndpointDescriptor();
   505 	if (self)
   543 	if (self)
   506 		{
   544 		{
   507 		if (self->Construct(aEndpointAddress, aEpInfo) != KErrNone)
   545 		if (self->Construct(aEndpointAddress, aEpInfo) != KErrNone)
   508 			{
   546 			{
   514 	}
   552 	}
   515 
   553 
   516 
   554 
   517 TInt TUsbcAudioEndpointDescriptor::Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo)
   555 TInt TUsbcAudioEndpointDescriptor::Construct(TUint8 aEndpointAddress, const TUsbcEndpointInfo& aEpInfo)
   518 	{
   556 	{
   519 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcAudioEndpointDescriptor::Construct()"));
   557 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCAUDIOENDPOINTDESCRIPTOR_CONSTRUCT,
       
   558 	        "TUsbcAudioEndpointDescriptor::Construct()" );
   520 	(void) TUsbcEndpointDescriptorBase::Construct(aEpInfo);	// Init Base class
   559 	(void) TUsbcEndpointDescriptorBase::Construct(aEpInfo);	// Init Base class
   521 	iBuf.SetMax();
   560 	iBuf.SetMax();
   522 	SetBufferPointer(iBuf);
   561 	SetBufferPointer(iBuf);
   523 	iBuf[0] = iBuf.Size();									// bLength
   562 	iBuf[0] = iBuf.Size();									// bLength
   524 	iBuf[1] = KUsbDescType_Endpoint;						// bDescriptorType
   563 	iBuf[1] = KUsbDescType_Endpoint;						// bDescriptorType
   534 
   573 
   535 // --- TUsbcOtgDescriptor
   574 // --- TUsbcOtgDescriptor
   536 
   575 
   537 TUsbcOtgDescriptor* TUsbcOtgDescriptor::New(TBool aHnpSupport, TBool aSrpSupport)
   576 TUsbcOtgDescriptor* TUsbcOtgDescriptor::New(TBool aHnpSupport, TBool aSrpSupport)
   538 	{
   577 	{
   539 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcOtgDescriptor::New()"));
   578 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCOTGDESCRIPTOR_NEW,
       
   579 	        "TUsbcOtgDescriptor::New()" );
   540 	TUsbcOtgDescriptor* self = new TUsbcOtgDescriptor();
   580 	TUsbcOtgDescriptor* self = new TUsbcOtgDescriptor();
   541 	if (self && (self->Construct(aHnpSupport, aSrpSupport) != KErrNone))
   581 	if (self && (self->Construct(aHnpSupport, aSrpSupport) != KErrNone))
   542 		{
   582 		{
   543 		delete self;
   583 		delete self;
   544 		return NULL;
   584 		return NULL;
   548 
   588 
   549 
   589 
   550 TUsbcOtgDescriptor::TUsbcOtgDescriptor()
   590 TUsbcOtgDescriptor::TUsbcOtgDescriptor()
   551 	: iBuf()
   591 	: iBuf()
   552 	{
   592 	{
   553 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcOtgDescriptor::TUsbcOtgDescriptor()"));
   593 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCOTGDESCRIPTOR_TUSBCOTGDESCRIPTOR_CONS, 
       
   594 	        "TUsbcOtgDescriptor::TUsbcOtgDescriptor()" );
   554 	}
   595 	}
   555 
   596 
   556 
   597 
   557 TInt TUsbcOtgDescriptor::Construct(TBool aHnpSupport, TBool aSrpSupport)
   598 TInt TUsbcOtgDescriptor::Construct(TBool aHnpSupport, TBool aSrpSupport)
   558 	{
   599 	{
   559 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcOtgDescriptor::Construct()"));
   600 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCOTGDESCRIPTOR_CONSTRUCT,
       
   601 	        "TUsbcOtgDescriptor::Construct()" );
   560 	iBuf.SetMax();
   602 	iBuf.SetMax();
   561 	SetBufferPointer(iBuf);
   603 	SetBufferPointer(iBuf);
   562 	iBuf[0] = iBuf.Size();									// bLength
   604 	iBuf[0] = iBuf.Size();									// bLength
   563 	iBuf[1] = KUsbDescType_Otg;								// bDescriptorType
   605 	iBuf[1] = KUsbDescType_Otg;								// bDescriptorType
   564 	iBuf[2] = (aHnpSupport ? KUsbOtgAttr_HnpSupp : 0) |
   606 	iBuf[2] = (aHnpSupport ? KUsbOtgAttr_HnpSupp : 0) |
   570 // --- TUsbcClassSpecificDescriptor
   612 // --- TUsbcClassSpecificDescriptor
   571 
   613 
   572 TUsbcClassSpecificDescriptor::TUsbcClassSpecificDescriptor()
   614 TUsbcClassSpecificDescriptor::TUsbcClassSpecificDescriptor()
   573 	: iBuf(NULL)
   615 	: iBuf(NULL)
   574 	{
   616 	{
   575 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcClassSpecificDescriptor::TUsbcClassSpecificDescriptor()"));
   617 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCCLASSSPECIFICDESCRIPTOR_TUSBCCLASSSPECIFICDESCRIPTOR_CONS,
       
   618 	        "TUsbcClassSpecificDescriptor::TUsbcClassSpecificDescriptor()" );
   576 	}
   619 	}
   577 
   620 
   578 
   621 
   579 TUsbcClassSpecificDescriptor::~TUsbcClassSpecificDescriptor()
   622 TUsbcClassSpecificDescriptor::~TUsbcClassSpecificDescriptor()
   580 	{
   623 	{
   581 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcClassSpecificDescriptor::~TUsbcClassSpecificDescriptor()"));
   624 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCCLASSSPECIFICDESCRIPTOR_TUSBCCLASSSPECIFICDESCRIPTOR_DES,
       
   625 	        "TUsbcClassSpecificDescriptor::~TUsbcClassSpecificDescriptor()" );
   582 	delete iBuf;
   626 	delete iBuf;
   583 	}
   627 	}
   584 
   628 
   585 
   629 
   586 TUsbcClassSpecificDescriptor* TUsbcClassSpecificDescriptor::New(TUint8 aType, TInt aSize)
   630 TUsbcClassSpecificDescriptor* TUsbcClassSpecificDescriptor::New(TUint8 aType, TInt aSize)
   587 	{
   631 	{
   588 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcClassSpecificDescriptor::New()"));
   632 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCCLASSSPECIFICDESCRIPTOR_NEW,
       
   633 	        "TUsbcClassSpecificDescriptor::New()" );
   589 	TUsbcClassSpecificDescriptor* self = new TUsbcClassSpecificDescriptor();
   634 	TUsbcClassSpecificDescriptor* self = new TUsbcClassSpecificDescriptor();
   590 	if (self)
   635 	if (self)
   591 		{
   636 		{
   592 		if (self->Construct(aType, aSize) != KErrNone)
   637 		if (self->Construct(aType, aSize) != KErrNone)
   593 			{
   638 			{
   599 	}
   644 	}
   600 
   645 
   601 
   646 
   602 TInt TUsbcClassSpecificDescriptor::Construct(TUint8 aType, TInt aSize)
   647 TInt TUsbcClassSpecificDescriptor::Construct(TUint8 aType, TInt aSize)
   603 	{
   648 	{
   604 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcClassSpecificDescriptor::Construct()"));
   649 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCCLASSSPECIFICDESCRIPTOR_CONSTRUCT, 
       
   650 	        "TUsbcClassSpecificDescriptor::Construct()" );
   605 	iBuf = HBuf8::New(aSize);
   651 	iBuf = HBuf8::New(aSize);
   606 	if (!iBuf)
   652 	if (!iBuf)
   607 		{
   653 		{
   608 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Allocation of CS desc buffer failed"));
   654 		OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCCLASSSPECIFICDESCRIPTOR_CONSTRUCT_DUP1,
       
   655 		        "  Error: Allocation of CS desc buffer failed" );
   609 		return KErrNoMemory;
   656 		return KErrNoMemory;
   610 		}
   657 		}
   611 	iBuf->SetMax();
   658 	iBuf->SetMax();
   612 	SetBufferPointer(*iBuf);
   659 	SetBufferPointer(*iBuf);
   613 	SetByte(1, aType);										// bDescriptorType
   660 	SetByte(1, aType);										// bDescriptorType
   618 // --- TUsbcStringDescriptorBase
   665 // --- TUsbcStringDescriptorBase
   619 
   666 
   620 TUsbcStringDescriptorBase::TUsbcStringDescriptorBase()
   667 TUsbcStringDescriptorBase::TUsbcStringDescriptorBase()
   621 	: /*iIndex(0),*/ iSBuf(0), iBufPtr(NULL, 0)
   668 	: /*iIndex(0),*/ iSBuf(0), iBufPtr(NULL, 0)
   622 	{
   669 	{
   623 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcStringDescriptorBase::TUsbcStringDescriptorBase()"));
   670 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCSTRINGDESCRIPTORBASE_TUSBCSTRINGDESCRIPTORBASE_CONS,
       
   671 	        "TUsbcStringDescriptorBase::TUsbcStringDescriptorBase()" );
   624 	}
   672 	}
   625 
   673 
   626 
   674 
   627 TUsbcStringDescriptorBase::~TUsbcStringDescriptorBase()
   675 TUsbcStringDescriptorBase::~TUsbcStringDescriptorBase()
   628 	{
   676 	{
   629 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcStringDescriptorBase::~TUsbcStringDescriptorBase()"));
   677 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCSTRINGDESCRIPTORBASE_TUSBCSTRINGDESCRIPTORBASE_DES, 
       
   678 	        "TUsbcStringDescriptorBase::~TUsbcStringDescriptorBase()" );
   630 	}
   679 	}
   631 
   680 
   632 
   681 
   633 TUint16 TUsbcStringDescriptorBase::Word(TInt aPosition) const
   682 TUint16 TUsbcStringDescriptorBase::Word(TInt aPosition) const
   634 	{
   683 	{
   635 	if (aPosition <= 1)
   684 	if (aPosition <= 1)
   636 		{
   685 		{
   637 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Word(%d) in string descriptor "
   686 		OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCSTRINGDESCRIPTORBASE_WORD,
   638 										  "(TUsbcStringDescriptorBase::Word)", aPosition));
   687 		        "  Error: Word(%d) in string descriptor (TUsbcStringDescriptorBase::Word)", aPosition );
   639 		return 0;
   688 		return 0;
   640 		}
   689 		}
   641 	else
   690 	else
   642 		{
   691 		{
   643 		// since iBufPtr[0] is actually string descriptor byte index 2,
   692 		// since iBufPtr[0] is actually string descriptor byte index 2,
   649 
   698 
   650 void TUsbcStringDescriptorBase::SetWord(TInt aPosition, TUint16 aValue)
   699 void TUsbcStringDescriptorBase::SetWord(TInt aPosition, TUint16 aValue)
   651 	{
   700 	{
   652 	if (aPosition <= 1)
   701 	if (aPosition <= 1)
   653 		{
   702 		{
   654 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: SetWord(%d) in string descriptor "
   703 		OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCSTRINGDESCRIPTORBASE_SETWORD,
   655 										  "(TUsbcStringDescriptorBase::SetWord)", aPosition));
   704 		        "  Error: SetWord(%d) in string descriptor (TUsbcStringDescriptorBase::SetWord)", aPosition );
   656 		return;
   705 		return;
   657 		}
   706 		}
   658 	else
   707 	else
   659 		{
   708 		{
   660 		// since iBufPtr[0] is actually string descriptor byte index 2,
   709 		// since iBufPtr[0] is actually string descriptor byte index 2,
   711 // --- TUsbcStringDescriptor
   760 // --- TUsbcStringDescriptor
   712 
   761 
   713 TUsbcStringDescriptor::TUsbcStringDescriptor()
   762 TUsbcStringDescriptor::TUsbcStringDescriptor()
   714 	: iBuf(NULL)
   763 	: iBuf(NULL)
   715 	{
   764 	{
   716 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcStringDescriptor::TUsbcStringDescriptor()"));
   765 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCSTRINGDESCRIPTOR_TUSBCSTRINGDESCRIPTOR_CONS, 
       
   766 	        "TUsbcStringDescriptor::TUsbcStringDescriptor()" );
   717 	}
   767 	}
   718 
   768 
   719 
   769 
   720 TUsbcStringDescriptor::~TUsbcStringDescriptor()
   770 TUsbcStringDescriptor::~TUsbcStringDescriptor()
   721 	{
   771 	{
   722 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcStringDescriptor::~TUsbcStringDescriptor()"));
   772 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCSTRINGDESCRIPTOR_TUSBCSTRINGDESCRIPTOR_DES,
       
   773 	        "TUsbcStringDescriptor::~TUsbcStringDescriptor()" );
   723 	delete iBuf;
   774 	delete iBuf;
   724 	}
   775 	}
   725 
   776 
   726 
   777 
   727 TUsbcStringDescriptor* TUsbcStringDescriptor::New(const TDesC8& aString)
   778 TUsbcStringDescriptor* TUsbcStringDescriptor::New(const TDesC8& aString)
   728 	{
   779 	{
   729 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcStringDescriptor::New"));
   780 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCSTRINGDESCRIPTOR_NEW, 
       
   781 	        "TUsbcStringDescriptor::New()" );
   730 	TUsbcStringDescriptor* self = new TUsbcStringDescriptor();
   782 	TUsbcStringDescriptor* self = new TUsbcStringDescriptor();
   731 	if (self)
   783 	if (self)
   732 		{
   784 		{
   733 		if (self->Construct(aString) != KErrNone)
   785 		if (self->Construct(aString) != KErrNone)
   734 			{
   786 			{
   740 	}
   792 	}
   741 
   793 
   742 
   794 
   743 TInt TUsbcStringDescriptor::Construct(const TDesC8& aString)
   795 TInt TUsbcStringDescriptor::Construct(const TDesC8& aString)
   744 	{
   796 	{
   745 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcStringDescriptor::Construct"));
   797 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCSTRINGDESCRIPTOR_CONSTRUCT,
       
   798 	        "TUsbcStringDescriptor::Construct()" );
   746 	iBuf = HBuf8::New(aString.Size());						// bytes, not UNICODE chars
   799 	iBuf = HBuf8::New(aString.Size());						// bytes, not UNICODE chars
   747 	if (!iBuf)
   800 	if (!iBuf)
   748 		{
   801 		{
   749 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Allocation of string buffer failed"));
   802 		OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCSTRINGDESCRIPTOR_CONSTRUCT_DUP1,
       
   803 		        "  Error: Allocation of string buffer failed" );
   750 		return KErrNoMemory;
   804 		return KErrNoMemory;
   751 		}
   805 		}
   752 	iBuf->SetMax();
   806 	iBuf->SetMax();
   753 	SetBufferPointer(*iBuf);
   807 	SetBufferPointer(*iBuf);
   754 	iBufPtr.Copy(aString);
   808 	iBufPtr.Copy(aString);
   762 // --- TUsbcLangIdDescriptor
   816 // --- TUsbcLangIdDescriptor
   763 
   817 
   764 TUsbcLangIdDescriptor::TUsbcLangIdDescriptor()
   818 TUsbcLangIdDescriptor::TUsbcLangIdDescriptor()
   765 	: iBuf(NULL)
   819 	: iBuf(NULL)
   766 	{
   820 	{
   767 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcLangIdDescriptor::TUsbcLangIdDescriptor()"));
   821 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCLANGIDDESCRIPTOR_TUSBCLANGIDDESCRIPTOR_CONS, 
       
   822 	        "TUsbcLangIdDescriptor::TUsbcLangIdDescriptor()" );
   768 	}
   823 	}
   769 
   824 
   770 
   825 
   771 TUsbcLangIdDescriptor::~TUsbcLangIdDescriptor()
   826 TUsbcLangIdDescriptor::~TUsbcLangIdDescriptor()
   772 	{
   827 	{
   773 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcLangIdDescriptor::~TUsbcLangIdDescriptor()"));
   828 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCLANGIDDESCRIPTOR_TUSBCLANGIDDESCRIPTOR_DES,
       
   829 	        "TUsbcLangIdDescriptor::~TUsbcLangIdDescriptor()" );
   774 	}
   830 	}
   775 
   831 
   776 
   832 
   777 TUsbcLangIdDescriptor* TUsbcLangIdDescriptor::New(TUint16 aLangId)
   833 TUsbcLangIdDescriptor* TUsbcLangIdDescriptor::New(TUint16 aLangId)
   778 	{
   834 	{
   779 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcLangIdDescriptor::New"));
   835 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCLANGIDDESCRIPTOR_NEW, 
       
   836 	        "TUsbcLangIdDescriptor::New()" );
   780 	TUsbcLangIdDescriptor* self = new TUsbcLangIdDescriptor();
   837 	TUsbcLangIdDescriptor* self = new TUsbcLangIdDescriptor();
   781 	if (self)
   838 	if (self)
   782 		{
   839 		{
   783 		if (self->Construct(aLangId) != KErrNone)
   840 		if (self->Construct(aLangId) != KErrNone)
   784 			{
   841 			{
   790 	}
   847 	}
   791 
   848 
   792 
   849 
   793 TInt TUsbcLangIdDescriptor::Construct(TUint16 aLangId)
   850 TInt TUsbcLangIdDescriptor::Construct(TUint16 aLangId)
   794 	{
   851 	{
   795 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcLangIdDescriptor::Construct"));
   852 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCLANGIDDESCRIPTOR_CONSTRUCT,
       
   853 	        "TUsbcLangIdDescriptor::Construct()" );
   796 	iBuf.SetMax();
   854 	iBuf.SetMax();
   797 	SetBufferPointer(iBuf);
   855 	SetBufferPointer(iBuf);
   798 	iBufPtr[0] = LowByte(SWAP_BYTES_16(aLangId));			// Language ID value
   856 	iBufPtr[0] = LowByte(SWAP_BYTES_16(aLangId));			// Language ID value
   799 	iBufPtr[1] = HighByte(SWAP_BYTES_16(aLangId));
   857 	iBufPtr[1] = HighByte(SWAP_BYTES_16(aLangId));
   800 	iSBuf.SetMax();
   858 	iSBuf.SetMax();
   810 //
   868 //
   811 //	The constructor for this class.
   869 //	The constructor for this class.
   812 //
   870 //
   813 	: iDescriptors(), iStrings(), iIfcIdx(0), iEp0_TxBuf(aEp0_TxBuf), iHighSpeed(EFalse)
   871 	: iDescriptors(), iStrings(), iIfcIdx(0), iEp0_TxBuf(aEp0_TxBuf), iHighSpeed(EFalse)
   814 	{
   872 	{
   815 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::TUsbcDescriptorPool()"));
   873 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_TUSBCDESCRIPTORPOOL_CONS,
       
   874 	        "TUsbcDescriptorPool::TUsbcDescriptorPool()" );
   816 	}
   875 	}
   817 
   876 
   818 
   877 
   819 TUsbcDescriptorPool::~TUsbcDescriptorPool()
   878 TUsbcDescriptorPool::~TUsbcDescriptorPool()
   820 	{
   879 	{
   821 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::~TUsbcDescriptorPool()"));
   880 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_TUSBCDESCRIPTORPOOL_DES, 
       
   881 	        "TUsbcDescriptorPool::~TUsbcDescriptorPool()" );
   822 	// The destructor of each <class T> object is called before the objects themselves are destroyed.
   882 	// The destructor of each <class T> object is called before the objects themselves are destroyed.
   823 	__KTRACE_OPT(KUSB, Kern::Printf("  iDescriptors.Count(): %d", iDescriptors.Count()));
   883 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_TUSBCDESCRIPTORPOOL_DES_DUP1,
       
   884 	        "  iDescriptors.Count(): %d", iDescriptors.Count() );
   824 	iDescriptors.ResetAndDestroy();
   885 	iDescriptors.ResetAndDestroy();
   825 	__KTRACE_OPT(KUSB, Kern::Printf("  iStrings.Count(): %d", iStrings.Count()));
   886     OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_TUSBCDESCRIPTORPOOL_DES_DUP2,
       
   887             "  iStrings.Count(): %d", iStrings.Count() );
       
   888 
   826 	iStrings.ResetAndDestroy();
   889 	iStrings.ResetAndDestroy();
   827 	}
   890 	}
   828 
   891 
   829 
   892 
   830 TInt TUsbcDescriptorPool::Init(TUsbcDeviceDescriptor* aDeviceDesc, TUsbcConfigDescriptor* aConfigDesc,
   893 TInt TUsbcDescriptorPool::Init(TUsbcDeviceDescriptor* aDeviceDesc, TUsbcConfigDescriptor* aConfigDesc,
   831 							   TUsbcLangIdDescriptor* aLangId, TUsbcStringDescriptor* aManufacturer,
   894 							   TUsbcLangIdDescriptor* aLangId, TUsbcStringDescriptor* aManufacturer,
   832 							   TUsbcStringDescriptor* aProduct, TUsbcStringDescriptor* aSerialNum,
   895 							   TUsbcStringDescriptor* aProduct, TUsbcStringDescriptor* aSerialNum,
   833 							   TUsbcStringDescriptor* aConfig, TUsbcOtgDescriptor* aOtgDesc)
   896 							   TUsbcStringDescriptor* aConfig, TUsbcOtgDescriptor* aOtgDesc)
   834 	{
   897 	{
   835 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::Init()"));
   898 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_INIT, 
       
   899 	        "TUsbcDescriptorPool::Init()" );
   836 	if (!aDeviceDesc || !aConfigDesc)
   900 	if (!aDeviceDesc || !aConfigDesc)
   837 		{
   901 		{
   838 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: No Device or Config descriptor specified"));
   902 		OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_INIT_DUP1, 
       
   903 		        "  Error: No Device or Config descriptor specified" );
   839 		return KErrArgument;
   904 		return KErrArgument;
   840 		}
   905 		}
   841 	for (TInt n = 0; n < KDescPosition_FirstAvailable; n++)
   906 	for (TInt n = 0; n < KDescPosition_FirstAvailable; n++)
   842 		{
   907 		{
   843 		iDescriptors.Append(NULL);
   908 		iDescriptors.Append(NULL);
   844 		}
   909 		}
   845 	__ASSERT_DEBUG((iDescriptors.Count() == KDescPosition_FirstAvailable),
   910 #ifdef _DEBUG
   846 				   Kern::Printf("  Error: iDescriptors.Count() (%d) != KDescPosition_FirstAvailable (%d)",
   911 	if (iDescriptors.Count() != KDescPosition_FirstAvailable)
   847 								iDescriptors.Count(), KDescPosition_FirstAvailable));
   912 	    {
       
   913         OstTraceDefExt2( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_INIT_DUP2,
       
   914                 "  Error: iDescriptors.Count() (%d) != KDescPosition_FirstAvailable (%d)",
       
   915                 iDescriptors.Count(), KDescPosition_FirstAvailable );
       
   916 
       
   917 	    }
       
   918 #endif
   848 	iDescriptors[KDescPosition_Device] = aDeviceDesc;
   919 	iDescriptors[KDescPosition_Device] = aDeviceDesc;
   849 	iDescriptors[KDescPosition_Config] = aConfigDesc;
   920 	iDescriptors[KDescPosition_Config] = aConfigDesc;
   850 	if (aOtgDesc)
   921 	if (aOtgDesc)
   851 		{
   922 		{
   852 		iDescriptors[KDescPosition_Otg] = aOtgDesc;
   923 		iDescriptors[KDescPosition_Otg] = aOtgDesc;
   857 		{
   928 		{
   858 		// USB spec 9.6.7 says: "String index zero for all languages returns a string descriptor
   929 		// USB spec 9.6.7 says: "String index zero for all languages returns a string descriptor
   859 		// that contains an array of two-byte LANGID codes supported by the device. ...
   930 		// that contains an array of two-byte LANGID codes supported by the device. ...
   860 		// USB devices that omit all string descriptors must not return an array of LANGID codes."
   931 		// USB devices that omit all string descriptors must not return an array of LANGID codes."
   861 		// So if we have at least one string descriptor, we must also have a LANGID descriptor.
   932 		// So if we have at least one string descriptor, we must also have a LANGID descriptor.
   862 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: No LANGID string descriptor specified"));
   933         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_INIT_DUP3, 
       
   934                 "  Error: No LANGID string descriptor specified" );
       
   935 
   863 		return KErrArgument;
   936 		return KErrArgument;
   864 		}
   937 		}
   865 	iStrings.Insert(aLangId, KStringPosition_Langid);
   938 	iStrings.Insert(aLangId, KStringPosition_Langid);
   866 	iStrings.Insert(aManufacturer, KStringPosition_Manufact);
   939 	iStrings.Insert(aManufacturer, KStringPosition_Manufact);
   867 	iStrings.Insert(aProduct, KStringPosition_Product);
   940 	iStrings.Insert(aProduct, KStringPosition_Product);
   868 	iStrings.Insert(aSerialNum, KStringPosition_Serial);
   941 	iStrings.Insert(aSerialNum, KStringPosition_Serial);
   869 	iStrings.Insert(aConfig, KStringPosition_Config);
   942 	iStrings.Insert(aConfig, KStringPosition_Config);
   870 	__ASSERT_DEBUG((iStrings.Count() == 5),
   943 #ifdef _DEBUG
   871 				   Kern::Printf("  Error: iStrings.Count() != 5 (%d)", iStrings.Count()));
   944 	if (iStrings.Count() != 5)
       
   945 	    {
       
   946         OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_INIT_DUP4,
       
   947                 "  Error: iStrings.Count() != 5 (%d)", iStrings.Count() );
       
   948 	    }
       
   949 #endif
   872 #ifdef _DEBUG
   950 #ifdef _DEBUG
   873 	for (TInt i = KStringPosition_Langid; i <= KStringPosition_Config; i++)
   951 	for (TInt i = KStringPosition_Langid; i <= KStringPosition_Config; i++)
   874 		{
   952 		{
   875 		__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool.iStrings[%d] = 0x%x", i, iStrings[i]));
   953         OstTraceDefExt2( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_INIT_DUP5,
       
   954                 "TUsbcDescriptorPool.iStrings[%d] = 0x%x", i, reinterpret_cast<TUint>(iStrings[i]) );
   876 		}
   955 		}
   877 #endif
   956 #endif
   878 	// Set string indices
   957 	// Set string indices
   879 	if (aManufacturer)
   958 	if (aManufacturer)
   880 		iDescriptors[KDescPosition_Device]->SetByte(KUsbDescStringIndex_Manufact,
   959 		iDescriptors[KDescPosition_Device]->SetByte(KUsbDescStringIndex_Manufact,
   892 	}
   971 	}
   893 
   972 
   894 
   973 
   895 TInt TUsbcDescriptorPool::InitHs()
   974 TInt TUsbcDescriptorPool::InitHs()
   896 	{
   975 	{
   897 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::InitHs()"));
   976 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_INITHS, 
   898 	__ASSERT_DEBUG((iDescriptors.Count() >= KDescPosition_FirstAvailable),
   977 	        "TUsbcDescriptorPool::InitHs()" );
   899 				   Kern::Printf("  Error: Call Init() first)"));
   978 #ifdef _DEBUG
       
   979 	if (iDescriptors.Count() < KDescPosition_FirstAvailable)
       
   980 	    {
       
   981         OstTraceDef0( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_INITHS_DUP1, 
       
   982                 "  Error: Call Init() first)" );
       
   983 
       
   984 	    }
       
   985 #endif
   900 
   986 
   901 	TUsbcDeviceQualifierDescriptor* const dq_desc = TUsbcDeviceQualifierDescriptor::New(
   987 	TUsbcDeviceQualifierDescriptor* const dq_desc = TUsbcDeviceQualifierDescriptor::New(
   902 		iDescriptors[KDescPosition_Device]->Byte(4),		// aDeviceClass
   988 		iDescriptors[KDescPosition_Device]->Byte(4),		// aDeviceClass
   903 		iDescriptors[KDescPosition_Device]->Byte(5),		// aDeviceSubClass
   989 		iDescriptors[KDescPosition_Device]->Byte(5),		// aDeviceSubClass
   904 		iDescriptors[KDescPosition_Device]->Byte(6),		// aDeviceProtocol
   990 		iDescriptors[KDescPosition_Device]->Byte(6),		// aDeviceProtocol
   905 		iDescriptors[KDescPosition_Device]->Byte(7),		// aMaxPacketSize0
   991 		iDescriptors[KDescPosition_Device]->Byte(7),		// aMaxPacketSize0
   906 		iDescriptors[KDescPosition_Device]->Byte(17));		// aNumConfigurations
   992 		iDescriptors[KDescPosition_Device]->Byte(17));		// aNumConfigurations
   907 	if (!dq_desc)
   993 	if (!dq_desc)
   908 		{
   994 		{
   909 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Memory allocation for dev qualif desc failed."));
   995         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_INITHS_DUP2,
       
   996                 "  Error: Memory allocation for dev qualif desc failed." );
   910 		return KErrGeneral;
   997 		return KErrGeneral;
   911 		}
   998 		}
   912 	iDescriptors[KDescPosition_DeviceQualifier] = dq_desc;
   999 	iDescriptors[KDescPosition_DeviceQualifier] = dq_desc;
   913 
  1000 
   914 	TUsbcOtherSpeedConfigDescriptor* const osc_desc = TUsbcOtherSpeedConfigDescriptor::New(
  1001 	TUsbcOtherSpeedConfigDescriptor* const osc_desc = TUsbcOtherSpeedConfigDescriptor::New(
   916 		iDescriptors[KDescPosition_Config]->Byte(7) & KUsbDevAttr_SelfPowered, // aSelfPowered
  1003 		iDescriptors[KDescPosition_Config]->Byte(7) & KUsbDevAttr_SelfPowered, // aSelfPowered
   917 		iDescriptors[KDescPosition_Config]->Byte(7) & KUsbDevAttr_RemoteWakeup,	// aRemoteWakeup
  1004 		iDescriptors[KDescPosition_Config]->Byte(7) & KUsbDevAttr_RemoteWakeup,	// aRemoteWakeup
   918 		iDescriptors[KDescPosition_Config]->Byte(8) * 2);	// aMaxPower (mA)
  1005 		iDescriptors[KDescPosition_Config]->Byte(8) * 2);	// aMaxPower (mA)
   919 	if (!osc_desc)
  1006 	if (!osc_desc)
   920 		{
  1007 		{
   921 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Memory allocation for other speed conf desc failed."));
  1008         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_INITHS_DUP3,
       
  1009                 "  Error: Memory allocation for other speed conf desc failed." );
   922 		return KErrGeneral;
  1010 		return KErrGeneral;
   923 		}
  1011 		}
   924 
  1012 
   925 	// We need to set the bDescriptorType field manually, as that's the only one
  1013 	// We need to set the bDescriptorType field manually, as that's the only one
   926 	// that differs from a Configuration descriptor.
  1014 	// that differs from a Configuration descriptor.
   937 	}
  1025 	}
   938 
  1026 
   939 
  1027 
   940 TInt TUsbcDescriptorPool::UpdateDescriptorsFs()
  1028 TInt TUsbcDescriptorPool::UpdateDescriptorsFs()
   941 	{
  1029 	{
   942 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::UpdateDescriptorsFs()"));
  1030 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_UPDATEDESCRIPTORSFS,
       
  1031 	        "TUsbcDescriptorPool::UpdateDescriptorsFs()" );
   943 	const TInt count = iDescriptors.Count();
  1032 	const TInt count = iDescriptors.Count();
   944 	for (TInt i = KDescPosition_FirstAvailable; i < count; i++)
  1033 	for (TInt i = KDescPosition_FirstAvailable; i < count; i++)
   945 		{
  1034 		{
   946 		TUsbcDescriptorBase* const ptr = iDescriptors[i];
  1035 		TUsbcDescriptorBase* const ptr = iDescriptors[i];
   947 		ptr->UpdateFs();
  1036 		ptr->UpdateFs();
   951 	}
  1040 	}
   952 
  1041 
   953 
  1042 
   954 TInt TUsbcDescriptorPool::UpdateDescriptorsHs()
  1043 TInt TUsbcDescriptorPool::UpdateDescriptorsHs()
   955 	{
  1044 	{
   956 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::UpdateDescriptorsHs()"));
  1045 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_UPDATEDESCRIPTORSHS,
       
  1046 	        "TUsbcDescriptorPool::UpdateDescriptorsHs()" );
   957 	const TInt count = iDescriptors.Count();
  1047 	const TInt count = iDescriptors.Count();
   958 	for (TInt i = KDescPosition_FirstAvailable; i < count; i++)
  1048 	for (TInt i = KDescPosition_FirstAvailable; i < count; i++)
   959 		{
  1049 		{
   960 		TUsbcDescriptorBase* const ptr = iDescriptors[i];
  1050 		TUsbcDescriptorBase* const ptr = iDescriptors[i];
   961 		ptr->UpdateHs();
  1051 		ptr->UpdateHs();
   968 //
  1058 //
   969 // An error can be indicated by either a return value != KErrNone or by a descriptor size == 0.
  1059 // An error can be indicated by either a return value != KErrNone or by a descriptor size == 0.
   970 //
  1060 //
   971 TInt TUsbcDescriptorPool::FindDescriptor(TUint8 aType, TUint8 aIndex, TUint16 aLangid, TInt& aSize) const
  1061 TInt TUsbcDescriptorPool::FindDescriptor(TUint8 aType, TUint8 aIndex, TUint16 aLangid, TInt& aSize) const
   972 	{
  1062 	{
   973 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::FindDescriptor()"));
  1063 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR, 
       
  1064 	        "TUsbcDescriptorPool::FindDescriptor()" );
   974 	TInt result = KErrGeneral;
  1065 	TInt result = KErrGeneral;
   975 	switch (aType)
  1066 	switch (aType)
   976 		{
  1067 		{
   977 	case KUsbDescType_Device:
  1068 	case KUsbDescType_Device:
   978 		if (aLangid != 0)
  1069 		if (aLangid != 0)
   979 			{
  1070 			{
   980 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: bad langid: 0x%04x", aLangid));
  1071 		 OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP1,
       
  1072 		         "  Error: bad langid: 0x%04x", aLangid );
   981 			}
  1073 			}
   982 		else if (aIndex > 0)
  1074 		else if (aIndex > 0)
   983 			{
  1075 			{
   984 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: bad device index: %d", aIndex));
  1076 	       OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP2,
       
  1077 	               "  Error: bad device index: %d", aIndex );
   985 			}
  1078 			}
   986 		else
  1079 		else
   987 			{
  1080 			{
   988 			aSize = GetDeviceDescriptor(KDescPosition_Device);
  1081 			aSize = GetDeviceDescriptor(KDescPosition_Device);
   989 			result = KErrNone;
  1082 			result = KErrNone;
   990 			}
  1083 			}
   991 		break;
  1084 		break;
   992 	case KUsbDescType_Config:
  1085 	case KUsbDescType_Config:
   993 		if (aLangid != 0)
  1086 		if (aLangid != 0)
   994 			{
  1087 			{
   995 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: bad langid: 0x%04x", aLangid));
  1088             OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP3,
       
  1089                     "  Error: bad langid: 0x%04x", aLangid );
   996 			}
  1090 			}
   997 		else if (aIndex > 0)
  1091 		else if (aIndex > 0)
   998 			{
  1092 			{
   999 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: bad config index: %d", aIndex));
  1093             OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP4,
       
  1094                     "  Error: bad config index: %d", aIndex );
  1000 			}
  1095 			}
  1001 		else
  1096 		else
  1002 			{
  1097 			{
  1003 			aSize = GetConfigurationDescriptor(KDescPosition_Config);
  1098 			aSize = GetConfigurationDescriptor(KDescPosition_Config);
  1004 			result = KErrNone;
  1099 			result = KErrNone;
  1005 			}
  1100 			}
  1006 		break;
  1101 		break;
  1007 	case KUsbDescType_DeviceQualifier:
  1102 	case KUsbDescType_DeviceQualifier:
  1008 		if (aLangid != 0)
  1103 		if (aLangid != 0)
  1009 			{
  1104 			{
  1010 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: bad langid: 0x%04x", aLangid));
  1105             OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP5,
       
  1106                     "  Error: bad langid: 0x%04x", aLangid );
  1011 			}
  1107 			}
  1012 		else if (aIndex > 0)
  1108 		else if (aIndex > 0)
  1013 			{
  1109 			{
  1014 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: bad device index: %d", aIndex));
  1110             OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP6,
       
  1111                     "  Error: bad device index: %d", aIndex );
  1015 			}
  1112 			}
  1016 		else
  1113 		else
  1017 			{
  1114 			{
  1018 			aSize = GetDeviceDescriptor(KDescPosition_DeviceQualifier);
  1115 			aSize = GetDeviceDescriptor(KDescPosition_DeviceQualifier);
  1019 			result = KErrNone;
  1116 			result = KErrNone;
  1020 			}
  1117 			}
  1021 		break;
  1118 		break;
  1022 	case KUsbDescType_OtherSpeedConfig:
  1119 	case KUsbDescType_OtherSpeedConfig:
  1023 		if (aLangid != 0)
  1120 		if (aLangid != 0)
  1024 			{
  1121 			{
  1025 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: bad langid: 0x%04x", aLangid));
  1122             OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP7,
       
  1123                     "  Error: bad langid: 0x%04x", aLangid );
  1026 			}
  1124 			}
  1027 		else if (aIndex > 0)
  1125 		else if (aIndex > 0)
  1028 			{
  1126 			{
  1029 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: bad config index: %d", aIndex));
  1127             OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP8,
       
  1128                     "  Error: bad config index: %d", aIndex );
  1030 			}
  1129 			}
  1031 		else
  1130 		else
  1032 			{
  1131 			{
  1033 			aSize = GetConfigurationDescriptor(KDescPosition_OtherSpeedConfig);
  1132 			aSize = GetConfigurationDescriptor(KDescPosition_OtherSpeedConfig);
  1034 			result = KErrNone;
  1133 			result = KErrNone;
  1046 				aSize = GetStringDescriptor(aIndex);
  1145 				aSize = GetStringDescriptor(aIndex);
  1047 				result = KErrNone;
  1146 				result = KErrNone;
  1048 				}
  1147 				}
  1049 			else
  1148 			else
  1050 				{
  1149 				{
  1051 				__KTRACE_OPT(KUSB, Kern::Printf("  No string descriptors: not returning LANGID array"));
  1150                 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP9,
       
  1151                         "  No string descriptors: not returning LANGID array" );
  1052 				}
  1152 				}
  1053 			}
  1153 			}
  1054 		else
  1154 		else
  1055 			{
  1155 			{
  1056    			if (!aLangid)
  1156    			if (!aLangid)
  1057    				{
  1157    				{
  1058    				__KTRACE_OPT(KUSB,
  1158                 OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP10,
  1059  							 Kern::Printf("  Strange: LANGID=0 for a $ descriptor (ignoring LANGID)"));
  1159                         "  Strange: LANGID=0 for a $ descriptor (ignoring LANGID)" );
  1060 				// The USB spec doesn't really say what to do in this case, but as there are host apps
  1160 				// The USB spec doesn't really say what to do in this case, but as there are host apps
  1061 				// that fail if we return an error here, we choose to ignore the issue.
  1161 				// that fail if we return an error here, we choose to ignore the issue.
  1062    				}
  1162    				}
  1063 			else if (aLangid != iStrings[KStringPosition_Langid]->Word(2))
  1163 			else if (aLangid != iStrings[KStringPosition_Langid]->Word(2))
  1064 				{
  1164 				{
  1065 				// We have only one (this) language
  1165 				// We have only one (this) language
  1066 				__KTRACE_OPT(KUSB,
  1166                 OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP11,
  1067 							 Kern::Printf("  Bad LANGID: 0x%04X requested, 0x%04X supported (ignoring LANGID)",
  1167                         "  Bad LANGID: 0x%04X requested, 0x%04X supported (ignoring LANGID)",
  1068 										  aLangid, iStrings[KStringPosition_Langid]->Word(2)));
  1168                         aLangid, iStrings[KStringPosition_Langid]->Word(2) );
  1069 				// We could return an error here, but rather choose to ignore the discrepancy
  1169 				// We could return an error here, but rather choose to ignore the discrepancy
  1070 				// (the USB spec is not very clear what to do in such a case anyway).
  1170 				// (the USB spec is not very clear what to do in such a case anyway).
  1071 				}
  1171 				}
  1072 			aSize = GetStringDescriptor(aIndex);
  1172 			aSize = GetStringDescriptor(aIndex);
  1073 			result = KErrNone;
  1173 			result = KErrNone;
  1074 			}
  1174 			}
  1075 		break;
  1175 		break;
  1076 	case KUsbDescType_CS_Interface:
  1176 	case KUsbDescType_CS_Interface:
  1077 		/* fall through */
  1177 		/* fall through */
  1078 	case KUsbDescType_CS_Endpoint:
  1178 	case KUsbDescType_CS_Endpoint:
  1079 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: finding of class specific descriptors not supported"));
  1179         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP12,
       
  1180                 "  Warning: finding of class specific descriptors not supported" );
  1080 		break;
  1181 		break;
  1081 	default:
  1182 	default:
  1082 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: unknown descriptor type requested: %d", aType));
  1183         OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDDESCRIPTOR_DUP13,
       
  1184                 "  Error: unknown descriptor type requested: %d", aType );
  1083 		break;
  1185 		break;
  1084 		}
  1186 		}
  1085 	return result;
  1187 	return result;
  1086 	}
  1188 	}
  1087 
  1189 
  1088 
  1190 
  1089 void TUsbcDescriptorPool::InsertDescriptor(TUsbcDescriptorBase* aDesc)
  1191 void TUsbcDescriptorPool::InsertDescriptor(TUsbcDescriptorBase* aDesc)
  1090 	{
  1192 	{
  1091 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::InsertDescriptor()"));
  1193 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_INSERTDESCRIPTOR, 
       
  1194 	        "TUsbcDescriptorPool::InsertDescriptor()" );
  1092 	switch (aDesc->Type())
  1195 	switch (aDesc->Type())
  1093 		{
  1196 		{
  1094 	case KUsbDescType_Interface:
  1197 	case KUsbDescType_Interface:
  1095 		InsertIfcDesc(aDesc);
  1198 		InsertIfcDesc(aDesc);
  1096 		break;
  1199 		break;
  1097 	case KUsbDescType_Endpoint:
  1200 	case KUsbDescType_Endpoint:
  1098 		InsertEpDesc(aDesc);
  1201 		InsertEpDesc(aDesc);
  1099 		break;
  1202 		break;
  1100 	default:
  1203 	default:
  1101 		__KTRACE_OPT(KUSB, Kern::Printf("  Error: unsupported descriptor type"));
  1204 	    OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_INSERTDESCRIPTOR_DUP1,
       
  1205 	            "  Error: unsupported descriptor type" );
  1102 		}
  1206 		}
  1103 	}
  1207 	}
  1104 
  1208 
  1105 
  1209 
  1106 void TUsbcDescriptorPool::SetIfcStringDescriptor(TUsbcStringDescriptor* aDesc, TInt aNumber, TInt aSetting)
  1210 void TUsbcDescriptorPool::SetIfcStringDescriptor(TUsbcStringDescriptor* aDesc, TInt aNumber, TInt aSetting)
  1107 	{
  1211 	{
  1108 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::SetIfcDescriptor(%d, %d)", aNumber, aSetting));
  1212 	OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_SETIFCSTRINGDESCRIPTOR,
       
  1213 	        "TUsbcDescriptorPool::SetIfcDescriptor(%d, %d)", aNumber, aSetting );
  1109 	const TInt i = FindIfcDescriptor(aNumber, aSetting);
  1214 	const TInt i = FindIfcDescriptor(aNumber, aSetting);
  1110 	if (i < 0)
  1215 	if (i < 0)
  1111 		{
  1216 		{
  1112 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Ifc descriptor not found (%d, %d)",
  1217 	    OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETIFCSTRINGDESCRIPTOR_DUP1,
  1113 										  aNumber, aSetting));
  1218 	           "  Error: Ifc descriptor not found (%d, %d)", aNumber, aSetting );
  1114 		return;
  1219 		return;
  1115 		}
  1220 		}
  1116 	// Try to find available NULL postition
  1221 	// Try to find available NULL postition
  1117 	TInt str_idx = FindAvailableStringPos();
  1222 	TInt str_idx = FindAvailableStringPos();
  1118 	if (str_idx >= 0)
  1223 	if (str_idx >= 0)
  1124 		{
  1229 		{
  1125 		// No NULL found - expand array
  1230 		// No NULL found - expand array
  1126 		str_idx = iStrings.Count();
  1231 		str_idx = iStrings.Count();
  1127 		if (str_idx > 0xff)
  1232 		if (str_idx > 0xff)
  1128 			{
  1233 			{
  1129 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: $ descriptor array full (idx=%d)", str_idx));
  1234             OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETIFCSTRINGDESCRIPTOR_DUP2,
       
  1235                     "  Error: $ descriptor array full (idx=%d)", str_idx );
  1130 			return;
  1236 			return;
  1131 			}
  1237 			}
  1132 		while (str_idx < KStringPosition_FirstAvailable)
  1238 		while (str_idx < KStringPosition_FirstAvailable)
  1133 			{
  1239 			{
  1134 			iStrings.Append(NULL);
  1240 			iStrings.Append(NULL);
  1137 		// Append string descriptor for specified interface
  1243 		// Append string descriptor for specified interface
  1138 		iStrings.Append(aDesc);
  1244 		iStrings.Append(aDesc);
  1139 		}
  1245 		}
  1140 	// Update this ifc descriptor's string index field
  1246 	// Update this ifc descriptor's string index field
  1141 	iDescriptors[i]->SetByte(8, str_idx);
  1247 	iDescriptors[i]->SetByte(8, str_idx);
  1142 	__KTRACE_OPT(KUSB, Kern::Printf("  String for ifc %d/%d (@ pos %d): \"%S\"", aNumber, aSetting, str_idx,
  1248 	OstTraceDefExt4( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_SETIFCSTRINGDESCRIPTOR_DUP3,
  1143 									&iStrings[str_idx]->StringData()));
  1249 	        "  String for ifc %d/%d (@ pos %d): \"%s\"", aNumber, aSetting, str_idx,
       
  1250 	        iStrings[str_idx]->StringData() );
  1144 	}
  1251 	}
  1145 
  1252 
  1146 
  1253 
  1147 void TUsbcDescriptorPool::DeleteIfcDescriptor(TInt aNumber, TInt aSetting)
  1254 void TUsbcDescriptorPool::DeleteIfcDescriptor(TInt aNumber, TInt aSetting)
  1148 	{
  1255 	{
  1149 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::DeleteIfcDescriptor(%d, %d)", aNumber, aSetting));
  1256 	OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_DELETEIFCDESCRIPTOR,
       
  1257 	        "TUsbcDescriptorPool::DeleteIfcDescriptor(%d, %d)", aNumber, aSetting );	        
  1150 	const TInt i = FindIfcDescriptor(aNumber, aSetting);
  1258 	const TInt i = FindIfcDescriptor(aNumber, aSetting);
  1151 	if (i < 0)
  1259 	if (i < 0)
  1152 		{
  1260 		{
  1153 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: DeleteIfcDescriptor - descriptor not found (%d, %d)",
  1261         OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_DELETEIFCDESCRIPTOR_DUP1,
  1154 										  aNumber, aSetting));
  1262                 "  Error: DeleteIfcDescriptor - descriptor not found (%d, %d)", aNumber, aSetting );
  1155 		return;
  1263 		return;
  1156 		}
  1264 		}
  1157 	// Delete (if necessary) specified interface's string descriptor
  1265 	// Delete (if necessary) specified interface's string descriptor
  1158 	const TInt si = iDescriptors[i]->Byte(8);
  1266 	const TInt si = iDescriptors[i]->Byte(8);
  1159 	if (si != 0)
  1267 	if (si != 0)
  1177 // The TC in many of the following functions stands for 'ThreadCopy',
  1285 // The TC in many of the following functions stands for 'ThreadCopy',
  1178 // because that's what's happening there.
  1286 // because that's what's happening there.
  1179 
  1287 
  1180 TInt TUsbcDescriptorPool::GetDeviceDescriptorTC(DThread* aThread, TDes8& aBuffer) const
  1288 TInt TUsbcDescriptorPool::GetDeviceDescriptorTC(DThread* aThread, TDes8& aBuffer) const
  1181 	{
  1289 	{
  1182 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetDeviceDescriptorTC()"));
  1290 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETDEVICEDESCRIPTORTC, 
       
  1291 	        "TUsbcDescriptorPool::GetDeviceDescriptorTC()" );
  1183 	return Kern::ThreadDesWrite(aThread, &aBuffer, iDescriptors[KDescPosition_Device]->DescriptorData(), 0);
  1292 	return Kern::ThreadDesWrite(aThread, &aBuffer, iDescriptors[KDescPosition_Device]->DescriptorData(), 0);
  1184 	}
  1293 	}
  1185 
  1294 
  1186 
  1295 
  1187 TInt TUsbcDescriptorPool::SetDeviceDescriptorTC(DThread* aThread, const TDes8& aBuffer)
  1296 TInt TUsbcDescriptorPool::SetDeviceDescriptorTC(DThread* aThread, const TDes8& aBuffer)
  1188 	{
  1297 	{
  1189 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::SetDeviceDescriptorTC()"));
  1298 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_SETDEVICEDESCRIPTORTC, 
       
  1299 	        "TUsbcDescriptorPool::SetDeviceDescriptorTC()" );
  1190 	TBuf8<KUsbDescSize_Device> device;
  1300 	TBuf8<KUsbDescSize_Device> device;
  1191 	const TInt r = Kern::ThreadDesRead(aThread, &aBuffer, device, 0);
  1301 	const TInt r = Kern::ThreadDesRead(aThread, &aBuffer, device, 0);
  1192 	if (r != KErrNone)
  1302 	if (r != KErrNone)
  1193 		{
  1303 		{
  1194 		return r;
  1304 		return r;
  1208 	}
  1318 	}
  1209 
  1319 
  1210 
  1320 
  1211 TInt TUsbcDescriptorPool::GetConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const
  1321 TInt TUsbcDescriptorPool::GetConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const
  1212 	{
  1322 	{
  1213 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetConfigurationDescriptorTC()"));
  1323 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONDESCRIPTORTC, 
       
  1324 	        "TUsbcDescriptorPool::GetConfigurationDescriptorTC()" );
  1214 	return Kern::ThreadDesWrite(aThread, &aBuffer, iDescriptors[KDescPosition_Config]->DescriptorData(), 0);
  1325 	return Kern::ThreadDesWrite(aThread, &aBuffer, iDescriptors[KDescPosition_Config]->DescriptorData(), 0);
  1215 	}
  1326 	}
  1216 
  1327 
  1217 
  1328 
  1218 TInt TUsbcDescriptorPool::SetConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer)
  1329 TInt TUsbcDescriptorPool::SetConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer)
  1219 	{
  1330 	{
  1220 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::SetConfigurationDescriptorTC()"));
  1331 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_SETCONFIGURATIONDESCRIPTORTC, 
       
  1332 	        "TUsbcDescriptorPool::SetConfigurationDescriptorTC()" );
  1221 	TBuf8<KUsbDescSize_Config> config;
  1333 	TBuf8<KUsbDescSize_Config> config;
  1222 	const TInt r = Kern::ThreadDesRead(aThread, &aBuffer, config, 0);
  1334 	const TInt r = Kern::ThreadDesRead(aThread, &aBuffer, config, 0);
  1223 	if (r != KErrNone)
  1335 	if (r != KErrNone)
  1224 		{
  1336 		{
  1225 		return r;
  1337 		return r;
  1244 
  1356 
  1245 
  1357 
  1246 TInt TUsbcDescriptorPool::GetInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer,
  1358 TInt TUsbcDescriptorPool::GetInterfaceDescriptorTC(DThread* aThread, TDes8& aBuffer,
  1247 												   TInt aInterface, TInt aSetting) const
  1359 												   TInt aInterface, TInt aSetting) const
  1248 	{
  1360 	{
  1249 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetInterfaceDescriptorTC()"));
  1361 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETINTERFACEDESCRIPTORTC,
       
  1362 	        "TUsbcDescriptorPool::GetInterfaceDescriptorTC()" );
  1250 	const TInt i = FindIfcDescriptor(aInterface, aSetting);
  1363 	const TInt i = FindIfcDescriptor(aInterface, aSetting);
  1251 	if (i < 0)
  1364 	if (i < 0)
  1252 		{
  1365 		{
  1253 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such interface"));
  1366         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETINTERFACEDESCRIPTORTC_DUP1,
       
  1367                 "  Error: no such interface" );
  1254 		return KErrNotFound;
  1368 		return KErrNotFound;
  1255 		}
  1369 		}
  1256 	return Kern::ThreadDesWrite(aThread, &aBuffer, iDescriptors[i]->DescriptorData(), 0);
  1370 	return Kern::ThreadDesWrite(aThread, &aBuffer, iDescriptors[i]->DescriptorData(), 0);
  1257 	}
  1371 	}
  1258 
  1372 
  1259 
  1373 
  1260 TInt TUsbcDescriptorPool::SetInterfaceDescriptor(const TDes8& aBuffer, TInt aInterface, TInt aSetting)
  1374 TInt TUsbcDescriptorPool::SetInterfaceDescriptor(const TDes8& aBuffer, TInt aInterface, TInt aSetting)
  1261 	{
  1375 	{
  1262 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::SetInterfaceDescriptor()"));
  1376 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_SETINTERFACEDESCRIPTOR, 
       
  1377 	        "TUsbcDescriptorPool::SetInterfaceDescriptor()" );
  1263 	const TInt i = FindIfcDescriptor(aInterface, aSetting);
  1378 	const TInt i = FindIfcDescriptor(aInterface, aSetting);
  1264 	if (i < 0)
  1379 	if (i < 0)
  1265 		{
  1380 		{
  1266 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such interface"));
  1381         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETINTERFACEDESCRIPTOR_DUP1,
       
  1382                 "  Error: no such interface" );
  1267 		return KErrNotFound;
  1383 		return KErrNotFound;
  1268 		}
  1384 		}
  1269 	iDescriptors[i]->SetByte(2, aBuffer[2]);				// bInterfaceNumber
  1385 	iDescriptors[i]->SetByte(2, aBuffer[2]);				// bInterfaceNumber
  1270 	iDescriptors[i]->SetByte(5, aBuffer[5]);				// bInterfaceClass
  1386 	iDescriptors[i]->SetByte(5, aBuffer[5]);				// bInterfaceClass
  1271 	iDescriptors[i]->SetByte(6, aBuffer[6]);				// bInterfaceSubClass
  1387 	iDescriptors[i]->SetByte(6, aBuffer[6]);				// bInterfaceSubClass
  1275 
  1391 
  1276 
  1392 
  1277 TInt TUsbcDescriptorPool::GetEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer,
  1393 TInt TUsbcDescriptorPool::GetEndpointDescriptorTC(DThread* aThread, TDes8& aBuffer,
  1278 												  TInt aInterface, TInt aSetting, TUint8 aEndpointAddress) const
  1394 												  TInt aInterface, TInt aSetting, TUint8 aEndpointAddress) const
  1279 	{
  1395 	{
  1280 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetEndpointDescriptorTC()"));
  1396 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETENDPOINTDESCRIPTORTC,
       
  1397 	        "TUsbcDescriptorPool::GetEndpointDescriptorTC()" );
  1281 	const TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1398 	const TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1282 	if (i < 0)
  1399 	if (i < 0)
  1283 		{
  1400 		{
  1284 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such endpoint"));
  1401         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETENDPOINTDESCRIPTORTC_DUP1,
       
  1402                 "  Error: no such endpoint" );
  1285 		return KErrNotFound;
  1403 		return KErrNotFound;
  1286 		}
  1404 		}
  1287 	return Kern::ThreadDesWrite(aThread, &aBuffer, iDescriptors[i]->DescriptorData(), 0);
  1405 	return Kern::ThreadDesWrite(aThread, &aBuffer, iDescriptors[i]->DescriptorData(), 0);
  1288 	}
  1406 	}
  1289 
  1407 
  1290 
  1408 
  1291 TInt TUsbcDescriptorPool::SetEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer,
  1409 TInt TUsbcDescriptorPool::SetEndpointDescriptorTC(DThread* aThread, const TDes8& aBuffer,
  1292 												  TInt aInterface, TInt aSetting, TUint8 aEndpointAddress)
  1410 												  TInt aInterface, TInt aSetting, TUint8 aEndpointAddress)
  1293 	{
  1411 	{
  1294 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::SetEndpointDescriptorTC()"));
  1412 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_SETENDPOINTDESCRIPTORTC, 
       
  1413 	        "TUsbcDescriptorPool::SetEndpointDescriptorTC()" );
  1295 	const TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1414 	const TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1296 	if (i < 0)
  1415 	if (i < 0)
  1297 		{
  1416 		{
  1298 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such endpoint"));
  1417 	    OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETENDPOINTDESCRIPTORTC_DUP1, 
       
  1418 	            "  Error: no such endpoint" );
  1299 		return KErrNotFound;
  1419 		return KErrNotFound;
  1300 		}
  1420 		}
  1301 	TBuf8<KUsbDescSize_AudioEndpoint> ep;					// it could be an audio endpoint
  1421 	TBuf8<KUsbDescSize_AudioEndpoint> ep;					// it could be an audio endpoint
  1302 	const TInt r = Kern::ThreadDesRead(aThread, &aBuffer, ep, 0);
  1422 	const TInt r = Kern::ThreadDesRead(aThread, &aBuffer, ep, 0);
  1303 	if (r != KErrNone)
  1423 	if (r != KErrNone)
  1316 
  1436 
  1317 
  1437 
  1318 TInt TUsbcDescriptorPool::GetEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress,
  1438 TInt TUsbcDescriptorPool::GetEndpointDescriptorSize(TInt aInterface, TInt aSetting, TUint8 aEndpointAddress,
  1319 													TInt& aSize) const
  1439 													TInt& aSize) const
  1320 	{
  1440 	{
  1321 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetEndpointDescriptorSize()"));
  1441 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETENDPOINTDESCRIPTORSIZE,
       
  1442 	        "TUsbcDescriptorPool::GetEndpointDescriptorSize()" );
  1322 	const TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1443 	const TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1323 	if (i < 0)
  1444 	if (i < 0)
  1324 		{
  1445 		{
  1325 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such endpoint"));
  1446         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETENDPOINTDESCRIPTORSIZE_DUP1,
       
  1447                 "  Error: no such endpoint" );
  1326 		return KErrNotFound;
  1448 		return KErrNotFound;
  1327 		}
  1449 		}
  1328 	aSize = iDescriptors[i]->Size();
  1450 	aSize = iDescriptors[i]->Size();
  1329 	return KErrNone;
  1451 	return KErrNone;
  1330 	}
  1452 	}
  1331 
  1453 
  1332 
  1454 
  1333 TInt TUsbcDescriptorPool::GetDeviceQualifierDescriptorTC(DThread* aThread, TDes8& aBuffer) const
  1455 TInt TUsbcDescriptorPool::GetDeviceQualifierDescriptorTC(DThread* aThread, TDes8& aBuffer) const
  1334 	{
  1456 	{
  1335 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetDeviceQualifierDescriptorTC()"));
  1457 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETDEVICEQUALIFIERDESCRIPTORTC, 
       
  1458 	        "TUsbcDescriptorPool::GetDeviceQualifierDescriptorTC()" );
  1336 	if (iDescriptors[KDescPosition_DeviceQualifier] == NULL)
  1459 	if (iDescriptors[KDescPosition_DeviceQualifier] == NULL)
  1337 		{
  1460 		{
  1338 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Device_Qualifier descriptor not supported"));
  1461 	    OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETDEVICEQUALIFIERDESCRIPTORTC_DUP1, 
       
  1462 	            "  Warning: Device_Qualifier descriptor not supported" );
  1339 		return KErrNotSupported;
  1463 		return KErrNotSupported;
  1340 		}
  1464 		}
  1341 	return Kern::ThreadDesWrite(aThread, &aBuffer,
  1465 	return Kern::ThreadDesWrite(aThread, &aBuffer,
  1342 								iDescriptors[KDescPosition_DeviceQualifier]->DescriptorData(), 0);
  1466 								iDescriptors[KDescPosition_DeviceQualifier]->DescriptorData(), 0);
  1343 	}
  1467 	}
  1344 
  1468 
  1345 
  1469 
  1346 TInt TUsbcDescriptorPool::SetDeviceQualifierDescriptorTC(DThread* aThread, const TDes8& aBuffer)
  1470 TInt TUsbcDescriptorPool::SetDeviceQualifierDescriptorTC(DThread* aThread, const TDes8& aBuffer)
  1347 	{
  1471 	{
  1348 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::SetDeviceQualifierDescriptorTC()"));
  1472 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_SETDEVICEQUALIFIERDESCRIPTORTC,
       
  1473 	        "TUsbcDescriptorPool::SetDeviceQualifierDescriptorTC()" );
  1349 	if (iDescriptors[KDescPosition_DeviceQualifier] == NULL)
  1474 	if (iDescriptors[KDescPosition_DeviceQualifier] == NULL)
  1350 		{
  1475 		{
  1351 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Device_Qualifier descriptor not supported"));
  1476         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETDEVICEQUALIFIERDESCRIPTORTC_DUP1,
       
  1477                 "  Warning: Device_Qualifier descriptor not supported" );
  1352 		return KErrNotSupported;
  1478 		return KErrNotSupported;
  1353 		}
  1479 		}
  1354 	TBuf8<KUsbDescSize_DeviceQualifier> device;
  1480 	TBuf8<KUsbDescSize_DeviceQualifier> device;
  1355 	const TInt r = Kern::ThreadDesRead(aThread, &aBuffer, device, 0);
  1481 	const TInt r = Kern::ThreadDesRead(aThread, &aBuffer, device, 0);
  1356 	if (r != KErrNone)
  1482 	if (r != KErrNone)
  1366 	}
  1492 	}
  1367 
  1493 
  1368 
  1494 
  1369 TInt TUsbcDescriptorPool::GetOtherSpeedConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const
  1495 TInt TUsbcDescriptorPool::GetOtherSpeedConfigurationDescriptorTC(DThread* aThread, TDes8& aBuffer) const
  1370 	{
  1496 	{
  1371 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetOtherSpeedConfigurationDescriptorTC()"));
  1497 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETOTHERSPEEDCONFIGURATIONDESCRIPTORTC, 
       
  1498 	        "TUsbcDescriptorPool::GetOtherSpeedConfigurationDescriptorTC()" );
  1372 	if (iDescriptors[KDescPosition_OtherSpeedConfig] == NULL)
  1499 	if (iDescriptors[KDescPosition_OtherSpeedConfig] == NULL)
  1373 		{
  1500 		{
  1374 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Other_Speed_Configuration descriptor not supported"));
  1501 	    OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETOTHERSPEEDCONFIGURATIONDESCRIPTORTC_DUP1, 
       
  1502 	            "  Warning: Other_Speed_Configuration descriptor not supported" );
  1375 		return KErrNotSupported;
  1503 		return KErrNotSupported;
  1376 		}
  1504 		}
  1377 	return Kern::ThreadDesWrite(aThread, &aBuffer,
  1505 	return Kern::ThreadDesWrite(aThread, &aBuffer,
  1378 								iDescriptors[KDescPosition_OtherSpeedConfig]->DescriptorData(), 0);
  1506 								iDescriptors[KDescPosition_OtherSpeedConfig]->DescriptorData(), 0);
  1379 	}
  1507 	}
  1380 
  1508 
  1381 
  1509 
  1382 TInt TUsbcDescriptorPool::SetOtherSpeedConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer)
  1510 TInt TUsbcDescriptorPool::SetOtherSpeedConfigurationDescriptorTC(DThread* aThread, const TDes8& aBuffer)
  1383 	{
  1511 	{
  1384 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::SetOtherSpeedConfigurationDescriptorTC()"));
  1512 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_SETOTHERSPEEDCONFIGURATIONDESCRIPTORTC, 
       
  1513 	        "TUsbcDescriptorPool::SetOtherSpeedConfigurationDescriptorTC()" );
  1385 	if (iDescriptors[KDescPosition_OtherSpeedConfig] == NULL)
  1514 	if (iDescriptors[KDescPosition_OtherSpeedConfig] == NULL)
  1386 		{
  1515 		{
  1387 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Other_Speed_Configuration descriptor not supported"));
  1516 	    OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETOTHERSPEEDCONFIGURATIONDESCRIPTORTC_DUP1, 
       
  1517 	            "  Warning: Other_Speed_Configuration descriptor not supported" );
  1388 		return KErrNotSupported;
  1518 		return KErrNotSupported;
  1389 		}
  1519 		}
  1390 	TBuf8<KUsbDescSize_OtherSpeedConfig> config;
  1520 	TBuf8<KUsbDescSize_OtherSpeedConfig> config;
  1391 	const TInt r = Kern::ThreadDesRead(aThread, &aBuffer, config, 0);
  1521 	const TInt r = Kern::ThreadDesRead(aThread, &aBuffer, config, 0);
  1392 	if (r != KErrNone)
  1522 	if (r != KErrNone)
  1404 	{
  1534 	{
  1405 	// first find the interface
  1535 	// first find the interface
  1406 	TInt i = FindIfcDescriptor(aInterface, aSetting);
  1536 	TInt i = FindIfcDescriptor(aInterface, aSetting);
  1407 	if (i < 0)
  1537 	if (i < 0)
  1408 		{
  1538 		{
  1409 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such interface"));
  1539 		OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETCSINTERFACEDESCRIPTORTC,
       
  1540 		        "  Error: no such interface" );
  1410 		return KErrNotFound;
  1541 		return KErrNotFound;
  1411 		}
  1542 		}
  1412 	TInt r = KErrNotFound;
  1543 	TInt r = KErrNotFound;
  1413 	TInt offset = 0;
  1544 	TInt offset = 0;
  1414 	const TInt count = iDescriptors.Count();
  1545 	const TInt count = iDescriptors.Count();
  1429 	{
  1560 	{
  1430 	// First find the interface
  1561 	// First find the interface
  1431 	TInt i = FindIfcDescriptor(aInterface, aSetting);
  1562 	TInt i = FindIfcDescriptor(aInterface, aSetting);
  1432 	if (i < 0)
  1563 	if (i < 0)
  1433 		{
  1564 		{
  1434 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such interface"));
  1565 		OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETCSINTERFACEDESCRIPTORTC, 
       
  1566 		        "  Error: no such interface" );
  1435 		return KErrNotFound;
  1567 		return KErrNotFound;
  1436 		}
  1568 		}
  1437 	// Find a position where to insert the new class specific interface descriptor(s)
  1569 	// Find a position where to insert the new class specific interface descriptor(s)
  1438 	const TInt count = iDescriptors.Count();
  1570 	const TInt count = iDescriptors.Count();
  1439 	while (++i < count && iDescriptors[i]->Type() == KUsbDescType_CS_Interface)
  1571 	while (++i < count && iDescriptors[i]->Type() == KUsbDescType_CS_Interface)
  1442 	TUsbcClassSpecificDescriptor* desc = TUsbcClassSpecificDescriptor::New(KUsbDescType_CS_Interface, aSize);
  1574 	TUsbcClassSpecificDescriptor* desc = TUsbcClassSpecificDescriptor::New(KUsbDescType_CS_Interface, aSize);
  1443 	if (!desc)
  1575 	if (!desc)
  1444 		{
  1576 		{
  1445 		return KErrNoMemory;
  1577 		return KErrNoMemory;
  1446 		}
  1578 		}
  1447 	__KTRACE_OPT(KUSB, Kern::Printf("  inserting descriptor at position %d", i));
  1579     OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_SETCSINTERFACEDESCRIPTORTC_DUP1,
       
  1580             "  inserting descriptor at position %d", i );
  1448 	iDescriptors.Insert(desc, i);
  1581 	iDescriptors.Insert(desc, i);
  1449 
  1582 
  1450 	// Update the config descriptor's wTotalLength field
  1583 	// Update the config descriptor's wTotalLength field
  1451 	UpdateConfigDescriptorLength(aSize);
  1584 	UpdateConfigDescriptorLength(aSize);
  1452 
  1585 
  1459 	{
  1592 	{
  1460 	// first find the interface
  1593 	// first find the interface
  1461 	TInt i = FindIfcDescriptor(aInterface, aSetting);
  1594 	TInt i = FindIfcDescriptor(aInterface, aSetting);
  1462 	if (i < 0)
  1595 	if (i < 0)
  1463 		{
  1596 		{
  1464 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such interface"));
  1597         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETCSINTERFACEDESCRIPTORSIZE, 
       
  1598                 "  Error: no such interface" );
  1465 		return KErrNotFound;
  1599 		return KErrNotFound;
  1466 		}
  1600 		}
  1467 	TInt r = KErrNotFound;
  1601 	TInt r = KErrNotFound;
  1468 	TInt size = 0;
  1602 	TInt size = 0;
  1469 	const TInt count = iDescriptors.Count();
  1603 	const TInt count = iDescriptors.Count();
  1483 	{
  1617 	{
  1484 	// first find the endpoint
  1618 	// first find the endpoint
  1485 	TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1619 	TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1486 	if (i < 0)
  1620 	if (i < 0)
  1487 		{
  1621 		{
  1488 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such endpoint"));
  1622 		OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETCSENDPOINTDESCRIPTORTC,
       
  1623 		        "  Error: no such endpoint" );
  1489 		return KErrNotFound;
  1624 		return KErrNotFound;
  1490 		}
  1625 		}
  1491 	TInt r = KErrNotFound;
  1626 	TInt r = KErrNotFound;
  1492 	TInt offset = 0;
  1627 	TInt offset = 0;
  1493 	const TInt count = iDescriptors.Count();
  1628 	const TInt count = iDescriptors.Count();
  1508 	{
  1643 	{
  1509 	// first find the endpoint
  1644 	// first find the endpoint
  1510 	TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1645 	TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1511 	if (i < 0)
  1646 	if (i < 0)
  1512 		{
  1647 		{
  1513 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such endpoint"));
  1648 		OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETCSENDPOINTDESCRIPTORTC,
       
  1649 		        "  Error: no such endpoint" );
  1514 		return KErrNotFound;
  1650 		return KErrNotFound;
  1515 		}
  1651 		}
  1516 	// find a position where to insert the new class specific endpoint descriptor(s)
  1652 	// find a position where to insert the new class specific endpoint descriptor(s)
  1517 	const TInt count = iDescriptors.Count();
  1653 	const TInt count = iDescriptors.Count();
  1518 	while (++i < count && iDescriptors[i]->Type() == KUsbDescType_CS_Endpoint)
  1654 	while (++i < count && iDescriptors[i]->Type() == KUsbDescType_CS_Endpoint)
  1536 	{
  1672 	{
  1537 	// first find the endpoint
  1673 	// first find the endpoint
  1538 	TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1674 	TInt i = FindEpDescriptor(aInterface, aSetting, aEndpointAddress);
  1539 	if (i < 0)
  1675 	if (i < 0)
  1540 		{
  1676 		{
  1541 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such endpoint"));
  1677 		OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETCSENDPOINTDESCRIPTORSIZE, 
       
  1678 		        "  Error: no such endpoint" );
  1542 		return KErrNotFound;
  1679 		return KErrNotFound;
  1543 		}
  1680 		}
  1544 	TInt r = KErrNotFound;
  1681 	TInt r = KErrNotFound;
  1545 	TInt size = 0;
  1682 	TInt size = 0;
  1546 	const TInt count = iDescriptors.Count();
  1683 	const TInt count = iDescriptors.Count();
  1634 	{
  1771 	{
  1635 	const TInt str_idx = iDescriptors[KDescPosition_Config]->Byte(KUsbDescStringIndex_Config);
  1772 	const TInt str_idx = iDescriptors[KDescPosition_Config]->Byte(KUsbDescStringIndex_Config);
  1636 	if (str_idx)
  1773 	if (str_idx)
  1637 		{
  1774 		{
  1638 		__ASSERT_ALWAYS((str_idx == KStringPosition_Config), Kern::Fault(KUsbPanicCat, __LINE__));
  1775 		__ASSERT_ALWAYS((str_idx == KStringPosition_Config), Kern::Fault(KUsbPanicCat, __LINE__));
  1639 		__KTRACE_OPT(KUSB, Kern::Printf("  String @ pos %d (conf $): \"%S\"",
  1776 		OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONSTRINGDESCRIPTORTC, 
  1640 										str_idx, &iStrings[str_idx]->StringData()));
  1777 		        "  String @ pos %d (conf $): \"%s\"", str_idx, iStrings[str_idx]->StringData() );
  1641 		return Kern::ThreadDesWrite(aThread, &aString,
  1778 		return Kern::ThreadDesWrite(aThread, &aString,
  1642 									iStrings[str_idx]->StringData(), 0);
  1779 									iStrings[str_idx]->StringData(), 0);
  1643 		}
  1780 		}
  1644 	else
  1781 	else
  1645 		{
  1782 		{
  1646 		__KTRACE_OPT(KUSB, Kern::Printf("  No config string descriptor @ pos %d", str_idx));
  1783         OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONSTRINGDESCRIPTORTC_DUP1,
       
  1784                 "  No config string descriptor @ pos %d", str_idx );
       
  1785 
  1647 		return KErrNotFound;
  1786 		return KErrNotFound;
  1648 		}
  1787 		}
  1649 	}
  1788 	}
  1650 
  1789 
  1651 
  1790 
  1653 	{
  1792 	{
  1654 	// we don't know the length of the string, so we have to allocate memory dynamically
  1793 	// we don't know the length of the string, so we have to allocate memory dynamically
  1655 	TUint strlen = Kern::ThreadGetDesLength(aThread, &aString);
  1794 	TUint strlen = Kern::ThreadGetDesLength(aThread, &aString);
  1656 	if (strlen > KUsbStringDescStringMaxSize)
  1795 	if (strlen > KUsbStringDescStringMaxSize)
  1657 		{
  1796 		{
  1658 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: config $ descriptor too long - will be truncated"));
  1797 		OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETCONFIGURATIONSTRINGDESCRIPTORTC,
       
  1798 		        "  Warning: config $ descriptor too long - will be truncated" );
  1659 		strlen = KUsbStringDescStringMaxSize;
  1799 		strlen = KUsbStringDescStringMaxSize;
  1660 		}
  1800 		}
  1661 	HBuf8* const strbuf = HBuf8::New(strlen);
  1801 	HBuf8* const strbuf = HBuf8::New(strlen);
  1662 	if (!strbuf)
  1802 	if (!strbuf)
  1663 		{
  1803 		{
  1664 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Memory allocation for config $ desc string failed (1)"));
  1804         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETCONFIGURATIONSTRINGDESCRIPTORTC_DUP1,
       
  1805                 "  Error: Memory allocation for config $ desc string failed (1)" );
  1665 		return KErrNoMemory;
  1806 		return KErrNoMemory;
  1666 		}
  1807 		}
  1667 	strbuf->SetMax();
  1808 	strbuf->SetMax();
  1668 	// the aString points to data that lives in user memory, so we have to copy it:
  1809 	// the aString points to data that lives in user memory, so we have to copy it:
  1669 	const TInt r = Kern::ThreadDesRead(aThread, &aString, *strbuf, 0);
  1810 	const TInt r = Kern::ThreadDesRead(aThread, &aString, *strbuf, 0);
  1670 	if (r != KErrNone)
  1811 	if (r != KErrNone)
  1671 		{
  1812 		{
  1672 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Thread read error"));
  1813         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETCONFIGURATIONSTRINGDESCRIPTORTC_DUP2,
       
  1814                 "  Error: Thread read error" );
  1673 		delete strbuf;
  1815 		delete strbuf;
  1674 		return r;
  1816 		return r;
  1675 		}
  1817 		}
  1676 	TUsbcStringDescriptor* sd = TUsbcStringDescriptor::New(*strbuf);
  1818 	TUsbcStringDescriptor* sd = TUsbcStringDescriptor::New(*strbuf);
  1677 	if (!sd)
  1819 	if (!sd)
  1678 		{
  1820 		{
  1679 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Memory allocation for config $ desc failed (2)"));
  1821         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETCONFIGURATIONSTRINGDESCRIPTORTC_DUP3,
       
  1822                 "  Error: Memory allocation for config $ desc failed (2)" );
  1680 		delete strbuf;
  1823 		delete strbuf;
  1681 		return KErrNoMemory;
  1824 		return KErrNoMemory;
  1682 		}
  1825 		}
  1683 	// Delete old string, put in new one
  1826 	// Delete old string, put in new one
  1684 	ExchangeStringDescriptor(KStringPosition_Config, sd);
  1827 	ExchangeStringDescriptor(KStringPosition_Config, sd);
  1695 
  1838 
  1696 TInt TUsbcDescriptorPool::RemoveConfigurationStringDescriptor()
  1839 TInt TUsbcDescriptorPool::RemoveConfigurationStringDescriptor()
  1697 	{
  1840 	{
  1698 	if (iDescriptors[KDescPosition_Config]->Byte(KUsbDescStringIndex_Config) == 0)
  1841 	if (iDescriptors[KDescPosition_Config]->Byte(KUsbDescStringIndex_Config) == 0)
  1699 		{
  1842 		{
  1700 		__KTRACE_OPT(KUSB, Kern::Printf("  RemoveConfigurationStringDescriptor: no $ desc @ index %d",
  1843 		OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_REMOVECONFIGURATIONSTRINGDESCRIPTOR,
  1701 										KUsbDescStringIndex_Config));
  1844 		        "  RemoveConfigurationStringDescriptor: no $ desc @ index %d", KUsbDescStringIndex_Config );
  1702 		return KErrNotFound;
  1845 		return KErrNotFound;
  1703 		}
  1846 		}
  1704 	// Delete old string, put in NULL pointer
  1847 	// Delete old string, put in NULL pointer
  1705 	ExchangeStringDescriptor(KStringPosition_Config, NULL);
  1848 	ExchangeStringDescriptor(KStringPosition_Config, NULL);
  1706 	// Update Config descriptor string index field
  1849 	// Update Config descriptor string index field
  1712 	}
  1855 	}
  1713 
  1856 
  1714 
  1857 
  1715 TInt TUsbcDescriptorPool::GetStringDescriptorTC(DThread* aThread, TInt aIndex, TDes8& aString) const
  1858 TInt TUsbcDescriptorPool::GetStringDescriptorTC(DThread* aThread, TInt aIndex, TDes8& aString) const
  1716 	{
  1859 	{
  1717 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetStringDescriptorTC()"));
  1860 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETSTRINGDESCRIPTORTC,
       
  1861 	        "TUsbcDescriptorPool::GetStringDescriptorTC()" );
  1718 	if (!StringDescriptorExists(aIndex))
  1862 	if (!StringDescriptorExists(aIndex))
  1719 		{
  1863 		{
  1720 		return KErrNotFound;
  1864 		return KErrNotFound;
  1721 		}
  1865 		}
  1722 	__KTRACE_OPT(KUSB, Kern::Printf("  String @ pos %d: \"%S\"",
  1866 	OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETSTRINGDESCRIPTORTC_DUP1,
  1723 									aIndex, &iStrings[aIndex]->StringData()));
  1867 	        "  String @ pos %d: \"%s\"", aIndex, iStrings[aIndex]->StringData() );
  1724 	return Kern::ThreadDesWrite(aThread, &aString, iStrings[aIndex]->StringData(), 0);
  1868 	return Kern::ThreadDesWrite(aThread, &aString, iStrings[aIndex]->StringData(), 0);
  1725 	}
  1869 	}
  1726 
  1870 
  1727 
  1871 
  1728 TInt TUsbcDescriptorPool::SetStringDescriptorTC(DThread* aThread, TInt aIndex, const TDes8& aString)
  1872 TInt TUsbcDescriptorPool::SetStringDescriptorTC(DThread* aThread, TInt aIndex, const TDes8& aString)
  1729 	{
  1873 	{
  1730 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::SetStringDescriptorTC()"));
  1874 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_SETSTRINGDESCRIPTORTC,
       
  1875 	        "TUsbcDescriptorPool::SetStringDescriptorTC()" );
  1731 	// we don't know the length of the string, so we have to allocate memory dynamically
  1876 	// we don't know the length of the string, so we have to allocate memory dynamically
  1732 	TUint strlen = Kern::ThreadGetDesLength(aThread, &aString);
  1877 	TUint strlen = Kern::ThreadGetDesLength(aThread, &aString);
  1733 	if (strlen > KUsbStringDescStringMaxSize)
  1878 	if (strlen > KUsbStringDescStringMaxSize)
  1734 		{
  1879 		{
  1735 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: $ descriptor too long - will be truncated"));
  1880 	   OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETSTRINGDESCRIPTORTC_DUP1,
       
  1881 	           "  Warning: $ descriptor too long - will be truncated" );
  1736 		strlen = KUsbStringDescStringMaxSize;
  1882 		strlen = KUsbStringDescStringMaxSize;
  1737 		}
  1883 		}
  1738 	HBuf8* strbuf = HBuf8::New(strlen);
  1884 	HBuf8* strbuf = HBuf8::New(strlen);
  1739 	if (!strbuf)
  1885 	if (!strbuf)
  1740 		{
  1886 		{
  1741 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Mem alloc for $ desc string failed (1)"));
  1887         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETSTRINGDESCRIPTORTC_DUP2,
       
  1888                 "  Error: Mem alloc for $ desc string failed (1)" );
  1742 		return KErrNoMemory;
  1889 		return KErrNoMemory;
  1743 		}
  1890 		}
  1744 	strbuf->SetMax();
  1891 	strbuf->SetMax();
  1745 	// the aString points to data that lives in user memory, so we have to copy it over:
  1892 	// the aString points to data that lives in user memory, so we have to copy it over:
  1746 	const TInt r = Kern::ThreadDesRead(aThread, &aString, *strbuf, 0);
  1893 	const TInt r = Kern::ThreadDesRead(aThread, &aString, *strbuf, 0);
  1747 	if (r != KErrNone)
  1894 	if (r != KErrNone)
  1748 		{
  1895 		{
  1749 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Thread read error"));
  1896         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETSTRINGDESCRIPTORTC_DUP3,
       
  1897                 "  Error: Thread read error" );
  1750 		delete strbuf;
  1898 		delete strbuf;
  1751 		return r;
  1899 		return r;
  1752 		}
  1900 		}
  1753 	TUsbcStringDescriptor* const sd = TUsbcStringDescriptor::New(*strbuf);
  1901 	TUsbcStringDescriptor* const sd = TUsbcStringDescriptor::New(*strbuf);
  1754 	if (!sd)
  1902 	if (!sd)
  1755 		{
  1903 		{
  1756 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Mem alloc for $ desc failed (2)"));
  1904         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETSTRINGDESCRIPTORTC_DUP4,
       
  1905                 "  Error: Mem alloc for $ desc failed (2)" );
  1757 		delete strbuf;
  1906 		delete strbuf;
  1758 		return KErrNoMemory;
  1907 		return KErrNoMemory;
  1759 		}
  1908 		}
  1760 	if (aIndex < iStrings.Count())
  1909 	if (aIndex < iStrings.Count())
  1761 		{
  1910 		{
  1774 	}
  1923 	}
  1775 
  1924 
  1776 
  1925 
  1777 TInt TUsbcDescriptorPool::RemoveStringDescriptor(TInt aIndex)
  1926 TInt TUsbcDescriptorPool::RemoveStringDescriptor(TInt aIndex)
  1778 	{
  1927 	{
  1779 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::RemoveStringDescriptor()"));
  1928 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_REMOVESTRINGDESCRIPTOR, 
       
  1929 	        "TUsbcDescriptorPool::RemoveStringDescriptor()" );
  1780 	if (!StringDescriptorExists(aIndex))
  1930 	if (!StringDescriptorExists(aIndex))
  1781 		{
  1931 		{
  1782 		return KErrNotFound;
  1932 		return KErrNotFound;
  1783 		}
  1933 		}
  1784 	__KTRACE_OPT(KUSB, Kern::Printf("  Removing string @ pos %d: \"%S\"",
  1934    OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_REMOVESTRINGDESCRIPTOR_DUP1, 
  1785 									aIndex, &iStrings[aIndex]->StringData()));
  1935            "  Removing string @ pos %d: \"%s\"", aIndex, iStrings[aIndex]->StringData() );
  1786 	ExchangeStringDescriptor(aIndex, NULL);
  1936 	ExchangeStringDescriptor(aIndex, NULL);
  1787 
  1937 
  1788 	// Make sure there's no $ after aIndex.
  1938 	// Make sure there's no $ after aIndex.
  1789 	const TInt n = iStrings.Count();
  1939 	const TInt n = iStrings.Count();
  1790 	for (TInt i = aIndex; i < n; i++)
  1940 	for (TInt i = aIndex; i < n; i++)
  1791 		{
  1941 		{
  1792 		if (iStrings[i] != NULL)
  1942 		if (iStrings[i] != NULL)
  1793 			{
  1943 			{
  1794 			__KTRACE_OPT(KUSB, Kern::Printf("  Found $ @ idx %d - not compressing", i));
  1944             OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_REMOVESTRINGDESCRIPTOR_DUP2, 
       
  1945                     "  Found $ @ idx %d - not compressing", i );
  1795 			return KErrNone;
  1946 			return KErrNone;
  1796 			}
  1947 			}
  1797 		}
  1948 		}
  1798 
  1949 
  1799 	__KTRACE_OPT(KUSB, Kern::Printf("  No $ found after idx %d - compressing array", aIndex));
  1950     OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_REMOVESTRINGDESCRIPTOR_DUP3,
       
  1951             "  No $ found after idx %d - compressing array", aIndex );
  1800 	// Move aIndex back just before the first !NULL element.
  1952 	// Move aIndex back just before the first !NULL element.
  1801 	while (iStrings[--aIndex] == NULL)
  1953 	while (iStrings[--aIndex] == NULL)
  1802 		;
  1954 		;
  1803 	// Let aIndex point to first NULL.
  1955 	// Let aIndex point to first NULL.
  1804 	aIndex++;
  1956 	aIndex++;
  1805 	__KTRACE_OPT(KUSB, Kern::Printf("  Starting at index %d", aIndex));
  1957     OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_REMOVESTRINGDESCRIPTOR_DUP4,
       
  1958             "  Starting at index %d", aIndex );
  1806 	// Now remove NULL pointers until (Count() == aIndex).
  1959 	// Now remove NULL pointers until (Count() == aIndex).
  1807 	__KTRACE_OPT(KUSB, Kern::Printf("  iStrings.Count() before: %d", iStrings.Count()));
  1960     OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_REMOVESTRINGDESCRIPTOR_DUP5,
       
  1961             "  iStrings.Count() before: %d", iStrings.Count() );
  1808 	do
  1962 	do
  1809 		{
  1963 		{
  1810 		iStrings.Remove(aIndex);
  1964 		iStrings.Remove(aIndex);
  1811 		__KTRACE_OPT(KUSB, Kern::Printf("  Removing $"));
  1965 	    OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_REMOVESTRINGDESCRIPTOR_DUP6,
       
  1966 	            "  Removing $" );
  1812 		}
  1967 		}
  1813 	while (iStrings.Count() > aIndex);
  1968 	while (iStrings.Count() > aIndex);
  1814 	__KTRACE_OPT(KUSB, Kern::Printf("  iStrings.Count() after: %d", iStrings.Count()));
  1969     OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_REMOVESTRINGDESCRIPTOR_DUP7,
  1815 
  1970             "  iStrings.Count() after: %d", iStrings.Count() );
  1816 	// Regain some memory.
  1971 	// Regain some memory.
  1817 	iStrings.Compress();
  1972 	iStrings.Compress();
  1818 
  1973 
  1819 	return KErrNone;
  1974 	return KErrNone;
  1820 	}
  1975 	}
  1827 //
  1982 //
  1828 // Insert an Interface descriptor into the descriptor array at the appropriate index.
  1983 // Insert an Interface descriptor into the descriptor array at the appropriate index.
  1829 //
  1984 //
  1830 void TUsbcDescriptorPool::InsertIfcDesc(TUsbcDescriptorBase* aDesc)
  1985 void TUsbcDescriptorPool::InsertIfcDesc(TUsbcDescriptorBase* aDesc)
  1831 	{
  1986 	{
  1832 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::InsertIfcDesc()"));
  1987 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_INSERTIFCDESC, 
       
  1988 	        "TUsbcDescriptorPool::InsertIfcDesc()" );
  1833 
  1989 
  1834 	const TInt count = iDescriptors.Count();
  1990 	const TInt count = iDescriptors.Count();
  1835 	TBool ifc_exists = EFalse;								// set to 'true' if we're adding an alternate
  1991 	TBool ifc_exists = EFalse;								// set to 'true' if we're adding an alternate
  1836 															// setting to an already existing interface
  1992 															// setting to an already existing interface
  1837 	TInt i = KDescPosition_FirstAvailable;
  1993 	TInt i = KDescPosition_FirstAvailable;
  1838 	while (i < count)
  1994 	while (i < count)
  1839 		{
  1995 		{
  1840 		__KTRACE_OPT(KUSB, Kern::Printf("  already descriptors there (%d)...", count));
  1996         OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_INSERTIFCDESC_DUP1, 
       
  1997                 "  already descriptors there (%d)...", count );
  1841 		if (iDescriptors[i]->Type() == KUsbDescType_Interface)
  1998 		if (iDescriptors[i]->Type() == KUsbDescType_Interface)
  1842 			{
  1999 			{
  1843 			if (iDescriptors[i]->Byte(2) > aDesc->Byte(2))
  2000 			if (iDescriptors[i]->Byte(2) > aDesc->Byte(2))
  1844 				{
  2001 				{
  1845 				// our interface number is less than the one's just found => insert before it (= here)
  2002 				// our interface number is less than the one's just found => insert before it (= here)
  1854 					// our setting number is less than the one's found => insert before (= here)
  2011 					// our setting number is less than the one's found => insert before (= here)
  1855 					break;
  2012 					break;
  1856 					}
  2013 					}
  1857 				else if (iDescriptors[i]->Byte(3) == aDesc->Byte(3))
  2014 				else if (iDescriptors[i]->Byte(3) == aDesc->Byte(3))
  1858 					{
  2015 					{
  1859 					__KTRACE_OPT(KPANIC, Kern::Printf("  Error: first delete old desc "
  2016                     OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_INSERTIFCDESC_DUP2, 
  1860 													  "(TUsbcDescriptorPool::InsertIfcDesc)"));
  2017                             "  Error: first delete old desc (TUsbcDescriptorPool::InsertIfcDesc)" );
  1861 					return;
  2018 					return;
  1862 					}
  2019 					}
  1863 				}
  2020 				}
  1864 			}
  2021 			}
  1865 		++i;
  2022 		++i;
  1866 		}
  2023 		}
  1867 	// In any case: put the new descriptor at position i.
  2024 	// In any case: put the new descriptor at position i.
  1868 	__KTRACE_OPT(KUSB, Kern::Printf("  inserting descriptor at position %d", i));
  2025     OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_INSERTIFCDESC_DUP3,
       
  2026             "  inserting descriptor at position %d", i );
  1869 	iDescriptors.Insert(aDesc, i);
  2027 	iDescriptors.Insert(aDesc, i);
  1870 
  2028 
  1871 	// Update the config descriptor's wTotalLength field.
  2029 	// Update the config descriptor's wTotalLength field.
  1872 	UpdateConfigDescriptorLength(KUsbDescSize_Interface);
  2030 	UpdateConfigDescriptorLength(KUsbDescSize_Interface);
  1873 
  2031 
  1884 //
  2042 //
  1885 // Insert an Endpoint descriptor into the descriptor array at the appropriate index.
  2043 // Insert an Endpoint descriptor into the descriptor array at the appropriate index.
  1886 //
  2044 //
  1887 void TUsbcDescriptorPool::InsertEpDesc(TUsbcDescriptorBase* aDesc)
  2045 void TUsbcDescriptorPool::InsertEpDesc(TUsbcDescriptorBase* aDesc)
  1888 	{
  2046 	{
  1889 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::InsertEpDesc()"));
  2047 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_INSERTEPDESC, 
       
  2048 	        "TUsbcDescriptorPool::InsertEpDesc()" );
  1890 	if (iIfcIdx == 0)
  2049 	if (iIfcIdx == 0)
  1891 		{
  2050 		{
  1892 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: only after interface "
  2051         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_INSERTEPDESC_DUP1, 
  1893 										  "(TUsbcDescriptorPool::InsertEpDesc)"));
  2052                 "  Error: only after interface (TUsbcDescriptorPool::InsertEpDesc)" );
  1894 		return;
  2053 		return;
  1895 		}
  2054 		}
  1896 	const TInt count = iDescriptors.Count();
  2055 	const TInt count = iDescriptors.Count();
  1897 	TInt i = iIfcIdx + 1;
  2056 	TInt i = iIfcIdx + 1;
  1898 	while (i < count)
  2057 	while (i < count)
  1911 //
  2070 //
  1912 // Find the index of the Interface descriptor for a given interface setting.
  2071 // Find the index of the Interface descriptor for a given interface setting.
  1913 //
  2072 //
  1914 TInt TUsbcDescriptorPool::FindIfcDescriptor(TInt aIfcNumber, TInt aIfcSetting) const
  2073 TInt TUsbcDescriptorPool::FindIfcDescriptor(TInt aIfcNumber, TInt aIfcSetting) const
  1915 	{
  2074 	{
  1916 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::FindIfcDescriptor(%d, %d)",
  2075 	OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_FINDIFCDESCRIPTOR,
  1917 									aIfcNumber, aIfcSetting));
  2076 	        "TUsbcDescriptorPool::FindIfcDescriptor(%d, %d)", aIfcNumber, aIfcSetting );
  1918 	const TInt count = iDescriptors.Count();
  2077 	const TInt count = iDescriptors.Count();
  1919 	for (TInt i = KDescPosition_FirstAvailable; i < count; i++)
  2078 	for (TInt i = KDescPosition_FirstAvailable; i < count; i++)
  1920 		{
  2079 		{
  1921 		if ((iDescriptors[i]->Type() == KUsbDescType_Interface) &&
  2080 		if ((iDescriptors[i]->Type() == KUsbDescType_Interface) &&
  1922 			(iDescriptors[i]->Byte(2) == aIfcNumber) &&
  2081 			(iDescriptors[i]->Byte(2) == aIfcNumber) &&
  1923 			(iDescriptors[i]->Byte(3) == aIfcSetting))
  2082 			(iDescriptors[i]->Byte(3) == aIfcSetting))
  1924 			{
  2083 			{
  1925 			return i;
  2084 			return i;
  1926 			}
  2085 			}
  1927 		}
  2086 		}
  1928 	__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such interface"));
  2087 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDIFCDESCRIPTOR_DUP1,
       
  2088 	        "  Error: no such interface" );
  1929 	return -1;
  2089 	return -1;
  1930 	}
  2090 	}
  1931 
  2091 
  1932 
  2092 
  1933 //
  2093 //
  1934 // Find the index of the Endpoint descriptor for a given endpoint on a given interface setting.
  2094 // Find the index of the Endpoint descriptor for a given endpoint on a given interface setting.
  1935 //
  2095 //
  1936 TInt TUsbcDescriptorPool::FindEpDescriptor(TInt aIfcNumber, TInt aIfcSetting, TUint8 aEpAddress) const
  2096 TInt TUsbcDescriptorPool::FindEpDescriptor(TInt aIfcNumber, TInt aIfcSetting, TUint8 aEpAddress) const
  1937 	{
  2097 	{
  1938 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::FindEpDescriptor(%d, %d, 0x%02x)",
  2098 	OstTraceDefExt3( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_FINDEPDESCRIPTOR,
  1939 									aIfcNumber, aIfcSetting, aEpAddress));
  2099 	        "TUsbcDescriptorPool::FindEpDescriptor(%d, %d, 0x%02x)", aIfcNumber, aIfcSetting, aEpAddress );
  1940 	// first find the interface
  2100 	// first find the interface
  1941 	const TInt ifc = FindIfcDescriptor(aIfcNumber, aIfcSetting);
  2101 	const TInt ifc = FindIfcDescriptor(aIfcNumber, aIfcSetting);
  1942 	if (ifc < 0)
  2102 	if (ifc < 0)
  1943 		{
  2103 		{
  1944 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such interface"));
  2104         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDEPDESCRIPTOR_DUP1,
       
  2105                 "  Error: no such interface" );
  1945 		return ifc;
  2106 		return ifc;
  1946 		}
  2107 		}
  1947 	const TInt count = iDescriptors.Count();
  2108 	const TInt count = iDescriptors.Count();
  1948 	// then, before the next interface, try to locate the endpoint
  2109 	// then, before the next interface, try to locate the endpoint
  1949 	for (TInt i = ifc + 1; i < count; i++)
  2110 	for (TInt i = ifc + 1; i < count; i++)
  1950 		{
  2111 		{
  1951 		if (iDescriptors[i]->Type() == KUsbDescType_Interface)
  2112 		if (iDescriptors[i]->Type() == KUsbDescType_Interface)
  1952 			{
  2113 			{
  1953 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such endpoint before next interface"));
  2114             OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDEPDESCRIPTOR_DUP2,
       
  2115                     "  Error: no such endpoint before next interface" );
  1954 			return -1;
  2116 			return -1;
  1955 			}
  2117 			}
  1956 		else if ((iDescriptors[i]->Type() == KUsbDescType_Endpoint) &&
  2118 		else if ((iDescriptors[i]->Type() == KUsbDescType_Endpoint) &&
  1957 				 (iDescriptors[i]->Byte(2) == aEpAddress))
  2119 				 (iDescriptors[i]->Byte(2) == aEpAddress))
  1958 			{
  2120 			{
  1959 			// found
  2121 			// found
  1960 			return i;
  2122 			return i;
  1961 			}
  2123 			}
  1962 		}
  2124 		}
  1963 	__KTRACE_OPT(KPANIC, Kern::Printf("  Error: no such endpoint"));
  2125     OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_FINDEPDESCRIPTOR_DUP3,
       
  2126             "  Error: no such endpoint" );
  1964 	return -1;
  2127 	return -1;
  1965 	}
  2128 	}
  1966 
  2129 
  1967 
  2130 
  1968 //
  2131 //
  1969 // Delete n descriptors starting from aIndex and remove their pointers from the array.
  2132 // Delete n descriptors starting from aIndex and remove their pointers from the array.
  1970 //
  2133 //
  1971 void TUsbcDescriptorPool::DeleteDescriptors(TInt aIndex, TInt aCount)
  2134 void TUsbcDescriptorPool::DeleteDescriptors(TInt aIndex, TInt aCount)
  1972 	{
  2135 	{
  1973 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::DeleteDescriptors()"));
  2136 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_DELETEDESCRIPTORS, 
       
  2137 	        "TUsbcDescriptorPool::DeleteDescriptors()" );
  1974 	if (aIndex < KDescPosition_FirstAvailable)
  2138 	if (aIndex < KDescPosition_FirstAvailable)
  1975 		{
  2139 		{
  1976 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: aIndex < KDescPosition_FirstAvailable"));
  2140         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_DELETEDESCRIPTORS_DUP1, 
       
  2141                 "  Error: aIndex < KDescPosition_FirstAvailable" );
  1977 		return;
  2142 		return;
  1978 		}
  2143 		}
  1979 	if (aCount <= 0)
  2144 	if (aCount <= 0)
  1980 		{
  2145 		{
  1981 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: aCount <= 0"));
  2146         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_DELETEDESCRIPTORS_DUP2, 
       
  2147                 "  Error: aCount <= 0" );
  1982 		return;
  2148 		return;
  1983 		}
  2149 		}
  1984 	__KTRACE_OPT(KUSB, Kern::Printf("  Removing descriptors at index %d:", aIndex));
  2150     OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_DELETEDESCRIPTORS_DUP3, 
       
  2151             "  Removing descriptors at index %d:", aIndex );
  1985 	// Try to update wTotalLength field in Config descriptor
  2152 	// Try to update wTotalLength field in Config descriptor
  1986 	while (aCount--)
  2153 	while (aCount--)
  1987 		{
  2154 		{
  1988 		// In this loop we don't decrement aIndex, because after deleting an element
  2155 		// In this loop we don't decrement aIndex, because after deleting an element
  1989 		// aIndex is already indexing the next one.
  2156 		// aIndex is already indexing the next one.
  1990 		TUsbcDescriptorBase* const ptr = iDescriptors[aIndex];
  2157 		TUsbcDescriptorBase* const ptr = iDescriptors[aIndex];
  1991 		switch (ptr->Type())
  2158 		switch (ptr->Type())
  1992 			{
  2159 			{
  1993 		case KUsbDescType_Interface:
  2160 		case KUsbDescType_Interface:
  1994 			__KTRACE_OPT(KUSB, Kern::Printf("  - an interface descriptor"));
  2161 		    OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_DELETEDESCRIPTORS_DUP4,
       
  2162 		            "  - an interface descriptor" );
  1995 			UpdateConfigDescriptorLength(-KUsbDescSize_Interface);
  2163 			UpdateConfigDescriptorLength(-KUsbDescSize_Interface);
  1996 			break;
  2164 			break;
  1997 		case KUsbDescType_Endpoint:
  2165 		case KUsbDescType_Endpoint:
  1998 			__KTRACE_OPT(KUSB, Kern::Printf("  - an endpoint descriptor"));
  2166 			OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_DELETEDESCRIPTORS_DUP5,
       
  2167 			        "  - an endpoint descriptor" );
  1999 			UpdateConfigDescriptorLength(-ptr->Size());
  2168 			UpdateConfigDescriptorLength(-ptr->Size());
  2000 			break;
  2169 			break;
  2001 		case KUsbDescType_CS_Interface:
  2170 		case KUsbDescType_CS_Interface:
  2002 			/* fall through */
  2171 			/* fall through */
  2003 		case KUsbDescType_CS_Endpoint:
  2172 		case KUsbDescType_CS_Endpoint:
  2004 			__KTRACE_OPT(KUSB, Kern::Printf("  - a class specific descriptor"));
  2173 		    OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_DELETEDESCRIPTORS_DUP6,
       
  2174 		            "  - a class specific descriptor" );
  2005 			UpdateConfigDescriptorLength(-ptr->Size());
  2175 			UpdateConfigDescriptorLength(-ptr->Size());
  2006 			break;
  2176 			break;
  2007 		default:
  2177 		default:
  2008 			__KTRACE_OPT(KUSB, Kern::Printf("  - an unknown descriptor"));
  2178 		    OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_DELETEDESCRIPTORS_DUP7,
  2009 			__KTRACE_OPT(KPANIC, Kern::Printf("  Error: unknown descriptor type"));
  2179 		            "  - an unknown descriptor" );
       
  2180 		    OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_DELETEDESCRIPTORS_DUP8,
       
  2181 		            "  Error: unknown descriptor type" );
  2010 			}
  2182 			}
  2011 		iDescriptors.Remove(aIndex);
  2183 		iDescriptors.Remove(aIndex);
  2012 		delete ptr;
  2184 		delete ptr;
  2013 		}
  2185 		}
  2014 	}
  2186 	}
  2017 //
  2189 //
  2018 // Update the wTotalLength field in the Configuration descriptor (aLength can be negative).
  2190 // Update the wTotalLength field in the Configuration descriptor (aLength can be negative).
  2019 //
  2191 //
  2020 void TUsbcDescriptorPool::UpdateConfigDescriptorLength(TInt aLength)
  2192 void TUsbcDescriptorPool::UpdateConfigDescriptorLength(TInt aLength)
  2021 	{
  2193 	{
  2022 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::UpdateConfigDescriptorLength(%d)", aLength));
  2194 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_UPDATECONFIGDESCRIPTORLENGTH,
       
  2195 	        "TUsbcDescriptorPool::UpdateConfigDescriptorLength(%d)", aLength );
  2023 	TUsbcDescriptorBase* const cnf = iDescriptors[KDescPosition_Config];
  2196 	TUsbcDescriptorBase* const cnf = iDescriptors[KDescPosition_Config];
  2024 	__KTRACE_OPT(KUSB, Kern::Printf("  wTotalLength old: %d", cnf->Word(2)));
  2197 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_UPDATECONFIGDESCRIPTORLENGTH_DUP1,
       
  2198 	        "  wTotalLength old: %d", cnf->Word(2) );
  2025 	// Update Config descriptor
  2199 	// Update Config descriptor
  2026 	cnf->SetWord(2, cnf->Word(2) + aLength);
  2200 	cnf->SetWord(2, cnf->Word(2) + aLength);
  2027 	__KTRACE_OPT(KUSB, Kern::Printf("  wTotalLength new: %d", cnf->Word(2)));
  2201 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_UPDATECONFIGDESCRIPTORLENGTH_DUP2,
       
  2202 	        "  wTotalLength new: %d", cnf->Word(2) );
  2028 	// Update Other_Speed_Config descriptor as well, if applicable
  2203 	// Update Other_Speed_Config descriptor as well, if applicable
  2029 	if (iDescriptors[KDescPosition_OtherSpeedConfig])
  2204 	if (iDescriptors[KDescPosition_OtherSpeedConfig])
  2030 		iDescriptors[KDescPosition_OtherSpeedConfig]->SetWord(2, cnf->Word(2));
  2205 		iDescriptors[KDescPosition_OtherSpeedConfig]->SetWord(2, cnf->Word(2));
  2031 	}
  2206 	}
  2032 
  2207 
  2034 //
  2209 //
  2035 // Update the bNumInterfaces field in the Configuration descriptor (aNumber can be negative).
  2210 // Update the bNumInterfaces field in the Configuration descriptor (aNumber can be negative).
  2036 //
  2211 //
  2037 void TUsbcDescriptorPool::UpdateConfigDescriptorNumIfcs(TInt aNumber)
  2212 void TUsbcDescriptorPool::UpdateConfigDescriptorNumIfcs(TInt aNumber)
  2038 	{
  2213 	{
  2039 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::UpdateConfigDescriptorNumIfcs(%d)", aNumber));
  2214 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_UPDATECONFIGDESCRIPTORNUMIFCS,
       
  2215 	        "TUsbcDescriptorPool::UpdateConfigDescriptorNumIfcs(%d)", aNumber );
  2040 	TUsbcDescriptorBase* const cnf = iDescriptors[KDescPosition_Config];
  2216 	TUsbcDescriptorBase* const cnf = iDescriptors[KDescPosition_Config];
  2041 	__KTRACE_OPT(KUSB, Kern::Printf("  bNumInterfaces old: %d", cnf->Byte(4)));
  2217 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_UPDATECONFIGDESCRIPTORNUMIFCS_DUP1,
       
  2218 	        "  bNumInterfaces old: %d", cnf->Byte(4) );
  2042 	const TInt n = cnf->Byte(4) + aNumber;
  2219 	const TInt n = cnf->Byte(4) + aNumber;
  2043 	if (n < 0)
  2220 	if (n < 0)
  2044 		{
  2221 		{
  2045 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: bNumInterfaces + aNumber < 0"));
  2222         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_UPDATECONFIGDESCRIPTORNUMIFCS_DUP2,
       
  2223                 "  Error: bNumInterfaces + aNumber < 0" );
  2046 		return;
  2224 		return;
  2047 		}
  2225 		}
  2048 	// Update Config descriptor
  2226 	// Update Config descriptor
  2049 	cnf->SetByte(4, n);
  2227 	cnf->SetByte(4, n);
  2050 	__KTRACE_OPT(KUSB, Kern::Printf("  bNumInterfaces new: %d", cnf->Byte(4)));
  2228     OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_UPDATECONFIGDESCRIPTORNUMIFCS_DUP3,
       
  2229             "  bNumInterfaces new: %d", cnf->Byte(4) );
  2051 	// Update Other_Speed_Config descriptor as well, if applicable
  2230 	// Update Other_Speed_Config descriptor as well, if applicable
  2052 	if (iDescriptors[KDescPosition_OtherSpeedConfig])
  2231 	if (iDescriptors[KDescPosition_OtherSpeedConfig])
  2053 		iDescriptors[KDescPosition_OtherSpeedConfig]->SetByte(4, n);
  2232 		iDescriptors[KDescPosition_OtherSpeedConfig]->SetByte(4, n);
  2054 	}
  2233 	}
  2055 
  2234 
  2057 //
  2236 //
  2058 // Update the bNumInterfaces field in the Configuration descriptor if necessary.
  2237 // Update the bNumInterfaces field in the Configuration descriptor if necessary.
  2059 //
  2238 //
  2060 void TUsbcDescriptorPool::UpdateIfcNumbers(TInt aNumber)
  2239 void TUsbcDescriptorPool::UpdateIfcNumbers(TInt aNumber)
  2061 	{
  2240 	{
  2062 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::UpdateIfcNumbers(%d)", aNumber));
  2241 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_UPDATEIFCNUMBERS,
       
  2242 	        "TUsbcDescriptorPool::UpdateIfcNumbers(%d)", aNumber );
  2063 	const TInt count = iDescriptors.Count();
  2243 	const TInt count = iDescriptors.Count();
  2064 	for (TInt i = KDescPosition_FirstAvailable; i < count; i++)
  2244 	for (TInt i = KDescPosition_FirstAvailable; i < count; i++)
  2065 		{
  2245 		{
  2066 		if ((iDescriptors[i]->Type() == KUsbDescType_Interface) &&
  2246 		if ((iDescriptors[i]->Type() == KUsbDescType_Interface) &&
  2067 			(iDescriptors[i]->Byte(2) == aNumber))
  2247 			(iDescriptors[i]->Byte(2) == aNumber))
  2079 // Put the current Device or Device_Qualifier descriptor in the Ep0 Tx buffer.
  2259 // Put the current Device or Device_Qualifier descriptor in the Ep0 Tx buffer.
  2080 // Only used for Ep0 standard requests, so target buffer can be hard-wired.
  2260 // Only used for Ep0 standard requests, so target buffer can be hard-wired.
  2081 //
  2261 //
  2082 TInt TUsbcDescriptorPool::GetDeviceDescriptor(TInt aIndex) const
  2262 TInt TUsbcDescriptorPool::GetDeviceDescriptor(TInt aIndex) const
  2083 	{
  2263 	{
  2084 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetDeviceDescriptor()"));
  2264 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETDEVICEDESCRIPTOR, 
  2085 	__ASSERT_DEBUG((aIndex == KDescPosition_Device) || (aIndex == KDescPosition_DeviceQualifier),
  2265 	        "TUsbcDescriptorPool::GetDeviceDescriptor()" );
  2086 				   Kern::Printf("  Error: invalid descriptor index: %d", aIndex));
  2266 #ifdef _DEBUG
       
  2267 	if (!((aIndex == KDescPosition_Device) || (aIndex == KDescPosition_DeviceQualifier)))
       
  2268 	    {
       
  2269         OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETDEVICEDESCRIPTOR_DUP1, 
       
  2270                 "  Error: invalid descriptor index: %d", aIndex );
       
  2271 	    }
       
  2272 #endif
  2087 	if (iDescriptors[aIndex] == NULL)
  2273 	if (iDescriptors[aIndex] == NULL)
  2088 		{
  2274 		{
  2089 		// This doesn't have to be an error - we might get asked here for the Device_Qualifier descriptor
  2275 		// This doesn't have to be an error - we might get asked here for the Device_Qualifier descriptor
  2090 		// on a FS-only device.
  2276 		// on a FS-only device.
  2091 		__KTRACE_OPT(KUSB, Kern::Printf("  Descriptor #%d requested but not available", aIndex));
  2277         OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETDEVICEDESCRIPTOR_DUP2, 
       
  2278                 "  Descriptor #%d requested but not available", aIndex );
  2092 		return 0;
  2279 		return 0;
  2093 		}
  2280 		}
  2094 	return iDescriptors[aIndex]->GetDescriptorData(iEp0_TxBuf, KUsbcBufSz_Ep0Tx);
  2281 	return iDescriptors[aIndex]->GetDescriptorData(iEp0_TxBuf, KUsbcBufSz_Ep0Tx);
  2095 	}
  2282 	}
  2096 	
  2283 	
  2100 // descriptors in the Ep0 Tx buffer.
  2287 // descriptors in the Ep0 Tx buffer.
  2101 // Only used for Ep0 standard requests, so target buffer can be hard-wired.
  2288 // Only used for Ep0 standard requests, so target buffer can be hard-wired.
  2102 //
  2289 //
  2103 TInt TUsbcDescriptorPool::GetConfigurationDescriptor(TInt aIndex) const
  2290 TInt TUsbcDescriptorPool::GetConfigurationDescriptor(TInt aIndex) const
  2104 	{
  2291 	{
  2105 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetConfigDescriptor(%d)", aIndex));
  2292 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONDESCRIPTOR,
  2106 	__ASSERT_DEBUG((aIndex == KDescPosition_Config) || (aIndex == KDescPosition_OtherSpeedConfig),
  2293 	        "TUsbcDescriptorPool::GetConfigDescriptor(%d)", aIndex );
  2107 				   Kern::Printf("  Error: invalid descriptor index: %d", aIndex));
  2294 #ifdef _DEBUG
       
  2295 	if (!((aIndex == KDescPosition_Config) || (aIndex == KDescPosition_OtherSpeedConfig)))
       
  2296 	    {
       
  2297         OstTraceDef1( OST_TRACE_CATEGORY_DEBUG, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONDESCRIPTOR_DUP1,
       
  2298                 "  Error: invalid descriptor index: %d", aIndex );
       
  2299 	    }
       
  2300 #endif
  2108 	if (iDescriptors[aIndex] == NULL)
  2301 	if (iDescriptors[aIndex] == NULL)
  2109 		{
  2302 		{
  2110 		// This is always an error: We should always have a Configuration descriptor and we should never
  2303 		// This is always an error: We should always have a Configuration descriptor and we should never
  2111 		// get asked for the Other_Speed_Configuration descriptor if we don't have one (9.6.2).
  2304 		// get asked for the Other_Speed_Configuration descriptor if we don't have one (9.6.2).
  2112 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: Descriptor %d requested but not available", aIndex));
  2305         OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONDESCRIPTOR_DUP2,
       
  2306                 "  Warning: Descriptor %d requested but not available", aIndex );
  2113 		return 0;
  2307 		return 0;
  2114 		}
  2308 		}
  2115 		
  2309 		
  2116 	const TInt count = iDescriptors.Count();	
  2310 	const TInt count = iDescriptors.Count();	
  2117 	TInt copied = 0;
  2311 	TInt copied = 0;
  2136 		if (pos == count)
  2330 		if (pos == count)
  2137 			{
  2331 			{
  2138 				if (iDescriptors[KDescPosition_Otg] == NULL)
  2332 				if (iDescriptors[KDescPosition_Otg] == NULL)
  2139 					{
  2333 					{
  2140 					// Skip since there is no otg descriptor
  2334 					// Skip since there is no otg descriptor
  2141 					__KTRACE_OPT(KUSB, Kern::Printf("  no otg descriptor"));
  2335                     OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONDESCRIPTOR_DUP3,
       
  2336                             "  no otg descriptor" );
  2142 					continue;				
  2337 					continue;				
  2143 					}
  2338 					}
  2144 				else
  2339 				else
  2145 					{
  2340 					{
  2146 					// add otg to the end of returned descriptors
  2341 					// add otg to the end of returned descriptors
  2166 				{
  2361 				{
  2167 				ptr->UpdateFs();
  2362 				ptr->UpdateFs();
  2168 				}
  2363 				}
  2169 			}
  2364 			}
  2170 
  2365 
  2171 		__KTRACE_OPT(KUSB, Kern::Printf("  desc[%02d]: type = 0x%02x size = %d ",
  2366         OstTraceDefExt3( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONDESCRIPTOR_DUP4,
  2172 										pos, ptr->Type(), ptr->Size()));				
  2367                 "  desc[%02d]: type = 0x%02x size = %d ", pos, ptr->Type(), ptr->Size() );			
  2173 		const TInt size = ptr->GetDescriptorData(buf, KUsbcBufSz_Ep0Tx - copied);
  2368 		const TInt size = ptr->GetDescriptorData(buf, KUsbcBufSz_Ep0Tx - copied);
  2174 		if (size == 0)
  2369 		if (size == 0)
  2175 			{
  2370 			{
  2176 			
  2371 			
  2177 			__KTRACE_OPT(KPANIC,
  2372             OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONDESCRIPTOR_DUP5,
  2178 						 Kern::Printf("  Error: No Tx buffer space to copy this descriptor -> exiting"));
  2373                     "  Error: No Tx buffer space to copy this descriptor -> exiting" );
  2179 			break;
  2374 			break;
  2180 			}
  2375 			}
  2181 		copied += size;
  2376 		copied += size;
  2182 		if (copied >= KUsbcBufSz_Ep0Tx)
  2377 		if (copied >= KUsbcBufSz_Ep0Tx)
  2183 			{
  2378 			{
  2184 			__KTRACE_OPT(KPANIC,
  2379             OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONDESCRIPTOR_DUP6,
  2185 						 Kern::Printf("  Error: No Tx buffer space left -> stopping here"));
  2380                     "  Error: No Tx buffer space left -> stopping here" );
  2186 			break;
  2381 			break;
  2187 			}
  2382 			}
  2188 		buf += size;
  2383 		buf += size;
  2189 		}
  2384 		}
  2190 		
  2385 		
  2191 		
  2386 		
  2192 	__KTRACE_OPT(KUSB, Kern::Printf("  copied %d bytes", copied));
  2387     OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETCONFIGURATIONDESCRIPTOR_DUP7,
       
  2388             "  copied %d bytes", copied );
  2193 	return copied;
  2389 	return copied;
  2194 	}
  2390 	}
  2195 
  2391 
  2196 
  2392 
  2197 //
  2393 //
  2198 // Put the current OTG descriptor in the Ep0 Tx buffer.
  2394 // Put the current OTG descriptor in the Ep0 Tx buffer.
  2199 // Only used for Ep0 standard requests, so target buffer can be hard-wired.
  2395 // Only used for Ep0 standard requests, so target buffer can be hard-wired.
  2200 //
  2396 //
  2201 TInt TUsbcDescriptorPool::GetOtgDescriptor() const
  2397 TInt TUsbcDescriptorPool::GetOtgDescriptor() const
  2202 	{
  2398 	{
  2203 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetOtgDescriptor()"));
  2399 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETOTGDESCRIPTOR,
       
  2400 	        "TUsbcDescriptorPool::GetOtgDescriptor()" );
  2204 	if (iDescriptors[KDescPosition_Otg] == NULL)
  2401 	if (iDescriptors[KDescPosition_Otg] == NULL)
  2205 		{
  2402 		{
  2206 		__KTRACE_OPT(KUSB, Kern::Printf("  OTG Descriptor not set"));
  2403         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETOTGDESCRIPTOR_DUP1,
       
  2404                 "  OTG Descriptor not set" );
  2207 		return 0;
  2405 		return 0;
  2208 		}
  2406 		}
  2209 	return iDescriptors[KDescPosition_Otg]->GetDescriptorData(iEp0_TxBuf, KUsbcBufSz_Ep0Tx);
  2407 	return iDescriptors[KDescPosition_Otg]->GetDescriptorData(iEp0_TxBuf, KUsbcBufSz_Ep0Tx);
  2210 	}
  2408 	}
  2211 
  2409 
  2214 // Put a specific String descriptor in the Ep0 Tx buffer.
  2412 // Put a specific String descriptor in the Ep0 Tx buffer.
  2215 // Only used for Ep0 standard requests, so target buffer can be hard-wired.
  2413 // Only used for Ep0 standard requests, so target buffer can be hard-wired.
  2216 //
  2414 //
  2217 TInt TUsbcDescriptorPool::GetStringDescriptor(TInt aIndex) const
  2415 TInt TUsbcDescriptorPool::GetStringDescriptor(TInt aIndex) const
  2218 	{
  2416 	{
  2219 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetStringDescriptor(%d)", aIndex));
  2417 	OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETSTRINGDESCRIPTOR,
       
  2418 	        "TUsbcDescriptorPool::GetStringDescriptor(%d)", aIndex );
  2220 	// I really would have liked to display the descriptor contents here, but without trailing zero
  2419 	// I really would have liked to display the descriptor contents here, but without trailing zero
  2221 	// we got a problem: how can we tell printf where the string ends? We would have to
  2420 	// we got a problem: how can we tell printf where the string ends? We would have to
  2222 	// dynamically allocate memory (since we don't know the size in advance), copy the descriptor
  2421 	// dynamically allocate memory (since we don't know the size in advance), copy the descriptor
  2223 	// contents there, append a zero, and give this to printf. That's a bit too much effort...
  2422 	// contents there, append a zero, and give this to printf. That's a bit too much effort...
  2224 	if (!StringDescriptorExists(aIndex))
  2423 	if (!StringDescriptorExists(aIndex))
  2234 // (one of Manufacturer, Product, SerialNumber).
  2433 // (one of Manufacturer, Product, SerialNumber).
  2235 //
  2434 //
  2236 TInt TUsbcDescriptorPool::GetDeviceStringDescriptorTC(DThread* aThread, TDes8& aString,
  2435 TInt TUsbcDescriptorPool::GetDeviceStringDescriptorTC(DThread* aThread, TDes8& aString,
  2237 													  TInt aIndex, TInt aPosition) const
  2436 													  TInt aIndex, TInt aPosition) const
  2238 	{
  2437 	{
  2239 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::GetDeviceStringDescriptorTC()"));
  2438 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_GETDEVICESTRINGDESCRIPTORTC, 
       
  2439 	        "TUsbcDescriptorPool::GetDeviceStringDescriptorTC()" );
  2240 	const TInt str_idx = iDescriptors[KDescPosition_Device]->Byte(aIndex);
  2440 	const TInt str_idx = iDescriptors[KDescPosition_Device]->Byte(aIndex);
  2241 	if (str_idx)
  2441 	if (str_idx)
  2242 		{
  2442 		{
  2243 		__ASSERT_ALWAYS((str_idx == aPosition), Kern::Fault(KUsbPanicCat, __LINE__));
  2443 		__ASSERT_ALWAYS((str_idx == aPosition), Kern::Fault(KUsbPanicCat, __LINE__));
  2244 		__KTRACE_OPT(KUSB, Kern::Printf("  String @ pos %d (device $): \"%S\"",
  2444         OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETDEVICESTRINGDESCRIPTORTC_DUP1, 
  2245 										str_idx, &iStrings[str_idx]->StringData()));
  2445                 "  String @ pos %d (device $): \"%s\"", str_idx, iStrings[str_idx]->StringData() );
  2246 		return Kern::ThreadDesWrite(aThread, &aString,
  2446 		return Kern::ThreadDesWrite(aThread, &aString,
  2247 									iStrings[str_idx]->StringData(), 0);
  2447 									iStrings[str_idx]->StringData(), 0);
  2248 		}
  2448 		}
  2249 	else
  2449 	else
  2250 		{
  2450 		{
  2251 		__KTRACE_OPT(KUSB, Kern::Printf("  No string descriptor @ pos %d", aIndex));
  2451         OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_GETDEVICESTRINGDESCRIPTORTC_DUP2, 
       
  2452                 "  No string descriptor @ pos %d", aIndex );
  2252 		return KErrNotFound;
  2453 		return KErrNotFound;
  2253 		}
  2454 		}
  2254 	}
  2455 	}
  2255 
  2456 
  2256 
  2457 
  2259 // (one of Manufacturer, Product, SerialNumber).
  2460 // (one of Manufacturer, Product, SerialNumber).
  2260 //
  2461 //
  2261 TInt TUsbcDescriptorPool::SetDeviceStringDescriptorTC(DThread* aThread, const TDes8& aString,
  2462 TInt TUsbcDescriptorPool::SetDeviceStringDescriptorTC(DThread* aThread, const TDes8& aString,
  2262 													  TInt aIndex, TInt aPosition)
  2463 													  TInt aIndex, TInt aPosition)
  2263 	{
  2464 	{
  2264 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::SetDeviceStringDescriptorTC()"));
  2465 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_SETDEVICESTRINGDESCRIPTORTC,
       
  2466 	        "TUsbcDescriptorPool::SetDeviceStringDescriptorTC()" );
  2265 	// we don't know the length of the string, so we have to allocate memory dynamically
  2467 	// we don't know the length of the string, so we have to allocate memory dynamically
  2266 	TUint strlen = Kern::ThreadGetDesLength(aThread, &aString);
  2468 	TUint strlen = Kern::ThreadGetDesLength(aThread, &aString);
  2267 	if (strlen > KUsbStringDescStringMaxSize)
  2469 	if (strlen > KUsbStringDescStringMaxSize)
  2268 		{
  2470 		{
  2269 		__KTRACE_OPT(KPANIC, Kern::Printf("  Warning: $ descriptor too long - will be truncated"));
  2471         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETDEVICESTRINGDESCRIPTORTC_DUP1,
       
  2472                 "  Warning: $ descriptor too long - will be truncated" );
  2270 		strlen = KUsbStringDescStringMaxSize;
  2473 		strlen = KUsbStringDescStringMaxSize;
  2271 		}
  2474 		}
  2272 	HBuf8* const strbuf = HBuf8::New(strlen);
  2475 	HBuf8* const strbuf = HBuf8::New(strlen);
  2273 	if (!strbuf)
  2476 	if (!strbuf)
  2274 		{
  2477 		{
  2275 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Memory allocation for dev $ desc string failed (1)"));
  2478         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETDEVICESTRINGDESCRIPTORTC_DUP2,
       
  2479                 "  Error: Memory allocation for dev $ desc string failed (1)" );
  2276 		return KErrNoMemory;
  2480 		return KErrNoMemory;
  2277 		}
  2481 		}
  2278 	strbuf->SetMax();
  2482 	strbuf->SetMax();
  2279 	// the aString points to data that lives in user memory, so we have to copy it:
  2483 	// the aString points to data that lives in user memory, so we have to copy it:
  2280 	const TInt r = Kern::ThreadDesRead(aThread, &aString, *strbuf, 0);
  2484 	const TInt r = Kern::ThreadDesRead(aThread, &aString, *strbuf, 0);
  2281 	if (r != KErrNone)
  2485 	if (r != KErrNone)
  2282 		{
  2486 		{
  2283 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Thread read error"));
  2487         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETDEVICESTRINGDESCRIPTORTC_DUP3,
       
  2488                 "  Error: Thread read error" );
  2284 		delete strbuf;
  2489 		delete strbuf;
  2285 		return r;
  2490 		return r;
  2286 		}
  2491 		}
  2287 	TUsbcStringDescriptor* const sd = TUsbcStringDescriptor::New(*strbuf);
  2492 	TUsbcStringDescriptor* const sd = TUsbcStringDescriptor::New(*strbuf);
  2288 	if (!sd)
  2493 	if (!sd)
  2289 		{
  2494 		{
  2290 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Memory allocation for dev $ desc failed (2)"));
  2495         OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_SETDEVICESTRINGDESCRIPTORTC_DUP4,
       
  2496                 "  Error: Memory allocation for dev $ desc failed (2)" );
  2291 		delete strbuf;
  2497 		delete strbuf;
  2292 		return KErrNoMemory;
  2498 		return KErrNoMemory;
  2293 		}
  2499 		}
  2294 	ExchangeStringDescriptor(aPosition, sd);
  2500 	ExchangeStringDescriptor(aPosition, sd);
  2295 	iDescriptors[KDescPosition_Device]->SetByte(aIndex, aPosition);
  2501 	iDescriptors[KDescPosition_Device]->SetByte(aIndex, aPosition);
  2302 // Remove a Device String descriptor from the descriptor arrays
  2508 // Remove a Device String descriptor from the descriptor arrays
  2303 // (one of Manufacturer, Product, SerialNumber).
  2509 // (one of Manufacturer, Product, SerialNumber).
  2304 //
  2510 //
  2305 TInt TUsbcDescriptorPool::RemoveDeviceStringDescriptor(TInt aIndex, TInt aPosition)
  2511 TInt TUsbcDescriptorPool::RemoveDeviceStringDescriptor(TInt aIndex, TInt aPosition)
  2306 	{
  2512 	{
  2307 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::RemoveDeviceStringDescriptor()"));
  2513 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_REMOVEDEVICESTRINGDESCRIPTOR, 
       
  2514 	        "TUsbcDescriptorPool::RemoveDeviceStringDescriptor()" );
  2308 	if (iDescriptors[KDescPosition_Device]->Byte(aIndex) == 0)
  2515 	if (iDescriptors[KDescPosition_Device]->Byte(aIndex) == 0)
  2309 		{
  2516 		{
  2310 		__KTRACE_OPT(KUSB, Kern::Printf("  RemoveDeviceStringDescriptor: no $ desc @ index %d", aIndex));
  2517         OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_REMOVEDEVICESTRINGDESCRIPTOR_DUP1, 
       
  2518                 "  RemoveDeviceStringDescriptor: no $ desc @ index %d", aIndex );
  2311 		return KErrNotFound;
  2519 		return KErrNotFound;
  2312 		}
  2520 		}
  2313 	ExchangeStringDescriptor(aPosition, NULL);
  2521 	ExchangeStringDescriptor(aPosition, NULL);
  2314 	iDescriptors[KDescPosition_Device]->SetByte(aIndex, 0);
  2522 	iDescriptors[KDescPosition_Device]->SetByte(aIndex, 0);
  2315 	return KErrNone;
  2523 	return KErrNone;
  2319 //
  2527 //
  2320 // Puts aDesc at postion aIndex in the string descriptor array, after deleting what was (possibly) there.
  2528 // Puts aDesc at postion aIndex in the string descriptor array, after deleting what was (possibly) there.
  2321 //
  2529 //
  2322 void TUsbcDescriptorPool::ExchangeStringDescriptor(TInt aIndex, const TUsbcStringDescriptor* aDesc)
  2530 void TUsbcDescriptorPool::ExchangeStringDescriptor(TInt aIndex, const TUsbcStringDescriptor* aDesc)
  2323 	{
  2531 	{
  2324 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::ExchangeStringDescriptor()"));
  2532 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_EXCHANGESTRINGDESCRIPTOR,
       
  2533 	        "TUsbcDescriptorPool::ExchangeStringDescriptor()" );
  2325 	TUsbcStringDescriptorBase* const ptr = iStrings[aIndex];
  2534 	TUsbcStringDescriptorBase* const ptr = iStrings[aIndex];
  2326 	__KTRACE_OPT(KUSB, Kern::Printf("  Deleting string descriptor at index %d: 0x%x", aIndex, ptr));
  2535     OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_EXCHANGESTRINGDESCRIPTOR_DUP1,
       
  2536             "  Deleting string descriptor at index %d: 0x%x", aIndex, reinterpret_cast<TUint>(ptr) );
  2327 	iStrings.Remove(aIndex);
  2537 	iStrings.Remove(aIndex);
  2328 	delete ptr;
  2538 	delete ptr;
  2329 	__KTRACE_OPT(KUSB, Kern::Printf("  Inserting string descriptor at index %d: 0x%x", aIndex, aDesc));
  2539     OstTraceDefExt2( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_EXCHANGESTRINGDESCRIPTOR_DUP2,
       
  2540             "  Inserting string descriptor at index %d: 0x%x", aIndex, reinterpret_cast<TUint>(aDesc) );
  2330 	iStrings.Insert(aDesc, aIndex);
  2541 	iStrings.Insert(aDesc, aIndex);
  2331 	}
  2542 	}
  2332 
  2543 
  2333 
  2544 
  2334 //
  2545 //
  2349 //
  2560 //
  2350 // Returns true if aIndex exists and what is at that positition is not a NULL pointer.
  2561 // Returns true if aIndex exists and what is at that positition is not a NULL pointer.
  2351 //
  2562 //
  2352 TBool TUsbcDescriptorPool::StringDescriptorExists(TInt aIndex) const
  2563 TBool TUsbcDescriptorPool::StringDescriptorExists(TInt aIndex) const
  2353 	{
  2564 	{
  2354 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::StringDescriptorExists()"));
  2565 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_STRINGDESCRIPTOREXISTS, 
       
  2566 	        "TUsbcDescriptorPool::StringDescriptorExists" );
  2355 	if (aIndex >= iStrings.Count())
  2567 	if (aIndex >= iStrings.Count())
  2356 		{
  2568 		{
  2357 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: Bad string index: %d", aIndex));
  2569         OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_STRINGDESCRIPTOREXISTS_DUP1, 
       
  2570                 "  Error: Bad string index: %d", aIndex );
  2358 		return EFalse;
  2571 		return EFalse;
  2359 		}
  2572 		}
  2360 	else if (iStrings[aIndex] == NULL)
  2573 	else if (iStrings[aIndex] == NULL)
  2361 		{
  2574 		{
  2362 		__KTRACE_OPT(KPANIC, Kern::Printf("  Error: No $ descriptor @ pos %d", aIndex));
  2575         OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_FATAL, TUSBCDESCRIPTORPOOL_STRINGDESCRIPTOREXISTS_DUP2,
       
  2576                 "  Error: No $ descriptor @ pos %d", aIndex );
  2363 		return EFalse;
  2577 		return EFalse;
  2364 		}
  2578 		}
  2365 	return ETrue;
  2579 	return ETrue;
  2366 	}
  2580 	}
  2367 
  2581 
  2369 //
  2583 //
  2370 //
  2584 //
  2371 //
  2585 //
  2372 TInt TUsbcDescriptorPool::FindAvailableStringPos() const
  2586 TInt TUsbcDescriptorPool::FindAvailableStringPos() const
  2373 	{
  2587 	{
  2374 	__KTRACE_OPT(KUSB, Kern::Printf("TUsbcDescriptorPool::FindAvailableStringPos()"));
  2588 	OstTraceDef0( OST_TRACE_CATEGORY_RND, TRACE_FLOW, TUSBCDESCRIPTORPOOL_FINDAVAILABLESTRINGPOS,
       
  2589 	        "TUsbcDescriptorPool::FindAvailableStringPos()" );
  2375 	const TInt n = iStrings.Count();
  2590 	const TInt n = iStrings.Count();
  2376 	// We don't start from 0 because the first few locations are 'reserved'.
  2591 	// We don't start from 0 because the first few locations are 'reserved'.
  2377 	for (TInt i = KStringPosition_FirstAvailable; i < n; i++)
  2592 	for (TInt i = KStringPosition_FirstAvailable; i < n; i++)
  2378 		{
  2593 		{
  2379 		if (iStrings[i] == NULL)
  2594 		if (iStrings[i] == NULL)
  2380 			{
  2595 			{
  2381 			__KTRACE_OPT(KUSB, Kern::Printf(" Found available NULL position: %d", i));
  2596             OstTraceDef1( OST_TRACE_CATEGORY_RND, TRACE_NORMAL, TUSBCDESCRIPTORPOOL_FINDAVAILABLESTRINGPOS_DUP1,
       
  2597                     " Found available NULL position: %d", i );
  2382 			return i;
  2598 			return i;
  2383 			}
  2599 			}
  2384 		}
  2600 		}
  2385 	return -1;
  2601 	return -1;
  2386 	}
  2602 	}