|
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 #if !defined(_EAP_DIAMETER_AVP_HEADER_H_) |
|
22 #define _EAP_DIAMETER_AVP_HEADER_H_ |
|
23 |
|
24 #include "eap_tools.h" |
|
25 #include "eap_general_header_base.h" |
|
26 #include "eap_diameter_avp_code.h" |
|
27 |
|
28 /** @file */ |
|
29 |
|
30 const u32_t TRACE_FLAGS_DIAMETER_ERROR = eap_am_tools_c::eap_trace_mask_error; |
|
31 |
|
32 //---------------------------------------------------------------------------- |
|
33 |
|
34 |
|
35 /// This class defines header of Attribute-Value Pairs. |
|
36 /** |
|
37 * Here is a figure of header of Attribute-Value Pairs. |
|
38 * Value data follows eap_diameter_avp_header_c. |
|
39 * @code |
|
40 * AVP-header: |
|
41 * 0 1 2 3 |
|
42 * 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 |
|
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
44 * | AVP Code | |
|
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
46 * |V|M|r r r r r r| AVP Length | |
|
47 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
48 * | Vendor-ID (optional) | |
|
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
50 * | Data .... |
|
51 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
|
52 * @endcode |
|
53 * |
|
54 * @code |
|
55 * The fields of this header are: |
|
56 * 32-bits AVP Code; This is a AVP Code. |
|
57 * 1-bit flag vendor specific (V); Whether this AVP is vendor specific (1) |
|
58 * 1-bit flag mandatory (M); Whether support of the AVP is required (1). |
|
59 * 6-bits reserved bits; Unused bits must be zero. |
|
60 * 24-bits value AVP Length; This is a length field, the length (in bytes) of the AVP header and data. |
|
61 * 32-bits Vendor-ID; This is a optional Vendor-ID. The flag vendor specific (V) must be set too. |
|
62 * @endcode |
|
63 * |
|
64 * See <a href="../../documentation/RFCs/draft-funk-eap-ttls-v0-00.txt">draft-funk-eap-ttls-v0-00.txt</a>. |
|
65 */ |
|
66 class EAP_EXPORT eap_diameter_avp_header_c |
|
67 : public eap_general_header_base_c |
|
68 { |
|
69 private: |
|
70 //-------------------------------------------------- |
|
71 |
|
72 /// This is pointer to the tools class. |
|
73 abs_eap_am_tools_c * const m_am_tools; |
|
74 |
|
75 /// This is enumeration of bit masks. |
|
76 enum bit_masks |
|
77 { |
|
78 m_flag_mask_vendor_specific_avp = 0x80, |
|
79 m_flag_mask_mandatory_avp = 0x40, |
|
80 m_flag_mask_reserved_avp = 0x3f, |
|
81 }; |
|
82 |
|
83 |
|
84 //-------------------------------------------------- |
|
85 protected: |
|
86 //-------------------------------------------------- |
|
87 |
|
88 /// This is enumeration of offsets to data fields. |
|
89 enum offsets |
|
90 { |
|
91 m_avp_code_offset = 0ul, ///< This is offset to AVP Code 32-bit field. |
|
92 m_flags_offset = m_avp_code_offset+sizeof(u32_t), ///< This is offset to flags 8-bit field. |
|
93 m_length_offset = m_flags_offset+sizeof(u8_t), ///< This is offset to length 24-bit field. |
|
94 m_vendor_id_or_data_offset = m_length_offset+(3ul*sizeof(u8_t)), ///< This is offset to vendor_specific id of data field. |
|
95 m_data_with_vendor_id_offset = m_vendor_id_or_data_offset+sizeof(u32_t), ///< This is offset to data field. |
|
96 }; |
|
97 |
|
98 /// This is enumeration of sizes of data fields. |
|
99 enum avp_sizes |
|
100 { |
|
101 EAP_DIAMETER_AVP_MINIMUM_HEADER_LENGTH = m_vendor_id_or_data_offset, |
|
102 }; |
|
103 |
|
104 //-------------------------------------------------- |
|
105 public: |
|
106 //-------------------------------------------------- |
|
107 |
|
108 /** |
|
109 * The destructor of the eap_diameter_avp_header_c class does nothing. |
|
110 */ |
|
111 virtual ~eap_diameter_avp_header_c(); |
|
112 |
|
113 /** |
|
114 * The constructor of the eap_diameter_avp_header_c class simply initializes the attributes. |
|
115 */ |
|
116 eap_diameter_avp_header_c( |
|
117 abs_eap_am_tools_c * const tools, |
|
118 void * const header_begin, |
|
119 const u32_t header_buffer_length); |
|
120 |
|
121 /** |
|
122 * This function returns lengthof required padding. |
|
123 */ |
|
124 u32_t get_padding_length() const; |
|
125 |
|
126 |
|
127 /** |
|
128 * This function returns the AVP Code. |
|
129 */ |
|
130 eap_diameter_avp_code_c get_avp_code() const; |
|
131 |
|
132 /** |
|
133 * This function returns the AVP vendor specific flag. |
|
134 */ |
|
135 bool get_avp_flag_vendor_specific() const; |
|
136 |
|
137 /** |
|
138 * This function returns the AVP mandatory flag. |
|
139 */ |
|
140 bool get_avp_flag_mandatory_avp() const; |
|
141 |
|
142 /** |
|
143 * This function returns the AVP reserved flags. |
|
144 */ |
|
145 u8_t get_avp_flags_reserved() const; |
|
146 |
|
147 /** |
|
148 * This function returns the length of AVP (header+data). |
|
149 */ |
|
150 u32_t get_length() const; |
|
151 |
|
152 /** |
|
153 * This function returns the length of AVP data. |
|
154 */ |
|
155 u32_t get_data_length() const; |
|
156 |
|
157 /** |
|
158 * This function returns the header length of AVP. |
|
159 */ |
|
160 static u32_t get_header_length(const bool include_vendor_specific); |
|
161 |
|
162 /** |
|
163 * This function returns the header length of AVP. |
|
164 */ |
|
165 u32_t get_header_length() const; |
|
166 |
|
167 /** |
|
168 * This function returns pointer to the offset of data of AVP. |
|
169 * @param offset is the offset of queried data in bytes. |
|
170 * @param contignuous_bytes is the length of queried data in bytes. |
|
171 */ |
|
172 u8_t * get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const; |
|
173 |
|
174 |
|
175 /** |
|
176 * This function returns pointer to the offset of data of AVP. |
|
177 * @param contignuous_bytes is the length of queried data in bytes. |
|
178 */ |
|
179 u8_t * get_data(const u32_t contignuous_bytes) const; |
|
180 |
|
181 |
|
182 /** |
|
183 * This function return pointer to the next AVP header in the same buffer. |
|
184 */ |
|
185 u8_t * get_next_header() const; |
|
186 |
|
187 |
|
188 /** |
|
189 * This function checks the header is valid. |
|
190 */ |
|
191 eap_status_e check_header() const; |
|
192 |
|
193 /** |
|
194 * This function returns debug strings of the AVP Code. |
|
195 */ |
|
196 eap_const_string get_avp_code_string() const; |
|
197 |
|
198 /** |
|
199 * This function sets the AVP Code. |
|
200 */ |
|
201 eap_status_e set_avp_code(const eap_diameter_avp_code_c code); |
|
202 |
|
203 /** |
|
204 * This function sets the AVP vendor specific flag. |
|
205 */ |
|
206 eap_status_e set_avp_flag_vendor_specific(const bool vendor_specific); |
|
207 |
|
208 /** |
|
209 * This function sets the AVP mandatory flag. |
|
210 */ |
|
211 eap_status_e set_avp_flag_mandatory_avp(const bool mandatory); |
|
212 |
|
213 /** |
|
214 * This function sets the AVP mandatory flag. |
|
215 */ |
|
216 eap_status_e set_avp_flags_reserved(); |
|
217 |
|
218 /** |
|
219 * This function sets the AVP data length. |
|
220 */ |
|
221 eap_status_e set_data_length(const u32_t p_length); |
|
222 |
|
223 /** |
|
224 * This function resets the AVP header. |
|
225 */ |
|
226 eap_status_e reset_header(const u16_t data_length); |
|
227 |
|
228 // |
|
229 //-------------------------------------------------- |
|
230 }; // class eap_diameter_avp_header_c |
|
231 |
|
232 |
|
233 //-------------------------------------------------- |
|
234 |
|
235 /// Macro traces payload type and data. |
|
236 #define EAP_DIAMETER_TRACE_PAYLOAD(prefix, payload) \ |
|
237 { \ |
|
238 EAP_TRACE_DEBUG( \ |
|
239 m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
240 (EAPL("%s (0x%08x): AVP code 0x%08x:0x%08x=%s, data length 0x%04x.\n"), \ |
|
241 prefix, (payload)->get_header_buffer((payload)->get_length()), \ |
|
242 (payload)->get_avp_code().get_vendor_id(), (payload)->get_avp_code().get_vendor_code(), \ |
|
243 (payload)->get_avp_code_string(), (payload)->get_data_length())); \ |
|
244 EAP_TRACE_DATA_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT|TRACE_TEST_VECTORS, \ |
|
245 (EAPL("payload"), (payload)->get_header_buffer((payload)->get_length()), \ |
|
246 (payload)->get_length())); \ |
|
247 } |
|
248 |
|
249 //-------------------------------------------------- |
|
250 |
|
251 #endif //#if !defined(_EAP_DIAMETER_AVP_HEADER_H_) |
|
252 |
|
253 |
|
254 |
|
255 // End. |