summaryrefslogtreecommitdiffstats
path: root/examples/direct_bt_scanner10
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-12-10 07:02:10 +0100
committerSven Gothel <[email protected]>2020-12-10 07:02:10 +0100
commitab86d222890076ce26b8638411e490c047add780 (patch)
treedd7f37fc70f35fe2278b9b001d2741d00819ac97 /examples/direct_bt_scanner10
parent118d564141d594e3f9fe0a082f1854289c95a7a8 (diff)
BluetoothDevice: Support SMPLongTermKeyInfo via [get/set]LongTermKeyInfo(..), tested with DBTScanner10.java
Java + Native test are now on par, may share the LTK binary file in example. On loading a pre-existing key when device found and before connecting, BlueZ/Kernel will try the uploaded key and no pairing procedure is being performed. This tested with explicit unpair before uploading the LTK, to ensure the pre-existing keys have been deleted.
Diffstat (limited to 'examples/direct_bt_scanner10')
-rw-r--r--examples/direct_bt_scanner10/dbt_scanner10.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp
index 72bd422c..27ef64e8 100644
--- a/examples/direct_bt_scanner10/dbt_scanner10.cpp
+++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp
@@ -165,11 +165,16 @@ __pack( struct MyLongTermKeyInfo {
BDAddressType address_type;
SMPLongTermKeyInfo smp_ltk;
- void write(const std::string filename) {
+ bool write(const std::string filename) {
+ if( !smp_ltk.isValid() ) {
+ return false;
+ }
std::ofstream file(filename, std::ios::binary | std::ios::trunc);
file.write((char*)this, sizeof(*this));
file.close();
+ return true;
}
+
bool read(const std::string filename) {
std::ifstream file(filename, std::ios::binary);
if (!file.is_open() ) {
@@ -177,7 +182,7 @@ __pack( struct MyLongTermKeyInfo {
}
file.read((char*)this, sizeof(*this));
file.close();
- return true;
+ return smp_ltk.isValid();
}
} );