os/kernelhwsrv/kerneltest/e32test/usb/t_usb_device/src/config.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usb/t_usb_device/src/config.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1157 @@
     1.4 +// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32test/usb/t_usbdev/src/config.cpp
    1.18 +// USB Test Program T_USB_DEVICE.
    1.19 +// Reading and converting the XML configuration file.
    1.20 +// 
    1.21 +//
    1.22 +
    1.23 +#include "general.h"
    1.24 +#include "config.h"
    1.25 +
    1.26 +_LIT(KCfgLDD,"LDD");
    1.27 +_LIT(KCfgLDD1,"ENDPOINTS");
    1.28 +_LIT(KCfgLDD2,"SOFTCONNECT");
    1.29 +_LIT(KCfgLDD3,"SELFPOWER");
    1.30 +_LIT(KCfgLDD4,"REMOTEWAKEUP");
    1.31 +_LIT(KCfgLDD5,"HIGHSPEED");
    1.32 +_LIT(KCfgLDD6,"FEATURES");
    1.33 +_LIT(KCfgLDD7,"MAXPOWER");
    1.34 +_LIT(KCfgLDD8,"EPSTALL");
    1.35 +_LIT(KCfgLDD9,"SPEC");
    1.36 +_LIT(KCfgLDD10,"VID");
    1.37 +_LIT(KCfgLDD11,"PID");
    1.38 +_LIT(KCfgLDD12,"RELEASE");
    1.39 +_LIT(KCfgLDD13,"MANUFACTURER");
    1.40 +_LIT(KCfgLDD14,"PRODUCT");
    1.41 +_LIT(KCfgLDD15,"SERIALNUMBER");
    1.42 +_LIT(KCfgLDD16,"OTG");
    1.43 +_LIT(KCfgIF,"INTERFACE");
    1.44 +_LIT(KCfgIFS,"ALT_SETTING");
    1.45 +_LIT(KCfgIF1,"CLASS");
    1.46 +_LIT(KCfgIF2,"SUBCLASS");
    1.47 +_LIT(KCfgIF3,"PROTOCOL");
    1.48 +_LIT(KCfgIF4,"DESCRIPTOR");
    1.49 +_LIT(KCfgIF5,"BANDWIDTH_IN");
    1.50 +_LIT(KCfgIF6,"BANDWIDTH_OUT");
    1.51 +_LIT(KCfgEP,"ENDPOINT");
    1.52 +_LIT(KCfgEP1,"SIZE");
    1.53 +_LIT(KCfgEP2,"INTERVAL");
    1.54 +_LIT(KCfgEP3,"HSINTERVAL");
    1.55 +_LIT(KCfgEP4,"HSTRANSACTIONS");
    1.56 +_LIT(KCfgEP5,"DMA");
    1.57 +_LIT(KCfgEP6,"DOUBLEBUFF");
    1.58 +_LIT(KCfgEP7,"EXTRA");
    1.59 +_LIT(KCfgEP8,"BUFFERSIZE");
    1.60 +_LIT(KCfgEP9,"READSIZE");
    1.61 +
    1.62 +
    1.63 +_LIT(KAttributeName,"name=");
    1.64 +_LIT(KAttributeNumber,"number=");
    1.65 +_LIT(KAttributeType,"type=");
    1.66 +_LIT(KAttributeDirection,"direction=");
    1.67 +
    1.68 +_LIT(KEpBulk,"\"BULK\"");
    1.69 +_LIT(KEpInterrupt,"\"INTERRUPT\"");
    1.70 +_LIT(KEpIsochronous,"\"ISOCHRONOUS\"");
    1.71 +_LIT(KEpIn,"\"IN\"");
    1.72 +_LIT(KEpOut,"\"OUT\"");
    1.73 +
    1.74 +static const TInt8 KMaxXMLNesting = 3;						// max 3 levels of xml nesting
    1.75 +
    1.76 +static const TPtrC xmlKeys[] = 
    1.77 +	{
    1.78 +	(TDesC&)KCfgLDD, (TDesC&)KCfgLDD1, (TDesC&)KCfgLDD2, (TDesC&)KCfgLDD3, (TDesC&)KCfgLDD4, (TDesC&)KCfgLDD5, (TDesC&)KCfgLDD6,
    1.79 +	(TDesC&)KCfgLDD7, (TDesC&)KCfgLDD8, (TDesC&)KCfgLDD9, (TDesC&)KCfgLDD10, (TDesC&)KCfgLDD11, (TDesC&)KCfgLDD12, (TDesC&)KCfgLDD13,
    1.80 +	(TDesC&)KCfgLDD14, (TDesC&)KCfgLDD15, (TDesC&)KCfgLDD16,
    1.81 +	(TDesC&)KCfgIF, (TDesC&)KCfgIFS, (TDesC&)KCfgIF1, (TDesC&)KCfgIF2, (TDesC&)KCfgIF3, (TDesC&)KCfgIF4, (TDesC&)KCfgIF5, (TDesC&)KCfgIF6,
    1.82 +	(TDesC&)KCfgEP, (TDesC&)KCfgEP1, (TDesC&)KCfgEP2, (TDesC&)KCfgEP3, (TDesC&)KCfgEP4, (TDesC&)KCfgEP5, (TDesC&)KCfgEP6, (TDesC&)KCfgEP7, (TDesC&)KCfgEP8, (TDesC&)KCfgEP9
    1.83 +	};
    1.84 +
    1.85 +enum xmlIndex
    1.86 +	{
    1.87 +	ExiLdd = 0,						// xmlKeys index for LDD
    1.88 +	ExiEndpoints,
    1.89 +	ExiSoftconnect,
    1.90 +	ExiSelfPower,
    1.91 +	ExiRemoteWakeup,
    1.92 +	ExiHighSpeed,
    1.93 +	ExiFeatures,
    1.94 +	ExiMaxPower,
    1.95 +	ExiEpStall,
    1.96 +	ExiSpec,
    1.97 +	ExiVID,
    1.98 +	ExiPID,
    1.99 +	ExiRelease,
   1.100 +	ExiManufacturer,
   1.101 +	ExiProduct,
   1.102 +	ExiSerialNumber,
   1.103 +	ExiOTG,
   1.104 +	ExiInterface,					// xmlKeys index for Interface
   1.105 +	ExiSetting,						
   1.106 +	ExiClass,
   1.107 +	ExiSubclass,
   1.108 +	ExiProtocol,
   1.109 +	ExiDescriptor,
   1.110 +	ExiBandwidthIn,
   1.111 +	ExiBandwidthOut,
   1.112 +	ExiEndpoint,					// xmlKeys index for Endpoint
   1.113 +	ExiSize,
   1.114 +	ExiInterval,
   1.115 +	ExiHSInterval,
   1.116 +	ExiHSTransactions,
   1.117 +	ExiDMA,
   1.118 +	ExiDoubleBuff,
   1.119 +	ExiExtra,
   1.120 +	ExiBufferSize,
   1.121 +	ExiReadSize,
   1.122 +	ExiLAST
   1.123 +	};
   1.124 +	
   1.125 +// This array provides the index into xmlKeys for each level of xml key
   1.126 +// the first index for level n being defined by xmlLevels[n]
   1.127 +// and the last index for level n being defined by xmlLevels[n+1] - 1
   1.128 +// this means this must have two more entries than the number of nesting levels
   1.129 +// and the last entry must be the size of xmlKeys 
   1.130 +static const TUint8 xmlLevels[] = 
   1.131 +	{
   1.132 +	ExiLdd,ExiLdd+1,ExiSetting+1,ExiEndpoint+1,ExiLAST
   1.133 +	};
   1.134 +
   1.135 +LDDConfig::LDDConfig (TPtrC aName)
   1.136 +	{
   1.137 +	iPtrNext = NULL;
   1.138 +	iIFPtr = NULL;
   1.139 +	iName = aName;
   1.140 +	iSoftConnect = ETrue;
   1.141 +	iSelfPower = ETrue;
   1.142 +	iRemoteWakeup = ETrue;
   1.143 +	iHighSpeed = ETrue;
   1.144 +	iEPStall = ETrue;
   1.145 +	iNumEndpoints = 15;
   1.146 +	iNumChannels = 0;
   1.147 +	iFeatures = 1;
   1.148 +	iMaxPower = 50;
   1.149 +	iSpec = 0x0200;
   1.150 +	iVid = 0x0E22;
   1.151 +	iPid = 0x1111;
   1.152 +	iRelease = 0x0305;
   1.153 +	iManufacturer = NULL;
   1.154 +	iProduct = NULL;
   1.155 +	iSerialNumber = NULL;
   1.156 +	iOtg_A = ETrue;
   1.157 +	iOtg_altA = ETrue;
   1.158 +	iOtg_altB = ETrue;
   1.159 +	};
   1.160 +
   1.161 +IFConfig::IFConfig(TUint8 aNumber)
   1.162 +	{
   1.163 +	iPtrNext = NULL;
   1.164 +	iNumber = aNumber;
   1.165 +	iAlternateSetting = EFalse;
   1.166 +	#ifdef USB_SC
   1.167 +	iInfoPtr = new TUsbcScInterfaceInfo(0xFF,0xFF,0xFF);
   1.168 +	#else
   1.169 +	iInfoPtr = new TUsbcInterfaceInfo(0xFF,0xFF,0xFF);
   1.170 +	iBandwidthIn = EUsbcBandwidthINDefault;
   1.171 +	iBandwidthOut = EUsbcBandwidthOUTDefault;
   1.172 +	#endif
   1.173 +	}
   1.174 +
   1.175 +ConfigPtrs::ConfigPtrs (LDDConfigPtr * aLDDPtrPtr)
   1.176 +	{
   1.177 +	iNextLDDPtrPtr = aLDDPtrPtr;
   1.178 +	iThisLDDPtr = * aLDDPtrPtr;
   1.179 +	iThisIFPtr = NULL;
   1.180 +	iNextIFPtrPtr = &iThisIFPtr;		// initialised to prevent warning
   1.181 +	}
   1.182 +
   1.183 +extern RTest test;
   1.184 +extern TBool gVerbose;
   1.185 +extern TBool gSkip;
   1.186 +extern TBool gStopOnFail;
   1.187 +extern TInt gSoakCount;
   1.188 +
   1.189 +bool ProcessConfigFile (RFile aConfigFile,CConsoleBase* iConsole, LDDConfigPtr * LDDPtrPtr)
   1.190 +	{
   1.191 +	TUSB_PRINT ("Processing Configuration File");
   1.192 +	
   1.193 +	TBuf8<100> configBuf;
   1.194 +	TBuf<101> stringBuf;
   1.195 +	bool done = false;
   1.196 +	bool error = false;
   1.197 +	TInt rStatus;
   1.198 +	XMLState state = EEmpty;
   1.199 +	TChar nextChar(' ');
   1.200 +	TChar lastChar(' ');
   1.201 +	TBuf<50> keyString;
   1.202 +	TBuf<50> endkeyString;
   1.203 +	TBuf<50> attributeString;
   1.204 +	TBuf<50> valueString;
   1.205 +	TInt level = -1;
   1.206 +	TInt levelKeys[KMaxXMLNesting+1];
   1.207 +
   1.208 +	* LDDPtrPtr = NULL;
   1.209 +	ConfigPtrsPtr cpPtr = new ConfigPtrs (LDDPtrPtr); 			
   1.210 +
   1.211 +	while (!done && !error)
   1.212 +		{
   1.213 +		rStatus = aConfigFile.Read((TDes8&)configBuf);
   1.214 +		if (rStatus != KErrNone)
   1.215 +			{
   1.216 +			error = true;
   1.217 +			TUSB_PRINT1("Config file error %d", rStatus);			
   1.218 +			}
   1.219 +		else
   1.220 +			{
   1.221 +			if (configBuf.Length() == 0)
   1.222 +				{
   1.223 +				done = true;			
   1.224 +				}
   1.225 +			else
   1.226 +				{
   1.227 +				stringBuf.Copy(configBuf);
   1.228 +				for (TInt i = 0; i < stringBuf.Length() && !error; i++)
   1.229 +					{
   1.230 +					lastChar = nextChar;
   1.231 +					nextChar = stringBuf[i];
   1.232 +					if (((nextChar == '<') && !((state == EEmpty) || (state == EValue))) ||
   1.233 +						((nextChar == '>') && ((state == EEmpty) || (state == EValue))) ||
   1.234 +						((nextChar == '/') && (lastChar != '<')))
   1.235 +						{
   1.236 +						error = true;
   1.237 +						TUSB_PRINT2 ("Config File Syntax Error at index %d of %s",i,stringBuf.PtrZ());
   1.238 +						}
   1.239 +					switch (state)
   1.240 +						{
   1.241 +						case EEmpty:
   1.242 +							if (nextChar == '<')
   1.243 +								{
   1.244 +								state = EStartKey;
   1.245 +								}
   1.246 +							else
   1.247 +								if (!nextChar.IsSpace())
   1.248 +									{
   1.249 +									error = true;
   1.250 +									TUSB_PRINT2 ("Config File Syntax Error at index %d of %s",i,stringBuf.PtrZ());
   1.251 +									}
   1.252 +							break;
   1.253 +						
   1.254 +						case EStartKey:
   1.255 +							if (nextChar == '/')
   1.256 +								{
   1.257 +								state = EEndKey;
   1.258 +								endkeyString.SetLength(0);															
   1.259 +								}
   1.260 +							else
   1.261 +								{
   1.262 +								if (nextChar == '>')
   1.263 +									{
   1.264 +									level++;
   1.265 +									if (level > KMaxXMLNesting)
   1.266 +										{
   1.267 +										error = true;
   1.268 +										TUSB_PRINT1 ("Config File Too Many levels %s",stringBuf.PtrZ());								
   1.269 +										}
   1.270 +									else
   1.271 +										{
   1.272 +										levelKeys[level] = CheckXmlKey (keyString,level);
   1.273 +										if (levelKeys[level] < 0)
   1.274 +											{
   1.275 +											error = true;
   1.276 +											TUSB_PRINT1 ("Invalid XML key %s",keyString.PtrZ());																	
   1.277 +											}
   1.278 +										else
   1.279 +											{
   1.280 +											if (CheckAttribute(iConsole,cpPtr,levelKeys[level],attributeString))
   1.281 +												{
   1.282 +												state = EValue;
   1.283 +												TUSB_VERBOSE_PRINT2 ("Start key: %s level %d",keyString.PtrZ(),level);			
   1.284 +												}
   1.285 +											else
   1.286 +												{
   1.287 +												error = true;	
   1.288 +												TUSB_PRINT1 ("No attribute for XML key %s",keyString.PtrZ());																	
   1.289 +												}
   1.290 +											}
   1.291 +										}
   1.292 +									}
   1.293 +								else
   1.294 +									{
   1.295 +									if (lastChar == '<')
   1.296 +										{
   1.297 +										keyString.SetLength(0);
   1.298 +										valueString.SetLength(0);
   1.299 +										attributeString.SetLength(0);
   1.300 +										if (nextChar.IsSpace())
   1.301 +											{
   1.302 +											error = true;
   1.303 +											TUSB_PRINT2 ("Config File Syntax Error at index %d of %s",i,stringBuf.PtrZ());					
   1.304 +											}
   1.305 +										}
   1.306 +									if (nextChar.IsSpace())
   1.307 +										{
   1.308 +										state = EAttribute;
   1.309 +										}
   1.310 +									else
   1.311 +										{
   1.312 +										keyString.Append(nextChar);
   1.313 +										}
   1.314 +									}
   1.315 +								}
   1.316 +							break;
   1.317 +							
   1.318 +						case EEndKey:
   1.319 +							if (nextChar == '>')
   1.320 +								{
   1.321 +								if (levelKeys[level] != CheckXmlKey (endkeyString,level))
   1.322 +									{
   1.323 +									error = true;
   1.324 +									TUSB_PRINT1 ("Invalid XML end key %s",endkeyString.PtrZ());																	
   1.325 +									}
   1.326 +								else
   1.327 +									{												
   1.328 +									if (CheckValue(iConsole,cpPtr,levelKeys[level],valueString))
   1.329 +										{
   1.330 +										state = EEmpty;
   1.331 +										TUSB_VERBOSE_PRINT2 ("End Key: %s value %s",endkeyString.PtrZ(),valueString.PtrZ());
   1.332 +										level--;
   1.333 +										valueString.SetLength(0);
   1.334 +										}
   1.335 +									else
   1.336 +										{
   1.337 +										error = true;
   1.338 +										TUSB_PRINT2 ("Incorrect value string %s for XML key %s",valueString.PtrZ(),endkeyString.PtrZ());	
   1.339 +										}
   1.340 +									}
   1.341 +								}
   1.342 +							if (nextChar.IsSpace())
   1.343 +								{
   1.344 +									error = true;
   1.345 +									TUSB_PRINT2 ("Config File Syntax Error at index %d of %s",i,stringBuf.PtrZ());
   1.346 +								}
   1.347 +							else
   1.348 +								{
   1.349 +								endkeyString.Append(nextChar);
   1.350 +								}
   1.351 +							break;
   1.352 +							
   1.353 +						case EAttribute:
   1.354 +							if (nextChar == '>')
   1.355 +								{
   1.356 +								level++;
   1.357 +								if (level > KMaxXMLNesting)
   1.358 +									{
   1.359 +									error = true;
   1.360 +									TUSB_PRINT1 ("Config File Too Many levels %s",stringBuf.PtrZ());								
   1.361 +									}
   1.362 +								else
   1.363 +									{
   1.364 +									levelKeys[level] = CheckXmlKey (keyString,level);
   1.365 +									if (levelKeys[level] < 0)
   1.366 +										{
   1.367 +										error = true;
   1.368 +										TUSB_PRINT1 ("Invalid XML key %s",keyString.PtrZ());																	
   1.369 +										}
   1.370 +									else
   1.371 +										{
   1.372 +										if (CheckAttribute(iConsole,cpPtr,levelKeys[level],attributeString))
   1.373 +											{
   1.374 +											state = EValue;
   1.375 +											TUSB_VERBOSE_PRINT3 ("Start key: %s level %d attribute %s",keyString.PtrZ(),level,attributeString.PtrZ());
   1.376 +											}
   1.377 +										else
   1.378 +											{
   1.379 +											error = true;	
   1.380 +											TUSB_PRINT2 ("Incorrect attribute %s for XML key %s",attributeString.PtrZ(),keyString.PtrZ());																	
   1.381 +											}
   1.382 +										}
   1.383 +									}
   1.384 +								}
   1.385 +							else
   1.386 +								{
   1.387 +								attributeString.Append(nextChar);
   1.388 +								}
   1.389 +							break;
   1.390 +							
   1.391 +						case EValue:
   1.392 +							if (nextChar == '<')
   1.393 +								{
   1.394 +								state = EStartKey;
   1.395 +								}
   1.396 +							else
   1.397 +								{
   1.398 +								// Don't add any leading spaces
   1.399 +								if (!nextChar.IsSpace() || valueString.Length() != 0)
   1.400 +									{
   1.401 +									valueString.Append(nextChar);						
   1.402 +									}
   1.403 +								}
   1.404 +							break;
   1.405 +						}
   1.406 +					}
   1.407 +				}
   1.408 +			}
   1.409 +		}
   1.410 +		
   1.411 +	delete cpPtr;
   1.412 +
   1.413 +	return !error;
   1.414 +	}
   1.415 +
   1.416 +
   1.417 +	
   1.418 +TBool CheckAttribute (CConsoleBase* iConsole, ConfigPtrsPtr cpPtr,TInt aKeyIndex, TPtrC aDes)
   1.419 +	{
   1.420 +	TBool retValue = ETrue;
   1.421 +	TBuf<50> attrib = aDes;
   1.422 +	TInt typePos;
   1.423 +	TInt dirPos;
   1.424 +	TInt typeLen;
   1.425 +	TInt dirLen;
   1.426 +	TUint epType = 0;
   1.427 +	TUint epDir = 0;
   1.428 +	TUint ifNumber = 0;
   1.429 +
   1.430 +	_LIT (KQuote,"\"");
   1.431 +
   1.432 +	switch (aKeyIndex)
   1.433 +		{
   1.434 +		// level 0 index LDD
   1.435 +		case ExiLdd :
   1.436 +			if (attrib.Find(KAttributeName) == 0)
   1.437 +				{
   1.438 +				attrib.Delete(0,((TDesC&)KAttributeName).Length());
   1.439 +				if (attrib[0] == ((TDesC&)KQuote)[0] && attrib[attrib.Length()-1] == ((TDesC&)KQuote)[0])
   1.440 +					{
   1.441 +					TUSB_VERBOSE_PRINT1 ("LDD with attribute name %s",attrib.PtrZ());
   1.442 +					cpPtr->iThisLDDPtr = new LDDConfig (attrib.MidTPtr(1,attrib.Length()-2));		
   1.443 +					*cpPtr->iNextLDDPtrPtr = cpPtr->iThisLDDPtr;
   1.444 +					cpPtr->iNextLDDPtrPtr = &(cpPtr->iThisLDDPtr->iPtrNext);
   1.445 +					cpPtr->iNextIFPtrPtr = &(cpPtr->iThisLDDPtr->iIFPtr);			
   1.446 +					}
   1.447 +				else
   1.448 +					retValue = EFalse;
   1.449 +				}
   1.450 +			else
   1.451 +				{
   1.452 +				retValue = EFalse;
   1.453 +				}
   1.454 +			break;
   1.455 +			
   1.456 +		//	level 1 index INTERFACE
   1.457 +		case ExiInterface :
   1.458 +			if (attrib.Find(KAttributeNumber) == 0)
   1.459 +				{
   1.460 +				attrib.Delete(0,((TDesC&)KAttributeNumber).Length());
   1.461 +				if (attrib[0] == ((TDesC&)KQuote)[0] && attrib[attrib.Length()-1] == ((TDesC&)KQuote)[0])
   1.462 +					{
   1.463 +					if (TDesToTUint(attrib.MidTPtr(1,attrib.Length()-2), &ifNumber))
   1.464 +						{
   1.465 +						if (cpPtr->iThisLDDPtr == NULL)
   1.466 +							{
   1.467 +							TUSB_PRINT ("No LDD container for interface");
   1.468 +							retValue = EFalse;				
   1.469 +							}
   1.470 +						}
   1.471 +					else
   1.472 +						{
   1.473 +						TUSB_PRINT2 ("Number conversion error %s %d",attrib.PtrZ(),ifNumber);
   1.474 +						retValue = EFalse;
   1.475 +						}
   1.476 +					}
   1.477 +				else
   1.478 +					{
   1.479 +					TUSB_PRINT1 ("Attribute number not in \"\" %s",attrib.PtrZ());
   1.480 +					retValue = EFalse;	
   1.481 +					}
   1.482 +				}
   1.483 +			if (retValue)
   1.484 +				{
   1.485 +	 			TUSB_VERBOSE_PRINT1 ("Interface number %d",ifNumber);
   1.486 +				cpPtr->iThisIFPtr = new IFConfig ((TUint8)ifNumber);
   1.487 +				* cpPtr->iNextIFPtrPtr = cpPtr->iThisIFPtr;
   1.488 +				cpPtr->iNextIFPtrPtr = &cpPtr->iThisIFPtr->iPtrNext;
   1.489 +				cpPtr->iThisLDDPtr->iNumChannels++;
   1.490 +				}
   1.491 +			break;	
   1.492 +			
   1.493 +
   1.494 +		//	level 1 index Setting
   1.495 +		case ExiSetting :
   1.496 +			if (aDes.Length() != 0)
   1.497 +				{
   1.498 +				retValue = EFalse;
   1.499 +				}
   1.500 +			else
   1.501 +				{
   1.502 +				if (cpPtr->iThisLDDPtr == NULL)
   1.503 +					{
   1.504 +					TUSB_PRINT ("No LDD container for interface");
   1.505 +					retValue = EFalse;				
   1.506 +					}
   1.507 +				else
   1.508 +					{
   1.509 +					TUSB_VERBOSE_PRINT ("Alternate Interface Setting");			
   1.510 +					cpPtr->iThisIFPtr = new IFConfig (0);		
   1.511 +					* cpPtr->iNextIFPtrPtr = cpPtr->iThisIFPtr;
   1.512 +					cpPtr->iNextIFPtrPtr = &cpPtr->iThisIFPtr->iPtrNext;
   1.513 +					cpPtr->iThisIFPtr->iAlternateSetting = ETrue;
   1.514 +					}					
   1.515 +				}
   1.516 +			break;
   1.517 +			
   1.518 +		//	level 2 index ENDPOINT
   1.519 +		case ExiEndpoint :
   1.520 +			typePos = attrib.Find(KAttributeType);
   1.521 +			dirPos = attrib.Find(KAttributeDirection);
   1.522 +			
   1.523 +			if (typePos == KErrNotFound || dirPos == KErrNotFound)
   1.524 +				{
   1.525 +				retValue = EFalse;
   1.526 +				}
   1.527 +			else	
   1.528 +				{
   1.529 +				if (typePos < dirPos)
   1.530 +					{
   1.531 +					typePos += ((TDesC&)KAttributeType).Length();
   1.532 +					typeLen = dirPos - typePos;
   1.533 +					dirPos += ((TDesC&)KAttributeDirection).Length();
   1.534 +					dirLen = attrib.Length() - dirPos;			
   1.535 +					}
   1.536 +				else
   1.537 +					{
   1.538 +					dirPos += ((TDesC&)KAttributeDirection).Length();			
   1.539 +					dirLen = typePos - dirPos;
   1.540 +					typePos += ((TDesC&)KAttributeType).Length();
   1.541 +					typeLen = attrib.Length() - typePos;			
   1.542 +					}
   1.543 +				TPtr attribPtr = attrib.MidTPtr(typePos,typeLen);
   1.544 +				attribPtr.UpperCase();
   1.545 +				attribPtr.TrimAll();
   1.546 +				if (attribPtr == KEpBulk)
   1.547 +					{
   1.548 +					epType = KUsbEpTypeBulk;
   1.549 +					}
   1.550 +				else
   1.551 +					{
   1.552 +					if (attribPtr == KEpInterrupt)
   1.553 +						{
   1.554 +						epType = KUsbEpTypeInterrupt;
   1.555 +						}
   1.556 +					else
   1.557 +						{
   1.558 +						if (attribPtr == KEpIsochronous)
   1.559 +							{
   1.560 +							epType = KUsbEpTypeIsochronous;
   1.561 +							}
   1.562 +						else
   1.563 +							{
   1.564 +							retValue = EFalse;					
   1.565 +							}
   1.566 +						}
   1.567 +					}
   1.568 +				attribPtr = attrib.MidTPtr(dirPos,dirLen);
   1.569 +				attribPtr.UpperCase();
   1.570 +				attribPtr.TrimAll();
   1.571 +				if (attribPtr == KEpIn)
   1.572 +					{
   1.573 +					epDir = KUsbEpDirIn;
   1.574 +					}
   1.575 +				else
   1.576 +					{
   1.577 +					if (attribPtr == KEpOut)
   1.578 +						{
   1.579 +						epDir = KUsbEpDirOut;
   1.580 +						}
   1.581 +					else
   1.582 +						{
   1.583 +						retValue = EFalse;
   1.584 +						}
   1.585 +					}
   1.586 +				if (retValue)
   1.587 +					{
   1.588 +					if (cpPtr->iThisIFPtr == NULL)
   1.589 +						{
   1.590 +						TUSB_PRINT ("No Interface container for Endpoint");
   1.591 +						retValue = EFalse;				
   1.592 +						}
   1.593 +					else
   1.594 +						{
   1.595 +						TUint epIndex = cpPtr->iThisIFPtr->iInfoPtr->iTotalEndpointsUsed;
   1.596 +						TUSB_VERBOSE_PRINT2 ("Endpoint with type %d %d",epType,epDir);			
   1.597 +						cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iType = epType;
   1.598 +						cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iDir = epDir;
   1.599 +						#ifdef USB_SC
   1.600 +						cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iBufferSize = 65536;
   1.601 +						cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iReadSize = 4096;
   1.602 +						#endif
   1.603 +						cpPtr->iThisIFPtr->iEpDMA[epIndex] = EFalse;
   1.604 +						cpPtr->iThisIFPtr->iEpDoubleBuff[epIndex] = EFalse;
   1.605 +						cpPtr->iThisIFPtr->iInfoPtr->iTotalEndpointsUsed++;
   1.606 +						}
   1.607 +					}
   1.608 +				}
   1.609 +			break;
   1.610 +		
   1.611 +		default :
   1.612 +			if (aDes.Length() != 0)
   1.613 +				{
   1.614 +				retValue = EFalse;
   1.615 +				}
   1.616 +		}
   1.617 +		
   1.618 +	return retValue;
   1.619 +	}
   1.620 +
   1.621 +TBool CheckValue (CConsoleBase* iConsole, ConfigPtrsPtr cpPtr, TInt aKeyIndex, TPtrC16 aDes)
   1.622 +	{
   1.623 +	TBool retValue = ETrue;
   1.624 +	TBool boolValue;
   1.625 +	TUint uintValue;
   1.626 +	TInt epIndex = -1;
   1.627 +	
   1.628 +	if (cpPtr->iThisIFPtr != NULL)
   1.629 +		{
   1.630 +		epIndex = cpPtr->iThisIFPtr->iInfoPtr->iTotalEndpointsUsed -1;
   1.631 +		}
   1.632 +		
   1.633 +	TUSB_VERBOSE_PRINT2 ("CheckValue keyIndex %d %s",aKeyIndex,aDes.Ptr());
   1.634 +	switch (aKeyIndex)
   1.635 +		{
   1.636 +		case ExiLdd:						// xmlKeys index for LDD
   1.637 +		case ExiInterface:					// xmlKeys index for Interface
   1.638 +		case ExiEndpoint:					// xmlKeys index for Endpoint
   1.639 +			if (aDes.Length() != 0)
   1.640 +				{
   1.641 +				retValue = EFalse;
   1.642 +				}
   1.643 +			break;
   1.644 +			
   1.645 +		case ExiEndpoints:
   1.646 +			retValue = TDesToTUint (aDes, &uintValue);
   1.647 +			if (uintValue == 0 || uintValue > 128)
   1.648 +				{
   1.649 +				retValue = EFalse;			
   1.650 +				}
   1.651 +			else
   1.652 +				{
   1.653 +				cpPtr->iThisLDDPtr->iNumEndpoints = uintValue;
   1.654 +				}
   1.655 +			break;
   1.656 +			
   1.657 +		case ExiSoftconnect:
   1.658 +			retValue = TDesToBool (aDes, &boolValue);
   1.659 +			if (cpPtr->iThisLDDPtr == NULL)
   1.660 +				retValue = EFalse;
   1.661 +			if (retValue)
   1.662 +				{
   1.663 +				cpPtr->iThisLDDPtr->iSoftConnect = boolValue;
   1.664 +				}
   1.665 +			break;
   1.666 +			
   1.667 +		case ExiSelfPower:
   1.668 +			retValue = TDesToBool (aDes, &boolValue);
   1.669 +			if (cpPtr->iThisLDDPtr == NULL)
   1.670 +				retValue = EFalse;
   1.671 +			if (retValue)
   1.672 +				{
   1.673 +				cpPtr->iThisLDDPtr->iSelfPower = boolValue;
   1.674 +				}
   1.675 +			break;
   1.676 +			
   1.677 +		case ExiRemoteWakeup:
   1.678 +			retValue = TDesToBool (aDes, &boolValue);
   1.679 +			if (cpPtr->iThisLDDPtr == NULL)
   1.680 +				retValue = EFalse;
   1.681 +			if (retValue)
   1.682 +				{
   1.683 +				cpPtr->iThisLDDPtr->iRemoteWakeup = boolValue;
   1.684 +				}
   1.685 +			break;
   1.686 +			
   1.687 +		case ExiHighSpeed:
   1.688 +			retValue = TDesToBool (aDes, &boolValue);
   1.689 +			if (cpPtr->iThisLDDPtr == NULL)
   1.690 +				retValue = EFalse;
   1.691 +			if (retValue)
   1.692 +				{
   1.693 +				cpPtr->iThisLDDPtr->iHighSpeed = boolValue;
   1.694 +				}
   1.695 +			break;
   1.696 +			
   1.697 +		case ExiFeatures:
   1.698 +			retValue = TDesToTUint (aDes, &uintValue);
   1.699 +			if (cpPtr->iThisLDDPtr == NULL)
   1.700 +				retValue = EFalse;
   1.701 +			if (retValue)
   1.702 +				{
   1.703 +				cpPtr->iThisLDDPtr->iFeatures = uintValue;
   1.704 +				}
   1.705 +			break;
   1.706 +			
   1.707 +		case ExiMaxPower:
   1.708 +			retValue = TDesToTUint (aDes, &uintValue);
   1.709 +			if (cpPtr->iThisLDDPtr == NULL || uintValue > 50)
   1.710 +				retValue = EFalse;
   1.711 +			if (retValue)
   1.712 +				{
   1.713 +				cpPtr->iThisLDDPtr->iMaxPower = uintValue;
   1.714 +				}
   1.715 +			break;
   1.716 +			
   1.717 +		case ExiEpStall:
   1.718 +			retValue = TDesToBool (aDes, &boolValue);
   1.719 +			if (cpPtr->iThisLDDPtr == NULL)
   1.720 +				retValue = EFalse;
   1.721 +			if (retValue)
   1.722 +				{
   1.723 +				cpPtr->iThisLDDPtr->iEPStall = boolValue;
   1.724 +				}
   1.725 +			break;
   1.726 +			
   1.727 +		case ExiSpec:
   1.728 +			retValue = TDesToTUint (aDes, &uintValue);
   1.729 +			if (cpPtr->iThisLDDPtr == NULL)
   1.730 +				retValue = EFalse;
   1.731 +			if (retValue)
   1.732 +				{
   1.733 +				cpPtr->iThisLDDPtr->iSpec = uintValue;
   1.734 +				}
   1.735 +			break;
   1.736 +			
   1.737 +		case ExiVID:
   1.738 +			retValue = TDesToTUint (aDes, &uintValue);
   1.739 +			if (cpPtr->iThisLDDPtr == NULL)
   1.740 +				retValue = EFalse;
   1.741 +			if (retValue)
   1.742 +				{
   1.743 +				cpPtr->iThisLDDPtr->iVid = uintValue;
   1.744 +				}
   1.745 +			break;
   1.746 +			
   1.747 +		case ExiPID:
   1.748 +			retValue = TDesToTUint (aDes, &uintValue);
   1.749 +			if (cpPtr->iThisLDDPtr == NULL)
   1.750 +				retValue = EFalse;
   1.751 +			if (retValue)
   1.752 +				{
   1.753 +				cpPtr->iThisLDDPtr->iPid = uintValue;
   1.754 +				}
   1.755 +			break;
   1.756 +			
   1.757 +		case ExiRelease:
   1.758 +			retValue = TDesToTUint (aDes, &uintValue);
   1.759 +			if (cpPtr->iThisLDDPtr == NULL)
   1.760 +				retValue = EFalse;
   1.761 +			if (retValue)
   1.762 +				{
   1.763 +				cpPtr->iThisLDDPtr->iRelease = uintValue;
   1.764 +				}
   1.765 +			break;
   1.766 +			
   1.767 +		case ExiManufacturer:
   1.768 +			cpPtr->iThisLDDPtr->iManufacturer = aDes.Alloc();
   1.769 +			break;
   1.770 +
   1.771 +		case ExiProduct:
   1.772 +			cpPtr->iThisLDDPtr->iProduct = aDes.Alloc();
   1.773 +			break;
   1.774 +
   1.775 +		case ExiSerialNumber:
   1.776 +			cpPtr->iThisLDDPtr->iSerialNumber = aDes.Alloc();
   1.777 +			break;
   1.778 +
   1.779 +		case ExiOTG:
   1.780 +			break;
   1.781 +			
   1.782 +		case ExiClass:
   1.783 +			retValue = TDesToTUint (aDes, &uintValue);
   1.784 +			if (cpPtr->iThisIFPtr == NULL || uintValue > 0xFF)
   1.785 +				retValue = EFalse;
   1.786 +			if (retValue)
   1.787 +				{
   1.788 +				cpPtr->iThisIFPtr->iInfoPtr->iClass.iClassNum = uintValue;
   1.789 +				}
   1.790 +			break;
   1.791 +			
   1.792 +		case ExiSubclass:
   1.793 +			retValue = TDesToTUint (aDes, &uintValue);
   1.794 +			if (cpPtr->iThisIFPtr == NULL || uintValue > 0xFF)
   1.795 +				retValue = EFalse;
   1.796 +			if (retValue)
   1.797 +				{
   1.798 +				cpPtr->iThisIFPtr->iInfoPtr->iClass.iSubClassNum = uintValue;
   1.799 +				}
   1.800 +			break;
   1.801 +			
   1.802 +		case ExiProtocol:
   1.803 +			retValue = TDesToTUint (aDes, &uintValue);
   1.804 +			if (cpPtr->iThisIFPtr == NULL || uintValue > 0xFF)
   1.805 +				retValue = EFalse;
   1.806 +			if (retValue)
   1.807 +				{
   1.808 +				cpPtr->iThisIFPtr->iInfoPtr->iClass.iProtocolNum = uintValue;
   1.809 +				}
   1.810 +			break;
   1.811 +			
   1.812 +		case ExiDescriptor:
   1.813 +			cpPtr->iThisIFPtr->iInfoPtr->iString = aDes.Alloc();
   1.814 +			break;
   1.815 +			
   1.816 +		case ExiBandwidthIn:
   1.817 +			#ifdef USB_SC
   1.818 +			retValue = EFalse;
   1.819 +			#else			
   1.820 +			retValue = TDesToTUint (aDes, &uintValue);
   1.821 +			if (cpPtr->iThisIFPtr == NULL || uintValue > 3)
   1.822 +				retValue = EFalse;
   1.823 +			if (retValue)
   1.824 +				{
   1.825 +				switch (uintValue)
   1.826 +					{
   1.827 +				case 0:
   1.828 +					cpPtr->iThisIFPtr->iBandwidthIn = EUsbcBandwidthINDefault;
   1.829 +					break;
   1.830 +				case 1:
   1.831 +					cpPtr->iThisIFPtr->iBandwidthIn = EUsbcBandwidthINPlus1;
   1.832 +					break;
   1.833 +				case 2:
   1.834 +					cpPtr->iThisIFPtr->iBandwidthIn = EUsbcBandwidthINPlus2;
   1.835 +					break;
   1.836 +				case 3:
   1.837 +					cpPtr->iThisIFPtr->iBandwidthIn = EUsbcBandwidthINMaximum;
   1.838 +					break;
   1.839 +					}
   1.840 +				}
   1.841 +			#endif
   1.842 +			break;
   1.843 +			
   1.844 +		case ExiBandwidthOut:
   1.845 +			#ifdef USB_SC
   1.846 +			retValue = EFalse;
   1.847 +			#else			
   1.848 +			retValue = TDesToTUint (aDes, &uintValue);
   1.849 +			if (cpPtr->iThisIFPtr == NULL || uintValue > 3)
   1.850 +				retValue = EFalse;
   1.851 +			if (retValue)
   1.852 +				{
   1.853 +				switch (uintValue)
   1.854 +					{
   1.855 +				case 0:
   1.856 +					cpPtr->iThisIFPtr->iBandwidthOut = EUsbcBandwidthOUTDefault;
   1.857 +					break;
   1.858 +				case 1:
   1.859 +					cpPtr->iThisIFPtr->iBandwidthOut = EUsbcBandwidthOUTPlus1;
   1.860 +					break;
   1.861 +				case 2:
   1.862 +					cpPtr->iThisIFPtr->iBandwidthOut = EUsbcBandwidthOUTPlus2;
   1.863 +					break;
   1.864 +				case 3:
   1.865 +					cpPtr->iThisIFPtr->iBandwidthOut = EUsbcBandwidthOUTMaximum;
   1.866 +					break;
   1.867 +					}
   1.868 +				}
   1.869 +			#endif
   1.870 +			break;
   1.871 +			
   1.872 +		case ExiSize:
   1.873 +			retValue = TDesToTUint (aDes, &uintValue);
   1.874 +			if (epIndex < 0)
   1.875 +				retValue = EFalse;
   1.876 +			if (retValue)
   1.877 +				{
   1.878 +				TBool defaultIF = cpPtr->iThisLDDPtr->iIFPtr == cpPtr->iThisIFPtr;
   1.879 +				switch (cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iType)
   1.880 +					{
   1.881 +					case KUsbEpTypeBulk :
   1.882 +						if (cpPtr->iThisLDDPtr->iHighSpeed)
   1.883 +							{
   1.884 +							if (uintValue != 512)
   1.885 +								retValue = EFalse;
   1.886 +							}
   1.887 +						else
   1.888 +							{
   1.889 +							if (!(uintValue == 8 || uintValue == 16 || uintValue == 32 || uintValue == 64))
   1.890 +								retValue = EFalse;
   1.891 +							}
   1.892 +						break;
   1.893 +						
   1.894 +					case KUsbEpTypeInterrupt :
   1.895 +						if ((defaultIF && uintValue > 64) ||
   1.896 +							(!cpPtr->iThisLDDPtr->iHighSpeed && uintValue > 64) ||
   1.897 +							(!defaultIF && cpPtr->iThisLDDPtr->iHighSpeed && uintValue > 1024))
   1.898 +							retValue = EFalse;
   1.899 +						break;
   1.900 +						
   1.901 +					case KUsbEpTypeIsochronous :
   1.902 +						if ((defaultIF && uintValue > 0) ||
   1.903 +							(!defaultIF && !cpPtr->iThisLDDPtr->iHighSpeed && uintValue > 1023) ||
   1.904 +							(!defaultIF && cpPtr->iThisLDDPtr->iHighSpeed && uintValue > 1024))
   1.905 +							retValue = EFalse;
   1.906 +						break;					
   1.907 +					}
   1.908 +				if (retValue)
   1.909 +					{
   1.910 +					cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iSize = uintValue;
   1.911 +					}
   1.912 +				}
   1.913 +			
   1.914 +			break;
   1.915 +			
   1.916 +		case ExiInterval:
   1.917 +			retValue = TDesToTUint (aDes, &uintValue);
   1.918 +			if (epIndex < 0)
   1.919 +				retValue = EFalse;
   1.920 +			if (retValue)
   1.921 +				{
   1.922 +				switch (cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iType)
   1.923 +					{
   1.924 +					case KUsbEpTypeBulk :
   1.925 +						retValue = EFalse;
   1.926 +						break;
   1.927 +						
   1.928 +					case KUsbEpTypeInterrupt :
   1.929 +						if (uintValue < 1 || uintValue > 255)
   1.930 +							retValue = EFalse;
   1.931 +						break;
   1.932 +						
   1.933 +					case KUsbEpTypeIsochronous :
   1.934 +						if (uintValue < 1 || uintValue > 16)
   1.935 +							retValue = EFalse;
   1.936 +						break;					
   1.937 +					}
   1.938 +				if (retValue)
   1.939 +					{
   1.940 +					cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iInterval = uintValue;
   1.941 +					}
   1.942 +				}
   1.943 +			break;
   1.944 +			
   1.945 +		case ExiHSInterval:
   1.946 +			retValue = TDesToTUint (aDes, &uintValue);
   1.947 +			if (epIndex < 0 || !cpPtr->iThisLDDPtr->iHighSpeed)
   1.948 +				retValue = EFalse;
   1.949 +			if (retValue)
   1.950 +				{
   1.951 +				switch (cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iType)
   1.952 +					{
   1.953 +					case KUsbEpTypeBulk :
   1.954 +						if (uintValue > 255)
   1.955 +							retValue = EFalse;
   1.956 +						break;
   1.957 +						
   1.958 +					case KUsbEpTypeInterrupt :
   1.959 +						if (uintValue < 1 || uintValue > 16)
   1.960 +							retValue = EFalse;
   1.961 +						break;
   1.962 +						
   1.963 +					case KUsbEpTypeIsochronous :
   1.964 +						if (uintValue < 1 || uintValue > 16)
   1.965 +							retValue = EFalse;
   1.966 +						break;					
   1.967 +					}
   1.968 +				if (retValue)
   1.969 +					{
   1.970 +					cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iInterval_Hs = uintValue;
   1.971 +					}
   1.972 +				}
   1.973 +			break;
   1.974 +			
   1.975 +		case ExiHSTransactions:
   1.976 +			retValue = TDesToTUint (aDes, &uintValue);
   1.977 +			if (epIndex < 0 || !cpPtr->iThisLDDPtr->iHighSpeed)
   1.978 +				retValue = EFalse;
   1.979 +			if (retValue)
   1.980 +				{
   1.981 +				if (uintValue > 2)
   1.982 +					retValue = EFalse;
   1.983 +				if (retValue)
   1.984 +					{
   1.985 +					cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iTransactions = uintValue;
   1.986 +					}
   1.987 +				}
   1.988 +			break;
   1.989 +			
   1.990 +		case ExiDMA:
   1.991 +			retValue = TDesToBool (aDes, &boolValue);
   1.992 +			if (epIndex < 0)
   1.993 +				retValue = EFalse;
   1.994 +			if (retValue)
   1.995 +				{
   1.996 +				cpPtr->iThisIFPtr->iEpDMA[epIndex] = boolValue;
   1.997 +				}
   1.998 +			break;
   1.999 +			
  1.1000 +		case ExiDoubleBuff:
  1.1001 +			#ifdef USB_SC
  1.1002 +			retValue = EFalse;
  1.1003 +			#else
  1.1004 +			retValue = TDesToBool (aDes, &boolValue);
  1.1005 +			if (epIndex < 0)
  1.1006 +				retValue = EFalse;
  1.1007 +			if (retValue)
  1.1008 +				{
  1.1009 +				cpPtr->iThisIFPtr->iEpDoubleBuff[epIndex] = boolValue;
  1.1010 +				}
  1.1011 +			#endif
  1.1012 +			break;
  1.1013 +			
  1.1014 +		case ExiExtra:
  1.1015 +			retValue = TDesToTUint (aDes, &uintValue);
  1.1016 +			if (epIndex < 0)
  1.1017 +				retValue = EFalse;
  1.1018 +			if (retValue)
  1.1019 +				{
  1.1020 +				cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iExtra = uintValue;
  1.1021 +				}
  1.1022 +			break;
  1.1023 +
  1.1024 +		case ExiBufferSize:
  1.1025 +			#ifdef USB_SC
  1.1026 +			retValue = TDesToTUint (aDes, &uintValue);
  1.1027 +			if (epIndex < 0 || uintValue < 4096)
  1.1028 +				retValue = EFalse;
  1.1029 +			if (retValue)
  1.1030 +				{
  1.1031 +				cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iBufferSize = uintValue;
  1.1032 +				}
  1.1033 +			#else			
  1.1034 +			retValue = EFalse;
  1.1035 +			#endif
  1.1036 +			break;
  1.1037 +
  1.1038 +		case ExiReadSize:
  1.1039 +			#ifdef USB_SC
  1.1040 +			retValue = TDesToTUint (aDes, &uintValue);
  1.1041 +			if (epIndex < 0 || uintValue < 1024)
  1.1042 +				retValue = EFalse;
  1.1043 +			if (retValue)
  1.1044 +				{
  1.1045 +				cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iReadSize = uintValue;
  1.1046 +				}
  1.1047 +			#else			
  1.1048 +			retValue = EFalse;
  1.1049 +			#endif
  1.1050 +			break;
  1.1051 +		}
  1.1052 +
  1.1053 +	return retValue;
  1.1054 +	}
  1.1055 +	
  1.1056 +TInt CheckXmlKey (TPtrC aKey,TInt aLevel)
  1.1057 +	{
  1.1058 +	TInt keyIndex = -1;
  1.1059 +	
  1.1060 +	for (TInt i = xmlLevels[aLevel]; i < xmlLevels[aLevel+1]; i++)
  1.1061 +		{
  1.1062 +		if (aKey == xmlKeys[i])
  1.1063 +			{
  1.1064 +			keyIndex = i;
  1.1065 +			break;
  1.1066 +			}
  1.1067 +		}
  1.1068 +
  1.1069 +			
  1.1070 +	return keyIndex;
  1.1071 +	}
  1.1072 +
  1.1073 +TBool TDesToTUint (TPtrC aDes, TUint * aValue)
  1.1074 +	{
  1.1075 +	_LIT (KHexPrefix,"0x");
  1.1076 +	TBuf<50> numDes = aDes;
  1.1077 +	TBool hexBase = EFalse;
  1.1078 +	TBool conversionOK = ETrue;
  1.1079 +	TUint8 desIndex = 0;
  1.1080 +	* aValue = 0;
  1.1081 +	
  1.1082 +	if (numDes.LeftTPtr(((TDesC&)KHexPrefix).Length()) == KHexPrefix)
  1.1083 +		{
  1.1084 +		hexBase = ETrue;
  1.1085 +		desIndex = ((TDesC&)KHexPrefix).Length();	
  1.1086 +		}
  1.1087 +		
  1.1088 +	while (desIndex < numDes.Length() && conversionOK)
  1.1089 +		{
  1.1090 +		if (hexBase)
  1.1091 +			{
  1.1092 +			TUint maxValue = 0xFFFFFFFF >> 4;
  1.1093 +			if (((TChar)numDes[desIndex]).IsHexDigit() && * aValue <= maxValue)
  1.1094 +				{
  1.1095 +				* aValue <<= 4;
  1.1096 +				* aValue += ((TChar)numDes[desIndex]).IsDigit() ? numDes[desIndex] - '0' : ((TChar)numDes[desIndex]).GetUpperCase() - 'A' + 10;
  1.1097 +				}
  1.1098 +			else
  1.1099 +				{
  1.1100 +				conversionOK = EFalse;
  1.1101 +				* aValue = 111;
  1.1102 +				}
  1.1103 +			}
  1.1104 +		else
  1.1105 +			{
  1.1106 +			TUint maxValue = 0xFFFFFFFF / 10;
  1.1107 +			if (((TChar)numDes[desIndex]).IsDigit())
  1.1108 +				{
  1.1109 +				TUint digit = numDes[desIndex] - '0';
  1.1110 +				if ((* aValue < maxValue) || (* aValue == maxValue && digit <= 5))
  1.1111 +					{
  1.1112 +					* aValue *= 10;
  1.1113 +					* aValue += digit;
  1.1114 +					}
  1.1115 +				else
  1.1116 +					{
  1.1117 +					conversionOK = EFalse;
  1.1118 +					* aValue = 222;				
  1.1119 +					}	
  1.1120 +				}
  1.1121 +			else
  1.1122 +				{
  1.1123 +				conversionOK = EFalse;	
  1.1124 +				* aValue = 333;
  1.1125 +				}
  1.1126 +			
  1.1127 +			}
  1.1128 +		desIndex++;
  1.1129 +		}
  1.1130 +		
  1.1131 +	return conversionOK;
  1.1132 +	}
  1.1133 +
  1.1134 +TBool TDesToBool (TPtrC aDes, TBool * aValue)
  1.1135 +	{
  1.1136 +	_LIT (KBoolY,"Y");
  1.1137 +	_LIT (KBoolN,"N");
  1.1138 +	TBool conversionOK = ETrue;
  1.1139 +	TBuf<50> boolDes = aDes;
  1.1140 +	
  1.1141 +	boolDes.TrimAll();
  1.1142 +	boolDes.UpperCase();
  1.1143 +	if (boolDes == KBoolY)
  1.1144 +		{
  1.1145 +		* aValue = ETrue;
  1.1146 +		}
  1.1147 +	else
  1.1148 +		{
  1.1149 +		if (boolDes == KBoolN)
  1.1150 +			{
  1.1151 +			* aValue = EFalse;
  1.1152 +			}
  1.1153 +		else
  1.1154 +			{
  1.1155 +			conversionOK = EFalse;	
  1.1156 +			}
  1.1157 +		}
  1.1158 +		
  1.1159 +	return conversionOK;
  1.1160 +	}