eapol/eapol_framework/eapol_common/type/simple_config/simple_config/src/simple_config_record.cpp
branchRCL_3
changeset 46 c74b3d9f6b9e
parent 45 bad0cc58d154
equal deleted inserted replaced
45:bad0cc58d154 46:c74b3d9f6b9e
    14 * Description:  EAP and WLAN authentication protocols.
    14 * Description:  EAP and WLAN authentication protocols.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: %
    19 * %version: 73 %
    20 */
    20 */
    21 
    21 
    22 // This is enumeration of EAPOL source code.
    22 // This is enumeration of EAPOL source code.
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    24 	#undef EAP_FILE_NUMBER_ENUM
    24 	#undef EAP_FILE_NUMBER_ENUM
    45 #include "eap_type_simple_config_types.h"
    45 #include "eap_type_simple_config_types.h"
    46 #include "eap_header_string.h"
    46 #include "eap_header_string.h"
    47 #include "abs_eap_am_mutex.h"
    47 #include "abs_eap_am_mutex.h"
    48 #include "simple_config_credential.h"
    48 #include "simple_config_credential.h"
    49 #include "eapol_key_types.h"
    49 #include "eapol_key_types.h"
    50 #include "eap_config.h"
       
    51 #include "eap_network_id_selector.h"
       
    52 #include "eap_tlv_message_data.h"
       
    53 
    50 
    54 //--------------------------------------------------
    51 //--------------------------------------------------
    55 
    52 
    56 
    53 
    57 EAP_FUNC_EXPORT simple_config_record_c::~simple_config_record_c()
    54 EAP_FUNC_EXPORT simple_config_record_c::~simple_config_record_c()
   415 		return EAP_STATUS_RETURN(m_am_tools, status);
   412 		return EAP_STATUS_RETURN(m_am_tools, status);
   416 	}
   413 	}
   417 
   414 
   418 	//----------------------------------------------------------
   415 	//----------------------------------------------------------
   419 
   416 
   420 #if 0
       
   421 	{
   417 	{
   422 		status = get_type_partner()->read_configure(
   418 		status = get_type_partner()->read_configure(
   423 			cf_str_EAP_SIMPLE_CONFIG_device_password.get_field(),
   419 			cf_str_EAP_SIMPLE_CONFIG_device_password.get_field(),
   424 			&m_device_password);
   420 			&m_device_password);
   425 		if (status != eap_status_ok
   421 		if (status != eap_status_ok
   433 				 (m_is_client == true ? "client": "server")));
   429 				 (m_is_client == true ? "client": "server")));
   434 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   430 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   435 			return EAP_STATUS_RETURN(m_am_tools, eap_status_wrong_password);
   431 			return EAP_STATUS_RETURN(m_am_tools, eap_status_wrong_password);
   436 		}
   432 		}
   437 	}
   433 	}
   438 #endif
       
   439 
   434 
   440 	if (m_is_client == false)
   435 	if (m_is_client == false)
   441 	{
   436 	{
   442 		status = get_type_partner()->read_configure(
       
   443 			cf_str_EAP_SIMPLE_CONFIG_device_password.get_field(),
       
   444 			&m_device_password);
       
   445 		if (status != eap_status_ok
       
   446 			|| m_device_password.get_is_valid_data() == false)
       
   447 		{
       
   448 			// This is mandatory value.
       
   449 			EAP_TRACE_ERROR(
       
   450 				m_am_tools,
       
   451 				TRACE_FLAGS_DEFAULT,
       
   452 				(EAPL("ERROR: SIMPLE_CONFIG: %s: simple_config_record_c::configure(): Missing device password.\n"),
       
   453 				 (m_is_client == true ? "client": "server")));
       
   454 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   455 			return EAP_STATUS_RETURN(m_am_tools, eap_status_wrong_password);
       
   456 		}
       
   457 
       
   458 		(void) get_type_partner()->read_configure(
   437 		(void) get_type_partner()->read_configure(
   459 			cf_str_EAP_SIMPLE_CONFIG_server_device_password.get_field(),
   438 			cf_str_EAP_SIMPLE_CONFIG_server_device_password.get_field(),
   460 			&m_device_password);
   439 			&m_device_password);
   461 	}
   440 	}
   462 
   441 
  4480 		}
  4459 		}
  4481 
  4460 
  4482 		// Compare RHash1.
  4461 		// Compare RHash1.
  4483 		if (local_RHash1.compare(&m_RHash1) != 0)
  4462 		if (local_RHash1.compare(&m_RHash1) != 0)
  4484 		{
  4463 		{
  4485 			EAP_TRACE_DATA_DEBUG(
       
  4486 				m_am_tools, 
       
  4487 				TRACE_FLAGS_DEFAULT, 
       
  4488 				(EAPL("local_RHash1"),
       
  4489 				 local_RHash1.get_data(),
       
  4490 				 local_RHash1.get_data_length()));
       
  4491 			EAP_TRACE_DATA_DEBUG(
       
  4492 				m_am_tools, 
       
  4493 				TRACE_FLAGS_DEFAULT, 
       
  4494 				(EAPL("m_RHash1"),
       
  4495 				 m_RHash1.get_data(),
       
  4496 				 m_RHash1.get_data_length()));
       
  4497 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  4464 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  4498 			return EAP_STATUS_RETURN(m_am_tools, eap_status_device_password_authentication_failure);
  4465 			return EAP_STATUS_RETURN(m_am_tools, eap_status_device_password_authentication_failure);
  4499 		}
  4466 		}
  4500 	}
  4467 	}
  4501 
  4468 
  6517 	eap_variable_data_c * const ER_Hash1,
  6484 	eap_variable_data_c * const ER_Hash1,
  6518 	eap_variable_data_c * const PSK2,
  6485 	eap_variable_data_c * const PSK2,
  6519 	eap_variable_data_c * const ER_S2,
  6486 	eap_variable_data_c * const ER_S2,
  6520 	eap_variable_data_c * const ER_Hash2)
  6487 	eap_variable_data_c * const ER_Hash2)
  6521 {
  6488 {
  6522 	EAP_TRACE_DATA_DEBUG(
       
  6523 		m_am_tools,
       
  6524 		TRACE_FLAGS_DEFAULT,
       
  6525 		(EAPL("SIMPLE_CONFIG: generate_er_hashs(): device_password"),
       
  6526 		device_password->get_data(),
       
  6527 		device_password->get_data_length()));
       
  6528 
  6489 
  6529 	eap_variable_data_c first_half_of_device_password(m_am_tools);
  6490 	eap_variable_data_c first_half_of_device_password(m_am_tools);
  6530 
  6491 
  6531 	if (first_half_of_device_password.get_is_valid() == false)
  6492 	if (first_half_of_device_password.get_is_valid() == false)
  6532 	{
  6493 	{
  8197 		{
  8158 		{
  8198 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  8159 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  8199 			return EAP_STATUS_RETURN(m_am_tools, status);
  8160 			return EAP_STATUS_RETURN(m_am_tools, status);
  8200 		}
  8161 		}
  8201 	}
  8162 	}
  8202 	else if (m_local_Device_Password_ID == simple_config_Device_Password_ID_Default_PIN
       
  8203 		&& m_is_client == true)
       
  8204 	{
       
  8205 		// Read PIN from memory store.
       
  8206 
       
  8207 		eap_variable_data_c memory_store_key(m_am_tools);
       
  8208 
       
  8209 		eap_status_e status = memory_store_key.set_copy_of_buffer(
       
  8210 			EAP_WPS_CONFIGURATION_MEMORY_STORE_KEY,
       
  8211 			sizeof(EAP_WPS_CONFIGURATION_MEMORY_STORE_KEY));
       
  8212 		if (status != eap_status_ok)
       
  8213 		{
       
  8214 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  8215 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  8216 		}
       
  8217 
       
  8218 		status = memory_store_key.add_data(
       
  8219 			&m_is_client,
       
  8220 			sizeof(m_is_client));
       
  8221 		if (status != eap_status_ok)
       
  8222 		{
       
  8223 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  8224 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  8225 		}
       
  8226 
       
  8227 		eap_am_network_id_c receive_network_id(m_am_tools,
       
  8228 			m_send_network_id.get_destination_id(),
       
  8229 			m_send_network_id.get_source_id(),
       
  8230 			m_send_network_id.get_type());
       
  8231 
       
  8232 		eap_network_id_selector_c state_selector(
       
  8233 			m_am_tools,
       
  8234 			&receive_network_id);
       
  8235 
       
  8236 		status = memory_store_key.add_data(
       
  8237 			&state_selector);
       
  8238 		if (status != eap_status_ok)
       
  8239 		{
       
  8240 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  8241 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  8242 		}
       
  8243 
       
  8244 		eap_tlv_message_data_c tlv_data(m_am_tools);
       
  8245 
       
  8246 		status = m_am_tools->memory_store_get_data(
       
  8247 			&memory_store_key,
       
  8248 			&tlv_data);
       
  8249 		if (status != eap_status_ok)
       
  8250 		{
       
  8251 			EAP_TRACE_DEBUG(
       
  8252 				m_am_tools,
       
  8253 				TRACE_FLAGS_DEFAULT,
       
  8254 				(EAPL("simple_config_record_c::complete_query_network_and_device_parameters(): cannot get WPS credentials\n")));
       
  8255 		}
       
  8256 		else
       
  8257 		{
       
  8258 			EAP_TRACE_DEBUG(
       
  8259 				m_am_tools,
       
  8260 				TRACE_FLAGS_DEFAULT,
       
  8261 				(EAPL("simple_config_record_c::complete_query_network_and_device_parameters(): WPS credentials found\n")));
       
  8262 
       
  8263 			// Parse read data.
       
  8264 			eap_array_c<eap_tlv_header_c> tlv_blocks(m_am_tools);
       
  8265 				
       
  8266 			status = tlv_data.parse_message_data(&tlv_blocks);
       
  8267 			if (status != eap_status_ok)
       
  8268 			{
       
  8269 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  8270 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  8271 			}
       
  8272 
       
  8273 			for (u32_t ind = 0ul; ind < tlv_blocks.get_object_count(); ind++)
       
  8274 			{
       
  8275 				eap_tlv_header_c * const tlv = tlv_blocks.get_object(ind);
       
  8276 				if (tlv != 0)
       
  8277 				{
       
  8278 					if (tlv->get_type() == eap_type_protected_setup_stored_preshared_key)
       
  8279 					{
       
  8280 						status = m_device_password.set_copy_of_buffer(
       
  8281 							tlv->get_value(tlv->get_value_length()),
       
  8282 							tlv->get_value_length());
       
  8283 						if (status != eap_status_ok)
       
  8284 						{
       
  8285 							EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  8286 							return EAP_STATUS_RETURN(m_am_tools, status);
       
  8287 						}
       
  8288 					}
       
  8289 					else if (tlv->get_type() == eap_type_protected_setup_stored_ssid)
       
  8290 					{
       
  8291 						status = m_SSID.set_copy_of_buffer(
       
  8292 							tlv->get_value(tlv->get_value_length()),
       
  8293 							tlv->get_value_length());
       
  8294 						if (status != eap_status_ok)
       
  8295 						{
       
  8296 							EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  8297 							return EAP_STATUS_RETURN(m_am_tools, status);
       
  8298 						}
       
  8299 					}
       
  8300 				}
       
  8301 			} // for()
       
  8302 
       
  8303 			if (m_device_password.get_is_valid_data() == false)
       
  8304 			{
       
  8305 				EAP_TRACE_ERROR(
       
  8306 					m_am_tools,
       
  8307 					TRACE_FLAGS_ERROR,
       
  8308 					(EAPL("simple_config_record_c::complete_query_network_and_device_parameters(): cannot get WPS PIN\n")));
       
  8309 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  8310 				return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
  8311 			}
       
  8312 		}
       
  8313 	}
       
  8314 
  8163 
  8315 
  8164 
  8316 	if (local_completion_status == eap_status_ok)
  8165 	if (local_completion_status == eap_status_ok)
  8317 	{
  8166 	{
  8318 		switch (state)
  8167 		switch (state)