1 /*
2  * Copyright 2023 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/class_of_device.h"
22 #include "hci/hci_packets.h"
23 #include "hci/le_rand_callback.h"
24 
25 namespace bluetooth {
26 namespace hci {
27 
28 class ControllerInterface {
29  public:
30   ControllerInterface() = default;
31   virtual ~ControllerInterface() = default;
32 
33   using CompletedAclPacketsCallback =
34       common::ContextualCallback<void(uint16_t /* handle */, uint16_t /* num_packets */)>;
35   virtual void RegisterCompletedAclPacketsCallback(CompletedAclPacketsCallback cb) = 0;
36 
37   virtual void UnregisterCompletedAclPacketsCallback() = 0;
38 
39   virtual void RegisterCompletedMonitorAclPacketsCallback(CompletedAclPacketsCallback cb) = 0;
40   virtual void UnregisterCompletedMonitorAclPacketsCallback() = 0;
41 
42   virtual std::string GetLocalName() const = 0;
43   virtual LocalVersionInformation GetLocalVersionInformation() const = 0;
44 
45   virtual bool SupportsSimplePairing() const = 0;
46   virtual bool SupportsSecureConnections() const = 0;
47   virtual bool SupportsSimultaneousLeBrEdr() const = 0;
48   virtual bool SupportsInterlacedInquiryScan() const = 0;
49   virtual bool SupportsRssiWithInquiryResults() const = 0;
50   virtual bool SupportsExtendedInquiryResponse() const = 0;
51   virtual bool SupportsRoleSwitch() const = 0;
52   virtual bool Supports3SlotPackets() const = 0;
53   virtual bool Supports5SlotPackets() const = 0;
54   virtual bool SupportsClassic2mPhy() const = 0;
55   virtual bool SupportsClassic3mPhy() const = 0;
56   virtual bool Supports3SlotEdrPackets() const = 0;
57   virtual bool Supports5SlotEdrPackets() const = 0;
58   virtual bool SupportsSco() const = 0;
59   virtual bool SupportsHv2Packets() const = 0;
60   virtual bool SupportsHv3Packets() const = 0;
61   virtual bool SupportsEv3Packets() const = 0;
62   virtual bool SupportsEv4Packets() const = 0;
63   virtual bool SupportsEv5Packets() const = 0;
64   virtual bool SupportsEsco2mPhy() const = 0;
65   virtual bool SupportsEsco3mPhy() const = 0;
66   virtual bool Supports3SlotEscoEdrPackets() const = 0;
67   virtual bool SupportsHoldMode() const = 0;
68   virtual bool SupportsSniffMode() const = 0;
69   virtual bool SupportsParkMode() const = 0;
70   virtual bool SupportsNonFlushablePb() const = 0;
71   virtual bool SupportsSniffSubrating() const = 0;
72   virtual bool SupportsEncryptionPause() const = 0;
73   virtual bool SupportsBle() const = 0;
74 
75   virtual bool SupportsBleEncryption() const = 0;
76   virtual bool SupportsBleConnectionParametersRequest() const = 0;
77   virtual bool SupportsBleExtendedReject() const = 0;
78   virtual bool SupportsBlePeripheralInitiatedFeaturesExchange() const = 0;
79   virtual bool SupportsBlePing() const = 0;
80   virtual bool SupportsBleDataPacketLengthExtension() const = 0;
81   virtual bool SupportsBlePrivacy() const = 0;
82   virtual bool SupportsBleExtendedScannerFilterPolicies() const = 0;
83   virtual bool SupportsBle2mPhy() const = 0;
84   virtual bool SupportsBleStableModulationIndexTx() const = 0;
85   virtual bool SupportsBleStableModulationIndexRx() const = 0;
86   virtual bool SupportsBleCodedPhy() const = 0;
87   virtual bool SupportsBleExtendedAdvertising() const = 0;
88   virtual bool SupportsBlePeriodicAdvertising() const = 0;
89   virtual bool SupportsBleChannelSelectionAlgorithm2() const = 0;
90   virtual bool SupportsBlePowerClass1() const = 0;
91   virtual bool SupportsBleMinimumUsedChannels() const = 0;
92   virtual bool SupportsBleConnectionCteRequest() const = 0;
93   virtual bool SupportsBleConnectionCteResponse() const = 0;
94   virtual bool SupportsBleConnectionlessCteTransmitter() const = 0;
95   virtual bool SupportsBleConnectionlessCteReceiver() const = 0;
96   virtual bool SupportsBleAntennaSwitchingDuringCteTx() const = 0;
97   virtual bool SupportsBleAntennaSwitchingDuringCteRx() const = 0;
98   virtual bool SupportsBleReceivingConstantToneExtensions() const = 0;
99   virtual bool SupportsBlePeriodicAdvertisingSyncTransferSender() const = 0;
100   virtual bool SupportsBlePeriodicAdvertisingSyncTransferRecipient() const = 0;
101   virtual bool SupportsBleSleepClockAccuracyUpdates() const = 0;
102   virtual bool SupportsBleRemotePublicKeyValidation() const = 0;
103   virtual bool SupportsBleConnectedIsochronousStreamCentral() const = 0;
104   virtual bool SupportsBleConnectedIsochronousStreamPeripheral() const = 0;
105   virtual bool SupportsBleIsochronousBroadcaster() const = 0;
106   virtual bool SupportsBleSynchronizedReceiver() const = 0;
107   virtual bool SupportsBleIsochronousChannelsHostSupport() const = 0;
108   virtual bool SupportsBlePowerControlRequest() const = 0;
109   virtual bool SupportsBlePowerChangeIndication() const = 0;
110   virtual bool SupportsBlePathLossMonitoring() const = 0;
111   virtual bool SupportsBlePeriodicAdvertisingAdi() const = 0;
112   virtual bool SupportsBleConnectionSubrating() const = 0;
113   virtual bool SupportsBleConnectionSubratingHost() const = 0;
114   virtual bool SupportsBleChannelSounding() const = 0;
115 
116   virtual uint16_t GetAclPacketLength() const = 0;
117 
118   virtual uint16_t GetNumAclPacketBuffers() const = 0;
119 
120   virtual uint8_t GetScoPacketLength() const = 0;
121 
122   virtual uint16_t GetNumScoPacketBuffers() const = 0;
123 
124   virtual Address GetMacAddress() const = 0;
125 
126   virtual void SetEventMask(uint64_t event_mask) = 0;
127 
128   virtual void Reset() = 0;
129 
130   virtual void LeRand(LeRandCallback cb) = 0;
131 
132   virtual void SetEventFilterClearAll() = 0;
133 
134   virtual void SetEventFilterInquiryResultAllDevices() = 0;
135 
136   virtual void SetEventFilterInquiryResultClassOfDevice(
137       ClassOfDevice class_of_device, ClassOfDevice class_of_device_mask) = 0;
138 
139   virtual void SetEventFilterInquiryResultAddress(Address address) = 0;
140 
141   virtual void SetEventFilterConnectionSetupAllDevices(AutoAcceptFlag auto_accept_flag) = 0;
142 
143   virtual void SetEventFilterConnectionSetupClassOfDevice(
144       ClassOfDevice class_of_device,
145       ClassOfDevice class_of_device_mask,
146       AutoAcceptFlag auto_accept_flag) = 0;
147 
148   virtual void SetEventFilterConnectionSetupAddress(
149       Address address, AutoAcceptFlag auto_accept_flag) = 0;
150 
151   virtual void WriteLocalName(std::string local_name) = 0;
152 
153   virtual void HostBufferSize(
154       uint16_t host_acl_data_packet_length,
155       uint8_t host_synchronous_data_packet_length,
156       uint16_t host_total_num_acl_data_packets,
157       uint16_t host_total_num_synchronous_data_packets) = 0;
158 
159   // LE controller commands
160   virtual void LeSetEventMask(uint64_t le_event_mask) = 0;
161 
162   virtual LeBufferSize GetLeBufferSize() const = 0;
163 
164   virtual uint64_t GetLeSupportedStates() const = 0;
165 
166   virtual LeBufferSize GetControllerIsoBufferSize() const = 0;
167 
168   virtual uint64_t GetControllerLeLocalSupportedFeatures() const = 0;
169 
170   virtual uint8_t GetLeFilterAcceptListSize() const = 0;
171 
172   virtual uint8_t GetLeResolvingListSize() const = 0;
173 
174   virtual LeMaximumDataLength GetLeMaximumDataLength() const = 0;
175 
176   virtual uint16_t GetLeMaximumAdvertisingDataLength() const = 0;
177 
178   virtual uint16_t GetLeSuggestedDefaultDataLength() const = 0;
179 
180   virtual uint8_t GetLeNumberOfSupportedAdverisingSets() const = 0;
181 
182   virtual uint8_t GetLePeriodicAdvertiserListSize() const = 0;
183 
184   // 7.4.8 Read Local Supported Codecs command v1 only returns codecs on the BR/EDR transport
185   virtual std::vector<uint8_t> GetLocalSupportedBrEdrCodecIds() const = 0;
186 
187   struct VendorCapabilities {
188     uint8_t is_supported_;
189     uint8_t max_advt_instances_;
190     uint8_t offloaded_resolution_of_private_address_;
191     uint16_t total_scan_results_storage_;
192     uint8_t max_irk_list_sz_;
193     uint8_t filtering_support_;
194     uint8_t max_filter_;
195     uint8_t activity_energy_info_support_;
196     uint16_t version_supported_;
197     uint16_t total_num_of_advt_tracked_;
198     uint8_t extended_scan_support_;
199     uint8_t debug_logging_supported_;
200     uint8_t le_address_generation_offloading_support_;
201     uint32_t a2dp_source_offload_capability_mask_;
202     uint8_t bluetooth_quality_report_support_;
203     uint32_t dynamic_audio_buffer_support_;
204     uint8_t a2dp_offload_v2_support_;
205   };
206 
207   virtual uint32_t GetDabSupportedCodecs() const = 0;
208   virtual const std::array<DynamicAudioBufferCodecCapability, 32>& GetDabCodecCapabilities()
209       const = 0;
210 
211   virtual void SetDabAudioBufferTime(uint16_t buffer_time_ms) = 0;
212 
213   virtual VendorCapabilities GetVendorCapabilities() const = 0;
214 
215   virtual bool IsSupported(OpCode op_code) const = 0;
216 };
217 
218 }  // namespace hci
219 }  // namespace bluetooth
220