eapol/eapol_framework/eapol_common/core/eap_session_core.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 60 
       
    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_session_core.h"
       
    32 #include "eap_state_notification.h"
       
    33 #include "eap_network_id_selector.h"
       
    34 #include "abs_eap_am_mutex.h"
       
    35 #include "eap_config.h"
       
    36 #include "eap_core.h"
       
    37 #include "eap_buffer.h"
       
    38 #include "eap_base_type.h"
       
    39 #include "eap_automatic_variable.h"
       
    40 
       
    41 
       
    42 //--------------------------------------------------
       
    43 
       
    44 // 
       
    45 EAP_FUNC_EXPORT eap_session_core_c::~eap_session_core_c()
       
    46 {
       
    47 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    48 
       
    49 	EAP_TRACE_DEBUG(
       
    50 		m_am_tools, 
       
    51 		TRACE_FLAGS_DEFAULT, 
       
    52 		(EAPL("eap_session_core_c::~eap_session_core_c(): this = 0x%08x => 0x%08x.\n"),
       
    53 		this,
       
    54 		dynamic_cast<abs_eap_base_timer_c *>(this)));
       
    55 
       
    56 	EAP_ASSERT(m_shutdown_was_called == true);
       
    57 
       
    58 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    59 }
       
    60 
       
    61 //--------------------------------------------------
       
    62 
       
    63 #if defined(_WIN32) && !defined(__GNUC__)
       
    64 	#pragma warning( disable : 4355 ) // 'this' : used in base member initializer list
       
    65 #endif
       
    66 
       
    67 // 
       
    68 EAP_FUNC_EXPORT eap_session_core_c::eap_session_core_c(
       
    69 	abs_eap_am_tools_c * const tools,
       
    70 	abs_eap_core_c * const partner,
       
    71 	const bool is_client_when_true)
       
    72 : m_partner(partner)
       
    73 , m_am_tools(tools)
       
    74 , m_session_map(tools, this)
       
    75 , m_remove_session_timeout(EAP_SESSION_CORE_REMOVE_SESSION_TIMEOUT)
       
    76 , m_is_client(is_client_when_true)
       
    77 , m_is_valid(false)
       
    78 , m_use_eap_session_core_reset_session(true)
       
    79 , m_shutdown_was_called(false)
       
    80 {
       
    81 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    82 
       
    83 	EAP_TRACE_DEBUG(
       
    84 		m_am_tools, 
       
    85 		TRACE_FLAGS_DEFAULT, 
       
    86 		(EAPL("eap_session_core_c::eap_session_core_c(): this = 0x%08x => 0x%08x.\n"),
       
    87 		this,
       
    88 		dynamic_cast<abs_eap_base_timer_c *>(this)));
       
    89 
       
    90 	set_is_valid();
       
    91 
       
    92 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    93 }
       
    94 
       
    95 //--------------------------------------------------
       
    96 
       
    97 //
       
    98 EAP_FUNC_EXPORT abs_eap_core_c * eap_session_core_c::get_partner()
       
    99 {
       
   100 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   101 
       
   102 	return m_partner;
       
   103 }
       
   104 
       
   105 //--------------------------------------------------
       
   106 
       
   107 //
       
   108 EAP_FUNC_EXPORT void eap_session_core_c::set_is_valid()
       
   109 {
       
   110 	m_is_valid = true;
       
   111 }
       
   112 
       
   113 //--------------------------------------------------
       
   114 
       
   115 //
       
   116 EAP_FUNC_EXPORT bool eap_session_core_c::get_is_valid()
       
   117 {
       
   118 	return m_is_valid;
       
   119 }
       
   120 
       
   121 //--------------------------------------------------
       
   122 
       
   123 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::reset()
       
   124 {
       
   125 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   126 
       
   127 	EAP_TRACE_DEBUG(
       
   128 		m_am_tools, 
       
   129 		TRACE_FLAGS_DEFAULT, 
       
   130 		(EAPL("eap_session_core_c::reset(): this = 0x%08x => 0x%08x.\n"),
       
   131 		this,
       
   132 		dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   133 
       
   134 	eap_status_e status = m_session_map.for_each(shutdown_operation, true);
       
   135 	(void)EAP_STATUS_RETURN(m_am_tools, status);
       
   136 
       
   137 	status = m_session_map.reset();
       
   138 	(void)EAP_STATUS_RETURN(m_am_tools, status);
       
   139 
       
   140 	m_partner->cancel_timer(this, EAP_SESSION_CORE_REMOVE_SESSION_ID);
       
   141 
       
   142 	EAP_TRACE_DEBUG(
       
   143 		m_am_tools, 
       
   144 		TRACE_FLAGS_DEFAULT, 
       
   145 		(EAPL("TIMER: EAP_SESSION_CORE_REMOVE_SESSION_ID cancelled, %s.\n"),
       
   146 		 (m_is_client == true) ? "client": "server"));
       
   147 
       
   148 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   149 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   150 }
       
   151 
       
   152 //--------------------------------------------------
       
   153 
       
   154 //
       
   155 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::load_module(
       
   156 	const eap_type_value_e type,
       
   157 	const eap_type_value_e tunneling_type,
       
   158 	abs_eap_base_type_c * const partner,
       
   159 	eap_base_type_c ** const eap_type,
       
   160 	const bool is_client_when_true,
       
   161 	const eap_am_network_id_c * const receive_network_id)
       
   162 {
       
   163 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   164 
       
   165 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   166 
       
   167 	eap_status_e status = m_partner->load_module(
       
   168 		type,
       
   169 		tunneling_type,
       
   170 		partner,
       
   171 		eap_type,
       
   172 		is_client_when_true,
       
   173 		receive_network_id);
       
   174 
       
   175 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   176 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   177 }
       
   178 
       
   179 //--------------------------------------------------
       
   180 
       
   181 //
       
   182 EAP_FUNC_EXPORT eap_core_c * eap_session_core_c::create_new_session(
       
   183 	const eap_am_network_id_c * const receive_network_id)
       
   184 {
       
   185 	eap_status_e status = eap_status_process_general_error;
       
   186 
       
   187 	// Create a new session.
       
   188 	eap_core_c *session = new eap_core_c(
       
   189 		m_am_tools,
       
   190 		this,
       
   191 		m_is_client,
       
   192 		receive_network_id,
       
   193 		false);
       
   194 
       
   195 	if (session == 0)
       
   196 	{
       
   197 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   198 		(void)EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   199 		return 0;
       
   200 	}
       
   201 
       
   202 	if (session->get_is_valid() == false)
       
   203 	{
       
   204 		session->shutdown();
       
   205 		delete session;
       
   206 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   207 		(void)EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   208 		return 0;
       
   209 	}
       
   210 
       
   211 	status = session->configure();
       
   212 	if (status != eap_status_ok)
       
   213 	{
       
   214 		session->shutdown();
       
   215 		delete session;
       
   216 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   217 		(void)EAP_STATUS_RETURN(m_am_tools, status);
       
   218 		return 0;
       
   219 	}
       
   220 
       
   221 	// Here we swap the addresses.
       
   222 	eap_am_network_id_c send_network_id(m_am_tools,
       
   223 		receive_network_id->get_destination_id(),
       
   224 		receive_network_id->get_source_id(),
       
   225 		receive_network_id->get_type());
       
   226 	if (send_network_id.get_is_valid_data() == false)
       
   227 	{
       
   228 		session->shutdown();
       
   229 		delete session;
       
   230 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   231 		(void)EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   232 		return 0;
       
   233 	}
       
   234 
       
   235 	eap_network_id_selector_c selector(
       
   236 		m_am_tools,
       
   237 		&send_network_id);
       
   238 	if (selector.get_is_valid() == false)
       
   239 	{
       
   240 		session->shutdown();
       
   241 		delete session;
       
   242 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   243 		(void)EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   244 		return 0;
       
   245 	}
       
   246 
       
   247 	EAP_TRACE_DATA_DEBUG(
       
   248 		m_am_tools,
       
   249 		TRACE_FLAGS_DEFAULT,
       
   250 		(EAPL("create_new_session() EAP-session"),
       
   251 		 selector.get_data(selector.get_data_length()),
       
   252 		 selector.get_data_length()));
       
   253 
       
   254 	status = m_session_map.add_handler(&selector, session);
       
   255 	if (status != eap_status_ok)
       
   256 	{
       
   257 		session->shutdown();
       
   258 		delete session;
       
   259 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   260 		(void)EAP_STATUS_RETURN(m_am_tools, status);
       
   261 		return 0;
       
   262 	}
       
   263 
       
   264 	return session;
       
   265 }
       
   266 
       
   267 //--------------------------------------------------
       
   268 
       
   269 //
       
   270 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::reset_or_remove_session(
       
   271 	eap_core_c ** const session,
       
   272 	const eap_network_id_selector_c * const selector,
       
   273 	const bool reset_immediately)
       
   274 {
       
   275 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   276 
       
   277 	eap_status_e status(eap_status_process_general_error);
       
   278 
       
   279 	if (session == 0
       
   280 		|| *session == 0
       
   281 		|| selector == 0)
       
   282 	{
       
   283 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   284 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
   285 	}
       
   286 
       
   287 
       
   288 	if (m_use_eap_session_core_reset_session == true)
       
   289 	{
       
   290 		// This will reuse session.
       
   291 		EAP_TRACE_DEBUG(
       
   292 			m_am_tools, 
       
   293 			TRACE_FLAGS_DEFAULT, 
       
   294 			(EAPL("eap_session_core_c::reset_or_remove_session(): resets session, session 0x%08x.\n"),
       
   295 			(*session)));
       
   296 
       
   297 		// NOTE, this delayed reset of session is used bacause the device is so slow it cannot respond to
       
   298 		// 4-Way Handshake message fast enough.
       
   299 
       
   300 		if (reset_immediately == true)
       
   301 		{
       
   302 			(*session)->unset_marked_removed();
       
   303 
       
   304 			status = (*session)->reset();
       
   305 		}
       
   306 		else
       
   307 		{
       
   308 			// This will delay reset to eap_core_c::packet_process().
       
   309 			status = eap_status_ok;
       
   310 		}
       
   311 	}
       
   312 	else
       
   313 	{
       
   314 		//  This will cause shutdown of the session.
       
   315 		status = eap_status_process_general_error;
       
   316 	}
       
   317 
       
   318 	if (status != eap_status_ok)
       
   319 	{
       
   320 		// We cannot reuse the session.
       
   321 
       
   322 		EAP_TRACE_DEBUG(
       
   323 			m_am_tools, 
       
   324 			TRACE_FLAGS_DEFAULT, 
       
   325 			(EAPL("eap_session_core_c::reset_or_remove_session(): shutdown session, session 0x%08x.\n"),
       
   326 			(*session)));
       
   327 
       
   328 		(*session)->shutdown();
       
   329 		(*session) = 0;
       
   330 
       
   331 		status = m_session_map.remove_handler(selector, true);
       
   332 		if (status != eap_status_ok)
       
   333 		{
       
   334 			EAP_TRACE_DEBUG(
       
   335 				m_am_tools, 
       
   336 				TRACE_FLAGS_DEFAULT, 
       
   337 				(EAPL("ERROR: eap_session_core_c::reset_or_remove_session(): m_session_map.remove_type(), eap_status_e %d\n"),
       
   338 				status));
       
   339 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   340 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   341 		}
       
   342 
       
   343 		EAP_TRACE_DEBUG(
       
   344 			m_am_tools, 
       
   345 			TRACE_FLAGS_DEFAULT, 
       
   346 			(EAPL("eap_session_core_c::reset_or_remove_session(): session NOT reused.\n")));
       
   347 	}
       
   348 	else
       
   349 	{
       
   350 		EAP_TRACE_DEBUG(
       
   351 			m_am_tools, 
       
   352 			TRACE_FLAGS_DEFAULT, 
       
   353 			(EAPL("eap_session_core_c::reset_or_remove_session(): session reused, session 0x%08x.\n"),
       
   354 			(*session)));
       
   355 	}
       
   356 
       
   357 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   358 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   359 }
       
   360 
       
   361 //--------------------------------------------------
       
   362 
       
   363 //
       
   364 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::packet_process(
       
   365 	const eap_am_network_id_c * const receive_network_id,
       
   366 	eap_general_header_base_c * const packet_data,
       
   367 	const u32_t packet_length)
       
   368 {
       
   369 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   370 
       
   371 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   372 
       
   373 	eap_status_e status = eap_status_process_general_error;
       
   374 
       
   375 	// Each EAP authentication session includes own eap_core_c object.
       
   376 	// EAP authentication sessions are separated by eap_am_network_id_c object.
       
   377 
       
   378 	if (packet_data == 0
       
   379 		|| packet_length < eap_header_base_c::get_header_length())
       
   380 	{
       
   381 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   382 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_illegal_packet_error);
       
   383 	}
       
   384 
       
   385 	if (receive_network_id == 0
       
   386 		|| receive_network_id->get_is_valid_data() == false)
       
   387 	{
       
   388 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   389 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
   390 	}
       
   391 
       
   392 	eap_header_wr_c eap(
       
   393 		m_am_tools,
       
   394 		packet_data->get_header_buffer(packet_data->get_header_buffer_length()),
       
   395 		packet_data->get_header_buffer_length());
       
   396 
       
   397 	if (eap.get_is_valid() == false)
       
   398 	{
       
   399 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   400 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_illegal_packet_error);
       
   401 	}
       
   402 
       
   403 	if (packet_length < eap.get_length())
       
   404 	{
       
   405 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   406 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_illegal_packet_error);
       
   407 	}
       
   408 
       
   409 	if (eap.get_code() == eap_code_none)
       
   410 	{
       
   411 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   412 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_illegal_packet_error);
       
   413 	}
       
   414 
       
   415 	EAP_TRACE_DEBUG(
       
   416 		m_am_tools, 
       
   417 		TRACE_FLAGS_DEFAULT, 
       
   418 		(EAPL("-> EAP_session: %s, code=0x%02x=%s, identifier=0x%02x, ")
       
   419 		 EAPL("length=0x%04x, type=0x%08x=%s, packet length 0x%04x\n"),
       
   420 		(m_is_client == true) ? "client": "server",
       
   421 		eap.get_code(),
       
   422 		eap.get_code_string(),
       
   423 		eap.get_identifier(),
       
   424 		eap.get_length(),
       
   425 		convert_eap_type_to_u32_t(eap.get_type()),
       
   426 		eap.get_type_string(),
       
   427 		packet_length));
       
   428 
       
   429 	status = eap.check_header();
       
   430 	if (status != eap_status_ok)
       
   431 	{
       
   432 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   433 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   434 	}
       
   435 
       
   436 	// Here we swap the addresses.
       
   437 	eap_am_network_id_c send_network_id(m_am_tools,
       
   438 		receive_network_id->get_destination_id(),
       
   439 		receive_network_id->get_source_id(),
       
   440 		receive_network_id->get_type());
       
   441 	if (send_network_id.get_is_valid_data() == false)
       
   442 	{
       
   443 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   444 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   445 	}
       
   446 
       
   447 	eap_network_id_selector_c selector(
       
   448 		m_am_tools,
       
   449 		&send_network_id);
       
   450 	if (selector.get_is_valid() == false)
       
   451 	{
       
   452 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   453 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   454 	}
       
   455 
       
   456 	EAP_TRACE_DATA_DEBUG(
       
   457 		m_am_tools,
       
   458 		TRACE_FLAGS_DEFAULT,
       
   459 		(EAPL("packet_process() EAP-session"),
       
   460 		 selector.get_data(selector.get_data_length()),
       
   461 		 selector.get_data_length()));
       
   462 
       
   463 	eap_core_c *session = m_session_map.get_handler(&selector);
       
   464 
       
   465 	if (session == 0)
       
   466 	{
       
   467 
       
   468 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
   469 
       
   470 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   471 		return EAP_STATUS_RETURN(m_am_tools, eap_status_handler_does_not_exists_error);
       
   472 
       
   473 #else
       
   474 		// Create a new session.
       
   475 		session = create_new_session(receive_network_id);
       
   476 
       
   477 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
   478 
       
   479 	}
       
   480 
       
   481 	if (session != 0)
       
   482 	{
       
   483 		status = session->packet_process(
       
   484 			receive_network_id,
       
   485 			&eap,
       
   486 			packet_length);
       
   487 
       
   488 		EAP_GENERAL_HEADER_COPY_ERROR_PARAMETERS(packet_data, &eap);
       
   489 	}
       
   490 	else
       
   491 	{
       
   492 		status = eap_status_illegal_eap_type;
       
   493 	}
       
   494 
       
   495 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   496 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   497 }
       
   498 
       
   499 //--------------------------------------------------
       
   500 
       
   501 //
       
   502 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::packet_send(
       
   503 	const eap_am_network_id_c * const send_network_id,
       
   504 	eap_buf_chain_wr_c * const sent_packet,
       
   505 	const u32_t header_offset,
       
   506 	const u32_t data_length,
       
   507 	const u32_t buffer_length)
       
   508 {
       
   509 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   510 
       
   511 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   512 
       
   513 	eap_header_wr_c eap(
       
   514 		m_am_tools,
       
   515 		sent_packet->get_data_offset(header_offset, data_length),
       
   516 		data_length);
       
   517 
       
   518 	if (eap.get_is_valid() == false)
       
   519 	{
       
   520 		EAP_TRACE_DEBUG(
       
   521 			m_am_tools, 
       
   522 			TRACE_FLAGS_DEFAULT, 
       
   523 			(EAPL("packet_send: packet buffer corrupted.\n")));
       
   524 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   525 		return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted);
       
   526 	}
       
   527 
       
   528 	EAP_ASSERT(header_offset < sent_packet->get_data_length());
       
   529 	EAP_ASSERT(data_length <= sent_packet->get_data_length());
       
   530 	EAP_ASSERT(sent_packet->get_data_length() <= buffer_length);
       
   531 
       
   532 	EAP_TRACE_DEBUG(
       
   533 		m_am_tools, 
       
   534 		TRACE_FLAGS_DEFAULT, 
       
   535 		(EAPL("<- EAP_session: %s, code=0x%02x=%s, identifier=0x%02x, ")
       
   536 		 EAPL("length=0x%04x, type=0x%08x=%s, packet length 0x%04x\n"),
       
   537 		(m_is_client == true) ? "client": "server",
       
   538 		eap.get_code(),
       
   539 		eap.get_code_string(),
       
   540 		eap.get_identifier(),
       
   541 		eap.get_length(),
       
   542 		convert_eap_type_to_u32_t(eap.get_type()),
       
   543 		eap.get_type_string(),
       
   544 		data_length));
       
   545 
       
   546 	eap_status_e status = m_partner->packet_send(
       
   547 		send_network_id, sent_packet, header_offset, data_length, buffer_length);
       
   548 
       
   549 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   550 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   551 }
       
   552 
       
   553 //--------------------------------------------------
       
   554 
       
   555 //
       
   556 EAP_FUNC_EXPORT u32_t eap_session_core_c::get_header_offset(
       
   557 	u32_t * const MTU,
       
   558 	u32_t * const trailer_length)
       
   559 {
       
   560 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   561 
       
   562 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   563 
       
   564 	const u32_t offset = m_partner->get_header_offset(MTU, trailer_length);
       
   565 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   566 	return offset;
       
   567 }
       
   568 
       
   569 //--------------------------------------------------
       
   570 
       
   571 //
       
   572 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::configure()
       
   573 {
       
   574 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   575 
       
   576 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   577 
       
   578 
       
   579 	{
       
   580 		// This is optional.
       
   581 		eap_variable_data_c data(m_am_tools);
       
   582 
       
   583 		eap_status_e status = m_partner->read_configure(
       
   584 			cf_str_EAP_SESSION_use_reset_session.get_field(),
       
   585 			&data);
       
   586 		if (status == eap_status_ok
       
   587 			&& data.get_data_length() == sizeof(u32_t)
       
   588 			&& data.get_data(data.get_data_length()) != 0)
       
   589 		{
       
   590 			u32_t *flag = reinterpret_cast<u32_t *>(data.get_data(data.get_data_length()));
       
   591 
       
   592 			if (flag != 0)
       
   593 			{
       
   594 				if ((*flag) != 0ul)
       
   595 				{
       
   596 					m_use_eap_session_core_reset_session = true;
       
   597 				}
       
   598 				else
       
   599 				{
       
   600 					m_use_eap_session_core_reset_session = false;
       
   601 				}
       
   602 			}
       
   603 		}
       
   604 	}
       
   605 
       
   606 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   607 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   608 }
       
   609 
       
   610 //--------------------------------------------------
       
   611 
       
   612 //
       
   613 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::shutdown_operation(
       
   614 	eap_core_c * const core,
       
   615 	abs_eap_am_tools_c * const m_am_tools)
       
   616 {
       
   617 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   618 
       
   619 	EAP_UNREFERENCED_PARAMETER(m_am_tools);
       
   620 
       
   621 	eap_status_e status = core->shutdown();
       
   622 
       
   623 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   624 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   625 }
       
   626 
       
   627 //--------------------------------------------------
       
   628 
       
   629 //
       
   630 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::shutdown()
       
   631 {
       
   632 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   633 
       
   634 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   635 
       
   636 	EAP_TRACE_DEBUG(
       
   637 		m_am_tools, 
       
   638 		TRACE_FLAGS_DEFAULT, 
       
   639 		(EAPL("eap_session_core_c::shutdown(): this = 0x%08x => 0x%08x.\n"),
       
   640 		this,
       
   641 		dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   642 
       
   643 	if (m_shutdown_was_called == true)
       
   644 	{
       
   645 		// Shutdown function was called already.
       
   646 		return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   647 	}
       
   648 	m_shutdown_was_called = true;
       
   649 
       
   650 	eap_status_e status = reset();
       
   651 
       
   652 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   653 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   654 }
       
   655 
       
   656 //--------------------------------------------------
       
   657 
       
   658 //
       
   659 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::unload_module(const eap_type_value_e type)
       
   660 {
       
   661 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   662 
       
   663 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   664 
       
   665 	const eap_status_e status = m_partner->unload_module(type);
       
   666 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   667 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   668 }
       
   669 
       
   670 //--------------------------------------------------
       
   671 
       
   672 //
       
   673 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::eap_acknowledge(
       
   674 	const eap_am_network_id_c * const receive_network_id)
       
   675 {
       
   676 	// Any Network Protocol packet is accepted as a success indication.
       
   677 	// This is described in RFC 2284 "PPP Extensible Authentication Protocol (EAP)".
       
   678 
       
   679 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   680 
       
   681 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   682 
       
   683 	eap_status_e status = eap_status_process_general_error;
       
   684 
       
   685 	if (receive_network_id == 0)
       
   686 	{
       
   687 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   688 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
   689 	}
       
   690 
       
   691 	// Here we swap the addresses.
       
   692 	eap_am_network_id_c send_network_id(m_am_tools,
       
   693 		receive_network_id->get_destination_id(),
       
   694 		receive_network_id->get_source_id(),
       
   695 		receive_network_id->get_type());
       
   696 	if (send_network_id.get_is_valid_data() == false)
       
   697 	{
       
   698 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   699 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   700 	}
       
   701 
       
   702 	eap_network_id_selector_c selector(
       
   703 		m_am_tools,
       
   704 		&send_network_id);
       
   705 	if (selector.get_is_valid() == false)
       
   706 	{
       
   707 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   708 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   709 	}
       
   710 
       
   711 	EAP_TRACE_DATA_DEBUG(
       
   712 		m_am_tools,
       
   713 		TRACE_FLAGS_DEFAULT,
       
   714 		(EAPL("eap_acknowledge() EAP-session"),
       
   715 		 selector.get_data(selector.get_data_length()),
       
   716 		 selector.get_data_length()));
       
   717 
       
   718 	eap_core_c *session = m_session_map.get_handler(&selector);
       
   719 
       
   720 	if (session != 0)
       
   721 	{
       
   722 		status = session->eap_acknowledge(
       
   723 			receive_network_id);
       
   724 	}
       
   725 	else
       
   726 	{
       
   727 		// Here we do not care of missing session.
       
   728 		// Acknowledge is meaningfull only for existing session.
       
   729 		status = eap_status_ok;
       
   730 	}
       
   731 
       
   732 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   733 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   734 }
       
   735 
       
   736 //--------------------------------------------------
       
   737 
       
   738 //
       
   739 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::restart_authentication(
       
   740 	const eap_am_network_id_c * const send_network_id,
       
   741 	const bool is_client_when_true)
       
   742 {
       
   743 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   744 
       
   745 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   746 
       
   747 	eap_status_e status = eap_status_process_general_error;
       
   748 
       
   749 	eap_network_id_selector_c selector(
       
   750 		m_am_tools,
       
   751 		send_network_id);
       
   752 	if (selector.get_is_valid() == false)
       
   753 	{
       
   754 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   755 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   756 	}
       
   757 
       
   758 	EAP_TRACE_DATA_DEBUG(
       
   759 		m_am_tools,
       
   760 		TRACE_FLAGS_DEFAULT,
       
   761 		(EAPL("restart_authentication() EAP-session"),
       
   762 		 selector.get_data(selector.get_data_length()),
       
   763 		 selector.get_data_length()));
       
   764 
       
   765 	eap_core_c *session = m_session_map.get_handler(&selector);
       
   766 
       
   767 	if (session != 0)
       
   768 	{
       
   769 		status = session->restart_authentication(send_network_id, is_client_when_true);
       
   770 	}
       
   771 
       
   772 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   773 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   774 }
       
   775 
       
   776 //--------------------------------------------------
       
   777 
       
   778 //
       
   779 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::restart_authentication(
       
   780 	const eap_am_network_id_c * const receive_network_id,
       
   781 	const bool /* is_client_when_true */,
       
   782 	const bool force_clean_restart,
       
   783 	const bool /* from_timer */)
       
   784 {
       
   785 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   786 
       
   787 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   788 
       
   789 	eap_status_e status = eap_status_process_general_error;
       
   790 
       
   791 	// Here we swap the addresses.
       
   792 	eap_am_network_id_c send_network_id(m_am_tools,
       
   793 		receive_network_id->get_destination_id(),
       
   794 		receive_network_id->get_source_id(),
       
   795 		receive_network_id->get_type());
       
   796 	if (send_network_id.get_is_valid_data() == false)
       
   797 	{
       
   798 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   799 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   800 	}
       
   801 
       
   802 	eap_network_id_selector_c selector(
       
   803 		m_am_tools,
       
   804 		&send_network_id);
       
   805 	if (selector.get_is_valid() == false)
       
   806 	{
       
   807 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   808 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   809 	}
       
   810 
       
   811 	EAP_TRACE_DATA_DEBUG(
       
   812 		m_am_tools,
       
   813 		TRACE_FLAGS_DEFAULT,
       
   814 		(EAPL("restart_authentication() EAP-session"),
       
   815 		 selector.get_data(selector.get_data_length()),
       
   816 		 selector.get_data_length()));
       
   817 
       
   818 	eap_core_c *session = m_session_map.get_handler(&selector);
       
   819 
       
   820 	if (session == 0)
       
   821 	{
       
   822 		// Create a new session.
       
   823 		session = create_new_session(receive_network_id);
       
   824 	}
       
   825 
       
   826 	if (session != 0)
       
   827 	{
       
   828 		status = m_partner->restart_authentication(
       
   829 			receive_network_id,
       
   830 			m_is_client,
       
   831 			force_clean_restart);
       
   832 	}
       
   833 
       
   834 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   835 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   836 }
       
   837 
       
   838 //--------------------------------------------------
       
   839 
       
   840 #if defined(USE_EAP_CORE_SERVER)
       
   841 
       
   842 //
       
   843 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::send_eap_identity_request(
       
   844 	const eap_am_network_id_c * const receive_network_id)
       
   845 {
       
   846 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   847 
       
   848 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   849 
       
   850 	eap_status_e status = eap_status_process_general_error;
       
   851 
       
   852 	EAP_TRACE_DEBUG(
       
   853 		m_am_tools, 
       
   854 		TRACE_FLAGS_DEFAULT, 
       
   855 		(EAPL("eap_session_core_c::send_eap_identity_request()\n")));
       
   856 
       
   857 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_session_core_c::send_eap_identity_request()");
       
   858 
       
   859 	// Here we swap the addresses.
       
   860 	eap_am_network_id_c send_network_id(m_am_tools,
       
   861 		receive_network_id->get_destination_id(),
       
   862 		receive_network_id->get_source_id(),
       
   863 		receive_network_id->get_type());
       
   864 	if (send_network_id.get_is_valid_data() == false)
       
   865 	{
       
   866 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   867 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   868 	}
       
   869 
       
   870 	eap_network_id_selector_c selector(
       
   871 		m_am_tools,
       
   872 		&send_network_id);
       
   873 	if (selector.get_is_valid() == false)
       
   874 	{
       
   875 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   876 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   877 	}
       
   878 
       
   879 	EAP_TRACE_DATA_DEBUG(
       
   880 		m_am_tools,
       
   881 		TRACE_FLAGS_DEFAULT,
       
   882 		(EAPL("send_eap_identity_request() EAP-session"),
       
   883 		 selector.get_data(selector.get_data_length()),
       
   884 		 selector.get_data_length()));
       
   885 
       
   886 	eap_core_c *session = m_session_map.get_handler(&selector);
       
   887 
       
   888 	if (session == 0)
       
   889 	{
       
   890 		// Create a new session.
       
   891 		session = create_new_session(receive_network_id);
       
   892 	}
       
   893 
       
   894 	if (session != 0)
       
   895 	{
       
   896 		status = session->send_eap_identity_request(receive_network_id);
       
   897 		(void)EAP_STATUS_RETURN(m_am_tools, status);
       
   898 	}
       
   899 
       
   900 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   901 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   902 }
       
   903 
       
   904 #endif //#if defined(USE_EAP_CORE_SERVER)
       
   905 
       
   906 //--------------------------------------------------
       
   907 
       
   908 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::packet_data_crypto_keys(
       
   909 	const eap_am_network_id_c * const send_network_id,
       
   910 	const eap_master_session_key_c * const master_session_key
       
   911 	)
       
   912 {
       
   913 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   914 
       
   915 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   916 
       
   917 	const eap_status_e status = m_partner->packet_data_crypto_keys(
       
   918 		send_network_id,
       
   919 		master_session_key);
       
   920 
       
   921 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   922 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   923 }
       
   924 
       
   925 //--------------------------------------------------
       
   926 
       
   927 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::read_configure(
       
   928 	const eap_configuration_field_c * const field,
       
   929 	eap_variable_data_c * const data)
       
   930 {
       
   931 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   932 
       
   933 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   934 
       
   935 	const eap_status_e status = m_partner->read_configure(field, data);
       
   936 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   937 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   938 }
       
   939 
       
   940 //--------------------------------------------------
       
   941 
       
   942 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::write_configure(
       
   943 	const eap_configuration_field_c * const field,
       
   944 	eap_variable_data_c * const data)
       
   945 {
       
   946 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   947 
       
   948 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   949 
       
   950 	const eap_status_e status = m_partner->write_configure(field, data);
       
   951 
       
   952 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   953 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   954 }
       
   955 
       
   956 //--------------------------------------------------
       
   957 
       
   958 //
       
   959 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::timer_expired(
       
   960 	const u32_t id, void *data)
       
   961 {
       
   962 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   963 
       
   964 	EAP_TRACE_DEBUG(
       
   965 		m_am_tools, 
       
   966 		TRACE_FLAGS_DEFAULT, 
       
   967 		(EAPL("TIMER: [0x%08x]->eap_session_core_c::")
       
   968 		 EAPL("timer_expired(id 0x%02x, data 0x%08x), %s.\n"),
       
   969 		 this,
       
   970 		 id,
       
   971 		 data,
       
   972 		 (m_is_client == true) ? "client": "server"));
       
   973 
       
   974 	if (id == EAP_SESSION_CORE_REMOVE_SESSION_ID)
       
   975 	{
       
   976 		EAP_TRACE_DEBUG(
       
   977 			m_am_tools, 
       
   978 			TRACE_FLAGS_DEFAULT, 
       
   979 			(EAPL("TIMER: EAP_SESSION_CORE_REMOVE_SESSION_ID elapsed, %s.\n"),
       
   980 			 (m_is_client == true) ? "client": "server"));
       
   981 
       
   982 		const eap_network_id_selector_c * const selector 
       
   983 			= reinterpret_cast<const eap_network_id_selector_c *>(data);
       
   984 		if (selector == 0
       
   985 			|| selector->get_is_valid() == false)
       
   986 		{
       
   987 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   988 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   989 		}
       
   990 
       
   991 		EAP_TRACE_DATA_DEBUG(
       
   992 			m_am_tools,
       
   993 			TRACE_FLAGS_DEFAULT,
       
   994 			(EAPL("timer_expired() EAP-session"),
       
   995 			 selector->get_data(selector->get_data_length()),
       
   996 			 selector->get_data_length()));
       
   997 
       
   998 		eap_core_c *session = m_session_map.get_handler(selector);
       
   999 
       
  1000 		if (session != 0
       
  1001 			&& session->get_marked_removed() == true)
       
  1002 		{
       
  1003 			EAP_TRACE_DEBUG(
       
  1004 				m_am_tools, 
       
  1005 				TRACE_FLAGS_DEFAULT, 
       
  1006 				(EAPL("TIMER: unused session found, it is deleted, session 0x%08x.\n"),
       
  1007 				session));
       
  1008 
       
  1009 			// Session must be deleted here.
       
  1010 			session->shutdown();
       
  1011 			session = 0;
       
  1012 
       
  1013 			// This will delete session.
       
  1014 			eap_status_e status = m_session_map.remove_handler(selector, true);
       
  1015 			if (status != eap_status_ok)
       
  1016 			{
       
  1017 				EAP_TRACE_DEBUG(
       
  1018 					m_am_tools, 
       
  1019 					TRACE_FLAGS_DEFAULT, 
       
  1020 					(EAPL("ERROR: m_session_map.remove_type(), eap_status_e %d\n"),
       
  1021 					 status));
       
  1022 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1023 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  1024 			}
       
  1025 		}
       
  1026 		else if (session != 0
       
  1027 			&& session->get_marked_removed() == false)
       
  1028 		{
       
  1029 			EAP_TRACE_DEBUG(
       
  1030 				m_am_tools, 
       
  1031 				TRACE_FLAGS_DEFAULT, 
       
  1032 				(EAPL("TIMER: session found, it is in use, session 0x%08x.\n"),
       
  1033 				session));
       
  1034 		}
       
  1035 		else
       
  1036 		{
       
  1037 			// Not found, no need to remove.
       
  1038 			EAP_TRACE_DEBUG(
       
  1039 				m_am_tools, 
       
  1040 				TRACE_FLAGS_DEFAULT, 
       
  1041 				(EAPL("TIMER: session not found.\n")));
       
  1042 		}
       
  1043 	}
       
  1044 
       
  1045 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1046 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  1047 }
       
  1048 
       
  1049 //--------------------------------------------------
       
  1050 
       
  1051 //
       
  1052 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::timer_delete_data(
       
  1053 	const u32_t id, void *data)
       
  1054 {
       
  1055 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1056 
       
  1057 	EAP_TRACE_DEBUG(
       
  1058 		m_am_tools, 
       
  1059 		TRACE_FLAGS_DEFAULT, 
       
  1060 		(EAPL("TIMER: [0x%08x]->eap_session_core_c::")
       
  1061 		 EAPL("timer_delete_data(id 0x%02x, data 0x%08x).\n"),
       
  1062 		this, id, data));
       
  1063 
       
  1064 	if (id == EAP_SESSION_CORE_REMOVE_SESSION_ID)
       
  1065 
       
  1066 	{
       
  1067 		const eap_network_id_selector_c * const selector 
       
  1068 			= reinterpret_cast<const eap_network_id_selector_c *>(data);
       
  1069 		delete selector;
       
  1070 	}
       
  1071 
       
  1072 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1073 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  1074 }
       
  1075 
       
  1076 //--------------------------------------------------
       
  1077 
       
  1078 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::synchronous_cancel_all_eap_sessions()
       
  1079 {
       
  1080 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1081 
       
  1082 	EAP_TRACE_DEBUG(
       
  1083 		m_am_tools, 
       
  1084 		TRACE_FLAGS_DEFAULT, 
       
  1085 		(EAPL("eap_session_core_c::synchronous_cancel_all_eap_sessions(): this = 0x%08x => 0x%08x.\n"),
       
  1086 		this,
       
  1087 		dynamic_cast<abs_eap_base_timer_c *>(this)));
       
  1088 
       
  1089 	eap_status_e status = reset();
       
  1090 
       
  1091 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1092 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1093 }
       
  1094 
       
  1095 //--------------------------------------------------
       
  1096 
       
  1097 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  1098 
       
  1099 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::synchronous_create_eap_session(
       
  1100 	const eap_am_network_id_c * const receive_network_id)
       
  1101 {
       
  1102 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1103 
       
  1104 	EAP_TRACE_DEBUG(
       
  1105 		m_am_tools, 
       
  1106 		TRACE_FLAGS_DEFAULT, 
       
  1107 		(EAPL("eap_session_core_c::synchronous_create_eap_session(): this = 0x%08x => 0x%08x.\n"),
       
  1108 		this,
       
  1109 		dynamic_cast<abs_eap_base_timer_c *>(this)));
       
  1110 
       
  1111 	eap_status_e status = eap_status_process_general_error;
       
  1112 
       
  1113 	// Here we swap the addresses.
       
  1114 	eap_am_network_id_c send_network_id(
       
  1115 		m_am_tools,
       
  1116 		receive_network_id->get_destination_id(),
       
  1117 		receive_network_id->get_source_id(),
       
  1118 		receive_network_id->get_type());
       
  1119 	if (send_network_id.get_is_valid_data() == false)
       
  1120 	{
       
  1121 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1122 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1123 	}
       
  1124 
       
  1125 	eap_network_id_selector_c selector(
       
  1126 		m_am_tools,
       
  1127 		&send_network_id);
       
  1128 	if (selector.get_is_valid() == false)
       
  1129 	{
       
  1130 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1131 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1132 	}
       
  1133 
       
  1134 	EAP_TRACE_DATA_DEBUG(
       
  1135 		m_am_tools,
       
  1136 		TRACE_FLAGS_DEFAULT,
       
  1137 		(EAPL("synchronous_create_eap_session() EAP-session"),
       
  1138 		 selector.get_data(selector.get_data_length()),
       
  1139 		 selector.get_data_length()));
       
  1140 
       
  1141 	eap_core_c *session = m_session_map.get_handler(&selector);
       
  1142 
       
  1143 	if (session == 0)
       
  1144 	{
       
  1145 		session = create_new_session(receive_network_id);
       
  1146 
       
  1147 		if (session == 0)
       
  1148 		{
       
  1149 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1150 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1151 		}
       
  1152 		else
       
  1153 		{
       
  1154 			status = eap_status_ok;
       
  1155 		}
       
  1156 	}
       
  1157 	else
       
  1158 	{
       
  1159 		status = eap_status_ok;
       
  1160 	}
       
  1161 
       
  1162 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1163 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1164 }
       
  1165 
       
  1166 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  1167 
       
  1168 //--------------------------------------------------
       
  1169 
       
  1170 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::synchronous_remove_eap_session(
       
  1171 	const eap_am_network_id_c * const receive_network_id)
       
  1172 {
       
  1173 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1174 
       
  1175 	EAP_TRACE_DEBUG(
       
  1176 		m_am_tools, 
       
  1177 		TRACE_FLAGS_DEFAULT, 
       
  1178 		(EAPL("eap_session_core_c::synchronous_remove_eap_session(): this = 0x%08x => 0x%08x.\n"),
       
  1179 		this,
       
  1180 		dynamic_cast<abs_eap_base_timer_c *>(this)));
       
  1181 
       
  1182 	eap_status_e status = eap_status_process_general_error;
       
  1183 
       
  1184 	// Here we swap the addresses.
       
  1185 	eap_am_network_id_c send_network_id(
       
  1186 		m_am_tools,
       
  1187 		receive_network_id->get_destination_id(),
       
  1188 		receive_network_id->get_source_id(),
       
  1189 		receive_network_id->get_type());
       
  1190 	if (send_network_id.get_is_valid_data() == false)
       
  1191 	{
       
  1192 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1193 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1194 	}
       
  1195 
       
  1196 	eap_network_id_selector_c selector(
       
  1197 		m_am_tools,
       
  1198 		&send_network_id);
       
  1199 	if (selector.get_is_valid() == false)
       
  1200 	{
       
  1201 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1202 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1203 	}
       
  1204 
       
  1205 	EAP_TRACE_DATA_DEBUG(
       
  1206 		m_am_tools,
       
  1207 		TRACE_FLAGS_DEFAULT,
       
  1208 		(EAPL("synchronous_remove_eap_session() EAP-session"),
       
  1209 		 selector.get_data(selector.get_data_length()),
       
  1210 		 selector.get_data_length()));
       
  1211 
       
  1212 	eap_core_c *session = m_session_map.get_handler(&selector);
       
  1213 
       
  1214 	if (session != 0)
       
  1215 	{
       
  1216 		// This reset is immediaete.
       
  1217 		status = reset_or_remove_session(
       
  1218 			&session,
       
  1219 			&selector,
       
  1220 			true);
       
  1221 		if (status != eap_status_ok)
       
  1222 		{
       
  1223 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1224 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1225 		}
       
  1226 	}
       
  1227 	else
       
  1228 	{
       
  1229 		// Not found, no need to remove.
       
  1230 		status = eap_status_ok;
       
  1231 	}
       
  1232 
       
  1233 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1234 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1235 }
       
  1236 
       
  1237 //--------------------------------------------------
       
  1238 
       
  1239 //
       
  1240 eap_status_e eap_session_core_c::asynchronous_init_remove_eap_session(
       
  1241 	const eap_am_network_id_c * const send_network_id)
       
  1242 {
       
  1243 	EAP_TRACE_DEBUG(
       
  1244 		m_am_tools, 
       
  1245 		TRACE_FLAGS_DEFAULT, 
       
  1246 		(EAPL("eap_session_core_c::asynchronous_init_remove_eap_session(): %s.\n"),
       
  1247 		 (m_is_client == true) ? "client": "server"));
       
  1248 
       
  1249 	eap_network_id_selector_c state_selector(
       
  1250 		m_am_tools,
       
  1251 		send_network_id);
       
  1252 	if (state_selector.get_is_valid() == false)
       
  1253 	{
       
  1254 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1255 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1256 	}
       
  1257 
       
  1258 	EAP_TRACE_DATA_DEBUG(
       
  1259 		m_am_tools,
       
  1260 		TRACE_FLAGS_DEFAULT,
       
  1261 		(EAPL("asynchronous_init_remove_eap_session() EAP-session"),
       
  1262 		 state_selector.get_data(state_selector.get_data_length()),
       
  1263 		 state_selector.get_data_length()));
       
  1264 
       
  1265 	eap_status_e status = asynchronous_init_remove_eap_session(
       
  1266 		&state_selector);
       
  1267 
       
  1268 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1269 }
       
  1270 
       
  1271 //--------------------------------------------------
       
  1272 
       
  1273 //
       
  1274 eap_status_e eap_session_core_c::asynchronous_init_remove_eap_session(
       
  1275 	const eap_network_id_selector_c * const state_selector)
       
  1276 {
       
  1277 	EAP_TRACE_DEBUG(
       
  1278 		m_am_tools, 
       
  1279 		TRACE_FLAGS_DEFAULT, 
       
  1280 		(EAPL("eap_session_core_c::asynchronous_init_remove_eap_session(): %s.\n"),
       
  1281 		 (m_is_client == true) ? "client": "server"));
       
  1282 
       
  1283 	// NOTE: we cannot call directly synchronous_remove_eap_session(), because we will
       
  1284 	// return from here to removed object.
       
  1285 
       
  1286 	eap_status_e status = eap_status_process_general_error;
       
  1287 
       
  1288 	EAP_TRACE_DATA_DEBUG(
       
  1289 		m_am_tools,
       
  1290 		TRACE_FLAGS_DEFAULT,
       
  1291 		(EAPL("asynchronous_init_remove_eap_session() EAP-session"),
       
  1292 		 state_selector->get_data(state_selector->get_data_length()),
       
  1293 		 state_selector->get_data_length()));
       
  1294 
       
  1295 	eap_core_c *session = m_session_map.get_handler(state_selector);
       
  1296 
       
  1297 	if (session != 0)
       
  1298 	{
       
  1299 		session->set_marked_removed();
       
  1300 
       
  1301 		// So we initiate a timer to remove session identified by state_selector.
       
  1302 		eap_network_id_selector_c * const copy_selector = state_selector->copy();
       
  1303 		if (copy_selector == 0
       
  1304 			|| copy_selector->get_is_valid() == false)
       
  1305 		{
       
  1306 			delete copy_selector;
       
  1307 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1308 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1309 		}
       
  1310 
       
  1311 		status = m_partner->set_timer(
       
  1312 			this,
       
  1313 			EAP_SESSION_CORE_REMOVE_SESSION_ID, 
       
  1314 			copy_selector,
       
  1315 			m_remove_session_timeout);
       
  1316 		if (status != eap_status_ok)
       
  1317 		{
       
  1318 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1319 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1320 		}
       
  1321 
       
  1322 		EAP_TRACE_DEBUG(
       
  1323 			m_am_tools, 
       
  1324 			TRACE_FLAGS_DEFAULT, 
       
  1325 			(EAPL("eap_session_core_c::asynchronous_init_remove_eap_session()")
       
  1326 			 EAPL(": %s: EAP_SESSION_CORE_REMOVE_SESSION_ID timer set %d ms.\n"),
       
  1327 			 (m_is_client == true) ? "client": "server",
       
  1328 			 m_remove_session_timeout));
       
  1329 	}
       
  1330 	else
       
  1331 	{
       
  1332 		// Not found, cannot remove.
       
  1333 		EAP_TRACE_DEBUG(
       
  1334 			m_am_tools, 
       
  1335 			TRACE_FLAGS_DEFAULT, 
       
  1336 			(EAPL("ERROR: eap_session_core_c::asynchronous_init_remove_eap_session()")
       
  1337 			 EAPL(": %s: failed session not found.\n"),
       
  1338 			 (m_is_client == true) ? "client": "server"));
       
  1339 
       
  1340 		status = eap_status_ok;
       
  1341 	}
       
  1342 
       
  1343 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1344 }
       
  1345 
       
  1346 //--------------------------------------------------
       
  1347 
       
  1348 EAP_FUNC_EXPORT void eap_session_core_c::state_notification(
       
  1349 	const abs_eap_state_notification_c * const state)
       
  1350 {
       
  1351 	m_partner->state_notification(state);
       
  1352 }
       
  1353 
       
  1354 //--------------------------------------------------
       
  1355 
       
  1356 //
       
  1357 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::set_timer(
       
  1358 	abs_eap_base_timer_c * const p_initializer, 
       
  1359 	const u32_t p_id, 
       
  1360 	void * const p_data,
       
  1361 	const u32_t p_time_ms)
       
  1362 {
       
  1363 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1364 
       
  1365 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1366 
       
  1367 	const eap_status_e status = m_partner->set_timer(
       
  1368 		p_initializer, 
       
  1369 		p_id, 
       
  1370 		p_data,
       
  1371 		p_time_ms);
       
  1372 
       
  1373 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1374 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1375 }
       
  1376 
       
  1377 //--------------------------------------------------
       
  1378 
       
  1379 //
       
  1380 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::cancel_timer(
       
  1381 	abs_eap_base_timer_c * const p_initializer, 
       
  1382 	const u32_t p_id)
       
  1383 {
       
  1384 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1385 
       
  1386 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1387 
       
  1388 	const eap_status_e status = m_partner->cancel_timer(
       
  1389 		p_initializer, 
       
  1390 		p_id);
       
  1391 
       
  1392 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1393 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1394 }
       
  1395 
       
  1396 //--------------------------------------------------
       
  1397 
       
  1398 //
       
  1399 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::cancel_all_timers()
       
  1400 {
       
  1401 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1402 
       
  1403 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1404 
       
  1405 	const eap_status_e status = m_partner->cancel_all_timers();
       
  1406 
       
  1407 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1408 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1409 }
       
  1410 
       
  1411 //--------------------------------------------------
       
  1412 
       
  1413 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::check_is_valid_eap_type(
       
  1414 	const eap_type_value_e eap_type)
       
  1415 {
       
  1416 	eap_status_e status = m_partner->check_is_valid_eap_type(eap_type);
       
  1417 
       
  1418 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1419 }
       
  1420 
       
  1421 //--------------------------------------------------
       
  1422 
       
  1423 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::get_eap_type_list(
       
  1424 	eap_array_c<eap_type_value_e> * const eap_type_list)
       
  1425 {
       
  1426 	eap_status_e status = m_partner->get_eap_type_list(eap_type_list);
       
  1427 
       
  1428 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1429 }
       
  1430 
       
  1431 //--------------------------------------------------
       
  1432 
       
  1433 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::add_rogue_ap(
       
  1434 	eap_array_c<eap_rogue_ap_entry_c> & rogue_ap_list)
       
  1435 {
       
  1436 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1437 
       
  1438 	const eap_status_e status = m_partner->add_rogue_ap(rogue_ap_list);
       
  1439 
       
  1440 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1441 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1442 }
       
  1443 
       
  1444 //--------------------------------------------------
       
  1445 
       
  1446 //
       
  1447 EAP_FUNC_EXPORT eap_status_e eap_session_core_c::set_session_timeout(
       
  1448 	const u32_t /* session_timeout_ms */)
       
  1449 {
       
  1450 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1451 
       
  1452 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1453 
       
  1454 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1455 	return EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported);
       
  1456 }
       
  1457 
       
  1458 //--------------------------------------------------
       
  1459 
       
  1460 
       
  1461 
       
  1462 // End.