Loading system/gd/l2cap/classic/fixed_channel_manager.h +1 −0 Original line number Diff line number Diff line Loading @@ -142,6 +142,7 @@ class FixedChannelManager { FixedChannelManager(internal::FixedChannelServiceManagerImpl* service_manager, internal::LinkManager* link_manager, os::Handler* l2cap_layer_handler) : service_manager_(service_manager), link_manager_(link_manager), l2cap_layer_handler_(l2cap_layer_handler) {} internal::FixedChannelServiceManagerImpl* service_manager_ = nullptr; internal::LinkManager* link_manager_ = nullptr; os::Handler* l2cap_layer_handler_ = nullptr; Loading system/gd/security/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ filegroup { "internal/security_manager_impl.cc", "security_module.cc", ":BluetoothSecurityChannelSources", ":BluetoothSecurityPairingSources", ], } Loading @@ -22,5 +23,6 @@ filegroup { "test/fake_l2cap_test.cc", "test/pairing_handler_le_pair_test.cc", ":BluetoothSecurityChannelTestSources", ":BluetoothSecurityPairingTestSources", ], } system/gd/security/channel/security_manager_channel.cc +19 −67 Original line number Diff line number Diff line /****************************************************************************** /* * * Copyright 2019 The Android Open Source Project * Loading @@ -14,80 +14,32 @@ * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ #include "security_manager_channel.h" */ #include "security/channel/security_manager_channel.h" #include "security/smp_packets.h" using namespace bluetooth::hci; using namespace bluetooth::packet; using namespace bluetooth::security::channel; namespace bluetooth { namespace security { namespace channel { void SecurityManagerChannel::SendCommand(std::shared_ptr<hci::Device> device, std::unique_ptr<SecurityCommandBuilder> command) { void SecurityManagerChannel::OnCommandComplete(hci::CommandCompleteView packet) { ASSERT(packet.IsValid()); // TODO(optedoblivion): Verify HCI commands } void SecurityManagerChannel::SendCommand(std::unique_ptr<hci::SecurityCommandBuilder> command) { hci_security_interface_->EnqueueCommand( std::move(command), common::BindOnce(&SecurityManagerChannel::OnCommandComplete, common::Unretained(this)), handler_); } void SecurityManagerChannel::OnCommandComplete(CommandCompleteView packet) { ASSERT_LOG(packet.IsValid(), "Received invalid packet: %hx", packet.GetCommandOpCode()); // TODO(optedoblivion): Verify HCI commands } void SecurityManagerChannel::OnHciEventReceived(EventPacketView packet) { void SecurityManagerChannel::OnHciEventReceived(hci::EventPacketView packet) { ASSERT_LOG(listener_ != nullptr, "No listener set!"); std::shared_ptr<Device> device = nullptr; auto event = EventPacketView::Create(std::move(packet)); ASSERT_LOG(event.IsValid(), "Received invalid packet"); const hci::EventCode code = event.GetEventCode(); switch (code) { case hci::EventCode::CHANGE_CONNECTION_LINK_KEY_COMPLETE: listener_->OnChangeConnectionLinkKeyComplete(device, hci::ChangeConnectionLinkKeyCompleteView::Create(std::move(event))); break; case hci::EventCode::MASTER_LINK_KEY_COMPLETE: listener_->OnMasterLinkKeyComplete(device, hci::MasterLinkKeyCompleteView::Create(std::move(event))); break; case hci::EventCode::PIN_CODE_REQUEST: listener_->OnPinCodeRequest(device, hci::PinCodeRequestView::Create(std::move(event))); break; case hci::EventCode::LINK_KEY_REQUEST: listener_->OnLinkKeyRequest(device, hci::LinkKeyRequestView::Create(std::move(event))); break; case hci::EventCode::LINK_KEY_NOTIFICATION: listener_->OnLinkKeyNotification(device, hci::LinkKeyNotificationView::Create(std::move(event))); break; case hci::EventCode::IO_CAPABILITY_REQUEST: listener_->OnIoCapabilityRequest(device, hci::IoCapabilityRequestView::Create(std::move(event))); break; case hci::EventCode::IO_CAPABILITY_RESPONSE: listener_->OnIoCapabilityResponse(device, IoCapabilityResponseView::Create(std::move(event))); break; case hci::EventCode::SIMPLE_PAIRING_COMPLETE: listener_->OnSimplePairingComplete(device, SimplePairingCompleteView::Create(std::move(event))); break; case hci::EventCode::RETURN_LINK_KEYS: listener_->OnReturnLinkKeys(device, hci::ReturnLinkKeysView::Create(std::move(event))); break; case hci::EventCode::ENCRYPTION_CHANGE: listener_->OnEncryptionChange(device, hci::EncryptionChangeView::Create(std::move(event))); break; case hci::EventCode::ENCRYPTION_KEY_REFRESH_COMPLETE: listener_->OnEncryptionKeyRefreshComplete(device, hci::EncryptionKeyRefreshCompleteView::Create(std::move(event))); break; case hci::EventCode::REMOTE_OOB_DATA_REQUEST: listener_->OnRemoteOobDataRequest(device, hci::RemoteOobDataRequestView::Create(std::move(event))); break; case hci::EventCode::USER_PASSKEY_NOTIFICATION: listener_->OnUserPasskeyNotification(device, hci::UserPasskeyNotificationView::Create(std::move(event))); break; case hci::EventCode::KEYPRESS_NOTIFICATION: listener_->OnKeypressNotification(device, hci::KeypressNotificationView::Create(std::move(event))); break; default: ASSERT_LOG(false, "Invalid packet received: %hhx", code); break; } ASSERT(packet.IsValid()); listener_->OnHciEventReceived(packet); } } // namespace channel } // namespace security } // namespace bluetooth system/gd/security/channel/security_manager_channel.h +8 −31 Original line number Diff line number Diff line /****************************************************************************** /* * * Copyright 2019 The Android Open Source Project * Loading @@ -14,50 +14,28 @@ * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ */ #pragma once #include <memory> #include <vector> #include "hci/classic_device.h" #include "hci/address_with_type.h" #include "hci/hci_layer.h" #include "hci/hci_packets.h" #include "hci/security_interface.h" #include "security/smp_packets.h" namespace bluetooth { namespace security { namespace channel { using hci::CommandCompleteView; using hci::EventPacketView; using hci::SecurityCommandBuilder; using hci::SecurityCommandView; /** * Interface for listening to the channel for SMP commands. */ class ISecurityManagerChannelListener { public: virtual ~ISecurityManagerChannelListener() = default; virtual void OnChangeConnectionLinkKeyComplete(std::shared_ptr<hci::Device> device, hci::ChangeConnectionLinkKeyCompleteView packet) = 0; virtual void OnMasterLinkKeyComplete(std::shared_ptr<hci::Device> device, hci::MasterLinkKeyCompleteView packet) = 0; virtual void OnPinCodeRequest(std::shared_ptr<hci::Device> device, hci::PinCodeRequestView packet) = 0; virtual void OnLinkKeyRequest(std::shared_ptr<hci::Device> device, hci::LinkKeyRequestView packet) = 0; virtual void OnLinkKeyNotification(std::shared_ptr<hci::Device> device, hci::LinkKeyNotificationView packet) = 0; virtual void OnIoCapabilityRequest(std::shared_ptr<hci::Device> device, hci::IoCapabilityRequestView packet) = 0; virtual void OnIoCapabilityResponse(std::shared_ptr<hci::Device> device, hci::IoCapabilityResponseView packet) = 0; virtual void OnSimplePairingComplete(std::shared_ptr<hci::Device> device, hci::SimplePairingCompleteView packet) = 0; virtual void OnReturnLinkKeys(std::shared_ptr<hci::Device> device, hci::ReturnLinkKeysView packet) = 0; virtual void OnEncryptionChange(std::shared_ptr<hci::Device> device, hci::EncryptionChangeView packet) = 0; virtual void OnEncryptionKeyRefreshComplete(std::shared_ptr<hci::Device> device, hci::EncryptionKeyRefreshCompleteView packet) = 0; virtual void OnRemoteOobDataRequest(std::shared_ptr<hci::Device> device, hci::RemoteOobDataRequestView packet) = 0; virtual void OnUserPasskeyNotification(std::shared_ptr<hci::Device> device, hci::UserPasskeyNotificationView packet) = 0; virtual void OnKeypressNotification(std::shared_ptr<hci::Device> device, hci::KeypressNotificationView packet) = 0; virtual void OnHciEventReceived(hci::EventPacketView packet) = 0; }; /** Loading @@ -77,10 +55,9 @@ class SecurityManagerChannel { /** * Send a given SMP command over the SecurityManagerChannel * * @param device target where command will be sent * @param command smp command to send */ void SendCommand(std::shared_ptr<hci::Device> device, std::unique_ptr<SecurityCommandBuilder> command); void SendCommand(std::unique_ptr<hci::SecurityCommandBuilder> command); /** * Sets the listener to listen for channel events Loading @@ -96,14 +73,14 @@ class SecurityManagerChannel { * * @param event_packet */ void OnHciEventReceived(EventPacketView packet); void OnHciEventReceived(hci::EventPacketView packet); /** * Called when an HCI command is completed * * @param on_complete */ void OnCommandComplete(CommandCompleteView packet); void OnCommandComplete(hci::CommandCompleteView packet); private: ISecurityManagerChannelListener* listener_; Loading system/gd/security/channel/security_manager_channel_unittest.cc +215 −135 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
system/gd/l2cap/classic/fixed_channel_manager.h +1 −0 Original line number Diff line number Diff line Loading @@ -142,6 +142,7 @@ class FixedChannelManager { FixedChannelManager(internal::FixedChannelServiceManagerImpl* service_manager, internal::LinkManager* link_manager, os::Handler* l2cap_layer_handler) : service_manager_(service_manager), link_manager_(link_manager), l2cap_layer_handler_(l2cap_layer_handler) {} internal::FixedChannelServiceManagerImpl* service_manager_ = nullptr; internal::LinkManager* link_manager_ = nullptr; os::Handler* l2cap_layer_handler_ = nullptr; Loading
system/gd/security/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ filegroup { "internal/security_manager_impl.cc", "security_module.cc", ":BluetoothSecurityChannelSources", ":BluetoothSecurityPairingSources", ], } Loading @@ -22,5 +23,6 @@ filegroup { "test/fake_l2cap_test.cc", "test/pairing_handler_le_pair_test.cc", ":BluetoothSecurityChannelTestSources", ":BluetoothSecurityPairingTestSources", ], }
system/gd/security/channel/security_manager_channel.cc +19 −67 Original line number Diff line number Diff line /****************************************************************************** /* * * Copyright 2019 The Android Open Source Project * Loading @@ -14,80 +14,32 @@ * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ #include "security_manager_channel.h" */ #include "security/channel/security_manager_channel.h" #include "security/smp_packets.h" using namespace bluetooth::hci; using namespace bluetooth::packet; using namespace bluetooth::security::channel; namespace bluetooth { namespace security { namespace channel { void SecurityManagerChannel::SendCommand(std::shared_ptr<hci::Device> device, std::unique_ptr<SecurityCommandBuilder> command) { void SecurityManagerChannel::OnCommandComplete(hci::CommandCompleteView packet) { ASSERT(packet.IsValid()); // TODO(optedoblivion): Verify HCI commands } void SecurityManagerChannel::SendCommand(std::unique_ptr<hci::SecurityCommandBuilder> command) { hci_security_interface_->EnqueueCommand( std::move(command), common::BindOnce(&SecurityManagerChannel::OnCommandComplete, common::Unretained(this)), handler_); } void SecurityManagerChannel::OnCommandComplete(CommandCompleteView packet) { ASSERT_LOG(packet.IsValid(), "Received invalid packet: %hx", packet.GetCommandOpCode()); // TODO(optedoblivion): Verify HCI commands } void SecurityManagerChannel::OnHciEventReceived(EventPacketView packet) { void SecurityManagerChannel::OnHciEventReceived(hci::EventPacketView packet) { ASSERT_LOG(listener_ != nullptr, "No listener set!"); std::shared_ptr<Device> device = nullptr; auto event = EventPacketView::Create(std::move(packet)); ASSERT_LOG(event.IsValid(), "Received invalid packet"); const hci::EventCode code = event.GetEventCode(); switch (code) { case hci::EventCode::CHANGE_CONNECTION_LINK_KEY_COMPLETE: listener_->OnChangeConnectionLinkKeyComplete(device, hci::ChangeConnectionLinkKeyCompleteView::Create(std::move(event))); break; case hci::EventCode::MASTER_LINK_KEY_COMPLETE: listener_->OnMasterLinkKeyComplete(device, hci::MasterLinkKeyCompleteView::Create(std::move(event))); break; case hci::EventCode::PIN_CODE_REQUEST: listener_->OnPinCodeRequest(device, hci::PinCodeRequestView::Create(std::move(event))); break; case hci::EventCode::LINK_KEY_REQUEST: listener_->OnLinkKeyRequest(device, hci::LinkKeyRequestView::Create(std::move(event))); break; case hci::EventCode::LINK_KEY_NOTIFICATION: listener_->OnLinkKeyNotification(device, hci::LinkKeyNotificationView::Create(std::move(event))); break; case hci::EventCode::IO_CAPABILITY_REQUEST: listener_->OnIoCapabilityRequest(device, hci::IoCapabilityRequestView::Create(std::move(event))); break; case hci::EventCode::IO_CAPABILITY_RESPONSE: listener_->OnIoCapabilityResponse(device, IoCapabilityResponseView::Create(std::move(event))); break; case hci::EventCode::SIMPLE_PAIRING_COMPLETE: listener_->OnSimplePairingComplete(device, SimplePairingCompleteView::Create(std::move(event))); break; case hci::EventCode::RETURN_LINK_KEYS: listener_->OnReturnLinkKeys(device, hci::ReturnLinkKeysView::Create(std::move(event))); break; case hci::EventCode::ENCRYPTION_CHANGE: listener_->OnEncryptionChange(device, hci::EncryptionChangeView::Create(std::move(event))); break; case hci::EventCode::ENCRYPTION_KEY_REFRESH_COMPLETE: listener_->OnEncryptionKeyRefreshComplete(device, hci::EncryptionKeyRefreshCompleteView::Create(std::move(event))); break; case hci::EventCode::REMOTE_OOB_DATA_REQUEST: listener_->OnRemoteOobDataRequest(device, hci::RemoteOobDataRequestView::Create(std::move(event))); break; case hci::EventCode::USER_PASSKEY_NOTIFICATION: listener_->OnUserPasskeyNotification(device, hci::UserPasskeyNotificationView::Create(std::move(event))); break; case hci::EventCode::KEYPRESS_NOTIFICATION: listener_->OnKeypressNotification(device, hci::KeypressNotificationView::Create(std::move(event))); break; default: ASSERT_LOG(false, "Invalid packet received: %hhx", code); break; } ASSERT(packet.IsValid()); listener_->OnHciEventReceived(packet); } } // namespace channel } // namespace security } // namespace bluetooth
system/gd/security/channel/security_manager_channel.h +8 −31 Original line number Diff line number Diff line /****************************************************************************** /* * * Copyright 2019 The Android Open Source Project * Loading @@ -14,50 +14,28 @@ * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ */ #pragma once #include <memory> #include <vector> #include "hci/classic_device.h" #include "hci/address_with_type.h" #include "hci/hci_layer.h" #include "hci/hci_packets.h" #include "hci/security_interface.h" #include "security/smp_packets.h" namespace bluetooth { namespace security { namespace channel { using hci::CommandCompleteView; using hci::EventPacketView; using hci::SecurityCommandBuilder; using hci::SecurityCommandView; /** * Interface for listening to the channel for SMP commands. */ class ISecurityManagerChannelListener { public: virtual ~ISecurityManagerChannelListener() = default; virtual void OnChangeConnectionLinkKeyComplete(std::shared_ptr<hci::Device> device, hci::ChangeConnectionLinkKeyCompleteView packet) = 0; virtual void OnMasterLinkKeyComplete(std::shared_ptr<hci::Device> device, hci::MasterLinkKeyCompleteView packet) = 0; virtual void OnPinCodeRequest(std::shared_ptr<hci::Device> device, hci::PinCodeRequestView packet) = 0; virtual void OnLinkKeyRequest(std::shared_ptr<hci::Device> device, hci::LinkKeyRequestView packet) = 0; virtual void OnLinkKeyNotification(std::shared_ptr<hci::Device> device, hci::LinkKeyNotificationView packet) = 0; virtual void OnIoCapabilityRequest(std::shared_ptr<hci::Device> device, hci::IoCapabilityRequestView packet) = 0; virtual void OnIoCapabilityResponse(std::shared_ptr<hci::Device> device, hci::IoCapabilityResponseView packet) = 0; virtual void OnSimplePairingComplete(std::shared_ptr<hci::Device> device, hci::SimplePairingCompleteView packet) = 0; virtual void OnReturnLinkKeys(std::shared_ptr<hci::Device> device, hci::ReturnLinkKeysView packet) = 0; virtual void OnEncryptionChange(std::shared_ptr<hci::Device> device, hci::EncryptionChangeView packet) = 0; virtual void OnEncryptionKeyRefreshComplete(std::shared_ptr<hci::Device> device, hci::EncryptionKeyRefreshCompleteView packet) = 0; virtual void OnRemoteOobDataRequest(std::shared_ptr<hci::Device> device, hci::RemoteOobDataRequestView packet) = 0; virtual void OnUserPasskeyNotification(std::shared_ptr<hci::Device> device, hci::UserPasskeyNotificationView packet) = 0; virtual void OnKeypressNotification(std::shared_ptr<hci::Device> device, hci::KeypressNotificationView packet) = 0; virtual void OnHciEventReceived(hci::EventPacketView packet) = 0; }; /** Loading @@ -77,10 +55,9 @@ class SecurityManagerChannel { /** * Send a given SMP command over the SecurityManagerChannel * * @param device target where command will be sent * @param command smp command to send */ void SendCommand(std::shared_ptr<hci::Device> device, std::unique_ptr<SecurityCommandBuilder> command); void SendCommand(std::unique_ptr<hci::SecurityCommandBuilder> command); /** * Sets the listener to listen for channel events Loading @@ -96,14 +73,14 @@ class SecurityManagerChannel { * * @param event_packet */ void OnHciEventReceived(EventPacketView packet); void OnHciEventReceived(hci::EventPacketView packet); /** * Called when an HCI command is completed * * @param on_complete */ void OnCommandComplete(CommandCompleteView packet); void OnCommandComplete(hci::CommandCompleteView packet); private: ISecurityManagerChannelListener* listener_; Loading
system/gd/security/channel/security_manager_channel_unittest.cc +215 −135 File changed.Preview size limit exceeded, changes collapsed. Show changes