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 <neighbor/name_db.h> 21 #include <utility> 22 23 #include "hci/address_with_type.h" 24 #include "hci/hci_packets.h" 25 #include "neighbor/name_db.h" 26 #include "security/channel/security_manager_channel.h" 27 #include "security/pairing/oob_data.h" 28 #include "security/record/security_record.h" 29 #include "security/smp_packets.h" 30 #include "security/ui.h" 31 32 namespace bluetooth { 33 namespace security { 34 namespace pairing { 35 36 /** 37 * Base structure for handling pairing events. 38 * 39 * <p>Extend this class in order to implement a new style of pairing. 40 */ 41 class PairingHandler : public UICallbacks { 42 public: PairingHandler(channel::SecurityManagerChannel * security_manager_channel,std::shared_ptr<record::SecurityRecord> record,neighbor::NameDbModule * name_db_module)43 PairingHandler( 44 channel::SecurityManagerChannel* security_manager_channel, 45 std::shared_ptr<record::SecurityRecord> record, 46 neighbor::NameDbModule* name_db_module) 47 : security_manager_channel_(security_manager_channel), 48 record_(std::move(record)), 49 name_db_module_(name_db_module) {} 50 ~PairingHandler() = default; 51 52 // Classic 53 virtual void Initiate( 54 bool locally_initiated, 55 hci::IoCapability io_capability, 56 hci::AuthenticationRequirements auth_requirements, 57 OobData local_p192_oob_data, 58 OobData local_p256_oob_data) = 0; 59 virtual void Cancel() = 0; 60 virtual void OnReceive(hci::ChangeConnectionLinkKeyCompleteView packet) = 0; 61 virtual void OnReceive(hci::CentralLinkKeyCompleteView packet) = 0; 62 virtual void OnReceive(hci::PinCodeRequestView packet) = 0; 63 virtual void OnReceive(hci::LinkKeyRequestView packet) = 0; 64 virtual void OnReceive(hci::LinkKeyNotificationView packet) = 0; 65 virtual void OnReceive(hci::IoCapabilityRequestView packet) = 0; 66 virtual void OnReceive(hci::IoCapabilityResponseView packet) = 0; 67 virtual void OnReceive(hci::SimplePairingCompleteView packet) = 0; 68 virtual void OnReceive(hci::ReturnLinkKeysView packet) = 0; 69 virtual void OnReceive(hci::EncryptionChangeView packet) = 0; 70 virtual void OnReceive(hci::EncryptionKeyRefreshCompleteView packet) = 0; 71 virtual void OnReceive(hci::RemoteOobDataRequestView packet) = 0; 72 virtual void OnReceive(hci::UserPasskeyNotificationView packet) = 0; 73 virtual void OnReceive(hci::KeypressNotificationView packet) = 0; 74 virtual void OnReceive(hci::UserConfirmationRequestView packet) = 0; 75 virtual void OnReceive(hci::UserPasskeyRequestView packet) = 0; 76 77 virtual void OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) = 0; 78 virtual void OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) = 0; 79 virtual void OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) = 0; 80 virtual void OnPinEntry(const bluetooth::hci::AddressWithType& address, std::vector<uint8_t> pin) override = 0; 81 82 protected: GetRecord()83 std::shared_ptr<record::SecurityRecord> GetRecord() { 84 return record_; 85 } GetChannel()86 channel::SecurityManagerChannel* GetChannel() { 87 return security_manager_channel_; 88 } GetNameDbModule()89 neighbor::NameDbModule* GetNameDbModule() { 90 return name_db_module_; 91 } 92 93 private: 94 channel::SecurityManagerChannel* security_manager_channel_ __attribute__((unused)); 95 std::shared_ptr<record::SecurityRecord> record_ __attribute__((unused)); 96 neighbor::NameDbModule* name_db_module_; 97 }; 98 99 } // namespace pairing 100 } // namespace security 101 } // namespace bluetooth 102