eapol/eapol_framework/eapol_common/core/eap_core_retransmission.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 47 
       
    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 "eap_am_memory.h"
       
    30 #include "eap_tools.h"
       
    31 #include "eap_am_export.h"
       
    32 #include "abs_eap_core.h"
       
    33 #include "eap_core.h"
       
    34 #include "eap_base_type.h"
       
    35 #include "eap_variable_data.h"
       
    36 #include "abs_eap_base_timer.h"
       
    37 #include "eap_core_retransmission.h"
       
    38 #include "eap_buffer.h"
       
    39 
       
    40 //--------------------------------------------------
       
    41 
       
    42 EAP_FUNC_EXPORT eap_core_retransmission_c::~eap_core_retransmission_c()
       
    43 {
       
    44 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    45 	if (m_send_network_id != 0)
       
    46 	{
       
    47 		delete m_send_network_id;
       
    48 		m_send_network_id = 0;
       
    49 	}
       
    50 	if (m_sent_packet != 0)
       
    51 	{
       
    52 		delete m_sent_packet;
       
    53 		m_sent_packet = 0;
       
    54 	}
       
    55 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    56 }
       
    57 
       
    58 //--------------------------------------------------
       
    59 
       
    60 EAP_FUNC_EXPORT eap_core_retransmission_c::eap_core_retransmission_c(
       
    61 	abs_eap_am_tools_c * const tools,
       
    62 	const eap_am_network_id_c * const send_network_id,
       
    63 	eap_buf_chain_wr_c * const sent_packet,
       
    64 	const u32_t header_offset,
       
    65 	const u32_t data_length,
       
    66 	const u32_t retransmission_time,
       
    67 	const u32_t retransmission_counter,
       
    68 	const eap_code_value_e eap_code,
       
    69 	const u8_t eap_identifier,
       
    70 	const eap_type_value_e eap_type)
       
    71 	: m_am_tools(tools)
       
    72 	, m_send_network_id(send_network_id->copy())
       
    73 	, m_sent_packet(sent_packet->copy())
       
    74 	, m_header_offset(header_offset)
       
    75 	, m_data_length(data_length)
       
    76 	, m_is_valid(false)
       
    77 	, m_retransmission_time(retransmission_time)
       
    78 	, m_retransmission_counter(retransmission_counter)
       
    79 	, m_eap_code(eap_code)
       
    80 	, m_eap_identifier(eap_identifier)
       
    81 	, m_eap_type(eap_type)
       
    82 {
       
    83 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    84 
       
    85 	if (m_send_network_id != 0
       
    86 		&& m_sent_packet != 0
       
    87 		&& m_send_network_id->get_is_valid_data() == true)
       
    88 	{
       
    89 		m_is_valid = true;
       
    90 	}
       
    91 	else
       
    92 	{
       
    93 		if (m_send_network_id != 0)
       
    94 		{
       
    95 			delete m_send_network_id;
       
    96 			m_send_network_id = 0;
       
    97 		}
       
    98 		if (m_send_network_id != 0)
       
    99 		{
       
   100 			delete m_sent_packet;
       
   101 			m_sent_packet = 0;
       
   102 		}
       
   103 	}
       
   104 
       
   105 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   106 }
       
   107 
       
   108 //--------------------------------------------------
       
   109 
       
   110 EAP_FUNC_EXPORT bool eap_core_retransmission_c::get_is_valid() const
       
   111 {
       
   112 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   113 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   114 	return m_is_valid;
       
   115 }
       
   116 
       
   117 //--------------------------------------------------
       
   118 
       
   119 EAP_FUNC_EXPORT u32_t eap_core_retransmission_c::get_next_retransmission_counter()
       
   120 {
       
   121 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   122 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   123 	return --m_retransmission_counter;
       
   124 }
       
   125 
       
   126 //--------------------------------------------------
       
   127 
       
   128 EAP_FUNC_EXPORT u32_t eap_core_retransmission_c::get_retransmission_counter() const
       
   129 {
       
   130 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   131 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   132 	return m_retransmission_counter;
       
   133 }
       
   134 
       
   135 //--------------------------------------------------
       
   136 
       
   137 EAP_FUNC_EXPORT u32_t eap_core_retransmission_c::get_next_retransmission_time()
       
   138 {
       
   139 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   140 	u32_t time = m_retransmission_time;
       
   141 
       
   142 	u32_t jitter_data = 0ul;
       
   143 	i32_t jitter = 0;
       
   144 	eap_status_e status = m_am_tools->get_crypto()->get_rand_bytes(
       
   145 		reinterpret_cast<u8_t *>(&jitter_data),
       
   146 		sizeof(jitter_data));
       
   147 	if (status != eap_status_ok)
       
   148 	{
       
   149 		jitter = 0;
       
   150 	}
       
   151 	else
       
   152 	{
       
   153 		// Jitter should be -m_retransmission_time/2 ... m_retransmission_time/2.
       
   154 		jitter_data = (jitter_data % (m_retransmission_time));
       
   155 		jitter = jitter_data - m_retransmission_time/2;
       
   156 	}
       
   157 	m_retransmission_time += (m_retransmission_time + jitter);
       
   158 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   159 	return time;
       
   160 }
       
   161 
       
   162 //--------------------------------------------------
       
   163 
       
   164 EAP_FUNC_EXPORT eap_am_network_id_c *eap_core_retransmission_c::get_send_network_id()
       
   165 {
       
   166 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   167 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   168 	return m_send_network_id;
       
   169 }
       
   170 
       
   171 //--------------------------------------------------
       
   172 
       
   173 EAP_FUNC_EXPORT eap_buf_chain_wr_c * eap_core_retransmission_c::get_sent_packet() const
       
   174 {
       
   175 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   176 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   177 	return m_sent_packet;
       
   178 }
       
   179 
       
   180 //--------------------------------------------------
       
   181 
       
   182 EAP_FUNC_EXPORT u32_t eap_core_retransmission_c::get_header_offset() const
       
   183 {
       
   184 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   185 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   186 	return m_header_offset;
       
   187 }
       
   188 
       
   189 //--------------------------------------------------
       
   190 
       
   191 EAP_FUNC_EXPORT u32_t eap_core_retransmission_c::get_data_length() const
       
   192 {
       
   193 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   194 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   195 	return m_data_length;
       
   196 }
       
   197 
       
   198 //--------------------------------------------------
       
   199 
       
   200 EAP_FUNC_EXPORT u32_t eap_core_retransmission_c::get_buffer_size() const
       
   201 {
       
   202 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   203 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   204 	return m_sent_packet->get_buffer_length();
       
   205 }
       
   206 
       
   207 //--------------------------------------------------
       
   208 
       
   209 EAP_FUNC_EXPORT eap_code_value_e eap_core_retransmission_c::get_eap_code() const
       
   210 {
       
   211 	return m_eap_code;
       
   212 }
       
   213 
       
   214 //--------------------------------------------------
       
   215 
       
   216 EAP_FUNC_EXPORT u8_t eap_core_retransmission_c::get_eap_identifier() const
       
   217 {
       
   218 	return m_eap_identifier;
       
   219 }
       
   220 
       
   221 //--------------------------------------------------
       
   222 
       
   223 EAP_FUNC_EXPORT eap_type_value_e eap_core_retransmission_c::get_eap_type() const
       
   224 {
       
   225 	return m_eap_type;
       
   226 }
       
   227 
       
   228 //--------------------------------------------------
       
   229 
       
   230 
       
   231 
       
   232 // End.