williamr@2: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@2: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // in_pkt.h - packet handling routines williamr@2: // Generic packet handling utility for mapping packet handling to the RMBufChain. williamr@2: // williamr@2: williamr@2: williamr@2: williamr@2: /** williamr@2: @file in_pkt.h williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: williamr@2: #ifndef __IN_PKT_H__ williamr@2: #define __IN_PKT_H__ williamr@2: williamr@2: #include "ip6_hdr.h" // ..should eventually be ? -- msa williamr@2: #include "ip4_hdr.h" williamr@4: class RMBufChain; williamr@2: williamr@4: williamr@4: #define TPACKETHEAD_FRAGMENT 1 //< Enable iFragment in TPacketHead williamr@2: williamr@2: /** williamr@2: TScopeType is only provided so that "magic" constants can be williamr@2: avoided in the source code. However, the max value cannot be changed williamr@2: to anything from 0xF. The scope type is assumed to be 4 bits long williamr@2: in many occasions. williamr@2: williamr@2: The value of the scope type is directly bound the the IPv6 Scope williamr@2: level - 1. This can be done, as IPv6 Scope level 0 is not legal williamr@2: (or usable) in any context within the stack. williamr@2: This allows our non-standard network scope (= 0x10) to williamr@2: be coded internally in 4 bits (as 0xF). williamr@2: williamr@2: @publishedAll williamr@2: @released williamr@2: @since v7.0s williamr@2: */ williamr@2: enum TScopeType williamr@2: { williamr@4: EScopeType_IF = 0x0, //< (= #KIp6AddrScopeNodeLocal - 1), id is interface index williamr@4: EScopeType_IAP = 0x1, //< (= #KIp6AddrScopeLinkLocal - 1). id is IAP number williamr@4: EScopeType_GLOBAL = 0xD,//< (= #KIp6AddrScopeGlobal - 1). id is global scope id williamr@2: // williamr@2: // no symbols defined for types 2..14 (they are also valid) williamr@2: // williamr@4: EScopeType_NET = 0xF //< (= #KIp6AddrScopeNetwork - 1), id is network number (must be the last entry) williamr@2: }; williamr@2: williamr@2: // williamr@2: // TIpHeader williamr@2: // ********* williamr@2: class TIpHeader williamr@2: /** williamr@2: A simple help class that uses a union to merge handling of either an IPv4 or williamr@2: an IPv6 header. williamr@2: @since v7.0 williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: /** williamr@2: Gets the minimum header length. williamr@2: williamr@2: IPv6 header is longer than minimum IPv4 header, thus williamr@2: returned value is for IPv4. This function only defined williamr@2: because it is required when this class is used as template williamr@2: parameter in TInet6Packet. williamr@2: williamr@2: @return Minimum IPv4 header length williamr@2: */ williamr@2: inline static TInt MinHeaderLength() {return TInet6HeaderIP4::MinHeaderLength(); } williamr@2: /** williamr@2: Gets the maximum header length. williamr@2: williamr@2: IPv6 header always shorter than maximum IPv4 header, thus williamr@2: returned value is for IPv4. This function is only defined williamr@2: because "header mapping" classes are expected to have it. williamr@2: williamr@2: @return Maximum IPv4 header length williamr@2: */ williamr@2: inline static TInt MaxHeaderLength() {return TInet6HeaderIP4::MaxHeaderLength(); } williamr@2: williamr@2: union williamr@2: { williamr@2: TInet6HeaderIP4 ip4; williamr@2: TInet6HeaderIP ip6; williamr@2: }; williamr@2: }; williamr@2: williamr@2: williamr@2: williamr@2: class TInet6PacketBase williamr@2: /** williamr@2: * Thin base class for the TInet6Packet. williamr@2: */ williamr@2: { williamr@2: public: williamr@2: enum TAlign williamr@2: { williamr@4: EAlign1 = 0, //< Align to byte (no align requirement) williamr@4: EAlign2 = 1, //< Align to 2 byte unit (even address) williamr@4: EAlign4 = 3, //< Align to 4 byte unit williamr@4: EAlign8 = 7 //< Align to 8 byte unit williamr@2: }; williamr@2: williamr@2: /** williamr@2: Constructor. williamr@2: williamr@2: @param aAlign The align requirement. williamr@2: */ williamr@2: TInet6PacketBase(TAlign aAlign) : iLength(0), iAlign(aAlign) {} williamr@2: williamr@2: /** williamr@2: Length of the mapped region. williamr@2: williamr@2: The real mapped length as computed by the Access function. williamr@2: If access returned non-NULL, the following is always TRUE: williamr@2: williamr@2: @li aMin <= iLength williamr@2: */ williamr@2: TInt iLength; williamr@2: williamr@2: IMPORT_C TUint8 *Access(RMBufChain &aPacket, TInt aOffset, TInt aSize, TInt aMin); williamr@2: williamr@2: inline void SetAlign(TAlign aAlign) williamr@2: /** williamr@2: * Changes the align requirement. williamr@2: * williamr@2: * @param aAlign The new align requirement. williamr@2: */ williamr@2: { williamr@2: iAlign = aAlign; williamr@2: } williamr@2: protected: williamr@2: /** williamr@2: The align requirement. williamr@2: */ williamr@2: TAlign iAlign; williamr@2: }; williamr@2: williamr@2: // TInet6Packet template williamr@2: // ********************* williamr@2: template williamr@2: class TInet6Packet : public TInet6PacketBase williamr@2: /** williamr@2: Encapsulates an IPv6 packet header as a section of an RMBufChain. williamr@2: williamr@2: The T template parameter should represent a packet header type. It should williamr@2: support static functions MaxHeaderLength() and MinHeaderLength() that return williamr@2: TInt values for maximum and minimum header lengths respectively. williamr@2: williamr@2: @publishedAll williamr@2: @released williamr@2: @since v7.0 williamr@2: */ williamr@2: { williamr@2: public: williamr@2: TInet6Packet(TAlign aAlign = EAlign4) : TInet6PacketBase(aAlign), iHdr(NULL) williamr@2: /** williamr@2: Default constructor. williamr@2: williamr@2: Construct an empty mapping. To be usable, the Set() function williamr@2: must be used. williamr@2: */ williamr@2: {} williamr@2: TInet6Packet(RMBufChain &aPacket) : TInet6PacketBase(EAlign4) williamr@2: /** williamr@2: Constructor specifying a RMBufChain object. williamr@2: williamr@2: Verify and arrange it so that a class T can be mapped williamr@2: to a contiguous octets from the beginning of the RMBufChain williamr@2: content, and set iHdr to point this area. williamr@2: williamr@2: If this is not possible, iHdr is initialized to NULL. williamr@2: williamr@2: @param aPacket williamr@2: Packet containing the header T at offset = 0 williamr@2: */ williamr@2: { williamr@2: iHdr = (T *)Access(aPacket, 0, T::MaxHeaderLength(), T::MinHeaderLength()); williamr@2: } williamr@2: williamr@2: TInet6Packet(RMBufChain &aPacket, TInt aOffset, TAlign aAlign = EAlign4) : TInet6PacketBase(aAlign) williamr@2: /** williamr@2: Constructor specifying a RMBufChain object and an offset. williamr@2: williamr@2: Verify and arrange it so that a class T can be mapped williamr@2: to a contiguous octets starting at specified offset of williamr@2: the RMBufChain content, and set iHdr to point this area. williamr@2: williamr@2: If this is not possible, iHdr is initialized to NULL. williamr@2: williamr@2: @param aPacket williamr@2: Packet containing the header T at aOffset williamr@2: @param aOffset williamr@2: Offset of the header to be mapped. williamr@2: @param aAlign williamr@2: The alignement requirement. williamr@2: */ williamr@2: { williamr@2: iHdr = (T *)Access(aPacket, aOffset, T::MaxHeaderLength(), T::MinHeaderLength()); williamr@2: } williamr@2: williamr@2: void Set(RMBufChain &aPacket, TInt aOffset, TInt aSize) williamr@2: /** williamr@2: Sets the packet header from a specified RMBufChain object. williamr@2: williamr@2: Verify and arrange it so that a aSize octets can be mapped williamr@2: to a contiguous octets starting at specified offset of williamr@2: the RMBufChain content, and set iHdr to point this area. williamr@2: williamr@2: If this is not possible, iHdr is initialized to NULL. williamr@2: williamr@2: Note that this differs from the contructors: the required williamr@2: size is a parameter, and not determined by the T::MinHeaderLength(). williamr@2: However, the "T* iHdr" is set to point the start of the requested williamr@2: area. It's a responsibility of the user of this method to know williamr@2: whether using this pointer is safe with the specified size parameter. williamr@2: williamr@2: @param aPacket williamr@2: Packet containing the header T at aOffset williamr@2: @param aOffset williamr@2: Offset (position) of the header to be mapped williamr@2: @param aSize williamr@2: Length of required contiguous memory williamr@2: */ williamr@2: { williamr@2: iHdr = (T *)Access(aPacket, aOffset, aSize, aSize); williamr@2: } williamr@2: williamr@2: inline T& operator()() williamr@2: { williamr@2: return *iHdr; williamr@2: } williamr@2: /** williamr@2: The pointer to the mapped region (if non-NULL). If NULL, williamr@2: then there is no mapping, and iLength == 0. williamr@2: */ williamr@2: T *iHdr; williamr@2: }; williamr@2: williamr@2: williamr@2: #endif