diff options
author | Sven Gothel <[email protected]> | 2021-01-18 19:09:57 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-01-18 19:09:57 +0100 |
commit | 0412bbb5d49ef9293742d3a40549e67ad6dfc666 (patch) | |
tree | 9a5b686241e43d653869422c608af044e91e670a /src/direct_bt | |
parent | a3471d7529fce91af8b96c888c314ed5a9d07061 (diff) |
DBTDevice: Avoid deadlock calling into processDeviceReady(..) within scope of locked mtx_pairing
Diffstat (limited to 'src/direct_bt')
-rw-r--r-- | src/direct_bt/DBTDevice.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp index b4a1d60e..d37a8318 100644 --- a/src/direct_bt/DBTDevice.cpp +++ b/src/direct_bt/DBTDevice.cpp @@ -437,11 +437,14 @@ void DBTDevice::notifyLEFeatures(std::shared_ptr<DBTDevice> sthis, const LEFeatu } void DBTDevice::processL2CAPSetup(std::shared_ptr<DBTDevice> sthis) { - const std::lock_guard<std::mutex> lock(mtx_pairing); // RAII-style acquire and relinquish via destructor - jau::sc_atomic_critical sync(sync_pairing); + bool callProcessDeviceReady = false; - DBG_PRINT("DBTDevice::processL2CAPSetup: Start %s", toString(false).c_str()); if( addressAndType.isLEAddress() && !l2cap_att.isOpen() ) { + const std::lock_guard<std::mutex> lock(mtx_pairing); // RAII-style acquire and relinquish via destructor + jau::sc_atomic_critical sync(sync_pairing); + + DBG_PRINT("DBTDevice::processL2CAPSetup: Start %s", toString(false).c_str()); + const BTSecurityLevel sec_level_user = pairing_data.sec_level_user; const SMPIOCapability io_cap_conn = pairing_data.ioCap_conn; BTSecurityLevel sec_level { BTSecurityLevel::UNSET }; @@ -483,8 +486,14 @@ void DBTDevice::processL2CAPSetup(std::shared_ptr<DBTDevice> sthis) { pairing_data.sec_level_conn = BTSecurityLevel::NONE; disconnect(HCIStatusCode::INTERNAL_FAILURE); } else if( !l2cap_enc ) { - processDeviceReady(sthis, jau::getCurrentMilliseconds()); + callProcessDeviceReady = true; } + } else { + DBG_PRINT("DBTDevice::processL2CAPSetup: Skipped (not LE) %s", toString(false).c_str()); + } + if( callProcessDeviceReady ) { + // call out of scope of locked mtx_pairing + processDeviceReady(sthis, jau::getCurrentMilliseconds()); } DBG_PRINT("DBTDevice::processL2CAPSetup: End %s", toString(false).c_str()); } |