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