eapol/eapol_framework/eapol_common/include/eapol_ethernet_header.h
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 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 the License "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:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #if !defined(_EAP_ETHERNET_HEADER_H_)
       
    22 #define _EAP_ETHERNET_HEADER_H_
       
    23 
       
    24 #include "eap_tools.h"
       
    25 #include "eapol_header.h"
       
    26 #include "eap_general_header_base.h"
       
    27 #include "eapol_ethernet_address.h"
       
    28 
       
    29 
       
    30 /** @file */
       
    31 
       
    32 /**
       
    33  * This is base class of Ethernet header used with EAPOL.
       
    34  * @code
       
    35  *  0                   1                   2                   3
       
    36  *  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
       
    37  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    38  *  |          Destination address                                  |
       
    39  *  +-                             -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    40  *  |                               |       Source address          |
       
    41  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-                             -+
       
    42  *  |                                                               |
       
    43  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    44  *  |             Type              |   Data ...                     
       
    45  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    46  * @endcode
       
    47  */
       
    48 class EAP_EXPORT eapol_ethernet_header_base_c
       
    49 : public eap_general_header_base_c
       
    50 {
       
    51 private:
       
    52 	//--------------------------------------------------
       
    53 
       
    54 	/// This is pointer to the tools class.
       
    55 	abs_eap_am_tools_c * const m_am_tools;
       
    56 
       
    57 	//--------------------------------------------------
       
    58 protected:
       
    59 	//--------------------------------------------------
       
    60 
       
    61 	/**
       
    62 	 * This enumeration defines the offsets of the Ethernet-header fields.
       
    63 	 */
       
    64 	enum offsets
       
    65 	{
       
    66 		m_destination_offset = 0ul,                                           ///< This is offset to destination address field.
       
    67 		m_source_offset = m_destination_offset+EAPOL_ETHERNET_ADDRESS_LENGTH, ///< This is offset to source address field.
       
    68 		m_type_offset = m_source_offset+EAPOL_ETHERNET_ADDRESS_LENGTH,        ///< This is offset to type field.
       
    69 		m_data_offset = m_type_offset+sizeof(u16_t),                          ///< This is offset to data field.
       
    70 	};
       
    71 
       
    72 	//--------------------------------------------------
       
    73 public:
       
    74 	//--------------------------------------------------
       
    75 
       
    76 	/// Destructor does nothing special.
       
    77 	EAP_FUNC_IMPORT virtual ~eapol_ethernet_header_base_c();
       
    78 
       
    79 	/// Constructor does nothing special.
       
    80 	/// The tools parameter is pointer to tools object.
       
    81 	/// The header_buffer parameter is pointer to buffer of Ethernet-packet including header and data.
       
    82 	/// The header_buffer_length parameter is length of the header_buffer.
       
    83 	EAP_FUNC_IMPORT eapol_ethernet_header_base_c(
       
    84 			abs_eap_am_tools_c * const tools,
       
    85 			void * const header_buffer,
       
    86 			const u32_t header_buffer_length);
       
    87 
       
    88 	/// This function returns pointer to the destination address of the Ethernet-packet.
       
    89 	EAP_FUNC_IMPORT u8_t * get_destination() const;
       
    90 
       
    91 	/// This function returns pointer to the source address of the Ethernet-packet.
       
    92 	EAP_FUNC_IMPORT u8_t * get_source() const;
       
    93 
       
    94 	/// This function returns length of the destination address of the Ethernet-packet.
       
    95 	EAP_FUNC_IMPORT u32_t get_destination_length() const;
       
    96 
       
    97 	/// This function returns length of the source address of the Ethernet-packet.
       
    98 	EAP_FUNC_IMPORT u32_t get_source_length() const;
       
    99 
       
   100 	/// This function returns the packet type field of Ethernet-header.
       
   101 	EAP_FUNC_IMPORT u16_t get_type() const;
       
   102 
       
   103 	/// This function returns pointer to the data of the Ethernet-packet.
       
   104 	EAP_FUNC_IMPORT u8_t * get_data(const u32_t data_length) const;
       
   105 
       
   106 	/// This function returns the length of the data of Ethernet-header.
       
   107 	EAP_FUNC_IMPORT u32_t get_data_length() const;
       
   108 
       
   109 	/// This function returns the header length of the Ethernet-packet.
       
   110 	EAP_FUNC_IMPORT static u16_t get_header_length();
       
   111 
       
   112 	/// This function sets the packet type field of the Ethernet-header.
       
   113 	EAP_FUNC_IMPORT void set_type(const eapol_ethernet_type_e type);
       
   114 
       
   115 	/// This function checks the validity of Ethernet-header.
       
   116 	EAP_FUNC_IMPORT eap_status_e check_header() const;
       
   117 
       
   118 	// 
       
   119 	//--------------------------------------------------
       
   120 }; // class eapol_ethernet_header_base_c
       
   121 
       
   122 
       
   123 
       
   124 
       
   125 
       
   126 /// @{ This class can be removed. eapol_ethernet_header_base_c could be used instead. }
       
   127 class EAP_EXPORT eapol_ethernet_header_rd_c
       
   128 : public eapol_ethernet_header_base_c
       
   129 {
       
   130 private:
       
   131 	//--------------------------------------------------
       
   132 
       
   133 	/// This is pointer to the tools class.
       
   134 	abs_eap_am_tools_c * const m_am_tools;
       
   135 
       
   136 	//--------------------------------------------------
       
   137 protected:
       
   138 	//--------------------------------------------------
       
   139 
       
   140 	//--------------------------------------------------
       
   141 public:
       
   142 	//--------------------------------------------------
       
   143 
       
   144 	/// Destructor does nothing special.
       
   145 	EAP_FUNC_IMPORT virtual ~eapol_ethernet_header_rd_c();
       
   146 
       
   147 	/// Constructor does nothing special.
       
   148 	/// The tools parameter is pointer to tools object.
       
   149 	/// The header_buffer parameter is pointer to buffer of Ethernet-packet including header and data.
       
   150 	/// The header_buffer_length parameter is length of the header_buffer.
       
   151 	EAP_FUNC_IMPORT eapol_ethernet_header_rd_c(
       
   152 			abs_eap_am_tools_c * const tools,
       
   153 			const u8_t * const header_buffer,
       
   154 			const u32_t header_buffer_length);
       
   155 
       
   156 	/// This function returns pointer to the header of the EAPOL-packet included in the Ethernet-packet.
       
   157 	EAP_FUNC_IMPORT u8_t * get_eapol_header() const;
       
   158 
       
   159 	// 
       
   160 	//--------------------------------------------------
       
   161 }; // class eapol_ethernet_header_rd_c
       
   162 
       
   163 
       
   164 
       
   165 /// @{ This class can be removed. eapol_ethernet_header_base_c could be used instead. }
       
   166 class EAP_EXPORT eapol_ethernet_header_wr_c
       
   167 : public eapol_ethernet_header_base_c
       
   168 {
       
   169 private:
       
   170 	//--------------------------------------------------
       
   171 
       
   172 	/// This is pointer to the tools class.
       
   173 	abs_eap_am_tools_c * const m_am_tools;
       
   174 
       
   175 	//--------------------------------------------------
       
   176 protected:
       
   177 	//--------------------------------------------------
       
   178 
       
   179 	//--------------------------------------------------
       
   180 public:
       
   181 	//--------------------------------------------------
       
   182 
       
   183 	/// Destructor does nothing special.
       
   184 	EAP_FUNC_IMPORT virtual ~eapol_ethernet_header_wr_c();
       
   185 
       
   186 	/// Constructor does nothing special.
       
   187 	/// The tools parameter is pointer to tools object.
       
   188 	/// The header_buffer parameter is pointer to buffer of Ethernet-packet including header and data.
       
   189 	/// The header_buffer_length parameter is length of the header_buffer.
       
   190 	EAP_FUNC_IMPORT eapol_ethernet_header_wr_c(
       
   191 			abs_eap_am_tools_c * const tools,
       
   192 			const u8_t * const header_buffer,
       
   193 			const u32_t header_buffer_length);
       
   194 
       
   195 	/// This function returns pointer to the header of the EAPOL-packet included in the Ethernet-packet.
       
   196 	EAP_FUNC_IMPORT u8_t * get_eapol_header() const;
       
   197 
       
   198 	/// This function returns pointer to the destination address of the Ethernet-packet.
       
   199 	EAP_FUNC_IMPORT u8_t * get_destination();
       
   200 
       
   201 	/// This function returns pointer to the source address of the Ethernet-packet.
       
   202 	EAP_FUNC_IMPORT u8_t * get_source();
       
   203 
       
   204 	/// This function resets the EAPOL-header.
       
   205 	/// The type parameter is the type of Ethernet-packet.
       
   206 	/// The buffer_length parameter is the length of the EAPOL-header and the following data buffer.
       
   207 	EAP_FUNC_IMPORT void reset_header(const eapol_ethernet_type_e type, const u16_t buffer_length);
       
   208 
       
   209 	// 
       
   210 	//--------------------------------------------------
       
   211 }; // class eapol_ethernet_header_wr_c
       
   212 
       
   213 
       
   214 
       
   215 #endif //#if !defined(_EAP_ETHERNET_HEADER_H_)
       
   216 
       
   217 //--------------------------------------------------
       
   218 
       
   219 
       
   220 
       
   221 // End.