networkcontrol/pfqoslib/src/pfqoslib.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2006-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 #include "pfqoslib.h"
       
    17 #include "pfqosparser.h"
       
    18 #include "pfqosliblog.h"
       
    19 //
       
    20 // DLL entry point
       
    21 //
       
    22 GLDEF_C TInt E32Dll()
       
    23 	{
       
    24 	return(KErrNone);
       
    25 	}
       
    26 
       
    27 
       
    28 EXPORT_C T_pfqos_msg::T_pfqos_msg(TUint8 aMsgType, TUint32 aSeq)
       
    29 	{
       
    30 	pfqos_msg_version = KPfqosMsgV1;
       
    31 	pfqos_msg_type = aMsgType;
       
    32 	pfqos_msg_errno = 0;
       
    33 	pfqos_msg_options = 0;
       
    34 	pfqos_msg_len = ((sizeof(*this) + 7) / 8);
       
    35 	pfqos_msg_reserved = 0;
       
    36 	pfqos_msg_seq = aSeq;
       
    37 	pfqos_msg_pid = 0;
       
    38 	}
       
    39 
       
    40 
       
    41 EXPORT_C T_pfqos_selector::T_pfqos_selector(CSelectorBase* aSelector)
       
    42 	{
       
    43 	pfqos_selector_len = ((sizeof(*this) + 7) / 8);
       
    44 	pfqos_ext_type = EPfqosExtSelector;
       
    45 	protocol = aSelector->iProtocol;
       
    46 	uid1 = aSelector->iUid.UidType()[0].iUid;
       
    47 	uid2 = aSelector->iUid.UidType()[1].iUid;
       
    48 	uid3 = aSelector->iUid.UidType()[2].iUid;
       
    49 	iap_id = aSelector->iIapId;
       
    50 	policy_type = aSelector->iType;
       
    51 	priority = aSelector->iPriority;
       
    52 	reserved = 0;
       
    53 	TPtr8 ptr((TUint8*)name, 0, KMaxName);
       
    54 	if (ptr.MaxLength() >= aSelector->iName.Length())
       
    55 		{
       
    56 		ptr.Copy(aSelector->iName);
       
    57 		}
       
    58 	ptr.ZeroTerminate();
       
    59 	}
       
    60 
       
    61 EXPORT_C T_pfqos_address::T_pfqos_address(TUint aType, TUint16 aPortMax)
       
    62 	{
       
    63 	pfqos_address_len = ((sizeof(*this) + sizeof(TInetAddr) + 
       
    64 						  sizeof(TInetAddr) + 7) / 8);
       
    65 	pfqos_ext_type = (TUint8)aType;
       
    66 	reserved = 0;
       
    67 	pfqos_port_max = aPortMax;
       
    68 	}
       
    69 
       
    70 
       
    71 EXPORT_C T_pfqos_module::T_pfqos_module(TUint aProtocolId, TUint32 aFlags, 
       
    72 					const TDesC& aName, const TDesC& aPath, TInt aDataLen)
       
    73 	{
       
    74 	pfqos_modulespec_len = (TUint16)((sizeof(*this) + aDataLen + 7) / 8);
       
    75 	pfqos_ext_type = EPfqosExtModulespec;
       
    76 	protocol_id = aProtocolId;
       
    77 	flags = aFlags;
       
    78 	TPtr8 namePtr((TUint8*)name, 0, KMaxName);
       
    79 	if (namePtr.MaxLength() >= aName.Length())
       
    80 		{
       
    81 		namePtr.Copy(aName);
       
    82 		}
       
    83 	namePtr.ZeroTerminate();
       
    84 	TPtr8 pathPtr((TUint8*)path, 0, KMaxFileName);
       
    85 	if (pathPtr.MaxLength() >= aPath.Length())
       
    86 		{
       
    87 		pathPtr.Copy(aPath);
       
    88 		}
       
    89 	pathPtr.ZeroTerminate();
       
    90 	reserved = 0;
       
    91 	}
       
    92  
       
    93 //lint -e{1928}
       
    94 EXPORT_C T_pfqos_flowspec::T_pfqos_flowspec(const TQoSParameters& aParameters)
       
    95 	{
       
    96 	pfqos_flowspec_len = ((sizeof(*this) + 7) / 8);
       
    97 
       
    98 	pfqos_ext_type = EPfqosExtFlowspec;
       
    99 
       
   100 	uplink_bandwidth = aParameters.GetUplinkBandwidth();
       
   101 	uplink_maximum_burst_size = aParameters.GetUpLinkMaximumBurstSize();
       
   102 	uplink_maximum_packet_size = aParameters.GetUpLinkMaximumPacketSize();
       
   103 	uplink_average_packet_size = aParameters.GetUpLinkAveragePacketSize();
       
   104 	uplink_delay = aParameters.GetUpLinkDelay();
       
   105 	uplink_priority = static_cast< TUint16 >(aParameters.GetUpLinkPriority());
       
   106 	
       
   107 	downlink_bandwidth = aParameters.GetDownlinkBandwidth();
       
   108 	downlink_maximum_burst_size = aParameters.GetDownLinkMaximumBurstSize();
       
   109 	downlink_maximum_packet_size = aParameters.GetDownLinkMaximumPacketSize();
       
   110 	downlink_average_packet_size = aParameters.GetDownLinkAveragePacketSize();
       
   111 	downlink_delay = aParameters.GetDownLinkDelay();
       
   112 	downlink_priority = static_cast< TUint16 >(aParameters.GetDownLinkPriority());
       
   113 	
       
   114 	// name
       
   115 	name.FillZ();
       
   116 	if (name.MaxLength() >= aParameters.GetName().Length())
       
   117 		{
       
   118 		name.Copy(aParameters.GetName());
       
   119 		}
       
   120 	name.ZeroTerminate();
       
   121 
       
   122 	flags = aParameters.Flags();
       
   123 	reserved = 0;
       
   124 
       
   125 	LOG(Log::Printf(_L("1 pfqos_flowspec_len -- [%d]"),pfqos_flowspec_len));
       
   126 	}
       
   127 
       
   128 
       
   129 EXPORT_C T_pfqos_event::T_pfqos_event(TUint8 aType, TUint16 aEventType, 
       
   130 									  TUint16 aValue)
       
   131 	{
       
   132 	pfqos_event_len = ((sizeof(*this) + 7) / 8);
       
   133 	pfqos_ext_type = aType;
       
   134 	event_type = aEventType;
       
   135 	event_value = aValue;
       
   136 	}
       
   137 
       
   138 EXPORT_C T_pfqos_channel::T_pfqos_channel(TUint32 aChannelId)
       
   139 	{
       
   140 	pfqos_channel_len = ((sizeof(*this) + 7) / 8);
       
   141 	pfqos_ext_type = EPfqosExtChannel;
       
   142 	channel_id= aChannelId;
       
   143 	};
       
   144 
       
   145 EXPORT_C T_pfqos_configure::T_pfqos_configure(TUint16 aProtocolId)
       
   146 	{
       
   147 	pfqos_configure_len = ((sizeof(*this) + 7) / 8);
       
   148 	pfqos_ext_type = EPfqosExtConfigure;
       
   149 	protocol_id = aProtocolId;
       
   150 	reserved = 0;
       
   151 	}
       
   152 
       
   153 
       
   154 //
       
   155 // Internal representation of PfqosMessage
       
   156 //
       
   157 EXPORT_C TPfqosBase::TPfqosBase() : iMsg(0)
       
   158 	{
       
   159 	}
       
   160 
       
   161 EXPORT_C TUint TPfqosBase::Length() const
       
   162 	{
       
   163 	return iMsg ? sizeof(*iMsg) : 0;
       
   164 	}
       
   165 
       
   166 EXPORT_C TInt TPfqosBase::ByteStream(RMBufChain &aPacket, TInt aTotal) const
       
   167 	{
       
   168 	if (iMsg)
       
   169 		{
       
   170 		struct pfqos_msg base = *iMsg;
       
   171 		base.pfqos_msg_len = (TUint16)(aTotal / 8);
       
   172 		aPacket.CopyIn(TPtrC8((TUint8 *)&base, sizeof(base)), 0);
       
   173 		return Length();
       
   174 		}
       
   175 	else
       
   176 		{
       
   177 		return 0;
       
   178 		}
       
   179 	}
       
   180 
       
   181 
       
   182 EXPORT_C TPfqosSelector::TPfqosSelector() : iExt(0)
       
   183 	{
       
   184 	}
       
   185 
       
   186 EXPORT_C TUint TPfqosSelector::Length() const
       
   187 	{
       
   188 	return iExt ? sizeof(*iExt) : 0;
       
   189 	}
       
   190 
       
   191 EXPORT_C TInt TPfqosSelector::ByteStream(RMBufChain &aPacket, TInt aOffset) 
       
   192 	const
       
   193 	{
       
   194 	if (iExt)
       
   195 		{
       
   196 		aPacket.CopyIn(TPtrC8((TUint8 *)iExt, sizeof(*iExt)), aOffset);
       
   197 		aOffset += Length();
       
   198 		}
       
   199 	return aOffset;
       
   200 	}
       
   201 
       
   202 EXPORT_C TInt TPfqosSelector::GetUid(TCheckedUid& aUid)
       
   203 	{
       
   204 	if (!iExt)
       
   205 		{
       
   206 		return KErrNotReady;
       
   207 		}
       
   208 	TUidType uid_type(TUid::Uid(iExt->uid1), TUid::Uid(iExt->uid2), 
       
   209 					  TUid::Uid(iExt->uid3));
       
   210 	aUid.Set(uid_type);
       
   211 	return KErrNone;
       
   212 	};
       
   213 
       
   214 EXPORT_C TPfqosAddress::TPfqosAddress() : iExt(0), iAddr(0), iPrefix(0)
       
   215 	{
       
   216 	}
       
   217 
       
   218 EXPORT_C TUint TPfqosAddress::Length() const
       
   219 	{
       
   220 	return iExt ? ((sizeof(*iExt) + sizeof(TInetAddr) + 
       
   221 		sizeof(TInetAddr) + 7) / 8) * 8 : 0;
       
   222 	}
       
   223 
       
   224 EXPORT_C TInt TPfqosAddress::ByteStream(RMBufChain &aPacket, TInt aOffset) 
       
   225 	const
       
   226 	{
       
   227 	if (iExt && iAddr && iPrefix)
       
   228 		{
       
   229 		aPacket.CopyIn(TPtrC8((TUint8 *)iExt, sizeof(*iExt)), aOffset);
       
   230 		aPacket.CopyIn(TPtrC8((TUint8 *)iAddr, sizeof(*iAddr)), aOffset + 
       
   231 			sizeof(*iExt));
       
   232 		aPacket.CopyIn(TPtrC8((TUint8 *)iPrefix, sizeof(*iPrefix)), aOffset + 
       
   233 			sizeof(*iExt) + sizeof(*iAddr));
       
   234 		aOffset += Length();
       
   235 		}
       
   236 	return aOffset;
       
   237 	}
       
   238 
       
   239 
       
   240 
       
   241 EXPORT_C TPfqosModule::TPfqosModule() : iExt(0), iData(0,0)
       
   242 	{
       
   243 	}
       
   244 
       
   245 EXPORT_C TUint TPfqosModule::Length() const
       
   246 	{
       
   247 	return iExt ? (sizeof(*iExt)+iData.Length()) : iData.Length();
       
   248 	}
       
   249 
       
   250 EXPORT_C TInt TPfqosModule::ByteStream(RMBufChain &aPacket, TInt aOffset) 
       
   251 	const
       
   252 	{
       
   253 	if (iExt)
       
   254 		{
       
   255 		aPacket.CopyIn(TPtrC8((TUint8 *)iExt, sizeof(*iExt)), aOffset);
       
   256 		aOffset += sizeof(*iExt);
       
   257 		}
       
   258 	if (iData.Length() > 0)
       
   259 		{
       
   260 		aPacket.CopyIn(iData, aOffset);
       
   261 		aOffset += iData.Length();
       
   262 		}
       
   263 	return aOffset;
       
   264 	}
       
   265 
       
   266 
       
   267 
       
   268 EXPORT_C TPfqosFlowSpec::TPfqosFlowSpec() : iExt(0)
       
   269 	{
       
   270 	}
       
   271 
       
   272 EXPORT_C TUint TPfqosFlowSpec::Length() const
       
   273 	{
       
   274 	return iExt ? sizeof(*iExt) : 0;
       
   275 	}
       
   276 
       
   277 EXPORT_C TInt TPfqosFlowSpec::ByteStream(RMBufChain &aPacket, TInt aOffset) 
       
   278 	const
       
   279 	{
       
   280 	if (iExt)
       
   281 		{
       
   282 		aPacket.CopyIn(TPtrC8((TUint8 *)iExt, sizeof(*iExt)), aOffset);
       
   283 		aOffset += Length();
       
   284 		}
       
   285 	return aOffset;
       
   286 	}
       
   287 
       
   288 
       
   289 
       
   290 EXPORT_C TPfqosEvent::TPfqosEvent() : iExt(0)
       
   291 	{
       
   292 	}
       
   293 
       
   294 EXPORT_C TUint TPfqosEvent::Length() const
       
   295 	{
       
   296 	return iExt ? sizeof(*iExt) : 0;
       
   297 	}
       
   298 
       
   299 EXPORT_C TInt TPfqosEvent::ByteStream(RMBufChain &aPacket, TInt aOffset) const
       
   300 	{
       
   301 	if (iExt)
       
   302 		{
       
   303 		aPacket.CopyIn(TPtrC8((TUint8 *)iExt, sizeof(*iExt)), aOffset);
       
   304 		aOffset += Length();
       
   305 		}
       
   306 	return aOffset;
       
   307 	}
       
   308 
       
   309 
       
   310 EXPORT_C TPfqosChannel::TPfqosChannel() : iExt(0)
       
   311 	{
       
   312 	}
       
   313 
       
   314 EXPORT_C TUint TPfqosChannel::Length() const
       
   315 	{
       
   316 	return iExt ? sizeof(*iExt) : 0;
       
   317 	}
       
   318 
       
   319 EXPORT_C TInt TPfqosChannel::ByteStream(RMBufChain &aPacket, TInt aOffset) 
       
   320 	const
       
   321 	{
       
   322 	if (iExt)
       
   323 		{
       
   324 		aPacket.CopyIn(TPtrC8((TUint8 *)iExt, sizeof(*iExt)), aOffset);
       
   325 		aOffset += Length();
       
   326 		}
       
   327 	return aOffset;
       
   328 	}
       
   329 
       
   330 
       
   331 EXPORT_C TPfqosConfigure::TPfqosConfigure() : iExt(0)
       
   332 	{
       
   333 	}
       
   334 
       
   335 EXPORT_C TUint TPfqosConfigure::Length() const
       
   336 	{
       
   337 	return iExt ? sizeof(*iExt) : 0;
       
   338 	}
       
   339 
       
   340 EXPORT_C TInt TPfqosConfigure::ByteStream(RMBufChain &aPacket, TInt aOffset) 
       
   341 	const
       
   342 	{
       
   343 	if (iExt)
       
   344 		{
       
   345 		aPacket.CopyIn(TPtrC8((TUint8 *)iExt, sizeof(*iExt)), aOffset);
       
   346 		aOffset += Length();
       
   347 		}
       
   348 	return aOffset;
       
   349 	}
       
   350 
       
   351 EXPORT_C TPfqosConfigFile::TPfqosConfigFile() : iExt(0)
       
   352 	{
       
   353 	}
       
   354 
       
   355 EXPORT_C TUint TPfqosConfigFile::Length() const
       
   356 	{
       
   357 	return iExt ? sizeof(*iExt) : 0;
       
   358 	}
       
   359 
       
   360 EXPORT_C TInt TPfqosConfigFile::ByteStream(RMBufChain &aPacket, TInt aOffset)
       
   361 	const
       
   362 	{
       
   363 	if (iExt)
       
   364 		{
       
   365 		aPacket.CopyIn(TPtrC8((TUint8 *)iExt, sizeof(*iExt)), aOffset);
       
   366 		aOffset += Length();
       
   367 		}
       
   368 	return aOffset;
       
   369 	}
       
   370 
       
   371 
       
   372 EXPORT_C CPfqosPolicyData::CPfqosPolicyData(TInt aType) : iBufPtr(0,0)
       
   373 	{
       
   374 	iType = aType;
       
   375 	iBuf = NULL;
       
   376 	}
       
   377 
       
   378 
       
   379 EXPORT_C CPfqosPolicyData::~CPfqosPolicyData()
       
   380 	{
       
   381 	delete iBuf;
       
   382 	}
       
   383 
       
   384 
       
   385 
       
   386 EXPORT_C void CPfqosPolicyData::ConstructL()
       
   387 	{
       
   388 	
       
   389 	}
       
   390 
       
   391 
       
   392 EXPORT_C CPfqosPolicyData* CPfqosPolicyData::NewL(TInt aType)
       
   393 	{
       
   394 
       
   395 	CPfqosPolicyData* pfqosPolicyData = new (ELeave) CPfqosPolicyData(aType);
       
   396 	CleanupStack::PushL(pfqosPolicyData);
       
   397 	pfqosPolicyData->ConstructL();
       
   398 	CleanupStack::Pop();
       
   399 	return pfqosPolicyData;
       
   400 	
       
   401 	}
       
   402 
       
   403 
       
   404 EXPORT_C CPfqosPolicyData* CPfqosPolicyData::NewL(TInt aType, 
       
   405 	const TUint8 *aBuf,TInt aLength)
       
   406 	{
       
   407 	CPfqosPolicyData* pfqosPolicyData = new (ELeave) CPfqosPolicyData(aType);
       
   408 	CleanupStack::PushL(pfqosPolicyData);
       
   409 	pfqosPolicyData->ConstructL();
       
   410 	pfqosPolicyData->CopyL(aBuf, aLength);
       
   411 	CleanupStack::Pop();
       
   412 	return pfqosPolicyData;
       
   413 	}
       
   414 
       
   415 
       
   416 EXPORT_C TUint CPfqosPolicyData::Length() const
       
   417 	{
       
   418 	return iBufPtr.Length();
       
   419 	}
       
   420 
       
   421 EXPORT_C TInt CPfqosPolicyData::Size() const
       
   422 	{
       
   423 	return iBufPtr.MaxLength();
       
   424 	}
       
   425 
       
   426 EXPORT_C void CPfqosPolicyData::CopyL(const TUint8 *aBuf,TInt aLength)
       
   427 	{
       
   428 	if (iBuf)
       
   429 		{
       
   430 		delete iBuf;
       
   431 		iBuf=NULL;
       
   432 		}
       
   433 
       
   434 	iBuf = HBufC8::NewL(aLength);
       
   435 	TPtr8 tmp(iBuf->Des());
       
   436 	iBufPtr.Set(tmp);
       
   437 	iBufPtr.Copy(aBuf, aLength);
       
   438 	}
       
   439 
       
   440 EXPORT_C TDesC8& CPfqosPolicyData::Data()
       
   441 	{
       
   442 	return iBufPtr;
       
   443 	}
       
   444 
       
   445 EXPORT_C TInt CPfqosPolicyData::Type()
       
   446 	{
       
   447 	return iType;
       
   448 	}
       
   449 
       
   450 EXPORT_C TInt CPfqosPolicyData::ByteStream(RMBufChain &aPacket, TInt aOffset)
       
   451 	const
       
   452 	{
       
   453 	if (iBufPtr.Length())
       
   454 		{
       
   455 		aPacket.CopyIn(TPtrC8((TUint8 *)iBufPtr.Ptr(), iBufPtr.Length()), 
       
   456 			aOffset);
       
   457 		aOffset += Length();
       
   458 		}
       
   459 	return aOffset;
       
   460 	}
       
   461 
       
   462 
       
   463 EXPORT_C TPfqosMessage::TPfqosMessage() 
       
   464 	: iError(0),
       
   465 	  iNumModules(0),
       
   466 	  iModuleList(_FOFF(TPfqosModule, iNext)),
       
   467 	  iNumExtensions(0), 
       
   468 	  iExtensions(_FOFF(CPfqosPolicyData, iNext))
       
   469 	{
       
   470 	}
       
   471 
       
   472 EXPORT_C void TPfqosMessage::Add(TPfqosModule& aModule)
       
   473 	{
       
   474 	iNumModules++;
       
   475 	iModuleList.AddLast(aModule);
       
   476 	}
       
   477 
       
   478 EXPORT_C void TPfqosMessage::AddExtension(CPfqosPolicyData& aExtension)
       
   479 	{
       
   480 	iNumExtensions++;
       
   481 	iExtensions.AddLast(aExtension);
       
   482 	}
       
   483 
       
   484 //
       
   485 // Internal representation of PF_QOS message.
       
   486 //
       
   487 EXPORT_C TPfqosMessage::TPfqosMessage(const TDesC8& aMsg)
       
   488 	: iError(KErrArgument),
       
   489 	  iNumModules(0),
       
   490 	  iModuleList(_FOFF(TPfqosModule, iNext)),
       
   491 	  iNumExtensions(0),
       
   492 	  iExtensions(_FOFF(CPfqosPolicyData, iNext))
       
   493 	{
       
   494 	const TUint8 *p = aMsg.Ptr();
       
   495 	TInt length = aMsg.Length();
       
   496 
       
   497 	if (length < (TInt)sizeof(pfqos_msg))
       
   498 		{
       
   499 		LOG(Log::Printf(_L("length < (TInt)sizeof(pfqos_msg) -- [%d,%d]"),
       
   500 			length,(TInt)sizeof(pfqos_msg)));
       
   501 
       
   502 		return;		// EMSGSIZE (impossible message size)
       
   503 		}
       
   504 	//
       
   505 	// Base Message Header
       
   506 	//lint -e{826}	Typecast below is ok.
       
   507 	iBase.iMsg = (struct pfqos_msg *)p;
       
   508 	if (iBase.iMsg->pfqos_msg_version != KPfqosMsgV1)
       
   509 		{
       
   510 		LOG(Log::Printf(_L("iBase.iMsg->pfqos_msg_version != KPfqosMsgV1 -- [%d,%d]"),
       
   511 			iBase.iMsg->pfqos_msg_version,KPfqosMsgV1));
       
   512 
       
   513 		return;		// EINVAL
       
   514 		}
       
   515 	if (iBase.iMsg->pfqos_msg_len * 8 != length)
       
   516 		{
       
   517 		LOG(Log::Printf(_L("iBase.iMsg->pfqos_msg_len * 8 != length -- [%d,%d]"),
       
   518 			iBase.iMsg->pfqos_msg_len * 8,length));
       
   519 		return;		// EMSGSIZE (incorrect message length)
       
   520 		}
       
   521 	if (iBase.iMsg->pfqos_msg_reserved)
       
   522 		{
       
   523 		LOG(Log::Printf(_L("iBase.iMsg->pfqos_msg_reserved -- [%d]"),
       
   524 			iBase.iMsg->pfqos_msg_reserved));
       
   525 		return;		// EINVAL (unused parts must be zeroed)
       
   526 		}
       
   527 	p += sizeof(struct pfqos_msg);
       
   528 	length -= sizeof(struct pfqos_msg);
       
   529 
       
   530 	LOG(Log::Printf(_L("**** length -- [%d]"),length));
       
   531 	LOG(Log::HexDump(_S("**** p"), _S(":  "), p, 8 ));
       
   532 
       
   533 	//
       
   534 	// Extension headers
       
   535 	// Some general rules:
       
   536 	// - only one instance of an extension type is valid
       
   537 	//
       
   538 	while (length > 0)
       
   539 		{
       
   540 		//lint -e{826}	Typecast below is ok.
       
   541 		struct pfqos_ext *ext = (struct pfqos_ext *)p;
       
   542 		int ext_len = ext->pfqos_ext_len;
       
   543 
       
   544 		if (ext_len < 1)
       
   545 			{
       
   546 			LOG(Log::Printf(_L("ext_len < 1 -- [%d]"),ext_len));
       
   547 
       
   548 			return;		// EINVAL (bad message format)
       
   549 			}
       
   550 		ext_len *= 8;
       
   551 
       
   552 		if (ext_len > length)
       
   553 			{
       
   554 			LOG(Log::Printf(_L("ext_len > length -- [%d, %d]"),ext_len, length));
       
   555 			LOG(Log::Printf(_L("calculated sizeof(pfqos_msg): %d"), 
       
   556 				sizeof(struct pfqos_msg)));
       
   557 			LOG(Log::HexDump(_S("pfqos_msg "), _S("pfqos_msg "), aMsg.Ptr(), 
       
   558 				sizeof(struct pfqos_msg)));
       
   559 			LOG(Log::HexDump(_S("p"), _S(":  "), p, 8 ));
       
   560 
       
   561 			return;		// EINVAL
       
   562 			}
       
   563 		switch (ext->pfqos_ext_type)
       
   564 			{
       
   565 		case EPfqosExtReserved:
       
   566 			{
       
   567 			LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtReserved")));
       
   568 			return;		// EINVAL (bad mesage format)
       
   569 			}
       
   570 
       
   571 		case EPfqosExtSrcAddress:
       
   572 			if (iSrcAddr.iExt)
       
   573 				{
       
   574 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtSrcAddress -1")));
       
   575 			
       
   576 				return;
       
   577 				}
       
   578 			if (ext_len != sizeof(struct pfqos_address) + sizeof(TInetAddr) + 
       
   579 				sizeof(TInetAddr))
       
   580 				{
       
   581 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtSrcAddress -2")));
       
   582 				return;
       
   583 				}
       
   584 			//lint -e{826}	Typecast below is ok.
       
   585 			iSrcAddr.iExt = (struct pfqos_address *)p;
       
   586 			//lint -e{826}	Typecast below is ok.
       
   587 			iSrcAddr.iAddr = (TInetAddr *)(p + sizeof(struct pfqos_address));
       
   588 			//lint -e{826}	Typecast below is ok.
       
   589 			iSrcAddr.iPrefix = (TInetAddr *)(p + sizeof(struct pfqos_address) 
       
   590 				+ sizeof(TInetAddr));
       
   591 			break;
       
   592 
       
   593 		case EPfqosExtDstAddress:
       
   594 			if (iDstAddr.iExt)
       
   595 				{
       
   596 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtDstAddress -1")));
       
   597 				return;
       
   598 				}
       
   599 			if (ext_len != sizeof(struct pfqos_address) + sizeof(TInetAddr) + 
       
   600 				sizeof(TInetAddr))
       
   601 				{
       
   602 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtDstAddress -2")));
       
   603 				return;
       
   604 				}
       
   605 			//lint -e{826}	Typecast below is ok.
       
   606 			iDstAddr.iExt = (struct pfqos_address *)p;
       
   607 			//lint -e{826}	Typecast below is ok.
       
   608 			iDstAddr.iAddr = (TInetAddr *)(p + sizeof(struct pfqos_address));
       
   609 			//lint -e{826}	Typecast below is ok.
       
   610 			iDstAddr.iPrefix = (TInetAddr *)(p + sizeof(struct pfqos_address) 
       
   611 				+ sizeof(TInetAddr));
       
   612 			break;
       
   613 
       
   614 		case EPfqosExtModulespec:
       
   615 			{
       
   616 			TPfqosModule *module = new TPfqosModule();
       
   617 			//lint -e{774}	new can return NULL!
       
   618 			if (module == NULL)
       
   619 				{
       
   620 				iError = KErrNoMemory;
       
   621 				LOG(Log::Printf(_L("TPfqosMessage::TPfqosMessage() iError -- [%d] -2"), iError));
       
   622 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtModulespec")));
       
   623 				return;
       
   624 				}
       
   625 			//lint -e{826}	Typecast below is ok.
       
   626 			module->iExt = (struct pfqos_modulespec *)p;
       
   627 			if (ext_len - sizeof(struct pfqos_modulespec) > 0)
       
   628 				{
       
   629 				module->iData.Set((TUint8 *)(p+sizeof(struct 
       
   630 					 pfqos_modulespec)), 
       
   631 					(ext_len - sizeof(struct pfqos_modulespec)));
       
   632 				}
       
   633 			//lint --e{429} Lint does not understand the Add semantics below!
       
   634 			Add(*module);
       
   635 			}
       
   636 			break;
       
   637 
       
   638 		case EPfqosExtSelector:
       
   639 			if (iSelector.iExt)
       
   640 				{
       
   641 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtSelector -1")));
       
   642 				return;
       
   643 				}
       
   644 			if (ext_len != sizeof(pfqos_selector))
       
   645 				{
       
   646 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtSelector -2")));
       
   647 				return;
       
   648 				}
       
   649 			//lint -e{826}	Typecast below is ok.
       
   650 			iSelector.iExt = (struct pfqos_selector *)p;
       
   651 			break;
       
   652 
       
   653 		case EPfqosExtFlowspec:
       
   654 			if (iFlowSpec.iExt)
       
   655 				{
       
   656 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtFlowspec -1")));
       
   657 				return;
       
   658 				}
       
   659 			if (ext_len != sizeof(pfqos_flowspec))
       
   660 				{
       
   661 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtFlowspec -2")));
       
   662 				return;
       
   663 				}
       
   664 			//lint -e{826}	Typecast below is ok.
       
   665 			iFlowSpec.iExt = (struct pfqos_flowspec *)p;
       
   666 			break;
       
   667 
       
   668 		case EPfqosExtEvent:
       
   669 			if (iEvent.iExt)
       
   670 				{
       
   671 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtEvent -1")));
       
   672 				return;
       
   673 				}
       
   674 			if (ext_len != sizeof(pfqos_event))
       
   675 				{
       
   676 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtEvent -2")));
       
   677 				return;
       
   678 				}
       
   679 			//lint -e{826}	Typecast below is ok.
       
   680 			iEvent.iExt = (struct pfqos_event *)p;
       
   681 			break;
       
   682 
       
   683 		case EPfqosExtChannel:
       
   684 			if (iChannel.iExt)
       
   685 				{
       
   686 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtChannel -1")));
       
   687 				return;
       
   688 				}
       
   689 			if (ext_len != sizeof(pfqos_channel))
       
   690 				{
       
   691 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtChannel -2")));
       
   692 				return;
       
   693 				}
       
   694 			//lint -e{826}	Typecast below is ok.
       
   695 			iChannel.iExt = (struct pfqos_channel *)p;
       
   696 			break;
       
   697 
       
   698 		case EPfqosExtExtension:
       
   699 			{
       
   700 			//lint -e{826}	Typecast below is ok.
       
   701 			pfqos_extension *extensionType = (pfqos_extension *) 
       
   702 				(p+sizeof(pfqos_configure));
       
   703 			TPtr8 ptr((TUint8*)ext, ext_len, ext_len);
       
   704 			TRAPD(err, AddExtensionL(ptr, 
       
   705 				extensionType->pfqos_extension_type));
       
   706 			if (err != KErrNone)
       
   707 				{
       
   708 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtExtension -2")));
       
   709 				return;
       
   710 				}
       
   711 			}
       
   712 			break;
       
   713 
       
   714 		case EPfqosExtConfigFile:
       
   715 			if (iConfigFile.iExt)
       
   716 				{
       
   717 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtConfigFile -1")));
       
   718 				return;
       
   719 				}
       
   720 			if (ext_len != sizeof(pfqos_config_file))
       
   721 				{
       
   722 				LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtConfigFile -2")));
       
   723 				return;
       
   724 				}
       
   725 			//lint -e{826}	Typecast below is ok.
       
   726 			iConfigFile.iExt = (struct pfqos_config_file *)p;
       
   727 			break;
       
   728 
       
   729 		default:
       
   730 			// Unknown extensions must be ignored, not an error!
       
   731 			break;
       
   732 			}
       
   733 		p += ext_len;
       
   734 		length -= ext_len;
       
   735 		}
       
   736 	if (length != 0)
       
   737 		{
       
   738 		LOG(Log::Printf(_L("ext->pfqos_ext_type : EPfqosExtConfigFile -2")));
       
   739 		return;
       
   740 		}
       
   741 
       
   742 #ifdef _LOG
       
   743 	// Message unpacked successfully
       
   744 
       
   745 	Log::Printf(_L("Following message unpacked successfully -- [%d]"),
       
   746 		iBase.iMsg->pfqos_msg_type);
       
   747 		
       
   748 	switch(iBase.iMsg->pfqos_msg_type)
       
   749 		{
       
   750 	case 0: 
       
   751 		Log::Printf(_L("EPfqosReserved"));
       
   752 		break;
       
   753 	case 1: 
       
   754 		Log::Printf(_L("EPfqosUpdate"));
       
   755 		break;			
       
   756 	case 2: 
       
   757 		Log::Printf(_L("EPfqosAdd"));
       
   758 		break;
       
   759 	case 3: 
       
   760 		Log::Printf(_L("EPfqosDelete"));
       
   761 		break;			
       
   762 	case 4: 
       
   763 		Log::Printf(_L("EPfqosGet"));
       
   764 		break;
       
   765 	case 5: 
       
   766 		Log::Printf(_L("EPfqosFlush"));
       
   767 		break;			
       
   768 	case 6: 
       
   769 		Log::Printf(_L("EPfqosDump"));
       
   770 		break;
       
   771 	case 7: 
       
   772 		Log::Printf(_L("EPfqosEvent"));
       
   773 		break;			
       
   774 	case 8: 
       
   775 		Log::Printf(_L("EPfqosConfigure"));
       
   776 		break;
       
   777 	case 9: 
       
   778 		Log::Printf(_L("EPfqosReject"));
       
   779 		break;			
       
   780 	case 10: 
       
   781 		Log::Printf(_L("EPfqosJoin"));
       
   782 		break;
       
   783 	case 11: 
       
   784 		Log::Printf(_L("EPfqosLeave"));
       
   785 		break;			
       
   786 	case 12: 
       
   787 		Log::Printf(_L("EPfqosCreateChannel"));
       
   788 		break;
       
   789 	case 13: 
       
   790 		Log::Printf(_L("EPfqosOpenExistingChannel"));
       
   791 		break;			
       
   792 	case 14: 
       
   793 		Log::Printf(_L("EPfqosDeleteChannel"));
       
   794 		break;
       
   795 	case 15: 
       
   796 		Log::Printf(_L("EPfqosConfigChannel"));
       
   797 		break;			
       
   798 	case 16: 
       
   799 		Log::Printf(_L("EPfqosLoadFile"));
       
   800 		break;
       
   801 	case 17: 
       
   802 		Log::Printf(_L("EPfqosUnloadFile"));
       
   803 		break;
       
   804 	default:
       
   805 		Log::Printf(_L("pfqos_msg_type = %d"), (TInt)iBase.iMsg->pfqos_msg_type);
       
   806 		break;			
       
   807 		}
       
   808 #endif		
       
   809 
       
   810 	iError = KErrNone;
       
   811 	}
       
   812 
       
   813 
       
   814 EXPORT_C TUint16 TPfqosMessage::Length64()
       
   815 	{
       
   816 	return (TUint16)((
       
   817 			 iBase.Length() +
       
   818 			 iEvent.Length() +
       
   819 			 iChannel.Length() +
       
   820 			 iSelector.Length() +
       
   821 			 iSrcAddr.Length() +
       
   822 			 iDstAddr.Length() +
       
   823 			 iFlowSpec.Length() +
       
   824 			 ModuleLength() + 
       
   825 			 iConfigFile.Length() +
       
   826 			 ExtensionLength())/8);
       
   827 	}
       
   828 
       
   829 
       
   830 EXPORT_C TUint TPfqosMessage::ExtensionLength()
       
   831 	{
       
   832 	TSglQueIter<CPfqosPolicyData> iter(iExtensions);
       
   833 	CPfqosPolicyData *item;
       
   834 	TUint length=0;
       
   835 
       
   836 	while ((item = iter++) != NULL)
       
   837 		{
       
   838 		length += item->Length();
       
   839 		}
       
   840 	return length;
       
   841 	}
       
   842 
       
   843 
       
   844 EXPORT_C TUint TPfqosMessage::ModuleLength()
       
   845 	{
       
   846 	TSglQueIter<TPfqosModule> iter(iModuleList);
       
   847 	TPfqosModule* item;
       
   848 	TUint length=0;
       
   849 
       
   850 	while ((item = iter++) != NULL)
       
   851 		{
       
   852 		length += item->Length();
       
   853 		}
       
   854 	return length;
       
   855 	}
       
   856 
       
   857 
       
   858 EXPORT_C void TPfqosMessage::ByteStreamL(RMBufChain &aPacket)
       
   859 	{
       
   860 	TInt totlen = Length64() * 8;
       
   861 
       
   862 	// (Any possible previous content is lost)
       
   863 	aPacket.AppendL(totlen);
       
   864 	TInt offset = iBase.ByteStream(aPacket, totlen);
       
   865 
       
   866 	// Always make sure that all possible extension fields in are included!
       
   867 	offset = iSelector.ByteStream(aPacket, offset);
       
   868 	offset = iSrcAddr.ByteStream(aPacket, offset);
       
   869 	offset = iDstAddr.ByteStream(aPacket, offset);
       
   870 	offset = iFlowSpec.ByteStream(aPacket, offset);
       
   871 	offset = iEvent.ByteStream(aPacket, offset);
       
   872 	offset = iChannel.ByteStream(aPacket, offset);
       
   873 	offset = iConfigFile.ByteStream(aPacket, offset);
       
   874 
       
   875 	TSglQueIter<TPfqosModule> iterM(iModuleList);
       
   876 	TPfqosModule *itemM;
       
   877 
       
   878 	while ((itemM = iterM++) != NULL)
       
   879 		{
       
   880 		offset = itemM->ByteStream(aPacket, offset);
       
   881 		}
       
   882 
       
   883 	TSglQueIter<CPfqosPolicyData> iter(iExtensions);
       
   884 	CPfqosPolicyData *item;
       
   885 
       
   886 	while ((item = iter++) != NULL)
       
   887 		{
       
   888 		offset = item->ByteStream(aPacket, offset);
       
   889 		}
       
   890 	}
       
   891 
       
   892 
       
   893 EXPORT_C TPfqosMessage::~TPfqosMessage()
       
   894 	{
       
   895 	TSglQueIter<TPfqosModule> iter(iModuleList);
       
   896 	TPfqosModule *item;
       
   897 
       
   898 	//
       
   899 	// Delete modulelist
       
   900 	//
       
   901 	while ((item = iter++) != NULL)
       
   902 		{
       
   903 		iModuleList.Remove(*item);
       
   904 		delete item;
       
   905 		}
       
   906 
       
   907 	//
       
   908 	// Delete extension list
       
   909 	//
       
   910 	TSglQueIter<CPfqosPolicyData> i(iExtensions);
       
   911 	CPfqosPolicyData *ext;
       
   912 
       
   913 	while ((ext = i++) != NULL)
       
   914 		{
       
   915 		iExtensions.Remove(*ext);
       
   916 		delete ext;
       
   917 		}
       
   918 	}
       
   919 
       
   920 EXPORT_C void TPfqosMessage::AddModuleL(T_pfqos_module& aModule, 
       
   921 	const TDesC8& aConfigData)
       
   922 	{
       
   923 	TPfqosModule* item = new (ELeave) TPfqosModule();
       
   924 	item->iExt = &aModule;
       
   925 	item->iData.Set(aConfigData);
       
   926 	//lint --e{429} Lint does not understand the Add semantics below!
       
   927 	Add(*item);
       
   928 	}
       
   929 
       
   930 EXPORT_C void TPfqosMessage::AddExtensionL(const TDesC8& aExtension, 
       
   931 	TInt aType)
       
   932 	{
       
   933 	CPfqosPolicyData* data = CPfqosPolicyData::NewL(aType,aExtension.Ptr(), 
       
   934 		aExtension.Length());
       
   935 	AddExtension(*data);
       
   936 	}
       
   937 
       
   938 
       
   939 EXPORT_C TInt TPfqosMessage::SetQoSParameters(TQoSParameters& aParameters) 
       
   940 	const
       
   941 	{
       
   942 	if (!iFlowSpec.iExt)
       
   943 		{
       
   944 		return KErrNotFound;
       
   945 		}
       
   946 
       
   947 	// uplink
       
   948 	aParameters.SetUpLinkDelay(iFlowSpec.iExt->uplink_delay);
       
   949 	aParameters.SetUpLinkMaximumPacketSize(
       
   950 		iFlowSpec.iExt->uplink_maximum_packet_size);
       
   951 	aParameters.SetUpLinkAveragePacketSize(
       
   952 		iFlowSpec.iExt->uplink_average_packet_size);
       
   953 	aParameters.SetUpLinkPriority(iFlowSpec.iExt->uplink_priority);
       
   954 	aParameters.SetUpLinkMaximumBurstSize(
       
   955 		iFlowSpec.iExt->uplink_maximum_burst_size);
       
   956 	aParameters.SetUplinkBandwidth(iFlowSpec.iExt->uplink_bandwidth);
       
   957 
       
   958 	// downlink
       
   959 	aParameters.SetDownLinkDelay(iFlowSpec.iExt->downlink_delay);
       
   960 	aParameters.SetDownLinkMaximumPacketSize(
       
   961 		iFlowSpec.iExt->downlink_maximum_packet_size);
       
   962 	aParameters.SetDownLinkAveragePacketSize(
       
   963 		iFlowSpec.iExt->downlink_average_packet_size);
       
   964 	aParameters.SetDownLinkPriority(iFlowSpec.iExt->downlink_priority);
       
   965 	aParameters.SetDownLinkMaximumBurstSize(
       
   966 		iFlowSpec.iExt->downlink_maximum_burst_size);
       
   967 	aParameters.SetDownlinkBandwidth(iFlowSpec.iExt->downlink_bandwidth);
       
   968 
       
   969 	// flags
       
   970 	aParameters.SetFlags(iFlowSpec.iExt->flags);
       
   971 
       
   972 	// names
       
   973 	aParameters.SetName(iFlowSpec.iExt->name);
       
   974 
       
   975 	return KErrNone;
       
   976 	}
       
   977 
       
   978 
       
   979 // Remove all policy data (flowspec, modules, extensions, event, configure)
       
   980 EXPORT_C void TPfqosMessage::RemovePolicyData()
       
   981 	{
       
   982 	TSglQueIter<TPfqosModule> iter(iModuleList);
       
   983 	TPfqosModule *item;
       
   984 
       
   985 	//
       
   986 	// Delete modulelist
       
   987 	//
       
   988 	while ((item = iter++) != NULL)
       
   989 		{
       
   990 		iModuleList.Remove(*item);
       
   991 		delete item;
       
   992 		}
       
   993 	iNumModules = 0;
       
   994 
       
   995 	//
       
   996 	// Delete extension list
       
   997 	//
       
   998 	TSglQueIter<CPfqosPolicyData> i(iExtensions);
       
   999 	CPfqosPolicyData *ext;
       
  1000 
       
  1001 	while ((ext = i++) != NULL)
       
  1002 		{
       
  1003 		iExtensions.Remove(*ext);
       
  1004 		delete ext;
       
  1005 		}
       
  1006 	iNumExtensions = 0;
       
  1007 
       
  1008 	iFlowSpec.iExt = NULL;
       
  1009 	iEvent.iExt = NULL;
       
  1010 	iChannel.iExt = NULL;
       
  1011 	iConfigure.iExt = NULL;
       
  1012 	}
       
  1013