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

Commit 29d29485 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski Committed by Gerrit Code Review
Browse files

Revert^2 "gatt: Improve queueing of GATT messages"

267a4807

Change-Id: I8e0ee9fa832207de6cd8e8c5c7f7b5a45a6f282a
parent 267a4807
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -17,7 +17,7 @@


#pragma once
#pragma once


#include <queue>
#include <deque>


#include "stack/gatt/gatt_int.h"
#include "stack/gatt/gatt_int.h"
#include "types/raw_address.h"
#include "types/raw_address.h"
@@ -54,7 +54,7 @@ class EattChannel {
  /* indication confirmation timer */
  /* indication confirmation timer */
  alarm_t* ind_confirmation_timer_;
  alarm_t* ind_confirmation_timer_;
  /* GATT client command queue */
  /* GATT client command queue */
  std::queue<tGATT_CMD_Q> cl_cmd_q_;
  std::deque<tGATT_CMD_Q> cl_cmd_q_;


  EattChannel(RawAddress& bda, uint16_t cid, uint16_t tx_mtu, uint16_t rx_mtu)
  EattChannel(RawAddress& bda, uint16_t cid, uint16_t tx_mtu, uint16_t rx_mtu)
      : bda_(bda),
      : bda_(bda),
@@ -79,7 +79,7 @@ class EattChannel {
  void EattChannelSetState(EattChannelState state) {
  void EattChannelSetState(EattChannelState state) {
    if (state_ == EattChannelState::EATT_CHANNEL_PENDING) {
    if (state_ == EattChannelState::EATT_CHANNEL_PENDING) {
      if (state == EattChannelState::EATT_CHANNEL_OPENED) {
      if (state == EattChannelState::EATT_CHANNEL_OPENED) {
        cl_cmd_q_ = std::queue<tGATT_CMD_Q>();
        cl_cmd_q_ = std::deque<tGATT_CMD_Q>();
        memset(&server_outstanding_cmd_, 0, sizeof(tGATT_SR_CMD));
        memset(&server_outstanding_cmd_, 0, sizeof(tGATT_SR_CMD));
        char name[64];
        char name[64];
        sprintf(name, "eatt_ind_ack_timer_%s_cid_0x%04x",
        sprintf(name, "eatt_ind_ack_timer_%s_cid_0x%04x",
+7 −0
Original line number Original line Diff line number Diff line
@@ -111,6 +111,13 @@ struct eatt_impl {
  }
  }


  void remove_channel_by_cid(eatt_device* eatt_dev, uint16_t lcid) {
  void remove_channel_by_cid(eatt_device* eatt_dev, uint16_t lcid) {
    auto channel = eatt_dev->eatt_channels[lcid];
    if (!channel->cl_cmd_q_.empty()) {
      LOG_WARN("Channel %c, for device %s is not empty on disconnection.", lcid,
               channel->bda_.ToString().c_str());
      channel->cl_cmd_q_.clear();
    }

    eatt_dev->eatt_channels.erase(lcid);
    eatt_dev->eatt_channels.erase(lcid);


    if (eatt_dev->eatt_channels.size() == 0) eatt_dev->eatt_tcb_ = NULL;
    if (eatt_dev->eatt_channels.size() == 0) eatt_dev->eatt_tcb_ = NULL;
+7 −3
Original line number Original line Diff line number Diff line
@@ -436,7 +436,8 @@ static tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
  if (gatt_tcb_is_cid_busy(tcb, p_clcb->cid) &&
  if (gatt_tcb_is_cid_busy(tcb, p_clcb->cid) &&
      cmd_code != GATT_HANDLE_VALUE_CONF) {
      cmd_code != GATT_HANDLE_VALUE_CONF) {
    gatt_cmd_enq(tcb, p_clcb, true, cmd_code, p_cmd);
    gatt_cmd_enq(tcb, p_clcb, true, cmd_code, p_cmd);
    LOG_DEBUG("Enqueued ATT command");
    LOG_DEBUG("Enqueued ATT command %p conn_id=0x%04x, cid=%d", p_clcb,
              p_clcb->conn_id, p_clcb->cid);
    return GATT_CMD_STARTED;
    return GATT_CMD_STARTED;
  }
  }


@@ -445,7 +446,9 @@ static tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
      p_clcb->cid, tcb.eatt, bt_transport_text(tcb.transport).c_str());
      p_clcb->cid, tcb.eatt, bt_transport_text(tcb.transport).c_str());
  tGATT_STATUS att_ret = attp_send_msg_to_l2cap(tcb, p_clcb->cid, p_cmd);
  tGATT_STATUS att_ret = attp_send_msg_to_l2cap(tcb, p_clcb->cid, p_cmd);
  if (att_ret != GATT_CONGESTED && att_ret != GATT_SUCCESS) {
  if (att_ret != GATT_CONGESTED && att_ret != GATT_SUCCESS) {
    LOG_WARN("Unable to send ATT command to l2cap layer");
    LOG_WARN(
        "Unable to send ATT command to l2cap layer %p conn_id=0x%04x, cid=%d",
        p_clcb, p_clcb->conn_id, p_clcb->cid);
    return GATT_INTERNAL_ERROR;
    return GATT_INTERNAL_ERROR;
  }
  }


@@ -453,7 +456,8 @@ static tGATT_STATUS attp_cl_send_cmd(tGATT_TCB& tcb, tGATT_CLCB* p_clcb,
    return att_ret;
    return att_ret;
  }
  }


  LOG_DEBUG("Starting ATT response timer");
  LOG_DEBUG("Starting ATT response timer %p conn_id=0x%04x, cid=%d", p_clcb,
            p_clcb->conn_id, p_clcb->cid);
  gatt_start_rsp_timer(p_clcb);
  gatt_start_rsp_timer(p_clcb);
  gatt_cmd_enq(tcb, p_clcb, false, cmd_code, NULL);
  gatt_cmd_enq(tcb, p_clcb, false, cmd_code, NULL);
  return att_ret;
  return att_ret;
+10 −33
Original line number Original line Diff line number Diff line
@@ -701,11 +701,6 @@ tGATT_STATUS GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu) {
    return GATT_ERROR;
    return GATT_ERROR;
  }
  }


  if (gatt_is_clcb_allocated(conn_id)) {
    LOG_WARN("Connection is already used conn_id:%hu", conn_id);
    return GATT_BUSY;
  }

  tGATT_CLCB* p_clcb = gatt_clcb_alloc(conn_id);
  tGATT_CLCB* p_clcb = gatt_clcb_alloc(conn_id);
  if (!p_clcb) {
  if (!p_clcb) {
    LOG_WARN("Unable to allocate connection link control block");
    LOG_WARN("Unable to allocate connection link control block");
@@ -764,11 +759,6 @@ tGATT_STATUS GATTC_Discover(uint16_t conn_id, tGATT_DISC_TYPE disc_type,
    return GATT_ILLEGAL_PARAMETER;
    return GATT_ILLEGAL_PARAMETER;
  }
  }


  if (gatt_is_clcb_allocated(conn_id)) {
    LOG(ERROR) << __func__ << "GATT_BUSY conn_id = " << +conn_id;
    return GATT_BUSY;
  }

  tGATT_CLCB* p_clcb = gatt_clcb_alloc(conn_id);
  tGATT_CLCB* p_clcb = gatt_clcb_alloc(conn_id);
  if (!p_clcb) {
  if (!p_clcb) {
    LOG(WARNING) << __func__ << " No resources conn_id=" << loghex(conn_id)
    LOG(WARNING) << __func__ << " No resources conn_id=" << loghex(conn_id)
@@ -834,11 +824,6 @@ tGATT_STATUS GATTC_Read(uint16_t conn_id, tGATT_READ_TYPE type,
    return GATT_ILLEGAL_PARAMETER;
    return GATT_ILLEGAL_PARAMETER;
  }
  }


  if (gatt_is_clcb_allocated(conn_id)) {
    LOG(ERROR) << "GATT_BUSY conn_id=" << loghex(conn_id);
    return GATT_BUSY;
  }

  tGATT_CLCB* p_clcb = gatt_clcb_alloc(conn_id);
  tGATT_CLCB* p_clcb = gatt_clcb_alloc(conn_id);
  if (!p_clcb) return GATT_NO_RESOURCES;
  if (!p_clcb) return GATT_NO_RESOURCES;


@@ -941,11 +926,6 @@ tGATT_STATUS GATTC_Write(uint16_t conn_id, tGATT_WRITE_TYPE type,
    return GATT_ILLEGAL_PARAMETER;
    return GATT_ILLEGAL_PARAMETER;
  }
  }


  if (gatt_is_clcb_allocated(conn_id)) {
    LOG(ERROR) << "GATT_BUSY conn_id=" << loghex(conn_id);
    return GATT_BUSY;
  }

  tGATT_CLCB* p_clcb = gatt_clcb_alloc(conn_id);
  tGATT_CLCB* p_clcb = gatt_clcb_alloc(conn_id);
  if (!p_clcb) return GATT_NO_RESOURCES;
  if (!p_clcb) return GATT_NO_RESOURCES;


@@ -994,11 +974,6 @@ tGATT_STATUS GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute) {
    return GATT_ILLEGAL_PARAMETER;
    return GATT_ILLEGAL_PARAMETER;
  }
  }


  if (gatt_is_clcb_allocated(conn_id)) {
    LOG(ERROR) << " GATT_BUSY conn_id=" << loghex(conn_id);
    return GATT_BUSY;
  }

  tGATT_CLCB* p_clcb = gatt_clcb_alloc(conn_id);
  tGATT_CLCB* p_clcb = gatt_clcb_alloc(conn_id);
  if (!p_clcb) return GATT_NO_RESOURCES;
  if (!p_clcb) return GATT_NO_RESOURCES;


@@ -1184,7 +1159,7 @@ void GATT_Deregister(tGATT_IF gatt_if) {
  /* When an application deregisters, check remove the link associated with the
  /* When an application deregisters, check remove the link associated with the
   * app */
   * app */
  tGATT_TCB* p_tcb;
  tGATT_TCB* p_tcb;
  int i, j;
  int i;
  for (i = 0, p_tcb = gatt_cb.tcb; i < GATT_MAX_PHY_CHANNEL; i++, p_tcb++) {
  for (i = 0, p_tcb = gatt_cb.tcb; i < GATT_MAX_PHY_CHANNEL; i++, p_tcb++) {
    if (!p_tcb->in_use) continue;
    if (!p_tcb->in_use) continue;


@@ -1192,13 +1167,15 @@ void GATT_Deregister(tGATT_IF gatt_if) {
      gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true);
      gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true);
    }
    }


    tGATT_CLCB* p_clcb;
    for (auto clcb_it = gatt_cb.clcb_queue.begin();
    for (j = 0, p_clcb = &gatt_cb.clcb[j]; j < GATT_CL_MAX_LCB; j++, p_clcb++) {
         clcb_it != gatt_cb.clcb_queue.end();) {
      if (p_clcb->in_use && (p_clcb->p_reg->gatt_if == gatt_if) &&
      if (clcb_it->in_use && (clcb_it->p_reg->gatt_if == gatt_if) &&
          (p_clcb->p_tcb->tcb_idx == p_tcb->tcb_idx)) {
          (clcb_it->p_tcb->tcb_idx == p_tcb->tcb_idx)) {
        alarm_cancel(p_clcb->gatt_rsp_timer_ent);
        alarm_cancel(clcb_it->gatt_rsp_timer_ent);
        gatt_clcb_dealloc(p_clcb);
        gatt_clcb_invalidate(p_tcb, &(*clcb_it));
        break;
        clcb_it = gatt_cb.clcb_queue.erase(clcb_it);
      } else {
        clcb_it++;
      }
      }
    }
    }
  }
  }
+10 −4
Original line number Original line Diff line number Diff line
@@ -1130,7 +1130,7 @@ uint8_t gatt_cmd_to_rsp_code(uint8_t cmd_code) {


/** Find next command in queue and sent to server */
/** Find next command in queue and sent to server */
bool gatt_cl_send_next_cmd_inq(tGATT_TCB& tcb) {
bool gatt_cl_send_next_cmd_inq(tGATT_TCB& tcb) {
  std::queue<tGATT_CMD_Q>* cl_cmd_q;
  std::deque<tGATT_CMD_Q>* cl_cmd_q = nullptr;


  while (!tcb.cl_cmd_q.empty() ||
  while (!tcb.cl_cmd_q.empty() ||
         EattExtension::GetInstance()->IsOutstandingMsgInSendQueue(tcb.peer_bda)) {
         EattExtension::GetInstance()->IsOutstandingMsgInSendQueue(tcb.peer_bda)) {
@@ -1153,7 +1153,7 @@ bool gatt_cl_send_next_cmd_inq(tGATT_TCB& tcb) {


    if (att_ret != GATT_SUCCESS && att_ret != GATT_CONGESTED) {
    if (att_ret != GATT_SUCCESS && att_ret != GATT_CONGESTED) {
      LOG(ERROR) << __func__ << ": L2CAP sent error";
      LOG(ERROR) << __func__ << ": L2CAP sent error";
      cl_cmd_q->pop();
      cl_cmd_q->pop_front();
      continue;
      continue;
    }
    }


@@ -1185,7 +1185,7 @@ bool gatt_cl_send_next_cmd_inq(tGATT_TCB& tcb) {
void gatt_client_handle_server_rsp(tGATT_TCB& tcb, uint16_t cid,
void gatt_client_handle_server_rsp(tGATT_TCB& tcb, uint16_t cid,
                                   uint8_t op_code, uint16_t len,
                                   uint8_t op_code, uint16_t len,
                                   uint8_t* p_data) {
                                   uint8_t* p_data) {
  VLOG(1) << __func__ << " opcode: " << loghex(op_code);
  VLOG(1) << __func__ << " opcode: " << loghex(op_code) << " cid" << +cid;


  uint16_t payload_size = gatt_tcb_get_payload_size_rx(tcb, cid);
  uint16_t payload_size = gatt_tcb_get_payload_size_rx(tcb, cid);


@@ -1205,7 +1205,13 @@ void gatt_client_handle_server_rsp(tGATT_TCB& tcb, uint16_t cid,
  uint8_t cmd_code = 0;
  uint8_t cmd_code = 0;
  tGATT_CLCB* p_clcb = gatt_cmd_dequeue(tcb, cid, &cmd_code);
  tGATT_CLCB* p_clcb = gatt_cmd_dequeue(tcb, cid, &cmd_code);
  uint8_t rsp_code = gatt_cmd_to_rsp_code(cmd_code);
  uint8_t rsp_code = gatt_cmd_to_rsp_code(cmd_code);
  if (!p_clcb || (rsp_code != op_code && op_code != GATT_RSP_ERROR)) {
  if (!p_clcb) {
    LOG_WARN("ATT - clcb already not in use, ignoring response");
    gatt_cl_send_next_cmd_inq(tcb);
    return;
  }

  if (rsp_code != op_code && op_code != GATT_RSP_ERROR) {
    LOG(WARNING) << StringPrintf(
    LOG(WARNING) << StringPrintf(
        "ATT - Ignore wrong response. Receives (%02x) Request(%02x) Ignored",
        "ATT - Ignore wrong response. Receives (%02x) Request(%02x) Ignored",
        op_code, rsp_code);
        op_code, rsp_code);
Loading