1 // Copyright 2023 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #pragma once 16 #include <lib/fit/function.h> 17 18 #include <memory> 19 #include <unordered_map> 20 21 #include "pw_bluetooth_sapphire/internal/host/common/device_address.h" 22 #include "pw_bluetooth_sapphire/internal/host/common/device_class.h" 23 #include "pw_bluetooth_sapphire/internal/host/common/macros.h" 24 #include "pw_bluetooth_sapphire/internal/host/hci-spec/constants.h" 25 #include "pw_bluetooth_sapphire/internal/host/hci-spec/le_connection_parameters.h" 26 #include "pw_bluetooth_sapphire/internal/host/hci-spec/protocol.h" 27 #include "pw_bluetooth_sapphire/internal/host/hci/low_energy_advertiser.h" 28 #include "pw_bluetooth_sapphire/internal/host/l2cap/l2cap_defs.h" 29 #include "pw_bluetooth_sapphire/internal/host/testing/controller_test_double_base.h" 30 #include "pw_bluetooth_sapphire/internal/host/testing/fake_peer.h" 31 32 namespace bt::testing { 33 34 namespace android_emb = pw::bluetooth::vendor::android_hci; 35 36 class FakePeer; 37 38 // FakeController emulates a real Bluetooth controller. It can be configured to 39 // respond to HCI commands in a predictable manner. 40 class FakeController final : public ControllerTestDoubleBase, 41 public WeakSelf<FakeController> { 42 public: 43 // Global settings for the FakeController. These can be used to initialize a 44 // FakeController and/or to re-configure an existing one. 45 struct Settings final { 46 // The default constructor initializes all fields to 0, unless another 47 // default is specified below. 48 Settings() = default; 49 ~Settings() = default; 50 51 void ApplyDualModeDefaults(); 52 void ApplyLEOnlyDefaults(); 53 void ApplyLegacyLEConfig(); 54 void ApplyExtendedLEConfig(); 55 void ApplyAndroidVendorExtensionDefaults(); 56 57 void AddBREDRSupportedCommands(); 58 void AddLESupportedCommands(); 59 60 bool is_event_unmasked(hci_spec::LEEventMask event) const; 61 SupportedCommandsViewfinal62 auto SupportedCommandsView() { 63 return pw::bluetooth::emboss::MakeSupportedCommandsView( 64 supported_commands, sizeof(supported_commands)); 65 } 66 67 // The time elapsed from the receipt of a LE Create Connection command until 68 // the resulting LE Connection Complete event. 69 pw::chrono::SystemClock::duration le_connection_delay = 70 std::chrono::seconds(0); 71 72 // Our role in any LE connections we make. 73 pw::bluetooth::emboss::ConnectionRole le_connection_role = 74 pw::bluetooth::emboss::ConnectionRole::CENTRAL; 75 76 // HCI settings. 77 pw::bluetooth::emboss::CoreSpecificationVersion hci_version = 78 pw::bluetooth::emboss::CoreSpecificationVersion::V5_0; 79 uint8_t num_hci_command_packets = 250; 80 uint64_t event_mask = 0; 81 uint64_t le_event_mask = 0; 82 83 // BD_ADDR (BR/EDR) or Public Device Address (LE) 84 DeviceAddress bd_addr; 85 86 // Local supported features and commands. 87 uint64_t lmp_features_page0 = 0; 88 uint64_t lmp_features_page1 = 0; 89 uint64_t lmp_features_page2 = 0; 90 uint64_t le_features = 0; 91 uint64_t le_supported_states = 0; 92 uint8_t supported_commands[64] = {0}; 93 94 // Buffer Size. 95 uint16_t acl_data_packet_length = 1; 96 uint8_t total_num_acl_data_packets = 1; 97 uint16_t le_acl_data_packet_length = 0; 98 uint8_t le_total_num_acl_data_packets = 0; 99 uint8_t synchronous_data_packet_length = 1; 100 uint8_t total_num_synchronous_data_packets = 0; 101 uint16_t iso_data_packet_length = 0; 102 uint8_t total_num_iso_data_packets = 0; 103 104 // Vendor extensions 105 StaticPacket<android_emb::LEGetVendorCapabilitiesCommandCompleteEventWriter> 106 android_extension_settings; 107 }; 108 109 // Configuration of an L2CAP channel for A2DP offloading. 110 struct OffloadedA2dpChannel final { 111 android_emb::A2dpCodecType codec_type = android_emb::A2dpCodecType::SBC; 112 uint16_t max_latency = 0; 113 StaticPacket<android_emb::A2dpScmsTEnableWriter> scms_t_enable; 114 android_emb::A2dpSamplingFrequency sampling_frequency = 115 android_emb::A2dpSamplingFrequency::HZ_44100; 116 android_emb::A2dpBitsPerSample bits_per_sample = 117 android_emb::A2dpBitsPerSample::BITS_PER_SAMPLE_16; 118 android_emb::A2dpChannelMode channel_mode = 119 android_emb::A2dpChannelMode::MONO; 120 uint32_t encoded_audio_bitrate = 0; 121 hci_spec::ConnectionHandle connection_handle = 0; 122 l2cap::ChannelId l2cap_channel_id = 0; 123 uint16_t l2cap_mtu_size = 0; 124 }; 125 126 // Current device low energy scan state. 127 struct LEScanState final { 128 bool enabled = false; 129 pw::bluetooth::emboss::LEScanType scan_type = 130 pw::bluetooth::emboss::LEScanType::PASSIVE; 131 pw::bluetooth::emboss::LEOwnAddressType own_address_type = 132 pw::bluetooth::emboss::LEOwnAddressType::PUBLIC; 133 pw::bluetooth::emboss::LEScanFilterPolicy filter_policy = 134 pw::bluetooth::emboss::LEScanFilterPolicy::BASIC_UNFILTERED; 135 uint16_t scan_interval = 0; 136 uint16_t scan_window = 0; 137 bool filter_duplicates = false; 138 uint16_t duration = 0; 139 uint16_t period = 0; 140 }; 141 142 // Current device basic advertising state 143 struct LEAdvertisingState final { advertised_viewfinal144 BufferView advertised_view() const { return BufferView(data, data_length); } scan_rsp_viewfinal145 BufferView scan_rsp_view() const { 146 return BufferView(scan_rsp_data, scan_rsp_length); 147 } 148 149 bool IsDirectedAdvertising() const; 150 151 bool enabled = false; 152 hci::LowEnergyAdvertiser::AdvertisingEventProperties properties; 153 154 std::optional<DeviceAddress> random_address; 155 pw::bluetooth::emboss::LEOwnAddressType own_address_type = 156 pw::bluetooth::emboss::LEOwnAddressType::PUBLIC; 157 158 uint32_t interval_min = 0; 159 uint32_t interval_max = 0; 160 161 uint16_t data_length = 0; 162 uint8_t data[hci_spec::kMaxLEExtendedAdvertisingDataLength] = {0}; 163 uint16_t scan_rsp_length = 0; 164 uint8_t scan_rsp_data[hci_spec::kMaxLEExtendedAdvertisingDataLength] = {0}; 165 }; 166 167 // The parameters of the most recent low energy connection initiation request 168 struct LEConnectParams final { 169 enum class InitiatingPHYs { 170 kLE_1M = 0, 171 kLE_2M, 172 kLE_Coded, 173 }; 174 175 struct Parameters { 176 uint16_t scan_interval = 0; 177 uint16_t scan_window = 0; 178 uint16_t connection_interval_min = 0; 179 uint16_t connection_interval_max = 0; 180 uint16_t max_latency = 0; 181 uint16_t supervision_timeout = 0; 182 uint16_t min_ce_length = 0; 183 uint16_t max_ce_length = 0; 184 }; 185 186 bool use_filter_policy = false; 187 pw::bluetooth::emboss::LEOwnAddressType own_address_type; 188 DeviceAddress peer_address; 189 std::unordered_map<InitiatingPHYs, Parameters> phy_conn_params; 190 }; 191 192 // Constructor initializes the controller with the minimal default settings 193 // (equivalent to calling Settings::ApplyDefaults()). FakeController(pw::async::Dispatcher & pw_dispatcher)194 explicit FakeController(pw::async::Dispatcher& pw_dispatcher) 195 : ControllerTestDoubleBase(pw_dispatcher), WeakSelf(this) {} 196 ~FakeController() override = default; 197 198 // Resets the controller settings. set_settings(const Settings & settings)199 void set_settings(const Settings& settings) { settings_ = settings; } 200 201 // Always respond to the given command |opcode| with an Command Status event 202 // specifying |status|. 203 void SetDefaultCommandStatus(hci_spec::OpCode opcode, 204 pw::bluetooth::emboss::StatusCode status); 205 void ClearDefaultCommandStatus(hci_spec::OpCode opcode); 206 207 // Tells the FakeController to always respond to the given command opcode with 208 // a Command Complete event specifying the given HCI status code. 209 void SetDefaultResponseStatus(hci_spec::OpCode opcode, 210 pw::bluetooth::emboss::StatusCode status); 211 void ClearDefaultResponseStatus(hci_spec::OpCode opcode); 212 213 // Returns the current LE scan state. le_scan_state()214 const LEScanState& le_scan_state() const { return le_scan_state_; } 215 216 // Returns the current LE advertising state for legacy advertising legacy_advertising_state()217 const LEAdvertisingState& legacy_advertising_state() const { 218 return legacy_advertising_state_; 219 } 220 221 // Returns the current LE advertising state for extended advertising, for the 222 // given advertising handle extended_advertising_state(hci_spec::AdvertisingHandle handle)223 const LEAdvertisingState& extended_advertising_state( 224 hci_spec::AdvertisingHandle handle) { 225 return extended_advertising_states_[handle]; 226 } 227 228 // Returns the most recent LE connection request parameters. le_connect_params()229 const std::optional<LEConnectParams>& le_connect_params() const { 230 return le_connect_params_; 231 } 232 233 // Store the most recent LE Connection Parameters for inspection 234 void CaptureLEConnectParams( 235 const pw::bluetooth::emboss::LECreateConnectionCommandView& params); 236 237 // Store the most recent LE Connection Parameters for inspection 238 void CaptureLEConnectParams( 239 const pw::bluetooth::emboss::LEExtendedCreateConnectionCommandV1View& 240 params); 241 242 // Returns the current local name set in the controller local_name()243 const std::string& local_name() const { return local_name_; } 244 245 // Returns the current class of device. device_class()246 const DeviceClass& device_class() const { return device_class_; } 247 248 // Adds a fake remote peer. Returns false if a peer with the same address 249 // was previously added. 250 bool AddPeer(std::unique_ptr<FakePeer> peer); 251 252 // Removes a previously registered peer with the given device |address|. 253 // Does nothing if |address| is unrecognized. 254 void RemovePeer(const DeviceAddress& address); 255 256 // Returns a pointer to the FakePeer with the given |address|. Returns 257 // nullptr if the |address| is unknown. 258 FakePeer* FindPeer(const DeviceAddress& address); 259 260 // Counters for HCI commands received. le_create_connection_command_count()261 int le_create_connection_command_count() const { 262 return le_create_connection_command_count_; 263 } acl_create_connection_command_count()264 int acl_create_connection_command_count() const { 265 return acl_create_connection_command_count_; 266 } 267 268 // Setting this callback allows test code to introspect the 269 // LECreateConnectionCommand from bt-host, but does not affect 270 // FakeController's handling of the command (i.e. this method exists solely 271 // for introspection). To change how FakeController responds to an 272 // LECreateConnectionCommand, use the FakePeer::set_connect_status or 273 // FakePeer::set_connect_response methods. set_le_create_connection_command_callback(fit::function<void (pw::bluetooth::emboss::LECreateConnectionCommandView)> callback)274 void set_le_create_connection_command_callback( 275 fit::function<void(pw::bluetooth::emboss::LECreateConnectionCommandView)> 276 callback) { 277 le_create_connection_cb_ = std::move(callback); 278 } 279 280 // Sets a callback to be invoked when the the base controller parameters 281 // change due to a HCI command. These parameters are: 282 // 283 // - The local name. 284 // - The local class of device. set_controller_parameters_callback(fit::closure callback)285 void set_controller_parameters_callback(fit::closure callback) { 286 controller_parameters_cb_ = std::move(callback); 287 } 288 289 // Sets a callback to be invoked when the scan state changes. 290 using ScanStateCallback = fit::function<void(bool enabled)>; set_scan_state_callback(ScanStateCallback callback)291 void set_scan_state_callback(ScanStateCallback callback) { 292 scan_state_cb_ = std::move(callback); 293 } 294 295 // Sets a callback to be invoked when the LE Advertising state changes. set_advertising_state_callback(fit::closure callback)296 void set_advertising_state_callback(fit::closure callback) { 297 advertising_state_cb_ = std::move(callback); 298 } 299 300 // Sets a callback to be invoked on connection events. 301 using ConnectionStateCallback = 302 fit::function<void(const DeviceAddress&, 303 hci_spec::ConnectionHandle handle, 304 bool connected, 305 bool canceled)>; set_connection_state_callback(ConnectionStateCallback callback)306 void set_connection_state_callback(ConnectionStateCallback callback) { 307 conn_state_cb_ = std::move(callback); 308 } 309 310 // Sets a callback to be invoked when LE connection parameters are updated 311 // for a fake device. 312 using LEConnectionParametersCallback = fit::function<void( 313 const DeviceAddress&, const hci_spec::LEConnectionParameters&)>; set_le_connection_parameters_callback(LEConnectionParametersCallback callback)314 void set_le_connection_parameters_callback( 315 LEConnectionParametersCallback callback) { 316 le_conn_params_cb_ = std::move(callback); 317 } 318 319 // Sets a callback to be invoked just before LE Read Remote Feature commands 320 // are handled. set_le_read_remote_features_callback(fit::closure callback)321 void set_le_read_remote_features_callback(fit::closure callback) { 322 le_read_remote_features_cb_ = std::move(callback); 323 } 324 325 // Sends a HCI event with the given parameters. 326 void SendEvent(hci_spec::EventCode event_code, const ByteBuffer& payload); 327 328 // Sends an HCI event, filling in the parameters in a provided event packet. 329 void SendEvent(hci_spec::EventCode event_code, hci::EventPacket* packet); 330 331 // Sends a LE Meta event with the given parameters. 332 void SendLEMetaEvent(hci_spec::EventCode subevent_code, 333 const ByteBuffer& payload); 334 335 // Sends an ACL data packet with the given parameters. 336 void SendACLPacket(hci_spec::ConnectionHandle handle, 337 const ByteBuffer& payload); 338 339 // Sends a L2CAP basic frame. 340 void SendL2CAPBFrame(hci_spec::ConnectionHandle handle, 341 l2cap::ChannelId channel_id, 342 const ByteBuffer& payload); 343 344 // Sends a L2CAP control frame over a signaling channel. If |is_le| is true, 345 // then the LE signaling channel will be used. 346 void SendL2CAPCFrame(hci_spec::ConnectionHandle handle, 347 bool is_le, 348 l2cap::CommandCode code, 349 uint8_t id, 350 const ByteBuffer& payload); 351 352 void SendNumberOfCompletedPacketsEvent(hci_spec::ConnectionHandle handle, 353 uint16_t num); 354 355 // Sets up a LE link to the device with the given |addr|. FakeController 356 // will report a connection event in which it is in the given |role|. 357 void ConnectLowEnergy(const DeviceAddress& addr, 358 pw::bluetooth::emboss::ConnectionRole role = 359 pw::bluetooth::emboss::ConnectionRole::PERIPHERAL); 360 361 // Sends an HCI Connection Request event. 362 void SendConnectionRequest(const DeviceAddress& addr, 363 pw::bluetooth::emboss::LinkType link_type); 364 365 // Tells a fake device to initiate the L2CAP Connection Parameter Update 366 // procedure using the given |params|. Has no effect if a connected fake 367 // device with the given |addr| is not found. 368 void L2CAPConnectionParameterUpdate( 369 const DeviceAddress& addr, 370 const hci_spec::LEPreferredConnectionParameters& params); 371 372 // Sends an LE Meta Event Connection Update Complete Subevent. Used to 373 // simulate updates initiated by LE central or spontaneously by the 374 // controller. 375 void SendLEConnectionUpdateCompleteSubevent( 376 hci_spec::ConnectionHandle handle, 377 const hci_spec::LEConnectionParameters& params, 378 pw::bluetooth::emboss::StatusCode status = 379 pw::bluetooth::emboss::StatusCode::SUCCESS); 380 381 // Marks the FakePeer with address |address| as disconnected and sends a HCI 382 // Disconnection Complete event for all of its links. 383 void Disconnect( 384 const DeviceAddress& addr, 385 pw::bluetooth::emboss::StatusCode reason = 386 pw::bluetooth::emboss::StatusCode::REMOTE_USER_TERMINATED_CONNECTION); 387 388 // Send HCI Disconnection Complete event for |handle|. 389 void SendDisconnectionCompleteEvent( 390 hci_spec::ConnectionHandle handle, 391 pw::bluetooth::emboss::StatusCode reason = 392 pw::bluetooth::emboss::StatusCode::REMOTE_USER_TERMINATED_CONNECTION); 393 394 // Send HCI encryption change event for |handle| with the given parameters. 395 void SendEncryptionChangeEvent( 396 hci_spec::ConnectionHandle handle, 397 pw::bluetooth::emboss::StatusCode status, 398 pw::bluetooth::emboss::EncryptionStatus encryption_enabled); 399 400 // Callback to invoke when a packet is received over the data channel. Care 401 // should be taken to ensure that a callback with a reference to test case 402 // variables is not invoked when tearing down. 403 using DataCallback = fit::function<void(const ByteBuffer& packet)>; 404 void SetDataCallback(DataCallback callback, 405 pw::async::Dispatcher& pw_dispatcher); 406 void ClearDataCallback(); 407 408 // Callback to invoke when a packet is received over the SCO data channel. SetScoDataCallback(DataCallback callback)409 void SetScoDataCallback(DataCallback callback) { 410 sco_data_callback_ = std::move(callback); 411 } ClearScoDataCallback()412 void ClearScoDataCallback() { sco_data_callback_ = nullptr; } 413 414 // Callback to invoke when a packet is received over the ISO data channel. SetIsoDataCallback(DataCallback callback)415 void SetIsoDataCallback(DataCallback callback) { 416 iso_data_callback_ = std::move(callback); 417 } ClearIsoDataCallback()418 void ClearIsoDataCallback() { iso_data_callback_ = nullptr; } 419 420 // Automatically send HCI Number of Completed Packets event for each packet 421 // received. Enabled by default. set_auto_completed_packets_event_enabled(bool enabled)422 void set_auto_completed_packets_event_enabled(bool enabled) { 423 auto_completed_packets_event_enabled_ = enabled; 424 } 425 426 // Automatically send HCI Disconnection Complete event when HCI Disconnect 427 // command received. Enabled by default. set_auto_disconnection_complete_event_enabled(bool enabled)428 void set_auto_disconnection_complete_event_enabled(bool enabled) { 429 auto_disconnection_complete_event_enabled_ = enabled; 430 } 431 432 // Sets the response flag for a TX Power Level Read. 433 // Enabled by default (i.e it will respond to TXPowerLevelRead by default). set_tx_power_level_read_response_flag(bool respond)434 void set_tx_power_level_read_response_flag(bool respond) { 435 respond_to_tx_power_read_ = respond; 436 } 437 438 // Upon reception of a command packet with `opcode`, FakeController invokes 439 // `pause_listener` with a closure. The command will hang until this closure 440 // is invoked, enabling clients to control the timing of command completion. pause_responses_for_opcode(hci_spec::OpCode code,fit::function<void (fit::closure)> pause_listener)441 void pause_responses_for_opcode( 442 hci_spec::OpCode code, fit::function<void(fit::closure)> pause_listener) { 443 paused_opcode_listeners_[code] = std::move(pause_listener); 444 } 445 clear_pause_listener_for_opcode(hci_spec::OpCode code)446 void clear_pause_listener_for_opcode(hci_spec::OpCode code) { 447 paused_opcode_listeners_.erase(code); 448 } 449 set_maximum_advertising_data_length(uint16_t value)450 void set_maximum_advertising_data_length(uint16_t value) { 451 max_advertising_data_length_ = value; 452 } 453 454 // Called when a HCI_LE_Read_Advertising_Channel_Tx_Power command is 455 // received. 456 void OnLEReadAdvertisingChannelTxPower(); 457 458 // Inform the controller that the advertising handle is connected via the 459 // connection handle. This method then generates the necessary LE Meta 460 // Events (e.g. Advertising Set Terminated) to inform extended advertising 461 // listeners. 462 void SendLEAdvertisingSetTerminatedEvent( 463 hci_spec::ConnectionHandle conn_handle, 464 hci_spec::AdvertisingHandle adv_handle); 465 466 // Inform the controller that the advertising handle is connected via the 467 // connection handle. This method then generates the necessary Vendor Event 468 // (e.g. LE multi-advertising state change sub-event) to inform Android 469 // Multiple Advertising listeners. 470 void SendAndroidLEMultipleAdvertisingStateChangeSubevent( 471 hci_spec::ConnectionHandle conn_handle, 472 hci_spec::AdvertisingHandle adv_handle); 473 474 // The maximum number of advertising sets supported by the controller. Core 475 // Spec Volume 4, Part E, Section 7.8.58: the memory used to store 476 // advertising sets can also be used for other purposes. This value can 477 // change over time. num_supported_advertising_sets()478 uint8_t num_supported_advertising_sets() const { 479 return num_supported_advertising_sets_; 480 } set_num_supported_advertising_sets(uint8_t value)481 void set_num_supported_advertising_sets(uint8_t value) { 482 PW_CHECK(value >= extended_advertising_states_.size()); 483 PW_CHECK(value <= hci_spec::kAdvertisingHandleMax + 484 1); // support advertising handle of 0 485 num_supported_advertising_sets_ = value; 486 } 487 488 // Controller overrides: 489 void SendCommand(pw::span<const std::byte> command) override; 490 SendAclData(pw::span<const std::byte> data)491 void SendAclData(pw::span<const std::byte> data) override { 492 // Post the packet to simulate async HCI behavior. 493 (void)heap_dispatcher().Post( 494 [self = GetWeakPtr(), data = DynamicByteBuffer(BufferView(data))]( 495 pw::async::Context /*ctx*/, pw::Status status) { 496 if (self.is_alive() && status.ok()) { 497 self->OnACLDataPacketReceived(BufferView(data)); 498 } 499 }); 500 } 501 SendScoData(pw::span<const std::byte> data)502 void SendScoData(pw::span<const std::byte> data) override { 503 // Post the packet to simulate async HCI behavior. 504 (void)heap_dispatcher().Post( 505 [self = GetWeakPtr(), data = DynamicByteBuffer(BufferView(data))]( 506 pw::async::Context /*ctx*/, pw::Status status) { 507 if (self.is_alive() && status.ok()) { 508 self->OnScoDataPacketReceived(BufferView(data)); 509 } 510 }); 511 } 512 SendIsoData(pw::span<const std::byte> data)513 void SendIsoData(pw::span<const std::byte> data) override { 514 // Post the packet to simulate async HCI behavior. 515 (void)heap_dispatcher().Post( 516 [self = GetWeakPtr(), data = DynamicByteBuffer(BufferView(data))]( 517 pw::async::Context /*ctx*/, pw::Status status) { 518 if (self.is_alive() && status.ok()) { 519 self->OnIsoDataPacketReceived(BufferView(data)); 520 } 521 }); 522 } 523 524 // Sends a single LE advertising report for the given peer. This method will 525 // send a legacy or extended advertising report, depending on which one the 526 // peer is configured to send. 527 // 528 // Does nothing if a LE scan is not currently enabled or if the peer doesn't 529 // support advertising. 530 void SendAdvertisingReport(const FakePeer& peer); 531 532 // Sends a single LE advertising report including the scan response for the 533 // given peer. This method will send a legacy or extended advertising 534 // report, depending on which one the peer is configured to send. 535 // 536 // Does nothing if a LE scan is not currently enabled or if the peer doesn't 537 // support advertising. 538 void SendScanResponseReport(const FakePeer& peer); 539 540 // Gets a reference to the set of LE Host Features that were set le_features()541 hci_spec::LESupportedFeatures le_features() { 542 return hci_spec::LESupportedFeatures{.le_features = settings_.le_features}; 543 } 544 545 private: IsValidAdvertisingHandle(hci_spec::AdvertisingHandle handle)546 static bool IsValidAdvertisingHandle(hci_spec::AdvertisingHandle handle) { 547 return handle <= hci_spec::kAdvertisingHandleMax; 548 } 549 550 // Helper function to capture_le_connect_params 551 void CaptureLEConnectParamsForPHY( 552 const pw::bluetooth::emboss::LEExtendedCreateConnectionCommandV1View& 553 params, 554 LEConnectParams::InitiatingPHYs phy); 555 556 // Finds and returns the FakePeer with the given parameters or nullptr if no 557 // such device exists. 558 FakePeer* FindByConnHandle(hci_spec::ConnectionHandle handle); 559 560 // Returns the next available L2CAP signaling channel command ID. 561 uint8_t NextL2CAPCommandId(); 562 563 // Sends a HCI_Command_Complete event with the given status in response to 564 // the command with |opcode|. 565 // 566 // NOTE: This method returns only a status field. Some HCI commands have 567 // multiple fields in their return message. In those cases, it's better (and 568 // clearer) to use the other RespondWithCommandComplete (ByteBuffer as 569 // second parameter) instead. 570 void RespondWithCommandComplete(hci_spec::OpCode opcode, 571 pw::bluetooth::emboss::StatusCode status); 572 573 // Sends an HCI_Command_Complete event in response to the command with 574 // |opcode| and using the provided event packet, filling in the event header 575 // fields. 576 void RespondWithCommandComplete(hci_spec::OpCode opcode, 577 hci::EventPacket* packet); 578 579 // Sends an HCI_Command_Complete event in response to the command with 580 // |opcode| and using the provided event packet, filling in the event header 581 // fields. 582 void RespondWithCommandComplete(pw::bluetooth::emboss::OpCode opcode, 583 hci::EventPacket* packet); 584 585 // Sends a HCI_Command_Status event in response to the command with |opcode| 586 // and using the given data as the parameter payload. 587 void RespondWithCommandStatus(hci_spec::OpCode opcode, 588 pw::bluetooth::emboss::StatusCode status); 589 590 // If a default Command Status event status has been set for the given 591 // |opcode|, send a Command Status event and returns true. 592 bool MaybeRespondWithDefaultCommandStatus(hci_spec::OpCode opcode); 593 594 // If a default status has been configured for the given opcode, sends back 595 // an error Command Complete event and returns true. Returns false if no 596 // response was set. 597 bool MaybeRespondWithDefaultStatus(hci_spec::OpCode opcode); 598 599 // Sends Inquiry Response reports for known BR/EDR devices. 600 void SendInquiryResponses(); 601 602 // Sends LE advertising reports for all known peers with advertising data, 603 // if a scan is currently enabled. If duplicate filtering is disabled then 604 // the reports are continued to be sent until scan is disabled. 605 void SendAdvertisingReports(); 606 607 // Notifies |controller_parameters_cb_|. 608 void NotifyControllerParametersChanged(); 609 610 // Notifies |advertising_state_cb_| 611 void NotifyAdvertisingState(); 612 613 // Notifies |conn_state_cb_| with the given parameters. 614 void NotifyConnectionState(const DeviceAddress& addr, 615 hci_spec::ConnectionHandle handle, 616 bool connected, 617 bool canceled = false); 618 619 // Notifies |le_conn_params_cb_| 620 void NotifyLEConnectionParameters( 621 const DeviceAddress& addr, 622 const hci_spec::LEConnectionParameters& params); 623 624 template <typename T> 625 void SendEnhancedConnectionCompleteEvent( 626 pw::bluetooth::emboss::StatusCode status, 627 const T& params, 628 uint16_t interval, 629 uint16_t max_latency, 630 uint16_t supervision_timeout); 631 632 void SendConnectionCompleteEvent( 633 pw::bluetooth::emboss::StatusCode status, 634 const pw::bluetooth::emboss::LECreateConnectionCommandView& params, 635 uint16_t interval); 636 637 // Called when a HCI_Create_Connection command is received. 638 void OnCreateConnectionCommandReceived( 639 const pw::bluetooth::emboss::CreateConnectionCommandView& params); 640 641 // Called when a HCI_LE_Create_Connection command is received. 642 void OnLECreateConnectionCommandReceived( 643 const pw::bluetooth::emboss::LECreateConnectionCommandView& params); 644 645 // Called when a HCI_LE_Create_Connection command is received. 646 void OnLEExtendedCreateConnectionCommandReceived( 647 const pw::bluetooth::emboss::LEExtendedCreateConnectionCommandV1View& 648 params); 649 650 // Called when a HCI_LE_Connection_Update command is received. 651 void OnLEConnectionUpdateCommandReceived( 652 const pw::bluetooth::emboss::LEConnectionUpdateCommandView& params); 653 654 // Called when a HCI_Disconnect command is received. 655 void OnDisconnectCommandReceived( 656 const pw::bluetooth::emboss::DisconnectCommandView& params); 657 658 // Called when a HCI_LE_Write_Host_Support command is received. 659 void OnWriteLEHostSupportCommandReceived( 660 const pw::bluetooth::emboss::WriteLEHostSupportCommandView& params); 661 662 // Called when a HCI_Write_Secure_Connections_Host_Support command is 663 // received. 664 void OnWriteSecureConnectionsHostSupport( 665 const pw::bluetooth::emboss::WriteSecureConnectionsHostSupportCommandView& 666 params); 667 668 // Called when a HCI_Reset command is received. 669 void OnReset(); 670 671 // Called when a HCI_Inquiry command is received. 672 void OnInquiry(const pw::bluetooth::emboss::InquiryCommandView& params); 673 674 // Called when a HCI_LE_Set_Scan_Enable command is received. 675 void OnLESetScanEnable( 676 const pw::bluetooth::emboss::LESetScanEnableCommandView& params); 677 678 // Called when a HCI_LE_Set_Extended_Scan_Enable command is received. 679 void OnLESetExtendedScanEnable( 680 const pw::bluetooth::emboss::LESetExtendedScanEnableCommandView& params); 681 682 // Called when a HCI_LE_Set_Scan_Parameters command is received. 683 684 void OnLESetScanParameters( 685 const pw::bluetooth::emboss::LESetScanParametersCommandView& params); 686 687 // Called when a HCI_LE_Extended_Set_Scan_Parameters command is received. 688 void OnLESetExtendedScanParameters( 689 const pw::bluetooth::emboss::LESetExtendedScanParametersCommandView& 690 params); 691 692 // Called when a HCI_Read_Local_Extended_Features command is received. 693 void OnReadLocalExtendedFeatures( 694 const pw::bluetooth::emboss::ReadLocalExtendedFeaturesCommandView& 695 params); 696 697 // Called when a HCI_SetEventMask command is received. 698 void OnSetEventMask( 699 const pw::bluetooth::emboss::SetEventMaskCommandView& params); 700 701 // Called when a HCI_LE_Set_Event_Mask command is received. 702 void OnLESetEventMask( 703 const pw::bluetooth::emboss::LESetEventMaskCommandView& params); 704 705 // Called when a HCI_LE_Read_Buffer_Size [v1] command is received. 706 void OnLEReadBufferSizeV1(); 707 708 // Called when a HCI_LE_Read_Buffer_Size [v2] command is received. 709 void OnLEReadBufferSizeV2(); 710 711 // Called when a HCI_LE_Read_Supported_States command is received. 712 void OnLEReadSupportedStates(); 713 714 // Called when a HCI_LE_Read_Local_Supported_Features command is received. 715 void OnLEReadLocalSupportedFeatures(); 716 717 // Called when a HCI_LE_Create_Connection_Cancel command is received. 718 void OnLECreateConnectionCancel(); 719 720 // Called when a HCI_Write_Extended_Inquiry_Response command is received. 721 void OnWriteExtendedInquiryResponse( 722 const pw::bluetooth::emboss::WriteExtendedInquiryResponseCommandView& 723 params); 724 725 // Called when a HCI_Write_Simple_PairingMode command is received. 726 void OnWriteSimplePairingMode( 727 const pw::bluetooth::emboss::WriteSimplePairingModeCommandView& params); 728 729 // Called when a HCI_Read_Simple_Pairing_Mode command is received. 730 void OnReadSimplePairingMode(); 731 732 // Called when a HCI_Write_Page_Scan_Type command is received. 733 void OnWritePageScanType( 734 const pw::bluetooth::emboss::WritePageScanTypeCommandView& params); 735 736 // Called when a HCI_Read_Page_Scan_Type command is received. 737 void OnReadPageScanType(); 738 739 // Called when a HCI_Write_Inquiry_Mode command is received. 740 void OnWriteInquiryMode( 741 const pw::bluetooth::emboss::WriteInquiryModeCommandView& params); 742 743 // Called when a HCI_Read_Inquiry_Mode command is received. 744 void OnReadInquiryMode(); 745 746 // Called when a HCI_Write_Class_OfDevice command is received. 747 void OnWriteClassOfDevice( 748 const pw::bluetooth::emboss::WriteClassOfDeviceCommandView& params); 749 750 // Called when a HCI_Write_Page_Scan_Activity command is received. 751 void OnWritePageScanActivity( 752 const pw::bluetooth::emboss::WritePageScanActivityCommandView& params); 753 754 // Called when a HCI_Read_Page_Scan_Activity command is received. 755 void OnReadPageScanActivity(); 756 757 // Called when a HCI_Write_Scan_Enable command is received. 758 void OnWriteScanEnable( 759 const pw::bluetooth::emboss::WriteScanEnableCommandView& params); 760 761 // Called when a HCI_Read_Scan_Enable command is received. 762 void OnReadScanEnable(); 763 764 // Called when a HCI_Read_Local_Name command is received. 765 void OnReadLocalName(); 766 767 // Called when a HCI_Write_Local_Name command is received. 768 void OnWriteLocalName( 769 const pw::bluetooth::emboss::WriteLocalNameCommandView& params); 770 771 // Called when a HCI_Create_Connection_Cancel command is received. 772 void OnCreateConnectionCancel(); 773 774 // Called when a HCI_Read_Buffer_Size command is received. 775 void OnReadBufferSize(); 776 777 // Called when a HCI_Read_BRADDR command is received. 778 void OnReadBRADDR(); 779 780 // Called when a HCI_LE_Set_Advertising_Enable command is received. 781 void OnLESetAdvertisingEnable( 782 const pw::bluetooth::emboss::LESetAdvertisingEnableCommandView& params); 783 784 // Called when a HCI_LE_Set_Scan_Response_Data command is received. 785 void OnLESetScanResponseData( 786 const pw::bluetooth::emboss::LESetScanResponseDataCommandView& params); 787 788 // Called when a HCI_LE_Set_Advertising_Data command is received. 789 void OnLESetAdvertisingData( 790 const pw::bluetooth::emboss::LESetAdvertisingDataCommandView& params); 791 792 // Called when a HCI_LE_Set_Advertising_Parameters command is received. 793 void OnLESetAdvertisingParameters( 794 const pw::bluetooth::emboss::LESetAdvertisingParametersCommandView& 795 params); 796 797 // Called when a HCI_LE_Set_Random_Address command is received. 798 void OnLESetRandomAddress( 799 const pw::bluetooth::emboss::LESetRandomAddressCommandView& params); 800 801 // Called when a HCI_LE_Set_Advertising_Set_Random_Address command is 802 // received. 803 void OnLESetAdvertisingSetRandomAddress( 804 const pw::bluetooth::emboss::LESetAdvertisingSetRandomAddressCommandView& 805 params); 806 807 // Called when a HCI_LE_Set_Extended_Advertising_Data command is received. 808 void OnLESetExtendedAdvertisingParameters( 809 const pw::bluetooth::emboss:: 810 LESetExtendedAdvertisingParametersV1CommandView& params); 811 812 // Called when a HCI_LE_Set_Extended_Advertising_Data command is received. 813 void OnLESetExtendedAdvertisingData( 814 const pw::bluetooth::emboss::LESetExtendedAdvertisingDataCommandView& 815 params); 816 817 // Called when a HCI_LE_Set_Extended_Scan_Response_Data command is received. 818 void OnLESetExtendedScanResponseData( 819 const pw::bluetooth::emboss::LESetExtendedScanResponseDataCommandView& 820 params); 821 822 // Called when a HCI_LE_Set_Extended_Advertising_Enable command is received. 823 void OnLESetExtendedAdvertisingEnable( 824 const pw::bluetooth::emboss::LESetExtendedAdvertisingEnableCommandView& 825 params); 826 827 // Called when a HCI_LE_Set_Host_Feature command is received. 828 void OnLESetHostFeature( 829 const pw::bluetooth::emboss::LESetHostFeatureCommandView& params); 830 831 // Called when a HCI_LE_Read_Maximum_Advertising_Data_Length command is 832 // received. 833 void OnLEReadMaximumAdvertisingDataLength(); 834 835 // Called when a HCI_LE_Read_Number_of_Supported_Advertising_Sets command is 836 // received. 837 void OnLEReadNumberOfSupportedAdvertisingSets(); 838 839 // Called when a HCI_LE_Remove_Advertising_Set command is received. 840 void OnLERemoveAdvertisingSet( 841 const pw::bluetooth::emboss::LERemoveAdvertisingSetCommandView& params); 842 843 // Called when a HCI_LE_Clear_Advertising_Sets command is received. 844 void OnLEClearAdvertisingSets(); 845 846 // Called when a HCI_Read_Local_Supported_Features command is received. 847 void OnReadLocalSupportedFeatures(); 848 849 // Called when a HCI_Read_Local_Supported_Commands command is received. 850 void OnReadLocalSupportedCommands(); 851 852 // Called when a HCI_Read_Local_Version_Info command is received. 853 void OnReadLocalVersionInfo(); 854 855 // Interrogation command handlers: 856 857 // Called when a HCI_Read_Remote_Name_Request command is received. 858 void OnReadRemoteNameRequestCommandReceived( 859 const pw::bluetooth::emboss::RemoteNameRequestCommandView& params); 860 861 // Called when a HCI_Read_Remote_Supported_Features command is received. 862 void OnReadRemoteSupportedFeaturesCommandReceived( 863 const pw::bluetooth::emboss::ReadRemoteSupportedFeaturesCommandView& 864 params); 865 866 // Called when a HCI_Read_Remote_Version_Information command is received. 867 void OnReadRemoteVersionInfoCommandReceived( 868 const pw::bluetooth::emboss::ReadRemoteVersionInfoCommandView& params); 869 870 // Called when a HCI_Read_Remote_Extended_Features command is received. 871 void OnReadRemoteExtendedFeaturesCommandReceived( 872 const pw::bluetooth::emboss::ReadRemoteExtendedFeaturesCommandView& 873 params); 874 875 // Pairing command handlers: 876 877 // Called when a HCI_Authentication_Requested command is received. 878 void OnAuthenticationRequestedCommandReceived( 879 const pw::bluetooth::emboss::AuthenticationRequestedCommandView& params); 880 881 // Called when a HCI_Link_Key_Request_Reply command is received. 882 void OnLinkKeyRequestReplyCommandReceived( 883 const pw::bluetooth::emboss::LinkKeyRequestReplyCommandView& params); 884 885 // Called when a HCI_Link_Key_Request_Negative_Reply command is received. 886 void OnLinkKeyRequestNegativeReplyCommandReceived( 887 const pw::bluetooth::emboss::LinkKeyRequestNegativeReplyCommandView& 888 params); 889 890 // Called when a HCI_IO_Capability_Request_Reply command is received. 891 void OnIOCapabilityRequestReplyCommand( 892 const pw::bluetooth::emboss::IoCapabilityRequestReplyCommandView& params); 893 894 // Called when a HCI_User_Confirmation_Request_Reply command is received. 895 void OnUserConfirmationRequestReplyCommand( 896 const pw::bluetooth::emboss::UserConfirmationRequestReplyCommandView& 897 params); 898 899 // Called when a HCI_User_Confirmation_Request_Negative_Reply command is 900 // received. 901 void OnUserConfirmationRequestNegativeReplyCommand( 902 const pw::bluetooth::emboss:: 903 UserConfirmationRequestNegativeReplyCommandView& params); 904 905 // Called when a HCI_Set_Connection_Encryption command is received. 906 void OnSetConnectionEncryptionCommand( 907 const pw::bluetooth::emboss::SetConnectionEncryptionCommandView& params); 908 909 // Called when a HCI_Read_Encryption_Key_Size command is received. 910 void OnReadEncryptionKeySizeCommand( 911 const pw::bluetooth::emboss::ReadEncryptionKeySizeCommandView& params); 912 913 // Called when a HCI_Enhanced_Accept_Synchronous_Connection_Request command 914 // is received. 915 void OnEnhancedAcceptSynchronousConnectionRequestCommand( 916 const pw::bluetooth::emboss:: 917 EnhancedAcceptSynchronousConnectionRequestCommandView& params); 918 919 // Called when a HCI_Enhanced_Setup_Synchronous_Connection command is 920 // received. 921 void OnEnhancedSetupSynchronousConnectionCommand( 922 const pw::bluetooth::emboss:: 923 EnhancedSetupSynchronousConnectionCommandView& params); 924 925 // Called when a HCI_LE_Read_Remote_Features_Command is received. 926 void OnLEReadRemoteFeaturesCommand( 927 const pw::bluetooth::emboss::LEReadRemoteFeaturesCommandView& params); 928 929 // Called when a HCI_LE_Enable_Encryption command is received, responds with 930 // a successful encryption change event. 931 void OnLEStartEncryptionCommand( 932 const pw::bluetooth::emboss::LEEnableEncryptionCommandView& params); 933 934 void OnWriteSynchronousFlowControlEnableCommand( 935 const pw::bluetooth::emboss::WriteSynchronousFlowControlEnableCommandView& 936 params); 937 938 void OnReadLocalSupportedControllerDelay( 939 const pw::bluetooth::emboss::ReadLocalSupportedControllerDelayCommandView& 940 params); 941 942 void OnAndroidLEGetVendorCapabilities(); 943 944 void OnAndroidA2dpOffloadCommand( 945 const PacketView<hci_spec::CommandHeader>& command_packet); 946 947 void OnAndroidStartA2dpOffload( 948 const android_emb::StartA2dpOffloadCommandView& params); 949 950 void OnAndroidStopA2dpOffload(); 951 952 void OnAndroidLEMultiAdvt( 953 const PacketView<hci_spec::CommandHeader>& command_packet); 954 955 void OnAndroidLEMultiAdvtSetAdvtParam( 956 const android_emb::LEMultiAdvtSetAdvtParamCommandView& params); 957 958 void OnAndroidLEMultiAdvtSetAdvtData( 959 const android_emb::LEMultiAdvtSetAdvtDataCommandView& params); 960 961 void OnAndroidLEMultiAdvtSetScanResp( 962 const android_emb::LEMultiAdvtSetScanRespDataCommandView& params); 963 964 void OnAndroidLEMultiAdvtSetRandomAddr( 965 const android_emb::LEMultiAdvtSetRandomAddrCommandView& params); 966 967 void OnAndroidLEMultiAdvtEnable( 968 const android_emb::LEMultiAdvtEnableCommandView& params); 969 970 // Called when a command with an OGF of hci_spec::kVendorOGF is received. 971 void OnVendorCommand( 972 const PacketView<hci_spec::CommandHeader>& command_packet); 973 974 // Respond to a command packet. This may be done immediately upon reception 975 // or via a client- triggered callback if pause_responses_for_opcode has 976 // been called for that command's opcode. 977 void HandleReceivedCommandPacket( 978 const PacketView<hci_spec::CommandHeader>& command_packet); 979 void HandleReceivedCommandPacket(const hci::CommandPacket& command_packet); 980 981 void OnCommandPacketReceived( 982 const PacketView<hci_spec::CommandHeader>& command_packet); 983 void OnACLDataPacketReceived(const ByteBuffer& acl_data_packet); 984 void OnScoDataPacketReceived(const ByteBuffer& sco_data_packet); 985 void OnIsoDataPacketReceived(const ByteBuffer& iso_data_packet); 986 987 const uint8_t BIT_1 = 1; isBREDRPageScanEnabled()988 bool isBREDRPageScanEnabled() const { 989 return (bredr_scan_state_ >> BIT_1) & BIT_1; 990 } 991 992 enum class AdvertisingProcedure : uint8_t { 993 kUnknown, 994 kLegacy, 995 kExtended, 996 }; 997 advertising_procedure()998 const AdvertisingProcedure& advertising_procedure() const { 999 return advertising_procedure_; 1000 } 1001 1002 bool EnableLegacyAdvertising(); 1003 bool EnableExtendedAdvertising(); 1004 1005 Settings settings_; 1006 1007 // Value is non-null when A2DP offload is started, and null when it is 1008 // stopped. 1009 std::optional<OffloadedA2dpChannel> offloaded_a2dp_channel_state_; 1010 1011 LEScanState le_scan_state_; 1012 LEAdvertisingState legacy_advertising_state_; 1013 std::unordered_map<hci_spec::AdvertisingHandle, LEAdvertisingState> 1014 extended_advertising_states_; 1015 1016 // Used for BR/EDR Scans 1017 uint8_t bredr_scan_state_ = 0x00; 1018 pw::bluetooth::emboss::PageScanType page_scan_type_ = 1019 pw::bluetooth::emboss::PageScanType::STANDARD_SCAN; 1020 uint16_t page_scan_interval_ = 0x0800; 1021 uint16_t page_scan_window_ = 0x0012; 1022 1023 // The GAP local name, as written/read by HCI_(Read/Write)_Local_Name. While 1024 // the aforementioned HCI commands carry the name in a 248 byte buffer, 1025 // |local_name_| contains the intended value. 1026 std::string local_name_; 1027 1028 // The local device class configured by HCI_Write_Class_of_Device. 1029 DeviceClass device_class_; 1030 1031 // Variables used for 1032 // HCI_LE_Create_Connection/HCI_LE_Create_Connection_Cancel. 1033 uint16_t next_conn_handle_ = 0u; 1034 SmartTask le_connect_rsp_task_{pw_dispatcher()}; 1035 std::optional<LEConnectParams> le_connect_params_; 1036 bool le_connect_pending_ = false; 1037 1038 // Variables used for 1039 // HCI_BREDR_Create_Connection/HCI_BREDR_Create_Connection_Cancel. 1040 bool bredr_connect_pending_ = false; 1041 DeviceAddress pending_bredr_connect_addr_; 1042 SmartTask bredr_connect_rsp_task_{pw_dispatcher()}; 1043 1044 // ID used for L2CAP LE signaling channel commands. 1045 uint8_t next_le_sig_id_ = 1u; 1046 1047 // Used to indicate whether to respond back to TX Power Level read or not. 1048 bool respond_to_tx_power_read_ = true; 1049 1050 // The Inquiry Mode that the controller is in. Determines what types of 1051 // events are faked when a hci_spec::kInquiry is started. 1052 pw::bluetooth::emboss::InquiryMode inquiry_mode_; 1053 1054 // The maximum number of advertising sets supported by the controller 1055 uint8_t num_supported_advertising_sets_ = 1; 1056 1057 // The number of results left in Inquiry Mode operation. 1058 // If negative, no limit has been set. 1059 int16_t inquiry_num_responses_left_; 1060 1061 // Used to setup default Command Status event responses. 1062 std::unordered_map<hci_spec::OpCode, pw::bluetooth::emboss::StatusCode> 1063 default_command_status_map_; 1064 1065 // Used to setup default Command Complete event status responses (for 1066 // simulating errors) 1067 std::unordered_map<hci_spec::OpCode, pw::bluetooth::emboss::StatusCode> 1068 default_status_map_; 1069 1070 // The set of fake peers that are visible. 1071 std::unordered_map<DeviceAddress, std::unique_ptr<FakePeer>> peers_; 1072 1073 // Callbacks and counters that are intended for unit tests. 1074 int le_create_connection_command_count_ = 0; 1075 int acl_create_connection_command_count_ = 0; 1076 1077 fit::function<void(pw::bluetooth::emboss::LECreateConnectionCommandView)> 1078 le_create_connection_cb_; 1079 fit::closure controller_parameters_cb_; 1080 ScanStateCallback scan_state_cb_; 1081 fit::closure advertising_state_cb_; 1082 ConnectionStateCallback conn_state_cb_; 1083 LEConnectionParametersCallback le_conn_params_cb_; 1084 fit::closure le_read_remote_features_cb_; 1085 1086 // Associates opcodes with client-supplied pause listeners. Commands with 1087 // these opcodes will hang with no response until the client invokes the 1088 // passed-out closure. 1089 std::unordered_map<hci_spec::OpCode, fit::function<void(fit::closure)>> 1090 paused_opcode_listeners_; 1091 1092 // Called when ACL data packets received. 1093 DataCallback acl_data_callback_ = nullptr; 1094 std::optional<pw::async::HeapDispatcher> data_dispatcher_; 1095 1096 // Called when SCO data packets received. 1097 DataCallback sco_data_callback_ = nullptr; 1098 1099 // Called when ISO data packets received. 1100 DataCallback iso_data_callback_ = nullptr; 1101 1102 bool auto_completed_packets_event_enabled_ = true; 1103 bool auto_disconnection_complete_event_enabled_ = true; 1104 1105 AdvertisingProcedure advertising_procedure_ = AdvertisingProcedure::kUnknown; 1106 uint16_t max_advertising_data_length_ = hci_spec::kMaxLEAdvertisingDataLength; 1107 1108 BT_DISALLOW_COPY_AND_ASSIGN_ALLOW_MOVE(FakeController); 1109 }; 1110 1111 } // namespace bt::testing 1112