epoc32/include/ext_hdr.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/ext_hdr.h	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,877 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// ext_hdr.h - IPv6 extension headers
    1.18 +// Defines the basic classes for accessing the extension
    1.19 +// header structures within IPv6 packets.
    1.20 +// All return types codified as TInt (Native form and signed)
    1.21 +//
    1.22 +
    1.23 +
    1.24 +
    1.25 +/**
    1.26 + @file ext_hdr.h
    1.27 + @ingroup ip_packet_formats
    1.28 + @publishedAll
    1.29 + @released
    1.30 +*/
    1.31 +
    1.32 +#ifndef __EXT_HDR_H__
    1.33 +#define __EXT_HDR_H__
    1.34 +
    1.35 +#include <e32def.h>
    1.36 +#include "in_hdr.h"
    1.37 +
    1.38 +/**
    1.39 +* @addtogroup  ip_packet_formats
    1.40 +* @{
    1.41 +*/
    1.42 +
    1.43 +/**
    1.44 +* @name Additional protocol numbers
    1.45 +*
    1.46 +* @{
    1.47 +*/
    1.48 +/** Hop-by-Hop Extension Header. See TInet6HeaderHopByHop. */
    1.49 +const TUint KProtocolInet6HopOptions = 0;
    1.50 +/** Tunneled IPv4. The next header is TInet6HeaderIP4. */
    1.51 +const TUint KProtocolInetIpip = 4;
    1.52 +/** Routing Header. See TInet6HeaderRouting. */
    1.53 +const TUint KProtocolInet6RoutingHeader = 43;
    1.54 +/** IPv6 Fragment Header. See TInet6HeaderFragment. */
    1.55 +const TUint KProtocolInet6Fragment = 44;
    1.56 +/** IPsec ESP header. See TInet6HeaderESP. */
    1.57 +const TUint KProtocolInetEsp	= 50;
    1.58 +/** IPsec AH header. See TInet6HeaderAH. */
    1.59 +const TUint KProtocolInetAh = 51;
    1.60 +/** No Next Header. */
    1.61 +const TUint KProtocolInet6NoNextHeader = 59;
    1.62 +/** Destination Options Extension Header. See TInet6Options. */
    1.63 +const TUint KProtocolInet6DestinationOptions = 60;
    1.64 +/* @} */
    1.65 +
    1.66 +//
    1.67 +// TInet6HeaderExtension
    1.68 +// *********************
    1.69 +class TInet6HeaderExtension
    1.70 +	/**
    1.71 +	* Basic part of normal IPv6 extension headers.
    1.72 +	*
    1.73 +	* This is simple class to be used in scanning the extension headers
    1.74 +	* which are known to follow the following format:
    1.75 +	*
    1.76 +	* - 1st octet = Next Header field
    1.77 +	*
    1.78 +	* - 2nd octet = Length of the extension header (= (x+1)*8 octets)
    1.79 +	*
    1.80 +	* @note
    1.81 +	*	Extension headers do not need to follow this format. Unknown
    1.82 +	*	headers cannot be skipped over by just assuming this format!
    1.83 +	*
    1.84 +	* @publishedAll
    1.85 +	* @released
    1.86 +	*/
    1.87 +	{
    1.88 +public:
    1.89 +	inline static TInt MinHeaderLength() {return 8; }
    1.90 +	inline static TInt MaxHeaderLength() {return 8; }	
    1.91 +
    1.92 +	inline TUint8* EndPtr() { return i + HeaderLength(); }
    1.93 +	inline TInt NextHeader() const { return i[0]; }
    1.94 +	inline TInt HdrExtLen() const { return i[1]; }	// Return raw value
    1.95 +	inline TInt HeaderLength() const { return (i[1]+1) << 3; } // Return true byte length
    1.96 +private:
    1.97 +	union
    1.98 +		{
    1.99 +		TUint8 i[8];
   1.100 +		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   1.101 +		};
   1.102 +	};
   1.103 +
   1.104 +
   1.105 +class TInet6HeaderHBH
   1.106 +	/**
   1.107 +	* IPv6 Hop-by-hop options header.
   1.108 +@verbatim
   1.109 +	From RFC 2460
   1.110 +
   1.111 +    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.112 +    |  Next Header  |  Hdr Ext Len  |                               |
   1.113 +    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
   1.114 +    |                                                               |
   1.115 +    .                                                               .
   1.116 +    .                            Options                            .
   1.117 +    .                                                               .
   1.118 +    |                                                               |
   1.119 +    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.120 +
   1.121 +   Next Header          8-bit selector.  Identifies the type of header
   1.122 +                        immediately following the Hop-by-Hop Options
   1.123 +                        header.  Uses the same values as the IPv4
   1.124 +                        Protocol field [RFC-1700 et seq.].
   1.125 +
   1.126 +   Hdr Ext Len          8-bit unsigned integer.  Length of the Hop-by-
   1.127 +                        Hop Options header in 8-octet units, not
   1.128 +                        including the first 8 octets.
   1.129 +
   1.130 +   Options              Variable-length field, of length such that the
   1.131 +                        complete Hop-by-Hop Options header is an integer
   1.132 +                        multiple of 8 octets long.  Contains one or more
   1.133 +                        TLV-encoded options, as described in section
   1.134 +                        4.2.
   1.135 +
   1.136 +  And Options is:
   1.137 +
   1.138 +	  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
   1.139 +      |  Option Type  |  Opt Data Len |  Option Data
   1.140 +      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
   1.141 +
   1.142 +      Option Type          8-bit identifier of the type of option.
   1.143 +
   1.144 +      Opt Data Len         8-bit unsigned integer.  Length of the Option
   1.145 +                           Data field of this option, in octets.
   1.146 +
   1.147 +      Option Data          Variable-length field.  Option-Type-specific
   1.148 +                           data.
   1.149 +@endverbatim
   1.150 +	* @publishedAll
   1.151 +	* @released
   1.152 +	*/
   1.153 +	{
   1.154 +public:
   1.155 +	inline TInt HeaderLength() const
   1.156 +		{
   1.157 +		return (i[1]+1) << 3;	// Return length in octets.
   1.158 +		}
   1.159 +
   1.160 +	inline TUint8* EndPtr() { return i + HeaderLength(); }
   1.161 +
   1.162 +	inline static TInt MinHeaderLength() {return 8; }	
   1.163 +	inline static TInt MaxHeaderLength() {return 8; }
   1.164 +	
   1.165 +	//
   1.166 +	// Access, Get Hop By Hop header values from the packet
   1.167 +	//
   1.168 +	inline TInt NextHeader() const
   1.169 +		{
   1.170 +		return i[0];
   1.171 +		}
   1.172 +
   1.173 +	//From Options
   1.174 +	inline TInt OptionType() const
   1.175 +		/** @return The type of the first option */
   1.176 +		{
   1.177 +		return i[2];
   1.178 +		}
   1.179 +	inline TInt OptionDataLen() const
   1.180 +		/** @return The data length of the first option */
   1.181 +		{
   1.182 +		return i[3];
   1.183 +		}
   1.184 +
   1.185 +	//
   1.186 +	// Access, SET Hop By Hop header values
   1.187 +	//
   1.188 +	inline void SetHdrExtLen(TInt aLength)
   1.189 +		{
   1.190 +		i[1]=(TUint8)aLength;
   1.191 +		}
   1.192 +	
   1.193 +	inline void SetNextHeader(TInt aNext)
   1.194 +		{
   1.195 +		i[0]=(TUint8)aNext;
   1.196 +		}
   1.197 +
   1.198 +	//From Options
   1.199 +	inline void SetOptionType(TInt aType)
   1.200 +		/** Sets type of the first option.*/
   1.201 +		{
   1.202 +		i[2]=(TUint8)aType;
   1.203 +		}
   1.204 +
   1.205 +	inline void SetOptionDataLen(TInt aLength)
   1.206 +		/** Sets data length of the first option.*/
   1.207 +		{
   1.208 +		i[3]=(TUint8)aLength;
   1.209 +		}
   1.210 +
   1.211 +private:
   1.212 +	union
   1.213 +		{
   1.214 +		TUint8 i[8];
   1.215 +		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   1.216 +		};
   1.217 +	};
   1.218 +
   1.219 +
   1.220 +class TInet6HeaderHopByHop
   1.221 +	/**
   1.222 +	* IPv6 Hop-by-hop options header.
   1.223 +	* @publishedAll
   1.224 +	* @deprecated
   1.225 +	*	Because of the non-standard method naming and
   1.226 +	*	semantics. Use TInet6HeaderHBH instead.
   1.227 +	*/
   1.228 +	{
   1.229 +public:
   1.230 +	inline TInt HeaderLength() const
   1.231 +		{
   1.232 +		return i[1];
   1.233 +		}
   1.234 +
   1.235 +	inline TUint8* EndPtr() { return i + HeaderLength() * 8 + MinHeaderLength(); }
   1.236 +
   1.237 +	inline static TInt MinHeaderLength() {return 8; }	
   1.238 +	inline static TInt MaxHeaderLength() {return 8; }
   1.239 +	
   1.240 +	//
   1.241 +	// Access, Get Hop By Hop header values from the packet
   1.242 +	//
   1.243 +	inline TInt NextHeader() const
   1.244 +		/** @return The length in 8-byte units! (non-standard, should be bytes!) */
   1.245 +		{
   1.246 +		return i[0];
   1.247 +		}
   1.248 +
   1.249 +	//From Options
   1.250 +	inline TInt OptionType() const
   1.251 +		/** @return The type of the first option */
   1.252 +		{
   1.253 +		return i[2];
   1.254 +		}
   1.255 +	inline TInt OptionDataLen() const
   1.256 +		/** @return The data length of the first option */
   1.257 +		{
   1.258 +		return i[3];
   1.259 +		}
   1.260 +
   1.261 +	//
   1.262 +	// Access, SET Hop By Hop header values
   1.263 +	//
   1.264 +	inline void SetHeaderLength(TInt aLength)
   1.265 +		{
   1.266 +		i[1]=(TUint8)aLength;
   1.267 +		}
   1.268 +	
   1.269 +	inline void SetNextHeader(TInt aNext)
   1.270 +		{
   1.271 +		i[0]=(TUint8)aNext;
   1.272 +		}
   1.273 +
   1.274 +	//From Options
   1.275 +	inline void SetOptionType(TInt aType)
   1.276 +		/** Sets type of the first option.*/
   1.277 +		{
   1.278 +		i[2]=(TUint8)aType;
   1.279 +		}
   1.280 +
   1.281 +	inline void SetOptionDataLen(TInt aLength)
   1.282 +		/** Sets data length of the first option.*/
   1.283 +		{
   1.284 +		i[3]=(TUint8)aLength;
   1.285 +		}
   1.286 +
   1.287 +private:
   1.288 +	union
   1.289 +		{
   1.290 +		TUint8 i[8];
   1.291 +		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   1.292 +		};
   1.293 +	};
   1.294 +
   1.295 +class TInet6HeaderRouting
   1.296 +	/**
   1.297 +	* IPv6 Routing Header.
   1.298 +	* The Type 0 Routing header has the following format:
   1.299 +@verbatim
   1.300 +
   1.301 +    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.302 +    |  Next Header  |  Hdr Ext Len  | Routing Type=0| Segments Left |
   1.303 +    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.304 +    |                            Reserved                           |
   1.305 +    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.306 +    |                                                               |
   1.307 +    +                                                               +
   1.308 +    |                                                               |
   1.309 +    +                           Address[1]                          +
   1.310 +    |                                                               |
   1.311 +    +                                                               +
   1.312 +    |                                                               |
   1.313 +    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.314 +    |                                                               |
   1.315 +    +                                                               +
   1.316 +    |                                                               |
   1.317 +    +                           Address[2]                          +
   1.318 +    |                                                               |
   1.319 +    +                                                               +
   1.320 +    |                                                               |
   1.321 +    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.322 +    .                               .                               .
   1.323 +    .                               .                               .
   1.324 +    .                               .                               .
   1.325 +    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.326 +    |                                                               |
   1.327 +    +                                                               +
   1.328 +    |                                                               |
   1.329 +    +                           Address[n]                          +
   1.330 +    |                                                               |
   1.331 +    +                                                               +
   1.332 +    |                                                               |
   1.333 +    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.334 +
   1.335 +   Next Header          8-bit selector.  Identifies the type of header
   1.336 +                        immediately following the Routing header.  Uses
   1.337 +                        the same values as the IPv4 Protocol field
   1.338 +                        [RFC-1700 et seq.].
   1.339 +
   1.340 +   Hdr Ext Len          8-bit unsigned integer.  Length of the Routing
   1.341 +                        header in 8-octet units, not including the first
   1.342 +                        8 octets.  For the Type 0 Routing header, Hdr
   1.343 +                        Ext Len is equal to two times the number of
   1.344 +                        addresses in the header.
   1.345 +
   1.346 +   Routing Type         0.
   1.347 +
   1.348 +
   1.349 +   Segments Left        8-bit unsigned integer.  Number of route
   1.350 +                        segments remaining, i.e., number of explicitly
   1.351 +                        listed intermediate nodes still to be visited
   1.352 +                        before reaching the final destination.
   1.353 +
   1.354 +   Reserved             32-bit reserved field.  Initialized to zero for
   1.355 +                        transmission; ignored on reception.
   1.356 +
   1.357 +   Address[1..n]        Vector of 128-bit addresses, numbered 1 to n.
   1.358 +
   1.359 +@endverbatim
   1.360 +	* This header mapping describes only the fixed part, without
   1.361 +	* any addresses.
   1.362 +	* @publishedAll
   1.363 +	* @released
   1.364 +	*/
   1.365 +	{
   1.366 +public:
   1.367 +	inline static TInt MinHeaderLength() {return 8; }
   1.368 +	inline static TInt MaxHeaderLength() {return 8; }	
   1.369 +
   1.370 +	inline TUint8* EndPtr() { return i + HeaderLength(); }
   1.371 +
   1.372 +	enum TOffsets
   1.373 +		{
   1.374 +		O_NextHeader,
   1.375 +		O_HdrExtLen,
   1.376 +		O_RoutingType,
   1.377 +		O_SegmentsLeft,
   1.378 +		O_Address = 8
   1.379 +		};
   1.380 +
   1.381 +	inline TInt NextHeader() const { return i[0]; }
   1.382 +	inline TInt HdrExtLen() const { return i[1]; }	// Return raw value
   1.383 +	inline TInt HeaderLength() const { return (i[1]+1) << 3; } // Return true byte length
   1.384 +	inline TInt RoutingType() const { return i[2]; }
   1.385 +	inline TInt SegmentsLeft() const { return i[3]; }
   1.386 +	
   1.387 +	//SET
   1.388 +	inline void SetNextHeader(TInt aNext) { i[0] = (TInt8)aNext; }
   1.389 +	inline void SetHdrExtLen(TInt aLen) { i[1] = (TUint8)aLen; }	
   1.390 +	inline void SetRoutingType(TInt aType) { i[2] = (TUint8)aType; }
   1.391 +	inline void SetSegmentsLeft(TInt aValue) { i[3] = (TUint8)aValue; }
   1.392 +
   1.393 +private:
   1.394 +	union
   1.395 +		{
   1.396 +		TUint8 i[8];
   1.397 +		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   1.398 +		};
   1.399 +	};
   1.400 +
   1.401 +
   1.402 +
   1.403 +class TInet6Options
   1.404 +	/**
   1.405 +	* IPv6 Option extension headers (Hop-by-Hop, Destination Options).
   1.406 +	*
   1.407 +@verbatim
   1.408 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.409 +   |  Next Header  |  Hdr Ext Len  |                               |
   1.410 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               +
   1.411 +   |                                                               |
   1.412 +   .                                                               .
   1.413 +   .                            Options                            .
   1.414 +   .                                                               .
   1.415 +   |                                                               |
   1.416 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.417 +
   1.418 +  Next Header          8-bit selector.  Identifies the type of header
   1.419 +                       immediately following the Destination Options
   1.420 +                       header.  Uses the same values as the IPv4
   1.421 +                       Protocol field [RFC-1700 et seq.].
   1.422 +
   1.423 +  Hdr Ext Len          8-bit unsigned integer.  Length of the
   1.424 +                       Destination Options header in 8-octet units, not
   1.425 +                       including the first 8 octets.
   1.426 +
   1.427 +  Options              Variable-length field, of length such that the
   1.428 +                       complete Destination Options header is an
   1.429 +                       integer multiple of 8 octets long.  Contains one
   1.430 +                       or  more TLV-encoded options, as described in
   1.431 +                       section 4.2.
   1.432 +@endverbatim
   1.433 +	* This mapping describes only the minimal 8 bytes.
   1.434 +	* @publishedAll
   1.435 +	* @released
   1.436 +	*/
   1.437 +	{
   1.438 +public:
   1.439 +	inline TInt HeaderLength() const { return (i[1]+1) << 3; } // Return true byte length
   1.440 +
   1.441 +	inline static TInt MinHeaderLength() {return 8; }
   1.442 +	inline static TInt MaxHeaderLength() {return 8; }	
   1.443 +
   1.444 +	inline TUint8* EndPtr() { return i + HeaderLength(); }
   1.445 +
   1.446 +	enum TOffsets
   1.447 +		{
   1.448 +		O_NextHeader,
   1.449 +		O_HdrExtLen,
   1.450 +		O_Options
   1.451 +		};
   1.452 +
   1.453 +	inline TInt NextHeader() const { return i[0]; }
   1.454 +	inline TInt HdrExtLen() const { return i[1]; }	// Return raw value
   1.455 +	
   1.456 +	inline void SetNextHeader(TInt aNext) { i[0] = (TInt8)aNext; }
   1.457 +	inline void SetHdrExtLen(TInt aLen) { i[1] = (TUint8)aLen; }
   1.458 +	
   1.459 +private:
   1.460 +	TUint8 i[8];
   1.461 +	};
   1.462 +
   1.463 +
   1.464 +/**
   1.465 +* @name Destination option types.
   1.466 +*
   1.467 +* @{
   1.468 +*/
   1.469 +/** One octet padding. */
   1.470 +const TUint8 KDstOptionPad1				= 0;
   1.471 +/** N octets padding */
   1.472 +const TUint8 KDstOptionPadN				= 1;
   1.473 +/** not used? (MIP6) */
   1.474 +const TUint8 KDstOptionBindingAck		= 7;
   1.475 +/** not used? (MIP6) */
   1.476 +const TUint8 KDstOptionBindingRequest	= 8;
   1.477 +/** not used? (MIP6) */
   1.478 +const TUint8 KDstOptionBindingUpdate	= 0xC6;
   1.479 +/** Home Address option (MIP6) */
   1.480 +const TUint8 KDstOptionHomeAddress		= 0xC9;
   1.481 +/** @} */
   1.482 +
   1.483 +class TInet6OptionBase
   1.484 +	/**
   1.485 +	* IPv6 Option value header.
   1.486 +	*
   1.487 +	* A basic class for handling Type-Length-Value (TLV) options.
   1.488 +	*
   1.489 +@verbatim
   1.490 +	  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
   1.491 +      |  Option Type  |  Opt Data Len |  Option Data
   1.492 +      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- - - - - - - - -
   1.493 +
   1.494 +      Option Type          8-bit identifier of the type of option.
   1.495 +
   1.496 +      Opt Data Len         8-bit unsigned integer.  Length of the Option
   1.497 +                           Data field of this option, in octets.
   1.498 +
   1.499 +      Option Data          Variable-length field.  Option-Type-specific
   1.500 +                           data.
   1.501 +@endverbatim
   1.502 +	* Option values are used inside option headers (for example:
   1.503 +	* Hop-by-Hop options and Destination options).
   1.504 +	*
   1.505 +	* @publishedAll
   1.506 +	* @released
   1.507 +	*/
   1.508 +	{
   1.509 +public:
   1.510 +	inline static TInt MinHeaderLength()	{ return 2; }
   1.511 +	inline static TInt MaxHeaderLength()	{ return 2; }
   1.512 +
   1.513 +	inline TInt Type() const				{ return i[0]; }
   1.514 +	inline TInt HeaderLength() const { return i[1] + 2; }
   1.515 +	
   1.516 +	inline void SetType(TInt aType)			{ i[0] = (TUint8)aType; }
   1.517 +	inline void SetDataLen(TInt aLen)		{ i[1] = (TUint8)aLen; }
   1.518 +
   1.519 +	inline TUint8* EndPtr() { return i + HeaderLength(); }
   1.520 +
   1.521 +private:
   1.522 +	TUint8	i[2];
   1.523 +	};
   1.524 +
   1.525 +class TInet6DstOptionBase
   1.526 +	/**
   1.527 +	* IPv6 Option value header.
   1.528 +	* @publishedAll
   1.529 +	* @deprecated
   1.530 +	*	Because of the non-standard method naming and
   1.531 +	*	semantics. Use TInet6OptionBase instead.
   1.532 +	*/
   1.533 +	{
   1.534 +public:
   1.535 +	inline static TInt MinHeaderLength()	{ return 2; }
   1.536 +	inline static TInt MaxHeaderLength()	{ return 2; }
   1.537 +
   1.538 +	inline TInt Type() const				{ return i[0]; }
   1.539 +	inline TInt HeaderLength() const { return i[1]; }
   1.540 +	
   1.541 +	inline void SetType(TInt aType)			{ i[0] = (TUint8)aType; }
   1.542 +	inline void SetHeaderLength(TInt aLen)	{ i[1] = (TUint8)aLen; }
   1.543 +
   1.544 +	inline TUint8* EndPtr() { return i + 2 + HeaderLength(); }
   1.545 +
   1.546 +private:
   1.547 +	TUint8	i[2];
   1.548 +	};
   1.549 +
   1.550 +
   1.551 +class TInet6HeaderFragment
   1.552 +	/**
   1.553 +	* IPv6 Fragment Header.
   1.554 +@verbatim
   1.555 +RFC2460
   1.556 +
   1.557 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.558 +   |  Next Header  |   Reserved    |      Fragment Offset    |Res|M|
   1.559 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.560 +   |                         Identification                        |
   1.561 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.562 +
   1.563 +   Next Header          8-bit selector.  Identifies the initial header
   1.564 +                        type of the Fragmentable Part of the original
   1.565 +                        packet (defined below).  Uses the same values as
   1.566 +                        the IPv4 Protocol field [RFC-1700 et seq.].
   1.567 +
   1.568 +   Reserved             8-bit reserved field.  Initialized to zero for
   1.569 +                        transmission; ignored on reception.
   1.570 +
   1.571 +   Fragment Offset      13-bit unsigned integer.  The offset, in 8-octet
   1.572 +                        units, of the data following this header,
   1.573 +                        relative to the start of the Fragmentable Part
   1.574 +                        of the original packet.
   1.575 +
   1.576 +   Res                  2-bit reserved field.  Initialized to zero for
   1.577 +                        transmission; ignored on reception.
   1.578 +
   1.579 +   M flag               1 = more fragments; 0 = last fragment.
   1.580 +
   1.581 +   Identification       32 bits.  See description below.
   1.582 +@endverbatim
   1.583 +	* @publishedAll
   1.584 +	* @released
   1.585 +	*/
   1.586 +	{
   1.587 +public:
   1.588 +	enum TOffsets
   1.589 +		{
   1.590 +		O_FragmentOffset = 2
   1.591 +		};
   1.592 +
   1.593 +	inline TInt HeaderLength() const
   1.594 +		{
   1.595 +		return 8;
   1.596 +		}
   1.597 +
   1.598 +	inline TUint8* EndPtr() { return i + HeaderLength(); }
   1.599 +
   1.600 +	inline static TInt MinHeaderLength() {return 8; }
   1.601 +	inline static TInt MaxHeaderLength() {return 8; }
   1.602 +	
   1.603 +	//
   1.604 +	// Access, Get Fragmentation header values from the packet
   1.605 +	//
   1.606 +	inline TInt NextHeader() const { return i[0]; }
   1.607 +
   1.608 +	inline TInt FragmentOffset() const
   1.609 +		{
   1.610 +		//
   1.611 +		//	The Offset is returned as octet count (3 righmost bits are zero)
   1.612 +		//
   1.613 +		return ((i[2] << 8) + i[3]) & 0xfff8;
   1.614 +		}
   1.615 +
   1.616 +	inline TInt MFlag() const
   1.617 +		{
   1.618 +		return i[3] & 0x01;
   1.619 +		}
   1.620 +
   1.621 +	inline TInt32 Id() const
   1.622 +		{
   1.623 +		return *(TInt32 *)(&i[4]);	// *ASSUMES* proper aligment!!!
   1.624 +		}
   1.625 +	//
   1.626 +	// Building methods
   1.627 +	//
   1.628 +	inline void ZeroAll()
   1.629 +		{
   1.630 +		*((TInt32 *)&i[0]) = 0;		// *ASSUMES* proper aligment!!!
   1.631 +		*((TInt32 *)&i[4]) = 0;		// *ASSUMES* proper aligment!!!
   1.632 +		}
   1.633 +	inline void SetNextHeader(TInt aNext)
   1.634 +		{
   1.635 +		i[0] = (TUint8)aNext;
   1.636 +		}
   1.637 +	inline void SetFragmentOffset(TInt aOffset)
   1.638 +		{
   1.639 +		//
   1.640 +		// The aOffset is assumed to be given in octets. The least significant
   1.641 +		// 3 bits should be ZERO (bits are just masked away).
   1.642 +		//
   1.643 +		i[2]=(TUint8)(aOffset >> 8);
   1.644 +		i[3]=(TUint8)((i[3] & 0x7) | (aOffset & ~0x7));
   1.645 +		}
   1.646 +
   1.647 +	inline void SetMFlag(TInt aFlag)
   1.648 +		{
   1.649 +		i[3]= (TUint8)((i[3] & ~0x1) | (aFlag & 0x1));
   1.650 +		}
   1.651 +
   1.652 +	inline void SetId(TInt32 aId)
   1.653 +		{
   1.654 +		*((TInt32 *)&i[4]) = aId;	// *ASSUMES* proper aligment!!!
   1.655 +		}
   1.656 +private:
   1.657 +	union
   1.658 +		{
   1.659 +		TUint8 i[8];
   1.660 +		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   1.661 +		};
   1.662 +	};
   1.663 +
   1.664 +class TInet6HeaderAH
   1.665 +	/**
   1.666 +	* IPsec Authentication Header.
   1.667 +	*
   1.668 +	* The function parameters and return values are in host order,
   1.669 +	* except SPI, which is always in network byte order.
   1.670 +@verbatim
   1.671 +Extract from RFC-2402
   1.672 +
   1.673 +    0                   1                   2                   3
   1.674 +    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
   1.675 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.676 +   | Next Header   |  Payload Len  |          RESERVED             |
   1.677 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.678 +   |                 Security Parameters Index (SPI)               |
   1.679 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.680 +   |                    Sequence Number Field                      |
   1.681 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.682 +   |                                                               |
   1.683 +   +                Authentication Data (variable)                 |
   1.684 +   |                                                               |
   1.685 +   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.686 +@endverbatim
   1.687 +	* @publishedAll
   1.688 +	* @released
   1.689 +	*/
   1.690 +	{
   1.691 +public:
   1.692 +	//
   1.693 +	// Basic
   1.694 +	//
   1.695 +	inline static TInt MinHeaderLength() {return 3*4; }
   1.696 +	inline static TInt MaxHeaderLength() {return 3*4; }
   1.697 +	inline TUint8 *EndPtr() {return i + HeaderLength();}
   1.698 +	//
   1.699 +	// Access, get values
   1.700 +	//
   1.701 +	inline TInt NextHeader() const
   1.702 +		{
   1.703 +		return i[0];
   1.704 +		}
   1.705 +	//
   1.706 +	// PayloadLength returns the raw value
   1.707 +	//
   1.708 +	inline TInt PayloadLength() const
   1.709 +		{
   1.710 +		return i[1];
   1.711 +		}
   1.712 +	//
   1.713 +	// *NOTE* AH is called IPv6 extension header, but its
   1.714 +	// length field semantics does not follow the normal
   1.715 +	// IPv6 extension header logic (it follows the IPv4)
   1.716 +	//
   1.717 +	inline TInt HeaderLength() const
   1.718 +		{
   1.719 +		return (i[1]+2) << 2;	// IPv4 and IPv6
   1.720 +		}
   1.721 +	//
   1.722 +	// SPI is returned in network byte order
   1.723 +	//
   1.724 +	inline TUint32 SPI() const
   1.725 +		{
   1.726 +		return *((TUint32 *)(i + 4));
   1.727 +		}
   1.728 +	inline TUint32 Sequence() const
   1.729 +		{
   1.730 +		return (i[8] << 24) | (i[9] << 16) | (i[10] << 8) | i[11];
   1.731 +		}
   1.732 +
   1.733 +	// The length of the Authentication Data (in octets).
   1.734 +	// *NOTE* This will include the potential padding! -- msa
   1.735 +	inline TInt DataLength() const		{
   1.736 +		return HeaderLength() - 12;
   1.737 +		}
   1.738 +	inline TPtr8 ICV()
   1.739 +		{
   1.740 +		return TPtr8((TUint8 *)&i[12], DataLength(), DataLength());
   1.741 +		}
   1.742 +	//
   1.743 +	// Build
   1.744 +	//
   1.745 +	inline void SetNextHeader(TInt aNext)
   1.746 +		{
   1.747 +		i[0] = (TUint8)aNext;
   1.748 +		}
   1.749 +	inline void SetPayloadLength(TInt aByte)
   1.750 +		{
   1.751 +		i[1] = (TUint8)aByte;
   1.752 +		}
   1.753 +	//
   1.754 +	// *NOTE* AH is called IPv6 extension header, but its
   1.755 +	// length field semantics does not follow the normal
   1.756 +	// IPv6 extension header logic (it follows the IPv4)
   1.757 +	// As this is bit tricky, a "cooked version" of PayloadLength
   1.758 +	// setting is also provided (e.g. take in bytes, and compute
   1.759 +	// the real payload length value) -- msa
   1.760 +	inline void SetHeaderLength(TInt aLength)
   1.761 +		{
   1.762 +		i[1] = (TUint8)((aLength >> 2) - 2);
   1.763 +		}
   1.764 +	inline void SetSPI(TUint32 aSPI)
   1.765 +		{
   1.766 +		*((TUint32 *)(i + 4)) = aSPI;
   1.767 +		}
   1.768 +	inline void SetReserved(TInt aValue)
   1.769 +		{
   1.770 +		i[3] = (TUint8)aValue;
   1.771 +		i[2] = (TUint8)(aValue >> 8);
   1.772 +		}
   1.773 +	inline void SetSequence(TUint32 aSeq)
   1.774 +		{
   1.775 +		i[11] = (TUint8)aSeq;
   1.776 +		i[10] = (TUint8)(aSeq >> 8);
   1.777 +		i[9] = (TUint8)(aSeq >> 16);
   1.778 +		i[8] = (TUint8)(aSeq >> 24);
   1.779 +		}
   1.780 +protected:
   1.781 +	union
   1.782 +		{
   1.783 +		TUint8 i[3*4];
   1.784 +		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   1.785 +		};
   1.786 +	};
   1.787 +
   1.788 +
   1.789 +
   1.790 +class TInet6HeaderESP
   1.791 +	/**
   1.792 +	* IPsec Encapsulating Security Payload Packet Format.
   1.793 +	*
   1.794 +	* The function parameters and return values are in host
   1.795 +	* order (except SPI, which is always in network byte order)
   1.796 +	*
   1.797 +@verbatim
   1.798 +RFC-2406
   1.799 + 0                   1                   2                   3
   1.800 + 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
   1.801 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ----
   1.802 +|               Security Parameters Index (SPI)                 | ^Auth.
   1.803 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Cov-
   1.804 +|                      Sequence Number                          | |erage
   1.805 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ----
   1.806 +|                    Payload Data* (variable)                   | |   ^
   1.807 +~                                                               ~ |   |
   1.808 +|                                                               | |Conf.
   1.809 ++               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Cov-
   1.810 +|               |     Padding (0-255 bytes)                     | |erage*
   1.811 ++-+-+-+-+-+-+-+-+               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |   |
   1.812 +|                               |  Pad Length   | Next Header   | v   v
   1.813 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ------
   1.814 +|                 Authentication Data (variable)                |
   1.815 +~                                                               ~
   1.816 +|                                                               |
   1.817 ++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1.818 +@endverbatim
   1.819 +	* This only defines the fixed portion of the ESP, 8 bytes).
   1.820 +	* @publishedAll
   1.821 +	* @released
   1.822 +	*/
   1.823 +	{
   1.824 +public:
   1.825 +	//
   1.826 +	// Basic
   1.827 +	//
   1.828 +	inline static TInt MinHeaderLength() {return 2*4; }
   1.829 +	inline static TInt MaxHeaderLength() {return 2*4; }
   1.830 +	inline TInt HeaderLength() const {return 2*4; }
   1.831 +	inline TUint8 *EndPtr() {return i + HeaderLength();}
   1.832 +
   1.833 +	//
   1.834 +	// Access, get values
   1.835 +	//
   1.836 +	//
   1.837 +	// SPI is returned in network byte order
   1.838 +	//
   1.839 +	inline TUint32 SPI() const
   1.840 +		{
   1.841 +		return *((TUint32 *)(i + 0));
   1.842 +		}
   1.843 +	inline TUint32 Sequence() const
   1.844 +		{
   1.845 +		return (i[4] << 24) | (i[5] << 16) | (i[6] << 8) | i[7];
   1.846 +		}
   1.847 +	//
   1.848 +	// IV is not exactly part of the header, but provide
   1.849 +	// a method that returns a Ptr to it (assuming the
   1.850 +	// IV is accessible directly after the fixed part).
   1.851 +	//
   1.852 +	inline TPtr8 IV(TInt aLen)
   1.853 +		{
   1.854 +		return TPtr8((TUint8 *)&i[sizeof(i)], aLen, aLen);
   1.855 +		}
   1.856 +
   1.857 +	//
   1.858 +	// Build
   1.859 +	//
   1.860 +	inline void SetSPI(TUint32 aSPI)
   1.861 +		{
   1.862 +		*((TUint32 *)(i + 0)) = aSPI;
   1.863 +		}
   1.864 +	inline void SetSequence(TUint32 aSeq)
   1.865 +		{
   1.866 +		i[7] = (TUint8)aSeq;
   1.867 +		i[6] = (TUint8)(aSeq >> 8);
   1.868 +		i[5] = (TUint8)(aSeq >> 16);
   1.869 +		i[4] = (TUint8)(aSeq >> 24);
   1.870 +		}
   1.871 +protected:
   1.872 +	union
   1.873 +		{
   1.874 +		TUint8 i[2*4];
   1.875 +		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
   1.876 +		};
   1.877 +	};
   1.878 +
   1.879 +/** @} */
   1.880 +#endif