1 /*
2  * Copyright 2019 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 #pragma once
17 
18 #include <memory>
19 
20 #include "l2cap/classic/dynamic_channel_manager.h"
21 #include "l2cap/classic/fixed_channel_manager.h"
22 #include "l2cap/classic/link_property_listener.h"
23 #include "l2cap/classic/link_security_interface.h"
24 #include "l2cap/classic/security_enforcement_interface.h"
25 #include "module.h"
26 
27 namespace bluetooth {
28 
29 namespace security {
30 class SecurityModule;
31 }
32 
33 namespace l2cap {
34 namespace classic {
35 
36 class L2capClassicModule : public bluetooth::Module {
37  public:
38   L2capClassicModule();
39   L2capClassicModule(const L2capClassicModule&) = delete;
40   L2capClassicModule& operator=(const L2capClassicModule&) = delete;
41 
42   virtual ~L2capClassicModule();
43 
44   /**
45    * Get the api to the classic fixed channel l2cap module
46    */
47   virtual std::unique_ptr<FixedChannelManager> GetFixedChannelManager();
48 
49   /**
50    * Get the api to the classic dynamic channel l2cap module
51    */
52   virtual std::unique_ptr<DynamicChannelManager> GetDynamicChannelManager();
53 
54   static const ModuleFactory Factory;
55   /**
56    * Only for the classic security module to inject functionality to enforce security level for a connection. When
57    * classic security module is stopping, inject nullptr. Note: We expect this only to be called during stack startup.
58    * This is not synchronized.
59    */
60   virtual void InjectSecurityEnforcementInterface(SecurityEnforcementInterface* security_enforcement_interface);
61 
62   /**
63    * Get the interface for Security Module to access link function.
64    * Security Module needs to register the callback for ACL link connected and disconnected. When connected, either by
65    * incoming or by outgoing connection request, Security Module receives a LinkSecurityInterface proxy, which can be
66    * used to access some link functionlities.
67    */
68   virtual SecurityInterface* GetSecurityInterface(os::Handler* handler, LinkSecurityInterfaceListener* listener);
69 
70   friend security::SecurityModule;
71 
72   /**
73    * Set the link property listener.
74    * This is not synchronized.
75    */
76   virtual void SetLinkPropertyListener(os::Handler* handler, LinkPropertyListener* listener);
77 
78  protected:
79   void ListDependencies(ModuleList* list) const override;
80 
81   void Start() override;
82 
83   void Stop() override;
84 
85   std::string ToString() const override;
86 
87   DumpsysDataFinisher GetDumpsysData(flatbuffers::FlatBufferBuilder* builder) const override;  // Module
88 
89  private:
90   struct impl;
91   std::unique_ptr<impl> pimpl_;
92 };
93 
94 }  // namespace classic
95 }  // namespace l2cap
96 }  // namespace bluetooth
97