1 /* 2 * Copyright 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <memory> 20 21 #include "hci/address.h" 22 23 namespace bluetooth { 24 namespace l2cap { 25 namespace classic { 26 27 /** 28 * This is a proxy for Security Module to unregister itself, or to initiate link connection. 29 */ 30 class SecurityInterface { 31 public: 32 virtual ~SecurityInterface() = default; 33 34 /** 35 * Page a remote device for ACL connection, when Security Module needs it for pairing. When the remote device is 36 * connected, Security Module will receive a callback through LinkSecurityInterfaceListener. 37 */ 38 virtual void InitiateConnectionForSecurity(hci::Address remote) = 0; 39 40 /** 41 * Unregister the security interface and the LinkSecurityInterfaceListener. 42 */ 43 virtual void Unregister() = 0; 44 }; 45 46 /** 47 * This is a proxy for Security Module to access some link function. This object is passed to Security Module when a 48 * link is established. 49 */ 50 class LinkSecurityInterface { 51 public: 52 virtual ~LinkSecurityInterface() = default; 53 54 virtual hci::Address GetRemoteAddress() = 0; 55 56 /** 57 * Hold the ACL link connection. Don't disconnect the link until Release() is called. 58 */ 59 virtual void Hold() = 0; 60 61 /** 62 * Release the ACL link connection. This doesn't guarantee link disconnection, if other L2cap services are using the 63 * link. 64 */ 65 virtual void Release() = 0; 66 67 /** 68 * Force the ACL link to disconnect. 69 */ 70 virtual void Disconnect() = 0; 71 72 /** 73 * Initiate pairing to HCI layer. 74 */ 75 virtual void EnsureAuthenticated() = 0; 76 }; 77 78 class LinkSecurityInterfaceListener { 79 public: 80 virtual ~LinkSecurityInterfaceListener() = default; 81 82 /** 83 * Each time when an ACL link is connected, security manager receives this callback to use LinkSecurityInterface 84 * functions. 85 */ OnLinkConnected(std::unique_ptr<LinkSecurityInterface>)86 virtual void OnLinkConnected(std::unique_ptr<LinkSecurityInterface>) {} 87 88 /** 89 * When an ACL link is disconnected, security manager receives this callback. The corresponding LinkSecurityInterface 90 * is invalidated then. 91 * @param remote 92 */ OnLinkDisconnected(hci::Address remote)93 virtual void OnLinkDisconnected(hci::Address remote) {} 94 }; 95 96 } // namespace classic 97 } // namespace l2cap 98 } // namespace bluetooth 99