eapol/eapol_framework/eapol_common/include/eapol_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(_EAPOL_HEADER_H_)
       
    22 #define _EAPOL_HEADER_H_
       
    23 
       
    24 
       
    25 #include "eap_tools.h"
       
    26 #include "eap_am_tools.h"
       
    27 #include "eap_header.h"
       
    28 #include "eap_general_header_base.h"
       
    29 #include "eapol_key_types.h"
       
    30 
       
    31 /** @file */
       
    32 
       
    33 /**
       
    34  * Enumeration of EAPOL Protocol Version.
       
    35  */
       
    36 enum eapol_protocol_version_e
       
    37 {
       
    38 	eapol_protocol_version_none = 0, ///< This is internal value for no version case.
       
    39 	eapol_protocol_version_1 = 1, ///< This is the original Protocol Version.
       
    40 	eapol_protocol_version_2 = 2, ///< This is the new Protocol Version defined in new IEEE P802.1X.
       
    41 };
       
    42 
       
    43 /**
       
    44  * Enumeration of EAPOL packet type.
       
    45  */
       
    46 enum eapol_packet_type_e
       
    47 {
       
    48 	eapol_packet_type_eap           = 0, ///< This the EAP-Packet.
       
    49 	eapol_packet_type_start         = 1, ///< This is EAPOL-Start.
       
    50 	eapol_packet_type_logoff        = 2, ///< This is EAPOL-Logoff.
       
    51 	eapol_packet_type_key           = 3, ///< This is EAPOL-Key.
       
    52 	eapol_packet_type_enc_asf_alert = 4, ///< This is EAPOL-Encapsulated-ASF-Alert.
       
    53 	eapol_packet_type_SAE_KE        = 5, ///< This is internal SAE testing.
       
    54 	eapol_packet_type_SAE_EAP       = 6, ///< This is internal SAE testing.
       
    55 	eapol_packet_type_SAE_START     = 7, ///< This is internal SAE testing.
       
    56 	eapol_packet_type_SAE_LOGOFF    = 8, ///< This is internal SAE testing.
       
    57 	eapol_packet_type_no_type       = 0xff, ///< This is internal value for no type case.
       
    58 };
       
    59 
       
    60 
       
    61 /**
       
    62  * This is base class of EAPOL header.
       
    63  * @code
       
    64  *  0                   1                   2                   3
       
    65  *  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
       
    66  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    67  *  | Prot. Version |  Packet Type  |       Data Length             |
       
    68  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    69  *  |  Data ...
       
    70  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    71  * @endcode
       
    72  */
       
    73 class EAP_EXPORT eapol_header_base_c
       
    74 : public eap_general_header_base_c
       
    75 {
       
    76 private:
       
    77 	//--------------------------------------------------
       
    78 
       
    79 	/// This is pointer to the tools class.
       
    80 	abs_eap_am_tools_c * const m_am_tools;
       
    81 
       
    82 	//--------------------------------------------------
       
    83 protected:
       
    84 	//--------------------------------------------------
       
    85 
       
    86 	/**
       
    87 	 * This enumeration defines the offsets of the EAPOL-header fields.
       
    88 	 */
       
    89 	enum offsets
       
    90 	{
       
    91 		m_version_offset = 0ul,                                   ///< This is the offset of the version field.
       
    92 		m_packet_type_offset = m_version_offset+sizeof(u8_t),     ///< This is the offset of the packet type field.
       
    93 		m_data_length_offset = m_packet_type_offset+sizeof(u8_t), ///< This is the offset of the data length field.
       
    94 		m_data_offset = m_data_length_offset+sizeof(u16_t),       ///< This is the offset of the data field.
       
    95 	};
       
    96 
       
    97 	//--------------------------------------------------
       
    98 public:
       
    99 	//--------------------------------------------------
       
   100 
       
   101 	/// Destructor does nothing special.
       
   102 	EAP_FUNC_IMPORT virtual ~eapol_header_base_c();
       
   103 
       
   104 	/// Constructor does nothing special.
       
   105 	/// The tools parameter is pointer to tools object.
       
   106 	/// The header_buffer parameter is pointer to buffer of EAPOL-packet including header and data.
       
   107 	/// The header_buffer_length parameter is length of the header_buffer.
       
   108 	EAP_FUNC_IMPORT eapol_header_base_c(
       
   109 		abs_eap_am_tools_c * const tools,
       
   110 		void * const header_buffer,
       
   111 		const u32_t header_buffer_length);
       
   112 
       
   113 	/// This function returns the Protocol Version field of EAPOL header.
       
   114 	EAP_FUNC_IMPORT eapol_protocol_version_e get_version() const;
       
   115 
       
   116 	/// This function returns the packet type field of EAPOL header.
       
   117 	EAP_FUNC_IMPORT eapol_packet_type_e get_packet_type() const;
       
   118 
       
   119 	/// This function returns the data length of the EAPOL-packet.
       
   120 	EAP_FUNC_IMPORT u16_t get_data_length() const;
       
   121 
       
   122 	/// This function returns the header length of the EAPOL-packet.
       
   123 	EAP_FUNC_IMPORT static u32_t get_header_length();
       
   124 
       
   125 	/// This function returns pointer to the data of the EAPOL-packet.
       
   126 	EAP_FUNC_IMPORT u8_t * get_data(const u32_t data_length) const;
       
   127 
       
   128 	/// This function sets the Protocol Version field of the EAPOL-header.
       
   129 	EAP_FUNC_IMPORT void set_version(const eapol_protocol_version_e p_version);
       
   130 
       
   131 	/// This function sets the packet type field of the EAPOL-header.
       
   132 	EAP_FUNC_IMPORT void set_packet_type(const eapol_packet_type_e p_packet_type);
       
   133 
       
   134 	/// This function sets the data length field of the EAPOL-header.
       
   135 	EAP_FUNC_IMPORT void set_data_length(const u16_t p_data_length);
       
   136 
       
   137 	/// This function returns debug string of the type of the EAPOL-packet.
       
   138 	EAP_FUNC_IMPORT eap_const_string get_type_string() const;
       
   139 
       
   140 	/// This function checks the validity of EAPOL-header.
       
   141 	EAP_FUNC_IMPORT eap_status_e check_header() const;
       
   142 
       
   143 	// 
       
   144 	//--------------------------------------------------
       
   145 }; // class eapol_header_base_c
       
   146 
       
   147 
       
   148 
       
   149 
       
   150 /// This is read only EAPOL header.
       
   151 /// @{ This class can be removed. eapol_header_base_c could be used instead. }
       
   152 class EAP_EXPORT eapol_header_rd_c
       
   153 : public eapol_header_base_c
       
   154 {
       
   155 private:
       
   156 	//--------------------------------------------------
       
   157 
       
   158 	/// This is pointer to the tools class.
       
   159 	abs_eap_am_tools_c * const m_am_tools;
       
   160 
       
   161 	//--------------------------------------------------
       
   162 protected:
       
   163 	//--------------------------------------------------
       
   164 
       
   165 	//--------------------------------------------------
       
   166 public:
       
   167 	//--------------------------------------------------
       
   168 
       
   169 	/// Destructor does nothing special.
       
   170 	EAP_FUNC_IMPORT virtual ~eapol_header_rd_c();
       
   171 
       
   172 	/// Constructor does nothing special.
       
   173 	/// The tools parameter is pointer to tools object.
       
   174 	/// The header_buffer parameter is pointer to buffer of EAPOL-packet including header and data.
       
   175 	/// The header_buffer_length parameter is length of the header_buffer.
       
   176 	EAP_FUNC_IMPORT eapol_header_rd_c(
       
   177 		abs_eap_am_tools_c * const tools,
       
   178 		u8_t * const header_buffer,
       
   179 		const u32_t header_buffer_length);
       
   180 
       
   181 	/// This function returns pointer to the header of the EAP-packet included in the EAPOL-packet.
       
   182 	EAP_FUNC_IMPORT u8_t * get_eap_header() const;
       
   183 
       
   184 	// 
       
   185 	//--------------------------------------------------
       
   186 }; // class eapol_header_rd_c
       
   187 
       
   188 
       
   189 
       
   190 
       
   191 /// This is read and write EAPOL header.
       
   192 /// @{ This class can be removed. eapol_header_base_c could be used instead. }
       
   193 class EAP_EXPORT eapol_header_wr_c
       
   194 : public eapol_header_base_c
       
   195 {
       
   196 private:
       
   197 	//--------------------------------------------------
       
   198 
       
   199 	/// This is pointer to the tools class.
       
   200 	abs_eap_am_tools_c * const m_am_tools;
       
   201 
       
   202 	//--------------------------------------------------
       
   203 protected:
       
   204 	//--------------------------------------------------
       
   205 
       
   206 	//--------------------------------------------------
       
   207 public:
       
   208 	//--------------------------------------------------
       
   209 
       
   210 	/// Destructor does nothing special.
       
   211 	EAP_FUNC_IMPORT virtual ~eapol_header_wr_c();
       
   212 
       
   213 	/// Constructor does nothing special.
       
   214 	/// The tools parameter is pointer to tools object.
       
   215 	/// The header_buffer parameter is pointer to buffer of EAPOL-packet including header and data.
       
   216 	/// The header_buffer_length parameter is length of the header_buffer.
       
   217 	EAP_FUNC_IMPORT eapol_header_wr_c(
       
   218 		abs_eap_am_tools_c * const tools,
       
   219 		u8_t * const header_buffer,
       
   220 		const u32_t header_buffer_length);
       
   221 
       
   222 	/// This function returns pointer to the header of the EAP-packet included in the EAPOL-packet.
       
   223 	EAP_FUNC_IMPORT u8_t * get_eap_header();
       
   224 
       
   225 	/// This function resets the EAPOL-header.
       
   226 	/// The buffer_length parameter is the length of the EAPOL-header and the following data buffer.
       
   227 	EAP_FUNC_IMPORT void reset_header(u16_t buffer_length);
       
   228 
       
   229 	// 
       
   230 	//--------------------------------------------------
       
   231 }; // class eapol_header_wr_c
       
   232 
       
   233 
       
   234 #endif //#if !defined(_EAPOL_HEADER_H_)
       
   235 
       
   236 //--------------------------------------------------
       
   237 
       
   238 
       
   239 
       
   240 // End.