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 /java | |
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 'java')
-rw-r--r-- | java/jau/direct_bt/DBTDevice.java | 29 | ||||
-rw-r--r-- | java/jni/direct_bt/DBTDevice.cxx | 52 | ||||
-rw-r--r-- | java/org/direct_bt/BTDevice.java | 93 |
3 files changed, 27 insertions, 147 deletions
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. |