diff options
author | Sven Gothel <[email protected]> | 2020-12-10 07:02:10 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-12-10 07:02:10 +0100 |
commit | ab86d222890076ce26b8638411e490c047add780 (patch) | |
tree | dd7f37fc70f35fe2278b9b001d2741d00819ac97 /examples/direct_bt_scanner10 | |
parent | 118d564141d594e3f9fe0a082f1854289c95a7a8 (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.cpp | 9 |
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(); } } ); |