eapol/eapol_framework/eapol_common/type/simple_config/simple_config/src/simple_config_record.cpp
changeset 49 43351a4f2da3
parent 26 9abfd4f00d37
equal deleted inserted replaced
47:712b4ffd76bb 49:43351a4f2da3
    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: 69.1.7 %
    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
   415 		return EAP_STATUS_RETURN(m_am_tools, status);
   415 		return EAP_STATUS_RETURN(m_am_tools, status);
   416 	}
   416 	}
   417 
   417 
   418 	//----------------------------------------------------------
   418 	//----------------------------------------------------------
   419 
   419 
   420 #if 0
       
   421 	{
       
   422 		status = get_type_partner()->read_configure(
       
   423 			cf_str_EAP_SIMPLE_CONFIG_device_password.get_field(),
       
   424 			&m_device_password);
       
   425 		if (status != eap_status_ok
       
   426 			|| m_device_password.get_is_valid_data() == false)
       
   427 		{
       
   428 			// This is mandatory value.
       
   429 			EAP_TRACE_ERROR(
       
   430 				m_am_tools,
       
   431 				TRACE_FLAGS_DEFAULT,
       
   432 				(EAPL("ERROR: SIMPLE_CONFIG: %s: simple_config_record_c::configure(): Missing device password.\n"),
       
   433 				 (m_is_client == true ? "client": "server")));
       
   434 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   435 			return EAP_STATUS_RETURN(m_am_tools, eap_status_wrong_password);
       
   436 		}
       
   437 	}
       
   438 #endif
       
   439 
       
   440 	if (m_is_client == false)
   420 	if (m_is_client == false)
   441 	{
   421 	{
   442 		status = get_type_partner()->read_configure(
   422 		status = get_type_partner()->read_configure(
   443 			cf_str_EAP_SIMPLE_CONFIG_device_password.get_field(),
   423 			cf_str_EAP_SIMPLE_CONFIG_device_password.get_field(),
   444 			&m_device_password);
   424 			&m_device_password);
  8027 	}
  8007 	}
  8028 
  8008 
  8029 	eap_status_e local_completion_status(p_completion_status);
  8009 	eap_status_e local_completion_status(p_completion_status);
  8030 	eap_status_e status(eap_status_process_general_error);
  8010 	eap_status_e status(eap_status_process_general_error);
  8031 
  8011 
  8032 
  8012 	if (m_is_client == true)
       
  8013 	{
       
  8014 		status = get_type_partner()->read_configure(
       
  8015 			cf_str_EAP_SIMPLE_CONFIG_device_password.get_field(),
       
  8016 			&m_device_password);
       
  8017 		if (status != eap_status_ok
       
  8018 			|| m_device_password.get_is_valid_data() == false)
       
  8019 		{
       
  8020 			// This is mandatory value.
       
  8021 			EAP_TRACE_ERROR(
       
  8022 				m_am_tools,
       
  8023 				TRACE_FLAGS_DEFAULT,
       
  8024 				(EAPL("ERROR: SIMPLE_CONFIG: %s: simple_config_record_c::configure(): Missing device password.\n"),
       
  8025 				 (m_is_client == true ? "client": "server")));
       
  8026 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  8027 			return EAP_STATUS_RETURN(m_am_tools, eap_status_wrong_password);
       
  8028 		}
       
  8029 	}
       
  8030 
       
  8031 	
  8033 	{
  8032 	{
  8034 		if (m_simple_config_state == simple_config_state_process_simple_config_start)
  8033 		if (m_simple_config_state == simple_config_state_process_simple_config_start)
  8035 		{
  8034 		{
  8036 			status = network_and_device_parameters->get_attribute_data(
  8035 			status = network_and_device_parameters->get_attribute_data(
  8037 				simple_config_Attribute_Type_UUID_E,
  8036 				simple_config_Attribute_Type_UUID_E,
  8185 			}
  8184 			}
  8186 		}
  8185 		}
  8187 	}
  8186 	}
  8188 
  8187 
  8189 
  8188 
  8190 	if (m_local_Device_Password_ID == simple_config_Device_Password_ID_PushButton)
       
  8191 	{
       
  8192 		// Set m_device_password to all ascii zeroes SIMPLE_CONFIG_PBC_DEVICE_PASSWORD_PIN.
       
  8193 		status = m_device_password.set_copy_of_buffer(
       
  8194 			SIMPLE_CONFIG_PBC_DEVICE_PASSWORD_PIN,
       
  8195 			SIMPLE_CONFIG_PBC_DEVICE_PASSWORD_PIN_SIZE);
       
  8196 		if (status != eap_status_ok)
       
  8197 		{
       
  8198 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  8199 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  8200 		}
       
  8201 	}
       
  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 
       
  8315 
       
  8316 	if (local_completion_status == eap_status_ok)
  8189 	if (local_completion_status == eap_status_ok)
  8317 	{
  8190 	{
  8318 		switch (state)
  8191 		switch (state)
  8319 		{
  8192 		{
  8320 
  8193