|
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 23 |
|
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 |
|
29 #include "eap_expanded_type.h" |
|
30 #include "eap_header.h" |
|
31 |
|
32 //-------------------------------------------------- |
|
33 |
|
34 EAP_FUNC_EXPORT eap_expanded_type_c::~eap_expanded_type_c() |
|
35 { |
|
36 } |
|
37 |
|
38 //-------------------------------------------------- |
|
39 |
|
40 EAP_FUNC_EXPORT eap_expanded_type_c::eap_expanded_type_c() |
|
41 { |
|
42 m_vendor_id = eap_type_vendor_id_ietf; |
|
43 m_vendor_type = static_cast<u32_t>(eap_type_none); |
|
44 } |
|
45 |
|
46 //-------------------------------------------------- |
|
47 |
|
48 EAP_FUNC_EXPORT eap_expanded_type_c::eap_expanded_type_c( |
|
49 const eap_type_vendor_id_e vendor_id, |
|
50 const u32_t vendor_type) |
|
51 { |
|
52 m_vendor_id = vendor_id; |
|
53 m_vendor_type = vendor_type; |
|
54 } |
|
55 |
|
56 //-------------------------------------------------- |
|
57 |
|
58 EAP_FUNC_EXPORT eap_expanded_type_c::eap_expanded_type_c( |
|
59 const eap_type_ietf_values_e type) |
|
60 { |
|
61 m_vendor_id = eap_type_vendor_id_ietf; |
|
62 m_vendor_type = static_cast<u32_t>(type); |
|
63 } |
|
64 |
|
65 //-------------------------------------------------- |
|
66 |
|
67 EAP_FUNC_EXPORT bool eap_expanded_type_c::is_expanded_type(const eap_type_ietf_values_e eap_type) |
|
68 { |
|
69 return (eap_type == eap_type_expanded_type); |
|
70 } |
|
71 |
|
72 //-------------------------------------------------- |
|
73 |
|
74 #if defined(USE_EAP_EXPANDED_TYPES) |
|
75 EAP_FUNC_EXPORT bool eap_expanded_type_c::is_ietf_type(const eap_expanded_type_c eap_type) |
|
76 { |
|
77 return (eap_type.get_vendor_id() == eap_type_vendor_id_ietf |
|
78 && eap_type.get_vendor_type() < eap_type_expanded_type); |
|
79 } |
|
80 |
|
81 #else |
|
82 EAP_FUNC_EXPORT bool eap_expanded_type_c::is_ietf_type(const eap_type_ietf_values_e eap_type) |
|
83 { |
|
84 return (eap_type < eap_type_expanded_type); |
|
85 } |
|
86 |
|
87 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
88 |
|
89 //-------------------------------------------------- |
|
90 |
|
91 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::get_type_data( |
|
92 abs_eap_am_tools_c * const am_tools, |
|
93 eap_type_ietf_values_e * const type) |
|
94 { |
|
95 if (type == 0) |
|
96 { |
|
97 EAP_UNREFERENCED_PARAMETER(am_tools); |
|
98 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
99 } |
|
100 |
|
101 if (m_vendor_type < eap_type_expanded_type |
|
102 && m_vendor_id == eap_type_vendor_id_ietf) |
|
103 { |
|
104 *type = static_cast<eap_type_ietf_values_e>(m_vendor_type); |
|
105 } |
|
106 else |
|
107 { |
|
108 // This is EAP type of other vendor than IETF. |
|
109 // This cannot be denoted in eap_type_ietf_values_e. |
|
110 *type = static_cast<eap_type_ietf_values_e>(m_vendor_type); |
|
111 } |
|
112 |
|
113 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
|
114 } |
|
115 |
|
116 //-------------------------------------------------- |
|
117 |
|
118 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::get_type_data( |
|
119 abs_eap_am_tools_c * const am_tools, |
|
120 eap_expanded_type_c * const type) |
|
121 { |
|
122 if (type == 0) |
|
123 { |
|
124 EAP_UNREFERENCED_PARAMETER(am_tools); |
|
125 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
126 } |
|
127 |
|
128 *type = *this; |
|
129 |
|
130 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
|
131 } |
|
132 |
|
133 //-------------------------------------------------- |
|
134 |
|
135 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::get_expanded_type_data( |
|
136 abs_eap_am_tools_c * const am_tools, |
|
137 eap_variable_data_c * const data) |
|
138 { |
|
139 if (data == 0) |
|
140 { |
|
141 EAP_UNREFERENCED_PARAMETER(am_tools); |
|
142 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
143 } |
|
144 |
|
145 eap_status_e status = data->reset(); |
|
146 if (status != eap_status_ok) |
|
147 { |
|
148 return EAP_STATUS_RETURN(am_tools, status); |
|
149 } |
|
150 |
|
151 status = data->set_buffer_length(get_eap_expanded_type_size()); |
|
152 if (status != eap_status_ok) |
|
153 { |
|
154 return EAP_STATUS_RETURN(am_tools, status); |
|
155 } |
|
156 |
|
157 status = data->set_data_length(get_eap_expanded_type_size()); |
|
158 if (status != eap_status_ok) |
|
159 { |
|
160 return EAP_STATUS_RETURN(am_tools, status); |
|
161 } |
|
162 |
|
163 u32_t offset = 0ul; |
|
164 |
|
165 { |
|
166 u8_t * const ietf_type = static_cast<u8_t *>(data->get_data_offset(offset, m_ietf_type_size)); |
|
167 if (ietf_type == 0) |
|
168 { |
|
169 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
170 } |
|
171 offset += m_ietf_type_size; |
|
172 |
|
173 *ietf_type = static_cast<u8_t>(eap_type_expanded_type); |
|
174 } |
|
175 |
|
176 { |
|
177 u8_t * const vendor_id = data->get_data_offset(offset, m_vendor_id_size); |
|
178 if (vendor_id == 0) |
|
179 { |
|
180 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
181 } |
|
182 offset += m_vendor_id_size; |
|
183 |
|
184 status = eap_write_u24_t_network_order( |
|
185 vendor_id, |
|
186 m_vendor_id_size, |
|
187 m_vendor_id); |
|
188 if (status != eap_status_ok) |
|
189 { |
|
190 return EAP_STATUS_RETURN(am_tools, status); |
|
191 } |
|
192 } |
|
193 |
|
194 { |
|
195 u8_t * const vendor_type = data->get_data_offset(offset, m_vendor_type_size); |
|
196 if (vendor_type == 0) |
|
197 { |
|
198 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
199 } |
|
200 offset += m_vendor_type_size; |
|
201 |
|
202 status = eap_write_u32_t_network_order( |
|
203 vendor_type, |
|
204 m_vendor_type_size, |
|
205 m_vendor_type); |
|
206 if (status != eap_status_ok) |
|
207 { |
|
208 return EAP_STATUS_RETURN(am_tools, status); |
|
209 } |
|
210 } |
|
211 |
|
212 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
|
213 } |
|
214 |
|
215 //-------------------------------------------------- |
|
216 |
|
217 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::set_expanded_type_data( |
|
218 abs_eap_am_tools_c * const am_tools, |
|
219 const eap_variable_data_c * const data) |
|
220 { |
|
221 if (data->get_data_length() != get_eap_expanded_type_size() |
|
222 || data->get_data(data->get_data_length()) == 0) |
|
223 { |
|
224 EAP_UNREFERENCED_PARAMETER(am_tools); |
|
225 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
226 } |
|
227 |
|
228 u32_t offset = 0ul; |
|
229 |
|
230 { |
|
231 u8_t * const ietf_type = static_cast<u8_t *>(data->get_data_offset(offset, m_ietf_type_size)); |
|
232 if (ietf_type == 0) |
|
233 { |
|
234 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
235 } |
|
236 offset += m_ietf_type_size; |
|
237 |
|
238 if (static_cast<eap_type_ietf_values_e>(*ietf_type) != eap_type_expanded_type) |
|
239 { |
|
240 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
241 } |
|
242 } |
|
243 |
|
244 { |
|
245 u8_t * const vendor_id = data->get_data_offset(offset, m_vendor_id_size); |
|
246 if (vendor_id == 0) |
|
247 { |
|
248 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
249 } |
|
250 offset += m_vendor_id_size; |
|
251 |
|
252 m_vendor_id = static_cast<eap_type_vendor_id_e>(eap_read_u24_t_network_order(vendor_id, m_vendor_id_size)); |
|
253 } |
|
254 |
|
255 { |
|
256 u8_t * const vendor_type = data->get_data_offset(offset, m_vendor_type_size); |
|
257 if (vendor_type == 0) |
|
258 { |
|
259 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
260 } |
|
261 offset += m_vendor_type_size; |
|
262 |
|
263 m_vendor_type = eap_read_u32_t_network_order(vendor_type, m_vendor_type_size); |
|
264 } |
|
265 |
|
266 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
|
267 } |
|
268 |
|
269 //-------------------------------------------------- |
|
270 |
|
271 EAP_FUNC_EXPORT void eap_expanded_type_c::set_eap_type_values( |
|
272 const eap_type_vendor_id_e vendor_id, |
|
273 const u32_t vendor_type) |
|
274 { |
|
275 m_vendor_id = vendor_id; |
|
276 m_vendor_type = vendor_type; |
|
277 } |
|
278 |
|
279 //-------------------------------------------------- |
|
280 |
|
281 EAP_FUNC_EXPORT eap_type_vendor_id_e eap_expanded_type_c::get_vendor_id() const |
|
282 { |
|
283 return m_vendor_id; |
|
284 } |
|
285 |
|
286 //-------------------------------------------------- |
|
287 |
|
288 EAP_FUNC_EXPORT u32_t eap_expanded_type_c::get_vendor_type() const |
|
289 { |
|
290 return m_vendor_type; |
|
291 } |
|
292 |
|
293 //-------------------------------------------------- |
|
294 |
|
295 EAP_FUNC_EXPORT u32_t eap_expanded_type_c::get_eap_expanded_type_size() |
|
296 { |
|
297 return m_eap_expanded_type_size; |
|
298 } |
|
299 |
|
300 //-------------------------------------------------- |
|
301 |
|
302 EAP_FUNC_EXPORT bool eap_expanded_type_c::operator == (const eap_type_ietf_values_e right_type_value) const |
|
303 { |
|
304 if (m_vendor_id != eap_type_vendor_id_ietf) |
|
305 { |
|
306 return false; |
|
307 } |
|
308 else if (m_vendor_type != static_cast<u32_t>(right_type_value)) |
|
309 { |
|
310 return false; |
|
311 } |
|
312 else |
|
313 { |
|
314 return true; |
|
315 } |
|
316 } |
|
317 |
|
318 //-------------------------------------------------- |
|
319 |
|
320 EAP_FUNC_EXPORT bool eap_expanded_type_c::operator != (const eap_type_ietf_values_e right_type_value) const |
|
321 { |
|
322 return !(*this == right_type_value); |
|
323 } |
|
324 |
|
325 //-------------------------------------------------- |
|
326 |
|
327 EAP_FUNC_EXPORT bool eap_expanded_type_c::operator == (const eap_expanded_type_c &right_type_value) const |
|
328 { |
|
329 if (m_vendor_id != right_type_value.get_vendor_id()) |
|
330 { |
|
331 return false; |
|
332 } |
|
333 else if (m_vendor_type != right_type_value.get_vendor_type()) |
|
334 { |
|
335 return false; |
|
336 } |
|
337 else |
|
338 { |
|
339 return true; |
|
340 } |
|
341 } |
|
342 |
|
343 //-------------------------------------------------- |
|
344 |
|
345 EAP_FUNC_EXPORT bool eap_expanded_type_c::operator != (const eap_expanded_type_c &right_type_value) const |
|
346 { |
|
347 return !(*this == right_type_value); |
|
348 } |
|
349 |
|
350 //-------------------------------------------------- |
|
351 |
|
352 EAP_FUNC_EXPORT eap_expanded_type_c &eap_expanded_type_c::operator = (const eap_type_ietf_values_e right_type_value) |
|
353 { |
|
354 m_vendor_id = eap_type_vendor_id_ietf; ///< Here we use only 24 least significant bits. |
|
355 m_vendor_type = static_cast<u32_t>(right_type_value); |
|
356 |
|
357 return *this; |
|
358 } |
|
359 |
|
360 //-------------------------------------------------- |
|
361 |
|
362 EAP_FUNC_EXPORT eap_expanded_type_c &eap_expanded_type_c::operator = (const eap_expanded_type_c &right_type_value) |
|
363 { |
|
364 m_vendor_id = right_type_value.get_vendor_id(); ///< Here we use only 24 least significant bits. |
|
365 m_vendor_type = right_type_value.get_vendor_type(); |
|
366 |
|
367 return *this; |
|
368 } |
|
369 |
|
370 //-------------------------------------------------- |
|
371 |
|
372 EAP_FUNC_EXPORT eap_expanded_type_c *eap_expanded_type_c::operator & () |
|
373 { |
|
374 return this; |
|
375 } |
|
376 |
|
377 //-------------------------------------------------- |
|
378 |
|
379 EAP_FUNC_EXPORT const eap_expanded_type_c *eap_expanded_type_c::operator & () const |
|
380 { |
|
381 return this; |
|
382 } |
|
383 |
|
384 //-------------------------------------------------- |
|
385 |
|
386 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::read_type( |
|
387 abs_eap_am_tools_c * const am_tools, |
|
388 const u32_t index, |
|
389 const void * const p_buffer, |
|
390 const u32_t buffer_length, |
|
391 #if defined(USE_EAP_EXPANDED_TYPES) |
|
392 eap_expanded_type_c * const type |
|
393 #else |
|
394 eap_type_ietf_values_e * const type |
|
395 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
396 ) |
|
397 { |
|
398 if (p_buffer == 0) |
|
399 { |
|
400 EAP_UNREFERENCED_PARAMETER(am_tools); |
|
401 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
402 } |
|
403 |
|
404 const u8_t * const buffer = static_cast<const u8_t *>(p_buffer); |
|
405 |
|
406 if (buffer_length >= eap_expanded_type_c::m_ietf_type_size) |
|
407 { |
|
408 const u8_t * const type_data = buffer; |
|
409 if (type_data != 0) |
|
410 { |
|
411 eap_type_ietf_values_e ietf_eap_type = static_cast<eap_type_ietf_values_e>(*type_data); |
|
412 |
|
413 if (ietf_eap_type < eap_type_expanded_type |
|
414 && buffer_length >= eap_expanded_type_c::m_ietf_type_size*(index+1)) |
|
415 { |
|
416 if (index > 0ul) |
|
417 { |
|
418 const u8_t * const offset_type_data = |
|
419 &(buffer[eap_expanded_type_c::m_ietf_type_size*index]); |
|
420 if (offset_type_data != 0) |
|
421 { |
|
422 *type = static_cast<eap_type_ietf_values_e>(*offset_type_data); |
|
423 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
|
424 } |
|
425 else |
|
426 { |
|
427 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
428 } |
|
429 } |
|
430 else |
|
431 { |
|
432 *type = ietf_eap_type; |
|
433 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
|
434 } |
|
435 } |
|
436 else if (ietf_eap_type == eap_type_expanded_type |
|
437 && buffer_length >= eap_header_base_c::get_expanded_type_field_length()*(index+1ul)) |
|
438 { |
|
439 // 0 1 2 3 |
|
440 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
|
441 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
442 // | Type | Vendor-Id | |
|
443 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
444 // | Vendor-Type | |
|
445 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
446 // | Vendor data... |
|
447 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
448 |
|
449 eap_type_ietf_values_e ietf_eap_type(eap_type_none); |
|
450 |
|
451 { |
|
452 const u8_t * const offset_type_data = |
|
453 &(buffer[eap_header_base_c::get_expanded_ietf_type_offset() |
|
454 +eap_header_base_c::get_expanded_type_field_length()*index]); |
|
455 if (offset_type_data != 0) |
|
456 { |
|
457 ietf_eap_type = static_cast<eap_type_ietf_values_e>(*offset_type_data); |
|
458 } |
|
459 else |
|
460 { |
|
461 EAP_UNREFERENCED_PARAMETER(ietf_eap_type); |
|
462 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
463 } |
|
464 } |
|
465 |
|
466 eap_type_vendor_id_e vendor_id_value = eap_type_vendor_id_ietf; |
|
467 |
|
468 { |
|
469 const u8_t * const vendor_id = |
|
470 &(buffer[eap_header_base_c::get_expanded_vendor_id_offset() |
|
471 +eap_header_base_c::get_expanded_type_field_length()*index]); |
|
472 if (vendor_id == 0) |
|
473 { |
|
474 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
475 } |
|
476 |
|
477 vendor_id_value = static_cast<eap_type_vendor_id_e>( |
|
478 eap_read_u24_t_network_order( |
|
479 vendor_id, |
|
480 3ul*sizeof(u8_t))); |
|
481 } |
|
482 |
|
483 u32_t vendor_type_value = 0ul; |
|
484 |
|
485 { |
|
486 const u8_t * const vendor_type = |
|
487 &(buffer[eap_header_base_c::get_expanded_vendor_type_offset() |
|
488 +eap_header_base_c::get_expanded_type_field_length()*index]); |
|
489 if (vendor_type == 0) |
|
490 { |
|
491 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
492 } |
|
493 |
|
494 vendor_type_value = eap_read_u32_t_network_order( |
|
495 vendor_type, |
|
496 sizeof(u32_t)); |
|
497 } |
|
498 |
|
499 #if defined(USE_EAP_EXPANDED_TYPES) |
|
500 type->set_eap_type_values( |
|
501 vendor_id_value, |
|
502 vendor_type_value); |
|
503 |
|
504 EAP_ASSERT_TOOLS(am_tools, (ietf_eap_type == eap_type_expanded_type)); |
|
505 #else |
|
506 if (vendor_id_value == eap_type_vendor_id_ietf) |
|
507 { |
|
508 *type = static_cast<eap_type_value_e>(vendor_type_value); // Type field follows eap_header_c. |
|
509 } |
|
510 else |
|
511 { |
|
512 *type = ietf_eap_type; // Type field follows eap_header_c. |
|
513 } |
|
514 #endif |
|
515 |
|
516 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
|
517 } |
|
518 else |
|
519 { |
|
520 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
521 } |
|
522 } |
|
523 else |
|
524 { |
|
525 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
526 } |
|
527 } |
|
528 else |
|
529 { |
|
530 // NOTE, Every EAP-packet does not include EAP-type field. |
|
531 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
|
532 } |
|
533 } |
|
534 |
|
535 //-------------------------------------------------- |
|
536 |
|
537 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::write_type( |
|
538 abs_eap_am_tools_c * const am_tools, |
|
539 const u32_t index, |
|
540 void * const p_buffer, |
|
541 const u32_t buffer_length, |
|
542 const bool write_extented_type_when_true, |
|
543 #if defined(USE_EAP_EXPANDED_TYPES) |
|
544 const eap_expanded_type_c p_type ///< The EAP type to be written. |
|
545 #else |
|
546 const eap_type_ietf_values_e p_type ///< The EAP type to be written. |
|
547 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
548 ) |
|
549 { |
|
550 if (p_buffer == 0) |
|
551 { |
|
552 EAP_UNREFERENCED_PARAMETER(am_tools); |
|
553 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
554 } |
|
555 |
|
556 u8_t * const buffer = static_cast<u8_t *>(p_buffer); |
|
557 |
|
558 #if defined(USE_EAP_EXPANDED_TYPES) |
|
559 |
|
560 if (write_extented_type_when_true == false |
|
561 && is_ietf_type(p_type) == true |
|
562 && buffer_length >= eap_expanded_type_c::m_ietf_type_size*(index+1ul)) |
|
563 { |
|
564 u8_t * const type_data = |
|
565 &(buffer[eap_expanded_type_c::m_ietf_type_size*index]); |
|
566 if (type_data == 0) |
|
567 { |
|
568 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
569 } |
|
570 |
|
571 *type_data = static_cast<u8_t>(p_type.get_vendor_type()); |
|
572 } |
|
573 else if ((write_extented_type_when_true == true |
|
574 || is_ietf_type(p_type) == false) |
|
575 && buffer_length >= eap_header_base_c::get_expanded_type_field_length()*(index+1ul)) |
|
576 { |
|
577 // 0 1 2 3 |
|
578 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
|
579 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
580 // | Type | Vendor-Id | |
|
581 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
582 // | Vendor-Type | |
|
583 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
584 // | Vendor data or other Type ... |
|
585 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
586 { |
|
587 u8_t * const type_data = |
|
588 &(buffer[eap_header_base_c::get_expanded_ietf_type_offset() |
|
589 +eap_header_base_c::get_expanded_type_field_length()*index]); |
|
590 if (type_data == 0) |
|
591 { |
|
592 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
593 } |
|
594 *type_data = static_cast<u8_t>(eap_type_expanded_type); |
|
595 } |
|
596 |
|
597 { |
|
598 u8_t * const vendor_id = |
|
599 &(buffer[eap_header_base_c::get_expanded_vendor_id_offset() |
|
600 +eap_header_base_c::get_expanded_type_field_length()*index]); |
|
601 if (vendor_id == 0) |
|
602 { |
|
603 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
604 } |
|
605 eap_status_e status = eap_write_u24_t_network_order( |
|
606 vendor_id, |
|
607 3ul*sizeof(u8_t), |
|
608 static_cast<u32_t>(p_type.get_vendor_id())); |
|
609 EAP_ASSERT_ALWAYS_TOOLS(am_tools, status == eap_status_ok); |
|
610 } |
|
611 |
|
612 { |
|
613 u8_t * const vendor_type = |
|
614 &(buffer[eap_header_base_c::get_expanded_vendor_type_offset() |
|
615 +eap_header_base_c::get_expanded_type_field_length()*index]); |
|
616 if (vendor_type == 0) |
|
617 { |
|
618 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
619 } |
|
620 eap_status_e status = eap_write_u32_t_network_order( |
|
621 vendor_type, |
|
622 sizeof(u32_t), |
|
623 p_type.get_vendor_type()); |
|
624 EAP_ASSERT_ALWAYS_TOOLS(am_tools, status == eap_status_ok); |
|
625 } |
|
626 } |
|
627 else |
|
628 { |
|
629 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
630 } |
|
631 |
|
632 #else |
|
633 |
|
634 EAP_UNREFERENCED_PARAMETER(write_extented_type_when_true); // Only Expanded Type version uses this. |
|
635 |
|
636 if (buffer_length >= eap_expanded_type_c::m_ietf_type_size*(index+1ul)) |
|
637 { |
|
638 u8_t * const type_data = |
|
639 &(buffer[eap_expanded_type_c::m_ietf_type_size*index]); |
|
640 if (type_data == 0) |
|
641 { |
|
642 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
643 } |
|
644 *type_data = static_cast<u8_t>(p_type); |
|
645 } |
|
646 else |
|
647 { |
|
648 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
649 } |
|
650 |
|
651 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
652 |
|
653 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
|
654 } |
|
655 |
|
656 //-------------------------------------------------- |
|
657 |
|
658 #if defined(USE_EAP_EXPANDED_TYPES) |
|
659 |
|
660 EAP_FUNC_EXPORT i32_t eap_expanded_type_c::compare(const eap_expanded_type_c * const data) const |
|
661 { |
|
662 if (*this == *data) |
|
663 { |
|
664 return 0; |
|
665 } |
|
666 else |
|
667 { |
|
668 if (get_vendor_id() < data->get_vendor_id() |
|
669 || (get_vendor_id() == data->get_vendor_id() |
|
670 && get_vendor_type() < data->get_vendor_type())) |
|
671 { |
|
672 // (*this < *data) |
|
673 return -1; |
|
674 } |
|
675 else |
|
676 { |
|
677 // (*this > *data) |
|
678 return +1; |
|
679 } |
|
680 } |
|
681 } |
|
682 |
|
683 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
684 |
|
685 //-------------------------------------------------- |
|
686 //-------------------------------------------------- |
|
687 //-------------------------------------------------- |
|
688 |
|
689 EAP_FUNC_EXPORT const eap_expanded_type_c &eap_static_expanded_type_c::get_type() const |
|
690 { |
|
691 return *reinterpret_cast<const eap_expanded_type_c *>(this); |
|
692 } |
|
693 |
|
694 //-------------------------------------------------- |
|
695 //-------------------------------------------------- |
|
696 //-------------------------------------------------- |
|
697 |
|
698 #if defined(USE_EAP_EXPANDED_TYPES) |
|
699 |
|
700 EAP_C_FUNC_EXPORT u32_t convert_eap_type_to_u32_t(eap_type_value_e type) |
|
701 { |
|
702 // NOTE, this returns only 8 least significant bits of vendor type. |
|
703 return static_cast<u32_t>(type.get_vendor_id() << sizeof(u8_t)*8ul |
|
704 | (0xff & type.get_vendor_type())); |
|
705 } |
|
706 |
|
707 EAP_C_FUNC_EXPORT u64_t convert_eap_type_to_u64_t(eap_type_value_e type) |
|
708 { |
|
709 return static_cast<u64_t>(type.get_vendor_id()) << sizeof(u32_t)*8ul |
|
710 | static_cast<u64_t>(type.get_vendor_type()); |
|
711 } |
|
712 |
|
713 #else |
|
714 |
|
715 EAP_C_FUNC_EXPORT u32_t convert_eap_type_to_u32_t(eap_type_value_e type) |
|
716 { |
|
717 return static_cast<u32_t>(type); |
|
718 } |
|
719 |
|
720 EAP_C_FUNC_EXPORT u64_t convert_eap_type_to_u64_t(eap_type_value_e type) |
|
721 { |
|
722 return static_cast<u64_t>(type); |
|
723 } |
|
724 |
|
725 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
726 |
|
727 //-------------------------------------------------- |
|
728 //-------------------------------------------------- |
|
729 //-------------------------------------------------- |
|
730 |
|
731 |
|
732 |
|
733 // End. |