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 19 #pragma once 20 21 #include "hci/address_with_type.h" 22 23 namespace bluetooth { 24 namespace security { 25 26 // Through this interface we talk to the user, asking for confirmations/acceptance. 27 class UI { 28 public: ~UI()29 virtual ~UI(){}; 30 31 /* Remote LE device tries to initiate pairing, ask user to confirm */ 32 virtual void DisplayPairingPrompt(const bluetooth::hci::AddressWithType& address, std::string name) = 0; 33 34 /* Remove the pairing prompt from DisplayPairingPrompt, i.e. remote device disconnected, or some application requested 35 * bond with this device */ 36 virtual void Cancel(const bluetooth::hci::AddressWithType& address) = 0; 37 38 /* Display value for Comprision, user responds yes/no */ 39 virtual void DisplayConfirmValue(const bluetooth::hci::AddressWithType& address, std::string name, 40 uint32_t numeric_value) = 0; 41 42 /* Display Yes/No dialog, Classic pairing, numeric comparison with NoInputNoOutput device */ 43 virtual void DisplayYesNoDialog(const bluetooth::hci::AddressWithType& address, std::string name) = 0; 44 45 /* Display a dialog box that will let user enter the Passkey */ 46 virtual void DisplayEnterPasskeyDialog(const bluetooth::hci::AddressWithType& address, std::string name) = 0; 47 48 /* Present the passkey value to the user, user compares with other device */ 49 virtual void DisplayPasskey(const bluetooth::hci::AddressWithType& address, std::string name, uint32_t passkey) = 0; 50 }; 51 52 /* Through this interface, UI provides us with user choices. */ 53 class UICallbacks { 54 public: 55 virtual ~UICallbacks() = default; 56 57 /* User accepted pairing prompt */ 58 virtual void OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address, bool confirmed) = 0; 59 60 /* User confirmed that displayed value matches the value on the other device */ 61 virtual void OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) = 0; 62 63 /* User typed the value displayed on the other device. This is either Passkey or the Confirm value */ 64 virtual void OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) = 0; 65 }; 66 67 } // namespace security 68 } // namespace bluetooth 69