eapol/eapol_framework/eapol_common/core/eapol_wlan_authentication.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 57 
       
    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 // INCLUDE FILES
       
    29 
       
    30 #include "eap_am_memory.h"
       
    31 
       
    32 #include "eap_am_tools.h"
       
    33 #include "eap_variable_data.h"
       
    34 #include "eap_tools.h"
       
    35 #include "eap_type_all.h"
       
    36 
       
    37 #include "eapol_wlan_authentication.h"
       
    38 #include "eapol_ethernet_header.h"
       
    39 #include "ethernet_core.h"
       
    40 #include "eap_crypto_api.h"
       
    41 #include "eap_header_string.h"
       
    42 #include "eap_rogue_ap_entry.h"
       
    43 #include "abs_eap_state_notification.h"
       
    44 #include "eapol_session_key.h"
       
    45 #include "eap_buffer.h"
       
    46 #include "eap_config.h"
       
    47 #include "eap_array_algorithms.h"
       
    48 #include "eap_state_notification.h"
       
    49 #include "eap_automatic_variable.h"
       
    50 
       
    51 // LOCAL CONSTANTS
       
    52 
       
    53 enum eapol_am_core_timer_id_e
       
    54 {
       
    55 	EAPOL_WLAN_AUTHENTICATION_TIMER_FAILED_COMPLETELY_ID,
       
    56 	EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID,
       
    57 	EAPOL_WLAN_AUTHENTICATION_TIMER_NO_RESPONSE_ID,
       
    58 	EAPOL_WLAN_AUTHENTICATION_TIMER_AUTHENTICATION_CANCELLED_ID
       
    59 };
       
    60 
       
    61 #if defined(USE_EAPOL_WLAN_AUTHENTICATION_MUTEX)
       
    62 
       
    63 	#if defined(USE_TEST_WLAN_AUTHENTICATION_MUTEX)
       
    64 		#error "You cannot define both USE_EAPOL_WLAN_AUTHENTICATION_MUTEX and USE_TEST_WLAN_AUTHENTICATION_MUTEX."
       
    65 	#endif
       
    66 
       
    67 	#define WAUTH_ENTER_MUTEX(tools) { tools->enter_global_mutex(); }
       
    68 
       
    69 	#define WAUTH_LEAVE_MUTEX(tools) { tools->leave_global_mutex(); }
       
    70 
       
    71 #else
       
    72 
       
    73 	#define WAUTH_ENTER_MUTEX(tools)
       
    74 
       
    75 	#define WAUTH_LEAVE_MUTEX(tools)
       
    76 
       
    77 #endif //#if defined(USE_EAPOL_WLAN_AUTHENTICATION_MUTEX)
       
    78 
       
    79 // ================= MEMBER FUNCTIONS =======================
       
    80 
       
    81 EAP_FUNC_EXPORT eapol_wlan_authentication_c * eapol_wlan_authentication_c::new_eapol_wlan_authentication(
       
    82 	abs_eap_am_tools_c * const tools,
       
    83 	abs_eapol_wlan_authentication_c * const partner,
       
    84 	const bool is_client_when_true,
       
    85 	const abs_eapol_wlan_database_reference_if_c * const wlan_database_reference
       
    86 	)
       
    87 {
       
    88 	EAP_TRACE_DEBUG(
       
    89 		tools, 
       
    90 		TRACE_FLAGS_DEFAULT, 
       
    91 		(EAPL("partner calls: eapol_wlan_authentication_c::new_eapol_wlan_authentication()\n")));
       
    92 
       
    93 	EAP_TRACE_RETURN_STRING(tools, "returns to partner: eapol_wlan_authentication_c::new_eapol_wlan_authentication()");
       
    94 
       
    95 	eapol_am_wlan_authentication_c * m_am_wauth = eapol_am_wlan_authentication_c::new_eapol_am_wlan_authentication(
       
    96 		tools,
       
    97 		is_client_when_true,
       
    98 		wlan_database_reference);
       
    99 	if (m_am_wauth == 0
       
   100 		|| m_am_wauth->get_is_valid() == false)
       
   101 	{
       
   102 		// ERROR.
       
   103 		if (m_am_wauth != 0)
       
   104 		{
       
   105 			EAP_TRACE_DEBUG(
       
   106 				tools,
       
   107 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   108 				(EAPL("calls: eapol_wlan_authentication_c::new_eapol_wlan_authentication(): m_am_wauth->shutdown(): %s.\n"),
       
   109 				(is_client_when_true == true) ? "client": "server"));
       
   110 
       
   111 			m_am_wauth->shutdown();
       
   112 			delete m_am_wauth;
       
   113 			m_am_wauth = 0;
       
   114 		}
       
   115 		return 0;
       
   116 	}
       
   117 
       
   118 	eapol_wlan_authentication_c * wauth = new eapol_wlan_authentication_c(tools, partner, m_am_wauth, is_client_when_true);
       
   119 	if (wauth == 0
       
   120 		|| wauth->get_is_valid() == false)
       
   121 	{
       
   122 		// ERROR.
       
   123 		if (wauth != 0)
       
   124 		{
       
   125 			wauth->shutdown();
       
   126 			delete wauth;
       
   127 		}
       
   128 		return 0;
       
   129 	}
       
   130 
       
   131 	EAP_TRACE_DEBUG(
       
   132 		tools,
       
   133 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   134 		(EAPL("calls: eapol_wlan_authentication_c::new_eapol_wlan_authentication(): m_am_wauth->set_am_partner(): %s.\n"),
       
   135 		(is_client_when_true == true) ? "client": "server"));
       
   136 
       
   137 	m_am_wauth->set_am_partner(
       
   138 		wauth
       
   139 #if defined(USE_EAP_SIMPLE_CONFIG)
       
   140 		, wauth
       
   141 #endif // #if defined(USE_EAP_SIMPLE_CONFIG)
       
   142 		);
       
   143 
       
   144 	return wauth;
       
   145 }	
       
   146 
       
   147 //--------------------------------------------------
       
   148 
       
   149 EAP_FUNC_EXPORT eapol_wlan_authentication_c::eapol_wlan_authentication_c(
       
   150 	abs_eap_am_tools_c * const tools,
       
   151 	abs_eapol_wlan_authentication_c * const partner,
       
   152 	eapol_am_wlan_authentication_c * const am_wauth, ///< eapol_wlan_authentication_c must always delete the am_wauth object.
       
   153 	const bool is_client_when_true)
       
   154 : m_partner(partner)
       
   155 , m_am_wauth(am_wauth)
       
   156 , m_ethernet_core(0)
       
   157 , m_am_tools(tools)
       
   158 , m_selected_eap_types(tools)
       
   159 , m_wpa_preshared_key_hash(tools)
       
   160 , m_authentication_type(eapol_key_authentication_type_none)
       
   161 , m_802_11_authentication_mode(eapol_key_802_11_authentication_mode_none)
       
   162 , m_received_WPA_IE(tools) // WLM must give only the WPA IE to EAPOL
       
   163 , m_sent_WPA_IE(tools)
       
   164 , m_group_key_cipher_suite(eapol_RSNA_key_header_c::eapol_RSNA_cipher_none)
       
   165 , m_pairwise_key_cipher_suite(eapol_RSNA_key_header_c::eapol_RSNA_cipher_none)
       
   166 , m_current_eap_index(0ul)
       
   167 , m_authentication_counter(0u)
       
   168 , m_successful_authentications(0u)
       
   169 , m_failed_authentications(0u)
       
   170 , m_is_valid(false)
       
   171 , m_is_client(is_client_when_true)
       
   172 , m_shutdown_was_called(false)
       
   173 #if defined(USE_EAP_ERROR_TESTS)
       
   174 , m_randomly_drop_packets(false)
       
   175 , m_randomly_drop_packets_probability(0u)
       
   176 , m_error_probability(0u)
       
   177 , m_generate_multiple_error_packets(0u)
       
   178 , m_packet_index(0u)
       
   179 , m_enable_random_errors(false)
       
   180 , m_manipulate_ethernet_header(false)
       
   181 , m_send_original_packet_first(false)
       
   182 #endif //#if defined(USE_EAP_ERROR_TESTS)
       
   183 {
       
   184 	EAP_TRACE_DEBUG(
       
   185 		m_am_tools, 
       
   186 		TRACE_FLAGS_DEFAULT, 
       
   187 		(EAPL("starts: eapol_wlan_authentication_c::eapol_wlan_authentication_c(): %s, this = 0x%08x => 0x%08x, compiled %s %s.\n"),
       
   188 		(m_is_client == true) ? "client": "server",
       
   189 		this,
       
   190 		dynamic_cast<abs_eap_base_timer_c *>(this),
       
   191 		__DATE__,
       
   192 		__TIME__));
       
   193 
       
   194 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eapol_wlan_authentication_c::eapol_wlan_authentication_c()");
       
   195 
       
   196 	if (m_am_wauth == 0
       
   197 		|| m_am_wauth->get_is_valid() == false)
       
   198 	{
       
   199 		// ERROR.
       
   200 		if (m_am_wauth != 0)
       
   201 		{
       
   202 			EAP_TRACE_DEBUG(
       
   203 				m_am_tools,
       
   204 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   205 				(EAPL("calls: eapol_wlan_authentication_c::eapol_wlan_authentication_c(): m_am_wauth->shutdown(): %s.\n"),
       
   206 				(is_client_when_true == true) ? "client": "server"));
       
   207 
       
   208 			m_am_wauth->shutdown();
       
   209 			delete am_wauth;
       
   210 		}
       
   211 		return;
       
   212 	}
       
   213 
       
   214 	if (m_am_tools == 0
       
   215 		|| m_am_tools->get_is_valid() == false)
       
   216 	{
       
   217 		// ERROR.
       
   218 		if (m_am_wauth != 0)
       
   219 		{
       
   220 			EAP_TRACE_DEBUG(
       
   221 				m_am_tools,
       
   222 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   223 				(EAPL("calls: eapol_wlan_authentication_c::eapol_wlan_authentication_c(): m_am_wauth->shutdown(): %s.\n"),
       
   224 				(is_client_when_true == true) ? "client": "server"));
       
   225 
       
   226 			m_am_wauth->shutdown();
       
   227 			delete am_wauth;
       
   228 		}
       
   229 		return;
       
   230 	}
       
   231 
       
   232 	m_is_valid = true;
       
   233 }	
       
   234 
       
   235 //--------------------------------------------------
       
   236 
       
   237 EAP_FUNC_EXPORT eapol_wlan_authentication_c::~eapol_wlan_authentication_c()
       
   238 {
       
   239 	EAP_TRACE_DEBUG(
       
   240 		m_am_tools, 
       
   241 		TRACE_FLAGS_DEFAULT, 
       
   242 		(EAPL("partner calls: eapol_wlan_authentication_c::~eapol_wlan_authentication_c(): this = 0x%08x\n"),
       
   243 		this));
       
   244 
       
   245 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::~eapol_wlan_authentication_c()");
       
   246 
       
   247 	EAP_ASSERT(m_shutdown_was_called == true);
       
   248 }
       
   249 
       
   250 //--------------------------------------------------
       
   251 
       
   252 //
       
   253 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::shutdown()
       
   254 {
       
   255 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   256 
       
   257 	EAP_TRACE_DEBUG(
       
   258 		m_am_tools,
       
   259 		TRACE_FLAGS_DEFAULT,
       
   260 		(EAPL("partner calls: eapol_wlan_authentication_c::shutdown(); %s, m_shutdown_was_called=%d\n"),
       
   261 		(m_is_client == true) ? "client": "server",
       
   262 		m_shutdown_was_called));
       
   263 
       
   264 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::shutdown()");
       
   265 
       
   266 	if (m_shutdown_was_called == true)
       
   267 	{
       
   268 		// Shutdown was already called once.
       
   269 		return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   270 	}
       
   271 	m_shutdown_was_called = true;
       
   272 	
       
   273 	// Cancel timer	
       
   274 	cancel_all_timers();
       
   275 
       
   276 	// Delete upper stack if it still exists
       
   277 	if (m_ethernet_core != 0)
       
   278 	{
       
   279 		WAUTH_ENTER_MUTEX(m_am_tools);
       
   280 
       
   281 		EAP_TRACE_DEBUG(
       
   282 			m_am_tools,
       
   283 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   284 			(EAPL("calls eapol: eapol_wlan_authentication_c::shutdown(): m_ethernet_core->shutdown(): %s.\n"),
       
   285 			(m_is_client == true) ? "client": "server"));
       
   286 
       
   287 		eap_status_e status = m_ethernet_core->shutdown();
       
   288 		EAP_UNREFERENCED_PARAMETER(status);
       
   289 
       
   290 		EAP_TRACE_DEBUG(
       
   291 			m_am_tools,
       
   292 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   293 			(EAPL("returns from eapol: eapol_wlan_authentication_c::shutdown(): m_ethernet_core->shutdown(): %s, status = %s.\n"),
       
   294 			(m_is_client == true) ? "client": "server",
       
   295 			eap_status_string_c::get_status_string(status)));
       
   296 
       
   297 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
   298 
       
   299 		delete m_ethernet_core;
       
   300 		m_ethernet_core = 0;
       
   301 	}
       
   302 	
       
   303 	// Print some statistics
       
   304 	if (m_is_client)
       
   305 	{
       
   306 		EAP_TRACE_ALWAYS(
       
   307 			m_am_tools,
       
   308 			TRACE_FLAGS_ALWAYS|TRACE_TEST_VECTORS,
       
   309 			(EAPL("eapol_wlan_authentication_c::shutdown(): client authentication SUCCESS %d, FAILED %d, count %d\n"),
       
   310 			m_successful_authentications,
       
   311 			m_failed_authentications,
       
   312 			m_authentication_counter));	
       
   313 	}
       
   314 	else
       
   315 	{
       
   316 		EAP_TRACE_ALWAYS(
       
   317 			m_am_tools,
       
   318 			TRACE_FLAGS_ALWAYS|TRACE_TEST_VECTORS,
       
   319 			(EAPL("eapol_wlan_authentication_c::shutdown(): server authentication SUCCESS %d, FAILED %d, count %d\n"),
       
   320 			m_successful_authentications,
       
   321 			m_failed_authentications,
       
   322 			m_authentication_counter));
       
   323 	}
       
   324 
       
   325 
       
   326 	if (m_am_wauth != 0)
       
   327 	{
       
   328 		EAP_TRACE_DEBUG(
       
   329 			m_am_tools,
       
   330 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   331 			(EAPL("calls: eapol_wlan_authentication_c::shutdown(): m_am_wauth->shutdown(): %s.\n"),
       
   332 			(m_is_client == true) ? "client": "server"));
       
   333 
       
   334 		m_am_wauth->shutdown();
       
   335 		delete m_am_wauth;
       
   336 		m_am_wauth = 0;
       
   337 	}
       
   338 	
       
   339 	EAP_TRACE_DEBUG(
       
   340 		m_am_tools,
       
   341 		TRACE_FLAGS_DEFAULT,
       
   342 		(EAPL("WAUTH EXITING.\n")));
       
   343 
       
   344 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   345 	return eap_status_ok;
       
   346 }
       
   347 
       
   348 //--------------------------------------------------
       
   349 
       
   350 //
       
   351 eap_status_e eapol_wlan_authentication_c::cancel_all_authentication_sessions()
       
   352 {
       
   353 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   354 
       
   355 	EAP_TRACE_DEBUG(
       
   356 		m_am_tools,
       
   357 		TRACE_FLAGS_DEFAULT,
       
   358 		(EAPL("eapol_wlan_authentication_c::cancel_all_authentication_sessions(): %s\n"),
       
   359 		(m_is_client == true) ? "client": "server"));
       
   360 
       
   361 	eap_status_e status(eap_status_process_general_error);
       
   362 
       
   363 	if (m_ethernet_core != 0)
       
   364 	{
       
   365 		WAUTH_ENTER_MUTEX(m_am_tools);
       
   366 		EAP_TRACE_DEBUG(
       
   367 			m_am_tools,
       
   368 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   369 			(EAPL("calls eapol: eapol_wlan_authentication_c::cancel_all_authentication_sessions(): m_ethernet_core->cancel_all_authentication_sessions(): %s.\n"),
       
   370 			(m_is_client == true) ? "client": "server"));
       
   371 		status = m_ethernet_core->cancel_all_authentication_sessions();
       
   372 		EAP_TRACE_DEBUG(
       
   373 			m_am_tools,
       
   374 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   375 			(EAPL("returns from eapol: eapol_wlan_authentication_c::cancel_all_authentication_sessions(): m_ethernet_core->cancel_all_authentication_sessions(): %s, status = %s.\n"),
       
   376 			(m_is_client == true) ? "client": "server",
       
   377 			eap_status_string_c::get_status_string(status)));
       
   378 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
   379 	}
       
   380 	else
       
   381 	{
       
   382 		EAP_TRACE_DEBUG(
       
   383 			m_am_tools,
       
   384 			TRACE_FLAGS_DEFAULT,
       
   385 			(EAPL("eapol_wlan_authentication_c::cancel_all_authentication_sessions(): Stack did not exists.\n")));
       
   386 		status = eap_status_process_general_error;
       
   387 	}
       
   388 
       
   389 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   390 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   391 }
       
   392 
       
   393 //--------------------------------------------------
       
   394 
       
   395 //
       
   396 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::start_authentication(
       
   397 	const eap_variable_data_c * const SSID,
       
   398 	const eapol_key_authentication_type_e selected_eapol_key_authentication_type,
       
   399 	const eap_variable_data_c * const wpa_preshared_key,
       
   400 	const bool WPA_override_enabled
       
   401 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
   402 	,
       
   403 	const eap_am_network_id_c * const receive_network_id ///< source includes remote address, destination includes local address.
       
   404 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
   405 	)
       
   406 {
       
   407 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   408 
       
   409 	EAP_TRACE_DEBUG(
       
   410 		m_am_tools,
       
   411 		TRACE_FLAGS_DEFAULT,
       
   412 		(EAPL("partner calls: eapol_wlan_authentication_c::start_authentication(): %s\n"),
       
   413 		(m_is_client == true) ? "client": "server"));
       
   414 
       
   415 	EAP_TRACE_DEBUG(
       
   416 		m_am_tools,
       
   417 		TRACE_FLAGS_DEFAULT,
       
   418 		(EAPL("Starting authentication, selected_eapol_key_authentication_type = %d.\n"),
       
   419 		selected_eapol_key_authentication_type));
       
   420 
       
   421 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::start_authentication()");
       
   422 
       
   423 	eap_status_e status(eap_status_ok);
       
   424 
       
   425 	status = cancel_all_authentication_sessions();
       
   426 	if (status != eap_status_ok)
       
   427 	{
       
   428 		(void) EAP_STATUS_RETURN(m_am_tools, status);
       
   429 	}
       
   430 
       
   431 	m_authentication_type = selected_eapol_key_authentication_type;
       
   432 
       
   433 	EAP_TRACE_DEBUG(
       
   434 		m_am_tools,
       
   435 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   436 		(EAPL("calls: eapol_wlan_authentication_c::start_authentication(): m_am_wauth->set_wlan_parameters(): %s.\n"),
       
   437 		(m_is_client == true) ? "client": "server"));
       
   438 
       
   439 	status = m_am_wauth->set_wlan_parameters(
       
   440 		SSID,
       
   441 		WPA_override_enabled,
       
   442 		wpa_preshared_key,
       
   443 		selected_eapol_key_authentication_type);
       
   444 	if (status != eap_status_ok)
       
   445 	{
       
   446 		(void) disassociation(0); // Note we have no addresses yet.
       
   447 
       
   448 		(void) eapol_indication(
       
   449 			0, // Note we have no addresses yet.
       
   450 			eapol_wlan_authentication_state_failed_completely);
       
   451 
       
   452 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   453 	}
       
   454 
       
   455 	EAP_TRACE_DEBUG(
       
   456 		m_am_tools,
       
   457 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   458 		(EAPL("calls: eapol_wlan_authentication_c::start_authentication(): m_am_wauth->reset_eap_configuration(): %s.\n"),
       
   459 		(m_is_client == true) ? "client": "server"));
       
   460 
       
   461 	status = m_am_wauth->reset_eap_configuration();
       
   462 	if (status != eap_status_ok)
       
   463 	{
       
   464 		(void) disassociation(0); // Note we have no addresses yet.
       
   465 
       
   466 		(void) eapol_indication(
       
   467 			0, // Note we have no addresses yet.
       
   468 			eapol_wlan_authentication_state_failed_completely);
       
   469 
       
   470 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   471 	}
       
   472 
       
   473 	EAP_TRACE_DEBUG(
       
   474 		m_am_tools,
       
   475 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   476 		(EAPL("calls: eapol_wlan_authentication_c::start_authentication(): m_am_wauth->get_selected_eap_types(): %s.\n"),
       
   477 		(m_is_client == true) ? "client": "server"));
       
   478 
       
   479 	status = m_am_wauth->get_selected_eap_types(&m_selected_eap_types);
       
   480 	if (status != eap_status_ok)
       
   481 	{
       
   482 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   483 	}
       
   484 
       
   485 	EAP_TRACE_DEBUG(
       
   486 		m_am_tools,
       
   487 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   488 		(EAPL("calls: eapol_wlan_authentication_c::start_authentication(): m_am_wauth->get_wlan_configuration(): %s.\n"),
       
   489 		(m_is_client == true) ? "client": "server"));
       
   490 
       
   491 	status = m_am_wauth->get_wlan_configuration(
       
   492 		&m_wpa_preshared_key_hash);
       
   493 	if (status != eap_status_ok)
       
   494 	{
       
   495 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   496 	}
       
   497 
       
   498 	// Start new authentication from scratch.
       
   499 	
       
   500 	if (m_authentication_type == eapol_key_authentication_type_RSNA_PSK
       
   501 		|| m_authentication_type == eapol_key_authentication_type_WPA_PSK)
       
   502 	{
       
   503 		// WPA Pre-shared key mode
       
   504 		m_802_11_authentication_mode = eapol_key_802_11_authentication_mode_open;
       
   505 
       
   506 		if (m_authentication_type == eapol_key_authentication_type_RSNA_PSK)
       
   507 		{
       
   508 			EAP_TRACE_ALWAYS(
       
   509 				m_am_tools,
       
   510 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   511 				(EAPL("start_authentication(): Trying auth mode OPEN and WPA2-PSK.\n")));
       
   512 		}
       
   513 		else
       
   514 		{
       
   515 			EAP_TRACE_ALWAYS(
       
   516 				m_am_tools,
       
   517 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   518 				(EAPL("start_authentication(): Trying auth mode OPEN and WPA-PSK.\n")));
       
   519 		}
       
   520 	}
       
   521 	else //if (wpa_preshared_key == 0
       
   522 		//|| wpa_preshared_key->get_is_valid_data() == false
       
   523 		//|| WPA_override_enabled == false)
       
   524 	{
       
   525 		// Check the first enabled type
       
   526 		eap_type_selection_c * eap_type = 0;
       
   527 		u32_t ind_type = 0ul;
       
   528 
       
   529 		for (ind_type = 0; ind_type < m_selected_eap_types.get_object_count(); ind_type++)
       
   530 		{
       
   531 			// Check if type is enabled
       
   532 			eap_type = m_selected_eap_types.get_object(ind_type);
       
   533 
       
   534 			if (eap_type->get_is_enabled() == true)
       
   535 			{	
       
   536 				break;
       
   537 			}
       
   538 		}
       
   539 
       
   540 		if (ind_type >= m_selected_eap_types.get_object_count())
       
   541 		{
       
   542 			// No enabled EAP types.
       
   543 			EAP_TRACE_ALWAYS(
       
   544 				m_am_tools,
       
   545 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
   546 				(EAPL("No enabled EAP types.\n")));
       
   547 			EAP_TRACE_ALWAYS(
       
   548 				m_am_tools,
       
   549 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
   550 				(EAPL("Indication sent to WLM: eap_status_failed_completely.\n")));
       
   551 
       
   552 			(void) disassociation(0); // Note we have no addresses yet.
       
   553 
       
   554 			status = eapol_indication(
       
   555 				0, // Note we have no addresses yet.
       
   556 				eapol_wlan_authentication_state_failed_completely);
       
   557 			if (status != eap_status_ok)
       
   558 			{
       
   559 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   560 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   561 			}
       
   562 
       
   563 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   564 			return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   565 		}	
       
   566 
       
   567 		// reset index (start from the first enabled EAP type)
       
   568 		m_current_eap_index = ind_type;
       
   569 		
       
   570 		if (eap_type->get_type() == eap_type_leap)
       
   571 		{
       
   572 			if (m_authentication_type == eapol_key_authentication_type_802_1X)
       
   573 			{
       
   574 				// LEAP uses it's own 802.11 authentication mode when 802.1X (dynamic WEP) is used.
       
   575 				m_802_11_authentication_mode = eapol_key_802_11_authentication_mode_leap;
       
   576 
       
   577 				EAP_TRACE_ALWAYS(
       
   578 					m_am_tools,
       
   579 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   580 					(EAPL("start_authentication(): Trying auth mode LEAP (802.1x mode).\n")));
       
   581 			}
       
   582 			else
       
   583 			{
       
   584 				// If security mode is WPA or RSNA then even LEAP uses open authentication!
       
   585 				m_802_11_authentication_mode = eapol_key_802_11_authentication_mode_open;
       
   586 
       
   587 				EAP_TRACE_ALWAYS(
       
   588 					m_am_tools,
       
   589 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   590 					(EAPL("start_authentication(): Trying auth mode OPEN (LEAP in WPA mode).\n")));
       
   591 			}
       
   592 
       
   593 		}
       
   594 		else
       
   595 		{
       
   596 			m_802_11_authentication_mode = eapol_key_802_11_authentication_mode_open;
       
   597 
       
   598 			EAP_TRACE_ALWAYS(
       
   599 				m_am_tools,
       
   600 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   601 				(EAPL("start_authentication(): Trying auth mode OPEN.\n")));
       
   602 		}
       
   603 	}
       
   604 
       
   605 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
   606 	WAUTH_ENTER_MUTEX(m_am_tools);
       
   607 	EAP_TRACE_DEBUG(
       
   608 		m_am_tools,
       
   609 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   610 		(EAPL("calls eapol: eapol_wlan_authentication_c::start_authentication(): m_ethernet_core->create_state(): %s.\n"),
       
   611 		(m_is_client == true) ? "client": "server"));
       
   612 	status = m_ethernet_core->create_state(
       
   613 		receive_network_id,
       
   614 		selected_eapol_key_authentication_type
       
   615 		);
       
   616 	EAP_TRACE_DEBUG(
       
   617 		m_am_tools,
       
   618 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   619 		(EAPL("returns from eapol: eapol_wlan_authentication_c::start_authentication(): m_ethernet_core->create_state(): %s, status = %s.\n"),
       
   620 		(m_is_client == true) ? "client": "server",
       
   621 		eap_status_string_c::get_status_string(status)));
       
   622 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
   623 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
   624 	
       
   625 
       
   626 	EAP_TRACE_DEBUG(
       
   627 		m_am_tools,
       
   628 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   629 		(EAPL("calls partner: eapol_wlan_authentication_c::start_authentication(): m_partner->associate(%d).\n"),
       
   630 		m_802_11_authentication_mode));
       
   631 
       
   632 	status = m_partner->associate(m_802_11_authentication_mode);
       
   633 	(void)EAP_STATUS_RETURN(m_am_tools, status);
       
   634 
       
   635 	EAP_TRACE_DEBUG(
       
   636 		m_am_tools,
       
   637 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   638 		(EAPL("returns from partner: eapol_wlan_authentication_c::start_authentication(): %s: m_partner->associate(): status = %s\n"),
       
   639 		 (m_is_client == true) ? "client": "server",
       
   640 		 eap_status_string_c::get_status_string(status)));
       
   641 
       
   642 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   643 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   644 }
       
   645 
       
   646 //--------------------------------------------------
       
   647 
       
   648 //
       
   649 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::complete_association(
       
   650 	const eapol_wlan_authentication_state_e association_result,
       
   651 	const eap_am_network_id_c * const receive_network_id, ///< source includes remote address, destination includes local address.
       
   652 	const eap_variable_data_c * const received_WPA_IE, ///< WLM must give only the WPA IE to EAPOL
       
   653 	const eap_variable_data_c * const sent_WPA_IE,
       
   654 	const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e pairwise_key_cipher_suite,
       
   655 	const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e group_key_cipher_suite
       
   656 	)
       
   657 {
       
   658 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   659 
       
   660 	EAP_TRACE_DEBUG(
       
   661 		m_am_tools,
       
   662 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
   663 		(EAPL("partner calls: eapol_wlan_authentication_c::complete_association(): %s: association_result=%d\n"),
       
   664 		(m_is_client == true) ? "client": "server",
       
   665 		association_result));
       
   666 
       
   667 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::complete_association()");
       
   668 
       
   669 	eap_status_e status(eap_status_ok);
       
   670 
       
   671 	// ASSOCIATION UNSUCCESSFUL
       
   672 	if (association_result != eapol_wlan_authentication_state_association_ok)
       
   673 	{
       
   674 		EAP_TRACE_DEBUG(
       
   675 			m_am_tools,
       
   676 			TRACE_FLAGS_DEFAULT,
       
   677 			(EAPL("complete_association: Unsuccessful.\n")));
       
   678 
       
   679 		EAP_TRACE_DATA_DEBUG(
       
   680 			m_am_tools, 
       
   681 			TRACE_FLAGS_DEFAULT, 
       
   682 			(EAPL("Got AP MAC address"),
       
   683 			receive_network_id->get_source(),
       
   684 			receive_network_id->get_source_length()));
       
   685 
       
   686 		// Report rogue AP if we tried LEAP and it failed
       
   687 		if (m_802_11_authentication_mode == eapol_key_802_11_authentication_mode_leap)
       
   688 		{
       
   689 			// Only add rogue AP if the error code is correct
       
   690 			if (association_result == eapol_wlan_authentication_state_802_11_auth_algorithm_not_supported)
       
   691 			{
       
   692 				eap_rogue_ap_entry_c rogue_entry(m_am_tools);
       
   693 			
       
   694 				rogue_entry.set_mac_address(receive_network_id->get_source());
       
   695 				rogue_entry.set_rogue_reason(rogue_ap_association_failed);
       
   696 
       
   697 				eap_array_c<eap_rogue_ap_entry_c> rogue_list(m_am_tools);
       
   698 				status = rogue_list.add_object(&rogue_entry, false);
       
   699 				if (status == eap_status_ok)
       
   700 				{	
       
   701 					status = add_rogue_ap(rogue_list);
       
   702 					// Ignore return value on purpose - it's not fatal if this fails
       
   703 				}
       
   704 			}			
       
   705 		}
       
   706 
       
   707 		EAP_TRACE_ALWAYS(
       
   708 			m_am_tools,
       
   709 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   710 			(EAPL("Could not associate to the AP.\n")));
       
   711 
       
   712 		EAP_TRACE_ALWAYS(
       
   713 			m_am_tools,
       
   714 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
   715 			(EAPL("Indication sent to WLM: eap_status_this_ap_failed.\n")));
       
   716 
       
   717 		(void) disassociation(receive_network_id);
       
   718 
       
   719 		status = eapol_indication(
       
   720 			receive_network_id,
       
   721 			eapol_wlan_authentication_state_this_ap_failed);
       
   722 		if (status != eap_status_ok)
       
   723 		{
       
   724 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   725 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   726 		}
       
   727 
       
   728 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   729 		return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   730 
       
   731 	}
       
   732 	
       
   733 	// ASSOCIATION SUCCESSFUL
       
   734 	EAP_TRACE_ALWAYS(
       
   735 		m_am_tools,
       
   736 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
   737 		(EAPL("complete_association: Successful.\n")));
       
   738 
       
   739 	// Store parameters
       
   740 
       
   741 	if (m_authentication_type == eapol_key_authentication_type_RSNA_EAP
       
   742 		|| m_authentication_type == eapol_key_authentication_type_RSNA_PSK
       
   743 		|| m_authentication_type == eapol_key_authentication_type_WPA_EAP
       
   744 		|| m_authentication_type == eapol_key_authentication_type_WPA_PSK
       
   745 #if defined(EAP_USE_WPXM)
       
   746 		|| m_authentication_type == eapol_key_authentication_type_WPXM
       
   747 #endif //#if defined(EAP_USE_WPXM)
       
   748 		)
       
   749 	{
       
   750 		status = m_received_WPA_IE.set_copy_of_buffer(received_WPA_IE);
       
   751 		if (status != eap_status_ok)
       
   752 		{
       
   753 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   754 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   755 		}
       
   756 
       
   757 		status = m_sent_WPA_IE.set_copy_of_buffer(sent_WPA_IE);
       
   758 		if (status != eap_status_ok)
       
   759 		{
       
   760 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   761 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   762 		}
       
   763 	}
       
   764 
       
   765 	m_group_key_cipher_suite = group_key_cipher_suite;
       
   766 
       
   767 	m_pairwise_key_cipher_suite = pairwise_key_cipher_suite;
       
   768 
       
   769 	eap_variable_data_c * wpa_preshared_key = 0;
       
   770 
       
   771 	if (m_authentication_type == eapol_key_authentication_type_RSNA_PSK
       
   772 		|| m_authentication_type == eapol_key_authentication_type_WPA_PSK)
       
   773 	{
       
   774 		wpa_preshared_key = &m_wpa_preshared_key_hash;
       
   775 	}
       
   776 
       
   777 	EAP_TRACE_DEBUG(
       
   778 		m_am_tools,
       
   779 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   780 		(EAPL("calls: eapol_wlan_authentication_c::complete_association(): m_am_wauth->association(): %s.\n"),
       
   781 		(m_is_client == true) ? "client": "server"));
       
   782 
       
   783 	status = m_am_wauth->association(receive_network_id);
       
   784 	if (status != eap_status_ok)
       
   785 	{
       
   786 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   787 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   788 	}
       
   789 
       
   790 	WAUTH_ENTER_MUTEX(m_am_tools);
       
   791 	EAP_TRACE_DEBUG(
       
   792 		m_am_tools,
       
   793 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   794 		(EAPL("calls eapol: eapol_wlan_authentication_c::complete_association(): m_ethernet_core->association(): %s.\n"),
       
   795 		(m_is_client == true) ? "client": "server"));
       
   796 	status = m_ethernet_core->association(
       
   797 		receive_network_id,
       
   798 		m_authentication_type,
       
   799 		&m_received_WPA_IE,
       
   800 		&m_sent_WPA_IE,
       
   801 		pairwise_key_cipher_suite,
       
   802 		group_key_cipher_suite,
       
   803 		wpa_preshared_key);
       
   804 	EAP_TRACE_DEBUG(
       
   805 		m_am_tools,
       
   806 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   807 		(EAPL("returns from eapol: eapol_wlan_authentication_c::complete_association(): m_ethernet_core->association(): %s, status = %s.\n"),
       
   808 		(m_is_client == true) ? "client": "server",
       
   809 		eap_status_string_c::get_status_string(status)));
       
   810 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
   811 
       
   812 	if (status != eap_status_ok)
       
   813 	{
       
   814 
       
   815 		EAP_TRACE_ALWAYS(
       
   816 			m_am_tools,
       
   817 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
   818 			(EAPL("m_ethernet_core->association call failed.\n")));
       
   819 
       
   820 		EAP_TRACE_ALWAYS(
       
   821 			m_am_tools,
       
   822 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
   823 			(EAPL("Indication sent to WLM: eap_status_failed_completely.\n")));
       
   824 
       
   825 		EAP_TRACE_DEBUG(
       
   826 			m_am_tools,
       
   827 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   828 			(EAPL("calls: eapol_wlan_authentication_c::complete_association(): this->disassociation(): %s.\n"),
       
   829 			(m_is_client == true) ? "client": "server"));
       
   830 
       
   831 		(void) disassociation(receive_network_id);
       
   832 
       
   833 		status = eapol_indication(
       
   834 			receive_network_id,
       
   835 			eapol_wlan_authentication_state_failed_completely);
       
   836 		if (status != eap_status_ok)
       
   837 		{
       
   838 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   839 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   840 		}
       
   841 
       
   842 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   843 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   844 	}
       
   845 
       
   846 	if (m_authentication_type == eapol_key_authentication_type_RSNA_EAP
       
   847 		|| m_authentication_type == eapol_key_authentication_type_WPA_EAP
       
   848 		|| m_authentication_type == eapol_key_authentication_type_802_1X
       
   849 		|| m_authentication_type == eapol_key_authentication_type_WFA_SC
       
   850 #if defined(EAP_USE_WPXM)
       
   851 		|| m_authentication_type == eapol_key_authentication_type_WPXM
       
   852 #endif //#if defined(EAP_USE_WPXM)
       
   853 		)
       
   854 	{
       
   855 		// Start authentication if mode is not pre-shared key. If mode is pre-shared key then
       
   856 		// just wait for EAPOL-Key frames.
       
   857 		WAUTH_ENTER_MUTEX(m_am_tools);
       
   858 		EAP_TRACE_DEBUG(
       
   859 			m_am_tools,
       
   860 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   861 			(EAPL("calls eapol: eapol_wlan_authentication_c::complete_association(): m_ethernet_core->start_authentication(): %s.\n"),
       
   862 			(m_is_client == true) ? "client": "server"));
       
   863 		status = m_ethernet_core->start_authentication(receive_network_id, m_is_client);
       
   864 		EAP_TRACE_DEBUG(
       
   865 			m_am_tools,
       
   866 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   867 			(EAPL("returns from eapol: eapol_wlan_authentication_c::complete_association(): m_ethernet_core->start_authentication(): %s, status = %s.\n"),
       
   868 			(m_is_client == true) ? "client": "server",
       
   869 			eap_status_string_c::get_status_string(status)));
       
   870 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
   871 	}
       
   872 	
       
   873 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   874 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   875 }
       
   876 
       
   877 //--------------------------------------------------
       
   878 
       
   879 //
       
   880 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::start_preauthentication(
       
   881 	const eap_am_network_id_c * const receive_network_id ///< source includes remote address, destination includes local address.
       
   882 	)
       
   883 {
       
   884 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   885 
       
   886 	EAP_TRACE_DEBUG(
       
   887 		m_am_tools,
       
   888 		TRACE_FLAGS_DEFAULT,
       
   889 		(EAPL("partner calls: eapol_wlan_authentication_c::start_preauthentication(): %s\n"),
       
   890 		(m_is_client == true) ? "client": "server"));
       
   891 
       
   892 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::start_preauthentication()");
       
   893 
       
   894 	WAUTH_ENTER_MUTEX(m_am_tools);
       
   895 	EAP_TRACE_DEBUG(
       
   896 		m_am_tools,
       
   897 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   898 		(EAPL("calls eapol: eapol_wlan_authentication_c::start_preauthentication(): m_ethernet_core->start_preauthentication(): %s.\n"),
       
   899 		(m_is_client == true) ? "client": "server"));
       
   900 	eap_status_e status = m_ethernet_core->start_preauthentication(
       
   901 		receive_network_id,
       
   902 		m_authentication_type);
       
   903 	EAP_TRACE_DEBUG(
       
   904 		m_am_tools,
       
   905 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   906 		(EAPL("returns from eapol: eapol_wlan_authentication_c::start_preauthentication(): m_ethernet_core->start_preauthentication(): %s, status = %s.\n"),
       
   907 		(m_is_client == true) ? "client": "server",
       
   908 		eap_status_string_c::get_status_string(status)));
       
   909 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
   910 
       
   911 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   912 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   913 }
       
   914 
       
   915 //--------------------------------------------------
       
   916 
       
   917 //
       
   918 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::check_pmksa_cache(
       
   919 	eap_array_c<eap_am_network_id_c> * const bssid_sta_receive_network_ids,
       
   920 	const eapol_key_authentication_type_e selected_eapol_key_authentication_type,
       
   921 	const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e pairwise_key_cipher_suite,
       
   922 	const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e group_key_cipher_suite
       
   923 	)
       
   924 {
       
   925 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   926 
       
   927 	EAP_TRACE_DEBUG(
       
   928 		m_am_tools,
       
   929 		TRACE_FLAGS_DEFAULT,
       
   930 		(EAPL("partner calls: eapol_wlan_authentication_c::check_pmksa_cache(): %s\n"),
       
   931 		(m_is_client == true) ? "client": "server"));
       
   932 
       
   933 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::check_pmksa_cache()");
       
   934 
       
   935 	WAUTH_ENTER_MUTEX(m_am_tools);
       
   936 	EAP_TRACE_DEBUG(
       
   937 		m_am_tools,
       
   938 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   939 		(EAPL("calls eapol: eapol_wlan_authentication_c::check_pmksa_cache(): m_ethernet_core->check_pmksa_cache(): %s.\n"),
       
   940 		(m_is_client == true) ? "client": "server"));
       
   941 	eap_status_e status = m_ethernet_core->check_pmksa_cache(
       
   942 		bssid_sta_receive_network_ids,
       
   943 		selected_eapol_key_authentication_type,
       
   944 		pairwise_key_cipher_suite,
       
   945 		group_key_cipher_suite);
       
   946 	EAP_TRACE_DEBUG(
       
   947 		m_am_tools,
       
   948 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   949 		(EAPL("returns from eapol: eapol_wlan_authentication_c::check_pmksa_cache(): m_ethernet_core->check_pmksa_cache(): %s, status = %s.\n"),
       
   950 		(m_is_client == true) ? "client": "server",
       
   951 		eap_status_string_c::get_status_string(status)));
       
   952 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
   953 
       
   954 	if (bssid_sta_receive_network_ids->get_object_count() == 0)
       
   955 	{
       
   956 		EAP_TRACE_DEBUG(
       
   957 			m_am_tools,
       
   958 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   959 			(EAPL("WARNING: eapol_wlan_authentication_c::check_pmksa_cache(): %s: No PMKSA:s found in cache.\n"),
       
   960 			(m_is_client == true) ? "client": "server"));
       
   961 	}
       
   962 
       
   963 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   964 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   965 }
       
   966 
       
   967 //--------------------------------------------------
       
   968 
       
   969 //
       
   970 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::start_reassociation(
       
   971 	const eap_am_network_id_c * const old_receive_network_id, ///< source includes remote address, destination includes local address.
       
   972 	const eap_am_network_id_c * const new_receive_network_id, ///< source includes remote address, destination includes local address.
       
   973 	const eapol_key_authentication_type_e selected_eapol_key_authentication_type ///< In WPXM this must be the same in old and new APs, other connections can change authentication type.
       
   974 	)
       
   975 {
       
   976 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
   977 
       
   978 	EAP_TRACE_DEBUG(
       
   979 		m_am_tools,
       
   980 		TRACE_FLAGS_DEFAULT,
       
   981 		(EAPL("partner calls: eapol_wlan_authentication_c::start_reassociation(): %s\n"),
       
   982 		(m_is_client == true) ? "client": "server"));
       
   983 
       
   984 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::start_reassociation()");
       
   985 
       
   986 	{
       
   987 		EAP_TRACE_DATA_DEBUG(m_am_tools,
       
   988 			TRACE_FLAGS_DEFAULT,
       
   989 			(EAPL("old_receive_network_id source:"),
       
   990 			old_receive_network_id->get_source_id()->get_data(),
       
   991 			old_receive_network_id->get_source_id()->get_data_length()));
       
   992 
       
   993 		EAP_TRACE_DATA_DEBUG(m_am_tools,
       
   994 			TRACE_FLAGS_DEFAULT,
       
   995 			(EAPL("old_receive_network_id destination:"),
       
   996 			old_receive_network_id->get_destination_id()->get_data(),
       
   997 			old_receive_network_id->get_destination_id()->get_data_length()));
       
   998 
       
   999 		EAP_TRACE_DATA_DEBUG(m_am_tools,
       
  1000 			TRACE_FLAGS_DEFAULT,
       
  1001 			(EAPL("new_receive_network_id source:"),
       
  1002 			new_receive_network_id->get_source_id()->get_data(),
       
  1003 			new_receive_network_id->get_source_id()->get_data_length()));
       
  1004 
       
  1005 		EAP_TRACE_DATA_DEBUG(m_am_tools,
       
  1006 			TRACE_FLAGS_DEFAULT,
       
  1007 			(EAPL("new_receive_network_id destination:"),
       
  1008 			new_receive_network_id->get_destination_id()->get_data(),
       
  1009 			new_receive_network_id->get_destination_id()->get_data_length()));
       
  1010 	}
       
  1011 
       
  1012 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1013 
       
  1014 	eap_status_e status = cancel_all_authentication_sessions();
       
  1015 	if (status != eap_status_ok)
       
  1016 	{
       
  1017 		(void) EAP_STATUS_RETURN(m_am_tools, status);
       
  1018 	}
       
  1019 
       
  1020 	EAP_TRACE_DEBUG(
       
  1021 		m_am_tools,
       
  1022 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1023 		(EAPL("calls: eapol_wlan_authentication_c::start_reassociation(): m_am_wauth->reset_eap_configuration(): %s.\n"),
       
  1024 		(m_is_client == true) ? "client": "server"));
       
  1025 
       
  1026 	status = m_am_wauth->reset_eap_configuration();
       
  1027 	if (status != eap_status_ok)
       
  1028 	{
       
  1029 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  1030 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1031 	}
       
  1032 
       
  1033 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1034 
       
  1035 	eap_variable_data_c reassociation_PMKID(m_am_tools);
       
  1036 
       
  1037 	WAUTH_ENTER_MUTEX(m_am_tools);
       
  1038 	EAP_TRACE_DEBUG(
       
  1039 		m_am_tools,
       
  1040 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1041 		(EAPL("calls eapol: eapol_wlan_authentication_c::start_reassociation(): m_ethernet_core->read_reassociation_parameters(): %s.\n"),
       
  1042 		(m_is_client == true) ? "client": "server"));
       
  1043 
       
  1044 	status = m_ethernet_core->read_reassociation_parameters(
       
  1045 		old_receive_network_id,
       
  1046 		new_receive_network_id,
       
  1047 		selected_eapol_key_authentication_type,
       
  1048 		&reassociation_PMKID,
       
  1049 		0,
       
  1050 		0);
       
  1051 
       
  1052 	EAP_TRACE_DEBUG(
       
  1053 		m_am_tools,
       
  1054 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1055 		(EAPL("returns from eapol: eapol_wlan_authentication_c::start_reassociation(): m_ethernet_core->read_reassociation_parameters(): %s, status = %s.\n"),
       
  1056 		(m_is_client == true) ? "client": "server",
       
  1057 		eap_status_string_c::get_status_string(status)));
       
  1058 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
  1059 
       
  1060 	if (status == eap_status_ok)
       
  1061 	{
       
  1062 		// Here we swap the addresses.
       
  1063 		eap_am_network_id_c send_network_id(
       
  1064 			m_am_tools,
       
  1065 			new_receive_network_id->get_destination_id(),
       
  1066 			new_receive_network_id->get_source_id(),
       
  1067 			new_receive_network_id->get_type());
       
  1068 		if (send_network_id.get_is_valid_data() == false)
       
  1069 		{
       
  1070 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  1071 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1072 		}
       
  1073 
       
  1074 		m_authentication_type = selected_eapol_key_authentication_type;
       
  1075 
       
  1076 		EAP_TRACE_DEBUG(
       
  1077 			m_am_tools,
       
  1078 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1079 			(EAPL("calls partner: eapol_wlan_authentication_c::start_reassociation(): %s: m_partner->reassociate(): m_authentication_type=%d.\n"),
       
  1080 			 (m_is_client == true) ? "client": "server",
       
  1081 			 m_authentication_type));
       
  1082 
       
  1083 		status = m_partner->reassociate(
       
  1084 			&send_network_id,
       
  1085 			m_authentication_type,
       
  1086 			&reassociation_PMKID);
       
  1087 
       
  1088 		EAP_TRACE_DEBUG(
       
  1089 			m_am_tools,
       
  1090 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1091 			(EAPL("returns from partner: eapol_wlan_authentication_c::start_reassociation(): %s: m_partner->reassociate(): status = %s\n"),
       
  1092 			 (m_is_client == true) ? "client": "server",
       
  1093 			 eap_status_string_c::get_status_string(status)));
       
  1094 	}
       
  1095 
       
  1096 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  1097 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1098 }
       
  1099 
       
  1100 //--------------------------------------------------
       
  1101 
       
  1102 //
       
  1103 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::complete_reassociation(
       
  1104 	const eapol_wlan_authentication_state_e reassociation_result,
       
  1105 	const eap_am_network_id_c * const receive_network_id,
       
  1106 	const eap_variable_data_c * const received_WPA_IE, // WLM must give only the WPA IE to EAPOL
       
  1107 	const eap_variable_data_c * const sent_WPA_IE,
       
  1108 	const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e pairwise_key_cipher_suite,
       
  1109 	const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e group_key_cipher_suite
       
  1110 	)
       
  1111 {
       
  1112 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1113 
       
  1114 	EAP_TRACE_DEBUG(
       
  1115 		m_am_tools,
       
  1116 		TRACE_FLAGS_DEFAULT,
       
  1117 		(EAPL("partner calls: eapol_wlan_authentication_c::complete_reassociation(): %s, reassociation_result=%d\n"),
       
  1118 		(m_is_client == true) ? "client": "server",
       
  1119 		reassociation_result));
       
  1120 
       
  1121 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::complete_reassociation()");
       
  1122 
       
  1123 	eap_status_e status(eap_status_process_general_error);
       
  1124 
       
  1125 	if (reassociation_result != eapol_wlan_authentication_state_association_ok)
       
  1126 	{
       
  1127 		EAP_TRACE_DEBUG(
       
  1128 			m_am_tools,
       
  1129 			TRACE_FLAGS_DEFAULT,
       
  1130 			(EAPL("complete_reassociation: Unsuccessful.\n")));
       
  1131 
       
  1132 		WAUTH_ENTER_MUTEX(m_am_tools);
       
  1133 		EAP_TRACE_DEBUG(
       
  1134 			m_am_tools,
       
  1135 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1136 			(EAPL("calls eapol: eapol_wlan_authentication_c::complete_reassociation(): m_ethernet_core->remove_pmksa_from_cache(): %s.\n"),
       
  1137 			(m_is_client == true) ? "client": "server"));
       
  1138 		status = m_ethernet_core->remove_pmksa_from_cache(
       
  1139 			receive_network_id);
       
  1140 		EAP_TRACE_DEBUG(
       
  1141 			m_am_tools,
       
  1142 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1143 			(EAPL("returns from eapol: eapol_wlan_authentication_c::complete_reassociation(): m_ethernet_core->remove_pmksa_from_cache(): %s, status = %s.\n"),
       
  1144 			(m_is_client == true) ? "client": "server",
       
  1145 			eap_status_string_c::get_status_string(status)));
       
  1146 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
  1147 
       
  1148 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1149 		return EAP_STATUS_RETURN(m_am_tools, eap_status_authentication_failure);
       
  1150 	}
       
  1151 	else
       
  1152 	{
       
  1153 		EAP_TRACE_DEBUG(
       
  1154 			m_am_tools,
       
  1155 			TRACE_FLAGS_DEFAULT,
       
  1156 			(EAPL("complete_reassociation: Successful.\n")));
       
  1157 
       
  1158 		WAUTH_ENTER_MUTEX(m_am_tools);
       
  1159 		EAP_TRACE_DEBUG(
       
  1160 			m_am_tools,
       
  1161 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1162 			(EAPL("calls eapol: eapol_wlan_authentication_c::complete_reassociation(): m_ethernet_core->complete_reassociation(): %s.\n"),
       
  1163 			(m_is_client == true) ? "client": "server"));
       
  1164 		status = m_ethernet_core->complete_reassociation(
       
  1165 			reassociation_result,
       
  1166 			receive_network_id,
       
  1167 			m_authentication_type,
       
  1168 			received_WPA_IE,
       
  1169 			sent_WPA_IE,
       
  1170 			pairwise_key_cipher_suite,
       
  1171 			group_key_cipher_suite);
       
  1172 		EAP_TRACE_DEBUG(
       
  1173 			m_am_tools,
       
  1174 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1175 			(EAPL("returns from eapol: eapol_wlan_authentication_c::complete_reassociation(): m_ethernet_core->complete_reassociation(): %s, status = %s.\n"),
       
  1176 			(m_is_client == true) ? "client": "server",
       
  1177 			eap_status_string_c::get_status_string(status)));
       
  1178 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
  1179 
       
  1180 		if (status != eap_status_ok)
       
  1181 		{
       
  1182 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1183 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1184 		}
       
  1185 	}
       
  1186 
       
  1187 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  1188 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1189 }
       
  1190 
       
  1191 //--------------------------------------------------
       
  1192 
       
  1193 //
       
  1194 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::packet_process(
       
  1195 	const eap_am_network_id_c * const receive_network_id, ///< source includes remote address, destination includes local address.
       
  1196 	eap_general_header_base_c * const packet_data,
       
  1197 	const u32_t packet_length)
       
  1198 {
       
  1199 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  1200 
       
  1201 	EAP_TRACE_DEBUG(
       
  1202 		m_am_tools,
       
  1203 		TRACE_FLAGS_DEFAULT,
       
  1204 		(EAPL("partner calls: eapol_wlan_authentication_c::packet_process(): %s\n"),
       
  1205 		(m_is_client == true) ? "client": "server"));
       
  1206 
       
  1207 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::packet_process()");
       
  1208 
       
  1209 	if (packet_length < eapol_ethernet_header_wr_c::get_header_length())
       
  1210 	{
       
  1211 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1212 		return EAP_STATUS_RETURN(m_am_tools, eap_status_too_short_message);
       
  1213 	}
       
  1214 
       
  1215 	eapol_ethernet_header_wr_c eth_header(
       
  1216 		m_am_tools,
       
  1217 		packet_data->get_header_buffer(packet_length),
       
  1218 		packet_length);
       
  1219 
       
  1220 	eap_status_e status(eap_status_process_general_error);
       
  1221 
       
  1222 	if (eth_header.get_type() == eapol_ethernet_type_pae
       
  1223 		|| eth_header.get_type() == eapol_ethernet_type_preauthentication)
       
  1224 	{
       
  1225 		// Forward the packet to the Ethernet layer of the EAPOL stack.
       
  1226 		// Ignore return value. Failure is signalled using state_notification.
       
  1227 		WAUTH_ENTER_MUTEX(m_am_tools);
       
  1228 		EAP_TRACE_DEBUG(
       
  1229 			m_am_tools,
       
  1230 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1231 			(EAPL("calls eapol: eapol_wlan_authentication_c::packet_process(): m_ethernet_core->packet_process(): %s.\n"),
       
  1232 			(m_is_client == true) ? "client": "server"));
       
  1233 		status = m_ethernet_core->packet_process(
       
  1234 			receive_network_id,
       
  1235 			&eth_header,
       
  1236 			packet_length);
       
  1237 		EAP_TRACE_DEBUG(
       
  1238 			m_am_tools,
       
  1239 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1240 			(EAPL("returns from eapol: eapol_wlan_authentication_c::packet_process(): m_ethernet_core->packet_process(): %s, status = %s.\n"),
       
  1241 			(m_is_client == true) ? "client": "server",
       
  1242 			eap_status_string_c::get_status_string(status)));
       
  1243 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
  1244 
       
  1245 		EAP_GENERAL_HEADER_COPY_ERROR_PARAMETERS(packet_data, &eth_header);
       
  1246 	} 
       
  1247 	else
       
  1248 	{
       
  1249 		EAP_TRACE_DEBUG(
       
  1250 			m_am_tools,
       
  1251 			TRACE_FLAGS_DEFAULT,
       
  1252 			(EAPL("Not supported ethernet type 0x%04x\n"), eth_header.get_type()));
       
  1253 		status = eap_status_ethernet_type_not_supported;
       
  1254 	}
       
  1255 	
       
  1256 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1257 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1258 }
       
  1259 
       
  1260 //--------------------------------------------------
       
  1261 
       
  1262 EAP_FUNC_EXPORT void eapol_wlan_authentication_c::set_is_valid()
       
  1263 {
       
  1264 	m_is_valid = true;
       
  1265 }
       
  1266 
       
  1267 //--------------------------------------------------
       
  1268 
       
  1269 EAP_FUNC_EXPORT bool eapol_wlan_authentication_c::get_is_valid()
       
  1270 {
       
  1271 	return m_is_valid;
       
  1272 }
       
  1273 
       
  1274 //--------------------------------------------------
       
  1275 
       
  1276 EAP_FUNC_EXPORT void eapol_wlan_authentication_c::increment_authentication_counter()
       
  1277 {
       
  1278 	++m_authentication_counter;
       
  1279 }
       
  1280 
       
  1281 //--------------------------------------------------
       
  1282 
       
  1283 EAP_FUNC_EXPORT u32_t eapol_wlan_authentication_c::get_authentication_counter()
       
  1284 {
       
  1285 	return m_authentication_counter;
       
  1286 }
       
  1287 
       
  1288 //--------------------------------------------------
       
  1289 
       
  1290 EAP_FUNC_EXPORT bool eapol_wlan_authentication_c::get_is_client()
       
  1291 {
       
  1292 	return m_is_client;
       
  1293 }
       
  1294 	
       
  1295 //--------------------------------------------------
       
  1296 
       
  1297 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::packet_data_session_key(
       
  1298 	const eap_am_network_id_c * const send_network_id,
       
  1299 	const eapol_session_key_c * const key)
       
  1300 {
       
  1301 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1302 	eap_status_e status(eap_status_ok);
       
  1303 
       
  1304 	EAP_TRACE_DEBUG(
       
  1305 		m_am_tools,
       
  1306 		TRACE_FLAGS_DEFAULT,
       
  1307 		(EAPL("eapol calls: eapol_wlan_authentication_c::packet_data_session_key(): %s\n"),
       
  1308 		(m_is_client == true) ? "client": "server"));
       
  1309 
       
  1310 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::packet_data_session_key()");
       
  1311 
       
  1312 	const eap_variable_data_c * const key_data = key->get_key();
       
  1313 	if (key_data == 0)
       
  1314 	{
       
  1315 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1316 		return EAP_STATUS_RETURN(m_am_tools, eap_status_key_error);
       
  1317 	}
       
  1318 
       
  1319 	EAP_TRACE_DEBUG(m_am_tools,
       
  1320 		TRACE_FLAGS_DEFAULT, 
       
  1321 		(EAPL("eapol_wlan_authentication_c::packet_data_session_key(): %s: key_type 0x%02x=%s, key_index %d\n"),
       
  1322 		(m_is_client == true) ? "client": "server",
       
  1323 		key->get_key_type(),
       
  1324 		eapol_session_key_c::get_eapol_key_type_string(key->get_key_type()),
       
  1325 		key->get_key_index()));
       
  1326 	
       
  1327 	EAP_TRACE_DATA_DEBUG(m_am_tools,
       
  1328 		TRACE_FLAGS_DEFAULT,
       
  1329 		(EAPL("packet_data_session_key:"),
       
  1330 		key_data->get_data(key_data->get_data_length()),
       
  1331 		key_data->get_data_length()));
       
  1332 
       
  1333 	EAP_TRACE_DATA_DEBUG(
       
  1334 		m_am_tools,
       
  1335 		TRACE_FLAGS_DEFAULT,
       
  1336 		(EAPL("packet_data_session_key      send source"), 
       
  1337 		 send_network_id->get_source(),
       
  1338 		 send_network_id->get_source_length()));
       
  1339 
       
  1340 	EAP_TRACE_DATA_DEBUG(
       
  1341 		m_am_tools,
       
  1342 		TRACE_FLAGS_DEFAULT,
       
  1343 		(EAPL("packet_data_session_key send destination"), 
       
  1344 		 send_network_id->get_destination(),
       
  1345 		 send_network_id->get_destination_length()));
       
  1346 
       
  1347 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1348 
       
  1349 	EAP_TRACE_DEBUG(
       
  1350 		m_am_tools,
       
  1351 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1352 		(EAPL("calls partner: eapol_wlan_authentication_c::packet_data_session_key(): %s: m_partner->packet_data_session_key()\n"),
       
  1353 		 (m_is_client == true) ? "client": "server"));
       
  1354 
       
  1355 	status = m_partner->packet_data_session_key(send_network_id, key);
       
  1356 	
       
  1357 	EAP_TRACE_DEBUG(
       
  1358 		m_am_tools,
       
  1359 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1360 		(EAPL("returns from partner: eapol_wlan_authentication_c::packet_data_session_key(): %s: m_partner->packet_data_session_key(): status = %s\n"),
       
  1361 		 (m_is_client == true) ? "client": "server",
       
  1362 		 eap_status_string_c::get_status_string(status)));
       
  1363 
       
  1364 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1365 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1366 }
       
  1367 
       
  1368 //--------------------------------------------------
       
  1369 
       
  1370 //
       
  1371 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::packet_send(
       
  1372 	const eap_am_network_id_c * const send_network_id,
       
  1373 	eap_buf_chain_wr_c * const sent_packet,
       
  1374 	const u32_t header_offset,
       
  1375 	const u32_t data_length,
       
  1376 	const u32_t buffer_length)
       
  1377 {
       
  1378 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1379 
       
  1380 	EAP_TRACE_DEBUG(
       
  1381 		m_am_tools,
       
  1382 		TRACE_FLAGS_DEFAULT,
       
  1383 		(EAPL("eapol calls: eapol_wlan_authentication_c::packet_send(data_length=%d): %s.\n"),
       
  1384 		data_length,
       
  1385 		(m_is_client == true) ? "client": "server"));
       
  1386 
       
  1387 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::packet_send()");
       
  1388 
       
  1389 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1390 
       
  1391 	if (header_offset != 0u)
       
  1392 	{
       
  1393 		EAP_TRACE_DEBUG(
       
  1394 			m_am_tools,
       
  1395 			TRACE_FLAGS_DEFAULT,
       
  1396 			(EAPL("packet_send: packet buffer corrupted.\n")));
       
  1397 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1398 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
  1399 	}
       
  1400 	else if (header_offset+data_length != sent_packet->get_data_length())
       
  1401 	{
       
  1402 		EAP_TRACE_DEBUG(
       
  1403 			m_am_tools,
       
  1404 			TRACE_FLAGS_DEFAULT,
       
  1405 			(EAPL("ERROR: packet_send: packet buffer corrupted (data_length != sent_packet->get_data_length()).\n")));
       
  1406 		EAP_ASSERT(data_length == sent_packet->get_buffer_length());
       
  1407 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1408 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
  1409 	}	
       
  1410 
       
  1411 	eap_status_e status(eap_status_ok);
       
  1412 
       
  1413 
       
  1414 #if defined(USE_EAP_ERROR_TESTS)
       
  1415 
       
  1416 	sent_packet->set_is_client(true);
       
  1417 
       
  1418 	if (m_randomly_drop_packets == true)
       
  1419 	{
       
  1420 		u32_t random_guard;
       
  1421 		crypto_random_c rand(m_am_tools);
       
  1422 		status = rand.get_rand_bytes(
       
  1423 			reinterpret_cast<u8_t *>(&random_guard),
       
  1424 			sizeof(random_guard));
       
  1425 		if (status != eap_status_ok)
       
  1426 		{
       
  1427 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1428 		}
       
  1429 
       
  1430 		// This is simple limiter to the probability of a packet drop.
       
  1431 		// probability = m_randomly_drop_packets_probability / (2^32)
       
  1432 		if (random_guard < m_randomly_drop_packets_probability)
       
  1433 		{
       
  1434 			// Drops this packet.
       
  1435 
       
  1436 			if (sent_packet->get_stack_address() == 0)
       
  1437 			{
       
  1438 				// Initialize error testing data.
       
  1439 				sent_packet->set_stack_address(this);
       
  1440 				m_am_tools->increase_packet_index();
       
  1441 				sent_packet->set_send_packet_index(++m_packet_index);
       
  1442 			}
       
  1443 
       
  1444 			EAP_TRACE_DEBUG(
       
  1445 				m_am_tools, 
       
  1446 				TRACE_FLAGS_DEFAULT, 
       
  1447 				(EAPL("TEST: random_error(): packet_index 0x%08x:%lu, Send packet dropped\n"),
       
  1448 				sent_packet->get_stack_address(),
       
  1449 				sent_packet->get_send_packet_index()));
       
  1450 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1451 			return eap_status_ok;
       
  1452 		}
       
  1453 	}
       
  1454 
       
  1455 	if (m_send_original_packet_first == true)
       
  1456 	{
       
  1457 		if (sent_packet->get_stack_address() == 0)
       
  1458 		{
       
  1459 			// Initialize error testing data.
       
  1460 			sent_packet->set_stack_address(this);
       
  1461 			sent_packet->set_send_packet_index(++m_packet_index);
       
  1462 		}
       
  1463 
       
  1464 		if (m_enable_random_errors == true)
       
  1465 		{
       
  1466 			EAP_TRACE_DEBUG(
       
  1467 				m_am_tools,
       
  1468 				TRACE_FLAGS_DEFAULT,
       
  1469 				(EAPL("TEST: random_error(): packet_index 0x%08x:%lu, Send original packet\n"),
       
  1470 				sent_packet->get_stack_address(),
       
  1471 				sent_packet->get_send_packet_index()));
       
  1472 		}
       
  1473 
       
  1474 		u8_t * const packet_data = sent_packet->get_data_offset(header_offset, data_length);
       
  1475 		if (packet_data == 0)
       
  1476 		{
       
  1477 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1478 			return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
       
  1479 		}
       
  1480 
       
  1481 		EAP_TRACE_DEBUG(
       
  1482 			m_am_tools,
       
  1483 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1484 			(EAPL("calls partner: eapol_wlan_authentication_c::packet_send(): %s: m_partner->packet_send()\n"),
       
  1485 			 (m_is_client == true) ? "client": "server"));
       
  1486 
       
  1487 		// Here we send the original packet.
       
  1488 		status = m_partner->packet_send(
       
  1489 			send_network_id,
       
  1490 			sent_packet,
       
  1491 			header_offset,
       
  1492 			data_length,
       
  1493 			buffer_length);
       
  1494 
       
  1495 		EAP_TRACE_DEBUG(
       
  1496 			m_am_tools,
       
  1497 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1498 			(EAPL("returns from partner: eapol_wlan_authentication_c::packet_send(): %s: m_partner->packet_send(): status = %s\n"),
       
  1499 			 (m_is_client == true) ? "client": "server",
       
  1500 			 eap_status_string_c::get_status_string(status)));
       
  1501 	}
       
  1502 
       
  1503 	if (m_enable_random_errors == true
       
  1504 		&& status == eap_status_ok)
       
  1505 	{
       
  1506 		if (m_generate_multiple_error_packets > 0ul)
       
  1507 		{
       
  1508 			// First create a copy of sent packet. Original correct packet will will be sent last.
       
  1509 			for (u32_t ind = 0ul; ind < m_generate_multiple_error_packets; ind++)
       
  1510 			{
       
  1511 				eap_buf_chain_wr_c *copy_packet = sent_packet->copy();
       
  1512 
       
  1513 				if (copy_packet != 0
       
  1514 					&& copy_packet->get_is_valid_data() == true)
       
  1515 				{
       
  1516 					copy_packet->set_send_packet_index(++m_packet_index);
       
  1517 
       
  1518 					// Make a random error to the copy message.
       
  1519 					m_am_tools->generate_random_error(
       
  1520 						copy_packet,
       
  1521 						true,
       
  1522 						copy_packet->get_send_packet_index(),
       
  1523 						0UL,
       
  1524 						m_error_probability,
       
  1525 						eapol_ethernet_header_wr_c::get_header_length());
       
  1526 
       
  1527 					EAP_TRACE_DEBUG(
       
  1528 						m_am_tools,
       
  1529 						TRACE_FLAGS_DEFAULT,
       
  1530 						(EAPL("TEST: random_error(): packet_index 0x%08x:%lu, Send error packet\n"),
       
  1531 						copy_packet->get_stack_address(),
       
  1532 						copy_packet->get_send_packet_index()));
       
  1533 					
       
  1534 					u8_t * const packet_data = copy_packet->get_data_offset(header_offset, data_length);
       
  1535 					if (packet_data == 0)
       
  1536 					{
       
  1537 						delete copy_packet;
       
  1538 						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1539 						return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
       
  1540 					}
       
  1541 
       
  1542 					EAP_TRACE_DEBUG(
       
  1543 						m_am_tools,
       
  1544 						TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1545 						(EAPL("calls partner: eapol_wlan_authentication_c::packet_send(): %s: m_partner->packet_send()\n"),
       
  1546 						 (m_is_client == true) ? "client": "server"));
       
  1547 
       
  1548 					// Here we send the copied and manipulated packet.
       
  1549 					status = m_partner->packet_send(
       
  1550 						send_network_id,
       
  1551 						copy_packet,
       
  1552 						header_offset,
       
  1553 						data_length,
       
  1554 						buffer_length);
       
  1555 
       
  1556 					EAP_TRACE_DEBUG(
       
  1557 						m_am_tools,
       
  1558 						TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1559 						(EAPL("returns from partner: eapol_wlan_authentication_c::packet_send(): %s: m_partner->packet_send(): status = %s\n"),
       
  1560 						 (m_is_client == true) ? "client": "server",
       
  1561 						 eap_status_string_c::get_status_string(status)));
       
  1562 				}
       
  1563 
       
  1564 				delete copy_packet;
       
  1565 			} // for()
       
  1566 		}
       
  1567 		else
       
  1568 		{
       
  1569 			if (sent_packet->get_stack_address() == 0)
       
  1570 			{
       
  1571 				// Initialize error testing data.
       
  1572 				sent_packet->set_stack_address(this);
       
  1573 				sent_packet->set_send_packet_index(++m_packet_index);
       
  1574 			}
       
  1575 
       
  1576 			eap_buf_chain_wr_c *copy_packet = sent_packet->copy();
       
  1577 
       
  1578 			if (copy_packet != 0
       
  1579 				&& copy_packet->get_is_valid_data() == true)
       
  1580 			{
       
  1581 				copy_packet->set_send_packet_index(++m_packet_index);
       
  1582 
       
  1583 				// Make a random error to the copy message.
       
  1584 				m_am_tools->generate_random_error(
       
  1585 					copy_packet,
       
  1586 					false,
       
  1587 					copy_packet->get_send_packet_index(),
       
  1588 					0UL,
       
  1589 					m_error_probability,
       
  1590 					eapol_ethernet_header_wr_c::get_header_length());
       
  1591 
       
  1592 				if (copy_packet->get_is_manipulated() == true)
       
  1593 				{
       
  1594 					EAP_TRACE_DEBUG(
       
  1595 						m_am_tools,
       
  1596 						TRACE_FLAGS_DEFAULT,
       
  1597 						(EAPL("TEST: random_error(): packet_index 0x%08x:%lu, Send error packet\n"),
       
  1598 						copy_packet->get_stack_address(),
       
  1599 						copy_packet->get_send_packet_index()));
       
  1600 
       
  1601 					u8_t * const packet_data = copy_packet->get_data_offset(header_offset, data_length);
       
  1602 					if (packet_data == 0)
       
  1603 					{
       
  1604 						delete copy_packet;
       
  1605 						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1606 						return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
       
  1607 					}
       
  1608 
       
  1609 					EAP_TRACE_DEBUG(
       
  1610 						m_am_tools,
       
  1611 						TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1612 						(EAPL("calls partner: eapol_wlan_authentication_c::packet_send(): %s: m_partner->packet_send()\n"),
       
  1613 						 (m_is_client == true) ? "client": "server"));
       
  1614 
       
  1615 					// Here we send the copied and manipulated packet.
       
  1616 					status = m_partner->packet_send(
       
  1617 						send_network_id,
       
  1618 						copy_packet,
       
  1619 						header_offset,
       
  1620 						data_length,
       
  1621 						buffer_length);
       
  1622 
       
  1623 					EAP_TRACE_DEBUG(
       
  1624 						m_am_tools,
       
  1625 						TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1626 						(EAPL("returns from partner: eapol_wlan_authentication_c::packet_send(): %s: m_partner->packet_send(): status = %s\n"),
       
  1627 						 (m_is_client == true) ? "client": "server",
       
  1628 						 eap_status_string_c::get_status_string(status)));
       
  1629 				}
       
  1630 			}
       
  1631 
       
  1632 			delete copy_packet;
       
  1633 		}
       
  1634 	}
       
  1635 
       
  1636 
       
  1637 	if (m_send_original_packet_first == false
       
  1638 		&& status == eap_status_ok)
       
  1639 	{
       
  1640 		if (sent_packet->get_stack_address() == 0)
       
  1641 		{
       
  1642 			// Initialize error testing data.
       
  1643 			sent_packet->set_stack_address(this);
       
  1644 			sent_packet->set_send_packet_index(++m_packet_index);
       
  1645 		}
       
  1646 
       
  1647 		if (m_enable_random_errors == true)
       
  1648 		{
       
  1649 			EAP_TRACE_DEBUG(
       
  1650 				m_am_tools,
       
  1651 				TRACE_FLAGS_DEFAULT,
       
  1652 				(EAPL("TEST: random_error(): packet_index 0x%08x:%lu, Send original packet\n"),
       
  1653 				sent_packet->get_stack_address(),
       
  1654 				sent_packet->get_send_packet_index()));
       
  1655 		}
       
  1656 
       
  1657 		u8_t * const packet_data = sent_packet->get_data_offset(header_offset, data_length);
       
  1658 		if (packet_data == 0)
       
  1659 		{
       
  1660 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1661 			return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
       
  1662 		}
       
  1663 
       
  1664 #endif //#if defined(USE_EAP_ERROR_TESTS)
       
  1665 
       
  1666 
       
  1667 		EAP_TRACE_DEBUG(
       
  1668 			m_am_tools,
       
  1669 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1670 			(EAPL("calls partner: eapol_wlan_authentication_c::packet_send(): %s: m_partner->packet_send()\n"),
       
  1671 			 (m_is_client == true) ? "client": "server"));
       
  1672 
       
  1673 		// Here we send the original packet.
       
  1674 		status = m_partner->packet_send(
       
  1675 			send_network_id,
       
  1676 			sent_packet,
       
  1677 			header_offset,
       
  1678 			data_length,
       
  1679 			buffer_length);
       
  1680 
       
  1681 		EAP_TRACE_DEBUG(
       
  1682 			m_am_tools,
       
  1683 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1684 			(EAPL("returns from partner: eapol_wlan_authentication_c::packet_send(): %s: m_partner->packet_send(): status = %s\n"),
       
  1685 			 (m_is_client == true) ? "client": "server",
       
  1686 			 eap_status_string_c::get_status_string(status)));
       
  1687 
       
  1688 #if defined(USE_EAP_ERROR_TESTS)
       
  1689 	}
       
  1690 #endif //#if defined(USE_EAP_ERROR_TESTS)
       
  1691 
       
  1692 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1693 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1694 }
       
  1695 
       
  1696 //--------------------------------------------------
       
  1697 
       
  1698 //
       
  1699 eap_status_e eapol_wlan_authentication_c::cancel_timer_this_ap_failed()
       
  1700 {
       
  1701 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1702 
       
  1703 	const eap_status_e status = cancel_timer(
       
  1704 		this,
       
  1705 		EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID);
       
  1706 
       
  1707 	EAP_TRACE_DEBUG(
       
  1708 		m_am_tools,
       
  1709 		TRACE_FLAGS_DEFAULT,
       
  1710 		(EAPL("eapol_wlan_authentication_c::cancel_timer_this_ap_failed(): Cancels timer EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID.\n")));
       
  1711 
       
  1712 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1713 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1714 }
       
  1715 
       
  1716 //--------------------------------------------------
       
  1717 
       
  1718 //
       
  1719 eap_status_e eapol_wlan_authentication_c::cancel_timer_failed_completely()
       
  1720 {
       
  1721 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1722 
       
  1723 	const eap_status_e status = cancel_timer(
       
  1724 		this,
       
  1725 		EAPOL_WLAN_AUTHENTICATION_TIMER_FAILED_COMPLETELY_ID);
       
  1726 
       
  1727 	EAP_TRACE_DEBUG(
       
  1728 		m_am_tools,
       
  1729 		TRACE_FLAGS_DEFAULT,
       
  1730 		(EAPL("eapol_wlan_authentication_c::cancel_timer_failed_completely(): Cancels timer EAPOL_WLAN_AUTHENTICATION_TIMER_FAILED_COMPLETELY_ID.\n")));
       
  1731 
       
  1732 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1733 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1734 }
       
  1735 
       
  1736 //--------------------------------------------------
       
  1737 
       
  1738 //
       
  1739 eap_status_e eapol_wlan_authentication_c::cancel_timer_no_response()
       
  1740 {
       
  1741 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1742 
       
  1743 	const eap_status_e status = cancel_timer(
       
  1744 		this,
       
  1745 		EAPOL_WLAN_AUTHENTICATION_TIMER_NO_RESPONSE_ID);
       
  1746 
       
  1747 	EAP_TRACE_DEBUG(
       
  1748 		m_am_tools,
       
  1749 		TRACE_FLAGS_DEFAULT,
       
  1750 		(EAPL("eapol_wlan_authentication_c::cancel_timer_no_response(): Cancels timer EAPOL_WLAN_AUTHENTICATION_TIMER_NO_RESPONSE_ID.\n")));
       
  1751 
       
  1752 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1753 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1754 }
       
  1755 
       
  1756 //--------------------------------------------------
       
  1757 
       
  1758 //
       
  1759 eap_status_e eapol_wlan_authentication_c::cancel_timer_authentication_cancelled()
       
  1760 {
       
  1761 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1762 
       
  1763 	const eap_status_e status = cancel_timer(
       
  1764 		this,
       
  1765 		EAPOL_WLAN_AUTHENTICATION_TIMER_AUTHENTICATION_CANCELLED_ID);
       
  1766 
       
  1767 	EAP_TRACE_DEBUG(
       
  1768 		m_am_tools,
       
  1769 		TRACE_FLAGS_DEFAULT,
       
  1770 		(EAPL("eapol_wlan_authentication_c::cancel_timer_authentication_cancelled(): Cancels timer EAPOL_WLAN_AUTHENTICATION_TIMER_AUTHENTICATION_CANCELLED_ID.\n")));
       
  1771 
       
  1772 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1773 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1774 }
       
  1775 
       
  1776 //--------------------------------------------------
       
  1777 
       
  1778 //
       
  1779 EAP_FUNC_EXPORT void eapol_wlan_authentication_c::state_notification(
       
  1780 	const abs_eap_state_notification_c * const state)
       
  1781 {
       
  1782 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1783 
       
  1784 	EAP_TRACE_DEBUG(
       
  1785 		m_am_tools,
       
  1786 		TRACE_FLAGS_DEFAULT,
       
  1787 		(EAPL("eapol calls: eapol_wlan_authentication_c::state_notification()\n")));
       
  1788 
       
  1789 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::state_notification()");
       
  1790 
       
  1791 	if (state == 0 
       
  1792 		|| state->get_send_network_id() == 0
       
  1793 		|| state->get_send_network_id()->get_is_valid_data() == false)
       
  1794 	{
       
  1795 		EAP_TRACE_DEBUG(
       
  1796 			m_am_tools,
       
  1797 			TRACE_FLAGS_DEFAULT,
       
  1798 			(EAPL("ERROR: Illegal state notification state=0x%08x, state->get_send_network_id()=0x%08x.\n"),
       
  1799 			state,
       
  1800 			((state != 0) ? state->get_send_network_id() : 0)));
       
  1801 		(void)EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
  1802 		return;
       
  1803 	}
       
  1804 
       
  1805 	EAP_TRACE_DATA_DEBUG(
       
  1806 		m_am_tools,
       
  1807 		TRACE_FLAGS_DEFAULT,
       
  1808 		(EAPL("    send source"),
       
  1809 		 state->get_send_network_id()->get_source(),
       
  1810 		 state->get_send_network_id()->get_source_length()));
       
  1811 	EAP_TRACE_DATA_DEBUG(
       
  1812 		m_am_tools,
       
  1813 		TRACE_FLAGS_DEFAULT,
       
  1814 		(EAPL("send destination"),
       
  1815 		 state->get_send_network_id()->get_destination(),
       
  1816 		 state->get_send_network_id()->get_destination_length()));
       
  1817 
       
  1818 	// Here we swap the addresses.
       
  1819 	eap_am_network_id_c receive_network_id(m_am_tools,
       
  1820 		state->get_send_network_id()->get_destination_id(),
       
  1821 		state->get_send_network_id()->get_source_id(),
       
  1822 		state->get_send_network_id()->get_type());
       
  1823 
       
  1824 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1825 
       
  1826 	eap_am_network_id_c* send_network_id = new eap_am_network_id_c(
       
  1827 		m_am_tools,
       
  1828 		state->get_send_network_id());
       
  1829 
       
  1830 	eap_automatic_variable_c<eap_am_network_id_c>
       
  1831 		automatic_send_network_id(m_am_tools, send_network_id);
       
  1832 
       
  1833 	if (send_network_id == 0 
       
  1834 		|| send_network_id->get_is_valid_data() == false)
       
  1835 	{
       
  1836 		EAP_TRACE_DEBUG(
       
  1837 			m_am_tools,
       
  1838 			TRACE_FLAGS_DEFAULT,
       
  1839 			(EAPL("ERROR: No network identity: Indication sent to WLM: eap_status_failed_completely.\n")));
       
  1840 
       
  1841 		(void) cancel_timer_failed_completely();
       
  1842 
       
  1843 		set_timer(
       
  1844 			this,
       
  1845 			EAPOL_WLAN_AUTHENTICATION_TIMER_FAILED_COMPLETELY_ID,
       
  1846 			send_network_id,
       
  1847 			0);
       
  1848 		
       
  1849 		automatic_send_network_id.do_not_free_variable();
       
  1850 
       
  1851 		EAP_TRACE_DEBUG(
       
  1852 			m_am_tools,
       
  1853 			TRACE_FLAGS_DEFAULT,
       
  1854 			(EAPL("Sets timer ")
       
  1855 			 EAPL("EAPOL_WLAN_AUTHENTICATION_TIMER_FAILED_COMPLETELY_ID.\n")));
       
  1856 	}
       
  1857 
       
  1858 
       
  1859 	{
       
  1860 		eap_status_string_c status_string;
       
  1861 		eap_header_string_c eap_string;
       
  1862 
       
  1863 		EAP_TRACE_DEBUG(
       
  1864 			m_am_tools, 
       
  1865 			TRACE_FLAGS_DEFAULT, 
       
  1866 			(EAPL("eapol_wlan_authentication_c::state_notification() %s: protocol layer %d=%s, protocol %d=%s, EAP-type 0x%08x=%s\n"),
       
  1867 			(state->get_is_client() == true ? "client": "server"),
       
  1868 			state->get_protocol_layer(),
       
  1869 			state->get_protocol_layer_string(),
       
  1870 			state->get_protocol(),
       
  1871 			state->get_protocol_string(),
       
  1872 			convert_eap_type_to_u32_t(state->get_eap_type()),
       
  1873 			eap_string.get_eap_type_string(state->get_eap_type())));
       
  1874 
       
  1875 		EAP_TRACE_DEBUG(
       
  1876 			m_am_tools, 
       
  1877 			TRACE_FLAGS_DEFAULT, 
       
  1878 			(EAPL("eapol_wlan_authentication_c::state_notification() %s: current state %d=%s, error %d=%s\n"),
       
  1879 			(state->get_is_client() == true ? "client": "server"),
       
  1880 			state->get_current_state(),
       
  1881 			state->get_current_state_string(),
       
  1882 			state->get_authentication_error(),
       
  1883 			status_string.get_status_string(state->get_authentication_error())));
       
  1884 	}
       
  1885 
       
  1886 
       
  1887 #if !defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  1888 
       
  1889 	EAP_TRACE_DEBUG(
       
  1890 		m_am_tools,
       
  1891 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1892 		(EAPL("calls partner: eapol_wlan_authentication_c::state_notification(): %s: m_partner->state_notification()\n"),
       
  1893 		 (m_is_client == true) ? "client": "server"));
       
  1894 
       
  1895 	// Calls lower layer.
       
  1896 	// Note the optimization prevents most of the state notifications to lower layer.
       
  1897 	m_partner->state_notification(state);
       
  1898 
       
  1899 	EAP_TRACE_DEBUG(
       
  1900 		m_am_tools,
       
  1901 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1902 		(EAPL("returns from partner: eapol_wlan_authentication_c::state_notification(): %s: m_partner->state_notification()\n"),
       
  1903 		 (m_is_client == true) ? "client": "server"));
       
  1904 
       
  1905 #endif //#if !defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  1906 
       
  1907 	if(state->get_protocol_layer() == eap_protocol_layer_general)
       
  1908 	{
       
  1909 		if (state->get_current_state() == eap_general_state_authentication_cancelled)
       
  1910 		{
       
  1911 			// Authentication was cancelled. Cannot continue.
       
  1912 			cancel_timer_authentication_cancelled();
       
  1913 
       
  1914 			set_timer(this, EAPOL_WLAN_AUTHENTICATION_TIMER_AUTHENTICATION_CANCELLED_ID, send_network_id, 0);
       
  1915 			automatic_send_network_id.do_not_free_variable();
       
  1916 
       
  1917 			EAP_TRACE_DEBUG(
       
  1918 				m_am_tools,
       
  1919 				TRACE_FLAGS_DEFAULT,
       
  1920 				(EAPL("Authentication was cancelled. Sets timer ")
       
  1921 				 EAPL("EAPOL_WLAN_AUTHENTICATION_TIMER_AUTHENTICATION_CANCELLED_ID.\n")));
       
  1922 
       
  1923 			// This indication is sent synchronously to WLAN engine. That prevent other indications to bypass this indication.
       
  1924 			eap_status_e status = eapol_indication(
       
  1925 				&receive_network_id,
       
  1926 				eapol_wlan_authentication_state_authentication_cancelled);
       
  1927 			if (status != eap_status_ok)
       
  1928 			{
       
  1929 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1930 				(void)EAP_STATUS_RETURN(m_am_tools, status);
       
  1931 				return;
       
  1932 			}
       
  1933 		}
       
  1934 		else if (state->get_current_state() == eap_general_state_configuration_error)
       
  1935 		{
       
  1936 			// Configuration error. Cannot continue.
       
  1937 			(void) cancel_timer_failed_completely();
       
  1938 
       
  1939 			set_timer(this, EAPOL_WLAN_AUTHENTICATION_TIMER_FAILED_COMPLETELY_ID, send_network_id, 0);
       
  1940 			automatic_send_network_id.do_not_free_variable();
       
  1941 
       
  1942 			EAP_TRACE_DEBUG(
       
  1943 				m_am_tools,
       
  1944 				TRACE_FLAGS_DEFAULT,
       
  1945 				(EAPL("Configuration error. Sets timer ")
       
  1946 				 EAPL("EAPOL_WLAN_AUTHENTICATION_TIMER_FAILED_COMPLETELY_ID.\n")));
       
  1947 		}
       
  1948 		else if (state->get_current_state() == eap_general_state_authentication_error)
       
  1949 		{
       
  1950 			// An authentication error from EAPOL-stack.
       
  1951 
       
  1952 			eap_status_string_c status_string;
       
  1953 			eap_header_string_c eap_string;
       
  1954 
       
  1955 			EAP_TRACE_ERROR(
       
  1956 				m_am_tools, 
       
  1957 				TRACE_FLAGS_DEFAULT, 
       
  1958 				(EAPL("ERROR: eapol_wlan_authentication_c::state_notification() %s: protocol layer %d=%s, protocol %d=%s, EAP-type 0x%08x=%s\n"),
       
  1959 				(state->get_is_client() == true ? "client": "server"),
       
  1960 				state->get_protocol_layer(),
       
  1961 				state->get_protocol_layer_string(),
       
  1962 				state->get_protocol(),
       
  1963 				state->get_protocol_string(),
       
  1964 				convert_eap_type_to_u32_t(state->get_eap_type()),
       
  1965 				eap_string.get_eap_type_string(state->get_eap_type())));
       
  1966 
       
  1967 			EAP_TRACE_ERROR(
       
  1968 				m_am_tools, 
       
  1969 				TRACE_FLAGS_DEFAULT, 
       
  1970 				(EAPL("ERROR: eapol_wlan_authentication_c::state_notification() %s: current state %d=%s, error %d=%s\n"),
       
  1971 				(state->get_is_client() == true ? "client": "server"),
       
  1972 				state->get_current_state(),
       
  1973 				state->get_current_state_string(),
       
  1974 				state->get_authentication_error(),
       
  1975 				status_string.get_status_string(state->get_authentication_error())));
       
  1976 
       
  1977 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  1978 			EAP_TRACE_DEBUG(
       
  1979 				m_am_tools,
       
  1980 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1981 				(EAPL("calls partner: eapol_wlan_authentication_c::state_notification(): %s: m_partner->state_notification()\n"),
       
  1982 				 (m_is_client == true) ? "client": "server"));
       
  1983 
       
  1984 			// Calls lower layer.
       
  1985 			// Note the optimization prevents most of the state notifications to lower layer.
       
  1986 			m_partner->state_notification(state);
       
  1987 
       
  1988 			EAP_TRACE_DEBUG(
       
  1989 				m_am_tools,
       
  1990 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1991 				(EAPL("returns from partner: eapol_wlan_authentication_c::state_notification(): %s: m_partner->state_notification()\n"),
       
  1992 				 (m_is_client == true) ? "client": "server"));
       
  1993 
       
  1994 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  1995 
       
  1996 			(void) cancel_timer_this_ap_failed();
       
  1997 
       
  1998 			set_timer(
       
  1999 				this,
       
  2000 				EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID,
       
  2001 				send_network_id,
       
  2002 				0);
       
  2003 			automatic_send_network_id.do_not_free_variable();
       
  2004 
       
  2005 			EAP_TRACE_DEBUG(
       
  2006 				m_am_tools,
       
  2007 				TRACE_FLAGS_DEFAULT,
       
  2008 				(EAPL("Sets timer EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID.\n")));
       
  2009 		}
       
  2010 		else if (state->get_current_state() == eap_general_state_immediate_reconnect)
       
  2011 		{
       
  2012 			// An provision protocol ready. Do immediate reconnect to use the new credentials.
       
  2013 
       
  2014 			eap_status_string_c status_string;
       
  2015 			eap_header_string_c eap_string;
       
  2016 
       
  2017 			EAP_TRACE_DEBUG(
       
  2018 				m_am_tools, 
       
  2019 				TRACE_FLAGS_DEFAULT, 
       
  2020 				(EAPL("eapol_wlan_authentication_c::state_notification() %s: protocol layer %d=%s, protocol %d=%s, EAP-type 0x%08x=%s\n"),
       
  2021 				(state->get_is_client() == true ? "client": "server"),
       
  2022 				state->get_protocol_layer(),
       
  2023 				state->get_protocol_layer_string(),
       
  2024 				state->get_protocol(),
       
  2025 				state->get_protocol_string(),
       
  2026 				convert_eap_type_to_u32_t(state->get_eap_type()),
       
  2027 				eap_string.get_eap_type_string(state->get_eap_type())));
       
  2028 
       
  2029 			EAP_TRACE_DEBUG(
       
  2030 				m_am_tools, 
       
  2031 				TRACE_FLAGS_DEFAULT, 
       
  2032 				(EAPL("eapol_wlan_authentication_c::state_notification() %s: current state %d=%s, error %d=%s\n"),
       
  2033 				(state->get_is_client() == true ? "client": "server"),
       
  2034 				state->get_current_state(),
       
  2035 				state->get_current_state_string(),
       
  2036 				state->get_authentication_error(),
       
  2037 				status_string.get_status_string(state->get_authentication_error())));
       
  2038 
       
  2039 				eap_status_e status = eapol_indication(
       
  2040 					&receive_network_id,
       
  2041 					eapol_wlan_authentication_state_immediate_reconnect);
       
  2042 				if (status != eap_status_ok)
       
  2043 				{
       
  2044 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2045 					return;
       
  2046 				}
       
  2047 
       
  2048 		}
       
  2049 	}
       
  2050 	else if(state->get_protocol_layer() == eap_protocol_layer_eap) // Check if this is EAP layer notification
       
  2051 	{
       
  2052 		switch (state->get_current_state())
       
  2053 		{
       
  2054 		case eap_state_none:
       
  2055 			break;
       
  2056 		case eap_state_identity_request_sent:
       
  2057 			// This is for server only so no need to notify WLM.
       
  2058 			break;
       
  2059 		case eap_state_identity_request_received:
       
  2060 			{
       
  2061 				EAP_TRACE_DEBUG(
       
  2062 					m_am_tools,
       
  2063 					TRACE_FLAGS_DEFAULT,
       
  2064 					(EAPL("EAP authentication running...\n")));
       
  2065 			}
       
  2066 			break;
       
  2067 		case eap_state_identity_response_received:
       
  2068 			// This is for server only so no need to notify WLM.
       
  2069 			break;
       
  2070 		case eap_state_authentication_finished_successfully:
       
  2071 			{
       
  2072 				EAP_TRACE_DEBUG(
       
  2073 					m_am_tools,
       
  2074 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2075 					(EAPL("calls: eapol_wlan_authentication_c::state_notification(): m_am_wauth->authentication_finished(): %s.\n"),
       
  2076 					(m_is_client == true) ? "client": "server"));
       
  2077 
       
  2078 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  2079 
       
  2080 				EAP_TRACE_DEBUG(
       
  2081 					m_am_tools,
       
  2082 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2083 					(EAPL("calls partner: eapol_wlan_authentication_c::state_notification(): %s: m_partner->state_notification()\n"),
       
  2084 					 (m_is_client == true) ? "client": "server"));
       
  2085 
       
  2086 				// Calls lower layer.
       
  2087 				// Note the optimization prevents most of the state notifications to lower layer.
       
  2088 				m_partner->state_notification(state);
       
  2089 
       
  2090 				EAP_TRACE_DEBUG(
       
  2091 					m_am_tools,
       
  2092 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2093 					(EAPL("returns from partner: eapol_wlan_authentication_c::state_notification(): %s: m_partner->state_notification()\n"),
       
  2094 					 (m_is_client == true) ? "client": "server"));
       
  2095 
       
  2096 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  2097 
       
  2098 				m_am_wauth->authentication_finished(
       
  2099 					true,
       
  2100 					state->get_eap_type(),
       
  2101 					m_authentication_type);
       
  2102 
       
  2103 #if defined(USE_EAP_EXPANDED_TYPES)
       
  2104 				if (state->get_eap_type() == eap_expanded_type_simple_config.get_type())
       
  2105 				{
       
  2106 					increment_authentication_counter();
       
  2107 					m_successful_authentications++;
       
  2108 
       
  2109 					EAP_TRACE_ALWAYS(
       
  2110 						m_am_tools,
       
  2111 						TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
  2112 						(EAPL("EAPOL_KEY: %s: EAP WFA Protected Setup SUCCESS\n"),
       
  2113 						(m_is_client == true ? "client": "server")));
       
  2114 
       
  2115 					eap_status_e status = eapol_indication(
       
  2116 						&receive_network_id,
       
  2117 						eapol_wlan_authentication_state_authentication_successfull);
       
  2118 					if (status != eap_status_ok)
       
  2119 					{
       
  2120 						EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2121 						return;
       
  2122 					}
       
  2123 				}
       
  2124 #endif //#if defined(USE_EAP_EXPANDED_TYPES)
       
  2125 
       
  2126 			}
       
  2127 			break;
       
  2128 		case eap_state_authentication_terminated_unsuccessfully:
       
  2129 			{
       
  2130 				increment_authentication_counter();
       
  2131 				m_failed_authentications++;
       
  2132 
       
  2133 #if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  2134 
       
  2135 				EAP_TRACE_DEBUG(
       
  2136 					m_am_tools,
       
  2137 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2138 					(EAPL("calls partner: eapol_wlan_authentication_c::state_notification(): %s: m_partner->state_notification()\n"),
       
  2139 					 (m_is_client == true) ? "client": "server"));
       
  2140 
       
  2141 				// Calls lower layer.
       
  2142 				// Note the optimization prevents most of the state notifications to lower layer.
       
  2143 				m_partner->state_notification(state);
       
  2144 
       
  2145 				EAP_TRACE_DEBUG(
       
  2146 					m_am_tools,
       
  2147 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2148 					(EAPL("returns from partner: eapol_wlan_authentication_c::state_notification(): %s: m_partner->state_notification()\n"),
       
  2149 					 (m_is_client == true) ? "client": "server"));
       
  2150 
       
  2151 #endif //#if defined(USE_EAPOL_KEY_STATE_OPTIMIZED_4_WAY_HANDSHAKE)
       
  2152 
       
  2153 				EAP_TRACE_DEBUG(
       
  2154 					m_am_tools,
       
  2155 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2156 					(EAPL("calls: eapol_wlan_authentication_c::state_notification(): m_am_wauth->authentication_finished(): %s.\n"),
       
  2157 					(m_is_client == true) ? "client": "server"));
       
  2158 
       
  2159 				m_am_wauth->authentication_finished(
       
  2160 					false,
       
  2161 					state->get_eap_type(),
       
  2162 					m_authentication_type);
       
  2163 
       
  2164 				(void) cancel_timer_this_ap_failed();
       
  2165 
       
  2166 				set_timer(
       
  2167 					this,
       
  2168 					EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID,
       
  2169 					send_network_id,
       
  2170 					0);
       
  2171 				automatic_send_network_id.do_not_free_variable();
       
  2172 
       
  2173 				EAP_TRACE_DEBUG(
       
  2174 					m_am_tools,
       
  2175 					TRACE_FLAGS_DEFAULT,
       
  2176 					(EAPL("Sets timer EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID.\n")));
       
  2177 			}
       
  2178 			break;
       
  2179 		default:
       
  2180 			break;
       
  2181 		}
       
  2182 	}
       
  2183 	else if(state->get_protocol_layer() == eap_protocol_layer_eapol)
       
  2184 	{
       
  2185 		switch (state->get_current_state())
       
  2186 		{
       
  2187 		case eapol_state_no_start_response:
       
  2188 			EAP_TRACE_DEBUG(
       
  2189 				m_am_tools,
       
  2190 				TRACE_FLAGS_DEFAULT,
       
  2191 				(EAPL("ERROR: Indication sent to WLM: ENoResponse.\n")));
       
  2192 
       
  2193 			{
       
  2194 				(void) cancel_timer_no_response();
       
  2195 
       
  2196 				set_timer(
       
  2197 					this,
       
  2198 					EAPOL_WLAN_AUTHENTICATION_TIMER_NO_RESPONSE_ID,
       
  2199 					send_network_id,
       
  2200 					0);
       
  2201 				automatic_send_network_id.do_not_free_variable();
       
  2202 
       
  2203 				EAP_TRACE_DEBUG(
       
  2204 					m_am_tools,
       
  2205 					TRACE_FLAGS_DEFAULT,
       
  2206 					(EAPL("Sets timer ")
       
  2207 					 EAPL("EAPOL_WLAN_AUTHENTICATION_TIMER_NO_RESPONSE_ID.\n")));
       
  2208 			}
       
  2209 			break;
       
  2210 		default:
       
  2211 			break;
       
  2212 		}
       
  2213 	}
       
  2214 	else if(state->get_protocol_layer() == eap_protocol_layer_eapol_key)
       
  2215 	{
       
  2216 		switch (state->get_current_state())
       
  2217 		{
       
  2218 
       
  2219 		case eapol_key_state_eap_authentication_running:
       
  2220 			{
       
  2221 				EAP_TRACE_ALWAYS(
       
  2222 					m_am_tools,
       
  2223 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
  2224 					(EAPL("EAPOL_KEY: %s: EAP authentication RUNNING\n"),
       
  2225 					(m_is_client == true ? "client": "server")));
       
  2226 
       
  2227 				eap_status_e status = eapol_indication(
       
  2228 					&receive_network_id,
       
  2229 					eapol_wlan_authentication_state_eap_authentication_running);
       
  2230 				if (status != eap_status_ok)
       
  2231 				{
       
  2232 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2233 					return;
       
  2234 				}
       
  2235 			}
       
  2236 			break;
       
  2237 
       
  2238 		case eapol_key_state_4_way_handshake_running:
       
  2239 			{
       
  2240 				EAP_TRACE_ALWAYS(
       
  2241 					m_am_tools,
       
  2242 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
  2243 					(EAPL("EAPOL_KEY: %s: 4-Way Handshake RUNNING\n"),
       
  2244 					(m_is_client == true ? "client": "server")));
       
  2245 
       
  2246 				eap_status_e status = eapol_indication(
       
  2247 					&receive_network_id,
       
  2248 					eapol_wlan_authentication_state_4_way_handshake_running);
       
  2249 				if (status != eap_status_ok)
       
  2250 				{
       
  2251 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2252 					return;
       
  2253 				}
       
  2254 			}
       
  2255 			break;
       
  2256 
       
  2257 		case eapol_key_state_802_11i_authentication_terminated_unsuccessfull:
       
  2258 		case eapol_key_state_reassociation_failed:
       
  2259 			{					
       
  2260 				increment_authentication_counter();
       
  2261 				m_failed_authentications++;
       
  2262 
       
  2263 				// Consider EAPOL layer failures fatal.
       
  2264 				EAP_TRACE_ERROR(
       
  2265 					m_am_tools,
       
  2266 					TRACE_FLAGS_DEFAULT,
       
  2267 					(EAPL("ERROR: Unsuccessful authentication on EAPOL level.\n")));
       
  2268 
       
  2269 				(void) cancel_timer_this_ap_failed();
       
  2270 
       
  2271 				set_timer(
       
  2272 					this,
       
  2273 					EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID,
       
  2274 					send_network_id,
       
  2275 					0);
       
  2276 				automatic_send_network_id.do_not_free_variable();
       
  2277 
       
  2278 				EAP_TRACE_DEBUG(
       
  2279 					m_am_tools,
       
  2280 					TRACE_FLAGS_DEFAULT,
       
  2281 					(EAPL("Sets timer EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID.\n")));
       
  2282 			}
       
  2283 			break;
       
  2284 
       
  2285 		case eapol_key_state_802_11i_authentication_finished_successfull:
       
  2286 #if defined(EAP_USE_WPXM)
       
  2287 		case eapol_key_state_wpxm_reassociation_finished_successfull:
       
  2288 #endif //#if defined(EAP_USE_WPXM)
       
  2289 			{
       
  2290 				// This is used in dynamic WEP (802.1x), WPA and WPA2 (RNS) authentications.
       
  2291 				increment_authentication_counter();
       
  2292 				m_successful_authentications++;
       
  2293 
       
  2294 				EAP_TRACE_ALWAYS(
       
  2295 					m_am_tools,
       
  2296 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
  2297 					(EAPL("EAPOL_KEY: %s: Authentication SUCCESS\n"),
       
  2298 					(m_is_client == true ? "client": "server")));
       
  2299 
       
  2300 				eap_status_e status = eapol_indication(
       
  2301 					&receive_network_id,
       
  2302 					eapol_wlan_authentication_state_authentication_successfull);
       
  2303 				if (status != eap_status_ok)
       
  2304 				{
       
  2305 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2306 					return;
       
  2307 				}
       
  2308 			}
       
  2309 			break;
       
  2310 
       
  2311 		default:
       
  2312 			break;
       
  2313 		}
       
  2314 	}
       
  2315 
       
  2316 	EAP_TRACE_DEBUG(
       
  2317 		m_am_tools,
       
  2318 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2319 		(EAPL("calls: eapol_wlan_authentication_c::state_notification(): m_am_wauth->state_notification(): %s.\n"),
       
  2320 		(m_is_client == true) ? "client": "server"));
       
  2321 
       
  2322 	// AM could have to show some notification to user.
       
  2323 	m_am_wauth->state_notification(state);
       
  2324 
       
  2325 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2326 }
       
  2327 
       
  2328 //--------------------------------------------------
       
  2329 
       
  2330 //
       
  2331 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::timer_expired(
       
  2332 	const u32_t id,
       
  2333 	void * data)
       
  2334 {
       
  2335 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2336 	EAP_TRACE_DEBUG(
       
  2337 		m_am_tools,
       
  2338 		TRACE_FLAGS_DEFAULT,
       
  2339 		(EAPL("eapol calls: eapol_wlan_authentication_c::timer_expired(): id = %d, data = 0x%08x.\n"),
       
  2340 		id,
       
  2341 		data));
       
  2342 
       
  2343 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::timer_expired()");
       
  2344 
       
  2345 	eap_am_network_id_c * const send_network_id = static_cast<eap_am_network_id_c *>(data);
       
  2346 	if (send_network_id == 0 
       
  2347 		|| send_network_id->get_is_valid_data() == false)
       
  2348 	{
       
  2349 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
  2350 	}
       
  2351 
       
  2352 	// Here we swap the addresses.
       
  2353 	eap_am_network_id_c receive_network_id(m_am_tools,
       
  2354 		send_network_id->get_destination_id(),
       
  2355 		send_network_id->get_source_id(),
       
  2356 		send_network_id->get_type());
       
  2357 
       
  2358 
       
  2359 	switch (id)
       
  2360 	{
       
  2361 	case EAPOL_WLAN_AUTHENTICATION_TIMER_FAILED_COMPLETELY_ID:
       
  2362 		{
       
  2363 			EAP_TRACE_DEBUG(
       
  2364 				m_am_tools,
       
  2365 				TRACE_FLAGS_DEFAULT,
       
  2366 				(EAPL("EAPOL_WLAN_AUTHENTICATION_TIMER_FAILED_COMPLETELY_ID elapsed: ")
       
  2367 				 EAPL("Indication sent to WLM: eap_status_failed_completely.\n")));
       
  2368 
       
  2369 			(void) disassociation_mutex_must_be_reserved(&receive_network_id);
       
  2370 
       
  2371 			eap_status_e status = eapol_indication(
       
  2372 				&receive_network_id,
       
  2373 				eapol_wlan_authentication_state_failed_completely);
       
  2374 			if (status != eap_status_ok)
       
  2375 			{
       
  2376 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2377 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2378 			}
       
  2379 		}
       
  2380 		break;
       
  2381 	
       
  2382 	case EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID:
       
  2383 		{
       
  2384 			EAP_TRACE_DEBUG(
       
  2385 				m_am_tools,
       
  2386 				TRACE_FLAGS_DEFAULT,
       
  2387 				(EAPL("EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID elapsed: ")
       
  2388 				 EAPL("Indication sent to WLM: eap_status_this_ap_failed.\n")));
       
  2389 
       
  2390 			(void) disassociation_mutex_must_be_reserved(&receive_network_id);
       
  2391 
       
  2392 			eap_status_e status = eapol_indication(
       
  2393 				&receive_network_id,
       
  2394 				eapol_wlan_authentication_state_this_ap_failed);
       
  2395 			if (status != eap_status_ok)
       
  2396 			{
       
  2397 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2398 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2399 			}
       
  2400 		}
       
  2401 		break;
       
  2402 
       
  2403 	case EAPOL_WLAN_AUTHENTICATION_TIMER_NO_RESPONSE_ID:
       
  2404 		{
       
  2405 			EAP_TRACE_DEBUG(
       
  2406 				m_am_tools,
       
  2407 				TRACE_FLAGS_DEFAULT,
       
  2408 				(EAPL("EAPOL_WLAN_AUTHENTICATION_TIMER_NO_RESPONSE_ID elapsed: ")
       
  2409 				 EAPL("Indication sent to WLM: eap_status_no_response.\n")));
       
  2410 
       
  2411 			(void) disassociation_mutex_must_be_reserved(&receive_network_id);
       
  2412 
       
  2413 			eap_status_e status = eapol_indication(
       
  2414 				&receive_network_id,
       
  2415 				eapol_wlan_authentication_state_no_response);
       
  2416 			if (status != eap_status_ok)
       
  2417 			{
       
  2418 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2419 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2420 			}
       
  2421 		}
       
  2422 		break;
       
  2423 		
       
  2424 	case EAPOL_WLAN_AUTHENTICATION_TIMER_AUTHENTICATION_CANCELLED_ID:
       
  2425 		{
       
  2426 			EAP_TRACE_DEBUG(
       
  2427 				m_am_tools,
       
  2428 				TRACE_FLAGS_DEFAULT,
       
  2429 				(EAPL("EAPOL_WLAN_AUTHENTICATION_TIMER_AUTHENTICATION_CANCELLED_ID elapsed: ")
       
  2430 				 EAPL("Indication sent to WLM: eapol_wlan_authentication_state_authentication_cancelled.\n")));
       
  2431 
       
  2432 			(void) disassociation_mutex_must_be_reserved(&receive_network_id);
       
  2433 		}
       
  2434 		break;
       
  2435 
       
  2436 	default:
       
  2437 		break;
       
  2438 	}
       
  2439 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  2440 }
       
  2441 
       
  2442 //--------------------------------------------------
       
  2443 
       
  2444 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::timer_delete_data(
       
  2445 	const u32_t id,
       
  2446 	void *data)
       
  2447 {
       
  2448 	EAP_TRACE_DEBUG(
       
  2449 		m_am_tools,
       
  2450 		TRACE_FLAGS_DEFAULT,
       
  2451 		(EAPL("eapol calls: eapol_wlan_authentication_c::timer_delete_data(): id = %d, data = 0x%08x.\n"),
       
  2452 		id,
       
  2453 		data));
       
  2454 
       
  2455 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::timer_delete_data()");
       
  2456 
       
  2457 	eap_am_network_id_c * const send_network_id = static_cast<eap_am_network_id_c *>(data);
       
  2458 	if (send_network_id == 0 
       
  2459 		|| send_network_id->get_is_valid_data() == false)
       
  2460 	{
       
  2461 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
  2462 	}
       
  2463 
       
  2464 	switch (id)
       
  2465 	{
       
  2466 	//case EAPOL_WLAN_AUTHENTICATION_TIMER_RESTART_AUTHENTICATION_ID:
       
  2467 	//case EAPOL_WLAN_AUTHENTICATION_TIMER_DELETE_STACK_ID:
       
  2468 	case EAPOL_WLAN_AUTHENTICATION_TIMER_FAILED_COMPLETELY_ID:
       
  2469 	case EAPOL_WLAN_AUTHENTICATION_TIMER_THIS_AP_FAILED_ID:
       
  2470 	case EAPOL_WLAN_AUTHENTICATION_TIMER_NO_RESPONSE_ID:
       
  2471 	case EAPOL_WLAN_AUTHENTICATION_TIMER_AUTHENTICATION_CANCELLED_ID:
       
  2472 		delete send_network_id;
       
  2473 		break;
       
  2474 	default:
       
  2475 		{
       
  2476 			EAP_TRACE_ERROR(
       
  2477 				m_am_tools,
       
  2478 				TRACE_FLAGS_DEFAULT,
       
  2479 				(EAPL("eapol_wlan_authentication_c::timer_delete_data: deleted unknown timer.\n")));
       
  2480 			(void)EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported);
       
  2481 		}
       
  2482 	}
       
  2483 
       
  2484 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  2485 }
       
  2486 
       
  2487 //--------------------------------------------------
       
  2488 
       
  2489 //
       
  2490 EAP_FUNC_EXPORT u32_t eapol_wlan_authentication_c::get_header_offset(
       
  2491 	u32_t * const MTU,
       
  2492 	u32_t * const trailer_length)
       
  2493 {
       
  2494 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2495 
       
  2496 	EAP_TRACE_DEBUG(
       
  2497 		m_am_tools,
       
  2498 		TRACE_FLAGS_DEFAULT,
       
  2499 		(EAPL("eapol calls: eapol_wlan_authentication_c::get_header_offset()\n")));
       
  2500 
       
  2501 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::get_header_offset()");
       
  2502 
       
  2503 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  2504 
       
  2505 	EAP_TRACE_DEBUG(
       
  2506 		m_am_tools,
       
  2507 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2508 		(EAPL("calls partner: eapol_wlan_authentication_c::get_header_offset(): %s: m_partner->get_header_offset()\n"),
       
  2509 		 (m_is_client == true) ? "client": "server"));
       
  2510 	
       
  2511 	const u32_t offset = m_partner->get_header_offset(MTU, trailer_length);
       
  2512 
       
  2513 	EAP_TRACE_DEBUG(
       
  2514 		m_am_tools,
       
  2515 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2516 		(EAPL("returns from partner: eapol_wlan_authentication_c::get_header_offset(): %s: m_partner->get_header_offset(): offset = %d\n"),
       
  2517 		 (m_is_client == true) ? "client": "server",
       
  2518 		 offset));
       
  2519 
       
  2520 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2521 	return offset;
       
  2522 
       
  2523 }
       
  2524 
       
  2525 //--------------------------------------------------
       
  2526 
       
  2527 //
       
  2528 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::unload_module(
       
  2529 	const eap_type_value_e type)
       
  2530 {
       
  2531 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2532 
       
  2533 	EAP_TRACE_DEBUG(
       
  2534 		m_am_tools,
       
  2535 		TRACE_FLAGS_DEFAULT,
       
  2536 		(EAPL("eapol calls: eapol_wlan_authentication_c::unload_module(type 0x%08x=%s): \n"),
       
  2537 		convert_eap_type_to_u32_t(type),
       
  2538 		eap_header_string_c::get_eap_type_string(type)
       
  2539 		));
       
  2540 
       
  2541 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::unload_module()");
       
  2542 
       
  2543 	eap_status_e status(eap_status_type_does_not_exists_error);
       
  2544 
       
  2545 	EAP_TRACE_DEBUG(
       
  2546 		m_am_tools,
       
  2547 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2548 		(EAPL("calls: eapol_wlan_authentication_c::unload_module(): m_am_wauth->unload_module(): %s.\n"),
       
  2549 		(m_is_client == true) ? "client": "server"));
       
  2550 
       
  2551 	status = m_am_wauth->unload_module(type);
       
  2552 
       
  2553 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2554 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2555 }
       
  2556 
       
  2557 //--------------------------------------------------
       
  2558 
       
  2559 //
       
  2560 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::eap_acknowledge(
       
  2561 	const eap_am_network_id_c * const receive_network_id)
       
  2562 {
       
  2563 	// Any Network Protocol packet is accepted as a success indication.
       
  2564 	// This is described in RFC 2284 "PPP Extensible Authentication Protocol (EAP)".
       
  2565 
       
  2566 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2567 
       
  2568 	EAP_TRACE_DEBUG(
       
  2569 		m_am_tools,
       
  2570 		TRACE_FLAGS_DEFAULT,
       
  2571 		(EAPL("partner calls: eapol_wlan_authentication_c::eap_acknowledge()\n")));
       
  2572 
       
  2573 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::eap_acknowledge()");
       
  2574 
       
  2575 	WAUTH_ENTER_MUTEX(m_am_tools);
       
  2576 	EAP_TRACE_DEBUG(
       
  2577 		m_am_tools,
       
  2578 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2579 		(EAPL("calls eapol: eapol_wlan_authentication_c::eap_acknowledge(): m_ethernet_core->eap_acknowledge(): %s.\n"),
       
  2580 		(m_is_client == true) ? "client": "server"));
       
  2581 	eap_status_e status = m_ethernet_core->eap_acknowledge(receive_network_id);
       
  2582 	EAP_TRACE_DEBUG(
       
  2583 		m_am_tools,
       
  2584 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2585 		(EAPL("returns from eapol: eapol_wlan_authentication_c::eap_acknowledge(): m_ethernet_core->eap_acknowledge(): %s, status = %s.\n"),
       
  2586 		 (m_is_client == true) ? "client": "server",
       
  2587 		 eap_status_string_c::get_status_string(status)));
       
  2588 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
  2589 
       
  2590 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2591 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2592 }
       
  2593 
       
  2594 //--------------------------------------------------
       
  2595 
       
  2596 //
       
  2597 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::load_module(
       
  2598 		const eap_type_value_e type,
       
  2599 		const eap_type_value_e tunneling_type,
       
  2600 		abs_eap_base_type_c * const partner,
       
  2601 		eap_base_type_c ** const eap_type_if,
       
  2602 		const bool is_client_when_true,
       
  2603 		const eap_am_network_id_c * const receive_network_id)
       
  2604 {	
       
  2605 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2606 
       
  2607 	EAP_TRACE_DEBUG(
       
  2608 		m_am_tools,
       
  2609 		TRACE_FLAGS_DEFAULT,
       
  2610 		(EAPL("eapol calls: eapol_wlan_authentication_c::load_module(type 0x%08x=%s, tunneling_type 0x%08x=%s), %s\n"),
       
  2611 		convert_eap_type_to_u32_t(type),
       
  2612 		eap_header_string_c::get_eap_type_string(type),
       
  2613 		convert_eap_type_to_u32_t(tunneling_type),
       
  2614 		eap_header_string_c::get_eap_type_string(tunneling_type),
       
  2615 		(m_is_client == true) ? "client": "server"));
       
  2616 
       
  2617 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::load_module()");
       
  2618 
       
  2619 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  2620 
       
  2621 	EAP_TRACE_DEBUG(
       
  2622 		m_am_tools,
       
  2623 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2624 		(EAPL("calls: eapol_wlan_authentication_c::load_module(): m_am_wauth->load_module(): %s.\n"),
       
  2625 		(m_is_client == true) ? "client": "server"));
       
  2626 
       
  2627 	eap_status_e status = m_am_wauth->load_module(
       
  2628 		type,
       
  2629 		tunneling_type,
       
  2630 		partner,
       
  2631 		eap_type_if,
       
  2632 		is_client_when_true,
       
  2633 		receive_network_id);
       
  2634 
       
  2635 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2636 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2637 }
       
  2638 
       
  2639 //--------------------------------------------------
       
  2640 
       
  2641 //
       
  2642 eap_status_e eapol_wlan_authentication_c::disassociation_mutex_must_be_reserved(
       
  2643 	const eap_am_network_id_c * const receive_network_id ///< source includes remote address, destination includes local address.
       
  2644 	)
       
  2645 {
       
  2646 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2647 
       
  2648 	EAP_TRACE_DEBUG(
       
  2649 		m_am_tools,
       
  2650 		TRACE_FLAGS_DEFAULT,
       
  2651 		(EAPL("eapol calls: eapol_wlan_authentication_c::disassociation_mutex_must_be_reserved(): %s\n"),
       
  2652 		(m_is_client == true) ? "client": "server"));
       
  2653 
       
  2654 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::disassociation_mutex_must_be_reserved()");
       
  2655 
       
  2656 	// reset index
       
  2657 	m_current_eap_index = 0UL;
       
  2658 
       
  2659 	eap_status_e status(eap_status_process_general_error);
       
  2660 
       
  2661 	if (m_ethernet_core != 0)
       
  2662 	{
       
  2663 		EAP_TRACE_DEBUG(
       
  2664 			m_am_tools,
       
  2665 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2666 			(EAPL("calls eapol: eapol_wlan_authentication_c::disassociation_mutex_must_be_reserved(): m_ethernet_core->disassociation(): %s.\n"),
       
  2667 			(m_is_client == true) ? "client": "server"));
       
  2668 
       
  2669 		status = m_ethernet_core->disassociation(receive_network_id);
       
  2670 
       
  2671 		EAP_TRACE_DEBUG(
       
  2672 			m_am_tools,
       
  2673 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2674 			(EAPL("returns from eapol: eapol_wlan_authentication_c::disassociation_mutex_must_be_reserved(): m_ethernet_core->disassociation(): %s, status = %s.\n"),
       
  2675 			 (m_is_client == true) ? "client": "server",
       
  2676 			 eap_status_string_c::get_status_string(status)));
       
  2677 
       
  2678 		if (status == eap_status_handler_does_not_exists_error)
       
  2679 		{
       
  2680 			EAP_TRACE_DEBUG(
       
  2681 				m_am_tools,
       
  2682 				TRACE_FLAGS_DEFAULT,
       
  2683 				(EAPL("eapol_wlan_authentication_c::disassociation_mutex_must_be_reserved(): Association did not exists.\n")));
       
  2684 			status = eap_status_ok;
       
  2685 		}
       
  2686 	}
       
  2687 	else
       
  2688 	{
       
  2689 		EAP_TRACE_DEBUG(
       
  2690 			m_am_tools,
       
  2691 			TRACE_FLAGS_DEFAULT,
       
  2692 			(EAPL("eapol_wlan_authentication_c::disassociation_mutex_must_be_reserved(): Stack did not exists.\n")));
       
  2693 	}
       
  2694 
       
  2695 	EAP_TRACE_DEBUG(
       
  2696 		m_am_tools,
       
  2697 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2698 		(EAPL("calls: eapol_wlan_authentication_c::disassociation_mutex_must_be_reserved(): m_am_wauth->disassociation(): %s.\n"),
       
  2699 		(m_is_client == true) ? "client": "server"));
       
  2700 
       
  2701 	// This call indicates the disassociation to adaptation.
       
  2702 	status = m_am_wauth->disassociation(receive_network_id);
       
  2703 	if (status != eap_status_ok)
       
  2704 	{
       
  2705 		EAP_TRACE_DEBUG(
       
  2706 			m_am_tools,
       
  2707 			TRACE_FLAGS_DEFAULT,
       
  2708 			(EAPL("eapol_wlan_authentication_c::disassociation_mutex_must_be_reserved(): m_am_wauth->disassociation() failed.\n")));
       
  2709 		(void) EAP_STATUS_RETURN(m_am_tools, status);
       
  2710 	}
       
  2711 
       
  2712 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2713 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2714 }
       
  2715 
       
  2716 //--------------------------------------------------
       
  2717 
       
  2718 //
       
  2719 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::disassociation(
       
  2720 	const eap_am_network_id_c * const receive_network_id ///< source includes remote address, destination includes local address.
       
  2721 	)
       
  2722 {
       
  2723 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2724 
       
  2725 	EAP_TRACE_DEBUG(
       
  2726 		m_am_tools,
       
  2727 		TRACE_FLAGS_DEFAULT,
       
  2728 		(EAPL("partner calls: eapol_wlan_authentication_c::disassociation(): %s\n"),
       
  2729 		(m_is_client == true) ? "client": "server"));
       
  2730 
       
  2731 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::disassociation()");
       
  2732 
       
  2733 	eap_status_e status(eap_status_ok);
       
  2734 
       
  2735 	WAUTH_ENTER_MUTEX(m_am_tools);
       
  2736 	status = disassociation_mutex_must_be_reserved(receive_network_id);
       
  2737 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
  2738 
       
  2739 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2740 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2741 }
       
  2742 
       
  2743 //--------------------------------------------------
       
  2744 
       
  2745 //
       
  2746 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::tkip_mic_failure(
       
  2747 	const eap_am_network_id_c * const receive_network_id,
       
  2748 	const bool fatal_failure_when_true,
       
  2749 	const eapol_RSNA_key_header_c::eapol_tkip_mic_failure_type_e tkip_mic_failure_type)
       
  2750 {
       
  2751 	EAP_TRACE_DEBUG(
       
  2752 		m_am_tools,
       
  2753 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
  2754 		(EAPL("partner calls: eapol_wlan_authentication_c::tkip_mic_failure(%d, %d).\n"),
       
  2755 		fatal_failure_when_true,
       
  2756 		tkip_mic_failure_type));
       
  2757 
       
  2758 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::tkip_mic_failure()");
       
  2759 
       
  2760 	WAUTH_ENTER_MUTEX(m_am_tools);
       
  2761 	EAP_TRACE_DEBUG(
       
  2762 		m_am_tools,
       
  2763 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2764 		(EAPL("calls eapol: eapol_wlan_authentication_c::tkip_mic_failure(): m_ethernet_core->tkip_mic_failure(): %s.\n"),
       
  2765 		(m_is_client == true) ? "client": "server"));
       
  2766 	const eap_status_e status = m_ethernet_core->tkip_mic_failure(
       
  2767 		receive_network_id,
       
  2768 		fatal_failure_when_true,
       
  2769 		tkip_mic_failure_type);
       
  2770 	EAP_TRACE_DEBUG(
       
  2771 		m_am_tools,
       
  2772 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2773 		(EAPL("returns from eapol: eapol_wlan_authentication_c::tkip_mic_failure(): m_ethernet_core->tkip_mic_failure(): %s, status = %s.\n"),
       
  2774 		 (m_is_client == true) ? "client": "server",
       
  2775 		 eap_status_string_c::get_status_string(status)));
       
  2776 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
  2777 
       
  2778 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2779 }
       
  2780 
       
  2781 //--------------------------------------------------
       
  2782 
       
  2783 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::configure()
       
  2784 {	
       
  2785 	EAP_TRACE_DEBUG(
       
  2786 		m_am_tools,
       
  2787 		TRACE_FLAGS_DEFAULT,
       
  2788 		(EAPL("partner calls: eapol_wlan_authentication_c::configure(): %s\n"),
       
  2789 		(m_is_client == true) ? "client": "server"));
       
  2790 
       
  2791 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::configure()");
       
  2792 
       
  2793 	//----------------------------------------------------------
       
  2794 
       
  2795 	EAP_TRACE_DEBUG(
       
  2796 		m_am_tools,
       
  2797 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2798 		(EAPL("calls: eapol_wlan_authentication_c::configure(): m_am_wauth->configure(): %s.\n"),
       
  2799 		(m_is_client == true) ? "client": "server"));
       
  2800 
       
  2801 	eap_status_e status = m_am_wauth->configure();
       
  2802 	if (status != eap_status_ok)
       
  2803 	{
       
  2804 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2805 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2806 	}
       
  2807 
       
  2808 	//----------------------------------------------------------
       
  2809 
       
  2810 #if defined(USE_EAP_ERROR_TESTS)
       
  2811 
       
  2812 	{
       
  2813 		eap_variable_data_c EAP_ERROR_TEST_randomly_drop_packets(m_am_tools);
       
  2814 		
       
  2815 		status = read_configure(
       
  2816 			cf_str_EAP_ERROR_TEST_randomly_drop_packets.get_field(),
       
  2817 			&EAP_ERROR_TEST_randomly_drop_packets);
       
  2818 		if (status == eap_status_ok
       
  2819 			&& EAP_ERROR_TEST_randomly_drop_packets.get_is_valid_data() == true)
       
  2820 		{
       
  2821 			u32_t *randomly_drop_packets = reinterpret_cast<u32_t *>(
       
  2822 				EAP_ERROR_TEST_randomly_drop_packets.get_data(sizeof(u32_t)));
       
  2823 			if (randomly_drop_packets != 0
       
  2824 				&& *randomly_drop_packets != 0)
       
  2825 			{
       
  2826 				m_randomly_drop_packets = true;
       
  2827 			}
       
  2828 		}
       
  2829 	}
       
  2830 		
       
  2831 	{
       
  2832 		eap_variable_data_c EAP_ERROR_TEST_randomly_drop_packets_probability(m_am_tools);
       
  2833 
       
  2834 		status = read_configure(
       
  2835 			cf_str_EAP_ERROR_TEST_randomly_drop_packets_probability.get_field(),
       
  2836 			&EAP_ERROR_TEST_randomly_drop_packets_probability);
       
  2837 		if (status == eap_status_ok
       
  2838 			&& EAP_ERROR_TEST_randomly_drop_packets_probability.get_is_valid_data() == true)
       
  2839 		{
       
  2840 			u32_t *randomly_drop_packets_probability = reinterpret_cast<u32_t *>(
       
  2841 				EAP_ERROR_TEST_randomly_drop_packets_probability.get_data(sizeof(u32_t)));
       
  2842 			if (randomly_drop_packets_probability != 0)
       
  2843 			{
       
  2844 				m_randomly_drop_packets_probability = *randomly_drop_packets_probability;
       
  2845 			}
       
  2846 		}
       
  2847 	}
       
  2848 		
       
  2849 	{
       
  2850 		eap_variable_data_c EAP_ERROR_TEST_enable_random_errors(m_am_tools);
       
  2851 
       
  2852 		eap_status_e status = read_configure(
       
  2853 			cf_str_EAP_ERROR_TEST_enable_random_errors.get_field(),
       
  2854 			&EAP_ERROR_TEST_enable_random_errors);
       
  2855 		if (status == eap_status_ok
       
  2856 			&& EAP_ERROR_TEST_enable_random_errors.get_is_valid_data() == true)
       
  2857 		{
       
  2858 			u32_t *enable_random_errors = reinterpret_cast<u32_t *>(
       
  2859 				EAP_ERROR_TEST_enable_random_errors.get_data(sizeof(u32_t)));
       
  2860 			if (enable_random_errors != 0
       
  2861 				&& *enable_random_errors != 0)
       
  2862 			{
       
  2863 				m_enable_random_errors = true;
       
  2864 			}
       
  2865 		}
       
  2866 	}
       
  2867 
       
  2868 	{
       
  2869 		eap_variable_data_c EAP_ERROR_TEST_send_original_packet_first(m_am_tools);
       
  2870 
       
  2871 		eap_status_e status = read_configure(
       
  2872 			cf_str_EAP_ERROR_TEST_send_original_packet_first.get_field(),
       
  2873 			&EAP_ERROR_TEST_send_original_packet_first);
       
  2874 		if (status == eap_status_ok
       
  2875 			&& EAP_ERROR_TEST_send_original_packet_first.get_is_valid_data() == true)
       
  2876 		{
       
  2877 			u32_t *send_original_packet_first = reinterpret_cast<u32_t *>(
       
  2878 				EAP_ERROR_TEST_send_original_packet_first.get_data(sizeof(u32_t)));
       
  2879 			if (send_original_packet_first != 0
       
  2880 				&& *send_original_packet_first != 0)
       
  2881 			{
       
  2882 				m_send_original_packet_first = true;
       
  2883 			}
       
  2884 		}
       
  2885 	}
       
  2886 
       
  2887 	{
       
  2888 		eap_variable_data_c EAP_ERROR_TEST_generate_multiple_error_packets(m_am_tools);
       
  2889 
       
  2890 		eap_status_e status = read_configure(
       
  2891 			cf_str_EAP_ERROR_TEST_generate_multiple_error_packets.get_field(),
       
  2892 			&EAP_ERROR_TEST_generate_multiple_error_packets);
       
  2893 		if (status == eap_status_ok
       
  2894 			&& EAP_ERROR_TEST_generate_multiple_error_packets.get_is_valid_data() == true)
       
  2895 		{
       
  2896 			u32_t *generate_multiple_error_packets = reinterpret_cast<u32_t *>(
       
  2897 				EAP_ERROR_TEST_generate_multiple_error_packets.get_data(sizeof(u32_t)));
       
  2898 			if (generate_multiple_error_packets != 0
       
  2899 				&& *generate_multiple_error_packets != 0)
       
  2900 			{
       
  2901 				m_generate_multiple_error_packets = *generate_multiple_error_packets;
       
  2902 			}
       
  2903 		}
       
  2904 	}
       
  2905 
       
  2906 
       
  2907 	{
       
  2908 		eap_variable_data_c EAP_ERROR_TEST_manipulate_ethernet_header(m_am_tools);
       
  2909 
       
  2910 		eap_status_e status = read_configure(
       
  2911 			cf_str_EAP_ERROR_TEST_manipulate_ethernet_header.get_field(),
       
  2912 			&EAP_ERROR_TEST_manipulate_ethernet_header);
       
  2913 		if (status == eap_status_ok
       
  2914 			&& EAP_ERROR_TEST_manipulate_ethernet_header.get_is_valid_data() == true)
       
  2915 		{
       
  2916 			u32_t *manipulate_ethernet_header = reinterpret_cast<u32_t *>(
       
  2917 				EAP_ERROR_TEST_manipulate_ethernet_header.get_data(sizeof(u32_t)));
       
  2918 			if (manipulate_ethernet_header != 0
       
  2919 				&& *manipulate_ethernet_header != 0)
       
  2920 			{
       
  2921 				m_manipulate_ethernet_header = true;
       
  2922 			}
       
  2923 		}
       
  2924 	}
       
  2925 
       
  2926 	{
       
  2927 		eap_variable_data_c EAP_ERROR_TEST_error_probability(m_am_tools);
       
  2928 
       
  2929 		eap_status_e status = read_configure(
       
  2930 			cf_str_EAP_ERROR_TEST_error_probability.get_field(),
       
  2931 			&EAP_ERROR_TEST_error_probability);
       
  2932 		if (status == eap_status_ok
       
  2933 			&& EAP_ERROR_TEST_error_probability.get_is_valid_data() == true)
       
  2934 		{
       
  2935 			u32_t *error_probability = reinterpret_cast<u32_t *>(
       
  2936 				EAP_ERROR_TEST_error_probability.get_data(sizeof(u32_t)));
       
  2937 			if (error_probability != 0)
       
  2938 			{
       
  2939 				m_error_probability = *error_probability;
       
  2940 			}
       
  2941 		}
       
  2942 	}	
       
  2943 
       
  2944 	{
       
  2945 		eap_variable_data_c EAP_disable_function_traces(m_am_tools);
       
  2946 
       
  2947 		eap_status_e status = read_configure(
       
  2948 			cf_str_EAP_TRACE_enable_function_traces.get_field(),
       
  2949 			&EAP_disable_function_traces);
       
  2950 		if (status == eap_status_ok
       
  2951 			&& EAP_disable_function_traces.get_is_valid_data() == true)
       
  2952 		{
       
  2953 			u32_t *disable_function_traces = reinterpret_cast<u32_t *>(
       
  2954 				EAP_disable_function_traces.get_data(sizeof(u32_t)));
       
  2955 			if (disable_function_traces != 0
       
  2956 				&& *disable_function_traces != 0)
       
  2957 			{
       
  2958 				m_am_tools->set_trace_mask(
       
  2959 					m_am_tools->get_trace_mask()
       
  2960 					| eap_am_tools_c::eap_trace_mask_functions
       
  2961 					);
       
  2962 			}
       
  2963 		}
       
  2964 	}
       
  2965 
       
  2966 #endif //#if defined(USE_EAP_ERROR_TESTS)
       
  2967 
       
  2968 
       
  2969 	//----------------------------------------------------------
       
  2970 
       
  2971 	{		
       
  2972 		eap_variable_data_c EAP_TRACE_disable_traces(m_am_tools);
       
  2973 
       
  2974 		eap_status_e status = read_configure(
       
  2975 			cf_str_EAP_TRACE_disable_traces.get_field(),
       
  2976 			&EAP_TRACE_disable_traces);
       
  2977 		if (status == eap_status_ok
       
  2978 			&& EAP_TRACE_disable_traces.get_is_valid_data() == true)
       
  2979 		{
       
  2980 			u32_t *disable_traces = reinterpret_cast<u32_t *>(
       
  2981 				EAP_TRACE_disable_traces.get_data(sizeof(u32_t)));
       
  2982 			if (disable_traces != 0
       
  2983 				&& *disable_traces != 0)
       
  2984 			{
       
  2985 				m_am_tools->set_trace_mask(eap_am_tools_c::eap_trace_mask_none);
       
  2986 			}
       
  2987 		}
       
  2988 	}
       
  2989 
       
  2990 	//----------------------------------------------------------
       
  2991 
       
  2992 	{		
       
  2993 		eap_variable_data_c EAP_TRACE_activate_only_trace_masks_always_and_error(m_am_tools);
       
  2994 
       
  2995 		eap_status_e status = read_configure(
       
  2996 			cf_str_EAP_TRACE_activate_only_trace_masks_always_and_error.get_field(),
       
  2997 			&EAP_TRACE_activate_only_trace_masks_always_and_error);
       
  2998 		if (status == eap_status_ok
       
  2999 			&& EAP_TRACE_activate_only_trace_masks_always_and_error.get_is_valid_data() == true)
       
  3000 		{
       
  3001 			u32_t *activate_trace_mask_always = reinterpret_cast<u32_t *>(
       
  3002 				EAP_TRACE_activate_only_trace_masks_always_and_error.get_data(sizeof(u32_t)));
       
  3003 			if (activate_trace_mask_always != 0
       
  3004 				&& *activate_trace_mask_always != 0)
       
  3005 			{
       
  3006 				m_am_tools->set_trace_mask(
       
  3007 					eap_am_tools_c::eap_trace_mask_always
       
  3008 					| eap_am_tools_c::eap_trace_mask_error
       
  3009 					);
       
  3010 			}
       
  3011 		}
       
  3012 	}
       
  3013 
       
  3014 	//----------------------------------------------------------
       
  3015 
       
  3016 	{		
       
  3017 		eap_variable_data_c EAP_TRACE_activate_trace_on_error(m_am_tools);
       
  3018 
       
  3019 		eap_status_e status = read_configure(
       
  3020 			cf_str_EAP_TRACE_activate_trace_on_error.get_field(),
       
  3021 			&EAP_TRACE_activate_trace_on_error);
       
  3022 		if (status == eap_status_ok
       
  3023 			&& EAP_TRACE_activate_trace_on_error.get_is_valid_data() == true)
       
  3024 		{
       
  3025 			u32_t *activate_trace_on_error = reinterpret_cast<u32_t *>(
       
  3026 				EAP_TRACE_activate_trace_on_error.get_data(sizeof(u32_t)));
       
  3027 			if (activate_trace_on_error != 0
       
  3028 				&& *activate_trace_on_error != 0)
       
  3029 			{
       
  3030 				m_am_tools->set_activate_trace_on_error();
       
  3031 			}
       
  3032 		}
       
  3033 	}
       
  3034 
       
  3035 	//----------------------------------------------------------
       
  3036 
       
  3037 	{
       
  3038 		eap_variable_data_c EAP_TRACE_enable_timer_traces(m_am_tools);
       
  3039 
       
  3040 		status = read_configure(
       
  3041 			cf_str_EAP_TRACE_enable_timer_traces.get_field(),
       
  3042 			&EAP_TRACE_enable_timer_traces);
       
  3043 		if (status == eap_status_ok
       
  3044 			&& EAP_TRACE_enable_timer_traces.get_is_valid_data() == true)
       
  3045 		{
       
  3046 			u32_t *enable_timer_traces = reinterpret_cast<u32_t *>(
       
  3047 				EAP_TRACE_enable_timer_traces.get_data(sizeof(u32_t)));
       
  3048 			if (enable_timer_traces != 0
       
  3049 				&& *enable_timer_traces != 0)
       
  3050 			{
       
  3051 				m_am_tools->set_trace_mask(
       
  3052 					m_am_tools->get_trace_mask()
       
  3053 					| TRACE_FLAGS_TIMER
       
  3054 					);
       
  3055 			}
       
  3056 		}
       
  3057 	}
       
  3058 
       
  3059 	//----------------------------------------------------------
       
  3060 
       
  3061 	{
       
  3062 		eap_variable_data_c EAP_TRACE_enable_timer_queue_traces(m_am_tools);
       
  3063 
       
  3064 		status = read_configure(
       
  3065 			cf_str_EAP_TRACE_enable_timer_queue_traces.get_field(),
       
  3066 			&EAP_TRACE_enable_timer_queue_traces);
       
  3067 		if (status == eap_status_ok
       
  3068 			&& EAP_TRACE_enable_timer_queue_traces.get_is_valid_data() == true)
       
  3069 		{
       
  3070 			u32_t *enable_timer_queue_traces = reinterpret_cast<u32_t *>(
       
  3071 				EAP_TRACE_enable_timer_queue_traces.get_data(sizeof(u32_t)));
       
  3072 			if (enable_timer_queue_traces != 0
       
  3073 				&& *enable_timer_queue_traces != 0)
       
  3074 			{
       
  3075 				m_am_tools->set_trace_mask(
       
  3076 					m_am_tools->get_trace_mask()
       
  3077 					| TRACE_FLAGS_TIMER_QUEUE
       
  3078 					);
       
  3079 			}
       
  3080 		}
       
  3081 	}
       
  3082 
       
  3083 	//----------------------------------------------------------
       
  3084 
       
  3085 	{
       
  3086 		eap_variable_data_c EAP_TRACE_enable_ok_return_traces(m_am_tools);
       
  3087 
       
  3088 		status = read_configure(
       
  3089 			cf_str_EAP_TRACE_enable_ok_return_traces.get_field(),
       
  3090 			&EAP_TRACE_enable_ok_return_traces);
       
  3091 		if (status == eap_status_ok
       
  3092 			&& EAP_TRACE_enable_ok_return_traces.get_is_valid_data() == true)
       
  3093 		{
       
  3094 			u32_t *enable_ok_return_traces = reinterpret_cast<u32_t *>(
       
  3095 				EAP_TRACE_enable_ok_return_traces.get_data(sizeof(u32_t)));
       
  3096 			if (enable_ok_return_traces != 0
       
  3097 				&& *enable_ok_return_traces != 0)
       
  3098 			{
       
  3099 				m_am_tools->set_trace_mask(
       
  3100 					m_am_tools->get_trace_mask()
       
  3101 					| TRACE_FLAGS_OK_RETURNS
       
  3102 					);
       
  3103 			}
       
  3104 		}
       
  3105 	}
       
  3106 
       
  3107 	//----------------------------------------------------------
       
  3108 
       
  3109 	{
       
  3110 		eap_variable_data_c EAP_TRACE_enable_message_data_traces(m_am_tools);
       
  3111 
       
  3112 		status = read_configure(
       
  3113 			cf_str_EAP_TRACE_enable_message_data_traces.get_field(),
       
  3114 			&EAP_TRACE_enable_message_data_traces);
       
  3115 		if (status == eap_status_ok
       
  3116 			&& EAP_TRACE_enable_message_data_traces.get_is_valid_data() == true)
       
  3117 		{
       
  3118 			u32_t *enable_message_data_traces = reinterpret_cast<u32_t *>(
       
  3119 				EAP_TRACE_enable_message_data_traces.get_data(sizeof(u32_t)));
       
  3120 			if (enable_message_data_traces != 0
       
  3121 				&& *enable_message_data_traces != 0)
       
  3122 			{
       
  3123 				m_am_tools->set_trace_mask(
       
  3124 					m_am_tools->get_trace_mask()
       
  3125 					| EAP_TRACE_FLAGS_MESSAGE_DATA
       
  3126 					);
       
  3127 			}
       
  3128 		}
       
  3129 	}
       
  3130 
       
  3131 	//----------------------------------------------------------
       
  3132 
       
  3133 	// Create stack if it does not already exist. 
       
  3134 	status = create_upper_stack();
       
  3135 
       
  3136 	if (status != eap_status_ok)
       
  3137 	{
       
  3138 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  3139 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  3140 	}
       
  3141 
       
  3142 	// All of the configuration options are optional.
       
  3143 	// So we return OK.
       
  3144 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  3145 }
       
  3146 
       
  3147 //--------------------------------------------------
       
  3148 
       
  3149 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::read_configure(
       
  3150 	const eap_configuration_field_c * const field,
       
  3151 	eap_variable_data_c * const data)
       
  3152 {
       
  3153 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3154 
       
  3155 	EAP_TRACE_DEBUG(
       
  3156 		m_am_tools,
       
  3157 		TRACE_FLAGS_DEFAULT,
       
  3158 		(EAPL("eapol calls: eapol_wlan_authentication_c::read_configure(): %s\n"),
       
  3159 		(m_is_client == true) ? "client": "server"));
       
  3160 
       
  3161 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::read_configure()");
       
  3162 
       
  3163 	EAP_ASSERT_ALWAYS(data != 0);
       
  3164 
       
  3165 	EAP_TRACE_DEBUG(
       
  3166 		m_am_tools,
       
  3167 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3168 		(EAPL("calls: eapol_wlan_authentication_c::read_configure(): m_am_wauth->read_configure(): %s.\n"),
       
  3169 		(m_is_client == true) ? "client": "server"));
       
  3170 
       
  3171 	eap_status_e status = m_am_wauth->read_configure(field, data);
       
  3172 
       
  3173 	m_am_tools->trace_configuration(
       
  3174 		status,
       
  3175 		field,
       
  3176 		data);
       
  3177 
       
  3178 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3179 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3180 }
       
  3181 
       
  3182 //--------------------------------------------------
       
  3183 
       
  3184 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::write_configure(
       
  3185 	const eap_configuration_field_c * const field,
       
  3186 	eap_variable_data_c * const data)
       
  3187 {
       
  3188 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3189 
       
  3190 	EAP_TRACE_DEBUG(
       
  3191 		m_am_tools,
       
  3192 		TRACE_FLAGS_DEFAULT,
       
  3193 		(EAPL("eapol calls: eapol_wlan_authentication_c::write_configure(): %s\n"),
       
  3194 		(m_is_client == true) ? "client": "server"));
       
  3195 
       
  3196 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::write_configure()");
       
  3197 
       
  3198 	EAP_TRACE_DEBUG(
       
  3199 		m_am_tools,
       
  3200 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3201 		(EAPL("calls: eapol_wlan_authentication_c::write_configure(): m_am_wauth->write_configure(): %s.\n"),
       
  3202 		(m_is_client == true) ? "client": "server"));
       
  3203 
       
  3204 	eap_status_e status = m_am_wauth->write_configure(field, data);
       
  3205 
       
  3206 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3207 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3208 }
       
  3209 
       
  3210 //--------------------------------------------------
       
  3211 
       
  3212 //
       
  3213 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::set_timer(
       
  3214 	abs_eap_base_timer_c * const p_initializer, 
       
  3215 	const u32_t p_id, 
       
  3216 	void * const p_data,
       
  3217 	const u32_t p_time_ms)
       
  3218 {
       
  3219 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3220 
       
  3221 	EAP_TRACE_DEBUG(
       
  3222 		m_am_tools,
       
  3223 		TRACE_FLAGS_DEFAULT,
       
  3224 		(EAPL("eapol calls: eapol_wlan_authentication_c::set_timer(): id = %d, data = 0x%08x, time = %d\n"),
       
  3225 		p_id,
       
  3226 		p_data,
       
  3227 		p_time_ms));
       
  3228 
       
  3229 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::set_timer()");
       
  3230 
       
  3231 	const eap_status_e status = m_am_tools->am_set_timer(
       
  3232 		p_initializer, 
       
  3233 		p_id, 
       
  3234 		p_data,
       
  3235 		p_time_ms);
       
  3236 
       
  3237 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3238 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3239 }
       
  3240 
       
  3241 //--------------------------------------------------
       
  3242 
       
  3243 //
       
  3244 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::cancel_timer(
       
  3245 	abs_eap_base_timer_c * const p_initializer, 
       
  3246 	const u32_t p_id)
       
  3247 {
       
  3248 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3249 	
       
  3250 	EAP_TRACE_DEBUG(
       
  3251 		m_am_tools,
       
  3252 		TRACE_FLAGS_DEFAULT,
       
  3253 		(EAPL("eapol calls: eapol_wlan_authentication_c::cancel_timer(): initializer = 0x%08x, id = %d\n"),
       
  3254 		p_initializer,
       
  3255 		p_id));
       
  3256 
       
  3257 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::cancel_timer()");
       
  3258 
       
  3259 	const eap_status_e status = m_am_tools->am_cancel_timer(
       
  3260 		p_initializer, 
       
  3261 		p_id);
       
  3262 
       
  3263 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3264 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3265 }
       
  3266 
       
  3267 //--------------------------------------------------
       
  3268 
       
  3269 //
       
  3270 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::cancel_all_timers()
       
  3271 {
       
  3272 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3273 
       
  3274 	EAP_TRACE_DEBUG(
       
  3275 		m_am_tools,
       
  3276 		TRACE_FLAGS_DEFAULT,
       
  3277 		(EAPL("eapol calls: eapol_wlan_authentication_c::cancel_all_timers()\n")));
       
  3278 
       
  3279 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::cancel_all_timers()");
       
  3280 
       
  3281 	eap_status_e status = eap_status_ok;
       
  3282 	
       
  3283 	if (m_am_tools != 0)
       
  3284 	{
       
  3285 		WAUTH_ENTER_MUTEX(m_am_tools);
       
  3286 		status = m_am_tools->am_cancel_all_timers();
       
  3287 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
  3288 	}
       
  3289 
       
  3290 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3291 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3292 }
       
  3293 
       
  3294 //--------------------------------------------------
       
  3295 
       
  3296 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::check_is_valid_eap_type(
       
  3297 	const eap_type_value_e eap_type)
       
  3298 {
       
  3299 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3300 
       
  3301 	EAP_TRACE_DEBUG(
       
  3302 		m_am_tools,
       
  3303 		TRACE_FLAGS_DEFAULT,
       
  3304 		(EAPL("eapol calls: eapol_wlan_authentication_c::check_is_valid_eap_type()\n")));
       
  3305 
       
  3306 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::check_is_valid_eap_type()");
       
  3307 
       
  3308 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  3309 
       
  3310 	EAP_TRACE_DEBUG(
       
  3311 		m_am_tools,
       
  3312 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3313 		(EAPL("calls: eapol_wlan_authentication_c::check_is_valid_eap_type(): m_am_wauth->check_is_valid_eap_type(): %s.\n"),
       
  3314 		(m_is_client == true) ? "client": "server"));
       
  3315 
       
  3316 	eap_status_e status = m_am_wauth->check_is_valid_eap_type(eap_type);
       
  3317 	
       
  3318 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3319 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3320 }
       
  3321 
       
  3322 //--------------------------------------------------
       
  3323 
       
  3324 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::get_eap_type_list(
       
  3325 	eap_array_c<eap_type_value_e> * const eap_type_list)
       
  3326 {
       
  3327 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3328 
       
  3329 	EAP_TRACE_DEBUG(
       
  3330 		m_am_tools,
       
  3331 		TRACE_FLAGS_DEFAULT,
       
  3332 		(EAPL("eapol calls: eapol_wlan_authentication_c::get_eap_type_list()\n")));
       
  3333 
       
  3334 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::get_eap_type_list()");
       
  3335 
       
  3336 	EAP_TRACE_DEBUG(
       
  3337 		m_am_tools,
       
  3338 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3339 		(EAPL("calls: eapol_wlan_authentication_c::get_eap_type_list(): m_am_wauth->get_eap_type_list(): %s.\n"),
       
  3340 		(m_is_client == true) ? "client": "server"));
       
  3341 
       
  3342 	eap_status_e status = m_am_wauth->get_eap_type_list(eap_type_list);
       
  3343 
       
  3344 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3345 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3346 }
       
  3347 
       
  3348 //--------------------------------------------------
       
  3349 
       
  3350 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::eapol_indication(
       
  3351 	const eap_am_network_id_c * const receive_network_id, ///< source includes remote address, destination includes local address.
       
  3352 	const eapol_wlan_authentication_state_e wlan_authentication_state)
       
  3353 {
       
  3354 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3355 
       
  3356 	EAP_TRACE_DEBUG(
       
  3357 		m_am_tools,
       
  3358 		TRACE_FLAGS_DEFAULT,
       
  3359 		(EAPL("eapol calls: eapol_wlan_authentication_c::eapol_indication()\n")));
       
  3360 
       
  3361 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::eapol_indication()");
       
  3362 
       
  3363 	eap_status_e status(eap_status_ok);
       
  3364 
       
  3365 	eap_am_network_id_c send_network_id(m_am_tools);
       
  3366 
       
  3367 	if (receive_network_id != 0)
       
  3368 	{
       
  3369 		// Here we swap the addresses.
       
  3370 		eap_am_network_id_c tmp_network_id(m_am_tools,
       
  3371 			receive_network_id->get_destination_id(),
       
  3372 			receive_network_id->get_source_id(),
       
  3373 			receive_network_id->get_type());
       
  3374 
       
  3375 		status = send_network_id.set_copy_of_network_id(&tmp_network_id);
       
  3376 		if (status != eap_status_ok)
       
  3377 		{
       
  3378 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3379 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  3380 		}
       
  3381 	}
       
  3382 
       
  3383 	eap_state_notification_c notification(
       
  3384 		m_am_tools,
       
  3385 		&send_network_id,
       
  3386 		m_is_client,
       
  3387 		eap_state_notification_generic,
       
  3388 		eap_protocol_layer_wlan_authentication,
       
  3389 		eap_type_none, // EAP-type is unknown.
       
  3390 		eapol_wlan_authentication_state_none, // Previous state is unknown.
       
  3391 		wlan_authentication_state, // The current indicated state.
       
  3392 		0UL, // EAP-identifier is unknown.
       
  3393 		false // This is not applicable here.
       
  3394 		);
       
  3395 
       
  3396 	EAP_TRACE_DEBUG(
       
  3397 		m_am_tools,
       
  3398 		TRACE_FLAGS_DEFAULT,
       
  3399 		(EAPL("eapol_wlan_authentication_c::eapol_indication(): Sending state notification to Engine. state=%s=%d\n"),
       
  3400 		 notification.get_state_string( notification.get_protocol_layer() ,wlan_authentication_state ),
       
  3401 		 wlan_authentication_state));	
       
  3402 	EAP_TRACE_DATA_DEBUG(
       
  3403 		m_am_tools,
       
  3404 		TRACE_FLAGS_DEFAULT,
       
  3405 		(EAPL("    send source"),
       
  3406 		 send_network_id.get_source(),
       
  3407 		 send_network_id.get_source_length()));
       
  3408 	EAP_TRACE_DATA_DEBUG(
       
  3409 		m_am_tools,
       
  3410 		TRACE_FLAGS_DEFAULT,
       
  3411 		(EAPL("send destination"),
       
  3412 		 send_network_id.get_destination(),
       
  3413 		 send_network_id.get_destination_length()));
       
  3414 		
       
  3415 	EAP_TRACE_DEBUG(
       
  3416 		m_am_tools,
       
  3417 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3418 		(EAPL("calls partner: eapol_wlan_authentication_c::eapol_indication(): %s: m_partner->state_notification()\n"),
       
  3419 		 (m_is_client == true) ? "client": "server"));
       
  3420 	
       
  3421 	m_partner->state_notification(&notification);
       
  3422 
       
  3423 	EAP_TRACE_DEBUG(
       
  3424 		m_am_tools,
       
  3425 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3426 		(EAPL("returns from partner: eapol_wlan_authentication_c::eapol_indication(): %s: m_partner->state_notification(): status = %s\n"),
       
  3427 		 (m_is_client == true) ? "client": "server",
       
  3428 		 eap_status_string_c::get_status_string(status)));
       
  3429 
       
  3430 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3431 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3432 }
       
  3433 
       
  3434 //--------------------------------------------------
       
  3435 
       
  3436 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::create_upper_stack()
       
  3437 {
       
  3438 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3439 	
       
  3440 	EAP_TRACE_DEBUG(
       
  3441 		m_am_tools,
       
  3442 		TRACE_FLAGS_DEFAULT,
       
  3443 		(EAPL("eapol calls: eapol_wlan_authentication_c::create_upper_stack()\n")));
       
  3444 
       
  3445 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::create_upper_stack()");
       
  3446 
       
  3447 	eap_status_e status(eap_status_ok);
       
  3448 
       
  3449 	if (m_ethernet_core == 0)
       
  3450 	{        
       
  3451 		m_ethernet_core = new ethernet_core_c(m_am_tools, this, m_is_client);
       
  3452 		if (m_ethernet_core == 0
       
  3453 			|| m_ethernet_core->get_is_valid() != true)
       
  3454 		{
       
  3455 			if (m_ethernet_core != 0)
       
  3456 			{
       
  3457 				WAUTH_ENTER_MUTEX(m_am_tools);
       
  3458 				EAP_TRACE_DEBUG(
       
  3459 					m_am_tools,
       
  3460 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3461 					(EAPL("calls eapol: eapol_wlan_authentication_c::create_upper_stack(): m_ethernet_core->shutdown(): %s.\n"),
       
  3462 					(m_is_client == true) ? "client": "server"));
       
  3463 				status = m_ethernet_core->shutdown();
       
  3464 				EAP_TRACE_DEBUG(
       
  3465 					m_am_tools,
       
  3466 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3467 					(EAPL("returns from eapol: eapol_wlan_authentication_c::create_upper_stack(): m_ethernet_core->shutdown(): %s, status = %s.\n"),
       
  3468 					 (m_is_client == true) ? "client": "server",
       
  3469 					 eap_status_string_c::get_status_string(status)));
       
  3470 				WAUTH_LEAVE_MUTEX(m_am_tools);
       
  3471 
       
  3472 				delete m_ethernet_core;
       
  3473 				m_ethernet_core = 0;							
       
  3474 			}			
       
  3475 			EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Stack creation failed.\n")));			
       
  3476 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  3477 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);	
       
  3478 		}
       
  3479 
       
  3480 		// Initialise upper stack
       
  3481 		WAUTH_ENTER_MUTEX(m_am_tools);
       
  3482 		EAP_TRACE_DEBUG(
       
  3483 			m_am_tools,
       
  3484 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3485 			(EAPL("calls eapol: eapol_wlan_authentication_c::create_upper_stack(): m_ethernet_core->configure(): %s.\n"),
       
  3486 			(m_is_client == true) ? "client": "server"));
       
  3487 		status = m_ethernet_core->configure();
       
  3488 		EAP_TRACE_DEBUG(
       
  3489 			m_am_tools,
       
  3490 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3491 			(EAPL("returns from eapol: eapol_wlan_authentication_c::create_upper_stack(): m_ethernet_core->configure(): %s, status = %s.\n"),
       
  3492 			 (m_is_client == true) ? "client": "server",
       
  3493 			 eap_status_string_c::get_status_string(status)));
       
  3494 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
  3495 		
       
  3496 		if (status != eap_status_ok)
       
  3497 		{
       
  3498 			WAUTH_ENTER_MUTEX(m_am_tools);
       
  3499 			EAP_TRACE_DEBUG(
       
  3500 				m_am_tools,
       
  3501 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3502 				(EAPL("calls eapol: eapol_wlan_authentication_c::create_upper_stack(): m_ethernet_core->shutdown(): %s.\n"),
       
  3503 				(m_is_client == true) ? "client": "server"));
       
  3504 			status = m_ethernet_core->shutdown();
       
  3505 			EAP_TRACE_DEBUG(
       
  3506 				m_am_tools,
       
  3507 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3508 				(EAPL("returns from eapol: eapol_wlan_authentication_c::create_upper_stack(): m_ethernet_core->shutdown(): %s, status = %s.\n"),
       
  3509 				 (m_is_client == true) ? "client": "server",
       
  3510 				 eap_status_string_c::get_status_string(status)));
       
  3511 			WAUTH_LEAVE_MUTEX(m_am_tools);
       
  3512 
       
  3513 			delete m_ethernet_core;
       
  3514 			m_ethernet_core = 0;							
       
  3515 
       
  3516 			EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Stack creation failed.\n")));			
       
  3517 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  3518 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);	
       
  3519 		}
       
  3520 	}
       
  3521 	else
       
  3522 	{			
       
  3523 		status = eap_status_already_exists;
       
  3524 	}
       
  3525 
       
  3526 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3527 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3528 }
       
  3529 
       
  3530 //--------------------------------------------------
       
  3531 
       
  3532 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::add_rogue_ap(
       
  3533 	eap_array_c<eap_rogue_ap_entry_c> & rogue_ap_list)
       
  3534 {
       
  3535 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3536 	
       
  3537 	EAP_TRACE_DEBUG(
       
  3538 		m_am_tools,
       
  3539 		TRACE_FLAGS_DEFAULT,
       
  3540 		(EAPL("eapol calls: eapol_wlan_authentication_c::add_rogue_ap()\n")));
       
  3541 
       
  3542 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::add_rogue_ap()");
       
  3543 
       
  3544 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  3545 
       
  3546 	eap_status_e status(eap_status_ok);
       
  3547 
       
  3548 	EAP_TRACE_DEBUG(
       
  3549 		m_am_tools,
       
  3550 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3551 		(EAPL("calls partner: eapol_wlan_authentication_c::add_rogue_ap(): %s: m_partner->add_rogue_ap()\n"),
       
  3552 		 (m_is_client == true) ? "client": "server"));
       
  3553 	
       
  3554 	status = m_partner->add_rogue_ap(rogue_ap_list);
       
  3555 
       
  3556 	EAP_TRACE_DEBUG(
       
  3557 		m_am_tools,
       
  3558 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3559 		(EAPL("returns from partner: eapol_wlan_authentication_c::add_rogue_ap(): %s: m_partner->add_rogue_ap(): status = %s\n"),
       
  3560 		 (m_is_client == true) ? "client": "server",
       
  3561 		 eap_status_string_c::get_status_string(status)));
       
  3562 
       
  3563 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  3564 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3565 }
       
  3566 
       
  3567 //--------------------------------------------------
       
  3568 
       
  3569 EAP_FUNC_EXPORT u32_t eapol_wlan_authentication_c::get_current_eap_index()
       
  3570 {
       
  3571 	return m_current_eap_index;
       
  3572 }
       
  3573 
       
  3574 //--------------------------------------------------
       
  3575 
       
  3576 EAP_FUNC_EXPORT void eapol_wlan_authentication_c::set_current_eap_index(u32_t eap_index)
       
  3577 {
       
  3578 	m_current_eap_index = eap_index;
       
  3579 }
       
  3580 
       
  3581 //--------------------------------------------------
       
  3582 
       
  3583 #if defined(USE_TEST_EAPOL_WLAN_AUTHENTICATION)
       
  3584 
       
  3585 EAP_FUNC_EXPORT u32_t eapol_wlan_authentication_c::get_wrong_send_packet_index()
       
  3586 {
       
  3587 	return 0ul;
       
  3588 }
       
  3589 
       
  3590 #endif //#if defined(USE_TEST_EAPOL_WLAN_AUTHENTICATION)
       
  3591 
       
  3592 //--------------------------------------------------
       
  3593 
       
  3594 #if defined(USE_TEST_EAPOL_WLAN_AUTHENTICATION)
       
  3595 
       
  3596 EAP_FUNC_EXPORT void eapol_wlan_authentication_c::reset_authentication_can_succeed()
       
  3597 {
       
  3598 }
       
  3599 
       
  3600 #endif //#if defined(USE_TEST_EAPOL_WLAN_AUTHENTICATION)
       
  3601 
       
  3602 //--------------------------------------------------
       
  3603 
       
  3604 #if defined(USE_TEST_EAPOL_WLAN_AUTHENTICATION)
       
  3605 
       
  3606 EAP_FUNC_EXPORT void eapol_wlan_authentication_c::set_authentication_can_succeed()
       
  3607 {
       
  3608 }
       
  3609 
       
  3610 #endif //#if defined(USE_TEST_EAPOL_WLAN_AUTHENTICATION)
       
  3611 
       
  3612 //--------------------------------------------------
       
  3613 
       
  3614 #if defined(USE_TEST_EAPOL_WLAN_AUTHENTICATION)
       
  3615 
       
  3616 EAP_FUNC_EXPORT void eapol_wlan_authentication_c::restore_authentication_can_succeed()
       
  3617 {
       
  3618 }
       
  3619 
       
  3620 #endif //#if defined(USE_TEST_EAPOL_WLAN_AUTHENTICATION)
       
  3621 
       
  3622 //--------------------------------------------------
       
  3623 
       
  3624 #if defined(USE_TEST_EAPOL_WLAN_AUTHENTICATION)
       
  3625 
       
  3626 EAP_FUNC_EXPORT void eapol_wlan_authentication_c::set_authentication_must_not_succeed(
       
  3627 	const u32_t /* wrong_packet_index */,
       
  3628 	const u32_t /* packet_index */,
       
  3629 	const void * const /* wrong_packet_stack */)
       
  3630 {
       
  3631 }
       
  3632 
       
  3633 #endif //#if defined(USE_TEST_EAPOL_WLAN_AUTHENTICATION)
       
  3634 
       
  3635 //--------------------------------------------------
       
  3636 
       
  3637 //
       
  3638 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::start_WPXM_reassociation(
       
  3639 	const eap_am_network_id_c * const old_receive_network_id, ///< source includes remote address, destination includes local address.
       
  3640 	const eap_am_network_id_c * const new_receive_network_id, ///< source includes remote address, destination includes local address.
       
  3641 	eap_variable_data_c * const send_reassociation_request_ie,
       
  3642 	const eap_variable_data_c * const received_WPA_ie,
       
  3643 	const eap_variable_data_c * const sent_WPA_ie
       
  3644 	)
       
  3645 {
       
  3646 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3647 
       
  3648 	EAP_TRACE_DEBUG(
       
  3649 		m_am_tools,
       
  3650 		TRACE_FLAGS_DEFAULT,
       
  3651 		(EAPL("partner calls: eapol_wlan_authentication_c::start_WPXM_reassociation(): %s\n"),
       
  3652 		(m_is_client == true) ? "client": "server"));
       
  3653 
       
  3654 	{
       
  3655 		EAP_TRACE_DATA_DEBUG(m_am_tools,
       
  3656 			TRACE_FLAGS_DEFAULT,
       
  3657 			(EAPL("old_receive_network_id source:"),
       
  3658 			old_receive_network_id->get_source_id()->get_data(),
       
  3659 			old_receive_network_id->get_source_id()->get_data_length()));
       
  3660 
       
  3661 		EAP_TRACE_DATA_DEBUG(m_am_tools,
       
  3662 			TRACE_FLAGS_DEFAULT,
       
  3663 			(EAPL("old_receive_network_id destination:"),
       
  3664 			old_receive_network_id->get_destination_id()->get_data(),
       
  3665 			old_receive_network_id->get_destination_id()->get_data_length()));
       
  3666 
       
  3667 		EAP_TRACE_DATA_DEBUG(m_am_tools,
       
  3668 			TRACE_FLAGS_DEFAULT,
       
  3669 			(EAPL("new_receive_network_id source:"),
       
  3670 			new_receive_network_id->get_source_id()->get_data(),
       
  3671 			new_receive_network_id->get_source_id()->get_data_length()));
       
  3672 
       
  3673 		EAP_TRACE_DATA_DEBUG(m_am_tools,
       
  3674 			TRACE_FLAGS_DEFAULT,
       
  3675 			(EAPL("new_receive_network_id destination:"),
       
  3676 			new_receive_network_id->get_destination_id()->get_data(),
       
  3677 			new_receive_network_id->get_destination_id()->get_data_length()));
       
  3678 	}
       
  3679 
       
  3680 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::start_WPXM_reassociation()");
       
  3681 
       
  3682 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  3683 
       
  3684 	eap_status_e status = cancel_all_authentication_sessions();
       
  3685 	if (status != eap_status_ok)
       
  3686 	{
       
  3687 		(void) EAP_STATUS_RETURN(m_am_tools, status);
       
  3688 	}
       
  3689 
       
  3690 	eap_variable_data_c reassociation_PMKID(m_am_tools);
       
  3691 
       
  3692 	WAUTH_ENTER_MUTEX(m_am_tools);
       
  3693 	EAP_TRACE_DEBUG(
       
  3694 		m_am_tools,
       
  3695 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3696 		(EAPL("calls eapol: eapol_wlan_authentication_c::start_reassociation(): m_ethernet_core->read_reassociation_parameters(): %s.\n"),
       
  3697 		(m_is_client == true) ? "client": "server"));
       
  3698 
       
  3699 	status = m_ethernet_core->read_reassociation_parameters(
       
  3700 		old_receive_network_id,
       
  3701 		new_receive_network_id,
       
  3702 		m_authentication_type,
       
  3703 		&reassociation_PMKID,
       
  3704 		received_WPA_ie,
       
  3705 		sent_WPA_ie);
       
  3706 
       
  3707 	EAP_TRACE_DEBUG(
       
  3708 		m_am_tools,
       
  3709 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3710 		(EAPL("returns from eapol: eapol_wlan_authentication_c::start_reassociation(): m_ethernet_core->read_reassociation_parameters(): %s, status = %s.\n"),
       
  3711 		(m_is_client == true) ? "client": "server",
       
  3712 		eap_status_string_c::get_status_string(status)));
       
  3713 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
  3714 
       
  3715 	if (status == eap_status_ok)
       
  3716 	{
       
  3717 		WAUTH_ENTER_MUTEX(m_am_tools);
       
  3718 		EAP_TRACE_DEBUG(
       
  3719 			m_am_tools,
       
  3720 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3721 			(EAPL("calls eapol: eapol_wlan_authentication_c::start_WPXM_reassociation(): m_ethernet_core->start_WPXM_reassociation(): %s.\n"),
       
  3722 			(m_is_client == true) ? "client": "server"));
       
  3723 
       
  3724 		status = m_ethernet_core->start_WPXM_reassociation(
       
  3725 			new_receive_network_id,
       
  3726 			m_authentication_type,
       
  3727 			send_reassociation_request_ie);
       
  3728 
       
  3729 		EAP_TRACE_DEBUG(
       
  3730 			m_am_tools,
       
  3731 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3732 			(EAPL("returns from eapol: eapol_wlan_authentication_c::start_WPXM_reassociation(): m_ethernet_core->start_WPXM_reassociation(): %s, status = %s.\n"),
       
  3733 			 (m_is_client == true) ? "client": "server",
       
  3734 			 eap_status_string_c::get_status_string(status)));
       
  3735 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
  3736 	}
       
  3737 
       
  3738 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  3739 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3740 }
       
  3741 
       
  3742 //--------------------------------------------------
       
  3743 
       
  3744 //
       
  3745 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::complete_WPXM_reassociation(
       
  3746 	const eapol_wlan_authentication_state_e reassociation_result,
       
  3747 	const eap_am_network_id_c * const receive_network_id,
       
  3748 	const eap_variable_data_c * const received_reassociation_ie
       
  3749 	)
       
  3750 {
       
  3751 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3752 
       
  3753 	EAP_TRACE_DEBUG(
       
  3754 		m_am_tools,
       
  3755 		TRACE_FLAGS_DEFAULT,
       
  3756 		(EAPL("partner calls: eapol_wlan_authentication_c::complete_WPXM_reassociation(): %s, reassociation_result=%d\n"),
       
  3757 		(m_is_client == true) ? "client": "server",
       
  3758 		reassociation_result));
       
  3759 
       
  3760 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eapol_wlan_authentication_c::complete_WPXM_reassociation()");
       
  3761 
       
  3762 	eap_status_e status(eap_status_process_general_error);
       
  3763 
       
  3764 	if (reassociation_result != eapol_wlan_authentication_state_association_ok)
       
  3765 	{
       
  3766 		EAP_TRACE_DEBUG(
       
  3767 			m_am_tools,
       
  3768 			TRACE_FLAGS_DEFAULT,
       
  3769 			(EAPL("complete_WPXM_reassociation: Unsuccessful.\n")));
       
  3770 
       
  3771 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3772 		return EAP_STATUS_RETURN(m_am_tools, eap_status_authentication_failure);
       
  3773 	}
       
  3774 	else
       
  3775 	{
       
  3776 		EAP_TRACE_DEBUG(
       
  3777 			m_am_tools,
       
  3778 			TRACE_FLAGS_DEFAULT,
       
  3779 			(EAPL("complete_WPXM_reassociation: Successful.\n")));
       
  3780 
       
  3781 		WAUTH_ENTER_MUTEX(m_am_tools);
       
  3782 		EAP_TRACE_DEBUG(
       
  3783 			m_am_tools,
       
  3784 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3785 			(EAPL("calls eapol: eapol_wlan_authentication_c::complete_WPXM_reassociation(): m_ethernet_core->complete_WPXM_reassociation(): %s.\n"),
       
  3786 			(m_is_client == true) ? "client": "server"));
       
  3787 		status = m_ethernet_core->complete_WPXM_reassociation(
       
  3788 			reassociation_result,
       
  3789 			receive_network_id,
       
  3790 			m_authentication_type,
       
  3791 			received_reassociation_ie);
       
  3792 		EAP_TRACE_DEBUG(
       
  3793 			m_am_tools,
       
  3794 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3795 			(EAPL("returns from eapol: eapol_wlan_authentication_c::complete_WPXM_reassociation(): m_ethernet_core->complete_WPXM_reassociation(): %s, status = %s.\n"),
       
  3796 			 (m_is_client == true) ? "client": "server",
       
  3797 			 eap_status_string_c::get_status_string(status)));
       
  3798 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
  3799 
       
  3800 		if (status != eap_status_ok)
       
  3801 		{
       
  3802 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3803 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  3804 		}
       
  3805 	}
       
  3806 
       
  3807 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  3808 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3809 }
       
  3810 
       
  3811 //--------------------------------------------------
       
  3812 
       
  3813 #if defined(USE_EAP_SIMPLE_CONFIG)
       
  3814 
       
  3815 //
       
  3816 EAP_FUNC_EXPORT eap_status_e eapol_wlan_authentication_c::save_simple_config_session(
       
  3817 	const simple_config_state_e state,
       
  3818 	EAP_TEMPLATE_CONST eap_array_c<simple_config_credential_c> * const credential_array,
       
  3819 	const eap_variable_data_c * const new_password,
       
  3820 	const simple_config_Device_Password_ID_e Device_Password_ID,
       
  3821 	const simple_config_payloads_c * const other_configuration)
       
  3822 {
       
  3823 	EAP_TRACE_DEBUG(
       
  3824 		m_am_tools,
       
  3825 		TRACE_FLAGS_DEFAULT,
       
  3826 		(EAPL("eapol calls: eapol_wlan_authentication_c::save_simple_config_session(): %s\n"),
       
  3827 		(m_is_client == true ? "client": "server")));
       
  3828 
       
  3829 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eapol: eapol_wlan_authentication_c::save_simple_config_session()");
       
  3830 
       
  3831 	for (u32_t ind = 0ul; ind < credential_array->get_object_count(); ind++)
       
  3832 	{
       
  3833 		simple_config_credential_c * const credential = credential_array->get_object(ind);
       
  3834 
       
  3835 		if (credential != 0
       
  3836 			&& credential->get_is_valid() == true)
       
  3837 		{
       
  3838 			EAP_TRACE_DEBUG(
       
  3839 				m_am_tools,
       
  3840 				TRACE_FLAGS_DEFAULT,
       
  3841 				(EAPL("SIMPLE_CONFIG: network_index=%d\n"),
       
  3842 				credential->get_network_index()));
       
  3843 
       
  3844 			EAP_TRACE_DATA_DEBUG(
       
  3845 				m_am_tools, 
       
  3846 				TRACE_FLAGS_DEFAULT, 
       
  3847 				(EAPL("SIMPLE_CONFIG: SSID"),
       
  3848 				credential->get_SSID()->get_data(),
       
  3849 				credential->get_SSID()->get_data_length()));
       
  3850 
       
  3851 			EAP_TRACE_DEBUG(
       
  3852 				m_am_tools,
       
  3853 				TRACE_FLAGS_DEFAULT,
       
  3854 				(EAPL("SIMPLE_CONFIG: Authentication_Type=%d\n"),
       
  3855 				credential->get_Authentication_Type()));
       
  3856 
       
  3857 			EAP_TRACE_DEBUG(
       
  3858 				m_am_tools,
       
  3859 				TRACE_FLAGS_DEFAULT,
       
  3860 				(EAPL("SIMPLE_CONFIG: Encryption_Type=%d\n"),
       
  3861 				credential->get_Encryption_Type()));
       
  3862 
       
  3863 			for (u32_t ind = 0ul; ind < credential->get_network_keys()->get_object_count(); ++ind)
       
  3864 			{
       
  3865 				network_key_and_index_c * const key = credential->get_network_keys()->get_object(ind);
       
  3866 				if (key != 0)
       
  3867 				{
       
  3868 
       
  3869 					EAP_TRACE_DEBUG(
       
  3870 						m_am_tools,
       
  3871 						TRACE_FLAGS_DEFAULT,
       
  3872 						(EAPL("SIMPLE_CONFIG: network_key_index=%d\n"),
       
  3873 						key->get_network_key_index()));
       
  3874 
       
  3875 					EAP_TRACE_DATA_DEBUG(
       
  3876 						m_am_tools, 
       
  3877 						TRACE_FLAGS_DEFAULT, 
       
  3878 						(EAPL("SIMPLE_CONFIG: Key"),
       
  3879 						key->get_network_key()->get_data(),
       
  3880 						key->get_network_key()->get_data_length()));
       
  3881 				}
       
  3882 			}
       
  3883 
       
  3884 			EAP_TRACE_DATA_DEBUG(
       
  3885 				m_am_tools, 
       
  3886 				TRACE_FLAGS_DEFAULT, 
       
  3887 				(EAPL("SIMPLE_CONFIG: MAC_address"),
       
  3888 				credential->get_MAC_address()->get_data(),
       
  3889 				credential->get_MAC_address()->get_data_length()));
       
  3890 		}
       
  3891 	}
       
  3892 
       
  3893 	EAP_TRACE_DATA_DEBUG(
       
  3894 		m_am_tools, 
       
  3895 		TRACE_FLAGS_DEFAULT, 
       
  3896 		(EAPL("SIMPLE_CONFIG: new_password"),
       
  3897 		new_password->get_data(),
       
  3898 		new_password->get_data_length()));
       
  3899 
       
  3900 	EAP_TRACE_DEBUG(
       
  3901 		m_am_tools,
       
  3902 		TRACE_FLAGS_DEFAULT,
       
  3903 		(EAPL("SIMPLE_CONFIG: Device_Password_ID=%d\n"),
       
  3904 		Device_Password_ID));
       
  3905 
       
  3906 	EAP_TRACE_DEBUG(
       
  3907 		m_am_tools,
       
  3908 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3909 		(EAPL("calls partner: eapol_wlan_authentication_c::save_simple_config_session(): %s: m_partner->save_simple_config_session()\n"),
       
  3910 		 (m_is_client == true) ? "client": "server"));
       
  3911 	
       
  3912 	eap_status_e status = m_partner->save_simple_config_session(
       
  3913 		state,
       
  3914 		credential_array,
       
  3915 		new_password,
       
  3916 		Device_Password_ID,
       
  3917 		other_configuration);
       
  3918 
       
  3919 	EAP_TRACE_DEBUG(
       
  3920 		m_am_tools,
       
  3921 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  3922 		(EAPL("returns from partner: eapol_wlan_authentication_c::save_simple_config_session(): %s: m_partner->save_simple_config_session(): status = %s\n"),
       
  3923 		 (m_is_client == true) ? "client": "server",
       
  3924 		 eap_status_string_c::get_status_string(status)));
       
  3925 
       
  3926 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  3927 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  3928 }
       
  3929 
       
  3930 #endif // #if defined(USE_EAP_SIMPLE_CONFIG)
       
  3931 
       
  3932 //--------------------------------------------------				
       
  3933 
       
  3934 // End of file