blob: f8a9d3974c63dd2054a1cd6573e0804739c7f1ca [file] [log] [blame]
Martin Brabham80854c22019-11-12 14:52:42 -08001/*
Martin Brabham605d6f12019-03-29 12:02:30 -07002 *
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 Brabham80854c22019-11-12 14:52:42 -080017 */
Martin Brabham605d6f12019-03-29 12:02:30 -070018#pragma once
19
Martin Brabham80854c22019-11-12 14:52:42 -080020#include "security/pairing/pairing_handler.h"
Martin Brabham605d6f12019-03-29 12:02:30 -070021
Martin Brabham80854c22019-11-12 14:52:42 -080022#include <utility>
Martin Brabham605d6f12019-03-29 12:02:30 -070023
Martin Brabham80854c22019-11-12 14:52:42 -080024#include "l2cap/classic/l2cap_classic_module.h"
Martin Brabham605d6f12019-03-29 12:02:30 -070025
26namespace bluetooth {
27namespace security {
28namespace pairing {
29
Martin Brabham80854c22019-11-12 14:52:42 -080030static constexpr hci::IoCapability kDefaultIoCapability = hci::IoCapability::DISPLAY_YES_NO;
31static constexpr hci::OobDataPresent kDefaultOobDataPresent = hci::OobDataPresent::NOT_PRESENT;
32static constexpr hci::AuthenticationRequirements kDefaultAuthenticationRequirements =
33 hci::AuthenticationRequirements::DEDICATED_BONDING_MITM_PROTECTION;
34
Martin Brabham605d6f12019-03-29 12:02:30 -070035class ClassicPairingHandler : public PairingHandler {
36 public:
Martin Brabham80854c22019-11-12 14:52:42 -080037 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 Brabham605d6f12019-03-29 12:02:30 -070047
Martin Brabham80854c22019-11-12 14:52:42 -080048 ~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 Brabham605d6f12019-03-29 12:02:30 -070090};
91
92} // namespace pairing
93} // namespace security
94} // namespace bluetooth