eapol/eapol_framework/wapi_common/src/wai_variable_data.cpp
changeset 18 7aac0b9e8906
parent 17 8840d3e38314
child 20 8b3129ac4c0f
equal deleted inserted replaced
17:8840d3e38314 18:7aac0b9e8906
     1 /*
       
     2 * ============================================================================
       
     3 *  Name        : ./accesssec/eapol/eapol_framework/wapi_common/src/wai_variable_data.cpp
       
     4 *  Part of     : WAPI / WAPI       *** Info from the SWAD
       
     5 *  Description : WAPI authentication
       
     6 *  Version     : %version: 20 % << Don't touch! Updated by Synergy at check-out.
       
     7 *
       
     8 *  Copyright © 2001-2009 Nokia.  All rights reserved.
       
     9 *  This material, including documentation and any related computer
       
    10 *  programs, is protected by copyright controlled by Nokia.  All
       
    11 *  rights are reserved.  Copying, including reproducing, storing,
       
    12 *  adapting or translating, any or all of this material requires the
       
    13 *  prior written consent of Nokia.  This material also contains
       
    14 *  confidential information which may not be disclosed to others
       
    15 *  without the prior written consent of Nokia.
       
    16 * ============================================================================
       
    17 * Template version: 4.1.1
       
    18 */
       
    19 
       
    20 // This is enumeration of WAPI source code.
       
    21 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    22 	#undef EAP_FILE_NUMBER_ENUM
       
    23 	#define EAP_FILE_NUMBER_ENUM 710 
       
    24 	#undef EAP_FILE_NUMBER_DATE 
       
    25 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    26 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    27 
       
    28 
       
    29 #if defined(USE_WAPI_CORE)
       
    30 
       
    31 
       
    32 #include "eap_am_memory.h"
       
    33 #include "wai_message_payloads.h"
       
    34 #include "wai_message.h"
       
    35 #include "abs_eap_am_tools.h"
       
    36 #include "eap_tools.h"
       
    37 #include "eap_array_algorithms.h"
       
    38 #include "eap_automatic_variable.h"
       
    39 #include "eap_crypto_api.h"
       
    40 #include "wapi_strings.h"
       
    41 
       
    42 
       
    43 //--------------------------------------------------
       
    44 
       
    45 EAP_FUNC_EXPORT wai_variable_data_c::~wai_variable_data_c()
       
    46 {
       
    47 	delete get_next_payload_with_same_tlv_type();
       
    48 	set_next_payload_with_same_tlv_type(0);
       
    49 }
       
    50 
       
    51 //--------------------------------------------------
       
    52 
       
    53 EAP_FUNC_EXPORT wai_variable_data_c::wai_variable_data_c(
       
    54 	abs_eap_am_tools_c * const tools)
       
    55 	: m_am_tools(tools)
       
    56 	  , m_data(tools)
       
    57 	  , m_wai_tlv_header(tools, 0, 0ul)
       
    58 	  , m_ec_cs_tlv_header(tools, 0, 0ul)
       
    59 	  , m_payload_type(wai_payload_type_none)
       
    60 	  , m_next_payload_with_same_tlv_type(0)
       
    61 	  , m_is_valid(false)
       
    62 {
       
    63 	if (m_data.get_is_valid() == false)
       
    64 	{
       
    65 		return;
       
    66 	}
       
    67 
       
    68 	m_is_valid = true;
       
    69 }
       
    70 
       
    71 //--------------------------------------------------
       
    72 
       
    73 EAP_FUNC_EXPORT bool wai_variable_data_c::get_is_valid() const
       
    74 {
       
    75 	return m_is_valid;
       
    76 }
       
    77 
       
    78 //--------------------------------------------------
       
    79 
       
    80 EAP_FUNC_EXPORT bool wai_variable_data_c::get_is_valid_data() const
       
    81 {
       
    82 	return get_is_valid() && m_data.get_is_valid_data();
       
    83 }
       
    84 
       
    85 //--------------------------------------------------
       
    86 
       
    87 EAP_FUNC_EXPORT wai_payload_type_e wai_variable_data_c::convert_to_wai_payload_type(const wai_tlv_type_e tlv_type)
       
    88 {
       
    89 	switch(tlv_type)
       
    90 	{
       
    91 	case wai_tlv_type_signature_attribute:
       
    92 		return wai_payload_type_signature_attributes;
       
    93 	case wai_tlv_type_result_of_certificate_validation:
       
    94 		return wai_payload_type_result_of_certificate_verification;
       
    95 	case wai_tlv_type_identity_list:
       
    96 		return wai_payload_type_identity_list;
       
    97 	default:
       
    98 		return wai_payload_type_none;
       
    99 	};
       
   100 }
       
   101 
       
   102 //--------------------------------------------------
       
   103 
       
   104 EAP_FUNC_EXPORT wai_tlv_type_e wai_variable_data_c::convert_to_wai_tlv_type(const wai_payload_type_e payload_type)
       
   105 {
       
   106 	switch(payload_type)
       
   107 	{
       
   108 	case wai_payload_type_signature_attributes:
       
   109 		return wai_tlv_type_signature_attribute;
       
   110 	case wai_payload_type_result_of_certificate_verification:
       
   111 		return wai_tlv_type_result_of_certificate_validation;
       
   112 	case wai_payload_type_identity_list:
       
   113 		return wai_tlv_type_identity_list;
       
   114 	case wai_payload_type_echd_parameter:
       
   115 		return wai_tlv_type_echd_parameter;
       
   116 	default:
       
   117 		return wai_tlv_type_none;
       
   118 	};
       
   119 }
       
   120 
       
   121 //--------------------------------------------------
       
   122 
       
   123 EAP_FUNC_EXPORT wai_certificate_identifier_e wai_variable_data_c::convert_to_wai_certificate_identifier(const wai_payload_type_e payload_type)
       
   124 {
       
   125 	switch(payload_type)
       
   126 	{
       
   127 	case wai_payload_type_certificate:
       
   128 	case wai_payload_type_identity:
       
   129 		return wai_certificate_identifier_x_509_v3;
       
   130 	default:
       
   131 		return wai_certificate_identifier_none;
       
   132 	};
       
   133 }
       
   134 
       
   135 //--------------------------------------------------
       
   136 
       
   137 EAP_FUNC_EXPORT ec_cs_tlv_type_e wai_variable_data_c::convert_to_ec_cs_tlv_type(const wai_payload_type_e payload_type)
       
   138 {
       
   139 	switch(payload_type)
       
   140 	{
       
   141 	case wai_payload_type_certificate:
       
   142 	case wai_payload_type_identity:
       
   143 		return static_cast<ec_cs_tlv_type_e>(convert_to_wai_certificate_identifier(payload_type));
       
   144 	default:
       
   145 		return static_cast<ec_cs_tlv_type_e>(payload_type);
       
   146 	};
       
   147 }
       
   148 
       
   149 //--------------------------------------------------
       
   150 
       
   151 eap_status_e wai_variable_data_c::set_header_buffer(
       
   152 	const wai_payload_type_e current_payload,
       
   153 	const bool write_header)
       
   154 {
       
   155 	if (m_data.get_is_valid_data() == false)
       
   156 	{
       
   157 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   158 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_payload);
       
   159 	}
       
   160 
       
   161 	switch (get_type_class())
       
   162 	{
       
   163 	case wai_payload_type_size_ec_cs_tlv_header:
       
   164 		{
       
   165 			m_ec_cs_tlv_header.set_header_buffer(
       
   166 				m_data.get_buffer(m_data.get_buffer_length()),
       
   167 				m_data.get_buffer_length());
       
   168 
       
   169 			if (write_header == true)
       
   170 			{
       
   171 				eap_status_e status = m_ec_cs_tlv_header.reset_header();
       
   172 				if (status != eap_status_ok)
       
   173 				{
       
   174 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   175 					return EAP_STATUS_RETURN(m_am_tools, status);
       
   176 				}
       
   177 
       
   178 				status = m_ec_cs_tlv_header.set_type(convert_to_ec_cs_tlv_type(current_payload));
       
   179 				if (status != eap_status_ok)
       
   180 				{
       
   181 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   182 					return EAP_STATUS_RETURN(m_am_tools, status);
       
   183 				}
       
   184 			}
       
   185 		}
       
   186 		break;
       
   187 	case wai_payload_type_size_wai_tlv_header:
       
   188 		{
       
   189 			m_wai_tlv_header.set_header_buffer(
       
   190 				m_data.get_buffer(m_data.get_buffer_length()),
       
   191 				m_data.get_buffer_length());
       
   192 
       
   193 			if (current_payload == wai_payload_type_optional)
       
   194 			{
       
   195 				m_payload_type = convert_to_wai_payload_type(m_wai_tlv_header.get_type());
       
   196 			}
       
   197 			else if (write_header == true)
       
   198 			{
       
   199 				eap_status_e status = m_wai_tlv_header.reset_header();
       
   200 				if (status != eap_status_ok)
       
   201 				{
       
   202 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   203 					return EAP_STATUS_RETURN(m_am_tools, status);
       
   204 				}
       
   205 
       
   206 				status = m_wai_tlv_header.set_type(convert_to_wai_tlv_type(current_payload));
       
   207 				if (status != eap_status_ok)
       
   208 				{
       
   209 					EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   210 					return EAP_STATUS_RETURN(m_am_tools, status);
       
   211 				}
       
   212 			}
       
   213 		}
       
   214 		break;
       
   215 	default:
       
   216 		;
       
   217 	}; // switch
       
   218 
       
   219 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   220 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   221 }
       
   222 
       
   223 //--------------------------------------------------
       
   224 
       
   225 eap_status_e wai_variable_data_c::set_header_buffer(
       
   226 	const wai_payload_type_e current_payload,
       
   227 	const bool write_header,
       
   228 	const u32_t data_length)
       
   229 {
       
   230 	eap_status_e status = set_header_buffer(
       
   231 		current_payload,
       
   232 		write_header);
       
   233 	if (status != eap_status_ok)
       
   234 	{
       
   235 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   236 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   237 	}
       
   238 
       
   239 	switch (get_type_class())
       
   240 	{
       
   241 	case wai_payload_type_size_ec_cs_tlv_header:
       
   242 		m_ec_cs_tlv_header.set_data_length(static_cast<u16_t>(data_length));
       
   243 		break;
       
   244 	case wai_payload_type_size_wai_tlv_header:
       
   245 		m_wai_tlv_header.set_data_length(static_cast<u16_t>(data_length));
       
   246 		break;
       
   247 	case wai_payload_type_size_1_octet_length_field:
       
   248 		{
       
   249 			u8_t * data = m_data.get_data(sizeof(u8_t));
       
   250 			if (data == 0)
       
   251 			{
       
   252 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   253 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   254 			}
       
   255 
       
   256 			if (data_length > 0xff)
       
   257 			{
       
   258 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   259 				return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
       
   260 			}
       
   261 
       
   262 			data[0ul] = static_cast<u8_t>(data_length);
       
   263 
       
   264 		}
       
   265 		break;
       
   266 	default:
       
   267 		;
       
   268 	}; // switch
       
   269 
       
   270 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   271 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   272 }
       
   273 
       
   274 //--------------------------------------------------
       
   275 
       
   276 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::init_header(
       
   277 	const wai_payload_type_e current_payload,
       
   278 	const u32_t default_buffer_length)
       
   279 {
       
   280 	if (default_buffer_length > 0xffff)
       
   281 	{
       
   282 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   283 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
   284 	}
       
   285 
       
   286 	eap_status_e status = set_payload_type(current_payload);
       
   287 	if (status != eap_status_ok)
       
   288 	{
       
   289 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   290 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   291 	}
       
   292 
       
   293 	status = m_data.set_buffer_length(
       
   294 		default_buffer_length);
       
   295 	if (status != eap_status_ok)
       
   296 	{
       
   297 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   298 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   299 	}
       
   300 
       
   301 
       
   302 	switch (get_type_class())
       
   303 	{
       
   304 	case wai_payload_type_size_wai_tlv_header:
       
   305 		{
       
   306 			status = m_data.set_data_length(
       
   307 				wai_tlv_header_c::get_header_length());
       
   308 			if (status != eap_status_ok)
       
   309 			{
       
   310 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   311 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   312 			}
       
   313 
       
   314 			status = m_wai_tlv_header.reset();
       
   315 			if (status != eap_status_ok)
       
   316 			{
       
   317 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   318 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   319 			}
       
   320 		}
       
   321 		break;
       
   322 	case wai_payload_type_size_ec_cs_tlv_header:
       
   323 		{
       
   324 			status = m_data.set_data_length(
       
   325 				ec_cs_tlv_header_c::get_header_length());
       
   326 			if (status != eap_status_ok)
       
   327 			{
       
   328 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   329 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   330 			}
       
   331 
       
   332 			status = m_ec_cs_tlv_header.reset();
       
   333 			if (status != eap_status_ok)
       
   334 			{
       
   335 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   336 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   337 			}
       
   338 		}
       
   339 		break;
       
   340 	case wai_payload_type_size_1_octet_length_field:
       
   341 		{
       
   342 			status = m_data.set_data_length(sizeof(u8_t));
       
   343 			if (status != eap_status_ok)
       
   344 			{
       
   345 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   346 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   347 			}
       
   348 
       
   349 			u8_t * data = m_data.get_data(sizeof(u8_t));
       
   350 			if (data == 0)
       
   351 			{
       
   352 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   353 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   354 			}
       
   355 
       
   356 			data[0ul] = 0u;
       
   357 
       
   358 		}
       
   359 		break;
       
   360 	default:
       
   361 		break;
       
   362 	}; // switch
       
   363 
       
   364 
       
   365 	status = set_header_buffer(current_payload, true);
       
   366 	if (status != eap_status_ok)
       
   367 	{
       
   368 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   369 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   370 	}
       
   371 
       
   372 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   373 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   374 }
       
   375 
       
   376 //--------------------------------------------------
       
   377 
       
   378 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::reset()
       
   379 {
       
   380 	(void) m_data.reset();
       
   381 
       
   382 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   383 }
       
   384 
       
   385 //--------------------------------------------------
       
   386 
       
   387 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::set_buffer(
       
   388 	const wai_payload_type_e current_payload,
       
   389 	const void * const buffer,
       
   390 	const u32_t buffer_length)
       
   391 {
       
   392 	if (buffer_length > 0xffff)
       
   393 	{
       
   394 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   395 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
   396 	}
       
   397 
       
   398 	eap_status_e status = m_data.set_buffer(
       
   399 		buffer,
       
   400 		buffer_length,
       
   401 		false,
       
   402 		false);
       
   403 	if (status != eap_status_ok)
       
   404 	{
       
   405 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   406 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   407 	}
       
   408 
       
   409 	status = set_payload_type(current_payload);
       
   410 	if (status != eap_status_ok)
       
   411 	{
       
   412 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   413 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   414 	}
       
   415 
       
   416 	status = m_wai_tlv_header.reset();
       
   417 	if (status != eap_status_ok)
       
   418 	{
       
   419 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   420 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   421 	}
       
   422 
       
   423 	status = m_ec_cs_tlv_header.reset();
       
   424 	if (status != eap_status_ok)
       
   425 	{
       
   426 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   427 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   428 	}
       
   429 
       
   430 	status = set_header_buffer(current_payload, false);
       
   431 	if (status != eap_status_ok)
       
   432 	{
       
   433 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   434 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   435 	}
       
   436 
       
   437 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   438 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   439 }
       
   440 
       
   441 //--------------------------------------------------
       
   442 
       
   443 u32_t wai_variable_data_c::get_header_length(
       
   444 	const wai_payload_type_e current_payload) const
       
   445 {
       
   446 	switch (get_type_class(current_payload))
       
   447 	{
       
   448 	case wai_payload_type_size_ec_cs_tlv_header:
       
   449 		{
       
   450 			return m_ec_cs_tlv_header.get_header_length();
       
   451 		}
       
   452 	case wai_payload_type_size_wai_tlv_header:
       
   453 		{
       
   454 			return m_wai_tlv_header.get_header_length();
       
   455 		}
       
   456 	case wai_payload_type_size_1_octet_length_field:
       
   457 		{
       
   458 			return sizeof(u8_t);
       
   459 		}
       
   460 	case wai_payload_type_size_wie:
       
   461 		{
       
   462 			return WIE_HEADER_LENGTH;
       
   463 		}
       
   464 	default:
       
   465 		{
       
   466 			return 0ul;
       
   467 		}
       
   468 	}; // switch
       
   469 }
       
   470 
       
   471 //--------------------------------------------------
       
   472 
       
   473 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::create(
       
   474 	const wai_payload_type_e current_payload,
       
   475 	const void * const buffer, // Buffer includes only data.
       
   476 	const u32_t buffer_length) // Buffer_length includes only data.
       
   477 {
       
   478 	eap_status_e status = init_header(
       
   479 		current_payload,
       
   480 		get_header_length(current_payload) + buffer_length);
       
   481 	if (status != eap_status_ok)
       
   482 	{
       
   483 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   484 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   485 	}
       
   486 
       
   487 	status = m_data.add_data(buffer, buffer_length);
       
   488 	if (status != eap_status_ok)
       
   489 	{
       
   490 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   491 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   492 	}
       
   493 
       
   494 	switch (get_type_class())
       
   495 	{
       
   496 	case wai_payload_type_size_ec_cs_tlv_header:
       
   497 		m_ec_cs_tlv_header.set_data_length(static_cast<u16_t>(buffer_length));
       
   498 		break;
       
   499 	case wai_payload_type_size_wai_tlv_header:
       
   500 		m_wai_tlv_header.set_data_length(static_cast<u16_t>(buffer_length));
       
   501 		break;
       
   502 	case wai_payload_type_size_1_octet_length_field:
       
   503 		{
       
   504 			u8_t * data = m_data.get_data(sizeof(u8_t));
       
   505 			if (data == 0)
       
   506 			{
       
   507 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   508 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   509 			}
       
   510 
       
   511 			if (buffer_length > 0xff)
       
   512 			{
       
   513 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   514 				return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
       
   515 			}
       
   516 
       
   517 			data[0ul] = static_cast<u8_t>(buffer_length);
       
   518 
       
   519 		}
       
   520 		break;
       
   521 	default:
       
   522 		;
       
   523 	}; // switch
       
   524 
       
   525 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   526 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   527 }
       
   528 
       
   529 //--------------------------------------------------
       
   530 
       
   531 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::create(
       
   532 	const wai_payload_type_e current_payload,
       
   533 	const eap_variable_data_c * const buffer) // Buffer includes only data.
       
   534 {
       
   535 	eap_status_e status = create(
       
   536 		current_payload,
       
   537 		buffer->get_data(),
       
   538 		buffer->get_data_length());
       
   539 	if (status != eap_status_ok)
       
   540 	{
       
   541 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   542 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   543 	}
       
   544 
       
   545 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   546 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   547 }
       
   548 
       
   549 //--------------------------------------------------
       
   550 
       
   551 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::set_copy_of_buffer(
       
   552 	const wai_payload_type_e current_payload,
       
   553 	const void * const buffer, // Buffer does include header and data.
       
   554 	const u32_t buffer_length) // Buffer_length does include header and data.
       
   555 {
       
   556 	eap_status_e status = init_header(
       
   557 		current_payload,
       
   558 		buffer_length);
       
   559 	if (status != eap_status_ok)
       
   560 	{
       
   561 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   562 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   563 	}
       
   564 
       
   565 	status = m_data.set_copy_of_buffer(buffer, buffer_length);
       
   566 	if (status != eap_status_ok)
       
   567 	{
       
   568 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   569 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   570 	}
       
   571 
       
   572 	switch (get_type_class())
       
   573 	{
       
   574 	case wai_payload_type_size_ec_cs_tlv_header:
       
   575 		m_ec_cs_tlv_header.set_data_length(static_cast<u16_t>(buffer_length - get_type_header_length()));
       
   576 		break;
       
   577 	case wai_payload_type_size_wai_tlv_header:
       
   578 		m_wai_tlv_header.set_data_length(static_cast<u16_t>(buffer_length - get_type_header_length()));
       
   579 		break;
       
   580 	case wai_payload_type_size_1_octet_length_field:
       
   581 		{
       
   582 			u8_t * data = m_data.get_data(sizeof(u8_t));
       
   583 			if (data == 0)
       
   584 			{
       
   585 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   586 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   587 			}
       
   588 
       
   589 			if (buffer_length > 0xff)
       
   590 			{
       
   591 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   592 				return EAP_STATUS_RETURN(m_am_tools, eap_status_buffer_too_short);
       
   593 			}
       
   594 
       
   595 			data[0ul] = static_cast<u8_t>(buffer_length - get_type_header_length());
       
   596 
       
   597 		}
       
   598 		break;
       
   599 	default:
       
   600 		;
       
   601 	}; // switch
       
   602 
       
   603 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   604 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   605 }
       
   606 
       
   607 //--------------------------------------------------
       
   608 
       
   609 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::set_copy_of_buffer(
       
   610 	const wai_payload_type_e current_payload,
       
   611 	const eap_variable_data_c * const buffer)
       
   612 {
       
   613 	eap_status_e status = set_copy_of_buffer(
       
   614 		current_payload,
       
   615 		buffer->get_data(),
       
   616 		buffer->get_data_length());
       
   617 	if (status != eap_status_ok)
       
   618 	{
       
   619 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   620 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   621 	}
       
   622 
       
   623 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   624 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   625 }
       
   626 
       
   627 //--------------------------------------------------
       
   628 
       
   629 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::set_copy_of_buffer(
       
   630 	const wai_variable_data_c * const source)
       
   631 {
       
   632 	eap_status_e status = set_copy_of_buffer(
       
   633 			source->get_payload_type(),
       
   634 			source->get_data(source->get_data_length()),
       
   635 			source->get_data_length());
       
   636 
       
   637 	if (status != eap_status_ok)
       
   638 	{
       
   639 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   640 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   641 	}
       
   642 
       
   643 	delete get_next_payload_with_same_tlv_type();
       
   644 	set_next_payload_with_same_tlv_type(0);
       
   645 
       
   646 	wai_variable_data_c * previous = this;
       
   647 
       
   648 	const wai_variable_data_c * next = source->get_next_payload_with_same_tlv_type();
       
   649 
       
   650 	while (next != 0)
       
   651 	{
       
   652 		// Copy the next payload in a list too.
       
   653 		wai_variable_data_c * const new_payload = next->copy();
       
   654 		if (new_payload == 0)
       
   655 		{
       
   656 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   657 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   658 		}
       
   659 
       
   660 		previous->set_next_payload_with_same_tlv_type(new_payload);
       
   661 
       
   662 		previous = new_payload;
       
   663 
       
   664 		next = next->get_next_payload_with_same_tlv_type();
       
   665 	}
       
   666 
       
   667 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   668 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   669 }
       
   670 
       
   671 //--------------------------------------------------
       
   672 
       
   673 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::add_data(
       
   674 	const wai_payload_type_e new_payload,
       
   675 	const void * const buffer,
       
   676 	const u32_t buffer_length)
       
   677 {
       
   678 	const wai_payload_type_e current_payload = get_payload_type();
       
   679 
       
   680 	if (new_payload != current_payload)
       
   681 	{
       
   682 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   683 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_payload);
       
   684 	}
       
   685 
       
   686 	const u32_t type_data_length(get_type_data_length());
       
   687 
       
   688 	eap_status_e status = m_data.add_data(
       
   689 		buffer,
       
   690 		buffer_length);
       
   691 	if (status != eap_status_ok)
       
   692 	{
       
   693 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   694 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   695 	}
       
   696 
       
   697 	status = set_header_buffer(current_payload, true, (type_data_length + buffer_length));
       
   698 	if (status != eap_status_ok)
       
   699 	{
       
   700 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   701 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   702 	}
       
   703 
       
   704 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   705 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   706 }
       
   707 
       
   708 //--------------------------------------------------
       
   709 
       
   710 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::add_data(
       
   711 	const wai_payload_type_e new_payload,
       
   712 	const eap_variable_data_c * const buffer)
       
   713 {
       
   714 	eap_status_e status = add_data(
       
   715 		new_payload,
       
   716 		buffer->get_data(),
       
   717 		buffer->get_data_length());
       
   718 	if (status != eap_status_ok)
       
   719 	{
       
   720 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   721 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   722 	}
       
   723 
       
   724 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   725 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   726 }
       
   727 
       
   728 //--------------------------------------------------
       
   729 
       
   730 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::add_data(
       
   731 	const wai_variable_data_c * const data)
       
   732 {
       
   733 	eap_status_e status = add_data(
       
   734 		data->get_payload_type(),
       
   735 		data->get_full_tlv_buffer()->get_data(),
       
   736 		data->get_full_tlv_buffer()->get_data_length());
       
   737 	if (status != eap_status_ok)
       
   738 	{
       
   739 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   740 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   741 	}
       
   742 
       
   743 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   744 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   745 }
       
   746 
       
   747 //--------------------------------------------------
       
   748 
       
   749 wai_payload_type_size_e wai_variable_data_c::get_type_class(const wai_payload_type_e current_payload) const
       
   750 {
       
   751 	if (current_payload <= wai_payload_type_last_known
       
   752 		&& current_payload == wai_payload_type_to_class_map[current_payload].m_type)
       
   753 	{
       
   754 		return wai_payload_type_to_class_map[current_payload].m_size;
       
   755 	}
       
   756 	else
       
   757 	{
       
   758 		return wai_payload_type_size_none;
       
   759 	}
       
   760 }
       
   761 
       
   762 //--------------------------------------------------
       
   763 
       
   764 EAP_FUNC_EXPORT wai_payload_type_size_e wai_variable_data_c::get_type_class() const
       
   765 {
       
   766 	const wai_payload_type_e current_payload(get_payload_type());
       
   767 
       
   768 	return get_type_class(current_payload);
       
   769 }
       
   770 
       
   771 //--------------------------------------------------
       
   772 
       
   773 EAP_FUNC_EXPORT u32_t wai_variable_data_c::get_type_data_length() const
       
   774 {
       
   775 	switch (get_type_class())
       
   776 	{
       
   777 	case wai_payload_type_size_ec_cs_tlv_header:
       
   778 		{
       
   779 			if (m_data.get_data_length() >= m_ec_cs_tlv_header.get_header_length())
       
   780 			{
       
   781 				return m_ec_cs_tlv_header.get_data_length();
       
   782 			}
       
   783 			else
       
   784 			{
       
   785 				return 0ul;
       
   786 			}
       
   787 		}
       
   788 	case wai_payload_type_size_wai_tlv_header:
       
   789 		{
       
   790 			if (m_data.get_data_length() >= m_wai_tlv_header.get_header_length())
       
   791 			{
       
   792 				return m_wai_tlv_header.get_data_length();
       
   793 			}
       
   794 			else
       
   795 			{
       
   796 				return 0ul;
       
   797 			}
       
   798 		}
       
   799 	case wai_payload_type_size_1_octet_length_field:
       
   800 		{
       
   801 			if (m_data.get_data_length() >= sizeof(u8_t))
       
   802 			{
       
   803 				const u8_t * data = m_data.get_data(sizeof(u8_t));
       
   804 				return data[0ul];
       
   805 			}
       
   806 			else
       
   807 			{
       
   808 				return 0ul;
       
   809 			}
       
   810 		}
       
   811 	case wai_payload_type_size_wie:
       
   812 		{
       
   813 			if (m_data.get_data_length() >= WIE_HEADER_LENGTH)
       
   814 			{
       
   815 				const u8_t * data = m_data.get_data(WIE_HEADER_LENGTH);
       
   816 				return data[1ul];
       
   817 			}
       
   818 			else
       
   819 			{
       
   820 				return 0ul;
       
   821 			}
       
   822 		}
       
   823 	default:
       
   824 		{
       
   825 			if (m_data.get_data_length() >= static_cast<u32_t>(get_type_class()))
       
   826 			{
       
   827 				return get_type_class();
       
   828 			}
       
   829 			else
       
   830 			{
       
   831 				return 0ul;
       
   832 			}
       
   833 		}
       
   834 	}; // switch
       
   835 }
       
   836 
       
   837 //--------------------------------------------------
       
   838 
       
   839 EAP_FUNC_EXPORT u32_t wai_variable_data_c::get_type_header_length() const
       
   840 {
       
   841 	switch (get_type_class())
       
   842 	{
       
   843 	case wai_payload_type_size_ec_cs_tlv_header:
       
   844 		{
       
   845 			if (m_data.get_data_length() >= m_ec_cs_tlv_header.get_header_length())
       
   846 			{
       
   847 				return m_ec_cs_tlv_header.get_header_length();
       
   848 			}
       
   849 			else
       
   850 			{
       
   851 				return 0ul;
       
   852 			}
       
   853 		}
       
   854 	case wai_payload_type_size_wai_tlv_header:
       
   855 		{
       
   856 			if (m_data.get_data_length() >= m_wai_tlv_header.get_header_length())
       
   857 			{
       
   858 				return m_wai_tlv_header.get_header_length();
       
   859 			}
       
   860 			else
       
   861 			{
       
   862 				return 0ul;
       
   863 			}
       
   864 		}
       
   865 	case wai_payload_type_size_1_octet_length_field:
       
   866 		{
       
   867 			if (m_data.get_data_length() >= sizeof(u8_t))
       
   868 			{
       
   869 				return sizeof(u8_t);
       
   870 			}
       
   871 			else
       
   872 			{
       
   873 				return 0ul;
       
   874 			}
       
   875 		}
       
   876 	case wai_payload_type_size_wie:
       
   877 		{
       
   878 			if (m_data.get_data_length() >= WIE_HEADER_LENGTH)
       
   879 			{
       
   880 				return WIE_HEADER_LENGTH;
       
   881 			}
       
   882 			else
       
   883 			{
       
   884 				return 0ul;
       
   885 			}
       
   886 		}
       
   887 	default:
       
   888 		{
       
   889 			return 0ul;
       
   890 		}
       
   891 	}; // switch
       
   892 }
       
   893 
       
   894 //--------------------------------------------------
       
   895 
       
   896 EAP_FUNC_EXPORT u8_t * wai_variable_data_c::get_type_data_offset(
       
   897 	const u32_t offset,
       
   898 	const u32_t data_length) const
       
   899 {
       
   900 	return m_data.get_data_offset(get_type_header_length()+offset, data_length);
       
   901 }
       
   902 
       
   903 //--------------------------------------------------
       
   904 
       
   905 EAP_FUNC_EXPORT u8_t * wai_variable_data_c::get_type_data(
       
   906 	const u32_t data_length) const
       
   907 {
       
   908 	return get_type_data_offset(0ul, data_length);
       
   909 }
       
   910 
       
   911 //--------------------------------------------------
       
   912 
       
   913 EAP_FUNC_EXPORT u32_t wai_variable_data_c::get_data_length() const
       
   914 {
       
   915 	return get_type_header_length() + get_type_data_length();
       
   916 }
       
   917 
       
   918 //--------------------------------------------------
       
   919 
       
   920 EAP_FUNC_EXPORT u8_t * wai_variable_data_c::get_data(
       
   921 	const u32_t data_length) const
       
   922 {
       
   923 #if 1
       
   924 
       
   925 	return m_data.get_data(data_length);
       
   926 
       
   927 #else
       
   928 
       
   929 	switch (get_type_class())
       
   930 	{
       
   931 	case wai_payload_type_size_ec_cs_tlv_header:
       
   932 		{
       
   933 			return m_ec_cs_tlv_header.get_data(data_length);
       
   934 		}
       
   935 	case wai_payload_type_size_wai_tlv_header:
       
   936 		{
       
   937 			return m_wai_tlv_header.get_data(data_length);
       
   938 		}
       
   939 	case wai_payload_type_size_1_octet_length_field:
       
   940 		{
       
   941 			if (m_data.get_data_length() >= (sizeof(u8_t) + data_length))
       
   942 			{
       
   943 				return m_data.get_data_offset(sizeof(u8_t), data_length);
       
   944 			}
       
   945 			else
       
   946 			{
       
   947 				return 0;
       
   948 			}
       
   949 		}
       
   950 	case wai_payload_type_size_wie:
       
   951 		{
       
   952 			if (m_data.get_data_length() >= (WIE_HEADER_LENGTH + data_length))
       
   953 			{
       
   954 				return m_data.get_data(data_length);
       
   955 			}
       
   956 			else
       
   957 			{
       
   958 				return 0;
       
   959 			}
       
   960 		}
       
   961 	case wai_payload_type_size_1_octet:
       
   962 	case wai_payload_type_size_12_octets:
       
   963 	case wai_payload_type_size_16_octets:
       
   964 	case wai_payload_type_size_20_octets:
       
   965 	case wai_payload_type_size_32_octets:
       
   966 		{
       
   967 			return m_data.get_data(data_length);
       
   968 		}
       
   969 	default:
       
   970 		{
       
   971 			return 0;
       
   972 		}
       
   973 	}; // switch
       
   974 
       
   975 #endif
       
   976 
       
   977 }
       
   978 
       
   979 //--------------------------------------------------
       
   980 
       
   981 EAP_FUNC_EXPORT u8_t * wai_variable_data_c::get_data_offset(const u32_t offset, const u32_t data_length) const
       
   982 {
       
   983 
       
   984 #if 1
       
   985 
       
   986 	return m_data.get_data_offset(offset, data_length);
       
   987 
       
   988 #else
       
   989 
       
   990 	switch (get_type_class())
       
   991 	{
       
   992 	case wai_payload_type_size_ec_cs_tlv_header:
       
   993 		{
       
   994 			return m_ec_cs_tlv_header.get_data_offset(offset, data_length);
       
   995 		}
       
   996 	case wai_payload_type_size_wai_tlv_header:
       
   997 		{
       
   998 			return m_wai_tlv_header.get_data_offset(offset, data_length);
       
   999 		}
       
  1000 	case wai_payload_type_size_1_octet_length_field:
       
  1001 		{
       
  1002 			if (m_data.get_data_length() >= (sizeof(u8_t) + offset + data_length))
       
  1003 			{
       
  1004 				return m_data.get_data_offset(offset + sizeof(u8_t), data_length);
       
  1005 			}
       
  1006 			else
       
  1007 			{
       
  1008 				return 0;
       
  1009 			}
       
  1010 		}
       
  1011 	case wai_payload_type_size_wie:
       
  1012 		{
       
  1013 			if (m_data.get_data_length() >= (WIE_HEADER_LENGTH + offset + data_length))
       
  1014 			{
       
  1015 				return m_data.get_data_offset(offset + WIE_HEADER_LENGTH, data_length);
       
  1016 			}
       
  1017 			else
       
  1018 			{
       
  1019 				return 0;
       
  1020 			}
       
  1021 		}
       
  1022 	case wai_payload_type_size_1_octet:
       
  1023 	case wai_payload_type_size_12_octets:
       
  1024 	case wai_payload_type_size_16_octets:
       
  1025 	case wai_payload_type_size_20_octets:
       
  1026 	case wai_payload_type_size_32_octets:
       
  1027 		{
       
  1028 			return m_data.get_data_offset(offset, data_length);
       
  1029 		}
       
  1030 	default:
       
  1031 		{
       
  1032 			return 0;
       
  1033 		}
       
  1034 	}; // switch
       
  1035 
       
  1036 #endif
       
  1037 
       
  1038 }
       
  1039 
       
  1040 //--------------------------------------------------
       
  1041 
       
  1042 EAP_FUNC_EXPORT const eap_variable_data_c * wai_variable_data_c::get_full_tlv_buffer() const
       
  1043 {
       
  1044 	return &m_data;
       
  1045 }
       
  1046 
       
  1047 //--------------------------------------------------
       
  1048 
       
  1049 EAP_FUNC_EXPORT eap_variable_data_c * wai_variable_data_c::get_writable_full_tlv_buffer()
       
  1050 {
       
  1051 	return &m_data;
       
  1052 }
       
  1053 
       
  1054 //--------------------------------------------------
       
  1055 
       
  1056 EAP_FUNC_EXPORT const wai_tlv_header_c * wai_variable_data_c::get_wai_tlv_header() const
       
  1057 {
       
  1058 	if (get_type_class() == wai_payload_type_size_wai_tlv_header)
       
  1059 	{
       
  1060 		return &m_wai_tlv_header;
       
  1061 	}
       
  1062 	else
       
  1063 	{
       
  1064 		return 0;
       
  1065 	}
       
  1066 }
       
  1067 
       
  1068 //--------------------------------------------------
       
  1069 
       
  1070 EAP_FUNC_EXPORT const ec_cs_tlv_header_c * wai_variable_data_c::get_ec_cs_tlv_header() const
       
  1071 {
       
  1072 	if (get_type_class() == wai_payload_type_size_ec_cs_tlv_header)
       
  1073 	{
       
  1074 		return &m_ec_cs_tlv_header;
       
  1075 	}
       
  1076 	else
       
  1077 	{
       
  1078 		return 0;
       
  1079 	}
       
  1080 }
       
  1081 
       
  1082 //--------------------------------------------------
       
  1083 
       
  1084 EAP_FUNC_EXPORT wai_payload_type_e wai_variable_data_c::get_payload_type() const
       
  1085 {
       
  1086 	return m_payload_type;
       
  1087 }
       
  1088 
       
  1089 //--------------------------------------------------
       
  1090 
       
  1091 EAP_FUNC_EXPORT eap_status_e wai_variable_data_c::set_payload_type(
       
  1092 	const wai_payload_type_e payload_type)
       
  1093 {
       
  1094 	eap_status_e status(eap_status_ok);
       
  1095 
       
  1096 	m_payload_type = payload_type;
       
  1097 
       
  1098 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1099 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1100 }
       
  1101 
       
  1102 //--------------------------------------------------
       
  1103 
       
  1104 EAP_FUNC_EXPORT void wai_variable_data_c::set_next_payload_with_same_tlv_type(
       
  1105 	wai_variable_data_c * const tlv)
       
  1106 {
       
  1107 	m_next_payload_with_same_tlv_type = tlv;
       
  1108 }
       
  1109 
       
  1110 //--------------------------------------------------
       
  1111 
       
  1112 EAP_FUNC_EXPORT wai_variable_data_c * wai_variable_data_c::get_next_payload_with_same_tlv_type() const
       
  1113 {
       
  1114 	return m_next_payload_with_same_tlv_type;
       
  1115 }
       
  1116 
       
  1117 //--------------------------------------------------
       
  1118 
       
  1119 EAP_FUNC_EXPORT void wai_variable_data_c::add_next_payload_with_same_tlv_type(
       
  1120 	wai_variable_data_c * const tlv)
       
  1121 {
       
  1122 	wai_variable_data_c *payload = get_next_payload_with_same_tlv_type();
       
  1123 	wai_variable_data_c *prev_payload = this;
       
  1124 
       
  1125 	while (payload != 0)
       
  1126 	{
       
  1127 		prev_payload = payload;
       
  1128 		payload = payload->get_next_payload_with_same_tlv_type();
       
  1129 	}
       
  1130 
       
  1131 	if (prev_payload != 0)
       
  1132 	{
       
  1133 		prev_payload->set_next_payload_with_same_tlv_type(tlv);
       
  1134 	}
       
  1135 }
       
  1136 
       
  1137 //--------------------------------------------------
       
  1138 
       
  1139 EAP_FUNC_EXPORT wai_variable_data_c * wai_variable_data_c::copy() const
       
  1140 {
       
  1141 	wai_variable_data_c * new_data = new wai_variable_data_c(m_am_tools);
       
  1142 
       
  1143 	if (new_data != 0)
       
  1144 	{
       
  1145 		eap_status_e status = new_data->set_copy_of_buffer(
       
  1146 			get_payload_type(),
       
  1147 			get_data(get_data_length()),
       
  1148 			get_data_length());
       
  1149 		if (status != eap_status_ok)
       
  1150 		{
       
  1151 			delete new_data;
       
  1152 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1153 			(void) EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
  1154 			return 0;
       
  1155 		}
       
  1156 	}
       
  1157 
       
  1158 	return new_data;
       
  1159 }
       
  1160 
       
  1161 //--------------------------------------------------
       
  1162 
       
  1163 EAP_FUNC_EXPORT  void wai_variable_data_c::object_increase_reference_count()
       
  1164 {
       
  1165 }
       
  1166 
       
  1167 //--------------------------------------------------
       
  1168 
       
  1169 EAP_FUNC_EXPORT i32_t wai_variable_data_c::compare(const wai_variable_data_c * right) const
       
  1170 {
       
  1171 	if (get_payload_type() != right->get_payload_type())
       
  1172 	{
       
  1173 		return -1;
       
  1174 	}
       
  1175 	else if (get_data_length() != right->get_data_length())
       
  1176 	{
       
  1177 		return -1;
       
  1178 	}
       
  1179 	else
       
  1180 	{
       
  1181 		// Compares the (possible) header and data.
       
  1182 		return m_am_tools->memcmp(get_data(get_data_length()), right->get_data(right->get_data_length()), get_data_length());
       
  1183 	}
       
  1184 }
       
  1185 
       
  1186 //--------------------------------------------------
       
  1187 
       
  1188 EAP_FUNC_EXPORT eap_const_string wai_variable_data_c::get_wai_payload_type_string() const
       
  1189 {
       
  1190 	return wapi_strings_c::get_wai_payload_type_string(get_payload_type());
       
  1191 }
       
  1192 
       
  1193 //--------------------------------------------------
       
  1194 
       
  1195 void wai_variable_data_c::wai_variable_data_trace(abs_eap_am_tools_c * const tools, eap_format_string prefix, const wai_variable_data_c * const wai_data, const bool when_true_is_client)
       
  1196 {
       
  1197 	EAP_TRACE_DEBUG(
       
  1198 		tools,
       
  1199 		TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS,
       
  1200 		(EAPL("v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v \n")));
       
  1201 
       
  1202 	EAP_TRACE_DEBUG(
       
  1203 		tools,
       
  1204 		TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS,
       
  1205 		(EAPL("- %s %s (0x%08x): TLV type 0x%04x=%s, data length 0x%04x.\n"),
       
  1206 		prefix,
       
  1207 		((when_true_is_client) == true ? "client" : "server"),
       
  1208 		(wai_data)->get_data((wai_data)->get_data_length()),
       
  1209 		(wai_data)->get_payload_type(),
       
  1210 		wapi_strings_c::get_wai_payload_type_string((wai_data)->get_payload_type()),
       
  1211 		(wai_data)->get_data_length()));
       
  1212 
       
  1213 	EAP_TRACE_DATA_DEBUG(
       
  1214 		tools,
       
  1215 		TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS,
       
  1216 		(wapi_strings_c::get_wai_payload_type_string((wai_data)->get_payload_type()),
       
  1217 		(wai_data)->get_data((wai_data)->get_data_length()),
       
  1218 		(wai_data)->get_data_length()));
       
  1219 
       
  1220 	EAP_TRACE_DEBUG(
       
  1221 		tools,
       
  1222 		TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS,
       
  1223 		(EAPL("^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ \n")));
       
  1224 }
       
  1225 
       
  1226 //--------------------------------------------------
       
  1227 
       
  1228 #endif //#if defined(USE_WAPI_CORE)
       
  1229 
       
  1230 // End.