eapol/eapol_framework/eapol_common/type/tls_peap/tls/include/tls_peap_tlv_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(_TLS_PEAP_TLV_HEADER_H_)
       
    22 #define _TLS_PEAP_TLV_HEADER_H_
       
    23 
       
    24 #include "eap_tools.h"
       
    25 #include "eap_general_header_base.h"
       
    26 
       
    27 /** @file */
       
    28 
       
    29 
       
    30 /**
       
    31  * This is enumeration of PEAP Type-Length-Value (TLV) values.
       
    32  * See <a href="../../type/tls_peap/documentation/draft-puthenkulam-eap-binding-03.txt">draft-puthenkulam-eap-binding-03.txt</a>
       
    33  * and <a href="../../type/tls_peap/documentation/draft-josefsson-pppext-eap-tls-eap-07.txt">draft-josefsson-pppext-eap-tls-eap-07.txt</a>.
       
    34  */
       
    35 enum tls_peap_tlv_type_e
       
    36 {
       
    37 	tls_peap_tlv_type_reserved_zero       = 0,
       
    38 	tls_peap_tlv_type_reserved_one        = 1,
       
    39 	tls_peap_tlv_type_reserved_two        = 2,
       
    40 	tls_peap_tlv_type_result              = 3,  ///< RESULT_TLV
       
    41 	tls_peap_tlv_type_nak                 = 4,  ///< NAK_TLV
       
    42 	tls_peap_tlv_type_crypto_binding      = 5,  ///< CRYPTO_BINDING_TLV
       
    43 	tls_peap_tlv_eap_payload              = 8,  ///< EAP-Payload TLV
       
    44 	tls_peap_tlv_type_intermediate_result = 10, ///< Intermediate Result TLV
       
    45 	tls_peap_tlv_type_none                = 255,
       
    46 };
       
    47 
       
    48 
       
    49 enum tls_peap_tlv_type_crypto_binding_type_e
       
    50 {
       
    51 	tls_peap_tlv_type_crypto_binding_request = 0,
       
    52 	tls_peap_tlv_type_crypto_binding_response = 1,
       
    53 	tls_peap_tlv_type_crypto_binding_none = 0xff,
       
    54 };
       
    55 
       
    56 /**
       
    57  * This is enumeration of status values of result TLV.
       
    58  * See <a href="../../type/tls_peap/documentation/draft-puthenkulam-eap-binding-03.txt">draft-puthenkulam-eap-binding-03.txt</a>
       
    59  * and <a href="../../type/tls_peap/documentation/draft-josefsson-pppext-eap-tls-eap-07.txt">draft-josefsson-pppext-eap-tls-eap-07.txt</a>.
       
    60  */
       
    61 enum tls_peap_tlv_status_e
       
    62 {
       
    63 	tls_peap_tlv_status_none = 0,
       
    64 	tls_peap_tlv_status_success = 1,
       
    65 	tls_peap_tlv_status_failure = 2,
       
    66 };
       
    67 
       
    68 
       
    69 //----------------------------------------------------------------------------
       
    70 
       
    71 
       
    72 /// This class defines header of Attribute-Value Pairs.
       
    73 /**
       
    74  * Here is a figure of header of Attribute-Value Pairs.
       
    75  * Value data follows tls_peap_tlv_header_c.
       
    76  * @code
       
    77  *  TLV-header:
       
    78  *  0                   1                   2                   3   
       
    79  *  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 
       
    80  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    81  * |M|R|         TLV Type          |            Length             |
       
    82  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    83  * |                              Value...
       
    84  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
    85  * @endcode
       
    86  * 
       
    87  * @code
       
    88  * The fields of this header are:
       
    89  * 1-bit   flag mandatory tlv (M); Whether this TLV is mandatory (1)
       
    90  * 1-bit   flag reserved (R);      This is a reserved field, this is zero.
       
    91  * 14-bits TLV Type;               This is a TLV type.
       
    92  * 16-bits value length (Length);  This is a length field, the length (in bytes) of the following value.
       
    93  * @endcode
       
    94  * 
       
    95  * See <a href="../../type/tls_peap/documentation/draft-puthenkulam-eap-binding-03.txt">draft-puthenkulam-eap-binding-03.txt</a>
       
    96  * and <a href="../../type/tls_peap/documentation/draft-josefsson-pppext-eap-tls-eap-07.txt">draft-josefsson-pppext-eap-tls-eap-07.txt</a>.
       
    97  */
       
    98 class EAP_EXPORT tls_peap_tlv_header_c
       
    99 : public eap_general_header_base_c
       
   100 {
       
   101 private:
       
   102 	//--------------------------------------------------
       
   103 
       
   104 	/// This is pointer to the tools class.
       
   105 	abs_eap_am_tools_c * const m_am_tools;
       
   106 
       
   107 	/// This is enumeration of bit masks.
       
   108 	enum bit_masks
       
   109 	{
       
   110 		m_flag_mask_mandatory_tlv = 0x80,
       
   111 		m_flag_mask_reserved = 0x40,
       
   112 	};
       
   113 
       
   114 	//--------------------------------------------------
       
   115 protected:
       
   116 	//--------------------------------------------------
       
   117 
       
   118 	/// This is enumeration of offsets to data fields.
       
   119 	enum offsets
       
   120 	{
       
   121 		m_flags_and_tlv_type_offset = 0ul,                           ///< This is offset to fags and tlv type 16-bit field.
       
   122 		m_length_offset = m_flags_and_tlv_type_offset+sizeof(u16_t), ///< This is offset to length 16-bit field.
       
   123 		m_data_offset = m_length_offset+sizeof(u16_t),               ///< This is offset to data field.
       
   124 	};
       
   125 
       
   126 	//--------------------------------------------------
       
   127 public:
       
   128 	//--------------------------------------------------
       
   129 
       
   130 	/**
       
   131 	 * The destructor of the tls_peap_tlv_header_c class does nothing.
       
   132 	 */
       
   133 	virtual ~tls_peap_tlv_header_c();
       
   134 
       
   135 	/**
       
   136 	 * The constructor of the tls_peap_tlv_header_c class simply initializes the attributes.
       
   137 	 */
       
   138 	tls_peap_tlv_header_c(
       
   139 		abs_eap_am_tools_c * const tools,
       
   140 		void * const header_begin,
       
   141 		const u32_t header_buffer_length);
       
   142 
       
   143 	/**
       
   144 	 * This function returns the TLV type flag.
       
   145 	 */
       
   146 	tls_peap_tlv_type_e get_flag_tlv_type() const;
       
   147 
       
   148 	/**
       
   149 	 * This function returns the TLV mandatory flag.
       
   150 	 */
       
   151 	bool get_flag_mandatory_tlv() const;
       
   152 
       
   153 	/**
       
   154 	 * This function returns the TLV reserved flag.
       
   155 	 */
       
   156 	bool get_flag_reserved() const;
       
   157 
       
   158 	/**
       
   159 	 * This function returns the data length of TLV.
       
   160 	 */
       
   161 	u16_t get_data_length() const;
       
   162 
       
   163 	/**
       
   164 	 * This function returns the header length of TLV.
       
   165 	 */
       
   166 	static u32_t get_header_length();
       
   167 
       
   168 	/**
       
   169 	 * This function returns pointer to the offset of data of TLV.
       
   170 	 * @param offset is the offset of queried data in bytes.
       
   171 	 * @param contignuous_bytes is the length of queried data in bytes.
       
   172 	 */
       
   173 	u8_t * get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const;
       
   174 
       
   175 
       
   176 	/**
       
   177 	 * This function returns pointer to the offset of data of TLV.
       
   178 	 * @param contignuous_bytes is the length of queried data in bytes.
       
   179 	 */
       
   180 	u8_t * get_data(const u32_t contignuous_bytes) const;
       
   181 
       
   182 
       
   183 	/**
       
   184 	 * This function return pointer to the next TLV header in the same buffer.
       
   185 	 */
       
   186 	u8_t * get_next_header() const;
       
   187 
       
   188 
       
   189 	/**
       
   190 	 * This function checks the header is valid.
       
   191 	 */
       
   192 	eap_status_e check_header() const;
       
   193 
       
   194 	/**
       
   195 	 * This function returns debug strings of the TLV type.
       
   196 	 */
       
   197 	eap_const_string get_tlv_type_string() const;
       
   198 
       
   199 	/**
       
   200 	 * This function sets the TLV type flag.
       
   201 	 */
       
   202 	void set_flag_tlv_type(tls_peap_tlv_type_e type);
       
   203 
       
   204 	/**
       
   205 	 * This function sets the TLV reserved flag.
       
   206 	 */
       
   207 	void set_flag_reserved(bool reserved);
       
   208 
       
   209 	/**
       
   210 	 * This function sets the TLV manadtory flag.
       
   211 	 */
       
   212 	void set_flag_mandatory_tlv(const bool mandatory_when_true);
       
   213 
       
   214 	/**
       
   215 	 * This function sets the TLV data length.
       
   216 	 */
       
   217 	void set_data_length(const u16_t p_length);
       
   218 
       
   219 	/**
       
   220 	 * This function resets the TLV header.
       
   221 	 */
       
   222 	void reset_header(const u16_t buffer_length);
       
   223 
       
   224 	// 
       
   225 	//--------------------------------------------------
       
   226 }; // class tls_peap_tlv_header_c
       
   227 
       
   228 //--------------------------------------------------
       
   229 
       
   230 /// Macro traces payload type and data.
       
   231 #define TLS_PEAP_TLV_TRACE_PAYLOAD(prefix, payload) \
       
   232 	{ \
       
   233 		EAP_TRACE_DEBUG( \
       
   234 			m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \
       
   235 			(EAPL("v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v \n"))); \
       
   236 		EAP_TRACE_DEBUG( \
       
   237 			m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \
       
   238 			(EAPL("%s (0x%08x): M=%d, R=%d, TLV type 0x%08x=%s, data length 0x%04x.\n"), \
       
   239 			prefix, (payload)->get_header_buffer((payload)->get_data_length()), \
       
   240 			(payload)->get_flag_mandatory_tlv(), \
       
   241 			(payload)->get_flag_reserved(), \
       
   242 			(payload)->get_flag_tlv_type(), \
       
   243 			(payload)->get_tlv_type_string(), \
       
   244 			(payload)->get_data_length())); \
       
   245 		EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \
       
   246 			(EAPL("data"), (payload)->get_data((payload)->get_data_length()), \
       
   247 			(payload)->get_data_length())); \
       
   248 		EAP_TRACE_DEBUG( \
       
   249 			m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \
       
   250 			(EAPL("^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \n"))); \
       
   251 	}
       
   252 
       
   253 //--------------------------------------------------
       
   254 
       
   255 #endif //#if !defined(_TLS_PEAP_TLV_HEADER_H_)
       
   256 
       
   257 
       
   258 
       
   259 // End.