networkprotocolmodules/suplprotocolmodule/SuplProtocol/src/suplprotocolmanager.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     1 // Copyright (c) 2008-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 // This file provides the implementation of the class that manages
       
    15 // protocol aspects of Test Protocol Module operation.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22  @deprecated
       
    23 */
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <lbs/lbslocdatasourcegpsbase.h>
       
    27 #include "suplconflictmanager.h"
       
    28 #include "suplmolrfsmsession.h"
       
    29 #include "suplmtlrfsmsession.h"
       
    30 #include "suplprotocolmanager.h"
       
    31 #include "suplassistancedatamgr.h"
       
    32 #include "suplasn1decoder.h"
       
    33 #include "suplinit.h"
       
    34 #include <lbs/lbssuplpushreceiver.h>
       
    35 #include "supldevloggermacros.h"
       
    36 
       
    37 /** The unique ID of this plug-in implementation.
       
    38 This corresponds to the implementation UID specified in the .rss file
       
    39 for this protocol module.
       
    40 */
       
    41 const TInt KPluginUidValue = 0x10285A9D;
       
    42 const TUid KPluginUid = { KPluginUidValue };
       
    43 
       
    44 /** Static constructor.
       
    45 @param aGateway A reference to the protocol manager observer
       
    46 @return A new instance of the CSuplProtocolManager class
       
    47 */
       
    48 CSuplProtocolManager* CSuplProtocolManager::NewL(MSuplProtocolManagerObserver& aGateway)
       
    49 	{
       
    50 	SUPLLOG(ELogP1, "CSuplProtocolManager::NewL() Begin\n");
       
    51 	CSuplProtocolManager* self = new (ELeave) CSuplProtocolManager(aGateway);
       
    52 	CleanupStack::PushL(self);
       
    53 	self->ConstructL();
       
    54 	CleanupStack::Pop(self);
       
    55 	SUPLLOG(ELogP1, "CSuplProtocolManager::NewL() End\n");
       
    56 	return self;
       
    57 	}
       
    58 
       
    59 /** Standard constructor.
       
    60 @param aGateway A reference to the protocol manager observer
       
    61 */
       
    62 CSuplProtocolManager::CSuplProtocolManager(MSuplProtocolManagerObserver& aGateway)
       
    63 : iGateway(aGateway), iLbsStatus(CLbsNetworkProtocolBase::ESystemStatusNone),
       
    64 	iActiveServiceMask(MLbsNetworkProtocolObserver::EServiceNone)
       
    65 	{
       
    66 	SUPLLOG(ELogP1, "CSuplProtocolManager::CSuplProtocolManager() Begin\n");
       
    67 	iInternalSessionId.SetSessionOwner(KPluginUid);
       
    68 	iInternalSessionId.SetSessionNum(0);
       
    69 	SUPLLOG(ELogP1, "CSuplProtocolManager::CSuplProtocolManager() End\n");
       
    70 	}
       
    71 	
       
    72 /** Private second-stage constructor.
       
    73 */
       
    74 void CSuplProtocolManager::ConstructL()
       
    75 	{
       
    76 	SUPLLOG(ELogP1, "CSuplProtocolManager::ConstructL() Begin\n");
       
    77 	iConnectionManager = CSuplConnectionManager::NewL();
       
    78 	iConflictManager = CSuplConflictManager::NewL();
       
    79 	iMoLr = CSuplMolrFsmSession::NewL(*this);
       
    80 	iNetLoc = CSuplMolrFsmSession::NewL(*this, CSuplMolrFsmSession::ESuplMolrCellBased);
       
    81 	iMtLr = CSuplMtlrFsmSession::NewL(*this);	
       
    82 	iAssistMgr = CSuplAssistanceDataManager::NewL(iGateway);
       
    83 	iSessionCompleter = CSuplSessionCompleter::NewL(iGateway);
       
    84 	iPushRec = CLbsSuplPushRec::NewL(*this);
       
    85 	iNetInfoHandler = CSuplNetworkInfoHandler::NewL(*this);
       
    86 	iNetInfoHandler->StartGettingNetworkInfoL();
       
    87 	// Initialise array of supported SUPL versions.
       
    88 	User::LeaveIfError(iSupportedVersions.Append(KSupportedSuplVersion_001));
       
    89 	SUPLLOG(ELogP1, "CSuplProtocolManager::ConstructL() End\n");
       
    90 	}
       
    91 
       
    92 /** Standard destructor.
       
    93 */
       
    94 CSuplProtocolManager::~CSuplProtocolManager()
       
    95 	{
       
    96 	SUPLLOG(ELogP1, "CSuplProtocolManager::~CSuplProtocolManager() Begin\n");
       
    97 	iSupportedVersions.Close();
       
    98 	delete iAssistMgr;
       
    99 	delete iMoLr;
       
   100 	delete iNetLoc;
       
   101 	delete iMtLr;
       
   102 	delete iConflictManager;
       
   103 	delete iConnectionManager;
       
   104 	delete iSessionCompleter;
       
   105     delete iNetInfoHandler;
       
   106 	delete iPushRec;
       
   107 	SUPLLOG(ELogP1, "CSuplProtocolManager::~CSuplProtocolManager() End\n");
       
   108 	}
       
   109 	
       
   110 /** Handle LBS request for self locate
       
   111 @param aSessionId The session ID supplied by LBS.
       
   112 @param aOptions Parameters for the self location request (mode, assistance data mask, newclient flag,...)
       
   113 */
       
   114 void CSuplProtocolManager::SelfLocationReq(const TLbsNetSessionId& aSessionId, 
       
   115 				const TLbsNetPosRequestOptionsBase& aOptions)
       
   116 	{
       
   117 	SUPLLOG(ELogP1, "CSuplProtocolManager::SelfLocationReq() Begin\n");
       
   118 	
       
   119 	const  TLbsNetPosRequestOptionsAssistance options = reinterpret_cast<const TLbsNetPosRequestOptionsAssistance&> (aOptions);
       
   120     TLbsAsistanceDataGroup dataRequestMask = options.DataRequestMask();
       
   121     
       
   122     // If the positioning method is autonomous, just complete the session
       
   123     //
       
   124     if (TPositionModuleInfo::ETechnologyTerminal == options.PosMode())
       
   125 	    {
       
   126     	iSessionCompleter->CompleteSession(aSessionId, KErrNone);
       
   127  	   	}
       
   128 
       
   129  	// If not a new session, then just complete with no error - even if assistance data needed.
       
   130  	else if (!options.NewClientConnected())
       
   131  		{
       
   132  		iSessionCompleter->CompleteSession(aSessionId, KErrNone);
       
   133  		}
       
   134     else 
       
   135  	   {
       
   136 		// Check if the conflict controller allows the self-locate
       
   137 		// 
       
   138 		switch (ResolveConflict(MLbsNetworkProtocolObserver::EServiceSelfLocation, aOptions))
       
   139 			{
       
   140 			case CSuplConflictManager::EConflictNone:
       
   141 				StatusUpdate(MLbsNetworkProtocolObserver::EServiceSelfLocation, ETrue); // ETrue=new operation
       
   142 				iMoLr->MoLrReq(aSessionId, options);
       
   143 				iAssistMgr->ProcessDataRequest(dataRequestMask);
       
   144 				break;
       
   145 
       
   146 			case CSuplConflictManager::EConflictAdoptNewSessionId:
       
   147 				// Continue with the existing MOLR network session but addopt new SessionId
       
   148 				// in future communications with LBS due to the MOLR
       
   149 				iMoLr->AdoptNewLbsSessionId(aSessionId);
       
   150 				break;
       
   151 
       
   152 			case CSuplConflictManager::EConflictCancelCurrent:
       
   153 				// Cancel ongoing MTLR
       
   154 				iMtLr->CancelMachine(CSuplFsmSessionBase::ECancelClient, CSuplFsmSessionBase::EReasonNone);
       
   155 
       
   156 				// Start new MOLR
       
   157 				StatusUpdate(MLbsNetworkProtocolObserver::EServiceSelfLocation, ETrue); // ETrue=new operation
       
   158 				iMoLr->MoLrReq(aSessionId, options);
       
   159 				break;
       
   160 
       
   161 			case CSuplConflictManager::EConflictRejectNew:
       
   162 				iSessionCompleter->CompleteSession(aSessionId, KErrServerBusy);
       
   163 				break;
       
   164 
       
   165 			default :
       
   166 				// No other conflict resolution is currently expected after
       
   167 				// a SelfLocateRequest
       
   168 				ASSERT(EFalse);
       
   169 				Gateway().SessionCompleteInd(aSessionId, KErrGeneral);
       
   170 				break;
       
   171 			}
       
   172 		}
       
   173 
       
   174 	SUPLLOG(ELogP1, "CSuplProtocolManager::SelfLocationReq() End\n");
       
   175 	}
       
   176 
       
   177 /** Handle LBS completion of self locate
       
   178 @param aSessionId The session to be completed.
       
   179 @param aReason Completion reason value.
       
   180 */
       
   181 void CSuplProtocolManager::SelfLocationCompleteInd(const TLbsNetSessionId& aSessionId, 
       
   182 				TInt /*aReason*/)
       
   183 	{
       
   184 	SUPLLOG(ELogP1, "CSuplProtocolManager::SelfLocationCompleteInd() Begin\n");
       
   185 	// Check we have an active self locate and valid session ID,
       
   186 	// otherwise silently consume this completion indication.
       
   187 	if ((CSuplFsmSessionBase::EStateActive == iMoLr->State()) &&
       
   188 		(aSessionId == iMoLr->LbsSessionId()))
       
   189 		{
       
   190 		iMoLr->CancelMachine(CSuplFsmSessionBase::ECancelClient, CSuplFsmSessionBase::EReasonNone);
       
   191 		}
       
   192 	SUPLLOG(ELogP1, "CSuplProtocolManager::SelfLocationCompleteInd() End\n");
       
   193 	}
       
   194 
       
   195 /** Handle LBS system status indication
       
   196 @param aStatus The status indication from LBS.
       
   197 */
       
   198 void CSuplProtocolManager::SystemStatusInd(CLbsNetworkProtocolBase::TLbsSystemStatus aStatus)
       
   199 	{
       
   200 	SUPLLOG(ELogP1, "CSuplProtocolManager::SystemStatusInd() Begin\n");
       
   201 	iLbsStatus = aStatus;
       
   202 	SUPLLOG(ELogP1, "CSuplProtocolManager::SystemStatusInd() End\n");
       
   203 	}
       
   204 
       
   205 /** Handle LBS Location Response
       
   206 @param aSessionId The session ID for which this response is provided.
       
   207 @param aReason An error response; KErrNone if position is okay.
       
   208 @param aPosInfo The location response information
       
   209 */
       
   210 void CSuplProtocolManager::LocationResp(const TLbsNetSessionId& aSessionId, TInt aReason, const TPositionInfoBase& aPosInfo)
       
   211 	{
       
   212 	SUPLLOG(ELogP1, "CSuplProtocolManager::LocationResp() Begin\n");
       
   213 
       
   214 	if (aSessionId == iMoLr->LbsSessionId())
       
   215 		{
       
   216 		iMoLr->LocationResp(aReason, aPosInfo);
       
   217 		}
       
   218 	else if (aSessionId == iMtLr->LbsSessionId())
       
   219 		{
       
   220 		iMtLr->LocationResp(aReason, aPosInfo);
       
   221 		}
       
   222 	else
       
   223 		{
       
   224 		// Unknown session ID
       
   225 		ASSERT(EFalse);
       
   226 		}
       
   227 	SUPLLOG(ELogP1, "CSuplProtocolManager::LocationResp() End\n");
       
   228 	}
       
   229 
       
   230 /** Handle LBS Privacy Response
       
   231 @param aResponse Privacy response value.
       
   232 */
       
   233 void CSuplProtocolManager::PrivacyResp(const TLbsNetSessionId& aSessionId, 
       
   234 			const CLbsNetworkProtocolBase::TLbsPrivacyResponse& aResponse,
       
   235 			TInt /*aReason*/)
       
   236 	{
       
   237 	SUPLLOG(ELogP1, "CSuplProtocolManager::PrivacyResp() Begin\n");
       
   238 	
       
   239 	
       
   240 	
       
   241 	
       
   242 	
       
   243 	iMtLr->PrivacyResp(aSessionId, aResponse);
       
   244 	SUPLLOG(ELogP1, "CSuplProtocolManager::PrivacyResp() End\n");
       
   245 	}
       
   246 
       
   247 
       
   248 /** Handle LBS Network Based Location Request
       
   249 */
       
   250 void CSuplProtocolManager::NetworkBasedLocationReq(const TLbsNetSessionId& aSessionId, 
       
   251 										const TLbsNetPosRequestOptionsBase& aOptions)
       
   252 	{
       
   253 	SUPLLOG(ELogP1, "CSuplProtocolManager::NetworkBasedLocationReq() Begin\n");
       
   254 	
       
   255 	switch (ResolveConflict(MLbsNetworkProtocolObserver::EServiceNetworkLocation, aOptions))
       
   256 		{
       
   257 		case CSuplConflictManager::EConflictNone:
       
   258 			StatusUpdate(MLbsNetworkProtocolObserver::EServiceNetworkLocation, ETrue); // ETrue=new operation
       
   259 			iNetLoc->MoLrReq(aSessionId, aOptions);
       
   260 			break;
       
   261 
       
   262 		case CSuplConflictManager::EConflictAdoptNewSessionId:
       
   263 			// Continue with the existing MOLR network session but addopt new SessionId
       
   264 			// in future communications with LBS due to the MOLR
       
   265 			iNetLoc->AdoptNewLbsSessionId(aSessionId);
       
   266 			break;
       
   267 
       
   268 		case CSuplConflictManager::EConflictCancelCurrent:
       
   269 			// Cancel ongoing MTLR
       
   270 			iMtLr->CancelMachine(CSuplFsmSessionBase::ECancelClient, CSuplFsmSessionBase::EReasonNone);
       
   271 
       
   272 			// Start new MOLR
       
   273 			StatusUpdate(MLbsNetworkProtocolObserver::EServiceNetworkLocation, ETrue); // ETrue=new operation
       
   274 			iNetLoc->MoLrReq(aSessionId, aOptions);
       
   275 			break;
       
   276 
       
   277 		case CSuplConflictManager::EConflictRejectNew:
       
   278 			// indicate server busy, continue with original request
       
   279 			iSessionCompleter->CompleteSession(aSessionId, KErrServerBusy);
       
   280 			break;
       
   281 
       
   282 		default :
       
   283 			// No other conflict resolution is currently expected after
       
   284 			// a SelfLocateRequest
       
   285 			ASSERT(EFalse);
       
   286 			Gateway().SessionCompleteInd(aSessionId, KErrGeneral);
       
   287 			break;
       
   288 		}
       
   289 	
       
   290 	SUPLLOG(ELogP1, "CSuplProtocolManager::NetworkBasedLocationReq() End\n");
       
   291 	}
       
   292 
       
   293 
       
   294 /** Handle LBS Completion of a Network Based Location Request
       
   295 */
       
   296 void CSuplProtocolManager::NetworkBasedLocationCompleteInd(const TLbsNetSessionId& aSessionId, 
       
   297 														   TInt /*aReason*/)
       
   298 	{
       
   299 	SUPLLOG(ELogP1, "CSuplProtocolManager::NetworkBasedLocationCompleteInd() Begin\n");
       
   300 	// Check we have an active cell-based self locate and valid session ID,
       
   301 	// otherwise silently consume this completion indication.
       
   302 	if ((CSuplFsmSessionBase::EStateActive == iNetLoc->State()) &&
       
   303 		(aSessionId == iNetLoc->LbsSessionId()))
       
   304 		{
       
   305 		iNetLoc->CancelMachine(CSuplFsmSessionBase::ECancelClient, CSuplFsmSessionBase::EReasonNone);
       
   306 		}
       
   307 	SUPLLOG(ELogP1, "CSuplProtocolManager::NetworkBasedLocationCompleteInd() End\n");
       
   308 	}
       
   309 
       
   310 
       
   311 /** Handle LBS request for Assistance Data
       
   312 @param aDataRequestMask A mask identifying the set of data requested.
       
   313 */
       
   314 void CSuplProtocolManager::AssistanceDataReq(TLbsAsistanceDataGroup aDataRequestMask)
       
   315 	{
       
   316 	SUPLLOG(ELogP1, "CSuplProtocolManager::AssistanceDataReq() Begin\n");
       
   317 
       
   318 	// Check with the Assistance Data Manager that the assistance data types requested by LBS
       
   319 	// are supported. 
       
   320     MLbsNetworkProtocolObserver::TLbsNetProtocolServiceMask serviceMask;
       
   321     serviceMask = iAssistMgr->ProcessDataRequest(aDataRequestMask);
       
   322 
       
   323 	// Send the request to ALL of the state machines in 
       
   324 	// the serviceMask.
       
   325 	//
       
   326 	if (serviceMask & MLbsNetworkProtocolObserver::EServiceSelfLocation)
       
   327 		{
       
   328 		iMoLr->AssistanceDataReq(aDataRequestMask);
       
   329 		}
       
   330 	if (serviceMask & MLbsNetworkProtocolObserver::EServiceMobileTerminated)
       
   331 		{
       
   332 		iMtLr->AssistanceDataReq(aDataRequestMask);
       
   333 		}			
       
   334 
       
   335 	SUPLLOG(ELogP1, "CSuplProtocolManager::AssistanceDataReq() End\n");
       
   336 	}
       
   337 
       
   338 
       
   339 /** Handle a request to transmit location to third party
       
   340 */
       
   341 void CSuplProtocolManager::TransmitLocationReq(const TLbsNetSessionId& aSessionId,
       
   342 								const TDesC& /*aDestination*/, TInt /*aPriority*/,
       
   343 								const TLbsNetPosRequestOptionsBase& /*aOptions*/)
       
   344 {
       
   345 	SUPLLOG(ELogP1, "CSuplProtocolManager::TransmitLocationReq() Begin\n");
       
   346  // SUPL V1 does not support this service. Terminate session
       
   347  //
       
   348  iSessionCompleter->CompleteSession(aSessionId, KErrNotSupported);
       
   349  SUPLLOG(ELogP1, "CSuplProtocolManager::TransmitLocationReq() End\n");
       
   350 }
       
   351 
       
   352 /** Handle a request to cancel transmition of location to third party
       
   353 */
       
   354 void CSuplProtocolManager::TransmitLocationCompleteInd(const TLbsNetSessionId& aSessionId, TInt /*aReason*/)
       
   355 {
       
   356 	SUPLLOG(ELogP1, "CSuplProtocolManager::TransmitLocationCompleteInd() Begin\n");
       
   357  // SUPL V1 does not support this service. Terminate session
       
   358  //
       
   359  iSessionCompleter->CompleteSession(aSessionId, KErrNotSupported);	
       
   360 	SUPLLOG(ELogP1, "CSuplProtocolManager::TransmitLocationCompleteInd() End\n");
       
   361 }
       
   362 
       
   363 // --------------------------------   MSuplFsmSessionObserver methods ----------------------------------------------
       
   364 
       
   365 /** Gateway interface pointer.
       
   366 This method is called from state handlers to gain access to 
       
   367 the Gateway Interface.
       
   368 @see MSuplFsmSessionObserver
       
   369 */
       
   370 MSuplProtocolManagerObserver& CSuplProtocolManager::Gateway()
       
   371 	{
       
   372 	SUPLLOG(ELogP1, "CSuplProtocolManager::Gateway() Begin\n");
       
   373 	SUPLLOG(ELogP1, "CSuplProtocolManager::Gateway() End\n");
       
   374 	return iGateway;
       
   375 	}
       
   376 
       
   377 /** Reference to the Connection Manager.
       
   378 This method is called from state handlers to gain access to 
       
   379 the Connection Manager.
       
   380 @see MSuplFsmSessionObserver
       
   381 */
       
   382 CSuplConnectionManager& CSuplProtocolManager::ConnectionManager()
       
   383 	{
       
   384 	SUPLLOG(ELogP1, "CSuplProtocolManager::ConnectionManager() Begin\n");
       
   385 	SUPLLOG(ELogP1, "CSuplProtocolManager::ConnectionManager() End\n");
       
   386 	return *iConnectionManager;
       
   387 	}
       
   388 
       
   389 /** Get a new session ID
       
   390 */
       
   391 const TLbsNetSessionId& CSuplProtocolManager::NewSessionId()
       
   392 	{
       
   393 	SUPLLOG(ELogP1, "CSuplProtocolManager::NewSessionId() Begin\n");
       
   394 	iInternalSessionId.IncrSession();
       
   395 	SUPLLOG(ELogP1, "CSuplProtocolManager::NewSessionId() End\n");
       
   396 	return iInternalSessionId;
       
   397 	}
       
   398 
       
   399 /** State machine procedure complete notification
       
   400 Called by the state machines to notify the completion of a procedure.
       
   401 @see MSuplFsmSessionObserver
       
   402 */
       
   403 void CSuplProtocolManager::ProcedureCompleteInd(const MLbsNetworkProtocolObserver::TLbsNetProtocolService& aService)
       
   404 	{
       
   405 	SUPLLOG(ELogP1, "CSuplProtocolManager::ProcedureCompleteInd() Begin\n");
       
   406 	// Status update sent to LBS
       
   407 	StatusUpdate(aService, EFalse); // EFalse=operation ended
       
   408 
       
   409 	// Inform the Assistance Data manager that a state machine has completed in case
       
   410 	// some assistance data types were expected from the machine
       
   411 	iAssistMgr->MachineTerminated(aService);
       
   412 
       
   413 	SUPLLOG(ELogP1, "CSuplProtocolManager::ProcedureCompleteInd() End\n");
       
   414 	}
       
   415 
       
   416 /** Handle a location request from the network. This can be due to a new
       
   417 location request (i.e, after SUPL INIT) or it can be due to a change to the quality
       
   418 of the position or to the positioning method requested by the remote SUPL server
       
   419 either after a SUPL message (e.g. SUPL RESPONSE) or after a positioning message
       
   420 (e.g. RRLP Measure Position Request).
       
   421 
       
   422 @param aQuality Accuracy of the positioning request
       
   423 @param aPosMethod Positioning methods requested by the remote SUPL server.
       
   424 @param aType type of service (procedure) of the state machine that issued the request
       
   425 @param aSessionId session ID of the state machine that issues the request
       
   426 */
       
   427 void CSuplProtocolManager::LocationReq(const TLbsNetSessionId& aSessionId, 
       
   428 				 const MLbsNetworkProtocolObserver::TLbsNetProtocolService& aType, 
       
   429 				const TLbsNetPosRequestQuality& aQuality, const TLbsNetPosRequestMethod& aPosMethod)
       
   430 	{
       
   431 	SUPLLOG(ELogP1, "CSuplProtocolManager::LocationReq() Begin\n");
       
   432 
       
   433 	// Let the assistance data manager know that the machine doing service of
       
   434 	// type aType is able to accept assistance data requests.
       
   435 	//
       
   436 	iAssistMgr->MachineReadyForAssistanceDataRequest(aType);
       
   437 
       
   438 	// Fordward network-received location request to Gateway Interface
       
   439 	iGateway.LocationReq(aSessionId, aType, aQuality, aPosMethod);
       
   440 	SUPLLOG(ELogP1, "CSuplProtocolManager::LocationReq() End\n");
       
   441 	}
       
   442 
       
   443 /** Handle a Privacy Request after receiving a SUPL INIT
       
   444 
       
   445 @param aSessionId session ID of the state machine that issues the request
       
   446 @param aPrivacy Privacy advice based on received SUPL INIT
       
   447 @param aRequestInfo Information about the requestor of the MT-LR from SUPL INIT
       
   448 */
       
   449 void CSuplProtocolManager::PrivacyReq(const TLbsNetSessionId& aSessionId,
       
   450 									   const TLbsNetPosRequestPrivacy& aPrivacy,
       
   451 									   const TLbsExternalRequestInfo& aRequestInfo)
       
   452 {
       
   453 	SUPLLOG(ELogP1, "CSuplProtocolManager::PrivacyReq() Begin\n");
       
   454 	// Fordward network-received location request to Gateway Interface
       
   455 	iGateway.PrivacyReq(aSessionId, EFalse, // No Emergency MT-LR in SUPL v1.0 
       
   456 					    aPrivacy, aRequestInfo);	
       
   457 	SUPLLOG(ELogP1, "CSuplProtocolManager::PrivacyReq() End\n");
       
   458 }
       
   459 
       
   460 
       
   461 /** Send Assistance Data from the state machines to the Assistance Data Manager
       
   462 
       
   463 This method is called by state machines when they have assistance data for LBS.
       
   464 
       
   465 @see CSuplAssistanceDataManager
       
   466 @see MSuplFsmSessionObserver
       
   467 */
       
   468 void CSuplProtocolManager::ProcessAssistanceData(const TLbsAsistanceDataGroup& aGroupMask, 
       
   469 							   const RLbsAssistanceDataBuilderSet& aData,const TInt& aReason,
       
   470 							   const MLbsNetworkProtocolObserver::TLbsNetProtocolService& aService)
       
   471 	{
       
   472 	SUPLLOG(ELogP1, "CSuplProtocolManager::ProcessAssistanceData() Begin\n");
       
   473 
       
   474 	// Get the session Id of the machine reporting assistance data
       
   475 	//
       
   476 	TLbsNetSessionId sessionId;
       
   477 	if (MLbsNetworkProtocolObserver::EServiceSelfLocation == aService)
       
   478 		{
       
   479 		sessionId = iMoLr->LbsSessionId();	
       
   480 		}
       
   481 	else if (MLbsNetworkProtocolObserver::EServiceMobileTerminated == aService)
       
   482 		{
       
   483 		sessionId = iMtLr->LbsSessionId();		
       
   484 		}
       
   485 	else
       
   486 		{
       
   487 		ASSERT(EFalse);
       
   488 		}
       
   489 
       
   490 	// Pass received assistance data to the assistance data manager
       
   491 	//
       
   492 	iAssistMgr->AssistanceDataReport(aData, aGroupMask, aReason, aService, sessionId);	
       
   493 	SUPLLOG(ELogP1, "CSuplProtocolManager::ProcessAssistanceData() End\n");
       
   494 	}
       
   495 
       
   496 
       
   497 
       
   498 
       
   499 // --------------------------------   MSuplNetworkInfoObserver methods ----------------------------------------------
       
   500 
       
   501 void CSuplProtocolManager::NetInfoResults(const RMobilePhone::TMobilePhoneNetworkInfoV1& aNetworkInfo,
       
   502 						   const RMobilePhone::TMobilePhoneLocationAreaV1& aLocationArea)
       
   503 	{
       
   504 	SUPLLOG(ELogP1, "CSuplProtocolManager::NetInfoResults() Begin\n");
       
   505 	iMoLr->StoreNetInfo(aNetworkInfo,aLocationArea);
       
   506 	iNetLoc->StoreNetInfo(aNetworkInfo,aLocationArea);
       
   507 	iMtLr->StoreNetInfo(aNetworkInfo,aLocationArea);
       
   508 	SUPLLOG(ELogP1, "CSuplProtocolManager::NetInfoResults() End\n");
       
   509 	}
       
   510 
       
   511 void CSuplProtocolManager::HomeMccMncResult(TUint aMcc, TUint aMnc)
       
   512 	{
       
   513 	SUPLLOG(ELogP1, "CSuplProtocolManager::HomeMccMncResult() Begin\n");
       
   514 	iMoLr->StoreMccMnc(aMcc, aMnc);
       
   515 	iNetLoc->StoreMccMnc(aMcc, aMnc);
       
   516 	iMtLr->StoreMccMnc(aMcc, aMnc);
       
   517 	SUPLLOG(ELogP1, "CSuplProtocolManager::HomeMccMncResult() End\n");
       
   518 	}
       
   519 
       
   520 void CSuplProtocolManager::MsisdnResult(const TDesC& aTelNumber)
       
   521 	{
       
   522 	SUPLLOG(ELogP1, "CSuplProtocolManager::MsisdnResult() Begin\n");
       
   523 	iMoLr->StoreMsisdn(aTelNumber);
       
   524 	iNetLoc->StoreMsisdn(aTelNumber);
       
   525 	iMtLr->StoreMsisdn(aTelNumber);
       
   526 	SUPLLOG(ELogP1, "CSuplProtocolManager::MsisdnResult() End\n");
       
   527 	}
       
   528 
       
   529 void CSuplProtocolManager::CellInfoResults(const RMobilePhone::TMobilePhoneCellInfoV9& aCellInfo)
       
   530 	{
       
   531 	SUPLLOG(ELogP1, "CSuplProtocolManager::CellInfoResults() Begin\n");
       
   532 	iMoLr->StoreCellInfo(aCellInfo);
       
   533 	iNetLoc->StoreCellInfo(aCellInfo);
       
   534 	iMtLr->StoreCellInfo(aCellInfo);
       
   535 	SUPLLOG(ELogP1, "CSuplProtocolManager::CellInfoResults() End\n");
       
   536 	}
       
   537 
       
   538 //-------------------------------- Private methods ----------------------------------------------------------
       
   539 
       
   540 /** Inform LBS of status update.
       
   541 This is called when a new operation starts or when a current operation ends.
       
   542 
       
   543 @param aService Indicates the type of service that has started or stopped
       
   544 @param aIsOperationStarting ETrue if operation is starting
       
   545 */
       
   546 void CSuplProtocolManager::StatusUpdate(
       
   547 					const MLbsNetworkProtocolObserver::TLbsNetProtocolService& aService, 
       
   548 					const TBool& aIsOperationStarting)
       
   549 	{
       
   550 	SUPLLOG(ELogP1, "CSuplProtocolManager::StatusUpdate() Begin\n");
       
   551 	if (aIsOperationStarting)
       
   552 		{
       
   553 		iActiveServiceMask |= aService;
       
   554 		}
       
   555 	else
       
   556 		{
       
   557 		iActiveServiceMask &= ~aService;
       
   558 		}
       
   559 
       
   560 	 Gateway().StatusUpdate(iActiveServiceMask);
       
   561 	SUPLLOG(ELogP1, "CSuplProtocolManager::StatusUpdate() End\n");
       
   562 	}
       
   563 
       
   564 
       
   565 /** Resolve the conflict between active procedures and a new request.
       
   566 
       
   567 @param aNewOperation The type of operation that is represented by the new request.
       
   568 @param aNewOperationOptions Options about the new operation that affect conflict control (posMethod, newClient,...)
       
   569 @param aNoMoreAssistDataNeeded A boolean that is 'true' is no assistance data is needed by the new operation.
       
   570 @return TConflictResult The action arising from the conflict resolution that is to be done.
       
   571 */
       
   572 CSuplConflictManager::TConflictResult CSuplProtocolManager::ResolveConflict(
       
   573 					const MLbsNetworkProtocolObserver::TLbsNetProtocolService& aNewOperation, 
       
   574 					const TLbsNetPosRequestOptionsBase& aNewOperationOptions)
       
   575 	{
       
   576 	SUPLLOG(ELogP1, "CSuplProtocolManager::ResolveConflict() Begin\n");
       
   577 
       
   578 	CSuplConflictManager::TConflictResult conflictResult = CSuplConflictManager::EConflictNone;
       
   579 
       
   580 	if (iActiveServiceMask != 0)
       
   581 		{
       
   582 		conflictResult = iConflictManager->ConflictDecision(iActiveServiceMask, aNewOperation, aNewOperationOptions);
       
   583 		}
       
   584 	else
       
   585 		{
       
   586 		// no previous active operation = no conflict
       
   587 		}
       
   588 
       
   589 	SUPLLOG(ELogP1, "CSuplProtocolManager::ResolveConflict() End\n");
       
   590 	return conflictResult;
       
   591 	}
       
   592 
       
   593 /** Receive notification about an incoming SUPL INIT message.
       
   594 
       
   595 @param aChannel  [In] The channel the call-back is related to.
       
   596 @param aReqId    [In] An Id of the request the call-back is related to.
       
   597 @param aMsg      [In] A buffer containing a SUPL INIT message.
       
   598 @see CLbsSuplPushRec::SuplInitComplete
       
   599 @see CLbsSuplPush::SuplInit
       
   600 */
       
   601 void CSuplProtocolManager::OnSuplInit(TLbsSuplPushChannel aChannel, TLbsSuplPushRequestId aReqId, TDesC8& aMsg)
       
   602 	{
       
   603 	SUPLLOG(ELogP1, "CSuplProtocolManager::OnSuplInit() Begin\n");
       
   604 	TInt err = KErrNone;
       
   605 	TInt reserved = KErrNone;
       
   606 	
       
   607 	TRAP(err, ProcessSuplInitL(aMsg));
       
   608 	
       
   609 	// notify the SUPL push receiver that the SUPL INIT has been received and processed.
       
   610 	iPushRec->SuplInitComplete(aChannel, aReqId, err, reserved);
       
   611 	SUPLLOG(ELogP1, "CSuplProtocolManager::OnSuplInit() End\n");
       
   612 	}
       
   613 
       
   614 void CSuplProtocolManager::ProcessSuplInitL(TDesC8& aMsg)
       
   615 	{
       
   616 	SUPLLOG(ELogP1, "CSuplProtocolManager::ProcessSuplInitL() Begin\n");
       
   617 	TInt error;
       
   618 	// decode the received message
       
   619 	CSuplAsn1Decoder* decoder = CSuplAsn1Decoder::NewL();
       
   620 	CleanupStack::PushL(decoder);
       
   621 	TPtrC8 msg(aMsg);
       
   622 	
       
   623 	// Check that the encoded length of the SUPL message matches 
       
   624 	// the actual length of the encoded supl message descriptor
       
   625 	TInt lengthField = msg[0] << 8;
       
   626 	lengthField |= msg[1];
       
   627 	if(msg.Length() != lengthField)
       
   628 		{
       
   629 		// Encoded message length does not match actual message length.
       
   630 		SUPLLOG3(ELogP1, "CSuplProtocolManager::ProcessSuplInitL() msg length (%d) != length field (%d)", msg.Length(), lengthField);
       
   631 		User::Leave(KErrCorrupt);
       
   632 		}
       
   633 
       
   634 	CSuplMessageBase* message = decoder->DecodeL(&msg, error);
       
   635 	CleanupStack::PushL(message);
       
   636 	
       
   637 	// check for decode error 
       
   638 	if (error!= KErrNone)
       
   639 		{
       
   640 		User::Leave(error);
       
   641 		}
       
   642 	
       
   643 	// check message is in fact a SUPL INIT
       
   644 	if (message->MessageType() != CSuplMessageBase::ESuplInit)
       
   645 		{
       
   646 		User::Leave(KErrNotSupported);
       
   647 		}
       
   648 	
       
   649 
       
   650 	// Check if this supl packets major version is supported by
       
   651 	// this implementation of the protocol
       
   652 
       
   653 	// Get major version from message.
       
   654 	CSuplVersion* version = CSuplVersion::NewL();
       
   655 	CleanupStack::PushL(version);
       
   656 	User::LeaveIfError(message->GetVersion(*version));
       
   657 
       
   658 	// Check if version is supported.
       
   659 	TBool versionMatchFound = EFalse;
       
   660 	for (TInt i = 0; i < iSupportedVersions.Count(); i++)
       
   661 		{
       
   662 		if (version->iMaj == iSupportedVersions[i])
       
   663 			{
       
   664 			versionMatchFound = ETrue;
       
   665 			break;
       
   666 			}
       
   667 		}
       
   668 
       
   669 	// Version not supported.
       
   670 	if (!versionMatchFound)
       
   671 		{
       
   672 		User::Leave(KErrNotSupported);
       
   673 		}
       
   674 
       
   675 	CleanupStack::PopAndDestroy(version);
       
   676 
       
   677 
       
   678 	// pop message off the stack as ownership will be
       
   679 	// transferred
       
   680 	CleanupStack::Pop(message);
       
   681 	NetworkLocationReq(message);
       
   682 	
       
   683 	CleanupStack::PopAndDestroy(decoder);
       
   684 	SUPLLOG(ELogP1, "CSuplProtocolManager::ProcessSuplInitL() End\n");
       
   685 	}
       
   686 
       
   687 /** Handle Network Location Request (SUPL INIT)
       
   688 */
       
   689 void CSuplProtocolManager::NetworkLocationReq(CSuplMessageBase* aSuplInit)
       
   690 	{
       
   691 	SUPLLOG(ELogP1, "CSuplProtocolManager::NetworkLocationReqL() Begin\n");
       
   692 	TBool messageTransferred = EFalse;
       
   693 	CSuplInit* suplInit = static_cast<CSuplInit*> (aSuplInit);
       
   694 	
       
   695 	// Set the Position Request options according to the received QoP element.
       
   696 	TLbsNetPosRequestOptions options;
       
   697 	options.SetNewClientConnected(ETrue);
       
   698 	TLbsNetPosRequestQuality quality;
       
   699 	if (suplInit->QopPresent())
       
   700 		{
       
   701 		suplInit->GetQop(quality);
       
   702 		options.SetRequestQuality(quality);
       
   703 		}
       
   704 		
       
   705 	// Check if the conflict controller allows the network initiated location request
       
   706 	switch (ResolveConflict(MLbsNetworkProtocolObserver::EServiceMobileTerminated, options))
       
   707 		{
       
   708 		// proceeed with the new request.
       
   709 		case CSuplConflictManager::EConflictNone:
       
   710 			// Status update sent to LBS
       
   711 			StatusUpdate(MLbsNetworkProtocolObserver::EServiceMobileTerminated, ETrue); // ETrue=new operation
       
   712 
       
   713 			// Start the MT-LR (passes ownership of CSuplInit object)
       
   714 			iMtLr->MtLrReq(NewSessionId(), suplInit); 
       
   715 			messageTransferred = ETrue;
       
   716 			break;
       
   717 
       
   718 		// Reject the new request
       
   719 		case CSuplConflictManager::EConflictRejectNew:
       
   720 			// Silently drop the SUPL INIT
       
   721 			break;
       
   722 
       
   723 		default:
       
   724 			// No other conflict decisions are currently supported after
       
   725 			// SUPL INIT
       
   726 			//
       
   727 			ASSERT(EFalse);
       
   728 			break;
       
   729 		}
       
   730 	
       
   731 	if (!messageTransferred)
       
   732 		{
       
   733 		delete suplInit;
       
   734 		}
       
   735 	
       
   736 	SUPLLOG(ELogP1, "CSuplProtocolManager::NetworkLocationReqL() End\n");
       
   737 	}
       
   738