Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89489fa1 authored by Chris Manton's avatar Chris Manton Committed by Hansong Zhang
Browse files

Plumb through hci_status to clients

Classic ACL:
- OnModeChange
- OnSniffSubrating
- OnRoleChange
- OnReadRemoteVersionInformationComplete

LE ACL:
- OnConnectionUpdate
- OnReadRemoteVersionInformationComplete
- OnPhyUpdate

Bug: 178358499
Test: cert
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I506dd6ae57e31e25f172f181951ae44fd1ea69d6
parent 6f187827
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -52,8 +52,8 @@ class AclConnectionTracker : public ConnectionManagementCallbacks {
  void OnConnectionPacketTypeChanged(uint16_t packet_type) override {
    SAVE_OR_CALL(OnConnectionPacketTypeChanged, packet_type)
  }
  void OnAuthenticationComplete() override {
    SAVE_OR_CALL(OnAuthenticationComplete)
  void OnAuthenticationComplete(hci::ErrorCode hci_status) override {
    SAVE_OR_CALL(OnAuthenticationComplete, hci_status)
  }
  void OnEncryptionChange(EncryptionEnabled enabled) override {
    SAVE_OR_CALL(OnEncryptionChange, enabled)
@@ -68,12 +68,14 @@ class AclConnectionTracker : public ConnectionManagementCallbacks {
    SAVE_OR_CALL(OnModeChange, status, current_mode, interval)
  }
  void OnSniffSubrating(
      hci::ErrorCode hci_status,
      uint16_t maximum_transmit_latency,
      uint16_t maximum_receive_latency,
      uint16_t minimum_remote_timeout,
      uint16_t minimum_local_timeout) override {
    SAVE_OR_CALL(
        OnSniffSubrating,
        hci_status,
        maximum_transmit_latency,
        maximum_receive_latency,
        minimum_remote_timeout,
@@ -125,12 +127,12 @@ class AclConnectionTracker : public ConnectionManagementCallbacks {
  void OnCentralLinkKeyComplete(KeyFlag key_flag) override {
    SAVE_OR_CALL(OnCentralLinkKeyComplete, key_flag)
  }
  void OnRoleChange(Role new_role) override {
    SAVE_OR_CALL(OnRoleChange, new_role)
  void OnRoleChange(hci::ErrorCode hci_status, Role new_role) override {
    SAVE_OR_CALL(OnRoleChange, hci_status, new_role)
  }
  void OnReadRemoteVersionInformationComplete(
      uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) override {
    SAVE_OR_CALL(OnReadRemoteVersionInformationComplete, lmp_version, manufacturer_name, sub_version);
      hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) override {
    SAVE_OR_CALL(OnReadRemoteVersionInformationComplete, hci_status, lmp_version, manufacturer_name, sub_version);
  }
  void OnReadRemoteExtendedFeaturesComplete(uint8_t page_number, uint8_t max_page_number, uint64_t features) override {
    SAVE_OR_CALL(OnReadRemoteExtendedFeaturesComplete, page_number, max_page_number, features);
+14 −33
Original line number Diff line number Diff line
@@ -241,7 +241,7 @@ struct classic_impl : public security::ISecurityManagerListener {
    connection->locally_initiated_ = locally_initiated;
    auto& connection_proxy = conn_pair.first->second;
    connection_proxy.connection_management_callbacks_ = connection->GetEventCallbacks();
    connection_proxy.connection_management_callbacks_->OnRoleChange(current_role);
    connection_proxy.connection_management_callbacks_->OnRoleChange(hci::ErrorCode::SUCCESS, current_role);
    client_handler_->Post(common::BindOnce(&ConnectionCallbacks::OnConnectSuccess,
                                           common::Unretained(client_callbacks_), std::move(connection)));
    while (!pending_outgoing_connections_.empty()) {
@@ -307,11 +307,6 @@ struct classic_impl : public security::ISecurityManagerListener {
    if (!authentication_complete.IsValid()) {
      LOG_ERROR("Received on_authentication_complete with invalid packet");
      return;
    } else if (authentication_complete.GetStatus() != ErrorCode::SUCCESS) {
      auto status = authentication_complete.GetStatus();
      std::string error_code = ErrorCodeText(status);
      LOG_ERROR("Received on_authentication_complete with error code %s", error_code.c_str());
      return;
    }
    uint16_t handle = authentication_complete.GetConnectionHandle();
    auto callbacks = get_callbacks(handle);
@@ -320,7 +315,7 @@ struct classic_impl : public security::ISecurityManagerListener {
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    callbacks->OnAuthenticationComplete();
    callbacks->OnAuthenticationComplete(authentication_complete.GetStatus());
  }

  void cancel_connect(Address address) {
@@ -408,21 +403,15 @@ struct classic_impl : public security::ISecurityManagerListener {
      LOG_ERROR("Received on_mode_change with invalid packet");
      return;
    }
    auto status = mode_change_view.GetStatus();
    uint16_t handle = mode_change_view.GetConnectionHandle();
    if (status != ErrorCode::SUCCESS) {
      std::string error_code = ErrorCodeText(status);
      LOG_ERROR("Received on_mode_change on handle 0x0%04hx with error code %s", handle, error_code.c_str());
    }
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    Mode current_mode = mode_change_view.GetCurrentMode();
    uint16_t interval = mode_change_view.GetInterval();
    callbacks->OnModeChange(status, current_mode, interval);
    callbacks->OnModeChange(
        mode_change_view.GetStatus(), mode_change_view.GetCurrentMode(), mode_change_view.GetInterval());
  }

  void on_sniff_subrating(EventView packet) {
@@ -430,11 +419,6 @@ struct classic_impl : public security::ISecurityManagerListener {
    if (!sniff_subrating_view.IsValid()) {
      LOG_ERROR("Received on_sniff_subrating with invalid packet");
      return;
    } else if (sniff_subrating_view.GetStatus() != ErrorCode::SUCCESS) {
      auto status = sniff_subrating_view.GetStatus();
      std::string error_code = ErrorCodeText(status);
      LOG_ERROR("Received on_sniff_subrating with error code %s", error_code.c_str());
      return;
    }
    uint16_t handle = sniff_subrating_view.GetConnectionHandle();
    auto callbacks = get_callbacks(handle);
@@ -443,11 +427,12 @@ struct classic_impl : public security::ISecurityManagerListener {
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    uint16_t max_tx_lat = sniff_subrating_view.GetMaximumTransmitLatency();
    uint16_t max_rx_lat = sniff_subrating_view.GetMaximumReceiveLatency();
    uint16_t min_remote_timeout = sniff_subrating_view.GetMinimumRemoteTimeout();
    uint16_t min_local_timeout = sniff_subrating_view.GetMinimumLocalTimeout();
    callbacks->OnSniffSubrating(max_tx_lat, max_rx_lat, min_remote_timeout, min_local_timeout);
    callbacks->OnSniffSubrating(
        sniff_subrating_view.GetStatus(),
        sniff_subrating_view.GetMaximumTransmitLatency(),
        sniff_subrating_view.GetMaximumReceiveLatency(),
        sniff_subrating_view.GetMinimumRemoteTimeout(),
        sniff_subrating_view.GetMinimumLocalTimeout());
  }

  void on_qos_setup_complete(EventView packet) {
@@ -481,17 +466,13 @@ struct classic_impl : public security::ISecurityManagerListener {
    if (!role_change_view.IsValid()) {
      LOG_ERROR("Received on_role_change with invalid packet");
      return;
    } else if (role_change_view.GetStatus() != ErrorCode::SUCCESS) {
      auto status = role_change_view.GetStatus();
      std::string error_code = ErrorCodeText(status);
      LOG_ERROR("Received on_role_change with error code %s", error_code.c_str());
      return;
    }
    auto hci_status = role_change_view.GetStatus();
    Address bd_addr = role_change_view.GetBdAddr();
    Role new_role = role_change_view.GetNewRole();
    for (auto& connection_pair : acl_connections_) {
      if (connection_pair.second.address_with_type_.GetAddress() == bd_addr) {
        connection_pair.second.connection_management_callbacks_->OnRoleChange(new_role);
        connection_pair.second.connection_management_callbacks_->OnRoleChange(hci_status, new_role);
      }
    }
  }
@@ -541,14 +522,14 @@ struct classic_impl : public security::ISecurityManagerListener {
  }

  void on_read_remote_version_information(
      uint16_t handle, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version) {
      hci::ErrorCode hci_status, uint16_t handle, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version) {
    auto callbacks = get_callbacks(handle);
    if (callbacks == nullptr) {
      LOG_WARN("Unknown connection handle 0x%04hx", handle);
      ASSERT(!crash_on_unknown_handle_);
      return;
    }
    callbacks->OnReadRemoteVersionInformationComplete(version, manufacturer_name, sub_version);
    callbacks->OnReadRemoteVersionInformationComplete(hci_status, version, manufacturer_name, sub_version);
  }

  void on_read_remote_supported_features_complete(EventView packet) {
+4 −3
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ class ConnectionManagementCallbacks {
  // Invoked when controller sends Connection Packet Type Changed event with Success error code
  virtual void OnConnectionPacketTypeChanged(uint16_t packet_type) = 0;
  // Invoked when controller sends Authentication Complete event with Success error code
  virtual void OnAuthenticationComplete() = 0;
  virtual void OnAuthenticationComplete(hci::ErrorCode hci_status) = 0;
  // Invoked when controller sends Encryption Change event with Success error code
  virtual void OnEncryptionChange(EncryptionEnabled enabled) = 0;
  // Invoked when controller sends Change Connection Link Key Complete event with Success error code
@@ -41,6 +41,7 @@ class ConnectionManagementCallbacks {
  virtual void OnModeChange(ErrorCode status, Mode current_mode, uint16_t interval) = 0;
  // Invoked when controller sends Sniff Subrating event with Success error code
  virtual void OnSniffSubrating(
      hci::ErrorCode hci_status,
      uint16_t maximum_transmit_latency,
      uint16_t maximum_receive_latency,
      uint16_t minimum_remote_timeout,
@@ -80,12 +81,12 @@ class ConnectionManagementCallbacks {
  // Invoked when controller sends Central Link Key Complete event
  virtual void OnCentralLinkKeyComplete(KeyFlag key_flag) = 0;
  // Invoked when controller sends Role Change event
  virtual void OnRoleChange(Role new_role) = 0;
  virtual void OnRoleChange(hci::ErrorCode hci_status, Role new_role) = 0;
  // Invoked when controller sends DisconnectComplete
  virtual void OnDisconnection(ErrorCode reason) = 0;
  // Invoked when controller sends Read Remote Version Information Complete
  virtual void OnReadRemoteVersionInformationComplete(
      uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) = 0;
      hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) = 0;
  // Invoked when controller sends Read Remote Extended Features Complete
  virtual void OnReadRemoteExtendedFeaturesComplete(
      uint8_t page_number, uint8_t max_page_number, uint64_t features) = 0;
+8 −6
Original line number Diff line number Diff line
@@ -47,19 +47,21 @@ class LeAclConnectionTracker : public LeConnectionManagementCallbacks {
        common::BindOnce(&LeConnectionManagementCallbacks::f, common::Unretained(client_callbacks_), __VA_ARGS__)); \
  }

  void OnConnectionUpdate(uint16_t conn_interval, uint16_t conn_latency, uint16_t supervision_timeout) override {
    SAVE_OR_CALL(OnConnectionUpdate, conn_interval, conn_latency, supervision_timeout)
  void OnConnectionUpdate(
      hci::ErrorCode hci_status, uint16_t conn_interval, uint16_t conn_latency, uint16_t supervision_timeout) override {
    SAVE_OR_CALL(OnConnectionUpdate, hci_status, conn_interval, conn_latency, supervision_timeout)
  }

  void OnDataLengthChange(uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time) override {
    SAVE_OR_CALL(OnDataLengthChange, tx_octets, tx_time, rx_octets, rx_time)
  }

  void OnReadRemoteVersionInformationComplete(uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {
    SAVE_OR_CALL(OnReadRemoteVersionInformationComplete, lmp_version, manufacturer_name, sub_version);
  void OnReadRemoteVersionInformationComplete(
      hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {
    SAVE_OR_CALL(OnReadRemoteVersionInformationComplete, hci_status, lmp_version, manufacturer_name, sub_version);
  }
  void OnPhyUpdate(uint8_t tx_phy, uint8_t rx_phy) override {
    SAVE_OR_CALL(OnPhyUpdate, tx_phy, rx_phy);
  void OnPhyUpdate(hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy) override {
    SAVE_OR_CALL(OnPhyUpdate, hci_status, tx_phy, rx_phy);
  }
  void OnLocalAddressUpdate(AddressWithType address_with_type) override {
    SAVE_OR_CALL(OnLocalAddressUpdate, address_with_type);
+7 −4
Original line number Diff line number Diff line
@@ -28,13 +28,16 @@ namespace acl_manager {
class LeConnectionManagementCallbacks {
 public:
  virtual ~LeConnectionManagementCallbacks() = default;
  virtual void OnConnectionUpdate(uint16_t connection_interval, uint16_t connection_latency,
  virtual void OnConnectionUpdate(
      hci::ErrorCode hci_status,
      uint16_t connection_interval,
      uint16_t connection_latency,
      uint16_t supervision_timeout) = 0;
  virtual void OnDataLengthChange(uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time) = 0;
  virtual void OnDisconnection(ErrorCode reason) = 0;
  virtual void OnReadRemoteVersionInformationComplete(
      uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) = 0;
  virtual void OnPhyUpdate(uint8_t tx_phy, uint8_t rx_phy) = 0;
      hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) = 0;
  virtual void OnPhyUpdate(hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy) = 0;
  virtual void OnLocalAddressUpdate(AddressWithType address_with_type) = 0;
};

Loading