• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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{};
34 
EnsureEncrypted()35   void EnsureEncrypted() override {}
36 
Release()37   void Release() override {
38     // TODO(optedoblivion): Simulate the delay
39     listener_->OnLinkDisconnected(address_);
40   }
Disconnect()41   void Disconnect() override {
42     listener_->OnLinkDisconnected(address_);
43   }
GetAclHandle()44   uint16_t GetAclHandle() override {
45     return 0;
46   }
47 
48  private:
49   l2cap::classic::LinkSecurityInterfaceListener* listener_ = nullptr;
50   hci::Address address_;
51 };
52 
53 class FakeSecurityInterface : public l2cap::classic::SecurityInterface {
54  public:
FakeSecurityInterface(os::Handler * handler,l2cap::classic::LinkSecurityInterfaceListener * listener)55   FakeSecurityInterface(os::Handler* handler, l2cap::classic::LinkSecurityInterfaceListener* listener)
56       : handler_(handler), listener_(listener) {}
~FakeSecurityInterface()57   ~FakeSecurityInterface() {}
InitiateConnectionForSecurity(hci::Address remote)58   void InitiateConnectionForSecurity(hci::Address remote) override {
59     listener_->OnLinkConnected(std::make_unique<FakeLinkSecurityInterface>(listener_, remote));
60   };
Unregister()61   void Unregister() override {}
62 
63  private:
64   os::Handler* handler_ __attribute__((unused));
65   l2cap::classic::LinkSecurityInterfaceListener* listener_ __attribute__((unused));
66 };
67 
68 }  // namespace security
69 }  // namespace bluetooth
70