|
1 /* |
|
2 * Copyright (c) 2002-2009 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: Simple utility functions for core |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "core_tools.h" |
|
20 #include "core_frame_beacon.h" |
|
21 #include "genscanoffsets.h" |
|
22 #include "am_debug.h" |
|
23 |
|
24 // ============================ MEMBER FUNCTIONS =============================== |
|
25 |
|
26 // ----------------------------------------------------------------------------- |
|
27 // core_tools_c::compare |
|
28 // ----------------------------------------------------------------------------- |
|
29 // |
|
30 int_t core_tools_c::compare( |
|
31 const u8_t* pl, |
|
32 int_t ll, |
|
33 const u8_t* pr, |
|
34 int_t rl ) |
|
35 { |
|
36 if ( ll != rl ) |
|
37 { |
|
38 return ll - rl; |
|
39 } |
|
40 |
|
41 if ( pl == pr ) |
|
42 { |
|
43 return 0; |
|
44 } |
|
45 |
|
46 for ( int_t i( 0 ); i < ll; ++i ) |
|
47 { |
|
48 if ( *(pl+i) != *(pr+i) ) |
|
49 { |
|
50 return *(pl+i) - *(pr+i); |
|
51 } |
|
52 } |
|
53 |
|
54 return 0; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // core_tools_c::copy |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 u8_t* core_tools_c::copy( |
|
62 void* trg, |
|
63 const void* src, |
|
64 int_t len ) |
|
65 { |
|
66 if ( len <= 0 ) |
|
67 { |
|
68 return reinterpret_cast<u8_t*>( trg ); |
|
69 } |
|
70 |
|
71 if ( trg == src ) |
|
72 { |
|
73 return reinterpret_cast<u8_t*>( trg ) + len; |
|
74 } |
|
75 |
|
76 // ensure areas do not overlap |
|
77 if ( trg > src ) |
|
78 { |
|
79 ASSERT( reinterpret_cast<u8_t*>( trg ) >= ( reinterpret_cast<const u8_t*>( src ) + len ) ); |
|
80 } |
|
81 else |
|
82 { |
|
83 ASSERT( reinterpret_cast<const u8_t*>( src ) >= ( reinterpret_cast<u8_t*>( trg ) + len ) ); |
|
84 } |
|
85 |
|
86 for ( i32_t i( 0 ); i < len; ++i ) |
|
87 { |
|
88 *( reinterpret_cast<u8_t*>( trg ) + i ) = *( reinterpret_cast<const u8_t*>( src ) + i ); |
|
89 } |
|
90 |
|
91 return reinterpret_cast<u8_t*>( trg ) + len; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // core_tools_c::fillz |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 void core_tools_c::fillz( |
|
99 void* trg, |
|
100 int_t len ) |
|
101 { |
|
102 if ( len <= 0 ) |
|
103 { |
|
104 return; |
|
105 } |
|
106 |
|
107 for ( int_t i( 0 ); i < len; ++i ) |
|
108 { |
|
109 *( reinterpret_cast<u8_t*>( trg ) + i ) = 0; |
|
110 } |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // core_tools_c::convert_host_to_big_endian |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 u16_t core_tools_c::convert_host_to_big_endian( |
|
118 u16_t src ) |
|
119 { |
|
120 return( static_cast<u16_t>( ( src >> 8 ) | ( src << 8 ) ) ); |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // core_tools_c::convert_host_to_big_endian |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 u32_t core_tools_c::convert_host_to_big_endian( |
|
128 u32_t src ) |
|
129 { |
|
130 return( static_cast<u32_t>( ( ( src & 0xFF ) << 24 ) | |
|
131 ( ( src & 0xFF00 ) << 8 ) | |
|
132 ( ( src & 0xFF0000 ) >> 8 ) | |
|
133 ( ( src & 0xFF000000 ) >> 24 ) ) ); |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // core_tools_c::convert_big_endian_to_host |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 u16_t core_tools_c::convert_big_endian_to_host( |
|
141 u16_t src ) |
|
142 { |
|
143 return( static_cast<u16_t>( ( src >> 8 ) | ( src << 8 ) ) ); |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // core_tools_c::convert_big_endian_to_host |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 u32_t core_tools_c::convert_big_endian_to_host( |
|
151 u32_t src ) |
|
152 { |
|
153 return( static_cast<u32_t>( ( ( src & 0xFF ) << 24 ) | |
|
154 ( ( src & 0xFF00 ) << 8 ) | |
|
155 ( ( src & 0xFF0000 ) >> 8 ) | |
|
156 ( ( src & 0xFF000000 ) >> 24 ) ) ); |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // core_tools_c::get_u16_big_endian |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 u16_t core_tools_c::get_u16_big_endian( |
|
164 const u8_t* data, |
|
165 u16_t index ) |
|
166 { |
|
167 return core_tools_c::convert_big_endian_to_host( |
|
168 get_u16( data, index ) ); |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // core_tools_c::get_u16 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 u16_t core_tools_c::get_u16( |
|
176 const u8_t* data, |
|
177 u16_t index ) |
|
178 { |
|
179 u16_t temp16( 0 ); |
|
180 core_tools_c::copy( reinterpret_cast<u8_t*>( &temp16 ), |
|
181 data + index, |
|
182 sizeof( temp16 ) ); |
|
183 |
|
184 return temp16; |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // core_tools_c::get_u32_big_endian |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 u32_t core_tools_c::get_u32_big_endian( |
|
192 const u8_t* data, |
|
193 u16_t index ) |
|
194 { |
|
195 return core_tools_c::convert_big_endian_to_host( |
|
196 get_u32( data, index ) ); |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // core_tools_c::get_u32 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 u32_t core_tools_c::get_u32( |
|
204 const u8_t* data, |
|
205 u16_t index ) |
|
206 { |
|
207 u32_t temp32( 0 ); |
|
208 core_tools_c::copy( reinterpret_cast<u8_t*>( &temp32 ), |
|
209 data + index, |
|
210 sizeof( temp32 ) ); |
|
211 |
|
212 return temp32; |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // core_tools_c::get_u64 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 u64_t core_tools_c::get_u64( |
|
220 const u8_t* data, |
|
221 u16_t index ) |
|
222 { |
|
223 u64_t temp64( 0 ); |
|
224 core_tools_c::copy( reinterpret_cast<u8_t*>( &temp64 ), |
|
225 data + index, |
|
226 sizeof( temp64 ) ); |
|
227 |
|
228 return temp64; |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // core_tools_c::insert_u16_big_endian |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void core_tools_c::insert_u16_big_endian( |
|
236 u8_t* data, |
|
237 u16_t index, |
|
238 u16_t value ) |
|
239 { |
|
240 u16_t temp16( |
|
241 convert_host_to_big_endian( value ) ); |
|
242 |
|
243 core_tools_c::copy( |
|
244 &data[index], |
|
245 reinterpret_cast<u8_t*>( &temp16 ), |
|
246 sizeof( temp16 ) ); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // core_tools_c::insert_u16 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void core_tools_c::insert_u16( |
|
254 u8_t* data, |
|
255 u16_t index, |
|
256 u16_t value ) |
|
257 { |
|
258 u16_t temp16( value ); |
|
259 |
|
260 core_tools_c::copy( |
|
261 &data[index], |
|
262 reinterpret_cast<u8_t*>( &temp16 ), |
|
263 sizeof( temp16 ) ); |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // core_tools_c::insert_u32_big_endian |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 void core_tools_c::insert_u32_big_endian( |
|
271 u8_t* data, |
|
272 u16_t index, |
|
273 u32_t value ) |
|
274 { |
|
275 u32_t temp32( |
|
276 convert_host_to_big_endian( value ) ); |
|
277 |
|
278 core_tools_c::copy( |
|
279 &data[index], |
|
280 reinterpret_cast<u8_t*>( &temp32 ), |
|
281 sizeof( temp32 ) ); |
|
282 } |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // core_tools_c::insert_u32 |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 void core_tools_c::insert_u32( |
|
289 u8_t* data, |
|
290 u16_t index, |
|
291 u32_t value ) |
|
292 { |
|
293 u32_t temp32( value ); |
|
294 |
|
295 core_tools_c::copy( |
|
296 &data[index], |
|
297 reinterpret_cast<u8_t*>( &temp32 ), |
|
298 sizeof( temp32 ) ); |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // core_tools_c::append_u16_big_endian |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 void core_tools_c::append_u16_big_endian( |
|
306 u8_t* data, |
|
307 u16_t& data_length, |
|
308 u16_t value ) |
|
309 { |
|
310 insert_u16_big_endian( |
|
311 data, |
|
312 data_length, |
|
313 value ); |
|
314 data_length += sizeof( value ); |
|
315 } |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // core_tools_c::append_u16 |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 void core_tools_c::append_u16( |
|
322 u8_t* data, |
|
323 u16_t& data_length, |
|
324 u16_t value ) |
|
325 { |
|
326 insert_u16( |
|
327 data, |
|
328 data_length, |
|
329 value ); |
|
330 data_length += sizeof( value ); |
|
331 } |
|
332 |
|
333 // ----------------------------------------------------------------------------- |
|
334 // core_tools_c::append_u32_big_endian |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 void core_tools_c::append_u32_big_endian( |
|
338 u8_t* data, |
|
339 u16_t& data_length, |
|
340 u32_t value ) |
|
341 { |
|
342 insert_u32_big_endian( |
|
343 data, |
|
344 data_length, |
|
345 value ); |
|
346 data_length += sizeof( value ); |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // core_tools_c::append_u32 |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 void core_tools_c::append_u32( |
|
354 u8_t* data, |
|
355 u16_t& data_length, |
|
356 u32_t value ) |
|
357 { |
|
358 insert_u32( |
|
359 data, |
|
360 data_length, |
|
361 value ); |
|
362 data_length += sizeof( value ); |
|
363 } |
|
364 |
|
365 // ----------------------------------------------------------------------------- |
|
366 // core_tools_c::cipher_key_type |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 core_cipher_key_type_e core_tools_c::cipher_key_type( |
|
370 core_cipher_suite_e cipher ) |
|
371 { |
|
372 switch( cipher ) |
|
373 { |
|
374 case core_cipher_suite_wep40: |
|
375 /** Falls through on purpose. */ |
|
376 case core_cipher_suite_wep104: |
|
377 return core_cipher_key_type_wep; |
|
378 case core_cipher_suite_tkip: |
|
379 return core_cipher_key_type_tkip; |
|
380 case core_cipher_suite_ccmp: |
|
381 return core_cipher_key_type_ccmp; |
|
382 case core_cipher_suite_wpi: |
|
383 return core_cipher_key_type_wpi; |
|
384 default: |
|
385 return core_cipher_key_type_none; |
|
386 } |
|
387 } |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // core_tools_c::cipher_key_type |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 core_cipher_key_type_e core_tools_c::cipher_key_type( |
|
394 wlan_eapol_if_eapol_key_type_e type, |
|
395 core_cipher_suite_e pairwise_cipher, |
|
396 core_cipher_suite_e group_cipher ) |
|
397 { |
|
398 core_cipher_key_type_e return_type( core_cipher_key_type_ccmp ); |
|
399 |
|
400 switch( type ) |
|
401 { |
|
402 case wlan_eapol_if_eapol_key_type_unicast: |
|
403 { |
|
404 if( pairwise_cipher == core_cipher_suite_ccmp ) |
|
405 { |
|
406 DEBUG( "core_tools_c::cipher_key_type() - pairwise CCMP key" ); |
|
407 return_type = core_cipher_key_type_ccmp; |
|
408 } |
|
409 else if( pairwise_cipher == core_cipher_suite_tkip ) |
|
410 { |
|
411 DEBUG( "core_tools_c::cipher_key_type() - pairwise TKIP key" ); |
|
412 return_type = core_cipher_key_type_tkip; |
|
413 } |
|
414 else if( pairwise_cipher == core_cipher_suite_wpi ) |
|
415 { |
|
416 DEBUG( "core_tools_c::cipher_key_type() - pairwise WPI key" ); |
|
417 return_type = core_cipher_key_type_wpi; |
|
418 } |
|
419 else |
|
420 { |
|
421 DEBUG( "core_tools_c::cipher_key_type() - pairwise WEP key" ); |
|
422 return_type = core_cipher_key_type_wep; |
|
423 } |
|
424 break; |
|
425 } |
|
426 case wlan_eapol_if_eapol_key_type_broadcast: |
|
427 { |
|
428 if( group_cipher == core_cipher_suite_ccmp ) |
|
429 { |
|
430 DEBUG( "core_tools_c::cipher_key_type() - group CCMP key" ); |
|
431 return_type = core_cipher_key_type_ccmp; |
|
432 } |
|
433 else if( group_cipher == core_cipher_suite_tkip ) |
|
434 { |
|
435 DEBUG( "core_tools_c::cipher_key_type() - group TKIP key" ); |
|
436 return_type = core_cipher_key_type_tkip; |
|
437 } |
|
438 else if( pairwise_cipher == core_cipher_suite_wpi ) |
|
439 { |
|
440 DEBUG( "core_tools_c::cipher_key_type() - group WPI key" ); |
|
441 return_type = core_cipher_key_type_wpi; |
|
442 } |
|
443 else |
|
444 { |
|
445 DEBUG( "core_tools_c::cipher_key_type() - group WEP key" ); |
|
446 return_type = core_cipher_key_type_wep; |
|
447 } |
|
448 break; |
|
449 } |
|
450 case wlan_eapol_if_eapol_key_type_pmkid: |
|
451 { |
|
452 DEBUG( "core_tools_c::cipher_key_type() - PMKID" ); |
|
453 ASSERT( false_t ); |
|
454 break; |
|
455 } |
|
456 default: |
|
457 { |
|
458 DEBUG1( "core_tools_c::cipher_key_type() - unknown EAPOL key type %u", |
|
459 type ); |
|
460 ASSERT( false_t ); |
|
461 } |
|
462 } |
|
463 |
|
464 return return_type; |
|
465 } |
|
466 |
|
467 // ----------------------------------------------------------------------------- |
|
468 // core_tools_c::cipher_key_type |
|
469 // ----------------------------------------------------------------------------- |
|
470 // |
|
471 wlan_eapol_if_eapol_key_authentication_type_e core_tools_c::eap_authentication_type( |
|
472 const core_iap_data_c& iap_data, |
|
473 const core_ap_data_c& ap_data ) |
|
474 { |
|
475 core_security_mode_e mode = |
|
476 iap_data.security_mode(); |
|
477 bool_t is_psk_required = |
|
478 iap_data.is_psk_used(); |
|
479 |
|
480 if( mode == core_security_mode_802dot1x && |
|
481 !ap_data.is_rsn_ie_present() && |
|
482 !ap_data.is_wpa_ie_present() ) |
|
483 { |
|
484 DEBUG( "core_tools_c::eap_authentication_type() - wlan_eapol_if_eapol_key_authentication_type_802_1x" ); |
|
485 return wlan_eapol_if_eapol_key_authentication_type_802_1x; |
|
486 } |
|
487 else if( mode == core_security_mode_802dot1x && |
|
488 ap_data.key_management_suites() & core_key_management_wpx_fast_roam ) |
|
489 { |
|
490 DEBUG( "core_tools_c::eap_authentication_type() - wlan_eapol_if_eapol_key_authentication_type_wpx_fast_roam" ); |
|
491 return wlan_eapol_if_eapol_key_authentication_type_wpx_fast_roam; |
|
492 } |
|
493 if( mode == core_security_mode_protected_setup ) |
|
494 { |
|
495 DEBUG( "core_tools_c::eap_authentication_type() - wlan_eapol_if_eapol_key_authentication_type_wfa_sc" ); |
|
496 return wlan_eapol_if_eapol_key_authentication_type_wfa_sc; |
|
497 } |
|
498 else if( iap_data.is_eap_used() ) |
|
499 { |
|
500 if( ap_data.is_rsn_ie_present() ) |
|
501 { |
|
502 if( !is_psk_required && |
|
503 ap_data.key_management_suites() & core_key_management_eap ) |
|
504 { |
|
505 DEBUG( "core_tools_c::eap_authentication_type() - wlan_eapol_if_eapol_key_authentication_type_rsna_eap" ); |
|
506 return wlan_eapol_if_eapol_key_authentication_type_rsna_eap; |
|
507 } |
|
508 else if( is_psk_required && |
|
509 ap_data.key_management_suites() & core_key_management_preshared ) |
|
510 { |
|
511 DEBUG( "core_tools_c::eap_authentication_type() - wlan_eapol_if_eapol_key_authentication_type_rsna_psk" ); |
|
512 return wlan_eapol_if_eapol_key_authentication_type_rsna_psk; |
|
513 } |
|
514 } |
|
515 else if( ap_data.is_wpa_ie_present() ) |
|
516 { |
|
517 if( !is_psk_required && |
|
518 ap_data.key_management_suites() & core_key_management_eap ) |
|
519 { |
|
520 DEBUG( "core_tools_c::eap_authentication_type() - wlan_eapol_if_eapol_key_authentication_type_wpa_eap" ); |
|
521 return wlan_eapol_if_eapol_key_authentication_type_wpa_eap; |
|
522 } |
|
523 else if( is_psk_required && |
|
524 ap_data.key_management_suites() & core_key_management_preshared ) |
|
525 { |
|
526 DEBUG( "core_tools_c::eap_authentication_type() - wlan_eapol_if_eapol_key_authentication_type_wpa_psk" ); |
|
527 return wlan_eapol_if_eapol_key_authentication_type_wpa_psk; |
|
528 } |
|
529 } |
|
530 } |
|
531 else if( iap_data.is_wapi_used() ) |
|
532 { |
|
533 if( !is_psk_required && |
|
534 ap_data.key_management_suites() & core_key_management_wapi_certificate ) |
|
535 { |
|
536 DEBUG( "core_tools_c::eap_authentication_type() - wlan_eapol_if_eapol_key_authentication_type_wapi" ); |
|
537 return wlan_eapol_if_eapol_key_authentication_type_wapi; |
|
538 } |
|
539 else if( is_psk_required && |
|
540 ap_data.key_management_suites() & core_key_management_wapi_psk ) |
|
541 { |
|
542 DEBUG( "core_tools_c::eap_authentication_type() - wlan_eapol_if_eapol_key_authentication_type_wapi_psk" ); |
|
543 return wlan_eapol_if_eapol_key_authentication_type_wapi_psk; |
|
544 } |
|
545 } |
|
546 |
|
547 DEBUG( "core_tools_c::eap_authentication_type() - unable to select security" ); |
|
548 |
|
549 return wlan_eapol_if_eapol_key_authentication_type_none; |
|
550 } |
|
551 |
|
552 // ----------------------------------------------------------------------------- |
|
553 // core_tools_c::eapol_cipher |
|
554 // ----------------------------------------------------------------------------- |
|
555 // |
|
556 wlan_eapol_if_rsna_cipher_e core_tools_c::eapol_cipher( |
|
557 core_cipher_suite_e cipher ) |
|
558 { |
|
559 switch( cipher ) |
|
560 { |
|
561 case core_cipher_suite_wep40: |
|
562 return wlan_eapol_if_rsna_cipher_wep_40; |
|
563 case core_cipher_suite_wep104: |
|
564 return wlan_eapol_if_rsna_cipher_wep_104; |
|
565 case core_cipher_suite_tkip: |
|
566 return wlan_eapol_if_rsna_cipher_tkip; |
|
567 case core_cipher_suite_ccmp: |
|
568 return wlan_eapol_if_rsna_cipher_ccmp; |
|
569 case core_cipher_suite_wpi: |
|
570 return wlan_eapol_if_wapi_cipher_wpi; |
|
571 default: |
|
572 return wlan_eapol_if_rsna_cipher_none; |
|
573 } |
|
574 } |
|
575 |
|
576 // ----------------------------------------------------------------------------- |
|
577 // core_tools_c::add_beacon_to_scan_list |
|
578 // ----------------------------------------------------------------------------- |
|
579 // |
|
580 void core_tools_c::add_beacon_to_scan_list( |
|
581 ScanList& scan_list, |
|
582 const core_ap_data_c& ap_data, |
|
583 u32_t rcpi ) |
|
584 { |
|
585 const u32_t frame_length = ap_data.frame()->data_length(); |
|
586 |
|
587 u8_t* buffer = new u8_t[frame_length + DOT11_BASE_OFFSET]; |
|
588 if ( !buffer ) |
|
589 { |
|
590 DEBUG( "core_tools_c::add_beacon_to_scan_list() - unable to create a frame buffer" ); |
|
591 |
|
592 return; |
|
593 } |
|
594 |
|
595 core_tools_c::fillz( |
|
596 buffer, |
|
597 frame_length ); |
|
598 |
|
599 /** |
|
600 * Set the RCPI value. |
|
601 */ |
|
602 core_tools_c::insert_u32( |
|
603 buffer, |
|
604 CNTRL_RX_LEVEL_OFFSET, |
|
605 rcpi ); |
|
606 |
|
607 /** |
|
608 * Set the frame length. |
|
609 */ |
|
610 core_tools_c::insert_u32( |
|
611 buffer, |
|
612 CNTRL_LENGTH_OFFSET, |
|
613 frame_length ); |
|
614 |
|
615 /** |
|
616 * Copy the actual frame data. |
|
617 */ |
|
618 core_tools_c::copy( |
|
619 &buffer[DOT11_BASE_OFFSET], |
|
620 ap_data.frame()->data(), |
|
621 frame_length ); |
|
622 |
|
623 u32_t list_length = scan_list.Append( |
|
624 frame_length + DOT11_BASE_OFFSET, |
|
625 reinterpret_cast<ScanFrame*>( buffer ) ); |
|
626 if ( list_length == APPEND_FAILED_NO_MEMORY ) |
|
627 { |
|
628 DEBUG( "core_tools_c::add_beacon_to_scan_list() - unable to append to the scan list" ); |
|
629 } |
|
630 else |
|
631 { |
|
632 DEBUG( "core_tools_c::add_beacon_to_scan_list() - BSSID added to the list" ); |
|
633 DEBUG1( "core_tools_c::add_beacon_to_scan_list() - entry length: %u", |
|
634 frame_length + DOT11_BASE_OFFSET ); |
|
635 DEBUG1( "core_tools_c::add_beacon_to_scan_list() - list size after append: %u", |
|
636 list_length ); |
|
637 } |
|
638 |
|
639 delete[] buffer; |
|
640 buffer = NULL; |
|
641 } |
|
642 |
|
643 // ----------------------------------------------------------------------------- |
|
644 // core_tools_c::convert_user_priority_to_ac |
|
645 // ----------------------------------------------------------------------------- |
|
646 // |
|
647 core_access_class_e core_tools_c::convert_user_priority_to_ac( |
|
648 u8_t user_priority ) |
|
649 { |
|
650 /** |
|
651 * Mapping of 802.1D Priority to Access Class from WMM specification. |
|
652 */ |
|
653 const u8_t mapping_table[MAX_QOS_USER_PRIORITY] = |
|
654 { |
|
655 core_access_class_best_effort, |
|
656 core_access_class_background, |
|
657 core_access_class_background, |
|
658 core_access_class_best_effort, |
|
659 core_access_class_video, |
|
660 core_access_class_video, |
|
661 core_access_class_voice, |
|
662 core_access_class_voice |
|
663 }; |
|
664 |
|
665 if ( user_priority >= MAX_QOS_USER_PRIORITY ) |
|
666 { |
|
667 return core_access_class_best_effort; |
|
668 } |
|
669 |
|
670 return static_cast<core_access_class_e>( mapping_table[user_priority] ); |
|
671 } |
|
672 |
|
673 // ----------------------------------------------------------------------------- |
|
674 // core_tools_c::convert_ac_to_user_priority |
|
675 // ----------------------------------------------------------------------------- |
|
676 // |
|
677 u8_t core_tools_c::convert_ac_to_user_priority( |
|
678 core_access_class_e access_class ) |
|
679 { |
|
680 /** |
|
681 * Based on 802.1D mapping from WMM specification. |
|
682 */ |
|
683 const u8_t mapping_table[MAX_QOS_ACCESS_CLASS] = |
|
684 { |
|
685 3, // core_access_class_best_effort |
|
686 2, // core_access_class_background |
|
687 5, // core_access_class_video |
|
688 7, // core_access_class_voice |
|
689 }; |
|
690 |
|
691 return mapping_table[access_class]; |
|
692 } |
|
693 |
|
694 // ----------------------------------------------------------------------------- |
|
695 // core_tools_c::convert_tx_rate_to_tx_rate_enum |
|
696 // ----------------------------------------------------------------------------- |
|
697 // |
|
698 core_tx_rate_e core_tools_c::convert_tx_rate_to_tx_rate_enum( |
|
699 u8_t tx_rate ) |
|
700 { |
|
701 switch( tx_rate ) |
|
702 { |
|
703 case core_tx_rate_value_1mbit: |
|
704 return core_tx_rate_1mbit; |
|
705 case core_tx_rate_value_2mbit: |
|
706 return core_tx_rate_2mbit; |
|
707 case core_tx_rate_value_5p5mbit: |
|
708 return core_tx_rate_5p5mbit; |
|
709 case core_tx_rate_value_6mbit: |
|
710 return core_tx_rate_6mbit; |
|
711 case core_tx_rate_value_9mbit: |
|
712 return core_tx_rate_9mbit; |
|
713 case core_tx_rate_value_11mbit: |
|
714 return core_tx_rate_11mbit; |
|
715 case core_tx_rate_value_12mbit: |
|
716 return core_tx_rate_12mbit; |
|
717 case core_tx_rate_value_18mbit: |
|
718 return core_tx_rate_18mbit; |
|
719 case core_tx_rate_value_22mbit: |
|
720 return core_tx_rate_22mbit; |
|
721 case core_tx_rate_value_24mbit: |
|
722 return core_tx_rate_24mbit; |
|
723 case core_tx_rate_value_33mbit: |
|
724 return core_tx_rate_33mbit; |
|
725 case core_tx_rate_value_36mbit: |
|
726 return core_tx_rate_36mbit; |
|
727 case core_tx_rate_value_48mbit: |
|
728 return core_tx_rate_48mbit; |
|
729 case core_tx_rate_value_54mbit: |
|
730 return core_tx_rate_54mbit; |
|
731 default: |
|
732 return core_tx_rate_none; |
|
733 } |
|
734 } |
|
735 |
|
736 // ----------------------------------------------------------------------------- |
|
737 // core_tools_c::convert_tx_rate_enum_to_tx_rate |
|
738 // ----------------------------------------------------------------------------- |
|
739 // |
|
740 u8_t core_tools_c::convert_tx_rate_enum_to_tx_rate( |
|
741 core_tx_rate_e tx_rate ) |
|
742 { |
|
743 switch( tx_rate ) |
|
744 { |
|
745 case core_tx_rate_1mbit: |
|
746 return core_tx_rate_value_1mbit; |
|
747 case core_tx_rate_2mbit: |
|
748 return core_tx_rate_value_2mbit; |
|
749 case core_tx_rate_5p5mbit: |
|
750 return core_tx_rate_value_5p5mbit; |
|
751 case core_tx_rate_6mbit: |
|
752 return core_tx_rate_value_6mbit; |
|
753 case core_tx_rate_9mbit: |
|
754 return core_tx_rate_value_9mbit; |
|
755 case core_tx_rate_11mbit: |
|
756 return core_tx_rate_value_11mbit; |
|
757 case core_tx_rate_12mbit: |
|
758 return core_tx_rate_value_12mbit; |
|
759 case core_tx_rate_18mbit: |
|
760 return core_tx_rate_value_18mbit; |
|
761 case core_tx_rate_22mbit: |
|
762 return core_tx_rate_value_22mbit; |
|
763 case core_tx_rate_24mbit: |
|
764 return core_tx_rate_value_24mbit; |
|
765 case core_tx_rate_33mbit: |
|
766 return core_tx_rate_value_33mbit; |
|
767 case core_tx_rate_36mbit: |
|
768 return core_tx_rate_value_36mbit; |
|
769 case core_tx_rate_48mbit: |
|
770 return core_tx_rate_value_48mbit; |
|
771 case core_tx_rate_54mbit: |
|
772 return core_tx_rate_value_54mbit; |
|
773 default: |
|
774 return core_tx_rate_value_none; |
|
775 } |
|
776 } |
|
777 |
|
778 // ----------------------------------------------------------------------------- |
|
779 // core_tools_c::highest_tx_rate |
|
780 // ----------------------------------------------------------------------------- |
|
781 // |
|
782 core_tx_rate_e core_tools_c::highest_tx_rate( |
|
783 u32_t tx_rates ) |
|
784 { |
|
785 if ( tx_rates & core_tx_rate_54mbit ) |
|
786 { |
|
787 return core_tx_rate_54mbit; |
|
788 } |
|
789 else if ( tx_rates & core_tx_rate_48mbit ) |
|
790 { |
|
791 return core_tx_rate_48mbit; |
|
792 } |
|
793 else if ( tx_rates & core_tx_rate_36mbit ) |
|
794 { |
|
795 return core_tx_rate_36mbit; |
|
796 } |
|
797 else if ( tx_rates & core_tx_rate_33mbit ) |
|
798 { |
|
799 return core_tx_rate_33mbit; |
|
800 } |
|
801 else if ( tx_rates & core_tx_rate_24mbit ) |
|
802 { |
|
803 return core_tx_rate_24mbit; |
|
804 } |
|
805 else if ( tx_rates & core_tx_rate_22mbit ) |
|
806 { |
|
807 return core_tx_rate_22mbit; |
|
808 } |
|
809 else if ( tx_rates & core_tx_rate_18mbit ) |
|
810 { |
|
811 return core_tx_rate_18mbit; |
|
812 } |
|
813 else if ( tx_rates & core_tx_rate_12mbit ) |
|
814 { |
|
815 return core_tx_rate_12mbit; |
|
816 } |
|
817 else if ( tx_rates & core_tx_rate_11mbit ) |
|
818 { |
|
819 return core_tx_rate_11mbit; |
|
820 } |
|
821 else if ( tx_rates & core_tx_rate_9mbit ) |
|
822 { |
|
823 return core_tx_rate_9mbit; |
|
824 } |
|
825 else if ( tx_rates & core_tx_rate_6mbit ) |
|
826 { |
|
827 return core_tx_rate_6mbit; |
|
828 } |
|
829 else if ( tx_rates & core_tx_rate_5p5mbit ) |
|
830 { |
|
831 return core_tx_rate_5p5mbit; |
|
832 } |
|
833 else if ( tx_rates & core_tx_rate_2mbit ) |
|
834 { |
|
835 return core_tx_rate_2mbit; |
|
836 } |
|
837 else if ( tx_rates & core_tx_rate_1mbit ) |
|
838 { |
|
839 return core_tx_rate_1mbit; |
|
840 } |
|
841 |
|
842 return core_tx_rate_none; |
|
843 } |
|
844 |
|
845 // ----------------------------------------------------------------------------- |
|
846 // core_tools_c::convert_tx_rates_to_tx_policy |
|
847 // ----------------------------------------------------------------------------- |
|
848 // |
|
849 core_tx_rate_policy_s core_tools_c::convert_tx_rates_to_tx_policy( |
|
850 u32_t tx_rates ) |
|
851 { |
|
852 const u8_t RETRIES = 1; |
|
853 |
|
854 core_tx_rate_policy_s policy; |
|
855 core_tools_c::fillz( |
|
856 &policy, |
|
857 sizeof( policy ) ); |
|
858 |
|
859 if ( tx_rates & core_tx_rate_54mbit ) |
|
860 { |
|
861 policy.tx_policy_54 = RETRIES; |
|
862 } |
|
863 if( tx_rates & core_tx_rate_48mbit ) |
|
864 { |
|
865 policy.tx_policy_48 = RETRIES; |
|
866 } |
|
867 if( tx_rates & core_tx_rate_36mbit ) |
|
868 { |
|
869 policy.tx_policy_36 = RETRIES; |
|
870 } |
|
871 if( tx_rates & core_tx_rate_33mbit ) |
|
872 { |
|
873 policy.tx_policy_33 = RETRIES; |
|
874 } |
|
875 if( tx_rates & core_tx_rate_24mbit ) |
|
876 { |
|
877 policy.tx_policy_24 = RETRIES; |
|
878 } |
|
879 if( tx_rates & core_tx_rate_22mbit ) |
|
880 { |
|
881 policy.tx_policy_22 = RETRIES; |
|
882 } |
|
883 if( tx_rates & core_tx_rate_18mbit ) |
|
884 { |
|
885 policy.tx_policy_18 = RETRIES; |
|
886 } |
|
887 if( tx_rates & core_tx_rate_12mbit ) |
|
888 { |
|
889 policy.tx_policy_12 = RETRIES; |
|
890 } |
|
891 if( tx_rates & core_tx_rate_11mbit ) |
|
892 { |
|
893 policy.tx_policy_11 = RETRIES; |
|
894 } |
|
895 if( tx_rates & core_tx_rate_9mbit ) |
|
896 { |
|
897 policy.tx_policy_9 = RETRIES; |
|
898 } |
|
899 if( tx_rates & core_tx_rate_6mbit ) |
|
900 { |
|
901 policy.tx_policy_6 = RETRIES; |
|
902 } |
|
903 if( tx_rates & core_tx_rate_5p5mbit ) |
|
904 { |
|
905 policy.tx_policy_5p5 = RETRIES; |
|
906 } |
|
907 if( tx_rates & core_tx_rate_2mbit ) |
|
908 { |
|
909 policy.tx_policy_2 = RETRIES; |
|
910 } |
|
911 if( tx_rates & core_tx_rate_1mbit ) |
|
912 { |
|
913 policy.tx_policy_1 = RETRIES; |
|
914 } |
|
915 |
|
916 /** |
|
917 * short_retry_limit, long_retry_limit, flags and initial_tx_rate |
|
918 * will be filled later. |
|
919 */ |
|
920 |
|
921 return policy; |
|
922 } |
|
923 |
|
924 // ----------------------------------------------------------------------------- |
|
925 // core_tools_c::security_mode |
|
926 // ----------------------------------------------------------------------------- |
|
927 // |
|
928 core_connection_security_mode_e core_tools_c::security_mode( |
|
929 const core_iap_data_c& iap_data, |
|
930 const core_ap_data_c& ap_data ) |
|
931 { |
|
932 // Check for open connection |
|
933 // (open security map 1:1 with iap's security mode) |
|
934 if( iap_data.security_mode() == core_security_mode_allow_unsecure ) |
|
935 { |
|
936 DEBUG( "core_tools_c::security_mode() - core_connection_security_mode_open" ); |
|
937 return core_connection_security_mode_open; |
|
938 } |
|
939 |
|
940 // Check for wep connection |
|
941 if( iap_data.security_mode() == core_security_mode_wep ) |
|
942 { |
|
943 DEBUG( "core_tools_c::security_mode() - core_security_mode_wep" ); |
|
944 if ( iap_data.authentication_mode() == core_authentication_mode_shared ) |
|
945 { |
|
946 return core_connection_security_mode_wep_shared; |
|
947 } |
|
948 return core_connection_security_mode_wep_open; |
|
949 } |
|
950 |
|
951 // Check for WPX fast-roam |
|
952 if( ( iap_data.security_mode() == core_security_mode_802dot1x ) && |
|
953 ( ap_data.key_management_suites() & core_key_management_wpx_fast_roam ) ) |
|
954 { |
|
955 DEBUG( "core_tools_c::security_mode() - core_connection_security_mode_802d1x" ); |
|
956 return core_connection_security_mode_802d1x; |
|
957 } |
|
958 |
|
959 // Check for wpa/wpa2 |
|
960 if( ap_data.key_management_suites() & core_key_management_eap ) |
|
961 { |
|
962 if( ap_data.is_rsn_ie_present() && |
|
963 ap_data.group_cipher() == core_cipher_suite_ccmp && |
|
964 ap_data.pairwise_ciphers() == core_cipher_suite_ccmp ) |
|
965 { |
|
966 DEBUG( "core_tools_c::security_mode() - core_connection_security_mode_wpa2" ); |
|
967 return core_connection_security_mode_wpa2; |
|
968 } |
|
969 else |
|
970 { |
|
971 DEBUG( "core_tools_c::security_mode() - core_connection_security_mode_wpa" ); |
|
972 return core_connection_security_mode_wpa; |
|
973 } |
|
974 } |
|
975 |
|
976 // Check for wpa_psk/wpa2_psk |
|
977 if( ap_data.key_management_suites() & core_key_management_preshared ) |
|
978 { |
|
979 if( ap_data.is_rsn_ie_present() && |
|
980 ap_data.group_cipher() == core_cipher_suite_ccmp && |
|
981 ap_data.pairwise_ciphers() == core_cipher_suite_ccmp ) |
|
982 { |
|
983 DEBUG( "core_tools_c::security_mode() - core_connection_security_mode_wpa2_psk" ); |
|
984 return core_connection_security_mode_wpa2_psk; |
|
985 } |
|
986 else |
|
987 { |
|
988 DEBUG( "core_tools_c::security_mode() - core_connection_security_mode_wpa_psk" ); |
|
989 return core_connection_security_mode_wpa_psk; |
|
990 } |
|
991 } |
|
992 |
|
993 if( ap_data.key_management_suites() & core_key_management_wapi_certificate ) |
|
994 { |
|
995 DEBUG( "core_tools_c::security_mode() - core_connection_security_mode_wapi" ); |
|
996 return core_connection_security_mode_wapi; |
|
997 } |
|
998 |
|
999 if( ap_data.key_management_suites() & core_key_management_wapi_psk ) |
|
1000 { |
|
1001 DEBUG( "core_tools_c::security_mode() - core_key_management_wapi_psk" ); |
|
1002 return core_connection_security_mode_wapi_psk; |
|
1003 } |
|
1004 |
|
1005 // 802.1x is the only one left |
|
1006 DEBUG( "core_tools_c::security_mode() - core_connection_security_mode_802d1x" ); |
|
1007 return core_connection_security_mode_802d1x; |
|
1008 } |
|
1009 |
|
1010 // ----------------------------------------------------------------------------- |
|
1011 // core_tools_c::convert_eapol_error_to_protected_setup_status |
|
1012 // ----------------------------------------------------------------------------- |
|
1013 // |
|
1014 core_protected_setup_status_e core_tools_c::convert_eapol_error_to_protected_setup_status( |
|
1015 const wlan_eapol_if_eap_status_e error ) |
|
1016 { |
|
1017 core_protected_setup_status_e status( core_protected_setup_status_undefined ); |
|
1018 switch ( error ) |
|
1019 { |
|
1020 case wlan_eapol_if_eap_status_OOB_interface_read_error: |
|
1021 status = core_protected_setup_status_OOB_interface_read_error; |
|
1022 break; |
|
1023 case wlan_eapol_if_eap_status_decryption_CRC_failure: |
|
1024 status = core_protected_setup_status_decryption_CRC_failure; |
|
1025 break; |
|
1026 case wlan_eapol_if_eap_status_RF_band_2_4_ghz_not_supported: |
|
1027 status = core_protected_setup_status_RF_band_2_4_ghz_not_supported; |
|
1028 break; |
|
1029 case wlan_eapol_if_eap_status_RF_band_5_0_ghz_not_supported: |
|
1030 status = core_protected_setup_status_RF_band_5_0_ghz_not_supported; |
|
1031 break; |
|
1032 case wlan_eapol_if_eap_status_signal_too_weak: |
|
1033 status = core_protected_setup_status_signal_too_weak; |
|
1034 break; |
|
1035 case wlan_eapol_if_eap_status_authentication_failure: // Falls through on purpose. |
|
1036 case wlan_eapol_if_eap_status_network_authentication_failure: |
|
1037 status = core_protected_setup_status_network_auth_failure; |
|
1038 break; |
|
1039 case wlan_eapol_if_eap_status_network_association_failure: |
|
1040 status = core_protected_setup_status_network_assoc_failure; |
|
1041 break; |
|
1042 case wlan_eapol_if_eap_status_no_DHCP_response: |
|
1043 status = core_protected_setup_status_no_DHCP_response; |
|
1044 break; |
|
1045 case wlan_eapol_if_eap_status_failed_DHCP_configure: |
|
1046 status = core_protected_setup_status_failed_DHCP_configure; |
|
1047 break; |
|
1048 case wlan_eapol_if_eap_status_ip_address_conflict: |
|
1049 status = core_protected_setup_status_ip_address_conflict; |
|
1050 break; |
|
1051 case wlan_eapol_if_eap_status_could_not_connect_to_registrar: |
|
1052 status = core_protected_setup_status_could_not_connect_to_registrar; |
|
1053 break; |
|
1054 case wlan_eapol_if_eap_status_multiple_PBC_sessions_detected: |
|
1055 status = core_protected_setup_status_multiple_PBC_sessions_detected; |
|
1056 break; |
|
1057 case wlan_eapol_if_eap_status_rogue_activity_suspected: |
|
1058 status = core_protected_setup_status_rogue_activity_suspected; |
|
1059 break; |
|
1060 case wlan_eapol_if_eap_status_device_busy: |
|
1061 status = core_protected_setup_status_device_busy; |
|
1062 break; |
|
1063 case wlan_eapol_if_eap_status_setup_locked: |
|
1064 status = core_protected_setup_status_setup_locked; |
|
1065 break; |
|
1066 case wlan_eapol_if_eap_status_message_timeout: |
|
1067 status = core_protected_setup_status_message_timeout; |
|
1068 break; |
|
1069 case wlan_eapol_if_eap_status_registration_session_timeout: |
|
1070 status = core_protected_setup_status_registration_session_timeout; |
|
1071 break; |
|
1072 case wlan_eapol_if_eap_status_device_password_authentication_failure: |
|
1073 status = core_protected_setup_status_device_password_authentication_failure; |
|
1074 break; |
|
1075 case wlan_eapol_if_eap_status_pin_code_authentication_not_supported: |
|
1076 status = core_protected_setup_status_pin_code_authentication_not_supported; |
|
1077 break; |
|
1078 case wlan_eapol_if_eap_status_push_button_authentication_not_supported: |
|
1079 status = core_protected_setup_status_push_button_authentication_not_supported; |
|
1080 break; |
|
1081 default: |
|
1082 status = core_protected_setup_status_undefined; |
|
1083 break; |
|
1084 } |
|
1085 |
|
1086 return status; |
|
1087 } |
|
1088 |
|
1089 // ----------------------------------------------------------------------------- |
|
1090 // core_tools_c::convert_country_to_region |
|
1091 // ----------------------------------------------------------------------------- |
|
1092 // |
|
1093 core_wlan_region_e core_tools_c::convert_country_to_region( |
|
1094 const core_country_string_s& found_country ) |
|
1095 { |
|
1096 bool_t match( true_t ); |
|
1097 for ( u8_t i(0); i < country_info_table_length; i++ ) |
|
1098 { |
|
1099 match = true_t; |
|
1100 for ( u8_t j( 0 ); j < MAX_COUNTRY_STRING_LENGTH-1; ++j ) |
|
1101 { |
|
1102 if ( *( country_info_table[i].country+j ) != *( found_country.country+j ) ) |
|
1103 { |
|
1104 match = false_t; |
|
1105 break; |
|
1106 } |
|
1107 } |
|
1108 if( match ) |
|
1109 { |
|
1110 return core_wlan_region_fcc; |
|
1111 } |
|
1112 } |
|
1113 return core_wlan_region_etsi; |
|
1114 } |
|
1115 |