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/le/dynamic_channel_manager.h"
21 #include "l2cap/le/fixed_channel_manager.h"
22 #include "l2cap/le/link_property_listener.h"
23 #include "l2cap/le/security_enforcement_interface.h"
24 #include "module.h"
25 
26 namespace bluetooth {
27 
28 namespace security {
29 class SecurityModule;
30 }
31 
32 namespace l2cap {
33 namespace le {
34 
35 class L2capLeModule : public bluetooth::Module {
36  public:
37   L2capLeModule();
38   L2capLeModule(const L2capLeModule&) = delete;
39   L2capLeModule& operator=(const L2capLeModule&) = delete;
40 
41   virtual ~L2capLeModule();
42 
43   /**
44    * Get the api to the LE fixed channel l2cap module
45    */
46   virtual std::unique_ptr<FixedChannelManager> GetFixedChannelManager();
47 
48   /**
49    * Get the api to the LE dynamic channel l2cap module
50    */
51   virtual std::unique_ptr<DynamicChannelManager> GetDynamicChannelManager();
52 
53   static const ModuleFactory Factory;
54 
55  protected:
56   void ListDependencies(ModuleList* list) const override;
57 
58   void Start() override;
59 
60   void Stop() override;
61 
62   std::string ToString() const override;
63 
64  private:
65   struct impl;
66   std::unique_ptr<impl> pimpl_;
67 
68   friend security::SecurityModule;
69 
70   /**
71    * Only for the LE security module to inject functionality to enforce security level for a connection. When LE
72    * security module is stopping, inject nullptr. Note: We expect this only to be called during stack startup. This is
73    * not synchronized.
74    */
75   virtual void InjectSecurityEnforcementInterface(SecurityEnforcementInterface* security_enforcement_interface);
76 
77   /**
78    * Set the link property listener.
79    * This is not synchronized.
80    */
81   virtual void SetLinkPropertyListener(os::Handler* handler, LinkPropertyListener* listener);
82 };
83 
84 }  // namespace le
85 }  // namespace l2cap
86 }  // namespace bluetooth
87