|
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 591 |
|
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 #if defined(USE_EAP_SIMPLE_CONFIG) |
|
29 |
|
30 |
|
31 #include "eap_am_memory.h" |
|
32 #include "eap_type_simple_config_header.h" |
|
33 #include "eap_header_string.h" |
|
34 |
|
35 |
|
36 /** @file */ |
|
37 |
|
38 //-------------------------------------------------- |
|
39 |
|
40 EAP_FUNC_EXPORT eap_simple_config_header_c::~eap_simple_config_header_c() |
|
41 { |
|
42 } |
|
43 |
|
44 //-------------------------------------------------- |
|
45 |
|
46 // |
|
47 EAP_FUNC_EXPORT eap_simple_config_header_c::eap_simple_config_header_c( |
|
48 abs_eap_am_tools_c * const tools, |
|
49 u8_t * const header_begin, |
|
50 const u32_t header_buffer_length) |
|
51 : eap_header_base_c(tools, header_begin, header_buffer_length) |
|
52 , m_am_tools(tools) |
|
53 { |
|
54 } |
|
55 |
|
56 //-------------------------------------------------- |
|
57 |
|
58 EAP_FUNC_EXPORT eap_code_value_e eap_simple_config_header_c::get_eap_code() const |
|
59 { |
|
60 return eap_header_base_c::get_code(); |
|
61 } |
|
62 |
|
63 //-------------------------------------------------- |
|
64 |
|
65 EAP_FUNC_EXPORT u8_t eap_simple_config_header_c::get_eap_identifier() const |
|
66 { |
|
67 return eap_header_base_c::get_identifier(); |
|
68 } |
|
69 |
|
70 //-------------------------------------------------- |
|
71 |
|
72 EAP_FUNC_EXPORT u16_t eap_simple_config_header_c::get_eap_length() const |
|
73 { |
|
74 return eap_header_base_c::get_length(); |
|
75 } |
|
76 |
|
77 //-------------------------------------------------- |
|
78 |
|
79 EAP_FUNC_EXPORT eap_type_value_e eap_simple_config_header_c::get_eap_type() const |
|
80 { |
|
81 return eap_header_base_c::get_type(); |
|
82 } |
|
83 |
|
84 //-------------------------------------------------- |
|
85 |
|
86 EAP_FUNC_EXPORT u32_t eap_simple_config_header_c::get_sc_op_code_offset() const |
|
87 { |
|
88 return eap_header_base_c::get_header_length() + eap_header_base_c::get_type_field_length() + m_op_code_delta_offset; |
|
89 } |
|
90 |
|
91 //-------------------------------------------------- |
|
92 |
|
93 EAP_FUNC_EXPORT u32_t eap_simple_config_header_c::get_sc_flags_offset() const |
|
94 { |
|
95 return eap_header_base_c::get_header_length() + eap_header_base_c::get_type_field_length() + m_flag_delta_offset; |
|
96 } |
|
97 |
|
98 //-------------------------------------------------- |
|
99 |
|
100 EAP_FUNC_EXPORT u32_t eap_simple_config_header_c::get_sc_length_offset() const |
|
101 { |
|
102 return eap_header_base_c::get_header_length() + eap_header_base_c::get_type_field_length() + m_data_or_message_length_delta_offset; |
|
103 } |
|
104 |
|
105 //-------------------------------------------------- |
|
106 |
|
107 EAP_FUNC_EXPORT eap_simple_config_header_c::op_code_e eap_simple_config_header_c::get_sc_op_code() const |
|
108 { |
|
109 u32_t op_code_offset(get_sc_op_code_offset()); |
|
110 |
|
111 u8_t * const op_code = get_header_offset(op_code_offset, sizeof(u8_t)); |
|
112 if (op_code != 0) |
|
113 { |
|
114 return static_cast<eap_simple_config_header_c::op_code_e>(*op_code); |
|
115 } |
|
116 else |
|
117 { |
|
118 return eap_simple_config_header_c::op_code_none; |
|
119 } |
|
120 } |
|
121 |
|
122 //-------------------------------------------------- |
|
123 |
|
124 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_sc_op_code(const eap_simple_config_header_c::op_code_e op_code) |
|
125 { |
|
126 u32_t op_code_offset(get_sc_op_code_offset()); |
|
127 |
|
128 u8_t * const p_op_code = get_header_offset(op_code_offset, sizeof(u8_t)); |
|
129 if (p_op_code != 0) |
|
130 { |
|
131 *p_op_code = static_cast<u8_t>(op_code); |
|
132 } |
|
133 else |
|
134 { |
|
135 EAP_ASSERT(p_op_code != 0); |
|
136 } |
|
137 } |
|
138 |
|
139 //-------------------------------------------------- |
|
140 |
|
141 EAP_FUNC_EXPORT u16_t eap_simple_config_header_c::get_data_length() const |
|
142 { |
|
143 if (get_flag_simple_config_length_included() == true |
|
144 && get_eap_length() > static_cast<u16_t>(get_header_length())) |
|
145 { |
|
146 return static_cast<u16_t>(get_eap_length()-static_cast<u16_t>(get_header_length())); |
|
147 } |
|
148 else if (get_flag_simple_config_length_included() == false |
|
149 && get_eap_length() > static_cast<u16_t>(get_header_length())) |
|
150 { |
|
151 return static_cast<u16_t>(get_eap_length()-static_cast<u16_t>(get_header_length())); |
|
152 } |
|
153 else |
|
154 { |
|
155 return 0; |
|
156 } |
|
157 } |
|
158 |
|
159 //-------------------------------------------------- |
|
160 |
|
161 EAP_FUNC_EXPORT u32_t eap_simple_config_header_c::get_simple_config_min_header_length() const |
|
162 { |
|
163 return eap_header_base_c::get_header_length() |
|
164 + eap_header_base_c::get_type_field_length() |
|
165 + m_data_or_message_length_delta_offset; |
|
166 } |
|
167 |
|
168 //-------------------------------------------------- |
|
169 |
|
170 EAP_FUNC_EXPORT u32_t eap_simple_config_header_c::get_simple_config_max_header_length() |
|
171 { |
|
172 return eap_header_base_c::get_header_length() |
|
173 + eap_header_base_c::get_expanded_type_field_length() |
|
174 + m_data_or_message_length_delta_offset |
|
175 + SIMPLE_CONFIG_MESSAGE_LENGTH_FIELD_SIZE; |
|
176 } |
|
177 |
|
178 //-------------------------------------------------- |
|
179 |
|
180 EAP_FUNC_EXPORT u32_t eap_simple_config_header_c::get_header_length() const |
|
181 { |
|
182 u32_t length = get_simple_config_min_header_length(); |
|
183 |
|
184 if (get_flag_simple_config_length_included() == true) |
|
185 { |
|
186 return length+SIMPLE_CONFIG_MESSAGE_LENGTH_FIELD_SIZE; |
|
187 } |
|
188 else |
|
189 { |
|
190 return length; |
|
191 } |
|
192 } |
|
193 |
|
194 //-------------------------------------------------- |
|
195 |
|
196 EAP_FUNC_EXPORT u32_t eap_simple_config_header_c::get_start_offset_of_data() const |
|
197 { |
|
198 return get_header_length(); |
|
199 } |
|
200 |
|
201 //-------------------------------------------------- |
|
202 |
|
203 EAP_FUNC_EXPORT u8_t * eap_simple_config_header_c::get_data_offset( |
|
204 abs_eap_am_tools_c * const m_am_tools, |
|
205 const u32_t offset, |
|
206 const u32_t contignuous_bytes) const |
|
207 { |
|
208 EAP_UNREFERENCED_PARAMETER(m_am_tools); |
|
209 |
|
210 u32_t data_length = get_data_length(); // Here is removed optional SIMPLE_CONFIG message length. |
|
211 |
|
212 if (data_length >= offset+contignuous_bytes) |
|
213 { |
|
214 // get_header_length() handles optional SIMPLE_CONFIG message length field. |
|
215 u32_t offset_of_data = get_start_offset_of_data(); |
|
216 u8_t * const data = get_header_offset(offset_of_data, offset+contignuous_bytes); |
|
217 if (data != 0) |
|
218 { |
|
219 return data+offset; // Data begins after the header. |
|
220 } |
|
221 else |
|
222 { |
|
223 return 0; |
|
224 } |
|
225 } |
|
226 else |
|
227 { |
|
228 EAP_ASSERT_ALWAYS(get_data_length() > 0u); |
|
229 } |
|
230 return 0; |
|
231 } |
|
232 |
|
233 //-------------------------------------------------- |
|
234 |
|
235 EAP_FUNC_EXPORT u8_t * eap_simple_config_header_c::get_data( |
|
236 abs_eap_am_tools_c * const m_am_tools, |
|
237 const u32_t contignuous_bytes) const |
|
238 { |
|
239 return get_data_offset(m_am_tools, 0u, contignuous_bytes); |
|
240 } |
|
241 |
|
242 //-------------------------------------------------- |
|
243 |
|
244 EAP_FUNC_EXPORT u8_t * eap_simple_config_header_c::get_simple_config_flags() const |
|
245 { |
|
246 u32_t flag_offset(get_sc_flags_offset()); |
|
247 |
|
248 return get_header_offset(flag_offset, sizeof(u8_t)); |
|
249 } |
|
250 |
|
251 //-------------------------------------------------- |
|
252 |
|
253 EAP_FUNC_EXPORT bool eap_simple_config_header_c::get_simple_config_flag_bit(const u32_t mask) const |
|
254 { |
|
255 const u8_t * const flag = get_simple_config_flags(); |
|
256 |
|
257 if (flag != 0 |
|
258 && ((*flag) & mask)) |
|
259 { |
|
260 return true; |
|
261 } |
|
262 return false; |
|
263 } |
|
264 |
|
265 //-------------------------------------------------- |
|
266 |
|
267 EAP_FUNC_EXPORT u8_t eap_simple_config_header_c::get_simple_config_flag_value(const u32_t mask, const u32_t shift) const |
|
268 { |
|
269 const u8_t * const flag = get_simple_config_flags(); |
|
270 |
|
271 if (flag != 0) |
|
272 { |
|
273 return static_cast<u8_t>(((*flag) & mask) >> shift); |
|
274 } |
|
275 else |
|
276 { |
|
277 return 0; |
|
278 } |
|
279 } |
|
280 |
|
281 //-------------------------------------------------- |
|
282 |
|
283 EAP_FUNC_EXPORT bool eap_simple_config_header_c::get_flag_simple_config_length_included() const |
|
284 { |
|
285 return get_simple_config_flag_bit(m_flag_mask_simple_config_length_included); |
|
286 } |
|
287 |
|
288 //-------------------------------------------------- |
|
289 |
|
290 EAP_FUNC_EXPORT bool eap_simple_config_header_c::get_flag_more_fragments() const |
|
291 { |
|
292 return get_simple_config_flag_bit(m_flag_mask_more_fragments); |
|
293 } |
|
294 |
|
295 //-------------------------------------------------- |
|
296 |
|
297 EAP_FUNC_EXPORT u8_t eap_simple_config_header_c::get_flag_reserved() const |
|
298 { |
|
299 return get_simple_config_flag_value(m_flag_mask_reserved, m_flag_shift_reserved); |
|
300 } |
|
301 |
|
302 //-------------------------------------------------- |
|
303 |
|
304 EAP_FUNC_EXPORT eap_status_e eap_simple_config_header_c::get_simple_config_message_length(u32_t * const simple_config_length) const |
|
305 { |
|
306 if (get_flag_simple_config_length_included() == false) |
|
307 { |
|
308 // SIMPLE_CONFIG data length is NOT included. |
|
309 *simple_config_length = 0u; |
|
310 return eap_status_ok; |
|
311 } |
|
312 |
|
313 u8_t * const data = get_header_offset(get_sc_length_offset(), sizeof(u32_t)); |
|
314 if (data != 0) |
|
315 { |
|
316 u32_t simple_config_message_length = |
|
317 eap_read_u32_t_network_order(data, sizeof(u32_t)); |
|
318 |
|
319 *simple_config_length = simple_config_message_length; |
|
320 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
321 } |
|
322 else |
|
323 { |
|
324 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
325 } |
|
326 } |
|
327 |
|
328 //-------------------------------------------------- |
|
329 |
|
330 EAP_FUNC_EXPORT eap_status_e eap_simple_config_header_c::check_header( |
|
331 abs_eap_am_tools_c * const /* tools */, |
|
332 const bool is_client_when_true) const |
|
333 { |
|
334 eap_status_e status = eap_status_ok; |
|
335 |
|
336 if (get_flag_reserved() != static_cast<u16_t>(0ul)) |
|
337 { |
|
338 status = EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
339 } |
|
340 |
|
341 if (status != eap_status_ok) |
|
342 { |
|
343 EAP_UNREFERENCED_PARAMETER(is_client_when_true); |
|
344 |
|
345 // In version negotiation this check will fail. |
|
346 // Do not add error traces here. |
|
347 eap_status_string_c status_string; |
|
348 EAP_UNREFERENCED_PARAMETER(status_string); |
|
349 EAP_TRACE_DEBUG( |
|
350 m_am_tools, |
|
351 TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, |
|
352 (EAPL("WARNING: EAP_type_SIMPLE_CONFIG: check_header(): failed, %s, ") |
|
353 EAPL("get_eap_type() 0x%08x, get_op_code() %d, get_flag_reserved() %d, status %s\n"), |
|
354 (is_client_when_true == true) ? "client": "server", |
|
355 convert_eap_type_to_u32_t(get_eap_type()), |
|
356 get_sc_op_code(), |
|
357 get_flag_reserved(), |
|
358 status_string.get_status_string(status))); |
|
359 } |
|
360 |
|
361 return EAP_STATUS_RETURN(m_am_tools, status); |
|
362 } |
|
363 |
|
364 //-------------------------------------------------- |
|
365 |
|
366 EAP_FUNC_EXPORT eap_const_string eap_simple_config_header_c::get_code_string() const |
|
367 { |
|
368 return eap_header_string_c::get_eap_code_string(get_eap_code()); |
|
369 } |
|
370 |
|
371 //-------------------------------------------------- |
|
372 |
|
373 EAP_FUNC_EXPORT eap_const_string eap_simple_config_header_c::get_eap_type_string() const |
|
374 { |
|
375 if (get_eap_length() <= eap_header_base_c::get_header_length()) |
|
376 { |
|
377 return EAPL("No EAP-type"); |
|
378 } |
|
379 |
|
380 return eap_header_string_c::get_eap_type_string(get_eap_type()); |
|
381 } |
|
382 |
|
383 //-------------------------------------------------- |
|
384 |
|
385 EAP_FUNC_EXPORT eap_const_string eap_simple_config_header_c::get_sc_op_code_string() const |
|
386 { |
|
387 const op_code_e op_code(get_sc_op_code()); |
|
388 |
|
389 #if defined(USE_EAP_TRACE_STRINGS) |
|
390 EAP_IF_RETURN_STRING(op_code, op_code_none) |
|
391 else EAP_IF_RETURN_STRING(op_code, op_code_WSC_Start) |
|
392 else EAP_IF_RETURN_STRING(op_code, op_code_WSC_ACK) |
|
393 else EAP_IF_RETURN_STRING(op_code, op_code_WSC_NACK) |
|
394 else EAP_IF_RETURN_STRING(op_code, op_code_WSC_MSG) |
|
395 else EAP_IF_RETURN_STRING(op_code, op_code_WSC_Done) |
|
396 else EAP_IF_RETURN_STRING(op_code, op_code_FRAG_ACK) |
|
397 #endif // #if defined(USE_EAP_TRACE_STRINGS) |
|
398 { |
|
399 EAP_UNREFERENCED_PARAMETER(op_code); |
|
400 return EAPL("Unknown SIMPLE CONFIG Op-Code"); |
|
401 } |
|
402 } |
|
403 |
|
404 //-------------------------------------------------- |
|
405 |
|
406 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_eap_code(const eap_code_value_e p_code) |
|
407 { |
|
408 eap_header_base_c::set_code(p_code); |
|
409 } |
|
410 |
|
411 //-------------------------------------------------- |
|
412 |
|
413 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_eap_identifier(const u8_t p_identifier) |
|
414 { |
|
415 eap_header_base_c::set_identifier(p_identifier); |
|
416 } |
|
417 |
|
418 //-------------------------------------------------- |
|
419 |
|
420 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_eap_length( |
|
421 const u16_t p_length, |
|
422 const bool expanded_type_when_true) |
|
423 { |
|
424 eap_header_base_c::set_length( |
|
425 p_length, |
|
426 expanded_type_when_true); |
|
427 } |
|
428 |
|
429 //-------------------------------------------------- |
|
430 |
|
431 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_eap_type( |
|
432 const eap_type_value_e p_type, |
|
433 const bool expanded_type_when_true) |
|
434 { |
|
435 eap_header_base_c::set_type(p_type, expanded_type_when_true); |
|
436 } |
|
437 |
|
438 |
|
439 //-------------------------------------------------- |
|
440 |
|
441 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_simple_config_flag_value(const u8_t value, const u32_t mask, const u32_t shift) const |
|
442 { |
|
443 u8_t *flag = get_simple_config_flags(); |
|
444 |
|
445 if (flag != 0) |
|
446 { |
|
447 (*flag) = static_cast<u8_t>(((*flag) & ~mask) | ((value << shift) & mask)); |
|
448 } |
|
449 } |
|
450 |
|
451 //-------------------------------------------------- |
|
452 |
|
453 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_simple_config_flag_bit(const bool flag, u32_t mask) const |
|
454 { |
|
455 u8_t *p_flag = get_simple_config_flags(); |
|
456 |
|
457 if (p_flag != 0) |
|
458 { |
|
459 if (flag == true) |
|
460 { |
|
461 (*p_flag) = static_cast<u8_t>((*p_flag) | mask); |
|
462 } |
|
463 else |
|
464 { |
|
465 (*p_flag) = static_cast<u8_t>((*p_flag) & ~mask); |
|
466 } |
|
467 } |
|
468 } |
|
469 |
|
470 //-------------------------------------------------- |
|
471 |
|
472 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_flag_reserved(const u8_t reserved) |
|
473 { |
|
474 set_simple_config_flag_value(reserved, m_flag_mask_reserved, m_flag_shift_reserved); |
|
475 } |
|
476 |
|
477 //-------------------------------------------------- |
|
478 |
|
479 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_flag_simple_config_length_included(const bool simple_config_length_included) |
|
480 { |
|
481 set_simple_config_flag_bit(simple_config_length_included, m_flag_mask_simple_config_length_included); |
|
482 } |
|
483 |
|
484 //-------------------------------------------------- |
|
485 |
|
486 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_flag_more_fragments(const bool more_fragments) |
|
487 { |
|
488 set_simple_config_flag_bit(more_fragments, m_flag_mask_more_fragments); |
|
489 } |
|
490 |
|
491 //-------------------------------------------------- |
|
492 |
|
493 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_data_length( |
|
494 const u32_t p_data_length, |
|
495 const bool expanded_type_when_true) |
|
496 { |
|
497 EAP_ASSERT_ALWAYS(p_data_length+get_header_length() <= 0xffff); |
|
498 |
|
499 set_eap_length( |
|
500 static_cast<u16_t>(p_data_length+get_header_length()), |
|
501 expanded_type_when_true); |
|
502 } |
|
503 |
|
504 //-------------------------------------------------- |
|
505 |
|
506 EAP_FUNC_EXPORT void eap_simple_config_header_c::set_simple_config_message_length(const u32_t simple_config_length) |
|
507 { |
|
508 EAP_ASSERT_ALWAYS(get_flag_simple_config_length_included() == true); |
|
509 |
|
510 u32_t message_length_offset(get_sc_length_offset()); |
|
511 |
|
512 u8_t * const data = get_header_offset(message_length_offset, sizeof(u32_t)); |
|
513 |
|
514 EAP_ASSERT(data != 0); |
|
515 |
|
516 data[0] = static_cast<u8_t>((simple_config_length & 0xff000000) >> 24); |
|
517 data[1] = static_cast<u8_t>((simple_config_length & 0x00ff0000) >> 16); |
|
518 data[2] = static_cast<u8_t>((simple_config_length & 0x0000ff00) >> 8); |
|
519 data[3] = static_cast<u8_t>((simple_config_length & 0x000000ff) >> 0); |
|
520 } |
|
521 |
|
522 //-------------------------------------------------- |
|
523 |
|
524 EAP_FUNC_EXPORT void eap_simple_config_header_c::reset_header( |
|
525 abs_eap_am_tools_c * const m_am_tools, |
|
526 const u32_t buffer_length, |
|
527 const bool expanded_type_when_true) |
|
528 { |
|
529 EAP_UNREFERENCED_PARAMETER(m_am_tools); |
|
530 |
|
531 eap_header_base_c::set_length( |
|
532 static_cast<u16_t>(buffer_length), |
|
533 expanded_type_when_true); |
|
534 |
|
535 set_eap_code(eap_code_none); |
|
536 |
|
537 set_eap_type( |
|
538 eap_type_none, |
|
539 true); |
|
540 |
|
541 set_flag_simple_config_length_included(false); |
|
542 set_flag_more_fragments(false); |
|
543 set_sc_op_code(op_code_none); |
|
544 |
|
545 set_flag_reserved(0u); |
|
546 |
|
547 set_eap_identifier(0u); |
|
548 } |
|
549 |
|
550 //-------------------------------------------------- |
|
551 |
|
552 #endif //#if defined(USE_EAP_SIMPLE_CONFIG) |
|
553 |
|
554 // End. |