|
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 39 |
|
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_am_memory.h" |
|
30 #include "eap_tlv_header.h" |
|
31 |
|
32 /** @file */ |
|
33 |
|
34 //-------------------------------------------------- |
|
35 |
|
36 EAP_FUNC_EXPORT eap_tlv_header_c::~eap_tlv_header_c() |
|
37 { |
|
38 } |
|
39 |
|
40 //-------------------------------------------------- |
|
41 |
|
42 EAP_FUNC_EXPORT eap_tlv_header_c::eap_tlv_header_c( |
|
43 abs_eap_am_tools_c * const tools, |
|
44 void * const header_begin, |
|
45 const u32_t header_buffer_length) |
|
46 : eap_general_header_base_c(tools, header_begin, header_buffer_length) |
|
47 , m_am_tools(tools) |
|
48 { |
|
49 } |
|
50 |
|
51 //-------------------------------------------------- |
|
52 |
|
53 EAP_FUNC_EXPORT eap_tlv_type_t eap_tlv_header_c::get_type() const |
|
54 { |
|
55 const u8_t * const tlv_type_data = get_header_offset(m_type_offset, sizeof(u32_t)); |
|
56 if (tlv_type_data != 0) |
|
57 { |
|
58 return static_cast<eap_tlv_type_t>(eap_read_u32_t_network_order(tlv_type_data, sizeof(u32_t))); |
|
59 } |
|
60 else |
|
61 { |
|
62 return eap_tlv_type_none; |
|
63 } |
|
64 } |
|
65 |
|
66 //-------------------------------------------------- |
|
67 |
|
68 EAP_FUNC_EXPORT u32_t eap_tlv_header_c::get_value_length() const |
|
69 { |
|
70 const u8_t * const tlv_length_data = get_header_offset(m_length_offset, sizeof(u32_t)); |
|
71 if (tlv_length_data != 0) |
|
72 { |
|
73 return eap_read_u32_t_network_order(tlv_length_data, sizeof(u32_t)); |
|
74 } |
|
75 else |
|
76 { |
|
77 return 0ul; |
|
78 } |
|
79 } |
|
80 |
|
81 //-------------------------------------------------- |
|
82 |
|
83 EAP_FUNC_EXPORT u32_t eap_tlv_header_c::get_header_length() |
|
84 { |
|
85 return m_data_offset; |
|
86 } |
|
87 |
|
88 //-------------------------------------------------- |
|
89 |
|
90 EAP_FUNC_EXPORT u8_t * eap_tlv_header_c::get_value_offset(const u32_t offset, const u32_t contignuous_bytes) const |
|
91 { |
|
92 EAP_UNREFERENCED_PARAMETER(m_am_tools); |
|
93 |
|
94 u32_t data_length = get_value_length(); |
|
95 |
|
96 if (data_length >= offset+contignuous_bytes) |
|
97 { |
|
98 u8_t * const data = get_header_offset(m_data_offset, offset+contignuous_bytes); |
|
99 if (data != 0) |
|
100 { |
|
101 return &data[offset]; |
|
102 } |
|
103 else |
|
104 { |
|
105 return 0; |
|
106 } |
|
107 } |
|
108 else |
|
109 { |
|
110 EAP_ASSERT_ALWAYS(data_length >= offset+contignuous_bytes); |
|
111 } |
|
112 return 0; |
|
113 } |
|
114 |
|
115 |
|
116 //-------------------------------------------------- |
|
117 |
|
118 EAP_FUNC_EXPORT u8_t * eap_tlv_header_c::get_value(const u32_t contignuous_bytes) const |
|
119 { |
|
120 return get_value_offset(0u, contignuous_bytes); |
|
121 } |
|
122 |
|
123 |
|
124 //-------------------------------------------------- |
|
125 |
|
126 EAP_FUNC_EXPORT eap_status_e eap_tlv_header_c::check_header() const |
|
127 { |
|
128 if ((get_header_length() + get_value_length()) > get_header_buffer_length()) |
|
129 { |
|
130 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
131 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
132 } |
|
133 |
|
134 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
135 } |
|
136 |
|
137 //-------------------------------------------------- |
|
138 |
|
139 EAP_FUNC_EXPORT eap_status_e eap_tlv_header_c::set_type(const eap_tlv_type_t type) |
|
140 { |
|
141 if (type == eap_tlv_type_none) |
|
142 { |
|
143 EAP_ASSERT(type != eap_tlv_type_none); |
|
144 return EAP_STATUS_RETURN(m_am_tools, eap_status_wrong_type); |
|
145 } |
|
146 |
|
147 u8_t * const type_data = get_header_offset(m_type_offset, sizeof(u32_t)); |
|
148 |
|
149 if (type_data == 0) |
|
150 { |
|
151 EAP_ASSERT(type_data != 0); |
|
152 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
153 } |
|
154 |
|
155 eap_write_u32_t_network_order(type_data, sizeof(u32_t), type); |
|
156 |
|
157 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
158 } |
|
159 |
|
160 //-------------------------------------------------- |
|
161 |
|
162 EAP_FUNC_EXPORT eap_status_e eap_tlv_header_c::set_value_length(const u32_t value_length) |
|
163 { |
|
164 if (get_header_length() + value_length > get_header_buffer_length()) |
|
165 { |
|
166 EAP_ASSERT(get_header_length() + value_length <= get_header_buffer_length()); |
|
167 return EAP_STATUS_RETURN(m_am_tools, eap_status_too_long_message); |
|
168 } |
|
169 |
|
170 u8_t * const length_data = get_header_offset(m_length_offset, sizeof(u32_t)); |
|
171 |
|
172 if (length_data == 0) |
|
173 { |
|
174 EAP_ASSERT(length_data != 0); |
|
175 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
176 } |
|
177 |
|
178 eap_write_u32_t_network_order(length_data, sizeof(u32_t), value_length); |
|
179 |
|
180 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
181 } |
|
182 |
|
183 //-------------------------------------------------- |
|
184 |
|
185 EAP_FUNC_EXPORT eap_status_e eap_tlv_header_c::reset_header( |
|
186 const eap_tlv_type_t type, |
|
187 const u32_t value_length) |
|
188 { |
|
189 eap_status_e status = set_type(type); |
|
190 if (status != eap_status_ok) |
|
191 { |
|
192 return EAP_STATUS_RETURN(m_am_tools, status); |
|
193 } |
|
194 |
|
195 status = set_value_length(value_length); |
|
196 if (status != eap_status_ok) |
|
197 { |
|
198 return EAP_STATUS_RETURN(m_am_tools, status); |
|
199 } |
|
200 |
|
201 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
202 } |
|
203 |
|
204 //-------------------------------------------------- |
|
205 |
|
206 |
|
207 |
|
208 // End. |