eapol/eapol_framework/eapol_common/type/tls_peap/tls/src/tls_peap_tlv_payloads.cpp
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 // This is enumeration of EAPOL source code.
       
    20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    21 	#undef EAP_FILE_NUMBER_ENUM
       
    22 	#define EAP_FILE_NUMBER_ENUM 133 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 
       
    28 
       
    29 #include "tls_peap_tlv_payloads.h"
       
    30 #include "abs_eap_am_tools.h"
       
    31 #include "eap_tools.h"
       
    32 
       
    33 
       
    34 
       
    35 EAP_FUNC_EXPORT peap_tlv_variable_data_c::~peap_tlv_variable_data_c()
       
    36 {
       
    37 }
       
    38 
       
    39 EAP_FUNC_EXPORT peap_tlv_variable_data_c::peap_tlv_variable_data_c(abs_eap_am_tools_c * const tools)
       
    40 	: eap_variable_data_c(tools)
       
    41 	, m_am_tools(tools)
       
    42 	, m_original_header(tools, 0, 0)
       
    43 	, m_header_copy(tools)
       
    44 {
       
    45 }
       
    46 
       
    47 EAP_FUNC_EXPORT const tls_peap_tlv_header_c * peap_tlv_variable_data_c::get_original_header() const
       
    48 {
       
    49 	return &m_original_header;
       
    50 }
       
    51 
       
    52 EAP_FUNC_EXPORT eap_status_e peap_tlv_variable_data_c::set_buffer(
       
    53 	const tls_peap_tlv_header_c * const original_header,
       
    54 	u8_t *data_buffer,
       
    55 	const u32_t data_buffer_length,
       
    56 	const bool free_buffer,
       
    57 	const bool is_writable)
       
    58 {
       
    59 	m_original_header.set_header_buffer(
       
    60 		original_header->get_header_buffer(original_header->get_header_buffer_length()),
       
    61 		original_header->get_header_buffer_length());
       
    62 
       
    63 	eap_status_e status = eap_variable_data_c::set_buffer(data_buffer, data_buffer_length, free_buffer, is_writable);
       
    64 
       
    65 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    66 	return EAP_STATUS_RETURN(m_am_tools, status);
       
    67 }
       
    68 
       
    69 EAP_FUNC_EXPORT eap_status_e peap_tlv_variable_data_c::set_copy_of_buffer(
       
    70 	const tls_peap_tlv_header_c * const original_header)
       
    71 {
       
    72 	u32_t data_length = original_header->get_header_length()+original_header->get_data_length();
       
    73 
       
    74 	if (original_header->get_header_buffer_length() < data_length)
       
    75 	{
       
    76 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    77 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_payload);
       
    78 	}
       
    79 
       
    80 	eap_status_e status = m_header_copy.set_copy_of_buffer(
       
    81 		original_header->get_header_buffer(data_length),
       
    82 		data_length);
       
    83 	if (status != eap_status_ok)
       
    84 	{
       
    85 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    86 		return EAP_STATUS_RETURN(m_am_tools, status);
       
    87 	}
       
    88 
       
    89 	m_original_header.set_header_buffer(
       
    90 		m_header_copy.get_data(m_header_copy.get_data_length()),
       
    91 		m_header_copy.get_data_length());
       
    92 
       
    93 	tls_peap_tlv_header_c payload_copy(
       
    94 		m_am_tools,
       
    95 		m_header_copy.get_data(m_header_copy.get_data_length()),
       
    96 		m_header_copy.get_data_length());
       
    97 
       
    98 	status = eap_variable_data_c::set_buffer(
       
    99 		payload_copy.get_data(payload_copy.get_data_length()),
       
   100 		payload_copy.get_data_length(),
       
   101 		false,
       
   102 		false);
       
   103 	if (status != eap_status_ok)
       
   104 	{
       
   105 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   106 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   107 	}
       
   108 
       
   109 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   110 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   111 }
       
   112 
       
   113 
       
   114 
       
   115 EAP_FUNC_EXPORT peap_tlv_payloads_c::~peap_tlv_payloads_c()
       
   116 {
       
   117 }
       
   118 
       
   119 EAP_FUNC_EXPORT peap_tlv_payloads_c::peap_tlv_payloads_c(
       
   120 	abs_eap_am_tools_c * const tools)
       
   121 	: m_am_tools(tools)
       
   122 	, m_result_tlv(tools)
       
   123 	, m_nak_tlv(tools)
       
   124 	, m_crypto_binding_tlv(tools)
       
   125 	, m_eap_payload_tlv(tools)
       
   126 	, m_intermediate_result_tlv(tools)
       
   127 	, m_is_valid(false)
       
   128 {
       
   129 	m_is_valid = true;
       
   130 }
       
   131 
       
   132 EAP_FUNC_EXPORT bool peap_tlv_payloads_c::check_one_payload(
       
   133 	const peap_tlv_payload_status_e status,
       
   134 	const peap_tlv_variable_data_c * const payload)
       
   135 {
       
   136 	if (status == peap_tlv_payload_status_optional)
       
   137 	{
       
   138 		return true;
       
   139 	}
       
   140 	else if (status == peap_tlv_payload_status_must_not_be
       
   141 		&& payload->eap_variable_data_c::get_is_valid_data() == false)
       
   142 	{
       
   143 		return true;
       
   144 	}
       
   145 	else if (status == peap_tlv_payload_status_must_be
       
   146 		&& payload->eap_variable_data_c::get_is_valid_data() == true)
       
   147 	{
       
   148 		return true;
       
   149 	}
       
   150 	else
       
   151 	{
       
   152 		return false;
       
   153 	}
       
   154 }
       
   155 
       
   156 EAP_FUNC_EXPORT bool peap_tlv_payloads_c::check_payloads(
       
   157 	const peap_tlv_payload_status_e result_tlv,
       
   158 	const peap_tlv_payload_status_e nak_tlv,
       
   159 	const peap_tlv_payload_status_e crypto_binding_tlv,
       
   160 	const peap_tlv_payload_status_e eap_payload_tlv,
       
   161 	const peap_tlv_payload_status_e intermediate_result_tlv
       
   162 	)
       
   163 {
       
   164 	if (check_one_payload(result_tlv, get_result_tlv()) == true
       
   165 		&& check_one_payload(nak_tlv, get_nak_tlv()) == true
       
   166 		&& check_one_payload(crypto_binding_tlv, get_crypto_binding_tlv()) == true
       
   167 		&& check_one_payload(eap_payload_tlv, get_eap_payload_tlv()) == true
       
   168 		&& check_one_payload(intermediate_result_tlv, get_intermediate_result_tlv()) == true
       
   169 		)
       
   170 	{
       
   171 		return true;
       
   172 	}
       
   173 	else
       
   174 	{
       
   175 		return false;
       
   176 	}
       
   177 }
       
   178 
       
   179 EAP_FUNC_EXPORT peap_tlv_variable_data_c * peap_tlv_payloads_c::get_result_tlv()
       
   180 {
       
   181 	return static_cast<peap_tlv_variable_data_c *>(&m_result_tlv);
       
   182 }
       
   183 
       
   184 EAP_FUNC_EXPORT peap_tlv_variable_data_c * peap_tlv_payloads_c::get_nak_tlv()
       
   185 {
       
   186 	return static_cast<peap_tlv_variable_data_c *>(&m_nak_tlv);
       
   187 }
       
   188 
       
   189 EAP_FUNC_EXPORT peap_tlv_variable_data_c * peap_tlv_payloads_c::get_crypto_binding_tlv()
       
   190 {
       
   191 	return static_cast<peap_tlv_variable_data_c *>(&m_crypto_binding_tlv);
       
   192 }
       
   193 
       
   194 EAP_FUNC_EXPORT peap_tlv_variable_data_c * peap_tlv_payloads_c::get_eap_payload_tlv()
       
   195 {
       
   196 	return static_cast<peap_tlv_variable_data_c *>(&m_eap_payload_tlv);
       
   197 }
       
   198 
       
   199 EAP_FUNC_EXPORT peap_tlv_variable_data_c * peap_tlv_payloads_c::get_intermediate_result_tlv()
       
   200 {
       
   201 	return static_cast<peap_tlv_variable_data_c *>(&m_intermediate_result_tlv);
       
   202 }
       
   203 
       
   204 EAP_FUNC_EXPORT bool peap_tlv_payloads_c::get_is_valid() const
       
   205 {
       
   206 	return m_is_valid;
       
   207 }
       
   208 
       
   209 EAP_FUNC_EXPORT void peap_tlv_payloads_c::reset()
       
   210 {
       
   211 	m_result_tlv.reset();
       
   212 	m_nak_tlv.reset();
       
   213 	m_crypto_binding_tlv.reset();
       
   214 	m_eap_payload_tlv.reset();
       
   215 	m_intermediate_result_tlv.reset();
       
   216 	m_is_valid = false;
       
   217 }
       
   218 
       
   219 
       
   220 //--------------------------------------------------
       
   221 
       
   222 
       
   223 
       
   224 // End.