|
1 /* |
|
2 * Copyright (c) 2006-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 running an echo test. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "core_sub_operation_echo_test.h" |
|
20 #include "core_operation_update_power_mode.h" |
|
21 #include "core_frame_echo_test.h" |
|
22 #include "core_tools.h" |
|
23 #include "core_server.h" |
|
24 #include "am_debug.h" |
|
25 |
|
26 // ======== MEMBER FUNCTIONS ======== |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 core_sub_operation_echo_test_c::core_sub_operation_echo_test_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 const core_ap_data_c& ap_data, |
|
37 u8_t max_retry_count, |
|
38 u32_t timeout, |
|
39 bool_t test_mode ) : |
|
40 core_operation_base_c( core_operation_unspecified, request_id, server, drivers, adaptation, |
|
41 core_base_flag_connection_needed ), |
|
42 current_ap_m( ap_data ), |
|
43 max_retry_count_m( max_retry_count ), |
|
44 retry_count_m( 0 ), |
|
45 timeout_m( timeout ), |
|
46 token_m( 0 ), |
|
47 return_status_m( core_error_ok ), |
|
48 is_unicast_mode_m( test_mode ) |
|
49 { |
|
50 DEBUG( "core_sub_operation_echo_test_c::core_sub_operation_echo_test_c()" ); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 core_sub_operation_echo_test_c::~core_sub_operation_echo_test_c() |
|
57 { |
|
58 DEBUG( "core_sub_operation_echo_test_c::~core_sub_operation_echo_test_c()" ); |
|
59 |
|
60 server_m->unregister_frame_handler( this ); |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 core_error_e core_sub_operation_echo_test_c::next_state() |
|
67 { |
|
68 DEBUG( "core_sub_operation_echo_test_c::next_state()" ); |
|
69 |
|
70 core_frame_echo_test_c* frame = NULL; |
|
71 |
|
72 switch ( operation_state_m ) |
|
73 { |
|
74 case core_state_init: |
|
75 { |
|
76 if ( is_unicast_mode_m ) |
|
77 { |
|
78 frame = core_frame_echo_test_c::instance( |
|
79 server_m->own_mac_addr(), |
|
80 server_m->own_mac_addr(), |
|
81 ++token_m ); |
|
82 } |
|
83 else |
|
84 { |
|
85 frame = core_frame_echo_test_c::instance( |
|
86 BROADCAST_MAC_ADDR, |
|
87 server_m->own_mac_addr(), |
|
88 ++token_m ); |
|
89 } |
|
90 if ( !frame ) |
|
91 { |
|
92 DEBUG( "core_sub_operation_echo_test_c::next_state() - unable to generate a test frame" ); |
|
93 |
|
94 return core_error_no_memory; |
|
95 } |
|
96 |
|
97 if ( is_unicast_mode_m ) |
|
98 { |
|
99 DEBUG( "core_sub_operation_echo_test_c::next_state() - sending a unicast echo test frame:" ); |
|
100 DEBUG_BUFFER( frame->data_length(), frame->data() ); |
|
101 |
|
102 operation_state_m = core_state_echo_frame_unicast_timeout; |
|
103 |
|
104 server_m->register_frame_handler( this ); |
|
105 |
|
106 server_m->send_data_frame( |
|
107 current_ap_m, |
|
108 core_frame_type_test, |
|
109 frame->data_length(), |
|
110 frame->data(), |
|
111 core_access_class_best_effort, |
|
112 server_m->own_mac_addr() ); |
|
113 } |
|
114 else |
|
115 { |
|
116 DEBUG( "core_sub_operation_echo_test_c::next_state() - sending a broadcast echo test frame:" ); |
|
117 DEBUG_BUFFER( frame->data_length(), frame->data() ); |
|
118 |
|
119 operation_state_m = core_state_echo_frame_broadcast_timeout; |
|
120 |
|
121 server_m->register_frame_handler( this ); |
|
122 |
|
123 server_m->send_data_frame( |
|
124 current_ap_m, |
|
125 core_frame_type_test, |
|
126 frame->data_length(), |
|
127 frame->data(), |
|
128 core_access_class_best_effort, |
|
129 BROADCAST_MAC_ADDR ); |
|
130 } |
|
131 |
|
132 delete frame; |
|
133 frame = NULL; |
|
134 |
|
135 /** |
|
136 * Schedule a timeout if no response is received. |
|
137 */ |
|
138 server_m->schedule_operation_timer( |
|
139 timeout_m ); |
|
140 |
|
141 break; |
|
142 } |
|
143 case core_state_echo_frame_broadcast_timeout: |
|
144 { |
|
145 /** |
|
146 * Timeout, no response to broadcast frame was received. |
|
147 */ |
|
148 |
|
149 DEBUG( "core_sub_operation_echo_test_c::next_state() - timeout while waiting for a broadcast frame" ); |
|
150 |
|
151 server_m->unregister_frame_handler( this ); |
|
152 ++retry_count_m; |
|
153 if ( retry_count_m < max_retry_count_m ) |
|
154 { |
|
155 DEBUG1( "core_sub_operation_echo_test_c::next_state() - %u broadcast retries still left, retrying", |
|
156 max_retry_count_m - retry_count_m ); |
|
157 |
|
158 return goto_state( core_state_init ); |
|
159 } |
|
160 else |
|
161 { |
|
162 DEBUG( "core_sub_operation_echo_test_c::next_state() - no broadcast retries left" ); |
|
163 } |
|
164 |
|
165 return core_error_timeout; |
|
166 } |
|
167 case core_state_echo_frame_unicast_timeout: |
|
168 { |
|
169 /** |
|
170 * Timeout, no response to unicast frame was received. |
|
171 */ |
|
172 |
|
173 DEBUG( "core_sub_operation_echo_test_c::next_state() - timeout while waiting for a unicast frame" ); |
|
174 |
|
175 server_m->unregister_frame_handler( this ); |
|
176 ++retry_count_m; |
|
177 if ( retry_count_m < max_retry_count_m ) |
|
178 { |
|
179 DEBUG1( "core_sub_operation_echo_test_c::next_state() - %u unicast retries still left, retrying", |
|
180 max_retry_count_m - retry_count_m ); |
|
181 |
|
182 return goto_state( core_state_init ); |
|
183 } |
|
184 else |
|
185 { |
|
186 DEBUG( "core_sub_operation_echo_test_c::next_state() - no unicast retries left" ); |
|
187 } |
|
188 |
|
189 return core_error_timeout; |
|
190 } |
|
191 case core_state_echo_frame_unicast: |
|
192 { |
|
193 /** |
|
194 * A unicast frame received successfully. |
|
195 */ |
|
196 DEBUG( "core_sub_operation_echo_test_c::next_state() unicast - echo test success" ); |
|
197 |
|
198 return core_error_ok; |
|
199 } |
|
200 case core_state_echo_frame_broadcast: |
|
201 { |
|
202 /** |
|
203 * A broadcast frame received successfully. |
|
204 */ |
|
205 DEBUG( "core_sub_operation_echo_test_c::next_state() broadcast - echo test success" ); |
|
206 |
|
207 return core_error_ok; |
|
208 } |
|
209 default: |
|
210 { |
|
211 ASSERT( false_t ); |
|
212 } |
|
213 } |
|
214 |
|
215 return core_error_request_pending; |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 bool_t core_sub_operation_echo_test_c::receive_test_frame( |
|
222 const core_frame_echo_test_c* frame, |
|
223 u8_t /* rcpi */ ) |
|
224 { |
|
225 DEBUG( "core_sub_operation_echo_test_c::receive_test_frame()" ); |
|
226 |
|
227 if ( frame->token() != token_m ) |
|
228 { |
|
229 DEBUG2( "core_sub_operation_echo_test_c::receive_test_frame() - token doesn't match, received %u, expected %u", |
|
230 frame->token(), token_m ); |
|
231 } |
|
232 |
|
233 if ( operation_state_m == core_state_echo_frame_unicast_timeout && |
|
234 frame->destination() == server_m->own_mac_addr() && |
|
235 frame->source() == server_m->own_mac_addr() ) |
|
236 { |
|
237 DEBUG( "core_sub_operation_echo_test_c::receive_test_frame() - unicast echo test frame received" ); |
|
238 |
|
239 server_m->cancel_operation_timer(); |
|
240 |
|
241 asynch_goto( core_state_echo_frame_unicast, CORE_TIMER_IMMEDIATELY ); |
|
242 } |
|
243 else if ( operation_state_m == core_state_echo_frame_broadcast_timeout && |
|
244 frame->destination() == BROADCAST_MAC_ADDR && |
|
245 frame->source() == server_m->own_mac_addr() ) |
|
246 { |
|
247 DEBUG( "core_sub_operation_echo_test_c::receive_test_frame() - broadcast echo test frame received" ); |
|
248 |
|
249 server_m->cancel_operation_timer(); |
|
250 |
|
251 asynch_goto( core_state_echo_frame_broadcast, CORE_TIMER_IMMEDIATELY ); |
|
252 } |
|
253 else |
|
254 { |
|
255 DEBUG( "core_sub_operation_echo_test_c::receive_test_frame() - unknown echo test frame" ); |
|
256 DEBUG( "core_sub_operation_echo_test_c::receive_test_frame() - destination:" ); |
|
257 DEBUG_MAC( frame->destination().addr ); |
|
258 DEBUG( "core_sub_operation_echo_test_c::receive_test_frame() - source:" ); |
|
259 DEBUG_MAC( frame->source().addr ); |
|
260 DEBUG1( "core_sub_operation_echo_test_c::receive_test_frame() - token: %u", |
|
261 frame->token() ); |
|
262 } |
|
263 |
|
264 return true_t; |
|
265 } |