eapol/eapol_framework/eapol_common/type/mschapv2/core/eap_type_mschapv2_state.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 100 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 #include "eap_am_tools.h"
       
    28 #include "eap_type_mschapv2_state.h"
       
    29 
       
    30 eap_type_mschapv2_state_c::eap_type_mschapv2_state_c(abs_eap_am_tools_c * const tools, const bool client)
       
    31 : m_am_tools(tools)
       
    32 , m_is_client(client)
       
    33 , m_state(eap_type_mschapv2_state_none)
       
    34 , m_prev_state(eap_type_mschapv2_state_none)
       
    35 , m_next_state(eap_type_mschapv2_state_none)
       
    36 , m_failure_message_received(false)
       
    37 {
       
    38 	if (m_is_client)
       
    39 	{
       
    40 		m_state = eap_type_mschapv2_state_none;
       
    41 		m_prev_state = eap_type_mschapv2_state_none;
       
    42 		m_next_state = eap_type_mschapv2_state_identity_request;
       
    43 	}
       
    44 	else
       
    45 	{
       
    46 		m_state = eap_type_mschapv2_state_none;
       
    47 		m_prev_state = eap_type_mschapv2_state_none;
       
    48 		m_next_state = eap_type_mschapv2_state_identity_response;
       
    49 	}
       
    50 }
       
    51 
       
    52 EAP_FUNC_EXPORT eap_type_mschapv2_state_c::~eap_type_mschapv2_state_c()
       
    53 {
       
    54 }
       
    55 
       
    56 eap_type_mschapv2_state_variable_e eap_type_mschapv2_state_c::get_state() const
       
    57 {
       
    58 	return m_state;
       
    59 }
       
    60 
       
    61 void eap_type_mschapv2_state_c::set_state(const eap_type_mschapv2_state_variable_e new_state)
       
    62 {
       
    63 	set_state(new_state, eap_type_mschapv2_state_none);
       
    64 }
       
    65 
       
    66 void eap_type_mschapv2_state_c::set_state(
       
    67 	const eap_type_mschapv2_state_variable_e new_state,
       
    68 	const eap_type_mschapv2_state_variable_e new_next_state)
       
    69 
       
    70 {
       
    71 	EAP_TRACE_DEBUG(
       
    72 		m_am_tools, 
       
    73 		TRACE_FLAGS_DEFAULT, 
       
    74 		(EAPL("eap_type_mschapv2_state_c::set_state(): this = 0x%08x, previous state %d, new state %d, new next state %d\n"),
       
    75 		this,
       
    76 		m_prev_state,
       
    77 		new_state,
       
    78 		new_next_state));
       
    79 
       
    80 	m_prev_state = m_state;
       
    81 	m_state = new_state;
       
    82 	m_next_state = new_next_state;
       
    83 }
       
    84 
       
    85 bool eap_type_mschapv2_state_c::is_valid_state(const eap_type_mschapv2_state_variable_e new_state) const
       
    86 {
       
    87 	EAP_TRACE_DEBUG(
       
    88 		m_am_tools, 
       
    89 		TRACE_FLAGS_DEFAULT, 
       
    90 		(EAPL("eap_type_mschapv2_state_c::is_valid_state(): this = 0x%08x, previous state %d, state %d, new state %d, new next state %d\n"),
       
    91 		this,
       
    92 		m_prev_state,
       
    93 		m_state,
       
    94 		new_state,
       
    95 		m_next_state));
       
    96 
       
    97 	if (m_is_client) // Client
       
    98 	{
       
    99 		if (new_state == eap_type_mschapv2_state_identity_request)
       
   100 		{
       
   101 			return true;
       
   102 		}
       
   103 
       
   104 		// Check validity against (current) state.
       
   105 		// If it fails then against previous state (in case of resending)
       
   106 
       
   107 		switch (m_state)
       
   108 		{
       
   109 		case eap_type_mschapv2_state_none:
       
   110 			if (new_state == eap_type_mschapv2_state_challenge_request)
       
   111 			{
       
   112 				return true;
       
   113 			}
       
   114 			break;
       
   115 
       
   116 		case eap_type_mschapv2_state_identity_request:
       
   117 			if (new_state == eap_type_mschapv2_state_challenge_request)
       
   118 			{
       
   119 				return true;
       
   120 			}
       
   121 			break;
       
   122 
       
   123 		case eap_type_mschapv2_state_challenge_request:
       
   124 			if (new_state == eap_type_mschapv2_state_success_request
       
   125 				|| new_state == eap_type_mschapv2_state_failure_request
       
   126 				|| new_state == eap_type_mschapv2_state_failure) // non-retryable error in Windows XP SP1
       
   127 			{
       
   128 				return true;
       
   129 			}
       
   130 			break;
       
   131 
       
   132 		case eap_type_mschapv2_state_failure_request:
       
   133 			if (new_state == eap_type_mschapv2_state_failure)
       
   134 			{
       
   135 				return true;
       
   136 			}
       
   137 			break;
       
   138 
       
   139 		case eap_type_mschapv2_state_success_request:
       
   140 			if (new_state == eap_type_mschapv2_state_success)
       
   141 			{
       
   142 				return true;
       
   143 			}
       
   144 			break;
       
   145 
       
   146 		case eap_type_mschapv2_state_change_password_request:
       
   147 			if (new_state == eap_type_mschapv2_state_success_request
       
   148 				|| new_state == eap_type_mschapv2_state_failure_request
       
   149 				|| new_state == eap_type_mschapv2_state_failure) // non-retryable error in Windows XP SP1
       
   150 			{
       
   151 				return true;
       
   152 			}
       
   153 			break;
       
   154 
       
   155 		case eap_type_mschapv2_state_success:
       
   156 		case eap_type_mschapv2_state_failure:
       
   157 			// Session is ended
       
   158 
       
   159 			EAP_TRACE_DEBUG(
       
   160 				m_am_tools, 
       
   161 				TRACE_FLAGS_DEFAULT, 
       
   162 				(EAPL("WARNING: eap_type_mschapv2_state_c::is_valid_state(): returns false: this = 0x%08x, previous state %d, state %d, new state %d, new next state %d\n"),
       
   163 				this,
       
   164 				m_prev_state,
       
   165 				m_state,
       
   166 				new_state,
       
   167 				m_next_state));
       
   168 
       
   169 			return false;
       
   170 
       
   171 		default:
       
   172 			;
       
   173 		}
       
   174 
       
   175 	}
       
   176 
       
   177 	else // Server
       
   178 	{
       
   179 		switch (m_state)
       
   180 		{
       
   181 		case eap_type_mschapv2_state_none:
       
   182 			if (new_state == eap_type_mschapv2_state_identity_response)
       
   183 			{
       
   184 				return true;
       
   185 			}
       
   186 			break;
       
   187 
       
   188 		case eap_type_mschapv2_state_identity_response:
       
   189 			if (new_state == eap_type_mschapv2_state_challenge_response)
       
   190 			{
       
   191 				return true;
       
   192 			}
       
   193 			break;
       
   194 
       
   195 		case eap_type_mschapv2_state_challenge_response:
       
   196 			if (m_next_state == new_state)
       
   197 			{
       
   198 				return true;
       
   199 			}
       
   200 			break;
       
   201 		case eap_type_mschapv2_state_change_password_response:
       
   202 			if (m_next_state == new_state)
       
   203 			{
       
   204 				return true;
       
   205 			}
       
   206 			break;
       
   207 
       
   208 		case eap_type_mschapv2_state_success_response:
       
   209 		case eap_type_mschapv2_state_failure_response:
       
   210 			// Session is ended
       
   211 
       
   212 			EAP_TRACE_DEBUG(
       
   213 				m_am_tools, 
       
   214 				TRACE_FLAGS_DEFAULT, 
       
   215 				(EAPL("WARNING: eap_type_mschapv2_state_c::is_valid_state(): returns false: this = 0x%08x, previous state %d, state %d, new state %d, new next state %d\n"),
       
   216 				this,
       
   217 				m_prev_state,
       
   218 				m_state,
       
   219 				new_state,
       
   220 				m_next_state));
       
   221 
       
   222 			return false;
       
   223 
       
   224 		default:
       
   225 			;
       
   226 		}
       
   227 	}
       
   228 	return false;
       
   229 }
       
   230 
       
   231 void eap_type_mschapv2_state_c::set_failure_message_received()
       
   232 {
       
   233 	EAP_TRACE_DEBUG(
       
   234 		m_am_tools, 
       
   235 		TRACE_FLAGS_DEFAULT, 
       
   236 		(EAPL("eap_type_mschapv2_state_c::set_failure_message_received(): this = 0x%08x, previous state %d, state %d, new next state %d\n"),
       
   237 		this,
       
   238 		m_prev_state,
       
   239 		m_state,
       
   240 		m_next_state));
       
   241 
       
   242 	m_failure_message_received = true;
       
   243 }
       
   244 
       
   245 void eap_type_mschapv2_state_c::unset_failure_message_received()
       
   246 {
       
   247 	EAP_TRACE_DEBUG(
       
   248 		m_am_tools, 
       
   249 		TRACE_FLAGS_DEFAULT, 
       
   250 		(EAPL("eap_type_mschapv2_state_c::unset_failure_message_received(): this = 0x%08x, previous state %d, state %d, new next state %d\n"),
       
   251 		this,
       
   252 		m_prev_state,
       
   253 		m_state,
       
   254 		m_next_state));
       
   255 
       
   256 	m_failure_message_received = false;
       
   257 }
       
   258 
       
   259 void eap_type_mschapv2_state_c::cancel_eap_failure_timer()
       
   260 {
       
   261 }