diff options
author | Sven Gothel <[email protected]> | 2022-04-11 01:57:12 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-04-11 01:57:12 +0200 |
commit | c84303948cb43831d28f09c56919846a4d024372 (patch) | |
tree | be982e7b9939aef384a73b8dfc31ea56cd00cb49 /src/direct_bt/BTAdapter.cpp | |
parent | 9f935016c572f9b037374c80179f423794bef705 (diff) |
BTAdapter::mgmtEvDeviceConnectedHCI(): As slave/server: Only device->setConnSecurity() if no pre-paired key is in use
Diffstat (limited to 'src/direct_bt/BTAdapter.cpp')
-rw-r--r-- | src/direct_bt/BTAdapter.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/direct_bt/BTAdapter.cpp b/src/direct_bt/BTAdapter.cpp index 3e9ca36a..74f462a4 100644 --- a/src/direct_bt/BTAdapter.cpp +++ b/src/direct_bt/BTAdapter.cpp @@ -1833,15 +1833,18 @@ bool BTAdapter::mgmtEvDeviceConnectedHCI(const MgmtEvent& e) noexcept { new_connect = BTRole::Master == getRole() ? 3 : 4; slave_unpair = BTRole::Slave == getRole(); } + bool has_smp_key; if( BTRole::Slave == getRole() ) { device->l2cap_att = std::move(l2cap_att_); + has_smp_key = nullptr != findSMPKeyBin( device->getAddressAndType() ); // PERIPHERAL_ADAPTER_MANAGES_SMP_KEYS + } else { + has_smp_key = false; } if( slave_unpair ) { /** * Without unpair in SC mode (or key pre-pairing), the peripheral fails the DHKey Check. */ - const SMPKeyBinRef key = findSMPKeyBin( device->getAddressAndType() ); // PERIPHERAL_ADAPTER_MANAGES_SMP_KEYS - if( nullptr == key ) { + if( !has_smp_key ) { // No pre-pairing -> unpair HCIStatusCode res = mgmt.unpairDevice(dev_id, device->getAddressAndType(), false /* disconnect */); if( HCIStatusCode::SUCCESS != res && HCIStatusCode::NOT_PAIRED != res ) { @@ -1869,7 +1872,9 @@ bool BTAdapter::mgmtEvDeviceConnectedHCI(const MgmtEvent& e) noexcept { device->toString().c_str()); } - if( BTRole::Slave == getRole() ) { + if( BTRole::Slave == getRole() && !has_smp_key ) { + // Skipped if has_smp_key, + // where BTDevice::uploadKeys() -> BTDevice::setSMPKeyBin() was performed at disconnected tuning the security setup. device->setConnSecurity(sec_level_server, io_cap_server); } device->notifyConnected(device, event.getHCIHandle(), io_cap_conn); |