networkprotocolmodules/suplproxyprotocolmodule/clientapi/suplposmsgplugin/src/lbsrequesthandler.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Class implementation of CSuplPosRequestHandler
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "lbsrequesthandler.h"
       
    21 #include "netpmutils.h"
       
    22 #include "lbsdevloggermacros.h"
       
    23 
       
    24 #include <lbs/epos_comasuplvelocity.h>
       
    25 #include <lbs/epos_comasuplreqasstdata.h>
       
    26 #include <lbs/epos_comasuplsetcapabilities.h>
       
    27 #include <lbs/epos_comasuplpospayload.h>
       
    28 #include <lbs/epos_eomasuplposerrors.h>
       
    29 #include <lbs/lbsnetcommon.h>
       
    30 
       
    31 _LIT(KPosPanicCategory, "SuplPosRequestHandler");
       
    32 
       
    33 //-----------------------------------------------------------------------------
       
    34 // CSuplPosRequestHandler
       
    35 //-----------------------------------------------------------------------------
       
    36 
       
    37 // Default constructor 
       
    38  CSuplPosRequestHandler::CSuplPosRequestHandler(MRequestHandlerObserver& aObserver, RSuplProxyPosSubSession& aSubSession) 
       
    39     : CActive(EPriorityStandard), iSubSession(aSubSession), iObserver(aObserver)
       
    40     {
       
    41 	LBSLOG(ELogP1, "CSuplPosRequestHandler::CSuplPosRequestHandler() Begin\n");
       
    42     CActiveScheduler::Add(this);
       
    43 	LBSLOG(ELogP1, "CSuplPosRequestHandler::CSuplPosRequestHandler() End\n");
       
    44     }
       
    45 
       
    46   // Static constructor
       
    47  CSuplPosRequestHandler* CSuplPosRequestHandler::NewL(MRequestHandlerObserver& aObserver, RSuplProxyPosSubSession& aSubSession)
       
    48     {
       
    49 	LBSLOG(ELogP1, "CSuplPosRequestHandler::NewL() Begin\n");
       
    50     CSuplPosRequestHandler* self = new (ELeave) CSuplPosRequestHandler(aObserver, aSubSession);
       
    51 	LBSLOG(ELogP1, "CSuplPosRequestHandler::NewL() End\n");
       
    52     return self;
       
    53     }
       
    54 
       
    55  // Destructor
       
    56  CSuplPosRequestHandler::~CSuplPosRequestHandler()
       
    57     {
       
    58 	LBSLOG(ELogP1, "CSuplPosRequestHandler::~CSuplPosRequestHandler() Begin\n");
       
    59 
       
    60     delete iPosPayload;
       
    61     iPosPayload = NULL;
       
    62     
       
    63     Cancel();
       
    64 
       
    65 	LBSLOG(ELogP1, "CSuplPosRequestHandler::~CSuplPosRequestHandler() End\n");
       
    66     }
       
    67 
       
    68 /**
       
    69  * Start the position request. 
       
    70  * @param aPosition 	holder for the position.
       
    71  * @param aStatus		client request status
       
    72  */
       
    73  void CSuplPosRequestHandler::GetPositionL(COMASuplPosition* aPosition)
       
    74     { 
       
    75 	LBSLOG(ELogP1, "CSuplPosRequestHandler::GetPositionL() Begin\n");
       
    76     __ASSERT_ALWAYS(!IsActive(), User::Leave(KErrInUse));
       
    77     __ASSERT_ALWAYS(aPosition, User::Leave(KErrArgument));
       
    78     __ASSERT_ALWAYS(iSubSession.SubSessionHandle(), User::Leave(KErrBadHandle));    
       
    79     // store the position holder to fill in on completion:
       
    80     iOmaPosition = aPosition;
       
    81     // Make request to subsession
       
    82     iStatus = KRequestPending;
       
    83     iSubSession.GetPositionL(iStatus, iPosition);	
       
    84     iRequestOutstanding = EGetPosition;
       
    85     SetActive();
       
    86 	LBSLOG(ELogP1, "CSuplPosRequestHandler::GetPositionL() End\n");
       
    87     }
       
    88 
       
    89  
       
    90  /**
       
    91   * Start the suplinfo request. 
       
    92   * @param aPosition 	holder for the position.
       
    93   * @param aStatus		client request status
       
    94   */
       
    95 void CSuplPosRequestHandler::GetSuplInfoL(COMASuplInfoRequestList* aSuplInfoRequestList)
       
    96 	{ 
       
    97 	LBSLOG(ELogP1, "CSuplPosRequestHandler::GetSuplInfoL() Begin\n");
       
    98 	__ASSERT_ALWAYS(!IsActive(), User::Leave(KErrInUse));
       
    99 	__ASSERT_ALWAYS(aSuplInfoRequestList, User::Leave(KErrArgument));
       
   100 	__ASSERT_ALWAYS(iSubSession.SubSessionHandle(), User::Leave(KErrBadHandle));  
       
   101 	// store the position holder to fill in on completion:
       
   102 	iSuplInfoReqList = aSuplInfoRequestList;
       
   103 	iRequestOutstanding = EGetSuplInfo;
       
   104 	__ASSERT_DEBUG(iPosPayload == NULL, User::Leave(KErrGeneral)); 
       
   105 	SetRequestMaskFromSuplInfoListL();
       
   106 	if(iSuplInfoRequestData.RequestMask() != 0)
       
   107 		{
       
   108 		// Make request to subsession 
       
   109 		if(iSuplInfoRequestData.RequestMask() & TSuplInfoRequestData::ERequestItemPosPayload)	// contains pospayload request
       
   110 			{
       
   111 			// allocate buffer to hold encoded payload
       
   112 			iPosPayload = HBufC8::NewL(KMaxOutgoingPosPayloadLength);
       
   113 			}
       
   114 		iStatus = KRequestPending;
       
   115 		iSubSession.GetSuplInfoL(iStatus, iSuplInfoRequestData, iPosPayload);
       
   116 		SetActive();
       
   117 		}
       
   118 	else	// we aren't going to ask the SPPM for any data, just self-complete
       
   119 		{
       
   120 		iStatus = KRequestPending;
       
   121 		TRequestStatus* pStat = &iStatus;
       
   122 		User::RequestComplete(pStat, KErrNone);
       
   123 		SetActive();		
       
   124 		}
       
   125 	LBSLOG(ELogP1, "CSuplPosRequestHandler::GetSuplInfoL() End\n");
       
   126 	}
       
   127 
       
   128  /**
       
   129   * From CActive. Called when request is complete
       
   130   */
       
   131  void CSuplPosRequestHandler::RunL()
       
   132     {    
       
   133 	LBSLOG3(ELogP1, "CSuplPosRequestHandler::RunL(request=%d result=%d) Begin\n", iRequestOutstanding, iStatus.Int());
       
   134     TInt result = iStatus.Int();
       
   135     
       
   136     switch(iRequestOutstanding)		// there can only be a single async request outstanding
       
   137     	{
       
   138     	case EGetPosition:
       
   139     		{   		
       
   140     	    // Notify observer that request completed:
       
   141     	    if(result == KErrNone)
       
   142     	    	{
       
   143     	    	FillOMAPositionL(iPosition, iOmaPosition);
       
   144     	    	}
       
   145 
       
   146     	    // tell the plugin
       
   147     	    iObserver.OnGetPositionComplete(result);  
       
   148     	    
       
   149     	    iOmaPosition = NULL;
       
   150     	    break;
       
   151     		}
       
   152     	case EGetSuplInfo:
       
   153     		{
       
   154     	    // Notify observer that request completed:
       
   155     	    if(result == KErrNone)
       
   156     	    	{
       
   157     	    	result = FillSuplInfoListL();
       
   158     	    	}
       
   159     	    else
       
   160     	    	{
       
   161     	    	delete iPosPayload;
       
   162     	    	iPosPayload = NULL;
       
   163     	    	}
       
   164     	    // tell the plugin
       
   165     	    iObserver.OnGetSuplInfoComplete(result);
       
   166     	    iSuplInfoReqList = NULL;    		
       
   167     		break;
       
   168     		}
       
   169     	case ENone:	
       
   170     	default:
       
   171     		{
       
   172     		__ASSERT_ALWAYS(EFalse, User::Panic(KPosPanicCategory, KErrUnknown));
       
   173     		break;
       
   174     		}
       
   175     	}
       
   176     // no request outstanding
       
   177     iRequestOutstanding = ENone;
       
   178 	LBSLOG(ELogP1, "CSuplPosRequestHandler::RunL() End\n");
       
   179     }
       
   180 
       
   181 /**
       
   182 * From CActive. Cancels the outstanding request.
       
   183 */
       
   184  void CSuplPosRequestHandler::DoCancel()
       
   185     {    
       
   186 	LBSLOG(ELogP1, "CSuplPosRequestHandler::DoCancel() Begin\n");
       
   187     
       
   188     // Cancel this request in the server and complete the
       
   189     // outstanding observer request immediately.
       
   190     
       
   191     switch(iRequestOutstanding)     // there can only be a single async request outstanding
       
   192         {
       
   193         case EGetPosition:
       
   194             {
       
   195                 iSubSession.CancelGetPosition();
       
   196                 iObserver.OnGetPositionComplete(KErrCancel);
       
   197                 break;
       
   198             }
       
   199         case EGetSuplInfo:
       
   200             {
       
   201                 iSubSession.CancelGetSuplInfo();
       
   202                 iObserver.OnGetSuplInfoComplete(KErrCancel);
       
   203                 break;
       
   204             }
       
   205         default:
       
   206             {
       
   207             //Behaviour expected by SUPL FW : If there is no outstanding request when a 
       
   208             //cancel request is received, no action is taken.
       
   209             }
       
   210         }
       
   211     // no request outstanding
       
   212     iRequestOutstanding = ENone;
       
   213 	LBSLOG(ELogP1, "CSuplPosRequestHandler::DoCancel() End\n");
       
   214     }
       
   215 
       
   216 /**
       
   217 * From CActive. Calls this function if RunL() function leaves
       
   218 */
       
   219  TInt CSuplPosRequestHandler::RunError(TInt aError)
       
   220     {
       
   221 	LBSLOG(ELogP1, "CSuplPosRequestHandler::RunError() Begin and End\n");
       
   222     return aError;
       
   223     }
       
   224  
       
   225 /*
       
   226  * Fills in the stored OMA position structure from the lbs position structure received
       
   227  */
       
   228  void CSuplPosRequestHandler::FillOMAPositionL(const TPositionInfoBase& aLbsPosition, COMASuplPosition* aSuplPosition)
       
   229 	{
       
   230 	LBSLOG(ELogP1, "CSuplPosRequestHandler::FillOMAPositionL() Begin\n");
       
   231 	__ASSERT_ALWAYS(aSuplPosition, User::Panic(KPosPanicCategory, KErrArgument));
       
   232 	
       
   233 	if (aLbsPosition.PositionClassType() & EPositionInfoClass)
       
   234 		{
       
   235 		TPosition pos;		
       
   236 		const TPositionInfo& posInfo = static_cast<const TPositionInfo&>(aLbsPosition);
       
   237 		posInfo.GetPosition(pos);
       
   238 	
       
   239 		// TIMESTAMP (mandatory)
       
   240 		TTime time = pos.Time();
       
   241 		TOMASuplUtcTime utcTime;
       
   242 		TInt zoneCode = 0;	// 0 means COORDINATED_UNIVERSAL_TIME 	1 means LOCAL_TIME_WITH_ZONE 
       
   243 		TInt zone = 0;	
       
   244 	
       
   245 		utcTime.SetUtcTime( time.DateTime(), zoneCode, zone);	
       
   246 		TOMASuplPositionEstimate posEstimate;
       
   247 		
       
   248 		// POSITION ESTIMATE (mandatory)
       
   249 		// -- latitude/longitude (mandatory)	
       
   250 		TReal64 latitude  = pos.Latitude();
       
   251 		TReal64 longitude = pos.Longitude();
       
   252 		TOMASuplPositionEstimate::TOMASuplLatitudeSign sign = TOMASuplPositionEstimate::ENorth;
       
   253 		if (latitude < 0)
       
   254 			{
       
   255 			sign = TOMASuplPositionEstimate::ESouth;
       
   256 			latitude *= -1;
       
   257 			}
       
   258 		latitude  = latitude  * KLbsLatitudeConst; 
       
   259 		longitude = longitude * KLbsLongitudeConst;	
       
   260 		posEstimate.SetPositionEstimate( sign, latitude, longitude);
       
   261 	
       
   262 		// -- uncertainty (optional)
       
   263 		if (pos.HorizontalAccuracy() != 0)
       
   264 			{
       
   265 			TOMASuplUncertainty uncertainty;
       
   266 			TInt uncert = NetPmUtils::Uncertainty(pos.HorizontalAccuracy());
       
   267 			uncertainty.SetUncertainty(uncert, uncert, 0);
       
   268 			posEstimate.SetUncertainty(uncertainty);
       
   269 			}
       
   270 		
       
   271 		// -- altitude information (optional)
       
   272 		if (pos.Altitude() != 0)
       
   273 			{
       
   274 			TOMASuplAltitudeInfo::TOMASuplAltitudeDirection direction = TOMASuplAltitudeInfo::EHeight;
       
   275 			TOMASuplAltitudeInfo altInfo;
       
   276 			TReal32 altitude = pos.Altitude();
       
   277 			TInt uncert = NetPmUtils::UncertaintyAltitude(pos.VerticalAccuracy());;
       
   278 			if (altitude < 0)
       
   279 				{
       
   280 				direction = TOMASuplAltitudeInfo::EDepth;
       
   281 				altitude *= -1;
       
   282 				}
       
   283 			
       
   284 			altitude = NetPmUtils::EncodeAltitude(altitude);
       
   285 			altInfo.SetAltitudeInfo(direction, altitude, uncert);
       
   286 			posEstimate.SetAltitudeInfo(altInfo);
       
   287 			}
       
   288 		
       
   289 		// -- confidence (optional)
       
   290 		// this information is not available, omitted.
       
   291 		/*
       
   292 		posEstimate.SetConfidence(TInt);
       
   293 		*/	
       
   294 	
       
   295 		aSuplPosition->SetPosition( utcTime, posEstimate );
       
   296 		
       
   297 		// -- velocity
       
   298 		if ((posInfo.PositionClassType() & EPositionCourseInfoClass) != 0)
       
   299 			{
       
   300 			COMASuplVelocity* velocityreq = COMASuplVelocity::NewL();
       
   301 			COMASuplHorizAndVertVelocity* horizverVel = COMASuplHorizAndVertVelocity::NewL();
       
   302 	
       
   303 			TCourse course;
       
   304 			const TPositionCourseInfo& courseInfo = static_cast<const TPositionCourseInfo&>(posInfo);			
       
   305 			courseInfo.GetCourse(course);
       
   306 			
       
   307 			// -- bearing
       
   308 			TUint16 bearing = (TUint)course.Heading();
       
   309 			
       
   310 			// -- horizontal speed. Convert meters per second -> kilometres per hour
       
   311 			TReal32 horSpeed = course.Speed() * KLbsMpsKmphConstant;
       
   312 			// adjust for GAD encoding and lose decimal precision
       
   313 			horSpeed += 0.5;
       
   314 			TUint horSpeedInt = (TUint)horSpeed;
       
   315 			//      limit to 2^16-1
       
   316 			if (horSpeedInt > 65535)
       
   317 				{
       
   318 				horSpeedInt = 65535;
       
   319 				}
       
   320 			TUint16 speed = horSpeedInt;
       
   321 			
       
   322 			// -- vertical speed. Convert meters per second -> kilometres per hour
       
   323 			TReal32 lbsVertSpeed = 0;
       
   324 			
       
   325 			lbsVertSpeed = course.VerticalSpeed() * KLbsMpsKmphConstant;			
       
   326 			// adjust for GAD encoding and lose decimal precision
       
   327 			TInt8 verDirect = (lbsVertSpeed > 0 ? 0 : 1);	// zero value indicates upward speed and 1 indicates downward speed
       
   328 			lbsVertSpeed += 0.5;
       
   329 			TUint lbsVertSpeedInt = (TUint)lbsVertSpeed;
       
   330 			//      limit to 2^8-1
       
   331 			if (lbsVertSpeedInt > 255)
       
   332 				{
       
   333 				lbsVertSpeedInt = 255;
       
   334 				}
       
   335 			TInt8 verSpeed = lbsVertSpeedInt;
       
   336 			
       
   337 			horizverVel->SetHorizAndVertVel(bearing, speed, verDirect, verSpeed);
       
   338 			
       
   339 			velocityreq->SetType(COMASuplInfoRequest::EOMASuplVelocity);
       
   340 			velocityreq->SetVelocity(horizverVel);
       
   341 	
       
   342 			aSuplPosition->SetSuplVelocity(velocityreq);	// ownership of velocity is taken here
       
   343 	
       
   344 			}
       
   345 		 
       
   346 		aSuplPosition->SetType(COMASuplInfoRequest::EOMASuplPosition);	// necessary or done in c'tor?
       
   347 		aSuplPosition->SetStatus(KErrNone);
       
   348 		}
       
   349 	else
       
   350 		{
       
   351 		aSuplPosition->SetStatus(KErrOMASuplPosInfo);			// indicates that requested info not filled in
       
   352 		}
       
   353 	 	 
       
   354 	LBSLOG(ELogP1, "CSuplPosRequestHandler::FillOMAPositionL() End\n");
       
   355 	}
       
   356 
       
   357 
       
   358 /**
       
   359  * Sets the request mask inside the structure we pass to SPPM 
       
   360  */
       
   361 void CSuplPosRequestHandler::SetRequestMaskFromSuplInfoListL()
       
   362  	{
       
   363 	LBSLOG(ELogP1, "CSuplPosRequestHandler::SetRequestMaskFromSuplInfoListL() Begin\n");
       
   364  	iSuplInfoRequestData.InitializeRequestMask();
       
   365  	// iterate list and set each requested type in the structure we pass to SPPM 
       
   366     TInt count = iSuplInfoReqList->GetCount();
       
   367     
       
   368     LBSLOG2(ELogP1, "Requested Info Type Count = %d \n", count);
       
   369 
       
   370     for ( TInt index = 0; index < count; index ++ )
       
   371         {
       
   372         // Determine the type of the element
       
   373         COMASuplInfoRequest *reqElement = iSuplInfoReqList->GetElement( index );
       
   374         __ASSERT_ALWAYS(reqElement,User::Leave(KErrArgument));
       
   375        	COMASuplInfoRequest::TOMASuplInfoType infoReqType = reqElement->Type();
       
   376  
       
   377         // Fill up the element with appropriate values
       
   378          switch( infoReqType )
       
   379              {
       
   380              case COMASuplInfoRequest::EOMASuplReqAsstData:
       
   381             	 {
       
   382                  LBSLOG(ELogP1, "Requested Info: EOMASuplReqAsstData\n");
       
   383             	 iSuplInfoRequestData.AddRequestItemToMask(TSuplInfoRequestData::ERequestItemAssistance);
       
   384                  break;
       
   385             	 }
       
   386              case COMASuplInfoRequest::EOMASuplSETCapabilities:
       
   387             	 {
       
   388                  LBSLOG(ELogP1, "Requested Info: EOMASuplSETCapabilities\n");
       
   389             	 iSuplInfoRequestData.AddRequestItemToMask(TSuplInfoRequestData::ERequestItemCapabilities);
       
   390                  break;
       
   391             	 }
       
   392                  
       
   393              case COMASuplInfoRequest::EOMASuplPosPayload:
       
   394             	 {
       
   395                  LBSLOG(ELogP1, "Requested Info: EOMASuplPosPayload\n");
       
   396                  //Uncomment the following after confirming if the SUPL FW is expected to set the payload type
       
   397                  //HBufC8* tempPtr;
       
   398                  //COMASuplPosPayload* posPayload = static_cast<COMASuplPosPayload*>(reqElement);
       
   399                  //COMASuplPosPayload::TOMASuplPosPayloadType type;
       
   400                  //posPayload->GetPosPayload(tempPtr, type);
       
   401                  //__ASSERT_ALWAYS(type == COMASuplPosPayload::ERRLP, User::Panic(KPosPanicCategory, KErrArgument));
       
   402             	 iSuplInfoRequestData.AddRequestItemToMask(TSuplInfoRequestData::ERequestItemPosPayload);
       
   403                  break;
       
   404             	 }
       
   405              case COMASuplInfoRequest::EOMASuplPosition:	
       
   406             	 {
       
   407                  LBSLOG(ELogP1, "Requested Info: EOMASuplPosition\n");
       
   408             	 iSuplInfoRequestData.AddRequestItemToMask(TSuplInfoRequestData::ERequestItemPosition);
       
   409                  break;
       
   410             	 }
       
   411                  
       
   412              case COMASuplInfoRequest::EOMASuplVelocity:
       
   413             	 {
       
   414                  LBSLOG(ELogP1, "Requested Info: EOMASuplVelocity\n");            	 
       
   415             	 // do nothing, we will never pass this
       
   416             	 break;
       
   417             	 }
       
   418              default:
       
   419                  LBSLOG(ELogP1, "Requested Info: Unknown\n");
       
   420 
       
   421             	 __ASSERT_DEBUG(EFalse, User::Leave(KErrArgument));
       
   422             	 break;
       
   423              }
       
   424         }
       
   425 
       
   426 	// SUPL FW sends 2 requests for pospayload that we don't need to respond to. 
       
   427 	// The first is when creating a POS_INIT and is requested along with all the other types of info (assistance mask, position, caps, velocity)
       
   428 	// The second is after the SUPL FW sends the POS_INIT (but before it receives a SUPL_POS) and that is requested (as all subsequent pospayload requests) along with velocity only.
       
   429 	// In those cases we don't bother to send a buffer to the SPPM, but return the error
       
   430     if(iSuplInfoRequestData.RequestMask() & TSuplInfoRequestData::ERequestItemPosPayload)
       
   431     	{
       
   432 		 if((iSuplInfoRequestData.RequestMask() & TSuplInfoRequestData::ERequestItemAssistance))
       
   433 			 {
       
   434 			 iSuplInfoRequestData.RemoveRequestItemFromMask(TSuplInfoRequestData::ERequestItemPosPayload);
       
   435 			 }
       
   436 		 else if(!iFirstSUPLPOSPosPayloadProcessed)
       
   437 			 {
       
   438 			 iSuplInfoRequestData.RemoveRequestItemFromMask(TSuplInfoRequestData::ERequestItemPosPayload);			
       
   439 			 iFirstSUPLPOSPosPayloadProcessed = ETrue;
       
   440 			 }  
       
   441     	}
       
   442 	LBSLOG(ELogP1, "CSuplPosRequestHandler::SetRequestMaskFromSuplInfoListL() End\n");
       
   443     }
       
   444 
       
   445 /**
       
   446  * Fills in the stored OMA suplinforequest list structure from the lbs structures received
       
   447  */
       
   448 TInt CSuplPosRequestHandler::FillSuplInfoListL()
       
   449 	{
       
   450 	LBSLOG2(ELogP1, "CSuplPosRequestHandler::FillSuplInfoListL() Begin with count=%d\n", iSuplInfoReqList->GetCount());
       
   451 
       
   452 	TInt result = KErrOMASuplPosInfo;	// no data being returned
       
   453 	// fill in the iSuplInfoReqList from iSuplInfoRequestData and iPosPayload
       
   454 	// set errors as approriate for each request 
       
   455 	
       
   456 	// iterate list and set each requested type in the structure we pass to SPPM 
       
   457     TInt count = iSuplInfoReqList->GetCount();
       
   458     for ( TInt index = 0; index < count; index ++ )
       
   459         {
       
   460         // Determine the type of the element
       
   461         COMASuplInfoRequest *reqElement = iSuplInfoReqList->GetElement( index );
       
   462        	COMASuplInfoRequest::TOMASuplInfoType infoReqType = reqElement->Type();
       
   463        	reqElement->SetStatus(KErrNone);
       
   464        	
       
   465         // Fill up the element with appropriate values
       
   466          switch(infoReqType)
       
   467 			{
       
   468 			case COMASuplInfoRequest::EOMASuplReqAsstData:
       
   469 				{
       
   470 				LBSLOG2(ELogP1, "CSuplPosRequestHandler::FillSuplInfoListL() EOMASuplReqAsstData, err=%d\n", iSuplInfoRequestData.AssistanceMaskError());
       
   471 
       
   472 				if(iSuplInfoRequestData.AssistanceMaskError() == KErrNone)
       
   473 					{
       
   474 					COMASuplReqAsstData* asstData = static_cast<COMASuplReqAsstData*>(reqElement);
       
   475 					TLbsAssistanceDataGroup asstMask = iSuplInfoRequestData.AssistanceDataMask();
       
   476 					asstData->SetReqAsstData(((asstMask & EAssistanceDataAlmanac)>0),
       
   477 											((asstMask & EAssistanceDataPositioningGpsUtcModel)>0),
       
   478 											((asstMask & EAssistanceDataIonosphericModel)>0),
       
   479 											((asstMask & EAssistanceDataDgpsCorrections)>0),
       
   480 											((asstMask & EAssistanceDataReferenceLocation)>0),
       
   481 											((asstMask & EAssistanceDataReferenceTime)>0),
       
   482 											((asstMask & EAssistanceDataAquisitionAssistance)>0),
       
   483 											((asstMask & EAssistanceDataBadSatList)>0) // 'real-time integrity' == 'bad sat list'
       
   484 											);	
       
   485 					//Set the Navigation Model parameters if it has been requested.
       
   486 					if ((asstMask & EAssistanceDataNavigationModel)>0)
       
   487 					    {
       
   488 					    // Note that setting nSAT (number of satellites for which the SET has
       
   489 					    // ephemeris data available) to zero means that the SLP should ignore
       
   490 					    // values for gpsWeek and gpsToe. The TOE-Limit is set to 2 [range 0-10]. 
       
   491 					    // Also means there is no need to include any additional satellite 
       
   492 					    // information. See OMA-TS-V1_0-20070615A p22-23 for further detail.
       
   493 					    TOMASuplNavigationModel naviModel;
       
   494 					    naviModel.SetNavigationModel(0, 0, 0, 2);
       
   495 					    asstData->SetNavigationData(naviModel);	// this sets 'navigationmodel requested' flag to true
       
   496 					    }
       
   497                     result = KErrNone;
       
   498 					}
       
   499 				else
       
   500 					{
       
   501 					reqElement->SetStatus(KErrOMASuplPosInfo);
       
   502 					}
       
   503 				break;
       
   504 				}
       
   505 			case COMASuplInfoRequest::EOMASuplSETCapabilities:
       
   506 				{
       
   507 				LBSLOG2(ELogP1, "CSuplPosRequestHandler::FillSuplInfoListL() EOMASuplSETCapabilities, err=%d\n", iSuplInfoRequestData.CapabilitiesError());
       
   508 
       
   509 				if(iSuplInfoRequestData.CapabilitiesError() == KErrNone)
       
   510 					{
       
   511 					COMASuplSETCapabilities* setCaps = static_cast<COMASuplSETCapabilities*>(reqElement);
       
   512 					TLbsNetPosCapabilities posCaps = iSuplInfoRequestData.Capabilities();
       
   513 					
       
   514 					// get the lbs preferred method
       
   515 					TLbsNetPosMethod prefMethod;
       
   516 					posCaps.GetPosMethod(0, prefMethod);
       
   517 					COMASuplSETCapabilities::TOMASuplPrefMethod omaPrefMethod = COMASuplSETCapabilities::EOMANoPreferred;
       
   518 					if(prefMethod.PosMode() & TPositionModuleInfo::ETechnologyTerminal)
       
   519 						{
       
   520 						omaPrefMethod = COMASuplSETCapabilities::EOMAAGpsSETBasedPreferred;
       
   521 						}
       
   522 					else
       
   523 						{
       
   524 						omaPrefMethod = COMASuplSETCapabilities::EOMAAGpsSETAssitedPreferred;
       
   525 						}
       
   526 					
       
   527 					// which methods does lbs support?
       
   528 					TBool setAssisted = EFalse, setBased = EFalse, autonomous = EFalse;
       
   529 					TLbsNetPosMethod posMethod;
       
   530 					for (TInt index = 0; index < posCaps.NumPosMethods(); index++)
       
   531 						{				
       
   532 						posCaps.GetPosMethod(index, posMethod);
       
   533 						if(posMethod.PosMode() == TPositionModuleInfo::ETechnologyTerminal)
       
   534 							{
       
   535 							autonomous = ETrue;
       
   536 							}
       
   537 						else if(posMethod.PosMode() == (TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted))
       
   538 							{
       
   539 							setBased = ETrue;
       
   540 							}
       
   541 						else if(posMethod.PosMode() == (TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted))
       
   542 							{
       
   543 							setAssisted = ETrue;
       
   544 							}
       
   545 						}
       
   546 					
       
   547 					TUid posProtocol;
       
   548 					TBool aFLT = EFalse, eOTD = EFalse, oTDOA = EFalse;
       
   549 					for (TInt index = 0; index < posCaps.NumPosProtocols(); index++)
       
   550 						{
       
   551 						posCaps.GetPosProtocol(index, posProtocol);
       
   552 						if(posProtocol == KLbsPositioningMeansAflt)
       
   553 							{
       
   554 							aFLT = ETrue;
       
   555 							}
       
   556 						else if(posProtocol == KLbsPositioningMeansEotd)
       
   557 							{
       
   558 							eOTD = ETrue;
       
   559 							}
       
   560 						else if(posProtocol == KLbsPositioningMeansOtdoa)
       
   561 							{
       
   562 							oTDOA = ETrue;
       
   563 							}
       
   564 						}
       
   565 					TOMASuplPosTechnology posTech;
       
   566 					posTech.SetPosTechnology(setAssisted, setBased, autonomous, aFLT, eOTD, oTDOA);
       
   567 					TOMASuplPosProtocol suplProtocol;
       
   568 					suplProtocol.SetPosProtocol(EFalse, ETrue, EFalse ); 	// RRLP protocol 
       
   569 					
       
   570 					TOMASuplPosProtocolVersion protocolVersion;
       
   571 					TUint8 RrlpMajorVersion = 5, RrlpTechVersion = 12, RrlpminorVersion = 0;
       
   572 					
       
   573 					protocolVersion.SetPosProtocolVersion(RrlpMajorVersion, RrlpTechVersion, RrlpminorVersion);
       
   574 					
       
   575 					setCaps->SetSETCapabilities(posTech, omaPrefMethod, suplProtocol, protocolVersion);
       
   576 					
       
   577 					result = KErrNone;
       
   578 					}
       
   579 				else	// something went wrong when trying to retrieve pos capabilities
       
   580 					{
       
   581 					reqElement->SetStatus(KErrOMASuplPosInfo);
       
   582 					}
       
   583 				break;
       
   584 				}
       
   585 			case COMASuplInfoRequest::EOMASuplPosPayload:
       
   586 				{
       
   587 				LBSLOG2(ELogP1, "CSuplPosRequestHandler::FillSuplInfoListL() EOMASuplPosPayload, err=%d\n", iSuplInfoRequestData.PosPayloadError());
       
   588 
       
   589 				TInt err = iSuplInfoRequestData.PosPayloadError();
       
   590 				TBool posPayloadReqSentToSPPM = (iSuplInfoRequestData.RequestMask() & TSuplInfoRequestData::ERequestItemPosPayload);
       
   591 				if(posPayloadReqSentToSPPM && (err == KErrNone))
       
   592 					{
       
   593 					COMASuplPosPayload* posPayload = static_cast<COMASuplPosPayload*>(reqElement);
       
   594 					// set the pospayload with data provided by SPPM (posPayload takes ownership)
       
   595 					posPayload->SetPosPayload(iPosPayload, COMASuplPosPayload::ERRLP);
       
   596 					iPosPayload = NULL;
       
   597 					if (iSuplInfoRequestData.IsLastPosMsg())
       
   598 					    {
       
   599 					    //inform the SUPL FW that this will be the last pospayload for this rrlp session
       
   600 					    reqElement->SetStatus(KErrOMASuplLastPosMsg);
       
   601 					    }
       
   602 					result = KErrNone;
       
   603 					}
       
   604 				else	// request for pospayload not sent to SPPM, or error returned from SPPM for pospayload
       
   605 					{
       
   606 					reqElement->SetStatus(KErrOMASuplPosInfo);
       
   607 					// iPosPayload has not been passed to the SUPL FW.
       
   608 					delete iPosPayload;
       
   609 					iPosPayload = NULL;
       
   610 					}
       
   611 				break;
       
   612 				}
       
   613 			case COMASuplInfoRequest::EOMASuplPosition:	
       
   614 				{
       
   615 				LBSLOG2(ELogP1, "CSuplPosRequestHandler::FillSuplInfoListL() EOMASuplPosition, err=%d\n", iSuplInfoRequestData.PositionError());
       
   616 
       
   617 				if(iSuplInfoRequestData.PositionError() == KErrNone)
       
   618 					{
       
   619 					COMASuplPosition* position = static_cast<COMASuplPosition*>(reqElement);
       
   620 					FillOMAPositionL(iSuplInfoRequestData.Position(), position);	
       
   621 					result = KErrNone;
       
   622 					}
       
   623 				else
       
   624 					{
       
   625 					reqElement->SetStatus(KErrOMASuplPosInfo);	
       
   626 					}
       
   627 				break;
       
   628 				}
       
   629 			case COMASuplInfoRequest::EOMASuplVelocity:
       
   630 				{
       
   631 				LBSLOG(ELogP1, "CSuplPosRequestHandler::FillSuplInfoListL() EOMASuplVelocity, err=KErrOMASuplPosInfo\n");
       
   632 				// we will never pass this, just fill in error code
       
   633 				reqElement->SetStatus(KErrOMASuplPosInfo);	
       
   634 				break;
       
   635 				}
       
   636 			default:
       
   637 				__ASSERT_DEBUG(EFalse, User::Leave(KErrArgument));
       
   638 				break;
       
   639 			}
       
   640         }
       
   641 
       
   642 	LBSLOG(ELogP1, "CSuplPosRequestHandler::FillSuplInfoListL() End\n");	
       
   643 	return result;
       
   644 	}
       
   645 
       
   646 /* Called when SUPL FW reinitializes a POS session object inorder to reuse it with a
       
   647  * different SUPL session.
       
   648  */
       
   649 void CSuplPosRequestHandler::ResetState()
       
   650     {
       
   651     iFirstSUPLPOSPosPayloadProcessed = EFalse;
       
   652     iRequestOutstanding = ENone;
       
   653     }