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

Commit 254fa248 authored by Chris Manton's avatar Chris Manton
Browse files

BTM_history: Add dev states to stack hid host profile

Toward loggable code

Bug: 163134718
Test: gd/cert/run
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: Ibc688eacf75a8520fdd74dfef41b2794668bbfa4
parent 564c787a
Loading
Loading
Loading
Loading
+15 −8
Original line number Diff line number Diff line
@@ -817,10 +817,12 @@ void bta_hh_open_failure(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
void bta_hh_close_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
  tBTA_HH_CONN conn_dat;
  tBTA_HH_CBDATA disc_dat = {BTA_HH_OK, 0};
  uint32_t reason = p_data->hid_cback.data; /* Reason for closing (32-bit) */

  // TODO Fix use proper types
  tHID_STATUS hid_status = static_cast<tHID_STATUS>(reason);
  uint32_t reason = p_data->hid_cback.data; /* Reason for closing (32-bit) */
  const bool l2cap_conn_fail = reason & HID_L2CAP_CONN_FAIL;
  const bool l2cap_req_fail = reason & HID_L2CAP_REQ_FAIL;
  const bool l2cap_cfg_fail = reason & HID_L2CAP_CFG_FAIL;
  const tHID_STATUS hid_status = static_cast<tHID_STATUS>(reason & 0xff);

  /* if HID_HDEV_EVT_VC_UNPLUG was received, report BTA_HH_VC_UNPLUG_EVT */
  uint16_t event = p_cb->vp ? BTA_HH_VC_UNPLUG_EVT : BTA_HH_CLOSE_EVT;
@@ -828,6 +830,16 @@ void bta_hh_close_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
  disc_dat.handle = p_cb->hid_handle;
  disc_dat.status = to_bta_hh_status(p_data->hid_cback.data);

  std::string overlay_fail =
      base::StringPrintf("%s %s %s", (l2cap_conn_fail) ? "l2cap_conn_fail" : "",
                         (l2cap_req_fail) ? "l2cap_req_fail" : "",
                         (l2cap_cfg_fail) ? "l2cap_cfg_fail" : "");
  BTM_LogHistory(kBtmLogTag, p_cb->addr, "Closed",
                 base::StringPrintf("%s reason %s %s",
                                    (p_cb->is_le_device) ? "le" : "classic",
                                    hid_status_text(hid_status).c_str(),
                                    overlay_fail.c_str()));

  /* Check reason for closing */
  if ((reason & (HID_L2CAP_CONN_FAIL |
                 HID_L2CAP_REQ_FAIL)) || /* Failure to initialize connection
@@ -851,11 +863,6 @@ void bta_hh_close_act(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
  }
  /* otherwise report CLOSE/VC_UNPLUG event */
  else {
    BTM_LogHistory(kBtmLogTag, p_cb->addr, "Closed",
                   base::StringPrintf("%s reason %s",
                                      (p_cb->is_le_device) ? "le" : "classic",
                                      hid_status_text(hid_status).c_str()));

    /* finaliza device driver */
    bta_hh_co_close(p_cb->hid_handle, p_cb->app_id);
    /* inform role manager */
+36 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@
 *
 ******************************************************************************/

#include <base/strings/stringprintf.h>
#include <string.h>

#include "bt_common.h"
@@ -40,6 +41,11 @@
#include "osi/include/osi.h"
#include "stack/btm/btm_sec.h"
#include "stack/include/acl_api.h"
#include "stack/include/btm_api.h"  // BTM_LogHistory

namespace {
constexpr char kBtmLogTag[] = "HIDH";
}

static uint8_t find_conn_by_cid(uint16_t cid);
static void hidh_conn_retry(uint8_t dhandle);
@@ -141,6 +147,8 @@ tHID_STATUS hidh_conn_disconnect(uint8_t dhandle) {
      hidh_l2cif_disconnect(p_hcon->intr_cid);
    else if (p_hcon->ctrl_cid)
      hidh_l2cif_disconnect(p_hcon->ctrl_cid);

    BTM_LogHistory(kBtmLogTag, hh_cb.devices[dhandle].addr, "Disconnecting");
  } else {
    p_hcon->conn_state = HID_CONN_STATE_UNUSED;
  }
@@ -176,6 +184,12 @@ static void hidh_l2cif_connect_ind(const RawAddress& bd_addr,

  p_hcon = &hh_cb.devices[i].conn;

  BTM_LogHistory(
      kBtmLogTag, hh_cb.devices[i].addr, "Connect request",
      base::StringPrintf("%s state:%s",
                         (psm == HID_PSM_CONTROL) ? "control" : "interrupt",
                         hid_conn::state_text(p_hcon->conn_state).c_str()));

  /* Check we are in the correct state for this */
  if (psm == HID_PSM_INTERRUPT) {
    if (p_hcon->ctrl_cid == 0) {
@@ -214,6 +228,8 @@ static void hidh_l2cif_connect_ind(const RawAddress& bd_addr,
                                              disc_reason (from
                                              HID_ERR_AUTH_FAILED) */
    p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR;
    BTM_LogHistory(kBtmLogTag, hh_cb.devices[i].addr, "Connecting",
                   "waiting for interrupt channel");
    return;
  }

@@ -329,7 +345,11 @@ static void hidh_l2cif_connect_cfm(uint16_t l2cap_cid, uint16_t result) {
  } else {
    p_hcon->conn_state = HID_CONN_STATE_CONFIG;
  }

  BTM_LogHistory(
      kBtmLogTag, hh_cb.devices[dhandle].addr, "Configuring",
      base::StringPrintf("control:0x%04x interrupt:0x%04x state:%s",
                         p_hcon->ctrl_cid, p_hcon->intr_cid,
                         hid_conn::state_text(p_hcon->conn_state).c_str()));
  return;
}

@@ -412,6 +432,7 @@ static void hidh_l2cif_config_cfm(uint16_t l2cap_cid, uint16_t initiator,
        HIDH_TRACE_WARNING("HID-Host INTR Originate failed");
        reason = HID_L2CAP_REQ_FAIL;
        p_hcon->conn_state = HID_CONN_STATE_UNUSED;
        BTM_LogHistory(kBtmLogTag, hh_cb.devices[dhandle].addr, "Failed");
        hidh_conn_disconnect(dhandle);
        hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE,
                       reason, NULL);
@@ -420,6 +441,8 @@ static void hidh_l2cif_config_cfm(uint16_t l2cap_cid, uint16_t initiator,
        /* Transition to the next appropriate state, waiting for connection
         * confirm on interrupt channel. */
        p_hcon->conn_state = HID_CONN_STATE_CONNECTING_INTR;
        BTM_LogHistory(kBtmLogTag, hh_cb.devices[dhandle].addr, "Connecting",
                       "interrupt channel");
      }
    }
  }
@@ -434,6 +457,11 @@ static void hidh_l2cif_config_cfm(uint16_t l2cap_cid, uint16_t initiator,
    hh_cb.devices[dhandle].state = HID_DEV_CONNECTED;
    hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0,
                   NULL);
    BTM_LogHistory(
        kBtmLogTag, hh_cb.devices[dhandle].addr, "Connected",
        base::StringPrintf("control:0x%04x interrupt:0x%04x state:%s",
                           p_hcon->ctrl_cid, p_hcon->intr_cid,
                           hid_conn::state_text(p_hcon->conn_state).c_str()));
  }
}

@@ -466,6 +494,10 @@ static void hidh_l2cif_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) {
  HIDH_TRACE_EVENT("HID-Host Rcvd L2CAP disc, CID: 0x%x", l2cap_cid);

  p_hcon->conn_state = HID_CONN_STATE_DISCONNECTING;
  BTM_LogHistory(
      kBtmLogTag, hh_cb.devices[dhandle].addr, "Disconnecting",
      base::StringPrintf(
          "%s", (l2cap_cid == p_hcon->ctrl_cid) ? "control" : "interrupt"));

  if (l2cap_cid == p_hcon->ctrl_cid)
    p_hcon->ctrl_cid = 0;
@@ -539,6 +571,7 @@ static void hidh_l2cif_disconnect(uint16_t l2cap_cid) {
  if ((p_hcon->ctrl_cid == 0) && (p_hcon->intr_cid == 0)) {
    hh_cb.devices[dhandle].state = HID_DEV_NO_CONN;
    p_hcon->conn_state = HID_CONN_STATE_UNUSED;
    BTM_LogHistory(kBtmLogTag, hh_cb.devices[dhandle].addr, "Disconnected");
    hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE,
                   p_hcon->disc_reason, NULL);
  }
@@ -831,6 +864,8 @@ tHID_STATUS hidh_conn_initiate(uint8_t dhandle) {
    /* Transition to the next appropriate state, waiting for connection confirm
     * on control channel. */
    p_dev->conn.conn_state = HID_CONN_STATE_CONNECTING_CTRL;
    BTM_LogHistory(kBtmLogTag, hh_cb.devices[dhandle].addr, "Connecting",
                   "control channel");
  }

  return (HID_SUCCESS);