OSDN Git Service

Use proper types tHCI_STATUS/tHCI_REASON
authorChris Manton <cmanton@google.com>
Wed, 3 Feb 2021 23:31:04 +0000 (15:31 -0800)
committerChris Manton <cmanton@google.com>
Wed, 3 Feb 2021 23:50:27 +0000 (15:50 -0800)
Towards readable code

Bug: 163134718
Tag: #refactor
Test: gd/cert/run
Change-Id: Ib8f01833a0de300b7612d584d2eae542f465f54c

stack/acl/btm_acl.cc
stack/btu/btu_hcif.cc
stack/include/l2cap_hci_link_interface.h
stack/l2cap/l2c_api.cc
stack/l2cap/l2c_int.h
stack/l2cap/l2c_link.cc
stack/l2cap/l2c_utils.cc
stack/test/common/mock_l2cap_l2c_link.cc

index 0f412e2..c8c2bcb 100644 (file)
@@ -59,6 +59,7 @@
 #include "stack/include/btm_api.h"
 #include "stack/include/btm_iso_api.h"
 #include "stack/include/btu.h"
+#include "stack/include/hci_error_code.h"
 #include "stack/include/hcimsgs.h"
 #include "stack/include/l2cap_acl_interface.h"
 #include "stack/include/sco_hci_link_interface.h"
@@ -66,7 +67,7 @@
 
 void gatt_find_in_device_record(const RawAddress& bd_addr,
                                 tBLE_BD_ADDR* address_with_type);
-void l2c_link_hci_conn_comp(uint8_t status, uint16_t handle,
+void l2c_link_hci_conn_comp(tHCI_STATUS status, uint16_t handle,
                             const RawAddress& p_bda);
 
 void BTM_db_reset(void);
index b7f393e..b5499d3 100644 (file)
@@ -42,6 +42,7 @@
 #include "stack/include/btu.h"
 #include "stack/include/dev_hci_link_interface.h"
 #include "stack/include/gatt_api.h"
+#include "stack/include/hci_error_code.h"
 #include "stack/include/hci_evt_length.h"
 #include "stack/include/hcidefs.h"
 #include "stack/include/inq_hci_link_interface.h"
@@ -52,7 +53,8 @@
 using base::Location;
 using bluetooth::hci::IsoManager;
 
-bool l2c_link_hci_disc_comp(uint16_t handle, uint8_t reason);  // TODO remove
+bool l2c_link_hci_disc_comp(uint16_t handle,
+                            tHCI_REASON reason);               // TODO remove
 bool BTM_BLE_IS_RESOLVE_BDA(const RawAddress& x);              // TODO remove
 void BTA_sys_signal_hw_error();                                // TODO remove
 void smp_cancel_start_encryption_attempt();                    // TODO remove
index a43015e..db4ecee 100644 (file)
 #pragma once
 
 #include "bt_common.h"
+#include "stack/include/hci_error_code.h"
 
 // This header contains functions for HCI-LinkManagement to invoke
 
-extern bool l2c_link_hci_disc_comp(uint16_t handle, uint8_t reason);
+extern bool l2c_link_hci_disc_comp(uint16_t handle, tHCI_REASON reason);
 
 extern void l2c_link_role_changed(const RawAddress* bd_addr, uint8_t new_role,
                                   uint8_t hci_status);
index 5158ff5..198ccf7 100644 (file)
@@ -1220,7 +1220,6 @@ bool L2CA_ConnectFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda) {
 
   // Get a CCB and link the lcb to it
   if (!l2cu_initialize_fixed_ccb(p_lcb, fixed_cid)) {
-    p_lcb->SetDisconnectReason(L2CAP_CONN_NO_RESOURCES);
     LOG_WARN("Unable to allocate fixed channel resource fixed_cid:0x%04x",
              fixed_cid);
     l2cu_release_lcb(p_lcb);
index f86e160..b454003 100644 (file)
@@ -39,6 +39,7 @@
 #include "osi/include/alarm.h"
 #include "osi/include/fixed_queue.h"
 #include "osi/include/list.h"
+#include "stack/include/hci_error_code.h"
 
 #define L2CAP_MIN_MTU 48 /* Minimum acceptable MTU is 48 bytes */
 
@@ -452,11 +453,13 @@ typedef struct t_l2c_linkcb {
   tL2C_CCB* p_fixed_ccbs[L2CAP_NUM_FIXED_CHNLS];
 
  private:
-  uint16_t disc_reason_;
+  tHCI_REASON disc_reason_{HCI_ERR_UNDEFINED};
 
  public:
-  uint16_t DisconnectReason() const { return disc_reason_; }
-  void SetDisconnectReason(uint16_t disc_reason) { disc_reason_ = disc_reason; }
+  tHCI_REASON DisconnectReason() const { return disc_reason_; }
+  void SetDisconnectReason(tHCI_REASON disc_reason) {
+    disc_reason_ = disc_reason;
+  }
 
   tBT_TRANSPORT transport;
   bool is_transport_br_edr() const { return transport == BT_TRANSPORT_BR_EDR; }
index 9555a71..660f683 100644 (file)
@@ -35,6 +35,7 @@
 #include "stack/btm/btm_int_types.h"
 #include "stack/include/acl_api.h"
 #include "stack/include/bt_types.h"
+#include "stack/include/hci_error_code.h"
 #include "stack/include/hcimsgs.h"
 #include "stack/l2cap/l2c_int.h"
 #include "types/bt_transport.h"
@@ -134,7 +135,7 @@ void l2c_link_hci_conn_req(const RawAddress& bd_addr) {
   }
 }
 
-void l2c_link_hci_conn_comp(uint8_t status, uint16_t handle,
+void l2c_link_hci_conn_comp(tHCI_STATUS status, uint16_t handle,
                             const RawAddress& p_bda) {
   if (bluetooth::shim::is_gd_l2cap_enabled()) {
     return;
@@ -325,7 +326,7 @@ void l2c_link_sec_comp2(const RawAddress& p_bda,
  * Returns          true if the link is known about, else false
  *
  ******************************************************************************/
-bool l2c_link_hci_disc_comp(uint16_t handle, uint8_t reason) {
+bool l2c_link_hci_disc_comp(uint16_t handle, tHCI_REASON reason) {
   if (bluetooth::shim::is_gd_l2cap_enabled()) {
     return false;
   }
index b7a1db5..72c5326 100644 (file)
@@ -40,6 +40,7 @@
 #include "osi/include/log.h"
 #include "stack/btm/btm_sec.h"
 #include "stack/include/acl_api.h"
+#include "stack/include/hci_error_code.h"
 
 tL2C_CCB* l2cu_get_next_channel_in_rr(tL2C_LCB* p_lcb); // TODO Move
 
@@ -2032,7 +2033,7 @@ void l2cu_device_reset(void) {
 
   for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_lcb++) {
     if ((p_lcb->in_use) && (p_lcb->Handle() != HCI_INVALID_HANDLE)) {
-      l2c_link_hci_disc_comp(p_lcb->Handle(), (uint8_t)-1);
+      l2c_link_hci_disc_comp(p_lcb->Handle(), HCI_ERR_UNDEFINED);
     }
   }
 }
index f7ae8c7..a0f1800 100644 (file)
@@ -30,7 +30,7 @@ BT_HDR* l2cu_get_next_buffer_to_send(tL2C_LCB* p_lcb) {
   mock_function_count_map[__func__]++;
   return nullptr;
 }
-bool l2c_link_hci_disc_comp(uint16_t handle, uint8_t reason) {
+bool l2c_link_hci_disc_comp(uint16_t handle, tHCI_REASON reason) {
   mock_function_count_map[__func__]++;
   return false;
 }
@@ -56,7 +56,7 @@ void l2c_link_check_send_pkts(tL2C_LCB* p_lcb, uint16_t local_cid,
                               BT_HDR* p_buf) {
   mock_function_count_map[__func__]++;
 }
-void l2c_link_hci_conn_comp(uint8_t status, uint16_t handle,
+void l2c_link_hci_conn_comp(tHCI_STATUS status, uint16_t handle,
                             const RawAddress& p_bda) {
   mock_function_count_map[__func__]++;
 }