1 /* 2 * 3 * Copyright 2019 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 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 * 17 */ 18 #pragma once 19 20 #include <utility> 21 22 #include "hci/address_with_type.h" 23 #include "hci/hci_packets.h" 24 #include "security/channel/security_manager_channel.h" 25 #include "security/record/security_record.h" 26 #include "security/smp_packets.h" 27 #include "security/ui.h" 28 29 namespace bluetooth { 30 namespace security { 31 namespace pairing { 32 33 /** 34 * Base structure for handling pairing events. 35 * 36 * <p>Extend this class in order to implement a new style of pairing. 37 */ 38 class PairingHandler : public UICallbacks { 39 public: PairingHandler(channel::SecurityManagerChannel * security_manager_channel,std::shared_ptr<record::SecurityRecord> record)40 PairingHandler(channel::SecurityManagerChannel* security_manager_channel, 41 std::shared_ptr<record::SecurityRecord> record) 42 : security_manager_channel_(security_manager_channel), record_(std::move(record)) {} 43 virtual ~PairingHandler() = default; 44 45 // Classic 46 virtual void Initiate(bool locally_initiated, hci::IoCapability io_capability, hci::OobDataPresent oob_present, 47 hci::AuthenticationRequirements auth_requirements) = 0; // This is for local initiated only 48 virtual void Cancel() = 0; 49 virtual void OnReceive(hci::ChangeConnectionLinkKeyCompleteView packet) = 0; 50 virtual void OnReceive(hci::MasterLinkKeyCompleteView packet) = 0; 51 virtual void OnReceive(hci::PinCodeRequestView packet) = 0; 52 virtual void OnReceive(hci::LinkKeyRequestView packet) = 0; 53 virtual void OnReceive(hci::LinkKeyNotificationView packet) = 0; 54 virtual void OnReceive(hci::IoCapabilityRequestView packet) = 0; 55 virtual void OnReceive(hci::IoCapabilityResponseView packet) = 0; 56 virtual void OnReceive(hci::SimplePairingCompleteView packet) = 0; 57 virtual void OnReceive(hci::ReturnLinkKeysView packet) = 0; 58 virtual void OnReceive(hci::EncryptionChangeView packet) = 0; 59 virtual void OnReceive(hci::EncryptionKeyRefreshCompleteView packet) = 0; 60 virtual void OnReceive(hci::RemoteOobDataRequestView packet) = 0; 61 virtual void OnReceive(hci::UserPasskeyNotificationView packet) = 0; 62 virtual void OnReceive(hci::KeypressNotificationView packet) = 0; 63 virtual void OnReceive(hci::UserConfirmationRequestView packet) = 0; 64 virtual void OnReceive(hci::UserPasskeyRequestView packet) = 0; 65 66 virtual void OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) = 0; 67 virtual void OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) = 0; 68 virtual void OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) = 0; 69 70 protected: GetRecord()71 std::shared_ptr<record::SecurityRecord> GetRecord() { 72 return record_; 73 } GetChannel()74 channel::SecurityManagerChannel* GetChannel() { 75 return security_manager_channel_; 76 } 77 78 private: 79 channel::SecurityManagerChannel* security_manager_channel_ __attribute__((unused)); 80 std::shared_ptr<record::SecurityRecord> record_ __attribute__((unused)); 81 }; 82 83 } // namespace pairing 84 } // namespace security 85 } // namespace bluetooth 86