|
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 56 |
|
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_rsna_key_header.h" |
|
30 #include "eap_automatic_variable.h" |
|
31 #include "eapol_key_state_string.h" |
|
32 |
|
33 //------------------------------------------------------ |
|
34 |
|
35 // |
|
36 EAP_FUNC_EXPORT eapol_RSNA_key_header_c::~eapol_RSNA_key_header_c() |
|
37 { |
|
38 } |
|
39 |
|
40 //------------------------------------------------------ |
|
41 |
|
42 // |
|
43 EAP_FUNC_EXPORT eapol_RSNA_key_header_c::eapol_RSNA_key_header_c( |
|
44 abs_eap_am_tools_c * const tools, |
|
45 const bool is_RSNA_when_true, |
|
46 const bool is_WPXM_when_true, |
|
47 void * const header_begin, |
|
48 const u32_t header_buffer_length) |
|
49 : eap_general_header_base_c(tools, header_begin, header_buffer_length) |
|
50 , m_am_tools(tools) |
|
51 , m_is_RSNA_when_true(is_RSNA_when_true) |
|
52 , m_is_WPXM_when_true(is_WPXM_when_true) |
|
53 { |
|
54 } |
|
55 |
|
56 //------------------------------------------------------ |
|
57 |
|
58 // |
|
59 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information(const u16_t info) |
|
60 { |
|
61 u8_t * const data = get_header_offset(m_offset_key_information, sizeof(u16_t)); |
|
62 if (data != 0) |
|
63 { |
|
64 return eap_write_u16_t_network_order(data, sizeof(u16_t), info); |
|
65 } |
|
66 else |
|
67 { |
|
68 // ERROR. |
|
69 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
70 } |
|
71 } |
|
72 |
|
73 //------------------------------------------------------ |
|
74 |
|
75 // |
|
76 EAP_FUNC_EXPORT eapol_protocol_version_e eapol_RSNA_key_header_c::get_eapol_protocol_version() const |
|
77 { |
|
78 const u8_t * const data = get_header_offset(m_offset_eapol_version, sizeof(u8_t)); |
|
79 if (data != 0) |
|
80 { |
|
81 return static_cast<eapol_protocol_version_e>(*data); |
|
82 } |
|
83 else |
|
84 { |
|
85 return eapol_protocol_version_none; |
|
86 } |
|
87 } |
|
88 |
|
89 //------------------------------------------------------ |
|
90 |
|
91 // |
|
92 EAP_FUNC_EXPORT eapol_packet_type_e eapol_RSNA_key_header_c::get_eapol_packet_type() const |
|
93 { |
|
94 const u8_t * const data = get_header_offset(m_offset_eapol_type, sizeof(u8_t)); |
|
95 if (data != 0) |
|
96 { |
|
97 return static_cast<eapol_packet_type_e>(*data); |
|
98 } |
|
99 else |
|
100 { |
|
101 return eapol_packet_type_no_type; |
|
102 } |
|
103 } |
|
104 |
|
105 //------------------------------------------------------ |
|
106 |
|
107 // |
|
108 EAP_FUNC_EXPORT u16_t eapol_RSNA_key_header_c::get_eapol_packet_body_length() const |
|
109 { |
|
110 const u8_t * const data = get_header_offset(m_offset_eapol_packet_body_length, sizeof(u16_t)); |
|
111 if (data != 0) |
|
112 { |
|
113 return eap_read_u16_t_network_order(data, sizeof(u16_t)); |
|
114 } |
|
115 else |
|
116 { |
|
117 return 0ul; |
|
118 } |
|
119 } |
|
120 |
|
121 //------------------------------------------------------ |
|
122 |
|
123 // |
|
124 EAP_FUNC_EXPORT u16_t eapol_RSNA_key_header_c::get_eapol_packet_length() const |
|
125 { |
|
126 // m_offset_key_descriptor_type is the length of the EAPOL header. |
|
127 // Including fields Version, Type and Packet Body Length. |
|
128 return static_cast<u16_t>(get_eapol_packet_body_length() + m_offset_key_descriptor_type); |
|
129 } |
|
130 |
|
131 //------------------------------------------------------ |
|
132 |
|
133 // |
|
134 EAP_FUNC_EXPORT eapol_key_descriptor_type_e eapol_RSNA_key_header_c::get_key_descriptor_type() const |
|
135 { |
|
136 const u8_t * const data = get_header_offset(m_offset_key_descriptor_type, sizeof(u8_t)); |
|
137 if (data != 0) |
|
138 { |
|
139 return static_cast<eapol_key_descriptor_type_e>(*data); |
|
140 } |
|
141 else |
|
142 { |
|
143 return eapol_key_descriptor_type_none; |
|
144 } |
|
145 } |
|
146 |
|
147 //------------------------------------------------------ |
|
148 |
|
149 // |
|
150 EAP_FUNC_EXPORT u16_t eapol_RSNA_key_header_c::get_key_information() const |
|
151 { |
|
152 const u8_t * const data = get_header_offset(m_offset_key_information, sizeof(u16_t)); |
|
153 if (data != 0) |
|
154 { |
|
155 return eap_read_u16_t_network_order(data, sizeof(u16_t)); |
|
156 } |
|
157 else |
|
158 { |
|
159 // ERROR. |
|
160 return 0ul; |
|
161 } |
|
162 } |
|
163 |
|
164 //------------------------------------------------------ |
|
165 |
|
166 // |
|
167 EAP_FUNC_EXPORT eapol_RSNA_key_header_c::key_descriptor_version_e eapol_RSNA_key_header_c::get_key_information_key_descriptor_version() const |
|
168 { |
|
169 const u16_t key_information = get_key_information(); |
|
170 return static_cast<key_descriptor_version_e>((key_information & m_key_information_mask_key_descriptor_version) |
|
171 >> m_key_information_mask_key_descriptor_version_shift); |
|
172 } |
|
173 |
|
174 //------------------------------------------------------ |
|
175 |
|
176 // |
|
177 EAP_FUNC_EXPORT bool eapol_RSNA_key_header_c::get_key_information_key_type() const |
|
178 { |
|
179 const u16_t key_information = get_key_information(); |
|
180 const u16_t key_type = static_cast<u16_t>(key_information & m_key_information_mask_key_type); |
|
181 if (key_type != 0) |
|
182 { |
|
183 return true; |
|
184 } |
|
185 else |
|
186 { |
|
187 return false; |
|
188 } |
|
189 } |
|
190 |
|
191 //------------------------------------------------------ |
|
192 |
|
193 // |
|
194 EAP_FUNC_EXPORT u8_t eapol_RSNA_key_header_c::get_key_information_reserved_a() const |
|
195 { |
|
196 EAP_ASSERT(m_is_RSNA_when_true == true || m_is_WPXM_when_true == true); |
|
197 |
|
198 const u16_t key_information = get_key_information(); |
|
199 return static_cast<u8_t>((key_information & m_key_information_mask_reserved_a_RSNA) |
|
200 >> m_key_information_mask_reserved_a_shift_RSNA); |
|
201 } |
|
202 |
|
203 //------------------------------------------------------ |
|
204 |
|
205 // |
|
206 EAP_FUNC_EXPORT u8_t eapol_RSNA_key_header_c::get_key_information_key_index() const |
|
207 { |
|
208 EAP_ASSERT(m_is_RSNA_when_true == false || m_is_WPXM_when_true == true); |
|
209 |
|
210 const u16_t key_information = get_key_information(); |
|
211 return static_cast<u8_t>((key_information & m_key_information_mask_key_index_WPA) |
|
212 >> m_key_information_mask_key_index_shift_WPA); |
|
213 } |
|
214 |
|
215 //------------------------------------------------------ |
|
216 |
|
217 // |
|
218 EAP_FUNC_EXPORT bool eapol_RSNA_key_header_c::get_key_information_install() const |
|
219 { |
|
220 const u16_t key_information = get_key_information(); |
|
221 const u16_t key_type = static_cast<u16_t>(key_information & m_key_information_mask_install); |
|
222 if (key_type != 0) |
|
223 { |
|
224 return true; |
|
225 } |
|
226 else |
|
227 { |
|
228 return false; |
|
229 } |
|
230 } |
|
231 |
|
232 //------------------------------------------------------ |
|
233 |
|
234 // |
|
235 EAP_FUNC_EXPORT bool eapol_RSNA_key_header_c::get_key_information_key_ack() const |
|
236 { |
|
237 const u16_t key_information = get_key_information(); |
|
238 const u16_t key_type = static_cast<u16_t>(key_information & m_key_information_mask_key_ack); |
|
239 if (key_type != 0) |
|
240 { |
|
241 return true; |
|
242 } |
|
243 else |
|
244 { |
|
245 return false; |
|
246 } |
|
247 } |
|
248 |
|
249 //------------------------------------------------------ |
|
250 |
|
251 // |
|
252 EAP_FUNC_EXPORT bool eapol_RSNA_key_header_c::get_key_information_key_MIC() const |
|
253 { |
|
254 const u16_t key_information = get_key_information(); |
|
255 const u16_t key_type = static_cast<u16_t>(key_information & m_key_information_mask_key_MIC); |
|
256 if (key_type != 0) |
|
257 { |
|
258 return true; |
|
259 } |
|
260 else |
|
261 { |
|
262 return false; |
|
263 } |
|
264 } |
|
265 |
|
266 //------------------------------------------------------ |
|
267 |
|
268 // |
|
269 EAP_FUNC_EXPORT bool eapol_RSNA_key_header_c::get_key_information_secure() const |
|
270 { |
|
271 const u16_t key_information = get_key_information(); |
|
272 const u16_t key_type = static_cast<u16_t>(key_information & m_key_information_mask_secure); |
|
273 if (key_type != 0) |
|
274 { |
|
275 return true; |
|
276 } |
|
277 else |
|
278 { |
|
279 return false; |
|
280 } |
|
281 } |
|
282 |
|
283 //------------------------------------------------------ |
|
284 |
|
285 // |
|
286 EAP_FUNC_EXPORT bool eapol_RSNA_key_header_c::get_key_information_error() const |
|
287 { |
|
288 const u16_t key_information = get_key_information(); |
|
289 const u16_t key_type = static_cast<u16_t>(key_information & m_key_information_mask_error); |
|
290 if (key_type != 0) |
|
291 { |
|
292 return true; |
|
293 } |
|
294 else |
|
295 { |
|
296 return false; |
|
297 } |
|
298 } |
|
299 |
|
300 //------------------------------------------------------ |
|
301 |
|
302 // |
|
303 EAP_FUNC_EXPORT bool eapol_RSNA_key_header_c::get_key_information_request() const |
|
304 { |
|
305 const u16_t key_information = get_key_information(); |
|
306 const u16_t key_type = static_cast<u16_t>(key_information & m_key_information_mask_request); |
|
307 if (key_type != 0) |
|
308 { |
|
309 return true; |
|
310 } |
|
311 else |
|
312 { |
|
313 return false; |
|
314 } |
|
315 } |
|
316 |
|
317 |
|
318 //------------------------------------------------------ |
|
319 |
|
320 // |
|
321 EAP_FUNC_EXPORT bool eapol_RSNA_key_header_c::get_key_information_encrypted_key_data() const |
|
322 { |
|
323 const u16_t key_information = get_key_information(); |
|
324 const u16_t key_type = static_cast<u16_t>(key_information & m_key_information_mask_encrypted_key_data_RSNA); |
|
325 if (key_type != 0) |
|
326 { |
|
327 return true; |
|
328 } |
|
329 else |
|
330 { |
|
331 return false; |
|
332 } |
|
333 } |
|
334 |
|
335 |
|
336 //------------------------------------------------------ |
|
337 |
|
338 // |
|
339 EAP_FUNC_EXPORT u8_t eapol_RSNA_key_header_c::get_key_information_reserved_b() const |
|
340 { |
|
341 const u16_t key_information = get_key_information(); |
|
342 |
|
343 if (m_is_RSNA_when_true == true || m_is_WPXM_when_true == true) |
|
344 { |
|
345 return static_cast<u8_t>((key_information & m_key_information_mask_reserved_b_RSNA) |
|
346 >> m_key_information_mask_reserved_b_shift_RSNA); |
|
347 } |
|
348 else |
|
349 { |
|
350 return static_cast<u8_t>((key_information & m_key_information_mask_reserved_b_WPA) |
|
351 >> m_key_information_mask_reserved_b_shift_WPA); |
|
352 } |
|
353 } |
|
354 |
|
355 //------------------------------------------------------ |
|
356 |
|
357 // |
|
358 EAP_FUNC_EXPORT u16_t eapol_RSNA_key_header_c::get_key_length() const |
|
359 { |
|
360 const u8_t * const data = get_header_offset(m_offset_key_length, sizeof(u16_t)); |
|
361 if (data != 0) |
|
362 { |
|
363 return eap_read_u16_t_network_order(data, sizeof(u16_t)); |
|
364 } |
|
365 else |
|
366 { |
|
367 return 0ul; |
|
368 } |
|
369 } |
|
370 |
|
371 //------------------------------------------------------ |
|
372 |
|
373 // |
|
374 EAP_FUNC_EXPORT u64_t eapol_RSNA_key_header_c::get_key_replay_counter() const |
|
375 { |
|
376 const u8_t * const data = get_header_offset(m_offset_key_replay_counter, EAPOL_RSNA_KEY_REPLY_COUNTER_SIZE); |
|
377 if (data != 0) |
|
378 { |
|
379 return eap_read_u64_t_network_order(data, EAPOL_RSNA_KEY_REPLY_COUNTER_SIZE); |
|
380 } |
|
381 else |
|
382 { |
|
383 return 0ul; |
|
384 } |
|
385 } |
|
386 |
|
387 //------------------------------------------------------ |
|
388 |
|
389 // |
|
390 EAP_FUNC_EXPORT u8_t * eapol_RSNA_key_header_c::get_key_NONCE() const |
|
391 { |
|
392 u8_t * const data = get_header_offset(m_offset_key_NONCE, EAPOL_RSNA_KEY_NONCE_SIZE); |
|
393 return data; |
|
394 } |
|
395 |
|
396 //------------------------------------------------------ |
|
397 |
|
398 // |
|
399 EAP_FUNC_EXPORT u8_t * eapol_RSNA_key_header_c::get_EAPOL_key_IV() const |
|
400 { |
|
401 u8_t * const data = get_header_offset(m_offset_EAPOL_key_IV, EAPOL_RSNA_EAPOL_KEY_IV_SIZE); |
|
402 return data; |
|
403 } |
|
404 |
|
405 //------------------------------------------------------ |
|
406 |
|
407 // |
|
408 EAP_FUNC_EXPORT u8_t * eapol_RSNA_key_header_c::get_key_RSC() const |
|
409 { |
|
410 u8_t * const data = get_header_offset(m_offset_key_RSC, EAPOL_RSNA_KEY_RSC_SIZE); |
|
411 return data; |
|
412 } |
|
413 |
|
414 //------------------------------------------------------ |
|
415 |
|
416 // |
|
417 EAP_FUNC_EXPORT u8_t * eapol_RSNA_key_header_c::get_key_STA_MAC_address() const |
|
418 { |
|
419 u8_t * const data = get_header_offset(m_offset_key_STA_MAC_address, EAPOL_RSNA_KEY_STA_MAC_ADDRESS_SIZE); |
|
420 return data; |
|
421 } |
|
422 |
|
423 //------------------------------------------------------ |
|
424 |
|
425 // |
|
426 EAP_FUNC_EXPORT u8_t * eapol_RSNA_key_header_c::get_key_reserved() const |
|
427 { |
|
428 u8_t * const data = get_header_offset(m_offset_key_reserved, EAPOL_RSNA_KEY_RESERVED_SIZE); |
|
429 return data; |
|
430 } |
|
431 |
|
432 //------------------------------------------------------ |
|
433 |
|
434 // |
|
435 EAP_FUNC_EXPORT u8_t * eapol_RSNA_key_header_c::get_key_MIC() const |
|
436 { |
|
437 u8_t * const data = get_header_offset(m_offset_key_MIC, EAPOL_RSNA_KEY_MIC_SIZE); |
|
438 return data; |
|
439 } |
|
440 |
|
441 //------------------------------------------------------ |
|
442 |
|
443 // |
|
444 EAP_FUNC_EXPORT u16_t eapol_RSNA_key_header_c::get_key_data_length() const |
|
445 { |
|
446 const u8_t * const data = get_header_offset(m_offset_key_data_length, EAPOL_RSNA_KEY_DATA_LENGTH_SIZE); |
|
447 if (data != 0) |
|
448 { |
|
449 return eap_read_u16_t_network_order(data, EAPOL_RSNA_KEY_DATA_LENGTH_SIZE); |
|
450 } |
|
451 else |
|
452 { |
|
453 return 0ul; |
|
454 } |
|
455 } |
|
456 |
|
457 //------------------------------------------------------ |
|
458 |
|
459 // |
|
460 EAP_FUNC_EXPORT u8_t * eapol_RSNA_key_header_c::get_key_data(const u32_t key_length) const |
|
461 { |
|
462 u8_t * const data = get_header_offset( |
|
463 m_offset_key_data, |
|
464 key_length); |
|
465 |
|
466 return data; // Data begins after the header. |
|
467 } |
|
468 |
|
469 //------------------------------------------------------ |
|
470 |
|
471 // |
|
472 EAP_FUNC_EXPORT u8_t * eapol_RSNA_key_header_c::get_key_data_offset(const u32_t offset, const u32_t key_length) const |
|
473 { |
|
474 u8_t * const data = get_header_offset( |
|
475 m_offset_key_data + offset, |
|
476 key_length); |
|
477 |
|
478 return data; // Data begins after the header. |
|
479 } |
|
480 |
|
481 //------------------------------------------------------ |
|
482 |
|
483 // |
|
484 EAP_FUNC_EXPORT u16_t eapol_RSNA_key_header_c::get_header_length() |
|
485 { |
|
486 return m_offset_key_data; |
|
487 } |
|
488 |
|
489 //------------------------------------------------------ |
|
490 |
|
491 // |
|
492 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_eapol_protocol_version(const eapol_protocol_version_e version) |
|
493 { |
|
494 u8_t * const data = get_header_offset(m_offset_eapol_version, sizeof(u8_t)); |
|
495 if (data != 0) |
|
496 { |
|
497 *data = static_cast<u8_t>(version); |
|
498 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
499 } |
|
500 else |
|
501 { |
|
502 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
503 } |
|
504 } |
|
505 |
|
506 //------------------------------------------------------ |
|
507 |
|
508 // |
|
509 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_eapol_packet_type(const eapol_packet_type_e type) |
|
510 { |
|
511 u8_t * const data = get_header_offset(m_offset_eapol_type, sizeof(u8_t)); |
|
512 if (data != 0) |
|
513 { |
|
514 *data = static_cast<u8_t>(type); |
|
515 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
516 } |
|
517 else |
|
518 { |
|
519 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
520 } |
|
521 } |
|
522 |
|
523 //------------------------------------------------------ |
|
524 |
|
525 // |
|
526 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_eapol_packet_body_length(const u32_t eapol_length) |
|
527 { |
|
528 if (eapol_length - eapol_header_base_c::get_header_length() > eapol_RSNA_key_header_c::EAPOL_RSNA_EAPOL_KEY_MAXIMUM_SIZE) |
|
529 { |
|
530 EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT); |
|
531 return EAP_STATUS_RETURN(m_am_tools, eap_status_too_long_message); |
|
532 } |
|
533 |
|
534 u8_t * const data = get_header_offset(m_offset_eapol_packet_body_length, sizeof(u16_t)); |
|
535 if (data != 0) |
|
536 { |
|
537 const u16_t eapol_length_u16_t = static_cast<u16_t>(eapol_length); |
|
538 return eap_write_u16_t_network_order(data, sizeof(u16_t), eapol_length_u16_t); |
|
539 } |
|
540 else |
|
541 { |
|
542 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
543 } |
|
544 } |
|
545 |
|
546 //------------------------------------------------------ |
|
547 |
|
548 // |
|
549 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_descriptor_type(const eapol_key_descriptor_type_e eapol_key_descriptor_type) |
|
550 { |
|
551 u8_t * const data = get_header_offset(m_offset_key_descriptor_type, sizeof(u8_t)); |
|
552 if (data != 0) |
|
553 { |
|
554 *data = static_cast<u8_t>(eapol_key_descriptor_type); |
|
555 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
556 } |
|
557 else |
|
558 { |
|
559 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
560 } |
|
561 } |
|
562 |
|
563 //------------------------------------------------------ |
|
564 |
|
565 // |
|
566 EAP_FUNC_EXPORT u16_t eapol_RSNA_key_header_c::set_bits_on( |
|
567 u16_t key_information, |
|
568 const u16_t set_bits, |
|
569 const u32_t mask, |
|
570 const u32_t shift) |
|
571 { |
|
572 key_information = |
|
573 static_cast<u16_t>((key_information & ~mask) |
|
574 | ((set_bits << shift) & mask)); |
|
575 |
|
576 return key_information; |
|
577 } |
|
578 |
|
579 //------------------------------------------------------ |
|
580 |
|
581 // |
|
582 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information_key_descriptor_version(const u8_t version) |
|
583 { |
|
584 u16_t key_information = get_key_information(); |
|
585 |
|
586 key_information = set_bits_on( |
|
587 key_information, |
|
588 static_cast<u16_t>(version), |
|
589 m_key_information_mask_key_descriptor_version, |
|
590 m_key_information_mask_key_descriptor_version_shift); |
|
591 |
|
592 return set_key_information(key_information); |
|
593 } |
|
594 |
|
595 //------------------------------------------------------ |
|
596 |
|
597 // |
|
598 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information_key_type(const bool key_type_bit_on_when_true) |
|
599 { |
|
600 u16_t key_information = get_key_information(); |
|
601 |
|
602 u16_t key_type_bit = 0; |
|
603 if (key_type_bit_on_when_true == true) |
|
604 { |
|
605 key_type_bit = 1; |
|
606 } |
|
607 |
|
608 key_information = set_bits_on( |
|
609 key_information, |
|
610 key_type_bit, |
|
611 m_key_information_mask_key_type, |
|
612 m_key_information_mask_key_type_shift); |
|
613 |
|
614 return set_key_information(key_information); |
|
615 } |
|
616 |
|
617 //------------------------------------------------------ |
|
618 |
|
619 // |
|
620 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information_key_index(const u8_t key_index) |
|
621 { |
|
622 EAP_ASSERT(m_is_RSNA_when_true == false || m_is_WPXM_when_true == true); |
|
623 |
|
624 u16_t key_information = get_key_information(); |
|
625 |
|
626 key_information = set_bits_on( |
|
627 key_information, |
|
628 static_cast<u16_t>(key_index), |
|
629 m_key_information_mask_key_index_WPA, |
|
630 m_key_information_mask_key_index_shift_WPA); |
|
631 |
|
632 return set_key_information(key_information); |
|
633 } |
|
634 |
|
635 //------------------------------------------------------ |
|
636 |
|
637 // |
|
638 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information_install(const bool install_bit_on_when_true) |
|
639 { |
|
640 u16_t key_information = get_key_information(); |
|
641 |
|
642 u16_t install_bit = 0; |
|
643 if (install_bit_on_when_true == true) |
|
644 { |
|
645 install_bit = 1; |
|
646 } |
|
647 |
|
648 key_information = set_bits_on( |
|
649 key_information, |
|
650 install_bit, |
|
651 m_key_information_mask_install, |
|
652 m_key_information_mask_install_shift); |
|
653 |
|
654 return set_key_information(key_information); |
|
655 } |
|
656 |
|
657 //------------------------------------------------------ |
|
658 |
|
659 // |
|
660 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information_key_ack(const bool key_ack_bit_on_when_true) |
|
661 { |
|
662 u16_t key_information = get_key_information(); |
|
663 |
|
664 u16_t key_ack_bit = 0; |
|
665 if (key_ack_bit_on_when_true == true) |
|
666 { |
|
667 key_ack_bit = 1; |
|
668 } |
|
669 |
|
670 key_information = set_bits_on( |
|
671 key_information, |
|
672 key_ack_bit, |
|
673 m_key_information_mask_key_ack, |
|
674 m_key_information_mask_key_ack_shift); |
|
675 |
|
676 return set_key_information(key_information); |
|
677 } |
|
678 |
|
679 //------------------------------------------------------ |
|
680 |
|
681 // |
|
682 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information_key_MIC(const bool key_MIC_bit_on_when_true) |
|
683 { |
|
684 u16_t key_information = get_key_information(); |
|
685 |
|
686 u16_t key_MIC_bit = 0; |
|
687 if (key_MIC_bit_on_when_true == true) |
|
688 { |
|
689 key_MIC_bit = 1; |
|
690 } |
|
691 |
|
692 key_information = set_bits_on( |
|
693 key_information, |
|
694 key_MIC_bit, |
|
695 m_key_information_mask_key_MIC, |
|
696 m_key_information_mask_key_MIC_shift); |
|
697 |
|
698 return set_key_information(key_information); |
|
699 } |
|
700 |
|
701 //------------------------------------------------------ |
|
702 |
|
703 // |
|
704 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information_secure(const bool secure_bit_on_when_true) |
|
705 { |
|
706 u16_t key_information = get_key_information(); |
|
707 |
|
708 u16_t secure_bit = 0; |
|
709 if (secure_bit_on_when_true == true) |
|
710 { |
|
711 secure_bit = 1; |
|
712 } |
|
713 |
|
714 key_information = set_bits_on( |
|
715 key_information, |
|
716 secure_bit, |
|
717 m_key_information_mask_secure, |
|
718 m_key_information_mask_secure_shift); |
|
719 |
|
720 return set_key_information(key_information); |
|
721 } |
|
722 |
|
723 //------------------------------------------------------ |
|
724 |
|
725 // |
|
726 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information_error(const bool error_bit_on_when_true) |
|
727 { |
|
728 u16_t key_information = get_key_information(); |
|
729 |
|
730 u16_t error_bit = 0; |
|
731 if (error_bit_on_when_true == true) |
|
732 { |
|
733 error_bit = 1; |
|
734 } |
|
735 |
|
736 key_information = set_bits_on( |
|
737 key_information, |
|
738 error_bit, |
|
739 m_key_information_mask_error, |
|
740 m_key_information_mask_error_shift); |
|
741 |
|
742 return set_key_information(key_information); |
|
743 } |
|
744 |
|
745 //------------------------------------------------------ |
|
746 |
|
747 // |
|
748 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information_request(const bool request_bit_is_on_when_true) |
|
749 { |
|
750 u16_t key_information = get_key_information(); |
|
751 |
|
752 u16_t request_bit = 0; |
|
753 if (request_bit_is_on_when_true == true) |
|
754 { |
|
755 request_bit = 1; |
|
756 } |
|
757 |
|
758 key_information = set_bits_on( |
|
759 key_information, |
|
760 request_bit, |
|
761 m_key_information_mask_request, |
|
762 m_key_information_mask_request_shift); |
|
763 |
|
764 return set_key_information(key_information); |
|
765 } |
|
766 |
|
767 //------------------------------------------------------ |
|
768 |
|
769 // |
|
770 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_information_encrypted_key_data(const bool encrypted_key_data_bit_is_on_when_true) |
|
771 { |
|
772 EAP_ASSERT(m_is_RSNA_when_true == true || m_is_WPXM_when_true == true); |
|
773 |
|
774 u16_t key_information = get_key_information(); |
|
775 |
|
776 u16_t encrypted_key_data_bit = 0; |
|
777 if (encrypted_key_data_bit_is_on_when_true == true) |
|
778 { |
|
779 encrypted_key_data_bit = 1; |
|
780 } |
|
781 |
|
782 key_information = set_bits_on( |
|
783 key_information, |
|
784 encrypted_key_data_bit, |
|
785 m_key_information_mask_encrypted_key_data_RSNA, |
|
786 m_key_information_mask_encrypted_key_data_shift_RSNA); |
|
787 |
|
788 return set_key_information(key_information); |
|
789 } |
|
790 |
|
791 //------------------------------------------------------ |
|
792 |
|
793 // |
|
794 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_length(const u16_t length) |
|
795 { |
|
796 u8_t * const data = get_header_offset(m_offset_key_length, sizeof(u16_t)); |
|
797 if (data != 0) |
|
798 { |
|
799 return eap_write_u16_t_network_order(data, sizeof(u16_t), length); |
|
800 } |
|
801 else |
|
802 { |
|
803 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
804 } |
|
805 } |
|
806 |
|
807 //------------------------------------------------------ |
|
808 |
|
809 // |
|
810 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_replay_counter(const u64_t reply_counter) |
|
811 { |
|
812 u8_t * const data = get_header_offset(m_offset_key_replay_counter, EAPOL_RSNA_KEY_REPLY_COUNTER_SIZE); |
|
813 if (data != 0) |
|
814 { |
|
815 return eap_write_u64_t_network_order(data, EAPOL_RSNA_KEY_REPLY_COUNTER_SIZE, reply_counter); |
|
816 } |
|
817 else |
|
818 { |
|
819 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
820 } |
|
821 } |
|
822 |
|
823 //------------------------------------------------------ |
|
824 |
|
825 // |
|
826 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::set_key_data_length(const u16_t key_data_length) |
|
827 { |
|
828 u8_t * const data = get_header_offset(m_offset_key_data_length, EAPOL_RSNA_KEY_DATA_LENGTH_SIZE); |
|
829 if (data != 0) |
|
830 { |
|
831 return eap_write_u16_t_network_order(data, EAPOL_RSNA_KEY_DATA_LENGTH_SIZE, key_data_length); |
|
832 } |
|
833 else |
|
834 { |
|
835 return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error); |
|
836 } |
|
837 } |
|
838 |
|
839 //------------------------------------------------------ |
|
840 |
|
841 // |
|
842 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::zero_EAPOL_header_and_Key_descriptor( |
|
843 abs_eap_am_tools_c * const tools |
|
844 ) |
|
845 { |
|
846 u8_t * const data = get_header_offset(0ul, get_header_length()); |
|
847 if (data != 0) |
|
848 { |
|
849 tools->memset(data, 0, get_header_length()); |
|
850 return EAP_STATUS_RETURN(tools, eap_status_ok); |
|
851 } |
|
852 else |
|
853 { |
|
854 return EAP_STATUS_RETURN(tools, eap_status_allocation_error); |
|
855 } |
|
856 } |
|
857 |
|
858 //------------------------------------------------------ |
|
859 |
|
860 // |
|
861 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::zero_key_MIC( |
|
862 abs_eap_am_tools_c * const tools |
|
863 ) |
|
864 { |
|
865 u8_t * const data = get_key_MIC(); |
|
866 if (data != 0) |
|
867 { |
|
868 tools->memset(data, 0, EAPOL_RSNA_KEY_MIC_SIZE); |
|
869 return EAP_STATUS_RETURN(tools, eap_status_ok); |
|
870 } |
|
871 else |
|
872 { |
|
873 return EAP_STATUS_RETURN(tools, eap_status_allocation_error); |
|
874 } |
|
875 } |
|
876 |
|
877 //------------------------------------------------------ |
|
878 |
|
879 // |
|
880 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::zero_key_NONCE( |
|
881 abs_eap_am_tools_c * const tools |
|
882 ) |
|
883 { |
|
884 u8_t * const data = get_key_NONCE(); |
|
885 if (data != 0) |
|
886 { |
|
887 tools->memset(data, 0, EAPOL_RSNA_KEY_NONCE_SIZE); |
|
888 return EAP_STATUS_RETURN(tools, eap_status_ok); |
|
889 } |
|
890 else |
|
891 { |
|
892 return EAP_STATUS_RETURN(tools, eap_status_allocation_error); |
|
893 } |
|
894 } |
|
895 |
|
896 //------------------------------------------------------ |
|
897 |
|
898 // |
|
899 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::zero_EAPOL_key_IV( |
|
900 abs_eap_am_tools_c * const tools |
|
901 ) |
|
902 { |
|
903 u8_t * const data = get_EAPOL_key_IV(); |
|
904 if (data != 0) |
|
905 { |
|
906 tools->memset(data, 0, EAPOL_RSNA_EAPOL_KEY_IV_SIZE); |
|
907 return EAP_STATUS_RETURN(tools, eap_status_ok); |
|
908 } |
|
909 else |
|
910 { |
|
911 return EAP_STATUS_RETURN(tools, eap_status_allocation_error); |
|
912 } |
|
913 } |
|
914 |
|
915 //------------------------------------------------------ |
|
916 |
|
917 // |
|
918 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::zero_key_RSC( |
|
919 abs_eap_am_tools_c * const tools |
|
920 ) |
|
921 { |
|
922 u8_t * const data = get_key_RSC(); |
|
923 if (data != 0) |
|
924 { |
|
925 tools->memset(data, 0, EAPOL_RSNA_KEY_RSC_SIZE); |
|
926 return EAP_STATUS_RETURN(tools, eap_status_ok); |
|
927 } |
|
928 else |
|
929 { |
|
930 return EAP_STATUS_RETURN(tools, eap_status_allocation_error); |
|
931 } |
|
932 } |
|
933 |
|
934 //------------------------------------------------------ |
|
935 |
|
936 // |
|
937 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::zero_key_STA_MAC_address( |
|
938 abs_eap_am_tools_c * const tools |
|
939 ) |
|
940 { |
|
941 u8_t * const data = get_key_STA_MAC_address(); |
|
942 if (data != 0) |
|
943 { |
|
944 tools->memset(data, 0, EAPOL_RSNA_KEY_STA_MAC_ADDRESS_SIZE); |
|
945 return EAP_STATUS_RETURN(tools, eap_status_ok); |
|
946 } |
|
947 else |
|
948 { |
|
949 return EAP_STATUS_RETURN(tools, eap_status_allocation_error); |
|
950 } |
|
951 } |
|
952 |
|
953 //------------------------------------------------------ |
|
954 |
|
955 // |
|
956 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::zero_key_reserved( |
|
957 abs_eap_am_tools_c * const tools |
|
958 ) |
|
959 { |
|
960 u8_t * const data = get_key_reserved(); |
|
961 if (data != 0) |
|
962 { |
|
963 tools->memset(data, 0, EAPOL_RSNA_KEY_RESERVED_SIZE); |
|
964 return EAP_STATUS_RETURN(tools, eap_status_ok); |
|
965 } |
|
966 else |
|
967 { |
|
968 return EAP_STATUS_RETURN(tools, eap_status_allocation_error); |
|
969 } |
|
970 } |
|
971 |
|
972 //------------------------------------------------------ |
|
973 |
|
974 // |
|
975 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::check_header() const |
|
976 { |
|
977 if (get_eapol_protocol_version() == eapol_protocol_version_none) |
|
978 { |
|
979 return EAP_STATUS_RETURN(m_am_tools, eap_status_wrong_eapol_version); |
|
980 } |
|
981 else if (get_eapol_packet_type() > eapol_packet_type_enc_asf_alert) |
|
982 { |
|
983 return EAP_STATUS_RETURN(m_am_tools, eap_status_wrong_eapol_type); |
|
984 } |
|
985 else if (get_key_information_key_descriptor_version() != m_key_descriptor_version_1 |
|
986 && get_key_information_key_descriptor_version() != m_key_descriptor_version_2) |
|
987 { |
|
988 return EAP_STATUS_RETURN(m_am_tools, eap_status_no_matching_protocol_version); |
|
989 } |
|
990 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
991 } |
|
992 |
|
993 //------------------------------------------------------ |
|
994 |
|
995 // |
|
996 EAP_FUNC_EXPORT eap_status_e eapol_RSNA_key_header_c::reset_header( |
|
997 const u8_t key_index, |
|
998 const eapol_key_authentication_type_e authentication_type, |
|
999 const eapol_RSNA_cipher_e eapol_pairwise_cipher, |
|
1000 const u64_t key_reply_counter, |
|
1001 const bool key_type_bit_on_when_true, |
|
1002 const bool install_bit_on_when_true, |
|
1003 const bool key_ack_bit_on_when_true, |
|
1004 const bool key_MIC_bit_on_when_true, |
|
1005 const bool secure_bit_on_when_true, |
|
1006 const bool error_bit_on_when_true, |
|
1007 const bool requst_bit_on_when_true, |
|
1008 const bool STAKey_bit_on_when_true, |
|
1009 const bool encrypted_key_data_bit_on_when_true, |
|
1010 const eapol_protocol_version_e used_rsna_eapol_protocol_version, |
|
1011 const eapol_key_descriptor_type_e received_key_descriptor_type) |
|
1012 { |
|
1013 EAP_UNREFERENCED_PARAMETER(encrypted_key_data_bit_on_when_true); |
|
1014 EAP_UNREFERENCED_PARAMETER(STAKey_bit_on_when_true); |
|
1015 |
|
1016 EAP_TRACE_DEBUG( |
|
1017 m_am_tools, |
|
1018 TRACE_FLAGS_DEFAULT, |
|
1019 (EAPL("EAPOL_KEY: eapol_RSNA_key_header_c::reset_header()\n"))); |
|
1020 |
|
1021 EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eapol_RSNA_key_header_c::reset_header()"); |
|
1022 |
|
1023 |
|
1024 eap_status_e status = zero_EAPOL_header_and_Key_descriptor(m_am_tools); |
|
1025 if (status != eap_status_ok) |
|
1026 { |
|
1027 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1028 } |
|
1029 |
|
1030 eapol_protocol_version_e eapol_version(eapol_protocol_version_1); |
|
1031 eapol_key_descriptor_type_e eapol_key_descriptor_type(eapol_key_descriptor_type_WPA); |
|
1032 |
|
1033 if (authentication_type == eapol_key_authentication_type_RSNA_EAP |
|
1034 || authentication_type == eapol_key_authentication_type_RSNA_PSK) |
|
1035 { |
|
1036 eapol_version = used_rsna_eapol_protocol_version; |
|
1037 eapol_key_descriptor_type = eapol_key_descriptor_type_RSNA; |
|
1038 } |
|
1039 else if (authentication_type == eapol_key_authentication_type_WPXM) |
|
1040 { |
|
1041 eapol_version = used_rsna_eapol_protocol_version; |
|
1042 |
|
1043 if (received_key_descriptor_type != eapol_key_descriptor_type_none) |
|
1044 { |
|
1045 eapol_key_descriptor_type = received_key_descriptor_type; |
|
1046 } |
|
1047 } |
|
1048 |
|
1049 eapol_key_state_string_c debug_string; |
|
1050 |
|
1051 EAP_TRACE_DEBUG( |
|
1052 m_am_tools, |
|
1053 TRACE_FLAGS_DEFAULT, |
|
1054 (EAPL("EAPOL_KEY: eapol_RSNA_key_header_c::reset_header(): eapol_key_descriptor_type = %s = 0x%02x\n"), |
|
1055 debug_string.get_eapol_key_descriptor_type_string(eapol_key_descriptor_type), |
|
1056 eapol_key_descriptor_type)); |
|
1057 |
|
1058 status = set_eapol_protocol_version(eapol_version); |
|
1059 if (status != eap_status_ok) |
|
1060 { |
|
1061 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1062 } |
|
1063 |
|
1064 |
|
1065 status = set_eapol_packet_type(eapol_packet_type_key); |
|
1066 if (status != eap_status_ok) |
|
1067 { |
|
1068 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1069 } |
|
1070 |
|
1071 status = set_key_descriptor_type(eapol_key_descriptor_type); |
|
1072 if (status != eap_status_ok) |
|
1073 { |
|
1074 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1075 } |
|
1076 |
|
1077 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
1078 |
|
1079 if (eapol_pairwise_cipher == eapol_RSNA_cipher_TKIP |
|
1080 || eapol_pairwise_cipher == eapol_RSNA_cipher_WEP_40 |
|
1081 || eapol_pairwise_cipher == eapol_RSNA_cipher_WEP_104) |
|
1082 { |
|
1083 status = set_key_information_key_descriptor_version(m_key_descriptor_version_1); |
|
1084 } |
|
1085 else if (eapol_pairwise_cipher == eapol_RSNA_cipher_CCMP) |
|
1086 { |
|
1087 status = set_key_information_key_descriptor_version(m_key_descriptor_version_2); |
|
1088 } |
|
1089 else |
|
1090 { |
|
1091 return EAP_STATUS_RETURN(m_am_tools, eap_status_no_matching_protocol_version); |
|
1092 } |
|
1093 |
|
1094 status = set_key_information_key_type(key_type_bit_on_when_true); |
|
1095 if (status != eap_status_ok) |
|
1096 { |
|
1097 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1098 } |
|
1099 |
|
1100 status = set_key_information_install(install_bit_on_when_true); |
|
1101 if (status != eap_status_ok) |
|
1102 { |
|
1103 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1104 } |
|
1105 |
|
1106 status = set_key_information_key_ack(key_ack_bit_on_when_true); |
|
1107 if (status != eap_status_ok) |
|
1108 { |
|
1109 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1110 } |
|
1111 |
|
1112 status = set_key_information_key_MIC(key_MIC_bit_on_when_true); |
|
1113 if (status != eap_status_ok) |
|
1114 { |
|
1115 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1116 } |
|
1117 |
|
1118 status = set_key_information_secure(secure_bit_on_when_true); |
|
1119 if (status != eap_status_ok) |
|
1120 { |
|
1121 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1122 } |
|
1123 |
|
1124 status = set_key_information_error(error_bit_on_when_true); |
|
1125 if (status != eap_status_ok) |
|
1126 { |
|
1127 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1128 } |
|
1129 |
|
1130 status = set_key_information_request(requst_bit_on_when_true); |
|
1131 if (status != eap_status_ok) |
|
1132 { |
|
1133 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1134 } |
|
1135 |
|
1136 if (m_is_RSNA_when_true == true || m_is_WPXM_when_true == true) |
|
1137 { |
|
1138 // RSNA |
|
1139 status = set_key_information_encrypted_key_data( |
|
1140 encrypted_key_data_bit_on_when_true); |
|
1141 if (status != eap_status_ok) |
|
1142 { |
|
1143 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1144 } |
|
1145 } |
|
1146 else |
|
1147 { |
|
1148 // WPA |
|
1149 status = set_key_information_key_index(key_index); |
|
1150 if (status != eap_status_ok) |
|
1151 { |
|
1152 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1153 } |
|
1154 |
|
1155 } |
|
1156 |
|
1157 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
1158 |
|
1159 status = set_key_replay_counter(key_reply_counter); |
|
1160 if (status != eap_status_ok) |
|
1161 { |
|
1162 return EAP_STATUS_RETURN(m_am_tools, status); |
|
1163 } |
|
1164 |
|
1165 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
|
1166 |
|
1167 return EAP_STATUS_RETURN(m_am_tools, eap_status_ok); |
|
1168 } |
|
1169 |
|
1170 // |
|
1171 //------------------------------------------------------ |
|
1172 |
|
1173 |
|
1174 |
|
1175 // End. |