sm.c (ea579a451be77a4a5dc2e0a81527f7d08d1a0cf3) | sm.c (49c9e430a1b2e317de597d51dee27c174ee41245) |
---|---|
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 --- 2688 unchanged lines hidden (view full) --- 2697#endif 2698 2699#ifdef ENABLE_LE_CENTRAL 2700 // initiator side 2701 2702 case SM_INITIATOR_PH4_HAS_LTK: { 2703 sm_reset_setup(); 2704 sm_load_security_info(connection); | 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 --- 2688 unchanged lines hidden (view full) --- 2697#endif 2698 2699#ifdef ENABLE_LE_CENTRAL 2700 // initiator side 2701 2702 case SM_INITIATOR_PH4_HAS_LTK: { 2703 sm_reset_setup(); 2704 sm_load_security_info(connection); |
2705 sm_reencryption_started(connection); | |
2706 2707 sm_key_t peer_ltk_flipped; 2708 reverse_128(setup->sm_peer_ltk, peer_ltk_flipped); 2709 connection->sm_engine_state = SM_PH4_W4_CONNECTION_ENCRYPTED; 2710 log_info("sm: hci_le_start_encryption ediv 0x%04x", setup->sm_peer_ediv); 2711 uint32_t rand_high = big_endian_read_32(setup->sm_peer_rand, 0); 2712 uint32_t rand_low = big_endian_read_32(setup->sm_peer_rand, 4); 2713 hci_send_cmd(&hci_le_start_encryption, connection->sm_handle,rand_low, rand_high, setup->sm_peer_ediv, peer_ltk_flipped); | 2705 2706 sm_key_t peer_ltk_flipped; 2707 reverse_128(setup->sm_peer_ltk, peer_ltk_flipped); 2708 connection->sm_engine_state = SM_PH4_W4_CONNECTION_ENCRYPTED; 2709 log_info("sm: hci_le_start_encryption ediv 0x%04x", setup->sm_peer_ediv); 2710 uint32_t rand_high = big_endian_read_32(setup->sm_peer_rand, 0); 2711 uint32_t rand_low = big_endian_read_32(setup->sm_peer_rand, 4); 2712 hci_send_cmd(&hci_le_start_encryption, connection->sm_handle,rand_low, rand_high, setup->sm_peer_ediv, peer_ltk_flipped); |
2713 2714 // notify after sending 2715 sm_reencryption_started(connection); |
|
2714 return; 2715 } 2716 2717 case SM_INITIATOR_PH1_W2_SEND_PAIRING_REQUEST: 2718 sm_reset_setup(); 2719 sm_init_setup(connection); | 2716 return; 2717 } 2718 2719 case SM_INITIATOR_PH1_W2_SEND_PAIRING_REQUEST: 2720 sm_reset_setup(); 2721 sm_init_setup(connection); |
2720 sm_timeout_start(connection); 2721 sm_pairing_started(connection); | |
2722 2723 sm_pairing_packet_set_code(setup->sm_m_preq, SM_CODE_PAIRING_REQUEST); 2724 connection->sm_engine_state = SM_INITIATOR_PH1_W4_PAIRING_RESPONSE; 2725 sm_send_connectionless(connection, (uint8_t*) &setup->sm_m_preq, sizeof(sm_pairing_packet_t)); 2726 sm_timeout_reset(connection); | 2722 2723 sm_pairing_packet_set_code(setup->sm_m_preq, SM_CODE_PAIRING_REQUEST); 2724 connection->sm_engine_state = SM_INITIATOR_PH1_W4_PAIRING_RESPONSE; 2725 sm_send_connectionless(connection, (uint8_t*) &setup->sm_m_preq, sizeof(sm_pairing_packet_t)); 2726 sm_timeout_reset(connection); |
2727 2728 // notify after sending 2729 sm_pairing_started(connection); |
|
2727 break; 2728#endif 2729 2730#ifdef ENABLE_LE_SECURE_CONNECTIONS 2731 2732 case SM_SC_SEND_PUBLIC_KEY_COMMAND: { 2733 bool trigger_user_response = false; 2734 bool trigger_start_calculating_local_confirm = false; --- 184 unchanged lines hidden (view full) --- 2919 sm_reencryption_complete(connection, ERROR_CODE_PIN_OR_KEY_MISSING); 2920 } 2921 break; 2922 default: 2923 break; 2924 } 2925 2926 sm_init_setup(connection); | 2730 break; 2731#endif 2732 2733#ifdef ENABLE_LE_SECURE_CONNECTIONS 2734 2735 case SM_SC_SEND_PUBLIC_KEY_COMMAND: { 2736 bool trigger_user_response = false; 2737 bool trigger_start_calculating_local_confirm = false; --- 184 unchanged lines hidden (view full) --- 2922 sm_reencryption_complete(connection, ERROR_CODE_PIN_OR_KEY_MISSING); 2923 } 2924 break; 2925 default: 2926 break; 2927 } 2928 2929 sm_init_setup(connection); |
2927 sm_pairing_started(connection); | |
2928 2929 // recover pairing request 2930 (void)memcpy(&setup->sm_m_preq, &connection->sm_m_preq, sizeof(sm_pairing_packet_t)); 2931 err = sm_stk_generation_init(connection); 2932 2933#ifdef ENABLE_TESTING_SUPPORT 2934 if ((0 < test_pairing_failure) && (test_pairing_failure < SM_REASON_DHKEY_CHECK_FAILED)){ 2935 log_info("testing_support: respond with pairing failure %u", test_pairing_failure); 2936 err = test_pairing_failure; 2937 } 2938#endif 2939 if (err != 0){ | 2930 2931 // recover pairing request 2932 (void)memcpy(&setup->sm_m_preq, &connection->sm_m_preq, sizeof(sm_pairing_packet_t)); 2933 err = sm_stk_generation_init(connection); 2934 2935#ifdef ENABLE_TESTING_SUPPORT 2936 if ((0 < test_pairing_failure) && (test_pairing_failure < SM_REASON_DHKEY_CHECK_FAILED)){ 2937 log_info("testing_support: respond with pairing failure %u", test_pairing_failure); 2938 err = test_pairing_failure; 2939 } 2940#endif 2941 if (err != 0){ |
2942 // emit pairing started/failed sequence 2943 sm_pairing_started(connection); |
|
2940 sm_pairing_error(connection, err); 2941 sm_trigger_run(); 2942 break; 2943 } 2944 2945 sm_timeout_start(connection); 2946 2947 // generate random number first, if we need to show passkey, otherwise send response --- 26 unchanged lines hidden (view full) --- 2974 if (setup->sm_use_secure_connections){ 2975 connection->sm_engine_state = SM_SC_W4_PUBLIC_KEY_COMMAND; 2976 } else { 2977 connection->sm_engine_state = SM_RESPONDER_PH1_W4_PAIRING_CONFIRM; 2978 } 2979 2980 sm_send_connectionless(connection, (uint8_t*) &setup->sm_s_pres, sizeof(sm_pairing_packet_t)); 2981 sm_timeout_reset(connection); | 2944 sm_pairing_error(connection, err); 2945 sm_trigger_run(); 2946 break; 2947 } 2948 2949 sm_timeout_start(connection); 2950 2951 // generate random number first, if we need to show passkey, otherwise send response --- 26 unchanged lines hidden (view full) --- 2978 if (setup->sm_use_secure_connections){ 2979 connection->sm_engine_state = SM_SC_W4_PUBLIC_KEY_COMMAND; 2980 } else { 2981 connection->sm_engine_state = SM_RESPONDER_PH1_W4_PAIRING_CONFIRM; 2982 } 2983 2984 sm_send_connectionless(connection, (uint8_t*) &setup->sm_s_pres, sizeof(sm_pairing_packet_t)); 2985 sm_timeout_reset(connection); |
2986 2987 // notify after sending 2988 sm_pairing_started(connection); 2989 |
|
2982 // SC Numeric Comparison will trigger user response after public keys & nonces have been exchanged 2983 if (!setup->sm_use_secure_connections || (setup->sm_stk_generation_method == JUST_WORKS)){ 2984 sm_trigger_user_response(connection); 2985 } 2986 return; 2987#endif 2988 2989 case SM_PH2_SEND_PAIRING_RANDOM: { --- 2307 unchanged lines hidden --- | 2990 // SC Numeric Comparison will trigger user response after public keys & nonces have been exchanged 2991 if (!setup->sm_use_secure_connections || (setup->sm_stk_generation_method == JUST_WORKS)){ 2992 sm_trigger_user_response(connection); 2993 } 2994 return; 2995#endif 2996 2997 case SM_PH2_SEND_PAIRING_RANDOM: { --- 2307 unchanged lines hidden --- |