supl/locationomasuplprotocolhandler/protocolhandlerver2/src/epos_comasuplposinitstate.cpp
changeset 0 667063e416a2
child 20 2b4ea9893b66
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 SUPL_POS_INIT message...
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <etelmm.h> 
       
    21 #include <hash.h>
       
    22 #include <f32file.h>
       
    23 #include <flogger.h>
       
    24 #include <lbs/epos_comasuplpossessionbase.h>
       
    25 #include "utf.h"
       
    26 #include "epos_comasupllocationid.h"
       
    27 #include "epos_comasupllocationidver2.h"
       
    28 #include "lbs/epos_comasuplreqasstdata.h"
       
    29 #include "lbs/epos_comasuplinforequestlist.h"
       
    30 #include "lbs/epos_comasuplsetcapabilities.h"
       
    31 #include "lbs/epos_comasuplpospayload.h"
       
    32 #include "lbs/epos_comasuplposition.h"
       
    33 #include "lbs/epos_comasuplvelocity.h"
       
    34 
       
    35 #include "epos_comasuplsession2.h"
       
    36 #include "epos_comasuplposinitver2.h"
       
    37 #include "epos_comasuplposinitstate.h"
       
    38 #include "epos_comasuplposrequestor.h"
       
    39 #include "epos_omasuplconstants.h"
       
    40 #include "epos_comasupltrace.h"
       
    41 
       
    42 
       
    43 _LIT(KTraceFileName,"SUPL_OMA_SESSION::EPos_COMASuplPosInitState.cpp");
       
    44 
       
    45 
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // COMASuplPosInitState::COMASuplPosInitState
       
    51 // C++ constructor can NOT contain any code, that might leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 COMASuplPosInitState::COMASuplPosInitState(COMASuplSETCapabilities* aOldCapabilities,
       
    55 										   RMobilePhone& aMobilePhone,TInt aMsgTimeout,
       
    56 										   COMASuplPOSRequestor* aPosRequestor,
       
    57 										   COMASuplSession::TOMASuplReqType aRequestType,
       
    58 										   COMASuplAsnHandlerBase* aOMASuplAsnHandlerBase):
       
    59 										   COMASuplStartState(aMobilePhone,
       
    60 										   aMsgTimeout,aPosRequestor,aOMASuplAsnHandlerBase),
       
    61 										   iRequestType(aRequestType),
       
    62                        iPosPayloadPresent(EFalse),iIgnorePosData(EFalse),iRepeatedPosDataFetch(EFalse)
       
    63     {
       
    64 		iCurrentState =  ESUPL_POS_INIT;
       
    65 		iOldCapabilities = aOldCapabilities;   // Caps recevied during SUPL_START from POS
       
    66 		iRes.FillZ();
       
    67 		iGenerationStatus = EFalse;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // COMASuplPosInitState::~COMASuplPosInitState
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 COMASuplPosInitState::~COMASuplPosInitState()
       
    75     {
       
    76 	if(iHSLPAddress)
       
    77 		{
       
    78 		delete iHSLPAddress;
       
    79 		}
       
    80 		
       
    81 	if(iEncodedSuplInit)
       
    82 		{
       
    83 		delete iEncodedSuplInit;
       
    84 		}
       
    85 
       
    86 	if(iLocationId)
       
    87 		{
       
    88 		delete iLocationId;	
       
    89 		iLocationId=NULL;
       
    90 		}    	
       
    91 		
       
    92 	if(iTrace)
       
    93 		{
       
    94 		iTrace->Trace(_L("COMASuplPosInitState::~COMASuplPosInitState..."), KTraceFileName, __LINE__); 							
       
    95 		}
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // COMASuplPosInitState::ConstructL
       
   100 // Symbian 2nd phase constructor can leave.
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void COMASuplPosInitState::ConstructL(TInt aAllowedCapabilities, TOMASuplPosMethod aPosMethod, HBufC8* aEncodedSuplInit, HBufC8* aHSLPAddress)
       
   104     {
       
   105     	COMASuplStartState::ConstructL(aAllowedCapabilities);
       
   106 		iTrace->Trace(_L(""), KTraceFileName, __LINE__); 							    	
       
   107 		
       
   108 		switch(aPosMethod)
       
   109 			{
       
   110 			case EOMAAgpsSETAssisted:
       
   111 				{
       
   112 				iTrace->Trace(_L("EGpsSETAssisted"), KTraceFileName, __LINE__); 
       
   113 				iPosMethod = COMASuplPosSessionBase::EGpsSETAssisted;
       
   114 				}
       
   115 				break;
       
   116 	
       
   117 			case EOMAAgpsSETAssistedPref:
       
   118 				{
       
   119 				iTrace->Trace(_L("EOMAAgpsSETAssistedPref"), KTraceFileName, __LINE__); 
       
   120 				iPosMethod = COMASuplPosSessionBase::EGpsSETAssistedPreferred;
       
   121 				}
       
   122 				break;
       
   123 	
       
   124 			case EOMAAgpsSETBased:
       
   125 				{
       
   126 				iTrace->Trace(_L("EOMAAgpsSETBased"), KTraceFileName, __LINE__); 
       
   127 				iPosMethod = COMASuplPosSessionBase::EGpsSETBased;
       
   128 				}
       
   129 				break;
       
   130 	
       
   131 			case EOMAAgpsSETBasedPref:
       
   132 				{
       
   133 				iTrace->Trace(_L("EOMAAgpsSETBasedPref"), KTraceFileName, __LINE__); 
       
   134 				iPosMethod = COMASuplPosSessionBase::EGpsSETBasedPreferred;
       
   135 				}
       
   136 				break;
       
   137 	
       
   138 			case EOMAAutonomousGps:
       
   139 				{
       
   140 				iTrace->Trace(_L("EOMAAutonomousGps"), KTraceFileName, __LINE__); 
       
   141 				iPosMethod = COMASuplPosSessionBase::EAutonomousGps;
       
   142 				}
       
   143 				break;
       
   144 	
       
   145 			case EOMAFLT:
       
   146 				{
       
   147 				iTrace->Trace(_L("EOMAFLT"), KTraceFileName, __LINE__); 
       
   148 				iPosMethod = COMASuplPosSessionBase::EAFLT;
       
   149 				}
       
   150 				break;
       
   151 	
       
   152 			case EOMAeOTD:
       
   153 				{
       
   154 				iTrace->Trace(_L("EOMAeOTD"), KTraceFileName, __LINE__); 
       
   155 				iPosMethod = COMASuplPosSessionBase::EeOTD;
       
   156 				}
       
   157 				break;
       
   158 	
       
   159 			case EOMAoTDOA:
       
   160 				{
       
   161 				iTrace->Trace(_L("EOMAoTDOA"), KTraceFileName, __LINE__); 
       
   162 				iPosMethod = COMASuplPosSessionBase::EoTDOA;
       
   163 				}
       
   164 				break;
       
   165 	
       
   166 			case EOMANoPosition:
       
   167 				{
       
   168 				iTrace->Trace(_L("EOMANoPosition"), KTraceFileName, __LINE__); 
       
   169 				iPosMethod = COMASuplPosSessionBase::ENoPosition;
       
   170 				}
       
   171 				break;
       
   172 	
       
   173 			default:
       
   174 	
       
   175 				{
       
   176 				iTrace->Trace(_L("default"), KTraceFileName, __LINE__); 
       
   177 				iPosMethod = COMASuplPosSessionBase::EPositionUndefined;			
       
   178 				}
       
   179 				break;
       
   180 			}
       
   181 		
       
   182 		TBuf<128> msg(_L("COMASuplPosInitState::ConstructL... iPosMethod: "));
       
   183 		msg.AppendNum(iPosMethod);
       
   184 		iTrace->Trace(msg, KTraceFileName, __LINE__); 
       
   185 		
       
   186 		if(aEncodedSuplInit)
       
   187 			{
       
   188 				TInt len = aEncodedSuplInit->Length();
       
   189 		    	if(len > 0)
       
   190 		    	{
       
   191 		    		iEncodedSuplInit = HBufC8::NewL(len);
       
   192 		    		*iEncodedSuplInit = *aEncodedSuplInit; 
       
   193 		       	}
       
   194 		    			
       
   195 			}
       
   196     	
       
   197     	if(aHSLPAddress)
       
   198 	   		{
       
   199 		    	TInt len = aHSLPAddress->Length();
       
   200  
       
   201 		    	if(len > 0)
       
   202 		    	{
       
   203 				   	iHSLPAddress = HBufC8::NewL(len);
       
   204 				  	*iHSLPAddress = *aHSLPAddress;
       
   205 		    	}
       
   206 			
       
   207     		}
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // COMASuplPosInitState::NewL
       
   212 // Two-phased constructor.
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 COMASuplPosInitState* COMASuplPosInitState::NewL(COMASuplSETCapabilities* aOldCapabilities,
       
   216 											RMobilePhone& aMobilePhone,TInt aMsgTimeout,
       
   217 											COMASuplPOSRequestor* aPosRequestor,TInt aAllowedCapabilities,
       
   218 											COMASuplSession::TOMASuplReqType aRequestType, TOMASuplPosMethod aPosMethod,
       
   219 											COMASuplAsnHandlerBase* aOMASuplAsnHandlerBase,
       
   220 											HBufC8* aEncodedSuplInit,
       
   221 											HBufC8* aHSLPAddress
       
   222 											)
       
   223     {
       
   224 	    COMASuplPosInitState* self =  new ( ELeave ) COMASuplPosInitState(aOldCapabilities,
       
   225 	    											  aMobilePhone,aMsgTimeout,aPosRequestor,aRequestType,aOMASuplAsnHandlerBase);
       
   226 	    CleanupStack::PushL( self );
       
   227 	    self->ConstructL(aAllowedCapabilities, aPosMethod, aEncodedSuplInit, aHSLPAddress);
       
   228 	    CleanupStack::Pop(self);
       
   229 	    return self;
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // COMASuplPosInitState::GenerateMessage
       
   234 // Generates SUPL_POS_INIT message
       
   235 // (other items were commented in a header).
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 TInt COMASuplPosInitState::GenerateMessageL() 
       
   239 	{
       
   240 		iGenerationStatus = ETrue;
       
   241 		iTrace->Trace(_L("Start of COMASuplPosInitState::GenerateMessage"), KTraceFileName, __LINE__); 					
       
   242 		iVerPresent = ComputeSuplInitVerL();
       
   243 		if(iVerPresent)
       
   244 			{
       
   245 				iLocationIDRequestor->GetLocationID();		
       
   246 			}
       
   247 		else
       
   248 			{
       
   249 				iMsgStateObserver->OperationCompleteL(KErrGeneral);
       
   250 			}
       
   251 		return KErrNone;				
       
   252 	}
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // COMASuplPosInitState::ComputeSuplInitVer
       
   256 // Generates SUPL_POS_INIT message
       
   257 // (other items were commented in a header).
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 TBool COMASuplPosInitState::ComputeSuplInitVerL() 
       
   261 	{
       
   262 	if(iRequestType == COMASuplSession::ESUPL_TERMINAL) 
       
   263 		{
       
   264 			return ETrue;
       
   265 		}
       
   266 
       
   267     if (iRequestType == COMASuplSession::ESUPL_NETWORK && GetTriggerSessionFlag())
       
   268 		{
       
   269 			return ETrue;
       
   270 		}
       
   271 	
       
   272 	if(iEncodedSuplInit && (iEncodedSuplInit->Length()) > 0 &&
       
   273 	iHSLPAddress && iHSLPAddress->Length() > 0)
       
   274 	{
       
   275 		TInt blockSize = 64;
       
   276 	    TChar ipad = 0x36;
       
   277 	    TChar opad = 0x5c;
       
   278 	    TBuf8<64> key0;
       
   279 	    TInt i;
       
   280 
       
   281 	    CMessageDigest* sha1 = CMessageDigestFactory::NewDigestLC(
       
   282 	                                CMessageDigest::ESHA1 );
       
   283 
       
   284 	    // Step 1: Append 0x00 to the key to create a string of size = blocksize
       
   285 	    key0.SetLength( blockSize );
       
   286 	    key0.FillZ();
       
   287 	    
       
   288 	    if ( iHSLPAddress->Length() != blockSize )
       
   289 	        {
       
   290 	        // If key greater than the block size of digest which is 64
       
   291 	        // then hash the key to get a 20 byte code
       
   292 	        if ( iHSLPAddress->Length() > blockSize )
       
   293 	            {
       
   294 	            TPtrC8 hashedKey = sha1->Hash(*iHSLPAddress );
       
   295 	            for ( i = 0; i < hashedKey.Length(); i++ )
       
   296 	                {
       
   297 	                key0[i] = hashedKey[i];
       
   298 	                }
       
   299 	            sha1->Reset();
       
   300 	            }
       
   301 	        else if ( iHSLPAddress->Length() < blockSize )
       
   302 	            {
       
   303 	            for ( i = 0; i < iHSLPAddress->Length(); i++ )
       
   304 	                {
       
   305 	                key0[i] = (*iHSLPAddress)[i];
       
   306 	                }
       
   307 	            }
       
   308 	        }
       
   309 	    else
       
   310 	        {
       
   311 	        for ( i = 0; i < iHSLPAddress->Length(); i++ )
       
   312 	            {
       
   313 	            key0[i] = (*iHSLPAddress)[i];
       
   314 	            }
       
   315 	        } 
       
   316 	    
       
   317 	    
       
   318 	     // Step 2: XOR the string obtained in Step 1 with ipad
       
   319 	    for ( TInt i = 0; i < blockSize; i++ )
       
   320 	        {
       
   321 	        iRes.Append( key0[i] ^ ipad );
       
   322 	        }
       
   323 	     
       
   324 	     
       
   325 #ifdef PRINT_MESSAGE
       
   326 	    iTrace->Trace(_L("ipad of server address  "), KTraceFileName, __LINE__); 					
       
   327 	    PrintHex(iRes,__LINE__); 
       
   328 #endif
       
   329 	    
       
   330 	    // Step 3: Append the message to the string resulting from Step 2
       
   331 	    HBufC8* messageKeyString = 
       
   332 	            HBufC8::NewLC( iEncodedSuplInit->Size() + iRes.Size() );
       
   333 	    messageKeyString->Des().Append( iRes );
       
   334 	    messageKeyString->Des().Append( *iEncodedSuplInit );
       
   335 
       
   336 	    
       
   337 	    // Step 4: Generate hash code of the string resulting in Step 3
       
   338 	    TPtrC8 innerHashedMessage = sha1->Hash( messageKeyString->Des() );
       
   339 	    HBufC8* step4Msg = HBufC8::NewLC(innerHashedMessage.Size());
       
   340 	    step4Msg->Des().Append(innerHashedMessage);
       
   341 	    sha1->Reset();
       
   342 	    
       
   343 	    
       
   344 	    // Step 5: XOR the string obtained in Step 1 with opad
       
   345 	    HBufC8* hmacString = HBufC8::NewLC( step4Msg->Size() + blockSize );
       
   346 	    for ( TInt i = 0; i < blockSize; i++ )
       
   347 	        {
       
   348 	        hmacString->Des().Append( key0[i] ^ opad );
       
   349 	        }
       
   350 	        
       
   351 	       
       
   352 #ifdef PRINT_MESSAGE
       
   353 	    iTrace->Trace(_L("xor ofserver address with opad"), KTraceFileName, __LINE__); 					
       
   354 	    PrintHex(hmacString->Des(),__LINE__); 
       
   355 #endif
       
   356 	    
       
   357 	    // Step 6: Append the string obtained in step 4 to the string 
       
   358 	    // obtained in Step 5
       
   359 	    hmacString->Des().Append( step4Msg->Des() );
       
   360 	  
       
   361 	    
       
   362 	    // Step 7: Generate hash code of the string resulting from Step 6
       
   363 	    iRes.FillZ();
       
   364 	    iRes.Zero();
       
   365 	    TPtrC8 hmacSha1Code = sha1->Hash( hmacString->Des() );
       
   366 
       
   367 	    // Truncate hash output to 64 bits
       
   368 	    iRes.Copy( hmacSha1Code.Ptr(), 8 );
       
   369 
       
   370 	    CleanupStack::PopAndDestroy( hmacString );
       
   371 	    CleanupStack::PopAndDestroy( step4Msg );
       
   372 	    CleanupStack::PopAndDestroy( messageKeyString );
       
   373 	    CleanupStack::PopAndDestroy( sha1 );
       
   374 	    
       
   375 #ifdef PRINT_MESSAGE
       
   376 		iTrace->Trace(_L("Final ver..."), KTraceFileName, __LINE__); 							
       
   377 		PrintHex(iRes,__LINE__);
       
   378 #endif
       
   379 		return ETrue;	
       
   380 	}
       
   381 	
       
   382 	return EFalse;
       
   383 	
       
   384 	}	
       
   385 // -----------------------------------------------------------------------------
       
   386 // COMASuplPosInitState::GetPosParamsL
       
   387 // Collects the optional parameters for SUPL_POS_INIT 
       
   388 // message from POS Message plugin
       
   389 // (other items were commented in a header).
       
   390 // -----------------------------------------------------------------------------
       
   391 //
       
   392 void COMASuplPosInitState::GetPosParamsL() 
       
   393 	{
       
   394 	
       
   395 	iGenerationStatus = ETrue;
       
   396 	
       
   397 	// Re-initialize the POS Requestor
       
   398 	if(iPosRequestor)
       
   399 		iPosRequestor->DestroyList();
       
   400 	iPosRequestor->CreateListL();
       
   401 	
       
   402 	// Create SET capabilities object
       
   403 	iCurSetCapabilities = COMASuplSETCapabilities::NewL();
       
   404 	
       
   405 	// Create the Request Assistance data object
       
   406 	iReqAsstData = COMASuplReqAsstData::NewL();
       
   407 	
       
   408 	// Create Position
       
   409 	iPosition = COMASuplPosition::NewL();
       
   410 
       
   411 	// Create POS Payload
       
   412 	iPosPayload = COMASuplPosPayload::NewL();
       
   413 
       
   414 	// Create Velocity
       
   415 	iVelocity = COMASuplVelocity::NewL();
       
   416 	
       
   417 
       
   418 	// Append the SUPL POS INIT optional parameters to the list
       
   419 	// in POS Requestor
       
   420 	iPosRequestor->AppendInfoRequest(iCurSetCapabilities);
       
   421 	iPosRequestor->AppendInfoRequest(iReqAsstData);
       
   422 	iPosRequestor->AppendInfoRequest(iPosition);
       
   423 	iPosRequestor->AppendInfoRequest(iPosPayload);
       
   424 	iPosRequestor->AppendInfoRequest(iVelocity);
       
   425 	
       
   426 	// Set self as Observer to POS Requestor
       
   427 	iPosRequestor->SetObserver(this);
       
   428 	
       
   429 	TBuf<128> msg(_L("Filling iPosMethod in iPosRequestor: "));
       
   430 	iTrace->Trace(msg, KTraceFileName, __LINE__); 
       
   431 	if(iPosRequestor)
       
   432 		{
       
   433 		iAllowedCapabilitiesforPOS.SetAllowedCapabilities(EFalse, EFalse, EFalse, EFalse, EFalse, EFalse, EFalse, EFalse);
       
   434 		iPosRequestor->SetPosMethodAndAllowedCapabilities (iAllowedCapabilitiesforPOS,iPosMethod ); 
       
   435         if(iHSLPAddress)
       
   436             {
       
   437             HBufC* slpAddress = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*iHSLPAddress);
       
   438             msg.Copy(_L("Filling iHSLPAddress in iPosRequestor: "));
       
   439             msg.Append(*slpAddress);
       
   440             iTrace->Trace(msg, KTraceFileName, __LINE__); 
       
   441             iPosRequestor->SetSLPAddressUsed(*slpAddress);
       
   442             }
       
   443 		}
       
   444 	// Get the information from POS
       
   445 	if(iPosRequestor)
       
   446 	User::LeaveIfError(iPosRequestor->GetSuplInfoL());
       
   447 	
       
   448 	}
       
   449 // -----------------------------------------------------------------------------
       
   450 // COMASuplPosInitState::OperationCompleteL
       
   451 // An observer method that indicates the completion of
       
   452 // data retrieval from POS Message plugin
       
   453 // (other items were commented in a header).
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 void COMASuplPosInitState::OperationCompleteL(TInt  aError ) 
       
   457 	{
       
   458 		if(iMsgStateObserver)
       
   459 		{
       
   460 			iGenerationStatus = EFalse;
       
   461 			if(aError == KErrNone)
       
   462 			    {
       
   463 			    iLocationIDRequestor->GetComparisionLocationID();
       
   464 			    }
       
   465 			else
       
   466 			    iMsgStateObserver->OperationCompleteL(aError);
       
   467 		}
       
   468 	}
       
   469 // -----------------------------------------------------------------------------
       
   470 // COMASuplPosInitState::ValidateSetCapabilities
       
   471 // Collects the optional parameters for SUPL_POS_INIT 
       
   472 // message from POS Message plugin
       
   473 // (other items were commented in a header).
       
   474 // -----------------------------------------------------------------------------
       
   475 //
       
   476 TInt COMASuplPosInitState::ValidateSetCapabilities() 
       
   477 	{
       
   478 		
       
   479   
       
   480 
       
   481 		if(!iPosRequestor || iRequestType == COMASuplSession::ESUPL_NETWORK )  //No need to check status if POS is not there
       
   482 			{
       
   483 				return KErrNone;  
       
   484 			}
       
   485 			
       
   486 		TInt status = iCurSetCapabilities->Status();  // Caps from POS
       
   487 		
       
   488 		if(status == KErrNone)
       
   489 		{
       
   490 			TOMASuplPosTechnology oldPosTech, curPosTech;
       
   491 			COMASuplSETCapabilities::TOMASuplPrefMethod oldPrefMethod, curPrefMethod;
       
   492 			TOMASuplPosProtocol oldPosProtocol, curPosProtocol;
       
   493 		
       
   494 			iOldCapabilities->GetSETCapabilities(oldPosTech, oldPrefMethod, oldPosProtocol);
       
   495 		
       
   496 			iCurSetCapabilities->GetSETCapabilities(curPosTech, curPrefMethod, curPosProtocol);
       
   497 			
       
   498 			TBool oldGpsSETAssisted, curGpsSETAssisted, oldGpsSETBased, curGpsSETBased;
       
   499 			TBool oldAutonomousGps, curAutonomousGps, oldaFLT, curaFLT, oldAeOTD, curAeOTD;
       
   500 			TBool oldOTDOA, curoTDOA;
       
   501 			
       
   502 			oldPosTech.GetPosTechnology(oldGpsSETAssisted, oldGpsSETBased, oldAutonomousGps, oldaFLT,
       
   503 										oldAeOTD, oldOTDOA);
       
   504 										
       
   505 			curPosTech.GetPosTechnology(curGpsSETAssisted, curGpsSETBased, curAutonomousGps, curaFLT,
       
   506 										curAeOTD, curoTDOA);
       
   507 										
       
   508 			if((oldGpsSETAssisted == curGpsSETAssisted) && (oldGpsSETBased == curGpsSETBased) &&
       
   509 			  (oldAutonomousGps == curAutonomousGps) && (oldaFLT == curaFLT) && (oldAeOTD == curAeOTD)
       
   510 			  && (oldOTDOA == curoTDOA))
       
   511 			{
       
   512 				TBool oldTIA801, curTIA801, oldRRLP, curRRLP, oldRRC, curRRC;
       
   513 				
       
   514 				oldPosProtocol.GetPosProtocol(oldTIA801, oldRRLP, oldRRC);
       
   515 				curPosProtocol.GetPosProtocol(curTIA801, curRRLP, curRRC);
       
   516 				
       
   517 				if((oldTIA801 == curTIA801) && (oldRRLP == curRRLP) && (oldRRC == curRRC))
       
   518 				{
       
   519 					if(oldPrefMethod == curPrefMethod)
       
   520 					{
       
   521 						return KErrNone;
       
   522 					}
       
   523 				}
       
   524 			}
       
   525 			
       
   526 			return KErrOMASETCapMisMatch;
       
   527 		
       
   528 		}
       
   529 		
       
   530 		return status;	
       
   531 
       
   532 	}
       
   533 
       
   534 
       
   535 	
       
   536 // -----------------------------------------------------------------------------
       
   537 // COMASuplPosInitState::EncodeMessageL
       
   538 // Encodes message ...returns encoded data
       
   539 // (other items were commented in a header).
       
   540 // -----------------------------------------------------------------------------
       
   541 //
       
   542 HBufC8* COMASuplPosInitState::EncodeMessageL(TOMASuplVersion &aSuplVersion,
       
   543 							  COMASuplSessionID* aSessionId,TInt &aError)
       
   544 	{
       
   545 
       
   546 		TInt error = KErrNone; 
       
   547 
       
   548 		iTrace->Trace(_L("Start of COMASuplPosInitState::EncodeMessageL"), KTraceFileName, __LINE__); 					
       
   549 		COMASuplState::EncodeMessageL(aSuplVersion,aSessionId,aError);
       
   550 
       
   551 		if(iRequestType == COMASuplSession::ESUPL_NETWORK )
       
   552 			{
       
   553 				UpdateCapabilities(); //update with caps from POS 
       
   554 			}
       
   555 			
       
   556 		aError = ValidateSetCapabilities(); 
       
   557 		if(aError != KErrNone)
       
   558 			{
       
   559 				return NULL;
       
   560 			}
       
   561 
       
   562 		COMASuplAsnMessageBase* OMASuplMessageBase = iOMASuplAsnHandlerBase->CreateOMASuplMessageL(COMASuplAsnMessageBase::ESUPL_POSINIT);
       
   563 		COMASuplPosInitVer2* OMASuplPosInit  =  static_cast<COMASuplPosInitVer2*>(OMASuplMessageBase);
       
   564 		CleanupStack::PushL(OMASuplMessageBase);
       
   565 		
       
   566 		iTrace->Trace(_L("Created COMASuplPosInit"), KTraceFileName, __LINE__); 							
       
   567 		
       
   568 		OMASuplPosInit->SetMessageBase(aSuplVersion,aSessionId); 
       
   569 		
       
   570 		if(iEncodedSuplInit)
       
   571 			{
       
   572 				OMASuplPosInit->SetVer(iRes);		
       
   573 			}
       
   574 		
       
   575 		ComputeCapabilities();
       
   576 		
       
   577 		COMASuplSETCapabilitiesVer2* setCapabilities2 = COMASuplSETCapabilitiesVer2::NewL();
       
   578 
       
   579 		if(iOldCapabilities && iPosRequestor)
       
   580 			{
       
   581 				iTrace->Trace(_L("Filling capability for POS....."), KTraceFileName, __LINE__);
       
   582 			
       
   583 				TOMASuplPosTechnology posTech;
       
   584 				COMASuplSETCapabilities::TOMASuplPrefMethod prefMethod;
       
   585 				TOMASuplPosProtocol posProtocol;
       
   586 				
       
   587 				iOldCapabilities->GetSETCapabilities(posTech, prefMethod, posProtocol);
       
   588 				
       
   589 				TBool aGpsSetAssisted, aGpsSetBased, autonomousGps, AFLT, EOTD, OTDOA;
       
   590 				posTech.GetPosTechnology(aGpsSetAssisted, aGpsSetBased, autonomousGps, AFLT, EOTD, OTDOA);
       
   591 				
       
   592 				iAllowedCapabilitiesforPOS.SetAllowedCapabilities(aGpsSetAssisted, aGpsSetBased, autonomousGps, AFLT, EOTD, OTDOA, ETrue, ETrue);
       
   593 
       
   594 				iPosRequestor->SetPosMethodAndAllowedCapabilities (iAllowedCapabilitiesforPOS,iPosMethod  ); 
       
   595 		    
       
   596         }
       
   597 		
       
   598 		COMASuplLocationIdVer2* locationId2 = COMASuplLocationIdVer2::NewL();
       
   599 		CopyLocationidToLocationId2L(locationId2);
       
   600 		OMASuplPosInit->SetLocationId2(locationId2);//Ownership will be with OMASuplPosInit
       
   601 		
       
   602 
       
   603         iTrace->Trace(_L("Filling capability for POS....."), KTraceFileName, __LINE__);
       
   604         
       
   605         TOMASuplPosTechnology posTech;
       
   606         COMASuplSETCapabilities::TOMASuplPrefMethod prefMethod;
       
   607         TOMASuplPosProtocol posProtocol;
       
   608 				
       
   609 				if (!iPosRequestor)
       
   610         	iOldCapabilities->GetSETCapabilities(posTech, prefMethod, posProtocol);// manish
       
   611         else
       
   612         	iCurSetCapabilities->GetSETCapabilities(posTech, prefMethod, posProtocol);
       
   613 
       
   614         TBool aGpsSetAssisted, aGpsSetBased, autonomousGps, AFLT, EOTD, OTDOA;
       
   615         posTech.GetPosTechnology(aGpsSetAssisted, aGpsSetBased, autonomousGps, AFLT, EOTD, OTDOA);
       
   616 
       
   617         TOMASuplPosTechnology2 posTechnology2; 
       
   618 		COMASuplSETCapabilitiesVer2::TOMASuplPrefMethod2    prefMethod2 = (COMASuplSETCapabilitiesVer2::TOMASuplPrefMethod2)prefMethod;
       
   619   	    TOMASuplPosProtocol2   posProtocol2; 
       
   620 
       
   621         posTechnology2.SetPosTechnology(aGpsSetAssisted, aGpsSetBased, autonomousGps, AFLT, EOTD, OTDOA);
       
   622 
       
   623 				TBool tia801, rrlp, rrc;
       
   624 				posProtocol.GetPosProtocol(tia801, rrlp, rrc);
       
   625 				posProtocol2.SetPosProtocol(tia801, rrlp, rrc);
       
   626 			
       
   627 				TOMASuplPosProtocolVersion   posProtocolVersion;
       
   628 				TOMASuplPosProtocolVersion3GPP2 posProtocolVersionTia;
       
   629 				TOMASuplPosProtocolVersion   tempProtocolVersion;
       
   630 
       
   631 				TOMASuplVer2ProtocolExt posProtocolExt;
       
   632 				
       
   633 				if(rrlp)
       
   634 				{
       
   635 						posProtocolExt.SetTOMASuplVer2ProtocolExt(posProtocolVersion,tempProtocolVersion,posProtocolVersionTia);
       
   636 						posProtocol2.SetVer2PosProtoExtn(posProtocolExt);
       
   637 				}
       
   638 				
       
   639 				if(rrc)
       
   640 				{
       
   641 					 posProtocolExt.SetTOMASuplVer2ProtocolExt(tempProtocolVersion,posProtocolVersion,posProtocolVersionTia);								
       
   642 					 posProtocol2.SetVer2PosProtoExtn(posProtocolExt);
       
   643 				}
       
   644 	
       
   645 			
       
   646 			setCapabilities2->SetSETCapabilities(posTechnology2, prefMethod2, posProtocol2);
       
   647 
       
   648 			OMASuplPosInit->SetSETCapabilities2(setCapabilities2); //ownership will be with OMASuplPosInit
       
   649 			
       
   650 			if(iECId)
       
   651 				{
       
   652 					OMASuplPosInit->SetECellId(iMmCellInfo);
       
   653 				}
       
   654 		
       
   655 		// Requested Assistance Data
       
   656 		if(iReqAsstData)
       
   657 			{
       
   658 				if(KErrNone == iReqAsstData->Status())
       
   659 					{
       
   660 						COMASuplReqAsstData* reqAsstData =static_cast <COMASuplReqAsstData *> (iReqAsstData->CloneL());
       
   661 						OMASuplPosInit->SetRequestAssistanceData(reqAsstData);
       
   662 					}
       
   663 			}
       
   664 
       
   665 		// Position
       
   666 		if(iPosition)
       
   667 			{
       
   668 			if(KErrNone == iPosition->Status() && !iIgnorePosData) //if iIgnorePosData is set do not use the pos data
       
   669 				{
       
   670 					COMASuplPosition* position =static_cast <COMASuplPosition *>(iPosition->CloneL());
       
   671 					position->SetType(COMASuplInfoRequest::EOMASuplPosition);
       
   672 					OMASuplPosInit->SetPosition(position);
       
   673 				}
       
   674 			else if(iIgnorePosData)
       
   675 			    iTrace->Trace(_L("COMASuplPosInitState::EncodeMessageL ignoring pos data"), KTraceFileName, __LINE__);
       
   676 			iIgnorePosData = EFalse; //reset the status back as we ignored pos data once
       
   677 			}
       
   678 			  
       
   679 		// POS Payload     
       
   680 		if(iPosPayload)
       
   681 			{
       
   682 			if(KErrNone == iPosPayload->Status())
       
   683 				{
       
   684 					COMASuplPosPayload *posPayload = static_cast <COMASuplPosPayload *>(iPosPayload->CloneL());
       
   685 					StripPospayLoadL();
       
   686 					OMASuplPosInit->SetSuplPosPayload(posPayload);
       
   687                     iPosPayloadPresent = ETrue;
       
   688 				}
       
   689 			}
       
   690 
       
   691 		// Velocity
       
   692 		if(iVelocity)
       
   693 			{
       
   694 				if(KErrNone == iVelocity->Status())
       
   695 					{				
       
   696 						COMASuplHorizVelocity* horVel = iVelocity->Velocity();
       
   697 						if(!horVel)
       
   698 						{
       
   699 							horVel = COMASuplHorizVelocity::NewL();
       
   700 							iVelocity->SetVelocity(horVel);
       
   701 						}
       
   702 						COMASuplVelocity *velocity =static_cast <COMASuplVelocity *>(iVelocity->CloneL());
       
   703 						OMASuplPosInit->SetVelocity(velocity);
       
   704 					}
       
   705 			}
       
   706 #ifdef PRINT_MESSAGE
       
   707 		LogSETCapabilities();
       
   708 		LogPosPayloadData();
       
   709 		LogPosition();
       
   710 		LogReqAssistanceData();
       
   711 		if(iVelocity)
       
   712 			{
       
   713 		if(KErrNone == iVelocity->Status())
       
   714 			{	
       
   715 				iTrace->Trace(_L("Velocity data in SUPL_POSINIT "), KTraceFileName, __LINE__);
       
   716 				LogVelocity(iVelocity);
       
   717 			}
       
   718 		else
       
   719 			{
       
   720 				iTrace->Trace(_L("No Velocity data provided for SUPL_POSINIT by POS message plugin"), KTraceFileName, __LINE__);	
       
   721 				}
       
   722 			}
       
   723 #endif
       
   724 	
       
   725 		iTrace->Trace(_L("Starting Encoding...SUPL_POS_INIT"), KTraceFileName, __LINE__); 							
       
   726 		
       
   727 		HBufC8 *encodedBuffer = NULL;
       
   728 		TRAPD(err,encodedBuffer = iOMASuplAsnHandlerBase->EncodeL(OMASuplPosInit,error));
       
   729 		CleanupStack::PopAndDestroy(OMASuplMessageBase);
       
   730 		
       
   731 		 if ( error == KErrNone && err == KErrNone )
       
   732 		 	{
       
   733 		 			iTrace->Trace(_L("Encoding Done..."), KTraceFileName, __LINE__); 							
       
   734 		 			aError = KErrNone;
       
   735 #ifdef PRINT_MESSAGE
       
   736                     RFile file;
       
   737 	                RFs   fs;
       
   738 		            TInt cErr=fs.Connect();
       
   739 	                TInt fErr = file.Open(fs,_L("c:\\logs\\epos\\packet.txt"),EFileWrite|EFileShareAny);
       
   740                     if (fErr == KErrNotFound)
       
   741                         {                            
       
   742                         file.Create(fs, _L("c:\\logs\\epos\\packet.txt"), EFileWrite|EFileShareAny);
       
   743 	                    fErr = file.Open(fs,_L("c:\\logs\\epos\\packet.txt"),EFileWrite|EFileShareAny);
       
   744                         }
       
   745                     TInt aPos;
       
   746                     file.Seek(ESeekEnd, aPos);
       
   747                     _LIT8(KMsgType, "SUPL POS INIT");
       
   748                     file.Write(KMsgType);
       
   749                     file.Write(_L8("\r \n"));
       
   750 	                file.Write(*encodedBuffer);
       
   751                     file.Write(_L8("\r \n"));
       
   752 	                file.Close();
       
   753 	                fs.Close();
       
   754 #endif
       
   755 					return encodedBuffer;
       
   756 		 	}
       
   757 		 else
       
   758 		 	{
       
   759 		 		iTrace->Trace(_L("Encoding Failed."), KTraceFileName, __LINE__); 
       
   760 				
       
   761 				aError = error;	
       
   762 		 		delete encodedBuffer;
       
   763 		 		encodedBuffer = NULL;
       
   764 		 	}
       
   765 		 	return NULL;
       
   766 	}
       
   767 
       
   768 void COMASuplPosInitState::GetPositionComplete(TInt /*aError*/)
       
   769 {
       
   770 }
       
   771 
       
   772    
       
   773 // -----------------------------------------------------------------------------
       
   774 // COMASuplPosInitState::ComparisionLocationIDRequestCompletedL
       
   775 // Gets called when location request for comparision completed
       
   776 // (other items were commented in a header).
       
   777 // -----------------------------------------------------------------------------
       
   778 //
       
   779 void COMASuplPosInitState::ComparisionLocationIDRequestCompletedL(COMASuplLocationId* aLocationId,
       
   780         TInt aErrorCode)
       
   781     {
       
   782     
       
   783     iTrace->Trace(_L("COMASuplPosInitState::ComparisionLocationIDRequestCompletedL..."), KTraceFileName, __LINE__);      
       
   784     
       
   785     if(aErrorCode!=KErrNone)
       
   786         {
       
   787         iTrace->Trace(_L("COMASuplPosInitState::ComparisionLocationIDRequestFailed"), KTraceFileName, __LINE__);       
       
   788         if(iMsgStateObserver)
       
   789             {
       
   790             iMsgStateObserver->OperationCompleteL(aErrorCode);
       
   791             return;
       
   792             }
       
   793         }
       
   794     //if the current Cell id is the same as the Cell id when we made the request for assistance data then use the assistance data
       
   795     //and we have not already repeated a request before
       
   796     if(!iRepeatedPosDataFetch && iLocationId->GetCellId() == aLocationId->GetCellId()) 
       
   797         {
       
   798         iTrace->Trace(_L("COMASuplPosInitState::ComparisionLocationIDRequestCompletedL Cell Id not changed since making last request, so continuing"), KTraceFileName, __LINE__); 
       
   799         if(iLocationId)
       
   800             {
       
   801             delete iLocationId;
       
   802             iLocationId = NULL;
       
   803             }
       
   804         iLocationId = aLocationId;
       
   805         if(iMsgStateObserver)
       
   806         iMsgStateObserver->OperationCompleteL(aErrorCode);
       
   807         }
       
   808     else // Cell id has changed since previous request so assistance data may be invalid
       
   809         {
       
   810         iTrace->Trace(_L("COMASuplPosInitState::ComparisionLocationIDRequestCompletedL Cell Id changed since making last request, retrieving toe limit"), KTraceFileName, __LINE__);
       
   811         TOMASuplNavigationModel navModel;
       
   812         if(KErrNone == iReqAsstData->GetNavigationData(navModel))
       
   813             {
       
   814             TInt gpsWeek, gpsToe, NSAT, toeLimit;
       
   815             navModel.GetNavigationModel(gpsWeek, gpsToe, NSAT, toeLimit);
       
   816             if(toeLimit >= KMaxCellIdChangeToeLimit) 
       
   817                 {
       
   818                 iTrace->Trace(_L("COMASuplPosInitState::ComparisionLocationIDRequestCompletedL toe limit greater than KMaxCellIdChangeToeLimit. getting  pos data again"), KTraceFileName, __LINE__);
       
   819                 if(!iRepeatedPosDataFetch)//if cell id changed and we have not already repeated fetching pos data
       
   820                     {
       
   821                     iRepeatedPosDataFetch = ETrue;
       
   822                     if(iLocationId)
       
   823                         {
       
   824                         delete iLocationId;
       
   825                         iLocationId = NULL;
       
   826                         }
       
   827                     iLocationId = aLocationId; //update the location id member for the next request as we are making a request again
       
   828                     iTrace->Trace(_L("COMASuplPosInitState::ComparisionLocationIDRequestCompletedL toe limit greater than KMaxCellIdChangeToeLimit. getting  pos data again"), KTraceFileName, __LINE__);
       
   829                     GetPosParamsL();
       
   830                     }
       
   831                 else
       
   832                     {
       
   833                     iRepeatedPosDataFetch = EFalse; //reset the status
       
   834                     if(iLocationId)
       
   835                         {
       
   836                        delete iLocationId;
       
   837                        iLocationId = NULL;
       
   838                         }
       
   839                     iLocationId = aLocationId;
       
   840                     iTrace->Trace(_L("COMASuplPosInitState::ComparisionLocationIDRequestCompletedL toe limit greater than KMaxCellIdChangeToeLimit. But repeated a pos fetch already so continuing"), KTraceFileName, __LINE__);
       
   841                     iMsgStateObserver->OperationCompleteL(aErrorCode);//use the pos data as it is
       
   842                     }
       
   843                 }
       
   844             else //ignore the position data
       
   845                 {
       
   846                 iIgnorePosData = ETrue;
       
   847                 iTrace->Trace(_L("COMASuplPosInitState::ComparisionLocationIDRequestCompletedL toe limit less than KMaxCellIdChangeToeLimit. Ignoring pos data"), KTraceFileName, __LINE__);
       
   848                 iRepeatedPosDataFetch = EFalse; //reset the status
       
   849                 if(iLocationId)
       
   850                     {
       
   851                 	delete iLocationId;
       
   852                 	iLocationId = NULL;
       
   853                     }
       
   854                 iLocationId = aLocationId;
       
   855                 iMsgStateObserver->OperationCompleteL(aErrorCode);
       
   856                 }
       
   857             }
       
   858         }
       
   859     }
       
   860 
       
   861 
       
   862 // -----------------------------------------------------------------------------
       
   863 // COMASuplPosInitState::ComputeCapabilities
       
   864 // Does ANDing of SETCapabilities with AllowedCapabilities & stores in SETCapabilities
       
   865 // (other items were commented in a header).
       
   866 // -----------------------------------------------------------------------------
       
   867 //
       
   868 void COMASuplPosInitState::ComputeCapabilities()
       
   869 {	
       
   870 	iTrace->Trace(_L("Start of COMASuplPosInitState::ComputeCapabilities"), KTraceFileName, __LINE__); 															
       
   871 	
       
   872 	TOMASuplPosProtocol   SETposProtocol;
       
   873 	COMASuplSETCapabilities::TOMASuplPrefMethod    SETprefMethod;
       
   874 	TOMASuplPosTechnology SETposTechnology;
       
   875 	
       
   876 	TOMASuplPosProtocol   AllowedposProtocol;
       
   877 	COMASuplSETCapabilities::TOMASuplPrefMethod    AllowedprefMethod;
       
   878 	TOMASuplPosTechnology AllowedposTechnology;
       
   879 	
       
   880 	TBool  SETGpsSETAssisted,AllowedGpsSETAssisted;
       
   881 	TBool  SETGpsSETBased,AllowedGpsSETBased;
       
   882 	TBool  SETAutonomousGps,AllowedAutonomousGps;
       
   883 	TBool  SETeOTD,AllowedeOTD;
       
   884 	TBool  SEToTDOA,AllowedoTDOA;
       
   885 	TBool SETFLT, AllowedFLT;	
       
   886 	TBool SETTIA801,AllowedTIA801; 
       
   887 	TBool SETRRLP,AllowedRRLP;
       
   888 	TBool SETRRC,AllowedRRC;
       
   889 	
       
   890 	iOldCapabilities->GetSETCapabilities(SETposTechnology,SETprefMethod,SETposProtocol);	
       
   891 	iAllowedCapabilities->GetSETCapabilities(AllowedposTechnology,AllowedprefMethod,AllowedposProtocol);	
       
   892 
       
   893 	SETposTechnology.GetPosTechnology(SETGpsSETAssisted,SETGpsSETBased,SETAutonomousGps,SETFLT,
       
   894 													   SETeOTD,SEToTDOA);
       
   895 	SETposProtocol.GetPosProtocol(SETTIA801,SETRRLP,SETRRC);
       
   896 //	SETprefMethod = COMASuplSETCapabilities::EOMANoPreferred; 
       
   897 
       
   898 	AllowedposTechnology.GetPosTechnology(AllowedGpsSETAssisted,AllowedGpsSETBased,AllowedAutonomousGps,AllowedFLT,
       
   899 													   AllowedeOTD,AllowedoTDOA);
       
   900 	SETposProtocol.GetPosProtocol(AllowedTIA801,AllowedRRLP,AllowedRRC);
       
   901 	AllowedprefMethod = COMASuplSETCapabilities::EOMANoPreferred; 
       
   902 
       
   903 	SETGpsSETAssisted &= AllowedGpsSETAssisted;
       
   904 	SETGpsSETBased &= AllowedGpsSETBased;
       
   905 	SETAutonomousGps &= AllowedAutonomousGps;
       
   906 	
       
   907 	SETFLT &= AllowedFLT; 
       
   908 	SETeOTD &=AllowedeOTD;
       
   909 	SEToTDOA &=AllowedoTDOA;
       
   910 	
       
   911 	SETTIA801 &= AllowedTIA801; 
       
   912 	SETRRLP &= AllowedRRLP;
       
   913 	SETRRC &= AllowedRRC;
       
   914 	
       
   915 	SETposTechnology.SetPosTechnology(SETGpsSETAssisted,SETGpsSETBased,SETAutonomousGps,SETFLT,
       
   916 													   SETeOTD,SEToTDOA);
       
   917 	
       
   918 	SETposProtocol.SetPosProtocol(SETTIA801,SETRRLP,SETRRC);
       
   919 	
       
   920 	//If client has restricted SETBased and still POS msg plugin sets SETBasedPreferred.....then 
       
   921 	// it as EOMANoPreferred
       
   922 	
       
   923 	if(SETprefMethod == COMASuplSETCapabilities::EOMAAGpsSETBasedPreferred && (!SETGpsSETBased ))
       
   924 		{
       
   925 			SETprefMethod = COMASuplSETCapabilities::EOMANoPreferred; 
       
   926 		}
       
   927 		
       
   928 	if(SETprefMethod == COMASuplSETCapabilities::EOMAAGpsSETAssitedPreferred  && (!SETGpsSETAssisted))
       
   929 		{
       
   930 			SETprefMethod = COMASuplSETCapabilities::EOMANoPreferred; 
       
   931 		}
       
   932 		
       
   933 	iOldCapabilities->SetSETCapabilities(SETposTechnology,SETprefMethod,SETposProtocol);	
       
   934 	
       
   935 	iTrace->Trace(_L("End of COMASuplPosInitState::ComputeCapabilities"), KTraceFileName, __LINE__); 															
       
   936 }
       
   937 
       
   938 // -----------------------------------------------------------------------------
       
   939 // COMASuplPosState::CancelOperation
       
   940 // Cancels Operation...which will be depend on derived class implementation
       
   941 // (other items were commented in a header).
       
   942 // -----------------------------------------------------------------------------
       
   943 //
       
   944 void COMASuplPosInitState::CancelOperation() 
       
   945 	{ 
       
   946 		 COMASuplStartState::CancelOperation();
       
   947 		 iTrace->Trace(_L("COMASuplPosState::CancelOperation..."), KTraceFileName, __LINE__); 							
       
   948 	}	
       
   949 
       
   950 // -----------------------------------------------------------------------------
       
   951 // COMASuplPosState::UpdateCapabilities
       
   952 //
       
   953 // (other items were commented in a header).
       
   954 // -----------------------------------------------------------------------------
       
   955 //
       
   956 void COMASuplPosInitState::UpdateCapabilities() 
       
   957 	{
       
   958 		if(!iPosRequestor)
       
   959 			{
       
   960 				return;
       
   961 			}
       
   962 			
       
   963 		TOMASuplPosTechnology  curPosTech;
       
   964 		COMASuplSETCapabilities::TOMASuplPrefMethod  curPrefMethod;
       
   965 		TOMASuplPosProtocol  curPosProtocol;
       
   966 		iCurSetCapabilities->GetSETCapabilities(curPosTech, curPrefMethod, curPosProtocol);
       
   967 		iOldCapabilities->SetSETCapabilities(curPosTech, curPrefMethod, curPosProtocol);
       
   968 	}
       
   969 	
       
   970 // -----------------------------------------------------------------------------
       
   971 // COMASuplPosState::IsGenerationInProgress
       
   972 //
       
   973 // (other items were commented in a header).
       
   974 // -----------------------------------------------------------------------------
       
   975 //
       
   976 TBool COMASuplPosInitState::IsGenerationInProgress()
       
   977 	{
       
   978 		return iGenerationStatus;
       
   979 	}
       
   980 
       
   981 // -----------------------------------------------------------------------------
       
   982 // COMASuplPosInitState::StartTimer
       
   983 // StartTimer...starts the timer ... 
       
   984 // (other items were commented in a header).
       
   985 // -----------------------------------------------------------------------------
       
   986 //
       
   987 void COMASuplPosInitState::StartTimer()
       
   988 {
       
   989 	iTrace->Trace(_L("COMASuplPosInitState::StartTimer..."), KTraceFileName, __LINE__); 							
       
   990 	if(!iPosPayloadPresent)
       
   991 		{
       
   992 			iTrace->Trace(_L("Timer Started"), KTraceFileName, __LINE__); 
       
   993 			COMASuplState::StartTimer();
       
   994 		}
       
   995     else
       
   996         {            
       
   997 			iTrace->Trace(_L("Timer Not Started"), KTraceFileName, __LINE__); 
       
   998         }
       
   999 }
       
  1000 
       
  1001 
       
  1002 TBool COMASuplPosInitState::IsPosPayloadPresent()
       
  1003 {
       
  1004 	if(iPosPayloadPresent)
       
  1005 	{
       
  1006 		return ETrue;	
       
  1007 	}
       
  1008 	else
       
  1009 	{
       
  1010 		return  EFalse;	
       
  1011 	}
       
  1012 	 
       
  1013 }
       
  1014 
       
  1015 // -----------------------------------------------------------------------------
       
  1016 // COMASuplPosInitState::StripPospayLoadL
       
  1017 // Strip the data if it exceeds more than 8 KB
       
  1018 // (other items were commented in a header).
       
  1019 // -----------------------------------------------------------------------------
       
  1020 //
       
  1021 void COMASuplPosInitState::StripPospayLoadL()
       
  1022 {
       
  1023 			HBufC8* payload;
       
  1024 			COMASuplPosPayload::TOMASuplPosPayloadType payloadType;
       
  1025 			
       
  1026 			iPosPayload->GetPosPayload(payload,payloadType);
       
  1027 			
       
  1028 			if(! payload) 
       
  1029 				{
       
  1030 					return;
       
  1031 				}
       
  1032 			
       
  1033 			TInt len = payload->Length();
       
  1034 			if(len > KMaxPosPayloadLength)  //Strip the data if it exceeds more than 8 Kb
       
  1035 				{
       
  1036 					HBufC8* remainingPospayloadData = HBufC8::NewL(len - KMaxPosPayloadLength);
       
  1037 					remainingPospayloadData->Des().Copy(payload->Des().Mid(KMaxPosPayloadLength));// Copy rest data
       
  1038 					iRemainingPospayload = static_cast <COMASuplPosPayload *>(iPosPayload->CloneL());	// Ownnership will not be with this class
       
  1039 					iRemainingPospayload->SetPosPayload(remainingPospayloadData,payloadType);			
       
  1040 					payload->Des().Copy(payload->Des().Left(KMaxPosPayloadLength));// Remove rest of data
       
  1041 					LogPacket(payload->Des());
       
  1042 				}
       
  1043 				
       
  1044 			//Remove following code after testing...	
       
  1045 			iPosPayload->GetPosPayload(payload,payloadType);
       
  1046 			len = payload->Length();
       
  1047 
       
  1048 }
       
  1049 
       
  1050 // -----------------------------------------------------------------------------
       
  1051 // COMASuplPosInitState::GetRemainingPospayLoadL
       
  1052 // Copies remaining PosPayload data to send with SUPL_POS
       
  1053 // Callee gets ownership....
       
  1054 // (other items were commented in a header).
       
  1055 // -----------------------------------------------------------------------------
       
  1056 //
       
  1057 COMASuplPosPayload* COMASuplPosInitState::GetRemainingPospayLoadL()
       
  1058 {
       
  1059 	return iRemainingPospayload;
       
  1060 }
       
  1061 
       
  1062 	
       
  1063 void COMASuplPosInitState::LogSETCapabilities()
       
  1064 	{
       
  1065 	
       
  1066 #ifdef PRINT_MESSAGE		
       
  1067 
       
  1068 		if(iSETCapabilities)
       
  1069 		{
       
  1070 			iTrace->Trace(_L("SET Capabilities in POS INIT....."), KTraceFileName, __LINE__);
       
  1071 			
       
  1072 			TOMASuplPosTechnology posTech;
       
  1073 			COMASuplSETCapabilities::TOMASuplPrefMethod prefMethod;
       
  1074 			TOMASuplPosProtocol posProtocol;
       
  1075 			
       
  1076 			if(iOldCapabilities)
       
  1077 			iOldCapabilities->GetSETCapabilities(posTech, prefMethod, posProtocol);
       
  1078 		
       
  1079 			TBuf <200> posTechStr;
       
  1080 			posTechStr.Append(_L("POS Technologies - "));
       
  1081 			TBool gpsSetAssisted, gpsSetBased, autonomousGps, AFLT, EOTD, OTDOA;
       
  1082 			posTech.GetPosTechnology(gpsSetAssisted, gpsSetBased, autonomousGps, AFLT, EOTD, OTDOA);
       
  1083 			
       
  1084 			if(gpsSetAssisted) posTechStr.Append(_L(" AGPS SET Assisted  "));
       
  1085 			if(gpsSetBased) posTechStr.Append(_L(" AGPS SET Based  "));
       
  1086 			if(autonomousGps) posTechStr.Append(_L(" Autonomous GPS  "));
       
  1087 			if(AFLT) posTechStr.Append(_L(" AFLT  "));
       
  1088 			if(EOTD) posTechStr.Append(_L(" EOTD  "));
       
  1089 			if(OTDOA) posTechStr.Append(_L(" OTDOA  "));
       
  1090 
       
  1091 			iTrace->Trace(posTechStr, KTraceFileName, __LINE__);
       
  1092 
       
  1093 			TBuf <80> prefMethodStr;
       
  1094 			prefMethodStr.Append(_L("Preferred Method - "));
       
  1095 
       
  1096 			switch(prefMethod)
       
  1097 			{
       
  1098 			case COMASuplSETCapabilities::EOMAAGpsSETAssitedPreferred:
       
  1099 				prefMethodStr.Append(_L(" AGPS SET Assisted Preferred"));
       
  1100 				break;
       
  1101 			case COMASuplSETCapabilities::EOMAAGpsSETBasedPreferred:
       
  1102 				prefMethodStr.Append(_L(" AGPS SET Based Preferred"));
       
  1103 				break;
       
  1104 			case COMASuplSETCapabilities::EOMANoPreferred:
       
  1105 				prefMethodStr.Append(_L(" No Preference"));
       
  1106 				break;
       
  1107 			}
       
  1108 			
       
  1109 			iTrace->Trace(prefMethodStr, KTraceFileName, __LINE__);
       
  1110 
       
  1111 			TBuf <80> posProtocolStr;
       
  1112 			posProtocolStr.Append(_L("POS Protocol - "));
       
  1113 			TBool tia801, rrlp, rrc;
       
  1114 			
       
  1115 			posProtocol.GetPosProtocol(tia801, rrlp, rrc);
       
  1116 			if(tia801) posProtocolStr.Append(_L(" TIA 801  "));
       
  1117 			if(rrlp) posProtocolStr.Append(_L(" RRLP  "));
       
  1118 			if(rrc) posProtocolStr.Append(_L(" RRC  "));
       
  1119 			
       
  1120 			iTrace->Trace(posProtocolStr, KTraceFileName, __LINE__);
       
  1121 		}
       
  1122 
       
  1123 		// Location ID
       
  1124 		if(iLocationId)
       
  1125 		{
       
  1126 			iTrace->Trace(_L("Location ID in POS_INIT......."), KTraceFileName, __LINE__);
       
  1127 			
       
  1128 			TBuf<50> locationIDTypeStr;
       
  1129 			locationIDTypeStr.Append(_L("Location ID Type - "));
       
  1130 			COMASuplLocationId::TOMASuplCellInfoType cellInfoType;
       
  1131 			COMASuplLocationId::TOMASuplStatus status;			
       
  1132 			TInt refMNC, refMcc, refCI, refLAC;
       
  1133 			TInt err;
       
  1134 			
       
  1135 			cellInfoType = iLocationId->SuplCellInfoType();
       
  1136 			switch(cellInfoType)
       
  1137 			{	
       
  1138 			case COMASuplLocationId::EGSM:
       
  1139 				locationIDTypeStr.Append(_L(" GSM "));
       
  1140 				iTrace->Trace(locationIDTypeStr, KTraceFileName, __LINE__);
       
  1141 
       
  1142 				COMASuplGSMCellInfo *gsmCellInfo ;
       
  1143 
       
  1144 				err = iLocationId->SuplLocationId(gsmCellInfo, status);
       
  1145 				if(KErrNone == err)
       
  1146 				{
       
  1147 					TBuf <100> gsmCellInfoStr;
       
  1148 					gsmCellInfoStr.Append(_L("GSM Cell Info - "));
       
  1149 					gsmCellInfo->SuplGSMCellInfo(refMNC, refMcc, refCI, refLAC);
       
  1150 					gsmCellInfoStr.Append(_L("MNC - "));
       
  1151 					gsmCellInfoStr.AppendNum(refMNC);
       
  1152 					gsmCellInfoStr.Append(_L(" MCC - "));
       
  1153 					gsmCellInfoStr.AppendNum(refMcc);
       
  1154 					gsmCellInfoStr.Append(_L(" CI - "));
       
  1155 					gsmCellInfoStr.AppendNum(refCI);
       
  1156 					gsmCellInfoStr.Append(_L(" LAC - "));
       
  1157 					gsmCellInfoStr.AppendNum(refLAC);
       
  1158 
       
  1159 					iTrace->Trace(gsmCellInfoStr, KTraceFileName, __LINE__);
       
  1160 				}
       
  1161 				break;
       
  1162 
       
  1163 			case COMASuplLocationId::EWCDMA:
       
  1164 				locationIDTypeStr.Append(_L(" WCDMA "));
       
  1165 				iTrace->Trace(locationIDTypeStr, KTraceFileName, __LINE__);
       
  1166 
       
  1167 				COMASuplCellInfo *wcdmaCellInfo ;
       
  1168 
       
  1169 				err = iLocationId->SuplLocationId(wcdmaCellInfo, status);
       
  1170 				if(KErrNone == err)
       
  1171 				{
       
  1172 					TBuf <100> wcdmaCellInfoStr;
       
  1173 					wcdmaCellInfoStr.Append(_L("WCDMA Cell Info - "));
       
  1174 					wcdmaCellInfo->SuplCellInfo(refMNC, refMcc, refCI);
       
  1175 					wcdmaCellInfoStr.Append(_L(" MNC - "));
       
  1176 					wcdmaCellInfoStr.AppendNum(refMNC);
       
  1177 					wcdmaCellInfoStr.Append(_L(" MCC - "));
       
  1178 					wcdmaCellInfoStr.AppendNum(refMcc);
       
  1179 					wcdmaCellInfoStr.Append(_L(" CI - "));
       
  1180 					wcdmaCellInfoStr.AppendNum(refCI);
       
  1181 
       
  1182 					iTrace->Trace(wcdmaCellInfoStr, KTraceFileName, __LINE__);
       
  1183 				}
       
  1184 
       
  1185 				break;
       
  1186 			}
       
  1187 			TBuf <60> locationIdStatusStr;
       
  1188 			locationIdStatusStr.Append(_L("Location ID Status - "));
       
  1189 			switch(status)
       
  1190 			{
       
  1191 			case COMASuplLocationId::EStale:
       
  1192 				locationIdStatusStr.Append(_L("Stale"));
       
  1193 				break;
       
  1194 			case COMASuplLocationId::ECurrent:
       
  1195 				locationIdStatusStr.Append(_L("Current"));
       
  1196 				break;
       
  1197 			case COMASuplLocationId::EUnknown:
       
  1198 				locationIdStatusStr.Append(_L("Unknown"));
       
  1199 				break;
       
  1200 			}
       
  1201 			iTrace->Trace(locationIdStatusStr, KTraceFileName, __LINE__);
       
  1202 		}
       
  1203 
       
  1204 
       
  1205 #endif
       
  1206 	}
       
  1207 	
       
  1208 void COMASuplPosInitState::LogPosPayloadData()
       
  1209 {
       
  1210 
       
  1211 #ifdef PRINT_MESSAGE
       
  1212 			
       
  1213 		if(iPosPayload)
       
  1214 		{
       
  1215 			TInt posPosPayLoadError = iPosPayload->Status();					
       
  1216 			if(posPosPayLoadError != KErrNone )
       
  1217 			{
       
  1218 				iTrace->Trace(_L("No POS Payload data provided for SUPL_POSINIT by POS message plugin"), KTraceFileName, __LINE__);	
       
  1219 				return;
       
  1220 			}
       
  1221 			
       
  1222 		iTrace->Trace(_L("**************** Start of SUPL_POSINIT PosPayLoad provided by POS message plugin **********************"), KTraceFileName, __LINE__);
       
  1223 
       
  1224 		HBufC8* payLoad = NULL;
       
  1225 		COMASuplPosPayload::TOMASuplPosPayloadType payLoadType;
       
  1226 		
       
  1227 		iPosPayload->GetPosPayload(payLoad,payLoadType);
       
  1228 		HBufC* payLoadBuffer = NULL; 
       
  1229 		if(payLoad)
       
  1230 			{
       
  1231 			TInt err;
       
  1232 			TRAP(err,payLoadBuffer = HBufC::NewL(payLoad->Length()));
       
  1233 			err = 0;
       
  1234 			payLoadBuffer->Des().Copy(payLoad->Des());
       
  1235 			}
       
  1236 		
       
  1237 		if(payLoadType == COMASuplPosPayload::ETIA801)
       
  1238 			{
       
  1239 			iTrace->Trace(_L("POS DATA Type - ETIA801 "), KTraceFileName, __LINE__);
       
  1240 			if(payLoadBuffer)
       
  1241 			  iTrace->Trace(payLoadBuffer->Des(),KTraceFileName, __LINE__);
       
  1242 			}
       
  1243 		else if(payLoadType == COMASuplPosPayload::ERRLP)
       
  1244 			{
       
  1245 			iTrace->Trace(_L("POS DATA Type - ERRLP "), KTraceFileName, __LINE__);
       
  1246 			if(payLoadBuffer)
       
  1247 				iTrace->Trace(payLoadBuffer->Des(),KTraceFileName, __LINE__);	
       
  1248 			}
       
  1249 		else if(payLoadType == COMASuplPosPayload::ERRC)
       
  1250 			{
       
  1251 			iTrace->Trace(_L("POS DATA Type - ERRC "), KTraceFileName, __LINE__);
       
  1252 			if(payLoadBuffer)
       
  1253 				iTrace->Trace(payLoadBuffer->Des(),KTraceFileName, __LINE__);		
       
  1254 			}
       
  1255 		delete payLoadBuffer;
       
  1256 		payLoadBuffer = NULL;
       
  1257 		}
       
  1258 #endif					
       
  1259 }
       
  1260 
       
  1261 void COMASuplPosInitState::LogPosition()
       
  1262 {
       
  1263 
       
  1264 #ifdef PRINT_MESSAGE
       
  1265  	if(!iPosition)
       
  1266  		return;
       
  1267  	
       
  1268 	if(KErrNone != iPosition->Status())
       
  1269 		{
       
  1270 			iTrace->Trace(_L("No Position is provided by POS message plugin for SUPL_POSINIT "), KTraceFileName, __LINE__);	
       
  1271 			return;
       
  1272 		}
       
  1273 
       
  1274 	  	TBuf <300> positionLog;
       
  1275 	    TOMASuplUtcTime utcTime;
       
  1276 	    TOMASuplPositionEstimate posEstimate;
       
  1277 		TDateTime lDateTime;
       
  1278 		TInt  	  zoneCode;
       
  1279 		TInt      zone;
       
  1280 		TInt error;
       
  1281 		iTrace->Trace(_L("-------Start of Position in SUPL_POSINIT ----------"), KTraceFileName, __LINE__);			        
       
  1282 		
       
  1283 	    iPosition->GetPosition(utcTime,posEstimate );	
       
  1284 	    utcTime.GetUtcTime(lDateTime,zoneCode,zone);		
       
  1285 	    
       
  1286 		positionLog.Append(_L("UTC Time Log : "));
       
  1287 		positionLog.Append(_L("Year : "));
       
  1288 		positionLog.AppendNum(lDateTime.Year());
       
  1289 		positionLog.Append(_L("Month : "));
       
  1290 		positionLog.AppendNum(lDateTime.Month());
       
  1291 		positionLog.Append(_L("Day : "));
       
  1292 		positionLog.AppendNum(lDateTime.Day());	
       
  1293 		positionLog.Append(_L("Hour : "));
       
  1294 		positionLog.AppendNum(lDateTime.Hour());	
       
  1295 		positionLog.Append(_L("Minute : "));
       
  1296 		positionLog.AppendNum(lDateTime.Minute());	
       
  1297 		positionLog.Append(_L("Second : "));
       
  1298 		positionLog.AppendNum(lDateTime.Second());	
       
  1299 		positionLog.Append(_L("MicroSecond : "));
       
  1300 		positionLog.AppendNum(lDateTime.MicroSecond());	
       
  1301 		positionLog.Append(_L("Zone Code : "));
       
  1302 		positionLog.AppendNum(zoneCode);	
       
  1303 		positionLog.Append(_L("Zone : "));
       
  1304 		positionLog.AppendNum(zone);
       
  1305 			
       
  1306 		iTrace->Trace(positionLog, KTraceFileName, __LINE__); 
       
  1307 		
       
  1308 		TOMASuplPositionEstimate::TOMASuplLatitudeSign  latSign;
       
  1309 	    TInt               latitude;
       
  1310 	    TInt               longitude;
       
  1311 	    posEstimate.GetPositionEstimate(latSign,latitude,longitude);
       
  1312 	    
       
  1313 	    positionLog.Copy(_L("Position Estimate : "));
       
  1314 		positionLog.Append(_L(" latitude Sign : "));
       
  1315 		positionLog.AppendNum(latSign);
       
  1316 		positionLog.Append(_L(" Latitude : "));
       
  1317 		positionLog.AppendNum(latitude);
       
  1318 		positionLog.Append(_L(" Longitude : "));
       
  1319 		positionLog.AppendNum(longitude);	
       
  1320 		
       
  1321 		iTrace->Trace(positionLog, KTraceFileName, __LINE__); 
       
  1322 
       
  1323 		TOMASuplUncertainty uncertainty;
       
  1324 		error = posEstimate.GetUncertainty(uncertainty);
       
  1325 		if(!error)
       
  1326 			{
       
  1327 			TInt uncertSemiMajor;
       
  1328 	       	TInt uncertSemiMinor;
       
  1329 	       	TInt orientMajorAxis;
       
  1330 	       	uncertainty.GetUncertainty(uncertSemiMajor,uncertSemiMinor,orientMajorAxis);
       
  1331 	       	
       
  1332 	       	positionLog.Copy(_L("Uncertainity Information of Position "));
       
  1333 	       	positionLog.Append(_L(" Uncertainity Semi Major : "));
       
  1334 			positionLog.AppendNum(uncertSemiMajor);
       
  1335 			positionLog.Append(_L(" Uncertainity Semi Minor : "));
       
  1336 			positionLog.AppendNum(uncertSemiMinor);
       
  1337 			positionLog.Append(_L(" Orientation Major Axis : "));
       
  1338 			positionLog.AppendNum(orientMajorAxis);	
       
  1339 			iTrace->Trace(positionLog, KTraceFileName, __LINE__);
       
  1340 			}
       
  1341 		else
       
  1342 			{
       
  1343 				iTrace->Trace(_L("Error in retriving Uncertinity"), KTraceFileName, __LINE__);
       
  1344 			}	
       
  1345 
       
  1346 		// Retrieve Confidence
       
  1347 		TInt confidence;
       
  1348 		error = posEstimate.GetConfidence(confidence);
       
  1349 		if(!error)
       
  1350 			{
       
  1351 			positionLog.Copy(_L("Confidence in Position : "));
       
  1352 			positionLog.AppendNum(confidence);	
       
  1353 			iTrace->Trace(positionLog, KTraceFileName, __LINE__);
       
  1354 			}
       
  1355 		else
       
  1356 			{
       
  1357 		 	iTrace->Trace(_L("Error in retriving Confidence"), KTraceFileName, __LINE__);
       
  1358 			}	
       
  1359 
       
  1360 		TOMASuplAltitudeInfo altitudeInfo;
       
  1361 		error = posEstimate.GetAltitudeInfo(altitudeInfo);
       
  1362 		if(!error)
       
  1363 			{
       
  1364 			TOMASuplAltitudeInfo::TOMASuplAltitudeDirection altDirection;
       
  1365 	    	TInt altitude;
       
  1366 	       	TInt altUncert;
       
  1367 	       	altitudeInfo.GetAltitudeInfo(altDirection,altitude,altUncert);
       
  1368 	       	
       
  1369 	       	positionLog.Copy(_L("Altitude Information of Position "));
       
  1370 	       	
       
  1371 	       	positionLog.Append(_L("Altitude Direction : "));
       
  1372 			positionLog.AppendNum(altDirection);
       
  1373 			positionLog.Append(_L(" Altitude : "));
       
  1374 			positionLog.AppendNum(altitude);
       
  1375 			positionLog.Append(_L(" Altitude Uncertainity : "));
       
  1376 			positionLog.AppendNum(altUncert);
       
  1377 			iTrace->Trace(positionLog, KTraceFileName, __LINE__);
       
  1378 			}
       
  1379 		else
       
  1380 			{
       
  1381 			iTrace->Trace(_L("Error in retriving AltitudeInfo"), KTraceFileName, __LINE__);
       
  1382 			}	
       
  1383 
       
  1384 
       
  1385 		COMASuplVelocity* velocity = NULL;
       
  1386 	    error = iPosition->GetVelocity(velocity);
       
  1387 	    if(!error)			
       
  1388 	    	{
       
  1389 	    	iTrace->Trace(_L("Velocity Information for position in SUPL_POS_INIT "), KTraceFileName, __LINE__);
       
  1390 	    	LogVelocity(velocity);
       
  1391 	    	}
       
  1392 		else
       
  1393 			{
       
  1394 			iTrace->Trace(_L("Error in retriving Velocity"), KTraceFileName, __LINE__);
       
  1395 			}	
       
  1396 			
       
  1397 		iTrace->Trace(_L("-------End of Position in SUPL_POSINIT ----------"), KTraceFileName, __LINE__);			        			
       
  1398 
       
  1399 #endif					
       
  1400 
       
  1401 }
       
  1402 
       
  1403 void COMASuplPosInitState::LogReqAssistanceData()
       
  1404 {
       
  1405 
       
  1406 #ifdef PRINT_MESSAGE
       
  1407 		 	if(!iReqAsstData)
       
  1408 		 		return;
       
  1409  	
       
  1410 			if(KErrNone != iReqAsstData->Status())
       
  1411 				{
       
  1412 					iTrace->Trace(_L("No Assistance data is provided by POS message plugin for SUPL_POSINIT "), KTraceFileName, __LINE__);	
       
  1413 					return;
       
  1414 				}
       
  1415 				
       
  1416 			iTrace->Trace(_L("-------Start of Assistance data in SUPL_POSINIT ----------"), KTraceFileName, __LINE__);			        	
       
  1417 			TOMASuplNavigationModel navModel;
       
  1418 			TBool almanacReq, utcModel, ionModel, dgpsCorrect, 
       
  1419 				  refeLocation, referenceTimeRequested,acquisition, realTime;
       
  1420 					
       
  1421 			iReqAsstData->GetReqAsstData(almanacReq, utcModel, ionModel, dgpsCorrect, refeLocation, 
       
  1422 						 referenceTimeRequested, acquisition, realTime);
       
  1423 						 
       
  1424 			TBuf <300> reqAsstDataStr;
       
  1425 			reqAsstDataStr.Append(_L("Requested Assistance Data - "));
       
  1426 						 
       
  1427 			if(almanacReq) reqAsstDataStr.Append(_L(" Almanac Requested "));
       
  1428 			if(utcModel) reqAsstDataStr.Append(_L(" UTC Model Requested "));
       
  1429 			if(ionModel) reqAsstDataStr.Append(_L(" Ionospheric Model Requested "));
       
  1430 			if(dgpsCorrect) reqAsstDataStr.Append(_L(" DGPS Corrections "));
       
  1431 			if(refeLocation) reqAsstDataStr.Append(_L(" Reference Location "));
       
  1432 			if(referenceTimeRequested) reqAsstDataStr.Append(_L(" Reference Time "));
       
  1433 			if(acquisition) reqAsstDataStr.Append(_L(" Acquisition Assistance "));
       
  1434 			if(realTime) reqAsstDataStr.Append(_L(" Real Time Integrity "));
       
  1435 			
       
  1436 			iTrace->Trace(reqAsstDataStr, KTraceFileName, __LINE__); 			 
       
  1437 			
       
  1438 			
       
  1439 			if(KErrNone == iReqAsstData->GetNavigationData(navModel))
       
  1440 			{
       
  1441 				TBuf <80> satInfoStr;
       
  1442 				satInfoStr.Append(_L("Satellite Info  - "));
       
  1443 
       
  1444 				TInt gpsWeek, gpsToe, NSAT, toeLimit;
       
  1445 				navModel.GetNavigationModel(gpsWeek, gpsToe, NSAT, toeLimit);
       
  1446 				
       
  1447 				if(gpsWeek) satInfoStr.Append(_L(" GPS Week "));
       
  1448 				if(gpsToe) satInfoStr.Append(_L(" GPS Toe "));
       
  1449 				if(NSAT) satInfoStr.Append(_L(" NSAT "));
       
  1450 				if(toeLimit) satInfoStr.Append(_L(" TOE Limit"));
       
  1451 				
       
  1452 				iTrace->Trace(satInfoStr, KTraceFileName, __LINE__);
       
  1453 				
       
  1454 				RArray<TOMASuplSatelliteInfoElement> satEleArr;
       
  1455 				
       
  1456 				if(KErrNone == navModel.GetSatInfoElement(satEleArr))
       
  1457 				{
       
  1458 					TInt count = satEleArr.Count();
       
  1459 					TBuf <50> satInfoElementStr;
       
  1460 					satInfoElementStr.Append(_L("Number of Satellite Info Elements - "));
       
  1461 					satInfoElementStr.AppendNum(count);
       
  1462 					iTrace->Trace(satInfoElementStr, KTraceFileName, __LINE__); 
       
  1463 					if(count > 0)
       
  1464 					{
       
  1465 						
       
  1466 						TOMASuplSatelliteInfoElement satInfoEle;
       
  1467 						
       
  1468 						for(TInt i = 0; i < count; i ++)
       
  1469 						{
       
  1470 							TInt err = navModel.GetSatInfoElement(satInfoEle, i);
       
  1471 							TInt satId,iode;
       
  1472 							
       
  1473 							satInfoEle.GetSatInfoElement(satId, iode);
       
  1474 							
       
  1475 							TBuf<50> satInfoEleStr;
       
  1476 							satInfoEleStr.Append(_L(" Satellite Info Element -  "));
       
  1477 							satInfoEleStr.AppendNum(satId);
       
  1478 							satInfoEleStr.Append(_L("    "));
       
  1479 							satInfoEleStr.AppendNum(iode);
       
  1480 							iTrace->Trace(satInfoEleStr, KTraceFileName, __LINE__); 
       
  1481 						}
       
  1482 					}
       
  1483 				}
       
  1484 				else
       
  1485 				{
       
  1486 					iTrace->Trace(_L("No Satelite Info OR error in retriving Satelite Info "), KTraceFileName, __LINE__); 
       
  1487 				}
       
  1488 				satEleArr.Close();
       
  1489 			}
       
  1490 			else
       
  1491 			{
       
  1492 				iTrace->Trace(_L("Error in Getting Navigationl Data... "), KTraceFileName, __LINE__); 
       
  1493 			}
       
  1494 
       
  1495 	iTrace->Trace(_L("------- End of Assistance data in SUPL_POSINIT ----------"), KTraceFileName, __LINE__);			        	
       
  1496 	
       
  1497 #endif	
       
  1498 }
       
  1499 
       
  1500 void COMASuplPosInitState::LogVelocity(COMASuplVelocity* 
       
  1501 #ifdef PRINT_MESSAGE
       
  1502 velocity
       
  1503 #endif
       
  1504 )
       
  1505 {
       
  1506 
       
  1507 #ifdef PRINT_MESSAGE
       
  1508 		if(velocity)
       
  1509 		{		
       
  1510 		
       
  1511 		TBuf<256> msg;
       
  1512 		TOMASuplVelocityType velocityType = velocity->VelType();
       
  1513 		COMASuplHorizVelocity* horizVelocity = velocity->Velocity();
       
  1514 		TUint16 bearing;
       
  1515 		TUint16 horSpeed;
       
  1516 		switch(velocityType)	
       
  1517 			{
       
  1518 				case  EHorizVelocity:
       
  1519 					{
       
  1520 					iTrace->Trace(_L("Velocity Type : EHorizVelocity - Values "), KTraceFileName, __LINE__);
       
  1521 					horizVelocity->GetHorizVel(bearing,horSpeed);
       
  1522 					
       
  1523 					msg.Append(_L("Bearing : "));
       
  1524 					msg.AppendNum(bearing);
       
  1525 					msg.Append(_L("Horizontal Speed : "));
       
  1526 					msg.AppendNum(horSpeed);
       
  1527 					iTrace->Trace(msg, KTraceFileName, __LINE__);
       
  1528 					break;
       
  1529 					}
       
  1530 				case EHorizAndVertVelocity:
       
  1531 					{
       
  1532 					TUint8 verDirect;
       
  1533 					TUint8 verSpeed;
       
  1534 					COMASuplHorizAndVertVelocity* horizVertVel = (COMASuplHorizAndVertVelocity*)horizVelocity;
       
  1535 					horizVertVel->GetHorizAndVertVel(bearing,horSpeed,verDirect,verSpeed);
       
  1536 					
       
  1537 					iTrace->Trace(_L("Velocity Type : EHorizVelocity - Values "), KTraceFileName, __LINE__);
       
  1538 										
       
  1539 					msg.Append(_L("Bearing : "));
       
  1540 					msg.AppendNum(bearing);
       
  1541 					msg.Append(_L("Horizontal Speed : "));
       
  1542 					msg.AppendNum(horSpeed);
       
  1543 					msg.Append(_L("Vertical Direction : "));
       
  1544 					msg.AppendNum(verDirect);
       
  1545 					msg.Append(_L("Vertical Speed : "));
       
  1546 					msg.AppendNum(verSpeed);					
       
  1547 					iTrace->Trace(msg, KTraceFileName, __LINE__);
       
  1548 					
       
  1549 					break;
       
  1550 					}
       
  1551 				case EHorizUncertVelocity: 
       
  1552 					{
       
  1553 					TUint8 uncertSpeed;
       
  1554 					COMASuplHorizUncertVelocity* horizUncertVel = (COMASuplHorizUncertVelocity*)horizVelocity;
       
  1555 	
       
  1556 					horizUncertVel->GetHorizUncertVel(bearing,horSpeed,uncertSpeed);	
       
  1557 					
       
  1558 					iTrace->Trace(_L("Velocity Type : EHorizUncertVelocity - Values "), KTraceFileName, __LINE__);
       
  1559 										
       
  1560 					msg.Append(_L("Bearing : "));
       
  1561 					msg.AppendNum(bearing);
       
  1562 					msg.Append(_L("Horizontal Speed : "));
       
  1563 					msg.AppendNum(horSpeed);
       
  1564 					msg.Append(_L("Uncertainity Speed : "));
       
  1565 					msg.AppendNum(uncertSpeed);
       
  1566 							
       
  1567 					iTrace->Trace(msg, KTraceFileName, __LINE__);
       
  1568 					
       
  1569 					break;
       
  1570 					}
       
  1571 				case EHorizAndVertUncertVelocity:
       
  1572 					{
       
  1573 					TUint8  verDirect;
       
  1574 					TUint8  verSpeed;
       
  1575 					TUint8  horizUncertSpeed;
       
  1576 					TUint8  vertUncertSpeed;
       
  1577 										
       
  1578 					COMASuplHorizAndVertUncertVelocity* horizVertUncertVel = (COMASuplHorizAndVertUncertVelocity*)horizVelocity;
       
  1579 
       
  1580 					horizVertUncertVel->GetHorizVertUncertVel(bearing,horSpeed,verDirect,verSpeed,
       
  1581 																horizUncertSpeed,vertUncertSpeed);
       
  1582 					
       
  1583 					iTrace->Trace(_L("Velocity Type : EHorizAndVertUncertVelocity - Values "), KTraceFileName, __LINE__);
       
  1584 										
       
  1585 					msg.Append(_L("Bearing : "));
       
  1586 					msg.AppendNum(bearing);
       
  1587 					msg.Append(_L("Horizontal Speed : "));
       
  1588 					msg.AppendNum(horSpeed);
       
  1589 					msg.Append(_L("Vertical Direction : "));
       
  1590 					msg.AppendNum(verDirect);
       
  1591 					msg.Append(_L("Vertical Speed : "));
       
  1592 					msg.AppendNum(verSpeed);					
       
  1593 					msg.Append(_L("Horiz Uncertain Speed : "));
       
  1594 					msg.AppendNum(horizUncertSpeed);
       
  1595 					msg.Append(_L("Vertical Uncertain Speed : "));
       
  1596 					msg.AppendNum(vertUncertSpeed);					
       
  1597 					iTrace->Trace(msg, KTraceFileName, __LINE__);																					
       
  1598 																
       
  1599 				    break;																
       
  1600 					}
       
  1601 			}
       
  1602 		}
       
  1603 #endif		
       
  1604 }
       
  1605 
       
  1606 void COMASuplPosInitState::LogPacket(const TDesC8& 
       
  1607 #ifdef PRINT_MESSAGE
       
  1608 aPacket
       
  1609 #endif
       
  1610 )
       
  1611 {
       
  1612 
       
  1613 #ifdef PRINT_MESSAGE
       
  1614             RFile file;
       
  1615             RFs   fs;
       
  1616             TInt cErr=fs.Connect();
       
  1617             
       
  1618             TInt fErr = file.Open(fs,_L("c:\\logs\\epos\\POSINITpacket.txt"),EFileWrite|EFileShareAny);
       
  1619 			if (fErr == KErrNotFound)
       
  1620 			{                            
       
  1621 				file.Create(fs, _L("c:\\logs\\epos\\POSINITpacket.txt"), EFileWrite|EFileShareAny);
       
  1622 				fErr = file.Open(fs,_L("c:\\logs\\epos\\POSINITpacket.txt"), EFileWrite|EFileShareAny);
       
  1623 			}
       
  1624 
       
  1625 			TInt aPos;
       
  1626 			file.Seek(ESeekEnd, aPos);
       
  1627 			file.Write(aPacket);
       
  1628 			file.Close();
       
  1629 			fs.Close();
       
  1630 #endif		
       
  1631 }
       
  1632 
       
  1633 void COMASuplPosInitState::PrintHex(const TDesC8& 
       
  1634 #ifdef PRINT_MESSAGE
       
  1635 aBuffer
       
  1636 #endif
       
  1637 ,
       
  1638 TInt 
       
  1639 #ifdef PRINT_MESSAGE
       
  1640 aLine
       
  1641 #endif
       
  1642 )
       
  1643 	{
       
  1644 #ifdef PRINT_MESSAGE
       
  1645 			TBuf<256> buffer;
       
  1646 			TBuf<2> buff;
       
  1647 			_LIT16(KFormat1,"%02x");
       
  1648 			TInt len = aBuffer.Length();
       
  1649 			for(TInt i = 0 ; i <len; i++)
       
  1650 				{
       
  1651 					buff.Zero();
       
  1652 					buff.Format(KFormat1,aBuffer[i]);
       
  1653 					buffer.Append(buff);	
       
  1654 					buffer.Append(_L(" "));	
       
  1655 				}
       
  1656 
       
  1657 				iTrace->Trace(buffer, KTraceFileName, aLine); 											
       
  1658 #endif
       
  1659 	}
       
  1660 	
       
  1661 void COMASuplPosInitState::SetTriggerSessionFlag(TBool aTriggerFlag)
       
  1662     {
       
  1663     iTriggerFlag = aTriggerFlag;                
       
  1664     }        
       
  1665 
       
  1666 TBool COMASuplPosInitState::GetTriggerSessionFlag()
       
  1667     {                
       
  1668     return iTriggerFlag;
       
  1669     }            
       
  1670 void COMASuplPosInitState::CopyLocationidToLocationId2L(COMASuplLocationIdVer2* aLocationId2)
       
  1671     {
       
  1672     
       
  1673     COMASuplLocationId::TOMASuplCellInfoType cellType = iLocationId->SuplCellInfoType();
       
  1674     if( cellType == COMASuplLocationId::EGSM)
       
  1675         {
       
  1676             TInt MNC,MCC,CI,Lac;
       
  1677             COMASuplGSMCellInfo* cellInfo;
       
  1678             COMASuplLocationId::TOMASuplStatus status;
       
  1679             iLocationId->SuplLocationId(cellInfo, status);
       
  1680             cellInfo->SuplGSMCellInfo(MNC,MCC,CI,Lac);
       
  1681             
       
  1682             COMASuplGSMCellInfo* gsmCellInfo = COMASuplGSMCellInfo::NewL();
       
  1683             gsmCellInfo->SetSuplGSMCellInfo(MNC,MCC,CI,Lac);
       
  1684             aLocationId2->SetSuplLocationId(gsmCellInfo, status);
       
  1685         }
       
  1686     else
       
  1687         {
       
  1688             TInt MNC,MCC,CI;
       
  1689             COMASuplCellInfo* cellInfo;
       
  1690             COMASuplLocationId::TOMASuplStatus status;
       
  1691             iLocationId->SuplLocationId(cellInfo, status);
       
  1692             cellInfo->SuplCellInfo(MNC,MCC,CI);
       
  1693             
       
  1694             COMASuplCellInfo* wcdmaCellInfo = COMASuplCellInfo::NewL();
       
  1695             wcdmaCellInfo->SetSuplCellInfo(MNC,MCC,CI);
       
  1696             aLocationId2->SetSuplLocationId(wcdmaCellInfo, status);
       
  1697         }
       
  1698 
       
  1699 
       
  1700     }
       
  1701 //  End of File
       
  1702 
       
  1703 
       
  1704