diff options
author | Sven Gothel <[email protected]> | 2022-01-13 05:35:58 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-01-13 05:35:58 +0100 |
commit | 48ff06cd7a4ebe0e22f82ac949624130f66dcdd1 (patch) | |
tree | 42c316243edb90fbeb634caa43af0dfcb8aa4f65 /src | |
parent | 3c73bd3a8c8bc3489d25a9eabd18ac2a08dc4501 (diff) |
BTDevice::setConnSecurity*(..): Consolidate write methods to setConnSecurity() and setConnSecurityAuto() only
Also revert change allowing BTDevice::setConnSecurity*(..) on connected devices, IF BTAdapter is server,
i.e. method must be called pre-connection notification (commit f4118b41672c17b2f0845ea9a23c87cfaa04cf39).
Diffstat (limited to 'src')
-rw-r--r-- | src/direct_bt/BTDevice.cpp | 82 |
1 files changed, 19 insertions, 63 deletions
diff --git a/src/direct_bt/BTDevice.cpp b/src/direct_bt/BTDevice.cpp index 7e8bc3ca..8c10b499 100644 --- a/src/direct_bt/BTDevice.cpp +++ b/src/direct_bt/BTDevice.cpp @@ -1650,63 +1650,18 @@ void BTDevice::setLinkKey(const SMPLinkKey& lk) noexcept { } } -bool BTDevice::setConnSecurityLevel(const BTSecurityLevel sec_level) noexcept { - if( BTSecurityLevel::UNSET == sec_level ) { - DBG_PRINT("DBTAdapter::setConnSecurityLevel: lvl %s, invalid value.", to_string(sec_level).c_str()); - return false; - } - - if( !isValid() || ( BTRole::Slave == getRole() && ( isConnected || allowDisconnect ) ) ) { - DBG_PRINT("BTDevice::setConnSecurityLevel: lvl %s failed, invalid state %s", - to_string(sec_level).c_str(), toString().c_str()); - return false; - } - jau::sc_atomic_critical sync(sync_data); - const bool res = true; - pairing_data.sec_level_user = sec_level; - pairing_data.ioCap_auto = SMPIOCapability::UNSET; // disable auto - - DBG_PRINT("BTDevice::setConnSecurityLevel: result %d: lvl %s, %s", res, - to_string(sec_level).c_str(), - toString().c_str()); - return res; -} - BTSecurityLevel BTDevice::getConnSecurityLevel() const noexcept { jau::sc_atomic_critical sync(sync_data); return pairing_data.sec_level_conn; } -bool BTDevice::setConnIOCapability(const SMPIOCapability io_cap) noexcept { - if( SMPIOCapability::UNSET == io_cap ) { - DBG_PRINT("BTDevice::setConnIOCapability: io %s, invalid value.", to_string(io_cap).c_str()); - return false; - } - - if( !isValid() || isConnected || allowDisconnect ) { - DBG_PRINT("BTDevice::setConnIOCapability: io %s failed, invalid state %s", - to_string(io_cap).c_str(), toString().c_str()); - return false; - } - jau::sc_atomic_critical sync(sync_data); - const bool res = true; - pairing_data.ioCap_user = io_cap; - pairing_data.ioCap_auto = SMPIOCapability::UNSET; // disable auto - - DBG_PRINT("BTDevice::setConnIOCapability: result %d: io %s, %s", res, - to_string(io_cap).c_str(), - toString().c_str()); - - return res; -} - SMPIOCapability BTDevice::getConnIOCapability() const noexcept { jau::sc_atomic_critical sync(sync_data); return pairing_data.ioCap_conn; } bool BTDevice::setConnSecurity(const BTSecurityLevel sec_level, const SMPIOCapability io_cap) noexcept { - if( !isValid() || ( BTRole::Slave == getRole() && ( isConnected || allowDisconnect ) ) ) { + if( !isValid() || isConnected || allowDisconnect ) { DBG_PRINT("BTDevice::setConnSecurity: lvl %s, io %s failed, invalid state %s", to_string(sec_level).c_str(), to_string(io_cap).c_str(), toString().c_str()); @@ -1714,32 +1669,33 @@ bool BTDevice::setConnSecurity(const BTSecurityLevel sec_level, const SMPIOCapab } jau::sc_atomic_critical sync(sync_data); const bool res = true; - pairing_data.ioCap_user = io_cap; - pairing_data.sec_level_user = sec_level; - pairing_data.ioCap_auto = SMPIOCapability::UNSET; // disable auto - - DBG_PRINT("BTDevice::setConnSecurity: result %d: lvl %s, io %s, %s", res, - to_string(sec_level).c_str(), - to_string(io_cap).c_str(), - toString().c_str()); - - return res; -} -bool BTDevice::setConnSecurityBest(const BTSecurityLevel sec_level, const SMPIOCapability io_cap) noexcept { if( BTSecurityLevel::UNSET < sec_level && SMPIOCapability::UNSET != io_cap ) { - return setConnSecurity(sec_level, io_cap); + pairing_data.sec_level_user = sec_level; + pairing_data.ioCap_user = io_cap; } else if( BTSecurityLevel::UNSET < sec_level ) { if( BTSecurityLevel::ENC_ONLY >= sec_level ) { - return setConnSecurity(sec_level, SMPIOCapability::NO_INPUT_NO_OUTPUT); + pairing_data.sec_level_user = sec_level; + pairing_data.ioCap_user = SMPIOCapability::NO_INPUT_NO_OUTPUT; } else { - return setConnSecurityLevel(sec_level); + pairing_data.sec_level_user = sec_level; + pairing_data.ioCap_user = SMPIOCapability::UNSET; } } else if( SMPIOCapability::UNSET != io_cap ) { - return setConnIOCapability(io_cap); + pairing_data.sec_level_user = BTSecurityLevel::UNSET; + pairing_data.ioCap_user = io_cap; } else { - return false; + pairing_data.sec_level_user = BTSecurityLevel::UNSET; + pairing_data.ioCap_user = SMPIOCapability::UNSET; } + pairing_data.ioCap_auto = SMPIOCapability::UNSET; // disable auto + + DBG_PRINT("BTDevice::setConnSecurity: result %d: lvl %s -> %s, io %s -> %s, %s", res, + to_string(sec_level).c_str(), to_string(pairing_data.sec_level_user).c_str(), + to_string(io_cap).c_str(), to_string(pairing_data.ioCap_user).c_str(), + toString().c_str()); + + return res; } bool BTDevice::setConnSecurityAuto(const SMPIOCapability iocap_auto) noexcept { |