OSDN Git Service

Use tHCI_STATUS throughout shim interface
authorChris Manton <cmanton@google.com>
Wed, 14 Oct 2020 15:32:33 +0000 (08:32 -0700)
committerChris Manton <cmanton@google.com>
Mon, 19 Oct 2020 16:47:38 +0000 (16:47 +0000)
Bug: 166280067
Tag: #refactor
Test: act.py -tc BleCocTest
Test: ble paired 2 phones
Test: classic paired Bose SoundLink

Change-Id: Ia6b600dbe0a8dbf99b1e97d6776a5dfe7f48248f

12 files changed:
main/shim/acl.cc
main/shim/acl_legacy_interface.h
main/shim/helpers.h
stack/acl/ble_acl.cc
stack/acl/btm_acl.cc
stack/acl/btm_ble_connection_establishment.cc
stack/btm/btm_sec.cc
stack/btm/btm_sec.h
stack/btu/btu_hcif.cc
stack/include/acl_hci_link_interface.h
stack/include/ble_acl_interface.h
stack/include/sec_hci_link_interface.h

index 4732676..c8d3e40 100644 (file)
@@ -180,7 +180,7 @@ class ClassicShimAclConnection
 
   void OnDisconnection(hci::ErrorCode reason) override {
     btm_sec_disconnected(connection_->GetHandle(),
-                         static_cast<uint8_t>(reason));
+                         static_cast<tHCI_STATUS>(reason));
   }
 
   void OnReadRemoteVersionInformationComplete(uint8_t lmp_version,
@@ -351,7 +351,7 @@ void bluetooth::shim::legacy::Acl::OnLeConnectFail(
 
   uint16_t handle{0};  /* TODO Unneeded */
   bool enhanced{true}; /* TODO logging metrics only */
-  uint8_t status = ToLegacyHciErrorCode(reason);
+  tHCI_STATUS status = ToLegacyHciErrorCode(reason);
 
   acl_ble_connection_fail(legacy_address_with_type, handle, enhanced, status);
 }
index f288e08..bb3eda7 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <cstdint>
 #include "stack/include/bt_types.h"
+#include "stack/include/hci_error_code.h"
 #include "types/raw_address.h"
 
 namespace bluetooth {
@@ -25,11 +26,11 @@ namespace shim {
 namespace legacy {
 
 typedef struct {
-  void (*on_connected)(const RawAddress& bda, uint16_t handle, uint8_t status,
-                       uint8_t enc_mode);
-  void (*on_failed)(const RawAddress& bda, uint16_t handle, uint8_t status,
+  void (*on_connected)(const RawAddress& bda, uint16_t handle,
+                       tHCI_STATUS status, uint8_t enc_mode);
+  void (*on_failed)(const RawAddress& bda, uint16_t handle, tHCI_STATUS status,
                     uint8_t enc_mode);
-  void (*on_disconnected)(uint16_t handle, uint8_t reason);
+  void (*on_disconnected)(uint16_t handle, tHCI_STATUS reason);
 } acl_classic_connection_interface_t;
 
 typedef struct {
@@ -39,8 +40,8 @@ typedef struct {
                        const RawAddress& local_rpa, const RawAddress& peer_rpa,
                        uint8_t peer_addr_type);
   void (*on_failed)(const tBLE_BD_ADDR& address_with_type, uint16_t handle,
-                    bool enhanced, uint8_t status);
-  void (*on_disconnected)(uint16_t handle, uint8_t reason);
+                    bool enhanced, tHCI_STATUS status);
+  void (*on_disconnected)(uint16_t handle, tHCI_STATUS reason);
 } acl_le_connection_interface_t;
 
 typedef struct {
@@ -77,7 +78,6 @@ typedef struct {
   void (*on_role_change)(uint8_t new_role);
   void (*on_role_discovery_complete)(uint8_t current_role);
 } acl_classic_link_interface_t;
-;
 
 typedef struct {
   void (*on_connection_update)(uint16_t connection_interval,
index 0f18073..e7601eb 100644 (file)
@@ -101,7 +101,7 @@ inline std::unique_ptr<bluetooth::packet::RawBuilder> MakeUniquePacket(
   return payload;
 }
 
-inline uint8_t ToLegacyHciErrorCode(hci::ErrorCode reason) {
+inline tHCI_STATUS ToLegacyHciErrorCode(hci::ErrorCode reason) {
   switch (reason) {
     case hci::ErrorCode::SUCCESS:
       return HCI_SUCCESS;
@@ -138,17 +138,17 @@ inline uint8_t ToLegacyHciErrorCode(hci::ErrorCode reason) {
     case hci::ErrorCode::CONNECTION_ACCEPT_TIMEOUT:
       return HCI_ERR_HOST_TIMEOUT;
     case hci::ErrorCode::UNSUPORTED_FEATURE_OR_PARAMETER_VALUE:
-      return static_cast<uint8_t>(
+      return static_cast<tHCI_STATUS>(
           hci::ErrorCode::UNSUPORTED_FEATURE_OR_PARAMETER_VALUE);
     case hci::ErrorCode::INVALID_HCI_COMMAND_PARAMETERS:
       return HCI_ERR_ILLEGAL_PARAMETER_FMT;
     case hci::ErrorCode::REMOTE_USER_TERMINATED_CONNECTION:
       return HCI_ERR_PEER_USER;
     case hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_LOW_RESOURCES:
-      return static_cast<uint8_t>(
+      return static_cast<tHCI_STATUS>(
           hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_LOW_RESOURCES);
     case hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_POWER_OFF:
-      return static_cast<uint8_t>(
+      return static_cast<tHCI_STATUS>(
           hci::ErrorCode::REMOTE_DEVICE_TERMINATED_CONNECTION_POWER_OFF);
     case hci::ErrorCode::CONNECTION_TERMINATED_BY_LOCAL_HOST:
       return HCI_ERR_CONN_CAUSE_LOCAL_HOST;
@@ -157,30 +157,31 @@ inline uint8_t ToLegacyHciErrorCode(hci::ErrorCode reason) {
     case hci::ErrorCode::PAIRING_NOT_ALLOWED:
       return HCI_ERR_PAIRING_NOT_ALLOWED;
     case hci::ErrorCode::UNKNOWN_LMP_PDU:
-      return static_cast<uint8_t>(hci::ErrorCode::UNKNOWN_LMP_PDU);
+      return static_cast<tHCI_STATUS>(hci::ErrorCode::UNKNOWN_LMP_PDU);
     case hci::ErrorCode::UNSUPPORTED_REMOTE_OR_LMP_FEATURE:
       return HCI_ERR_UNSUPPORTED_REM_FEATURE;
     case hci::ErrorCode::SCO_OFFSET_REJECTED:
-      return static_cast<uint8_t>(hci::ErrorCode::SCO_OFFSET_REJECTED);
+      return static_cast<tHCI_STATUS>(hci::ErrorCode::SCO_OFFSET_REJECTED);
     case hci::ErrorCode::SCO_INTERVAL_REJECTED:
-      return static_cast<uint8_t>(hci::ErrorCode::SCO_INTERVAL_REJECTED);
+      return static_cast<tHCI_STATUS>(hci::ErrorCode::SCO_INTERVAL_REJECTED);
     case hci::ErrorCode::SCO_AIR_MODE_REJECTED:
-      return static_cast<uint8_t>(hci::ErrorCode::SCO_AIR_MODE_REJECTED);
+      return static_cast<tHCI_STATUS>(hci::ErrorCode::SCO_AIR_MODE_REJECTED);
     case hci::ErrorCode::INVALID_LMP_OR_LL_PARAMETERS:
-      return static_cast<uint8_t>(hci::ErrorCode::INVALID_LMP_OR_LL_PARAMETERS);
+      return static_cast<tHCI_STATUS>(
+          hci::ErrorCode::INVALID_LMP_OR_LL_PARAMETERS);
     case hci::ErrorCode::UNSPECIFIED_ERROR:
       return HCI_ERR_UNSPECIFIED;
     case hci::ErrorCode::UNSUPPORTED_LMP_OR_LL_PARAMETER:
-      return static_cast<uint8_t>(
+      return static_cast<tHCI_STATUS>(
           hci::ErrorCode::UNSUPPORTED_LMP_OR_LL_PARAMETER);
     case hci::ErrorCode::ROLE_CHANGE_NOT_ALLOWED:
-      return static_cast<uint8_t>(hci::ErrorCode::ROLE_CHANGE_NOT_ALLOWED);
+      return static_cast<tHCI_STATUS>(hci::ErrorCode::ROLE_CHANGE_NOT_ALLOWED);
     case hci::ErrorCode::LINK_LAYER_COLLISION:
       return HCI_ERR_LMP_ERR_TRANS_COLLISION;
     case hci::ErrorCode::ENCRYPTION_MODE_NOT_ACCEPTABLE:
       return HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE;
     case hci::ErrorCode::CONTROLLER_BUSY:
-      return static_cast<uint8_t>(hci::ErrorCode::CONTROLLER_BUSY);
+      return static_cast<tHCI_STATUS>(hci::ErrorCode::CONTROLLER_BUSY);
   }
 }
 
index a19e92a..0ed840e 100644 (file)
@@ -107,7 +107,8 @@ void acl_ble_enhanced_connection_complete(
 }
 
 void acl_ble_connection_fail(const tBLE_BD_ADDR& address_with_type,
-                             uint16_t handle, bool enhanced, uint8_t status) {
+                             uint16_t handle, bool enhanced,
+                             tHCI_STATUS status) {
   if (status != HCI_ERR_ADVERTISING_TIMEOUT) {
     btm_cb.ble_ctr_cb.set_connection_state_idle();
     btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT);
index b730bab..32972ed 100644 (file)
@@ -2761,8 +2761,8 @@ bool acl_set_peer_le_features_from_handle(uint16_t hci_handle,
   return true;
 }
 
-void btm_acl_connected(const RawAddress& bda, uint16_t handle, uint8_t status,
-                       uint8_t enc_mode) {
+void btm_acl_connected(const RawAddress& bda, uint16_t handle,
+                       tHCI_STATUS status, uint8_t enc_mode) {
   btm_sec_connected(bda, handle, status, enc_mode);
   btm_acl_set_paging(false);
   l2c_link_hci_conn_comp(status, handle, bda);
index b08cb5e..152ba1d 100644 (file)
@@ -190,7 +190,8 @@ void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,
         android::bluetooth::hci::STATUS_UNKNOWN);
 
     tBLE_BD_ADDR address_with_type{.bda = bda, .type = bda_type};
-    acl_ble_connection_fail(address_with_type, handle, enhanced, status);
+    acl_ble_connection_fail(address_with_type, handle, enhanced,
+                            static_cast<tHCI_STATUS>(status));
   }
 }
 
index e0b8296..807179c 100644 (file)
@@ -3683,17 +3683,7 @@ tBTM_STATUS btm_sec_disconnect(uint16_t handle, uint8_t reason) {
   return (btm_sec_send_hci_disconnect(p_dev_rec, reason, handle));
 }
 
-/*******************************************************************************
- *
- * Function         btm_sec_disconnected
- *
- * Description      This function is when a connection to the peer device is
- *                  dropped
- *
- * Returns          void
- *
- ******************************************************************************/
-void btm_sec_disconnected(uint16_t handle, uint8_t reason) {
+void btm_sec_disconnected(uint16_t handle, tHCI_STATUS reason) {
   tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle);
   uint8_t old_pairing_flags = btm_cb.pairing_flags;
   int result = HCI_ERR_AUTH_FAILURE;
index 790649d..3464d5d 100644 (file)
@@ -25,6 +25,7 @@
 #include <cstdint>
 #include "stack/btm/security_device_record.h"
 #include "stack/include/btm_api_types.h"
+#include "stack/include/hci_error_code.h"
 
 #define BTM_SEC_MAX_COLLISION_DELAY (5000)
 
@@ -645,7 +646,7 @@ tBTM_STATUS btm_sec_disconnect(uint16_t handle, uint8_t reason);
  * Returns          void
  *
  ******************************************************************************/
-void btm_sec_disconnected(uint16_t handle, uint8_t reason);
+void btm_sec_disconnected(uint16_t handle, tHCI_STATUS reason);
 
 /** This function is called when a new connection link key is generated */
 void btm_sec_link_key_notification(const RawAddress& p_bda,
index beac8d3..5feb3f0 100644 (file)
@@ -961,7 +961,7 @@ static void btu_hcif_connection_comp_evt(uint8_t* p, uint8_t evt_len) {
   }
 
   if (link_type == HCI_LINK_TYPE_ACL) {
-    btm_acl_connected(bda, handle, status, enc_mode);
+    btm_acl_connected(bda, handle, static_cast<tHCI_STATUS>(status), enc_mode);
   } else {
     memset(&esco_data, 0, sizeof(tBTM_ESCO_DATA));
     /* esco_data.link_type = HCI_LINK_TYPE_SCO; already zero */
@@ -1022,7 +1022,7 @@ static void btu_hcif_disconnection_comp_evt(uint8_t* p) {
   }
 
   /* Notify security manager */
-  btm_sec_disconnected(handle, reason);
+  btm_sec_disconnected(handle, static_cast<tHCI_STATUS>(reason));
 }
 
 /*******************************************************************************
@@ -1400,7 +1400,8 @@ static void btu_hcif_hdl_command_status(uint16_t opcode, uint8_t status,
     case HCI_CREATE_CONNECTION:
       if (status != HCI_SUCCESS) {
         STREAM_TO_BDADDR(bd_addr, p_cmd);
-        btm_acl_connected(bd_addr, HCI_INVALID_HANDLE, status, 0);
+        btm_acl_connected(bd_addr, HCI_INVALID_HANDLE,
+                          static_cast<tHCI_STATUS>(status), 0);
       }
       break;
     case HCI_AUTHENTICATION_REQUESTED:
index 39d2336..76a9861 100644 (file)
@@ -25,8 +25,8 @@
 // This header contains functions for HCIF-Acl Management to invoke
 //
 void btm_acl_connection_request(const RawAddress& bda, uint8_t* dc);
-void btm_acl_connected(const RawAddress& bda, uint16_t handle, uint8_t status,
-                       uint8_t enc_mode);
+void btm_acl_connected(const RawAddress& bda, uint16_t handle,
+                       tHCI_STATUS status, uint8_t enc_mode);
 void btm_acl_encrypt_change(uint16_t handle, uint8_t status,
                             uint8_t encr_enable);
 void btm_acl_paging(BT_HDR* p, const RawAddress& dest);
index 948c6b8..5c56c32 100644 (file)
@@ -29,4 +29,5 @@ void acl_ble_enhanced_connection_complete(
     uint16_t conn_timeout, const RawAddress& local_rpa,
     const RawAddress& peer_rpa, uint8_t peer_addr_type);
 void acl_ble_connection_fail(const tBLE_BD_ADDR& address_with_type,
-                             uint16_t handle, bool enhanced, uint8_t status);
+                             uint16_t handle, bool enhanced,
+                             tHCI_STATUS status);
index f2392fd..786abc2 100644 (file)
@@ -35,7 +35,7 @@ void btm_read_inq_tx_power_complete(uint8_t* p);
 void btm_read_local_oob_complete(uint8_t* p);
 void btm_rem_oob_req(uint8_t* p);
 void btm_sec_auth_complete(uint16_t handle, uint8_t status);
-void btm_sec_disconnected(uint16_t handle, uint8_t reason);
+void btm_sec_disconnected(uint16_t handle, tHCI_STATUS reason);
 void btm_sec_encrypt_change(uint16_t handle, uint8_t status,
                             uint8_t encr_enable);
 void btm_sec_link_key_notification(const RawAddress& p_bda,