|
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 |
|
20 |
|
21 |
|
22 #if !defined(_EAP_HEADER_H_) |
|
23 #define _EAP_HEADER_H_ |
|
24 |
|
25 |
|
26 #include "eap_general_header_base.h" |
|
27 #include "eap_expanded_type.h" |
|
28 |
|
29 |
|
30 /** @file */ |
|
31 |
|
32 //----------------------------------------------------------------------------------------- |
|
33 |
|
34 /** This is base class defining the EAP-packet header. |
|
35 * @code |
|
36 * Original EAP-header. |
|
37 * 0 1 2 3 |
|
38 * 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 |
|
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
40 * | Code | Identifier | Length | |
|
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
42 * | Type | Type data ... |
|
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
44 * 0 1 2 3 |
|
45 * |
|
46 * EAP-header with expanded type field. |
|
47 * 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 |
|
48 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
49 * | Code | Identifier | Length | |
|
50 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
51 * | Type | Vendor-Id | |
|
52 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
53 * | Vendor-Type | |
|
54 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
55 * | Type data ... |
|
56 * +-+-+-+-+-+-+-+-+ |
|
57 * @endcode |
|
58 */ |
|
59 class EAP_EXPORT eap_header_base_c |
|
60 : public eap_general_header_base_c |
|
61 { |
|
62 private: |
|
63 //-------------------------------------------------- |
|
64 |
|
65 /// This is pointer to the tools class. |
|
66 abs_eap_am_tools_c * const m_am_tools; |
|
67 |
|
68 /** |
|
69 * This enumeration defines the offsets of the EAP-header fields. |
|
70 */ |
|
71 enum offsets |
|
72 { |
|
73 m_code_offset = 0ul, ///< This is offset to code field. |
|
74 m_identifier_offset = m_code_offset+sizeof(u8_t), ///< This is offset to identifier field. |
|
75 m_length_offset = m_identifier_offset+sizeof(u8_t), ///< This is offset to length field. |
|
76 |
|
77 m_type_offset = m_length_offset+sizeof(u16_t), ///< This is offset to optional type field. |
|
78 m_data_offset = m_type_offset+sizeof(u8_t), ///< This is offset to optional data field. |
|
79 |
|
80 m_exp_ietf_type_offset = 0ul, ///< This is offset of extented type IETF type field in the Extepanded Type field. |
|
81 m_exp_vendor_id_offset = m_exp_ietf_type_offset+eap_expanded_type_c::m_ietf_type_size, ///< This is offset of extented type vendor ID field in the Extepanded Type field. |
|
82 m_exp_vendor_type_offset = m_exp_vendor_id_offset+eap_expanded_type_c::m_vendor_id_size, ///< This is offset of extented type vendor type field in the Extepanded Type field. |
|
83 }; |
|
84 |
|
85 //-------------------------------------------------- |
|
86 public: |
|
87 //-------------------------------------------------- |
|
88 |
|
89 /// Destructor does nothing special. |
|
90 EAP_FUNC_IMPORT virtual ~eap_header_base_c(); |
|
91 |
|
92 /// Constructor does nothing special. |
|
93 /// The tools parameter is pointer to tools object. |
|
94 /// The header_buffer parameter is pointer to buffer of EAP-packet including header and data. |
|
95 /// The header_buffer_length parameter is length of the header_buffer. |
|
96 EAP_FUNC_IMPORT eap_header_base_c( |
|
97 abs_eap_am_tools_c * const tools, |
|
98 void * const header_buffer, |
|
99 const u32_t header_buffer_length); |
|
100 |
|
101 /// This function returns the header length of the EAP-packet. |
|
102 EAP_FUNC_IMPORT static u32_t get_header_length(); |
|
103 |
|
104 /// This function returns the length of the ietf type field. |
|
105 EAP_FUNC_IMPORT static u32_t get_ietf_type_field_length(); |
|
106 |
|
107 /// This function returns the length of the extented type field. |
|
108 EAP_FUNC_IMPORT static u32_t get_expanded_type_field_length(); |
|
109 |
|
110 /// This function returns the offset of the IETF type field. |
|
111 EAP_FUNC_IMPORT static u32_t get_expanded_ietf_type_offset(); |
|
112 |
|
113 /// This function returns the offset of the vendor ID of type field. |
|
114 EAP_FUNC_IMPORT static u32_t get_expanded_vendor_id_offset(); |
|
115 |
|
116 /// This function returns the offset of the vendor type of type field. |
|
117 EAP_FUNC_IMPORT static u32_t get_expanded_vendor_type_offset(); |
|
118 |
|
119 /// This function returns the offset of the start of the type data. |
|
120 EAP_FUNC_IMPORT static u32_t get_type_data_start_offset( |
|
121 const bool expanded_type_when_true); |
|
122 |
|
123 |
|
124 /// This function returns the code field of EAP-header. |
|
125 EAP_FUNC_IMPORT eap_code_value_e get_code() const; |
|
126 |
|
127 /// This function returns the identifier field of EAP-header. |
|
128 EAP_FUNC_IMPORT u8_t get_identifier() const; |
|
129 |
|
130 /// This function returns the length field of EAP-header. |
|
131 EAP_FUNC_IMPORT u16_t get_length() const; |
|
132 |
|
133 /// This function returns the IETF type field of EAP-header. |
|
134 /// This means the first 8-bits of type field, whether it is short or expanded type. |
|
135 EAP_FUNC_IMPORT eap_type_ietf_values_e get_ietf_type() const; |
|
136 |
|
137 /// This function returns the type field of EAP-header. |
|
138 EAP_FUNC_IMPORT eap_type_value_e get_type() const; |
|
139 |
|
140 /// This function returns the length of type field of EAP-header. |
|
141 EAP_FUNC_IMPORT u32_t get_type_field_length() const; |
|
142 |
|
143 /// This function returns the type data length of EAP-packet. |
|
144 EAP_FUNC_IMPORT u16_t get_type_data_length() const; |
|
145 |
|
146 /// This function returns the data length of EAP-packet. |
|
147 /// The data length includes type field. |
|
148 EAP_FUNC_IMPORT u16_t get_data_length() const; |
|
149 |
|
150 /// This function returns the pointer to the offset of the type data field of EAP-packet. |
|
151 EAP_FUNC_IMPORT u8_t * get_type_data_offset( |
|
152 const u32_t p_offset, const u32_t p_continuous_bytes) const; |
|
153 |
|
154 /// This function returns the pointer to the offset of the data field of EAP-packet. |
|
155 /// Data field includes type field. |
|
156 EAP_FUNC_IMPORT u8_t * get_data_offset( |
|
157 const u32_t p_offset, const u32_t p_continuous_bytes) const; |
|
158 |
|
159 /// This function returns the pointer to the type data field of EAP-packet. |
|
160 EAP_FUNC_IMPORT u8_t * get_type_data( |
|
161 const u32_t p_continuous_bytes) const; |
|
162 |
|
163 /// This function returns the pointer to the data field of EAP-packet. |
|
164 /// Data field includes type field. |
|
165 EAP_FUNC_IMPORT u8_t * get_data( |
|
166 const u32_t p_continuous_bytes) const; |
|
167 |
|
168 /// This function sets the code field of the EAP-header. |
|
169 EAP_FUNC_IMPORT void set_code(const eap_code_value_e p_code); |
|
170 |
|
171 /// This function sets the identifier field of the EAP-header. |
|
172 EAP_FUNC_IMPORT void set_identifier(const u8_t p_identifier); |
|
173 |
|
174 /// This function sets the length field of the EAP-header. |
|
175 EAP_FUNC_IMPORT void set_length( |
|
176 const u16_t p_length, |
|
177 const bool expanded_type_when_true); |
|
178 |
|
179 /// This function sets the length field of the EAP-header using the length of the type data. |
|
180 EAP_FUNC_IMPORT void set_type_data_length( |
|
181 const u16_t p_length, |
|
182 const bool expanded_type_when_true); |
|
183 |
|
184 /// This function sets the type field of the EAP-header. |
|
185 EAP_FUNC_IMPORT eap_status_e set_type( |
|
186 const eap_type_value_e p_type, |
|
187 const bool expanded_type_when_true); |
|
188 |
|
189 /// This function returns debug string of the code of the EAP-packet. |
|
190 EAP_FUNC_IMPORT eap_const_string get_code_string() const; |
|
191 |
|
192 /// This function returns debug string of the type of the EAP-packet. |
|
193 EAP_FUNC_IMPORT eap_const_string get_type_string() const; |
|
194 |
|
195 /// This function checks the validity of EAP-header. |
|
196 EAP_FUNC_IMPORT eap_status_e check_header() const; |
|
197 |
|
198 // |
|
199 //-------------------------------------------------- |
|
200 }; // class eap_header_c |
|
201 |
|
202 |
|
203 //----------------------------------------------------------------------------------------- |
|
204 |
|
205 |
|
206 /// This class is read only EAP-packet header. |
|
207 /// @{ This class can be removed. eap_header_base_c could be used instead. } |
|
208 class EAP_EXPORT eap_header_rd_c |
|
209 : public eap_header_base_c |
|
210 { |
|
211 private: |
|
212 //-------------------------------------------------- |
|
213 |
|
214 /// This is pointer to the tools class. |
|
215 abs_eap_am_tools_c * const m_am_tools; |
|
216 |
|
217 //-------------------------------------------------- |
|
218 protected: |
|
219 //-------------------------------------------------- |
|
220 |
|
221 //-------------------------------------------------- |
|
222 public: |
|
223 //-------------------------------------------------- |
|
224 |
|
225 /// Destructor does nothing special. |
|
226 EAP_FUNC_IMPORT virtual ~eap_header_rd_c(); |
|
227 |
|
228 /// Constructor does nothing special. |
|
229 /// The tools parameter is pointer to tools object. |
|
230 /// The header_buffer parameter is pointer to buffer of EAP-packet including header and data. |
|
231 /// The header_buffer_length parameter is length of the header_buffer. |
|
232 EAP_FUNC_IMPORT eap_header_rd_c( |
|
233 abs_eap_am_tools_c * const tools, |
|
234 u8_t * const header_buffer, |
|
235 const u32_t header_buffer_length); |
|
236 |
|
237 |
|
238 // |
|
239 //-------------------------------------------------- |
|
240 }; // class eap_header_rd_c |
|
241 |
|
242 |
|
243 //----------------------------------------------------------------------------------------- |
|
244 |
|
245 |
|
246 /// This class is read and write EAP-packet header. |
|
247 /// @{ This class can be removed. eap_header_base_c could be used instead. } |
|
248 class EAP_EXPORT eap_header_wr_c |
|
249 : public eap_header_base_c |
|
250 { |
|
251 private: |
|
252 //-------------------------------------------------- |
|
253 |
|
254 /// This is pointer to the tools class. |
|
255 abs_eap_am_tools_c * const m_am_tools; |
|
256 |
|
257 //-------------------------------------------------- |
|
258 protected: |
|
259 //-------------------------------------------------- |
|
260 |
|
261 //-------------------------------------------------- |
|
262 public: |
|
263 //-------------------------------------------------- |
|
264 |
|
265 /// Destructor does nothing special. |
|
266 EAP_FUNC_IMPORT virtual ~eap_header_wr_c(); |
|
267 |
|
268 /// Constructor does nothing special. |
|
269 /// The tools parameter is pointer to tools object. |
|
270 /// The header_buffer parameter is pointer to buffer of EAP-packet including header and data. |
|
271 /// The header_buffer_length parameter is length of the header_buffer. |
|
272 EAP_FUNC_IMPORT eap_header_wr_c( |
|
273 abs_eap_am_tools_c * const tools, |
|
274 u8_t * const header_buffer, |
|
275 const u32_t header_buffer_length); |
|
276 |
|
277 |
|
278 /// This function returns the pointer to the type data field of EAP-packet. |
|
279 EAP_FUNC_IMPORT u8_t * get_type_data( |
|
280 const u32_t p_continuous_bytes) const; |
|
281 |
|
282 /// This function returns the pointer to the offset of the type data field of EAP-packet. |
|
283 EAP_FUNC_IMPORT u8_t * get_type_data_offset( |
|
284 const u32_t p_offset, |
|
285 const u32_t p_continuous_bytes) const; |
|
286 |
|
287 /// This function resets the EAP-header. |
|
288 /// The buffer_length parameter is the length of the EAP-header and the following data buffer. |
|
289 EAP_FUNC_IMPORT void reset_header( |
|
290 const u16_t buffer_length, |
|
291 const bool expanded_type_when_true); |
|
292 |
|
293 // |
|
294 //-------------------------------------------------- |
|
295 }; // class eap_header_c |
|
296 |
|
297 |
|
298 //----------------------------------------------------------------------------------------- |
|
299 |
|
300 |
|
301 |
|
302 #endif //#if !defined(_EAP_HEADER_H_) |
|
303 |
|
304 //-------------------------------------------------- |
|
305 |
|
306 |
|
307 |
|
308 // End. |