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