eapol/eapol_framework/eapol_common/core/eap_core_server_message_if.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
child 55 9c2aa05919d9
equal deleted inserted replaced
45:bad0cc58d154 46:c74b3d9f6b9e
     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 * %version: 33 %
       
    20 */
       
    21 
       
    22 // This is enumeration of EAPOL source code.
       
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    24 	#undef EAP_FILE_NUMBER_ENUM
       
    25 	#define EAP_FILE_NUMBER_ENUM 48 
       
    26 	#undef EAP_FILE_NUMBER_DATE 
       
    27 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    28 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    29 
       
    30 
       
    31 
       
    32 #include "eap_am_memory.h"
       
    33 #include "eap_tools.h"
       
    34 #include "eap_core_server_message_if.h"
       
    35 #include "eap_crypto_api.h"
       
    36 #include "eap_state_notification.h"
       
    37 #include "eap_automatic_variable.h"
       
    38 #include "eap_network_id_selector.h"
       
    39 #include "eap_config.h"
       
    40 #include "eap_buffer.h"
       
    41 #include "eapol_session_key.h"
       
    42 #include "eap_master_session_key.h"
       
    43 #include "eap_am_stack.h"
       
    44 
       
    45 //--------------------------------------------------
       
    46 
       
    47 // 
       
    48 EAP_FUNC_EXPORT eap_core_server_message_if_c::~eap_core_server_message_if_c()
       
    49 {
       
    50 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    51 
       
    52 	EAP_TRACE_DEBUG(
       
    53 		m_am_tools, 
       
    54 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
    55 		(EAPL("eap_core_server_message_if_c::~eap_core_server_message_if_c(): this = 0x%08x\n"),
       
    56 		this));
       
    57 
       
    58 	EAP_ASSERT(m_shutdown_was_called == true);
       
    59 
       
    60 	delete m_eap_core;
       
    61 	delete m_am_stack;
       
    62 
       
    63 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    64 }
       
    65 
       
    66 //--------------------------------------------------
       
    67 
       
    68 #if defined(_WIN32) && !defined(__GNUC__)
       
    69 	#pragma warning( disable : 4355 ) // 'this' : used in base member initializer list
       
    70 #endif
       
    71 
       
    72 // 
       
    73 EAP_FUNC_EXPORT eap_core_server_message_if_c::eap_core_server_message_if_c(
       
    74 	abs_eap_am_tools_c * const tools,
       
    75 	const bool is_client_when_true,
       
    76 	const u32_t MTU)
       
    77 	: m_partner(0)
       
    78 	, m_eap_core(eap_session_core_base_c::new_eap_session_core_c(tools, this, is_client_when_true, MTU))
       
    79 	, m_am_stack(new_eap_am_stack_c(tools, is_client_when_true))
       
    80 	, m_am_tools(tools)
       
    81 	, m_eap_header_offset(0u)
       
    82 	, m_MTU(MTU)
       
    83 	, m_trailer_length(0u)
       
    84 	, m_error_code(eap_status_ok)
       
    85 	, m_error_function(eap_tlv_message_type_function_none)
       
    86 	, m_is_client(is_client_when_true)
       
    87 	, m_is_valid(false)
       
    88 	, m_shutdown_was_called(false)
       
    89 {
       
    90 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    91 
       
    92 	EAP_TRACE_DEBUG(
       
    93 		m_am_tools, 
       
    94 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
    95 		(EAPL("eap_core_server_message_if_c::eap_core_server_message_if_c(): %s, this = 0x%08x => 0x%08x, compiled %s %s.\n"),
       
    96 		(m_is_client == true) ? "client": "server",
       
    97 		this,
       
    98 		dynamic_cast<abs_eap_base_timer_c *>(this),
       
    99 		__DATE__,
       
   100 		__TIME__));
       
   101 
       
   102 	if (m_eap_core != 0
       
   103 		&& m_eap_core->get_is_valid() == true
       
   104 		&& m_am_stack != 0
       
   105 		&& m_am_stack->get_is_valid() == true)
       
   106 	{
       
   107 		set_is_valid();
       
   108 	}
       
   109 
       
   110 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   111 }
       
   112 
       
   113 //--------------------------------------------------
       
   114 
       
   115 //
       
   116 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::configure(
       
   117 	const eap_variable_data_c * const client_configuration)
       
   118 {
       
   119 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   120 
       
   121 	EAP_TRACE_DEBUG(
       
   122 		m_am_tools,
       
   123 		EAP_TRACE_FLAGS_MESSAGE_DATA,
       
   124 		(EAPL("%s: eap_core_server_message_if_c::configure()\n"),
       
   125 		(m_is_client == true) ? "client": "server"));
       
   126 
       
   127 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::configure()");
       
   128 
       
   129 	eap_status_e status(eap_status_process_general_error);
       
   130 
       
   131 	m_eap_header_offset = 0ul;
       
   132 	m_trailer_length = 0ul;
       
   133 
       
   134 	if (m_am_stack != 0)
       
   135 	{
       
   136 		status = m_am_stack->set_partner(
       
   137 			this
       
   138 #if defined(USE_EAP_SIMPLE_CONFIG)
       
   139 			, this
       
   140 #endif // #if defined(USE_EAP_SIMPLE_CONFIG)
       
   141 			);
       
   142 		if (status != eap_status_ok)
       
   143 		{
       
   144 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   145 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   146 		}
       
   147 
       
   148 		status = m_am_stack->configure(client_configuration);
       
   149 		if (status != eap_status_ok)
       
   150 		{
       
   151 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   152 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   153 		}
       
   154 	}
       
   155 	
       
   156 	if (m_eap_core != 0)
       
   157 	{
       
   158 		status = m_eap_core->configure();
       
   159 		if (status != eap_status_ok)
       
   160 		{
       
   161 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   162 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   163 		}
       
   164 	}
       
   165 
       
   166 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   167 }
       
   168 
       
   169 //--------------------------------------------------
       
   170 
       
   171 //
       
   172 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::shutdown()
       
   173 {
       
   174 	EAP_TRACE_DEBUG(
       
   175 		m_am_tools,
       
   176 		EAP_TRACE_FLAGS_MESSAGE_DATA,
       
   177 		(EAPL("%s: eap_core_server_message_if_c::shutdown(), m_shutdown_was_called=%d\n"),
       
   178 		(m_is_client == true) ? "client": "server",
       
   179 		m_shutdown_was_called));
       
   180 
       
   181 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::shutdown()");
       
   182 
       
   183 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   184 
       
   185 	if (m_shutdown_was_called == true)
       
   186 	{
       
   187 		// Shutdown function was called already.
       
   188 		return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   189 	}
       
   190 	m_shutdown_was_called = true;
       
   191 
       
   192 	if (m_eap_core != 0)
       
   193 	{
       
   194 		(void) m_eap_core->shutdown();
       
   195 	}
       
   196 
       
   197 	if (m_am_stack != 0)
       
   198 	{
       
   199 		(void) m_am_stack->shutdown();
       
   200 	}
       
   201 
       
   202 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   203 }
       
   204 
       
   205 //--------------------------------------------------
       
   206 
       
   207 //
       
   208 EAP_FUNC_EXPORT void eap_core_server_message_if_c::set_partner(abs_eap_am_message_if_c * const partner)
       
   209 {
       
   210 	m_partner = partner;
       
   211 }
       
   212 
       
   213 //--------------------------------------------------
       
   214 
       
   215 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::send_error_message(
       
   216 	const eap_status_e error_code,
       
   217 	const eap_tlv_message_type_function_e function)
       
   218 {
       
   219 	eap_status_e status(eap_status_ok);
       
   220 
       
   221 	{
       
   222 		// Creates message data composed of Attribute-Value Pairs.
       
   223 		eap_process_tlv_message_data_c message(m_am_tools);
       
   224 
       
   225 		if (message.get_is_valid() == false)
       
   226 		{
       
   227 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   228 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   229 		}
       
   230 
       
   231 		status = message.add_parameter_data(
       
   232 			eap_tlv_message_type_error,
       
   233 			static_cast<u32_t>(error_code));
       
   234 		if (status != eap_status_ok)
       
   235 		{
       
   236 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   237 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   238 		}
       
   239 
       
   240 		status = message.add_parameter_data(function);
       
   241 		if (status != eap_status_ok)
       
   242 		{
       
   243 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   244 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   245 		}
       
   246 
       
   247 		status = send_message(&message);
       
   248 		if (status != eap_status_ok)
       
   249 		{
       
   250 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   251 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   252 		}
       
   253 	}
       
   254 
       
   255 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   256 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   257 }
       
   258 
       
   259 //--------------------------------------------------
       
   260 
       
   261 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::send_message(eap_process_tlv_message_data_c * const message)
       
   262 {
       
   263 	// Sends message data composed of Attribute-Value Pairs.
       
   264 
       
   265 	EAP_TRACE_DEBUG(
       
   266 		m_am_tools, 
       
   267 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
   268 		(EAPL("eap_core_server_message_if_c::send_message(): this = 0x%08x => 0x%08x.\n"),
       
   269 		this,
       
   270 		dynamic_cast<abs_eap_base_timer_c *>(this)));
       
   271 
       
   272 	EAP_TRACE_DATA_DEBUG(
       
   273 		m_am_tools,
       
   274 		EAP_TRACE_FLAGS_NEVER,
       
   275 		(EAPL("eap_core_client_message_if_c::send_message()"),
       
   276 		message->get_message_data(),
       
   277 		message->get_message_data_length()));
       
   278 
       
   279 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_client_message_if_c::send_message()");
       
   280 
       
   281 
       
   282 	{
       
   283 		eap_status_e send_status = m_partner->send_data(
       
   284 			message->get_message_data(),
       
   285 			message->get_message_data_length());
       
   286 		if (send_status != eap_status_ok)
       
   287 		{
       
   288 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   289 			return EAP_STATUS_RETURN(m_am_tools, send_status);
       
   290 		}
       
   291 
       
   292 
       
   293 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   294 		return EAP_STATUS_RETURN(m_am_tools, send_status);
       
   295 	}
       
   296 
       
   297 }
       
   298 
       
   299 //--------------------------------------------------
       
   300 
       
   301 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::process_message_type_error(
       
   302 	EAP_TEMPLATE_CONST eap_array_c<eap_tlv_header_c> * const parameters)
       
   303 {
       
   304 	eap_status_e status(eap_status_ok);
       
   305 
       
   306 	eap_process_tlv_message_data_c message_data(m_am_tools);
       
   307 
       
   308 	if (message_data.get_is_valid() == false)
       
   309 	{
       
   310 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   311 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   312 	}
       
   313 
       
   314 	// Error payload is the first in this case.
       
   315 	status = message_data.read_parameter_data(parameters, eap_message_payload_index_function, eap_tlv_message_type_error, &m_error_code);
       
   316 	if (status != eap_status_ok)
       
   317 	{
       
   318 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   319 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   320 	}
       
   321 
       
   322 	// Fuction payload is the second in this case.
       
   323 	status = message_data.read_parameter_data(parameters, eap_message_payload_index_first_parameter, &m_error_function);
       
   324 	if (status != eap_status_ok)
       
   325 	{
       
   326 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   327 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   328 	}
       
   329 
       
   330 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   331 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   332 }
       
   333 
       
   334 //--------------------------------------------------
       
   335 
       
   336 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::process_message(eap_process_tlv_message_data_c * const message)
       
   337 {
       
   338 	// Parses message data composed of Attribute-Value Pairs.
       
   339 
       
   340 	EAP_TRACE_DATA_DEBUG(
       
   341 		m_am_tools,
       
   342 		EAP_TRACE_FLAGS_MESSAGE_DATA,
       
   343 		(EAPL("eap_core_server_message_if_c::process_message()"),
       
   344 		message->get_message_data(),
       
   345 		message->get_message_data_length()));
       
   346 
       
   347 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::process_message()");
       
   348 
       
   349 	eap_array_c<eap_tlv_header_c> parameters(m_am_tools);
       
   350 
       
   351 	eap_status_e status = message->parse_message_data(&parameters);
       
   352 	if (status != eap_status_ok)
       
   353 	{
       
   354 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   355 
       
   356 		(void) send_error_message(
       
   357 			status,
       
   358 			eap_tlv_message_type_function_none);
       
   359 
       
   360 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   361 	}
       
   362 
       
   363 	if (parameters.get_object_count() == 0)
       
   364 	{
       
   365 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   366 
       
   367 		status = eap_status_illegal_parameter;
       
   368 
       
   369 		(void) send_error_message(
       
   370 			status,
       
   371 			eap_tlv_message_type_function_none);
       
   372 
       
   373 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   374 	}
       
   375 
       
   376 	const eap_tlv_header_c * const function_header = parameters.get_object(eap_message_payload_index_function);
       
   377 	if (function_header == 0
       
   378 		|| (function_header->get_type() != eap_tlv_message_type_error
       
   379 			&& function_header->get_type() != eap_tlv_message_type_function))
       
   380 	{
       
   381 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   382 
       
   383 		status = eap_status_illegal_parameter;
       
   384 
       
   385 		(void) send_error_message(
       
   386 			status,
       
   387 			eap_tlv_message_type_function_none);
       
   388 
       
   389 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   390 	}
       
   391 
       
   392 	if (function_header->get_type() == eap_tlv_message_type_error)
       
   393 	{
       
   394 		status = process_message_type_error(&parameters);
       
   395 	}
       
   396 	else // function_header->get_type() == eap_tlv_message_type_function
       
   397 	{
       
   398 		eap_tlv_message_type_function_e function(eap_tlv_message_type_function_none);
       
   399 
       
   400 		status = message->get_parameter_data(function_header, &function);
       
   401 		if (status != eap_status_ok)
       
   402 		{
       
   403 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   404 
       
   405 			(void) send_error_message(
       
   406 				status,
       
   407 				eap_tlv_message_type_function_none);
       
   408 
       
   409 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   410 		}
       
   411 
       
   412 		switch(function)
       
   413 		{
       
   414 		case eap_tlv_message_type_function_create_eap_session:
       
   415 			status = create_eap_session(&parameters);
       
   416 			break;
       
   417 		case eap_tlv_message_type_function_remove_eap_session:
       
   418 			status = remove_eap_session(&parameters);
       
   419 			break;
       
   420 		case eap_tlv_message_type_function_send_eap_identity_request:
       
   421 			status = send_eap_identity_request(&parameters);
       
   422 			break;
       
   423 		case eap_tlv_message_type_function_packet_process:
       
   424 			status = packet_process(&parameters);
       
   425 			break;
       
   426 		case eap_tlv_message_type_function_eap_acknowledge:
       
   427 			status = eap_acknowledge(&parameters);
       
   428 			break;
       
   429 		case eap_tlv_message_type_function_set_eap_database_reference_values:
       
   430 			status = set_eap_database_reference_values(&parameters);
       
   431 			break;
       
   432 		case eap_tlv_message_type_function_eap_mtu:
       
   433 			status = eap_mtu(&parameters);
       
   434 			break;
       
   435 		case eap_tlv_message_type_function_get_802_11_authentication_mode:
       
   436 			status = get_802_11_authentication_mode(&parameters);
       
   437 			break;
       
   438 		default:
       
   439 			EAP_TRACE_ERROR(
       
   440 				m_am_tools,
       
   441 				TRACE_FLAGS_DEFAULT,
       
   442 				(EAPL("ERROR: process_data(): unknown function %d.\n"),
       
   443 				 function));
       
   444 
       
   445 			status = eap_status_illegal_parameter;
       
   446 
       
   447 			EAP_ASSERT_ANYWAY_TOOLS(m_am_tools);
       
   448 		};
       
   449 
       
   450 		if (status != eap_status_ok
       
   451 			&& status != eap_status_success
       
   452 			&& status != eap_status_pending_request
       
   453 			&& status != eap_status_completed_request
       
   454 			&& status != eap_status_drop_packet_quietly)
       
   455 		{
       
   456 			(void) send_error_message(
       
   457 				status,
       
   458 				function);
       
   459 		}
       
   460 	}
       
   461 
       
   462 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   463 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   464 }
       
   465 
       
   466 //--------------------------------------------------
       
   467 
       
   468 /// Function receives the data message from lower layer.
       
   469 /// Data is formatted to Attribute-Value Pairs.
       
   470 /// Look at eap_tlv_header_c and eap_tlv_message_data_c.
       
   471 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::process_data(const void * const data, const u32_t length)
       
   472 {
       
   473 	eap_status_e status(eap_status_process_general_error);
       
   474 
       
   475 	{
       
   476 		eap_process_tlv_message_data_c message(m_am_tools);
       
   477 
       
   478 		if (message.get_is_valid() == false)
       
   479 		{
       
   480 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   481 
       
   482 			status = eap_status_allocation_error;
       
   483 
       
   484 			(void) send_error_message(
       
   485 				status,
       
   486 				eap_tlv_message_type_function_none);
       
   487 
       
   488 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   489 		}
       
   490 
       
   491 		status = message.set_message_data(length, data);
       
   492 		if (status != eap_status_ok)
       
   493 		{
       
   494 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   495 
       
   496 			(void) send_error_message(
       
   497 				status,
       
   498 				eap_tlv_message_type_function_none);
       
   499 
       
   500 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   501 		}
       
   502 
       
   503 		status = process_message(&message);
       
   504 	}
       
   505 
       
   506 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   507 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   508 }
       
   509 
       
   510 //--------------------------------------------------
       
   511 
       
   512 //
       
   513 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::packet_send(
       
   514 	const eap_am_network_id_c * const send_network_id,
       
   515 	eap_buf_chain_wr_c * const sent_packet,
       
   516 	const u32_t header_offset,
       
   517 	const u32_t data_length,
       
   518 	const u32_t buffer_length)
       
   519 {
       
   520 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   521 
       
   522 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   523 	EAP_ASSERT(header_offset < sent_packet->get_data_length());
       
   524 	EAP_ASSERT(data_length <= sent_packet->get_data_length());
       
   525 	EAP_ASSERT(sent_packet->get_data_length() <= buffer_length);
       
   526 
       
   527 	eap_status_e status(eap_status_process_general_error);
       
   528 
       
   529 	if (sent_packet->get_do_length_checks() == true)
       
   530 	{
       
   531 		if (header_offset != 0ul)
       
   532 		{
       
   533 			EAP_TRACE_ERROR(
       
   534 				m_am_tools,
       
   535 				TRACE_FLAGS_DEFAULT,
       
   536 				(EAPL("ERROR: packet_send: packet buffer corrupted (header_offset != %d).\n"),
       
   537 				0ul));
       
   538 			EAP_ASSERT_ALWAYS(header_offset == 0ul);
       
   539 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   540 		}
       
   541 		else if (header_offset+data_length != sent_packet->get_data_length())
       
   542 		{
       
   543 			EAP_TRACE_ERROR(
       
   544 				m_am_tools,
       
   545 				TRACE_FLAGS_DEFAULT,
       
   546 				(EAPL("ERROR: packet_send: packet buffer corrupted ")
       
   547 				 EAPL("(data_length %d != sent_packet->get_data_length() %d).\n"),
       
   548 				 header_offset+data_length,
       
   549 				 sent_packet->get_data_length()));
       
   550 			EAP_ASSERT_ALWAYS(data_length == sent_packet->get_buffer_length());
       
   551 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   552 		}
       
   553 		else if (header_offset+data_length > buffer_length)
       
   554 		{
       
   555 			EAP_TRACE_ERROR(
       
   556 				m_am_tools,
       
   557 				TRACE_FLAGS_DEFAULT,
       
   558 				(EAPL("ERROR: packet_send: packet buffer corrupted ")
       
   559 				 EAPL("(header_offset+data_length %d > buffer_length %d).\n"),
       
   560 				 header_offset+data_length,
       
   561 				 buffer_length));
       
   562 			EAP_ASSERT_ALWAYS(header_offset+data_length <= buffer_length);
       
   563 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   564 		}
       
   565 		else if (header_offset+data_length > m_MTU)
       
   566 		{
       
   567 			EAP_TRACE_ERROR(
       
   568 				m_am_tools,
       
   569 				TRACE_FLAGS_DEFAULT,
       
   570 				(EAPL("ERROR: packet_send: packet buffer corrupted ")
       
   571 				 EAPL("(header_offset+data_length %d > m_MTU %d).\n"),
       
   572 				 header_offset+data_length,
       
   573 				 m_MTU));
       
   574 			EAP_ASSERT_ALWAYS(header_offset+data_length <= m_MTU);
       
   575 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   576 		}
       
   577 	}
       
   578 	else
       
   579 	{
       
   580 		// Always we need at least the EAP header.
       
   581 		if (sent_packet->get_data_length()
       
   582 			< eap_header_base_c::get_header_length())
       
   583 		{
       
   584 			EAP_TRACE_ERROR(
       
   585 				m_am_tools,
       
   586 				TRACE_FLAGS_DEFAULT,
       
   587 				(EAPL("ERROR: packet_send: packet buffer corrupted ")
       
   588 				 EAPL("(sent_packet->get_data_length() %d < ")
       
   589 				 EAPL("eap_header_base_c::get_header_length() %d).\n"),
       
   590 				 sent_packet->get_data_length(),
       
   591 				 eap_header_base_c::get_header_length()));
       
   592 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);
       
   593 		}
       
   594 	}
       
   595 	
       
   596 	{
       
   597 		// Creates message data composed of Attribute-Value Pairs.
       
   598 		eap_process_tlv_message_data_c message(m_am_tools);
       
   599 
       
   600 		if (message.get_is_valid() == false)
       
   601 		{
       
   602 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   603 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   604 		}
       
   605 
       
   606 		status = message.add_parameter_data(eap_tlv_message_type_function_packet_send);
       
   607 		if (status != eap_status_ok)
       
   608 		{
       
   609 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   610 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   611 		}
       
   612 
       
   613 		status = message.add_parameter_data(send_network_id);
       
   614 		if (status != eap_status_ok)
       
   615 		{
       
   616 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   617 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   618 		}
       
   619 
       
   620 		status = message.add_parameter_data(sent_packet);
       
   621 		if (status != eap_status_ok)
       
   622 		{
       
   623 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   624 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   625 		}
       
   626 
       
   627 		status = send_message(&message);
       
   628 		if (status != eap_status_ok)
       
   629 		{
       
   630 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   631 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   632 		}
       
   633 	}
       
   634 
       
   635 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   636 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   637 }
       
   638 
       
   639 //--------------------------------------------------
       
   640 
       
   641 //
       
   642 EAP_FUNC_EXPORT u32_t eap_core_server_message_if_c::get_header_offset(
       
   643 	u32_t * const MTU,
       
   644 	u32_t * const trailer_length)
       
   645 {
       
   646 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   647 
       
   648 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   649 
       
   650 	const u32_t offset = 0ul;
       
   651 
       
   652 	*MTU = m_MTU;
       
   653 	*trailer_length = m_trailer_length;
       
   654 
       
   655 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   656 	return offset;
       
   657 }
       
   658 
       
   659 //--------------------------------------------------
       
   660 
       
   661 //
       
   662 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::load_module(
       
   663 	const eap_type_value_e type,
       
   664 	const eap_type_value_e tunneling_type,
       
   665 	abs_eap_base_type_c * const partner,
       
   666 	eap_base_type_c ** const eap_type,
       
   667 	const bool is_client_when_true,
       
   668 	const eap_am_network_id_c * const receive_network_id)
       
   669 {
       
   670 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   671 
       
   672 	eap_status_e status = m_am_stack->load_module(
       
   673 		type,
       
   674 		tunneling_type,
       
   675 		partner,
       
   676 		eap_type,
       
   677 		is_client_when_true,
       
   678 		receive_network_id);
       
   679 
       
   680 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   681 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   682 }
       
   683 
       
   684 //--------------------------------------------------
       
   685 
       
   686 //
       
   687 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::unload_module(const eap_type_value_e /* type*/)
       
   688 {
       
   689 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   690 
       
   691 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   692 
       
   693 	eap_status_e status(eap_status_process_general_error);
       
   694 
       
   695 	EAP_ASSERT_ANYWAY_TOOLS(m_am_tools);
       
   696 
       
   697 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   698 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   699 }
       
   700 
       
   701 //--------------------------------------------------
       
   702 
       
   703 //
       
   704 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::packet_data_crypto_keys(
       
   705 	const eap_am_network_id_c * const send_network_id,
       
   706 	const eap_master_session_key_c * const master_session_key
       
   707 	)
       
   708 {
       
   709 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   710 
       
   711 	EAP_TRACE_DEBUG(
       
   712 		m_am_tools,
       
   713 		EAP_TRACE_FLAGS_MESSAGE_DATA,
       
   714 		(EAPL("%s: eap_core_server_message_if_c::packet_data_crypto_keys()\n"),
       
   715 		(m_is_client == true) ? "client": "server"));
       
   716 
       
   717 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::packet_data_crypto_keys()");
       
   718 
       
   719 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   720 
       
   721 	eap_status_e status(eap_status_process_general_error);
       
   722 
       
   723 	if (master_session_key == 0
       
   724 		|| master_session_key->get_is_valid() == false)
       
   725 	{
       
   726 		EAP_TRACE_DEBUG(
       
   727 			m_am_tools,
       
   728 			TRACE_FLAGS_DEFAULT,
       
   729 			(EAPL("ERROR: eap_core_server_message_if_c::packet_data_crypto_keys(), invalid key.\n")));
       
   730 		return EAP_STATUS_RETURN(m_am_tools, eap_status_key_error);
       
   731 	}
       
   732 	
       
   733 	EAP_TRACE_DATA_DEBUG(
       
   734 		m_am_tools,
       
   735 		EAP_TRACE_FLAGS_MESSAGE_DATA,
       
   736 		(EAPL("eap_core_server_message_if_c::packet_data_crypto_keys(): master_session_key"), 
       
   737 		 master_session_key->get_data(),
       
   738 		 master_session_key->get_data_length()));
       
   739 	
       
   740 	{
       
   741 		// Creates message data composed of Attribute-Value Pairs.
       
   742 		eap_process_tlv_message_data_c message(m_am_tools);
       
   743 
       
   744 		if (message.get_is_valid() == false)
       
   745 		{
       
   746 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   747 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   748 		}
       
   749 
       
   750 		status = message.add_parameter_data(eap_tlv_message_type_function_packet_data_crypto_keys);
       
   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 = message.add_parameter_data(send_network_id);
       
   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 		// This adds only the EAP-type.
       
   765 		status = message.add_parameter_data(master_session_key->get_eap_type());
       
   766 		if (status != eap_status_ok)
       
   767 		{
       
   768 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   769 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   770 		}
       
   771 
       
   772 		// This adds only the eap_variable_data.
       
   773 		status = message.add_parameter_data(master_session_key);
       
   774 		if (status != eap_status_ok)
       
   775 		{
       
   776 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   777 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   778 		}
       
   779 
       
   780 		status = send_message(&message);
       
   781 		if (status != eap_status_ok)
       
   782 		{
       
   783 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   784 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   785 		}
       
   786 	}
       
   787 
       
   788 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   789 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   790 }
       
   791 
       
   792 //--------------------------------------------------
       
   793 
       
   794 //
       
   795 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::complete_get_802_11_authentication_mode(
       
   796 	const eap_status_e completion_status,
       
   797 	const eap_am_network_id_c * const receive_network_id,
       
   798 	const eapol_key_802_11_authentication_mode_e mode)
       
   799 {
       
   800 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   801 
       
   802 	EAP_TRACE_DEBUG(
       
   803 		m_am_tools,
       
   804 		EAP_TRACE_FLAGS_MESSAGE_DATA,
       
   805 		(EAPL("%s: eap_core_server_message_if_c::complete_get_802_11_authentication_mode()\n"),
       
   806 		(m_is_client == true) ? "client": "server"));
       
   807 
       
   808 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::complete_get_802_11_authentication_mode()");
       
   809 
       
   810 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   811 
       
   812 	eap_status_e status(eap_status_process_general_error);
       
   813 
       
   814 	{
       
   815 		// Creates message data composed of Attribute-Value Pairs.
       
   816 		eap_process_tlv_message_data_c message(m_am_tools);
       
   817 
       
   818 		if (message.get_is_valid() == false)
       
   819 		{
       
   820 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   821 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   822 		}
       
   823 
       
   824 		status = message.add_parameter_data(eap_tlv_message_type_function_complete_get_802_11_authentication_mode);
       
   825 		if (status != eap_status_ok)
       
   826 		{
       
   827 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   828 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   829 		}
       
   830 
       
   831 		status = message.add_parameter_data(completion_status);
       
   832 		if (status != eap_status_ok)
       
   833 		{
       
   834 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   835 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   836 		}
       
   837 
       
   838 		status = message.add_parameter_data(receive_network_id);
       
   839 		if (status != eap_status_ok)
       
   840 		{
       
   841 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   842 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   843 		}
       
   844 
       
   845 		status = message.add_parameter_data(mode);
       
   846 		if (status != eap_status_ok)
       
   847 		{
       
   848 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   849 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   850 		}
       
   851 
       
   852 		status = send_message(&message);
       
   853 		if (status != eap_status_ok)
       
   854 		{
       
   855 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   856 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   857 		}
       
   858 	}
       
   859 
       
   860 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   861 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   862 }
       
   863 
       
   864 //--------------------------------------------------
       
   865 
       
   866 //
       
   867 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::complete_remove_eap_session(
       
   868 	const bool complete_to_lower_layer,
       
   869 	const eap_am_network_id_c * const receive_network_id)
       
   870 {
       
   871 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   872 
       
   873 	EAP_TRACE_DEBUG(
       
   874 		m_am_tools,
       
   875 		EAP_TRACE_FLAGS_MESSAGE_DATA,
       
   876 		(EAPL("%s: eap_core_server_message_if_c::complete_remove_eap_session(): complete_to_lower_layer=%s\n"),
       
   877 		(m_is_client == true) ? "client": "server",
       
   878 		(complete_to_lower_layer == true) ? "true": "false"));
       
   879 
       
   880 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::complete_remove_eap_session()");
       
   881 
       
   882 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   883 
       
   884 	eap_status_e status(eap_status_process_general_error);
       
   885 
       
   886 	{
       
   887 		// Creates message data composed of Attribute-Value Pairs.
       
   888 		eap_process_tlv_message_data_c message(m_am_tools);
       
   889 
       
   890 		if (message.get_is_valid() == false)
       
   891 		{
       
   892 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   893 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   894 		}
       
   895 
       
   896 		status = message.add_parameter_data(eap_tlv_message_type_function_complete_remove_eap_session);
       
   897 		if (status != eap_status_ok)
       
   898 		{
       
   899 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   900 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   901 		}
       
   902 
       
   903 		status = message.add_parameter_data(complete_to_lower_layer);
       
   904 		if (status != eap_status_ok)
       
   905 		{
       
   906 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   907 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   908 		}
       
   909 
       
   910 		status = message.add_parameter_data(receive_network_id);
       
   911 		if (status != eap_status_ok)
       
   912 		{
       
   913 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   914 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   915 		}
       
   916 
       
   917 		status = send_message(&message);
       
   918 		if (status != eap_status_ok)
       
   919 		{
       
   920 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   921 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   922 		}
       
   923 	}
       
   924 
       
   925 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   926 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   927 }
       
   928 
       
   929 //--------------------------------------------------
       
   930 
       
   931 //
       
   932 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::read_configure(
       
   933 	const eap_configuration_field_c * const field,
       
   934 	eap_variable_data_c * const data)
       
   935 {
       
   936 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   937 
       
   938 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   939 
       
   940 	eap_status_e status = m_am_stack->read_configure(
       
   941 		field,
       
   942 		data);
       
   943 
       
   944 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   945 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   946 }
       
   947 
       
   948 //--------------------------------------------------
       
   949 
       
   950 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::write_configure(
       
   951 	const eap_configuration_field_c * const /* field */,
       
   952 	eap_variable_data_c * const /* data */)
       
   953 {
       
   954 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   955 
       
   956 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   957 
       
   958 	eap_status_e status(eap_status_process_general_error);
       
   959 
       
   960 	EAP_ASSERT_ANYWAY_TOOLS(m_am_tools);
       
   961 
       
   962 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   963 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   964 }
       
   965 
       
   966 //--------------------------------------------------
       
   967 
       
   968 //
       
   969 EAP_FUNC_EXPORT void eap_core_server_message_if_c::set_is_valid()
       
   970 {
       
   971 	m_is_valid = true;
       
   972 }
       
   973 
       
   974 //--------------------------------------------------
       
   975 
       
   976 //
       
   977 EAP_FUNC_EXPORT bool eap_core_server_message_if_c::get_is_valid()
       
   978 {
       
   979 	return m_is_valid;
       
   980 }
       
   981 
       
   982 //--------------------------------------------------
       
   983 
       
   984 //
       
   985 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::timer_expired(
       
   986 	const u32_t id, void *data)
       
   987 {
       
   988 	EAP_UNREFERENCED_PARAMETER(id);
       
   989 	EAP_UNREFERENCED_PARAMETER(data);
       
   990 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   991 
       
   992 	EAP_TRACE_DEBUG(
       
   993 		m_am_tools,
       
   994 		EAP_TRACE_FLAGS_MESSAGE_DATA,
       
   995 		(EAPL("TIMER: %s: [0x%08x]->eap_core_server_message_if_c::timer_expired(id 0x%02x, data 0x%08x).\n"),
       
   996 		 (m_is_client == true) ? "client": "server",
       
   997 		 this,
       
   998 		 id,
       
   999 		 data));
       
  1000 
       
  1001 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::timer_expired()");
       
  1002 
       
  1003 
       
  1004 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  1005 }
       
  1006 
       
  1007 //--------------------------------------------------
       
  1008 
       
  1009 //
       
  1010 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::timer_delete_data(
       
  1011 	const u32_t id, void *data)
       
  1012 {
       
  1013 	EAP_UNREFERENCED_PARAMETER(id);
       
  1014 	EAP_UNREFERENCED_PARAMETER(data);
       
  1015 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1016 
       
  1017 	EAP_TRACE_DEBUG(
       
  1018 		m_am_tools,
       
  1019 		EAP_TRACE_FLAGS_MESSAGE_DATA,
       
  1020 		(EAPL("TIMER: %s: [0x%08x]->eap_core_server_message_if_c::timer_delete_data(id 0x%02x, data 0x%08x).\n"),
       
  1021 		(m_is_client == true) ? "client": "server",
       
  1022 		this, id, data));
       
  1023 
       
  1024 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::timer_delete_data()");
       
  1025 
       
  1026 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  1027 }
       
  1028 
       
  1029 //--------------------------------------------------
       
  1030 
       
  1031 EAP_FUNC_EXPORT void eap_core_server_message_if_c::state_notification(
       
  1032 	const abs_eap_state_notification_c * const state)
       
  1033 {
       
  1034 	eap_status_e status(eap_status_process_general_error);
       
  1035 
       
  1036 	EAP_TRACE_DEBUG(
       
  1037 		m_am_tools, 
       
  1038 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1039 		(EAPL("%s: eap_core_server_message_if_c::state_notification()\n"),
       
  1040 		 (m_is_client == true) ? "client": "server"));
       
  1041 
       
  1042 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::state_notification()");
       
  1043 
       
  1044 	{
       
  1045 		// Creates message data composed of Attribute-Value Pairs.
       
  1046 		eap_process_tlv_message_data_c message(m_am_tools);
       
  1047 
       
  1048 		if (message.get_is_valid() == false)
       
  1049 		{
       
  1050 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1051 			(void)EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1052 			return;
       
  1053 		}
       
  1054 
       
  1055 		status = message.add_parameter_data(eap_tlv_message_type_function_state_notification);
       
  1056 		if (status != eap_status_ok)
       
  1057 		{
       
  1058 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1059 			(void)EAP_STATUS_RETURN(m_am_tools, status);
       
  1060 			return;
       
  1061 		}
       
  1062 
       
  1063 		status = message.add_parameter_data(state);
       
  1064 		if (status != eap_status_ok)
       
  1065 		{
       
  1066 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1067 			(void)EAP_STATUS_RETURN(m_am_tools, status);
       
  1068 			return;
       
  1069 		}
       
  1070 
       
  1071 		status = send_message(&message);
       
  1072 		if (status != eap_status_ok)
       
  1073 		{
       
  1074 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1075 			(void)EAP_STATUS_RETURN(m_am_tools, status);
       
  1076 			return;
       
  1077 		}
       
  1078 	}
       
  1079 }
       
  1080 
       
  1081 //--------------------------------------------------
       
  1082 
       
  1083 //
       
  1084 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::asynchronous_init_remove_eap_session(
       
  1085 	const eap_am_network_id_c * const /* send_network_id */)
       
  1086 {
       
  1087 	// eap_core_server_message_if_c object does not support asynchronous_init_remove_eap_session().
       
  1088 	return EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported);
       
  1089 }
       
  1090 
       
  1091 //--------------------------------------------------
       
  1092 
       
  1093 //
       
  1094 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::asynchronous_start_authentication(
       
  1095 	const eap_am_network_id_c * const /* receive_network_id */,
       
  1096 	const bool /* is_client_when_true */)
       
  1097 {
       
  1098 	return EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported);
       
  1099 }
       
  1100 
       
  1101 //--------------------------------------------------
       
  1102 
       
  1103 //
       
  1104 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::restart_authentication(
       
  1105 	const eap_am_network_id_c * const send_network_id,
       
  1106 	const bool is_client_when_true,
       
  1107 	const bool force_clean_restart,
       
  1108 	const bool from_timer)
       
  1109 {
       
  1110 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1111 
       
  1112 	EAP_TRACE_DEBUG(
       
  1113 		m_am_tools,
       
  1114 		EAP_TRACE_FLAGS_MESSAGE_DATA,
       
  1115 		(EAPL("%s: eap_core_server_message_if_c::restart_authentication()\n"),
       
  1116 		(m_is_client == true) ? "client": "server"));
       
  1117 
       
  1118 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::restart_authentication()");
       
  1119 
       
  1120 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1121 
       
  1122 	eap_status_e status(eap_status_process_general_error);
       
  1123 
       
  1124 	{
       
  1125 		// Creates message data composed of Attribute-Value Pairs.
       
  1126 		eap_process_tlv_message_data_c message(m_am_tools);
       
  1127 
       
  1128 		if (message.get_is_valid() == false)
       
  1129 		{
       
  1130 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1131 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1132 		}
       
  1133 
       
  1134 		status = message.add_parameter_data(eap_tlv_message_type_function_restart_authentication);
       
  1135 		if (status != eap_status_ok)
       
  1136 		{
       
  1137 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1138 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1139 		}
       
  1140 
       
  1141 		status = message.add_parameter_data(send_network_id);
       
  1142 		if (status != eap_status_ok)
       
  1143 		{
       
  1144 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1145 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1146 		}
       
  1147 
       
  1148 		status = message.add_parameter_data(is_client_when_true);
       
  1149 		if (status != eap_status_ok)
       
  1150 		{
       
  1151 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1152 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1153 		}
       
  1154 
       
  1155 		status = message.add_parameter_data(force_clean_restart);
       
  1156 		if (status != eap_status_ok)
       
  1157 		{
       
  1158 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1159 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1160 		}
       
  1161 
       
  1162 		status = message.add_parameter_data(from_timer);
       
  1163 		if (status != eap_status_ok)
       
  1164 		{
       
  1165 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1166 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1167 		}
       
  1168 
       
  1169 		status = send_message(&message);
       
  1170 		if (status != eap_status_ok)
       
  1171 		{
       
  1172 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1173 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1174 		}
       
  1175 	}
       
  1176 
       
  1177 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1178 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1179 }
       
  1180 
       
  1181 //--------------------------------------------------
       
  1182 
       
  1183 //
       
  1184 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::set_timer(
       
  1185 	abs_eap_base_timer_c * const p_initializer, 
       
  1186 	const u32_t p_id, 
       
  1187 	void * const p_data,
       
  1188 	const u32_t p_time_ms)
       
  1189 {
       
  1190 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1191 
       
  1192 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1193 
       
  1194 	eap_status_e status = m_am_stack->set_timer(
       
  1195 		p_initializer, 
       
  1196 		p_id, 
       
  1197 		p_data,
       
  1198 		p_time_ms);
       
  1199 
       
  1200 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1201 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1202 }
       
  1203 
       
  1204 //--------------------------------------------------
       
  1205 
       
  1206 //
       
  1207 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::cancel_timer(
       
  1208 	abs_eap_base_timer_c * const p_initializer, 
       
  1209 	const u32_t p_id)
       
  1210 {
       
  1211 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1212 
       
  1213 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1214 
       
  1215 	eap_status_e status(eap_status_ok);
       
  1216 
       
  1217 	if (m_am_stack != 0)
       
  1218 	{
       
  1219 		status = m_am_stack->cancel_timer(
       
  1220 			p_initializer, 
       
  1221 			p_id);
       
  1222 	}
       
  1223 
       
  1224 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1225 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1226 }
       
  1227 
       
  1228 //--------------------------------------------------
       
  1229 
       
  1230 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::check_is_valid_eap_type(
       
  1231 	const eap_type_value_e eap_type)
       
  1232 {
       
  1233 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1234 
       
  1235 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1236 
       
  1237 	eap_status_e status = m_am_stack->check_is_valid_eap_type(eap_type);
       
  1238 
       
  1239 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1240 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1241 }
       
  1242 
       
  1243 //--------------------------------------------------
       
  1244 
       
  1245 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::get_eap_type_list(
       
  1246 	eap_array_c<eap_type_value_e> * const eap_type_list)
       
  1247 {
       
  1248 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1249 
       
  1250 	eap_status_e status = m_am_stack->get_eap_type_list(eap_type_list);
       
  1251 
       
  1252 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1253 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1254 }
       
  1255 
       
  1256 //--------------------------------------------------
       
  1257 
       
  1258 /// @see abs_eap_core_c::add_rogue_ap().
       
  1259 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::add_rogue_ap(
       
  1260 	eap_array_c<eap_rogue_ap_entry_c> & /* rogue_ap_list */)
       
  1261 {
       
  1262 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1263 
       
  1264 	EAP_TRACE_DEBUG(
       
  1265 		m_am_tools, 
       
  1266 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1267 		(EAPL("%s: eap_core_server_message_if_c::add_rogue_ap(): Does nothing.\n"),
       
  1268 		 (m_is_client == true) ? "client": "server"));
       
  1269 
       
  1270 	eap_status_e status(eap_status_ok);
       
  1271 
       
  1272 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1273 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1274 }
       
  1275 
       
  1276 //--------------------------------------------------
       
  1277 
       
  1278 //
       
  1279 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::set_session_timeout(
       
  1280 	const u32_t /* session_timeout_ms */)
       
  1281 {
       
  1282 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1283 
       
  1284 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
  1285 
       
  1286 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1287 	return EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported);
       
  1288 }
       
  1289 
       
  1290 //--------------------------------------------------
       
  1291 
       
  1292 eap_status_e eap_core_server_message_if_c::create_eap_session(
       
  1293 	EAP_TEMPLATE_CONST eap_array_c<eap_tlv_header_c> * const parameters)
       
  1294 {
       
  1295 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1296 
       
  1297 	EAP_TRACE_DEBUG(
       
  1298 		m_am_tools, 
       
  1299 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1300 		(EAPL("%s: eap_core_server_message_if_c::create_eap_session()\n"),
       
  1301 		 (m_is_client == true) ? "client": "server"));
       
  1302 
       
  1303 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::create_eap_session()");
       
  1304 
       
  1305 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1306 
       
  1307 	eap_status_e status(eap_status_ok);
       
  1308 
       
  1309 	u32_t parameter_index(eap_message_payload_index_first_parameter);
       
  1310 
       
  1311 	eap_process_tlv_message_data_c message_data(m_am_tools);
       
  1312 
       
  1313 	if (message_data.get_is_valid() == false)
       
  1314 	{
       
  1315 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1316 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1317 	}
       
  1318 
       
  1319 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1320 
       
  1321 	eap_am_network_id_c receive_network_id(m_am_tools);
       
  1322 
       
  1323 	status = message_data.read_parameter_data(parameters, parameter_index, &receive_network_id);
       
  1324 	if (status != eap_status_ok)
       
  1325 	{
       
  1326 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1327 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1328 	}
       
  1329 
       
  1330 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1331 
       
  1332 	status = m_eap_core->create_eap_session(
       
  1333 		&receive_network_id ///< source includes remote address, destination includes local address.
       
  1334 		);
       
  1335 
       
  1336 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1337 
       
  1338 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1339 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1340 }
       
  1341 
       
  1342 //--------------------------------------------------
       
  1343 
       
  1344 eap_status_e eap_core_server_message_if_c::remove_eap_session(
       
  1345 	EAP_TEMPLATE_CONST eap_array_c<eap_tlv_header_c> * const parameters)
       
  1346 {
       
  1347 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1348 
       
  1349 	EAP_TRACE_DEBUG(
       
  1350 		m_am_tools, 
       
  1351 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1352 		(EAPL("%s: eap_core_server_message_if_c::remove_eap_session()\n"),
       
  1353 		 (m_is_client == true) ? "client": "server"));
       
  1354 
       
  1355 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::remove_eap_session()");
       
  1356 
       
  1357 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1358 
       
  1359 	eap_status_e status(eap_status_ok);
       
  1360 
       
  1361 	u32_t parameter_index(eap_message_payload_index_first_parameter);
       
  1362 
       
  1363 	eap_process_tlv_message_data_c message_data(m_am_tools);
       
  1364 
       
  1365 	if (message_data.get_is_valid() == false)
       
  1366 	{
       
  1367 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1368 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1369 	}
       
  1370 
       
  1371 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1372 
       
  1373 	bool complete_to_lower_layer(false);
       
  1374 
       
  1375 	status = message_data.read_parameter_data(parameters, parameter_index, &complete_to_lower_layer);
       
  1376 	if (status != eap_status_ok)
       
  1377 	{
       
  1378 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1379 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1380 	}
       
  1381 
       
  1382 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1383 
       
  1384 	++parameter_index;
       
  1385 
       
  1386 	eap_am_network_id_c receive_network_id(m_am_tools);
       
  1387 
       
  1388 	status = message_data.read_parameter_data(parameters, parameter_index, &receive_network_id);
       
  1389 	if (status != eap_status_ok)
       
  1390 	{
       
  1391 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1392 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1393 	}
       
  1394 
       
  1395 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1396 
       
  1397 	status = m_eap_core->remove_eap_session(
       
  1398 		complete_to_lower_layer,
       
  1399 		&receive_network_id ///< source includes remote address, destination includes local address.
       
  1400 		);
       
  1401 
       
  1402 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1403 
       
  1404 	// This is a new function to synchronize EAP-client and EAP-server.
       
  1405 	eap_status_e completion_status = complete_remove_eap_session(
       
  1406 		complete_to_lower_layer,
       
  1407 		&receive_network_id ///< source includes remote address, destination includes local address.
       
  1408 		);
       
  1409 
       
  1410 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1411 
       
  1412 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1413 	return EAP_STATUS_RETURN(m_am_tools, completion_status);
       
  1414 }
       
  1415 
       
  1416 //--------------------------------------------------
       
  1417 
       
  1418 eap_status_e eap_core_server_message_if_c::send_eap_identity_request(
       
  1419 	EAP_TEMPLATE_CONST eap_array_c<eap_tlv_header_c> * const parameters)
       
  1420 {
       
  1421 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1422 
       
  1423 	EAP_TRACE_DEBUG(
       
  1424 		m_am_tools, 
       
  1425 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1426 		(EAPL("%s: eap_core_server_message_if_c::send_eap_identity_request()\n"),
       
  1427 		 (m_is_client == true) ? "client": "server"));
       
  1428 
       
  1429 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::send_eap_identity_request()");
       
  1430 
       
  1431 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1432 
       
  1433 	eap_status_e status(eap_status_ok);
       
  1434 
       
  1435 	u32_t parameter_index(eap_message_payload_index_first_parameter);
       
  1436 
       
  1437 	eap_process_tlv_message_data_c message_data(m_am_tools);
       
  1438 
       
  1439 	if (message_data.get_is_valid() == false)
       
  1440 	{
       
  1441 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1442 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1443 	}
       
  1444 
       
  1445 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1446 
       
  1447 	eap_am_network_id_c receive_network_id(m_am_tools);
       
  1448 
       
  1449 	status = message_data.read_parameter_data(parameters, parameter_index, &receive_network_id);
       
  1450 	if (status != eap_status_ok)
       
  1451 	{
       
  1452 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1453 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1454 	}
       
  1455 
       
  1456 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1457 
       
  1458 	status = m_eap_core->send_eap_identity_request(
       
  1459 		&receive_network_id ///< source includes remote address, destination includes local address.
       
  1460 		);
       
  1461 
       
  1462 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1463 
       
  1464 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1465 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1466 }
       
  1467 
       
  1468 //--------------------------------------------------
       
  1469 
       
  1470 eap_status_e eap_core_server_message_if_c::packet_process(
       
  1471 	EAP_TEMPLATE_CONST eap_array_c<eap_tlv_header_c> * const parameters)
       
  1472 {
       
  1473 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1474 
       
  1475 	EAP_TRACE_DEBUG(
       
  1476 		m_am_tools, 
       
  1477 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1478 		(EAPL("%s: eap_core_server_message_if_c::packet_process()\n"),
       
  1479 		 (m_is_client == true) ? "client": "server"));
       
  1480 
       
  1481 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::packet_process()");
       
  1482 
       
  1483 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1484 
       
  1485 	eap_status_e status(eap_status_ok);
       
  1486 
       
  1487 	u32_t parameter_index(eap_message_payload_index_first_parameter);
       
  1488 
       
  1489 	eap_process_tlv_message_data_c message_data(m_am_tools);
       
  1490 
       
  1491 	if (message_data.get_is_valid() == false)
       
  1492 	{
       
  1493 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1494 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1495 	}
       
  1496 
       
  1497 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1498 
       
  1499 	eap_am_network_id_c receive_network_id(m_am_tools);
       
  1500 
       
  1501 	status = message_data.read_parameter_data(parameters, parameter_index, &receive_network_id);
       
  1502 	if (status != eap_status_ok)
       
  1503 	{
       
  1504 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1505 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1506 	}
       
  1507 
       
  1508 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1509 
       
  1510 	++parameter_index;
       
  1511 
       
  1512 	eap_variable_data_c packet_data_payload(m_am_tools);
       
  1513 
       
  1514 	status = message_data.read_parameter_data(parameters, parameter_index, &packet_data_payload);
       
  1515 	if (status != eap_status_ok)
       
  1516 	{
       
  1517 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1518 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1519 	}
       
  1520 
       
  1521 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1522 
       
  1523 	eap_header_wr_c eap(
       
  1524 		m_am_tools,
       
  1525 		packet_data_payload.get_data(),
       
  1526 		packet_data_payload.get_data_length());
       
  1527 	if (eap.get_is_valid() == false)
       
  1528 	{
       
  1529 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1530 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1531 	}
       
  1532 
       
  1533 	status = m_eap_core->packet_process(
       
  1534 		&receive_network_id,
       
  1535 		&eap,
       
  1536 		packet_data_payload.get_data_length()
       
  1537 		);
       
  1538 
       
  1539 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1540 
       
  1541 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1542 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1543 }
       
  1544 
       
  1545 //--------------------------------------------------
       
  1546 
       
  1547 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::eap_acknowledge(
       
  1548 	EAP_TEMPLATE_CONST eap_array_c<eap_tlv_header_c> * const parameters)
       
  1549 {
       
  1550 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1551 
       
  1552 	EAP_TRACE_DEBUG(
       
  1553 		m_am_tools, 
       
  1554 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1555 		(EAPL("%s: eap_core_server_message_if_c::eap_acknowledge()\n"),
       
  1556 		 (m_is_client == true) ? "client": "server"));
       
  1557 
       
  1558 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::eap_acknowledge()");
       
  1559 
       
  1560 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1561 
       
  1562 	eap_status_e status(eap_status_ok);
       
  1563 
       
  1564 	u32_t parameter_index(eap_message_payload_index_first_parameter);
       
  1565 
       
  1566 	eap_process_tlv_message_data_c message_data(m_am_tools);
       
  1567 
       
  1568 	if (message_data.get_is_valid() == false)
       
  1569 	{
       
  1570 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1571 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1572 	}
       
  1573 
       
  1574 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1575 
       
  1576 	eap_am_network_id_c receive_network_id(m_am_tools);
       
  1577 
       
  1578 	status = message_data.read_parameter_data(parameters, parameter_index, &receive_network_id);
       
  1579 	if (status != eap_status_ok)
       
  1580 	{
       
  1581 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1582 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1583 	}
       
  1584 
       
  1585 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1586 
       
  1587 	status = m_eap_core->eap_acknowledge(
       
  1588 		&receive_network_id ///< source includes remote address, destination includes local address.
       
  1589 		);
       
  1590 
       
  1591 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1592 
       
  1593 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1594 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1595 }
       
  1596 
       
  1597 //--------------------------------------------------
       
  1598 
       
  1599 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::eap_mtu(
       
  1600 	EAP_TEMPLATE_CONST eap_array_c<eap_tlv_header_c> * const parameters)
       
  1601 {
       
  1602 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1603 
       
  1604 	EAP_TRACE_DEBUG(
       
  1605 		m_am_tools, 
       
  1606 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1607 		(EAPL("%s: eap_core_server_message_if_c::eap_mtu()\n"),
       
  1608 		 (m_is_client == true) ? "client": "server"));
       
  1609 
       
  1610 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::eap_mtu()");
       
  1611 
       
  1612 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1613 
       
  1614 	eap_status_e status(eap_status_ok);
       
  1615 
       
  1616 	u32_t parameter_index(eap_message_payload_index_first_parameter);
       
  1617 
       
  1618 	eap_process_tlv_message_data_c message_data(m_am_tools);
       
  1619 
       
  1620 	if (message_data.get_is_valid() == false)
       
  1621 	{
       
  1622 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1623 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1624 	}
       
  1625 
       
  1626 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1627 
       
  1628 	status = message_data.read_parameter_data(parameters, parameter_index, &m_MTU);
       
  1629 	if (status != eap_status_ok)
       
  1630 	{
       
  1631 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1632 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1633 	}
       
  1634 
       
  1635 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1636 
       
  1637 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1638 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1639 }
       
  1640 
       
  1641 //--------------------------------------------------
       
  1642 
       
  1643 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::get_802_11_authentication_mode(
       
  1644 	EAP_TEMPLATE_CONST eap_array_c<eap_tlv_header_c> * const parameters)
       
  1645 {
       
  1646 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1647 
       
  1648 	EAP_TRACE_DEBUG(
       
  1649 		m_am_tools, 
       
  1650 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1651 		(EAPL("%s: eap_core_server_message_if_c::get_802_11_authentication_mode()\n"),
       
  1652 		 (m_is_client == true) ? "client": "server"));
       
  1653 
       
  1654 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::get_802_11_authentication_mode()");
       
  1655 
       
  1656 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1657 
       
  1658 	eap_status_e status(eap_status_ok);
       
  1659 
       
  1660 	u32_t parameter_index(eap_message_payload_index_first_parameter);
       
  1661 
       
  1662 	eap_process_tlv_message_data_c message_data(m_am_tools);
       
  1663 
       
  1664 	if (message_data.get_is_valid() == false)
       
  1665 	{
       
  1666 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1667 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1668 	}
       
  1669 
       
  1670 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1671 
       
  1672 	eap_am_network_id_c receive_network_id(m_am_tools);
       
  1673 
       
  1674 	status = message_data.read_parameter_data(parameters, parameter_index, &receive_network_id);
       
  1675 	if (status != eap_status_ok)
       
  1676 	{
       
  1677 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1678 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1679 	}
       
  1680 
       
  1681 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1682 
       
  1683 	++parameter_index;
       
  1684 
       
  1685 	eapol_key_authentication_type_e authentication_type(eapol_key_authentication_type_none);
       
  1686 
       
  1687 	status = message_data.read_parameter_data(parameters, parameter_index, &authentication_type);
       
  1688 	if (status != eap_status_ok)
       
  1689 	{
       
  1690 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1691 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1692 	}
       
  1693 
       
  1694 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1695 
       
  1696 	++parameter_index;
       
  1697 
       
  1698 	eap_variable_data_c SSID(m_am_tools);
       
  1699 
       
  1700 	status = message_data.read_parameter_data(parameters, parameter_index, &SSID);
       
  1701 	if (status != eap_status_ok)
       
  1702 	{
       
  1703 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1704 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1705 	}
       
  1706 
       
  1707 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1708 
       
  1709 	++parameter_index;
       
  1710 
       
  1711 	eap_variable_data_c preshared_key(m_am_tools);
       
  1712 
       
  1713 	status = message_data.read_parameter_data(parameters, parameter_index, &preshared_key);
       
  1714 	if (status != eap_status_ok)
       
  1715 	{
       
  1716 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1717 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1718 	}
       
  1719 
       
  1720 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1721 
       
  1722 	if (authentication_type == eapol_key_authentication_type_WPS)
       
  1723 	{
       
  1724 		// Save SSID and pre-shared key for WPS to memory store.
       
  1725 		eap_variable_data_c memory_store_key(m_am_tools);
       
  1726 
       
  1727 		eap_status_e status = memory_store_key.set_copy_of_buffer(
       
  1728 			EAP_WPS_CONFIGURATION_MEMORY_STORE_KEY,
       
  1729 			sizeof(EAP_WPS_CONFIGURATION_MEMORY_STORE_KEY));
       
  1730 		if (status != eap_status_ok)
       
  1731 		{
       
  1732 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1733 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1734 		}
       
  1735 
       
  1736 		status = memory_store_key.add_data(
       
  1737 			&m_is_client,
       
  1738 			sizeof(m_is_client));
       
  1739 		if (status != eap_status_ok)
       
  1740 		{
       
  1741 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1742 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1743 		}
       
  1744 
       
  1745 		eap_network_id_selector_c state_selector(
       
  1746 			m_am_tools,
       
  1747 			&receive_network_id);
       
  1748 
       
  1749 		status = memory_store_key.add_data(
       
  1750 			&state_selector);
       
  1751 		if (status != eap_status_ok)
       
  1752 		{
       
  1753 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1754 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1755 		}
       
  1756 
       
  1757 		eap_tlv_message_data_c tlv_data(m_am_tools);
       
  1758 
       
  1759 		status = tlv_data.add_message_data(
       
  1760 			eap_type_protected_setup_stored_preshared_key,
       
  1761 			preshared_key.get_data_length(),
       
  1762 			preshared_key.get_data());
       
  1763 		if (status != eap_status_ok)
       
  1764 		{
       
  1765 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1766 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1767 		}
       
  1768 
       
  1769 		status = tlv_data.add_message_data(
       
  1770 			eap_type_protected_setup_stored_ssid,
       
  1771 			SSID.get_data_length(),
       
  1772 			SSID.get_data());
       
  1773 		if (status != eap_status_ok)
       
  1774 		{
       
  1775 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1776 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1777 		}
       
  1778 
       
  1779 		status = m_am_tools->memory_store_remove_data(&memory_store_key);
       
  1780 		if (status != eap_status_ok
       
  1781 			&& status != eap_status_not_found)
       
  1782 		{
       
  1783 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1784 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1785 		}
       
  1786 
       
  1787 		status = m_am_tools->memory_store_add_data(
       
  1788 			&memory_store_key,
       
  1789 			&tlv_data,
       
  1790 			eap_type_default_credential_timeout);
       
  1791 		if (status != eap_status_ok)
       
  1792 		{
       
  1793 			EAP_TRACE_ERROR(
       
  1794 				m_am_tools,
       
  1795 				TRACE_FLAGS_ERROR,
       
  1796 				(EAPL("eap_core_server_message_if_c::get_802_11_authentication_mode(): cannot store WPS credentials\n")));
       
  1797 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1798 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  1799 		}
       
  1800 	}
       
  1801 
       
  1802 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1803 
       
  1804 	status = m_am_stack->get_802_11_authentication_mode(
       
  1805 		&receive_network_id, ///< source includes remote address, destination includes local address.
       
  1806 		authentication_type);
       
  1807 
       
  1808 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1809 
       
  1810 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1811 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1812 }
       
  1813 
       
  1814 //--------------------------------------------------
       
  1815 
       
  1816 eap_status_e eap_core_server_message_if_c::set_eap_database_reference_values(
       
  1817 	EAP_TEMPLATE_CONST eap_array_c<eap_tlv_header_c> * const parameters)
       
  1818 {
       
  1819 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1820 
       
  1821 	EAP_TRACE_DEBUG(
       
  1822 		m_am_tools, 
       
  1823 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1824 		(EAPL("%s: eap_core_server_message_if_c::set_eap_database_reference_values()\n"),
       
  1825 		 (m_is_client == true) ? "client": "server"));
       
  1826 
       
  1827 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::set_eap_database_reference_values()");
       
  1828 
       
  1829 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1830 
       
  1831 	eap_status_e status(eap_status_ok);
       
  1832 
       
  1833 	u32_t parameter_index(eap_message_payload_index_first_parameter);
       
  1834 
       
  1835 	eap_process_tlv_message_data_c message_data(m_am_tools);
       
  1836 
       
  1837 	if (message_data.get_is_valid() == false)
       
  1838 	{
       
  1839 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1840 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1841 	}
       
  1842 
       
  1843 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1844 
       
  1845 	eap_variable_data_c reference(m_am_tools);
       
  1846 
       
  1847 	status = message_data.read_parameter_data(parameters, parameter_index, &reference);
       
  1848 	if (status != eap_status_ok)
       
  1849 	{
       
  1850 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1851 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1852 	}
       
  1853 
       
  1854 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1855 
       
  1856 	status = m_am_stack->set_eap_database_reference_values(
       
  1857 		&reference
       
  1858 		);
       
  1859 
       
  1860 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1861 
       
  1862 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1863 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1864 }
       
  1865 
       
  1866 //--------------------------------------------------
       
  1867 
       
  1868 #if defined(USE_EAP_SIMPLE_CONFIG)
       
  1869 
       
  1870 EAP_FUNC_EXPORT eap_status_e eap_core_server_message_if_c::save_simple_config_session(
       
  1871 	const simple_config_state_e /* state */,
       
  1872 	EAP_TEMPLATE_CONST eap_array_c<simple_config_credential_c> * const credential_array,
       
  1873 	const eap_variable_data_c * const /* new_password */,
       
  1874 	const simple_config_Device_Password_ID_e /* Device_Password_ID */,
       
  1875 	const simple_config_payloads_c * const /* other_configuration */)
       
  1876 {
       
  1877 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1878 
       
  1879 	EAP_TRACE_DEBUG(
       
  1880 		m_am_tools, 
       
  1881 		EAP_TRACE_FLAGS_MESSAGE_DATA, 
       
  1882 		(EAPL("%s: eap_core_server_message_if_c::save_simple_config_session()\n"),
       
  1883 		 (m_is_client == true) ? "client": "server"));
       
  1884 
       
  1885 	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, EAP_TRACE_FLAGS_MESSAGE_DATA, "returns: eap_core_server_message_if_c::save_simple_config_session()");
       
  1886 
       
  1887 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  1888 
       
  1889 	// Message is formatted as:
       
  1890 	// 0                   1                   2                   3   
       
  1891 	//  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
       
  1892 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
       
  1893 	// |                    Type = Function                            |
       
  1894 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1895 	// |                    Length = 4                                 |
       
  1896 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1897 	// |                    Value = New_protected_setup_credentials    |
       
  1898 	// +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+ <= start of Array of Protected setup credential
       
  1899 	// |                    Type = Array                               |
       
  1900 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1901 	// |                    Length = 137                               |
       
  1902 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ <= start of Array of Protected setup credential value
       
  1903 	// |                    Type = Protected setup credential          |
       
  1904 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1905 	// |                    Length = 129                               |
       
  1906 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
       
  1907 	// |                    Type = Unsigned 8 bit integer              |
       
  1908 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1909 	// |                    Length = 1                                 |
       
  1910 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1911 	// |   u8_t value  |
       
  1912 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
       
  1913 	// |                    Type = Variable data                       |
       
  1914 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1915 	// |                    Length = 12                                |
       
  1916 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1917 	// |                    Value = SSID string                        |
       
  1918 	// +-+-+-+-                                                 -+-+-+-+
       
  1919 	// |                                                               |
       
  1920 	// +-+-+-+-                                                 -+-+-+-+
       
  1921 	// |                                                               |
       
  1922 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
       
  1923 	// |                    Type = Unsigned 16 bit integer             |
       
  1924 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1925 	// |                    Length = 2                                 |
       
  1926 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1927 	// |   u16_t Authentication type   |
       
  1928 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
       
  1929 	// |                    Type = Unsigned 16 bit integer             |
       
  1930 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1931 	// |                    Length = 2                                 |
       
  1932 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1933 	// |   u16_t Encryption type       |
       
  1934 	// +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+ <= start of Array of Network key
       
  1935 	// |                    Type = Array                               |
       
  1936 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1937 	// |                    Length = 66                                |
       
  1938 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ <= start of Array of Network key value
       
  1939 	// |                    Type = Network key                         |
       
  1940 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1941 	// |                    Length = 25                                |
       
  1942 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
       
  1943 	// |                    Type = Unsigned 8 bit integer              |
       
  1944 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1945 	// |                    Length = 1                                 |
       
  1946 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1947 	// |   u8_t value  |
       
  1948 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
       
  1949 	// |                    Type = Variable data                       |
       
  1950 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1951 	// |                    Length = 8                                 |
       
  1952 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1953 	// |                    Value = Network key                        |
       
  1954 	// +-+-+-+-                                                 -+-+-+-+
       
  1955 	// |                                                               |
       
  1956 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
       
  1957 	// |                    Type = Network key                         |
       
  1958 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1959 	// |                    Length = 25                                |
       
  1960 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
       
  1961 	// |                    Type = Unsigned 8 bit integer              |
       
  1962 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1963 	// |                    Length = 1                                 |
       
  1964 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1965 	// |   u8_t value  |
       
  1966 	// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
       
  1967 	// |                    Type = Variable data                       |
       
  1968 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1969 	// |                    Length = 8                                 |
       
  1970 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1971 	// |                    Value = Network key                        |
       
  1972 	// +-+-+-+-                                                 -+-+-+-+
       
  1973 	// |                                                               |
       
  1974 	// +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+ <= end of Array of Network key
       
  1975 	// |                    Type = Variable data                       |
       
  1976 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1977 	// |                    Length = 6                                 |
       
  1978 	// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1979 	// |                    Value = MAC address                        |
       
  1980 	// +-+-+-+-                        +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       
  1981 	// |                               |
       
  1982 	// +#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+#+                                 <= end of Array of Protected setup credential
       
  1983 
       
  1984 
       
  1985 	eap_status_e status(eap_status_ok);
       
  1986 
       
  1987 	{
       
  1988 		// Creates message data composed of Attribute-Value Pairs.
       
  1989 		eap_process_tlv_message_data_c message(m_am_tools);
       
  1990 
       
  1991 		if (message.get_is_valid() == false)
       
  1992 		{
       
  1993 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1994 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1995 		}
       
  1996 
       
  1997 		status = message.add_parameter_data(eap_tlv_message_type_function_new_protected_setup_credentials);
       
  1998 		if (status != eap_status_ok)
       
  1999 		{
       
  2000 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2001 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2002 		}
       
  2003 
       
  2004 		status = message.add_parameter_data(credential_array);
       
  2005 		if (status != eap_status_ok)
       
  2006 		{
       
  2007 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2008 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2009 		}
       
  2010 
       
  2011 		status = send_message(&message);
       
  2012 		if (status != eap_status_ok)
       
  2013 		{
       
  2014 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2015 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2016 		}
       
  2017 	}
       
  2018 
       
  2019 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
  2020 
       
  2021 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2022 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2023 }
       
  2024 
       
  2025 #endif // #if defined(USE_EAP_SIMPLE_CONFIG)
       
  2026 
       
  2027 //--------------------------------------------------
       
  2028 
       
  2029 eap_am_message_if_c * eap_am_message_if_c::new_eap_am_server_message_if_c(
       
  2030 	abs_eap_am_tools_c * const tools,
       
  2031 	const bool is_client_when_true,
       
  2032 	const u32_t MTU)
       
  2033 {
       
  2034 	eap_am_message_if_c * server = new eap_core_server_message_if_c(
       
  2035 		tools,
       
  2036 		is_client_when_true,
       
  2037 		MTU);
       
  2038 
       
  2039 	eap_automatic_variable_c<eap_am_message_if_c> automatic_server(
       
  2040 		tools,
       
  2041 		server);
       
  2042 
       
  2043 	if (server == 0
       
  2044 		|| server->get_is_valid() == false)
       
  2045 	{
       
  2046 		// ERROR.
       
  2047 		if (server != 0)
       
  2048 		{
       
  2049 			EAP_TRACE_DEBUG(
       
  2050 				tools,
       
  2051 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  2052 				(EAPL("ERROR: calls: eap_am_message_if_c::new_eap_am_server_message_if_c(): server->shutdown(): %s.\n"),
       
  2053 				(is_client_when_true == true) ? "client": "server"));
       
  2054 
       
  2055 			server->shutdown();
       
  2056 		}
       
  2057 
       
  2058 		return 0;
       
  2059 	}
       
  2060 
       
  2061 	automatic_server.do_not_free_variable();
       
  2062 
       
  2063 	return server;
       
  2064 }
       
  2065 
       
  2066 //--------------------------------------------------
       
  2067 // End.