sm.c (f3582630aa9f7f5652be9a6149e147187935e485) | sm.c (8b3ffec5c933068b9ea632385ab6f80d1a7ed022) |
---|---|
1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 1351 unchanged lines hidden (view full) --- 1360 1361static void sm_sc_prepare_dhkey_check(sm_connection_t * sm_conn); 1362static int sm_passkey_used(stk_generation_method_t method); 1363static int sm_just_works_or_numeric_comparison(stk_generation_method_t method); 1364 1365static void sm_sc_start_calculating_local_confirm(sm_connection_t * sm_conn){ 1366 if (sm_passkey_used(setup->sm_stk_generation_method)){ 1367 // sm_conn->sm_engine_state = SM_SC_W2_GET_RANDOM_A; | 1/* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 1351 unchanged lines hidden (view full) --- 1360 1361static void sm_sc_prepare_dhkey_check(sm_connection_t * sm_conn); 1362static int sm_passkey_used(stk_generation_method_t method); 1363static int sm_just_works_or_numeric_comparison(stk_generation_method_t method); 1364 1365static void sm_sc_start_calculating_local_confirm(sm_connection_t * sm_conn){ 1366 if (sm_passkey_used(setup->sm_stk_generation_method)){ 1367 // sm_conn->sm_engine_state = SM_SC_W2_GET_RANDOM_A; |
1368 btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_nonce, 16, &sm_handle_random_result_sc_get_random, sm_conn); | 1368 btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_nonce, 16, &sm_handle_random_result_sc_get_random, (void *)(uintptr_t) sm_conn->sm_handle); |
1369 } else { 1370 sm_conn->sm_engine_state = SM_SC_W2_CMAC_FOR_CONFIRMATION; 1371 } 1372} 1373 1374static void sm_sc_state_after_receiving_random(sm_connection_t * sm_conn){ 1375 if (IS_RESPONDER(sm_conn->sm_role)){ 1376 // Responder 1377 if (setup->sm_stk_generation_method == OOB){ 1378 // generate Nb 1379 log_info("Generate Nb"); 1380 // sm_conn->sm_engine_state = SM_SC_W2_GET_RANDOM_A; | 1369 } else { 1370 sm_conn->sm_engine_state = SM_SC_W2_CMAC_FOR_CONFIRMATION; 1371 } 1372} 1373 1374static void sm_sc_state_after_receiving_random(sm_connection_t * sm_conn){ 1375 if (IS_RESPONDER(sm_conn->sm_role)){ 1376 // Responder 1377 if (setup->sm_stk_generation_method == OOB){ 1378 // generate Nb 1379 log_info("Generate Nb"); 1380 // sm_conn->sm_engine_state = SM_SC_W2_GET_RANDOM_A; |
1381 btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_nonce, 16, &sm_handle_random_result_sc_get_random, sm_conn); | 1381 btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_nonce, 16, &sm_handle_random_result_sc_get_random, (void *)(uintptr_t) sm_conn->sm_handle); |
1382 } else { 1383 sm_conn->sm_engine_state = SM_SC_SEND_PAIRING_RANDOM; 1384 } 1385 } else { 1386 // Initiator role 1387 switch (setup->sm_stk_generation_method){ 1388 case JUST_WORKS: 1389 sm_sc_prepare_dhkey_check(sm_conn); --- 1570 unchanged lines hidden (view full) --- 2960 } else { 2961 if (setup->sm_use_secure_connections){ 2962 connection->sm_engine_state = SM_SC_SEND_PUBLIC_KEY_COMMAND; 2963 } else { 2964 connection->sm_engine_state = SM_PH1_W4_USER_RESPONSE; 2965 sm_trigger_user_response(connection); 2966 // response_idle == nothing <--> sm_trigger_user_response() did not require response 2967 if (setup->sm_user_response == SM_USER_RESPONSE_IDLE){ | 1382 } else { 1383 sm_conn->sm_engine_state = SM_SC_SEND_PAIRING_RANDOM; 1384 } 1385 } else { 1386 // Initiator role 1387 switch (setup->sm_stk_generation_method){ 1388 case JUST_WORKS: 1389 sm_sc_prepare_dhkey_check(sm_conn); --- 1570 unchanged lines hidden (view full) --- 2960 } else { 2961 if (setup->sm_use_secure_connections){ 2962 connection->sm_engine_state = SM_SC_SEND_PUBLIC_KEY_COMMAND; 2963 } else { 2964 connection->sm_engine_state = SM_PH1_W4_USER_RESPONSE; 2965 sm_trigger_user_response(connection); 2966 // response_idle == nothing <--> sm_trigger_user_response() did not require response 2967 if (setup->sm_user_response == SM_USER_RESPONSE_IDLE){ |
2968 btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_random, 16, &sm_handle_random_result_ph2_random, (void *)(uintptr_t) connection->sm_handle); | 2968 btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_random, 16, &sm_handle_random_result_ph2_random, (void *)(uintptr_t) connection->sm_handle); |
2969 } 2970 } 2971 } 2972 sm_run(); 2973} 2974 2975static void sm_handle_random_result_ph3_div(void * arg){ 2976 hci_con_handle_t con_handle = (hci_con_handle_t) (uintptr_t) arg; --- 12 unchanged lines hidden (view full) --- 2989 sm_connection_t * connection = sm_get_connection_for_handle(con_handle); 2990 if (connection == NULL) return; 2991 2992 reverse_64(sm_random_data, setup->sm_local_rand); 2993 // no db for encryption size hack: encryption size is stored in lowest nibble of setup->sm_local_rand 2994 setup->sm_local_rand[7] = (setup->sm_local_rand[7] & 0xf0) + (connection->sm_actual_encryption_key_size - 1); 2995 // no db for authenticated flag hack: store flag in bit 4 of LSB 2996 setup->sm_local_rand[7] = (setup->sm_local_rand[7] & 0xef) + (connection->sm_connection_authenticated << 4); | 2969 } 2970 } 2971 } 2972 sm_run(); 2973} 2974 2975static void sm_handle_random_result_ph3_div(void * arg){ 2976 hci_con_handle_t con_handle = (hci_con_handle_t) (uintptr_t) arg; --- 12 unchanged lines hidden (view full) --- 2989 sm_connection_t * connection = sm_get_connection_for_handle(con_handle); 2990 if (connection == NULL) return; 2991 2992 reverse_64(sm_random_data, setup->sm_local_rand); 2993 // no db for encryption size hack: encryption size is stored in lowest nibble of setup->sm_local_rand 2994 setup->sm_local_rand[7] = (setup->sm_local_rand[7] & 0xf0) + (connection->sm_actual_encryption_key_size - 1); 2995 // no db for authenticated flag hack: store flag in bit 4 of LSB 2996 setup->sm_local_rand[7] = (setup->sm_local_rand[7] & 0xef) + (connection->sm_connection_authenticated << 4); |
2997 btstack_crypto_random_generate(&sm_crypto_random_request, sm_random_data, 2, &sm_handle_random_result_ph3_div, connection); | 2997 btstack_crypto_random_generate(&sm_crypto_random_request, sm_random_data, 2, &sm_handle_random_result_ph3_div, (void *)(uintptr_t) connection->sm_handle); |
2998} 2999static void sm_validate_er_ir(void){ 3000 // warn about default ER/IR 3001 int warning = 0; 3002 if (sm_ir_is_default()){ 3003 warning = 1; 3004 log_error("Persistent IR not set with sm_set_ir. Use of private addresses will cause pairing issues"); 3005 } --- 1335 unchanged lines hidden --- | 2998} 2999static void sm_validate_er_ir(void){ 3000 // warn about default ER/IR 3001 int warning = 0; 3002 if (sm_ir_is_default()){ 3003 warning = 1; 3004 log_error("Persistent IR not set with sm_set_ir. Use of private addresses will cause pairing issues"); 3005 } --- 1335 unchanged lines hidden --- |