aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/direct_bt/BTDevice.hpp6
-rw-r--r--src/direct_bt/BTDevice.cpp12
2 files changed, 13 insertions, 5 deletions
diff --git a/api/direct_bt/BTDevice.hpp b/api/direct_bt/BTDevice.hpp
index 50be88ff..c42a8b88 100644
--- a/api/direct_bt/BTDevice.hpp
+++ b/api/direct_bt/BTDevice.hpp
@@ -679,6 +679,9 @@ namespace direct_bt {
*/
HCIStatusCode disconnect(const HCIStatusCode reason=HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION ) noexcept;
+ /** Returns true if this device has completed SMP pairing or keys are set via uploadKeys() */
+ bool isPrePaired() const noexcept { return pairing_data.is_pre_paired; }
+
/**
* Returns the responder SMP passkey, ranging from [0..999999].
* <p>
@@ -737,6 +740,7 @@ namespace direct_bt {
* Must be called before connecting to this device, otherwise HCIStatusCode::CONNECTION_ALREADY_EXISTS will be returned.
*
* @return ::HCIStatusCode::SUCCESS if successful, otherwise the appropriate error code.
+ * @see isPrePaired()
* @see setLongTermKey()
* @see setIdentityResolvingKey()
* @see setSignatureResolvingKey()
@@ -927,7 +931,7 @@ namespace direct_bt {
* Method either changes both parameter for the upcoming connection or none at all.
* </p>
* @param[in] sec_level ::BTSecurityLevel to be applied.
- * @param[in] io_cap ::SMPIOCapability to be applied.
+ * @param[in] io_cap ::SMPIOCapability to be applied, defaults to ::SMPIOCapability::UNSET
* @see ::BTSecurityLevel
* @see ::SMPIOCapability
* @see getConnSecurityLevel()
diff --git a/src/direct_bt/BTDevice.cpp b/src/direct_bt/BTDevice.cpp
index 8524c507..8c0240f1 100644
--- a/src/direct_bt/BTDevice.cpp
+++ b/src/direct_bt/BTDevice.cpp
@@ -1603,10 +1603,10 @@ bool BTDevice::setSMPKeyBin(const SMPKeyBin& bin) noexcept {
const BTSecurityLevel applySecLevel = BTSecurityLevel::NONE == bin.getSecLevel() ?
BTSecurityLevel::NONE : BTSecurityLevel::ENC_ONLY;
- pairing_data.is_pre_paired = true;
- pairing_data.io_cap_user = SMPIOCapability::NO_INPUT_NO_OUTPUT;
- pairing_data.sec_level_user = applySecLevel;
- pairing_data.io_cap_auto = SMPIOCapability::UNSET; // disable auto
+ if( !setConnSecurity(applySecLevel, SMPIOCapability::NO_INPUT_NO_OUTPUT) ) {
+ DBG_PRINT("BTDevice::setSMPKeyBin: Setting security failed: Device Connected/ing: %s, %s", bin.toString().c_str(), toString().c_str());
+ return false;
+ }
}
pairing_data.use_sc = bin.uses_SC();
@@ -1690,6 +1690,7 @@ HCIStatusCode BTDevice::uploadKeys() noexcept {
if( BDAddressType::BDADDR_BREDR != addressAndType.type ) {
// Not supported
DBG_PRINT("BTDevice::uploadKeys: Upload LK for LE address not supported -> ignored: %s", toString().c_str());
+ pairing_data.is_pre_paired = true;
return HCIStatusCode::SUCCESS;
}
@@ -1706,6 +1707,9 @@ HCIStatusCode BTDevice::uploadKeys() noexcept {
DBG_PRINT("BTDevice::uploadKeys.LK[adapter slave]: %s", to_string(res).c_str());
}
}
+ if( HCIStatusCode::SUCCESS == res ) {
+ pairing_data.is_pre_paired = true;
+ }
return res;
} else if constexpr ( SMP_SUPPORTED_BY_OS ) {
return HCIStatusCode::NOT_SUPPORTED;