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

Commit 92371552 authored by Hui Peng's avatar Hui Peng
Browse files

Clean up logs in bta/hh

Bug: 305066880
Test: m com.android.btservices
Flag: EXEMPT, no-op
Change-Id: I971790c897cfd966c9484aceaf2cf3677b60d87b
parent 42363b5d
Loading
Loading
Loading
Loading
+22 −22
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
 *
 ******************************************************************************/

#define LOG_TAG "bluetooth"
#define LOG_TAG "bt_bta_hh"

#include <cstdint>
#include <string>
@@ -204,8 +204,8 @@ static void bta_hh_sdp_cback(uint16_t result, uint16_t attr_mask,
    /* security is required for the connection, add attr_mask bit*/
    attr_mask |= HID_SEC_REQUIRED;

    LOG_VERBOSE("%s: p_cb: %p result 0x%02x, attr_mask 0x%02x, handle %x",
                __func__, p_cb, result, attr_mask, p_cb->hid_handle);
    LOG_VERBOSE("p_cb:%p result:0x%02x, attr_mask:0x%02x, handle:0x%x", p_cb,
                result, attr_mask, p_cb->hid_handle);

    /* check to see type of device is supported , and should not been added
     * before */
@@ -266,7 +266,7 @@ static void bta_hh_di_sdp_cback(UNUSED_ATTR const RawAddress& bd_addr,
  tBTA_HH_STATUS status = BTA_HH_ERR_SDP;
  tSDP_DI_GET_RECORD di_rec;
  tHID_STATUS ret;
  LOG_VERBOSE("%s: p_cb: %p result 0x%02x", __func__, p_cb, result);
  LOG_VERBOSE("p_cb:%p result:0x%02x", p_cb, result);

  /* if DI record does not exist on remote device, vendor_id in
   * tBTA_HH_DEV_DSCP_INFO will be set to 0xffff and we will allow the
@@ -296,8 +296,7 @@ static void bta_hh_di_sdp_cback(UNUSED_ATTR const RawAddress& bd_addr,
    if (ret == HID_SUCCESS) {
      status = BTA_HH_OK;
    } else {
      LOG_VERBOSE("%s:  HID_HostGetSDPRecord failed: Status 0x%2x", __func__,
                  ret);
      LOG_VERBOSE("failure Status 0x%2x", ret);
    }
  }

@@ -372,7 +371,7 @@ void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
  tBTA_HH_CONN conn_dat;
  tBTA_HH_STATUS status = p_data->status;

  LOG_VERBOSE("%s:  status 0x%2X", __func__, p_data->status);
  LOG_VERBOSE("status 0x%2X", p_data->status);

  /* initialize call back data */
  memset((void*)&conn_dat, 0, sizeof(tBTA_HH_CONN));
@@ -387,17 +386,17 @@ void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {

      /* open HID connection */
      ret = HID_HostOpenDev(p_cb->hid_handle);
      LOG_VERBOSE("%s: HID_HostOpenDev returned=%d", __func__, ret);
      LOG_VERBOSE("HID_HostOpenDev returned=%d", ret);
      if (ret == HID_SUCCESS || ret == HID_ERR_ALREADY_CONN) {
        status = BTA_HH_OK;
      } else if (ret == HID_ERR_CONN_IN_PROCESS) {
        /* Connection already in progress, return from here, SDP
         * will be performed after connection is completed.
         */
        LOG_VERBOSE("%s: connection already in progress", __func__);
        LOG_VERBOSE("connection already in progress");
        return;
      } else {
        LOG_VERBOSE("%s: HID_HostOpenDev failed: Status 0x%2X", __func__, ret);
        LOG_VERBOSE("HID_HostOpenDev failed: Status 0x%2X", ret);
        /* open fail, remove device from management device list */
        HID_HostRemoveDev(p_cb->hid_handle);
        status = BTA_HH_ERR;
@@ -416,7 +415,7 @@ void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
     */
    if ((status == BTA_HH_ERR_SDP) && (p_cb->incoming_conn) &&
        (p_cb->app_id == 0)) {
      LOG_ERROR("%s: SDP failed for  incoming conn hndl: %d", __func__,
      LOG_ERROR("SDP failed for  incoming conn hndl:%d",
                p_cb->incoming_hid_handle);
      HID_HostRemoveDev(p_cb->incoming_hid_handle);
    }
@@ -457,7 +456,7 @@ static void bta_hh_bredr_conn(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data)
    tBTA_HH_DATA bta_hh_data;
    bta_hh_data.status = BTA_HH_OK;

    LOG_VERBOSE("%s: skip SDP for known devices", __func__);
    LOG_VERBOSE("skip SDP for known devices");

    if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE) {
      uint8_t hdl;
@@ -673,7 +672,7 @@ void bta_hh_open_act(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
  uint8_t dev_handle =
      p_data ? (uint8_t)p_data->hid_cback.hdr.layer_specific : p_cb->hid_handle;

  LOG_VERBOSE("%s:  Device[%d] connected", __func__, dev_handle);
  LOG_VERBOSE("Device[%d] connected", dev_handle);

  /* SDP has been done */
  if (p_cb->app_id != 0) {
@@ -1124,9 +1123,10 @@ void bta_hh_write_dev_act(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
        };
        (*bta_hh_cb.p_cback)(BTA_HH_VC_UNPLUG_EVT, &cbdata);
      } else {
        LOG_ERROR("skipped executing callback in hid host error handling. "
                  "command type: %d, param: %d", p_data->api_sndcmd.t_type,
                  p_data->api_sndcmd.param);
        LOG_ERROR(
            "skipped executing callback in hid host error handling. "
            "command type:%d, param:%d",
            p_data->api_sndcmd.t_type, p_data->api_sndcmd.param);
      }
    } else {
      switch (p_data->api_sndcmd.t_type) {
@@ -1156,7 +1156,7 @@ void bta_hh_write_dev_act(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
        /* currently not expected */
        case HID_TRANS_DATAC:
        default:
          LOG_VERBOSE("%s: cmd type = %d", __func__, p_data->api_sndcmd.t_type);
          LOG_VERBOSE("cmd type=%d", p_data->api_sndcmd.t_type);
          break;
      }

@@ -1193,7 +1193,7 @@ static void bta_hh_cback(uint8_t dev_handle, const RawAddress& addr,
  uint16_t sm_event = BTA_HH_INVALID_EVT;
  uint8_t xx = 0;

  LOG_VERBOSE("%s::HID_event [%s]", __func__, bta_hh_hid_event_name(event));
  LOG_VERBOSE("HID_event [%s]", bta_hh_hid_event_name(event));

  switch (event) {
    case HID_HDEV_EVT_OPEN:
+1 −1
Original line number Diff line number Diff line
@@ -26,9 +26,9 @@

#include <cstdint>

#include "bt_target.h"  // Must be first to define build configuration
#include "bta/hh/bta_hh_int.h"
#include "bta/sys/bta_sys.h"
#include "os/log.h"
#include "osi/include/allocator.h"
#include "osi/include/osi.h"  // UNUSED_ATTR
#include "stack/include/bt_hdr.h"
+70 −83
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
 *
 ******************************************************************************/

#define LOG_TAG "bt_bta_hh"
#define LOG_TAG "ble_bta_hh"

#include <base/functional/bind.h>
#include <base/functional/callback.h>
@@ -28,6 +28,7 @@
#include "bta/include/bta_gatt_queue.h"
#include "bta/include/bta_hh_co.h"
#include "device/include/interop.h"
#include "os/log.h"
#include "osi/include/allocator.h"
#include "osi/include/osi.h"    // ARRAY_SIZE
#include "stack/btm/btm_sec.h"  // BTM_
@@ -63,8 +64,7 @@ constexpr bool kBTA_HH_LE_RECONN = false;

namespace {

constexpr char kBtmLogTag[] = "HIDH";

constexpr char kBtmLogTag[] = "LE HIDH";
}

static const uint16_t bta_hh_uuid_to_rtp_type[BTA_LE_HID_RTP_UUID_MAX][2] = {
@@ -94,7 +94,7 @@ static const char* bta_hh_le_rpt_name[4] = {"UNKNOWN", "INPUT", "OUTPUT",
 *
 ******************************************************************************/
static void bta_hh_le_hid_report_dbg(tBTA_HH_DEV_CB* p_cb) {
  LOG_VERBOSE("%s: HID Report DB", __func__);
  LOG_VERBOSE("HID Report DB");

  if (p_cb->hid_srvc.state < BTA_HH_SERVICE_DISCOVERED) return;

@@ -359,8 +359,7 @@ static tBTA_HH_LE_RPT* bta_hh_le_find_rpt_by_idtype(tBTA_HH_LE_RPT* p_head,
  tBTA_HH_LE_RPT* p_rpt = p_head;
  uint8_t i;

  LOG_VERBOSE("bta_hh_le_find_rpt_by_idtype: r_type: %d rpt_id: %d", r_type,
              rpt_id);
  LOG_VERBOSE("r_type:%d rpt_id:%d", r_type, rpt_id);

  for (i = 0; i < BTA_HH_LE_RPT_MAX; i++, p_rpt++) {
    if (p_rpt->in_use && p_rpt->rpt_id == rpt_id && r_type == p_rpt->rpt_type) {
@@ -441,7 +440,7 @@ static const gatt::Descriptor* find_descriptor_by_short_uuid(
      BTA_GATTC_GetCharacteristic(conn_id, char_handle);

  if (!p_char) {
    LOG_WARN("%s No such characteristic: %d", __func__, char_handle);
    LOG_WARN("No such characteristic:%d", char_handle);
    return NULL;
  }

@@ -503,7 +502,7 @@ static void bta_hh_le_save_report_ref(tBTA_HH_DEV_CB* p_dev_cb,
    if (p_rpt->rpt_type > BTA_HH_RPTT_FEATURE) /* invalid report type */
      p_rpt->rpt_type = BTA_HH_RPTT_RESRV;

    LOG_VERBOSE("%s: report ID: %d", __func__, p_rpt->rpt_id);
    LOG_VERBOSE("report ID:%d", p_rpt->rpt_id);
    tBTA_HH_RPT_CACHE_ENTRY rpt_entry;
    rpt_entry.rpt_id = p_rpt->rpt_id;
    rpt_entry.rpt_type = p_rpt->rpt_type;
@@ -535,8 +534,7 @@ static void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB* p_dev_cb,
                                           bool register_ba) {
  tBTA_HH_LE_RPT* p_rpt = &p_dev_cb->hid_srvc.report[0];

  LOG_VERBOSE("%s: bta_hh_le_register_input_notif mode: %d", __func__,
              proto_mode);
  LOG_VERBOSE("mode:%d", proto_mode);

  for (int i = 0; i < BTA_HH_LE_RPT_MAX; i++, p_rpt++) {
    if (p_rpt->rpt_type == BTA_HH_RPTT_INPUT) {
@@ -548,16 +546,14 @@ static void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB* p_dev_cb,
      else if (proto_mode == BTA_HH_PROTO_BOOT_MODE) {
        if (p_rpt->uuid == GATT_UUID_HID_REPORT &&
            p_rpt->client_cfg_value == GATT_CLT_CONFIG_NOTIFICATION) {
          LOG_VERBOSE("%s ---> Deregister Report ID: %d", __func__,
                      p_rpt->rpt_id);
          LOG_VERBOSE("---> Deregister Report ID:%d", p_rpt->rpt_id);
          BTA_GATTC_DeregisterForNotifications(
              bta_hh_cb.gatt_if, p_dev_cb->addr, p_rpt->char_inst_id);
        }
        /* register boot reports notification */
        else if (p_rpt->uuid == GATT_UUID_HID_BT_KB_INPUT ||
                 p_rpt->uuid == GATT_UUID_HID_BT_MOUSE_INPUT) {
          LOG_VERBOSE("%s <--- Register Boot Report ID: %d", __func__,
                      p_rpt->rpt_id);
          LOG_VERBOSE("<--- Register Boot Report ID:%d", p_rpt->rpt_id);
          BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr,
                                             p_rpt->char_inst_id);
        }
@@ -565,14 +561,12 @@ static void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB* p_dev_cb,
        if ((p_rpt->uuid == GATT_UUID_HID_BT_KB_INPUT ||
             p_rpt->uuid == GATT_UUID_HID_BT_MOUSE_INPUT) &&
            p_rpt->client_cfg_value == GATT_CLT_CONFIG_NOTIFICATION) {
          LOG_VERBOSE("%s ---> Deregister Boot Report ID: %d", __func__,
                      p_rpt->rpt_id);
          LOG_VERBOSE("--> Deregister Boot Report ID:%d", p_rpt->rpt_id);
          BTA_GATTC_DeregisterForNotifications(
              bta_hh_cb.gatt_if, p_dev_cb->addr, p_rpt->char_inst_id);
        } else if (p_rpt->uuid == GATT_UUID_HID_REPORT &&
                   p_rpt->client_cfg_value == GATT_CLT_CONFIG_NOTIFICATION) {
          LOG_VERBOSE("%s <--- Register Report ID: %d", __func__,
                      p_rpt->rpt_id);
          LOG_VERBOSE("<--- Register Report ID:%d", p_rpt->rpt_id);
          BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr,
                                             p_rpt->char_inst_id);
        }
@@ -597,15 +591,13 @@ static void bta_hh_le_deregister_input_notif(tBTA_HH_DEV_CB* p_dev_cb) {
    if (p_rpt->rpt_type == BTA_HH_RPTT_INPUT) {
      if (p_rpt->uuid == GATT_UUID_HID_REPORT &&
          p_rpt->client_cfg_value == GATT_CLT_CONFIG_NOTIFICATION) {
        LOG_VERBOSE("%s ---> Deregister Report ID: %d", __func__,
                    p_rpt->rpt_id);
        LOG_VERBOSE("---> Deregister Report ID:%d", p_rpt->rpt_id);
        BTA_GATTC_DeregisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr,
                                             p_rpt->char_inst_id);
      } else if ((p_rpt->uuid == GATT_UUID_HID_BT_KB_INPUT ||
                  p_rpt->uuid == GATT_UUID_HID_BT_MOUSE_INPUT) &&
                 p_rpt->client_cfg_value == GATT_CLT_CONFIG_NOTIFICATION) {
        LOG_VERBOSE("%s ---> Deregister Boot Report ID: %d", __func__,
                    p_rpt->rpt_id);
        LOG_VERBOSE("---> Deregister Boot Report ID:%d", p_rpt->rpt_id);
        BTA_GATTC_DeregisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr,
                                             p_rpt->char_inst_id);
      }
@@ -762,7 +754,7 @@ static bool bta_hh_le_set_protocol_mode(tBTA_HH_DEV_CB* p_cb,
                                        tBTA_HH_PROTO_MODE mode) {
  tBTA_HH_CBDATA cback_data;

  LOG_VERBOSE("%s attempt mode: %s", __func__,
  LOG_VERBOSE("attempt mode:%s",
              (mode == BTA_HH_PROTO_RPT_MODE) ? "Report" : "Boot");

  cback_data.handle = p_cb->hid_handle;
@@ -973,7 +965,8 @@ static void bta_hh_le_encrypt_cback(const RawAddress* bd_addr,
 ******************************************************************************/
void bta_hh_security_cmpl(tBTA_HH_DEV_CB* p_cb,
                          UNUSED_ATTR const tBTA_HH_DATA* p_buf) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s, status:%d", ADDRESS_TO_LOGGABLE_CSTR(p_cb->addr),
              p_cb->status);
  if (p_cb->status == BTA_HH_OK) {
    if (p_cb->hid_srvc.state < BTA_HH_SERVICE_DISCOVERED) {
      LOG_DEBUG("No reports loaded, try to load");
@@ -991,7 +984,7 @@ void bta_hh_security_cmpl(tBTA_HH_DEV_CB* p_cb,
    /*  discovery has been done for HID service */
    if (p_cb->app_id != 0 &&
        p_cb->hid_srvc.state >= BTA_HH_SERVICE_DISCOVERED) {
      LOG_VERBOSE("%s: discovery has been done for HID service", __func__);
      LOG_VERBOSE("discovery has been done for HID service");
      /* configure protocol mode */
      if (!bta_hh_le_set_protocol_mode(p_cb, p_cb->mode)) {
        bta_hh_le_open_cmpl(p_cb);
@@ -999,7 +992,7 @@ void bta_hh_security_cmpl(tBTA_HH_DEV_CB* p_cb,
    }
    /* start primary service discovery for HID service */
    else {
      LOG_VERBOSE("%s: Starting service discovery", __func__);
      LOG_VERBOSE("Starting service discovery");
      bta_hh_le_pri_service_discovery(p_cb);
    }
  }
@@ -1070,6 +1063,7 @@ static void bta_hh_clear_service_cache(tBTA_HH_DEV_CB* p_cb) {
 ******************************************************************************/
void bta_hh_start_security(tBTA_HH_DEV_CB* p_cb,
                           UNUSED_ATTR const tBTA_HH_DATA* p_buf) {
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->addr));
  if (BTM_SecIsSecurityPending(p_cb->addr)) {
    /* if security collision happened, wait for encryption done */
    p_cb->security_pending = true;
@@ -1078,17 +1072,22 @@ void bta_hh_start_security(tBTA_HH_DEV_CB* p_cb,

  /* if link has been encrypted */
  if (BTM_IsEncrypted(p_cb->addr, BT_TRANSPORT_LE)) {
    LOG_DEBUG("addr:%s already encrypted",
              ADDRESS_TO_LOGGABLE_CSTR(p_cb->addr));
    p_cb->status = BTA_HH_OK;
    bta_hh_sm_execute(p_cb, BTA_HH_ENC_CMPL_EVT, NULL);
  }
  /* if bonded and link not encrypted */
  else if (BTM_IsLinkKeyKnown(p_cb->addr, BT_TRANSPORT_LE)) {
    LOG_DEBUG("addr:%s bonded, not encrypted",
              ADDRESS_TO_LOGGABLE_CSTR(p_cb->addr));
    p_cb->status = BTA_HH_ERR_AUTH_FAILED;
    BTM_SetEncryption(p_cb->addr, BT_TRANSPORT_LE, bta_hh_le_encrypt_cback,
                      NULL, BTM_BLE_SEC_ENCRYPT);
  }
  /* unbonded device, report security error here */
  else {
    LOG_DEBUG("addr:%s not bonded", ADDRESS_TO_LOGGABLE_CSTR(p_cb->addr));
    p_cb->status = BTA_HH_ERR_AUTH_FAILED;
    bta_hh_clear_service_cache(p_cb);
    BTM_SetEncryption(p_cb->addr, BT_TRANSPORT_LE, bta_hh_le_encrypt_cback,
@@ -1107,16 +1106,12 @@ void bta_hh_start_security(tBTA_HH_DEV_CB* p_cb,
 ******************************************************************************/
void bta_hh_gatt_open(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_buf) {
  const tBTA_GATTC_OPEN* p_data = &p_buf->le_open;
  const uint8_t* p2;

  /* if received invalid callback data , ignore it */
  if (p_cb == NULL || p_data == NULL) return;

  p2 = p_data->remote_bda.address;

  LOG_VERBOSE("bta_hh_gatt_open BTA_GATTC_OPEN_EVT bda= [%08x%04x] status =%d",
              ((p2[0]) << 24) + ((p2[1]) << 16) + ((p2[2]) << 8) + (p2[3]),
              ((p2[4]) << 8) + p2[5], p_data->status);
  LOG_VERBOSE("BTA_GATTC_OPEN_EVT bda=%s status=%d",
              ADDRESS_TO_LOGGABLE_CSTR(p_data->remote_bda), p_data->status);

  if (p_data->status == GATT_SUCCESS) {
    p_cb->hid_handle = bta_hh_le_get_le_dev_hdl(p_cb->index);
@@ -1133,8 +1128,8 @@ void bta_hh_gatt_open(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_buf) {

    BtaGattQueue::Clean(p_cb->conn_id);

    LOG_VERBOSE("hid_handle = %2x conn_id = %04x cb_index = %d",
                p_cb->hid_handle, p_cb->conn_id, p_cb->index);
    LOG_VERBOSE("hid_handle=0x%2x conn_id=0x%04x cb_index=%d", p_cb->hid_handle,
                p_cb->conn_id, p_cb->index);

    bta_hh_sm_execute(p_cb, BTA_HH_START_ENC_EVT, NULL);

@@ -1157,7 +1152,7 @@ void bta_hh_gatt_open(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_buf) {
static void bta_hh_le_close(const tBTA_GATTC_CLOSE& gattc_data) {
  tBTA_HH_DEV_CB* p_cb = bta_hh_le_find_dev_cb_by_bda(gattc_data.remote_bda);
  if (p_cb == nullptr) {
    LOG_WARN("Received close event with unknown device:%s",
    LOG_WARN("unknown device:%s",
             ADDRESS_TO_LOGGABLE_CSTR(gattc_data.remote_bda));
    return;
  }
@@ -1201,7 +1196,7 @@ static void bta_hh_le_close(const tBTA_GATTC_CLOSE& gattc_data) {
 ******************************************************************************/
static void bta_hh_le_gatt_disc_cmpl(tBTA_HH_DEV_CB* p_cb,
                                     tBTA_HH_STATUS status) {
  LOG_VERBOSE("bta_hh_le_gatt_disc_cmpl ");
  LOG_VERBOSE("status:%d", status);

  /* if open sucessful or protocol mode not desired, keep the connection open
   * but inform app */
@@ -1223,12 +1218,12 @@ static void read_hid_info_cb(uint16_t conn_id, tGATT_STATUS status,
                             uint16_t handle, uint16_t len, uint8_t* value,
                             void* data) {
  if (status != GATT_SUCCESS) {
    LOG_ERROR("%s: error: %d", __func__, status);
    LOG_ERROR("error:%d", status);
    return;
  }

  if (len != 4) {
    LOG_ERROR("%s: wrong length: %d", __func__, len);
    LOG_ERROR("wrong length:%d", len);
    return;
  }

@@ -1244,7 +1239,7 @@ static void read_hid_report_map_cb(uint16_t conn_id, tGATT_STATUS status,
                                   uint16_t handle, uint16_t len,
                                   uint8_t* value, void* data) {
  if (status != GATT_SUCCESS) {
    LOG_ERROR("%s: error reading characteristic: %d", __func__, status);
    LOG_ERROR("error reading characteristic:%d", status);
    return;
  }

@@ -1267,14 +1262,14 @@ static void read_ext_rpt_ref_desc_cb(uint16_t conn_id, tGATT_STATUS status,
                                     uint16_t handle, uint16_t len,
                                     uint8_t* value, void* data) {
  if (status != GATT_SUCCESS) {
    LOG_ERROR("%s: error: %d", __func__, status);
    LOG_ERROR("error:%d", status);
    return;
  }

  /* if the length of the descriptor value is right, parse it assume it's a 16
   * bits UUID */
  if (len != Uuid::kNumBytes16) {
    LOG_ERROR("%s: we support only 16bit UUID: %d", __func__, len);
    LOG_ERROR("we support only 16bit UUID %d", len);
    return;
  }

@@ -1283,7 +1278,7 @@ static void read_ext_rpt_ref_desc_cb(uint16_t conn_id, tGATT_STATUS status,

  STREAM_TO_UINT16(p_dev_cb->hid_srvc.ext_rpt_ref, pp);

  LOG_VERBOSE("%s: External Report Reference UUID 0x%04x", __func__,
  LOG_VERBOSE("External Report Reference UUID 0x%04x",
              p_dev_cb->hid_srvc.ext_rpt_ref);
}

@@ -1291,7 +1286,7 @@ static void read_report_ref_desc_cb(uint16_t conn_id, tGATT_STATUS status,
                                    uint16_t handle, uint16_t len,
                                    uint8_t* value, void* data) {
  if (status != GATT_SUCCESS) {
    LOG_ERROR("%s: error: %d", __func__, status);
    LOG_ERROR("error:%d", status);
    return;
  }

@@ -1299,7 +1294,7 @@ static void read_report_ref_desc_cb(uint16_t conn_id, tGATT_STATUS status,
  const gatt::Descriptor* p_desc = BTA_GATTC_GetDescriptor(conn_id, handle);

  if (!p_desc) {
    LOG_ERROR("%s: error: descriptor is null!", __func__);
    LOG_ERROR("error: descriptor is null!");
    return;
  }

@@ -1319,12 +1314,12 @@ static void read_pref_conn_params_cb(uint16_t conn_id, tGATT_STATUS status,
                                     uint16_t handle, uint16_t len,
                                     uint8_t* value, void* data) {
  if (status != GATT_SUCCESS) {
    LOG_ERROR("%s: error: %d", __func__, status);
    LOG_ERROR("error:%d", status);
    return;
  }

  if (len != 8) {
    LOG_ERROR("%s: we support only 16bit UUID: %d", __func__, len);
    LOG_ERROR("we support only 16bit UUID:%d", len);
    return;
  }

@@ -1353,9 +1348,8 @@ static void read_pref_conn_params_cb(uint16_t conn_id, tGATT_STATUS status,
      timeout < BTM_BLE_CONN_SUP_TOUT_MIN ||
      timeout > BTM_BLE_CONN_SUP_TOUT_MAX || max_interval < min_interval) {
    LOG_ERROR(
        "%s: Invalid connection parameters. min=%d, max=%d, latency=%d, "
        "timeout=%d",
        __func__, min_interval, max_interval, latency, timeout);
        "Invalid connection parameters. min=%d, max=%d, latency=%d, timeout=%d",
        min_interval, max_interval, latency, timeout);
    return;
  }

@@ -1390,7 +1384,7 @@ static void bta_hh_le_search_hid_chars(tBTA_HH_DEV_CB* p_dev_cb,
    if (!charac.uuid.Is16Bit()) continue;

    uint16_t uuid16 = charac.uuid.As16Bit();
    LOG_INFO("%s: %s %s", __func__, bta_hh_uuid_to_str(uuid16),
    LOG_INFO("%s %s", bta_hh_uuid_to_str(uuid16),
             charac.uuid.ToString().c_str());

    switch (uuid16) {
@@ -1417,7 +1411,7 @@ static void bta_hh_le_search_hid_chars(tBTA_HH_DEV_CB* p_dev_cb,
            p_dev_cb, p_dev_cb->hid_srvc.srvc_inst_id, GATT_UUID_HID_REPORT,
            charac.value_handle);
        if (p_rpt == NULL) {
          LOG_ERROR("%s: Add report entry failed !!!", __func__);
          LOG_ERROR("Add report entry failed !!!");
          break;
        }

@@ -1434,13 +1428,13 @@ static void bta_hh_le_search_hid_chars(tBTA_HH_DEV_CB* p_dev_cb,
      case GATT_UUID_HID_BT_KB_INPUT:
        if (bta_hh_le_find_alloc_report_entry(p_dev_cb, service->handle, uuid16,
                                              charac.value_handle) == NULL)
          LOG_ERROR("%s: Add report entry failed !!!", __func__);
          LOG_ERROR("Add report entry failed !!!");

        break;

      default:
        LOG_VERBOSE("%s: not processing %s 0x%04d", __func__,
                    bta_hh_uuid_to_str(uuid16), uuid16);
        LOG_VERBOSE("not processing %s 0x%04d", bta_hh_uuid_to_str(uuid16),
                    uuid16);
    }
  }

@@ -1494,7 +1488,7 @@ static void bta_hh_le_srvc_search_cmpl(tBTA_GATTC_SEARCH_CMPL* p_data) {

      bta_hh_le_search_hid_chars(p_dev_cb, &service);

      LOG_VERBOSE("%s: have HID service inst_id= %d", __func__,
      LOG_VERBOSE("have HID service inst_id=%d",
                  p_dev_cb->hid_srvc.srvc_inst_id);
    } else if (service.uuid == Uuid::From16Bit(UUID_SERVCLASS_SCAN_PARAM)) {
      scp_service = &service;
@@ -1554,18 +1548,15 @@ static void bta_hh_le_input_rpt_notify(tBTA_GATTC_NOTIFY* p_data) {
  tBTA_HH_LE_RPT* p_rpt;

  if (p_dev_cb == NULL) {
    LOG_ERROR("%s: notification received from Unknown device, conn_id: 0x%04x",
              __func__, p_data->conn_id);
    LOG_ERROR("Unknown device, conn_id: 0x%04x", p_data->conn_id);
    return;
  }

  const gatt::Characteristic* p_char =
      BTA_GATTC_GetCharacteristic(p_dev_cb->conn_id, p_data->handle);
  if (p_char == NULL) {
    LOG_ERROR(
        "%s: notification received for Unknown Characteristic, conn_id: "
        "0x%04x, handle: 0x%04x",
        __func__, p_dev_cb->conn_id, p_data->handle);
    LOG_ERROR("Unknown Characteristic, conn_id:0x%04x, handle:0x%04x",
              p_dev_cb->conn_id, p_data->handle);
    return;
  }

@@ -1577,10 +1568,8 @@ static void bta_hh_le_input_rpt_notify(tBTA_GATTC_NOTIFY* p_data) {
  p_rpt = bta_hh_le_find_report_entry(
      p_dev_cb, p_svc->handle, p_char->uuid.As16Bit(), p_char->value_handle);
  if (p_rpt == NULL) {
    LOG_ERROR(
        "%s: notification received for Unknown Report, uuid: %s, handle: "
        "0x%04x",
        __func__, p_char->uuid.ToString().c_str(), p_char->value_handle);
    LOG_ERROR("Unknown Report, uuid:%s, handle:0x%04x",
              p_char->uuid.ToString().c_str(), p_char->value_handle);
    return;
  }

@@ -1589,7 +1578,7 @@ static void bta_hh_le_input_rpt_notify(tBTA_GATTC_NOTIFY* p_data) {
  else if (p_char->uuid == Uuid::From16Bit(GATT_UUID_HID_BT_KB_INPUT))
    app_id = BTA_HH_APP_ID_KB;

  LOG_VERBOSE("Notification received on report ID: %d", p_rpt->rpt_id);
  LOG_VERBOSE("report ID: %d", p_rpt->rpt_id);

  /* need to append report ID to the head of data */
  if (p_rpt->rpt_id != 0) {
@@ -1829,7 +1818,7 @@ static void bta_hh_le_get_rpt(tBTA_HH_DEV_CB* p_cb, tBTA_HH_RPT_TYPE r_type,
      p_cb->hid_srvc.report, p_cb->mode, r_type, rpt_id);

  if (p_rpt == NULL) {
    LOG_ERROR("%s: no matching report", __func__);
    LOG_ERROR("no matching report");
    return;
  }

@@ -1847,7 +1836,7 @@ static void write_report_cb(uint16_t conn_id, tGATT_STATUS status,

  if (cb_evt == 0) return;

  LOG_VERBOSE("bta_hh_le_write_cmpl w4_evt: %d", p_dev_cb->w4_evt);
  LOG_VERBOSE("w4_evt:%d", p_dev_cb->w4_evt);

  const gatt::Characteristic* p_char =
      BTA_GATTC_GetCharacteristic(conn_id, handle);
@@ -1882,7 +1871,7 @@ static void bta_hh_le_write_rpt(tBTA_HH_DEV_CB* p_cb, tBTA_HH_RPT_TYPE r_type,
  uint8_t rpt_id;

  if (p_buf == NULL || p_buf->len == 0) {
    LOG_ERROR("%s: Illegal data", __func__);
    LOG_ERROR("Illegal data");
    return;
  }

@@ -1894,7 +1883,7 @@ static void bta_hh_le_write_rpt(tBTA_HH_DEV_CB* p_cb, tBTA_HH_RPT_TYPE r_type,
  p_rpt = bta_hh_le_find_rpt_by_idtype(p_cb->hid_srvc.report, p_cb->mode,
                                       r_type, rpt_id);
  if (p_rpt == NULL) {
    LOG_ERROR("%s: no matching report", __func__);
    LOG_ERROR("no matching report");
    osi_free(p_buf);
    return;
  }
@@ -1978,7 +1967,7 @@ void bta_hh_le_write_dev_act(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
      break;

    default:
      LOG_ERROR("%s unsupported transaction for BLE HID device: %d", __func__,
      LOG_ERROR("unsupported transaction for BLE HID device:%d",
                p_data->api_sndcmd.t_type);
      break;
  }
@@ -2117,8 +2106,7 @@ static void bta_hh_le_service_changed(RawAddress remote_bda) {
static void bta_hh_le_service_discovery_done(RawAddress remote_bda) {
  tBTA_HH_DEV_CB* p_cb = bta_hh_le_find_dev_cb_by_bda(remote_bda);
  if (p_cb == nullptr) {
    LOG_WARN("Received service discovery done event for unknown device:%s",
             ADDRESS_TO_LOGGABLE_CSTR(remote_bda));
    LOG_WARN("unknown device:%s", ADDRESS_TO_LOGGABLE_CSTR(remote_bda));
    return;
  }

@@ -2151,8 +2139,7 @@ static void bta_hh_le_service_discovery_done(RawAddress remote_bda) {
 ******************************************************************************/
static void bta_hh_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) {
  tBTA_HH_DEV_CB* p_dev_cb;
  LOG_VERBOSE("bta_hh_gattc_callback event:%s",
              gatt_client_event_text(event).c_str());
  LOG_VERBOSE("event:%s", gatt_client_event_text(event).c_str());
  if (p_data == NULL) return;

  switch (event) {
@@ -2229,7 +2216,7 @@ static void bta_hh_process_cache_rpt(tBTA_HH_DEV_CB* p_cb,
      if ((p_rpt = bta_hh_le_find_alloc_report_entry(
               p_cb, p_rpt_cache->srvc_inst_id, p_rpt_cache->rpt_uuid,
               p_rpt_cache->char_inst_id)) == NULL) {
        LOG_ERROR("bta_hh_process_cache_rpt: allocation report entry failure");
        LOG_ERROR("allocation report entry failure");
        break;
      } else {
        p_rpt->rpt_type = p_rpt_cache->rpt_type;
+11 −7
Original line number Diff line number Diff line
@@ -22,12 +22,14 @@
 *
 ******************************************************************************/

#define LOG_TAG "bt_bta_hh"

#include <string.h>  // memset

#include <cstdint>

#include "bt_target.h"  // Must be first to define build configuration
#include "bta/hh/bta_hh_int.h"
#include "os/log.h"
#include "osi/include/allocator.h"
#include "stack/include/bt_hdr.h"

@@ -44,6 +46,8 @@ static const char* bta_hh_state_code(tBTA_HH_STATE state_code);

static void bta_hh_better_state_machine(tBTA_HH_DEV_CB* p_cb, uint16_t event,
                                        const tBTA_HH_DATA* p_data) {
  LOG_VERBOSE("state:%s, event:%s", bta_hh_state_code(p_cb->state),
              bta_hh_evt_code(static_cast<tBTA_HH_INT_EVT>(event)));
  switch (p_cb->state) {
    case BTA_HH_IDLE_ST:
      switch (event) {
@@ -195,6 +199,8 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB* p_cb, uint16_t event,

  /* handle exception, no valid control block was found */
  if (!p_cb) {
    LOG_VERBOSE("Event:%s, bta_hh_cb.p_cback:%p", bta_hh_evt_code(debug_event),
                bta_hh_cb.p_cback);
    /* BTA HH enabled already? otherwise ignore the event although it's bad*/
    if (bta_hh_cb.p_cback != NULL) {
      switch (event) {
@@ -255,7 +261,7 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB* p_cb, uint16_t event,

        default:
          /* invalid handle, call bad API event */
          LOG_ERROR("wrong device handle: [%d]", p_data->hdr.layer_specific);
          LOG_ERROR("wrong device handle:%d", p_data->hdr.layer_specific);
          /* Free the callback buffer now */
          if (p_data != NULL)
            osi_free_and_reset((void**)&p_data->hid_cback.p_data);
@@ -267,12 +273,11 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB* p_cb, uint16_t event,
  /* corresponding CB is found, go to state machine */
  else {
    in_state = p_cb->state;
    LOG_VERBOSE("bta_hh_sm_execute: State 0x%02x [%s], Event [%s]", in_state,
    LOG_VERBOSE("State 0x%02x [%s], Event [%s]", in_state,
                bta_hh_state_code(in_state), bta_hh_evt_code(debug_event));

    if ((p_cb->state == BTA_HH_NULL_ST) || (p_cb->state >= BTA_HH_INVALID_ST)) {
      LOG_ERROR("bta_hh_sm_execute: Invalid state State = 0x%x, Event = %d",
                p_cb->state, event);
      LOG_ERROR("Invalid state State=0x%x, Event=%d", p_cb->state, event);
      return;
    }

@@ -332,8 +337,7 @@ bool bta_hh_hdl_event(const BT_HDR_RIGID* p_msg) {

  if (index != BTA_HH_IDX_INVALID) p_cb = &bta_hh_cb.kdev[index];

  LOG_VERBOSE("bta_hh_hdl_event:: handle = %d dev_cb[%d] ",
              p_msg->layer_specific, index);
  LOG_VERBOSE("handle=%d dev_cb[%d]", p_msg->layer_specific, index);
  bta_hh_sm_execute(p_cb, p_msg->event, (tBTA_HH_DATA*)p_msg);

  return (true);