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@2: // 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 williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.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 williamr@2: #include "ip6_hdr.h" // ..should eventually be ? -- msa williamr@2: #include "ip4_hdr.h" williamr@2: williamr@2: #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@2: EScopeType_IF = 0x0, ///< (= #KIp6AddrScopeNodeLocal - 1), id is interface index williamr@2: EScopeType_IAP = 0x1, ///< (= #KIp6AddrScopeLinkLocal - 1). id is IAP number williamr@2: 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@2: 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: // RMBufPacketPeek williamr@2: // *************** williamr@2: class RMBufPacketPeek : public RMBufChain williamr@2: /** williamr@2: Extends RMBufChain to add functions to read packet data as a descriptor williamr@2: and as an IP header. williamr@2: williamr@2: The RMBufChain is assumed to contain the raw packet, without williamr@2: the info block prepended (e.g. if this class is used for RMBufPacketBase williamr@2: derived handle, it must be in "unpacked" state). williamr@2: williamr@2: @since v7.0 williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TPtr8 Access(TInt aSize, TUint aOffset = 0); williamr@2: IMPORT_C TIpHeader *GetIpHeader(); williamr@2: }; williamr@2: williamr@2: // TPacketHead williamr@2: // *********** williamr@2: class TPacketHead williamr@2: /** williamr@2: Storage for some precomputed information for an outbound packet flow. williamr@2: williamr@2: The outbound TPacketHead is part of the flow context (CFlowContext). williamr@2: williamr@2: The CFlowContext::Connect initializes the content from the parameters williamr@2: of the flow (TFlowInfo) and runs the connection process.. The connection williamr@2: process (MIp6Hook::OpenL and MFlowHook::ReadyL phases) completes the williamr@2: information. After this, as long as the flow is connected, the content williamr@2: is mostly frozen and must not be modified by anyone. williamr@2: williamr@2: When there is a need to change any flow information, the changes must williamr@2: be done to the flow parameters (and not to TPacketHead). The change of williamr@2: flow parameters also sets the CFlowContext::iChanged flag, and this williamr@2: eventually causes a new CFlowContext::Connect, which re-initializes williamr@2: the TPacketHead with the new information. williamr@2: williamr@2: For each field in the TPacketHead, the hook writer must follow the williamr@2: basic rule (only for fields that it intends to change): williamr@2: williamr@2: - if some field is changed in MIp6Hook::OpenL, then the previous williamr@2: value should be restored in the MFlowHook::ReadyL. williamr@2: - an exeception: the hook must omit the restore, if the williamr@2: previous value was unspecified value (for example, the source williamr@2: address). williamr@2: - the content of #iPacket (and #iOffset) are special: they cannot williamr@2: be modified in the MIp6Hook::OpenL phase. A hook can williamr@2: modify them only in the MFlowHook::ReadyL phase. And, if the hook williamr@2: is adding an IP header for tunneling, it must save the current content williamr@2: of these fields in the ReadyL function, and then clear out the fields williamr@2: (it must make the iPacket empty and zero iOffset). The hook must add williamr@2: the saved iPacket content below the added tunnel header in williamr@2: MFlowHook::ApplyL . williamr@2: williamr@2: @since v7.0 williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TBool ExtHdrGet(TInt aType, TInt& aOfs, TInt& aLen); williamr@2: IMPORT_C TBool ExtHdrGetOrPrependL(TInt aType, TInt& aOfs, TInt& aLen); williamr@2: IMPORT_C TBool ExtHdrGetOrAppendL(TInt aType, TInt& aOfs, TInt& aLen); williamr@2: IMPORT_C void AddDestinationOptionL(const TPtrC8& aOption, TUint8 aAlign=0, TUint8 aModulo=4); williamr@2: IMPORT_C void AddDestinationOptionL(const TUint8* aOption, TUint8 aLen, TUint8 aAlign=0, TUint8 aModulo=4); williamr@2: williamr@2: public: williamr@2: /** williamr@2: "Virtual" IP header. The IPv6 header stucture is used, but the same williamr@2: format is also used for the IPv4 destinations (Version() == 4, williamr@2: even though the header format is still IPv6!) williamr@2: williamr@2: This header is initialized in the beginning of the OpenL phase williamr@2: as follows: williamr@2: @li Version = 0 williamr@2: @li Traffic Class, copied from the flow iOptions.iTrafficClass williamr@2: @li Flow Label = 0 williamr@2: @li Payload Length = 0 (dummy field, not used) williamr@2: @li Next Header, copied from the flow iProtocol williamr@2: @li Hop Limit, copied from the flow iOptions.iHopLimit williamr@2: @li Src Address, copied from the flow Local Address (usually unspecified) williamr@2: @li Dst Address, copied from the flow Remote Address williamr@2: williamr@2: At beginning of the ReadyL phase (= at end of OpenL), the destination williamr@2: address (and iDstId) are used to find a route on the interface. Depending williamr@2: on whether this address is IPv4 (mapped) or IPv6, the Version field is set williamr@2: accordingly to either 4 or 6. williamr@2: williamr@2: After succesfull completion of the ReadyL, this used for *each* packet williamr@2: which needs an IP header to be generated on send. The Version() determines williamr@2: whether IPv4 or IPv6 frame is to be generated (this is the initial williamr@2: header in the packet, *before* running outbound ApplyL hooks): williamr@2: williamr@2: @verbatim williamr@2: IPv6 IPv4 williamr@2: Version == 6 ==4 williamr@2: Traffic Class used as is used as TOS williamr@2: Flow Label used as is ignored williamr@2: Payload Length ignored ignored williamr@2: Next Header used as is used as Protocol williamr@2: Hop Limit used as is used as TTL williamr@2: Src Address used as is used as IPv4 mapped williamr@2: Dst Address used as is used as IPv4 mapped williamr@2: @endverbatim williamr@2: */ williamr@2: TInet6HeaderIP ip6; williamr@2: /** williamr@2: Contains the scope id associated with the destination address williamr@2: which is stored in #ip6 Dst Address. This id and address must williamr@2: always be considered as a unit. Logically, any change changes williamr@2: both values. williamr@2: williamr@2: iDstId is initialized from the flow context TFlowInfo::iRemote.Scope() at williamr@2: beginning of the flow connect phase. If application does not define williamr@2: this scope id, then the system will attempt to choose a default value williamr@2: at beginning of the connect phase. If the default cannot be determined, williamr@2: the flow is put into pending state (and no connect happens). williamr@2: williamr@2: @par MIp6Hook::OpenL williamr@2: On entry to the OpenL, the iDstId is always non-zero and destination williamr@2: address is specified. If a hook changes the destination address in williamr@2: OpenL method, it must provide the correct id value williamr@2: which goes with the new destination. If it cannot do this, it williamr@2: must either abort the connect by leaving with an error state, or it williamr@2: can leave with PENDING (> 0) status to signal there is no route williamr@2: for the new destination. williamr@2: If the stack cannot find suitable interface for the destination, then williamr@2: it aborts the connect phase, and the flow is placed into holding state. williamr@2: williamr@2: @note williamr@2: Only a tunneling hook can safely change the destination williamr@2: address (a use of routing header can also be a kind of williamr@2: tunneling). williamr@2: williamr@2: @par MFlowHook::ReadyL williamr@2: If the hook changed the destination address (or id) in the OpenL, williamr@2: the ReadyL must restore the original values back. williamr@2: williamr@2: */ williamr@2: TUint32 iDstId; williamr@2: /** williamr@2: Contains the scope id associated with the source address williamr@2: which is stored in #ip6 Src address. This is defined when the source williamr@2: address is defined, and otherwise undefined. williamr@2: williamr@2: iSrcId is initialized from TFlowInfo::iLocal.Scope() at beginning of the williamr@2: flow connect phase. If application defines the source address, williamr@2: but does not specify this scope id, then the system chooses williamr@2: the id based on the interface defined by the source address. williamr@2: If scope and address are both specified, they must match the williamr@2: selected interface. williamr@2: williamr@2: @par MIp6Hook::OpenL williamr@2: On entry to the OpenL, the iSrcId (and source address) may be williamr@2: undefined (#iSourceSet = 0). If defined (iSourceSet = 1), then williamr@2: both address and iSrcId are defined (iSrcId != 0). A hook may williamr@2: force a reselection of the source just by zeroing the williamr@2: iSourceSet. williamr@2: williamr@2: @par MFlowHook::ReadyL williamr@2: If the hook changed the source address (or id) in the OpenL, williamr@2: the ReadyL must restore the original values back, but only williamr@2: if the original value was defined (#iSourceSet = 1 in OpenL). williamr@2: */ williamr@2: TUint32 iSrcId; williamr@2: /** williamr@2: The source address has been set. williamr@2: williamr@2: This bit indicates whether the value stored in #ip6 src field williamr@2: and #iSrcId is to be used as a source address as is. williamr@2: williamr@2: Initialized from TFlowInfo::iLocalSet, which tells whether user williamr@2: specified tbe source address or not (e.g used RSocket Bind method). williamr@2: The stack checks the value after each MIp6Hook::OpenL call, and williamr@2: if the flag is set, the source in ip6 is used as is. If the flag williamr@2: is zero, then the stack performs the normal source address selection williamr@2: based on the current destination address (#iSrcId and destination williamr@2: address). williamr@2: williamr@2: @par MIp6Hook::OpenL williamr@2: On entry, this flag is always set and source address is defined. williamr@2: A hook may clear this flag, if it wants the williamr@2: stack choose the source address based on current destination. williamr@2: The clearing operation is normally needed only by a tunneling williamr@2: hook. williamr@2: williamr@2: @note williamr@2: If the hook specifies the source address, it must be either williamr@2: a valid source address for the interface or unspecified williamr@2: address. williamr@2: williamr@2: @par MFlowHook::ReadyL williamr@2: Upon entry to the ReadyL, the source address is always fully williamr@2: known (the hook can assume that #iSrcId and the #ip6 source williamr@2: addresses are valid). williamr@2: If the source address was set before the OpenL, then this williamr@2: must restore the original value (along with the #iSrcId williamr@2: and source address). williamr@2: */ williamr@2: TUint iSourceSet:1; williamr@2: #ifdef TPACKETHEAD_FRAGMENT williamr@2: /** williamr@2: The fragment processing alredy done. williamr@2: williamr@2: This bit is meaningful only in OpenL phase. If already set, williamr@2: then some ealier hook has requested that the packet must williamr@2: be fragmented to fit the mtu. williamr@2: williamr@2: A tunneling hook can set this bit in OpenL, if it needs williamr@2: the fragmenting to happen before the ApplyL is called (e.g. williamr@2: the fragments are tunneled instead of fragmenting the williamr@2: tunneling). williamr@2: williamr@2: This bit can only be set or left as is. It cannot be cleared williamr@2: once set. williamr@2: */ williamr@2: TUint iFragment:1; williamr@2: #endif williamr@2: /** williamr@2: Selector info, the upper layer protocol. williamr@2: williamr@2: iProtocol has the same value as ip6.NextHeader() when iPacket is empty, williamr@2: and otherwise it is the same as NextHeader() of the last extension williamr@2: header in the iPacket. williamr@2: williamr@2: The values of the other selector fields: #iIcmpType, #iIcmpCode williamr@2: #iSrcPort and #iDstPort depend on iProtocol. Whenever iProtocol williamr@2: is changed, the other fields must be updated accordingly. williamr@2: williamr@2: @par MIp6Hook::OpenL williamr@2: Because iPacket cannot be modified during the OpenL phase, the williamr@2: content of this field and the Next Header (protocol) field in williamr@2: the #ip6 pseudoheader must always be the same. This field should williamr@2: be considered as read-only, unless the hook intends to williamr@2: apply IP-in-IP tunneling, in which case the hook must williamr@2: change the value to the appropriate tunneling protocol williamr@2: (#KProtocolInet6Ipip or #KProtocolInetIpip). williamr@2: williamr@2: @par MFlowHook::ReadyL williamr@2: Only a tunneling hook needs to restore the value here to match williamr@2: the original upper layer protocol. See #iPacket for williamr@2: more detailed information. williamr@2: */ williamr@2: TUint8 iProtocol; williamr@2: /** williamr@2: Selector field whose value depends on #iProtocol. williamr@2: williamr@2: If this field does not have meaning with the protocol, williamr@2: the field content should be set to ZERO. williamr@2: */ williamr@2: TUint8 iIcmpType; williamr@2: /** williamr@2: Selector field whose value depends on #iProtocol. williamr@2: williamr@2: If this field does not have meaning with the protocol, williamr@2: the field content should be set to ZERO. williamr@2: */ williamr@2: TUint8 iIcmpCode; williamr@2: /** williamr@2: Selector field whose value depends on #iProtocol. williamr@2: williamr@2: If this field does not have meaning with the protocol, williamr@2: the field content should be set to ZERO. williamr@2: */ williamr@2: TUint16 iSrcPort; williamr@2: /** williamr@2: Selector field whose value depends on #iProtocol. williamr@2: williamr@2: If this field does not have meaning with the protocol, williamr@2: the field content should be set to ZERO. williamr@2: */ williamr@2: TUint16 iDstPort; williamr@2: /** williamr@2: The amount of pre-computed IPv6 extension headers in iPacket which williamr@2: are copied to the beginning of each outgoing packet williamr@2: williamr@2: If iOffset > 0, then #iPacket includes that much of extension williamr@2: headers that are copied in front of each packet. williamr@2: */ williamr@2: TInt iOffset; williamr@2: /** williamr@2: Pre-computed extension headers for all packets in this flow. williamr@2: williamr@2: These can only be added in the ReadyL phase. If any of the williamr@2: ReadyL's adds extension headers into this, it must take care williamr@2: of maintaining the correct Next Header in the virtual IP header williamr@2: (and the original upper layer protocol must be placed in the williamr@2: next header of the last extension header added. williamr@2: williamr@2: Stack copies the content of this to each outgoing packet, just below williamr@2: the IP header, before running the ApplyL functions of the outbound williamr@2: flow hooks. williamr@2: williamr@2: @par MIp6Hook::OpenL williamr@2: The iPacket must not be modified during the OpenL phase. williamr@2: williamr@2: @par MFlowHook::ReadyL williamr@2: A non-tunneling hook may add extension headers into the current williamr@2: iPacket. A tunneling hook has more complex requirements: williamr@2: it must save the current iPacket and #iOffset and initialize williamr@2: iOffset = 0, and iPacket as empty. williamr@2: williamr@2: @par MFlowHook::ApplyL williamr@2: When a tunneling hook adds the tunneling IP header, it williamr@2: must also copy the saved iPacket below the added IP header. williamr@2: */ williamr@2: RMBufPacketPeek iPacket; williamr@2: /** williamr@2: The received packet which caused an ICMP error reply to be sent. williamr@2: williamr@2: This is only used for ICMP error repply flows, and should be williamr@2: ignored by others -- mainly for IPSEC hook. The packet, if williamr@2: present, is in unpacked state. williamr@2: */ williamr@2: RMBufPacketBase iIcmp; williamr@2: /** williamr@2: The current destination interface. williamr@2: williamr@2: This is ONLY used during connect/OpenL phase. williamr@2: williamr@2: The value is maintained by the stack, and is intended as williamr@2: read-only information for the hooks that have a use for williamr@2: it (for example, IPSEC implementing VPN specific policies). williamr@2: williamr@2: A hook must not modify this value (the stack will recompute williamr@2: the value after each OpenL, based on the possibly changed williamr@2: address parameters in the TPacketHead) williamr@2: williamr@2: @par MIp6Hook::OpenL williamr@2: read-only williamr@2: @par MFlowHook::ReadyL williamr@2: read-only williamr@2: */ williamr@2: TUint32 iInterfaceIndex; 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@2: EAlign1 = 0, ///< Align to byte (no align requirement) williamr@2: EAlign2 = 1, ///< Align to 2 byte unit (even address) williamr@2: EAlign4 = 3, ///< Align to 4 byte unit williamr@2: 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: // TPacketPoker williamr@2: // ************ williamr@2: class TPacketPoker williamr@2: /** williamr@2: Provides a utility for linear scanning of a chain of RMBuf objects (an RMBufChain). williamr@2: williamr@2: An object of this type maintains a current point in the RMBufChain. This point williamr@2: can only move forward, and a leave occurs if the point advances beyond the williamr@2: end of the chain. williamr@2: williamr@2: Any pointers and aligns arranged before the current point, remain valid: for williamr@2: example, you can save a reference and advance the pointer, and the reference williamr@2: remains usable. williamr@2: williamr@2: If instead you need to go to a single specified offset, then use williamr@2: RMBufChain::Goto() or RMBufPacketPeek::Access(). williamr@2: williamr@2: @post williamr@2: A Generic implementation assert: williamr@2: after construct, iTail == 0 iff iCurrent == 0 (all scanned), or williamr@2: in other words: as long as there are bytes after current point, williamr@2: iTail will be non-zero (and More() returns ETrue). williamr@2: All methods maintain this invariant or leave, if impossible. williamr@2: williamr@2: Some other utility methods, not directly related to scanning, are also included. williamr@2: @since v7.0 williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C TPacketPoker(RMBufChain &aChain); williamr@2: williamr@2: inline void SkipL(TInt aSize) williamr@2: /** williamr@2: Moves the current point forward a specified number of bytes. williamr@2: williamr@2: @param aSize Number of bytes to move forward williamr@2: @leave KErrEof williamr@2: if the request cannot be satisfied. williamr@2: */ williamr@2: { if (aSize < iTail) { iTail -= aSize; iOffset += aSize; } else OverL(aSize); } williamr@2: williamr@2: inline TUint8 *Ptr() const williamr@2: /** williamr@2: Raw pointer to the current point (can be invalid, if iTail = 0). williamr@2: williamr@2: @note Internal "unsafe" method williamr@2: */ williamr@2: {return iCurrent->Ptr() + iOffset; } williamr@2: williamr@2: inline TUint8 *ReferenceL(TInt aSize = 1) williamr@2: /** williamr@2: Gets a pointer to the current point, such that williamr@2: at least the specified minimum number of bytes can be read. williamr@2: williamr@2: @param aSize williamr@2: Specified minimum number of bytes to be read through williamr@2: the returned pointer. williamr@2: @return Raw data pointer williamr@2: @leave KErrEof williamr@2: if the request cannot be satisfied. williamr@2: */ williamr@2: { if (iTail >= aSize) return Ptr(); else return AdjustL(aSize); } williamr@2: williamr@2: inline TUint8 *ReferenceAndSkipL(TInt aSize) williamr@2: /** williamr@2: Gets a pointer to the current point, such that at least the williamr@2: specified minimum number of bytes can be read, williamr@2: and moves the point the specified number of bytes forward. williamr@2: williamr@2: @param aSize williamr@2: Specified minimum number of bytes to be read through the returned williamr@2: pointer, and the number of bytes to move forward williamr@2: @return williamr@2: Raw data pointer williamr@2: @leave KErrEof williamr@2: if the request cannot be satisfied. williamr@2: */ williamr@2: { TUint8 *x = ReferenceL(aSize); SkipL(aSize); return x; } williamr@2: williamr@2: inline TInt Remainder() const williamr@2: /** williamr@2: Gets the length of the contiguous space after the current point. williamr@2: williamr@2: @return Length after the current point williamr@2: */ williamr@2: { return iTail; } williamr@2: williamr@2: inline TBool AtBegin() const williamr@2: /** williamr@2: Tests whether the current point is at the beginning of an RMBuf. williamr@2: williamr@2: @return ETrue if current point is at the beginning williamr@2: */ williamr@2: { return iOffset == 0; } williamr@2: williamr@2: inline TBool More() const williamr@2: /** williamr@2: Tests whether there is more data to scan. williamr@2: williamr@2: @return ETrue if there is more data to scan williamr@2: */ williamr@2: { return iTail > 0; } williamr@2: williamr@2: IMPORT_C static TBool IsExtensionHeader(TInt aProtocolId); williamr@2: private: williamr@2: IMPORT_C void OverL(TInt aSize); williamr@2: IMPORT_C TUint8 *AdjustL(TInt aSize); williamr@2: /** The RMBuf of the current point. */ williamr@2: RMBuf *iCurrent; williamr@2: /** The offset of the current point in the RMBuf. */ williamr@2: TInt iOffset; williamr@2: /** Remaining bytes starting from the current point in the RMBuf. */ williamr@2: TInt iTail; williamr@2: }; williamr@2: williamr@2: #endif