1 /*
2  *
3  *  Copyright 2020 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 #include "common/bind.h"
19 #include "os/handler.h"
20 
21 namespace bluetooth {
22 namespace security {
23 
24 class FakeLinkSecurityInterface : public l2cap::classic::LinkSecurityInterface {
25  public:
FakeLinkSecurityInterface(l2cap::classic::LinkSecurityInterfaceListener * listener,hci::Address address)26   FakeLinkSecurityInterface(l2cap::classic::LinkSecurityInterfaceListener* listener, hci::Address address)
27       : listener_(listener), address_(address) {}
28 
GetRemoteAddress()29   hci::Address GetRemoteAddress() {
30     return address_;
31   }
Hold()32   void Hold() override {}
EnsureAuthenticated()33   void EnsureAuthenticated() override{};
Release()34   void Release() override {
35     // TODO(optedoblivion): Simulate the delay
36     listener_->OnLinkDisconnected(address_);
37   }
Disconnect()38   void Disconnect() override {
39     listener_->OnLinkDisconnected(address_);
40   }
41 
42  private:
43   l2cap::classic::LinkSecurityInterfaceListener* listener_ = nullptr;
44   hci::Address address_;
45 };
46 
47 class FakeSecurityInterface : public l2cap::classic::SecurityInterface {
48  public:
FakeSecurityInterface(os::Handler * handler,l2cap::classic::LinkSecurityInterfaceListener * listener)49   FakeSecurityInterface(os::Handler* handler, l2cap::classic::LinkSecurityInterfaceListener* listener)
50       : handler_(handler), listener_(listener) {}
~FakeSecurityInterface()51   ~FakeSecurityInterface() {}
InitiateConnectionForSecurity(hci::Address remote)52   void InitiateConnectionForSecurity(hci::Address remote) override {
53     listener_->OnLinkConnected(std::make_unique<FakeLinkSecurityInterface>(listener_, remote));
54   };
Unregister()55   void Unregister() override {}
56 
57  private:
58   os::Handler* handler_ __attribute__((unused));
59   l2cap::classic::LinkSecurityInterfaceListener* listener_ __attribute__((unused));
60 };
61 
62 }  // namespace security
63 }  // namespace bluetooth
64