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

Commit 148efc5c authored by Chris Manton's avatar Chris Manton
Browse files

Re-log stack/gatt/att_protocol::attp_send_msg_to_l2cap

Towards loggable code

Bug: 163134718
Tag: #refactor
Test: act.py -tc BleCocTest
Test: ble paired 2 phones
Test: classic paired Bose SoundLink
Change-Id: I3d030824629bb43cfc7f2b6d8e1c4367f591017e
parent 4e0d52e1
Loading
Loading
Loading
Loading
+33 −10
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@

#include "gatt_int.h"
#include "l2c_api.h"
#include "osi/include/log.h"

#define GATT_HDR_FIND_TYPE_VALUE_LEN 21
#define GATT_OP_CODE_SIZE 1
@@ -326,10 +327,13 @@ tGATT_STATUS attp_send_msg_to_l2cap(tGATT_TCB& tcb, uint16_t lcid,
                                    BT_HDR* p_toL2CAP) {
  uint16_t l2cap_ret;

  if (lcid == L2CAP_ATT_CID)
  if (lcid == L2CAP_ATT_CID) {
    LOG_DEBUG("Sending ATT message on att fixed channel");
    l2cap_ret = L2CA_SendFixedChnlData(lcid, tcb.peer_bda, p_toL2CAP);
  else
  } else {
    LOG_DEBUG("Sending ATT message on lcid:%hu", lcid);
    l2cap_ret = (uint16_t)L2CA_DataWrite(lcid, p_toL2CAP);
  }

  if (l2cap_ret == L2CAP_DW_FAILED) {
    LOG(ERROR) << __func__ << ": failed to write data to L2CAP";
@@ -421,20 +425,21 @@ tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
  if (gatt_tcb_is_cid_busy(tcb, p_clcb->cid) &&
      cmd_code != GATT_HANDLE_VALUE_CONF) {
    gatt_cmd_enq(tcb, p_clcb, true, cmd_code, p_cmd);
    LOG_DEBUG("Enqueued ATT command");
    return GATT_CMD_STARTED;
  }

  /* no pending request or value confirmation */
  tGATT_STATUS att_ret = attp_send_msg_to_l2cap(tcb, p_clcb->cid, p_cmd);
  if (att_ret != GATT_CONGESTED && att_ret != GATT_SUCCESS) {
    LOG_WARN("Unable to send ATT command to l2cap layer");
    return GATT_INTERNAL_ERROR;
  }

  /* do not enq cmd if handle value confirmation or set request */
  if (cmd_code == GATT_HANDLE_VALUE_CONF || cmd_code == GATT_CMD_WRITE) {
    return att_ret;
  }

  LOG_DEBUG("Starting ATT response timer");
  gatt_start_rsp_timer(p_clcb);
  gatt_cmd_enq(tcb, p_clcb, false, cmd_code, NULL);
  return att_ret;
@@ -491,7 +496,7 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
  uint16_t offset = 0, handle;

  if (!p_clcb) {
    LOG(ERROR) << "Missing p_clcb" << +op_code;
    LOG_ERROR("Missing p_clcb");
    return GATT_ILLEGAL_PARAMETER;
  }

@@ -499,7 +504,12 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,

  switch (op_code) {
    case GATT_REQ_MTU:
      if (p_msg->mtu > GATT_MAX_MTU_SIZE) return GATT_ILLEGAL_PARAMETER;
      if (p_msg->mtu > GATT_MAX_MTU_SIZE) {
        LOG_WARN(
            "GATT message MTU is larger than max GATT MTU size op_code:%hhu",
            op_code);
        return GATT_ILLEGAL_PARAMETER;
      }

      tcb.payload_size = p_msg->mtu;
      p_cmd = attp_build_mtu_cmd(GATT_REQ_MTU, p_msg->mtu);
@@ -510,8 +520,10 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
    case GATT_REQ_READ_BY_GRP_TYPE:
      if (!GATT_HANDLE_IS_VALID(p_msg->browse.s_handle) ||
          !GATT_HANDLE_IS_VALID(p_msg->browse.e_handle) ||
          p_msg->browse.s_handle > p_msg->browse.e_handle)
          p_msg->browse.s_handle > p_msg->browse.e_handle) {
        LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code);
        return GATT_ILLEGAL_PARAMETER;
      }

      p_cmd = attp_build_browse_cmd(op_code, p_msg->browse.s_handle,
                                    p_msg->browse.e_handle, p_msg->browse.uuid);
@@ -524,7 +536,10 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
      handle =
          (op_code == GATT_REQ_READ) ? p_msg->handle : p_msg->read_blob.handle;
      /*  handle checking */
      if (!GATT_HANDLE_IS_VALID(handle)) return GATT_ILLEGAL_PARAMETER;
      if (!GATT_HANDLE_IS_VALID(handle)) {
        LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code);
        return GATT_ILLEGAL_PARAMETER;
      }

      p_cmd = attp_build_handle_cmd(op_code, handle, offset);
      break;
@@ -535,8 +550,10 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
    case GATT_REQ_WRITE:
    case GATT_CMD_WRITE:
    case GATT_SIGN_CMD_WRITE:
      if (!GATT_HANDLE_IS_VALID(p_msg->attr_value.handle))
      if (!GATT_HANDLE_IS_VALID(p_msg->attr_value.handle)) {
        LOG_WARN("GATT message has invalid handle op_code:%hhu", op_code);
        return GATT_ILLEGAL_PARAMETER;
      }

      p_cmd = attp_build_value_cmd(
          payload_size, op_code, p_msg->attr_value.handle, offset,
@@ -562,7 +579,13 @@ tGATT_STATUS attp_send_cl_msg(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
      break;
  }

  if (p_cmd == NULL) return GATT_NO_RESOURCES;
  if (p_cmd == NULL) {
    LOG_WARN(
        "Unable to build proper GATT message to send to peer device "
        "op_code:%hhu",
        op_code);
    return GATT_NO_RESOURCES;
  }

  return attp_cl_send_cmd(tcb, p_clcb, op_code, p_cmd);
}