epoc32/include/arp_hdr.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
       
     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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // arp_hdr.h - ARP header structure
       
    15 // ARP header structure.
       
    16 //
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  @file arp_hdr.h
       
    22  @ingroup ip_packet_formats
       
    23  @publishedAll
       
    24  @released
       
    25 */
       
    26 
       
    27 #ifndef __ARP_HDR_H__
       
    28 #define __ARP_HDR_H__
       
    29 
       
    30 #include "in_hdr.h"
       
    31 
       
    32 /**
       
    33 * @addtogroup  ip_packet_formats
       
    34 * @{
       
    35 */
       
    36 
       
    37 /**
       
    38 * "Fake" protocol number for ARP.
       
    39 *
       
    40 * This protocol value is only used to recognize the ARP packets
       
    41 * coming from the interface. There is no "real" ARP.PRT.
       
    42 */
       
    43 const TUint KProtocolArp		= 0xFAD;	// (get some better value)
       
    44 
       
    45 const TUint16 KArpProtocolType_IP = 0x0800;	// Protocol Type value for IPv4
       
    46 //
       
    47 // Hardware types listed only as example, it is assumed that the
       
    48 // driver knows its own type...
       
    49 //
       
    50 const TUint16 KArpHarwareType_ETHERNET = 1;
       
    51 const TUint16 KArpHarwareType_IEEE_802 = 6;
       
    52 
       
    53 /**
       
    54 @publishedAll
       
    55 @released
       
    56 */
       
    57 enum TArpOperation	// from RFC-1700
       
    58 	{
       
    59 	EArpOperation_REQUEST = 1,			// RFC-826
       
    60 	EArpOperation_REPLY = 2,			// RFC-826
       
    61 	EArpOperation_REQUEST_REVERSE = 3,	// RFC-903
       
    62 	EArpOperation_REPLY_REVERSE = 4,	// RFC-903
       
    63 	EArpOperation_DRARP_REQUEST = 5,	//
       
    64 	EArpOperation_DRARP_REPLY = 6,
       
    65 	EArpOperation_DRARP_ERROR = 7,
       
    66 	EArpOperation_INARP_REQUEST = 8,	// RFC-1293
       
    67 	EArpOperation_INARP_REPLY = 9,		// RFC-1293
       
    68 	EArpOperation_ARP_NAK = 10
       
    69 	};
       
    70 
       
    71 
       
    72 class TInet6HeaderArp
       
    73 	/**
       
    74 	* ARP Header.
       
    75 	*
       
    76 @verbatim
       
    77  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    78  |        Hardware Type          |         Protocol Type         |
       
    79  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    80  |  HwAddrLen    |   PrAddrLen   |         ARP Operation         |
       
    81  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    82  |         Sender's physical hardware address                    |
       
    83    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    84  |         Sender's protocol address                             |
       
    85    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    86  |         Target's physical hardware address                    |
       
    87    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    88  |         Target's protocol address                             |
       
    89  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    90 @endverbatim
       
    91 	* @note
       
    92 	* This definition covers only the fixed portion of the
       
    93 	* message. DO NOT DECLARE A VARIABLE WITH THIS CLASS!
       
    94 	* @publishedAll
       
    95 	* @released
       
    96 	*/
       
    97 	{
       
    98 public:
       
    99 	inline static TInt MinHeaderLength() {return 8; }
       
   100 	inline static TInt MaxHeaderLength() {return 128; }	
       
   101 
       
   102 	inline TUint8* EndPtr() { return i + HeaderLength(); }
       
   103 	inline TInt HeaderLength() const { return 8 + 2 * HwAddrLen() + 2 * PrAddrLen(); } // Return true byte length
       
   104 
       
   105 	// Access methods
       
   106 
       
   107 	inline TInt HardwareType() const	// Return hardware type value in host order
       
   108 		{
       
   109 		return i[0] << 8 | i[1];
       
   110 		}
       
   111 
       
   112 	inline TInt ProtocolType() const	// Return protocol type value in host order
       
   113 		{
       
   114 		return i[2] << 8 | i[3];
       
   115 		}
       
   116 
       
   117 	inline TInt HwAddrLen()	const		// Return hardware address length (in bytes)
       
   118 		{
       
   119 		return i[4];
       
   120 		}
       
   121 
       
   122 	inline TInt PrAddrLen()	const		// Return protocol address length (in bytes)
       
   123 		{
       
   124 		return i[5];
       
   125 		}
       
   126 
       
   127 	inline TInt Operation() const
       
   128 		{
       
   129 		return i[6] << 8 | i[7];
       
   130 		}
       
   131 
       
   132 	// Access/Modify
       
   133 
       
   134 	inline TPtr8 SenderHwAddr()
       
   135 		{
       
   136 		return TPtr8(&i[8], HwAddrLen(), HwAddrLen());
       
   137 		}
       
   138 	inline TPtr8 SenderPrAddr()
       
   139 		{
       
   140 		return TPtr8(&i[8] + HwAddrLen(), PrAddrLen(), PrAddrLen());
       
   141 		}
       
   142 	inline TPtr8 TargetHwAddr()
       
   143 		{
       
   144 		return TPtr8(&i[8] + HwAddrLen() + PrAddrLen(), HwAddrLen(), HwAddrLen());
       
   145 		}
       
   146 	inline TPtr8 TargetPrAddr()
       
   147 		{
       
   148 		return TPtr8(&i[8] + 2*HwAddrLen() + PrAddrLen(), PrAddrLen(), PrAddrLen());
       
   149 		}
       
   150 
       
   151 	// Modify
       
   152 
       
   153 	inline void SetHardwareType(TInt aType)	// Set hardware type value
       
   154 		{
       
   155 		i[1] = (TUint8)aType;
       
   156 		i[0] = (TUint8)(aType >> 8);
       
   157 		}
       
   158 
       
   159 	inline void SetProtocolType(TInt aType)	// Set protocol type value
       
   160 		{
       
   161 		i[3] = (TUint8)aType;
       
   162 		i[2] = (TUint8)(aType >> 8);
       
   163 		}
       
   164 
       
   165 	inline void SetHwAddrLen(TInt aLength)	// Set hardware address length (in bytes)
       
   166 		{
       
   167 		i[4] = (TUint8)aLength;
       
   168 		}
       
   169 
       
   170 	inline void SetPrAddrLen(TInt aLength)	// Set protocol address length (in bytes)
       
   171 		{
       
   172 		i[5] = (TUint8)aLength;
       
   173 		}
       
   174 
       
   175 	inline void SetOperation(TInt aOperation)
       
   176 		{
       
   177 		i[7] = (TUint8)aOperation;
       
   178 		i[6] = (TUint8)(aOperation >> 8);
       
   179 		}
       
   180 
       
   181 private:
       
   182 	union
       
   183 		{
       
   184 		TUint8 i[8];
       
   185 		TUint32 iAlign;	// A dummy member to force the 4 byte alignment
       
   186 		};
       
   187 	};
       
   188 
       
   189 /** @} */
       
   190 #endif