os/kernelhwsrv/kerneltest/e32test/usb/t_usb_device/src/config.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // e32test/usb/t_usbdev/src/config.cpp
    15 // USB Test Program T_USB_DEVICE.
    16 // Reading and converting the XML configuration file.
    17 // 
    18 //
    19 
    20 #include "general.h"
    21 #include "config.h"
    22 
    23 _LIT(KCfgLDD,"LDD");
    24 _LIT(KCfgLDD1,"ENDPOINTS");
    25 _LIT(KCfgLDD2,"SOFTCONNECT");
    26 _LIT(KCfgLDD3,"SELFPOWER");
    27 _LIT(KCfgLDD4,"REMOTEWAKEUP");
    28 _LIT(KCfgLDD5,"HIGHSPEED");
    29 _LIT(KCfgLDD6,"FEATURES");
    30 _LIT(KCfgLDD7,"MAXPOWER");
    31 _LIT(KCfgLDD8,"EPSTALL");
    32 _LIT(KCfgLDD9,"SPEC");
    33 _LIT(KCfgLDD10,"VID");
    34 _LIT(KCfgLDD11,"PID");
    35 _LIT(KCfgLDD12,"RELEASE");
    36 _LIT(KCfgLDD13,"MANUFACTURER");
    37 _LIT(KCfgLDD14,"PRODUCT");
    38 _LIT(KCfgLDD15,"SERIALNUMBER");
    39 _LIT(KCfgLDD16,"OTG");
    40 _LIT(KCfgIF,"INTERFACE");
    41 _LIT(KCfgIFS,"ALT_SETTING");
    42 _LIT(KCfgIF1,"CLASS");
    43 _LIT(KCfgIF2,"SUBCLASS");
    44 _LIT(KCfgIF3,"PROTOCOL");
    45 _LIT(KCfgIF4,"DESCRIPTOR");
    46 _LIT(KCfgIF5,"BANDWIDTH_IN");
    47 _LIT(KCfgIF6,"BANDWIDTH_OUT");
    48 _LIT(KCfgEP,"ENDPOINT");
    49 _LIT(KCfgEP1,"SIZE");
    50 _LIT(KCfgEP2,"INTERVAL");
    51 _LIT(KCfgEP3,"HSINTERVAL");
    52 _LIT(KCfgEP4,"HSTRANSACTIONS");
    53 _LIT(KCfgEP5,"DMA");
    54 _LIT(KCfgEP6,"DOUBLEBUFF");
    55 _LIT(KCfgEP7,"EXTRA");
    56 _LIT(KCfgEP8,"BUFFERSIZE");
    57 _LIT(KCfgEP9,"READSIZE");
    58 
    59 
    60 _LIT(KAttributeName,"name=");
    61 _LIT(KAttributeNumber,"number=");
    62 _LIT(KAttributeType,"type=");
    63 _LIT(KAttributeDirection,"direction=");
    64 
    65 _LIT(KEpBulk,"\"BULK\"");
    66 _LIT(KEpInterrupt,"\"INTERRUPT\"");
    67 _LIT(KEpIsochronous,"\"ISOCHRONOUS\"");
    68 _LIT(KEpIn,"\"IN\"");
    69 _LIT(KEpOut,"\"OUT\"");
    70 
    71 static const TInt8 KMaxXMLNesting = 3;						// max 3 levels of xml nesting
    72 
    73 static const TPtrC xmlKeys[] = 
    74 	{
    75 	(TDesC&)KCfgLDD, (TDesC&)KCfgLDD1, (TDesC&)KCfgLDD2, (TDesC&)KCfgLDD3, (TDesC&)KCfgLDD4, (TDesC&)KCfgLDD5, (TDesC&)KCfgLDD6,
    76 	(TDesC&)KCfgLDD7, (TDesC&)KCfgLDD8, (TDesC&)KCfgLDD9, (TDesC&)KCfgLDD10, (TDesC&)KCfgLDD11, (TDesC&)KCfgLDD12, (TDesC&)KCfgLDD13,
    77 	(TDesC&)KCfgLDD14, (TDesC&)KCfgLDD15, (TDesC&)KCfgLDD16,
    78 	(TDesC&)KCfgIF, (TDesC&)KCfgIFS, (TDesC&)KCfgIF1, (TDesC&)KCfgIF2, (TDesC&)KCfgIF3, (TDesC&)KCfgIF4, (TDesC&)KCfgIF5, (TDesC&)KCfgIF6,
    79 	(TDesC&)KCfgEP, (TDesC&)KCfgEP1, (TDesC&)KCfgEP2, (TDesC&)KCfgEP3, (TDesC&)KCfgEP4, (TDesC&)KCfgEP5, (TDesC&)KCfgEP6, (TDesC&)KCfgEP7, (TDesC&)KCfgEP8, (TDesC&)KCfgEP9
    80 	};
    81 
    82 enum xmlIndex
    83 	{
    84 	ExiLdd = 0,						// xmlKeys index for LDD
    85 	ExiEndpoints,
    86 	ExiSoftconnect,
    87 	ExiSelfPower,
    88 	ExiRemoteWakeup,
    89 	ExiHighSpeed,
    90 	ExiFeatures,
    91 	ExiMaxPower,
    92 	ExiEpStall,
    93 	ExiSpec,
    94 	ExiVID,
    95 	ExiPID,
    96 	ExiRelease,
    97 	ExiManufacturer,
    98 	ExiProduct,
    99 	ExiSerialNumber,
   100 	ExiOTG,
   101 	ExiInterface,					// xmlKeys index for Interface
   102 	ExiSetting,						
   103 	ExiClass,
   104 	ExiSubclass,
   105 	ExiProtocol,
   106 	ExiDescriptor,
   107 	ExiBandwidthIn,
   108 	ExiBandwidthOut,
   109 	ExiEndpoint,					// xmlKeys index for Endpoint
   110 	ExiSize,
   111 	ExiInterval,
   112 	ExiHSInterval,
   113 	ExiHSTransactions,
   114 	ExiDMA,
   115 	ExiDoubleBuff,
   116 	ExiExtra,
   117 	ExiBufferSize,
   118 	ExiReadSize,
   119 	ExiLAST
   120 	};
   121 	
   122 // This array provides the index into xmlKeys for each level of xml key
   123 // the first index for level n being defined by xmlLevels[n]
   124 // and the last index for level n being defined by xmlLevels[n+1] - 1
   125 // this means this must have two more entries than the number of nesting levels
   126 // and the last entry must be the size of xmlKeys 
   127 static const TUint8 xmlLevels[] = 
   128 	{
   129 	ExiLdd,ExiLdd+1,ExiSetting+1,ExiEndpoint+1,ExiLAST
   130 	};
   131 
   132 LDDConfig::LDDConfig (TPtrC aName)
   133 	{
   134 	iPtrNext = NULL;
   135 	iIFPtr = NULL;
   136 	iName = aName;
   137 	iSoftConnect = ETrue;
   138 	iSelfPower = ETrue;
   139 	iRemoteWakeup = ETrue;
   140 	iHighSpeed = ETrue;
   141 	iEPStall = ETrue;
   142 	iNumEndpoints = 15;
   143 	iNumChannels = 0;
   144 	iFeatures = 1;
   145 	iMaxPower = 50;
   146 	iSpec = 0x0200;
   147 	iVid = 0x0E22;
   148 	iPid = 0x1111;
   149 	iRelease = 0x0305;
   150 	iManufacturer = NULL;
   151 	iProduct = NULL;
   152 	iSerialNumber = NULL;
   153 	iOtg_A = ETrue;
   154 	iOtg_altA = ETrue;
   155 	iOtg_altB = ETrue;
   156 	};
   157 
   158 IFConfig::IFConfig(TUint8 aNumber)
   159 	{
   160 	iPtrNext = NULL;
   161 	iNumber = aNumber;
   162 	iAlternateSetting = EFalse;
   163 	#ifdef USB_SC
   164 	iInfoPtr = new TUsbcScInterfaceInfo(0xFF,0xFF,0xFF);
   165 	#else
   166 	iInfoPtr = new TUsbcInterfaceInfo(0xFF,0xFF,0xFF);
   167 	iBandwidthIn = EUsbcBandwidthINDefault;
   168 	iBandwidthOut = EUsbcBandwidthOUTDefault;
   169 	#endif
   170 	}
   171 
   172 ConfigPtrs::ConfigPtrs (LDDConfigPtr * aLDDPtrPtr)
   173 	{
   174 	iNextLDDPtrPtr = aLDDPtrPtr;
   175 	iThisLDDPtr = * aLDDPtrPtr;
   176 	iThisIFPtr = NULL;
   177 	iNextIFPtrPtr = &iThisIFPtr;		// initialised to prevent warning
   178 	}
   179 
   180 extern RTest test;
   181 extern TBool gVerbose;
   182 extern TBool gSkip;
   183 extern TBool gStopOnFail;
   184 extern TInt gSoakCount;
   185 
   186 bool ProcessConfigFile (RFile aConfigFile,CConsoleBase* iConsole, LDDConfigPtr * LDDPtrPtr)
   187 	{
   188 	TUSB_PRINT ("Processing Configuration File");
   189 	
   190 	TBuf8<100> configBuf;
   191 	TBuf<101> stringBuf;
   192 	bool done = false;
   193 	bool error = false;
   194 	TInt rStatus;
   195 	XMLState state = EEmpty;
   196 	TChar nextChar(' ');
   197 	TChar lastChar(' ');
   198 	TBuf<50> keyString;
   199 	TBuf<50> endkeyString;
   200 	TBuf<50> attributeString;
   201 	TBuf<50> valueString;
   202 	TInt level = -1;
   203 	TInt levelKeys[KMaxXMLNesting+1];
   204 
   205 	* LDDPtrPtr = NULL;
   206 	ConfigPtrsPtr cpPtr = new ConfigPtrs (LDDPtrPtr); 			
   207 
   208 	while (!done && !error)
   209 		{
   210 		rStatus = aConfigFile.Read((TDes8&)configBuf);
   211 		if (rStatus != KErrNone)
   212 			{
   213 			error = true;
   214 			TUSB_PRINT1("Config file error %d", rStatus);			
   215 			}
   216 		else
   217 			{
   218 			if (configBuf.Length() == 0)
   219 				{
   220 				done = true;			
   221 				}
   222 			else
   223 				{
   224 				stringBuf.Copy(configBuf);
   225 				for (TInt i = 0; i < stringBuf.Length() && !error; i++)
   226 					{
   227 					lastChar = nextChar;
   228 					nextChar = stringBuf[i];
   229 					if (((nextChar == '<') && !((state == EEmpty) || (state == EValue))) ||
   230 						((nextChar == '>') && ((state == EEmpty) || (state == EValue))) ||
   231 						((nextChar == '/') && (lastChar != '<')))
   232 						{
   233 						error = true;
   234 						TUSB_PRINT2 ("Config File Syntax Error at index %d of %s",i,stringBuf.PtrZ());
   235 						}
   236 					switch (state)
   237 						{
   238 						case EEmpty:
   239 							if (nextChar == '<')
   240 								{
   241 								state = EStartKey;
   242 								}
   243 							else
   244 								if (!nextChar.IsSpace())
   245 									{
   246 									error = true;
   247 									TUSB_PRINT2 ("Config File Syntax Error at index %d of %s",i,stringBuf.PtrZ());
   248 									}
   249 							break;
   250 						
   251 						case EStartKey:
   252 							if (nextChar == '/')
   253 								{
   254 								state = EEndKey;
   255 								endkeyString.SetLength(0);															
   256 								}
   257 							else
   258 								{
   259 								if (nextChar == '>')
   260 									{
   261 									level++;
   262 									if (level > KMaxXMLNesting)
   263 										{
   264 										error = true;
   265 										TUSB_PRINT1 ("Config File Too Many levels %s",stringBuf.PtrZ());								
   266 										}
   267 									else
   268 										{
   269 										levelKeys[level] = CheckXmlKey (keyString,level);
   270 										if (levelKeys[level] < 0)
   271 											{
   272 											error = true;
   273 											TUSB_PRINT1 ("Invalid XML key %s",keyString.PtrZ());																	
   274 											}
   275 										else
   276 											{
   277 											if (CheckAttribute(iConsole,cpPtr,levelKeys[level],attributeString))
   278 												{
   279 												state = EValue;
   280 												TUSB_VERBOSE_PRINT2 ("Start key: %s level %d",keyString.PtrZ(),level);			
   281 												}
   282 											else
   283 												{
   284 												error = true;	
   285 												TUSB_PRINT1 ("No attribute for XML key %s",keyString.PtrZ());																	
   286 												}
   287 											}
   288 										}
   289 									}
   290 								else
   291 									{
   292 									if (lastChar == '<')
   293 										{
   294 										keyString.SetLength(0);
   295 										valueString.SetLength(0);
   296 										attributeString.SetLength(0);
   297 										if (nextChar.IsSpace())
   298 											{
   299 											error = true;
   300 											TUSB_PRINT2 ("Config File Syntax Error at index %d of %s",i,stringBuf.PtrZ());					
   301 											}
   302 										}
   303 									if (nextChar.IsSpace())
   304 										{
   305 										state = EAttribute;
   306 										}
   307 									else
   308 										{
   309 										keyString.Append(nextChar);
   310 										}
   311 									}
   312 								}
   313 							break;
   314 							
   315 						case EEndKey:
   316 							if (nextChar == '>')
   317 								{
   318 								if (levelKeys[level] != CheckXmlKey (endkeyString,level))
   319 									{
   320 									error = true;
   321 									TUSB_PRINT1 ("Invalid XML end key %s",endkeyString.PtrZ());																	
   322 									}
   323 								else
   324 									{												
   325 									if (CheckValue(iConsole,cpPtr,levelKeys[level],valueString))
   326 										{
   327 										state = EEmpty;
   328 										TUSB_VERBOSE_PRINT2 ("End Key: %s value %s",endkeyString.PtrZ(),valueString.PtrZ());
   329 										level--;
   330 										valueString.SetLength(0);
   331 										}
   332 									else
   333 										{
   334 										error = true;
   335 										TUSB_PRINT2 ("Incorrect value string %s for XML key %s",valueString.PtrZ(),endkeyString.PtrZ());	
   336 										}
   337 									}
   338 								}
   339 							if (nextChar.IsSpace())
   340 								{
   341 									error = true;
   342 									TUSB_PRINT2 ("Config File Syntax Error at index %d of %s",i,stringBuf.PtrZ());
   343 								}
   344 							else
   345 								{
   346 								endkeyString.Append(nextChar);
   347 								}
   348 							break;
   349 							
   350 						case EAttribute:
   351 							if (nextChar == '>')
   352 								{
   353 								level++;
   354 								if (level > KMaxXMLNesting)
   355 									{
   356 									error = true;
   357 									TUSB_PRINT1 ("Config File Too Many levels %s",stringBuf.PtrZ());								
   358 									}
   359 								else
   360 									{
   361 									levelKeys[level] = CheckXmlKey (keyString,level);
   362 									if (levelKeys[level] < 0)
   363 										{
   364 										error = true;
   365 										TUSB_PRINT1 ("Invalid XML key %s",keyString.PtrZ());																	
   366 										}
   367 									else
   368 										{
   369 										if (CheckAttribute(iConsole,cpPtr,levelKeys[level],attributeString))
   370 											{
   371 											state = EValue;
   372 											TUSB_VERBOSE_PRINT3 ("Start key: %s level %d attribute %s",keyString.PtrZ(),level,attributeString.PtrZ());
   373 											}
   374 										else
   375 											{
   376 											error = true;	
   377 											TUSB_PRINT2 ("Incorrect attribute %s for XML key %s",attributeString.PtrZ(),keyString.PtrZ());																	
   378 											}
   379 										}
   380 									}
   381 								}
   382 							else
   383 								{
   384 								attributeString.Append(nextChar);
   385 								}
   386 							break;
   387 							
   388 						case EValue:
   389 							if (nextChar == '<')
   390 								{
   391 								state = EStartKey;
   392 								}
   393 							else
   394 								{
   395 								// Don't add any leading spaces
   396 								if (!nextChar.IsSpace() || valueString.Length() != 0)
   397 									{
   398 									valueString.Append(nextChar);						
   399 									}
   400 								}
   401 							break;
   402 						}
   403 					}
   404 				}
   405 			}
   406 		}
   407 		
   408 	delete cpPtr;
   409 
   410 	return !error;
   411 	}
   412 
   413 
   414 	
   415 TBool CheckAttribute (CConsoleBase* iConsole, ConfigPtrsPtr cpPtr,TInt aKeyIndex, TPtrC aDes)
   416 	{
   417 	TBool retValue = ETrue;
   418 	TBuf<50> attrib = aDes;
   419 	TInt typePos;
   420 	TInt dirPos;
   421 	TInt typeLen;
   422 	TInt dirLen;
   423 	TUint epType = 0;
   424 	TUint epDir = 0;
   425 	TUint ifNumber = 0;
   426 
   427 	_LIT (KQuote,"\"");
   428 
   429 	switch (aKeyIndex)
   430 		{
   431 		// level 0 index LDD
   432 		case ExiLdd :
   433 			if (attrib.Find(KAttributeName) == 0)
   434 				{
   435 				attrib.Delete(0,((TDesC&)KAttributeName).Length());
   436 				if (attrib[0] == ((TDesC&)KQuote)[0] && attrib[attrib.Length()-1] == ((TDesC&)KQuote)[0])
   437 					{
   438 					TUSB_VERBOSE_PRINT1 ("LDD with attribute name %s",attrib.PtrZ());
   439 					cpPtr->iThisLDDPtr = new LDDConfig (attrib.MidTPtr(1,attrib.Length()-2));		
   440 					*cpPtr->iNextLDDPtrPtr = cpPtr->iThisLDDPtr;
   441 					cpPtr->iNextLDDPtrPtr = &(cpPtr->iThisLDDPtr->iPtrNext);
   442 					cpPtr->iNextIFPtrPtr = &(cpPtr->iThisLDDPtr->iIFPtr);			
   443 					}
   444 				else
   445 					retValue = EFalse;
   446 				}
   447 			else
   448 				{
   449 				retValue = EFalse;
   450 				}
   451 			break;
   452 			
   453 		//	level 1 index INTERFACE
   454 		case ExiInterface :
   455 			if (attrib.Find(KAttributeNumber) == 0)
   456 				{
   457 				attrib.Delete(0,((TDesC&)KAttributeNumber).Length());
   458 				if (attrib[0] == ((TDesC&)KQuote)[0] && attrib[attrib.Length()-1] == ((TDesC&)KQuote)[0])
   459 					{
   460 					if (TDesToTUint(attrib.MidTPtr(1,attrib.Length()-2), &ifNumber))
   461 						{
   462 						if (cpPtr->iThisLDDPtr == NULL)
   463 							{
   464 							TUSB_PRINT ("No LDD container for interface");
   465 							retValue = EFalse;				
   466 							}
   467 						}
   468 					else
   469 						{
   470 						TUSB_PRINT2 ("Number conversion error %s %d",attrib.PtrZ(),ifNumber);
   471 						retValue = EFalse;
   472 						}
   473 					}
   474 				else
   475 					{
   476 					TUSB_PRINT1 ("Attribute number not in \"\" %s",attrib.PtrZ());
   477 					retValue = EFalse;	
   478 					}
   479 				}
   480 			if (retValue)
   481 				{
   482 	 			TUSB_VERBOSE_PRINT1 ("Interface number %d",ifNumber);
   483 				cpPtr->iThisIFPtr = new IFConfig ((TUint8)ifNumber);
   484 				* cpPtr->iNextIFPtrPtr = cpPtr->iThisIFPtr;
   485 				cpPtr->iNextIFPtrPtr = &cpPtr->iThisIFPtr->iPtrNext;
   486 				cpPtr->iThisLDDPtr->iNumChannels++;
   487 				}
   488 			break;	
   489 			
   490 
   491 		//	level 1 index Setting
   492 		case ExiSetting :
   493 			if (aDes.Length() != 0)
   494 				{
   495 				retValue = EFalse;
   496 				}
   497 			else
   498 				{
   499 				if (cpPtr->iThisLDDPtr == NULL)
   500 					{
   501 					TUSB_PRINT ("No LDD container for interface");
   502 					retValue = EFalse;				
   503 					}
   504 				else
   505 					{
   506 					TUSB_VERBOSE_PRINT ("Alternate Interface Setting");			
   507 					cpPtr->iThisIFPtr = new IFConfig (0);		
   508 					* cpPtr->iNextIFPtrPtr = cpPtr->iThisIFPtr;
   509 					cpPtr->iNextIFPtrPtr = &cpPtr->iThisIFPtr->iPtrNext;
   510 					cpPtr->iThisIFPtr->iAlternateSetting = ETrue;
   511 					}					
   512 				}
   513 			break;
   514 			
   515 		//	level 2 index ENDPOINT
   516 		case ExiEndpoint :
   517 			typePos = attrib.Find(KAttributeType);
   518 			dirPos = attrib.Find(KAttributeDirection);
   519 			
   520 			if (typePos == KErrNotFound || dirPos == KErrNotFound)
   521 				{
   522 				retValue = EFalse;
   523 				}
   524 			else	
   525 				{
   526 				if (typePos < dirPos)
   527 					{
   528 					typePos += ((TDesC&)KAttributeType).Length();
   529 					typeLen = dirPos - typePos;
   530 					dirPos += ((TDesC&)KAttributeDirection).Length();
   531 					dirLen = attrib.Length() - dirPos;			
   532 					}
   533 				else
   534 					{
   535 					dirPos += ((TDesC&)KAttributeDirection).Length();			
   536 					dirLen = typePos - dirPos;
   537 					typePos += ((TDesC&)KAttributeType).Length();
   538 					typeLen = attrib.Length() - typePos;			
   539 					}
   540 				TPtr attribPtr = attrib.MidTPtr(typePos,typeLen);
   541 				attribPtr.UpperCase();
   542 				attribPtr.TrimAll();
   543 				if (attribPtr == KEpBulk)
   544 					{
   545 					epType = KUsbEpTypeBulk;
   546 					}
   547 				else
   548 					{
   549 					if (attribPtr == KEpInterrupt)
   550 						{
   551 						epType = KUsbEpTypeInterrupt;
   552 						}
   553 					else
   554 						{
   555 						if (attribPtr == KEpIsochronous)
   556 							{
   557 							epType = KUsbEpTypeIsochronous;
   558 							}
   559 						else
   560 							{
   561 							retValue = EFalse;					
   562 							}
   563 						}
   564 					}
   565 				attribPtr = attrib.MidTPtr(dirPos,dirLen);
   566 				attribPtr.UpperCase();
   567 				attribPtr.TrimAll();
   568 				if (attribPtr == KEpIn)
   569 					{
   570 					epDir = KUsbEpDirIn;
   571 					}
   572 				else
   573 					{
   574 					if (attribPtr == KEpOut)
   575 						{
   576 						epDir = KUsbEpDirOut;
   577 						}
   578 					else
   579 						{
   580 						retValue = EFalse;
   581 						}
   582 					}
   583 				if (retValue)
   584 					{
   585 					if (cpPtr->iThisIFPtr == NULL)
   586 						{
   587 						TUSB_PRINT ("No Interface container for Endpoint");
   588 						retValue = EFalse;				
   589 						}
   590 					else
   591 						{
   592 						TUint epIndex = cpPtr->iThisIFPtr->iInfoPtr->iTotalEndpointsUsed;
   593 						TUSB_VERBOSE_PRINT2 ("Endpoint with type %d %d",epType,epDir);			
   594 						cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iType = epType;
   595 						cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iDir = epDir;
   596 						#ifdef USB_SC
   597 						cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iBufferSize = 65536;
   598 						cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iReadSize = 4096;
   599 						#endif
   600 						cpPtr->iThisIFPtr->iEpDMA[epIndex] = EFalse;
   601 						cpPtr->iThisIFPtr->iEpDoubleBuff[epIndex] = EFalse;
   602 						cpPtr->iThisIFPtr->iInfoPtr->iTotalEndpointsUsed++;
   603 						}
   604 					}
   605 				}
   606 			break;
   607 		
   608 		default :
   609 			if (aDes.Length() != 0)
   610 				{
   611 				retValue = EFalse;
   612 				}
   613 		}
   614 		
   615 	return retValue;
   616 	}
   617 
   618 TBool CheckValue (CConsoleBase* iConsole, ConfigPtrsPtr cpPtr, TInt aKeyIndex, TPtrC16 aDes)
   619 	{
   620 	TBool retValue = ETrue;
   621 	TBool boolValue;
   622 	TUint uintValue;
   623 	TInt epIndex = -1;
   624 	
   625 	if (cpPtr->iThisIFPtr != NULL)
   626 		{
   627 		epIndex = cpPtr->iThisIFPtr->iInfoPtr->iTotalEndpointsUsed -1;
   628 		}
   629 		
   630 	TUSB_VERBOSE_PRINT2 ("CheckValue keyIndex %d %s",aKeyIndex,aDes.Ptr());
   631 	switch (aKeyIndex)
   632 		{
   633 		case ExiLdd:						// xmlKeys index for LDD
   634 		case ExiInterface:					// xmlKeys index for Interface
   635 		case ExiEndpoint:					// xmlKeys index for Endpoint
   636 			if (aDes.Length() != 0)
   637 				{
   638 				retValue = EFalse;
   639 				}
   640 			break;
   641 			
   642 		case ExiEndpoints:
   643 			retValue = TDesToTUint (aDes, &uintValue);
   644 			if (uintValue == 0 || uintValue > 128)
   645 				{
   646 				retValue = EFalse;			
   647 				}
   648 			else
   649 				{
   650 				cpPtr->iThisLDDPtr->iNumEndpoints = uintValue;
   651 				}
   652 			break;
   653 			
   654 		case ExiSoftconnect:
   655 			retValue = TDesToBool (aDes, &boolValue);
   656 			if (cpPtr->iThisLDDPtr == NULL)
   657 				retValue = EFalse;
   658 			if (retValue)
   659 				{
   660 				cpPtr->iThisLDDPtr->iSoftConnect = boolValue;
   661 				}
   662 			break;
   663 			
   664 		case ExiSelfPower:
   665 			retValue = TDesToBool (aDes, &boolValue);
   666 			if (cpPtr->iThisLDDPtr == NULL)
   667 				retValue = EFalse;
   668 			if (retValue)
   669 				{
   670 				cpPtr->iThisLDDPtr->iSelfPower = boolValue;
   671 				}
   672 			break;
   673 			
   674 		case ExiRemoteWakeup:
   675 			retValue = TDesToBool (aDes, &boolValue);
   676 			if (cpPtr->iThisLDDPtr == NULL)
   677 				retValue = EFalse;
   678 			if (retValue)
   679 				{
   680 				cpPtr->iThisLDDPtr->iRemoteWakeup = boolValue;
   681 				}
   682 			break;
   683 			
   684 		case ExiHighSpeed:
   685 			retValue = TDesToBool (aDes, &boolValue);
   686 			if (cpPtr->iThisLDDPtr == NULL)
   687 				retValue = EFalse;
   688 			if (retValue)
   689 				{
   690 				cpPtr->iThisLDDPtr->iHighSpeed = boolValue;
   691 				}
   692 			break;
   693 			
   694 		case ExiFeatures:
   695 			retValue = TDesToTUint (aDes, &uintValue);
   696 			if (cpPtr->iThisLDDPtr == NULL)
   697 				retValue = EFalse;
   698 			if (retValue)
   699 				{
   700 				cpPtr->iThisLDDPtr->iFeatures = uintValue;
   701 				}
   702 			break;
   703 			
   704 		case ExiMaxPower:
   705 			retValue = TDesToTUint (aDes, &uintValue);
   706 			if (cpPtr->iThisLDDPtr == NULL || uintValue > 50)
   707 				retValue = EFalse;
   708 			if (retValue)
   709 				{
   710 				cpPtr->iThisLDDPtr->iMaxPower = uintValue;
   711 				}
   712 			break;
   713 			
   714 		case ExiEpStall:
   715 			retValue = TDesToBool (aDes, &boolValue);
   716 			if (cpPtr->iThisLDDPtr == NULL)
   717 				retValue = EFalse;
   718 			if (retValue)
   719 				{
   720 				cpPtr->iThisLDDPtr->iEPStall = boolValue;
   721 				}
   722 			break;
   723 			
   724 		case ExiSpec:
   725 			retValue = TDesToTUint (aDes, &uintValue);
   726 			if (cpPtr->iThisLDDPtr == NULL)
   727 				retValue = EFalse;
   728 			if (retValue)
   729 				{
   730 				cpPtr->iThisLDDPtr->iSpec = uintValue;
   731 				}
   732 			break;
   733 			
   734 		case ExiVID:
   735 			retValue = TDesToTUint (aDes, &uintValue);
   736 			if (cpPtr->iThisLDDPtr == NULL)
   737 				retValue = EFalse;
   738 			if (retValue)
   739 				{
   740 				cpPtr->iThisLDDPtr->iVid = uintValue;
   741 				}
   742 			break;
   743 			
   744 		case ExiPID:
   745 			retValue = TDesToTUint (aDes, &uintValue);
   746 			if (cpPtr->iThisLDDPtr == NULL)
   747 				retValue = EFalse;
   748 			if (retValue)
   749 				{
   750 				cpPtr->iThisLDDPtr->iPid = uintValue;
   751 				}
   752 			break;
   753 			
   754 		case ExiRelease:
   755 			retValue = TDesToTUint (aDes, &uintValue);
   756 			if (cpPtr->iThisLDDPtr == NULL)
   757 				retValue = EFalse;
   758 			if (retValue)
   759 				{
   760 				cpPtr->iThisLDDPtr->iRelease = uintValue;
   761 				}
   762 			break;
   763 			
   764 		case ExiManufacturer:
   765 			cpPtr->iThisLDDPtr->iManufacturer = aDes.Alloc();
   766 			break;
   767 
   768 		case ExiProduct:
   769 			cpPtr->iThisLDDPtr->iProduct = aDes.Alloc();
   770 			break;
   771 
   772 		case ExiSerialNumber:
   773 			cpPtr->iThisLDDPtr->iSerialNumber = aDes.Alloc();
   774 			break;
   775 
   776 		case ExiOTG:
   777 			break;
   778 			
   779 		case ExiClass:
   780 			retValue = TDesToTUint (aDes, &uintValue);
   781 			if (cpPtr->iThisIFPtr == NULL || uintValue > 0xFF)
   782 				retValue = EFalse;
   783 			if (retValue)
   784 				{
   785 				cpPtr->iThisIFPtr->iInfoPtr->iClass.iClassNum = uintValue;
   786 				}
   787 			break;
   788 			
   789 		case ExiSubclass:
   790 			retValue = TDesToTUint (aDes, &uintValue);
   791 			if (cpPtr->iThisIFPtr == NULL || uintValue > 0xFF)
   792 				retValue = EFalse;
   793 			if (retValue)
   794 				{
   795 				cpPtr->iThisIFPtr->iInfoPtr->iClass.iSubClassNum = uintValue;
   796 				}
   797 			break;
   798 			
   799 		case ExiProtocol:
   800 			retValue = TDesToTUint (aDes, &uintValue);
   801 			if (cpPtr->iThisIFPtr == NULL || uintValue > 0xFF)
   802 				retValue = EFalse;
   803 			if (retValue)
   804 				{
   805 				cpPtr->iThisIFPtr->iInfoPtr->iClass.iProtocolNum = uintValue;
   806 				}
   807 			break;
   808 			
   809 		case ExiDescriptor:
   810 			cpPtr->iThisIFPtr->iInfoPtr->iString = aDes.Alloc();
   811 			break;
   812 			
   813 		case ExiBandwidthIn:
   814 			#ifdef USB_SC
   815 			retValue = EFalse;
   816 			#else			
   817 			retValue = TDesToTUint (aDes, &uintValue);
   818 			if (cpPtr->iThisIFPtr == NULL || uintValue > 3)
   819 				retValue = EFalse;
   820 			if (retValue)
   821 				{
   822 				switch (uintValue)
   823 					{
   824 				case 0:
   825 					cpPtr->iThisIFPtr->iBandwidthIn = EUsbcBandwidthINDefault;
   826 					break;
   827 				case 1:
   828 					cpPtr->iThisIFPtr->iBandwidthIn = EUsbcBandwidthINPlus1;
   829 					break;
   830 				case 2:
   831 					cpPtr->iThisIFPtr->iBandwidthIn = EUsbcBandwidthINPlus2;
   832 					break;
   833 				case 3:
   834 					cpPtr->iThisIFPtr->iBandwidthIn = EUsbcBandwidthINMaximum;
   835 					break;
   836 					}
   837 				}
   838 			#endif
   839 			break;
   840 			
   841 		case ExiBandwidthOut:
   842 			#ifdef USB_SC
   843 			retValue = EFalse;
   844 			#else			
   845 			retValue = TDesToTUint (aDes, &uintValue);
   846 			if (cpPtr->iThisIFPtr == NULL || uintValue > 3)
   847 				retValue = EFalse;
   848 			if (retValue)
   849 				{
   850 				switch (uintValue)
   851 					{
   852 				case 0:
   853 					cpPtr->iThisIFPtr->iBandwidthOut = EUsbcBandwidthOUTDefault;
   854 					break;
   855 				case 1:
   856 					cpPtr->iThisIFPtr->iBandwidthOut = EUsbcBandwidthOUTPlus1;
   857 					break;
   858 				case 2:
   859 					cpPtr->iThisIFPtr->iBandwidthOut = EUsbcBandwidthOUTPlus2;
   860 					break;
   861 				case 3:
   862 					cpPtr->iThisIFPtr->iBandwidthOut = EUsbcBandwidthOUTMaximum;
   863 					break;
   864 					}
   865 				}
   866 			#endif
   867 			break;
   868 			
   869 		case ExiSize:
   870 			retValue = TDesToTUint (aDes, &uintValue);
   871 			if (epIndex < 0)
   872 				retValue = EFalse;
   873 			if (retValue)
   874 				{
   875 				TBool defaultIF = cpPtr->iThisLDDPtr->iIFPtr == cpPtr->iThisIFPtr;
   876 				switch (cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iType)
   877 					{
   878 					case KUsbEpTypeBulk :
   879 						if (cpPtr->iThisLDDPtr->iHighSpeed)
   880 							{
   881 							if (uintValue != 512)
   882 								retValue = EFalse;
   883 							}
   884 						else
   885 							{
   886 							if (!(uintValue == 8 || uintValue == 16 || uintValue == 32 || uintValue == 64))
   887 								retValue = EFalse;
   888 							}
   889 						break;
   890 						
   891 					case KUsbEpTypeInterrupt :
   892 						if ((defaultIF && uintValue > 64) ||
   893 							(!cpPtr->iThisLDDPtr->iHighSpeed && uintValue > 64) ||
   894 							(!defaultIF && cpPtr->iThisLDDPtr->iHighSpeed && uintValue > 1024))
   895 							retValue = EFalse;
   896 						break;
   897 						
   898 					case KUsbEpTypeIsochronous :
   899 						if ((defaultIF && uintValue > 0) ||
   900 							(!defaultIF && !cpPtr->iThisLDDPtr->iHighSpeed && uintValue > 1023) ||
   901 							(!defaultIF && cpPtr->iThisLDDPtr->iHighSpeed && uintValue > 1024))
   902 							retValue = EFalse;
   903 						break;					
   904 					}
   905 				if (retValue)
   906 					{
   907 					cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iSize = uintValue;
   908 					}
   909 				}
   910 			
   911 			break;
   912 			
   913 		case ExiInterval:
   914 			retValue = TDesToTUint (aDes, &uintValue);
   915 			if (epIndex < 0)
   916 				retValue = EFalse;
   917 			if (retValue)
   918 				{
   919 				switch (cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iType)
   920 					{
   921 					case KUsbEpTypeBulk :
   922 						retValue = EFalse;
   923 						break;
   924 						
   925 					case KUsbEpTypeInterrupt :
   926 						if (uintValue < 1 || uintValue > 255)
   927 							retValue = EFalse;
   928 						break;
   929 						
   930 					case KUsbEpTypeIsochronous :
   931 						if (uintValue < 1 || uintValue > 16)
   932 							retValue = EFalse;
   933 						break;					
   934 					}
   935 				if (retValue)
   936 					{
   937 					cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iInterval = uintValue;
   938 					}
   939 				}
   940 			break;
   941 			
   942 		case ExiHSInterval:
   943 			retValue = TDesToTUint (aDes, &uintValue);
   944 			if (epIndex < 0 || !cpPtr->iThisLDDPtr->iHighSpeed)
   945 				retValue = EFalse;
   946 			if (retValue)
   947 				{
   948 				switch (cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iType)
   949 					{
   950 					case KUsbEpTypeBulk :
   951 						if (uintValue > 255)
   952 							retValue = EFalse;
   953 						break;
   954 						
   955 					case KUsbEpTypeInterrupt :
   956 						if (uintValue < 1 || uintValue > 16)
   957 							retValue = EFalse;
   958 						break;
   959 						
   960 					case KUsbEpTypeIsochronous :
   961 						if (uintValue < 1 || uintValue > 16)
   962 							retValue = EFalse;
   963 						break;					
   964 					}
   965 				if (retValue)
   966 					{
   967 					cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iInterval_Hs = uintValue;
   968 					}
   969 				}
   970 			break;
   971 			
   972 		case ExiHSTransactions:
   973 			retValue = TDesToTUint (aDes, &uintValue);
   974 			if (epIndex < 0 || !cpPtr->iThisLDDPtr->iHighSpeed)
   975 				retValue = EFalse;
   976 			if (retValue)
   977 				{
   978 				if (uintValue > 2)
   979 					retValue = EFalse;
   980 				if (retValue)
   981 					{
   982 					cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iTransactions = uintValue;
   983 					}
   984 				}
   985 			break;
   986 			
   987 		case ExiDMA:
   988 			retValue = TDesToBool (aDes, &boolValue);
   989 			if (epIndex < 0)
   990 				retValue = EFalse;
   991 			if (retValue)
   992 				{
   993 				cpPtr->iThisIFPtr->iEpDMA[epIndex] = boolValue;
   994 				}
   995 			break;
   996 			
   997 		case ExiDoubleBuff:
   998 			#ifdef USB_SC
   999 			retValue = EFalse;
  1000 			#else
  1001 			retValue = TDesToBool (aDes, &boolValue);
  1002 			if (epIndex < 0)
  1003 				retValue = EFalse;
  1004 			if (retValue)
  1005 				{
  1006 				cpPtr->iThisIFPtr->iEpDoubleBuff[epIndex] = boolValue;
  1007 				}
  1008 			#endif
  1009 			break;
  1010 			
  1011 		case ExiExtra:
  1012 			retValue = TDesToTUint (aDes, &uintValue);
  1013 			if (epIndex < 0)
  1014 				retValue = EFalse;
  1015 			if (retValue)
  1016 				{
  1017 				cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iExtra = uintValue;
  1018 				}
  1019 			break;
  1020 
  1021 		case ExiBufferSize:
  1022 			#ifdef USB_SC
  1023 			retValue = TDesToTUint (aDes, &uintValue);
  1024 			if (epIndex < 0 || uintValue < 4096)
  1025 				retValue = EFalse;
  1026 			if (retValue)
  1027 				{
  1028 				cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iBufferSize = uintValue;
  1029 				}
  1030 			#else			
  1031 			retValue = EFalse;
  1032 			#endif
  1033 			break;
  1034 
  1035 		case ExiReadSize:
  1036 			#ifdef USB_SC
  1037 			retValue = TDesToTUint (aDes, &uintValue);
  1038 			if (epIndex < 0 || uintValue < 1024)
  1039 				retValue = EFalse;
  1040 			if (retValue)
  1041 				{
  1042 				cpPtr->iThisIFPtr->iInfoPtr->iEndpointData[epIndex].iReadSize = uintValue;
  1043 				}
  1044 			#else			
  1045 			retValue = EFalse;
  1046 			#endif
  1047 			break;
  1048 		}
  1049 
  1050 	return retValue;
  1051 	}
  1052 	
  1053 TInt CheckXmlKey (TPtrC aKey,TInt aLevel)
  1054 	{
  1055 	TInt keyIndex = -1;
  1056 	
  1057 	for (TInt i = xmlLevels[aLevel]; i < xmlLevels[aLevel+1]; i++)
  1058 		{
  1059 		if (aKey == xmlKeys[i])
  1060 			{
  1061 			keyIndex = i;
  1062 			break;
  1063 			}
  1064 		}
  1065 
  1066 			
  1067 	return keyIndex;
  1068 	}
  1069 
  1070 TBool TDesToTUint (TPtrC aDes, TUint * aValue)
  1071 	{
  1072 	_LIT (KHexPrefix,"0x");
  1073 	TBuf<50> numDes = aDes;
  1074 	TBool hexBase = EFalse;
  1075 	TBool conversionOK = ETrue;
  1076 	TUint8 desIndex = 0;
  1077 	* aValue = 0;
  1078 	
  1079 	if (numDes.LeftTPtr(((TDesC&)KHexPrefix).Length()) == KHexPrefix)
  1080 		{
  1081 		hexBase = ETrue;
  1082 		desIndex = ((TDesC&)KHexPrefix).Length();	
  1083 		}
  1084 		
  1085 	while (desIndex < numDes.Length() && conversionOK)
  1086 		{
  1087 		if (hexBase)
  1088 			{
  1089 			TUint maxValue = 0xFFFFFFFF >> 4;
  1090 			if (((TChar)numDes[desIndex]).IsHexDigit() && * aValue <= maxValue)
  1091 				{
  1092 				* aValue <<= 4;
  1093 				* aValue += ((TChar)numDes[desIndex]).IsDigit() ? numDes[desIndex] - '0' : ((TChar)numDes[desIndex]).GetUpperCase() - 'A' + 10;
  1094 				}
  1095 			else
  1096 				{
  1097 				conversionOK = EFalse;
  1098 				* aValue = 111;
  1099 				}
  1100 			}
  1101 		else
  1102 			{
  1103 			TUint maxValue = 0xFFFFFFFF / 10;
  1104 			if (((TChar)numDes[desIndex]).IsDigit())
  1105 				{
  1106 				TUint digit = numDes[desIndex] - '0';
  1107 				if ((* aValue < maxValue) || (* aValue == maxValue && digit <= 5))
  1108 					{
  1109 					* aValue *= 10;
  1110 					* aValue += digit;
  1111 					}
  1112 				else
  1113 					{
  1114 					conversionOK = EFalse;
  1115 					* aValue = 222;				
  1116 					}	
  1117 				}
  1118 			else
  1119 				{
  1120 				conversionOK = EFalse;	
  1121 				* aValue = 333;
  1122 				}
  1123 			
  1124 			}
  1125 		desIndex++;
  1126 		}
  1127 		
  1128 	return conversionOK;
  1129 	}
  1130 
  1131 TBool TDesToBool (TPtrC aDes, TBool * aValue)
  1132 	{
  1133 	_LIT (KBoolY,"Y");
  1134 	_LIT (KBoolN,"N");
  1135 	TBool conversionOK = ETrue;
  1136 	TBuf<50> boolDes = aDes;
  1137 	
  1138 	boolDes.TrimAll();
  1139 	boolDes.UpperCase();
  1140 	if (boolDes == KBoolY)
  1141 		{
  1142 		* aValue = ETrue;
  1143 		}
  1144 	else
  1145 		{
  1146 		if (boolDes == KBoolN)
  1147 			{
  1148 			* aValue = EFalse;
  1149 			}
  1150 		else
  1151 			{
  1152 			conversionOK = EFalse;	
  1153 			}
  1154 		}
  1155 		
  1156 	return conversionOK;
  1157 	}