eapol/eapol_framework/eapol_common/common/eapol_session_key.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // This is enumeration of EAPOL source code.
       
    20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    21 	#undef EAP_FILE_NUMBER_ENUM
       
    22 	#define EAP_FILE_NUMBER_ENUM 34 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 
       
    28 
       
    29 #include "eapol_session_key.h"
       
    30 #include "eap_tools.h"
       
    31 
       
    32 
       
    33 //--------------------------------------------------
       
    34 
       
    35 EAP_FUNC_EXPORT eapol_session_key_c::~eapol_session_key_c()
       
    36 {
       
    37 }
       
    38 
       
    39 //--------------------------------------------------
       
    40 
       
    41 EAP_FUNC_EXPORT eapol_session_key_c::eapol_session_key_c(
       
    42 		abs_eap_am_tools_c * const tools,
       
    43 		eap_variable_data_c * const key, ///< Here is the key.
       
    44 		const eapol_key_type_e key_type, ///< This the type of the key.
       
    45 		const u32_t key_index, ///< This is the index of the key.
       
    46 		const bool key_tx_bit, ///< This is the TX bit of the key.
       
    47 		const u8_t * const key_RSC, ///< This is the RSC counter
       
    48 		const u32_t key_RSC_size ///< This is the size of RSC counter
       
    49 		)
       
    50 	: m_am_tools(tools)
       
    51 	  , m_key(tools)
       
    52 	  , m_sequence_number(tools)
       
    53 	  , m_key_type(key_type)
       
    54 	  , m_key_index(key_index)
       
    55 	  , m_key_tx_bit(key_tx_bit)
       
    56 	  , m_is_valid(false)
       
    57 {
       
    58 	eap_status_e status = m_key.set_copy_of_buffer(key);
       
    59 	if (status != eap_status_ok)
       
    60 	{
       
    61 		return;
       
    62 	}
       
    63 
       
    64 	if (key_RSC != 0
       
    65 		&& key_RSC_size > 0ul)
       
    66 	{
       
    67 		status = m_sequence_number.set_copy_of_buffer(
       
    68 			key_RSC,
       
    69 			key_RSC_size);
       
    70 		if (status != eap_status_ok)
       
    71 		{
       
    72 			return;
       
    73 		}
       
    74 	}
       
    75 
       
    76 	m_is_valid = true;
       
    77 }
       
    78 
       
    79 //--------------------------------------------------
       
    80 
       
    81 EAP_FUNC_EXPORT eapol_session_key_c::eapol_session_key_c(
       
    82 	abs_eap_am_tools_c * const tools
       
    83 	)
       
    84 	: m_am_tools(tools)
       
    85 	  , m_key(tools)
       
    86 	  , m_sequence_number(tools)
       
    87 	  , m_key_type(eapol_key_type_last_type)
       
    88 	  , m_key_index(0ul)
       
    89 	  , m_key_tx_bit(false)
       
    90 	  , m_is_valid(true)
       
    91 {
       
    92 }
       
    93 
       
    94 //--------------------------------------------------
       
    95 
       
    96 EAP_FUNC_EXPORT const eap_variable_data_c * eapol_session_key_c::get_key() const
       
    97 {
       
    98 	return &m_key;
       
    99 }
       
   100 
       
   101 //--------------------------------------------------
       
   102 
       
   103 EAP_FUNC_EXPORT const eap_variable_data_c * eapol_session_key_c::get_sequence_number() const
       
   104 {
       
   105 	return &m_sequence_number;
       
   106 }
       
   107 
       
   108 //--------------------------------------------------
       
   109 
       
   110 EAP_FUNC_EXPORT eapol_key_type_e eapol_session_key_c::get_key_type() const
       
   111 {
       
   112 	return m_key_type;
       
   113 }
       
   114 
       
   115 //--------------------------------------------------
       
   116 
       
   117 EAP_FUNC_EXPORT u32_t eapol_session_key_c::get_key_index() const
       
   118 {
       
   119 	return m_key_index;
       
   120 }
       
   121 
       
   122 //--------------------------------------------------
       
   123 
       
   124 EAP_FUNC_EXPORT bool eapol_session_key_c::get_key_tx_bit() const
       
   125 {
       
   126 	return m_key_tx_bit;
       
   127 }
       
   128 
       
   129 //--------------------------------------------------
       
   130 
       
   131 EAP_FUNC_EXPORT bool eapol_session_key_c::get_is_valid() const
       
   132 {
       
   133 	return m_is_valid;
       
   134 }
       
   135 
       
   136 //--------------------------------------------------
       
   137 
       
   138 EAP_FUNC_EXPORT eap_status_e eapol_session_key_c::set_key(const eap_variable_data_c * const key)
       
   139 {
       
   140 	return m_key.set_copy_of_buffer(key);
       
   141 }
       
   142 
       
   143 //--------------------------------------------------
       
   144 
       
   145 EAP_FUNC_EXPORT eap_status_e eapol_session_key_c::set_sequence_number(eap_variable_data_c * const sequence_number)
       
   146 {
       
   147 	return m_sequence_number.set_copy_of_buffer(sequence_number);
       
   148 }
       
   149 
       
   150 //--------------------------------------------------
       
   151 
       
   152 EAP_FUNC_EXPORT void eapol_session_key_c::set_key_type(const eapol_key_type_e key_type)
       
   153 {
       
   154 	m_key_type = key_type;
       
   155 }
       
   156 
       
   157 //--------------------------------------------------
       
   158 
       
   159 EAP_FUNC_EXPORT void eapol_session_key_c::set_key_index(const u32_t key_index)
       
   160 {
       
   161 	m_key_index = key_index;
       
   162 }
       
   163 
       
   164 //--------------------------------------------------
       
   165 
       
   166 EAP_FUNC_EXPORT void eapol_session_key_c::set_key_tx_bit(const bool key_tx_bit)
       
   167 {
       
   168 	m_key_tx_bit = key_tx_bit;
       
   169 }
       
   170 
       
   171 //--------------------------------------------------
       
   172 
       
   173 EAP_FUNC_EXPORT eap_const_string eapol_session_key_c::get_eapol_key_type_string(
       
   174 	const eapol_key_type_e key_type)
       
   175 {
       
   176 #if defined(USE_EAP_TRACE_STRINGS)
       
   177 	EAP_IF_RETURN_STRING(key_type, eapol_key_type_broadcast)
       
   178 	else EAP_IF_RETURN_STRING(key_type, eapol_key_type_unicast)
       
   179 #if defined(EAP_USE_WPXM)
       
   180 	else EAP_IF_RETURN_STRING(key_type, eapol_key_type_wpxm_wpxk1)
       
   181 	else EAP_IF_RETURN_STRING(key_type, eapol_key_type_wpxm_wpxk2)
       
   182 #endif //#if defined(EAP_USE_WPXM)
       
   183 	else EAP_IF_RETURN_STRING(key_type, eapol_key_type_pmkid)
       
   184 	else EAP_IF_RETURN_STRING(key_type, eapol_key_type_last_type)
       
   185 	else
       
   186 #endif // #if defined(USE_EAP_TRACE_STRINGS)
       
   187 	{
       
   188 		EAP_UNREFERENCED_PARAMETER(key_type);
       
   189 
       
   190 		return EAPL("Unknown EAPOL-Key type");
       
   191 	}
       
   192 }
       
   193 
       
   194 //--------------------------------------------------
       
   195 
       
   196 
       
   197 
       
   198 // End.