eapol/eapol_framework/wapi_common/src/ec_cs_tlv_message.cpp
changeset 17 8840d3e38314
equal deleted inserted replaced
2:1c7bc153c08e 17:8840d3e38314
       
     1 /*
       
     2 * ============================================================================
       
     3 *  Name        : ./accesssec/eapol/eapol_framework/wapi_common/src/ec_cs_tlv_message.cpp
       
     4 *  Part of     : WAPI / WAPI       *** Info from the SWAD
       
     5 *  Description : WAPI authentication
       
     6 *  Version     : %version: 6 % << 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 704 
       
    24 	#undef EAP_FILE_NUMBER_DATE 
       
    25 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    26 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    27 
       
    28 #if defined(USE_WAPI_CORE)
       
    29 
       
    30 #include "eap_am_memory.h"
       
    31 #include "eap_tools.h"
       
    32 #include "eap_array.h"
       
    33 #include "ec_cs_tlv_message.h"
       
    34 
       
    35 /** @file */
       
    36 
       
    37 
       
    38 //--------------------------------------------------
       
    39 
       
    40 EAP_FUNC_EXPORT ec_cs_tlv_message_c::~ec_cs_tlv_message_c()
       
    41 {
       
    42 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    43 
       
    44 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    45 }
       
    46 
       
    47 //--------------------------------------------------
       
    48 
       
    49 EAP_FUNC_EXPORT ec_cs_tlv_message_c::ec_cs_tlv_message_c(
       
    50 	abs_eap_am_tools_c * const tools,
       
    51 	const bool is_client)
       
    52 	: m_am_tools(tools)
       
    53 	, m_message_data(tools)
       
    54 	, m_is_client(is_client)
       
    55 {
       
    56 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    57 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    58 }
       
    59 
       
    60 //--------------------------------------------------
       
    61 
       
    62 EAP_FUNC_EXPORT eap_status_e ec_cs_tlv_message_c::reset()
       
    63 {
       
    64 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    65 
       
    66 	eap_status_e status = m_message_data.reset();
       
    67 
       
    68 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    69 	return EAP_STATUS_RETURN(m_am_tools, status);
       
    70 }
       
    71 
       
    72 //--------------------------------------------------
       
    73 
       
    74 EAP_FUNC_EXPORT eap_status_e ec_cs_tlv_message_c::set_ec_cs_message_data(
       
    75 	eap_variable_data_c * const ec_cs_message_data)
       
    76 {
       
    77 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    78 
       
    79 	eap_status_e status = m_message_data.set_copy_of_buffer(ec_cs_message_data);
       
    80 	if (status != eap_status_ok)
       
    81 	{
       
    82 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    83 		return EAP_STATUS_RETURN(m_am_tools, status);
       
    84 	}
       
    85 
       
    86 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    87 	return EAP_STATUS_RETURN(m_am_tools, status);
       
    88 }
       
    89 
       
    90 //--------------------------------------------------
       
    91 
       
    92 EAP_FUNC_EXPORT eap_variable_data_c * ec_cs_tlv_message_c::get_ec_cs_message_data()
       
    93 {
       
    94 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    95 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    96 	return &m_message_data;
       
    97 }
       
    98 
       
    99 //--------------------------------------------------
       
   100 
       
   101 EAP_FUNC_EXPORT eap_status_e ec_cs_tlv_message_c::add_padding(const u32_t block_size)
       
   102 {
       
   103 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   104 
       
   105 	eap_status_e status = eap_status_ok;
       
   106 
       
   107 	u32_t data_length = m_message_data.get_data_length();
       
   108 	u32_t remaining_bytes = data_length % block_size;
       
   109 
       
   110 	{
       
   111 		const u32_t padding_length = block_size - remaining_bytes;
       
   112 
       
   113 		status = m_message_data.set_buffer_length(data_length + padding_length);
       
   114 		if (status != eap_status_ok)
       
   115 		{
       
   116 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   117 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   118 		}
       
   119 
       
   120 		status = m_message_data.set_data_length(data_length + padding_length);
       
   121 		if (status != eap_status_ok)
       
   122 		{
       
   123 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   124 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   125 		}
       
   126 
       
   127 		const u8_t padding_byte = static_cast<u8_t>(padding_length);
       
   128 
       
   129 		m_am_tools->memset(m_message_data.get_data_offset(data_length, padding_length), padding_byte, padding_length);
       
   130 
       
   131 		EAP_TRACE_DEBUG(
       
   132 			m_am_tools,
       
   133 			TRACE_FLAGS_DEFAULT,
       
   134 			(EAPL("EC-CS: %s: message_function: ec_cs_tlv_message_c::add_padding(): %d bytes\n"),
       
   135 			(m_is_client == true ? "client": "server"),
       
   136 			padding_length));
       
   137 	}
       
   138 
       
   139 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   140 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   141 }
       
   142 
       
   143 //--------------------------------------------------
       
   144 
       
   145 EAP_FUNC_EXPORT bool ec_cs_tlv_message_c::get_is_valid()
       
   146 {
       
   147 	return m_message_data.get_is_valid();
       
   148 }
       
   149 
       
   150 //--------------------------------------------------
       
   151 
       
   152 #endif //#if defined(USE_WAPI_CORE)
       
   153 
       
   154 // End.