supl/locationomasuplprotocolhandler/protocolhandlerver1/src/epos_comasuplfallbackhandler.cpp
changeset 0 667063e416a2
child 22 4c4ed41530db
child 23 5944cae565c9
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Class for handling fallback in case of multiple SLP
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "epos_csuplsettingsinternal.h"
       
    21 #include "epos_comasuplfallbackhandler.h"
       
    22 #include "epos_omasuplconstants.h"
       
    23 #include "epos_momasuplconnobserver.h"
       
    24 #include "epos_comasupltrace.h"
       
    25 #include "epos_csuplsettingparams.h"
       
    26 #include "epos_csuplsettingextensionparams.h"
       
    27 #include "epos_csuplsettingsinternalconstants.h"
       
    28 
       
    29 #include <networking/dnd_err.h>   //Error codes
       
    30 #include <etelpckt.h> //Error codes
       
    31 #include <exterror.h>
       
    32 
       
    33 _LIT(KTraceFileName,"SUPL_OMA_SESSION::epos_comasuplfallbackhandler.cpp");
       
    34 
       
    35 
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // COMASuplFallBackHandler::COMASuplFallBackHandler
       
    41 // C++ constructor can NOT contain any code, that might leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 COMASuplFallBackHandler::COMASuplFallBackHandler(CSuplSettingsInternal& aSettings):
       
    45 												iSuplSettings(aSettings)
       
    46     {
       
    47 
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // COMASuplFallBackHandler::ConstructL
       
    52 // Symbian 2nd phase constructor can leave.
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 void COMASuplFallBackHandler::ConstructL()
       
    56     {
       
    57     	iCurrentServerCounter = 0;
       
    58     	iTLSAuthenticationFailed = EFalse;
       
    59     	iErrorCode = KErrNone;
       
    60     	
       
    61     	iSLPList = new (ELeave) CArrayFixFlat<TSLPDetails>(16);
       
    62     	
       
    63     	iTrace = COMASuplTrace::NewL();
       
    64 		
       
    65 		 TInt err = iSuplSettings.GetFallBackTimerValue(iAllowedFallBackTimerValue);
       
    66 		 
       
    67 		 if(err != KErrNone)
       
    68 		 	{
       
    69 		 		iAllowedFallBackTimerValue = 200000000;
       
    70 		 	}
       
    71 		 	
       
    72 		TBuf<64> buffer(_L("Fallback Timer Value in Seconds : "));
       
    73 		buffer.AppendNum(iAllowedFallBackTimerValue);
       
    74 		iTrace->Trace(buffer,KTraceFileName, __LINE__); 				
       
    75 
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // COMASuplFallBackHandler::NewL
       
    80 // Two-phased constructor.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 COMASuplFallBackHandler* COMASuplFallBackHandler::NewL( CSuplSettingsInternal& aSettings)
       
    84     {
       
    85 	    COMASuplFallBackHandler* self =  new ( ELeave ) COMASuplFallBackHandler(aSettings);
       
    86 	    CleanupStack::PushL( self );
       
    87 	    self->ConstructL();
       
    88 	    CleanupStack::Pop(self);
       
    89 	    return self;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // COMASuplFallBackHandler::COMASuplFallBackHandler
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 COMASuplFallBackHandler::~COMASuplFallBackHandler()
       
    97     {
       
    98     	delete iTrace;
       
    99     	if(iSLPList)
       
   100     	    {
       
   101     	    iSLPList->Reset();
       
   102     	    }
       
   103     	delete iSLPList;
       
   104     	iSLPList=NULL;
       
   105     	iGenratedHslpAddress.Close();
       
   106     	iDefaultIAPName.Close();
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // COMASuplFallBackHandler::GetNextSLPAddressL
       
   111 // -----------------------------------------------------------------------------
       
   112 //    TODO: Merge if conditions...
       
   113 TInt COMASuplFallBackHandler::GetNextSLPAddressL(TInt64& aSLPId, TDes& aHslpToBeUsedAddress,TDes& aIAPName,TBool& aTls,
       
   114                                                  TBool& aPskTls,TInt aLastErrorCode,TBool& aIsIapDialogShown)
       
   115     {
       
   116     _LIT(KFormatTxt,"%/0%1%/1%2%/2%3%/3 %-B%:0%J%:1%T%:2%S%:3%+B"); 
       
   117     
       
   118     TBuf<256> LogBuffer;
       
   119     
       
   120      if( aLastErrorCode != KErrNone)// If its KErrNone then its means server name is asked first time and no need for Tls failure check
       
   121     	{
       
   122     	
       
   123     	if( CheckErrorCodeL(aLastErrorCode) )
       
   124         	{
       
   125         
       
   126         	if( iTLSAuthenticationFailed )
       
   127         		{
       
   128         		if(iErrorCode == KErrNone)
       
   129             		{	
       
   130             		aHslpToBeUsedAddress.Copy(iGenratedHslpAddress);
       
   131             		aIAPName.Zero();   
       
   132             		aIAPName.Copy(iDefaultIAPName);
       
   133             		aTls = ETrue;
       
   134             		aPskTls = EFalse;
       
   135             		aIsIapDialogShown = ETrue;
       
   136                                 
       
   137             		iTrace->Trace(_L("Fallback allowed & TLSAuth failed"),KTraceFileName, __LINE__);
       
   138             		iTrace->Trace(_L("Server being used:"),KTraceFileName, __LINE__);
       
   139             		LogBuffer.Copy(aHslpToBeUsedAddress);
       
   140             		iTrace->Trace(LogBuffer,KTraceFileName, __LINE__);
       
   141                                                                         
       
   142             		iTrace->Trace(_L("iap being used:"),KTraceFileName, __LINE__);
       
   143             		LogBuffer.Copy(aIAPName);
       
   144             		iTrace->Trace(LogBuffer,KTraceFileName, __LINE__);
       
   145                                                                         
       
   146             		iTrace->Trace(_L("iap dlg configuration:"),KTraceFileName, __LINE__);
       
   147             		LogBuffer.Delete(0,256);
       
   148             		LogBuffer.AppendNum(aIsIapDialogShown);
       
   149             		iTrace->Trace(LogBuffer,KTraceFileName, __LINE__);
       
   150             		return KErrNone;
       
   151             		}
       
   152         		else
       
   153             		{
       
   154             		return KErrArgument;        
       
   155             		}
       
   156             	}
       
   157        	 	}
       
   158         
       
   159      	else
       
   160 	     	{
       
   161 	     	return KErrNotFound;
       
   162 	     	}  
       
   163 	 	} 
       
   164     
       
   165     if( iSLPList->Count() <= 0 || iCurrentServerCounter >= iSLPList->Count() ) 
       
   166         {
       
   167         LogBuffer.Copy(_L("No more servers available..."));
       
   168         iTrace->Trace(LogBuffer,KTraceFileName, __LINE__); 				
       
   169         return KErrNotFound;
       
   170         }
       
   171              
       
   172     iTrace->Trace(_L("Trying next server..."),KTraceFileName, __LINE__); 				
       
   173              
       
   174     //Fallback Timer...
       
   175     if(aLastErrorCode == KErrNone) //This means, server name is asked for first time only...
       
   176         {
       
   177         iTrace->Trace(_L("Start Time: "),KTraceFileName, __LINE__); 				
       
   178         iFallBackStartTime.HomeTime();
       
   179         LogBuffer.Zero();
       
   180         iFallBackStartTime.FormatL(LogBuffer,KFormatTxt); 
       
   181         iTrace->Trace(LogBuffer,KTraceFileName, __LINE__); 				
       
   182         }
       
   183     else
       
   184         {
       
   185         TTime currentTime;
       
   186         currentTime.HomeTime();
       
   187         TTimeIntervalMicroSeconds diff = currentTime.MicroSecondsFrom(iFallBackStartTime); 
       
   188                         
       
   189                         
       
   190         iTrace->Trace(_L("Current Time: "),KTraceFileName, __LINE__); 				
       
   191         LogBuffer.Zero();
       
   192         currentTime.FormatL(LogBuffer,KFormatTxt); 
       
   193         iTrace->Trace(LogBuffer,KTraceFileName, __LINE__); 				
       
   194                         
       
   195         LogBuffer.Copy(_L("Difference between time: "));
       
   196         LogBuffer.AppendNum(diff.Int64());
       
   197         iTrace->Trace(LogBuffer,KTraceFileName, __LINE__); 				
       
   198                         
       
   199         if( diff.Int64() > iAllowedFallBackTimerValue)	
       
   200             {
       
   201             LogBuffer.Copy(_L("Timeout happened..."));
       
   202             iTrace->Trace(LogBuffer,KTraceFileName, __LINE__); 		
       
   203             
       
   204             return KErrTimedOut;
       
   205             }
       
   206         }	
       
   207                 
       
   208     if(aLastErrorCode == KErrNone)  //This will be called only once...for first time only
       
   209         {
       
   210         aSLPId = (*iSLPList)[0].iSLPId;
       
   211         aHslpToBeUsedAddress.Copy((*iSLPList)[0].iHSLPAddress);
       
   212         aIAPName.Copy((*iSLPList)[0].iIapName);
       
   213         aTls = (*iSLPList)[0].iTls;
       
   214         aPskTls = (*iSLPList)[0].iPskTls;
       
   215         aIsIapDialogShown = (*iSLPList)[0].iIsIAPDialgShown;
       
   216         iCurrentServerCounter++;				
       
   217                     
       
   218         iTrace->Trace(_L("Server being used:"),KTraceFileName, __LINE__);
       
   219         LogBuffer.Copy(aHslpToBeUsedAddress);
       
   220         iTrace->Trace(LogBuffer,KTraceFileName, __LINE__);
       
   221                     
       
   222         iTrace->Trace(_L("iap being used:"),KTraceFileName, __LINE__);
       
   223         LogBuffer.Copy(aIAPName);
       
   224         iTrace->Trace(LogBuffer,KTraceFileName, __LINE__);
       
   225                     
       
   226         iTrace->Trace(_L("iap dlg configuration:"),KTraceFileName, __LINE__);
       
   227         LogBuffer.Delete(0,256);
       
   228         LogBuffer.AppendNum(aIsIapDialogShown);
       
   229         iTrace->Trace(LogBuffer,KTraceFileName, __LINE__);
       
   230                     
       
   231         return KErrNone;
       
   232         }
       
   233     else
       
   234         {
       
   235         if(iIsFallBackAllowed && CheckErrorCodeL(aLastErrorCode))// Do not fallback in case if IMSI generated address failed for previous try.
       
   236             {
       
   237             aSLPId = (*iSLPList)[iCurrentServerCounter].iSLPId;	
       
   238             aHslpToBeUsedAddress.Copy((*iSLPList)[iCurrentServerCounter].iHSLPAddress);
       
   239             aIAPName.Copy((*iSLPList)[iCurrentServerCounter].iIapName);    			
       
   240             aTls = (*iSLPList)[iCurrentServerCounter].iTls;
       
   241             aPskTls = (*iSLPList)[iCurrentServerCounter].iPskTls;
       
   242             aIsIapDialogShown = (*iSLPList)[iCurrentServerCounter].iIsIAPDialgShown;
       
   243             iCurrentServerCounter++;
       
   244             iTrace->Trace(_L("Fallback allowed & TLSAuth passed"),KTraceFileName, __LINE__);
       
   245             iTrace->Trace(_L("Server being used:"),KTraceFileName, __LINE__);
       
   246             LogBuffer.Copy(aHslpToBeUsedAddress);
       
   247             iTrace->Trace(LogBuffer,KTraceFileName, __LINE__);
       
   248                                                                    
       
   249             iTrace->Trace(_L("iap being used:"),KTraceFileName, __LINE__);
       
   250             LogBuffer.Copy(aIAPName);
       
   251             iTrace->Trace(LogBuffer,KTraceFileName, __LINE__);
       
   252                                                                     
       
   253             iTrace->Trace(_L("iap dlg configuration:"),KTraceFileName, __LINE__);
       
   254             LogBuffer.Delete(0,256);
       
   255             LogBuffer.AppendNum(aIsIapDialogShown);
       
   256             iTrace->Trace(LogBuffer,KTraceFileName, __LINE__);
       
   257             return KErrNone;
       
   258             }
       
   259         else
       
   260             {
       
   261             return KErrNotFound;
       
   262             }
       
   263         }
       
   264                     
       
   265     }
       
   266     
       
   267 // -----------------------------------------------------------------------------
       
   268 // COMASuplFallBackHandler::CheckErrorCodeL
       
   269 // -----------------------------------------------------------------------------
       
   270 //    
       
   271 TBool COMASuplFallBackHandler::CheckErrorCodeL(TInt aLastErrorCode)
       
   272 {
       
   273 	   if(iTLSAuthenticationFailed)
       
   274 		{
       
   275 			iTrace->Trace(_L("IMSI Generated SLP also failed after TLS faliure for previous SLP..."), KTraceFileName, __LINE__); 				
       
   276 			return EFalse;		
       
   277 				
       
   278 		}
       
   279 		if ( (aLastErrorCode >= KErrSSLAlertNoRenegotiation ) && (aLastErrorCode <= KErrSSLAlertCloseNotify)  && !iTLSAuthenticationFailed )
       
   280 		{
       
   281 			iTrace->Trace(_L("TLS Authentication Failed..."), KTraceFileName, __LINE__); 				
       
   282 			iTLSAuthenticationFailed = ETrue;	
       
   283 			GenerateHslpAddressFromIMSIL();
       
   284 			return ETrue;
       
   285 		}
       
   286 		
       
   287 		if ( (aLastErrorCode >= KErrDndServerUnusable ) && (aLastErrorCode <= KErrDndNameNotFound) )
       
   288 		{
       
   289 			iTrace->Trace(_L("DNS Error..."), KTraceFileName, __LINE__); 				
       
   290 			return ETrue;		
       
   291 		}
       
   292 		
       
   293 		if ( (aLastErrorCode >= KErrUrgentData  ) && (aLastErrorCode <= KErrNetUnreach ) )
       
   294 		{
       
   295 			iTrace->Trace(_L("Sockets Error..."), KTraceFileName, __LINE__); 				
       
   296 			return ETrue;		
       
   297 		}
       
   298 
       
   299 		if  (aLastErrorCode == KErrCouldNotConnect  )
       
   300 		{
       
   301 			iTrace->Trace(_L("Could not connect to Server..."), KTraceFileName, __LINE__); 				
       
   302 			return ETrue;		
       
   303 		}
       
   304 
       
   305 		if  (aLastErrorCode == KErrSuplTimeout  )
       
   306 		{
       
   307 			iTrace->Trace(_L("Timeout for DNS/TLS operation..."), KTraceFileName, __LINE__); 				
       
   308 			return ETrue;		
       
   309 		}
       
   310 		
       
   311 		if( aLastErrorCode == KErrGsmMMServiceOptionNotSubscribed )
       
   312 		{
       
   313 		   iTrace->Trace(_L("GSM MM Service Option Not Subscribed ..."), KTraceFileName, __LINE__);                 
       
   314 		   return ETrue;  
       
   315 	    }
       
   316 		
       
   317 		if ( (aLastErrorCode >= KErrGprsFeatureNotSupported ) && (aLastErrorCode <= KErrGsmRRUnspecifedAbnormalRelease) )
       
   318 		{
       
   319 			iTrace->Trace(_L("GPRS Service is not allowed/rejected/not supported..."), KTraceFileName, __LINE__); 				
       
   320 			return EFalse;	
       
   321 		}
       
   322 
       
   323 		
       
   324 
       
   325 	return EFalse;
       
   326 }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // COMASuplFallBackHandler::ReadSLPListL
       
   330 // -----------------------------------------------------------------------------
       
   331 //    
       
   332 void COMASuplFallBackHandler::ReadSLPListL(const TDesC& aClientProvidedHSLPAddress)
       
   333 {
       
   334 	  	RPointerArray<CServerParams> SLPList;
       
   335 	  
       
   336 		TBool isSLPEntryExist = EFalse;
       
   337 		
       
   338     	TBool serverEnabled,simChangeRemove,usageInHomeNw,editable;
       
   339     	
       
   340 		TInt err = iSuplSettings.GetAllSlp(SLPList);
       
   341 		TInt cnt = SLPList.Count();
       
   342 		
       
   343 		TSLPDetails	 SlpEntry;
       
   344 		TSLPDetails  FirstSlpEntry;
       
   345 		HBufC* dmConfigurableIapFirstEntry =  HBufC::NewL(KMaxIapNameLength);
       
   346 		TPtr dmConfigIap(NULL,KMaxIapNameLength);
       
   347 		dmConfigIap.Set(dmConfigurableIapFirstEntry->Des());
       
   348 		HBufC* hslpAddress =  HBufC::NewL(KHSLPAddressLength);       
       
   349 		HBufC* iapName =  HBufC::NewL(KMaxIapNameLength);   
       
   350 		HBufC* dmConfigurableIapName =  HBufC::NewL(KMaxIapNameLength); 
       
   351 		
       
   352 		HBufC* serverid =  HBufC::NewL(KMaxServerIdLen); 
       
   353 		HBufC* iap2 =  HBufC::NewL(KMaxIapNameLength); 
       
   354 		HBufC* serveradd =  HBufC::NewL(KMaxServerAddLen); 
       
   355 		HBufC* serveraddtype =  HBufC::NewL(KMaxServerAddTypeLen); 
       
   356 		
       
   357 		iSLPList->Reset(); // Reset the list
       
   358 		for(TInt i = 0; i < cnt; i++ )
       
   359 		{
       
   360 				TInt64 SLPId;	
       
   361 			   	CServerParams* params = SLPList[i];
       
   362 			   	params->Get(SLPId,hslpAddress->Des(),iapName->Des(),serverEnabled,simChangeRemove,usageInHomeNw,editable);
       
   363 			   	
       
   364 			   	CServerExtensionParams* extnparams = CServerExtensionParams::NewL();
       
   365 			   	TInt err = iSuplSettings.GetServerExtensionParams(SLPId,extnparams); // Ignore error
       
   366 			   	extnparams->Get(serverid->Des(),dmConfigurableIapName->Des(),iap2->Des(),serveradd->Des(),serveraddtype->Des() );
       
   367 			   	
       
   368 		   	    delete extnparams; 
       
   369 			   	SlpEntry.iHSLPAddress.LowerCase();
       
   370 			   	
       
   371 			   	TBuf<KHSLPAddressLength> clientHSLP;
       
   372 			   	clientHSLP.Copy(aClientProvidedHSLPAddress);
       
   373 			   	clientHSLP.LowerCase();
       
   374 			   	
       
   375 			   	SlpEntry.iSLPId = SLPId;
       
   376 			   	SlpEntry.iHSLPAddress.Copy(hslpAddress->Des());
       
   377 			   	SlpEntry.iIapName.Copy(iapName->Des());
       
   378 			   	SlpEntry.iIapName.LowerCase();
       
   379 			   	SlpEntry.iHomeNetworkUsage = usageInHomeNw;
       
   380 			   	
       
   381 			   	iSuplSettings.GetTlsFlag(SLPId,SlpEntry.iTls);
       
   382 			   	iSuplSettings.GetPskTlsFlag(SLPId,SlpEntry.iPskTls);
       
   383 			   	SlpEntry.iHSLPAddress.LowerCase();
       
   384 			   	SlpEntry.iIsIAPDialgShown=ETrue;//To identify its a entry with primary iap
       
   385 
       
   386 
       
   387 		   	if(!isSLPEntryExist && (SlpEntry.iHSLPAddress.Compare(clientHSLP) == KErrNone) )// Client provided SLP will be on top of list.
       
   388 		   	{
       
   389 		   		if(serverEnabled)   // Following is to handle specical case where client specified SLP is disabled and fallback not allowed...
       
   390 				{
       
   391 				 FirstSlpEntry = SlpEntry;
       
   392 				 // Store the 2ndary iap if exists
       
   393 				if( dmConfigurableIapName->Length() > 0 )
       
   394 				    {
       
   395 				    dmConfigIap=dmConfigurableIapName->Des();
       
   396 				    }
       
   397 				else
       
   398 				    {
       
   399 				    dmConfigIap.Zero();
       
   400 				    }
       
   401 				
       
   402 				isSLPEntryExist = ETrue;
       
   403 				} 		
       
   404         		  else
       
   405 				  {
       
   406 						if(iIsFallBackAllowed)
       
   407 						{
       
   408 							continue;
       
   409 						}
       
   410 			   		  	else
       
   411 			   		  	{
       
   412 			   		  			isSLPEntryExist = EFalse;
       
   413 			   		  			iSLPList->Reset();
       
   414 			   		  			break;
       
   415 			   		  	}
       
   416                   } 	
       
   417 		   	}
       
   418 		   	else
       
   419 		   	{
       
   420 		   		if(serverEnabled)
       
   421 		   		{
       
   422 				iSLPList->AppendL(SlpEntry);
       
   423 				if( dmConfigurableIapName->Length() > 0 )
       
   424                     {
       
   425                     // Replace default iap field with 2ndary iap field
       
   426                     SlpEntry.iIapName.Copy(dmConfigurableIapName->Des());
       
   427                     SlpEntry.iIapName.LowerCase();
       
   428                     // Set IapDialog flag to false for entry with secondary iap
       
   429                     SlpEntry.iIsIAPDialgShown=EFalse;
       
   430                     // Append this entry to the list
       
   431                     iSLPList->AppendL(SlpEntry);
       
   432                     }
       
   433 							
       
   434 				}	
       
   435 			}
       
   436 				
       
   437 		}
       
   438 		
       
   439 		if(isSLPEntryExist)
       
   440 		{
       
   441 		iSLPList->InsertL(0,FirstSlpEntry);
       
   442 		if( dmConfigIap.Length() > 0 )
       
   443 		    {
       
   444 		    FirstSlpEntry.iIapName.Copy(dmConfigIap);
       
   445 		    SlpEntry.iIapName.LowerCase();
       
   446 		    FirstSlpEntry.iIsIAPDialgShown=EFalse;
       
   447 		    iSLPList->AppendL(FirstSlpEntry);
       
   448 		    }
       
   449 		}
       
   450 			
       
   451 		delete serverid;
       
   452 		delete iap2;
       
   453 		delete serveradd;
       
   454 		delete serveraddtype;
       
   455 		
       
   456 		delete dmConfigurableIapFirstEntry;
       
   457 		delete hslpAddress;
       
   458 		delete iapName;
       
   459 		delete dmConfigurableIapName;
       
   460 			
       
   461 		SLPList.ResetAndDestroy();
       
   462 		
       
   463 		SLPList.Close();
       
   464 		
       
   465 }
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 // COMASuplFallBackHandler::GenerateHslpAddressFromIMSIL
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 void COMASuplFallBackHandler::GenerateHslpAddressFromIMSIL()
       
   472 	{
       
   473 	    iGenratedHslpAddress.Close();
       
   474 	    iDefaultIAPName.Close();
       
   475 	    iGenratedHslpAddress.CreateL(KHSLPAddressLength);
       
   476 	    iDefaultIAPName.CreateL(KMaxIapNameLength);
       
   477 		TInt err = iSuplSettings.GenerateHslpAddressFromImsi(iGenratedHslpAddress);
       
   478 		if(err != KErrNone)
       
   479 			{
       
   480 				iTrace->Trace(_L("GenerateHslpAddressFromImsi Failed..."), KTraceFileName, __LINE__); 				
       
   481 				iErrorCode = err;				
       
   482 			}
       
   483 		else
       
   484 			{
       
   485 				TBuf<256> msg(_L("New Generated H-SLP address: "));
       
   486 				msg.Append(iGenratedHslpAddress);
       
   487 				iTrace->Trace(msg, KTraceFileName, __LINE__); 		
       
   488 				iErrorCode = KErrNone;
       
   489 				err = iSuplSettings.GetDefaultIAPName(iDefaultIAPName);
       
   490 				if(err != KErrNone)
       
   491 				    {
       
   492                     iTrace->Trace(_L("GetDefaultIAPName Failed..."), KTraceFileName, __LINE__);               
       
   493                     iErrorCode = err;
       
   494 				    }
       
   495 				else
       
   496 				    {
       
   497 				    msg.Copy(iDefaultIAPName);
       
   498                     iTrace->Trace(msg, KTraceFileName, __LINE__);       
       
   499                     iErrorCode = KErrNone;
       
   500 				    }
       
   501 			}
       
   502 	}
       
   503 
       
   504 // -----------------------------------------------------------------------------
       
   505 // COMASuplFallBackHandler::SetFallBackParametersL
       
   506 // -----------------------------------------------------------------------------
       
   507 //
       
   508 void COMASuplFallBackHandler::SetFallBackParametersL(const TDesC& aClientProvidedHSLPAddress,TBool aFallBackAllowed)
       
   509 	{
       
   510 		
       
   511 		TBool userSetFallback = ETrue;
       
   512 		iSuplSettings.GetFallBack(userSetFallback);		
       
   513 		iIsFallBackAllowed = aFallBackAllowed & userSetFallback;
       
   514 		
       
   515 		TBuf<64> buffer(_L("Final Fallback Value... "));
       
   516 		buffer.AppendNum(iIsFallBackAllowed);
       
   517 		iTrace->Trace(buffer,KTraceFileName, __LINE__); 	
       
   518 		
       
   519 		ReadSLPListL(aClientProvidedHSLPAddress);			
       
   520 		// Reset the counter
       
   521 		iCurrentServerCounter=0;
       
   522 		
       
   523 		PrintSLPList();
       
   524 	}
       
   525 	
       
   526 // -----------------------------------------------------------------------------
       
   527 // COMASuplFallBackHandler::PrintSLPList()
       
   528 // -----------------------------------------------------------------------------
       
   529 //
       
   530 void COMASuplFallBackHandler::PrintSLPList()
       
   531 {
       
   532 //This function can be put under debug flag...	
       
   533 	TBuf<256> hslpAddress;
       
   534 	TBuf<100> accessPoint;
       
   535 	TInt64 slpid;
       
   536 	TBool Psk,Tls,HomeUsage;
       
   537 	TBuf<256> buffer;
       
   538 	TInt cnt = iSLPList->Count();	
       
   539 	
       
   540 	buffer.Copy(_L("Number of Entries : "));
       
   541 	buffer.AppendNum(cnt);
       
   542 	iTrace->Trace(buffer,KTraceFileName, __LINE__); 	
       
   543 	
       
   544 	for(TInt Counter = 0; Counter < cnt; Counter++)
       
   545 	{
       
   546 				slpid = (*iSLPList)[Counter].iSLPId;	
       
   547 				hslpAddress.Copy((*iSLPList)[Counter].iHSLPAddress);
       
   548 				accessPoint.Copy((*iSLPList)[Counter].iIapName);    			
       
   549 				Tls = (*iSLPList)[Counter].iTls;
       
   550 				Psk = (*iSLPList)[Counter].iPskTls;
       
   551 				HomeUsage = (*iSLPList)[Counter].iHomeNetworkUsage;
       
   552 				
       
   553 				buffer.Copy(_L("==================================="));
       
   554 				iTrace->Trace(buffer,KTraceFileName, __LINE__); 	
       
   555 				
       
   556 				buffer.Copy(_L("SLP id : "));
       
   557 				buffer.AppendNum(slpid);
       
   558 				iTrace->Trace(buffer,KTraceFileName, __LINE__); 	
       
   559 				
       
   560 				buffer.Copy(_L("Server Name: "));
       
   561 				buffer.Append(hslpAddress);
       
   562 				iTrace->Trace(buffer,KTraceFileName, __LINE__); 	
       
   563 				
       
   564 				buffer.Copy(_L("Access Point: "));
       
   565 				buffer.Append(accessPoint);
       
   566 				iTrace->Trace(buffer,KTraceFileName, __LINE__); 	
       
   567 				
       
   568 				buffer.Copy(_L("TLS : "));
       
   569 				buffer.AppendNum(Tls);
       
   570 				iTrace->Trace(buffer,KTraceFileName, __LINE__); 	
       
   571 				
       
   572 				buffer.Copy(_L("PSK TLS : "));
       
   573 				buffer.AppendNum(Psk);
       
   574 				iTrace->Trace(buffer,KTraceFileName, __LINE__); 	
       
   575 				
       
   576 				buffer.Copy(_L("Home Usage : "));
       
   577 				buffer.AppendNum(HomeUsage);
       
   578 				iTrace->Trace(buffer,KTraceFileName, __LINE__); 	
       
   579 				
       
   580 	}
       
   581 	
       
   582 	if(cnt > 0)
       
   583 	{
       
   584 				buffer.Copy(_L("==================================="));
       
   585 				iTrace->Trace(buffer,KTraceFileName, __LINE__); 	
       
   586 	}
       
   587 	
       
   588 }
       
   589 
       
   590 // -----------------------------------------------------------------------------
       
   591 // COMASuplFallBackHandler::ReadSLPListForNIL
       
   592 // -----------------------------------------------------------------------------
       
   593 //    
       
   594 void COMASuplFallBackHandler::ReadSLPListForNIL(const TDesC& aClientProvidedHSLPAddress)
       
   595 {
       
   596 
       
   597 		TBuf<64> msg;
       
   598 		iSLPList->Reset();//Clear previous list if any
       
   599 		// Reset the counter
       
   600 		iCurrentServerCounter=0;
       
   601 		iIsFallBackAllowed=ETrue;// IAP Fallback is allowed within a SLP
       
   602 		
       
   603  		TInt err;
       
   604  		if(aClientProvidedHSLPAddress.Length() == 0)
       
   605  		{
       
   606 			GetFirstEnabledSLPL();
       
   607 			msg.Copy(_L("Using Default SLP for SUPL_INIT"));
       
   608 			iTrace->Trace(msg,KTraceFileName, __LINE__); 
       
   609 			PrintSLPList();
       
   610 			return;
       
   611 		}
       
   612 		else
       
   613 		{
       
   614 		 		CServerParams* params =  CServerParams::NewL();
       
   615 				err = iSuplSettings.GetSlpInfoAddress(aClientProvidedHSLPAddress,params);
       
   616 				msg.Copy(_L("Using SLP provided in SUPL_INIT"));
       
   617 				iTrace->Trace(msg,KTraceFileName, __LINE__); 
       
   618 				if(err != KErrNone)
       
   619 				{
       
   620 					msg.Copy(_L("Error in getting Parameters : "));
       
   621 					msg.AppendNum(err);
       
   622 		            iTrace->Trace(msg,KTraceFileName, __LINE__); 
       
   623 		            delete params; 
       
   624 					return;
       
   625 				}
       
   626 			
       
   627 				CleanupStack::PushL(params);		
       
   628 		    	TBool serverEnabled,simChangeRemove,usageInHomeNw,editable;
       
   629 				
       
   630 				TSLPDetails	 SlpEntry;
       
   631 				
       
   632 				HBufC* hslpAddress =  HBufC::NewL(KHSLPAddressLength);		
       
   633 				CleanupStack::PushL(hslpAddress);
       
   634 				
       
   635 				HBufC* iapName =  HBufC::NewL(KMaxIapNameLength);		
       
   636 				CleanupStack::PushL(iapName);
       
   637 				
       
   638 				TInt64 SLPId;	
       
   639 		   	
       
   640 		  	 	params->Get(SLPId,hslpAddress->Des(),iapName->Des(),serverEnabled,simChangeRemove,usageInHomeNw,editable);
       
   641 		   	
       
   642 		  	 	HBufC* dmConfigurableIapName =  HBufC::NewL(KMaxIapNameLength); 
       
   643 		  	 	HBufC* serverid =  HBufC::NewL(KMaxServerIdLen); 
       
   644 		  	 	HBufC* iap2 =  HBufC::NewL(KMaxIapNameLength); 
       
   645 		  	 	HBufC* serveradd =  HBufC::NewL(KMaxServerAddLen); 
       
   646 		  	 	HBufC* serveraddtype =  HBufC::NewL(KMaxServerAddTypeLen); 
       
   647 			   	
       
   648 		  	 	CServerExtensionParams* extnparams = CServerExtensionParams::NewL();
       
   649 		  	 	err = iSuplSettings.GetServerExtensionParams(SLPId,extnparams); // Ignore error
       
   650 		  	 	extnparams->Get(serverid->Des(),dmConfigurableIapName->Des(),iap2->Des(),serveradd->Des(),serveraddtype->Des() );
       
   651 		  	 	delete extnparams; 
       
   652 		  	 	
       
   653 		  	 	if(serverEnabled)
       
   654 			   	{
       
   655 					   	SlpEntry.iSLPId = SLPId;
       
   656 					   	SlpEntry.iHSLPAddress.Copy(hslpAddress->Des());
       
   657 					   	SlpEntry.iIapName.Copy(iapName->Des());
       
   658 					   	SlpEntry.iIapName.LowerCase();
       
   659 					   	SlpEntry.iHomeNetworkUsage = usageInHomeNw;
       
   660 					   	
       
   661 					   	iSuplSettings.GetTlsFlag(SLPId,SlpEntry.iTls);
       
   662 					   	iSuplSettings.GetPskTlsFlag(SLPId,SlpEntry.iPskTls);
       
   663 					   	SlpEntry.iIsIAPDialgShown=ETrue;
       
   664 					   	iSLPList->AppendL(SlpEntry);
       
   665 					   	if( dmConfigurableIapName->Length() > 0 )
       
   666                             {
       
   667                             // Replace default iap field with 2ndary iap field
       
   668                             SlpEntry.iIapName.Copy(dmConfigurableIapName->Des());
       
   669                             SlpEntry.iIapName.LowerCase();
       
   670                             // Set IapDialog flag to false for entry with secondary iap
       
   671                             SlpEntry.iIsIAPDialgShown=EFalse;
       
   672                             // Append this entry to the list
       
   673                             iSLPList->AppendL(SlpEntry);
       
   674                             }
       
   675 					   	
       
   676 			   	}
       
   677 				
       
   678 				CleanupStack::PopAndDestroy(3);//params,hslpAddress iapName	   	
       
   679 		        delete dmConfigurableIapName;
       
   680 		        delete serverid;
       
   681 		        delete iap2;
       
   682 		        delete serveradd;
       
   683 		        delete serveraddtype;
       
   684 		}
       
   685 		PrintSLPList();
       
   686 }
       
   687 
       
   688 // -----------------------------------------------------------------------------
       
   689 // COMASuplFallBackHandler::UpdateSLPListForHomeUsage
       
   690 // -----------------------------------------------------------------------------
       
   691 //    
       
   692 void COMASuplFallBackHandler::UpdateSLPListForHomeUsage(TBool aHomeNetwork)
       
   693 {
       
   694 	if(!aHomeNetwork)//User is in Roaming...
       
   695 	{
       
   696 				TInt TotalServers = iSLPList->Count();	
       
   697 				TInt cnt = 0;
       
   698 				while( cnt < TotalServers )
       
   699 				{
       
   700 					TInt  hwUsageInt = (*iSLPList)[cnt].iHomeNetworkUsage;
       
   701 					
       
   702 					
       
   703 					if (hwUsageInt)
       
   704 					{
       
   705 						(*iSLPList).Delete(cnt);
       
   706 						TotalServers--;
       
   707 					}
       
   708 					else
       
   709 					{
       
   710 							cnt++;
       
   711 					}
       
   712 				}
       
   713 	}		
       
   714 		iTrace->Trace(_L("After roaming check..."),KTraceFileName, __LINE__); 	
       
   715 		PrintSLPList();
       
   716 		
       
   717 }
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 // COMASuplFallBackHandler::GetFirstEnabledSLPL
       
   721 // -----------------------------------------------------------------------------
       
   722 //    
       
   723 void COMASuplFallBackHandler::GetFirstEnabledSLPL()
       
   724 {
       
   725 		RPointerArray<CServerParams> SLPList;
       
   726 	  
       
   727     	TBool serverEnabled,simChangeRemove,usageInHomeNw,editable;
       
   728     	
       
   729 		TInt err = iSuplSettings.GetAllSlp(SLPList);
       
   730 		TInt cnt = SLPList.Count();
       
   731 		HBufC* hslpAddress =  HBufC::NewL(KHSLPAddressLength);		
       
   732 		CleanupStack::PushL(hslpAddress);
       
   733 		HBufC* iapName =  HBufC::NewL(KMaxIapNameLength);		
       
   734 		CleanupStack::PushL(iapName);
       
   735 		
       
   736 		HBufC* dmConfigurableIapName =  HBufC::NewL(KMaxIapNameLength); 
       
   737 		HBufC* serverid =  HBufC::NewL(KMaxServerIdLen); 
       
   738 		HBufC* iap2 =  HBufC::NewL(KMaxIapNameLength); 
       
   739 		HBufC* serveradd =  HBufC::NewL(KMaxServerAddLen); 
       
   740 		HBufC* serveraddtype =  HBufC::NewL(KMaxServerAddTypeLen); 
       
   741 		                
       
   742 		CServerExtensionParams* extnparams = CServerExtensionParams::NewL();
       
   743 			
       
   744 		for(TInt i = 0; i < cnt; i++ )
       
   745 		{
       
   746 				TInt64 SLPId;	
       
   747 			   	CServerParams* params = SLPList[i];
       
   748 			   	params->Get(SLPId,hslpAddress->Des(),iapName->Des(),serverEnabled,simChangeRemove,usageInHomeNw,editable);
       
   749 			   	if(serverEnabled)
       
   750 		   		{
       
   751 					   	TSLPDetails	 SlpEntry;
       
   752 					   	SlpEntry.iSLPId = SLPId;
       
   753 					   	SlpEntry.iHSLPAddress.Copy(hslpAddress->Des());
       
   754 					   	SlpEntry.iIapName.Copy(iapName->Des());
       
   755 					   	SlpEntry.iIapName.LowerCase();
       
   756 					   	SlpEntry.iHomeNetworkUsage = usageInHomeNw;
       
   757 						iSuplSettings.GetTlsFlag(SLPId,SlpEntry.iTls);
       
   758 						iSuplSettings.GetPskTlsFlag(SLPId,SlpEntry.iPskTls);
       
   759 						SlpEntry.iIsIAPDialgShown=ETrue;
       
   760 						iSLPList->AppendL(SlpEntry);
       
   761 						
       
   762 						err = iSuplSettings.GetServerExtensionParams(SLPId,extnparams); // Ignore error
       
   763 						extnparams->Get(serverid->Des(),dmConfigurableIapName->Des(),iap2->Des(),serveradd->Des(),serveraddtype->Des() );
       
   764 						
       
   765 						if( dmConfigurableIapName->Length() > 0 )
       
   766                             {
       
   767                             // Replace default iap field with 2ndary iap field
       
   768                             SlpEntry.iIapName.Copy(dmConfigurableIapName->Des());
       
   769                             SlpEntry.iIapName.LowerCase();
       
   770                             // Set IapDialog flag to false for entry with secondary iap
       
   771                             SlpEntry.iIsIAPDialgShown=EFalse;
       
   772                             // Append this entry to the list
       
   773                             iSLPList->AppendL(SlpEntry);
       
   774                             }
       
   775 						
       
   776 						break;
       
   777 				}	
       
   778 		}
       
   779 		
       
   780 		CleanupStack::PopAndDestroy(2);//hslpAddress iapName	   	
       
   781 		delete extnparams; 
       
   782 		delete dmConfigurableIapName;
       
   783 		delete serverid;
       
   784 		delete iap2;
       
   785 		delete serveradd;
       
   786 		delete serveraddtype;
       
   787 		SLPList.ResetAndDestroy();
       
   788 		SLPList.Close();
       
   789 }
       
   790 
       
   791 
       
   792 
       
   793 
       
   794