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 #include "hci/controller.h"
18
19 #include <bluetooth/log.h>
20 #include <com_android_bluetooth_flags.h>
21
22 #include <future>
23 #include <memory>
24 #include <string>
25 #include <utility>
26
27 #include "common/init_flags.h"
28 #include "dumpsys_data_generated.h"
29 #include "hci/controller_interface.h"
30 #include "hci/event_checkers.h"
31 #include "hci/hci_layer.h"
32 #include "hci_controller_generated.h"
33 #include "os/log.h"
34 #include "os/metrics.h"
35 #include "os/system_properties.h"
36 #if TARGET_FLOSS
37 #include "sysprops/sysprops_module.h"
38 #endif
39
40 namespace bluetooth {
41 namespace hci {
42
43 constexpr uint8_t kMinEncryptionKeySize = 7; // #define MIN_ENCRYPTION_KEY_SIZE 7
44
45 constexpr bool kDefaultVendorCapabilitiesEnabled = true;
46 static const std::string kPropertyVendorCapabilitiesEnabled =
47 "bluetooth.core.le.vendor_capabilities.enabled";
48
49 using os::Handler;
50
51 struct Controller::impl {
implbluetooth::hci::Controller::impl52 impl(Controller& module) : module_(module) {}
53
Startbluetooth::hci::Controller::impl54 void Start(hci::HciLayer* hci) {
55 hci_ = hci;
56 Handler* handler = module_.GetHandler();
57 hci_->RegisterEventHandler(
58 EventCode::NUMBER_OF_COMPLETED_PACKETS, handler->BindOn(this, &Controller::impl::NumberOfCompletedPackets));
59
60 set_event_mask(kDefaultEventMask);
61 write_le_host_support(Enable::ENABLED, Enable::DISABLED);
62 hci_->EnqueueCommand(ReadLocalNameBuilder::Create(),
63 handler->BindOnceOn(this, &Controller::impl::read_local_name_complete_handler));
64 hci_->EnqueueCommand(ReadLocalVersionInformationBuilder::Create(),
65 handler->BindOnceOn(this, &Controller::impl::read_local_version_information_complete_handler));
66 hci_->EnqueueCommand(ReadLocalSupportedCommandsBuilder::Create(),
67 handler->BindOnceOn(this, &Controller::impl::read_local_supported_commands_complete_handler));
68
69 hci_->EnqueueCommand(
70 LeReadLocalSupportedFeaturesBuilder::Create(),
71 handler->BindOnceOn(this, &Controller::impl::le_read_local_supported_features_handler));
72
73 hci_->EnqueueCommand(
74 LeReadSupportedStatesBuilder::Create(),
75 handler->BindOnceOn(this, &Controller::impl::le_read_supported_states_handler));
76
77 // Wait for all extended features read
78 std::promise<void> features_promise;
79 auto features_future = features_promise.get_future();
80
81 hci_->EnqueueCommand(ReadLocalExtendedFeaturesBuilder::Create(0x00),
82 handler->BindOnceOn(this, &Controller::impl::read_local_extended_features_complete_handler,
83 std::move(features_promise)));
84 features_future.wait();
85
86 if (com::android::bluetooth::flags::channel_sounding_in_stack() &&
87 module_.SupportsBleChannelSounding()) {
88 le_set_event_mask(MaskLeEventMask(
89 local_version_information_.hci_version_, kDefaultLeEventMask | kLeCSEventMask));
90 } else {
91 le_set_event_mask(
92 MaskLeEventMask(local_version_information_.hci_version_, kDefaultLeEventMask));
93 }
94
95 hci_->EnqueueCommand(ReadBufferSizeBuilder::Create(),
96 handler->BindOnceOn(this, &Controller::impl::read_buffer_size_complete_handler));
97
98 if (common::init_flags::set_min_encryption_is_enabled() && is_supported(OpCode::SET_MIN_ENCRYPTION_KEY_SIZE)) {
99 hci_->EnqueueCommand(
100 SetMinEncryptionKeySizeBuilder::Create(kMinEncryptionKeySize),
101 handler->BindOnceOn(this, &Controller::impl::set_min_encryption_key_size_handler));
102 }
103
104 if (is_supported(OpCode::LE_READ_BUFFER_SIZE_V2)) {
105 hci_->EnqueueCommand(
106 LeReadBufferSizeV2Builder::Create(),
107 handler->BindOnceOn(this, &Controller::impl::le_read_buffer_size_v2_handler));
108 } else {
109 hci_->EnqueueCommand(
110 LeReadBufferSizeV1Builder::Create(),
111 handler->BindOnceOn(this, &Controller::impl::le_read_buffer_size_handler));
112 }
113
114 if (is_supported(OpCode::READ_LOCAL_SUPPORTED_CODECS_V1)) {
115 hci_->EnqueueCommand(
116 ReadLocalSupportedCodecsV1Builder::Create(),
117 handler->BindOnceOn(this, &Controller::impl::read_local_supported_codecs_v1_handler));
118 }
119
120 hci_->EnqueueCommand(
121 LeReadFilterAcceptListSizeBuilder::Create(),
122 handler->BindOnceOn(this, &Controller::impl::le_read_accept_list_size_handler));
123
124 if (is_supported(OpCode::LE_READ_RESOLVING_LIST_SIZE) && module_.SupportsBlePrivacy()) {
125 hci_->EnqueueCommand(
126 LeReadResolvingListSizeBuilder::Create(),
127 handler->BindOnceOn(this, &Controller::impl::le_read_resolving_list_size_handler));
128 } else {
129 log::info("LE_READ_RESOLVING_LIST_SIZE not supported, defaulting to 0");
130 le_resolving_list_size_ = 0;
131 }
132
133 if (is_supported(OpCode::LE_READ_MAXIMUM_DATA_LENGTH) && module_.SupportsBleDataPacketLengthExtension()) {
134 hci_->EnqueueCommand(LeReadMaximumDataLengthBuilder::Create(),
135 handler->BindOnceOn(this, &Controller::impl::le_read_maximum_data_length_handler));
136 } else {
137 log::info("LE_READ_MAXIMUM_DATA_LENGTH not supported, defaulting to 0");
138 le_maximum_data_length_.supported_max_rx_octets_ = 0;
139 le_maximum_data_length_.supported_max_rx_time_ = 0;
140 le_maximum_data_length_.supported_max_tx_octets_ = 0;
141 le_maximum_data_length_.supported_max_tx_time_ = 0;
142 }
143
144 // SSP is managed by security layer once enabled
145 write_simple_pairing_mode(Enable::ENABLED);
146 if (module_.SupportsSecureConnections()) {
147 hci_->EnqueueCommand(
148 WriteSecureConnectionsHostSupportBuilder::Create(Enable::ENABLED),
149 handler->BindOnceOn(
150 this, &Controller::impl::write_secure_connections_host_support_complete_handler));
151 }
152 if (is_supported(OpCode::LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH) && module_.SupportsBleDataPacketLengthExtension()) {
153 hci_->EnqueueCommand(
154 LeReadSuggestedDefaultDataLengthBuilder::Create(),
155 handler->BindOnceOn(this, &Controller::impl::le_read_suggested_default_data_length_handler));
156 } else {
157 log::info("LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH not supported, defaulting to 27 (0x1B)");
158 le_suggested_default_data_length_ = 27;
159 }
160
161 if (is_supported(OpCode::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH) && module_.SupportsBleExtendedAdvertising()) {
162 hci_->EnqueueCommand(
163 LeReadMaximumAdvertisingDataLengthBuilder::Create(),
164 handler->BindOnceOn(this, &Controller::impl::le_read_maximum_advertising_data_length_handler));
165 } else {
166 log::info("LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH not supported, defaulting to 31 (0x1F)");
167 le_maximum_advertising_data_length_ = 31;
168 }
169
170 if (is_supported(OpCode::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS) &&
171 module_.SupportsBleExtendedAdvertising()) {
172 hci_->EnqueueCommand(
173 LeReadNumberOfSupportedAdvertisingSetsBuilder::Create(),
174 handler->BindOnceOn(this, &Controller::impl::le_read_number_of_supported_advertising_sets_handler));
175 } else {
176 log::info("LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS not supported, defaulting to 1");
177 le_number_supported_advertising_sets_ = 1;
178 }
179
180 if (is_supported(OpCode::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE) &&
181 module_.SupportsBlePeriodicAdvertising()) {
182 hci_->EnqueueCommand(
183 LeReadPeriodicAdvertiserListSizeBuilder::Create(),
184 handler->BindOnceOn(this, &Controller::impl::le_read_periodic_advertiser_list_size_handler));
185 } else {
186 log::info("LE_READ_PERIODIC_ADVERTISER_LIST_SIZE not supported, defaulting to 0");
187 le_periodic_advertiser_list_size_ = 0;
188 }
189 if (is_supported(OpCode::LE_SET_HOST_FEATURE) && module_.SupportsBleConnectedIsochronousStreamCentral()) {
190 hci_->EnqueueCommand(
191 LeSetHostFeatureBuilder::Create(LeHostFeatureBits::CONNECTED_ISO_STREAM_HOST_SUPPORT, Enable::ENABLED),
192 handler->BindOnceOn(this, &Controller::impl::le_set_host_feature_handler));
193 }
194
195 if (common::init_flags::subrating_is_enabled() && is_supported(OpCode::LE_SET_HOST_FEATURE) &&
196 module_.SupportsBleConnectionSubrating()) {
197 hci_->EnqueueCommand(
198 LeSetHostFeatureBuilder::Create(
199 LeHostFeatureBits::CONNECTION_SUBRATING_HOST_SUPPORT, Enable::ENABLED),
200 handler->BindOnceOn(this, &Controller::impl::le_set_host_feature_handler));
201 }
202
203 if (com::android::bluetooth::flags::channel_sounding_in_stack() &&
204 module_.SupportsBleChannelSounding()) {
205 hci_->EnqueueCommand(
206 LeSetHostFeatureBuilder::Create(
207 LeHostFeatureBits::CHANNEL_SOUNDING_HOST_SUPPORT, Enable::ENABLED),
208 handler->BindOnceOn(this, &Controller::impl::le_set_host_feature_handler));
209 }
210
211 if (is_supported(OpCode::READ_DEFAULT_ERRONEOUS_DATA_REPORTING)) {
212 hci_->EnqueueCommand(
213 ReadDefaultErroneousDataReportingBuilder::Create(),
214 handler->BindOnceOn(
215 this, &Controller::impl::read_default_erroneous_data_reporting_handler));
216 }
217
218 // Skip vendor capabilities check if configured.
219 if (os::GetSystemPropertyBool(
220 kPropertyVendorCapabilitiesEnabled, kDefaultVendorCapabilitiesEnabled)) {
221 // More commands can be enqueued from le_get_vendor_capabilities_handler
222 std::promise<void> vendor_promise;
223 auto vendor_future = vendor_promise.get_future();
224 hci_->EnqueueCommand(
225 LeGetVendorCapabilitiesBuilder::Create(),
226 handler->BindOnceOn(
227 this,
228 &Controller::impl::le_get_vendor_capabilities_handler,
229 std::move(vendor_promise)));
230 vendor_future.wait();
231 } else {
232 vendor_capabilities_.is_supported_ = 0x00;
233 }
234
235 // We only need to synchronize the last read. Make BD_ADDR to be the last one.
236 std::promise<void> promise;
237 auto future = promise.get_future();
238 hci_->EnqueueCommand(
239 ReadBdAddrBuilder::Create(),
240 handler->BindOnceOn(this, &Controller::impl::read_controller_mac_address_handler, std::move(promise)));
241 future.wait();
242 }
243
Stopbluetooth::hci::Controller::impl244 void Stop() {
245 hci_ = nullptr;
246 }
247
NumberOfCompletedPacketsbluetooth::hci::Controller::impl248 void NumberOfCompletedPackets(EventView event) {
249 if (!acl_credits_callback_) {
250 log::warn("Received event when AclManager is not listening");
251 return;
252 }
253 auto complete_view = NumberOfCompletedPacketsView::Create(event);
254 ASSERT(complete_view.IsValid());
255 for (auto completed_packets : complete_view.GetCompletedPackets()) {
256 uint16_t handle = completed_packets.connection_handle_;
257 uint16_t credits = completed_packets.host_num_of_completed_packets_;
258 acl_credits_callback_(handle, credits);
259 if (acl_monitor_credits_callback_) {
260 acl_monitor_credits_callback_(handle, credits);
261 }
262 }
263 }
264
register_completed_acl_packets_callbackbluetooth::hci::Controller::impl265 void register_completed_acl_packets_callback(CompletedAclPacketsCallback callback) {
266 ASSERT(!acl_credits_callback_);
267 acl_credits_callback_ = callback;
268 }
269
unregister_completed_acl_packets_callbackbluetooth::hci::Controller::impl270 void unregister_completed_acl_packets_callback() {
271 ASSERT(acl_credits_callback_);
272 acl_credits_callback_ = {};
273 }
274
register_completed_monitor_acl_packets_callbackbluetooth::hci::Controller::impl275 void register_completed_monitor_acl_packets_callback(CompletedAclPacketsCallback callback) {
276 ASSERT(!acl_monitor_credits_callback_);
277 acl_monitor_credits_callback_ = callback;
278 }
279
unregister_completed_monitor_acl_packets_callbackbluetooth::hci::Controller::impl280 void unregister_completed_monitor_acl_packets_callback() {
281 ASSERT(acl_monitor_credits_callback_);
282 acl_monitor_credits_callback_ = {};
283 }
284
register_monitor_completed_acl_packets_callbackbluetooth::hci::Controller::impl285 void register_monitor_completed_acl_packets_callback(CompletedAclPacketsCallback callback) {
286 ASSERT(!acl_monitor_credits_callback_);
287 acl_monitor_credits_callback_ = callback;
288 }
289
unregister_monitor_completed_acl_packets_callbackbluetooth::hci::Controller::impl290 void unregister_monitor_completed_acl_packets_callback() {
291 ASSERT(acl_monitor_credits_callback_);
292 acl_monitor_credits_callback_ = {};
293 }
294
write_secure_connections_host_support_complete_handlerbluetooth::hci::Controller::impl295 void write_secure_connections_host_support_complete_handler(CommandCompleteView view) {
296 auto complete_view = WriteSecureConnectionsHostSupportCompleteView::Create(view);
297 ASSERT(complete_view.IsValid());
298 ErrorCode status = complete_view.GetStatus();
299 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
300 }
301
read_local_name_complete_handlerbluetooth::hci::Controller::impl302 void read_local_name_complete_handler(CommandCompleteView view) {
303 auto complete_view = ReadLocalNameCompleteView::Create(view);
304 ASSERT(complete_view.IsValid());
305 ErrorCode status = complete_view.GetStatus();
306 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
307 std::array<uint8_t, 248> local_name_array = complete_view.GetLocalName();
308
309 local_name_ = std::string(local_name_array.begin(), local_name_array.end());
310 // erase \0
311 local_name_.erase(std::find(local_name_.begin(), local_name_.end(), '\0'), local_name_.end());
312 }
313
read_local_version_information_complete_handlerbluetooth::hci::Controller::impl314 void read_local_version_information_complete_handler(CommandCompleteView view) {
315 auto complete_view = ReadLocalVersionInformationCompleteView::Create(view);
316 ASSERT(complete_view.IsValid());
317 ErrorCode status = complete_view.GetStatus();
318 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
319
320 local_version_information_ = complete_view.GetLocalVersionInformation();
321 bluetooth::os::LogMetricBluetoothLocalVersions(
322 local_version_information_.manufacturer_name_,
323 static_cast<uint8_t>(local_version_information_.lmp_version_),
324 local_version_information_.lmp_subversion_,
325 static_cast<uint8_t>(local_version_information_.hci_version_),
326 local_version_information_.hci_revision_);
327 }
328
read_local_supported_commands_complete_handlerbluetooth::hci::Controller::impl329 void read_local_supported_commands_complete_handler(CommandCompleteView view) {
330 auto complete_view = ReadLocalSupportedCommandsCompleteView::Create(view);
331 ASSERT(complete_view.IsValid());
332 ErrorCode status = complete_view.GetStatus();
333 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
334 local_supported_commands_ = complete_view.GetSupportedCommands();
335 }
336
read_local_extended_features_complete_handlerbluetooth::hci::Controller::impl337 void read_local_extended_features_complete_handler(std::promise<void> promise, CommandCompleteView view) {
338 auto complete_view = ReadLocalExtendedFeaturesCompleteView::Create(view);
339 ASSERT(complete_view.IsValid());
340 ErrorCode status = complete_view.GetStatus();
341 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
342 uint8_t page_number = complete_view.GetPageNumber();
343 extended_lmp_features_array_.push_back(complete_view.GetExtendedLmpFeatures());
344 bluetooth::os::LogMetricBluetoothLocalSupportedFeatures(page_number, complete_view.GetExtendedLmpFeatures());
345 // Query all extended features
346 if (page_number < complete_view.GetMaximumPageNumber()) {
347 page_number++;
348 hci_->EnqueueCommand(
349 ReadLocalExtendedFeaturesBuilder::Create(page_number),
350 module_.GetHandler()->BindOnceOn(this, &Controller::impl::read_local_extended_features_complete_handler,
351 std::move(promise)));
352 } else {
353 promise.set_value();
354 }
355 }
356
read_buffer_size_complete_handlerbluetooth::hci::Controller::impl357 void read_buffer_size_complete_handler(CommandCompleteView view) {
358 auto complete_view = ReadBufferSizeCompleteView::Create(view);
359 ASSERT(complete_view.IsValid());
360 ErrorCode status = complete_view.GetStatus();
361 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
362 acl_buffer_length_ = complete_view.GetAclDataPacketLength();
363 acl_buffers_ = complete_view.GetTotalNumAclDataPackets();
364
365 sco_buffer_length_ = complete_view.GetSynchronousDataPacketLength();
366 sco_buffers_ = complete_view.GetTotalNumSynchronousDataPackets();
367 }
368
read_controller_mac_address_handlerbluetooth::hci::Controller::impl369 void read_controller_mac_address_handler(std::promise<void> promise, CommandCompleteView view) {
370 auto complete_view = ReadBdAddrCompleteView::Create(view);
371 ASSERT(complete_view.IsValid());
372 ErrorCode status = complete_view.GetStatus();
373 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
374 mac_address_ = complete_view.GetBdAddr();
375 promise.set_value();
376 }
377
le_read_buffer_size_handlerbluetooth::hci::Controller::impl378 void le_read_buffer_size_handler(CommandCompleteView view) {
379 auto complete_view = LeReadBufferSizeV1CompleteView::Create(view);
380 ASSERT(complete_view.IsValid());
381 ErrorCode status = complete_view.GetStatus();
382 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
383 le_buffer_size_ = complete_view.GetLeBufferSize();
384
385 // If LE buffer size is zero, then buffers returned by Read_Buffer_Size are shared between BR/EDR and LE.
386 if (le_buffer_size_.total_num_le_packets_ == 0) {
387 ASSERT(acl_buffers_ != 0);
388 le_buffer_size_.total_num_le_packets_ = acl_buffers_ / 2;
389 acl_buffers_ -= le_buffer_size_.total_num_le_packets_;
390 le_buffer_size_.le_data_packet_length_ = acl_buffer_length_;
391 }
392 }
393
read_local_supported_codecs_v1_handlerbluetooth::hci::Controller::impl394 void read_local_supported_codecs_v1_handler(CommandCompleteView view) {
395 auto complete_view = ReadLocalSupportedCodecsV1CompleteView::Create(view);
396 ASSERT(complete_view.IsValid());
397 ErrorCode status = complete_view.GetStatus();
398 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
399 local_supported_codec_ids_ = complete_view.GetSupportedCodecs();
400 local_supported_vendor_codec_ids_ = complete_view.GetVendorSpecificCodecs();
401 }
402
set_min_encryption_key_size_handlerbluetooth::hci::Controller::impl403 void set_min_encryption_key_size_handler(CommandCompleteView view) {
404 auto complete_view = SetMinEncryptionKeySizeCompleteView::Create(view);
405 ASSERT(complete_view.IsValid());
406 ErrorCode status = complete_view.GetStatus();
407 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
408 }
409
le_read_buffer_size_v2_handlerbluetooth::hci::Controller::impl410 void le_read_buffer_size_v2_handler(CommandCompleteView view) {
411 auto complete_view = LeReadBufferSizeV2CompleteView::Create(view);
412 ASSERT(complete_view.IsValid());
413 ErrorCode status = complete_view.GetStatus();
414 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
415 le_buffer_size_ = complete_view.GetLeBufferSize();
416 iso_buffer_size_ = complete_view.GetIsoBufferSize();
417
418 // If LE buffer size is zero, then buffers returned by Read_Buffer_Size are shared between BR/EDR and LE.
419 if (le_buffer_size_.total_num_le_packets_ == 0) {
420 ASSERT(acl_buffers_ != 0);
421 le_buffer_size_.total_num_le_packets_ = acl_buffers_ / 2;
422 acl_buffers_ -= le_buffer_size_.total_num_le_packets_;
423 le_buffer_size_.le_data_packet_length_ = acl_buffer_length_;
424 }
425 }
426
le_set_host_feature_handlerbluetooth::hci::Controller::impl427 void le_set_host_feature_handler(CommandCompleteView view) {
428 auto complete_view = LeSetHostFeatureCompleteView::Create(view);
429 ASSERT(complete_view.IsValid());
430 ErrorCode status = complete_view.GetStatus();
431 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
432 }
433
read_default_erroneous_data_reporting_handlerbluetooth::hci::Controller::impl434 void read_default_erroneous_data_reporting_handler(CommandCompleteView view) {
435 ASSERT(view.GetCommandOpCode() == OpCode::READ_DEFAULT_ERRONEOUS_DATA_REPORTING);
436 auto complete_view = ReadDefaultErroneousDataReportingCompleteView::Create(view);
437 // Check to see that the opcode was correct.
438 // log::assert_that is not used here to avoid process abort.
439 // Some devices, such as mokey_go32, may claim to support it but do not
440 // actually do so (b/277589118).
441 if (!complete_view.IsValid()) {
442 log::error("invalid command complete view");
443 return;
444 }
445
446 ErrorCode status = complete_view.GetStatus();
447 // This is an optional feature to enhance audio quality. It is okay
448 // to just return if the status is not SUCCESS.
449 if (status != ErrorCode::SUCCESS) {
450 log::error("Unexpected status: {}", ErrorCodeText(status));
451 return;
452 }
453
454 Enable erroneous_data_reporting = complete_view.GetErroneousDataReporting();
455 log::info("erroneous data reporting: {}", erroneous_data_reporting);
456
457 // Enable Erroneous Data Reporting if it is disabled and the write command is supported.
458 if (erroneous_data_reporting == Enable::DISABLED &&
459 is_supported(OpCode::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING)) {
460 std::unique_ptr<WriteDefaultErroneousDataReportingBuilder> packet =
461 WriteDefaultErroneousDataReportingBuilder::Create(Enable::ENABLED);
462 hci_->EnqueueCommand(
463 std::move(packet),
464 module_.GetHandler()->BindOnceOn(
465 this, &Controller::impl::write_default_erroneous_data_reporting_handler));
466 }
467 }
468
write_default_erroneous_data_reporting_handlerbluetooth::hci::Controller::impl469 void write_default_erroneous_data_reporting_handler(CommandCompleteView view) {
470 ASSERT(view.GetCommandOpCode() == OpCode::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING);
471 auto complete_view = WriteDefaultErroneousDataReportingCompleteView::Create(view);
472 // Check to see that the opcode was correct.
473 // log::assert_that is not used here to avoid process abort.
474 // Some devices, such as mokey_go32, may claim to support it but do not
475 // actually do so (b/277589118).
476 if (!complete_view.IsValid()) {
477 log::error("invalid command complete view");
478 return;
479 }
480
481 ErrorCode status = complete_view.GetStatus();
482 // This is an optional feature to enhance audio quality. It is okay
483 // to just return if the status is not SUCCESS.
484 if (status != ErrorCode::SUCCESS) {
485 log::error("Unexpected status: {}", ErrorCodeText(status));
486 return;
487 }
488 }
489
le_read_local_supported_features_handlerbluetooth::hci::Controller::impl490 void le_read_local_supported_features_handler(CommandCompleteView view) {
491 auto complete_view = LeReadLocalSupportedFeaturesCompleteView::Create(view);
492 ASSERT(complete_view.IsValid());
493 ErrorCode status = complete_view.GetStatus();
494 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", status, ErrorCodeText(status));
495 le_local_supported_features_ = complete_view.GetLeFeatures();
496 }
497
le_read_supported_states_handlerbluetooth::hci::Controller::impl498 void le_read_supported_states_handler(CommandCompleteView view) {
499 auto complete_view = LeReadSupportedStatesCompleteView::Create(view);
500 ASSERT(complete_view.IsValid());
501 ErrorCode status = complete_view.GetStatus();
502 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
503 le_supported_states_ = complete_view.GetLeStates();
504 }
505
le_read_accept_list_size_handlerbluetooth::hci::Controller::impl506 void le_read_accept_list_size_handler(CommandCompleteView view) {
507 auto complete_view = LeReadFilterAcceptListSizeCompleteView::Create(view);
508 ASSERT(complete_view.IsValid());
509 ErrorCode status = complete_view.GetStatus();
510 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
511 le_accept_list_size_ = complete_view.GetFilterAcceptListSize();
512 }
513
le_read_resolving_list_size_handlerbluetooth::hci::Controller::impl514 void le_read_resolving_list_size_handler(CommandCompleteView view) {
515 auto complete_view = LeReadResolvingListSizeCompleteView::Create(view);
516 ASSERT(complete_view.IsValid());
517 ErrorCode status = complete_view.GetStatus();
518 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
519 le_resolving_list_size_ = complete_view.GetResolvingListSize();
520 }
521
le_read_maximum_data_length_handlerbluetooth::hci::Controller::impl522 void le_read_maximum_data_length_handler(CommandCompleteView view) {
523 auto complete_view = LeReadMaximumDataLengthCompleteView::Create(view);
524 ASSERT(complete_view.IsValid());
525 ErrorCode status = complete_view.GetStatus();
526 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
527 le_maximum_data_length_ = complete_view.GetLeMaximumDataLength();
528 }
529
le_read_suggested_default_data_length_handlerbluetooth::hci::Controller::impl530 void le_read_suggested_default_data_length_handler(CommandCompleteView view) {
531 auto complete_view = LeReadSuggestedDefaultDataLengthCompleteView::Create(view);
532 ASSERT(complete_view.IsValid());
533 ErrorCode status = complete_view.GetStatus();
534 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
535 le_suggested_default_data_length_ = complete_view.GetTxOctets();
536 }
537
le_read_maximum_advertising_data_length_handlerbluetooth::hci::Controller::impl538 void le_read_maximum_advertising_data_length_handler(CommandCompleteView view) {
539 auto complete_view = LeReadMaximumAdvertisingDataLengthCompleteView::Create(view);
540 ASSERT(complete_view.IsValid());
541 ErrorCode status = complete_view.GetStatus();
542 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
543 le_maximum_advertising_data_length_ = complete_view.GetMaximumAdvertisingDataLength();
544 }
545
le_read_number_of_supported_advertising_sets_handlerbluetooth::hci::Controller::impl546 void le_read_number_of_supported_advertising_sets_handler(CommandCompleteView view) {
547 auto complete_view = LeReadNumberOfSupportedAdvertisingSetsCompleteView::Create(view);
548 ASSERT(complete_view.IsValid());
549 ErrorCode status = complete_view.GetStatus();
550 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
551 le_number_supported_advertising_sets_ = complete_view.GetNumberSupportedAdvertisingSets();
552 }
553
le_read_periodic_advertiser_list_size_handlerbluetooth::hci::Controller::impl554 void le_read_periodic_advertiser_list_size_handler(CommandCompleteView view) {
555 auto complete_view = LeReadPeriodicAdvertiserListSizeCompleteView::Create(view);
556 ASSERT(complete_view.IsValid());
557 ErrorCode status = complete_view.GetStatus();
558 log::assert_that(status == ErrorCode::SUCCESS, "Status {}", ErrorCodeText(status));
559 le_periodic_advertiser_list_size_ = complete_view.GetPeriodicAdvertiserListSize();
560 }
561
le_get_vendor_capabilities_handlerbluetooth::hci::Controller::impl562 void le_get_vendor_capabilities_handler(
563 std::promise<void> vendor_promise, CommandCompleteView view) {
564 auto complete_view = LeGetVendorCapabilitiesCompleteView::Create(view);
565
566 vendor_capabilities_.is_supported_ = 0x00;
567 vendor_capabilities_.max_advt_instances_ = 0x00;
568 vendor_capabilities_.offloaded_resolution_of_private_address_ = 0x00;
569 vendor_capabilities_.total_scan_results_storage_ = 0x00;
570 vendor_capabilities_.max_irk_list_sz_ = 0x00;
571 vendor_capabilities_.filtering_support_ = 0x00;
572 vendor_capabilities_.max_filter_ = 0x00;
573 vendor_capabilities_.activity_energy_info_support_ = 0x00;
574 vendor_capabilities_.version_supported_ = 0x00;
575 vendor_capabilities_.version_supported_ = 0x00;
576 vendor_capabilities_.total_num_of_advt_tracked_ = 0x00;
577 vendor_capabilities_.extended_scan_support_ = 0x00;
578 vendor_capabilities_.debug_logging_supported_ = 0x00;
579 vendor_capabilities_.le_address_generation_offloading_support_ = 0x00;
580 vendor_capabilities_.a2dp_source_offload_capability_mask_ = 0x00;
581 vendor_capabilities_.bluetooth_quality_report_support_ = 0x00;
582 vendor_capabilities_.a2dp_offload_v2_support_ = 0x00;
583
584 if (!complete_view.IsValid()) {
585 vendor_promise.set_value();
586 return;
587 }
588 vendor_capabilities_.is_supported_ = 0x01;
589
590 // v0.55
591 BaseVendorCapabilities base_vendor_capabilities = complete_view.GetBaseVendorCapabilities();
592 vendor_capabilities_.max_advt_instances_ = base_vendor_capabilities.max_advt_instances_;
593 vendor_capabilities_.offloaded_resolution_of_private_address_ =
594 base_vendor_capabilities.offloaded_resolution_of_private_address_;
595 vendor_capabilities_.total_scan_results_storage_ =
596 base_vendor_capabilities.total_scan_results_storage_;
597 vendor_capabilities_.max_irk_list_sz_ = base_vendor_capabilities.max_irk_list_sz_;
598 vendor_capabilities_.filtering_support_ = base_vendor_capabilities.filtering_support_;
599 vendor_capabilities_.max_filter_ = base_vendor_capabilities.max_filter_;
600 vendor_capabilities_.activity_energy_info_support_ =
601 base_vendor_capabilities.activity_energy_info_support_;
602
603 if (complete_view.GetPayload().size() == 0) {
604 vendor_capabilities_.version_supported_ = 55;
605 vendor_promise.set_value();
606 return;
607 }
608
609 // v0.95
610 auto v95 = LeGetVendorCapabilitiesComplete095View::Create(complete_view);
611 if (!v95.IsValid()) {
612 log::info("invalid data for hci requirements v0.95");
613 vendor_promise.set_value();
614 return;
615 }
616 vendor_capabilities_.version_supported_ = v95.GetVersionSupported();
617 vendor_capabilities_.total_num_of_advt_tracked_ = v95.GetTotalNumOfAdvtTracked();
618 vendor_capabilities_.extended_scan_support_ = v95.GetExtendedScanSupport();
619 vendor_capabilities_.debug_logging_supported_ = v95.GetDebugLoggingSupported();
620 if (vendor_capabilities_.version_supported_ <= 95 || complete_view.GetPayload().size() == 0) {
621 vendor_promise.set_value();
622 return;
623 }
624
625 // v0.96
626 auto v96 = LeGetVendorCapabilitiesComplete096View::Create(v95);
627 if (!v96.IsValid()) {
628 log::info("invalid data for hci requirements v0.96");
629 vendor_promise.set_value();
630 return;
631 }
632 vendor_capabilities_.le_address_generation_offloading_support_ =
633 v96.GetLeAddressGenerationOffloadingSupport();
634 if (vendor_capabilities_.version_supported_ <= 96 || complete_view.GetPayload().size() == 0) {
635 vendor_promise.set_value();
636 return;
637 }
638
639 // v0.98
640 auto v98 = LeGetVendorCapabilitiesComplete098View::Create(v96);
641 if (!v98.IsValid()) {
642 log::info("invalid data for hci requirements v0.98");
643 vendor_promise.set_value();
644 return;
645 }
646 vendor_capabilities_.a2dp_source_offload_capability_mask_ =
647 v98.GetA2dpSourceOffloadCapabilityMask();
648 vendor_capabilities_.bluetooth_quality_report_support_ = v98.GetBluetoothQualityReportSupport();
649
650 // v1.03
651 auto v103 = LeGetVendorCapabilitiesComplete103View::Create(v98);
652 if (!v103.IsValid()) {
653 log::info("invalid data for hci requirements v1.03");
654 vendor_promise.set_value();
655 return;
656 }
657 vendor_capabilities_.dynamic_audio_buffer_support_ = v103.GetDynamicAudioBufferSupport();
658
659 if (com::android::bluetooth::flags::a2dp_offload_codec_extensibility()) {
660 // v1.04
661 auto v104 = LeGetVendorCapabilitiesComplete104View::Create(v103);
662 if (!v104.IsValid()) {
663 log::info("invalid data for hci requirements v1.04");
664 } else {
665 vendor_capabilities_.a2dp_offload_v2_support_ = v104.GetA2dpOffloadV2Support();
666 }
667
668 if (vendor_capabilities_.dynamic_audio_buffer_support_) {
669 hci_->EnqueueCommand(
670 DabGetAudioBufferTimeCapabilityBuilder::Create(),
671 module_.GetHandler()->BindOnceOn(
672 this,
673 &Controller::impl::le_get_dynamic_audio_buffer_support_handler,
674 std::move(vendor_promise)));
675 return;
676 }
677
678 vendor_promise.set_value();
679 } else {
680 if (vendor_capabilities_.dynamic_audio_buffer_support_ == 0) {
681 vendor_promise.set_value();
682 return;
683 }
684 hci_->EnqueueCommand(
685 DabGetAudioBufferTimeCapabilityBuilder::Create(),
686 module_.GetHandler()->BindOnceOn(
687 this,
688 &Controller::impl::le_get_dynamic_audio_buffer_support_handler,
689 std::move(vendor_promise)));
690 }
691 }
692
le_get_dynamic_audio_buffer_support_handlerbluetooth::hci::Controller::impl693 void le_get_dynamic_audio_buffer_support_handler(
694 std::promise<void> vendor_promise, CommandCompleteView view) {
695 vendor_promise.set_value();
696 auto dab_complete_view = DynamicAudioBufferCompleteView::Create(view);
697 if (!dab_complete_view.IsValid()) {
698 log::warn("Invalid command complete");
699 return;
700 }
701
702 if (dab_complete_view.GetStatus() != ErrorCode::SUCCESS) {
703 log::warn("Unexpected error code {}", ErrorCodeText(dab_complete_view.GetStatus()));
704 return;
705 }
706
707 auto complete_view = DabGetAudioBufferTimeCapabilityCompleteView::Create(dab_complete_view);
708 if (!complete_view.IsValid()) {
709 log::warn("Invalid get complete");
710 return;
711 }
712 dab_supported_codecs_ = complete_view.GetAudioCodecTypeSupported();
713 dab_codec_capabilities_ = complete_view.GetAudioCodecCapabilities();
714 }
715
set_controller_dab_audio_buffer_time_completebluetooth::hci::Controller::impl716 void set_controller_dab_audio_buffer_time_complete(CommandCompleteView complete) {
717 auto dab_complete = DynamicAudioBufferCompleteView::Create(complete);
718 if (!dab_complete.IsValid()) {
719 log::warn("Invalid command complete");
720 return;
721 }
722
723 if (dab_complete.GetStatus() != ErrorCode::SUCCESS) {
724 log::warn("Unexpected return code {}", ErrorCodeText(dab_complete.GetStatus()));
725 return;
726 }
727
728 auto dab_set_complete = DabSetAudioBufferTimeCompleteView::Create(dab_complete);
729
730 if (!dab_set_complete.IsValid()) {
731 log::warn("Invalid set complete");
732 return;
733 }
734
735 log::info(
736 "Configured Media Tx Buffer, time returned = {}",
737 dab_set_complete.GetCurrentBufferTimeMs());
738 }
739
set_controller_dab_audio_buffer_timebluetooth::hci::Controller::impl740 void set_controller_dab_audio_buffer_time(uint16_t buffer_time_ms) {
741 hci_->EnqueueCommand(
742 DabSetAudioBufferTimeBuilder::Create(buffer_time_ms),
743 module_.GetHandler()->BindOnceOn(
744 this, &Controller::impl::set_controller_dab_audio_buffer_time_complete));
745 }
746
set_event_maskbluetooth::hci::Controller::impl747 void set_event_mask(uint64_t event_mask) {
748 std::unique_ptr<SetEventMaskBuilder> packet = SetEventMaskBuilder::Create(event_mask);
749 hci_->EnqueueCommand(
750 std::move(packet),
751 module_.GetHandler()->BindOnce(check_complete<SetEventMaskCompleteView>));
752 }
753
write_le_host_supportbluetooth::hci::Controller::impl754 void write_le_host_support(Enable enable, Enable deprecated_host_bit) {
755 if (deprecated_host_bit == Enable::ENABLED) {
756 // Since Bluetooth Core Spec 4.1, this bit should be 0
757 log::warn("Setting deprecated Simultaneous LE BR/EDR Host bit");
758 }
759 std::unique_ptr<WriteLeHostSupportBuilder> packet = WriteLeHostSupportBuilder::Create(enable, deprecated_host_bit);
760 hci_->EnqueueCommand(
761 std::move(packet),
762 module_.GetHandler()->BindOnce(check_complete<WriteLeHostSupportCompleteView>));
763 }
764
write_simple_pairing_modebluetooth::hci::Controller::impl765 void write_simple_pairing_mode(Enable enable) {
766 std::unique_ptr<WriteSimplePairingModeBuilder> packet = WriteSimplePairingModeBuilder::Create(enable);
767 hci_->EnqueueCommand(
768 std::move(packet),
769 module_.GetHandler()->BindOnce(check_complete<WriteSimplePairingModeCompleteView>));
770 }
771
resetbluetooth::hci::Controller::impl772 void reset() {
773 std::unique_ptr<ResetBuilder> packet = ResetBuilder::Create();
774 hci_->EnqueueCommand(
775 std::move(packet), module_.GetHandler()->BindOnce(check_complete<ResetCompleteView>));
776 }
777
le_randbluetooth::hci::Controller::impl778 void le_rand(LeRandCallback cb) {
779 std::unique_ptr<LeRandBuilder> packet = LeRandBuilder::Create();
780 hci_->EnqueueCommand(
781 std::move(packet),
782 module_.GetHandler()->BindOnceOn(this, &Controller::impl::le_rand_cb, std::move(cb)));
783 }
784
le_rand_cbbluetooth::hci::Controller::impl785 void le_rand_cb(LeRandCallback cb, CommandCompleteView view) {
786 ASSERT(view.IsValid());
787 auto status_view = LeRandCompleteView::Create(view);
788 ASSERT(status_view.IsValid());
789 ASSERT(status_view.GetStatus() == ErrorCode::SUCCESS);
790 std::move(cb)(status_view.GetRandomNumber());
791 }
792
set_event_filterbluetooth::hci::Controller::impl793 void set_event_filter(std::unique_ptr<SetEventFilterBuilder> packet) {
794 hci_->EnqueueCommand(
795 std::move(packet),
796 module_.GetHandler()->BindOnce(check_complete<SetEventFilterCompleteView>));
797 }
798
write_local_namebluetooth::hci::Controller::impl799 void write_local_name(std::string local_name) {
800 ASSERT(local_name.length() <= 248);
801 // Fill remaining char with 0
802 local_name.append(std::string(248 - local_name.length(), '\0'));
803 std::array<uint8_t, 248> local_name_array;
804 std::copy(std::begin(local_name), std::end(local_name), std::begin(local_name_array));
805
806 std::unique_ptr<WriteLocalNameBuilder> packet = WriteLocalNameBuilder::Create(local_name_array);
807 hci_->EnqueueCommand(
808 std::move(packet),
809 module_.GetHandler()->BindOnce(check_complete<WriteLocalNameCompleteView>));
810 }
811
host_buffer_sizebluetooth::hci::Controller::impl812 void host_buffer_size(uint16_t host_acl_data_packet_length, uint8_t host_synchronous_data_packet_length,
813 uint16_t host_total_num_acl_data_packets, uint16_t host_total_num_synchronous_data_packets) {
814 std::unique_ptr<HostBufferSizeBuilder> packet =
815 HostBufferSizeBuilder::Create(host_acl_data_packet_length, host_synchronous_data_packet_length,
816 host_total_num_acl_data_packets, host_total_num_synchronous_data_packets);
817 hci_->EnqueueCommand(
818 std::move(packet),
819 module_.GetHandler()->BindOnce(check_complete<HostBufferSizeCompleteView>));
820 }
821
le_set_event_maskbluetooth::hci::Controller::impl822 void le_set_event_mask(uint64_t le_event_mask) {
823 std::unique_ptr<LeSetEventMaskBuilder> packet = LeSetEventMaskBuilder::Create(le_event_mask);
824 hci_->EnqueueCommand(
825 std::move(packet),
826 module_.GetHandler()->BindOnce(check_complete<LeSetEventMaskCompleteView>));
827 }
828
829 #define OP_CODE_MAPPING(name) \
830 case OpCode::name: { \
831 uint16_t index = (uint16_t)OpCodeIndex::name; \
832 uint16_t byte_index = index / 10; \
833 uint16_t bit_index = index % 10; \
834 bool supported = local_supported_commands_[byte_index] & (1 << bit_index); \
835 if (!supported) { \
836 log::debug("unsupported command opcode: 0x{:04x}", (uint16_t)OpCode::name); \
837 } \
838 return supported; \
839 }
840
841 void Dump(
842 std::promise<flatbuffers::Offset<ControllerData>> promise, flatbuffers::FlatBufferBuilder* fb_builder) const;
843
is_supportedbluetooth::hci::Controller::impl844 bool is_supported(OpCode op_code) {
845 switch (op_code) {
846 OP_CODE_MAPPING(INQUIRY)
847 OP_CODE_MAPPING(INQUIRY_CANCEL)
848 OP_CODE_MAPPING(PERIODIC_INQUIRY_MODE)
849 OP_CODE_MAPPING(EXIT_PERIODIC_INQUIRY_MODE)
850 OP_CODE_MAPPING(CREATE_CONNECTION)
851 OP_CODE_MAPPING(DISCONNECT)
852 OP_CODE_MAPPING(CREATE_CONNECTION_CANCEL)
853 OP_CODE_MAPPING(ACCEPT_CONNECTION_REQUEST)
854 OP_CODE_MAPPING(REJECT_CONNECTION_REQUEST)
855 OP_CODE_MAPPING(LINK_KEY_REQUEST_REPLY)
856 OP_CODE_MAPPING(LINK_KEY_REQUEST_NEGATIVE_REPLY)
857 OP_CODE_MAPPING(PIN_CODE_REQUEST_REPLY)
858 OP_CODE_MAPPING(PIN_CODE_REQUEST_NEGATIVE_REPLY)
859 OP_CODE_MAPPING(CHANGE_CONNECTION_PACKET_TYPE)
860 OP_CODE_MAPPING(AUTHENTICATION_REQUESTED)
861 OP_CODE_MAPPING(SET_CONNECTION_ENCRYPTION)
862 OP_CODE_MAPPING(CHANGE_CONNECTION_LINK_KEY)
863 OP_CODE_MAPPING(CENTRAL_LINK_KEY)
864 OP_CODE_MAPPING(REMOTE_NAME_REQUEST)
865 OP_CODE_MAPPING(REMOTE_NAME_REQUEST_CANCEL)
866 OP_CODE_MAPPING(READ_REMOTE_SUPPORTED_FEATURES)
867 OP_CODE_MAPPING(READ_REMOTE_EXTENDED_FEATURES)
868 OP_CODE_MAPPING(READ_REMOTE_VERSION_INFORMATION)
869 OP_CODE_MAPPING(READ_CLOCK_OFFSET)
870 OP_CODE_MAPPING(READ_LMP_HANDLE)
871 OP_CODE_MAPPING(SETUP_SYNCHRONOUS_CONNECTION)
872 OP_CODE_MAPPING(ACCEPT_SYNCHRONOUS_CONNECTION)
873 OP_CODE_MAPPING(REJECT_SYNCHRONOUS_CONNECTION)
874 OP_CODE_MAPPING(IO_CAPABILITY_REQUEST_REPLY)
875 OP_CODE_MAPPING(USER_CONFIRMATION_REQUEST_REPLY)
876 OP_CODE_MAPPING(USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY)
877 OP_CODE_MAPPING(USER_PASSKEY_REQUEST_REPLY)
878 OP_CODE_MAPPING(USER_PASSKEY_REQUEST_NEGATIVE_REPLY)
879 OP_CODE_MAPPING(REMOTE_OOB_DATA_REQUEST_REPLY)
880 OP_CODE_MAPPING(REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY)
881 OP_CODE_MAPPING(IO_CAPABILITY_REQUEST_NEGATIVE_REPLY)
882 OP_CODE_MAPPING(ENHANCED_SETUP_SYNCHRONOUS_CONNECTION)
883 OP_CODE_MAPPING(ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION)
884 OP_CODE_MAPPING(TRUNCATED_PAGE)
885 OP_CODE_MAPPING(TRUNCATED_PAGE_CANCEL)
886 OP_CODE_MAPPING(SET_CONNECTIONLESS_PERIPHERAL_BROADCAST)
887 OP_CODE_MAPPING(SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE)
888 OP_CODE_MAPPING(START_SYNCHRONIZATION_TRAIN)
889 OP_CODE_MAPPING(RECEIVE_SYNCHRONIZATION_TRAIN)
890 OP_CODE_MAPPING(REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY)
891 OP_CODE_MAPPING(HOLD_MODE)
892 OP_CODE_MAPPING(SNIFF_MODE)
893 OP_CODE_MAPPING(EXIT_SNIFF_MODE)
894 OP_CODE_MAPPING(PARK_STATE)
895 OP_CODE_MAPPING(EXIT_PARK_STATE)
896 OP_CODE_MAPPING(QOS_SETUP)
897 OP_CODE_MAPPING(ROLE_DISCOVERY)
898 OP_CODE_MAPPING(SWITCH_ROLE)
899 OP_CODE_MAPPING(READ_LINK_POLICY_SETTINGS)
900 OP_CODE_MAPPING(WRITE_LINK_POLICY_SETTINGS)
901 OP_CODE_MAPPING(READ_DEFAULT_LINK_POLICY_SETTINGS)
902 OP_CODE_MAPPING(WRITE_DEFAULT_LINK_POLICY_SETTINGS)
903 OP_CODE_MAPPING(FLOW_SPECIFICATION)
904 OP_CODE_MAPPING(SNIFF_SUBRATING)
905 OP_CODE_MAPPING(SET_EVENT_MASK)
906 OP_CODE_MAPPING(RESET)
907 OP_CODE_MAPPING(SET_EVENT_FILTER)
908 OP_CODE_MAPPING(FLUSH)
909 OP_CODE_MAPPING(READ_PIN_TYPE)
910 OP_CODE_MAPPING(WRITE_PIN_TYPE)
911 OP_CODE_MAPPING(READ_STORED_LINK_KEY)
912 OP_CODE_MAPPING(WRITE_STORED_LINK_KEY)
913 OP_CODE_MAPPING(DELETE_STORED_LINK_KEY)
914 OP_CODE_MAPPING(WRITE_LOCAL_NAME)
915 OP_CODE_MAPPING(READ_LOCAL_NAME)
916 OP_CODE_MAPPING(READ_CONNECTION_ACCEPT_TIMEOUT)
917 OP_CODE_MAPPING(WRITE_CONNECTION_ACCEPT_TIMEOUT)
918 OP_CODE_MAPPING(READ_PAGE_TIMEOUT)
919 OP_CODE_MAPPING(WRITE_PAGE_TIMEOUT)
920 OP_CODE_MAPPING(READ_SCAN_ENABLE)
921 OP_CODE_MAPPING(WRITE_SCAN_ENABLE)
922 OP_CODE_MAPPING(READ_PAGE_SCAN_ACTIVITY)
923 OP_CODE_MAPPING(WRITE_PAGE_SCAN_ACTIVITY)
924 OP_CODE_MAPPING(READ_INQUIRY_SCAN_ACTIVITY)
925 OP_CODE_MAPPING(WRITE_INQUIRY_SCAN_ACTIVITY)
926 OP_CODE_MAPPING(READ_AUTHENTICATION_ENABLE)
927 OP_CODE_MAPPING(WRITE_AUTHENTICATION_ENABLE)
928 OP_CODE_MAPPING(READ_CLASS_OF_DEVICE)
929 OP_CODE_MAPPING(WRITE_CLASS_OF_DEVICE)
930 OP_CODE_MAPPING(READ_VOICE_SETTING)
931 OP_CODE_MAPPING(WRITE_VOICE_SETTING)
932 OP_CODE_MAPPING(READ_AUTOMATIC_FLUSH_TIMEOUT)
933 OP_CODE_MAPPING(WRITE_AUTOMATIC_FLUSH_TIMEOUT)
934 OP_CODE_MAPPING(READ_NUM_BROADCAST_RETRANSMITS)
935 OP_CODE_MAPPING(WRITE_NUM_BROADCAST_RETRANSMITS)
936 OP_CODE_MAPPING(READ_HOLD_MODE_ACTIVITY)
937 OP_CODE_MAPPING(WRITE_HOLD_MODE_ACTIVITY)
938 OP_CODE_MAPPING(READ_TRANSMIT_POWER_LEVEL)
939 OP_CODE_MAPPING(READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE)
940 OP_CODE_MAPPING(WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE)
941 OP_CODE_MAPPING(SET_CONTROLLER_TO_HOST_FLOW_CONTROL)
942 OP_CODE_MAPPING(HOST_BUFFER_SIZE)
943 OP_CODE_MAPPING(HOST_NUMBER_OF_COMPLETED_PACKETS)
944 OP_CODE_MAPPING(READ_LINK_SUPERVISION_TIMEOUT)
945 OP_CODE_MAPPING(WRITE_LINK_SUPERVISION_TIMEOUT)
946 OP_CODE_MAPPING(READ_NUMBER_OF_SUPPORTED_IAC)
947 OP_CODE_MAPPING(READ_CURRENT_IAC_LAP)
948 OP_CODE_MAPPING(WRITE_CURRENT_IAC_LAP)
949 OP_CODE_MAPPING(SET_AFH_HOST_CHANNEL_CLASSIFICATION)
950 OP_CODE_MAPPING(READ_INQUIRY_SCAN_TYPE)
951 OP_CODE_MAPPING(WRITE_INQUIRY_SCAN_TYPE)
952 OP_CODE_MAPPING(READ_INQUIRY_MODE)
953 OP_CODE_MAPPING(WRITE_INQUIRY_MODE)
954 OP_CODE_MAPPING(READ_PAGE_SCAN_TYPE)
955 OP_CODE_MAPPING(WRITE_PAGE_SCAN_TYPE)
956 OP_CODE_MAPPING(READ_AFH_CHANNEL_ASSESSMENT_MODE)
957 OP_CODE_MAPPING(WRITE_AFH_CHANNEL_ASSESSMENT_MODE)
958 OP_CODE_MAPPING(READ_EXTENDED_INQUIRY_RESPONSE)
959 OP_CODE_MAPPING(WRITE_EXTENDED_INQUIRY_RESPONSE)
960 OP_CODE_MAPPING(REFRESH_ENCRYPTION_KEY)
961 OP_CODE_MAPPING(READ_SIMPLE_PAIRING_MODE)
962 OP_CODE_MAPPING(WRITE_SIMPLE_PAIRING_MODE)
963 OP_CODE_MAPPING(READ_LOCAL_OOB_DATA)
964 OP_CODE_MAPPING(READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL)
965 OP_CODE_MAPPING(WRITE_INQUIRY_TRANSMIT_POWER_LEVEL)
966 OP_CODE_MAPPING(READ_DEFAULT_ERRONEOUS_DATA_REPORTING)
967 OP_CODE_MAPPING(WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING)
968 OP_CODE_MAPPING(ENHANCED_FLUSH)
969 OP_CODE_MAPPING(SEND_KEYPRESS_NOTIFICATION)
970 OP_CODE_MAPPING(SET_EVENT_MASK_PAGE_2)
971 OP_CODE_MAPPING(READ_FLOW_CONTROL_MODE)
972 OP_CODE_MAPPING(WRITE_FLOW_CONTROL_MODE)
973 OP_CODE_MAPPING(READ_ENHANCED_TRANSMIT_POWER_LEVEL)
974 OP_CODE_MAPPING(READ_LE_HOST_SUPPORT)
975 OP_CODE_MAPPING(WRITE_LE_HOST_SUPPORT)
976 OP_CODE_MAPPING(SET_MWS_CHANNEL_PARAMETERS)
977 OP_CODE_MAPPING(SET_EXTERNAL_FRAME_CONFIGURATION)
978 OP_CODE_MAPPING(SET_MWS_SIGNALING)
979 OP_CODE_MAPPING(SET_MWS_TRANSPORT_LAYER)
980 OP_CODE_MAPPING(SET_MWS_SCAN_FREQUENCY_TABLE)
981 OP_CODE_MAPPING(SET_MWS_PATTERN_CONFIGURATION)
982 OP_CODE_MAPPING(SET_RESERVED_LT_ADDR)
983 OP_CODE_MAPPING(DELETE_RESERVED_LT_ADDR)
984 OP_CODE_MAPPING(SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA)
985 OP_CODE_MAPPING(READ_SYNCHRONIZATION_TRAIN_PARAMETERS)
986 OP_CODE_MAPPING(WRITE_SYNCHRONIZATION_TRAIN_PARAMETERS)
987 OP_CODE_MAPPING(READ_SECURE_CONNECTIONS_HOST_SUPPORT)
988 OP_CODE_MAPPING(WRITE_SECURE_CONNECTIONS_HOST_SUPPORT)
989 OP_CODE_MAPPING(READ_AUTHENTICATED_PAYLOAD_TIMEOUT)
990 OP_CODE_MAPPING(WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT)
991 OP_CODE_MAPPING(READ_LOCAL_OOB_EXTENDED_DATA)
992 OP_CODE_MAPPING(READ_EXTENDED_PAGE_TIMEOUT)
993 OP_CODE_MAPPING(WRITE_EXTENDED_PAGE_TIMEOUT)
994 OP_CODE_MAPPING(READ_EXTENDED_INQUIRY_LENGTH)
995 OP_CODE_MAPPING(WRITE_EXTENDED_INQUIRY_LENGTH)
996 OP_CODE_MAPPING(SET_ECOSYSTEM_BASE_INTERVAL)
997 OP_CODE_MAPPING(CONFIGURE_DATA_PATH)
998 OP_CODE_MAPPING(SET_MIN_ENCRYPTION_KEY_SIZE)
999 OP_CODE_MAPPING(READ_LOCAL_VERSION_INFORMATION)
1000 OP_CODE_MAPPING(READ_LOCAL_SUPPORTED_FEATURES)
1001 OP_CODE_MAPPING(READ_LOCAL_EXTENDED_FEATURES)
1002 OP_CODE_MAPPING(READ_BUFFER_SIZE)
1003 OP_CODE_MAPPING(READ_BD_ADDR)
1004 OP_CODE_MAPPING(READ_DATA_BLOCK_SIZE)
1005 OP_CODE_MAPPING(READ_LOCAL_SUPPORTED_CODECS_V1)
1006 OP_CODE_MAPPING(READ_LOCAL_SIMPLE_PAIRING_OPTIONS)
1007 OP_CODE_MAPPING(READ_LOCAL_SUPPORTED_CODECS_V2)
1008 OP_CODE_MAPPING(READ_LOCAL_SUPPORTED_CODEC_CAPABILITIES)
1009 OP_CODE_MAPPING(READ_LOCAL_SUPPORTED_CONTROLLER_DELAY)
1010 OP_CODE_MAPPING(READ_FAILED_CONTACT_COUNTER)
1011 OP_CODE_MAPPING(RESET_FAILED_CONTACT_COUNTER)
1012 OP_CODE_MAPPING(READ_LINK_QUALITY)
1013 OP_CODE_MAPPING(READ_RSSI)
1014 OP_CODE_MAPPING(READ_AFH_CHANNEL_MAP)
1015 OP_CODE_MAPPING(READ_CLOCK)
1016 OP_CODE_MAPPING(READ_ENCRYPTION_KEY_SIZE)
1017 OP_CODE_MAPPING(GET_MWS_TRANSPORT_LAYER_CONFIGURATION)
1018 OP_CODE_MAPPING(SET_TRIGGERED_CLOCK_CAPTURE)
1019 OP_CODE_MAPPING(READ_LOOPBACK_MODE)
1020 OP_CODE_MAPPING(WRITE_LOOPBACK_MODE)
1021 OP_CODE_MAPPING(ENABLE_DEVICE_UNDER_TEST_MODE)
1022 OP_CODE_MAPPING(WRITE_SIMPLE_PAIRING_DEBUG_MODE)
1023 OP_CODE_MAPPING(WRITE_SECURE_CONNECTIONS_TEST_MODE)
1024 OP_CODE_MAPPING(LE_SET_EVENT_MASK)
1025 OP_CODE_MAPPING(LE_READ_BUFFER_SIZE_V1)
1026 OP_CODE_MAPPING(LE_READ_LOCAL_SUPPORTED_FEATURES)
1027 OP_CODE_MAPPING(LE_SET_RANDOM_ADDRESS)
1028 OP_CODE_MAPPING(LE_SET_ADVERTISING_PARAMETERS)
1029 OP_CODE_MAPPING(LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER)
1030 OP_CODE_MAPPING(LE_SET_ADVERTISING_DATA)
1031 OP_CODE_MAPPING(LE_SET_SCAN_RESPONSE_DATA)
1032 OP_CODE_MAPPING(LE_SET_ADVERTISING_ENABLE)
1033 OP_CODE_MAPPING(LE_SET_SCAN_PARAMETERS)
1034 OP_CODE_MAPPING(LE_SET_SCAN_ENABLE)
1035 OP_CODE_MAPPING(LE_CREATE_CONNECTION)
1036 OP_CODE_MAPPING(LE_CREATE_CONNECTION_CANCEL)
1037 OP_CODE_MAPPING(LE_READ_FILTER_ACCEPT_LIST_SIZE)
1038 OP_CODE_MAPPING(LE_CLEAR_FILTER_ACCEPT_LIST)
1039 OP_CODE_MAPPING(LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST)
1040 OP_CODE_MAPPING(LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST)
1041 OP_CODE_MAPPING(LE_CONNECTION_UPDATE)
1042 OP_CODE_MAPPING(LE_SET_HOST_CHANNEL_CLASSIFICATION)
1043 OP_CODE_MAPPING(LE_READ_CHANNEL_MAP)
1044 OP_CODE_MAPPING(LE_READ_REMOTE_FEATURES)
1045 OP_CODE_MAPPING(LE_ENCRYPT)
1046 OP_CODE_MAPPING(LE_RAND)
1047 OP_CODE_MAPPING(LE_START_ENCRYPTION)
1048 OP_CODE_MAPPING(LE_LONG_TERM_KEY_REQUEST_REPLY)
1049 OP_CODE_MAPPING(LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY)
1050 OP_CODE_MAPPING(LE_READ_SUPPORTED_STATES)
1051 OP_CODE_MAPPING(LE_RECEIVER_TEST_V1)
1052 OP_CODE_MAPPING(LE_TRANSMITTER_TEST_V1)
1053 OP_CODE_MAPPING(LE_TEST_END)
1054 OP_CODE_MAPPING(LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY)
1055 OP_CODE_MAPPING(LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY)
1056 OP_CODE_MAPPING(LE_SET_DATA_LENGTH)
1057 OP_CODE_MAPPING(LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH)
1058 OP_CODE_MAPPING(LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH)
1059 OP_CODE_MAPPING(LE_READ_LOCAL_P_256_PUBLIC_KEY)
1060 OP_CODE_MAPPING(LE_GENERATE_DHKEY_V1)
1061 OP_CODE_MAPPING(LE_ADD_DEVICE_TO_RESOLVING_LIST)
1062 OP_CODE_MAPPING(LE_REMOVE_DEVICE_FROM_RESOLVING_LIST)
1063 OP_CODE_MAPPING(LE_CLEAR_RESOLVING_LIST)
1064 OP_CODE_MAPPING(LE_READ_RESOLVING_LIST_SIZE)
1065 OP_CODE_MAPPING(LE_READ_PEER_RESOLVABLE_ADDRESS)
1066 OP_CODE_MAPPING(LE_READ_LOCAL_RESOLVABLE_ADDRESS)
1067 OP_CODE_MAPPING(LE_SET_ADDRESS_RESOLUTION_ENABLE)
1068 OP_CODE_MAPPING(LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT)
1069 OP_CODE_MAPPING(LE_READ_MAXIMUM_DATA_LENGTH)
1070 OP_CODE_MAPPING(LE_READ_PHY)
1071 OP_CODE_MAPPING(LE_SET_DEFAULT_PHY)
1072 OP_CODE_MAPPING(LE_SET_PHY)
1073 OP_CODE_MAPPING(LE_RECEIVER_TEST_V2)
1074 OP_CODE_MAPPING(LE_TRANSMITTER_TEST_V2)
1075 OP_CODE_MAPPING(LE_SET_ADVERTISING_SET_RANDOM_ADDRESS)
1076 OP_CODE_MAPPING(LE_SET_EXTENDED_ADVERTISING_PARAMETERS)
1077 OP_CODE_MAPPING(LE_SET_EXTENDED_ADVERTISING_DATA)
1078 OP_CODE_MAPPING(LE_SET_EXTENDED_SCAN_RESPONSE_DATA)
1079 OP_CODE_MAPPING(LE_SET_EXTENDED_ADVERTISING_ENABLE)
1080 OP_CODE_MAPPING(LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH)
1081 OP_CODE_MAPPING(LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS)
1082 OP_CODE_MAPPING(LE_REMOVE_ADVERTISING_SET)
1083 OP_CODE_MAPPING(LE_CLEAR_ADVERTISING_SETS)
1084 OP_CODE_MAPPING(LE_SET_PERIODIC_ADVERTISING_PARAMETERS)
1085 OP_CODE_MAPPING(LE_SET_PERIODIC_ADVERTISING_DATA)
1086 OP_CODE_MAPPING(LE_SET_PERIODIC_ADVERTISING_ENABLE)
1087 OP_CODE_MAPPING(LE_SET_EXTENDED_SCAN_PARAMETERS)
1088 OP_CODE_MAPPING(LE_SET_EXTENDED_SCAN_ENABLE)
1089 OP_CODE_MAPPING(LE_EXTENDED_CREATE_CONNECTION)
1090 OP_CODE_MAPPING(LE_PERIODIC_ADVERTISING_CREATE_SYNC)
1091 OP_CODE_MAPPING(LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL)
1092 OP_CODE_MAPPING(LE_PERIODIC_ADVERTISING_TERMINATE_SYNC)
1093 OP_CODE_MAPPING(LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST)
1094 OP_CODE_MAPPING(LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST)
1095 OP_CODE_MAPPING(LE_CLEAR_PERIODIC_ADVERTISER_LIST)
1096 OP_CODE_MAPPING(LE_READ_PERIODIC_ADVERTISER_LIST_SIZE)
1097 OP_CODE_MAPPING(LE_READ_TRANSMIT_POWER)
1098 OP_CODE_MAPPING(LE_READ_RF_PATH_COMPENSATION_POWER)
1099 OP_CODE_MAPPING(LE_WRITE_RF_PATH_COMPENSATION_POWER)
1100 OP_CODE_MAPPING(LE_SET_PRIVACY_MODE)
1101 OP_CODE_MAPPING(LE_RECEIVER_TEST_V3)
1102 OP_CODE_MAPPING(LE_TRANSMITTER_TEST_V3)
1103 OP_CODE_MAPPING(LE_SET_CONNECTIONLESS_CTE_TRANSMIT_PARAMETERS)
1104 OP_CODE_MAPPING(LE_SET_CONNECTIONLESS_CTE_TRANSMIT_ENABLE)
1105 OP_CODE_MAPPING(LE_SET_CONNECTIONLESS_IQ_SAMPLING_ENABLE)
1106 OP_CODE_MAPPING(LE_SET_CONNECTION_CTE_RECEIVE_PARAMETERS)
1107 OP_CODE_MAPPING(LE_SET_CONNECTION_CTE_TRANSMIT_PARAMETERS)
1108 OP_CODE_MAPPING(LE_CONNECTION_CTE_REQUEST_ENABLE)
1109 OP_CODE_MAPPING(LE_CONNECTION_CTE_RESPONSE_ENABLE)
1110 OP_CODE_MAPPING(LE_READ_ANTENNA_INFORMATION)
1111 OP_CODE_MAPPING(LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE)
1112 OP_CODE_MAPPING(LE_PERIODIC_ADVERTISING_SYNC_TRANSFER)
1113 OP_CODE_MAPPING(LE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER)
1114 OP_CODE_MAPPING(LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS)
1115 OP_CODE_MAPPING(LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS)
1116 OP_CODE_MAPPING(LE_GENERATE_DHKEY_V2)
1117 OP_CODE_MAPPING(LE_MODIFY_SLEEP_CLOCK_ACCURACY)
1118 OP_CODE_MAPPING(LE_READ_BUFFER_SIZE_V2)
1119 OP_CODE_MAPPING(LE_READ_ISO_TX_SYNC)
1120 OP_CODE_MAPPING(LE_SET_CIG_PARAMETERS)
1121 OP_CODE_MAPPING(LE_SET_CIG_PARAMETERS_TEST)
1122 OP_CODE_MAPPING(LE_CREATE_CIS)
1123 OP_CODE_MAPPING(LE_REMOVE_CIG)
1124 OP_CODE_MAPPING(LE_ACCEPT_CIS_REQUEST)
1125 OP_CODE_MAPPING(LE_REJECT_CIS_REQUEST)
1126 OP_CODE_MAPPING(LE_CREATE_BIG)
1127 OP_CODE_MAPPING(LE_CREATE_BIG_TEST)
1128 OP_CODE_MAPPING(LE_TERMINATE_BIG)
1129 OP_CODE_MAPPING(LE_BIG_CREATE_SYNC)
1130 OP_CODE_MAPPING(LE_BIG_TERMINATE_SYNC)
1131 OP_CODE_MAPPING(LE_REQUEST_PEER_SCA)
1132 OP_CODE_MAPPING(LE_SETUP_ISO_DATA_PATH)
1133 OP_CODE_MAPPING(LE_REMOVE_ISO_DATA_PATH)
1134 OP_CODE_MAPPING(LE_ISO_TRANSMIT_TEST)
1135 OP_CODE_MAPPING(LE_ISO_RECEIVE_TEST)
1136 OP_CODE_MAPPING(LE_ISO_READ_TEST_COUNTERS)
1137 OP_CODE_MAPPING(LE_ISO_TEST_END)
1138 OP_CODE_MAPPING(LE_SET_HOST_FEATURE)
1139 OP_CODE_MAPPING(LE_READ_ISO_LINK_QUALITY)
1140 OP_CODE_MAPPING(LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL)
1141 OP_CODE_MAPPING(LE_READ_REMOTE_TRANSMIT_POWER_LEVEL)
1142 OP_CODE_MAPPING(LE_SET_PATH_LOSS_REPORTING_PARAMETERS)
1143 OP_CODE_MAPPING(LE_SET_PATH_LOSS_REPORTING_ENABLE)
1144 OP_CODE_MAPPING(LE_SET_TRANSMIT_POWER_REPORTING_ENABLE)
1145 OP_CODE_MAPPING(LE_TRANSMITTER_TEST_V4)
1146 OP_CODE_MAPPING(LE_SET_DATA_RELATED_ADDRESS_CHANGES)
1147 OP_CODE_MAPPING(LE_SET_DEFAULT_SUBRATE)
1148 OP_CODE_MAPPING(LE_SUBRATE_REQUEST)
1149
1150 // deprecated
1151 case OpCode::ADD_SCO_CONNECTION:
1152 return false;
1153
1154 // vendor specific
1155 case OpCode::LE_GET_VENDOR_CAPABILITIES:
1156 return vendor_capabilities_.is_supported_ == 0x01;
1157 case OpCode::LE_MULTI_ADVT:
1158 return vendor_capabilities_.max_advt_instances_ != 0x00;
1159 case OpCode::LE_BATCH_SCAN:
1160 return vendor_capabilities_.total_scan_results_storage_ != 0x00;
1161 case OpCode::LE_ADV_FILTER:
1162 return vendor_capabilities_.filtering_support_ == 0x01;
1163 case OpCode::LE_ENERGY_INFO:
1164 return vendor_capabilities_.activity_energy_info_support_ == 0x01;
1165 case OpCode::LE_EXTENDED_SCAN_PARAMS:
1166 return vendor_capabilities_.extended_scan_support_ == 0x01;
1167 case OpCode::CONTROLLER_DEBUG_INFO:
1168 return vendor_capabilities_.debug_logging_supported_ == 0x01;
1169 case OpCode::CONTROLLER_A2DP_OPCODE:
1170 return vendor_capabilities_.a2dp_source_offload_capability_mask_ != 0x00;
1171 case OpCode::CONTROLLER_BQR:
1172 return vendor_capabilities_.bluetooth_quality_report_support_ == 0x01;
1173 case OpCode::DYNAMIC_AUDIO_BUFFER:
1174 return vendor_capabilities_.dynamic_audio_buffer_support_ > 0x00;
1175 // Before MSFT extension is fully supported, return false for the following MSFT_OPCODE_XXXX for now.
1176 case OpCode::MSFT_OPCODE_INTEL:
1177 return false;
1178 case OpCode::MSFT_OPCODE_MEDIATEK:
1179 return false;
1180 case OpCode::MSFT_OPCODE_QUALCOMM:
1181 return false;
1182 // undefined in local_supported_commands_
1183 case OpCode::READ_LOCAL_SUPPORTED_COMMANDS:
1184 return true;
1185 case OpCode::NONE:
1186 return false;
1187 case OpCode::LE_CS_READ_LOCAL_SUPPORTED_CAPABILITIES:
1188 case OpCode::LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES:
1189 case OpCode::LE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPABILITIES:
1190 case OpCode::LE_CS_SECURITY_ENABLE:
1191 case OpCode::LE_CS_SET_DEFAULT_SETTINGS:
1192 case OpCode::LE_CS_READ_REMOTE_FAE_TABLE:
1193 case OpCode::LE_CS_WRITE_CACHED_REMOTE_FAE_TABLE:
1194 case OpCode::LE_CS_CREATE_CONFIG:
1195 case OpCode::LE_CS_REMOVE_CONFIG:
1196 case OpCode::LE_CS_SET_CHANNEL_CLASSIFICATION:
1197 case OpCode::LE_CS_PROCEDURE_ENABLE:
1198 case OpCode::LE_CS_TEST:
1199 case OpCode::LE_CS_TEST_END:
1200 case OpCode::LE_CS_SET_PROCEDURE_PARAMETERS:
1201 // TODO add to OP_CODE_MAPPING list
1202 return false;
1203 }
1204 return false;
1205 }
1206 #undef OP_CODE_MAPPING
1207
1208 Controller& module_;
1209
1210 HciLayer* hci_;
1211
1212 CompletedAclPacketsCallback acl_credits_callback_{};
1213 CompletedAclPacketsCallback acl_monitor_credits_callback_{};
1214 LocalVersionInformation local_version_information_{};
1215 std::array<uint8_t, 64> local_supported_commands_{};
1216 std::vector<uint64_t> extended_lmp_features_array_{};
1217 uint16_t acl_buffer_length_{};
1218 uint16_t acl_buffers_{};
1219 uint8_t sco_buffer_length_{};
1220 uint16_t sco_buffers_{};
1221 Address mac_address_{};
1222 std::string local_name_{};
1223 LeBufferSize le_buffer_size_{};
1224 std::vector<uint8_t> local_supported_codec_ids_{};
1225 std::vector<uint32_t> local_supported_vendor_codec_ids_{};
1226 LeBufferSize iso_buffer_size_{};
1227 uint64_t le_local_supported_features_{};
1228 uint64_t le_supported_states_{};
1229 uint8_t le_accept_list_size_{};
1230 uint8_t le_resolving_list_size_{};
1231 LeMaximumDataLength le_maximum_data_length_{};
1232 uint16_t le_maximum_advertising_data_length_{};
1233 uint16_t le_suggested_default_data_length_{};
1234 uint8_t le_number_supported_advertising_sets_{};
1235 uint8_t le_periodic_advertiser_list_size_{};
1236 VendorCapabilities vendor_capabilities_{};
1237 uint32_t dab_supported_codecs_{};
1238 std::array<DynamicAudioBufferCodecCapability, 32> dab_codec_capabilities_{};
1239 }; // namespace hci
1240
Controller()1241 Controller::Controller() : impl_(std::make_unique<impl>(*this)) {}
1242
1243 Controller::~Controller() = default;
1244
RegisterCompletedAclPacketsCallback(CompletedAclPacketsCallback cb)1245 void Controller::RegisterCompletedAclPacketsCallback(CompletedAclPacketsCallback cb) {
1246 CallOn(impl_.get(), &impl::register_completed_acl_packets_callback, cb);
1247 }
1248
UnregisterCompletedAclPacketsCallback()1249 void Controller::UnregisterCompletedAclPacketsCallback() {
1250 CallOn(impl_.get(), &impl::unregister_completed_acl_packets_callback);
1251 }
1252
RegisterCompletedMonitorAclPacketsCallback(CompletedAclPacketsCallback cb)1253 void Controller::RegisterCompletedMonitorAclPacketsCallback(CompletedAclPacketsCallback cb) {
1254 CallOn(impl_.get(), &impl::register_completed_monitor_acl_packets_callback, cb);
1255 }
1256
UnregisterCompletedMonitorAclPacketsCallback()1257 void Controller::UnregisterCompletedMonitorAclPacketsCallback() {
1258 CallOn(impl_.get(), &impl::unregister_completed_monitor_acl_packets_callback);
1259 }
1260
GetLocalName() const1261 std::string Controller::GetLocalName() const {
1262 return impl_->local_name_;
1263 }
1264
GetLocalVersionInformation() const1265 LocalVersionInformation Controller::GetLocalVersionInformation() const {
1266 return impl_->local_version_information_;
1267 }
1268
GetLocalSupportedBrEdrCodecIds() const1269 std::vector<uint8_t> Controller::GetLocalSupportedBrEdrCodecIds() const {
1270 return impl_->local_supported_codec_ids_;
1271 }
1272
1273 #define BIT(x) (0x1ULL << (x))
1274
1275 #define LOCAL_FEATURE_ACCESSOR(name, page, bit) \
1276 bool Controller::name() const { \
1277 return GetLocalFeatures(page) & BIT(bit); \
1278 }
1279
1280 LOCAL_FEATURE_ACCESSOR(Supports3SlotPackets, 0, 0)
1281 LOCAL_FEATURE_ACCESSOR(Supports5SlotPackets, 0, 1)
1282 LOCAL_FEATURE_ACCESSOR(SupportsRoleSwitch, 0, 5)
1283 LOCAL_FEATURE_ACCESSOR(SupportsHoldMode, 0, 6)
1284 LOCAL_FEATURE_ACCESSOR(SupportsSniffMode, 0, 7)
1285 LOCAL_FEATURE_ACCESSOR(SupportsParkMode, 0, 8)
1286 LOCAL_FEATURE_ACCESSOR(SupportsSco, 0, 11)
1287 LOCAL_FEATURE_ACCESSOR(SupportsHv2Packets, 0, 12)
1288 LOCAL_FEATURE_ACCESSOR(SupportsHv3Packets, 0, 13)
1289 LOCAL_FEATURE_ACCESSOR(SupportsClassic2mPhy, 0, 25)
1290 LOCAL_FEATURE_ACCESSOR(SupportsClassic3mPhy, 0, 26)
1291 LOCAL_FEATURE_ACCESSOR(SupportsInterlacedInquiryScan, 0, 28)
1292 LOCAL_FEATURE_ACCESSOR(SupportsRssiWithInquiryResults, 0, 30)
1293 LOCAL_FEATURE_ACCESSOR(SupportsEv3Packets, 0, 31)
1294 LOCAL_FEATURE_ACCESSOR(SupportsEv4Packets, 0, 32)
1295 LOCAL_FEATURE_ACCESSOR(SupportsEv5Packets, 0, 33)
1296 LOCAL_FEATURE_ACCESSOR(SupportsBle, 0, 38)
1297 LOCAL_FEATURE_ACCESSOR(Supports3SlotEdrPackets, 0, 39)
1298 LOCAL_FEATURE_ACCESSOR(Supports5SlotEdrPackets, 0, 40)
1299 LOCAL_FEATURE_ACCESSOR(SupportsSniffSubrating, 0, 41)
1300 LOCAL_FEATURE_ACCESSOR(SupportsEncryptionPause, 0, 42)
1301 LOCAL_FEATURE_ACCESSOR(SupportsEsco2mPhy, 0, 45)
1302 LOCAL_FEATURE_ACCESSOR(SupportsEsco3mPhy, 0, 46)
1303 LOCAL_FEATURE_ACCESSOR(Supports3SlotEscoEdrPackets, 0, 47)
1304 LOCAL_FEATURE_ACCESSOR(SupportsExtendedInquiryResponse, 0, 48)
1305 LOCAL_FEATURE_ACCESSOR(SupportsSimultaneousLeBrEdr, 0, 49)
1306 LOCAL_FEATURE_ACCESSOR(SupportsSimplePairing, 0, 51)
1307 LOCAL_FEATURE_ACCESSOR(SupportsNonFlushablePb, 0, 54)
1308
1309 LOCAL_FEATURE_ACCESSOR(SupportsSecureConnections, 2, 8)
1310
1311 #define LOCAL_LE_FEATURE_ACCESSOR(name, bit) \
1312 bool Controller::name() const { \
1313 return GetLocalLeFeatures() & BIT(bit); \
1314 }
1315
1316 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleEncryption, 0)
1317 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleConnectionParametersRequest, 1)
1318 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleExtendedReject, 2)
1319 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePeripheralInitiatedFeaturesExchange, 3)
1320 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePing, 4)
1321 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleDataPacketLengthExtension, 5)
1322 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePrivacy, 6)
1323 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleExtendedScannerFilterPolicies, 7)
1324 LOCAL_LE_FEATURE_ACCESSOR(SupportsBle2mPhy, 8)
1325 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleStableModulationIndexTx, 9)
1326 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleStableModulationIndexRx, 10)
1327 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleCodedPhy, 11)
1328 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleExtendedAdvertising, 12)
1329 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePeriodicAdvertising, 13)
1330 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleChannelSelectionAlgorithm2, 14)
1331 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePowerClass1, 15)
1332 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleMinimumUsedChannels, 16)
1333 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleConnectionCteRequest, 17)
1334 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleConnectionCteResponse, 18)
1335 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleConnectionlessCteTransmitter, 19)
1336 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleConnectionlessCteReceiver, 20)
1337 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleAntennaSwitchingDuringCteTx, 21)
1338 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleAntennaSwitchingDuringCteRx, 22)
1339 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleReceivingConstantToneExtensions, 23)
1340 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePeriodicAdvertisingSyncTransferSender, 24)
1341 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePeriodicAdvertisingSyncTransferRecipient, 25)
1342 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleSleepClockAccuracyUpdates, 26)
1343 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleRemotePublicKeyValidation, 27)
1344 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleConnectedIsochronousStreamCentral, 28)
1345 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleConnectedIsochronousStreamPeripheral, 29)
1346 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleIsochronousBroadcaster, 30)
1347 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleSynchronizedReceiver, 31)
1348 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleIsochronousChannelsHostSupport, 32)
1349 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePowerControlRequest, 33)
1350 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePowerChangeIndication, 34)
1351 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePathLossMonitoring, 35)
1352 LOCAL_LE_FEATURE_ACCESSOR(SupportsBlePeriodicAdvertisingAdi, 36)
1353 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleConnectionSubrating, 37)
1354 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleConnectionSubratingHost, 38)
1355 LOCAL_LE_FEATURE_ACCESSOR(SupportsBleChannelSounding, 46)
1356
GetLocalFeatures(uint8_t page_number) const1357 uint64_t Controller::GetLocalFeatures(uint8_t page_number) const {
1358 if (page_number < impl_->extended_lmp_features_array_.size()) {
1359 return impl_->extended_lmp_features_array_[page_number];
1360 }
1361 return 0x00;
1362 }
1363
GetAclPacketLength() const1364 uint16_t Controller::GetAclPacketLength() const {
1365 return impl_->acl_buffer_length_;
1366 }
1367
GetNumAclPacketBuffers() const1368 uint16_t Controller::GetNumAclPacketBuffers() const {
1369 return impl_->acl_buffers_;
1370 }
1371
GetScoPacketLength() const1372 uint8_t Controller::GetScoPacketLength() const {
1373 return impl_->sco_buffer_length_;
1374 }
1375
GetNumScoPacketBuffers() const1376 uint16_t Controller::GetNumScoPacketBuffers() const {
1377 return impl_->sco_buffers_;
1378 }
1379
GetMacAddress() const1380 Address Controller::GetMacAddress() const {
1381 return impl_->mac_address_;
1382 }
1383
SetEventMask(uint64_t event_mask)1384 void Controller::SetEventMask(uint64_t event_mask) {
1385 CallOn(impl_.get(), &impl::set_event_mask, event_mask);
1386 }
1387
Reset()1388 void Controller::Reset() {
1389 CallOn(impl_.get(), &impl::reset);
1390 }
1391
LeRand(LeRandCallback cb)1392 void Controller::LeRand(LeRandCallback cb) {
1393 CallOn(impl_.get(), &impl::le_rand, std::move(cb));
1394 }
1395
SetEventFilterClearAll()1396 void Controller::SetEventFilterClearAll() {
1397 std::unique_ptr<SetEventFilterClearAllBuilder> packet = SetEventFilterClearAllBuilder::Create();
1398 CallOn(impl_.get(), &impl::set_event_filter, std::move(packet));
1399 }
1400
SetEventFilterInquiryResultAllDevices()1401 void Controller::SetEventFilterInquiryResultAllDevices() {
1402 std::unique_ptr<SetEventFilterInquiryResultAllDevicesBuilder> packet =
1403 SetEventFilterInquiryResultAllDevicesBuilder::Create();
1404 CallOn(impl_.get(), &impl::set_event_filter, std::move(packet));
1405 }
1406
SetEventFilterInquiryResultClassOfDevice(ClassOfDevice class_of_device,ClassOfDevice class_of_device_mask)1407 void Controller::SetEventFilterInquiryResultClassOfDevice(ClassOfDevice class_of_device,
1408 ClassOfDevice class_of_device_mask) {
1409 std::unique_ptr<SetEventFilterInquiryResultClassOfDeviceBuilder> packet =
1410 SetEventFilterInquiryResultClassOfDeviceBuilder::Create(class_of_device, class_of_device_mask);
1411 CallOn(impl_.get(), &impl::set_event_filter, std::move(packet));
1412 }
1413
SetEventFilterInquiryResultAddress(Address address)1414 void Controller::SetEventFilterInquiryResultAddress(Address address) {
1415 std::unique_ptr<SetEventFilterInquiryResultAddressBuilder> packet =
1416 SetEventFilterInquiryResultAddressBuilder::Create(address);
1417 CallOn(impl_.get(), &impl::set_event_filter, std::move(packet));
1418 }
1419
SetEventFilterConnectionSetupAllDevices(AutoAcceptFlag auto_accept_flag)1420 void Controller::SetEventFilterConnectionSetupAllDevices(AutoAcceptFlag auto_accept_flag) {
1421 std::unique_ptr<SetEventFilterConnectionSetupAllDevicesBuilder> packet =
1422 SetEventFilterConnectionSetupAllDevicesBuilder::Create(auto_accept_flag);
1423 CallOn(impl_.get(), &impl::set_event_filter, std::move(packet));
1424 }
1425
SetEventFilterConnectionSetupClassOfDevice(ClassOfDevice class_of_device,ClassOfDevice class_of_device_mask,AutoAcceptFlag auto_accept_flag)1426 void Controller::SetEventFilterConnectionSetupClassOfDevice(ClassOfDevice class_of_device,
1427 ClassOfDevice class_of_device_mask,
1428 AutoAcceptFlag auto_accept_flag) {
1429 std::unique_ptr<SetEventFilterConnectionSetupClassOfDeviceBuilder> packet =
1430 SetEventFilterConnectionSetupClassOfDeviceBuilder::Create(class_of_device, class_of_device_mask,
1431 auto_accept_flag);
1432 CallOn(impl_.get(), &impl::set_event_filter, std::move(packet));
1433 }
1434
SetEventFilterConnectionSetupAddress(Address address,AutoAcceptFlag auto_accept_flag)1435 void Controller::SetEventFilterConnectionSetupAddress(Address address, AutoAcceptFlag auto_accept_flag) {
1436 std::unique_ptr<SetEventFilterConnectionSetupAddressBuilder> packet =
1437 SetEventFilterConnectionSetupAddressBuilder::Create(address, auto_accept_flag);
1438 CallOn(impl_.get(), &impl::set_event_filter, std::move(packet));
1439 }
1440
WriteLocalName(std::string local_name)1441 void Controller::WriteLocalName(std::string local_name) {
1442 impl_->local_name_ = local_name;
1443 CallOn(impl_.get(), &impl::write_local_name, local_name);
1444 }
1445
HostBufferSize(uint16_t host_acl_data_packet_length,uint8_t host_synchronous_data_packet_length,uint16_t host_total_num_acl_data_packets,uint16_t host_total_num_synchronous_data_packets)1446 void Controller::HostBufferSize(uint16_t host_acl_data_packet_length, uint8_t host_synchronous_data_packet_length,
1447 uint16_t host_total_num_acl_data_packets,
1448 uint16_t host_total_num_synchronous_data_packets) {
1449 CallOn(
1450 impl_.get(),
1451 &impl::host_buffer_size,
1452 host_acl_data_packet_length,
1453 host_synchronous_data_packet_length,
1454 host_total_num_acl_data_packets,
1455 host_total_num_synchronous_data_packets);
1456 }
1457
LeSetEventMask(uint64_t le_event_mask)1458 void Controller::LeSetEventMask(uint64_t le_event_mask) {
1459 CallOn(impl_.get(), &impl::le_set_event_mask, le_event_mask);
1460 }
1461
GetLeBufferSize() const1462 LeBufferSize Controller::GetLeBufferSize() const {
1463 return impl_->le_buffer_size_;
1464 }
1465
GetLocalLeFeatures() const1466 uint64_t Controller::GetLocalLeFeatures() const {
1467 return impl_->le_local_supported_features_;
1468 }
1469
GetControllerIsoBufferSize() const1470 LeBufferSize Controller::GetControllerIsoBufferSize() const {
1471 return impl_->iso_buffer_size_;
1472 }
1473
GetControllerLeLocalSupportedFeatures() const1474 uint64_t Controller::GetControllerLeLocalSupportedFeatures() const {
1475 return impl_->le_local_supported_features_;
1476 }
1477
GetLeSupportedStates() const1478 uint64_t Controller::GetLeSupportedStates() const {
1479 return impl_->le_supported_states_;
1480 }
1481
GetLeFilterAcceptListSize() const1482 uint8_t Controller::GetLeFilterAcceptListSize() const {
1483 return impl_->le_accept_list_size_;
1484 }
1485
GetLeResolvingListSize() const1486 uint8_t Controller::GetLeResolvingListSize() const {
1487 return impl_->le_resolving_list_size_;
1488 }
1489
GetLeMaximumDataLength() const1490 LeMaximumDataLength Controller::GetLeMaximumDataLength() const {
1491 return impl_->le_maximum_data_length_;
1492 }
1493
GetLeMaximumAdvertisingDataLength() const1494 uint16_t Controller::GetLeMaximumAdvertisingDataLength() const {
1495 return impl_->le_maximum_advertising_data_length_;
1496 }
1497
GetLeSuggestedDefaultDataLength() const1498 uint16_t Controller::GetLeSuggestedDefaultDataLength() const {
1499 return impl_->le_suggested_default_data_length_;
1500 }
1501
GetLeNumberOfSupportedAdverisingSets() const1502 uint8_t Controller::GetLeNumberOfSupportedAdverisingSets() const {
1503 return impl_->le_number_supported_advertising_sets_;
1504 }
1505
GetVendorCapabilities() const1506 Controller::VendorCapabilities Controller::GetVendorCapabilities() const {
1507 return impl_->vendor_capabilities_;
1508 }
1509
GetDabSupportedCodecs() const1510 uint32_t Controller::GetDabSupportedCodecs() const {
1511 return impl_->dab_supported_codecs_;
1512 }
1513
GetDabCodecCapabilities() const1514 const std::array<DynamicAudioBufferCodecCapability, 32>& Controller::GetDabCodecCapabilities()
1515 const {
1516 return impl_->dab_codec_capabilities_;
1517 }
1518
SetDabAudioBufferTime(uint16_t buffer_time_ms)1519 void Controller::SetDabAudioBufferTime(uint16_t buffer_time_ms) {
1520 if (impl_->vendor_capabilities_.dynamic_audio_buffer_support_ == 0) {
1521 log::warn("Dynamic Audio Buffer not supported");
1522 return;
1523 }
1524 impl_->set_controller_dab_audio_buffer_time(buffer_time_ms);
1525 }
1526
GetLePeriodicAdvertiserListSize() const1527 uint8_t Controller::GetLePeriodicAdvertiserListSize() const {
1528 return impl_->le_periodic_advertiser_list_size_;
1529 }
1530
IsSupported(bluetooth::hci::OpCode op_code) const1531 bool Controller::IsSupported(bluetooth::hci::OpCode op_code) const {
1532 return impl_->is_supported(op_code);
1533 }
1534
MaskLeEventMask(HciVersion version,uint64_t mask)1535 uint64_t Controller::MaskLeEventMask(HciVersion version, uint64_t mask) {
1536 if (!common::init_flags::subrating_is_enabled()) {
1537 mask = mask & ~(static_cast<uint64_t>(LLFeaturesBits::CONNECTION_SUBRATING_HOST_SUPPORT));
1538 }
1539 if (version >= HciVersion::V_5_3) {
1540 return mask;
1541 } else if (version >= HciVersion::V_5_2) {
1542 return mask & kLeEventMask52;
1543 } else if (version >= HciVersion::V_5_1) {
1544 return mask & kLeEventMask51;
1545 } else if (version >= HciVersion::V_5_0) {
1546 return mask & kLeEventMask50;
1547 } else if (version >= HciVersion::V_4_2) {
1548 return mask & kLeEventMask42;
1549 } else {
1550 return mask & kLeEventMask41;
1551 }
1552 }
1553
__anon6987be630102() 1554 const ModuleFactory Controller::Factory = ModuleFactory([]() { return new Controller(); });
1555
ListDependencies(ModuleList * list) const1556 void Controller::ListDependencies(ModuleList* list) const {
1557 list->add<hci::HciLayer>();
1558 #if TARGET_FLOSS
1559 list->add<sysprops::SyspropsModule>();
1560 #endif
1561 }
1562
Start()1563 void Controller::Start() {
1564 impl_->Start(GetDependency<hci::HciLayer>());
1565 }
1566
Stop()1567 void Controller::Stop() {
1568 impl_->Stop();
1569 }
1570
ToString() const1571 std::string Controller::ToString() const {
1572 return "Controller";
1573 }
1574
Dump(std::promise<flatbuffers::Offset<ControllerData>> promise,flatbuffers::FlatBufferBuilder * fb_builder) const1575 void Controller::impl::Dump(
1576 std::promise<flatbuffers::Offset<ControllerData>> promise, flatbuffers::FlatBufferBuilder* fb_builder) const {
1577 ASSERT(fb_builder != nullptr);
1578 auto title = fb_builder->CreateString("----- Hci Controller Dumpsys -----");
1579
1580 auto local_version_information_data = CreateLocalVersionInformationData(
1581 *fb_builder,
1582 fb_builder->CreateString(HciVersionText(local_version_information_.hci_version_)),
1583 local_version_information_.hci_revision_,
1584 fb_builder->CreateString(LmpVersionText(local_version_information_.lmp_version_)),
1585 local_version_information_.manufacturer_name_,
1586 local_version_information_.lmp_subversion_);
1587
1588 auto acl_buffer_size_data = BufferSizeData(acl_buffer_length_, acl_buffers_);
1589
1590 auto sco_buffer_size_data = BufferSizeData(sco_buffer_length_, sco_buffers_);
1591
1592 auto le_buffer_size_data =
1593 BufferSizeData(le_buffer_size_.le_data_packet_length_, le_buffer_size_.total_num_le_packets_);
1594
1595 auto iso_buffer_size_data =
1596 BufferSizeData(iso_buffer_size_.le_data_packet_length_, iso_buffer_size_.total_num_le_packets_);
1597
1598 auto le_maximum_data_length_data = LeMaximumDataLengthData(
1599 le_maximum_data_length_.supported_max_tx_octets_,
1600 le_maximum_data_length_.supported_max_tx_time_,
1601 le_maximum_data_length_.supported_max_rx_octets_,
1602 le_maximum_data_length_.supported_max_rx_time_);
1603
1604 std::vector<LocalSupportedCommandsData> local_supported_commands_vector;
1605 for (uint8_t index = 0; index < local_supported_commands_.size(); index++) {
1606 local_supported_commands_vector.push_back(LocalSupportedCommandsData(index, local_supported_commands_[index]));
1607 }
1608 auto local_supported_commands_data = fb_builder->CreateVectorOfStructs(local_supported_commands_vector);
1609
1610 auto vendor_capabilities_data = VendorCapabilitiesData(
1611 vendor_capabilities_.is_supported_,
1612 vendor_capabilities_.max_advt_instances_,
1613 vendor_capabilities_.offloaded_resolution_of_private_address_,
1614 vendor_capabilities_.total_scan_results_storage_,
1615 vendor_capabilities_.max_irk_list_sz_,
1616 vendor_capabilities_.filtering_support_,
1617 vendor_capabilities_.max_filter_,
1618 vendor_capabilities_.activity_energy_info_support_,
1619 vendor_capabilities_.version_supported_,
1620 vendor_capabilities_.total_num_of_advt_tracked_,
1621 vendor_capabilities_.extended_scan_support_,
1622 vendor_capabilities_.debug_logging_supported_,
1623 vendor_capabilities_.le_address_generation_offloading_support_,
1624 vendor_capabilities_.a2dp_source_offload_capability_mask_,
1625 vendor_capabilities_.bluetooth_quality_report_support_);
1626
1627 auto extended_lmp_features_vector = fb_builder->CreateVector(extended_lmp_features_array_);
1628
1629 // Create the root table
1630 ControllerDataBuilder builder(*fb_builder);
1631
1632 builder.add_title(title);
1633 builder.add_local_version_information(local_version_information_data);
1634
1635 builder.add_acl_buffer_size(&acl_buffer_size_data);
1636 builder.add_sco_buffer_size(&sco_buffer_size_data);
1637 builder.add_iso_buffer_size(&iso_buffer_size_data);
1638 builder.add_le_buffer_size(&le_buffer_size_data);
1639
1640 builder.add_le_accept_list_size(le_accept_list_size_);
1641 builder.add_le_resolving_list_size(le_resolving_list_size_);
1642
1643 builder.add_le_maximum_data_length(&le_maximum_data_length_data);
1644 builder.add_le_maximum_advertising_data_length(le_maximum_advertising_data_length_);
1645 builder.add_le_suggested_default_data_length(le_suggested_default_data_length_);
1646 builder.add_le_number_supported_advertising_sets(le_number_supported_advertising_sets_);
1647 builder.add_le_periodic_advertiser_list_size(le_periodic_advertiser_list_size_);
1648
1649 builder.add_local_supported_commands(local_supported_commands_data);
1650 builder.add_extended_lmp_features_array(extended_lmp_features_vector);
1651 builder.add_le_local_supported_features(le_local_supported_features_);
1652 builder.add_le_supported_states(le_supported_states_);
1653 builder.add_vendor_capabilities(&vendor_capabilities_data);
1654
1655 flatbuffers::Offset<ControllerData> dumpsys_data = builder.Finish();
1656 promise.set_value(dumpsys_data);
1657 }
1658
GetDumpsysData(flatbuffers::FlatBufferBuilder * fb_builder) const1659 DumpsysDataFinisher Controller::GetDumpsysData(flatbuffers::FlatBufferBuilder* fb_builder) const {
1660 ASSERT(fb_builder != nullptr);
1661
1662 std::promise<flatbuffers::Offset<ControllerData>> promise;
1663 auto future = promise.get_future();
1664 impl_->Dump(std::move(promise), fb_builder);
1665
1666 auto dumpsys_data = future.get();
1667
1668 return [dumpsys_data](DumpsysDataBuilder* dumpsys_builder) {
1669 dumpsys_builder->add_hci_controller_dumpsys_data(dumpsys_data);
1670 };
1671 }
1672
1673 } // namespace hci
1674 } // namespace bluetooth
1675