eapol/eapol_framework/eapol_common/am/include/eap_am_tools.h
changeset 49 43351a4f2da3
parent 36 c98682f98478
equal deleted inserted replaced
47:712b4ffd76bb 49:43351a4f2da3
    25 #include "abs_eap_am_tools.h"
    25 #include "abs_eap_am_tools.h"
    26 #include "eap_variable_data.h"
    26 #include "eap_variable_data.h"
    27 #include "eap_tools.h"
    27 #include "eap_tools.h"
    28 #include "eap_status.h"
    28 #include "eap_status.h"
    29 #include "eap_am_export.h"
    29 #include "eap_am_export.h"
       
    30 // Start: added by script change_export_macros.sh.
       
    31 #if defined(EAP_NO_EXPORT_EAP_AM_TOOLS_H)
       
    32 	#define EAP_CLASS_VISIBILITY_EAP_AM_TOOLS_H EAP_NONSHARABLE 
       
    33 	#define EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H 
       
    34 	#define EAP_C_FUNC_VISIBILITY_EAP_AM_TOOLS_H 
       
    35 	#define EAP_FUNC_EXPORT_EAP_AM_TOOLS_H 
       
    36 	#define EAP_C_FUNC_EXPORT_EAP_AM_TOOLS_H 
       
    37 #elif defined(EAP_EXPORT_EAP_AM_TOOLS_H)
       
    38 	#define EAP_CLASS_VISIBILITY_EAP_AM_TOOLS_H EAP_EXPORT 
       
    39 	#define EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H EAP_FUNC_EXPORT 
       
    40 	#define EAP_C_FUNC_VISIBILITY_EAP_AM_TOOLS_H EAP_C_FUNC_EXPORT 
       
    41 	#define EAP_FUNC_EXPORT_EAP_AM_TOOLS_H EAP_FUNC_EXPORT 
       
    42 	#define EAP_C_FUNC_EXPORT_EAP_AM_TOOLS_H EAP_C_FUNC_EXPORT 
       
    43 #else
       
    44 	#define EAP_CLASS_VISIBILITY_EAP_AM_TOOLS_H EAP_IMPORT 
       
    45 	#define EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H EAP_FUNC_IMPORT 
       
    46 	#define EAP_C_FUNC_VISIBILITY_EAP_AM_TOOLS_H EAP_C_FUNC_IMPORT 
       
    47 	#define EAP_FUNC_EXPORT_EAP_AM_TOOLS_H 
       
    48 	#define EAP_C_FUNC_EXPORT_EAP_AM_TOOLS_H 
       
    49 #endif
       
    50 // End: added by script change_export_macros.sh.
    30 #include "eap_status_string.h"
    51 #include "eap_status_string.h"
    31 #include "abs_eap_am_memory_store_data.h"
    52 #include "abs_eap_am_memory_store_data.h"
    32 
    53 
    33 
    54 
    34 //#if !defined(NO_EAP_AM_MEMORY_STORE)
    55 //#if !defined(NO_EAP_AM_MEMORY_STORE)
    37 //#endif //#if !defined(NO_EAP_AM_MEMORY_STORE)
    58 //#endif //#if !defined(NO_EAP_AM_MEMORY_STORE)
    38 
    59 
    39 
    60 
    40 /// This class defines the common functions of tools.
    61 /// This class defines the common functions of tools.
    41 /// These are the platform independent functions used in tools.
    62 /// These are the platform independent functions used in tools.
    42 class EAP_EXPORT eap_am_tools_c
    63 class EAP_CLASS_VISIBILITY_EAP_AM_TOOLS_H eap_am_tools_c
    43 : public abs_eap_am_tools_c
    64 : public abs_eap_am_tools_c
    44 //#if !defined(NO_EAP_AM_MEMORY_STORE)
    65 //#if !defined(NO_EAP_AM_MEMORY_STORE)
    45 , public abs_eap_am_memory_store_data_c
    66 , public abs_eap_am_memory_store_data_c
    46 //#endif //#if !defined(NO_EAP_AM_MEMORY_STORE)
    67 //#endif //#if !defined(NO_EAP_AM_MEMORY_STORE)
    47 {
    68 {
    75 	u8_t m_tmp_buffer[256];
    96 	u8_t m_tmp_buffer[256];
    76 	
    97 	
    77 	u8_t m_tmp_ascii_buffer[256];
    98 	u8_t m_tmp_ascii_buffer[256];
    78 
    99 
    79 
   100 
    80 	EAP_FUNC_IMPORT u8_t octet_to_ascii_armor(
   101 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H u8_t octet_to_ascii_armor(
    81 		const u8_t source_byte);
   102 		const u8_t source_byte);
    82 
   103 
    83 	EAP_FUNC_IMPORT u8_t octet_from_ascii_armor(
   104 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H u8_t octet_from_ascii_armor(
    84 		const u8_t source_byte);
   105 		const u8_t source_byte);
    85 
   106 
    86 	EAP_FUNC_IMPORT void convert_selected_bytes_to_ascii_armor(
   107 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H void convert_selected_bytes_to_ascii_armor(
    87 		const u8_t source_byte,
   108 		const u8_t source_byte,
    88 		u32_t * const saved_bit_count,
   109 		u32_t * const saved_bit_count,
    89 		u8_t * const saved_bits,
   110 		u8_t * const saved_bits,
    90 		u8_t * const target,
   111 		u8_t * const target,
    91 		u32_t * const output_ind,
   112 		u32_t * const output_ind,
    92 		const bool last_input_byte);
   113 		const bool last_input_byte);
    93 
   114 
    94 	EAP_FUNC_IMPORT void restore_selected_bytes_from_ascii_armor(
   115 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H void restore_selected_bytes_from_ascii_armor(
    95 		const u8_t source_byte,
   116 		const u8_t source_byte,
    96 		u32_t * const missing_bit_count,
   117 		u32_t * const missing_bit_count,
    97 		u8_t * const target,
   118 		u8_t * const target,
    98 		u32_t * const output_ind,
   119 		u32_t * const output_ind,
    99 		const bool last_input_byte);
   120 		const bool last_input_byte);
   121 		eap_trace_mask_timer_queue        = (1u << 14u), ///< This value traces the timer queue.
   142 		eap_trace_mask_timer_queue        = (1u << 14u), ///< This value traces the timer queue.
   122 		eap_trace_mask_ok_returns         = (1u << 15u), ///< This value traces the OK return values, alot of them.
   143 		eap_trace_mask_ok_returns         = (1u << 15u), ///< This value traces the OK return values, alot of them.
   123 		eap_trace_mask_trace_never        = (1u << 16u), ///< This value never traces. This can disable trace always.
   144 		eap_trace_mask_trace_never        = (1u << 16u), ///< This value never traces. This can disable trace always.
   124 	};
   145 	};
   125 
   146 
   126 	EAP_FUNC_IMPORT u8_t octet_to_ascii(i32_t octet);
   147 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H u8_t octet_to_ascii(i32_t octet);
   127 
   148 
   128 	EAP_FUNC_IMPORT u8_t ascii_to_octet(i32_t character);
   149 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H u8_t ascii_to_octet(i32_t character);
   129 
   150 
   130 	EAP_FUNC_IMPORT virtual ~eap_am_tools_c();
   151 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H virtual ~eap_am_tools_c();
   131 
   152 
   132 	EAP_FUNC_IMPORT eap_am_tools_c();
   153 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_am_tools_c();
   133 
   154 
   134 	EAP_FUNC_IMPORT bool get_use_seconds_timestamp_in_traces();
   155 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H bool get_use_seconds_timestamp_in_traces();
   135 
   156 
   136 	EAP_FUNC_IMPORT bool get_thread_stopped();
   157 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H bool get_thread_stopped();
   137 
   158 
   138 	EAP_FUNC_IMPORT void set_use_timer_queue();
   159 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H void set_use_timer_queue();
   139 
   160 
   140 	EAP_FUNC_IMPORT bool get_use_timer_queue();
   161 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H bool get_use_timer_queue();
   141 
   162 
   142 	EAP_FUNC_IMPORT u32_t get_trace_mask() const;
   163 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H u32_t get_trace_mask() const;
   143 
   164 
   144 	EAP_FUNC_IMPORT void set_trace_mask(const u32_t mask);
   165 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H void set_trace_mask(const u32_t mask);
   145 
   166 
   146 	EAP_FUNC_IMPORT void set_activate_trace_on_error();
   167 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H void set_activate_trace_on_error();
   147 
   168 
   148 	EAP_FUNC_IMPORT void check_activate_trace_on_error();
   169 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H void check_activate_trace_on_error();
   149 
   170 
   150 	EAP_FUNC_IMPORT void trace_data(eap_const_string prefix, const void * const data, const u32_t data_length);
   171 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H void trace_data(eap_const_string prefix, const void * const data, const u32_t data_length);
   151 
   172 
   152 	EAP_FUNC_IMPORT eap_status_e timer_thread_function();
   173 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e timer_thread_function();
   153 
   174 
   154 	EAP_FUNC_IMPORT eap_status_e convert_ascii_to_uppercase(
   175 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e convert_ascii_to_uppercase(
   155 		u8_t * const source_bytes,
   176 		u8_t * const source_bytes,
   156 		const u32_t source_bytes_length);
   177 		const u32_t source_bytes_length);
   157 
   178 
   158 	EAP_FUNC_IMPORT eap_status_e convert_bytes_to_hex_ascii(
   179 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e convert_bytes_to_hex_ascii(
   159 		const u8_t * const source_bytes,
   180 		const u8_t * const source_bytes,
   160 		const u32_t source_bytes_length,
   181 		const u32_t source_bytes_length,
   161 		u8_t * const target,
   182 		u8_t * const target,
   162 		u32_t *target_length);
   183 		u32_t *target_length);
   163 
   184 
   164 	EAP_FUNC_IMPORT eap_status_e convert_bytes_to_hex_ascii(
   185 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e convert_bytes_to_hex_ascii(
   165 		const void * const source_bytes,
   186 		const void * const source_bytes,
   166 		const u32_t source_bytes_length,
   187 		const u32_t source_bytes_length,
   167 		eap_variable_data_c * const target);
   188 		eap_variable_data_c * const target);
   168 
   189 
   169 	EAP_FUNC_IMPORT eap_status_e convert_hex_ascii_to_bytes(
   190 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e convert_hex_ascii_to_bytes(
   170 		const u8_t * const source_bytes,
   191 		const u8_t * const source_bytes,
   171 		const u32_t source_bytes_length,
   192 		const u32_t source_bytes_length,
   172 		u8_t * const target,
   193 		u8_t * const target,
   173 		u32_t *target_length);
   194 		u32_t *target_length);
   174 
   195 
   175 	EAP_FUNC_IMPORT eap_status_e convert_hex_ascii_to_bytes(
   196 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e convert_hex_ascii_to_bytes(
   176 		const void * const source_bytes,
   197 		const void * const source_bytes,
   177 		const u32_t source_bytes_length,
   198 		const u32_t source_bytes_length,
   178 		eap_variable_data_c * const target);
   199 		eap_variable_data_c * const target);
   179 
   200 
   180 	
   201 	
   181 	EAP_FUNC_IMPORT eap_status_e convert_bytes_to_ascii_armor(
   202 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e convert_bytes_to_ascii_armor(
   182 		const u8_t * const source_bytes,
   203 		const u8_t * const source_bytes,
   183 		const u32_t source_bytes_length,
   204 		const u32_t source_bytes_length,
   184 		u8_t * const target,
   205 		u8_t * const target,
   185 		u32_t *target_length);
   206 		u32_t *target_length);
   186 
   207 
   187 	EAP_FUNC_IMPORT eap_status_e restore_bytes_from_ascii_armor(
   208 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e restore_bytes_from_ascii_armor(
   188 		const u8_t * const source_bytes,
   209 		const u8_t * const source_bytes,
   189 		const u32_t source_bytes_length,
   210 		const u32_t source_bytes_length,
   190 		u8_t * const target,
   211 		u8_t * const target,
   191 		u32_t *target_length);
   212 		u32_t *target_length);
   192 
   213 
   193 	EAP_FUNC_IMPORT eap_status_e eap_status_return(
   214 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e eap_status_return(
   194 		const bool print_error_when_true,
   215 		const bool print_error_when_true,
   195 		const eap_status_e status,
   216 		const eap_status_e status,
   196 		const eap_char * const file_name,
   217 		const eap_char * const file_name,
   197 		const i32_t line_number);
   218 		const i32_t line_number);
   198 
   219 
   199 	EAP_FUNC_IMPORT eap_status_e eap_status_return_file_number(
   220 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e eap_status_return_file_number(
   200 		const bool print_error_when_true,
   221 		const bool print_error_when_true,
   201 		const eap_status_e status,
   222 		const eap_status_e status,
   202 		const u32_t file_date,
   223 		const u32_t file_date,
   203 		const u32_t file_number,
   224 		const u32_t file_number,
   204 		const i32_t line_number);
   225 		const i32_t line_number);
   205 
   226 
   206 
   227 
   207 	// This is documented in abs_eap_am_tools_c::memory_store_add_data().
   228 	// This is documented in abs_eap_am_tools_c::memory_store_add_data().
   208 	EAP_FUNC_IMPORT eap_status_e memory_store_add_data(
   229 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e memory_store_add_data(
   209 		const eap_variable_data_c * const key,
   230 		const eap_variable_data_c * const key,
   210 		eap_tlv_message_data_c * const data,
   231 		eap_tlv_message_data_c * const data,
   211 		const u32_t timeout);
   232 		const u32_t timeout);
   212 
   233 
   213 	// This is documented in abs_eap_am_tools_c::memory_store_get_data().
   234 	// This is documented in abs_eap_am_tools_c::memory_store_get_data().
   214 	EAP_FUNC_IMPORT eap_status_e memory_store_get_data(
   235 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e memory_store_get_data(
   215 		const eap_variable_data_c * const key,
   236 		const eap_variable_data_c * const key,
   216 		eap_tlv_message_data_c * const data);
   237 		eap_tlv_message_data_c * const data);
   217 
   238 
   218 	// This is documented in abs_eap_am_tools_c::memory_store_remove_data().
   239 	// This is documented in abs_eap_am_tools_c::memory_store_remove_data().
   219 	EAP_FUNC_IMPORT eap_status_e memory_store_remove_data(
   240 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e memory_store_remove_data(
   220 		const eap_variable_data_c * const key);
   241 		const eap_variable_data_c * const key);
   221 
   242 
   222 
   243 
   223 	/// This function shuts down eap_am_tools_c object.
   244 	/// This function shuts down eap_am_tools_c object.
   224 	EAP_FUNC_IMPORT eap_status_e shutdown_am_tools();
   245 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e shutdown_am_tools();
   225 
   246 
   226 	/// The implementing function must call eap_am_tools_c::shutdown_am_tools().
   247 	/// The implementing function must call eap_am_tools_c::shutdown_am_tools().
   227 	EAP_FUNC_IMPORT virtual eap_status_e shutdown() = 0;
   248 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H virtual eap_status_e shutdown() = 0;
   228 
   249 
   229 	/**
   250 	/**
   230 	 * Function converts unicode characters into UTF8 characters.
   251 	 * Function converts unicode characters into UTF8 characters.
   231 	 * @param dest is reference to destination utf8 variable data.
   252 	 * @param dest is reference to destination utf8 variable data.
   232 	 * @param src is refrence to unicode variable data.
   253 	 * @param src is refrence to unicode variable data.
   233 	 * @return eap status code.
   254 	 * @return eap status code.
   234 	 */
   255 	 */
   235 	EAP_FUNC_IMPORT eap_status_e generic_convert_unicode_to_utf8(
   256 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e generic_convert_unicode_to_utf8(
   236 		eap_variable_data_c & dest,
   257 		eap_variable_data_c & dest,
   237 		const eap_variable_data_c & src);
   258 		const eap_variable_data_c & src);
   238 
   259 
   239 	/**
   260 	/**
   240 	 * Function converts UTF8 characters into unicode characters.
   261 	 * Function converts UTF8 characters into unicode characters.
   241 	 * @param dest is reference to destination unicode variable data.
   262 	 * @param dest is reference to destination unicode variable data.
   242 	 * @param src is refrence to UTF8 variable data.
   263 	 * @param src is refrence to UTF8 variable data.
   243 	 * @return eap status code.
   264 	 * @return eap status code.
   244 	 */
   265 	 */
   245 	EAP_FUNC_IMPORT eap_status_e generic_convert_utf8_to_unicode(
   266 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e generic_convert_utf8_to_unicode(
   246 		eap_variable_data_c & dest,
   267 		eap_variable_data_c & dest,
   247 		const eap_variable_data_c & src);
   268 		const eap_variable_data_c & src);
   248 
   269 
   249 	/**
   270 	/**
   250 	 * Function parses NAI to usename and realm.
   271 	 * Function parses NAI to usename and realm.
   251 	 * If either is missing the corresponding value will be invalid.
   272 	 * If either is missing the corresponding value will be invalid.
   252 	 */
   273 	 */
   253 	EAP_FUNC_IMPORT eap_status_e parse_nai(
   274 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e parse_nai(
   254 		const eap_variable_data_c * const nai,
   275 		const eap_variable_data_c * const nai,
   255 		eap_variable_data_c * const username,
   276 		eap_variable_data_c * const username,
   256 		eap_variable_data_c * const realm);
   277 		eap_variable_data_c * const realm);
   257 
   278 
   258 
   279 
   259 #if defined(USE_EAP_ERROR_TESTS)
   280 #if defined(USE_EAP_ERROR_TESTS)
   260 	EAP_FUNC_IMPORT eap_status_e generate_random_error(
   281 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e generate_random_error(
   261 		eap_buf_chain_wr_c * const sent_packet,
   282 		eap_buf_chain_wr_c * const sent_packet,
   262 		const bool forse_error,
   283 		const bool forse_error,
   263 		const u32_t packet_index,
   284 		const u32_t packet_index,
   264 		const u32_t minimum_index,
   285 		const u32_t minimum_index,
   265 		const u32_t error_probability,
   286 		const u32_t error_probability,
   266 		const u32_t minimum_packet_length);
   287 		const u32_t minimum_packet_length);
   267 
   288 
   268 	EAP_FUNC_IMPORT u32_t get_packet_index();
   289 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H u32_t get_packet_index();
   269 
   290 
   270 	EAP_FUNC_IMPORT void increase_packet_index();
   291 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H void increase_packet_index();
   271 #endif //#if defined(USE_EAP_ERROR_TESTS)
   292 #endif //#if defined(USE_EAP_ERROR_TESTS)
   272 
   293 
   273 
   294 
   274 	EAP_FUNC_IMPORT eap_status_e number_string_to_u32(
   295 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e number_string_to_u32(
   275 		const u8_t * const number_string,
   296 		const u8_t * const number_string,
   276 		const u32_t number_string_length,
   297 		const u32_t number_string_length,
   277 		u32_t * const integer);
   298 		u32_t * const integer);
   278 
   299 
   279 	EAP_FUNC_IMPORT void trace_configuration(
   300 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H void trace_configuration(
   280 		const eap_status_e configuration_read_status,
   301 		const eap_status_e configuration_read_status,
   281 		const eap_configuration_field_c * const field,
   302 		const eap_configuration_field_c * const field,
   282 		const eap_variable_data_c * const data);
   303 		const eap_variable_data_c * const data);
   283 
   304 
   284 	EAP_FUNC_IMPORT u64_t xor_u64(const u64_t a, const u64_t b);
   305 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H u64_t xor_u64(const u64_t a, const u64_t b);
   285 
   306 
   286 	EAP_FUNC_IMPORT u64_t multiply_u64(const u64_t a, const u64_t b);
   307 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H u64_t multiply_u64(const u64_t a, const u64_t b);
   287 
   308 
   288 	EAP_FUNC_IMPORT i32_t compare_u64(const u64_t a, const u64_t b);
   309 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H i32_t compare_u64(const u64_t a, const u64_t b);
   289 
   310 
   290 	EAP_FUNC_IMPORT eap_status_e create_uuid_v5( 
   311 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e create_uuid_v5( 
   291 		const void* const ns_uuid,
   312 		const void* const ns_uuid,
   292 		const u32_t ns_uuid_length,
   313 		const u32_t ns_uuid_length,
   293 		const void* const name, 
   314 		const void* const name, 
   294 		const u32_t name_length,
   315 		const u32_t name_length,
   295 		eap_variable_data_c* const uuid );
   316 		eap_variable_data_c* const uuid );
   296 
   317 
   297 	EAP_FUNC_IMPORT eap_status_e create_uuid_v5_from_mac_address( 
   318 	EAP_FUNC_VISIBILITY_EAP_AM_TOOLS_H eap_status_e create_uuid_v5_from_mac_address( 
   298 		const u8_t* const mac_address, 
   319 		const u8_t* const mac_address, 
   299 		const u32_t mac_address_length,
   320 		const u32_t mac_address_length,
   300 		eap_variable_data_c* const uuid );
   321 		eap_variable_data_c* const uuid );
   301 
   322 
   302 };
   323 };