eapol/eapol_framework/eapol_common/type/mschapv2/core/eap_type_mschapv2_state.cpp
changeset 26 9abfd4f00d37
parent 2 1c7bc153c08e
child 46 c74b3d9f6b9e
equal deleted inserted replaced
25:e03a3db4489e 26:9abfd4f00d37
    14 * Description:  EAP and WLAN authentication protocols.
    14 * Description:  EAP and WLAN authentication protocols.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 10.1.3 %
    19 * %version: %
    20 */
    20 */
    21 
    21 
    22 // This is enumeration of EAPOL source code.
    22 // This is enumeration of EAPOL source code.
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    24 	#undef EAP_FILE_NUMBER_ENUM
    24 	#undef EAP_FILE_NUMBER_ENUM
    36 , m_state(eap_type_mschapv2_state_none)
    36 , m_state(eap_type_mschapv2_state_none)
    37 , m_prev_state(eap_type_mschapv2_state_none)
    37 , m_prev_state(eap_type_mschapv2_state_none)
    38 , m_next_state(eap_type_mschapv2_state_none)
    38 , m_next_state(eap_type_mschapv2_state_none)
    39 , m_failure_message_received(false)
    39 , m_failure_message_received(false)
    40 {
    40 {
       
    41 	reset();
       
    42 }
       
    43 
       
    44 EAP_FUNC_EXPORT eap_type_mschapv2_state_c::~eap_type_mschapv2_state_c()
       
    45 {
       
    46 }
       
    47 
       
    48 eap_type_mschapv2_state_variable_e eap_type_mschapv2_state_c::get_state() const
       
    49 {
       
    50 	return m_state;
       
    51 }
       
    52 
       
    53 void eap_type_mschapv2_state_c::reset()
       
    54 {
    41 	if (m_is_client)
    55 	if (m_is_client)
    42 	{
    56 	{
    43 		m_state = eap_type_mschapv2_state_none;
    57 		m_state = eap_type_mschapv2_state_none;
    44 		m_prev_state = eap_type_mschapv2_state_none;
    58 		m_prev_state = eap_type_mschapv2_state_none;
    45 		m_next_state = eap_type_mschapv2_state_identity_request;
    59 		m_next_state = eap_type_mschapv2_state_identity_request;
    50 		m_prev_state = eap_type_mschapv2_state_none;
    64 		m_prev_state = eap_type_mschapv2_state_none;
    51 		m_next_state = eap_type_mschapv2_state_identity_response;
    65 		m_next_state = eap_type_mschapv2_state_identity_response;
    52 	}
    66 	}
    53 }
    67 }
    54 
    68 
    55 EAP_FUNC_EXPORT eap_type_mschapv2_state_c::~eap_type_mschapv2_state_c()
       
    56 {
       
    57 }
       
    58 
       
    59 eap_type_mschapv2_state_variable_e eap_type_mschapv2_state_c::get_state() const
       
    60 {
       
    61 	return m_state;
       
    62 }
       
    63 
       
    64 void eap_type_mschapv2_state_c::set_state(const eap_type_mschapv2_state_variable_e new_state)
    69 void eap_type_mschapv2_state_c::set_state(const eap_type_mschapv2_state_variable_e new_state)
    65 {
    70 {
    66 	set_state(new_state, eap_type_mschapv2_state_none);
    71 	set_state(new_state, eap_type_mschapv2_state_none);
    67 }
    72 }
    68 
    73 
    72 
    77 
    73 {
    78 {
    74 	EAP_TRACE_DEBUG(
    79 	EAP_TRACE_DEBUG(
    75 		m_am_tools, 
    80 		m_am_tools, 
    76 		TRACE_FLAGS_DEFAULT, 
    81 		TRACE_FLAGS_DEFAULT, 
    77 		(EAPL("eap_type_mschapv2_state_c::set_state(): this = 0x%08x, previous state %d, new state %d, new next state %d\n"),
    82 		(EAPL("eap_type_mschapv2_state_c::set_state(): this = 0x%08x, previous state %d=%s, new state %d=%s, new next state %d=%s\n"),
    78 		this,
    83 		 this,
    79 		m_prev_state,
    84 		 m_prev_state,
    80 		new_state,
    85 		 get_state_string(m_prev_state),
    81 		new_next_state));
    86 		 new_state,
       
    87 		 get_state_string(new_state),
       
    88 		 new_next_state,
       
    89 		 get_state_string(m_next_state)));
    82 
    90 
    83 	m_prev_state = m_state;
    91 	m_prev_state = m_state;
    84 	m_state = new_state;
    92 	m_state = new_state;
    85 	m_next_state = new_next_state;
    93 	m_next_state = new_next_state;
    86 }
    94 }
    88 bool eap_type_mschapv2_state_c::is_valid_state(const eap_type_mschapv2_state_variable_e new_state) const
    96 bool eap_type_mschapv2_state_c::is_valid_state(const eap_type_mschapv2_state_variable_e new_state) const
    89 {
    97 {
    90 	EAP_TRACE_DEBUG(
    98 	EAP_TRACE_DEBUG(
    91 		m_am_tools, 
    99 		m_am_tools, 
    92 		TRACE_FLAGS_DEFAULT, 
   100 		TRACE_FLAGS_DEFAULT, 
    93 		(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"),
   101 		(EAPL("eap_type_mschapv2_state_c::is_valid_state(): this = 0x%08x, previous state %d=%s, state %d=%s, new state %d=%s, new next state %d\n"),
    94 		this,
   102 		 this,
    95 		m_prev_state,
   103 		 m_prev_state,
    96 		m_state,
   104 		 get_state_string(m_prev_state),
    97 		new_state,
   105 		 m_state,
    98 		m_next_state));
   106 		 get_state_string(m_state),
       
   107 		 new_state,
       
   108 		 get_state_string(new_state),
       
   109 		 m_next_state,
       
   110 		 get_state_string(m_next_state)));
    99 
   111 
   100 	if (m_is_client) // Client
   112 	if (m_is_client) // Client
   101 	{
   113 	{
   102 		if (new_state == eap_type_mschapv2_state_identity_request)
   114 		if (new_state == eap_type_mschapv2_state_identity_request)
   103 		{
   115 		{
   160 			// Session is ended
   172 			// Session is ended
   161 
   173 
   162 			EAP_TRACE_DEBUG(
   174 			EAP_TRACE_DEBUG(
   163 				m_am_tools, 
   175 				m_am_tools, 
   164 				TRACE_FLAGS_DEFAULT, 
   176 				TRACE_FLAGS_DEFAULT, 
   165 				(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"),
   177 				(EAPL("WARNING: eap_type_mschapv2_state_c::is_valid_state(): returns false: this = 0x%08x, previous state %d=%s, state %d=%s, new state %d=%s, new next state %d=%s\n"),
   166 				this,
   178 				 this,
   167 				m_prev_state,
   179 				 m_prev_state,
   168 				m_state,
   180 				 get_state_string(m_prev_state),
   169 				new_state,
   181 				 m_state,
   170 				m_next_state));
   182 				 get_state_string(m_state),
       
   183 				 new_state,
       
   184 				 get_state_string(new_state),
       
   185 				 m_next_state,
       
   186 				 get_state_string(m_next_state)));
   171 
   187 
   172 			return false;
   188 			return false;
   173 
   189 
   174 		default:
   190 		default:
   175 			;
   191 			;
   213 			// Session is ended
   229 			// Session is ended
   214 
   230 
   215 			EAP_TRACE_DEBUG(
   231 			EAP_TRACE_DEBUG(
   216 				m_am_tools, 
   232 				m_am_tools, 
   217 				TRACE_FLAGS_DEFAULT, 
   233 				TRACE_FLAGS_DEFAULT, 
   218 				(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"),
   234 				(EAPL("WARNING: eap_type_mschapv2_state_c::is_valid_state(): returns false: this = 0x%08x, previous state %d=%s, state %d=%s, new state %d=%s, new next state %d=%s\n"),
   219 				this,
   235 				 this,
   220 				m_prev_state,
   236 				 m_prev_state,
   221 				m_state,
   237 				 get_state_string(m_prev_state),
   222 				new_state,
   238 				 m_state,
   223 				m_next_state));
   239 				 get_state_string(m_state),
       
   240 				 new_state,
       
   241 				 get_state_string(new_state),
       
   242 				 m_next_state,
       
   243 				 get_state_string(m_next_state)));
   224 
   244 
   225 			return false;
   245 			return false;
   226 
   246 
   227 		default:
   247 		default:
   228 			;
   248 			;
   234 void eap_type_mschapv2_state_c::set_failure_message_received()
   254 void eap_type_mschapv2_state_c::set_failure_message_received()
   235 {
   255 {
   236 	EAP_TRACE_DEBUG(
   256 	EAP_TRACE_DEBUG(
   237 		m_am_tools, 
   257 		m_am_tools, 
   238 		TRACE_FLAGS_DEFAULT, 
   258 		TRACE_FLAGS_DEFAULT, 
   239 		(EAPL("eap_type_mschapv2_state_c::set_failure_message_received(): this = 0x%08x, previous state %d, state %d, new next state %d\n"),
   259 		(EAPL("eap_type_mschapv2_state_c::set_failure_message_received(): this = 0x%08x, previous state %d=%s, state %d=%s, new next state %d=%s\n"),
   240 		this,
   260 		 this,
   241 		m_prev_state,
   261 		 m_prev_state,
   242 		m_state,
   262 		 get_state_string(m_prev_state),
   243 		m_next_state));
   263 		 m_state,
       
   264 		 get_state_string(m_state),
       
   265 		 m_next_state,
       
   266 		 get_state_string(m_next_state)));
   244 
   267 
   245 	m_failure_message_received = true;
   268 	m_failure_message_received = true;
   246 }
   269 }
   247 
   270 
   248 void eap_type_mschapv2_state_c::unset_failure_message_received()
   271 void eap_type_mschapv2_state_c::unset_failure_message_received()
   249 {
   272 {
   250 	EAP_TRACE_DEBUG(
   273 	EAP_TRACE_DEBUG(
   251 		m_am_tools, 
   274 		m_am_tools, 
   252 		TRACE_FLAGS_DEFAULT, 
   275 		TRACE_FLAGS_DEFAULT, 
   253 		(EAPL("eap_type_mschapv2_state_c::unset_failure_message_received(): this = 0x%08x, previous state %d, state %d, new next state %d\n"),
   276 		(EAPL("eap_type_mschapv2_state_c::unset_failure_message_received(): this = 0x%08x, previous state %d=%s, state %d=%s, new next state %d=%s\n"),
   254 		this,
   277 		 this,
   255 		m_prev_state,
   278 		 m_prev_state,
   256 		m_state,
   279 		 get_state_string(m_prev_state),
   257 		m_next_state));
   280 		 m_state,
       
   281 		 get_state_string(m_state),
       
   282 		 m_next_state,
       
   283 		 get_state_string(m_next_state)));
   258 
   284 
   259 	m_failure_message_received = false;
   285 	m_failure_message_received = false;
   260 }
   286 }
   261 
   287 
   262 void eap_type_mschapv2_state_c::cancel_eap_failure_timer()
   288 void eap_type_mschapv2_state_c::cancel_eap_failure_timer()
   263 {
   289 {
   264 }
   290 }
       
   291 
       
   292 eap_const_string eap_type_mschapv2_state_c::get_state_string(const eap_type_mschapv2_state_variable_e state)
       
   293 {
       
   294 #if defined(USE_EAP_TRACE_STRINGS)
       
   295 	EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_none)
       
   296 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_success)
       
   297 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_failure)
       
   298 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_identity_request)
       
   299 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_challenge_request)
       
   300 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_success_request)
       
   301 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_failure_request)
       
   302 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_change_password_request)
       
   303 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_identity_response)
       
   304 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_challenge_response)
       
   305 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_success_response)
       
   306 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_failure_response)
       
   307 	else EAP_IF_RETURN_STRING(state, eap_type_mschapv2_state_change_password_response)
       
   308 	else
       
   309 #endif // #if defined(USE_EAP_TRACE_STRINGS)
       
   310 	{
       
   311 		EAP_UNREFERENCED_PARAMETER(state);
       
   312 		return EAPL("Unknown EAP-MsChapv2-state");
       
   313 	}
       
   314 }
       
   315 
       
   316 
       
   317 // End