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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // in_pkt.h - packet handling routines
15 // Generic packet handling utility for mapping packet handling to the RMBufChain.
29 #include "ip6_hdr.h" // ..should eventually be <inet/ip6_hdr.h>? -- msa
34 #define TPACKETHEAD_FRAGMENT 1 //< Enable iFragment in TPacketHead
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
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).
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
58 // no symbols defined for types 2..14 (they are also valid)
60 EScopeType_NET = 0xF //< (= #KIp6AddrScopeNetwork - 1), id is network number (must be the last entry)
68 A simple help class that uses a union to merge handling of either an IPv4 or
77 Gets the minimum header length.
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.
84 @return Minimum IPv4 header length
86 inline static TInt MinHeaderLength() {return TInet6HeaderIP4::MinHeaderLength(); }
88 Gets the maximum header length.
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.
94 @return Maximum IPv4 header length
96 inline static TInt MaxHeaderLength() {return TInet6HeaderIP4::MaxHeaderLength(); }
107 class TInet6PacketBase
109 * Thin base class for the TInet6Packet.
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
124 @param aAlign The align requirement.
126 TInet6PacketBase(TAlign aAlign) : iLength(0), iAlign(aAlign) {}
129 Length of the mapped region.
131 The real mapped length as computed by the Access function.
132 If access returned non-NULL, the following is always TRUE:
138 IMPORT_C TUint8 *Access(RMBufChain &aPacket, TInt aOffset, TInt aSize, TInt aMin);
140 inline void SetAlign(TAlign aAlign)
142 * Changes the align requirement.
144 * @param aAlign The new align requirement.
151 The align requirement.
156 // TInet6Packet template
157 // *********************
159 class TInet6Packet : public TInet6PacketBase
161 Encapsulates an IPv6 packet header as a section of an RMBufChain.
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.
173 TInet6Packet(TAlign aAlign = EAlign4) : TInet6PacketBase(aAlign), iHdr(NULL)
177 Construct an empty mapping. To be usable, the Set() function
181 TInet6Packet(RMBufChain &aPacket) : TInet6PacketBase(EAlign4)
183 Constructor specifying a RMBufChain object.
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.
189 If this is not possible, iHdr is initialized to NULL.
192 Packet containing the header T at offset = 0
195 iHdr = (T *)Access(aPacket, 0, T::MaxHeaderLength(), T::MinHeaderLength());
198 TInet6Packet(RMBufChain &aPacket, TInt aOffset, TAlign aAlign = EAlign4) : TInet6PacketBase(aAlign)
200 Constructor specifying a RMBufChain object and an offset.
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.
206 If this is not possible, iHdr is initialized to NULL.
209 Packet containing the header T at aOffset
211 Offset of the header to be mapped.
213 The alignement requirement.
216 iHdr = (T *)Access(aPacket, aOffset, T::MaxHeaderLength(), T::MinHeaderLength());
219 void Set(RMBufChain &aPacket, TInt aOffset, TInt aSize)
221 Sets the packet header from a specified RMBufChain object.
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.
227 If this is not possible, iHdr is initialized to NULL.
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.
236 Packet containing the header T at aOffset
238 Offset (position) of the header to be mapped
240 Length of required contiguous memory
243 iHdr = (T *)Access(aPacket, aOffset, aSize, aSize);
246 inline T& operator()()
251 The pointer to the mapped region (if non-NULL). If NULL,
252 then there is no mapping, and iLength == 0.