Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 1 | /* |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright 2019 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License") override; |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 17 | */ |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 18 | #pragma once |
| 19 | |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 20 | #include "security/pairing/pairing_handler.h" |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 21 | |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 22 | #include <utility> |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 23 | |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 24 | #include "l2cap/classic/l2cap_classic_module.h" |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 25 | |
| 26 | namespace bluetooth { |
| 27 | namespace security { |
| 28 | namespace pairing { |
| 29 | |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 30 | static constexpr hci::IoCapability kDefaultIoCapability = hci::IoCapability::DISPLAY_YES_NO; |
| 31 | static constexpr hci::OobDataPresent kDefaultOobDataPresent = hci::OobDataPresent::NOT_PRESENT; |
| 32 | static constexpr hci::AuthenticationRequirements kDefaultAuthenticationRequirements = |
| 33 | hci::AuthenticationRequirements::DEDICATED_BONDING_MITM_PROTECTION; |
| 34 | |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 35 | class ClassicPairingHandler : public PairingHandler { |
| 36 | public: |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 37 | ClassicPairingHandler(std::shared_ptr<l2cap::classic::FixedChannelManager> fixed_channel_manager, |
| 38 | channel::SecurityManagerChannel* security_manager_channel, |
| 39 | std::shared_ptr<record::SecurityRecord> record, os::Handler* security_handler, |
| 40 | common::OnceCallback<void(hci::Address)> complete_callback) |
| 41 | : PairingHandler(security_manager_channel, std::move(record)), |
| 42 | fixed_channel_manager_(std::move(fixed_channel_manager)), security_policy_(), |
| 43 | security_handler_(security_handler), remote_io_capability_(kDefaultIoCapability), |
| 44 | local_io_capability_(kDefaultIoCapability), local_oob_present_(kDefaultOobDataPresent), |
| 45 | local_authentication_requirements_(kDefaultAuthenticationRequirements), |
| 46 | complete_callback_(std::move(complete_callback)) {} |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 47 | |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 48 | ~ClassicPairingHandler() override = default; |
| 49 | |
| 50 | void Initiate(bool locally_initiated, hci::IoCapability io_capability, hci::OobDataPresent oob_present, |
| 51 | hci::AuthenticationRequirements auth_requirements) override; |
| 52 | void Cancel() override; |
| 53 | |
| 54 | void OnReceive(hci::ChangeConnectionLinkKeyCompleteView packet) override; |
| 55 | void OnReceive(hci::MasterLinkKeyCompleteView packet) override; |
| 56 | void OnReceive(hci::PinCodeRequestView packet) override; |
| 57 | void OnReceive(hci::LinkKeyRequestView packet) override; |
| 58 | void OnReceive(hci::LinkKeyNotificationView packet) override; |
| 59 | void OnReceive(hci::IoCapabilityRequestView packet) override; |
| 60 | void OnReceive(hci::IoCapabilityResponseView packet) override; |
| 61 | void OnReceive(hci::SimplePairingCompleteView packet) override; |
| 62 | void OnReceive(hci::ReturnLinkKeysView packet) override; |
| 63 | void OnReceive(hci::EncryptionChangeView packet) override; |
| 64 | void OnReceive(hci::EncryptionKeyRefreshCompleteView packet) override; |
| 65 | void OnReceive(hci::RemoteOobDataRequestView packet) override; |
| 66 | void OnReceive(hci::UserPasskeyNotificationView packet) override; |
| 67 | void OnReceive(hci::KeypressNotificationView packet) override; |
| 68 | void OnReceive(hci::UserConfirmationRequestView packet) override; |
| 69 | void OnReceive(hci::UserPasskeyRequestView packet) override; |
| 70 | |
| 71 | private: |
| 72 | void OnRegistrationComplete(l2cap::classic::FixedChannelManager::RegistrationResult result, |
| 73 | std::unique_ptr<l2cap::classic::FixedChannelService> fixed_channel_service); |
| 74 | void OnUnregistered(); |
| 75 | void OnConnectionOpen(std::unique_ptr<l2cap::classic::FixedChannel> fixed_channel); |
| 76 | void OnConnectionFail(l2cap::classic::FixedChannelManager::ConnectionResult result); |
| 77 | void OnConnectionClose(hci::ErrorCode error_code); |
| 78 | |
| 79 | std::shared_ptr<l2cap::classic::FixedChannelManager> fixed_channel_manager_; |
| 80 | std::unique_ptr<l2cap::classic::FixedChannelService> fixed_channel_service_{nullptr}; |
| 81 | l2cap::SecurityPolicy security_policy_ __attribute__((unused)); |
| 82 | os::Handler* security_handler_ __attribute__((unused)); |
| 83 | hci::IoCapability remote_io_capability_ __attribute__((unused)); |
| 84 | hci::IoCapability local_io_capability_ __attribute__((unused)); |
| 85 | hci::OobDataPresent local_oob_present_ __attribute__((unused)); |
| 86 | hci::AuthenticationRequirements local_authentication_requirements_ __attribute__((unused)); |
| 87 | std::unique_ptr<l2cap::classic::FixedChannel> fixed_channel_{nullptr}; |
| 88 | common::OnceCallback<void(hci::Address)> complete_callback_; |
| 89 | bool locally_initiated_ = false; |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | } // namespace pairing |
| 93 | } // namespace security |
| 94 | } // namespace bluetooth |