• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 void RegisterCompletedMonitorAclPacketsCallback(CompletedAclPacketsCallback cb);
41   virtual void UnregisterCompletedMonitorAclPacketsCallback();
42 
43   virtual std::string GetLocalName() const;
44 
45   virtual LocalVersionInformation GetLocalVersionInformation() const;
46 
47   virtual bool SupportsSimplePairing() const;
48   virtual bool SupportsSecureConnections() const;
49   virtual bool SupportsSimultaneousLeBrEdr() const;
50   virtual bool SupportsInterlacedInquiryScan() const;
51   virtual bool SupportsRssiWithInquiryResults() const;
52   virtual bool SupportsExtendedInquiryResponse() const;
53   virtual bool SupportsRoleSwitch() const;
54   virtual bool Supports3SlotPackets() const;
55   virtual bool Supports5SlotPackets() const;
56   virtual bool SupportsClassic2mPhy() const;
57   virtual bool SupportsClassic3mPhy() const;
58   virtual bool Supports3SlotEdrPackets() const;
59   virtual bool Supports5SlotEdrPackets() const;
60   virtual bool SupportsSco() const;
61   virtual bool SupportsHv2Packets() const;
62   virtual bool SupportsHv3Packets() const;
63   virtual bool SupportsEv3Packets() const;
64   virtual bool SupportsEv4Packets() const;
65   virtual bool SupportsEv5Packets() const;
66   virtual bool SupportsEsco2mPhy() const;
67   virtual bool SupportsEsco3mPhy() const;
68   virtual bool Supports3SlotEscoEdrPackets() const;
69   virtual bool SupportsHoldMode() const;
70   virtual bool SupportsSniffMode() const;
71   virtual bool SupportsParkMode() const;
72   virtual bool SupportsNonFlushablePb() const;
73   virtual bool SupportsSniffSubrating() const;
74   virtual bool SupportsEncryptionPause() const;
75 
76   virtual bool SupportsBle() const;
77   virtual bool SupportsBlePrivacy() const;
78   virtual bool SupportsBlePacketExtension() const;
79   virtual bool SupportsBleConnectionParametersRequest() const;
80   virtual bool SupportsBle2mPhy() const;
81   virtual bool SupportsBleCodedPhy() const;
82   virtual bool SupportsBleExtendedAdvertising() const;
83   virtual bool SupportsBlePeriodicAdvertising() const;
84   virtual bool SupportsBlePeripheralInitiatedFeatureExchange() const;
85   virtual bool SupportsBleConnectionParameterRequest() const;
86   virtual bool SupportsBlePeriodicAdvertisingSyncTransferSender() const;
87   virtual bool SupportsBlePeriodicAdvertisingSyncTransferRecipient() const;
88   virtual bool SupportsBleConnectedIsochronousStreamCentral() const;
89   virtual bool SupportsBleConnectedIsochronousStreamPeripheral() const;
90   virtual bool SupportsBleIsochronousBroadcaster() const;
91   virtual bool SupportsBleSynchronizedReceiver() const;
92 
93   virtual uint16_t GetAclPacketLength() const;
94 
95   virtual uint16_t GetNumAclPacketBuffers() const;
96 
97   virtual uint8_t GetScoPacketLength() const;
98 
99   virtual uint16_t GetNumScoPacketBuffers() const;
100 
101   virtual Address GetMacAddress() const;
102 
103   virtual void SetEventMask(uint64_t event_mask);
104 
105   virtual void Reset();
106 
107   virtual void SetEventFilterClearAll();
108 
109   virtual void SetEventFilterInquiryResultAllDevices();
110 
111   virtual void SetEventFilterInquiryResultClassOfDevice(ClassOfDevice class_of_device,
112                                                         ClassOfDevice class_of_device_mask);
113 
114   virtual void SetEventFilterInquiryResultAddress(Address address);
115 
116   virtual void SetEventFilterConnectionSetupAllDevices(AutoAcceptFlag auto_accept_flag);
117 
118   virtual void SetEventFilterConnectionSetupClassOfDevice(ClassOfDevice class_of_device,
119                                                           ClassOfDevice class_of_device_mask,
120                                                           AutoAcceptFlag auto_accept_flag);
121 
122   virtual void SetEventFilterConnectionSetupAddress(Address address, AutoAcceptFlag auto_accept_flag);
123 
124   virtual void WriteLocalName(std::string local_name);
125 
126   virtual void HostBufferSize(uint16_t host_acl_data_packet_length, uint8_t host_synchronous_data_packet_length,
127                               uint16_t host_total_num_acl_data_packets,
128                               uint16_t host_total_num_synchronous_data_packets);
129 
130   // LE controller commands
131   virtual void LeSetEventMask(uint64_t le_event_mask);
132 
133   virtual LeBufferSize GetLeBufferSize() const;
134 
135   virtual uint64_t GetLeSupportedStates() const;
136 
137   virtual LeBufferSize GetControllerIsoBufferSize() const;
138 
139   virtual uint64_t GetControllerLeLocalSupportedFeatures() const;
140 
141   virtual uint8_t GetLeConnectListSize() const;
142 
143   virtual uint8_t GetLeResolvingListSize() const;
144 
145   virtual LeMaximumDataLength GetLeMaximumDataLength() const;
146 
147   virtual uint16_t GetLeMaximumAdvertisingDataLength() const;
148 
149   virtual uint16_t GetLeSuggestedDefaultDataLength() const;
150 
151   virtual uint8_t GetLeNumberOfSupportedAdverisingSets() const;
152 
153   virtual uint8_t GetLePeriodicAdvertiserListSize() const;
154 
155   virtual VendorCapabilities GetVendorCapabilities() const;
156 
157   virtual bool IsSupported(OpCode op_code) const;
158 
159   static const ModuleFactory Factory;
160 
161   static constexpr uint64_t kDefaultEventMask = 0x3dbfffffffffffff;
162   static constexpr uint64_t kDefaultLeEventMask = 0x0000000000021e7f;
163 
164  protected:
165   void ListDependencies(ModuleList* list) override;
166 
167   void Start() override;
168 
169   void Stop() override;
170 
171   std::string ToString() const override;
172 
173  private:
174   virtual uint64_t GetLocalFeatures(uint8_t page_number) const;
175   virtual uint64_t GetLocalLeFeatures() const;
176 
177   struct impl;
178   std::unique_ptr<impl> impl_;
179 };
180 
181 }  // namespace hci
182 }  // namespace bluetooth
183