diff options
-rw-r--r-- | api/direct_bt/DBTManager.hpp | 2 | ||||
-rw-r--r-- | src/direct_bt/DBTManager.cpp | 26 |
2 files changed, 23 insertions, 5 deletions
diff --git a/api/direct_bt/DBTManager.hpp b/api/direct_bt/DBTManager.hpp index 86ec22aa..4bf22a2f 100644 --- a/api/direct_bt/DBTManager.hpp +++ b/api/direct_bt/DBTManager.hpp @@ -437,6 +437,8 @@ namespace direct_bt { std::shared_ptr<ConnectionInfo> getConnectionInfo(const uint16_t dev_id, const EUI48 &address, const BDAddressType address_type) noexcept; std::shared_ptr<NameAndShortName> setLocalName(const uint16_t dev_id, const std::string & name, const std::string & short_name) noexcept; + /** Security commands */ + MgmtStatus uploadLinkKey(const uint16_t dev_id, const bool debug_keys, const MgmtLinkKey &key) noexcept; MgmtStatus uploadLongTermKey(const uint16_t dev_id, const MgmtLongTermKey &key) noexcept; diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index 9f89bbee..eb27d611 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -235,6 +235,8 @@ std::shared_ptr<MgmtEvent> DBTManager::sendWithReply(MgmtCommand &req) noexcept } std::shared_ptr<AdapterInfo> DBTManager::initAdapter(const uint16_t dev_id, const BTMode btMode) noexcept { + // const MgmtIOCapability iocap { MgmtIOCapability::KeyboardDisplay }; + const MgmtIOCapability iocap { MgmtIOCapability::DisplayOnly }; std::shared_ptr<AdapterInfo> adapterInfo = nullptr; AdapterSetting current_settings; MgmtCommand req0(MgmtCommand::Opcode::READ_INFO, dev_id); @@ -258,27 +260,36 @@ std::shared_ptr<AdapterInfo> DBTManager::initAdapter(const uint16_t dev_id, cons switch ( btMode ) { case BTMode::DUAL: - setMode(dev_id, MgmtCommand::Opcode::SET_SSP, 1, current_settings); setMode(dev_id, MgmtCommand::Opcode::SET_BREDR, 1, current_settings); setDiscoverable(dev_id, 0, 0, current_settings); setMode(dev_id, MgmtCommand::Opcode::SET_LE, 1, current_settings); #if USE_LINUX_BT_SECURITY + // setMode(dev_id, MgmtCommand::Opcode::SET_DEBUG_KEYS, 1, current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_IO_CAPABILITY, number(iocap), current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_SSP, 1, current_settings); setMode(dev_id, MgmtCommand::Opcode::SET_SECURE_CONN, 1, current_settings); #endif break; case BTMode::BREDR: - setMode(dev_id, MgmtCommand::Opcode::SET_SSP, 1, current_settings); setMode(dev_id, MgmtCommand::Opcode::SET_BREDR, 1, current_settings); setDiscoverable(dev_id, 0, 0, current_settings); setMode(dev_id, MgmtCommand::Opcode::SET_LE, 0, current_settings); +#if USE_LINUX_BT_SECURITY + // setMode(dev_id, MgmtCommand::Opcode::SET_DEBUG_KEYS, 1, current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_IO_CAPABILITY, number(iocap), current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_SSP, 1, current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_SECURE_CONN, 0, current_settings); +#endif break; case BTMode::NONE: [[fallthrough]]; // map NONE -> LE case BTMode::LE: - setMode(dev_id, MgmtCommand::Opcode::SET_SSP, 0, current_settings); setMode(dev_id, MgmtCommand::Opcode::SET_BREDR, 0, current_settings); setMode(dev_id, MgmtCommand::Opcode::SET_LE, 1, current_settings); #if USE_LINUX_BT_SECURITY + // setMode(dev_id, MgmtCommand::Opcode::SET_DEBUG_KEYS, 1, current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_IO_CAPABILITY, number(iocap), current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_SSP, 0, current_settings); setMode(dev_id, MgmtCommand::Opcode::SET_SECURE_CONN, 1, current_settings); #endif break; @@ -320,11 +331,16 @@ fail: void DBTManager::shutdownAdapter(const uint16_t dev_id) noexcept { AdapterSetting current_settings; - setMode(dev_id, MgmtCommand::Opcode::SET_SECURE_CONN, 0, current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_POWERED, 0, current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_BONDABLE, 0, current_settings); setMode(dev_id, MgmtCommand::Opcode::SET_CONNECTABLE, 0, current_settings); setMode(dev_id, MgmtCommand::Opcode::SET_FAST_CONNECTABLE, 0, current_settings); - setMode(dev_id, MgmtCommand::Opcode::SET_POWERED, 0, current_settings); + + setMode(dev_id, MgmtCommand::Opcode::SET_DEBUG_KEYS, 0, current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_IO_CAPABILITY, number(MgmtIOCapability::DisplayOnly), current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_SSP, 0, current_settings); + setMode(dev_id, MgmtCommand::Opcode::SET_SECURE_CONN, 0, current_settings); } DBTManager::DBTManager(const BTMode _defaultBTMode) noexcept |