1 /* |
|
2 * ============================================================================ |
|
3 * Name : ./accesssec/eapol/eapol_framework/wapi_common/src/wapi_session_core.cpp |
|
4 * Part of : WAPI / WAPI *** Info from the SWAD |
|
5 * Description : WAPI authentication |
|
6 * Version : %version: 16.1.1 % << Don't touch! Updated by Synergy at check-out. |
|
7 * |
|
8 * Copyright © 2001-2009 Nokia. All rights reserved. |
|
9 * This material, including documentation and any related computer |
|
10 * programs, is protected by copyright controlled by Nokia. All |
|
11 * rights are reserved. Copying, including reproducing, storing, |
|
12 * adapting or translating, any or all of this material requires the |
|
13 * prior written consent of Nokia. This material also contains |
|
14 * confidential information which may not be disclosed to others |
|
15 * without the prior written consent of Nokia. |
|
16 * ============================================================================ |
|
17 * Template version: 4.1.1 |
|
18 */ |
|
19 |
|
20 // This is enumeration of WAPI source code. |
|
21 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
22 #undef EAP_FILE_NUMBER_ENUM |
|
23 #define EAP_FILE_NUMBER_ENUM 20004 |
|
24 #undef EAP_FILE_NUMBER_DATE |
|
25 #define EAP_FILE_NUMBER_DATE 1127594498 |
|
26 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
27 |
|
28 |
|
29 |
|
30 #include "eap_am_memory.h" |
|
31 #include "eap_tools.h" |
|
32 #include "wapi_session_core.h" |
|
33 #include "eap_state_notification.h" |
|
34 #include "eap_network_id_selector.h" |
|
35 #include "abs_eap_am_mutex.h" |
|
36 #include "eap_config.h" |
|
37 #include "wapi_core.h" |
|
38 #include "eap_buffer.h" |
|
39 #include "eap_automatic_variable.h" |
|
40 #include "wai_protocol_packet_header.h" |
|
41 #include "wapi_strings.h" |
|
42 #include "eapol_session_key.h" |
|
43 |
|
44 |
|
45 //-------------------------------------------------- |
|
46 |
|
47 // |
|
48 EAP_FUNC_EXPORT wapi_session_core_c::~wapi_session_core_c() |
|
49 { |
|
50 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
51 |
|
52 EAP_TRACE_DEBUG( |
|
53 m_am_tools, |
|
54 TRACE_FLAGS_DEFAULT, |
|
55 (EAPL("wapi_session_core_c::~wapi_session_core_c(): this = 0x%08x => 0x%08x.\n"), |
|
56 this, |
|
57 dynamic_cast<abs_eap_base_timer_c *>(this))); |
|
58 |
|
59 EAP_ASSERT(m_shutdown_was_called == true); |
|
60 |
|
61 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
62 } |
|
63 |
|
64 //-------------------------------------------------- |
|
65 |
|
66 #if defined(_WIN32) && !defined(__GNUC__) |
|
67 #pragma warning( disable : 4355 ) // 'this' : used in base member initializer list |
|
68 #endif |
|
69 |
|
70 // |
|
71 EAP_FUNC_EXPORT wapi_session_core_c::wapi_session_core_c( |
|
72 abs_eap_am_tools_c * const tools, |
|
73 abs_wapi_core_c * const partner, |
|
74 const bool is_client_when_true) |
|
75 : m_partner(partner) |
|
76 , m_am_tools(tools) |
|
77 , m_session_map(tools, this) |
|
78 , m_remove_session_timeout(WAPI_SESSION_CORE_REMOVE_SESSION_TIMEOUT) |
|
79 , m_is_client(is_client_when_true) |
|
80 , m_is_valid(false) |
|
81 , m_use_wapi_session_core_reset_session(true) |
|
82 , m_shutdown_was_called(false) |
|
83 { |
|
84 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
85 |
|
86 EAP_TRACE_DEBUG( |
|
87 m_am_tools, |
|
88 TRACE_FLAGS_DEFAULT, |
|
89 (EAPL("wapi_session_core_c::wapi_session_core_c(): this = 0x%08x => 0x%08x.\n"), |
|
90 this, |
|
91 dynamic_cast<abs_eap_base_timer_c *>(this))); |
|
92 |
|
93 set_is_valid(); |
|
94 |
|
95 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
96 } |
|
97 |
|
98 //-------------------------------------------------- |
|
99 |
|
100 // |
|
101 EAP_FUNC_EXPORT abs_wapi_core_c * wapi_session_core_c::get_partner() |
|
102 { |
|
103 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
104 |
|
105 return m_partner; |
|
106 } |
|
107 |
|
108 //-------------------------------------------------- |
|
109 |
|
110 // |
|
111 EAP_FUNC_EXPORT void wapi_session_core_c::set_is_valid() |
|
112 { |
|
113 m_is_valid = true; |
|
114 } |
|
115 |
|
116 //-------------------------------------------------- |
|
117 |
|
118 // |
|
119 EAP_FUNC_EXPORT bool wapi_session_core_c::get_is_valid() |
|
120 { |
|
121 return m_is_valid; |
|
122 } |
|
123 |
|
124 //-------------------------------------------------- |
|
125 |
|
126 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::reset() |
|
127 { |
|
128 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
129 |
|
130 EAP_TRACE_DEBUG( |
|
131 m_am_tools, |
|
132 TRACE_FLAGS_DEFAULT, |
|
133 (EAPL("wapi_session_core_c::reset(): this = 0x%08x => 0x%08x.\n"), |
|
134 this, |
|
135 dynamic_cast<abs_eap_base_timer_c *>(this))); |
|
136 |
|
137 eap_status_e status = m_session_map.for_each(shutdown_operation, true); |
|
138 (void)EAP_STATUS_RETURN(m_am_tools, status); |
|
139 |
|
140 status = m_session_map.reset(); |
|
141 (void)EAP_STATUS_RETURN(m_am_tools, status); |
|
142 |
|
143 m_partner->cancel_timer(this, WAPI_SESSION_CORE_REMOVE_SESSION_ID); |
|
144 |
|
145 EAP_TRACE_DEBUG( |
|
146 m_am_tools, |
|
147 TRACE_FLAGS_DEFAULT, |
|
148 (EAPL("TIMER: WAPI_SESSION_CORE_REMOVE_SESSION_ID cancelled, %s.\n"), |
|
149 (m_is_client == true) ? "client": "server")); |
|
150 |
|
151 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
152 return EAP_STATUS_RETURN(m_am_tools, status); |
|
153 } |
|
154 |
|
155 //-------------------------------------------------- |
|
156 |
|
157 // |
|
158 EAP_FUNC_EXPORT wapi_core_c * wapi_session_core_c::create_new_session( |
|
159 const eap_am_network_id_c * const receive_network_id) |
|
160 { |
|
161 eap_status_e status = eap_status_process_general_error; |
|
162 |
|
163 // Create a new session. |
|
164 wapi_core_c * const session = new wapi_core_c( |
|
165 m_am_tools, |
|
166 this, |
|
167 m_is_client, |
|
168 receive_network_id); |
|
169 |
|
170 if (session == 0) |
|
171 { |
|
172 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
173 (void)EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
174 return 0; |
|
175 } |
|
176 |
|
177 if (session->get_is_valid() == false) |
|
178 { |
|
179 session->shutdown(); |
|
180 delete session; |
|
181 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
182 (void)EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
183 return 0; |
|
184 } |
|
185 |
|
186 status = session->configure(); |
|
187 if (status != eap_status_ok) |
|
188 { |
|
189 session->shutdown(); |
|
190 delete session; |
|
191 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
192 (void)EAP_STATUS_RETURN(m_am_tools, status); |
|
193 return 0; |
|
194 } |
|
195 |
|
196 // Here we swap the addresses. |
|
197 eap_am_network_id_c send_network_id(m_am_tools, |
|
198 receive_network_id->get_destination_id(), |
|
199 receive_network_id->get_source_id(), |
|
200 receive_network_id->get_type()); |
|
201 if (send_network_id.get_is_valid_data() == false) |
|
202 { |
|
203 session->shutdown(); |
|
204 delete session; |
|
205 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
206 (void)EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
207 return 0; |
|
208 } |
|
209 |
|
210 eap_network_id_selector_c selector( |
|
211 m_am_tools, |
|
212 &send_network_id); |
|
213 if (selector.get_is_valid() == false) |
|
214 { |
|
215 session->shutdown(); |
|
216 delete session; |
|
217 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
218 (void)EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
219 return 0; |
|
220 } |
|
221 |
|
222 EAP_TRACE_DATA_DEBUG( |
|
223 m_am_tools, |
|
224 TRACE_FLAGS_DEFAULT, |
|
225 (EAPL("create_new_session() WAPI session"), |
|
226 selector.get_data(selector.get_data_length()), |
|
227 selector.get_data_length())); |
|
228 |
|
229 status = m_session_map.add_handler(&selector, session); |
|
230 if (status != eap_status_ok) |
|
231 { |
|
232 session->shutdown(); |
|
233 delete session; |
|
234 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
235 (void)EAP_STATUS_RETURN(m_am_tools, status); |
|
236 return 0; |
|
237 } |
|
238 |
|
239 return session; |
|
240 } |
|
241 |
|
242 //-------------------------------------------------- |
|
243 |
|
244 // |
|
245 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::reset_or_remove_session( |
|
246 wapi_core_c ** const session, |
|
247 const eap_network_id_selector_c * const selector, |
|
248 const bool reset_immediately) |
|
249 { |
|
250 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
251 |
|
252 eap_status_e status(eap_status_process_general_error); |
|
253 |
|
254 if (session == 0 |
|
255 || *session == 0 |
|
256 || selector == 0) |
|
257 { |
|
258 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
259 return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter); |
|
260 } |
|
261 |
|
262 |
|
263 if (m_use_wapi_session_core_reset_session == true) |
|
264 { |
|
265 // This will reuse session. |
|
266 EAP_TRACE_DEBUG( |
|
267 m_am_tools, |
|
268 TRACE_FLAGS_DEFAULT, |
|
269 (EAPL("wapi_session_core_c::reset_or_remove_session(): resets session, session 0x%08x.\n"), |
|
270 (*session))); |
|
271 |
|
272 // NOTE, this delayed reset of session is used bacause the device is so slow in some cases |
|
273 // (e.g. it cannot respond to WPA 4-Way Handshake message fast enough) |
|
274 |
|
275 if (reset_immediately == true) |
|
276 { |
|
277 (*session)->unset_marked_removed(); |
|
278 |
|
279 status = (*session)->reset(); |
|
280 } |
|
281 else |
|
282 { |
|
283 // This will delay reset to wapi_core_c::packet_process(). |
|
284 status = eap_status_ok; |
|
285 } |
|
286 } |
|
287 else |
|
288 { |
|
289 // This will cause shutdown of the session. |
|
290 status = eap_status_process_general_error; |
|
291 } |
|
292 |
|
293 if (status != eap_status_ok) |
|
294 { |
|
295 // We cannot reuse the session. |
|
296 |
|
297 EAP_TRACE_DEBUG( |
|
298 m_am_tools, |
|
299 TRACE_FLAGS_DEFAULT, |
|
300 (EAPL("wapi_session_core_c::reset_or_remove_session(): shutdown session, session 0x%08x.\n"), |
|
301 (*session))); |
|
302 |
|
303 (*session)->shutdown(); |
|
304 (*session) = 0; |
|
305 |
|
306 status = m_session_map.remove_handler(selector, true); |
|
307 if (status != eap_status_ok) |
|
308 { |
|
309 EAP_TRACE_DEBUG( |
|
310 m_am_tools, |
|
311 TRACE_FLAGS_DEFAULT, |
|
312 (EAPL("ERROR: wapi_session_core_c::reset_or_remove_session(): m_session_map.remove_type(), eap_status_e %d\n"), |
|
313 status)); |
|
314 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
315 return EAP_STATUS_RETURN(m_am_tools, status); |
|
316 } |
|
317 |
|
318 EAP_TRACE_DEBUG( |
|
319 m_am_tools, |
|
320 TRACE_FLAGS_DEFAULT, |
|
321 (EAPL("wapi_session_core_c::reset_or_remove_session(): session NOT reused.\n"))); |
|
322 } |
|
323 else |
|
324 { |
|
325 EAP_TRACE_DEBUG( |
|
326 m_am_tools, |
|
327 TRACE_FLAGS_DEFAULT, |
|
328 (EAPL("wapi_session_core_c::reset_or_remove_session(): session reused, session 0x%08x.\n"), |
|
329 (*session))); |
|
330 } |
|
331 |
|
332 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
333 return EAP_STATUS_RETURN(m_am_tools, status); |
|
334 } |
|
335 |
|
336 //-------------------------------------------------- |
|
337 |
|
338 // |
|
339 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::packet_process( |
|
340 const eap_am_network_id_c * const receive_network_id, |
|
341 eap_general_header_base_c * const packet_data, |
|
342 const u32_t packet_length) |
|
343 { |
|
344 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
345 |
|
346 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
347 |
|
348 eap_status_e status = eap_status_process_general_error; |
|
349 |
|
350 // Each WAPI authentication session includes its own wapi_core_c object. |
|
351 // WAPI authentication sessions are separated by eap_am_network_id_c object. |
|
352 |
|
353 if (packet_data == 0 |
|
354 || packet_length < eap_header_base_c::get_header_length()) |
|
355 { |
|
356 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
357 return EAP_STATUS_RETURN(m_am_tools, eap_status_process_illegal_packet_error); |
|
358 } |
|
359 |
|
360 if (receive_network_id == 0 |
|
361 || receive_network_id->get_is_valid_data() == false) |
|
362 { |
|
363 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
364 return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter); |
|
365 } |
|
366 |
|
367 wai_protocol_packet_header_c wai( |
|
368 m_am_tools, |
|
369 packet_data->get_header_buffer(packet_length), |
|
370 packet_length); |
|
371 |
|
372 if (wai.get_is_valid() == false) |
|
373 { |
|
374 EAP_TRACE_ERROR( |
|
375 m_am_tools, |
|
376 TRACE_FLAGS_DEFAULT, |
|
377 (EAPL("wapi_session_core_c::packet_process(): %s, packet buffer corrupted.\n"), |
|
378 (m_is_client == true) ? "client": "server" |
|
379 )); |
|
380 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
381 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
382 } |
|
383 |
|
384 EAP_TRACE_DATA_DEBUG( |
|
385 m_am_tools, |
|
386 EAP_TRACE_FLAGS_MESSAGE_DATA|TRACE_TEST_VECTORS, |
|
387 (EAPL("WAI-packet"), |
|
388 wai.get_header_buffer(packet_length), |
|
389 packet_length)); |
|
390 |
|
391 WAI_PROTOCOL_PACKET_TRACE_HEADER("->", &wai, m_is_client); |
|
392 |
|
393 status = wai.check_header(); |
|
394 if (status != eap_status_ok) |
|
395 { |
|
396 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
397 return EAP_STATUS_RETURN(m_am_tools, status); |
|
398 } |
|
399 |
|
400 // Here we swap the addresses. |
|
401 eap_am_network_id_c send_network_id(m_am_tools, |
|
402 receive_network_id->get_destination_id(), |
|
403 receive_network_id->get_source_id(), |
|
404 receive_network_id->get_type()); |
|
405 if (send_network_id.get_is_valid_data() == false) |
|
406 { |
|
407 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
408 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
409 } |
|
410 |
|
411 eap_network_id_selector_c selector( |
|
412 m_am_tools, |
|
413 &send_network_id); |
|
414 if (selector.get_is_valid() == false) |
|
415 { |
|
416 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
417 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
418 } |
|
419 |
|
420 EAP_TRACE_DATA_DEBUG( |
|
421 m_am_tools, |
|
422 TRACE_FLAGS_DEFAULT, |
|
423 (EAPL("packet_process() WAPI-session"), |
|
424 selector.get_data(selector.get_data_length()), |
|
425 selector.get_data_length())); |
|
426 |
|
427 wapi_core_c *session = m_session_map.get_handler(&selector); |
|
428 |
|
429 if (session == 0) |
|
430 { |
|
431 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
432 return EAP_STATUS_RETURN(m_am_tools, eap_status_handler_does_not_exists_error); |
|
433 } |
|
434 |
|
435 if (session != 0) |
|
436 { |
|
437 status = session->packet_process( |
|
438 receive_network_id, |
|
439 &wai, |
|
440 packet_length); |
|
441 } |
|
442 else |
|
443 { |
|
444 status = eap_status_illegal_eap_type; |
|
445 } |
|
446 |
|
447 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
448 return EAP_STATUS_RETURN(m_am_tools, status); |
|
449 } |
|
450 |
|
451 //-------------------------------------------------- |
|
452 |
|
453 // |
|
454 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::packet_send( |
|
455 const eap_am_network_id_c * const send_network_id, |
|
456 eap_buf_chain_wr_c * const sent_packet, |
|
457 const u32_t header_offset, |
|
458 const u32_t data_length, |
|
459 const u32_t buffer_length) |
|
460 { |
|
461 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
462 |
|
463 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
464 |
|
465 EAP_ASSERT(header_offset < sent_packet->get_data_length()); |
|
466 EAP_ASSERT(data_length <= sent_packet->get_data_length()); |
|
467 EAP_ASSERT(sent_packet->get_data_length() <= buffer_length); |
|
468 |
|
469 wai_protocol_packet_header_c wai( |
|
470 m_am_tools, |
|
471 sent_packet->get_data_offset(header_offset, data_length), |
|
472 data_length); |
|
473 |
|
474 if (wai.get_is_valid() == false) |
|
475 { |
|
476 EAP_TRACE_ERROR( |
|
477 m_am_tools, |
|
478 TRACE_FLAGS_DEFAULT, |
|
479 (EAPL("wapi_session_core_c::packet_process(): %s, packet buffer corrupted.\n"), |
|
480 (m_is_client == true) ? "client": "server" |
|
481 )); |
|
482 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
483 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
484 } |
|
485 |
|
486 EAP_TRACE_DATA_DEBUG( |
|
487 m_am_tools, |
|
488 EAP_TRACE_FLAGS_MESSAGE_DATA|TRACE_TEST_VECTORS, |
|
489 (EAPL("WAI-packet"), |
|
490 wai.get_header_buffer(data_length), |
|
491 data_length)); |
|
492 |
|
493 WAI_PROTOCOL_PACKET_TRACE_HEADER("<-", &wai, m_is_client); |
|
494 |
|
495 eap_status_e status = m_partner->packet_send( |
|
496 send_network_id, sent_packet, header_offset, data_length, buffer_length); |
|
497 |
|
498 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
499 return EAP_STATUS_RETURN(m_am_tools, status); |
|
500 } |
|
501 |
|
502 //-------------------------------------------------- |
|
503 |
|
504 // |
|
505 EAP_FUNC_EXPORT u32_t wapi_session_core_c::get_header_offset( |
|
506 u32_t * const MTU, |
|
507 u32_t * const trailer_length) |
|
508 { |
|
509 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
510 |
|
511 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
512 |
|
513 const u32_t offset = m_partner->get_header_offset(MTU, trailer_length); |
|
514 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
515 return offset; |
|
516 } |
|
517 |
|
518 //-------------------------------------------------- |
|
519 |
|
520 // |
|
521 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::configure() |
|
522 { |
|
523 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
524 |
|
525 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
526 |
|
527 |
|
528 { |
|
529 // This is optional. |
|
530 eap_variable_data_c data(m_am_tools); |
|
531 |
|
532 eap_status_e status = m_partner->read_configure( |
|
533 cf_str_EAP_SESSION_use_reset_session.get_field(), |
|
534 &data); |
|
535 if (status == eap_status_ok |
|
536 && data.get_data_length() == sizeof(u32_t) |
|
537 && data.get_data(data.get_data_length()) != 0) |
|
538 { |
|
539 u32_t *flag = reinterpret_cast<u32_t *>(data.get_data(data.get_data_length())); |
|
540 |
|
541 if (flag != 0) |
|
542 { |
|
543 if ((*flag) != 0ul) |
|
544 { |
|
545 m_use_wapi_session_core_reset_session = true; |
|
546 } |
|
547 else |
|
548 { |
|
549 m_use_wapi_session_core_reset_session = false; |
|
550 } |
|
551 } |
|
552 } |
|
553 } |
|
554 |
|
555 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
556 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
557 } |
|
558 |
|
559 //-------------------------------------------------- |
|
560 |
|
561 // |
|
562 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::shutdown_operation( |
|
563 wapi_core_c * const core, |
|
564 abs_eap_am_tools_c * const m_am_tools) |
|
565 { |
|
566 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
567 |
|
568 EAP_UNREFERENCED_PARAMETER(m_am_tools); |
|
569 |
|
570 eap_status_e status = core->shutdown(); |
|
571 |
|
572 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
573 return EAP_STATUS_RETURN(m_am_tools, status); |
|
574 } |
|
575 |
|
576 //-------------------------------------------------- |
|
577 |
|
578 // |
|
579 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::shutdown() |
|
580 { |
|
581 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
582 |
|
583 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
584 |
|
585 EAP_TRACE_DEBUG( |
|
586 m_am_tools, |
|
587 TRACE_FLAGS_DEFAULT, |
|
588 (EAPL("wapi_session_core_c::shutdown(): this = 0x%08x => 0x%08x.\n"), |
|
589 this, |
|
590 dynamic_cast<abs_eap_base_timer_c *>(this))); |
|
591 |
|
592 if (m_shutdown_was_called == true) |
|
593 { |
|
594 // Shutdown function was called already. |
|
595 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
596 } |
|
597 m_shutdown_was_called = true; |
|
598 |
|
599 eap_status_e status = reset(); |
|
600 |
|
601 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
602 return EAP_STATUS_RETURN(m_am_tools, status); |
|
603 } |
|
604 |
|
605 //-------------------------------------------------- |
|
606 |
|
607 // |
|
608 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::restart_authentication( |
|
609 const eap_am_network_id_c * const send_network_id, |
|
610 const bool is_client_when_true) |
|
611 { |
|
612 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
613 |
|
614 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
615 EAP_ASSERT(is_client_when_true == m_is_client); |
|
616 |
|
617 eap_status_e status = eap_status_process_general_error; |
|
618 |
|
619 eap_network_id_selector_c selector( |
|
620 m_am_tools, |
|
621 send_network_id); |
|
622 if (selector.get_is_valid() == false) |
|
623 { |
|
624 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
625 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
626 } |
|
627 |
|
628 EAP_TRACE_DATA_DEBUG( |
|
629 m_am_tools, |
|
630 TRACE_FLAGS_DEFAULT, |
|
631 (EAPL("restart_authentication() WAPI session"), |
|
632 selector.get_data(selector.get_data_length()), |
|
633 selector.get_data_length())); |
|
634 |
|
635 wapi_core_c *session = m_session_map.get_handler(&selector); |
|
636 |
|
637 if (session != 0) |
|
638 { |
|
639 status = session->restart_authentication( |
|
640 send_network_id, |
|
641 is_client_when_true); |
|
642 } |
|
643 |
|
644 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
645 return EAP_STATUS_RETURN(m_am_tools, status); |
|
646 } |
|
647 |
|
648 //-------------------------------------------------- |
|
649 |
|
650 // |
|
651 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::restart_authentication( |
|
652 const eap_am_network_id_c * const receive_network_id, |
|
653 const bool is_client_when_true, |
|
654 const bool force_clean_restart, |
|
655 const bool from_timer) |
|
656 { |
|
657 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
658 |
|
659 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
660 EAP_ASSERT(is_client_when_true == m_is_client); |
|
661 |
|
662 eap_status_e status = eap_status_process_general_error; |
|
663 |
|
664 // Here we swap the addresses. |
|
665 eap_am_network_id_c send_network_id(m_am_tools, |
|
666 receive_network_id->get_destination_id(), |
|
667 receive_network_id->get_source_id(), |
|
668 receive_network_id->get_type()); |
|
669 if (send_network_id.get_is_valid_data() == false) |
|
670 { |
|
671 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
672 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
673 } |
|
674 |
|
675 eap_network_id_selector_c selector( |
|
676 m_am_tools, |
|
677 &send_network_id); |
|
678 if (selector.get_is_valid() == false) |
|
679 { |
|
680 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
681 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
682 } |
|
683 |
|
684 EAP_TRACE_DATA_DEBUG( |
|
685 m_am_tools, |
|
686 TRACE_FLAGS_DEFAULT, |
|
687 (EAPL("restart_authentication() WAPI session"), |
|
688 selector.get_data(selector.get_data_length()), |
|
689 selector.get_data_length())); |
|
690 |
|
691 wapi_core_c *session = m_session_map.get_handler(&selector); |
|
692 |
|
693 if (session == 0) |
|
694 { |
|
695 // Create a new session. |
|
696 session = create_new_session(receive_network_id); |
|
697 } |
|
698 |
|
699 if (session != 0) |
|
700 { |
|
701 status = session->restart_authentication( |
|
702 receive_network_id, |
|
703 is_client_when_true); |
|
704 } |
|
705 |
|
706 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
707 return EAP_STATUS_RETURN(m_am_tools, status); |
|
708 } |
|
709 |
|
710 //-------------------------------------------------- |
|
711 |
|
712 // |
|
713 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::packet_data_session_key( |
|
714 const eap_am_network_id_c * const send_network_id, |
|
715 const eapol_session_key_c * const key) |
|
716 { |
|
717 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
718 |
|
719 EAP_TRACE_DEBUG( |
|
720 m_am_tools, |
|
721 TRACE_FLAGS_DEFAULT, |
|
722 (EAPL("%s: wapi_session_core_c::packet_data_session_key()\n"), |
|
723 (m_is_client == true) ? "client": "server")); |
|
724 |
|
725 EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_session_core_c::packet_data_session_key()"); |
|
726 |
|
727 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
728 |
|
729 eap_status_e status = eap_status_process_general_error; |
|
730 |
|
731 if (key->get_is_valid() == true) |
|
732 { |
|
733 EAP_TRACE_DEBUG( |
|
734 m_am_tools, |
|
735 TRACE_FLAGS_DEFAULT, |
|
736 (EAPL("eapol session key: type 0x%02x, index 0x%02x, tx %d\n"), |
|
737 key->get_key_type(), |
|
738 key->get_key_index(), |
|
739 key->get_key_tx_bit())); |
|
740 |
|
741 EAP_TRACE_DATA_DEBUG( |
|
742 m_am_tools, |
|
743 TRACE_FLAGS_DEFAULT, |
|
744 (EAPL("eapol session key"), |
|
745 key->get_key()->get_data(key->get_key()->get_data_length()), |
|
746 key->get_key()->get_data_length())); |
|
747 } |
|
748 |
|
749 // Forward the keys to lower layers |
|
750 status = m_partner->packet_data_session_key( |
|
751 send_network_id, |
|
752 key); |
|
753 |
|
754 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
755 return EAP_STATUS_RETURN(m_am_tools, status); |
|
756 } |
|
757 |
|
758 //-------------------------------------------------- |
|
759 |
|
760 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::read_configure( |
|
761 const eap_configuration_field_c * const field, |
|
762 eap_variable_data_c * const data) |
|
763 { |
|
764 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
765 |
|
766 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
767 |
|
768 const eap_status_e status = m_partner->read_configure(field, data); |
|
769 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
770 return EAP_STATUS_RETURN(m_am_tools, status); |
|
771 } |
|
772 |
|
773 //-------------------------------------------------- |
|
774 |
|
775 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::write_configure( |
|
776 const eap_configuration_field_c * const field, |
|
777 eap_variable_data_c * const data) |
|
778 { |
|
779 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
780 |
|
781 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
782 |
|
783 const eap_status_e status = m_partner->write_configure(field, data); |
|
784 |
|
785 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
786 return EAP_STATUS_RETURN(m_am_tools, status); |
|
787 } |
|
788 |
|
789 //-------------------------------------------------- |
|
790 |
|
791 // |
|
792 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::timer_expired( |
|
793 const u32_t id, void *data) |
|
794 { |
|
795 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
796 |
|
797 EAP_TRACE_DEBUG( |
|
798 m_am_tools, |
|
799 TRACE_FLAGS_DEFAULT, |
|
800 (EAPL("TIMER: [0x%08x]->wapi_session_core_c::") |
|
801 EAPL("timer_expired(id 0x%02x, data 0x%08x), %s.\n"), |
|
802 this, |
|
803 id, |
|
804 data, |
|
805 (m_is_client == true) ? "client": "server")); |
|
806 |
|
807 if (id == WAPI_SESSION_CORE_REMOVE_SESSION_ID) |
|
808 { |
|
809 EAP_TRACE_DEBUG( |
|
810 m_am_tools, |
|
811 TRACE_FLAGS_DEFAULT, |
|
812 (EAPL("TIMER: WAPI_SESSION_CORE_REMOVE_SESSION_ID elapsed, %s.\n"), |
|
813 (m_is_client == true) ? "client": "server")); |
|
814 |
|
815 const eap_network_id_selector_c * const selector |
|
816 = reinterpret_cast<const eap_network_id_selector_c *>(data); |
|
817 if (selector == 0 |
|
818 || selector->get_is_valid() == false) |
|
819 { |
|
820 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
821 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
822 } |
|
823 |
|
824 EAP_TRACE_DATA_DEBUG( |
|
825 m_am_tools, |
|
826 TRACE_FLAGS_DEFAULT, |
|
827 (EAPL("timer_expired() WAPI-session"), |
|
828 selector->get_data(selector->get_data_length()), |
|
829 selector->get_data_length())); |
|
830 |
|
831 wapi_core_c *session = m_session_map.get_handler(selector); |
|
832 |
|
833 if (session != 0 |
|
834 && session->get_marked_removed() == true) |
|
835 { |
|
836 EAP_TRACE_DEBUG( |
|
837 m_am_tools, |
|
838 TRACE_FLAGS_DEFAULT, |
|
839 (EAPL("TIMER: unused session found, it is deleted, session 0x%08x.\n"), |
|
840 session)); |
|
841 |
|
842 // Session must be deleted here. |
|
843 session->shutdown(); |
|
844 session = 0; |
|
845 |
|
846 // This will delete session. |
|
847 eap_status_e status = m_session_map.remove_handler(selector, true); |
|
848 if (status != eap_status_ok) |
|
849 { |
|
850 EAP_TRACE_DEBUG( |
|
851 m_am_tools, |
|
852 TRACE_FLAGS_DEFAULT, |
|
853 (EAPL("ERROR: m_session_map.remove_type(), eap_status_e %d\n"), |
|
854 status)); |
|
855 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
856 return EAP_STATUS_RETURN(m_am_tools, status); |
|
857 } |
|
858 } |
|
859 else if (session != 0 |
|
860 && session->get_marked_removed() == false) |
|
861 { |
|
862 EAP_TRACE_DEBUG( |
|
863 m_am_tools, |
|
864 TRACE_FLAGS_DEFAULT, |
|
865 (EAPL("TIMER: session found, it is in use, session 0x%08x.\n"), |
|
866 session)); |
|
867 } |
|
868 else |
|
869 { |
|
870 // Not found, no need to remove. |
|
871 EAP_TRACE_DEBUG( |
|
872 m_am_tools, |
|
873 TRACE_FLAGS_DEFAULT, |
|
874 (EAPL("TIMER: session not found.\n"))); |
|
875 } |
|
876 } |
|
877 |
|
878 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
879 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
880 } |
|
881 |
|
882 //-------------------------------------------------- |
|
883 |
|
884 // |
|
885 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::timer_delete_data( |
|
886 const u32_t id, void *data) |
|
887 { |
|
888 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
889 |
|
890 EAP_TRACE_DEBUG( |
|
891 m_am_tools, |
|
892 TRACE_FLAGS_DEFAULT, |
|
893 (EAPL("TIMER: [0x%08x]->wapi_session_core_c::") |
|
894 EAPL("timer_delete_data(id 0x%02x, data 0x%08x).\n"), |
|
895 this, id, data)); |
|
896 |
|
897 if (id == WAPI_SESSION_CORE_REMOVE_SESSION_ID) |
|
898 |
|
899 { |
|
900 const eap_network_id_selector_c * const selector |
|
901 = reinterpret_cast<const eap_network_id_selector_c *>(data); |
|
902 delete selector; |
|
903 } |
|
904 |
|
905 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
906 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
907 } |
|
908 |
|
909 //-------------------------------------------------- |
|
910 |
|
911 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::synchronous_cancel_all_wapi_sessions() |
|
912 { |
|
913 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
914 |
|
915 EAP_TRACE_DEBUG( |
|
916 m_am_tools, |
|
917 TRACE_FLAGS_DEFAULT, |
|
918 (EAPL("wapi_session_core_c::synchronous_cancel_all_wapi_sessions(): this = 0x%08x => 0x%08x.\n"), |
|
919 this, |
|
920 dynamic_cast<abs_eap_base_timer_c *>(this))); |
|
921 |
|
922 eap_status_e status = reset(); |
|
923 |
|
924 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
925 return EAP_STATUS_RETURN(m_am_tools, status); |
|
926 } |
|
927 |
|
928 //-------------------------------------------------- |
|
929 |
|
930 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::synchronous_create_wapi_session( |
|
931 const eap_am_network_id_c * const receive_network_id) |
|
932 { |
|
933 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
934 |
|
935 EAP_TRACE_DEBUG( |
|
936 m_am_tools, |
|
937 TRACE_FLAGS_DEFAULT, |
|
938 (EAPL("wapi_session_core_c::synchronous_create_wapi_session(): this = 0x%08x => 0x%08x.\n"), |
|
939 this, |
|
940 dynamic_cast<abs_eap_base_timer_c *>(this))); |
|
941 |
|
942 eap_status_e status = eap_status_process_general_error; |
|
943 |
|
944 // Here we swap the addresses. |
|
945 eap_am_network_id_c send_network_id( |
|
946 m_am_tools, |
|
947 receive_network_id->get_destination_id(), |
|
948 receive_network_id->get_source_id(), |
|
949 receive_network_id->get_type()); |
|
950 if (send_network_id.get_is_valid_data() == false) |
|
951 { |
|
952 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
953 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
954 } |
|
955 |
|
956 eap_network_id_selector_c selector( |
|
957 m_am_tools, |
|
958 &send_network_id); |
|
959 if (selector.get_is_valid() == false) |
|
960 { |
|
961 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
962 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
963 } |
|
964 |
|
965 EAP_TRACE_DATA_DEBUG( |
|
966 m_am_tools, |
|
967 TRACE_FLAGS_DEFAULT, |
|
968 (EAPL("synchronous_create_eap_session() WAPI-session"), |
|
969 selector.get_data(selector.get_data_length()), |
|
970 selector.get_data_length())); |
|
971 |
|
972 wapi_core_c *session = m_session_map.get_handler(&selector); |
|
973 |
|
974 if (session == 0) |
|
975 { |
|
976 session = create_new_session(receive_network_id); |
|
977 |
|
978 if (session == 0) |
|
979 { |
|
980 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
981 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
982 } |
|
983 else |
|
984 { |
|
985 status = eap_status_ok; |
|
986 } |
|
987 } |
|
988 else |
|
989 { |
|
990 status = eap_status_ok; |
|
991 } |
|
992 |
|
993 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
994 return EAP_STATUS_RETURN(m_am_tools, status); |
|
995 } |
|
996 |
|
997 //-------------------------------------------------- |
|
998 |
|
999 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::synchronous_remove_wapi_session( |
|
1000 const eap_am_network_id_c * const receive_network_id) |
|
1001 { |
|
1002 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1003 |
|
1004 EAP_TRACE_DEBUG( |
|
1005 m_am_tools, |
|
1006 TRACE_FLAGS_DEFAULT, |
|
1007 (EAPL("wapi_session_core_c::synchronous_remove_eap_session(): this = 0x%08x => 0x%08x.\n"), |
|
1008 this, |
|
1009 dynamic_cast<abs_eap_base_timer_c *>(this))); |
|
1010 |
|
1011 eap_status_e status = eap_status_process_general_error; |
|
1012 |
|
1013 // Here we swap the addresses. |
|
1014 eap_am_network_id_c send_network_id( |
|
1015 m_am_tools, |
|
1016 receive_network_id->get_destination_id(), |
|
1017 receive_network_id->get_source_id(), |
|
1018 receive_network_id->get_type()); |
|
1019 if (send_network_id.get_is_valid_data() == false) |
|
1020 { |
|
1021 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1022 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1023 } |
|
1024 |
|
1025 eap_network_id_selector_c selector( |
|
1026 m_am_tools, |
|
1027 &send_network_id); |
|
1028 if (selector.get_is_valid() == false) |
|
1029 { |
|
1030 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1031 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1032 } |
|
1033 |
|
1034 EAP_TRACE_DATA_DEBUG( |
|
1035 m_am_tools, |
|
1036 TRACE_FLAGS_DEFAULT, |
|
1037 (EAPL("synchronous_remove_eap_session() WAPI-session"), |
|
1038 selector.get_data(selector.get_data_length()), |
|
1039 selector.get_data_length())); |
|
1040 |
|
1041 wapi_core_c *session = m_session_map.get_handler(&selector); |
|
1042 |
|
1043 if (session != 0) |
|
1044 { |
|
1045 // This reset is immediaete. |
|
1046 status = reset_or_remove_session( |
|
1047 &session, |
|
1048 &selector, |
|
1049 true); |
|
1050 if (status != eap_status_ok) |
|
1051 { |
|
1052 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1053 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1054 } |
|
1055 } |
|
1056 else |
|
1057 { |
|
1058 // Not found, no need to remove. |
|
1059 status = eap_status_ok; |
|
1060 } |
|
1061 |
|
1062 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1063 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1064 } |
|
1065 |
|
1066 //-------------------------------------------------- |
|
1067 |
|
1068 // |
|
1069 eap_status_e wapi_session_core_c::asynchronous_init_remove_wapi_session( |
|
1070 const eap_am_network_id_c * const send_network_id) |
|
1071 { |
|
1072 EAP_TRACE_DEBUG( |
|
1073 m_am_tools, |
|
1074 TRACE_FLAGS_DEFAULT, |
|
1075 (EAPL("wapi_session_core_c::asynchronous_init_remove_wapi_session(): %s.\n"), |
|
1076 (m_is_client == true) ? "client": "server")); |
|
1077 |
|
1078 eap_network_id_selector_c state_selector( |
|
1079 m_am_tools, |
|
1080 send_network_id); |
|
1081 if (state_selector.get_is_valid() == false) |
|
1082 { |
|
1083 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1084 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1085 } |
|
1086 |
|
1087 EAP_TRACE_DATA_DEBUG( |
|
1088 m_am_tools, |
|
1089 TRACE_FLAGS_DEFAULT, |
|
1090 (EAPL("asynchronous_init_remove_wapi_session() WAPI session"), |
|
1091 state_selector.get_data(state_selector.get_data_length()), |
|
1092 state_selector.get_data_length())); |
|
1093 |
|
1094 eap_status_e status = asynchronous_init_remove_wapi_session( |
|
1095 &state_selector); |
|
1096 |
|
1097 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1098 } |
|
1099 |
|
1100 //-------------------------------------------------- |
|
1101 |
|
1102 // |
|
1103 eap_status_e wapi_session_core_c::asynchronous_init_remove_wapi_session( |
|
1104 const eap_network_id_selector_c * const state_selector) |
|
1105 { |
|
1106 EAP_TRACE_DEBUG( |
|
1107 m_am_tools, |
|
1108 TRACE_FLAGS_DEFAULT, |
|
1109 (EAPL("wapi_session_core_c::asynchronous_init_remove_wapi_session(): %s.\n"), |
|
1110 (m_is_client == true) ? "client": "server")); |
|
1111 |
|
1112 // NOTE: we cannot call directly synchronous_remove_wapi_session(), because we will |
|
1113 // return from here to removed object. |
|
1114 |
|
1115 eap_status_e status = eap_status_process_general_error; |
|
1116 |
|
1117 EAP_TRACE_DATA_DEBUG( |
|
1118 m_am_tools, |
|
1119 TRACE_FLAGS_DEFAULT, |
|
1120 (EAPL("asynchronous_init_remove_wapi_session() WAPI session"), |
|
1121 state_selector->get_data(state_selector->get_data_length()), |
|
1122 state_selector->get_data_length())); |
|
1123 |
|
1124 wapi_core_c *session = m_session_map.get_handler(state_selector); |
|
1125 |
|
1126 if (session != 0) |
|
1127 { |
|
1128 session->set_marked_removed(); |
|
1129 |
|
1130 // So we initiate a timer to remove session identified by state_selector. |
|
1131 eap_network_id_selector_c * const copy_selector = state_selector->copy(); |
|
1132 if (copy_selector == 0 |
|
1133 || copy_selector->get_is_valid() == false) |
|
1134 { |
|
1135 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1136 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1137 } |
|
1138 |
|
1139 status = m_partner->set_timer( |
|
1140 this, |
|
1141 WAPI_SESSION_CORE_REMOVE_SESSION_ID, |
|
1142 copy_selector, |
|
1143 m_remove_session_timeout); |
|
1144 if (status != eap_status_ok) |
|
1145 { |
|
1146 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1147 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1148 } |
|
1149 |
|
1150 EAP_TRACE_DEBUG( |
|
1151 m_am_tools, |
|
1152 TRACE_FLAGS_DEFAULT, |
|
1153 (EAPL("wapi_session_core_c::asynchronous_init_remove_wapi_session()") |
|
1154 EAPL(": %s: WAPI_SESSION_CORE_REMOVE_SESSION_ID timer set %d ms.\n"), |
|
1155 (m_is_client == true) ? "client": "server", |
|
1156 m_remove_session_timeout)); |
|
1157 } |
|
1158 else |
|
1159 { |
|
1160 // Not found, cannot remove. |
|
1161 EAP_TRACE_DEBUG( |
|
1162 m_am_tools, |
|
1163 TRACE_FLAGS_DEFAULT, |
|
1164 (EAPL("ERROR: wapi_session_core_c::asynchronous_init_remove_wapi_session()") |
|
1165 EAPL(": %s: failed session not found.\n"), |
|
1166 (m_is_client == true) ? "client": "server")); |
|
1167 |
|
1168 status = eap_status_ok; |
|
1169 } |
|
1170 |
|
1171 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1172 } |
|
1173 |
|
1174 //-------------------------------------------------- |
|
1175 |
|
1176 EAP_FUNC_EXPORT void wapi_session_core_c::state_notification( |
|
1177 const abs_eap_state_notification_c * const state) |
|
1178 { |
|
1179 m_partner->state_notification(state); |
|
1180 } |
|
1181 |
|
1182 //-------------------------------------------------- |
|
1183 |
|
1184 // |
|
1185 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::set_timer( |
|
1186 abs_eap_base_timer_c * const p_initializer, |
|
1187 const u32_t p_id, |
|
1188 void * const p_data, |
|
1189 const u32_t p_time_ms) |
|
1190 { |
|
1191 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1192 |
|
1193 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
1194 |
|
1195 const eap_status_e status = m_partner->set_timer( |
|
1196 p_initializer, |
|
1197 p_id, |
|
1198 p_data, |
|
1199 p_time_ms); |
|
1200 |
|
1201 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1202 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1203 } |
|
1204 |
|
1205 //-------------------------------------------------- |
|
1206 |
|
1207 // |
|
1208 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::cancel_timer( |
|
1209 abs_eap_base_timer_c * const p_initializer, |
|
1210 const u32_t p_id) |
|
1211 { |
|
1212 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1213 |
|
1214 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
1215 |
|
1216 const eap_status_e status = m_partner->cancel_timer( |
|
1217 p_initializer, |
|
1218 p_id); |
|
1219 |
|
1220 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1221 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1222 } |
|
1223 |
|
1224 //-------------------------------------------------- |
|
1225 |
|
1226 // |
|
1227 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::cancel_all_timers() |
|
1228 { |
|
1229 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1230 |
|
1231 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
1232 |
|
1233 const eap_status_e status = m_partner->cancel_all_timers(); |
|
1234 |
|
1235 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1236 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1237 } |
|
1238 |
|
1239 //-------------------------------------------------- |
|
1240 |
|
1241 // |
|
1242 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::set_session_timeout( |
|
1243 const u32_t /* session_timeout_ms */) |
|
1244 { |
|
1245 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1246 |
|
1247 EAP_ASSERT(m_am_tools->get_global_mutex()->get_is_reserved() == true); |
|
1248 |
|
1249 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1250 return EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported); |
|
1251 } |
|
1252 |
|
1253 //-------------------------------------------------- |
|
1254 |
|
1255 // |
|
1256 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::cancel_authentication_session( |
|
1257 wapi_core_c * const handler, |
|
1258 abs_eap_am_tools_c * const m_am_tools) |
|
1259 { |
|
1260 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1261 |
|
1262 EAP_TRACE_DEBUG( |
|
1263 m_am_tools, |
|
1264 TRACE_FLAGS_DEFAULT, |
|
1265 (EAPL("wapi_session_core_c::cancel_authentication_session(): this = 0x%08x => 0x%08x.\n"), |
|
1266 handler, |
|
1267 dynamic_cast<abs_eap_base_timer_c *>(handler))); |
|
1268 |
|
1269 EAP_UNREFERENCED_PARAMETER(m_am_tools); |
|
1270 |
|
1271 eap_status_e status = handler->cancel_authentication_session(); |
|
1272 |
|
1273 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1274 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1275 } |
|
1276 |
|
1277 //-------------------------------------------------- |
|
1278 |
|
1279 // |
|
1280 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::cancel_all_authentication_sessions() |
|
1281 { |
|
1282 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1283 |
|
1284 EAP_TRACE_DEBUG( |
|
1285 m_am_tools, |
|
1286 TRACE_FLAGS_DEFAULT, |
|
1287 (EAPL("wapi_ethernet_core_c::cancel_all_authentication_sessions()\n"))); |
|
1288 |
|
1289 eap_status_e status = m_session_map.for_each(cancel_authentication_session, true); |
|
1290 |
|
1291 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1292 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1293 } |
|
1294 |
|
1295 //-------------------------------------------------- |
|
1296 |
|
1297 // |
|
1298 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::check_bksa_cache( |
|
1299 eap_array_c<eap_am_network_id_c> * const bssid_sta_receive_network_ids, |
|
1300 // **** |
|
1301 // TODO: This needs to be updated for WAPI |
|
1302 const eapol_key_authentication_type_e selected_eapol_key_authentication_type, |
|
1303 const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e pairwise_key_cipher_suite, |
|
1304 const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e group_key_cipher_suite |
|
1305 ) |
|
1306 { |
|
1307 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1308 |
|
1309 eap_status_e status = eap_status_ok; |
|
1310 |
|
1311 for (u32_t ind = 0ul; ind < bssid_sta_receive_network_ids->get_object_count();) |
|
1312 { |
|
1313 eap_am_network_id_c * const receive_network_id = bssid_sta_receive_network_ids->get_object(ind); |
|
1314 if (receive_network_id == 0) |
|
1315 { |
|
1316 bssid_sta_receive_network_ids->reset(); |
|
1317 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1318 } |
|
1319 |
|
1320 // Here we swap the addresses. |
|
1321 eap_am_network_id_c send_network_id( |
|
1322 m_am_tools, |
|
1323 receive_network_id->get_destination_id(), |
|
1324 receive_network_id->get_source_id(), |
|
1325 receive_network_id->get_type()); |
|
1326 if (send_network_id.get_is_valid_data() == false) |
|
1327 { |
|
1328 bssid_sta_receive_network_ids->reset(); |
|
1329 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1330 } |
|
1331 |
|
1332 eap_network_id_selector_c state_selector( |
|
1333 m_am_tools, |
|
1334 &send_network_id); |
|
1335 if (state_selector.get_is_valid() == false) |
|
1336 { |
|
1337 bssid_sta_receive_network_ids->reset(); |
|
1338 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1339 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1340 } |
|
1341 |
|
1342 EAP_TRACE_DATA_DEBUG( |
|
1343 m_am_tools, |
|
1344 TRACE_FLAGS_DEFAULT, |
|
1345 (EAPL("check_pmksa_cache(): checks WAPI-session"), |
|
1346 state_selector.get_data(state_selector.get_data_length()), |
|
1347 state_selector.get_data_length())); |
|
1348 |
|
1349 wapi_core_c *session = m_session_map.get_handler(&state_selector); |
|
1350 |
|
1351 if (session == 0 |
|
1352 || selected_eapol_key_authentication_type == eapol_key_authentication_type_RSNA_PSK |
|
1353 || selected_eapol_key_authentication_type == eapol_key_authentication_type_WPA_PSK |
|
1354 || session->check_bksa_cache( |
|
1355 selected_eapol_key_authentication_type, |
|
1356 pairwise_key_cipher_suite, |
|
1357 group_key_cipher_suite) != eap_status_ok) |
|
1358 { |
|
1359 // No cached PMKID for this address and security suite. |
|
1360 EAP_TRACE_DATA_DEBUG( |
|
1361 m_am_tools, |
|
1362 TRACE_FLAGS_DEFAULT, |
|
1363 (EAPL("No cached PMKID for this address"), |
|
1364 state_selector.get_data(state_selector.get_data_length()), |
|
1365 state_selector.get_data_length())); |
|
1366 |
|
1367 status = bssid_sta_receive_network_ids->remove_object(ind); |
|
1368 if (status != eap_status_ok) |
|
1369 { |
|
1370 bssid_sta_receive_network_ids->reset(); |
|
1371 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1372 } |
|
1373 |
|
1374 // Note here we do not increase index because we removed the current object. |
|
1375 } |
|
1376 else |
|
1377 { |
|
1378 // Check the next index. |
|
1379 ++ind; |
|
1380 } |
|
1381 } // for() |
|
1382 |
|
1383 if (bssid_sta_receive_network_ids->get_object_count() > 0ul) |
|
1384 { |
|
1385 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1386 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1387 } |
|
1388 else |
|
1389 { |
|
1390 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1391 return EAP_STATUS_RETURN(m_am_tools, eap_status_not_found); |
|
1392 } |
|
1393 } |
|
1394 |
|
1395 //-------------------------------------------------- |
|
1396 |
|
1397 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::association( |
|
1398 const eap_am_network_id_c * const receive_network_id, |
|
1399 // **** |
|
1400 // TODO: This needs to be updated for WAPI |
|
1401 const eapol_key_authentication_type_e authentication_type, |
|
1402 const eap_variable_data_c * const wapi_ie_ae, |
|
1403 const eap_variable_data_c * const wapi_ie_asue, |
|
1404 const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e eapol_pairwise_cipher, |
|
1405 const eapol_RSNA_key_header_c::eapol_RSNA_cipher_e eapol_group_cipher, |
|
1406 const eap_variable_data_c * const /* pre_shared_key_PSK */ |
|
1407 ) |
|
1408 { |
|
1409 eap_status_e status = eap_status_process_general_error; |
|
1410 |
|
1411 EAP_TRACE_DEBUG( |
|
1412 m_am_tools, |
|
1413 TRACE_FLAGS_DEFAULT, |
|
1414 (EAPL("%s: wapi_session_core_c::association().\n"), |
|
1415 (m_is_client == true) ? "client": "server")); |
|
1416 |
|
1417 EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_session_core_c::association()"); |
|
1418 |
|
1419 if (receive_network_id->get_type() != eapol_ethernet_type_wapi) |
|
1420 { |
|
1421 EAP_TRACE_DEBUG( |
|
1422 m_am_tools, |
|
1423 TRACE_FLAGS_DEFAULT, |
|
1424 (EAPL("WARNING: wapi_session_core_c::association(): Illegal Ethernet type %d\n"), |
|
1425 receive_network_id->get_type())); |
|
1426 |
|
1427 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1428 return EAP_STATUS_RETURN(m_am_tools, eap_status_ethernet_type_not_supported); |
|
1429 } |
|
1430 |
|
1431 // Here we swap the addresses. |
|
1432 eap_am_network_id_c send_network_id( |
|
1433 m_am_tools, |
|
1434 receive_network_id->get_destination_id(), |
|
1435 receive_network_id->get_source_id(), |
|
1436 receive_network_id->get_type()); |
|
1437 if (send_network_id.get_is_valid_data() == false) |
|
1438 { |
|
1439 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1440 } |
|
1441 |
|
1442 eap_network_id_selector_c state_selector( |
|
1443 m_am_tools, |
|
1444 &send_network_id); |
|
1445 |
|
1446 if (state_selector.get_is_valid() == false) |
|
1447 { |
|
1448 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1449 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1450 } |
|
1451 |
|
1452 EAP_TRACE_DATA_DEBUG( |
|
1453 m_am_tools, |
|
1454 TRACE_FLAGS_DEFAULT, |
|
1455 (EAPL("association(): WAPI-session"), |
|
1456 state_selector.get_data(state_selector.get_data_length()), |
|
1457 state_selector.get_data_length())); |
|
1458 |
|
1459 |
|
1460 wapi_core_c *session = m_session_map.get_handler(&state_selector); |
|
1461 |
|
1462 if (session != 0) |
|
1463 { |
|
1464 // Reuse the session. |
|
1465 session->unset_marked_removed(); |
|
1466 |
|
1467 if (m_is_client == false) |
|
1468 { |
|
1469 // In test version do not reset server. |
|
1470 } |
|
1471 else |
|
1472 { |
|
1473 status = session->reset(); |
|
1474 if (status != eap_status_ok) |
|
1475 { |
|
1476 // We cannot reuse the session. |
|
1477 EAP_TRACE_ERROR( |
|
1478 m_am_tools, |
|
1479 TRACE_FLAGS_ERROR, |
|
1480 (EAPL("wapi_session_core_c::association(): session NOT reused.\n"))); |
|
1481 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1482 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1483 } |
|
1484 } |
|
1485 } |
|
1486 |
|
1487 if (session == 0) |
|
1488 { |
|
1489 session = new wapi_core_c( |
|
1490 m_am_tools, |
|
1491 this, |
|
1492 m_is_client, |
|
1493 receive_network_id); |
|
1494 if (session == 0 |
|
1495 || session->get_is_valid() == false) |
|
1496 { |
|
1497 if (session != 0) |
|
1498 { |
|
1499 session->shutdown(); |
|
1500 } |
|
1501 else |
|
1502 { |
|
1503 EAP_TRACE_DEBUG( |
|
1504 m_am_tools, |
|
1505 TRACE_FLAGS_DEFAULT, |
|
1506 (EAPL("WARNING: wapi_session_core_c::association(): Cannot run session->shutdown() 0x%08x\n"), |
|
1507 session)); |
|
1508 } |
|
1509 delete session; |
|
1510 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1511 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1512 } |
|
1513 |
|
1514 status = session->configure(); |
|
1515 if (status != eap_status_ok) |
|
1516 { |
|
1517 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1518 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1519 } |
|
1520 |
|
1521 status = session->initialize( |
|
1522 receive_network_id, |
|
1523 authentication_type, |
|
1524 wapi_ie_ae, |
|
1525 wapi_ie_asue, |
|
1526 eapol_pairwise_cipher, |
|
1527 eapol_group_cipher); |
|
1528 if (status != eap_status_ok) |
|
1529 { |
|
1530 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1531 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1532 } |
|
1533 |
|
1534 status = m_session_map.add_handler(&state_selector, session); |
|
1535 if (status != eap_status_ok) |
|
1536 { |
|
1537 if (session != 0) |
|
1538 { |
|
1539 session->shutdown(); |
|
1540 } |
|
1541 else |
|
1542 { |
|
1543 EAP_TRACE_DEBUG( |
|
1544 m_am_tools, |
|
1545 TRACE_FLAGS_DEFAULT, |
|
1546 (EAPL("WARNING: wapi_session_core_c::association(): Cannot run session->shutdown() 0x%08x\n"), |
|
1547 session)); |
|
1548 } |
|
1549 delete session; |
|
1550 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1551 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1552 } |
|
1553 |
|
1554 } |
|
1555 else |
|
1556 { |
|
1557 status = session->initialize( |
|
1558 receive_network_id, |
|
1559 authentication_type, |
|
1560 wapi_ie_ae, |
|
1561 wapi_ie_asue, |
|
1562 eapol_pairwise_cipher, |
|
1563 eapol_group_cipher); |
|
1564 if (status != eap_status_ok) |
|
1565 { |
|
1566 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1567 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1568 } |
|
1569 } |
|
1570 |
|
1571 |
|
1572 #if 0 |
|
1573 #if defined(USE_WAPI_CORE_SERVER) |
|
1574 if (m_is_client == false) |
|
1575 { |
|
1576 status = session->start_authentication(); |
|
1577 if (status != eap_status_ok) |
|
1578 { |
|
1579 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1580 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1581 } |
|
1582 } |
|
1583 else |
|
1584 #endif //#if defined(USE_WAPI_CORE_SERVER) |
|
1585 #endif |
|
1586 if (m_is_client == true) |
|
1587 { |
|
1588 status = session->allow_authentication(); |
|
1589 if (status != eap_status_ok) |
|
1590 { |
|
1591 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1592 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1593 } |
|
1594 } |
|
1595 |
|
1596 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1597 } |
|
1598 |
|
1599 //-------------------------------------------------- |
|
1600 |
|
1601 // |
|
1602 eap_status_e wapi_session_core_c::init_eapol_key_bksa_caching_timeout( |
|
1603 const eap_am_network_id_c * const send_network_id) |
|
1604 { |
|
1605 EAP_TRACE_DEBUG( |
|
1606 m_am_tools, |
|
1607 TRACE_FLAGS_DEFAULT, |
|
1608 (EAPL("%s: wapi_session_core_c::init_eapol_key_pmksa_caching_timeout().\n"), |
|
1609 (m_is_client == true) ? "client": "server")); |
|
1610 |
|
1611 EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_session_core_c::init_eapol_key_bksa_caching_timeout()"); |
|
1612 |
|
1613 // Initialize BKSA caching timeout of WAPI-session. |
|
1614 eap_network_id_selector_c state_selector( |
|
1615 m_am_tools, |
|
1616 send_network_id); |
|
1617 |
|
1618 if (state_selector.get_is_valid() == false) |
|
1619 { |
|
1620 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1621 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1622 } |
|
1623 |
|
1624 EAP_TRACE_DATA_DEBUG( |
|
1625 m_am_tools, |
|
1626 TRACE_FLAGS_DEFAULT, |
|
1627 (EAPL("init_eapol_key_bksa_caching_timeout(): WAPI session"), |
|
1628 state_selector.get_data(state_selector.get_data_length()), |
|
1629 state_selector.get_data_length())); |
|
1630 |
|
1631 wapi_core_c *session = m_session_map.get_handler(&state_selector); |
|
1632 |
|
1633 if (session == 0) |
|
1634 { |
|
1635 EAP_TRACE_DEBUG( |
|
1636 m_am_tools, |
|
1637 TRACE_FLAGS_DEFAULT, |
|
1638 (EAPL("session not found.\n"), |
|
1639 (m_is_client == true) ? "client": "server")); |
|
1640 |
|
1641 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1642 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
1643 } |
|
1644 |
|
1645 eap_status_e status = session->init_bksa_caching_timeout(); |
|
1646 if (status != eap_status_ok) |
|
1647 { |
|
1648 EAP_TRACE_DEBUG( |
|
1649 m_am_tools, |
|
1650 TRACE_FLAGS_DEFAULT, |
|
1651 (EAPL("WARNING: wapi_session_core_c::init_eapol_key_bksa_caching_timeout(): ") |
|
1652 EAPL("session->init_pmksa_caching_timeout(), eap_status_e %d\n"), |
|
1653 status)); |
|
1654 } |
|
1655 |
|
1656 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1657 } |
|
1658 |
|
1659 //-------------------------------------------------- |
|
1660 |
|
1661 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::disassociation( |
|
1662 const eap_am_network_id_c * const receive_network_id |
|
1663 ) |
|
1664 { |
|
1665 eap_status_e status = eap_status_process_general_error; |
|
1666 |
|
1667 EAP_TRACE_DEBUG( |
|
1668 m_am_tools, |
|
1669 TRACE_FLAGS_DEFAULT, |
|
1670 (EAPL("%s: wapi_session_core_c::disassociation().\n"), |
|
1671 (m_is_client == true) ? "client": "server")); |
|
1672 |
|
1673 EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_session_core_c::disassociation()"); |
|
1674 |
|
1675 if (receive_network_id == 0) |
|
1676 { |
|
1677 return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter); |
|
1678 } |
|
1679 |
|
1680 // Here we swap the addresses. |
|
1681 eap_am_network_id_c send_network_id( |
|
1682 m_am_tools, |
|
1683 receive_network_id->get_destination_id(), |
|
1684 receive_network_id->get_source_id(), |
|
1685 receive_network_id->get_type()); |
|
1686 if (send_network_id.get_is_valid_data() == false) |
|
1687 { |
|
1688 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1689 } |
|
1690 |
|
1691 status = init_eapol_key_bksa_caching_timeout( |
|
1692 &send_network_id); |
|
1693 if (status != eap_status_ok) |
|
1694 { |
|
1695 EAP_TRACE_DEBUG( |
|
1696 m_am_tools, |
|
1697 TRACE_FLAGS_DEFAULT, |
|
1698 (EAPL("WARNING: wapi_session_core_c::disassociation(): ") |
|
1699 EAPL("init_eapol_key_pmksa_caching_timeout(), eap_status_e %d\n"), |
|
1700 status)); |
|
1701 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1702 } |
|
1703 |
|
1704 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1705 } |
|
1706 |
|
1707 //-------------------------------------------------- |
|
1708 |
|
1709 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::create_state( |
|
1710 const eap_am_network_id_c * const receive_network_id, |
|
1711 // **** |
|
1712 // TODO: This needs to be updated for WAPI |
|
1713 const eapol_key_authentication_type_e authentication_type |
|
1714 ) |
|
1715 { |
|
1716 eap_status_e status = eap_status_process_general_error; |
|
1717 |
|
1718 EAP_TRACE_DEBUG( |
|
1719 m_am_tools, |
|
1720 TRACE_FLAGS_DEFAULT, |
|
1721 (EAPL("%s: eapol_core_c::create_state().\n"), |
|
1722 (m_is_client == true) ? "client": "server")); |
|
1723 |
|
1724 EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_session_core_c::create_state()"); |
|
1725 |
|
1726 if (receive_network_id->get_type() != eapol_ethernet_type_wapi) |
|
1727 { |
|
1728 EAP_TRACE_DEBUG( |
|
1729 m_am_tools, |
|
1730 TRACE_FLAGS_DEFAULT, |
|
1731 (EAPL("WARNING: eapol_core_c::create_state(): Illegal Ethernet type %d\n"), |
|
1732 receive_network_id->get_type())); |
|
1733 |
|
1734 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1735 return EAP_STATUS_RETURN(m_am_tools, eap_status_ethernet_type_not_supported); |
|
1736 } |
|
1737 |
|
1738 // Here we swap the addresses. |
|
1739 eap_am_network_id_c send_network_id( |
|
1740 m_am_tools, |
|
1741 receive_network_id->get_destination_id(), |
|
1742 receive_network_id->get_source_id(), |
|
1743 receive_network_id->get_type()); |
|
1744 if (send_network_id.get_is_valid_data() == false) |
|
1745 { |
|
1746 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1747 } |
|
1748 |
|
1749 eap_network_id_selector_c state_selector( |
|
1750 m_am_tools, |
|
1751 &send_network_id); |
|
1752 |
|
1753 if (state_selector.get_is_valid() == false) |
|
1754 { |
|
1755 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1756 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1757 } |
|
1758 |
|
1759 EAP_TRACE_DATA_DEBUG( |
|
1760 m_am_tools, |
|
1761 TRACE_FLAGS_DEFAULT, |
|
1762 (EAPL("wapi_session_core_c::create_state(): WAPI-session"), |
|
1763 state_selector.get_data(state_selector.get_data_length()), |
|
1764 state_selector.get_data_length())); |
|
1765 |
|
1766 |
|
1767 wapi_core_c *session = m_session_map.get_handler(&state_selector); |
|
1768 |
|
1769 if (session != 0) |
|
1770 { |
|
1771 // Reuse the session. |
|
1772 session->unset_marked_removed(); |
|
1773 |
|
1774 if (m_is_client == false) |
|
1775 { |
|
1776 // In test version do not reset server. |
|
1777 } |
|
1778 else |
|
1779 { |
|
1780 status = session->reset(); |
|
1781 if (status != eap_status_ok) |
|
1782 { |
|
1783 // We cannot reuse the session. |
|
1784 EAP_TRACE_ERROR( |
|
1785 m_am_tools, |
|
1786 TRACE_FLAGS_ERROR, |
|
1787 (EAPL("wapi_session_core_c::create_state(): session NOT reused.\n"))); |
|
1788 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1789 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1790 } |
|
1791 } |
|
1792 } |
|
1793 |
|
1794 |
|
1795 if (session == 0) |
|
1796 { |
|
1797 session = new wapi_core_c( |
|
1798 m_am_tools, |
|
1799 this, |
|
1800 m_is_client, |
|
1801 receive_network_id); |
|
1802 if (session == 0 |
|
1803 || session->get_is_valid() == false) |
|
1804 { |
|
1805 if (session != 0) |
|
1806 { |
|
1807 session->shutdown(); |
|
1808 } |
|
1809 else |
|
1810 { |
|
1811 EAP_TRACE_DEBUG( |
|
1812 m_am_tools, |
|
1813 TRACE_FLAGS_DEFAULT, |
|
1814 (EAPL("WARNING: wapi_session_core_c::create_state(): Cannot run session->shutdown() 0x%08x\n"), |
|
1815 session)); |
|
1816 } |
|
1817 delete session; |
|
1818 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1819 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1820 } |
|
1821 |
|
1822 status = session->initialize( |
|
1823 receive_network_id, |
|
1824 authentication_type); |
|
1825 if (status != eap_status_ok) |
|
1826 { |
|
1827 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1828 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1829 } |
|
1830 |
|
1831 status = m_session_map.add_handler(&state_selector, session); |
|
1832 if (status != eap_status_ok) |
|
1833 { |
|
1834 if (session != 0) |
|
1835 { |
|
1836 session->shutdown(); |
|
1837 } |
|
1838 else |
|
1839 { |
|
1840 EAP_TRACE_DEBUG( |
|
1841 m_am_tools, |
|
1842 TRACE_FLAGS_DEFAULT, |
|
1843 (EAPL("WARNING: wapi_session_core_c::create_state(): Cannot run session->shutdown() 0x%08x\n"), |
|
1844 session)); |
|
1845 } |
|
1846 delete session; |
|
1847 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1848 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1849 } |
|
1850 } |
|
1851 else |
|
1852 { |
|
1853 status = session->initialize( |
|
1854 receive_network_id, |
|
1855 authentication_type); |
|
1856 if (status != eap_status_ok) |
|
1857 { |
|
1858 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1859 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1860 } |
|
1861 } |
|
1862 |
|
1863 status = session->configure(); |
|
1864 if (status != eap_status_ok) |
|
1865 { |
|
1866 status = remove_wapi_state( |
|
1867 &send_network_id); |
|
1868 if (status != eap_status_ok) |
|
1869 { |
|
1870 EAP_TRACE_DEBUG( |
|
1871 m_am_tools, |
|
1872 TRACE_FLAGS_DEFAULT, |
|
1873 (EAPL("WARNING: wapi_session_core_c::create_state(): ") |
|
1874 EAPL("remove_eapol_key_state(), eap_status_e %d\n"), |
|
1875 status)); |
|
1876 } |
|
1877 |
|
1878 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1879 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1880 } |
|
1881 |
|
1882 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1883 } |
|
1884 |
|
1885 //-------------------------------------------------- |
|
1886 |
|
1887 // |
|
1888 eap_status_e wapi_session_core_c::remove_wapi_state( |
|
1889 const eap_am_network_id_c * const send_network_id) |
|
1890 { |
|
1891 EAP_TRACE_DEBUG( |
|
1892 m_am_tools, |
|
1893 TRACE_FLAGS_DEFAULT, |
|
1894 (EAPL("%s: wapi_session_core_c::remove_wapi_state().\n"), |
|
1895 (m_is_client == true) ? "client": "server")); |
|
1896 |
|
1897 EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_session_core_c::remove_wapi_state()"); |
|
1898 |
|
1899 // Remove possible WAPI state. |
|
1900 eap_network_id_selector_c state_selector( |
|
1901 m_am_tools, |
|
1902 send_network_id); |
|
1903 |
|
1904 if (state_selector.get_is_valid() == false) |
|
1905 { |
|
1906 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1907 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1908 } |
|
1909 |
|
1910 EAP_TRACE_DATA_DEBUG( |
|
1911 m_am_tools, |
|
1912 TRACE_FLAGS_DEFAULT, |
|
1913 (EAPL("remove_eapol_key_state(): WAPI-session"), |
|
1914 state_selector.get_data(state_selector.get_data_length()), |
|
1915 state_selector.get_data_length())); |
|
1916 |
|
1917 wapi_core_c * const session = m_session_map.get_handler(&state_selector); |
|
1918 |
|
1919 if (session != 0) |
|
1920 { |
|
1921 if (session->get_marked_removed() == false) |
|
1922 { |
|
1923 // Do not remove object in use. |
|
1924 EAP_TRACE_DEBUG( |
|
1925 m_am_tools, |
|
1926 TRACE_FLAGS_DEFAULT, |
|
1927 (EAPL("WARNING: wapi_session_core_c::remove_eapol_key_state(): Cannot removed used object 0x%08x\n"), |
|
1928 session)); |
|
1929 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
1930 } |
|
1931 |
|
1932 session->shutdown(); |
|
1933 } |
|
1934 else |
|
1935 { |
|
1936 EAP_TRACE_DEBUG( |
|
1937 m_am_tools, |
|
1938 TRACE_FLAGS_DEFAULT, |
|
1939 (EAPL("WARNING: wapi_session_core_c::remove_eapol_key_state(): Cannot run session->shutdown() 0x%08x\n"), |
|
1940 session)); |
|
1941 } |
|
1942 |
|
1943 eap_status_e status = m_session_map.remove_handler(&state_selector, true); |
|
1944 if (status != eap_status_ok) |
|
1945 { |
|
1946 EAP_TRACE_DEBUG( |
|
1947 m_am_tools, |
|
1948 TRACE_FLAGS_DEFAULT, |
|
1949 (EAPL("WARNING: wapi_session_core_c::remove_eapol_key_state(): ") |
|
1950 EAPL("session->remove_handler(), eap_status_e %d\n"), |
|
1951 status)); |
|
1952 } |
|
1953 |
|
1954 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1955 } |
|
1956 |
|
1957 //-------------------------------------------------- |
|
1958 |
|
1959 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::remove_bksa_from_cache( |
|
1960 const eap_am_network_id_c * const receive_network_id) |
|
1961 { |
|
1962 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1963 |
|
1964 eap_status_e status = eap_status_process_general_error; |
|
1965 |
|
1966 EAP_TRACE_DEBUG( |
|
1967 m_am_tools, |
|
1968 TRACE_FLAGS_DEFAULT, |
|
1969 (EAPL("%s: wapi_session_core_c::remove_bksa_from_cache().\n"), |
|
1970 (m_is_client == true) ? "client": "server")); |
|
1971 |
|
1972 EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_session_core_c::remove_bksa_from_cache()"); |
|
1973 |
|
1974 if (receive_network_id == 0) |
|
1975 { |
|
1976 return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter); |
|
1977 } |
|
1978 |
|
1979 // Here we swap the addresses. |
|
1980 eap_am_network_id_c send_network_id( |
|
1981 m_am_tools, |
|
1982 receive_network_id->get_destination_id(), |
|
1983 receive_network_id->get_source_id(), |
|
1984 receive_network_id->get_type()); |
|
1985 if (send_network_id.get_is_valid_data() == false) |
|
1986 { |
|
1987 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
1988 } |
|
1989 |
|
1990 status = remove_wapi_state( |
|
1991 &send_network_id); |
|
1992 if (status != eap_status_ok) |
|
1993 { |
|
1994 EAP_TRACE_DEBUG( |
|
1995 m_am_tools, |
|
1996 TRACE_FLAGS_DEFAULT, |
|
1997 (EAPL("WARNING: ewapi_session_core_c::remove_bksa_from_cache(): ") |
|
1998 EAPL("remove_eapol_key_state(), eap_status_e %d\n"), |
|
1999 status)); |
|
2000 return EAP_STATUS_RETURN(m_am_tools, status); |
|
2001 } |
|
2002 |
|
2003 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2004 return EAP_STATUS_RETURN(m_am_tools, status); |
|
2005 } |
|
2006 |
|
2007 //-------------------------------------------------- |
|
2008 |
|
2009 EAP_FUNC_EXPORT eap_status_e wapi_session_core_c::read_reassociation_parameters( |
|
2010 const eap_am_network_id_c * const old_receive_network_id, ///< source includes remote address, destination includes local address. |
|
2011 const eap_am_network_id_c * const new_receive_network_id, ///< source includes remote address, destination includes local address. |
|
2012 const eapol_key_authentication_type_e authentication_type, |
|
2013 eap_variable_data_c * const BKID, |
|
2014 const eap_variable_data_c * const received_WAPI_ie, |
|
2015 const eap_variable_data_c * const sent_WAPI_ie) |
|
2016 { |
|
2017 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2018 |
|
2019 EAP_TRACE_DEBUG( |
|
2020 m_am_tools, |
|
2021 TRACE_FLAGS_DEFAULT, |
|
2022 (EAPL("%s: wapi_session_core_c::read_reassociation_parameters()\n"), |
|
2023 (m_is_client == true) ? "client": "server")); |
|
2024 |
|
2025 EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_session_core_c::read_reassociation_parameters()"); |
|
2026 |
|
2027 eap_status_e status(eap_status_process_general_error); |
|
2028 |
|
2029 // No need to check authentication type anymore. It can be changed in reassociation. |
|
2030 |
|
2031 // Here we swap the addresses. |
|
2032 eap_am_network_id_c new_send_network_id( |
|
2033 m_am_tools, |
|
2034 new_receive_network_id->get_destination_id(), |
|
2035 new_receive_network_id->get_source_id(), |
|
2036 new_receive_network_id->get_type()); |
|
2037 if (new_send_network_id.get_is_valid_data() == false) |
|
2038 { |
|
2039 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
2040 } |
|
2041 |
|
2042 eap_network_id_selector_c state_selector( |
|
2043 m_am_tools, |
|
2044 &new_send_network_id); |
|
2045 |
|
2046 if (state_selector.get_is_valid() == false) |
|
2047 { |
|
2048 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2049 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
2050 } |
|
2051 |
|
2052 EAP_TRACE_DATA_DEBUG( |
|
2053 m_am_tools, |
|
2054 TRACE_FLAGS_DEFAULT, |
|
2055 (EAPL("read_reassociation_parameters(): WAPI-session"), |
|
2056 state_selector.get_data(state_selector.get_data_length()), |
|
2057 state_selector.get_data_length())); |
|
2058 |
|
2059 wapi_core_c * const session = m_session_map.get_handler(&state_selector); |
|
2060 |
|
2061 if (session != 0) |
|
2062 { |
|
2063 status = session->reset_cached_bksa(); |
|
2064 if (status != eap_status_ok) |
|
2065 { |
|
2066 // We cannot reuse the session. |
|
2067 EAP_TRACE_ERROR( |
|
2068 m_am_tools, |
|
2069 TRACE_FLAGS_ERROR, |
|
2070 (EAPL("wapi_session_core_c::read_reassociation_parameters(): session NOT reused.\n"))); |
|
2071 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2072 return EAP_STATUS_RETURN(m_am_tools, status); |
|
2073 } |
|
2074 |
|
2075 // We have state for this connection. |
|
2076 status = session->read_reassociation_parameters( |
|
2077 new_receive_network_id, ///< source includes remote address, destination includes local address. |
|
2078 authentication_type, |
|
2079 BKID, |
|
2080 received_WAPI_ie, |
|
2081 sent_WAPI_ie); |
|
2082 if (status != eap_status_ok) |
|
2083 { |
|
2084 // ERROR, Cannot reassociate. |
|
2085 |
|
2086 EAP_TRACE_DEBUG( |
|
2087 m_am_tools, |
|
2088 TRACE_FLAGS_DEFAULT, |
|
2089 (EAPL("ERROR: wapi_session_core_c::read_reassociation_parameters(): Cannot reassociate.\n"))); |
|
2090 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2091 return EAP_STATUS_RETURN(m_am_tools, status); |
|
2092 } |
|
2093 } |
|
2094 else |
|
2095 { |
|
2096 status = eap_status_not_found; |
|
2097 } |
|
2098 |
|
2099 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2100 return EAP_STATUS_RETURN(m_am_tools, status); |
|
2101 } |
|
2102 |
|
2103 //-------------------------------------------------- |
|
2104 |
|
2105 // End. |
|