summaryrefslogtreecommitdiffstats
path: root/examples/direct_bt_scanner10
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-02-21 00:42:26 +0100
committerSven Gothel <[email protected]>2021-02-21 00:42:26 +0100
commita66c137167a9527f33063193d53108eb5fa6bb91 (patch)
tree5279571a669424c3cce3e0f454a1ce2865877844 /examples/direct_bt_scanner10
parent56902698fa3b0e64c4b050d83008e648a71c823b (diff)
SMPKeyBin: Allow BTSecurityLevel::NONE case; Add more convenient createAndWrite(..) and readAndApply(..) one-liner
Further: - Bump to version 2 - Add creation timestamp (seconds since epoch) - Convenient createAndWrite(..) and readAndApply(..) one-liner handle overwrite and remove-invalid use-case
Diffstat (limited to 'examples/direct_bt_scanner10')
-rw-r--r--examples/direct_bt_scanner10/dbt_scanner10.cpp41
1 files changed, 5 insertions, 36 deletions
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp
index 2b8d55fd..a7b6e6bc 100644
--- a/examples/direct_bt_scanner10/dbt_scanner10.cpp
+++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp
@@ -327,7 +327,7 @@ class MyAdapterStatusListener : public AdapterStatusListener {
case SMPPairingState::FAILED: {
const bool res = SMPKeyBin::remove(KEY_PATH, device->getAddressAndType());
fprintf_td(stderr, "****** PAIRING_STATE: state %s; Remove key file %s, res %d\n",
- to_string(state).c_str(), SMPKeyBin::getFilePath(KEY_PATH, device->getAddressAndType()).c_str(), res);
+ to_string(state).c_str(), SMPKeyBin::getFilename(KEY_PATH, device->getAddressAndType()).c_str(), res);
// next: deviceReady() or deviceDisconnected(..)
} break;
case SMPPairingState::REQUESTED_BY_RESPONDER:
@@ -488,15 +488,8 @@ static void connectDiscoveredDevice(std::shared_ptr<BTDevice> device) {
device->getAdapter().stopDiscovery();
- bool useSMPKeyBin = false;
+ if( HCIStatusCode::SUCCESS != SMPKeyBin::readAndApply(KEY_PATH, *device, true /* removeInvalidFile */, true /* verbose */) )
{
- SMPKeyBin smpKeyBin;
- smpKeyBin.setVerbose( true );
- if( smpKeyBin.read(KEY_PATH, device->getAddressAndType()) ) {
- useSMPKeyBin = HCIStatusCode::SUCCESS == smpKeyBin.apply(*device);
- }
- }
- if( !useSMPKeyBin ) {
const MyBTSecurityDetail* sec = MyBTSecurityDetail::get(device->getAddressAndType());
if( nullptr != sec ) {
if( sec->isSecurityAutoEnabled() ) {
@@ -533,36 +526,12 @@ static void connectDiscoveredDevice(std::shared_ptr<BTDevice> device) {
static void processReadyDevice(std::shared_ptr<BTDevice> device) {
fprintf_td(stderr, "****** Processing Ready Device: Start %s\n", device->toString().c_str());
device->getAdapter().stopDiscovery(); // make sure for pending connections on failed connect*(..) command
+
const uint64_t t1 = getCurrentMilliseconds();
- bool success = false;
- {
- const SMPPairingState pstate = device->getPairingState();
- const PairingMode pmode = device->getPairingMode(); // Skip PairingMode::PRE_PAIRED (write again)
- if( SMPPairingState::COMPLETED == pstate && PairingMode::PRE_PAIRED != pmode ) {
- const SMPKeyType keys_resp = device->getAvailableSMPKeys(true /* responder */);
- const SMPKeyType keys_init = device->getAvailableSMPKeys(false /* responder */);
-
- SMPKeyBin smpKeyBin(device->getAddressAndType(),
- device->getConnSecurityLevel(), device->getConnIOCapability());
- smpKeyBin.setVerbose( true );
-
- if( ( SMPKeyType::ENC_KEY & keys_init ) != SMPKeyType::NONE ) {
- smpKeyBin.setLTKInit( device->getLongTermKeyInfo(false /* responder */) );
- }
- if( ( SMPKeyType::ENC_KEY & keys_resp ) != SMPKeyType::NONE ) {
- smpKeyBin.setLTKResp( device->getLongTermKeyInfo(true /* responder */) );
- }
+ SMPKeyBin::createAndWrite(*device, KEY_PATH, false /* overwrite */, true /* verbose */);
- if( ( SMPKeyType::SIGN_KEY & keys_init ) != SMPKeyType::NONE ) {
- smpKeyBin.setCSRKInit( device->getSignatureResolvingKeyInfo(false /* responder */) );
- }
- if( ( SMPKeyType::SIGN_KEY & keys_resp ) != SMPKeyType::NONE ) {
- smpKeyBin.setCSRKResp( device->getSignatureResolvingKeyInfo(true /* responder */) );
- }
- smpKeyBin.write(KEY_PATH);
- }
- }
+ bool success = false;
//
// GATT Service Processing