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