|
1 /* |
|
2 * Copyright (c) 2006-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: Timer for handling WPA TKIP counter measures |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "core_timer_factory.h" |
|
20 #include "core_timer_counter_measures.h" |
|
21 #include "core_callback.h" |
|
22 #include "am_debug.h" |
|
23 |
|
24 /** Wait time for the next secure connection failure (60 sec). */ |
|
25 const uint_t CORE_CM_FAIL_WAIT_TIME = 60000000; |
|
26 |
|
27 /** Blocking time for WPA connections (60 sec). */ |
|
28 const uint_t CORE_CM_BLOCKING_TIME = 60000000; |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // --------------------------------------------------------------------------- |
|
34 core_timer_counter_measures_c::core_timer_counter_measures_c() : |
|
35 state_m( core_state_not_running ), |
|
36 timer_m( NULL ) |
|
37 { |
|
38 DEBUG( "core_timer_counter_measures_c::core_timer_counter_measures_c()" ); |
|
39 |
|
40 core_callback_c* timer_callback = |
|
41 new core_callback_c( &(core_timer_counter_measures_c::timer_expired), this ); |
|
42 if( !timer_callback ) |
|
43 { |
|
44 DEBUG( "core_timer_counter_measures_c::core_timer_counter_measures_c() - unable to create callbacks" ); |
|
45 } |
|
46 |
|
47 timer_m = core_timer_factory_c::create_timer( timer_callback ); |
|
48 if( !timer_m ) |
|
49 { |
|
50 delete timer_callback; |
|
51 DEBUG( "core_timer_counter_measures_c::core_timer_counter_measures_c() - unable to create timer" ); |
|
52 } |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // --------------------------------------------------------------------------- |
|
57 core_timer_counter_measures_c::~core_timer_counter_measures_c() |
|
58 { |
|
59 DEBUG( "core_timer_counter_measures_c::~core_timer_counter_measures_c()" ); |
|
60 |
|
61 if ( timer_m ) |
|
62 { |
|
63 timer_m->stop(); |
|
64 core_timer_factory_c::destroy_timer( timer_m ); |
|
65 } |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 bool_t core_timer_counter_measures_c::is_wpa_allowed() |
|
72 { |
|
73 return ( state_m != core_state_blocked ); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void core_timer_counter_measures_c::mic_failure() |
|
80 { |
|
81 DEBUG( "core_timer_counter_measures_c::mic_failure()" ); |
|
82 |
|
83 switch ( state_m ) |
|
84 { |
|
85 case core_state_not_running: |
|
86 DEBUG( "core_timer_counter_measures_c::mic_failure() - new state is core_state_activated" ); |
|
87 state_m = core_state_activated; |
|
88 if ( timer_m ) |
|
89 { |
|
90 timer_m->start( CORE_CM_FAIL_WAIT_TIME ); |
|
91 } |
|
92 break; |
|
93 case core_state_activated: |
|
94 DEBUG( "core_timer_counter_measures_c::mic_failure() - new state is core_state_blocked" ); |
|
95 state_m = core_state_blocked; |
|
96 if ( timer_m ) |
|
97 { |
|
98 timer_m->stop(); |
|
99 timer_m->start( CORE_CM_BLOCKING_TIME ); |
|
100 } |
|
101 break; |
|
102 default: |
|
103 DEBUG( "core_timer_counter_measures_c::mic_failure() - indication in wrong state" ); |
|
104 ASSERT( false_t ); |
|
105 break; |
|
106 } |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 void core_timer_counter_measures_c::timer_expired( |
|
113 void* this_ptr ) |
|
114 { |
|
115 DEBUG( "core_timer_counter_measures_c::timer_expired()" ); |
|
116 |
|
117 core_timer_counter_measures_c* self = |
|
118 static_cast<core_timer_counter_measures_c*>( this_ptr ); |
|
119 |
|
120 switch ( self->state_m ) |
|
121 { |
|
122 case core_state_activated: |
|
123 /** Falls through on purpose. */ |
|
124 case core_state_blocked: |
|
125 DEBUG( "core_timer_counter_measures_c::timer_expired() - new state is core_state_not_running" ); |
|
126 self->state_m = core_state_not_running; |
|
127 break; |
|
128 default: |
|
129 DEBUG( "core_timer_counter_measures_c::timer_expired() - expiration in wrong state" ); |
|
130 ASSERT( false_t ); |
|
131 break; |
|
132 } |
|
133 } |