diff --git a/CHANGELOG.md b/CHANGELOG.md index 3db5e0023..8c3ada719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - SM: Fix LE Secure Connection pairing in Central role - le_device_db_tlv: fix seq nr management +- SM: improve le_device_db lookup and storing of IRK ## Changes April 2018 diff --git a/src/ble/sm.c b/src/ble/sm.c index f1d56f0fc..3eacb0401 100644 --- a/src/ble/sm.c +++ b/src/ble/sm.c @@ -1204,14 +1204,20 @@ static void sm_key_distribution_handle_all_received(sm_connection_t * sm_conn){ for (i=0; i < le_device_db_max_count(); i++){ sm_key_t irk; bd_addr_t address; - int address_type; + int address_type = BD_ADDR_TYPE_UNKNOWN; le_device_db_info(i, &address_type, address, irk); - if (memcmp(irk, setup->sm_peer_irk, 16) == 0){ - log_info("sm: device found for IRK, updating"); - le_db_index = i; - break; - } + // check if valid entry retrieved + if (address_type == BD_ADDR_TYPE_UNKNOWN) continue; + // compare IRK + if (memcmp(irk, setup->sm_peer_irk, 16) != 0) continue; + + log_info("sm: device found for IRK, updating"); + le_db_index = i; + break; } + } else { + // assert IRK is set to zero + memset(setup->sm_peer_irk, 0, 16); } // if not found, lookup via public address if possible