epoc32/include/ext_hdr.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 // Copyright (c) 2004-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 // ext_hdr.h - IPv6 extension headers
    15 // Defines the basic classes for accessing the extension
    16 // header structures within IPv6 packets.
    17 // All return types codified as TInt (Native form and signed)
    18 //
    19 
    20 
    21 
    22 /**
    23  @file ext_hdr.h
    24  @ingroup ip_packet_formats
    25  @publishedAll
    26  @released
    27 */
    28 
    29 #ifndef __EXT_HDR_H__
    30 #define __EXT_HDR_H__
    31 
    32 #include <e32def.h>
    33 #include "in_hdr.h"
    34 
    35 /**
    36 * @addtogroup  ip_packet_formats
    37 * @{
    38 */
    39 
    40 /**
    41 * @name Additional protocol numbers
    42 *
    43 * @{
    44 */
    45 /** Hop-by-Hop Extension Header. See TInet6HeaderHopByHop. */
    46 const TUint KProtocolInet6HopOptions = 0;
    47 /** Tunneled IPv4. The next header is TInet6HeaderIP4. */
    48 const TUint KProtocolInetIpip = 4;
    49 /** Routing Header. See TInet6HeaderRouting. */
    50 const TUint KProtocolInet6RoutingHeader = 43;
    51 /** IPv6 Fragment Header. See TInet6HeaderFragment. */
    52 const TUint KProtocolInet6Fragment = 44;
    53 /** IPsec ESP header. See TInet6HeaderESP. */
    54 const TUint KProtocolInetEsp	= 50;
    55 /** IPsec AH header. See TInet6HeaderAH. */
    56 const TUint KProtocolInetAh = 51;
    57 /** No Next Header. */
    58 const TUint KProtocolInet6NoNextHeader = 59;
    59 /** Destination Options Extension Header. See TInet6Options. */
    60 const TUint KProtocolInet6DestinationOptions = 60;
    61 /* @} */
    62 
    63 //
    64 // TInet6HeaderExtension
    65 // *********************
    66 class TInet6HeaderExtension
    67 	/**
    68 	* Basic part of normal IPv6 extension headers.
    69 	*
    70 	* This is simple class to be used in scanning the extension headers
    71 	* which are known to follow the following format:
    72 	*
    73 	* - 1st octet = Next Header field
    74 	*
    75 	* - 2nd octet = Length of the extension header (= (x+1)*8 octets)
    76 	*
    77 	* @note
    78 	*	Extension headers do not need to follow this format. Unknown
    79 	*	headers cannot be skipped over by just assuming this format!
    80 	*
    81 	* @publishedAll
    82 	* @released
    83 	*/
    84 	{
    85 public:
    86 	inline static TInt MinHeaderLength() {return 8; }
    87 	inline static TInt MaxHeaderLength() {return 8; }	
    88 
    89 	inline TUint8* EndPtr() { return i + HeaderLength(); }
    90 	inline TInt NextHeader() const { return i[0]; }
    91 	inline TInt HdrExtLen() const { return i[1]; }	// Return raw value
    92 	inline TInt HeaderLength() const { return (i[1]+1) << 3; } // Return true byte length
    93 private:
    94 	union
    95 		{
    96 		TUint8 i[8];
    97 		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
    98 		};
    99 	};
   100 
   101 
   102 class TInet6HeaderHBH
   103 	/**
   104 	* IPv6 Hop-by-hop options header.
   105 @verbatim
   106 	From RFC 2460
   107 
   108     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   109     |  Next Header  |  Hdr Ext Len  |                               |
   110     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
   111     |                                                               |
   112     .                                                               .
   113     .                            Options                            .
   114     .                                                               .
   115     |                                                               |
   116     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   117 
   118    Next Header          8-bit selector.  Identifies the type of header
   119                         immediately following the Hop-by-Hop Options
   120                         header.  Uses the same values as the IPv4
   121                         Protocol field [RFC-1700 et seq.].
   122 
   123    Hdr Ext Len          8-bit unsigned integer.  Length of the Hop-by-
   124                         Hop Options header in 8-octet units, not
   125                         including the first 8 octets.
   126 
   127    Options              Variable-length field, of length such that the
   128                         complete Hop-by-Hop Options header is an integer
   129                         multiple of 8 octets long.  Contains one or more
   130                         TLV-encoded options, as described in section
   131                         4.2.
   132 
   133   And Options is:
   134 
   135 	  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
   136       |  Option Type  |  Opt Data Len |  Option Data
   137       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
   138 
   139       Option Type          8-bit identifier of the type of option.
   140 
   141       Opt Data Len         8-bit unsigned integer.  Length of the Option
   142                            Data field of this option, in octets.
   143 
   144       Option Data          Variable-length field.  Option-Type-specific
   145                            data.
   146 @endverbatim
   147 	* @publishedAll
   148 	* @released
   149 	*/
   150 	{
   151 public:
   152 	inline TInt HeaderLength() const
   153 		{
   154 		return (i[1]+1) << 3;	// Return length in octets.
   155 		}
   156 
   157 	inline TUint8* EndPtr() { return i + HeaderLength(); }
   158 
   159 	inline static TInt MinHeaderLength() {return 8; }	
   160 	inline static TInt MaxHeaderLength() {return 8; }
   161 	
   162 	//
   163 	// Access, Get Hop By Hop header values from the packet
   164 	//
   165 	inline TInt NextHeader() const
   166 		{
   167 		return i[0];
   168 		}
   169 
   170 	//From Options
   171 	inline TInt OptionType() const
   172 		/** @return The type of the first option */
   173 		{
   174 		return i[2];
   175 		}
   176 	inline TInt OptionDataLen() const
   177 		/** @return The data length of the first option */
   178 		{
   179 		return i[3];
   180 		}
   181 
   182 	//
   183 	// Access, SET Hop By Hop header values
   184 	//
   185 	inline void SetHdrExtLen(TInt aLength)
   186 		{
   187 		i[1]=(TUint8)aLength;
   188 		}
   189 	
   190 	inline void SetNextHeader(TInt aNext)
   191 		{
   192 		i[0]=(TUint8)aNext;
   193 		}
   194 
   195 	//From Options
   196 	inline void SetOptionType(TInt aType)
   197 		/** Sets type of the first option.*/
   198 		{
   199 		i[2]=(TUint8)aType;
   200 		}
   201 
   202 	inline void SetOptionDataLen(TInt aLength)
   203 		/** Sets data length of the first option.*/
   204 		{
   205 		i[3]=(TUint8)aLength;
   206 		}
   207 
   208 private:
   209 	union
   210 		{
   211 		TUint8 i[8];
   212 		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   213 		};
   214 	};
   215 
   216 
   217 class TInet6HeaderHopByHop
   218 	/**
   219 	* IPv6 Hop-by-hop options header.
   220 	* @publishedAll
   221 	* @deprecated
   222 	*	Because of the non-standard method naming and
   223 	*	semantics. Use TInet6HeaderHBH instead.
   224 	*/
   225 	{
   226 public:
   227 	inline TInt HeaderLength() const
   228 		{
   229 		return i[1];
   230 		}
   231 
   232 	inline TUint8* EndPtr() { return i + HeaderLength() * 8 + MinHeaderLength(); }
   233 
   234 	inline static TInt MinHeaderLength() {return 8; }	
   235 	inline static TInt MaxHeaderLength() {return 8; }
   236 	
   237 	//
   238 	// Access, Get Hop By Hop header values from the packet
   239 	//
   240 	inline TInt NextHeader() const
   241 		/** @return The length in 8-byte units! (non-standard, should be bytes!) */
   242 		{
   243 		return i[0];
   244 		}
   245 
   246 	//From Options
   247 	inline TInt OptionType() const
   248 		/** @return The type of the first option */
   249 		{
   250 		return i[2];
   251 		}
   252 	inline TInt OptionDataLen() const
   253 		/** @return The data length of the first option */
   254 		{
   255 		return i[3];
   256 		}
   257 
   258 	//
   259 	// Access, SET Hop By Hop header values
   260 	//
   261 	inline void SetHeaderLength(TInt aLength)
   262 		{
   263 		i[1]=(TUint8)aLength;
   264 		}
   265 	
   266 	inline void SetNextHeader(TInt aNext)
   267 		{
   268 		i[0]=(TUint8)aNext;
   269 		}
   270 
   271 	//From Options
   272 	inline void SetOptionType(TInt aType)
   273 		/** Sets type of the first option.*/
   274 		{
   275 		i[2]=(TUint8)aType;
   276 		}
   277 
   278 	inline void SetOptionDataLen(TInt aLength)
   279 		/** Sets data length of the first option.*/
   280 		{
   281 		i[3]=(TUint8)aLength;
   282 		}
   283 
   284 private:
   285 	union
   286 		{
   287 		TUint8 i[8];
   288 		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   289 		};
   290 	};
   291 
   292 class TInet6HeaderRouting
   293 	/**
   294 	* IPv6 Routing Header.
   295 	* The Type 0 Routing header has the following format:
   296 @verbatim
   297 
   298     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   299     |  Next Header  |  Hdr Ext Len  | Routing Type=0| Segments Left |
   300     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   301     |                            Reserved                           |
   302     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   303     |                                                               |
   304     +                                                               +
   305     |                                                               |
   306     +                           Address[1]                          +
   307     |                                                               |
   308     +                                                               +
   309     |                                                               |
   310     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   311     |                                                               |
   312     +                                                               +
   313     |                                                               |
   314     +                           Address[2]                          +
   315     |                                                               |
   316     +                                                               +
   317     |                                                               |
   318     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   319     .                               .                               .
   320     .                               .                               .
   321     .                               .                               .
   322     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   323     |                                                               |
   324     +                                                               +
   325     |                                                               |
   326     +                           Address[n]                          +
   327     |                                                               |
   328     +                                                               +
   329     |                                                               |
   330     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   331 
   332    Next Header          8-bit selector.  Identifies the type of header
   333                         immediately following the Routing header.  Uses
   334                         the same values as the IPv4 Protocol field
   335                         [RFC-1700 et seq.].
   336 
   337    Hdr Ext Len          8-bit unsigned integer.  Length of the Routing
   338                         header in 8-octet units, not including the first
   339                         8 octets.  For the Type 0 Routing header, Hdr
   340                         Ext Len is equal to two times the number of
   341                         addresses in the header.
   342 
   343    Routing Type         0.
   344 
   345 
   346    Segments Left        8-bit unsigned integer.  Number of route
   347                         segments remaining, i.e., number of explicitly
   348                         listed intermediate nodes still to be visited
   349                         before reaching the final destination.
   350 
   351    Reserved             32-bit reserved field.  Initialized to zero for
   352                         transmission; ignored on reception.
   353 
   354    Address[1..n]        Vector of 128-bit addresses, numbered 1 to n.
   355 
   356 @endverbatim
   357 	* This header mapping describes only the fixed part, without
   358 	* any addresses.
   359 	* @publishedAll
   360 	* @released
   361 	*/
   362 	{
   363 public:
   364 	inline static TInt MinHeaderLength() {return 8; }
   365 	inline static TInt MaxHeaderLength() {return 8; }	
   366 
   367 	inline TUint8* EndPtr() { return i + HeaderLength(); }
   368 
   369 	enum TOffsets
   370 		{
   371 		O_NextHeader,
   372 		O_HdrExtLen,
   373 		O_RoutingType,
   374 		O_SegmentsLeft,
   375 		O_Address = 8
   376 		};
   377 
   378 	inline TInt NextHeader() const { return i[0]; }
   379 	inline TInt HdrExtLen() const { return i[1]; }	// Return raw value
   380 	inline TInt HeaderLength() const { return (i[1]+1) << 3; } // Return true byte length
   381 	inline TInt RoutingType() const { return i[2]; }
   382 	inline TInt SegmentsLeft() const { return i[3]; }
   383 	
   384 	//SET
   385 	inline void SetNextHeader(TInt aNext) { i[0] = (TInt8)aNext; }
   386 	inline void SetHdrExtLen(TInt aLen) { i[1] = (TUint8)aLen; }	
   387 	inline void SetRoutingType(TInt aType) { i[2] = (TUint8)aType; }
   388 	inline void SetSegmentsLeft(TInt aValue) { i[3] = (TUint8)aValue; }
   389 
   390 private:
   391 	union
   392 		{
   393 		TUint8 i[8];
   394 		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   395 		};
   396 	};
   397 
   398 
   399 
   400 class TInet6Options
   401 	/**
   402 	* IPv6 Option extension headers (Hop-by-Hop, Destination Options).
   403 	*
   404 @verbatim
   405    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   406    |  Next Header  |  Hdr Ext Len  |                               |
   407    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
   408    |                                                               |
   409    .                                                               .
   410    .                            Options                            .
   411    .                                                               .
   412    |                                                               |
   413    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   414 
   415   Next Header          8-bit selector.  Identifies the type of header
   416                        immediately following the Destination Options
   417                        header.  Uses the same values as the IPv4
   418                        Protocol field [RFC-1700 et seq.].
   419 
   420   Hdr Ext Len          8-bit unsigned integer.  Length of the
   421                        Destination Options header in 8-octet units, not
   422                        including the first 8 octets.
   423 
   424   Options              Variable-length field, of length such that the
   425                        complete Destination Options header is an
   426                        integer multiple of 8 octets long.  Contains one
   427                        or  more TLV-encoded options, as described in
   428                        section 4.2.
   429 @endverbatim
   430 	* This mapping describes only the minimal 8 bytes.
   431 	* @publishedAll
   432 	* @released
   433 	*/
   434 	{
   435 public:
   436 	inline TInt HeaderLength() const { return (i[1]+1) << 3; } // Return true byte length
   437 
   438 	inline static TInt MinHeaderLength() {return 8; }
   439 	inline static TInt MaxHeaderLength() {return 8; }	
   440 
   441 	inline TUint8* EndPtr() { return i + HeaderLength(); }
   442 
   443 	enum TOffsets
   444 		{
   445 		O_NextHeader,
   446 		O_HdrExtLen,
   447 		O_Options
   448 		};
   449 
   450 	inline TInt NextHeader() const { return i[0]; }
   451 	inline TInt HdrExtLen() const { return i[1]; }	// Return raw value
   452 	
   453 	inline void SetNextHeader(TInt aNext) { i[0] = (TInt8)aNext; }
   454 	inline void SetHdrExtLen(TInt aLen) { i[1] = (TUint8)aLen; }
   455 	
   456 private:
   457 	TUint8 i[8];
   458 	};
   459 
   460 
   461 /**
   462 * @name Destination option types.
   463 *
   464 * @{
   465 */
   466 /** One octet padding. */
   467 const TUint8 KDstOptionPad1				= 0;
   468 /** N octets padding */
   469 const TUint8 KDstOptionPadN				= 1;
   470 /** not used? (MIP6) */
   471 const TUint8 KDstOptionBindingAck		= 7;
   472 /** not used? (MIP6) */
   473 const TUint8 KDstOptionBindingRequest	= 8;
   474 /** not used? (MIP6) */
   475 const TUint8 KDstOptionBindingUpdate	= 0xC6;
   476 /** Home Address option (MIP6) */
   477 const TUint8 KDstOptionHomeAddress		= 0xC9;
   478 /** @} */
   479 
   480 class TInet6OptionBase
   481 	/**
   482 	* IPv6 Option value header.
   483 	*
   484 	* A basic class for handling Type-Length-Value (TLV) options.
   485 	*
   486 @verbatim
   487 	  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
   488       |  Option Type  |  Opt Data Len |  Option Data
   489       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
   490 
   491       Option Type          8-bit identifier of the type of option.
   492 
   493       Opt Data Len         8-bit unsigned integer.  Length of the Option
   494                            Data field of this option, in octets.
   495 
   496       Option Data          Variable-length field.  Option-Type-specific
   497                            data.
   498 @endverbatim
   499 	* Option values are used inside option headers (for example:
   500 	* Hop-by-Hop options and Destination options).
   501 	*
   502 	* @publishedAll
   503 	* @released
   504 	*/
   505 	{
   506 public:
   507 	inline static TInt MinHeaderLength()	{ return 2; }
   508 	inline static TInt MaxHeaderLength()	{ return 2; }
   509 
   510 	inline TInt Type() const				{ return i[0]; }
   511 	inline TInt HeaderLength() const { return i[1] + 2; }
   512 	
   513 	inline void SetType(TInt aType)			{ i[0] = (TUint8)aType; }
   514 	inline void SetDataLen(TInt aLen)		{ i[1] = (TUint8)aLen; }
   515 
   516 	inline TUint8* EndPtr() { return i + HeaderLength(); }
   517 
   518 private:
   519 	TUint8	i[2];
   520 	};
   521 
   522 class TInet6DstOptionBase
   523 	/**
   524 	* IPv6 Option value header.
   525 	* @publishedAll
   526 	* @deprecated
   527 	*	Because of the non-standard method naming and
   528 	*	semantics. Use TInet6OptionBase instead.
   529 	*/
   530 	{
   531 public:
   532 	inline static TInt MinHeaderLength()	{ return 2; }
   533 	inline static TInt MaxHeaderLength()	{ return 2; }
   534 
   535 	inline TInt Type() const				{ return i[0]; }
   536 	inline TInt HeaderLength() const { return i[1]; }
   537 	
   538 	inline void SetType(TInt aType)			{ i[0] = (TUint8)aType; }
   539 	inline void SetHeaderLength(TInt aLen)	{ i[1] = (TUint8)aLen; }
   540 
   541 	inline TUint8* EndPtr() { return i + 2 + HeaderLength(); }
   542 
   543 private:
   544 	TUint8	i[2];
   545 	};
   546 
   547 
   548 class TInet6HeaderFragment
   549 	/**
   550 	* IPv6 Fragment Header.
   551 @verbatim
   552 RFC2460
   553 
   554    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   555    |  Next Header  |   Reserved    |      Fragment Offset    |Res|M|
   556    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   557    |                         Identification                        |
   558    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   559 
   560    Next Header          8-bit selector.  Identifies the initial header
   561                         type of the Fragmentable Part of the original
   562                         packet (defined below).  Uses the same values as
   563                         the IPv4 Protocol field [RFC-1700 et seq.].
   564 
   565    Reserved             8-bit reserved field.  Initialized to zero for
   566                         transmission; ignored on reception.
   567 
   568    Fragment Offset      13-bit unsigned integer.  The offset, in 8-octet
   569                         units, of the data following this header,
   570                         relative to the start of the Fragmentable Part
   571                         of the original packet.
   572 
   573    Res                  2-bit reserved field.  Initialized to zero for
   574                         transmission; ignored on reception.
   575 
   576    M flag               1 = more fragments; 0 = last fragment.
   577 
   578    Identification       32 bits.  See description below.
   579 @endverbatim
   580 	* @publishedAll
   581 	* @released
   582 	*/
   583 	{
   584 public:
   585 	enum TOffsets
   586 		{
   587 		O_FragmentOffset = 2
   588 		};
   589 
   590 	inline TInt HeaderLength() const
   591 		{
   592 		return 8;
   593 		}
   594 
   595 	inline TUint8* EndPtr() { return i + HeaderLength(); }
   596 
   597 	inline static TInt MinHeaderLength() {return 8; }
   598 	inline static TInt MaxHeaderLength() {return 8; }
   599 	
   600 	//
   601 	// Access, Get Fragmentation header values from the packet
   602 	//
   603 	inline TInt NextHeader() const { return i[0]; }
   604 
   605 	inline TInt FragmentOffset() const
   606 		{
   607 		//
   608 		//	The Offset is returned as octet count (3 righmost bits are zero)
   609 		//
   610 		return ((i[2] << 8) + i[3]) & 0xfff8;
   611 		}
   612 
   613 	inline TInt MFlag() const
   614 		{
   615 		return i[3] & 0x01;
   616 		}
   617 
   618 	inline TInt32 Id() const
   619 		{
   620 		return *(TInt32 *)(&i[4]);	// *ASSUMES* proper aligment!!!
   621 		}
   622 	//
   623 	// Building methods
   624 	//
   625 	inline void ZeroAll()
   626 		{
   627 		*((TInt32 *)&i[0]) = 0;		// *ASSUMES* proper aligment!!!
   628 		*((TInt32 *)&i[4]) = 0;		// *ASSUMES* proper aligment!!!
   629 		}
   630 	inline void SetNextHeader(TInt aNext)
   631 		{
   632 		i[0] = (TUint8)aNext;
   633 		}
   634 	inline void SetFragmentOffset(TInt aOffset)
   635 		{
   636 		//
   637 		// The aOffset is assumed to be given in octets. The least significant
   638 		// 3 bits should be ZERO (bits are just masked away).
   639 		//
   640 		i[2]=(TUint8)(aOffset >> 8);
   641 		i[3]=(TUint8)((i[3] & 0x7) | (aOffset & ~0x7));
   642 		}
   643 
   644 	inline void SetMFlag(TInt aFlag)
   645 		{
   646 		i[3]= (TUint8)((i[3] & ~0x1) | (aFlag & 0x1));
   647 		}
   648 
   649 	inline void SetId(TInt32 aId)
   650 		{
   651 		*((TInt32 *)&i[4]) = aId;	// *ASSUMES* proper aligment!!!
   652 		}
   653 private:
   654 	union
   655 		{
   656 		TUint8 i[8];
   657 		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   658 		};
   659 	};
   660 
   661 class TInet6HeaderAH
   662 	/**
   663 	* IPsec Authentication Header.
   664 	*
   665 	* The function parameters and return values are in host order,
   666 	* except SPI, which is always in network byte order.
   667 @verbatim
   668 Extract from RFC-2402
   669 
   670     0                   1                   2                   3
   671     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   672    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   673    | Next Header   |  Payload Len  |          RESERVED             |
   674    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   675    |                 Security Parameters Index (SPI)               |
   676    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   677    |                    Sequence Number Field                      |
   678    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   679    |                                                               |
   680    +                Authentication Data (variable)                 |
   681    |                                                               |
   682    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   683 @endverbatim
   684 	* @publishedAll
   685 	* @released
   686 	*/
   687 	{
   688 public:
   689 	//
   690 	// Basic
   691 	//
   692 	inline static TInt MinHeaderLength() {return 3*4; }
   693 	inline static TInt MaxHeaderLength() {return 3*4; }
   694 	inline TUint8 *EndPtr() {return i + HeaderLength();}
   695 	//
   696 	// Access, get values
   697 	//
   698 	inline TInt NextHeader() const
   699 		{
   700 		return i[0];
   701 		}
   702 	//
   703 	// PayloadLength returns the raw value
   704 	//
   705 	inline TInt PayloadLength() const
   706 		{
   707 		return i[1];
   708 		}
   709 	//
   710 	// *NOTE* AH is called IPv6 extension header, but its
   711 	// length field semantics does not follow the normal
   712 	// IPv6 extension header logic (it follows the IPv4)
   713 	//
   714 	inline TInt HeaderLength() const
   715 		{
   716 		return (i[1]+2) << 2;	// IPv4 and IPv6
   717 		}
   718 	//
   719 	// SPI is returned in network byte order
   720 	//
   721 	inline TUint32 SPI() const
   722 		{
   723 		return *((TUint32 *)(i + 4));
   724 		}
   725 	inline TUint32 Sequence() const
   726 		{
   727 		return (i[8] << 24) | (i[9] << 16) | (i[10] << 8) | i[11];
   728 		}
   729 
   730 	// The length of the Authentication Data (in octets).
   731 	// *NOTE* This will include the potential padding! -- msa
   732 	inline TInt DataLength() const		{
   733 		return HeaderLength() - 12;
   734 		}
   735 	inline TPtr8 ICV()
   736 		{
   737 		return TPtr8((TUint8 *)&i[12], DataLength(), DataLength());
   738 		}
   739 	//
   740 	// Build
   741 	//
   742 	inline void SetNextHeader(TInt aNext)
   743 		{
   744 		i[0] = (TUint8)aNext;
   745 		}
   746 	inline void SetPayloadLength(TInt aByte)
   747 		{
   748 		i[1] = (TUint8)aByte;
   749 		}
   750 	//
   751 	// *NOTE* AH is called IPv6 extension header, but its
   752 	// length field semantics does not follow the normal
   753 	// IPv6 extension header logic (it follows the IPv4)
   754 	// As this is bit tricky, a "cooked version" of PayloadLength
   755 	// setting is also provided (e.g. take in bytes, and compute
   756 	// the real payload length value) -- msa
   757 	inline void SetHeaderLength(TInt aLength)
   758 		{
   759 		i[1] = (TUint8)((aLength >> 2) - 2);
   760 		}
   761 	inline void SetSPI(TUint32 aSPI)
   762 		{
   763 		*((TUint32 *)(i + 4)) = aSPI;
   764 		}
   765 	inline void SetReserved(TInt aValue)
   766 		{
   767 		i[3] = (TUint8)aValue;
   768 		i[2] = (TUint8)(aValue >> 8);
   769 		}
   770 	inline void SetSequence(TUint32 aSeq)
   771 		{
   772 		i[11] = (TUint8)aSeq;
   773 		i[10] = (TUint8)(aSeq >> 8);
   774 		i[9] = (TUint8)(aSeq >> 16);
   775 		i[8] = (TUint8)(aSeq >> 24);
   776 		}
   777 protected:
   778 	union
   779 		{
   780 		TUint8 i[3*4];
   781 		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   782 		};
   783 	};
   784 
   785 
   786 
   787 class TInet6HeaderESP
   788 	/**
   789 	* IPsec Encapsulating Security Payload Packet Format.
   790 	*
   791 	* The function parameters and return values are in host
   792 	* order (except SPI, which is always in network byte order)
   793 	*
   794 @verbatim
   795 RFC-2406
   796  0                   1                   2                   3
   797  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   798 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ----
   799 |               Security Parameters Index (SPI)                 | ^Auth.
   800 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Cov-
   801 |                      Sequence Number                          | |erage
   802 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ----
   803 |                    Payload Data* (variable)                   | |   ^
   804 ~                                                               ~ |   |
   805 |                                                               | |Conf.
   806 +               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Cov-
   807 |               |     Padding (0-255 bytes)                     | |erage*
   808 +-+-+-+-+-+-+-+-+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |   |
   809 |                               |  Pad Length   | Next Header   | v   v
   810 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ------
   811 |                 Authentication Data (variable)                |
   812 ~                                                               ~
   813 |                                                               |
   814 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   815 @endverbatim
   816 	* This only defines the fixed portion of the ESP, 8 bytes).
   817 	* @publishedAll
   818 	* @released
   819 	*/
   820 	{
   821 public:
   822 	//
   823 	// Basic
   824 	//
   825 	inline static TInt MinHeaderLength() {return 2*4; }
   826 	inline static TInt MaxHeaderLength() {return 2*4; }
   827 	inline TInt HeaderLength() const {return 2*4; }
   828 	inline TUint8 *EndPtr() {return i + HeaderLength();}
   829 
   830 	//
   831 	// Access, get values
   832 	//
   833 	//
   834 	// SPI is returned in network byte order
   835 	//
   836 	inline TUint32 SPI() const
   837 		{
   838 		return *((TUint32 *)(i + 0));
   839 		}
   840 	inline TUint32 Sequence() const
   841 		{
   842 		return (i[4] << 24) | (i[5] << 16) | (i[6] << 8) | i[7];
   843 		}
   844 	//
   845 	// IV is not exactly part of the header, but provide
   846 	// a method that returns a Ptr to it (assuming the
   847 	// IV is accessible directly after the fixed part).
   848 	//
   849 	inline TPtr8 IV(TInt aLen)
   850 		{
   851 		return TPtr8((TUint8 *)&i[sizeof(i)], aLen, aLen);
   852 		}
   853 
   854 	//
   855 	// Build
   856 	//
   857 	inline void SetSPI(TUint32 aSPI)
   858 		{
   859 		*((TUint32 *)(i + 0)) = aSPI;
   860 		}
   861 	inline void SetSequence(TUint32 aSeq)
   862 		{
   863 		i[7] = (TUint8)aSeq;
   864 		i[6] = (TUint8)(aSeq >> 8);
   865 		i[5] = (TUint8)(aSeq >> 16);
   866 		i[4] = (TUint8)(aSeq >> 24);
   867 		}
   868 protected:
   869 	union
   870 		{
   871 		TUint8 i[2*4];
   872 		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   873 		};
   874 	};
   875 
   876 /** @} */
   877 #endif