|
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 68 |
|
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 #include "eap_tools.h" |
|
29 #include "eap_header.h" |
|
30 #include "eap_header_string.h" |
|
31 #include "eap_type_aka_header.h" |
|
32 |
|
33 /** @file */ |
|
34 |
|
35 |
|
36 // |
|
37 EAP_FUNC_EXPORT aka_payload_AT_header_c::~aka_payload_AT_header_c() |
|
38 { |
|
39 } |
|
40 |
|
41 // |
|
42 EAP_FUNC_EXPORT aka_payload_AT_header_c::aka_payload_AT_header_c( |
|
43 abs_eap_am_tools_c * const tools, |
|
44 void * const header_buffer, |
|
45 const u32_t header_buffer_length) |
|
46 : eap_general_header_base_c(tools, header_buffer, header_buffer_length) |
|
47 , m_am_tools(tools) |
|
48 { |
|
49 } |
|
50 |
|
51 EAP_FUNC_EXPORT aka_payload_AT_type_e aka_payload_AT_header_c::get_current_payload() const |
|
52 { |
|
53 const u8_t * const payload_data = get_header_offset(m_type_offset, sizeof(u8_t)); |
|
54 if (payload_data != 0) |
|
55 { |
|
56 return static_cast<aka_payload_AT_type_e>(*payload_data); |
|
57 } |
|
58 else |
|
59 { |
|
60 return aka_payload_NONE; |
|
61 } |
|
62 } |
|
63 |
|
64 EAP_FUNC_EXPORT u16_t aka_payload_AT_header_c::get_payload_length() const |
|
65 { |
|
66 const u8_t * const length_data = get_header_offset(m_length_offset, sizeof(u8_t)); |
|
67 if (length_data != 0) |
|
68 { |
|
69 return static_cast<u16_t>(*length_data * 4u); |
|
70 } |
|
71 else |
|
72 { |
|
73 return 0ul; |
|
74 } |
|
75 } |
|
76 |
|
77 EAP_FUNC_EXPORT u16_t aka_payload_AT_header_c::get_reserved() const |
|
78 { |
|
79 const u8_t * const reserved = get_header_offset(m_reserved_offset, sizeof(u16_t)); |
|
80 if (reserved != 0) |
|
81 { |
|
82 return eap_read_u16_t_network_order(reserved, sizeof(u16_t)); |
|
83 } |
|
84 else |
|
85 { |
|
86 // this is illegal reserved field value. |
|
87 return 0xffff; |
|
88 } |
|
89 } |
|
90 |
|
91 EAP_FUNC_EXPORT u8_t * aka_payload_AT_header_c::get_reserved_pointer(const u32_t contignuous_bytes) const |
|
92 { |
|
93 const u32_t required_data_bytes = contignuous_bytes - 2ul; |
|
94 |
|
95 if (get_data_length() >= required_data_bytes |
|
96 && required_data_bytes > 0) |
|
97 { |
|
98 u8_t * const reserved = get_header_offset(m_reserved_offset, contignuous_bytes); |
|
99 return reserved; |
|
100 } |
|
101 else |
|
102 { |
|
103 EAP_ASSERT( |
|
104 get_data_length() >= required_data_bytes |
|
105 && required_data_bytes > 0); |
|
106 } |
|
107 return 0; |
|
108 } |
|
109 |
|
110 EAP_FUNC_EXPORT u32_t aka_payload_AT_header_c::get_data_length() const |
|
111 { |
|
112 if (get_payload_length() > get_header_length()) |
|
113 return static_cast<u32_t>(get_payload_length()-get_header_length()); |
|
114 else |
|
115 return 0; |
|
116 } |
|
117 |
|
118 EAP_FUNC_EXPORT u16_t aka_payload_AT_header_c::get_header_length() |
|
119 { |
|
120 return m_data_offset; |
|
121 } |
|
122 |
|
123 EAP_FUNC_EXPORT u16_t aka_payload_AT_header_c::get_max_payload_data_length() |
|
124 { |
|
125 return static_cast<u16_t>((0xff*4u-get_header_length())); |
|
126 } |
|
127 |
|
128 EAP_FUNC_EXPORT u8_t * aka_payload_AT_header_c::get_data(const u32_t contignuous_bytes) const |
|
129 { |
|
130 if (get_data_length() >= contignuous_bytes |
|
131 && contignuous_bytes > 0) |
|
132 { |
|
133 return get_header_offset(m_data_offset, contignuous_bytes); // Data begins after the header. |
|
134 } |
|
135 else |
|
136 { |
|
137 EAP_ASSERT( |
|
138 get_data_length() >= contignuous_bytes |
|
139 && contignuous_bytes > 0); |
|
140 } |
|
141 return 0; |
|
142 } |
|
143 |
|
144 EAP_FUNC_EXPORT u8_t * aka_payload_AT_header_c::get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const |
|
145 { |
|
146 if (get_header_buffer_length()-get_header_length() >= offset+contignuous_bytes |
|
147 && contignuous_bytes > 0) |
|
148 { |
|
149 u8_t * const data = get_header_offset(m_data_offset, contignuous_bytes); |
|
150 if (data != 0) |
|
151 { |
|
152 return data+offset; // Data begins after the header. |
|
153 } |
|
154 else |
|
155 { |
|
156 return 0; |
|
157 } |
|
158 } |
|
159 else |
|
160 { |
|
161 EAP_ASSERT( |
|
162 get_data_length() >= offset+contignuous_bytes |
|
163 && contignuous_bytes > 0); |
|
164 } |
|
165 return 0; |
|
166 } |
|
167 |
|
168 EAP_FUNC_EXPORT u8_t * aka_payload_AT_header_c::get_next_header() const |
|
169 { |
|
170 if (get_header_buffer_length() >= get_data_length()+2ul*get_header_length()) |
|
171 { |
|
172 return get_data_offset(get_data_length(), get_header_length()); |
|
173 } |
|
174 else |
|
175 { |
|
176 return 0; |
|
177 } |
|
178 } |
|
179 |
|
180 // Mostly this is zero. |
|
181 // With some attributes this is used for special purposes. |
|
182 EAP_FUNC_EXPORT void aka_payload_AT_header_c::set_reserved(const u16_t reserved) |
|
183 { |
|
184 u8_t *reserved_data = get_header_offset(m_reserved_offset, sizeof(u16_t)); |
|
185 |
|
186 EAP_ASSERT(reserved_data != 0); |
|
187 |
|
188 reserved_data[0] = static_cast<u8_t>(((reserved & 0xff00) >> 8)); |
|
189 reserved_data[1] = static_cast<u8_t>((reserved & 0x00ff)); |
|
190 } |
|
191 |
|
192 EAP_FUNC_EXPORT void aka_payload_AT_header_c::set_current_payload(const aka_payload_AT_type_e p_current_payload) |
|
193 { |
|
194 EAP_ASSERT_ALWAYS(p_current_payload == static_cast<aka_payload_AT_type_e>(static_cast<u8_t>(p_current_payload))); |
|
195 |
|
196 u8_t * const payload_type = get_header_offset(m_type_offset, sizeof(u8_t)); |
|
197 |
|
198 EAP_ASSERT(payload_type != 0); |
|
199 |
|
200 *payload_type = static_cast<u8_t>(p_current_payload); |
|
201 } |
|
202 |
|
203 EAP_FUNC_EXPORT void aka_payload_AT_header_c::set_data_length(const u16_t p_data_length) |
|
204 { |
|
205 u32_t total_length = p_data_length+aka_payload_AT_header_c::get_header_length(); |
|
206 u32_t remaider = total_length % 4u; |
|
207 |
|
208 EAP_ASSERT(remaider == 0); |
|
209 EAP_ASSERT((total_length / 4u) <= 0xff); |
|
210 |
|
211 EAP_UNREFERENCED_PARAMETER(remaider); |
|
212 |
|
213 u8_t * const length_data = get_header_offset(m_length_offset, sizeof(u8_t)); |
|
214 |
|
215 EAP_ASSERT(length_data != 0); |
|
216 |
|
217 *length_data = static_cast<u8_t>(total_length/4u); |
|
218 } |
|
219 |
|
220 EAP_FUNC_EXPORT void aka_payload_AT_header_c::reset_header(const u16_t data_length) |
|
221 { |
|
222 set_reserved(0u); |
|
223 set_current_payload(aka_payload_NONE); |
|
224 set_data_length(data_length); |
|
225 } |
|
226 |
|
227 EAP_FUNC_EXPORT eap_const_string aka_payload_AT_header_c::get_payload_AT_string(const aka_payload_AT_type_e payload_type) |
|
228 { |
|
229 |
|
230 #if defined(USE_EAP_TRACE_STRINGS) |
|
231 EAP_IF_RETURN_STRING(payload_type, aka_payload_NONE) |
|
232 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_RAND) |
|
233 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_AUTN) |
|
234 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_RES) |
|
235 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_AUTS) |
|
236 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_PADDING) |
|
237 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_PERMANENT_ID_REQ) |
|
238 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_MAC) |
|
239 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_NOTIFICATION) |
|
240 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_ANY_ID_REQ) |
|
241 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_IDENTITY) |
|
242 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_FULLAUTH_ID_REQ) |
|
243 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_COUNTER) |
|
244 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_COUNTER_TOO_SMALL) |
|
245 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_NONCE_S) |
|
246 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_CLIENT_ERROR_CODE) |
|
247 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_IV) |
|
248 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_ENCR_DATA) |
|
249 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_NEXT_PSEUDONYM) |
|
250 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_NEXT_REAUTH_ID) |
|
251 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_RESULT_IND) |
|
252 else EAP_IF_RETURN_STRING(payload_type, aka_payload_AT_CHECKCODE) |
|
253 else |
|
254 #endif // #if defined(USE_EAP_TRACE_STRINGS) |
|
255 { |
|
256 EAP_UNREFERENCED_PARAMETER(payload_type); |
|
257 return EAPL("Unknown AKA payload AT"); |
|
258 } |
|
259 } |
|
260 |
|
261 EAP_FUNC_EXPORT eap_const_string aka_payload_AT_header_c::get_payload_AT_string() const |
|
262 { |
|
263 return get_payload_AT_string(get_current_payload()); |
|
264 } |
|
265 |
|
266 EAP_FUNC_EXPORT eap_status_e aka_payload_AT_header_c::check_header() const |
|
267 { |
|
268 if (get_reserved() != 0) |
|
269 { |
|
270 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
271 } |
|
272 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
273 } |
|
274 |
|
275 //-------------------------------------------------- |
|
276 //-------------------------------------------------- |
|
277 //-------------------------------------------------- |
|
278 |
|
279 |
|
280 // |
|
281 EAP_FUNC_EXPORT aka_header_c::~aka_header_c() |
|
282 { |
|
283 } |
|
284 |
|
285 // |
|
286 EAP_FUNC_EXPORT aka_header_c::aka_header_c( |
|
287 abs_eap_am_tools_c * const tools, |
|
288 u8_t * const header_buffer, |
|
289 const u32_t header_buffer_length) |
|
290 : eap_header_base_c(tools, header_buffer, header_buffer_length) |
|
291 , m_am_tools(tools) |
|
292 { |
|
293 } |
|
294 |
|
295 EAP_FUNC_EXPORT aka_subtype_e aka_header_c::get_subtype() const |
|
296 { |
|
297 u32_t subtype_offset(get_sub_type_offset()); |
|
298 |
|
299 const u8_t * const subtype_data = get_header_offset(subtype_offset, sizeof(u8_t)); |
|
300 if (subtype_data != 0) |
|
301 { |
|
302 return static_cast<aka_subtype_e>(*subtype_data); |
|
303 } |
|
304 else |
|
305 { |
|
306 return aka_subtype_NONE; |
|
307 } |
|
308 } |
|
309 |
|
310 EAP_FUNC_EXPORT u16_t aka_header_c::get_data_length() const |
|
311 { |
|
312 if (get_length() > static_cast<u16_t>(get_header_length())) |
|
313 { |
|
314 return static_cast<u16_t>(get_length()-static_cast<u16_t>(get_header_length())); |
|
315 } |
|
316 else |
|
317 { |
|
318 return 0; |
|
319 } |
|
320 } |
|
321 |
|
322 EAP_FUNC_EXPORT u32_t aka_header_c::get_sub_type_offset() const |
|
323 { |
|
324 return eap_header_base_c::get_header_length() + eap_header_base_c::get_type_field_length() + m_subtype_delta_offset; |
|
325 } |
|
326 |
|
327 EAP_FUNC_EXPORT u32_t aka_header_c::get_header_length() const |
|
328 { |
|
329 return get_sub_type_offset() + m_data_delta_offset; |
|
330 } |
|
331 |
|
332 EAP_FUNC_EXPORT u8_t * aka_header_c::get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const |
|
333 { |
|
334 u32_t data_length = get_data_length(); |
|
335 |
|
336 if (data_length >= offset+contignuous_bytes |
|
337 && contignuous_bytes > 0u) |
|
338 { |
|
339 return (get_header_offset(get_header_length(), contignuous_bytes)+offset); // Data begins after the header. |
|
340 } |
|
341 else |
|
342 { |
|
343 EAP_ASSERT(get_data_length() > 0u); |
|
344 } |
|
345 return 0; |
|
346 } |
|
347 |
|
348 |
|
349 EAP_FUNC_EXPORT u8_t * aka_header_c::get_data(const u32_t contignuous_bytes) const |
|
350 { |
|
351 return get_data_offset(0u, contignuous_bytes); |
|
352 } |
|
353 |
|
354 |
|
355 EAP_FUNC_EXPORT u16_t aka_header_c::get_reserved() const |
|
356 { |
|
357 u32_t reserved_offset(get_sub_type_offset()+m_reserved_delta_offset); |
|
358 |
|
359 u8_t * const reserved_data = get_header_offset(reserved_offset, sizeof(u16_t)); |
|
360 if (reserved_data != 0) |
|
361 { |
|
362 return eap_read_u16_t_network_order(reserved_data, sizeof(u16_t)); |
|
363 } |
|
364 else |
|
365 { |
|
366 // This is illegal reserved data value. |
|
367 return 0xffff; |
|
368 } |
|
369 } |
|
370 |
|
371 |
|
372 EAP_FUNC_EXPORT eap_status_e aka_header_c::check_header() const |
|
373 { |
|
374 if (get_type() != eap_type_aka) |
|
375 { |
|
376 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
377 } |
|
378 else if (get_reserved() != static_cast<u16_t>(0ul)) |
|
379 { |
|
380 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
381 } |
|
382 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
383 } |
|
384 |
|
385 EAP_FUNC_EXPORT eap_const_string aka_header_c::get_subtype_string() const |
|
386 { |
|
387 |
|
388 #if defined(USE_EAP_TRACE_STRINGS) |
|
389 const aka_subtype_e packet_type = get_subtype(); |
|
390 |
|
391 EAP_IF_RETURN_STRING(packet_type, aka_subtype_NONE) |
|
392 else EAP_IF_RETURN_STRING(packet_type, aka_subtype_Synchronization_Failure) |
|
393 else EAP_IF_RETURN_STRING(packet_type, aka_subtype_Authentication_Reject) |
|
394 else EAP_IF_RETURN_STRING(packet_type, aka_subtype_Identity) |
|
395 else EAP_IF_RETURN_STRING(packet_type, aka_subtype_Challenge) |
|
396 else EAP_IF_RETURN_STRING(packet_type, aka_subtype_Notification) |
|
397 else EAP_IF_RETURN_STRING(packet_type, aka_subtype_Re_authentication) |
|
398 else EAP_IF_RETURN_STRING(packet_type, aka_subtype_Client_Error) |
|
399 else |
|
400 #endif // #if defined(USE_EAP_TRACE_STRINGS) |
|
401 { |
|
402 return EAPL("Unknown AKA-type"); |
|
403 } |
|
404 } |
|
405 |
|
406 EAP_FUNC_EXPORT eap_const_string aka_header_c::get_code_string() const |
|
407 { |
|
408 return eap_header_string_c::get_eap_code_string(get_code()); |
|
409 } |
|
410 |
|
411 EAP_FUNC_EXPORT eap_const_string aka_header_c::get_eap_type_string() const |
|
412 { |
|
413 if (get_length() <= eap_header_base_c::get_header_length()) |
|
414 { |
|
415 return EAPL("No EAP-type"); |
|
416 } |
|
417 |
|
418 return eap_header_string_c::get_eap_type_string(get_type()); |
|
419 } |
|
420 |
|
421 EAP_FUNC_EXPORT void aka_header_c::set_reserved(const u16_t reserved) |
|
422 { |
|
423 u32_t reserved_offset(get_sub_type_offset()+m_reserved_delta_offset); |
|
424 u8_t *reserved_data = get_header_offset(reserved_offset, sizeof(u16_t)); |
|
425 |
|
426 EAP_ASSERT(reserved_data != 0); |
|
427 |
|
428 reserved_data[0] = static_cast<u8_t>((reserved & 0xff00) >> 8); |
|
429 reserved_data[1] = static_cast<u8_t>(reserved & 0x00ff); |
|
430 } |
|
431 |
|
432 EAP_FUNC_EXPORT void aka_header_c::set_subtype(const aka_subtype_e p_subtype) |
|
433 { |
|
434 u32_t subtype_offset(get_sub_type_offset()); |
|
435 u8_t * const subtype_data = get_header_offset(subtype_offset, sizeof(u8_t)); |
|
436 |
|
437 EAP_ASSERT(subtype_data != 0); |
|
438 |
|
439 *subtype_data = static_cast<u8_t>(p_subtype); |
|
440 } |
|
441 |
|
442 EAP_FUNC_EXPORT void aka_header_c::set_data_length( |
|
443 const u32_t p_data_length, |
|
444 const bool expanded_type_when_true) |
|
445 { |
|
446 EAP_ASSERT_ALWAYS(p_data_length+get_header_length() <= 0xffff); |
|
447 |
|
448 set_length( |
|
449 static_cast<u16_t>(p_data_length+get_header_length()), |
|
450 expanded_type_when_true); |
|
451 } |
|
452 |
|
453 EAP_FUNC_EXPORT void aka_header_c::reset_header( |
|
454 const u32_t buffer_length, |
|
455 const bool expanded_type_when_true) |
|
456 { |
|
457 eap_header_base_c::set_length( |
|
458 static_cast<u16_t>(buffer_length), |
|
459 expanded_type_when_true); |
|
460 |
|
461 set_code(eap_code_none); |
|
462 |
|
463 set_identifier(0u); |
|
464 |
|
465 set_type( |
|
466 eap_type_aka, |
|
467 expanded_type_when_true); // AKA = 18 |
|
468 |
|
469 set_subtype(aka_subtype_NONE); |
|
470 set_reserved(0u); |
|
471 } |
|
472 |
|
473 //-------------------------------------------------- |
|
474 |
|
475 |
|
476 |
|
477 // End. |