sm.c (1c34405f174d665bd436352e52b50c795c922c39) sm.c (db88441f671cf9b797d1a7638cc0e38d13db6ac0)
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

--- 192 unchanged lines hidden (view full) ---

201static uint8_t sm_slave_request_security;
202#endif
203
204#ifdef ENABLE_LE_SECURE_CONNECTIONS
205static bool sm_sc_only_mode;
206static uint8_t sm_sc_oob_random[16];
207static void (*sm_sc_oob_callback)(const uint8_t * confirm_value, const uint8_t * random_value);
208static sm_sc_oob_state_t sm_sc_oob_state;
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

--- 192 unchanged lines hidden (view full) ---

201static uint8_t sm_slave_request_security;
202#endif
203
204#ifdef ENABLE_LE_SECURE_CONNECTIONS
205static bool sm_sc_only_mode;
206static uint8_t sm_sc_oob_random[16];
207static void (*sm_sc_oob_callback)(const uint8_t * confirm_value, const uint8_t * random_value);
208static sm_sc_oob_state_t sm_sc_oob_state;
209#ifdef ENABLE_LE_SECURE_CONNECTIONS_DEBUG_KEY
210static bool sm_sc_debug_keys_enabled;
209#endif
211#endif
212#endif
210
211
212static bool sm_persistent_keys_random_active;
213static const btstack_tlv_t * sm_tlv_impl;
214static void * sm_tlv_context;
215
216// Security Manager Master Keys, please use sm_set_er(er) and sm_set_ir(ir) with your own 128 bit random values
217static sm_key_t sm_persistent_er;

--- 4741 unchanged lines hidden (view full) ---

4959
4960#ifdef ENABLE_LE_SECURE_CONNECTIONS
4961static void sm_ec_generated(void * arg){
4962 UNUSED(arg);
4963 ec_key_generation_state = EC_KEY_GENERATION_DONE;
4964 // trigger pairing if pending for ec key
4965 sm_trigger_run();
4966}
213
214
215static bool sm_persistent_keys_random_active;
216static const btstack_tlv_t * sm_tlv_impl;
217static void * sm_tlv_context;
218
219// Security Manager Master Keys, please use sm_set_er(er) and sm_set_ir(ir) with your own 128 bit random values
220static sm_key_t sm_persistent_er;

--- 4741 unchanged lines hidden (view full) ---

4962
4963#ifdef ENABLE_LE_SECURE_CONNECTIONS
4964static void sm_ec_generated(void * arg){
4965 UNUSED(arg);
4966 ec_key_generation_state = EC_KEY_GENERATION_DONE;
4967 // trigger pairing if pending for ec key
4968 sm_trigger_run();
4969}
4967static void sm_ec_generate_new_key(void){
4970static void sm_ec_generate_new_key(void) {
4968 log_info("sm: generate new ec key");
4971 log_info("sm: generate new ec key");
4969 ec_key_generation_state = EC_KEY_GENERATION_ACTIVE;
4970 btstack_crypto_ecc_p256_generate_key(&sm_crypto_ecc_p256_request, ec_q, &sm_ec_generated, NULL);
4972#ifdef ENABLE_LE_SECURE_CONNECTIONS_DEBUG_KEY
4973 // LE Secure Connections Debug Key
4974 const uint8_t debug_key_public[64] = {
4975 0x20, 0xb0, 0x03, 0xd2, 0xf2, 0x97, 0xbe, 0x2c, 0x5e, 0x2c, 0x83, 0xa7, 0xe9, 0xf9, 0xa5, 0xb9,
4976 0xef, 0xf4, 0x91, 0x11, 0xac, 0xf4, 0xfd, 0xdb, 0xcc, 0x03, 0x01, 0x48, 0x0e, 0x35, 0x9d, 0xe6,
4977 0xdc, 0x80, 0x9c, 0x49, 0x65, 0x2a, 0xeb, 0x6d, 0x63, 0x32, 0x9a, 0xbf, 0x5a, 0x52, 0x15, 0x5c,
4978 0x76, 0x63, 0x45, 0xc2, 0x8f, 0xed, 0x30, 0x24, 0x74, 0x1c, 0x8e, 0xd0, 0x15, 0x89, 0xd2, 0x8b
4979 };
4980 const uint8_t debug_key_private[32] = {
4981 0x3f, 0x49, 0xf6, 0xd4, 0xa3, 0xc5, 0x5f, 0x38, 0x74, 0xc9, 0xb3, 0xe3, 0xd2, 0x10, 0x3f, 0x50,
4982 0x4a, 0xff, 0x60, 0x7b, 0xeb, 0x40, 0xb7, 0x99, 0x58, 0x99, 0xb8, 0xa6, 0xcd, 0x3c, 0x1a, 0xbd
4983 };
4984 if (sm_sc_debug_keys_enabled) {
4985 memcpy(ec_q, debug_key_public, 64);
4986 btstack_crypto_ecc_p256_set_key(debug_key_public, debug_key_private);
4987 ec_key_generation_state = EC_KEY_GENERATION_DONE;
4988 } else
4989#endif
4990 {
4991 ec_key_generation_state = EC_KEY_GENERATION_ACTIVE;
4992 btstack_crypto_ecc_p256_generate_key(&sm_crypto_ecc_p256_request, ec_q, &sm_ec_generated, NULL);
4993 }
4971}
4972#endif
4973
4974#ifdef ENABLE_TESTING_SUPPORT
4975void sm_test_set_pairing_failure(int reason){
4976 test_pairing_failure = reason;
4977}
4978#endif

--- 67 unchanged lines hidden (view full) ---

5046 sm_state_reset();
5047
5048 sm_initialized = true;
5049}
5050
5051void sm_deinit(void){
5052 sm_initialized = false;
5053 btstack_run_loop_remove_timer(&sm_run_timer);
4994}
4995#endif
4996
4997#ifdef ENABLE_TESTING_SUPPORT
4998void sm_test_set_pairing_failure(int reason){
4999 test_pairing_failure = reason;
5000}
5001#endif

--- 67 unchanged lines hidden (view full) ---

5069 sm_state_reset();
5070
5071 sm_initialized = true;
5072}
5073
5074void sm_deinit(void){
5075 sm_initialized = false;
5076 btstack_run_loop_remove_timer(&sm_run_timer);
5077#if defined(ENABLE_LE_SECURE_CONNECTIONS) || defined (ENABLE_LE_SECURE_CONNECTION_DEBUG_KEY)
5078 sm_sc_debug_keys_enabled = false;
5079#endif
5054}
5055
5056void sm_use_fixed_passkey_in_display_role(uint32_t passkey){
5057 sm_fixed_passkey_in_display_role = passkey;
5058}
5059
5060void sm_allow_ltk_reconstruction_without_le_device_db_entry(int allow){
5061 sm_reconstruct_ltk_without_le_device_db_entry = allow != 0;

--- 407 unchanged lines hidden (view full) ---

5469#ifdef ENABLE_LE_SECURE_CONNECTIONS
5470 sm_sc_only_mode = enable;
5471#else
5472 // SC Only mode not possible without support for SC
5473 btstack_assert(enable == false);
5474#endif
5475}
5476
5080}
5081
5082void sm_use_fixed_passkey_in_display_role(uint32_t passkey){
5083 sm_fixed_passkey_in_display_role = passkey;
5084}
5085
5086void sm_allow_ltk_reconstruction_without_le_device_db_entry(int allow){
5087 sm_reconstruct_ltk_without_le_device_db_entry = allow != 0;

--- 407 unchanged lines hidden (view full) ---

5495#ifdef ENABLE_LE_SECURE_CONNECTIONS
5496 sm_sc_only_mode = enable;
5497#else
5498 // SC Only mode not possible without support for SC
5499 btstack_assert(enable == false);
5500#endif
5501}
5502
5503#if defined(ENABLE_LE_SECURE_CONNECTIONS) || defined (ENABLE_LE_SECURE_CONNECTION_DEBUG_KEY)
5504void sm_test_enable_secure_connections_debug_keys(void) {
5505 log_info("Enable LE Secure Connection Debug Keys for testing");
5506 sm_sc_debug_keys_enabled = true;
5507 // set debug key
5508 sm_ec_generate_new_key();
5509}
5510#endif
5511
5477const uint8_t * gap_get_persistent_irk(void){
5478 return sm_persistent_irk;
5479}
5480
5481void gap_delete_bonding(bd_addr_type_t address_type, bd_addr_t address){
5482 int index = sm_le_device_db_index_lookup(address_type, address);
5483 if (index >= 0){
5484 sm_remove_le_device_db_entry(index);
5485 }
5486}
5512const uint8_t * gap_get_persistent_irk(void){
5513 return sm_persistent_irk;
5514}
5515
5516void gap_delete_bonding(bd_addr_type_t address_type, bd_addr_t address){
5517 int index = sm_le_device_db_index_lookup(address_type, address);
5518 if (index >= 0){
5519 sm_remove_le_device_db_entry(index);
5520 }
5521}