|
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 33 |
|
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 "eapol_header.h" |
|
30 |
|
31 |
|
32 //-------------------------------------------------- |
|
33 |
|
34 // |
|
35 EAP_FUNC_EXPORT eapol_header_base_c::~eapol_header_base_c() |
|
36 { |
|
37 } |
|
38 |
|
39 // |
|
40 EAP_FUNC_EXPORT eapol_header_base_c::eapol_header_base_c( |
|
41 abs_eap_am_tools_c * const tools, |
|
42 void * const header_buffer, |
|
43 const u32_t header_buffer_length) |
|
44 : eap_general_header_base_c(tools, header_buffer, header_buffer_length) |
|
45 , m_am_tools(tools) |
|
46 { |
|
47 } |
|
48 |
|
49 EAP_FUNC_EXPORT eapol_protocol_version_e eapol_header_base_c::get_version() const |
|
50 { |
|
51 const u8_t * const version_data = get_header_offset(m_version_offset, sizeof(u8_t)); |
|
52 if (version_data != 0) |
|
53 { |
|
54 return static_cast<eapol_protocol_version_e>(*version_data); |
|
55 } |
|
56 else |
|
57 { |
|
58 return eapol_protocol_version_none; |
|
59 } |
|
60 } |
|
61 |
|
62 EAP_FUNC_EXPORT eapol_packet_type_e eapol_header_base_c::get_packet_type() const |
|
63 { |
|
64 const u8_t * const type_data = get_header_offset(m_packet_type_offset, sizeof(u8_t)); |
|
65 if (type_data != 0) |
|
66 { |
|
67 return static_cast<eapol_packet_type_e>(*type_data); |
|
68 } |
|
69 else |
|
70 { |
|
71 return eapol_packet_type_no_type; |
|
72 } |
|
73 } |
|
74 |
|
75 EAP_FUNC_EXPORT u16_t eapol_header_base_c::get_data_length() const |
|
76 { |
|
77 const u8_t * const length_data = get_header_offset(m_data_length_offset, sizeof(u16_t)); |
|
78 if (length_data != 0) |
|
79 { |
|
80 return eap_read_u16_t_network_order(length_data, sizeof(u16_t)); |
|
81 } |
|
82 else |
|
83 { |
|
84 return 0ul; |
|
85 } |
|
86 } |
|
87 |
|
88 EAP_FUNC_EXPORT u32_t eapol_header_base_c::get_header_length() |
|
89 { |
|
90 return m_data_offset; |
|
91 } |
|
92 |
|
93 EAP_FUNC_EXPORT u8_t * eapol_header_base_c::get_data(const u32_t data_length) const |
|
94 { |
|
95 return get_header_offset(m_data_offset, data_length); // Data begins after the header. |
|
96 } |
|
97 |
|
98 EAP_FUNC_EXPORT void eapol_header_base_c::set_version(const eapol_protocol_version_e p_version) |
|
99 { |
|
100 u8_t * const version_data = get_header_offset(m_version_offset, sizeof(u8_t)); |
|
101 EAP_ASSERT(version_data != 0); |
|
102 *version_data = static_cast<u8_t>(p_version); |
|
103 } |
|
104 |
|
105 EAP_FUNC_EXPORT void eapol_header_base_c::set_packet_type(const eapol_packet_type_e p_packet_type) |
|
106 { |
|
107 u8_t * const type_data = get_header_offset(m_packet_type_offset, sizeof(u8_t)); |
|
108 EAP_ASSERT(type_data != 0); |
|
109 *type_data = static_cast<u8_t>(p_packet_type); |
|
110 } |
|
111 |
|
112 EAP_FUNC_EXPORT void eapol_header_base_c::set_data_length(const u16_t p_data_length) |
|
113 { |
|
114 u8_t * const data_length = get_header_offset(m_data_length_offset, sizeof(u16_t)); |
|
115 EAP_ASSERT(data_length != 0); |
|
116 data_length[0] = static_cast<u8_t>((p_data_length & 0xff00) >> 8); |
|
117 data_length[1] = static_cast<u8_t>(p_data_length & 0x00ff); |
|
118 } |
|
119 |
|
120 EAP_FUNC_EXPORT eap_const_string eapol_header_base_c::get_type_string() const |
|
121 { |
|
122 |
|
123 #if defined(USE_EAP_TRACE_STRINGS) |
|
124 eapol_packet_type_e type = get_packet_type(); |
|
125 |
|
126 EAP_IF_RETURN_STRING(type, eapol_packet_type_eap) |
|
127 else EAP_IF_RETURN_STRING(type, eapol_packet_type_start) |
|
128 else EAP_IF_RETURN_STRING(type, eapol_packet_type_logoff) |
|
129 else EAP_IF_RETURN_STRING(type, eapol_packet_type_key) |
|
130 else EAP_IF_RETURN_STRING(type, eapol_packet_type_enc_asf_alert) |
|
131 else EAP_IF_RETURN_STRING(type, eapol_packet_type_SAE_KE) |
|
132 else EAP_IF_RETURN_STRING(type, eapol_packet_type_SAE_EAP) |
|
133 else EAP_IF_RETURN_STRING(type, eapol_packet_type_SAE_START) |
|
134 else EAP_IF_RETURN_STRING(type, eapol_packet_type_SAE_LOGOFF) |
|
135 else EAP_IF_RETURN_STRING(type, eapol_packet_type_no_type) |
|
136 else |
|
137 #endif // #if defined(USE_EAP_TRACE_STRINGS) |
|
138 { |
|
139 return EAPL("Unknown EAPOL-type"); |
|
140 } |
|
141 } |
|
142 |
|
143 EAP_FUNC_EXPORT eap_status_e eapol_header_base_c::check_header() const |
|
144 { |
|
145 eap_status_e status = eap_status_process_general_error; |
|
146 |
|
147 if (get_version() == eapol_protocol_version_none) |
|
148 { |
|
149 status = eap_status_wrong_eapol_version; |
|
150 |
|
151 EAP_TRACE_DEBUG( |
|
152 m_am_tools, |
|
153 TRACE_FLAGS_DEFAULT, |
|
154 (EAPL("ERROR: eapol_header_base_c::check_header(), illegal version field 0x%02x, at least 0x%02x was expected, eap_status_e %d\n"), |
|
155 get_version(), |
|
156 eapol_protocol_version_none+1, |
|
157 status)); |
|
158 } |
|
159 else if (/* get_packet_type() < eapol_packet_type_eap // This is always false. |
|
160 || */ |
|
161 eapol_packet_type_SAE_LOGOFF < get_packet_type()) |
|
162 { |
|
163 status = eap_status_wrong_eapol_type; |
|
164 |
|
165 EAP_TRACE_DEBUG( |
|
166 m_am_tools, |
|
167 TRACE_FLAGS_DEFAULT, |
|
168 (EAPL("ERROR: eapol_header_base_c::check_header(), illegal type field 0x%02x, eap_status_e %d\n"), |
|
169 get_packet_type(), status)); |
|
170 } |
|
171 else |
|
172 { |
|
173 status = eap_status_ok; |
|
174 } |
|
175 return EAP_STATUS_RETURN(m_am_tools, status); |
|
176 } |
|
177 |
|
178 //-------------------------------------------------- |
|
179 //-------------------------------------------------- |
|
180 //-------------------------------------------------- |
|
181 |
|
182 // |
|
183 EAP_FUNC_EXPORT eapol_header_rd_c::~eapol_header_rd_c() |
|
184 { |
|
185 } |
|
186 |
|
187 // |
|
188 EAP_FUNC_EXPORT eapol_header_rd_c::eapol_header_rd_c( |
|
189 abs_eap_am_tools_c * const tools, |
|
190 u8_t * const header_buffer, |
|
191 const u32_t header_buffer_length) |
|
192 : eapol_header_base_c(tools, header_buffer, header_buffer_length) |
|
193 , m_am_tools(tools) |
|
194 { |
|
195 } |
|
196 |
|
197 EAP_FUNC_EXPORT u8_t * eapol_header_rd_c::get_eap_header() const |
|
198 { |
|
199 return get_data(eap_header_base_c::get_header_length()); |
|
200 } |
|
201 |
|
202 //-------------------------------------------------- |
|
203 //-------------------------------------------------- |
|
204 //-------------------------------------------------- |
|
205 |
|
206 // |
|
207 EAP_FUNC_EXPORT eapol_header_wr_c::~eapol_header_wr_c() |
|
208 { |
|
209 } |
|
210 |
|
211 //-------------------------------------------------- |
|
212 |
|
213 // |
|
214 EAP_FUNC_EXPORT eapol_header_wr_c::eapol_header_wr_c( |
|
215 abs_eap_am_tools_c * const tools, |
|
216 u8_t * const header_buffer, |
|
217 const u32_t header_buffer_length) |
|
218 : eapol_header_base_c(tools, header_buffer, header_buffer_length) |
|
219 , m_am_tools(tools) |
|
220 { |
|
221 } |
|
222 |
|
223 //-------------------------------------------------- |
|
224 |
|
225 EAP_FUNC_EXPORT u8_t * eapol_header_wr_c::get_eap_header() |
|
226 { |
|
227 return get_data(eap_header_base_c::get_header_length()); |
|
228 } |
|
229 |
|
230 //-------------------------------------------------- |
|
231 |
|
232 EAP_FUNC_EXPORT void eapol_header_wr_c::reset_header(u16_t buffer_length) |
|
233 { |
|
234 set_version(eapol_protocol_version_none); |
|
235 set_packet_type(eapol_packet_type_eap); |
|
236 EAP_ASSERT(buffer_length >= get_header_length()); |
|
237 set_data_length(static_cast<u16_t>(buffer_length-get_header_length())); |
|
238 } |
|
239 |
|
240 //-------------------------------------------------- |
|
241 |
|
242 |
|
243 |
|
244 // End. |