|
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 36 |
|
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_sim_triplets.h" |
|
31 #include "abs_eap_am_tools.h" |
|
32 |
|
33 |
|
34 EAP_FUNC_EXPORT eap_type_saesim_triplet_c::~eap_type_saesim_triplet_c() |
|
35 { |
|
36 reset(); |
|
37 } |
|
38 |
|
39 EAP_FUNC_EXPORT eap_type_saesim_triplet_c::eap_type_saesim_triplet_c( |
|
40 abs_eap_am_tools_c * const tools |
|
41 ) |
|
42 : m_kc(0) |
|
43 , m_rand(0) |
|
44 , m_sres(0) |
|
45 , m_is_valid(false) |
|
46 { |
|
47 m_kc = new eap_variable_data_c(tools); |
|
48 m_rand = new eap_variable_data_c(tools); |
|
49 m_sres = new eap_variable_data_c(tools); |
|
50 |
|
51 if (m_kc == 0 |
|
52 || m_rand == 0 |
|
53 || m_sres == 0) |
|
54 { |
|
55 reset(); |
|
56 } |
|
57 else |
|
58 { |
|
59 eap_status_e status = m_kc->init(SIM_KC_LENGTH); |
|
60 if (status != eap_status_ok) |
|
61 { |
|
62 return; |
|
63 } |
|
64 m_kc->set_is_valid(); |
|
65 |
|
66 status = m_rand->init(SIM_RAND_LENGTH); |
|
67 if (status != eap_status_ok) |
|
68 { |
|
69 return; |
|
70 } |
|
71 m_rand->set_is_valid(); |
|
72 |
|
73 status = m_sres->init(SIM_SRES_LENGTH); |
|
74 if (status != eap_status_ok) |
|
75 { |
|
76 return; |
|
77 } |
|
78 m_sres->set_is_valid(); |
|
79 |
|
80 set_is_valid(); |
|
81 } |
|
82 } |
|
83 |
|
84 EAP_FUNC_EXPORT void eap_type_saesim_triplet_c::reset() |
|
85 { |
|
86 if (m_kc) |
|
87 { |
|
88 delete m_kc; |
|
89 m_kc = 0; |
|
90 } |
|
91 if (m_rand) |
|
92 { |
|
93 delete m_rand; |
|
94 m_rand = 0; |
|
95 } |
|
96 if (m_sres) |
|
97 { |
|
98 delete m_sres; |
|
99 m_sres = 0; |
|
100 } |
|
101 } |
|
102 |
|
103 EAP_FUNC_EXPORT eap_status_e eap_type_saesim_triplet_c::set_triplet( |
|
104 eap_variable_data_c * const kc, |
|
105 eap_variable_data_c * const rand, |
|
106 eap_variable_data_c * const sres |
|
107 ) |
|
108 { |
|
109 reset(); |
|
110 |
|
111 m_kc = kc; |
|
112 m_rand = rand; |
|
113 m_sres = sres; |
|
114 |
|
115 if (m_kc == 0 |
|
116 || m_rand == 0 |
|
117 || m_sres == 0) |
|
118 { |
|
119 return eap_status_allocation_error; |
|
120 } |
|
121 return eap_status_ok; |
|
122 } |
|
123 |
|
124 EAP_FUNC_EXPORT eap_type_saesim_triplet_c * eap_type_saesim_triplet_c::copy( |
|
125 abs_eap_am_tools_c * const tools |
|
126 ) |
|
127 { |
|
128 eap_type_saesim_triplet_c * const triplet = new eap_type_saesim_triplet_c(tools); |
|
129 |
|
130 if (triplet != 0 |
|
131 && triplet->get_is_valid() == true) |
|
132 { |
|
133 eap_status_e status = triplet->set_triplet( |
|
134 get_kc()->copy(), |
|
135 get_rand()->copy(), |
|
136 get_sres()->copy()); |
|
137 if (status != eap_status_ok) |
|
138 { |
|
139 delete triplet; |
|
140 return 0; |
|
141 } |
|
142 } |
|
143 else |
|
144 { |
|
145 delete triplet; |
|
146 return 0; |
|
147 } |
|
148 |
|
149 return triplet; |
|
150 } |
|
151 |
|
152 EAP_FUNC_EXPORT void eap_type_saesim_triplet_c::set_is_valid() |
|
153 { |
|
154 m_is_valid = true; |
|
155 } |
|
156 |
|
157 EAP_FUNC_EXPORT bool eap_type_saesim_triplet_c::get_is_valid() |
|
158 { |
|
159 return m_is_valid; |
|
160 } |
|
161 |
|
162 EAP_FUNC_EXPORT eap_variable_data_c *eap_type_saesim_triplet_c::get_kc() |
|
163 { |
|
164 return m_kc; |
|
165 } |
|
166 |
|
167 EAP_FUNC_EXPORT eap_variable_data_c *eap_type_saesim_triplet_c::get_rand() |
|
168 { |
|
169 return m_rand; |
|
170 } |
|
171 |
|
172 EAP_FUNC_EXPORT eap_variable_data_c *eap_type_saesim_triplet_c::get_sres() |
|
173 { |
|
174 return m_sres; |
|
175 } |
|
176 |
|
177 |
|
178 |
|
179 EAP_FUNC_EXPORT eap_type_sim_triplet_array_c::~eap_type_sim_triplet_array_c() |
|
180 { |
|
181 reset(); |
|
182 } |
|
183 |
|
184 EAP_FUNC_EXPORT eap_type_sim_triplet_array_c::eap_type_sim_triplet_array_c( |
|
185 abs_eap_am_tools_c * const tools |
|
186 ) |
|
187 : m_triplet_count(0) |
|
188 , m_array(0) |
|
189 , m_am_tools(tools) |
|
190 { |
|
191 } |
|
192 |
|
193 EAP_FUNC_EXPORT eap_status_e eap_type_sim_triplet_array_c::set_triplet_count( |
|
194 const u32_t triplet_count |
|
195 ) |
|
196 { |
|
197 m_triplet_count = triplet_count; |
|
198 |
|
199 m_array = new eap_type_saesim_triplet_c *[m_triplet_count]; |
|
200 |
|
201 if (m_array != 0) |
|
202 { |
|
203 u32_t ind = 0; |
|
204 |
|
205 for (ind = 0; ind < m_triplet_count; ind++) |
|
206 { |
|
207 m_array[ind] = 0; |
|
208 } |
|
209 |
|
210 for (ind = 0; ind < m_triplet_count; ind++) |
|
211 { |
|
212 m_array[ind] = new eap_type_saesim_triplet_c(m_am_tools); |
|
213 if (m_array[ind] == 0) |
|
214 { |
|
215 return eap_status_allocation_error; |
|
216 } |
|
217 } |
|
218 return eap_status_ok; |
|
219 } |
|
220 else |
|
221 { |
|
222 return eap_status_allocation_error; |
|
223 } |
|
224 } |
|
225 |
|
226 EAP_FUNC_EXPORT eap_type_saesim_triplet_c * eap_type_sim_triplet_array_c::add_triplet() |
|
227 { |
|
228 eap_type_saesim_triplet_c **old_array = m_array; |
|
229 |
|
230 m_array = new eap_type_saesim_triplet_c *[m_triplet_count+1u]; |
|
231 |
|
232 if (m_array != 0) |
|
233 { |
|
234 u32_t ind; |
|
235 |
|
236 for (ind = 0; ind < m_triplet_count; ind++) |
|
237 { |
|
238 m_array[ind] = old_array[ind]; |
|
239 } |
|
240 |
|
241 delete [] old_array; |
|
242 ++m_triplet_count; |
|
243 |
|
244 m_array[ind] = new eap_type_saesim_triplet_c(m_am_tools); |
|
245 if (m_array[ind] == 0) |
|
246 { |
|
247 return 0; |
|
248 } |
|
249 |
|
250 return m_array[ind]; |
|
251 } |
|
252 else |
|
253 { |
|
254 m_array = old_array; |
|
255 return 0; |
|
256 } |
|
257 } |
|
258 |
|
259 EAP_FUNC_EXPORT eap_type_saesim_triplet_c * eap_type_sim_triplet_array_c::get_triplet( |
|
260 abs_eap_am_tools_c * const /* m_am_tools */, u32_t index) |
|
261 { |
|
262 if (index < m_triplet_count) |
|
263 { |
|
264 return m_array[index]; |
|
265 } |
|
266 else |
|
267 { |
|
268 EAP_ASSERT_ALWAYS(index < m_triplet_count); |
|
269 return 0; |
|
270 } |
|
271 } |
|
272 |
|
273 EAP_FUNC_EXPORT eap_status_e eap_type_sim_triplet_array_c::set_triplet(u32_t index, eap_type_saesim_triplet_c * const triplet) |
|
274 { |
|
275 if (index < m_triplet_count) |
|
276 { |
|
277 if (m_array[index] != 0) |
|
278 { |
|
279 delete m_array[index]; |
|
280 } |
|
281 m_array[index] = triplet; |
|
282 return eap_status_ok; |
|
283 } |
|
284 else |
|
285 { |
|
286 return eap_status_illegal_index; |
|
287 } |
|
288 } |
|
289 |
|
290 EAP_FUNC_EXPORT u32_t eap_type_sim_triplet_array_c::get_triplet_count() |
|
291 { |
|
292 return m_triplet_count; |
|
293 } |
|
294 |
|
295 EAP_FUNC_EXPORT eap_type_sim_triplet_array_c * eap_type_sim_triplet_array_c::copy() |
|
296 { |
|
297 eap_type_sim_triplet_array_c * const new_triplets |
|
298 = new eap_type_sim_triplet_array_c(m_am_tools); |
|
299 if (new_triplets == 0) |
|
300 { |
|
301 return 0; |
|
302 } |
|
303 |
|
304 eap_status_e status = new_triplets->set_triplet_count(get_triplet_count()); |
|
305 if (status != eap_status_ok) |
|
306 { |
|
307 delete new_triplets; |
|
308 return 0; |
|
309 } |
|
310 |
|
311 for (u32_t ind = 0; ind < get_triplet_count(); ind++) |
|
312 { |
|
313 eap_status_e status = new_triplets->set_triplet( |
|
314 ind, |
|
315 get_triplet(m_am_tools, ind)->copy(m_am_tools)); |
|
316 if (status != eap_status_ok) |
|
317 { |
|
318 delete new_triplets; |
|
319 return 0; |
|
320 } |
|
321 } |
|
322 |
|
323 return new_triplets; |
|
324 } |
|
325 |
|
326 EAP_FUNC_EXPORT void eap_type_sim_triplet_array_c::reset() |
|
327 { |
|
328 if (m_array != 0) |
|
329 { |
|
330 for (u32_t ind = 0; ind < m_triplet_count; ind++) |
|
331 { |
|
332 delete m_array[ind]; |
|
333 m_array[ind] = 0; |
|
334 } |
|
335 delete [] m_array; |
|
336 m_array = 0; |
|
337 } |
|
338 |
|
339 m_triplet_count = 0u; |
|
340 m_am_tools = 0; |
|
341 } |
|
342 |
|
343 |
|
344 //-------------------------------------------------- |
|
345 |
|
346 |
|
347 |
|
348 // End. |