epoc32/include/in_pkt.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 // in_pkt.h - packet handling routines
    15 // Generic packet handling utility for mapping packet handling to the RMBufChain.
    16 //
    17 
    18 
    19 
    20 /**
    21  @file in_pkt.h
    22  @publishedAll
    23  @released
    24 */
    25 
    26 #ifndef __IN_PKT_H__
    27 #define __IN_PKT_H__
    28 
    29 #include "ip6_hdr.h"	// ..should eventually be <inet/ip6_hdr.h>? -- msa
    30 #include "ip4_hdr.h"
    31 class RMBufChain;
    32 
    33 
    34 #define TPACKETHEAD_FRAGMENT	1	//< Enable iFragment in TPacketHead
    35 
    36 /**
    37  TScopeType is only provided so that "magic" constants can be
    38  avoided in the source code. However, the max value cannot be changed
    39  to anything from 0xF. The scope type is assumed to be 4 bits long
    40  in many occasions.
    41 
    42  The value of the scope type is directly bound the the IPv6 Scope
    43  level - 1. This can be done, as IPv6 Scope level 0 is not legal
    44  (or usable) in any context within the stack.
    45  This allows our non-standard network scope (= 0x10) to
    46  be coded internally in 4 bits (as 0xF).
    47 
    48  @publishedAll
    49  @released
    50  @since v7.0s
    51 */
    52 enum TScopeType
    53 	{
    54 	EScopeType_IF	= 0x0,	//< (= #KIp6AddrScopeNodeLocal - 1), id is interface index
    55 	EScopeType_IAP	= 0x1,	//< (= #KIp6AddrScopeLinkLocal - 1). id is IAP number
    56 	EScopeType_GLOBAL = 0xD,//< (= #KIp6AddrScopeGlobal - 1). id is global scope id
    57 	//
    58 	// no symbols defined for types 2..14 (they are also valid)
    59 	//
    60 	EScopeType_NET	= 0xF	//< (= #KIp6AddrScopeNetwork - 1), id is network number (must be the last entry)
    61 	};
    62 
    63 //
    64 //	TIpHeader
    65 //	*********
    66 class TIpHeader
    67 	/**
    68 	A simple help class that uses a union to merge handling of either an IPv4 or 
    69 	an IPv6 header. 
    70 	@since v7.0
    71 	@publishedAll
    72 	@released
    73 	*/
    74 	{
    75 public:
    76 	/**
    77 	Gets the minimum header length.
    78 
    79 	IPv6 header is longer than minimum IPv4 header, thus
    80 	returned value is for IPv4. This function only defined
    81 	because it is required when this class is used as template
    82 	parameter in TInet6Packet.
    83 	
    84 	@return Minimum IPv4 header length
    85 	*/
    86 	inline static TInt MinHeaderLength() {return TInet6HeaderIP4::MinHeaderLength(); }
    87 	/**
    88 	Gets the maximum header length.
    89 
    90 	IPv6 header always shorter than maximum IPv4 header, thus
    91 	returned value is for IPv4. This function is only defined
    92 	because "header mapping" classes are expected to have it.
    93 	
    94 	@return Maximum IPv4 header length
    95 	*/
    96 	inline static TInt MaxHeaderLength() {return TInet6HeaderIP4::MaxHeaderLength(); }
    97 
    98 	union
    99 		{
   100 		TInet6HeaderIP4 ip4;
   101 		TInet6HeaderIP ip6;
   102 		};
   103 	};
   104 
   105 
   106 
   107 class TInet6PacketBase
   108 	/**
   109 	* Thin base class for the TInet6Packet.
   110 	*/
   111 	{
   112 public:
   113 	enum TAlign
   114 		{
   115 		EAlign1 = 0,	//< Align to byte (no align requirement)
   116 		EAlign2 = 1,	//< Align to 2 byte unit (even address)
   117 		EAlign4 = 3,	//< Align to 4 byte unit
   118 		EAlign8 = 7		//< Align to 8 byte unit
   119 		};
   120 
   121 	/**
   122 	Constructor.
   123 
   124 	@param aAlign	The align requirement.
   125 	*/
   126 	TInet6PacketBase(TAlign aAlign) : iLength(0), iAlign(aAlign) {}
   127 
   128 	/**
   129 	Length of the mapped region.
   130 
   131 	The real mapped length as computed by the Access function.
   132 	If access returned non-NULL, the following is always TRUE:
   133 
   134 	@li	aMin <= iLength
   135 	*/
   136 	TInt iLength;
   137 
   138 	IMPORT_C TUint8 *Access(RMBufChain &aPacket, TInt aOffset, TInt aSize, TInt aMin);
   139 
   140 	inline void SetAlign(TAlign aAlign)
   141 		/**
   142 		* Changes the align requirement.
   143 		*
   144 		* @param aAlign The new align requirement.
   145 		*/
   146 		{
   147 		iAlign = aAlign;
   148 		}
   149 protected:
   150 	/**
   151 	The align requirement.
   152 	*/
   153 	TAlign iAlign;
   154 	};
   155 
   156 // TInet6Packet template
   157 // *********************
   158 template <class T>
   159 class TInet6Packet : public TInet6PacketBase
   160 	/**
   161 	Encapsulates an IPv6 packet header as a section of an RMBufChain.
   162 
   163 	The T template parameter should represent a packet header type. It should 
   164 	support static functions MaxHeaderLength() and MinHeaderLength() that return 
   165 	TInt values for maximum and minimum header lengths respectively.
   166 
   167 	@publishedAll
   168 	@released
   169 	@since v7.0
   170 	*/
   171 	{
   172 public:
   173 	TInet6Packet(TAlign aAlign = EAlign4) : TInet6PacketBase(aAlign), iHdr(NULL)
   174 		/**
   175 		Default constructor.
   176 
   177 		Construct an empty mapping. To be usable, the Set() function
   178 		must be used.
   179 		*/
   180 		{}
   181 	TInet6Packet(RMBufChain &aPacket) : TInet6PacketBase(EAlign4)
   182 		/**
   183 		Constructor specifying a RMBufChain object.
   184 
   185 		Verify and arrange it so that a class T can be mapped
   186 		to a contiguous octets from the beginning of the RMBufChain
   187 		content, and set iHdr to point this area.
   188 
   189 		If this is not possible, iHdr is initialized to NULL.
   190 
   191 		@param	aPacket
   192 			Packet containing the header T at offset = 0
   193 		*/
   194 		{
   195 		iHdr = (T *)Access(aPacket, 0, T::MaxHeaderLength(), T::MinHeaderLength());
   196 		}
   197 
   198 	TInet6Packet(RMBufChain &aPacket, TInt aOffset, TAlign aAlign = EAlign4) : TInet6PacketBase(aAlign)
   199 		/**
   200 		Constructor specifying a RMBufChain object and an offset.
   201 
   202 		Verify and arrange it so that a class T can be mapped
   203 		to a contiguous octets starting at specified offset of
   204 		the RMBufChain content, and set iHdr to point this area.
   205 
   206 		If this is not possible, iHdr is initialized to NULL.
   207 
   208 		@param aPacket
   209 			Packet containing the header T at aOffset
   210 		@param aOffset
   211 			Offset of the header to be mapped.
   212 		@param aAlign
   213 			The alignement requirement.
   214 		*/
   215 		{
   216 		iHdr = (T *)Access(aPacket, aOffset, T::MaxHeaderLength(), T::MinHeaderLength());
   217 		}
   218 
   219 	void Set(RMBufChain &aPacket, TInt aOffset, TInt aSize)
   220 		/**
   221 		Sets the packet header from a specified RMBufChain object.
   222 
   223 		Verify and arrange it so that a aSize octets can be mapped
   224 		to a contiguous octets starting at specified offset of
   225 		the RMBufChain content, and set iHdr to point this area.
   226 
   227 		If this is not possible, iHdr is initialized to NULL.
   228 
   229 		Note that this differs from the contructors: the required
   230 		size is a parameter, and not determined by the T::MinHeaderLength().
   231 		However, the "T* iHdr" is set to point the start of the requested
   232 		area. It's a responsibility of the user of this method to know
   233 		whether using this pointer is safe with the specified size parameter.
   234 
   235 		@param	aPacket
   236 			Packet containing the header T at aOffset
   237 		@param	aOffset
   238 			Offset (position) of the header to be mapped
   239 		@param	aSize
   240 			Length of required contiguous memory
   241 		*/
   242 		{
   243 		iHdr = (T *)Access(aPacket, aOffset, aSize, aSize);
   244 		}
   245 
   246 	inline T& operator()()
   247 		{
   248 		return *iHdr;
   249 		}
   250 	/**
   251 	The pointer to the mapped region (if non-NULL). If NULL,
   252 	then there is no mapping, and iLength == 0.
   253 	*/
   254 	T *iHdr;
   255 	};
   256 
   257 
   258 #endif