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 
17 #pragma once
18 
19 #include "common/contextual_callback.h"
20 #include "hci/address.h"
21 #include "hci/hci_packets.h"
22 #include "module.h"
23 #include "os/handler.h"
24 
25 namespace bluetooth {
26 namespace hci {
27 
28 class Controller : public Module {
29  public:
30   Controller();
31   virtual ~Controller();
32   DISALLOW_COPY_AND_ASSIGN(Controller);
33 
34   using CompletedAclPacketsCallback =
35       common::ContextualCallback<void(uint16_t /* handle */, uint16_t /* num_packets */)>;
36   virtual void RegisterCompletedAclPacketsCallback(CompletedAclPacketsCallback cb);
37 
38   virtual void UnregisterCompletedAclPacketsCallback();
39 
40   virtual std::string GetControllerLocalName() const;
41 
42   virtual LocalVersionInformation GetControllerLocalVersionInformation() const;
43 
44   virtual std::array<uint8_t, 64> GetControllerLocalSupportedCommands() const;
45 
46   virtual uint64_t GetControllerLocalSupportedFeatures() const;
47 
48   virtual uint8_t GetControllerLocalExtendedFeaturesMaxPageNumber() const;
49 
50   virtual uint64_t GetControllerLocalExtendedFeatures(uint8_t page_number) const;
51 
52   virtual uint16_t GetControllerAclPacketLength() const;
53 
54   virtual uint16_t GetControllerNumAclPacketBuffers() const;
55 
56   virtual uint8_t GetControllerScoPacketLength() const;
57 
58   virtual uint16_t GetControllerNumScoPacketBuffers() const;
59 
60   virtual Address GetControllerMacAddress() const;
61 
62   virtual void SetEventMask(uint64_t event_mask);
63 
64   virtual void Reset();
65 
66   virtual void SetEventFilterClearAll();
67 
68   virtual void SetEventFilterInquiryResultAllDevices();
69 
70   virtual void SetEventFilterInquiryResultClassOfDevice(ClassOfDevice class_of_device,
71                                                         ClassOfDevice class_of_device_mask);
72 
73   virtual void SetEventFilterInquiryResultAddress(Address address);
74 
75   virtual void SetEventFilterConnectionSetupAllDevices(AutoAcceptFlag auto_accept_flag);
76 
77   virtual void SetEventFilterConnectionSetupClassOfDevice(ClassOfDevice class_of_device,
78                                                           ClassOfDevice class_of_device_mask,
79                                                           AutoAcceptFlag auto_accept_flag);
80 
81   virtual void SetEventFilterConnectionSetupAddress(Address address, AutoAcceptFlag auto_accept_flag);
82 
83   virtual void WriteLocalName(std::string local_name);
84 
85   virtual void HostBufferSize(uint16_t host_acl_data_packet_length, uint8_t host_synchronous_data_packet_length,
86                               uint16_t host_total_num_acl_data_packets,
87                               uint16_t host_total_num_synchronous_data_packets);
88 
89   // LE controller commands
90   virtual void LeSetEventMask(uint64_t le_event_mask);
91 
92   virtual LeBufferSize GetControllerLeBufferSize() const;
93 
94   virtual uint64_t GetControllerLeLocalSupportedFeatures() const;
95 
96   virtual uint64_t GetControllerLeSupportedStates() const;
97 
98   virtual uint8_t GetControllerLeConnectListSize() const;
99 
100   virtual uint8_t GetControllerLeResolvingListSize() const;
101 
102   virtual LeMaximumDataLength GetControllerLeMaximumDataLength() const;
103 
104   virtual uint16_t GetControllerLeMaximumAdvertisingDataLength() const;
105 
106   virtual uint8_t GetControllerLeNumberOfSupportedAdverisingSets() const;
107 
108   virtual VendorCapabilities GetControllerVendorCapabilities() const;
109 
110   virtual bool IsSupported(OpCode op_code) const;
111 
112   static const ModuleFactory Factory;
113 
114   static constexpr uint64_t kDefaultEventMask = 0x3dbfffffffffffff;
115 
116  protected:
117   void ListDependencies(ModuleList* list) override;
118 
119   void Start() override;
120 
121   void Stop() override;
122 
123   std::string ToString() const override;
124 
125  private:
126   struct impl;
127   std::unique_ptr<impl> impl_;
128 };
129 
130 }  // namespace hci
131 }  // namespace bluetooth
132