OSDN Git Service

Plumb through hci_status to clients
authorChris Manton <cmanton@google.com>
Mon, 1 Feb 2021 04:00:34 +0000 (20:00 -0800)
committerHansong Zhang <hsz@google.com>
Tue, 2 Feb 2021 00:17:21 +0000 (00:17 +0000)
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

32 files changed:
gd/hci/acl_manager/classic_acl_connection.cc
gd/hci/acl_manager/classic_impl.h
gd/hci/acl_manager/connection_management_callbacks.h
gd/hci/acl_manager/le_acl_connection.cc
gd/hci/acl_manager/le_connection_management_callbacks.h
gd/hci/acl_manager/le_impl.h
gd/hci/acl_manager_test.cc
gd/hci/facade/acl_manager_facade.cc
gd/hci/facade/le_acl_manager_facade.cc
gd/hci/fuzz/fuzz_hci_layer.cc
gd/hci/fuzz/fuzz_hci_layer.h
gd/hci/fuzz/hci_layer_fuzz_client.cc
gd/hci/hci_layer.cc
gd/hci/hci_layer.h
gd/l2cap/classic/facade.cc
gd/l2cap/classic/internal/link.cc
gd/l2cap/classic/internal/link.h
gd/l2cap/classic/internal/link_manager.cc
gd/l2cap/classic/internal/link_manager.h
gd/l2cap/classic/link_property_listener.h
gd/l2cap/classic/link_security_interface.h
gd/l2cap/le/internal/link.cc
gd/l2cap/le/internal/link.h
gd/l2cap/le/internal/link_manager.cc
gd/l2cap/le/internal/link_manager.h
gd/l2cap/le/link_property_listener.h
gd/security/channel/security_manager_channel.cc
gd/security/channel/security_manager_channel.h
gd/security/channel/security_manager_channel_unittest.cc
gd/security/pairing/classic_pairing_handler_unittest.cc
main/shim/acl.cc
main/shim/l2c_api.cc

index a8f46aa..0d5f68a 100644 (file)
@@ -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);
index e411607..9853821 100644 (file)
@@ -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) {
index 56a6842..4308f39 100644 (file)
@@ -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;
index 0320b79..bade58e 100644 (file)
@@ -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);
index d34cd5e..59d38a6 100644 (file)
@@ -28,13 +28,16 @@ namespace acl_manager {
 class LeConnectionManagementCallbacks {
  public:
   virtual ~LeConnectionManagementCallbacks() = default;
-  virtual void OnConnectionUpdate(uint16_t connection_interval, uint16_t connection_latency,
-                                  uint16_t supervision_timeout) = 0;
+  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;
 };
 
index bb22551..1c42706 100644 (file)
@@ -250,11 +250,6 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
     if (!complete_view.IsValid()) {
       LOG_ERROR("Received on_le_connection_update_complete with invalid packet");
       return;
-    } else if (complete_view.GetStatus() != ErrorCode::SUCCESS) {
-      auto status = complete_view.GetStatus();
-      std::string error_code = ErrorCodeText(status);
-      LOG_ERROR("Received on_le_connection_update_complete with error code %s", error_code.c_str());
-      return;
     }
     auto handle = complete_view.GetConnectionHandle();
     auto callbacks = get_callbacks(handle);
@@ -264,7 +259,10 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
       return;
     }
     callbacks->OnConnectionUpdate(
-        complete_view.GetConnInterval(), complete_view.GetConnLatency(), complete_view.GetSupervisionTimeout());
+        complete_view.GetStatus(),
+        complete_view.GetConnInterval(),
+        complete_view.GetConnLatency(),
+        complete_view.GetSupervisionTimeout());
   }
 
   void on_le_phy_update_complete(LeMetaEventView view) {
@@ -272,11 +270,6 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
     if (!complete_view.IsValid()) {
       LOG_ERROR("Received on_le_phy_update_complete with invalid packet");
       return;
-    } else if (complete_view.GetStatus() != ErrorCode::SUCCESS) {
-      auto status = complete_view.GetStatus();
-      std::string error_code = ErrorCodeText(status);
-      LOG_ERROR("Received on_le_connection_update_complete with error code %s", error_code.c_str());
-      return;
     }
     auto handle = complete_view.GetConnectionHandle();
     auto callbacks = get_callbacks(handle);
@@ -285,18 +278,18 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
       ASSERT(!crash_on_unknown_handle_);
       return;
     }
-    callbacks->OnPhyUpdate(complete_view.GetTxPhy(), complete_view.GetRxPhy());
+    callbacks->OnPhyUpdate(complete_view.GetStatus(), complete_view.GetTxPhy(), complete_view.GetRxPhy());
   }
 
   void on_le_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("Can't find connection 0x%hx", handle);
       ASSERT(!crash_on_unknown_handle_);
       return;
     }
-    callbacks->OnReadRemoteVersionInformationComplete(version, manufacturer_name, sub_version);
+    callbacks->OnReadRemoteVersionInformationComplete(hci_status, version, manufacturer_name, sub_version);
   }
 
   void enqueue_command(std::unique_ptr<CommandBuilder> command_packet) {
index cd81ac1..6165a9a 100644 (file)
@@ -479,14 +479,15 @@ class AclManagerWithConnectionTest : public AclManagerTest {
   class MockConnectionManagementCallbacks : public ConnectionManagementCallbacks {
    public:
     MOCK_METHOD1(OnConnectionPacketTypeChanged, void(uint16_t packet_type));
-    MOCK_METHOD0(OnAuthenticationComplete, void());
+    MOCK_METHOD1(OnAuthenticationComplete, void(hci::ErrorCode hci_status));
     MOCK_METHOD1(OnEncryptionChange, void(EncryptionEnabled enabled));
     MOCK_METHOD0(OnChangeConnectionLinkKeyComplete, void());
     MOCK_METHOD1(OnReadClockOffsetComplete, void(uint16_t clock_offse));
     MOCK_METHOD3(OnModeChange, void(ErrorCode status, Mode current_mode, uint16_t interval));
-    MOCK_METHOD4(
+    MOCK_METHOD5(
         OnSniffSubrating,
         void(
+            ErrorCode status,
             uint16_t maximum_transmit_latency,
             uint16_t maximum_receive_latency,
             uint16_t minimum_remote_timeout,
@@ -508,11 +509,11 @@ class AclManagerWithConnectionTest : public AclManagerTest {
     MOCK_METHOD1(OnReadRssiComplete, void(uint8_t rssi));
     MOCK_METHOD2(OnReadClockComplete, void(uint32_t clock, uint16_t accuracy));
     MOCK_METHOD1(OnCentralLinkKeyComplete, void(KeyFlag flag));
-    MOCK_METHOD1(OnRoleChange, void(Role new_role));
+    MOCK_METHOD2(OnRoleChange, void(ErrorCode hci_status, Role new_role));
     MOCK_METHOD1(OnDisconnection, void(ErrorCode reason));
-    MOCK_METHOD3(
+    MOCK_METHOD4(
         OnReadRemoteVersionInformationComplete,
-        void(uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version));
+        void(hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version));
     MOCK_METHOD3(
         OnReadRemoteExtendedFeaturesComplete, void(uint8_t page_number, uint8_t max_page_number, uint64_t features));
   } mock_connection_management_callbacks_;
@@ -648,14 +649,18 @@ class AclManagerWithLeConnectionTest : public AclManagerTest {
   class MockLeConnectionManagementCallbacks : public LeConnectionManagementCallbacks {
    public:
     MOCK_METHOD1(OnDisconnection, void(ErrorCode reason));
-    MOCK_METHOD3(
+    MOCK_METHOD4(
         OnConnectionUpdate,
-        void(uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout));
+        void(
+            hci::ErrorCode hci_status,
+            uint16_t connection_interval,
+            uint16_t connection_latency,
+            uint16_t supervision_timeout));
     MOCK_METHOD4(OnDataLengthChange, void(uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time));
-    MOCK_METHOD3(
+    MOCK_METHOD4(
         OnReadRemoteVersionInformationComplete,
-        void(uint8_t version, uint16_t manufacturer_name, uint16_t sub_version));
-    MOCK_METHOD2(OnPhyUpdate, void(uint8_t tx_phy, uint8_t rx_phy));
+        void(hci::ErrorCode hci_status, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version));
+    MOCK_METHOD3(OnPhyUpdate, void(hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy));
     MOCK_METHOD1(OnLocalAddressUpdate, void(AddressWithType address_with_type));
   } mock_le_connection_management_callbacks_;
 };
@@ -780,6 +785,7 @@ TEST_F(AclManagerWithLeConnectionTest, invoke_registered_callback_le_connection_
   connection_->RegisterCallbacks(&mock_le_connection_management_callbacks_, client_handler_);
 
   std::promise<ErrorCode> promise;
+  ErrorCode hci_status = hci::ErrorCode::SUCCESS;
   uint16_t connection_interval_min = 0x0012;
   uint16_t connection_interval_max = 0x0080;
   uint16_t connection_interval = (connection_interval_max + connection_interval_min) / 2;
@@ -793,8 +799,9 @@ TEST_F(AclManagerWithLeConnectionTest, invoke_registered_callback_le_connection_
       LeConnectionUpdateView::Create(LeConnectionManagementCommandView::Create(AclCommandView::Create(update_packet)));
   ASSERT_TRUE(update_view.IsValid());
   EXPECT_EQ(update_view.GetConnectionHandle(), handle_);
-  EXPECT_CALL(mock_le_connection_management_callbacks_,
-              OnConnectionUpdate(connection_interval, connection_latency, supervision_timeout));
+  EXPECT_CALL(
+      mock_le_connection_management_callbacks_,
+      OnConnectionUpdate(hci_status, connection_interval, connection_latency, supervision_timeout));
   test_hci_layer_->IncomingLeMetaEvent(LeConnectionUpdateCompleteBuilder::Create(
       ErrorCode::SUCCESS, handle_, connection_interval, connection_latency, supervision_timeout));
 }
@@ -897,7 +904,7 @@ TEST_F(AclManagerWithConnectionTest, send_switch_role) {
   ASSERT_EQ(command_view.GetBdAddr(), connection_->GetAddress());
   ASSERT_EQ(command_view.GetRole(), Role::PERIPHERAL);
 
-  EXPECT_CALL(mock_connection_management_callbacks_, OnRoleChange(Role::PERIPHERAL));
+  EXPECT_CALL(mock_connection_management_callbacks_, OnRoleChange(hci::ErrorCode::SUCCESS, Role::PERIPHERAL));
   test_hci_layer_->IncomingEvent(
       RoleChangeBuilder::Create(ErrorCode::SUCCESS, connection_->GetAddress(), Role::PERIPHERAL));
 }
index a9aaa9f..f867b00 100644 (file)
@@ -383,7 +383,7 @@ class AclManagerFacadeService : public AclManagerFacade::Service, public Connect
       LOG_INFO("key_flag:%s", KeyFlagText(key_flag).c_str());
     }
 
-    void OnRoleChange(Role new_role) override {
+    void OnRoleChange(hci::ErrorCode hci_status, Role new_role) override {
       LOG_INFO("new_role:%d", (uint8_t)new_role);
     }
 
@@ -395,7 +395,7 @@ class AclManagerFacadeService : public AclManagerFacade::Service, public Connect
       LOG_INFO("OnConnectionPacketTypeChanged packet_type:%d", packet_type);
     }
 
-    void OnAuthenticationComplete() override {
+    void OnAuthenticationComplete(hci::ErrorCode hci_status) override {
       LOG_INFO("OnAuthenticationComplete");
     }
 
@@ -416,6 +416,7 @@ class AclManagerFacadeService : public AclManagerFacade::Service, public Connect
     };
 
     void OnSniffSubrating(
+        hci::ErrorCode hci_status,
         uint16_t maximum_transmit_latency,
         uint16_t maximum_receive_latency,
         uint16_t minimum_remote_timeout,
@@ -511,7 +512,7 @@ class AclManagerFacadeService : public AclManagerFacade::Service, public Connect
       event_stream_->OnIncomingEvent(disconnection);
     }
     void OnReadRemoteVersionInformationComplete(
-        uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) override {
+        hci::ErrorCode error_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) override {
       LOG_INFO(
           "OnReadRemoteVersionInformationComplete lmp_version:%hhu manufacturer_name:%hu sub_version:%hu",
           lmp_version,
index 0a10e76..f1ae509 100644 (file)
@@ -267,7 +267,10 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, public LeC
         std::shared_ptr<::bluetooth::grpc::GrpcEventQueue<LeConnectionEvent>> event_stream)
         : handle_(handle), connection_(std::move(connection)), event_stream_(std::move(event_stream)) {}
     void OnConnectionUpdate(
-        uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout) override {
+        hci::ErrorCode hci_status,
+        uint16_t connection_interval,
+        uint16_t connection_latency,
+        uint16_t supervision_timeout) override {
       LOG_INFO(
           "interval: 0x%hx, latency: 0x%hx, timeout 0x%hx",
           connection_interval,
@@ -280,7 +283,7 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, public LeC
           "tx_octets: 0x%hx, tx_time: 0x%hx, rx_octets 0x%hx, rx_time 0x%hx", tx_octets, tx_time, rx_octets, rx_time);
     }
 
-    void OnPhyUpdate(uint8_t tx_phy, uint8_t rx_phy) override {}
+    void OnPhyUpdate(hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy) override {}
     void OnLocalAddressUpdate(AddressWithType address_with_type) override {}
     void OnDisconnection(ErrorCode reason) override {
       std::unique_ptr<BasePacketBuilder> builder =
@@ -291,7 +294,7 @@ class LeAclManagerFacadeService : public LeAclManagerFacade::Service, public LeC
     }
 
     void OnReadRemoteVersionInformationComplete(
-        uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) override {}
+        hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) override {}
 
     LeConnectionManagementCallbacks* GetCallbacks() {
       return this;
index 55acf9b..c54960d 100644 (file)
@@ -37,7 +37,8 @@ hci::LeSecurityInterface* FuzzHciLayer::GetLeSecurityInterface(
 hci::AclConnectionInterface* FuzzHciLayer::GetAclConnectionInterface(
     ContextualCallback<void(hci::EventView)> event_handler,
     ContextualCallback<void(uint16_t, hci::ErrorCode)> on_disconnect,
-    ContextualCallback<void(uint16_t, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version)>
+    ContextualCallback<
+        void(hci::ErrorCode, uint16_t, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version)>
         on_read_remote_version) {
   return &acl_connection_interface_;
 }
@@ -45,7 +46,8 @@ hci::AclConnectionInterface* FuzzHciLayer::GetAclConnectionInterface(
 hci::LeAclConnectionInterface* FuzzHciLayer::GetLeAclConnectionInterface(
     ContextualCallback<void(hci::LeMetaEventView)> event_handler,
     ContextualCallback<void(uint16_t, hci::ErrorCode)> on_disconnect,
-    ContextualCallback<void(uint16_t, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version)>
+    ContextualCallback<
+        void(hci::ErrorCode, uint16_t, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version)>
         on_read_remote_version) {
   return &le_acl_connection_interface_;
 }
index 0043182..2271edb 100644 (file)
@@ -102,12 +102,14 @@ class FuzzHciLayer : public HciLayer {
   hci::AclConnectionInterface* GetAclConnectionInterface(
       common::ContextualCallback<void(hci::EventView)> event_handler,
       common::ContextualCallback<void(uint16_t, hci::ErrorCode)> on_disconnect,
-      common::ContextualCallback<void(uint16_t, uint8_t, uint16_t, uint16_t)> on_read_remote_version) override;
+      common::ContextualCallback<void(hci::ErrorCode hci_status, uint16_t, uint8_t, uint16_t, uint16_t)>
+          on_read_remote_version) override;
 
   hci::LeAclConnectionInterface* GetLeAclConnectionInterface(
       common::ContextualCallback<void(hci::LeMetaEventView)> event_handler,
       common::ContextualCallback<void(uint16_t, hci::ErrorCode)> on_disconnect,
-      common::ContextualCallback<void(uint16_t, uint8_t, uint16_t, uint16_t)> on_read_remote_version) override;
+      common::ContextualCallback<void(hci::ErrorCode hci_status, uint16_t, uint8_t, uint16_t, uint16_t)>
+          on_read_remote_version) override;
 
   hci::LeAdvertisingInterface* GetLeAdvertisingInterface(
       common::ContextualCallback<void(hci::LeMetaEventView)> event_handler) override;
index bd23853..3a19df4 100644 (file)
@@ -37,11 +37,11 @@ void HciLayerFuzzClient::Start() {
   acl_connection_interface_ = hci_->GetAclConnectionInterface(
       GetHandler()->Bind([](EventView) {}),
       GetHandler()->Bind([](uint16_t, hci::ErrorCode) {}),
-      GetHandler()->Bind([](uint16_t, uint8_t, uint16_t, uint16_t) {}));
+      GetHandler()->Bind([](hci::ErrorCode, uint16_t, uint8_t, uint16_t, uint16_t) {}));
   le_acl_connection_interface_ = hci_->GetLeAclConnectionInterface(
       GetHandler()->Bind([](LeMetaEventView) {}),
       GetHandler()->Bind([](uint16_t, hci::ErrorCode) {}),
-      GetHandler()->Bind([](uint16_t, uint8_t, uint16_t, uint16_t) {}));
+      GetHandler()->Bind([](hci::ErrorCode, uint16_t, uint8_t, uint16_t, uint16_t) {}));
   le_advertising_interface_ = hci_->GetLeAdvertisingInterface(GetHandler()->Bind([](LeMetaEventView) {}));
   le_scanning_interface_ = hci_->GetLeScanningInterface(GetHandler()->Bind([](LeMetaEventView) {}));
 }
index c319d91..f806fe4 100644 (file)
@@ -335,26 +335,26 @@ void HciLayer::Disconnect(uint16_t handle, ErrorCode reason) {
 void HciLayer::on_read_remote_version_complete(EventView event_view) {
   auto view = ReadRemoteVersionInformationCompleteView::Create(event_view);
   ASSERT_LOG(view.IsValid(), "Read remote version information packet invalid");
-  if (view.GetStatus() != ErrorCode::SUCCESS) {
-    auto status = view.GetStatus();
-    std::string error_code = ErrorCodeText(status);
-    LOG_ERROR("Received with error code %s", error_code.c_str());
-    return;
-  }
-  uint16_t handle = view.GetConnectionHandle();
-  ReadRemoteVersion(handle, view.GetVersion(), view.GetManufacturerName(), view.GetSubVersion());
+  ReadRemoteVersion(
+      view.GetStatus(),
+      view.GetConnectionHandle(),
+      view.GetVersion(),
+      view.GetManufacturerName(),
+      view.GetSubVersion());
 }
 
-void HciLayer::ReadRemoteVersion(uint16_t handle, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version) {
+void HciLayer::ReadRemoteVersion(
+    hci::ErrorCode hci_status, uint16_t handle, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version) {
   for (auto callback : read_remote_version_handlers_) {
-    callback.Invoke(handle, version, manufacturer_name, sub_version);
+    callback.Invoke(hci_status, handle, version, manufacturer_name, sub_version);
   }
 }
 
 AclConnectionInterface* HciLayer::GetAclConnectionInterface(
     ContextualCallback<void(EventView)> event_handler,
     ContextualCallback<void(uint16_t, ErrorCode)> on_disconnect,
-    ContextualCallback<void(uint16_t, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version)>
+    ContextualCallback<
+        void(hci::ErrorCode hci_status, uint16_t, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version)>
         on_read_remote_version) {
   for (const auto event : AclConnectionEvents) {
     RegisterEventHandler(event, event_handler);
@@ -367,7 +367,8 @@ AclConnectionInterface* HciLayer::GetAclConnectionInterface(
 LeAclConnectionInterface* HciLayer::GetLeAclConnectionInterface(
     ContextualCallback<void(LeMetaEventView)> event_handler,
     ContextualCallback<void(uint16_t, ErrorCode)> on_disconnect,
-    ContextualCallback<void(uint16_t, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version)>
+    ContextualCallback<
+        void(hci::ErrorCode hci_status, uint16_t, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version)>
         on_read_remote_version) {
   for (const auto event : LeConnectionManagementEvents) {
     RegisterLeEventHandler(event, event_handler);
index 9c5013a..4b2b214 100644 (file)
@@ -72,12 +72,14 @@ class HciLayer : public Module, public CommandInterface<CommandBuilder> {
   virtual AclConnectionInterface* GetAclConnectionInterface(
       common::ContextualCallback<void(EventView)> event_handler,
       common::ContextualCallback<void(uint16_t, hci::ErrorCode)> on_disconnect,
-      common::ContextualCallback<void(uint16_t, uint8_t, uint16_t, uint16_t)> on_read_remote_version_complete);
+      common::ContextualCallback<void(hci::ErrorCode, uint16_t, uint8_t, uint16_t, uint16_t)>
+          on_read_remote_version_complete);
 
   virtual LeAclConnectionInterface* GetLeAclConnectionInterface(
       common::ContextualCallback<void(LeMetaEventView)> event_handler,
       common::ContextualCallback<void(uint16_t, hci::ErrorCode)> on_disconnect,
-      common::ContextualCallback<void(uint16_t, uint8_t, uint16_t, uint16_t)> on_read_remote_version_complete);
+      common::ContextualCallback<void(hci::ErrorCode, uint16_t, uint8_t, uint16_t, uint16_t)>
+          on_read_remote_version_complete);
 
   virtual LeAdvertisingInterface* GetLeAdvertisingInterface(
       common::ContextualCallback<void(LeMetaEventView)> event_handler);
@@ -103,7 +105,8 @@ class HciLayer : public Module, public CommandInterface<CommandBuilder> {
   void Stop() override;
 
   virtual void Disconnect(uint16_t handle, ErrorCode reason);
-  virtual void ReadRemoteVersion(uint16_t handle, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version);
+  virtual void ReadRemoteVersion(
+      hci::ErrorCode hci_status, uint16_t handle, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version);
   virtual void RegisterLeMetaEventHandler(common::ContextualCallback<void(EventView)> event_handler);
 
  private:
@@ -131,7 +134,8 @@ class HciLayer : public Module, public CommandInterface<CommandBuilder> {
   };
 
   std::list<common::ContextualCallback<void(uint16_t, ErrorCode)>> disconnect_handlers_;
-  std::list<common::ContextualCallback<void(uint16_t, uint8_t, uint16_t, uint16_t)>> read_remote_version_handlers_;
+  std::list<common::ContextualCallback<void(hci::ErrorCode, uint16_t, uint8_t, uint16_t, uint16_t)>>
+      read_remote_version_handlers_;
   void on_disconnection_complete(EventView event_view);
   void on_read_remote_version_complete(EventView event_view);
 
index 68f0790..57d8255 100644 (file)
@@ -141,7 +141,8 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service
     return ::grpc::Status::OK;
   }
 
-  void SecurityConnectionEventOccurred(hci::Address remote, LinkSecurityInterfaceCallbackEventType event_type) {
+  void SecurityConnectionEventOccurred(
+      hci::ErrorCode hci_status, hci::Address remote, LinkSecurityInterfaceCallbackEventType event_type) {
     LinkSecurityInterfaceCallbackEvent msg;
     msg.mutable_address()->set_address(remote.ToString());
     msg.set_event_type(event_type);
@@ -226,7 +227,8 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service
       outgoing_pairing_remote_devices_.erase(remote);
     }
     security_link_map_.emplace(remote, std::move(link));
-    SecurityConnectionEventOccurred(remote, LinkSecurityInterfaceCallbackEventType::ON_CONNECTED);
+    SecurityConnectionEventOccurred(
+        hci::ErrorCode::SUCCESS, remote, LinkSecurityInterfaceCallbackEventType::ON_CONNECTED);
   }
 
   void OnLinkDisconnected(hci::Address remote) override {
@@ -237,20 +239,23 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service
     }
     entry->second.reset();
     security_link_map_.erase(entry);
-    SecurityConnectionEventOccurred(remote, LinkSecurityInterfaceCallbackEventType::ON_DISCONNECTED);
+    SecurityConnectionEventOccurred(
+        hci::ErrorCode::SUCCESS, remote, LinkSecurityInterfaceCallbackEventType::ON_DISCONNECTED);
   }
 
-  void OnAuthenticationComplete(hci::Address remote) override {
+  void OnAuthenticationComplete(hci::ErrorCode hci_status, hci::Address remote) override {
     auto entry = security_link_map_.find(remote);
     if (entry != security_link_map_.end()) {
       entry->second->EnsureEncrypted();
       return;
     }
-    SecurityConnectionEventOccurred(remote, LinkSecurityInterfaceCallbackEventType::ON_AUTHENTICATION_COMPLETE);
+    SecurityConnectionEventOccurred(
+        hci_status, remote, LinkSecurityInterfaceCallbackEventType::ON_AUTHENTICATION_COMPLETE);
   }
 
   void OnEncryptionChange(hci::Address remote, bool encrypted) override {
-    SecurityConnectionEventOccurred(remote, LinkSecurityInterfaceCallbackEventType::ON_ENCRYPTION_CHANGE);
+    SecurityConnectionEventOccurred(
+        hci::ErrorCode::SUCCESS, remote, LinkSecurityInterfaceCallbackEventType::ON_ENCRYPTION_CHANGE);
   }
 
   class L2capDynamicChannelHelper {
index ea2619a..be84dac 100644 (file)
@@ -316,8 +316,8 @@ void Link::OnConnectionPacketTypeChanged(uint16_t packet_type) {
   LOG_INFO("UNIMPLEMENTED %s packet_type:%x", __func__, packet_type);
 }
 
-void Link::OnAuthenticationComplete() {
-  link_manager_->OnAuthenticationComplete(GetDevice().GetAddress());
+void Link::OnAuthenticationComplete(hci::ErrorCode hci_status) {
+  link_manager_->OnAuthenticationComplete(hci_status, GetDevice().GetAddress());
 }
 
 void Link::OnEncryptionChange(hci::EncryptionEnabled enabled) {
@@ -341,15 +341,17 @@ void Link::OnReadClockOffsetComplete(uint16_t clock_offset) {
 }
 
 void Link::OnModeChange(hci::ErrorCode status, hci::Mode current_mode, uint16_t interval) {
-  link_manager_->OnModeChange(GetDevice().GetAddress(), current_mode, interval);
+  link_manager_->OnModeChange(status, GetDevice().GetAddress(), current_mode, interval);
 }
 
 void Link::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) {
   link_manager_->OnSniffSubrating(
+      hci_status,
       GetDevice().GetAddress(),
       maximum_transmit_latency,
       maximum_receive_latency,
@@ -418,22 +420,24 @@ void Link::OnReadClockComplete(uint32_t clock, uint16_t accuracy) {
 void Link::OnCentralLinkKeyComplete(hci::KeyFlag key_flag) {
   LOG_INFO("UNIMPLEMENTED key_flag:%s", hci::KeyFlagText(key_flag).c_str());
 }
-void Link::OnRoleChange(hci::Role new_role) {
+void Link::OnRoleChange(hci::ErrorCode hci_status, hci::Role new_role) {
   role_ = new_role;
-  link_manager_->OnRoleChange(GetDevice().GetAddress(), new_role);
+  link_manager_->OnRoleChange(hci_status, GetDevice().GetAddress(), new_role);
 }
 void Link::OnDisconnection(hci::ErrorCode reason) {
   OnAclDisconnected(reason);
   link_manager_->OnDisconnect(GetDevice().GetAddress(), reason);
 }
 void Link::OnReadRemoteVersionInformationComplete(
-    uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {
+    hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {
   LOG_INFO(
-      "UNIMPLEMENTED lmp_version:%hhu manufacturer_name:%hu sub_version:%hu",
+      "UNIMPLEMENTED hci_status:%s lmp_version:%hhu manufacturer_name:%hu sub_version:%hu",
+      ErrorCodeText(hci_status).c_str(),
       lmp_version,
       manufacturer_name,
       sub_version);
-  link_manager_->OnReadRemoteVersionInformation(GetDevice().GetAddress(), lmp_version, manufacturer_name, sub_version);
+  link_manager_->OnReadRemoteVersionInformation(
+      hci_status, GetDevice().GetAddress(), lmp_version, manufacturer_name, sub_version);
 }
 void Link::OnReadRemoteExtendedFeaturesComplete(uint8_t page_number, uint8_t max_page_number, uint64_t features) {
   LOG_INFO(
index af69bb0..4696741 100644 (file)
@@ -151,12 +151,13 @@ class Link : public l2cap::internal::ILink, public hci::acl_manager::ConnectionM
 
   // ConnectionManagementCallbacks
   void OnConnectionPacketTypeChanged(uint16_t packet_type) override;
-  void OnAuthenticationComplete() override;
+  void OnAuthenticationComplete(hci::ErrorCode hci_status) override;
   void OnEncryptionChange(hci::EncryptionEnabled enabled) override;
   void OnChangeConnectionLinkKeyComplete() override;
   void OnReadClockOffsetComplete(uint16_t clock_offset) override;
   void OnModeChange(hci::ErrorCode status, hci::Mode current_mode, uint16_t interval) override;
   void OnSniffSubrating(
+      hci::ErrorCode hci_status,
       uint16_t maximum_transmit_latency,
       uint16_t maximum_receive_latency,
       uint16_t minimum_remote_timeout,
@@ -178,9 +179,10 @@ class Link : public l2cap::internal::ILink, public hci::acl_manager::ConnectionM
   void OnReadRssiComplete(uint8_t rssi) override;
   void OnReadClockComplete(uint32_t clock, uint16_t accuracy) override;
   void OnCentralLinkKeyComplete(hci::KeyFlag key_flag) override;
-  void OnRoleChange(hci::Role new_role) override;
+  void OnRoleChange(hci::ErrorCode hci_status, hci::Role new_role) override;
   void OnDisconnection(hci::ErrorCode reason) override;
-  void OnReadRemoteVersionInformationComplete(uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version);
+  void OnReadRemoteVersionInformationComplete(
+      hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version);
   void OnReadRemoteExtendedFeaturesComplete(uint8_t page_number, uint8_t max_page_number, uint64_t features);
 
   struct EncryptionChangeListener {
index e0dce38..22dee47 100644 (file)
@@ -317,10 +317,13 @@ void LinkManager::OnDisconnect(hci::Address device, hci::ErrorCode status) {
   links_.erase(device);
 }
 
-void LinkManager::OnAuthenticationComplete(hci::Address device) {
+void LinkManager::OnAuthenticationComplete(hci::ErrorCode hci_status, hci::Address device) {
   if (link_security_interface_listener_handler_ != nullptr) {
     link_security_interface_listener_handler_->CallOn(
-        link_security_interface_listener_, &LinkSecurityInterfaceListener::OnAuthenticationComplete, device);
+        link_security_interface_listener_,
+        &LinkSecurityInterfaceListener::OnAuthenticationComplete,
+        hci_status,
+        device);
   }
 }
 
@@ -335,11 +338,16 @@ void LinkManager::OnEncryptionChange(hci::Address device, hci::EncryptionEnabled
 }
 
 void LinkManager::OnReadRemoteVersionInformation(
-    hci::Address device, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {
+    hci::ErrorCode hci_status,
+    hci::Address device,
+    uint8_t lmp_version,
+    uint16_t manufacturer_name,
+    uint16_t sub_version) {
   if (link_property_callback_handler_ != nullptr) {
     link_property_callback_handler_->CallOn(
         link_property_listener_,
         &LinkPropertyListener::OnReadRemoteVersionInformation,
+        hci_status,
         device,
         lmp_version,
         manufacturer_name,
@@ -360,9 +368,10 @@ void LinkManager::OnReadRemoteExtendedFeatures(
   }
 }
 
-void LinkManager::OnRoleChange(hci::Address remote, hci::Role role) {
+void LinkManager::OnRoleChange(hci::ErrorCode hci_status, hci::Address remote, hci::Role role) {
   if (link_property_callback_handler_ != nullptr) {
-    link_property_callback_handler_->CallOn(link_property_listener_, &LinkPropertyListener::OnRoleChange, remote, role);
+    link_property_callback_handler_->CallOn(
+        link_property_listener_, &LinkPropertyListener::OnRoleChange, hci_status, remote, role);
   }
 }
 
@@ -373,14 +382,15 @@ void LinkManager::OnReadClockOffset(hci::Address remote, uint16_t clock_offset)
   }
 }
 
-void LinkManager::OnModeChange(hci::Address remote, hci::Mode mode, uint16_t interval) {
+void LinkManager::OnModeChange(hci::ErrorCode hci_status, hci::Address remote, hci::Mode mode, uint16_t interval) {
   if (link_property_callback_handler_ != nullptr) {
     link_property_callback_handler_->CallOn(
-        link_property_listener_, &LinkPropertyListener::OnModeChange, remote, mode, interval);
+        link_property_listener_, &LinkPropertyListener::OnModeChange, hci_status, remote, mode, interval);
   }
 }
 
 void LinkManager::OnSniffSubrating(
+    hci::ErrorCode hci_status,
     hci::Address remote,
     uint16_t max_tx_lat,
     uint16_t max_rx_lat,
@@ -390,6 +400,7 @@ void LinkManager::OnSniffSubrating(
     link_property_callback_handler_->CallOn(
         link_property_listener_,
         &LinkPropertyListener::OnSniffSubrating,
+        hci_status,
         remote,
         max_tx_lat,
         max_rx_lat,
index 0c91a4d..95bb0de 100644 (file)
@@ -66,16 +66,21 @@ class LinkManager : public hci::acl_manager::ConnectionCallbacks {
   void OnConnectSuccess(std::unique_ptr<hci::acl_manager::ClassicAclConnection> acl_connection) override;
   void OnConnectFail(hci::Address device, hci::ErrorCode reason) override;
   virtual void OnDisconnect(hci::Address device, hci::ErrorCode status);
-  void OnAuthenticationComplete(hci::Address device);
+  void OnAuthenticationComplete(hci::ErrorCode hci_status, hci::Address device);
   void OnEncryptionChange(hci::Address device, hci::EncryptionEnabled enabled);
   void OnReadRemoteVersionInformation(
-      hci::Address device, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version);
+      hci::ErrorCode hci_status,
+      hci::Address device,
+      uint8_t lmp_version,
+      uint16_t manufacturer_name,
+      uint16_t sub_version);
   void OnReadRemoteExtendedFeatures(
       hci::Address device, uint8_t page_number, uint8_t max_page_number, uint64_t features);
-  void OnRoleChange(hci::Address remote, hci::Role role);
+  void OnRoleChange(hci::ErrorCode hci_status, hci::Address remote, hci::Role role);
   void OnReadClockOffset(hci::Address remote, uint16_t clock_offset);
-  void OnModeChange(hci::Address remote, hci::Mode mode, uint16_t interval);
+  void OnModeChange(hci::ErrorCode hci_status, hci::Address remote, hci::Mode mode, uint16_t interval);
   void OnSniffSubrating(
+      hci::ErrorCode hci_status,
       hci::Address remote,
       uint16_t max_tx_lat,
       uint16_t max_rx_lat,
index ddf1e85..afff663 100644 (file)
@@ -46,7 +46,11 @@ class LinkPropertyListener {
    * Invoked when received remote version information for a given link
    */
   virtual void OnReadRemoteVersionInformation(
-      hci::Address remote, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {}
+      hci::ErrorCode hci_status,
+      hci::Address remote,
+      uint8_t lmp_version,
+      uint16_t manufacturer_name,
+      uint16_t sub_version) {}
 
   /**
    * Invoked when received remote features and remote extended features for a given link
@@ -57,7 +61,7 @@ class LinkPropertyListener {
   /**
    * Invoked when received role change
    */
-  virtual void OnRoleChange(hci::Address remote, hci::Role role) {}
+  virtual void OnRoleChange(hci::ErrorCode hci_status, hci::Address remote, hci::Role role) {}
 
   /**
    * Invoked when received clock offset
@@ -67,12 +71,13 @@ class LinkPropertyListener {
   /**
    * Invoked when received mode change
    */
-  virtual void OnModeChange(hci::Address remote, hci::Mode mode, uint16_t interval) {}
+  virtual void OnModeChange(hci::ErrorCode hci_status, hci::Address remote, hci::Mode mode, uint16_t interval) {}
 
   /**
    * Invoked when received sniff subrating
    */
   virtual void OnSniffSubrating(
+      hci::ErrorCode hci_status,
       hci::Address remote,
       uint16_t max_tx_lat,
       uint16_t max_rx_lat,
index 314c91c..90fac62 100644 (file)
@@ -107,7 +107,7 @@ class LinkSecurityInterfaceListener {
   /**
    * Invoked when AuthenticationComplete event is received for a given link
    */
-  virtual void OnAuthenticationComplete(hci::Address remote) {}
+  virtual void OnAuthenticationComplete(hci::ErrorCode hci_status, hci::Address remote) {}
 
   /**
    * Invoked when EncryptionChange event is received for a given link
index 63844b6..0cb0c7d 100644 (file)
@@ -64,7 +64,11 @@ void Link::OnDisconnection(hci::ErrorCode status) {
   link_manager_->OnDisconnect(GetAclConnection()->GetRemoteAddress());
 }
 
-void Link::OnConnectionUpdate(uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout) {
+void Link::OnConnectionUpdate(
+    hci::ErrorCode hci_status,
+    uint16_t connection_interval,
+    uint16_t connection_latency,
+    uint16_t supervision_timeout) {
   LOG_INFO(
       "interval %hx latency %hx supervision_timeout %hx", connection_interval, connection_latency, supervision_timeout);
   if (update_request_signal_id_ != kInvalidSignalId) {
@@ -88,12 +92,13 @@ void Link::OnDataLengthChange(uint16_t tx_octets, uint16_t tx_time, uint16_t rx_
 }
 
 void Link::OnReadRemoteVersionInformationComplete(
-    uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {
+    hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {
   LOG_INFO("lmp_version:%hhu manufacturer_name:%hu sub_version:%hu", lmp_version, manufacturer_name, sub_version);
-  link_manager_->OnReadRemoteVersionInformationComplete(GetDevice(), lmp_version, manufacturer_name, sub_version);
+  link_manager_->OnReadRemoteVersionInformationComplete(
+      hci_status, GetDevice(), lmp_version, manufacturer_name, sub_version);
 }
 
-void Link::OnPhyUpdate(uint8_t tx_phy, uint8_t rx_phy) {}
+void Link::OnPhyUpdate(hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy) {}
 
 void Link::OnLocalAddressUpdate(hci::AddressWithType address_with_type) {
   acl_connection_->UpdateLocalAddress(address_with_type);
index 5c531f7..46140e6 100644 (file)
@@ -75,14 +75,17 @@ class Link : public l2cap::internal::ILink, public hci::acl_manager::LeConnectio
 
   void OnDisconnection(hci::ErrorCode reason) override;
 
-  void OnConnectionUpdate(uint16_t connection_interval, uint16_t connection_latency,
-                          uint16_t supervision_timeout) override;
+  void OnConnectionUpdate(
+      hci::ErrorCode hci_status,
+      uint16_t connection_interval,
+      uint16_t connection_latency,
+      uint16_t supervision_timeout) override;
 
   void OnDataLengthChange(uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time) override;
 
   void OnReadRemoteVersionInformationComplete(
-      uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) override;
-  void OnPhyUpdate(uint8_t tx_phy, uint8_t rx_phy) override;
+      hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) override;
+  void OnPhyUpdate(hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy) override;
 
   void OnLocalAddressUpdate(hci::AddressWithType address_with_type) override;
 
index bd4023c..e1964b4 100644 (file)
@@ -163,11 +163,16 @@ void LinkManager::RegisterLinkPropertyListener(os::Handler* handler, LinkPropert
 }
 
 void LinkManager::OnReadRemoteVersionInformationComplete(
-    hci::AddressWithType address_with_type, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {
+    hci::ErrorCode hci_status,
+    hci::AddressWithType address_with_type,
+    uint8_t lmp_version,
+    uint16_t manufacturer_name,
+    uint16_t sub_version) {
   if (link_property_callback_handler_ != nullptr) {
     link_property_callback_handler_->CallOn(
         link_property_listener_,
         &LinkPropertyListener::OnReadRemoteVersionInformation,
+        hci_status,
         address_with_type,
         lmp_version,
         manufacturer_name,
index ede43f1..da70354 100644 (file)
@@ -88,7 +88,11 @@ class LinkManager : public hci::acl_manager::LeConnectionCallbacks {
   void RegisterLinkPropertyListener(os::Handler* handler, LinkPropertyListener* listener);
 
   void OnReadRemoteVersionInformationComplete(
-      hci::AddressWithType address_with_type, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version);
+      hci::ErrorCode hci_status,
+      hci::AddressWithType address_with_type,
+      uint8_t lmp_version,
+      uint16_t manufacturer_name,
+      uint16_t sub_version);
 
  private:
   // Dependencies
index e45b96c..9af175b 100644 (file)
@@ -46,7 +46,11 @@ class LinkPropertyListener {
    * Invoked when received remote version information for a given link
    */
   virtual void OnReadRemoteVersionInformation(
-      hci::AddressWithType remote, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version) {}
+      hci::ErrorCode hci_status,
+      hci::AddressWithType remote,
+      uint8_t lmp_version,
+      uint16_t manufacturer_name,
+      uint16_t sub_version) {}
 
   /**
    * Invoked when received connection update for a given link
index 696956e..8c90a36 100644 (file)
@@ -114,7 +114,7 @@ void SecurityManagerChannel::OnLinkDisconnected(hci::Address address) {
   listener_->OnConnectionClosed(address);
 }
 
-void SecurityManagerChannel::OnAuthenticationComplete(hci::Address remote) {
+void SecurityManagerChannel::OnAuthenticationComplete(hci::ErrorCode hci_status, hci::Address remote) {
   ASSERT_LOG(l2cap_security_interface_ != nullptr, "L2cap Security Interface is null!");
   auto entry = link_map_.find(remote);
   if (entry != link_map_.end()) {
index a0a15b1..9e23604 100644 (file)
@@ -124,7 +124,7 @@ class SecurityManagerChannel : public l2cap::classic::LinkSecurityInterfaceListe
   // Interface overrides
   void OnLinkConnected(std::unique_ptr<l2cap::classic::LinkSecurityInterface> link) override;
   void OnLinkDisconnected(hci::Address address) override;
-  void OnAuthenticationComplete(hci::Address remote) override;
+  void OnAuthenticationComplete(hci::ErrorCode hci_status, hci::Address remote) override;
   void OnEncryptionChange(hci::Address, bool encrypted) override;
 
  private:
index d52625c..22b16d8 100644 (file)
@@ -60,7 +60,7 @@ class FakeSecurityManagerChannel : public SecurityManagerChannel {
     on_link_disconnected_called = true;
   }
 
-  void OnAuthenticationComplete(hci::Address remote) override {}
+  void OnAuthenticationComplete(hci::ErrorCode hci_status, hci::Address remote) override {}
 
   void OnEncryptionChange(hci::Address address, bool encrypted) override {}
 };
index 4385cff..dde08cc 100644 (file)
@@ -65,7 +65,7 @@ class FakeSecurityManagerChannel : public channel::SecurityManagerChannel {
     LOG_ERROR("CALLED");
   }
 
-  void OnAuthenticationComplete(hci::Address remote) override {
+  void OnAuthenticationComplete(hci::ErrorCode hci_status, hci::Address remote) override {
     LOG_ERROR("CALLED");
   }
 };
index c77786a..39fb030 100644 (file)
@@ -326,9 +326,9 @@ class ClassicShimAclConnection
     TRY_POSTING_ON_MAIN(interface_.on_packet_type_changed, packet_type);
   }
 
-  void OnAuthenticationComplete() override {
+  void OnAuthenticationComplete(hci::ErrorCode hci_status) override {
     TRY_POSTING_ON_MAIN(interface_.on_authentication_complete, handle_,
-                        ToLegacyHciErrorCode(hci::ErrorCode::SUCCESS));
+                        ToLegacyHciErrorCode(hci_status));
   }
 
   void OnEncryptionChange(hci::EncryptionEnabled enabled) override {
@@ -351,12 +351,13 @@ class ClassicShimAclConnection
                         handle_, ToLegacyHciMode(current_mode), interval);
   }
 
-  void OnSniffSubrating(uint16_t maximum_transmit_latency,
+  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) {
     TRY_POSTING_ON_MAIN(interface_.on_sniff_subrating,
-                        ToLegacyHciErrorCode(hci::ErrorCode::SUCCESS), handle_,
+                        ToLegacyHciErrorCode(hci_status), handle_,
                         maximum_transmit_latency, maximum_receive_latency,
                         minimum_remote_timeout, minimum_local_timeout);
   }
@@ -424,14 +425,14 @@ class ClassicShimAclConnection
     LOG_INFO("%s UNIMPLEMENTED", __func__);
   }
 
-  void OnRoleChange(hci::Role new_role) override {
-    TRY_POSTING_ON_MAIN(interface_.on_role_change,
-                        ToLegacyHciErrorCode(hci::ErrorCode::SUCCESS),
-                        ToRawAddress(connection_->GetAddress()),
-                        ToLegacyRole(new_role));
+  void OnRoleChange(hci::ErrorCode hci_status, hci::Role new_role) override {
+    TRY_POSTING_ON_MAIN(
+        interface_.on_role_change, ToLegacyHciErrorCode(hci_status),
+        ToRawAddress(connection_->GetAddress()), ToLegacyRole(new_role));
     BTM_LogHistory(kBtmLogTag, ToRawAddress(connection_->GetAddress()),
                    "Role change",
-                   base::StringPrintf("classic new_role:%s",
+                   base::StringPrintf("classic  status:%s new_role:%s",
+                                      hci::ErrorCodeText(hci_status).c_str(),
                                       hci::RoleText(new_role).c_str()));
   }
 
@@ -440,12 +441,13 @@ class ClassicShimAclConnection
     on_disconnect_(handle_, reason);
   }
 
-  void OnReadRemoteVersionInformationComplete(uint8_t lmp_version,
+  void OnReadRemoteVersionInformationComplete(hci::ErrorCode hci_status,
+                                              uint8_t lmp_version,
                                               uint16_t manufacturer_name,
                                               uint16_t sub_version) override {
     TRY_POSTING_ON_MAIN(interface_.on_read_remote_version_information_complete,
-                        ToLegacyHciErrorCode(hci::ErrorCode::SUCCESS), handle_,
-                        lmp_version, manufacturer_name, sub_version);
+                        ToLegacyHciErrorCode(hci_status), handle_, lmp_version,
+                        manufacturer_name, sub_version);
   }
 
   void OnReadRemoteExtendedFeaturesComplete(uint8_t page_number,
@@ -519,13 +521,13 @@ class LeShimAclConnection
     // TODO Issue LeReadRemoteFeatures Command
   }
 
-  void OnConnectionUpdate(uint16_t connection_interval,
+  void OnConnectionUpdate(hci::ErrorCode hci_status,
+                          uint16_t connection_interval,
                           uint16_t connection_latency,
                           uint16_t supervision_timeout) {
-    TRY_POSTING_ON_MAIN(interface_.on_connection_update,
-                        ToLegacyHciErrorCode(hci::ErrorCode::SUCCESS), handle_,
-                        connection_interval, connection_latency,
-                        supervision_timeout);
+    TRY_POSTING_ON_MAIN(
+        interface_.on_connection_update, ToLegacyHciErrorCode(hci_status),
+        handle_, connection_interval, connection_latency, supervision_timeout);
   }
   void OnDataLengthChange(uint16_t tx_octets, uint16_t tx_time,
                           uint16_t rx_octets, uint16_t rx_time) {
@@ -533,18 +535,20 @@ class LeShimAclConnection
                         rx_octets, rx_time);
   }
 
-  void OnReadRemoteVersionInformationComplete(uint8_t lmp_version,
+  void OnReadRemoteVersionInformationComplete(hci::ErrorCode hci_status,
+                                              uint8_t lmp_version,
                                               uint16_t manufacturer_name,
                                               uint16_t sub_version) override {
     TRY_POSTING_ON_MAIN(interface_.on_read_remote_version_information_complete,
-                        ToLegacyHciErrorCode(hci::ErrorCode::SUCCESS), handle_,
-                        lmp_version, manufacturer_name, sub_version);
+                        ToLegacyHciErrorCode(hci_status), handle_, lmp_version,
+                        manufacturer_name, sub_version);
   }
 
-  void OnPhyUpdate(uint8_t tx_phy, uint8_t rx_phy) override {
+  void OnPhyUpdate(hci::ErrorCode hci_status, uint8_t tx_phy,
+                   uint8_t rx_phy) override {
     TRY_POSTING_ON_MAIN(interface_.on_phy_update,
-                        ToLegacyHciErrorCode(hci::ErrorCode::SUCCESS), handle_,
-                        tx_phy, rx_phy);
+                        ToLegacyHciErrorCode(hci_status), handle_, tx_phy,
+                        rx_phy);
   }
 
   void OnLocalAddressUpdate(hci::AddressWithType address_with_type) override {}
index c0befca..6c28cd1 100644 (file)
@@ -375,7 +375,8 @@ struct LinkPropertyListenerShim
     address_to_handle_.erase(remote);
   }
 
-  void OnReadRemoteVersionInformation(hci::Address remote, uint8_t lmp_version,
+  void OnReadRemoteVersionInformation(hci::ErrorCode error_code,
+                                      hci::Address remote, uint8_t lmp_version,
                                       uint16_t manufacturer_name,
                                       uint16_t sub_version) override {
     auto bda = bluetooth::ToRawAddress(remote);
@@ -406,28 +407,33 @@ struct LinkPropertyListenerShim
     }
   }
 
-  void OnRoleChange(hci::Address remote, hci::Role role) override {
-    btm_rejectlist_role_change_device(ToRawAddress(remote), HCI_SUCCESS);
-    btm_acl_role_changed(HCI_SUCCESS, ToRawAddress(remote),
-                         static_cast<uint8_t>(role));
+  void OnRoleChange(hci::ErrorCode error_code, hci::Address remote,
+                    hci::Role role) override {
+    btm_rejectlist_role_change_device(ToRawAddress(remote),
+                                      ToLegacyHciErrorCode(error_code));
+    btm_acl_role_changed(ToLegacyHciErrorCode(error_code), ToRawAddress(remote),
+                         ToLegacyRole(role));
   }
 
   void OnReadClockOffset(hci::Address remote, uint16_t clock_offset) override {
     btm_sec_update_clock_offset(address_to_handle_[remote], clock_offset);
   }
 
-  void OnModeChange(hci::Address remote, hci::Mode mode,
-                    uint16_t interval) override {
-    btm_sco_chk_pend_unpark(HCI_SUCCESS, address_to_handle_[remote]);
-    btm_pm_proc_mode_change(HCI_SUCCESS, address_to_handle_[remote],
-                            static_cast<tHCI_MODE>(mode), interval);
+  void OnModeChange(hci::ErrorCode error_code, hci::Address remote,
+                    hci::Mode mode, uint16_t interval) override {
+    btm_sco_chk_pend_unpark(ToLegacyHciErrorCode(error_code),
+                            address_to_handle_[remote]);
+    btm_pm_proc_mode_change(ToLegacyHciErrorCode(error_code),
+                            address_to_handle_[remote], ToLegacyHciMode(mode),
+                            interval);
   }
 
-  void OnSniffSubrating(hci::Address remote, uint16_t max_tx_lat,
-                        uint16_t max_rx_lat, uint16_t min_remote_timeout,
+  void OnSniffSubrating(hci::ErrorCode error_code, hci::Address remote,
+                        uint16_t max_tx_lat, uint16_t max_rx_lat,
+                        uint16_t min_remote_timeout,
                         uint16_t min_local_timeout) override {
-    process_ssr_event(HCI_SUCCESS, address_to_handle_[remote], max_tx_lat,
-                      max_rx_lat);
+    process_ssr_event(ToLegacyHciErrorCode(error_code),
+                      address_to_handle_[remote], max_tx_lat, max_rx_lat);
   }
 
 } link_property_listener_shim_;
@@ -448,11 +454,12 @@ class SecurityListenerShim
     address_to_interface_[bda] = std::move(interface);
   }
 
-  void OnAuthenticationComplete(bluetooth::hci::Address remote) override {
+  void OnAuthenticationComplete(hci::ErrorCode hci_status,
+                                bluetooth::hci::Address remote) override {
     // Note: if gd security is not enabled, we should use btu_hcif.cc path
     auto bda = bluetooth::ToRawAddress(remote);
     uint16_t handle = address_to_handle_[bda];
-    btm_sec_auth_complete(handle, HCI_SUCCESS);
+    btm_sec_auth_complete(handle, ToLegacyHciErrorCode(hci_status));
   }
 
   void OnLinkDisconnected(bluetooth::hci::Address remote) override {
@@ -536,7 +543,8 @@ struct LeLinkPropertyListenerShim
     info_.erase(remote.GetAddress());
   }
 
-  void OnReadRemoteVersionInformation(hci::AddressWithType remote,
+  void OnReadRemoteVersionInformation(hci::ErrorCode hci_status,
+                                      hci::AddressWithType remote,
                                       uint8_t lmp_version,
                                       uint16_t manufacturer_name,
                                       uint16_t sub_version) override {