|
1 /* |
|
2 * Copyright (c) 2005-2010 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: Statemachine for connection release |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 17 % |
|
20 */ |
|
21 |
|
22 #include "core_operation_release.h" |
|
23 #include "core_server.h" |
|
24 #include "am_debug.h" |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 core_operation_release_c::core_operation_release_c( |
|
32 u32_t request_id, |
|
33 core_server_c* server, |
|
34 abs_core_driverif_c* drivers, |
|
35 abs_core_server_callback_c* adaptation, |
|
36 core_release_reason_e reason ) : |
|
37 core_operation_base_c( core_operation_release, request_id, server, drivers, adaptation, |
|
38 core_base_flag_none ), |
|
39 reason_m( reason ) |
|
40 { |
|
41 DEBUG( "core_operation_release_c::core_operation_release_c()" ); |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 core_operation_release_c::~core_operation_release_c() |
|
48 { |
|
49 DEBUG( "core_operation_release_c::~core_operation_release_c()" ); |
|
50 |
|
51 if ( server_m->get_connection_data() ) |
|
52 { |
|
53 DEBUG( "core_operation_release_c::~core_operation_release_c() - marking is_disconnecting as false" ); |
|
54 server_m->get_connection_data()->set_disconnecting( |
|
55 false_t ); |
|
56 } |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 core_error_e core_operation_release_c::next_state() |
|
63 { |
|
64 DEBUG( "core_operation_release_c::next_state()" ); |
|
65 switch( operation_state_m ) |
|
66 { |
|
67 case core_state_init: |
|
68 { |
|
69 DEBUG( "core_operation_release_c::next_state() - core_state_init" ); |
|
70 // ensure state is correct |
|
71 if( server_m->get_core_settings().connection_state() |
|
72 == core_connection_state_notconnected ) |
|
73 { |
|
74 return core_error_not_supported; |
|
75 } |
|
76 |
|
77 DEBUG( "core_operation_release_c::next_state() - marking is_disconnecting as true" ); |
|
78 server_m->get_connection_data()->set_disconnecting( |
|
79 true_t ); |
|
80 |
|
81 server_m->cancel_roam_timer(); |
|
82 server_m->cancel_dhcp_timer(); |
|
83 server_m->get_wpx_adaptation_instance().handle_wpx_connection_stop(); |
|
84 |
|
85 #ifdef _DEBUG |
|
86 switch ( reason_m ) |
|
87 { |
|
88 case core_release_reason_external_request: |
|
89 DEBUG( "core_operation_release_c::next_state() - release due to core_release_reason_external_request" ); |
|
90 break; |
|
91 case core_release_reason_max_roam_attempts_exceeded: |
|
92 DEBUG( "core_operation_release_c::next_state() - release due to core_release_reason_max_roam_attempts_exceeded" ); |
|
93 |
|
94 switch ( server_m->get_connection_data()->last_roam_reason() ) |
|
95 { |
|
96 case core_roam_reason_initial_connect: |
|
97 DEBUG( "core_operation_release_c::next_state() - roam was initiated due to core_roam_reason_initial_connect" ); |
|
98 break; |
|
99 case core_roam_reason_bss_lost: |
|
100 DEBUG( "core_operation_release_c::next_state() - roam was initiated due to core_roam_reason_bss_lost" ); |
|
101 break; |
|
102 case core_roam_reason_media_disconnect: |
|
103 DEBUG( "core_operation_release_c::next_state() - roam was initiated due to core_roam_reason_media_disconnect" ); |
|
104 break; |
|
105 case core_roam_reason_signal_strength: |
|
106 DEBUG( "core_operation_release_c::next_state() - roam was initiated due to core_roam_reason_signal_strength" ); |
|
107 break; |
|
108 case core_roam_reason_signal_loss_prediction: |
|
109 DEBUG( "core_operation_release_c::next_state() - roam was initiated due to core_roam_reason_signal_loss_prediction" ); |
|
110 break; |
|
111 case core_roam_reason_failed_reauthentication: |
|
112 DEBUG( "core_operation_release_c::next_state() - roam was initiated due to core_roam_reason_failed_reauthentication" ); |
|
113 break; |
|
114 default: |
|
115 DEBUG( "core_operation_release_c::next_state() - roam was initiated due to an undefined reason" ); |
|
116 ASSERT( false_t ); |
|
117 } |
|
118 |
|
119 switch ( server_m->get_connection_data()->last_roam_failed_reason() ) |
|
120 { |
|
121 case core_roam_failed_reason_timeout: |
|
122 DEBUG( "core_operation_release_c::next_state() - roam failed due to core_roam_failed_reason_timeout" ); |
|
123 break; |
|
124 case core_roam_failed_reason_no_suitable_ap: |
|
125 DEBUG( "core_operation_release_c::next_state() - roam failed due to core_roam_failed_reason_no_suitable_ap" ); |
|
126 break; |
|
127 case core_roam_failed_reason_ap_status_code: |
|
128 DEBUG( "core_operation_release_c::next_state() - roam failed due to core_roam_failed_reason_ap_status_code" ); |
|
129 break; |
|
130 case core_roam_failed_reason_eapol_failure: |
|
131 DEBUG( "core_operation_release_c::next_state() - roam failed due to core_roam_failed_reason_eapol_failure" ); |
|
132 break; |
|
133 case core_roam_failed_reason_other_failure: |
|
134 DEBUG( "core_operation_release_c::next_state() - roam failed due to core_roam_failed_reason_other_failure" ); |
|
135 break; |
|
136 default: |
|
137 DEBUG( "core_operation_release_c::next_state() - roam failed due to an undefined reason" ); |
|
138 ASSERT( false_t ); |
|
139 } |
|
140 break; |
|
141 case core_release_reason_hw_failure: |
|
142 DEBUG( "core_operation_release_c::next_state() - release due to core_release_reason_hw_failure" ); |
|
143 break; |
|
144 case core_release_reason_tkip_mic_failure: |
|
145 DEBUG( "core_operation_release_c::next_state() - release due to core_release_reason_tkip_mic_failure" ); |
|
146 break; |
|
147 case core_release_reason_other: |
|
148 DEBUG( "core_operation_release_c::next_state() - release due to core_release_reason_other" ); |
|
149 break; |
|
150 default: |
|
151 DEBUG( "core_operation_release_c::next_state() - release due to an undefined reason" ); |
|
152 ASSERT( false_t ); |
|
153 } |
|
154 |
|
155 server_m->get_core_settings().roam_metrics().trace_current_roam_metrics(); |
|
156 #endif // _DEBUG |
|
157 |
|
158 /** |
|
159 * EAPOL must notified about the disassociation. |
|
160 */ |
|
161 if ( ( server_m->get_connection_data()->iap_data().is_eap_used() || |
|
162 server_m->get_connection_data()->iap_data().is_wapi_used() ) && |
|
163 server_m->get_connection_data()->current_ap_data() ) |
|
164 { |
|
165 /*const*/ core_mac_address_s bssid = |
|
166 server_m->get_connection_data()->current_ap_data()->bssid(); |
|
167 |
|
168 network_id_c network( |
|
169 &bssid.addr[0], |
|
170 MAC_ADDR_LEN, |
|
171 &server_m->own_mac_addr().addr[0], |
|
172 MAC_ADDR_LEN, |
|
173 server_m->get_eapol_instance().ethernet_type() ); |
|
174 |
|
175 DEBUG6( "core_operation_release_c::next_state() - EAPOL disassociation from BSSID %02X:%02X:%02X:%02X:%02X:%02X", |
|
176 bssid.addr[0], bssid.addr[1], bssid.addr[2], |
|
177 bssid.addr[3], bssid.addr[4], bssid.addr[5] ); |
|
178 |
|
179 server_m->get_eapol_instance().disassociation( &network ); |
|
180 } |
|
181 |
|
182 // disable user data |
|
183 drivers_m->disable_user_data( request_id_m ); |
|
184 operation_state_m = core_state_disable_user_data; |
|
185 break; |
|
186 } |
|
187 case core_state_disable_user_data: |
|
188 { |
|
189 DEBUG( "core_operation_release_c::next_state() - core_state_disable_user_data" ); |
|
190 drivers_m->set_tx_power_level( |
|
191 request_id_m, |
|
192 server_m->get_device_settings().tx_power_level ); |
|
193 operation_state_m = core_state_tx_power_level; |
|
194 break; |
|
195 } |
|
196 case core_state_tx_power_level: |
|
197 { |
|
198 DEBUG( "core_operation_release_c::next_state() - core_state_tx_power_level" ); |
|
199 |
|
200 u32_t tx_level = server_m->get_device_settings().tx_power_level; |
|
201 |
|
202 if ( server_m->get_connection_data()->last_tx_level() != tx_level ) |
|
203 { |
|
204 DEBUG( "core_operation_release_c::next_state() - TX level has changed, notifying change" ); |
|
205 |
|
206 adaptation_m->notify( |
|
207 core_notification_tx_power_level_changed, |
|
208 sizeof( tx_level ), |
|
209 reinterpret_cast<u8_t*>( &tx_level ) ); |
|
210 |
|
211 server_m->get_connection_data()->set_last_tx_level( tx_level ); |
|
212 } |
|
213 |
|
214 drivers_m->disconnect( request_id_m ); |
|
215 operation_state_m = core_state_disconnect; |
|
216 break; |
|
217 } |
|
218 case core_state_disconnect: |
|
219 { |
|
220 DEBUG( "core_operation_release_c::next_state() - core_state_disconnect" ); |
|
221 |
|
222 // notify adaptation |
|
223 core_connection_state_e state = core_connection_state_notconnected; |
|
224 server_m->get_core_settings().set_connection_state( state ); |
|
225 |
|
226 if ( server_m->get_connection_data()->last_connection_state() != state ) |
|
227 { |
|
228 u8_t buf[5]; |
|
229 buf[0] = static_cast<u8_t>( state ); |
|
230 buf[1] = static_cast<u8_t>( reason_m ); |
|
231 buf[2] = 0; |
|
232 buf[3] = 0; |
|
233 if ( reason_m == core_release_reason_max_roam_attempts_exceeded ) |
|
234 { |
|
235 buf[2] = static_cast<u8_t>( |
|
236 server_m->get_connection_data()->last_roam_reason() ); |
|
237 buf[3] = static_cast<u8_t>( |
|
238 server_m->get_connection_data()->last_roam_failed_reason() ); |
|
239 } |
|
240 |
|
241 adaptation_m->notify( |
|
242 core_notification_connection_state_changed, |
|
243 sizeof( buf ), |
|
244 buf ); |
|
245 |
|
246 server_m->get_connection_data()->set_last_connection_state( |
|
247 state ); |
|
248 } |
|
249 |
|
250 // destroy connection data |
|
251 server_m->clear_connection_data(); |
|
252 |
|
253 // Cancel any operations that depend on an active connection. |
|
254 server_m->cancel_operations_with_flags( |
|
255 core_operation_base_c::core_base_flag_connection_needed ); |
|
256 |
|
257 return core_error_ok; |
|
258 } |
|
259 default: |
|
260 { |
|
261 ASSERT( false_t ); |
|
262 } |
|
263 } |
|
264 return core_error_request_pending; |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 void core_operation_release_c::user_cancel( |
|
271 bool_t do_graceful_cancel ) |
|
272 { |
|
273 DEBUG( "core_operation_release_c::user_cancel()" ); |
|
274 |
|
275 if ( !do_graceful_cancel ) |
|
276 { |
|
277 core_operation_base_c::user_cancel( do_graceful_cancel ); |
|
278 return; |
|
279 } |
|
280 |
|
281 /** |
|
282 * On graceful cancel this operation must be executed completely |
|
283 * to guarantee disconnect. Therefore user_cancel() is ignored. |
|
284 */ |
|
285 } |