|
1 /* |
|
2 * Copyright (c) 2005-2009 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 doing scans when roaming |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 22 % |
|
20 */ |
|
21 |
|
22 #include "core_sub_operation_roam_scan.h" |
|
23 #include "core_frame_dot11.h" |
|
24 #include "core_server.h" |
|
25 #include "core_tools_parser.h" |
|
26 #include "core_tools.h" |
|
27 #include "am_debug.h" |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 core_sub_operation_roam_scan_c::core_sub_operation_roam_scan_c( |
|
35 u32_t request_id, |
|
36 core_server_c* server, |
|
37 abs_core_driverif_c* drivers, |
|
38 abs_core_server_callback_c* adaptation, |
|
39 const core_ssid_s& scan_ssid, |
|
40 const core_scan_channels_s& scan_channels, |
|
41 bool_t is_connected, |
|
42 bool_t is_first_match_selected ) : |
|
43 core_operation_base_c( core_operation_scan, request_id, server, drivers, adaptation, |
|
44 core_base_flag_drivers_needed ), |
|
45 scan_ssid_m( scan_ssid ), |
|
46 scan_channels_m( scan_channels ), |
|
47 is_connected_m( is_connected ), |
|
48 is_first_match_selected( is_first_match_selected ) |
|
49 { |
|
50 DEBUG( "core_sub_operation_roam_scan_c::core_sub_operation_roam_scan_c()" ); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 core_sub_operation_roam_scan_c::~core_sub_operation_roam_scan_c() |
|
57 { |
|
58 DEBUG( "core_sub_operation_roam_scan_c::~core_sub_operation_roam_scan_c()" ); |
|
59 |
|
60 server_m->unregister_event_handler( this ); |
|
61 server_m->unregister_frame_handler( this ); |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 core_error_e core_sub_operation_roam_scan_c::next_state() |
|
68 { |
|
69 DEBUG( "core_sub_operation_roam_scan_c::next_state()" ); |
|
70 |
|
71 switch ( operation_state_m ) |
|
72 { |
|
73 case core_state_init: |
|
74 { |
|
75 operation_state_m = core_state_scan_start; |
|
76 |
|
77 if ( scan_ssid_m.length ) |
|
78 { |
|
79 DEBUG1S( "core_sub_operation_roam_scan_c::next_state() - requesting a direct scan with SSID ", |
|
80 scan_ssid_m.length, &scan_ssid_m.ssid[0] ); |
|
81 } |
|
82 else |
|
83 { |
|
84 DEBUG( "core_sub_operation_roam_scan_c::next_state() - requesting a broadcast scan" ); |
|
85 } |
|
86 |
|
87 if ( is_connected_m ) |
|
88 { |
|
89 DEBUG( "core_sub_operation_roam_scan_c::next_state() - requesting a split-scan" ); |
|
90 } |
|
91 else |
|
92 { |
|
93 DEBUG( "core_sub_operation_roam_scan_c::next_state() - requesting a regular scan" ); |
|
94 } |
|
95 |
|
96 DEBUG2( "core_sub_operation_roam_scan_c::next_state() - requesting scan on channels 0x%02X%02X", |
|
97 scan_channels_m.channels2dot4ghz[1], |
|
98 scan_channels_m.channels2dot4ghz[0] ); |
|
99 |
|
100 server_m->get_scan_list().remove_entries_by_age( |
|
101 server_m->get_device_settings().scan_list_expiration_time ); |
|
102 |
|
103 server_m->register_event_handler( this ); |
|
104 server_m->register_frame_handler( this ); |
|
105 |
|
106 drivers_m->scan( |
|
107 request_id_m, |
|
108 core_scan_mode_active, |
|
109 scan_ssid_m, |
|
110 server_m->get_device_settings().scan_rate, |
|
111 server_m->get_core_settings().valid_scan_channels( scan_channels_m ), |
|
112 server_m->get_device_settings().active_scan_min_ch_time, |
|
113 server_m->get_device_settings().active_scan_max_ch_time, |
|
114 is_connected_m ); |
|
115 |
|
116 break; |
|
117 } |
|
118 case core_state_scan_start: |
|
119 { |
|
120 operation_state_m = core_state_scan_started; |
|
121 |
|
122 DEBUG( "core_sub_operation_roam_scan_c::next_state() - scan start completed, waiting for scan completion" ); |
|
123 |
|
124 break; |
|
125 } |
|
126 case core_state_scan_stop: |
|
127 { |
|
128 operation_state_m = core_state_scan_stopped; |
|
129 |
|
130 DEBUG( "core_sub_operation_roam_scan_c::next_state() - scan stop completed, waiting for scan completion" ); |
|
131 |
|
132 break; |
|
133 } |
|
134 case core_state_scan_stopped: |
|
135 { |
|
136 DEBUG( "core_sub_operation_roam_scan_c::next_state() - invalid state transition in core_state_scan_stopped" ); |
|
137 ASSERT( false_t ); |
|
138 } |
|
139 case core_state_scan_complete: |
|
140 { |
|
141 server_m->unregister_frame_handler( this ); |
|
142 |
|
143 return core_error_ok; |
|
144 } |
|
145 default: |
|
146 { |
|
147 ASSERT( false_t ); |
|
148 } |
|
149 } |
|
150 |
|
151 return core_error_request_pending; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void core_sub_operation_roam_scan_c::user_cancel( |
|
158 bool_t do_graceful_cancel ) |
|
159 { |
|
160 DEBUG( "core_sub_operation_roam_scan_c::user_cancel()" ); |
|
161 |
|
162 if ( !do_graceful_cancel ) |
|
163 { |
|
164 /** |
|
165 * If we are in a middle of a scan, we have to schedule our own |
|
166 * event. |
|
167 */ |
|
168 if ( operation_state_m == core_state_scan_started ) |
|
169 { |
|
170 asynch_default_user_cancel(); |
|
171 |
|
172 return; |
|
173 } |
|
174 |
|
175 /** |
|
176 * Everything else is handled by the default implementation. |
|
177 */ |
|
178 core_operation_base_c::user_cancel( do_graceful_cancel ); |
|
179 } |
|
180 } |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 bool_t core_sub_operation_roam_scan_c::receive_frame( |
|
186 const core_frame_dot11_c* frame, |
|
187 u8_t rcpi ) |
|
188 { |
|
189 DEBUG( "core_sub_operation_roam_scan_c::receive_frame()" ); |
|
190 |
|
191 if ( frame->type() != core_frame_dot11_c::core_dot11_type_beacon && |
|
192 frame->type() != core_frame_dot11_c::core_dot11_type_probe_resp ) |
|
193 { |
|
194 DEBUG( "core_sub_operation_roam_scan_c::receive_frame() - not a beacon or a probe" ); |
|
195 return false_t; |
|
196 } |
|
197 |
|
198 core_ap_data_c* ap_data = core_ap_data_c::instance( |
|
199 server_m->get_wpx_adaptation_instance(), |
|
200 frame, |
|
201 rcpi, |
|
202 false_t ); |
|
203 if ( ap_data ) |
|
204 { |
|
205 const core_ssid_s ssid( |
|
206 ap_data->ssid() ); |
|
207 |
|
208 #ifdef _DEBUG |
|
209 DEBUG1S( "core_sub_operation_roam_scan_c::receive_frame() - SSID: ", |
|
210 ssid.length, &ssid.ssid[0] ); |
|
211 |
|
212 const core_mac_address_s bssid( |
|
213 ap_data->bssid() ); |
|
214 DEBUG6( "core_sub_operation_roam_scan_c::receive_frame() - BSSID: %02X:%02X:%02X:%02X:%02X:%02X", |
|
215 bssid.addr[0], bssid.addr[1], bssid.addr[2], |
|
216 bssid.addr[3], bssid.addr[4], bssid.addr[5] ); |
|
217 #endif // _DEBUG |
|
218 |
|
219 server_m->get_scan_list().update_entry( *ap_data ); |
|
220 |
|
221 /** |
|
222 * The current implementation assumes that scan is only stopped |
|
223 * in an emergency situation so there's no need to check for |
|
224 * admission control parameters. |
|
225 */ |
|
226 if ( operation_state_m == core_state_scan_started && |
|
227 is_first_match_selected && |
|
228 scan_ssid_m == ssid && |
|
229 core_tools_parser_c::is_ap_suitable( |
|
230 server_m->get_wpx_adaptation_instance(), |
|
231 *ap_data, |
|
232 server_m->get_connection_data()->iap_data(), |
|
233 server_m->get_core_settings(), |
|
234 *server_m->get_connection_data(), |
|
235 server_m->get_device_settings().scan_stop_rcpi_threshold, |
|
236 MEDIUM_TIME_NOT_DEFINED, |
|
237 server_m->is_cm_active(), |
|
238 ZERO_MAC_ADDR ) == core_connect_ok ) |
|
239 { |
|
240 DEBUG( "core_sub_operation_roam_scan_c::receive_frame() - AP is suitable, requesting scan to be stopped" ); |
|
241 |
|
242 operation_state_m = core_state_scan_stop; |
|
243 |
|
244 drivers_m->stop_scan( |
|
245 request_id_m ); |
|
246 } |
|
247 else if ( operation_state_m == core_state_scan_start ) |
|
248 { |
|
249 DEBUG( "core_sub_operation_roam_scan_c::receive_frame() - scan frame received while starting scan" ); |
|
250 } |
|
251 else if ( operation_state_m == core_state_scan_stop ) |
|
252 { |
|
253 DEBUG( "core_sub_operation_roam_scan_c::receive_frame() - scan frame received while stopping scan" ); |
|
254 } |
|
255 else if ( operation_state_m == core_state_scan_stopped ) |
|
256 { |
|
257 DEBUG( "core_sub_operation_roam_scan_c::receive_frame() - scan frame after scan was stopped" ); |
|
258 } |
|
259 |
|
260 delete ap_data; |
|
261 ap_data = NULL; |
|
262 } |
|
263 |
|
264 return true_t; |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 bool_t core_sub_operation_roam_scan_c::notify( |
|
271 core_am_indication_e indication ) |
|
272 { |
|
273 if ( indication == core_am_indication_wlan_scan_complete ) |
|
274 { |
|
275 server_m->unregister_event_handler( this ); |
|
276 |
|
277 if ( operation_state_m == core_state_scan_start ) |
|
278 { |
|
279 DEBUG( "core_sub_operation_roam_scan_c::notify() - scan complete received while starting scan" ); |
|
280 |
|
281 /** |
|
282 * No need to do anything here, state will be changed when the request completes. |
|
283 */ |
|
284 operation_state_m = core_state_scan_complete; |
|
285 } |
|
286 else if ( operation_state_m == core_state_scan_started ) |
|
287 { |
|
288 DEBUG( "core_sub_operation_roam_scan_c::notify() - scan complete" ); |
|
289 |
|
290 asynch_goto( core_state_scan_complete, CORE_TIMER_IMMEDIATELY ); |
|
291 } |
|
292 else if ( operation_state_m == core_state_scan_stop ) |
|
293 { |
|
294 DEBUG( "core_sub_operation_roam_scan_c::notify() - scan complete received while stopping scan" ); |
|
295 |
|
296 /** |
|
297 * No need to do anything here, state will be changed when the request completes. |
|
298 */ |
|
299 operation_state_m = core_state_scan_complete; |
|
300 } |
|
301 else if ( operation_state_m == core_state_scan_stopped ) |
|
302 { |
|
303 DEBUG( "core_sub_operation_roam_scan_c::notify() - scan complete after scan stop completed" ); |
|
304 |
|
305 asynch_goto( core_state_scan_complete, CORE_TIMER_IMMEDIATELY ); |
|
306 } |
|
307 else |
|
308 { |
|
309 DEBUG( "core_sub_operation_roam_scan_c::notify() - scan complete in unknown state" ); |
|
310 ASSERT( false_t ); |
|
311 } |
|
312 |
|
313 return true_t; |
|
314 } |
|
315 |
|
316 return false_t; |
|
317 } |