linklayerprotocols/pppnif/INC/VJ.H
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 1997-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 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @internalComponent 
       
    19 */
       
    20 
       
    21 #if !defined(__VJ_H__)
       
    22 #define __VJ_H__
       
    23 
       
    24 #include <networking/in_tcp.h>
       
    25 #include <networking/vjif.h>
       
    26 
       
    27 const TUint8 KVJDiscard			= 1;
       
    28 
       
    29 // Limits on the number of slots that can be handled by the VJ code
       
    30 // in terms of the enumerated slot number.
       
    31 // The VJ code may work with KMinVjSlot=0, but 2 is safer without more testing.
       
    32 const TUint8 KMinVjSlot			= 2;
       
    33 const TUint8 KDesiredVjSlot		= 15;
       
    34 const TUint8 KMaxVjSlot			= 255;
       
    35 
       
    36 const TUint8 KVjCompSlotId		= 1;
       
    37 const TUint8 KVjCompMaskConn	= 0x40;
       
    38 const TUint8 KVjCompMaskIp		= 0x20;
       
    39 const TUint8 KVjCompMaskPush	= 0x10;
       
    40 const TUint8 KVjCompMaskSeq		= 0x08;
       
    41 const TUint8 KVjCompMaskAck		= 0x04;
       
    42 const TUint8 KVjCompMaskWindow	= 0x02;
       
    43 const TUint8 KVjCompMaskUrgent	= 0x01;
       
    44 const TUint8 KVjCompMaskSpecialD = KVjCompMaskSeq 
       
    45 								| KVjCompMaskAck 
       
    46 								| KVjCompMaskWindow 
       
    47 								| KVjCompMaskUrgent;
       
    48 const TUint8 KVjCompMaskSpecials = KVjCompMaskSpecialD;
       
    49 const TUint8 KVjCompMaskSpecialI = KVjCompMaskSeq 
       
    50 								| KVjCompMaskWindow 
       
    51 								| KVjCompMaskUrgent;
       
    52 
       
    53 
       
    54 const TUint32 KUidVJCompDll		=  0x10000ba8;
       
    55 const TUint32 KUidUnicodeVJCompDll		=  0x10003d43;
       
    56 
       
    57 // moved from ncpip.h
       
    58 const TUint KPppIdIp = 0x0021;
       
    59 const TUint KPppIdVjCompTcp = 0x002d;
       
    60 const TUint KPppIdVjUncompTcp = 0x002f;
       
    61 //
       
    62 
       
    63 class TVJCompHdr
       
    64 /**
       
    65 Van Jacobson compressed TCP/IP header container class.
       
    66 Implements a linked list.
       
    67 @internalComponent
       
    68 */
       
    69 	{
       
    70 public:
       
    71 	TVJCompHdr();
       
    72 	void			StoreTCPIPHeader(ThdrIP * aHeader);
       
    73 	void			RetrieveTCPIPHeader(ThdrIP* aIPHeader, ThdrTCP* aTCPHeader);
       
    74 	inline void		SetNextPtr(TVJCompHdr * aNextPtr);
       
    75 	inline TVJCompHdr*		NextPtr() const;
       
    76 	inline void		SetConnectionNumber(TUint aConnection);
       
    77 	inline TUint	ConnectionNumber() const;
       
    78 	inline TBool	IsValid() const;
       
    79 private:
       
    80 	inline void		MarkValid();
       
    81 
       
    82 private:
       
    83     /** Pointer to the next object in the linked list */
       
    84 	TVJCompHdr*		iNextPtr;
       
    85 	
       
    86 	/** Flag for iConnectionId indicating this object contains valid data */
       
    87 	enum {KVJValidFlag = 0x80000000};
       
    88 	
       
    89 	/** VJ connection number */
       
    90 	TUint			iConnectionId;
       
    91 	
       
    92 	/** IP header */
       
    93 	ThdrIP			iIPHeader;
       
    94 	
       
    95 	/** TCP header */
       
    96 	ThdrTCP			iTCPHeader;
       
    97 	};
       
    98 
       
    99 #include <networking/vj.inl>
       
   100 
       
   101 NONSHARABLE_CLASS(CVJDeCompressor) : public CVJDeCompressorIf
       
   102 /**
       
   103 Van Jacobson TCP/IP header decompressor (RFC 1144)
       
   104 @internalComponent
       
   105 */
       
   106 	{
       
   107 public:
       
   108 	~CVJDeCompressor();
       
   109 	//IMPORT_C static CVJDeCompressor* NewL(TUint aSlots);
       
   110 	TBool	DecompVJUncomp(RMBufChain& aPacket);
       
   111 	TBool	DecompVJComp(RMBufChain& aPacket);
       
   112 	void	CRCError();
       
   113 	void	ConstructL( CVJCompFactory* aFactory, TUint aSlots );
       
   114 	CVJDeCompressor();
       
   115 private:
       
   116 	inline	void	SetFlag( const TUint aFlag);
       
   117 	inline	void	ClearFlag( const TUint aFlag);
       
   118 	inline	TBool	TestFlag( const TUint aFlag);
       
   119 	void	DecompSWAU(const TUint aChanges, TUint8** aVJCompHeader, ThdrTCP* aTCPHeader, TUint16 aPreviousFrameLength);
       
   120 	void	DecompPushFlag(const TUint aChanges, ThdrTCP* aHeader);
       
   121 	void	DecompIPId(const TUint aChanges, TUint8** aVJCompHeader, ThdrIP* aIPHeader );
       
   122 	TUint16	DecodeDelta( TUint8 ** aVJCompHeader );
       
   123 	void	EncodeDelta(TUint8** aVJCompHeader, TUint16 aValue);
       
   124 	void	DecompUrgent(TUint8** aVJCompHeader, ThdrTCP* aTCPHeader, TUint aChanges);
       
   125 	void	DecompWindow(TUint8** aVJCompHeader, ThdrTCP* aTCPHeader);
       
   126 	void	DecompAck(TUint8** aVJCompHeader, ThdrTCP* aTCPHeader);
       
   127 	void	DecompSeq(TUint8** aVJCompHeader, ThdrTCP* aTCPHeader);
       
   128 	TUint8*	GetVJPtr(RMBufChain &aChain, TUint16* aCurrentFrameLength);
       
   129 	void	DecompressFrameL(RMBufChain& aPacket, TUint8 aConnection, TUint8 aChanges, TUint8* const aInitialHeaderPtr, TUint Offset, TUint16 aCurrentFrameLength);
       
   130 	void	CopyInNewHeaderL(RMBufChain* aPacket, ThdrIP * aIPHeader, ThdrTCP * aTCPHeader, TUint aCompressedHeaderLength, TUint16 aIPHeaderLength, TUint16 aTCPHeaderLength);
       
   131 	ThdrIP*	GetIPHeader(RMBufChain &aChain);
       
   132 	void	DoIPChecksum(ThdrIP* aIPHeader, TUint16 aIPHeaderLength);
       
   133 	void	CopyRecvHeader(const TUint aConnectionNumber, ThdrIP * aHeader);
       
   134 	void	GetStoredRxHeader(const TUint aConnectionNumber, ThdrIP * aIPHeader, ThdrTCP * aTCPHeader);
       
   135 	TBool	CheckStoredRxHeader(const TUint aConnection) const;
       
   136 	
       
   137 private:
       
   138     /** Index of the highest-numbered VJ connection */
       
   139 	TUint		iNumVJSlots;
       
   140 	
       
   141 	/** VJ connection number of the last valid packet received */
       
   142 	TUint		iLastRxConn;
       
   143 	
       
   144 	/** Set to KVJDiscard while discarding received packets due to lost synchronization */
       
   145 	TUint		iFlags;
       
   146 
       
   147     /** Pointer to start of array of VJ connections */
       
   148 	TVJCompHdr* iRxStates;
       
   149 	};
       
   150 
       
   151 #include <networking/vjdecomp.inl>
       
   152 
       
   153 NONSHARABLE_CLASS(CVJCompressor) : public CVJCompressorIf
       
   154 /**
       
   155 Van Jacobson TCP/IP header compressor (RFC 1144)
       
   156 @internalComponent
       
   157 */
       
   158 	{
       
   159 public:
       
   160 
       
   161 	~CVJCompressor();
       
   162 	//IMPORT_C static CVJCompressor* NewL( TUint aSlots, TBool aCompressConnId );
       
   163 	TInt	VJCompressFrame(RMBufChain& aPacket);
       
   164 	void	ConstructL(CVJCompFactory* aFactory, TUint aMaxSlot, TBool aCompressConnId);
       
   165 	CVJCompressor();
       
   166 
       
   167 private:
       
   168 	void	EncodeDelta(TUint8** aVJCompHeader, TInt16 aValue);
       
   169 	inline TBool	IsDeltaCompressible(TUint32 aDelta) const;
       
   170 	ThdrIP*	GetIPHeader(RMBufChain &aChain);
       
   171 	TBool	SuitableForVJCompression(ThdrIP* aIPHeader, ThdrTCP* aTCPHeader, TUint* aConnection, ThdrIP* aRetrievedIPHdr, ThdrTCP* aRetrievedTCPHdr);
       
   172 	TBool	CompressFrame(	RMBufChain& aPacket, 
       
   173 							ThdrIP* aIPHeader, 
       
   174 							ThdrTCP* aTCPHeader, 
       
   175 							TUint aConnection,
       
   176 							ThdrIP* aRetrievedIPHdr,
       
   177 							ThdrTCP* aRetrievedTCPHdr);
       
   178 	TBool	SendAsRawIP(ThdrIP* aIPHeader, ThdrTCP* aTCPHeader);
       
   179 	TBool	IsIPCompressible( ThdrIP* aIPHeader, ThdrIP* aRetrievedIPHdr);
       
   180 	TBool	IsTCPCompressible( ThdrTCP* aTCPHeader, ThdrTCP* aRetrievedTCPHdr);
       
   181 	TBool	CompressUrgentPtr(TUint8** aVJPtr, TUint8* aChanges, ThdrTCP* aTCPHeader, ThdrTCP* aRetrievedTCPHdr);
       
   182 	TBool	CompressWindow(TUint8** aVJPtr, TUint8* aChanges, ThdrTCP* aTCPHeader, ThdrTCP* aRetrievedTCPHdr);
       
   183 	TBool	CompressAck(TUint8** aVJPtr, TUint8* aChanges, ThdrTCP* aTCPHeader, ThdrTCP* aRetrievedTCPHdr);
       
   184 	TBool	CompressSeq(TUint8** aVJPtr, TUint8* aChanges, ThdrTCP* aTCPHeader, ThdrTCP* aRetrievedTCPHdr);
       
   185 	TBool	CompressIPId(TUint8** aVJPtr, TUint8* aChanges, ThdrIP* aIPHeader, ThdrIP* aRetrievedIPHdr);
       
   186 	TBool	CompressPush(TUint8* aChanges,  ThdrTCP* aTCPHeader);
       
   187 	TBool	IsSameConnAsLast(TUint* aCompressedHdrLen, TUint aConnection);
       
   188 	void	SetFirstFewBytes(TUint8* aChanges, TBool aNewConnection, TUint8** aVJHeader, ThdrTCP* aTCPHeader, TUint aConnection);
       
   189 	void	CopyInNewTxHeader(RMBufChain& aPacket, TUint8* aCompressedHdr, TUint aOldHeaderLength, TUint aNewHeaderLength);
       
   190 	void	DecrementPacketLen( RMBufChain& aPacket, TUint SizeDecrease );
       
   191 	TBool	CompressSpecialCases(	TUint8** aVJPtr, 
       
   192 									TUint8* const aVJInitialDeltaPtr, 
       
   193 									TUint8* aChanges, 
       
   194 									ThdrTCP* aTCPHeader, 
       
   195 									ThdrTCP* aRetrievedTCPHdr, 
       
   196 									ThdrIP* aIPHeader,
       
   197 									ThdrIP* aRetrievedIPHdr);
       
   198 	void	ConvertFrameToUncompVJ(ThdrIP* aIPHeader, TUint aConnection);
       
   199 	inline TUint8* GetTCPOpts(ThdrTCP* aTCPHeader) const;
       
   200 	void	CopyTxHeader( ThdrIP* aIPHeader, TUint aConnection);
       
   201 	TBool	GetStoredTxHeader(	TUint* aConnection, 
       
   202 								ThdrIP * aIPHeader, 
       
   203 								ThdrTCP* aTCPHeader, 
       
   204 								ThdrIP* aRetrievedIPHdr, 
       
   205 								ThdrTCP* aRetrievedTCPHdr);
       
   206 	TBool	IPAddressesMatch(ThdrIP* aIPHeader,ThdrIP* aNotherIPHdr);	
       
   207 	TBool	TCPPortsMatch(ThdrTCP* aHeader, ThdrTCP* aNotherHdr );
       
   208 	
       
   209 private:
       
   210     /** Maximum number of VJ connections */
       
   211 	TUint		iMaxVJSlots;
       
   212 	
       
   213 	/** Whether VJ was configured to compress the connection number */
       
   214 	TBool		iCompressConnId;
       
   215 	
       
   216 	/** Connection number of the last packet compressed */
       
   217 	TUint		iLastTxConn;
       
   218 	
       
   219     /** Pointer to the last element in the LRU circular list */
       
   220 	TVJCompHdr*	iLastTxHdr;
       
   221 
       
   222     /** Pointer to start of array of VJ connections */
       
   223 	TVJCompHdr*	iTxStates;
       
   224 	};
       
   225 
       
   226 #include <networking/vjcomp.inl>
       
   227 
       
   228 NONSHARABLE_CLASS(CVJFactory) : public CVJCompFactory
       
   229 /**
       
   230 Factory base for creating a concrete instance of a
       
   231 compressor or decompressor object
       
   232 @internalTechnology
       
   233 */
       
   234 	{
       
   235 public:
       
   236 	CVJFactory();
       
   237 	void InstallL();
       
   238 	CVJCompressorIf* NewVJCompressorL( TInt aMaxVJSlots, TInt aCompressConnId);
       
   239 	CVJDeCompressorIf* NewVJDeCompressorL(TInt aMaxVJSlots);
       
   240 	};
       
   241 
       
   242 extern "C"
       
   243 	{
       
   244 /**
       
   245 Generates and returns a CVJFactory object.
       
   246 This is the polymorphic DLL entry point.
       
   247 
       
   248 @return New CVJFactory object
       
   249 @internalTechnology
       
   250 */
       
   251 	IMPORT_C CVJCompFactory* NewVJCompFactoryL(void);
       
   252 	}
       
   253 
       
   254 #endif // __VJ_H__