1 /* |
|
2 * ============================================================================ |
|
3 * Name : ./accesssec/eapol/eapol_framework/wapi_common/src/ec_cs_tlv_header.cpp |
|
4 * Part of : WAPI / WAPI *** Info from the SWAD |
|
5 * Description : WAPI authentication |
|
6 * Version : %version: 10 % << Don't touch! Updated by Synergy at check-out. |
|
7 * |
|
8 * Copyright © 2001-2009 Nokia. All rights reserved. |
|
9 * This material, including documentation and any related computer |
|
10 * programs, is protected by copyright controlled by Nokia. All |
|
11 * rights are reserved. Copying, including reproducing, storing, |
|
12 * adapting or translating, any or all of this material requires the |
|
13 * prior written consent of Nokia. This material also contains |
|
14 * confidential information which may not be disclosed to others |
|
15 * without the prior written consent of Nokia. |
|
16 * ============================================================================ |
|
17 * Template version: 4.1.1 |
|
18 */ |
|
19 |
|
20 // This is enumeration of WAPI source code. |
|
21 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
22 #undef EAP_FILE_NUMBER_ENUM |
|
23 #define EAP_FILE_NUMBER_ENUM 705 |
|
24 #undef EAP_FILE_NUMBER_DATE |
|
25 #define EAP_FILE_NUMBER_DATE 1127594498 |
|
26 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES) |
|
27 |
|
28 #if defined(USE_WAPI_CORE) |
|
29 |
|
30 #include "eap_am_memory.h" |
|
31 #include "ec_cs_tlv_header.h" |
|
32 #include "ec_cs_strings.h" |
|
33 |
|
34 /** @file */ |
|
35 |
|
36 |
|
37 /** |
|
38 * The destructor of the ec_cs_tlv_header_c class does nothing. |
|
39 */ |
|
40 ec_cs_tlv_header_c::~ec_cs_tlv_header_c() |
|
41 { |
|
42 } |
|
43 |
|
44 /** |
|
45 * The constructor of the ec_cs_tlv_header_c class simply initializes the attributes. |
|
46 */ |
|
47 ec_cs_tlv_header_c::ec_cs_tlv_header_c( |
|
48 abs_eap_am_tools_c * const tools, |
|
49 void * const header_begin, |
|
50 const u32_t header_buffer_length) |
|
51 : eap_general_header_base_c(tools, header_begin, header_buffer_length) |
|
52 , m_am_tools(tools) |
|
53 { |
|
54 } |
|
55 |
|
56 /** |
|
57 * This function returns the TLV Type. |
|
58 */ |
|
59 ec_cs_tlv_type_e ec_cs_tlv_header_c::get_type() const |
|
60 { |
|
61 const u8_t * const data = get_header_offset(m_type_offset, m_type_size); |
|
62 if (data != 0) |
|
63 { |
|
64 const u16_t value(eap_read_u16_t_network_order(data, m_type_size)); |
|
65 |
|
66 EAP_STATIC_ASSERT(m_type_size == sizeof(value)); |
|
67 |
|
68 return static_cast<ec_cs_tlv_type_e>(value); |
|
69 } |
|
70 else |
|
71 { |
|
72 return ec_cs_tlv_type_none; |
|
73 } |
|
74 } |
|
75 |
|
76 /** |
|
77 * This function returns the data length of TLV. |
|
78 */ |
|
79 u32_t ec_cs_tlv_header_c::get_data_length() const |
|
80 { |
|
81 const u8_t * const length_data = get_header_offset(m_length_offset, m_length_size); |
|
82 if (length_data != 0) |
|
83 { |
|
84 return static_cast<u32_t>(eap_read_u16_t_network_order(length_data, m_length_size)); |
|
85 } |
|
86 else |
|
87 { |
|
88 return 0ul; |
|
89 } |
|
90 } |
|
91 |
|
92 /** |
|
93 * This function returns the header length of TLV. |
|
94 */ |
|
95 u32_t ec_cs_tlv_header_c::get_header_length() |
|
96 { |
|
97 return m_data_offset; |
|
98 } |
|
99 |
|
100 /** |
|
101 * This function returns pointer to the offset of data of TLV. |
|
102 * @param offset is the offset of queried data in bytes. |
|
103 * @param contignuous_bytes is the length of queried data in bytes. |
|
104 */ |
|
105 u8_t * ec_cs_tlv_header_c::get_data_offset(const u32_t offset, const u32_t contignuous_bytes) const |
|
106 { |
|
107 EAP_UNREFERENCED_PARAMETER(m_am_tools); |
|
108 |
|
109 u32_t data_length = get_data_length(); |
|
110 |
|
111 if (data_length >= offset+contignuous_bytes) |
|
112 { |
|
113 u8_t * const data = get_header_offset(m_data_offset, offset+contignuous_bytes); |
|
114 if (data != 0) |
|
115 { |
|
116 return &data[offset]; |
|
117 } |
|
118 else |
|
119 { |
|
120 return 0; |
|
121 } |
|
122 } |
|
123 else |
|
124 { |
|
125 EAP_ASSERT_ALWAYS(data_length >= offset+contignuous_bytes); |
|
126 } |
|
127 return 0; |
|
128 } |
|
129 |
|
130 |
|
131 /** |
|
132 * This function returns pointer to the offset of data of TLV. |
|
133 * @param contignuous_bytes is the length of queried data in bytes. |
|
134 */ |
|
135 u8_t * ec_cs_tlv_header_c::get_data(const u32_t contignuous_bytes) const |
|
136 { |
|
137 return get_data_offset(0u, contignuous_bytes); |
|
138 } |
|
139 |
|
140 |
|
141 /** |
|
142 * This function return pointer to the next TLV header in the same buffer. |
|
143 */ |
|
144 u8_t * ec_cs_tlv_header_c::get_next_header() const |
|
145 { |
|
146 if (get_header_buffer_length() >= 2ul*get_header_length()+get_data_length()) |
|
147 { |
|
148 return get_data_offset(get_data_length(), get_header_length()); |
|
149 } |
|
150 else |
|
151 { |
|
152 return 0; |
|
153 } |
|
154 } |
|
155 |
|
156 |
|
157 /** |
|
158 * This function checks the header is valid. |
|
159 */ |
|
160 eap_status_e ec_cs_tlv_header_c::check_header() const |
|
161 { |
|
162 if (get_type() == ec_cs_tlv_type_none) |
|
163 { |
|
164 return EAP_STATUS_RETURN(m_am_tools, eap_status_header_corrupted); |
|
165 } |
|
166 |
|
167 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
168 } |
|
169 |
|
170 /** |
|
171 * This function returns debug strings of the TLV type. |
|
172 */ |
|
173 eap_const_string ec_cs_tlv_header_c::get_tlv_string(const ec_cs_tlv_type_e type) |
|
174 { |
|
175 return ec_cs_strings_c::get_ec_cs_tlv_header_string(type); |
|
176 } |
|
177 |
|
178 /** |
|
179 * This function returns debug strings of the TLV type. |
|
180 */ |
|
181 eap_const_string ec_cs_tlv_header_c::get_tlv_string() const |
|
182 { |
|
183 const ec_cs_tlv_type_e type = get_type(); |
|
184 return get_tlv_string(type); |
|
185 } |
|
186 |
|
187 /** |
|
188 * This function sets the TLV type flag. |
|
189 */ |
|
190 eap_status_e ec_cs_tlv_header_c::set_type(const ec_cs_tlv_type_e type) |
|
191 { |
|
192 u8_t * const data = get_header_offset(m_type_offset, m_type_size); |
|
193 if (data != 0) |
|
194 { |
|
195 const u16_t value(static_cast<u16_t>(type)); |
|
196 |
|
197 EAP_STATIC_ASSERT(m_type_size == sizeof(value)); |
|
198 |
|
199 return EAP_STATUS_RETURN(m_am_tools, eap_write_u16_t_network_order( |
|
200 data, |
|
201 sizeof(value), |
|
202 value)); |
|
203 } |
|
204 else |
|
205 { |
|
206 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
207 } |
|
208 } |
|
209 |
|
210 /** |
|
211 * This function sets the TLV data length. |
|
212 */ |
|
213 eap_status_e ec_cs_tlv_header_c::set_data_length(const u32_t p_length) |
|
214 { |
|
215 u8_t * const data = get_header_offset(m_length_offset, m_length_size); |
|
216 if (data != 0) |
|
217 { |
|
218 const u16_t value(static_cast<u16_t>(p_length)); |
|
219 |
|
220 EAP_STATIC_ASSERT(m_length_offset == sizeof(value)); |
|
221 |
|
222 return EAP_STATUS_RETURN(m_am_tools, eap_write_u16_t_network_order( |
|
223 data, |
|
224 sizeof(value), |
|
225 value)); |
|
226 } |
|
227 else |
|
228 { |
|
229 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
230 } |
|
231 } |
|
232 |
|
233 /** |
|
234 * This function resets the TLV header. |
|
235 */ |
|
236 eap_status_e ec_cs_tlv_header_c::reset_header() |
|
237 { |
|
238 eap_status_e status = set_type(ec_cs_tlv_type_none); |
|
239 if (status != eap_status_ok) |
|
240 { |
|
241 return EAP_STATUS_RETURN(m_am_tools, status); |
|
242 } |
|
243 |
|
244 status = set_data_length(0ul); |
|
245 |
|
246 return EAP_STATUS_RETURN(m_am_tools, status); |
|
247 } |
|
248 |
|
249 /** |
|
250 * This function resets the TLV header object. |
|
251 */ |
|
252 eap_status_e ec_cs_tlv_header_c::reset() |
|
253 { |
|
254 eap_general_header_base_c::set_header_buffer(0, 0ul); |
|
255 |
|
256 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
257 } |
|
258 |
|
259 //------------------------------------------------------------------------------ |
|
260 |
|
261 #endif //#if defined(USE_WAPI_CORE) |
|
262 |
|
263 // End. |
|