Lines Matching refs:setup

388 static sm_setup_context_t * setup = &the_setup;  variable
522 setup->sm_tk[i] = 0; in sm_reset_tk()
659 …sizeof(event), SM_EVENT_PAIRING_STARTED, sm_conn->sm_handle, setup->sm_peer_addr_type, setup->sm_p… in sm_pairing_started()
670 …izeof(event), SM_EVENT_PAIRING_COMPLETE, sm_conn->sm_handle, setup->sm_peer_addr_type, setup->sm_p… in sm_pairing_complete()
700 btstack_run_loop_remove_timer(&setup->sm_timeout); in sm_timeout_start()
701 btstack_run_loop_set_timer_context(&setup->sm_timeout, sm_conn); in sm_timeout_start()
702 btstack_run_loop_set_timer_handler(&setup->sm_timeout, sm_timeout_handler); in sm_timeout_start()
703 btstack_run_loop_set_timer(&setup->sm_timeout, 30000); // 30 seconds sm timeout in sm_timeout_start()
704 btstack_run_loop_add_timer(&setup->sm_timeout); in sm_timeout_start()
707 btstack_run_loop_remove_timer(&setup->sm_timeout); in sm_timeout_stop()
851 setup->sm_stk_generation_method = JUST_WORKS; in sm_setup_tk()
854 setup->sm_use_secure_connections = ( sm_pairing_packet_get_auth_req(setup->sm_m_preq) in sm_setup_tk()
855 & sm_pairing_packet_get_auth_req(setup->sm_s_pres) in sm_setup_tk()
858 setup->sm_use_secure_connections = false; in sm_setup_tk()
860 log_info("Secure pairing: %u", setup->sm_use_secure_connections); in sm_setup_tk()
865 if (setup->sm_use_secure_connections){ in sm_setup_tk()
868 …se_oob = (sm_pairing_packet_get_oob_data_flag(setup->sm_m_preq) | sm_pairing_packet_get_oob_data_f… in sm_setup_tk()
872 …se_oob = (sm_pairing_packet_get_oob_data_flag(setup->sm_m_preq) & sm_pairing_packet_get_oob_data_f… in sm_setup_tk()
876 log_info_key("OOB", setup->sm_tk); in sm_setup_tk()
877 setup->sm_stk_generation_method = OOB; in sm_setup_tk()
884 if (((sm_pairing_packet_get_auth_req(setup->sm_m_preq) & SM_AUTHREQ_MITM_PROTECTION) == 0u) in sm_setup_tk()
885 … && ((sm_pairing_packet_get_auth_req(setup->sm_s_pres) & SM_AUTHREQ_MITM_PROTECTION) == 0u)){ in sm_setup_tk()
894 …ng_packet_get_io_capability(setup->sm_m_preq) > IO_CAPABILITY_KEYBOARD_DISPLAY) || (sm_pairing_pac… in sm_setup_tk()
905 if (setup->sm_use_secure_connections){ in sm_setup_tk()
909setup->sm_stk_generation_method = generation_method[sm_pairing_packet_get_io_capability(setup->sm_… in sm_setup_tk()
912 …sm_pairing_packet_get_io_capability(setup->sm_m_preq), sm_pairing_packet_get_io_capability(setup->… in sm_setup_tk()
932 setup->sm_key_distribution_received_set = 0; in sm_setup_key_distribution()
933 setup->sm_key_distribution_expected_set = sm_key_distribution_flags_for_set(keys_to_receive); in sm_setup_key_distribution()
934 setup->sm_key_distribution_send_set = sm_key_distribution_flags_for_set(keys_to_send); in sm_setup_key_distribution()
935 setup->sm_key_distribution_sent_set = 0; in sm_setup_key_distribution()
937 setup->sm_le_device_index = -1; in sm_setup_key_distribution()
1043 setup->sm_user_response = SM_USER_RESPONSE_PENDING; in sm_trigger_user_response_basic()
1046 event[11] = setup->sm_use_secure_connections ? 1 : 0; in sm_trigger_user_response_basic()
1052 uint32_t passkey = big_endian_read_32(setup->sm_tk, 12); in sm_trigger_user_response_passkey()
1055 event[11] = setup->sm_use_secure_connections ? 1 : 0; in sm_trigger_user_response_passkey()
1062 setup->sm_user_response = SM_USER_RESPONSE_IDLE; in sm_trigger_user_response()
1064 switch (setup->sm_stk_generation_method){ in sm_trigger_user_response()
1098 …on_all_received: received 0x%02x, expecting 0x%02x", setup->sm_key_distribution_received_set, setu… in sm_key_distribution_all_received()
1099 …return (setup->sm_key_distribution_expected_set & setup->sm_key_distribution_received_set) == setu… in sm_key_distribution_all_received()
1110 if (setup->sm_use_secure_connections){ in sm_done_for_handle()
1144 setup->sm_state_vars = 0; in sm_reset_setup()
1145 setup->sm_keypress_notification = 0; in sm_reset_setup()
1146 setup->sm_have_oob_data = 0; in sm_reset_setup()
1152 setup->sm_peer_addr_type = sm_conn->sm_peer_addr_type; in sm_init_setup()
1153 (void)memcpy(setup->sm_peer_address, sm_conn->sm_peer_address, 6); in sm_init_setup()
1157setup->sm_have_oob_data = (*sm_get_oob_data)(sm_conn->sm_peer_addr_type, sm_conn->sm_peer_address,… in sm_init_setup()
1162 memset(setup->sm_ra, 0, 16); in sm_init_setup()
1163 memset(setup->sm_rb, 0, 16); in sm_init_setup()
1164 if (setup->sm_have_oob_data && (sm_auth_req & SM_AUTHREQ_SECURE_CONNECTION)){ in sm_init_setup()
1167 setup->sm_have_oob_data = (*sm_get_sc_oob_data)( in sm_init_setup()
1170 setup->sm_peer_confirm, in sm_init_setup()
1171 setup->sm_ra); in sm_init_setup()
1173 setup->sm_have_oob_data = (*sm_get_sc_oob_data)( in sm_init_setup()
1176 setup->sm_peer_confirm, in sm_init_setup()
1177 setup->sm_rb); in sm_init_setup()
1180 setup->sm_have_oob_data = 0; in sm_init_setup()
1188 local_packet = &setup->sm_s_pres; in sm_init_setup()
1189 setup->sm_m_addr_type = sm_conn->sm_peer_addr_type; in sm_init_setup()
1190 setup->sm_s_addr_type = sm_conn->sm_own_addr_type; in sm_init_setup()
1191 (void)memcpy(setup->sm_m_address, sm_conn->sm_peer_address, 6); in sm_init_setup()
1192 (void)memcpy(setup->sm_s_address, sm_conn->sm_own_address, 6); in sm_init_setup()
1195 local_packet = &setup->sm_m_preq; in sm_init_setup()
1196 setup->sm_s_addr_type = sm_conn->sm_peer_addr_type; in sm_init_setup()
1197 setup->sm_m_addr_type = sm_conn->sm_own_addr_type; in sm_init_setup()
1198 (void)memcpy(setup->sm_s_address, sm_conn->sm_peer_address, 6); in sm_init_setup()
1199 (void)memcpy(setup->sm_m_address, sm_conn->sm_own_address, 6); in sm_init_setup()
1202 sm_pairing_packet_set_initiator_key_distribution(setup->sm_m_preq, key_distribution_flags); in sm_init_setup()
1203 sm_pairing_packet_set_responder_key_distribution(setup->sm_m_preq, key_distribution_flags); in sm_init_setup()
1226 sm_pairing_packet_set_oob_data_flag(*local_packet, setup->sm_have_oob_data); in sm_init_setup()
1238 remote_packet = &setup->sm_m_preq; in sm_stk_generation_init()
1239 keys_to_send = sm_pairing_packet_get_responder_key_distribution(setup->sm_m_preq); in sm_stk_generation_init()
1240 keys_to_receive = sm_pairing_packet_get_initiator_key_distribution(setup->sm_m_preq); in sm_stk_generation_init()
1243 remote_packet = &setup->sm_s_pres; in sm_stk_generation_init()
1244 keys_to_send = sm_pairing_packet_get_initiator_key_distribution(setup->sm_s_pres); in sm_stk_generation_init()
1245 keys_to_receive = sm_pairing_packet_get_responder_key_distribution(setup->sm_s_pres); in sm_stk_generation_init()
1260 log_info("SMP: generation method %u", setup->sm_stk_generation_method); in sm_stk_generation_init()
1267 if (sm_sc_only_mode && (setup->sm_use_secure_connections == false)){ in sm_stk_generation_init()
1273 if (setup->sm_use_secure_connections){ in sm_stk_generation_init()
1283 sm_conn->sm_connection_authenticated = (setup->sm_stk_generation_method == JUST_WORKS) ? 0 : 1; in sm_stk_generation_init()
1459 if ((setup->sm_key_distribution_received_set & SM_KEYDIST_FLAG_IDENTITY_INFORMATION) != 0u){ in sm_store_bonding_information()
1469 if (memcmp(address, setup->sm_peer_address, 6) != 0) continue; in sm_store_bonding_information()
1471 if (memcmp(irk, setup->sm_peer_irk, 16) != 0) continue; in sm_store_bonding_information()
1479 memset(setup->sm_peer_irk, 0, 16); in sm_store_bonding_information()
1483 …log_info("sm peer addr type %u, peer addres %s", setup->sm_peer_addr_type, bd_addr_to_str(setup->s… in sm_store_bonding_information()
1484 if ((le_db_index < 0) && (setup->sm_peer_addr_type == BD_ADDR_TYPE_LE_PUBLIC)){ in sm_store_bonding_information()
1493 …if ((address_type == BD_ADDR_TYPE_LE_PUBLIC) && (memcmp(address, setup->sm_peer_address, 6) == 0)){ in sm_store_bonding_information()
1504 …le_db_index = le_device_db_add(setup->sm_peer_addr_type, setup->sm_peer_address, setup->sm_peer_ir… in sm_store_bonding_information()
1519 …_client_index(SM_EVENT_IDENTITY_CREATED, sm_conn->sm_handle, setup->sm_peer_addr_type, setup->sm_p… in sm_store_bonding_information()
1525 setup->sm_le_device_index = le_db_index; in sm_store_bonding_information()
1526 if ((setup->sm_key_distribution_sent_set) & SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION){ in sm_store_bonding_information()
1528 le_device_db_local_csrk_set(le_db_index, setup->sm_local_csrk); in sm_store_bonding_information()
1533 if (setup->sm_key_distribution_received_set & SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION){ in sm_store_bonding_information()
1535 le_device_db_remote_csrk_set(le_db_index, setup->sm_peer_csrk); in sm_store_bonding_information()
1540 if (setup->sm_use_secure_connections){ in sm_store_bonding_information()
1544 …le_device_db_encryption_set(le_db_index, 0, zero_rand, setup->sm_ltk, sm_conn->sm_actual_encryptio… in sm_store_bonding_information()
1549 else if ( (setup->sm_key_distribution_received_set & SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION) in sm_store_bonding_information()
1550 && (setup->sm_key_distribution_received_set & SM_KEYDIST_FLAG_MASTER_IDENTIFICATION )){ in sm_store_bonding_information()
1552 …le_device_db_encryption_set(le_db_index, setup->sm_peer_ediv, setup->sm_peer_rand, setup->sm_peer_… in sm_store_bonding_information()
1592 if ((setup->sm_key_distribution_received_set & SM_KEYDIST_FLAG_IDENTITY_INFORMATION) != 0u){ in sm_key_distribution_validate_received()
1593 int index = sm_le_device_db_index_lookup(BD_ADDR_TYPE_LE_PUBLIC, setup->sm_peer_address); in sm_key_distribution_validate_received()
1597 if (memcmp(irk, setup->sm_peer_irk, 16) != 0){ in sm_key_distribution_validate_received()
1617 bool bonding_enabled = (sm_pairing_packet_get_auth_req(setup->sm_m_preq) in sm_key_distribution_handle_all_received()
1618 & sm_pairing_packet_get_auth_req(setup->sm_s_pres) in sm_key_distribution_handle_all_received()
1640 if (setup->sm_stk_generation_method == OOB){ in sm_sc_start_calculating_local_confirm()
1643 …btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_nonce, 16, &sm_handle_ra… in sm_sc_start_calculating_local_confirm()
1650 if (setup->sm_stk_generation_method == OOB){ in sm_sc_state_after_receiving_random()
1657 switch (setup->sm_stk_generation_method){ in sm_sc_state_after_receiving_random()
1668 if (setup->sm_passkey_bit < 20u) { in sm_sc_state_after_receiving_random()
1702 (void)memcpy(setup->sm_local_confirm, hash, 16); in sm_sc_cmac_done()
1707 if (0 != memcmp(hash, setup->sm_peer_confirm, 16)){ in sm_sc_cmac_done()
1712 if (setup->sm_stk_generation_method == OOB){ in sm_sc_cmac_done()
1720 big_endian_store_32(setup->sm_tk, 12, vab); in sm_sc_cmac_done()
1726 (void)memcpy(setup->sm_t, hash, 16); in sm_sc_cmac_done()
1730 (void)memcpy(setup->sm_mackey, hash, 16); in sm_sc_cmac_done()
1738 (void)memcpy(setup->sm_ltk, hash, 16); in sm_sc_cmac_done()
1739 (void)memcpy(setup->sm_local_ltk, hash, 16); in sm_sc_cmac_done()
1740 sm_truncate_key(setup->sm_ltk, sm_conn->sm_actual_encryption_key_size); in sm_sc_cmac_done()
1744 (void)memcpy(setup->sm_local_dhkey_check, hash, 16); in sm_sc_cmac_done()
1747 if ((setup->sm_state_vars & SM_STATE_VAR_DHKEY_COMMAND_RECEIVED) != 0u){ in sm_sc_cmac_done()
1757 if (0 != memcmp(hash, setup->sm_peer_dhkey_check, 16) ){ in sm_sc_cmac_done()
1771 (void)memcpy(setup->sm_t, hash, 16); in sm_sc_cmac_done()
1775 reverse_128(hash, setup->sm_t); in sm_sc_cmac_done()
1779 gap_store_link_key_for_bd_addr(setup->sm_peer_address, setup->sm_t, link_key_type); in sm_sc_cmac_done()
1789 (void)memcpy(setup->sm_t, hash, 16); in sm_sc_cmac_done()
1795 (void)memcpy(setup->sm_ltk, hash, 16); in sm_sc_cmac_done()
1796 sm_truncate_key(setup->sm_ltk, sm_conn->sm_actual_encryption_key_size); in sm_sc_cmac_done()
1797 …sm_conn->sm_connection_authenticated = setup->sm_link_key_type == AUTHENTICATED_COMBINATION_KEY_GE… in sm_sc_cmac_done()
1833 (void)memcpy(sm_cmac_sc_buffer, setup->sm_dhkey, message_len); in f5_calculate_salt()
1858 bd_addr_master[0] = setup->sm_m_addr_type; in f5_calculate_mackey()
1859 bd_addr_slave[0] = setup->sm_s_addr_type; in f5_calculate_mackey()
1860 (void)memcpy(&bd_addr_master[1], setup->sm_m_address, 6); in f5_calculate_mackey()
1861 (void)memcpy(&bd_addr_slave[1], setup->sm_s_address, 6); in f5_calculate_mackey()
1864 …f5_mackkey(sm_conn, setup->sm_t, setup->sm_peer_nonce, setup->sm_local_nonce, bd_addr_master, bd_a… in f5_calculate_mackey()
1867 …f5_mackkey(sm_conn, setup->sm_t, setup->sm_local_nonce, setup->sm_peer_nonce, bd_addr_master, bd_a… in f5_calculate_mackey()
1885 f5_ltk(sm_conn, setup->sm_t); in f5_calculate_ltk()
1929 g2_engine(sm_conn, setup->sm_peer_q, ec_q, setup->sm_peer_nonce, setup->sm_local_nonce);; in g2_calculate()
1932 g2_engine(sm_conn, ec_q, setup->sm_peer_q, setup->sm_local_nonce, setup->sm_peer_nonce); in g2_calculate()
1938 if (sm_passkey_entry(setup->sm_stk_generation_method)){ in sm_sc_calculate_local_confirm()
1940 uint32_t pk = big_endian_read_32(setup->sm_tk, 12); in sm_sc_calculate_local_confirm()
1941 z = 0x80u | ((pk >> setup->sm_passkey_bit) & 1u); in sm_sc_calculate_local_confirm()
1942 setup->sm_passkey_bit++; in sm_sc_calculate_local_confirm()
1944 f4_engine(sm_conn, ec_q, setup->sm_peer_q, setup->sm_local_nonce, z); in sm_sc_calculate_local_confirm()
1949 if (setup->sm_stk_generation_method == OOB){ in sm_sc_calculate_remote_confirm()
1951 f4_engine(sm_conn, setup->sm_peer_q, setup->sm_peer_q, setup->sm_ra, 0); in sm_sc_calculate_remote_confirm()
1953 f4_engine(sm_conn, setup->sm_peer_q, setup->sm_peer_q, setup->sm_rb, 0); in sm_sc_calculate_remote_confirm()
1959 if (sm_passkey_entry(setup->sm_stk_generation_method)){ in sm_sc_calculate_remote_confirm()
1961 uint32_t pk = big_endian_read_32(setup->sm_tk, 12); in sm_sc_calculate_remote_confirm()
1963 z = 0x80u | ((pk >> (setup->sm_passkey_bit-1u)) & 1u); in sm_sc_calculate_remote_confirm()
1965 f4_engine(sm_conn, setup->sm_peer_q, ec_q, setup->sm_peer_nonce, z); in sm_sc_calculate_remote_confirm()
1969 …log_info("sm_sc_prepare_dhkey_check, DHKEY calculated %u", (setup->sm_state_vars & SM_STATE_VAR_DH… in sm_sc_prepare_dhkey_check()
1971 if ((setup->sm_state_vars & SM_STATE_VAR_DHKEY_CALCULATED) != 0u){ in sm_sc_prepare_dhkey_check()
1984 if (sm_is_ff(setup->sm_dhkey, 32)){ in sm_sc_dhkey_calculated()
1991 log_info_hexdump(&setup->sm_dhkey[0], 32); in sm_sc_dhkey_calculated()
1992 setup->sm_state_vars |= SM_STATE_VAR_DHKEY_CALCULATED; in sm_sc_dhkey_calculated()
2003 bd_addr_master[0] = setup->sm_m_addr_type; in sm_sc_calculate_f6_for_dhkey_check()
2004 bd_addr_slave[0] = setup->sm_s_addr_type; in sm_sc_calculate_f6_for_dhkey_check()
2005 (void)memcpy(&bd_addr_master[1], setup->sm_m_address, 6); in sm_sc_calculate_f6_for_dhkey_check()
2006 (void)memcpy(&bd_addr_slave[1], setup->sm_s_address, 6); in sm_sc_calculate_f6_for_dhkey_check()
2008 iocap_a[0] = sm_pairing_packet_get_auth_req(setup->sm_m_preq); in sm_sc_calculate_f6_for_dhkey_check()
2009 iocap_a[1] = sm_pairing_packet_get_oob_data_flag(setup->sm_m_preq); in sm_sc_calculate_f6_for_dhkey_check()
2010 iocap_a[2] = sm_pairing_packet_get_io_capability(setup->sm_m_preq); in sm_sc_calculate_f6_for_dhkey_check()
2012 iocap_b[0] = sm_pairing_packet_get_auth_req(setup->sm_s_pres); in sm_sc_calculate_f6_for_dhkey_check()
2013 iocap_b[1] = sm_pairing_packet_get_oob_data_flag(setup->sm_s_pres); in sm_sc_calculate_f6_for_dhkey_check()
2014 iocap_b[2] = sm_pairing_packet_get_io_capability(setup->sm_s_pres); in sm_sc_calculate_f6_for_dhkey_check()
2017 …f6_setup(setup->sm_local_nonce, setup->sm_peer_nonce, setup->sm_ra, iocap_b, bd_addr_slave, bd_add… in sm_sc_calculate_f6_for_dhkey_check()
2018 f6_engine(sm_conn, setup->sm_mackey); in sm_sc_calculate_f6_for_dhkey_check()
2021 …f6_setup( setup->sm_local_nonce, setup->sm_peer_nonce, setup->sm_rb, iocap_a, bd_addr_master, bd_a… in sm_sc_calculate_f6_for_dhkey_check()
2022 f6_engine(sm_conn, setup->sm_mackey); in sm_sc_calculate_f6_for_dhkey_check()
2029 bd_addr_master[0] = setup->sm_m_addr_type; in sm_sc_calculate_f6_to_verify_dhkey_check()
2030 bd_addr_slave[0] = setup->sm_s_addr_type; in sm_sc_calculate_f6_to_verify_dhkey_check()
2031 (void)memcpy(&bd_addr_master[1], setup->sm_m_address, 6); in sm_sc_calculate_f6_to_verify_dhkey_check()
2032 (void)memcpy(&bd_addr_slave[1], setup->sm_s_address, 6); in sm_sc_calculate_f6_to_verify_dhkey_check()
2035 iocap_a[0] = sm_pairing_packet_get_auth_req(setup->sm_m_preq); in sm_sc_calculate_f6_to_verify_dhkey_check()
2036 iocap_a[1] = sm_pairing_packet_get_oob_data_flag(setup->sm_m_preq); in sm_sc_calculate_f6_to_verify_dhkey_check()
2037 iocap_a[2] = sm_pairing_packet_get_io_capability(setup->sm_m_preq); in sm_sc_calculate_f6_to_verify_dhkey_check()
2039 iocap_b[0] = sm_pairing_packet_get_auth_req(setup->sm_s_pres); in sm_sc_calculate_f6_to_verify_dhkey_check()
2040 iocap_b[1] = sm_pairing_packet_get_oob_data_flag(setup->sm_s_pres); in sm_sc_calculate_f6_to_verify_dhkey_check()
2041 iocap_b[2] = sm_pairing_packet_get_io_capability(setup->sm_s_pres); in sm_sc_calculate_f6_to_verify_dhkey_check()
2044 …f6_setup(setup->sm_peer_nonce, setup->sm_local_nonce, setup->sm_rb, iocap_a, bd_addr_master, bd_ad… in sm_sc_calculate_f6_to_verify_dhkey_check()
2045 f6_engine(sm_conn, setup->sm_mackey); in sm_sc_calculate_f6_to_verify_dhkey_check()
2048 …f6_setup(setup->sm_peer_nonce, setup->sm_local_nonce, setup->sm_ra, iocap_b, bd_addr_slave, bd_add… in sm_sc_calculate_f6_to_verify_dhkey_check()
2049 f6_engine(sm_conn, setup->sm_mackey); in sm_sc_calculate_f6_to_verify_dhkey_check()
2056 …btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_nonce, 16, &sm_handle_ra… in sm_sc_generate_nx_for_send_random()
2099 h6_engine(sm_conn, setup->sm_local_ltk, 0x746D7031); // "tmp1" in h6_calculate_ilk_from_le_ltk()
2103 h6_engine(sm_conn, setup->sm_link_key, 0x746D7032); // "tmp2" in h6_calculate_ilk_from_br_edr()
2107 h6_engine(sm_conn, setup->sm_t, 0x6c656272); // "lebr" in h6_calculate_br_edr_link_key()
2111 h6_engine(sm_conn, setup->sm_t, 0x62726C65); // "brle" in h6_calculate_le_ltk()
2116 h7_engine(sm_conn, salt, setup->sm_local_ltk); in h7_calculate_ilk_from_le_ltk()
2121 h7_engine(sm_conn, salt, setup->sm_link_key); in h7_calculate_ilk_from_br_edr()
2127 reverse_128(hci_connection->link_key, setup->sm_link_key); in sm_ctkd_fetch_br_edr_link_key()
2128 setup->sm_link_key_type = hci_connection->link_key_type; in sm_ctkd_fetch_br_edr_link_key()
2133 bool derive_ltk = (sm_pairing_packet_get_initiator_key_distribution(setup->sm_s_pres) & in sm_ctkd_start_from_br_edr()
2134 … sm_pairing_packet_get_responder_key_distribution(setup->sm_s_pres) & SM_KEYDIST_ENC_KEY) != 0; in sm_ctkd_start_from_br_edr()
2136 …bool use_h7 = (sm_pairing_packet_get_auth_req(setup->sm_m_preq) & sm_pairing_packet_get_auth_req(s… in sm_ctkd_start_from_br_edr()
2164 …ce_db_encryption_get(sm_connection->sm_le_db_index, &setup->sm_peer_ediv, setup->sm_peer_rand, set… in sm_load_security_info()
2176 (void)memcpy(setup->sm_local_rand, sm_connection->sm_local_rand, 8); in sm_start_calculating_ltk_from_ediv_and_rand()
2177 setup->sm_local_ediv = sm_connection->sm_local_ediv; in sm_start_calculating_ltk_from_ediv_and_rand()
2180 sm_connection->sm_actual_encryption_key_size = (setup->sm_local_rand[7u] & 0x0fu) + 1u; in sm_start_calculating_ltk_from_ediv_and_rand()
2182 sm_connection->sm_connection_authenticated = (setup->sm_local_rand[7u] & 0x10u) >> 4u; in sm_start_calculating_ltk_from_ediv_and_rand()
2458 uint8_t flags = setup->sm_keypress_notification & 0x1fu; in sm_run_send_keypress_notification()
2459 uint8_t num_actions = setup->sm_keypress_notification >> 5; in sm_run_send_keypress_notification()
2483 setup->sm_keypress_notification = (num_actions << 5) | flags; in sm_run_send_keypress_notification()
2496 if ((setup->sm_key_distribution_send_set & SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION) != 0u){ in sm_run_distribute_keys()
2497 setup->sm_key_distribution_send_set &= ~SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION; in sm_run_distribute_keys()
2498 setup->sm_key_distribution_sent_set |= SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION; in sm_run_distribute_keys()
2501 reverse_128(setup->sm_ltk, &buffer[1]); in sm_run_distribute_keys()
2506 if ((setup->sm_key_distribution_send_set & SM_KEYDIST_FLAG_MASTER_IDENTIFICATION) != 0u){ in sm_run_distribute_keys()
2507 setup->sm_key_distribution_send_set &= ~SM_KEYDIST_FLAG_MASTER_IDENTIFICATION; in sm_run_distribute_keys()
2508 setup->sm_key_distribution_sent_set |= SM_KEYDIST_FLAG_MASTER_IDENTIFICATION; in sm_run_distribute_keys()
2511 little_endian_store_16(buffer, 1, setup->sm_local_ediv); in sm_run_distribute_keys()
2512 reverse_64(setup->sm_local_rand, &buffer[3]); in sm_run_distribute_keys()
2517 if ((setup->sm_key_distribution_send_set & SM_KEYDIST_FLAG_IDENTITY_INFORMATION) != 0u){ in sm_run_distribute_keys()
2518 setup->sm_key_distribution_send_set &= ~SM_KEYDIST_FLAG_IDENTITY_INFORMATION; in sm_run_distribute_keys()
2519 setup->sm_key_distribution_sent_set |= SM_KEYDIST_FLAG_IDENTITY_INFORMATION; in sm_run_distribute_keys()
2527 … if ((setup->sm_key_distribution_send_set & SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION) != 0u){ in sm_run_distribute_keys()
2528 setup->sm_key_distribution_send_set &= ~SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION; in sm_run_distribute_keys()
2529 setup->sm_key_distribution_sent_set |= SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION; in sm_run_distribute_keys()
2554 if ((setup->sm_key_distribution_send_set & SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION) != 0u){ in sm_run_distribute_keys()
2555 setup->sm_key_distribution_send_set &= ~SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION; in sm_run_distribute_keys()
2556 setup->sm_key_distribution_sent_set |= SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION; in sm_run_distribute_keys()
2561 memset(setup->sm_local_csrk, 0xcc, 16); in sm_run_distribute_keys()
2565 if (setup->sm_le_device_index >= 0){ in sm_run_distribute_keys()
2567 … le_device_db_local_csrk_set(setup->sm_le_device_index, setup->sm_local_csrk); in sm_run_distribute_keys()
2568 le_device_db_local_counter_set(setup->sm_le_device_index, 0); in sm_run_distribute_keys()
2574 reverse_128(setup->sm_local_csrk, &buffer[1]); in sm_run_distribute_keys()
2586 if (setup->sm_use_secure_connections == 0) return false; in sm_ctkd_from_le()
2588 …nding_enabled = (sm_pairing_packet_get_auth_req(setup->sm_m_preq) & sm_pairing_packet_get_auth_req… in sm_ctkd_from_le()
2591 …dentity_address_info = ((setup->sm_key_distribution_received_set & SM_KEYDIST_FLAG_IDENTITY_ADDRES… in sm_ctkd_from_le()
2599 …bool have_link_key = gap_get_link_key_for_bd_addr(setup->sm_peer_address, link_key, &l… in sm_ctkd_from_le()
2637 …bool use_h7 = (sm_pairing_packet_get_auth_req(setup->sm_m_preq) & sm_pairing_packet_get_auth_req(s… in sm_key_distribution_complete_responder()
2648 …bool use_h7 = (sm_pairing_packet_get_auth_req(setup->sm_m_preq) & sm_pairing_packet_get_auth_req(s… in sm_key_distribution_complete_initiator()
2659 reverse_128(setup->sm_local_confirm, &buffer[1]); in sm_run_state_sc_send_confirmation()
2672 reverse_128(setup->sm_local_nonce, &buffer[1]); in sm_run_state_sc_send_pairing_random()
2673 log_info("stk method %u, bit num: %u", setup->sm_stk_generation_method, setup->sm_passkey_bit); in sm_run_state_sc_send_pairing_random()
2674 if (sm_passkey_entry(setup->sm_stk_generation_method) && (setup->sm_passkey_bit < 20u)){ in sm_run_state_sc_send_pairing_random()
2687 if (setup->sm_stk_generation_method == NUMERIC_COMPARISON){ in sm_run_state_sc_send_pairing_random()
2706 reverse_128(setup->sm_local_dhkey_check, &buffer[1]); in sm_run_state_sc_send_dhkey_check_command()
2737 switch (setup->sm_stk_generation_method){ in sm_run_state_sc_send_public_key_command()
2753 (void)memcpy(setup->sm_ra, setup->sm_tk, 16); in sm_run_state_sc_send_public_key_command()
2754 (void)memcpy(setup->sm_rb, setup->sm_tk, 16); in sm_run_state_sc_send_public_key_command()
2755 setup->sm_passkey_bit = 0; in sm_run_state_sc_send_public_key_command()
2866 if (setup->sm_keypress_notification != 0u){ in sm_run()
2934 sm_cache_ltk(connection, setup->sm_peer_ltk); in sm_run()
2937 reverse_128(setup->sm_peer_ltk, peer_ltk_flipped); in sm_run()
2939 log_info("sm: hci_le_start_encryption ediv 0x%04x", setup->sm_peer_ediv); in sm_run()
2940 uint32_t rand_high = big_endian_read_32(setup->sm_peer_rand, 0); in sm_run()
2941 uint32_t rand_low = big_endian_read_32(setup->sm_peer_rand, 4); in sm_run()
2942 …_cmd(&hci_le_start_encryption, connection->sm_handle,rand_low, rand_high, setup->sm_peer_ediv, pee… in sm_run()
2953 sm_pairing_packet_set_code(setup->sm_m_preq, SM_CODE_PAIRING_REQUEST); in sm_run()
2955 … sm_send_connectionless(connection, (uint8_t*) &setup->sm_m_preq, sizeof(sm_pairing_packet_t)); in sm_run()
2996 …if ((setup->sm_peer_ediv == 0u) && sm_is_null_random(setup->sm_peer_rand) && !sm_is_null_key(setup in sm_run()
2997 (void)memcpy(setup->sm_ltk, setup->sm_peer_ltk, 16); in sm_run()
3036 (void)memcpy(&setup->sm_m_preq, &connection->sm_m_preq, sizeof(sm_pairing_packet_t)); in sm_run()
3056 if (setup->sm_stk_generation_method == PK_INIT_INPUT){ in sm_run()
3064 sm_pairing_packet_set_code(setup->sm_s_pres,SM_CODE_PAIRING_RESPONSE); in sm_run()
3071 if (setup->sm_use_secure_connections){ in sm_run()
3076 …g_packet_set_initiator_key_distribution(setup->sm_s_pres, sm_pairing_packet_get_initiator_key_dist… in sm_run()
3077 …g_packet_set_responder_key_distribution(setup->sm_s_pres, sm_pairing_packet_get_responder_key_dist… in sm_run()
3080 …g_packet_get_responder_key_distribution(setup->sm_s_pres), sm_pairing_packet_get_initiator_key_dis… in sm_run()
3082 if (setup->sm_use_secure_connections){ in sm_run()
3088 … sm_send_connectionless(connection, (uint8_t*) &setup->sm_s_pres, sizeof(sm_pairing_packet_t)); in sm_run()
3095 … if (!setup->sm_use_secure_connections || (setup->sm_stk_generation_method == JUST_WORKS)){ in sm_run()
3104 reverse_128(setup->sm_local_random, &buffer[1]); in sm_run()
3119 …sm_c1_t1(setup->sm_local_random, (uint8_t*) &setup->sm_m_preq, (uint8_t*) &setup->sm_s_pres, setup in sm_run()
3122 …btstack_crypto_aes128_encrypt(&sm_crypto_aes128_request, setup->sm_tk, sm_aes128_plaintext, sm_aes… in sm_run()
3129 …sm_c1_t1(setup->sm_peer_random, (uint8_t*) &setup->sm_m_preq, (uint8_t*) &setup->sm_s_pres, setup-… in sm_run()
3132 …btstack_crypto_aes128_encrypt(&sm_crypto_aes128_request, setup->sm_tk, sm_aes128_plaintext, sm_aes… in sm_run()
3140 … sm_s1_r_prime(setup->sm_local_random, setup->sm_peer_random, sm_aes128_plaintext); in sm_run()
3142 … sm_s1_r_prime(setup->sm_peer_random, setup->sm_local_random, sm_aes128_plaintext); in sm_run()
3146 …tstack_crypto_aes128_encrypt(&sm_crypto_aes128_request, setup->sm_tk, sm_aes128_plaintext, setup->… in sm_run()
3158 (void)memcpy(&sm_aes128_plaintext[8], setup->sm_local_rand, 8); in sm_run()
3169 reverse_128(setup->sm_local_confirm, &buffer[1]); in sm_run()
3182 sm_cache_ltk(connection, setup->sm_ltk); in sm_run()
3184 reverse_128(setup->sm_ltk, stk_flipped); in sm_run()
3192 …(connection->sm_handle, connection->sm_peer_addr_type, connection->sm_peer_address, setup->sm_ltk); in sm_run()
3195 sm_cache_ltk(connection, setup->sm_ltk); in sm_run()
3197 reverse_128(setup->sm_ltk, ltk_flipped); in sm_run()
3206 log_info("LTK Request: recalculating with ediv 0x%04x", setup->sm_local_ediv); in sm_run()
3217 (void)memcpy(&sm_aes128_plaintext[8], setup->sm_local_rand, 8); in sm_run()
3228 sm_cache_ltk(connection, setup->sm_ltk); in sm_run()
3231 reverse_128(setup->sm_ltk, stk_flipped); in sm_run()
3240 if (setup->sm_key_distribution_send_set != 0){ in sm_run()
3245 if (setup->sm_key_distribution_send_set != 0){ in sm_run()
3269 setup->sm_peer_addr_type = connection->sm_peer_addr_type; in sm_run()
3270 setup->sm_m_addr_type = connection->sm_peer_addr_type; in sm_run()
3271 setup->sm_s_addr_type = connection->sm_own_addr_type; in sm_run()
3272 (void) memcpy(setup->sm_peer_address, connection->sm_peer_address, 6); in sm_run()
3273 (void) memcpy(setup->sm_m_address, connection->sm_peer_address, 6); in sm_run()
3274 (void) memcpy(setup->sm_s_address, connection->sm_own_address, 6); in sm_run()
3275 setup->sm_use_secure_connections = true; in sm_run()
3284 sm_pairing_packet_set_code(setup->sm_m_preq, SM_CODE_PAIRING_REQUEST); in sm_run()
3285 sm_pairing_packet_set_io_capability(setup->sm_m_preq, 0); in sm_run()
3286 sm_pairing_packet_set_oob_data_flag(setup->sm_m_preq, 0); in sm_run()
3287 sm_pairing_packet_set_auth_req(setup->sm_m_preq, SM_AUTHREQ_CT2); in sm_run()
3288 … sm_pairing_packet_set_max_encryption_key_size(setup->sm_m_preq, sm_max_encryption_key_size); in sm_run()
3289 … sm_pairing_packet_set_initiator_key_distribution(setup->sm_m_preq, key_distribution_flags); in sm_run()
3290 … sm_pairing_packet_set_responder_key_distribution(setup->sm_m_preq, key_distribution_flags); in sm_run()
3295 … sm_send_connectionless(connection, (uint8_t *) &setup->sm_m_preq, sizeof(sm_pairing_packet_t)); in sm_run()
3301 setup->sm_peer_addr_type = connection->sm_peer_addr_type; in sm_run()
3302 setup->sm_m_addr_type = connection->sm_peer_addr_type; in sm_run()
3303 setup->sm_s_addr_type = connection->sm_own_addr_type; in sm_run()
3304 (void) memcpy(setup->sm_peer_address, connection->sm_peer_address, 6); in sm_run()
3305 (void) memcpy(setup->sm_m_address, connection->sm_peer_address, 6); in sm_run()
3306 (void) memcpy(setup->sm_s_address, connection->sm_own_address, 6); in sm_run()
3307 setup->sm_use_secure_connections = true; in sm_run()
3309 … (void) memcpy(&setup->sm_m_preq, &connection->sm_m_preq, sizeof(sm_pairing_packet_t)); in sm_run()
3324 sm_pairing_packet_set_code(setup->sm_s_pres, SM_CODE_PAIRING_RESPONSE); in sm_run()
3325 sm_pairing_packet_set_io_capability(setup->sm_s_pres, 0); in sm_run()
3326 sm_pairing_packet_set_oob_data_flag(setup->sm_s_pres, 0); in sm_run()
3327 sm_pairing_packet_set_auth_req(setup->sm_s_pres, SM_AUTHREQ_CT2); in sm_run()
3328 …sm_pairing_packet_set_max_encryption_key_size(setup->sm_s_pres, connection->sm_actual_encryption_k… in sm_run()
3329 … sm_pairing_packet_set_initiator_key_distribution(setup->sm_s_pres, key_distribution_flags); in sm_run()
3330 … sm_pairing_packet_set_responder_key_distribution(setup->sm_s_pres, key_distribution_flags); in sm_run()
3339 … sm_send_connectionless(connection, (uint8_t *) &setup->sm_s_pres, sizeof(sm_pairing_packet_t)); in sm_run()
3343 if (setup->sm_key_distribution_send_set != 0) { in sm_run()
3348 if (setup->sm_key_distribution_send_set != 0){ in sm_run()
3406 sm_c1_t3(sm_aes128_ciphertext, setup->sm_m_address, setup->sm_s_address, setup->sm_c1_t3_value); in sm_handle_encryption_result_enc_a()
3408 …stack_crypto_aes128_encrypt(&sm_crypto_aes128_request, setup->sm_tk, setup->sm_c1_t3_value, setup-… in sm_handle_encryption_result_enc_a()
3418 log_info_key("c1!", setup->sm_local_confirm); in sm_handle_encryption_result_enc_b()
3431 sm_c1_t3(sm_aes128_ciphertext, setup->sm_m_address, setup->sm_s_address, setup->sm_c1_t3_value); in sm_handle_encryption_result_enc_c()
3433 …btstack_crypto_aes128_encrypt(&sm_crypto_aes128_request, setup->sm_tk, setup->sm_c1_t3_value, sm_a… in sm_handle_encryption_result_enc_c()
3444 if (memcmp(setup->sm_peer_confirm, sm_aes128_ciphertext, 16) != 0){ in sm_handle_encryption_result_enc_d()
3453 sm_s1_r_prime(setup->sm_peer_random, setup->sm_local_random, sm_aes128_plaintext); in sm_handle_encryption_result_enc_d()
3455 …tstack_crypto_aes128_encrypt(&sm_crypto_aes128_request, setup->sm_tk, sm_aes128_plaintext, setup->… in sm_handle_encryption_result_enc_d()
3466 sm_truncate_key(setup->sm_ltk, connection->sm_actual_encryption_key_size); in sm_handle_encryption_result_enc_stk()
3467 log_info_key("stk", setup->sm_ltk); in sm_handle_encryption_result_enc_stk()
3484 setup->sm_local_y = big_endian_read_16(sm_aes128_ciphertext, 14); in sm_handle_encryption_result_enc_ph3_y()
3485 log_info_hex16("y", setup->sm_local_y); in sm_handle_encryption_result_enc_ph3_y()
3487 setup->sm_local_ediv = setup->sm_local_y ^ setup->sm_local_div; in sm_handle_encryption_result_enc_ph3_y()
3488 log_info_hex16("ediv", setup->sm_local_ediv); in sm_handle_encryption_result_enc_ph3_y()
3491 sm_d1_d_prime(setup->sm_local_div, 0, sm_aes128_plaintext); in sm_handle_encryption_result_enc_ph3_y()
3493 …encrypt(&sm_crypto_aes128_request, sm_persistent_er, sm_aes128_plaintext, setup->sm_ltk, sm_handle… in sm_handle_encryption_result_enc_ph3_y()
3505 setup->sm_local_y = big_endian_read_16(sm_aes128_ciphertext, 14); in sm_handle_encryption_result_enc_ph4_y()
3506 log_info_hex16("y", setup->sm_local_y); in sm_handle_encryption_result_enc_ph4_y()
3509 setup->sm_local_div = setup->sm_local_y ^ setup->sm_local_ediv; in sm_handle_encryption_result_enc_ph4_y()
3510 log_info_hex16("ediv", setup->sm_local_ediv); in sm_handle_encryption_result_enc_ph4_y()
3513 sm_d1_d_prime(setup->sm_local_div, 0, sm_aes128_plaintext); in sm_handle_encryption_result_enc_ph4_y()
3515 …encrypt(&sm_crypto_aes128_request, sm_persistent_er, sm_aes128_plaintext, setup->sm_ltk, sm_handle… in sm_handle_encryption_result_enc_ph4_y()
3527 log_info_key("ltk", setup->sm_ltk); in sm_handle_encryption_result_enc_ph3_ltk()
3529 sm_d1_d_prime(setup->sm_local_div, 1, sm_aes128_plaintext); in sm_handle_encryption_result_enc_ph3_ltk()
3531 …encrypt(&sm_crypto_aes128_request, sm_persistent_er, sm_aes128_plaintext, setup->sm_local_csrk, sm… in sm_handle_encryption_result_enc_ph3_ltk()
3542 log_info_key("csrk", setup->sm_local_csrk); in sm_handle_encryption_result_enc_csrk()
3543 if (setup->sm_key_distribution_send_set != 0u){ in sm_handle_encryption_result_enc_csrk()
3570 sm_truncate_key(setup->sm_ltk, connection->sm_actual_encryption_key_size); in sm_handle_encryption_result_enc_ph4_ltk()
3571 log_info_key("ltk", setup->sm_ltk); in sm_handle_encryption_result_enc_ph4_ltk()
3692 big_endian_store_32(setup->sm_tk, 12, tk); in sm_handle_random_result_ph2_tk()
3696 if (setup->sm_use_secure_connections){ in sm_handle_random_result_ph2_tk()
3702 if (setup->sm_user_response == SM_USER_RESPONSE_IDLE){ in sm_handle_random_result_ph2_tk()
3703 …btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_random, 16, &sm_handle_r… in sm_handle_random_result_ph2_tk()
3716 setup->sm_local_div = big_endian_read_16(sm_random_data, 0); in sm_handle_random_result_ph3_div()
3717 log_info_hex16("div", setup->sm_local_div); in sm_handle_random_result_ph3_div()
3727 reverse_64(sm_random_data, setup->sm_local_rand); in sm_handle_random_result_ph3_random()
3729setup->sm_local_rand[7u] = (setup->sm_local_rand[7u] & 0xf0u) + (connection->sm_actual_encryption_… in sm_handle_random_result_ph3_random()
3731setup->sm_local_rand[7u] = (setup->sm_local_rand[7u] & 0xefu) + (connection->sm_connection_authent… in sm_handle_random_result_ph3_random()
4133 sm_conn->sm_connection_sc = setup->sm_use_secure_connections; in sm_event_packet_handler()
4183 sm_conn->sm_connection_sc = setup->sm_use_secure_connections; in sm_event_packet_handler()
4316 switch (setup->sm_stk_generation_method){ in sm_validate_stk_generation_method()
4412 reverse_256(&packet[01], &setup->sm_peer_q[0]); in sm_pdu_handler_pairing_public_key()
4413 reverse_256(&packet[33], &setup->sm_peer_q[32]); in sm_pdu_handler_pairing_public_key()
4416 if (memcmp(&setup->sm_peer_q, ec_q, 64) == 0){ in sm_pdu_handler_pairing_public_key()
4423 int err = btstack_crypto_ecc_p256_validate_public_key(setup->sm_peer_q); in sm_pdu_handler_pairing_public_key()
4431 …btstack_crypto_ecc_p256_calculate_dhkey(&sm_crypto_ecc_p256_request, setup->sm_peer_q, setup->sm_d… in sm_pdu_handler_pairing_public_key()
4433 log_info("public key received, generation method %u", setup->sm_stk_generation_method); in sm_pdu_handler_pairing_public_key()
4441 switch (setup->sm_stk_generation_method){ in sm_pdu_handler_pairing_public_key()
4451 if (setup->sm_user_response != SM_USER_RESPONSE_PASSKEY){ in sm_pdu_handler_pairing_public_key()
4458 if (setup->sm_have_oob_data){ in sm_pdu_handler_pairing_public_key()
4516 (void)memcpy(&setup->sm_s_pres, packet, in sm_pdu_handler()
4520 … max_encryption_key_size = sm_pairing_packet_get_max_encryption_key_size(setup->sm_s_pres); in sm_pdu_handler()
4541 if (setup->sm_stk_generation_method == PK_RESP_INPUT){ in sm_pdu_handler()
4547 if (setup->sm_use_secure_connections){ in sm_pdu_handler()
4549 if (setup->sm_stk_generation_method == JUST_WORKS){ in sm_pdu_handler()
4552 if (setup->sm_user_response == SM_USER_RESPONSE_IDLE){ in sm_pdu_handler()
4564 if (setup->sm_user_response == SM_USER_RESPONSE_IDLE){ in sm_pdu_handler()
4565 …btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_random, 16, &sm_handle_r… in sm_pdu_handler()
4576 reverse_128(&packet[1], setup->sm_peer_confirm); in sm_pdu_handler()
4579 if (memcmp(setup->sm_local_confirm, setup->sm_peer_confirm, 16) == 0){ in sm_pdu_handler()
4587 memset(setup->sm_peer_confirm, 0, 16); in sm_pdu_handler()
4600 reverse_128(&packet[1], setup->sm_peer_random); in sm_pdu_handler()
4661 reverse_128(&packet[1], setup->sm_peer_confirm); in sm_pdu_handler()
4666 memset(setup->sm_peer_confirm, 0, 16); in sm_pdu_handler()
4671 if (sm_passkey_used(setup->sm_stk_generation_method)){ in sm_pdu_handler()
4672 if (setup->sm_user_response != SM_USER_RESPONSE_PASSKEY){ in sm_pdu_handler()
4681 if (sm_just_works_or_numeric_comparison(setup->sm_stk_generation_method)){ in sm_pdu_handler()
4682 …btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_nonce, 16, &sm_handle_ra… in sm_pdu_handler()
4696 reverse_128(&packet[1], setup->sm_peer_nonce); in sm_pdu_handler()
4701 …IS_RESPONDER(sm_conn->sm_role), sm_just_works_or_numeric_comparison(setup->sm_stk_generation_metho… in sm_pdu_handler()
4702 …sm_passkey_used(setup->sm_stk_generation_method), sm_passkey_entry(setup->sm_stk_generation_method… in sm_pdu_handler()
4703 …if ( (!IS_RESPONDER(sm_conn->sm_role) && sm_just_works_or_numeric_comparison(setup->sm_stk_generat… in sm_pdu_handler()
4704 || (sm_passkey_entry(setup->sm_stk_generation_method)) ) { in sm_pdu_handler()
4710 if (setup->sm_stk_generation_method == OOB){ in sm_pdu_handler()
4715 if (sm_pairing_packet_get_oob_data_flag(setup->sm_m_preq) == 0u) { in sm_pdu_handler()
4717 memset(setup->sm_rb, 0, 16); in sm_pdu_handler()
4719 (void) memcpy(setup->sm_rb, sm_sc_oob_random, 16); in sm_pdu_handler()
4721 log_info_hexdump(setup->sm_rb, 16); in sm_pdu_handler()
4724 if (sm_pairing_packet_get_oob_data_flag(setup->sm_s_pres) == 0u){ in sm_pdu_handler()
4726 memset(setup->sm_ra, 0, 16); in sm_pdu_handler()
4728 (void)memcpy(setup->sm_ra, sm_sc_oob_random, 16); in sm_pdu_handler()
4730 log_info_hexdump(setup->sm_ra, 16); in sm_pdu_handler()
4735 if (setup->sm_have_oob_data){ in sm_pdu_handler()
4772 setup->sm_state_vars |= SM_STATE_VAR_DHKEY_COMMAND_RECEIVED; in sm_pdu_handler()
4773 reverse_128(&packet[01], setup->sm_peer_dhkey_check); in sm_pdu_handler()
4790 reverse_128(&packet[1], setup->sm_peer_confirm); in sm_pdu_handler()
4795 memset(setup->sm_peer_confirm, 0, 16); in sm_pdu_handler()
4799 if (setup->sm_stk_generation_method == PK_INIT_INPUT){ in sm_pdu_handler()
4804 if (setup->sm_user_response == SM_USER_RESPONSE_DECLINE){ in sm_pdu_handler()
4810 if (setup->sm_user_response == SM_USER_RESPONSE_PENDING){ in sm_pdu_handler()
4816 …btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_random, 16, &sm_handle_r… in sm_pdu_handler()
4826 reverse_128(&packet[1], setup->sm_peer_random); in sm_pdu_handler()
4835setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION; in sm_pdu_handler()
4836 reverse_128(&packet[1], setup->sm_peer_ltk); in sm_pdu_handler()
4840setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_MASTER_IDENTIFICATION; in sm_pdu_handler()
4841 setup->sm_peer_ediv = little_endian_read_16(packet, 1); in sm_pdu_handler()
4842 reverse_64(&packet[3], setup->sm_peer_rand); in sm_pdu_handler()
4846 setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_IDENTITY_INFORMATION; in sm_pdu_handler()
4847 reverse_128(&packet[1], setup->sm_peer_irk); in sm_pdu_handler()
4851setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION; in sm_pdu_handler()
4852 setup->sm_peer_addr_type = packet[1]; in sm_pdu_handler()
4853 reverse_bd_addr(&packet[2], setup->sm_peer_address); in sm_pdu_handler()
4857setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION; in sm_pdu_handler()
4858 reverse_128(&packet[1], setup->sm_peer_csrk); in sm_pdu_handler()
4873 if (setup->sm_use_secure_connections){ in sm_pdu_handler()
4901 (void)memcpy(&setup->sm_s_pres, packet, sizeof(sm_pairing_packet_t)); in sm_pdu_handler()
4904 … max_encryption_key_size = sm_pairing_packet_get_max_encryption_key_size(setup->sm_s_pres); in sm_pdu_handler()
4920 …sm_setup_key_distribution(sm_pairing_packet_get_initiator_key_distribution(setup->sm_s_pres) & ~SM… in sm_pdu_handler()
4921 … sm_pairing_packet_get_responder_key_distribution(setup->sm_s_pres) & ~SM_KEYDIST_ENC_KEY); in sm_pdu_handler()
4967 setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_IDENTITY_INFORMATION; in sm_pdu_handler()
4968 reverse_128(&packet[1], setup->sm_peer_irk); in sm_pdu_handler()
4971setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION; in sm_pdu_handler()
4972 setup->sm_peer_addr_type = packet[1]; in sm_pdu_handler()
4973 reverse_bd_addr(&packet[2], setup->sm_peer_address); in sm_pdu_handler()
4976setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION; in sm_pdu_handler()
4977 reverse_128(&packet[1], setup->sm_peer_csrk); in sm_pdu_handler()
5370 setup->sm_user_response = SM_USER_RESPONSE_DECLINE; in sm_bonding_decline()
5379 switch (setup->sm_stk_generation_method){ in sm_bonding_decline()
5406 setup->sm_user_response = SM_USER_RESPONSE_CONFIRM; in sm_just_works_confirm()
5408 if (setup->sm_use_secure_connections){ in sm_just_works_confirm()
5411 …btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_random, 16, &sm_handle_r… in sm_just_works_confirm()
5433 big_endian_store_32(setup->sm_tk, 12, passkey); in sm_passkey_input()
5434 setup->sm_user_response = SM_USER_RESPONSE_PASSKEY; in sm_passkey_input()
5436 …btstack_crypto_random_generate(&sm_crypto_random_request, setup->sm_local_random, 16, &sm_handle_r… in sm_passkey_input()
5439 (void)memcpy(setup->sm_ra, setup->sm_tk, 16); in sm_passkey_input()
5440 (void)memcpy(setup->sm_rb, setup->sm_tk, 16); in sm_passkey_input()
5452 uint8_t num_actions = setup->sm_keypress_notification >> 5; in sm_keypress_notification()
5453 uint8_t flags = setup->sm_keypress_notification & 0x1fu; in sm_keypress_notification()
5492 setup->sm_keypress_notification = (num_actions << 5) | flags; in sm_keypress_notification()