65 m_vendor_type = static_cast<u32_t>(type); |
65 m_vendor_type = static_cast<u32_t>(type); |
66 } |
66 } |
67 |
67 |
68 //-------------------------------------------------- |
68 //-------------------------------------------------- |
69 |
69 |
|
70 EAP_FUNC_EXPORT bool eap_expanded_type_c::get_is_valid() const |
|
71 { |
|
72 return true; |
|
73 } |
|
74 |
|
75 //-------------------------------------------------- |
|
76 |
|
77 EAP_FUNC_EXPORT bool eap_expanded_type_c::get_is_valid_data() const |
|
78 { |
|
79 return get_is_valid(); |
|
80 } |
|
81 |
|
82 //-------------------------------------------------- |
|
83 |
|
84 EAP_FUNC_EXPORT eap_expanded_type_c * eap_expanded_type_c::copy() const |
|
85 { |
|
86 eap_expanded_type_c * const new_entry = new eap_expanded_type_c; |
|
87 |
|
88 if (new_entry == 0 |
|
89 || new_entry->get_is_valid() == false) |
|
90 { |
|
91 delete new_entry; |
|
92 return 0; |
|
93 } |
|
94 |
|
95 new_entry->set_eap_type_values(m_vendor_id, m_vendor_type); |
|
96 |
|
97 return new_entry; |
|
98 } |
|
99 |
|
100 //-------------------------------------------------- |
|
101 |
70 EAP_FUNC_EXPORT bool eap_expanded_type_c::is_expanded_type(const eap_type_ietf_values_e eap_type) |
102 EAP_FUNC_EXPORT bool eap_expanded_type_c::is_expanded_type(const eap_type_ietf_values_e eap_type) |
71 { |
103 { |
72 return (eap_type == eap_type_expanded_type); |
104 return (eap_type == eap_type_expanded_type); |
73 } |
105 } |
74 |
106 |
75 //-------------------------------------------------- |
107 //-------------------------------------------------- |
76 |
108 |
77 #if defined(USE_EAP_EXPANDED_TYPES) |
|
78 EAP_FUNC_EXPORT bool eap_expanded_type_c::is_ietf_type(const eap_expanded_type_c eap_type) |
109 EAP_FUNC_EXPORT bool eap_expanded_type_c::is_ietf_type(const eap_expanded_type_c eap_type) |
79 { |
110 { |
80 return (eap_type.get_vendor_id() == eap_type_vendor_id_ietf |
111 return (eap_type.get_vendor_id() == eap_type_vendor_id_ietf |
81 && eap_type.get_vendor_type() < eap_type_expanded_type); |
112 && eap_type.get_vendor_type() < eap_type_expanded_type); |
82 } |
113 } |
83 |
114 |
84 #else |
|
85 EAP_FUNC_EXPORT bool eap_expanded_type_c::is_ietf_type(const eap_type_ietf_values_e eap_type) |
|
86 { |
|
87 return (eap_type < eap_type_expanded_type); |
|
88 } |
|
89 |
|
90 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
91 |
|
92 //-------------------------------------------------- |
115 //-------------------------------------------------- |
93 |
116 |
94 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::get_type_data( |
117 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::get_type_data( |
95 abs_eap_am_tools_c * const am_tools, |
118 abs_eap_am_tools_c * const am_tools, |
96 eap_type_ietf_values_e * const type) |
119 eap_type_ietf_values_e * const type) const |
97 { |
120 { |
98 if (type == 0) |
121 if (type == 0) |
99 { |
122 { |
100 EAP_UNREFERENCED_PARAMETER(am_tools); |
123 EAP_UNREFERENCED_PARAMETER(am_tools); |
101 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
124 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
118 |
141 |
119 //-------------------------------------------------- |
142 //-------------------------------------------------- |
120 |
143 |
121 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::get_type_data( |
144 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::get_type_data( |
122 abs_eap_am_tools_c * const am_tools, |
145 abs_eap_am_tools_c * const am_tools, |
123 eap_expanded_type_c * const type) |
146 eap_expanded_type_c * const type) const |
124 { |
147 { |
125 if (type == 0) |
148 if (type == 0) |
126 { |
149 { |
127 EAP_UNREFERENCED_PARAMETER(am_tools); |
150 EAP_UNREFERENCED_PARAMETER(am_tools); |
128 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
151 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
135 |
158 |
136 //-------------------------------------------------- |
159 //-------------------------------------------------- |
137 |
160 |
138 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::get_expanded_type_data( |
161 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::get_expanded_type_data( |
139 abs_eap_am_tools_c * const am_tools, |
162 abs_eap_am_tools_c * const am_tools, |
140 eap_variable_data_c * const data) |
163 eap_variable_data_c * const data) const |
141 { |
164 { |
142 if (data == 0) |
165 if (data == 0 |
|
166 || data->get_is_valid() == false) |
143 { |
167 { |
144 EAP_UNREFERENCED_PARAMETER(am_tools); |
168 EAP_UNREFERENCED_PARAMETER(am_tools); |
145 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
169 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
146 } |
170 } |
147 |
171 |
219 |
243 |
220 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::set_expanded_type_data( |
244 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::set_expanded_type_data( |
221 abs_eap_am_tools_c * const am_tools, |
245 abs_eap_am_tools_c * const am_tools, |
222 const eap_variable_data_c * const data) |
246 const eap_variable_data_c * const data) |
223 { |
247 { |
224 if (data->get_data_length() != get_eap_expanded_type_size() |
248 if (data == 0 |
|
249 || data->get_data_length() != get_eap_expanded_type_size() |
225 || data->get_data(data->get_data_length()) == 0) |
250 || data->get_data(data->get_data_length()) == 0) |
226 { |
251 { |
227 EAP_UNREFERENCED_PARAMETER(am_tools); |
252 EAP_UNREFERENCED_PARAMETER(am_tools); |
228 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
253 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
229 } |
254 } |
255 m_vendor_id = static_cast<eap_type_vendor_id_e>(eap_read_u24_t_network_order(vendor_id, m_vendor_id_size)); |
280 m_vendor_id = static_cast<eap_type_vendor_id_e>(eap_read_u24_t_network_order(vendor_id, m_vendor_id_size)); |
256 } |
281 } |
257 |
282 |
258 { |
283 { |
259 u8_t * const vendor_type = data->get_data_offset(offset, m_vendor_type_size); |
284 u8_t * const vendor_type = data->get_data_offset(offset, m_vendor_type_size); |
|
285 if (vendor_type == 0) |
|
286 { |
|
287 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
288 } |
|
289 offset += m_vendor_type_size; |
|
290 |
|
291 m_vendor_type = eap_read_u32_t_network_order(vendor_type, m_vendor_type_size); |
|
292 } |
|
293 |
|
294 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
|
295 } |
|
296 |
|
297 //-------------------------------------------------- |
|
298 |
|
299 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::set_expanded_type_data( |
|
300 abs_eap_am_tools_c * const am_tools, |
|
301 const void * const data, |
|
302 const u32_t data_length) |
|
303 { |
|
304 if (data_length != get_eap_expanded_type_size() |
|
305 || data == 0) |
|
306 { |
|
307 EAP_UNREFERENCED_PARAMETER(am_tools); |
|
308 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
309 } |
|
310 |
|
311 u32_t offset = 0ul; |
|
312 |
|
313 { |
|
314 const u8_t * const ietf_type = &(reinterpret_cast<const u8_t *>(data)[offset]); |
|
315 if (ietf_type == 0) |
|
316 { |
|
317 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
318 } |
|
319 offset += m_ietf_type_size; |
|
320 |
|
321 if (static_cast<eap_type_ietf_values_e>(*ietf_type) != eap_type_expanded_type) |
|
322 { |
|
323 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
324 } |
|
325 } |
|
326 |
|
327 { |
|
328 const u8_t * const vendor_id = &(reinterpret_cast<const u8_t *>(data)[offset]); |
|
329 if (vendor_id == 0) |
|
330 { |
|
331 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
|
332 } |
|
333 offset += m_vendor_id_size; |
|
334 |
|
335 m_vendor_id = static_cast<eap_type_vendor_id_e>(eap_read_u24_t_network_order(vendor_id, m_vendor_id_size)); |
|
336 } |
|
337 |
|
338 { |
|
339 const u8_t * const vendor_type = &(reinterpret_cast<const u8_t *>(data)[offset]); |
260 if (vendor_type == 0) |
340 if (vendor_type == 0) |
261 { |
341 { |
262 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
342 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
263 } |
343 } |
264 offset += m_vendor_type_size; |
344 offset += m_vendor_type_size; |
389 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::read_type( |
469 EAP_FUNC_EXPORT eap_status_e eap_expanded_type_c::read_type( |
390 abs_eap_am_tools_c * const am_tools, |
470 abs_eap_am_tools_c * const am_tools, |
391 const u32_t index, |
471 const u32_t index, |
392 const void * const p_buffer, |
472 const void * const p_buffer, |
393 const u32_t buffer_length, |
473 const u32_t buffer_length, |
394 #if defined(USE_EAP_EXPANDED_TYPES) |
|
395 eap_expanded_type_c * const type |
474 eap_expanded_type_c * const type |
396 #else |
|
397 eap_type_ietf_values_e * const type |
|
398 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
399 ) |
475 ) |
400 { |
476 { |
401 if (p_buffer == 0) |
477 if (p_buffer == 0) |
402 { |
478 { |
403 EAP_UNREFERENCED_PARAMETER(am_tools); |
479 EAP_UNREFERENCED_PARAMETER(am_tools); |
497 vendor_type_value = eap_read_u32_t_network_order( |
573 vendor_type_value = eap_read_u32_t_network_order( |
498 vendor_type, |
574 vendor_type, |
499 sizeof(u32_t)); |
575 sizeof(u32_t)); |
500 } |
576 } |
501 |
577 |
502 #if defined(USE_EAP_EXPANDED_TYPES) |
|
503 type->set_eap_type_values( |
578 type->set_eap_type_values( |
504 vendor_id_value, |
579 vendor_id_value, |
505 vendor_type_value); |
580 vendor_type_value); |
506 |
581 |
507 EAP_ASSERT_TOOLS(am_tools, (ietf_eap_type == eap_type_expanded_type)); |
582 EAP_ASSERT_TOOLS(am_tools, (ietf_eap_type == eap_type_expanded_type)); |
508 #else |
|
509 if (vendor_id_value == eap_type_vendor_id_ietf) |
|
510 { |
|
511 *type = static_cast<eap_type_value_e>(vendor_type_value); // Type field follows eap_header_c. |
|
512 } |
|
513 else |
|
514 { |
|
515 *type = ietf_eap_type; // Type field follows eap_header_c. |
|
516 } |
|
517 #endif |
|
518 |
583 |
519 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
584 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
520 } |
585 } |
521 else |
586 else |
522 { |
587 { |
541 abs_eap_am_tools_c * const am_tools, |
606 abs_eap_am_tools_c * const am_tools, |
542 const u32_t index, |
607 const u32_t index, |
543 void * const p_buffer, |
608 void * const p_buffer, |
544 const u32_t buffer_length, |
609 const u32_t buffer_length, |
545 const bool write_extented_type_when_true, |
610 const bool write_extented_type_when_true, |
546 #if defined(USE_EAP_EXPANDED_TYPES) |
|
547 const eap_expanded_type_c p_type ///< The EAP type to be written. |
611 const eap_expanded_type_c p_type ///< The EAP type to be written. |
548 #else |
|
549 const eap_type_ietf_values_e p_type ///< The EAP type to be written. |
|
550 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
551 ) |
612 ) |
552 { |
613 { |
553 if (p_buffer == 0) |
614 if (p_buffer == 0) |
554 { |
615 { |
555 EAP_UNREFERENCED_PARAMETER(am_tools); |
616 EAP_UNREFERENCED_PARAMETER(am_tools); |
556 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
617 return EAP_STATUS_RETURN(am_tools, eap_status_illegal_parameter); |
557 } |
618 } |
558 |
619 |
559 u8_t * const buffer = static_cast<u8_t *>(p_buffer); |
620 u8_t * const buffer = static_cast<u8_t *>(p_buffer); |
560 |
|
561 #if defined(USE_EAP_EXPANDED_TYPES) |
|
562 |
621 |
563 if (write_extented_type_when_true == false |
622 if (write_extented_type_when_true == false |
564 && is_ietf_type(p_type) == true |
623 && is_ietf_type(p_type) == true |
565 && buffer_length >= eap_expanded_type_c::m_ietf_type_size*(index+1ul)) |
624 && buffer_length >= eap_expanded_type_c::m_ietf_type_size*(index+1ul)) |
566 { |
625 { |
630 else |
689 else |
631 { |
690 { |
632 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
691 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
633 } |
692 } |
634 |
693 |
635 #else |
|
636 |
|
637 EAP_UNREFERENCED_PARAMETER(write_extented_type_when_true); // Only Expanded Type version uses this. |
|
638 |
|
639 if (buffer_length >= eap_expanded_type_c::m_ietf_type_size*(index+1ul)) |
|
640 { |
|
641 u8_t * const type_data = |
|
642 &(buffer[eap_expanded_type_c::m_ietf_type_size*index]); |
|
643 if (type_data == 0) |
|
644 { |
|
645 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
646 } |
|
647 *type_data = static_cast<u8_t>(p_type); |
|
648 } |
|
649 else |
|
650 { |
|
651 return EAP_STATUS_RETURN(am_tools, eap_status_allocation_error); |
|
652 } |
|
653 |
|
654 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
655 |
|
656 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
694 return EAP_STATUS_RETURN(am_tools, eap_status_ok); |
657 } |
695 } |
658 |
696 |
659 //-------------------------------------------------- |
697 //-------------------------------------------------- |
660 |
|
661 #if defined(USE_EAP_EXPANDED_TYPES) |
|
662 |
698 |
663 EAP_FUNC_EXPORT i32_t eap_expanded_type_c::compare(const eap_expanded_type_c * const data) const |
699 EAP_FUNC_EXPORT i32_t eap_expanded_type_c::compare(const eap_expanded_type_c * const data) const |
664 { |
700 { |
665 if (*this == *data) |
701 if (*this == *data) |
666 { |
702 { |
681 return +1; |
717 return +1; |
682 } |
718 } |
683 } |
719 } |
684 } |
720 } |
685 |
721 |
686 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
687 |
|
688 //-------------------------------------------------- |
722 //-------------------------------------------------- |
689 //-------------------------------------------------- |
723 //-------------------------------------------------- |
690 //-------------------------------------------------- |
724 //-------------------------------------------------- |
691 |
725 |
692 EAP_FUNC_EXPORT const eap_expanded_type_c &eap_static_expanded_type_c::get_type() const |
726 EAP_FUNC_EXPORT const eap_expanded_type_c &eap_static_expanded_type_c::get_type() const |
695 } |
729 } |
696 |
730 |
697 //-------------------------------------------------- |
731 //-------------------------------------------------- |
698 //-------------------------------------------------- |
732 //-------------------------------------------------- |
699 //-------------------------------------------------- |
733 //-------------------------------------------------- |
700 |
|
701 #if defined(USE_EAP_EXPANDED_TYPES) |
|
702 |
734 |
703 EAP_C_FUNC_EXPORT u32_t convert_eap_type_to_u32_t(eap_type_value_e type) |
735 EAP_C_FUNC_EXPORT u32_t convert_eap_type_to_u32_t(eap_type_value_e type) |
704 { |
736 { |
705 // NOTE, this returns only 8 least significant bits of vendor type. |
737 // NOTE, this returns only 8 least significant bits of vendor type. |
706 return static_cast<u32_t>(type.get_vendor_id() << sizeof(u8_t)*8ul |
738 return static_cast<u32_t>(type.get_vendor_id() << sizeof(u8_t)*8ul |
711 { |
743 { |
712 return static_cast<u64_t>(type.get_vendor_id()) << sizeof(u32_t)*8ul |
744 return static_cast<u64_t>(type.get_vendor_id()) << sizeof(u32_t)*8ul |
713 | static_cast<u64_t>(type.get_vendor_type()); |
745 | static_cast<u64_t>(type.get_vendor_type()); |
714 } |
746 } |
715 |
747 |
716 #else |
|
717 |
|
718 EAP_C_FUNC_EXPORT u32_t convert_eap_type_to_u32_t(eap_type_value_e type) |
|
719 { |
|
720 return static_cast<u32_t>(type); |
|
721 } |
|
722 |
|
723 EAP_C_FUNC_EXPORT u64_t convert_eap_type_to_u64_t(eap_type_value_e type) |
|
724 { |
|
725 return static_cast<u64_t>(type); |
|
726 } |
|
727 |
|
728 #endif //#if defined(USE_EAP_EXPANDED_TYPES) |
|
729 |
|
730 //-------------------------------------------------- |
748 //-------------------------------------------------- |
731 //-------------------------------------------------- |
749 //-------------------------------------------------- |
732 //-------------------------------------------------- |
750 //-------------------------------------------------- |
733 |
751 |
734 |
752 |