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