eapol/eapol_framework/eapol_common/core/eapol_rsna_key_data_gtk_header.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 53 
       
    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_rsna_key_data_gtk_header.h"
       
    30 
       
    31 
       
    32 //------------------------------------------------------
       
    33 
       
    34 // 
       
    35 eapol_rsna_key_data_gtk_header_c::~eapol_rsna_key_data_gtk_header_c()
       
    36 {
       
    37 }
       
    38 
       
    39 //------------------------------------------------------
       
    40 
       
    41 // 
       
    42 eapol_rsna_key_data_gtk_header_c::eapol_rsna_key_data_gtk_header_c(
       
    43 	abs_eap_am_tools_c * const tools,
       
    44 	void * const header_begin,
       
    45 	const u32_t header_buffer_length)
       
    46 	: eap_general_header_base_c(tools, header_begin, header_buffer_length)
       
    47 	, m_am_tools(tools)
       
    48 {
       
    49 }
       
    50 
       
    51 //------------------------------------------------------
       
    52 
       
    53 // 
       
    54 u8_t eapol_rsna_key_data_gtk_header_c::get_key_index() const
       
    55 {
       
    56 	const u8_t * const data = get_header_offset(m_offset_flags, EAPOL_RSNA_KEY_DATA_FLAGS_FIELD_SIZE);
       
    57 	if (data != 0)
       
    58 	{
       
    59 		return static_cast<u8_t>(((*data) & EAPOL_RSNA_KEY_DATA_GTK_INDEX_MASK) >> EAPOL_RSNA_KEY_DATA_GTK_INDEX_SHIFT);
       
    60 	}
       
    61 	else
       
    62 	{
       
    63 		return EAPOL_RSNA_KEY_DATA_INVALID_GTK_INDEX;
       
    64 	}
       
    65 }
       
    66 
       
    67 //------------------------------------------------------
       
    68 
       
    69 // 
       
    70 bool eapol_rsna_key_data_gtk_header_c::get_tx_bit() const
       
    71 {
       
    72 	const u8_t * const data = get_header_offset(m_offset_flags, EAPOL_RSNA_KEY_DATA_FLAGS_FIELD_SIZE);
       
    73 	if (data != 0)
       
    74 	{
       
    75 		u8_t flag = static_cast<u8_t>(((*data) & EAPOL_RSNA_KEY_DATA_TX_MASK) >> EAPOL_RSNA_KEY_DATA_TX_SHIFT);
       
    76 		if (flag != 0)
       
    77 		{
       
    78 			return true;
       
    79 		}
       
    80 		else
       
    81 		{
       
    82 			return false;
       
    83 		}
       
    84 	}
       
    85 	else
       
    86 	{
       
    87 		return false;
       
    88 	}
       
    89 }
       
    90 
       
    91 //------------------------------------------------------
       
    92 
       
    93 // 
       
    94 u8_t * eapol_rsna_key_data_gtk_header_c::get_gtk_offset(const u32_t offset, const u32_t contignuous_bytes) const
       
    95 {
       
    96 	u32_t GTK_buffer_length = get_header_buffer_length() - get_header_length();
       
    97 
       
    98 	if (GTK_buffer_length >= offset+contignuous_bytes)
       
    99 	{
       
   100 		// This is pointer to the offset of the Data.
       
   101 		u8_t * const data = get_header_offset(m_offset_gtk, offset+contignuous_bytes);
       
   102 		if (data != 0)
       
   103 		{
       
   104 			return &data[offset];
       
   105 		}
       
   106 		else
       
   107 		{
       
   108 			return 0;
       
   109 		}
       
   110 	}
       
   111 	else
       
   112 	{
       
   113 		EAP_ASSERT_ALWAYS(GTK_buffer_length >= offset+contignuous_bytes);
       
   114 	}
       
   115 	return 0;
       
   116 }
       
   117 
       
   118 //------------------------------------------------------
       
   119 
       
   120 // 
       
   121 u8_t * eapol_rsna_key_data_gtk_header_c::get_gtk(const u32_t contignuous_bytes) const
       
   122 {
       
   123 	return get_gtk_offset(0u, contignuous_bytes);
       
   124 }
       
   125 
       
   126 //------------------------------------------------------
       
   127 
       
   128 // 
       
   129 u16_t eapol_rsna_key_data_gtk_header_c::get_header_length()
       
   130 {
       
   131 	return m_offset_gtk;
       
   132 }
       
   133 
       
   134 //------------------------------------------------------
       
   135 
       
   136 // 
       
   137 eap_status_e eapol_rsna_key_data_gtk_header_c::set_key_index(const u32_t index)
       
   138 {
       
   139 	u8_t * const data = get_header_offset(m_offset_flags, EAPOL_RSNA_KEY_DATA_FLAGS_FIELD_SIZE);
       
   140 	if (data != 0)
       
   141 	{
       
   142 		*data = static_cast<u8_t>(((*data) && ~EAPOL_RSNA_KEY_DATA_GTK_INDEX_MASK)
       
   143 								  | ((index <<EAPOL_RSNA_KEY_DATA_GTK_INDEX_SHIFT) & EAPOL_RSNA_KEY_DATA_GTK_INDEX_MASK));
       
   144 		return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   145 	}
       
   146 	else
       
   147 	{
       
   148 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   149 	}
       
   150 }
       
   151 
       
   152 //------------------------------------------------------
       
   153 
       
   154 // 
       
   155 eap_status_e eapol_rsna_key_data_gtk_header_c::set_tx(const bool tx)
       
   156 {
       
   157 	u8_t * const data = get_header_offset(m_offset_flags, EAPOL_RSNA_KEY_DATA_FLAGS_FIELD_SIZE);
       
   158 	if (data != 0)
       
   159 	{
       
   160 		*data = static_cast<u8_t>(((*data) && ~EAPOL_RSNA_KEY_DATA_TX_MASK)
       
   161 								  | ((tx <<EAPOL_RSNA_KEY_DATA_TX_SHIFT) & EAPOL_RSNA_KEY_DATA_TX_MASK));
       
   162 		return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   163 	}
       
   164 	else
       
   165 	{
       
   166 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   167 	}
       
   168 }
       
   169 
       
   170 //------------------------------------------------------
       
   171 
       
   172 // 
       
   173 eap_status_e eapol_rsna_key_data_gtk_header_c::set_reserved_flag(const u32_t index)
       
   174 {
       
   175 	u8_t * const data = get_header_offset(m_offset_flags, EAPOL_RSNA_KEY_DATA_FLAGS_FIELD_SIZE);
       
   176 	if (data != 0)
       
   177 	{
       
   178 		*data = static_cast<u8_t>(((*data) && ~EAPOL_RSNA_KEY_DATA_RESERVED_MASK)
       
   179 								  | ((index <<EAPOL_RSNA_KEY_DATA_RESERVED_SHIFT) & EAPOL_RSNA_KEY_DATA_RESERVED_MASK));
       
   180 		return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   181 	}
       
   182 	else
       
   183 	{
       
   184 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   185 	}
       
   186 }
       
   187 
       
   188 //------------------------------------------------------
       
   189 
       
   190 // 
       
   191 eap_status_e eapol_rsna_key_data_gtk_header_c::set_reserved_field(const u32_t reserved)
       
   192 {
       
   193 	u8_t * const data = get_header_offset(m_offset_reserved, EAPOL_RSNA_KEY_DATA_RESERVED_FIELD_SIZE);
       
   194 	if (data != 0)
       
   195 	{
       
   196 		*data = static_cast<u8_t>(reserved);
       
   197 		return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   198 	}
       
   199 	else
       
   200 	{
       
   201 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   202 	}
       
   203 }
       
   204 
       
   205 //------------------------------------------------------
       
   206 
       
   207 // 
       
   208 eap_status_e eapol_rsna_key_data_gtk_header_c::check_header() const
       
   209 {
       
   210 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   211 }
       
   212 
       
   213 //------------------------------------------------------
       
   214 
       
   215 // 
       
   216 eap_status_e eapol_rsna_key_data_gtk_header_c::reset_header()
       
   217 {
       
   218 	eap_status_e status(eap_status_process_general_error);
       
   219 
       
   220 	m_am_tools->memset(
       
   221 		get_header_buffer(get_header_buffer_length()),
       
   222 		0ul,
       
   223 		get_header_buffer_length());
       
   224 
       
   225 	status = set_key_index(0ul);
       
   226 	if (status != eap_status_ok)
       
   227 	{
       
   228 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   229 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   230 	}
       
   231 
       
   232 	status = set_tx(false);
       
   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 	status = set_reserved_flag(0ul);
       
   240 	if (status != eap_status_ok)
       
   241 	{
       
   242 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   243 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   244 	}
       
   245 
       
   246 	status = set_reserved_field(0ul);
       
   247 	if (status != eap_status_ok)
       
   248 	{
       
   249 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   250 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   251 	}
       
   252 
       
   253 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   254 }
       
   255 
       
   256 //------------------------------------------------------
       
   257 
       
   258 
       
   259 
       
   260 // End.