summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-11-24 21:05:27 +0100
committerSven Gothel <[email protected]>2020-11-24 21:05:27 +0100
commitcc475330fd173ee0e38b4a9a8cb5205fa2136bed (patch)
treec6c97247cbd8f0304473caf1865f366b3ea9cab9 /examples
parent9f932fc51e5bed3d1a059131667191f56c20d7fb (diff)
DBTDevice: Clarify setConn* Security parameter API: Provide more versatile overloaded variant and simplified API entries.
setConnSecurityLevel(..) no more sets SMPIOCapability, only advise in API doc to avoid complexity.
Diffstat (limited to 'examples')
-rw-r--r--examples/direct_bt_scanner10/dbt_scanner10.cpp14
-rw-r--r--examples/java/DBTScanner10.java8
2 files changed, 15 insertions, 7 deletions
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp
index bcda886a..74565da3 100644
--- a/examples/direct_bt_scanner10/dbt_scanner10.cpp
+++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp
@@ -76,8 +76,8 @@ static bool QUIET = false;
static std::vector<EUI48> waitForDevices;
-const static uint32_t NO_PASSKEY = 0xffffffffU;
-static uint32_t pairing_passkey = NO_PASSKEY;
+const static int NO_PASSKEY = -1;
+static int pairing_passkey = NO_PASSKEY;
static BTSecurityLevel sec_level = BTSecurityLevel::UNSET;
static SMPIOCapability io_capabilities = SMPIOCapability::UNSET;
@@ -250,7 +250,7 @@ class MyAdapterStatusListener : public AdapterStatusListener {
break;
case SMPPairingState::PASSKEY_EXPECTED: {
if( pairing_passkey != NO_PASSKEY ) {
- std::thread dc(&DBTDevice::setPairingPasskey, device, pairing_passkey); // @suppress("Invalid arguments")
+ std::thread dc(&DBTDevice::setPairingPasskey, device, static_cast<uint32_t>(pairing_passkey)); // @suppress("Invalid arguments")
dc.detach();
} /* else {
std::thread dc(&DBTDevice::setPairingPasskeyNegative, device); // @suppress("Invalid arguments")
@@ -367,7 +367,11 @@ static void connectDiscoveredDevice(std::shared_ptr<DBTDevice> device) {
if( BTSecurityLevel::UNSET < sec_level && SMPIOCapability::UNSET != io_capabilities ) {
device->setConnSecurity(sec_level, io_capabilities, true /* blocking */);
} else if( BTSecurityLevel::UNSET < sec_level ) {
- device->setConnSecurityLevel(sec_level, true /* blocking */);
+ if( BTSecurityLevel::ENC_ONLY >= sec_level ) {
+ device->setConnSecurity(sec_level, SMPIOCapability::NO_INPUT_NO_OUTPUT, true /* blocking */);
+ } else {
+ device->setConnSecurityLevel(sec_level);
+ }
} else if( SMPIOCapability::UNSET != io_capabilities ) {
device->setConnIOCapability(io_capabilities, true /* blocking */);
}
@@ -807,7 +811,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "SHOW_UPDATE_EVENTS %d\n", SHOW_UPDATE_EVENTS);
fprintf(stderr, "QUIET %d\n", QUIET);
fprintf(stderr, "btmode %s\n", getBTModeString(btMode).c_str());
- fprintf(stderr, "passkey %u\n", pairing_passkey);
+ fprintf(stderr, "passkey %d\n", pairing_passkey);
fprintf(stderr, "seclevel %s\n", getBTSecurityLevelString(sec_level).c_str());
fprintf(stderr, "iocap %s\n", getSMPIOCapabilityString(io_capabilities).c_str());
fprintf(stderr, "characteristic-id: %s\n", charIdentifier.c_str());
diff --git a/examples/java/DBTScanner10.java b/examples/java/DBTScanner10.java
index 33e799ca..1cbfb426 100644
--- a/examples/java/DBTScanner10.java
+++ b/examples/java/DBTScanner10.java
@@ -77,7 +77,7 @@ public class DBTScanner10 {
final List<String> waitForDevices = new ArrayList<String>();
- static final int NO_PASSKEY = 0xffffffff;
+ static final int NO_PASSKEY = -1;
int pairing_passkey = NO_PASSKEY;
BTSecurityLevel sec_level = BTSecurityLevel.UNSET;
SMPIOCapability io_capabilities = SMPIOCapability.UNSET;
@@ -295,7 +295,11 @@ public class DBTScanner10 {
if( BTSecurityLevel.UNSET.value < sec_level.value && SMPIOCapability.UNSET.value != io_capabilities.value ) {
device.setConnSecurity(sec_level, io_capabilities, true /* blocking */);
} else if( BTSecurityLevel.UNSET.value < sec_level.value ) {
- device.setConnSecurityLevel(sec_level, true /* blocking */);
+ if( BTSecurityLevel.ENC_ONLY.value >= sec_level.value ) {
+ device.setConnSecurity(sec_level, SMPIOCapability.NO_INPUT_NO_OUTPUT, true /* blocking */);
+ } else {
+ device.setConnSecurityLevel(sec_level);
+ }
} else if( SMPIOCapability.UNSET.value != io_capabilities.value ) {
device.setConnIOCapability(io_capabilities, true /* blocking */);
}