eapol/eapol_framework/eapol_common/core/eap_wimax_authentication.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2007 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 stack interface for Wimax.
       
    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 1001 
       
    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 // INCLUDE FILES
       
    29 #include <eap_am_memory.h>
       
    30 
       
    31 #include <eap_am_tools.h>
       
    32 #include <eap_variable_data.h>
       
    33 #include <eap_tools.h>
       
    34 #include "eap_type_all.h"
       
    35 
       
    36 #include "eap_wimax_authentication.h"
       
    37 #include "eap_session_core.h"
       
    38 #include <eap_header_string.h>
       
    39 #include <eap_rogue_ap_entry.h>
       
    40 #include <abs_eap_state_notification.h>
       
    41 #include <eap_config.h>
       
    42 #include <eap_buffer.h>
       
    43 #include <eap_state_notification.h>
       
    44 #include "eap_automatic_variable.h"
       
    45 #include <eap_am_network_id.h>
       
    46 
       
    47 #include <eap_master_session_key.h>
       
    48 #include <abs_eap_am_mutex.h>
       
    49 
       
    50 
       
    51 #if defined(USE_EAP_WIMAX_AUTHENTICATION_MUTEX)
       
    52 
       
    53 	#if defined(USE_TEST_WIMAX_AUTHENTICATION_MUTEX)
       
    54 		#error "You cannot define both USE_EAP_WIMAX_AUTHENTICATION_MUTEX and USE_TEST_WIMAX_AUTHENTICATION_MUTEX."
       
    55 	#endif
       
    56 
       
    57 	#define WAUTH_ENTER_MUTEX(tools) { tools->enter_global_mutex(); }
       
    58 
       
    59 	#define WAUTH_LEAVE_MUTEX(tools) { tools->leave_global_mutex(); }
       
    60 
       
    61 #else
       
    62 
       
    63 	#define WAUTH_ENTER_MUTEX(tools)
       
    64 
       
    65 	#define WAUTH_LEAVE_MUTEX(tools)
       
    66 
       
    67 #endif //#if defined(USE_EAP_WIMAX_AUTHENTICATION_MUTEX)
       
    68 
       
    69 
       
    70 
       
    71 // ================= MEMBER FUNCTIONS =======================
       
    72 
       
    73 EAP_FUNC_EXPORT eap_wimax_authentication_c::~eap_wimax_authentication_c()
       
    74 {
       
    75   EAP_TRACE_DEBUG
       
    76     (m_am_tools,
       
    77      TRACE_FLAGS_DEFAULT, 
       
    78      (EAPL("partner calls: eap_wimax_authentication_c::~eap_wimax_authentication_c(): this = 0x%08x\n"),
       
    79       this));
       
    80   
       
    81   EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eap_wimax_authentication_c::~eap_wimax_authentication_c()\n");
       
    82   
       
    83   EAP_ASSERT(m_shutdown_was_called == true);
       
    84 }
       
    85 
       
    86 //--------------------------------------------------
       
    87 
       
    88 EAP_FUNC_EXPORT eap_wimax_authentication_c::eap_wimax_authentication_c
       
    89 (abs_eap_am_tools_c* const tools, 
       
    90  abs_eap_wimax_authentication_c* const partner,
       
    91  // eap_wimax_authentication_c must always delete the am_wauth object
       
    92  eap_am_wimax_authentication_c* const am_wauth,
       
    93  const bool is_client_when_true)
       
    94   : m_am_tools(tools), 
       
    95     m_partner(partner),
       
    96     m_am_wauth(am_wauth),
       
    97     m_eap_core(0), // created in configure
       
    98     m_is_valid(false),
       
    99     m_is_client(is_client_when_true),
       
   100     m_shutdown_was_called(false),
       
   101     m_block_state_notifications(false)    
       
   102 {
       
   103   EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   104   
       
   105   EAP_TRACE_DEBUG
       
   106     (m_am_tools, 
       
   107      TRACE_FLAGS_DEFAULT, 
       
   108      (EAPL("starts: eap_wimax_authentication_c::eap_wimax_authentication_c(): %s, this = 0x%08x.\n"),
       
   109       (m_is_client == true) ? "client": "server",
       
   110       this));
       
   111   
       
   112   EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_wimax_authentication_c::eap_wimax_authentication_c()\n");
       
   113   
       
   114   if (m_am_wauth == 0
       
   115       || m_am_wauth->get_is_valid() == false)
       
   116     {
       
   117       // ERROR.
       
   118       if (m_am_wauth != 0)
       
   119 	{
       
   120 	  EAP_TRACE_DEBUG
       
   121 	    (m_am_tools,
       
   122 	     TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   123 	     (EAPL("calls: eap_wimax_authentication_c::eap_wimax_authentication_c(): m_am_wauth->shutdown(): %s.\n"),
       
   124 	      (is_client_when_true == true) ? "client": "server"));
       
   125 	  
       
   126 	  m_am_wauth->shutdown();
       
   127 	  delete am_wauth;
       
   128 	}
       
   129       return;
       
   130     }
       
   131   
       
   132   if (m_am_tools == 0
       
   133       || m_am_tools->get_is_valid() == false)
       
   134     {
       
   135       // ERROR.
       
   136       if (m_am_wauth != 0)
       
   137 	{
       
   138 	  EAP_TRACE_DEBUG
       
   139 	    (m_am_tools,
       
   140 	     TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   141 	     (EAPL("calls: eap_wimax_authentication_c::eap_wimax_authentication_c(): m_am_wauth->shutdown(): %s.\n"),
       
   142 	      (is_client_when_true == true) ? "client": "server"));
       
   143 	  
       
   144 	  m_am_wauth->shutdown();
       
   145 	  delete am_wauth;
       
   146 	}
       
   147       return;
       
   148     }
       
   149   
       
   150   m_is_valid = true;
       
   151 }
       
   152 
       
   153 //--------------------------------------------------
       
   154 
       
   155 EAP_FUNC_EXPORT eap_wimax_authentication_c* eap_wimax_authentication_c::new_eap_wimax_authentication_c
       
   156 (abs_eap_am_tools_c* const tools,
       
   157  abs_eap_wimax_authentication_c* const partner,
       
   158  const bool is_client_when_true,
       
   159  const abs_eapol_wlan_database_reference_if_c* const wimax_database_reference)
       
   160 {
       
   161   EAP_TRACE_DEBUG
       
   162     (tools, 
       
   163      TRACE_FLAGS_DEFAULT, 
       
   164      (EAPL("partner calls: eap_wimax_authentication_c::new_eap_wimax_authentication_c()\n")));
       
   165 
       
   166   EAP_TRACE_RETURN_STRING(tools, "returns to partner: eap_wimax_authentication_c::new_eap_wimax_authentication_c()\n");
       
   167 
       
   168   eap_am_wimax_authentication_c* m_am_wauth = eap_am_wimax_authentication_c::new_eap_am_wimax_authentication
       
   169     (tools,
       
   170      is_client_when_true,
       
   171      wimax_database_reference);
       
   172 
       
   173   if (m_am_wauth == 0
       
   174       || m_am_wauth->get_is_valid() == false)
       
   175     {
       
   176       // ERROR.
       
   177       if (m_am_wauth != 0)
       
   178 	{
       
   179 	  EAP_TRACE_DEBUG
       
   180 	    (tools,
       
   181 	     TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   182 	     (EAPL("calls: eap_wimax_authentication_c::new_eap_wimax_authentication_c(): m_am_wauth->shutdown(): %s.\n"),
       
   183 	      (is_client_when_true == true) ? "client": "server"));
       
   184 	  
       
   185 	  m_am_wauth->shutdown();
       
   186 	  delete m_am_wauth;
       
   187 	  m_am_wauth = 0;
       
   188 	}
       
   189       return 0;
       
   190     }
       
   191 
       
   192   eap_wimax_authentication_c* wauth = new eap_wimax_authentication_c(tools, partner, m_am_wauth, is_client_when_true);
       
   193   if (wauth == 0
       
   194       || wauth->get_is_valid() == false)
       
   195     {
       
   196       // ERROR.
       
   197       if (wauth != 0)
       
   198 	{
       
   199 	  wauth->shutdown();
       
   200 	  delete wauth;
       
   201 	}
       
   202       return 0;
       
   203     }
       
   204   
       
   205   EAP_TRACE_DEBUG
       
   206     (tools,
       
   207      TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   208      (EAPL("calls: eap_wimax_authentication_c::new_eap_wimax_authentication_c(): m_am_wauth->set_am_partner(): %s.\n"),
       
   209       (is_client_when_true == true) ? "client": "server"));
       
   210   
       
   211   m_am_wauth->set_am_partner(wauth);
       
   212   
       
   213   return wauth;
       
   214 }
       
   215 
       
   216 //--------------------------------------------------
       
   217 
       
   218 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::shutdown()
       
   219 {
       
   220   EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   221   
       
   222   EAP_TRACE_DEBUG
       
   223     (m_am_tools,
       
   224      TRACE_FLAGS_DEFAULT,
       
   225      (EAPL("partner calls: eap_wimax_authentication_c::shutdown(); %s, m_shutdown_was_called=%d\n"),
       
   226       (m_is_client == true) ? "client": "server",
       
   227       m_shutdown_was_called));
       
   228 
       
   229   EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eap_wimax_authentication_c::shutdown()\n");
       
   230 
       
   231   if (m_shutdown_was_called == true)
       
   232     {
       
   233       // Shutdown was already called once.
       
   234       return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
   235     }
       
   236 
       
   237   m_shutdown_was_called = true;
       
   238 	
       
   239   // Cancel timers	
       
   240   cancel_all_timers();
       
   241 
       
   242   // Delete upper stack if it still exists
       
   243   if (m_eap_core != 0)
       
   244     {
       
   245       WAUTH_ENTER_MUTEX(m_am_tools);
       
   246       
       
   247       EAP_TRACE_DEBUG
       
   248 	(m_am_tools,
       
   249 	 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   250 	 (EAPL("calls eap: eap_wimax_authentication_c::shutdown(): m_eap_core->shutdown(): %s.\n"),
       
   251 	  (m_is_client == true) ? "client": "server"));
       
   252       
       
   253       eap_status_e status = m_eap_core->shutdown();
       
   254 
       
   255       EAP_TRACE_DEBUG
       
   256 	(m_am_tools,
       
   257 	 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   258 	 (EAPL("returns from eap: eap_wimax_authentication_c::shutdown(): m_eap_core->shutdown(): %s, status = %s.\n"),
       
   259 	  (m_is_client == true) ? "client": "server",
       
   260 	  eap_status_string_c::get_status_string(status)));
       
   261       
       
   262       EAP_UNREFERENCED_PARAMETER(status); // in release
       
   263       
       
   264       WAUTH_LEAVE_MUTEX(m_am_tools);
       
   265       
       
   266       delete m_eap_core;
       
   267       m_eap_core = 0;
       
   268     }
       
   269 	
       
   270   if (m_am_wauth != 0)
       
   271     {
       
   272       EAP_TRACE_DEBUG
       
   273 		(m_am_tools,
       
   274 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   275 		(EAPL("calls: eap_wimax_authentication_c::shutdown(): m_am_wauth->shutdown(): %s.\n"),
       
   276 		(m_is_client == true) ? "client": "server"));
       
   277       
       
   278       m_am_wauth->shutdown();
       
   279       delete m_am_wauth;
       
   280       m_am_wauth = 0;
       
   281     }
       
   282   
       
   283   EAP_TRACE_DEBUG
       
   284     (m_am_tools,
       
   285 	TRACE_FLAGS_DEFAULT,
       
   286     (EAPL("WAUTH EXITING.\n")));
       
   287   
       
   288   EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   289   return eap_status_ok;
       
   290 }
       
   291 
       
   292 //--------------------------------------------------
       
   293 
       
   294 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::cancel_all_authentication_sessions()
       
   295 {
       
   296   EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   297   
       
   298   EAP_TRACE_DEBUG
       
   299     (m_am_tools, 
       
   300      TRACE_FLAGS_DEFAULT, 
       
   301      (EAPL("eap_wimax_authentication_c::cancel_all_authentication_sessions(): this = 0x%08x.\n"),
       
   302       this));
       
   303   
       
   304   eap_status_e status(eap_status_ok);
       
   305   
       
   306   bool previous_block = m_block_state_notifications;
       
   307   m_block_state_notifications = true;
       
   308   
       
   309   if (m_eap_core != 0)
       
   310     {
       
   311 
       
   312       WAUTH_ENTER_MUTEX(m_am_tools);
       
   313 
       
   314       EAP_TRACE_DEBUG
       
   315 		(m_am_tools,
       
   316 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   317 		(EAPL("calls eap: eap_wimax_authentication_c:cancel_all_authentication_sessions(): m_eap_core->synchronous_cancel_all_eap_sessions(): %s.\n"),
       
   318 		(m_is_client == true) ? "client": "server"));
       
   319 
       
   320       status = m_eap_core->synchronous_cancel_all_eap_sessions();
       
   321 
       
   322       EAP_TRACE_DEBUG
       
   323 		(m_am_tools,
       
   324 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   325 		(EAPL("returns from eap: eap_wimax_authentication_c:cancel_all_authentication_sessions(): m_eap_core->synchronous_cancel_all_eap_sessions(): %s, status = %s.\n"),
       
   326 		(m_is_client == true) ? "client": "server",
       
   327 		eap_status_string_c::get_status_string(status)));
       
   328 
       
   329       WAUTH_LEAVE_MUTEX(m_am_tools); 
       
   330     }
       
   331   
       
   332   m_block_state_notifications = previous_block;
       
   333   
       
   334   EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   335   return EAP_STATUS_RETURN(m_am_tools, status);
       
   336 }
       
   337 
       
   338 //--------------------------------------------------
       
   339 
       
   340 EAP_FUNC_EXPORT bool eap_wimax_authentication_c::get_is_valid()
       
   341 {
       
   342 	return m_is_valid;
       
   343 }
       
   344 
       
   345 //--------------------------------------------------
       
   346 
       
   347 EAP_FUNC_EXPORT bool eap_wimax_authentication_c::get_is_client()
       
   348 {
       
   349 	return m_is_client;
       
   350 }
       
   351 
       
   352 //--------------------------------------------------
       
   353 
       
   354 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::packet_data_crypto_keys(
       
   355 	const eap_am_network_id_c * const send_network_id,
       
   356 	const eap_master_session_key_c * const master_session_key)
       
   357 {
       
   358 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   359 
       
   360 	EAP_TRACE_DEBUG(
       
   361 		m_am_tools,
       
   362 		TRACE_FLAGS_DEFAULT,
       
   363 		(EAPL("%s: eap_wimax_authentication_c::packet_data_crypto_keys()\n"),
       
   364 		(m_is_client == true) ? "client": "server"));
       
   365 
       
   366 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   367 
       
   368 	eap_status_e status = eap_status_process_general_error;
       
   369 
       
   370 	if (master_session_key->get_is_valid() == true)
       
   371 	{
       
   372 		EAP_TRACE_DATA_DEBUG(
       
   373 			m_am_tools,
       
   374 			TRACE_FLAGS_DEFAULT,
       
   375 			(EAPL("master session key"),
       
   376 			 master_session_key->get_data(master_session_key->get_data_length()),
       
   377 			 master_session_key->get_data_length()));
       
   378 	}
       
   379 
       
   380 	EAP_TRACE_DEBUG(
       
   381 		m_am_tools,
       
   382 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   383 		(EAPL("calls partner: eap_wimax_authentication_c::packet_data_crypto_keys(): %s: m_partner->packet_data_crypto_keys()\n"),
       
   384 		 (m_is_client == true) ? "client": "server"));
       
   385 
       
   386 	// Forward the keys to lower layers (defined in abs_eap_wimax_authentication_c)
       
   387 	status = m_partner->packet_data_crypto_keys(send_network_id, master_session_key);
       
   388 	
       
   389 	EAP_TRACE_DEBUG(
       
   390 		m_am_tools,
       
   391 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   392 		(EAPL("returns from partner: eap_wimax_authentication_c::packet_data_crypto_keys(): %s: m_partner->packet_data_crypto_keys(): status = %s\n"),
       
   393 		 (m_is_client == true) ? "client": "server",
       
   394 		 eap_status_string_c::get_status_string(status)));
       
   395 
       
   396 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   397 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   398 }
       
   399 
       
   400 //--------------------------------------------------
       
   401 
       
   402 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::packet_send(
       
   403 	const eap_am_network_id_c * const network_id,
       
   404 	eap_buf_chain_wr_c * const sent_packet,
       
   405 	const u32_t header_offset,
       
   406 	const u32_t data_length,
       
   407 	const u32_t buffer_length)
       
   408 {
       
   409 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   410 
       
   411 	EAP_TRACE_DEBUG(
       
   412 		m_am_tools,
       
   413 		TRACE_FLAGS_DEFAULT,
       
   414 		(EAPL("eapol calls: eap_wimax_authentication_c::packet_send(data_length=%d): %s.\n"),
       
   415 		data_length,
       
   416 		(m_is_client == true) ? "client": "server"));
       
   417 
       
   418 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::packet_send()\n");
       
   419 
       
   420 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   421 
       
   422 	eap_status_e status(eap_status_ok);
       
   423 
       
   424 	EAP_TRACE_DEBUG(
       
   425 		m_am_tools,
       
   426 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   427 		(EAPL("calls partner: eap_wimax_authentication_c::packet_send(): %s: m_partner->packet_send()\n"),
       
   428 		 (m_is_client == true) ? "client": "server"));
       
   429 
       
   430 	// Here we send the original packet.
       
   431 	status = m_partner->packet_send(
       
   432 		network_id,
       
   433 		sent_packet,
       
   434 		header_offset,
       
   435 		data_length,
       
   436 		buffer_length);
       
   437 
       
   438 	EAP_TRACE_DEBUG(
       
   439 		m_am_tools,
       
   440 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   441 		(EAPL("returns from partner: eap_wimax_authentication_c::packet_send(): %s: m_partner->packet_send(): status = %s\n"),
       
   442 		 (m_is_client == true) ? "client": "server",
       
   443 		 eap_status_string_c::get_status_string(status)));
       
   444 
       
   445 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   446 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   447 }
       
   448 
       
   449 //--------------------------------------------------
       
   450 
       
   451 EAP_FUNC_EXPORT u32_t eap_wimax_authentication_c::get_header_offset(
       
   452 	u32_t * const MTU, 
       
   453 	u32_t * const trailer_length)
       
   454 {
       
   455 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   456 
       
   457 	EAP_TRACE_DEBUG(
       
   458 		m_am_tools,
       
   459 		TRACE_FLAGS_DEFAULT,
       
   460 		(EAPL("eapol calls: eap_wimax_authentication_c::get_header_offset()\n")));
       
   461 
       
   462 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::get_header_offset()\n");
       
   463 
       
   464 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   465 
       
   466 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   467 
       
   468 	EAP_TRACE_DEBUG(
       
   469 		m_am_tools,
       
   470 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   471 		(EAPL("calls partner: eap_wimax_authentication_c::get_header_offset(): %s: m_partner->get_header_offset()\n"),
       
   472 		 (m_is_client == true) ? "client": "server"));
       
   473 	
       
   474 	// we ask these from the partner in case it wants to leave some 
       
   475 	// room for adding something (e.g. Ethernet header)
       
   476 	const u32_t offset = m_partner->get_header_offset(MTU, trailer_length);
       
   477 
       
   478 	EAP_TRACE_DEBUG(
       
   479 		m_am_tools,
       
   480 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   481 		(EAPL("returns from partner: eap_wimax_authentication_c::get_header_offset(): %s: m_partner->get_header_offset(): offset = %d\n"),
       
   482 		 (m_is_client == true) ? "client": "server",
       
   483 		 offset));
       
   484 
       
   485 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   486 	return offset;
       
   487 
       
   488 }
       
   489 
       
   490 //--------------------------------------------------
       
   491 
       
   492 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::load_module(
       
   493 	const eap_type_value_e type,
       
   494 	const eap_type_value_e tunneling_type,
       
   495 	abs_eap_base_type_c * const partner,
       
   496 	eap_base_type_c ** const eap_type,
       
   497 	const bool is_client_when_true,
       
   498 	const eap_am_network_id_c * const receive_network_id)
       
   499 {	
       
   500 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   501 
       
   502 	EAP_TRACE_DEBUG(
       
   503 		m_am_tools,
       
   504 		TRACE_FLAGS_DEFAULT,
       
   505 		(EAPL("eapol calls: eap_wimax_authentication_c::load_module(type 0x%08x=%s, tunneling_type 0x%08x=%s)\n"),
       
   506 		convert_eap_type_to_u32_t(type),
       
   507 		eap_header_string_c::get_eap_type_string(type),
       
   508 		convert_eap_type_to_u32_t(tunneling_type),
       
   509 		eap_header_string_c::get_eap_type_string(tunneling_type)));
       
   510 
       
   511 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::load_module()\n");
       
   512 
       
   513 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   514 
       
   515 	EAP_TRACE_DEBUG(
       
   516 		m_am_tools,
       
   517 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   518 		(EAPL("calls: eap_wimax_authentication_c::load_module(): m_am_wauth->load_module(): %s.\n"),
       
   519 		(m_is_client == true) ? "client": "server"));
       
   520 
       
   521 	eap_status_e status = m_am_wauth->load_module(
       
   522 		type,
       
   523 		tunneling_type,
       
   524 		partner,
       
   525 		eap_type,
       
   526 		is_client_when_true,
       
   527 		receive_network_id);
       
   528 
       
   529 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   530 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   531 }
       
   532 
       
   533 //--------------------------------------------------
       
   534 
       
   535 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::unload_module(const eap_type_value_e eap_type)
       
   536 {
       
   537 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   538 
       
   539 	EAP_TRACE_DEBUG(
       
   540 		m_am_tools,
       
   541 		TRACE_FLAGS_DEFAULT,
       
   542 		(EAPL("eap calls: eap_wimax_authentication_c::unload_module(type 0x%08x=%s): \n"),
       
   543 		convert_eap_type_to_u32_t(eap_type),
       
   544 		eap_header_string_c::get_eap_type_string(eap_type)
       
   545 		));
       
   546 
       
   547 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::unload_module()\n");
       
   548 
       
   549 	eap_status_e status(eap_status_type_does_not_exists_error);
       
   550 
       
   551 	EAP_TRACE_DEBUG(
       
   552 		m_am_tools,
       
   553 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   554 		(EAPL("calls: eap_wimax_authentication_c::unload_module(): m_am_wauth->unload_module(): %s.\n"),
       
   555 		(m_is_client == true) ? "client": "server"));
       
   556 
       
   557 	status = m_am_wauth->unload_module(eap_type);
       
   558 
       
   559 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   560 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   561 }
       
   562 
       
   563 //--------------------------------------------------
       
   564 
       
   565 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::restart_authentication(
       
   566 	const eap_am_network_id_c * const receive_network_id,
       
   567 	const bool is_client_when_true,
       
   568 	const bool force_clean_restart,
       
   569 	const bool from_timer)
       
   570 {
       
   571 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   572 
       
   573 	eap_status_e status(eap_status_not_supported);
       
   574 
       
   575 #if defined(USE_EAP_CORE_SERVER)
       
   576 	if(is_client_when_true == false)
       
   577 	{
       
   578 		// only the server can start authentication
       
   579 		status = m_eap_core->send_eap_identity_request(receive_network_id);
       
   580 	}
       
   581 #endif
       
   582 
       
   583 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   584 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   585 }
       
   586 
       
   587 //--------------------------------------------------
       
   588 
       
   589 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::read_configure(
       
   590 	const eap_configuration_field_c * const field,
       
   591 	eap_variable_data_c * const data)
       
   592 {
       
   593 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   594 
       
   595 	EAP_TRACE_DEBUG(
       
   596 		m_am_tools,
       
   597 		TRACE_FLAGS_DEFAULT,
       
   598 		(EAPL("eapol calls: eap_wimax_authentication_c::read_configure(): %s\n"),
       
   599 		(m_is_client == true) ? "client": "server"));
       
   600 
       
   601 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::read_configure()\n");
       
   602 
       
   603 	EAP_ASSERT_ALWAYS(data != 0);
       
   604 
       
   605 	EAP_TRACE_DEBUG(
       
   606 		m_am_tools,
       
   607 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   608 		(EAPL("calls: eap_wimax_authentication_c::read_configure(): m_am_wauth->read_configure(): %s.\n"),
       
   609 		(m_is_client == true) ? "client": "server"));
       
   610 
       
   611 	eap_status_e status = m_am_wauth->read_configure(field, data);
       
   612 
       
   613 	m_am_tools->trace_configuration(
       
   614 		status,
       
   615 		field,
       
   616 		data);
       
   617 
       
   618 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   619 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   620 }
       
   621 
       
   622 //--------------------------------------------------
       
   623 
       
   624 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::write_configure(
       
   625 	const eap_configuration_field_c * const field,
       
   626 	eap_variable_data_c * const data)
       
   627 {
       
   628 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   629 
       
   630 	EAP_TRACE_DEBUG(
       
   631 		m_am_tools,
       
   632 		TRACE_FLAGS_DEFAULT,
       
   633 		(EAPL("eapol calls: eap_wimax_authentication_c::write_configure(): %s\n"),
       
   634 		(m_is_client == true) ? "client": "server"));
       
   635 
       
   636 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::write_configure()\n");
       
   637 
       
   638 	EAP_TRACE_DEBUG(
       
   639 		m_am_tools,
       
   640 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   641 		(EAPL("calls: eap_wimax_authentication_c::write_configure(): m_am_wauth->write_configure(): %s.\n"),
       
   642 		(m_is_client == true) ? "client": "server"));
       
   643 
       
   644 	eap_status_e status = m_am_wauth->write_configure(field, data);
       
   645 
       
   646 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   647 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   648 }
       
   649 
       
   650 //--------------------------------------------------
       
   651 
       
   652 EAP_FUNC_EXPORT void eap_wimax_authentication_c::state_notification(
       
   653 	const abs_eap_state_notification_c * const state)
       
   654 {
       
   655 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   656 
       
   657 	EAP_TRACE_DEBUG(
       
   658 		m_am_tools,
       
   659 		TRACE_FLAGS_DEFAULT,
       
   660 		(EAPL("eap calls: eap_wimax_authentication_c::state_notification()\n")));
       
   661 
       
   662 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::state_notification()\n");
       
   663 
       
   664 	// Calls lower layer.
       
   665 	m_partner->state_notification(state);
       
   666 
       
   667 	// AM could have to show some notification to user.
       
   668 	m_am_wauth->state_notification(state);
       
   669 
       
   670 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   671 	return;
       
   672 }
       
   673 
       
   674 //--------------------------------------------------
       
   675 
       
   676 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::asynchronous_init_remove_eap_session(
       
   677 		const eap_am_network_id_c * const send_network_id)
       
   678 {
       
   679 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   680 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   681 	// not supported
       
   682 	return EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported);
       
   683 }
       
   684 
       
   685 //--------------------------------------------------
       
   686 
       
   687 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::set_timer(
       
   688 		abs_eap_base_timer_c * const initializer, 
       
   689 		const u32_t id, 
       
   690 		void * const data,
       
   691 		const u32_t time_ms)
       
   692 {
       
   693 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   694 
       
   695 	EAP_TRACE_DEBUG(
       
   696 		m_am_tools,
       
   697 		TRACE_FLAGS_DEFAULT,
       
   698 		(EAPL("eap calls: eap_wimax_authentication_c::set_timer(): id = %d, data = 0x%08x, time = %d\n"),
       
   699 		id,
       
   700 		data,
       
   701 		time_ms));
       
   702 
       
   703 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::set_timer()\n");
       
   704 
       
   705 	const eap_status_e status = m_am_tools->am_set_timer(
       
   706 		initializer, 
       
   707 		id, 
       
   708 		data,
       
   709 		time_ms);
       
   710 
       
   711 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   712 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   713 }
       
   714 
       
   715 //--------------------------------------------------
       
   716 
       
   717 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::cancel_timer(
       
   718 		abs_eap_base_timer_c * const initializer, 
       
   719 		const u32_t id)
       
   720 {
       
   721 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   722 	
       
   723 	EAP_TRACE_DEBUG(
       
   724 		m_am_tools,
       
   725 		TRACE_FLAGS_DEFAULT,
       
   726 		(EAPL("eap calls: eap_wimax_authentication_c::cancel_timer(): initializer = 0x%08x, id = %d\n"),
       
   727 		initializer,
       
   728 		id));
       
   729 
       
   730 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::cancel_timer()\n");
       
   731 
       
   732 	const eap_status_e status = m_am_tools->am_cancel_timer(
       
   733 		initializer, 
       
   734 		id);
       
   735 
       
   736 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   737 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   738 }
       
   739 
       
   740 //--------------------------------------------------
       
   741 
       
   742 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::cancel_all_timers()
       
   743 {
       
   744 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   745 
       
   746 	EAP_TRACE_DEBUG(
       
   747 		m_am_tools,
       
   748 		TRACE_FLAGS_DEFAULT,
       
   749 		(EAPL("eap calls: eap_wimax_authentication_c::cancel_all_timers()\n")));
       
   750 
       
   751 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::cancel_all_timers()\n");
       
   752 
       
   753 	eap_status_e status = eap_status_ok;
       
   754 	
       
   755 	if (m_am_tools != 0)
       
   756 	{
       
   757 		WAUTH_ENTER_MUTEX(m_am_tools);
       
   758 		status = m_am_tools->am_cancel_all_timers();
       
   759 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
   760 	}
       
   761 
       
   762 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   763 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   764 }
       
   765 
       
   766 //--------------------------------------------------
       
   767 
       
   768 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::check_is_valid_eap_type(
       
   769 	const eap_type_value_e eap_type)
       
   770 {
       
   771 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   772 
       
   773 	EAP_TRACE_DEBUG(
       
   774 		m_am_tools,
       
   775 		TRACE_FLAGS_DEFAULT,
       
   776 		(EAPL("eap calls: eap_wimax_authentication_c::check_is_valid_eap_type()\n")));
       
   777 
       
   778 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::check_is_valid_eap_type()\n");
       
   779 
       
   780 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   781 
       
   782 	EAP_TRACE_DEBUG(
       
   783 		m_am_tools,
       
   784 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   785 		(EAPL("calls: eap_wimax_authentication_c::check_is_valid_eap_type(): m_am_wauth->check_is_valid_eap_type(): %s.\n"),
       
   786 		(m_is_client == true) ? "client": "server"));
       
   787 
       
   788 	eap_status_e status = m_am_wauth->check_is_valid_eap_type(eap_type);
       
   789 	
       
   790 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   791 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   792 }
       
   793 
       
   794 //--------------------------------------------------
       
   795 
       
   796 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::get_eap_type_list(
       
   797 		eap_array_c<eap_type_value_e> * const eap_type_list)
       
   798 {
       
   799 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   800 
       
   801 	EAP_TRACE_DEBUG(
       
   802 		m_am_tools,
       
   803 		TRACE_FLAGS_DEFAULT,
       
   804 		(EAPL("eap calls: eap_wimax_authentication_c::get_eap_type_list()\n")));
       
   805 
       
   806 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::get_eap_type_list()\n");
       
   807 
       
   808 	EAP_TRACE_DEBUG(
       
   809 		m_am_tools,
       
   810 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   811 		(EAPL("calls: eap_wimax_authentication_c::get_eap_type_list(): m_am_wauth->get_eap_type_list(): %s.\n"),
       
   812 		(m_is_client == true) ? "client": "server"));
       
   813 
       
   814 	eap_status_e status = m_am_wauth->get_eap_type_list(eap_type_list);
       
   815 
       
   816 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   817 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   818 }
       
   819 
       
   820 //--------------------------------------------------
       
   821 
       
   822 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::add_rogue_ap(
       
   823 	eap_array_c<eap_rogue_ap_entry_c> & rogue_ap_list)
       
   824 {
       
   825 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   826 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   827 	// not used in Wimax
       
   828 	return EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported);
       
   829 }
       
   830 
       
   831 //--------------------------------------------------
       
   832 
       
   833 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::set_session_timeout(
       
   834 		const u32_t /* session_timeout_ms */)
       
   835 {
       
   836 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   837 
       
   838 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   839 
       
   840 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   841 	
       
   842 	// not supported
       
   843 	return EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported);
       
   844 }
       
   845 
       
   846 //--------------------------------------------------
       
   847 
       
   848 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::packet_process(
       
   849 	const eap_am_network_id_c * const receive_network_id,
       
   850 	eap_general_header_base_c * const packet_data,
       
   851 	const u32_t packet_length)
       
   852 {
       
   853 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   854 
       
   855 	EAP_TRACE_DEBUG(
       
   856 		m_am_tools,
       
   857 		TRACE_FLAGS_DEFAULT,
       
   858 		(EAPL("partner calls: eap_wimax_authentication_c::packet_process(): %s\n"),
       
   859 		(m_is_client == true) ? "client": "server"));
       
   860 
       
   861 	if (packet_data == 0
       
   862 		|| packet_length < eap_header_base_c::get_header_length())
       
   863 	{
       
   864 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   865 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_illegal_packet_error);
       
   866 	}
       
   867 
       
   868 	if (receive_network_id == 0
       
   869 		|| receive_network_id->get_is_valid_data() == false)
       
   870 	{
       
   871 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   872 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
   873 	}
       
   874 
       
   875 	eap_header_wr_c eap(
       
   876 		m_am_tools,
       
   877 		packet_data->get_header_buffer(packet_data->get_header_buffer_length()),
       
   878 		packet_data->get_header_buffer_length());
       
   879 
       
   880 	if (eap.get_is_valid() == false)
       
   881 	{
       
   882 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   883 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_illegal_packet_error);
       
   884 	}
       
   885 
       
   886 	if (packet_length < eap.get_data_length())
       
   887 	{
       
   888 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   889 		return EAP_STATUS_RETURN(m_am_tools, eap_status_process_illegal_packet_error);
       
   890 	}
       
   891 
       
   892 	if (m_eap_core == 0)
       
   893 	{
       
   894 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   895 	}
       
   896 	
       
   897 	// Forward the packet to the EAP layer of the EAP stack.
       
   898 	// Ignore return value. Failure is signalled using state_notification.
       
   899 	WAUTH_ENTER_MUTEX(m_am_tools);
       
   900 
       
   901 	EAP_TRACE_DEBUG(
       
   902 		m_am_tools,
       
   903 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT,
       
   904 		(EAPL("calls eapol: eap_wimax_authentication_c::packet_process(): m_eap_core->packet_process(): %s. %d %d\n"),
       
   905 		(m_is_client == true) ? "client": "server", eap.get_data_length(), packet_length));
       
   906 
       
   907 	eap_status_e status = m_eap_core->packet_process(
       
   908 		receive_network_id,
       
   909 		&eap,
       
   910                 packet_length);
       
   911 
       
   912 	EAP_TRACE_DEBUG(
       
   913 		m_am_tools,
       
   914 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   915 		(EAPL("returns from eapol: eap_wimax_authentication_c::packet_process(): m_eap_core->packet_process(): %s, status = %s.\n"),
       
   916 		(m_is_client == true) ? "client": "server",
       
   917 		eap_status_string_c::get_status_string(status)));
       
   918 
       
   919 	EAP_UNREFERENCED_PARAMETER(status); // in release
       
   920 
       
   921 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
   922 
       
   923 	EAP_GENERAL_HEADER_COPY_ERROR_PARAMETERS(packet_data, &eap);
       
   924 
       
   925 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   926 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   927 }
       
   928 
       
   929 //--------------------------------------------------
       
   930 
       
   931 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::eap_acknowledge(
       
   932 	const eap_am_network_id_c * const receive_network_id)
       
   933 {
       
   934 	// Any Network Protocol packet is accepted as a success indication.
       
   935 	// This is described in RFC 2284 "PPP Extensible Authentication Protocol (EAP)".
       
   936 
       
   937 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   938 
       
   939 	EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true);
       
   940 
       
   941 	if (m_eap_core == 0)
       
   942 	{
       
   943 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   944 	}
       
   945 
       
   946 	WAUTH_ENTER_MUTEX(m_am_tools);
       
   947 	eap_status_e status = m_eap_core->eap_acknowledge(receive_network_id);
       
   948 	WAUTH_LEAVE_MUTEX(m_am_tools);
       
   949 
       
   950 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   951 
       
   952 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   953 }
       
   954 
       
   955 
       
   956 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::configure()
       
   957 {
       
   958 	EAP_TRACE_DEBUG(
       
   959 		m_am_tools,
       
   960 		TRACE_FLAGS_DEFAULT,
       
   961 		(EAPL("partner calls: eap_wimax_authentication_c::configure(): %s\n"),
       
   962 		(m_is_client == true) ? "client": "server"));
       
   963 
       
   964 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to partner: eap_wimax_authentication_c::configure()\n");
       
   965 
       
   966 	//----------------------------------------------------------
       
   967 
       
   968 	EAP_TRACE_DEBUG(
       
   969 		m_am_tools,
       
   970 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
   971 		(EAPL("calls: eap_wimax_authentication_c::configure(): m_am_wauth->configure(): %s.\n"),
       
   972 		(m_is_client == true) ? "client": "server"));
       
   973 
       
   974 	eap_status_e status = m_am_wauth->configure();
       
   975 	if (status != eap_status_ok)
       
   976 	{
       
   977 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   978 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   979 	}
       
   980 
       
   981 	//----------------------------------------------------------
       
   982 
       
   983 	{		
       
   984 		eap_variable_data_c EAP_TRACE_disable_traces(m_am_tools);
       
   985 
       
   986 		eap_status_e status = read_configure(
       
   987 			cf_str_EAP_TRACE_disable_traces.get_field(),
       
   988 			&EAP_TRACE_disable_traces);
       
   989 		if (status == eap_status_ok
       
   990 			&& EAP_TRACE_disable_traces.get_is_valid_data() == true)
       
   991 		{
       
   992 			u32_t *disable_traces = reinterpret_cast<u32_t *>(
       
   993 				EAP_TRACE_disable_traces.get_data(sizeof(u32_t)));
       
   994 			if (disable_traces != 0
       
   995 				&& *disable_traces != 0)
       
   996 			{
       
   997 				m_am_tools->set_trace_mask(eap_am_tools_c::eap_trace_mask_none);
       
   998 			}
       
   999 		}
       
  1000 	}
       
  1001 
       
  1002 	//----------------------------------------------------------
       
  1003 
       
  1004 	{		
       
  1005 		eap_variable_data_c EAP_TRACE_activate_only_trace_masks_always_and_error(m_am_tools);
       
  1006 
       
  1007 		eap_status_e status = read_configure(
       
  1008 			cf_str_EAP_TRACE_activate_only_trace_masks_always_and_error.get_field(),
       
  1009 			&EAP_TRACE_activate_only_trace_masks_always_and_error);
       
  1010 		if (status == eap_status_ok
       
  1011 			&& EAP_TRACE_activate_only_trace_masks_always_and_error.get_is_valid_data() == true)
       
  1012 		{
       
  1013 			u32_t *activate_trace_mask_always = reinterpret_cast<u32_t *>(
       
  1014 				EAP_TRACE_activate_only_trace_masks_always_and_error.get_data(sizeof(u32_t)));
       
  1015 			if (activate_trace_mask_always != 0
       
  1016 				&& *activate_trace_mask_always != 0)
       
  1017 			{
       
  1018 				m_am_tools->set_trace_mask(
       
  1019 					eap_am_tools_c::eap_trace_mask_always
       
  1020 					| eap_am_tools_c::eap_trace_mask_error
       
  1021 					);
       
  1022 			}
       
  1023 		}
       
  1024 	}
       
  1025 
       
  1026 	//----------------------------------------------------------
       
  1027 
       
  1028 	{		
       
  1029 		eap_variable_data_c EAP_TRACE_activate_trace_on_error(m_am_tools);
       
  1030 
       
  1031 		eap_status_e status = read_configure(
       
  1032 			cf_str_EAP_TRACE_activate_trace_on_error.get_field(),
       
  1033 			&EAP_TRACE_activate_trace_on_error);
       
  1034 		if (status == eap_status_ok
       
  1035 			&& EAP_TRACE_activate_trace_on_error.get_is_valid_data() == true)
       
  1036 		{
       
  1037 			u32_t *activate_trace_on_error = reinterpret_cast<u32_t *>(
       
  1038 				EAP_TRACE_activate_trace_on_error.get_data(sizeof(u32_t)));
       
  1039 			if (activate_trace_on_error != 0
       
  1040 				&& *activate_trace_on_error != 0)
       
  1041 			{
       
  1042 				m_am_tools->set_activate_trace_on_error();
       
  1043 			}
       
  1044 		}
       
  1045 	}
       
  1046 
       
  1047 	//----------------------------------------------------------
       
  1048 
       
  1049 	{
       
  1050 		eap_variable_data_c EAP_TRACE_enable_timer_traces(m_am_tools);
       
  1051 
       
  1052 		status = read_configure(
       
  1053 			cf_str_EAP_TRACE_enable_timer_traces.get_field(),
       
  1054 			&EAP_TRACE_enable_timer_traces);
       
  1055 		if (status == eap_status_ok
       
  1056 			&& EAP_TRACE_enable_timer_traces.get_is_valid_data() == true)
       
  1057 		{
       
  1058 			u32_t *enable_timer_traces = reinterpret_cast<u32_t *>(
       
  1059 				EAP_TRACE_enable_timer_traces.get_data(sizeof(u32_t)));
       
  1060 			if (enable_timer_traces != 0
       
  1061 				&& *enable_timer_traces != 0)
       
  1062 			{
       
  1063 				m_am_tools->set_trace_mask(
       
  1064 					m_am_tools->get_trace_mask()
       
  1065 					| TRACE_FLAGS_TIMER
       
  1066 					);
       
  1067 			}
       
  1068 		}
       
  1069 	}
       
  1070 
       
  1071 	//----------------------------------------------------------
       
  1072 
       
  1073 	{
       
  1074 		eap_variable_data_c EAP_TRACE_enable_timer_queue_traces(m_am_tools);
       
  1075 
       
  1076 		status = read_configure(
       
  1077 			cf_str_EAP_TRACE_enable_timer_queue_traces.get_field(),
       
  1078 			&EAP_TRACE_enable_timer_queue_traces);
       
  1079 		if (status == eap_status_ok
       
  1080 			&& EAP_TRACE_enable_timer_queue_traces.get_is_valid_data() == true)
       
  1081 		{
       
  1082 			u32_t *enable_timer_queue_traces = reinterpret_cast<u32_t *>(
       
  1083 				EAP_TRACE_enable_timer_queue_traces.get_data(sizeof(u32_t)));
       
  1084 			if (enable_timer_queue_traces != 0
       
  1085 				&& *enable_timer_queue_traces != 0)
       
  1086 			{
       
  1087 				m_am_tools->set_trace_mask(
       
  1088 					m_am_tools->get_trace_mask()
       
  1089 					| TRACE_FLAGS_TIMER_QUEUE
       
  1090 					);
       
  1091 			}
       
  1092 		}
       
  1093 	}
       
  1094 
       
  1095 	//----------------------------------------------------------
       
  1096 
       
  1097 	{
       
  1098 		eap_variable_data_c EAP_TRACE_enable_ok_return_traces(m_am_tools);
       
  1099 
       
  1100 		status = read_configure(
       
  1101 			cf_str_EAP_TRACE_enable_ok_return_traces.get_field(),
       
  1102 			&EAP_TRACE_enable_ok_return_traces);
       
  1103 		if (status == eap_status_ok
       
  1104 			&& EAP_TRACE_enable_ok_return_traces.get_is_valid_data() == true)
       
  1105 		{
       
  1106 			u32_t *enable_ok_return_traces = reinterpret_cast<u32_t *>(
       
  1107 				EAP_TRACE_enable_ok_return_traces.get_data(sizeof(u32_t)));
       
  1108 			if (enable_ok_return_traces != 0
       
  1109 				&& *enable_ok_return_traces != 0)
       
  1110 			{
       
  1111 				m_am_tools->set_trace_mask(
       
  1112 					m_am_tools->get_trace_mask()
       
  1113 					| TRACE_FLAGS_OK_RETURNS
       
  1114 					);
       
  1115 			}
       
  1116 		}
       
  1117 	}
       
  1118 
       
  1119 	//----------------------------------------------------------
       
  1120 
       
  1121 	{
       
  1122 		eap_variable_data_c EAP_TRACE_enable_message_data_traces(m_am_tools);
       
  1123 
       
  1124 		status = read_configure(
       
  1125 			cf_str_EAP_TRACE_enable_message_data_traces.get_field(),
       
  1126 			&EAP_TRACE_enable_message_data_traces);
       
  1127 		if (status == eap_status_ok
       
  1128 			&& EAP_TRACE_enable_message_data_traces.get_is_valid_data() == true)
       
  1129 		{
       
  1130 			u32_t *enable_message_data_traces = reinterpret_cast<u32_t *>(
       
  1131 				EAP_TRACE_enable_message_data_traces.get_data(sizeof(u32_t)));
       
  1132 			if (enable_message_data_traces != 0
       
  1133 				&& *enable_message_data_traces != 0)
       
  1134 			{
       
  1135 				m_am_tools->set_trace_mask(
       
  1136 					m_am_tools->get_trace_mask()
       
  1137 					| EAP_TRACE_FLAGS_MESSAGE_DATA
       
  1138 					);
       
  1139 			}
       
  1140 		}
       
  1141 	}
       
  1142 
       
  1143 	//----------------------------------------------------------
       
  1144 
       
  1145 	// Create stack if it does not already exist. 
       
  1146 	status = create_upper_stack();
       
  1147 	if (status != eap_status_ok)
       
  1148 	{
       
  1149 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  1150 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1151 	}
       
  1152 
       
  1153 	// All of the configuration options are optional.
       
  1154 	// So we return OK.
       
  1155 	return EAP_STATUS_RETURN(m_am_tools, eap_status_ok);
       
  1156 }
       
  1157 
       
  1158 //--------------------------------------------------
       
  1159 
       
  1160 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::set_wimax_parameters(
       
  1161 	eap_variable_data_c* const routing_info,
       
  1162 	eap_variable_data_c* const nai_decoration)
       
  1163 {
       
  1164 
       
  1165 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1166 
       
  1167 	EAP_TRACE_DEBUG(
       
  1168 		m_am_tools,
       
  1169 		TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1170 		(EAPL("calls: eap_wimax_authentication_c::set_wimax_parameters(): m_am_wauth->reset_eap_configuration(): %s.\n"),
       
  1171 		(m_is_client == true) ? "client": "server"));
       
  1172 
       
  1173 	eap_status_e status = m_am_wauth->reset_eap_configuration();
       
  1174 
       
  1175 	if (status != eap_status_ok)
       
  1176 	{
       
  1177 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1178 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1179 	}
       
  1180 
       
  1181 	status = m_am_wauth->set_wimax_parameters(routing_info, nai_decoration);
       
  1182 	if (status != eap_status_ok)
       
  1183 	{
       
  1184 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1185 		return EAP_STATUS_RETURN(m_am_tools, status);
       
  1186 	}
       
  1187 
       
  1188 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1189 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1190 }
       
  1191 
       
  1192 //--------------------------------------------------
       
  1193 
       
  1194 EAP_FUNC_EXPORT eap_status_e eap_wimax_authentication_c::create_upper_stack()
       
  1195 {
       
  1196 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1197 	
       
  1198 	EAP_TRACE_DEBUG(
       
  1199 		m_am_tools,
       
  1200 		TRACE_FLAGS_DEFAULT,
       
  1201 		(EAPL("eap calls: eap_wimax_authentication_c::create_upper_stack()\n")));
       
  1202 
       
  1203 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns to eap: eap_wimax_authentication_c::create_upper_stack()\n");
       
  1204 
       
  1205 	eap_status_e status(eap_status_ok);
       
  1206 
       
  1207 	if (m_eap_core == 0)
       
  1208 	{        
       
  1209 		// we use session always
       
  1210 		m_eap_core = new eap_session_core_c(m_am_tools, this, m_is_client);
       
  1211 		if (m_eap_core == 0
       
  1212 			|| m_eap_core->get_is_valid() != true)
       
  1213 		{
       
  1214 			if (m_eap_core != 0)
       
  1215 			{
       
  1216 				WAUTH_ENTER_MUTEX(m_am_tools);
       
  1217 
       
  1218 				EAP_TRACE_DEBUG(
       
  1219 					m_am_tools,
       
  1220 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1221 					(EAPL("calls eap: eap_wimax_authentication_c::create_upper_stack(): m_eap_core->shutdown(): %s.\n"),
       
  1222 					(m_is_client == true) ? "client": "server"));
       
  1223 
       
  1224 				status = m_eap_core->shutdown();
       
  1225 
       
  1226 				EAP_TRACE_DEBUG(
       
  1227 					m_am_tools,
       
  1228 					TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1229 					(EAPL("returns from eap: eap_wimax_authentication_c::create_upper_stack(): m_eap_core->shutdown(): %s, status = %s.\n"),
       
  1230 					 (m_is_client == true) ? "client": "server",
       
  1231 					 eap_status_string_c::get_status_string(status)));
       
  1232 
       
  1233 				WAUTH_LEAVE_MUTEX(m_am_tools);
       
  1234 
       
  1235 				delete m_eap_core;
       
  1236 				m_eap_core = 0;							
       
  1237 			}			
       
  1238 			EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Stack creation failed.\n")));			
       
  1239 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  1240 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);	
       
  1241 		}
       
  1242 
       
  1243 		// Initialise upper stack
       
  1244 		WAUTH_ENTER_MUTEX(m_am_tools);
       
  1245 
       
  1246 		EAP_TRACE_DEBUG(
       
  1247 			m_am_tools,
       
  1248 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1249 			(EAPL("calls eapol: eap_wimax_authentication_c::create_upper_stack(): m_eap_core->configure(): %s.\n"),
       
  1250 			(m_is_client == true) ? "client": "server"));
       
  1251 
       
  1252 		status = m_eap_core->configure();
       
  1253 
       
  1254 		EAP_TRACE_DEBUG(
       
  1255 			m_am_tools,
       
  1256 			TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1257 			(EAPL("returns from eapol: eap_wimax_authentication_c::create_upper_stack(): m_eap_core->configure(): %s, status = %s.\n"),
       
  1258 			 (m_is_client == true) ? "client": "server",
       
  1259 			 eap_status_string_c::get_status_string(status)));
       
  1260 
       
  1261 		WAUTH_LEAVE_MUTEX(m_am_tools);
       
  1262 		
       
  1263 		if (status != eap_status_ok)
       
  1264 		{
       
  1265 			WAUTH_ENTER_MUTEX(m_am_tools);
       
  1266 
       
  1267 			EAP_TRACE_DEBUG(
       
  1268 				m_am_tools,
       
  1269 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1270 				(EAPL("calls eap: eap_wimax_authentication_c::create_upper_stack(): m_eap_core->shutdown(): %s.\n"),
       
  1271 				(m_is_client == true) ? "client": "server"));
       
  1272 
       
  1273 			status = m_eap_core->shutdown();
       
  1274 
       
  1275 			EAP_TRACE_DEBUG(
       
  1276 				m_am_tools,
       
  1277 				TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, 
       
  1278 				(EAPL("returns from eap: eapol_wlan_authentication_c::create_upper_stack(): m_eap_core->shutdown(): %s, status = %s.\n"),
       
  1279 				 (m_is_client == true) ? "client": "server",
       
  1280 				 eap_status_string_c::get_status_string(status)));
       
  1281 
       
  1282 			WAUTH_LEAVE_MUTEX(m_am_tools);
       
  1283 
       
  1284 			delete m_eap_core;
       
  1285 			m_eap_core = 0;							
       
  1286 
       
  1287 			EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Stack creation failed.\n")));			
       
  1288 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);	
       
  1289 			return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error);	
       
  1290 		}
       
  1291 	}
       
  1292 	else
       
  1293 	{			
       
  1294 		status = eap_status_already_exists;
       
  1295 	}
       
  1296 
       
  1297 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
  1298 	return EAP_STATUS_RETURN(m_am_tools, status);
       
  1299 }
       
  1300 
       
  1301 //--------------------------------------------------
       
  1302 
       
  1303 
       
  1304 // End.