vpnengine/ikeutils/inc/ikemsgheader.h
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: IKE message header class
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef _IKE_MSG_HEADER_H_
       
    19 #define _IKE_MSG_HEADER_H_
       
    20 
       
    21 #include <e32base.h>
       
    22 
       
    23 #define ISAKMP_COOKIE_SIZE 8
       
    24 #define IKEV2_SPI_SIZE     8
       
    25 typedef TBuf8<ISAKMP_COOKIE_SIZE> TCookie;
       
    26 typedef TBuf8<IKEV2_SPI_SIZE> TIkeSPI;
       
    27 
       
    28 #define ISAKMP_HDR_SIZE sizeof(ThdrISAKMP)
       
    29 #define IKEV2_HDR_SIZE  sizeof(ThdrISAKMP)
       
    30 
       
    31 #define IKE_PORT                  500
       
    32 #define FLOATED_IKE_PORT          4500     
       
    33 #define NON_ESP_MARKER            0x0     
       
    34 #define NON_ESP_MARKER_SIZE       4   // Corresponds IPSEC SPI size
       
    35 
       
    36 //
       
    37 //  NAT flags
       
    38 //
       
    39 #define LOCAL_END_NAT       0x1
       
    40 #define REMOTE_END_NAT      0x2
       
    41 #define MOBIKE_USED         0x4
       
    42 
       
    43 //
       
    44 // These macro definitions takes care of 16- and 32-bit data packing and
       
    45 // unpacking.
       
    46 // The following assumptions are in use for macros:
       
    47 // -- The connection memory is a little-endian configured (= Intel format)
       
    48 // -- A macro does always an unconditional conversion for the parameter data
       
    49 //    PUTxx(d, s) = Source data is supposed to be in "Network order". Data
       
    50 //                  is stored to *p as little-endian.
       
    51 //    GETxx(s)    = Source data is supposed to be in memory as little-endian.
       
    52 //                  Macro return data in "Network order"
       
    53 //
       
    54 #define PUT16(d, s)  \
       
    55    (*(unsigned char*)((unsigned char*)(d)+1)) = (unsigned char)((s) & 0xff);\
       
    56    (*(unsigned char*)(d))                     = (unsigned char)(((s) >> 8 ) & 0xff)
       
    57 
       
    58 #define PUT32(d, s)  \
       
    59     (*(unsigned char*)((unsigned char*)(d)+3)) = (unsigned char)((s) & 0xff);\
       
    60     (*(unsigned char*)((unsigned char*)(d)+2)) = (unsigned char)(((s) >> 8 ) & 0xff);\
       
    61     (*(unsigned char*)((unsigned char*)(d)+1)) = (unsigned char)(((s) >> 16) & 0xff);\
       
    62     (*(unsigned char*)(d))                     = (unsigned char)(((s) >> 24) & 0xff)
       
    63 
       
    64 #define GET16(s)  \
       
    65      (((unsigned short)(*((unsigned char*)(s)+1)))     | \
       
    66       ((unsigned short)(*(unsigned char*)(s)) << 8 ))
       
    67 
       
    68 #define GET32(s)  \
       
    69      (((unsigned int)(*((unsigned char*)(s)+3)))         | \
       
    70      (((unsigned int)(*((unsigned char*)(s)+2))) << 8  ) | \
       
    71      (((unsigned int)(*((unsigned char*)(s)+1))) << 16 ) | \
       
    72       ((unsigned int)(*(unsigned char*)(s)) << 24 ))
       
    73 
       
    74 
       
    75 //
       
    76 //   IKEv2 MESSAGE FIXED HEADER
       
    77 //                       1                   2                   3
       
    78 //   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
       
    79 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    80 //   !                       IKE_SA Initiator's SPI                  !
       
    81 //   !                                                               !
       
    82 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    83 //   !                       IKE_SA Responder's SPI                  !
       
    84 //   !                                                               !
       
    85 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    86 //   !  Next Payload ! MjVer ! MnVer ! Exchange Type !     Flags     !
       
    87 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    88 //   !                          Message ID                           !
       
    89 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    90 //   !                            Length                             !
       
    91 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    92 //
       
    93 //   IKEv1 MESSAGE FIXED HEADER
       
    94 //
       
    95 //                     1                   2                   3
       
    96 //   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
       
    97 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    98 //   !                          Initiator                            !
       
    99 //   !                            Cookie                             !
       
   100 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   101 //   !                          Responder                            !
       
   102 //   !                            Cookie                             !
       
   103 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   104 //   !  Next Payload ! MjVer ! MnVer ! Exchange Type !     Flags     !
       
   105 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   106 //   !                          Message ID                           !
       
   107 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   108 //   !                            Length                             !
       
   109 //   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
   110 //
       
   111 class ThdrISAKMP
       
   112 {
       
   113 public:
       
   114     static inline const ThdrISAKMP* Ptr(const TDes8& aMsg, TInt aOffset) { return (ThdrISAKMP*)(aMsg.Ptr() + aOffset); }
       
   115     static inline const ThdrISAKMP* Ptr(const TDes8& aMsg) { return (ThdrISAKMP*)aMsg.Ptr(); }
       
   116 	static inline TInt Size() { return sizeof(ThdrISAKMP); }	
       
   117     inline const ThdrISAKMP* GotoOffset(TUint8 aOffset) const { return (const ThdrISAKMP*)((char*)this + aOffset); }
       
   118     inline TUint8* Next() const { return (TUint8*)((char*)this + sizeof(ThdrISAKMP)); }
       
   119 	inline TCookie GetCookieI() const
       
   120 		{ TCookie c;
       
   121           c.Copy(&u.iData8[0],ISAKMP_COOKIE_SIZE);
       
   122 	      return c;
       
   123 		}
       
   124 	inline void GetSPI_I(TIkeSPI& aSPI) const { aSPI.Copy(&u.iData8[0], IKEV2_SPI_SIZE); }
       
   125 	inline TUint32 GetSPI_I_Low32() const  { return GET32(&u.iData32[1]); }
       
   126 	inline TUint32 GetNegotiationID_I() const  { return GET32(&u.iData32[0]); }
       
   127 	inline TCookie GetCookieR() const
       
   128 		{ TCookie c;
       
   129 	      c.Copy(&u.iData8[8],ISAKMP_COOKIE_SIZE);
       
   130 	      return c;
       
   131 		}
       
   132 	inline void GetSPI_R(TIkeSPI& aSPI) const { aSPI.Copy(&u.iData8[8], IKEV2_SPI_SIZE); }
       
   133 	inline TUint32 GetSPI_R_Low32() const  { return GET32(&u.iData32[3]); }	
       
   134 	inline TUint32 GetNegotiationID_R() const  { return GET32(&u.iData32[2]); }
       
   135 	inline void SetCookieI(const TCookie& aCookie)
       
   136 		{ Mem::Copy(&u.iData8[0], aCookie.Ptr(), ISAKMP_COOKIE_SIZE); }
       
   137 	inline void SetSPI_I(const TIkeSPI& aSPI)	{Mem::Copy(&u.iData8[0],aSPI.Ptr(),IKEV2_SPI_SIZE); }
       
   138 	inline void SetCookieR(const TCookie& aCookie)
       
   139 		{ Mem::Copy(&u.iData8[8],aCookie.Ptr(),ISAKMP_COOKIE_SIZE); }
       
   140 	inline void SetSPI_R(const TIkeSPI& aSPI)	{ Mem::Copy(&u.iData8[8],aSPI.Ptr(),IKEV2_SPI_SIZE); }
       
   141 	inline TUint8 GetPayload() const { return u.iData8[16]; }
       
   142 	inline void SetPayload(TUint8 aPayload) { u.iData8[16] = aPayload; }
       
   143 	inline TUint8 GetVersion() const { return u.iData8[17]; }
       
   144 	inline TUint8 GetMajorVersion() const { return (TUint8)(u.iData8[17] >> 4); }
       
   145 	inline TUint8 GetMinorVersion() const { return (TUint8)(u.iData8[17] & 0xf); }		
       
   146 	inline void SetVersion(TUint8 aVersion) { u.iData8[17] = aVersion; }
       
   147 	inline TUint8 GetExchange() const { return u.iData8[18]; }
       
   148 	inline void SetExchange(TUint8 aType) { u.iData8[18] = aType; }
       
   149 	inline TUint8 GetFlags() const { return u.iData8[19]; }
       
   150 	inline void SetFlags(TUint8 aFlags) { u.iData8[19] = aFlags; }
       
   151 	inline TUint32 GetMessageId() const { return GET32(&u.iData32[5]); }
       
   152 	inline void SetMessageId(TUint32 aId) { PUT32(&u.iData32[5], aId); }
       
   153 	inline TUint32 GetLength() const { return GET32(&u.iData32[6]); }
       
   154 	inline void SetLength(TUint32 aLength) { PUT32(&u.iData32[6], aLength); }
       
   155 private:
       
   156     union
       
   157         {
       
   158         TUint32 iData32[7];
       
   159         TUint16 iData16[14];
       
   160         TUint8  iData8[28];
       
   161         } u;
       
   162 };
       
   163 
       
   164 
       
   165 #endif