aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2022-01-13 05:35:58 +0100
committerSven Gothel <[email protected]>2022-01-13 05:35:58 +0100
commit48ff06cd7a4ebe0e22f82ac949624130f66dcdd1 (patch)
tree42c316243edb90fbeb634caa43af0dfcb8aa4f65
parent3c73bd3a8c8bc3489d25a9eabd18ac2a08dc4501 (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).
-rw-r--r--api/direct_bt/BTDevice.hpp94
-rw-r--r--examples/dbt_scanner10.cpp2
-rw-r--r--examples/dbt_test_gattcharlifecycle01.cpp2
-rw-r--r--examples/java/DBTScanner10.java2
-rw-r--r--java/jau/direct_bt/DBTDevice.java29
-rw-r--r--java/jni/direct_bt/DBTDevice.cxx52
-rw-r--r--java/org/direct_bt/BTDevice.java93
-rw-r--r--src/direct_bt/BTDevice.cpp82
8 files changed, 61 insertions, 295 deletions
diff --git a/api/direct_bt/BTDevice.hpp b/api/direct_bt/BTDevice.hpp
index da07b32b..aaba8bdc 100644
--- a/api/direct_bt/BTDevice.hpp
+++ b/api/direct_bt/BTDevice.hpp
@@ -791,114 +791,46 @@ namespace direct_bt {
HCIStatusCode unpair() noexcept;
/**
- * Set the ::BTSecurityLevel used to connect to this device on the upcoming connection.
- * <p>
- * Method returns false if ::BTSecurityLevel::UNSET has been given,
- * operation fails, this device has already being connected,
- * or BTDevice::connectLE() or BTDevice::connectBREDR() has been issued already.
- * </p>
- * <p>
- * To ensure a consistent authentication setup,
- * it is advised to set ::SMPIOCapability::NO_INPUT_NO_OUTPUT for sec_level <= ::BTSecurityLevel::ENC_ONLY
- * using setConnSecurity() as well as an IO capable ::SMPIOCapability value
- * for ::BTSecurityLevel::ENC_AUTH or ::BTSecurityLevel::ENC_AUTH_FIPS.<br>
- * You may like to consider using setConnSecurityBest().
- * </p>
- * @param sec_level ::BTSecurityLevel to be applied, ::BTSecurityLevel::UNSET will be ignored and method fails.
- * @see ::BTSecurityLevel
- * @see ::SMPIOCapability
- * @see getConnSecurityLevel()
- * @see setConnIOCapability()
- * @see getConnIOCapability()
- * @see setConnSecurity()
- * @see setConnSecurityBest()
- */
- bool setConnSecurityLevel(const BTSecurityLevel sec_level) noexcept;
-
- /**
* Return the ::BTSecurityLevel, determined when the connection is established.
* @see ::BTSecurityLevel
* @see ::SMPIOCapability
- * @see setConnSecurityLevel()
- * @see setConnIOCapability()
* @see getConnIOCapability()
* @see setConnSecurity()
- * @see setConnSecurityBest()
+ * @see setConnSecurityAuto()
*/
BTSecurityLevel getConnSecurityLevel() const noexcept;
/**
- * Sets the given ::SMPIOCapability used to connect to this device on the upcoming connection.
- * <p>
- * Method returns false if ::SMPIOCapability::UNSET has been given,
- * operation fails, this device has already being connected,
- * or BTDevice::connectLE() or BTDevice::connectBREDR() has been issued already.
- * </p>
- * @param[in] io_cap ::SMPIOCapability to be applied, ::SMPIOCapability::UNSET will be ignored and method fails.
- * @see ::BTSecurityLevel
- * @see ::SMPIOCapability
- * @see setConnSecurityLevel()
- * @see getConnSecurityLevel()
- * @see getConnIOCapability()
- * @see setConnSecurity()
- * @see setConnSecurityBest()
- */
- bool setConnIOCapability(const SMPIOCapability io_cap) noexcept;
-
- /**
* Return the set ::SMPIOCapability value, determined when the connection is established.
* @see ::BTSecurityLevel
* @see ::SMPIOCapability
- * @see setConnSecurityLevel()
* @see getConnSecurityLevel()
- * @see setConnIOCapability()
* @see setConnSecurity()
- * @see setConnSecurityBest()
+ * @see setConnSecurityAuto()
*/
SMPIOCapability getConnIOCapability() const noexcept;
/**
* Sets the given ::BTSecurityLevel and ::SMPIOCapability used to connect to this device on the upcoming connection.
- * <p>
- * Method returns false if this device has already being connected,
- * or BTDevice::connectLE() or BTDevice::connectBREDR() has been issued already.
- * </p>
- * <p>
- * 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.
- * @see ::BTSecurityLevel
- * @see ::SMPIOCapability
- * @see setConnSecurityLevel()
- * @see getConnSecurityLevel()
- * @see setConnIOCapability()
- * @see getConnIOCapability()
- * @see setConnSecurityBest()
- */
- bool setConnSecurity(const BTSecurityLevel sec_level, const SMPIOCapability io_cap) noexcept;
-
- /**
- * Convenience method to determine the best practice ::BTSecurityLevel and ::SMPIOCapability
- * based on the given arguments, used to connect to this device on the upcoming connection.
+ *
+ * Implementation using following pseudo-code, validating the user settings:
* <pre>
* if( BTSecurityLevel::UNSET < sec_level && SMPIOCapability::UNSET != io_cap ) {
- * return setConnSecurity(sec_level, io_cap);
+ * USING: sec_level, io_cap
* } else if( BTSecurityLevel::UNSET < sec_level ) {
* if( BTSecurityLevel::ENC_ONLY >= sec_level ) {
- * return setConnSecurity(sec_level, SMPIOCapability::NO_INPUT_NO_OUTPUT);
+ * USING: sec_level, SMPIOCapability::NO_INPUT_NO_OUTPUT
* } else {
- * return setConnSecurityLevel(sec_level);
+ * USING: sec_level, SMPIOCapability::UNSET
* }
* } else if( SMPIOCapability::UNSET != io_cap ) {
- * return setConnIOCapability(io_cap);
+ * USING BTSecurityLevel::UNSET, io_cap
* } else {
- * return false;
+ * USING BTSecurityLevel::UNSET, SMPIOCapability::UNSET
* }
* </pre>
* <p>
- * Method returns false if ::BTSecurityLevel::UNSET and ::SMPIOCapability::UNSET has been given,
- * operation fails, this device has already being connected,
+ * Method returns false if this device has already being connected,
* or BTDevice::connectLE() or BTDevice::connectBREDR() has been issued already.
* </p>
* <p>
@@ -908,14 +840,11 @@ namespace direct_bt {
* @param[in] io_cap ::SMPIOCapability to be applied.
* @see ::BTSecurityLevel
* @see ::SMPIOCapability
- * @see setConnSecurityLevel()
* @see getConnSecurityLevel()
- * @see setConnIOCapability()
* @see getConnIOCapability()
- * @see setConnSecurityBest()
* @see setConnSecurityAuto()
*/
- bool setConnSecurityBest(const BTSecurityLevel sec_level, const SMPIOCapability io_cap) noexcept;
+ bool setConnSecurity(const BTSecurityLevel sec_level, const SMPIOCapability io_cap=SMPIOCapability::UNSET) noexcept;
/**
* Set automatic security negotiation of BTSecurityLevel and SMPIOCapability pairing mode.
@@ -944,6 +873,7 @@ namespace direct_bt {
* @see isConnSecurityAutoEnabled()
* @see ::BTSecurityLevel
* @see ::SMPIOCapability
+ * @see setConnSecurity()
*/
bool setConnSecurityAuto(const SMPIOCapability iocap_auto) noexcept;
diff --git a/examples/dbt_scanner10.cpp b/examples/dbt_scanner10.cpp
index 6c1597a1..d70c7afa 100644
--- a/examples/dbt_scanner10.cpp
+++ b/examples/dbt_scanner10.cpp
@@ -384,7 +384,7 @@ static void connectDiscoveredDevice(BTDeviceRef device) {
bool r = device->setConnSecurityAuto( sec->getSecurityAutoIOCap() );
fprintf_td(stderr, "****** Connecting Device: Using SecurityDetail.SEC AUTO %s, set OK %d\n", sec->toString().c_str(), r);
} else if( sec->isSecLevelOrIOCapSet() ) {
- bool r = device->setConnSecurityBest( sec->getSecLevel(), sec->getIOCap() );
+ bool r = device->setConnSecurity( sec->getSecLevel(), sec->getIOCap() );
fprintf_td(stderr, "****** Connecting Device: Using SecurityDetail.Level+IOCap %s, set OK %d\n", sec->toString().c_str(), r);
} else {
bool r = device->setConnSecurityAuto( SMPIOCapability::KEYBOARD_ONLY );
diff --git a/examples/dbt_test_gattcharlifecycle01.cpp b/examples/dbt_test_gattcharlifecycle01.cpp
index 2039baa5..00c5310f 100644
--- a/examples/dbt_test_gattcharlifecycle01.cpp
+++ b/examples/dbt_test_gattcharlifecycle01.cpp
@@ -308,7 +308,7 @@ static void connectDiscoveredDevice(std::shared_ptr<BTDevice> device) {
bool r = device->setConnSecurityAuto( sec->getSecurityAutoIOCap() );
fprintf_td(stderr, "****** Connecting Device: Using SecurityDetail.SEC AUTO %s, set OK %d\n", sec->toString().c_str(), r);
} else if( sec->isSecLevelOrIOCapSet() ) {
- bool r = device->setConnSecurityBest( sec->getSecLevel(), sec->getIOCap() );
+ bool r = device->setConnSecurity( sec->getSecLevel(), sec->getIOCap() );
fprintf_td(stderr, "****** Connecting Device: Using SecurityDetail.Level+IOCap %s, set OK %d\n", sec->toString().c_str(), r);
} else {
bool r = device->setConnSecurityAuto( SMPIOCapability::KEYBOARD_ONLY );
diff --git a/examples/java/DBTScanner10.java b/examples/java/DBTScanner10.java
index 31755ca5..308e8f99 100644
--- a/examples/java/DBTScanner10.java
+++ b/examples/java/DBTScanner10.java
@@ -364,7 +364,7 @@ public class DBTScanner10 {
final boolean r = device.setConnSecurityAuto( sec.getSecurityAutoIOCap() );
BTUtils.println(System.err, "****** Connecting Device: Using SecurityDetail.SEC AUTO "+sec+" -> set OK "+r);
} else if( sec.isSecLevelOrIOCapSet() ) {
- final boolean r = device.setConnSecurityBest(sec.getSecLevel(), sec.getIOCap());
+ final boolean r = device.setConnSecurity(sec.getSecLevel(), sec.getIOCap());
BTUtils.println(System.err, "****** Connecting Device: Using SecurityDetail.Level+IOCap "+sec+" -> set OK "+r);
} else {
final boolean r = device.setConnSecurityAuto( SMPIOCapability.KEYBOARD_ONLY );
diff --git a/java/jau/direct_bt/DBTDevice.java b/java/jau/direct_bt/DBTDevice.java
index 3f2f5b76..70fdf7e9 100644
--- a/java/jau/direct_bt/DBTDevice.java
+++ b/java/jau/direct_bt/DBTDevice.java
@@ -519,24 +519,12 @@ public class DBTDevice extends DBTObject implements BTDevice
private final native byte unpairImpl();
@Override
- public final boolean setConnSecurityLevel(final BTSecurityLevel sec_level) {
- return setConnSecurityLevelImpl(sec_level.value);
- }
- private final native boolean setConnSecurityLevelImpl(final byte sec_level);
-
- @Override
public final BTSecurityLevel getConnSecurityLevel() {
return BTSecurityLevel.get( getConnSecurityLevelImpl() );
}
private final native byte getConnSecurityLevelImpl();
@Override
- public final boolean setConnIOCapability(final SMPIOCapability io_cap) {
- return setConnIOCapabilityImpl(io_cap.value);
- }
- private final native boolean setConnIOCapabilityImpl(final byte io_cap);
-
- @Override
public final SMPIOCapability getConnIOCapability() {
return SMPIOCapability.get( getConnIOCapabilityImpl() );
}
@@ -549,23 +537,6 @@ public class DBTDevice extends DBTObject implements BTDevice
private final native boolean setConnSecurityImpl(final byte sec_level, final byte io_cap);
@Override
- public final boolean setConnSecurityBest(final BTSecurityLevel sec_level, final SMPIOCapability io_cap) {
- if( BTSecurityLevel.UNSET.value < sec_level.value && SMPIOCapability.UNSET.value != io_cap.value ) {
- return setConnSecurity(sec_level, io_cap);
- } else if( BTSecurityLevel.UNSET.value < sec_level.value ) {
- if( BTSecurityLevel.ENC_ONLY.value >= sec_level.value ) {
- return setConnSecurity(sec_level, SMPIOCapability.NO_INPUT_NO_OUTPUT);
- } else {
- return setConnSecurityLevel(sec_level);
- }
- } else if( SMPIOCapability.UNSET.value != io_cap.value ) {
- return setConnIOCapability(io_cap);
- } else {
- return false;
- }
- }
-
- @Override
public final boolean setConnSecurityAuto(final SMPIOCapability iocap_auto) {
return setConnSecurityAutoImpl( iocap_auto.value );
}
diff --git a/java/jni/direct_bt/DBTDevice.cxx b/java/jni/direct_bt/DBTDevice.cxx
index 4bcf6492..8457d024 100644
--- a/java/jni/direct_bt/DBTDevice.cxx
+++ b/java/jni/direct_bt/DBTDevice.cxx
@@ -704,65 +704,65 @@ jbyte Java_jau_direct_1bt_DBTDevice_unpairImpl(JNIEnv *env, jobject obj) {
return (jbyte) number(HCIStatusCode::INTERNAL_FAILURE);
}
-jboolean Java_jau_direct_1bt_DBTDevice_setConnSecurityLevelImpl(JNIEnv *env, jobject obj, jbyte jsec_level) {
+jbyte Java_jau_direct_1bt_DBTDevice_getConnSecurityLevelImpl(JNIEnv *env, jobject obj) {
try {
BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- return device->setConnSecurityLevel( to_BTSecurityLevel( static_cast<uint8_t>(jsec_level) ));
+ return number( device->getConnSecurityLevel() );
} catch(...) {
rethrow_and_raise_java_exception(env);
}
- return JNI_FALSE;
+ return number( BTSecurityLevel::UNSET );
}
-jbyte Java_jau_direct_1bt_DBTDevice_getConnSecurityLevelImpl(JNIEnv *env, jobject obj) {
+jbyte Java_jau_direct_1bt_DBTDevice_getConnIOCapabilityImpl(JNIEnv *env, jobject obj) {
try {
BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- return number( device->getConnSecurityLevel() );
+ return number( device->getConnIOCapability() );
} catch(...) {
rethrow_and_raise_java_exception(env);
}
- return number( BTSecurityLevel::UNSET );
+ return number( SMPIOCapability::UNSET );
}
-jboolean Java_jau_direct_1bt_DBTDevice_setConnIOCapabilityImpl(JNIEnv *env, jobject obj, jbyte jio_cap) {
+jboolean Java_jau_direct_1bt_DBTDevice_setConnSecurityImpl(JNIEnv *env, jobject obj, jbyte jsec_level, jbyte jio_cap) {
try {
BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- return device->setConnIOCapability( to_SMPIOCapability( static_cast<uint8_t>(jio_cap) ));
+ return device->setConnSecurity( to_BTSecurityLevel( static_cast<uint8_t>(jsec_level) ),
+ to_SMPIOCapability( static_cast<uint8_t>(jio_cap) ) );
} catch(...) {
rethrow_and_raise_java_exception(env);
}
return JNI_FALSE;
}
-jboolean Java_jau_direct_1bt_DBTDevice_setConnSecurityImpl(JNIEnv *env, jobject obj, jbyte jsec_level, jbyte jio_cap) {
+jboolean Java_jau_direct_1bt_DBTDevice_setConnSecurityAutoImpl(JNIEnv *env, jobject obj, jbyte jio_cap) {
try {
BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- return device->setConnSecurity( to_BTSecurityLevel( static_cast<uint8_t>(jsec_level) ),
- to_SMPIOCapability( static_cast<uint8_t>(jio_cap) ) );
+ return device->setConnSecurityAuto( to_SMPIOCapability( static_cast<uint8_t>(jio_cap) ) );
} catch(...) {
rethrow_and_raise_java_exception(env);
}
return JNI_FALSE;
}
-jbyte Java_jau_direct_1bt_DBTDevice_getConnIOCapabilityImpl(JNIEnv *env, jobject obj) {
+jboolean Java_jau_direct_1bt_DBTDevice_isConnSecurityAutoEnabled(JNIEnv *env, jobject obj) {
try {
BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
- return number( device->getConnIOCapability() );
+ return device->isConnSecurityAutoEnabled();
} catch(...) {
rethrow_and_raise_java_exception(env);
}
- return number( SMPIOCapability::UNSET );
+ return JNI_FALSE;
}
jbyte Java_jau_direct_1bt_DBTDevice_getPairingModeImpl(JNIEnv *env, jobject obj) {
@@ -789,30 +789,6 @@ jbyte Java_jau_direct_1bt_DBTDevice_getPairingStateImpl(JNIEnv *env, jobject obj
return static_cast<uint8_t>( SMPPairingState::NONE );
}
-jboolean Java_jau_direct_1bt_DBTDevice_setConnSecurityAutoImpl(JNIEnv *env, jobject obj, jbyte jio_cap) {
- try {
- BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
- JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
-
- return device->setConnSecurityAuto( to_SMPIOCapability( static_cast<uint8_t>(jio_cap) ) );
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
-jboolean Java_jau_direct_1bt_DBTDevice_isConnSecurityAutoEnabled(JNIEnv *env, jobject obj) {
- try {
- BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
- JavaGlobalObj::check(device->getJavaObject(), E_FILE_LINE);
-
- return device->isConnSecurityAutoEnabled();
- } catch(...) {
- rethrow_and_raise_java_exception(env);
- }
- return JNI_FALSE;
-}
-
jbyte Java_jau_direct_1bt_DBTDevice_setPairingPasskeyImpl(JNIEnv *env, jobject obj, jint jpasskey) {
try {
BTDevice *device = getJavaUplinkObject<BTDevice>(env, obj);
diff --git a/java/org/direct_bt/BTDevice.java b/java/org/direct_bt/BTDevice.java
index 66136f90..f82fc408 100644
--- a/java/org/direct_bt/BTDevice.java
+++ b/java/org/direct_bt/BTDevice.java
@@ -370,34 +370,6 @@ public interface BTDevice extends BTObject
HCIStatusCode unpair();
/**
- * Set the {@link BTSecurityLevel} used to connect to this device on the upcoming connection.
- * <p>
- * Method returns false if {@link BTSecurityLevel#UNSET} has been given,
- * operation fails, this device has already being connected,
- * or {@link #connectLE(short, short, short, short, short, short) connectLE} or {@link #connectDefault()} has been issued already.
- * </p>
- * <p>
- * To ensure a consistent authentication setup,
- * it is advised to set {@link SMPIOCapability#NO_INPUT_NO_OUTPUT} for sec_level <= {@link BTSecurityLevel#ENC_ONLY}
- * using {@link #setConnSecurity(BTSecurityLevel, SMPIOCapability, boolean) setConnSecurity(..)}
- * as well as an IO capable {@link SMPIOCapability} value
- * for {@link BTSecurityLevel#ENC_AUTH} or {@link BTSecurityLevel#ENC_AUTH_FIPS}.<br>
- * You may like to consider using {@link #setConnSecurityBest(BTSecurityLevel, SMPIOCapability)}.
- * </p>
- * @param sec_level {@link BTSecurityLevel} to be applied, {@link BTSecurityLevel#UNSET} will be ignored and method fails.
- * @return
- * @since 2.1.0
- * @see BTSecurityLevel
- * @see SMPIOCapability
- * @see #getConnSecurityLevel()
- * @see #setConnIOCapability(SMPIOCapability)
- * @see #getConnIOCapability()
- * @see #setConnSecurity(BTSecurityLevel, SMPIOCapability)
- * @see #setConnSecurityBest(BTSecurityLevel, SMPIOCapability)
- */
- boolean setConnSecurityLevel(final BTSecurityLevel sec_level);
-
- /**
* Return the {@link BTSecurityLevel}, determined when the connection is established.
* @since 2.1.0
* @see BTSecurityLevel
@@ -411,25 +383,6 @@ public interface BTDevice extends BTObject
BTSecurityLevel getConnSecurityLevel();
/**
- * Sets the given {@link SMPIOCapability} used to connect to this device on the upcoming connection.
- * <p>
- * Method returns false if {@link SMPIOCapability#UNSET} has been given,
- * operation fails, this device has already being connected,
- * or {@link #connectLE(short, short, short, short, short, short) connectLE} or {@link #connectDefault()} has been issued already.
- * </p>
- * @param io_cap {@link SMPIOCapability} to be applied, {@link SMPIOCapability#UNSET} will be ignored and method fails.
- * @since 2.1.0
- * @see BTSecurityLevel
- * @see SMPIOCapability
- * @see #setConnSecurityLevel(BTSecurityLevel)
- * @see #getConnSecurityLevel()
- * @see #getConnIOCapability()
- * @see #setConnSecurity(BTSecurityLevel, SMPIOCapability)
- * @see #setConnSecurityBest(BTSecurityLevel, SMPIOCapability)
- */
- boolean setConnIOCapability(final SMPIOCapability io_cap);
-
- /**
* Return the {@link SMPIOCapability} value, determined when the connection is established.
* @since 2.1.0
* @see BTSecurityLevel
@@ -444,49 +397,30 @@ public interface BTDevice extends BTObject
/**
* Sets the given {@link BTSecurityLevel} and {@link SMPIOCapability} used to connect to this device on the upcoming connection.
- * <p>
- * Method returns false if this device has already being connected,
- * or {@link #connectLE(short, short, short, short, short, short) connectLE} or {@link #connectDefault()} has been issued already.
- * </p>
- * <p>
- * Method either changes both parameter for the upcoming connection or none at all.
- * </p>
- * @param sec_level {@link BTSecurityLevel} to be applied.
- * @param io_cap {@link SMPIOCapability} to be applied.
- * @since 2.1.0
- * @see BTSecurityLevel
- * @see SMPIOCapability
- * @see #setConnSecurityLevel(BTSecurityLevel)
- * @see #getConnSecurityLevel()
- * @see #setConnIOCapability(SMPIOCapability)
- * @see #getConnIOCapability()
- * @see #setConnSecurityBest(BTSecurityLevel, SMPIOCapability)
- */
- boolean setConnSecurity(final BTSecurityLevel sec_level, final SMPIOCapability io_cap);
-
- /**
- * Convenience method to determine the best practice {@link BTSecurityLevel} and {@link SMPIOCapability}
- * based on the given arguments, used to connect to this device on the upcoming connection.
+ *
+ * Implementation using following pseudo-code, validating the user settings:
* <pre>
* if( BTSecurityLevel::UNSET < sec_level && SMPIOCapability::UNSET != io_cap ) {
- * return setConnSecurity(sec_level, io_cap);
+ * USING: sec_level, io_cap
* } else if( BTSecurityLevel::UNSET < sec_level ) {
* if( BTSecurityLevel::ENC_ONLY >= sec_level ) {
- * return setConnSecurity(sec_level, SMPIOCapability::NO_INPUT_NO_OUTPUT);
+ * USING: sec_level, SMPIOCapability::NO_INPUT_NO_OUTPUT
* } else {
- * return setConnSecurityLevel(sec_level);
+ * USING: sec_level, SMPIOCapability::UNSET
* }
* } else if( SMPIOCapability::UNSET != io_cap ) {
- * return setConnIOCapability(io_cap);
+ * USING BTSecurityLevel::UNSET, io_cap
* } else {
- * return false;
+ * USING BTSecurityLevel::UNSET, SMPIOCapability::UNSET
* }
* </pre>
* <p>
- * Method returns false if {@link BTSecurityLevel#UNSET} and {@link SMPIOCapability#UNSET} has been given,
- * operation fails, this device has already being connected,
+ * Method returns false if this device has already being connected,
* or {@link #connectLE(short, short, short, short, short, short) connectLE} or {@link #connectDefault()} has been issued already.
* </p>
+ * <p>
+ * Method either changes both parameter for the upcoming connection or none at all.
+ * </p>
* @param sec_level {@link BTSecurityLevel} to be applied.
* @param io_cap {@link SMPIOCapability} to be applied.
* @since 2.1.0
@@ -496,10 +430,9 @@ public interface BTDevice extends BTObject
* @see #getConnSecurityLevel()
* @see #setConnIOCapability(SMPIOCapability)
* @see #getConnIOCapability()
- * @see #setConnSecurity(BTSecurityLevel, SMPIOCapability)
- * @see #setConnSecurityAuto(SMPIOCapability)
+ * @see #setConnSecurityBest(BTSecurityLevel, SMPIOCapability)
*/
- boolean setConnSecurityBest(final BTSecurityLevel sec_level, final SMPIOCapability io_cap);
+ boolean setConnSecurity(final BTSecurityLevel sec_level, final SMPIOCapability io_cap);
/**
* Set automatic security negotiation of {@link BTSecurityLevel} and {@link SMPIOCapability} pairing mode.
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 {