summaryrefslogtreecommitdiffstats
path: root/examples/direct_bt_scanner10
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-12-10 09:46:45 +0100
committerSven Gothel <[email protected]>2020-12-10 09:46:45 +0100
commitde11465791d2766525febcaa6934154a31d9c733 (patch)
tree203db2f9f4b336f5d883608eb6af8c4cc66475b9 /examples/direct_bt_scanner10
parentab86d222890076ce26b8638411e490c047add780 (diff)
SMPLongTermKeyInfo: Encode RESPONDER (or INITIATOR) within its Property bit mask, determining key role; ...
DBTDevice::setLongTermKeyInfo() writes given key to pairing_data.ltk_resp or pairing_data.ltk_init to reflect proper state.
Diffstat (limited to 'examples/direct_bt_scanner10')
-rw-r--r--examples/direct_bt_scanner10/dbt_scanner10.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp
index 27ef64e8..1336c71e 100644
--- a/examples/direct_bt_scanner10/dbt_scanner10.cpp
+++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp
@@ -167,11 +167,17 @@ __pack( struct MyLongTermKeyInfo {
bool write(const std::string filename) {
if( !smp_ltk.isValid() ) {
+ fprintf(stderr, "****** WRITE LTK [%s %s, invalid, skipped]: %s\n",
+ address.toString().c_str(), getBDAddressTypeString(address_type).c_str(),
+ smp_ltk.toString().c_str());
return false;
}
std::ofstream file(filename, std::ios::binary | std::ios::trunc);
file.write((char*)this, sizeof(*this));
file.close();
+ fprintf(stderr, "****** WRITE LTK [%s %s, valid, written]: %s\n",
+ address.toString().c_str(), getBDAddressTypeString(address_type).c_str(),
+ smp_ltk.toString().c_str());
return true;
}
@@ -182,6 +188,9 @@ __pack( struct MyLongTermKeyInfo {
}
file.read((char*)this, sizeof(*this));
file.close();
+ fprintf(stderr, "****** READ LTK [%s %s, valid %d]: %s\n",
+ address.toString().c_str(), getBDAddressTypeString(address_type).c_str(),
+ smp_ltk.isValid(), smp_ltk.toString().c_str());
return smp_ltk.isValid();
}
} );
@@ -406,8 +415,8 @@ static void connectDiscoveredDevice(std::shared_ptr<DBTDevice> device) {
MyLongTermKeyInfo my_ltk_init;
if( my_ltk_init.read(device->getAddress().toString()+".init.ltk") &&
my_ltk_resp.read(device->getAddress().toString()+".resp.ltk") &&
- HCIStatusCode::SUCCESS == device->setLongTermKeyInfo(my_ltk_init.smp_ltk, false /* responder */) &&
- HCIStatusCode::SUCCESS == device->setLongTermKeyInfo(my_ltk_resp.smp_ltk, true /* responder */) ) {
+ HCIStatusCode::SUCCESS == device->setLongTermKeyInfo(my_ltk_init.smp_ltk) &&
+ HCIStatusCode::SUCCESS == device->setLongTermKeyInfo(my_ltk_resp.smp_ltk) ) {
fprintf(stderr, "****** Connecting Device: Loaded LTKs from file successfully\n");
} else {
fprintf(stderr, "****** Connecting Device: Error loading LTKs from file\n");
@@ -437,7 +446,8 @@ static void processReadyDevice(std::shared_ptr<DBTDevice> device) {
{
const SMPPairingState pstate = device->getPairingState();
- if( SMPPairingState::COMPLETED == pstate) {
+ const PairingMode pmode = device->getPairingMode(); // Skip PairingMode::PRE_PAIRED (write again)
+ if( SMPPairingState::COMPLETED == pstate && PairingMode::PRE_PAIRED != pmode ) {
{
MyLongTermKeyInfo my_ltk { device->getAddress(), device->getAddressType(),
device->getLongTermKeyInfo(false /* responder */) };