networkprotocolmodules/common/suplrrlpasn1/src/suplinit.cpp
branchGCC_SURGE
changeset 49 5f20f71a57a3
parent 41 ec40843d536a
parent 45 15a2125aa2f3
equal deleted inserted replaced
41:ec40843d536a 49:5f20f71a57a3
     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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalTechnology
       
    19  
       
    20 */
       
    21 
       
    22 #include "suplmessagebase.h"
       
    23 #include "ULP.h"
       
    24 #include "suplinit.h"
       
    25 #include "supldevloggermacros.h" 
       
    26 #include <lbs/lbslocclasstypes.h>
       
    27 #include <hash.h>
       
    28 
       
    29 /**
       
    30 Static factory constructor
       
    31 */
       
    32 EXPORT_C CSuplInit* CSuplInit::NewL()
       
    33 	{
       
    34 	SUPLLOG(ELogP1, "CSuplInit::NewL() Begin\n");
       
    35 	CSuplInit* self = new (ELeave) CSuplInit();
       
    36 	CleanupStack::PushL(self);
       
    37 	self->ConstructL();
       
    38 	SUPLLOG(ELogP1, "CSuplInit::NewL() End\n");
       
    39 	CleanupStack::Pop(self);
       
    40 	return self;
       
    41 	}
       
    42 	
       
    43 /** 
       
    44 Constructor 
       
    45 */
       
    46 CSuplInit::CSuplInit()
       
    47  : CSuplMessageBase::CSuplMessageBase(ESuplInit, EFalse)
       
    48 	{
       
    49 	}
       
    50 
       
    51 /** 
       
    52 Second stage constructor
       
    53 */
       
    54 void CSuplInit::ConstructL()
       
    55 	{
       
    56 	CSuplMessageBase::ConstructL();
       
    57 	}
       
    58 
       
    59 /**
       
    60 Destructor
       
    61 */	
       
    62 CSuplInit::~CSuplInit()
       
    63 	{
       
    64 	SUPLLOG(ELogP1, "CSuplInit::~CSuplInit() Begin\n");
       
    65 	delete iMessage;
       
    66 	SUPLLOG(ELogP1, "CSuplInit::~CSuplInit() End\n");
       
    67 	}
       
    68 
       
    69 /** 
       
    70 GetPosMethod() 
       
    71 
       
    72 Populates aMethod according to SUPL INIT positioning method parameter 
       
    73 
       
    74 The Positioning Method parameter of the SUPL INIT message is the method
       
    75 desired by the SLP for the SUPL POS session.
       
    76 
       
    77 @param aMethod, on return populated as per the positioning method element
       
    78 @return error indication, KErrNone otherwise
       
    79 */
       
    80 EXPORT_C TInt CSuplInit::GetPosMethod(TLbsNetPosRequestMethod& aMethod)
       
    81 	{
       
    82 	__ASSERT_DEBUG(iData->message.u.msSUPLINIT != NULL, User::Invariant());
       
    83 
       
    84 	SUPLLOG(ELogP1, "CSuplInit::GetPosMethod() Begin\n");
       
    85 	
       
    86 	// retrieve the posMethod value
       
    87 	ASN1T_PosMethod posMethod = iData->message.u.msSUPLINIT->posMethod;
       
    88 	
       
    89 	TLbsNetPosMethod posMethods[2];
       
    90 	TInt numMethods = 1;
       
    91 	
       
    92 	switch (posMethod)
       
    93 		{
       
    94 		case PosMethod::agpsSETassisted:
       
    95 			posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
    96 			break;
       
    97 
       
    98 		case PosMethod::agpsSETbased:
       
    99 			posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);
       
   100 			break;
       
   101 
       
   102 		case PosMethod::agpsSETassistedpref:
       
   103 			posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   104 			posMethods[1].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);		
       
   105 			++numMethods;
       
   106 			break;
       
   107 
       
   108 		case PosMethod::PosMethod::agpsSETbasedpref:
       
   109 			posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal | TPositionModuleInfo::ETechnologyAssisted);
       
   110 			posMethods[1].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyNetwork | TPositionModuleInfo::ETechnologyAssisted);
       
   111 			++numMethods;
       
   112 			break;
       
   113 
       
   114 		case PosMethod::autonomousGPS:
       
   115 			posMethods[0].SetPosMethod(KLbsPositioningMeansGps, TPositionModuleInfo::ETechnologyTerminal);
       
   116 			break;
       
   117 
       
   118 		case PosMethod::aFLT:
       
   119 			posMethods[0].SetPosMethod(KLbsPositioningMeansAflt, TPositionModuleInfo::ETechnologyTerminal);
       
   120 			break;
       
   121 
       
   122 		case PosMethod::eCID:
       
   123 			posMethods[0].SetPosMethod(KLbsPositioningMeansCell, TPositionModuleInfo::ETechnologyTerminal);
       
   124 			break;
       
   125 
       
   126 		case PosMethod::PosMethod::eOTD:
       
   127 			posMethods[0].SetPosMethod(KLbsPositioningMeansEotd, TPositionModuleInfo::ETechnologyTerminal);
       
   128 			break;
       
   129 
       
   130 		case PosMethod::oTDOA:
       
   131 			posMethods[0].SetPosMethod(KLbsPositioningMeansOtdoa, TPositionModuleInfo::ETechnologyTerminal);
       
   132 			break;
       
   133 
       
   134 		case PosMethod::noPosition:
       
   135 			posMethods[0].SetPosMethod(KLbsPositioningMeansNone, TPositionModuleInfo::ETechnologyTerminal);
       
   136 			break;
       
   137 
       
   138 		default:
       
   139 			// error
       
   140 			__ASSERT_DEBUG(EFalse, User::Invariant());
       
   141 			SUPLLOG(ELogP1, "CSuplInit::GetPosMethod() Error - invalid argument\n");
       
   142 			return KErrArgument;
       
   143 		}
       
   144 
       
   145 	// populate the return parameter	
       
   146 	TInt err = aMethod.SetPosMethods(posMethods, numMethods);
       
   147 
       
   148 	SUPLLOG(ELogP1, "CSuplInit::GetPosMethod() End\n");
       
   149 	return err;
       
   150 	}
       
   151 	
       
   152 
       
   153 /** 
       
   154 NotificationPresent()
       
   155 
       
   156 @return ETrue if optional notification parameter is present, EFalse otherwise
       
   157 */
       
   158 EXPORT_C TBool CSuplInit::NotificationPresent()
       
   159 	{
       
   160 	SUPLLOG(ELogP1, "CSuplInit::NotificationPresent() Begin\n");
       
   161 	__ASSERT_DEBUG(iData->message.u.msSUPLINIT != NULL, User::Invariant());
       
   162 	
       
   163 	if (iData->message.u.msSUPLINIT->m.notificationPresent != 0)
       
   164 		{
       
   165 		SUPLLOG(ELogP1, "CSuplInit::NotificationPresent(ETrue) End\n");
       
   166 		return ETrue;
       
   167 		}
       
   168 	SUPLLOG(ELogP1, "CSuplInit::NotificationPresent(EFalse) End\n");
       
   169 	return EFalse;
       
   170 	}
       
   171 	
       
   172 /** 
       
   173 NotificationType()
       
   174 
       
   175 Populates aPrivacy according to SUPL INIT notification element.
       
   176 
       
   177 If the notification element is not present, this is interpreted as "no 
       
   178 notification and no verification", as per the SUPL spec.
       
   179 
       
   180 @param  aPrivacy, populated according to the notification element
       
   181 @return error indication, KErrNone otherwise
       
   182 */
       
   183 EXPORT_C TInt CSuplInit::GetNotificationType(TLbsNetPosRequestPrivacy& aPrivacy)
       
   184 	{
       
   185 	__ASSERT_DEBUG(iData->message.u.msSUPLINIT != NULL, User::Invariant());
       
   186 	SUPLLOG(ELogP1, "CSuplInit::NotificationType() Begin\n");
       
   187 
       
   188 	if (iData->message.u.msSUPLINIT->m.notificationPresent == 0)
       
   189 		{
       
   190 		aPrivacy.SetRequestAdvice(TLbsNetPosRequestPrivacy::ERequestAdviceSilent);
       
   191 		aPrivacy.SetRequestAction(TLbsNetPosRequestPrivacy::ERequestActionAllow);
       
   192 		}
       
   193 	else
       
   194 		{
       
   195 		ASN1T_Notification& notification = iData->message.u.msSUPLINIT->notification;
       
   196 		
       
   197 		// populate privacy request according to notification type.
       
   198 		switch (notification.notificationType)
       
   199 			{
       
   200 			case NotificationType::noNotificationNoVerification:
       
   201 				{
       
   202 				aPrivacy.SetRequestAdvice(TLbsNetPosRequestPrivacy::ERequestAdviceSilent);
       
   203 				aPrivacy.SetRequestAction(TLbsNetPosRequestPrivacy::ERequestActionAllow);
       
   204 				break;
       
   205 				}
       
   206 			case NotificationType::notificationOnly:
       
   207 				{
       
   208 				aPrivacy.SetRequestAdvice(TLbsNetPosRequestPrivacy::ERequestAdviceNotify);
       
   209 				aPrivacy.SetRequestAction(TLbsNetPosRequestPrivacy::ERequestActionAllow);
       
   210 				break;
       
   211 				}
       
   212 			case NotificationType::notificationAndVerficationAllowedNA:
       
   213 				{
       
   214 				aPrivacy.SetRequestAdvice(TLbsNetPosRequestPrivacy::ERequestAdviceVerify);
       
   215 				aPrivacy.SetRequestAction(TLbsNetPosRequestPrivacy::ERequestActionAllow);
       
   216 				break;
       
   217 				}
       
   218 			case NotificationType::notificationAndVerficationDeniedNA:
       
   219 				{
       
   220 				aPrivacy.SetRequestAdvice(TLbsNetPosRequestPrivacy::ERequestAdviceVerify);
       
   221 				aPrivacy.SetRequestAction(TLbsNetPosRequestPrivacy::ERequestActionReject);
       
   222 				break;
       
   223 				}
       
   224 			case NotificationType::privacyOverride:
       
   225 				{
       
   226 				// this is option is not implemented by the LBS subsystem
       
   227 				aPrivacy.SetRequestAdvice(TLbsNetPosRequestPrivacy::ERequestAdviceStealth);
       
   228 				aPrivacy.SetRequestAction(TLbsNetPosRequestPrivacy::ERequestActionAllow);
       
   229 				break;
       
   230 				}
       
   231 			default:
       
   232 				{
       
   233 				// error
       
   234 				__ASSERT_DEBUG(EFalse, User::Invariant());
       
   235 				SUPLLOG(ELogP1, "CSuplInit::NotificationType() Error - invalid notification type\n");
       
   236 				return KErrNotFound;
       
   237 				}
       
   238 			}
       
   239 		}
       
   240 
       
   241 	SUPLLOG(ELogP1, "CSuplInit::NotificationType() End\n");
       
   242 	return KErrNone;
       
   243 	}
       
   244 		
       
   245 /** 
       
   246 ExternalRequestInfoPresent()
       
   247 
       
   248 @return ETrue if optional requestor id and/or client name subparameter of the 
       
   249 		notification element is present 
       
   250 		EFalse otherwise
       
   251 */
       
   252 EXPORT_C TBool CSuplInit::ExternalRequestInfoPresent()
       
   253 	{
       
   254 	SUPLLOG(ELogP1, "CSuplInit::ExternalRequestInfoPresent() Begin\n");
       
   255 	__ASSERT_DEBUG(iData->message.u.msSUPLINIT != NULL, User::Invariant());
       
   256 	
       
   257 	if (iData->message.u.msSUPLINIT->m.notificationPresent != 0)
       
   258 		{
       
   259 		if (iData->message.u.msSUPLINIT->notification.m.requestorIdPresent != 0 ||
       
   260 		    iData->message.u.msSUPLINIT->notification.m.clientNamePresent  != 0 )
       
   261 			{
       
   262 			SUPLLOG(ELogP1, "CSuplInit::ExternalRequestInfoPresent(ETrue) End\n");
       
   263 			return ETrue;
       
   264 			}
       
   265 		}
       
   266 	SUPLLOG(ELogP1, "CSuplInit::ExternalRequestInfoPresent(EFalse) End\n");
       
   267 	return EFalse;
       
   268 	}
       
   269 
       
   270 
       
   271 /** 
       
   272 ExternalRequestInfo()
       
   273 
       
   274 Populates aRequestInfo according to SUPL INIT requestor id and/or client name 
       
   275 sub-elements of the notification element.
       
   276 
       
   277 @param  aRequestInfo, populated according to received notification element
       
   278 @return KErrNotFound if the notification element is not present
       
   279 		KErrNone     otherwise
       
   280 */
       
   281 EXPORT_C TInt CSuplInit::GetExternalRequestInfo(TLbsExternalRequestInfo& aRequestInfo)
       
   282 	{
       
   283 	__ASSERT_DEBUG(iData->message.u.msSUPLINIT != NULL, User::Invariant());
       
   284 	SUPLLOG(ELogP1, "CSuplInit::ExternalRequestInfo() Begin\n");
       
   285 
       
   286 	if (iData->message.u.msSUPLINIT->m.notificationPresent != 0)
       
   287 		{
       
   288 		ASN1T_Notification& notification = iData->message.u.msSUPLINIT->notification;
       
   289 
       
   290 		// process requestor ID if it is present
       
   291 		if (notification.m.requestorIdPresent != 0 && notification.m.requestorIdTypePresent != 0)
       
   292 			{
       
   293 			// requestor type
       
   294 			switch (notification.requestorIdType)
       
   295 				{
       
   296 				case FormatIndicator::logicalName:
       
   297 					{
       
   298 					aRequestInfo.SetRequesterIdFormat(TLbsExternalRequestInfo::EFormatLogicalName);
       
   299 					break;
       
   300 					}
       
   301       			case FormatIndicator::e_mailAddress:
       
   302 					{
       
   303 					aRequestInfo.SetRequesterIdFormat(TLbsExternalRequestInfo::EFormatEmailAddress);
       
   304 					break;
       
   305 					}
       
   306       			case FormatIndicator::msisdn:
       
   307 					{
       
   308 					aRequestInfo.SetRequesterIdFormat(TLbsExternalRequestInfo::EFormatMSISDN);
       
   309 					break;
       
   310 					}
       
   311       			case FormatIndicator::url:
       
   312 					{
       
   313 					aRequestInfo.SetRequesterIdFormat(TLbsExternalRequestInfo::EFormatURL);
       
   314 					break;
       
   315 					}
       
   316       			case FormatIndicator::sipUrl:
       
   317 					{
       
   318 					aRequestInfo.SetRequesterIdFormat(TLbsExternalRequestInfo::EFormatSIPURL);
       
   319 					break;
       
   320 					}
       
   321       			case FormatIndicator::min:
       
   322 					{
       
   323 					aRequestInfo.SetRequesterIdFormat(TLbsExternalRequestInfo::EFormatMIN);
       
   324 					break;
       
   325 					}
       
   326       			case FormatIndicator::mdn:
       
   327 					{
       
   328 					aRequestInfo.SetRequesterIdFormat(TLbsExternalRequestInfo::EFormatMDN);
       
   329 					break;
       
   330 					}
       
   331 				default:
       
   332 					{
       
   333 					// error
       
   334 					__ASSERT_DEBUG(EFalse, User::Invariant());
       
   335 					aRequestInfo.SetRequesterIdFormat(TLbsExternalRequestInfo::EFormatUnknown);
       
   336 					break;
       
   337 					}
       
   338 				}
       
   339 			
       
   340 			// requestor id
       
   341 			ASN1T_Notification_requestorId& requestorId = notification.requestorId;
       
   342 			TPtrC8 ptr(requestorId.data, requestorId.numocts);
       
   343 			aRequestInfo.SetRequesterId(ptr);
       
   344 			
       
   345 			// requestor encoding type
       
   346 			switch (notification.encodingType)
       
   347 				{
       
   348 				case EncodingType::ucs2:
       
   349 					{
       
   350 					aRequestInfo.SetRequesterIdCodingScheme(TLbsExternalRequestInfo::ECodingSchemeUCS2);
       
   351 					break;
       
   352 					}
       
   353       			case EncodingType::gsmDefault:
       
   354       				{
       
   355       				aRequestInfo.SetRequesterIdCodingScheme(TLbsExternalRequestInfo::ECodingSchemeGSMDefault);
       
   356       				break;
       
   357       				}
       
   358       			case EncodingType::utf8:
       
   359       				{
       
   360             		aRequestInfo.SetRequesterIdCodingScheme(TLbsExternalRequestInfo::ECodingSchemeUTF8);
       
   361             		break;
       
   362             		}
       
   363       			default:
       
   364       				{
       
   365 					// error
       
   366 					__ASSERT_DEBUG(EFalse, User::Invariant());
       
   367       				aRequestInfo.SetRequesterIdCodingScheme(TLbsExternalRequestInfo::ECodingSchemeUnknown);
       
   368       				break;
       
   369       				}
       
   370 				}
       
   371 			}
       
   372 
       
   373 		// process Client Name if it is present
       
   374 		if (notification.m.clientNamePresent != 0 && notification.m.clientNameTypePresent != 0)
       
   375 			{
       
   376 			// client name type
       
   377 			switch (notification.clientNameType)
       
   378 				{
       
   379 				case FormatIndicator::logicalName:
       
   380 					{
       
   381 					aRequestInfo.SetClientNameFormat(TLbsExternalRequestInfo::EFormatLogicalName);
       
   382 					break;
       
   383 					}
       
   384       			case FormatIndicator::e_mailAddress:
       
   385 					{
       
   386 					aRequestInfo.SetClientNameFormat(TLbsExternalRequestInfo::EFormatEmailAddress);
       
   387 					break;
       
   388 					}
       
   389       			case FormatIndicator::msisdn:
       
   390 					{
       
   391 					aRequestInfo.SetClientNameFormat(TLbsExternalRequestInfo::EFormatMSISDN);
       
   392 					break;
       
   393 					}
       
   394       			case FormatIndicator::url:
       
   395 					{
       
   396 					aRequestInfo.SetClientNameFormat(TLbsExternalRequestInfo::EFormatURL);
       
   397 					break;
       
   398 					}
       
   399       			case FormatIndicator::sipUrl:
       
   400 					{
       
   401 					aRequestInfo.SetClientNameFormat(TLbsExternalRequestInfo::EFormatSIPURL);
       
   402 					break;
       
   403 					}
       
   404       			case FormatIndicator::min:
       
   405 					{
       
   406 					aRequestInfo.SetClientNameFormat(TLbsExternalRequestInfo::EFormatMIN);
       
   407 					break;
       
   408 					}
       
   409       			case FormatIndicator::mdn:
       
   410 					{
       
   411 					aRequestInfo.SetClientNameFormat(TLbsExternalRequestInfo::EFormatMDN);
       
   412 					break;
       
   413 					}
       
   414 				default:
       
   415 					{
       
   416 					// error
       
   417 					__ASSERT_DEBUG(EFalse, User::Invariant());
       
   418 					aRequestInfo.SetClientNameFormat(TLbsExternalRequestInfo::EFormatUnknown);
       
   419 					break;
       
   420 					}
       
   421 				}
       
   422 			
       
   423 			// client name
       
   424 			ASN1T_Notification_clientName& clientName = notification.clientName;
       
   425 			TPtrC8 ptr(clientName.data, clientName.numocts);
       
   426 			aRequestInfo.SetClientName(ptr);
       
   427 			
       
   428 			// client name encoding type
       
   429 			switch (notification.encodingType)
       
   430 				{
       
   431 				case EncodingType::ucs2:
       
   432 					{
       
   433 					aRequestInfo.SetClientNameCodingScheme(TLbsExternalRequestInfo::ECodingSchemeUCS2);
       
   434 					break;
       
   435 					}
       
   436       			case EncodingType::gsmDefault:
       
   437       				{
       
   438       				aRequestInfo.SetClientNameCodingScheme(TLbsExternalRequestInfo::ECodingSchemeGSMDefault);
       
   439       				break;
       
   440       				}
       
   441       			case EncodingType::utf8:
       
   442       				{
       
   443             		aRequestInfo.SetClientNameCodingScheme(TLbsExternalRequestInfo::ECodingSchemeUTF8);
       
   444             		break;
       
   445             		}
       
   446       			default:
       
   447       				{
       
   448 					// error
       
   449 					__ASSERT_DEBUG(EFalse, User::Invariant());
       
   450       				aRequestInfo.SetClientNameCodingScheme(TLbsExternalRequestInfo::ECodingSchemeUnknown);
       
   451       				break;
       
   452       				}
       
   453 				}
       
   454 			}
       
   455 		
       
   456 		SUPLLOG(ELogP1, "CSuplInit::ExternalRequestInfo() End\n");
       
   457 		return KErrNone;
       
   458 		}
       
   459 	
       
   460 	// notification element not present.	
       
   461 	SUPLLOG(ELogP1, "CSuplInit::ExternalRequestInfo() End (Notification element not present)\n");
       
   462 	return KErrNotFound;
       
   463 	}
       
   464 
       
   465 
       
   466 /** 
       
   467 SlpAddressPresent()
       
   468 
       
   469 The SLP address is mandatory for non-Proxy mode operation, for proxy mode
       
   470 operation the paramater is optional.
       
   471 
       
   472 @return ETrue if optional SLP address parameter is present, EFalse otherwise
       
   473 */
       
   474 EXPORT_C TBool CSuplInit::SlpAddressPresent()
       
   475 	{
       
   476 	SUPLLOG(ELogP1, "CSuplInit::SlpAddressPresent() Begin\n");
       
   477 	__ASSERT_DEBUG(iData->message.u.msSUPLINIT != NULL, User::Invariant());
       
   478 	
       
   479 	if (iData->message.u.msSUPLINIT->m.sLPAddressPresent != 0)
       
   480 		{
       
   481 		SUPLLOG(ELogP1, "CSuplInit::SlpAddressPresent(ETrue) End\n");
       
   482 		return ETrue;
       
   483 		}
       
   484 	
       
   485 	SUPLLOG(ELogP1, "CSuplInit::SlpAddressPresent(EFalse) End\n");
       
   486 	return EFalse;
       
   487 	}
       
   488 
       
   489 
       
   490 /** 
       
   491 SlpAddress()
       
   492 
       
   493 Populates aAddress according to SUPL INIT SLP address parameter 
       
   494 
       
   495 The SLP address is mandatory for non-Proxy mode operation, for proxy mode
       
   496 operation the paramater is optional.
       
   497 
       
   498 @param aAddress, populated according to the SLP Address Parameter
       
   499 @return error indication, KErrNone otherwise
       
   500 */
       
   501 EXPORT_C TInt CSuplInit::GetSlpAddress(CSuplSlpAddress& aAddress)
       
   502 	{
       
   503 	SUPLLOG(ELogP1, "CSuplInit::SlpAddress() Begin\n");
       
   504 	__ASSERT_DEBUG(iData->message.u.msSUPLINIT != NULL, User::Invariant());
       
   505 	
       
   506 	if (iData->message.u.msSUPLINIT->m.sLPAddressPresent == 0)
       
   507 		{
       
   508 		SUPLLOG(ELogP1, "CSuplInit::SlpAddress() End (SLP Address Not Present)\n");
       
   509 		return KErrNotFound;
       
   510 		}
       
   511 	
       
   512 	ASN1T_SLPAddress& slpAddress = iData->message.u.msSUPLINIT->sLPAddress;
       
   513 	
       
   514 	switch (slpAddress.t)
       
   515 		{
       
   516 		case T_SLPAddress_iPAddress:
       
   517 			{
       
   518 			// SLP ID is an IP Address
       
   519 			aAddress.iSlpAddressType = ESuplSlpAddressTypeIp;
       
   520 
       
   521 			// Pointer to the address data buffer
       
   522 			TBuf8<16>& ipAddress = aAddress.iIpAddress->iIpAddress;
       
   523 							
       
   524 			// IPv4 or IPv6 address?
       
   525 			if (slpAddress.u.iPAddress->t == T_IPAddress_ipv6Address)
       
   526 				{
       
   527 				aAddress.iIpAddress->iIpAddressType = ESuplIpAddressTypeV6;
       
   528 				TInt len = slpAddress.u.iPAddress->u.ipv6Address->numocts;
       
   529 				TUint8* data = slpAddress.u.iPAddress->u.ipv6Address->data;
       
   530 				ipAddress.Copy(data, len);
       
   531 				}
       
   532 			else
       
   533 				{
       
   534 				aAddress.iIpAddress->iIpAddressType = ESuplIpAddressTypeV4;
       
   535 				TInt len = slpAddress.u.iPAddress->u.ipv4Address->numocts;
       
   536 				TUint8* data = slpAddress.u.iPAddress->u.ipv4Address->data;
       
   537 				ipAddress.Copy(data, len);
       
   538 				}
       
   539 			break;
       
   540 			}
       
   541 		case T_SLPAddress_fQDN:
       
   542 			{
       
   543 			// FQDN is a NULL terminated string, length 1..255
       
   544 			aAddress.iSlpAddressType = ESuplSlpAddressTypeFqdn;
       
   545 						
       
   546 			// find the length of the FQDN (NULL terminated)
       
   547 			const TUint8* tmp = (const TUint8*)slpAddress.u.fQDN;
       
   548 			TPtrC8 source = TPtrC8(tmp, 256);
       
   549 			_LIT8(KNull,"\0");
       
   550 			TInt fqdnLength = source.Find(KNull);
       
   551 			
       
   552 			if (fqdnLength > 0 && fqdnLength <256)
       
   553 				{
       
   554 				// copy to the container
       
   555 				source.Set(tmp, fqdnLength);
       
   556 				TBuf8<256>& fqdn = aAddress.iFqdn->iFqdn;
       
   557 				fqdn.Copy(source);
       
   558 				fqdn.SetLength(fqdnLength);
       
   559 				}
       
   560 			else
       
   561 				{
       
   562 				// fqdn length is corrupt
       
   563 				__ASSERT_DEBUG(0, User::Invariant());
       
   564 				return KErrCorrupt;
       
   565 				}
       
   566 			break;
       
   567 			}
       
   568 		case T_SLPAddress_extElem1:
       
   569 		default:
       
   570 			{
       
   571 			// error
       
   572 			__ASSERT_DEBUG(EFalse, User::Invariant());
       
   573 			return KErrUnknown;
       
   574 			}
       
   575 		}
       
   576 		
       
   577 	SUPLLOG(ELogP1, "CSuplInit::SlpAddress() End\n");
       
   578 	return KErrNone;
       
   579 	}
       
   580 
       
   581 /** 
       
   582 QopPresent()
       
   583 
       
   584 @return ETrue if optional QoP parameter is present, EFalse otherwise
       
   585 */
       
   586 EXPORT_C TBool CSuplInit::QopPresent()
       
   587 	{
       
   588 	SUPLLOG(ELogP1, "CSuplInit::QopPresent() Begin\n");
       
   589 	__ASSERT_DEBUG(iData->message.u.msSUPLINIT != NULL, User::Invariant());
       
   590 	
       
   591 	if (iData->message.u.msSUPLINIT->m.qoPPresent != 0)
       
   592 		{
       
   593 		SUPLLOG(ELogP1, "CSuplInit::QopPresent(ETrue) End\n");
       
   594 		return ETrue;
       
   595 		}
       
   596 
       
   597 	SUPLLOG(ELogP1, "CSuplInit::QopPresent(EFalse) End\n");
       
   598 	return EFalse;
       
   599 	}
       
   600 
       
   601 	
       
   602 /**
       
   603 Qop()
       
   604 
       
   605 Populates aAddress according to SUPL INIT QoP parameter
       
   606 
       
   607 @param aQuality, populated according to QoP parameter
       
   608 @return error indication, KErrNone otherwise
       
   609 */
       
   610 EXPORT_C TInt CSuplInit::GetQop (TLbsNetPosRequestQuality& aQuality)
       
   611 	{
       
   612 	SUPLLOG(ELogP1, "CSuplInit::Qop() Begin\n");
       
   613 	__ASSERT_DEBUG(iData->message.u.msSUPLINIT != NULL, User::Invariant());
       
   614 	
       
   615 	if (iData->message.u.msSUPLINIT->m.qoPPresent == 0)
       
   616 		{
       
   617 		SUPLLOG(ELogP1, "CSuplInit::Qop() End (QoP element not present)\n");
       
   618 		return KErrNotFound;
       
   619 		}
       
   620 	
       
   621 	ASN1T_QoP& qop = iData->message.u.msSUPLINIT->qoP;
       
   622 	
       
   623 	// horizontal accuracy
       
   624 	// convert to meters according to 3GPP TS 23.032
       
   625 	TReal temp ;
       
   626 	Math::Pow(temp, 1.1, qop.horacc);
       
   627 	TReal accuracy = 10 * (temp - 1);
       
   628 	aQuality.SetMinHorizontalAccuracy(accuracy);
       
   629 	
       
   630 	// vertical accuracy
       
   631 	if (qop.m.veraccPresent)
       
   632 		{
       
   633 		// convert to meters according to 3GPP TS 23.032
       
   634 		Math::Pow(temp, 1.025, qop.veracc);
       
   635 		TReal verAccuracy = 45 * (temp - 1);
       
   636 		aQuality.SetMinVerticalAccuracy(verAccuracy);
       
   637 		}
       
   638 	else
       
   639 		{
       
   640 		// Set vertical accuracy to NaN
       
   641 		TRealX nan;
       
   642 		nan.SetNaN();
       
   643 		aQuality.SetMinVerticalAccuracy(nan);	
       
   644 		}
       
   645 	
       
   646 	// max location age (max fix age)
       
   647 	if (qop.m.maxLocAgePresent)
       
   648 		{
       
   649 		// convert from seconds to microseconds
       
   650 		TTimeIntervalMicroSeconds maxLocAge(qop.maxLocAge * 1000 * 1000);
       
   651 		aQuality.SetMaxFixAge(maxLocAge);	
       
   652 		}
       
   653 
       
   654 	// delay (max fix time)
       
   655 	if (qop.m.delayPresent)
       
   656 		{
       
   657 		Math::Pow(temp, 2, qop.delay);
       
   658 		TTimeIntervalMicroSeconds maxFixTime(temp * 1000 * 1000);
       
   659 		aQuality.SetMaxFixTime(maxFixTime);
       
   660 		}
       
   661 
       
   662 	SUPLLOG(ELogP1, "CSuplInit::Qop() End\n");
       
   663 	return KErrNone;
       
   664 	}
       
   665 
       
   666 /** 
       
   667 SlpMode()
       
   668 
       
   669 Returns the SLP mode specified in the received SUPL INIT message. 
       
   670 Note that this implementation of the SUPL ASN1 does not include full support
       
   671 of non-proxy operation.
       
   672 
       
   673 @return the mode of operation supported by the SLP, either proxy or non-proxy.
       
   674 */
       
   675 EXPORT_C CSuplInit::TSuplSlpMode CSuplInit::SlpMode()
       
   676 	{
       
   677 	SUPLLOG(ELogP1, "CSuplInit::SlpMode() Begin\n");
       
   678 	__ASSERT_DEBUG(iData->message.u.msSUPLINIT != NULL, User::Invariant());
       
   679 	
       
   680 	if (iData->message.u.msSUPLINIT->sLPMode == SLPMode::proxy)
       
   681 		{
       
   682 		SUPLLOG(ELogP1, "CSuplInit::SlpMode(EProxyMode) End\n");
       
   683 		return CSuplInit::ESuplSlpModeProxy;
       
   684 		}
       
   685 	
       
   686 	SUPLLOG(ELogP1, "CSuplInit::SlpMode(ENonProxyMode) End\n");
       
   687 	return CSuplInit::ESuplSlpModeNonProxy;
       
   688 	}
       
   689 
       
   690 /**
       
   691 SetReceivedMessageL()
       
   692 
       
   693 Stores a copy of the unencoded received message data. This is required in the
       
   694 calculation of the hash key for SUPL INIT authorisation.
       
   695 
       
   696 @param  aData - descriptor containing the received SUPL INIT message
       
   697 @leave  KErrNoMemory or other error codes
       
   698 */
       
   699 void CSuplInit::SetReceivedMessageL(const TDesC8& aData)
       
   700 	{
       
   701 	SUPLLOG(ELogP1, "CSuplInit::SetReceivedMessageL() Begin\n");
       
   702 	delete iMessage;
       
   703 	iMessage = NULL;
       
   704 	iMessage = HBufC8::NewL(aData.Length());
       
   705 	*iMessage = aData;
       
   706 	SUPLLOG(ELogP1, "CSuplInit::SetReceivedMessageL() End\n");
       
   707 	}
       
   708 
       
   709 
       
   710 /** 
       
   711 GetVerL()
       
   712 
       
   713 Returns the encoded hash of the received SUPL INIT message.
       
   714 VER=H(H-SLP XOR opad, H(H-SLP XOR ipad, SUPL INIT))
       
   715 
       
   716 @param  aHSlp - the provisioned H-SLP address
       
   717 @return descriptor pointer to the encoded hash of the received message
       
   718 */
       
   719 EXPORT_C TPtrC8 CSuplInit::GetVerL(const TDesC8 &aHSlp)
       
   720 	{
       
   721 	SUPLLOG(ELogP1, "CSuplInit::GetVerL() Begin\n");
       
   722 	CMessageDigest *sha1  = CSHA1::NewL();
       
   723 	CleanupStack::PushL(sha1);
       
   724 	CHMAC *hmac = CHMAC::NewL(aHSlp, sha1);
       
   725 	// If construction works, the CHMAC takes ownership of the sha1 object
       
   726 	CleanupStack::Pop(sha1);
       
   727 	CleanupStack::PushL(hmac);
       
   728 
       
   729 	TPtrC8 hmac_value = hmac->Final(iMessage->Des());
       
   730 
       
   731 	// store the hmac.
       
   732 	iVer.Copy(hmac_value.Left(8));
       
   733 	iVer.SetLength(8);	
       
   734 	
       
   735 	CleanupStack::PopAndDestroy(hmac);
       
   736 
       
   737 	// return a pointer to it.
       
   738 	TPtrC8 ver(iVer.Ptr(), 8);
       
   739 
       
   740 	SUPLLOG(ELogP1, "CSuplInit::GetVerL() End\n");
       
   741 	return ver;
       
   742 	}
       
   743 
       
   744