eapol/eapol_framework/eapol_common/am/common/eap_file_config.cpp
branchRCL_3
changeset 19 c74b3d9f6b9e
parent 18 bad0cc58d154
equal deleted inserted replaced
18:bad0cc58d154 19: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: 33 %
    19 * %version: 17.1.3 %
    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
    29 
    29 
    30 
    30 
    31 #include "eap_am_memory.h"
    31 #include "eap_am_memory.h"
    32 #include "eap_file_config.h"
    32 #include "eap_file_config.h"
    33 #include "eap_automatic_variable.h"
    33 #include "eap_automatic_variable.h"
    34 #include "eap_tlv_message_data.h"
       
    35 #include "eap_process_tlv_message_data.h"
       
    36 #include "eap_config.h"
       
    37 
    34 
    38 #if defined(_WIN32) && !defined(__GNUC__)
    35 #if defined(_WIN32) && !defined(__GNUC__)
    39 	#pragma warning( disable : 4355 ) // 'this' : used in base member initializer list
    36 	#pragma warning( disable : 4355 ) // 'this' : used in base member initializer list
    40 #endif
    37 #endif
    41 
    38 
    48 
    45 
    49 //-----------------------------------------------------------------
    46 //-----------------------------------------------------------------
    50 //-----------------------------------------------------------------
    47 //-----------------------------------------------------------------
    51 //-----------------------------------------------------------------
    48 //-----------------------------------------------------------------
    52 
    49 
    53 EAP_FUNC_EXPORT eap_config_value_c::~eap_config_value_c()
    50 eap_config_value_c::~eap_config_value_c()
    54 {
    51 {
    55 	delete m_subsection_map;
    52 	delete m_subsection_map;
    56 	m_subsection_map = 0;
    53 	m_subsection_map = 0;
    57 }
    54 }
    58 
    55 
    59 EAP_FUNC_EXPORT eap_config_value_c::eap_config_value_c(
    56 eap_config_value_c::eap_config_value_c(
    60 	abs_eap_am_tools_c* const tools)
    57 	abs_eap_am_tools_c* const tools)
    61 	: m_am_tools(tools)
    58 	: m_am_tools(tools)
    62 	, m_subsection_map(0)
    59 	, m_subsection_map(0)
    63 	, m_data(tools)
    60 	, m_data(tools)
    64 	, m_type(eap_configure_type_none)
    61 	, m_type(eap_configure_type_none)
    65 	, m_is_valid(false)
    62 	, m_is_valid(false)
    66 {
    63 {
    67 	EAP_ASSERT(eap_configure_type_id[eap_configure_type_none].type == eap_configure_type_none);	
       
    68 	EAP_ASSERT(eap_configure_type_id[eap_configure_type_u32_t].type == eap_configure_type_u32_t);	
       
    69 	EAP_ASSERT(eap_configure_type_id[eap_configure_type_boolean].type == eap_configure_type_boolean);	
       
    70 	EAP_ASSERT(eap_configure_type_id[eap_configure_type_string].type == eap_configure_type_string);	
       
    71 	EAP_ASSERT(eap_configure_type_id[eap_configure_type_hex_data].type == eap_configure_type_hex_data);	
       
    72 	EAP_ASSERT(eap_configure_type_id[eap_configure_type_u32array].type == eap_configure_type_u32array);	
       
    73 
       
    74 	if (m_data.get_is_valid() == false)
    64 	if (m_data.get_is_valid() == false)
    75 	{
    65 	{
    76 		return;
    66 		return;
    77 	}
    67 	}
    78 
    68 
    79 	m_is_valid = true;
    69 	m_is_valid = true;
    80 }
    70 }
    81 
    71 
    82 EAP_FUNC_EXPORT void eap_config_value_c::set_subsection(
    72 void eap_config_value_c::set_subsection(
    83 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const subsection_map)
    73 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const subsection_map)
    84 {
    74 {
    85 	m_subsection_map = subsection_map;
    75 	m_subsection_map = subsection_map;
    86 }
    76 }
    87 
    77 
    88 EAP_FUNC_EXPORT eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * eap_config_value_c::get_subsection()
    78 eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * eap_config_value_c::get_subsection()
    89 {
    79 {
    90 	return m_subsection_map;
    80 	return m_subsection_map;
    91 }
    81 }
    92 
    82 
    93 EAP_FUNC_EXPORT eap_variable_data_c * eap_config_value_c::get_data()
    83 eap_variable_data_c * eap_config_value_c::get_data()
    94 {
    84 {
    95 	return &m_data;
    85 	return &m_data;
    96 }
    86 }
    97 
    87 
    98 EAP_FUNC_EXPORT const eap_variable_data_c * eap_config_value_c::get_const_data() const
    88 void eap_config_value_c::set_type(const eap_configure_type_e type)
    99 {
       
   100 	return &m_data;
       
   101 }
       
   102 
       
   103 EAP_FUNC_EXPORT void eap_config_value_c::set_type(const eap_configure_type_e type)
       
   104 {
    89 {
   105 	m_type = type;
    90 	m_type = type;
   106 }
    91 }
   107 
    92 
   108 EAP_FUNC_EXPORT eap_configure_type_e eap_config_value_c::get_type()
    93 eap_configure_type_e eap_config_value_c::get_type()
   109 {
    94 {
   110 	return m_type;
    95 	return m_type;
   111 }
    96 }
   112 
    97 
   113 EAP_FUNC_EXPORT eap_configure_type_e eap_config_value_c::get_const_type() const
    98 void eap_config_value_c::object_increase_reference_count()
   114 {
    99 {
   115 	return m_type;
   100 }
   116 }
   101 
   117 
   102 bool eap_config_value_c::get_is_valid()
   118 EAP_FUNC_EXPORT void eap_config_value_c::object_increase_reference_count()
       
   119 {
       
   120 }
       
   121 
       
   122 EAP_FUNC_EXPORT bool eap_config_value_c::get_is_valid() const
       
   123 {
   103 {
   124 	return m_is_valid;
   104 	return m_is_valid;
   125 }
   105 }
   126 
   106 
   127 //-----------------------------------------------------------------
   107 //-----------------------------------------------------------------
   129 //-----------------------------------------------------------------
   109 //-----------------------------------------------------------------
   130 
   110 
   131 
   111 
   132 EAP_FUNC_EXPORT eap_file_config_c::eap_file_config_c(
   112 EAP_FUNC_EXPORT eap_file_config_c::eap_file_config_c(
   133 	abs_eap_am_tools_c* const tools)
   113 	abs_eap_am_tools_c* const tools)
   134   : m_am_tools(tools)
   114 : m_am_tools(tools)
   135   , m_config_map(tools, this)
   115 , m_config_map(tools, this)
   136   , m_value_buffer(tools)
   116 , m_is_valid(false)
   137   , m_is_valid(false)
       
   138 {
   117 {
   139 	EAP_UNREFERENCED_PARAMETER(TRACE_FLAGS_CONFIGURE_DATA); // in release
   118 	EAP_UNREFERENCED_PARAMETER(TRACE_FLAGS_CONFIGURE_DATA); // in release
   140 	
   119 	
   141 	set_is_valid();
   120 	set_is_valid();
   142 }
   121 }
   163 	return EAP_STATUS_RETURN(m_am_tools, status);
   142 	return EAP_STATUS_RETURN(m_am_tools, status);
   164 }
   143 }
   165 
   144 
   166 //-----------------------------------------------------------------
   145 //-----------------------------------------------------------------
   167 
   146 
   168 eap_status_e eap_file_config_c::expand_environment_variables(
   147 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::expand_environment_variables(
   169 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
   148 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
   170 	const eap_variable_data_c * const original_value,
   149 	const eap_variable_data_c * const original_value,
   171 	eap_variable_data_c * const expanded_value
   150 	eap_variable_data_c * const expanded_value
   172 	)
   151 	)
   173 {
   152 {
   182 	}
   161 	}
   183 
   162 
   184 	const u8_t env_char = '$';
   163 	const u8_t env_char = '$';
   185 	const u8_t char_left_parenthesis = '(';
   164 	const u8_t char_left_parenthesis = '(';
   186 	const u8_t char_right_parenthesis = ')';
   165 	const u8_t char_right_parenthesis = ')';
       
   166 
       
   167 	eap_variable_data_c tmp_value_buffer(m_am_tools);
       
   168 	if (tmp_value_buffer.get_is_valid() == false)
       
   169 	{
       
   170 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   171 	}
       
   172 
       
   173 	status = tmp_value_buffer.set_buffer_length(MAX_LINE_LENGTH);
       
   174 	if (status != eap_status_ok)
       
   175 	{
       
   176 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   177 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   178 	}
       
   179 
   187 	bool expanded_value_when_true = false;
   180 	bool expanded_value_when_true = false;
   188 
       
   189 	if (m_value_buffer.get_buffer_length() < MAX_LINE_LENGTH)
       
   190 	{
       
   191 		status = m_value_buffer.set_buffer_length(MAX_LINE_LENGTH);
       
   192 		if (status != eap_status_ok)
       
   193 		{
       
   194 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   195 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   196 		}
       
   197 	}
       
   198 
   181 
   199 	status = expanded_value->set_copy_of_buffer(original_value);
   182 	status = expanded_value->set_copy_of_buffer(original_value);
   200 	if (status != eap_status_ok)
   183 	if (status != eap_status_ok)
   201 	{
   184 	{
   202 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   185 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   520 
   503 
   521 
   504 
   522 					if (configure_option.get_is_valid_data() == true
   505 					if (configure_option.get_is_valid_data() == true
   523 						&& configure_option.get_data_length() > 0ul)
   506 						&& configure_option.get_data_length() > 0ul)
   524 					{
   507 					{
   525 						m_value_buffer.reset_start_offset_and_data_length();
   508 						tmp_value_buffer.reset();
   526 
   509 
   527 						u32_t tmp_index = 0ul;
   510 						u32_t tmp_index = 0ul;
   528 
   511 
   529 						if (env_start > start_of_value)
   512 						if (env_start > start_of_value)
   530 						{
   513 						{
   531 							u32_t length_of_begin = env_start-start_of_value;
   514 							u32_t length_of_begin = env_start-start_of_value;
   532 							if (length_of_begin > 0ul)
   515 							if (length_of_begin > 0ul)
   533 							{
   516 							{
   534 								status = m_value_buffer.set_copy_of_buffer(
   517 								status = tmp_value_buffer.set_copy_of_buffer(
   535 									expanded_value->get_data(length_of_begin),
   518 									expanded_value->get_data(length_of_begin),
   536 									length_of_begin);
   519 									length_of_begin);
   537 								if (status != eap_status_ok)
   520 								if (status != eap_status_ok)
   538 								{
   521 								{
   539 									EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   522 									EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   544 							}
   527 							}
   545 						}
   528 						}
   546 
   529 
   547 						if (configure_option.get_data_length() > 0ul)
   530 						if (configure_option.get_data_length() > 0ul)
   548 						{
   531 						{
   549 							status = m_value_buffer.add_data(&configure_option);
   532 							status = tmp_value_buffer.add_data(&configure_option);
   550 							if (status != eap_status_ok)
   533 							if (status != eap_status_ok)
   551 							{
   534 							{
   552 								EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   535 								EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   553 								return EAP_STATUS_RETURN(m_am_tools, status);
   536 								return EAP_STATUS_RETURN(m_am_tools, status);
   554 							}
   537 							}
   559 						if (tmp_end > (env_end+1))
   542 						if (tmp_end > (env_end+1))
   560 						{
   543 						{
   561 							u32_t length_of_end = tmp_end-(env_end+1);
   544 							u32_t length_of_end = tmp_end-(env_end+1);
   562 							if (length_of_end > 0ul)
   545 							if (length_of_end > 0ul)
   563 							{
   546 							{
   564 								status = m_value_buffer.add_data(
   547 								status = tmp_value_buffer.add_data(
   565 									(env_end+1),
   548 									(env_end+1),
   566 									length_of_end);
   549 									length_of_end);
   567 								if (status != eap_status_ok)
   550 								if (status != eap_status_ok)
   568 								{
   551 								{
   569 									EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   552 									EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   572 
   555 
   573 								tmp_index += length_of_end;
   556 								tmp_index += length_of_end;
   574 							}
   557 							}
   575 						}
   558 						}
   576 
   559 
   577 						if (m_value_buffer.get_is_valid_data() == true
   560 						if (tmp_value_buffer.get_is_valid_data() == true
   578 							&& m_value_buffer.get_data_length() > 0ul)
   561 							&& tmp_value_buffer.get_data_length() > 0ul)
   579 						{
   562 						{
   580 							status = expanded_value->set_copy_of_buffer(&m_value_buffer);
   563 							status = expanded_value->set_copy_of_buffer(&tmp_value_buffer);
   581 							if (status != eap_status_ok)
   564 							if (status != eap_status_ok)
   582 							{
   565 							{
   583 								EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   566 								EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   584 								return EAP_STATUS_RETURN(m_am_tools, status);
   567 								return EAP_STATUS_RETURN(m_am_tools, status);
   585 							}
   568 							}
   645 	return EAP_STATUS_RETURN(m_am_tools, status);
   628 	return EAP_STATUS_RETURN(m_am_tools, status);
   646 }
   629 }
   647 
   630 
   648 //-----------------------------------------------------------------
   631 //-----------------------------------------------------------------
   649 
   632 
   650 u8_t * eap_file_config_c::read_hex_byte(
   633 EAP_FUNC_EXPORT u8_t * eap_file_config_c::read_hex_byte(
   651 	u8_t * cursor,
   634 	u8_t * cursor,
   652 	const u8_t * const end,
   635 	const u8_t * const end,
   653 	u8_t * const hex_byte, // This buffer is one byte in length.
   636 	u8_t * const hex_byte)
   654 	const u32_t hex_byte_length)
       
   655 {
   637 {
   656 	u8_t * start = cursor;
   638 	u8_t * start = cursor;
   657 	bool stop = false;
   639 	bool stop = false;
   658 
   640 
   659 	while(stop == false && cursor < end)
   641 	while(stop == false && cursor < end)
   672 
   654 
   673 	}
   655 	}
   674 
   656 
   675 	if (cursor <= end)
   657 	if (cursor <= end)
   676 	{
   658 	{
   677 		u32_t target_length = hex_byte_length;
   659 		u32_t target_length = sizeof(*hex_byte);
   678 
   660 
   679 		eap_status_e status = m_am_tools->convert_hex_ascii_to_bytes(
   661 		eap_status_e status = m_am_tools->convert_hex_ascii_to_bytes(
   680 			start,
   662 			start,
   681 			cursor-start,
   663 			cursor-start,
   682 			hex_byte,
   664 			hex_byte,
   683 			&target_length);
   665 			&target_length);
   684 		if (status != eap_status_ok
   666 		if (status != eap_status_ok)
   685 			|| target_length != hex_byte_length)
       
   686 		{
   667 		{
   687 			return 0;
   668 			return 0;
   688 		}
   669 		}
   689 
   670 
   690 		return ++cursor;
   671 		return ++cursor;
   693 	return 0;
   674 	return 0;
   694 }
   675 }
   695 
   676 
   696 //-----------------------------------------------------------------
   677 //-----------------------------------------------------------------
   697 
   678 
   698 u8_t * eap_file_config_c::read_u32_t(
   679 EAP_FUNC_EXPORT u8_t * eap_file_config_c::read_u32_t(
   699 	u8_t * cursor,
   680 	u8_t * cursor,
   700 	const u8_t * const end,
   681 	const u8_t * const end,
   701 	u32_t * const integer)
   682 	u32_t * const integer)
   702 {
   683 {
   703 	u8_t * start = cursor;
   684 	u8_t * start = cursor;
   752 	return 0;
   733 	return 0;
   753 }
   734 }
   754 
   735 
   755 //-----------------------------------------------------------------
   736 //-----------------------------------------------------------------
   756 
   737 
   757 eap_status_e eap_file_config_c::convert_value(
   738 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::convert_value(
   758 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
   739 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
   759 	const eap_variable_data_c * const value_buffer,
   740 	const eap_variable_data_c * const value_buffer,
   760 	const eap_configure_type_e type,
   741 	const eap_configure_type_e type,
   761 	eap_variable_data_c * const value_data)
   742 	eap_variable_data_c * const value_data)
   762 {
   743 {
   867 			{
   848 			{
   868 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   849 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   869 				return EAP_STATUS_RETURN(m_am_tools, status);
   850 				return EAP_STATUS_RETURN(m_am_tools, status);
   870 			}
   851 			}
   871 			
   852 			
   872 			status = value_data->set_buffer_length((expanded_value_buffer.get_data_length()+1)/3);
       
   873 			if (status != eap_status_ok)
       
   874 			{
       
   875 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   876 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   877 			}
       
   878 
       
   879 			status = value_data->set_data_length(value_data->get_buffer_length());
       
   880 			if (status != eap_status_ok)
       
   881 			{
       
   882 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   883 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   884 			}
       
   885 
       
   886 			u8_t * const target = value_data->get_data(value_data->get_buffer_length());
       
   887 			if (target == 0)
       
   888 			{
       
   889 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   890 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   891 			}
       
   892 
       
   893 			u32_t ind_target(0ul);
       
   894 
       
   895 			u8_t * cursor = expanded_value_buffer.get_data(expanded_value_buffer.get_data_length());
   853 			u8_t * cursor = expanded_value_buffer.get_data(expanded_value_buffer.get_data_length());
   896 			if (cursor == 0)
       
   897 			{
       
   898 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   899 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   900 			}
       
   901 
       
   902 			const u8_t * const cursor_end = cursor + expanded_value_buffer.get_data_length();
   854 			const u8_t * const cursor_end = cursor + expanded_value_buffer.get_data_length();
   903 
   855 			
   904 			// Only one byte is needed. This is because coverity complains of using "u8_t hex_byte".
       
   905 			const u32_t BUFFER_SIZE=1ul;
       
   906 			u8_t hex_byte[BUFFER_SIZE];
       
   907 
       
   908 			while(cursor < cursor_end)
   856 			while(cursor < cursor_end)
   909 			{
   857 			{
       
   858 				u8_t hex_byte = 0;
   910 				cursor = read_hex_byte(
   859 				cursor = read_hex_byte(
   911 					cursor,
   860 					cursor,
   912 					cursor_end,
   861 					cursor_end,
   913 					hex_byte,
   862 					&hex_byte);
   914 					BUFFER_SIZE);
       
   915 				if (cursor == 0)
   863 				if (cursor == 0)
   916 				{
   864 				{
   917 					break;
   865 					break;
   918 				}
   866 				}
   919 
   867 
   920 				// Here we read only one byte.
   868 				status = value_data->add_data(&hex_byte, sizeof(hex_byte));
   921 				target[ind_target] = hex_byte[0];
   869 				if (status != eap_status_ok)
   922 				++ind_target;
   870 				{
   923 			}
   871 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   924 
   872 					return EAP_STATUS_RETURN(m_am_tools, status);
   925 			status = value_data->set_buffer_length(ind_target);
   873 				}
       
   874 			}
       
   875 		}
       
   876 		else if (type == eap_configure_type_u32array)
       
   877 		{
       
   878 			status = remove_spaces(&expanded_value_buffer);
   926 			if (status != eap_status_ok)
   879 			if (status != eap_status_ok)
   927 			{
   880 			{
   928 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   881 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
   929 				return EAP_STATUS_RETURN(m_am_tools, status);
   882 				return EAP_STATUS_RETURN(m_am_tools, status);
   930 			}
   883 			}
   931 		}
       
   932 		else if (type == eap_configure_type_u32array)
       
   933 		{
       
   934 			status = remove_spaces(&expanded_value_buffer);
       
   935 			if (status != eap_status_ok)
       
   936 			{
       
   937 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   938 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   939 			}
       
   940 			
   884 			
   941 			u8_t * cursor = expanded_value_buffer.get_data(expanded_value_buffer.get_data_length());
   885 			u8_t * cursor = expanded_value_buffer.get_data(expanded_value_buffer.get_data_length());
   942 			if (cursor == 0)
       
   943 			{
       
   944 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   945 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   946 			}
       
   947 
       
   948 			const u8_t * const cursor_end = cursor + expanded_value_buffer.get_data_length();
   886 			const u8_t * const cursor_end = cursor + expanded_value_buffer.get_data_length();
   949 			
   887 			
   950 			while(cursor < cursor_end)
   888 			while(cursor < cursor_end)
   951 			{
   889 			{
   952 				u32_t integer = 0;
   890 				u32_t integer = 0;
   976 }
   914 }
   977 
   915 
   978 
   916 
   979 //-----------------------------------------------------------------
   917 //-----------------------------------------------------------------
   980 
   918 
   981 eap_status_e eap_file_config_c::store_configure(
   919 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::store_configure(
   982 	abs_eap_am_file_input_c * const file,
   920 	abs_eap_am_file_input_c * const file,
   983 	const eap_variable_data_c * const line,
   921 	const eap_variable_data_c * const line,
   984 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map)
   922 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map)
   985 {
   923 {
   986 	eap_status_e status = eap_status_process_general_error;
   924 	eap_status_e status = eap_status_process_general_error;
  1322 			TRACE_FLAGS_DEFAULT, 
  1260 			TRACE_FLAGS_DEFAULT, 
  1323 			(EAPL("CONFIG: data"), 
  1261 			(EAPL("CONFIG: data"), 
  1324 			 config->get_data()->get_data(), 
  1262 			 config->get_data()->get_data(), 
  1325 			 config->get_data()->get_data_length()));
  1263 			 config->get_data()->get_data_length()));
  1326 
  1264 
  1327 		EAP_TRACE_DEBUG(
       
  1328 			m_am_tools,
       
  1329 			TRACE_FLAGS_DEFAULT,
       
  1330 			(EAPL("CONFIG: option type %d=%s\n"),
       
  1331 			 config->get_type(),
       
  1332 			 eap_configuration_field_c::get_configure_type_string(config->get_type())));
       
  1333 
       
  1334 		//-----------------------------------------------------------------------------
  1265 		//-----------------------------------------------------------------------------
  1335 
  1266 
  1336 	}
  1267 	}
  1337 
  1268 
  1338 	return EAP_STATUS_RETURN(m_am_tools, status);
  1269 	return EAP_STATUS_RETURN(m_am_tools, status);
  1481 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
  1412 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
  1482 }
  1413 }
  1483 
  1414 
  1484 //-----------------------------------------------------------------
  1415 //-----------------------------------------------------------------
  1485 
  1416 
  1486 eap_status_e eap_file_config_c::cnf_parse_value(
  1417 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::cnf_parse_value(
  1487 	const eap_variable_data_c * const found_type_value,
  1418 	const eap_variable_data_c * const found_type_value,
  1488 	const eap_variable_data_c * const found_type_name,
  1419 	const eap_variable_data_c * const found_type_name,
  1489 	eap_configure_type_e * const parsed_type,
  1420 	eap_configure_type_e * const parsed_type,
  1490 	eap_variable_data_c * const parsed_type_value,
  1421 	eap_variable_data_c * const parsed_type_value,
  1491 	const bool is_environment_variable)
  1422 	const bool is_environment_variable)
  1609 	if (status != eap_status_ok)
  1540 	if (status != eap_status_ok)
  1610 	{
  1541 	{
  1611 		return EAP_STATUS_RETURN(m_am_tools, status);
  1542 		return EAP_STATUS_RETURN(m_am_tools, status);
  1612 	}
  1543 	}
  1613 	
  1544 	
  1614 	EAP_TRACE_DEBUG(
       
  1615 		m_am_tools,
       
  1616 		TRACE_FLAGS_DEFAULT,
       
  1617 		(EAPL("\n")));
       
  1618 
       
  1619 	if (is_environment_variable == true)
  1545 	if (is_environment_variable == true)
  1620 	{
  1546 	{
  1621 		#if defined(EAP_FILE_CONFIG_USE_CONSOLE_PRINTS)
  1547 		#if defined(EAP_FILE_CONFIG_USE_CONSOLE_PRINTS)
  1622 			printf("CONFIG: %s=%s%s; from environment variable\n",
  1548 			printf("CONFIG: %s=%s%s; from environment variable\n",
  1623 				   found_type_name->get_data(found_type_name->get_data_length()),
  1549 				   found_type_name->get_data(found_type_name->get_data_length()),
  1650 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
  1576 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
  1651 }
  1577 }
  1652 
  1578 
  1653 //-----------------------------------------------------------------
  1579 //-----------------------------------------------------------------
  1654 
  1580 
  1655 eap_status_e eap_file_config_c::cnf_get_string(
  1581 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::cnf_get_string(
  1656 	const eap_variable_data_c * const param,
  1582 	const eap_variable_data_c * const param,
  1657 	eap_variable_data_c * const param_name,
  1583 	eap_variable_data_c * const param_name,
  1658 	eap_variable_data_c * const param_value,
  1584 	eap_variable_data_c * const param_value,
  1659 	eap_configure_type_e * const type)
  1585 	eap_configure_type_e * const type)
  1660 {
  1586 {
  1726 	return EAP_STATUS_RETURN(m_am_tools, status);
  1652 	return EAP_STATUS_RETURN(m_am_tools, status);
  1727 }
  1653 }
  1728 
  1654 
  1729 //-----------------------------------------------------------------
  1655 //-----------------------------------------------------------------
  1730 
  1656 
  1731 eap_status_e eap_file_config_c::read_subsections(
  1657 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::read_subsections(
  1732 	abs_eap_am_file_input_c * const file,
  1658 	abs_eap_am_file_input_c * const file,
  1733 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map)
  1659 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map)
  1734 {
  1660 {
  1735 	eap_variable_data_c line(m_am_tools);
  1661 	eap_variable_data_c line(m_am_tools);
  1736 	if (line.get_is_valid() == false)
  1662 	if (line.get_is_valid() == false)
  1762 	return EAP_STATUS_RETURN(m_am_tools, status);
  1688 	return EAP_STATUS_RETURN(m_am_tools, status);
  1763 }
  1689 }
  1764 
  1690 
  1765 //-----------------------------------------------------------------
  1691 //-----------------------------------------------------------------
  1766 
  1692 
  1767 eap_status_e eap_file_config_c::read_section(
  1693 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::read_section(
  1768 	abs_eap_am_file_input_c * const file,
  1694 	abs_eap_am_file_input_c * const file,
  1769 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map)
  1695 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map)
  1770 {
  1696 {
  1771 	eap_variable_data_c line(m_am_tools);
  1697 	eap_variable_data_c line(m_am_tools);
  1772 	if (line.get_is_valid() == false)
  1698 	if (line.get_is_valid() == false)
  1816 	return EAP_STATUS_RETURN(m_am_tools, status);
  1742 	return EAP_STATUS_RETURN(m_am_tools, status);
  1817 }
  1743 }
  1818 
  1744 
  1819 //-----------------------------------------------------------------
  1745 //-----------------------------------------------------------------
  1820 
  1746 
  1821 eap_status_e eap_file_config_c::remove_spaces(eap_variable_data_c * const buffer)
  1747 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::remove_spaces(eap_variable_data_c * const buffer)
  1822 {
  1748 {
  1823 	if (buffer == 0
  1749 	eap_variable_data_c tmp(m_am_tools);
  1824 		|| buffer->get_is_valid() == false)
  1750 	if (tmp.get_is_valid() == false)
  1825 	{
  1751 	{
  1826 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
  1752 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
  1827 	}
  1753 	}
  1828 
  1754 
  1829 	u32_t length = buffer->get_data_length();
  1755 	eap_status_e status(eap_status_ok);
  1830 	const u8_t * source = buffer->get_data(length);
  1756 
  1831 	u8_t * destination = buffer->get_data(length);
  1757 	for (u32_t ind = 0ul; ind < buffer->get_data_length(); ind++)
  1832 	u32_t ind_dest(0ul);
  1758 	{
  1833 
  1759 		u8_t * const character = buffer->get_data_offset(ind, sizeof(u8_t));
  1834 	for (u32_t ind = 0ul; ind < length; ind++)
  1760 		if (character == 0)
  1835 	{
  1761 		{
  1836 		const u8_t character = source[ind];
  1762 			return EAP_STATUS_RETURN(m_am_tools, status);
  1837 
  1763 		}
  1838 		if (m_am_tools->isspace(character) == false)
  1764 
  1839 		{
  1765 		if (m_am_tools->isspace(*character) == false)
  1840 			destination[ind_dest] = character;
  1766 		{
  1841 			++ind_dest;
  1767 			status = tmp.add_data(character, sizeof(*character));
       
  1768 			if (status != eap_status_ok)
       
  1769 			{
       
  1770 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  1771 			}
  1842 		}
  1772 		}
  1843 	} // for()
  1773 	} // for()
  1844 
  1774 
  1845 	eap_status_e status = buffer->set_data_length(ind_dest);
  1775 	status = buffer->set_copy_of_buffer(&tmp);
  1846 
  1776 
  1847 	return EAP_STATUS_RETURN(m_am_tools, status);
  1777 	return EAP_STATUS_RETURN(m_am_tools, status);
  1848 }
  1778 }
  1849 
  1779 
  1850 //-----------------------------------------------------------------
  1780 //-----------------------------------------------------------------
  1851 
  1781 
  1852 eap_status_e eap_file_config_c::remove_leading_spaces(
  1782 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::remove_leading_spaces(
  1853 	eap_variable_data_c * const line)
  1783 	eap_variable_data_c * const line)
  1854 {
  1784 {
  1855 	if (line->get_data_length() == 0)
  1785 	if (line->get_data_length() == 0)
  1856 	{
  1786 	{
  1857 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1787 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1882 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
  1812 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
  1883 }
  1813 }
  1884 
  1814 
  1885 //-----------------------------------------------------------------
  1815 //-----------------------------------------------------------------
  1886 
  1816 
  1887 eap_status_e eap_file_config_c::file_read_line(
  1817 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::file_read_line(
  1888 	abs_eap_am_file_input_c * const file,
  1818 	abs_eap_am_file_input_c * const file,
  1889 	eap_variable_data_c * const line)
  1819 	eap_variable_data_c * const line)
  1890 {
  1820 {
  1891 	eap_status_e status(eap_status_ok);
  1821 	eap_status_e status(eap_status_ok);
  1892 	bool line_continues(true);
  1822 	bool line_continues(true);
  1995 	return EAP_STATUS_RETURN(m_am_tools, status);
  1925 	return EAP_STATUS_RETURN(m_am_tools, status);
  1996 }
  1926 }
  1997 
  1927 
  1998 //-----------------------------------------------------------------
  1928 //-----------------------------------------------------------------
  1999 
  1929 
  2000 eap_status_e eap_file_config_c::get_subsect(
  1930 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::get_subsect(
  2001 	abs_eap_am_file_input_c * const file,
  1931 	abs_eap_am_file_input_c * const file,
  2002 	eap_variable_data_c * const line)
  1932 	eap_variable_data_c * const line)
  2003 {
  1933 {
  2004 	if( file == 0
  1934 	if( file == 0
  2005 		|| line == 0)
  1935 		|| line == 0)
  2070 	return EAP_STATUS_RETURN(m_am_tools, status);
  2000 	return EAP_STATUS_RETURN(m_am_tools, status);
  2071 }
  2001 }
  2072 
  2002 
  2073 //-----------------------------------------------------------------
  2003 //-----------------------------------------------------------------
  2074 
  2004 
  2075 eap_status_e eap_file_config_c::read_configure(
  2005 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::read_configure(
  2076 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
  2006 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
  2077 	const eap_configuration_field_c * const field,
  2007 	const eap_configuration_field_c * const field,
  2078 	eap_variable_data_c* const data,
  2008 	eap_variable_data_c* const data,
  2079 	eap_configure_type_e * const configuration_data_type,
  2009 	eap_configure_type_e * const configuration_data_type,
  2080 	const bool existence_test)
  2010 	const bool existence_test)
  2131 	return status; // Here EAP_STATUS_RETURN() macro is too noisy.
  2061 	return status; // Here EAP_STATUS_RETURN() macro is too noisy.
  2132 }
  2062 }
  2133 
  2063 
  2134 //-----------------------------------------------------------------
  2064 //-----------------------------------------------------------------
  2135 
  2065 
  2136 eap_status_e eap_file_config_c::read_all_configurations(
  2066 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::read_configure(
  2137 	const eap_configuration_field_c * const /* field */,
       
  2138 	eap_variable_data_c* const data,
       
  2139 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map)
       
  2140 {
       
  2141 	eap_status_e status = eap_status_process_general_error;
       
  2142 
       
  2143 	/**
       
  2144 	 * Here is a figure of message data composed of Attribute-Value Pairs (See eap_tlv_header_c).
       
  2145 	 * Value data follows eap_tlv_message_data_c.
       
  2146 	 * @code
       
  2147 	 *  Configuration data:
       
  2148 	 *  0                   1                   2                   3   
       
  2149 	 *  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 
       
  2150 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -+
       
  2151 	 * |       Type = eap_tlv_message_type_configuration_option        |  |
       
  2152 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2153 	 * |                             Length = 8+4+8+m+8+n              |  |
       
  2154 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2155 	 * |       Type = eap_tlv_message_type_u32_t                       |  |
       
  2156 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2157 	 * |                             Length = 4                        |  |
       
  2158 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2159 	 * |          option type eap_configure_type_hex_data              |  |
       
  2160 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2161 	 * |       Type = eap_tlv_message_type_variable_data               |  |
       
  2162 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  | First configuration option
       
  2163 	 * |                             Length = m                        |  |
       
  2164 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2165 	 * |               Value (m octets) option name                    |  |
       
  2166 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2167 	 * |       Type = eap_tlv_message_type_variable_data               |  |
       
  2168 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2169 	 * |                             Length = n                        |  |
       
  2170 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2171 	 * |               Value (n octets) option data                    |  |
       
  2172 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -+
       
  2173 	 * |       Type = eap_tlv_message_type_configuration_option        |  |
       
  2174 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2175 	 * |                             Length = 8+4+8+m+8+4              |  |
       
  2176 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2177 	 * |       Type = eap_tlv_message_type_u32_t                       |  |
       
  2178 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2179 	 * |                             Length = 4                        |  |
       
  2180 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2181 	 * |          option type  eap_configure_type_u32_t                |  |
       
  2182 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2183 	 * |       Type = eap_tlv_message_type_variable_data               |  |
       
  2184 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  | Second configuration option
       
  2185 	 * |                             Length = m                        |  |
       
  2186 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2187 	 * |               Value (m octets) option name                    |  |
       
  2188 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2189 	 * |       Type = eap_tlv_message_type_u32_t                       |  |
       
  2190 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2191 	 * |                             Length = 4                        |  |
       
  2192 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+  |
       
  2193 	 * |               Value option data 32-bit integer                |  |
       
  2194 	 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -+
       
  2195 	 *
       
  2196 	 * @endcode
       
  2197 	 * 
       
  2198 	 */
       
  2199 
       
  2200 	u32_t size_of_data(0ul);
       
  2201 	u32_t ind(0ul);
       
  2202 
       
  2203 	eap_process_tlv_message_data_c message(m_am_tools);
       
  2204 
       
  2205 	if (message.get_is_valid() == false)
       
  2206 	{
       
  2207 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2208 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  2209 	}
       
  2210 
       
  2211 	for (ind = 0ul; ind < config_map->get_atom_count(); ++ind)
       
  2212 	{
       
  2213 		const eap_state_map_atom_c<eap_config_value_c, eap_variable_data_c> * atom = config_map->get_atom(ind);
       
  2214 		while (atom != 0)
       
  2215 		{
       
  2216 			u32_t size = message.get_payload_size(
       
  2217 					atom->get_selector(),
       
  2218 					atom->get_const_object());
       
  2219 
       
  2220 			if (size > 0ul)
       
  2221 			{
       
  2222 				// The extra size of header is added because the whole allocated message size includes all headers.
       
  2223 				// The get_payload_size() function calculates only payload of the option without the main header.
       
  2224 				size_of_data +=
       
  2225 					size
       
  2226 					+ eap_tlv_header_c::get_header_length();
       
  2227 			}
       
  2228 			else
       
  2229 			{
       
  2230 				// Some konfiguration objects are not included to message yet.
       
  2231 			}
       
  2232 
       
  2233 			atom = atom->get_next_atom();
       
  2234 		}
       
  2235 	}
       
  2236 
       
  2237 	EAP_TRACE_DEBUG(
       
  2238 		m_am_tools,
       
  2239 		TRACE_FLAGS_DEFAULT,
       
  2240 		(EAPL("CONFIG: data size %d\n"),
       
  2241 		 size_of_data));
       
  2242 
       
  2243 	status = message.allocate_message_data_buffer(size_of_data);
       
  2244 	if (status != eap_status_ok)
       
  2245 	{
       
  2246 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2247 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2248 	}
       
  2249 
       
  2250 
       
  2251 	for (ind = 0ul; ind < config_map->get_atom_count(); ++ind)
       
  2252 	{
       
  2253 		const eap_state_map_atom_c<eap_config_value_c, eap_variable_data_c> * atom = config_map->get_atom(ind);
       
  2254 		while (atom != 0)
       
  2255 		{
       
  2256 			status = message.add_parameter_data(atom->get_selector(), atom->get_const_object());
       
  2257 			if (status != eap_status_ok)
       
  2258 			{
       
  2259 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2260 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2261 			}
       
  2262 
       
  2263 			atom = atom->get_next_atom();
       
  2264 		}
       
  2265 	}
       
  2266 
       
  2267 	status = data->set_copy_of_buffer(
       
  2268 		message.get_message_data(),
       
  2269 		message.get_message_data_length());
       
  2270 	if (status != eap_status_ok)
       
  2271 	{
       
  2272 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2273 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2274 	}
       
  2275 
       
  2276 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2277 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2278 }
       
  2279 
       
  2280 //-----------------------------------------------------------------
       
  2281 
       
  2282 eap_status_e eap_file_config_c::add_option(
       
  2283 	const eap_tlv_header_c * const option_header)
       
  2284 {
       
  2285 	eap_status_e status = eap_status_process_general_error;
       
  2286 
       
  2287 	eap_process_tlv_message_data_c message(m_am_tools);
       
  2288 
       
  2289 	if (message.get_is_valid() == false)
       
  2290 	{
       
  2291 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2292 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2293 	}
       
  2294 
       
  2295 	status = message.set_message_data(option_header->get_value_length(), option_header->get_value(option_header->get_value_length()));
       
  2296 	if (status != eap_status_ok)
       
  2297 	{
       
  2298 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2299 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2300 	}
       
  2301 
       
  2302 	eap_array_c<eap_tlv_header_c> parameters(m_am_tools);
       
  2303 
       
  2304 	status = message.parse_message_data(&parameters);
       
  2305 	if (status != eap_status_ok)
       
  2306 	{
       
  2307 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2308 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2309 	}
       
  2310 
       
  2311 	eap_config_value_c * config = new eap_config_value_c(m_am_tools);
       
  2312 
       
  2313 	eap_automatic_variable_c<eap_config_value_c>
       
  2314 		automatic_config(m_am_tools, config);
       
  2315 
       
  2316 	if (config == 0
       
  2317 		|| config->get_is_valid() == false)
       
  2318 	{
       
  2319 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  2320 	}
       
  2321 
       
  2322 	u32_t parameter_index(0ul);
       
  2323 
       
  2324 	eap_variable_data_c selector(m_am_tools);
       
  2325 	if (selector.get_is_valid() == false)
       
  2326 	{
       
  2327 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  2328 	}
       
  2329 
       
  2330 	{
       
  2331 		const eap_tlv_header_c * const a_option_header = parameters.get_object(parameter_index);
       
  2332 		if (a_option_header == 0
       
  2333 			|| a_option_header->get_type() != eap_tlv_message_type_u32_t)
       
  2334 		{
       
  2335 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2336 
       
  2337 			status = eap_status_illegal_parameter;
       
  2338 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2339 		}
       
  2340 
       
  2341 		u32_t value(0ul);
       
  2342 
       
  2343 		status = message.get_parameter_data(
       
  2344 			a_option_header,
       
  2345 			&value);
       
  2346 		if (status != eap_status_ok)
       
  2347 		{
       
  2348 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2349 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2350 		}
       
  2351 
       
  2352 		config->set_type(static_cast<eap_configure_type_e>(value));
       
  2353 	}
       
  2354 
       
  2355 	++parameter_index;
       
  2356 	
       
  2357 	{
       
  2358 		const eap_tlv_header_c * const a_option_header = parameters.get_object(parameter_index);
       
  2359 		if (a_option_header == 0
       
  2360 			|| a_option_header->get_type() != eap_tlv_message_type_variable_data)
       
  2361 		{
       
  2362 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2363 
       
  2364 			status = eap_status_illegal_parameter;
       
  2365 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2366 		}
       
  2367 
       
  2368 		status = message.get_parameter_data(
       
  2369 			a_option_header,
       
  2370 			&selector);
       
  2371 		if (status != eap_status_ok)
       
  2372 		{
       
  2373 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2374 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2375 		}
       
  2376 	}
       
  2377 	
       
  2378 	++parameter_index;
       
  2379 
       
  2380 	switch(config->get_type())
       
  2381 	{
       
  2382 	case eap_configure_type_string:
       
  2383 	case eap_configure_type_hex_data:
       
  2384 		{
       
  2385 			const eap_tlv_header_c * const a_option_header = parameters.get_object(parameter_index);
       
  2386 			if (a_option_header == 0
       
  2387 				|| a_option_header->get_type() != eap_tlv_message_type_variable_data)
       
  2388 			{
       
  2389 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2390 
       
  2391 				status = eap_status_illegal_parameter;
       
  2392 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2393 			}
       
  2394 
       
  2395 			status = message.get_parameter_data(
       
  2396 				a_option_header,
       
  2397 				config->get_data());
       
  2398 			if (status != eap_status_ok)
       
  2399 			{
       
  2400 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2401 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2402 			}
       
  2403 		}
       
  2404 		break;
       
  2405 	case eap_configure_type_u32_t:
       
  2406 	case eap_configure_type_boolean:
       
  2407 		{
       
  2408 			const eap_tlv_header_c * const a_option_header = parameters.get_object(parameter_index);
       
  2409 			if (a_option_header == 0
       
  2410 				|| a_option_header->get_type() != eap_tlv_message_type_u32_t)
       
  2411 			{
       
  2412 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2413 
       
  2414 				status = eap_status_illegal_parameter;
       
  2415 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2416 			}
       
  2417 
       
  2418 			u32_t value(0ul);
       
  2419 
       
  2420 			status = message.get_parameter_data(
       
  2421 				a_option_header,
       
  2422 				&value);
       
  2423 			if (status != eap_status_ok)
       
  2424 			{
       
  2425 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2426 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2427 			}
       
  2428 
       
  2429 			status = config->get_data()->set_copy_of_buffer(&value, sizeof(value));
       
  2430 			if (status != eap_status_ok)
       
  2431 			{
       
  2432 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2433 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2434 			}
       
  2435 		}
       
  2436 		break;
       
  2437 	case eap_configure_type_u32array:
       
  2438 		{
       
  2439 			const eap_tlv_header_c * const a_option_header = parameters.get_object(parameter_index);
       
  2440 			if (a_option_header == 0
       
  2441 				|| a_option_header->get_type() != eap_tlv_message_type_array)
       
  2442 			{
       
  2443 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2444 
       
  2445 				status = eap_status_illegal_parameter;
       
  2446 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2447 			}
       
  2448 
       
  2449 			eap_process_tlv_message_data_c array_message(m_am_tools);
       
  2450 
       
  2451 			if (array_message.get_is_valid() == false)
       
  2452 			{
       
  2453 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2454 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2455 			}
       
  2456 
       
  2457 			status = array_message.set_message_data(a_option_header->get_value_length(), a_option_header->get_value(a_option_header->get_value_length()));
       
  2458 			if (status != eap_status_ok)
       
  2459 			{
       
  2460 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2461 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2462 			}
       
  2463 
       
  2464 			eap_array_c<eap_tlv_header_c> array_parameters(m_am_tools);
       
  2465 
       
  2466 			status = array_message.parse_message_data(&array_parameters);
       
  2467 			if (status != eap_status_ok)
       
  2468 			{
       
  2469 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2470 				return EAP_STATUS_RETURN(m_am_tools, status);
       
  2471 			}
       
  2472 
       
  2473 			for (u32_t ind = 0ul; ind < array_parameters.get_object_count(); ++ind)
       
  2474 			{
       
  2475 				const eap_tlv_header_c * const a_option_header = array_parameters.get_object(ind);
       
  2476 				if (a_option_header == 0
       
  2477 					|| a_option_header->get_type() != eap_tlv_message_type_u32_t)
       
  2478 				{
       
  2479 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2480 
       
  2481 					status = eap_status_illegal_parameter;
       
  2482 					return EAP_STATUS_RETURN(m_am_tools, status);
       
  2483 				}
       
  2484 
       
  2485 				u32_t value(0ul);
       
  2486 
       
  2487 				status = array_message.get_parameter_data(
       
  2488 					a_option_header,
       
  2489 					&value);
       
  2490 				if (status != eap_status_ok)
       
  2491 				{
       
  2492 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2493 					return EAP_STATUS_RETURN(m_am_tools, status);
       
  2494 				}
       
  2495 
       
  2496 				status = config->get_data()->add_data(&value, sizeof(value));
       
  2497 				if (status != eap_status_ok)
       
  2498 				{
       
  2499 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2500 					return EAP_STATUS_RETURN(m_am_tools, status);
       
  2501 				}
       
  2502 			}
       
  2503 		}
       
  2504 		break;
       
  2505 	default:
       
  2506 		break;
       
  2507 	};
       
  2508 
       
  2509 	status = m_config_map.add_handler(&selector, config);
       
  2510 	if (status == eap_status_ok)
       
  2511 	{
       
  2512 		automatic_config.do_not_free_variable();
       
  2513 	}
       
  2514 	else //if (status != eap_status_ok)
       
  2515 	{
       
  2516 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2517 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2518 	}
       
  2519 
       
  2520 	EAP_TRACE_DEBUG(
       
  2521 		m_am_tools,
       
  2522 		TRACE_FLAGS_DEFAULT,
       
  2523 		(EAPL("\n")));
       
  2524 
       
  2525 	EAP_TRACE_DATA_DEBUG(
       
  2526 		m_am_tools,
       
  2527 		TRACE_FLAGS_DEFAULT,
       
  2528 		(EAPL("CONFIG MESSAGE: option added"),
       
  2529 		 selector.get_data(),
       
  2530 		 selector.get_data_length()));
       
  2531 	
       
  2532 	EAP_TRACE_DATA_DEBUG(
       
  2533 		m_am_tools, 
       
  2534 		TRACE_FLAGS_DEFAULT, 
       
  2535 		(EAPL("CONFIG MESSAGE: data"), 
       
  2536 		 config->get_data()->get_data(), 
       
  2537 		 config->get_data()->get_data_length()));
       
  2538 
       
  2539 	EAP_TRACE_DEBUG(
       
  2540 		m_am_tools,
       
  2541 		TRACE_FLAGS_DEFAULT,
       
  2542 		(EAPL("CONFIG MESSAGE: option type %d=%s\n"),
       
  2543 		 config->get_type(),
       
  2544 		 eap_configuration_field_c::get_configure_type_string(config->get_type())));
       
  2545 
       
  2546 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2547 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2548 }
       
  2549 
       
  2550 //-----------------------------------------------------------------
       
  2551 
       
  2552 EAP_FUNC_EXPORT eap_status_e eap_file_config_c::read_configuration_message(
       
  2553 	const eap_variable_data_c * const configuration_message)
       
  2554 {
       
  2555 	EAP_TRACE_DEBUG(
       
  2556 		m_am_tools,
       
  2557 		TRACE_FLAGS_DEFAULT,
       
  2558 		(EAPL("eap_file_config_c::read_configuration_message(): data=0x%08x, length=%d\n"),
       
  2559 		configuration_message->get_data(),
       
  2560 		configuration_message->get_data_length()));
       
  2561 
       
  2562 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_file_config_c::read_configuration_message()");
       
  2563 
       
  2564 	eap_status_e status = eap_status_process_general_error;
       
  2565 
       
  2566 	eap_process_tlv_message_data_c message(m_am_tools);
       
  2567 
       
  2568 	if (message.get_is_valid() == false)
       
  2569 	{
       
  2570 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2571 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2572 	}
       
  2573 
       
  2574 	status = message.set_message_data(configuration_message->get_data_length(), configuration_message->get_data());
       
  2575 	if (status != eap_status_ok)
       
  2576 	{
       
  2577 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2578 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2579 	}
       
  2580 
       
  2581 	eap_array_c<eap_tlv_header_c> parameters(m_am_tools);
       
  2582 
       
  2583 	status = message.parse_message_data(&parameters);
       
  2584 	if (status != eap_status_ok)
       
  2585 	{
       
  2586 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2587 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  2588 	}
       
  2589 
       
  2590 	for (u32_t ind = 0ul; ind < parameters.get_object_count(); ++ind)
       
  2591 	{
       
  2592 		const eap_tlv_header_c * const option_header = parameters.get_object(ind);
       
  2593 		if (option_header == 0
       
  2594 			|| option_header->get_type() != eap_tlv_message_type_configuration_option)
       
  2595 		{
       
  2596 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2597 
       
  2598 			status = eap_status_illegal_parameter;
       
  2599 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2600 		}
       
  2601 
       
  2602 		status = add_option(option_header);
       
  2603 		if (status != eap_status_ok)
       
  2604 		{
       
  2605 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2606 			return EAP_STATUS_RETURN(m_am_tools, status);
       
  2607 		}
       
  2608 	}
       
  2609 
       
  2610 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  2611 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  2612 }
       
  2613 
       
  2614 //-----------------------------------------------------------------
       
  2615 
       
  2616 eap_status_e eap_file_config_c::read_configure(
       
  2617 	const eap_configuration_field_c * const field,
  2067 	const eap_configuration_field_c * const field,
  2618 	eap_variable_data_c* const data,
  2068 	eap_variable_data_c* const data,
  2619 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
  2069 	eap_core_map_c<eap_config_value_c, abs_eap_core_map_c, eap_variable_data_c> * const config_map,
  2620 	const bool check_subsection_when_true)
  2070 	const bool check_subsection_when_true)
  2621 {
  2071 {
  2709 			if (field->get_type() != config->get_type())
  2159 			if (field->get_type() != config->get_type())
  2710 			{
  2160 			{
  2711 				EAP_TRACE_DEBUG(
  2161 				EAP_TRACE_DEBUG(
  2712 					m_am_tools,
  2162 					m_am_tools,
  2713 					TRACE_FLAGS_DEFAULT,
  2163 					TRACE_FLAGS_DEFAULT,
  2714 					(EAPL("WARNING: CONFIG: option type failed: required %d=%s != actual %d=%s\n"),
  2164 					(EAPL("WARNING: CONFIG: option type failed: required %d != actual %d\n"),
  2715 					 field->get_type(),
  2165 					 field->get_type(),
  2716 					 eap_configuration_field_c::get_configure_type_string(field->get_type()),
  2166 					 config->get_type()));
  2717 					 config->get_type(),
       
  2718 					 eap_configuration_field_c::get_configure_type_string(config->get_type())));
       
  2719 				EAP_TRACE_DEBUG(
  2167 				EAP_TRACE_DEBUG(
  2720 					m_am_tools,
  2168 					m_am_tools,
  2721 					TRACE_FLAGS_DEFAULT,
  2169 					TRACE_FLAGS_DEFAULT,
  2722 					(EAPL("WARNING: CONFIG: rear option type failed: %s\n"),
  2170 					(EAPL("WARNING: CONFIG: rear option type failed: %s\n"),
  2723 					 field->get_field()));
  2171 					 field->get_field()));
  2746 				m_am_tools,
  2194 				m_am_tools,
  2747 				TRACE_FLAGS_DEFAULT,
  2195 				TRACE_FLAGS_DEFAULT,
  2748 				(EAPL("WARNING: CONFIG: option not found"),
  2196 				(EAPL("WARNING: CONFIG: option not found"),
  2749 				 field->get_field(),
  2197 				 field->get_field(),
  2750 				 field->get_field_length()));
  2198 				 field->get_field_length()));
  2751 			EAP_TRACE_DEBUG(
       
  2752 				m_am_tools,
       
  2753 				TRACE_FLAGS_DEFAULT,
       
  2754 				(EAPL("WARNING: CONFIG: option type %d=%s\n"),
       
  2755 				 field->get_type(),
       
  2756 				 eap_configuration_field_c::get_configure_type_string(field->get_type())));
       
  2757 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  2199 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  2758 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_configure_field);
  2200 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_configure_field);
  2759 		}
  2201 		}
  2760 
  2202 
  2761 	}
  2203 	}
  2775 		TRACE_FLAGS_DEFAULT,
  2217 		TRACE_FLAGS_DEFAULT,
  2776 		(EAPL("eap_file_config_c::read_configure()"),
  2218 		(EAPL("eap_file_config_c::read_configure()"),
  2777 		 field->get_field(),
  2219 		 field->get_field(),
  2778 		 field->get_field_length()));
  2220 		 field->get_field_length()));
  2779 
  2221 
  2780 	eap_status_e status(eap_status_process_general_error);
  2222 	eap_status_e status = read_configure(
  2781 
  2223 		field,
  2782 	if (field->get_type() == eap_configure_type_all_configurations
  2224 		data,
  2783 		&& field->compare(
  2225 		&m_config_map,
  2784 			m_am_tools,
  2226 		true);
  2785 			cf_str_EAP_read_all_configurations.get_field()) == true)
       
  2786 	{
       
  2787 		status = read_all_configurations(
       
  2788 			field,
       
  2789 			data,
       
  2790 			&m_config_map);
       
  2791 	}
       
  2792 	else
       
  2793 	{
       
  2794 		status = read_configure(
       
  2795 			field,
       
  2796 			data,
       
  2797 			&m_config_map,
       
  2798 			true);
       
  2799 	}
       
  2800 
  2227 
  2801 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  2228 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  2802 	return EAP_STATUS_RETURN(m_am_tools, status);
  2229 	return EAP_STATUS_RETURN(m_am_tools, status);
  2803 }
  2230 }
  2804 
  2231