|
1 /* |
|
2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: EAP and WLAN authentication protocols. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // This is enumeration of EAPOL source code. |
|
20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
21 #undef EAP_FILE_NUMBER_ENUM |
|
22 #define EAP_FILE_NUMBER_ENUM 148 |
|
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 |
|
30 #include "eap_am_memory.h" |
|
31 |
|
32 #include "eap_variable_data.h" |
|
33 #include "eap_tools.h" |
|
34 #include "eap_type_all.h" |
|
35 |
|
36 #include "eapol_am_core_symbian.h" |
|
37 #include "eapol_ethernet_header.h" |
|
38 #include "ethernet_core.h" |
|
39 #include "eap_am_tools_symbian.h" |
|
40 #include <EapolToWlmIf.h> |
|
41 #include "EapolDbDefaults.h" |
|
42 #include "EapolDbParameterNames.h" |
|
43 #include "eap_crypto_api.h" |
|
44 #include "eap_header_string.h" |
|
45 #include "eap_am_file_input_symbian.h" |
|
46 #include "eap_rogue_ap_entry.h" |
|
47 #include "abs_eap_state_notification.h" |
|
48 #include "eapol_session_key.h" |
|
49 #include "eap_buffer.h" |
|
50 #include "eap_config.h" |
|
51 |
|
52 #if defined(USE_EAP_FILECONFIG) |
|
53 #include "eap_file_config.h" |
|
54 #endif //#if defined(USE_EAP_FILECONFIG) |
|
55 |
|
56 #if defined (USE_EAPOL_KEY_STATE) |
|
57 #include "eapol_key_state.h" |
|
58 #endif |
|
59 |
|
60 // LOCAL CONSTANTS |
|
61 const TUint KMaxSqlQueryLength = 2048; |
|
62 const TUint KMaxConfigStringLength = 256; |
|
63 const u32_t KMTU = 1500u; |
|
64 const u32_t KTrailerLength = 0; |
|
65 const u32_t KHeaderOffset = 0; |
|
66 const TUint KMaxEapCueLength = 3; |
|
67 |
|
68 enum eapol_am_core_timer_id_e |
|
69 { |
|
70 EAPOL_AM_CORE_TIMER_RESTART_AUTHENTICATION_ID, |
|
71 EAPOL_AM_CORE_TIMER_DELETE_STACK_ID, |
|
72 EAPOL_AM_CORE_TIMER_FAILED_COMPLETELY_ID, |
|
73 }; |
|
74 |
|
75 |
|
76 const TUint8 TEST_RSN_IE[] = |
|
77 { |
|
78 0xdd, // information element id, 221 expressed as Hex value |
|
79 0x14, // length in octets, 20 expressed as Hex value |
|
80 0x01, 0x00, // Version 1 |
|
81 0x00, 0x0f, 0xac, 0x04, // CCMP as group key cipher suite |
|
82 0x01, 0x00, // pairwise key cipher suite count |
|
83 0x00, 0x0f, 0xac, 0x04, // CCMP as pairwise key cipher suite |
|
84 0x01, 0x00, // authentication count |
|
85 0x00, 0x0f, 0xac, 0x01, // 802.1X authentication |
|
86 0x01, 0x00, // Pre-authentication capabilities |
|
87 }; |
|
88 |
|
89 // ================= MEMBER FUNCTIONS ======================= |
|
90 |
|
91 eapol_am_core_symbian_c::eapol_am_core_symbian_c(MEapolToWlmIf * const aPartner, |
|
92 const bool is_client_when_true, |
|
93 const TUint aServerIndex) |
|
94 : CActive(CActive::EPriorityStandard) |
|
95 , m_partner(aPartner) |
|
96 , m_ethernet_core(0) |
|
97 , m_am_tools(0) |
|
98 , m_enable_random_errors(false) |
|
99 , m_error_probability(0u) |
|
100 , m_generate_multiple_error_packets(0u) |
|
101 , m_authentication_counter(0u) |
|
102 , m_successful_authentications(0u) |
|
103 , m_failed_authentications(0u) |
|
104 , m_is_valid(false) |
|
105 , m_is_client(is_client_when_true) |
|
106 , m_eap_index(0u) |
|
107 , m_index_type(ELan) |
|
108 , m_index(aServerIndex) |
|
109 //, m_timer(0) |
|
110 , m_packet_index(0) |
|
111 , m_manipulate_ethernet_header(false) |
|
112 , m_send_original_packet_first(false) |
|
113 , m_authentication_indication_sent(false) |
|
114 , m_unicast_wep_key_received(false) |
|
115 , m_broadcast_wep_key_received(false) |
|
116 , m_block_packet_sends_and_notifications(false) |
|
117 , m_success_indication_sent(false) |
|
118 , m_first_authentication(true) |
|
119 , m_self_disassociated(false) |
|
120 , m_802_11_authentication_mode(EAuthModeOpen) |
|
121 , m_receive_network_id(0) |
|
122 , m_wpa_override_enabled(false) |
|
123 , m_wpa_psk_mode_allowed(false) |
|
124 , m_wpa_psk_mode_active(false) |
|
125 , m_stack_marked_to_be_deleted(false) |
|
126 , m_active_type_is_leap(false) |
|
127 , m_fileconfig(0) |
|
128 { |
|
129 } |
|
130 |
|
131 //-------------------------------------------------- |
|
132 |
|
133 void eapol_am_core_symbian_c::ConstructL() |
|
134 { |
|
135 if (m_partner == 0) |
|
136 { |
|
137 User::Leave(KErrGeneral); |
|
138 } |
|
139 |
|
140 // Create tools class |
|
141 m_am_tools = new(ELeave) eap_am_tools_symbian_c(EAP_DEFAULT_TRACE_FILE); |
|
142 if (m_am_tools->get_is_valid() != true) |
|
143 { |
|
144 // The real reason most likely is KErrNoMemory but since that is not sure we'll use KErrGeneral |
|
145 User::Leave(KErrGeneral); |
|
146 } |
|
147 if (m_am_tools->configure() != eap_status_ok) |
|
148 { |
|
149 User::Leave(KErrGeneral); |
|
150 } |
|
151 |
|
152 |
|
153 EAP_TRACE_DEBUG( |
|
154 m_am_tools, |
|
155 TRACE_FLAGS_DEFAULT, |
|
156 (EAPL("EAPOL INITIALISATION\n"))); |
|
157 EAP_TRACE_DEBUG( |
|
158 m_am_tools, |
|
159 TRACE_FLAGS_DEFAULT, |
|
160 (EAPL("====================\n"))); |
|
161 |
|
162 m_wpa_preshared_key = new (ELeave) eap_variable_data_c(m_am_tools); |
|
163 |
|
164 m_ssid = new (ELeave) eap_variable_data_c(m_am_tools); |
|
165 |
|
166 m_wpa_psk_password_override = new (ELeave) eap_variable_data_c(m_am_tools); |
|
167 |
|
168 // Create/initialise the database |
|
169 OpenDatabaseL(m_database, m_session); |
|
170 |
|
171 EAP_TRACE_DEBUG( |
|
172 m_am_tools, |
|
173 TRACE_FLAGS_DEFAULT, |
|
174 (EAPL("Database initialized...\n"))); |
|
175 |
|
176 #if defined(USE_EAP_FILECONFIG) |
|
177 |
|
178 { |
|
179 EAP_TRACE_DEBUG( |
|
180 m_am_tools, |
|
181 TRACE_FLAGS_DEFAULT, |
|
182 (EAPL("Initialize file configuration.\n"))); |
|
183 eap_am_file_input_symbian_c fileio(m_am_tools); |
|
184 |
|
185 eap_variable_data_c file_name_c_data(m_am_tools); |
|
186 |
|
187 eap_status_e status(eap_status_process_general_error); |
|
188 |
|
189 { |
|
190 eap_const_string const FILECONFIG_FILENAME_C |
|
191 = "c:\\system\\data\\eap.conf"; |
|
192 |
|
193 status = file_name_c_data.set_copy_of_buffer( |
|
194 FILECONFIG_FILENAME_C, |
|
195 m_am_tools->strlen(FILECONFIG_FILENAME_C)); |
|
196 if (status != eap_status_ok) |
|
197 { |
|
198 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
199 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
200 } |
|
201 |
|
202 status = file_name_c_data.add_end_null(); |
|
203 if (status != eap_status_ok) |
|
204 { |
|
205 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
206 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
207 } |
|
208 } |
|
209 |
|
210 eap_variable_data_c file_name_z_data(m_am_tools); |
|
211 |
|
212 { |
|
213 eap_const_string const FILECONFIG_FILENAME_Z |
|
214 = "z:\\private\\101F8EC5\\eap.conf"; |
|
215 |
|
216 status = file_name_z_data.set_copy_of_buffer( |
|
217 FILECONFIG_FILENAME_Z, |
|
218 m_am_tools->strlen(FILECONFIG_FILENAME_Z)); |
|
219 if (status != eap_status_ok) |
|
220 { |
|
221 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
222 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
223 } |
|
224 |
|
225 status = file_name_z_data.add_end_null(); |
|
226 if (status != eap_status_ok) |
|
227 { |
|
228 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
229 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
230 } |
|
231 } |
|
232 |
|
233 if (status == eap_status_ok) |
|
234 { |
|
235 // First try open from C: disk. |
|
236 status = fileio.file_open( |
|
237 &file_name_c_data, |
|
238 eap_file_io_direction_read); |
|
239 if (status == eap_status_ok) |
|
240 { |
|
241 EAP_TRACE_DEBUG( |
|
242 m_am_tools, |
|
243 TRACE_FLAGS_DEFAULT, |
|
244 (EAPL("Opens configure file %s\n"), |
|
245 file_name_c_data.get_data(file_name_c_data.get_data_length()))); |
|
246 } |
|
247 else if (status != eap_status_ok) |
|
248 { |
|
249 // Second try open from Z: disk. |
|
250 status = fileio.file_open( |
|
251 &file_name_z_data, |
|
252 eap_file_io_direction_read); |
|
253 if (status == eap_status_ok) |
|
254 { |
|
255 EAP_TRACE_DEBUG( |
|
256 m_am_tools, |
|
257 TRACE_FLAGS_DEFAULT, |
|
258 (EAPL("Opens configure file %s\n"), |
|
259 file_name_z_data.get_data(file_name_z_data.get_data_length()))); |
|
260 } |
|
261 } |
|
262 |
|
263 if (status == eap_status_ok) |
|
264 { |
|
265 // Some of the files were opened. |
|
266 |
|
267 m_fileconfig = new eap_file_config_c(m_am_tools); |
|
268 if (m_fileconfig != 0 |
|
269 && m_fileconfig->get_is_valid() == true) |
|
270 { |
|
271 status = m_fileconfig->configure(&fileio); |
|
272 if (status != eap_status_ok) |
|
273 { |
|
274 EAP_TRACE_DEBUG( |
|
275 m_am_tools, |
|
276 TRACE_FLAGS_DEFAULT, |
|
277 (EAPL("ERROR: Configure read from %s failed.\n"), |
|
278 file_name_c_data.get_data(file_name_c_data.get_data_length()))); |
|
279 } |
|
280 else |
|
281 { |
|
282 EAP_TRACE_DEBUG( |
|
283 m_am_tools, |
|
284 TRACE_FLAGS_DEFAULT, |
|
285 (EAPL("Configure read from %s\n"), |
|
286 file_name_c_data.get_data(file_name_c_data.get_data_length()))); |
|
287 } |
|
288 } |
|
289 else |
|
290 { |
|
291 // No file configuration. |
|
292 delete m_fileconfig; |
|
293 m_fileconfig = 0; |
|
294 |
|
295 EAP_TRACE_DEBUG( |
|
296 m_am_tools, |
|
297 TRACE_FLAGS_DEFAULT, |
|
298 (EAPL("ERROR: Cannot create configure object for file %s\n"), |
|
299 file_name_c_data.get_data(file_name_c_data.get_data_length()))); |
|
300 } |
|
301 } |
|
302 else |
|
303 { |
|
304 EAP_TRACE_DEBUG( |
|
305 m_am_tools, |
|
306 TRACE_FLAGS_DEFAULT, |
|
307 (EAPL("ERROR: Cannot open configure file neither %s nor %s\n"), |
|
308 file_name_c_data.get_data(file_name_c_data.get_data_length()), |
|
309 file_name_z_data.get_data(file_name_z_data.get_data_length()))); |
|
310 } |
|
311 } |
|
312 } |
|
313 |
|
314 #endif //#if defined(USE_EAP_FILECONFIG) |
|
315 |
|
316 #if !defined(USE_EAP_HARDWARE_TRACE) |
|
317 { |
|
318 // Disable traces. |
|
319 m_am_tools->set_trace_mask(eap_am_tools_c::eap_trace_mask_none); |
|
320 |
|
321 eap_variable_data_c trace_output_file(m_am_tools); |
|
322 |
|
323 eap_status_e status = read_configure( |
|
324 cf_str_EAP_TRACE_output_file_name.get_field(), |
|
325 &trace_output_file); |
|
326 if (status == eap_status_ok |
|
327 && trace_output_file.get_is_valid_data() == true) |
|
328 { |
|
329 status = m_am_tools->set_trace_file_name(&trace_output_file); |
|
330 if (status == eap_status_ok) |
|
331 { |
|
332 // OK, set the default trace mask. |
|
333 m_am_tools->set_trace_mask( |
|
334 eap_am_tools_c::eap_trace_mask_debug |
|
335 | eap_am_tools_c::eap_trace_mask_always |
|
336 | eap_am_tools_c::eap_trace_mask_error); |
|
337 } |
|
338 } |
|
339 } |
|
340 #endif //#if defined(USE_EAP_HARDWARE_TRACE) |
|
341 |
|
342 |
|
343 { |
|
344 eap_status_e status = configure(); |
|
345 if (status != eap_status_ok) |
|
346 { |
|
347 User::Leave(KErrGeneral); |
|
348 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
349 } |
|
350 } |
|
351 |
|
352 EAP_TRACE_DEBUG( |
|
353 m_am_tools, |
|
354 TRACE_FLAGS_DEFAULT, |
|
355 (EAPL("Configured EAPOL AM...\n"))); |
|
356 |
|
357 EAP_TRACE_DEBUG( |
|
358 m_am_tools, |
|
359 TRACE_FLAGS_DEFAULT, |
|
360 (EAPL("Created timer...\n"))); |
|
361 |
|
362 // SERVER TEST CODE |
|
363 if (m_is_client == false) |
|
364 { |
|
365 TRAPD(err, ReadEAPSettingsL()); |
|
366 if (err != KErrNone) |
|
367 { |
|
368 // Setting reading from CommDB failed. Use default values instead (only EAP-SIM). |
|
369 |
|
370 // SIM |
|
371 _LIT(KSIM, "18"); |
|
372 TEap* sim = new(ELeave) TEap; |
|
373 CleanupStack::PushL(sim); |
|
374 sim->Enabled = ETrue; |
|
375 sim->UID.Copy(KSIM); |
|
376 User::LeaveIfError(m_iap_eap_array.Append(sim)); |
|
377 CleanupStack::Pop(sim); |
|
378 } |
|
379 |
|
380 } |
|
381 |
|
382 EAP_TRACE_DEBUG( |
|
383 m_am_tools, |
|
384 TRACE_FLAGS_DEFAULT, |
|
385 (EAPL("========================\n"))); |
|
386 |
|
387 set_is_valid(); |
|
388 |
|
389 } |
|
390 |
|
391 |
|
392 //-------------------------------------------------- |
|
393 |
|
394 eapol_am_core_symbian_c* eapol_am_core_symbian_c::NewL(MEapolToWlmIf * const aPartner, |
|
395 const bool aIsClient, |
|
396 const TUint aServerIndex) |
|
397 { |
|
398 eapol_am_core_symbian_c* self = new(ELeave) eapol_am_core_symbian_c(aPartner, aIsClient, aServerIndex); |
|
399 CleanupStack::PushL(self); |
|
400 self->ConstructL(); |
|
401 |
|
402 if (self->get_is_valid() != true) |
|
403 { |
|
404 User::Leave(KErrGeneral); |
|
405 } |
|
406 |
|
407 CleanupStack::Pop(); |
|
408 return self; |
|
409 } |
|
410 |
|
411 //-------------------------------------------------- |
|
412 |
|
413 eapol_am_core_symbian_c::~eapol_am_core_symbian_c() |
|
414 { |
|
415 |
|
416 #if defined(USE_EAP_FILECONFIG) |
|
417 delete m_fileconfig; |
|
418 m_fileconfig = 0; |
|
419 #endif //#if defined(USE_EAP_FILECONFIG) |
|
420 |
|
421 shutdown(); |
|
422 } |
|
423 |
|
424 //-------------------------------------------------- |
|
425 |
|
426 // |
|
427 eap_status_e eapol_am_core_symbian_c::shutdown() |
|
428 { |
|
429 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
430 |
|
431 EAP_TRACE_DEBUG( |
|
432 m_am_tools, |
|
433 TRACE_FLAGS_DEFAULT, |
|
434 (EAPL("eapol_am_core_symbian_c::shutdown()\n"))); |
|
435 |
|
436 // Cancel timer |
|
437 cancel_all_timers(); |
|
438 |
|
439 // Delete upper stack if it still exists |
|
440 if (m_ethernet_core != 0) |
|
441 { |
|
442 m_ethernet_core->shutdown(); |
|
443 delete m_ethernet_core; |
|
444 } |
|
445 |
|
446 delete m_wpa_preshared_key; |
|
447 |
|
448 delete m_ssid; |
|
449 |
|
450 delete m_wpa_psk_password_override; |
|
451 |
|
452 delete m_receive_network_id; |
|
453 |
|
454 m_database.Close(); |
|
455 m_session.Close(); |
|
456 |
|
457 // Print some statistics |
|
458 if (m_is_client) |
|
459 { |
|
460 EAP_TRACE_ALWAYS( |
|
461 m_am_tools, |
|
462 TRACE_FLAGS_ALWAYS|TRACE_TEST_VECTORS, |
|
463 (EAPL("client authentication SUCCESS %d, FAILED %d, count %d\n"), |
|
464 m_successful_authentications, |
|
465 m_failed_authentications, |
|
466 m_authentication_counter)); |
|
467 } |
|
468 else |
|
469 { |
|
470 EAP_TRACE_ALWAYS( |
|
471 m_am_tools, |
|
472 TRACE_FLAGS_ALWAYS|TRACE_TEST_VECTORS, |
|
473 (EAPL("server authentication SUCCESS %d, FAILED %d, count %d\n"), |
|
474 m_successful_authentications, |
|
475 m_failed_authentications, |
|
476 m_authentication_counter)); |
|
477 } |
|
478 |
|
479 EAP_TRACE_DEBUG( |
|
480 m_am_tools, |
|
481 TRACE_FLAGS_DEFAULT, |
|
482 (EAPL("EAPOL EXITING.\n"))); |
|
483 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
484 |
|
485 // Finally delete tools. No logging is allowed after this. |
|
486 if (m_am_tools != 0) |
|
487 { |
|
488 m_am_tools->shutdown(); |
|
489 delete m_am_tools; |
|
490 } |
|
491 |
|
492 |
|
493 // Unload all loaded plugins |
|
494 // NOTE this must be after the m_am_tools->shutdown() call. |
|
495 // m_am_tools->shutdown() will run virtual functions of some plugins. |
|
496 for(int i = 0; i < m_plugin_if_array.Count(); i++) |
|
497 { |
|
498 delete m_plugin_if_array[i]; |
|
499 } |
|
500 |
|
501 m_plugin_if_array.Close(); |
|
502 m_eap_type_array.Close(); |
|
503 |
|
504 // Delete the IAP EAP type info array |
|
505 m_iap_eap_array.ResetAndDestroy(); |
|
506 |
|
507 |
|
508 return eap_status_ok; |
|
509 } |
|
510 |
|
511 //-------------------------------------------------- |
|
512 |
|
513 // |
|
514 void eapol_am_core_symbian_c::RunL() |
|
515 { |
|
516 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
517 EAP_TRACE_DEBUG( |
|
518 m_am_tools, |
|
519 TRACE_FLAGS_DEFAULT, |
|
520 (EAPL("eapol_am_core_symbian_c::RunL(): iStatus.Int() = %d\n"), |
|
521 iStatus.Int())); |
|
522 |
|
523 if (iStatus.Int() != KErrNone) |
|
524 { |
|
525 return; |
|
526 } |
|
527 |
|
528 // Authentication cancelled. |
|
529 EAP_TRACE_ALWAYS( |
|
530 m_am_tools, |
|
531 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
532 (EAPL("Authentication cancelled.\n"))); |
|
533 |
|
534 // Set block on. |
|
535 m_block_packet_sends_and_notifications = true; |
|
536 |
|
537 // Reset flags |
|
538 m_success_indication_sent = false; |
|
539 m_unicast_wep_key_received = false; |
|
540 m_broadcast_wep_key_received = false; |
|
541 m_authentication_indication_sent = false; |
|
542 |
|
543 m_stack_marked_to_be_deleted = true; |
|
544 set_timer(this, EAPOL_AM_CORE_TIMER_DELETE_STACK_ID, 0, 0); |
|
545 |
|
546 // reset index |
|
547 m_eap_index = 0; |
|
548 |
|
549 EAP_TRACE_ALWAYS( |
|
550 m_am_tools, |
|
551 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
552 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
553 |
|
554 m_partner->EapIndication(EFailedCompletely); |
|
555 |
|
556 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
557 } |
|
558 |
|
559 //-------------------------------------------------- |
|
560 |
|
561 // |
|
562 void eapol_am_core_symbian_c::DoCancel() |
|
563 { |
|
564 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
565 |
|
566 EAP_TRACE_DEBUG( |
|
567 m_am_tools, |
|
568 TRACE_FLAGS_DEFAULT, |
|
569 (EAPL("eapol_am_core_symbian_c::DoCancel()\n"))); |
|
570 |
|
571 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
572 } |
|
573 |
|
574 //-------------------------------------------------- |
|
575 |
|
576 // |
|
577 TInt eapol_am_core_symbian_c::Start(const TIndexType aIndexType, |
|
578 const TUint aIndex, |
|
579 const TSSID& aSSID, |
|
580 const TBool aWPAOverrideEnabled, |
|
581 const TUint8* aWPAPSK, |
|
582 const TUint aWPAPSKLength) |
|
583 { |
|
584 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
585 |
|
586 EAP_TRACE_DEBUG( |
|
587 m_am_tools, |
|
588 TRACE_FLAGS_DEFAULT, |
|
589 (EAPL("eapol_am_core_symbian_c::Start()\n"))); |
|
590 |
|
591 EAP_TRACE_DEBUG( |
|
592 m_am_tools, |
|
593 TRACE_FLAGS_DEFAULT, |
|
594 (EAPL("STARTING AUTHENTICATION.\n"))); |
|
595 |
|
596 eap_status_e status(eap_status_ok); |
|
597 |
|
598 if (m_ethernet_core != 0) |
|
599 { |
|
600 EAP_TRACE_DEBUG( |
|
601 m_am_tools, |
|
602 TRACE_FLAGS_DEFAULT, |
|
603 (EAPL("Deleting previously used stack.\n"))); |
|
604 |
|
605 // It is an error to call start without calling disassociated |
|
606 if (m_stack_marked_to_be_deleted == false) |
|
607 { |
|
608 EAP_TRACE_ERROR( |
|
609 m_am_tools, |
|
610 TRACE_FLAGS_DEFAULT, |
|
611 (EAPL("eapol_am_core_symbian_c::Start called twice!\n"))); |
|
612 return KErrAlreadyExists; |
|
613 } |
|
614 |
|
615 // The previously used stack is perhaps still waiting for deletion. |
|
616 cancel_timer(this, EAPOL_AM_CORE_TIMER_DELETE_STACK_ID); |
|
617 |
|
618 // Delete stack |
|
619 m_ethernet_core->shutdown(); |
|
620 delete m_ethernet_core; |
|
621 m_ethernet_core = 0; |
|
622 |
|
623 m_stack_marked_to_be_deleted = false; |
|
624 } |
|
625 |
|
626 // Clear packet send and notification blocking. |
|
627 m_block_packet_sends_and_notifications = false; |
|
628 |
|
629 // Store SSID. This is needed for WPA PSK calculation. |
|
630 if (aSSID.ssidLength > 0) |
|
631 { |
|
632 status = m_ssid->set_copy_of_buffer(aSSID.ssid, aSSID.ssidLength); |
|
633 if (status != eap_status_ok) |
|
634 { |
|
635 return m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)); |
|
636 } |
|
637 } |
|
638 |
|
639 // Store WPAPSK. This is needed for WPA PSK mode in Easy WLAN. |
|
640 if (aWPAPSKLength > 0 |
|
641 && aWPAPSK != 0) |
|
642 { |
|
643 status = m_wpa_psk_password_override->set_copy_of_buffer(aWPAPSK, aWPAPSKLength); |
|
644 if (status != eap_status_ok) |
|
645 { |
|
646 return m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)); |
|
647 } |
|
648 } |
|
649 |
|
650 if (aWPAOverrideEnabled) |
|
651 { |
|
652 m_wpa_override_enabled = true; |
|
653 } |
|
654 else |
|
655 { |
|
656 m_wpa_override_enabled = false; |
|
657 } |
|
658 |
|
659 /////////////////////////////////// |
|
660 // Get EAP parameters from CommDbIf |
|
661 /////////////////////////////////// |
|
662 m_index_type = aIndexType; |
|
663 m_index = aIndex; |
|
664 |
|
665 TRAPD(err, ReadEAPSettingsL()); |
|
666 if (err != KErrNone) |
|
667 { |
|
668 EAP_TRACE_ERROR( |
|
669 m_am_tools, |
|
670 TRACE_FLAGS_DEFAULT, |
|
671 (EAPL("EAP settings reading from CommDb failed or cancelled(err %d).\n"), err)); |
|
672 m_partner->EapIndication(EFailedCompletely); |
|
673 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
674 return err; |
|
675 } |
|
676 |
|
677 // Start new authentication from scratch. |
|
678 m_unicast_wep_key_received = false; |
|
679 m_broadcast_wep_key_received = false; |
|
680 m_wpa_psk_mode_active = false; |
|
681 |
|
682 if (m_wpa_psk_mode_allowed == false |
|
683 || m_wpa_preshared_key->get_data_length() == 0) |
|
684 { |
|
685 // Check the first enabled type |
|
686 TEap* eapType = 0; |
|
687 TInt i(0); |
|
688 for (i = 0; i < m_iap_eap_array.Count(); i++) |
|
689 { |
|
690 // Check if type is enabled |
|
691 eapType = m_iap_eap_array[i]; |
|
692 if (eapType->Enabled == 1) |
|
693 { |
|
694 break; |
|
695 } |
|
696 } |
|
697 if (i >= m_iap_eap_array.Count()) |
|
698 { |
|
699 // No enabled EAP types. |
|
700 EAP_TRACE_ALWAYS( |
|
701 m_am_tools, |
|
702 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
703 (EAPL("No enabled EAP types.\n"))); |
|
704 EAP_TRACE_ALWAYS( |
|
705 m_am_tools, |
|
706 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
707 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
708 |
|
709 m_partner->EapIndication(EFailedCompletely); |
|
710 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
711 return KErrNone; |
|
712 } |
|
713 |
|
714 // reset index (start from the first enabled EAP type) |
|
715 m_eap_index = i; |
|
716 |
|
717 // Check if the first enabled type is LEAP. |
|
718 TLex8 tmp(eapType->UID); |
|
719 TInt type(0); |
|
720 tmp.Val(type); |
|
721 |
|
722 switch (type) |
|
723 { |
|
724 case eap_type_leap: |
|
725 if (m_security_mode != Wpa |
|
726 && m_security_mode != Wpa2Only) |
|
727 { |
|
728 m_802_11_authentication_mode = EAuthModeLeap; |
|
729 |
|
730 EAP_TRACE_ALWAYS( |
|
731 m_am_tools, |
|
732 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
733 (EAPL("Start: Trying auth mode LEAP.\n"))); |
|
734 } |
|
735 else |
|
736 { |
|
737 // If security mode is WPA or WPA2 then even LEAP uses open authentication! |
|
738 m_802_11_authentication_mode = EAuthModeOpen; |
|
739 |
|
740 EAP_TRACE_ALWAYS( |
|
741 m_am_tools, |
|
742 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
743 (EAPL("Start: Trying auth mode OPEN (LEAP in WPA mode).\n"))); |
|
744 } |
|
745 |
|
746 m_active_type_is_leap = true; |
|
747 break; |
|
748 default: |
|
749 m_802_11_authentication_mode = EAuthModeOpen; |
|
750 |
|
751 EAP_TRACE_ALWAYS( |
|
752 m_am_tools, |
|
753 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
754 (EAPL("Start: Trying auth mode OPEN.\n"))); |
|
755 |
|
756 m_active_type_is_leap = false; |
|
757 break; |
|
758 } |
|
759 } |
|
760 else |
|
761 { |
|
762 // WPA Pre-shared key mode |
|
763 m_active_type_is_leap = false; |
|
764 m_wpa_psk_mode_active = true; |
|
765 m_802_11_authentication_mode = EAuthModeOpen; |
|
766 |
|
767 EAP_TRACE_ALWAYS( |
|
768 m_am_tools, |
|
769 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
770 (EAPL("Start: Trying auth mode OPEN.\n"))); |
|
771 } |
|
772 |
|
773 // Ignore return value. Result comes with CompleteAssociation call. |
|
774 m_partner->Associate(m_802_11_authentication_mode); |
|
775 |
|
776 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
777 return m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)); |
|
778 } |
|
779 |
|
780 //-------------------------------------------------- |
|
781 |
|
782 // |
|
783 TInt eapol_am_core_symbian_c::CompleteAssociation( |
|
784 const TInt aResult, |
|
785 const TMacAddress& aLocalAddress, |
|
786 const TMacAddress& aRemoteAddress, |
|
787 const TUint8* const aReceivedWPAIE, // WLM must give only the WPA IE to EAPOL |
|
788 const TUint aReceivedWPAIELength, |
|
789 const TUint8* const aSentWPAIE, |
|
790 const TUint aSentWPAIELength, |
|
791 const TWPACipherSuite aGroupKeyCipherSuite, |
|
792 const TWPACipherSuite aPairwiseKeyCipherSuite |
|
793 ) |
|
794 { |
|
795 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
796 |
|
797 EAP_TRACE_ALWAYS( |
|
798 m_am_tools, |
|
799 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
800 (EAPL("eapol_am_core_symbian_c::CompleteAssociation(): aResult %d\n"), |
|
801 aResult)); |
|
802 |
|
803 eap_status_e status(eap_status_ok); |
|
804 |
|
805 // ASSOCIATION UNSUCCESSFUL |
|
806 if (aResult != KErrNone) |
|
807 { |
|
808 EAP_TRACE_DEBUG( |
|
809 m_am_tools, |
|
810 TRACE_FLAGS_DEFAULT, |
|
811 (EAPL("CompleteAssociation: Unsuccessful.\n"))); |
|
812 |
|
813 EAP_TRACE_DATA_DEBUG( |
|
814 m_am_tools, |
|
815 TRACE_FLAGS_DEFAULT, |
|
816 (EAPL("Got AP MAC address"), |
|
817 aRemoteAddress.iMacAddress, |
|
818 KMacAddressLength)); |
|
819 |
|
820 // Report rogue AP if we tried LEAP and it failed |
|
821 if (m_802_11_authentication_mode == EAuthModeLeap) |
|
822 { |
|
823 // Only add rogue AP if the error code is correct |
|
824 if (aResult == E802Dot11StatusAuthAlgorithmNotSupported) |
|
825 { |
|
826 eap_rogue_ap_entry_c rogue_entry(m_am_tools); |
|
827 |
|
828 rogue_entry.set_mac_address(static_cast<const u8_t *>(aRemoteAddress.iMacAddress)); |
|
829 rogue_entry.set_rogue_reason(rogue_ap_association_failed); |
|
830 |
|
831 eap_array_c<eap_rogue_ap_entry_c> rogue_list(m_am_tools); |
|
832 status = rogue_list.add_object(&rogue_entry, false); |
|
833 if (status == eap_status_ok) |
|
834 { |
|
835 status = add_rogue_ap(rogue_list); |
|
836 // Ignore return value on purpose - it's not fatal if this fails |
|
837 } |
|
838 } |
|
839 } |
|
840 |
|
841 if (m_wpa_psk_mode_active == false) |
|
842 { |
|
843 if (aResult == E802Dot11StatusAuthAlgorithmNotSupported |
|
844 && m_security_mode != Wpa |
|
845 && m_security_mode != Wpa2Only) // If security mode is WPA or WPA2 then only OPEN auth should be used |
|
846 { |
|
847 // Association failed because we had wrong authentication type. |
|
848 // Try to find next allowed type that uses different authentication type |
|
849 m_eap_index++; |
|
850 |
|
851 TEap* eapType; |
|
852 TBool found(EFalse); |
|
853 TInt i(0); |
|
854 for (i = m_eap_index; i < m_iap_eap_array.Count(); i++) |
|
855 { |
|
856 // Check if type is enabled |
|
857 eapType = m_iap_eap_array[i]; |
|
858 if (eapType->Enabled == 1) |
|
859 { |
|
860 TLex8 tmp(eapType->UID); |
|
861 TInt type(0); |
|
862 tmp.Val(type); |
|
863 |
|
864 switch (type) |
|
865 { |
|
866 case eap_type_leap: |
|
867 if (m_802_11_authentication_mode != EAuthModeLeap) |
|
868 { |
|
869 // This type will do; it uses different authentication mode. |
|
870 EAP_TRACE_ALWAYS( |
|
871 m_am_tools, |
|
872 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
873 (EAPL("CompleteAssociation: Changed auth mode to LEAP.\n"))); |
|
874 |
|
875 m_802_11_authentication_mode = EAuthModeLeap; |
|
876 m_active_type_is_leap = true; |
|
877 found = ETrue; |
|
878 } |
|
879 break; |
|
880 default: |
|
881 if (m_802_11_authentication_mode != EAuthModeOpen) |
|
882 { |
|
883 // This type will do; it uses different authentication mode. |
|
884 EAP_TRACE_ALWAYS( |
|
885 m_am_tools, |
|
886 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
887 (EAPL("CompleteAssociation: Changed auth mode to OPEN.\n"))); |
|
888 |
|
889 m_802_11_authentication_mode = EAuthModeOpen; |
|
890 m_active_type_is_leap = false; |
|
891 found = ETrue; |
|
892 } |
|
893 break; |
|
894 } |
|
895 if (found) |
|
896 { |
|
897 break; |
|
898 } |
|
899 } |
|
900 } |
|
901 |
|
902 m_eap_index = i; |
|
903 |
|
904 if (i >= m_iap_eap_array.Count()) |
|
905 { |
|
906 // All the remaining allowed types had the same authentication mode. |
|
907 // Give up this AP. |
|
908 EAP_TRACE_ALWAYS( |
|
909 m_am_tools, |
|
910 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
911 (EAPL("Could not associate to the AP. Tried all types.\n"))); |
|
912 |
|
913 EAP_TRACE_ALWAYS( |
|
914 m_am_tools, |
|
915 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
916 (EAPL("Indication sent to WLM: EThisAPFailed.\n"))); |
|
917 |
|
918 m_partner->EapIndication(EThisAPFailed); |
|
919 return KErrNone; |
|
920 |
|
921 } |
|
922 |
|
923 // We found a type with different authentication mode. Try it. |
|
924 |
|
925 // Ignore return value. Result comes with CompleteAssociation call. |
|
926 m_partner->Associate(m_802_11_authentication_mode); |
|
927 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
928 return KErrNone; |
|
929 } |
|
930 else |
|
931 { |
|
932 EAP_TRACE_ALWAYS( |
|
933 m_am_tools, |
|
934 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
935 (EAPL("Could not associate to the AP (error %d).\n"), aResult)); |
|
936 |
|
937 EAP_TRACE_ALWAYS( |
|
938 m_am_tools, |
|
939 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
940 (EAPL("Indication sent to WLM: EThisAPFailed.\n"))); |
|
941 |
|
942 m_partner->EapIndication(EThisAPFailed); |
|
943 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
944 return KErrNone; |
|
945 } |
|
946 } |
|
947 else |
|
948 { |
|
949 EAP_TRACE_ALWAYS( |
|
950 m_am_tools, |
|
951 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
952 (EAPL("Could not associate to the AP with WPA pre-shared-key.\n"))); |
|
953 |
|
954 EAP_TRACE_ALWAYS( |
|
955 m_am_tools, |
|
956 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
957 (EAPL("Indication sent to WLM: EThisAPFailed.\n"))); |
|
958 |
|
959 m_partner->EapIndication(EThisAPFailed); |
|
960 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
961 return KErrNone; |
|
962 } |
|
963 } |
|
964 |
|
965 // ASSOCIATION SUCCESSFUL |
|
966 EAP_TRACE_ALWAYS( |
|
967 m_am_tools, |
|
968 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
969 (EAPL("CompleteAssociation: Successful.\n"))); |
|
970 |
|
971 // Store parameters |
|
972 m_local_address = aLocalAddress; |
|
973 |
|
974 m_remote_address = aRemoteAddress; |
|
975 |
|
976 m_received_wpa_ie = aReceivedWPAIE; |
|
977 |
|
978 m_received_wpa_ie_length = aReceivedWPAIELength; |
|
979 |
|
980 m_sent_wpa_ie = aSentWPAIE; |
|
981 |
|
982 m_sent_wpa_ie_length = aSentWPAIELength; |
|
983 |
|
984 m_group_key_cipher_suite = aGroupKeyCipherSuite; |
|
985 |
|
986 m_pairwise_key_cipher_suite = aPairwiseKeyCipherSuite; |
|
987 |
|
988 // Create stack if it does not already exist. |
|
989 status = create_upper_stack(); |
|
990 if (status != eap_status_ok |
|
991 && status != eap_status_already_exists) |
|
992 { |
|
993 EAP_TRACE_ALWAYS( |
|
994 m_am_tools, |
|
995 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
996 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
997 |
|
998 m_partner->EapIndication(EFailedCompletely); |
|
999 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1000 return KErrNone; |
|
1001 } |
|
1002 |
|
1003 // First create stack object and then copy it to heap object. This is because |
|
1004 // eap_am_network_id_c does not have a constructor that copies the buffers. |
|
1005 eap_am_network_id_c receive_network_id( |
|
1006 m_am_tools, |
|
1007 &aRemoteAddress, |
|
1008 sizeof(TMacAddress), |
|
1009 &aLocalAddress, |
|
1010 sizeof(TMacAddress), |
|
1011 eapol_ethernet_type_pae, |
|
1012 false, |
|
1013 false); |
|
1014 |
|
1015 delete m_receive_network_id; |
|
1016 m_receive_network_id = new eap_am_network_id_c( |
|
1017 m_am_tools); |
|
1018 |
|
1019 if (m_receive_network_id == 0) |
|
1020 { |
|
1021 EAP_TRACE_ALWAYS( |
|
1022 m_am_tools, |
|
1023 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
1024 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
1025 |
|
1026 m_partner->EapIndication(EFailedCompletely); |
|
1027 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1028 return KErrNone; |
|
1029 } |
|
1030 |
|
1031 status = m_receive_network_id->set_copy_of_network_id(&receive_network_id); |
|
1032 if (status != eap_status_ok) |
|
1033 { |
|
1034 EAP_TRACE_ALWAYS( |
|
1035 m_am_tools, |
|
1036 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
1037 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
1038 |
|
1039 m_partner->EapIndication(EFailedCompletely); |
|
1040 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1041 return KErrNone; |
|
1042 } |
|
1043 |
|
1044 |
|
1045 #if defined (USE_EAPOL_KEY_STATE) |
|
1046 |
|
1047 // Initialise EAPOL key state |
|
1048 |
|
1049 eapol_key_authentication_type_e authentication_type(eapol_key_authentication_type_802_1X); |
|
1050 |
|
1051 if (aReceivedWPAIE !=0 |
|
1052 && aSentWPAIE != 0) |
|
1053 { |
|
1054 // WPA (in wpa or 802.1x security mode) |
|
1055 if (m_wpa_psk_mode_allowed == false) |
|
1056 { |
|
1057 authentication_type = eapol_key_authentication_type_WPA_EAP; |
|
1058 } |
|
1059 else |
|
1060 { |
|
1061 m_wpa_psk_mode_active = true; |
|
1062 authentication_type = eapol_key_authentication_type_WPA_PSK; |
|
1063 } |
|
1064 |
|
1065 } |
|
1066 else |
|
1067 { |
|
1068 // Non-wpa mode |
|
1069 authentication_type = eapol_key_authentication_type_802_1X; |
|
1070 } |
|
1071 |
|
1072 eap_variable_data_c authenticator_RSNA_IE(m_am_tools); |
|
1073 eap_variable_data_c supplicant_RSNA_IE(m_am_tools); |
|
1074 |
|
1075 // Note: the default values here are only for 802.1x mode. In that mode |
|
1076 // we don't know the WEP key length beforehand so we will have to guess. |
|
1077 // It does not matter in this case if we guess wrong - only thing that matters |
|
1078 // is that it is WEP. |
|
1079 eapol_RSNA_key_header_c::eapol_RSNA_cipher_e |
|
1080 eapol_pairwise_cipher(eapol_RSNA_key_header_c::eapol_RSNA_cipher_WEP_40); |
|
1081 eapol_RSNA_key_header_c::eapol_RSNA_cipher_e |
|
1082 eapol_group_cipher(eapol_RSNA_key_header_c::eapol_RSNA_cipher_WEP_40); |
|
1083 |
|
1084 // WPA mode is active if information elements are valid |
|
1085 if (aReceivedWPAIE != 0 |
|
1086 && aSentWPAIE != 0) |
|
1087 { |
|
1088 status = authenticator_RSNA_IE.set_copy_of_buffer(aReceivedWPAIE, aReceivedWPAIELength); |
|
1089 if (status != eap_status_ok) |
|
1090 { |
|
1091 EAP_TRACE_ALWAYS( |
|
1092 m_am_tools, |
|
1093 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
1094 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
1095 |
|
1096 m_partner->EapIndication(EFailedCompletely); |
|
1097 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1098 return KErrNoMemory; |
|
1099 } |
|
1100 status = supplicant_RSNA_IE.set_copy_of_buffer(aSentWPAIE, aSentWPAIELength); |
|
1101 if (status != eap_status_ok) |
|
1102 { |
|
1103 EAP_TRACE_ALWAYS( |
|
1104 m_am_tools, |
|
1105 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
1106 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
1107 |
|
1108 m_partner->EapIndication(EFailedCompletely); |
|
1109 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1110 return KErrNoMemory; |
|
1111 } |
|
1112 |
|
1113 switch (aGroupKeyCipherSuite) |
|
1114 { |
|
1115 case ENoCipherSuite: |
|
1116 eapol_group_cipher = eapol_RSNA_key_header_c::eapol_RSNA_cipher_none; |
|
1117 break; |
|
1118 case EWEP40: |
|
1119 eapol_group_cipher = eapol_RSNA_key_header_c::eapol_RSNA_cipher_WEP_40; |
|
1120 break; |
|
1121 case EWEP104: |
|
1122 eapol_group_cipher = eapol_RSNA_key_header_c::eapol_RSNA_cipher_WEP_104; |
|
1123 break; |
|
1124 case ETKIP: |
|
1125 eapol_group_cipher = eapol_RSNA_key_header_c::eapol_RSNA_cipher_TKIP; |
|
1126 break; |
|
1127 case ECCMP: |
|
1128 eapol_group_cipher = eapol_RSNA_key_header_c::eapol_RSNA_cipher_CCMP; |
|
1129 break; |
|
1130 case EWRAP: |
|
1131 default: |
|
1132 User::Panic(_L("EAPOL"), KErrNotSupported); |
|
1133 } |
|
1134 |
|
1135 switch (aPairwiseKeyCipherSuite) |
|
1136 { |
|
1137 case ENoCipherSuite: |
|
1138 eapol_pairwise_cipher = eapol_RSNA_key_header_c::eapol_RSNA_cipher_none; |
|
1139 break; |
|
1140 case EWEP40: |
|
1141 eapol_pairwise_cipher = eapol_RSNA_key_header_c::eapol_RSNA_cipher_WEP_40; |
|
1142 break; |
|
1143 case EWEP104: |
|
1144 eapol_pairwise_cipher = eapol_RSNA_key_header_c::eapol_RSNA_cipher_WEP_104; |
|
1145 break; |
|
1146 case ETKIP: |
|
1147 eapol_pairwise_cipher = eapol_RSNA_key_header_c::eapol_RSNA_cipher_TKIP; |
|
1148 break; |
|
1149 case ECCMP: |
|
1150 eapol_pairwise_cipher = eapol_RSNA_key_header_c::eapol_RSNA_cipher_CCMP; |
|
1151 break; |
|
1152 case EWRAP: |
|
1153 default: |
|
1154 User::Panic(_L("EAPOL"), KErrNotSupported); |
|
1155 } |
|
1156 } |
|
1157 |
|
1158 if (authentication_type == eapol_key_authentication_type_WPA_PSK) |
|
1159 { |
|
1160 status = m_ethernet_core->association( |
|
1161 m_receive_network_id, |
|
1162 authentication_type, |
|
1163 &authenticator_RSNA_IE, |
|
1164 &supplicant_RSNA_IE, |
|
1165 eapol_pairwise_cipher, |
|
1166 eapol_group_cipher, |
|
1167 m_wpa_preshared_key); |
|
1168 } |
|
1169 else |
|
1170 { |
|
1171 status = m_ethernet_core->association( |
|
1172 m_receive_network_id, |
|
1173 authentication_type, |
|
1174 &authenticator_RSNA_IE, |
|
1175 &supplicant_RSNA_IE, |
|
1176 eapol_pairwise_cipher, |
|
1177 eapol_group_cipher, |
|
1178 0); |
|
1179 } |
|
1180 if (status != eap_status_ok) |
|
1181 { |
|
1182 |
|
1183 EAP_TRACE_ALWAYS( |
|
1184 m_am_tools, |
|
1185 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
1186 (EAPL("m_ethernet_core->association call failed.\n"))); |
|
1187 |
|
1188 EAP_TRACE_ALWAYS( |
|
1189 m_am_tools, |
|
1190 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
1191 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
1192 |
|
1193 m_partner->EapIndication(EFailedCompletely); |
|
1194 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1195 return KErrGeneral; |
|
1196 } |
|
1197 |
|
1198 #endif // USE_EAPOL_KEY_STATE |
|
1199 |
|
1200 if (m_wpa_psk_mode_active == false) |
|
1201 { |
|
1202 // Start authentication if mode is not pre-shared key. If mode is pre-shared key then |
|
1203 // just wait for EAPOL-Key frames. |
|
1204 status = m_ethernet_core->start_authentication(m_receive_network_id, m_is_client); |
|
1205 } |
|
1206 |
|
1207 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1208 return m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)); |
|
1209 } |
|
1210 |
|
1211 //-------------------------------------------------- |
|
1212 |
|
1213 // |
|
1214 TInt eapol_am_core_symbian_c::ReceivePacket(const TUint aLength, const TUint8* const aPacket) |
|
1215 { |
|
1216 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1217 |
|
1218 EAP_TRACE_DEBUG( |
|
1219 m_am_tools, |
|
1220 TRACE_FLAGS_DEFAULT, |
|
1221 (EAPL("eapol_am_core_symbian_c::ReceivePacket()\n"))); |
|
1222 |
|
1223 if (aLength < eapol_ethernet_header_wr_c::get_header_length()) |
|
1224 { |
|
1225 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1226 return m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, eap_status_too_short_message)); |
|
1227 } |
|
1228 |
|
1229 eapol_ethernet_header_wr_c eth_header(m_am_tools, aPacket, aLength); |
|
1230 eap_am_network_id_c receive_network_id( |
|
1231 m_am_tools, |
|
1232 eth_header.get_source(), |
|
1233 eth_header.get_source_length(), |
|
1234 eth_header.get_destination(), |
|
1235 eth_header.get_destination_length(), |
|
1236 eth_header.get_type(), |
|
1237 false, |
|
1238 false); |
|
1239 eap_status_e status(eap_status_process_general_error); |
|
1240 if (eth_header.get_type() == eapol_ethernet_type_pae) |
|
1241 { |
|
1242 status = create_upper_stack(); |
|
1243 if (status != eap_status_ok |
|
1244 && status != eap_status_already_exists) |
|
1245 { |
|
1246 EAP_TRACE_DEBUG( |
|
1247 m_am_tools, |
|
1248 TRACE_FLAGS_DEFAULT, |
|
1249 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
1250 m_partner->EapIndication(EFailedCompletely); |
|
1251 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1252 return KErrNone; |
|
1253 } |
|
1254 |
|
1255 #if defined (USE_EAPOL_KEY_STATE) |
|
1256 if (m_is_client == false |
|
1257 && status != eap_status_already_exists) |
|
1258 { |
|
1259 // If we are server we need to do associate here. |
|
1260 eapol_key_authentication_type_e authentication_type( |
|
1261 eapol_key_authentication_type_WPA_EAP); |
|
1262 |
|
1263 eap_variable_data_c authenticator_RSNA_IE(m_am_tools); |
|
1264 eap_variable_data_c supplicant_RSNA_IE(m_am_tools); |
|
1265 |
|
1266 status = authenticator_RSNA_IE.set_buffer(TEST_RSN_IE, sizeof(TEST_RSN_IE), false, false); |
|
1267 if (status != eap_status_ok) |
|
1268 { |
|
1269 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1270 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
1271 } |
|
1272 |
|
1273 status = supplicant_RSNA_IE.set_buffer(TEST_RSN_IE, sizeof(TEST_RSN_IE), false, false); |
|
1274 if (status != eap_status_ok) |
|
1275 { |
|
1276 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1277 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
1278 } |
|
1279 |
|
1280 eapol_RSNA_key_header_c::eapol_RSNA_cipher_e |
|
1281 eapol_pairwise_cipher(eapol_RSNA_key_header_c::eapol_RSNA_cipher_TKIP); |
|
1282 eapol_RSNA_key_header_c::eapol_RSNA_cipher_e |
|
1283 eapol_group_cipher(eapol_RSNA_key_header_c::eapol_RSNA_cipher_TKIP); |
|
1284 |
|
1285 |
|
1286 if (authentication_type == eapol_key_authentication_type_WPA_PSK) |
|
1287 { |
|
1288 status = m_ethernet_core->association( |
|
1289 &receive_network_id, |
|
1290 authentication_type, |
|
1291 &authenticator_RSNA_IE, |
|
1292 &supplicant_RSNA_IE, |
|
1293 eapol_pairwise_cipher, |
|
1294 eapol_group_cipher, |
|
1295 m_wpa_preshared_key); |
|
1296 } |
|
1297 else |
|
1298 { |
|
1299 status = m_ethernet_core->association( |
|
1300 &receive_network_id, |
|
1301 authentication_type, |
|
1302 &authenticator_RSNA_IE, |
|
1303 &supplicant_RSNA_IE, |
|
1304 eapol_pairwise_cipher, |
|
1305 eapol_group_cipher, |
|
1306 0); |
|
1307 } |
|
1308 |
|
1309 } |
|
1310 #endif // USE_EAPOL_KEY_STATE |
|
1311 |
|
1312 // Forward the packet to the Ethernet layer of the EAPOL stack. Ignore return value. Failure is signalled using state_notification. |
|
1313 status = m_ethernet_core->packet_process( |
|
1314 &receive_network_id, |
|
1315 ð_header, |
|
1316 aLength); |
|
1317 |
|
1318 } |
|
1319 else |
|
1320 { |
|
1321 EAP_TRACE_DEBUG( |
|
1322 m_am_tools, |
|
1323 TRACE_FLAGS_DEFAULT, |
|
1324 (EAPL("Not supported ethernet type 0x%04x\n"), eth_header.get_type())); |
|
1325 status = eap_status_ethernet_type_not_supported; |
|
1326 } |
|
1327 |
|
1328 status = eap_status_ok; |
|
1329 |
|
1330 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1331 return m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)); |
|
1332 } |
|
1333 |
|
1334 //-------------------------------------------------- |
|
1335 |
|
1336 void eapol_am_core_symbian_c::set_is_valid() |
|
1337 { |
|
1338 m_is_valid = true; |
|
1339 } |
|
1340 |
|
1341 bool eapol_am_core_symbian_c::get_is_valid() |
|
1342 { |
|
1343 return m_is_valid; |
|
1344 } |
|
1345 |
|
1346 void eapol_am_core_symbian_c::increment_authentication_counter() |
|
1347 { |
|
1348 ++m_authentication_counter; |
|
1349 } |
|
1350 |
|
1351 u32_t eapol_am_core_symbian_c::get_authentication_counter() |
|
1352 { |
|
1353 return m_authentication_counter; |
|
1354 } |
|
1355 |
|
1356 bool eapol_am_core_symbian_c::get_is_client() |
|
1357 { |
|
1358 return m_is_client; |
|
1359 } |
|
1360 |
|
1361 |
|
1362 //-------------------------------------------------- |
|
1363 |
|
1364 // |
|
1365 eap_status_e eapol_am_core_symbian_c::packet_data_crypto_keys( |
|
1366 const eap_am_network_id_c * const /*send_network_id*/, |
|
1367 const eap_variable_data_c * const /*master_session_key*/) |
|
1368 { |
|
1369 // Not needed in Symbian version |
|
1370 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1371 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1372 return eap_status_ok; |
|
1373 } |
|
1374 |
|
1375 //-------------------------------------------------- |
|
1376 |
|
1377 eap_status_e eapol_am_core_symbian_c::packet_data_session_key( |
|
1378 const eap_am_network_id_c * const /*send_network_id*/, |
|
1379 const eapol_session_key_c * const key) |
|
1380 { |
|
1381 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1382 TInt status(KErrNone); |
|
1383 |
|
1384 const eap_variable_data_c * const key_data = key->get_key(); |
|
1385 if (key_data == 0) |
|
1386 { |
|
1387 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1388 return eap_status_key_error; |
|
1389 } |
|
1390 |
|
1391 EAP_TRACE_DEBUG(m_am_tools, |
|
1392 TRACE_FLAGS_DEFAULT, |
|
1393 (EAPL("packet_data_session_key: index: %d, type %d\n"), |
|
1394 key->get_key_index(), |
|
1395 key->get_key_type())); |
|
1396 |
|
1397 EAP_TRACE_DATA_DEBUG(m_am_tools, |
|
1398 TRACE_FLAGS_DEFAULT, |
|
1399 (EAPL("packet_data_session_key:"), |
|
1400 key_data->get_data(key_data->get_data_length()), |
|
1401 key_data->get_data_length())); |
|
1402 |
|
1403 switch (key->get_key_type()) |
|
1404 { |
|
1405 case eapol_key_type_broadcast: |
|
1406 EAP_TRACE_DEBUG( |
|
1407 m_am_tools, |
|
1408 TRACE_FLAGS_DEFAULT, |
|
1409 (EAPL("eapol_am_core_symbian_c::packet_data_session_key: Got rc4_broadcast key.\n"))); |
|
1410 |
|
1411 status = m_partner->SetCipherKey( |
|
1412 ERC4Broadcast, |
|
1413 static_cast<TUint8> (key->get_key_index()), |
|
1414 key_data->get_data(key_data->get_data_length()), |
|
1415 key_data->get_data_length()); |
|
1416 m_broadcast_wep_key_received = true; |
|
1417 break; |
|
1418 case eapol_key_type_unicast: |
|
1419 EAP_TRACE_DEBUG( |
|
1420 m_am_tools, |
|
1421 TRACE_FLAGS_DEFAULT, |
|
1422 (EAPL("eapol_am_core_symbian_c::packet_data_session_key: Got rc4_unicast key.\n"))); |
|
1423 |
|
1424 status = m_partner->SetCipherKey( |
|
1425 ERC4Unicast, |
|
1426 static_cast<TUint8> (key->get_key_index()), |
|
1427 key_data->get_data(key_data->get_data_length()), |
|
1428 key_data->get_data_length()); |
|
1429 m_unicast_wep_key_received = true; |
|
1430 break; |
|
1431 default: |
|
1432 EAP_TRACE_ERROR( |
|
1433 m_am_tools, |
|
1434 TRACE_FLAGS_DEFAULT, |
|
1435 (EAPL("eapol_am_core_symbian_c::packet_data_session_key: Got unsupported key, type %d.\n"), |
|
1436 key->get_key_type())); |
|
1437 status = KErrNotSupported; |
|
1438 break; |
|
1439 } |
|
1440 |
|
1441 if (m_unicast_wep_key_received == true |
|
1442 && m_broadcast_wep_key_received == true |
|
1443 && m_success_indication_sent == false) |
|
1444 { |
|
1445 // Signal success because we have received one unicast (pairwise) key and one broadcast (group) key. |
|
1446 // If there are more keys coming later they are saved also. |
|
1447 if (m_active_type_is_leap == true) |
|
1448 { |
|
1449 // Leap was successful |
|
1450 EAP_TRACE_DEBUG( |
|
1451 m_am_tools, |
|
1452 TRACE_FLAGS_DEFAULT, |
|
1453 (EAPL("Indication sent to WLM: ELeapSuccess.\n"))); |
|
1454 m_partner->EapIndication(ELeapSuccess); |
|
1455 } |
|
1456 else |
|
1457 { |
|
1458 // some other type was successful |
|
1459 EAP_TRACE_DEBUG( |
|
1460 m_am_tools, |
|
1461 TRACE_FLAGS_DEFAULT, |
|
1462 (EAPL("Indication sent to WLM: ESuccess.\n"))); |
|
1463 m_partner->EapIndication(ESuccess); |
|
1464 } |
|
1465 |
|
1466 m_success_indication_sent = true; |
|
1467 m_first_authentication = false; |
|
1468 } |
|
1469 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1470 return EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(status)); |
|
1471 } |
|
1472 |
|
1473 //-------------------------------------------------- |
|
1474 |
|
1475 // |
|
1476 |
|
1477 eap_status_e eapol_am_core_symbian_c::packet_send( |
|
1478 const eap_am_network_id_c * const /*send_network_id*/, |
|
1479 eap_buf_chain_wr_c * const sent_packet, |
|
1480 const u32_t header_offset, |
|
1481 const u32_t data_length, |
|
1482 const u32_t /*buffer_length*/) |
|
1483 { |
|
1484 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1485 |
|
1486 EAP_TRACE_DEBUG( |
|
1487 m_am_tools, |
|
1488 TRACE_FLAGS_DEFAULT, |
|
1489 (EAPL("eapol_am_core_symbian_c::packet_send(data_length=%d).\n"), |
|
1490 data_length)); |
|
1491 |
|
1492 if (header_offset != 0u) |
|
1493 { |
|
1494 EAP_TRACE_DEBUG( |
|
1495 m_am_tools, |
|
1496 TRACE_FLAGS_DEFAULT, |
|
1497 (EAPL("packet_send: packet buffer corrupted.\n"))); |
|
1498 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1499 return eap_status_process_general_error; |
|
1500 } |
|
1501 else if (header_offset+data_length != sent_packet->get_data_length()) |
|
1502 { |
|
1503 EAP_TRACE_DEBUG( |
|
1504 m_am_tools, |
|
1505 TRACE_FLAGS_DEFAULT, |
|
1506 (EAPL("ERROR: packet_send: packet buffer corrupted (data_length != sent_packet->get_data_length()).\n"))); |
|
1507 EAP_ASSERT(data_length == sent_packet->get_buffer_length()); |
|
1508 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1509 return eap_status_process_general_error; |
|
1510 } |
|
1511 |
|
1512 if (m_block_packet_sends_and_notifications == true) |
|
1513 { |
|
1514 // Packet sending block is active. This happens when disassociated has been called. |
|
1515 // start_authentication clears the block. |
|
1516 EAP_TRACE_DEBUG( |
|
1517 m_am_tools, |
|
1518 TRACE_FLAGS_DEFAULT, |
|
1519 (EAPL("packet_send: packet ignored because Disassociated() was called.\n"))); |
|
1520 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1521 return eap_status_ok; |
|
1522 } |
|
1523 |
|
1524 TInt status(KErrNone); |
|
1525 if (m_send_original_packet_first == true) |
|
1526 { |
|
1527 if (m_enable_random_errors == true) |
|
1528 { |
|
1529 EAP_TRACE_DEBUG( |
|
1530 m_am_tools, |
|
1531 TRACE_FLAGS_DEFAULT, |
|
1532 (EAPL("TEST: random_error(): packet_index 0x%08x:%lu, Send original packet\n"), |
|
1533 this, |
|
1534 m_packet_index)); |
|
1535 } |
|
1536 |
|
1537 u8_t * const packet_data = sent_packet->get_data_offset(header_offset, data_length); |
|
1538 if (packet_data == 0) |
|
1539 { |
|
1540 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1541 return eap_status_buffer_too_short; |
|
1542 } |
|
1543 |
|
1544 // Here we send the original packet. |
|
1545 status = m_partner->EapPacketSend( |
|
1546 data_length, |
|
1547 static_cast<TUint8*>(packet_data)); |
|
1548 ++m_packet_index; |
|
1549 } |
|
1550 |
|
1551 if (m_enable_random_errors == true |
|
1552 && status == KErrNone) |
|
1553 { |
|
1554 if (m_generate_multiple_error_packets > 0ul) |
|
1555 { |
|
1556 // First create a copy of sent packet. Original correct packet will will be sent last. |
|
1557 for (u32_t ind = 0ul; ind < m_generate_multiple_error_packets; ind++) |
|
1558 { |
|
1559 eap_buf_chain_wr_c *copy_packet = sent_packet->copy(); |
|
1560 |
|
1561 if (copy_packet != 0 |
|
1562 && copy_packet->get_is_valid_data() == true) |
|
1563 { |
|
1564 // Make a random error to the copy message. |
|
1565 random_error(copy_packet, true, m_packet_index); |
|
1566 |
|
1567 EAP_TRACE_DEBUG( |
|
1568 m_am_tools, |
|
1569 TRACE_FLAGS_DEFAULT, |
|
1570 (EAPL("TEST: random_error(): packet_index 0x%08x:%lu, Send error packet\n"), |
|
1571 this, |
|
1572 m_packet_index)); |
|
1573 |
|
1574 u8_t * const packet_data = copy_packet->get_data_offset(header_offset, data_length); |
|
1575 if (packet_data == 0) |
|
1576 { |
|
1577 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1578 return eap_status_buffer_too_short; |
|
1579 } |
|
1580 |
|
1581 // Here we send the copied and manipulated packet. |
|
1582 status = m_partner->EapPacketSend( |
|
1583 data_length, |
|
1584 static_cast<TUint8*>(packet_data)); |
|
1585 |
|
1586 ++m_packet_index; |
|
1587 } |
|
1588 delete copy_packet; |
|
1589 } |
|
1590 } |
|
1591 else |
|
1592 { |
|
1593 // Make a random error to the original message. |
|
1594 random_error(sent_packet, false, m_packet_index); |
|
1595 |
|
1596 if (sent_packet->get_is_manipulated() == true) |
|
1597 { |
|
1598 EAP_TRACE_DEBUG( |
|
1599 m_am_tools, |
|
1600 TRACE_FLAGS_DEFAULT, |
|
1601 (EAPL("TEST: random_error(): packet_index 0x%08x:%lu, Send error packet\n"), |
|
1602 this, |
|
1603 m_packet_index)); |
|
1604 } |
|
1605 } |
|
1606 } |
|
1607 |
|
1608 |
|
1609 if (m_send_original_packet_first == false |
|
1610 && status == KErrNone) |
|
1611 { |
|
1612 if (m_enable_random_errors == true) |
|
1613 { |
|
1614 EAP_TRACE_DEBUG( |
|
1615 m_am_tools, |
|
1616 TRACE_FLAGS_DEFAULT, |
|
1617 (EAPL("TEST: random_error(): packet_index 0x%08x:%lu, Send original packet\n"), |
|
1618 this, |
|
1619 m_packet_index)); |
|
1620 } |
|
1621 |
|
1622 u8_t * const packet_data = sent_packet->get_data_offset(header_offset, data_length); |
|
1623 if (packet_data == 0) |
|
1624 { |
|
1625 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1626 return eap_status_buffer_too_short; |
|
1627 } |
|
1628 |
|
1629 // Here we send the original packet. |
|
1630 status = m_partner->EapPacketSend( |
|
1631 data_length, |
|
1632 static_cast<TUint8*>(packet_data)); |
|
1633 ++m_packet_index; |
|
1634 } |
|
1635 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1636 |
|
1637 return EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(status)); |
|
1638 } |
|
1639 |
|
1640 //-------------------------------------------------- |
|
1641 |
|
1642 // |
|
1643 eap_status_e eapol_am_core_symbian_c::reassociate( |
|
1644 const eap_am_network_id_c * const /* send_network_id */, |
|
1645 const eapol_key_authentication_type_e /* authentication_type */, |
|
1646 const eap_variable_data_c * const /* PMKID */, |
|
1647 const eap_variable_data_c * const /* WPXM_WPXK1 */, |
|
1648 const eap_variable_data_c * const /* WPXM_WPXK2 */) |
|
1649 { |
|
1650 return EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported); |
|
1651 } |
|
1652 |
|
1653 //-------------------------------------------------- |
|
1654 |
|
1655 // |
|
1656 void eapol_am_core_symbian_c::state_notification(const abs_eap_state_notification_c * const state) |
|
1657 { |
|
1658 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1659 |
|
1660 if(state->get_protocol_layer() == eap_protocol_layer_general) |
|
1661 { |
|
1662 if (state->get_current_state() == eap_general_state_authentication_cancelled) |
|
1663 { |
|
1664 // Authentication was cancelled. Cannot continue. |
|
1665 EAP_TRACE_DEBUG( |
|
1666 m_am_tools, |
|
1667 TRACE_FLAGS_DEFAULT, |
|
1668 (EAPL("Authentication was cancelled. Sets timer EAPOL_AM_CORE_TIMER_FAILED_COMPLETELY_ID.\n"))); |
|
1669 |
|
1670 set_timer(this, EAPOL_AM_CORE_TIMER_FAILED_COMPLETELY_ID, 0, 0); |
|
1671 } |
|
1672 else if (state->get_current_state() == eap_general_state_configuration_error) |
|
1673 { |
|
1674 // Configuration error. Cannot continue. |
|
1675 EAP_TRACE_DEBUG( |
|
1676 m_am_tools, |
|
1677 TRACE_FLAGS_DEFAULT, |
|
1678 (EAPL("Configuration error. Sets timer EAPOL_AM_CORE_TIMER_FAILED_COMPLETELY_ID.\n"))); |
|
1679 |
|
1680 set_timer(this, EAPOL_AM_CORE_TIMER_FAILED_COMPLETELY_ID, 0, 0); |
|
1681 } |
|
1682 } |
|
1683 |
|
1684 |
|
1685 if (m_block_packet_sends_and_notifications == true) |
|
1686 { |
|
1687 // Notification block is active. |
|
1688 EAP_TRACE_DEBUG( |
|
1689 m_am_tools, |
|
1690 TRACE_FLAGS_DEFAULT, |
|
1691 (EAPL("state_notification: notification ignored because Disassociated() was called.\n"))); |
|
1692 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1693 return; |
|
1694 } |
|
1695 |
|
1696 |
|
1697 // Check if this is EAP layer notification |
|
1698 if(state->get_protocol_layer() == eap_protocol_layer_eap) |
|
1699 { |
|
1700 switch (state->get_current_state()) |
|
1701 { |
|
1702 case eap_state_none: |
|
1703 break; |
|
1704 case eap_state_identity_request_sent: |
|
1705 // This is for server only so no need to notify WLM. |
|
1706 break; |
|
1707 case eap_state_identity_request_received: |
|
1708 if (m_authentication_indication_sent == false) |
|
1709 { |
|
1710 EAP_TRACE_DEBUG( |
|
1711 m_am_tools, |
|
1712 TRACE_FLAGS_DEFAULT, |
|
1713 (EAPL("Indication sent to WLM: EAuthenticating.\n"))); |
|
1714 m_partner->EapIndication(EAuthenticating); |
|
1715 m_authentication_indication_sent = true; |
|
1716 } |
|
1717 break; |
|
1718 case eap_state_identity_response_received: |
|
1719 // This is for server only so no need to notify WLM. |
|
1720 break; |
|
1721 case eap_state_authentication_finished_successfully: |
|
1722 { |
|
1723 |
|
1724 increment_authentication_counter(); |
|
1725 m_successful_authentications++; |
|
1726 |
|
1727 if (m_wpa_psk_mode_active == false) |
|
1728 { |
|
1729 TEap eap; |
|
1730 eap.Enabled = ETrue; |
|
1731 eap.UID.Num(static_cast<TInt>(state->get_eap_type())); |
|
1732 |
|
1733 // This moves the successful type to be the top priority type in IAP settings. |
|
1734 TRAPD(err, SetToTopPriorityL(&eap)); |
|
1735 if (err != KErrNone) |
|
1736 { |
|
1737 // Just log the error. |
|
1738 EAP_TRACE_DEBUG( |
|
1739 m_am_tools, |
|
1740 TRACE_FLAGS_DEFAULT, |
|
1741 (EAPL("state_notification: SetToTopPriorityL leaved!\n"))); |
|
1742 } |
|
1743 |
|
1744 // Move the active eap type index to the first type |
|
1745 m_eap_index = 0; |
|
1746 } |
|
1747 |
|
1748 |
|
1749 } |
|
1750 break; |
|
1751 case eap_state_authentication_terminated_unsuccessfully: |
|
1752 { |
|
1753 if (m_wpa_psk_mode_active == false) |
|
1754 { |
|
1755 // Set index to next type. |
|
1756 m_eap_index++; |
|
1757 } |
|
1758 |
|
1759 increment_authentication_counter(); |
|
1760 m_failed_authentications++; |
|
1761 |
|
1762 // Restart authentication |
|
1763 eap_am_network_id_c* send_network_id = new eap_am_network_id_c(m_am_tools, state->get_send_network_id()); |
|
1764 if (send_network_id == 0 |
|
1765 || send_network_id->get_is_valid_data() == false) |
|
1766 { |
|
1767 delete send_network_id; |
|
1768 EAP_TRACE_DEBUG( |
|
1769 m_am_tools, |
|
1770 TRACE_FLAGS_DEFAULT, |
|
1771 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
1772 m_partner->EapIndication(EFailedCompletely); |
|
1773 break; |
|
1774 } |
|
1775 set_timer(this, EAPOL_AM_CORE_TIMER_RESTART_AUTHENTICATION_ID, send_network_id, 0); |
|
1776 |
|
1777 } |
|
1778 break; |
|
1779 default: |
|
1780 break; |
|
1781 } |
|
1782 } |
|
1783 else |
|
1784 { |
|
1785 if(state->get_protocol_layer() == eap_protocol_layer_eapol) |
|
1786 { |
|
1787 switch (state->get_current_state()) |
|
1788 { |
|
1789 case eapol_state_no_start_response: |
|
1790 EAP_TRACE_DEBUG( |
|
1791 m_am_tools, |
|
1792 TRACE_FLAGS_DEFAULT, |
|
1793 (EAPL("Indication sent to WLM: ENoResponse.\n"))); |
|
1794 m_partner->EapIndication(ENoResponse); |
|
1795 break; |
|
1796 default: |
|
1797 break; |
|
1798 } |
|
1799 } |
|
1800 else if(state->get_protocol_layer() == eap_protocol_layer_eapol_key) |
|
1801 { |
|
1802 switch (state->get_current_state()) |
|
1803 { |
|
1804 case eapol_key_state_802_11i_authentication_terminated_unsuccessfull: |
|
1805 { |
|
1806 increment_authentication_counter(); |
|
1807 m_failed_authentications++; |
|
1808 |
|
1809 // Consider EAPOL layer failures fatal. |
|
1810 EAP_TRACE_ERROR( |
|
1811 m_am_tools, |
|
1812 TRACE_FLAGS_DEFAULT, |
|
1813 (EAPL("ERROR: Unsuccessful authentication on EAPOL level.\n"))); |
|
1814 EAP_TRACE_DEBUG( |
|
1815 m_am_tools, |
|
1816 TRACE_FLAGS_DEFAULT, |
|
1817 (EAPL("Indication sent to WLM: EThisAPFailed.\n"))); |
|
1818 m_partner->EapIndication(EThisAPFailed); |
|
1819 } |
|
1820 break; |
|
1821 case eapol_key_state_802_11i_authentication_finished_successfull: |
|
1822 { |
|
1823 EAP_TRACE_ALWAYS( |
|
1824 m_am_tools, |
|
1825 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
1826 (EAPL("EAPOL_KEY: %s: Authentication SUCCESS\n"), |
|
1827 (m_is_client == true ? "client": "server"))); |
|
1828 } |
|
1829 break; |
|
1830 default: |
|
1831 break; |
|
1832 } |
|
1833 } |
|
1834 } |
|
1835 |
|
1836 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1837 } |
|
1838 |
|
1839 //-------------------------------------------------- |
|
1840 |
|
1841 // |
|
1842 |
|
1843 eap_status_e eapol_am_core_symbian_c::timer_expired( |
|
1844 const u32_t id, void * /* data */) |
|
1845 { |
|
1846 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1847 EAP_TRACE_DEBUG( |
|
1848 m_am_tools, |
|
1849 TRACE_FLAGS_DEFAULT, |
|
1850 (EAPL("eapol_am_core_symbian_c::TimerExpired id = %d.\n"), |
|
1851 id)); |
|
1852 |
|
1853 switch (id) |
|
1854 { |
|
1855 case EAPOL_AM_CORE_TIMER_RESTART_AUTHENTICATION_ID: |
|
1856 { |
|
1857 EAP_TRACE_DEBUG( |
|
1858 m_am_tools, |
|
1859 TRACE_FLAGS_DEFAULT, |
|
1860 (EAPL("EAPOL_AM_CORE_TIMER_RESTART_AUTHENTICATION_ID elapsed: Stopping stack.\n"))); |
|
1861 |
|
1862 // Stop stack. Do this only if Ethernet core still exists. |
|
1863 if (m_ethernet_core != 0) |
|
1864 { |
|
1865 m_ethernet_core->shutdown(); |
|
1866 delete m_ethernet_core; |
|
1867 m_ethernet_core = 0; |
|
1868 } |
|
1869 if (m_wpa_psk_mode_active == true) |
|
1870 { |
|
1871 // PSK mode active - cannot restart. Just fail. |
|
1872 EAP_TRACE_DEBUG( |
|
1873 m_am_tools, |
|
1874 TRACE_FLAGS_DEFAULT, |
|
1875 (EAPL("WPA PSK mode failed.\n"))); |
|
1876 EAP_TRACE_DEBUG( |
|
1877 m_am_tools, |
|
1878 TRACE_FLAGS_DEFAULT, |
|
1879 (EAPL("Indication sent to WLM: EThisAPFailed.\n"))); |
|
1880 m_partner->EapIndication(EThisAPFailed); |
|
1881 break; |
|
1882 |
|
1883 } |
|
1884 |
|
1885 EAP_TRACE_DEBUG( |
|
1886 m_am_tools, |
|
1887 TRACE_FLAGS_DEFAULT, |
|
1888 (EAPL("Checking if more types.\n"))); |
|
1889 |
|
1890 TInt i; |
|
1891 TEap *eapType = 0; |
|
1892 // Search for more EAP types to try |
|
1893 for (i = m_eap_index; i < m_iap_eap_array.Count(); i++) |
|
1894 { |
|
1895 // Find the next enabled EAP type (highest priority) |
|
1896 eapType = m_iap_eap_array[i]; |
|
1897 if (eapType->Enabled == 1) |
|
1898 { |
|
1899 break; |
|
1900 } |
|
1901 } |
|
1902 // Update index to point to next type to be tried |
|
1903 m_eap_index = i; |
|
1904 |
|
1905 if (i >= m_iap_eap_array.Count()) |
|
1906 { |
|
1907 EAP_TRACE_DEBUG( |
|
1908 m_am_tools, |
|
1909 TRACE_FLAGS_DEFAULT, |
|
1910 (EAPL("No more configured EAP types to try.\n"))); |
|
1911 |
|
1912 // No point in trying to restart authentication because there isn't any more |
|
1913 // EAP types left to try... |
|
1914 EAP_TRACE_DEBUG( |
|
1915 m_am_tools, |
|
1916 TRACE_FLAGS_DEFAULT, |
|
1917 (EAPL("Indication sent to WLM: EThisAPFailed.\n"))); |
|
1918 m_partner->EapIndication(EThisAPFailed); |
|
1919 break; |
|
1920 } |
|
1921 |
|
1922 // Check if authentication mode must be changed |
|
1923 TLex8 tmp(eapType->UID); |
|
1924 TInt type(0); |
|
1925 tmp.Val(type); |
|
1926 |
|
1927 EAP_TRACE_DEBUG( |
|
1928 m_am_tools, |
|
1929 TRACE_FLAGS_DEFAULT, |
|
1930 (EAPL("Found new type to try: %d.\n"), type)); |
|
1931 |
|
1932 switch (type) |
|
1933 { |
|
1934 case eap_type_leap: |
|
1935 m_active_type_is_leap = true; |
|
1936 if (m_802_11_authentication_mode != EAuthModeLeap |
|
1937 && m_security_mode != Wpa |
|
1938 && m_security_mode != Wpa2Only) // In WPA or WPA2 even LEAP uses open authentication |
|
1939 { |
|
1940 // New type is LEAP and the old was something else: |
|
1941 // must reassociate with correct authentication mode. |
|
1942 m_self_disassociated = true; |
|
1943 TInt result = m_partner->Disassociate(); |
|
1944 if (result != KErrNone) |
|
1945 { |
|
1946 // Probably unrecoverable error |
|
1947 EAP_TRACE_DEBUG( |
|
1948 m_am_tools, |
|
1949 TRACE_FLAGS_DEFAULT, |
|
1950 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
1951 m_partner->EapIndication(EFailedCompletely); |
|
1952 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1953 return eap_status_ok; |
|
1954 } |
|
1955 |
|
1956 EAP_TRACE_DEBUG( |
|
1957 m_am_tools, |
|
1958 TRACE_FLAGS_DEFAULT, |
|
1959 (EAPL("TimerExpired: Changing auth type to LEAP.\n"))); |
|
1960 |
|
1961 m_802_11_authentication_mode = EAuthModeLeap; |
|
1962 |
|
1963 m_partner->Associate(EAuthModeLeap); |
|
1964 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1965 return eap_status_ok; |
|
1966 } |
|
1967 break; |
|
1968 default: |
|
1969 m_active_type_is_leap = false; |
|
1970 if (m_802_11_authentication_mode != EAuthModeOpen |
|
1971 && m_security_mode != Wpa |
|
1972 && m_security_mode != Wpa2Only) // In WPA or WPA2 even LEAP uses open authentication) |
|
1973 { |
|
1974 // New type is non-LEAP and the old was LEAP: |
|
1975 // must reassociate with correct authentication mode |
|
1976 m_self_disassociated = true; |
|
1977 TInt result = m_partner->Disassociate(); |
|
1978 if (result != KErrNone) |
|
1979 { |
|
1980 // Probably unrecoverable error |
|
1981 EAP_TRACE_DEBUG( |
|
1982 m_am_tools, |
|
1983 TRACE_FLAGS_DEFAULT, |
|
1984 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
1985 |
|
1986 m_partner->EapIndication(EFailedCompletely); |
|
1987 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
1988 return eap_status_ok; |
|
1989 } |
|
1990 |
|
1991 EAP_TRACE_DEBUG( |
|
1992 m_am_tools, |
|
1993 TRACE_FLAGS_DEFAULT, |
|
1994 (EAPL("TimerExpired: Changing auth type to OPEN.\n"))); |
|
1995 |
|
1996 m_802_11_authentication_mode = EAuthModeOpen; |
|
1997 |
|
1998 m_partner->Associate(EAuthModeOpen); |
|
1999 |
|
2000 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2001 return eap_status_ok; |
|
2002 } |
|
2003 break; |
|
2004 } |
|
2005 |
|
2006 EAP_TRACE_DEBUG( |
|
2007 m_am_tools, |
|
2008 TRACE_FLAGS_DEFAULT, |
|
2009 (EAPL("TimerExpired: No need to change auth type.\n"))); |
|
2010 |
|
2011 if (CompleteAssociation( |
|
2012 KErrNone, |
|
2013 m_local_address, |
|
2014 m_remote_address, |
|
2015 m_received_wpa_ie, |
|
2016 m_received_wpa_ie_length, |
|
2017 m_sent_wpa_ie, |
|
2018 m_sent_wpa_ie_length, |
|
2019 m_group_key_cipher_suite, |
|
2020 m_pairwise_key_cipher_suite) != KErrNone) |
|
2021 { |
|
2022 // Probably unrecoverable error |
|
2023 EAP_TRACE_DEBUG( |
|
2024 m_am_tools, |
|
2025 TRACE_FLAGS_DEFAULT, |
|
2026 (EAPL("Indication sent to WLM: EFailedCompletely.\n"))); |
|
2027 m_partner->EapIndication(EFailedCompletely); |
|
2028 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2029 return eap_status_ok; |
|
2030 } |
|
2031 } |
|
2032 break; |
|
2033 |
|
2034 case EAPOL_AM_CORE_TIMER_DELETE_STACK_ID: |
|
2035 { |
|
2036 EAP_TRACE_DEBUG( |
|
2037 m_am_tools, |
|
2038 TRACE_FLAGS_DEFAULT, |
|
2039 (EAPL("EAPOL_AM_CORE_TIMER_DELETE_STACK_ID elapsed: Delete stack.\n"))); |
|
2040 |
|
2041 cancel_all_timers(); |
|
2042 |
|
2043 // Delete stack |
|
2044 if (m_ethernet_core != 0) |
|
2045 { |
|
2046 m_ethernet_core->shutdown(); |
|
2047 delete m_ethernet_core; |
|
2048 m_ethernet_core = 0; |
|
2049 } |
|
2050 m_stack_marked_to_be_deleted = false; |
|
2051 |
|
2052 // Re-activates timer queue. |
|
2053 eap_status_e status = m_am_tools->re_activate_timer_queue(); |
|
2054 if (status != eap_status_ok) |
|
2055 { |
|
2056 EAP_TRACE_DEBUG( |
|
2057 m_am_tools, |
|
2058 TRACE_FLAGS_DEFAULT, |
|
2059 (EAPL("ERROR: re_activate_timer_queue() failed, status = %d\n"))); |
|
2060 } |
|
2061 } |
|
2062 break; |
|
2063 |
|
2064 case EAPOL_AM_CORE_TIMER_FAILED_COMPLETELY_ID: |
|
2065 { |
|
2066 EAP_TRACE_DEBUG( |
|
2067 m_am_tools, |
|
2068 TRACE_FLAGS_DEFAULT, |
|
2069 (EAPL("EAPOL_AM_CORE_TIMER_FAILED_COMPLETELY_ID elapsed: Indication sent to WLM: EFailedCompletely.\n"))); |
|
2070 |
|
2071 m_partner->EapIndication(EFailedCompletely); |
|
2072 } |
|
2073 break; |
|
2074 |
|
2075 default: |
|
2076 break; |
|
2077 } |
|
2078 return eap_status_ok; |
|
2079 } |
|
2080 |
|
2081 eap_status_e eapol_am_core_symbian_c::timer_delete_data( |
|
2082 const u32_t id, void *data) |
|
2083 { |
|
2084 switch (id) |
|
2085 { |
|
2086 case EAPOL_AM_CORE_TIMER_RESTART_AUTHENTICATION_ID: |
|
2087 { |
|
2088 eap_am_network_id_c* tmp = static_cast<eap_am_network_id_c*>(data); |
|
2089 delete tmp; |
|
2090 } |
|
2091 break; |
|
2092 case EAPOL_AM_CORE_TIMER_DELETE_STACK_ID: |
|
2093 break; |
|
2094 case EAPOL_AM_CORE_TIMER_FAILED_COMPLETELY_ID: |
|
2095 break; |
|
2096 |
|
2097 default: |
|
2098 { |
|
2099 EAP_TRACE_ERROR( |
|
2100 m_am_tools, |
|
2101 TRACE_FLAGS_DEFAULT, |
|
2102 (EAPL("eapol_am_core_symbian_c::timer_delete_data: deleted unknown timer.\n"))); |
|
2103 (void)EAP_STATUS_RETURN(m_am_tools, eap_status_not_supported); |
|
2104 } |
|
2105 } |
|
2106 return eap_status_ok; |
|
2107 } |
|
2108 //-------------------------------------------------- |
|
2109 |
|
2110 // |
|
2111 u32_t eapol_am_core_symbian_c::get_header_offset( |
|
2112 u32_t * const MTU, |
|
2113 u32_t * const trailer_length) |
|
2114 { |
|
2115 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2116 *MTU = KMTU; |
|
2117 *trailer_length = KTrailerLength; |
|
2118 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2119 return KHeaderOffset; |
|
2120 } |
|
2121 |
|
2122 //-------------------------------------------------- |
|
2123 |
|
2124 // |
|
2125 eap_status_e eapol_am_core_symbian_c::unload_module(const eap_type_value_e type) |
|
2126 { |
|
2127 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2128 eap_status_e status(eap_status_type_does_not_exists_error); |
|
2129 TInt index = m_eap_type_array.Find(type); |
|
2130 if (index != KErrNotFound) |
|
2131 { |
|
2132 delete m_plugin_if_array[index]; |
|
2133 m_plugin_if_array.Remove(index); |
|
2134 m_eap_type_array.Remove(index); |
|
2135 status = eap_status_ok; |
|
2136 } |
|
2137 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2138 return EAP_STATUS_RETURN(m_am_tools, status); |
|
2139 } |
|
2140 |
|
2141 //-------------------------------------------------- |
|
2142 |
|
2143 // |
|
2144 eap_status_e eapol_am_core_symbian_c::eap_acknowledge(const eap_am_network_id_c * const receive_network_id) |
|
2145 { |
|
2146 // Any Network Protocol packet is accepted as a success indication. |
|
2147 // This is described in RFC 2284 "PPP Extensible Authentication Protocol (EAP)". |
|
2148 |
|
2149 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2150 |
|
2151 eap_status_e status = m_ethernet_core->eap_acknowledge(receive_network_id); |
|
2152 |
|
2153 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2154 return EAP_STATUS_RETURN(m_am_tools, status); |
|
2155 } |
|
2156 |
|
2157 //-------------------------------------------------- |
|
2158 |
|
2159 // |
|
2160 eap_status_e eapol_am_core_symbian_c::load_module( |
|
2161 const eap_type_value_e type, |
|
2162 const eap_type_value_e tunneling_type, |
|
2163 abs_eap_base_type_c * const partner, |
|
2164 eap_base_type_c ** const eap_type_if, |
|
2165 const bool is_client_when_true, |
|
2166 const eap_am_network_id_c * const receive_network_id) |
|
2167 { |
|
2168 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2169 |
|
2170 EAP_TRACE_DEBUG( |
|
2171 m_am_tools, |
|
2172 TRACE_FLAGS_DEFAULT, |
|
2173 (EAPL("eapol_am_core_symbian_c::load_module(type %d=%s, tunneling_type %d=%s)\n"), |
|
2174 static_cast<TInt>(type), |
|
2175 eap_header_string_c::get_eap_type_string(type), |
|
2176 static_cast<TInt>(tunneling_type), |
|
2177 eap_header_string_c::get_eap_type_string(tunneling_type))); |
|
2178 |
|
2179 eap_status_e status = eap_status_process_general_error; |
|
2180 TBuf8<KMaxEapCueLength> cue; |
|
2181 cue.Num(static_cast<TInt>(convert_eap_type_to_u32_t(type))); |
|
2182 CEapType* eapType = 0; |
|
2183 TInt error(KErrNone); |
|
2184 |
|
2185 // Check if this EAP type has already been loaded |
|
2186 TInt eapArrayIndex = m_eap_type_array.Find(type); |
|
2187 if (eapArrayIndex != KErrNotFound) |
|
2188 { |
|
2189 // Yep. It was loaded already. |
|
2190 eapType = m_plugin_if_array[eapArrayIndex]; |
|
2191 } |
|
2192 else |
|
2193 { |
|
2194 // We must have a trap here since the EAPOL core knows nothing about Symbian. |
|
2195 TRAP(error, (eapType = CEapType::NewL(cue, m_index_type, m_index))); |
|
2196 if (error != KErrNone |
|
2197 || eapType == 0) |
|
2198 { |
|
2199 // Interface not found or implementation creation function failed |
|
2200 EAP_TRACE_DEBUG( |
|
2201 m_am_tools, |
|
2202 TRACE_FLAGS_DEFAULT, |
|
2203 (EAPL("ECom could not find/initiate implementation.\n"))); |
|
2204 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
2205 } |
|
2206 } |
|
2207 // Set the tunneling type |
|
2208 eapType->SetTunnelingType(convert_eap_type_to_u32_t(tunneling_type)); |
|
2209 |
|
2210 // Create the EAP protocol interface implementation. |
|
2211 TRAP(error, (*eap_type_if = eapType->GetStackInterfaceL(m_am_tools, partner, is_client_when_true, receive_network_id))); |
|
2212 |
|
2213 if (error != KErrNone |
|
2214 || *eap_type_if == 0 |
|
2215 || (*eap_type_if)->get_is_valid() == false) |
|
2216 { |
|
2217 EAP_TRACE_DEBUG( |
|
2218 m_am_tools, |
|
2219 TRACE_FLAGS_DEFAULT, |
|
2220 (EAPL("Could not create EAP type interface instance. Error: %d\n"), error)); |
|
2221 |
|
2222 status = eap_status_allocation_error; |
|
2223 // Unload DLL (two ways, depending whether this type was already loaded...) |
|
2224 if (eapArrayIndex == KErrNotFound) |
|
2225 { |
|
2226 // No need to call shutdown here because GetStackInterfaceL has done it. |
|
2227 delete eapType; |
|
2228 } |
|
2229 else |
|
2230 { |
|
2231 unload_module(type); |
|
2232 } |
|
2233 // Note: even in error cases eap_core_c deletes eap_type_if |
|
2234 } |
|
2235 else |
|
2236 { |
|
2237 status = eap_status_ok; |
|
2238 if (eapArrayIndex == KErrNotFound) |
|
2239 { |
|
2240 // Add plugin information to the member arrays. There is no need to store eap_type pointer because |
|
2241 // the stack takes care of its deletion. |
|
2242 if (m_plugin_if_array.Append(eapType) != KErrNone) |
|
2243 { |
|
2244 delete eapType; |
|
2245 status = eap_status_allocation_error; |
|
2246 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2247 return EAP_STATUS_RETURN(m_am_tools, status); |
|
2248 } |
|
2249 if (m_eap_type_array.Append(type) != KErrNone) |
|
2250 { |
|
2251 // Remove the eap type added just previously |
|
2252 m_plugin_if_array.Remove(m_plugin_if_array.Count() - 1); |
|
2253 delete eapType; |
|
2254 status = eap_status_allocation_error; |
|
2255 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2256 return EAP_STATUS_RETURN(m_am_tools, status); |
|
2257 } |
|
2258 } |
|
2259 } |
|
2260 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2261 return EAP_STATUS_RETURN(m_am_tools, status); |
|
2262 } |
|
2263 |
|
2264 //-------------------------------------------------- |
|
2265 |
|
2266 // |
|
2267 TInt eapol_am_core_symbian_c::Disassociated() |
|
2268 { |
|
2269 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2270 |
|
2271 EAP_TRACE_DEBUG( |
|
2272 m_am_tools, |
|
2273 TRACE_FLAGS_DEFAULT, |
|
2274 (EAPL("eapol_am_core_symbian_c::Disassociated()\n"))); |
|
2275 |
|
2276 if (m_self_disassociated == true) |
|
2277 { |
|
2278 // We were expecting this. No need to reset state. |
|
2279 m_self_disassociated = false; |
|
2280 return KErrNone; |
|
2281 } |
|
2282 |
|
2283 EAP_TRACE_DEBUG( |
|
2284 m_am_tools, |
|
2285 TRACE_FLAGS_DEFAULT, |
|
2286 (EAPL("eapol_am_core_symbian_c::Disassociated.\n"))); |
|
2287 |
|
2288 eap_status_e status(eap_status_ok); |
|
2289 |
|
2290 // Set block on. |
|
2291 m_block_packet_sends_and_notifications = true; |
|
2292 |
|
2293 // Reset flags |
|
2294 m_success_indication_sent = false; |
|
2295 m_unicast_wep_key_received = false; |
|
2296 m_broadcast_wep_key_received = false; |
|
2297 m_authentication_indication_sent = false; |
|
2298 |
|
2299 if (m_ethernet_core != 0) |
|
2300 { |
|
2301 EAP_TRACE_DEBUG( |
|
2302 m_am_tools, |
|
2303 TRACE_FLAGS_DEFAULT, |
|
2304 (EAPL("Stack exists. Set EAPOL_AM_CORE_TIMER_DELETE_STACK_ID timer.\n"))); |
|
2305 |
|
2306 m_stack_marked_to_be_deleted = true; |
|
2307 set_timer(this, EAPOL_AM_CORE_TIMER_DELETE_STACK_ID, 0, 0); |
|
2308 } |
|
2309 else |
|
2310 { |
|
2311 EAP_TRACE_DEBUG( |
|
2312 m_am_tools, |
|
2313 TRACE_FLAGS_DEFAULT, |
|
2314 (EAPL("Stack did not exists. EAPOL_AM_CORE_TIMER_DELETE_STACK_ID timer not set.\n"))); |
|
2315 } |
|
2316 |
|
2317 // reset index |
|
2318 m_eap_index = 0; |
|
2319 |
|
2320 |
|
2321 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2322 return m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)); |
|
2323 } |
|
2324 |
|
2325 //-------------------------------------------------- |
|
2326 |
|
2327 // |
|
2328 TInt eapol_am_core_symbian_c::SendWPAMICFailureReport( |
|
2329 TBool aFatalMICFailure, |
|
2330 const TMICFailureType aMICFailureType) |
|
2331 { |
|
2332 EAP_TRACE_ALWAYS( |
|
2333 m_am_tools, |
|
2334 TRACE_FLAGS_ALWAYS|TRACE_FLAGS_DEFAULT, |
|
2335 (EAPL("eapol_am_core_symbian_c::SendWPAMICFailureReport(%d, %d).\n"), |
|
2336 aFatalMICFailure, |
|
2337 aMICFailureType)); |
|
2338 |
|
2339 bool fatal_failure_when_true = true; |
|
2340 |
|
2341 if (!aFatalMICFailure) |
|
2342 { |
|
2343 fatal_failure_when_true = false; |
|
2344 } |
|
2345 |
|
2346 eapol_RSNA_key_header_c::eapol_tkip_mic_failure_type_e tkip_mic_failure_type |
|
2347 = eapol_RSNA_key_header_c::eapol_tkip_mic_failure_type_pairwise_key; |
|
2348 |
|
2349 if (aMICFailureType == EGroupKey) |
|
2350 { |
|
2351 tkip_mic_failure_type |
|
2352 = eapol_RSNA_key_header_c::eapol_tkip_mic_failure_type_group_key; |
|
2353 } |
|
2354 |
|
2355 const eap_status_e status = m_ethernet_core->tkip_mic_failure( |
|
2356 m_receive_network_id, |
|
2357 fatal_failure_when_true, |
|
2358 tkip_mic_failure_type); |
|
2359 |
|
2360 return m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status)); |
|
2361 } |
|
2362 |
|
2363 |
|
2364 //-------------------------------------------------- |
|
2365 |
|
2366 // |
|
2367 void eapol_am_core_symbian_c::ReadEAPSettingsL() |
|
2368 { |
|
2369 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2370 |
|
2371 EAP_TRACE_DEBUG( |
|
2372 m_am_tools, |
|
2373 TRACE_FLAGS_DEFAULT, |
|
2374 (EAPL("eapol_am_core_symbian_c::ReadEAPSettingsL()\n"))); |
|
2375 |
|
2376 eap_status_e status(eap_status_ok); |
|
2377 |
|
2378 // Delete old IAP settings |
|
2379 m_iap_eap_array.ResetAndDestroy(); |
|
2380 if (m_index_type == ELan) |
|
2381 { |
|
2382 EAP_TRACE_DEBUG( |
|
2383 m_am_tools, |
|
2384 TRACE_FLAGS_DEFAULT, |
|
2385 (EAPL("Beginning to read IAP settings - Type: %d, Index: %d.\n"), m_index_type, m_index)); |
|
2386 |
|
2387 CWLanSettings* wlan = new(ELeave) CWLanSettings; |
|
2388 CleanupStack::PushL(wlan); |
|
2389 SWLANSettings wlanSettings; |
|
2390 if (wlan->Connect() != KErrNone) |
|
2391 { |
|
2392 // Could not connect to CommDB |
|
2393 User::Leave(KErrCouldNotConnect); |
|
2394 } |
|
2395 |
|
2396 EAP_TRACE_DEBUG( |
|
2397 m_am_tools, |
|
2398 TRACE_FLAGS_DEFAULT, (EAPL("Connected to CommDbIf.\n"))); |
|
2399 |
|
2400 if (wlan->GetWlanSettingsForService(m_index, wlanSettings) != KErrNone) |
|
2401 { |
|
2402 wlan->Disconnect(); |
|
2403 User::Leave(KErrUnknown); |
|
2404 } |
|
2405 |
|
2406 EAP_TRACE_DEBUG( |
|
2407 m_am_tools, |
|
2408 TRACE_FLAGS_DEFAULT, |
|
2409 (EAPL("Got WLAN settings.\n"))); |
|
2410 |
|
2411 wlan->GetEapDataL(m_iap_eap_array); |
|
2412 |
|
2413 EAP_TRACE_DEBUG( |
|
2414 m_am_tools, |
|
2415 TRACE_FLAGS_DEFAULT, |
|
2416 (EAPL("Got EAP data:\n"))); |
|
2417 |
|
2418 for (TInt i = 0; i < m_iap_eap_array.Count(); i++) |
|
2419 { |
|
2420 EAP_TRACE_DEBUG( |
|
2421 m_am_tools, |
|
2422 TRACE_FLAGS_DEFAULT, |
|
2423 (EAPL("EAP type %d\n"), |
|
2424 i)); |
|
2425 |
|
2426 TLex8 tmp(m_iap_eap_array[i]->UID); |
|
2427 TInt val(0); |
|
2428 tmp.Val(val); |
|
2429 |
|
2430 EAP_TRACE_DEBUG( |
|
2431 m_am_tools, |
|
2432 TRACE_FLAGS_DEFAULT, |
|
2433 (EAPL(" UID: %d\n"), val)); |
|
2434 EAP_TRACE_DEBUG( |
|
2435 m_am_tools, |
|
2436 TRACE_FLAGS_DEFAULT, |
|
2437 (EAPL(" Enabled: %d\n"), |
|
2438 m_iap_eap_array[i]->Enabled)); |
|
2439 } |
|
2440 |
|
2441 EAP_TRACE_DEBUG( |
|
2442 m_am_tools, |
|
2443 TRACE_FLAGS_DEFAULT, |
|
2444 (EAPL("End EAP data:\n"))); |
|
2445 |
|
2446 if (m_iap_eap_array.Count() == 0) |
|
2447 { |
|
2448 // The EAP field was empty. Allow all types. |
|
2449 |
|
2450 EAP_TRACE_DEBUG( |
|
2451 m_am_tools, |
|
2452 TRACE_FLAGS_DEFAULT, |
|
2453 (EAPL("Empty EAP field -> enable all types.\n"))); |
|
2454 |
|
2455 RImplInfoPtrArray eapArray; |
|
2456 |
|
2457 REComSession::ListImplementationsL(KEapTypeInterfaceUid, eapArray); |
|
2458 |
|
2459 TEap *eap; |
|
2460 for (TInt i = 0; i < eapArray.Count(); i++) |
|
2461 { |
|
2462 eap = new(ELeave) TEap; |
|
2463 eap->UID.Copy(eapArray[i]->DataType()); |
|
2464 eap->Enabled = ETrue; |
|
2465 m_iap_eap_array.Append(eap); |
|
2466 } |
|
2467 |
|
2468 eapArray.ResetAndDestroy(); |
|
2469 } |
|
2470 |
|
2471 // Get security mode |
|
2472 if (m_wpa_override_enabled == false) |
|
2473 { |
|
2474 m_security_mode = static_cast<EWlanSecurityMode>(wlanSettings.SecurityMode); |
|
2475 |
|
2476 if (wlanSettings.EnableWpaPsk) |
|
2477 { |
|
2478 m_wpa_psk_mode_allowed = true; |
|
2479 } |
|
2480 else |
|
2481 { |
|
2482 m_wpa_psk_mode_allowed = false; |
|
2483 } |
|
2484 } |
|
2485 else |
|
2486 { |
|
2487 // WPA override is enabled |
|
2488 m_security_mode = Wpa; |
|
2489 if (m_wpa_psk_password_override->get_is_valid_data() == true |
|
2490 && m_wpa_psk_password_override->get_data_length() > 0) |
|
2491 { |
|
2492 m_wpa_psk_mode_allowed = true; |
|
2493 } |
|
2494 else |
|
2495 { |
|
2496 m_wpa_psk_mode_allowed = false; |
|
2497 } |
|
2498 } |
|
2499 |
|
2500 |
|
2501 // Get WPA or WPA2 pre shared key & SSID |
|
2502 if ((m_security_mode == Wlan8021x |
|
2503 || m_security_mode == Wpa |
|
2504 || m_security_mode == Wpa2Only) |
|
2505 && m_wpa_psk_mode_allowed == true |
|
2506 && m_is_client == true) |
|
2507 { |
|
2508 eap_variable_data_c * password = new eap_variable_data_c(m_am_tools); |
|
2509 if (password == 0) |
|
2510 { |
|
2511 wlan->Disconnect(); |
|
2512 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2513 User::Leave(KErrNoMemory); |
|
2514 } |
|
2515 eap_variable_data_c * ssid = new eap_variable_data_c(m_am_tools); |
|
2516 if (ssid == 0) |
|
2517 { |
|
2518 delete password; |
|
2519 wlan->Disconnect(); |
|
2520 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2521 User::Leave(KErrNoMemory); |
|
2522 } |
|
2523 |
|
2524 // When using easy WLAN there might be WPA PSK override |
|
2525 if (m_wpa_psk_password_override->get_is_valid_data() == true |
|
2526 && m_wpa_psk_password_override->get_data_length() > 0) |
|
2527 { |
|
2528 // Use WPA PSK override |
|
2529 status = password->set_copy_of_buffer( |
|
2530 m_wpa_psk_password_override->get_data(m_wpa_psk_password_override->get_data_length()), |
|
2531 m_wpa_psk_password_override->get_data_length()); |
|
2532 if (status != eap_status_ok) |
|
2533 { |
|
2534 delete password; |
|
2535 delete ssid; |
|
2536 wlan->Disconnect(); |
|
2537 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2538 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
2539 } |
|
2540 } |
|
2541 else |
|
2542 { |
|
2543 status = password->set_copy_of_buffer(wlanSettings.WPAPreSharedKey.Ptr(), wlanSettings.WPAPreSharedKey.Size()); |
|
2544 if (status != eap_status_ok) |
|
2545 { |
|
2546 delete password; |
|
2547 delete ssid; |
|
2548 wlan->Disconnect(); |
|
2549 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2550 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
2551 } |
|
2552 } |
|
2553 |
|
2554 TBuf8<KMaxSSIDLength> tmp; |
|
2555 tmp.Copy(wlanSettings.SSID); |
|
2556 status = ssid->set_copy_of_buffer(tmp.Ptr(), tmp.Size()); |
|
2557 if (status != eap_status_ok) |
|
2558 { |
|
2559 delete password; |
|
2560 delete ssid; |
|
2561 wlan->Disconnect(); |
|
2562 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2563 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
2564 } |
|
2565 |
|
2566 crypto_wpa_psk_password_hash_c password_hash(m_am_tools); |
|
2567 |
|
2568 if (ssid->get_data_length() == 0) |
|
2569 { |
|
2570 status = ssid->set_copy_of_buffer(m_ssid); |
|
2571 if (status != eap_status_ok) |
|
2572 { |
|
2573 delete password; |
|
2574 delete ssid; |
|
2575 wlan->Disconnect(); |
|
2576 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2577 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
2578 } |
|
2579 } |
|
2580 |
|
2581 TPSKEntry pskEntry; |
|
2582 |
|
2583 pskEntry.indexType = m_index_type; |
|
2584 pskEntry.index = m_index; |
|
2585 |
|
2586 TPtr8 ssidPtr( |
|
2587 ssid->get_data(ssid->get_data_length()), |
|
2588 ssid->get_data_length(), |
|
2589 ssid->get_data_length() |
|
2590 ); |
|
2591 |
|
2592 TInt err(KErrNone); |
|
2593 |
|
2594 if (m_wpa_psk_password_override->get_is_valid_data() == false |
|
2595 || m_wpa_psk_password_override->get_data_length() == 0) |
|
2596 { |
|
2597 // Retrieve saved PSK only when override is not in effect |
|
2598 TRAP(err, RetrievePSKL(pskEntry)); |
|
2599 } |
|
2600 |
|
2601 if (err != KErrNone |
|
2602 || pskEntry.ssid.Compare(ssidPtr) != 0 |
|
2603 || pskEntry.password.Compare(wlanSettings.WPAPreSharedKey) != 0) |
|
2604 { |
|
2605 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("No previous PSK found...\n"))); |
|
2606 // No previous PSK or parameters were changed. We need to calculate |
|
2607 // PSK again |
|
2608 |
|
2609 status = password_hash.password_hash( |
|
2610 password, |
|
2611 ssid, |
|
2612 m_wpa_preshared_key, |
|
2613 0, |
|
2614 0); |
|
2615 |
|
2616 if (status != eap_status_ok) |
|
2617 { |
|
2618 delete password; |
|
2619 delete ssid; |
|
2620 wlan->Disconnect(); |
|
2621 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2622 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
2623 // return; |
|
2624 } |
|
2625 |
|
2626 if (m_wpa_psk_password_override->get_is_valid_data() == false |
|
2627 || m_wpa_psk_password_override->get_data_length() == 0) |
|
2628 { |
|
2629 // Save new PSK (only if psk override is not in effect) |
|
2630 pskEntry.ssid.Copy(ssidPtr); |
|
2631 |
|
2632 pskEntry.password.Copy(wlanSettings.WPAPreSharedKey); |
|
2633 |
|
2634 pskEntry.psk.Copy( |
|
2635 m_wpa_preshared_key->get_data(m_wpa_preshared_key->get_data_length()), |
|
2636 m_wpa_preshared_key->get_data_length() |
|
2637 ); |
|
2638 |
|
2639 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Saving PSK.\n"))); |
|
2640 SavePSKL(pskEntry); |
|
2641 } |
|
2642 } |
|
2643 else |
|
2644 { |
|
2645 // Copy retrieved psk to member variable |
|
2646 status = m_wpa_preshared_key->set_copy_of_buffer(pskEntry.psk.Ptr(), pskEntry.psk.Size()); |
|
2647 if (status != eap_status_ok) |
|
2648 { |
|
2649 delete password; |
|
2650 delete ssid; |
|
2651 wlan->Disconnect(); |
|
2652 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2653 User::Leave(m_am_tools->convert_eapol_error_to_am_error(EAP_STATUS_RETURN(m_am_tools, status))); |
|
2654 } |
|
2655 } |
|
2656 delete password; |
|
2657 delete ssid; |
|
2658 } |
|
2659 |
|
2660 wlan->Disconnect(); |
|
2661 CleanupStack::PopAndDestroy(wlan); |
|
2662 if (m_security_mode != Wlan8021x |
|
2663 && m_security_mode != Wpa |
|
2664 && m_security_mode != Wpa2Only) |
|
2665 { |
|
2666 // Unsupported mode |
|
2667 User::Leave(KErrNotSupported); |
|
2668 } |
|
2669 } |
|
2670 else |
|
2671 { |
|
2672 // At the moment only LAN bearer is supported. |
|
2673 User::Leave(KErrNotSupported); |
|
2674 } |
|
2675 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2676 } |
|
2677 |
|
2678 //-------------------------------------------------- |
|
2679 |
|
2680 void eapol_am_core_symbian_c::SetToTopPriorityL(const TEap* const aEapType) |
|
2681 { |
|
2682 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2683 |
|
2684 EAP_TRACE_DEBUG( |
|
2685 m_am_tools, |
|
2686 TRACE_FLAGS_DEFAULT, |
|
2687 (EAPL("eapol_am_core_symbian_c::SetToTopPriorityL()\n"))); |
|
2688 |
|
2689 if (m_index_type == ELan) |
|
2690 { |
|
2691 TInt i(0); |
|
2692 TBuf8<3> uid; |
|
2693 for (i = 0; i < m_iap_eap_array.Count(); i++) |
|
2694 { |
|
2695 TEap* eap = m_iap_eap_array[i]; |
|
2696 if (eap->UID[0] == '0') |
|
2697 { |
|
2698 // Cut the leading zero |
|
2699 uid.Copy(eap->UID.Right(eap->UID.Length()-1)); |
|
2700 } |
|
2701 else |
|
2702 { |
|
2703 uid.Copy(eap->UID); |
|
2704 } |
|
2705 if (eap->Enabled == aEapType->Enabled |
|
2706 && uid.Compare(aEapType->UID) == 0) |
|
2707 { |
|
2708 // Found |
|
2709 break; |
|
2710 } |
|
2711 } |
|
2712 if (i >= m_iap_eap_array.Count()) |
|
2713 { |
|
2714 // This should never happen |
|
2715 User::Leave(KErrNotFound); |
|
2716 } |
|
2717 |
|
2718 TLex8 tmp(aEapType->UID); |
|
2719 TInt val(0); |
|
2720 tmp.Val(val); |
|
2721 |
|
2722 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Setting to top priority:\n"))); |
|
2723 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Old index: %d\n"), i)); |
|
2724 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL(" UID: %d\n"), val)); |
|
2725 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL(" Enabled: %d\n"), aEapType->Enabled)); |
|
2726 |
|
2727 if (i == 0) |
|
2728 { |
|
2729 // Already at the highest priority |
|
2730 return; |
|
2731 } |
|
2732 |
|
2733 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Beginning to write IAP EAP settings - Type: %d, Index: %d.\n"), m_index_type, m_index)); |
|
2734 |
|
2735 CWLanSettings* wlan = new(ELeave) CWLanSettings; |
|
2736 CleanupStack::PushL(wlan); |
|
2737 SWLANSettings wlanSettings; |
|
2738 if (wlan->Connect() != KErrNone) |
|
2739 { |
|
2740 // Could not connect to CommDB |
|
2741 User::Leave(KErrCouldNotConnect); |
|
2742 } |
|
2743 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Connected to CommDbIf.\n"))); |
|
2744 if (wlan->GetWlanSettingsForService(m_index, wlanSettings) != KErrNone) |
|
2745 { |
|
2746 wlan->Disconnect(); |
|
2747 User::Leave(KErrUnknown); |
|
2748 } |
|
2749 EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Got WLAN settings.\n"))); |
|
2750 |
|
2751 // Change the order |
|
2752 TEap* eap = m_iap_eap_array[i]; |
|
2753 |
|
2754 m_iap_eap_array.Remove(i); // This does not delete the object |
|
2755 |
|
2756 m_iap_eap_array.Insert(eap, 0); |
|
2757 |
|
2758 wlan->SetEapDataL(m_iap_eap_array); |
|
2759 |
|
2760 wlan->Disconnect(); |
|
2761 |
|
2762 CleanupStack::PopAndDestroy(wlan); |
|
2763 } |
|
2764 else |
|
2765 { |
|
2766 // At the moment only LAN bearer is supported. |
|
2767 User::Leave(KErrNotSupported); |
|
2768 } |
|
2769 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2770 } |
|
2771 |
|
2772 //-------------------------------------------------- |
|
2773 |
|
2774 eap_status_e eapol_am_core_symbian_c::configure() |
|
2775 { |
|
2776 EAP_TRACE_DEBUG( |
|
2777 m_am_tools, |
|
2778 TRACE_FLAGS_DEFAULT, |
|
2779 (EAPL("eapol_am_core_symbian_c::configure()\n"))); |
|
2780 |
|
2781 |
|
2782 //---------------------------------------------------------- |
|
2783 |
|
2784 #if defined(USE_EAP_ERROR_TESTS) |
|
2785 |
|
2786 { |
|
2787 eap_variable_data_c EAP_ERROR_TEST_enable_random_errors(m_am_tools); |
|
2788 |
|
2789 eap_status_e status = read_configure( |
|
2790 cf_str_EAP_ERROR_TEST_enable_random_errors.get_field(), |
|
2791 &EAP_ERROR_TEST_enable_random_errors); |
|
2792 if (status == eap_status_ok |
|
2793 && EAP_ERROR_TEST_enable_random_errors.get_is_valid_data() == true) |
|
2794 { |
|
2795 u32_t *enable_random_errors = reinterpret_cast<u32_t *>( |
|
2796 EAP_ERROR_TEST_enable_random_errors.get_data(sizeof(u32_t)); |
|
2797 if (enable_random_errors != 0 |
|
2798 && *enable_random_errors != 0) |
|
2799 { |
|
2800 m_enable_random_errors = true; |
|
2801 } |
|
2802 } |
|
2803 } |
|
2804 |
|
2805 { |
|
2806 eap_variable_data_c EAP_ERROR_TEST_send_original_packet_first(m_am_tools); |
|
2807 |
|
2808 eap_status_e status = read_configure( |
|
2809 cf_str_EAP_ERROR_TEST_send_original_packet_first.get_field(), |
|
2810 &EAP_ERROR_TEST_send_original_packet_first); |
|
2811 if (status == eap_status_ok |
|
2812 && EAP_ERROR_TEST_send_original_packet_first.get_is_valid_data() == true) |
|
2813 { |
|
2814 u32_t *send_original_packet_first = reinterpret_cast<u32_t *>( |
|
2815 EAP_ERROR_TEST_send_original_packet_first.get_data(sizeof(u32_t)); |
|
2816 if (send_original_packet_first != 0 |
|
2817 && *send_original_packet_first != 0) |
|
2818 { |
|
2819 m_send_original_packet_first = true; |
|
2820 } |
|
2821 } |
|
2822 } |
|
2823 |
|
2824 { |
|
2825 eap_variable_data_c EAP_ERROR_TEST_generate_multiple_error_packets(m_am_tools); |
|
2826 |
|
2827 eap_status_e status = read_configure( |
|
2828 cf_str_EAP_ERROR_TEST_generate_multiple_error_packets.get_field(), |
|
2829 &EAP_ERROR_TEST_generate_multiple_error_packets); |
|
2830 if (status == eap_status_ok |
|
2831 && EAP_ERROR_TEST_generate_multiple_error_packets.get_is_valid_data() == true) |
|
2832 { |
|
2833 u32_t *generate_multiple_error_packets = reinterpret_cast<u32_t *>( |
|
2834 EAP_ERROR_TEST_generate_multiple_error_packets.get_data(sizeof(u32_t)); |
|
2835 if (generate_multiple_error_packets != 0 |
|
2836 && *generate_multiple_error_packets != 0) |
|
2837 { |
|
2838 m_generate_multiple_error_packets = *generate_multiple_error_packets; |
|
2839 } |
|
2840 } |
|
2841 } |
|
2842 |
|
2843 |
|
2844 { |
|
2845 eap_variable_data_c EAP_ERROR_TEST_manipulate_ethernet_header(m_am_tools); |
|
2846 |
|
2847 eap_status_e status = read_configure( |
|
2848 cf_str_EAP_ERROR_TEST_manipulate_ethernet_header.get_field(), |
|
2849 &EAP_ERROR_TEST_manipulate_ethernet_header); |
|
2850 if (status == eap_status_ok |
|
2851 && EAP_ERROR_TEST_manipulate_ethernet_header.get_is_valid_data() == true) |
|
2852 { |
|
2853 u32_t *manipulate_ethernet_header = reinterpret_cast<u32_t *>( |
|
2854 EAP_ERROR_TEST_manipulate_ethernet_header.get_data(sizeof(u32_t)); |
|
2855 if (manipulate_ethernet_header != 0 |
|
2856 && *manipulate_ethernet_header != 0) |
|
2857 { |
|
2858 m_manipulate_ethernet_header = true; |
|
2859 } |
|
2860 } |
|
2861 } |
|
2862 |
|
2863 { |
|
2864 eap_variable_data_c EAP_ERROR_TEST_error_probability(m_am_tools); |
|
2865 |
|
2866 eap_status_e status = read_configure( |
|
2867 cf_str_EAP_ERROR_TEST_error_probability.get_field(), |
|
2868 &EAP_ERROR_TEST_error_probability); |
|
2869 if (status == eap_status_ok |
|
2870 && EAP_ERROR_TEST_error_probability.get_is_valid_data() == true) |
|
2871 { |
|
2872 u32_t *error_probability = reinterpret_cast<u32_t *>( |
|
2873 EAP_ERROR_TEST_error_probability.get_data(sizeof(u32_t)); |
|
2874 if (error_probability != 0) |
|
2875 { |
|
2876 m_error_probability = *error_probability; |
|
2877 } |
|
2878 } |
|
2879 } |
|
2880 |
|
2881 { |
|
2882 eap_variable_data_c EAP_disable_function_traces(m_am_tools); |
|
2883 |
|
2884 eap_status_e status = read_configure( |
|
2885 cf_str_EAP_TRACE_enable_function_traces.get_field(), |
|
2886 &EAP_disable_function_traces); |
|
2887 if (status == eap_status_ok |
|
2888 && EAP_disable_function_traces.get_is_valid_data() == true) |
|
2889 { |
|
2890 u32_t *disable_function_traces = reinterpret_cast<u32_t *>( |
|
2891 EAP_disable_function_traces.get_data(sizeof(u32_t)); |
|
2892 if (disable_function_traces != 0 |
|
2893 && *disable_function_traces != 0) |
|
2894 { |
|
2895 m_am_tools->set_trace_mask( |
|
2896 m_am_tools->get_trace_mask() |
|
2897 | eap_am_tools_c::eap_trace_mask_functions |
|
2898 ); |
|
2899 } |
|
2900 } |
|
2901 } |
|
2902 |
|
2903 #endif //#if defined(USE_EAP_ERROR_TESTS) |
|
2904 |
|
2905 |
|
2906 //---------------------------------------------------------- |
|
2907 |
|
2908 { |
|
2909 eap_variable_data_c EAP_TRACE_disable_traces(m_am_tools); |
|
2910 |
|
2911 eap_status_e status = read_configure( |
|
2912 cf_str_EAP_TRACE_disable_traces.get_field(), |
|
2913 &EAP_TRACE_disable_traces); |
|
2914 if (status == eap_status_ok |
|
2915 && EAP_TRACE_disable_traces.get_is_valid_data() == true) |
|
2916 { |
|
2917 u32_t *disable_traces = reinterpret_cast<u32_t *>( |
|
2918 EAP_TRACE_disable_traces.get_data(sizeof(u32_t))); |
|
2919 if (disable_traces != 0 |
|
2920 && *disable_traces != 0) |
|
2921 { |
|
2922 m_am_tools->set_trace_mask(eap_am_tools_c::eap_trace_mask_none); |
|
2923 } |
|
2924 else |
|
2925 { |
|
2926 // OK, set the default trace mask. |
|
2927 m_am_tools->set_trace_mask( |
|
2928 eap_am_tools_c::eap_trace_mask_debug |
|
2929 | eap_am_tools_c::eap_trace_mask_always |
|
2930 | eap_am_tools_c::eap_trace_mask_error); |
|
2931 } |
|
2932 } |
|
2933 } |
|
2934 |
|
2935 //---------------------------------------------------------- |
|
2936 |
|
2937 { |
|
2938 eap_variable_data_c EAP_TRACE_activate_only_trace_masks_always_and_error(m_am_tools); |
|
2939 |
|
2940 eap_status_e status = read_configure( |
|
2941 cf_str_EAP_TRACE_activate_only_trace_masks_always_and_error.get_field(), |
|
2942 &EAP_TRACE_activate_only_trace_masks_always_and_error); |
|
2943 if (status == eap_status_ok |
|
2944 && EAP_TRACE_activate_only_trace_masks_always_and_error.get_is_valid_data() == true) |
|
2945 { |
|
2946 u32_t *activate_trace_mask_always |
|
2947 = reinterpret_cast<u32_t *>( |
|
2948 EAP_TRACE_activate_only_trace_masks_always_and_error.get_data( |
|
2949 sizeof(u32_t))); |
|
2950 if (activate_trace_mask_always != 0 |
|
2951 && *activate_trace_mask_always != 0) |
|
2952 { |
|
2953 m_am_tools->set_trace_mask( |
|
2954 eap_am_tools_c::eap_trace_mask_always |
|
2955 | eap_am_tools_c::eap_trace_mask_error |
|
2956 ); |
|
2957 } |
|
2958 } |
|
2959 } |
|
2960 |
|
2961 //---------------------------------------------------------- |
|
2962 |
|
2963 { |
|
2964 eap_variable_data_c EAP_TRACE_activate_trace_on_error(m_am_tools); |
|
2965 |
|
2966 eap_status_e status = read_configure( |
|
2967 cf_str_EAP_TRACE_activate_trace_on_error.get_field(), |
|
2968 &EAP_TRACE_activate_trace_on_error); |
|
2969 if (status == eap_status_ok |
|
2970 && EAP_TRACE_activate_trace_on_error.get_is_valid_data() == true) |
|
2971 { |
|
2972 u32_t *activate_trace_on_error = reinterpret_cast<u32_t *>( |
|
2973 EAP_TRACE_activate_trace_on_error.get_data(sizeof(u32_t))); |
|
2974 if (activate_trace_on_error != 0 |
|
2975 && *activate_trace_on_error != 0) |
|
2976 { |
|
2977 m_am_tools->set_activate_trace_on_error(); |
|
2978 } |
|
2979 } |
|
2980 } |
|
2981 |
|
2982 //---------------------------------------------------------- |
|
2983 |
|
2984 // All of the configuration options are optional. |
|
2985 // So we return OK. |
|
2986 return eap_status_ok; |
|
2987 } |
|
2988 |
|
2989 //-------------------------------------------------- |
|
2990 |
|
2991 eap_status_e eapol_am_core_symbian_c::read_configure( |
|
2992 const eap_configuration_field_c * const field, |
|
2993 eap_variable_data_c * const data) |
|
2994 { |
|
2995 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
2996 EAP_ASSERT_ALWAYS(data != NULL); |
|
2997 |
|
2998 // To remove compilation warning in UREL due to KMaxConfigStringLength. |
|
2999 if(field->get_field_length() > KMaxConfigStringLength) |
|
3000 { |
|
3001 return eap_status_process_general_error; |
|
3002 } |
|
3003 |
|
3004 // Trap must be set here because the OS independent portion of EAPOL |
|
3005 // that calls this function does not know anything about Symbian. |
|
3006 eap_status_e status(eap_status_ok); |
|
3007 |
|
3008 // Check if the wanted parameter is default type |
|
3009 |
|
3010 eap_variable_data_c wanted_field(m_am_tools); |
|
3011 eap_variable_data_c type_field(m_am_tools); |
|
3012 eap_variable_data_c type_field_server(m_am_tools); |
|
3013 |
|
3014 status = wanted_field.set_buffer( |
|
3015 field->get_field(), |
|
3016 field->get_field_length(), |
|
3017 false, |
|
3018 false); |
|
3019 if (status != eap_status_ok) |
|
3020 { |
|
3021 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3022 return status; |
|
3023 } |
|
3024 |
|
3025 status = type_field.set_buffer( |
|
3026 cf_str_EAP_default_type_u32_t.get_field()->get_field(), |
|
3027 cf_str_EAP_default_type_u32_t.get_field()->get_field_length(), |
|
3028 false, |
|
3029 false); |
|
3030 if (status != eap_status_ok) |
|
3031 { |
|
3032 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3033 return status; |
|
3034 } |
|
3035 |
|
3036 status = type_field_server.set_buffer( |
|
3037 cf_str_EAP_server_default_type_u32_t.get_field()->get_field(), |
|
3038 cf_str_EAP_server_default_type_u32_t.get_field()->get_field_length(), |
|
3039 false, |
|
3040 false); |
|
3041 if (status != eap_status_ok) |
|
3042 { |
|
3043 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3044 return status; |
|
3045 } |
|
3046 |
|
3047 if (!wanted_field.compare(&type_field) |
|
3048 || !wanted_field.compare(&type_field_server)) |
|
3049 { |
|
3050 TInt i; |
|
3051 // We need to return here the next EAP type we should try |
|
3052 for (i = m_eap_index; i < m_iap_eap_array.Count(); i++) |
|
3053 { |
|
3054 // Find the first enabled EAP type (highest priority) |
|
3055 TEap *eapType = m_iap_eap_array[i]; |
|
3056 if (eapType->Enabled == 1) |
|
3057 { |
|
3058 // Convert the string to integer |
|
3059 TLex8 tmp(eapType->UID); |
|
3060 TInt val(0); |
|
3061 tmp.Val(val); |
|
3062 status = data->set_copy_of_buffer(reinterpret_cast<u8_t *>(&val), sizeof(TUint)); |
|
3063 if (status != eap_status_ok) |
|
3064 { |
|
3065 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3066 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
3067 } |
|
3068 |
|
3069 EAP_TRACE_DEBUG( |
|
3070 m_am_tools, |
|
3071 TRACE_FLAGS_DEFAULT, |
|
3072 (EAPL("EAPOL: Trying EAP type: %d.\n"), val)); |
|
3073 break; |
|
3074 } |
|
3075 } |
|
3076 m_eap_index = i; |
|
3077 if (i >= m_iap_eap_array.Count()) |
|
3078 { |
|
3079 // Not found |
|
3080 // Send WLM notification because there is no way that the authentication |
|
3081 // can be successful if we don't have any EAP types to use... |
|
3082 if (m_is_client) |
|
3083 { |
|
3084 EAP_TRACE_ERROR( |
|
3085 m_am_tools, |
|
3086 TRACE_FLAGS_DEFAULT, |
|
3087 (EAPL("ERROR: No configured EAP types or all tried unsuccessfully.\n"))); |
|
3088 } |
|
3089 |
|
3090 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3091 return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_configure_field); |
|
3092 } |
|
3093 |
|
3094 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3095 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3096 } |
|
3097 |
|
3098 // It was something else than EAP type. Read it from DB. |
|
3099 TRAPD(err, read_configureL( |
|
3100 field->get_field(), |
|
3101 field->get_field_length(), |
|
3102 data)); |
|
3103 if (err != KErrNone) |
|
3104 { |
|
3105 status = m_am_tools->convert_am_error_to_eapol_error(err); |
|
3106 |
|
3107 #if defined(USE_EAP_FILECONFIG) |
|
3108 if (m_fileconfig != 0 |
|
3109 && m_fileconfig->get_is_valid() == true) |
|
3110 { |
|
3111 // Here we could try the final configuration option. |
|
3112 status = m_fileconfig->read_configure( |
|
3113 field, |
|
3114 data); |
|
3115 } |
|
3116 #endif //#if defined(USE_EAP_FILECONFIG) |
|
3117 } |
|
3118 |
|
3119 m_am_tools->trace_configuration( |
|
3120 status, |
|
3121 field, |
|
3122 data); |
|
3123 |
|
3124 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3125 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3126 } |
|
3127 |
|
3128 //-------------------------------------------------- |
|
3129 |
|
3130 void eapol_am_core_symbian_c::read_configureL( |
|
3131 eap_config_string field, |
|
3132 const u32_t /*field_length*/, |
|
3133 eap_variable_data_c * const data) |
|
3134 { |
|
3135 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3136 |
|
3137 // Create a buffer for the ascii strings - initialised with the argument |
|
3138 HBufC8* asciibuf = HBufC8::NewLC(128); |
|
3139 TPtr8 asciiString = asciibuf->Des(); |
|
3140 asciiString.Copy(reinterpret_cast<const unsigned char *>(field)); |
|
3141 |
|
3142 // Buffer for unicode parameter |
|
3143 HBufC* unicodebuf = HBufC::NewLC(128); |
|
3144 TPtr unicodeString = unicodebuf->Des(); |
|
3145 |
|
3146 // Convert to unicode |
|
3147 unicodeString.Copy(asciiString); |
|
3148 |
|
3149 // Now do the database query |
|
3150 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
3151 TPtr sqlStatement = buf->Des(); |
|
3152 _LIT(KSQLQueryRow, "SELECT %S FROM eapol"); |
|
3153 sqlStatement.Format(KSQLQueryRow, &unicodeString); |
|
3154 |
|
3155 RDbView view; |
|
3156 User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
3157 CleanupClosePushL(view); |
|
3158 User::LeaveIfError(view.EvaluateAll()); |
|
3159 if (view.FirstL()) |
|
3160 { |
|
3161 eap_status_e status(eap_status_process_general_error); |
|
3162 view.GetL(); |
|
3163 switch (view.ColType(1)) |
|
3164 { |
|
3165 case EDbColText: |
|
3166 { |
|
3167 unicodeString = view.ColDes(1); |
|
3168 // Convert to 8-bit |
|
3169 asciiString.Copy(unicodeString); |
|
3170 if (asciiString.Size() > 0) |
|
3171 { |
|
3172 status = data->set_copy_of_buffer(asciiString.Ptr(), asciiString.Size()); |
|
3173 if (status != eap_status_ok) |
|
3174 { |
|
3175 User::Leave(KErrNoMemory); |
|
3176 } |
|
3177 } |
|
3178 else |
|
3179 { |
|
3180 // Empty field. Do nothing...data remains invalid |
|
3181 // and the stack knows what to do hopefully. |
|
3182 break; |
|
3183 } |
|
3184 } |
|
3185 break; |
|
3186 case EDbColUint32: |
|
3187 { |
|
3188 TUint value; |
|
3189 value = view.ColUint32(1); |
|
3190 status = data->set_copy_of_buffer((const unsigned char *) &value, sizeof(value)); |
|
3191 if (status != eap_status_ok) |
|
3192 { |
|
3193 User::Leave(KErrNoMemory); |
|
3194 } |
|
3195 } |
|
3196 break; |
|
3197 default: |
|
3198 EAP_TRACE_DEBUG( |
|
3199 m_am_tools, |
|
3200 TRACE_FLAGS_DEFAULT, |
|
3201 (EAPL("read_configureL: Unexpected column type.\n"))); |
|
3202 User::Panic(_L("EAPOL"), 1); |
|
3203 } |
|
3204 } |
|
3205 else |
|
3206 { |
|
3207 // Could not find parameter |
|
3208 EAP_TRACE_DEBUG( |
|
3209 m_am_tools, |
|
3210 TRACE_FLAGS_DEFAULT, |
|
3211 (EAPL("read_configureL: Could not find configuration parameter.\n"))); |
|
3212 User::Leave(KErrNotFound); |
|
3213 } |
|
3214 |
|
3215 // Close database |
|
3216 CleanupStack::PopAndDestroy(4); // session & 3 buffers |
|
3217 |
|
3218 |
|
3219 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3220 } |
|
3221 |
|
3222 //-------------------------------------------------- |
|
3223 |
|
3224 eap_status_e eapol_am_core_symbian_c::write_configure( |
|
3225 const eap_configuration_field_c * const /*field*/, |
|
3226 eap_variable_data_c * const /*data*/) |
|
3227 { |
|
3228 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3229 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3230 return eap_status_not_supported; |
|
3231 } |
|
3232 |
|
3233 //-------------------------------------------------- |
|
3234 |
|
3235 // |
|
3236 eap_status_e eapol_am_core_symbian_c::set_timer( |
|
3237 abs_eap_base_timer_c * const p_initializer, |
|
3238 const u32_t p_id, |
|
3239 void * const p_data, |
|
3240 const u32_t p_time_ms) |
|
3241 { |
|
3242 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3243 |
|
3244 const eap_status_e status = m_am_tools->am_set_timer( |
|
3245 p_initializer, |
|
3246 p_id, |
|
3247 p_data, |
|
3248 p_time_ms); |
|
3249 |
|
3250 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3251 return status; |
|
3252 } |
|
3253 |
|
3254 //-------------------------------------------------- |
|
3255 |
|
3256 // |
|
3257 eap_status_e eapol_am_core_symbian_c::cancel_timer( |
|
3258 abs_eap_base_timer_c * const p_initializer, |
|
3259 const u32_t p_id) |
|
3260 { |
|
3261 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3262 |
|
3263 const eap_status_e status = m_am_tools->am_cancel_timer( |
|
3264 p_initializer, |
|
3265 p_id); |
|
3266 |
|
3267 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3268 return status; |
|
3269 } |
|
3270 |
|
3271 //-------------------------------------------------- |
|
3272 |
|
3273 // |
|
3274 eap_status_e eapol_am_core_symbian_c::cancel_all_timers() |
|
3275 { |
|
3276 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3277 |
|
3278 const eap_status_e status = m_am_tools->am_cancel_all_timers(); |
|
3279 |
|
3280 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3281 return status; |
|
3282 } |
|
3283 |
|
3284 //-------------------------------------------------- |
|
3285 |
|
3286 eap_status_e eapol_am_core_symbian_c::check_is_valid_eap_type(const eap_type_value_e eap_type) |
|
3287 { |
|
3288 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3289 |
|
3290 TEap *eapType = 0; |
|
3291 |
|
3292 eap_status_e status(eap_status_illegal_eap_type); |
|
3293 |
|
3294 for (int i = 0; i < m_iap_eap_array.Count(); i++) |
|
3295 { |
|
3296 // Try next EAP type |
|
3297 eapType = m_iap_eap_array[i]; |
|
3298 if (eapType->Enabled == 1) |
|
3299 { |
|
3300 // Convert the string to integer |
|
3301 TLex8 tmp(eapType->UID); |
|
3302 TInt val(0); |
|
3303 tmp.Val(val); |
|
3304 if (eap_type == static_cast<eap_type_ietf_values_e>(val)) |
|
3305 { |
|
3306 // Allowed |
|
3307 status = eap_status_ok; |
|
3308 break; |
|
3309 } |
|
3310 } |
|
3311 } |
|
3312 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3313 |
|
3314 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3315 } |
|
3316 |
|
3317 //-------------------------------------------------- |
|
3318 |
|
3319 eap_status_e eapol_am_core_symbian_c::get_eap_type_list( |
|
3320 eap_array_c<eap_type_value_e> * const eap_type_list) |
|
3321 { |
|
3322 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3323 |
|
3324 TEap *eapType = 0; |
|
3325 |
|
3326 eap_status_e status(eap_status_illegal_eap_type); |
|
3327 |
|
3328 status = eap_type_list->reset(); |
|
3329 if (status != eap_status_ok) |
|
3330 { |
|
3331 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3332 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3333 } |
|
3334 |
|
3335 for (TInt i = 0; i < m_iap_eap_array.Count(); i++) |
|
3336 { |
|
3337 // Check if type is enabled |
|
3338 eapType = m_iap_eap_array[i]; |
|
3339 if (eapType->Enabled == 1) |
|
3340 { |
|
3341 TLex8 tmp(eapType->UID); |
|
3342 TInt val(0); |
|
3343 tmp.Val(val); |
|
3344 |
|
3345 eap_type_value_e * const eap_type = new eap_type_value_e( |
|
3346 static_cast<eap_type_ietf_values_e>(val)); |
|
3347 if (eap_type == 0) |
|
3348 { |
|
3349 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3350 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
3351 } |
|
3352 |
|
3353 status = eap_type_list->add_object(eap_type, true); |
|
3354 if (status != eap_status_ok) |
|
3355 { |
|
3356 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3357 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3358 } |
|
3359 } |
|
3360 } |
|
3361 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3362 return eap_status_ok; |
|
3363 } |
|
3364 |
|
3365 //-------------------------------------------------- |
|
3366 |
|
3367 void eapol_am_core_symbian_c::TryOpenDatabaseL(RDbNamedDatabase& aDatabase, RDbs& aSession) |
|
3368 { |
|
3369 EAP_TRACE_DEBUG( |
|
3370 m_am_tools, |
|
3371 TRACE_FLAGS_DEFAULT, |
|
3372 (EAPL("eapol_am_core_symbian_c::TryOpenDatabaseL()\n"))); |
|
3373 |
|
3374 // 1. Open/create a database |
|
3375 |
|
3376 // Connect to the DBMS server. |
|
3377 User::LeaveIfError(aSession.Connect()); |
|
3378 CleanupClosePushL(aSession); |
|
3379 // aSession and aDatabase are pushed to the cleanup stack even though they may be member |
|
3380 // variables of the calling class and would be closed in the destructor anyway. This ensures |
|
3381 // that if they are not member variables they will be closed. Closing the handle twice |
|
3382 // does no harm. |
|
3383 |
|
3384 #ifdef SYMBIAN_SECURE_DBMS |
|
3385 |
|
3386 // Create the secure shared database (if necessary) with the specified secure policy. |
|
3387 // Database will be created in the data caging path for DBMS (C:\private\100012a5). |
|
3388 |
|
3389 TInt err = aDatabase.Create(aSession, KDatabaseName, KSecureUIDFormat); |
|
3390 |
|
3391 EAP_TRACE_DEBUG( |
|
3392 m_am_tools, |
|
3393 TRACE_FLAGS_DEFAULT, |
|
3394 (EAPL("TryOpenDatabaseL() - Created Secure DB for eapol.dat. err=%d\n"), err )); |
|
3395 |
|
3396 if(err == KErrNone) |
|
3397 { |
|
3398 aDatabase.Close(); |
|
3399 |
|
3400 } else if (err != KErrAlreadyExists) |
|
3401 { |
|
3402 User::LeaveIfError(err); |
|
3403 } |
|
3404 |
|
3405 User::LeaveIfError(aDatabase.Open(aSession, KDatabaseName, KSecureUIDFormat)); |
|
3406 CleanupClosePushL(aDatabase); |
|
3407 |
|
3408 #else |
|
3409 // For non-secured database. The database will be created in the old location (c:\system\data). |
|
3410 |
|
3411 RFs fsSession; |
|
3412 User::LeaveIfError(fsSession.Connect()); |
|
3413 CleanupClosePushL(fsSession); |
|
3414 |
|
3415 // Create the database (if necessary) |
|
3416 TInt err = aDatabase.Create(fsSession, KDatabaseName); |
|
3417 |
|
3418 EAP_TRACE_DEBUG( |
|
3419 m_am_tools, |
|
3420 TRACE_FLAGS_DEFAULT, |
|
3421 (EAPL("TryOpenDatabaseL() - Created Non-Secure DB for eapol.dat. err=%d\n"), err )); |
|
3422 |
|
3423 if(err == KErrNone) |
|
3424 { |
|
3425 aDatabase.Close(); |
|
3426 |
|
3427 } else if (err != KErrAlreadyExists) |
|
3428 { |
|
3429 User::LeaveIfError(err); |
|
3430 } |
|
3431 CleanupStack::PopAndDestroy(); // close fsSession |
|
3432 |
|
3433 User::LeaveIfError(aDatabase.Open(aSession, KDatabaseName)); |
|
3434 CleanupClosePushL(aDatabase); |
|
3435 |
|
3436 #endif // #ifdef SYMBIAN_SECURE_DBMS |
|
3437 |
|
3438 HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength); |
|
3439 TPtr sqlStatement = buf->Des(); |
|
3440 |
|
3441 // 2. Create the table for pre-shared keys in database (ignore error if exists) |
|
3442 |
|
3443 //// NAME /////////////////////////////////////////////////// TYPE ////////////// Constant /////// |
|
3444 //| ServiceType | UNSIGNED INTEGER | KServiceType |// |
|
3445 //| ServiceIndex | UNSIGNED INTEGER | KServiceIndex |// |
|
3446 //| SSID | VARBINARY(255) | KSSID |// |
|
3447 //| Password | VARBINARY(255) | KPassword |// |
|
3448 //| PSK | VARBINARY(255) | KPSK |// |
|
3449 ////////////////////////////////////////////////////////////////////////////////////////////////// |
|
3450 |
|
3451 _LIT(KSQLCreateTable2, "CREATE TABLE %S (%S UNSIGNED INTEGER, \ |
|
3452 %S UNSIGNED INTEGER, \ |
|
3453 %S VARBINARY(255), \ |
|
3454 %S VARBINARY(255), \ |
|
3455 %S VARBINARY(255))"); |
|
3456 |
|
3457 sqlStatement.Format(KSQLCreateTable2, &KEapolPSKTableName, |
|
3458 &KServiceType, &KServiceIndex, &KSSID, &KPassword, &KPSK); |
|
3459 |
|
3460 err = aDatabase.Execute(sqlStatement); |
|
3461 if (err != KErrNone && err != KErrAlreadyExists) |
|
3462 { |
|
3463 User::Leave(err); |
|
3464 } |
|
3465 |
|
3466 CleanupStack::PopAndDestroy(); // buf |
|
3467 CleanupStack::Pop(2); // database, session |
|
3468 |
|
3469 // If compacting is not done the database will start growing |
|
3470 aDatabase.Compact(); |
|
3471 } |
|
3472 |
|
3473 //-------------------------------------------------- |
|
3474 |
|
3475 void eapol_am_core_symbian_c::OpenDatabaseL(RDbNamedDatabase& aDatabase, RDbs& aSession) |
|
3476 { |
|
3477 EAP_TRACE_DEBUG( |
|
3478 m_am_tools, |
|
3479 TRACE_FLAGS_DEFAULT, |
|
3480 (EAPL("eapol_am_core_symbian_c::OpenDatabaseL()\n"))); |
|
3481 |
|
3482 // Create the database (if necessary) |
|
3483 TRAPD(err, TryOpenDatabaseL(aDatabase, aSession)); |
|
3484 if (err != KErrNone) |
|
3485 { |
|
3486 // Because of error remove the database file. |
|
3487 RFs fsDataBaseFile; |
|
3488 User::LeaveIfError(fsDataBaseFile.Connect()); |
|
3489 CleanupClosePushL(fsDataBaseFile); |
|
3490 err = fsDataBaseFile.Delete(KDatabaseName); |
|
3491 if(err != KErrNone) |
|
3492 { |
|
3493 User::Leave(KErrCorrupt); |
|
3494 } |
|
3495 CleanupStack::PopAndDestroy(); // close fsDataBaseFile |
|
3496 |
|
3497 // Try open database again. This will leave if fails second time. |
|
3498 TryOpenDatabaseL(aDatabase, aSession); |
|
3499 } |
|
3500 } |
|
3501 |
|
3502 //-------------------------------------------------- |
|
3503 |
|
3504 eap_status_e eapol_am_core_symbian_c::random_error( |
|
3505 eap_buf_chain_wr_c * const sent_packet, |
|
3506 const bool forse_error, |
|
3507 const u32_t packet_index) |
|
3508 { |
|
3509 EAP_UNREFERENCED_PARAMETER(packet_index); |
|
3510 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3511 |
|
3512 EAP_TRACE_DEBUG( |
|
3513 m_am_tools, |
|
3514 TRACE_FLAGS_DEFAULT, |
|
3515 (EAPL("eapol_am_core_symbian_c::random_error()\n"))); |
|
3516 |
|
3517 eap_status_e status(eap_status_ok); |
|
3518 u8_t *data = sent_packet->get_data(sent_packet->get_data_length()); |
|
3519 |
|
3520 crypto_random_c rand(m_am_tools); |
|
3521 u32_t random_guard(0); |
|
3522 bool error_generated(false); |
|
3523 u32_t minimum_index(0); |
|
3524 |
|
3525 if (m_manipulate_ethernet_header == false) |
|
3526 { |
|
3527 minimum_index = eapol_ethernet_header_wr_c::get_header_length(); |
|
3528 } |
|
3529 |
|
3530 for (u32_t ind = minimum_index; ind < sent_packet->get_data_length(); ind++) |
|
3531 { |
|
3532 status = rand.get_rand_bytes( |
|
3533 reinterpret_cast<u8_t *>(&random_guard), |
|
3534 sizeof(random_guard)); |
|
3535 if (status != eap_status_ok) |
|
3536 { |
|
3537 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3538 } |
|
3539 |
|
3540 // This is simple limiter to the probability of an error. |
|
3541 // probability = m_error_probability / (2^32) |
|
3542 if (random_guard < m_error_probability) |
|
3543 { |
|
3544 u8_t rnd(0); |
|
3545 u8_t previous_data(0); |
|
3546 // Create an error. |
|
3547 status = rand.get_rand_bytes( |
|
3548 &rnd, |
|
3549 sizeof(rnd)); |
|
3550 if (status != eap_status_ok) |
|
3551 { |
|
3552 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3553 } |
|
3554 |
|
3555 previous_data = data[ind]; |
|
3556 data[ind] ^= rnd; |
|
3557 |
|
3558 if (previous_data != data[ind]) |
|
3559 { |
|
3560 error_generated = true; |
|
3561 sent_packet->set_random_error_type(eap_random_error_type_manipulate_byte); |
|
3562 |
|
3563 EAP_TRACE_DEBUG( |
|
3564 m_am_tools, |
|
3565 TRACE_FLAGS_DEFAULT, |
|
3566 (EAPL("TEST: random_error(): packet_index 0x%08x:%lu, data[0x%04x] changed from 0x%02x to 0x%02x.\n"), |
|
3567 this, |
|
3568 packet_index, |
|
3569 ind, |
|
3570 previous_data, |
|
3571 data[ind])); |
|
3572 } |
|
3573 } |
|
3574 } |
|
3575 |
|
3576 if (error_generated == false |
|
3577 && forse_error == true |
|
3578 && sent_packet->get_data_length() > 0ul) |
|
3579 { |
|
3580 // Generate one error. |
|
3581 |
|
3582 // Random error type. |
|
3583 eap_random_error_type error_type = eap_random_error_type_none_keep_this_last_case; |
|
3584 status = rand.get_rand_bytes( |
|
3585 reinterpret_cast<u8_t *>(&error_type), |
|
3586 sizeof(error_type)); |
|
3587 if (status != eap_status_ok) |
|
3588 { |
|
3589 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3590 } |
|
3591 |
|
3592 error_type = static_cast<eap_random_error_type>( |
|
3593 static_cast<u32_t>(error_type % static_cast<u32_t>( |
|
3594 eap_random_error_type_none_keep_this_last_case))); |
|
3595 |
|
3596 sent_packet->set_random_error_type(error_type); |
|
3597 |
|
3598 switch(error_type) |
|
3599 { |
|
3600 case eap_random_error_type_manipulate_byte: |
|
3601 { |
|
3602 u32_t rnd_index(0); |
|
3603 u8_t previous_data(0); |
|
3604 u32_t index(0); |
|
3605 |
|
3606 do |
|
3607 { |
|
3608 do |
|
3609 { |
|
3610 // Create an error index. |
|
3611 status = rand.get_rand_bytes( |
|
3612 reinterpret_cast<u8_t *>(&rnd_index), |
|
3613 sizeof(rnd_index)); |
|
3614 if (status != eap_status_ok) |
|
3615 { |
|
3616 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3617 } |
|
3618 |
|
3619 index = (rnd_index % (sent_packet->get_data_length() - minimum_index)) |
|
3620 + minimum_index; |
|
3621 } |
|
3622 while(index < minimum_index |
|
3623 || index > sent_packet->get_buffer_length()); |
|
3624 |
|
3625 u8_t rnd(0); |
|
3626 // Create an error. |
|
3627 status = rand.get_rand_bytes( |
|
3628 &rnd, |
|
3629 sizeof(rnd)); |
|
3630 if (status != eap_status_ok) |
|
3631 { |
|
3632 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3633 } |
|
3634 |
|
3635 previous_data = data[index]; |
|
3636 data[index] ^= rnd; |
|
3637 } |
|
3638 while(previous_data == data[index]); |
|
3639 |
|
3640 EAP_TRACE_DEBUG( |
|
3641 m_am_tools, |
|
3642 TRACE_FLAGS_DEFAULT, |
|
3643 (EAPL("TEST: random_error(): packet_index 0x%08x:%lu, data[0x%04x] changed from 0x%02x to 0x%02x.\n"), |
|
3644 this, |
|
3645 packet_index, |
|
3646 index, |
|
3647 previous_data, |
|
3648 data[index])); |
|
3649 |
|
3650 error_generated = true; |
|
3651 } |
|
3652 break; |
|
3653 case eap_random_error_type_change_packet_length_longer: |
|
3654 { |
|
3655 u8_t delta_length(0); |
|
3656 i32_t new_length(0); |
|
3657 |
|
3658 do |
|
3659 { |
|
3660 status = rand.get_rand_bytes( |
|
3661 reinterpret_cast<u8_t *>(&delta_length), |
|
3662 sizeof(delta_length)); |
|
3663 if (status != eap_status_ok) |
|
3664 { |
|
3665 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3666 } |
|
3667 |
|
3668 new_length = static_cast<i32_t>(sent_packet->get_data_length() |
|
3669 + static_cast<i32_t>(delta_length)); |
|
3670 } |
|
3671 while (new_length < static_cast<i32_t>( |
|
3672 eapol_ethernet_header_wr_c::get_header_length()) |
|
3673 || new_length > static_cast<i32_t>(sent_packet->get_buffer_length())); |
|
3674 |
|
3675 EAP_TRACE_DEBUG( |
|
3676 m_am_tools, |
|
3677 TRACE_FLAGS_DEFAULT, |
|
3678 (EAPL("TEST: random_error(): packet_index 0x%08x:%lu, packet length changed from %lu to %lu.\n"), |
|
3679 this, |
|
3680 packet_index, |
|
3681 sent_packet->get_data_length(), |
|
3682 new_length)); |
|
3683 |
|
3684 sent_packet->set_data_length(new_length); |
|
3685 |
|
3686 error_generated = true; |
|
3687 } |
|
3688 break; |
|
3689 case eap_random_error_type_change_packet_length_shorter: |
|
3690 { |
|
3691 u8_t delta_length(0); |
|
3692 i32_t new_length(0); |
|
3693 |
|
3694 do |
|
3695 { |
|
3696 status = rand.get_rand_bytes( |
|
3697 reinterpret_cast<u8_t *>(&delta_length), |
|
3698 sizeof(delta_length)); |
|
3699 if (status != eap_status_ok) |
|
3700 { |
|
3701 return EAP_STATUS_RETURN(m_am_tools, status); |
|
3702 } |
|
3703 |
|
3704 delta_length %= static_cast<i32_t>( |
|
3705 sent_packet->get_data_length() |
|
3706 - static_cast<i32_t>(eapol_ethernet_header_wr_c::get_header_length())); |
|
3707 |
|
3708 if (delta_length == 0) |
|
3709 { |
|
3710 continue; |
|
3711 } |
|
3712 |
|
3713 new_length = static_cast<i32_t>( |
|
3714 sent_packet->get_data_length() - static_cast<i32_t>(delta_length)); |
|
3715 } |
|
3716 while (new_length < static_cast<i32_t>( |
|
3717 eapol_ethernet_header_wr_c::get_header_length()) |
|
3718 || new_length > static_cast<i32_t>(sent_packet->get_buffer_length())); |
|
3719 |
|
3720 EAP_TRACE_DEBUG( |
|
3721 m_am_tools, |
|
3722 TRACE_FLAGS_DEFAULT, |
|
3723 (EAPL("TEST: random_error(): packet_index 0x%08x:%lu, packet length changed from %lu to %lu.\n"), |
|
3724 this, |
|
3725 packet_index, |
|
3726 sent_packet->get_data_length(), |
|
3727 new_length)); |
|
3728 |
|
3729 sent_packet->set_data_length(new_length); |
|
3730 |
|
3731 error_generated = true; |
|
3732 } |
|
3733 break; |
|
3734 default: |
|
3735 User::Panic(_L("EAPOL"), 1); |
|
3736 break; |
|
3737 } |
|
3738 } |
|
3739 |
|
3740 if (error_generated == true) |
|
3741 { |
|
3742 sent_packet->set_is_manipulated(); |
|
3743 } |
|
3744 |
|
3745 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3746 return status; |
|
3747 } |
|
3748 |
|
3749 //-------------------------------------------------- |
|
3750 |
|
3751 eap_status_e eapol_am_core_symbian_c::create_upper_stack() |
|
3752 { |
|
3753 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3754 |
|
3755 EAP_TRACE_DEBUG( |
|
3756 m_am_tools, |
|
3757 TRACE_FLAGS_DEFAULT, |
|
3758 (EAPL("eapol_am_core_symbian_c::create_upper_stack()\n"))); |
|
3759 |
|
3760 eap_status_e status(eap_status_ok); |
|
3761 |
|
3762 if (m_ethernet_core == 0) |
|
3763 { |
|
3764 m_ethernet_core = new ethernet_core_c(m_am_tools, this, m_is_client); |
|
3765 if (m_ethernet_core == 0 |
|
3766 || m_ethernet_core->get_is_valid() != true) |
|
3767 { |
|
3768 if (m_ethernet_core != 0) |
|
3769 { |
|
3770 m_ethernet_core->shutdown(); |
|
3771 delete m_ethernet_core; |
|
3772 m_ethernet_core = 0; |
|
3773 } |
|
3774 EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Stack creation failed.\n"))); |
|
3775 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3776 return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error); |
|
3777 } |
|
3778 |
|
3779 // Initialise upper stack |
|
3780 status = m_ethernet_core->configure(); |
|
3781 |
|
3782 if (status != eap_status_ok) |
|
3783 { |
|
3784 m_ethernet_core->shutdown(); |
|
3785 delete m_ethernet_core; |
|
3786 m_ethernet_core = 0; |
|
3787 |
|
3788 EAP_TRACE_ERROR(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("Stack creation failed.\n"))); |
|
3789 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3790 return EAP_STATUS_RETURN(m_am_tools, eap_status_process_general_error); |
|
3791 } |
|
3792 } |
|
3793 else |
|
3794 { |
|
3795 status = eap_status_already_exists; |
|
3796 } |
|
3797 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3798 return status; |
|
3799 } |
|
3800 |
|
3801 //-------------------------------------------------- |
|
3802 |
|
3803 eap_status_e eapol_am_core_symbian_c::add_rogue_ap( |
|
3804 eap_array_c<eap_rogue_ap_entry_c> & rogue_ap_list) |
|
3805 { |
|
3806 EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3807 |
|
3808 EAP_TRACE_DEBUG( |
|
3809 m_am_tools, |
|
3810 TRACE_FLAGS_DEFAULT, |
|
3811 (EAPL("eapol_am_core_symbian_c::add_rogue_ap()\n"))); |
|
3812 |
|
3813 TInt err(KErrNone); |
|
3814 eap_rogue_ap_entry_c* entry = 0; |
|
3815 |
|
3816 TMacAddress mac; |
|
3817 |
|
3818 TRogueType type; |
|
3819 |
|
3820 for (u32_t i = 0; i < rogue_ap_list.get_object_count(); i++) |
|
3821 { |
|
3822 entry = rogue_ap_list.get_object(i); |
|
3823 |
|
3824 entry->get_mac_address(mac.iMacAddress); |
|
3825 |
|
3826 EAP_TRACE_DEBUG( |
|
3827 m_am_tools, |
|
3828 TRACE_FLAGS_DEFAULT, |
|
3829 (EAPL("Adding rogue AP - type: %d\n"), |
|
3830 entry->get_rogue_reason())); |
|
3831 EAP_TRACE_DATA_DEBUG( |
|
3832 m_am_tools, |
|
3833 TRACE_FLAGS_DEFAULT, |
|
3834 (EAPL("Rogue MAC address"), |
|
3835 mac.iMacAddress, |
|
3836 KMacAddressLength)); |
|
3837 |
|
3838 switch (entry->get_rogue_reason()) |
|
3839 { |
|
3840 case rogue_ap_none: |
|
3841 // Ignore this |
|
3842 continue; |
|
3843 case rogue_ap_association_failed: |
|
3844 type = EInvalidAuthenticationType; |
|
3845 break; |
|
3846 case rogue_ap_timeout: |
|
3847 type = EAuthenticationTimeout; |
|
3848 break; |
|
3849 case rogue_ap_challenge_to_client_failed: |
|
3850 type = EChallengeFromAPFailed; |
|
3851 break; |
|
3852 case rogue_ap_challenge_to_ap_failed: |
|
3853 type = EChallengeToAPFailed; |
|
3854 break; |
|
3855 default: |
|
3856 // ignore others |
|
3857 continue; |
|
3858 } |
|
3859 |
|
3860 err = m_partner->AddRogueAP(mac, type); |
|
3861 if (err != KErrNone) |
|
3862 { |
|
3863 break; |
|
3864 } |
|
3865 } |
|
3866 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
3867 return EAP_STATUS_RETURN(m_am_tools, m_am_tools->convert_am_error_to_eapol_error(err)); |
|
3868 } |
|
3869 |
|
3870 //-------------------------------------------------- |
|
3871 |
|
3872 void eapol_am_core_symbian_c::RetrievePSKL(TPSKEntry& entry) |
|
3873 { |
|
3874 HBufC* sqlbuf = HBufC::NewLC(KMaxSqlQueryLength); |
|
3875 TPtr sqlStatement = sqlbuf->Des(); |
|
3876 |
|
3877 RDbView view; |
|
3878 |
|
3879 _LIT(KSQL, "SELECT %S, %S, %S, %S, %S FROM %S WHERE %S=%d AND %S=%d"); |
|
3880 |
|
3881 sqlStatement.Format(KSQL, &KServiceType, &KServiceIndex, &KSSID, &KPassword, &KPSK, |
|
3882 &KEapolPSKTableName, &KServiceType, entry.indexType, &KServiceIndex, entry.index); |
|
3883 |
|
3884 User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
3885 CleanupClosePushL(view); |
|
3886 User::LeaveIfError(view.EvaluateAll()); |
|
3887 |
|
3888 TInt rows = view.CountL(); |
|
3889 |
|
3890 if (rows == 0) |
|
3891 { |
|
3892 // No saved PSK |
|
3893 User::Leave(KErrNotFound); |
|
3894 } |
|
3895 view.FirstL(); |
|
3896 view.GetL(); |
|
3897 |
|
3898 entry.ssid.Copy(view.ColDes8(3)); |
|
3899 entry.password.Copy(view.ColDes8(4)); |
|
3900 entry.psk.Copy(view.ColDes8(5)); |
|
3901 |
|
3902 CleanupStack::PopAndDestroy(2); // view, buf |
|
3903 } |
|
3904 |
|
3905 //-------------------------------------------------- |
|
3906 |
|
3907 void eapol_am_core_symbian_c::SavePSKL(TPSKEntry& entry) |
|
3908 { |
|
3909 // Connect to CommDBif so that we can delete PSK entries that have no IAP associated anymore. |
|
3910 CWLanSettings* wlan = new(ELeave) CWLanSettings; |
|
3911 CleanupStack::PushL(wlan); |
|
3912 |
|
3913 SWLANSettings wlanSettings; |
|
3914 |
|
3915 if (wlan->Connect() != KErrNone) |
|
3916 { |
|
3917 // Could not connect to CommDB |
|
3918 User::Leave(KErrCouldNotConnect); |
|
3919 } |
|
3920 |
|
3921 HBufC* sqlbuf = HBufC::NewLC(KMaxSqlQueryLength); |
|
3922 TPtr sqlStatement = sqlbuf->Des(); |
|
3923 |
|
3924 RDbView view; |
|
3925 |
|
3926 _LIT(KSQL, "SELECT %S, %S, %S, %S, %S FROM %S"); |
|
3927 |
|
3928 sqlStatement.Format(KSQL, &KServiceType, &KServiceIndex, &KSSID, &KPassword, &KPSK, |
|
3929 &KEapolPSKTableName); |
|
3930 |
|
3931 User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited)); |
|
3932 CleanupClosePushL(view); |
|
3933 User::LeaveIfError(view.EvaluateAll()); |
|
3934 |
|
3935 // Get column set so we get the correct column numbers |
|
3936 CDbColSet* colSet = view.ColSetL(); |
|
3937 CleanupStack::PushL(colSet); |
|
3938 |
|
3939 // Delete old row and also rows that have no associated IAP settings. |
|
3940 if (view.FirstL()) |
|
3941 { |
|
3942 do { |
|
3943 view.GetL(); |
|
3944 |
|
3945 if ((wlan->GetWlanSettingsForService(view.ColUint32(colSet->ColNo(KServiceIndex)), wlanSettings) != KErrNone) |
|
3946 || (view.ColUint32(colSet->ColNo(KServiceType)) == static_cast<TUint>(entry.indexType) |
|
3947 && view.ColUint32(colSet->ColNo(KServiceIndex)) == static_cast<TUint>(entry.index))) |
|
3948 { |
|
3949 // Not found or current IAP |
|
3950 view.DeleteL(); |
|
3951 } |
|
3952 |
|
3953 } while (view.NextL() != EFalse); |
|
3954 } |
|
3955 |
|
3956 wlan->Disconnect(); |
|
3957 |
|
3958 view.InsertL(); |
|
3959 |
|
3960 view.SetColL(colSet->ColNo(KServiceType), (TUint)entry.indexType); |
|
3961 view.SetColL(colSet->ColNo(KServiceIndex), (TUint)entry.index); |
|
3962 view.SetColL(colSet->ColNo(KSSID), entry.ssid); |
|
3963 view.SetColL(colSet->ColNo(KPassword), entry.password); |
|
3964 view.SetColL(colSet->ColNo(KPSK), entry.psk); |
|
3965 |
|
3966 view.PutL(); |
|
3967 |
|
3968 CleanupStack::PopAndDestroy( colSet ); // Delete colSet. |
|
3969 |
|
3970 CleanupStack::PopAndDestroy(3); // CWLanSettings, session, database |
|
3971 |
|
3972 } |
|
3973 |
|
3974 |
|
3975 //-------------------------------------------------- |
|
3976 |
|
3977 |
|
3978 // End of file |