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 <vector>
20 
21 #include "hci/address.h"
22 #include "hci/controller_interface.h"
23 #include "hci/hci_packets.h"
24 #include "hci/le_rand_callback.h"
25 #include "module.h"
26 
27 // TODO Remove this once all QTI specific hacks are removed.
28 #define LMP_COMPID_QTI 0x001D
29 
30 namespace bluetooth {
31 namespace hci {
32 
33 class Controller : public Module, public ControllerInterface {
34  public:
35   Controller();
36   Controller(const Controller&) = delete;
37   Controller& operator=(const Controller&) = delete;
38 
39   virtual ~Controller();
40 
41   virtual void RegisterCompletedAclPacketsCallback(CompletedAclPacketsCallback cb) override;
42 
43   virtual void UnregisterCompletedAclPacketsCallback() override;
44 
45   virtual void RegisterCompletedMonitorAclPacketsCallback(CompletedAclPacketsCallback cb) override;
46   virtual void UnregisterCompletedMonitorAclPacketsCallback() override;
47 
48   virtual std::string GetLocalName() const override;
49 
50   virtual LocalVersionInformation GetLocalVersionInformation() const override;
51 
52   virtual bool SupportsSimplePairing() const override;
53   virtual bool SupportsSecureConnections() const override;
54   virtual bool SupportsSimultaneousLeBrEdr() const override;
55   virtual bool SupportsInterlacedInquiryScan() const override;
56   virtual bool SupportsRssiWithInquiryResults() const override;
57   virtual bool SupportsExtendedInquiryResponse() const override;
58   virtual bool SupportsRoleSwitch() const override;
59   virtual bool Supports3SlotPackets() const override;
60   virtual bool Supports5SlotPackets() const override;
61   virtual bool SupportsClassic2mPhy() const override;
62   virtual bool SupportsClassic3mPhy() const override;
63   virtual bool Supports3SlotEdrPackets() const override;
64   virtual bool Supports5SlotEdrPackets() const override;
65   virtual bool SupportsSco() const override;
66   virtual bool SupportsHv2Packets() const override;
67   virtual bool SupportsHv3Packets() const override;
68   virtual bool SupportsEv3Packets() const override;
69   virtual bool SupportsEv4Packets() const override;
70   virtual bool SupportsEv5Packets() const override;
71   virtual bool SupportsEsco2mPhy() const override;
72   virtual bool SupportsEsco3mPhy() const override;
73   virtual bool Supports3SlotEscoEdrPackets() const override;
74   virtual bool SupportsHoldMode() const override;
75   virtual bool SupportsSniffMode() const override;
76   virtual bool SupportsParkMode() const override;
77   virtual bool SupportsNonFlushablePb() const override;
78   virtual bool SupportsSniffSubrating() const override;
79   virtual bool SupportsEncryptionPause() const override;
80   virtual bool SupportsBle() const override;
81 
82   virtual bool SupportsBleEncryption() const override;
83   virtual bool SupportsBleConnectionParametersRequest() const override;
84   virtual bool SupportsBleExtendedReject() const override;
85   virtual bool SupportsBlePeripheralInitiatedFeaturesExchange() const override;
86   virtual bool SupportsBlePing() const override;
87   virtual bool SupportsBleDataPacketLengthExtension() const override;
88   virtual bool SupportsBlePrivacy() const override;
89   virtual bool SupportsBleExtendedScannerFilterPolicies() const override;
90   virtual bool SupportsBle2mPhy() const override;
91   virtual bool SupportsBleStableModulationIndexTx() const override;
92   virtual bool SupportsBleStableModulationIndexRx() const override;
93   virtual bool SupportsBleCodedPhy() const override;
94   virtual bool SupportsBleExtendedAdvertising() const override;
95   virtual bool SupportsBlePeriodicAdvertising() const override;
96   virtual bool SupportsBleChannelSelectionAlgorithm2() const override;
97   virtual bool SupportsBlePowerClass1() const override;
98   virtual bool SupportsBleMinimumUsedChannels() const override;
99   virtual bool SupportsBleConnectionCteRequest() const override;
100   virtual bool SupportsBleConnectionCteResponse() const override;
101   virtual bool SupportsBleConnectionlessCteTransmitter() const override;
102   virtual bool SupportsBleConnectionlessCteReceiver() const override;
103   virtual bool SupportsBleAntennaSwitchingDuringCteTx() const override;
104   virtual bool SupportsBleAntennaSwitchingDuringCteRx() const override;
105   virtual bool SupportsBleReceivingConstantToneExtensions() const override;
106   virtual bool SupportsBlePeriodicAdvertisingSyncTransferSender() const override;
107   virtual bool SupportsBlePeriodicAdvertisingSyncTransferRecipient() const override;
108   virtual bool SupportsBleSleepClockAccuracyUpdates() const override;
109   virtual bool SupportsBleRemotePublicKeyValidation() const override;
110   virtual bool SupportsBleConnectedIsochronousStreamCentral() const override;
111   virtual bool SupportsBleConnectedIsochronousStreamPeripheral() const override;
112   virtual bool SupportsBleIsochronousBroadcaster() const override;
113   virtual bool SupportsBleSynchronizedReceiver() const override;
114   virtual bool SupportsBleIsochronousChannelsHostSupport() const override;
115   virtual bool SupportsBlePowerControlRequest() const override;
116   virtual bool SupportsBlePowerChangeIndication() const override;
117   virtual bool SupportsBlePathLossMonitoring() const override;
118   virtual bool SupportsBlePeriodicAdvertisingAdi() const override;
119   virtual bool SupportsBleConnectionSubrating() const override;
120   virtual bool SupportsBleConnectionSubratingHost() const override;
121   virtual bool SupportsBleChannelSounding() const override;
122 
123   virtual uint16_t GetAclPacketLength() const override;
124 
125   virtual uint16_t GetNumAclPacketBuffers() const override;
126 
127   virtual uint8_t GetScoPacketLength() const override;
128 
129   virtual uint16_t GetNumScoPacketBuffers() const override;
130 
131   virtual Address GetMacAddress() const override;
132 
133   virtual void SetEventMask(uint64_t event_mask) override;
134 
135   virtual void Reset() override;
136 
137   virtual void LeRand(LeRandCallback cb) override;
138 
139   virtual void SetEventFilterClearAll() override;
140 
141   virtual void SetEventFilterInquiryResultAllDevices() override;
142 
143   virtual void SetEventFilterInquiryResultClassOfDevice(
144       ClassOfDevice class_of_device, ClassOfDevice class_of_device_mask) override;
145 
146   virtual void SetEventFilterInquiryResultAddress(Address address) override;
147 
148   virtual void SetEventFilterConnectionSetupAllDevices(AutoAcceptFlag auto_accept_flag) override;
149 
150   virtual void SetEventFilterConnectionSetupClassOfDevice(
151       ClassOfDevice class_of_device,
152       ClassOfDevice class_of_device_mask,
153       AutoAcceptFlag auto_accept_flag) override;
154 
155   virtual void SetEventFilterConnectionSetupAddress(
156       Address address, AutoAcceptFlag auto_accept_flag) override;
157 
158   virtual void WriteLocalName(std::string local_name) override;
159 
160   virtual void HostBufferSize(
161       uint16_t host_acl_data_packet_length,
162       uint8_t host_synchronous_data_packet_length,
163       uint16_t host_total_num_acl_data_packets,
164       uint16_t host_total_num_synchronous_data_packets) override;
165 
166   // LE controller commands
167   virtual void LeSetEventMask(uint64_t le_event_mask) override;
168 
169   virtual LeBufferSize GetLeBufferSize() const override;
170 
171   virtual uint64_t GetLeSupportedStates() const override;
172 
173   virtual LeBufferSize GetControllerIsoBufferSize() const override;
174 
175   virtual uint64_t GetControllerLeLocalSupportedFeatures() const override;
176 
177   virtual uint8_t GetLeFilterAcceptListSize() const override;
178 
179   virtual uint8_t GetLeResolvingListSize() const override;
180 
181   virtual LeMaximumDataLength GetLeMaximumDataLength() const override;
182 
183   virtual uint16_t GetLeMaximumAdvertisingDataLength() const override;
184 
185   virtual uint16_t GetLeSuggestedDefaultDataLength() const override;
186 
187   virtual uint8_t GetLeNumberOfSupportedAdverisingSets() const override;
188 
189   virtual uint8_t GetLePeriodicAdvertiserListSize() const override;
190 
191   // 7.4.8 Read Local Supported Codecs command v1 only returns codecs on the BR/EDR transport
192   virtual std::vector<uint8_t> GetLocalSupportedBrEdrCodecIds() const override;
193 
194   virtual VendorCapabilities GetVendorCapabilities() const override;
195 
196   virtual uint32_t GetDabSupportedCodecs() const override;
197   virtual const std::array<DynamicAudioBufferCodecCapability, 32>& GetDabCodecCapabilities()
198       const override;
199 
200   virtual void SetDabAudioBufferTime(uint16_t buffer_time_ms) override;
201 
202   virtual bool IsSupported(OpCode op_code) const override;
203 
204   static const ModuleFactory Factory;
205 
206   static constexpr uint64_t kDefaultEventMask = 0x3dbfffffffffffff;
207   static constexpr uint64_t kDefaultLeEventMask = 0x000000074d02fe7f;
208   static constexpr uint64_t kLeCSEventMask = 0x0007f80000000000;
209 
210   static constexpr uint64_t kLeEventMask53 = 0x00000007ffffffff;
211   static constexpr uint64_t kLeEventMask52 = 0x00000003ffffffff;
212   static constexpr uint64_t kLeEventMask51 = 0x0000000000ffffff;
213   static constexpr uint64_t kLeEventMask50 = 0x00000000000fffff;
214   static constexpr uint64_t kLeEventMask42 = 0x00000000000003ff;
215   static constexpr uint64_t kLeEventMask41 = 0x000000000000003f;
216 
217   static uint64_t MaskLeEventMask(HciVersion version, uint64_t mask);
218 
219  protected:
220   void ListDependencies(ModuleList* list) const override;
221 
222   void Start() override;
223 
224   void Stop() override;
225 
226   std::string ToString() const override;
227 
228   DumpsysDataFinisher GetDumpsysData(flatbuffers::FlatBufferBuilder* builder) const override;  // Module
229 
230  private:
231   virtual uint64_t GetLocalFeatures(uint8_t page_number) const;
232   virtual uint64_t GetLocalLeFeatures() const;
233 
234   struct impl;
235   std::unique_ptr<impl> impl_;
236 };
237 
238 }  // namespace hci
239 }  // namespace bluetooth
240