Loading system/gd/security/internal/security_manager_impl.cc +11 −6 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include "hci/address_with_type.h" #include "os/log.h" #include "security/initial_informations.h" #include "security/security_manager.h" namespace bluetooth { Loading Loading @@ -48,7 +49,7 @@ std::shared_ptr<bluetooth::security::record::SecurityRecord> SecurityManagerImpl void SecurityManagerImpl::DispatchPairingHandler(std::shared_ptr<security::record::SecurityRecord> record, bool locally_initiated) { common::OnceCallback<void(hci::Address)> callback = common::OnceCallback<void(hci::Address, PairingResultOrFailure)> callback = common::BindOnce(&SecurityManagerImpl::OnPairingHandlerComplete, common::Unretained(this)); auto entry = pairing_handler_map_.find(record->GetDevice().GetAddress()); if (entry != pairing_handler_map_.end()) { Loading Loading @@ -136,10 +137,10 @@ void SecurityManagerImpl::NotifyDeviceBonded(hci::AddressWithType device) { } } void SecurityManagerImpl::NotifyDeviceBondFailed(hci::AddressWithType device) { void SecurityManagerImpl::NotifyDeviceBondFailed(hci::AddressWithType device, PairingResultOrFailure status) { for (auto& iter : listeners_) { iter.second->Post( common::Bind(&ISecurityManagerListener::OnDeviceBondFailed, common::Unretained(iter.first), device)); iter.second->Post(common::Bind(&ISecurityManagerListener::OnDeviceBondFailed, common::Unretained(iter.first), device /*, status */)); } } Loading Loading @@ -219,12 +220,16 @@ void SecurityManagerImpl::OnHciEventReceived(hci::EventPacketView packet) { } } void SecurityManagerImpl::OnPairingHandlerComplete(hci::Address address) { void SecurityManagerImpl::OnPairingHandlerComplete(hci::Address address, PairingResultOrFailure status) { auto entry = pairing_handler_map_.find(address); if (entry != pairing_handler_map_.end()) { pairing_handler_map_.erase(entry); } if (!std::holds_alternative<PairingFailure>(status)) { NotifyDeviceBonded(hci::AddressWithType(address, hci::AddressType::PUBLIC_DEVICE_ADDRESS)); } else { NotifyDeviceBondFailed(hci::AddressWithType(address, hci::AddressType::PUBLIC_DEVICE_ADDRESS), status); } } } // namespace internal Loading system/gd/security/internal/security_manager_impl.h +13 −3 Original line number Diff line number Diff line Loading @@ -94,15 +94,25 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener { */ void UnregisterCallbackListener(ISecurityManagerListener* listener); // ISecurityManagerChannel /** * Handle the events sent back from HCI that we care about * * @param packet data received from HCI */ void OnHciEventReceived(hci::EventPacketView packet) override; void OnPairingHandlerComplete(hci::Address address); /** * Pairing handler has finished or cancelled * * @param address address for pairing handler * @param status status from SimplePairingComplete or other error code */ void OnPairingHandlerComplete(hci::Address address, PairingResultOrFailure status); protected: std::vector<std::pair<ISecurityManagerListener*, os::Handler*>> listeners_; void NotifyDeviceBonded(hci::AddressWithType device); void NotifyDeviceBondFailed(hci::AddressWithType device); void NotifyDeviceBondFailed(hci::AddressWithType device, PairingResultOrFailure status); void NotifyDeviceUnbonded(hci::AddressWithType device); private: Loading system/gd/security/pairing/classic_pairing_handler.cc +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ void ClassicPairingHandler::OnRegistrationComplete( } void ClassicPairingHandler::OnUnregistered() { std::move(complete_callback_).Run(GetRecord()->GetDevice().GetAddress()); std::move(complete_callback_).Run(GetRecord()->GetDevice().GetAddress(), last_status_); } void ClassicPairingHandler::OnConnectionOpen(std::unique_ptr<l2cap::classic::FixedChannel> fixed_channel) { Loading system/gd/security/pairing/classic_pairing_handler.h +4 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <utility> #include "l2cap/classic/l2cap_classic_module.h" #include "security/initial_informations.h" namespace bluetooth { namespace security { Loading @@ -37,7 +38,7 @@ class ClassicPairingHandler : public PairingHandler { ClassicPairingHandler(std::shared_ptr<l2cap::classic::FixedChannelManager> fixed_channel_manager, channel::SecurityManagerChannel* security_manager_channel, std::shared_ptr<record::SecurityRecord> record, os::Handler* security_handler, common::OnceCallback<void(hci::Address)> complete_callback) common::OnceCallback<void(hci::Address, PairingResultOrFailure)> complete_callback) : PairingHandler(security_manager_channel, std::move(record)), fixed_channel_manager_(std::move(fixed_channel_manager)), security_policy_(), security_handler_(security_handler), remote_io_capability_(kDefaultIoCapability), Loading Loading @@ -85,7 +86,8 @@ class ClassicPairingHandler : public PairingHandler { hci::OobDataPresent local_oob_present_ __attribute__((unused)); hci::AuthenticationRequirements local_authentication_requirements_ __attribute__((unused)); std::unique_ptr<l2cap::classic::FixedChannel> fixed_channel_{nullptr}; common::OnceCallback<void(hci::Address)> complete_callback_; common::OnceCallback<void(hci::Address, PairingResultOrFailure)> complete_callback_; PairingResultOrFailure last_status_; bool locally_initiated_ = false; }; Loading system/gd/security/pairing/classic_pairing_handler_unittest.cc +9 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include "l2cap/classic/fixed_channel_manager_mock.h" #include "packet/raw_builder.h" #include "security/channel/security_manager_channel.h" #include "security/initial_informations.h" #include "security/smp_packets.h" #include "security/test/fake_hci_layer.h" Loading Loading @@ -99,7 +100,14 @@ class SecurityManagerChannelCallback : public ISecurityManagerChannelListener { pairing::ClassicPairingHandler* pairing_handler_ = nullptr; }; static void pairing_complete_callback(bluetooth::hci::Address address) {} static void pairing_complete_callback(bluetooth::hci::Address address, PairingResultOrFailure status) { // if (std::holds_alternative<PairingResult>(status)) { // auto result = status::get<PairingResult>(status); // } // if (std::holds_alternative<PairingFailure>(status)) { // auto failure = status::get<PairingFailure>(status); // } } class ClassicPairingHandlerTest : public ::testing::Test { protected: Loading Loading
system/gd/security/internal/security_manager_impl.cc +11 −6 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include "hci/address_with_type.h" #include "os/log.h" #include "security/initial_informations.h" #include "security/security_manager.h" namespace bluetooth { Loading Loading @@ -48,7 +49,7 @@ std::shared_ptr<bluetooth::security::record::SecurityRecord> SecurityManagerImpl void SecurityManagerImpl::DispatchPairingHandler(std::shared_ptr<security::record::SecurityRecord> record, bool locally_initiated) { common::OnceCallback<void(hci::Address)> callback = common::OnceCallback<void(hci::Address, PairingResultOrFailure)> callback = common::BindOnce(&SecurityManagerImpl::OnPairingHandlerComplete, common::Unretained(this)); auto entry = pairing_handler_map_.find(record->GetDevice().GetAddress()); if (entry != pairing_handler_map_.end()) { Loading Loading @@ -136,10 +137,10 @@ void SecurityManagerImpl::NotifyDeviceBonded(hci::AddressWithType device) { } } void SecurityManagerImpl::NotifyDeviceBondFailed(hci::AddressWithType device) { void SecurityManagerImpl::NotifyDeviceBondFailed(hci::AddressWithType device, PairingResultOrFailure status) { for (auto& iter : listeners_) { iter.second->Post( common::Bind(&ISecurityManagerListener::OnDeviceBondFailed, common::Unretained(iter.first), device)); iter.second->Post(common::Bind(&ISecurityManagerListener::OnDeviceBondFailed, common::Unretained(iter.first), device /*, status */)); } } Loading Loading @@ -219,12 +220,16 @@ void SecurityManagerImpl::OnHciEventReceived(hci::EventPacketView packet) { } } void SecurityManagerImpl::OnPairingHandlerComplete(hci::Address address) { void SecurityManagerImpl::OnPairingHandlerComplete(hci::Address address, PairingResultOrFailure status) { auto entry = pairing_handler_map_.find(address); if (entry != pairing_handler_map_.end()) { pairing_handler_map_.erase(entry); } if (!std::holds_alternative<PairingFailure>(status)) { NotifyDeviceBonded(hci::AddressWithType(address, hci::AddressType::PUBLIC_DEVICE_ADDRESS)); } else { NotifyDeviceBondFailed(hci::AddressWithType(address, hci::AddressType::PUBLIC_DEVICE_ADDRESS), status); } } } // namespace internal Loading
system/gd/security/internal/security_manager_impl.h +13 −3 Original line number Diff line number Diff line Loading @@ -94,15 +94,25 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener { */ void UnregisterCallbackListener(ISecurityManagerListener* listener); // ISecurityManagerChannel /** * Handle the events sent back from HCI that we care about * * @param packet data received from HCI */ void OnHciEventReceived(hci::EventPacketView packet) override; void OnPairingHandlerComplete(hci::Address address); /** * Pairing handler has finished or cancelled * * @param address address for pairing handler * @param status status from SimplePairingComplete or other error code */ void OnPairingHandlerComplete(hci::Address address, PairingResultOrFailure status); protected: std::vector<std::pair<ISecurityManagerListener*, os::Handler*>> listeners_; void NotifyDeviceBonded(hci::AddressWithType device); void NotifyDeviceBondFailed(hci::AddressWithType device); void NotifyDeviceBondFailed(hci::AddressWithType device, PairingResultOrFailure status); void NotifyDeviceUnbonded(hci::AddressWithType device); private: Loading
system/gd/security/pairing/classic_pairing_handler.cc +1 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ void ClassicPairingHandler::OnRegistrationComplete( } void ClassicPairingHandler::OnUnregistered() { std::move(complete_callback_).Run(GetRecord()->GetDevice().GetAddress()); std::move(complete_callback_).Run(GetRecord()->GetDevice().GetAddress(), last_status_); } void ClassicPairingHandler::OnConnectionOpen(std::unique_ptr<l2cap::classic::FixedChannel> fixed_channel) { Loading
system/gd/security/pairing/classic_pairing_handler.h +4 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ #include <utility> #include "l2cap/classic/l2cap_classic_module.h" #include "security/initial_informations.h" namespace bluetooth { namespace security { Loading @@ -37,7 +38,7 @@ class ClassicPairingHandler : public PairingHandler { ClassicPairingHandler(std::shared_ptr<l2cap::classic::FixedChannelManager> fixed_channel_manager, channel::SecurityManagerChannel* security_manager_channel, std::shared_ptr<record::SecurityRecord> record, os::Handler* security_handler, common::OnceCallback<void(hci::Address)> complete_callback) common::OnceCallback<void(hci::Address, PairingResultOrFailure)> complete_callback) : PairingHandler(security_manager_channel, std::move(record)), fixed_channel_manager_(std::move(fixed_channel_manager)), security_policy_(), security_handler_(security_handler), remote_io_capability_(kDefaultIoCapability), Loading Loading @@ -85,7 +86,8 @@ class ClassicPairingHandler : public PairingHandler { hci::OobDataPresent local_oob_present_ __attribute__((unused)); hci::AuthenticationRequirements local_authentication_requirements_ __attribute__((unused)); std::unique_ptr<l2cap::classic::FixedChannel> fixed_channel_{nullptr}; common::OnceCallback<void(hci::Address)> complete_callback_; common::OnceCallback<void(hci::Address, PairingResultOrFailure)> complete_callback_; PairingResultOrFailure last_status_; bool locally_initiated_ = false; }; Loading
system/gd/security/pairing/classic_pairing_handler_unittest.cc +9 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ #include "l2cap/classic/fixed_channel_manager_mock.h" #include "packet/raw_builder.h" #include "security/channel/security_manager_channel.h" #include "security/initial_informations.h" #include "security/smp_packets.h" #include "security/test/fake_hci_layer.h" Loading Loading @@ -99,7 +100,14 @@ class SecurityManagerChannelCallback : public ISecurityManagerChannelListener { pairing::ClassicPairingHandler* pairing_handler_ = nullptr; }; static void pairing_complete_callback(bluetooth::hci::Address address) {} static void pairing_complete_callback(bluetooth::hci::Address address, PairingResultOrFailure status) { // if (std::holds_alternative<PairingResult>(status)) { // auto result = status::get<PairingResult>(status); // } // if (std::holds_alternative<PairingFailure>(status)) { // auto failure = status::get<PairingFailure>(status); // } } class ClassicPairingHandlerTest : public ::testing::Test { protected: Loading